motion-dom 14.10.0 → 14.11.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 +886 -126
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs +21 -15
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +15 -4
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +44 -16
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/get-final.mjs +18 -4
- package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +155 -42
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +4 -0
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
- package/dist/es/gestures/pinch/index.mjs +552 -0
- package/dist/es/gestures/pinch/index.mjs.map +1 -0
- package/dist/es/gestures/press/index.mjs +6 -2
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +39 -17
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/render/utils/get-variant-context.mjs.map +1 -1
- package/dist/es/render/utils/variant-props.mjs +1 -0
- package/dist/es/render/utils/variant-props.mjs.map +1 -1
- package/dist/es/value/index.mjs +24 -20
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/utils/animatable-none.mjs +13 -1
- package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
- package/dist/index.d.ts +360 -105
- package/dist/motion-dom.dev.js +886 -126
- 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-pinch.js +2 -0
- package/dist/size-rollup-pinch.js.map +1 -0
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +6 -2
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
class GroupAnimation {
|
|
2
2
|
constructor(animations) {
|
|
3
3
|
// Bound to accommodate common `return animation.stop` pattern
|
|
4
|
-
this.stop = () =>
|
|
4
|
+
this.stop = () => {
|
|
5
|
+
for (const animation of this.animations)
|
|
6
|
+
animation.stop();
|
|
7
|
+
};
|
|
5
8
|
this.animations = animations.filter(Boolean);
|
|
6
9
|
}
|
|
7
10
|
get finished() {
|
|
@@ -13,11 +16,6 @@ class GroupAnimation {
|
|
|
13
16
|
getAll(propName) {
|
|
14
17
|
return this.animations[0][propName];
|
|
15
18
|
}
|
|
16
|
-
setAll(propName, newValue) {
|
|
17
|
-
for (let i = 0; i < this.animations.length; i++) {
|
|
18
|
-
this.animations[i][propName] = newValue;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
19
|
attachTimeline(timeline) {
|
|
22
20
|
const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
|
|
23
21
|
return () => {
|
|
@@ -30,14 +28,21 @@ class GroupAnimation {
|
|
|
30
28
|
get time() {
|
|
31
29
|
return this.getAll("time");
|
|
32
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Setters and methods name the property directly, rather than through
|
|
33
|
+
* a shared helper, so each call site stays monomorphic. Sequences
|
|
34
|
+
* call these on every animation, many times a second.
|
|
35
|
+
*/
|
|
33
36
|
set time(time) {
|
|
34
|
-
this.
|
|
37
|
+
for (const animation of this.animations)
|
|
38
|
+
animation.time = time;
|
|
35
39
|
}
|
|
36
40
|
get speed() {
|
|
37
41
|
return this.getAll("speed");
|
|
38
42
|
}
|
|
39
43
|
set speed(speed) {
|
|
40
|
-
this.
|
|
44
|
+
for (const animation of this.animations)
|
|
45
|
+
animation.speed = speed;
|
|
41
46
|
}
|
|
42
47
|
get state() {
|
|
43
48
|
return this.getAll("state");
|
|
@@ -51,20 +56,21 @@ class GroupAnimation {
|
|
|
51
56
|
get iterationDuration() {
|
|
52
57
|
return getMax(this.animations, "iterationDuration");
|
|
53
58
|
}
|
|
54
|
-
runAll(methodName) {
|
|
55
|
-
this.animations.forEach((controls) => controls[methodName]());
|
|
56
|
-
}
|
|
57
59
|
play() {
|
|
58
|
-
this.
|
|
60
|
+
for (const animation of this.animations)
|
|
61
|
+
animation.play();
|
|
59
62
|
}
|
|
60
63
|
pause() {
|
|
61
|
-
this.
|
|
64
|
+
for (const animation of this.animations)
|
|
65
|
+
animation.pause();
|
|
62
66
|
}
|
|
63
67
|
cancel() {
|
|
64
|
-
this.
|
|
68
|
+
for (const animation of this.animations)
|
|
69
|
+
animation.cancel();
|
|
65
70
|
}
|
|
66
71
|
complete() {
|
|
67
|
-
this.
|
|
72
|
+
for (const animation of this.animations)
|
|
73
|
+
animation.complete();
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
function getMax(animations, propName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupAnimation.mjs","sources":["../../../src/animation/GroupAnimation.ts"],"sourcesContent":["import { AnimationPlaybackControls, TimelineWithFallback } from \"./types\"\n\ntype PropNames =\n | \"time\"\n | \"speed\"\n | \"duration\"\n | \"attachTimeline\"\n | \"startTime\"\n | \"state\"\n\nexport type AcceptedAnimations = AnimationPlaybackControls\n\nexport type GroupedAnimations = AcceptedAnimations[]\n\nexport class GroupAnimation implements AnimationPlaybackControls {\n animations: GroupedAnimations\n\n constructor(animations: Array<AcceptedAnimations | undefined>) {\n this.animations = animations.filter(Boolean) as GroupedAnimations\n }\n\n get finished() {\n return Promise.all(\n this.animations.map((animation) => animation.finished)\n )\n }\n\n /**\n * TODO: Filter out cancelled or stopped animations before returning\n */\n private getAll(propName: PropNames) {\n return this.animations[0][propName] as any\n }\n\n
|
|
1
|
+
{"version":3,"file":"GroupAnimation.mjs","sources":["../../../src/animation/GroupAnimation.ts"],"sourcesContent":["import { AnimationPlaybackControls, TimelineWithFallback } from \"./types\"\n\ntype PropNames =\n | \"time\"\n | \"speed\"\n | \"duration\"\n | \"attachTimeline\"\n | \"startTime\"\n | \"state\"\n\nexport type AcceptedAnimations = AnimationPlaybackControls\n\nexport type GroupedAnimations = AcceptedAnimations[]\n\nexport class GroupAnimation implements AnimationPlaybackControls {\n animations: GroupedAnimations\n\n constructor(animations: Array<AcceptedAnimations | undefined>) {\n this.animations = animations.filter(Boolean) as GroupedAnimations\n }\n\n get finished() {\n return Promise.all(\n this.animations.map((animation) => animation.finished)\n )\n }\n\n /**\n * TODO: Filter out cancelled or stopped animations before returning\n */\n private getAll(propName: PropNames) {\n return this.animations[0][propName] as any\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n const subscriptions = this.animations.map((animation) =>\n animation.attachTimeline(timeline)\n )\n\n return () => {\n subscriptions.forEach((cancel, i) => {\n cancel && cancel()\n this.animations[i].stop()\n })\n }\n }\n\n get time() {\n return this.getAll(\"time\")\n }\n\n /**\n * Setters and methods name the property directly, rather than through\n * a shared helper, so each call site stays monomorphic. Sequences\n * call these on every animation, many times a second.\n */\n set time(time: number) {\n for (const animation of this.animations) animation.time = time\n }\n\n get speed() {\n return this.getAll(\"speed\")\n }\n\n set speed(speed: number) {\n for (const animation of this.animations) animation.speed = speed\n }\n\n get state() {\n return this.getAll(\"state\")\n }\n\n get startTime() {\n return this.getAll(\"startTime\")\n }\n\n get duration() {\n return getMax(this.animations, \"duration\")\n }\n\n get iterationDuration() {\n return getMax(this.animations, \"iterationDuration\")\n }\n\n play() {\n for (const animation of this.animations) animation.play()\n }\n\n pause() {\n for (const animation of this.animations) animation.pause()\n }\n\n // Bound to accommodate common `return animation.stop` pattern\n stop = () => {\n for (const animation of this.animations) animation.stop()\n }\n\n cancel() {\n for (const animation of this.animations) animation.cancel()\n }\n\n complete() {\n for (const animation of this.animations) animation.complete()\n }\n}\n\nfunction getMax(\n animations: GroupedAnimations,\n propName: \"iterationDuration\" | \"duration\"\n): number {\n let max = 0\n\n for (let i = 0; i < animations.length; i++) {\n const value = animations[i][propName]\n if (value !== null && value > max) {\n max = value\n }\n }\n return max\n}\n"],"names":[],"mappings":"MAca,cAAc,CAAA;AAGvB,IAAA,WAAA,CAAY,UAAiD,EAAA;;QA4E7D,IAAA,CAAA,IAAI,GAAG,MAAK;AACR,YAAA,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU;gBAAE,SAAS,CAAC,IAAI,EAAE;AAC7D,QAAA,CAAC;QA7EG,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAsB;IACrE;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,OAAO,CAAC,GAAG,CACd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,QAAQ,CAAC,CACzD;IACL;AAEA;;AAEG;AACK,IAAA,MAAM,CAAC,QAAmB,EAAA;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAQ;IAC9C;AAEA,IAAA,cAAc,CAAC,QAA8B,EAAA;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,KAChD,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC,CACrC;AAED,QAAA,OAAO,MAAK;YACR,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,KAAI;gBAChC,MAAM,IAAI,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S,IAAI,IAAI,CAAC,UAAU;YAAE,SAAS,CAAC,MAAM,EAAE;IAC/D;IAEA,QAAQ,GAAA;AACJ,QAAA,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU;YAAE,SAAS,CAAC,QAAQ,EAAE;IACjE;AACH;AAED,SAAS,MAAM,CACX,UAA6B,EAC7B,QAA0C,EAAA;IAE1C,IAAI,GAAG,GAAG,CAAC;AAEX,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACrC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,GAAG,GAAG,EAAE;YAC/B,GAAG,GAAG,KAAK;QACf;IACJ;AACA,IAAA,OAAO,GAAG;AACd;;;;"}
|
|
@@ -59,7 +59,7 @@ function animateValues(getValue, keyframes, transition = {}, element) {
|
|
|
59
59
|
frame.update(() => value.set(target));
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
|
-
value.
|
|
62
|
+
value.run(animateMotionValue(key, value, target, reduceMotion && positionalKeys.has(key)
|
|
63
63
|
? { type: false }
|
|
64
64
|
: transition, element));
|
|
65
65
|
value.animation &&
|
|
@@ -89,8 +89,14 @@ function animateValues(getValue, keyframes, transition = {}, element) {
|
|
|
89
89
|
* measurement) via `element`.
|
|
90
90
|
*/
|
|
91
91
|
function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Values made for this call are bound with one effect call, after the
|
|
94
|
+
* loop, rather than one each.
|
|
95
|
+
*/
|
|
96
|
+
let created;
|
|
97
|
+
let isBound = false;
|
|
98
|
+
const animations = animateValues((key) => {
|
|
99
|
+
let value = created?.[key] ?? effect.get(subject, key);
|
|
94
100
|
if (!value) {
|
|
95
101
|
let initial;
|
|
96
102
|
if (!element) {
|
|
@@ -102,10 +108,15 @@ function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
|
102
108
|
invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
103
109
|
}
|
|
104
110
|
value = motionValue(initial, { owner: element });
|
|
105
|
-
|
|
111
|
+
isBound
|
|
112
|
+
? effect(subject, { [key]: value })
|
|
113
|
+
: ((created || (created = {}))[key] = value);
|
|
106
114
|
}
|
|
107
115
|
return value;
|
|
108
116
|
}, keyframes, transition, element);
|
|
117
|
+
isBound = true;
|
|
118
|
+
created && effect(subject, created);
|
|
119
|
+
return animations;
|
|
109
120
|
}
|
|
110
121
|
function firstKeyframe(target) {
|
|
111
122
|
const first = Array.isArray(target) ? target[0] : undefined;
|
|
@@ -1 +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 process.env.NODE_ENV !== \"production\" &&\n invariant(\n typeof effect.test === \"function\" &&\n 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, path } = transition\n const reduceMotion = transition.reduceMotion ?? element?.shouldReduceMotion\n\n /**\n * Only elements have x/y to move along a path. path claims them by\n * deleting them, so hand it a copy.\n */\n if (path?.animateValues && element) {\n keyframes = { ...keyframes }\n path.animateValues(getValue, keyframes, transition, 0, animations)\n }\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 process.env.NODE_ENV !== \"production\" &&\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,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;AACjC,QAAA,SAAS,CACL,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU;YAC7B,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EACrC,+DAA+D,EAC/D,qBAAqB,C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C,OAAO,EAAE;AACV,gBAAA,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAEG;gBAC/B,OAAO;oBACH,aAAa,CAAC,MAAM,CAAC;wBACrB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC;AAErC,gBAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;oBACjC,SAAS,CACL,OAAO,KAAK,SAAS,EACrB,CAAA,CAAA,EAAI,GAAG,CAAA,wEAAA,CAA0E,EACjF,yBAAyB,CAC5B;YACT;YAEA,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAChD,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,CAAC;QACrC;AAEA,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;;;;"}
|
|
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 process.env.NODE_ENV !== \"production\" &&\n invariant(\n typeof effect.test === \"function\" &&\n 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, path } = transition\n const reduceMotion = transition.reduceMotion ?? element?.shouldReduceMotion\n\n /**\n * Only elements have x/y to move along a path. path claims them by\n * deleting them, so hand it a copy.\n */\n if (path?.animateValues && element) {\n keyframes = { ...keyframes }\n path.animateValues(getValue, keyframes, transition, 0, animations)\n }\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.run(\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 /**\n * Values made for this call are bound with one effect call, after the\n * loop, rather than one each.\n */\n let created: Record<string, MotionValue> | undefined\n let isBound = false\n\n const animations = animateValues(\n (key) => {\n let value = created?.[key] ?? 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 process.env.NODE_ENV !== \"production\" &&\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 isBound\n ? effect(subject, { [key]: value })\n : ((created ||= {})[key] = value)\n }\n\n return value\n },\n keyframes,\n transition,\n element\n )\n\n isBound = true\n created && effect(subject, created)\n\n return animations\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,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;AACjC,QAAA,SAAS,CACL,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU;YAC7B,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EACrC,+DAA+D,EAC/D,qBAAqB,CACxB;IAEL,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,IAAA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzD;AAqBA;;;;AAIG;AACG,SAAU,aAAa,CACzB,QAAsC,EACtC,SAA0B,EAC1B,UAAA,GAA+B,EAAE,EACjC,OAA0B,EAAA;IAE1B,MAAM,UAAU,GAAwC,EAAE;AAC1D,IAAA,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,UAAU;IACrC,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,IAAI,OAAO,EAAE,kBAAkB;AAE3E;;;AAGG;AACH,IAAA,IAAI,IAAI,EAAE,aAAa,IAAI,OAAO,EAAE;AAChC,QAAA,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE;AAC5B,QAAA,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,EAA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,EACT,UAAU,EACV,OAAO,CACV;IAED,OAAO,GAAG,IAAI;AACd,IAAA,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;AAEnC,IAAA,OAAO,UAAU;AACrB;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;;;;"}
|
|
@@ -4,7 +4,7 @@ import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
|
4
4
|
|
|
5
5
|
function animateSingleValue(value, keyframes, options) {
|
|
6
6
|
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
7
|
-
motionValue$1.
|
|
7
|
+
motionValue$1.run(animateMotionValue("", motionValue$1, keyframes, options));
|
|
8
8
|
return motionValue$1.animation;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -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.
|
|
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.run(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,GAAG,CAAC,kBAAkB,CAAC,EAAE,EAAEA,aAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAExE,OAAOA,aAAW,CAAC,SAA8C;AACrE;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { easeInOut, isEasingArray, easingDefinitionToFunction, MotionGlobalConfig
|
|
1
|
+
import { easeInOut, isEasingArray, easingDefinitionToFunction, MotionGlobalConfig } from 'motion-utils';
|
|
2
2
|
import { interpolate } from '../../utils/interpolate.mjs';
|
|
3
3
|
import { mix } from '../../utils/mix/index.mjs';
|
|
4
4
|
import { defaultOffset } from '../keyframes/offsets/default.mjs';
|
|
@@ -30,25 +30,53 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
30
30
|
value: keyframeValues[0],
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* a
|
|
33
|
+
* Two keyframes, or keyframes that hold, move once, then hold, as each
|
|
34
|
+
* value of a sequence does, ease and mix only the pair that moves.
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
let span = -1;
|
|
37
|
+
if (!customMixer) {
|
|
38
|
+
for (let i = 1; i < keyframeValues.length; i++) {
|
|
39
|
+
if (keyframeValues[i] !== keyframeValues[i - 1]) {
|
|
40
|
+
if (span >= 0) {
|
|
41
|
+
span = -2;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
span = i - 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (span >= 0) {
|
|
49
|
+
const offsets = times && times.length === keyframeValues.length
|
|
50
|
+
? times
|
|
51
|
+
: defaultOffset(keyframeValues);
|
|
52
|
+
const from = offsets[span] * duration;
|
|
53
|
+
const to = offsets[span + 1] * duration;
|
|
54
|
+
const origin = keyframeValues[span];
|
|
55
|
+
const target = keyframeValues[span + 1];
|
|
56
|
+
const ease = Array.isArray(easingFunctions)
|
|
57
|
+
? easingFunctions[span]
|
|
58
|
+
: easingFunctions;
|
|
59
|
+
const mixer = (MotionGlobalConfig.mix || mix)(origin, target);
|
|
60
|
+
const last = keyframeValues.length - 2;
|
|
46
61
|
return {
|
|
47
62
|
calculatedDuration: duration,
|
|
48
63
|
next: (t) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Held keyframes either side of the move are mixed as
|
|
66
|
+
* interpolate() mixes them, so colours keep its format.
|
|
67
|
+
*/
|
|
68
|
+
state.value =
|
|
69
|
+
span && t < from
|
|
70
|
+
? mixer(0)
|
|
71
|
+
: span < last && (t >= to || !duration)
|
|
72
|
+
? typeof target === "number"
|
|
73
|
+
? target
|
|
74
|
+
: mixer(1)
|
|
75
|
+
: mixer(ease(t >= to || !duration
|
|
76
|
+
? 1
|
|
77
|
+
: t <= from
|
|
78
|
+
? 0
|
|
79
|
+
: (t - from) / (to - from)));
|
|
52
80
|
state.done = t >= duration;
|
|
53
81
|
return state;
|
|
54
82
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\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 mixer: transitionMixer,\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n /**\n * A mixer only blends values that aren't numbers. Numbers blend as\n * usual, as they do in springs, and so do the progress animations\n * behind layout and path animations, which take the same transition.\n */\n const customMixer =\n typeof keyframeValues[0] === \"number\" ? undefined : transitionMixer\n\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) || easeInOut\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 * Two keyframes, or keyframes that hold, move once, then hold, as each\n * value of a sequence does, ease and mix only the pair that moves.\n */\n let span = -1\n if (!customMixer) {\n for (let i = 1; i < keyframeValues.length; i++) {\n if (keyframeValues[i] !== keyframeValues[i - 1]) {\n if (span >= 0) {\n span = -2\n break\n }\n span = i - 1\n }\n }\n }\n\n if (span >= 0) {\n const offsets =\n times && times.length === keyframeValues.length\n ? times\n : defaultOffset(keyframeValues)\n const from = offsets[span] * duration\n const to = offsets[span + 1] * duration\n const origin = keyframeValues[span]\n const target = keyframeValues[span + 1]\n const ease = Array.isArray(easingFunctions)\n ? easingFunctions[span]\n : easingFunctions\n const mixer = (MotionGlobalConfig.mix || mix)(origin, target)\n const last = keyframeValues.length - 2\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n /**\n * Held keyframes either side of the move are mixed as\n * interpolate() mixes them, so colours keep its format.\n */\n state.value =\n span && t < from\n ? mixer(0)\n : span < last && (t >= to || !duration)\n ? typeof target === \"number\"\n ? target\n : mixer(1)\n : mixer(\n ease(\n t >= to || !duration\n ? 1\n : t <= from\n ? 0\n : (t - from) / (to - from)\n )\n )\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 mixer: customMixer,\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":";;;;;;AAkBM,SAAU,aAAa,CACzB,MAAa,EACb,MAAuB,EAAA;IAEvB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,IAAI,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,CAAC,cAAc,CAAC,EACnC,QAAQ,CACX;AAED,IAAA,MAAM,iBAAiB,GAAG,WAAW,CAAI,aAAa,EAAE,cAAc,EAAE;AACpE,QAAA,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe;AAC/B,cAAE;AACF,cAAE,aAAa,CAAC,cAAc,EAAE,eAAe,CAAC;AACpD,QAAA,KAAK,EAAE,WAAW;AACrB,KAAA,CAAC;IAEF,OAAO;AACH,QAAA,kBAAkB,EAAE,QAAQ;AAC5B,QAAA,IAAI,EAAE,CAAC,CAAS,KAAI;AAChB,YAAA,KAAK,CAAC,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC;AAClC,YAAA,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,QAAQ;AAC1B,YAAA,OAAO,KAAK;QAChB,CAAC;KACJ;AACL;;;;"}
|
|
@@ -83,7 +83,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
83
83
|
}
|
|
84
84
|
addValueToWillChange(visualElement, key);
|
|
85
85
|
const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
|
|
86
|
-
value.
|
|
86
|
+
value.run(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
|
|
87
87
|
? { type: false }
|
|
88
88
|
: valueTransition, visualElement, isHandoff));
|
|
89
89
|
const animation = value.animation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock = key in protectedKeys && !needsAnimating[key]\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition,\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const defaultTransition = visualElement.getDefaultTransition()\n transition = transition\n ? resolveTransition(transition, defaultTransition)\n : defaultTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n const skipAnimations = transition?.skipAnimations\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type && visualElement.animationState?.getState()[type]\n\n const path = (transition as { path?: MotionPath } | undefined)?.path\n if (path) {\n // path mutates `target` to claim x/y; loop below skips them.\n path.animateValues\n ? path.animateValues(\n (key) =>\n visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? 0\n ),\n target,\n transition,\n delay,\n animations\n )\n : path.animateVisualElement?.(\n visualElement,\n target,\n transition,\n delay,\n animations\n )\n }\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(\n animationTypeState?.out[key] || transition || {},\n key\n ),\n }\n\n if (skipAnimations) valueTransition.skipAnimations = true\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 currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n frame.update(() => value.set(valueTarget as any))\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (isBrowser && window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.
|
|
1
|
+
{"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock = key in protectedKeys && !needsAnimating[key]\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition,\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const defaultTransition = visualElement.getDefaultTransition()\n transition = transition\n ? resolveTransition(transition, defaultTransition)\n : defaultTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n const skipAnimations = transition?.skipAnimations\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type && visualElement.animationState?.getState()[type]\n\n const path = (transition as { path?: MotionPath } | undefined)?.path\n if (path) {\n // path mutates `target` to claim x/y; loop below skips them.\n path.animateValues\n ? path.animateValues(\n (key) =>\n visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? 0\n ),\n target,\n transition,\n delay,\n animations\n )\n : path.animateVisualElement?.(\n visualElement,\n target,\n transition,\n delay,\n animations\n )\n }\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(\n animationTypeState?.out[key] || transition || {},\n key\n ),\n }\n\n if (skipAnimations) valueTransition.skipAnimations = true\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 currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n frame.update(() => value.set(valueTarget as any))\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (isBrowser && window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.run(\n animateMotionValue(\n key,\n value,\n valueTarget,\n shouldReduceMotion && positionalKeys.has(key)\n ? { type: false }\n : valueTransition,\n visualElement,\n isHandoff\n )\n )\n\n const animation = value.animation as\n | AnimationPlaybackControlsWithThen\n | undefined\n\n if (animation) {\n animations.push(animation)\n }\n }\n\n if (transitionEnd) {\n const applyTransitionEnd = () =>\n frame.update(() => {\n transitionEnd && setTarget(visualElement, transitionEnd)\n })\n\n if (animations.length) {\n Promise.all(animations).then(applyTransitionEnd)\n } else {\n applyTransitionEnd()\n }\n }\n\n return animations\n}\n"],"names":[],"mappings":";;;;;;;;;AAeA,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW;AAE/C;;;;;AAKG;AACH,SAAS,oBAAoB,CACzB,EAAE,aAAa,EAAE,cAAc,EAAsB,EACrD,GAAW,EAAA;IAEX,MAAM,WAAW,GAAG,GAAG,IAAI,aAAa,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;AAEhE,IAAA,cAAc,CAAC,GAAG,CAAC,GAAG,KAAK;AAC3B,IAAA,OAAO,WAAW;AACtB;SAEgB,aAAa,CACzB,aAA4B,EAC5B,mBAAwC,EACxC,EAAE,KAAK,GAAG,CAAC,EAAE,kBAAkB,EAAE,IA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AI,cAAc,CAAC,GAAG,CAAC,GAAG;AACxC,cAAE,EAAE,IAAI,EAAE,KAAK;cACb,eAAe,EACrB,aAAa,EACb,SAAS,CACZ,CACJ;AAED,QAAA,MAAM,SAAS,GAAG,KAAK,CAAC,SAET;QAEf,IAAI,SAAS,EAAE;AACX,YAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QAC9B;IACJ;IAEA,IAAI,aAAa,EAAE;QACf,MAAM,kBAAkB,GAAG,MACvB,KAAK,CAAC,MAAM,CAAC,MAAK;AACd,YAAA,aAAa,IAAI,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;AAC5D,QAAA,CAAC,CAAC;AAEN,QAAA,IAAI,UAAU,CAAC,MAAM,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACpD;aAAO;AACH,YAAA,kBAAkB,EAAE;QACxB;IACJ;AAEA,IAAA,OAAO,UAAU;AACrB;;;;"}
|
|
@@ -8,9 +8,14 @@ import { makeNoneKeyframesAnimatable } from './utils/make-none-animatable.mjs';
|
|
|
8
8
|
import { positionalValues, isNumOrPxType } from './utils/unit-conversion.mjs';
|
|
9
9
|
|
|
10
10
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Passes isAsync to the base constructor rather than setting it as a
|
|
13
|
+
* class field, which would compile to a constructor that spreads
|
|
14
|
+
* `arguments` into super(). That spread is slow in the interpreter,
|
|
15
|
+
* and animate() constructs one resolver per value.
|
|
16
|
+
*/
|
|
17
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
18
|
+
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMKeyframesResolver.mjs","sources":["../../../../src/animation/keyframes/DOMKeyframesResolver.ts"],"sourcesContent":["import { positionalKeys } from \"../../render/utils/keys-position\"\nimport { findDimensionValueType } from \"../../value/types/dimensions\"\nimport { AnyResolvedKeyframe } from \"../types\"\nimport { getVariableValue } from \"../utils/css-variables-conversion\"\nimport {\n containsCSSVariable,\n isCSSVariableToken,\n} from \"../utils/is-css-variable\"\nimport { KeyframeResolver } from \"./KeyframesResolver\"\nimport { WithRender } from \"./types\"\nimport { isNone } from \"./utils/is-none\"\nimport { makeNoneKeyframesAnimatable } from \"./utils/make-none-animatable\"\nimport { isNumOrPxType, positionalValues } from \"./utils/unit-conversion\"\n\nexport class DOMKeyframesResolver<\n T extends AnyResolvedKeyframe\n> extends KeyframeResolver<T> {\n name: string\n element?: WithRender\n\n private measuredOrigin?: AnyResolvedKeyframe\n\n protected isAsync = true\n\n /**\n * Keyframes that don't need reading from the DOM, or measuring,\n * resolve straight away rather than in the frame loop's batched read.\n */\n scheduleResolve() {\n if (this.canReadNow()) {\n this.readKeyframes()\n if (!this.needsMeasurement) return this.complete()\n }\n\n super.scheduleResolve()\n }\n\n private canReadNow() {\n const { unresolvedKeyframes, element, motionValue } = this\n const origin = unresolvedKeyframes[0] ?? motionValue?.get()\n\n if (!element?.current || origin === undefined) return false\n\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (containsCSSVariable(i ? unresolvedKeyframes[i] : origin)) {\n return false\n }\n }\n\n return true\n }\n\n readKeyframes() {\n const { unresolvedKeyframes, element, name } = this\n\n if (!element?.current) return\n\n super.readKeyframes()\n\n /**\n * If any keyframe is a CSS variable, we need to find its value by sampling the element\n */\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n let keyframe = unresolvedKeyframes[i]\n\n if (typeof keyframe === \"string\") {\n keyframe = keyframe.trim()\n\n if (isCSSVariableToken(keyframe)) {\n const resolved = getVariableValue(keyframe, element.current)\n\n if (resolved !== undefined) {\n unresolvedKeyframes[i] = resolved as T\n }\n\n if (i === unresolvedKeyframes.length - 1) {\n this.finalKeyframe = keyframe as T\n }\n }\n }\n }\n\n /**\n * Resolve \"none\" values. We do this potentially twice - once before and once after measuring keyframes.\n * This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which\n * have a far bigger performance impact.\n */\n this.resolveNoneKeyframes()\n\n /**\n * Check to see if unit type has changed. If so schedule jobs that will\n * temporarily set styles to the destination keyframes.\n * Skip if we have more than two keyframes or this isn't a positional value.\n * TODO: We can throw if there are multiple keyframes and the value type changes.\n */\n if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {\n return\n }\n\n const [origin, target] = unresolvedKeyframes\n\n // Two numbers share a unit, so skip the value type search.\n if (typeof origin === \"number\" && typeof target === \"number\") return\n\n const originType = findDimensionValueType(origin)\n const targetType = findDimensionValueType(target)\n\n /**\n * If one keyframe contains embedded CSS variables (e.g. in calc()) and the other\n * doesn't, we need to measure to convert to pixels. This handles GitHub issue #3410.\n */\n const originHasVar = containsCSSVariable(origin)\n const targetHasVar = containsCSSVariable(target)\n\n if (originHasVar !== targetHasVar && positionalValues[name]) {\n this.needsMeasurement = true\n return\n }\n\n /**\n * Either we don't recognise these value types or we can animate between them.\n */\n if (originType === targetType) return\n\n /**\n * If both values are numbers or pixels, we can animate between them by\n * converting them to numbers.\n */\n if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n const value = unresolvedKeyframes[i]\n if (typeof value === \"string\") {\n unresolvedKeyframes[i] = parseFloat(value as string)\n }\n }\n } else if (positionalValues[name]) {\n /**\n * Else, the only way to resolve this is by measuring the element.\n */\n this.needsMeasurement = true\n }\n }\n\n resolveNoneKeyframes() {\n const { unresolvedKeyframes, name } = this\n\n const noneKeyframeIndexes: number[] = []\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (\n unresolvedKeyframes[i] === null ||\n isNone(unresolvedKeyframes[i])\n ) {\n noneKeyframeIndexes.push(i)\n }\n }\n\n if (noneKeyframeIndexes.length) {\n makeNoneKeyframesAnimatable(\n unresolvedKeyframes,\n noneKeyframeIndexes,\n name\n )\n }\n }\n\n private measure() {\n const { element, name } = this\n return positionalValues[name](\n window.getComputedStyle(element!.current!),\n () => element!.measureViewportBox()\n )\n }\n\n measureInitialState() {\n const { element, unresolvedKeyframes, name } = this\n\n if (!element?.current) return\n\n if (name === \"height\") this.suspendedScrollY = window.pageYOffset\n\n this.measuredOrigin = this.measure()\n\n unresolvedKeyframes[0] = this.measuredOrigin\n\n // Set final key frame to measure after next render\n const measureKeyframe =\n unresolvedKeyframes[unresolvedKeyframes.length - 1]\n\n if (measureKeyframe !== undefined) {\n this.motionValue?.jump(measureKeyframe as T, false)\n }\n }\n\n measureEndState() {\n const { element, unresolvedKeyframes } = this\n\n if (!element?.current) return\n\n this.motionValue?.jump(this.measuredOrigin as T, false)\n\n const finalKeyframeIndex = unresolvedKeyframes.length - 1\n const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex]\n\n unresolvedKeyframes[finalKeyframeIndex] = this.measure() as any\n\n if (finalKeyframe !== null && this.finalKeyframe === undefined) {\n this.finalKeyframe = finalKeyframe as T\n }\n\n this.resolveNoneKeyframes()\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAcM,MAAO,oBAEX,SAAQ,gBAAmB,CAAA;AAF7B,IAAA,WAAA,GAAA;;QAQc,IAAA,CAAA,OAAO,GAAG,IAAI;IA6L5B;AA3LI;;;AAGG;IACH,eAAe,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YACnB,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,gBAAgB;AAAE,gBAAA,OAAO,IAAI,CAAC,QAAQ,EAAE;QACtD;QAEA,KAAK,CAAC,eAAe,EAAE;IAC3B;IAEQ,UAAU,GAAA;QACd,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;QAC1D,MAAM,MAAM,G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AE;YAC/B,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,eAAoB,EAAE,KAAK,CAAC;QACvD;IACJ;IAEA,eAAe,GAAA;AACX,QAAA,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,IAAI;QAE7C,IAAI,CAAC,OAAO,EAAE,OAAO;YAAE;QAEvB,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,cAAmB,EAAE,KAAK,CAAC;AAEvD,QAAA,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,MAAM,GAAG,CAAC;AACzD,QAAA,MAAM,aAAa,GAAG,mBAAmB,CAAC,kBAAkB,CAAC;QAE7D,mBAAmB,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,OAAO,EAAS;QAE/D,IAAI,aAAa,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AAC5D,YAAA,IAAI,CAAC,aAAa,GAAG,aAAkB;QAC3C;QAEA,IAAI,CAAC,oBAAoB,EAAE;IAC/B;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"DOMKeyframesResolver.mjs","sources":["../../../../src/animation/keyframes/DOMKeyframesResolver.ts"],"sourcesContent":["import { positionalKeys } from \"../../render/utils/keys-position\"\nimport { findDimensionValueType } from \"../../value/types/dimensions\"\nimport { AnyResolvedKeyframe } from \"../types\"\nimport { getVariableValue } from \"../utils/css-variables-conversion\"\nimport {\n containsCSSVariable,\n isCSSVariableToken,\n} from \"../utils/is-css-variable\"\nimport type { MotionValue } from \"../../value\"\nimport {\n KeyframeResolver,\n OnKeyframesResolved,\n UnresolvedKeyframes,\n} from \"./KeyframesResolver\"\nimport { WithRender } from \"./types\"\nimport { isNone } from \"./utils/is-none\"\nimport { makeNoneKeyframesAnimatable } from \"./utils/make-none-animatable\"\nimport { isNumOrPxType, positionalValues } from \"./utils/unit-conversion\"\n\nexport class DOMKeyframesResolver<\n T extends AnyResolvedKeyframe\n> extends KeyframeResolver<T> {\n name: string\n element?: WithRender\n\n private measuredOrigin?: AnyResolvedKeyframe\n\n /**\n * Passes isAsync to the base constructor rather than setting it as a\n * class field, which would compile to a constructor that spreads\n * `arguments` into super(). That spread is slow in the interpreter,\n * and animate() constructs one resolver per value.\n */\n constructor(\n unresolvedKeyframes: UnresolvedKeyframes<AnyResolvedKeyframe>,\n onComplete: OnKeyframesResolved<T>,\n name?: string,\n motionValue?: MotionValue<T>,\n element?: WithRender\n ) {\n super(unresolvedKeyframes, onComplete, name, motionValue, element, true)\n }\n\n /**\n * Keyframes that don't need reading from the DOM, or measuring,\n * resolve straight away rather than in the frame loop's batched read.\n */\n scheduleResolve() {\n if (this.canReadNow()) {\n this.readKeyframes()\n if (!this.needsMeasurement) return this.complete()\n }\n\n super.scheduleResolve()\n }\n\n private canReadNow() {\n const { unresolvedKeyframes, element, motionValue } = this\n const origin = unresolvedKeyframes[0] ?? motionValue?.get()\n\n if (!element?.current || origin === undefined) return false\n\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (containsCSSVariable(i ? unresolvedKeyframes[i] : origin)) {\n return false\n }\n }\n\n return true\n }\n\n readKeyframes() {\n const { unresolvedKeyframes, element, name } = this\n\n if (!element?.current) return\n\n super.readKeyframes()\n\n /**\n * If any keyframe is a CSS variable, we need to find its value by sampling the element\n */\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n let keyframe = unresolvedKeyframes[i]\n\n if (typeof keyframe === \"string\") {\n keyframe = keyframe.trim()\n\n if (isCSSVariableToken(keyframe)) {\n const resolved = getVariableValue(keyframe, element.current)\n\n if (resolved !== undefined) {\n unresolvedKeyframes[i] = resolved as T\n }\n\n if (i === unresolvedKeyframes.length - 1) {\n this.finalKeyframe = keyframe as T\n }\n }\n }\n }\n\n /**\n * Resolve \"none\" values. We do this potentially twice - once before and once after measuring keyframes.\n * This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which\n * have a far bigger performance impact.\n */\n this.resolveNoneKeyframes()\n\n /**\n * Check to see if unit type has changed. If so schedule jobs that will\n * temporarily set styles to the destination keyframes.\n * Skip if we have more than two keyframes or this isn't a positional value.\n * TODO: We can throw if there are multiple keyframes and the value type changes.\n */\n if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {\n return\n }\n\n const [origin, target] = unresolvedKeyframes\n\n // Two numbers share a unit, so skip the value type search.\n if (typeof origin === \"number\" && typeof target === \"number\") return\n\n const originType = findDimensionValueType(origin)\n const targetType = findDimensionValueType(target)\n\n /**\n * If one keyframe contains embedded CSS variables (e.g. in calc()) and the other\n * doesn't, we need to measure to convert to pixels. This handles GitHub issue #3410.\n */\n const originHasVar = containsCSSVariable(origin)\n const targetHasVar = containsCSSVariable(target)\n\n if (originHasVar !== targetHasVar && positionalValues[name]) {\n this.needsMeasurement = true\n return\n }\n\n /**\n * Either we don't recognise these value types or we can animate between them.\n */\n if (originType === targetType) return\n\n /**\n * If both values are numbers or pixels, we can animate between them by\n * converting them to numbers.\n */\n if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n const value = unresolvedKeyframes[i]\n if (typeof value === \"string\") {\n unresolvedKeyframes[i] = parseFloat(value as string)\n }\n }\n } else if (positionalValues[name]) {\n /**\n * Else, the only way to resolve this is by measuring the element.\n */\n this.needsMeasurement = true\n }\n }\n\n resolveNoneKeyframes() {\n const { unresolvedKeyframes, name } = this\n\n const noneKeyframeIndexes: number[] = []\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (\n unresolvedKeyframes[i] === null ||\n isNone(unresolvedKeyframes[i])\n ) {\n noneKeyframeIndexes.push(i)\n }\n }\n\n if (noneKeyframeIndexes.length) {\n makeNoneKeyframesAnimatable(\n unresolvedKeyframes,\n noneKeyframeIndexes,\n name\n )\n }\n }\n\n private measure() {\n const { element, name } = this\n return positionalValues[name](\n window.getComputedStyle(element!.current!),\n () => element!.measureViewportBox()\n )\n }\n\n measureInitialState() {\n const { element, unresolvedKeyframes, name } = this\n\n if (!element?.current) return\n\n if (name === \"height\") this.suspendedScrollY = window.pageYOffset\n\n this.measuredOrigin = this.measure()\n\n unresolvedKeyframes[0] = this.measuredOrigin\n\n // Set final key frame to measure after next render\n const measureKeyframe =\n unresolvedKeyframes[unresolvedKeyframes.length - 1]\n\n if (measureKeyframe !== undefined) {\n this.motionValue?.jump(measureKeyframe as T, false)\n }\n }\n\n measureEndState() {\n const { element, unresolvedKeyframes } = this\n\n if (!element?.current) return\n\n this.motionValue?.jump(this.measuredOrigin as T, false)\n\n const finalKeyframeIndex = unresolvedKeyframes.length - 1\n const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex]\n\n unresolvedKeyframes[finalKeyframeIndex] = this.measure() as any\n\n if (finalKeyframe !== null && this.finalKeyframe === undefined) {\n this.finalKeyframe = finalKeyframe as T\n }\n\n this.resolveNoneKeyframes()\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBM,MAAO,oBAEX,SAAQ,gBAAmB,CAAA;AAMzB;;;;;AAKG;IACH,WAAA,CACI,mBAA6D,EAC7D,UAAkC,EAClC,IAAa,EACb,WAA4B,EAC5B,OAAoB,EAAA;AAEpB,QAAA,KAAK,CAAC,mBAAmB,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;IAC5E;AAEA;;;AAGG;IACH,eAAe,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YACnB,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,gBAAgB;AAAE,gBAAA,OAAO,IAAI,CAAC,QAAQ,EAAE;QACtD;QAEA,KAAK,CAAC,eAAe,EAAE;IAC3B;IAEQ,UAAU,GAAA;QACd,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;QAC1D,MAAM,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,GAAG,EAAE;AAE3D,QAAA,IA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;IACJ;IAEA,eAAe,GAAA;AACX,QAAA,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,IAAI;QAE7C,IAAI,CAAC,OAAO,EAAE,OAAO;YAAE;QAEvB,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,cAAmB,EAAE,KAAK,CAAC;AAEvD,QAAA,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,MAAM,GAAG,CAAC;AACzD,QAAA,MAAM,aAAa,GAAG,mBAAmB,CAAC,kBAAkB,CAAC;QAE7D,mBAAmB,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,OAAO,EAAS;QAE/D,IAAI,aAAa,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AAC5D,YAAA,IAAI,CAAC,aAAa,GAAG,aAAkB;QAC3C;QAEA,IAAI,CAAC,oBAAoB,EAAE;IAC/B;AACH;;;;"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
const isNotNull = (value) => value !== null;
|
|
2
1
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The first and last keyframes that aren't null, and how many there
|
|
4
|
+
* are. Found in one pass rather than filtering into a new array, as
|
|
5
|
+
* this runs for every value of every animation.
|
|
6
|
+
*/
|
|
7
|
+
let first;
|
|
8
|
+
let last;
|
|
9
|
+
let numResolved = 0;
|
|
10
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
11
|
+
const keyframe = keyframes[i];
|
|
12
|
+
if (keyframe !== null) {
|
|
13
|
+
if (!numResolved++)
|
|
14
|
+
first = keyframe;
|
|
15
|
+
last = keyframe;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
4
18
|
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
5
|
-
const index = useFirstKeyframe ? 0 :
|
|
19
|
+
const index = useFirstKeyframe ? 0 : numResolved - 1;
|
|
6
20
|
return !index || finalKeyframe === undefined
|
|
7
|
-
?
|
|
21
|
+
? (index ? last : first)
|
|
8
22
|
: finalKeyframe;
|
|
9
23
|
}
|
|
10
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-final.mjs","sources":["../../../../src/animation/keyframes/get-final.ts"],"sourcesContent":["import { AnimationPlaybackOptions } from \"../types\"\n\
|
|
1
|
+
{"version":3,"file":"get-final.mjs","sources":["../../../../src/animation/keyframes/get-final.ts"],"sourcesContent":["import { AnimationPlaybackOptions } from \"../types\"\n\nexport function getFinalKeyframe<T>(\n keyframes: T[],\n { repeat, repeatType = \"loop\" }: AnimationPlaybackOptions,\n finalKeyframe?: T,\n speed: number = 1\n): T {\n /**\n * The first and last keyframes that aren't null, and how many there\n * are. Found in one pass rather than filtering into a new array, as\n * this runs for every value of every animation.\n */\n let first: T | undefined\n let last: T | undefined\n let numResolved = 0\n for (let i = 0; i < keyframes.length; i++) {\n const keyframe = keyframes[i]\n if (keyframe !== null) {\n if (!numResolved++) first = keyframe\n last = keyframe\n }\n }\n\n const useFirstKeyframe =\n speed < 0 || (repeat && repeatType !== \"loop\" && repeat % 2 === 1)\n const index = useFirstKeyframe ? 0 : numResolved - 1\n\n return !index || finalKeyframe === undefined\n ? ((index ? last : first) as T)\n : finalKeyframe\n}\n"],"names":[],"mappings":"SAEgB,gBAAgB,CAC5B,SAAc,EACd,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,EAA4B,EACzD,aAAiB,EACjB,QAAgB,CAAC,EAAA;AAEjB;;;;AAIG;AACH,IAAA,IAAI,KAAoB;AACxB,IAAA,IAAI,IAAmB;IACvB,IAAI,WAAW,GAAG,CAAC;AACnB,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACvC,QAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;AAC7B,QAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;YACnB,IAAI,CAAC,WAAW,EAAE;gBAAE,KAAK,GAAG,QAAQ;YACpC,IAAI,GAAG,QAAQ;QACnB;IACJ;AAEA,IAAA,MAAM,gBAAgB,GAClB,KAAK,GAAG,CAAC,KAAK,MAAM,IAAI,UAAU,KAAK,MAAM,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;AACtE,IAAA,MAAM,KAAK,GAAG,gBAAgB,GAAG,CAAC,GAAG,WAAW,GAAG,CAAC;AAEpD,IAAA,OAAO,CAAC,KAAK,IAAI,aAAa,KAAK;WAC3B,KAAK,GAAG,IAAI,GAAG,KAAK;UACtB,aAAa;AACvB;;;;"}
|