framer-motion 12.4.13 → 12.6.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 (100) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client.js +1 -1
  3. package/dist/cjs/{create-DkTZDHiS.js → create-CgwP8YNL.js} +4234 -4792
  4. package/dist/cjs/debug.js +5 -281
  5. package/dist/cjs/dom-mini.js +9 -7
  6. package/dist/cjs/dom.js +81 -639
  7. package/dist/cjs/index.js +1555 -1553
  8. package/dist/cjs/m.js +11 -179
  9. package/dist/cjs/mini.js +8 -0
  10. package/dist/debug.d.ts +2 -35
  11. package/dist/dom-mini.d.ts +1 -181
  12. package/dist/dom-mini.js +1 -1
  13. package/dist/dom.d.ts +3 -242
  14. package/dist/dom.js +1 -1
  15. package/dist/es/animation/animate/single-value.mjs +1 -1
  16. package/dist/es/animation/animators/BaseAnimation.mjs +1 -1
  17. package/dist/es/animation/animators/MainThreadAnimation.mjs +1 -2
  18. package/dist/es/animation/animators/drivers/driver-frameloop.mjs +1 -2
  19. package/dist/es/animation/animators/waapi/index.mjs +1 -3
  20. package/dist/es/animation/generators/utils/velocity.mjs +1 -1
  21. package/dist/es/animation/interfaces/motion-value.mjs +2 -4
  22. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
  23. package/dist/es/animation/optimized-appear/start.mjs +3 -3
  24. package/dist/es/animation/sequence/utils/edit.mjs +1 -1
  25. package/dist/es/components/AnimatePresence/index.mjs +1 -1
  26. package/dist/es/components/Reorder/utils/check-reorder.mjs +1 -1
  27. package/dist/es/debug.mjs +1 -1
  28. package/dist/es/dom.mjs +1 -5
  29. package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -2
  30. package/dist/es/gestures/hover.mjs +1 -2
  31. package/dist/es/gestures/pan/PanSession.mjs +1 -2
  32. package/dist/es/gestures/pan/index.mjs +1 -1
  33. package/dist/es/gestures/press.mjs +1 -2
  34. package/dist/es/index.mjs +14 -19
  35. package/dist/es/motion/features/layout/MeasureLayout.mjs +1 -2
  36. package/dist/es/motion/utils/use-visual-element.mjs +6 -6
  37. package/dist/es/projection/node/create-projection-node.mjs +2 -8
  38. package/dist/es/projection/shared/stack.mjs +1 -1
  39. package/dist/es/projection.mjs +1 -3
  40. package/dist/es/render/VisualElement.mjs +2 -5
  41. package/dist/es/render/components/create-proxy.mjs +1 -1
  42. package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
  43. package/dist/es/render/dom/scroll/info.mjs +1 -2
  44. package/dist/es/render/dom/scroll/observe.mjs +1 -1
  45. package/dist/es/render/dom/scroll/on-scroll-handler.mjs +1 -1
  46. package/dist/es/render/dom/scroll/track.mjs +1 -1
  47. package/dist/es/render/svg/SVGVisualElement.mjs +1 -1
  48. package/dist/es/render/svg/config-motion.mjs +1 -1
  49. package/dist/es/render/utils/KeyframesResolver.mjs +1 -1
  50. package/dist/es/render/utils/flat-tree.mjs +1 -1
  51. package/dist/es/render/utils/motion-values.mjs +3 -3
  52. package/dist/es/render/utils/setters.mjs +1 -1
  53. package/dist/es/utils/delay.mjs +1 -2
  54. package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +1 -1
  55. package/dist/es/utils/use-animation-frame.mjs +1 -1
  56. package/dist/es/utils/use-force-update.mjs +1 -1
  57. package/dist/es/utils/use-instant-transition.mjs +1 -1
  58. package/dist/es/value/scroll/use-element-scroll.mjs +1 -1
  59. package/dist/es/value/scroll/use-viewport-scroll.mjs +1 -1
  60. package/dist/es/value/use-combine-values.mjs +2 -2
  61. package/dist/es/value/use-computed.mjs +1 -1
  62. package/dist/es/value/use-inverted-scale.mjs +3 -3
  63. package/dist/es/value/use-motion-value.mjs +1 -1
  64. package/dist/es/value/use-scroll.mjs +4 -4
  65. package/dist/es/value/use-spring.mjs +1 -1
  66. package/dist/es/value/use-transform.mjs +1 -1
  67. package/dist/es/value/use-velocity.mjs +1 -1
  68. package/dist/es/value/use-will-change/WillChangeMotionValue.mjs +2 -2
  69. package/dist/framer-motion.dev.js +8227 -8251
  70. package/dist/framer-motion.js +1 -1
  71. package/dist/m.d.ts +49 -241
  72. package/dist/size-rollup-animate.js +1 -1
  73. package/dist/size-rollup-dom-animation-assets.js +1 -1
  74. package/dist/size-rollup-dom-animation.js +1 -1
  75. package/dist/size-rollup-dom-max-assets.js +1 -1
  76. package/dist/size-rollup-dom-max.js +1 -1
  77. package/dist/size-rollup-m.js +1 -1
  78. package/dist/size-rollup-motion.js +1 -1
  79. package/dist/size-rollup-scroll.js +1 -1
  80. package/dist/types/client.d.ts +2 -2
  81. package/dist/types/index.d.ts +43 -79
  82. package/dist/{types.d-6pKw1mTI.d.ts → types.d-B50aGbjN.d.ts} +81 -289
  83. package/package.json +4 -6
  84. package/dist/es/frameloop/batcher.mjs +0 -69
  85. package/dist/es/frameloop/frame.mjs +0 -6
  86. package/dist/es/frameloop/index-legacy.mjs +0 -20
  87. package/dist/es/frameloop/microtask.mjs +0 -5
  88. package/dist/es/frameloop/order.mjs +0 -10
  89. package/dist/es/frameloop/render-step.mjs +0 -92
  90. package/dist/es/frameloop/sync-time.mjs +0 -31
  91. package/dist/es/stats/animation-count.mjs +0 -7
  92. package/dist/es/stats/buffer.mjs +0 -6
  93. package/dist/es/stats/index.mjs +0 -113
  94. package/dist/es/utils/GlobalConfig.mjs +0 -6
  95. package/dist/es/utils/array.mjs +0 -21
  96. package/dist/es/utils/subscription-manager.mjs +0 -40
  97. package/dist/es/utils/velocity-per-second.mjs +0 -11
  98. package/dist/es/utils/warn-once.mjs +0 -11
  99. package/dist/es/value/index.mjs +0 -319
  100. package/dist/three.d.ts +0 -2833
