motion-dom 12.37.0 → 12.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -3057,7 +3057,8 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
3057
3057
  }
3058
3058
  if (motionUtils.MotionGlobalConfig.instantAnimations ||
3059
3059
  motionUtils.MotionGlobalConfig.skipAnimations ||
3060
- element?.shouldSkipAnimations) {
3060
+ element?.shouldSkipAnimations ||
3061
+ valueTransition.skipAnimations) {
3061
3062
  shouldSkip = true;
3062
3063
  makeAnimationInstant(options);
3063
3064
  options.delay = 0;
@@ -3536,6 +3537,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3536
3537
  ? resolveTransition(transition, defaultTransition)
3537
3538
  : defaultTransition;
3538
3539
  const reduceMotion = transition?.reduceMotion;
3540
+ const skipAnimations = transition?.skipAnimations;
3539
3541
  if (transitionOverride)
3540
3542
  transition = transitionOverride;
3541
3543
  const animations = [];
@@ -3554,15 +3556,20 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3554
3556
  delay,
3555
3557
  ...getValueTransition(transition || {}, key),
3556
3558
  };
3559
+ if (skipAnimations)
3560
+ valueTransition.skipAnimations = true;
3557
3561
  /**
3558
3562
  * If the value is already at the defined target, skip the animation.
3563
+ * We still re-assert the value via frame.update to take precedence
3564
+ * over any stale transitionEnd callbacks from previous animations.
3559
3565
  */
3560
3566
  const currentValue = value.get();
3561
3567
  if (currentValue !== undefined &&
3562
- !value.isAnimating &&
3568
+ !value.isAnimating() &&
3563
3569
  !Array.isArray(valueTarget) &&
3564
3570
  valueTarget === currentValue &&
3565
3571
  !valueTransition.velocity) {
3572
+ frame.update(() => value.set(valueTarget));
3566
3573
  continue;
3567
3574
  }
3568
3575
  /**
@@ -5915,8 +5922,8 @@ class VisualElement {
5915
5922
  removeOnChange();
5916
5923
  if (removeSyncCheck)
5917
5924
  removeSyncCheck();
5918
- if (value.owner)
5919
- value.stop();
5925
+ // Defer to MotionValue.on("change") auto-stop so React 19 remounts
5926
+ // can resubscribe before the animation is cancelled (#3315).
5920
5927
  });
5921
5928
  }
5922
5929
  sortNodePosition(other) {
@@ -7160,7 +7167,8 @@ function createAnimationState(visualElement) {
7160
7167
  */
7161
7168
  let valueHasChanged = false;
7162
7169
  if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
7163
- valueHasChanged = !shallowCompare(next, prev);
7170
+ valueHasChanged =
7171
+ !shallowCompare(next, prev) || variantDidChange;
7164
7172
  }
7165
7173
  else {
7166
7174
  valueHasChanged = next !== prev;
@@ -7393,21 +7401,27 @@ function calcBoxDelta(delta, source, target, origin) {
7393
7401
  calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : undefined);
7394
7402
  calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : undefined);
7395
7403
  }
