motion-dom 12.31.2 → 12.32.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
@@ -2760,10 +2760,27 @@ function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyfr
2760
2760
  : finalKeyframe;
2761
2761
  }
2762
2762
 
2763
+ /**
2764
+ * If `transition` has `inherit: true`, shallow-merge it with
2765
+ * `parentTransition` (child keys win) and strip the `inherit` key.
2766
+ * Otherwise return `transition` unchanged.
2767
+ */
2768
+ function resolveTransition(transition, parentTransition) {
2769
+ if (transition?.inherit && parentTransition) {
2770
+ const { inherit: _, ...rest } = transition;
2771
+ return { ...parentTransition, ...rest };
2772
+ }
2773
+ return transition;
2774
+ }
2775
+
2763
2776
  function getValueTransition(transition, key) {
2764
- return (transition?.[key] ??
2777
+ const valueTransition = transition?.[key] ??
2765
2778
  transition?.["default"] ??
2766
- transition);
2779
+ transition;
2780
+ if (valueTransition !== transition) {
2781
+ return resolveTransition(valueTransition, transition);
2782
+ }
2783
+ return valueTransition;
2767
2784
  }
2768
2785
 
2769
2786
  /**
@@ -3310,7 +3327,11 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
3310
3327
  return shouldBlock;
3311
3328
  }
3312
3329
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
3313
- let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
3330
+ let { transition, transitionEnd, ...target } = targetAndTransition;
3331
+ const defaultTransition = visualElement.getDefaultTransition();
3332
+ transition = transition
3333
+ ? resolveTransition(transition, defaultTransition)
3334
+ : defaultTransition;
3314
3335
  const reduceMotion = transition?.reduceMotion;
3315
3336
  if (transitionOverride)
3316
3337
  transition = transitionOverride;
@@ -3367,11 +3388,15 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3367
3388
  }
3368
3389
  }
3369
3390
  if (transitionEnd) {
3370
- Promise.all(animations).then(() => {
3371
- frame.update(() => {
3372
- transitionEnd && setTarget(visualElement, transitionEnd);
3373
- });
3391
+ const applyTransitionEnd = () => frame.update(() => {
3392
+ transitionEnd && setTarget(visualElement, transitionEnd);
3374
3393
  });
3394
+ if (animations.length) {
3395
+ Promise.all(animations).then(applyTransitionEnd);
3396
+ }
3397
+ else {
3398
+ applyTransitionEnd();
3399
+ }
3375
3400
  }
3376
3401
  return animations;
3377
3402
  }
@@ -5475,6 +5500,11 @@ class VisualElement {
5475
5500
  * if any motion values need to be removed after props are updated.
5476
5501
  */
5477
5502
  this.prevMotionValues = {};
5503
+ /**
5504
+ * Track whether this element has been mounted before, to detect
5505
+ * remounts after Suspense unmount/remount cycles.
5506
+ */
5507
+ this.hasBeenMounted = false;
5478
5508
  /**
5479
5509
  * An object containing a SubscriptionManager for each active event.
5480
5510
  */
@@ -5538,6 +5568,17 @@ class VisualElement {
5538
5568
  }
5539
5569
  }
5540
5570
  mount(instance) {
5571
+ /**
5572
+ * If this element has been mounted before (e.g. after a Suspense
5573
+ * unmount/remount), reset motion values to their initial state
5574
+ * so animations replay correctly from initial → animate.
5575
+ */
5576
+ if (this.hasBeenMounted) {
5577
+ for (const key in this.initialValues) {
5578
+ this.values.get(key)?.jump(this.initialValues[key]);
5579
+ this.latestValues[key] = this.initialValues[key];
5580
+ }
5581
+ }
5541
5582
  this.current = instance;
5542
5583
  visualElementStore.set(instance, this);
5543
5584
  if (this.projection && !this.projection.instance) {
@@ -5573,6 +5614,7 @@ class VisualElement {
5573
5614
  this.shouldSkipAnimations = this.skipAnimationsConfig ?? false;
5574
5615
  this.parent?.addChild(this);
5575
5616
  this.update(this.props, this.presenceContext);
5617
+ this.hasBeenMounted = true;
5576
5618
  }
5577
5619
  unmount() {
5578
5620
  this.projection && this.projection.unmount();
@@ -9617,6 +9659,7 @@ exports.renderSVG = renderSVG;
9617
9659
  exports.resize = resize;
9618
9660
  exports.resolveElements = resolveElements;
9619
9661
  exports.resolveMotionValue = resolveMotionValue;
9662
+ exports.resolveTransition = resolveTransition;
9620
9663
  exports.resolveVariant = resolveVariant;
9621
9664
  exports.resolveVariantFromProps = resolveVariantFromProps;
9622
9665
  exports.rgbUnit = rgbUnit;