UNPKG

ll-package

Version:

2 lines (1 loc) 1.71 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("vue"),r=require("../../../_util/hooks/useState.js"),N=.1,S=.01,i=20,L=Math.pow(.995,i);function O(E,v){const[c,f]=r.default(),[P,y]=r.default(0),[m,I]=r.default(0),[_,M]=r.default(),d=u.ref();function p(e){const{screenX:t,screenY:n}=e.touches[0];f({x:t,y:n}),clearInterval(d.value)}function D(e){if(!c.value)return;e.preventDefault();const{screenX:t,screenY:n}=e.touches[0],o=t-c.value.x,a=n-c.value.y;v(o,a),f({x:t,y:n});const s=Date.now();I(s-P.value),y(s),M({x:o,y:a})}function X(){if(!c.value)return;const e=_.value;if(f(null),M(null),e){const t=e.x/m.value,n=e.y/m.value,o=Math.abs(t),a=Math.abs(n);if(Math.max(o,a)<N)return;let s=t,T=n;d.value=setInterval(()=>{if(Math.abs(s)<S&&Math.abs(T)<S){clearInterval(d.value);return}s*=L,T*=L,v(s*i,T*i)},i)}}const h=u.ref();function Y(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"),v(-o,-o)&&e.preventDefault()}const l=u.ref({onTouchStart:p,onTouchMove:D,onTouchEnd:X,onWheel:Y});function W(e){l.value.onTouchStart(e)}function b(e){l.value.onTouchMove(e)}function x(e){l.value.onTouchEnd(e)}function w(e){l.value.onWheel(e)}u.onMounted(()=>{var e,t;document.addEventListener("touchmove",b,{passive:!1}),document.addEventListener("touchend",x,{passive:!1}),(e=E.value)===null||e===void 0||e.addEventListener("touchstart",W,{passive:!1}),(t=E.value)===null||t===void 0||t.addEventListener("wheel",w,{passive:!1})}),u.onBeforeUnmount(()=>{document.removeEventListener("touchmove",b),document.removeEventListener("touchend",x)})}exports.default=O;