motion-dom 12.24.11 → 12.26.2

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 (77) hide show
  1. package/dist/cjs/index.js +6197 -1833
  2. package/dist/es/animation/animate/single-value.mjs +11 -0
  3. package/dist/es/animation/interfaces/motion-value.mjs +102 -0
  4. package/dist/es/animation/interfaces/visual-element-target.mjs +85 -0
  5. package/dist/es/animation/interfaces/visual-element-variant.mjs +59 -0
  6. package/dist/es/animation/interfaces/visual-element.mjs +26 -0
  7. package/dist/es/animation/optimized-appear/data-id.mjs +6 -0
  8. package/dist/es/animation/optimized-appear/get-appear-id.mjs +7 -0
  9. package/dist/es/animation/utils/calc-child-stagger.mjs +15 -0
  10. package/dist/es/animation/utils/default-transitions.mjs +40 -0
  11. package/dist/es/animation/utils/get-final-keyframe.mjs +12 -0
  12. package/dist/es/animation/utils/is-transition-defined.mjs +10 -0
  13. package/dist/es/events/add-dom-event.mjs +6 -0
  14. package/dist/es/index.mjs +71 -0
  15. package/dist/es/projection/animation/mix-values.mjs +66 -0
  16. package/dist/es/projection/geometry/conversion.mjs +33 -0
  17. package/dist/es/projection/geometry/copy.mjs +31 -0
  18. package/dist/es/projection/geometry/delta-apply.mjs +119 -0
  19. package/dist/es/projection/geometry/delta-calc.mjs +52 -0
  20. package/dist/es/projection/geometry/delta-remove.mjs +54 -0
  21. package/dist/es/projection/geometry/models.mjs +17 -0
  22. package/dist/es/projection/geometry/utils.mjs +31 -0
  23. package/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
  24. package/dist/es/projection/node/HTMLProjectionNode.mjs +27 -0
  25. package/dist/es/projection/node/create-projection-node.mjs +1628 -0
  26. package/dist/es/projection/node/group.mjs +24 -0
  27. package/dist/es/projection/node/state.mjs +19 -0
  28. package/dist/es/projection/shared/stack.mjs +100 -0
  29. package/dist/es/projection/styles/scale-border-radius.mjs +41 -0
  30. package/dist/es/projection/styles/scale-box-shadow.mjs +35 -0
  31. package/dist/es/projection/styles/scale-correction.mjs +30 -0
  32. package/dist/es/projection/styles/transform.mjs +49 -0
  33. package/dist/es/projection/utils/compare-by-depth.mjs +3 -0
  34. package/dist/es/projection/utils/each-axis.mjs +5 -0
  35. package/dist/es/projection/utils/flat-tree.mjs +24 -0
  36. package/dist/es/projection/utils/has-transform.mjs +26 -0
  37. package/dist/es/projection/utils/measure.mjs +17 -0
  38. package/dist/es/render/Feature.mjs +14 -0
  39. package/dist/es/render/VisualElement.mjs +510 -0
  40. package/dist/es/render/dom/DOMVisualElement.mjs +42 -0
  41. package/dist/es/render/html/HTMLVisualElement.mjs +44 -0
  42. package/dist/es/render/html/utils/build-styles.mjs +65 -0
  43. package/dist/es/render/html/utils/build-transform.mjs +62 -0
  44. package/dist/es/render/html/utils/render.mjs +17 -0
  45. package/dist/es/render/html/utils/scrape-motion-values.mjs +21 -0
  46. package/dist/es/render/object/ObjectVisualElement.mjs +41 -0
  47. package/dist/es/render/store.mjs +3 -0
  48. package/dist/es/render/svg/SVGVisualElement.mjs +45 -0
  49. package/dist/es/render/svg/utils/build-attrs.mjs +72 -0
  50. package/dist/es/render/svg/utils/camel-case-attrs.mjs +30 -0
  51. package/dist/es/render/svg/utils/is-svg-tag.mjs +3 -0
  52. package/dist/es/render/svg/utils/path.mjs +32 -0
  53. package/dist/es/render/svg/utils/render.mjs +12 -0
  54. package/dist/es/render/svg/utils/scrape-motion-values.mjs +19 -0
  55. package/dist/es/render/utils/animation-state.mjs +364 -0
  56. package/dist/es/render/utils/get-variant-context.mjs +32 -0
  57. package/dist/es/render/utils/is-animation-controls.mjs +7 -0
  58. package/dist/es/render/utils/is-controlling-variants.mjs +13 -0
  59. package/dist/es/render/utils/is-forced-motion-value.mjs +12 -0
  60. package/dist/es/render/utils/is-keyframes-target.mjs +5 -0
  61. package/dist/es/render/utils/is-variant-label.mjs +8 -0
  62. package/dist/es/render/utils/motion-values.mjs +55 -0
  63. package/dist/es/render/utils/reduced-motion/index.mjs +19 -0
  64. package/dist/es/render/utils/reduced-motion/state.mjs +5 -0
  65. package/dist/es/render/utils/resolve-dynamic-variants.mjs +8 -0
  66. package/dist/es/render/utils/resolve-variants.mjs +36 -0
  67. package/dist/es/render/utils/setters.mjs +31 -0
  68. package/dist/es/render/utils/shallow-compare.mjs +14 -0
  69. package/dist/es/render/utils/variant-props.mjs +12 -0
  70. package/dist/es/utils/delay.mjs +24 -0
  71. package/dist/es/value/utils/resolve-motion-value.mjs +10 -0
  72. package/dist/es/value/will-change/add-will-change.mjs +20 -0
  73. package/dist/es/value/will-change/is.mjs +7 -0
  74. package/dist/index.d.ts +3853 -2136
  75. package/dist/motion-dom.dev.js +6197 -1833
  76. package/dist/motion-dom.js +1 -1
  77. package/package.json +2 -2
