motion-dom 12.27.0-alpha.6 → 12.27.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
@@ -2660,6 +2660,20 @@ function getAnimationMap(element) {
2660
2660
  return map;
2661
2661
  }
2662
2662
 
2663
+ function calcChildStagger(children, child, delayChildren, staggerChildren = 0, staggerDirection = 1) {
2664
+ const index = Array.from(children)
2665
+ .sort((a, b) => a.sortNodePosition(b))
2666
+ .indexOf(child);
2667
+ const numChildren = children.size;
2668
+ const maxStaggerDuration = (numChildren - 1) * staggerChildren;
2669
+ const delayIsFunction = typeof delayChildren === "function";
2670
+ return delayIsFunction
2671
+ ? delayChildren(index, numChildren)
2672
+ : staggerDirection === 1
2673
+ ? index * staggerChildren
2674
+ : maxStaggerDuration - index * staggerChildren;
2675
+ }
2676
+
2663
2677
  /**
2664
2678
  * Parse Framer's special CSS variable format into a CSS token and a fallback.
2665
2679
  *
@@ -2697,12 +2711,6 @@ function getVariableValue(current, element, depth = 1) {
2697
2711
  : fallback;
2698
2712
  }
2699
2713
 
2700
- function getValueTransition(transition, key) {
2701
- return (transition?.[key] ??
2702
- transition?.["default"] ??
2703
- transition);
2704
- }
2705
-
2706
2714
  const underDampedSpring = {
2707
2715
  type: "spring",
2708
2716
  stiffness: 500,
@@ -2740,15 +2748,6 @@ const getDefaultTransition = (valueKey, { keyframes }) => {
2740
2748
  return ease;
2741
2749
  };
2742
2750
 
2743
- /**
2744
- * Decide whether a transition is defined on a given Transition.
2745
- * This filters out orchestration options and returns true
2746
- * if any options are left.
2747
- */
2748
- function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, elapsed, ...transition }) {
2749
- return !!Object.keys(transition).length;
2750
- }
2751
-
2752
2751
  const isNotNull = (value) => value !== null;
2753
2752
  function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
2754
2753
  const resolvedKeyframes = keyframes.filter(isNotNull);
@@ -2760,18 +2759,19 @@ function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyfr
2760
2759
  : finalKeyframe;
2761
2760
  }
2762
2761
 
2763
- function calcChildStagger(children, child, delayChildren, staggerChildren = 0, staggerDirection = 1) {
2764
- const index = Array.from(children)
2765
- .sort((a, b) => a.sortNodePosition(b))
2766
- .indexOf(child);
2767
- const numChildren = children.size;
2768
- const maxStaggerDuration = (numChildren - 1) * staggerChildren;
2769
- const delayIsFunction = typeof delayChildren === "function";
2770
- return delayIsFunction
2771
- ? delayChildren(index, numChildren)
2772
- : staggerDirection === 1
2773
- ? index * staggerChildren
2774
- : maxStaggerDuration - index * staggerChildren;
2762
+ function getValueTransition(transition, key) {
2763
+ return (transition?.[key] ??
2764
+ transition?.["default"] ??
2765
+ transition);
2766
+ }
2767
+
2768
+ /**
2769
+ * Decide whether a transition is defined on a given Transition.
2770
+ * This filters out orchestration options and returns true
2771
+ * if any options are left.
2772
+ */
2773
+ function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, elapsed, ...transition }) {
2774
+ return !!Object.keys(transition).length;
2775
2775
  }
2776
2776
 
2777
2777
  const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
@@ -2865,6 +2865,46 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
2865
2865
  : new AsyncMotionValueAnimation(options);
2866
2866
  };
2867
2867
 
