motion-dom 13.4.4 → 13.5.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 (54) hide show
  1. package/dist/cjs/index.js +469 -415
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/FollowAnimation.mjs +1 -4
  4. package/dist/es/animation/FollowAnimation.mjs.map +1 -1
  5. package/dist/es/animation/NativeAnimation.mjs +2 -5
  6. package/dist/es/animation/NativeAnimation.mjs.map +1 -1
  7. package/dist/es/animation/drivers/frame.mjs +2 -1
  8. package/dist/es/animation/drivers/frame.mjs.map +1 -1
  9. package/dist/es/animation/generators/spring.mjs +99 -95
  10. package/dist/es/animation/generators/spring.mjs.map +1 -1
  11. package/dist/es/animation/utils/notify-inspector.mjs +1 -1
  12. package/dist/es/animation/utils/notify-inspector.mjs.map +1 -1
  13. package/dist/es/frameloop/batcher.mjs +5 -6
  14. package/dist/es/frameloop/batcher.mjs.map +1 -1
  15. package/dist/es/frameloop/frame-data.mjs +12 -0
  16. package/dist/es/frameloop/frame-data.mjs.map +1 -0
  17. package/dist/es/frameloop/frame.mjs +3 -2
  18. package/dist/es/frameloop/frame.mjs.map +1 -1
  19. package/dist/es/frameloop/sync-time.mjs +1 -1
  20. package/dist/es/frameloop/sync-time.mjs.map +1 -1
  21. package/dist/es/index.mjs +2 -2
  22. package/dist/es/layout/LayoutAnimationBuilder.mjs +2 -1
  23. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  24. package/dist/es/projection/animation/mix-values.mjs +1 -1
  25. package/dist/es/projection/animation/mix-values.mjs.map +1 -1
  26. package/dist/es/projection/node/create-projection-node.mjs +32 -10
  27. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  28. package/dist/es/projection/styles/default-scale-correctors.mjs +18 -0
  29. package/dist/es/projection/styles/default-scale-correctors.mjs.map +1 -0
  30. package/dist/es/projection/styles/scale-correction.mjs +1 -14
  31. package/dist/es/projection/styles/scale-correction.mjs.map +1 -1
  32. package/dist/es/projection/utils/each-axis.mjs.map +1 -1
  33. package/dist/es/render/VisualElement.mjs +12 -2
  34. package/dist/es/render/VisualElement.mjs.map +1 -1
  35. package/dist/es/render/svg/SVGVisualElement.mjs +19 -1
  36. package/dist/es/render/svg/SVGVisualElement.mjs.map +1 -1
  37. package/dist/es/value/follow-value.mjs +8 -85
  38. package/dist/es/value/follow-value.mjs.map +1 -1
  39. package/dist/es/value/spring-value.mjs +8 -3
  40. package/dist/es/value/spring-value.mjs.map +1 -1
  41. package/dist/es/value/utils/as-number.mjs +4 -0
  42. package/dist/es/value/utils/as-number.mjs.map +1 -0
  43. package/dist/es/value/utils/follow.mjs +94 -0
  44. package/dist/es/value/utils/follow.mjs.map +1 -0
  45. package/dist/index.d.ts +31 -22
  46. package/dist/motion-dom.dev.js +469 -415
  47. package/dist/motion-dom.js +1 -1
  48. package/dist/size-rollup-motion-value.js +1 -1
  49. package/dist/size-rollup-motion-value.js.map +1 -1
  50. package/dist/size-rollup-style-effect.js +1 -1
  51. package/dist/size-rollup-style-effect.js.map +1 -1
  52. package/package.json +6 -5
  53. package/dist/es/scroll/observe.mjs +0 -19
  54. package/dist/es/scroll/observe.mjs.map +0 -1
