motion 10.6.1 → 10.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,25 @@
2
2
 
3
3
  Motion One adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## [10.6.1] [2022-02-07]
5
+ ## [10.7.1] [2022-04-11]
6
+
7
+ ### Fixed
8
+
9
+ - Fixed `stagger` calculations with easings.
10
+
11
+ ## [10.7.0] [2022-03-20]
12
+
13
+ ### Added
14
+
15
+ - Added support for Motion Developer Tools.
16
+
17
+ ## [10.6.2] [2022-02-08]
18
+
19
+ ### Fixed
20
+
21
+ - Fixed velocity calculations of critically and overdamped animations.
22
+
23
+ ## [10.6.1] [2022-02-06]
6
24
 
7
25
  ### Fixed
8
26
 
package/README.md CHANGED
@@ -18,5 +18,6 @@ A huge thank you to all sponsors of this project, with a special shoutout to:
18
18
  - [Mihael Konjević](https://github.com/retro)
19
19
  - [impactvelocity](https://github.com/impactvelocity)
20
20
  - [Namit Chadha](https://github.com/nc)
21
+ - [Adam Snodgrass](https://twitter.com/overra)
21
22
 
22
23
  [Become a sponsor](https://github.com/sponsors/mattgperry) and get access to the private Motion One repo. File issues, read the changelog and source code, and join discussions that help shape the future of the API.
@@ -1 +1 @@
1
- !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";class e{setAnimation(t){this.animation=t,null==t||t.finished.then((()=>this.clearAnimation())).catch((()=>{}))}clearAnimation(){this.animation=this.generator=void 0}}const n=new WeakMap;function a(t){return n.has(t)||n.set(t,{transforms:[],values:new Map}),n.get(t)}function i(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const r={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},s=t=>"number"==typeof t,o=t=>"object"==typeof t&&Boolean(t.createAnimation),c=t=>Array.isArray(t)&&!s(t[0]),l=(t,e,n)=>-n*t+n*e+t,u=()=>{},h=t=>t,f=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function d(t,e){const n=t[t.length-1];for(let a=1;a<=e;a++){const i=f(0,e,a);t.push(l(n,1,i))}}function m(t){const e=[0];return d(e,t-1),e}const p=t=>1e3*t,y=t=>t/1e3;const g=["","X","Y","Z"],v={x:"translateX",y:"translateY",z:"translateZ"},b={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},M={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:b,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:h},skew:b},T=new Map,w=t=>`--motion-${t}`,x=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{g.forEach((e=>{x.push(t+e),T.set(w(t+e),M[t])}))}));const S=(t,e)=>x.indexOf(t)-x.indexOf(e),O=new Set(x),A=t=>O.has(t),j=t=>t.sort(S).reduce(k,"").trim(),k=(t,e)=>`${t} ${e}(var(${w(e)}))`,D=t=>t.startsWith("--"),P=new Set;const R=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function $(t,e,n,a){if(t===e&&n===a)return h;const i=e=>function(t,e,n,a,i){let r,s,o=0;do{s=e+(n-e)/2,r=R(s,a,i)-t,r>0?n=s:e=s}while(Math.abs(r)>1e-7&&++o<12);return s}(e,0,1,t,n);return t=>0===t||1===t?t:R(i(t),e,a)}const q=(t,e="end")=>n=>{const a=(n="end"===e?Math.min(n,.999):Math.max(n,.001))*t,i="end"===e?Math.floor(a):Math.ceil(a);return r=0,s=1,o=i/t,Math.min(Math.max(o,r),s);var r,s,o},E={ease:$(.25,.1,.25,1),"ease-in":$(.42,0,1,1),"ease-in-out":$(.42,0,.58,1),"ease-out":$(0,0,.58,1)},V=/\((.*?)\)/;function F(t){if("function"==typeof t)return t;if(Array.isArray(t))return $(...t);if(E[t])return E[t];if(t.startsWith("steps")){const e=V.exec(t);if(e){const t=e[1].split(",");return q(parseFloat(t[0]),t[1].trim())}}return h}function W(t,e){return c(t)?t[((t,e,n)=>{const a=e-t;return((n-t)%a+a)%a+t})(0,t.length,e)]:t}function U(t,e=m(t.length),n=h){const a=t.length,i=a-e.length;return i>0&&d(e,i),i=>{let r=0;for(;r<a-2&&!(i<e[r+1]);r++);let s=(o=f(e[r],e[r+1],i),Math.min(1,Math.max(o,0)));var o;return s=W(n,r)(s),l(t[r],t[r+1],s)}}class B{constructor(t,e=[0,1],{easing:n=r.easing,duration:a=r.duration,delay:i=r.delay,endDelay:s=r.endDelay,repeat:l=r.repeat,offset:u,direction:h="normal"}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e})),o(n)){const t=n.createAnimation(e,(()=>"0"),!0);n=t.easing,void 0!==t.keyframes&&(e=t.keyframes),void 0!==t.duration&&(a=t.duration)}const f=a*(l+1),d=U(e,u,c(n)?n.map(F):F(n));this.tick=e=>{var n;this.pauseTime&&(e=this.pauseTime);let r=(e-this.startTime)*this.rate;this.t=r,r/=1e3,r=Math.max(r-i,0),"finished"===this.playState&&(r=f);const o=r/a;let c=Math.floor(o),l=o%1;!l&&o>=1&&(l=1),1===l&&c--;const u=c%2;("reverse"===h||"alternate"===h&&u||"alternate-reverse"===h&&!u)&&(l=1-l);const m=d(r>=f?1:Math.min(l,1));t(m);"finished"===this.playState||r>=f+s?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,m)):"idle"!==this.playState&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){var t;const e=performance.now();this.playState="running",this.pauseTime?this.startTime=e-(this.pauseTime-(null!==(t=this.startTime)&&void 0!==t?t:0)):this.startTime||(this.startTime=e),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}stop(){var t;this.playState="idle",void 0!==this.frameRequestId&&cancelAnimationFrame(this.frameRequestId),null===(t=this.reject)||void 0===t||t.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}get currentTime(){return this.t}set currentTime(t){this.pauseTime||0===this.rate?this.pauseTime=t:this.startTime=performance.now()-t/this.rate}get playbackRate(){return this.rate}set playbackRate(t){this.rate=t}}const C=t=>(t=>Array.isArray(t)&&s(t[0]))(t)?I(t):t,I=([t,e,n,a])=>`cubic-bezier(${t}, ${e}, ${n}, ${a})`,z=t=>document.createElement("div").animate(t,{duration:.001}),K={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{z({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(z({opacity:[0,1]}).finished)},X={},Y={};for(const t in K)Y[t]=()=>(void 0===X[t]&&(X[t]=K[t]()),X[t]);const Z=t=>Array.isArray(t)?t:[t];function _(t){return v[t]&&(t=v[t]),A(t)?w(t):t}const G={get:(t,e)=>{e=_(e);let n=D(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=T.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=_(e),D(e)?t.style.setProperty(e,n):t.style[e]=n}};function H(t,e=!0){if(t&&"finished"!==t.playState)try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(t){}}function J(t,n,i,l={}){let h,{duration:f=r.duration,delay:d=r.delay,endDelay:m=r.endDelay,repeat:y=r.repeat,easing:g=r.easing,direction:b,offset:M,allowWebkitAcceleration:w=!1}=l;const x=a(t);let S=Y.waapi();const O=A(n);O&&((t,e)=>{v[e]&&(e=v[e]);const{transforms:n}=a(t);var i,r;r=e,-1===(i=n).indexOf(r)&&i.push(r),t.style.transform=j(n)})(t,n);const k=_(n),R=function(t,n){return t.has(n)||t.set(n,new e),t.get(n)}(x.values,k),$=T.get(k);return H(R.animation,!(o(g)&&R.generator)),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=G.get(t,k))&&void 0!==e?e:null==$?void 0:$.initialValue)&&void 0!==n?n:0};let n=function(t,e){for(let n=0;n<t.length;n++)null===t[n]&&(t[n]=n?t[n-1]:e());return t}(Z(i),e);if(o(g)){const t=g.createAnimation(n,e,O,k,R);g=t.easing,void 0!==t.keyframes&&(n=t.keyframes),void 0!==t.duration&&(f=t.duration)}if(D(k)&&(Y.cssRegisterProperty()?function(t){if(!P.has(t)){P.add(t);try{const{syntax:e,initialValue:n}=T.has(t)?T.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(k):S=!1),S){$&&(n=n.map((t=>s(t)?$.toDefaultUnit(t):t))),Y.partialKeyframes()||1!==n.length||n.unshift(e());const a={delay:p(d),duration:p(f),endDelay:p(m),easing:c(g)?void 0:C(g),direction:b,iterations:y+1,fill:"both"};h=t.animate({[k]:n,offset:M,easing:c(g)?g.map(C):void 0},a),h.finished||(h.finished=new Promise(((t,e)=>{h.onfinish=t,h.oncancel=e})));const i=n[n.length-1];h.finished.then((()=>{G.set(t,k,i),h.cancel()})).catch(u),w||(h.playbackRate=1.000001)}else if(O&&n.every(s)){1===n.length&&n.unshift(parseFloat(e()));h=new B((e=>{$&&(e=$.toDefaultUnit(e)),G.set(t,k,e)}),n,Object.assign(Object.assign({},l),{duration:f,easing:g}))}else{const e=n[n.length-1];G.set(t,k,$&&s(e)?$.toDefaultUnit(e):e)}return R.setAnimation(h),h}}const L=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function N(t,e){var n;return"string"==typeof t?e?(null!==(n=e[t])&&void 0!==n||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t)}const Q=t=>t(),tt=(t,e=r.duration)=>new Proxy({animations:t.map(Q).filter(Boolean),duration:e},nt),et=t=>t.animations[0],nt={get:(t,e)=>{var n,a;switch(e){case"duration":return t.duration;case"currentTime":let i=(null===(n=et(t))||void 0===n?void 0:n[e])||0;return i?i/1e3:0;case"playbackRate":return null===(a=et(t))||void 0===a?void 0:a[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(at)).catch(u)),t.finished;case"stop":return()=>t.animations.forEach((t=>H(t)));default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=p(n);case"currentTime":case"playbackRate":for(let a=0;a<t.animations.length;a++)t.animations[a][e]=n;return!0}return!1}},at=t=>t.finished;function it(t,e,n){return"function"==typeof t?t(e,n):t}function rt(t,e,n={}){const a=(t=N(t)).length,i=[];for(let r=0;r<a;r++){const s=t[r];for(const t in e){const o=L(n,t);o.delay=it(o.delay,r,a);const c=J(s,t,e[t],o);i.push(c)}}return tt(i,n.duration)}function st(t,e,n,a){var i;return s(e)?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(i=a.get(e))&&void 0!==i?i:t}function ot(t,e,n,a,r,s){!function(t,e,n){for(let a=0;a<t.length;a++){const r=t[a];r.at>e&&r.at<n&&(i(t,r),a--)}}(t,r,s);for(let i=0;i<e.length;i++)t.push({value:e[i],at:l(r,s,a[i]),easing:W(n,i)})}function ct(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function lt(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function ut(t,e){return e[t]||(e[t]=[]),e[t]}function ht(t,e,n){const a=Math.max(e-5,0);return i=n-t(a),(r=5)?i*(1e3/r):0;var i,r}const ft=100,dt=10,mt=1;const pt=({stiffness:t=ft,damping:e=dt,mass:n=mt,from:a=0,to:i=1,velocity:r=0,restSpeed:s=2,restDistance:o=.5}={})=>{r=r?y(r):0;const c={done:!1,hasReachedTarget:!1,current:a,target:i,velocity:r},l=((t=ft,e=dt,n=mt)=>e/(2*Math.sqrt(t*n)))(t,e,n),u=i-a,h=Math.sqrt(t/n)/1e3,f=((t,e)=>t*Math.sqrt(1-e*e))(h,l);let d;return d=l<1?t=>i-Math.exp(-l*h*t)*((l*h*u-r)/f*Math.sin(f*t)+u*Math.cos(f*t)):t=>i-Math.exp(-h*t)*(u+(r+h*u)*t),t=>{c.current=d(t),c.velocity=0===t?r:ht(d,t,c.current);const e=Math.abs(c.velocity)<=s,n=Math.abs(i-c.current)<=o;var l,u,h;return c.done=e&&n,c.hasReachedTarget=(l=a,u=i,h=c.current,l<u&&h>=u||l>u&&h<=u),c}};function yt(t){const e=new WeakMap;return(n={})=>{const a=new Map,i=(e=0,i=100,r=0,s=!1)=>{const o=`${e}-${i}-${r}-${s}`;return a.has(o)||a.set(o,t(Object.assign({from:e,to:i,velocity:r,restSpeed:s?.05:2,restDistance:s?.01:.5},n))),a.get(o)},r=t=>(e.has(t)||e.set(t,function(t){let e,n=10,a=t(0);const i=[a.current];for(;!a.done&&n<1e4;)a=t(n),i.push(a.done?a.target:a.current),void 0===e&&a.hasReachedTarget&&(e=n),n+=10;const r=n-10;return 1===i.length&&i.push(a.current),{keyframes:i,duration:r/1e3,overshootDuration:(null!=e?e:r)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,a,s)=>{let o,c;const l=t.length;if(n&&l<=2&&t.every(gt)){const n=function(t){if(!t)return;const{animation:e,generator:n,generatorStartTime:a}=t;if(!n)return;const i=(null==e?void 0:e.startTime)||a||0,r=(null==e?void 0:e.currentTime)||performance.now()-i;return n(r)}(s),u=n&&(1===l||2===l&&null===t[0])?n.velocity:0,h=t[l-1],f=1===l?null:t[0],d=null===f?n?n.current:parseFloat(e()):f;c=i(d,h,u,null==a?void 0:a.includes("scale"));const m=r(c);o=Object.assign(Object.assign({},m),{easing:"linear"}),s&&(s.generator=c,s.generatorStartTime=performance.now())}else{c=i(0,100);o={easing:"ease",duration:r(c).overshootDuration}}return o}}}}const gt=t=>"string"!=typeof t;const vt=yt(pt),bt=yt((({from:t=0,velocity:e=0,power:n=.8,decay:a=.325,bounceDamping:i,bounceStiffness:r,changeTarget:s,min:o,max:c,restDistance:l=.5,restSpeed:u})=>{a=p(a);const h={hasReachedTarget:!1,done:!1,current:t,target:t,velocity:e},f=t=>void 0===o?c:void 0===c||Math.abs(o-t)<Math.abs(c-t)?o:c;let d=n*e;const m=t+d,y=void 0===s?m:s(m);h.target=y,y!==m&&(d=y-t);const g=t=>-d*Math.exp(-t/a),v=t=>y+g(t),b=t=>{const n=g(t),a=v(t);h.done=Math.abs(n)<=l,h.current=h.done?y:a,h.velocity=0===t?e:ht(v,t,h.current)};let M,T;const w=t=>{var e;(e=h.current,void 0!==o&&e<o||void 0!==c&&e>c)&&(M=t,T=pt({from:h.current,to:f(h.current),velocity:h.velocity,damping:i,stiffness:r,restDistance:l,restSpeed:u}))};return w(0),t=>{let e=!1;return T||void 0!==M||(e=!0,b(t),w(t)),void 0!==M&&t>M?(h.hasReachedTarget=!0,T(t-M)):(h.hasReachedTarget=!1,!e&&b(t),h)}}));function Mt(t,e){return tt([()=>{const n=new B(t,[0,1],e);return n.finished.catch((()=>{})),n}],null==e?void 0:e.duration)}t.animate=function(t,e,n){return("function"==typeof t?Mt:rt)(t,e,n)},t.glide=bt,t.spring=vt,t.stagger=function(t=.1,{start:e=0,from:n=0,easing:a}={}){return(i,r)=>{const o=s(n)?n:function(t,e){if("first"===t)return 0;{const n=e-1;return"last"===t?n:n/2}}(n,r),c=Math.abs(o-i);let l=t*c;if(a){const t=r*i;l=F(a)(l/t)*t}return e+l}},t.style=G,t.timeline=function(t,e={}){var n;const a=function(t,e={}){var{defaultOptions:n={}}=e,a=function(t,e){var n={};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.indexOf(a)<0&&(n[a]=t[a]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(t);i<a.length;i++)e.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(t,a[i])&&(n[a[i]]=t[a[i]])}return n}(e,["defaultOptions"]);const i=[],s=new Map,c={},l=new Map;let u=0,h=0,p=0;for(let e=0;e<t.length;e++){const[a,i,f={}]=t[e];void 0!==f.at&&(h=st(h,f.at,u,l));let y=0;const g=N(a,c),v=g.length;for(let t=0;t<v;t++){const e=lt(g[t],s);for(const a in i){const s=ut(a,e);let c=Z(i[a]);const l=L(f,a);let{duration:u=n.duration||r.duration,easing:g=n.easing||r.easing}=l;if(o(g)){const t=A(a);c.length;const e=g.createAnimation(c,(()=>"0"),t);g=e.easing,void 0!==e.keyframes&&(c=e.keyframes),void 0!==e.duration&&(u=e.duration)}const b=it(f.delay,t,v)||0,M=h+b,T=M+u;let{offset:w=m(c.length)}=l;1===w.length&&0===w[0]&&(w[1]=1);const x=length-c.length;x>0&&d(w,x),1===c.length&&c.unshift(null),ot(s,c,g,w,M,T),y=Math.max(b+u,y),p=Math.max(T,p)}}u=h,h+=y}return s.forEach(((t,e)=>{for(const s in t){const o=t[s];o.sort(ct);const c=[],l=[],u=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:a}=o[t];c.push(n),l.push(f(0,p,e)),u.push(a||r.easing)}0!==l[0]&&(l.unshift(0),c.unshift(c[0]),u.unshift("linear")),1!==l[l.length-1]&&(l.push(1),c.push(null)),i.push([e,s,c,Object.assign(Object.assign(Object.assign({},n),{duration:p,easing:u,offset:l}),a)])}})),i}(t,e),i=a.map((t=>J(...t))).filter(Boolean);return tt(i,null===(n=a[0])||void 0===n?void 0:n[3].duration)},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !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";class e{setAnimation(t){this.animation=t,null==t||t.finished.then((()=>this.clearAnimation())).catch((()=>{}))}clearAnimation(){this.animation=this.generator=void 0}}const n=new WeakMap;function a(t){return n.has(t)||n.set(t,{transforms:[],values:new Map}),n.get(t)}function i(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const r={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},s=t=>"number"==typeof t,o=t=>"object"==typeof t&&Boolean(t.createAnimation),c=t=>Array.isArray(t)&&!s(t[0]),l=(t,e,n)=>-n*t+n*e+t,u=()=>{},h=t=>t,f=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function d(t,e){const n=t[t.length-1];for(let a=1;a<=e;a++){const i=f(0,e,a);t.push(l(n,1,i))}}function m(t){const e=[0];return d(e,t-1),e}const p=t=>1e3*t,g=t=>t/1e3;const y=["","X","Y","Z"],v={x:"translateX",y:"translateY",z:"translateZ"},b={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},M={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:b,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:h},skew:b},T=new Map,w=t=>`--motion-${t}`,O=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{y.forEach((e=>{O.push(t+e),T.set(w(t+e),M[t])}))}));const S=(t,e)=>O.indexOf(t)-O.indexOf(e),x=new Set(O),A=t=>x.has(t),j=t=>t.sort(S).reduce(k,"").trim(),k=(t,e)=>`${t} ${e}(var(${w(e)}))`,D=t=>t.startsWith("--"),R=new Set;const P=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function $(t,e,n,a){if(t===e&&n===a)return h;const i=e=>function(t,e,n,a,i){let r,s,o=0;do{s=e+(n-e)/2,r=P(s,a,i)-t,r>0?n=s:e=s}while(Math.abs(r)>1e-7&&++o<12);return s}(e,0,1,t,n);return t=>0===t||1===t?t:P(i(t),e,a)}const E=(t,e="end")=>n=>{const a=(n="end"===e?Math.min(n,.999):Math.max(n,.001))*t,i="end"===e?Math.floor(a):Math.ceil(a);return r=0,s=1,o=i/t,Math.min(Math.max(o,r),s);var r,s,o},q={ease:$(.25,.1,.25,1),"ease-in":$(.42,0,1,1),"ease-in-out":$(.42,0,.58,1),"ease-out":$(0,0,.58,1)},V=/\((.*?)\)/;function F(t){if("function"==typeof t)return t;if(Array.isArray(t))return $(...t);if(q[t])return q[t];if(t.startsWith("steps")){const e=V.exec(t);if(e){const t=e[1].split(",");return E(parseFloat(t[0]),t[1].trim())}}return h}function W(t,e){return c(t)?t[((t,e,n)=>{const a=e-t;return((n-t)%a+a)%a+t})(0,t.length,e)]:t}function _(t,e=m(t.length),n=h){const a=t.length,i=a-e.length;return i>0&&d(e,i),i=>{let r=0;for(;r<a-2&&!(i<e[r+1]);r++);let s=(o=f(e[r],e[r+1],i),Math.min(1,Math.max(o,0)));var o;return s=W(n,r)(s),l(t[r],t[r+1],s)}}class U{constructor(t,e=[0,1],{easing:n=r.easing,duration:a=r.duration,delay:i=r.delay,endDelay:s=r.endDelay,repeat:l=r.repeat,offset:u,direction:h="normal"}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e})),o(n)){const t=n.createAnimation(e,(()=>"0"),!0);n=t.easing,void 0!==t.keyframes&&(e=t.keyframes),void 0!==t.duration&&(a=t.duration)}const f=a*(l+1),d=_(e,u,c(n)?n.map(F):F(n));this.tick=e=>{var n;this.pauseTime&&(e=this.pauseTime);let r=(e-this.startTime)*this.rate;this.t=r,r/=1e3,r=Math.max(r-i,0),"finished"===this.playState&&(r=f);const o=r/a;let c=Math.floor(o),l=o%1;!l&&o>=1&&(l=1),1===l&&c--;const u=c%2;("reverse"===h||"alternate"===h&&u||"alternate-reverse"===h&&!u)&&(l=1-l);const m=d(r>=f?1:Math.min(l,1));t(m);"finished"===this.playState||r>=f+s?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,m)):"idle"!==this.playState&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){var t;const e=performance.now();this.playState="running",this.pauseTime?this.startTime=e-(this.pauseTime-(null!==(t=this.startTime)&&void 0!==t?t:0)):this.startTime||(this.startTime=e),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}stop(){var t;this.playState="idle",void 0!==this.frameRequestId&&cancelAnimationFrame(this.frameRequestId),null===(t=this.reject)||void 0===t||t.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}get currentTime(){return this.t}set currentTime(t){this.pauseTime||0===this.rate?this.pauseTime=t:this.startTime=performance.now()-t/this.rate}get playbackRate(){return this.rate}set playbackRate(t){this.rate=t}}const C=t=>(t=>Array.isArray(t)&&s(t[0]))(t)?I(t):t,I=([t,e,n,a])=>`cubic-bezier(${t}, ${e}, ${n}, ${a})`,B=t=>document.createElement("div").animate(t,{duration:.001}),z={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{B({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(B({opacity:[0,1]}).finished)},K={},X={};for(const t in z)X[t]=()=>(void 0===K[t]&&(K[t]=z[t]()),K[t]);const Y=t=>Array.isArray(t)?t:[t];function Z(t){return v[t]&&(t=v[t]),A(t)?w(t):t}const L={get:(t,e)=>{e=Z(e);let n=D(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=T.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=Z(e),D(e)?t.style.setProperty(e,n):t.style[e]=n}};function N(t,e=!0){if(t&&"finished"!==t.playState)try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(t){}}function G(t,n,i,l={}){const h=window.__MOTION_DEV_TOOLS_RECORD,f=!1!==l.record&&h;let d,{duration:m=r.duration,delay:g=r.delay,endDelay:y=r.endDelay,repeat:b=r.repeat,easing:M=r.easing,direction:w,offset:O,allowWebkitAcceleration:S=!1}=l;const x=a(t);let k=X.waapi();const P=A(n);P&&((t,e)=>{v[e]&&(e=v[e]);const{transforms:n}=a(t);var i,r;r=e,-1===(i=n).indexOf(r)&&i.push(r),t.style.transform=j(n)})(t,n);const $=Z(n),E=function(t,n){return t.has(n)||t.set(n,new e),t.get(n)}(x.values,$),q=T.get($);return N(E.animation,!(o(M)&&E.generator)&&!1!==l.record),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=L.get(t,$))&&void 0!==e?e:null==q?void 0:q.initialValue)&&void 0!==n?n:0};let a=function(t,e){for(let n=0;n<t.length;n++)null===t[n]&&(t[n]=n?t[n-1]:e());return t}(Y(i),e);if(o(M)){const t=M.createAnimation(a,e,P,$,E);M=t.easing,void 0!==t.keyframes&&(a=t.keyframes),void 0!==t.duration&&(m=t.duration)}if(D($)&&(X.cssRegisterProperty()?function(t){if(!R.has(t)){R.add(t);try{const{syntax:e,initialValue:n}=T.has(t)?T.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}($):k=!1),k){q&&(a=a.map((t=>s(t)?q.toDefaultUnit(t):t)));const n=!X.partialKeyframes()&&1===a.length;(f||n)&&a.unshift(e());const i={delay:p(g),duration:p(m),endDelay:p(y),easing:c(M)?void 0:C(M),direction:w,iterations:b+1,fill:"both"};d=t.animate({[$]:a,offset:O,easing:c(M)?M.map(C):void 0},i),d.finished||(d.finished=new Promise(((t,e)=>{d.onfinish=t,d.oncancel=e})));const r=a[a.length-1];d.finished.then((()=>{L.set(t,$,r),d.cancel()})).catch(u),S||(d.playbackRate=1.000001)}else if(P&&a.every(s)){1===a.length&&a.unshift(parseFloat(e()));d=new U((e=>{q&&(e=q.toDefaultUnit(e)),L.set(t,$,e)}),a,Object.assign(Object.assign({},l),{duration:m,easing:M}))}else{const e=a[a.length-1];L.set(t,$,q&&s(e)?q.toDefaultUnit(e):e)}return f&&h(t,n,a,{duration:m,delay:g,easing:M,repeat:b,offset:O},"motion-one"),E.setAnimation(d),d}}const H=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function J(t,e){var n;return"string"==typeof t?e?(null!==(n=e[t])&&void 0!==n||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t)}const Q=t=>t(),tt=(t,e=r.duration)=>new Proxy({animations:t.map(Q).filter(Boolean),duration:e},nt),et=t=>t.animations[0],nt={get:(t,e)=>{var n,a;switch(e){case"duration":return t.duration;case"currentTime":let i=(null===(n=et(t))||void 0===n?void 0:n[e])||0;return i?i/1e3:0;case"playbackRate":return null===(a=et(t))||void 0===a?void 0:a[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(at)).catch(u)),t.finished;case"stop":return()=>t.animations.forEach((t=>N(t)));default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=p(n);case"currentTime":case"playbackRate":for(let a=0;a<t.animations.length;a++)t.animations[a][e]=n;return!0}return!1}},at=t=>t.finished;function it(t,e,n){return"function"==typeof t?t(e,n):t}function rt(t,e,n={}){const a=(t=J(t)).length,i=[];for(let r=0;r<a;r++){const s=t[r];for(const t in e){const o=H(n,t);o.delay=it(o.delay,r,a);const c=G(s,t,e[t],o);i.push(c)}}return tt(i,n.duration)}function st(t,e,n,a){var i;return s(e)?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(i=a.get(e))&&void 0!==i?i:t}function ot(t,e,n,a,r,s){!function(t,e,n){for(let a=0;a<t.length;a++){const r=t[a];r.at>e&&r.at<n&&(i(t,r),a--)}}(t,r,s);for(let i=0;i<e.length;i++)t.push({value:e[i],at:l(r,s,a[i]),easing:W(n,i)})}function ct(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function lt(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function ut(t,e){return e[t]||(e[t]=[]),e[t]}function ht(t,e,n){const a=Math.max(e-5,0);return i=n-t(a),(r=e-a)?i*(1e3/r):0;var i,r}const ft=100,dt=10,mt=1;const pt=({stiffness:t=ft,damping:e=dt,mass:n=mt,from:a=0,to:i=1,velocity:r=0,restSpeed:s=2,restDistance:o=.5}={})=>{r=r?g(r):0;const c={done:!1,hasReachedTarget:!1,current:a,target:i},l=i-a,u=Math.sqrt(t/n)/1e3,h=((t=ft,e=dt,n=mt)=>e/(2*Math.sqrt(t*n)))(t,e,n);let f;if(h<1){const t=u*Math.sqrt(1-h*h);f=e=>i-Math.exp(-h*u*e)*((h*u*l-r)/t*Math.sin(t*e)+l*Math.cos(t*e))}else f=t=>i-Math.exp(-u*t)*(l+(u*l-r)*t);return t=>{c.current=f(t);const e=0===t?r:ht(f,t,c.current),n=Math.abs(e)<=s,l=Math.abs(i-c.current)<=o;var u,h,d;return c.done=n&&l,c.hasReachedTarget=(u=a,h=i,d=c.current,u<h&&d>=h||u>h&&d<=h),c}};function gt(t){const e=new WeakMap;return(n={})=>{const a=new Map,i=(e=0,i=100,r=0,s=!1)=>{const o=`${e}-${i}-${r}-${s}`;return a.has(o)||a.set(o,t(Object.assign({from:e,to:i,velocity:r,restSpeed:s?.05:2,restDistance:s?.01:.5},n))),a.get(o)},r=t=>(e.has(t)||e.set(t,function(t){let e,n=10,a=t(0);const i=[a.current];for(;!a.done&&n<1e4;)a=t(n),i.push(a.done?a.target:a.current),void 0===e&&a.hasReachedTarget&&(e=n),n+=10;const r=n-10;return 1===i.length&&i.push(a.current),{keyframes:i,duration:r/1e3,overshootDuration:(null!=e?e:r)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,a,s)=>{var o,c;let l;const u=t.length;if(n&&u<=2&&t.every(yt)){const n=t[u-1],h=1===u?null:t[0];let f=0,d=0;const m=null==s?void 0:s.generator;if(m){const{animation:e,generatorStartTime:n}=s,a=(null==e?void 0:e.startTime)||n||0,i=(null==e?void 0:e.currentTime)||performance.now()-a,r=m(i).current;d=null!==(o=h)&&void 0!==o?o:r,(1===u||2===u&&null===t[0])&&(f=ht((t=>m(t).current),i,r))}else d=null!==(c=h)&&void 0!==c?c:parseFloat(e());const p=i(d,n,f,null==a?void 0:a.includes("scale")),g=r(p);l=Object.assign(Object.assign({},g),{easing:"linear"}),s&&(s.generator=p,s.generatorStartTime=performance.now())}else{l={easing:"ease",duration:r(i(0,100)).overshootDuration}}return l}}}}const yt=t=>"string"!=typeof t,vt=gt(pt),bt=gt((({from:t=0,velocity:e=0,power:n=.8,decay:a=.325,bounceDamping:i,bounceStiffness:r,changeTarget:s,min:o,max:c,restDistance:l=.5,restSpeed:u})=>{a=p(a);const h={hasReachedTarget:!1,done:!1,current:t,target:t},f=t=>void 0===o?c:void 0===c||Math.abs(o-t)<Math.abs(c-t)?o:c;let d=n*e;const m=t+d,g=void 0===s?m:s(m);h.target=g,g!==m&&(d=g-t);const y=t=>-d*Math.exp(-t/a),v=t=>g+y(t),b=t=>{const e=y(t),n=v(t);h.done=Math.abs(e)<=l,h.current=h.done?g:n};let M,T;const w=t=>{var e;(e=h.current,void 0!==o&&e<o||void 0!==c&&e>c)&&(M=t,T=pt({from:h.current,to:f(h.current),velocity:ht(v,t,h.current),damping:i,stiffness:r,restDistance:l,restSpeed:u}))};return w(0),t=>{let e=!1;return T||void 0!==M||(e=!0,b(t),w(t)),void 0!==M&&t>M?(h.hasReachedTarget=!0,T(t-M)):(h.hasReachedTarget=!1,!e&&b(t),h)}}));function Mt(t,e){return tt([()=>{const n=new U(t,[0,1],e);return n.finished.catch((()=>{})),n}],null==e?void 0:e.duration)}t.animate=function(t,e,n){return("function"==typeof t?Mt:rt)(t,e,n)},t.glide=bt,t.spring=vt,t.stagger=function(t=.1,{start:e=0,from:n=0,easing:a}={}){return(i,r)=>{const o=s(n)?n:function(t,e){if("first"===t)return 0;{const n=e-1;return"last"===t?n:n/2}}(n,r),c=Math.abs(o-i);let l=t*c;if(a){const e=r*t;l=F(a)(l/e)*e}return e+l}},t.style=L,t.timeline=function(t,e={}){var n;const a=function(t,e={}){var{defaultOptions:n={}}=e,a=function(t,e){var n={};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.indexOf(a)<0&&(n[a]=t[a]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(t);i<a.length;i++)e.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(t,a[i])&&(n[a[i]]=t[a[i]])}return n}(e,["defaultOptions"]);const i=[],s=new Map,c={},l=new Map;let u=0,h=0,p=0;for(let e=0;e<t.length;e++){const[a,i,f={}]=t[e];void 0!==f.at&&(h=st(h,f.at,u,l));let g=0;const y=J(a,c),v=y.length;for(let t=0;t<v;t++){const e=lt(y[t],s);for(const a in i){const s=ut(a,e);let c=Y(i[a]);const l=H(f,a);let{duration:u=n.duration||r.duration,easing:y=n.easing||r.easing}=l;if(o(y)){const t=A(a);c.length;const e=y.createAnimation(c,(()=>"0"),t);y=e.easing,void 0!==e.keyframes&&(c=e.keyframes),void 0!==e.duration&&(u=e.duration)}const b=it(f.delay,t,v)||0,M=h+b,T=M+u;let{offset:w=m(c.length)}=l;1===w.length&&0===w[0]&&(w[1]=1);const O=length-c.length;O>0&&d(w,O),1===c.length&&c.unshift(null),ot(s,c,y,w,M,T),g=Math.max(b+u,g),p=Math.max(T,p)}}u=h,h+=g}return s.forEach(((t,e)=>{for(const s in t){const o=t[s];o.sort(ct);const c=[],l=[],u=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:a}=o[t];c.push(n),l.push(f(0,p,e)),u.push(a||r.easing)}0!==l[0]&&(l.unshift(0),c.unshift(c[0]),u.unshift("linear")),1!==l[l.length-1]&&(l.push(1),c.push(null)),i.push([e,s,c,Object.assign(Object.assign(Object.assign({},n),{duration:p,easing:u,offset:l}),a)])}})),i}(t,e),i=a.map((t=>G(...t))).filter(Boolean);return tt(i,null===(n=a[0])||void 0===n?void 0:n[3].duration)},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -539,7 +539,12 @@
539
539
  catch (e) { }
540
540
  }
541
541
 
542
+ function getDevToolsRecord() {
543
+ return window.__MOTION_DEV_TOOLS_RECORD;
544
+ }
542
545
  function animateStyle(element, key, keyframesDefinition, options = {}) {
546
+ const record = getDevToolsRecord();
547
+ const isRecording = options.record !== false && record;
543
548
  let animation;
544
549
  let { duration = defaults$1.duration, delay = defaults$1.delay, endDelay = defaults$1.endDelay, repeat = defaults$1.repeat, easing = defaults$1.easing, direction, offset, allowWebkitAcceleration = false, } = options;
545
550
  const data = getAnimationData(element);
@@ -563,7 +568,8 @@
563
568
  * this is fired now and we return a factory function to create
564
569
  * the actual animation that can get called in batch,
565
570
  */
566
- stopAnimation(motionValue.animation, !(isEasingGenerator(easing) && motionValue.generator));
571
+ stopAnimation(motionValue.animation, !(isEasingGenerator(easing) && motionValue.generator) &&
572
+ options.record !== false);
567
573
  /**
568
574
  * Batchable factory function containing all DOM reads.
569
575
  */
@@ -611,7 +617,8 @@
611
617
  * If this browser doesn't support partial/implicit keyframes we need to
612
618
  * explicitly provide one.
613
619
  */
614
- if (!supports.partialKeyframes() && keyframes.length === 1) {
620
+ const needsToReadInitialKeyframe = !supports.partialKeyframes() && keyframes.length === 1;
621
+ if (isRecording || needsToReadInitialKeyframe) {
615
622
  keyframes.unshift(readInitialValue());
616
623
  }
617
624
  const animationOptions = {
@@ -684,6 +691,15 @@
684
691
  ? definition.toDefaultUnit(target)
685
692
  : target);
686
693
  }
694
+ if (isRecording) {
695
+ record(element, key, keyframes, {
696
+ duration,
697
+ delay,
698
+ easing,
699
+ repeat,
700
+ offset,
701
+ }, "motion-one");
702
+ }
687
703
  motionValue.setAnimation(animation);
688
704
  return animation;
689
705
  };
@@ -769,7 +785,7 @@
769
785
  const distance = Math.abs(fromIndex - i);
770
786
  let delay = duration * distance;
771
787
  if (easing) {
772
- const maxDelay = total * i;
788
+ const maxDelay = total * duration;
773
789
  const easingFunction = getEasingFunction(easing);
774
790
  delay = easingFunction(delay / maxDelay) * maxDelay;
775
791
  }
@@ -1077,7 +1093,7 @@
1077
1093
  const sampleT = 5; // ms
1078
1094
  function calcGeneratorVelocity(resolveValue, t, current) {
1079
1095
  const prevT = Math.max(t - sampleT, 0);
1080
- return velocityPerSecond(current - resolveValue(prevT), 5);
1096
+ return velocityPerSecond(current - resolveValue(prevT), t - prevT);
1081
1097
  }
1082
1098
 
1083
1099
  const defaults = {
@@ -1087,7 +1103,6 @@
1087
1103
  };
1088
1104
 
1089
1105
  const calcDampingRatio = (stiffness = defaults.stiffness, damping = defaults.damping, mass = defaults.mass) => damping / (2 * Math.sqrt(stiffness * mass));
1090
- const calcAngularFreq = (undampedFreq, dampingRatio) => undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
1091
1106
 
1092
1107
  function hasReachedTarget(origin, target, current) {
1093
1108
  return ((origin < target && current >= target) ||
@@ -1101,14 +1116,13 @@
1101
1116
  hasReachedTarget: false,
1102
1117
  current: from,
1103
1118
  target: to,
1104
- velocity,
1105
1119
  };
1106
- const dampingRatio = calcDampingRatio(stiffness, damping, mass);
1107
1120
  const initialDelta = to - from;
1108
1121
  const undampedAngularFreq = Math.sqrt(stiffness / mass) / 1000;
1109
- const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
1122
+ const dampingRatio = calcDampingRatio(stiffness, damping, mass);
1110
1123
  let resolveSpring;
1111
1124
  if (dampingRatio < 1) {
1125
+ const angularFreq = undampedAngularFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
1112
1126
  // Underdamped spring (bouncy)
1113
1127
  resolveSpring = (t) => to -
1114
1128
  Math.exp(-dampingRatio * undampedAngularFreq * t) *
@@ -1119,17 +1133,18 @@
1119
1133
  }
1120
1134
  else {
1121
1135
  // Critically damped spring
1122
- resolveSpring = (t) => to -
1123
- Math.exp(-undampedAngularFreq * t) *
1124
- (initialDelta + (velocity + undampedAngularFreq * initialDelta) * t);
1136
+ resolveSpring = (t) => {
1137
+ return (to -
1138
+ Math.exp(-undampedAngularFreq * t) *
1139
+ (initialDelta + (-velocity + undampedAngularFreq * initialDelta) * t));
1140
+ };
1125
1141
  }
1126
1142
  return (t) => {
1127
1143
  state.current = resolveSpring(t);
1128
- state.velocity =
1129
- t === 0
1130
- ? velocity
1131
- : calcGeneratorVelocity(resolveSpring, t, state.current);
1132
- const isBelowVelocityThreshold = Math.abs(state.velocity) <= restSpeed;
1144
+ const currentVelocity = t === 0
1145
+ ? velocity
1146
+ : calcGeneratorVelocity(resolveSpring, t, state.current);
1147
+ const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
1133
1148
  const isBelowDisplacementThreshold = Math.abs(to - state.current) <= restDistance;
1134
1149
  state.done = isBelowVelocityThreshold && isBelowDisplacementThreshold;
1135
1150
  state.hasReachedTarget = hasReachedTarget(from, to, state.current);
@@ -1144,7 +1159,6 @@
1144
1159
  done: false,
1145
1160
  current: from,
1146
1161
  target: from,
1147
- velocity,
1148
1162
  };
1149
1163
  const isOutOfBounds = (v) => (min !== undefined && v < min) || (max !== undefined && v > max);
1150
1164
  const nearestBoundary = (v) => {
@@ -1171,8 +1185,6 @@
1171
1185
  const latest = calcLatest(t);
1172
1186
  state.done = Math.abs(delta) <= restDistance;
1173
1187
  state.current = state.done ? target : latest;
1174
- state.velocity =
1175
- t === 0 ? velocity : calcGeneratorVelocity(calcLatest, t, state.current);
1176
1188
  };
1177
1189
  /**
1178
1190
  * Ideally this would resolve for t in a stateless way, we could
@@ -1189,7 +1201,7 @@
1189
1201
  spring$1$1 = spring$1({
1190
1202
  from: state.current,
1191
1203
  to: nearestBoundary(state.current),
1192
- velocity: state.velocity,
1204
+ velocity: calcGeneratorVelocity(calcLatest, t, state.current),
1193
1205
  damping: bounceDamping,
1194
1206
  stiffness: bounceStiffness,
1195
1207
  restDistance,
@@ -1276,27 +1288,37 @@
1276
1288
  };
1277
1289
  return {
1278
1290
  createAnimation: (keyframes, getOrigin, canUseGenerator, name, motionValue) => {
1291
+ var _a, _b;
1279
1292
  let settings;
1280
- let generator;
1281
1293
  const numKeyframes = keyframes.length;
1282
1294
  let shouldUseGenerator = canUseGenerator &&
1283
1295
  numKeyframes <= 2 &&
1284
1296
  keyframes.every(isNumberOrNull);
1285
1297
  if (shouldUseGenerator) {
1286
- const prevMotionState = getPrevMotionState(motionValue);
1287
- const velocity = prevMotionState &&
1288
- (numKeyframes === 1 ||
1289
- (numKeyframes === 2 && keyframes[0] === null))
1290
- ? prevMotionState.velocity
1291
- : 0;
1292
1298
  const target = keyframes[numKeyframes - 1];
1293
1299
  const unresolvedOrigin = numKeyframes === 1 ? null : keyframes[0];
1294
- const origin = unresolvedOrigin === null
1295
- ? prevMotionState
1296
- ? prevMotionState.current
1297
- : parseFloat(getOrigin())
1298
- : unresolvedOrigin;
1299
- generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
1300
+ let velocity = 0;
1301
+ let origin = 0;
1302
+ const prevGenerator = motionValue === null || motionValue === void 0 ? void 0 : motionValue.generator;
1303
+ if (prevGenerator) {
1304
+ /**
1305
+ * If we have a generator for this value we can use it to resolve
1306
+ * the animations's current value and velocity.
1307
+ */
1308
+ const { animation, generatorStartTime } = motionValue;
1309
+ const startTime = (animation === null || animation === void 0 ? void 0 : animation.startTime) || generatorStartTime || 0;
1310
+ const currentTime = (animation === null || animation === void 0 ? void 0 : animation.currentTime) || performance.now() - startTime;
1311
+ const prevGeneratorCurrent = prevGenerator(currentTime).current;
1312
+ origin = (_a = unresolvedOrigin) !== null && _a !== void 0 ? _a : prevGeneratorCurrent;
1313
+ if (numKeyframes === 1 ||
1314
+ (numKeyframes === 2 && keyframes[0] === null)) {
1315
+ velocity = calcGeneratorVelocity((t) => prevGenerator(t).current, currentTime, prevGeneratorCurrent);
1316
+ }
1317
+ }
1318
+ else {
1319
+ origin = (_b = unresolvedOrigin) !== null && _b !== void 0 ? _b : parseFloat(getOrigin());
1320
+ }
1321
+ const generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
1300
1322
  const keyframesMetadata = getKeyframes(generator);
1301
1323
  settings = Object.assign(Object.assign({}, keyframesMetadata), { easing: "linear" });
1302
1324
  // TODO Add test for this
@@ -1306,8 +1328,7 @@
1306
1328
  }
