motion 12.6.4-alpha.0 → 12.6.4

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 (64) hide show
  1. package/dist/cjs/debug.js +2 -6
  2. package/dist/cjs/index.js +24 -14
  3. package/dist/cjs/mini.js +177 -0
  4. package/dist/cjs/react-client.js +24 -13
  5. package/dist/cjs/react-m.js +12 -6
  6. package/dist/cjs/react-mini.js +177 -0
  7. package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +1 -0
  8. package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +1 -0
  9. package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -0
  10. package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +1 -0
  11. package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +1 -0
  12. package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +1 -0
  13. package/dist/es/framer-motion/dist/es/animation/animators/drivers/driver-frameloop.mjs +1 -0
  14. package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +1 -0
  15. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +1 -0
  16. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +1 -0
  17. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +1 -0
  18. package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +1 -0
  19. package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +1 -0
  20. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +1 -0
  21. package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +1 -0
  22. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +1 -0
  23. package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +1 -0
  24. package/dist/es/framer-motion/dist/es/events/event-info.mjs +1 -0
  25. package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -0
  26. package/dist/es/framer-motion/dist/es/gestures/hover.mjs +1 -0
  27. package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +1 -0
  28. package/dist/es/framer-motion/dist/es/gestures/pan/index.mjs +1 -0
  29. package/dist/es/framer-motion/dist/es/gestures/press.mjs +1 -0
  30. package/dist/es/framer-motion/dist/es/motion/features/layout/MeasureLayout.mjs +1 -0
  31. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +1 -0
  32. package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +1 -0
  33. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +1 -0
  34. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +1 -0
  35. package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +1 -0
  36. package/dist/es/framer-motion/dist/es/render/dom/scroll/observe.mjs +1 -0
  37. package/dist/es/framer-motion/dist/es/render/dom/scroll/track.mjs +1 -0
  38. package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +1 -0
  39. package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +1 -0
  40. package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +1 -0
  41. package/dist/es/framer-motion/dist/es/render/utils/KeyframesResolver.mjs +1 -0
  42. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +2 -1
  43. package/dist/es/framer-motion/dist/es/render/utils/setters.mjs +1 -0
  44. package/dist/es/framer-motion/dist/es/utils/delay.mjs +1 -0
  45. package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +1 -2
  46. package/dist/es/framer-motion/dist/es/utils/use-animation-frame.mjs +1 -0
  47. package/dist/es/framer-motion/dist/es/utils/use-force-update.mjs +1 -0
  48. package/dist/es/framer-motion/dist/es/utils/use-instant-transition.mjs +1 -0
  49. package/dist/es/framer-motion/dist/es/value/use-combine-values.mjs +1 -0
  50. package/dist/es/framer-motion/dist/es/value/use-computed.mjs +1 -0
  51. package/dist/es/framer-motion/dist/es/value/use-motion-value.mjs +1 -0
  52. package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +1 -0
  53. package/dist/es/framer-motion/dist/es/value/use-spring.mjs +1 -0
  54. package/dist/es/framer-motion/dist/es/value/use-velocity.mjs +1 -0
  55. package/dist/es/framer-motion/dist/es/value/use-will-change/WillChangeMotionValue.mjs +1 -0
  56. package/dist/es/framer-motion/dist/es/value/use-will-change/add-will-change.mjs +7 -0
  57. package/dist/es/motion/lib/index.mjs +0 -1
  58. package/dist/es/motion/lib/react.mjs +1 -1
  59. package/dist/es/motion-dom/dist/es/frameloop/index-legacy.mjs +12 -0
  60. package/dist/es/motion-dom/dist/es/value/index.mjs +1 -1
  61. package/dist/es/motion-utils/dist/es/global-config.mjs +4 -1
  62. package/dist/motion.dev.js +24 -14
  63. package/dist/motion.js +1 -1
  64. package/package.json +3 -3
package/dist/cjs/debug.js CHANGED
@@ -4,8 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  if (process.env.NODE_ENV !== "production") ;
6
6
 
