motion-dom 14.6.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 (85) hide show
  1. package/dist/cjs/index.js +564 -579
  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 +4 -4
  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 +40 -44
  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/utils/can-animate.mjs +1 -0
  21. package/dist/es/animation/utils/can-animate.mjs.map +1 -1
  22. package/dist/es/animation/utils/css-variables-conversion.mjs +2 -1
  23. package/dist/es/animation/utils/css-variables-conversion.mjs.map +1 -1
  24. package/dist/es/animation/utils/is-transition-defined.mjs +1 -0
  25. package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
  26. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +44 -21
  27. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  28. package/dist/es/animation/waapi/utils/accelerated-values.mjs +4 -1
  29. package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
  30. package/dist/es/effects/style/transform.mjs +4 -20
  31. package/dist/es/effects/style/transform.mjs.map +1 -1
  32. package/dist/es/gestures/drag/VisualElementDragControls.mjs +78 -61
  33. package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
  34. package/dist/es/gestures/pan/PanSession.mjs +28 -39
  35. package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
  36. package/dist/es/index.mjs +1 -1
  37. package/dist/es/layout/LayoutAnimationBuilder.mjs +2 -2
  38. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  39. package/dist/es/projection/animation/mix-values.mjs +3 -11
  40. package/dist/es/projection/animation/mix-values.mjs.map +1 -1
  41. package/dist/es/projection/geometry/delta-apply.mjs +10 -6
  42. package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
  43. package/dist/es/projection/geometry/delta-calc.mjs +2 -2
  44. package/dist/es/projection/geometry/delta-calc.mjs.map +1 -1
  45. package/dist/es/projection/geometry/delta-remove.mjs +2 -2
  46. package/dist/es/projection/geometry/delta-remove.mjs.map +1 -1
  47. package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
  48. package/dist/es/projection/node/HTMLProjectionNode.mjs.map +1 -1
  49. package/dist/es/projection/node/create-projection-node.mjs +138 -137
  50. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  51. package/dist/es/projection/styles/transform.mjs +12 -16
  52. package/dist/es/projection/styles/transform.mjs.map +1 -1
  53. package/dist/es/projection/utils/has-transform.mjs +16 -2
  54. package/dist/es/projection/utils/has-transform.mjs.map +1 -1
  55. package/dist/es/render/VisualElement.mjs +20 -37
  56. package/dist/es/render/VisualElement.mjs.map +1 -1
  57. package/dist/es/render/dom/parse-transform.mjs +6 -17
  58. package/dist/es/render/dom/parse-transform.mjs.map +1 -1
  59. package/dist/es/render/html/HTMLVisualElement.mjs +2 -1
  60. package/dist/es/render/html/HTMLVisualElement.mjs.map +1 -1
  61. package/dist/es/render/html/utils/build-transform.mjs +25 -29
  62. package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
  63. package/dist/es/render/utils/animation-state.mjs +57 -13
  64. package/dist/es/render/utils/animation-state.mjs.map +1 -1
  65. package/dist/es/utils/interpolate.mjs +2 -1
  66. package/dist/es/utils/interpolate.mjs.map +1 -1
  67. package/dist/es/utils/mix/color.mjs +2 -1
  68. package/dist/es/utils/mix/color.mjs.map +1 -1
  69. package/dist/es/utils/mix/complex.mjs +4 -4
  70. package/dist/es/utils/mix/complex.mjs.map +1 -1
  71. package/dist/es/utils/resolve-elements.mjs.map +1 -1
  72. package/dist/es/value/index.mjs +13 -34
  73. package/dist/es/value/index.mjs.map +1 -1
  74. package/dist/es/value/types/color/hex.mjs +13 -26
  75. package/dist/es/value/types/color/hex.mjs.map +1 -1
  76. package/dist/es/value/types/complex/index.mjs +1 -1
  77. package/dist/es/value/types/complex/index.mjs.map +1 -1
  78. package/dist/index.d.ts +72 -21
  79. package/dist/motion-dom.dev.js +548 -572
  80. package/dist/motion-dom.js +1 -1
  81. package/dist/size-rollup-motion-value.js +1 -1
  82. package/dist/size-rollup-motion-value.js.map +1 -1
  83. package/dist/size-rollup-style-effect.js +1 -1
  84. package/dist/size-rollup-style-effect.js.map +1 -1
  85. package/package.json +4 -3
