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/debug.js CHANGED
@@ -2,287 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var motionUtils = require('motion-utils');
5
+ var motionDom = require('motion-dom');
6
6
 
7
- const stepsOrder = [
8
- "read", // Read
9
- "resolveKeyframes", // Write/Read/Write/Read
10
- "update", // Compute
11
- "preRender", // Compute
12
- "render", // Write
13
- "postRender", // Compute
14
- ];
15
7
 
16
- const statsBuffer = {
17
- value: null,
18
- addProjectionMetrics: null,
19
- };
20
8
 
21
- function createRenderStep(runNextFrame, stepName) {
22
- /**
23
- * We create and reuse two queues, one to queue jobs for the current frame
24
- * and one for the next. We reuse to avoid triggering GC after x frames.
25
- */
26
- let thisFrame = new Set();
27
- let nextFrame = new Set();
28
- /**
29
- * Track whether we're currently processing jobs in this step. This way
30
- * we can decide whether to schedule new jobs for this frame or next.
31
- */
32
- let isProcessing = false;
33
- let flushNextFrame = false;
34
- /**
35
- * A set of processes which were marked keepAlive when scheduled.
36
- */
37
- const toKeepAlive = new WeakSet();
38
- let latestFrameData = {
39
- delta: 0.0,
40
- timestamp: 0.0,
41
- isProcessing: false,
42
- };
43
- let numCalls = 0;
44
- function triggerCallback(callback) {
45
- if (toKeepAlive.has(callback)) {
46
- step.schedule(callback);
47
- runNextFrame();
48
- }
49
- numCalls++;
50
- callback(latestFrameData);
51
- }
52
- const step = {
53
- /**
54
- * Schedule a process to run on the next frame.
55
- */
56
- schedule: (callback, keepAlive = false, immediate = false) => {
57
- const addToCurrentFrame = immediate && isProcessing;
58
- const queue = addToCurrentFrame ? thisFrame : nextFrame;
59
- if (keepAlive)
60
- toKeepAlive.add(callback);
61
- if (!queue.has(callback))
62
- queue.add(callback);
63
- return callback;
64
- },
65
- /**
66
- * Cancel the provided callback from running on the next frame.
67
- */
68
- cancel: (callback) => {
69
- nextFrame.delete(callback);
70
- toKeepAlive.delete(callback);
71
- },
72
- /**
73
- * Execute all schedule callbacks.
74
- */
75
- process: (frameData) => {
76
- latestFrameData = frameData;
77
- /**
78
- * If we're already processing we've probably been triggered by a flushSync
79
- * inside an existing process. Instead of executing, mark flushNextFrame
80
- * as true and ensure we flush the following frame at the end of this one.
81
- */
82
- if (isProcessing) {
83
- flushNextFrame = true;
84
- return;
85
- }
86
- isProcessing = true;
87
- [thisFrame, nextFrame] = [nextFrame, thisFrame];
88
- // Execute this frame
89
- thisFrame.forEach(triggerCallback);
90
- /**
91
- * If we're recording stats then
92
- */
93
- if (stepName && statsBuffer.value) {
94
- statsBuffer.value.frameloop[stepName].push(numCalls);
95
- }
96
- numCalls = 0;
97
- // Clear the frame so no callbacks remain. This is to avoid
98
- // memory leaks should this render step not run for a while.
99
- thisFrame.clear();
100
- isProcessing = false;
101
- if (flushNextFrame) {
102
- flushNextFrame = false;
103
- step.process(frameData);
104
- }
105
- },
106
- };
107
- return step;
108
- }
109
-
110
- const maxElapsed = 40;
111
- function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
112
- let runNextFrame = false;
113
- let useDefaultElapsed = true;
114
- const state = {
115
- delta: 0.0,
116
- timestamp: 0.0,
117
- isProcessing: false,
118
- };
119
- const flagRunNextFrame = () => (runNextFrame = true);
120
- const steps = stepsOrder.reduce((acc, key) => {
121
- acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
122
- return acc;
123
- }, {});
124
- const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
125
- const processBatch = () => {
126
- const timestamp = performance.now();
127
- runNextFrame = false;
128
- {
129
- state.delta = useDefaultElapsed
130
- ? 1000 / 60
131
- : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
132
- }
133
- state.timestamp = timestamp;
134
- state.isProcessing = true;
135
- // Unrolled render loop for better per-frame performance
136
- read.process(state);
137
- resolveKeyframes.process(state);
138
- update.process(state);
139
- preRender.process(state);
140
- render.process(state);
141
- postRender.process(state);
142
- state.isProcessing = false;
143
- if (runNextFrame && allowKeepAlive) {
144
- useDefaultElapsed = false;
145
- scheduleNextBatch(processBatch);
146
- }
147
- };
148
- const wake = () => {
149
- runNextFrame = true;
150
- useDefaultElapsed = true;
151
- if (!state.isProcessing) {
152
- scheduleNextBatch(processBatch);
153
- }
154
- };
155
- const schedule = stepsOrder.reduce((acc, key) => {
156
- const step = steps[key];
157
- acc[key] = (process, keepAlive = false, immediate = false) => {
158
- if (!runNextFrame)
159
- wake();
160
- return step.schedule(process, keepAlive, immediate);
161
- };
162
- return acc;
163
- }, {});
164
- const cancel = (process) => {
165
- for (let i = 0; i < stepsOrder.length; i++) {
166
- steps[stepsOrder[i]].cancel(process);
167
- }
168
- };
169
- return { schedule, cancel, state, steps };
170
- }
171
-
172
- const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
173
-
174
- const activeAnimations = {
175
- layout: 0,
176
- mainThread: 0,
177
- waapi: 0,
178
- };
179
-
180
- function record() {
181
- const { value } = statsBuffer;
182
- if (value === null) {
183
- cancelFrame(record);
184
- return;
185
- }
186
- value.frameloop.rate.push(frameData.delta);
187
- value.animations.mainThread.push(activeAnimations.mainThread);
188
- value.animations.waapi.push(activeAnimations.waapi);
189
- value.animations.layout.push(activeAnimations.layout);
190
- }
191
- function mean(values) {
192
- return values.reduce((acc, value) => acc + value, 0) / values.length;
193
- }
194
- function summarise(values, calcAverage = mean) {
195
- if (values.length === 0) {
196
- return {
197
- min: 0,
198
- max: 0,
199
- avg: 0,
200
- };
201
- }
202
- return {
203
- min: Math.min(...values),
204
- max: Math.max(...values),
205
- avg: calcAverage(values),
206
- };
207
- }
208
- const msToFps = (ms) => Math.round(1000 / ms);
209
- function clearStatsBuffer() {
210
- statsBuffer.value = null;
211
- statsBuffer.addProjectionMetrics = null;
212
- }
213
- function reportStats() {
214
- const { value } = statsBuffer;
215
- if (!value) {
216
- throw new Error("Stats are not being measured");
217
- }
218
- clearStatsBuffer();
219
- cancelFrame(record);
220
- const summary = {
221
- frameloop: {
222
- rate: summarise(value.frameloop.rate),
223
- read: summarise(value.frameloop.read),
224
- resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
225
- update: summarise(value.frameloop.update),
226
- preRender: summarise(value.frameloop.preRender),
227
- render: summarise(value.frameloop.render),
228
- postRender: summarise(value.frameloop.postRender),
229
- },
230
- animations: {
231
- mainThread: summarise(value.animations.mainThread),
232
- waapi: summarise(value.animations.waapi),
233
- layout: summarise(value.animations.layout),
234
- },
235
- layoutProjection: {
236
- nodes: summarise(value.layoutProjection.nodes),
237
- calculatedTargetDeltas: summarise(value.layoutProjection.calculatedTargetDeltas),
238
- calculatedProjections: summarise(value.layoutProjection.calculatedProjections),
239
- },
240
- };
241
- /**
242
- * Convert the rate to FPS
243
- */
244
- const { rate } = summary.frameloop;
245
- rate.min = msToFps(rate.min);
246
- rate.max = msToFps(rate.max);
247
- rate.avg = msToFps(rate.avg);
248
- [rate.min, rate.max] = [rate.max, rate.min];
249
- return summary;
250
- }
251
- function recordStats() {
252
- if (statsBuffer.value) {
253
- clearStatsBuffer();
254
- throw new Error("Stats are already being measured");
255
- }
256
- const newStatsBuffer = statsBuffer;
257
- newStatsBuffer.value = {
258
- frameloop: {
259
- rate: [],
260
- read: [],
261
- resolveKeyframes: [],
262
- update: [],
263
- preRender: [],
264
- render: [],
265
- postRender: [],
266
- },
267
- animations: {
268
- mainThread: [],
269
- waapi: [],
270
- layout: [],
271
- },
272
- layoutProjection: {
273
- nodes: [],
274
- calculatedTargetDeltas: [],
275
- calculatedProjections: [],
276
- },
277
- };
278
- newStatsBuffer.addProjectionMetrics = (metrics) => {
279
- const { layoutProjection } = newStatsBuffer.value;
280
- layoutProjection.nodes.push(metrics.nodes);
281
- layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
282
- layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
283
- };
284
- frame.postRender(record, true);
285
- return reportStats;
286
- }
287
-
288
- exports.recordStats = recordStats;
9
+ Object.defineProperty(exports, "recordStats", {
10
+ enumerable: true,
11
+ get: function () { return motionDom.recordStats; }
12
+ });
@@ -102,17 +102,11 @@ function calcNextTime(current, next, prev, labels) {
102
102
  }
