motion 10.1.3 → 10.3.0
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 +22 -0
- package/README.md +1 -0
- package/dist/main.cjs.js +4 -0
- package/dist/main.es.js +2 -0
- package/dist/motion.min.js +1 -1
- package/dist/motion.umd.js +524 -189
- package/dist/size-animate-dom.js +1 -1
- package/dist/size-animate-style.js +1 -1
- package/dist/size-react.js +1 -1
- package/dist/size-spring.js +1 -1
- package/dist/size-timeline-dom.js +1 -1
- package/dist/size-webpack-animate.js +1 -1
- package/dist/targets/dom/animate-style.cjs.js +136 -111
- package/dist/targets/dom/animate-style.es.js +139 -114
- package/dist/targets/dom/animate.cjs.js +16 -3
- package/dist/targets/dom/animate.es.js +17 -4
- package/dist/targets/dom/data.cjs.js +4 -2
- package/dist/targets/dom/data.es.js +4 -2
- package/dist/targets/dom/style.cjs.js +1 -1
- package/dist/targets/dom/style.es.js +2 -2
- package/dist/targets/dom/timeline/index.cjs.js +17 -7
- package/dist/targets/dom/timeline/index.es.js +18 -8
- package/dist/targets/dom/timeline/utils/calc-time.cjs.js +3 -1
- package/dist/targets/dom/timeline/utils/calc-time.es.js +3 -1
- package/dist/targets/dom/utils/apply.cjs.js +4 -8
- package/dist/targets/dom/utils/apply.es.js +3 -7
- package/dist/targets/dom/utils/controls.cjs.js +6 -2
- package/dist/targets/dom/utils/controls.es.js +6 -2
- package/dist/targets/dom/utils/css-var.cjs.js +2 -2
- package/dist/targets/dom/utils/css-var.es.js +3 -3
- package/dist/targets/dom/utils/easing.cjs.js +7 -2
- package/dist/targets/dom/utils/easing.es.js +7 -3
- package/dist/targets/dom/utils/feature-detection.cjs.js +4 -4
- package/dist/targets/dom/utils/feature-detection.es.js +4 -4
- package/dist/targets/dom/utils/get-style-name.cjs.js +13 -0
- package/dist/targets/dom/utils/get-style-name.es.js +9 -0
- package/dist/targets/dom/utils/keyframes.cjs.js +2 -4
- package/dist/targets/dom/utils/keyframes.es.js +2 -4
- package/dist/targets/dom/utils/options.cjs.js +1 -1
- package/dist/targets/dom/utils/options.es.js +1 -1
- package/dist/targets/dom/utils/stop-animation.cjs.js +2 -0
- package/dist/targets/dom/utils/stop-animation.es.js +2 -0
- package/dist/targets/dom/utils/transforms.cjs.js +10 -7
- package/dist/targets/dom/utils/transforms.es.js +10 -7
- package/dist/targets/js/{animate-number.cjs.js → NumberAnimation.cjs.js} +42 -29
- package/dist/targets/js/{animate-number.es.js → NumberAnimation.es.js} +43 -29
- package/dist/targets/js/easing/glide/generator.cjs.js +99 -0
- package/dist/targets/js/easing/glide/generator.es.js +95 -0
- package/dist/targets/js/easing/glide/index.cjs.js +10 -0
- package/dist/targets/js/easing/glide/index.es.js +6 -0
- package/dist/targets/js/easing/spring/generator.cjs.js +64 -0
- package/dist/targets/js/easing/spring/generator.es.js +57 -0
- package/dist/targets/js/easing/spring/index.cjs.js +10 -0
- package/dist/targets/js/easing/spring/index.es.js +6 -0
- package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +71 -0
- package/dist/targets/js/easing/utils/create-generator-easing.es.js +67 -0
- package/dist/targets/js/easing/{get-function.cjs.js → utils/get-function.cjs.js} +3 -3
- package/dist/targets/js/easing/{get-function.es.js → utils/get-function.es.js} +3 -3
- package/dist/targets/js/easing/utils/has-reached-target.cjs.js +10 -0
- package/dist/targets/js/easing/utils/has-reached-target.es.js +6 -0
- package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +34 -0
- package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +30 -0
- package/dist/targets/react/hooks/use-animation.cjs.js +5 -2
- package/dist/targets/react/hooks/use-animation.es.js +5 -2
- package/dist/targets/react/utils/keyframes.cjs.js +5 -3
- package/dist/targets/react/utils/keyframes.es.js +6 -4
- package/dist/utils/is-number.cjs.js +7 -0
- package/dist/utils/is-number.es.js +3 -0
- package/dist/utils/stagger.cjs.js +3 -2
- package/dist/utils/stagger.es.js +3 -2
- package/dist/utils/velocity-per-second.cjs.js +15 -0
- package/dist/utils/velocity-per-second.es.js +11 -0
- package/package.json +8 -14
- package/types/index.d.ts +2 -0
- package/types/targets/dom/animate-style.d.ts +2 -2
- package/types/targets/dom/data.d.ts +1 -7
- package/types/targets/dom/style.d.ts +1 -1
- package/types/targets/dom/types.d.ts +24 -18
- package/types/targets/dom/utils/apply.d.ts +3 -2
- package/types/targets/dom/utils/controls.d.ts +3 -3
- package/types/targets/dom/utils/easing.d.ts +2 -1
- package/types/targets/dom/utils/get-style-name.d.ts +1 -0
- package/types/targets/dom/utils/keyframes.d.ts +1 -1
- package/types/targets/dom/utils/stop-animation.d.ts +1 -1
- package/types/targets/dom/utils/transforms.d.ts +2 -2
- package/types/targets/js/{animate-number.d.ts → NumberAnimation.d.ts} +2 -3
- package/types/targets/js/easing/glide/generator.d.ts +5 -0
- package/types/targets/js/easing/glide/index.d.ts +2 -0
- package/types/targets/js/easing/glide/types.d.ts +14 -0
- package/types/targets/js/easing/spring/generator.d.ts +6 -0
- package/types/targets/js/easing/spring/index.d.ts +2 -0
- package/types/targets/js/easing/spring/types.d.ts +10 -0
- package/types/targets/js/easing/utils/create-generator-easing.d.ts +3 -0
- package/types/targets/js/easing/{get-function.d.ts → utils/get-function.d.ts} +2 -2
- package/types/targets/js/easing/utils/has-reached-target.d.ts +1 -0
- package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +7 -0
- package/types/targets/js/types.d.ts +11 -0
- package/types/utils/is-number.d.ts +1 -0
- package/types/generators/index.d.ts +0 -2
- package/types/generators/spring/create.d.ts +0 -13
- package/types/generators/spring/index.d.ts +0 -2
- package/types/generators/types.d.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Motion One adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
+
## [10.3.0] [2021-12-05]
|
|
6
|
+
|
|
7
|
+
### New
|
|
8
|
+
|
|
9
|
+
- **Glide:** Animate transforms with realistic [glide](https://motion.dev/dom/glide) that can be used to mimic momentum scroll.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Fixing a bug where sometimes velocity wasn't being correctly passed to the next animation.
|
|
14
|
+
|
|
15
|
+
## [10.2.1] [2021-10-06]
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Ensuring `duration` is always passed correctly to the independent transform polyfill.
|
|
20
|
+
|
|
21
|
+
## [10.2.0] [2021-10-05]
|
|
22
|
+
|
|
23
|
+
### New
|
|
24
|
+
|
|
25
|
+
- **Springs:** Animate transforms with realistic [spring](https://motion.dev/dom/spring) simulations.
|
|
26
|
+
|
|
5
27
|
## [10.1.3] [2021-10-01]
|
|
6
28
|
|
|
7
29
|
### Fixed
|
package/README.md
CHANGED
|
@@ -14,5 +14,6 @@ A huge thank you to all sponsors of this project, with a special shoutout to:
|
|
|
14
14
|
- [Derek Reynolds](https://github.com/derekr)
|
|
15
15
|
- [Martin Pitt](https://github.com/Martin-Pitt)
|
|
16
16
|
- [Ryan Yogan](https://github.com/ryanyogan)
|
|
17
|
+
- [Mihael Konjević](https://github.com/retro)
|
|
17
18
|
|
|
18
19
|
[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.
|
package/dist/main.cjs.js
CHANGED
|
@@ -6,6 +6,8 @@ var animate = require('./targets/dom/animate.cjs.js');
|
|
|
6
6
|
var animateStyle = require('./targets/dom/animate-style.cjs.js');
|
|
7
7
|
var index = require('./targets/dom/timeline/index.cjs.js');
|
|
8
8
|
var stagger = require('./utils/stagger.cjs.js');
|
|
9
|
+
var index$1 = require('./targets/js/easing/spring/index.cjs.js');
|
|
10
|
+
var index$2 = require('./targets/js/easing/glide/index.cjs.js');
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
|
|
@@ -13,3 +15,5 @@ exports.animate = animate.animate;
|
|
|
13
15
|
exports.animateStyle = animateStyle.animateStyle;
|
|
14
16
|
exports.timeline = index.timeline;
|
|
15
17
|
exports.stagger = stagger.stagger;
|
|
18
|
+
exports.spring = index$1.spring;
|
|
19
|
+
exports.glide = index$2.glide;
|
package/dist/main.es.js
CHANGED
|
@@ -2,3 +2,5 @@ export { animate } from './targets/dom/animate.es.js';
|
|
|
2
2
|
export { animateStyle } from './targets/dom/animate-style.es.js';
|
|
3
3
|
export { timeline } from './targets/dom/timeline/index.es.js';
|
|
4
4
|
export { stagger } from './utils/stagger.es.js';
|
|
5
|
+
export { spring } from './targets/js/easing/spring/index.es.js';
|
|
6
|
+
export { glide } from './targets/js/easing/glide/index.es.js';
|
package/dist/motion.min.js
CHANGED
|
@@ -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,{activeTransforms:[],activeAnimations:{}}),e.get(t)}function i(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const a=()=>{},s=t=>t,r=["","X","Y","Z"],o={x:"translateX",y:"translateY",z:"translateZ"},l={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},c={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:l,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:s},skew:l},u=new Map,f=t=>`--motion-${t}`,h=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{r.forEach((e=>{h.push(t+e),u.set(f(t+e),c[t])}))}));const p=(t,e)=>h.indexOf(t)-h.indexOf(e),d=new Set(h),y=t=>t.sort(p).reduce(m,"").trim(),m=(t,e)=>`${t} ${e}(var(${f(e)}))`,g=t=>t.startsWith("--"),v=new Set;const b=t=>1e3*t;function x(t){try{"finished"!==t.playState&&t.commitStyles(),t.cancel()}catch(t){}}const O=t=>Array.isArray(t)&&"number"!=typeof t[0],T=t=>(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?w(t):t,w=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,S=t=>document.createElement("div").animate(t,{duration:.001}),M={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{S({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(S({opacity:[0,1]}).finished)},A={},j=Object.keys(M).reduce(((t,e)=>(t[e]=()=>(void 0===A[e]&&(A[e]=M[e]()),A[e]),t)),{}),P={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},k=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t;function D(t,e,n,i){if(t===e&&n===i)return s;const a=e=>function(t,e,n,i,a){let s,r,o=0;do{r=e+(n-e)/2,s=k(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:k(a(t),e,i)}const E=(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},V={ease:D(.25,.1,.25,1),"ease-in":D(.42,0,1,1),"ease-in-out":D(.42,0,.58,1),"ease-out":D(0,0,.58,1)},$=/\((.*?)\)/;function R(t){if("function"==typeof t)return t;if(Array.isArray(t))return D(...t);if(V[t])return V[t];if(t.startsWith("steps")){const e=$.exec(t);if(e){const t=e[1].split(",");return E(parseFloat(t[0]),t[1].trim())}}return s}const U=(t,e,n)=>-n*t+n*e+t,W=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function F(t,e){return O(t)?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t}function q(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 C(t){const e=[0];return q(e,t-1),e}function z(t,e=C(t.length),n=s){const i=t.length,a=i-e.length;return a>0&&q(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=F(n,s)(r),U(t[s],t[s+1],r)}}class K{constructor(t,e,{easing:n=P.easing,duration:i=P.duration,delay:a=P.delay,endDelay:s=P.endDelay,offset:r,repeat:o=P.repeat,direction:l="normal"}){this.startTime=0,this.rate=1,this.t=0,this.cancelT=0,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e}));const c=i*(o+1),u=z(e,r,O(n)?n.map(R):R(n));this.tick=e=>{if("finished"===this.playState){const e=u(1);return t(e),void this.resolve(e)}this.pauseTime&&(e=this.pauseTime);let n=(e-this.startTime)*this.rate;this.t=n,n/=1e3,n=Math.max(n-a,0);const r=n/i;let o=Math.floor(r),f=r%1;!f&&r>=1&&(f=1),1===f&&o--;const h=o%2;("reverse"===l||"alternate"===l&&h||"alternate-reverse"===l&&!h)&&(f=1-f);const p=n>=c?1:Math.min(f,1),d=u(p);t(d);n>=c+s?(this.playState="finished",this.resolve(d)):"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(){this.playState="idle",this.tick(this.cancelT),this.reject(!1)}reverse(){this.rate*=-1}commitStyles(){this.cancelT=this.t}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 X=(t,e)=>{let n=g(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=u.get(e);t&&(n=t.initialValue)}return n};const Y=t=>Array.isArray(t)?t:[t];function Z(t,e,i,s={}){let{duration:r=P.duration,delay:l=P.delay,endDelay:c=P.endDelay,repeat:h=P.repeat,easing:p=P.easing,direction:m,offset:w,allowWebkitAcceleration:S=!1}=s;const M=n(t);let A=j.waapi(),k=a;const D=(t=>d.has(t))(e);D&&(o[e]&&(e=o[e]),((t,e)=>{const{activeTransforms:i}=n(t);var a,s;s=e,-1===(a=i).indexOf(s)&&a.push(s),t.style.transform=y(i)})(t,e),e=f(e));const E=u.get(e);let V,$=function(t,e,n){for(let i=0;i<t.length;i++)null===t[i]&&(t[i]=i?t[i-1]:X(e,n));return t}(Y(i),t,e);if(function(t,e){t.activeAnimations[e]&&(x(t.activeAnimations[e]),t.activeAnimations[e]=void 0)}(M,e),g(e)?(k=((t,e)=>n=>t.style.setProperty(e,n))(t,e),j.cssRegisterProperty()?function(t){if(!v.has(t)){v.add(t);try{const{syntax:e,initialValue:n}=u.has(t)?u.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(e):A=!1):k=((t,e)=>n=>t.style[e]=n)(t,e),A){E&&($=$.map((t=>"number"==typeof t?E.toDefaultUnit(t):t))),j.partialKeyframes()||1!==$.length||$.unshift(X(t,e));const n={delay:b(l),duration:b(r),endDelay:b(c),easing:O(p)?void 0:T(p),direction:m,iterations:h+1,fill:"both"};V=t.animate({[e]:$,offset:w,easing:O(p)?p.map(T):void 0},n),V.finished||(V.finished=new Promise(((t,e)=>{V.onfinish=t,V.oncancel=e})));const i=$[$.length-1];V.finished.then((()=>k(i))).catch(a),S||(V.playbackRate=1.000001)}else if(D&&$.every(_)){if(1===$.length&&$.unshift(X(t,e)||(null==E?void 0:E.initialValue)||0),$=$.map((t=>"string"==typeof t?parseFloat(t):t)),E){const t=k;k=e=>t(E.toDefaultUnit(e))}V=function(t,e=[0,1],n={}){return new K(t,e,n)}(k,$,s)}else{const t=$[$.length-1];k(E&&"number"==typeof t?E.toDefaultUnit(t):t)}return M.activeAnimations[e]=V,null==V||V.finished.then((()=>M.activeAnimations[e]=void 0)).catch(a),V}const _=t=>"number"==typeof t,B=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):Object.assign({},t);function I(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 G=(t,e)=>new Proxy({animations:t,duration:e},J),H=t=>t.animations[0],J={get:(t,e)=>{var n,i;switch(e){case"duration":return t.duration;case"currentTime":let s=(null===(n=H(t))||void 0===n?void 0:n[e])||0;return s?s/1e3:0;case"playbackRate":return null===(i=H(t))||void 0===i?void 0:i[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(L)).catch(a)),t.finished;case"stop":return()=>t.animations.forEach(x);default:return()=>t.animations.forEach((t=>t[e]()))}},set:(t,e,n)=>{switch(e){case"currentTime":n=b(n);case"currentTime":case"playbackRate":for(let i=0;i<t.animations.length;i++)t.animations[i][e]=n;return!0}return!1}},L=t=>t.finished;function N(t,e,n){return"function"==typeof t?t(e,n):t}function Q(t,e,n,i){var a;return"number"==typeof 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 tt(t,e,n,a,s,r){!function(t,e,n){for(let a=0;a<t.length;a++){const s=t[a];s.at>e&&s.at<n&&(i(t,s),a--)}}(t,s,r);for(let i=0;i<e.length;i++)t.push({value:e[i],at:U(s,r,a[i]),easing:F(n,i)})}function et(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function nt(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function it(t,e){return e[t]||(e[t]=[]),e[t]}t.animate=function(t,e,n={}){var i;const a=[],s=(t=I(t)).length;for(let i=0;i<s;i++){const r=t[i];for(const t in e){const o=B(n,t);o.delay=N(o.delay,i,s);const l=Z(r,t,e[t],o);l&&a.push(l)}}return G(a,null!==(i=n.duration)&&void 0!==i?i:P.duration)},t.animateStyle=Z,t.stagger=function(t=.1,{start:e=0,from:n=0,easing:i}={}){return(a,s)=>{const r="number"==typeof 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 l=t*o;if(i){const t=s*a;l=R(i)(l/t)*t}return e+l}},t.timeline=function(t,e={}){var n,i;const a=[],s=function(t,e={}){var{defaultOptions:n={}}=e,i=function(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}(e,["defaultOptions"]);const a=[],s=new Map,r={},o=new Map;let l=0,c=0,u=0;for(let e=0;e<t.length;e++){const[i,a,f={}]=t[e];void 0!==f.at&&(c=Q(c,f.at,l,o));let h=0;const p=I(i,r),d=p.length;for(let t=0;t<d;t++){const e=nt(p[t],s);for(const i in a){const s=it(i,e),r=Y(a[i]),o=B(f,i),{duration:l=n.duration||P.duration,easing:p=n.easing||P.easing,offset:y=C(r.length)}=o,m=N(f.delay,t,d)||0,g=c+m,v=g+l;1===y.length&&0===y[0]&&(y[1]=1);const b=length-r.length;b>0&&q(y,b),1===r.length&&r.unshift(null),tt(s,r,p,y,g,v),h=Math.max(m+l,h),u=Math.max(v,u)}}l=c,c+=h}return s.forEach(((t,e)=>{for(const s in t){const r=t[s];r.sort(et);const o=[],l=[],c=[];for(let t=0;t<r.length;t++){const{at:e,value:n,easing:i}=r[t];o.push(n),l.push(W(0,u,e)),c.push(i||P.easing)}0!==l[0]&&(l.unshift(0),o.unshift(o[0]),c.unshift("linear")),1!==l[l.length-1]&&(l.push(1),o.push(null)),a.push([e,s,o,Object.assign(Object.assign(Object.assign({},n),{duration:u,easing:c,offset:l}),i)])}})),a}(t,e);for(let t=0;t<s.length;t++){const e=Z(...s[t]);e&&a.push(e)}return G(a,null!==(i=null===(n=s[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=()=>{},s=t=>t,r=["","X","Y","Z"],o={x:"translateX",y:"translateY",z:"translateZ"},l={syntax:"<angle>",initialValue:"0deg",toDefaultUnit:t=>t+"deg"},c={translate:{syntax:"<length-percentage>",initialValue:"0px",toDefaultUnit:t=>t+"px"},rotate:l,scale:{syntax:"<number>",initialValue:1,toDefaultUnit:s},skew:l},u=new Map,h=t=>`--motion-${t}`,f=["x","y","z"];["translate","scale","rotate","skew"].forEach((t=>{r.forEach((e=>{f.push(t+e),u.set(h(t+e),c[t])}))}));const d=(t,e)=>f.indexOf(t)-f.indexOf(e),p=new Set(f),y=t=>p.has(t),m=t=>t.sort(d).reduce(g,"").trim(),g=(t,e)=>`${t} ${e}(var(${h(e)}))`,v=t=>t.startsWith("--"),b=new Set;const M=t=>1e3*t,x=t=>"number"==typeof t,S=t=>Array.isArray(t)&&!x(t[0]),T=t=>"object"==typeof t&&Boolean(t.createAnimation),O=t=>(t=>Array.isArray(t)&&x(t[0]))(t)?w(t):t,w=([t,e,n,a])=>`cubic-bezier(${t}, ${e}, ${n}, ${a})`,j=t=>document.createElement("div").animate(t,{duration:.001}),D={cssRegisterProperty:()=>"undefined"!=typeof CSS&&Object.hasOwnProperty.call(CSS,"registerProperty"),waapi:()=>Object.hasOwnProperty.call(Element.prototype,"animate"),partialKeyframes:()=>{try{j({opacity:[1]})}catch(t){return!1}return!0},finished:()=>Boolean(j({opacity:[0,1]}).finished)},k={},A={};for(const t in D)A[t]=()=>(void 0===k[t]&&(k[t]=D[t]()),k[t]);const P={duration:.3,delay:0,endDelay:0,repeat:0,easing:"ease"},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 s;const i=e=>function(t,e,n,a,i){let s,r,o=0;do{r=e+(n-e)/2,s=R(r,a,i)-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: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 s=0,r=1,o=i/t,Math.min(Math.max(o,s),r);var s,r,o},V={ease:$(.25,.1,.25,1),"ease-in":$(.42,0,1,1),"ease-in-out":$(.42,0,.58,1),"ease-out":$(0,0,.58,1)},q=/\((.*?)\)/;function W(t){if("function"==typeof t)return t;if(Array.isArray(t))return $(...t);if(V[t])return V[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 s}const F=(t,e,n)=>-n*t+n*e+t,U=(t,e,n)=>e-t==0?1:(n-t)/(e-t);function B(t,e){return S(t)?t[((t,e,n)=>{const a=e-t;return((n-t)%a+a)%a+t})(0,t.length,e)]:t}function C(t,e){const n=t[t.length-1];for(let a=1;a<=e;a++){const i=U(0,e,a);t.push(F(n,1,i))}}function z(t){const e=[0];return C(e,t-1),e}function G(t,e=z(t.length),n=s){const a=t.length,i=a-e.length;return i>0&&C(e,i),i=>{let s=0;for(;s<a-2&&!(i<e[s+1]);s++);let r=(o=U(e[s],e[s+1],i),Math.min(1,Math.max(o,0)));var o;return r=B(n,s)(r),F(t[s],t[s+1],r)}}class K{constructor(t,e=[0,1],{easing:n=P.easing,duration:a=P.duration,delay:i=P.delay,endDelay:s=P.endDelay,repeat:r=P.repeat,offset:o,direction:l="normal"}={}){this.startTime=0,this.rate=1,this.t=0,this.cancelT=0,this.playState="idle",this.finished=new Promise(((t,e)=>{this.resolve=t,this.reject=e}));const c=a*(r+1);T(n)&&(n="ease");const u=G(e,o,S(n)?n.map(W):W(n));this.tick=e=>{this.pauseTime&&(e=this.pauseTime);let n=(e-this.startTime)*this.rate;this.t=n,n/=1e3,n=Math.max(n-i,0),"finished"===this.playState&&(n=c);const r=n/a;let o=Math.floor(r),h=r%1;!h&&r>=1&&(h=1),1===h&&o--;const f=o%2;("reverse"===l||"alternate"===l&&f||"alternate-reverse"===l&&!f)&&(h=1-h);const d=u(n>=c?1:Math.min(h,1));t(d);"finished"===this.playState||n>=c+s?(this.playState="finished",this.resolve(d)):"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(){this.playState="idle",this.tick(this.cancelT),this.reject(!1)}reverse(){this.rate*=-1}commitStyles(){this.cancelT=this.t}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 X=t=>Array.isArray(t)?t:[t],Y=(t,e)=>{let n=v(e)?t.style.getPropertyValue(e):getComputedStyle(t)[e];if(!n&&0!==n){const t=u.get(e);t&&(n=t.initialValue)}return n};function Z(t){if(t)try{"finished"!==t.playState&&t.commitStyles(),t.cancel()}catch(t){}}function _(t,e,a,s={}){let r,{duration:l=P.duration,delay:c=P.delay,endDelay:f=P.endDelay,repeat:d=P.repeat,easing:p=P.easing,direction:g,offset:w,allowWebkitAcceleration:j=!1}=s;const D=n(t);let k=A.waapi(),R=i;const $=y(e);$&&((t,e)=>{o[e]&&(e=o[e]);const{transforms:a}=n(t);var i,s;s=e,-1===(i=a).indexOf(s)&&i.push(s),t.style.transform=m(a)})(t,e);const E=function(t){return o[t]&&(t=o[t]),y(t)?h(t):t}(e),V=u.get(E);return Z(D.animations[E]),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=Y(t,E))&&void 0!==e?e:null==V?void 0:V.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(T(p)){const t=p.createAnimation(n,e,$,E,D);p=t.easing,void 0!==t.keyframes&&(n=t.keyframes),void 0!==t.duration&&(l=t.duration)}if(v(E)?(R=((t,e)=>n=>t.style.setProperty(e,n))(t,E),A.cssRegisterProperty()?function(t){if(!b.has(t)){b.add(t);try{const{syntax:e,initialValue:n}=u.has(t)?u.get(t):{};CSS.registerProperty({name:t,inherits:!1,syntax:e,initialValue:n})}catch(t){}}}(E):k=!1):R=((t,e)=>n=>t.style[e]=n)(t,E),k){V&&(n=n.map((t=>x(t)?V.toDefaultUnit(t):t))),A.partialKeyframes()||1!==n.length||n.unshift(e());const a={delay:M(c),duration:M(l),endDelay:M(f),easing:S(p)?void 0:O(p),direction:g,iterations:d+1,fill:"both"};r=t.animate({[E]:n,offset:w,easing:S(p)?p.map(O):void 0},a),r.finished||(r.finished=new Promise(((t,e)=>{r.onfinish=t,r.oncancel=e})));const s=n[n.length-1];r.finished.then((()=>{R(s),r.cancel()})).catch(i),j||(r.playbackRate=1.000001)}else if($&&n.every(x)){if(1===n.length&&n.unshift(parseFloat(e())),V){const t=R;R=e=>t(V.toDefaultUnit(e))}r=new K(R,n,Object.assign(Object.assign({},s),{duration:l,easing:p}))}else{const t=n[n.length-1];R(V&&x(t)?V.toDefaultUnit(t):t)}return D.animations[E]=r,null==r||r.finished.then((()=>{D.animations[E]=void 0,D.generators[E]=void 0,D.prevGeneratorState[E]=void 0})).catch(i),r}}const I=(t,e)=>t[e]?Object.assign(Object.assign({},t),t[e]):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(),L=(t,e)=>new Proxy({animations:t.map(J).filter(Boolean),duration:e},Q),N=t=>t.animations[0],Q={get:(t,e)=>{var n,a;switch(e){case"duration":return t.duration;case"currentTime":let s=(null===(n=N(t))||void 0===n?void 0:n[e])||0;return s?s/1e3:0;case"playbackRate":return null===(a=N(t))||void 0===a?void 0:a[e];case"finished":return t.finished||(t.finished=Promise.all(t.animations.map(tt)).catch(i)),t.finished;case"stop":return()=>t.animations.forEach(Z);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}},tt=t=>t.finished;function et(t,e,n){return"function"==typeof t?t(e,n):t}function nt(t,e,n,a){var i;return x(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 at(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:F(s,r,i[a]),easing:B(n,a)})}function it(t,e){return t.at===e.at?null===t.value?1:-1:t.at-e.at}function st(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function rt(t,e){return e[t]||(e[t]=[]),e[t]}const ot=({stiffness:t=100,damping:e=10,mass:n=1,from:a=0,to:i=1,velocity:s=0,restSpeed:r=2,restDistance:o=.5}={})=>{const l={done:!1,value:a,target:i,velocity:s=s?s/1e3:0,hasReachedTarget:!1},c=((t=100,e=10,n=1)=>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,c);let d;return d=c<1?t=>i-Math.exp(-c*h*t)*((c*h*u-s)/f*Math.sin(f*t)+u*Math.cos(f*t)):t=>i-Math.exp(-h*t)*(u+(s+h*u)*t),{next:t=>{l.value=d(t),l.velocity=0===t?s:lt(d,t,l.value);const e=Math.abs(l.velocity)<=r,n=Math.abs(i-l.value)<=o;var c,u,h;return l.done=e&&n,l.hasReachedTarget=(c=a,u=i,h=l.value,c<u&&h>=u||c>u&&h<=u),l}}};function lt(t,e,n){const a=Math.max(e-5,0);return i=n-t(a),(s=5)?i*(1e3/s):0;var i,s}function ct(t){const e=new WeakMap;return(n={})=>{const a=new Map,i=(e=0,i=100,s=0,r=!1)=>{const o=`${e}-${i}-${s}-${r}`;return a.has(o)||a.set(o,t(Object.assign({from:e,to:i,velocity:s,restSpeed:r?.05:2,restDistance:r?.01:.5},n))),a.get(o)},s=t=>(e.has(t)||e.set(t,function(t){let e,n=10,a=t.next(0);const i=[a.value];for(;!a.done&&n<1e4;)a=t.next(n),i.push(a.done?a.target:a.value),void 0===e&&a.hasReachedTarget&&(e=n),n+=10;const s=n-10;return 1===i.length&&i.push(a.value),{keyframes:i,duration:s/1e3,overshootDuration:(null!=e?e:s)/1e3}}(t)),e.get(t));return{createAnimation:(t,e,n,a,r)=>{let o,l;const c=t.length;if(n&&c<=2&&t.every(ut)){const n=a&&r&&r.prevGeneratorState[a],u=n&&(1===c||2===c&&null===t[0])?n.velocity:0,h=t[c-1],f=1===c?null:t[0],d=null===f?n?n.value:parseFloat(e()):f;l=i(d,h,u,null==a?void 0:a.includes("scale"));const p=s(l);o=Object.assign(Object.assign({},p),{easing:"linear"})}else{l=i(0,100);o={easing:"ease",duration:s(l).overshootDuration}}return l&&r&&a&&(r.generators[a]=l),o}}}}const ut=t=>"string"!=typeof t,ht=ct(ot),ft=ct((({from:t=0,velocity:e=0,power:n=.8,decay:a=.325,bounceDamping:i,bounceStiffness:s,changeTarget:r,min:o,max:l,restDistance:c=.5,restSpeed:u})=>{a=M(a);const h={value:t,target:t,velocity:e,hasReachedTarget:!1,done:!1},f=t=>void 0===o?l:void 0===l||Math.abs(o-t)<Math.abs(l-t)?o:l;let d=n*e;const p=t+d,y=void 0===r?p:r(p);h.target=y,y!==p&&(d=y-t);const m=t=>-d*Math.exp(-t/a),g=t=>y+m(t),v=t=>{const n=m(t),a=g(t);h.done=Math.abs(n)<=c,h.value=h.done?y:a,h.velocity=0===t?e:lt(g,t,h.value)};let b,x;const S=t=>{var e;(e=h.value,void 0!==o&&e<o||void 0!==l&&e>l)&&(b=t,x=ot({from:h.value,to:f(h.value),velocity:h.velocity,damping:i,stiffness:s,restDistance:c,restSpeed:u}))};return S(0),{next:t=>{let e=!1;return x||void 0!==b||(e=!0,v(t),S(t)),void 0!==b&&t>b?(h.hasReachedTarget=!0,x.next(t-b)):(h.hasReachedTarget=!1,!e&&v(t),h)}}}));t.animate=function(t,e,n={}){var a;const i=(t=H(t)).length,s=[];for(let a=0;a<i;a++){const r=t[a];for(const t in e){const o=I(n,t);o.delay=et(o.delay,a,i);const l=_(r,t,e[t],o);s.push(l)}}return L(s,null!==(a=n.duration)&&void 0!==a?a:P.duration)},t.animateStyle=_,t.glide=ft,t.spring=ht,t.stagger=function(t=.1,{start:e=0,from:n=0,easing:a}={}){return(i,s)=>{const r=x(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-i);let l=t*o;if(a){const t=s*i;l=W(a)(l/t)*t}return e+l}},t.timeline=function(t,e={}){var n,a;const i=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,r={},o=new Map;let l=0,c=0,u=0;for(let e=0;e<t.length;e++){const[a,i,h={}]=t[e];void 0!==h.at&&(c=nt(c,h.at,l,o));let f=0;const d=H(a,r),p=d.length;for(let t=0;t<p;t++){const e=st(d[t],s);for(const a in i){const s=rt(a,e),r=X(i[a]),o=I(h,a);let{duration:l=n.duration||P.duration,easing:d=n.easing||P.easing}=o;const y=et(h.delay,t,p)||0,m=c+y,g=m+l;let{offset:v=z(r.length)}=o;1===v.length&&0===v[0]&&(v[1]=1);const b=length-r.length;b>0&&C(v,b),1===r.length&&r.unshift(null),at(s,r,d,v,m,g),f=Math.max(y+l,f),u=Math.max(g,u)}}l=c,c+=f}return s.forEach(((t,e)=>{for(const s in t){const r=t[s];r.sort(it);const o=[],l=[],c=[];for(let t=0;t<r.length;t++){const{at:e,value:n,easing:a}=r[t];o.push(n),l.push(U(0,u,e)),c.push(a||P.easing)}0!==l[0]&&(l.unshift(0),o.unshift(o[0]),c.unshift("linear")),1!==l[l.length-1]&&(l.push(1),o.push(null)),i.push([e,s,o,Object.assign(Object.assign(Object.assign({},n),{duration:u,easing:c,offset:l}),a)])}})),i}(t,e),s=i.map((t=>_(...t))).filter(Boolean);return L(s,null!==(a=null===(n=i[0])||void 0===n?void 0:n[3].duration)&&void 0!==a?a:P.duration)},Object.defineProperty(t,"__esModule",{value:!0})}));
|