motion-dom 13.4.5 → 13.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/cjs/index.js +698 -790
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/FollowAnimation.mjs +1 -4
  4. package/dist/es/animation/FollowAnimation.mjs.map +1 -1
  5. package/dist/es/animation/NativeAnimation.mjs +5 -5
  6. package/dist/es/animation/NativeAnimation.mjs.map +1 -1
  7. package/dist/es/animation/drivers/frame.mjs +2 -1
  8. package/dist/es/animation/drivers/frame.mjs.map +1 -1
  9. package/dist/es/animation/generators/spring.mjs +64 -35
  10. package/dist/es/animation/generators/spring.mjs.map +1 -1
  11. package/dist/es/animation/interfaces/visual-element-target.mjs +2 -4
  12. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  13. package/dist/es/animation/interfaces/visual-element-variant.mjs +29 -49
  14. package/dist/es/animation/interfaces/visual-element-variant.mjs.map +1 -1
  15. package/dist/es/animation/interfaces/visual-element.mjs +5 -14
  16. package/dist/es/animation/interfaces/visual-element.mjs.map +1 -1
  17. package/dist/es/animation/utils/notify-inspector.mjs +1 -1
  18. package/dist/es/animation/utils/notify-inspector.mjs.map +1 -1
  19. package/dist/es/effects/MotionValueState.mjs +6 -1
  20. package/dist/es/effects/MotionValueState.mjs.map +1 -1
  21. package/dist/es/effects/style/index.mjs +1 -1
  22. package/dist/es/effects/style/index.mjs.map +1 -1
  23. package/dist/es/effects/svg/index.mjs +18 -7
  24. package/dist/es/effects/svg/index.mjs.map +1 -1
  25. package/dist/es/frameloop/batcher.mjs +5 -6
  26. package/dist/es/frameloop/batcher.mjs.map +1 -1
  27. package/dist/es/frameloop/frame-data.mjs +12 -0
  28. package/dist/es/frameloop/frame-data.mjs.map +1 -0
  29. package/dist/es/frameloop/frame.mjs +3 -2
  30. package/dist/es/frameloop/frame.mjs.map +1 -1
  31. package/dist/es/frameloop/sync-time.mjs +1 -1
  32. package/dist/es/frameloop/sync-time.mjs.map +1 -1
  33. package/dist/es/index.mjs +3 -2
  34. package/dist/es/index.mjs.map +1 -1
  35. package/dist/es/layout/LayoutAnimationBuilder.mjs +2 -1
  36. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  37. package/dist/es/projection/animation/mix-values.mjs +1 -1
  38. package/dist/es/projection/animation/mix-values.mjs.map +1 -1
  39. package/dist/es/projection/node/create-projection-node.mjs +11 -1
  40. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  41. package/dist/es/projection/styles/default-scale-correctors.mjs +18 -0
  42. package/dist/es/projection/styles/default-scale-correctors.mjs.map +1 -0
  43. package/dist/es/projection/styles/scale-correction.mjs +1 -14
  44. package/dist/es/projection/styles/scale-correction.mjs.map +1 -1
  45. package/dist/es/projection/utils/each-axis.mjs.map +1 -1
  46. package/dist/es/render/VisualElement.mjs +29 -59
  47. package/dist/es/render/VisualElement.mjs.map +1 -1
  48. package/dist/es/render/svg/SVGVisualElement.mjs +19 -1
  49. package/dist/es/render/svg/SVGVisualElement.mjs.map +1 -1
  50. package/dist/es/render/utils/animation-state.mjs +144 -267
  51. package/dist/es/render/utils/animation-state.mjs.map +1 -1
  52. package/dist/es/render/utils/resolve-dynamic-variants.mjs +7 -3
  53. package/dist/es/render/utils/resolve-dynamic-variants.mjs.map +1 -1
  54. package/dist/es/render/utils/resolve-variants.mjs +8 -19
  55. package/dist/es/render/utils/resolve-variants.mjs.map +1 -1
  56. package/dist/es/scroll/observe.mjs +4 -0
  57. package/dist/es/scroll/observe.mjs.map +1 -1
  58. package/dist/es/value/follow-value.mjs +8 -85
  59. package/dist/es/value/follow-value.mjs.map +1 -1
  60. package/dist/es/value/spring-value.mjs +8 -3
  61. package/dist/es/value/spring-value.mjs.map +1 -1
  62. package/dist/es/value/utils/as-number.mjs +4 -0
  63. package/dist/es/value/utils/as-number.mjs.map +1 -0
  64. package/dist/es/value/utils/follow.mjs +94 -0
  65. package/dist/es/value/utils/follow.mjs.map +1 -0
  66. package/dist/index.d.ts +55 -30
  67. package/dist/motion-dom.dev.js +698 -790
  68. package/dist/motion-dom.js +1 -1
  69. package/dist/size-rollup-motion-value.js +1 -1
  70. package/dist/size-rollup-motion-value.js.map +1 -1
  71. package/dist/size-rollup-style-effect.js +1 -1
  72. package/dist/size-rollup-style-effect.js.map +1 -1
  73. package/package.json +6 -5