7
- const MotionGlobalConfig = {};
8
-
9
7
  /*#__NO_SIDE_EFFECTS__*/
10
8
  const noop = (any) => any;
11
9
 
@@ -134,11 +132,9 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
134
132
  }, {});
135
133
  const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
136
134
  const processBatch = () => {
137
- const timestamp = MotionGlobalConfig.useManualTiming
138
- ? state.timestamp
139
- : performance.now();
135
+ const timestamp = performance.now();
140
136
  runNextFrame = false;
141
- if (!MotionGlobalConfig.useManualTiming) {
137
+ {
142
138
  state.delta = useDefaultElapsed
143
139
  ? 1000 / 60
144
140
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
package/dist/cjs/index.js CHANGED
@@ -27,7 +27,10 @@ if (process.env.NODE_ENV !== "production") {
27
27
  };
28
28
  }
29
29
 
30
- const MotionGlobalConfig = {};
30
+ const MotionGlobalConfig = {
31
+ skipAnimations: false,
32
+ useManualTiming: false,
33
+ };
31
34
 
32
35
  /*#__NO_SIDE_EFFECTS__*/
33
36
  function memo(callback) {
@@ -737,11 +740,9 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
737
740
  }, {});
738
741
  const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
739
742
  const processBatch = () => {
740
- const timestamp = MotionGlobalConfig.useManualTiming
741
- ? state.timestamp
742
- : performance.now();
743
+ const timestamp = performance.now();
743
744
  runNextFrame = false;
744
- if (!MotionGlobalConfig.useManualTiming) {
745
+ {
745
746
  state.delta = useDefaultElapsed
746
747
  ? 1000 / 60
747
748
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed$1), 1);
@@ -1064,7 +1065,7 @@ class MotionValue {
1064
1065
  * This will be replaced by the build step with the latest version number.
1065
1066
  * When MotionValues are provided to motion components, warn if versions are mixed.
1066
1067
  */
1067
- this.version = "12.6.4-alpha.0";
1068
+ this.version = "12.6.4";
1068
1069
  /**
1069
1070
  * Tracks whether this value can output a velocity. Currently this is only true
1070
1071
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1339,6 +1340,16 @@ function motionValue(init, options) {
1339
1340
  return new MotionValue(init, options);
1340
1341
  }
1341
1342
 
1343
+ /**
1344
+ * @deprecated
1345
+ *
1346
+ * Use cancelFrame(callback) instead.
1347
+ */
1348
+ stepsOrder.reduce((acc, key) => {
1349
+ acc[key] = (process) => cancelFrame(process);
1350
+ return acc;
1351
+ }, {});
1352
+
1342
1353
  const clamp = (min, max, v) => {
1343
1354
  if (v > max)
1344
1355
  return max;
@@ -2134,6 +2145,11 @@ function addValueToWillChange(visualElement, key) {
2134
2145
  if (isWillChangeMotionValue(willChange)) {
2135
2146
  return willChange.add(key);
2136
2147
  }
2148
+ else if (!willChange && MotionGlobalConfig.WillChange) {
2149
+ const newWillChange = new MotionGlobalConfig.WillChange("auto");
2150
+ visualElement.addValue("willChange", newWillChange);
2151
+ newWillChange.add(key);
2152
+ }
2137
2153
  }
2138
2154
 
2139
2155
  /**
@@ -3619,7 +3635,7 @@ const easingDefinitionToFunction = (definition) => {
3619
3635
 
3620
3636
  function createMixers(output, ease, customMixer) {
3621
3637
  const mixers = [];
3622
- const mixerFactory = customMixer || MotionGlobalConfig.mix || mix;
3638
+ const mixerFactory = customMixer || mix;
3623
3639
  const numMixers = output.length - 1;
3624
3640
  for (let i = 0; i < numMixers; i++) {
3625
3641
  let mixer = mixerFactory(output[i], output[i + 1]);
@@ -4552,11 +4568,6 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
4552
4568
  shouldSkip = true;
4553
4569
  }
4554
4570
  }
4555
- if (MotionGlobalConfig.skipAnimations) {
4556
- shouldSkip = true;
4557
- options.duration = 0;
4558
- options.delay = 0;
4559
- }
4560
4571
  /**
4561
4572
  * If the transition type or easing has been explicitly set by the user
4562
4573
  * then we don't want to allow flattening the animation.
@@ -4771,7 +4782,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4771
4782
  * and warn against mismatches.
4772
4783
  */
4773
4784
  if (process.env.NODE_ENV === "development") {
4774
- warnOnce(nextValue.version === "12.6.4-alpha.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.4-alpha.0 may not work as expected.`);
4785
+ warnOnce(nextValue.version === "12.6.4", `Attempting to mix Motion versions ${nextValue.version} with 12.6.4 may not work as expected.`);
4775
4786
  }
4776
4787
  }
4777
4788
  else if (isMotionValue(prevValue)) {
@@ -6626,7 +6637,6 @@ exports.easeOut = easeOut;
6626
6637
  exports.frame = frame;
6627
6638
  exports.frameData = frameData;
6628
6639
  exports.hover = hover;
6629
- exports.hslaToRgba = hslaToRgba;
6630
6640
  exports.inView = inView;
6631
6641
  exports.inertia = inertia;
6632
6642
  exports.interpolate = interpolate;
package/dist/cjs/mini.js CHANGED
@@ -239,6 +239,11 @@ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
239
239
  return keyframes;
240
240
  }
241
241
 
242
+ const statsBuffer = {
243
+ value: null,
244
+ addProjectionMetrics: null,
245
+ };
246
+
242
247
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
243
248
 
244
249
  /**
@@ -535,6 +540,168 @@ function createGeneratorEasing(options, scale = 100, createGenerator) {
535
540
  };
536
541
  }
537
542
 
543
+ const stepsOrder = [
544
+ "read", // Read
545
+ "resolveKeyframes", // Write/Read/Write/Read
546
+ "update", // Compute
547
+ "preRender", // Compute
548
+ "render", // Write
549
+ "postRender", // Compute
550
+ ];
551
+
552
+ function createRenderStep(runNextFrame, stepName) {
553
+ /**
554
+ * We create and reuse two queues, one to queue jobs for the current frame
555
+ * and one for the next. We reuse to avoid triggering GC after x frames.
556
+ */
557
+ let thisFrame = new Set();
558
+ let nextFrame = new Set();
559
+ /**
560
+ * Track whether we're currently processing jobs in this step. This way
561
+ * we can decide whether to schedule new jobs for this frame or next.
562
+ */
563
+ let isProcessing = false;
564
+ let flushNextFrame = false;
565
+ /**
566
+ * A set of processes which were marked keepAlive when scheduled.
567
+ */
568
+ const toKeepAlive = new WeakSet();
569
+ let latestFrameData = {
570
+ delta: 0.0,
571
+ timestamp: 0.0,
572
+ isProcessing: false,
573
+ };
574
+ let numCalls = 0;
575
+ function triggerCallback(callback) {
576
+ if (toKeepAlive.has(callback)) {
577
+ step.schedule(callback);
578
+ runNextFrame();
579
+ }
580
+ numCalls++;
581
+ callback(latestFrameData);
582
+ }
583
+ const step = {
584
+ /**
585
+ * Schedule a process to run on the next frame.
586
+ */
587
+ schedule: (callback, keepAlive = false, immediate = false) => {
588
+ const addToCurrentFrame = immediate && isProcessing;
589
+ const queue = addToCurrentFrame ? thisFrame : nextFrame;
590
+ if (keepAlive)
591
+ toKeepAlive.add(callback);
592
+ if (!queue.has(callback))
593
+ queue.add(callback);
594
+ return callback;
595
+ },
596
+ /**
597
+ * Cancel the provided callback from running on the next frame.
598
+ */
599
+ cancel: (callback) => {
600
+ nextFrame.delete(callback);
601
+ toKeepAlive.delete(callback);
602
+ },
603
+ /**
604
+ * Execute all schedule callbacks.
605
+ */
606
+ process: (frameData) => {
607
+ latestFrameData = frameData;
608
+ /**
609
+ * If we're already processing we've probably been triggered by a flushSync
610
+ * inside an existing process. Instead of executing, mark flushNextFrame
611
+ * as true and ensure we flush the following frame at the end of this one.
612
+ */
613
+ if (isProcessing) {
614
+ flushNextFrame = true;
615
+ return;
616
+ }
617
+ isProcessing = true;
618
+ [thisFrame, nextFrame] = [nextFrame, thisFrame];
619
+ // Execute this frame
620
+ thisFrame.forEach(triggerCallback);
621
+ /**
622
+ * If we're recording stats then
623
+ */
624
+ if (stepName && statsBuffer.value) {
625
+ statsBuffer.value.frameloop[stepName].push(numCalls);
626
+ }
627
+ numCalls = 0;
628
+ // Clear the frame so no callbacks remain. This is to avoid
629
+ // memory leaks should this render step not run for a while.
630
+ thisFrame.clear();
631
+ isProcessing = false;
632
+ if (flushNextFrame) {
633
+ flushNextFrame = false;
634
+ step.process(frameData);
635
+ }
636
+ },
637
+ };
638
+ return step;
639
+ }
640
+
641
+ const maxElapsed = 40;
642
+ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
643
+ let runNextFrame = false;
644
+ let useDefaultElapsed = true;
645
+ const state = {
646
+ delta: 0.0,
647
+ timestamp: 0.0,
648
+ isProcessing: false,
649
+ };
650
+ const flagRunNextFrame = () => (runNextFrame = true);
651
+ const steps = stepsOrder.reduce((acc, key) => {
652
+ acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
653
+ return acc;
654
+ }, {});
655
+ const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
656
+ const processBatch = () => {
657
+ const timestamp = performance.now();
658
+ runNextFrame = false;
659
+ {
660
+ state.delta = useDefaultElapsed
661
+ ? 1000 / 60
662
+ : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
663
+ }
664
+ state.timestamp = timestamp;
665
+ state.isProcessing = true;
666
+ // Unrolled render loop for better per-frame performance
667
+ read.process(state);
668
+ resolveKeyframes.process(state);
669
+ update.process(state);
670
+ preRender.process(state);
671
+ render.process(state);
672
+ postRender.process(state);
673
+ state.isProcessing = false;
674
+ if (runNextFrame && allowKeepAlive) {
675
+ useDefaultElapsed = false;
676
+ scheduleNextBatch(processBatch);
677
+ }
678
+ };
679
+ const wake = () => {
680
+ runNextFrame = true;
681
+ useDefaultElapsed = true;
682
+ if (!state.isProcessing) {
683
+ scheduleNextBatch(processBatch);
684
+ }
685
+ };
686
+ const schedule = stepsOrder.reduce((acc, key) => {
687
+ const step = steps[key];
688
+ acc[key] = (process, keepAlive = false, immediate = false) => {
689
+ if (!runNextFrame)
690
+ wake();
691
+ return step.schedule(process, keepAlive, immediate);
692
+ };
693
+ return acc;
694
+ }, {});
695
+ const cancel = (process) => {
696
+ for (let i = 0; i < stepsOrder.length; i++) {
697
+ steps[stepsOrder[i]].cancel(process);
698
+ }
699
+ };
700
+ return { schedule, cancel, state, steps };
701
+ }
702
+
703
+ const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop, true);
704
+
538
705
  function resolveElements(elementOrSelector, scope, selectorCache) {
539
706
  if (elementOrSelector instanceof EventTarget) {
540
707
  return [elementOrSelector];
@@ -551,6 +718,16 @@ function resolveElements(elementOrSelector, scope, selectorCache) {
551
718
  return Array.from(elementOrSelector);
552
719
  }
553
720
 
721
+ /**
722
+ * @deprecated
723
+ *
724
+ * Use cancelFrame(callback) instead.
725
+ */
726
+ stepsOrder.reduce((acc, key) => {
727
+ acc[key] = (process) => cancelFrame(process);
728
+ return acc;
729
+ }, {});
730
+
554
731
  const wrap = (min, max, v) => {
555
732
  const rangeSize = max - min;
556
733
  return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
@@ -76,7 +76,10 @@ if (process.env.NODE_ENV !== "production") {
76
76
  };
77
77
  }
78
78
 
79
- const MotionGlobalConfig = {};
79
+ const MotionGlobalConfig = {
80
+ skipAnimations: false,
81
+ useManualTiming: false,
82
+ };
80
83
 
81
84
  /*#__NO_SIDE_EFFECTS__*/
82
85
  function memo(callback) {
@@ -530,11 +533,9 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
530
533
  }, {});
531
534
  const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
532
535
  const processBatch = () => {
533
- const timestamp = MotionGlobalConfig.useManualTiming
534
- ? state.timestamp
535
- : performance.now();
536
+ const timestamp = performance.now();
536
537
  runNextFrame = false;
537
- if (!MotionGlobalConfig.useManualTiming) {
538
+ {
538
539
  state.delta = useDefaultElapsed
539
540
  ? 1000 / 60
540
541
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
@@ -885,7 +886,7 @@ class MotionValue {
885
886
  * This will be replaced by the build step with the latest version number.
886
887
  * When MotionValues are provided to motion components, warn if versions are mixed.
887
888
  */
888
- this.version = "12.6.4-alpha.0";
889
+ this.version = "12.6.4";
889
890
  /**
890
891
  * Tracks whether this value can output a velocity. Currently this is only true
891
892
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1160,6 +1161,16 @@ function motionValue(init, options) {
1160
1161
  return new MotionValue(init, options);
1161
1162
  }
1162
1163
 
1164
+ /**
1165
+ * @deprecated
1166
+ *
1167
+ * Use cancelFrame(callback) instead.
1168
+ */
1169
+ stepsOrder.reduce((acc, key) => {
1170
+ acc[key] = (process) => cancelFrame(process);
1171
+ return acc;
1172
+ }, {});
1173
+
1163
1174
  /**
1164
1175
  * Generate a list of every possible transform key.
1165
1176
  */
@@ -1246,6 +1257,11 @@ function addValueToWillChange(visualElement, key) {
1246
1257
  if (isWillChangeMotionValue(willChange)) {
1247
1258
  return willChange.add(key);
1248
1259
  }
1260
+ else if (!willChange && MotionGlobalConfig.WillChange) {
1261
+ const newWillChange = new MotionGlobalConfig.WillChange("auto");
1262
+ visualElement.addValue("willChange", newWillChange);
1263
+ newWillChange.add(key);
1264
+ }
1249
1265
  }
1250
1266
 
1251
1267
  /**
@@ -3046,7 +3062,7 @@ const easingDefinitionToFunction = (definition) => {
3046
3062
 
3047
3063
  function createMixers(output, ease, customMixer) {
3048
3064
  const mixers = [];
3049
- const mixerFactory = customMixer || MotionGlobalConfig.mix || mix;
3065
+ const mixerFactory = customMixer || mix;
3050
3066
  const numMixers = output.length - 1;
3051
3067
  for (let i = 0; i < numMixers; i++) {
3052
3068
  let mixer = mixerFactory(output[i], output[i + 1]);
@@ -3993,11 +4009,6 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
3993
4009
  shouldSkip = true;
3994
4010
  }
3995
4011
  }
3996
- if (MotionGlobalConfig.skipAnimations) {
3997
- shouldSkip = true;
3998
- options.duration = 0;
3999
- options.delay = 0;
4000
- }
4001
4012
  /**
4002
4013
  * If the transition type or easing has been explicitly set by the user
4003
4014
  * then we don't want to allow flattening the animation.
@@ -9334,7 +9345,7 @@ function updateMotionValuesFromProps(element, next, prev) {
9334
9345
  * and warn against mismatches.
9335
9346
  */
9336
9347
  if (process.env.NODE_ENV === "development") {
9337
- warnOnce(nextValue.version === "12.6.4-alpha.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.4-alpha.0 may not work as expected.`);
9348
+ warnOnce(nextValue.version === "12.6.4", `Attempting to mix Motion versions ${nextValue.version} with 12.6.4 may not work as expected.`);
9338
9349
  }
9339
9350
  }
9340
9351
  else if (isMotionValue(prevValue)) {
@@ -20,8 +20,6 @@ if (process.env.NODE_ENV !== "production") {
20
20
  };
21
21
  }
22
22
 
23
- const MotionGlobalConfig = {};
24
-
25
23
  /*#__NO_SIDE_EFFECTS__*/
26
24
  const noop = (any) => any;
27
25
 
@@ -292,11 +290,9 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
292
290
  }, {});
293
291
  const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
294
292
  const processBatch = () => {
295
- const timestamp = MotionGlobalConfig.useManualTiming
296
- ? state.timestamp
297
- : performance.now();
293
+ const timestamp = performance.now();
298
294
  runNextFrame = false;
299
- if (!MotionGlobalConfig.useManualTiming) {
295
+ {
300
296
  state.delta = useDefaultElapsed
301
297
  ? 1000 / 60
302
298
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
@@ -345,6 +341,16 @@ const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameStep
345
341
  const { schedule: microtask, cancel: cancelMicrotask } =
346
342
  /* @__PURE__ */ createRenderBatcher(queueMicrotask, false);
347
343
 
344
+ /**
345
+ * @deprecated
346
+ *
347
+ * Use cancelFrame(callback) instead.
348
+ */
349
+ stepsOrder.reduce((acc, key) => {
350
+ acc[key] = (process) => cancelFrame(process);
351
+ return acc;
352
+ }, {});
353
+
348
354
  /**
349
355
  * Convert camelCase to dash-case properties.
350
356
  */
@@ -236,6 +236,11 @@ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
236
236
  return keyframes;
237
237
  }
238
238
 
239
+ const statsBuffer = {
240
+ value: null,
241
+ addProjectionMetrics: null,
242
+ };
243
+
239
244
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
240
245
 
241
246
  /**
@@ -501,6 +506,168 @@ function getValueTransition(transition, key) {
501
506
  transition);
502
507
  }
503
508
 
509
+ const stepsOrder = [
510
+ "read", // Read
511
+ "resolveKeyframes", // Write/Read/Write/Read
512
+ "update", // Compute
513
+ "preRender", // Compute
514
+ "render", // Write
515
+ "postRender", // Compute
516
+ ];
517
+
518
+ function createRenderStep(runNextFrame, stepName) {
519
+ /**
520
+ * We create and reuse two queues, one to queue jobs for the current frame
521
+ * and one for the next. We reuse to avoid triggering GC after x frames.
522
+ */
523
+ let thisFrame = new Set();
524
+ let nextFrame = new Set();
525
+ /**
526
+ * Track whether we're currently processing jobs in this step. This way
527
+ * we can decide whether to schedule new jobs for this frame or next.
528
+ */
529
+ let isProcessing = false;
530
+ let flushNextFrame = false;
531
+ /**
532
+ * A set of processes which were marked keepAlive when scheduled.
533
+ */
534
+ const toKeepAlive = new WeakSet();
535
+ let latestFrameData = {
536
+ delta: 0.0,
537
+ timestamp: 0.0,
538
+ isProcessing: false,
539
+ };
540
+ let numCalls = 0;
541
+ function triggerCallback(callback) {
542
+ if (toKeepAlive.has(callback)) {
543
+ step.schedule(callback);
544
+ runNextFrame();
545
+ }
546
+ numCalls++;
547
+ callback(latestFrameData);
548
+ }
549
+ const step = {
550
+ /**
551
+ * Schedule a process to run on the next frame.
552
+ */
553
+ schedule: (callback, keepAlive = false, immediate = false) => {
554
+ const addToCurrentFrame = immediate && isProcessing;
555
+ const queue = addToCurrentFrame ? thisFrame : nextFrame;
556
+ if (keepAlive)
557
+ toKeepAlive.add(callback);
558
+ if (!queue.has(callback))
559
+ queue.add(callback);
560
+ return callback;
561
+ },
562
+ /**
563
+ * Cancel the provided callback from running on the next frame.
564
+ */
565
+ cancel: (callback) => {
566
+ nextFrame.delete(callback);
567
+ toKeepAlive.delete(callback);
568
+ },
569
+ /**
570
+ * Execute all schedule callbacks.
571
+ */
572
+ process: (frameData) => {
573
+ latestFrameData = frameData;
574
+ /**
575
+ * If we're already processing we've probably been triggered by a flushSync
576
+ * inside an existing process. Instead of executing, mark flushNextFrame
577
+ * as true and ensure we flush the following frame at the end of this one.
578
+ */
579
+ if (isProcessing) {
580
+ flushNextFrame = true;
581
+ return;
582
+ }
583
+ isProcessing = true;
584
+ [thisFrame, nextFrame] = [nextFrame, thisFrame];
585
+ // Execute this frame
586
+ thisFrame.forEach(triggerCallback);
587
+ /**
588
+ * If we're recording stats then
589
+ */
590
+ if (stepName && statsBuffer.value) {
591
+ statsBuffer.value.frameloop[stepName].push(numCalls);
592
+ }
593
+ numCalls = 0;
594
+ // Clear the frame so no callbacks remain. This is to avoid
595
+ // memory leaks should this render step not run for a while.
596
+ thisFrame.clear();
597
+ isProcessing = false;
598
+ if (flushNextFrame) {
599
+ flushNextFrame = false;
600
+ step.process(frameData);
601
+ }
602
+ },
603
+ };
604
+ return step;
605
+ }
606
+
607
+ const maxElapsed = 40;
608
+ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
609
+ let runNextFrame = false;
610
+ let useDefaultElapsed = true;
611
+ const state = {
612
+ delta: 0.0,
613
+ timestamp: 0.0,
614
+ isProcessing: false,
615
+ };
616
+ const flagRunNextFrame = () => (runNextFrame = true);
617
+ const steps = stepsOrder.reduce((acc, key) => {
618
+ acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
619
+ return acc;
620
+ }, {});
621
+ const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
622
+ const processBatch = () => {
623
+ const timestamp = performance.now();
624
+ runNextFrame = false;
625
+ {
626
+ state.delta = useDefaultElapsed
627
+ ? 1000 / 60
628
+ : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
629
+ }
630
+ state.timestamp = timestamp;
631
+ state.isProcessing = true;
632
+ // Unrolled render loop for better per-frame performance
633
+ read.process(state);
634
+ resolveKeyframes.process(state);
635
+ update.process(state);
636
+ preRender.process(state);
637
+ render.process(state);
638
+ postRender.process(state);
639
+ state.isProcessing = false;
640
+ if (runNextFrame && allowKeepAlive) {
641
+ useDefaultElapsed = false;
642
+ scheduleNextBatch(processBatch);
643
+ }
644
+ };
645
+ const wake = () => {
646
+ runNextFrame = true;
647
+ useDefaultElapsed = true;
648
+ if (!state.isProcessing) {
649
+ scheduleNextBatch(processBatch);
650
+ }
651
+ };
652
+ const schedule = stepsOrder.reduce((acc, key) => {
653
+ const step = steps[key];
654
+ acc[key] = (process, keepAlive = false, immediate = false) => {
655
+ if (!runNextFrame)
656
+ wake();
657
+ return step.schedule(process, keepAlive, immediate);
658
+ };
659
+ return acc;
660
+ }, {});
661
+ const cancel = (process) => {
662
+ for (let i = 0; i < stepsOrder.length; i++) {
663
+ steps[stepsOrder[i]].cancel(process);
664
+ }
665
+ };
666
+ return { schedule, cancel, state, steps };
667
+ }
668
+
669
+ const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop, true);
670
+
504
671
  function resolveElements(elementOrSelector, scope, selectorCache) {
505
672
  if (elementOrSelector instanceof EventTarget) {
506
673
  return [elementOrSelector];
@@ -517,6 +684,16 @@ function resolveElements(elementOrSelector, scope, selectorCache) {
517
684
  return Array.from(elementOrSelector);
518
685
  }
519
686
 
687
+ /**
688
+ * @deprecated
689
+ *
690
+ * Use cancelFrame(callback) instead.
691
+ */
692
+ stepsOrder.reduce((acc, key) => {
693
+ acc[key] = (process) => cancelFrame(process);
694
+ return acc;
695
+ }, {});
696
+
520
697
  function animateElements(elementOrSelector, keyframes, options, scope) {
521
698
  const elements = resolveElements(elementOrSelector, scope);
522
699
  const numElements = elements.length;
@@ -1,5 +1,6 @@
1
1
  import '../../../../../motion-utils/dist/es/errors.mjs';
2
2
  import { GroupAnimationWithThen } from '../../../../../motion-dom/dist/es/animation/GroupAnimationWithThen.mjs';
3
+ import '../../../../../motion-dom/dist/es/frameloop/index-legacy.mjs';
3
4
  import { animateSequence } from './sequence.mjs';
4
5
  import { animateSubject } from './subject.mjs';
5
6
 
@@ -1,5 +1,6 @@
1
1
  import '../../../../../motion-utils/dist/es/errors.mjs';
2
2
  import { resolveElements } from '../../../../../motion-dom/dist/es/utils/resolve-elements.mjs';
3
+ import '../../../../../motion-dom/dist/es/frameloop/index-legacy.mjs';
3
4
  import { isDOMKeyframes } from '../utils/is-dom-keyframes.mjs';
4
5
 
5
6
  function resolveSubjects(subject, keyframes, scope, selectorCache) {
@@ -1,5 +1,6 @@
1
1
  import '../../../../../motion-utils/dist/es/errors.mjs';
2
2
  import { motionValue } from '../../../../../motion-dom/dist/es/value/index.mjs';
3
+ import '../../../../../motion-dom/dist/es/frameloop/index-legacy.mjs';
3
4
  import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
4
5
  import { animateMotionValue } from '../interfaces/motion-value.mjs';
5
6
 
@@ -6,6 +6,7 @@ import { isGenerator } from '../../../../../motion-dom/dist/es/animation/generat
6
6
  import { isWaapiSupportedEasing } from '../../../../../motion-dom/dist/es/animation/waapi/easing/is-supported.mjs';
7
7
  import { supportsLinearEasing } from '../../../../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
8
8
  import { attachTimeline } from '../../../../../motion-dom/dist/es/animation/waapi/utils/attach-timeline.mjs';
9
+ import '../../../../../motion-dom/dist/es/frameloop/index-legacy.mjs';
9
10
  import { anticipate } from '../../easing/anticipate.mjs';
10
11
  import { backInOut } from '../../easing/back.mjs';
11
12
  import { circInOut } from '../../easing/circ.mjs';
@@ -1,5 +1,6 @@
1
1
  import '../../../../../motion-utils/dist/es/errors.mjs';
2
2
  import { time } from '../../../../../motion-dom/dist/es/frameloop/sync-time.mjs';
3
+ import '../../../../../motion-dom/dist/es/frameloop/index-legacy.mjs';
3
4
  import { flushKeyframeResolvers } from '../../render/utils/KeyframesResolver.mjs';
4
5
  import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
5
6
  import { canAnimate } from './utils/can-animate.mjs';