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
@@ -1,7 +0,0 @@
1
- const activeAnimations = {
2
- layout: 0,
3
- mainThread: 0,
4
- waapi: 0,
5
- };
6
-
7
- export { activeAnimations };
@@ -1,6 +0,0 @@
1
- const statsBuffer = {
2
- value: null,
3
- addProjectionMetrics: null,
4
- };
5
-
6
- export { statsBuffer };
@@ -1,113 +0,0 @@
1
- import { activeAnimations } from './animation-count.mjs';
2
- import { statsBuffer } from './buffer.mjs';
3
- import { frame, cancelFrame, frameData } from '../frameloop/frame.mjs';
4
-
5
- function record() {
6
- const { value } = statsBuffer;
7
- if (value === null) {
8
- cancelFrame(record);
9
- return;
10
- }
11
- value.frameloop.rate.push(frameData.delta);
12
- value.animations.mainThread.push(activeAnimations.mainThread);
13
- value.animations.waapi.push(activeAnimations.waapi);
14
- value.animations.layout.push(activeAnimations.layout);
15
- }
16
- function mean(values) {
17
- return values.reduce((acc, value) => acc + value, 0) / values.length;
18
- }
19
- function summarise(values, calcAverage = mean) {
20
- if (values.length === 0) {
21
- return {
22
- min: 0,
23
- max: 0,
24
- avg: 0,
25
- };
26
- }
27
- return {
28
- min: Math.min(...values),
29
- max: Math.max(...values),
30
- avg: calcAverage(values),
31
- };
32
- }
33
- const msToFps = (ms) => Math.round(1000 / ms);
34
- function clearStatsBuffer() {
35
- statsBuffer.value = null;
36
- statsBuffer.addProjectionMetrics = null;
37
- }
38
- function reportStats() {
39
- const { value } = statsBuffer;
40
- if (!value) {
41
- throw new Error("Stats are not being measured");
42
- }
43
- clearStatsBuffer();
44
- cancelFrame(record);
45
- const summary = {
46
- frameloop: {
47
- rate: summarise(value.frameloop.rate),
48
- read: summarise(value.frameloop.read),
49
- resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
50
- update: summarise(value.frameloop.update),
51
- preRender: summarise(value.frameloop.preRender),
52
- render: summarise(value.frameloop.render),
53
- postRender: summarise(value.frameloop.postRender),
54
- },
55
- animations: {
56
- mainThread: summarise(value.animations.mainThread),
57
- waapi: summarise(value.animations.waapi),
58
- layout: summarise(value.animations.layout),
59
- },
60
- layoutProjection: {
61
- nodes: summarise(value.layoutProjection.nodes),
62
- calculatedTargetDeltas: summarise(value.layoutProjection.calculatedTargetDeltas),
63
- calculatedProjections: summarise(value.layoutProjection.calculatedProjections),
64
- },
65
- };
66
- /**
67
- * Convert the rate to FPS
68
- */
69
- const { rate } = summary.frameloop;
70
- rate.min = msToFps(rate.min);
71
- rate.max = msToFps(rate.max);
72
- rate.avg = msToFps(rate.avg);
73
- [rate.min, rate.max] = [rate.max, rate.min];
74
- return summary;
75
- }
76
- function recordStats() {
77
- if (statsBuffer.value) {
78
- clearStatsBuffer();
79
- throw new Error("Stats are already being measured");
80
- }
81
- const newStatsBuffer = statsBuffer;
82
- newStatsBuffer.value = {
83
- frameloop: {
84
- rate: [],
85
- read: [],
86
- resolveKeyframes: [],
87
- update: [],
88
- preRender: [],
89
- render: [],
90
- postRender: [],
91
- },
92
- animations: {
93
- mainThread: [],
94
- waapi: [],
95
- layout: [],
96
- },
97
- layoutProjection: {
98
- nodes: [],
99
- calculatedTargetDeltas: [],
100
- calculatedProjections: [],
101
- },
102
- };
103
- newStatsBuffer.addProjectionMetrics = (metrics) => {
104
- const { layoutProjection } = newStatsBuffer.value;
105
- layoutProjection.nodes.push(metrics.nodes);
106
- layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
107
- layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
108
- };
109
- frame.postRender(record, true);
110
- return reportStats;
111
- }
112
-
113
- export { recordStats };
@@ -1,6 +0,0 @@
1
- const MotionGlobalConfig = {
2
- skipAnimations: false,
3
- useManualTiming: false,
4
- };
5
-
6
- export { MotionGlobalConfig };
@@ -1,21 +0,0 @@
1
- function addUniqueItem(arr, item) {
2
- if (arr.indexOf(item) === -1)
3
- arr.push(item);
4
- }
5
- function removeItem(arr, item) {
6
- const index = arr.indexOf(item);
7
- if (index > -1)
8
- arr.splice(index, 1);
9
- }
10
- // Adapted from array-move
11
- function moveItem([...arr], fromIndex, toIndex) {
12
- const startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
13
- if (startIndex >= 0 && startIndex < arr.length) {
14
- const endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
15
- const [item] = arr.splice(fromIndex, 1);
16
- arr.splice(endIndex, 0, item);
17
- }
18
- return arr;
19
- }
20
-
21
- export { addUniqueItem, moveItem, removeItem };
@@ -1,40 +0,0 @@
1
- import { addUniqueItem, removeItem } from './array.mjs';
2
-
3
- class SubscriptionManager {
4
- constructor() {
5
- this.subscriptions = [];
6
- }
7
- add(handler) {
8
- addUniqueItem(this.subscriptions, handler);
9
- return () => removeItem(this.subscriptions, handler);
10
- }
11
- notify(a, b, c) {
12
- const numSubscriptions = this.subscriptions.length;
13
- if (!numSubscriptions)
14
- return;
15
- if (numSubscriptions === 1) {
16
- /**
17
- * If there's only a single handler we can just call it without invoking a loop.
18
- */
19
- this.subscriptions[0](a, b, c);
20
- }
21
- else {
22
- for (let i = 0; i < numSubscriptions; i++) {
23
- /**
24
- * Check whether the handler exists before firing as it's possible
25
- * the subscriptions were modified during this loop running.
26
- */
27
- const handler = this.subscriptions[i];
28
- handler && handler(a, b, c);
29
- }
30
- }
31
- }
32
- getSize() {
33
- return this.subscriptions.length;
34
- }
35
- clear() {
36
- this.subscriptions.length = 0;
37
- }
38
- }
39
-
40
- export { SubscriptionManager };
@@ -1,11 +0,0 @@
1
- /*
2
- Convert velocity into velocity per second
3
-
4
- @param [number]: Unit per frame
5
- @param [number]: Frame duration in ms
6
- */
7
- function velocityPerSecond(velocity, frameDuration) {
8
- return frameDuration ? velocity * (1000 / frameDuration) : 0;
9
- }
10
-
11
- export { velocityPerSecond };
@@ -1,11 +0,0 @@
1
- const warned = new Set();
2
- function warnOnce(condition, message, element) {
3
- if (condition || warned.has(message))
4
- return;
5
- console.warn(message);
6
- if (element)
7
- console.warn(element);
8
- warned.add(message);
9
- }
10
-
11
- export { warnOnce };
@@ -1,319 +0,0 @@
1
- import { time } from '../frameloop/sync-time.mjs';
2
- import { SubscriptionManager } from '../utils/subscription-manager.mjs';
3
- import { velocityPerSecond } from '../utils/velocity-per-second.mjs';
4
- import { warnOnce } from '../utils/warn-once.mjs';
5
- import { frame } from '../frameloop/frame.mjs';
6
-
7
- /**
8
- * Maximum time between the value of two frames, beyond which we
9
- * assume the velocity has since been 0.
10
- */
11
- const MAX_VELOCITY_DELTA = 30;
12
- const isFloat = (value) => {
13
- return !isNaN(parseFloat(value));
14
- };
15
- const collectMotionValues = {
16
- current: undefined,
17
- };
18
- /**
19
- * `MotionValue` is used to track the state and velocity of motion values.
20
- *
21
- * @public
22
- */
23
- class MotionValue {
24
- /**
25
- * @param init - The initiating value
26
- * @param config - Optional configuration options
27
- *
28
- * - `transformer`: A function to transform incoming values with.
29
- *
30
- * @internal
31
- */
32
- constructor(init, options = {}) {
33
- /**
34
- * This will be replaced by the build step with the latest version number.
35
- * When MotionValues are provided to motion components, warn if versions are mixed.
36
- */
37
- this.version = "12.4.13";
38
- /**
39
- * Tracks whether this value can output a velocity. Currently this is only true
40
- * if the value is numerical, but we might be able to widen the scope here and support
41
- * other value types.
42
- *
43
- * @internal
44
- */
45
- this.canTrackVelocity = null;
46
- /**
47
- * An object containing a SubscriptionManager for each active event.
48
- */
49
- this.events = {};
50
- this.updateAndNotify = (v, render = true) => {
51
- const currentTime = time.now();
52
- /**
53
- * If we're updating the value during another frame or eventloop
54
- * than the previous frame, then the we set the previous frame value
55
- * to current.
56
- */
57
- if (this.updatedAt !== currentTime) {
58
- this.setPrevFrameValue();
59
- }
60
- this.prev = this.current;
61
- this.setCurrent(v);
62
- // Update update subscribers
63
- if (this.current !== this.prev && this.events.change) {
64
- this.events.change.notify(this.current);
65
- }
66
- // Update render subscribers
67
- if (render && this.events.renderRequest) {
68
- this.events.renderRequest.notify(this.current);
69
- }
70
- };
71
- this.hasAnimated = false;
72
- this.setCurrent(init);
73
- this.owner = options.owner;
74
- }
75
- setCurrent(current) {
76
- this.current = current;
77
- this.updatedAt = time.now();
78
- if (this.canTrackVelocity === null && current !== undefined) {
79
- this.canTrackVelocity = isFloat(this.current);
80
- }
81
- }
82
- setPrevFrameValue(prevFrameValue = this.current) {
83
- this.prevFrameValue = prevFrameValue;
84
- this.prevUpdatedAt = this.updatedAt;
85
- }
86
- /**
87
- * Adds a function that will be notified when the `MotionValue` is updated.
88
- *
89
- * It returns a function that, when called, will cancel the subscription.
90
- *
91
- * When calling `onChange` inside a React component, it should be wrapped with the
92
- * `useEffect` hook. As it returns an unsubscribe function, this should be returned
93
- * from the `useEffect` function to ensure you don't add duplicate subscribers..
94
- *
95
- * ```jsx
96
- * export const MyComponent = () => {
97
- * const x = useMotionValue(0)
98
- * const y = useMotionValue(0)
99
- * const opacity = useMotionValue(1)
100
- *
101
- * useEffect(() => {
102
- * function updateOpacity() {
103
- * const maxXY = Math.max(x.get(), y.get())
104
- * const newOpacity = transform(maxXY, [0, 100], [1, 0])
105
- * opacity.set(newOpacity)
106
- * }
107
- *
108
- * const unsubscribeX = x.on("change", updateOpacity)
109
- * const unsubscribeY = y.on("change", updateOpacity)
110
- *
111
- * return () => {
112
- * unsubscribeX()
113
- * unsubscribeY()
114
- * }
115
- * }, [])
116
- *
117
- * return <motion.div style={{ x }} />
118
- * }
119
- * ```
120
- *
121
- * @param subscriber - A function that receives the latest value.
122
- * @returns A function that, when called, will cancel this subscription.
123
- *
124
- * @deprecated
125
- */
126
- onChange(subscription) {
127
- if (process.env.NODE_ENV !== "production") {
128
- warnOnce(false, `value.onChange(callback) is deprecated. Switch to value.on("change", callback).`);
129
- }
130
- return this.on("change", subscription);
131
- }
132
- on(eventName, callback) {
133
- if (!this.events[eventName]) {
134
- this.events[eventName] = new SubscriptionManager();
135
- }
136
- const unsubscribe = this.events[eventName].add(callback);
137
- if (eventName === "change") {
138
- return () => {
139
- unsubscribe();
140
- /**
141
- * If we have no more change listeners by the start
142
- * of the next frame, stop active animations.
143
- */
144
- frame.read(() => {
145
- if (!this.events.change.getSize()) {
146
- this.stop();
147
- }
148
- });
149
- };
150
- }
151
- return unsubscribe;
152
- }
153
- clearListeners() {
154
- for (const eventManagers in this.events) {
155
- this.events[eventManagers].clear();
156
- }
157
- }
158
- /**
159
- * Attaches a passive effect to the `MotionValue`.
160
- *
161
- * @internal
162
- */
163
- attach(passiveEffect, stopPassiveEffect) {
164
- this.passiveEffect = passiveEffect;
165
- this.stopPassiveEffect = stopPassiveEffect;
166
- }
167
- /**
168
- * Sets the state of the `MotionValue`.
169
- *
170
- * @remarks
171
- *
172
- * ```jsx
173
- * const x = useMotionValue(0)
174
- * x.set(10)
175
- * ```
176
- *
177
- * @param latest - Latest value to set.
178
- * @param render - Whether to notify render subscribers. Defaults to `true`
179
- *
180
- * @public
181
- */
182
- set(v, render = true) {
183
- if (!render || !this.passiveEffect) {
184
- this.updateAndNotify(v, render);
185
- }
186
- else {
187
- this.passiveEffect(v, this.updateAndNotify);
188
- }
189
- }
190
- setWithVelocity(prev, current, delta) {
191
- this.set(current);
192
- this.prev = undefined;
193
- this.prevFrameValue = prev;
194
- this.prevUpdatedAt = this.updatedAt - delta;
195
- }
196
- /**
197
- * Set the state of the `MotionValue`, stopping any active animations,
198
- * effects, and resets velocity to `0`.
199
- */
200
- jump(v, endAnimation = true) {
201
- this.updateAndNotify(v);
202
- this.prev = v;
203
- this.prevUpdatedAt = this.prevFrameValue = undefined;
204
- endAnimation && this.stop();
205
- if (this.stopPassiveEffect)
206
- this.stopPassiveEffect();
207
- }
208
- /**
209
- * Returns the latest state of `MotionValue`
210
- *
211
- * @returns - The latest state of `MotionValue`
212
- *
213
- * @public
214
- */
215
- get() {
216
- if (collectMotionValues.current) {
217
- collectMotionValues.current.push(this);
218
- }
219
- return this.current;
220
- }
221
- /**
222
- * @public
223
- */
224
- getPrevious() {
225
- return this.prev;
226
- }
227
- /**
228
- * Returns the latest velocity of `MotionValue`
229
- *
230
- * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
231
- *
232
- * @public
233
- */
234
- getVelocity() {
235
- const currentTime = time.now();
236
- if (!this.canTrackVelocity ||
237
- this.prevFrameValue === undefined ||
238
- currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
239
- return 0;
240
- }
241
- const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
242
- // Casts because of parseFloat's poor typing
243
- return velocityPerSecond(parseFloat(this.current) -
244
- parseFloat(this.prevFrameValue), delta);
245
- }
246
- /**
247
- * Registers a new animation to control this `MotionValue`. Only one
248
- * animation can drive a `MotionValue` at one time.
249
- *
250
- * ```jsx
251
- * value.start()
252
- * ```
253
- *
254
- * @param animation - A function that starts the provided animation
255
- *
256
- * @internal
257
- */
258
- start(startAnimation) {
259
- this.stop();
260
- return new Promise((resolve) => {
261
- this.hasAnimated = true;
262
- this.animation = startAnimation(resolve);
263
- if (this.events.animationStart) {
264
- this.events.animationStart.notify();
265
- }
266
- }).then(() => {
267
- if (this.events.animationComplete) {
268
- this.events.animationComplete.notify();
269
- }
270
- this.clearAnimation();
271
- });
272
- }
273
- /**
274
- * Stop the currently active animation.
275
- *
276
- * @public
277
- */
278
- stop() {
279
- if (this.animation) {
280
- this.animation.stop();
281
- if (this.events.animationCancel) {
282
- this.events.animationCancel.notify();
283
- }
284
- }
285
- this.clearAnimation();
286
- }
287
- /**
288
- * Returns `true` if this value is currently animating.
289
- *
290
- * @public
291
- */
292
- isAnimating() {
293
- return !!this.animation;
294
- }
295
- clearAnimation() {
296
- delete this.animation;
297
- }
298
- /**
299
- * Destroy and clean up subscribers to this `MotionValue`.
300
- *
301
- * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
302
- * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
303
- * created a `MotionValue` via the `motionValue` function.
304
- *
305
- * @public
306
- */
307
- destroy() {
308
- this.clearListeners();
309
- this.stop();
310
- if (this.stopPassiveEffect) {
311
- this.stopPassiveEffect();
312
- }
313
- }
314
- }
315
- function motionValue(init, options) {
316
- return new MotionValue(init, options);
317
- }
318
-
319
- export { MotionValue, collectMotionValues, motionValue };