motion-dom 13.5.0 → 14.0.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 +260 -442
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +2 -4
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-variant.mjs +29 -49
- package/dist/es/animation/interfaces/visual-element-variant.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element.mjs +5 -14
- package/dist/es/animation/interfaces/visual-element.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +6 -1
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +1 -1
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/svg/index.mjs +18 -7
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/render/VisualElement.mjs +17 -57
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +144 -267
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +7 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs.map +1 -1
- package/dist/es/render/utils/resolve-variants.mjs +8 -19
- package/dist/es/render/utils/resolve-variants.mjs.map +1 -1
- package/dist/index.d.ts +16 -24
- package/dist/motion-dom.dev.js +260 -442
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,340 +1,218 @@
|
|
|
1
1
|
import { animateVisualElement } from '../../animation/interfaces/visual-element.mjs';
|
|
2
2
|
import { calcChildStagger } from '../../animation/utils/calc-child-stagger.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
4
4
|
import { isAnimationControls } from './is-animation-controls.mjs';
|
|
5
|
-
import { isKeyframesTarget } from './is-keyframes-target.mjs';
|
|
6
5
|
import { isVariantLabel } from './is-variant-label.mjs';
|
|
7
|
-
import { resolveVariant } from './resolve-dynamic-variants.mjs';
|
|
6
|
+
import { resolveVariant, getTypeCustom } from './resolve-dynamic-variants.mjs';
|
|
8
7
|
import { shallowCompare } from './shallow-compare.mjs';
|
|
9
8
|
import { variantPriorityOrder } from './variant-props.mjs';
|
|
10
9
|
|
|
11
10
|
const reversePriorityOrder = [...variantPriorityOrder].reverse();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Diffs the element's animation props (one layer per AnimationType, highest
|
|
13
|
+
* priority wins each value) against the previous call and starts animations
|
|
14
|
+
* for what changed.
|
|
15
|
+
*
|
|
16
|
+
* Uses `any` type for visualElement to avoid circular dependencies. It reads
|
|
17
|
+
* props, parent, presenceContext, variantChildren, enteringChildren,
|
|
18
|
+
* manuallyAnimateOnMount, blockInitialAnimation, getValue(),
|
|
19
|
+
* getBaseTargetFromProps(), baseTarget and initialValues.
|
|
20
|
+
*/
|
|
18
21
|
function createAnimationState(visualElement) {
|
|
19
|
-
let animate =
|
|
22
|
+
let animate = (animations) => Promise.all(animations.map(({ animation, options }) => animateVisualElement(visualElement, animation, options)));
|
|
20
23
|
let state = createState();
|
|
21
24
|
let isInitialRender = true;
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* animateChanges() call after a reset we need to behave like the initial
|
|
26
|
-
* render for variant-inheritance checks, even though isInitialRender is
|
|
27
|
-
* already false.
|
|
26
|
+
* After a reset (StrictMode, Suspense, AnimatePresence re-entry) the next
|
|
27
|
+
* animateChanges() mounts again, but initial={false} no longer applies.
|
|
28
28
|
*/
|
|
29
29
|
let wasReset = false;
|
|
30
|
-
/**
|
|
31
|
-
* This function will be used to reduce the animation definitions for
|
|
32
|
-
* each active animation type into an object of resolved values for it.
|
|
33
|
-
*/
|
|
34
|
-
const buildResolvedTypeValues = (type) => (acc, definition) => {
|
|
35
|
-
const resolved = resolveVariant(visualElement, definition, type === "exit"
|
|
36
|
-
? visualElement.presenceContext?.custom
|
|
37
|
-
: undefined);
|
|
38
|
-
if (resolved) {
|
|
39
|
-
const { transition, transitionEnd, ...target } = resolved;
|
|
40
|
-
acc = { ...acc, ...target, ...transitionEnd };
|
|
41
|
-
}
|
|
42
|
-
return acc;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* This just allows us to inject mocked animation functions
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
function setAnimateFunction(makeAnimator) {
|
|
49
|
-
animate = makeAnimator(visualElement);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* When we receive new props, we need to:
|
|
53
|
-
* 1. Create a list of protected keys for each type. This is a directory of
|
|
54
|
-
* value keys that are currently being "handled" by types of a higher priority
|
|
55
|
-
* so that whenever an animation is played of a given type, these values are
|
|
56
|
-
* protected from being animated.
|
|
57
|
-
* 2. Determine if an animation type needs animating.
|
|
58
|
-
* 3. Determine if any values have been removed from a type and figure out
|
|
59
|
-
* what to animate those to.
|
|
60
|
-
*/
|
|
61
30
|
function animateChanges(changedActiveType) {
|
|
62
|
-
const { props } = visualElement;
|
|
63
|
-
const
|
|
64
|
-
/**
|
|
65
|
-
* A list of animations that we'll build into as we iterate through the animation
|
|
66
|
-
* types. This will get executed at the end of the function.
|
|
67
|
-
*/
|
|
31
|
+
const { props, parent, manuallyAnimateOnMount } = visualElement;
|
|
32
|
+
const isMounting = isInitialRender || wasReset;
|
|
68
33
|
const animations = [];
|
|
69
34
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
35
|
+
* Values removed from a type. A lower-priority type that defines
|
|
36
|
+
* them animates them back, otherwise they fall back to a base target.
|
|
72
37
|
*/
|
|
73
38
|
const removedKeys = new Set();
|
|
74
39
|
/**
|
|
75
|
-
*
|
|
76
|
-
* copy it without iteration. Each time we hit an animation type we set its protected
|
|
77
|
-
* keys - the keys its not allowed to animate - to the latest version of this object.
|
|
40
|
+
* Values claimed by active, higher-priority types.
|
|
78
41
|
*/
|
|
79
42
|
let encounteredKeys = {};
|
|
80
43
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
44
|
+
* Once a type has been deactivated, lower-priority variant labels
|
|
45
|
+
* re-animate so variant children animate back too.
|
|
83
46
|
*/
|
|
84
47
|
let removedVariantIndex = Infinity;
|
|
85
48
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* need to be animated). If any values have been removed, we want to detect those in
|
|
89
|
-
* lower priority props and flag for animation.
|
|
49
|
+
* Variant labels are inherited from the closest variant-controlling
|
|
50
|
+
* ancestor, unless an element on the way has inherit={false}.
|
|
90
51
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
52
|
+
let source = visualElement;
|
|
53
|
+
do
|
|
54
|
+
source = source.props.inherit !== false && source.parent;
|
|
55
|
+
while (source && !source.isControllingVariants);
|
|
56
|
+
reversePriorityOrder.forEach((type, i) => {
|
|
93
57
|
const typeState = state[type];
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
58
|
+
const ownProp = props[type];
|
|
59
|
+
const inheritedProp = source && source.props[type];
|
|
60
|
+
const prop = ownProp !== undefined
|
|
61
|
+
? ownProp
|
|
62
|
+
: isVariantLabel(inheritedProp) || inheritedProp === false
|
|
63
|
+
? inheritedProp
|
|
64
|
+
: undefined;
|
|
97
65
|
const propIsVariant = isVariantLabel(prop);
|
|
98
|
-
/**
|
|
99
|
-
* If this type has *just* changed isActive status, set activeDelta
|
|
100
|
-
* to that status. Otherwise set to null.
|
|
101
|
-
*/
|
|
102
66
|
const activeDelta = type === changedActiveType ? typeState.isActive : null;
|
|
103
67
|
if (activeDelta === false)
|
|
104
68
|
removedVariantIndex = i;
|
|
105
69
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* TODO: Can probably change this to a !isControllingVariants check
|
|
110
|
-
*/
|
|
111
|
-
let isInherited = prop === context[type] &&
|
|
112
|
-
prop !== props[type] &&
|
|
113
|
-
propIsVariant;
|
|
114
|
-
if (isInherited &&
|
|
115
|
-
(isInitialRender || wasReset) &&
|
|
116
|
-
visualElement.manuallyAnimateOnMount) {
|
|
117
|
-
isInherited = false;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Set all encountered keys so far as the protected keys for this type. This will
|
|
121
|
-
* be any key that has been animated or otherwise handled by active, higher-priority types.
|
|
70
|
+
* Inherited labels are animated by the parent through
|
|
71
|
+
* variantChildren, unless this element mounted after its parent.
|
|
122
72
|
*/
|
|
73
|
+
const isInherited = propIsVariant &&
|
|
74
|
+
ownProp === undefined &&
|
|
75
|
+
!(isMounting && manuallyAnimateOnMount);
|
|
123
76
|
typeState.protectedKeys = { ...encounteredKeys };
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
// If it isn't active and hasn't *just* been set as inactive
|
|
127
|
-
(!typeState.isActive && activeDelta === null) ||
|
|
128
|
-
// If we didn't and don't have any defined prop for this animation type
|
|
77
|
+
if ((!typeState.isActive && activeDelta === null) ||
|
|
129
78
|
(!prop && !typeState.prevProp) ||
|
|
130
|
-
// Or if the prop doesn't define an animation
|
|
131
79
|
isAnimationControls(prop) ||
|
|
132
80
|
typeof prop === "boolean") {
|
|
133
|
-
|
|
81
|
+
return;
|
|
134
82
|
}
|
|
135
83
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* value animations that stop the originals, leaving the exit
|
|
140
|
-
* animation promise unresolved and the component stuck in the DOM.
|
|
84
|
+
* Don't re-resolve a running exit: a changed custom would start
|
|
85
|
+
* new value animations that stop the originals, leaving the exit
|
|
86
|
+
* promise unresolved and the element stuck in the DOM.
|
|
141
87
|
*/
|
|
142
88
|
if (type === "exit" && typeState.isActive && activeDelta !== true) {
|
|
143
|
-
|
|
144
|
-
encounteredKeys
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
continue;
|
|
89
|
+
encounteredKeys = {
|
|
90
|
+
...encounteredKeys,
|
|
91
|
+
...typeState.prevResolvedValues,
|
|
92
|
+
};
|
|
93
|
+
return;
|
|
150
94
|
}
|
|
151
|
-
/**
|
|
152
|
-
* As we go look through the values defined on this type, if we detect
|
|
153
|
-
* a changed value or a value that was removed in a higher priority, we set
|
|
154
|
-
* this to true and add this prop to the animation list.
|
|
155
|
-
*/
|
|
156
95
|
const variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
|
|
157
96
|
let shouldAnimateType = variantDidChange ||
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
typeState.isActive &&
|
|
161
|
-
!isInherited &&
|
|
162
|
-
propIsVariant) ||
|
|
163
|
-
// If we removed a higher-priority variant (i is in reverse order)
|
|
164
|
-
(i > removedVariantIndex && propIsVariant);
|
|
97
|
+
(propIsVariant &&
|
|
98
|
+
((activeDelta && !isInherited) || i > removedVariantIndex));
|
|
165
99
|
let handledRemovedValues = false;
|
|
166
|
-
/**
|
|
167
|
-
* As animations can be set as variant lists, variants or target objects, we
|
|
168
|
-
* coerce everything to an array if it isn't one already
|
|
169
|
-
*/
|
|
170
100
|
const definitionList = Array.isArray(prop) ? prop : [prop];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* and decide:
|
|
181
|
-
* 1. If the value has changed, and needs animating
|
|
182
|
-
* 2. If it has been removed, and needs adding to the removedKeys set
|
|
183
|
-
* 3. If it has been removed in a higher priority type and needs animating
|
|
184
|
-
* 4. If it hasn't been removed in a higher priority but hasn't changed, and
|
|
185
|
-
* needs adding to the type's protectedKeys list.
|
|
186
|
-
*/
|
|
187
|
-
const { prevResolvedValues = {} } = typeState;
|
|
188
|
-
const allKeys = {
|
|
189
|
-
...prevResolvedValues,
|
|
190
|
-
...resolvedValues,
|
|
191
|
-
};
|
|
192
|
-
const markToAnimate = (key) => {
|
|
193
|
-
shouldAnimateType = true;
|
|
194
|
-
if (removedKeys.has(key)) {
|
|
195
|
-
handledRemovedValues = true;
|
|
196
|
-
removedKeys.delete(key);
|
|
101
|
+
let resolvedValues = {};
|
|
102
|
+
if (activeDelta !== false) {
|
|
103
|
+
for (const definition of definitionList) {
|
|
104
|
+
const { transition, transitionEnd, ...target } = resolveVariant(visualElement, definition, getTypeCustom(visualElement, type)) || {};
|
|
105
|
+
resolvedValues = {
|
|
106
|
+
...resolvedValues,
|
|
107
|
+
...target,
|
|
108
|
+
...transitionEnd,
|
|
109
|
+
};
|
|
197
110
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (const key in allKeys) {
|
|
111
|
+
}
|
|
112
|
+
const { prevResolvedValues } = typeState;
|
|
113
|
+
for (const key in { ...prevResolvedValues, ...resolvedValues }) {
|
|
114
|
+
if (key in encounteredKeys)
|
|
115
|
+
continue;
|
|
204
116
|
const next = resolvedValues[key];
|
|
205
117
|
const prev = prevResolvedValues[key];
|
|
206
|
-
// If we've already handled this we can just skip ahead
|
|
207
|
-
if (encounteredKeys.hasOwnProperty(key))
|
|
208
|
-
continue;
|
|
209
118
|
/**
|
|
210
|
-
*
|
|
119
|
+
* Keyframes compare by value, but replay whenever the
|
|
120
|
+
* variant label changed.
|
|
211
121
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
valueHasChanged = next !== prev;
|
|
122
|
+
const valueHasChanged = Array.isArray(next) && Array.isArray(prev)
|
|
123
|
+
? !shallowCompare(next, prev) || variantDidChange
|
|
124
|
+
: next !== prev;
|
|
125
|
+
if (valueHasChanged &&
|
|
126
|
+
(next === undefined || next === null)) {
|
|
127
|
+
removedKeys.add(key);
|
|
219
128
|
}
|
|
220
|
-
if (valueHasChanged
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
else if (next !== undefined && removedKeys.has(key)) {
|
|
231
|
-
/**
|
|
232
|
-
* If next hasn't changed and it isn't undefined, we want to check if it's
|
|
233
|
-
* been removed by a higher priority
|
|
234
|
-
*/
|
|
235
|
-
markToAnimate(key);
|
|
129
|
+
else if (valueHasChanged ||
|
|
130
|
+
(next !== undefined && removedKeys.has(key))) {
|
|
131
|
+
shouldAnimateType = true;
|
|
132
|
+
if (removedKeys.delete(key))
|
|
133
|
+
handledRemovedValues = true;
|
|
134
|
+
typeState.needsAnimating[key] = true;
|
|
135
|
+
const motionValue = visualElement.getValue(key);
|
|
136
|
+
if (motionValue)
|
|
137
|
+
motionValue.liveStyle = false;
|
|
236
138
|
}
|
|
237
139
|
else {
|
|
238
|
-
/**
|
|
239
|
-
* If it hasn't changed, we add it to the list of protected values
|
|
240
|
-
* to ensure it doesn't get animated.
|
|
241
|
-
*/
|
|
242
140
|
typeState.protectedKeys[key] = true;
|
|
243
141
|
}
|
|
244
142
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Update the typeState so next time animateChanges is called we can compare the
|
|
247
|
-
* latest prop and resolvedValues to these.
|
|
248
|
-
*/
|
|
249
143
|
typeState.prevProp = prop;
|
|
250
144
|
typeState.prevResolvedValues = resolvedValues;
|
|
251
145
|
if (typeState.isActive) {
|
|
252
146
|
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
253
147
|
}
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* If this is an inherited prop we want to skip this animation
|
|
260
|
-
* unless the inherited variants haven't changed on this render.
|
|
261
|
-
*/
|
|
262
|
-
const willAnimateViaParent = isInherited && variantDidChange;
|
|
263
|
-
const needsAnimating = !willAnimateViaParent || handledRemovedValues;
|
|
264
|
-
if (shouldAnimateType && needsAnimating) {
|
|
265
|
-
animations.push(...definitionList.map((animation) => {
|
|
148
|
+
if (shouldAnimateType &&
|
|
149
|
+
(!(isInherited && variantDidChange) || handledRemovedValues)) {
|
|
150
|
+
for (const animation of definitionList) {
|
|
266
151
|
const options = { type };
|
|
267
152
|
/**
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
153
|
+
* Elements that mount into an already-mounted parent
|
|
154
|
+
* animate themselves, staggered by the parent variant's
|
|
155
|
+
* delayChildren.
|
|
271
156
|
*/
|
|
272
157
|
if (typeof animation === "string" &&
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (parent.enteringChildren && parentVariant) {
|
|
280
|
-
const { delayChildren } = parentVariant.transition || {};
|
|
281
|
-
options.delay = calcChildStagger(parent.enteringChildren, visualElement, delayChildren);
|
|
282
|
-
}
|
|
158
|
+
isMounting &&
|
|
159
|
+
manuallyAnimateOnMount &&
|
|
160
|
+
parent?.enteringChildren) {
|
|
161
|
+
const delayChildren = resolveVariant(parent, animation)
|
|
162
|
+
?.transition?.delayChildren;
|
|
163
|
+
options.delay = calcChildStagger(parent.enteringChildren, visualElement, delayChildren);
|
|
283
164
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
options,
|
|
287
|
-
};
|
|
288
|
-
}));
|
|
165
|
+
animations.push({ animation, options });
|
|
166
|
+
}
|
|
289
167
|
}
|
|
290
|
-
}
|
|
168
|
+
});
|
|
291
169
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
170
|
+
* Removed values that no lower-priority type defines animate back to
|
|
171
|
+
* initial, then style, then the value as first read. If initial no
|
|
172
|
+
* longer defines a value it once did, it stays where it is.
|
|
295
173
|
*/
|
|
296
174
|
if (removedKeys.size) {
|
|
175
|
+
const { initial } = props;
|
|
297
176
|
const fallbackAnimation = {};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (typeof props.initial !== "boolean") {
|
|
303
|
-
const initialTransition = resolveVariant(visualElement, Array.isArray(props.initial)
|
|
304
|
-
? props.initial[0]
|
|
305
|
-
: props.initial);
|
|
306
|
-
if (initialTransition && initialTransition.transition) {
|
|
307
|
-
fallbackAnimation.transition = initialTransition.transition;
|
|
308
|
-
}
|
|
177
|
+
const resolvedInitial = typeof initial !== "boolean" &&
|
|
178
|
+
resolveVariant(visualElement, Array.isArray(initial) ? initial[0] : initial, visualElement.presenceContext?.custom);
|
|
179
|
+
if (resolvedInitial && resolvedInitial.transition) {
|
|
180
|
+
fallbackAnimation.transition = resolvedInitial.transition;
|
|
309
181
|
}
|
|
310
182
|
removedKeys.forEach((key) => {
|
|
311
|
-
const fallbackTarget = visualElement.getBaseTarget(key);
|
|
312
183
|
const motionValue = visualElement.getValue(key);
|
|
313
184
|
if (motionValue)
|
|
314
185
|
motionValue.liveStyle = true;
|
|
315
|
-
|
|
316
|
-
|
|
186
|
+
const fromInitial = resolvedInitial && !Array.isArray(initial)
|
|
187
|
+
? resolvedInitial[key]
|
|
188
|
+
: undefined;
|
|
189
|
+
const fromProps = visualElement.getBaseTargetFromProps(props, key);
|
|
190
|
+
fallbackAnimation[key] =
|
|
191
|
+
(fromInitial !== undefined
|
|
192
|
+
? fromInitial
|
|
193
|
+
: fromProps !== undefined && !isMotionValue(fromProps)
|
|
194
|
+
? fromProps
|
|
195
|
+
: visualElement.initialValues[key] === undefined
|
|
196
|
+
? visualElement.baseTarget[key]
|
|
197
|
+
: undefined) ?? null;
|
|
317
198
|
});
|
|
318
199
|
animations.push({ animation: fallbackAnimation });
|
|
319
200
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return shouldAnimate ? animate(animations) : Promise.resolve();
|
|
201
|
+
const blockAnimation = (isMounting && visualElement.blockInitialAnimation) ||
|
|
202
|
+
(isInitialRender &&
|
|
203
|
+
!manuallyAnimateOnMount &&
|
|
204
|
+
(props.initial === false || props.initial === props.animate));
|
|
205
|
+
isInitialRender = wasReset = false;
|
|
206
|
+
return !blockAnimation && animations.length
|
|
207
|
+
? animate(animations)
|
|
208
|
+
: Promise.resolve();
|
|
329
209
|
}
|
|
330
210
|
/**
|
|
331
211
|
* Change whether a certain animation type is active.
|
|
332
212
|
*/
|
|
333
213
|
function setActive(type, isActive) {
|
|
334
|
-
// If the active state hasn't changed, we can safely do nothing here
|
|
335
214
|
if (state[type].isActive === isActive)
|
|
336
215
|
return Promise.resolve();
|
|
337
|
-
// Propagate active change to children
|
|
338
216
|
visualElement.variantChildren?.forEach((child) => child.animationState?.setActive(type, isActive));
|
|
339
217
|
state[type].isActive = isActive;
|
|
340
218
|
const animations = animateChanges(type);
|
|
@@ -346,7 +224,13 @@ function createAnimationState(visualElement) {
|
|
|
346
224
|
return {
|
|
347
225
|
animateChanges,
|
|
348
226
|
setActive,
|
|
349
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Allows tests to inject a mocked animate function.
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
setAnimateFunction: (makeAnimator) => {
|
|
232
|
+
animate = makeAnimator(visualElement);
|
|
233
|
+
},
|
|
350
234
|
getState: () => state,
|
|
351
235
|
reset: () => {
|
|
352
236
|
state = createState();
|
|
@@ -363,24 +247,17 @@ function checkVariantsDidChange(prev, next) {
|
|
|
363
247
|
}
|
|
364
248
|
return false;
|
|
365
249
|
}
|
|
366
|
-
function createTypeState(isActive = false) {
|
|
367
|
-
return {
|
|
368
|
-
isActive,
|
|
369
|
-
protectedKeys: {},
|
|
370
|
-
needsAnimating: {},
|
|
371
|
-
prevResolvedValues: {},
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
250
|
function createState() {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
251
|
+
const state = {};
|
|
252
|
+
for (const type of variantPriorityOrder) {
|
|
253
|
+
state[type] = {
|
|
254
|
+
isActive: type === "animate",
|
|
255
|
+
protectedKeys: {},
|
|
256
|
+
needsAnimating: {},
|
|
257
|
+
prevResolvedValues: {},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return state;
|
|
384
261
|
}
|
|
385
262
|
|
|
386
263
|
export { checkVariantsDidChange, createAnimationState };
|