framer-motion 12.35.0 → 12.35.2

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.
Files changed (43) hide show
  1. package/dist/cjs/client.js +1 -1
  2. package/dist/cjs/dom.js +1 -1
  3. package/dist/cjs/dom.js.map +1 -1
  4. package/dist/cjs/{feature-bundle-jADFMKLx.js → feature-bundle-DqHxNjy5.js} +14 -4
  5. package/dist/cjs/feature-bundle-DqHxNjy5.js.map +1 -0
  6. package/dist/cjs/index.js +77 -5
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/dom-mini.d.ts +17 -5
  9. package/dist/dom-mini.js +1 -1
  10. package/dist/dom.d.ts +18 -6
  11. package/dist/dom.js +1 -1
  12. package/dist/es/components/AnimatePresence/PopChild.mjs +4 -3
  13. package/dist/es/components/AnimatePresence/PopChild.mjs.map +1 -1
  14. package/dist/es/events/event-info.mjs +1 -3
  15. package/dist/es/events/event-info.mjs.map +1 -1
  16. package/dist/es/gestures/pan/PanSession.mjs +12 -0
  17. package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
  18. package/dist/es/index.mjs +1 -0
  19. package/dist/es/index.mjs.map +1 -1
  20. package/dist/es/render/dom/scroll/info.mjs +1 -1
  21. package/dist/es/render/dom/scroll/info.mjs.map +1 -1
  22. package/dist/es/utils/transform-rotated-parent.mjs +72 -0
  23. package/dist/es/utils/transform-rotated-parent.mjs.map +1 -0
  24. package/dist/framer-motion.dev.js +294 -88
  25. package/dist/framer-motion.js +1 -1
  26. package/dist/mini.js +1 -1
  27. package/dist/size-rollup-animate.js +1 -1
  28. package/dist/size-rollup-animate.js.map +1 -1
  29. package/dist/size-rollup-dom-animation-assets.js +1 -1
  30. package/dist/size-rollup-dom-animation.js +1 -1
  31. package/dist/size-rollup-dom-max-assets.js +1 -1
  32. package/dist/size-rollup-dom-max.js +1 -1
  33. package/dist/size-rollup-m.js +1 -1
  34. package/dist/size-rollup-m.js.map +1 -1
  35. package/dist/size-rollup-motion.js +1 -1
  36. package/dist/size-rollup-motion.js.map +1 -1
  37. package/dist/size-rollup-scroll.js +1 -1
  38. package/dist/size-rollup-scroll.js.map +1 -1
  39. package/dist/size-rollup-waapi-animate.js +1 -1
  40. package/dist/size-rollup-waapi-animate.js.map +1 -1
  41. package/dist/types/index.d.ts +50 -6
  42. package/package.json +3 -3
  43. package/dist/cjs/feature-bundle-jADFMKLx.js.map +0 -1
@@ -1,5 +1,17 @@
1
1
  import { UnresolvedValueKeyframe, AnimationOptions, MotionValue, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationPlaybackOptions, GroupAnimationWithThen, AnimationPlaybackControlsWithThen } from 'motion-dom';
2
2
 
3
+ /**
4
+ * Lifecycle callbacks are not supported on individual sequence segments
5
+ * because segments are consolidated into a single animation per subject.
6
+ * Use sequence-level options (e.g. SequenceOptions.onComplete) instead.
7
+ */
8
+ type LifecycleCallbacks = "onUpdate" | "onPlay" | "onComplete" | "onRepeat" | "onStop";
9
+ /**
10
+ * Distributive Omit preserves union branches (unlike plain Omit).
11
+ */
12
+ type DistributiveOmit<T, K extends string> = T extends any ? Omit<T, K> : never;
13
+ type SegmentTransitionOptions = DistributiveOmit<AnimationOptions, LifecycleCallbacks> & At;
14
+ type SegmentValueTransitionOptions = DistributiveOmit<Transition, LifecycleCallbacks> & At;
3
15
  type ObjectTarget<O> = {
4
16
  [K in keyof O]?: O[K] | UnresolvedValueKeyframe[];
5
17
  };