@@ -26,7 +26,7 @@ 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';
@@ -36,7 +36,10 @@ const metrics = {
36
36
  calculatedTargetDeltas: 0,
37
37
  calculatedProjections: 0,
38
38
  };
39
- 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"];
40
43
  /**
41
44
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
42
45
  * which has a noticeable difference in spring animations
@@ -244,8 +247,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
244
247
  return this.eventHandlers.get(name).add(handler);
245
248
  }
246
249
  notifyListeners(name, ...args) {
247
- const subscriptionManager = this.eventHandlers.get(name);
248
- subscriptionManager && subscriptionManager.notify(...args);
250
+ this.eventHandlers.get(name)?.notify(...args);
249
251
  }
250
252
  hasListeners(name) {
251
253
  return this.eventHandlers.has(name);
@@ -263,7 +265,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
263
265
  visualElement.mount(instance);
264
266
  }
265
267
  this.root.nodes.add(this);
266
- this.parent && this.parent.children.add(this);
268
+ this.parent?.children.add(this);
267
269
  if (this.root.hasTreeAnimated && (layout || layoutId)) {
268
270
  this.isLayoutDirty = true;
269
271
  }
@@ -281,7 +283,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
281
283
  return;
282
284
  innerWidth = newInnerWidth;
283
285
  this.root.updateBlockedByResize = true;
284
- cancelDelay && cancelDelay();
286
+ cancelDelay?.();
285
287
  cancelDelay = delay(resizeUnblockUpdate, 250);
286
288
  if (globalProjectionState.hasAnimatedSinceResize) {
287
289
  globalProjectionState.hasAnimatedSinceResize = false;
@@ -372,9 +374,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
372
374
  if (!hasLayoutChanged) {
373
375
  finishAnimation(this);
374
376
  }
375
- if (this.isLead() && this.options.onExitComplete) {
376
- this.options.onExitComplete();
377
- }
377
+ this.isLead() && this.options.onExitComplete?.();
378
378
  }
379
379
  this.targetLayout = newLayout;
380
380
  });
@@ -382,9 +382,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
382
382
  unmount() {
383
383
  this.options.layoutId && this.willUpdate();
384
384
  this.root.nodes.remove(this);
385
- const stack = this.getStack();
386
- stack && stack.remove(this);
387
- this.parent && this.parent.children.delete(this);
385
+ this.getStack()?.remove(this);
386
+ this.parent?.children.delete(this);
388
387
  this.instance = undefined;
389
388
  this.eventHandlers.clear();
390
389
  this.hasLayoutListener = false;
@@ -405,7 +404,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
405
404
  if (this.isUpdateBlocked())
406
405
  return;
407
406
  this.isUpdating = true;
408
- this.nodes && this.nodes.forEach(resetSkewAndRotation);
407
+ this.nodes?.forEach(resetSkewAndRotation);
409
408
  this.animationId++;
410
409
  }
411
410
  getTransformTemplate() {
@@ -415,7 +414,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
415
414
  willUpdate(shouldNotifyListeners = true) {
416
415
  this.root.hasTreeAnimated = true;
417
416
  if (this.root.isUpdateBlocked()) {
418
- this.options.onExitComplete && this.options.onExitComplete();
417
+ this.options.onExitComplete?.();
419
418
  return;
420
419
  }
421
420
  /**
@@ -632,24 +631,23 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
632
631
  this.projectionDelta = undefined;
633
632
  this.notifyListeners("measure", this.layout.layoutBox);
634
633
  const { visualElement } = this.options;
635
- visualElement &&
636
- visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
634
+ visualElement?.notify("LayoutMeasure", this.layout.layoutBox, prevLayout?.layoutBox);
637
635
  }
638
636
  updateScroll(phase = "measure") {
639
- let needsMeasurement = Boolean(this.options.layoutScroll && this.instance);
640
- if (this.scroll &&
641
- this.scroll.animationId === this.root.animationId &&
642
- this.scroll.phase === phase) {
643
- needsMeasurement = false;
644
- }
645
- if (needsMeasurement && this.instance) {
646
- 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);
647
645
  this.scroll = {
648
- animationId: this.root.animationId,
646
+ animationId,
649
647
  phase,
650
648
  isRoot,
651
- offset: measureScroll(this.instance),
652
- wasRoot: this.scroll ? this.scroll.isRoot : isRoot,
649
+ offset: measureScroll(instance),
650
+ wasRoot: scroll ? scroll.isRoot : isRoot,
653
651
  };
654
652
  }
655
653
  }
@@ -739,10 +737,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
739
737
  }
740
738
  return boxWithoutScroll;
741
739
  }
742
- applyTransform(box, transformOnly = false, output, skipOwnTransform) {
740
+ applyTransform(box, transformOnly = false, output, skipOwnTransform, start = 0) {
743
741
  const withTransforms = output || createBox();
744
742
  copyBoxInto(withTransforms, box);
745
- for (let i = 0; i < this.path.length; i++) {
743
+ for (let i = start; i < this.path.length; i++) {
746
744
  const node = this.path[i];
747
745
  if (!transformOnly &&
748
746
  node.options.layoutScroll &&
@@ -914,8 +912,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
914
912
  this.attemptToResolveRelativeTarget = false;
915
913
  if (this.options.layoutAnchor !== false &&
916
914
  relativeParent &&
917
- Boolean(relativeParent.resumingFrom) ===
918
- 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)) &&
919
922
  !relativeParent.options.layoutScroll &&
920
923
  relativeParent.target &&
921
924
  this.animationProgress !== 1) {
@@ -995,7 +998,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
995
998
  * If this section of the tree isn't animating we can
996
999
  * delete our target sources for the following frame.
997
1000
  */