7396
- function calcRelativeAxis(target, relative, parent) {
7397
- target.min = parent.min + relative.min;
7404
+ function calcRelativeAxis(target, relative, parent, anchor = 0) {
7405
+ const anchorPoint = anchor
7406
+ ? mixNumber$1(parent.min, parent.max, anchor)
7407
+ : parent.min;
7408
+ target.min = anchorPoint + relative.min;
7398
7409
  target.max = target.min + calcLength(relative);
7399
7410
  }
7400
- function calcRelativeBox(target, relative, parent) {
7401
- calcRelativeAxis(target.x, relative.x, parent.x);
7402
- calcRelativeAxis(target.y, relative.y, parent.y);
7411
+ function calcRelativeBox(target, relative, parent, anchor) {
7412
+ calcRelativeAxis(target.x, relative.x, parent.x, anchor?.x);
7413
+ calcRelativeAxis(target.y, relative.y, parent.y, anchor?.y);
7403
7414
  }
7404
- function calcRelativeAxisPosition(target, layout, parent) {
7405
- target.min = layout.min - parent.min;
7415
+ function calcRelativeAxisPosition(target, layout, parent, anchor = 0) {
7416
+ const anchorPoint = anchor
7417
+ ? mixNumber$1(parent.min, parent.max, anchor)
7418
+ : parent.min;
7419
+ target.min = layout.min - anchorPoint;
7406
7420
  target.max = target.min + calcLength(layout);
7407
7421
  }
7408
- function calcRelativePosition(target, layout, parent) {
7409
- calcRelativeAxisPosition(target.x, layout.x, parent.x);
7410
- calcRelativeAxisPosition(target.y, layout.y, parent.y);
7422
+ function calcRelativePosition(target, layout, parent, anchor) {
7423
+ calcRelativeAxisPosition(target.x, layout.x, parent.x, anchor?.x);
7424
+ calcRelativeAxisPosition(target.y, layout.y, parent.y, anchor?.y);
7411
7425
  }
7412
7426
 
7413
7427
  /**
@@ -8187,8 +8201,18 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8187
8201
  // but should still clean up the measurements so that the next
8188
8202
  // snapshot could be taken correctly.
8189
8203
  if (updateWasBlocked) {
8204
+ const wasBlockedByResize = this.updateBlockedByResize;
8190
8205
  this.unblockUpdate();
8206
+ this.updateBlockedByResize = false;
8191
8207
  this.clearAllSnapshots();
8208
+ /**
8209
+ * When blocked by resize, still measure layouts so
8210
+ * callbacks like onLayoutMeasure fire (e.g. Reorder).
8211
+ * Skip notifyLayoutUpdate to prevent animations.
8212
+ */
8213
+ if (wasBlockedByResize) {
8214
+ this.nodes.forEach(forceLayoutMeasure);
8215
+ }
8192
8216
  this.nodes.forEach(clearMeasurements);
8193
8217
  return;
8194
8218
  }
@@ -8538,7 +8562,9 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8538
8562
  * even if no animation has started.
8539
8563
  */
8540
8564
  if (!this.targetDelta && !this.relativeTarget) {
8541
- if (relativeParent && relativeParent.layout) {
8565
+ if (this.options.layoutAnchor !== false &&
8566
+ relativeParent &&
8567
+ relativeParent.layout) {
8542
8568
  this.createRelativeTarget(relativeParent, this.layout.layoutBox, relativeParent.layout.layoutBox);
8543
8569
  }
8544
8570
  else {
@@ -8566,7 +8592,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8566
8592
  this.relativeParent &&
8567
8593
  this.relativeParent.target) {
8568
8594
  this.forceRelativeParentToResolveTarget();
8569
- calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target);
8595
+ calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target, this.options.layoutAnchor || undefined);
8570
8596
  /**
8571
8597
  * If we've only got a targetDelta, resolve it into a target
8572
8598
  */
@@ -8591,7 +8617,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8591
8617
  */
8592
8618
  if (this.attemptToResolveRelativeTarget) {
8593
8619
  this.attemptToResolveRelativeTarget = false;
8594
- if (relativeParent &&
8620
+ if (this.options.layoutAnchor !== false &&
8621
+ relativeParent &&
8595
8622
  Boolean(relativeParent.resumingFrom) ===
8596
8623
  Boolean(this.resumingFrom) &&
8597
8624
  !relativeParent.options.layoutScroll &&
@@ -8635,7 +8662,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8635
8662
  this.forceRelativeParentToResolveTarget();
8636
8663
  this.relativeTarget = createBox();
8637
8664
  this.relativeTargetOrigin = createBox();
8638
- calcRelativePosition(this.relativeTargetOrigin, layout, parentLayout);
8665
+ calcRelativePosition(this.relativeTargetOrigin, layout, parentLayout, this.options.layoutAnchor || undefined);
8639
8666
  copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
8640
8667
  }
8641
8668
  removeRelativeTarget() {
@@ -8807,7 +8834,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8807
8834
  this.layout &&
8808
8835
  this.relativeParent &&
8809
8836
  this.relativeParent.layout) {
8810
- calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox);
8837
+ calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox, this.options.layoutAnchor || undefined);
8811
8838
  mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
8812
8839
  /**
8813
8840
  * If this is an unchanged relative target we can consider the
@@ -9226,10 +9253,11 @@ function notifyLayoutUpdate(node) {
9226
9253
  if (relativeParent && !relativeParent.resumeFrom) {
9227
9254
  const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
9228
9255
  if (parentSnapshot && parentLayout) {
9256
+ const anchor = node.options.layoutAnchor || undefined;
9229
9257
  const relativeSnapshot = createBox();
9230
- calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox);
9258
+ calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
9231
9259
  const relativeLayout = createBox();
9232
- calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox);
9260
+ calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox, anchor);
9233
9261
  if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
9234
9262
  hasRelativeLayoutChanged = true;
9235
9263
  }
@@ -9301,6 +9329,10 @@ function clearSnapshot(node) {
9301
9329
  function clearMeasurements(node) {
9302
9330
  node.clearMeasurements();
9303
9331
  }
9332
+ function forceLayoutMeasure(node) {
9333
+ node.isLayoutDirty = true;
9334
+ node.updateLayout();
9335
+ }
9304
9336
  function clearIsLayoutDirty(node) {
9305
9337
  node.isLayoutDirty = false;
9306
9338
  }