motion-dom 12.39.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.
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,342 +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
- valueTransition.skipAnimations) {
3062
- shouldSkip = true;
3063
- makeAnimationInstant(options);
3064
- options.delay = 0;
3065
- }
3066
- /**
3067
- * If the transition type or easing has been explicitly set by the user
3068
- * then we don't want to allow flattening the animation.
3069
- */
3070
- options.allowFlatten = !valueTransition.type && !valueTransition.ease;
3071
- /**
3072
- * If we can or must skip creating the animation, and apply only
3073
- * the final keyframe, do so. We also check once keyframes are resolved but
3074
- * this early check prevents the need to create an animation at all.
3075
- */
3076
- if (shouldSkip && !isHandoff && value.get() !== undefined) {
3077
- const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
3078
- if (finalKeyframe !== undefined) {
3079
- frame.update(() => {
3080
- options.onUpdate(finalKeyframe);
3081
- options.onComplete();
3082
- });
3083
- return;
3084
- }
3085
- }
3086
- return valueTransition.isSync
3087
- ? new JSAnimation(options)
3088
- : new AsyncMotionValueAnimation(options);
3089
- };
3090
-
3091
- function getValueState(visualElement) {
3092
- const state = [{}, {}];
3093
- visualElement?.values.forEach((value, key) => {
3094
- state[0][key] = value.get();
3095
- state[1][key] = value.getVelocity();
3096
- });
3097
- return state;
3098
- }
3099
- function resolveVariantFromProps(props, definition, custom, visualElement) {
3100
- /**
3101
- * If the variant definition is a function, resolve.
3102
- */
3103
- if (typeof definition === "function") {
3104
- const [current, velocity] = getValueState(visualElement);
3105
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3106
- }
3107
- /**
3108
- * If the variant definition is a variant label, or
3109
- * the function returned a variant label, resolve.
3110
- */
3111
- if (typeof definition === "string") {
3112
- definition = props.variants && props.variants[definition];
3113
- }
3114
- /**
3115
- * At this point we've resolved both functions and variant labels,
3116
- * but the resolved variant label might itself have been a function.
3117
- * If so, resolve. This can only have returned a valid target object.
3118
- */
3119
- if (typeof definition === "function") {
3120
- const [current, velocity] = getValueState(visualElement);
3121
- definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3122
- }
3123
- return definition;
3124
- }
3125
-
3126
- function resolveVariant(visualElement, definition, custom) {
3127
- const props = visualElement.getProps();
3128
- return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
3129
- }
3130
-
3131
- const positionalKeys = new Set([
3132
- "width",
3133
- "height",
3134
- "top",
3135
- "left",
3136
- "right",
3137
- "bottom",
3138
- ...transformPropOrder,
3139
- ]);
3140
-
3141
- /**
3142
- * Maximum time between the value of two frames, beyond which we
3143
- * assume the velocity has since been 0.
3144
- */
3145
- const MAX_VELOCITY_DELTA = 30;
3146
- const isFloat = (value) => {
3147
- return !isNaN(parseFloat(value));
3148
- };
3149
- const collectMotionValues = {
3150
- current: undefined,
3151
- };
3152
- /**
3153
- * `MotionValue` is used to track the state and velocity of motion values.
3154
- *
3155
- * @public
3156
- */
3157
- class MotionValue {
3158
- /**
3159
- * @param init - The initiating value
3160
- * @param config - Optional configuration options
3161
- *
3162
- * - `transformer`: A function to transform incoming values with.
3163
- */
3164
- constructor(init, options = {}) {
3165
- /**
3166
- * Tracks whether this value can output a velocity. Currently this is only true
3167
- * if the value is numerical, but we might be able to widen the scope here and support
3168
- * other value types.
3169
- *
3170
- * @internal
3171
- */
3172
- this.canTrackVelocity = null;
3173
- /**
3174
- * An object containing a SubscriptionManager for each active event.
3175
- */
3176
- this.events = {};
3177
- this.updateAndNotify = (v) => {
3178
- const currentTime = time.now();
3179
- /**
3180
- * If we're updating the value during another frame or eventloop
3181
- * than the previous frame, then the we set the previous frame value
3182
- * to current.
3183
- */
3184
- if (this.updatedAt !== currentTime) {
3185
- this.setPrevFrameValue();
3186
- }
3187
- this.prev = this.current;
3188
- this.setCurrent(v);
3189
- // Update update subscribers
3190
- if (this.current !== this.prev) {
3191
- this.events.change?.notify(this.current);
3192
- if (this.dependents) {
3193
- for (const dependent of this.dependents) {
3194
- dependent.dirty();
3195
- }
3196
- }
3197
- }
3198
- };
3199
- this.hasAnimated = false;
3200
- this.setCurrent(init);
3201
- this.owner = options.owner;
3202
- }
3203
- setCurrent(current) {
3204
- this.current = current;
3205
- this.updatedAt = time.now();
3206
- if (this.canTrackVelocity === null && current !== undefined) {
3207
- this.canTrackVelocity = isFloat(this.current);
3208
- }
3209
- }
3210
- setPrevFrameValue(prevFrameValue = this.current) {
3211
- this.prevFrameValue = prevFrameValue;
3212
- this.prevUpdatedAt = this.updatedAt;
2952
+ setPrevFrameValue(prevFrameValue = this.current) {
2953
+ this.prevFrameValue = prevFrameValue;
2954
+ this.prevUpdatedAt = this.updatedAt;
3213
2955
  }
3214
2956
  /**
3215
2957
  * Adds a function that will be notified when the `MotionValue` is updated.
@@ -3320,142 +3062,588 @@ class MotionValue {
3320
3062
  this.prevUpdatedAt = this.updatedAt - delta;
3321
3063
  }
3322
3064
  /**
3323
- * Set the state of the `MotionValue`, stopping any active animations,
3324
- * 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.
3325
3334
  */
3326
- jump(v, endAnimation = true) {
3327
- this.updateAndNotify(v);
3328
- this.prev = v;
3329
- this.prevUpdatedAt = this.prevFrameValue = undefined;
3330
- endAnimation && this.stop();
3331
- if (this.stopPassiveEffect)
3332
- this.stopPassiveEffect();
3333
- }
3334
- dirty() {
3335
- this.events.change?.notify(this.current);
3336
- }
3337
- addDependent(dependent) {
3338
- if (!this.dependents) {
3339
- this.dependents = new Set();
3340
- }
3341
- this.dependents.add(dependent);
3335
+ if (options.from !== undefined) {
3336
+ options.keyframes[0] = options.from;
3342
3337
  }
3343
- removeDependent(dependent) {
3344
- if (this.dependents) {
3345
- 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;
3346
3344
  }
3347
3345
  }
3348
- /**
3349
- * Returns the latest state of `MotionValue`
3350
- *
3351
- * @returns - The latest state of `MotionValue`
3352
- *
3353
- * @public
3354
- */
3355
- get() {
3356
- if (collectMotionValues.current) {
3357
- collectMotionValues.current.push(this);
3358
- }
3359
- 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;
3360
3353
  }
3361
3354
  /**
3362
- * @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.
3363
3357
  */
3364
- getPrevious() {
3365
- return this.prev;
3366
- }
3358
+ options.allowFlatten = !valueTransition.type && !valueTransition.ease;
3367
3359
  /**
3368
- * Returns the latest velocity of `MotionValue`
3369
- *
3370
- * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
3371
- *
3372
- * @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.
3373
3363
  */
3374
- getVelocity() {
3375
- const currentTime = time.now();
3376
- if (!this.canTrackVelocity ||
3377
- this.prevFrameValue === undefined ||
3378
- currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
3379
- 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;
3380
3372
  }
3381
- const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
3382
- // Casts because of parseFloat's poor typing
3383
- return motionUtils.velocityPerSecond(parseFloat(this.current) -
3384
- parseFloat(this.prevFrameValue), delta);
3385
3373
  }
3386
- /**
3387
- * Registers a new animation to control this `MotionValue`. Only one
3388
- * animation can drive a `MotionValue` at one time.
3389
- *
3390
- * ```jsx
3391
- * value.start()
3392
- * ```
3393
- *
3394
- * @param animation - A function that starts the provided animation
3395
- */
3396
- start(startAnimation) {
3397
- this.stop();
3398
- return new Promise((resolve) => {
3399
- this.hasAnimated = true;
3400
- this.animation = startAnimation(resolve);
3401
- if (this.events.animationStart) {
3402
- 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;
3403
3464
  }
3404
- }).then(() => {
3405
- if (this.events.animationComplete) {
3406
- 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;
3407
3491
  }
3408
- this.clearAnimation();
3409
- });
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;
3410
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) {
3411
3606
  /**
3412
- * Stop the currently active animation.
3413
- *
3414
- * @public
3607
+ * If the variant definition is a function, resolve.
3415
3608
  */
3416
- stop() {
3417
- if (this.animation) {
3418
- this.animation.stop();
3419
- if (this.events.animationCancel) {
3420
- this.events.animationCancel.notify();
3421
- }
3422
- }
3423
- this.clearAnimation();
3609
+ if (typeof definition === "function") {
3610
+ const [current, velocity] = getValueState(visualElement);
3611
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3424
3612
  }
3425
3613
  /**
3426
- * Returns `true` if this value is currently animating.
3427
- *
3428
- * @public
3614
+ * If the variant definition is a variant label, or
3615
+ * the function returned a variant label, resolve.
3429
3616
  */
3430
- isAnimating() {
3431
- return !!this.animation;
3432
- }
3433
- clearAnimation() {
3434
- delete this.animation;
3617
+ if (typeof definition === "string") {
3618
+ definition = props.variants && props.variants[definition];
3435
3619
  }
3436
3620
  /**
3437
- * Destroy and clean up subscribers to this `MotionValue`.
3438
- *
3439
- * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
3440
- * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
3441
- * created a `MotionValue` via the `motionValue` function.
3442
- *
3443
- * @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.
3444
3624
  */
3445
- destroy() {
3446
- this.dependents?.clear();
3447
- this.events.destroy?.notify();
3448
- this.clearListeners();
3449
- this.stop();
3450
- if (this.stopPassiveEffect) {
3451
- this.stopPassiveEffect();
3452
- }
3625
+ if (typeof definition === "function") {
3626
+ const [current, velocity] = getValueState(visualElement);
3627
+ definition = definition(custom !== undefined ? custom : props.custom, current, velocity);
3453
3628
  }
3629
+ return definition;
3454
3630
  }
3455
- function motionValue(init, options) {
3456
- 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);
3457
3635
  }
3458
3636
 
3637
+ const positionalKeys = new Set([
3638
+ "width",
3639
+ "height",
3640
+ "top",
3641
+ "left",
3642
+ "right",
3643
+ "bottom",
3644
+ ...transformPropOrder,
3645
+ ]);
3646
+
3459
3647
  const isKeyframesTarget = (v) => {
3460
3648
  return Array.isArray(v);
3461
3649
  };
@@ -3544,6 +3732,11 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3544
3732
  const animationTypeState = type &&
3545
3733
  visualElement.animationState &&
3546
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
+ }
3547
3740
  for (const key in target) {
3548
3741
  const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
3549
3742
  const valueTarget = target[key];
@@ -3762,6 +3955,12 @@ const int = {
3762
3955
 
3763
3956
  const transformValueTypes = {
3764
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,
3765
3964
  rotateX: degrees,
3766
3965
  rotateY: degrees,
3767
3966
  rotateZ: degrees,
@@ -4313,6 +4512,15 @@ function buildTransform$1(state) {
4313
4512
  transform += `${transformName}(${value}) `;
4314
4513
  }
4315
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
+ }
4316
4524
  return transformIsDefault ? "none" : transform.trim();
4317
4525
  }
4318
4526
 
@@ -6465,6 +6673,14 @@ function buildTransform(latestValues, transform, transformTemplate) {
6465
6673
  }
6466
6674
  }
6467
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
+ }
6468
6684
  transformString = transformString.trim();
6469
6685
  // If we have a custom `transform` template, pass our transform values and
6470
6686
  // generated transformString to that before returning
@@ -7527,11 +7743,14 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
7527
7743
  transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
7528
7744
  }
7529
7745
  if (latestTransform) {
7530
- const { transformPerspective, rotate, rotateX, rotateY, skewX, skewY } = latestTransform;
7746
+ const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY, } = latestTransform;
7531
7747
  if (transformPerspective)
7532
7748
  transform = `perspective(${transformPerspective}px) ${transform}`;
7533
7749
  if (rotate)
7534
7750
  transform += `rotate(${rotate}deg) `;
7751
+ // Additive `rotate()` so user `rotate` isn't clobbered.
7752
+ if (pathRotation)
7753
+ transform += `rotate(${pathRotation}deg) `;
7535
7754
  if (rotateX)
7536
7755
  transform += `rotateX(${rotateX}deg) `;
7537
7756
  if (rotateY)
@@ -8086,7 +8305,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8086
8305
  * Set animation origin after starting animation to avoid layout jump
8087
8306
  * caused by stopping previous layout animation
8088
8307
  */
8089
- this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
8308
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged, animationOptions
8309
+ .path);
8090
8310
  }