@@ -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 { getVariantContext } from './get-variant-context.mjs';
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
- const numAnimationTypes = variantPriorityOrder.length;
13
- function createAnimateFunction(visualElement) {
14
- return (animations) => {
15
- return Promise.all(animations.map(({ animation, options }) => animateVisualElement(visualElement, animation, options)));
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 = createAnimateFunction(visualElement);
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
- * Track whether the animation state has been reset (e.g. via StrictMode
24
- * double-invocation or Suspense unmount/remount). On the first
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 context = getVariantContext(visualElement.parent) || {};
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
- * Keep track of which values have been removed. Then, as we hit lower priority
71
- * animation types, we can check if they contain removed values and animate to that.
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
- * A dictionary of all encountered keys. This is an object to let us build into and
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
- * If a variant has been removed at a given index, and this component is controlling
82
- * variant animations, we want to ensure lower-priority variants are forced to animate.
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
- * Iterate through all animation types in reverse priority order. For each, we want to
87
- * detect which values it's handling and whether or not they've changed (and therefore
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
- for (let i = 0; i < numAnimationTypes; i++) {
92
- const type = reversePriorityOrder[i];
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 prop = props[type] !== undefined
95
- ? props[type]
96
- : context[type];
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
- * If this prop is an inherited variant, rather than been set directly on the
107
- * component itself, we want to make sure we allow the parent to trigger animations.
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
- // Check if we can skip analysing this prop early
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
- continue;
81
+ return;
134
82
  }
135
83
  /**
136
- * If exit is already active and wasn't just activated, skip
137
- * re-processing to prevent interrupting running exit animations.
138
- * Re-resolving exit with a changed custom value can start new
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
- if (typeState.prevResolvedValues) {
144
- encounteredKeys = {
145
- ...encounteredKeys,
146
- ...typeState.prevResolvedValues,
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
- // If we're making this variant active, we want to always make it active
159
- (type === changedActiveType &&
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
- * Build an object of all the resolved values. We'll use this in the subsequent
173
- * animateChanges calls to determine whether a value has changed.
174
- */
175
- let resolvedValues = definitionList.reduce(buildResolvedTypeValues(type), {});
176
- if (activeDelta === false)
177
- resolvedValues = {};
178
- /**
179
- * Now we need to loop through all the keys in the prev prop and this prop,
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
- typeState.needsAnimating[key] = true;
199
- const motionValue = visualElement.getValue(key);
200
- if (motionValue)
201
- motionValue.liveStyle = false;
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
- * If the value has changed, we probably want to animate it.
119
+ * Keyframes compare by value, but replay whenever the
120
+ * variant label changed.
211
121
  */
212
- let valueHasChanged = false;
213
- if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
214
- valueHasChanged =
215
- !shallowCompare(next, prev) || variantDidChange;
216
- }
217
- else {
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
- if (next !== undefined && next !== null) {
222
- // If next is defined and doesn't equal prev, it needs animating
223
- markToAnimate(key);
224
- }
225
- else {
226
- // If it's undefined, it's been removed.
227
- removedKeys.add(key);
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 ((isInitialRender || wasReset) &&
255
- visualElement.blockInitialAnimation) {
256
- shouldAnimateType = false;
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
- * If we're performing the initial animation, but we're not
269
- * rendering at the same time as the variant-controlling parent,
270
- * we want to use the parent's transition to calculate the stagger.
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
- (isInitialRender || wasReset) &&
274
- !willAnimateViaParent &&
275
- visualElement.manuallyAnimateOnMount &&
276
- visualElement.parent) {
277
- const { parent } = visualElement;
278
- const parentVariant = resolveVariant(parent, animation);
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
- return {
285
- animation: animation,
286
- options,
287
- };
288
- }));
165
+ animations.push({ animation, options });
166
+ }
289
167
  }
290
- }
168
+ });
291
169
  /**
292
- * If there are some removed value that haven't been dealt with,
293
- * we need to create a new animation that falls back either to the value
294
- * defined in the style prop, or the last read value.
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
- * If the initial prop contains a transition we can use that, otherwise
300
- * allow the animation function to use the visual element's default.
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
- // @ts-expect-error - @mattgperry to figure if we should do something here
316
- fallbackAnimation[key] = fallbackTarget ?? null;
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
- let shouldAnimate = Boolean(animations.length);
321
- if (isInitialRender &&
322
- (props.initial === false || props.initial === props.animate) &&
323
- !visualElement.manuallyAnimateOnMount) {
324
- shouldAnimate = false;
325
- }
326
- isInitialRender = false;
327
- wasReset = false;
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
- setAnimateFunction,
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
- return {
376
- animate: createTypeState(true),
377
- whileInView: createTypeState(),
378
- whileHover: createTypeState(),
379
- whileTap: createTypeState(),
380
- whileDrag: createTypeState(),
381
- whileFocus: createTypeState(),
382
- exit: createTypeState(),
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 };