package/dist/cjs/dom.js CHANGED
@@ -13,20 +13,10 @@ const clamp = (min, max, v) => {
13
13
  return v;
14
14
  };
15
15
 
16
- /*
17
- Convert velocity into velocity per second
18
-
19
- @param [number]: Unit per frame
20
- @param [number]: Frame duration in ms
21
- */
22
- function velocityPerSecond(velocity, frameDuration) {
23
- return frameDuration ? velocity * (1000 / frameDuration) : 0;
24
- }
25
-
26
16
  const velocitySampleDuration = 5; // ms
27
17
  function calcGeneratorVelocity(resolveValue, t, current) {
28
18
  const prevT = Math.max(t - velocitySampleDuration, 0);
29
- return velocityPerSecond(current - resolveValue(prevT), t - prevT);
19
+ return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
30
20
  }
31
21
 
32
22
  const springDefaults = {
@@ -390,21 +380,11 @@ function calcNextTime(current, next, prev, labels) {
390
380
  }
391
381
  }
392
382
 
393
- function addUniqueItem(arr, item) {
394
- if (arr.indexOf(item) === -1)
395
- arr.push(item);
396
- }
397
- function removeItem(arr, item) {
398
- const index = arr.indexOf(item);
399
- if (index > -1)
400
- arr.splice(index, 1);
401
- }
402
-
403
383
  function eraseKeyframes(sequence, startTime, endTime) {
404
384
  for (let i = 0; i < sequence.length; i++) {
405
385
  const keyframe = sequence[i];
406
386
  if (keyframe.at > startTime && keyframe.at < endTime) {
407
- removeItem(sequence, keyframe);
387
+ motionUtils.removeItem(sequence, keyframe);
408
388
  // If we remove this item we have to push the pointer back one
409
389
  i--;
410
390
  }
@@ -692,178 +672,6 @@ const isNumberKeyframesArray = (keyframes) => keyframes.every(isNumber);
692
672
 
693
673
  const visualElementStore = new WeakMap();
694
674
 
695
- const MotionGlobalConfig = {
696
- skipAnimations: false,
697
- useManualTiming: false,
698
- };
699
-
700
- const stepsOrder = [
701
- "read", // Read
702
- "resolveKeyframes", // Write/Read/Write/Read
703
- "update", // Compute
704
- "preRender", // Compute
705
- "render", // Write
706
- "postRender", // Compute
707
- ];
708
-
709
- const statsBuffer = {
710
- value: null,
711
- addProjectionMetrics: null,
712
- };
713
-
714
- function createRenderStep(runNextFrame, stepName) {
715
- /**
716
- * We create and reuse two queues, one to queue jobs for the current frame
717
- * and one for the next. We reuse to avoid triggering GC after x frames.
718
- */
719
- let thisFrame = new Set();
720
- let nextFrame = new Set();
721
- /**
722
- * Track whether we're currently processing jobs in this step. This way
723
- * we can decide whether to schedule new jobs for this frame or next.
724
- */
725
- let isProcessing = false;
726
- let flushNextFrame = false;
727
- /**
728
- * A set of processes which were marked keepAlive when scheduled.
729
- */
730
- const toKeepAlive = new WeakSet();
731
- let latestFrameData = {
732
- delta: 0.0,
733
- timestamp: 0.0,
734
- isProcessing: false,
735
- };
736
- let numCalls = 0;
737
- function triggerCallback(callback) {
738
- if (toKeepAlive.has(callback)) {
739
- step.schedule(callback);
740
- runNextFrame();
741
- }
742
- numCalls++;
743
- callback(latestFrameData);
744
- }
745
- const step = {
746
- /**
747
- * Schedule a process to run on the next frame.
748
- */
749
- schedule: (callback, keepAlive = false, immediate = false) => {
750
- const addToCurrentFrame = immediate && isProcessing;
751
- const queue = addToCurrentFrame ? thisFrame : nextFrame;
752
- if (keepAlive)
753
- toKeepAlive.add(callback);
754
- if (!queue.has(callback))
755
- queue.add(callback);
756
- return callback;
757
- },
758
- /**
759
- * Cancel the provided callback from running on the next frame.
760
- */
761
- cancel: (callback) => {
762
- nextFrame.delete(callback);
763
- toKeepAlive.delete(callback);
764
- },
765
- /**
766
- * Execute all schedule callbacks.
767
- */
768
- process: (frameData) => {
769
- latestFrameData = frameData;
770
- /**
771
- * If we're already processing we've probably been triggered by a flushSync
772
- * inside an existing process. Instead of executing, mark flushNextFrame
773
- * as true and ensure we flush the following frame at the end of this one.
774
- */
775
- if (isProcessing) {
776
- flushNextFrame = true;
777
- return;
778
- }
779
- isProcessing = true;
780
- [thisFrame, nextFrame] = [nextFrame, thisFrame];
781
- // Execute this frame
782
- thisFrame.forEach(triggerCallback);
783
- /**
784
- * If we're recording stats then
785
- */
786
- if (stepName && statsBuffer.value) {
787
- statsBuffer.value.frameloop[stepName].push(numCalls);
788
- }
789
- numCalls = 0;
790
- // Clear the frame so no callbacks remain. This is to avoid
791
- // memory leaks should this render step not run for a while.
792
- thisFrame.clear();
793
- isProcessing = false;
794
- if (flushNextFrame) {
795
- flushNextFrame = false;
796
- step.process(frameData);
797
- }
798
- },
799
- };
800
- return step;
801
- }
802
-
803
- const maxElapsed$1 = 40;
804
- function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
805
- let runNextFrame = false;
806
- let useDefaultElapsed = true;
807
- const state = {
808
- delta: 0.0,
809
- timestamp: 0.0,
810
- isProcessing: false,
811
- };
812
- const flagRunNextFrame = () => (runNextFrame = true);
813
- const steps = stepsOrder.reduce((acc, key) => {
814
- acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
815
- return acc;
816
- }, {});
817
- const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
818
- const processBatch = () => {
819
- const timestamp = performance.now();
820
- runNextFrame = false;
821
- {
822
- state.delta = useDefaultElapsed
823
- ? 1000 / 60
824
- : Math.max(Math.min(timestamp - state.timestamp, maxElapsed$1), 1);
825
- }
826
- state.timestamp = timestamp;
827
- state.isProcessing = true;
828
- // Unrolled render loop for better per-frame performance
829
- read.process(state);
830
- resolveKeyframes.process(state);
831
- update.process(state);
832
- preRender.process(state);
833
- render.process(state);
834
- postRender.process(state);
835
- state.isProcessing = false;
836
- if (runNextFrame && allowKeepAlive) {
837
- useDefaultElapsed = false;
838
- scheduleNextBatch(processBatch);
839
- }
840
- };
841
- const wake = () => {
842
- runNextFrame = true;
843
- useDefaultElapsed = true;
844
- if (!state.isProcessing) {
845
- scheduleNextBatch(processBatch);
846
- }
847
- };
848
- const schedule = stepsOrder.reduce((acc, key) => {
849
- const step = steps[key];
850
- acc[key] = (process, keepAlive = false, immediate = false) => {
851
- if (!runNextFrame)
852
- wake();
853
- return step.schedule(process, keepAlive, immediate);
854
- };
855
- return acc;
856
- }, {});
857
- const cancel = (process) => {
858
- for (let i = 0; i < stepsOrder.length; i++) {
859
- steps[stepsOrder[i]].cancel(process);
860
- }
861
- };
862
- return { schedule, cancel, state, steps };
863
- }
864
-
865
- const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
866
-
867
675
  /**
868
676
  * Generate a list of every possible transform key.
869
677
  */
@@ -910,386 +718,6 @@ const resolveFinalValueInKeyframes = (v) => {
910
718
  return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
911
719
  };
912
720
 
913
- let now;
914
- function clearTime() {
915
- now = undefined;
916
- }
917
- /**
918
- * An eventloop-synchronous alternative to performance.now().
919
- *
920
- * Ensures that time measurements remain consistent within a synchronous context.
921
- * Usually calling performance.now() twice within the same synchronous context
922
- * will return different values which isn't useful for animations when we're usually
923
- * trying to sync animations to the same frame.
924
- */
925
- const time = {
926
- now: () => {
927
- if (now === undefined) {
928
- time.set(frameData.isProcessing || MotionGlobalConfig.useManualTiming
929
- ? frameData.timestamp
930
- : performance.now());
931
- }
932
- return now;
933
- },
934
- set: (newTime) => {
935
- now = newTime;
936
- queueMicrotask(clearTime);
937
- },
938
- };
939
-
940
- class SubscriptionManager {
941
- constructor() {
942
- this.subscriptions = [];
943
- }
944
- add(handler) {
945
- addUniqueItem(this.subscriptions, handler);
946
- return () => removeItem(this.subscriptions, handler);
947
- }
948
- notify(a, b, c) {
949
- const numSubscriptions = this.subscriptions.length;
950
- if (!numSubscriptions)
951
- return;
952
- if (numSubscriptions === 1) {
953
- /**
954
- * If there's only a single handler we can just call it without invoking a loop.
955
- */
956
- this.subscriptions[0](a, b, c);
957
- }
958
- else {
959
- for (let i = 0; i < numSubscriptions; i++) {
960
- /**
961
- * Check whether the handler exists before firing as it's possible
962
- * the subscriptions were modified during this loop running.
963
- */
964
- const handler = this.subscriptions[i];
965
- handler && handler(a, b, c);
966
- }
967
- }
968
- }
969
- getSize() {
970
- return this.subscriptions.length;
971
- }
972
- clear() {
973
- this.subscriptions.length = 0;
974
- }
975
- }
976
-
977
- const warned = new Set();
978
- function warnOnce(condition, message, element) {
979
- if (condition || warned.has(message))
980
- return;
981
- console.warn(message);
982
- if (element)
983
- console.warn(element);
984
- warned.add(message);
985
- }
986
-
987
- /**
988
- * Maximum time between the value of two frames, beyond which we
989
- * assume the velocity has since been 0.
990
- */
991
- const MAX_VELOCITY_DELTA = 30;
992
- const isFloat = (value) => {
993
- return !isNaN(parseFloat(value));
994
- };
995
- /**
996
- * `MotionValue` is used to track the state and velocity of motion values.
997
- *
998
- * @public
999
- */
1000
- class MotionValue {
1001
- /**
1002
- * @param init - The initiating value
1003
- * @param config - Optional configuration options
1004
- *
1005
- * - `transformer`: A function to transform incoming values with.
1006
- *
1007
- * @internal
1008
- */
1009
- constructor(init, options = {}) {
1010
- /**
1011
- * This will be replaced by the build step with the latest version number.
1012
- * When MotionValues are provided to motion components, warn if versions are mixed.
1013
- */
1014
- this.version = "12.4.13";
1015
- /**
1016
- * Tracks whether this value can output a velocity. Currently this is only true
1017
- * if the value is numerical, but we might be able to widen the scope here and support
1018
- * other value types.
1019
- *
1020
- * @internal
1021
- */
1022
- this.canTrackVelocity = null;
1023
- /**
1024
- * An object containing a SubscriptionManager for each active event.
1025
- */
1026
- this.events = {};
1027
- this.updateAndNotify = (v, render = true) => {
1028
- const currentTime = time.now();
1029
- /**
1030
- * If we're updating the value during another frame or eventloop
1031
- * than the previous frame, then the we set the previous frame value
1032
- * to current.
1033
- */
1034
- if (this.updatedAt !== currentTime) {
1035
- this.setPrevFrameValue();
1036
- }
1037
- this.prev = this.current;
1038
- this.setCurrent(v);
1039
- // Update update subscribers
1040
- if (this.current !== this.prev && this.events.change) {
1041
- this.events.change.notify(this.current);
1042
- }
1043
- // Update render subscribers
1044
- if (render && this.events.renderRequest) {
1045
- this.events.renderRequest.notify(this.current);
1046
- }
1047
- };
1048
- this.hasAnimated = false;
1049
- this.setCurrent(init);
1050
- this.owner = options.owner;
1051
- }
1052
- setCurrent(current) {
1053
- this.current = current;
1054
- this.updatedAt = time.now();
1055
- if (this.canTrackVelocity === null && current !== undefined) {
1056
- this.canTrackVelocity = isFloat(this.current);
1057
- }
1058
- }
1059
- setPrevFrameValue(prevFrameValue = this.current) {
1060
- this.prevFrameValue = prevFrameValue;
1061
- this.prevUpdatedAt = this.updatedAt;
1062
- }
1063
- /**
1064
- * Adds a function that will be notified when the `MotionValue` is updated.
1065
- *
1066
- * It returns a function that, when called, will cancel the subscription.
1067
- *
1068
- * When calling `onChange` inside a React component, it should be wrapped with the
1069
- * `useEffect` hook. As it returns an unsubscribe function, this should be returned
1070
- * from the `useEffect` function to ensure you don't add duplicate subscribers..
1071
- *
1072
- * ```jsx
1073
- * export const MyComponent = () => {
1074
- * const x = useMotionValue(0)
1075
- * const y = useMotionValue(0)
1076
- * const opacity = useMotionValue(1)
1077
- *
1078
- * useEffect(() => {
1079
- * function updateOpacity() {
1080
- * const maxXY = Math.max(x.get(), y.get())
1081
- * const newOpacity = transform(maxXY, [0, 100], [1, 0])
1082
- * opacity.set(newOpacity)
1083
- * }
1084
- *
1085
- * const unsubscribeX = x.on("change", updateOpacity)
1086
- * const unsubscribeY = y.on("change", updateOpacity)
1087
- *
1088
- * return () => {
1089
- * unsubscribeX()
1090
- * unsubscribeY()
1091
- * }
1092
- * }, [])
1093
- *
1094
- * return <motion.div style={{ x }} />
1095
- * }
1096
- * ```
1097
- *
1098
- * @param subscriber - A function that receives the latest value.
1099
- * @returns A function that, when called, will cancel this subscription.
1100
- *
1101
- * @deprecated
1102
- */
1103
- onChange(subscription) {
1104
- if (process.env.NODE_ENV !== "production") {
1105
- warnOnce(false, `value.onChange(callback) is deprecated. Switch to value.on("change", callback).`);
1106
- }
1107
- return this.on("change", subscription);
1108
- }
1109
- on(eventName, callback) {
1110
- if (!this.events[eventName]) {
1111
- this.events[eventName] = new SubscriptionManager();
1112
- }
1113
- const unsubscribe = this.events[eventName].add(callback);
1114
- if (eventName === "change") {
1115
- return () => {
1116
- unsubscribe();
1117
- /**
1118
- * If we have no more change listeners by the start
1119
- * of the next frame, stop active animations.
1120
- */
1121
- frame.read(() => {
1122
- if (!this.events.change.getSize()) {
1123
- this.stop();
1124
- }
1125
- });
1126
- };
1127
- }
1128
- return unsubscribe;
1129
- }
1130
- clearListeners() {
1131
- for (const eventManagers in this.events) {
1132
- this.events[eventManagers].clear();
1133
- }
1134
- }
1135
- /**
1136
- * Attaches a passive effect to the `MotionValue`.
1137
- *
1138
- * @internal
1139
- */
1140
- attach(passiveEffect, stopPassiveEffect) {
1141
- this.passiveEffect = passiveEffect;
1142
- this.stopPassiveEffect = stopPassiveEffect;
1143
- }
1144
- /**
1145
- * Sets the state of the `MotionValue`.
1146
- *
1147
- * @remarks
1148
- *
1149
- * ```jsx
1150
- * const x = useMotionValue(0)
1151
- * x.set(10)
1152
- * ```
1153
- *
1154
- * @param latest - Latest value to set.
1155
- * @param render - Whether to notify render subscribers. Defaults to `true`
1156
- *
1157
- * @public
1158
- */
1159
- set(v, render = true) {
1160
- if (!render || !this.passiveEffect) {
1161
- this.updateAndNotify(v, render);
1162
- }
1163
- else {
1164
- this.passiveEffect(v, this.updateAndNotify);
1165
- }
1166
- }
1167
- setWithVelocity(prev, current, delta) {
1168
- this.set(current);
1169
- this.prev = undefined;
1170
- this.prevFrameValue = prev;
1171
- this.prevUpdatedAt = this.updatedAt - delta;
1172
- }
1173
- /**
1174
- * Set the state of the `MotionValue`, stopping any active animations,
1175
- * effects, and resets velocity to `0`.
1176
- */
1177
- jump(v, endAnimation = true) {
1178
- this.updateAndNotify(v);
1179
- this.prev = v;
1180
- this.prevUpdatedAt = this.prevFrameValue = undefined;
1181
- endAnimation && this.stop();
1182
- if (this.stopPassiveEffect)
1183
- this.stopPassiveEffect();
1184
- }
1185
- /**
1186
- * Returns the latest state of `MotionValue`
1187
- *
1188
- * @returns - The latest state of `MotionValue`
1189
- *
1190
- * @public
1191
- */
1192
- get() {
1193
- return this.current;
1194
- }
1195
- /**
1196
- * @public
1197
- */
1198
- getPrevious() {
1199
- return this.prev;
1200
- }
1201
- /**
1202
- * Returns the latest velocity of `MotionValue`
1203
- *
1204
- * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
1205
- *
1206
- * @public
1207
- */
1208
- getVelocity() {
1209
- const currentTime = time.now();
1210
- if (!this.canTrackVelocity ||
1211
- this.prevFrameValue === undefined ||
1212
- currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
1213
- return 0;
1214
- }
1215
- const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
1216
- // Casts because of parseFloat's poor typing
1217
- return velocityPerSecond(parseFloat(this.current) -
1218
- parseFloat(this.prevFrameValue), delta);
1219
- }
1220
- /**
1221
- * Registers a new animation to control this `MotionValue`. Only one
1222
- * animation can drive a `MotionValue` at one time.
1223
- *
1224
- * ```jsx
1225
- * value.start()
1226
- * ```
1227
- *
1228
- * @param animation - A function that starts the provided animation
1229
- *
1230
- * @internal
1231
- */
1232
- start(startAnimation) {
1233
- this.stop();
1234
- return new Promise((resolve) => {
1235
- this.hasAnimated = true;
1236
- this.animation = startAnimation(resolve);
1237
- if (this.events.animationStart) {
1238
- this.events.animationStart.notify();
1239
- }
1240
- }).then(() => {
1241
- if (this.events.animationComplete) {
1242
- this.events.animationComplete.notify();
1243
- }
1244
- this.clearAnimation();
1245
- });
1246
- }
1247
- /**
1248
- * Stop the currently active animation.
1249
- *
1250
- * @public
1251
- */
1252
- stop() {
1253
- if (this.animation) {
1254
- this.animation.stop();
1255
- if (this.events.animationCancel) {
1256
- this.events.animationCancel.notify();
1257
- }
1258
- }
1259
- this.clearAnimation();
1260
- }
1261
- /**
1262
- * Returns `true` if this value is currently animating.
1263
- *
1264
- * @public
1265
- */
1266
- isAnimating() {
1267
- return !!this.animation;
1268
- }
1269
- clearAnimation() {
1270
- delete this.animation;
1271
- }
1272
- /**
1273
- * Destroy and clean up subscribers to this `MotionValue`.
1274
- *
1275
- * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
1276
- * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
1277
- * created a `MotionValue` via the `motionValue` function.
1278
- *
1279
- * @public
1280
- */
1281
- destroy() {
1282
- this.clearListeners();
1283
- this.stop();
1284
- if (this.stopPassiveEffect) {
1285
- this.stopPassiveEffect();
1286
- }
1287
- }
1288
- }
1289
- function motionValue(init, options) {
1290
- return new MotionValue(init, options);
1291
- }
1292
-
1293
721
  function getValueState(visualElement) {
1294
722
  const state = [{}, {}];
1295
723
  visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
@@ -1339,7 +767,7 @@ function setMotionValue(visualElement, key, value) {
1339
767
  visualElement.getValue(key).set(value);
1340
768
  }
1341
769
  else {
1342
- visualElement.addValue(key, motionValue(value));
770
+ visualElement.addValue(key, motionDom.motionValue(value));
1343
771
  }
1344
772
  }
1345
773
  function setTarget(visualElement, definition) {
@@ -2083,8 +1511,8 @@ class KeyframeResolver {
2083
1511
  toResolve.add(this);
2084
1512
  if (!isScheduled) {
2085
1513
  isScheduled = true;
2086
- frame.read(readAllKeyframes);
2087
- frame.resolveKeyframes(measureAllKeyframes);
1514
+ motionDom.frame.read(readAllKeyframes);
1515
+ motionDom.frame.resolveKeyframes(measureAllKeyframes);
2088
1516
  }
2089
1517
  }
2090
1518
  else {
@@ -2437,7 +1865,7 @@ class BaseAnimation {
2437
1865
  // Track whether the animation has been stopped. Stopped animations won't restart.
2438
1866
  this.isStopped = false;
2439
1867
  this.hasAttemptedResolve = false;
2440
- this.createdAt = time.now();
1868
+ this.createdAt = motionDom.time.now();
2441
1869
  this.options = {
2442
1870
  autoplay,
2443
1871
  delay,
@@ -2483,7 +1911,7 @@ class BaseAnimation {
2483
1911
  * Otherwise, it will call initPlayback on the implementing class.
2484
1912
  */
2485
1913
  onKeyframesResolved(keyframes, finalKeyframe) {
2486
- this.resolvedAt = time.now();
1914
+ this.resolvedAt = motionDom.time.now();
2487
1915
  this.hasAttemptedResolve = true;
2488
1916
  const { name, type, velocity, delay, onComplete, onUpdate, isGenerator, } = this.options;
2489
1917
  /**
@@ -2972,13 +2400,13 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
2972
2400
  const frameloopDriver = (update) => {
2973
2401
  const passTimestamp = ({ timestamp }) => update(timestamp);
2974
2402
  return {
2975
- start: () => frame.update(passTimestamp, true),
2976
- stop: () => cancelFrame(passTimestamp),
2403
+ start: () => motionDom.frame.update(passTimestamp, true),
2404
+ stop: () => motionDom.cancelFrame(passTimestamp),
2977
2405
  /**
2978
2406
  * If we're processing this frame we can use the
2979
2407
  * framelocked timestamp to keep things in sync.
2980
2408
  */
2981
- now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),
2409
+ now: () => (motionDom.frameData.isProcessing ? motionDom.frameData.timestamp : motionDom.time.now()),
2982
2410
  };
2983
2411
  };
2984
2412
 
@@ -3110,6 +2538,7 @@ class MainThreadAnimation extends BaseAnimation {
3110
2538
  }
3111
2539
  onPostResolved() {
3112
2540
  const { autoplay = true } = this.options;
2541
+ motionDom.activeAnimations.mainThread++;
3113
2542
  this.play();
3114
2543
  if (this.pendingPlayState === "paused" || !autoplay) {
3115
2544
  this.pause();
@@ -3341,6 +2770,7 @@ class MainThreadAnimation extends BaseAnimation {
3341
2770
  this.updateFinishedPromise();
3342
2771
  this.startTime = this.cancelTime = null;
3343
2772
  this.resolver.cancel();
2773
+ motionDom.activeAnimations.mainThread--;
3344
2774
  }
3345
2775
  stopDriver() {
3346
2776
  if (!this.driver)
@@ -3377,6 +2807,9 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
3377
2807
  */
3378
2808
  if (Array.isArray(easing))
3379
2809
  keyframeOptions.easing = easing;
2810
+ if (motionDom.statsBuffer.value) {
2811
+ motionDom.activeAnimations.waapi++;
2812
+ }
3380
2813
  const animation = element.animate(keyframeOptions, {
3381
2814
  delay,
3382
2815
  duration,
@@ -3385,6 +2818,11 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
3385
2818
  iterations: repeat + 1,
3386
2819
  direction: repeatType === "reverse" ? "alternate" : "normal",
3387
2820
  });
2821
+ if (motionDom.statsBuffer.value) {
2822
+ animation.finished.finally(() => {
2823
+ motionDom.activeAnimations.waapi--;
2824
+ });
2825
+ }
3388
2826
  return animation;
3389
2827
  }
3390
2828
 
@@ -3803,6 +3241,11 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
3803
3241
  shouldSkip = true;
3804
3242
  }
3805
3243
  }
3244
+ if (motionUtils.MotionGlobalConfig.skipAnimations) {
3245
+ shouldSkip = true;
3246
+ options.duration = 0;
3247
+ options.delay = 0;
3248
+ }
3806
3249
  /**
3807
3250
  * If the transition type or easing has been explicitly set by the user
3808
3251
  * then we don't want to allow flattening the animation.
@@ -3816,7 +3259,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
3816
3259
  if (shouldSkip && !isHandoff && value.get() !== undefined) {
3817
3260
  const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
3818
3261
  if (finalKeyframe !== undefined) {
3819
- frame.update(() => {
3262
+ motionDom.frame.update(() => {
3820
3263
  options.onUpdate(finalKeyframe);
3821
3264
  options.onComplete();
3822
3265
  });
@@ -3878,7 +3321,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3878
3321
  if (window.MotionHandoffAnimation) {
3879
3322
  const appearId = getOptimisedAppearId(visualElement);
3880
3323
  if (appearId) {
3881
- const startTime = window.MotionHandoffAnimation(appearId, key, frame);
3324
+ const startTime = window.MotionHandoffAnimation(appearId, key, motionDom.frame);
3882
3325
  if (startTime !== null) {
3883
3326
  valueTransition.startTime = startTime;
3884
3327
  isHandoff = true;
@@ -3896,7 +3339,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3896
3339
  }
3897
3340
  if (transitionEnd) {
3898
3341
  Promise.all(animations).then(() => {
3899
- frame.update(() => {
3342
+ motionDom.frame.update(() => {
3900
3343
  transitionEnd && setTarget(visualElement, transitionEnd);
3901
3344
  });
3902
3345
  });
@@ -4018,7 +3461,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4018
3461
  * and warn against mismatches.
4019
3462
  */
4020
3463
  if (process.env.NODE_ENV === "development") {
4021
- warnOnce(nextValue.version === "12.4.13", `Attempting to mix Motion versions ${nextValue.version} with 12.4.13 may not work as expected.`);
3464
+ motionUtils.warnOnce(nextValue.version === "12.6.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.0 may not work as expected.`);
4022
3465
  }
4023
3466
  }
4024
3467
  else if (isMotionValue(prevValue)) {
@@ -4026,7 +3469,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4026
3469
  * If we're swapping from a motion value to a static value,
4027
3470
  * create a new motion value from that
4028
3471
  */
4029
- element.addValue(key, motionValue(nextValue, { owner: element }));
3472
+ element.addValue(key, motionDom.motionValue(nextValue, { owner: element }));
4030
3473
  }
4031
3474
  else if (prevValue !== nextValue) {
4032
3475
  /**
@@ -4045,7 +3488,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4045
3488
  }
4046
3489
  else {
4047
3490
  const latestValue = element.getStaticValue(key);
4048
- element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue, { owner: element }));
3491
+ element.addValue(key, motionDom.motionValue(latestValue !== undefined ? latestValue : nextValue, { owner: element }));
4049
3492
  }
4050
3493
  }
4051
3494
  }
@@ -4145,10 +3588,10 @@ class VisualElement {
4145
3588
  };
4146
3589
  this.renderScheduledAt = 0.0;
4147
3590
  this.scheduleRender = () => {
4148
- const now = time.now();
3591
+ const now = motionDom.time.now();
4149
3592
  if (this.renderScheduledAt < now) {
4150
3593
  this.renderScheduledAt = now;
4151
- frame.render(this.render, false, true);
3594
+ motionDom.frame.render(this.render, false, true);
4152
3595
  }
4153
3596
  };
4154
3597
  const { latestValues, renderState, onUpdate } = visualState;
@@ -4208,7 +3651,7 @@ class VisualElement {
4208
3651
  ? true
4209
3652
  : prefersReducedMotion.current;
4210
3653
  if (process.env.NODE_ENV !== "production") {
4211
- warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.");
3654
+ motionUtils.warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.");
4212
3655
  }
4213
3656
  if (this.parent)
4214
3657
  this.parent.children.add(this);
@@ -4216,8 +3659,8 @@ class VisualElement {
4216
3659
  }
4217
3660
  unmount() {
4218
3661
  this.projection && this.projection.unmount();
4219
- cancelFrame(this.notifyUpdate);
4220
- cancelFrame(this.render);
3662
+ motionDom.cancelFrame(this.notifyUpdate);
3663
+ motionDom.cancelFrame(this.render);
4221
3664
  this.valueSubscriptions.forEach((remove) => remove());
4222
3665
  this.valueSubscriptions.clear();
4223
3666
  this.removeFromVariantTree && this.removeFromVariantTree();
@@ -4244,7 +3687,7 @@ class VisualElement {
4244
3687
  }
4245
3688
  const removeOnChange = value.on("change", (latestValue) => {
4246
3689
  this.latestValues[key] = latestValue;
4247
- this.props.onUpdate && frame.preRender(this.notifyUpdate);
3690
+ this.props.onUpdate && motionDom.frame.preRender(this.notifyUpdate);
4248
3691
  if (valueIsTransform && this.projection) {
4249
3692
  this.projection.isTransformDirty = true;
4250
3693
  }
@@ -4431,7 +3874,7 @@ class VisualElement {
4431
3874
  }
4432
3875
  let value = this.values.get(key);
4433
3876
  if (value === undefined && defaultValue !== undefined) {
4434
- value = motionValue(defaultValue === null ? undefined : defaultValue, { owner: this });
3877
+ value = motionDom.motionValue(defaultValue === null ? undefined : defaultValue, { owner: this });
4435
3878
  this.addValue(key, value);
4436
3879
  }
4437
3880
  return value;
@@ -4504,7 +3947,7 @@ class VisualElement {
4504
3947
  }
4505
3948
  on(eventName, callback) {
4506
3949
  if (!this.events[eventName]) {
4507
- this.events[eventName] = new SubscriptionManager();
3950
+ this.events[eventName] = new motionUtils.SubscriptionManager();
4508
3951
  }
4509
3952
  return this.events[eventName].add(callback);
4510
3953
  }
@@ -4899,7 +4342,7 @@ class SVGVisualElement extends DOMVisualElement {
4899
4342
  }
4900
4343
  onBindTransform() {
4901
4344
  if (this.current && !this.renderState.dimensions) {
4902
- frame.postRender(this.updateDimensions);
4345
+ motionDom.frame.postRender(this.updateDimensions);
4903
4346
  }
4904
4347
  }
4905
4348
  build(renderState, latestValues, props) {
@@ -5054,9 +4497,9 @@ function createObjectVisualElement(subject) {
5054
4497
  }
5055
4498
 
5056
4499
  function animateSingleValue(value, keyframes, options) {
5057
- const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
5058
- motionValue$1.start(animateMotionValue("", motionValue$1, keyframes, options));
5059
- return motionValue$1.animation;
4500
+ const motionValue = isMotionValue(value) ? value : motionDom.motionValue(value);
4501
+ motionValue.start(animateMotionValue("", motionValue, keyframes, options));
4502
+ return motionValue.animation;
5060
4503
  }
5061
4504
 
5062
4505
  function isSingleValue(subject, keyframes) {
@@ -5308,8 +4751,8 @@ function observeTimeline(update, timeline) {
5308
4751
  }
5309
4752
  prevProgress = progress;
5310
4753
  };
5311
- frame.update(onFrame, true);
5312
- return () => cancelFrame(onFrame);
4754
+ motionDom.frame.update(onFrame, true);
4755
+ return () => motionDom.cancelFrame(onFrame);
5313
4756
  }
5314
4757
 
5315
4758
  const resizeHandlers = new WeakMap();
@@ -5450,7 +4893,7 @@ function updateAxisInfo(element, axisName, info, time) {
5450
4893
  axis.velocity =
5451
4894
  elapsed > maxElapsed
5452
4895
  ? 0
5453
- : velocityPerSecond(axis.current - prev, elapsed);
4896
+ : motionUtils.velocityPerSecond(axis.current - prev, elapsed);
5454
4897
  }
5455
4898
  function updateScrollInfo(element, info, time) {
5456
4899
  updateAxisInfo(element, "x", info, time);
@@ -5675,7 +5118,7 @@ function measure(container, target = container, info) {
5675
5118
  */
5676
5119
  if (process.env.NODE_ENV !== "production") {
5677
5120
  if (container && target && target !== container) {
5678
- warnOnce(getComputedStyle(container).position !== "static", "Please ensure that the container has a non-static position, like 'relative', 'fixed', or 'absolute' to ensure scroll offset is calculated correctly.");
5121
+ motionUtils.warnOnce(getComputedStyle(container).position !== "static", "Please ensure that the container has a non-static position, like 'relative', 'fixed', or 'absolute' to ensure scroll offset is calculated correctly.");
5679
5122
  }
5680
5123
  }
5681
5124
  }
@@ -5723,7 +5166,7 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
5723
5166
  };
5724
5167
  const updateAll = () => {
5725
5168
  for (const handler of containerHandlers) {
5726
- handler.update(frameData.timestamp);
5169
+ handler.update(motionDom.frameData.timestamp);
5727
5170
  }
5728
5171
  };
5729
5172
  const notifyAll = () => {
@@ -5731,9 +5174,9 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
5731
5174
  handler.notify();
5732
5175
  };
5733
5176
  const listener = () => {
5734
- frame.read(measureAll, false, true);
5735
- frame.read(updateAll, false, true);
5736
- frame.update(notifyAll, false, true);
5177
+ motionDom.frame.read(measureAll, false, true);
5178
+ motionDom.frame.read(updateAll, false, true);
5179
+ motionDom.frame.update(notifyAll, false, true);
5737
5180
  };
5738
5181
  scrollListeners.set(container, listener);
5739
5182
  const target = getEventTarget(container);
@@ -5744,10 +5187,10 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
5744
5187
  target.addEventListener("scroll", listener, { passive: true });
5745
5188
  }
5746
5189
  const listener = scrollListeners.get(container);
5747
- frame.read(listener, false, true);
5190
+ motionDom.frame.read(listener, false, true);
5748
5191
  return () => {
5749
5192
  var _a;
5750
- cancelFrame(listener);
5193
+ motionDom.cancelFrame(listener);
5751
5194
  /**
5752
5195
  * Check if we even have any handlers for this container.
5753
5196
  */
@@ -5930,16 +5373,16 @@ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
5930
5373
  * Timeout defined in ms
5931
5374
  */
5932
5375
  function delay(callback, timeout) {
5933
- const start = time.now();
5376
+ const start = motionDom.time.now();
5934
5377
  const checkElapsed = ({ timestamp }) => {
5935
5378
  const elapsed = timestamp - start;
5936
5379
  if (elapsed >= timeout) {
5937
- cancelFrame(checkElapsed);
5380
+ motionDom.cancelFrame(checkElapsed);
5938
5381
  callback(elapsed - timeout);
5939
5382
  }
5940
5383
  };
5941
- frame.read(checkElapsed, true);
5942
- return () => cancelFrame(checkElapsed);
5384
+ motionDom.frame.read(checkElapsed, true);
5385
+ return () => motionDom.cancelFrame(checkElapsed);
5943
5386
  }
5944
5387
  function delayInSeconds(callback, timeout) {
5945
5388
  return delay(callback, motionUtils.secondsToMilliseconds(timeout));
@@ -5971,22 +5414,22 @@ function transform(...args) {
5971
5414
  return useImmediate ? interpolator(inputValue) : interpolator;
5972
5415
  }
5973
5416
 
5974
- /**
5975
- * @deprecated
5976
- *
5977
- * Import as `frame` instead.
5978
- */
5979
- const sync = frame;
5980
- /**
5981
- * @deprecated
5982
- *
5983
- * Use cancelFrame(callback) instead.
5984
- */
5985
- const cancelSync = stepsOrder.reduce((acc, key) => {
5986
- acc[key] = (process) => cancelFrame(process);
5987
- return acc;
5988
- }, {});
5989
-
5417
+ Object.defineProperty(exports, "MotionValue", {
5418
+ enumerable: true,
5419
+ get: function () { return motionDom.MotionValue; }
5420
+ });
5421
+ Object.defineProperty(exports, "cancelFrame", {
5422
+ enumerable: true,
5423
+ get: function () { return motionDom.cancelFrame; }
5424
+ });
5425
+ Object.defineProperty(exports, "frame", {
5426
+ enumerable: true,
5427
+ get: function () { return motionDom.frame; }
5428
+ });
5429
+ Object.defineProperty(exports, "frameData", {
5430
+ enumerable: true,
5431
+ get: function () { return motionDom.frameData; }
5432
+ });
5990
5433
  Object.defineProperty(exports, "hover", {
5991
5434
  enumerable: true,
5992
5435
  get: function () { return motionDom.hover; }
@@ -5995,10 +5438,18 @@ Object.defineProperty(exports, "isDragActive", {
5995
5438
  enumerable: true,
5996
5439
  get: function () { return motionDom.isDragActive; }
5997
5440
  });
5441
+ Object.defineProperty(exports, "motionValue", {
5442
+ enumerable: true,
5443
+ get: function () { return motionDom.motionValue; }
5444
+ });
5998
5445
  Object.defineProperty(exports, "press", {
5999
5446
  enumerable: true,
6000
5447
  get: function () { return motionDom.press; }
6001
5448
  });
5449
+ Object.defineProperty(exports, "time", {
5450
+ enumerable: true,
5451
+ get: function () { return motionDom.time; }
5452
+ });
6002
5453
  Object.defineProperty(exports, "invariant", {
6003
5454
  enumerable: true,
6004
5455
  get: function () { return motionUtils.invariant; }
@@ -6011,15 +5462,12 @@ Object.defineProperty(exports, "progress", {
6011
5462
  enumerable: true,
6012
5463
  get: function () { return motionUtils.progress; }
6013
5464
  });
6014
- exports.MotionValue = MotionValue;
6015
5465
  exports.animate = animate;
6016
5466
  exports.animateMini = animateMini;
6017
5467
  exports.anticipate = anticipate;
6018
5468
  exports.backIn = backIn;
6019
5469
  exports.backInOut = backInOut;
6020
5470
  exports.backOut = backOut;
6021
- exports.cancelFrame = cancelFrame;
6022
- exports.cancelSync = cancelSync;
6023
5471
  exports.circIn = circIn;
6024
5472
  exports.circInOut = circInOut;
6025
5473
  exports.circOut = circOut;
@@ -6032,16 +5480,12 @@ exports.distance2D = distance2D;
6032
5480
  exports.easeIn = easeIn;
6033
5481
  exports.easeInOut = easeInOut;
6034
5482
  exports.easeOut = easeOut;
6035
- exports.frame = frame;
6036
- exports.frameData = frameData;
6037
- exports.frameSteps = frameSteps;
6038
5483
  exports.inView = inView;
6039
5484
  exports.inertia = inertia;
6040
5485
  exports.interpolate = interpolate;
6041
5486
  exports.keyframes = keyframes;
6042
5487
  exports.mirrorEasing = mirrorEasing;
6043
5488
  exports.mix = mix;
6044
- exports.motionValue = motionValue;
6045
5489
  exports.pipe = pipe;
6046
5490
  exports.reverseEasing = reverseEasing;
6047
5491
  exports.scroll = scroll;
@@ -6049,7 +5493,5 @@ exports.scrollInfo = scrollInfo;
6049
5493
  exports.spring = spring;
6050
5494
  exports.stagger = stagger;
6051
5495
  exports.steps = steps;
6052
- exports.sync = sync;
6053
- exports.time = time;
6054
5496
  exports.transform = transform;
6055
5497
  exports.wrap = wrap;