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