motion 10.5.1 → 10.6.0-rc.4

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,6 +2,18 @@
2
2
 
3
3
  Motion One adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [10.6.0] [2022-01-22]
6
+
7
+ ### Added
8
+
9
+ - Custom animations by passing function to `animate`.
10
+
11
+ ## [10.5.2] [2022-01-16]
12
+
13
+ ### Fixed
14
+
15
+ - Fixing types for `Presence`. [Issue (sponsors only)](https://github.com/motiondivision/motionone/issues/44)
16
+
5
17
  ## [10.5.1] [2022-01-15]
6
18
 
7
19
  ### Fixed
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var dom = require('@motionone/dom');
6
+ var animation = require('@motionone/animation');
7
+
8
+ function animateProgress(target, options) {
9
+ return dom.wrapAnimationWithControls([
10
+ () => {
11
+ const animation$1 = new animation.Animation(target, [0, 1], options);
12
+ animation$1.finished.catch(() => { });
13
+ return animation$1;
14
+ },
15
+ ], options === null || options === void 0 ? void 0 : options.duration);
16
+ }
17
+ function animate(target, keyframesOrOptions, options) {
18
+ const animationFunction = typeof target === "function" ? animateProgress : dom.animate;
19
+ return animationFunction(target, keyframesOrOptions, options);
20
+ }
21
+
22
+ exports.animate = animate;
23
+ exports.animateProgress = animateProgress;
@@ -0,0 +1,18 @@
1
+ import { animate as animate$1, wrapAnimationWithControls } from '@motionone/dom';
2
+ import { Animation } from '@motionone/animation';
3
+
4
+ function animateProgress(target, options) {
5
+ return wrapAnimationWithControls([
6
+ () => {
7
+ const animation = new Animation(target, [0, 1], options);
8
+ animation.finished.catch(() => { });
9
+ return animation;
10
+ },
11
+ ], options === null || options === void 0 ? void 0 : options.duration);
12
+ }
13
+ function animate(target, keyframesOrOptions, options) {
14
+ const animationFunction = typeof target === "function" ? animateProgress : animate$1;
15
+ return animationFunction(target, keyframesOrOptions, options);
16
+ }
17
+
18
+ export { animate, animateProgress };
package/dist/main.cjs.js CHANGED
@@ -3,12 +3,28 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var dom = require('@motionone/dom');
6
+ var animate = require('./animate.cjs.js');
6
7
 
7
8
 
8
9
 
9
- Object.keys(dom).forEach(function (k) {
10
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
11
- enumerable: true,
12
- get: function () { return dom[k]; }
13
- });
10
+ Object.defineProperty(exports, 'glide', {
11
+ enumerable: true,
12
+ get: function () { return dom.glide; }
14
13
  });
14
+ Object.defineProperty(exports, 'spring', {
15
+ enumerable: true,
16
+ get: function () { return dom.spring; }
17
+ });
18
+ Object.defineProperty(exports, 'stagger', {
19
+ enumerable: true,
20
+ get: function () { return dom.stagger; }
21
+ });
22
+ Object.defineProperty(exports, 'style', {
23
+ enumerable: true,
24
+ get: function () { return dom.style; }
25
+ });
26
+ Object.defineProperty(exports, 'timeline', {
27
+ enumerable: true,
28
+ get: function () { return dom.timeline; }
29
+ });
30
+ exports.animate = animate.animate;
package/dist/main.es.js CHANGED
@@ -1 +1,2 @@
1
- export * from '@motionone/dom';
1
+ export { glide, spring, stagger, style, timeline } from '@motionone/dom';
2
+ export { animate } from './animate.es.js';
@@ -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";const e=new WeakMap;function n(t){return e.has(t)||e.set(t,{transforms:[],animations:{},generators:{},prevGeneratorState:{}}),e.get(t)}function i(t,e){-1===t.indexOf(e)&&t.push(e)}function a(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const s=()=>{},r=t=>t,o=["","X","Y","Z"],c={x:"translateX",y:"translateY",z:"translateZ"},l={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},u={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:l,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:r},skew:l},f=new Map,h=t=>`--motion-${t}`,d=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{o.forEach((e=>{d.push(t+e),f.set(h(t+e),u[t])}))}));const p=(t,e)=>d.indexOf(t)-d.indexOf(e),m=new Set(d),v=t=>m.has(t),g=t=>t.sort(p).reduce(y,"").trim(),y=(t,e)=>`${t} ${e}(var(${h(e)}))`,b=t=>t.startsWith("--"),w=new Set;const x=t=>1e3*t,M=t=>"number"==typeof t,S=t=>Array.isArray(t)&&!M(t[0]),O=t=>"object"==typeof t&&Boolean(t.createAnimation),T=t=>(t=>Array.isArray(t)&&M(t[0]))(t)?A(t):t,A=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,E=t=>document.createElement("div").animate(t,{duration:.001}),j={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{E({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(E({opacity:[0,1]}).finished)},D={},k={};for(const t in j)k[t]=()=>(void 0===D[t]&&(D[t]=j[t]()),D[t]);const P={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},$=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function R(t,e,n,i){if(t===e&&n===i)return r;const a=e=>function(t,e,n,i,a){let s,r,o=0;do{r=e+(n-e)/2,s=$(r,i,a)-t,s>0?n=r:e=r}while(Math.abs(s)>1e-7&&++o<12);return r}(e,0,1,t,n);return t=>0===t||1===t?t:$(a(t),e,i)}const C=(t,e="end")=>n=>{const i=(n="end"===e?Math.min(n,.999):Math.max(n,.001))*t,a="end"===e?Math.floor(i):Math.ceil(i);return s=0,r=1,o=a/t,Math.min(Math.max(o,s),r);var s,r,o},L={ease:R(.25,.1,.25,1),"ease-in":R(.42,0,1,1),"ease-in-out":R(.42,0,.58,1),"ease-out":R(0,0,.58,1)},V=/\((.*?)\)/;function B(t){if("function"==typeof t)return t;if(Array.isArray(t))return R(...t);if(L[t])return L[t];if(t.startsWith("steps")){const e=V.exec(t);if(e){const t=e[1].split(",");return C(parseFloat(t[0]),t[1].trim())}}return r}const U=(t,e,n)=>-n*t+n*e+t,W=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function q(t,e){return S(t)?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t}function F(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const a=W(0,e,i);t.push(U(n,1,a))}}function I(t){const e=[0];return F(e,t-1),e}function z(t,e=I(t.length),n=r){const i=t.length,a=i-e.length;return a>0&&F(e,a),a=>{let s=0;for(;s<i-2&&!(a<e[s+1]);s++);let r=(o=W(e[s],e[s+1],a),Math.min(1,Math.max(o,0)));var o;return r=q(n,s)(r),U(t[s],t[s+1],r)}}class G{constructor(t,e=[0,1],{easing:n=P.easing,duration:i=P.duration,delay:a=P.delay,endDelay:s=P.endDelay,repeat:r=P.repeat,offset:o,direction:c="normal"}={}){this.startTime=0,this.rate=1,this.t=0,this.cancelTimestamp=0,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e}));const l=i*(r+1);O(n)&&(n="ease");const u=z(e,o,S(n)?n.map(B):B(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-a,0),"finished"===this.playState&&(r=l);const o=r/i;let f=Math.floor(o),h=o%1;!h&&o>=1&&(h=1),1===h&&f--;const d=f%2;("reverse"===c||"alternate"===c&&d||"alternate-reverse"===c&&!d)&&(h=1-h);const p=u(r>=l?1:Math.min(h,1));t(p);"finished"===this.playState||r>=l+s?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,p)):"idle"!==this.playState&&requestAnimationFrame(this.tick)},this.play()}play(){const t=performance.now();this.playState="running",this.pauseTime?this.startTime=t-(this.pauseTime-this.startTime):this.startTime||(this.startTime=t),this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}cancel(){var t;this.playState="idle",this.tick(this.cancelTimestamp),null===(t=this.reject)||void 0===t||t.call(this,!1)}reverse(){this.rate*=-1}commitStyles(){this.cancelTimestamp=performance.now()}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 Z=t=>Array.isArray(t)?t:[t];function K(t){return c[t]&&(t=c[t]),v(t)?h(t):t}const X={get:(t,e)=>{e=K(e);let n=b(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=f.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=K(e),b(e)?t.style.setProperty(e,n):t.style[e]=n}};function Y(t){if(t)try{"finished"!==t.playState&&t.commitStyles(),t.cancel()}catch(t){}}function _(t,e,a,r={}){let o,{duration:l=P.duration,delay:u=P.delay,endDelay:h=P.endDelay,repeat:d=P.repeat,easing:p=P.easing,direction:m,offset:y,allowWebkitAcceleration:A=!1}=r;const E=n(t);let j=k.waapi();const D=v(e);D&&((t,e)=>{c[e]&&(e=c[e]);const{transforms:a}=n(t);i(a,e),t.style.transform=g(a)})(t,e);const $=K(e),R=f.get($);return Y(E.animations[$]),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=X.get(t,$))&&void 0!==e?e:null==R?void 0:R.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(a),e);if(O(p)){const t=p.createAnimation(n,e,D,$,E);p=t.easing,void 0!==t.keyframes&&(n=t.keyframes),void 0!==t.duration&&(l=t.duration)}if(b($)&&(k.cssRegisterProperty()?function(t){if(!w.has(t)){w.add(t);try{const{syntax:e,initialValue:n}=f.has(t)?f.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}($):j=!1),j){R&&(n=n.map((t=>M(t)?R.toDefaultUnit(t):t))),k.partialKeyframes()||1!==n.length||n.unshift(e());const i={delay:x(u),duration:x(l),endDelay:x(h),easing:S(p)?void 0:T(p),direction:m,iterations:d+1,fill:"both"};o=t.animate({[$]:n,offset:y,easing:S(p)?p.map(T):void 0},i),o.finished||(o.finished=new Promise(((t,e)=>{o.onfinish=t,o.oncancel=e})));const a=n[n.length-1];o.finished.then((()=>{X.set(t,$,a),o.cancel()})).catch(s),A||(o.playbackRate=1.000001)}else if(D&&n.every(M)){1===n.length&&n.unshift(parseFloat(e()));o=new G((e=>{R&&(e=R.toDefaultUnit(e)),X.set(t,$,e)}),n,Object.assign(Object.assign({},r),{duration:l,easing:p}))}else{const e=n[n.length-1];X.set(t,$,R&&M(e)?R.toDefaultUnit(e):e)}return E.animations[$]=o,null==o||o.finished.then((()=>{E.animations[$]=void 0,E.generators[$]=void 0,E.prevGeneratorState[$]=void 0})).catch(s),o}}const N=(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)=>new Proxy({animations:t.map(J).filter(Boolean),duration:e},et),tt=t=>t.animations[0],et={get:(t,e)=>{var n,i;switch(e){case"duration":return t.duration;case"currentTime":let a=(null===(n=tt(t))||void 0===n?void 0:n[e])||0;return a?a/1e3:0;case"playbackRate":return null===(i=tt(t))||void 0===i?void 0:i[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(nt)).catch(s)),t.finished;case"stop":return()=>t.animations.forEach(Y);default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=x(n);case"currentTime":case"playbackRate":for(let i=0;i<t.animations.length;i++)t.animations[i][e]=n;return!0}return!1}},nt=t=>t.finished;function it(t,e,n){return"function"==typeof t?t(e,n):t}function at(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(t);a<i.length;a++)e.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(t,i[a])&&(n[i[a]]=t[i[a]])}return n}function st(t,e,n,i){var a;return M(e)?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(a=i.get(e))&&void 0!==a?a:t}function rt(t,e,n,i,s,r){!function(t,e,n){for(let i=0;i<t.length;i++){const s=t[i];s.at>e&&s.at<n&&(a(t,s),i--)}}(t,s,r);for(let a=0;a<e.length;a++)t.push({value:e[a],at:U(s,r,i[a]),easing:q(n,a)})}function ot(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function ct(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function lt(t,e){return e[t]||(e[t]=[]),e[t]}const ut=({stiffness:t=100,damping:e=10,mass:n=1,from:i=0,to:a=1,velocity:s=0,restSpeed:r=2,restDistance:o=.5}={})=>{const c={done:!1,value:i,target:a,velocity:s=s?s/1e3:0,hasReachedTarget:!1},l=((t=100,e=10,n=1)=>e/(2*Math.sqrt(t*n)))(t,e,n),u=a-i,f=Math.sqrt(t/n)/1e3,h=((t,e)=>t*Math.sqrt(1-e*e))(f,l);let d;return d=l<1?t=>a-Math.exp(-l*f*t)*((l*f*u-s)/h*Math.sin(h*t)+u*Math.cos(h*t)):t=>a-Math.exp(-f*t)*(u+(s+f*u)*t),{next:t=>{c.value=d(t),c.velocity=0===t?s:ft(d,t,c.value);const e=Math.abs(c.velocity)<=r,n=Math.abs(a-c.value)<=o;var l,u,f;return c.done=e&&n,c.hasReachedTarget=(l=i,u=a,f=c.value,l<u&&f>=u||l>u&&f<=u),c}}};function ft(t,e,n){const i=Math.max(e-5,0);return a=n-t(i),(s=5)?a*(1e3/s):0;var a,s}function ht(t){const e=new WeakMap;return(n={})=>{const i=new Map,a=(e=0,a=100,s=0,r=!1)=>{const o=`${e}-${a}-${s}-${r}`;return i.has(o)||i.set(o,t(Object.assign({from:e,to:a,velocity:s,restSpeed:r?.05:2,restDistance:r?.01:.5},n))),i.get(o)},s=t=>(e.has(t)||e.set(t,function(t){let e,n=10,i=t.next(0);const a=[i.value];for(;!i.done&&n<1e4;)i=t.next(n),a.push(i.done?i.target:i.value),void 0===e&&i.hasReachedTarget&&(e=n),n+=10;const s=n-10;return 1===a.length&&a.push(i.value),{keyframes:a,duration:s/1e3,overshootDuration:(null!=e?e:s)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,i,r)=>{let o,c;const l=t.length;if(n&&l<=2&&t.every(dt)){const n=i&&r&&r.prevGeneratorState[i],u=n&&(1===l||2===l&&null===t[0])?n.velocity:0,f=t[l-1],h=1===l?null:t[0],d=null===h?n?n.value:parseFloat(e()):h;c=a(d,f,u,null==i?void 0:i.includes("scale"));const p=s(c);o=Object.assign(Object.assign({},p),{easing:"linear"})}else{c=a(0,100);o={easing:"ease",duration:s(c).overshootDuration}}return c&&r&&i&&(r.generators[i]=c),o}}}}const dt=t=>"string"!=typeof t,pt=ht(ut),mt=ht((({from:t=0,velocity:e=0,power:n=.8,decay:i=.325,bounceDamping:a,bounceStiffness:s,changeTarget:r,min:o,max:c,restDistance:l=.5,restSpeed:u})=>{i=x(i);const f={value:t,target:t,velocity:e,hasReachedTarget:!1,done:!1},h=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,m=void 0===r?p:r(p);f.target=m,m!==p&&(d=m-t);const v=t=>-d*Math.exp(-t/i),g=t=>m+v(t),y=t=>{const n=v(t),i=g(t);f.done=Math.abs(n)<=l,f.value=f.done?m:i,f.velocity=0===t?e:ft(g,t,f.value)};let b,w;const M=t=>{var e;(e=f.value,void 0!==o&&e<o||void 0!==c&&e>c)&&(b=t,w=ut({from:f.value,to:h(f.value),velocity:f.velocity,damping:a,stiffness:s,restDistance:l,restSpeed:u}))};return M(0),{next:t=>{let e=!1;return w||void 0!==b||(e=!0,y(t),M(t)),void 0!==b&&t>b?(f.hasReachedTarget=!0,w.next(t-b)):(f.hasReachedTarget=!1,!e&&y(t),f)}}}));function vt(t,e){return function(t){return"object"==typeof t}(t)?t:t&&e?e[t]:void 0}let gt;function yt(){if(!gt)return;const t=gt.sort(wt).map(xt);t.forEach(Mt),t.forEach(Mt),gt=void 0}function bt(t){gt?i(gt,t):(gt=[t],requestAnimationFrame(yt))}const wt=(t,e)=>t.getDepth()-e.getDepth(),xt=t=>t.animateUpdates(),Mt=t=>t.next(),St=(t,e)=>new CustomEvent(t,{detail:{target:e}});function Ot(t,e,n){t.dispatchEvent(new CustomEvent(e,{detail:{originalEvent:n}}))}function Tt(t,e,n){t.dispatchEvent(new CustomEvent(e,{detail:{originalEntry:n}}))}const At=(t,e,n)=>i=>{i.pointerType&&"mouse"!==i.pointerType||(n(),Ot(t,e,i))},Et={inView:{isActive:t=>Boolean(t.inView),subscribe:(t,{enable:e,disable:n})=>{let i=!1;if("undefined"!=typeof IntersectionObserver){const a=new IntersectionObserver((([a])=>{!i&&a.isIntersecting?(e(),Tt(t,"viewenter",a)):i&&!a.isIntersecting&&(n(),Tt(t,"viewleave",a)),i=a.isIntersecting}));return a.observe(t),()=>{a.unobserve(t),a.disconnect()}}return e(),()=>{}}},hover:{isActive:t=>Boolean(t.hover),subscribe:(t,{enable:e,disable:n})=>{const i=At(t,"hoverstart",e),a=At(t,"hoverend",n);return t.addEventListener("pointerenter",i),t.addEventListener("pointerleave",a),()=>{t.removeEventListener("pointerenter",i),t.removeEventListener("pointerleave",a)}}},press:{isActive:t=>Boolean(t.press),subscribe:(t,{enable:e,disable:n})=>{const i=e=>{n(),Ot(t,"pressend",e),window.removeEventListener("pointerup",i)},a=n=>{e(),Ot(t,"pressstart",n),window.addEventListener("pointerup",i)};return t.addEventListener("pointerdown",a),()=>{t.removeEventListener("pointerdown",a),window.removeEventListener("pointerup",i)}}}},jt=["initial","animate",...Object.keys(Et),"exit"],Dt=new WeakMap;function kt(t){const e={},n=[];for(let i in t){const a=t[i];v(i)&&(c[i]&&(i=c[i]),n.push(i),i=h(i));let s=Array.isArray(a)?a[0]:a;const r=f.get(i);r&&(s=M(a)?r.toDefaultUnit(a):a),e[i]=s}return n.length&&(e.transform=g(n)),e}const Pt=t=>`-${t.toLowerCase()}`;t.animate=function(t,e,n={}){var i;const a=(t=H(t)).length,s=[];for(let i=0;i<a;i++){const r=t[i];for(const t in e){const o=N(n,t);o.delay=it(o.delay,i,a);const c=_(r,t,e[t],o);s.push(c)}}return Q(s,null!==(i=n.duration)&&void 0!==i?i:P.duration)},t.animateStyle=_,t.createMotionState=function(t={},e){let n,i=e?e.getDepth()+1:0;const r={initial:!0,animate:!0},o={},c={};for(const n of jt)c[n]="string"==typeof t[n]?t[n]:null==e?void 0:e.getContext()[n];const l=!1===t.initial?"animate":"initial";let u=at(vt(t[l]||c[l],t.variants)||{},["transition"]);const f=Object.assign({},u),h=(t,e)=>()=>{r[t]=e,bt(p)},d=()=>{for(const e in Et){const i=Et[e].isActive(t),a=o[e];i&&!a?o[e]=Et[e].subscribe(n,{enable:h(e,!0),disable:h(e,!1)}):!i&&a&&(a(),delete o[e])}},p={update:e=>{n&&(t=e,d(),bt(p))},setActive:(t,e)=>{n&&(r[t]=e,bt(p))},animateUpdates:function*(){var e,i;const a=u;u={};const o={},c={},l={};for(const n of jt){if(!r[n])continue;const a=vt(t[n]);if(a){o[n]=a;for(const s in a)"transition"!==s&&(u[s]=a[s],l[s]=N(null!==(i=null!==(e=a.transition)&&void 0!==e?e:t.transition)&&void 0!==i?i:{},s),c[s]=n)}}const h=new Set([...Object.keys(u),...Object.keys(a)]),d=[];h.forEach((t=>{var e,i,s;void 0===u[t]&&(u[t]=f[t]),i=a[t],s=u[t],typeof i==typeof s&&(Array.isArray(i)&&Array.isArray(s)?function(t,e){const n=e.length;if(n!==t.length)return!1;for(let i=0;i<n;i++)if(e[i]!==t[i])return!1;return!0}(i,s):i===s)||(null!==(e=f[t])&&void 0!==e||(f[t]=X.get(n,t)),d.push(_(n,t,u[t],l[t])))})),yield;const p=d.map((t=>t())).filter(Boolean);if(!p.length)return;const m=u;n.dispatchEvent(St("motionstart",m)),Promise.all(p.map((t=>t.finished))).then((()=>{n.dispatchEvent(St("motioncomplete",m))})).catch(s)},getDepth:()=>i,getTarget:()=>u,getOptions:()=>t,getContext:()=>c,mount:t=>(n=t,Dt.set(n,p),d(),()=>{Dt.delete(n),function(t){gt&&a(gt,t)}(p);for(const t in o)o[t]()}),isMounted:()=>Boolean(n)};return p},t.createStyleString=function(t={}){const e=kt(t);let n="";for(const t in e)n+=t.startsWith("--")?t:t.replace(/[A-Z]/g,Pt),n+=`: ${e[t]}; `;return n},t.createStyles=kt,t.getAnimationData=n,t.getStyleName=K,t.glide=mt,t.mountedStates=Dt,t.spring=pt,t.stagger=function(t=.1,{start:e=0,from:n=0,easing:i}={}){return(a,s)=>{const r=M(n)?n:function(t,e){if("first"===t)return 0;{const n=e-1;return"last"===t?n:n/2}}(n,s),o=Math.abs(r-a);let c=t*o;if(i){const t=s*a;c=B(i)(c/t)*t}return e+c}},t.style=X,t.timeline=function(t,e={}){var n,i;const a=function(t,e={}){var{defaultOptions:n={}}=e,i=at(e,["defaultOptions"]);const a=[],s=new Map,r={},o=new Map;let c=0,l=0,u=0;for(let e=0;e<t.length;e++){const[i,a,f={}]=t[e];void 0!==f.at&&(l=st(l,f.at,c,o));let h=0;const d=H(i,r),p=d.length;for(let t=0;t<p;t++){const e=ct(d[t],s);for(const i in a){const s=lt(i,e);let r=Z(a[i]);const o=N(f,i);let{duration:c=n.duration||P.duration,easing:d=n.easing||P.easing}=o;if(O(d)){const t=v(i);r.length;const e=d.createAnimation(r,(()=>"0"),t);d=e.easing,void 0!==e.keyframes&&(r=e.keyframes),void 0!==e.duration&&(c=e.duration)}const m=it(f.delay,t,p)||0,g=l+m,y=g+c;let{offset:b=I(r.length)}=o;1===b.length&&0===b[0]&&(b[1]=1);const w=length-r.length;w>0&&F(b,w),1===r.length&&r.unshift(null),rt(s,r,d,b,g,y),h=Math.max(m+c,h),u=Math.max(y,u)}}c=l,l+=h}return s.forEach(((t,e)=>{for(const s in t){const r=t[s];r.sort(ot);const o=[],c=[],l=[];for(let t=0;t<r.length;t++){const{at:e,value:n,easing:i}=r[t];o.push(n),c.push(W(0,u,e)),l.push(i||P.easing)}0!==c[0]&&(c.unshift(0),o.unshift(o[0]),l.unshift("linear")),1!==c[c.length-1]&&(c.push(1),o.push(null)),a.push([e,s,o,Object.assign(Object.assign(Object.assign({},n),{duration:u,easing:l,offset:c}),i)])}})),a}(t,e),s=a.map((t=>_(...t))).filter(Boolean);return Q(s,null!==(i=null===(n=a[0])||void 0===n?void 0:n[3].duration)&&void 0!==i?i:P.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";const e=new WeakMap;function n(t){return e.has(t)||e.set(t,{transforms:[],animations:{},generators:{},prevGeneratorState:{}}),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 p=t=>1e3*t,m=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},M=new Map,S=t=>`--motion-${t}`,x=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{y.forEach((e=>{x.push(t+e),M.set(S(t+e),b[t])}))}));const T=(t,e)=>x.indexOf(t)-x.indexOf(e),w=new Set(x),O=t=>w.has(t),j=t=>t.sort(T).reduce(k,"").trim(),k=(t,e)=>`${t} ${e}(var(${S(e)}))`,A=t=>t.startsWith("--"),D=new Set;const P=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function R(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=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 $=(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:R(.25,.1,.25,1),"ease-in":R(.42,0,1,1),"ease-in-out":R(.42,0,.58,1),"ease-out":R(0,0,.58,1)},E=/\((.*?)\)/;function V(t){if("function"==typeof t)return t;if(Array.isArray(t))return R(...t);if(q[t])return q[t];if(t.startsWith("steps")){const e=E.exec(t);if(e){const t=e[1].split(",");return $(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"}={}){this.startTime=0,this.rate=1,this.t=0,this.cancelTimestamp=0,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e}));const f=a*(l+1);s(n)&&(n="ease");const 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 p=d(i>=f?1:Math.min(l,1));t(p);"finished"===this.playState||i>=f+c?(this.playState="finished",null===(n=this.resolve)||void 0===n||n.call(this,p)):"idle"!==this.playState&&(this.frameRequestId=requestAnimationFrame(this.tick))},this.play()}play(){const t=performance.now();this.playState="running",this.pauseTime?this.startTime=t-(this.pauseTime-this.startTime):this.startTime||(this.startTime=t),this.pauseTime=void 0,requestAnimationFrame(this.tick)}pause(){this.playState="paused",this.pauseTime=performance.now()}finish(){this.playState="finished",this.tick(0)}cancel(){var t;this.playState="idle",this.tick(this.cancelTimestamp),null===(t=this.reject)||void 0===t||t.call(this,!1),void 0!==this.frameRequestId&&cancelAnimationFrame(this.frameRequestId)}reverse(){this.rate*=-1}commitStyles(){this.cancelTimestamp=performance.now()}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)},G={},K={};for(const t in z)K[t]=()=>(void 0===G[t]&&(G[t]=z[t]()),G[t]);const X=t=>Array.isArray(t)?t:[t];function Y(t){return g[t]&&(t=g[t]),O(t)?S(t):t}const Z={get:(t,e)=>{e=Y(e);let n=A(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=M.get(e);t&&(n=t.initialValue)}return n},set:(t,e,n)=>{e=Y(e),A(e)?t.style.setProperty(e,n):t.style[e]=n}};function _(t){if(t&&"finished"!==t.playState)try{t.commitStyles(),t.cancel()}catch(t){}}function H(t,e,a,c={}){let u,{duration:h=i.duration,delay:f=i.delay,endDelay:d=i.endDelay,repeat:m=i.repeat,easing:y=i.easing,direction:v,offset:b,allowWebkitAcceleration:S=!1}=c;const x=n(t);let T=K.waapi();const w=O(e);w&&((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=j(a)})(t,e);const k=Y(e),P=M.get(k);return _(x.animations[k]),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=Z.get(t,k))&&void 0!==e?e:null==P?void 0:P.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(a),e);if(s(y)){const t=y.createAnimation(n,e,w,k,x);y=t.easing,void 0!==t.keyframes&&(n=t.keyframes),void 0!==t.duration&&(h=t.duration)}if(A(k)&&(K.cssRegisterProperty()?function(t){if(!D.has(t)){D.add(t);try{const{syntax:e,initialValue:n}=M.has(t)?M.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(k):T=!1),T){P&&(n=n.map((t=>r(t)?P.toDefaultUnit(t):t))),K.partialKeyframes()||1!==n.length||n.unshift(e());const a={delay:p(f),duration:p(h),endDelay:p(d),easing:o(y)?void 0:B(y),direction:v,iterations:m+1,fill:"both"};u=t.animate({[k]:n,offset:b,easing:o(y)?y.map(B):void 0},a),u.finished||(u.finished=new Promise(((t,e)=>{u.onfinish=t,u.oncancel=e})));const i=n[n.length-1];u.finished.then((()=>{Z.set(t,k,i),u.cancel()})).catch(l),S||(u.playbackRate=1.000001)}else if(w&&n.every(r)){1===n.length&&n.unshift(parseFloat(e()));u=new U((e=>{P&&(e=P.toDefaultUnit(e)),Z.set(t,k,e)}),n,Object.assign(Object.assign({},c),{duration:h,easing:y}))}else{const e=n[n.length-1];Z.set(t,k,P&&r(e)?P.toDefaultUnit(e):e)}return x.animations[k]=u,null==u||u.finished.then((()=>{x.animations[k]=void 0,x.generators[k]=void 0,x.prevGeneratorState[k]=void 0})).catch(l),u}}const J=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function L(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 N=t=>t(),Q=(t,e=i.duration)=>new Proxy({animations:t.map(N).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(_);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}},nt=t=>t.finished;function at(t,e,n){return"function"==typeof t?t(e,n):t}function it(t,e,n={}){const a=(t=L(t)).length,i=[];for(let r=0;r<a;r++){const s=t[r];for(const t in e){const o=J(n,t);o.delay=at(o.delay,r,a);const c=H(s,t,e[t],o);i.push(c)}}return Q(i,n.duration)}function rt(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 st(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 ot(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function ct(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function lt(t,e){return e[t]||(e[t]=[]),e[t]}function ut(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 ht=100,ft=10,dt=1;const pt=({stiffness:t=ht,damping:e=ft,mass:n=dt,from:a=0,to:i=1,velocity:r=0,restSpeed:s=2,restDistance:o=.5}={})=>{r=r?m(r):0;const c={done:!1,hasReachedTarget:!1,current:a,target:i,velocity:r},l=((t=ht,e=ft,n=dt)=>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:ut(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 mt(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(yt)){const n=a&&s&&s.prevGeneratorState[a],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 p=r(c);o=Object.assign(Object.assign({},p),{easing:"linear"})}else{c=i(0,100);o={easing:"ease",duration:r(c).overshootDuration}}return s&&a&&(s.generators[a]=c),o}}}}const yt=t=>"string"!=typeof t,gt=mt(pt),vt=mt((({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:ut(v,t,h.current)};let M,S;const x=t=>{var e;(e=h.current,void 0!==o&&e<o||void 0!==c&&e>c)&&(M=t,S=pt({from:h.current,to:f(h.current),velocity:h.velocity,damping:i,stiffness:r,restDistance:l,restSpeed:u}))};return x(0),t=>{let e=!1;return S||void 0!==M||(e=!0,b(t),x(t)),void 0!==M&&t>M?(h.hasReachedTarget=!0,S(t-M)):(h.hasReachedTarget=!1,!e&&b(t),h)}}));function bt(t,e){return Q([()=>{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?bt:it)(t,e,n)},t.glide=vt,t.spring=gt,t.stagger=function(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}},t.style=Z,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 r=[],o=new Map,c={},l=new Map;let u=0,p=0,m=0;for(let e=0;e<t.length;e++){const[a,r,h={}]=t[e];void 0!==h.at&&(p=rt(p,h.at,u,l));let y=0;const g=L(a,c),v=g.length;for(let t=0;t<v;t++){const e=ct(g[t],o);for(const a in r){const o=lt(a,e);let c=X(r[a]);const l=J(h,a);let{duration:u=n.duration||i.duration,easing:g=n.easing||i.easing}=l;if(s(g)){const t=O(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=at(h.delay,t,v)||0,M=p+b,S=M+u;let{offset:x=d(c.length)}=l;1===x.length&&0===x[0]&&(x[1]=1);const T=length-c.length;T>0&&f(x,T),1===c.length&&c.unshift(null),st(o,c,g,x,M,S),y=Math.max(b+u,y),m=Math.max(S,m)}}u=p,p+=y}return o.forEach(((t,e)=>{for(const s in t){const o=t[s];o.sort(ot);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,m,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:m,easing:u,offset:l}),a)])}})),r}(t,e),r=a.map((t=>H(...t))).filter(Boolean);return Q(r,null===(n=a[0])||void 0===n?void 0:n[3].duration)},Object.defineProperty(t,"__esModule",{value:!0})}));