motion-dom 13.1.1 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +6178 -5360
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +41 -38
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/FollowAnimation.mjs +152 -0
- package/dist/es/animation/FollowAnimation.mjs.map +1 -0
- package/dist/es/animation/JSAnimation.mjs +7 -11
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +2 -0
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationWrapper.mjs +7 -0
- package/dist/es/animation/NativeAnimationWrapper.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +105 -0
- package/dist/es/animation/animate/effects.mjs.map +1 -0
- package/dist/es/animation/animate/element.mjs +80 -0
- package/dist/es/animation/animate/element.mjs.map +1 -0
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/inertia.mjs +8 -6
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +25 -1
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +119 -86
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/animation/generators/utils/calc-duration.mjs +5 -4
- package/dist/es/animation/generators/utils/calc-duration.mjs.map +1 -1
- package/dist/es/animation/generators/utils/velocity.mjs +13 -1
- package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +12 -6
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/KeyframesResolver.mjs +38 -7
- package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs +8 -2
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs +45 -19
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
- package/dist/es/animation/utils/WithPromise.mjs +12 -5
- package/dist/es/animation/utils/WithPromise.mjs.map +1 -1
- package/dist/es/animation/utils/arc.mjs +2 -1
- package/dist/es/animation/utils/arc.mjs.map +1 -1
- package/dist/es/animation/utils/can-animate.mjs +3 -1
- package/dist/es/animation/utils/can-animate.mjs.map +1 -1
- package/dist/es/animation/utils/notify-inspector.mjs +56 -0
- package/dist/es/animation/utils/notify-inspector.mjs.map +1 -0
- package/dist/es/animation/waapi/supports/waapi.mjs +8 -1
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +90 -26
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/attr/index.mjs +15 -9
- package/dist/es/effects/attr/index.mjs.map +1 -1
- package/dist/es/effects/prop/index.mjs +15 -2
- package/dist/es/effects/prop/index.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +52 -9
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +28 -25
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/svg/index.mjs +40 -7
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/effects/utils/create-dom-effect.mjs +9 -1
- package/dist/es/effects/utils/create-dom-effect.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs +8 -3
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs +5 -2
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/index.mjs +7 -3
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +9 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +4 -1
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +11 -2
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/utils/is-controlling-variants.mjs +8 -2
- package/dist/es/render/utils/is-controlling-variants.mjs.map +1 -1
- package/dist/es/utils/mix/color.mjs +3 -2
- package/dist/es/utils/mix/color.mjs.map +1 -1
- package/dist/es/utils/mix/index.mjs +28 -0
- package/dist/es/utils/mix/index.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +33 -30
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/es/value/index.mjs +73 -29
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs +17 -4
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/index.d.ts +307 -47
- package/dist/motion-dom.dev.js +6178 -5360
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NativeAnimation } from './NativeAnimation.mjs';
|
|
2
|
+
import { notifyAnimationStart } from './utils/notify-inspector.mjs';
|
|
2
3
|
|
|
3
4
|
class NativeAnimationWrapper extends NativeAnimation {
|
|
4
5
|
constructor(animation) {
|
|
@@ -8,6 +9,12 @@ class NativeAnimationWrapper extends NativeAnimation {
|
|
|
8
9
|
this.finishedTime = this.time;
|
|
9
10
|
this.notifyFinished();
|
|
10
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* The optionless super() returns before NativeAnimation's own
|
|
14
|
+
* notify, so wrapped animations (view transition cross-fades)
|
|
15
|
+
* report here, after the wrapped WAAPI animation is attached.
|
|
16
|
+
*/
|
|
17
|
+
notifyAnimationStart(this, {});
|
|
11
18
|
}
|
|
12
19
|
}
|
|
13
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAnimationWrapper.mjs","sources":["../../../src/animation/NativeAnimationWrapper.ts"],"sourcesContent":["import { NativeAnimation } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe } from \"./types\"\n\nexport class NativeAnimationWrapper<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n constructor(animation: Animation) {\n super()\n\n this.animation = animation\n animation.onfinish = () => {\n this.finishedTime = this.time\n this.notifyFinished()\n }\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NativeAnimationWrapper.mjs","sources":["../../../src/animation/NativeAnimationWrapper.ts"],"sourcesContent":["import { NativeAnimation } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe } from \"./types\"\nimport { notifyAnimationStart } from \"./utils/notify-inspector\"\n\nexport class NativeAnimationWrapper<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n constructor(animation: Animation) {\n super()\n\n this.animation = animation\n animation.onfinish = () => {\n this.finishedTime = this.time\n this.notifyFinished()\n }\n\n /**\n * The optionless super() returns before NativeAnimation's own\n * notify, so wrapped animations (view transition cross-fades)\n * report here, after the wrapped WAAPI animation is attached.\n */\n notifyAnimationStart(this, {})\n }\n}\n"],"names":[],"mappings":";;;AAIM,MAAO,sBAEX,SAAQ,eAAkB,CAAA;AACxB,IAAA,WAAA,CAAY,SAAoB,EAAA;AAC5B,QAAA,KAAK,EAAE;AAEP,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;AAC1B,QAAA,SAAS,CAAC,QAAQ,GAAG,MAAK;AACtB,YAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,IAAI;YAC7B,IAAI,CAAC,cAAc,EAAE;AACzB,QAAA,CAAC;AAED;;;;AAIG;AACH,QAAA,oBAAoB,CAAC,IAAI,EAAE,EAAE,CAAC;IAClC;AACH;;;;"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { invariant, removeItem } from 'motion-utils';
|
|
2
|
+
import { positionalKeys } from '../../render/utils/keys-position.mjs';
|
|
3
|
+
import { motionValue } from '../../value/index.mjs';
|
|
4
|
+
import { animateMotionValue } from '../interfaces/motion-value.mjs';
|
|
5
|
+
import { frame } from '../../frameloop/frame.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Effects registered via `animate.addEffect()`, most recent first.
|
|
9
|
+
*/
|
|
10
|
+
const effects = [];
|
|
11
|
+
function addEffect(effect) {
|
|
12
|
+
invariant(typeof effect.test === "function" && typeof effect.read === "function", "Effects passed to animate.addEffect() need test() and read().", "effect-missing-test");
|
|
13
|
+
removeEffect(effect);
|
|
14
|
+
effects.unshift(effect);
|
|
15
|
+
}
|
|
16
|
+
function removeEffect(effect) {
|
|
17
|
+
removeItem(effects, effect);
|
|
18
|
+
}
|
|
19
|
+
function findEffect(subject) {
|
|
20
|
+
return effects.find((effect) => effect.test(subject));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Animate each key in `keyframes` on the motion value `getValue` returns
|
|
24
|
+
* for it. `element` is what the keyframe resolver uses to read, render
|
|
25
|
+
* and measure the subject when the effect defers resolution to it.
|
|
26
|
+
*/
|
|
27
|
+
function animateValues(getValue, keyframes, transition = {}, element) {
|
|
28
|
+
const animations = [];
|
|
29
|
+
const { velocity } = transition;
|
|
30
|
+
const reduceMotion = transition.reduceMotion ?? element?.shouldReduceMotion;
|
|
31
|
+
for (const key in keyframes) {
|
|
32
|
+
if (key === "transition" || key === "transitionEnd")
|
|
33
|
+
continue;
|
|
34
|
+
const target = keyframes[key];
|
|
35
|
+
if (target === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
const value = getValue(key);
|
|
38
|
+
/**
|
|
39
|
+
* If the value is already at the defined target, skip the animation.
|
|
40
|
+
* We still re-assert the value via frame.update to take precedence
|
|
41
|
+
* over any stale transitionEnd callbacks from previous animations.
|
|
42
|
+
*/
|
|
43
|
+
const current = value.get();
|
|
44
|
+
if (current !== undefined &&
|
|
45
|
+
!value.isAnimating() &&
|
|
46
|
+
!Array.isArray(target) &&
|
|
47
|
+
target === current &&
|
|
48
|
+
!velocity) {
|
|
49
|
+
frame.update(() => value.set(target));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
value.start(animateMotionValue(key, value, target, reduceMotion && positionalKeys.has(key)
|
|
53
|
+
? { type: false }
|
|
54
|
+
: transition, element));
|
|
55
|
+
value.animation &&
|
|
56
|
+
animations.push(value.animation);
|
|
57
|
+
}
|
|
58
|
+
const { transitionEnd } = keyframes;
|
|
59
|
+
if (transitionEnd) {
|
|
60
|
+
const applyTransitionEnd = () => frame.update(() => {
|
|
61
|
+
for (const key in transitionEnd) {
|
|
62
|
+
getValue(key).set(transitionEnd[key]);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
animations.length
|
|
66
|
+
? Promise.all(animations).then(applyTransitionEnd)
|
|
67
|
+
: applyTransitionEnd();
|
|
68
|
+
}
|
|
69
|
+
return animations;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Animate the keys of `subject` via `effect`. Motion values are created on
|
|
73
|
+
* first animation and bound to the subject through the effect for the
|
|
74
|
+
* rest of its life.
|
|
75
|
+
*
|
|
76
|
+
* Without `element`, a new value is seeded synchronously from the first
|
|
77
|
+
* keyframe or `effect.read()`. With it, the value starts undefined and the
|
|
78
|
+
* keyframe resolver reads the subject (batched, with unit conversion by
|
|
79
|
+
* measurement) via `element`.
|
|
80
|
+
*/
|
|
81
|
+
function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
82
|
+
return animateValues((key) => {
|
|
83
|
+
let value = effect.get(subject, key);
|
|
84
|
+
if (!value) {
|
|
85
|
+
let initial;
|
|
86
|
+
if (!element) {
|
|
87
|
+
const target = keyframes[key];
|
|
88
|
+
initial =
|
|
89
|
+
firstKeyframe(target) ??
|
|
90
|
+
effect.read(subject, key, target);
|
|
91
|
+
invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
92
|
+
}
|
|
93
|
+
value = motionValue(initial, { owner: element });
|
|
94
|
+
effect(subject, { [key]: value });
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}, keyframes, transition, element);
|
|
98
|
+
}
|
|
99
|
+
function firstKeyframe(target) {
|
|
100
|
+
const first = Array.isArray(target) ? target[0] : undefined;
|
|
101
|
+
return first === null ? undefined : first;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { addEffect, animateEffectSubject, animateValues, findEffect, removeEffect };
|
|
105
|
+
//# sourceMappingURL=effects.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.mjs","sources":["../../../../src/animation/animate/effects.ts"],"sourcesContent":["import { invariant, removeItem } from \"motion-utils\"\nimport { AnimateEffect } from \"../../effects/utils/create-effect\"\nimport { frame } from \"../../frameloop\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { MotionValue, motionValue } from \"../../value\"\nimport { animateMotionValue } from \"../interfaces/motion-value\"\nimport { AnimationElement } from \"../keyframes/types\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n ValueTransition,\n} from \"../types\"\n\n/**\n * Effects registered via `animate.addEffect()`, most recent first.\n */\nconst effects: AnimateEffect<any>[] = []\n\nexport function addEffect(effect: AnimateEffect<any>): void {\n invariant(\n typeof effect.test === \"function\" && typeof effect.read === \"function\",\n \"Effects passed to animate.addEffect() need test() and read().\",\n \"effect-missing-test\"\n )\n\n removeEffect(effect)\n effects.unshift(effect)\n}\n\nexport function removeEffect(effect: AnimateEffect<any>): void {\n removeItem(effects, effect)\n}\n\nexport function findEffect(subject: unknown): AnimateEffect | undefined {\n return effects.find((effect) => effect.test(subject))\n}\n\nexport interface EffectKeyframes {\n [key: string]:\n | UnresolvedValueKeyframe\n | UnresolvedValueKeyframe[]\n | Record<string, unknown>\n | undefined\n transition?: Record<string, unknown>\n transitionEnd?: Record<string, AnyResolvedKeyframe>\n}\n\n/**\n * Effect subjects can expose any key, so per-key transition overrides\n * are keyed by arbitrary strings.\n */\nexport type EffectTransition = ValueTransition & {\n reduceMotion?: boolean\n skipAnimations?: boolean\n} & Record<string, unknown>\n\n/**\n * Animate each key in `keyframes` on the motion value `getValue` returns\n * for it. `element` is what the keyframe resolver uses to read, render\n * and measure the subject when the effect defers resolution to it.\n */\nexport function animateValues(\n getValue: (key: string) => MotionValue,\n keyframes: EffectKeyframes,\n transition: EffectTransition = {},\n element?: AnimationElement\n): AnimationPlaybackControlsWithThen[] {\n const animations: AnimationPlaybackControlsWithThen[] = []\n const { velocity } = transition\n const reduceMotion = transition.reduceMotion ?? element?.shouldReduceMotion\n\n for (const key in keyframes) {\n if (key === \"transition\" || key === \"transitionEnd\") continue\n\n const target = keyframes[key]\n if (target === undefined) continue\n\n const value = getValue(key)\n\n /**\n * If the value is already at the defined target, skip the animation.\n * We still re-assert the value via frame.update to take precedence\n * over any stale transitionEnd callbacks from previous animations.\n */\n const current = value.get()\n if (\n current !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(target) &&\n target === current &&\n !velocity\n ) {\n frame.update(() => value.set(target))\n continue\n }\n\n value.start(\n animateMotionValue(\n key,\n value,\n target as any,\n reduceMotion && positionalKeys.has(key)\n ? { type: false }\n : transition,\n element\n )\n )\n\n value.animation &&\n animations.push(\n value.animation as AnimationPlaybackControlsWithThen\n )\n }\n\n const { transitionEnd } = keyframes\n if (transitionEnd) {\n const applyTransitionEnd = () =>\n frame.update(() => {\n for (const key in transitionEnd) {\n getValue(key).set(transitionEnd[key])\n }\n })\n\n animations.length\n ? Promise.all(animations).then(applyTransitionEnd)\n : applyTransitionEnd()\n }\n\n return animations\n}\n\n/**\n * Animate the keys of `subject` via `effect`. Motion values are created on\n * first animation and bound to the subject through the effect for the\n * rest of its life.\n *\n * Without `element`, a new value is seeded synchronously from the first\n * keyframe or `effect.read()`. With it, the value starts undefined and the\n * keyframe resolver reads the subject (batched, with unit conversion by\n * measurement) via `element`.\n */\nexport function animateEffectSubject<Subject extends object>(\n effect: AnimateEffect<Subject>,\n subject: Subject,\n keyframes: EffectKeyframes,\n transition?: EffectTransition,\n element?: AnimationElement\n): AnimationPlaybackControlsWithThen[] {\n return animateValues(\n (key) => {\n let value = effect.get(subject, key)\n\n if (!value) {\n let initial: AnyResolvedKeyframe | undefined\n\n if (!element) {\n const target = keyframes[key] as\n | UnresolvedValueKeyframe\n | UnresolvedValueKeyframe[]\n initial =\n firstKeyframe(target) ??\n effect.read(subject, key, target)\n\n invariant(\n initial !== undefined,\n `\"${key}\" can't be read from the animated subject. Provide [from, to] keyframes.`,\n \"effect-unreadable-value\"\n )\n }\n\n value = motionValue(initial, { owner: element })\n effect(subject, { [key]: value })\n }\n\n return value\n },\n keyframes,\n transition,\n element\n )\n}\n\nfunction firstKeyframe(\n target: UnresolvedValueKeyframe | UnresolvedValueKeyframe[] | undefined\n) {\n const first = Array.isArray(target) ? target[0] : undefined\n return first === null ? undefined : first\n}\n"],"names":[],"mappings":";;;;;;AAcA;;AAEG;AACH,MAAM,OAAO,GAAyB,EAAE;AAElC,SAAU,SAAS,CAAC,MAA0B,EAAA;AAChD,IAAA,SAAS,CACL,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EACtE,+DAA+D,EAC/D,qBAAqB,CACxB;IAED,YAAY,CAAC,MAAM,CAAC;AACpB,IAAA,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;AAC3B;AAEM,SAAU,YAAY,CAAC,MAA0B,EAAA;AACnD,IAAA,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;AAC/B;AAEM,SAAU,UAAU,CAAC,OAAgB,EAAA;AACvC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QAAA,OAAO,KAAK;AAChB,IAAA,CAAC,EACD,SAAS,EACT,UAAU,EACV,OAAO,CACV;AACL;AAEA,SAAS,aAAa,CAClB,MAAuE,EAAA;AAEvE,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS;IAC3D,OAAO,KAAK,KAAK,IAAI,GAAG,SAAS,GAAG,KAAK;AAC7C;;;;"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { styleSubjectEffect } from '../../effects/style/index.mjs';
|
|
2
|
+
import { svgSubjectEffect } from '../../effects/svg/index.mjs';
|
|
3
|
+
import { measureViewportBox } from '../../projection/utils/measure.mjs';
|
|
4
|
+
import { isSVGElement } from '../../utils/is-svg-element.mjs';
|
|
5
|
+
import { DOMKeyframesResolver } from '../keyframes/DOMKeyframesResolver.mjs';
|
|
6
|
+
import { animateValues, animateEffectSubject } from './effects.mjs';
|
|
7
|
+
|
|
8
|
+
const noProps = {};
|
|
9
|
+
const getElementEffect = (element) => (isSVGElement(element)
|
|
10
|
+
? svgSubjectEffect
|
|
11
|
+
: styleSubjectEffect);
|
|
12
|
+
/**
|
|
13
|
+
* Presents an effect bound to a DOM element in the shape the DOM keyframe
|
|
14
|
+
* resolver and WAAPI expect, which is that of a VisualElement. Holds no
|
|
15
|
+
* state: everything delegates to the effect. Goes once the resolver takes
|
|
16
|
+
* an effect and subject directly.
|
|
17
|
+
*/
|
|
18
|
+
class EffectSubject {
|
|
19
|
+
constructor(effect, current) {
|
|
20
|
+
this.effect = effect;
|
|
21
|
+
this.current = current;
|
|
22
|
+
this.KeyframeResolver = DOMKeyframesResolver;
|
|
23
|
+
}
|
|
24
|
+
getValue(key) {
|
|
25
|
+
return this.effect.get(this.current, key);
|
|
26
|
+
}
|
|
27
|
+
readValue(key, target) {
|
|
28
|
+
return this.effect.read(this.current, key, target);
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
this.effect.flush(this.current);
|
|
32
|
+
}
|
|
33
|
+
measureViewportBox() {
|
|
34
|
+
return measureViewportBox(this.current);
|
|
35
|
+
}
|
|
36
|
+
getProps() {
|
|
37
|
+
return noProps;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Animate a DOM element's styles. HTML elements are bound through
|
|
42
|
+
* styleEffect, SVG through svgEffect, and both are resolved with the DOM
|
|
43
|
+
* keyframe resolver so reads are batched, units are converted by
|
|
44
|
+
* measurement and eligible values run on WAAPI.
|
|
45
|
+
*
|
|
46
|
+
* Pass the element's VisualElement (a <motion.*> component or an
|
|
47
|
+
* animateLayout() node) to animate its values instead, so the two keep
|
|
48
|
+
* sharing values and a renderer.
|
|
49
|
+
*/
|
|
50
|
+
function animateElement(element, keyframes, transition, visualElement) {
|
|
51
|
+
if (visualElement) {
|
|
52
|
+
return animateValues((key) => visualElement.getValue(key, null), keyframes, transition, visualElement);
|
|
53
|
+
}
|
|
54
|
+
const effect = getElementEffect(element);
|
|
55
|
+
return animateEffectSubject(effect, element, keyframes, transition, new EffectSubject(effect, element));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Hand the values styleEffect/svgEffect are rendering on `element`,
|
|
59
|
+
* whether bound by animate() or directly, to a VisualElement that now
|
|
60
|
+
* owns the element (e.g. created by animateLayout()), so a single
|
|
61
|
+
* renderer drives them alongside its own values.
|
|
62
|
+
*/
|
|
63
|
+
function handOffElementState(element, visualElement) {
|
|
64
|
+
const state = getElementEffect(element).state(element);
|
|
65
|
+
if (!state)
|
|
66
|
+
return;
|
|
67
|
+
const { transformKeys } = state;
|
|
68
|
+
state.release().forEach((value, key) => {
|
|
69
|
+
/**
|
|
70
|
+
* The style effect derives transform (from the bound transform
|
|
71
|
+
* keys) and transformBox itself; a VisualElement builds its own.
|
|
72
|
+
*/
|
|
73
|
+
const derived = key === "transformBox" ||
|
|
74
|
+
(key === "transform" && transformKeys?.length);
|
|
75
|
+
derived || visualElement.addValue(key, value);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { animateElement, handOffElementState };
|
|
80
|
+
//# sourceMappingURL=element.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.mjs","sources":["../../../../src/animation/animate/element.ts"],"sourcesContent":["import { styleSubjectEffect, StyleSubject } from \"../../effects/style\"\nimport { svgSubjectEffect } from \"../../effects/svg\"\nimport { measureViewportBox } from \"../../projection/utils/measure\"\nimport type { VisualElement } from \"../../render/VisualElement\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue, Owner } from \"../../value\"\nimport { DOMKeyframesResolver } from \"../keyframes/DOMKeyframesResolver\"\nimport { AnimationElement } from \"../keyframes/types\"\nimport { AnimationPlaybackControlsWithThen } from \"../types\"\nimport {\n animateEffectSubject,\n animateValues,\n EffectKeyframes,\n EffectTransition,\n} from \"./effects\"\n\nconst noProps = {}\n\ntype ElementEffect = typeof styleSubjectEffect\n\nconst getElementEffect = (element: Element) =>\n (isSVGElement(element)\n ? svgSubjectEffect\n : styleSubjectEffect) as ElementEffect\n\n/**\n * Presents an effect bound to a DOM element in the shape the DOM keyframe\n * resolver and WAAPI expect, which is that of a VisualElement. Holds no\n * state: everything delegates to the effect. Goes once the resolver takes\n * an effect and subject directly.\n */\nclass EffectSubject implements AnimationElement, Owner {\n KeyframeResolver = DOMKeyframesResolver\n\n constructor(private effect: ElementEffect, public current: StyleSubject) {}\n\n getValue(key: string) {\n return this.effect.get(this.current, key)\n }\n\n readValue(key: string, target?: unknown) {\n return this.effect.read(this.current, key, target as any)\n }\n\n render() {\n this.effect.flush(this.current)\n }\n\n measureViewportBox() {\n return measureViewportBox(this.current as HTMLElement)\n }\n\n getProps() {\n return noProps\n }\n}\n\n/**\n * Animate a DOM element's styles. HTML elements are bound through\n * styleEffect, SVG through svgEffect, and both are resolved with the DOM\n * keyframe resolver so reads are batched, units are converted by\n * measurement and eligible values run on WAAPI.\n *\n * Pass the element's VisualElement (a <motion.*> component or an\n * animateLayout() node) to animate its values instead, so the two keep\n * sharing values and a renderer.\n */\nexport function animateElement(\n element: StyleSubject,\n keyframes: EffectKeyframes,\n transition?: EffectTransition,\n visualElement?: VisualElement\n): AnimationPlaybackControlsWithThen[] {\n if (visualElement) {\n return animateValues(\n (key) => visualElement.getValue(key, null),\n keyframes,\n transition,\n visualElement\n )\n }\n\n const effect = getElementEffect(element)\n\n return animateEffectSubject(\n effect,\n element,\n keyframes,\n transition,\n new EffectSubject(effect, element)\n )\n}\n\n/**\n * Hand the values styleEffect/svgEffect are rendering on `element`,\n * whether bound by animate() or directly, to a VisualElement that now\n * owns the element (e.g. created by animateLayout()), so a single\n * renderer drives them alongside its own values.\n */\nexport function handOffElementState(\n element: Element,\n visualElement: VisualElement\n) {\n const state = getElementEffect(element).state(element as StyleSubject)\n if (!state) return\n\n const { transformKeys } = state\n state.release().forEach((value: MotionValue, key: string) => {\n /**\n * The style effect derives transform (from the bound transform\n * keys) and transformBox itself; a VisualElement builds its own.\n */\n const derived =\n key === \"transformBox\" ||\n (key === \"transform\" && transformKeys?.length)\n\n derived || visualElement.addValue(key, value)\n })\n}\n"],"names":[],"mappings":";;;;;;;AAgBA,MAAM,OAAO,GAAG,EAAE;AAIlB,MAAM,gBAAgB,GAAG,CAAC,OAAgB,MACrC,YAAY,CAAC,OAAO;AACjB,MAAE;MACA,kBAAkB,CAAkB;AAE9C;;;;;AAKG;AACH,MAAM,aAAa,CAAA;IAGf,WAAA,CAAoB,MAAqB,EAAS,OAAqB,EAAA;QAAnD,IAAA,CAAA,MAAM,GAAN,MAAM;QAAwB,IAAA,CAAA,OAAO,GAAP,OAAO;QAFzD,IAAA,CAAA,gBAAgB,GAAG,oBAAoB;IAEmC;AAE1E,IAAA,QAAQ,CAAC,GAAW,EAAA;AAChB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAA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KAAK,WAAW,IAAI,aAAa,EAAE,MAAM,CAAC;QAElD,OAAO,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;AACjD,IAAA,CAAC,CAAC;AACN;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-value.mjs","sources":["../../../../src/animation/animate/single-value.ts"],"sourcesContent":["import { animateMotionValue } from \"../interfaces/motion-value\"\nimport type {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n ValueAnimationTransition,\n} from \"../types\"\nimport {\n motionValue as createMotionValue,\n MotionValue,\n} from \"../../value\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\n\nexport function animateSingleValue<V extends AnyResolvedKeyframe>(\n value: MotionValue<V> | V,\n keyframes: V | UnresolvedValueKeyframe<V>[],\n options?: ValueAnimationTransition\n): AnimationPlaybackControlsWithThen {\n const motionValue = isMotionValue(value) ? value : createMotionValue(value)\n\n motionValue.start(animateMotionValue(\"\", motionValue, keyframes, options))\n\n return motionValue.animation
|
|
1
|
+
{"version":3,"file":"single-value.mjs","sources":["../../../../src/animation/animate/single-value.ts"],"sourcesContent":["import { animateMotionValue } from \"../interfaces/motion-value\"\nimport type {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n ValueAnimationTransition,\n} from \"../types\"\nimport {\n motionValue as createMotionValue,\n MotionValue,\n} from \"../../value\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\n\nexport function animateSingleValue<V extends AnyResolvedKeyframe>(\n value: MotionValue<V> | V,\n keyframes: V | UnresolvedValueKeyframe<V>[],\n options?: ValueAnimationTransition\n): AnimationPlaybackControlsWithThen {\n const motionValue = isMotionValue(value) ? value : createMotionValue(value)\n\n motionValue.start(animateMotionValue(\"\", motionValue, keyframes, options))\n\n return motionValue.animation as AnimationPlaybackControlsWithThen\n}\n"],"names":["motionValue","createMotionValue"],"mappings":";;;;SAagB,kBAAkB,CAC9B,KAAyB,EACzB,SAA2C,EAC3C,OAAkC,EAAA;AAElC,IAAA,MAAMA,aAAW,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,KAAK,GAAGC,WAAiB,CAAC,KAAK,CAAC;AAE3E,IAAAD,aAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,EAAEA,aAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAE1E,OAAOA,aAAW,CAAC,SAA8C;AACrE;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { spring } from './spring.mjs';
|
|
2
|
-
import { getGeneratorVelocity } from './utils/velocity.mjs';
|
|
3
2
|
|
|
4
3
|
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
5
4
|
const origin = keyframes[0];
|
|
@@ -7,7 +6,7 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
7
6
|
done: false,
|
|
8
7
|
value: origin,
|
|
9
8
|
};
|
|
10
|
-
const isOutOfBounds = (v) =>
|
|
9
|
+
const isOutOfBounds = (v) => v < min || v > max;
|
|
11
10
|
const nearestBoundary = (v) => {
|
|
12
11
|
if (min === undefined)
|
|
13
12
|
return max;
|
|
@@ -25,12 +24,10 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
25
24
|
if (target !== ideal)
|
|
26
25
|
amplitude = target - origin;
|
|
27
26
|
const calcDelta = (t) => -amplitude * Math.exp(-t / timeConstant);
|
|
28
|
-
const calcLatest = (t) => target + calcDelta(t);
|
|
29
27
|
const applyFriction = (t) => {
|
|
30
28
|
const delta = calcDelta(t);
|
|
31
|
-
const latest = calcLatest(t);
|
|
32
29
|
state.done = Math.abs(delta) <= restDelta;
|
|
33
|
-
state.value = state.done ? target :
|
|
30
|
+
state.value = state.done ? target : target + delta;
|
|
34
31
|
};
|
|
35
32
|
/**
|
|
36
33
|
* Ideally this would resolve for t in a stateless way, we could
|
|
@@ -46,7 +43,12 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
46
43
|
timeReachedBoundary = t;
|
|
47
44
|
spring$1 = spring({
|
|
48
45
|
keyframes: [state.value, nearestBoundary(state.value)],
|
|
49
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The friction curve is target + calcDelta(t), so its exact
|
|
48
|
+
* derivative is -calcDelta(t) / timeConstant in units/ms,
|
|
49
|
+
* converted here to the units/second expected by spring.
|
|
50
|
+
*/
|
|
51
|
+
velocity: (-calcDelta(t) / timeConstant) * 1000,
|
|
50
52
|
damping: bounceDamping,
|
|
51
53
|
stiffness: bounceStiffness,
|
|
52
54
|
restDelta,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inertia.mjs","sources":["../../../../src/animation/generators/inertia.ts"],"sourcesContent":["import {\n AnimationState,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\nimport { spring as createSpring } from \"./spring\"\
|
|
1
|
+
{"version":3,"file":"inertia.mjs","sources":["../../../../src/animation/generators/inertia.ts"],"sourcesContent":["import {\n AnimationState,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\nimport { spring as createSpring } from \"./spring\"\n\nexport function inertia({\n keyframes,\n velocity = 0.0,\n power = 0.8,\n timeConstant = 325,\n bounceDamping = 10,\n bounceStiffness = 500,\n modifyTarget,\n min,\n max,\n restDelta = 0.5,\n restSpeed,\n}: ValueAnimationOptions<number>): KeyframeGenerator<number> {\n const origin = keyframes[0]\n\n const state: AnimationState<number> = {\n done: false,\n value: origin,\n }\n\n const isOutOfBounds = (v: number) => v < min! || v > max!\n\n const nearestBoundary = (v: number) => {\n if (min === undefined) return max\n if (max === undefined) return min\n\n return Math.abs(min - v) < Math.abs(max - v) ? min : max\n }\n\n let amplitude = power * velocity\n const ideal = origin + amplitude\n const target = modifyTarget === undefined ? ideal : modifyTarget(ideal)\n\n /**\n * If the target has changed we need to re-calculate the amplitude, otherwise\n * the animation will start from the wrong position.\n */\n if (target !== ideal) amplitude = target - origin\n\n const calcDelta = (t: number) => -amplitude * Math.exp(-t / timeConstant)\n\n const applyFriction = (t: number) => {\n const delta = calcDelta(t)\n state.done = Math.abs(delta) <= restDelta\n state.value = state.done ? target : target + delta\n }\n\n /**\n * Ideally this would resolve for t in a stateless way, we could\n * do that by always precalculating the animation but as we know\n * this will be done anyway we can assume that spring will\n * be discovered during that.\n */\n let timeReachedBoundary: number | undefined\n let spring: KeyframeGenerator<number> | undefined\n\n const checkCatchBoundary = (t: number) => {\n if (!isOutOfBounds(state.value)) return\n\n timeReachedBoundary = t\n\n spring = createSpring({\n keyframes: [state.value, nearestBoundary(state.value)!],\n /**\n * The friction curve is target + calcDelta(t), so its exact\n * derivative is -calcDelta(t) / timeConstant in units/ms,\n * converted here to the units/second expected by spring.\n */\n velocity: (-calcDelta(t) / timeConstant) * 1000,\n damping: bounceDamping,\n stiffness: bounceStiffness,\n restDelta,\n restSpeed,\n })\n }\n\n checkCatchBoundary(0)\n\n return {\n calculatedDuration: null,\n next: (t: number) => {\n /**\n * We need to resolve the friction to figure out if we need a\n * spring but we don't want to do this twice per frame. So here\n * we flag if we updated for this frame and later if we did\n * we can skip doing it again.\n */\n let hasUpdatedFrame = false\n if (!spring && timeReachedBoundary === undefined) {\n hasUpdatedFrame = true\n applyFriction(t)\n checkCatchBoundary(t)\n }\n\n /**\n * If we have a spring and the provided t is beyond the moment the friction\n * animation crossed the min/max boundary, use the spring.\n */\n if (timeReachedBoundary !== undefined && t >= timeReachedBoundary) {\n return spring!.next(t - timeReachedBoundary)\n } else {\n !hasUpdatedFrame && applyFriction(t)\n return state\n }\n },\n }\n}\n"],"names":["spring","createSpring"],"mappings":";;SAOgB,OAAO,CAAC,EACpB,SAAS,EACT,QAAQ,GAAG,GAAG,EACd,KAAK,GAAG,GAAG,EACX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Aa,CAAC,CAAC,CAAC;AACpC,gBAAA,OAAO,KAAK;YAChB;QACJ,CAAC;KACJ;AACL;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { easeInOut, isEasingArray, easingDefinitionToFunction } from 'motion-utils';
|
|
1
|
+
import { easeInOut, isEasingArray, easingDefinitionToFunction, MotionGlobalConfig, clamp } from 'motion-utils';
|
|
2
2
|
import { interpolate } from '../../utils/interpolate.mjs';
|
|
3
|
+
import { mix } from '../../utils/mix/index.mjs';
|
|
3
4
|
import { defaultOffset } from '../keyframes/offsets/default.mjs';
|
|
4
5
|
import { convertOffsetToTimes } from '../keyframes/offsets/time.mjs';
|
|
5
6
|
|
|
@@ -22,6 +23,29 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
22
23
|
done: false,
|
|
23
24
|
value: keyframeValues[0],
|
|
24
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Fast setup path for two keyframes one easing.
|
|
28
|
+
*/
|
|
29
|
+
if (keyframeValues.length === 2 &&
|
|
30
|
+
!Array.isArray(easingFunctions) &&
|
|
31
|
+
(!times ||
|
|
32
|
+
times.length !== 2 ||
|
|
33
|
+
(times[0] === 0 && times[1] === 1))) {
|
|
34
|
+
const [origin, target] = keyframeValues;
|
|
35
|
+
const mixer = origin === target
|
|
36
|
+
? undefined
|
|
37
|
+
: (MotionGlobalConfig.mix || mix)(origin, target);
|
|
38
|
+
return {
|
|
39
|
+
calculatedDuration: duration,
|
|
40
|
+
next: (t) => {
|
|
41
|
+
state.value = mixer
|
|
42
|
+
? mixer(easingFunctions(duration > 0 ? clamp(0, 1, t / duration) : 1))
|
|
43
|
+
: target;
|
|
44
|
+
state.done = t >= duration;
|
|
45
|
+
return state;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
25
49
|
/**
|
|
26
50
|
* Create a times array based on the provided 0-1 offsets
|
|
27
51
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\nimport { defaultOffset } from \"../keyframes/offsets/default\"\nimport { convertOffsetToTimes } from \"../keyframes/offsets/time\"\nimport {\n AnimationState,\n AnyResolvedKeyframe,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\n\nexport function defaultEasing(\n values: any[],\n easing?: EasingFunction\n): EasingFunction[] {\n return values.map(() => easing || easeInOut).splice(0, values.length - 1)\n}\n\nexport function keyframes<T extends AnyResolvedKeyframe>({\n duration = 300,\n keyframes: keyframeValues,\n times,\n ease = \"easeInOut\",\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n /**\n * Easing functions can be externally defined as strings. Here we convert them\n * into actual functions.\n */\n const easingFunctions = isEasingArray(ease)\n ? ease.map(easingDefinitionToFunction)\n : easingDefinitionToFunction(ease)\n\n /**\n * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator\n * to reduce GC during animation.\n */\n const state: AnimationState<T> = {\n done: false,\n value: keyframeValues[0],\n }\n\n /**\n * Create a times array based on the provided 0-1 offsets\n */\n const absoluteTimes = convertOffsetToTimes(\n // Only use the provided offsets if they're the correct length\n // TODO Maybe we should warn here if there's a length mismatch\n times && times.length === keyframeValues.length\n ? times\n : defaultOffset(keyframeValues),\n duration\n )\n\n const mapTimeToKeyframe = interpolate<T>(absoluteTimes, keyframeValues, {\n ease: Array.isArray(easingFunctions)\n ? easingFunctions\n : defaultEasing(keyframeValues, easingFunctions),\n })\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mapTimeToKeyframe(t)\n state.done = t >= duration\n return state\n },\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n clamp,\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n MotionGlobalConfig,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\nimport { mix } from \"../../utils/mix\"\nimport { defaultOffset } from \"../keyframes/offsets/default\"\nimport { convertOffsetToTimes } from \"../keyframes/offsets/time\"\nimport {\n AnimationState,\n AnyResolvedKeyframe,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\n\nexport function defaultEasing(\n values: any[],\n easing?: EasingFunction\n): EasingFunction[] {\n return values.map(() => easing || easeInOut).splice(0, values.length - 1)\n}\n\nexport function keyframes<T extends AnyResolvedKeyframe>({\n duration = 300,\n keyframes: keyframeValues,\n times,\n ease = \"easeInOut\",\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n /**\n * Easing functions can be externally defined as strings. Here we convert them\n * into actual functions.\n */\n const easingFunctions = isEasingArray(ease)\n ? ease.map(easingDefinitionToFunction)\n : easingDefinitionToFunction(ease)\n\n /**\n * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator\n * to reduce GC during animation.\n */\n const state: AnimationState<T> = {\n done: false,\n value: keyframeValues[0],\n }\n\n /**\n * Fast setup path for two keyframes one easing.\n */\n if (\n keyframeValues.length === 2 &&\n !Array.isArray(easingFunctions) &&\n (!times ||\n times.length !== 2 ||\n (times[0] === 0 && times[1] === 1))\n ) {\n const [origin, target] = keyframeValues\n const mixer =\n origin === target\n ? undefined\n : (MotionGlobalConfig.mix || mix)(origin, target)\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mixer\n ? mixer(\n easingFunctions(\n duration > 0 ? clamp(0, 1, t / duration) : 1\n )\n )\n : target\n state.done = t >= duration\n return state\n },\n }\n }\n\n /**\n * Create a times array based on the provided 0-1 offsets\n */\n const absoluteTimes = convertOffsetToTimes(\n // Only use the provided offsets if they're the correct length\n // TODO Maybe we should warn here if there's a length mismatch\n times && times.length === keyframeValues.length\n ? times\n : defaultOffset(keyframeValues),\n duration\n )\n\n const mapTimeToKeyframe = interpolate<T>(absoluteTimes, keyframeValues, {\n ease: Array.isArray(easingFunctions)\n ? easingFunctions\n : defaultEasing(keyframeValues, easingFunctions),\n })\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mapTimeToKeyframe(t)\n state.done = t >= duration\n return state\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAmBM,SAAU,aAAa,CACzB,MAAa,EACb,MAAuB,EAAA;IAEvB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7E;SAEgB,SAAS,CAAgC,EACrD,QAAQ,GAAG,GAAG,EACd,SAAS,EAAE,cAAc,EACzB,KAAK,EACL,IAAI,GAAG,WAAW,GACK,EAAA;AACvB;;;AAGG;AACH,IAAA,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI;AACtC,UAAE,IAAI,CAAC,GAAG,CAAC,0BAA0B;AACrC,UAAE,0BAA0B,CAAC,IAAI,CAAC;AAEtC;;;AAGG;AACH,IAAA,MAAM,KAAK,GAAsB;AAC7B,QAAA,IAAI,EAAE,KAAK;AACX,QAAA,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;KAC3B;AAED;;AAEG;AACH,IAAA,IACI,cAAc,CAAC,MAAM,KAAK,CAAC;AAC3B,QAAA,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;AAC/B,SAAC,CAAC,KAAK;YACH,KAAK,CAAC,MAAM,KAAK,CAAC;AAClB,aAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACzC;AACE,QAAA,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc;AACvC,QAAA,MAAM,KAAK,GACP,MAAM,KAAK;AACP,cAAE;AACF,cAAE,CAAC,kBAAkB,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