998
- this.isTreeAnimating = Boolean((this.parent && this.parent.isTreeAnimating) ||
1001
+ this.isTreeAnimating = Boolean(this.parent?.isTreeAnimating ||
999
1002
  this.currentAnimation ||
1000
1003
  this.pendingAnimation);
1001
1004
  if (!this.isTreeAnimating) {
@@ -1016,8 +1019,17 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1016
1019
  /**
1017
1020
  * Apply all the parent deltas to this box to produce the corrected box. This
1018
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.
1019
1028
  */
1020
- 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));
1021
1033
  /**
1022
1034
  * If this layer needs to perform scale correction but doesn't have a target,
1023
1035
  * use the layout as the target.
@@ -1084,8 +1096,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1084
1096
  scheduleRender(notifyAll = true) {
1085
1097
  this.options.visualElement?.scheduleRender();
1086
1098
  if (notifyAll) {
1087
- const stack = this.getStack();
1088
- stack && stack.scheduleRender();
1099
+ this.getStack()?.scheduleRender();
1089
1100
  }
1090
1101
  if (this.resumingFrom && !this.resumingFrom.instance) {
1091
1102
  this.resumingFrom = undefined;
@@ -1107,9 +1118,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1107
1118
  }
1108
1119
  this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
1109
1120
  const relativeLayout = createBox();
1110
- const snapshotSource = snapshot ? snapshot.source : undefined;
1111
- const layoutSource = this.layout ? this.layout.source : undefined;
1112
- const isSharedLayoutAnimation = snapshotSource !== layoutSource;
1121
+ const isSharedLayoutAnimation = snapshot?.source !== this.layout?.source;
1113
1122
  const stack = this.getStack();
1114
1123
  const isOnlyMember = !stack || stack.members.length <= 1;
1115
1124
  const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
@@ -1124,19 +1133,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1124
1133
  this.mixTargetDelta = (latest) => {
1125
1134
  const progress = latest / 1000;
1126
1135
  const point = interpolate?.(progress);
1136
+ mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
1137
+ mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
1127
1138
  if (point) {
1128
1139
  targetDelta.x.translate = point.x;
1129
- targetDelta.x.scale = mixNumber(delta.x.scale, 1, progress);
1130
- targetDelta.x.origin = delta.x.origin;
1131
- targetDelta.x.originPoint = delta.x.originPoint;
1132
1140
  targetDelta.y.translate = point.y;
1133
- targetDelta.y.scale = mixNumber(delta.y.scale, 1, progress);
1134
- targetDelta.y.origin = delta.y.origin;
1135
- targetDelta.y.originPoint = delta.y.originPoint;
1136
- }
1137
- else {
1138
- mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
1139
- mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
1140
1141
  }
1141
1142
  this.setTargetDelta(targetDelta);
1142
1143
  if (this.relativeTarget &&
@@ -1162,7 +1163,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1162
1163
  this.animationValues = mixedValues;
1163
1164
  mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
1164
1165
  }
1165
- if (point && point.rotate !== undefined) {
1166
+ if (point?.rotate !== undefined) {
1166
1167
  // Dedicated `pathRotation` channel, not `rotate`, so an
1167
1168
  // animating `rotate` is composed with, never clobbered.
1168
1169
  if (!this.animationValues)
@@ -1227,7 +1228,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1227
1228
  }
1228
1229
  finishAnimation() {
1229
1230
  if (this.currentAnimation) {
1230
- this.mixTargetDelta && this.mixTargetDelta(animationTarget);
1231
+ this.mixTargetDelta?.(animationTarget);
1231
1232
  this.currentAnimation.stop();
1232
1233
  }
1233
1234
  this.completeAnimation();
@@ -1247,13 +1248,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1247
1248
  this.layout &&
1248
1249
  layout &&
1249
1250
  shouldAnimatePositionOnly(this.options.animationType, this.layout.layoutBox, layout.layoutBox)) {
1251
+ const { layoutBox } = this.layout;
1252
+ const leadTarget = target;
1250
1253
  target = this.target || createBox();
1251
- const xLength = calcLength(this.layout.layoutBox.x);
1252
- target.x.min = lead.target.x.min;
1253
- target.x.max = target.x.min + xLength;
1254
- const yLength = calcLength(this.layout.layoutBox.y);
1255
- target.y.min = lead.target.y.min;
1256
- target.y.max = target.y.min + yLength;
1254
+ alignAxis(target.x, leadTarget.x, layoutBox.x);
1255
+ alignAxis(target.y, leadTarget.y, layoutBox.y);
1257
1256
  }
1258
1257
  copyBoxInto(targetWithTransforms, target);
1259
1258
  /**
@@ -1278,8 +1277,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1278
1277
  stack.add(node);
1279
1278
  const config = node.options.initialPromotionConfig;
1280
1279
  node.promote({
1281
- transition: config ? config.transition : undefined,
1282
- preserveFollowOpacity: config && config.shouldPreserveFollowOpacity
1280
+ transition: config?.transition,
1281
+ preserveFollowOpacity: config?.shouldPreserveFollowOpacity
1283
1282
  ? config.shouldPreserveFollowOpacity(node)
1284
1283
  : undefined,
1285
1284
  });
@@ -1302,9 +1301,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1302
1301
  return this.root.sharedNodes.get(layoutId);
1303
1302
  }
1304
1303
  promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
1305
- const stack = this.getStack();
1306
- if (stack)
1307
- stack.promote(this, preserveFollowOpacity);
1304
+ this.getStack()?.promote(this, preserveFollowOpacity);
1308
1305
  if (needsReset) {
1309
1306
  this.projectionDelta = undefined;
1310
1307
  this.needsReset = true;
@@ -1313,45 +1310,27 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1313
1310
  this.setOptions({ transition });
1314
1311
  }
1315
1312
  relegate() {
1316
- const stack = this.getStack();
1317
- if (stack) {
1318
- return stack.relegate(this);
1319
- }
1320
- else {
1321
- return false;
1322
- }
1313
+ return this.getStack()?.relegate(this) || false;
1323
1314
  }
1324
1315
  resetSkewAndRotation() {
1325
1316
  const { visualElement } = this.options;
1326
1317
  if (!visualElement)
1327
1318
  return;
1328
- // If there's no detected skew or rotation values, we can early return without a forced render.
1329
- let hasDistortingTransform = false;
1330
1319
  /**
1331
1320
  * An unrolled check for rotation values. Most elements don't have any rotation and
1332
- * 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.
1333
1323
  */
