!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).EmblaCarouselAutoScroll=n()}(this,(function(){"use strict";const t={direction:"forward",speed:2,startDelay:1e3,active:!0,breakpoints:{},playOnInit:!0,stopOnFocusIn:!0,stopOnInteraction:!0,stopOnMouseEnter:!1,rootNode:null};function n(o={}){let e,i,r,s,c,a=0,u=!1,l=!1;function f(){if(r)return;if(u)return;i.emit("autoScroll:play");const t=i.internalEngine(),{ownerWindow:n}=t;a=n.setTimeout((()=>{t.scrollBody=function(t){const{location:n,previousLocation:o,offsetLocation:r,target:s,scrollTarget:c,index:a,indexPrevious:u,limit:{reachedMin:l,reachedMax:f,constrain:p},options:{loop:g}}=t,y="forward"===e.direction?-1:1,m=()=>v;let O=0,w=0,E=n.get(),I=0,b=!1;function h(){let t=0;o.set(n),O=y*e.speed,E+=O,n.add(O),s.set(n),t=E-I,w=Math.sign(t),I=E;const m=c.byDistance(0,!1).index;a.get()!==m&&(u.set(a.get()),a.set(m),i.emit("select"));const h="forward"===e.direction?l(r.get()):f(r.get());if(!g&&h){b=!0;const t=p(n.get());n.set(t),s.set(n),d()}return v}const v={direction:()=>w,duration:()=>-1,velocity:()=>O,settled:()=>b,seek:h,useBaseFriction:m,useBaseDuration:m,useFriction:m,useDuration:m};return v}(t),t.animation.start()}),s),u=!0}function d(){if(r)return;if(!u)return;i.emit("autoScroll:stop");const t=i.internalEngine(),{ownerWindow:n}=t;t.scrollBody=c,n.clearTimeout(a),a=0,u=!1}function p(){l||d()}function g(){l||w()}function y(){l=!0,d()}function m(){l=!1,f()}function O(){i.off("settle",O),f()}function w(){i.on("settle",O)}return{name:"autoScroll",options:o,init:function(a,u){i=a;const{mergeOptions:l,optionsAtMedia:O}=u,w=l(t,n.globalOptions),E=l(w,o);if(e=O(E),i.scrollSnapList().length<=1)return;s=e.startDelay,r=!1,c=i.internalEngine().scrollBody;const{eventStore:I}=i.internalEngine(),b=!!i.internalEngine().options.watchDrag,h=function(t,n){const o=t.rootNode();return n&&n(o)||o}(i,e.rootNode);b&&i.on("pointerDown",p),b&&!e.stopOnInteraction&&i.on("pointerUp",g),e.stopOnMouseEnter&&I.add(h,"mouseenter",y),e.stopOnMouseEnter&&!e.stopOnInteraction&&I.add(h,"mouseleave",m),e.stopOnFocusIn&&i.on("slideFocusStart",d),e.stopOnFocusIn&&!e.stopOnInteraction&&I.add(i.containerNode(),"focusout",f),e.playOnInit&&f()},destroy:function(){i.off("pointerDown",p).off("pointerUp",g).off("slideFocusStart",d).off("settle",O),d(),r=!0,u=!1},play:function(t){void 0!==t&&(s=t),f()},stop:function(){u&&d()},reset:function(){u&&(d(),w())},isPlaying:function(){return u}}}return n.globalOptions=void 0,n}));
