motion-dom 14.5.0 → 14.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/cjs/index.js +706 -632
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/AsyncMotionValueAnimation.mjs +3 -6
  4. package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
  5. package/dist/es/animation/JSAnimation.mjs +18 -30
  6. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  7. package/dist/es/animation/NativeAnimation.mjs +14 -8
  8. package/dist/es/animation/NativeAnimation.mjs.map +1 -1
  9. package/dist/es/animation/animate/effects.mjs +5 -2
  10. package/dist/es/animation/animate/effects.mjs.map +1 -1
  11. package/dist/es/animation/generators/inertia.mjs +3 -2
  12. package/dist/es/animation/generators/inertia.mjs.map +1 -1
  13. package/dist/es/animation/generators/spring.mjs +50 -52
  14. package/dist/es/animation/generators/spring.mjs.map +1 -1
  15. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
  16. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  17. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +7 -15
  18. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
  19. package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
  20. package/dist/es/animation/keyframes/utils/unit-conversion.mjs +8 -7
  21. package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
  22. package/dist/es/animation/optimized-appear/data-id.mjs +1 -3
  23. package/dist/es/animation/optimized-appear/data-id.mjs.map +1 -1
  24. package/dist/es/animation/utils/can-animate.mjs +1 -0
  25. package/dist/es/animation/utils/can-animate.mjs.map +1 -1
  26. package/dist/es/animation/utils/css-variables-conversion.mjs +2 -1
  27. package/dist/es/animation/utils/css-variables-conversion.mjs.map +1 -1
  28. package/dist/es/animation/utils/is-transition-defined.mjs +1 -0
  29. package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
  30. package/dist/es/animation/waapi/supports/waapi.mjs +8 -2
  31. package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
  32. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +44 -21
  33. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  34. package/dist/es/animation/waapi/utils/accelerated-values.mjs +4 -1
  35. package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
  36. package/dist/es/effects/style/transform.mjs +4 -20
  37. package/dist/es/effects/style/transform.mjs.map +1 -1
  38. package/dist/es/frameloop/process-frame.mjs +42 -0
  39. package/dist/es/frameloop/process-frame.mjs.map +1 -0
  40. package/dist/es/frameloop/render-step.mjs +15 -1
  41. package/dist/es/frameloop/render-step.mjs.map +1 -1
  42. package/dist/es/gestures/drag/VisualElementDragControls.mjs +94 -67
  43. package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
  44. package/dist/es/gestures/pan/PanSession.mjs +28 -39
  45. package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
  46. package/dist/es/index.mjs +4 -2
  47. package/dist/es/index.mjs.map +1 -1
  48. package/dist/es/layout/LayoutAnimationBuilder.mjs +2 -2
  49. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  50. package/dist/es/projection/animation/mix-values.mjs +3 -11
  51. package/dist/es/projection/animation/mix-values.mjs.map +1 -1
  52. package/dist/es/projection/geometry/delta-apply.mjs +10 -6
  53. package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
  54. package/dist/es/projection/geometry/delta-calc.mjs +2 -2
  55. package/dist/es/projection/geometry/delta-calc.mjs.map +1 -1
  56. package/dist/es/projection/geometry/delta-remove.mjs +2 -2
  57. package/dist/es/projection/geometry/delta-remove.mjs.map +1 -1
  58. package/dist/es/projection/node/DocumentProjectionNode.mjs +8 -3
  59. package/dist/es/projection/node/DocumentProjectionNode.mjs.map +1 -1
  60. package/dist/es/projection/node/HTMLProjectionNode.mjs +5 -6
  61. package/dist/es/projection/node/HTMLProjectionNode.mjs.map +1 -1
  62. package/dist/es/projection/node/create-projection-node.mjs +158 -148
  63. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  64. package/dist/es/projection/node/root.mjs +6 -0
  65. package/dist/es/projection/node/root.mjs.map +1 -0
  66. package/dist/es/projection/styles/default-scale-correctors.mjs +3 -4
  67. package/dist/es/projection/styles/default-scale-correctors.mjs.map +1 -1
  68. package/dist/es/projection/styles/transform.mjs +12 -16
  69. package/dist/es/projection/styles/transform.mjs.map +1 -1
  70. package/dist/es/projection/utils/has-transform.mjs +16 -2
  71. package/dist/es/projection/utils/has-transform.mjs.map +1 -1
  72. package/dist/es/render/VisualElement.mjs +20 -37
  73. package/dist/es/render/VisualElement.mjs.map +1 -1
  74. package/dist/es/render/dom/parse-transform.mjs +6 -17
  75. package/dist/es/render/dom/parse-transform.mjs.map +1 -1
  76. package/dist/es/render/html/HTMLVisualElement.mjs +2 -1
  77. package/dist/es/render/html/HTMLVisualElement.mjs.map +1 -1
  78. package/dist/es/render/html/utils/build-transform.mjs +25 -29
  79. package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
  80. package/dist/es/render/utils/animation-state.mjs +58 -15
  81. package/dist/es/render/utils/animation-state.mjs.map +1 -1
  82. package/dist/es/render/utils/variant-props.mjs +1 -1
  83. package/dist/es/render/utils/variant-props.mjs.map +1 -1
  84. package/dist/es/utils/interpolate.mjs +2 -1
  85. package/dist/es/utils/interpolate.mjs.map +1 -1
  86. package/dist/es/utils/mix/color.mjs +2 -1
  87. package/dist/es/utils/mix/color.mjs.map +1 -1
  88. package/dist/es/utils/mix/complex.mjs +4 -4
  89. package/dist/es/utils/mix/complex.mjs.map +1 -1
  90. package/dist/es/utils/resolve-elements.mjs.map +1 -1
  91. package/dist/es/value/index.mjs +13 -34
  92. package/dist/es/value/index.mjs.map +1 -1
  93. package/dist/es/value/types/color/hex.mjs +13 -26
  94. package/dist/es/value/types/color/hex.mjs.map +1 -1
  95. package/dist/es/value/types/complex/index.mjs +1 -1
  96. package/dist/es/value/types/complex/index.mjs.map +1 -1
  97. package/dist/index.d.ts +111 -30
  98. package/dist/motion-dom.dev.js +690 -625
  99. package/dist/motion-dom.js +1 -1
  100. package/dist/size-rollup-motion-value.js +1 -1
  101. package/dist/size-rollup-motion-value.js.map +1 -1
  102. package/dist/size-rollup-style-effect.js +1 -1
  103. package/dist/size-rollup-style-effect.js.map +1 -1
  104. package/package.json +4 -3