1334
1324
  const { latestValues } = visualElement;
1335
- if (latestValues.z ||
1336
- latestValues.rotate ||
1337
- latestValues.rotateX ||
1338
- latestValues.rotateY ||
1339
- latestValues.rotateZ ||
1340
- latestValues.skewX ||
1341
- latestValues.skewY) {
1342
- hasDistortingTransform = true;
1343
- }
1344
- // If there's no distorting values, we don't need to do any more.
1345
- if (!hasDistortingTransform)
1325
+ if (!hasDistortingTransform(latestValues))
1346
1326
  return;
1347
1327
  const resetValues = {};
1348
- if (latestValues.z) {
1349
- resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
1350
- }
1351
1328
  // Check the skew and rotate value of all axes and reset to 0
1352
- for (let i = 0; i < transformAxes.length; i++) {
1353
- resetDistortingTransform(`rotate${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
1354
- 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);
1355
1334
  }
1356
1335
  // Force a render of this element to apply the transform with all skews and rotations
1357
1336
  // set to 0.
@@ -1371,7 +1350,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1371
1350
  styleProp) {
1372
1351
  if (!this.instance || this.isSVG)
1373
1352
  return;
1374
- 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) {
1375
1360
  targetStyle.visibility = "hidden";
1376
1361
  return;
1377
1362
  }
@@ -1387,9 +1372,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1387
1372
  : "none";
1388
1373
  return;
1389
1374
  }
1390
- const lead = this.getLead();
1391
1375
  if (!this.projectionDelta || !this.layout || !lead.target) {
1392
- if (this.options.layoutId) {
1376
+ if (this.options.layoutId || this.needsShow) {
1377
+ this.needsShow = false;
1378
+ targetStyle.visibility = "";
1393
1379
  targetStyle.opacity =
1394
1380
  this.latestValues.opacity !== undefined
1395
1381
  ? this.latestValues.opacity
@@ -1523,52 +1509,49 @@ function notifyLayoutUpdate(node) {
1523
1509
  const isShared = snapshot.source !== node.layout.source;
1524
1510
  // TODO Maybe we want to also resize the layout snapshot so we don't trigger
1525
1511
  // animations for instance if layout="size" and an element has only changed position
1526
- if (animationType === "size") {
1527
- eachAxis((axis) => {
1528
- const axisSnapshot = isShared
1529
- ? snapshot.measuredBox[axis]
1530
- : snapshot.layoutBox[axis];
1531
- const length = calcLength(axisSnapshot);
1532
- axisSnapshot.min = layout[axis].min;
1533
- axisSnapshot.max = axisSnapshot.min + length;
1534
- });
1535
- }
1536
- else if (animationType === "x" || animationType === "y") {
1537
- const snapAxis = animationType === "x" ? "y" : "x";
1538
- copyAxisInto(isShared
1539
- ? snapshot.measuredBox[snapAxis]
1540
- : snapshot.layoutBox[snapAxis], layout[snapAxis]);
1541
- }
1542
- else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
1543
- eachAxis((axis) => {
1544
- const axisSnapshot = isShared
1545
- ? snapshot.measuredBox[axis]
1546
- : snapshot.layoutBox[axis];
1547
- const length = calcLength(layout[axis]);
1548
- axisSnapshot.max = axisSnapshot.min + length;
1549
- /**
1550
- * Ensure relative target gets resized and rerendererd
1551
- */
1552
- if (node.relativeTarget && !node.currentAnimation) {
1553
- node.isProjectionDirty = true;
1554
- node.relativeTarget[axis].max =
1555
- node.relativeTarget[axis].min + length;
1556
- }
1557
- });
1558
- }
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);
1559
1541
  const layoutDelta = createDelta();
1560
1542
  calcBoxDelta(layoutDelta, layout, snapshot.layoutBox);
1561
1543
  const visualDelta = createDelta();
1562
- if (isShared) {
1563
- calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measuredBox);
1564
- }
1565
- else {
1566
- calcBoxDelta(visualDelta, layout, snapshot.layoutBox);
1567
- }
1544
+ calcBoxDelta(visualDelta, isShared ? node.applyTransform(measuredLayout, true) : layout, snapshotBox);
1568
1545
  const hasLayoutChanged = !isDeltaZero(layoutDelta);
1569
1546
  let hasRelativeLayoutChanged = false;
1570
- if (!node.resumeFrom) {
1571
- 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))) {
1572
1555
  /**
1573
1556
  * If the relativeParent is itself resuming from a different element then
1574
1557
  * the relative snapshot is not relavent
@@ -1577,10 +1560,22 @@ function notifyLayoutUpdate(node) {
1577
1560
  const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
1578
1561
  if (parentSnapshot && parentLayout) {
1579
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
+ */
1580
1568
  const relativeSnapshot = createBox();
1581
- 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);
1582
1572
  const relativeLayout = createBox();
1583
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);
1584
1579
  if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
1585
1580
  hasRelativeLayoutChanged = true;
1586
1581
  }
@@ -1602,8 +1597,7 @@ function notifyLayoutUpdate(node) {
1602
1597
  });
1603
1598
  }
1604
1599
  else if (node.isLead()) {
1605
- const { onExitComplete } = node.options;
1606
- onExitComplete && onExitComplete();
1600
+ node.options.onExitComplete?.();
1607
1601
  }
1608
1602
  /**
1609
1603
  * Clearing transition
@@ -1709,7 +1703,7 @@ function syncRelativeLayout(node) {
1709
1703
  }
1710
1704
  function resetTransformStyle(node) {
1711
1705
  const { visualElement } = node.options;
1712
- if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
1706
+ if (visualElement?.getProps().onBeforeLayoutMeasure) {
1713
1707
  visualElement.notify("BeforeLayoutMeasure");
1714
1708
  }
1715
1709
  node.resetTransform();
@@ -1743,7 +1737,7 @@ function mixBox(output, from, to, p) {
1743
1737
  mixAxis(output.y, from.y, to.y, p);
1744
1738
  }
1745
1739
  function hasOpacityCrossfade(node) {
1746
- return (node.animationValues && node.animationValues.opacityExit !== undefined);
1740
+ return node.animationValues?.opacityExit !== undefined;
1747
1741
  }
1748
1742
  const defaultLayoutTransition = {
1749
1743
  duration: 0.45,
@@ -1769,6 +1763,13 @@ function roundBox(box) {
1769
1763
  roundAxis(box.x);
1770
1764
  roundAxis(box.y);
1771
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
+ }
1772
1773
  function shouldAnimatePositionOnly(animationType, snapshot, layout) {
1773
1774
  return (animationType === "position" ||
1774
1775
  (animationType === "preserve-aspect" &&