@@ -4,170 +4,15 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MotionDom = {}, global.MotionUtils));
5
5
  })(this, (function (exports, motionUtils) { 'use strict';
6
6
 
7
- const stepsOrder = [
8
- "setup", // Compute
9
- "read", // Read
10
- "resolveKeyframes", // Write/Read/Write/Read
11
- "preUpdate", // Compute
12
- "update", // Compute
13
- "preRender", // Compute
14
- "render", // Write
15
- "postRender", // Compute
16
- ];
17
-
18
- function createRenderStep(runNextFrame) {
19
- /**
20
- * We create and reuse two queues, one to queue jobs for the current frame
21
- * and one for the next. We reuse to avoid triggering GC after x frames.
22
- */
23
- let thisFrame = new Set();
24
- let nextFrame = new Set();
25
- /**
26
- * Track whether we're currently processing jobs in this step. This way
27
- * we can decide whether to schedule new jobs for this frame or next.
28
- */
29
- let isProcessing = false;
30
- let flushNextFrame = false;
31
- /**
32
- * A set of processes which were marked keepAlive when scheduled.
33
- * A keepAlive process is always also held by a frame queue until
34
- * it's cancelled, so a Set has the same lifetime semantics as a
35
- * WeakSet here while being considerably faster to query every frame.
36
- */
37
- const toKeepAlive = new Set();
38
- let latestFrameData = {
39
- delta: 0.0,
40
- timestamp: 0.0,
41
- isProcessing: false,
42
- };
43
- function triggerCallback(callback) {
44
- if (toKeepAlive.has(callback)) {
45
- nextFrame.add(callback);
46
- runNextFrame();
47
- }
48
- callback(latestFrameData);
49
- }
50
- const step = {
51
- /**
52
- * Schedule a process to run on the next frame.
53
- */
54
- schedule: (callback, keepAlive = false, immediate = false) => {
55
- const addToCurrentFrame = immediate && isProcessing;
56
- const queue = addToCurrentFrame ? thisFrame : nextFrame;
57
- if (keepAlive)
58
- toKeepAlive.add(callback);
59
- queue.add(callback);
60
- return callback;
61
- },
62
- /**
63
- * Cancel the provided callback from running on the next frame.
64
- */
65
- cancel: (callback) => {
66
- nextFrame.delete(callback);
67
- toKeepAlive.delete(callback);
68
- },
69
- /**
70
- * Execute all schedule callbacks.
71
- */
72
- process: (frameData) => {
73
- latestFrameData = frameData;
74
- /**
75
- * If we're already processing we've probably been triggered by a flushSync
76
- * inside an existing process. Instead of executing, mark flushNextFrame
77
- * as true and ensure we flush the following frame at the end of this one.
78
- */
79
- if (isProcessing) {
80
- flushNextFrame = true;
81
- return;
82
- }
83
- isProcessing = true;
84
- // Swap this frame and the next to avoid GC
85
- const prevFrame = thisFrame;
86
- thisFrame = nextFrame;
87
- nextFrame = prevFrame;
88
- // Execute this frame
89
- thisFrame.forEach(triggerCallback);
90
- // Clear the frame so no callbacks remain. This is to avoid
91
- // memory leaks should this render step not run for a while.
92
- thisFrame.clear();
93
- isProcessing = false;
94
- if (flushNextFrame) {
95
- flushNextFrame = false;
96
- step.process(frameData);
97
- }
98
- },
99
- };
100
- return step;
101
- }
102
-
103
- const maxElapsed = 40;
104
- function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
105
- let runNextFrame = false;
106
- let useDefaultElapsed = true;
107
- const state = {
108
- delta: 0.0,
109
- timestamp: 0.0,
110
- isProcessing: false,
111
- };
112
- const flagRunNextFrame = () => (runNextFrame = true);
113
- const steps = stepsOrder.reduce((acc, key) => {
114
- acc[key] = createRenderStep(flagRunNextFrame);
115
- return acc;
116
- }, {});
117
- const { setup, read, resolveKeyframes, preUpdate, update, preRender, render, postRender, } = steps;
118
- const processBatch = () => {
119
- const useManualTiming = motionUtils.MotionGlobalConfig.useManualTiming;
120
- const timestamp = useManualTiming
121
- ? state.timestamp
122
- : performance.now();
123
- runNextFrame = false;
124
- if (!useManualTiming) {
125
- state.delta = useDefaultElapsed
126
- ? 1000 / 60
127
- : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
128
- }
129
- state.timestamp = timestamp;
130
- state.isProcessing = true;
131
- // Unrolled render loop for better per-frame performance
132
- setup.process(state);
133
- read.process(state);
134
- resolveKeyframes.process(state);
135
- preUpdate.process(state);
136
- update.process(state);
137
- preRender.process(state);
138
- render.process(state);
139
- postRender.process(state);
140
- state.isProcessing = false;
141
- if (runNextFrame && allowKeepAlive) {
142
- useDefaultElapsed = false;
143
- scheduleNextBatch(processBatch);
144
- }
145
- };
146
- const wake = () => {
147
- runNextFrame = true;
148
- useDefaultElapsed = true;
149
- if (!state.isProcessing) {
150
- scheduleNextBatch(processBatch);
151
- }
152
- };
153
- const schedule = stepsOrder.reduce((acc, key) => {
154
- const step = steps[key];
155
- acc[key] = (process, keepAlive = false, immediate = false) => {
156
- if (!runNextFrame)
157
- wake();
158
- return step.schedule(process, keepAlive, immediate);
159
- };
160
- return acc;
161
- }, {});
162
- const cancel = (process) => {
163
- for (let i = 0; i < stepsOrder.length; i++) {
164
- steps[stepsOrder[i]].cancel(process);
165
- }
166
- };
167
- return { schedule, cancel, state, steps };
168
- }
169
-
170
- const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
7
+ /**
8
+ * The frameloop's state, kept apart from the frameloop itself so that
9
+ * reading it doesn't bundle the scheduler.
10
+ */
11
+ const frameData = {
12
+ delta: 0.0,
13
+ timestamp: 0.0,
14
+ isProcessing: false,
15
+ };
171
16
 
172
17
  let now;
173
18
  function clearTime() {
@@ -751,6 +596,170 @@
751
596
  return mixer(from, to);
752
597
  }
753
598
 
599
+ const stepsOrder = [
600
+ "setup", // Compute
601
+ "read", // Read
602
+ "resolveKeyframes", // Write/Read/Write/Read
603
+ "preUpdate", // Compute
604
+ "update", // Compute
605
+ "preRender", // Compute
606
+ "render", // Write
607
+ "postRender", // Compute
608
+ ];
609
+
610
+ function createRenderStep(runNextFrame) {
611
+ /**
612
+ * We create and reuse two queues, one to queue jobs for the current frame
613
+ * and one for the next. We reuse to avoid triggering GC after x frames.
614
+ */
615
+ let thisFrame = new Set();
616
+ let nextFrame = new Set();
617
+ /**
618
+ * Track whether we're currently processing jobs in this step. This way
619
+ * we can decide whether to schedule new jobs for this frame or next.
620
+ */
621
+ let isProcessing = false;
622
+ let flushNextFrame = false;
623
+ /**
624
+ * A set of processes which were marked keepAlive when scheduled.
625
+ * A keepAlive process is always also held by a frame queue until
626
+ * it's cancelled, so a Set has the same lifetime semantics as a
627
+ * WeakSet here while being considerably faster to query every frame.
628
+ */
629
+ const toKeepAlive = new Set();
630
+ let latestFrameData = {
631
+ delta: 0.0,
632
+ timestamp: 0.0,
633
+ isProcessing: false,
634
+ };
635
+ function triggerCallback(callback) {
636
+ if (toKeepAlive.has(callback)) {
637
+ nextFrame.add(callback);
638
+ runNextFrame();
639
+ }
640
+ callback(latestFrameData);
641
+ }
642
+ const step = {
643
+ /**
644
+ * Schedule a process to run on the next frame.
645
+ */
646
+ schedule: (callback, keepAlive = false, immediate = false) => {
647
+ const addToCurrentFrame = immediate && isProcessing;
648
+ const queue = addToCurrentFrame ? thisFrame : nextFrame;
649
+ if (keepAlive)
650
+ toKeepAlive.add(callback);
651
+ queue.add(callback);
652
+ return callback;
653
+ },
654
+ /**
655
+ * Cancel the provided callback from running on the next frame.
656
+ */
657
+ cancel: (callback) => {
658
+ nextFrame.delete(callback);
659
+ toKeepAlive.delete(callback);
660
+ },
661
+ /**
662
+ * Execute all schedule callbacks.
663
+ */
664
+ process: (frameData) => {
665
+ latestFrameData = frameData;
666
+ /**
667
+ * If we're already processing we've probably been triggered by a flushSync
668
+ * inside an existing process. Instead of executing, mark flushNextFrame
669
+ * as true and ensure we flush the following frame at the end of this one.
670
+ */
671
+ if (isProcessing) {
672
+ flushNextFrame = true;
673
+ return;
674
+ }
675
+ isProcessing = true;
676
+ // Swap this frame and the next to avoid GC
677
+ const prevFrame = thisFrame;
678
+ thisFrame = nextFrame;
679
+ nextFrame = prevFrame;
680
+ // Execute this frame
681
+ thisFrame.forEach(triggerCallback);
682
+ // Clear the frame so no callbacks remain. This is to avoid
683
+ // memory leaks should this render step not run for a while.
684
+ thisFrame.clear();
685
+ isProcessing = false;
686
+ if (flushNextFrame) {
687
+ flushNextFrame = false;
688
+ step.process(frameData);
689
+ }
690
+ },
691
+ };
692
+ return step;
693
+ }
694
+
695
+ const maxElapsed = 40;
696
+ function createRenderBatcher(scheduleNextBatch, allowKeepAlive, state = {
697
+ delta: 0.0,
698
+ timestamp: 0.0,
699
+ isProcessing: false,
700
+ }) {
701
+ let runNextFrame = false;
702
+ let useDefaultElapsed = true;
703
+ const flagRunNextFrame = () => (runNextFrame = true);
704
+ const steps = stepsOrder.reduce((acc, key) => {
705
+ acc[key] = createRenderStep(flagRunNextFrame);
706
+ return acc;
707
+ }, {});
708
+ const { setup, read, resolveKeyframes, preUpdate, update, preRender, render, postRender, } = steps;
709
+ const processBatch = () => {
710
+ const useManualTiming = motionUtils.MotionGlobalConfig.useManualTiming;
711
+ const timestamp = useManualTiming
712
+ ? state.timestamp
713
+ : performance.now();
714
+ runNextFrame = false;
715
+ if (!useManualTiming) {
716
+ state.delta = useDefaultElapsed
717
+ ? 1000 / 60
718
+ : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
719
+ }
720
+ state.timestamp = timestamp;
721
+ state.isProcessing = true;
722
+ // Unrolled render loop for better per-frame performance
723
+ setup.process(state);
724
+ read.process(state);
725
+ resolveKeyframes.process(state);
726
+ preUpdate.process(state);
727
+ update.process(state);
728
+ preRender.process(state);
729
+ render.process(state);
730
+ postRender.process(state);
731
+ state.isProcessing = false;
732
+ if (runNextFrame && allowKeepAlive) {
733
+ useDefaultElapsed = false;
734
+ scheduleNextBatch(processBatch);
735
+ }
736
+ };
737
+ const wake = () => {
738
+ runNextFrame = true;
739
+ useDefaultElapsed = true;
740
+ if (!state.isProcessing) {
741
+ scheduleNextBatch(processBatch);
742
+ }
743
+ };
744
+ const schedule = stepsOrder.reduce((acc, key) => {
745
+ const step = steps[key];
746
+ acc[key] = (process, keepAlive = false, immediate = false) => {
747
+ if (!runNextFrame)
748
+ wake();
749
+ return step.schedule(process, keepAlive, immediate);
750
+ };
751
+ return acc;
752
+ }, {});
753
+ const cancel = (process) => {
754
+ for (let i = 0; i < stepsOrder.length; i++) {
755
+ steps[stepsOrder[i]].cancel(process);
756
+ }
757
+ };
758
+ return { schedule, cancel, state, steps };
759
+ }
760
+
761
+ const { schedule: frame, cancel: cancelFrame, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true, frameData);
762
+
754
763
  const frameloopDriver = (update) => {
755
764
  const passTimestamp = ({ timestamp }) => update(timestamp);
756
765
  return {
@@ -812,7 +821,6 @@
812
821
  stiffness: 100,
813
822
  damping: 10,
814
823
  mass: 1.0,
815
- velocity: 0.0,
816
824
  // Default duration/bounce-based options
817
825
  duration: 800, // in ms
818
826
  bounce: 0.3,
@@ -830,8 +838,37 @@
830
838
  minDuration: 0.01, // in seconds
831
839
  maxDuration: 10.0, // in seconds
832
840
  minDamping: 0.05,
833
- maxDamping: 1,
834
841
  };
842
+ /**
843
+ * Maps bounce to a damping ratio as SwiftUI does: 0 is critically damped, and
844
+ * it approaches undamped towards 1 and infinitely overdamped towards -1. Both
845
+ * ends are limited so the spring still moves and settles.
846
+ */
847
+ const bounceToDampingRatio = (bounce) => bounce < 0
848
+ ? 1 / Math.max(1 + bounce, springDefaults.minDamping)
849
+ : Math.max(1 - bounce, springDefaults.minDamping);
850
+ /**
851
+ * Scales an overdamped spring's undamped frequency so that, at its defining
852
+ * time, it has as far left to go as the critically damped spring that's
853
+ * criticalFreqTime radians in by then. A negative bounce then changes the
854
+ * shape of the curve, not when it arrives. 1 at a damping ratio of 1, so
855
+ * there's no jump at a bounce of 0.
856
+ *
857
+ * Solved by Newton on the remaining distance (times fast - slow), which is
858
+ * convex from criticalFreqTime onwards. criticalFreqTime is always below the
859
+ * answer, so it converges from below without overshooting.
860
+ */
861
+ function overdampedFreqScale(dampingRatio, criticalFreqTime) {
862
+ if (!(dampingRatio > 1))
863
+ return 1;
864
+ const root = Math.sqrt(dampingRatio * dampingRatio - 1);
865
+ const slow = dampingRatio - root;
866
+ const fast = dampingRatio + root;
867
+ const target = 2 * root * Math.exp(-criticalFreqTime) * (1 + criticalFreqTime);
868
+ return (approximateRoot((freqTime) => fast * Math.exp(-slow * freqTime) -
869
+ slow * Math.exp(-fast * freqTime) -
870
+ target, (freqTime) => Math.exp(-fast * freqTime) - Math.exp(-slow * freqTime), criticalFreqTime) / criticalFreqTime);
871
+ }
835
872
  function calcAngularFreq(undampedFreq, dampingRatio) {
836
873
  return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
837
874
  }
@@ -847,15 +884,16 @@
847
884
  * This is ported from the Framer implementation of duration-based spring resolution.
848
885
  */
849
886
  const safeMin = 0.001;
850
- function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
887
+ /**
888
+ * Assumes zero initial velocity and the default mass: time-defined springs
889
+ * ignore inherited velocity and only resolve without valid physics. Returns
890
+ * NaN physics when the root search doesn't converge.
891
+ */
892
+ function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, }) {
851
893
  let envelope;
852
894
  let derivative;
853
895
  motionUtils.warning(duration <= motionUtils.secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less", "spring-duration-limit");
854
- let dampingRatio = 1 - bounce;
855
- /**
856
- * Restrict dampingRatio and duration to within acceptable ranges.
857
- */
858
- dampingRatio = motionUtils.clamp(springDefaults.minDamping, springDefaults.maxDamping, dampingRatio);
896
+ const dampingRatio = bounceToDampingRatio(bounce);
859
897
  duration = motionUtils.clamp(springDefaults.minDuration, springDefaults.maxDuration, motionUtils.millisecondsToSeconds(duration));
860
898
  if (dampingRatio < 1) {
861
899
  /**
@@ -864,15 +902,13 @@
864
902
  envelope = (undampedFreq) => {
865
903
  const exponentialDecay = undampedFreq * dampingRatio;
866
904
  const delta = exponentialDecay * duration;
867
- const a = exponentialDecay - velocity;
868
905
  const b = calcAngularFreq(undampedFreq, dampingRatio);
869
906
  const c = Math.exp(-delta);
870
- return safeMin - (a / b) * c;
907
+ return safeMin - (exponentialDecay / b) * c;
871
908
  };
872
909
  derivative = (undampedFreq) => {
873
910
  const exponentialDecay = undampedFreq * dampingRatio;
874
911
  const delta = exponentialDecay * duration;
875
- const d = delta * velocity + velocity;
876
912
  const e = dampingRatio *
877
913
  dampingRatio *
878
914
  undampedFreq *
@@ -881,46 +917,35 @@
881
917
  const f = Math.exp(-delta);
882
918
  const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio);
883
919
  const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
884
- return (factor * ((d - e) * f)) / g;
920
+ return (factor * -e * f) / g;
885
921
  };
886
922
  }
887
923
  else {
888
924
  /**
889
- * Critically-damped spring
925
+ * Critically-damped spring. Overdamped springs reuse this root,
926
+ * scaled below.
890
927
  */
891
928
  envelope = (undampedFreq) => {
892
929
  const a = Math.exp(-undampedFreq * duration);
893
- const b = (undampedFreq - velocity) * duration + 1;
930
+ const b = undampedFreq * duration + 1;
894
931
  return -safeMin + a * b;
895
932
  };
896
933
  derivative = (undampedFreq) => {
897
934
  const a = Math.exp(-undampedFreq * duration);
898
- const b = (velocity - undampedFreq) * (duration * duration);
935
+ const b = -undampedFreq * (duration * duration);
899
936
  return a * b;
900
937
  };
901
938
  }
902
939
  const initialGuess = 5 / duration;
903
- const undampedFreq = approximateRoot(envelope, derivative, initialGuess);
904
- duration = motionUtils.secondsToMilliseconds(duration);
905
- if (isNaN(undampedFreq)) {
906
- return {
907
- stiffness: springDefaults.stiffness,
908
- damping: springDefaults.damping,
909
- duration,
910
- };
911
- }
912
- else {
913
- const stiffness = undampedFreq * undampedFreq * mass;
914
- return {
915
- stiffness,
916
- damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
917
- duration,
918
- };
919
- }
920
- }
921
- const durationKeys = ["duration", "bounce"];
922
- function isSpringType(options, keys) {
923
- return keys.some((key) => options[key] !== undefined);
940
+ const criticalFreq = approximateRoot(envelope, derivative, initialGuess);
941
+ const undampedFreq = criticalFreq *
942
+ overdampedFreqScale(dampingRatio, criticalFreq * duration);
943
+ const stiffness = undampedFreq * undampedFreq;
944
+ return {
945
+ stiffness,
946
+ damping: dampingRatio * 2 * Math.sqrt(stiffness),
947
+ duration: motionUtils.secondsToMilliseconds(duration),
948
+ };
924
949
  }
925
950
  /**
926
951
  * Spring physics must be finite. stiffness and mass are also divisors so must
@@ -952,7 +977,7 @@
952
977
  const validStiffness = resolvePhysics(options.stiffness);
953
978
  const validDamping = resolvePhysics(options.damping, true);
954
979
  const validMass = resolvePhysics(options.mass);
955
- let springOptions = {
980
+ const springOptions = {
956
981
  ...options,
957
982
  stiffness: validStiffness ?? springDefaults.stiffness,
958
983
  damping: validDamping ?? springDefaults.damping,
@@ -960,42 +985,27 @@
960
985
  isResolvedFromDuration: false,
961
986
  // stiffness/damping/mass overrides duration/bounce
962
987
  isTimeDefined: (validStiffness ?? validDamping ?? validMass) === undefined &&
963
- isSpringType(options, durationKeys),
988
+ (options.duration !== undefined || options.bounce !== undefined),
964
989
  };
965
990
  if (springOptions.isTimeDefined) {
966
- // Time-defined springs should ignore inherited velocity.
967
- // Velocity from interrupted animations can cause findSpring()
968
- // to compute wildly different spring parameters, leading to
969
- // massive oscillation on small-range animations.
970
- springOptions.velocity = 0;
971
991
  if (options.visualDuration) {
972
- const visualDuration = options.visualDuration;
973
- const root = (2 * Math.PI) / (visualDuration * 1.2);
974
- const stiffness = root * root;
975
- const damping = 2 *
976
- motionUtils.clamp(0.05, 1, 1 - (options.bounce || 0)) *
977
- Math.sqrt(stiffness);
978
- springOptions = {
979
- ...springOptions,
980
- mass: springDefaults.mass,
981
- stiffness,
982
- damping,
983
- };
992
+ const dampingRatio = bounceToDampingRatio(options.bounce || 0);
993
+ const root = ((2 * Math.PI) / (options.visualDuration * 1.2)) *
994
+ overdampedFreqScale(dampingRatio, (2 * Math.PI) / 1.2);
995
+ springOptions.stiffness = root * root;
996
+ springOptions.damping =
997
+ 2 * dampingRatio * Math.sqrt(springOptions.stiffness);
984
998
  }
985
999
  else {
986
- const derived = findSpring(springOptions);
987
- springOptions = {
988
- ...springOptions,
989
- ...derived,
990
- mass: springDefaults.mass,
991
- };
1000
+ Object.assign(springOptions, findSpring(springOptions));
992
1001
  springOptions.isResolvedFromDuration = true;
993
1002
  }
994
1003
  /**
995
- * Non-finite time options degenerate: a NaN bounce gives a NaN
996
- * damping, an infinite visualDuration a 0 stiffness. Replace the two
997
- * together, so the relationship duration resolution establishes
998
- * between them is never left half-overwritten.
1004
+ * Time options can degenerate: a NaN bounce gives a NaN damping, an
1005
+ * infinite visualDuration a 0 stiffness, and findSpring NaN for both
1006
+ * when it doesn't converge. Replace the two together, so the
1007
+ * relationship duration resolution establishes between them is never
1008
+ * left half-overwritten.
999
1009
  */
1000
1010
  if (!isValidPhysics(springOptions.stiffness) ||
1001
1011
  !isValidPhysics(springOptions.damping, true)) {
@@ -1020,10 +1030,13 @@
1020
1030
  * to reduce GC during animation.
1021
1031
  */
1022
1032
  const state = { done: false, value: origin };
1023
- const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, isTimeDefined, } = getSpringOptions({
1024
- ...options,
1025
- velocity: -motionUtils.millisecondsToSeconds(options.velocity || 0),
1026
- });
1033
+ const { stiffness, damping, mass, duration, isResolvedFromDuration, isTimeDefined, } = getSpringOptions({ ...options });
1034
+ /**
1035
+ * Time-defined springs ignore inherited velocity. Velocity from
1036
+ * interrupted animations causes massive oscillation on small-range
1037
+ * animations.
1038
+ */
1039
+ const inheritVelocity = (velocity) => isTimeDefined ? 0 : -motionUtils.millisecondsToSeconds(velocity);
1027
1040
  const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
1028
1041
  const undampedAngularFreq = motionUtils.millisecondsToSeconds(Math.sqrt(stiffness / mass));
1029
1042
  const decay = dampingRatio * undampedAngularFreq;
@@ -1037,7 +1050,7 @@
1037
1050
  const s = {
1038
1051
  target,
1039
1052
  delta: target - origin,
1040
- velocity: velocity || 0.0,
1053
+ velocity: inheritVelocity(options.velocity || 0) || 0,
1041
1054
  restSpeed: 0,
1042
1055
  restDelta: 0,
1043
1056
  };
@@ -1116,31 +1129,32 @@
1116
1129
  (undampedAngularFreq * c.C * t - s.velocity);
1117
1130
  }
1118
1131
  else {
1119
- // Overdamped spring
1132
+ /**
1133
+ * Overdamped spring: the sum of a slow and a fast decaying
1134
+ * exponential, so no term can overflow however heavily it's damped.
1135
+ */
1120
1136
  const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
1121
- resolveSpring = (t) => {
1122
- const envelope = Math.exp(-decay * t);
1123
- // When performing sinh or cosh values can hit Infinity so we cap them here
1124
- const freqForT = Math.min(dampedAngularFreq * t, 300);
1125
- return (s.target -
1126
- (envelope *
1127
- ((s.velocity + decay * s.delta) * Math.sinh(freqForT) +
1128
- dampedAngularFreq * s.delta * Math.cosh(freqForT))) /
1129
- dampedAngularFreq);
1130
- };
1131
- // Analytical derivative of overdamped spring (px/ms)
1132
- const c = { P: 0, sinh: 0, cosh: 0 };
1137
+ const slow = decay - dampedAngularFreq;
1138
+ const fast = decay + dampedAngularFreq;
1139
+ /**
1140
+ * Physics-defined springs keep a non-physical limit: once
1141
+ * dampedAngularFreq * t passes 300, both terms decay at the damping
1142
+ * rate. Heavily overdamped drag springs (dragElastic: 0,
1143
+ * dragTransition) rely on this to settle almost at once rather than
1144
+ * creep at stiffness / damping. Negative bounce needs the exact
1145
+ * curve, so time-defined springs are exempt.
1146
+ */
1147
+ const limit = isTimeDefined ? Infinity : 300 / dampedAngularFreq;
1148
+ const decayAt = (rate, t) => Math.exp(t > limit ? -rate * limit - decay * (t - limit) : -rate * t);
1149
+ const c = { S: 0, F: 0 };
1133
1150
  update = () => {
1134
- c.P = (s.velocity + decay * s.delta) / dampedAngularFreq;
1135
- c.sinh = decay * c.P - s.delta * dampedAngularFreq;
1136
- c.cosh = decay * s.delta - c.P * dampedAngularFreq;
1137
- };
1138
- resolveVelocity = (t) => {
1139
- const envelope = Math.exp(-decay * t);
1140
- const freqForT = Math.min(dampedAngularFreq * t, 300);
1141
- return (envelope *
1142
- (c.sinh * Math.sinh(freqForT) + c.cosh * Math.cosh(freqForT)));
1151
+ const P = (s.velocity + decay * s.delta) / dampedAngularFreq;
1152
+ c.S = (s.delta + P) / 2;
1153
+ c.F = (s.delta - P) / 2;
1143
1154
  };
1155
+ resolveSpring = (t) => s.target - c.S * decayAt(slow, t) - c.F * decayAt(fast, t);
1156
+ // Analytical derivative of overdamped spring (px/ms)
1157
+ resolveVelocity = (t) => slow * c.S * decayAt(slow, t) + fast * c.F * decayAt(fast, t);
1144
1158
  }
1145
1159
  update();
1146
1160
  const calculatedDuration = isResolvedFromDuration ? duration || null : null;
@@ -1153,8 +1167,7 @@
1153
1167
  retarget: (keyframes, newVelocity) => {
1154
1168
  s.target = keyframes[keyframes.length - 1];
1155
1169
  s.delta = s.target - keyframes[0];
1156
- // Time-defined springs ignore inherited velocity, see getSpringOptions
1157
- s.velocity = isTimeDefined ? 0 : -motionUtils.millisecondsToSeconds(newVelocity);
1170
+ s.velocity = inheritVelocity(newVelocity);
1158
1171
  // Default thresholds depend on the scale of the new delta
1159
1172
  if (!(options.restSpeed && options.restDelta))
1160
1173
  setRestThresholds();
@@ -2719,17 +2732,14 @@
2719
2732
  /**
2720
2733
  * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
2721
2734
  */
2722
- attachTimeline({ timeline, rangeStart, rangeEnd, observe, }) {
2735
+ attachTimeline({ timeline, onAttach, observe, }) {
2723
2736
  if (this.allowFlatten) {
2724
2737
  this.animation.effect?.updateTiming({ easing: "linear" });
2725
2738
  }
2726
2739
  this.animation.onfinish = null;
2727
2740
  if (timeline && supportsScrollTimeline()) {
2728
2741
  this.animation.timeline = timeline;
2729
- if (rangeStart)
2730
- this.animation.rangeStart = rangeStart;
2731
- if (rangeEnd)
2732
- this.animation.rangeEnd = rangeEnd;
2742
+ onAttach?.(this.animation);
2733
2743
  return motionUtils.noop;
2734
2744
  }
2735
2745
  else {
@@ -6062,21 +6072,6 @@
6062
6072
  return typeof a === "function" ? resizeWindow(a) : resizeElement(a, b);
6063
6073
  }
6064
6074
 
6065
- function observeTimeline(update, timeline) {
6066
- let prevProgress;
6067
- const onFrame = () => {
6068
- const { currentTime } = timeline;
6069
- const percentage = currentTime === null ? 0 : currentTime.value;
6070
- const progress = percentage / 100;
6071
- if (prevProgress !== progress) {
6072
- update(progress);
6073
- }
6074
- prevProgress = progress;
6075
- };
6076
- frame.preUpdate(onFrame, true);
6077
- return () => cancelFrame(onFrame);
6078
- }
6079
-
6080
6075
  const statsBuffer = {
6081
6076
  value: null,
6082
6077
  addProjectionMetrics: null,
@@ -6190,8 +6185,7 @@
6190
6185
  this.options.onStop?.();
6191
6186
  };
6192
6187
  this.options = options;
6193
- replaceTransitionType(options);
6194
- this.factory = options.type || keyframes;
6188
+ this.factory = options.type;
6195
6189
  this.generator = this.factory(options);
6196
6190
  const { driver } = options;
6197
6191
  if (driver)
@@ -6292,41 +6286,15 @@
6292
6286
  }
6293
6287
  }
6294
6288
 
6289
+ const asNumber = (v) => typeof v === "number" ? v : parseFloat(v);
6290
+
6295
6291
  /**
6296
- * Create a `MotionValue` that animates to its latest value using any transition type.
6297
- * Can either be a value or track another `MotionValue`.
6298
- *
6299
- * ```jsx
6300
- * const x = motionValue(0)
6301
- * const y = followValue(x, { type: "spring", stiffness: 300 })
6302
- * // or with tween
6303
- * const z = followValue(x, { type: "tween", duration: 0.5, ease: "easeOut" })
6304
- * ```
6305
- *
6306
- * @param source - Initial value or MotionValue to track
6307
- * @param options - Animation transition options
6308
- * @returns `MotionValue`
6309
- *
6310
- * @public
6311
- */
6312
- function followValue(source, options) {
6313
- const initialValue = isMotionValue(source) ? source.get() : source;
6314
- const value = motionValue(initialValue);
6315
- attachFollow(value, source, options);
6316
- return value;
6317
- }
6318
- /**
6319
- * Attach an animation to a MotionValue that will animate whenever the value changes.
6320
- * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)
6321
- *
6322
- * @param value - The MotionValue to animate
6323
- * @param source - Initial value or MotionValue to track
6324
- * @param options - Animation transition options
6325
- * @returns Cleanup function
6326
- *
6327
- * @public
6292
+ * Animate `value` to its latest value with the generator in
6293
+ * `options.type`, tracking `source` if it's a `MotionValue`. Takes a
6294
+ * generator rather than a type name, so spring-only callers don't
6295
+ * bundle every generator.
6328
6296
  */
6329
- function attachFollow(value, source, options = {}) {
6297
+ function follow(value, source, options) {
6330
6298
  const initialValue = value.get();
6331
6299
  let activeAnimation = null;
6332
6300
  let set;
@@ -6344,7 +6312,7 @@
6344
6312
  };
6345
6313
  value.attach((v, safeSet) => {
6346
6314
  set = safeSet;
6347
- const target = asNumber$1(v);
6315
+ const target = asNumber(v);
6348
6316
  if (activeAnimation?.state === "running") {
6349
6317
  /**
6350
6318
  * Steer the running animation rather than replacing it. This
@@ -6355,7 +6323,7 @@
6355
6323
  activeAnimation.setTarget(target, options.velocity);
6356
6324
  return;
6357
6325
  }
6358
- const current = asNumber$1(value.get());
6326
+ const current = asNumber(value.get());
6359
6327
  const velocity = activeAnimation
6360
6328
  ? activeAnimation.getGeneratorVelocity()
6361
6329
  : value.getVelocity();
@@ -6366,8 +6334,6 @@
6366
6334
  const animationOptions = {
6367
6335
  keyframes: [current, target],
6368
6336
  velocity,
6369
- // Default to spring if no type specified (matches useSpring behavior)
6370
- type: "spring",
6371
6337
  restDelta: 0.001,
6372
6338
  restSpeed: 0.01,
6373
6339
  ...options,
@@ -6409,8 +6375,47 @@
6409
6375
  function parseValue(v, unit) {
6410
6376
  return unit ? v + unit : v;
6411
6377
  }
6412
- function asNumber$1(v) {
6413
- return typeof v === "number" ? v : parseFloat(v);
6378
+
6379
+ /**
6380
+ * Create a `MotionValue` that animates to its latest value using any transition type.
6381
+ * Can either be a value or track another `MotionValue`.
6382
+ *
6383
+ * ```jsx
6384
+ * const x = motionValue(0)
6385
+ * const y = followValue(x, { type: "spring", stiffness: 300 })
6386
+ * // or with tween
6387
+ * const z = followValue(x, { type: "tween", duration: 0.5, ease: "easeOut" })
6388
+ * ```
6389
+ *
6390
+ * @param source - Initial value or MotionValue to track
6391
+ * @param options - Animation transition options
6392
+ * @returns `MotionValue`
6393
+ *
6394
+ * @public
6395
+ */
6396
+ function followValue(source, options) {
6397
+ const initialValue = isMotionValue(source) ? source.get() : source;
6398
+ const value = motionValue(initialValue);
6399
+ attachFollow(value, source, options);
6400
+ return value;
6401
+ }
6402
+ /**
6403
+ * Attach an animation to a MotionValue that will animate whenever the value changes.
6404
+ * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)
6405
+ *
6406
+ * @param value - The MotionValue to animate
6407
+ * @param source - Initial value or MotionValue to track
6408
+ * @param options - Animation transition options
6409
+ * @returns Cleanup function
6410
+ *
6411
+ * @public
6412
+ */
6413
+ function attachFollow(value, source, options = {}) {
6414
+ // Default to spring if no type specified (matches useSpring behavior)
6415
+ const transition = { type: "spring", ...options };
6416
+ replaceTransitionType(transition);
6417
+ transition.type = transition.type || keyframes;
6418
+ return follow(value, source, transition);
6414
6419
  }
6415
6420
 
6416
6421
  function subscribeValue(inputValues, outputValue, getLatest) {
@@ -6512,7 +6517,9 @@
6512
6517
  * @public
6513
6518
  */
6514
6519
  function springValue(source, options) {
6515
- return followValue(source, { type: "spring", ...options });
6520
+ const value = motionValue(isMotionValue(source) ? source.get() : source);
6521
+ attachSpring(value, source, options);
6522
+ return value;
6516
6523
  }
6517
6524
  /**
6518
6525
  * Attach a spring animation to a MotionValue that will animate whenever the value changes.
@@ -6525,7 +6532,7 @@
6525
6532
  * @public
6526
6533
  */
6527
6534
  function attachSpring(value, source, options) {
6528
- return attachFollow(value, source, { type: "spring", ...options });
6535
+ return follow(value, source, { ...options, type: spring });
6529
6536
  }
6530
6537
 
6531
6538
  /**
@@ -8195,7 +8202,15 @@
8195
8202
  this.removeValue(key);
8196
8203
  this.bindToMotionValue(key, value);
8197
8204
  this.values.set(key, value);
8198
- this.latestValues[key] = value.get();
8205
+ /**
8206
+ * An animated value with no base value is undefined until the
8207
+ * keyframe resolver reads its origin. Rendering it before then
8208
+ * writes an invalid placeholder (e.g. points="undefined") that
8209
+ * the resolver can read back from the DOM as the origin.
8210
+ */
8211
+ const latest = value.get();
8212
+ if (latest !== undefined)
8213
+ this.latestValues[key] = latest;
8199
8214
  }
8200
8215
  }
8201
8216
  /**
@@ -8223,7 +8238,9 @@
8223
8238
  }
8224
8239
  let value = this.values.get(key);
8225
8240
  if (value === undefined && defaultValue !== undefined) {
8226
- value = motionValue(defaultValue === null ? undefined : defaultValue, { owner: this });
8241
+ value = motionValue(defaultValue ?? this.getDefaultValue?.(key), {
8242
+ owner: this,
8243
+ });
8227
8244
  this.addValue(key, value);
8228
8245
  }
8229
8246
  return value;
@@ -8385,86 +8402,7 @@
8385
8402
  }
8386
8403
  }
8387
8404
 
8388
- function pixelsToPercent(pixels, axis) {
8389
- if (axis.max === axis.min)
8390
- return 0;
8391
- return (pixels / (axis.max - axis.min)) * 100;
8392
- }
8393
- /**
8394
- * We always correct borderRadius as a percentage rather than pixels to reduce paints.
8395
- * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
8396
- * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
8397
- * borderRadius in both states. If we animate between the two in pixels that will trigger
8398
- * a paint each time. If we animate between the two in percentage we'll avoid a paint.
8399
- */
8400
- const correctBorderRadius = {
8401
- correct: (latest, node) => {
8402
- if (!node.target)
8403
- return latest;
8404
- /**
8405
- * If latest is a string, if it's a percentage we can return immediately as it's
8406
- * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
8407
- */
8408
- if (typeof latest === "string") {
8409
- if (px.test(latest)) {
8410
- latest = parseFloat(latest);
8411
- }
8412
- else {
8413
- return latest;
8414
- }
8415
- }
8416
- /**
8417
- * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
8418
- * pixel value as a percentage of each axis
8419
- */
8420
- const x = pixelsToPercent(latest, node.target.x);
8421
- const y = pixelsToPercent(latest, node.target.y);
8422
- return `${x}% ${y}%`;
8423
- },
8424
- };
8425
-
8426
- const correctBoxShadow = {
8427
- correct: (latest, { treeScale, projectionDelta }) => {
8428
- const original = latest;
8429
- const shadow = complex.parse(latest);
8430
- // TODO: Doesn't support multiple shadows
8431
- if (shadow.length > 5)
8432
- return original;
8433
- const template = complex.createTransformer(latest);
8434
- const offset = typeof shadow[0] !== "number" ? 1 : 0;
8435
- // Calculate the overall context scale
8436
- const xScale = projectionDelta.x.scale * treeScale.x;
8437
- const yScale = projectionDelta.y.scale * treeScale.y;
8438
- shadow[0 + offset] /= xScale;
8439
- shadow[1 + offset] /= yScale;
8440
- /**
8441
- * Ideally we'd correct x and y scales individually, but because blur and
8442
- * spread apply to both we have to take a scale average and apply that instead.
8443
- * We could potentially improve the outcome of this by incorporating the ratio between
8444
- * the two scales.
8445
- */
8446
- const averageScale = mixNumber$1(xScale, yScale, 0.5);
8447
- // Blur
8448
- if (typeof shadow[2 + offset] === "number")
8449
- shadow[2 + offset] /= averageScale;
8450
- // Spread
8451
- if (typeof shadow[3 + offset] === "number")
8452
- shadow[3 + offset] /= averageScale;
8453
- return template(shadow);
8454
- },
8455
- };
8456
-
8457
- const scaleCorrectors = {
8458
- borderRadius: {
8459
- ...correctBorderRadius,
8460
- applyTo: [...cornerRadiusProps],
8461
- },
8462
- borderTopLeftRadius: correctBorderRadius,
8463
- borderTopRightRadius: correctBorderRadius,
8464
- borderBottomLeftRadius: correctBorderRadius,
8465
- borderBottomRightRadius: correctBorderRadius,
8466
- boxShadow: correctBoxShadow,
8467
- };
8405
+ const scaleCorrectors = {};
8468
8406
  function addScaleCorrector(correctors) {
8469
8407
  for (const key in correctors) {
8470
8408
  scaleCorrectors[key] = correctors[key];
@@ -8638,7 +8576,24 @@
8638
8576
  this.measureInstanceViewportBox = createBox;
8639
8577
  }
8640
8578
  getBaseTargetFromProps(props, key) {
8641
- return props[key];
8579
+ /**
8580
+ * An independent transform's base is never an attribute of the same
8581
+ * name, e.g. <rect x> is a position, not a translate. Like HTML it
8582
+ * comes from style, falling back to the transform's default.
8583
+ */
8584
+ return transformProps.has(key)
8585
+ ? super.getBaseTargetFromProps(props, key) ??
8586
+ defaultTransformValue(key)
8587
+ : props[key];
8588
+ }
8589
+ /**
8590
+ * An independent transform's origin is never read from the DOM, so it
8591
+ * starts from its latest or default value and renders on mount.
8592
+ */
8593
+ getDefaultValue(key) {
8594
+ return transformProps.has(key)
8595
+ ? this.latestValues[key] ?? defaultTransformValue(key)
8596
+ : undefined;
8642
8597
  }
8643
8598
  readValueFromInstance(instance, key) {
8644
8599
  if (transformProps.has(key)) {
@@ -9251,6 +9206,75 @@
9251
9206
  return [callback("x"), callback("y")];
9252
9207
  }
9253
9208
 
9209
+ function pixelsToPercent(pixels, axis) {
9210
+ if (axis.max === axis.min)
9211
+ return 0;
9212
+ return (pixels / (axis.max - axis.min)) * 100;
9213
+ }
9214
+ /**
9215
+ * We always correct borderRadius as a percentage rather than pixels to reduce paints.
9216
+ * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
9217
+ * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
9218
+ * borderRadius in both states. If we animate between the two in pixels that will trigger
9219
+ * a paint each time. If we animate between the two in percentage we'll avoid a paint.
9220
+ */
9221
+ const correctBorderRadius = {
9222
+ correct: (latest, node) => {
9223
+ if (!node.target)
9224
+ return latest;
9225
+ /**
9226
+ * If latest is a string, if it's a percentage we can return immediately as it's
9227
+ * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
9228
+ */
9229
+ if (typeof latest === "string") {
9230
+ if (px.test(latest)) {
9231
+ latest = parseFloat(latest);
9232
+ }
9233
+ else {
9234
+ return latest;
9235
+ }
9236
+ }
9237
+ /**
9238
+ * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
9239
+ * pixel value as a percentage of each axis
9240
+ */
9241
+ const x = pixelsToPercent(latest, node.target.x);
9242
+ const y = pixelsToPercent(latest, node.target.y);
9243
+ return `${x}% ${y}%`;
9244
+ },
9245
+ };
9246
+
9247
+ const correctBoxShadow = {
9248
+ correct: (latest, { treeScale, projectionDelta }) => {
9249
+ const original = latest;
9250
+ const shadow = complex.parse(latest);
9251
+ // TODO: Doesn't support multiple shadows
9252
+ if (shadow.length > 5)
9253
+ return original;
9254
+ const template = complex.createTransformer(latest);
9255
+ const offset = typeof shadow[0] !== "number" ? 1 : 0;
9256
+ // Calculate the overall context scale
9257
+ const xScale = projectionDelta.x.scale * treeScale.x;
9258
+ const yScale = projectionDelta.y.scale * treeScale.y;
9259
+ shadow[0 + offset] /= xScale;
9260
+ shadow[1 + offset] /= yScale;
9261
+ /**
9262
+ * Ideally we'd correct x and y scales individually, but because blur and
9263
+ * spread apply to both we have to take a scale average and apply that instead.
9264
+ * We could potentially improve the outcome of this by incorporating the ratio between
9265
+ * the two scales.
9266
+ */
9267
+ const averageScale = mixNumber$1(xScale, yScale, 0.5);
9268
+ // Blur
9269
+ if (typeof shadow[2 + offset] === "number")
9270
+ shadow[2 + offset] /= averageScale;
9271
+ // Spread
9272
+ if (typeof shadow[3 + offset] === "number")
9273
+ shadow[3 + offset] /= averageScale;
9274
+ return template(shadow);
9275
+ },
9276
+ };
9277
+
9254
9278
  function buildProjectionTransform(delta, treeScale, latestTransform) {
9255
9279
  let transform = "";
9256
9280
  /**
@@ -9303,7 +9327,6 @@
9303
9327
  }
9304
9328
 
9305
9329
  const numBorders = cornerRadiusProps.length;
9306
- const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
9307
9330
  const isPx = (value) => typeof value === "number" || px.test(value);
9308
9331
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
9309
9332
  if (shouldCrossfadeOpacity) {
@@ -9502,6 +9525,18 @@
9502
9525
  }
9503
9526
  }
9504
9527
 
9528
+ const defaultScaleCorrectors = {
9529
+ borderRadius: {
9530
+ ...correctBorderRadius,
9531
+ applyTo: [...cornerRadiusProps],
9532
+ },
9533
+ borderTopLeftRadius: correctBorderRadius,
9534
+ borderTopRightRadius: correctBorderRadius,
9535
+ borderBottomLeftRadius: correctBorderRadius,
9536
+ borderBottomRightRadius: correctBorderRadius,
9537
+ boxShadow: correctBoxShadow,
9538
+ };
9539
+
9505
9540
  /**
9506
9541
  * This should only ever be modified on the client otherwise it'll
9507
9542
  * persist through server requests. If we need instanced states we
@@ -9520,6 +9555,14 @@
9520
9555
  hasEverUpdated: false,
9521
9556
  };
9522
9557
 
9558
+ /**
9559
+ * Correctors registered via addScaleCorrector before projection loaded
9560
+ * (e.g. with an async LazyMotion bundle) take precedence over the defaults.
9561
+ */
9562
+ Object.assign(scaleCorrectors, {
9563
+ ...defaultScaleCorrectors,
9564
+ ...scaleCorrectors,
9565
+ });
9523
9566
  const metrics = {
9524
9567
  nodes: 0,
9525
9568
  calculatedTargetDeltas: 0,
@@ -9657,7 +9700,6 @@
9657
9700
  */
9658
9701
  this.eventHandlers = new Map();
9659
9702
  this.hasTreeAnimated = false;
9660
- this.layoutVersion = 0;
9661
9703
  // Note: Currently only running on root node
9662
9704
  this.updateScheduled = false;
9663
9705
  this.scheduleUpdate = () => this.update();
@@ -9697,7 +9739,6 @@
9697
9739
  * Frame calculations
9698
9740
  */
9699
9741
  this.resolvedRelativeTargetAt = 0.0;
9700
- this.linkedParentVersion = 0;
9701
9742
  this.hasProjected = false;
9702
9743
  this.isVisible = true;
9703
9744
  this.animationProgress = 0;
@@ -9978,6 +10019,7 @@
9978
10019
  * get measured even when memoized (willUpdate skipped).
9979
10020
  */
9980
10021
  this.nodes.forEach(ensureDraggedNodesSnapshotted);
10022
+ this.nodes.forEach(syncRelativeLayout);
9981
10023
  /**
9982
10024
  * Write
9983
10025
  */
@@ -10075,7 +10117,6 @@
10075
10117
  }
10076
10118
  const prevLayout = this.layout;
10077
10119
  this.layout = this.measure(false);
10078
- this.layoutVersion++;
10079
10120
  if (!this.layoutCorrected)
10080
10121
  this.layoutCorrected = createBox();
10081
10122
  this.isLayoutDirty = false;
@@ -10295,11 +10336,6 @@
10295
10336
  return;
10296
10337
  this.resolvedRelativeTargetAt = frameData.timestamp;
10297
10338
  const relativeParent = this.getClosestProjectingParent();
10298
- if (relativeParent &&
10299
- this.linkedParentVersion !== relativeParent.layoutVersion &&
10300
- !relativeParent.options.layoutRoot) {
10301
- this.removeRelativeTarget();
10302
- }
10303
10339
  /**
10304
10340
  * If we don't have a targetDelta but do have a layout, we can attempt to resolve
10305
10341
  * a relativeParent. This will allow a component to perform scale correction
@@ -10402,7 +10438,6 @@
10402
10438
  }
10403
10439
  createRelativeTarget(relativeParent, layout, parentLayout) {
10404
10440
  this.relativeParent = relativeParent;
10405
- this.linkedParentVersion = relativeParent.layoutVersion;
10406
10441
  this.forceRelativeParentToResolveTarget();
10407
10442
  this.relativeTarget = createBox();
10408
10443
  this.relativeTargetOrigin = createBox();
@@ -11112,6 +11147,26 @@
11112
11147
  node.isLayoutDirty = true;
11113
11148
  }
11114
11149
  }
11150
+ /**
11151
+ * If a node's relative parent is about to be re-measured but the node isn't
11152
+ * (e.g. it's in another LayoutGroup), its relative target is out of date.
11153
+ * If it's layout animating, re-measure it too, so its relative target keeps
11154
+ * resolving against current layouts. Otherwise its layout is still valid
11155
+ * relative to its parent, so drop the relative target, and any targetDelta
11156
+ * left over from a finished animation while an ancestor still animates, to be
11157
+ * rebuilt from its layout.
11158
+ */
11159
+ function syncRelativeLayout(node) {
11160
+ if (node.relativeTarget && node.relativeParent?.isLayoutDirty) {
11161
+ if (node.currentAnimation) {
11162
+ node.isLayoutDirty = true;
11163
+ }
11164
+ else {
11165
+ node.targetDelta = undefined;
11166
+ node.removeRelativeTarget();
11167
+ }
11168
+ }
11169
+ }
11115
11170
  function resetTransformStyle(node) {
11116
11171
  const { visualElement } = node.options;
11117
11172
  if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
@@ -11807,7 +11862,6 @@
11807
11862
  exports.nodeGroup = nodeGroup;
11808
11863
  exports.number = number;
11809
11864
  exports.numberValueTypes = numberValueTypes;
11810
- exports.observeTimeline = observeTimeline;
11811
11865
  exports.optimizedAppearDataAttribute = optimizedAppearDataAttribute;
11812
11866
  exports.optimizedAppearDataId = optimizedAppearDataId;
11813
11867
  exports.parseAnimateLayoutArgs = parseAnimateLayoutArgs;