import t from"../core/Interaction.prod.js";import*as n from"../utils/domUtils.prod.js";import e from"../utils/is.prod.js";import o from"../utils/raf.prod.js";import{getStringOptionResult as r}from"../utils/rect.prod.js";import{getWindow as i}from"../utils/window.prod.js";const l={defaults:{enabled:!1,margin:60,container:null,speed:300},now:Date.now,interaction:null,i:0,x:0,y:0,isScrolling:!1,prevTime:0,margin:0,speed:0,start(t){l.isScrolling=!0,o.cancel(l.i),t.autoScroll=l,l.interaction=t,l.prevTime=l.now(),l.i=o.request(l.scroll)},stop(){l.isScrolling=!1,l.interaction&&(l.interaction.autoScroll=null),o.cancel(l.i)},scroll(){const{interaction:t}=l,{interactable:n,element:r}=t,i=t.prepared.name,c=n.options[i].autoScroll,a=getContainer(c.container,n,r),s=l.now(),p=(s-l.prevTime)/1e3,u=c.speed*p;if(u>=1){const o={x:l.x*u,y:l.y*u};if(o.x||o.y){const i=getScroll(a);e.window(a)?a.scrollBy(o.x,o.y):a&&(a.scrollLeft+=o.x,a.scrollTop+=o.y);const l=getScroll(a),c={x:l.x-i.x,y:l.y-i.y};(c.x||c.y)&&n.fire({type:"autoscroll",target:r,interactable:n,delta:c,interaction:t,container:a})}l.prevTime=s}l.isScrolling&&(o.cancel(l.i),l.i=o.request(l.scroll))},check(t,n){var e;return null==(e=t.options[n].autoScroll)?void 0:e.enabled},onInteractionMove({interaction:t,pointer:o}){if(!t.interacting()||!l.check(t.interactable,t.prepared.name))return;if(t.simulation)return void(l.x=l.y=0);let r,i,c,a;const{interactable:s,element:p}=t,u=t.prepared.name,m=s.options[u].autoScroll,d=getContainer(m.container,s,p);if(e.window(d))a=o.clientX<l.margin,r=o.clientY<l.margin,i=o.clientX>d.innerWidth-l.margin,c=o.clientY>d.innerHeight-l.margin;else{const t=n.getElementClientRect(d);a=o.clientX<t.left+l.margin,r=o.clientY<t.top+l.margin,i=o.clientX>t.right-l.margin,c=o.clientY>t.bottom-l.margin}l.x=i?1:a?-1:0,l.y=c?1:r?-1:0,l.isScrolling||(l.margin=m.margin,l.speed=m.speed,l.start(t))}};export function getContainer(t,n,o){return(e.string(t)?r(t,n,o):t)||i(o)}export function getScroll(t){return e.window(t)&&(t=window.document.body),{x:t.scrollLeft,y:t.scrollTop}}export function getScrollSize(t){return e.window(t)&&(t=window.document.body),{x:t.scrollWidth,y:t.scrollHeight}}export function getScrollSizeDelta({interaction:t,element:n},e){const o=t&&t.interactable.options[t.prepared.name].autoScroll;if(!o||!o.enabled)return e(),{x:0,y:0};const r=getContainer(o.container,t.interactable,n),i=getScroll(r);e();const l=getScroll(r);return{x:l.x-i.x,y:l.y-i.y}}const c={id:"auto-scroll",install(t){const{defaults:n,actions:e}=t;t.autoScroll=l,l.now=()=>t.now(),e.phaselessTypes.autoscroll=!0,n.perAction.autoScroll=l.defaults},listeners:{"interactions:new"({interaction:t}){t.autoScroll=null},"interactions:destroy"({interaction:t}){t.autoScroll=null,l.stop(),l.interaction&&(l.interaction=null)},"interactions:stop":l.stop,"interactions:action-move":t=>l.onInteractionMove(t)}};export default c;
//# sourceMappingURL=plugin.prod.js.map