motion 10.3.2 → 10.5.0-alpha.3
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/README.md +0 -19
- package/dist/main.cjs.js +11 -13
- package/dist/main.es.js +7 -6
- package/dist/motion.min.js +1 -1
- package/dist/motion.umd.js +412 -16
- package/dist/react.cjs.js +7 -2
- package/dist/react.es.js +1 -1
- package/dist/size-index.js +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/react.js +2 -0
- package/lib/react.js.map +1 -0
- package/lib/vue.js +2 -0
- package/lib/vue.js.map +1 -0
- package/package.json +16 -134
- package/react/package.json +1 -1
- package/types/index.d.ts +3 -7
- package/types/index.d.ts.map +1 -0
- package/types/react.d.ts +2 -0
- package/types/react.d.ts.map +1 -0
- package/types/vue.d.ts +2 -0
- package/types/vue.d.ts.map +1 -0
- package/CHANGELOG.md +0 -97
- package/dist/size-animate-dom.js +0 -1
- package/dist/size-animate-style.js +0 -1
- package/dist/size-react.js +0 -1
- package/dist/size-spring.js +0 -1
- package/dist/size-timeline-dom.js +0 -1
- package/dist/size-webpack-animate.js +0 -1
- package/dist/targets/dom/animate-style.cjs.js +0 -182
- package/dist/targets/dom/animate-style.es.js +0 -178
- package/dist/targets/dom/animate.cjs.js +0 -42
- package/dist/targets/dom/animate.es.js +0 -38
- package/dist/targets/dom/data.cjs.js +0 -18
- package/dist/targets/dom/data.es.js +0 -14
- package/dist/targets/dom/style.cjs.js +0 -22
- package/dist/targets/dom/style.es.js +0 -18
- package/dist/targets/dom/timeline/index.cjs.js +0 -174
- package/dist/targets/dom/timeline/index.es.js +0 -169
- package/dist/targets/dom/timeline/utils/calc-time.cjs.js +0 -23
- package/dist/targets/dom/timeline/utils/calc-time.es.js +0 -19
- package/dist/targets/dom/timeline/utils/edit.cjs.js +0 -36
- package/dist/targets/dom/timeline/utils/edit.es.js +0 -31
- package/dist/targets/dom/timeline/utils/sort.cjs.js +0 -14
- package/dist/targets/dom/timeline/utils/sort.es.js +0 -10
- package/dist/targets/dom/utils/apply.cjs.js +0 -9
- package/dist/targets/dom/utils/apply.es.js +0 -4
- package/dist/targets/dom/utils/controls.cjs.js +0 -59
- package/dist/targets/dom/utils/controls.es.js +0 -54
- package/dist/targets/dom/utils/css-var.cjs.js +0 -29
- package/dist/targets/dom/utils/css-var.es.js +0 -23
- package/dist/targets/dom/utils/defaults.cjs.js +0 -13
- package/dist/targets/dom/utils/defaults.es.js +0 -9
- package/dist/targets/dom/utils/easing.cjs.js +0 -18
- package/dist/targets/dom/utils/easing.es.js +0 -10
- package/dist/targets/dom/utils/feature-detection.cjs.js +0 -31
- package/dist/targets/dom/utils/feature-detection.es.js +0 -27
- package/dist/targets/dom/utils/get-style-name.cjs.js +0 -13
- package/dist/targets/dom/utils/get-style-name.es.js +0 -9
- package/dist/targets/dom/utils/keyframes.cjs.js +0 -16
- package/dist/targets/dom/utils/keyframes.es.js +0 -11
- package/dist/targets/dom/utils/options.cjs.js +0 -13
- package/dist/targets/dom/utils/options.es.js +0 -9
- package/dist/targets/dom/utils/resolve-elements.cjs.js +0 -22
- package/dist/targets/dom/utils/resolve-elements.es.js +0 -18
- package/dist/targets/dom/utils/stop-animation.cjs.js +0 -19
- package/dist/targets/dom/utils/stop-animation.es.js +0 -15
- package/dist/targets/dom/utils/time.cjs.js +0 -7
- package/dist/targets/dom/utils/time.es.js +0 -3
- package/dist/targets/dom/utils/transforms.cjs.js +0 -85
- package/dist/targets/dom/utils/transforms.es.js +0 -74
- package/dist/targets/js/NumberAnimation.cjs.js +0 -144
- package/dist/targets/js/NumberAnimation.es.js +0 -140
- package/dist/targets/js/easing/cubic-bezier.cjs.js +0 -57
- package/dist/targets/js/easing/cubic-bezier.es.js +0 -53
- package/dist/targets/js/easing/glide/generator.cjs.js +0 -99
- package/dist/targets/js/easing/glide/generator.es.js +0 -95
- package/dist/targets/js/easing/glide/index.cjs.js +0 -10
- package/dist/targets/js/easing/glide/index.es.js +0 -6
- package/dist/targets/js/easing/spring/generator.cjs.js +0 -64
- package/dist/targets/js/easing/spring/generator.es.js +0 -57
- package/dist/targets/js/easing/spring/index.cjs.js +0 -10
- package/dist/targets/js/easing/spring/index.es.js +0 -6
- package/dist/targets/js/easing/steps.cjs.js +0 -15
- package/dist/targets/js/easing/steps.es.js +0 -11
- package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +0 -71
- package/dist/targets/js/easing/utils/create-generator-easing.es.js +0 -67
- package/dist/targets/js/easing/utils/get-function.cjs.js +0 -37
- package/dist/targets/js/easing/utils/get-function.es.js +0 -33
- package/dist/targets/js/easing/utils/has-reached-target.cjs.js +0 -10
- package/dist/targets/js/easing/utils/has-reached-target.es.js +0 -6
- package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +0 -34
- package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +0 -30
- package/dist/targets/js/utils/get-easing.cjs.js +0 -14
- package/dist/targets/js/utils/get-easing.es.js +0 -10
- package/dist/targets/js/utils/interpolate.cjs.js +0 -35
- package/dist/targets/js/utils/interpolate.es.js +0 -31
- package/dist/targets/js/utils/offset.cjs.js +0 -22
- package/dist/targets/js/utils/offset.es.js +0 -17
- package/dist/targets/react/animated.cjs.js +0 -126
- package/dist/targets/react/animated.es.js +0 -101
- package/dist/targets/react/context.cjs.js +0 -9
- package/dist/targets/react/context.es.js +0 -5
- package/dist/targets/react/hooks/use-animation.cjs.js +0 -47
- package/dist/targets/react/hooks/use-animation.es.js +0 -43
- package/dist/targets/react/hooks/use-exit.cjs.js +0 -27
- package/dist/targets/react/hooks/use-exit.es.js +0 -23
- package/dist/targets/react/hooks/use-gesture-state.cjs.js +0 -17
- package/dist/targets/react/hooks/use-gesture-state.es.js +0 -13
- package/dist/targets/react/hooks/use-hover.cjs.js +0 -24
- package/dist/targets/react/hooks/use-hover.es.js +0 -20
- package/dist/targets/react/hooks/use-press.cjs.js +0 -25
- package/dist/targets/react/hooks/use-press.es.js +0 -21
- package/dist/targets/react/hooks/use-viewport.cjs.js +0 -37
- package/dist/targets/react/hooks/use-viewport.es.js +0 -33
- package/dist/targets/react/index.cjs.js +0 -17
- package/dist/targets/react/index.es.js +0 -13
- package/dist/targets/react/utils/has-changed.cjs.js +0 -24
- package/dist/targets/react/utils/has-changed.es.js +0 -19
- package/dist/targets/react/utils/keyframes.cjs.js +0 -38
- package/dist/targets/react/utils/keyframes.es.js +0 -34
- package/dist/targets/react/utils/poses.cjs.js +0 -14
- package/dist/targets/react/utils/poses.es.js +0 -10
- package/dist/targets/react/utils/update-target.cjs.js +0 -20
- package/dist/targets/react/utils/update-target.es.js +0 -16
- package/dist/utils/array.cjs.js +0 -14
- package/dist/utils/array.es.js +0 -9
- package/dist/utils/clamp.cjs.js +0 -7
- package/dist/utils/clamp.es.js +0 -3
- package/dist/utils/is-number.cjs.js +0 -7
- package/dist/utils/is-number.es.js +0 -3
- package/dist/utils/mix.cjs.js +0 -28
- package/dist/utils/mix.es.js +0 -24
- package/dist/utils/noop.cjs.js +0 -9
- package/dist/utils/noop.es.js +0 -4
- package/dist/utils/progress.cjs.js +0 -20
- package/dist/utils/progress.es.js +0 -16
- package/dist/utils/stagger.cjs.js +0 -38
- package/dist/utils/stagger.es.js +0 -32
- package/dist/utils/velocity-per-second.cjs.js +0 -15
- package/dist/utils/velocity-per-second.es.js +0 -11
- package/dist/utils/wrap.cjs.js +0 -10
- package/dist/utils/wrap.es.js +0 -6
- package/types/react-entry.d.ts +0 -2
- package/types/targets/dom/animate-style.d.ts +0 -2
- package/types/targets/dom/animate.d.ts +0 -2
- package/types/targets/dom/data.d.ts +0 -2
- package/types/targets/dom/style.d.ts +0 -3
- package/types/targets/dom/timeline/index.d.ts +0 -15
- package/types/targets/dom/timeline/types.d.ts +0 -13
- package/types/targets/dom/timeline/utils/calc-time.d.ts +0 -2
- package/types/targets/dom/timeline/utils/edit.d.ts +0 -4
- package/types/targets/dom/timeline/utils/sort.d.ts +0 -2
- package/types/targets/dom/types.d.ts +0 -114
- package/types/targets/dom/utils/apply.d.ts +0 -3
- package/types/targets/dom/utils/controls.d.ts +0 -12
- package/types/targets/dom/utils/css-var.d.ts +0 -3
- package/types/targets/dom/utils/defaults.d.ts +0 -8
- package/types/targets/dom/utils/easing.d.ts +0 -6
- package/types/targets/dom/utils/feature-detection.d.ts +0 -8
- package/types/targets/dom/utils/get-style-name.d.ts +0 -1
- package/types/targets/dom/utils/keyframes.d.ts +0 -3
- package/types/targets/dom/utils/options.d.ts +0 -2
- package/types/targets/dom/utils/resolve-elements.d.ts +0 -4
- package/types/targets/dom/utils/stop-animation.d.ts +0 -6
- package/types/targets/dom/utils/time.d.ts +0 -1
- package/types/targets/dom/utils/transforms.d.ts +0 -20
- package/types/targets/js/NumberAnimation.d.ts +0 -24
- package/types/targets/js/easing/cubic-bezier.d.ts +0 -1
- package/types/targets/js/easing/glide/generator.d.ts +0 -5
- package/types/targets/js/easing/glide/index.d.ts +0 -2
- package/types/targets/js/easing/glide/types.d.ts +0 -14
- package/types/targets/js/easing/spring/generator.d.ts +0 -6
- package/types/targets/js/easing/spring/index.d.ts +0 -2
- package/types/targets/js/easing/spring/types.d.ts +0 -10
- package/types/targets/js/easing/steps.d.ts +0 -3
- package/types/targets/js/easing/utils/create-generator-easing.d.ts +0 -3
- package/types/targets/js/easing/utils/get-function.d.ts +0 -3
- package/types/targets/js/easing/utils/has-reached-target.d.ts +0 -1
- package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +0 -7
- package/types/targets/js/types.d.ts +0 -12
- package/types/targets/js/utils/get-easing.d.ts +0 -1
- package/types/targets/js/utils/interpolate.d.ts +0 -2
- package/types/targets/js/utils/offset.d.ts +0 -2
- package/types/targets/react/animated.d.ts +0 -3
- package/types/targets/react/context.d.ts +0 -3
- package/types/targets/react/hooks/use-animation.d.ts +0 -4
- package/types/targets/react/hooks/use-exit.d.ts +0 -3
- package/types/targets/react/hooks/use-gesture-state.d.ts +0 -4
- package/types/targets/react/hooks/use-hover.d.ts +0 -4
- package/types/targets/react/hooks/use-press.d.ts +0 -4
- package/types/targets/react/hooks/use-viewport.d.ts +0 -4
- package/types/targets/react/index.d.ts +0 -2
- package/types/targets/react/types.d.ts +0 -108
- package/types/targets/react/utils/has-changed.d.ts +0 -2
- package/types/targets/react/utils/keyframes.d.ts +0 -3
- package/types/targets/react/utils/poses.d.ts +0 -2
- package/types/targets/react/utils/supported-elements.d.ts +0 -8
- package/types/targets/react/utils/update-target.d.ts +0 -3
- package/types/utils/array.d.ts +0 -2
- package/types/utils/clamp.d.ts +0 -1
- package/types/utils/interpolate.d.ts +0 -0
- package/types/utils/is-number.d.ts +0 -1
- package/types/utils/mix.d.ts +0 -1
- package/types/utils/noop.d.ts +0 -2
- package/types/utils/progress.d.ts +0 -1
- package/types/utils/stagger.d.ts +0 -12
- package/types/utils/value-types.d.ts +0 -0
- package/types/utils/velocity-per-second.d.ts +0 -1
- package/types/utils/wrap.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Motion One
|
|
2
|
-
|
|
3
|
-
A new animation library, built on the Web Animations API for the smallest filesize and the fastest performance.
|
|
4
|
-
|
|
5
|
-
## 📚 Documentation
|
|
6
|
-
|
|
7
|
-
Full docs are available at [motion.dev](https://motion.dev).
|
|
8
|
-
|
|
9
|
-
## 🙌 Sponsors
|
|
10
|
-
|
|
11
|
-
A huge thank you to all sponsors of this project, with a special shoutout to:
|
|
12
|
-
|
|
13
|
-
- [Alex Frazer](https://github.com/AlexFrazer)
|
|
14
|
-
- [Derek Reynolds](https://github.com/derekr)
|
|
15
|
-
- [Martin Pitt](https://github.com/Martin-Pitt)
|
|
16
|
-
- [Ryan Yogan](https://github.com/ryanyogan)
|
|
17
|
-
- [Mihael Konjević](https://github.com/retro)
|
|
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
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var animateStyle = require('./targets/dom/animate-style.cjs.js');
|
|
7
|
-
var index = require('./targets/dom/timeline/index.cjs.js');
|
|
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');
|
|
5
|
+
var dom = require('@motionone/dom');
|
|
11
6
|
|
|
7
|
+
function test() {
|
|
8
|
+
console.log("test");
|
|
9
|
+
}
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
exports.test = test;
|
|
12
|
+
Object.keys(dom).forEach(function (k) {
|
|
13
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return dom[k]; }
|
|
16
|
+
});
|
|
17
|
+
});
|
package/dist/main.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export * from '@motionone/dom';
|
|
2
|
+
|
|
3
|
+
function test() {
|
|
4
|
+
console.log("test");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { test };
|
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,{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),m=t=>p.has(t),y=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.cancelTimestamp=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.cancelTimestamp),this.reject(!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 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 $=m(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=y(a)})(t,e);const E=function(t){return o[t]&&(t=o[t]),m(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]):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(),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,m=void 0===r?p:r(p);h.target=m,m!==p&&(d=m-t);const y=t=>-d*Math.exp(-t/a),g=t=>m+y(t),v=t=>{const n=y(t),a=g(t);h.done=Math.abs(n)<=c,h.value=h.done?m: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 m=et(h.delay,t,p)||0,y=c+m,g=y+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,y,g),f=Math.max(m+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})}));
|
|
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}};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(),D=s;const $=v(e);$&&((t,e)=>{c[e]&&(e=c[e]);const{transforms:a}=n(t);i(a,e),t.style.transform=g(a)})(t,e);const R=K(e),C=f.get(R);return Y(E.animations[R]),()=>{const e=()=>{var e,n;return null!==(n=null!==(e=X.get(t,R))&&void 0!==e?e:null==C?void 0:C.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,$,R,E);p=t.easing,void 0!==t.keyframes&&(n=t.keyframes),void 0!==t.duration&&(l=t.duration)}if(b(R)?(D=((t,e)=>n=>t.style.setProperty(e,n))(t,R),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){}}}(R):j=!1):D=((t,e)=>n=>t.style[e]=n)(t,R),j){C&&(n=n.map((t=>M(t)?C.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({[R]: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((()=>{D(a),o.cancel()})).catch(s),A||(o.playbackRate=1.000001)}else if($&&n.every(M)){if(1===n.length&&n.unshift(parseFloat(e())),C){const t=D;D=e=>t(C.toDefaultUnit(e))}o=new G(D,n,Object.assign(Object.assign({},r),{duration:l,easing:p}))}else{const t=n[n.length-1];D(C&&M(t)?C.toDefaultUnit(t):t)}return E.animations[R]=o,null==o||o.finished.then((()=>{E.animations[R]=void 0,E.generators[R]=void 0,E.prevGeneratorState[R]=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),new Promise((t=>{setTimeout((()=>t()),100)}))):Promise.resolve(),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.test=function(){console.log("test")},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})}));
|
package/dist/motion.umd.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Motion = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const data = new WeakMap();
|
|
8
8
|
function getAnimationData(element) {
|
|
@@ -362,6 +362,7 @@
|
|
|
362
362
|
? easing.map(getEasingFunction)
|
|
363
363
|
: getEasingFunction(easing));
|
|
364
364
|
this.tick = (timestamp) => {
|
|
365
|
+
var _a;
|
|
365
366
|
if (this.pauseTime)
|
|
366
367
|
timestamp = this.pauseTime;
|
|
367
368
|
let t = (timestamp - this.startTime) * this.rate;
|
|
@@ -415,7 +416,7 @@
|
|
|
415
416
|
const isAnimationFinished = this.playState === "finished" || t >= totalDuration + endDelay;
|
|
416
417
|
if (isAnimationFinished) {
|
|
417
418
|
this.playState = "finished";
|
|
418
|
-
this.resolve(latest);
|
|
419
|
+
(_a = this.resolve) === null || _a === void 0 ? void 0 : _a.call(this, latest);
|
|
419
420
|
}
|
|
420
421
|
else if (this.playState !== "idle") {
|
|
421
422
|
requestAnimationFrame(this.tick);
|
|
@@ -444,9 +445,10 @@
|
|
|
444
445
|
this.tick(0);
|
|
445
446
|
}
|
|
446
447
|
cancel() {
|
|
448
|
+
var _a;
|
|
447
449
|
this.playState = "idle";
|
|
448
450
|
this.tick(this.cancelTimestamp);
|
|
449
|
-
this.reject(false);
|
|
451
|
+
(_a = this.reject) === null || _a === void 0 ? void 0 : _a.call(this, false);
|
|
450
452
|
}
|
|
451
453
|
reverse() {
|
|
452
454
|
this.rate *= -1;
|
|
@@ -483,8 +485,15 @@
|
|
|
483
485
|
}
|
|
484
486
|
const keyframesList = (keyframes) => Array.isArray(keyframes) ? keyframes : [keyframes];
|
|
485
487
|
|
|
488
|
+
function getStyleName(key) {
|
|
489
|
+
if (transformAlias[key])
|
|
490
|
+
key = transformAlias[key];
|
|
491
|
+
return isTransform(key) ? asTransformCssVar(key) : key;
|
|
492
|
+
}
|
|
493
|
+
|
|
486
494
|
const style = {
|
|
487
495
|
get: (element, name) => {
|
|
496
|
+
name = getStyleName(name);
|
|
488
497
|
let value = isCssVar(name)
|
|
489
498
|
? element.style.getPropertyValue(name)
|
|
490
499
|
: getComputedStyle(element)[name];
|
|
@@ -497,12 +506,6 @@
|
|
|
497
506
|
},
|
|
498
507
|
};
|
|
499
508
|
|
|
500
|
-
function getStyleName(key) {
|
|
501
|
-
if (transformAlias[key])
|
|
502
|
-
key = transformAlias[key];
|
|
503
|
-
return isTransform(key) ? asTransformCssVar(key) : key;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
509
|
function stopAnimation(animation) {
|
|
507
510
|
if (!animation)
|
|
508
511
|
return;
|
|
@@ -837,6 +840,15 @@
|
|
|
837
840
|
return t;
|
|
838
841
|
}
|
|
839
842
|
|
|
843
|
+
var invariant = function () { };
|
|
844
|
+
{
|
|
845
|
+
invariant = function (check, message) {
|
|
846
|
+
if (!check) {
|
|
847
|
+
throw new Error(message);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
840
852
|
function calcNextTime(current, next, prev, labels) {
|
|
841
853
|
var _a;
|
|
842
854
|
if (isNumber(next)) {
|
|
@@ -940,9 +952,22 @@
|
|
|
940
952
|
const elementSequence = getElementSequence(element, elementSequences);
|
|
941
953
|
for (const key in keyframes) {
|
|
942
954
|
const valueSequence = getValueSequence(key, elementSequence);
|
|
943
|
-
|
|
955
|
+
let valueKeyframes = keyframesList(keyframes[key]);
|
|
944
956
|
const valueOptions = getOptions(options, key);
|
|
945
957
|
let { duration = defaultOptions.duration || defaults.duration, easing = defaultOptions.easing || defaults.easing, } = valueOptions;
|
|
958
|
+
if (isCustomEasing(easing)) {
|
|
959
|
+
const valueIsTransform = isTransform(key);
|
|
960
|
+
invariant(valueKeyframes.length === 2 || !valueIsTransform, "spring must be provided 2 keyframes within timeline");
|
|
961
|
+
const custom = easing.createAnimation(valueKeyframes,
|
|
962
|
+
// TODO We currently only support explicit keyframes
|
|
963
|
+
// so this doesn't currently read from the DOM
|
|
964
|
+
() => "0", valueIsTransform);
|
|
965
|
+
easing = custom.easing;
|
|
966
|
+
if (custom.keyframes !== undefined)
|
|
967
|
+
valueKeyframes = custom.keyframes;
|
|
968
|
+
if (custom.duration !== undefined)
|
|
969
|
+
duration = custom.duration;
|
|
970
|
+
}
|
|
946
971
|
const delay = resolveOption(options.delay, elementIndex, numElements) || 0;
|
|
947
972
|
const startTime = currentTime + delay;
|
|
948
973
|
const targetTime = startTime + duration;
|
|
@@ -1167,17 +1192,17 @@
|
|
|
1167
1192
|
numKeyframes <= 2 &&
|
|
1168
1193
|
keyframes.every(isNumberOrNull);
|
|
1169
1194
|
if (shouldUseGenerator) {
|
|
1170
|
-
const
|
|
1171
|
-
const velocity =
|
|
1195
|
+
const prevMotionState = name && data && data.prevGeneratorState[name];
|
|
1196
|
+
const velocity = prevMotionState &&
|
|
1172
1197
|
(numKeyframes === 1 ||
|
|
1173
1198
|
(numKeyframes === 2 && keyframes[0] === null))
|
|
1174
|
-
?
|
|
1199
|
+
? prevMotionState.velocity
|
|
1175
1200
|
: 0;
|
|
1176
1201
|
const target = keyframes[numKeyframes - 1];
|
|
1177
1202
|
const unresolvedOrigin = numKeyframes === 1 ? null : keyframes[0];
|
|
1178
1203
|
const origin = unresolvedOrigin === null
|
|
1179
|
-
?
|
|
1180
|
-
?
|
|
1204
|
+
? prevMotionState
|
|
1205
|
+
? prevMotionState.value
|
|
1181
1206
|
: parseFloat(getOrigin())
|
|
1182
1207
|
: unresolvedOrigin;
|
|
1183
1208
|
generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
|
|
@@ -1298,13 +1323,384 @@
|
|
|
1298
1323
|
|
|
1299
1324
|
const glide = createGeneratorEasing(createGlideGenerator);
|
|
1300
1325
|
|
|
1326
|
+
function hasChanged(a, b) {
|
|
1327
|
+
if (typeof a !== typeof b)
|
|
1328
|
+
return true;
|
|
1329
|
+
if (Array.isArray(a) && Array.isArray(b))
|
|
1330
|
+
return !shallowCompare(a, b);
|
|
1331
|
+
return a !== b;
|
|
1332
|
+
}
|
|
1333
|
+
function shallowCompare(next, prev) {
|
|
1334
|
+
const prevLength = prev.length;
|
|
1335
|
+
if (prevLength !== next.length)
|
|
1336
|
+
return false;
|
|
1337
|
+
for (let i = 0; i < prevLength; i++) {
|
|
1338
|
+
if (prev[i] !== next[i])
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
function isVariant(definition) {
|
|
1345
|
+
return typeof definition === "object";
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function resolveVariant(definition, variants) {
|
|
1349
|
+
if (isVariant(definition)) {
|
|
1350
|
+
return definition;
|
|
1351
|
+
}
|
|
1352
|
+
else if (definition && variants) {
|
|
1353
|
+
return variants[definition];
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
let scheduled = undefined;
|
|
1358
|
+
function processScheduledAnimations() {
|
|
1359
|
+
if (!scheduled)
|
|
1360
|
+
return;
|
|
1361
|
+
const generators = scheduled.sort(compareByDepth).map(fireAnimateUpdates);
|
|
1362
|
+
generators.forEach(fireNext);
|
|
1363
|
+
generators.forEach(fireNext);
|
|
1364
|
+
scheduled = undefined;
|
|
1365
|
+
}
|
|
1366
|
+
function scheduleAnimation(state) {
|
|
1367
|
+
if (!scheduled) {
|
|
1368
|
+
scheduled = [state];
|
|
1369
|
+
requestAnimationFrame(processScheduledAnimations);
|
|
1370
|
+
}
|
|
1371
|
+
else {
|
|
1372
|
+
addUniqueItem(scheduled, state);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
function unscheduleAnimation(state) {
|
|
1376
|
+
scheduled && removeItem(scheduled, state);
|
|
1377
|
+
}
|
|
1378
|
+
const compareByDepth = (a, b) => a.getDepth() - b.getDepth();
|
|
1379
|
+
const fireAnimateUpdates = (state) => state.animateUpdates();
|
|
1380
|
+
const fireNext = (iterator) => iterator.next();
|
|
1381
|
+
|
|
1382
|
+
const motionEvent = (name, target) => new CustomEvent(name, { detail: { target } });
|
|
1383
|
+
function dispatchPointerEvent(element, name, event) {
|
|
1384
|
+
element.dispatchEvent(new CustomEvent(name, { detail: { originalEvent: event } }));
|
|
1385
|
+
}
|
|
1386
|
+
function dispatchViewEvent(element, name, entry) {
|
|
1387
|
+
element.dispatchEvent(new CustomEvent(name, { detail: { originalEntry: entry } }));
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* TODO: Support viewport options
|
|
1392
|
+
*/
|
|
1393
|
+
const inView = {
|
|
1394
|
+
isActive: (options) => Boolean(options.inView),
|
|
1395
|
+
subscribe: (element, { enable, disable }) => {
|
|
1396
|
+
let isVisible = false;
|
|
1397
|
+
if (typeof IntersectionObserver !== "undefined") {
|
|
1398
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
1399
|
+
if (!isVisible && entry.isIntersecting) {
|
|
1400
|
+
enable();
|
|
1401
|
+
dispatchViewEvent(element, "viewenter", entry);
|
|
1402
|
+
}
|
|
1403
|
+
else if (isVisible && !entry.isIntersecting) {
|
|
1404
|
+
disable();
|
|
1405
|
+
dispatchViewEvent(element, "viewleave", entry);
|
|
1406
|
+
}
|
|
1407
|
+
isVisible = entry.isIntersecting;
|
|
1408
|
+
});
|
|
1409
|
+
observer.observe(element);
|
|
1410
|
+
return () => {
|
|
1411
|
+
observer.unobserve(element);
|
|
1412
|
+
observer.disconnect();
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
else {
|
|
1416
|
+
enable();
|
|
1417
|
+
return () => { };
|
|
1418
|
+
}
|
|
1419
|
+
},
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
const mouseEvent = (element, name, action) => (event) => {
|
|
1423
|
+
if (event.pointerType && event.pointerType !== "mouse")
|
|
1424
|
+
return;
|
|
1425
|
+
action();
|
|
1426
|
+
dispatchPointerEvent(element, name, event);
|
|
1427
|
+
};
|
|
1428
|
+
const hover = {
|
|
1429
|
+
isActive: (options) => Boolean(options.hover),
|
|
1430
|
+
subscribe: (element, { enable, disable }) => {
|
|
1431
|
+
const onEnter = mouseEvent(element, "hoverstart", enable);
|
|
1432
|
+
const onLeave = mouseEvent(element, "hoverend", disable);
|
|
1433
|
+
element.addEventListener("pointerenter", onEnter);
|
|
1434
|
+
element.addEventListener("pointerleave", onLeave);
|
|
1435
|
+
return () => {
|
|
1436
|
+
element.removeEventListener("pointerenter", onEnter);
|
|
1437
|
+
element.removeEventListener("pointerleave", onLeave);
|
|
1438
|
+
};
|
|
1439
|
+
},
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
const press = {
|
|
1443
|
+
isActive: (options) => Boolean(options.press),
|
|
1444
|
+
subscribe: (element, { enable, disable }) => {
|
|
1445
|
+
const onPointerUp = (event) => {
|
|
1446
|
+
disable();
|
|
1447
|
+
dispatchPointerEvent(element, "pressend", event);
|
|
1448
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
1449
|
+
};
|
|
1450
|
+
const onPointerDown = (event) => {
|
|
1451
|
+
enable();
|
|
1452
|
+
dispatchPointerEvent(element, "pressstart", event);
|
|
1453
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
1454
|
+
};
|
|
1455
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
1456
|
+
return () => {
|
|
1457
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
1458
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
1459
|
+
};
|
|
1460
|
+
},
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
const gestures = { inView, hover, press };
|
|
1464
|
+
/**
|
|
1465
|
+
* A list of state types, in priority order. If a value is defined in
|
|
1466
|
+
* a righter-most type, it will override any definition in a lefter-most.
|
|
1467
|
+
*/
|
|
1468
|
+
const stateTypes = ["initial", "animate", ...Object.keys(gestures), "exit"];
|
|
1469
|
+
/**
|
|
1470
|
+
* A global store of all generated motion states. This can be used to lookup
|
|
1471
|
+
* a motion state for a given Element.
|
|
1472
|
+
*/
|
|
1473
|
+
const mountedStates = new WeakMap();
|
|
1474
|
+
function createMotionState(options = {}, parent) {
|
|
1475
|
+
/**
|
|
1476
|
+
* The element represented by the motion state. This is an empty reference
|
|
1477
|
+
* when we create the state to support SSR and allow for later mounting
|
|
1478
|
+
* in view libraries.
|
|
1479
|
+
*
|
|
1480
|
+
* @ts-ignore
|
|
1481
|
+
*/
|
|
1482
|
+
let element;
|
|
1483
|
+
/**
|
|
1484
|
+
* Calculate a depth that we can use to order motion states by tree depth.
|
|
1485
|
+
*/
|
|
1486
|
+
let depth = parent ? parent.getDepth() + 1 : 0;
|
|
1487
|
+
/**
|
|
1488
|
+
* Track which states are currently active.
|
|
1489
|
+
*/
|
|
1490
|
+
const activeStates = { initial: true, animate: true };
|
|
1491
|
+
/**
|
|
1492
|
+
* A map of functions that, when called, will remove event listeners for
|
|
1493
|
+
* a given gesture.
|
|
1494
|
+
*/
|
|
1495
|
+
const gestureSubscriptions = {};
|
|
1496
|
+
/**
|
|
1497
|
+
* Initialise a context to share through motion states. This
|
|
1498
|
+
* will be populated by variant names (if any).
|
|
1499
|
+
*/
|
|
1500
|
+
const context = {};
|
|
1501
|
+
for (const name of stateTypes) {
|
|
1502
|
+
context[name] =
|
|
1503
|
+
typeof options[name] === "string"
|
|
1504
|
+
? options[name]
|
|
1505
|
+
: parent === null || parent === void 0 ? void 0 : parent.getContext()[name];
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* If initial is set to false we use the animate prop as the initial
|
|
1509
|
+
* animation state.
|
|
1510
|
+
*/
|
|
1511
|
+
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
1512
|
+
/**
|
|
1513
|
+
* Destructure an initial target out from the resolved initial variant.
|
|
1514
|
+
*/
|
|
1515
|
+
let _a = resolveVariant(options[initialVariantSource] || context[initialVariantSource], options.variants) || {}, target = __rest(_a, ["transition"]);
|
|
1516
|
+
/**
|
|
1517
|
+
* The base target is a cached map of values that we'll use to animate
|
|
1518
|
+
* back to if a value is removed from all active state types. This
|
|
1519
|
+
* is usually the initial value as read from the DOM, for instance if
|
|
1520
|
+
* it hasn't been defined in initial.
|
|
1521
|
+
*/
|
|
1522
|
+
const baseTarget = Object.assign({}, target);
|
|
1523
|
+
/**
|
|
1524
|
+
* A generator that will be processed by the global animation scheduler.
|
|
1525
|
+
* This yeilds when it switches from reading the DOM to writing to it
|
|
1526
|
+
* to prevent layout thrashing.
|
|
1527
|
+
*/
|
|
1528
|
+
function* animateUpdates() {
|
|
1529
|
+
var _a, _b;
|
|
1530
|
+
const prevTarget = target;
|
|
1531
|
+
target = {};
|
|
1532
|
+
const resolvedVariants = {};
|
|
1533
|
+
const enteringInto = {};
|
|
1534
|
+
const animationOptions = {};
|
|
1535
|
+
for (const name of stateTypes) {
|
|
1536
|
+
if (!activeStates[name])
|
|
1537
|
+
continue;
|
|
1538
|
+
const variant = resolveVariant(options[name]);
|
|
1539
|
+
if (!variant)
|
|
1540
|
+
continue;
|
|
1541
|
+
resolvedVariants[name] = variant;
|
|
1542
|
+
for (const key in variant) {
|
|
1543
|
+
if (key === "transition")
|
|
1544
|
+
continue;
|
|
1545
|
+
target[key] = variant[key];
|
|
1546
|
+
animationOptions[key] = getOptions((_b = (_a = variant.transition) !== null && _a !== void 0 ? _a : options.transition) !== null && _b !== void 0 ? _b : {}, key);
|
|
1547
|
+
/**
|
|
1548
|
+
* Mark which state type this value is animating into.
|
|
1549
|
+
*/
|
|
1550
|
+
enteringInto[key] = name;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
const allTargetKeys = new Set([
|
|
1554
|
+
...Object.keys(target),
|
|
1555
|
+
...Object.keys(prevTarget),
|
|
1556
|
+
]);
|
|
1557
|
+
const animationFactories = [];
|
|
1558
|
+
allTargetKeys.forEach((key) => {
|
|
1559
|
+
var _a;
|
|
1560
|
+
if (target[key] === undefined) {
|
|
1561
|
+
target[key] = baseTarget[key];
|
|
1562
|
+
}
|
|
1563
|
+
if (hasChanged(prevTarget[key], target[key])) {
|
|
1564
|
+
(_a = baseTarget[key]) !== null && _a !== void 0 ? _a : (baseTarget[key] = style.get(element, key));
|
|
1565
|
+
animationFactories.push(animateStyle(element, key, target[key], animationOptions[key]));
|
|
1566
|
+
}
|
|
1567
|
+
});
|
|
1568
|
+
// Wait for all animation states to read from the DOM
|
|
1569
|
+
yield;
|
|
1570
|
+
const animations = animationFactories
|
|
1571
|
+
.map((factory) => factory())
|
|
1572
|
+
.filter(Boolean);
|
|
1573
|
+
if (!animations.length)
|
|
1574
|
+
return;
|
|
1575
|
+
const animationTarget = target;
|
|
1576
|
+
element.dispatchEvent(motionEvent("motionstart", animationTarget));
|
|
1577
|
+
Promise.all(animations.map((animation) => animation.finished))
|
|
1578
|
+
.then(() => {
|
|
1579
|
+
element.dispatchEvent(motionEvent("motioncomplete", animationTarget));
|
|
1580
|
+
})
|
|
1581
|
+
.catch(noop);
|
|
1582
|
+
}
|
|
1583
|
+
const setGesture = (name, isActive) => () => {
|
|
1584
|
+
activeStates[name] = isActive;
|
|
1585
|
+
scheduleAnimation(state);
|
|
1586
|
+
};
|
|
1587
|
+
const updateGestureSubscriptions = () => {
|
|
1588
|
+
for (const name in gestures) {
|
|
1589
|
+
const isGestureActive = gestures[name].isActive(options);
|
|
1590
|
+
const remove = gestureSubscriptions[name];
|
|
1591
|
+
if (isGestureActive && !remove) {
|
|
1592
|
+
gestureSubscriptions[name] = gestures[name].subscribe(element, {
|
|
1593
|
+
enable: setGesture(name, true),
|
|
1594
|
+
disable: setGesture(name, false),
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
else if (!isGestureActive && remove) {
|
|
1598
|
+
remove();
|
|
1599
|
+
delete gestureSubscriptions[name];
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const state = {
|
|
1604
|
+
update: (newOptions) => {
|
|
1605
|
+
if (!element)
|
|
1606
|
+
return;
|
|
1607
|
+
options = newOptions;
|
|
1608
|
+
updateGestureSubscriptions();
|
|
1609
|
+
scheduleAnimation(state);
|
|
1610
|
+
},
|
|
1611
|
+
setActive: (name, isActive) => {
|
|
1612
|
+
if (!element)
|
|
1613
|
+
return Promise.resolve();
|
|
1614
|
+
activeStates[name] = isActive;
|
|
1615
|
+
scheduleAnimation(state);
|
|
1616
|
+
return new Promise((resolve) => {
|
|
1617
|
+
setTimeout(() => resolve(), 100);
|
|
1618
|
+
});
|
|
1619
|
+
},
|
|
1620
|
+
animateUpdates,
|
|
1621
|
+
getDepth: () => depth,
|
|
1622
|
+
getTarget: () => target,
|
|
1623
|
+
getOptions: () => options,
|
|
1624
|
+
getContext: () => context,
|
|
1625
|
+
mount: (newElement) => {
|
|
1626
|
+
invariant(Boolean(newElement), "Animation state must be mounted with valid Element");
|
|
1627
|
+
element = newElement;
|
|
1628
|
+
mountedStates.set(element, state);
|
|
1629
|
+
updateGestureSubscriptions();
|
|
1630
|
+
return () => {
|
|
1631
|
+
mountedStates.delete(element);
|
|
1632
|
+
unscheduleAnimation(state);
|
|
1633
|
+
for (const key in gestureSubscriptions) {
|
|
1634
|
+
gestureSubscriptions[key]();
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
},
|
|
1638
|
+
isMounted: () => Boolean(element),
|
|
1639
|
+
};
|
|
1640
|
+
return state;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
function createStyles(keyframes) {
|
|
1644
|
+
const initialKeyframes = {};
|
|
1645
|
+
const transformKeys = [];
|
|
1646
|
+
for (let key in keyframes) {
|
|
1647
|
+
const value = keyframes[key];
|
|
1648
|
+
if (isTransform(key)) {
|
|
1649
|
+
if (transformAlias[key])
|
|
1650
|
+
key = transformAlias[key];
|
|
1651
|
+
transformKeys.push(key);
|
|
1652
|
+
key = asTransformCssVar(key);
|
|
1653
|
+
}
|
|
1654
|
+
let initialKeyframe = Array.isArray(value) ? value[0] : value;
|
|
1655
|
+
/**
|
|
1656
|
+
* If this is a number and we have a default value type, convert the number
|
|
1657
|
+
* to this type.
|
|
1658
|
+
*/
|
|
1659
|
+
const definition = transformDefinitions.get(key);
|
|
1660
|
+
if (definition) {
|
|
1661
|
+
initialKeyframe = isNumber(value)
|
|
1662
|
+
? definition.toDefaultUnit(value)
|
|
1663
|
+
: value;
|
|
1664
|
+
}
|
|
1665
|
+
initialKeyframes[key] = initialKeyframe;
|
|
1666
|
+
}
|
|
1667
|
+
if (transformKeys.length) {
|
|
1668
|
+
initialKeyframes.transform = buildTransformTemplate(transformKeys);
|
|
1669
|
+
}
|
|
1670
|
+
return initialKeyframes;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
const camelLetterToPipeLetter = (letter) => `-${letter.toLowerCase()}`;
|
|
1674
|
+
const camelToPipeCase = (str) => str.replace(/[A-Z]/g, camelLetterToPipeLetter);
|
|
1675
|
+
function createStyleString(target = {}) {
|
|
1676
|
+
const styles = createStyles(target);
|
|
1677
|
+
let style = "";
|
|
1678
|
+
for (const key in styles) {
|
|
1679
|
+
style += key.startsWith("--") ? key : camelToPipeCase(key);
|
|
1680
|
+
style += `: ${styles[key]}; `;
|
|
1681
|
+
}
|
|
1682
|
+
return style;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
function test() {
|
|
1686
|
+
console.log("test");
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1301
1689
|
exports.animate = animate;
|
|
1302
1690
|
exports.animateStyle = animateStyle;
|
|
1691
|
+
exports.createMotionState = createMotionState;
|
|
1692
|
+
exports.createStyleString = createStyleString;
|
|
1693
|
+
exports.createStyles = createStyles;
|
|
1694
|
+
exports.getAnimationData = getAnimationData;
|
|
1695
|
+
exports.getStyleName = getStyleName;
|
|
1303
1696
|
exports.glide = glide;
|
|
1697
|
+
exports.mountedStates = mountedStates;
|
|
1304
1698
|
exports.spring = spring;
|
|
1305
1699
|
exports.stagger = stagger;
|
|
1700
|
+
exports.style = style;
|
|
1701
|
+
exports.test = test;
|
|
1306
1702
|
exports.timeline = timeline;
|
|
1307
1703
|
|
|
1308
1704
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1309
1705
|
|
|
1310
|
-
}))
|
|
1706
|
+
}));
|