import{ref as m,onMounted as R,onBeforeUnmount as w}from"vue";import l from"../../../_util/hooks/useState.mjs";const A=.1,p=.01,r=20,I=.995**r;function C(E,i){const[u,v]=l(),[P,S]=l(0),[T,b]=l(0),[y,x]=l(),f=m();function D(e){const{screenX:t,screenY:n}=e.touches[0];v({x:t,y:n}),clearInterval(f.value)}function X(e){if(!u.value)return;e.preventDefault();const{screenX:t,screenY:n}=e.touches[0],o=t-u.value.x,a=n-u.value.y;i(o,a),v({x:t,y:n});const s=Date.now();b(s-P.value),S(s),x({x:o,y:a})}function Y(){if(!u.value)return;const e=y.value;if(v(null),x(null),e){const t=e.x/T.value,n=e.y/T.value,o=Math.abs(t),a=Math.abs(n);if(Math.max(o,a)<A)return;let s=t,d=n;f.value=setInterval(()=>{if(Math.abs(s)<p&&Math.abs(d)<p){clearInterval(f.value);return}s*=I,d*=I,i(s*r,d*r)},r)}}const h=m();function _(e){const{deltaX:t,deltaY:n}=e;let o=0;const a=Math.abs(t),s=Math.abs(n);a===s?o=h.value==="x"?t:n:a>s?(o=t,h.value="x"):(o=n,h.value="y"),i(-o,-o)&&e.preventDefault()}const c=m({onTouchStart:D,onTouchMove:X,onTouchEnd:Y,onWheel:_});function W(e){c.value.onTouchStart(e)}function M(e){c.value.onTouchMove(e)}function L(e){c.value.onTouchEnd(e)}function N(e){c.value.onWheel(e)}R(()=>{document.addEventListener("touchmove",M,{passive:!1}),document.addEventListener("touchend",L,{passive:!1}),E.value?.addEventListener("touchstart",W,{passive:!1}),E.value?.addEventListener("wheel",N,{passive:!1})}),w(()=>{document.removeEventListener("touchmove",M),document.removeEventListener("touchend",L)})}export{C as default};
