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