import{r as h,ag as x}from"./main-TIUJvpaR.js";import{$ as b}from"./useGlobalListeners-_BzTaAbJ.js";function U({onMoveStart:s,onMove:a,onMoveEnd:c,minimumMovement:g=0,preventDefault:w,stopPropagation:T=!0,onPress:f,onLongPress:n,...l}){const t=h.useRef({lastPosition:{x:0,y:0},started:!1,longPressTriggered:!1}).current,{addGlobalListener:d,removeGlobalListener:u}=b(),P=e=>{!t.el||(s==null?void 0:s(e,t.el))===!1||(t.originalTouchAction=t.el.style.touchAction,t.el.style.touchAction="none",t.originalUserSelect=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",t.started=!0)},y=e=>{var i;if(e.button===0&&t.id==null){if(t.started=!1,((i=l.onPointerDown)==null?void 0:i.call(l,e))===!1)return;T&&e.stopPropagation(),w&&e.preventDefault(),t.id=e.pointerId,t.el=e.currentTarget,t.lastPosition={x:e.clientX,y:e.clientY},n&&(t.longPressTimer=setTimeout(()=>{n(e,t.el),t.longPressTriggered=!0},400)),(s||a)&&d(window,"pointermove",m,!1),d(window,"pointerup",o,!1),d(window,"pointercancel",o,!1)}},m=e=>{if(e.pointerId===t.id){const i=e.clientX-t.lastPosition.x,r=e.clientY-t.lastPosition.y;(Math.abs(i)>=g||Math.abs(r)>=g)&&!t.started&&P(e),t.started&&(a==null||a(e,i,r),t.lastPosition={x:e.clientX,y:e.clientY})}},o=e=>{var i;if(e.pointerId===t.id){t.longPressTimer&&clearTimeout(t.longPressTimer);const r=t.longPressTriggered;t.longPressTriggered=!1,t.started&&(c==null||c(e)),t.el&&(e.type!=="pointercancel"&&((i=l.onPointerUp)==null||i.call(l,e,t.el),e.target&&t.el.contains(e.target)&&(r?n==null||n(e,t.el):f==null||f(e,t.el))),document.documentElement.style.userSelect=t.originalUserSelect||"",t.el.style.touchAction=t.originalTouchAction||""),t.id=void 0,t.started=!1,u(window,"pointermove",m,!1),u(window,"pointerup",o,!1),u(window,"pointercancel",o,!1)}};return{domProps:{onPointerDown:x(y)}}}export{U as u};
