!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)}function n(t,e){return e?`${t}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${e}`:t}let i=()=>{},s=()=>{};"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&(i=(t,e,i)=>{t||"undefined"==typeof console||console.warn(n(e,i))},s=(t,e,i)=>{if(!t)throw new Error(n(e,i))});const o=t=>t,a=(t,e,n)=>{const i=e-t;return i?(n-t)/i:1},r=t=>1e3*t,l=t=>t/1e3;function u(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 h=(t,e,n)=>t+(e-t)*n,c=2e4;function f(t,e=100,n){const i=n({...t,keyframes:[0,e]}),s=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e=c?1/0:e}(i),c);return{type:"keyframes",ease:t=>i.next(s*t).value/e,duration:l(s)}}function d(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const s=a(0,e,i);t.push(h(n,1,s))}}function m(t){const e=[0];return d(e,t.length-1),e}const p=t=>null!==t;class g{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(t=>{this.resolve=t})}notifyFinished(){this.resolve()}then(t,e){return this.finished.then(t,e)}}function y(t){for(let e=1;et.startsWith("--");const T={};function b(t,e){const n=function(t){let e;return()=>(void 0===e&&(e=t()),e)}(t);return()=>T[e]??n()}const v=b(()=>void 0!==window.ScrollTimeline,"scrollTimeline"),S=b(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),k=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,E={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:k([0,.65,.55,1]),circOut:k([.55,0,1,.45]),backIn:k([.31,.01,.66,-.59]),backOut:k([.33,1.53,.69,.99])};function w(t,e){return t?"function"==typeof t?S()?((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)?k(t):Array.isArray(t)?t.map(t=>w(t,e)||E.easeOut):E[t]:void 0}function M(t){return"function"==typeof t&&"applyToOptions"in t}class B extends g{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:e,name:n,keyframes:i,pseudoElement:o,allowFlatten:a=!1,finalKeyframe:r,onComplete:l}=t;this.isPseudoElement=Boolean(o),this.allowFlatten=a,this.options=t,s("string"!=typeof t.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const u=function({type:t,...e}){return M(t)&&S()?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=w(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,u,o),!1===u.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!o){const t=function(t,{repeat:e,repeatType:n="loop"},i,s=1){const o=t.filter(p),a=s<0||e&&"loop"!==n&&e%2==1?0:o.length-1;return a&&void 0!==i?i:o[a]}(i,this.options,r,this.speed);this.updateMotionValue&&this.updateMotionValue(t),function(t,e,n){A(e)?t.style.setProperty(e,n):t.style[e]=n}(e,n,t),this.animation.cancel()}l?.(),this.notifyFinished()}}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 l(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+l(t)}get time(){return l(Number(this.animation.currentTime)||0)}set time(t){const e=null!==this.finishedTime;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=r(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,rangeStart:e,rangeEnd:n,observe:i}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&v()?(this.animation.timeline=t,e&&(this.animation.rangeStart=e),n&&(this.animation.rangeEnd=n),o):i(this)}}class x{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 I(this.animations,"duration")}get iterationDuration(){return I(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 I(t,e){let n=0;for(let i=0;in&&(n=s)}return n}class O extends x{then(t,e){return this.finished.finally(t).then(()=>{})}}const F=new WeakMap,R=(t,e="")=>`${t}:${e}`;function W(t){let e=F.get(t);return e||(e=new Map,F.set(t,e)),e}function $(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 P=t=>Boolean(t&&t.getVelocity),N=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 V(t,e){for(let n=0;nnull!=t)}function D(t,e){const n=window.getComputedStyle(t);return A(e)?n.getPropertyValue(e):n[e]}function q(t,e,n,i){return null==t?[]:"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?L(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t.filter(t=>null!=t):[t]}function C(t,e,n){return t*(e+1)+n*e}function K(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 _(t,n,i,s,o,a){!function(t,n,i){for(let s=0;sn&&o.at"number"==typeof t,J=t=>t.every(G);function Q(t,e,n,i){if(null==t)return[];const o=L(t),a=o.length;s(Boolean(a),"No valid elements provided.","no-valid-elements");const l=[];for(let t=0;te.delete(n)),u.push(s)}return u}const Z=(()=>function(t,e,n){return new O(Q(t,e,n))})();t.animate=Z,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},s,o){const l=e.duration||.3,h=new Map,c=new Map,p={},g=new Map;let y=0,A=0,T=0;for(let n=0;n{const c=X(t),{delay:p=0,times:g=m(c),type:y=e.type||"keyframes",repeat:b,repeatType:S,repeatDelay:k=0,...E}=n;let{ease:w=e.ease||"easeOut",duration:B}=n;const x="function"==typeof p?p(a,h):p,I=c.length,O=M(y)?y:o?.[y||"keyframes"];if(I<=2&&O){let t=100;if(2===I&&J(c)){const e=c[1]-c[0];t=Math.abs(e)}const n={...e,...E};void 0!==B&&(n.duration=r(B));const i=f(n,t,O);w=i.ease,B=i.duration}B??(B=l);const F=A+x;1===g.length&&0===g[0]&&(g[1]=1);const R=g.length-c.length;if(R>0&&d(g,R),1===c.length&&c.unshift(null),b&&i(b<20,`Sequence segments can't repeat ${b} times — ignoring repeat option. Use a value below 20 or apply repeat at the sequence level instead.`),b&&b<20){const t=B>0?k/B:0;B=C(B,b,k);const e=[...c],n=[...g];w=Array.isArray(w)?[...w]:[w];const i=[...w],s="reverse"===S||"mirror"===S;let o=e,a=i;s&&(o=[...e].reverse(),"reverse"===S&&(a=[...i].reverse().map(t=>{return"function"==typeof t?(e=t,t=>1-e(1-t)):t;var e})));for(let r=0;r0&&(c.push(c[c.length-1]),g.push(d),w.push("linear")),c.push(...h);for(let t=0;t{for(const s in t){const o=t[s];o.sort(z);const r=[],l=[],u=[];for(let t=0;t{n.push(...Q(i,t,e))}),new O(n)}});