103
103
  }
104
104
 
105
- function removeItem(arr, item) {
106
- const index = arr.indexOf(item);
107
- if (index > -1)
108
- arr.splice(index, 1);
109
- }
110
-
111
105
  function eraseKeyframes(sequence, startTime, endTime) {
112
106
  for (let i = 0; i < sequence.length; i++) {
113
107
  const keyframe = sequence[i];
114
108
  if (keyframe.at > startTime && keyframe.at < endTime) {
115
- removeItem(sequence, keyframe);
109
+ motionUtils.removeItem(sequence, keyframe);
116
110
  // If we remove this item we have to push the pointer back one
117
111
  i--;
118
112
  }
@@ -408,6 +402,9 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
408
402
  */
409
403
  if (Array.isArray(easing))
410
404
  keyframeOptions.easing = easing;
405
+ if (motionDom.statsBuffer.value) {
406
+ motionDom.activeAnimations.waapi++;
407
+ }
411
408
  const animation = element.animate(keyframeOptions, {
412
409
  delay,
413
410
  duration,
@@ -416,6 +413,11 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
416
413
  iterations: repeat + 1,
417
414
  direction: repeatType === "reverse" ? "alternate" : "normal",
418
415
  });
416
+ if (motionDom.statsBuffer.value) {
417
+ animation.finished.finally(() => {
418
+ motionDom.activeAnimations.waapi--;
419
+ });
420
+ }
419
421
  return animation;
420
422
  }
421
423