1307
1329
  }
1308
1330
  else {
1309
- generator = getGenerator(0, 100);
1310
- const keyframesMetadata = getKeyframes(generator);
1331
+ const keyframesMetadata = getKeyframes(getGenerator(0, 100));
1311
1332
  settings = {
1312
1333
  easing: "ease",
1313
1334
  duration: keyframesMetadata.overshootDuration,
@@ -1319,16 +1340,6 @@
1319
1340
  };
1320
1341
  }
1321
1342
  const isNumberOrNull = (value) => typeof value !== "string";
1322
- function getPrevMotionState(motionValue) {
1323
- if (!motionValue)
1324
- return;
1325
- const { animation, generator, generatorStartTime } = motionValue;
1326
- if (!generator)
1327
- return;
1328
- const startTime = (animation === null || animation === void 0 ? void 0 : animation.startTime) || generatorStartTime || 0;
1329
- const currentTime = (animation === null || animation === void 0 ? void 0 : animation.currentTime) || performance.now() - startTime;
1330
- return generator(currentTime);
1331
- }
1332
1343
 
1333
1344
  const spring = createGeneratorEasing(spring$1);
1334
1345
 
@@ -1 +1 @@
1
- class t{setAnimation(t){this.animation=t,null==t||t.finished.then((()=>this.clearAnimation())).catch((()=>{}))}clearAnimation(){this.animation=this.generator=void 0}}const e=new WeakMap;function n(t){return e.has(t)||e.set(t,{transforms:[],values:new Map}),e.get(t)}function a(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const i={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},r=t=>"number"==typeof t,s=t=>"object"==typeof t&&Boolean(t.createAnimation),o=t=>Array.isArray(t)&&!r(t[0]),c=(t,e,n)=>-n*t+n*e+t,l=()=>{},u=t=>t,h=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function f(t,e){const n=t[t.length-1];for(let a=1;a<=e;a++){const i=h(0,e,a);t.push(c(n,1,i))}}function d(t){const e=[0];return f(e,t-1),e}const m=t=>1e3*t,p=t=>t/1e3;const y=["","X","Y","Z"],g={x:"translateX",y:"translateY",z:"translateZ"},v={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},b={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:v,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:u},skew:v},w=new Map,M=t=>`--motion-${t}`,T=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{y.forEach((e=>{T.push(t+e),w.set(M(t+e),b[t])}))}));const S=(t,e)=>T.indexOf(t)-T.indexOf(e),O=new Set(T),x=t=>O.has(t),A=t=>t.sort(S).reduce(k,"").trim(),k=(t,e)=>`${t} ${e}(var(${M(e)}))`,j=t=>t.startsWith("--"),D=new Set;const R=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function P(t,e,n,a){if(t===e&&n===a)return u;const i=e=>function(t,e,n,a,i){let r,s,o=0;do{s=e+(n-e)/2,r=R(s,a,i)-t,r>0?n=s:e=s}while(Math.abs(r)>1e-7&&++o<12);return s}(e,0,1,t,n);return t=>0===t||1===t?t:R(i(t),e,a)}const E=(t,e="end")=>n=>{const a=(n="end"===e?Math.min(n,.999):Math.max(n,.001))*t,i="end"===e?Math.floor(a):Math.ceil(a);return r=0,s=1,o=i/t,Math.min(Math.max(o,r),s);var r,s,o},$={ease:P(.25,.1,.25,1),"ease-in":P(.42,0,1,1),"ease-in-out":P(.42,0,.58,1),"ease-out":P(0,0,.58,1)},q=/\((.*?)\)/;function V(t){if("function"==typeof t)return t;if(Array.isArray(t))return P(...t);if($[t])return $[t];if(t.startsWith("steps")){const e=q.exec(t);if(e){const t=e[1].split(",");return E(parseFloat(t[0]),t[1].trim())}}return u}function F(t,e){return o(t)?t[((t,e,n)=>{const a=e-t;return((n-t)%a+a)%a+t})(0,t.length,e)]:t}function W(t,e=d(t.length),n=u){const a=t.length,i=a-e.length;return i>0&&f(e,i),i=>{let r=0;for(;r<a-2&&!(i<e[r+1]);r++);let s=(o=h(e[r],e[r+1],i),Math.min(1,Math.max(o,0)));var o;return s=F(n,r)(s),c(t[r],t[r+1],s)}}class U{constructor(t,e=[0,1],{easing:n=i.easing,duration:a=i.duration,delay:r=i.delay,endDelay:c=i.endDelay,repeat:l=i.repeat,offset:u,direction:h="normal"}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e})),s(n)){const t=n.createAnimation(e,(()=>"0"),!0);n=t.easing,void 0!==t.keyframes&&(e=t.keyframes),void 0!==t.duration&&(a=t.duration)}const f=a*(l+1),d=W(e,u,o(n)?n.map(V):V(n));this.tick=e=>{var n;this.pauseTime&&(e=this.pauseTime);let i=(e-this.startTime)*this.rate;this.t=i,i/=1e3,i=Math.max(i-r,0),"finished"===this.playState&&(i=f);const s=i/a;let o=Math.floor(s),l=s%1;!l&&s>=1&&(l=1),1===l&&o--;const u=o%2;("reverse"===h||"alternate"===h&&u||"alternate-reverse"===h&&!u)&&(l=1-l);const m=d(i>=f?1:Math.min(l,1));t(m);"finished"===this.playState||i>=f+c?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,m)):"idle"!==this.playState&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){var t;const e=performance.now();this.playState="running",this.pauseTime?this.startTime=e-(this.pauseTime-(null!==(t=this.startTime)&&void 0!==t?t:0)):this.startTime||(this.startTime=e),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}stop(){var t;this.playState="idle",void 0!==this.frameRequestId&&cancelAnimationFrame(this.frameRequestId),null===(t=this.reject)||void 0===t||t.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}get currentTime(){return this.t}set currentTime(t){this.pauseTime||0===this.rate?this.pauseTime=t:this.startTime=performance.now()-t/this.rate}get playbackRate(){return this.rate}set playbackRate(t){this.rate=t}}const B=t=>(t=>Array.isArray(t)&&r(t[0]))(t)?C(t):t,C=([t,e,n,a])=>`cubic-bezier(${t}, ${e}, ${n}, ${a})`,I=t=>document.createElement("div").animate(t,{duration:.001}),z={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{I({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(I({opacity:[0,1]}).finished)},K={},N={};for(const t in z)N[t]=()=>(void 0===K[t]&&(K[t]=z[t]()),K[t]);const X=t=>Array.isArray(t)?t:[t];function Y(t){return g[t]&&(t=g[t]),x(t)?M(t):t}const Z={get:(t,e)=>{e=Y(e);let n=j(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=w.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=Y(e),j(e)?t.style.setProperty(e,n):t.style[e]=n}};function _(t,e=!0){if(t&&"finished"!==t.playState)try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(t){}}function G(e,a,c,u={}){let h,{duration:f=i.duration,delay:d=i.delay,endDelay:p=i.endDelay,repeat:y=i.repeat,easing:v=i.easing,direction:b,offset:M,allowWebkitAcceleration:T=!1}=u;const S=n(e);let O=N.waapi();const k=x(a);k&&((t,e)=>{g[e]&&(e=g[e]);const{transforms:a}=n(t);var i,r;r=e,-1===(i=a).indexOf(r)&&i.push(r),t.style.transform=A(a)})(e,a);const R=Y(a),P=function(e,n){return e.has(n)||e.set(n,new t),e.get(n)}(S.values,R),E=w.get(R);return _(P.animation,!(s(v)&&P.generator)),()=>{const t=()=>{var t,n;return null!==(n=null!==(t=Z.get(e,R))&&void 0!==t?t:null==E?void 0:E.initialValue)&&void 0!==n?n:0};let n=function(t,e){for(let n=0;n<t.length;n++)null===t[n]&&(t[n]=n?t[n-1]:e());return t}(X(c),t);if(s(v)){const e=v.createAnimation(n,t,k,R,P);v=e.easing,void 0!==e.keyframes&&(n=e.keyframes),void 0!==e.duration&&(f=e.duration)}if(j(R)&&(N.cssRegisterProperty()?function(t){if(!D.has(t)){D.add(t);try{const{syntax:e,initialValue:n}=w.has(t)?w.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(R):O=!1),O){E&&(n=n.map((t=>r(t)?E.toDefaultUnit(t):t))),N.partialKeyframes()||1!==n.length||n.unshift(t());const a={delay:m(d),duration:m(f),endDelay:m(p),easing:o(v)?void 0:B(v),direction:b,iterations:y+1,fill:"both"};h=e.animate({[R]:n,offset:M,easing:o(v)?v.map(B):void 0},a),h.finished||(h.finished=new Promise(((t,e)=>{h.onfinish=t,h.oncancel=e})));const i=n[n.length-1];h.finished.then((()=>{Z.set(e,R,i),h.cancel()})).catch(l),T||(h.playbackRate=1.000001)}else if(k&&n.every(r)){1===n.length&&n.unshift(parseFloat(t()));h=new U((t=>{E&&(t=E.toDefaultUnit(t)),Z.set(e,R,t)}),n,Object.assign(Object.assign({},u),{duration:f,easing:v}))}else{const t=n[n.length-1];Z.set(e,R,E&&r(t)?E.toDefaultUnit(t):t)}return P.setAnimation(h),h}}const H=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function J(t,e){var n;return"string"==typeof t?e?(null!==(n=e[t])&&void 0!==n||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t)}const L=t=>t(),Q=(t,e=i.duration)=>new Proxy({animations:t.map(L).filter(Boolean),duration:e},et),tt=t=>t.animations[0],et={get:(t,e)=>{var n,a;switch(e){case"duration":return t.duration;case"currentTime":let i=(null===(n=tt(t))||void 0===n?void 0:n[e])||0;return i?i/1e3:0;case"playbackRate":return null===(a=tt(t))||void 0===a?void 0:a[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(nt)).catch(l)),t.finished;case"stop":return()=>t.animations.forEach((t=>_(t)));default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=m(n);case"currentTime":case"playbackRate":for(let a=0;a<t.animations.length;a++)t.animations[a][e]=n;return!0}return!1}},nt=t=>t.finished;function at(t=.1,{start:e=0,from:n=0,easing:a}={}){return(i,s)=>{const o=r(n)?n:function(t,e){if("first"===t)return 0;{const n=e-1;return"last"===t?n:n/2}}(n,s),c=Math.abs(o-i);let l=t*c;if(a){const t=s*i;l=V(a)(l/t)*t}return e+l}}function it(t,e,n){return"function"==typeof t?t(e,n):t}function rt(t,e,n={}){const a=(t=J(t)).length,i=[];for(let r=0;r<a;r++){const s=t[r];for(const t in e){const o=H(n,t);o.delay=it(o.delay,r,a);const c=G(s,t,e[t],o);i.push(c)}}return Q(i,n.duration)}var st=function(){};function ot(t,e,n,a){var i;return r(e)?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(i=a.get(e))&&void 0!==i?i:t}function ct(t,e,n,i,r,s){!function(t,e,n){for(let i=0;i<t.length;i++){const r=t[i];r.at>e&&r.at<n&&(a(t,r),i--)}}(t,r,s);for(let a=0;a<e.length;a++)t.push({value:e[a],at:c(r,s,i[a]),easing:F(n,a)})}function lt(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function ut(t,e={}){var n;const a=function(t,e={}){var{defaultOptions:n={}}=e,a=function(t,e){var n={};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.indexOf(a)<0&&(n[a]=t[a]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(t);i<a.length;i++)e.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(t,a[i])&&(n[a[i]]=t[a[i]])}return n}(e,["defaultOptions"]);const r=[],o=new Map,c={},l=new Map;let u=0,m=0,p=0;for(let e=0;e<t.length;e++){const[a,r,h={}]=t[e];void 0!==h.at&&(m=ot(m,h.at,u,l));let y=0;const g=J(a,c),v=g.length;for(let t=0;t<v;t++){const e=ht(g[t],o);for(const a in r){const o=ft(a,e);let c=X(r[a]);const l=H(h,a);let{duration:u=n.duration||i.duration,easing:g=n.easing||i.easing}=l;if(s(g)){const t=x(a);st(2===c.length||!t,"spring must be provided 2 keyframes within timeline");const e=g.createAnimation(c,(()=>"0"),t);g=e.easing,void 0!==e.keyframes&&(c=e.keyframes),void 0!==e.duration&&(u=e.duration)}const b=it(h.delay,t,v)||0,w=m+b,M=w+u;let{offset:T=d(c.length)}=l;1===T.length&&0===T[0]&&(T[1]=1);const S=length-c.length;S>0&&f(T,S),1===c.length&&c.unshift(null),ct(o,c,g,T,w,M),y=Math.max(b+u,y),p=Math.max(M,p)}}u=m,m+=y}return o.forEach(((t,e)=>{for(const s in t){const o=t[s];o.sort(lt);const c=[],l=[],u=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:a}=o[t];c.push(n),l.push(h(0,p,e)),u.push(a||i.easing)}0!==l[0]&&(l.unshift(0),c.unshift(c[0]),u.unshift("linear")),1!==l[l.length-1]&&(l.push(1),c.push(null)),r.push([e,s,c,Object.assign(Object.assign(Object.assign({},n),{duration:p,easing:u,offset:l}),a)])}})),r}(t,e),r=a.map((t=>G(...t))).filter(Boolean);return Q(r,null===(n=a[0])||void 0===n?void 0:n[3].duration)}function ht(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function ft(t,e){return e[t]||(e[t]=[]),e[t]}"production"!==process.env.NODE_ENV&&(st=function(t,e){if(!t)throw new Error(e)});function dt(t,e,n){const a=Math.max(e-5,0);return i=n-t(a),(r=5)?i*(1e3/r):0;var i,r}const mt=100,pt=10,yt=1;const gt=({stiffness:t=mt,damping:e=pt,mass:n=yt,from:a=0,to:i=1,velocity:r=0,restSpeed:s=2,restDistance:o=.5}={})=>{r=r?p(r):0;const c={done:!1,hasReachedTarget:!1,current:a,target:i,velocity:r},l=((t=mt,e=pt,n=yt)=>e/(2*Math.sqrt(t*n)))(t,e,n),u=i-a,h=Math.sqrt(t/n)/1e3,f=((t,e)=>t*Math.sqrt(1-e*e))(h,l);let d;return d=l<1?t=>i-Math.exp(-l*h*t)*((l*h*u-r)/f*Math.sin(f*t)+u*Math.cos(f*t)):t=>i-Math.exp(-h*t)*(u+(r+h*u)*t),t=>{c.current=d(t),c.velocity=0===t?r:dt(d,t,c.current);const e=Math.abs(c.velocity)<=s,n=Math.abs(i-c.current)<=o;var l,u,h;return c.done=e&&n,c.hasReachedTarget=(l=a,u=i,h=c.current,l<u&&h>=u||l>u&&h<=u),c}};function vt(t){const e=new WeakMap;return(n={})=>{const a=new Map,i=(e=0,i=100,r=0,s=!1)=>{const o=`${e}-${i}-${r}-${s}`;return a.has(o)||a.set(o,t(Object.assign({from:e,to:i,velocity:r,restSpeed:s?.05:2,restDistance:s?.01:.5},n))),a.get(o)},r=t=>(e.has(t)||e.set(t,function(t){let e,n=10,a=t(0);const i=[a.current];for(;!a.done&&n<1e4;)a=t(n),i.push(a.done?a.target:a.current),void 0===e&&a.hasReachedTarget&&(e=n),n+=10;const r=n-10;return 1===i.length&&i.push(a.current),{keyframes:i,duration:r/1e3,overshootDuration:(null!=e?e:r)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,a,s)=>{let o,c;const l=t.length;if(n&&l<=2&&t.every(bt)){const n=function(t){if(!t)return;const{animation:e,generator:n,generatorStartTime:a}=t;if(!n)return;const i=(null==e?void 0:e.startTime)||a||0,r=(null==e?void 0:e.currentTime)||performance.now()-i;return n(r)}(s),u=n&&(1===l||2===l&&null===t[0])?n.velocity:0,h=t[l-1],f=1===l?null:t[0],d=null===f?n?n.current:parseFloat(e()):f;c=i(d,h,u,null==a?void 0:a.includes("scale"));const m=r(c);o=Object.assign(Object.assign({},m),{easing:"linear"}),s&&(s.generator=c,s.generatorStartTime=performance.now())}else{c=i(0,100);o={easing:"ease",duration:r(c).overshootDuration}}return o}}}}const bt=t=>"string"!=typeof t;const wt=vt(gt),Mt=vt((({from:t=0,velocity:e=0,power:n=.8,decay:a=.325,bounceDamping:i,bounceStiffness:r,changeTarget:s,min:o,max:c,restDistance:l=.5,restSpeed:u})=>{a=m(a);const h={hasReachedTarget:!1,done:!1,current:t,target:t,velocity:e},f=t=>void 0===o?c:void 0===c||Math.abs(o-t)<Math.abs(c-t)?o:c;let d=n*e;const p=t+d,y=void 0===s?p:s(p);h.target=y,y!==p&&(d=y-t);const g=t=>-d*Math.exp(-t/a),v=t=>y+g(t),b=t=>{const n=g(t),a=v(t);h.done=Math.abs(n)<=l,h.current=h.done?y:a,h.velocity=0===t?e:dt(v,t,h.current)};let w,M;const T=t=>{var e;(e=h.current,void 0!==o&&e<o||void 0!==c&&e>c)&&(w=t,M=gt({from:h.current,to:f(h.current),velocity:h.velocity,damping:i,stiffness:r,restDistance:l,restSpeed:u}))};return T(0),t=>{let e=!1;return M||void 0!==w||(e=!0,b(t),T(t)),void 0!==w&&t>w?(h.hasReachedTarget=!0,M(t-w)):(h.hasReachedTarget=!1,!e&&b(t),h)}}));function Tt(t,e){return Q([()=>{const n=new U(t,[0,1],e);return n.finished.catch((()=>{})),n}],null==e?void 0:e.duration)}function St(t,e,n){return("function"==typeof t?Tt:rt)(t,e,n)}export{St as animate,Mt as glide,wt as spring,at as stagger,Z as style,ut as timeline};
1
+ class t{setAnimation(t){this.animation=t,null==t||t.finished.then((()=>this.clearAnimation())).catch((()=>{}))}clearAnimation(){this.animation=this.generator=void 0}}const e=new WeakMap;function n(t){return e.has(t)||e.set(t,{transforms:[],values:new Map}),e.get(t)}function a(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const i={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},r=t=>"number"==typeof t,s=t=>"object"==typeof t&&Boolean(t.createAnimation),o=t=>Array.isArray(t)&&!r(t[0]),c=(t,e,n)=>-n*t+n*e+t,l=()=>{},u=t=>t,h=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function f(t,e){const n=t[t.length-1];for(let a=1;a<=e;a++){const i=h(0,e,a);t.push(c(n,1,i))}}function d(t){const e=[0];return f(e,t-1),e}const m=t=>1e3*t,p=t=>t/1e3;const g=["","X","Y","Z"],y={x:"translateX",y:"translateY",z:"translateZ"},v={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},b={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:v,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:u},skew:v},w=new Map,M=t=>`--motion-${t}`,T=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{g.forEach((e=>{T.push(t+e),w.set(M(t+e),b[t])}))}));const O=(t,e)=>T.indexOf(t)-T.indexOf(e),S=new Set(T),x=t=>S.has(t),A=t=>t.sort(O).reduce(k,"").trim(),k=(t,e)=>`${t} ${e}(var(${M(e)}))`,D=t=>t.startsWith("--"),j=new Set;const R=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function P(t,e,n,a){if(t===e&&n===a)return u;const i=e=>function(t,e,n,a,i){let r,s,o=0;do{s=e+(n-e)/2,r=R(s,a,i)-t,r>0?n=s:e=s}while(Math.abs(r)>1e-7&&++o<12);return s}(e,0,1,t,n);return t=>0===t||1===t?t:R(i(t),e,a)}const E=(t,e="end")=>n=>{const a=(n="end"===e?Math.min(n,.999):Math.max(n,.001))*t,i="end"===e?Math.floor(a):Math.ceil(a);return r=0,s=1,o=i/t,Math.min(Math.max(o,r),s);var r,s,o},$={ease:P(.25,.1,.25,1),"ease-in":P(.42,0,1,1),"ease-in-out":P(.42,0,.58,1),"ease-out":P(0,0,.58,1)},q=/\((.*?)\)/;function V(t){if("function"==typeof t)return t;if(Array.isArray(t))return P(...t);if($[t])return $[t];if(t.startsWith("steps")){const e=q.exec(t);if(e){const t=e[1].split(",");return E(parseFloat(t[0]),t[1].trim())}}return u}function F(t,e){return o(t)?t[((t,e,n)=>{const a=e-t;return((n-t)%a+a)%a+t})(0,t.length,e)]:t}function W(t,e=d(t.length),n=u){const a=t.length,i=a-e.length;return i>0&&f(e,i),i=>{let r=0;for(;r<a-2&&!(i<e[r+1]);r++);let s=(o=h(e[r],e[r+1],i),Math.min(1,Math.max(o,0)));var o;return s=F(n,r)(s),c(t[r],t[r+1],s)}}class U{constructor(t,e=[0,1],{easing:n=i.easing,duration:a=i.duration,delay:r=i.delay,endDelay:c=i.endDelay,repeat:l=i.repeat,offset:u,direction:h="normal"}={}){if(this.startTime=null,this.rate=1,this.t=0,this.cancelTimestamp=null,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e})),s(n)){const t=n.createAnimation(e,(()=>"0"),!0);n=t.easing,void 0!==t.keyframes&&(e=t.keyframes),void 0!==t.duration&&(a=t.duration)}const f=a*(l+1),d=W(e,u,o(n)?n.map(V):V(n));this.tick=e=>{var n;this.pauseTime&&(e=this.pauseTime);let i=(e-this.startTime)*this.rate;this.t=i,i/=1e3,i=Math.max(i-r,0),"finished"===this.playState&&(i=f);const s=i/a;let o=Math.floor(s),l=s%1;!l&&s>=1&&(l=1),1===l&&o--;const u=o%2;("reverse"===h||"alternate"===h&&u||"alternate-reverse"===h&&!u)&&(l=1-l);const m=d(i>=f?1:Math.min(l,1));t(m);"finished"===this.playState||i>=f+c?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,m)):"idle"!==this.playState&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){var t;const e=performance.now();this.playState="running",this.pauseTime?this.startTime=e-(this.pauseTime-(null!==(t=this.startTime)&&void 0!==t?t:0)):this.startTime||(this.startTime=e),this.cancelTimestamp=this.startTime,this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}stop(){var t;this.playState="idle",void 0!==this.frameRequestId&&cancelAnimationFrame(this.frameRequestId),null===(t=this.reject)||void 0===t||t.call(this,!1)}cancel(){this.stop(),this.tick(this.cancelTimestamp)}reverse(){this.rate*=-1}commitStyles(){}get currentTime(){return this.t}set currentTime(t){this.pauseTime||0===this.rate?this.pauseTime=t:this.startTime=performance.now()-t/this.rate}get playbackRate(){return this.rate}set playbackRate(t){this.rate=t}}const _=t=>(t=>Array.isArray(t)&&r(t[0]))(t)?C(t):t,C=([t,e,n,a])=>`cubic-bezier(${t}, ${e}, ${n}, ${a})`,I=t=>document.createElement("div").animate(t,{duration:.001}),B={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{I({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(I({opacity:[0,1]}).finished)},z={},N={};for(const t in B)N[t]=()=>(void 0===z[t]&&(z[t]=B[t]()),z[t]);const K=t=>Array.isArray(t)?t:[t];function X(t){return y[t]&&(t=y[t]),x(t)?M(t):t}const Y={get:(t,e)=>{e=X(e);let n=D(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=w.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=X(e),D(e)?t.style.setProperty(e,n):t.style[e]=n}};function Z(t,e=!0){if(t&&"finished"!==t.playState)try{t.stop?t.stop():(e&&t.commitStyles(),t.cancel())}catch(t){}}function L(e,a,c,u={}){const h=window.__MOTION_DEV_TOOLS_RECORD,f=!1!==u.record&&h;let d,{duration:p=i.duration,delay:g=i.delay,endDelay:v=i.endDelay,repeat:b=i.repeat,easing:M=i.easing,direction:T,offset:O,allowWebkitAcceleration:S=!1}=u;const k=n(e);let R=N.waapi();const P=x(a);P&&((t,e)=>{y[e]&&(e=y[e]);const{transforms:a}=n(t);var i,r;r=e,-1===(i=a).indexOf(r)&&i.push(r),t.style.transform=A(a)})(e,a);const E=X(a),$=function(e,n){return e.has(n)||e.set(n,new t),e.get(n)}(k.values,E),q=w.get(E);return Z($.animation,!(s(M)&&$.generator)&&!1!==u.record),()=>{const t=()=>{var t,n;return null!==(n=null!==(t=Y.get(e,E))&&void 0!==t?t:null==q?void 0:q.initialValue)&&void 0!==n?n:0};let n=function(t,e){for(let n=0;n<t.length;n++)null===t[n]&&(t[n]=n?t[n-1]:e());return t}(K(c),t);if(s(M)){const e=M.createAnimation(n,t,P,E,$);M=e.easing,void 0!==e.keyframes&&(n=e.keyframes),void 0!==e.duration&&(p=e.duration)}if(D(E)&&(N.cssRegisterProperty()?function(t){if(!j.has(t)){j.add(t);try{const{syntax:e,initialValue:n}=w.has(t)?w.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(E):R=!1),R){q&&(n=n.map((t=>r(t)?q.toDefaultUnit(t):t)));const a=!N.partialKeyframes()&&1===n.length;(f||a)&&n.unshift(t());const i={delay:m(g),duration:m(p),endDelay:m(v),easing:o(M)?void 0:_(M),direction:T,iterations:b+1,fill:"both"};d=e.animate({[E]:n,offset:O,easing:o(M)?M.map(_):void 0},i),d.finished||(d.finished=new Promise(((t,e)=>{d.onfinish=t,d.oncancel=e})));const s=n[n.length-1];d.finished.then((()=>{Y.set(e,E,s),d.cancel()})).catch(l),S||(d.playbackRate=1.000001)}else if(P&&n.every(r)){1===n.length&&n.unshift(parseFloat(t()));d=new U((t=>{q&&(t=q.toDefaultUnit(t)),Y.set(e,E,t)}),n,Object.assign(Object.assign({},u),{duration:p,easing:M}))}else{const t=n[n.length-1];Y.set(e,E,q&&r(t)?q.toDefaultUnit(t):t)}return f&&h(e,a,n,{duration:p,delay:g,easing:M,repeat:b,offset:O},"motion-one"),$.setAnimation(d),d}}const G=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function H(t,e){var n;return"string"==typeof t?e?(null!==(n=e[t])&&void 0!==n||(e[t]=document.querySelectorAll(t)),t=e[t]):t=document.querySelectorAll(t):t instanceof Element&&(t=[t]),Array.from(t)}const J=t=>t(),Q=(t,e=i.duration)=>new Proxy({animations:t.map(J).filter(Boolean),duration:e},et),tt=t=>t.animations[0],et={get:(t,e)=>{var n,a;switch(e){case"duration":return t.duration;case"currentTime":let i=(null===(n=tt(t))||void 0===n?void 0:n[e])||0;return i?i/1e3:0;case"playbackRate":return null===(a=tt(t))||void 0===a?void 0:a[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(nt)).catch(l)),t.finished;case"stop":return()=>t.animations.forEach((t=>Z(t)));default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=m(n);case"currentTime":case"playbackRate":for(let a=0;a<t.animations.length;a++)t.animations[a][e]=n;return!0}return!1}},nt=t=>t.finished;function at(t=.1,{start:e=0,from:n=0,easing:a}={}){return(i,s)=>{const o=r(n)?n:function(t,e){if("first"===t)return 0;{const n=e-1;return"last"===t?n:n/2}}(n,s),c=Math.abs(o-i);let l=t*c;if(a){const e=s*t;l=V(a)(l/e)*e}return e+l}}function it(t,e,n){return"function"==typeof t?t(e,n):t}function rt(t,e,n={}){const a=(t=H(t)).length,i=[];for(let r=0;r<a;r++){const s=t[r];for(const t in e){const o=G(n,t);o.delay=it(o.delay,r,a);const c=L(s,t,e[t],o);i.push(c)}}return Q(i,n.duration)}var st=function(){};function ot(t,e,n,a){var i;return r(e)?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(i=a.get(e))&&void 0!==i?i:t}function ct(t,e,n,i,r,s){!function(t,e,n){for(let i=0;i<t.length;i++){const r=t[i];r.at>e&&r.at<n&&(a(t,r),i--)}}(t,r,s);for(let a=0;a<e.length;a++)t.push({value:e[a],at:c(r,s,i[a]),easing:F(n,a)})}function lt(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function ut(t,e={}){var n;const a=function(t,e={}){var{defaultOptions:n={}}=e,a=function(t,e){var n={};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.indexOf(a)<0&&(n[a]=t[a]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(t);i<a.length;i++)e.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(t,a[i])&&(n[a[i]]=t[a[i]])}return n}(e,["defaultOptions"]);const r=[],o=new Map,c={},l=new Map;let u=0,m=0,p=0;for(let e=0;e<t.length;e++){const[a,r,h={}]=t[e];void 0!==h.at&&(m=ot(m,h.at,u,l));let g=0;const y=H(a,c),v=y.length;for(let t=0;t<v;t++){const e=ht(y[t],o);for(const a in r){const o=ft(a,e);let c=K(r[a]);const l=G(h,a);let{duration:u=n.duration||i.duration,easing:y=n.easing||i.easing}=l;if(s(y)){const t=x(a);st(2===c.length||!t,"spring must be provided 2 keyframes within timeline");const e=y.createAnimation(c,(()=>"0"),t);y=e.easing,void 0!==e.keyframes&&(c=e.keyframes),void 0!==e.duration&&(u=e.duration)}const b=it(h.delay,t,v)||0,w=m+b,M=w+u;let{offset:T=d(c.length)}=l;1===T.length&&0===T[0]&&(T[1]=1);const O=length-c.length;O>0&&f(T,O),1===c.length&&c.unshift(null),ct(o,c,y,T,w,M),g=Math.max(b+u,g),p=Math.max(M,p)}}u=m,m+=g}return o.forEach(((t,e)=>{for(const s in t){const o=t[s];o.sort(lt);const c=[],l=[],u=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:a}=o[t];c.push(n),l.push(h(0,p,e)),u.push(a||i.easing)}0!==l[0]&&(l.unshift(0),c.unshift(c[0]),u.unshift("linear")),1!==l[l.length-1]&&(l.push(1),c.push(null)),r.push([e,s,c,Object.assign(Object.assign(Object.assign({},n),{duration:p,easing:u,offset:l}),a)])}})),r}(t,e),r=a.map((t=>L(...t))).filter(Boolean);return Q(r,null===(n=a[0])||void 0===n?void 0:n[3].duration)}function ht(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function ft(t,e){return e[t]||(e[t]=[]),e[t]}"production"!==process.env.NODE_ENV&&(st=function(t,e){if(!t)throw new Error(e)});function dt(t,e,n){const a=Math.max(e-5,0);return i=n-t(a),(r=e-a)?i*(1e3/r):0;var i,r}const mt=100,pt=10,gt=1;const yt=({stiffness:t=mt,damping:e=pt,mass:n=gt,from:a=0,to:i=1,velocity:r=0,restSpeed:s=2,restDistance:o=.5}={})=>{r=r?p(r):0;const c={done:!1,hasReachedTarget:!1,current:a,target:i},l=i-a,u=Math.sqrt(t/n)/1e3,h=((t=mt,e=pt,n=gt)=>e/(2*Math.sqrt(t*n)))(t,e,n);let f;if(h<1){const t=u*Math.sqrt(1-h*h);f=e=>i-Math.exp(-h*u*e)*((h*u*l-r)/t*Math.sin(t*e)+l*Math.cos(t*e))}else f=t=>i-Math.exp(-u*t)*(l+(u*l-r)*t);return t=>{c.current=f(t);const e=0===t?r:dt(f,t,c.current),n=Math.abs(e)<=s,l=Math.abs(i-c.current)<=o;var u,h,d;return c.done=n&&l,c.hasReachedTarget=(u=a,h=i,d=c.current,u<h&&d>=h||u>h&&d<=h),c}};function vt(t){const e=new WeakMap;return(n={})=>{const a=new Map,i=(e=0,i=100,r=0,s=!1)=>{const o=`${e}-${i}-${r}-${s}`;return a.has(o)||a.set(o,t(Object.assign({from:e,to:i,velocity:r,restSpeed:s?.05:2,restDistance:s?.01:.5},n))),a.get(o)},r=t=>(e.has(t)||e.set(t,function(t){let e,n=10,a=t(0);const i=[a.current];for(;!a.done&&n<1e4;)a=t(n),i.push(a.done?a.target:a.current),void 0===e&&a.hasReachedTarget&&(e=n),n+=10;const r=n-10;return 1===i.length&&i.push(a.current),{keyframes:i,duration:r/1e3,overshootDuration:(null!=e?e:r)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,a,s)=>{var o,c;let l;const u=t.length;if(n&&u<=2&&t.every(bt)){const n=t[u-1],h=1===u?null:t[0];let f=0,d=0;const m=null==s?void 0:s.generator;if(m){const{animation:e,generatorStartTime:n}=s,a=(null==e?void 0:e.startTime)||n||0,i=(null==e?void 0:e.currentTime)||performance.now()-a,r=m(i).current;d=null!==(o=h)&&void 0!==o?o:r,(1===u||2===u&&null===t[0])&&(f=dt((t=>m(t).current),i,r))}else d=null!==(c=h)&&void 0!==c?c:parseFloat(e());const p=i(d,n,f,null==a?void 0:a.includes("scale")),g=r(p);l=Object.assign(Object.assign({},g),{easing:"linear"}),s&&(s.generator=p,s.generatorStartTime=performance.now())}else{l={easing:"ease",duration:r(i(0,100)).overshootDuration}}return l}}}}const bt=t=>"string"!=typeof t,wt=vt(yt),Mt=vt((({from:t=0,velocity:e=0,power:n=.8,decay:a=.325,bounceDamping:i,bounceStiffness:r,changeTarget:s,min:o,max:c,restDistance:l=.5,restSpeed:u})=>{a=m(a);const h={hasReachedTarget:!1,done:!1,current:t,target:t},f=t=>void 0===o?c:void 0===c||Math.abs(o-t)<Math.abs(c-t)?o:c;let d=n*e;const p=t+d,g=void 0===s?p:s(p);h.target=g,g!==p&&(d=g-t);const y=t=>-d*Math.exp(-t/a),v=t=>g+y(t),b=t=>{const e=y(t),n=v(t);h.done=Math.abs(e)<=l,h.current=h.done?g:n};let w,M;const T=t=>{var e;(e=h.current,void 0!==o&&e<o||void 0!==c&&e>c)&&(w=t,M=yt({from:h.current,to:f(h.current),velocity:dt(v,t,h.current),damping:i,stiffness:r,restDistance:l,restSpeed:u}))};return T(0),t=>{let e=!1;return M||void 0!==w||(e=!0,b(t),T(t)),void 0!==w&&t>w?(h.hasReachedTarget=!0,M(t-w)):(h.hasReachedTarget=!1,!e&&b(t),h)}}));function Tt(t,e){return Q([()=>{const n=new U(t,[0,1],e);return n.finished.catch((()=>{})),n}],null==e?void 0:e.duration)}function Ot(t,e,n){return("function"==typeof t?Tt:rt)(t,e,n)}export{Ot as animate,Mt as glide,wt as spring,at as stagger,Y as style,ut as timeline};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "motion",
3
3
  "description": "A tiny, performant animation library for the web",
4
- "version": "10.6.1",
4
+ "version": "10.7.1",
5
5
  "license": "MIT",
6
6
  "author": "Matt Perry",
7
7
  "main": "dist/main.cjs.js",
@@ -20,14 +20,14 @@
20
20
  "scripts": {
21
21
  "build": "rm -rf lib dist types && tsc -p . && rollup -c",
22
22
  "test": "jest --coverage --config jest.config.js",
23
- "dev": "rollup -c -w"
23
+ "dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --c --watch --no-watch.clearScreen\""
24
24
  },
25
25
  "dependencies": {
26
- "@motionone/animation": "^10.6.1",
27
- "@motionone/dom": "^10.6.1",
28
- "@motionone/react": "^10.6.1",
29
- "@motionone/svelte": "^10.6.1",
30
- "@motionone/vue": "^10.6.1"
26
+ "@motionone/animation": "^10.7.0",
27
+ "@motionone/dom": "^10.7.1",
28
+ "@motionone/react": "^10.7.1",
29
+ "@motionone/svelte": "^10.7.1",
30
+ "@motionone/vue": "^10.7.1"
31
31
  },
32
- "gitHead": "2d0605d1e1903b47ad20c6338588362371a3b6e5"
32
+ "gitHead": "9a1936a0b6f9242295ab51f180b86fbfc5c3c47d"
33
33
  }