motion-dom 12.38.0 → 12.40.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 (33) hide show
  1. package/dist/cjs/index.js +694 -445
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/interfaces/motion-value.mjs +2 -1
  4. package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
  5. package/dist/es/animation/interfaces/visual-element-target.mjs +8 -0
  6. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  7. package/dist/es/animation/utils/arc.mjs +188 -0
  8. package/dist/es/animation/utils/arc.mjs.map +1 -0
  9. package/dist/es/effects/style/transform.mjs +9 -0
  10. package/dist/es/effects/style/transform.mjs.map +1 -1
  11. package/dist/es/index.mjs +1 -0
  12. package/dist/es/index.mjs.map +1 -1
  13. package/dist/es/projection/node/create-projection-node.mjs +30 -6
  14. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  15. package/dist/es/projection/styles/transform.mjs +4 -1
  16. package/dist/es/projection/styles/transform.mjs.map +1 -1
  17. package/dist/es/render/VisualElement.mjs +2 -2
  18. package/dist/es/render/VisualElement.mjs.map +1 -1
  19. package/dist/es/render/html/utils/build-transform.mjs +8 -0
  20. package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
  21. package/dist/es/render/utils/animation-state.mjs +2 -1
  22. package/dist/es/render/utils/animation-state.mjs.map +1 -1
  23. package/dist/es/render/utils/keys-transform.mjs +8 -1
  24. package/dist/es/render/utils/keys-transform.mjs.map +1 -1
  25. package/dist/es/value/types/maps/transform.mjs +6 -0
  26. package/dist/es/value/types/maps/transform.mjs.map +1 -1
  27. package/dist/index.d.ts +1160 -1062
  28. package/dist/motion-dom.dev.js +694 -445
  29. package/dist/motion-dom.js +1 -1
  30. package/dist/size-rollup-motion-value.js.map +1 -1
  31. package/dist/size-rollup-style-effect.js +1 -1
  32. package/dist/size-rollup-style-effect.js.map +1 -1
  33. package/package.json +3 -3
package/dist/cjs/index.js CHANGED
@@ -1859,8 +1859,15 @@ const transformPropOrder = [
1859
1859
  ];
1860
1860
  /**
1861
1861
  * A quick lookup for transform props.
1862
+ *
1863
+ * `pathRotation` is a transform for routing purposes (skipped from raw
1864
+ * style application, wired to the transform composite, flags transform
1865
+ * dirty) but is intentionally NOT in `transformPropOrder` — it is
1866
+ * composed onto `rotate` at the build sites, not serialized in its own
1867
+ * slot, and must stay out of the order-array consumers (parse-transform,
1868
+ * unit-conversion, keys-position).
1862
1869
  */
1863
- const transformProps = /*@__PURE__*/ (() => new Set(transformPropOrder))();
1870
+ const transformProps = /*@__PURE__*/ (() => new Set([...transformPropOrder, "pathRotation"]))();
1864
1871
 
1865
1872
  const isNumOrPxType = (v) => v === number || v === px;
1866
1873
  const transformKeys = new Set(["x", "y", "z"]);
@@ -2874,341 +2881,77 @@ function calcChildStagger(children, child, delayChildren, staggerChildren = 0, s
2874
2881
  }
2875
2882
 
2876
2883
  /**
2877
- * Parse Framer's special CSS variable format into a CSS token and a fallback.
2878
- *
2879
- * ```
2880
- * `var(--foo, #fff)` => [`--foo`, '#fff']
2881
- * ```
2882
- *
2883
- * @param current
2884
- */
2885
- const splitCSSVariableRegex =
2886
- // eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
2887
- /^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;
2888
- function parseCSSVariable(current) {
2889
- const match = splitCSSVariableRegex.exec(current);
2890
- if (!match)
2891
- return [,];
2892
- const [, token1, token2, fallback] = match;
2893
- return [`--${token1 ?? token2}`, fallback];
2894
- }
2895
- const maxDepth = 4;
2896
- function getVariableValue(current, element, depth = 1) {
2897
- motionUtils.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
2898
- const [token, fallback] = parseCSSVariable(current);
2899
- // No CSS variable detected
2900
- if (!token)
2901
- return;
2902
- // Attempt to read this CSS variable off the element
2903
- const resolved = window.getComputedStyle(element).getPropertyValue(token);
2904
- if (resolved) {
2905
- const trimmed = resolved.trim();
2906
- return motionUtils.isNumericalString(trimmed) ? parseFloat(trimmed) : trimmed;
2907
- }
2908
- return isCSSVariableToken(fallback)
2909
- ? getVariableValue(fallback, element, depth + 1)
2910
- : fallback;
2911
- }
2912
-
2913
- const underDampedSpring = {
2914
- type: "spring",
2915
- stiffness: 500,
2916
- damping: 25,
2917
- restSpeed: 10,
2918
- };
2919
- const criticallyDampedSpring = (target) => ({
2920
- type: "spring",
2921
- stiffness: 550,
2922
- damping: target === 0 ? 2 * Math.sqrt(550) : 30,
2923
- restSpeed: 10,
2924
- });
2925
- const keyframesTransition = {
2926
- type: "keyframes",
2927
- duration: 0.8,
2928
- };
2929
- /**
2930
- * Default easing curve is a slightly shallower version of
2931
- * the default browser easing curve.
2884
+ * Maximum time between the value of two frames, beyond which we
2885
+ * assume the velocity has since been 0.
2932
2886
  */
