UNPKG

@snapdrag/plugins

Version:

Plugins for Snapdrag drag and drop library

2 lines 1.47 kB
'use strict';var v={threshold:100,speed:2e3,distancePower:1.5};function P(e){return typeof e=="boolean"?{...v}:{...v,...e}}function E(e,f){if(e instanceof Window)return {top:0,left:0,bottom:e.innerHeight,right:e.innerWidth};{let{top:r,bottom:o,left:n,right:d}=e.getBoundingClientRect();return {top:r*f,bottom:o*f,left:n*f,right:d*f}}}function q(e){return function(r){if(!r)return {};let o=e.x?P(e.x):null,n=e.y?P(e.y):null,d=false,s=null,g=0,l=0,i=0,m=1;function y(h){if(!d)return;let b=h-g;g=h;let a=0,u=0,{top:w,bottom:x,left:A,right:c}=E(r,m);if(o){let{threshold:t,speed:M,distancePower:C}=o,S=Math.max(t+A-l,t-c+l),p=Math.pow(Math.min(S/t,1),C)*M*b/1e3;l<t-A?a=-p:l>c-t&&(a=p);}if(n){let{threshold:t,speed:M,distancePower:C}=n,S=Math.max(t+w-i,t-x+i),p=Math.pow(Math.min(S/t,1),C)*M*b/1e3;i<t-w?u=-p:i>x-t&&(u=p);}(a!==0||u!==0)&&r?.scrollBy(a,u),s=requestAnimationFrame(y);}function R(){d=true,g=performance.now();}function D(){d=false,g=0,s&&cancelAnimationFrame(s);}function T({event:h}){let b=window.devicePixelRatio,a=window.visualViewport?window.visualViewport.scale:1;m=b/a,l=h.x*m,i=h.y*m;let{top:u,bottom:w,left:x,right:A}=E(r,m),c=false;o&&(c||(c=l<o.threshold+x||l>A-o.threshold)),n&&(c||(c=i<n.threshold+u||i>w-n.threshold)),s&&cancelAnimationFrame(s),c&&(s=requestAnimationFrame(y));}function F(){D();}return {onDragStart:R,onDragEnd:D,onDragMove:T,cleanup:F}}}exports.createScroller=q;//# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map