@@ -26,25 +26,20 @@ import { defaultScaleCorrectors } from '../styles/default-scale-correctors.mjs';
26
26
  import { buildProjectionTransform } from '../styles/transform.mjs';
27
27
  import { eachAxis } from '../utils/each-axis.mjs';
28
28
  import { FlatTree } from '../utils/flat-tree.mjs';
29
- import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
29
+ import { hasTransform, hasScale, has2DTranslate, hasDistortingTransform, angleTransforms } from '../utils/has-transform.mjs';
30
30
  import { globalProjectionState } from './state.mjs';
31
31
  import { frame, cancelFrame, frameSteps } from '../../frameloop/frame.mjs';
32
32
  import { frameData } from '../../frameloop/frame-data.mjs';
33
33
 
34
- /**
35
- * Correctors registered via addScaleCorrector before projection loaded
36
- * (e.g. with an async LazyMotion bundle) take precedence over the defaults.
37
- */
38
- Object.assign(scaleCorrectors, {
39
- ...defaultScaleCorrectors,
40
- ...scaleCorrectors,
41
- });
42
34
  const metrics = {
43
35
  nodes: 0,
44
36
  calculatedTargetDeltas: 0,
45
37
  calculatedProjections: 0,
46
38
  };
47
- const transformAxes = ["", "X", "Y", "Z"];
39
+ /**
40
+ * Transforms that distort an element's layout, so must be reset before measuring.
41
+ */
42
+ const distortingTransforms = ["z", "skew", "skewZ"];
48
43
  /**
49
44
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
50
45
  * which has a noticeable difference in spring animations
@@ -81,6 +76,16 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
81
76
  }
82
77
  }
83
78
  function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
79
+ /**
80
+ * Correctors registered via addScaleCorrector before projection loaded
81
+ * (e.g. with an async LazyMotion bundle) take precedence over the defaults.
82
+ * Applied here rather than at module scope so bundlers can drop projection
83
+ * when it's unused.
84
+ */
85
+ Object.assign(scaleCorrectors, {
86
+ ...defaultScaleCorrectors,
87
+ ...scaleCorrectors,
88
+ });
84
89
  return class ProjectionNode {
85
90
  constructor(latestValues = {}, parent = defaultParent?.()) {
86
91
  /**
@@ -242,8 +247,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
242
247
  return this.eventHandlers.get(name).add(handler);
243
248
  }
244
249
  notifyListeners(name, ...args) {
245
- const subscriptionManager = this.eventHandlers.get(name);
246
- subscriptionManager && subscriptionManager.notify(...args);
250
+ this.eventHandlers.get(name)?.notify(...args);
247
251
  }
248
252
  hasListeners(name) {
249
253
  return this.eventHandlers.has(name);
@@ -261,7 +265,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
261
265
  visualElement.mount(instance);
262
266
  }
263
267
  this.root.nodes.add(this);
264
- this.parent && this.parent.children.add(this);
268
+ this.parent?.children.add(this);
265
269
  if (this.root.hasTreeAnimated && (layout || layoutId)) {
266
270
  this.isLayoutDirty = true;
267
271
  }
@@ -279,7 +283,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
279
283
  return;
280
284
  innerWidth = newInnerWidth;
281
285
  this.root.updateBlockedByResize = true;
282
- cancelDelay && cancelDelay();
286
+ cancelDelay?.();
283
287
  cancelDelay = delay(resizeUnblockUpdate, 250);
284
288
  if (globalProjectionState.hasAnimatedSinceResize) {
285
289
  globalProjectionState.hasAnimatedSinceResize = false;
@@ -370,9 +374,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
370
374
  if (!hasLayoutChanged) {
371
375
  finishAnimation(this);
372
376
  }
373
- if (this.isLead() && this.options.onExitComplete) {
374
- this.options.onExitComplete();
375
- }
377
+ this.isLead() && this.options.onExitComplete?.();
376
378
  }
377
379
  this.targetLayout = newLayout;
378
380
  });
@@ -380,9 +382,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
380
382
  unmount() {
381
383
  this.options.layoutId && this.willUpdate();
382
384
  this.root.nodes.remove(this);
383
- const stack = this.getStack();
384
- stack && stack.remove(this);
385
- this.parent && this.parent.children.delete(this);
385
+ this.getStack()?.remove(this);
386
+ this.parent?.children.delete(this);
386
387
  this.instance = undefined;
387
388
  this.eventHandlers.clear();
388
389
  this.hasLayoutListener = false;
@@ -403,7 +404,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
403
404
  if (this.isUpdateBlocked())
404
405
  return;
405
406
  this.isUpdating = true;
406
- this.nodes && this.nodes.forEach(resetSkewAndRotation);
407
+ this.nodes?.forEach(resetSkewAndRotation);
407
408
  this.animationId++;
408
409
  }
409
410
  getTransformTemplate() {
@@ -413,7 +414,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
413
414
  willUpdate(shouldNotifyListeners = true) {
414
415
  this.root.hasTreeAnimated = true;
415
416
  if (this.root.isUpdateBlocked()) {
416
- this.options.onExitComplete && this.options.onExitComplete();
417
+ this.options.onExitComplete?.();
417
418
  return;
418
419
  }
419
420
  /**
@@ -630,24 +631,23 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
630
631
  this.projectionDelta = undefined;
631
632
  this.notifyListeners("measure", this.layout.layoutBox);
632
633
  const { visualElement } = this.options;
633
- visualElement &&
634
- visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
634
+ visualElement?.notify("LayoutMeasure", this.layout.layoutBox, prevLayout?.layoutBox);
635
635
  }
636
636
  updateScroll(phase = "measure") {
637
- let needsMeasurement = Boolean(this.options.layoutScroll && this.instance);
638
- if (this.scroll &&
639
- this.scroll.animationId === this.root.animationId &&
640
- this.scroll.phase === phase) {
641
- needsMeasurement = false;
642
- }
643
- if (needsMeasurement && this.instance) {
644
- const isRoot = checkIsScrollRoot(this.instance);
637
+ const { scroll, instance } = this;
638
+ const { animationId } = this.root;
639
+ if (this.options.layoutScroll &&
640
+ instance &&
641
+ !(scroll &&
642
+ scroll.animationId === animationId &&
643
+ scroll.phase === phase)) {
644
+ const isRoot = checkIsScrollRoot(instance);
645
645
  this.scroll = {
646
- animationId: this.root.animationId,
646
+ animationId,
647
647
  phase,
648
648
  isRoot,
649
- offset: measureScroll(this.instance),
650
- wasRoot: this.scroll ? this.scroll.isRoot : isRoot,
649
+ offset: measureScroll(instance),
650
+ wasRoot: scroll ? scroll.isRoot : isRoot,
651
651
  };
652
652
  }
653
653
  }
@@ -737,10 +737,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
737
737
  }
738
738
  return boxWithoutScroll;
739
739
  }
740
- applyTransform(box, transformOnly = false, output) {
740
+ applyTransform(box, transformOnly = false, output, skipOwnTransform, start = 0) {
741
741
  const withTransforms = output || createBox();
742
742
  copyBoxInto(withTransforms, box);
743
- for (let i = 0; i < this.path.length; i++) {
743
+ for (let i = start; i < this.path.length; i++) {
744
744
  const node = this.path[i];
745
745
  if (!transformOnly &&
746
746
  node.options.layoutScroll &&
@@ -753,7 +753,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
753
753
  continue;
754
754
  transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
755
755
  }
756
- if (hasTransform(this.latestValues)) {
756
+ if (!skipOwnTransform && hasTransform(this.latestValues)) {
757
757
  transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
758
758
  }
759
759
  return withTransforms;
@@ -888,7 +888,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
888
888
  }
889
889
  else if (this.targetDelta) {
890
890
  if (Boolean(this.resumingFrom)) {
891
- this.applyTransform(this.layout.layoutBox, false, this.target);
891
+ /**
892
+ * Own transforms are applied later, in applyTransformsToTarget,
893
+ * so only apply ancestor transforms here or they'd be doubled.
894
+ */
895
+ this.applyTransform(this.layout.layoutBox, false, this.target, true);
892
896
  }
893
897
  else {
894
898
  copyBoxInto(this.target, this.layout.layoutBox);
@@ -908,8 +912,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
908
912
  this.attemptToResolveRelativeTarget = false;
909
913
  if (this.options.layoutAnchor !== false &&
910
914
  relativeParent &&
911
- Boolean(relativeParent.resumingFrom) ===
912
- Boolean(this.resumingFrom) &&
915
+ (!relativeParent.resumingFrom === !this.resumingFrom ||
916
+ /**
917
+ * Shared layout animations within a layoutRoot
918
+ * animate relative to it.
919
+ */
920
+ (relativeParent.options.layoutRoot &&
921
+ !relativeParent.resumingFrom)) &&
913
922
  !relativeParent.options.layoutScroll &&
914
923
  relativeParent.target &&
915
924
  this.animationProgress !== 1) {
@@ -989,7 +998,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
989
998
  * If this section of the tree isn't animating we can
990
999
  * delete our target sources for the following frame.
991
1000
  */
992
- this.isTreeAnimating = Boolean((this.parent && this.parent.isTreeAnimating) ||
1001
+ this.isTreeAnimating = Boolean(this.parent?.isTreeAnimating ||
993
1002
  this.currentAnimation ||
994
1003
  this.pendingAnimation);
995
1004
  if (!this.isTreeAnimating) {
@@ -1010,8 +1019,17 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1010
1019
  /**
1011
1020
  * Apply all the parent deltas to this box to produce the corrected box. This
1012
1021
  * is the layout box, as it will appear on screen as a result of the transforms of its parents.
1022
+ *
1023
+ * A shared target is usually in page space, so ancestor transforms are applied
1024
+ * too. But a target relative to a parent that isn't itself shared (like a
1025
+ * layoutRoot) is in that parent's layout space. So the transforms of the
1026
+ * parent and its ancestors, which move both elements alike, are skipped,
1027
+ * but those of other ancestors (between it and either element) apply.
1013
1028
  */
1014
- applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared);
1029
+ applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared &&
1030
+ (lead.relativeTarget && !lead.relativeParent.resumingFrom
1031
+ ? lead.relativeParent
1032
+ : true));
1015
1033
  /**
1016
1034
  * If this layer needs to perform scale correction but doesn't have a target,
1017
1035
  * use the layout as the target.
@@ -1078,8 +1096,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1078
1096
  scheduleRender(notifyAll = true) {
1079
1097
  this.options.visualElement?.scheduleRender();
1080
1098
  if (notifyAll) {
1081
- const stack = this.getStack();
1082
- stack && stack.scheduleRender();
1099
+ this.getStack()?.scheduleRender();
1083
1100
  }
1084
1101
  if (this.resumingFrom && !this.resumingFrom.instance) {
1085
1102
  this.resumingFrom = undefined;
@@ -1101,9 +1118,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1101
1118
  }
1102
1119
  this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
1103
1120
  const relativeLayout = createBox();
1104
- const snapshotSource = snapshot ? snapshot.source : undefined;
1105
- const layoutSource = this.layout ? this.layout.source : undefined;
1106
- const isSharedLayoutAnimation = snapshotSource !== layoutSource;
1121
+ const isSharedLayoutAnimation = snapshot?.source !== this.layout?.source;
1107
1122
  const stack = this.getStack();
1108
1123
  const isOnlyMember = !stack || stack.members.length <= 1;
1109
1124
  const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
@@ -1118,19 +1133,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1118
1133
  this.mixTargetDelta = (latest) => {
1119
1134
  const progress = latest / 1000;
1120
1135
  const point = interpolate?.(progress);
1136
+ mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
1137
+ mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
1121
1138
  if (point) {
1122
1139
  targetDelta.x.translate = point.x;
1123
- targetDelta.x.scale = mixNumber(delta.x.scale, 1, progress);
1124
- targetDelta.x.origin = delta.x.origin;
1125
- targetDelta.x.originPoint = delta.x.originPoint;
1126
1140
  targetDelta.y.translate = point.y;
1127
- targetDelta.y.scale = mixNumber(delta.y.scale, 1, progress);
1128
- targetDelta.y.origin = delta.y.origin;
1129
- targetDelta.y.originPoint = delta.y.originPoint;
1130
- }
1131
- else {
1132
- mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
1133
- mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
1134
1141
  }
1135
1142
  this.setTargetDelta(targetDelta);
1136
1143
  if (this.relativeTarget &&
@@ -1156,7 +1163,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1156
1163
  this.animationValues = mixedValues;
1157
1164
  mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
1158
1165
  }
1159
- if (point && point.rotate !== undefined) {
1166
+ if (point?.rotate !== undefined) {
1160
1167
  // Dedicated `pathRotation` channel, not `rotate`, so an
1161
1168
  // animating `rotate` is composed with, never clobbered.
1162
1169
  if (!this.animationValues)
@@ -1221,7 +1228,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1221
1228
  }
1222
1229
  finishAnimation() {
1223
1230
  if (this.currentAnimation) {
1224
- this.mixTargetDelta && this.mixTargetDelta(animationTarget);
1231
+ this.mixTargetDelta?.(animationTarget);
1225
1232
  this.currentAnimation.stop();
1226
1233
  }
1227
1234
  this.completeAnimation();
@@ -1241,13 +1248,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1241
1248
  this.layout &&
1242
1249
  layout &&
1243
1250
  shouldAnimatePositionOnly(this.options.animationType, this.layout.layoutBox, layout.layoutBox)) {
1251
+ const { layoutBox } = this.layout;
1252
+ const leadTarget = target;
1244
1253
  target = this.target || createBox();
1245
- const xLength = calcLength(this.layout.layoutBox.x);
1246
- target.x.min = lead.target.x.min;
1247
- target.x.max = target.x.min + xLength;
1248
- const yLength = calcLength(this.layout.layoutBox.y);
1249
- target.y.min = lead.target.y.min;
1250
- target.y.max = target.y.min + yLength;
1254
+ alignAxis(target.x, leadTarget.x, layoutBox.x);
1255
+ alignAxis(target.y, leadTarget.y, layoutBox.y);
1251
1256
  }
1252
1257
  copyBoxInto(targetWithTransforms, target);
1253
1258
  /**
@@ -1272,8 +1277,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1272
1277
  stack.add(node);
1273
1278
  const config = node.options.initialPromotionConfig;
1274
1279
  node.promote({
1275
- transition: config ? config.transition : undefined,
1276
- preserveFollowOpacity: config && config.shouldPreserveFollowOpacity
1280
+ transition: config?.transition,
1281
+ preserveFollowOpacity: config?.shouldPreserveFollowOpacity
1277
1282
  ? config.shouldPreserveFollowOpacity(node)
1278
1283
  : undefined,
1279
1284
  });
@@ -1296,9 +1301,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1296
1301
  return this.root.sharedNodes.get(layoutId);
1297
1302
  }
1298
1303
  promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
1299
- const stack = this.getStack();
1300
- if (stack)
1301
- stack.promote(this, preserveFollowOpacity);
1304
+ this.getStack()?.promote(this, preserveFollowOpacity);
1302
1305
  if (needsReset) {
1303
1306
  this.projectionDelta = undefined;
1304
1307
  this.needsReset = true;
@@ -1307,45 +1310,27 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1307
1310
  this.setOptions({ transition });
1308
1311
  }
1309
1312
  relegate() {
1310
- const stack = this.getStack();
1311
- if (stack) {
1312
- return stack.relegate(this);
1313
- }
1314
- else {
1315
- return false;
1316
- }
1313
+ return this.getStack()?.relegate(this) || false;
1317
1314
  }
1318
1315
  resetSkewAndRotation() {
1319
1316
  const { visualElement } = this.options;
1320
1317
  if (!visualElement)
1321
1318
  return;
1322
- // If there's no detected skew or rotation values, we can early return without a forced render.
1323
- let hasDistortingTransform = false;
1324
1319
  /**
1325
1320
  * An unrolled check for rotation values. Most elements don't have any rotation and
1326
- * skipping the nested loop and new object creation is 50% faster.
1321
+ * skipping the loop and new object creation is 50% faster.
1322
+ * If there's no distorting values, we don't need to do any more.
1327
1323
  */
1328
1324
  const { latestValues } = visualElement;
1329
- if (latestValues.z ||
1330
- latestValues.rotate ||
1331
- latestValues.rotateX ||
1332
- latestValues.rotateY ||
1333
- latestValues.rotateZ ||
1334
- latestValues.skewX ||
1335
- latestValues.skewY) {
1336
- hasDistortingTransform = true;
1337
- }
1338
- // If there's no distorting values, we don't need to do any more.
1339
- if (!hasDistortingTransform)
1325
+ if (!hasDistortingTransform(latestValues))
1340
1326
  return;
1341
1327
  const resetValues = {};
1342
- if (latestValues.z) {
1343
- resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
1344
- }
1345
1328
  // Check the skew and rotate value of all axes and reset to 0
1346
- for (let i = 0; i < transformAxes.length; i++) {
1347
- resetDistortingTransform(`rotate${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
1348
- resetDistortingTransform(`skew${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
1329
+ for (let i = 0; i < distortingTransforms.length; i++) {
1330
+ resetDistortingTransform(distortingTransforms[i], visualElement, resetValues, this.animationValues);
1331
+ }
1332
+ for (let i = 0; i < angleTransforms.length; i++) {
1333
+ resetDistortingTransform(angleTransforms[i], visualElement, resetValues, this.animationValues);
1349
1334
  }
1350
1335
  // Force a render of this element to apply the transform with all skews and rotations
1351
1336
  // set to 0.
@@ -1365,7 +1350,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1365
1350
  styleProp) {
1366
1351
  if (!this.instance || this.isSVG)
1367
1352
  return;
1368
- if (!this.isVisible) {
1353
+ const lead = this.getLead();
1354
+ /**
1355
+ * Without crossfade, a new lead hides the previous one, as it's
1356
+ * usually unmounting. One that gave its layoutId away keeps
1357
+ * rendering, so only hide nodes that follow another.
1358
+ */
1359
+ if (!this.isVisible && lead !== this) {
1369
1360
  targetStyle.visibility = "hidden";
1370
1361
  return;
1371
1362
  }
@@ -1381,9 +1372,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1381
1372
  : "none";
1382
1373
  return;
1383
1374
  }
1384
- const lead = this.getLead();
1385
1375
  if (!this.projectionDelta || !this.layout || !lead.target) {
1386
- if (this.options.layoutId) {
1376
+ if (this.options.layoutId || this.needsShow) {
1377
+ this.needsShow = false;
1378
+ targetStyle.visibility = "";
1387
1379
  targetStyle.opacity =
1388
1380
  this.latestValues.opacity !== undefined
1389
1381
  ? this.latestValues.opacity
@@ -1517,52 +1509,49 @@ function notifyLayoutUpdate(node) {
1517
1509
  const isShared = snapshot.source !== node.layout.source;
1518
1510
  // TODO Maybe we want to also resize the layout snapshot so we don't trigger
1519
1511
  // animations for instance if layout="size" and an element has only changed position
1520
- if (animationType === "size") {
1521
- eachAxis((axis) => {
1522
- const axisSnapshot = isShared
1523
- ? snapshot.measuredBox[axis]
1524
- : snapshot.layoutBox[axis];
1525
- const length = calcLength(axisSnapshot);
1526
- axisSnapshot.min = layout[axis].min;
1527
- axisSnapshot.max = axisSnapshot.min + length;
1528
- });
1529
- }
1530
- else if (animationType === "x" || animationType === "y") {
1531
- const snapAxis = animationType === "x" ? "y" : "x";
1532
- copyAxisInto(isShared
1533
- ? snapshot.measuredBox[snapAxis]
1534
- : snapshot.layoutBox[snapAxis], layout[snapAxis]);
1535
- }
1536
- else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
1537
- eachAxis((axis) => {
1538
- const axisSnapshot = isShared
1539
- ? snapshot.measuredBox[axis]
1540
- : snapshot.layoutBox[axis];
1541
- const length = calcLength(layout[axis]);
1542
- axisSnapshot.max = axisSnapshot.min + length;
1543
- /**
1544
- * Ensure relative target gets resized and rerendererd
1545
- */
1546
- if (node.relativeTarget && !node.currentAnimation) {
1547
- node.isProjectionDirty = true;
1548
- node.relativeTarget[axis].max =
1549
- node.relativeTarget[axis].min + length;
1550
- }
1551
- });
1552
- }
1512
+ const resizeSnapshot = (box, to) => {
1513
+ if (animationType === "size") {
1514
+ eachAxis((axis) => {
1515
+ const length = calcLength(box[axis]);
1516
+ box[axis].min = to[axis].min;
1517
+ box[axis].max = box[axis].min + length;
1518
+ });
1519
+ }
1520
+ else if (animationType === "x" || animationType === "y") {
1521
+ const snapAxis = animationType === "x" ? "y" : "x";
1522
+ copyAxisInto(box[snapAxis], to[snapAxis]);
1523
+ }
1524
+ else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
1525
+ eachAxis((axis) => {
1526
+ const length = calcLength(to[axis]);
1527
+ box[axis].max = box[axis].min + length;
1528
+ /**
1529
+ * Ensure relative target gets resized and rerendererd
1530
+ */
1531
+ if (node.relativeTarget && !node.currentAnimation) {
1532
+ node.isProjectionDirty = true;
1533
+ node.relativeTarget[axis].max =
1534
+ node.relativeTarget[axis].min + length;
1535
+ }
1536
+ });
1537
+ }
1538
+ };
1539
+ const snapshotBox = isShared ? snapshot.measuredBox : snapshot.layoutBox;
1540
+ resizeSnapshot(snapshotBox, layout);
1553
1541
  const layoutDelta = createDelta();
1554
1542
  calcBoxDelta(layoutDelta, layout, snapshot.layoutBox);
1555
1543
  const visualDelta = createDelta();
1556
- if (isShared) {
1557
- calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measuredBox);
1558
- }
1559
- else {
1560
- calcBoxDelta(visualDelta, layout, snapshot.layoutBox);
1561
- }
1544
+ calcBoxDelta(visualDelta, isShared ? node.applyTransform(measuredLayout, true) : layout, snapshotBox);
1562
1545
  const hasLayoutChanged = !isDeltaZero(layoutDelta);
1563
1546
  let hasRelativeLayoutChanged = false;
1564
- if (!node.resumeFrom) {
1565
- const relativeParent = node.getClosestProjectingParent();
1547
+ const relativeParent = node.getClosestProjectingParent();
1548
+ /**
1549
+ * A snapshot resumed from another element is only relative to this
1550
+ * node's relativeParent if it's a layoutRoot that contains both.
1551
+ */
1552
+ if (!node.resumeFrom ||
1553
+ (relativeParent?.options.layoutRoot &&
1554
+ node.resumeFrom.path.includes(relativeParent))) {
1566
1555
  /**
1567
1556
  * If the relativeParent is itself resuming from a different element then
1568
1557
  * the relative snapshot is not relavent
@@ -1571,10 +1560,22 @@ function notifyLayoutUpdate(node) {
1571
1560
  const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
1572
1561
  if (parentSnapshot && parentLayout) {
1573
1562
  const anchor = node.options.layoutAnchor || undefined;
1563
+ /**
1564
+ * A shared snapshot includes the transforms of the old
1565
+ * element's ancestors below the layoutRoot, as they
1566
+ * aren't shared with the new element.
1567
+ */
1574
1568
  const relativeSnapshot = createBox();
1575
- calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
1569
+ calcRelativePosition(relativeSnapshot, isShared
1570
+ ? node.resumeFrom.applyTransform(snapshot.layoutBox, true, undefined, true, relativeParent.depth + 1)
1571
+ : snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
1576
1572
  const relativeLayout = createBox();
1577
1573
  calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox, anchor);
1574
+ /**
1575
+ * A shared snapshot is resized in page space, above, so
1576
+ * resize it relative to the layoutRoot too.
1577
+ */
1578
+ isShared && resizeSnapshot(relativeSnapshot, relativeLayout);
1578
1579
  if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
1579
1580
  hasRelativeLayoutChanged = true;
1580
1581
  }
@@ -1596,8 +1597,7 @@ function notifyLayoutUpdate(node) {
1596
1597
  });
1597
1598
  }
1598
1599
  else if (node.isLead()) {
1599
- const { onExitComplete } = node.options;
1600
- onExitComplete && onExitComplete();
1600
+ node.options.onExitComplete?.();
1601
1601
  }
1602
1602
  /**
1603
1603
  * Clearing transition
@@ -1657,10 +1657,13 @@ function clearIsLayoutDirty(node) {
1657
1657
  * A dragged node doesn't layout animate, so it jumps to its new layout. Shift
1658
1658
  * its descendants' snapshots by the same amount, so they only animate layout
1659
1659
  * changes relative to it, rather than lagging behind.
1660
+ *
1661
+ * If its drag ended since the snapshot (e.g. drag disabled from onDrag), it
1662
+ * layout animates again, so its descendants mustn't follow its jump.
1660
1663
  */
1661
1664
  function followDraggedAncestor(node) {
1662
1665
  const { snapshot, dragAncestor } = node;
1663
- const to = dragAncestor?.layout;
1666
+ const to = dragAncestor?.isAnimationBlocked && dragAncestor.layout;
1664
1667
  if (!snapshot || !to || node.resumeFrom || node.isAnimationBlocked)
1665
1668
  return;
1666
1669
  const from = dragAncestor.dragSnapshot;
@@ -1700,7 +1703,7 @@ function syncRelativeLayout(node) {
1700
1703
  }
1701
1704
  function resetTransformStyle(node) {
1702
1705
  const { visualElement } = node.options;
1703
- if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
1706
+ if (visualElement?.getProps().onBeforeLayoutMeasure) {
1704
1707
  visualElement.notify("BeforeLayoutMeasure");
1705
1708
  }
1706
1709
  node.resetTransform();
@@ -1734,7 +1737,7 @@ function mixBox(output, from, to, p) {
1734
1737
  mixAxis(output.y, from.y, to.y, p);
1735
1738
  }
1736
1739
  function hasOpacityCrossfade(node) {
1737
- return (node.animationValues && node.animationValues.opacityExit !== undefined);
1740
+ return node.animationValues?.opacityExit !== undefined;
1738
1741
  }
1739
1742
  const defaultLayoutTransition = {
1740
1743
  duration: 0.45,
@@ -1760,6 +1763,13 @@ function roundBox(box) {
1760
1763
  roundAxis(box.x);
1761
1764
  roundAxis(box.y);
1762
1765
  }
1766
+ /**
1767
+ * Align an axis to the start of another, keeping the length of a layout axis.
1768
+ * The length is read first, as output can be the layout axis itself.
1769
+ */
1770
+ function alignAxis(output, from, layout) {
1771
+ output.max = calcLength(layout) + (output.min = from.min);
1772
+ }
1763
1773
  function shouldAnimatePositionOnly(animationType, snapshot, layout) {
1764
1774
  return (animationType === "position" ||
1765
1775
  (animationType === "preserve-aspect" &&