@@ -0,0 +1,1628 @@
1
+ import { activeAnimations } from '../../stats/animation-count.mjs';
2
+ import { getValueTransition } from '../../animation/utils/get-value-transition.mjs';
3
+ import { microtask } from '../../frameloop/microtask.mjs';
4
+ import { time } from '../../frameloop/sync-time.mjs';
5
+ import { translateAxis, transformBox, applyBoxDelta, applyTreeDeltas } from '../geometry/delta-apply.mjs';
6
+ import { calcLength, calcRelativeBox, calcRelativePosition, calcBoxDelta, isNear } from '../geometry/delta-calc.mjs';
7
+ import { removeBoxTransforms } from '../geometry/delta-remove.mjs';
8
+ import { copyBoxInto, copyAxisDeltaInto } from '../geometry/copy.mjs';
9
+ import { createBox, createDelta } from '../geometry/models.mjs';
10
+ import { boxEqualsRounded, isDeltaZero, axisDeltaEquals, aspectRatio, boxEquals } from '../geometry/utils.mjs';
11
+ import { buildProjectionTransform } from '../styles/transform.mjs';
12
+ import { eachAxis } from '../utils/each-axis.mjs';
13
+ import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
14
+ import { mixValues } from '../animation/mix-values.mjs';
15
+ import { isSVGElement } from '../../utils/is-svg-element.mjs';
16
+ import { isSVGSVGElement } from '../../utils/is-svg-svg-element.mjs';
17
+ import { mixNumber } from '../../utils/mix/number.mjs';
18
+ import { motionValue } from '../../value/index.mjs';
19
+ import { scaleCorrectors } from '../styles/scale-correction.mjs';
20
+ import { statsBuffer } from '../../stats/buffer.mjs';
21
+ import { SubscriptionManager, clamp, noop } from 'motion-utils';
22
+ import { animateSingleValue } from '../../animation/animate/single-value.mjs';
23
+ import { getOptimisedAppearId } from '../../animation/optimized-appear/get-appear-id.mjs';
24
+ import { FlatTree } from '../utils/flat-tree.mjs';
25
+ import { delay } from '../../utils/delay.mjs';
26
+ import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
27
+ import { NodeStack } from '../shared/stack.mjs';
28
+ import { globalProjectionState } from './state.mjs';
29
+ import { frame, cancelFrame, frameData, frameSteps } from '../../frameloop/frame.mjs';
30
+
31
+ const metrics = {
32
+ nodes: 0,
33
+ calculatedTargetDeltas: 0,
34
+ calculatedProjections: 0,
35
+ };
36
+ const transformAxes = ["", "X", "Y", "Z"];
37
+ /**
38
+ * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
39
+ * which has a noticeable difference in spring animations
40
+ */
41
+ const animationTarget = 1000;
42
+ let id = 0;
43
+ function resetDistortingTransform(key, visualElement, values, sharedAnimationValues) {
44
+ const { latestValues } = visualElement;
45
+ // Record the distorting transform and then temporarily set it to 0
46
+ if (latestValues[key]) {
47
+ values[key] = latestValues[key];
48
+ visualElement.setStaticValue(key, 0);
49
+ if (sharedAnimationValues) {
50
+ sharedAnimationValues[key] = 0;
51
+ }
52
+ }
53
+ }
54
+ function cancelTreeOptimisedTransformAnimations(projectionNode) {
55
+ projectionNode.hasCheckedOptimisedAppear = true;
56
+ if (projectionNode.root === projectionNode)
57
+ return;
58
+ const { visualElement } = projectionNode.options;
59
+ if (!visualElement)
60
+ return;
61
+ const appearId = getOptimisedAppearId(visualElement);
62
+ if (window.MotionHasOptimisedAnimation(appearId, "transform")) {
63
+ const { layout, layoutId } = projectionNode.options;
64
+ window.MotionCancelOptimisedAnimation(appearId, "transform", frame, !(layout || layoutId));
65
+ }
66
+ const { parent } = projectionNode;
67
+ if (parent && !parent.hasCheckedOptimisedAppear) {
68
+ cancelTreeOptimisedTransformAnimations(parent);
69
+ }
70
+ }
71
+ function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
72
+ return class ProjectionNode {
73
+ constructor(latestValues = {}, parent = defaultParent?.()) {
74
+ /**
75
+ * A unique ID generated for every projection node.
76
+ */
77
+ this.id = id++;
78
+ /**
79
+ * An id that represents a unique session instigated by startUpdate.
80
+ */
81
+ this.animationId = 0;
82
+ this.animationCommitId = 0;
83
+ /**
84
+ * A Set containing all this component's children. This is used to iterate
85
+ * through the children.
86
+ *
87
+ * TODO: This could be faster to iterate as a flat array stored on the root node.
88
+ */
89
+ this.children = new Set();
90
+ /**
91
+ * Options for the node. We use this to configure what kind of layout animations
92
+ * we should perform (if any).
93
+ */
94
+ this.options = {};
95
+ /**
96
+ * We use this to detect when its safe to shut down part of a projection tree.
97
+ * We have to keep projecting children for scale correction and relative projection
98
+ * until all their parents stop performing layout animations.
99
+ */
100
+ this.isTreeAnimating = false;
101
+ this.isAnimationBlocked = false;
102
+ /**
103
+ * Flag to true if we think this layout has been changed. We can't always know this,
104
+ * currently we set it to true every time a component renders, or if it has a layoutDependency
105
+ * if that has changed between renders. Additionally, components can be grouped by LayoutGroup
106
+ * and if one node is dirtied, they all are.
107
+ */
108
+ this.isLayoutDirty = false;
109
+ /**
110
+ * Flag to true if we think the projection calculations for this node needs
111
+ * recalculating as a result of an updated transform or layout animation.
112
+ */
113
+ this.isProjectionDirty = false;
114
+ /**
115
+ * Flag to true if the layout *or* transform has changed. This then gets propagated
116
+ * throughout the projection tree, forcing any element below to recalculate on the next frame.
117
+ */
118
+ this.isSharedProjectionDirty = false;
119
+ /**
120
+ * Flag transform dirty. This gets propagated throughout the whole tree but is only
121
+ * respected by shared nodes.
122
+ */
123
+ this.isTransformDirty = false;
124
+ /**
125
+ * Block layout updates for instant layout transitions throughout the tree.
126
+ */
127
+ this.updateManuallyBlocked = false;
128
+ this.updateBlockedByResize = false;
129
+ /**
130
+ * Set to true between the start of the first `willUpdate` call and the end of the `didUpdate`
131
+ * call.
132
+ */
133
+ this.isUpdating = false;
134
+ /**
135
+ * If this is an SVG element we currently disable projection transforms
136
+ */
137
+ this.isSVG = false;
138
+ /**
139
+ * Flag to true (during promotion) if a node doing an instant layout transition needs to reset
140
+ * its projection styles.
141
+ */
142
+ this.needsReset = false;
143
+ /**
144
+ * Flags whether this node should have its transform reset prior to measuring.
145
+ */
146
+ this.shouldResetTransform = false;
147
+ /**
148
+ * Store whether this node has been checked for optimised appear animations. As
149
+ * effects fire bottom-up, and we want to look up the tree for appear animations,
150
+ * this makes sure we only check each path once, stopping at nodes that
151
+ * have already been checked.
152
+ */
153
+ this.hasCheckedOptimisedAppear = false;
154
+ /**
155
+ * An object representing the calculated contextual/accumulated/tree scale.
156
+ * This will be used to scale calculcated projection transforms, as these are
157
+ * calculated in screen-space but need to be scaled for elements to layoutly
158
+ * make it to their calculated destinations.
159
+ *
160
+ * TODO: Lazy-init
161
+ */
162
+ this.treeScale = { x: 1, y: 1 };
163
+ /**
164
+ *
165
+ */
166
+ this.eventHandlers = new Map();
167
+ this.hasTreeAnimated = false;
168
+ this.layoutVersion = 0;
169
+ // Note: Currently only running on root node
170
+ this.updateScheduled = false;
171
+ this.scheduleUpdate = () => this.update();
172
+ this.projectionUpdateScheduled = false;
173
+ this.checkUpdateFailed = () => {
174
+ if (this.isUpdating) {
175
+ this.isUpdating = false;
176
+ this.clearAllSnapshots();
177
+ }
178
+ };
179
+ /**
180
+ * This is a multi-step process as shared nodes might be of different depths. Nodes
181
+ * are sorted by depth order, so we need to resolve the entire tree before moving to
182
+ * the next step.
183
+ */
184
+ this.updateProjection = () => {
185
+ this.projectionUpdateScheduled = false;
186
+ /**
187
+ * Reset debug counts. Manually resetting rather than creating a new
188
+ * object each frame.
189
+ */
190
+ if (statsBuffer.value) {
191
+ metrics.nodes =
192
+ metrics.calculatedTargetDeltas =
193
+ metrics.calculatedProjections =
194
+ 0;
195
+ }
196
+ this.nodes.forEach(propagateDirtyNodes);
197
+ this.nodes.forEach(resolveTargetDelta);
198
+ this.nodes.forEach(calcProjection);
199
+ this.nodes.forEach(cleanDirtyNodes);
200
+ if (statsBuffer.addProjectionMetrics) {
201
+ statsBuffer.addProjectionMetrics(metrics);
202
+ }
203
+ };
204
+ /**
205
+ * Frame calculations
206
+ */
207
+ this.resolvedRelativeTargetAt = 0.0;
208
+ this.linkedParentVersion = 0;
209
+ this.hasProjected = false;
210
+ this.isVisible = true;
211
+ this.animationProgress = 0;
212
+ /**
213
+ * Shared layout
214
+ */
215
+ // TODO Only running on root node
216
+ this.sharedNodes = new Map();
217
+ this.latestValues = latestValues;
218
+ this.root = parent ? parent.root || parent : this;
219
+ this.path = parent ? [...parent.path, parent] : [];
220
+ this.parent = parent;
221
+ this.depth = parent ? parent.depth + 1 : 0;
222
+ for (let i = 0; i < this.path.length; i++) {
223
+ this.path[i].shouldResetTransform = true;
224
+ }
225
+ if (this.root === this)
226
+ this.nodes = new FlatTree();
227
+ }
228
+ addEventListener(name, handler) {
229
+ if (!this.eventHandlers.has(name)) {
230
+ this.eventHandlers.set(name, new SubscriptionManager());
231
+ }
232
+ return this.eventHandlers.get(name).add(handler);
233
+ }
234
+ notifyListeners(name, ...args) {
235
+ const subscriptionManager = this.eventHandlers.get(name);
236
+ subscriptionManager && subscriptionManager.notify(...args);
237
+ }
238
+ hasListeners(name) {
239
+ return this.eventHandlers.has(name);
240
+ }
241
+ /**
242
+ * Lifecycles
243
+ */
244
+ mount(instance) {
245
+ if (this.instance)
246
+ return;
247
+ this.isSVG = isSVGElement(instance) && !isSVGSVGElement(instance);
248
+ this.instance = instance;
249
+ const { layoutId, layout, visualElement } = this.options;
250
+ if (visualElement && !visualElement.current) {
251
+ visualElement.mount(instance);
252
+ }
253
+ this.root.nodes.add(this);
254
+ this.parent && this.parent.children.add(this);
255
+ if (this.root.hasTreeAnimated && (layout || layoutId)) {
256
+ this.isLayoutDirty = true;
257
+ }
258
+ if (attachResizeListener) {
259
+ let cancelDelay;
260
+ let innerWidth = 0;
261
+ const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
262
+ // Set initial innerWidth in a frame.read callback to batch the read
263
+ frame.read(() => {
264
+ innerWidth = window.innerWidth;
265
+ });
266
+ attachResizeListener(instance, () => {
267
+ const newInnerWidth = window.innerWidth;
268
+ if (newInnerWidth === innerWidth)
269
+ return;
270
+ innerWidth = newInnerWidth;
271
+ this.root.updateBlockedByResize = true;
272
+ cancelDelay && cancelDelay();
273
+ cancelDelay = delay(resizeUnblockUpdate, 250);
274
+ if (globalProjectionState.hasAnimatedSinceResize) {
275
+ globalProjectionState.hasAnimatedSinceResize = false;
276
+ this.nodes.forEach(finishAnimation);
277
+ }
278
+ });
279
+ }
280
+ if (layoutId) {
281
+ this.root.registerSharedNode(layoutId, this);
282
+ }
283
+ // Only register the handler if it requires layout animation
284
+ if (this.options.animate !== false &&
285
+ visualElement &&
286
+ (layoutId || layout)) {
287
+ this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeLayoutChanged, layout: newLayout, }) => {
288
+ if (this.isTreeAnimationBlocked()) {
289
+ this.target = undefined;
290
+ this.relativeTarget = undefined;
291
+ return;
292
+ }
293
+ // TODO: Check here if an animation exists
294
+ const layoutTransition = this.options.transition ||
295
+ visualElement.getDefaultTransition() ||
296
+ defaultLayoutTransition;
297
+ const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
298
+ /**
299
+ * The target layout of the element might stay the same,
300
+ * but its position relative to its parent has changed.
301
+ */
302
+ const hasTargetChanged = !this.targetLayout ||
303
+ !boxEqualsRounded(this.targetLayout, newLayout);
304
+ /*
305
+ * Note: Disabled to fix relative animations always triggering new
306
+ * layout animations. If this causes further issues, we can try
307
+ * a different approach to detecting relative target changes.
308
+ */
309
+ // || hasRelativeLayoutChanged
310
+ /**
311
+ * If the layout hasn't seemed to have changed, it might be that the
312
+ * element is visually in the same place in the document but its position
313
+ * relative to its parent has indeed changed. So here we check for that.
314
+ */
315
+ const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeLayoutChanged;
316
+ if (this.options.layoutRoot ||
317
+ this.resumeFrom ||
318
+ hasOnlyRelativeTargetChanged ||
319
+ (hasLayoutChanged &&
320
+ (hasTargetChanged || !this.currentAnimation))) {
321
+ if (this.resumeFrom) {
322
+ this.resumingFrom = this.resumeFrom;
323
+ this.resumingFrom.resumingFrom = undefined;
324
+ }
325
+ const animationOptions = {
326
+ ...getValueTransition(layoutTransition, "layout"),
327
+ onPlay: onLayoutAnimationStart,
328
+ onComplete: onLayoutAnimationComplete,
329
+ };
330
+ if (visualElement.shouldReduceMotion ||
331
+ this.options.layoutRoot) {
332
+ animationOptions.delay = 0;
333
+ animationOptions.type = false;
334
+ }
335
+ this.startAnimation(animationOptions);
336
+ /**
337
+ * Set animation origin after starting animation to avoid layout jump
338
+ * caused by stopping previous layout animation
339
+ */
340
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
341
+ }
342
+ else {
343
+ /**
344
+ * If the layout hasn't changed and we have an animation that hasn't started yet,
345
+ * finish it immediately. Otherwise it will be animating from a location
346
+ * that was probably never committed to screen and look like a jumpy box.
347
+ */
348
+ if (!hasLayoutChanged) {
349
+ finishAnimation(this);
350
+ }
351
+ if (this.isLead() && this.options.onExitComplete) {
352
+ this.options.onExitComplete();
353
+ }
354
+ }
355
+ this.targetLayout = newLayout;
356
+ });
357
+ }
358
+ }
359
+ unmount() {
360
+ this.options.layoutId && this.willUpdate();
361
+ this.root.nodes.remove(this);
362
+ const stack = this.getStack();
363
+ stack && stack.remove(this);
364
+ this.parent && this.parent.children.delete(this);
365
+ this.instance = undefined;
366
+ this.eventHandlers.clear();
367
+ cancelFrame(this.updateProjection);
368
+ }
369
+ // only on the root
370
+ blockUpdate() {
371
+ this.updateManuallyBlocked = true;
372
+ }
373
+ unblockUpdate() {
374
+ this.updateManuallyBlocked = false;
375
+ }
376
+ isUpdateBlocked() {
377
+ return this.updateManuallyBlocked || this.updateBlockedByResize;
378
+ }
379
+ isTreeAnimationBlocked() {
380
+ return (this.isAnimationBlocked ||
381
+ (this.parent && this.parent.isTreeAnimationBlocked()) ||
382
+ false);
383
+ }
384
+ // Note: currently only running on root node
385
+ startUpdate() {
386
+ if (this.isUpdateBlocked())
387
+ return;
388
+ this.isUpdating = true;
389
+ this.nodes && this.nodes.forEach(resetSkewAndRotation);
390
+ this.animationId++;
391
+ }
392
+ getTransformTemplate() {
393
+ const { visualElement } = this.options;
394
+ return visualElement && visualElement.getProps().transformTemplate;
395
+ }
396
+ willUpdate(shouldNotifyListeners = true) {
397
+ this.root.hasTreeAnimated = true;
398
+ if (this.root.isUpdateBlocked()) {
399
+ this.options.onExitComplete && this.options.onExitComplete();
400
+ return;
401
+ }
402
+ /**
403
+ * If we're running optimised appear animations then these must be
404
+ * cancelled before measuring the DOM. This is so we can measure
405
+ * the true layout of the element rather than the WAAPI animation
406
+ * which will be unaffected by the resetSkewAndRotate step.
407
+ *
408
+ * Note: This is a DOM write. Worst case scenario is this is sandwiched
409
+ * between other snapshot reads which will cause unnecessary style recalculations.
410
+ * This has to happen here though, as we don't yet know which nodes will need
411
+ * snapshots in startUpdate(), but we only want to cancel optimised animations
412
+ * if a layout animation measurement is actually going to be affected by them.
413
+ */
414
+ if (window.MotionCancelOptimisedAnimation &&
415
+ !this.hasCheckedOptimisedAppear) {
416
+ cancelTreeOptimisedTransformAnimations(this);
417
+ }
418
+ !this.root.isUpdating && this.root.startUpdate();
419
+ if (this.isLayoutDirty)
420
+ return;
421
+ this.isLayoutDirty = true;
422
+ for (let i = 0; i < this.path.length; i++) {
423
+ const node = this.path[i];
424
+ node.shouldResetTransform = true;
425
+ node.updateScroll("snapshot");
426
+ if (node.options.layoutRoot) {
427
+ node.willUpdate(false);
428
+ }
429
+ }
430
+ const { layoutId, layout } = this.options;
431
+ if (layoutId === undefined && !layout)
432
+ return;
433
+ const transformTemplate = this.getTransformTemplate();
434
+ this.prevTransformTemplateValue = transformTemplate
435
+ ? transformTemplate(this.latestValues, "")
436
+ : undefined;
437
+ this.updateSnapshot();
438
+ shouldNotifyListeners && this.notifyListeners("willUpdate");
439
+ }
440
+ update() {
441
+ this.updateScheduled = false;
442
+ const updateWasBlocked = this.isUpdateBlocked();
443
+ // When doing an instant transition, we skip the layout update,
444
+ // but should still clean up the measurements so that the next
445
+ // snapshot could be taken correctly.
446
+ if (updateWasBlocked) {
447
+ this.unblockUpdate();
448
+ this.clearAllSnapshots();
449
+ this.nodes.forEach(clearMeasurements);
450
+ return;
451
+ }
452
+ /**
453
+ * If this is a repeat of didUpdate then ignore the animation.
454
+ */
455
+ if (this.animationId <= this.animationCommitId) {
456
+ this.nodes.forEach(clearIsLayoutDirty);
457
+ return;
458
+ }
459
+ this.animationCommitId = this.animationId;
460
+ if (!this.isUpdating) {
461
+ this.nodes.forEach(clearIsLayoutDirty);
462
+ }
463
+ else {
464
+ this.isUpdating = false;
465
+ /**
466
+ * Write
467
+ */
468
+ this.nodes.forEach(resetTransformStyle);
469
+ /**
470
+ * Read ==================
471
+ */
472
+ // Update layout measurements of updated children
473
+ this.nodes.forEach(updateLayout);
474
+ /**
475
+ * Write
476
+ */
477
+ // Notify listeners that the layout is updated
478
+ this.nodes.forEach(notifyLayoutUpdate);
479
+ }
480
+ this.clearAllSnapshots();
481
+ /**
482
+ * Manually flush any pending updates. Ideally
483
+ * we could leave this to the following requestAnimationFrame but this seems
484
+ * to leave a flash of incorrectly styled content.
485
+ */
486
+ const now = time.now();
487
+ frameData.delta = clamp(0, 1000 / 60, now - frameData.timestamp);
488
+ frameData.timestamp = now;
489
+ frameData.isProcessing = true;
490
+ frameSteps.update.process(frameData);
491
+ frameSteps.preRender.process(frameData);
492
+ frameSteps.render.process(frameData);
493
+ frameData.isProcessing = false;
494
+ }
495
+ didUpdate() {
496
+ if (!this.updateScheduled) {
497
+ this.updateScheduled = true;
498
+ microtask.read(this.scheduleUpdate);
499
+ }
500
+ }
501
+ clearAllSnapshots() {
502
+ this.nodes.forEach(clearSnapshot);
503
+ this.sharedNodes.forEach(removeLeadSnapshots);
504
+ }
505
+ scheduleUpdateProjection() {
506
+ if (!this.projectionUpdateScheduled) {
507
+ this.projectionUpdateScheduled = true;
508
+ frame.preRender(this.updateProjection, false, true);
509
+ }
510
+ }
511
+ scheduleCheckAfterUnmount() {
512
+ /**
513
+ * If the unmounting node is in a layoutGroup and did trigger a willUpdate,
514
+ * we manually call didUpdate to give a chance to the siblings to animate.
515
+ * Otherwise, cleanup all snapshots to prevents future nodes from reusing them.
516
+ */
517
+ frame.postRender(() => {
518
+ if (this.isLayoutDirty) {
519
+ this.root.didUpdate();
520
+ }
521
+ else {
522
+ this.root.checkUpdateFailed();
523
+ }
524
+ });
525
+ }
526
+ /**
527
+ * Update measurements
528
+ */
529
+ updateSnapshot() {
530
+ if (this.snapshot || !this.instance)
531
+ return;
532
+ this.snapshot = this.measure();
533
+ if (this.snapshot &&
534
+ !calcLength(this.snapshot.measuredBox.x) &&
535
+ !calcLength(this.snapshot.measuredBox.y)) {
536
+ this.snapshot = undefined;
537
+ }
538
+ }
539
+ updateLayout() {
540
+ if (!this.instance)
541
+ return;
542
+ this.updateScroll();
543
+ if (!(this.options.alwaysMeasureLayout && this.isLead()) &&
544
+ !this.isLayoutDirty) {
545
+ return;
546
+ }
547
+ /**
548
+ * When a node is mounted, it simply resumes from the prevLead's
549
+ * snapshot instead of taking a new one, but the ancestors scroll
550
+ * might have updated while the prevLead is unmounted. We need to
551
+ * update the scroll again to make sure the layout we measure is
552
+ * up to date.
553
+ */
554
+ if (this.resumeFrom && !this.resumeFrom.instance) {
555
+ for (let i = 0; i < this.path.length; i++) {
556
+ const node = this.path[i];
557
+ node.updateScroll();
558
+ }
559
+ }
560
+ const prevLayout = this.layout;
561
+ this.layout = this.measure(false);
562
+ this.layoutVersion++;
563
+ this.layoutCorrected = createBox();
564
+ this.isLayoutDirty = false;
565
+ this.projectionDelta = undefined;
566
+ this.notifyListeners("measure", this.layout.layoutBox);
567
+ const { visualElement } = this.options;
568
+ visualElement &&
569
+ visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
570
+ }
571
+ updateScroll(phase = "measure") {
572
+ let needsMeasurement = Boolean(this.options.layoutScroll && this.instance);
573
+ if (this.scroll &&
574
+ this.scroll.animationId === this.root.animationId &&
575
+ this.scroll.phase === phase) {
576
+ needsMeasurement = false;
577
+ }
578
+ if (needsMeasurement && this.instance) {
579
+ const isRoot = checkIsScrollRoot(this.instance);
580
+ this.scroll = {
581
+ animationId: this.root.animationId,
582
+ phase,
583
+ isRoot,
584
+ offset: measureScroll(this.instance),
585
+ wasRoot: this.scroll ? this.scroll.isRoot : isRoot,
586
+ };
587
+ }
588
+ }
589
+ resetTransform() {
590
+ if (!resetTransform)
591
+ return;
592
+ const isResetRequested = this.isLayoutDirty ||
593
+ this.shouldResetTransform ||
594
+ this.options.alwaysMeasureLayout;
595
+ const hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
596
+ const transformTemplate = this.getTransformTemplate();
597
+ const transformTemplateValue = transformTemplate
598
+ ? transformTemplate(this.latestValues, "")
599
+ : undefined;
600
+ const transformTemplateHasChanged = transformTemplateValue !== this.prevTransformTemplateValue;
601
+ if (isResetRequested &&
602
+ this.instance &&
603
+ (hasProjection ||
604
+ hasTransform(this.latestValues) ||
605
+ transformTemplateHasChanged)) {
606
+ resetTransform(this.instance, transformTemplateValue);
607
+ this.shouldResetTransform = false;
608
+ this.scheduleRender();
609
+ }
610
+ }
611
+ measure(removeTransform = true) {
612
+ const pageBox = this.measurePageBox();
613
+ let layoutBox = this.removeElementScroll(pageBox);
614
+ /**
615
+ * Measurements taken during the pre-render stage
616
+ * still have transforms applied so we remove them
617
+ * via calculation.
618
+ */
619
+ if (removeTransform) {
620
+ layoutBox = this.removeTransform(layoutBox);
621
+ }
622
+ roundBox(layoutBox);
623
+ return {
624
+ animationId: this.root.animationId,
625
+ measuredBox: pageBox,
626
+ layoutBox,
627
+ latestValues: {},
628
+ source: this.id,
629
+ };
630
+ }
631
+ measurePageBox() {
632
+ const { visualElement } = this.options;
633
+ if (!visualElement)
634
+ return createBox();
635
+ const box = visualElement.measureViewportBox();
636
+ const wasInScrollRoot = this.scroll?.wasRoot || this.path.some(checkNodeWasScrollRoot);
637
+ if (!wasInScrollRoot) {
638
+ // Remove viewport scroll to give page-relative coordinates
639
+ const { scroll } = this.root;
640
+ if (scroll) {
641
+ translateAxis(box.x, scroll.offset.x);
642
+ translateAxis(box.y, scroll.offset.y);
643
+ }
644
+ }
645
+ return box;
646
+ }
647
+ removeElementScroll(box) {
648
+ const boxWithoutScroll = createBox();
649
+ copyBoxInto(boxWithoutScroll, box);
650
+ if (this.scroll?.wasRoot) {
651
+ return boxWithoutScroll;
652
+ }
653
+ /**
654
+ * Performance TODO: Keep a cumulative scroll offset down the tree
655
+ * rather than loop back up the path.
656
+ */
657
+ for (let i = 0; i < this.path.length; i++) {
658
+ const node = this.path[i];
659
+ const { scroll, options } = node;
660
+ if (node !== this.root && scroll && options.layoutScroll) {
661
+ /**
662
+ * If this is a new scroll root, we want to remove all previous scrolls
663
+ * from the viewport box.
664
+ */
665
+ if (scroll.wasRoot) {
666
+ copyBoxInto(boxWithoutScroll, box);
667
+ }
668
+ translateAxis(boxWithoutScroll.x, scroll.offset.x);
669
+ translateAxis(boxWithoutScroll.y, scroll.offset.y);
670
+ }
671
+ }
672
+ return boxWithoutScroll;
673
+ }
674
+ applyTransform(box, transformOnly = false) {
675
+ const withTransforms = createBox();
676
+ copyBoxInto(withTransforms, box);
677
+ for (let i = 0; i < this.path.length; i++) {
678
+ const node = this.path[i];
679
+ if (!transformOnly &&
680
+ node.options.layoutScroll &&
681
+ node.scroll &&
682
+ node !== node.root) {
683
+ transformBox(withTransforms, {
684
+ x: -node.scroll.offset.x,
685
+ y: -node.scroll.offset.y,
686
+ });
687
+ }
688
+ if (!hasTransform(node.latestValues))
689
+ continue;
690
+ transformBox(withTransforms, node.latestValues);
691
+ }
692
+ if (hasTransform(this.latestValues)) {
693
+ transformBox(withTransforms, this.latestValues);
694
+ }
695
+ return withTransforms;
696
+ }
697
+ removeTransform(box) {
698
+ const boxWithoutTransform = createBox();
699
+ copyBoxInto(boxWithoutTransform, box);
700
+ for (let i = 0; i < this.path.length; i++) {
701
+ const node = this.path[i];
702
+ if (!node.instance)
703
+ continue;
704
+ if (!hasTransform(node.latestValues))
705
+ continue;
706
+ hasScale(node.latestValues) && node.updateSnapshot();
707
+ const sourceBox = createBox();
708
+ const nodeBox = node.measurePageBox();
709
+ copyBoxInto(sourceBox, nodeBox);
710
+ removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot ? node.snapshot.layoutBox : undefined, sourceBox);
711
+ }
712
+ if (hasTransform(this.latestValues)) {
713
+ removeBoxTransforms(boxWithoutTransform, this.latestValues);
714
+ }
715
+ return boxWithoutTransform;
716
+ }
717
+ setTargetDelta(delta) {
718
+ this.targetDelta = delta;
719
+ this.root.scheduleUpdateProjection();
720
+ this.isProjectionDirty = true;
721
+ }
722
+ setOptions(options) {
723
+ this.options = {
724
+ ...this.options,
725
+ ...options,
726
+ crossfade: options.crossfade !== undefined ? options.crossfade : true,
727
+ };
728
+ }
729
+ clearMeasurements() {
730
+ this.scroll = undefined;
731
+ this.layout = undefined;
732
+ this.snapshot = undefined;
733
+ this.prevTransformTemplateValue = undefined;
734
+ this.targetDelta = undefined;
735
+ this.target = undefined;
736
+ this.isLayoutDirty = false;
737
+ }
738
+ forceRelativeParentToResolveTarget() {
739
+ if (!this.relativeParent)
740
+ return;
741
+ /**
742
+ * If the parent target isn't up-to-date, force it to update.
743
+ * This is an unfortunate de-optimisation as it means any updating relative
744
+ * projection will cause all the relative parents to recalculate back
745
+ * up the tree.
746
+ */
747
+ if (this.relativeParent.resolvedRelativeTargetAt !==
748
+ frameData.timestamp) {
749
+ this.relativeParent.resolveTargetDelta(true);
750
+ }
751
+ }
752
+ resolveTargetDelta(forceRecalculation = false) {
753
+ /**
754
+ * Once the dirty status of nodes has been spread through the tree, we also
755
+ * need to check if we have a shared node of a different depth that has itself
756
+ * been dirtied.
757
+ */
758
+ const lead = this.getLead();
759
+ this.isProjectionDirty || (this.isProjectionDirty = lead.isProjectionDirty);
760
+ this.isTransformDirty || (this.isTransformDirty = lead.isTransformDirty);
761
+ this.isSharedProjectionDirty || (this.isSharedProjectionDirty = lead.isSharedProjectionDirty);
762
+ const isShared = Boolean(this.resumingFrom) || this !== lead;
763
+ /**
764
+ * We don't use transform for this step of processing so we don't
765
+ * need to check whether any nodes have changed transform.
766
+ */
767
+ const canSkip = !(forceRecalculation ||
768
+ (isShared && this.isSharedProjectionDirty) ||
769
+ this.isProjectionDirty ||
770
+ this.parent?.isProjectionDirty ||
771
+ this.attemptToResolveRelativeTarget ||
772
+ this.root.updateBlockedByResize);
773
+ if (canSkip)
774
+ return;
775
+ const { layout, layoutId } = this.options;
776
+ /**
777
+ * If we have no layout, we can't perform projection, so early return
778
+ */
779
+ if (!this.layout || !(layout || layoutId))
780
+ return;
781
+ this.resolvedRelativeTargetAt = frameData.timestamp;
782
+ const relativeParent = this.getClosestProjectingParent();
783
+ if (relativeParent &&
784
+ this.linkedParentVersion !== relativeParent.layoutVersion &&
785
+ !relativeParent.options.layoutRoot) {
786
+ this.removeRelativeTarget();
787
+ }
788
+ /**
789
+ * If we don't have a targetDelta but do have a layout, we can attempt to resolve
790
+ * a relativeParent. This will allow a component to perform scale correction
791
+ * even if no animation has started.
792
+ */
793
+ if (!this.targetDelta && !this.relativeTarget) {
794
+ if (relativeParent && relativeParent.layout) {
795
+ this.createRelativeTarget(relativeParent, this.layout.layoutBox, relativeParent.layout.layoutBox);
796
+ }
797
+ else {
798
+ this.removeRelativeTarget();
799
+ }
800
+ }
801
+ /**
802
+ * If we have no relative target or no target delta our target isn't valid
803
+ * for this frame.
804
+ */
805
+ if (!this.relativeTarget && !this.targetDelta)
806
+ return;
807
+ /**
808
+ * Lazy-init target data structure
809
+ */
810
+ if (!this.target) {
811
+ this.target = createBox();
812
+ this.targetWithTransforms = createBox();
813
+ }
814
+ /**
815
+ * If we've got a relative box for this component, resolve it into a target relative to the parent.
816
+ */
817
+ if (this.relativeTarget &&
818
+ this.relativeTargetOrigin &&
819
+ this.relativeParent &&
820
+ this.relativeParent.target) {
821
+ this.forceRelativeParentToResolveTarget();
822
+ calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target);
823
+ /**
824
+ * If we've only got a targetDelta, resolve it into a target
825
+ */
826
+ }
827
+ else if (this.targetDelta) {
828
+ if (Boolean(this.resumingFrom)) {
829
+ // TODO: This is creating a new object every frame
830
+ this.target = this.applyTransform(this.layout.layoutBox);
831
+ }
832
+ else {
833
+ copyBoxInto(this.target, this.layout.layoutBox);
834
+ }
835
+ applyBoxDelta(this.target, this.targetDelta);
836
+ }
837
+ else {
838
+ /**
839
+ * If no target, use own layout as target
840
+ */
841
+ copyBoxInto(this.target, this.layout.layoutBox);
842
+ }
843
+ /**
844
+ * If we've been told to attempt to resolve a relative target, do so.
845
+ */
846
+ if (this.attemptToResolveRelativeTarget) {
847
+ this.attemptToResolveRelativeTarget = false;
848
+ if (relativeParent &&
849
+ Boolean(relativeParent.resumingFrom) ===
850
+ Boolean(this.resumingFrom) &&
851
+ !relativeParent.options.layoutScroll &&
852
+ relativeParent.target &&
853
+ this.animationProgress !== 1) {
854
+ this.createRelativeTarget(relativeParent, this.target, relativeParent.target);
855
+ }
856
+ else {
857
+ this.relativeParent = this.relativeTarget = undefined;
858
+ }
859
+ }
860
+ /**
861
+ * Increase debug counter for resolved target deltas
862
+ */
863
+ if (statsBuffer.value) {
864
+ metrics.calculatedTargetDeltas++;
865
+ }
866
+ }
867
+ getClosestProjectingParent() {
868
+ if (!this.parent ||
869
+ hasScale(this.parent.latestValues) ||
870
+ has2DTranslate(this.parent.latestValues)) {
871
+ return undefined;
872
+ }
873
+ if (this.parent.isProjecting()) {
874
+ return this.parent;
875
+ }
876
+ else {
877
+ return this.parent.getClosestProjectingParent();
878
+ }
879
+ }
880
+ isProjecting() {
881
+ return Boolean((this.relativeTarget ||
882
+ this.targetDelta ||
883
+ this.options.layoutRoot) &&
884
+ this.layout);
885
+ }
886
+ createRelativeTarget(relativeParent, layout, parentLayout) {
887
+ this.relativeParent = relativeParent;
888
+ this.linkedParentVersion = relativeParent.layoutVersion;
889
+ this.forceRelativeParentToResolveTarget();
890
+ this.relativeTarget = createBox();
891
+ this.relativeTargetOrigin = createBox();
892
+ calcRelativePosition(this.relativeTargetOrigin, layout, parentLayout);
893
+ copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
894
+ }
895
+ removeRelativeTarget() {
896
+ this.relativeParent = this.relativeTarget = undefined;
897
+ }
898
+ calcProjection() {
899
+ const lead = this.getLead();
900
+ const isShared = Boolean(this.resumingFrom) || this !== lead;
901
+ let canSkip = true;
902
+ /**
903
+ * If this is a normal layout animation and neither this node nor its nearest projecting
904
+ * is dirty then we can't skip.
905
+ */
906
+ if (this.isProjectionDirty || this.parent?.isProjectionDirty) {
907
+ canSkip = false;
908
+ }
909
+ /**
910
+ * If this is a shared layout animation and this node's shared projection is dirty then
911
+ * we can't skip.
912
+ */
913
+ if (isShared &&
914
+ (this.isSharedProjectionDirty || this.isTransformDirty)) {
915
+ canSkip = false;
916
+ }
917
+ /**
918
+ * If we have resolved the target this frame we must recalculate the
919
+ * projection to ensure it visually represents the internal calculations.
920
+ */
921
+ if (this.resolvedRelativeTargetAt === frameData.timestamp) {
922
+ canSkip = false;
923
+ }
924
+ if (canSkip)
925
+ return;
926
+ const { layout, layoutId } = this.options;
927
+ /**
928
+ * If this section of the tree isn't animating we can
929
+ * delete our target sources for the following frame.
930
+ */
931
+ this.isTreeAnimating = Boolean((this.parent && this.parent.isTreeAnimating) ||
932
+ this.currentAnimation ||
933
+ this.pendingAnimation);
934
+ if (!this.isTreeAnimating) {
935
+ this.targetDelta = this.relativeTarget = undefined;
936
+ }
937
+ if (!this.layout || !(layout || layoutId))
938
+ return;
939
+ /**
940
+ * Reset the corrected box with the latest values from box, as we're then going
941
+ * to perform mutative operations on it.
942
+ */
943
+ copyBoxInto(this.layoutCorrected, this.layout.layoutBox);
944
+ /**
945
+ * Record previous tree scales before updating.
946
+ */
947
+ const prevTreeScaleX = this.treeScale.x;
948
+ const prevTreeScaleY = this.treeScale.y;
949
+ /**
950
+ * Apply all the parent deltas to this box to produce the corrected box. This
951
+ * is the layout box, as it will appear on screen as a result of the transforms of its parents.
952
+ */
953
+ applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared);
954
+ /**
955
+ * If this layer needs to perform scale correction but doesn't have a target,
956
+ * use the layout as the target.
957
+ */
958
+ if (lead.layout &&
959
+ !lead.target &&
960
+ (this.treeScale.x !== 1 || this.treeScale.y !== 1)) {
961
+ lead.target = lead.layout.layoutBox;
962
+ lead.targetWithTransforms = createBox();
963
+ }
964
+ const { target } = lead;
965
+ if (!target) {
966
+ /**
967
+ * If we don't have a target to project into, but we were previously
968
+ * projecting, we want to remove the stored transform and schedule
969
+ * a render to ensure the elements reflect the removed transform.
970
+ */
971
+ if (this.prevProjectionDelta) {
972
+ this.createProjectionDeltas();
973
+ this.scheduleRender();
974
+ }
975
+ return;
976
+ }
977
+ if (!this.projectionDelta || !this.prevProjectionDelta) {
978
+ this.createProjectionDeltas();
979
+ }
980
+ else {
981
+ copyAxisDeltaInto(this.prevProjectionDelta.x, this.projectionDelta.x);
982
+ copyAxisDeltaInto(this.prevProjectionDelta.y, this.projectionDelta.y);
983
+ }
984
+ /**
985
+ * Update the delta between the corrected box and the target box before user-set transforms were applied.
986
+ * This will allow us to calculate the corrected borderRadius and boxShadow to compensate
987
+ * for our layout reprojection, but still allow them to be scaled correctly by the user.
988
+ * It might be that to simplify this we may want to accept that user-set scale is also corrected
989
+ * and we wouldn't have to keep and calc both deltas, OR we could support a user setting
990
+ * to allow people to choose whether these styles are corrected based on just the
991
+ * layout reprojection or the final bounding box.
992
+ */
993
+ calcBoxDelta(this.projectionDelta, this.layoutCorrected, target, this.latestValues);
994
+ if (this.treeScale.x !== prevTreeScaleX ||
995
+ this.treeScale.y !== prevTreeScaleY ||
996
+ !axisDeltaEquals(this.projectionDelta.x, this.prevProjectionDelta.x) ||
997
+ !axisDeltaEquals(this.projectionDelta.y, this.prevProjectionDelta.y)) {
998
+ this.hasProjected = true;
999
+ this.scheduleRender();
1000
+ this.notifyListeners("projectionUpdate", target);
1001
+ }
1002
+ /**
1003
+ * Increase debug counter for recalculated projections
1004
+ */
1005
+ if (statsBuffer.value) {
1006
+ metrics.calculatedProjections++;
1007
+ }
1008
+ }
1009
+ hide() {
1010
+ this.isVisible = false;
1011
+ // TODO: Schedule render
1012
+ }
1013
+ show() {
1014
+ this.isVisible = true;
1015
+ // TODO: Schedule render
1016
+ }
1017
+ scheduleRender(notifyAll = true) {
1018
+ this.options.visualElement?.scheduleRender();
1019
+ if (notifyAll) {
1020
+ const stack = this.getStack();
1021
+ stack && stack.scheduleRender();
1022
+ }
1023
+ if (this.resumingFrom && !this.resumingFrom.instance) {
1024
+ this.resumingFrom = undefined;
1025
+ }
1026
+ }
1027
+ createProjectionDeltas() {
1028
+ this.prevProjectionDelta = createDelta();
1029
+ this.projectionDelta = createDelta();
1030
+ this.projectionDeltaWithTransform = createDelta();
1031
+ }
1032
+ setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
1033
+ const snapshot = this.snapshot;
1034
+ const snapshotLatestValues = snapshot ? snapshot.latestValues : {};
1035
+ const mixedValues = { ...this.latestValues };
1036
+ const targetDelta = createDelta();
1037
+ if (!this.relativeParent ||
1038
+ !this.relativeParent.options.layoutRoot) {
1039
+ this.relativeTarget = this.relativeTargetOrigin = undefined;
1040
+ }
1041
+ this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
1042
+ const relativeLayout = createBox();
1043
+ const snapshotSource = snapshot ? snapshot.source : undefined;
1044
+ const layoutSource = this.layout ? this.layout.source : undefined;
1045
+ const isSharedLayoutAnimation = snapshotSource !== layoutSource;
1046
+ const stack = this.getStack();
1047
+ const isOnlyMember = !stack || stack.members.length <= 1;
1048
+ const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
1049
+ !isOnlyMember &&
1050
+ this.options.crossfade === true &&
1051
+ !this.path.some(hasOpacityCrossfade));
1052
+ this.animationProgress = 0;
1053
+ let prevRelativeTarget;
1054
+ this.mixTargetDelta = (latest) => {
1055
+ const progress = latest / 1000;
1056
+ mixAxisDelta(targetDelta.x, delta.x, progress);
1057
+ mixAxisDelta(targetDelta.y, delta.y, progress);
1058
+ this.setTargetDelta(targetDelta);
1059
+ if (this.relativeTarget &&
1060
+ this.relativeTargetOrigin &&
1061
+ this.layout &&
1062
+ this.relativeParent &&
1063
+ this.relativeParent.layout) {
1064
+ calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox);
1065
+ mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
1066
+ /**
1067
+ * If this is an unchanged relative target we can consider the
1068
+ * projection not dirty.
1069
+ */
1070
+ if (prevRelativeTarget &&
1071
+ boxEquals(this.relativeTarget, prevRelativeTarget)) {
1072
+ this.isProjectionDirty = false;
1073
+ }
1074
+ if (!prevRelativeTarget)
1075
+ prevRelativeTarget = createBox();
1076
+ copyBoxInto(prevRelativeTarget, this.relativeTarget);
1077
+ }
1078
+ if (isSharedLayoutAnimation) {
1079
+ this.animationValues = mixedValues;
1080
+ mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
1081
+ }
1082
+ this.root.scheduleUpdateProjection();
1083
+ this.scheduleRender();
1084
+ this.animationProgress = progress;
1085
+ };
1086
+ this.mixTargetDelta(this.options.layoutRoot ? 1000 : 0);
1087
+ }
1088
+ startAnimation(options) {
1089
+ this.notifyListeners("animationStart");
1090
+ this.currentAnimation?.stop();
1091
+ this.resumingFrom?.currentAnimation?.stop();
1092
+ if (this.pendingAnimation) {
1093
+ cancelFrame(this.pendingAnimation);
1094
+ this.pendingAnimation = undefined;
1095
+ }
1096
+ /**
1097
+ * Start the animation in the next frame to have a frame with progress 0,
1098
+ * where the target is the same as when the animation started, so we can
1099
+ * calculate the relative positions correctly for instant transitions.
1100
+ */
1101
+ this.pendingAnimation = frame.update(() => {
1102
+ globalProjectionState.hasAnimatedSinceResize = true;
1103
+ activeAnimations.layout++;
1104
+ this.motionValue || (this.motionValue = motionValue(0));
1105
+ this.currentAnimation = animateSingleValue(this.motionValue, [0, 1000], {
1106
+ ...options,
1107
+ velocity: 0,
1108
+ isSync: true,
1109
+ onUpdate: (latest) => {
1110
+ this.mixTargetDelta(latest);
1111
+ options.onUpdate && options.onUpdate(latest);
1112
+ },
1113
+ onStop: () => {
1114
+ activeAnimations.layout--;
1115
+ },
1116
+ onComplete: () => {
1117
+ activeAnimations.layout--;
1118
+ options.onComplete && options.onComplete();
1119
+ this.completeAnimation();
1120
+ },
1121
+ });
1122
+ if (this.resumingFrom) {
1123
+ this.resumingFrom.currentAnimation = this.currentAnimation;
1124
+ }
1125
+ this.pendingAnimation = undefined;
1126
+ });
1127
+ }
1128
+ completeAnimation() {
1129
+ if (this.resumingFrom) {
1130
+ this.resumingFrom.currentAnimation = undefined;
1131
+ this.resumingFrom.preserveOpacity = undefined;
1132
+ }
1133
+ const stack = this.getStack();
1134
+ stack && stack.exitAnimationComplete();
1135
+ this.resumingFrom =
1136
+ this.currentAnimation =
1137
+ this.animationValues =
1138
+ undefined;
1139
+ this.notifyListeners("animationComplete");
1140
+ }
1141
+ finishAnimation() {
1142
+ if (this.currentAnimation) {
1143
+ this.mixTargetDelta && this.mixTargetDelta(animationTarget);
1144
+ this.currentAnimation.stop();
1145
+ }
1146
+ this.completeAnimation();
1147
+ }
1148
+ applyTransformsToTarget() {
1149
+ const lead = this.getLead();
1150
+ let { targetWithTransforms, target, layout, latestValues } = lead;
1151
+ if (!targetWithTransforms || !target || !layout)
1152
+ return;
1153
+ /**
1154
+ * If we're only animating position, and this element isn't the lead element,
1155
+ * then instead of projecting into the lead box we instead want to calculate
1156
+ * a new target that aligns the two boxes but maintains the layout shape.
1157
+ */
1158
+ if (this !== lead &&
1159
+ this.layout &&
1160
+ layout &&
1161
+ shouldAnimatePositionOnly(this.options.animationType, this.layout.layoutBox, layout.layoutBox)) {
1162
+ target = this.target || createBox();
1163
+ const xLength = calcLength(this.layout.layoutBox.x);
1164
+ target.x.min = lead.target.x.min;
1165
+ target.x.max = target.x.min + xLength;
1166
+ const yLength = calcLength(this.layout.layoutBox.y);
1167
+ target.y.min = lead.target.y.min;
1168
+ target.y.max = target.y.min + yLength;
1169
+ }
1170
+ copyBoxInto(targetWithTransforms, target);
1171
+ /**
1172
+ * Apply the latest user-set transforms to the targetBox to produce the targetBoxFinal.
1173
+ * This is the final box that we will then project into by calculating a transform delta and
1174
+ * applying it to the corrected box.
1175
+ */
1176
+ transformBox(targetWithTransforms, latestValues);
1177
+ /**
1178
+ * Update the delta between the corrected box and the final target box, after
1179
+ * user-set transforms are applied to it. This will be used by the renderer to
1180
+ * create a transform style that will reproject the element from its layout layout
1181
+ * into the desired bounding box.
1182
+ */
1183
+ calcBoxDelta(this.projectionDeltaWithTransform, this.layoutCorrected, targetWithTransforms, latestValues);
1184
+ }
1185
+ registerSharedNode(layoutId, node) {
1186
+ if (!this.sharedNodes.has(layoutId)) {
1187
+ this.sharedNodes.set(layoutId, new NodeStack());
1188
+ }
1189
+ const stack = this.sharedNodes.get(layoutId);
1190
+ stack.add(node);
1191
+ const config = node.options.initialPromotionConfig;
1192
+ node.promote({
1193
+ transition: config ? config.transition : undefined,
1194
+ preserveFollowOpacity: config && config.shouldPreserveFollowOpacity
1195
+ ? config.shouldPreserveFollowOpacity(node)
1196
+ : undefined,
1197
+ });
1198
+ }
1199
+ isLead() {
1200
+ const stack = this.getStack();
1201
+ return stack ? stack.lead === this : true;
1202
+ }
1203
+ getLead() {
1204
+ const { layoutId } = this.options;
1205
+ return layoutId ? this.getStack()?.lead || this : this;
1206
+ }
1207
+ getPrevLead() {
1208
+ const { layoutId } = this.options;
1209
+ return layoutId ? this.getStack()?.prevLead : undefined;
1210
+ }
1211
+ getStack() {
1212
+ const { layoutId } = this.options;
1213
+ if (layoutId)
1214
+ return this.root.sharedNodes.get(layoutId);
1215
+ }
1216
+ promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
1217
+ const stack = this.getStack();
1218
+ if (stack)
1219
+ stack.promote(this, preserveFollowOpacity);
1220
+ if (needsReset) {
1221
+ this.projectionDelta = undefined;
1222
+ this.needsReset = true;
1223
+ }
1224
+ if (transition)
1225
+ this.setOptions({ transition });
1226
+ }
1227
+ relegate() {
1228
+ const stack = this.getStack();
1229
+ if (stack) {
1230
+ return stack.relegate(this);
1231
+ }
1232
+ else {
1233
+ return false;
1234
+ }
1235
+ }
1236
+ resetSkewAndRotation() {
1237
+ const { visualElement } = this.options;
1238
+ if (!visualElement)
1239
+ return;
1240
+ // If there's no detected skew or rotation values, we can early return without a forced render.
1241
+ let hasDistortingTransform = false;
1242
+ /**
1243
+ * An unrolled check for rotation values. Most elements don't have any rotation and
1244
+ * skipping the nested loop and new object creation is 50% faster.
1245
+ */
1246
+ const { latestValues } = visualElement;
1247
+ if (latestValues.z ||
1248
+ latestValues.rotate ||
1249
+ latestValues.rotateX ||
1250
+ latestValues.rotateY ||
1251
+ latestValues.rotateZ ||
1252
+ latestValues.skewX ||
1253
+ latestValues.skewY) {
1254
+ hasDistortingTransform = true;
1255
+ }
1256
+ // If there's no distorting values, we don't need to do any more.
1257
+ if (!hasDistortingTransform)
1258
+ return;
1259
+ const resetValues = {};
1260
+ if (latestValues.z) {
1261
+ resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
1262
+ }
1263
+ // Check the skew and rotate value of all axes and reset to 0
1264
+ for (let i = 0; i < transformAxes.length; i++) {
1265
+ resetDistortingTransform(`rotate${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
1266
+ resetDistortingTransform(`skew${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
1267
+ }
1268
+ // Force a render of this element to apply the transform with all skews and rotations
1269
+ // set to 0.
1270
+ visualElement.render();
1271
+ // Put back all the values we reset
1272
+ for (const key in resetValues) {
1273
+ visualElement.setStaticValue(key, resetValues[key]);
1274
+ if (this.animationValues) {
1275
+ this.animationValues[key] = resetValues[key];
1276
+ }
1277
+ }
1278
+ // Schedule a render for the next frame. This ensures we won't visually
1279
+ // see the element with the reset rotate value applied.
1280
+ visualElement.scheduleRender();
1281
+ }
1282
+ applyProjectionStyles(targetStyle, // CSSStyleDeclaration - doesn't allow numbers to be assigned to properties
1283
+ styleProp) {
1284
+ if (!this.instance || this.isSVG)
1285
+ return;
1286
+ if (!this.isVisible) {
1287
+ targetStyle.visibility = "hidden";
1288
+ return;
1289
+ }
1290
+ const transformTemplate = this.getTransformTemplate();
1291
+ if (this.needsReset) {
1292
+ this.needsReset = false;
1293
+ targetStyle.visibility = "";
1294
+ targetStyle.opacity = "";
1295
+ targetStyle.pointerEvents =
1296
+ resolveMotionValue(styleProp?.pointerEvents) || "";
1297
+ targetStyle.transform = transformTemplate
1298
+ ? transformTemplate(this.latestValues, "")
1299
+ : "none";
1300
+ return;
1301
+ }
1302
+ const lead = this.getLead();
1303
+ if (!this.projectionDelta || !this.layout || !lead.target) {
1304
+ if (this.options.layoutId) {
1305
+ targetStyle.opacity =
1306
+ this.latestValues.opacity !== undefined
1307
+ ? this.latestValues.opacity
1308
+ : 1;
1309
+ targetStyle.pointerEvents =
1310
+ resolveMotionValue(styleProp?.pointerEvents) || "";
1311
+ }
1312
+ if (this.hasProjected && !hasTransform(this.latestValues)) {
1313
+ targetStyle.transform = transformTemplate
1314
+ ? transformTemplate({}, "")
1315
+ : "none";
1316
+ this.hasProjected = false;
1317
+ }
1318
+ return;
1319
+ }
1320
+ targetStyle.visibility = "";
1321
+ const valuesToRender = lead.animationValues || lead.latestValues;
1322
+ this.applyTransformsToTarget();
1323
+ let transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
1324
+ if (transformTemplate) {
1325
+ transform = transformTemplate(valuesToRender, transform);
1326
+ }
1327
+ targetStyle.transform = transform;
1328
+ const { x, y } = this.projectionDelta;
1329
+ targetStyle.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
1330
+ if (lead.animationValues) {
1331
+ /**
1332
+ * If the lead component is animating, assign this either the entering/leaving
1333
+ * opacity
1334
+ */
1335
+ targetStyle.opacity =
1336
+ lead === this
1337
+ ? valuesToRender.opacity ??
1338
+ this.latestValues.opacity ??
1339
+ 1
1340
+ : this.preserveOpacity
1341
+ ? this.latestValues.opacity
1342
+ : valuesToRender.opacityExit;
1343
+ }
1344
+ else {
1345
+ /**
1346
+ * Or we're not animating at all, set the lead component to its layout
1347
+ * opacity and other components to hidden.
1348
+ */
1349
+ targetStyle.opacity =
1350
+ lead === this
1351
+ ? valuesToRender.opacity !== undefined
1352
+ ? valuesToRender.opacity
1353
+ : ""
1354
+ : valuesToRender.opacityExit !== undefined
1355
+ ? valuesToRender.opacityExit
1356
+ : 0;
1357
+ }
1358
+ /**
1359
+ * Apply scale correction
1360
+ */
1361
+ for (const key in scaleCorrectors) {
1362
+ if (valuesToRender[key] === undefined)
1363
+ continue;
1364
+ const { correct, applyTo, isCSSVariable } = scaleCorrectors[key];
1365
+ /**
1366
+ * Only apply scale correction to the value if we have an
1367
+ * active projection transform. Otherwise these values become
1368
+ * vulnerable to distortion if the element changes size without
1369
+ * a corresponding layout animation.
1370
+ */
1371
+ const corrected = transform === "none"
1372
+ ? valuesToRender[key]
1373
+ : correct(valuesToRender[key], lead);
1374
+ if (applyTo) {
1375
+ const num = applyTo.length;
1376
+ for (let i = 0; i < num; i++) {
1377
+ targetStyle[applyTo[i]] = corrected;
1378
+ }
1379
+ }
1380
+ else {
1381
+ // If this is a CSS variable, set it directly on the instance.
1382
+ // Replacing this function from creating styles to setting them
1383
+ // would be a good place to remove per frame object creation
1384
+ if (isCSSVariable) {
1385
+ this.options.visualElement.renderState.vars[key] = corrected;
1386
+ }
1387
+ else {
1388
+ targetStyle[key] = corrected;
1389
+ }
1390
+ }
1391
+ }
1392
+ /**
1393
+ * Disable pointer events on follow components. This is to ensure
1394
+ * that if a follow component covers a lead component it doesn't block
1395
+ * pointer events on the lead.
1396
+ */
1397
+ if (this.options.layoutId) {
1398
+ targetStyle.pointerEvents =
1399
+ lead === this
1400
+ ? resolveMotionValue(styleProp?.pointerEvents) || ""
1401
+ : "none";
1402
+ }
1403
+ }
1404
+ clearSnapshot() {
1405
+ this.resumeFrom = this.snapshot = undefined;
1406
+ }
1407
+ // Only run on root
1408
+ resetTree() {
1409
+ this.root.nodes.forEach((node) => node.currentAnimation?.stop());
1410
+ this.root.nodes.forEach(clearMeasurements);
1411
+ this.root.sharedNodes.clear();
1412
+ }
1413
+ };
1414
+ }
1415
+ function updateLayout(node) {
1416
+ node.updateLayout();
1417
+ }
1418
+ function notifyLayoutUpdate(node) {
1419
+ const snapshot = node.resumeFrom?.snapshot || node.snapshot;
1420
+ if (node.isLead() &&
1421
+ node.layout &&
1422
+ snapshot &&
1423
+ node.hasListeners("didUpdate")) {
1424
+ const { layoutBox: layout, measuredBox: measuredLayout } = node.layout;
1425
+ const { animationType } = node.options;
1426
+ const isShared = snapshot.source !== node.layout.source;
1427
+ // TODO Maybe we want to also resize the layout snapshot so we don't trigger
1428
+ // animations for instance if layout="size" and an element has only changed position
1429
+ if (animationType === "size") {
1430
+ eachAxis((axis) => {
1431
+ const axisSnapshot = isShared
1432
+ ? snapshot.measuredBox[axis]
1433
+ : snapshot.layoutBox[axis];
1434
+ const length = calcLength(axisSnapshot);
1435
+ axisSnapshot.min = layout[axis].min;
1436
+ axisSnapshot.max = axisSnapshot.min + length;
1437
+ });
1438
+ }
1439
+ else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
1440
+ eachAxis((axis) => {
1441
+ const axisSnapshot = isShared
1442
+ ? snapshot.measuredBox[axis]
1443
+ : snapshot.layoutBox[axis];
1444
+ const length = calcLength(layout[axis]);
1445
+ axisSnapshot.max = axisSnapshot.min + length;
1446
+ /**
1447
+ * Ensure relative target gets resized and rerendererd
1448
+ */
1449
+ if (node.relativeTarget && !node.currentAnimation) {
1450
+ node.isProjectionDirty = true;
1451
+ node.relativeTarget[axis].max =
1452
+ node.relativeTarget[axis].min + length;
1453
+ }
1454
+ });
1455
+ }
1456
+ const layoutDelta = createDelta();
1457
+ calcBoxDelta(layoutDelta, layout, snapshot.layoutBox);
1458
+ const visualDelta = createDelta();
1459
+ if (isShared) {
1460
+ calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measuredBox);
1461
+ }
1462
+ else {
1463
+ calcBoxDelta(visualDelta, layout, snapshot.layoutBox);
1464
+ }
1465
+ const hasLayoutChanged = !isDeltaZero(layoutDelta);
1466
+ let hasRelativeLayoutChanged = false;
1467
+ if (!node.resumeFrom) {
1468
+ const relativeParent = node.getClosestProjectingParent();
1469
+ /**
1470
+ * If the relativeParent is itself resuming from a different element then
1471
+ * the relative snapshot is not relavent
1472
+ */
1473
+ if (relativeParent && !relativeParent.resumeFrom) {
1474
+ const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
1475
+ if (parentSnapshot && parentLayout) {
1476
+ const relativeSnapshot = createBox();
1477
+ calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox);
1478
+ const relativeLayout = createBox();
1479
+ calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox);
1480
+ if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
1481
+ hasRelativeLayoutChanged = true;
1482
+ }
1483
+ if (relativeParent.options.layoutRoot) {
1484
+ node.relativeTarget = relativeLayout;
1485
+ node.relativeTargetOrigin = relativeSnapshot;
1486
+ node.relativeParent = relativeParent;
1487
+ }
1488
+ }
1489
+ }
1490
+ }
1491
+ node.notifyListeners("didUpdate", {
1492
+ layout,
1493
+ snapshot,
1494
+ delta: visualDelta,
1495
+ layoutDelta,
1496
+ hasLayoutChanged,
1497
+ hasRelativeLayoutChanged,
1498
+ });
1499
+ }
1500
+ else if (node.isLead()) {
1501
+ const { onExitComplete } = node.options;
1502
+ onExitComplete && onExitComplete();
1503
+ }
1504
+ /**
1505
+ * Clearing transition
1506
+ * TODO: Investigate why this transition is being passed in as {type: false } from Framer
1507
+ * and why we need it at all
1508
+ */
1509
+ node.options.transition = undefined;
1510
+ }
1511
+ function propagateDirtyNodes(node) {
1512
+ /**
1513
+ * Increase debug counter for nodes encountered this frame
1514
+ */
1515
+ if (statsBuffer.value) {
1516
+ metrics.nodes++;
1517
+ }
1518
+ if (!node.parent)
1519
+ return;
1520
+ /**
1521
+ * If this node isn't projecting, propagate isProjectionDirty. It will have
1522
+ * no performance impact but it will allow the next child that *is* projecting
1523
+ * but *isn't* dirty to just check its parent to see if *any* ancestor needs
1524
+ * correcting.
1525
+ */
1526
+ if (!node.isProjecting()) {
1527
+ node.isProjectionDirty = node.parent.isProjectionDirty;
1528
+ }
1529
+ /**
1530
+ * Propagate isSharedProjectionDirty and isTransformDirty
1531
+ * throughout the whole tree. A future revision can take another look at
1532
+ * this but for safety we still recalcualte shared nodes.
1533
+ */
1534
+ node.isSharedProjectionDirty || (node.isSharedProjectionDirty = Boolean(node.isProjectionDirty ||
1535
+ node.parent.isProjectionDirty ||
1536
+ node.parent.isSharedProjectionDirty));
1537
+ node.isTransformDirty || (node.isTransformDirty = node.parent.isTransformDirty);
1538
+ }
1539
+ function cleanDirtyNodes(node) {
1540
+ node.isProjectionDirty =
1541
+ node.isSharedProjectionDirty =
1542
+ node.isTransformDirty =
1543
+ false;
1544
+ }
1545
+ function clearSnapshot(node) {
1546
+ node.clearSnapshot();
1547
+ }
1548
+ function clearMeasurements(node) {
1549
+ node.clearMeasurements();
1550
+ }
1551
+ function clearIsLayoutDirty(node) {
1552
+ node.isLayoutDirty = false;
1553
+ }
1554
+ function resetTransformStyle(node) {
1555
+ const { visualElement } = node.options;
1556
+ if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
1557
+ visualElement.notify("BeforeLayoutMeasure");
1558
+ }
1559
+ node.resetTransform();
1560
+ }
1561
+ function finishAnimation(node) {
1562
+ node.finishAnimation();
1563
+ node.targetDelta = node.relativeTarget = node.target = undefined;
1564
+ node.isProjectionDirty = true;
1565
+ }
1566
+ function resolveTargetDelta(node) {
1567
+ node.resolveTargetDelta();
1568
+ }
1569
+ function calcProjection(node) {
1570
+ node.calcProjection();
1571
+ }
1572
+ function resetSkewAndRotation(node) {
1573
+ node.resetSkewAndRotation();
1574
+ }
1575
+ function removeLeadSnapshots(stack) {
1576
+ stack.removeLeadSnapshot();
1577
+ }
1578
+ function mixAxisDelta(output, delta, p) {
1579
+ output.translate = mixNumber(delta.translate, 0, p);
1580
+ output.scale = mixNumber(delta.scale, 1, p);
1581
+ output.origin = delta.origin;
1582
+ output.originPoint = delta.originPoint;
1583
+ }
1584
+ function mixAxis(output, from, to, p) {
1585
+ output.min = mixNumber(from.min, to.min, p);
1586
+ output.max = mixNumber(from.max, to.max, p);
1587
+ }
1588
+ function mixBox(output, from, to, p) {
1589
+ mixAxis(output.x, from.x, to.x, p);
1590
+ mixAxis(output.y, from.y, to.y, p);
1591
+ }
1592
+ function hasOpacityCrossfade(node) {
1593
+ return (node.animationValues && node.animationValues.opacityExit !== undefined);
1594
+ }
1595
+ const defaultLayoutTransition = {
1596
+ duration: 0.45,
1597
+ ease: [0.4, 0, 0.1, 1],
1598
+ };
1599
+ const userAgentContains = (string) => typeof navigator !== "undefined" &&
1600
+ navigator.userAgent &&
1601
+ navigator.userAgent.toLowerCase().includes(string);
1602
+ /**
1603
+ * Measured bounding boxes must be rounded in Safari and
1604
+ * left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
1605
+ * can appear to jump.
1606
+ */
1607
+ const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
1608
+ ? Math.round
1609
+ : noop;
1610
+ function roundAxis(axis) {
1611
+ // Round to the nearest .5 pixels to support subpixel layouts
1612
+ axis.min = roundPoint(axis.min);
1613
+ axis.max = roundPoint(axis.max);
1614
+ }
1615
+ function roundBox(box) {
1616
+ roundAxis(box.x);
1617
+ roundAxis(box.y);
1618
+ }
1619
+ function shouldAnimatePositionOnly(animationType, snapshot, layout) {
1620
+ return (animationType === "position" ||
1621
+ (animationType === "preserve-aspect" &&
1622
+ !isNear(aspectRatio(snapshot), aspectRatio(layout), 0.2)));
1623
+ }
1624
+ function checkNodeWasScrollRoot(node) {
1625
+ return node !== node.root && node.scroll?.wasRoot;
1626
+ }
1627
+
1628
+ export { cleanDirtyNodes, createProjectionNode, mixAxis, mixAxisDelta, mixBox, propagateDirtyNodes };