!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,function(t){"use strict";function e(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const n={};const i=t=>t,s=(t,e,n)=>{const i=e-t;return i?(n-t)/i:1},o=t=>1e3*t,a=t=>t/1e3;function r(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const l=0,u=!1;let h;function c(){h=void 0}const f={now:()=>(void 0===h&&f.set(n.useManualTiming?l:performance.now()),h),set:t=>{h=t,queueMicrotask(c)}},m=(t,e,n)=>t+(e-t)*n;function d(t,e=100,n){const{keyframes:i,velocity:s}=t,o=i&&i[i.length-1]-i[0],r=n({...t,velocity:s&&o?s*e/o:s,keyframes:[0,e]}),l=Math.min(function(t,e=50,n=2e4){let i=0,s=t.next(i);for(;!s.done&&i=n?1/0:i}(r),2e4);return{type:"keyframes",ease:t=>r.next(l*t).value/e,duration:a(l)}}function p(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const o=s(0,e,i);t.push(m(n,1,o))}}function y(t){const e=[0];return p(e,t.length-1),e}const g=t=>null!==t;function T(t,e){return{kind:t,animation:e,timestamp:f.now(),frameTimestamp:l,frameIsProcessing:u}}class A{constructor(){this.isResolved=!1}get finished(){return this._finished||(this._finished=this.isResolved?Promise.resolve():new Promise(t=>{this._resolve=t})),this._finished}updateFinished(){this._finished=this._resolve=void 0,this.isResolved=!1}notifyFinished(){this.isResolved=!0,this._resolve?.()}then(t,e){return this.finished.then(t,e)}}function v(t){for(let e=1;et.startsWith("--");const k={};function S(t,e){const n=function(t){let e;return()=>(void 0===e&&(e=t()),e)}(t);return()=>k[e]??n()}const w=S(()=>void 0!==window.ScrollTimeline,"scrollTimeline"),M=S(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),E=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,x={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:E([0,.65,.55,1]),circOut:E([.55,0,1,.45]),backIn:E([.31,.01,.66,-.59]),backOut:E([.33,1.53,.69,.99])};function B(t,e){return t?"function"==typeof t?M()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;eArray.isArray(t)&&"number"==typeof t[0])(t)?E(t):Array.isArray(t)?t.map(t=>B(t,e)||x.easeOut):x[t]:void 0}function I(t){return"function"==typeof t&&"applyToOptions"in t}class R extends A{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:e,name:n,keyframes:i,pseudoElement:s,allowFlatten:o=!1,finalKeyframe:a,onComplete:r}=t;this.isPseudoElement=Boolean(s),this.allowFlatten=o,this.options=t,t.type;const l=function({type:t,...e}){return I(t)&&M()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(t);this.animation=function(t,e,n,{delay:i=0,duration:s=300,repeat:o=0,repeatType:a="loop",ease:r="easeOut",times:l}={},u){const h={[e]:n};l&&(h.offset=l);const c=B(r,s);Array.isArray(c)&&(h.easing=c);const f={delay:i,duration:s,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:o+1,direction:"reverse"===a?"alternate":"normal"};return u&&(f.pseudoElement=u),t.animate(h,f)}(e,n,i,l,s),!1===l.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!s){const t=function(t,{repeat:e,repeatType:n="loop"},i,s=1){const o=t.filter(g),a=s<0||e&&"loop"!==n&&e%2==1?0:o.length-1;return a&&void 0!==i?i:o[a]}(i,this.options,a,this.speed);this.updateMotionValue&&this.updateMotionValue(t),function(t,e,n){b(e)?t.style.setProperty(e,n):t.style[e]=n}(e,n,t),this.animation.cancel()}r?.(),this.notifyFinished()},function(t,e,n){const i=globalThis.__MOTION_INSPECT__;if(i)try{i({...T("animation-start",t),options:n?{...e,...n}:e})}catch{}}(this,t,l)}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){const t=this.options?.element;!this.isPseudoElement&&t?.isConnected&&this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return a(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+a(t)}get time(){return a(Number(this.animation.currentTime)||0)}set time(t){const e=null!==this.finishedTime;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=o(t),e&&this.animation.pause()}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,onAttach:e,observe:n}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&w()?(this.animation.timeline=t,e?.(this.animation),i):n(this)}}class O{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;ne.attachTimeline(t));return()=>{e.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return P(this.animations,"duration")}get iterationDuration(){return P(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(e=>e[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function P(t,e){let n=0;for(let i=0;in&&(n=s)}return n}class _ extends O{then(t,e){return this.finished.finally(t).then(()=>{})}}const W=new WeakMap,F=(t,e="")=>`${t}:${e}`;function $(t){let e=W.get(t);return e||(e=new Map,W.set(t,e)),e}function L(t,e){const n=t?.[e]??t?.default??t;return n!==t?function(t,e){if(t?.inherit&&e){const{inherit:n,...i}=t;return{...e,...i}}return t}(n,t):n}const N=t=>Boolean(t&&t.getVelocity),V=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","inset","insetBlock","insetBlockStart","insetBlockEnd","insetInline","insetInlineStart","insetInlineEnd","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingBlockStart","paddingBlockEnd","paddingInline","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginBlockStart","marginBlockEnd","marginInline","marginInlineStart","marginInlineEnd","fontSize","backgroundPositionX","backgroundPositionY"]);function C(t,e){for(let n=0;nnull!=t)}function q(t,e){const n=window.getComputedStyle(t);return b(e)?n.getPropertyValue(e):n[e]}function K(t,e,n,i){return null==t?[]:"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?D(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t.filter(t=>null!=t):[t]}function j(t,e,n){return t*(e+1)+n*e}function z(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:e.startsWith("<")?Math.max(0,n+parseFloat(e.slice(1))):i.get(e)??t}function H(t,n,i,s,o,a){!function(t,n,i){for(let s=0;sn&&o.at"number"==typeof t,tt=t=>t.every(Z);function et(t,e,n,i){if(null==t)return[];const s=D(t),a=s.length,r=[];for(let t=0;te.delete(n)),l.push(s)}return l}const nt=(()=>function(t,e,n){return new _(et(t,e,n))})();t.animate=nt,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const l=e.duration||.3,u=new Map,h=new Map,c={},f=new Map;let m=0,g=0,T=0;for(let n=0;n{const h=Q(t),{delay:c=0,times:f=y(h),type:m=e.type||"keyframes",repeat:A,repeatType:b,repeatDelay:k=0,...S}=n;let{ease:w=e.ease||"easeOut",duration:M}=n;const E="function"==typeof c?c(s,u):c,x=h.length,B=I(m)?m:a?.[m||"keyframes"];if(x<=2&&B){let t=100;if(2===x&&tt(h)){const e=h[1]-h[0];t=Math.abs(e)}const n={...e,...S};void 0!==M&&(n.duration=o(M));const i=d(n,t,B);w=i.ease,M=i.duration}M??(M=l);const R=g+E;1===f.length&&0===f[0]&&(f[1]=1);const O=f.length-h.length;if(O>0&&p(f,O),1===h.length&&h.unshift(null),A&&A<20){const t=M>0?k/M:0;M=j(M,A,k);const e=[...h],n=[...f];w=Array.isArray(w)?[...w]:[w];const i=[...w],s="reverse"===b||"mirror"===b;let o=e,a=i;s&&(o=[...e].reverse(),"reverse"===b&&(a=[...i].reverse().map(t=>{return"function"==typeof t?(e=t,t=>1-e(1-t)):t;var e})));for(let l=0;l0&&(h.push(h[h.length-1]),f.push(d),w.push("linear")),h.push(...c);for(let t=0;t{for(const o in t){const a=t[o];a.sort(Y);const r=[],l=[],h=[];for(let t=0;t{n.push(...et(i,t,e))}),new _(n)}});