@@ -19,25 +31,25 @@ type MotionValueSegment = [
19
31
  type MotionValueSegmentWithTransition = [
20
32
  MotionValue,
21
33
  UnresolvedValueKeyframe | UnresolvedValueKeyframe[],
22
- Transition & At
34
+ SegmentValueTransitionOptions
23
35
  ];
24
36
  type DOMSegment = [ElementOrSelector, DOMKeyframesDefinition];
25
37
  type DOMSegmentWithTransition = [
26
38
  ElementOrSelector,
27
39
  DOMKeyframesDefinition,
28
- AnimationOptions & At
40
+ SegmentTransitionOptions
29
41
  ];
30
42
  type ObjectSegment<O extends {} = {}> = [O, ObjectTarget<O>];
31
43
  type ObjectSegmentWithTransition<O extends {} = {}> = [
32
44
  O,
33
45
  ObjectTarget<O>,
34
- AnimationOptions & At
46
+ SegmentTransitionOptions
35
47
  ];
36
48
  type SequenceProgressCallback = (value: any) => void;
37
- type FunctionSegment = [SequenceProgressCallback] | [SequenceProgressCallback, AnimationOptions & At] | [
49
+ type FunctionSegment = [SequenceProgressCallback] | [SequenceProgressCallback, SegmentTransitionOptions] | [
38
50
  SequenceProgressCallback,
39
51
  UnresolvedValueKeyframe | UnresolvedValueKeyframe[],
40
- AnimationOptions & At
52
+ SegmentTransitionOptions
41
53
  ];
42
54
  type Segment = ObjectSegment | ObjectSegmentWithTransition | SequenceLabel | SequenceLabelWithTime | MotionValueSegment | MotionValueSegmentWithTransition | DOMSegment | DOMSegmentWithTransition | FunctionSegment;
43
55
  type AnimationSequence = Segment[];
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)}let n=()=>{};"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&(n=(t,e,n)=>{if(!t)throw new Error(function(t,e){return e?`${t}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${e}`:t}(e,n))});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 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 g=t=>t.startsWith("--");const y={};function A(t,e){const n=function(t){let e;return()=>(void 0===e&&(e=t()),e)}(t);return()=>y[e]??n()}const T=A(()=>void 0!==window.ScrollTimeline,"scrollTimeline"),b=A(()=>{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})`,k={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 S(t,e){return t?"function"==typeof t?b()?((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=>S(t,e)||k.easeOut):k[t]:void 0}function E(t){return"function"==typeof t&&"applyToOptions"in t}class w extends m{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:e,name:i,keyframes:s,pseudoElement:o,allowFlatten:a=!1,finalKeyframe:r,onComplete:l}=t;this.isPseudoElement=Boolean(o),this.allowFlatten=a,this.options=t,n("string"!=typeof t.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const u=function({type:t,...e}){return E(t)&&b()?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=S(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,i,s,u,o),!1===u.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!o){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]}(s,this.options,r,this.speed);this.updateMotionValue&&this.updateMotionValue(t),function(t,e,n){g(e)?t.style.setProperty(e,n):t.style[e]=n}(e,i,t),this.animation.cancel()}l?.(),this.notifyFinished()}}play(){this.isStopped||(this.manualStartTime=null,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(){const t=this.options?.element;!this.isPseudoElement&&t?.isConnected&&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.manualStartTime=null,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 this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,rangeStart:e,rangeEnd:n,observe:s}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&T()?(this.animation.timeline=t,e&&(this.animation.rangeStart=e),n&&(this.animation.rangeEnd=n),i):s(this)}}class M{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 B(this.animations,"duration")}get iterationDuration(){return B(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 B(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 x extends M{then(t,e){return this.finished.finally(t).then(()=>{})}}const I=new WeakMap,O=(t,e="")=>`${t}:${e}`;function R(t){const e=I.get(t)||new Map;return I.set(t,e),e}function F(t,e){const n=t?.[e]??t?.default??t;return n!==t?function(t,e){if(t?.inherit&&e){const{inherit:n,...i}=t;return{...e,...i}}return t}(n,t):n}const W=t=>Boolean(t&&t.getVelocity),P=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","inset","insetBlock","insetBlockStart","insetBlockEnd","insetInline","insetInlineStart","insetInlineEnd","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingBlockStart","paddingBlockEnd","paddingInline","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginBlockStart","marginBlockEnd","marginInline","marginInlineStart","marginInlineEnd","fontSize","backgroundPositionX","backgroundPositionY"]);function $(t,e){for(let n=0;n<t.length;n++)"number"==typeof t[n]&&P.has(e)&&(t[n]=t[n]+"px")}function N(t,e,n){if(null==t)return[];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).filter(t=>null!=t)}function V(t,e){const n=window.getComputedStyle(t);return g(e)?n.getPropertyValue(e):n[e]}function L(t,e,n,i){return null==t?[]:"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?N(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t.filter(t=>null!=t):[t]}function D(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 _(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function j(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function q(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,i,s){if(null==t)return[];const a=N(t),r=a.length;n(Boolean(r),"No valid elements provided.","no-valid-elements");const l=[];for(let t=0;t<r;t++){const n=a[t],s={...i};"function"==typeof s.delay&&(s.delay=s.delay(t,r));for(const t in e){let i=e[t];Array.isArray(i)||(i=[i]);const a={...F(s,t)};a.duration&&(a.duration=o(a.duration)),a.delay&&(a.delay=o(a.delay));const r=R(n),u=O(t,a.pseudoElement||""),h=r.get(u);h&&h.stop(),l.push({map:r,key:u,unresolvedKeyframes:i,options:{...a,element:n,name:t,allowFlatten:!s.type&&!s.ease}})}}for(let t=0;t<l.length;t++){const{unresolvedKeyframes:e,options:n}=l[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<l.length;t++){const{map:e,key:n,options:i}=l[t],s=new w(i);e.set(n,s),s.finished.finally(()=>e.delete(n)),u.push(s)}return u}const Q=(()=>function(t,e,n){return new x(J(t,e,n))})();t.animate=Q,t.animateSequence=function(t,e){const i=[];return function(t,{defaultTransition:e={},...i}={},a,l){const u=e.duration||.3,d=new Map,m=new Map,p={},g=new Map;let y=0,A=0,T=0;for(let i=0;i<t.length;i++){const s=t[i];if("string"==typeof s){g.set(s,A);continue}if(!Array.isArray(s)){g.set(s.name,C(A,s.at,y,g));continue}let[a,d,b={}]=s;void 0!==b.at&&(A=C(A,b.at,y,g));let v=0;const k=(t,i,s,a=0,d=0)=>{const m=H(t),{delay:p=0,times:g=f(m),type:y=e.type||"keyframes",repeat:b,repeatType:k,repeatDelay:S=0,...w}=i;let{ease:M=e.ease||"easeOut",duration:B}=i;const x="function"==typeof p?p(a,d):p,I=m.length,O=E(y)?y:l?.[y||"keyframes"];if(I<=2&&O){let t=100;if(2===I&&G(m)){const e=m[1]-m[0];t=Math.abs(e)}const n={...e,...w};void 0!==B&&(n.duration=o(B));const i=h(n,t,O);M=i.ease,B=i.duration}B??(B=u);const R=A+x;1===g.length&&0===g[0]&&(g[1]=1);const F=g.length-m.length;if(F>0&&c(g,F),1===m.length&&m.unshift(null),b){n(b<20,"Repeat count too high, must be less than 20","repeat-count-high"),B=D(B,b);const t=[...m],e=[...g];M=Array.isArray(M)?[...M]:[M];const i=[...M];for(let n=0;n<b;n++){m.push(...t);for(let s=0;s<t.length;s++)g.push(e[s]+(n+1)),M.push(0===s?"linear":r(i,s-1))}_(g,b)}const W=R+B;K(s,m,M,g,R,W),v=Math.max(x+B,v),T=Math.max(W,T)};if(W(a))k(d,b,z("default",q(a,m)));else{const t=L(a,d,0,p),e=t.length;for(let n=0;n<e;n++){const i=q(t[n],m);for(const t in d)k(d[t],X(b,t),z(t,i),n,e)}}y=A,A+=v}return m.forEach((t,n)=>{for(const o in t){const a=t[o];a.sort(j);const r=[],l=[],u=[];for(let t=0;t<a.length;t++){const{at:e,value:n,easing:i}=a[t];r.push(n),l.push(s(0,T,e)),u.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),r.unshift(r[0]),u.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),r.push(null)),d.has(n)||d.set(n,{keyframes:{},transition:{}});const h=d.get(n);h.keyframes[o]=r;const{type:c,...f}=e;h.transition[o]={...f,duration:T,ease:u,times:l,...i}}}),d}(t,e).forEach(({keyframes:t,transition:e},n)=>{i.push(...J(n,t,e))}),new x(i)}});
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)}let n=()=>{};"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&(n=(t,e,n)=>{if(!t)throw new Error(function(t,e){return e?`${t}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${e}`:t}(e,n))});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 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 g=t=>t.startsWith("--");const y={};function A(t,e){const n=function(t){let e;return()=>(void 0===e&&(e=t()),e)}(t);return()=>y[e]??n()}const T=A(()=>void 0!==window.ScrollTimeline,"scrollTimeline"),b=A(()=>{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})`,k={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 S(t,e){return t?"function"==typeof t?b()?((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=>S(t,e)||k.easeOut):k[t]:void 0}function E(t){return"function"==typeof t&&"applyToOptions"in t}class w extends m{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:e,name:i,keyframes:s,pseudoElement:o,allowFlatten:a=!1,finalKeyframe:r,onComplete:l}=t;this.isPseudoElement=Boolean(o),this.allowFlatten=a,this.options=t,n("string"!=typeof t.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const u=function({type:t,...e}){return E(t)&&b()?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=S(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,i,s,u,o),!1===u.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!o){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]}(s,this.options,r,this.speed);this.updateMotionValue&&this.updateMotionValue(t),function(t,e,n){g(e)?t.style.setProperty(e,n):t.style[e]=n}(e,i,t),this.animation.cancel()}l?.(),this.notifyFinished()}}play(){this.isStopped||(this.manualStartTime=null,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(){const t=this.options?.element;!this.isPseudoElement&&t?.isConnected&&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){const e=null!==this.finishedTime;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=o(t),e&&this.animation.pause()}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 this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,rangeStart:e,rangeEnd:n,observe:s}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&T()?(this.animation.timeline=t,e&&(this.animation.rangeStart=e),n&&(this.animation.rangeEnd=n),i):s(this)}}class M{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 B(this.animations,"duration")}get iterationDuration(){return B(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 B(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 x extends M{then(t,e){return this.finished.finally(t).then(()=>{})}}const I=new WeakMap,O=(t,e="")=>`${t}:${e}`;function R(t){const e=I.get(t)||new Map;return I.set(t,e),e}function F(t,e){const n=t?.[e]??t?.default??t;return n!==t?function(t,e){if(t?.inherit&&e){const{inherit:n,...i}=t;return{...e,...i}}return t}(n,t):n}const W=t=>Boolean(t&&t.getVelocity),P=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","inset","insetBlock","insetBlockStart","insetBlockEnd","insetInline","insetInlineStart","insetInlineEnd","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingBlockStart","paddingBlockEnd","paddingInline","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginBlockStart","marginBlockEnd","marginInline","marginInlineStart","marginInlineEnd","fontSize","backgroundPositionX","backgroundPositionY"]);function $(t,e){for(let n=0;n<t.length;n++)"number"==typeof t[n]&&P.has(e)&&(t[n]=t[n]+"px")}function N(t,e,n){if(null==t)return[];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).filter(t=>null!=t)}function V(t,e){const n=window.getComputedStyle(t);return g(e)?n.getPropertyValue(e):n[e]}function L(t,e,n,i){return null==t?[]:"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?N(t,0,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t.filter(t=>null!=t):[t]}function D(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 _(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function j(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function q(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,i,s){if(null==t)return[];const a=N(t),r=a.length;n(Boolean(r),"No valid elements provided.","no-valid-elements");const l=[];for(let t=0;t<r;t++){const n=a[t],s={...i};"function"==typeof s.delay&&(s.delay=s.delay(t,r));for(const t in e){let i=e[t];Array.isArray(i)||(i=[i]);const a={...F(s,t)};a.duration&&(a.duration=o(a.duration)),a.delay&&(a.delay=o(a.delay));const r=R(n),u=O(t,a.pseudoElement||""),h=r.get(u);h&&h.stop(),l.push({map:r,key:u,unresolvedKeyframes:i,options:{...a,element:n,name:t,allowFlatten:!s.type&&!s.ease}})}}for(let t=0;t<l.length;t++){const{unresolvedKeyframes:e,options:n}=l[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<l.length;t++){const{map:e,key:n,options:i}=l[t],s=new w(i);e.set(n,s),s.finished.finally(()=>e.delete(n)),u.push(s)}return u}const Q=(()=>function(t,e,n){return new x(J(t,e,n))})();t.animate=Q,t.animateSequence=function(t,e){const i=[];return function(t,{defaultTransition:e={},...i}={},a,l){const u=e.duration||.3,d=new Map,m=new Map,p={},g=new Map;let y=0,A=0,T=0;for(let i=0;i<t.length;i++){const s=t[i];if("string"==typeof s){g.set(s,A);continue}if(!Array.isArray(s)){g.set(s.name,C(A,s.at,y,g));continue}let[a,d,b={}]=s;void 0!==b.at&&(A=C(A,b.at,y,g));let v=0;const k=(t,i,s,a=0,d=0)=>{const m=H(t),{delay:p=0,times:g=f(m),type:y=e.type||"keyframes",repeat:b,repeatType:k,repeatDelay:S=0,...w}=i;let{ease:M=e.ease||"easeOut",duration:B}=i;const x="function"==typeof p?p(a,d):p,I=m.length,O=E(y)?y:l?.[y||"keyframes"];if(I<=2&&O){let t=100;if(2===I&&G(m)){const e=m[1]-m[0];t=Math.abs(e)}const n={...e,...w};void 0!==B&&(n.duration=o(B));const i=h(n,t,O);M=i.ease,B=i.duration}B??(B=u);const R=A+x;1===g.length&&0===g[0]&&(g[1]=1);const F=g.length-m.length;if(F>0&&c(g,F),1===m.length&&m.unshift(null),b){n(b<20,"Repeat count too high, must be less than 20","repeat-count-high"),B=D(B,b);const t=[...m],e=[...g];M=Array.isArray(M)?[...M]:[M];const i=[...M];for(let n=0;n<b;n++){m.push(...t);for(let s=0;s<t.length;s++)g.push(e[s]+(n+1)),M.push(0===s?"linear":r(i,s-1))}_(g,b)}const W=R+B;K(s,m,M,g,R,W),v=Math.max(x+B,v),T=Math.max(W,T)};if(W(a))k(d,b,z("default",q(a,m)));else{const t=L(a,d,0,p),e=t.length;for(let n=0;n<e;n++){const i=q(t[n],m);for(const t in d)k(d[t],X(b,t),z(t,i),n,e)}}y=A,A+=v}return m.forEach((t,n)=>{for(const o in t){const a=t[o];a.sort(j);const r=[],l=[],u=[];for(let t=0;t<a.length;t++){const{at:e,value:n,easing:i}=a[t];r.push(n),l.push(s(0,T,e)),u.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),r.unshift(r[0]),u.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),r.push(null)),d.has(n)||d.set(n,{keyframes:{},transition:{}});const h=d.get(n);h.keyframes[o]=r;const{type:c,...f}=e;h.transition[o]={...f,duration:T,ease:u,times:l,...i}}}),d}(t,e).forEach(({keyframes:t,transition:e},n)=>{i.push(...J(n,t,e))}),new x(i)}});
package/dist/dom.d.ts CHANGED
@@ -4,6 +4,18 @@ export { DelayedFunction, delayInSeconds as delay } from 'motion-dom';
4
4
  import { Easing, EasingFunction, Point } from 'motion-utils';
5
5
  export * from 'motion-utils';
6
6
 
7
+ /**
8
+ * Lifecycle callbacks are not supported on individual sequence segments
9
+ * because segments are consolidated into a single animation per subject.
10
+ * Use sequence-level options (e.g. SequenceOptions.onComplete) instead.
11
+ */
12
+ type LifecycleCallbacks = "onUpdate" | "onPlay" | "onComplete" | "onRepeat" | "onStop";
13
+ /**
14
+ * Distributive Omit preserves union branches (unlike plain Omit).
15
+ */
16
+ type DistributiveOmit<T, K extends string> = T extends any ? Omit<T, K> : never;
17
+ type SegmentTransitionOptions = DistributiveOmit<AnimationOptions, LifecycleCallbacks> & At;
18
+ type SegmentValueTransitionOptions = DistributiveOmit<Transition, LifecycleCallbacks> & At;
7
19
  type ObjectTarget<O> = {
8
20
  [K in keyof O]?: O[K] | UnresolvedValueKeyframe[];
9
21
  };
@@ -23,25 +35,25 @@ type MotionValueSegment = [
23
35
  type MotionValueSegmentWithTransition = [
24
36
  MotionValue,
25
37
  UnresolvedValueKeyframe | UnresolvedValueKeyframe[],
26
- Transition & At
38
+ SegmentValueTransitionOptions
27
39
  ];
28
40
  type DOMSegment = [ElementOrSelector, DOMKeyframesDefinition];
29
41
  type DOMSegmentWithTransition = [
30
42
  ElementOrSelector,
31
43
  DOMKeyframesDefinition,
32
- AnimationOptions & At
44
+ SegmentTransitionOptions
33
45
  ];
34
46
  type ObjectSegment<O extends {} = {}> = [O, ObjectTarget<O>];
35
47
  type ObjectSegmentWithTransition<O extends {} = {}> = [
36
48
  O,
37
49
  ObjectTarget<O>,
38
- AnimationOptions & At
50
+ SegmentTransitionOptions
39
51
  ];
40
52
  type SequenceProgressCallback = (value: any) => void;
41
- type FunctionSegment = [SequenceProgressCallback] | [SequenceProgressCallback, AnimationOptions & At] | [
53
+ type FunctionSegment = [SequenceProgressCallback] | [SequenceProgressCallback, SegmentTransitionOptions] | [
42
54
  SequenceProgressCallback,
43
55
  UnresolvedValueKeyframe | UnresolvedValueKeyframe[],
44
- AnimationOptions & At
56
+ SegmentTransitionOptions
45
57
  ];
46
58
  type Segment = ObjectSegment | ObjectSegmentWithTransition | SequenceLabel | SequenceLabelWithTime | MotionValueSegment | MotionValueSegmentWithTransition | DOMSegment | DOMSegmentWithTransition | FunctionSegment;
47
59
  type AnimationSequence = Segment[];
@@ -287,4 +299,4 @@ interface HTMLElements {
287
299
  declare const distance: (a: number, b: number) => number;
288
300
  declare function distance2D(a: Point, b: Point): number;
289
301
 
290
- export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type FunctionSegment, 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 SequenceProgressCallback, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, distance, distance2D, inView, scroll, scrollInfo };
302
+ export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type FunctionSegment, type HTMLElements, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SegmentTransitionOptions, type SegmentValueTransitionOptions, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceProgressCallback, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, distance, distance2D, inView, scroll, scrollInfo };