framer-motion 12.15.0 → 12.16.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var create = require('./create-CozUbvT0.js');
5
+ var create = require('./create-DflTeyPc.js');
6
6
  require('motion-dom');
7
7
  require('motion-utils');
8
8
  require('react/jsx-runtime');
@@ -1956,6 +1956,7 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
1956
1956
  this.motionValue || (this.motionValue = motionDom.motionValue(0));
1957
1957
  this.currentAnimation = animateSingleValue(this.motionValue, [0, 1000], {
1958
1958
  ...options,
1959
+ velocity: 0,
1959
1960
  isSync: true,
1960
1961
  onUpdate: (latest) => {
1961
1962
  this.mixTargetDelta(latest);
@@ -156,7 +156,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
156
156
  const numKeyframes = valueKeyframesAsList.length;
157
157
  const createGenerator = motionDom.isGenerator(type)
158
158
  ? type
159
- : generators?.[type];
159
+ : generators?.[type || "keyframes"];
160
160
  if (numKeyframes <= 2 && createGenerator) {
161
161
  /**
162
162
  * As we're creating an easing function from a spring,
package/dist/cjs/dom.js CHANGED
@@ -156,7 +156,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
156
156
  const numKeyframes = valueKeyframesAsList.length;
157
157
  const createGenerator = motionDom.isGenerator(type)
158
158
  ? type
159
- : generators?.[type];
159
+ : generators?.[type || "keyframes"];
160
160
  if (numKeyframes <= 2 && createGenerator) {
161
161
  /**
162
162
  * As we're creating an easing function from a spring,
@@ -1941,99 +1941,6 @@ const createScopedWaapiAnimate = (scope) => {
1941
1941
  };
1942
1942
  const animateMini = /*@__PURE__*/ createScopedWaapiAnimate();
1943
1943
 
1944
- const resizeHandlers = new WeakMap();
1945
- let observer;
1946
- function getElementSize(target, borderBoxSize) {
1947
- if (borderBoxSize) {
1948
- const { inlineSize, blockSize } = borderBoxSize[0];
1949
- return { width: inlineSize, height: blockSize };
1950
- }
1951
- else if (motionDom.isSVGElement(target) && "getBBox" in target) {
1952
- return target.getBBox();
1953
- }
1954
- else {
1955
- return {
1956
- width: target.offsetWidth,
1957
- height: target.offsetHeight,
1958
- };
1959
- }
1960
- }
1961
- function notifyTarget({ target, contentRect, borderBoxSize, }) {
1962
- resizeHandlers.get(target)?.forEach((handler) => {
1963
- handler({
1964
- target,
1965
- contentSize: contentRect,
1966
- get size() {
1967
- return getElementSize(target, borderBoxSize);
1968
- },
1969
- });
1970
- });
1971
- }
1972
- function notifyAll(entries) {
1973
- entries.forEach(notifyTarget);
1974
- }
1975
- function createResizeObserver() {
1976
- if (typeof ResizeObserver === "undefined")
1977
- return;
1978
- observer = new ResizeObserver(notifyAll);
1979
- }
1980
- function resizeElement(target, handler) {
1981
- if (!observer)
1982
- createResizeObserver();
1983
- const elements = motionDom.resolveElements(target);
1984
- elements.forEach((element) => {
1985
- let elementHandlers = resizeHandlers.get(element);
1986
- if (!elementHandlers) {
1987
- elementHandlers = new Set();
1988
- resizeHandlers.set(element, elementHandlers);
1989
- }
1990
- elementHandlers.add(handler);
1991
- observer?.observe(element);
1992
- });
1993
- return () => {
1994
- elements.forEach((element) => {
1995
- const elementHandlers = resizeHandlers.get(element);
1996
- elementHandlers?.delete(handler);
1997
- if (!elementHandlers?.size) {
1998
- observer?.unobserve(element);
1999
- }
2000
- });
2001
- };
2002
- }
2003
-
2004
- const windowCallbacks = new Set();
2005
- let windowResizeHandler;
2006
- function createWindowResizeHandler() {
2007
- windowResizeHandler = () => {
2008
- const size = {
2009
- width: window.innerWidth,
2010
- height: window.innerHeight,
2011
- };
2012
- const info = {
2013
- target: window,
2014
- size,
2015
- contentSize: size,
2016
- };
2017
- windowCallbacks.forEach((callback) => callback(info));
2018
- };
2019
- window.addEventListener("resize", windowResizeHandler);
2020
- }
2021
- function resizeWindow(callback) {
2022
- windowCallbacks.add(callback);
2023
- if (!windowResizeHandler)
2024
- createWindowResizeHandler();
2025
- return () => {
2026
- windowCallbacks.delete(callback);
2027
- if (!windowCallbacks.size && windowResizeHandler) {
2028
- windowResizeHandler = undefined;
2029
- }
2030
- };
2031
- }
2032
-
2033
- function resize(a, b) {
2034
- return typeof a === "function" ? resizeWindow(a) : resizeElement(a, b);
2035
- }
2036
-
2037
1944
  /**
2038
1945
  * A time in milliseconds, beyond which we consider the scroll velocity to be 0.
2039
1946
  */
@@ -2363,7 +2270,7 @@ function scrollInfo(onScroll, { container = document.scrollingElement, ...option
2363
2270
  const target = getEventTarget(container);
2364
2271
  window.addEventListener("resize", listener, { passive: true });
2365
2272
  if (container !== document.documentElement) {
2366
- resizeListeners.set(container, resize(container, listener));
2273
+ resizeListeners.set(container, motionDom.resize(container, listener));
2367
2274
  }
2368
2275
  target.addEventListener("scroll", listener, { passive: true });
2369
2276
  listener();
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
- var create = require('./create-CozUbvT0.js');
7
+ var create = require('./create-DflTeyPc.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
@@ -889,7 +889,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
889
889
  const numKeyframes = valueKeyframesAsList.length;
890
890
  const createGenerator = motionDom.isGenerator(type)
891
891
  ? type
892
- : generators?.[type];
892
+ : generators?.[type || "keyframes"];
893
893
  if (numKeyframes <= 2 && createGenerator) {
894
894
  /**
895
895
  * As we're creating an easing function from a spring,
@@ -1333,99 +1333,6 @@ const createScopedWaapiAnimate = (scope) => {
1333
1333
  };
1334
1334
  const animateMini = /*@__PURE__*/ createScopedWaapiAnimate();
1335
1335
 
1336
- const resizeHandlers = new WeakMap();
1337
- let observer;
1338
- function getElementSize(target, borderBoxSize) {
1339
- if (borderBoxSize) {
1340
- const { inlineSize, blockSize } = borderBoxSize[0];
1341
- return { width: inlineSize, height: blockSize };
1342
- }
1343
- else if (motionDom.isSVGElement(target) && "getBBox" in target) {
1344
- return target.getBBox();
1345
- }
1346
- else {
1347
- return {
1348
- width: target.offsetWidth,
1349
- height: target.offsetHeight,
1350
- };
1351
- }
1352
- }
1353
- function notifyTarget({ target, contentRect, borderBoxSize, }) {
1354
- resizeHandlers.get(target)?.forEach((handler) => {
1355
- handler({
1356
- target,
1357
- contentSize: contentRect,
1358
- get size() {
1359
- return getElementSize(target, borderBoxSize);
1360
- },
1361
- });
1362
- });
1363
- }
1364
- function notifyAll(entries) {
1365
- entries.forEach(notifyTarget);
1366
- }
1367
- function createResizeObserver() {
1368
- if (typeof ResizeObserver === "undefined")
1369
- return;
1370
- observer = new ResizeObserver(notifyAll);
1371
- }
1372
- function resizeElement(target, handler) {
1373
- if (!observer)
1374
- createResizeObserver();
1375
- const elements = motionDom.resolveElements(target);
1376
- elements.forEach((element) => {
1377
- let elementHandlers = resizeHandlers.get(element);
1378
- if (!elementHandlers) {
1379
- elementHandlers = new Set();
1380
- resizeHandlers.set(element, elementHandlers);
1381
- }
1382
- elementHandlers.add(handler);
1383
- observer?.observe(element);
1384
- });
1385
- return () => {
1386
- elements.forEach((element) => {
1387
- const elementHandlers = resizeHandlers.get(element);
1388
- elementHandlers?.delete(handler);
1389
- if (!elementHandlers?.size) {
1390
- observer?.unobserve(element);
1391
- }
1392
- });
1393
- };
1394
- }
1395
-
1396
- const windowCallbacks = new Set();
1397
- let windowResizeHandler;
1398
- function createWindowResizeHandler() {
1399
- windowResizeHandler = () => {
1400
- const size = {
1401
- width: window.innerWidth,
1402
- height: window.innerHeight,
1403
- };
1404
- const info = {
1405
- target: window,
1406
- size,
1407
- contentSize: size,
1408
- };
1409
- windowCallbacks.forEach((callback) => callback(info));
1410
- };
1411
- window.addEventListener("resize", windowResizeHandler);
1412
- }
1413
- function resizeWindow(callback) {
1414
- windowCallbacks.add(callback);
1415
- if (!windowResizeHandler)
1416
- createWindowResizeHandler();
1417
- return () => {
1418
- windowCallbacks.delete(callback);
1419
- if (!windowCallbacks.size && windowResizeHandler) {
1420
- windowResizeHandler = undefined;
1421
- }
1422
- };
1423
- }
1424
-
1425
- function resize(a, b) {
1426
- return typeof a === "function" ? resizeWindow(a) : resizeElement(a, b);
1427
- }
1428
-
1429
1336
  /**
1430
1337
  * A time in milliseconds, beyond which we consider the scroll velocity to be 0.
1431
1338
  */
@@ -1755,7 +1662,7 @@ function scrollInfo(onScroll, { container = document.scrollingElement, ...option
1755
1662
  const target = getEventTarget(container);
1756
1663
  window.addEventListener("resize", listener, { passive: true });
1757
1664
  if (container !== document.documentElement) {
1758
- resizeListeners.set(container, resize(container, listener));
1665
+ resizeListeners.set(container, motionDom.resize(container, listener));
1759
1666
  }
1760
1667
  target.addEventListener("scroll", listener, { passive: true });
1761
1668
  listener();
@@ -2293,10 +2200,10 @@ function useAnimateMini() {
2293
2200
  }
2294
2201
 
2295
2202
  /**
2296
- * Creates `AnimationControls`, which can be used to manually start, stop
2203
+ * Creates `LegacyAnimationControls`, which can be used to manually start, stop
2297
2204
  * and sequence animations on one or more components.
2298
2205
  *
2299
- * The returned `AnimationControls` should be passed to the `animate` property
2206
+ * The returned `LegacyAnimationControls` should be passed to the `animate` property
2300
2207
  * of the components you want to animate.
2301
2208
  *
2302
2209
  * These components can then be animated with the `start` method.
@@ -1,9 +1,7 @@
1
1
  import { AnimationPlaybackOptions, Transition, MotionValue, UnresolvedValueKeyframe, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, GroupAnimationWithThen, AnimationPlaybackControlsWithThen } from 'motion-dom';
2
2
 
3
- type GenericKeyframesTarget<V> = V[] | Array<null | V>;
4
-
5
3
  type ObjectTarget<O> = {
6
- [K in keyof O]?: O[K] | GenericKeyframesTarget<O[K]>;
4
+ [K in keyof O]?: O[K] | UnresolvedValueKeyframe[];
7
5
  };
8
6
  type SequenceTime = number | "<" | `+${number}` | `-${number}` | `${string}`;
9
7
  type SequenceLabel = string;
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 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 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})`,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+=t(e/(s-1))+", ";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 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 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(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 i=document;e&&(i=e.current);const s=n?.[t]??i.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function L(t,e){const n=window.getComputedStyle(t);return y(e)?n.getPropertyValue(e):n[e]}function V(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?$(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function I(t,e,n){return t*(e+1)}function N(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:i.get(e)??t}function C(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 K(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 _(t,e){return e[t]||(e[t]=[]),e[t]}function z(t){return Array.isArray(t)?t:[t]}function D(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const H=t=>"number"==typeof t,X=t=>t.every(H);function Y(t,e,n,i){const s=$(t,i),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={...W(u,t)};s.duration&&(s.duration=o(s.duration)),s.delay&&(s.delay=o(s.delay));const a=F(i),l=R(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]=L(i,s)),p(e),B(e,s),!o&&e.length<2&&e.unshift(L(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 G=(t=>function(e,n,i){return new O(Y(e,n,i,t))})();t.animate=G,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const u=e.duration||.3,l=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 s=t[n];if("string"==typeof s){p.set(s,g);continue}if(!Array.isArray(s)){p.set(s.name,N(g,s.at,y,p));continue}let[l,T,v={}]=s;void 0!==v.at&&(g=N(g,v.at,y,p));let w=0;const M=(t,n,i,s=0,l=0)=>{const m=z(t),{delay:d=0,times:p=f(m),type:y="keyframes",repeat:b,repeatType:T,repeatDelay:v=0,...M}=n;let{ease:x=e.ease||"easeOut",duration:E}=n;const O="function"==typeof d?d(s,l):d,S=m.length,R=k(y)?y:a?.[y];if(S<=2&&R){let t=100;if(2===S&&X(m)){const e=m[1]-m[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-m.length;if(W>0&&c(p,W),1===m.length&&m.unshift(null),b){E=I(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))}K(p,b)}const P=F+E;C(i,m,x,p,F,P),w=Math.max(O+E,w),A=Math.max(P,A)};if(b=l,Boolean(b&&b.getVelocity))M(T,v,_("default",q(l,m)));else{const t=V(l,T,i,d),e=t.length;for(let n=0;n<e;n++){const i=q(t[n],m);for(const t in T)M(T[t],D(v,t),_(t,i),n,e)}}y=g,g+=w}var b;return m.forEach(((t,i)=>{for(const o in t){const a=t[o];a.sort(j);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(...Y(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 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})`,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 k(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+=t(e/(s-1))+", ";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=>k(t,e)||w.easeOut)):w[t]:void 0}function M(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 u=function({type:t,...e}){return M(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=k(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(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 i=document;e&&(i=e.current);const s=n?.[t]??i.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function L(t,e){const n=window.getComputedStyle(t);return y(e)?n.getPropertyValue(e):n[e]}function V(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?$(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function I(t,e,n){return t*(e+1)}function N(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:i.get(e)??t}function C(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 K(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 _(t,e){return e[t]||(e[t]=[]),e[t]}function z(t){return Array.isArray(t)?t:[t]}function D(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const H=t=>"number"==typeof t,X=t=>t.every(H);function Y(t,e,n,i){const s=$(t,i),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={...W(u,t)};s.duration&&(s.duration=o(s.duration)),s.delay&&(s.delay=o(s.delay));const a=F(i),l=R(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]=L(i,s)),p(e),B(e,s),!o&&e.length<2&&e.unshift(L(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 G=(t=>function(e,n,i){return new O(Y(e,n,i,t))})();t.animate=G,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const u=e.duration||.3,l=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 s=t[n];if("string"==typeof s){p.set(s,g);continue}if(!Array.isArray(s)){p.set(s.name,N(g,s.at,y,p));continue}let[l,T,v={}]=s;void 0!==v.at&&(g=N(g,v.at,y,p));let w=0;const k=(t,n,i,s=0,l=0)=>{const m=z(t),{delay:d=0,times:p=f(m),type:y="keyframes",repeat:b,repeatType:T,repeatDelay:v=0,...k}=n;let{ease:x=e.ease||"easeOut",duration:E}=n;const O="function"==typeof d?d(s,l):d,S=m.length,R=M(y)?y:a?.[y||"keyframes"];if(S<=2&&R){let t=100;if(2===S&&X(m)){const e=m[1]-m[0];t=Math.abs(e)}const e={...k};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-m.length;if(W>0&&c(p,W),1===m.length&&m.unshift(null),b){E=I(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))}K(p,b)}const P=F+E;C(i,m,x,p,F,P),w=Math.max(O+E,w),A=Math.max(P,A)};if(b=l,Boolean(b&&b.getVelocity))k(T,v,_("default",q(l,m)));else{const t=V(l,T,i,d),e=t.length;for(let n=0;n<e;n++){const i=q(t[n],m);for(const t in T)k(T[t],D(v,t),_(t,i),n,e)}}y=g,g+=w}var b;return m.forEach(((t,i)=>{for(const o in t){const a=t[o];a.sort(j);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(...Y(i,t,e))})),new O(n)}}));
package/dist/dom.d.ts CHANGED
@@ -1,12 +1,10 @@
1
- import { MotionValue, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, AnimationPlaybackControls, DynamicOption } from 'motion-dom';
1
+ import { UnresolvedValueKeyframe, MotionValue, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, AnimationPlaybackControls, DynamicOption } from 'motion-dom';
2
2
  export * from 'motion-dom';
3
3
  import { Easing, EasingFunction, Point } from 'motion-utils';
4
4
  export * from 'motion-utils';
5
5
 
6
- type GenericKeyframesTarget<V> = V[] | Array<null | V>;
7
-
8
6
  type ObjectTarget<O> = {
9
- [K in keyof O]?: O[K] | GenericKeyframesTarget<O[K]>;
7
+ [K in keyof O]?: O[K] | UnresolvedValueKeyframe[];
10
8
  };
11
9
  type SequenceTime = number | "<" | `+${number}` | `-${number}` | `${string}`;
12
10
  type SequenceLabel = string;
@@ -70,17 +68,17 @@ type ResolvedAnimationDefinitions = Map<Element | MotionValue, ResolvedAnimation
70
68
  */
71
69
  declare function createScopedAnimate(scope?: AnimationScope): {
72
70
  (sequence: AnimationSequence, options?: SequenceOptions): AnimationPlaybackControlsWithThen;
73
- (value: string | MotionValue<string>, keyframes: string | GenericKeyframesTarget<string>, options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen;
74
- (value: number | MotionValue<number>, keyframes: number | GenericKeyframesTarget<number>, options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen;
75
- <V>(value: V | MotionValue<V>, keyframes: V | GenericKeyframesTarget<V>, options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen;
71
+ (value: string | MotionValue<string>, keyframes: string | UnresolvedValueKeyframe<string>[], options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen;
72
+ (value: number | MotionValue<number>, keyframes: number | UnresolvedValueKeyframe<number>[], options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen;
73
+ <V extends string | number>(value: V | MotionValue<V>, keyframes: V | UnresolvedValueKeyframe<V>[], options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen;
76
74
  (element: ElementOrSelector, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
77
75
  <O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
78
76
  };
79
77
  declare const animate: {
80
78
  (sequence: AnimationSequence, options?: SequenceOptions): AnimationPlaybackControlsWithThen;
81
- (value: string | MotionValue<string>, keyframes: string | GenericKeyframesTarget<string>, options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen;
82
- (value: number | MotionValue<number>, keyframes: number | GenericKeyframesTarget<number>, options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen;
83
- <V>(value: V | MotionValue<V>, keyframes: V | GenericKeyframesTarget<V>, options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen;
79
+ (value: string | MotionValue<string>, keyframes: string | UnresolvedValueKeyframe<string>[], options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen;
80
+ (value: number | MotionValue<number>, keyframes: number | UnresolvedValueKeyframe<number>[], options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen;
81
+ <V extends string | number>(value: V | MotionValue<V>, keyframes: V | UnresolvedValueKeyframe<V>[], options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen;
84
82
  (element: ElementOrSelector, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
85
83
  <O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
86
84
  };