2868
+ function getValueState(visualElement) {
2869
+ const state = [{}, {}];
2870
+ visualElement?.values.forEach((value, key) => {
2871
+ state[0][key] = value.get();
2872
+ state[1][key] = value.getVelocity();
2873
+ });
2874
+ return state;
2875
+ }
2876
+ function resolveVariantFromProps(props, definition, custom, visualElement) {
2877
+ /**
2878
+ * If the variant definition is a function, resolve.
2879
+ */
2880
+ if (typeof definition === "function") {
2881
+ const [current, velocity] = getValueState(visualElement);
2882
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
2883
+ }
2884
+ /**
2885
+ * If the variant definition is a variant label, or
2886
+ * the function returned a variant label, resolve.
2887
+ */
2888
+ if (typeof definition === "string") {
2889
+ definition = props.variants && props.variants[definition];
2890
+ }
2891
+ /**
2892
+ * At this point we've resolved both functions and variant labels,
2893
+ * but the resolved variant label might itself have been a function.
2894
+ * If so, resolve. This can only have returned a valid target object.
2895
+ */
2896
+ if (typeof definition === "function") {
2897
+ const [current, velocity] = getValueState(visualElement);
2898
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
2899
+ }
2900
+ return definition;
2901
+ }
2902
+
2903
+ function resolveVariant(visualElement, definition, custom) {
2904
+ const props = visualElement.getProps();
2905
+ return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
2906
+ }
2907
+
2868
2908
  const positionalKeys = new Set([
2869
2909
  "width",
2870
2910
  "height",
@@ -3193,46 +3233,6 @@ function motionValue(init, options) {
3193
3233
  return new MotionValue(init, options);
3194
3234
  }
3195
3235
 
3196
- function getValueState(visualElement) {
3197
- const state = [{}, {}];
3198
- visualElement?.values.forEach((value, key) => {
3199
- state[0][key] = value.get();
3200
- state[1][key] = value.getVelocity();
3201
- });
3202
- return state;
3203
- }
3204
- function resolveVariantFromProps(props, definition, custom, visualElement) {
3205
- /**
3206
- * If the variant definition is a function, resolve.
3207
- */
3208
- if (typeof definition === "function") {
3209
- const [current, velocity] = getValueState(visualElement);
3210
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3211
- }
3212
- /**
3213
- * If the variant definition is a variant label, or
3214
- * the function returned a variant label, resolve.
3215
- */
3216
- if (typeof definition === "string") {
3217
- definition = props.variants && props.variants[definition];
3218
- }
3219
- /**
3220
- * At this point we've resolved both functions and variant labels,
3221
- * but the resolved variant label might itself have been a function.
3222
- * If so, resolve. This can only have returned a valid target object.
3223
- */
3224
- if (typeof definition === "function") {
3225
- const [current, velocity] = getValueState(visualElement);
3226
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3227
- }
3228
- return definition;
3229
- }
3230
-
3231
- function resolveVariant(visualElement, definition, custom) {
3232
- const props = visualElement.getProps();
3233
- return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
3234
- }
3235
-
3236
3236
  const isKeyframesTarget = (v) => {
3237
3237
  return Array.isArray(v);
3238
3238
  };
@@ -5763,19 +5763,6 @@ class VisualElement {
5763
5763
  }
5764
5764
  }
5765
5765
 
5766
- /**
5767
- * Feature base class for extending VisualElement functionality.
5768
- * Features are plugins that can be mounted/unmounted to add behavior
5769
- * like gestures, animations, or layout tracking.
5770
- */
5771
- class Feature {
5772
- constructor(node) {
5773
- this.isMounted = false;
5774
- this.node = node;
5775
- }
5776
- update() { }
5777
- }
5778
-
5779
5766
  class DOMVisualElement extends VisualElement {
5780
5767
  constructor() {
5781
5768
  super(...arguments);
@@ -5813,6 +5800,19 @@ class DOMVisualElement extends VisualElement {
5813
5800
  }
5814
5801
  }
5815
5802
 
5803
+ /**
5804
+ * Feature base class for extending VisualElement functionality.
5805
+ * Features are plugins that can be mounted/unmounted to add behavior
5806
+ * like gestures, animations, or layout tracking.
5807
+ */
5808
+ class Feature {
5809
+ constructor(node) {
5810
+ this.isMounted = false;
5811
+ this.node = node;
5812
+ }
5813
+ update() { }
5814
+ }
5815
+
5816
5816
  /**
5817
5817
  * Bounding boxes tend to be defined as top, left, right, bottom. For various operations
5818
5818
  * it's easier to consider each axis individually. This function returns a bounding box
@@ -6281,6 +6281,43 @@ class HTMLVisualElement extends DOMVisualElement {
6281
6281
  }
6282
6282
  }
6283
6283
 
6284
+ function isObjectKey(key, object) {
6285
+ return key in object;
6286
+ }
6287
+ class ObjectVisualElement extends VisualElement {
6288
+ constructor() {
6289
+ super(...arguments);
6290
+ this.type = "object";
6291
+ }
6292
+ readValueFromInstance(instance, key) {
6293
+ if (isObjectKey(key, instance)) {
6294
+ const value = instance[key];
6295
+ if (typeof value === "string" || typeof value === "number") {
6296
+ return value;
6297
+ }
6298
+ }
6299
+ return undefined;
6300
+ }
6301
+ getBaseTargetFromProps() {
6302
+ return undefined;
6303
+ }
6304
+ removeValueFromRenderState(key, renderState) {
6305
+ delete renderState.output[key];
6306
+ }
6307
+ measureInstanceViewportBox() {
6308
+ return createBox();
6309
+ }
6310
+ build(renderState, latestValues) {
6311
+ Object.assign(renderState.output, latestValues);
6312
+ }
6313
+ renderInstance(instance, { output }) {
6314
+ Object.assign(instance, output);
6315
+ }
6316
+ sortInstanceNodePosition() {
6317
+ return 0;
6318
+ }
6319
+ }
6320
+
6284
6321
  const dashKeys = {
6285
6322
  offset: "stroke-dashoffset",
6286
6323
  array: "stroke-dasharray",
@@ -6463,43 +6500,6 @@ class SVGVisualElement extends DOMVisualElement {
6463
6500
  }
6464
6501
  }
6465
6502
 
6466
- function isObjectKey(key, object) {
6467
- return key in object;
6468
- }
6469
- class ObjectVisualElement extends VisualElement {
6470
- constructor() {
6471
- super(...arguments);
6472
- this.type = "object";
6473
- }
6474
- readValueFromInstance(instance, key) {
6475
- if (isObjectKey(key, instance)) {
6476
- const value = instance[key];
6477
- if (typeof value === "string" || typeof value === "number") {
6478
- return value;
6479
- }
6480
- }
6481
- return undefined;
6482
- }
6483
- getBaseTargetFromProps() {
6484
- return undefined;
6485
- }
6486
- removeValueFromRenderState(key, renderState) {
6487
- delete renderState.output[key];
6488
- }
6489
- measureInstanceViewportBox() {
6490
- return createBox();
6491
- }
6492
- build(renderState, latestValues) {
6493
- Object.assign(renderState.output, latestValues);
6494
- }
6495
- renderInstance(instance, { output }) {
6496
- Object.assign(instance, output);
6497
- }
6498
- sortInstanceNodePosition() {
6499
- return 0;
6500
- }
6501
- }
6502
-
6503
6503
  const numVariantProps = variantProps.length;
6504
6504
  /**
6505
6505
  * Get variant context from a visual element's parent chain.
@@ -6894,6 +6894,36 @@ function createState() {
6894
6894
  };
6895
6895
  }
6896
6896
 
6897
+ /**
6898
+ * Reset an axis to the provided origin box.
6899
+ *
6900
+ * This is a mutative operation.
6901
+ */
6902
+ function copyAxisInto(axis, originAxis) {
6903
+ axis.min = originAxis.min;
6904
+ axis.max = originAxis.max;
6905
+ }
6906
+ /**
6907
+ * Reset a box to the provided origin box.
6908
+ *
6909
+ * This is a mutative operation.
6910
+ */
6911
+ function copyBoxInto(box, originBox) {
6912
+ copyAxisInto(box.x, originBox.x);
6913
+ copyAxisInto(box.y, originBox.y);
6914
+ }
6915
+ /**
6916
+ * Reset a delta to the provided origin box.
6917
+ *
6918
+ * This is a mutative operation.
6919
+ */
6920
+ function copyAxisDeltaInto(delta, originDelta) {
6921
+ delta.translate = originDelta.translate;
6922
+ delta.scale = originDelta.scale;
6923
+ delta.originPoint = originDelta.originPoint;
6924
+ delta.origin = originDelta.origin;
6925
+ }
6926
+
6897
6927
  const SCALE_PRECISION = 0.0001;
6898
6928
  const SCALE_MIN = 1 - SCALE_PRECISION;
6899
6929
  const SCALE_MAX = 1 + SCALE_PRECISION;
@@ -6992,36 +7022,6 @@ function removeBoxTransforms(box, transforms, originBox, sourceBox) {
6992
7022
  removeAxisTransforms(box.y, transforms, yKeys, originBox ? originBox.y : undefined, sourceBox ? sourceBox.y : undefined);
6993
7023
  }
6994
7024
 
6995
- /**
6996
- * Reset an axis to the provided origin box.
6997
- *
6998
- * This is a mutative operation.
6999
- */
7000
- function copyAxisInto(axis, originAxis) {
7001
- axis.min = originAxis.min;
7002
- axis.max = originAxis.max;
7003
- }
7004
- /**
7005
- * Reset a box to the provided origin box.
7006
- *
7007
- * This is a mutative operation.
7008
- */
7009
- function copyBoxInto(box, originBox) {
7010
- copyAxisInto(box.x, originBox.x);
7011
- copyAxisInto(box.y, originBox.y);
7012
- }
7013
- /**
7014
- * Reset a delta to the provided origin box.
7015
- *
7016
- * This is a mutative operation.
7017
- */
7018
- function copyAxisDeltaInto(delta, originDelta) {
7019
- delta.translate = originDelta.translate;
7020
- delta.scale = originDelta.scale;
7021
- delta.originPoint = originDelta.originPoint;
7022
- delta.origin = originDelta.origin;
7023
- }
7024
-
7025
7025
  function isAxisDeltaZero(delta) {
7026
7026
  return delta.translate === 0 && delta.scale === 1;
7027
7027
  }
@@ -7163,23 +7163,10 @@ function compress(min, max, easing) {
7163
7163
  };
7164
7164
  }
7165
7165
 
7166
- /**
7167
- * Timeout defined in ms
7168
- */
7169
- function delay(callback, timeout) {
7170
- const start = time.now();
7171
- const checkElapsed = ({ timestamp }) => {
7172
- const elapsed = timestamp - start;
7173
- if (elapsed >= timeout) {
7174
- cancelFrame(checkElapsed);
7175
- callback(elapsed - timeout);
7176
- }
7177
- };
7178
- frame.setup(checkElapsed, true);
7179
- return () => cancelFrame(checkElapsed);
7180
- }
7181
- function delayInSeconds(callback, timeout) {
7182
- return delay(callback, motionUtils.secondsToMilliseconds(timeout));
7166
+ function animateSingleValue(value, keyframes, options) {
7167
+ const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
7168
+ motionValue$1.start(animateMotionValue("", motionValue$1, keyframes, options));
7169
+ return motionValue$1.animation;
7183
7170
  }
7184
7171
 
7185
7172
  function addDomEvent(target, eventName, handler, options = { passive: true }) {
@@ -7187,19 +7174,6 @@ function addDomEvent(target, eventName, handler, options = { passive: true }) {
7187
7174
  return () => target.removeEventListener(eventName, handler);
7188
7175
  }
7189
7176
 
7190
- /**
7191
- * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
7192
- */
7193
- function resolveMotionValue(value) {
7194
- return isMotionValue(value) ? value.get() : value;
7195
- }
7196
-
7197
- function animateSingleValue(value, keyframes, options) {
7198
- const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
7199
- motionValue$1.start(animateMotionValue("", motionValue$1, keyframes, options));
7200
- return motionValue$1.animation;
7201
- }
7202
-
7203
7177
  const compareByDepth = (a, b) => a.depth - b.depth;
7204
7178
 
7205
7179
  class FlatTree {
@@ -7222,6 +7196,32 @@ class FlatTree {
7222
7196
  }
7223
7197
  }
7224
7198
 
7199
+ /**
7200
+ * Timeout defined in ms
7201
+ */
7202
+ function delay(callback, timeout) {
7203
+ const start = time.now();
7204
+ const checkElapsed = ({ timestamp }) => {
7205
+ const elapsed = timestamp - start;
7206
+ if (elapsed >= timeout) {
7207
+ cancelFrame(checkElapsed);
7208
+ callback(elapsed - timeout);
7209
+ }
7210
+ };
7211
+ frame.setup(checkElapsed, true);
7212
+ return () => cancelFrame(checkElapsed);
7213
+ }
7214
+ function delayInSeconds(callback, timeout) {
7215
+ return delay(callback, motionUtils.secondsToMilliseconds(timeout));
7216
+ }
7217
+
7218
+ /**
7219
+ * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
7220
+ */
7221
+ function resolveMotionValue(value) {
7222
+ return isMotionValue(value) ? value.get() : value;
7223
+ }
7224
+
7225
7225
  class NodeStack {
7226
7226
  constructor() {
7227
7227
  this.members = [];
@@ -7599,13 +7599,6 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
7599
7599
  this.relativeTarget = undefined;
7600
7600
  return;
7601
7601
  }
7602
- /**
7603
- * Check if this is a follow element in a crossfade (exiting element
7604
- * whose lead has resumeFrom pointing to it). These elements should
7605
- * NOT create their own animation - they get the lead's animation via
7606
- * resumingFrom.currentAnimation in startAnimation().
7607
- */
7608
- const isFollowInCrossfade = this.isPresent === false && !this.isLead();
7609
7602
  // TODO: Check here if an animation exists
7610
7603
  const layoutTransition = this.options.transition ||
7611
7604
  visualElement.getDefaultTransition() ||
@@ -7629,51 +7622,43 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
7629
7622
  * relative to its parent has indeed changed. So here we check for that.
7630
7623
  */
7631
7624
  const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeLayoutChanged;
7632
- /**
7633
- * Skip animation handling for follow elements in a crossfade.
7634
- * These elements get the lead's animation via resumingFrom.currentAnimation
7635
- * in startAnimation(), so they shouldn't create their own animation.
7636
- * They also shouldn't call finishAnimation(), which would reset their state.
7637
- */
7638
- if (!isFollowInCrossfade) {
7639
- if (this.options.layoutRoot ||
7640
- this.resumeFrom ||
7641
- hasOnlyRelativeTargetChanged ||
7642
- (hasLayoutChanged &&
7643
- (hasTargetChanged || !this.currentAnimation))) {
7644
- if (this.resumeFrom) {
7645
- this.resumingFrom = this.resumeFrom;
7646
- this.resumingFrom.resumingFrom = undefined;
7647
- }
7648
- const animationOptions = {
7649
- ...getValueTransition(layoutTransition, "layout"),
7650
- onPlay: onLayoutAnimationStart,
7651
- onComplete: onLayoutAnimationComplete,
7652
- };
7653
- if (visualElement.shouldReduceMotion ||
7654
- this.options.layoutRoot) {
7655
- animationOptions.delay = 0;
7656
- animationOptions.type = false;
7657
- }
7658
- this.startAnimation(animationOptions);
7659
- /**
7660
- * Set animation origin after starting animation to avoid layout jump
7661
- * caused by stopping previous layout animation
7662
- */
7663
- this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
7625
+ if (this.options.layoutRoot ||
7626
+ this.resumeFrom ||
7627
+ hasOnlyRelativeTargetChanged ||
7628
+ (hasLayoutChanged &&
7629
+ (hasTargetChanged || !this.currentAnimation))) {
7630
+ if (this.resumeFrom) {
7631
+ this.resumingFrom = this.resumeFrom;
7632
+ this.resumingFrom.resumingFrom = undefined;
7664
7633
  }
7665
- else {
7666
- /**
7667
- * If the layout hasn't changed and we have an animation that hasn't started yet,
7668
- * finish it immediately. Otherwise it will be animating from a location
7669
- * that was probably never committed to screen and look like a jumpy box.
7670
- */
7671
- if (!hasLayoutChanged) {
7672
- finishAnimation(this);
7673
- }
7674
- if (this.isLead() && this.options.onExitComplete) {
7675
- this.options.onExitComplete();
7676
- }
7634
+ const animationOptions = {
7635
+ ...getValueTransition(layoutTransition, "layout"),
7636
+ onPlay: onLayoutAnimationStart,
7637
+ onComplete: onLayoutAnimationComplete,
7638
+ };
7639
+ if (visualElement.shouldReduceMotion ||
7640
+ this.options.layoutRoot) {
7641
+ animationOptions.delay = 0;
7642
+ animationOptions.type = false;
7643
+ }
7644
+ this.startAnimation(animationOptions);
7645
+ /**
7646
+ * Set animation origin after starting animation to avoid layout jump
7647
+ * caused by stopping previous layout animation
7648
+ */
7649
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
7650
+ }
7651
+ else {
7652
+ /**
7653
+ * If the layout hasn't changed and we have an animation that hasn't started yet,
7654
+ * finish it immediately. Otherwise it will be animating from a location
7655
+ * that was probably never committed to screen and look like a jumpy box.
7656
+ */
7657
+ if (!hasLayoutChanged) {
7658
+ finishAnimation(this);
7659
+ }
7660
+ if (this.isLead() && this.options.onExitComplete) {
7661
+ this.options.onExitComplete();
7677
7662
  }
7678
7663
  }
7679
7664
  this.targetLayout = newLayout;
@@ -8958,29 +8943,6 @@ const DocumentProjectionNode = createProjectionNode$1({
8958
8943
  checkIsScrollRoot: () => true,
8959
8944
  });
8960
8945
 
8961
- const rootProjectionNode = {
8962
- current: undefined,
8963
- };
8964
- const HTMLProjectionNode = createProjectionNode$1({
8965
- measureScroll: (instance) => ({
8966
- x: instance.scrollLeft,
8967
- y: instance.scrollTop,
8968
- }),
8969
- defaultParent: () => {
8970
- if (!rootProjectionNode.current) {
8971
- const documentNode = new DocumentProjectionNode({});
8972
- documentNode.mount(window);
8973
- documentNode.setOptions({ layoutScroll: true });
8974
- rootProjectionNode.current = documentNode;
8975
- }
8976
- return rootProjectionNode.current;
8977
- },
8978
- resetTransform: (instance, value) => {
8979
- instance.style.transform = value !== undefined ? value : "none";
8980
- },
8981
- checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
8982
- });
8983
-
8984
8946
  const notify = (node) => !node.isLayoutDirty && node.willUpdate(false);
8985
8947
  function nodeGroup() {
8986
8948
  const nodes = new Set();
@@ -9004,6 +8966,29 @@ function nodeGroup() {
9004
8966
  };
9005
8967
  }
9006
8968
 
8969
+ const rootProjectionNode = {
8970
+ current: undefined,
8971
+ };
8972
+ const HTMLProjectionNode = createProjectionNode$1({
8973
+ measureScroll: (instance) => ({
8974
+ x: instance.scrollLeft,
8975
+ y: instance.scrollTop,
8976
+ }),
8977
+ defaultParent: () => {
8978
+ if (!rootProjectionNode.current) {
8979
+ const documentNode = new DocumentProjectionNode({});
8980
+ documentNode.mount(window);
8981
+ documentNode.setOptions({ layoutScroll: true });
8982
+ rootProjectionNode.current = documentNode;
8983
+ }
8984
+ return rootProjectionNode.current;
8985
+ },
8986
+ resetTransform: (instance, value) => {
8987
+ instance.style.transform = value !== undefined ? value : "none";
8988
+ },
8989
+ checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
8990
+ });
8991
+
9007
8992
  const LAYOUT_SELECTOR = "[data-layout], [data-layout-id]";
9008
8993
  function getLayoutElements(scope) {
9009
8994
  const elements = Array.from(scope.querySelectorAll(LAYOUT_SELECTOR));
@@ -9020,79 +9005,6 @@ function hasLayout(element) {
9020
9005
  return (element.hasAttribute("data-layout") ||
9021
9006
  element.hasAttribute("data-layout-id"));
9022
9007
  }
9023
- /**
9024
- * Track layout elements before mutation.
9025
- * Does NOT measure bounds - that's handled by the projection system via willUpdate().
9026
- */
9027
- function trackLayoutElements(scope) {
9028
- const elements = getLayoutElements(scope);
9029
- const records = new Map();
9030
- for (const element of elements) {
9031
- records.set(element, {
9032
- element,
9033
- parentElement: element.parentElement,
9034
- nextSibling: element.nextSibling,
9035
- layoutId: getLayoutId(element),
9036
- });
9037
- }
9038
- return records;
9039
- }
9040
- /**
9041
- * Compare before/after records to detect entering/exiting/persisting elements
9042
- */
9043
- function detectMutations(beforeRecords, scope) {
9044
- const afterElements = new Set(getLayoutElements(scope));
9045
- const beforeElements = new Set(beforeRecords.keys());
9046
- const entering = [];
9047
- const exiting = [];
9048
- const persisting = [];
9049
- const sharedEntering = new Map();
9050
- const sharedExiting = new Map();
9051
- const sharedPersisting = new Map();
9052
- // Find exiting elements (were in before, not in after)
9053
- for (const element of beforeElements) {
9054
- if (!afterElements.has(element)) {
9055
- const record = beforeRecords.get(element);
9056
- exiting.push({
9057
- element,
9058
- parentElement: record.parentElement,
9059
- nextSibling: record.nextSibling,
9060
- });
9061
- if (record.layoutId) {
9062
- sharedExiting.set(record.layoutId, element);
9063
- }
9064
- }
9065
- }
9066
- // Find entering and persisting elements
9067
- for (const element of afterElements) {
9068
- if (!beforeElements.has(element)) {
9069
- entering.push(element);
9070
- const layoutId = getLayoutId(element);
9071
- if (layoutId) {
9072
- sharedEntering.set(layoutId, element);
9073
- }
9074
- }
9075
- else {
9076
- persisting.push(element);
9077
- }
9078
- }
9079
- // Find persisting elements that share a layoutId with exiting elements
9080
- // This handles the A -> AB -> A pattern where A persists and B exits
9081
- for (const element of persisting) {
9082
- const layoutId = getLayoutId(element);
9083
- if (layoutId && sharedExiting.has(layoutId)) {
9084
- sharedPersisting.set(layoutId, element);
9085
- }
9086
- }
9087
- return {
9088
- entering,
9089
- exiting,
9090
- persisting,
9091
- sharedEntering,
9092
- sharedExiting,
9093
- sharedPersisting,
9094
- };
9095
- }
9096
9008
 
9097
9009
  let scaleCorrectorAdded = false;
9098
9010
  /**
@@ -9270,9 +9182,7 @@ function parseLayoutMode(value) {
9270
9182
  * matching React's behavior where nodes persist for elements that remain in the DOM.
9271
9183
  */
9272
9184
  function cleanupProjectionTree(context, elementsToCleanup) {
9273
- const elementsToProcess = elementsToCleanup
9274
- ? [...context.nodes.entries()].filter(([el]) => elementsToCleanup.has(el))
9275
- : [...context.nodes.entries()];
9185
+ const elementsToProcess = [...context.nodes.entries()];
9276
9186
  for (const [element, node] of elementsToProcess) {
9277
9187
  context.group.remove(node);
9278
9188
  node.unmount();
@@ -9300,12 +9210,8 @@ class LayoutAnimationBuilder {
9300
9210
  // Queue execution on microtask to allow builder methods to be called
9301
9211
  queueMicrotask(() => this.execute());
9302
9212
  }
9303
- shared(layoutIdOrOptions, options) {
9304
- if (typeof layoutIdOrOptions === "string") {
9305
- this.sharedTransitions.set(layoutIdOrOptions, options);
9306
- }
9307
- // For now, we ignore default shared options as the projection system
9308
- // handles shared transitions automatically
9213
+ shared(id, options) {
9214
+ this.sharedTransitions.set(id, options);
9309
9215
  return this;
9310
9216
  }
9311
9217
  then(onfulfilled, onrejected) {
@@ -9315,132 +9221,56 @@ class LayoutAnimationBuilder {
9315
9221
  if (this.executed)
9316
9222
  return;
9317
9223
  this.executed = true;
9318
- const animations = [];
9319
9224
  let context;
9320
- try {
9321
- // Phase 1: Pre-mutation - Build projection tree and take snapshots
9322
- const existingElements = getLayoutElements(this.scope);
9323
- // Build projection tree for existing elements FIRST
9324
- // This allows the projection system to handle measurements correctly
9325
- if (existingElements.length > 0) {
9326
- context = buildProjectionTree(existingElements, undefined, this.getBuildOptions());
9327
- // Start update cycle
9328
- context.root.startUpdate();
9329
- // Call willUpdate on all nodes to capture snapshots via projection system
9330
- // This handles transforms, scroll, etc. correctly
9331
- for (const node of context.nodes.values()) {
9332
- // Reset isLayoutDirty so willUpdate can take a snapshot.
9333
- // When hasTreeAnimated is true on the global root, newly mounted nodes
9334
- // get isLayoutDirty=true, which causes willUpdate to skip snapshot capture.
9335
- node.isLayoutDirty = false;
9336
- node.willUpdate();
9337
- }
9338
- }
9339
- // Track DOM structure (parent, sibling) for detecting removals
9340
- // No bounds measurement here - projection system already handled that
9341
- const beforeRecords = trackLayoutElements(this.scope);
9342
- // Phase 2: Execute DOM update
9343
- this.updateDom();
9344
- // Phase 3: Post-mutation (Detect & Prepare)
9345
- const mutationResult = detectMutations(beforeRecords, this.scope);
9346
- // Determine which exiting elements should be reattached:
9347
- // Non-shared exiting elements (no layoutId or no matching entering/persisting element)
9348
- const exitingToReattach = mutationResult.exiting.filter(({ element }) => {
9349
- const layoutId = element.getAttribute("data-layout-id");
9350
- const isSharedWithEntering = layoutId && mutationResult.sharedEntering.has(layoutId);
9351
- const isSharedWithPersisting = layoutId && mutationResult.sharedPersisting.has(layoutId);
9352
- // Reattach if not a shared element
9353
- return !isSharedWithEntering && !isSharedWithPersisting;
9354
- });
9355
- this.reattachExitingElements(exitingToReattach, context);
9356
- // Build projection nodes for entering elements
9357
- if (mutationResult.entering.length > 0) {
9358
- context = buildProjectionTree(mutationResult.entering, context, this.getBuildOptions());
9359
- }
9360
- // Also ensure persisting elements have nodes if context didn't exist
9361
- if (!context && mutationResult.persisting.length > 0) {
9362
- context = buildProjectionTree(mutationResult.persisting, undefined, this.getBuildOptions());
9363
- }
9364
- // Build set of shared exiting elements (they don't animate separately)
9365
- const sharedExitingElements = new Set();
9366
- for (const [layoutId, enteringElement] of mutationResult.sharedEntering) {
9367
- const exitingElement = mutationResult.sharedExiting.get(layoutId);
9368
- if (exitingElement) {
9369
- sharedExitingElements.add(exitingElement);
9370
- const exitingNode = context?.nodes.get(exitingElement);
9371
- const enteringNode = context?.nodes.get(enteringElement);
9372
- if (exitingNode && enteringNode) {
9373
- // Remove exiting node from stack, no crossfade
9374
- const stack = exitingNode.getStack();
9375
- if (stack) {
9376
- stack.remove(exitingNode);
9377
- }
9378
- }
9379
- else if (exitingNode && !enteringNode) {
9380
- // Fallback: If entering node doesn't exist yet, just handle exiting
9381
- const stack = exitingNode.getStack();
9382
- if (stack) {
9383
- stack.remove(exitingNode);
9384
- }
9385
- }
9386
- }
9387
- }
9388
- // Handle A -> AB -> A pattern: persisting element should become lead again
9389
- // when exiting element with same layoutId is removed
9390
- for (const [layoutId, persistingElement] of mutationResult.sharedPersisting) {
9391
- const exitingElement = mutationResult.sharedExiting.get(layoutId);
9392
- if (!exitingElement)
9393
- continue;
9394
- sharedExitingElements.add(exitingElement);
9395
- const exitingNode = context?.nodes.get(exitingElement);
9396
- const persistingNode = context?.nodes.get(persistingElement);
9397
- if (exitingNode && persistingNode) {
9398
- // Remove exiting node from stack, no crossfade
9399
- const stack = exitingNode.getStack();
9400
- if (stack) {
9401
- stack.remove(exitingNode);
9402
- }
9403
- }
9404
- }
9405
- // Phase 4: Animate
9406
- if (context) {
9407
- // Trigger layout animations via didUpdate
9408
- context.root.didUpdate();
9409
- // Wait for animations to be created (they're scheduled via frame.update)
9410
- await new Promise((resolve) => frame.postRender(() => resolve()));
9411
- // Collect layout animations from projection nodes
9412
- // Skip shared exiting elements (they don't animate)
9413
- for (const [element, node] of context.nodes.entries()) {
9414
- if (sharedExitingElements.has(element))
9415
- continue;
9416
- if (node.currentAnimation) {
9417
- animations.push(node.currentAnimation);
9418
- }
9419
- }
9420
- }
9421
- // Create and return group animation
9422
- const groupAnimation = new GroupAnimation(animations);
9423
- // Phase 5: Setup cleanup on complete
9424
- // Only cleanup exiting elements - persisting elements keep their nodes
9425
- // This matches React's behavior where nodes persist for elements in the DOM
9426
- const exitingElements = new Set(mutationResult.exiting.map(({ element }) => element));
9427
- groupAnimation.finished.then(() => {
9428
- // Clean up all reattached exiting elements (remove from DOM)
9429
- this.cleanupExitingElements(exitingToReattach);
9430
- if (context) {
9431
- // Only cleanup projection nodes for exiting elements
9432
- cleanupProjectionTree(context, exitingElements);
9433
- }
9434
- });
9435
- this.notifyReady(groupAnimation);
9225
+ // Phase 1: Pre-mutation - Build projection tree and take snapshots
9226
+ const beforeElements = getLayoutElements(this.scope);
9227
+ if (beforeElements.length > 0) {
9228
+ context = buildProjectionTree(beforeElements, undefined, this.getBuildOptions());
9229
+ context.root.startUpdate();
9230
+ for (const node of context.nodes.values()) {
9231
+ node.isLayoutDirty = false;
9232
+ node.willUpdate();
9233
+ }
9234
+ }
9235
+ // Phase 2: Execute DOM update
9236
+ this.updateDom();
9237
+ // Phase 3: Post-mutation - Compare before/after elements
9238
+ const afterElements = getLayoutElements(this.scope);
9239
+ const beforeSet = new Set(beforeElements);
9240
+ const afterSet = new Set(afterElements);
9241
+ const entering = afterElements.filter((el) => !beforeSet.has(el));
9242
+ const exiting = beforeElements.filter((el) => !afterSet.has(el));
9243
+ // Build projection nodes for entering elements
9244
+ if (entering.length > 0) {
9245
+ context = buildProjectionTree(entering, context, this.getBuildOptions());
9246
+ }
9247
+ // No layout elements - return empty animation
9248
+ if (!context) {
9249
+ this.notifyReady(new GroupAnimation([]));
9250
+ return;
9251
+ }
9252
+ // Handle shared elements
9253
+ for (const element of exiting) {
9254
+ const node = context.nodes.get(element);
9255
+ node?.getStack()?.remove(node);
9436
9256
  }
9437
- catch (error) {
9438
- // Cleanup on error - cleanup all nodes since animation failed
9439
- if (context) {
9440
- cleanupProjectionTree(context);
9257
+ for (const element of entering) {
9258
+ context.nodes.get(element)?.promote();
9259
+ }
9260
+ // Phase 4: Animate
9261
+ context.root.didUpdate();
9262
+ await new Promise((resolve) => frame.postRender(() => resolve()));
9263
+ const animations = [];
9264
+ for (const node of context.nodes.values()) {
9265
+ if (node.currentAnimation) {
9266
+ animations.push(node.currentAnimation);
9441
9267
  }
9442
- throw error;
9443
9268
  }
9269
+ const groupAnimation = new GroupAnimation(animations);
9270
+ groupAnimation.finished.then(() => {
9271
+ cleanupProjectionTree(context);
9272
+ });
9273
+ this.notifyReady(groupAnimation);
9444
9274
  }
9445
9275
  getBuildOptions() {
9446
9276
  return {
@@ -9453,43 +9283,6 @@ class LayoutAnimationBuilder {
9453
9283
  : undefined,
9454
9284
  };
9455
9285
  }
9456
- reattachExitingElements(exiting, context) {
9457
- for (const { element, parentElement, nextSibling } of exiting) {
9458
- // Check if parent still exists in DOM
9459
- if (!parentElement.isConnected)
9460
- continue;
9461
- // Get bounds from projection node snapshot (measured correctly via projection system)
9462
- const node = context?.nodes.get(element);
9463
- const snapshot = node?.snapshot;
9464
- if (!snapshot)
9465
- continue;
9466
- const { layoutBox } = snapshot;
9467
- // Reattach element
9468
- if (nextSibling && nextSibling.parentNode === parentElement) {
9469
- parentElement.insertBefore(element, nextSibling);
9470
- }
9471
- else {
9472
- parentElement.appendChild(element);
9473
- }
9474
- // Apply absolute positioning to prevent layout shift
9475
- // Use layoutBox from projection system which has transform-free measurements
9476
- const htmlElement = element;
9477
- htmlElement.style.position = "absolute";
9478
- htmlElement.style.top = `${layoutBox.y.min}px`;
9479
- htmlElement.style.left = `${layoutBox.x.min}px`;
9480
- htmlElement.style.width = `${layoutBox.x.max - layoutBox.x.min}px`;
9481
- htmlElement.style.height = `${layoutBox.y.max - layoutBox.y.min}px`;
9482
- htmlElement.style.margin = "0";
9483
- htmlElement.style.pointerEvents = "none";
9484
- }
9485
- }
9486
- cleanupExitingElements(exiting) {
9487
- for (const { element } of exiting) {
9488
- if (element.parentElement) {
9489
- element.parentElement.removeChild(element);
9490
- }
9491
- }
9492
- }
9493
9286
  }
9494
9287
  /**
9495
9288
  * Parse arguments for animateLayout overloads
@@ -9513,45 +9306,6 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
9513
9306
  };
9514
9307
  }
9515
9308
 
9516
- /**
9517
- * Animate layout changes within a DOM tree.
9518
- *
9519
- * @example
9520
- * ```typescript
9521
- * // Basic usage - animates all elements with data-layout or data-layout-id
9522
- * await animateLayout(() => {
9523
- * container.innerHTML = newContent
9524
- * })
9525
- *
9526
- * // With scope - only animates within the container
9527
- * await animateLayout(".container", () => {
9528
- * updateContent()
9529
- * })
9530
- *
9531
- * // With options
9532
- * await animateLayout(() => update(), { duration: 0.5 })
9533
- *
9534
- * // Configure shared element transitions
9535
- * animateLayout(".cards", () => {
9536
- * container.innerHTML = newCards
9537
- * }, { duration: 0.3 })
9538
- * .shared("hero", { type: "spring" })
9539
- * ```
9540
- *
9541
- * Elements are animated if they have:
9542
- * - `data-layout` attribute (layout animation only)
9543
- * - `data-layout-id` attribute (shared element transitions)
9544
- *
9545
- * @param scopeOrUpdateDom - Either a scope selector/element, or the DOM update function
9546
- * @param updateDomOrOptions - Either the DOM update function or animation options
9547
- * @param options - Animation options (when scope is provided)
9548
- * @returns A builder that resolves to animation controls
9549
- */
9550
- function unstable_animateLayout(scopeOrUpdateDom, updateDomOrOptions, options) {
9551
- const { scope, updateDom, defaultOptions } = parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options);
9552
- return new LayoutAnimationBuilder(scope, updateDom, defaultOptions);
9553
- }
9554
-
9555
9309
  /**
9556
9310
  * @deprecated
9557
9311
  *
@@ -9760,6 +9514,7 @@ exports.numberValueTypes = numberValueTypes;
9760
9514
  exports.observeTimeline = observeTimeline;
9761
9515
  exports.optimizedAppearDataAttribute = optimizedAppearDataAttribute;
9762
9516
  exports.optimizedAppearDataId = optimizedAppearDataId;
9517
+ exports.parseAnimateLayoutArgs = parseAnimateLayoutArgs;
9763
9518
  exports.parseCSSVariable = parseCSSVariable;
9764
9519
  exports.parseValueFromTransform = parseValueFromTransform;
9765
9520
  exports.percent = percent;
@@ -9821,7 +9576,6 @@ exports.transformProps = transformProps;
9821
9576
  exports.transformValue = transformValue;
9822
9577
  exports.transformValueTypes = transformValueTypes;
9823
9578
  exports.translateAxis = translateAxis;
9824
- exports.unstable_animateLayout = unstable_animateLayout;
9825
9579
  exports.updateMotionValuesFromProps = updateMotionValuesFromProps;
9826
9580
  exports.variantPriorityOrder = variantPriorityOrder;
9827
9581
  exports.variantProps = variantProps;