8091
8311
  else {
8092
8312
  /**
@@ -8802,7 +9022,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8802
9022
  this.projectionDelta = createDelta();
8803
9023
  this.projectionDeltaWithTransform = createDelta();
8804
9024
  }
8805
- setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
9025
+ setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false, pathFn) {
8806
9026
  const snapshot = this.snapshot;
8807
9027
  const snapshotLatestValues = snapshot ? snapshot.latestValues : {};
8808
9028
  const mixedValues = { ...this.latestValues };
@@ -8824,10 +9044,26 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8824
9044
  !this.path.some(hasOpacityCrossfade));
8825
9045
  this.animationProgress = 0;
8826
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);
8827
9050
  this.mixTargetDelta = (latest) => {
8828
9051
  const progress = latest / 1000;
8829
- mixAxisDelta(targetDelta.x, delta.x, progress);
8830
- 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
+ }
8831
9067
  this.setTargetDelta(targetDelta);
8832
9068
  if (this.relativeTarget &&
8833
9069
  this.relativeTargetOrigin &&
@@ -8852,6 +9088,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
8852
9088
  this.animationValues = mixedValues;
8853
9089
  mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
8854
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
+ }
8855
9098
  this.root.scheduleUpdateProjection();
8856
9099
  this.scheduleRender();
8857
9100
  this.animationProgress = progress;
@@ -9372,7 +9615,7 @@ function resetSkewAndRotation(node) {
9372
9615
  function removeLeadSnapshots(stack) {
9373
9616
  stack.removeLeadSnapshot();
9374
9617
  }
9375
- function mixAxisDelta(output, delta, p) {
9618
+ function mixAxisDeltaLinear(output, delta, p) {
9376
9619
  output.translate = mixNumber$1(delta.translate, 0, p);
9377
9620
  output.scale = mixNumber$1(delta.scale, 1, p);
9378
9621
  output.origin = delta.origin;
@@ -9796,6 +10039,7 @@ exports.applyGeneratorOptions = applyGeneratorOptions;
9796
10039
  exports.applyPointDelta = applyPointDelta;
9797
10040
  exports.applyPxDefaults = applyPxDefaults;
9798
10041
  exports.applyTreeDeltas = applyTreeDeltas;
10042
+ exports.arc = arc;
9799
10043
  exports.aspectRatio = aspectRatio;
9800
10044
  exports.attachFollow = attachFollow;
9801
10045
  exports.attachSpring = attachSpring;