2933
- const ease = {
2934
- type: "keyframes",
2935
- ease: [0.25, 0.1, 0.35, 1],
2936
- duration: 0.3,
2887
+ const MAX_VELOCITY_DELTA = 30;
2888
+ const isFloat = (value) => {
2889
+ return !isNaN(parseFloat(value));
2937
2890
  };
2938
- const getDefaultTransition = (valueKey, { keyframes }) => {
2939
- if (keyframes.length > 2) {
2940
- return keyframesTransition;
2941
- }
2942
- else if (transformProps.has(valueKey)) {
2943
- return valueKey.startsWith("scale")
2944
- ? criticallyDampedSpring(keyframes[1])
2945
- : underDampedSpring;
2946
- }
2947
- return ease;
2891
+ const collectMotionValues = {
2892
+ current: undefined,
2948
2893
  };
2949
-
2950
- /**
2951
- * If `transition` has `inherit: true`, shallow-merge it with
2952
- * `parentTransition` (child keys win) and strip the `inherit` key.
2953
- * Otherwise return `transition` unchanged.
2954
- */
2955
- function resolveTransition(transition, parentTransition) {
2956
- if (transition?.inherit && parentTransition) {
2957
- const { inherit: _, ...rest } = transition;
2958
- return { ...parentTransition, ...rest };
2959
- }
2960
- return transition;
2961
- }
2962
-
2963
- function getValueTransition(transition, key) {
2964
- const valueTransition = transition?.[key] ??
2965
- transition?.["default"] ??
2966
- transition;
2967
- if (valueTransition !== transition) {
2968
- return resolveTransition(valueTransition, transition);
2969
- }
2970
- return valueTransition;
2971
- }
2972
-
2973
- const orchestrationKeys = new Set([
2974
- "when",
2975
- "delay",
2976
- "delayChildren",
2977
- "staggerChildren",
2978
- "staggerDirection",
2979
- "repeat",
2980
- "repeatType",
2981
- "repeatDelay",
2982
- "from",
2983
- "elapsed",
2984
- ]);
2985
2894
  /**
2986
- * Decide whether a transition is defined on a given Transition.
2987
- * This filters out orchestration options and returns true
2988
- * if any options are left.
2895
+ * `MotionValue` is used to track the state and velocity of motion values.
2896
+ *
2897
+ * @public
2989
2898
  */
2990
- function isTransitionDefined(transition) {
2991
- for (const key in transition) {
2992
- if (!orchestrationKeys.has(key))
2993
- return true;
2994
- }
2995
- return false;
2996
- }
2997
-
2998
- const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
2999
- const valueTransition = getValueTransition(transition, name) || {};
3000
- /**
3001
- * Most transition values are currently completely overwritten by value-specific
3002
- * transitions. In the future it'd be nicer to blend these transitions. But for now
3003
- * delay actually does inherit from the root transition if not value-specific.
3004
- */
3005
- const delay = valueTransition.delay || transition.delay || 0;
3006
- /**
3007
- * Elapsed isn't a public transition option but can be passed through from
3008
- * optimized appear effects in milliseconds.
3009
- */
3010
- let { elapsed = 0 } = transition;
3011
- elapsed = elapsed - motionUtils.secondsToMilliseconds(delay);
3012
- const options = {
3013
- keyframes: Array.isArray(target) ? target : [null, target],
3014
- ease: "easeOut",
3015
- velocity: value.getVelocity(),
3016
- ...valueTransition,
3017
- delay: -elapsed,
3018
- onUpdate: (v) => {
3019
- value.set(v);
3020
- valueTransition.onUpdate && valueTransition.onUpdate(v);
3021
- },
3022
- onComplete: () => {
3023
- onComplete();
3024
- valueTransition.onComplete && valueTransition.onComplete();
3025
- },
3026
- name,
3027
- motionValue: value,
3028
- element: isHandoff ? undefined : element,
3029
- };
3030
- /**
3031
- * If there's no transition defined for this value, we can generate
3032
- * unique transition settings for this value.
3033
- */
3034
- if (!isTransitionDefined(valueTransition)) {
3035
- Object.assign(options, getDefaultTransition(name, options));
3036
- }
3037
- /**
3038
- * Both WAAPI and our internal animation functions use durations
3039
- * as defined by milliseconds, while our external API defines them
3040
- * as seconds.
3041
- */
3042
- options.duration && (options.duration = motionUtils.secondsToMilliseconds(options.duration));
3043
- options.repeatDelay && (options.repeatDelay = motionUtils.secondsToMilliseconds(options.repeatDelay));
2899
+ class MotionValue {
3044
2900
  /**
3045
- * Support deprecated way to set initial value. Prefer keyframe syntax.
2901
+ * @param init - The initiating value
2902
+ * @param config - Optional configuration options
2903
+ *
2904
+ * - `transformer`: A function to transform incoming values with.
3046
2905
  */
3047
- if (options.from !== undefined) {
3048
- options.keyframes[0] = options.from;
2906
+ constructor(init, options = {}) {
2907
+ /**
2908
+ * Tracks whether this value can output a velocity. Currently this is only true
2909
+ * if the value is numerical, but we might be able to widen the scope here and support
2910
+ * other value types.
2911
+ *
2912
+ * @internal
2913
+ */
2914
+ this.canTrackVelocity = null;
2915
+ /**
2916
+ * An object containing a SubscriptionManager for each active event.
2917
+ */
2918
+ this.events = {};
2919
+ this.updateAndNotify = (v) => {
2920
+ const currentTime = time.now();
2921
+ /**
2922
+ * If we're updating the value during another frame or eventloop
2923
+ * than the previous frame, then the we set the previous frame value
2924
+ * to current.
2925
+ */
2926
+ if (this.updatedAt !== currentTime) {
2927
+ this.setPrevFrameValue();
2928
+ }
2929
+ this.prev = this.current;
2930
+ this.setCurrent(v);
2931
+ // Update update subscribers
2932
+ if (this.current !== this.prev) {
2933
+ this.events.change?.notify(this.current);
2934
+ if (this.dependents) {
2935
+ for (const dependent of this.dependents) {
2936
+ dependent.dirty();
2937
+ }
2938
+ }
2939
+ }
2940
+ };
2941
+ this.hasAnimated = false;
2942
+ this.setCurrent(init);
2943
+ this.owner = options.owner;
3049
2944
  }
3050
- let shouldSkip = false;
3051
- if (options.type === false ||
3052
- (options.duration === 0 && !options.repeatDelay)) {
3053
- makeAnimationInstant(options);
3054
- if (options.delay === 0) {
3055
- shouldSkip = true;
2945
+ setCurrent(current) {
2946
+ this.current = current;
2947
+ this.updatedAt = time.now();
2948
+ if (this.canTrackVelocity === null && current !== undefined) {
2949
+ this.canTrackVelocity = isFloat(this.current);
3056
2950
  }
3057
2951
  }
3058
- if (motionUtils.MotionGlobalConfig.instantAnimations ||
3059
- motionUtils.MotionGlobalConfig.skipAnimations ||
3060
- element?.shouldSkipAnimations) {
3061
- shouldSkip = true;
3062
- makeAnimationInstant(options);
3063
- options.delay = 0;
3064
- }
3065
- /**
3066
- * If the transition type or easing has been explicitly set by the user
3067
- * then we don't want to allow flattening the animation.
3068
- */
3069
- options.allowFlatten = !valueTransition.type && !valueTransition.ease;
3070
- /**
3071
- * If we can or must skip creating the animation, and apply only
3072
- * the final keyframe, do so. We also check once keyframes are resolved but
3073
- * this early check prevents the need to create an animation at all.
3074
- */
3075
- if (shouldSkip && !isHandoff && value.get() !== undefined) {
3076
- const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
3077
- if (finalKeyframe !== undefined) {
3078
- frame.update(() => {
3079
- options.onUpdate(finalKeyframe);
3080
- options.onComplete();
3081
- });
3082
- return;
3083
- }
3084
- }
3085
- return valueTransition.isSync
3086
- ? new JSAnimation(options)
3087
- : new AsyncMotionValueAnimation(options);
3088
- };
3089
-
3090
- function getValueState(visualElement) {
3091
- const state = [{}, {}];
3092
- visualElement?.values.forEach((value, key) => {
3093
- state[0][key] = value.get();
3094
- state[1][key] = value.getVelocity();
3095
- });
3096
- return state;
3097
- }
3098
- function resolveVariantFromProps(props, definition, custom, visualElement) {
3099
- /**
3100
- * If the variant definition is a function, resolve.
3101
- */
3102
- if (typeof definition === "function") {
3103
- const [current, velocity] = getValueState(visualElement);
3104
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3105
- }
3106
- /**
3107
- * If the variant definition is a variant label, or
3108
- * the function returned a variant label, resolve.
3109
- */
3110
- if (typeof definition === "string") {
3111
- definition = props.variants && props.variants[definition];
3112
- }
3113
- /**
3114
- * At this point we've resolved both functions and variant labels,
3115
- * but the resolved variant label might itself have been a function.
3116
- * If so, resolve. This can only have returned a valid target object.
3117
- */
3118
- if (typeof definition === "function") {
3119
- const [current, velocity] = getValueState(visualElement);
3120
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3121
- }
3122
- return definition;
3123
- }
3124
-
3125
- function resolveVariant(visualElement, definition, custom) {
3126
- const props = visualElement.getProps();
3127
- return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
3128
- }
3129
-
3130
- const positionalKeys = new Set([
3131
- "width",
3132
- "height",
3133
- "top",
3134
- "left",
3135
- "right",
3136
- "bottom",
3137
- ...transformPropOrder,
3138
- ]);
3139
-
3140
- /**
3141
- * Maximum time between the value of two frames, beyond which we
3142
- * assume the velocity has since been 0.
3143
- */
3144
- const MAX_VELOCITY_DELTA = 30;
3145
- const isFloat = (value) => {
3146
- return !isNaN(parseFloat(value));
3147
- };
3148
- const collectMotionValues = {
3149
- current: undefined,
3150
- };
3151
- /**
3152
- * `MotionValue` is used to track the state and velocity of motion values.
3153
- *
3154
- * @public
3155
- */
3156
- class MotionValue {
3157
- /**
3158
- * @param init - The initiating value
3159
- * @param config - Optional configuration options
3160
- *
3161
- * - `transformer`: A function to transform incoming values with.
3162
- */
3163
- constructor(init, options = {}) {
3164
- /**
3165
- * Tracks whether this value can output a velocity. Currently this is only true
3166
- * if the value is numerical, but we might be able to widen the scope here and support
3167
- * other value types.
3168
- *
3169
- * @internal
3170
- */
3171
- this.canTrackVelocity = null;
3172
- /**
3173
- * An object containing a SubscriptionManager for each active event.
3174
- */
3175
- this.events = {};
3176
- this.updateAndNotify = (v) => {
3177
- const currentTime = time.now();
3178
- /**
3179
- * If we're updating the value during another frame or eventloop
3180
- * than the previous frame, then the we set the previous frame value
3181
- * to current.
3182
- */
3183
- if (this.updatedAt !== currentTime) {
3184
- this.setPrevFrameValue();
3185
- }
3186
- this.prev = this.current;
3187
- this.setCurrent(v);
3188
- // Update update subscribers
3189
- if (this.current !== this.prev) {
3190
- this.events.change?.notify(this.current);
3191
- if (this.dependents) {
3192
- for (const dependent of this.dependents) {
3193
- dependent.dirty();
3194
- }
3195
- }
3196
- }
3197
- };
3198
- this.hasAnimated = false;
3199
- this.setCurrent(init);
3200
- this.owner = options.owner;
3201
- }
3202
- setCurrent(current) {
3203
- this.current = current;
3204
- this.updatedAt = time.now();
3205
- if (this.canTrackVelocity === null && current !== undefined) {
3206
- this.canTrackVelocity = isFloat(this.current);
3207
- }
3208
- }
3209
- setPrevFrameValue(prevFrameValue = this.current) {
3210
- this.prevFrameValue = prevFrameValue;
3211
- this.prevUpdatedAt = this.updatedAt;
2952
+ setPrevFrameValue(prevFrameValue = this.current) {
2953
+ this.prevFrameValue = prevFrameValue;
2954
+ this.prevUpdatedAt = this.updatedAt;
3212
2955
  }
3213
2956
  /**
3214
2957
  * Adds a function that will be notified when the `MotionValue` is updated.
@@ -3319,142 +3062,588 @@ class MotionValue {
3319
3062
  this.prevUpdatedAt = this.updatedAt - delta;
3320
3063
  }
3321
3064
  /**
3322
- * Set the state of the `MotionValue`, stopping any active animations,
3323
- * effects, and resets velocity to `0`.
3065
+ * Set the state of the `MotionValue`, stopping any active animations,
3066
+ * effects, and resets velocity to `0`.
3067
+ */
3068
+ jump(v, endAnimation = true) {
3069
+ this.updateAndNotify(v);
3070
+ this.prev = v;
3071
+ this.prevUpdatedAt = this.prevFrameValue = undefined;
3072
+ endAnimation && this.stop();
3073
+ if (this.stopPassiveEffect)
3074
+ this.stopPassiveEffect();
3075
+ }
3076
+ dirty() {
3077
+ this.events.change?.notify(this.current);
3078
+ }
3079
+ addDependent(dependent) {
3080
+ if (!this.dependents) {
3081
+ this.dependents = new Set();
3082
+ }
3083
+ this.dependents.add(dependent);
3084
+ }
3085
+ removeDependent(dependent) {
3086
+ if (this.dependents) {
3087
+ this.dependents.delete(dependent);
3088
+ }
3089
+ }
3090
+ /**
3091
+ * Returns the latest state of `MotionValue`
3092
+ *
3093
+ * @returns - The latest state of `MotionValue`
3094
+ *
3095
+ * @public
3096
+ */
3097
+ get() {
3098
+ if (collectMotionValues.current) {
3099
+ collectMotionValues.current.push(this);
3100
+ }
3101
+ return this.current;
3102
+ }
3103
+ /**
3104
+ * @public
3105
+ */
3106
+ getPrevious() {
3107
+ return this.prev;
3108
+ }
3109
+ /**
3110
+ * Returns the latest velocity of `MotionValue`
3111
+ *
3112
+ * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
3113
+ *
3114
+ * @public
3115
+ */
3116
+ getVelocity() {
3117
+ const currentTime = time.now();
3118
+ if (!this.canTrackVelocity ||
3119
+ this.prevFrameValue === undefined ||
3120
+ currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
3121
+ return 0;
3122
+ }
3123
+ const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
3124
+ // Casts because of parseFloat's poor typing
3125
+ return motionUtils.velocityPerSecond(parseFloat(this.current) -
3126
+ parseFloat(this.prevFrameValue), delta);
3127
+ }
3128
+ /**
3129
+ * Registers a new animation to control this `MotionValue`. Only one
3130
+ * animation can drive a `MotionValue` at one time.
3131
+ *
3132
+ * ```jsx
3133
+ * value.start()
3134
+ * ```
3135
+ *
3136
+ * @param animation - A function that starts the provided animation
3137
+ */
3138
+ start(startAnimation) {
3139
+ this.stop();
3140
+ return new Promise((resolve) => {
3141
+ this.hasAnimated = true;
3142
+ this.animation = startAnimation(resolve);
3143
+ if (this.events.animationStart) {
3144
+ this.events.animationStart.notify();
3145
+ }
3146
+ }).then(() => {
3147
+ if (this.events.animationComplete) {
3148
+ this.events.animationComplete.notify();
3149
+ }
3150
+ this.clearAnimation();
3151
+ });
3152
+ }
3153
+ /**
3154
+ * Stop the currently active animation.
3155
+ *
3156
+ * @public
3157
+ */
3158
+ stop() {
3159
+ if (this.animation) {
3160
+ this.animation.stop();
3161
+ if (this.events.animationCancel) {
3162
+ this.events.animationCancel.notify();
3163
+ }
3164
+ }
3165
+ this.clearAnimation();
3166
+ }
3167
+ /**
3168
+ * Returns `true` if this value is currently animating.
3169
+ *
3170
+ * @public
3171
+ */
3172
+ isAnimating() {
3173
+ return !!this.animation;
3174
+ }
3175
+ clearAnimation() {
3176
+ delete this.animation;
3177
+ }
3178
+ /**
3179
+ * Destroy and clean up subscribers to this `MotionValue`.
3180
+ *
3181
+ * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
3182
+ * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
3183
+ * created a `MotionValue` via the `motionValue` function.
3184
+ *
3185
+ * @public
3186
+ */
3187
+ destroy() {
3188
+ this.dependents?.clear();
3189
+ this.events.destroy?.notify();
3190
+ this.clearListeners();
3191
+ this.stop();
3192
+ if (this.stopPassiveEffect) {
3193
+ this.stopPassiveEffect();
3194
+ }
3195
+ }
3196
+ }
3197
+ function motionValue(init, options) {
3198
+ return new MotionValue(init, options);
3199
+ }
3200
+
3201
+ /**
3202
+ * If `transition` has `inherit: true`, shallow-merge it with
3203
+ * `parentTransition` (child keys win) and strip the `inherit` key.
3204
+ * Otherwise return `transition` unchanged.
3205
+ */
3206
+ function resolveTransition(transition, parentTransition) {
3207
+ if (transition?.inherit && parentTransition) {
3208
+ const { inherit: _, ...rest } = transition;
3209
+ return { ...parentTransition, ...rest };
3210
+ }
3211
+ return transition;
3212
+ }
3213
+
3214
+ function getValueTransition(transition, key) {
3215
+ const valueTransition = transition?.[key] ??
3216
+ transition?.["default"] ??
3217
+ transition;
3218
+ if (valueTransition !== transition) {
3219
+ return resolveTransition(valueTransition, transition);
3220
+ }
3221
+ return valueTransition;
3222
+ }
3223
+
3224
+ const underDampedSpring = {
3225
+ type: "spring",
3226
+ stiffness: 500,
3227
+ damping: 25,
3228
+ restSpeed: 10,
3229
+ };
3230
+ const criticallyDampedSpring = (target) => ({
3231
+ type: "spring",
3232
+ stiffness: 550,
3233
+ damping: target === 0 ? 2 * Math.sqrt(550) : 30,
3234
+ restSpeed: 10,
3235
+ });
3236
+ const keyframesTransition = {
3237
+ type: "keyframes",
3238
+ duration: 0.8,
3239
+ };
3240
+ /**
3241
+ * Default easing curve is a slightly shallower version of
3242
+ * the default browser easing curve.
3243
+ */
3244
+ const ease = {
3245
+ type: "keyframes",
3246
+ ease: [0.25, 0.1, 0.35, 1],
3247
+ duration: 0.3,
3248
+ };
3249
+ const getDefaultTransition = (valueKey, { keyframes }) => {
3250
+ if (keyframes.length > 2) {
3251
+ return keyframesTransition;
3252
+ }
3253
+ else if (transformProps.has(valueKey)) {
3254
+ return valueKey.startsWith("scale")
3255
+ ? criticallyDampedSpring(keyframes[1])
3256
+ : underDampedSpring;
3257
+ }
3258
+ return ease;
3259
+ };
3260
+
3261
+ const orchestrationKeys = new Set([
3262
+ "when",
3263
+ "delay",
3264
+ "delayChildren",
3265
+ "staggerChildren",
3266
+ "staggerDirection",
3267
+ "repeat",
3268
+ "repeatType",
3269
+ "repeatDelay",
3270
+ "from",
3271
+ "elapsed",
3272
+ ]);
3273
+ /**
3274
+ * Decide whether a transition is defined on a given Transition.
3275
+ * This filters out orchestration options and returns true
3276
+ * if any options are left.
3277
+ */
3278
+ function isTransitionDefined(transition) {
3279
+ for (const key in transition) {
3280
+ if (!orchestrationKeys.has(key))
3281
+ return true;
3282
+ }
3283
+ return false;
3284
+ }
3285
+
3286
+ const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
3287
+ const valueTransition = getValueTransition(transition, name) || {};
3288
+ /**
3289
+ * Most transition values are currently completely overwritten by value-specific
3290
+ * transitions. In the future it'd be nicer to blend these transitions. But for now
3291
+ * delay actually does inherit from the root transition if not value-specific.
3292
+ */
3293
+ const delay = valueTransition.delay || transition.delay || 0;
3294
+ /**
3295
+ * Elapsed isn't a public transition option but can be passed through from
3296
+ * optimized appear effects in milliseconds.
3297
+ */
3298
+ let { elapsed = 0 } = transition;
3299
+ elapsed = elapsed - motionUtils.secondsToMilliseconds(delay);
3300
+ const options = {
3301
+ keyframes: Array.isArray(target) ? target : [null, target],
3302
+ ease: "easeOut",
3303
+ velocity: value.getVelocity(),
3304
+ ...valueTransition,
3305
+ delay: -elapsed,
3306
+ onUpdate: (v) => {
3307
+ value.set(v);
3308
+ valueTransition.onUpdate && valueTransition.onUpdate(v);
3309
+ },
3310
+ onComplete: () => {
3311
+ onComplete();
3312
+ valueTransition.onComplete && valueTransition.onComplete();
3313
+ },
3314
+ name,
3315
+ motionValue: value,
3316
+ element: isHandoff ? undefined : element,
3317
+ };
3318
+ /**
3319
+ * If there's no transition defined for this value, we can generate
3320
+ * unique transition settings for this value.
3321
+ */
3322
+ if (!isTransitionDefined(valueTransition)) {
3323
+ Object.assign(options, getDefaultTransition(name, options));
3324
+ }
3325
+ /**
3326
+ * Both WAAPI and our internal animation functions use durations
3327
+ * as defined by milliseconds, while our external API defines them
3328
+ * as seconds.
3329
+ */
3330
+ options.duration && (options.duration = motionUtils.secondsToMilliseconds(options.duration));
3331
+ options.repeatDelay && (options.repeatDelay = motionUtils.secondsToMilliseconds(options.repeatDelay));
3332
+ /**
3333
+ * Support deprecated way to set initial value. Prefer keyframe syntax.
3324
3334
  */
3325
- jump(v, endAnimation = true) {
3326
- this.updateAndNotify(v);
3327
- this.prev = v;
3328
- this.prevUpdatedAt = this.prevFrameValue = undefined;
3329
- endAnimation && this.stop();
3330
- if (this.stopPassiveEffect)
3331
- this.stopPassiveEffect();
3332
- }
3333
- dirty() {
3334
- this.events.change?.notify(this.current);
3335
- }
3336
- addDependent(dependent) {
3337
- if (!this.dependents) {
3338
- this.dependents = new Set();
3339
- }
3340
- this.dependents.add(dependent);
3335
+ if (options.from !== undefined) {
3336
+ options.keyframes[0] = options.from;
3341
3337
  }
3342
- removeDependent(dependent) {
3343
- if (this.dependents) {
3344
- this.dependents.delete(dependent);
3338
+ let shouldSkip = false;
3339
+ if (options.type === false ||
3340
+ (options.duration === 0 && !options.repeatDelay)) {
3341
+ makeAnimationInstant(options);
3342
+ if (options.delay === 0) {
3343
+ shouldSkip = true;
3345
3344
  }
3346
3345
  }
3347
- /**
3348
- * Returns the latest state of `MotionValue`
3349
- *
3350
- * @returns - The latest state of `MotionValue`
3351
- *
3352
- * @public
3353
- */
3354
- get() {
3355
- if (collectMotionValues.current) {
3356
- collectMotionValues.current.push(this);
3357
- }
3358
- return this.current;
3346
+ if (motionUtils.MotionGlobalConfig.instantAnimations ||
3347
+ motionUtils.MotionGlobalConfig.skipAnimations ||
3348
+ element?.shouldSkipAnimations ||
3349
+ valueTransition.skipAnimations) {
3350
+ shouldSkip = true;
3351
+ makeAnimationInstant(options);
3352
+ options.delay = 0;
3359
3353
  }
3360
3354
  /**
3361
- * @public
3355
+ * If the transition type or easing has been explicitly set by the user
3356
+ * then we don't want to allow flattening the animation.
3362
3357
  */
3363
- getPrevious() {
3364
- return this.prev;
3365
- }
3358
+ options.allowFlatten = !valueTransition.type && !valueTransition.ease;
3366
3359
  /**
3367
- * Returns the latest velocity of `MotionValue`
3368
- *
3369
- * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
3370
- *
3371
- * @public
3360
+ * If we can or must skip creating the animation, and apply only
3361
+ * the final keyframe, do so. We also check once keyframes are resolved but
3362
+ * this early check prevents the need to create an animation at all.
3372
3363
  */
3373
- getVelocity() {
3374
- const currentTime = time.now();
3375
- if (!this.canTrackVelocity ||
3376
- this.prevFrameValue === undefined ||
3377
- currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
3378
- return 0;
3364
+ if (shouldSkip && !isHandoff && value.get() !== undefined) {
3365
+ const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
3366
+ if (finalKeyframe !== undefined) {
3367
+ frame.update(() => {
3368
+ options.onUpdate(finalKeyframe);
3369
+ options.onComplete();
3370
+ });
3371
+ return;
3379
3372
  }
3380
- const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
3381
- // Casts because of parseFloat's poor typing
3382
- return motionUtils.velocityPerSecond(parseFloat(this.current) -
3383
- parseFloat(this.prevFrameValue), delta);
3384
3373
  }
3385
- /**
3386
- * Registers a new animation to control this `MotionValue`. Only one
3387
- * animation can drive a `MotionValue` at one time.
3388
- *
3389
- * ```jsx
3390
- * value.start()
3391
- * ```
3392
- *
3393
- * @param animation - A function that starts the provided animation
3394
- */
3395
- start(startAnimation) {
3396
- this.stop();
3397
- return new Promise((resolve) => {
3398
- this.hasAnimated = true;
3399
- this.animation = startAnimation(resolve);
3400
- if (this.events.animationStart) {
3401
- this.events.animationStart.notify();
3374
+ return valueTransition.isSync
3375
+ ? new JSAnimation(options)
3376
+ : new AsyncMotionValueAnimation(options);
3377
+ };
3378
+
3379
+ const MIN_LAYOUT_DISTANCE = 20;
3380
+ function bezierPoint(t, origin, control, target) {
3381
+ const inv = 1 - t;
3382
+ return inv * inv * origin + 2 * inv * t * control + t * t * target;
3383
+ }
3384
+ function bezierTangentAngle(t, originX, controlX, targetX, originY, controlY, targetY) {
3385
+ const dx = 2 * (1 - t) * (controlX - originX) + 2 * t * (targetX - controlX);
3386
+ const dy = 2 * (1 - t) * (controlY - originY) + 2 * t * (targetY - controlY);
3387
+ return Math.atan2(dy, dx) * (180 / Math.PI);
3388
+ }
3389
+ function computeArcControlPoint(fromX, fromY, toX, toY, strength, peak) {
3390
+ const deltaX = toX - fromX;
3391
+ const deltaY = toY - fromY;
3392
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
3393
+ if (distance > 0) {
3394
+ const normalPerpX = -deltaY / distance;
3395
+ const normalPerpY = deltaX / distance;
3396
+ const desiredHeight = strength * distance;
3397
+ return {
3398
+ x: fromX + deltaX * peak + normalPerpX * desiredHeight,
3399
+ y: fromY + deltaY * peak + normalPerpY * desiredHeight,
3400
+ };
3401
+ }
3402
+ return { x: fromX, y: fromY };
3403
+ }
3404
+ /**
3405
+ * The pure sampling factory: `(from, to) => (t) => point`. Internal —
3406
+ * used by {@link arc} and the unit tests. Not part of the public surface.
3407
+ */
3408
+ function createArcPath({ strength = 0.5, peak = 0.5, direction, rotate = false, } = {}) {
3409
+ const rotationScale = rotate === true ? 1 : typeof rotate === "number" ? rotate : 0;
3410
+ // Auto-direction only: persists across calls to flip the bulge back
3411
+ // onto the same screen side when the dominant axis changes between
3412
+ // calls. Reuse the factory (module scope / useMemo) to keep this alive.
3413
+ let prevBulgeSign;
3414
+ const createInterpolator = (from, to) => {
3415
+ const dx = to.x - from.x;
3416
+ const dy = to.y - from.y;
3417
+ let signed;
3418
+ if (direction === "cw") {
3419
+ signed = -strength;
3420
+ }
3421
+ else if (direction === "ccw") {
3422
+ signed = strength;
3423
+ }
3424
+ else {
3425
+ const dom = Math.abs(dx) >= Math.abs(dy) ? dx : dy;
3426
+ signed = dom < 0 ? -strength : strength;
3427
+ }
3428
+ let control = computeArcControlPoint(from.x, from.y, to.x, to.y, signed, peak);
3429
+ if (direction === undefined) {
3430
+ const isVertical = Math.abs(dx) < Math.abs(dy);
3431
+ const midX = from.x + dx * peak;
3432
+ const midY = from.y + dy * peak;
3433
+ const bulgeSign = isVertical
3434
+ ? Math.sign(control.x - midX)
3435
+ : Math.sign(control.y - midY);
3436
+ if (prevBulgeSign !== undefined &&
3437
+ bulgeSign !== 0 &&
3438
+ bulgeSign !== prevBulgeSign) {
3439
+ signed = -signed;
3440
+ control = computeArcControlPoint(from.x, from.y, to.x, to.y, signed, peak);
3441
+ }
3442
+ else if (bulgeSign !== 0) {
3443
+ prevBulgeSign = bulgeSign;
3444
+ }
3445
+ }
3446
+ const tangent0 = rotationScale
3447
+ ? bezierTangentAngle(0, from.x, control.x, to.x, from.y, control.y, to.y)
3448
+ : 0;
3449
+ const tangent1 = rotationScale
3450
+ ? bezierTangentAngle(1, from.x, control.x, to.x, from.y, control.y, to.y)
3451
+ : 0;
3452
+ const tangentDelta = rotationScale
3453
+ ? motionUtils.wrap(-180, 180, tangent1 - tangent0)
3454
+ : 0;
3455
+ return (t) => {
3456
+ const out = {
3457
+ x: bezierPoint(t, from.x, control.x, to.x),
3458
+ y: bezierPoint(t, from.y, control.y, to.y),
3459
+ };
3460
+ if (rotationScale) {
3461
+ const raw = bezierTangentAngle(t, from.x, control.x, to.x, from.y, control.y, to.y);
3462
+ const baseline = tangent0 + tangentDelta * t;
3463
+ out.rotate = motionUtils.wrap(-180, 180, raw - baseline) * rotationScale;
3402
3464
  }
3403
- }).then(() => {
3404
- if (this.events.animationComplete) {
3405
- this.events.animationComplete.notify();
3465
+ return out;
3466
+ };
3467
+ };
3468
+ return createInterpolator;
3469
+ }
3470
+ /**
3471
+ * Creates a curved path for `transition.path`:
3472
+ *
3473
+ * ```ts
3474
+ * <motion.div animate={{ x: 200, y: 100 }} transition={{ path: arc() }} />
3475
+ * ```
3476
+ *
3477
+ * Reuse the returned value (module scope / useMemo / useRef) so its
3478
+ * continuity closure survives re-renders — a fresh `arc()` has no memory.
3479
+ */
3480
+ function arc(options = {}) {
3481
+ const sample = createArcPath(options);
3482
+ const path = {
3483
+ interpolateProjection(delta) {
3484
+ // `from` is the current translate offset (carries any in-flight
3485
+ // displacement when interrupted); `to` is the new layout origin.
3486
+ // The distance floor avoids visible wobble on tiny shifts.
3487
+ const tx = delta.x.translate;
3488
+ const ty = delta.y.translate;
3489
+ if (Math.sqrt(tx * tx + ty * ty) < MIN_LAYOUT_DISTANCE) {
3490
+ return undefined;
3406
3491
  }
3407
- this.clearAnimation();
3408
- });
3492
+ return sample({ x: tx, y: ty }, { x: 0, y: 0 });
3493
+ },
3494
+ animateVisualElement(visualElement, target, transition, delay, animations) {
3495
+ if (!("x" in target || "y" in target))
3496
+ return;
3497
+ const xValue = visualElement.getValue("x", visualElement.latestValues["x"] ?? 0);
3498
+ const yValue = visualElement.getValue("y", visualElement.latestValues["y"] ?? 0);
3499
+ const xRaw = target.x;
3500
+ const yRaw = target.y;
3501
+ const xFrom = (Array.isArray(xRaw) && xRaw[0] != null
3502
+ ? xRaw[0]
3503
+ : xValue?.get()) ?? 0;
3504
+ const yFrom = (Array.isArray(yRaw) && yRaw[0] != null
3505
+ ? yRaw[0]
3506
+ : yValue?.get()) ?? 0;
3507
+ const xTo = (Array.isArray(xRaw)
3508
+ ? xRaw[xRaw.length - 1]
3509
+ : xRaw ?? xFrom);
3510
+ const yTo = (Array.isArray(yRaw)
3511
+ ? yRaw[yRaw.length - 1]
3512
+ : yRaw ?? yFrom);
3513
+ // Interruption needs no flag: x/y already hold the displaced
3514
+ // mid-arc position, so xFrom/yFrom carry the continuity geometry.
3515
+ const interpolate = sample({ x: xFrom, y: yFrom }, { x: xTo, y: yTo });
3516
+ // Drive a dedicated `pathRotation` value (composed onto `rotate`
3517
+ // at the build sites) rather than `rotate` itself, so a
3518
+ // concurrent rotate animation composes and nothing accumulates
3519
+ // on interrupt.
3520
+ const pathRotationValue = interpolate(0).rotate !== undefined
3521
+ ? visualElement.getValue("pathRotation", 0)
3522
+ : undefined;
3523
+ const pathTransition = {
3524
+ delay,
3525
+ ...getValueTransition(transition || {}, "x"),
3526
+ };
3527
+ delete pathTransition.path;
3528
+ const progress = motionValue(0);
3529
+ progress.start(animateMotionValue("", progress, [0, 1000], {
3530
+ ...pathTransition,
3531
+ isSync: true,
3532
+ velocity: 0,
3533
+ onUpdate: (latest) => {
3534
+ const point = interpolate(latest / 1000);
3535
+ xValue?.set(point.x);
3536
+ yValue?.set(point.y);
3537
+ if (pathRotationValue && point.rotate !== undefined) {
3538
+ pathRotationValue.set(point.rotate);
3539
+ }
3540
+ },
3541
+ onComplete: () => {
3542
+ xValue?.set(xTo);
3543
+ yValue?.set(yTo);
3544
+ pathRotationValue?.set(0);
3545
+ },
3546
+ // Interrupt/cancel must clear our additive contribution
3547
+ // so it can't linger on top of the user's `rotate`.
3548
+ onStop: () => pathRotationValue?.set(0),
3549
+ onCancel: () => pathRotationValue?.set(0),
3550
+ }));
3551
+ if (progress.animation)
3552
+ animations.push(progress.animation);
3553
+ delete target.x;
3554
+ delete target.y;
3555
+ },
3556
+ };
3557
+ return path;
3558
+ }
3559
+
3560
+ /**
3561
+ * Parse Framer's special CSS variable format into a CSS token and a fallback.
3562
+ *
3563
+ * ```
3564
+ * `var(--foo, #fff)` => [`--foo`, '#fff']
3565
+ * ```
3566
+ *
3567
+ * @param current
3568
+ */
3569
+ const splitCSSVariableRegex =
3570
+ // eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
3571
+ /^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;
3572
+ function parseCSSVariable(current) {
3573
+ const match = splitCSSVariableRegex.exec(current);
3574
+ if (!match)
3575
+ return [,];
3576
+ const [, token1, token2, fallback] = match;
3577
+ return [`--${token1 ?? token2}`, fallback];
3578
+ }
3579
+ const maxDepth = 4;
3580
+ function getVariableValue(current, element, depth = 1) {
3581
+ motionUtils.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
3582
+ const [token, fallback] = parseCSSVariable(current);
3583
+ // No CSS variable detected
3584
+ if (!token)
3585
+ return;
3586
+ // Attempt to read this CSS variable off the element
3587
+ const resolved = window.getComputedStyle(element).getPropertyValue(token);
3588
+ if (resolved) {
3589
+ const trimmed = resolved.trim();
3590
+ return motionUtils.isNumericalString(trimmed) ? parseFloat(trimmed) : trimmed;
3409
3591
  }
3592
+ return isCSSVariableToken(fallback)
3593
+ ? getVariableValue(fallback, element, depth + 1)
3594
+ : fallback;
3595
+ }
3596
+
3597
+ function getValueState(visualElement) {
3598
+ const state = [{}, {}];
3599
+ visualElement?.values.forEach((value, key) => {
3600
+ state[0][key] = value.get();
3601
+ state[1][key] = value.getVelocity();
3602
+ });
3603
+ return state;
3604
+ }
3605
+ function resolveVariantFromProps(props, definition, custom, visualElement) {
3410
3606
  /**
3411
- * Stop the currently active animation.
3412
- *
3413
- * @public
3607
+ * If the variant definition is a function, resolve.
3414
3608
  */
3415
- stop() {
3416
- if (this.animation) {
3417
- this.animation.stop();
3418
- if (this.events.animationCancel) {
3419
- this.events.animationCancel.notify();
3420
- }
3421
- }
3422
- this.clearAnimation();
3609
+ if (typeof definition === "function") {
3610
+ const [current, velocity] = getValueState(visualElement);
3611
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3423
3612
  }
3424
3613
  /**
3425
- * Returns `true` if this value is currently animating.
3426
- *
3427
- * @public
3614
+ * If the variant definition is a variant label, or
3615
+ * the function returned a variant label, resolve.
3428
3616
  */
3429
- isAnimating() {
3430
- return !!this.animation;
3431
- }
3432
- clearAnimation() {
3433
- delete this.animation;
3617
+ if (typeof definition === "string") {
3618
+ definition = props.variants && props.variants[definition];
3434
3619
  }
3435
3620
  /**
3436
- * Destroy and clean up subscribers to this `MotionValue`.
3437
- *
3438
- * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
3439
- * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
3440
- * created a `MotionValue` via the `motionValue` function.
3441
- *
3442
- * @public
3621
+ * At this point we've resolved both functions and variant labels,
3622
+ * but the resolved variant label might itself have been a function.
3623
+ * If so, resolve. This can only have returned a valid target object.
3443
3624
  */
3444
- destroy() {
3445
- this.dependents?.clear();
3446
- this.events.destroy?.notify();
3447
- this.clearListeners();
3448
- this.stop();
3449
- if (this.stopPassiveEffect) {
3450
- this.stopPassiveEffect();
3451
- }
3625
+ if (typeof definition === "function") {
3626
+ const [current, velocity] = getValueState(visualElement);
3627
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3452
3628
  }
3629
+ return definition;
3453
3630
  }
3454
- function motionValue(init, options) {
3455
- return new MotionValue(init, options);
3631
+
3632
+ function resolveVariant(visualElement, definition, custom) {
3633
+ const props = visualElement.getProps();
3634
+ return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
3456
3635
  }
3457
3636
 
3637
+ const positionalKeys = new Set([
3638
+ "width",
3639
+ "height",
3640
+ "top",
3641
+ "left",
3642
+ "right",
3643
+ "bottom",
3644
+ ...transformPropOrder,
3645
+ ]);
3646
+
3458
3647
  const isKeyframesTarget = (v) => {
3459
3648
  return Array.isArray(v);
3460
3649
  };
@@ -3536,12 +3725,18 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3536
3725
  ? resolveTransition(transition, defaultTransition)
3537
3726
  : defaultTransition;
3538
3727
  const reduceMotion = transition?.reduceMotion;
3728
+ const skipAnimations = transition?.skipAnimations;
3539
3729
  if (transitionOverride)
3540
3730
  transition = transitionOverride;
3541
3731
  const animations = [];
3542
3732
  const animationTypeState = type &&
3543
3733
  visualElement.animationState &&
3544
3734
  visualElement.animationState.getState()[type];
3735
+ const path = transition?.path;
3736
+ if (path) {
3737
+ // path mutates `target` to claim x/y; loop below skips them.
3738
+ path.animateVisualElement(visualElement, target, transition, delay, animations);
3739
+ }
3545
3740
  for (const key in target) {
3546
3741
  const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
3547
3742
  const valueTarget = target[key];
@@ -3554,6 +3749,8 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3554
3749
  delay,
3555
3750
  ...getValueTransition(transition || {}, key),
3556
3751
  };
3752
+ if (skipAnimations)
3753
+ valueTransition.skipAnimations = true;
3557
3754
  /**
3558
3755
  * If the value is already at the defined target, skip the animation.
3559
3756
  * We still re-assert the value via frame.update to take precedence
@@ -3758,6 +3955,12 @@ const int = {
3758
3955
 
3759
3956
  const transformValueTypes = {
3760
3957
  rotate: degrees,
3958
+ /**
3959
+ * Internal channel for `transition.path` orientToPath. Composed onto
3960
+ * `rotate` at the transform-build sites so the user's `rotate` is
3961
+ * never read or overwritten. Not part of `transformPropOrder`.
3962
+ */
3963
+ pathRotation: degrees,
3761
3964
  rotateX: degrees,
3762
3965
  rotateY: degrees,
3763
3966
  rotateZ: degrees,
@@ -4309,6 +4512,15 @@ function buildTransform$1(state) {
4309
4512
  transform += `${transformName}(${value}) `;
4310
4513
  }
4311
4514
  }
4515
+ // See build-transform.ts: additive `rotate()` so user `rotate` isn't
4516
+ // clobbered. Not a `transformPropOrder` slot.
4517
+ const pathRotation = state.latest.pathRotation;
4518
+ if (pathRotation) {
4519
+ transformIsDefault = false;
4520
+ transform += `rotate(${typeof pathRotation === "number"
4521
+ ? `${pathRotation}deg`
4522
+ : pathRotation}) `;
4523
+ }
4312
4524
  return transformIsDefault ? "none" : transform.trim();
4313
4525
  }
4314
4526
 
@@ -5918,8 +6130,8 @@ class VisualElement {
5918
6130
  removeOnChange();
5919
6131
  if (removeSyncCheck)
5920
6132
  removeSyncCheck();
5921
- if (value.owner)
5922
- value.stop();
6133
+ // Defer to MotionValue.on("change") auto-stop so React 19 remounts
6134
+ // can resubscribe before the animation is cancelled (#3315).
5923
6135
  });
5924
6136
  }
5925
6137
  sortNodePosition(other) {
@@ -6461,6 +6673,14 @@ function buildTransform(latestValues, transform, transformTemplate) {
6461
6673
  }
6462
6674
  }
6463
6675
  }
6676
+ // `pathRotation` composes onto `rotate` as a separate additive term so
6677
+ // the user's `rotate` is never clobbered. Deliberately not a slot in
6678
+ // `transformPropOrder`.
6679
+ const pathRotation = latestValues.pathRotation;
6680
+ if (pathRotation) {
6681
+ transformIsDefault = false;
6682
+ transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
6683
+ }
6464
6684
  transformString = transformString.trim();
6465
6685
  // If we have a custom `transform` template, pass our transform values and
6466
6686
  // generated transformString to that before returning
@@ -7163,7 +7383,8 @@ function createAnimationState(visualElement) {
7163
7383
  */
7164
7384
  let valueHasChanged = false;
7165
7385
  if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
7166
- valueHasChanged = !shallowCompare(next, prev);
7386
+ valueHasChanged =
7387
+ !shallowCompare(next, prev) || variantDidChange;
7167
7388
  }
7168
7389
  else {
7169
7390
  valueHasChanged = next !== prev;
@@ -7522,11 +7743,14 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
7522
7743
  transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
7523
7744
  }
7524
7745
  if (latestTransform) {
7525
- const { transformPerspective, rotate, rotateX, rotateY, skewX, skewY } = latestTransform;
7746
+ const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY, } = latestTransform;
7526
7747
  if (transformPerspective)
7527
7748
  transform = `perspective(${transformPerspective}px) ${transform}`;
7528
7749
  if (rotate)
7529
7750
  transform += `rotate(${rotate}deg) `;
7751
+ // Additive `rotate()` so user `rotate` isn't clobbered.
7752
+ if (pathRotation)
7753
+ transform += `rotate(${pathRotation}deg) `;
7530
7754
  if (rotateX)
7531
7755
  transform += `rotateX(${rotateX}deg) `;
7532
7756
  if (rotateY)
@@ -8081,7 +8305,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8081
8305
  * Set animation origin after starting animation to avoid layout jump
8082
8306
  * caused by stopping previous layout animation
8083
8307
  */
8084
- this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
8308
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged, animationOptions
8309
+ .path);
8085
8310
  }
8086
8311
  else {
8087
8312
  /**
@@ -8797,7 +9022,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8797
9022
  this.projectionDelta = createDelta();
8798
9023
  this.projectionDeltaWithTransform = createDelta();
8799
9024
  }
8800
- setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
9025
+ setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false, pathFn) {
8801
9026
  const snapshot = this.snapshot;
8802
9027
  const snapshotLatestValues = snapshot ? snapshot.latestValues : {};
8803
9028
  const mixedValues = { ...this.latestValues };
@@ -8819,10 +9044,26 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8819
9044
  !this.path.some(hasOpacityCrossfade));
8820
9045
  this.animationProgress = 0;
8821
9046
  let prevRelativeTarget;
9047
+ // The path decides whether the layout shift is worth curving
9048
+ // (distance floor) and resolves the interpolator from the delta.
9049
+ const interpolate = pathFn?.interpolateProjection(delta);
8822
9050
  this.mixTargetDelta = (latest) => {
8823
9051
  const progress = latest / 1000;
8824
- mixAxisDelta(targetDelta.x, delta.x, progress);
8825
- mixAxisDelta(targetDelta.y, delta.y, progress);
9052
+ const point = interpolate?.(progress);
9053
+ if (point) {
9054
+ targetDelta.x.translate = point.x;
9055
+ targetDelta.x.scale = mixNumber$1(delta.x.scale, 1, progress);
9056
+ targetDelta.x.origin = delta.x.origin;
9057
+ targetDelta.x.originPoint = delta.x.originPoint;
9058
+ targetDelta.y.translate = point.y;
9059
+ targetDelta.y.scale = mixNumber$1(delta.y.scale, 1, progress);
9060
+ targetDelta.y.origin = delta.y.origin;
9061
+ targetDelta.y.originPoint = delta.y.originPoint;
9062
+ }
9063
+ else {
9064
+ mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
9065
+ mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
9066
+ }
8826
9067
  this.setTargetDelta(targetDelta);
8827
9068
  if (this.relativeTarget &&
8828
9069
  this.relativeTargetOrigin &&
@@ -8847,6 +9088,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8847
9088
  this.animationValues = mixedValues;
8848
9089
  mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
8849
9090
  }
9091
+ if (point && point.rotate !== undefined) {
9092
+ // Dedicated `pathRotation` channel, not `rotate`, so an
9093
+ // animating `rotate` is composed with, never clobbered.
9094
+ if (!this.animationValues)
9095
+ this.animationValues = mixedValues;
9096
+ this.animationValues.pathRotation = point.rotate;
9097
+ }
8850
9098
  this.root.scheduleUpdateProjection();
8851
9099
  this.scheduleRender();
8852
9100
  this.animationProgress = progress;
@@ -9367,7 +9615,7 @@ function resetSkewAndRotation(node) {
9367
9615
  function removeLeadSnapshots(stack) {
9368
9616
  stack.removeLeadSnapshot();
9369
9617
  }
9370
- function mixAxisDelta(output, delta, p) {
9618
+ function mixAxisDeltaLinear(output, delta, p) {
9371
9619
  output.translate = mixNumber$1(delta.translate, 0, p);
9372
9620
  output.scale = mixNumber$1(delta.scale, 1, p);
9373
9621
  output.origin = delta.origin;
@@ -9791,6 +10039,7 @@ exports.applyGeneratorOptions = applyGeneratorOptions;
9791
10039
  exports.applyPointDelta = applyPointDelta;
9792
10040
  exports.applyPxDefaults = applyPxDefaults;
9793
10041
  exports.applyTreeDeltas = applyTreeDeltas;
10042
+ exports.arc = arc;
9794
10043
  exports.aspectRatio = aspectRatio;
9795
10044
  exports.attachFollow = attachFollow;
9796
10045
  exports.attachSpring = attachSpring;