vexip-ui
Version:
A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good
3 lines (2 loc) • 1.84 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),p=require("@vexip-ui/utils"),g=require("./symbol.cjs");function x({currentScroll:e=l.ref(0),trackSpeed:f=l.ref(2),track:s=l.ref(null),bar:u=l.ref(null),tracking:v=l.ref(!1),type:d=l.ref(g.ScrollbarType.VERTICAL),barLength:h=l.ref(35),disabled:A=l.ref(!1),onDown:L=p.noop,onMove:b=p.noop,onUp:q=p.noop,onScroll:D=p.noop}){let m,n,i,o,M=!0,T=!1;function E(){if(!v.value)return;T=!0;const t=B(o,e.value);let a=!1;M?e.value<o&&(e.value+=t*f.value,a=!0):e.value>o&&(e.value-=t*f.value,a=!0),a&&(w(),D(e.value)),(v.value&&M?e.value<o:e.value>o)?requestAnimationFrame(E):T=!1}function c(t){if(A.value||t.button>0||(t.stopPropagation(),t.preventDefault(),!s.value||!u.value))return!1;document.addEventListener("pointermove",C),document.addEventListener("pointerup",y);const a=s.value.getBoundingClientRect(),r=u.value.getBoundingClientRect();let R;d.value===g.ScrollbarType.VERTICAL?(m=a.height,n=r.top-a.top,i=r.top,R=n+t.clientY-i):(m=a.width,n=r.left-a.left,i=r.left,R=n+t.clientX-i),o=Math.max(0,Math.min(R/m/(100-h.value/2)*1e4,100)),M=o>=e.value,v.value=!0,L(e.value),E()}function C(t){t.stopPropagation(),p.USE_TOUCH||t.preventDefault(),b(e.value);let a;d.value===g.ScrollbarType.VERTICAL?a=n+t.clientY-i:a=n+t.clientX-i,o=Math.max(0,Math.min(a/m/(100-h.value/2)*1e4,100)),!T&&E()}function y(t){t.preventDefault(),document.removeEventListener("pointermove",C),document.removeEventListener("pointerup",y),v.value=!1,q(e.value)}function w(){e.value=Math.max(0,Math.min(e.value,100))}return{currentScroll:e,trackSpeed:f,track:s,bar:u,tracking:v,type:d,barLength:h,disabled:A,handleMouseDown:c}}function B(e,f){const s=Math.abs(e-f);for(let u=0;u<5;++u)if(s<(u+1)*20)return 1+.25*u;return 2}exports.useTrack=x;
//# sourceMappingURL=hooks.cjs.map