framer-motion 12.23.20 → 12.23.22
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 +1 -1
- package/dist/cjs/dom.js +2 -1
- package/dist/cjs/index.js +6 -1
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +123 -1
- package/dist/dom.js +1 -1
- package/dist/es/components/AnimatePresence/PopChild.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/render/dom/scroll/attach-animation.mjs +2 -1
- package/dist/es/{components/AnimatePresence → utils}/use-composed-ref.mjs +3 -0
- package/dist/framer-motion.dev.js +31 -6
- package/dist/framer-motion.js +1 -1
- package/dist/mini.js +1 -1
- package/dist/size-rollup-animate.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/size-rollup-scroll.js +1 -1
- package/dist/size-rollup-waapi-animate.js +1 -1
- package/dist/types/index.d.ts +93 -82
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -122,7 +122,7 @@ Motion powers Framer animations, the web builder for creative pros. Design and s
|
|
|
122
122
|
|
|
123
123
|
### Gold
|
|
124
124
|
|
|
125
|
-
<a href="https://tailwindcss.com"><img alt="Tailwind" src="https://github.com/user-attachments/assets/1d5f2571-8bc3-4367-9fec-14d291168ff0" width="200px" height="120px"></a> <a href="https://emilkowal.ski"><img alt="Emil Kowalski" src="https://github.com/user-attachments/assets/33d1cb98-238a-4eed-a0df-9c7ab097d65b" width="200px" height="120px"></a> <a href="https://liveblocks.io"><img alt="Liveblocks" src="https://github.com/user-attachments/assets/28eddbe5-1617-4e74-969d-2eb6fcd481af" width="200px" height="120px"></a> <a href="https://vercel.com"><img alt="Vercel" src="https://github.com/user-attachments/assets/abc473bd-07ae-4a7d-9833-efe9dadb3773" width="200px" height="120px"></a> <a href="https://lu.ma"><img alt="Luma" src="https://github.com/user-attachments/assets/ac282433-6adb-4ad2-9fd2-5c6ee513c14b" width="200px" height="120px"></a>
|
|
125
|
+
<a href="https://tailwindcss.com"><img alt="Tailwind" src="https://github.com/user-attachments/assets/1d5f2571-8bc3-4367-9fec-14d291168ff0" width="200px" height="120px"></a> <a href="https://emilkowal.ski"><img alt="Emil Kowalski" src="https://github.com/user-attachments/assets/33d1cb98-238a-4eed-a0df-9c7ab097d65b" width="200px" height="120px"></a> <a href="https://liveblocks.io"><img alt="Liveblocks" src="https://github.com/user-attachments/assets/28eddbe5-1617-4e74-969d-2eb6fcd481af" width="200px" height="120px"></a> <a href="https://vercel.com"><img alt="Vercel" src="https://github.com/user-attachments/assets/abc473bd-07ae-4a7d-9833-efe9dadb3773" width="200px" height="120px"></a> <a href="https://lu.ma"><img alt="Luma" src="https://github.com/user-attachments/assets/ac282433-6adb-4ad2-9fd2-5c6ee513c14b" width="200px" height="120px"></a> <a href="https://notion.com"><img alt="Notion" src="https://github.com/user-attachments/assets/a27a6033-3cb0-4232-a6bb-625e1824517b" width="200px" height="120px"></a>
|
|
126
126
|
|
|
127
127
|
### Silver
|
|
128
128
|
|
package/dist/cjs/dom.js
CHANGED
|
@@ -2368,7 +2368,8 @@ function attachToAnimation(animation, options) {
|
|
|
2368
2368
|
observe: (valueAnimation) => {
|
|
2369
2369
|
valueAnimation.pause();
|
|
2370
2370
|
return motionDom.observeTimeline((progress) => {
|
|
2371
|
-
valueAnimation.time =
|
|
2371
|
+
valueAnimation.time =
|
|
2372
|
+
valueAnimation.iterationDuration * progress;
|
|
2372
2373
|
}, timeline);
|
|
2373
2374
|
},
|
|
2374
2375
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,9 @@ function _interopNamespaceDefault(e) {
|
|
|
27
27
|
|
|
28
28
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Taken from https://github.com/radix-ui/primitives/blob/main/packages/react/compose-refs/src/compose-refs.tsx
|
|
32
|
+
*/
|
|
30
33
|
/**
|
|
31
34
|
* Set a given ref to a given value
|
|
32
35
|
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
@@ -1804,7 +1807,8 @@ function attachToAnimation(animation, options) {
|
|
|
1804
1807
|
observe: (valueAnimation) => {
|
|
1805
1808
|
valueAnimation.pause();
|
|
1806
1809
|
return motionDom.observeTimeline((progress) => {
|
|
1807
|
-
valueAnimation.time =
|
|
1810
|
+
valueAnimation.time =
|
|
1811
|
+
valueAnimation.iterationDuration * progress;
|
|
1808
1812
|
}, timeline);
|
|
1809
1813
|
},
|
|
1810
1814
|
});
|
|
@@ -2986,6 +2990,7 @@ exports.useAnimateMini = useAnimateMini;
|
|
|
2986
2990
|
exports.useAnimation = useAnimation;
|
|
2987
2991
|
exports.useAnimationControls = useAnimationControls;
|
|
2988
2992
|
exports.useAnimationFrame = useAnimationFrame;
|
|
2993
|
+
exports.useComposedRefs = useComposedRefs;
|
|
2989
2994
|
exports.useCycle = useCycle;
|
|
2990
2995
|
exports.useDeprecatedAnimatedState = useAnimatedState;
|
|
2991
2996
|
exports.useDeprecatedInvertedScale = useInvertedScale;
|
package/dist/dom-mini.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";function e(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function n(t){let e;return()=>(void 0===e&&(e=t()),e)}const i=t=>t,s=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},o=t=>1e3*t,a=t=>t/1e3;function r(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const l=(t,e,n)=>t+(e-t)*n,u=2e4;function h(t,e=100,n){const i=n({...t,keyframes:[0,e]}),s=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<u;)e+=50,n=t.next(e);return e>=u?1/0:e}(i),u);return{type:"keyframes",ease:t=>i.next(s*t).value/e,duration:a(s)}}function c(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const o=s(0,e,i);t.push(l(n,1,o))}}function f(t){const e=[0];return c(e,t.length-1),e}const m=t=>null!==t;class d{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(t=>{this.resolve=t})}notifyFinished(){this.resolve()}then(t,e){return this.finished.then(t,e)}}function p(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}const y=t=>t.startsWith("--");const g=n(()=>void 0!==window.ScrollTimeline),A={};function b(t,e){const i=n(t);return()=>A[e]??i()}const T=b(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),v=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,M={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:v([0,.65,.55,1]),circOut:v([.55,0,1,.45]),backIn:v([.31,.01,.66,-.59]),backOut:v([.33,1.53,.69,.99])};function w(t,e){return t?"function"==typeof t?T()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;e<s;e++)i+=Math.round(1e4*t(e/(s-1)))/1e4+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):"ease-out":(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?v(t):Array.isArray(t)?t.map(t=>w(t,e)||M.easeOut):M[t]:void 0}function k(t){return"function"==typeof t&&"applyToOptions"in t}class x extends d{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,!t)return;const{element:e,name:n,keyframes:i,pseudoElement:s,allowFlatten:o=!1,finalKeyframe:a,onComplete:r}=t;this.isPseudoElement=Boolean(s),this.allowFlatten=o,this.options=t,t.type;const l=function({type:t,...e}){return k(t)&&T()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(t);this.animation=function(t,e,n,{delay:i=0,duration:s=300,repeat:o=0,repeatType:a="loop",ease:r="easeOut",times:l}={},u){const h={[e]:n};l&&(h.offset=l);const c=w(r,s);Array.isArray(c)&&(h.easing=c);const f={delay:i,duration:s,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:o+1,direction:"reverse"===a?"alternate":"normal"};return u&&(f.pseudoElement=u),t.animate(h,f)}(e,n,i,l,s),!1===l.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!s){const t=function(t,{repeat:e,repeatType:n="loop"},i,s=1){const o=t.filter(m),a=s<0||e&&"loop"!==n&&e%2==1?0:o.length-1;return a&&void 0!==i?i:o[a]}(i,this.options,a,this.speed);this.updateMotionValue?this.updateMotionValue(t):function(t,e,n){y(e)?t.style.setProperty(e,n):t.style[e]=n}(e,n,t),this.animation.cancel()}r?.(),this.notifyFinished()}}play(){this.isStopped||(this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return a(Number(t))}get time(){return a(Number(this.animation.currentTime)||0)}set time(t){this.finishedTime=null,this.animation.currentTime=o(t)}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return Number(this.animation.startTime)}set startTime(t){this.animation.startTime=t}attachTimeline({timeline:t,observe:e}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&g()?(this.animation.timeline=t,i):e(this)}}class E{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t){const e=this.animations.map(e=>e.attachTimeline(t));return()=>{e.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}class O extends E{then(t,e){return this.finished.finally(t).then(()=>{})}}const S=new WeakMap,R=(t,e="")=>`${t}:${e}`;function F(t){const e=S.get(t)||new Map;return S.set(t,e),e}function W(t,e){return t?.[e]??t?.default??t}const P=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","backgroundPositionX","backgroundPositionY"]);function B(t,e){for(let n=0;n<t.length;n++)"number"==typeof t[n]&&P.has(e)&&(t[n]=t[n]+"px")}function $(t,e,n){if(t instanceof EventTarget)return[t];if("string"==typeof t){let e=document;const i=n?.[t]??e.querySelectorAll(t);return i?Array.from(i):[]}return Array.from(t)}function L(t,e){const n=window.getComputedStyle(t);return y(e)?n.getPropertyValue(e):n[e]}const V=t=>Boolean(t&&t.getVelocity);function I(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?$(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function N(t,e,n){return t*(e+1)}function C(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:e.startsWith("<")?Math.max(0,n+parseFloat(e.slice(1))):i.get(e)??t}function K(t,n,i,s,o,a){!function(t,n,i){for(let s=0;s<t.length;s++){const o=t[s];o.at>n&&o.at<i&&(e(t,o),s--)}}(t,o,a);for(let e=0;e<n.length;e++)t.push({value:n[e],at:l(o,a,s[e]),easing:r(i,e)})}function j(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function q(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function _(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function z(t,e){return e[t]||(e[t]=[]),e[t]}function D(t){return Array.isArray(t)?t:[t]}function H(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const X=t=>"number"==typeof t,Y=t=>t.every(X);function G(t,e,n,i){const s=$(t),a=s.length,r=[];for(let t=0;t<a;t++){const i=s[t],l={...n};"function"==typeof l.delay&&(l.delay=l.delay(t,a));for(const t in e){let n=e[t];Array.isArray(n)||(n=[n]);const s={...W(l,t)};s.duration&&(s.duration=o(s.duration)),s.delay&&(s.delay=o(s.delay));const a=F(i),u=R(t,s.pseudoElement||""),h=a.get(u);h&&h.stop(),r.push({map:a,key:u,unresolvedKeyframes:n,options:{...s,element:i,name:t,allowFlatten:!l.type&&!l.ease}})}}for(let t=0;t<r.length;t++){const{unresolvedKeyframes:e,options:n}=r[t],{element:i,name:s,pseudoElement:o}=n;o||null!==e[0]||(e[0]=L(i,s)),p(e),B(e,s),!o&&e.length<2&&e.unshift(L(i,s)),n.keyframes=e}const l=[];for(let t=0;t<r.length;t++){const{map:e,key:n,options:i}=r[t],s=new x(i);e.set(n,s),s.finished.finally(()=>e.delete(n)),l.push(s)}return l}const J=(()=>function(t,e,n){return new O(G(t,e,n))})();t.animate=J,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const l=e.duration||.3,u=new Map,m=new Map,d={},p=new Map;let y=0,g=0,A=0;for(let n=0;n<t.length;n++){const i=t[n];if("string"==typeof i){p.set(i,g);continue}if(!Array.isArray(i)){p.set(i.name,C(g,i.at,y,p));continue}let[s,u,b={}]=i;void 0!==b.at&&(g=C(g,b.at,y,p));let T=0;const v=(t,n,i,s=0,u=0)=>{const m=D(t),{delay:d=0,times:p=f(m),type:y="keyframes",repeat:b,repeatType:v,repeatDelay:M=0,...w}=n;let{ease:x=e.ease||"easeOut",duration:E}=n;const O="function"==typeof d?d(s,u):d,S=m.length,R=k(y)?y:a?.[y||"keyframes"];if(S<=2&&R){let t=100;if(2===S&&Y(m)){const e=m[1]-m[0];t=Math.abs(e)}const e={...w};void 0!==E&&(e.duration=o(E));const n=h(e,t,R);x=n.ease,E=n.duration}E??(E=l);const F=g+O;1===p.length&&0===p[0]&&(p[1]=1);const W=p.length-m.length;if(W>0&&c(p,W),1===m.length&&m.unshift(null),b){E=N(E,b);const t=[...m],e=[...p];x=Array.isArray(x)?[...x]:[x];const n=[...x];for(let i=0;i<b;i++){m.push(...t);for(let s=0;s<t.length;s++)p.push(e[s]+(i+1)),x.push(0===s?"linear":r(n,s-1))}j(p,b)}const P=F+E;K(i,m,x,p,F,P),T=Math.max(O+E,T),A=Math.max(P,A)};if(V(s))v(u,b,z("default",_(s,m)));else{const t=I(s,u,0,d),e=t.length;for(let n=0;n<e;n++){const i=_(t[n],m);for(const t in u)v(u[t],H(b,t),z(t,i),n,e)}}y=g,g+=T}return m.forEach((t,i)=>{for(const o in t){const a=t[o];a.sort(q);const r=[],l=[],h=[];for(let t=0;t<a.length;t++){const{at:e,value:n,easing:i}=a[t];r.push(n),l.push(s(0,A,e)),h.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),r.unshift(r[0]),h.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),r.push(null)),u.has(i)||u.set(i,{keyframes:{},transition:{}});const c=u.get(i);c.keyframes[o]=r,c.transition[o]={...e,duration:A,ease:h,times:l,...n}}}),u}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...G(i,t,e))}),new O(n)}});
|
|
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";function e(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function n(t){let e;return()=>(void 0===e&&(e=t()),e)}const i=t=>t,s=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},o=t=>1e3*t,a=t=>t/1e3;function r(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const u=(t,e,n)=>t+(e-t)*n,l=2e4;function h(t,e=100,n){const i=n({...t,keyframes:[0,e]}),s=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<l;)e+=50,n=t.next(e);return e>=l?1/0:e}(i),l);return{type:"keyframes",ease:t=>i.next(s*t).value/e,duration:a(s)}}function c(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const o=s(0,e,i);t.push(u(n,1,o))}}function f(t){const e=[0];return c(e,t.length-1),e}const d=t=>null!==t;class m{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(t=>{this.resolve=t})}notifyFinished(){this.resolve()}then(t,e){return this.finished.then(t,e)}}function p(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}const y=t=>t.startsWith("--");const g=n(()=>void 0!==window.ScrollTimeline),A={};function b(t,e){const i=n(t);return()=>A[e]??i()}const T=b(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),v=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,w={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:v([0,.65,.55,1]),circOut:v([.55,0,1,.45]),backIn:v([.31,.01,.66,-.59]),backOut:v([.33,1.53,.69,.99])};function M(t,e){return t?"function"==typeof t?T()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;e<s;e++)i+=Math.round(1e4*t(e/(s-1)))/1e4+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):"ease-out":(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?v(t):Array.isArray(t)?t.map(t=>M(t,e)||w.easeOut):w[t]:void 0}function k(t){return"function"==typeof t&&"applyToOptions"in t}class x extends m{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,!t)return;const{element:e,name:n,keyframes:i,pseudoElement:s,allowFlatten:o=!1,finalKeyframe:a,onComplete:r}=t;this.isPseudoElement=Boolean(s),this.allowFlatten=o,this.options=t,t.type;const u=function({type:t,...e}){return k(t)&&T()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(t);this.animation=function(t,e,n,{delay:i=0,duration:s=300,repeat:o=0,repeatType:a="loop",ease:r="easeOut",times:u}={},l){const h={[e]:n};u&&(h.offset=u);const c=M(r,s);Array.isArray(c)&&(h.easing=c);const f={delay:i,duration:s,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:o+1,direction:"reverse"===a?"alternate":"normal"};return l&&(f.pseudoElement=l),t.animate(h,f)}(e,n,i,u,s),!1===u.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!s){const t=function(t,{repeat:e,repeatType:n="loop"},i,s=1){const o=t.filter(d),a=s<0||e&&"loop"!==n&&e%2==1?0:o.length-1;return a&&void 0!==i?i:o[a]}(i,this.options,a,this.speed);this.updateMotionValue?this.updateMotionValue(t):function(t,e,n){y(e)?t.style.setProperty(e,n):t.style[e]=n}(e,n,t),this.animation.cancel()}r?.(),this.notifyFinished()}}play(){this.isStopped||(this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return a(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+a(t)}get time(){return a(Number(this.animation.currentTime)||0)}set time(t){this.finishedTime=null,this.animation.currentTime=o(t)}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return Number(this.animation.startTime)}set startTime(t){this.animation.startTime=t}attachTimeline({timeline:t,observe:e}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&g()?(this.animation.timeline=t,i):e(this)}}class E{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t){const e=this.animations.map(e=>e.attachTimeline(t));return()=>{e.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return O(this.animations,"duration")}get iterationDuration(){return O(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(e=>e[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function O(t,e){let n=0;for(let i=0;i<t.length;i++){const s=t[i][e];null!==s&&s>n&&(n=s)}return n}class S extends E{then(t,e){return this.finished.finally(t).then(()=>{})}}const R=new WeakMap,F=(t,e="")=>`${t}:${e}`;function W(t){const e=R.get(t)||new Map;return R.set(t,e),e}function P(t,e){return t?.[e]??t?.default??t}const B=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","backgroundPositionX","backgroundPositionY"]);function $(t,e){for(let n=0;n<t.length;n++)"number"==typeof t[n]&&B.has(e)&&(t[n]=t[n]+"px")}function L(t,e,n){if(t instanceof EventTarget)return[t];if("string"==typeof t){let e=document;const i=n?.[t]??e.querySelectorAll(t);return i?Array.from(i):[]}return Array.from(t)}function V(t,e){const n=window.getComputedStyle(t);return y(e)?n.getPropertyValue(e):n[e]}const I=t=>Boolean(t&&t.getVelocity);function D(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?L(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function N(t,e,n){return t*(e+1)}function C(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:e.startsWith("<")?Math.max(0,n+parseFloat(e.slice(1))):i.get(e)??t}function K(t,n,i,s,o,a){!function(t,n,i){for(let s=0;s<t.length;s++){const o=t[s];o.at>n&&o.at<i&&(e(t,o),s--)}}(t,o,a);for(let e=0;e<n.length;e++)t.push({value:n[e],at:u(o,a,s[e]),easing:r(i,e)})}function j(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function q(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function _(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function z(t,e){return e[t]||(e[t]=[]),e[t]}function H(t){return Array.isArray(t)?t:[t]}function X(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const Y=t=>"number"==typeof t,G=t=>t.every(Y);function J(t,e,n,i){const s=L(t),a=s.length,r=[];for(let t=0;t<a;t++){const i=s[t],u={...n};"function"==typeof u.delay&&(u.delay=u.delay(t,a));for(const t in e){let n=e[t];Array.isArray(n)||(n=[n]);const s={...P(u,t)};s.duration&&(s.duration=o(s.duration)),s.delay&&(s.delay=o(s.delay));const a=W(i),l=F(t,s.pseudoElement||""),h=a.get(l);h&&h.stop(),r.push({map:a,key:l,unresolvedKeyframes:n,options:{...s,element:i,name:t,allowFlatten:!u.type&&!u.ease}})}}for(let t=0;t<r.length;t++){const{unresolvedKeyframes:e,options:n}=r[t],{element:i,name:s,pseudoElement:o}=n;o||null!==e[0]||(e[0]=V(i,s)),p(e),$(e,s),!o&&e.length<2&&e.unshift(V(i,s)),n.keyframes=e}const u=[];for(let t=0;t<r.length;t++){const{map:e,key:n,options:i}=r[t],s=new x(i);e.set(n,s),s.finished.finally(()=>e.delete(n)),u.push(s)}return u}const Q=(()=>function(t,e,n){return new S(J(t,e,n))})();t.animate=Q,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const u=e.duration||.3,l=new Map,d=new Map,m={},p=new Map;let y=0,g=0,A=0;for(let n=0;n<t.length;n++){const i=t[n];if("string"==typeof i){p.set(i,g);continue}if(!Array.isArray(i)){p.set(i.name,C(g,i.at,y,p));continue}let[s,l,b={}]=i;void 0!==b.at&&(g=C(g,b.at,y,p));let T=0;const v=(t,n,i,s=0,l=0)=>{const d=H(t),{delay:m=0,times:p=f(d),type:y="keyframes",repeat:b,repeatType:v,repeatDelay:w=0,...M}=n;let{ease:x=e.ease||"easeOut",duration:E}=n;const O="function"==typeof m?m(s,l):m,S=d.length,R=k(y)?y:a?.[y||"keyframes"];if(S<=2&&R){let t=100;if(2===S&&G(d)){const e=d[1]-d[0];t=Math.abs(e)}const e={...M};void 0!==E&&(e.duration=o(E));const n=h(e,t,R);x=n.ease,E=n.duration}E??(E=u);const F=g+O;1===p.length&&0===p[0]&&(p[1]=1);const W=p.length-d.length;if(W>0&&c(p,W),1===d.length&&d.unshift(null),b){E=N(E,b);const t=[...d],e=[...p];x=Array.isArray(x)?[...x]:[x];const n=[...x];for(let i=0;i<b;i++){d.push(...t);for(let s=0;s<t.length;s++)p.push(e[s]+(i+1)),x.push(0===s?"linear":r(n,s-1))}j(p,b)}const P=F+E;K(i,d,x,p,F,P),T=Math.max(O+E,T),A=Math.max(P,A)};if(I(s))v(l,b,z("default",_(s,d)));else{const t=D(s,l,0,m),e=t.length;for(let n=0;n<e;n++){const i=_(t[n],d);for(const t in l)v(l[t],X(b,t),z(t,i),n,e)}}y=g,g+=T}return d.forEach((t,i)=>{for(const o in t){const a=t[o];a.sort(q);const r=[],u=[],h=[];for(let t=0;t<a.length;t++){const{at:e,value:n,easing:i}=a[t];r.push(n),u.push(s(0,A,e)),h.push(i||"easeOut")}0!==u[0]&&(u.unshift(0),r.unshift(r[0]),h.unshift("easeInOut")),1!==u[u.length-1]&&(u.push(1),r.push(null)),l.has(i)||l.set(i,{keyframes:{},transition:{}});const c=l.get(i);c.keyframes[o]=r,c.transition[o]={...e,duration:A,ease:h,times:u,...n}}}),l}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...J(i,t,e))}),new S(n)}});
|
package/dist/dom.d.ts
CHANGED
|
@@ -142,10 +142,132 @@ interface InViewOptions {
|
|
|
142
142
|
}
|
|
143
143
|
declare function inView(elementOrSelector: ElementOrSelector, onStart: (element: Element, entry: IntersectionObserverEntry) => void | ViewChangeHandler, { root, margin: rootMargin, amount }?: InViewOptions): VoidFunction;
|
|
144
144
|
|
|
145
|
+
interface HTMLElements {
|
|
146
|
+
a: HTMLAnchorElement;
|
|
147
|
+
abbr: HTMLElement;
|
|
148
|
+
address: HTMLElement;
|
|
149
|
+
area: HTMLAreaElement;
|
|
150
|
+
article: HTMLElement;
|
|
151
|
+
aside: HTMLElement;
|
|
152
|
+
audio: HTMLAudioElement;
|
|
153
|
+
b: HTMLElement;
|
|
154
|
+
base: HTMLBaseElement;
|
|
155
|
+
bdi: HTMLElement;
|
|
156
|
+
bdo: HTMLElement;
|
|
157
|
+
big: HTMLElement;
|
|
158
|
+
blockquote: HTMLQuoteElement;
|
|
159
|
+
body: HTMLBodyElement;
|
|
160
|
+
br: HTMLBRElement;
|
|
161
|
+
button: HTMLButtonElement;
|
|
162
|
+
canvas: HTMLCanvasElement;
|
|
163
|
+
caption: HTMLElement;
|
|
164
|
+
center: HTMLElement;
|
|
165
|
+
cite: HTMLElement;
|
|
166
|
+
code: HTMLElement;
|
|
167
|
+
col: HTMLTableColElement;
|
|
168
|
+
colgroup: HTMLTableColElement;
|
|
169
|
+
data: HTMLDataElement;
|
|
170
|
+
datalist: HTMLDataListElement;
|
|
171
|
+
dd: HTMLElement;
|
|
172
|
+
del: HTMLModElement;
|
|
173
|
+
details: HTMLDetailsElement;
|
|
174
|
+
dfn: HTMLElement;
|
|
175
|
+
dialog: HTMLDialogElement;
|
|
176
|
+
div: HTMLDivElement;
|
|
177
|
+
dl: HTMLDListElement;
|
|
178
|
+
dt: HTMLElement;
|
|
179
|
+
em: HTMLElement;
|
|
180
|
+
embed: HTMLEmbedElement;
|
|
181
|
+
fieldset: HTMLFieldSetElement;
|
|
182
|
+
figcaption: HTMLElement;
|
|
183
|
+
figure: HTMLElement;
|
|
184
|
+
footer: HTMLElement;
|
|
185
|
+
form: HTMLFormElement;
|
|
186
|
+
h1: HTMLHeadingElement;
|
|
187
|
+
h2: HTMLHeadingElement;
|
|
188
|
+
h3: HTMLHeadingElement;
|
|
189
|
+
h4: HTMLHeadingElement;
|
|
190
|
+
h5: HTMLHeadingElement;
|
|
191
|
+
h6: HTMLHeadingElement;
|
|
192
|
+
head: HTMLHeadElement;
|
|
193
|
+
header: HTMLElement;
|
|
194
|
+
hgroup: HTMLElement;
|
|
195
|
+
hr: HTMLHRElement;
|
|
196
|
+
html: HTMLHtmlElement;
|
|
197
|
+
i: HTMLElement;
|
|
198
|
+
iframe: HTMLIFrameElement;
|
|
199
|
+
img: HTMLImageElement;
|
|
200
|
+
input: HTMLInputElement;
|
|
201
|
+
ins: HTMLModElement;
|
|
202
|
+
kbd: HTMLElement;
|
|
203
|
+
keygen: HTMLElement;
|
|
204
|
+
label: HTMLLabelElement;
|
|
205
|
+
legend: HTMLLegendElement;
|
|
206
|
+
li: HTMLLIElement;
|
|
207
|
+
link: HTMLLinkElement;
|
|
208
|
+
main: HTMLElement;
|
|
209
|
+
map: HTMLMapElement;
|
|
210
|
+
mark: HTMLElement;
|
|
211
|
+
menu: HTMLElement;
|
|
212
|
+
menuitem: HTMLElement;
|
|
213
|
+
meta: HTMLMetaElement;
|
|
214
|
+
meter: HTMLMeterElement;
|
|
215
|
+
nav: HTMLElement;
|
|
216
|
+
noindex: HTMLElement;
|
|
217
|
+
noscript: HTMLElement;
|
|
218
|
+
object: HTMLObjectElement;
|
|
219
|
+
ol: HTMLOListElement;
|
|
220
|
+
optgroup: HTMLOptGroupElement;
|
|
221
|
+
option: HTMLOptionElement;
|
|
222
|
+
output: HTMLOutputElement;
|
|
223
|
+
p: HTMLParagraphElement;
|
|
224
|
+
param: HTMLParamElement;
|
|
225
|
+
picture: HTMLElement;
|
|
226
|
+
pre: HTMLPreElement;
|
|
227
|
+
progress: HTMLProgressElement;
|
|
228
|
+
q: HTMLQuoteElement;
|
|
229
|
+
rp: HTMLElement;
|
|
230
|
+
rt: HTMLElement;
|
|
231
|
+
ruby: HTMLElement;
|
|
232
|
+
s: HTMLElement;
|
|
233
|
+
samp: HTMLElement;
|
|
234
|
+
search: HTMLElement;
|
|
235
|
+
slot: HTMLSlotElement;
|
|
236
|
+
script: HTMLScriptElement;
|
|
237
|
+
section: HTMLElement;
|
|
238
|
+
select: HTMLSelectElement;
|
|
239
|
+
small: HTMLElement;
|
|
240
|
+
source: HTMLSourceElement;
|
|
241
|
+
span: HTMLSpanElement;
|
|
242
|
+
strong: HTMLElement;
|
|
243
|
+
style: HTMLStyleElement;
|
|
244
|
+
sub: HTMLElement;
|
|
245
|
+
summary: HTMLElement;
|
|
246
|
+
sup: HTMLElement;
|
|
247
|
+
table: HTMLTableElement;
|
|
248
|
+
template: HTMLTemplateElement;
|
|
249
|
+
tbody: HTMLTableSectionElement;
|
|
250
|
+
td: HTMLTableDataCellElement;
|
|
251
|
+
textarea: HTMLTextAreaElement;
|
|
252
|
+
tfoot: HTMLTableSectionElement;
|
|
253
|
+
th: HTMLTableHeaderCellElement;
|
|
254
|
+
thead: HTMLTableSectionElement;
|
|
255
|
+
time: HTMLTimeElement;
|
|
256
|
+
title: HTMLTitleElement;
|
|
257
|
+
tr: HTMLTableRowElement;
|
|
258
|
+
track: HTMLTrackElement;
|
|
259
|
+
u: HTMLElement;
|
|
260
|
+
ul: HTMLUListElement;
|
|
261
|
+
var: HTMLElement;
|
|
262
|
+
video: HTMLVideoElement;
|
|
263
|
+
wbr: HTMLElement;
|
|
264
|
+
webview: HTMLWebViewElement;
|
|
265
|
+
}
|
|
266
|
+
|
|
145
267
|
type DelayedFunction = (overshoot: number) => void;
|
|
146
268
|
declare function delayInSeconds(callback: DelayedFunction, timeout: number): () => void;
|
|
147
269
|
|
|
148
270
|
declare const distance: (a: number, b: number) => number;
|
|
149
271
|
declare function distance2D(a: Point, b: Point): number;
|
|
150
272
|
|
|
151
|
-
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo };
|
|
273
|
+
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type HTMLElements, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo };
|