motion 12.6.3-alpha.0 → 12.6.3

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 (74) hide show
  1. package/dist/cjs/debug.js +12 -12
  2. package/dist/cjs/index.js +402 -352
  3. package/dist/cjs/mini.js +339 -352
  4. package/dist/cjs/react-client.js +169 -181
  5. package/dist/cjs/react-m.js +18 -22
  6. package/dist/cjs/react-mini.js +275 -336
  7. package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +2 -2
  8. package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +7 -4
  9. package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +8 -6
  10. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +10 -8
  11. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +2 -2
  12. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -2
  13. package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +11 -1
  14. package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +3 -3
  15. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
  16. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-variant.mjs +1 -2
  17. package/dist/es/framer-motion/dist/es/animation/optimized-appear/handoff.mjs +2 -4
  18. package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +4 -6
  19. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +3 -3
  20. package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-time.mjs +1 -2
  21. package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +2 -2
  22. package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +5 -10
  23. package/dist/es/framer-motion/dist/es/motion/features/animation/index.mjs +1 -2
  24. package/dist/es/framer-motion/dist/es/motion/index.mjs +2 -3
  25. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +3 -5
  26. package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +19 -27
  27. package/dist/es/framer-motion/dist/es/projection/styles/transform.mjs +1 -1
  28. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +3 -4
  29. package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +1 -2
  30. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +5 -6
  31. package/dist/es/framer-motion/dist/es/render/dom/scroll/track.mjs +1 -2
  32. package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
  33. package/dist/es/framer-motion/dist/es/render/dom/utils/filter-props.mjs +1 -1
  34. package/dist/es/framer-motion/dist/es/render/html/utils/scrape-motion-values.mjs +1 -2
  35. package/dist/es/framer-motion/dist/es/render/utils/KeyframesResolver.mjs +2 -3
  36. package/dist/es/framer-motion/dist/es/render/utils/animation-state.mjs +3 -5
  37. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  38. package/dist/es/framer-motion/dist/es/render/utils/resolve-variants.mjs +1 -1
  39. package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -2
  40. package/dist/es/framer-motion/dist/es/value/types/complex/index.mjs +2 -3
  41. package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +2 -2
  42. package/dist/es/framer-motion/dist/es/value/use-will-change/add-will-change.mjs +0 -7
  43. package/dist/es/motion/lib/react.mjs +0 -1
  44. package/dist/es/motion-dom/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
  45. package/dist/es/motion-dom/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
  46. package/dist/es/motion-dom/dist/es/animation/NativeAnimation.mjs +161 -0
  47. package/dist/es/motion-dom/dist/es/animation/generators/utils/is-generator.mjs +1 -1
  48. package/dist/es/motion-dom/dist/es/animation/keyframes/get-final.mjs +12 -0
  49. package/dist/es/motion-dom/dist/es/animation/keyframes/hydrate.mjs +26 -0
  50. package/dist/es/motion-dom/dist/es/animation/utils/get-value-transition.mjs +3 -5
  51. package/dist/es/motion-dom/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
  52. package/dist/es/motion-dom/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
  53. package/dist/es/motion-dom/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
  54. package/dist/es/motion-dom/dist/es/animation/waapi/easing/supported.mjs +15 -0
  55. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/index.mjs → motion-dom/dist/es/animation/waapi/start-waapi-animation.mjs} +8 -6
  56. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs → motion-dom/dist/es/animation/waapi/supports/partial-keyframes.mjs} +2 -2
  57. package/dist/es/motion-dom/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
  58. package/dist/es/motion-dom/dist/es/animation/waapi/utils/linear.mjs +1 -4
  59. package/dist/es/motion-dom/dist/es/animation/waapi/utils/px-values.mjs +39 -0
  60. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +1 -1
  61. package/dist/es/motion-dom/dist/es/render/dom/style.mjs +15 -0
  62. package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +2 -7
  63. package/dist/es/motion-dom/dist/es/utils/supports/flags.mjs +1 -3
  64. package/dist/es/motion-dom/dist/es/utils/supports/memo.mjs +1 -1
  65. package/dist/es/motion-dom/dist/es/value/index.mjs +1 -1
  66. package/dist/es/motion-utils/dist/es/errors.mjs +2 -4
  67. package/dist/motion.dev.js +402 -352
  68. package/dist/motion.js +1 -1
  69. package/package.json +3 -3
  70. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -116
  71. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
  72. package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +0 -13
  73. package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -85
  74. package/dist/es/motion-dom/dist/es/animation/waapi/utils/easing.mjs +0 -44
package/dist/cjs/index.js CHANGED
@@ -12,11 +12,8 @@ function removeItem(arr, item) {
12
12
  arr.splice(index, 1);
13
13
  }
14
14
 
15
- /*#__NO_SIDE_EFFECTS__*/
16
- const noop = (any) => any;
17
-
18
- let warning = noop;
19
- exports.invariant = noop;
15
+ let warning = () => { };
16
+ exports.invariant = () => { };
20
17
  if (process.env.NODE_ENV !== "production") {
21
18
  warning = (check, message) => {
22
19
  if (!check && typeof console !== "undefined") {
@@ -45,6 +42,9 @@ function memo(callback) {
45
42
  };
46
43
  }
47
44
 
45
+ /*#__NO_SIDE_EFFECTS__*/
46
+ const noop = (any) => any;
47
+
48
48
  /*
49
49
  Progress within given range
50
50
 
@@ -133,15 +133,14 @@ function warnOnce(condition, message, element) {
133
133
 
134
134
  const supportsScrollTimeline = /* @__PURE__ */ memo(() => window.ScrollTimeline !== undefined);
135
135
 
136
- class BaseGroupPlaybackControls {
136
+ class GroupAnimation {
137
137
  constructor(animations) {
138
138
  // Bound to accomodate common `return animation.stop` pattern
139
139
  this.stop = () => this.runAll("stop");
140
140
  this.animations = animations.filter(Boolean);
141
141
  }
142
142
  get finished() {
143
- // Support for new finished Promise and legacy thennable API
144
- return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
143
+ return Promise.all(this.animations.map((animation) => animation.finished));
145
144
  }
146
145
  /**
147
146
  * TODO: Filter out cancelled or stopped animations before returning
@@ -212,156 +211,122 @@ class BaseGroupPlaybackControls {
212
211
  }
213
212
  }
214
213
 
215
- /**
216
- * TODO: This is a temporary class to support the legacy
217
- * thennable API
218
- */
219
- class GroupPlaybackControls extends BaseGroupPlaybackControls {
220
- then(onResolve, onReject) {
221
- return Promise.all(this.animations).then(onResolve).catch(onReject);
214
+ class GroupAnimationWithThen extends GroupAnimation {
215
+ then(onResolve, _onReject) {
216
+ return this.finished.finally(onResolve).then(() => { });
222
217
  }
223
218
  }
224
219
 
225
- function getValueTransition$1(transition, key) {
226
- return transition
227
- ? transition[key] ||
228
- transition["default"] ||
229
- transition
230
- : undefined;
231
- }
232
-
233
- /**
234
- * Implement a practical max duration for keyframe generation
235
- * to prevent infinite loops
236
- */
237
- const maxGeneratorDuration = 20000;
238
- function calcGeneratorDuration(generator) {
239
- let duration = 0;
240
- const timeStep = 50;
241
- let state = generator.next(duration);
242
- while (!state.done && duration < maxGeneratorDuration) {
243
- duration += timeStep;
244
- state = generator.next(duration);
245
- }
246
- return duration >= maxGeneratorDuration ? Infinity : duration;
247
- }
248
-
249
- /**
250
- * Create a progress => progress easing function from a generator.
251
- */
252
- function createGeneratorEasing(options, scale = 100, createGenerator) {
253
- const generator = createGenerator({ ...options, keyframes: [0, scale] });
254
- const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
255
- return {
256
- type: "keyframes",
257
- ease: (progress) => {
258
- return generator.next(duration * progress).value / scale;
259
- },
260
- duration: millisecondsToSeconds(duration),
261
- };
262
- }
263
-
264
- function isGenerator(type) {
265
- return typeof type === "function";
266
- }
220
+ const isCSSVar = (name) => name.startsWith("--");
221
+ const style = {
222
+ set: (element, name, value) => {
223
+ isCSSVar(name)
224
+ ? element.style.setProperty(name, value)
225
+ : (element.style[name] = value);
226
+ },
227
+ get: (element, name) => {
228
+ return isCSSVar(name)
229
+ ? element.style.getPropertyValue(name)
230
+ : element.style[name];
231
+ },
232
+ };
267
233
 
268
- function attachTimeline(animation, timeline) {
269
- animation.timeline = timeline;
270
- animation.onfinish = null;
234
+ const isNotNull$1 = (value) => value !== null;
235
+ function getFinalKeyframe$1(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
236
+ const resolvedKeyframes = keyframes.filter(isNotNull$1);
237
+ const index = repeat && repeatType !== "loop" && repeat % 2 === 1
238
+ ? 0
239
+ : resolvedKeyframes.length - 1;
240
+ return !index || finalKeyframe === undefined
241
+ ? resolvedKeyframes[index]
242
+ : finalKeyframe;
271
243
  }
272
244
 
273
- class NativeAnimationControls {
274
- constructor(animation) {
275
- this.animation = animation;
276
- }
277
- get duration() {
278
- var _a, _b, _c;
279
- const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
280
- ((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
281
- 300;
282
- return millisecondsToSeconds(Number(durationInMs));
283
- }
284
- get time() {
285
- var _a;
286
- if (this.animation) {
287
- return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
288
- }
289
- return 0;
290
- }
291
- set time(newTime) {
292
- if (this.animation) {
293
- this.animation.currentTime = secondsToMilliseconds(newTime);
294
- }
295
- }
296
- get speed() {
297
- return this.animation ? this.animation.playbackRate : 1;
298
- }
299
- set speed(newSpeed) {
300
- if (this.animation) {
301
- this.animation.playbackRate = newSpeed;
302
- }
303
- }
304
- get state() {
305
- return this.animation ? this.animation.playState : "finished";
306
- }
307
- get startTime() {
308
- return this.animation ? this.animation.startTime : null;
309
- }
310
- get finished() {
311
- return this.animation ? this.animation.finished : Promise.resolve();
245
+ const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
246
+ try {
247
+ document.createElement("div").animate({ opacity: [1] });
312
248
  }
313
- play() {
314
- this.animation && this.animation.play();
249
+ catch (e) {
250
+ return false;
315
251
  }
316
- pause() {
317
- this.animation && this.animation.pause();
252
+ return true;
253
+ });
254
+
255
+ const pxValues = new Set([
256
+ // Border props
257
+ "borderWidth",
258
+ "borderTopWidth",
259
+ "borderRightWidth",
260
+ "borderBottomWidth",
261
+ "borderLeftWidth",
262
+ "borderRadius",
263
+ "radius",
264
+ "borderTopLeftRadius",
265
+ "borderTopRightRadius",
266
+ "borderBottomRightRadius",
267
+ "borderBottomLeftRadius",
268
+ // Positioning props
269
+ "width",
270
+ "maxWidth",
271
+ "height",
272
+ "maxHeight",
273
+ "top",
274
+ "right",
275
+ "bottom",
276
+ "left",
277
+ // Spacing props
278
+ "padding",
279
+ "paddingTop",
280
+ "paddingRight",
281
+ "paddingBottom",
282
+ "paddingLeft",
283
+ "margin",
284
+ "marginTop",
285
+ "marginRight",
286
+ "marginBottom",
287
+ "marginLeft",
288
+ // Misc
289
+ "backgroundPositionX",
290
+ "backgroundPositionY",
291
+ ]);
292
+
293
+ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
294
+ if (!Array.isArray(keyframes)) {
295
+ keyframes = [keyframes];
318
296
  }
319
- stop() {
320
- if (!this.animation ||
321
- this.state === "idle" ||
322
- this.state === "finished") {
323
- return;
297
+ for (let i = 0; i < keyframes.length; i++) {
298
+ if (keyframes[i] === null) {
299
+ keyframes[i] =
300
+ i === 0 && !pseudoElement
301
+ ? style.get(element, name)
302
+ : keyframes[i - 1];
324
303
  }
325
- if (this.animation.commitStyles) {
326
- this.animation.commitStyles();
304
+ if (typeof keyframes[i] === "number" && pxValues.has(name)) {
305
+ keyframes[i] = keyframes[i] + "px";
327
306
  }
328
- this.cancel();
329
- }
330
- flatten() {
331
- var _a, _b;
332
- if (!this.animation || !((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowFlatten))
333
- return;
334
- (_b = this.animation.effect) === null || _b === void 0 ? void 0 : _b.updateTiming({ easing: "linear" });
335
- }
336
- attachTimeline(timeline) {
337
- if (this.animation)
338
- attachTimeline(this.animation, timeline);
339
- return noop;
340
307
  }
341
- complete() {
342
- this.animation && this.animation.finish();
343
- }
344
- cancel() {
345
- try {
346
- this.animation && this.animation.cancel();
347
- }
348
- catch (e) { }
308
+ if (!pseudoElement && !supportsPartialKeyframes() && keyframes.length < 2) {
309
+ keyframes.unshift(style.get(element, name));
349
310
  }
311
+ return keyframes;
350
312
  }
351
313
 
314
+ const statsBuffer = {
315
+ value: null,
316
+ addProjectionMetrics: null,
317
+ };
318
+
352
319
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
353
320
 
354
321
  /**
355
322
  * Add the ability for test suites to manually set support flags
356
323
  * to better test more environments.
357
324
  */
358
- const supportsFlags = {
359
- linearEasing: undefined,
360
- };
325
+ const supportsFlags = {};
361
326
 
362
327
  function memoSupports(callback, supportsFlag) {
363
328
  const memoized = memo(callback);
364
- return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
329
+ return () => supportsFlags[supportsFlag] ?? memoized();
365
330
  }
366
331
 
367
332
  const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
@@ -382,20 +347,13 @@ resolution = 10 // as milliseconds
382
347
  let points = "";
383
348
  const numPoints = Math.max(Math.round(duration / resolution), 2);
384
349
  for (let i = 0; i < numPoints; i++) {
385
- points += easing(progress(0, numPoints - 1, i)) + ", ";
350
+ points += easing(i / (numPoints - 1)) + ", ";
386
351
  }
387
352
  return `linear(${points.substring(0, points.length - 2)})`;
388
353
  };
389
354
 
390
- function isWaapiSupportedEasing(easing) {
391
- return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
392
- !easing ||
393
- (typeof easing === "string" &&
394
- (easing in supportedWaapiEasing || supportsLinearEasing())) ||
395
- isBezierDefinition(easing) ||
396
- (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
397
- }
398
355
  const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
356
+
399
357
  const supportedWaapiEasing = {
400
358
  linear: "linear",
401
359
  ease: "ease",
@@ -407,6 +365,7 @@ const supportedWaapiEasing = {
407
365
  backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
408
366
  backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
409
367
  };
368
+
410
369
  function mapEasingToNativeEasing(easing, duration) {
411
370
  if (!easing) {
412
371
  return undefined;
@@ -426,6 +385,247 @@ function mapEasingToNativeEasing(easing, duration) {
426
385
  }
427
386
  }
428
387
 
388
+ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
389
+ const keyframeOptions = {
390
+ [valueName]: keyframes,
391
+ };
392
+ if (times)
393
+ keyframeOptions.offset = times;
394
+ const easing = mapEasingToNativeEasing(ease, duration);
395
+ /**
396
+ * If this is an easing array, apply to keyframes, not animation as a whole
397
+ */
398
+ if (Array.isArray(easing))
399
+ keyframeOptions.easing = easing;
400
+ const animation = element.animate(keyframeOptions, {
401
+ delay,
402
+ duration,
403
+ easing: !Array.isArray(easing) ? easing : "linear",
404
+ fill: "both",
405
+ iterations: repeat + 1,
406
+ direction: repeatType === "reverse" ? "alternate" : "normal",
407
+ pseudoElement,
408
+ });
409
+ return animation;
410
+ }
411
+
412
+ function isGenerator(type) {
413
+ return typeof type === "function" && "applyToOptions" in type;
414
+ }
415
+
416
+ function applyGeneratorOptions({ type, ...options }) {
417
+ if (isGenerator(type)) {
418
+ return type.applyToOptions(options);
419
+ }
420
+ else {
421
+ options.duration ?? (options.duration = 300);
422
+ options.ease ?? (options.ease = "easeOut");
423
+ }
424
+ return options;
425
+ }
426
+
427
+ const animationMaps = new WeakMap();
428
+ const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
429
+ function getAnimationMap(element) {
430
+ const map = animationMaps.get(element) || new Map();
431
+ animationMaps.set(element, map);
432
+ return map;
433
+ }
434
+ /**
435
+ * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
436
+ */
437
+ class NativeAnimation {
438
+ constructor(options) {
439
+ /**
440
+ * If we already have an animation, we don't need to instantiate one
441
+ * and can just use this as a controls interface.
442
+ */
443
+ if ("animation" in options) {
444
+ this.animation = options.animation;
445
+ return;
446
+ }
447
+ const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
448
+ let { transition } = options;
449
+ this.allowFlatten = allowFlatten;
450
+ /**
451
+ * Stop any existing animations on the element before reading existing keyframes.
452
+ *
453
+ * TODO: Check for VisualElement before using animation state. This is a fallback
454
+ * for mini animate(). Do this when implementing NativeAnimationExtended.
455
+ */
456
+ const animationMap = getAnimationMap(element);
457
+ const key = animationMapKey(name, pseudoElement || "");
458
+ const currentAnimation = animationMap.get(key);
459
+ currentAnimation && currentAnimation.stop();
460
+ /**
461
+ * TODO: If these keyframes aren't correctly hydrated then we want to throw
462
+ * run an instant animation.
463
+ */
464
+ const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
465
+ exports.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
466
+ transition = applyGeneratorOptions(transition);
467
+ this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
468
+ if (transition.autoplay === false) {
469
+ this.animation.pause();
470
+ }
471
+ this.removeAnimation = () => animationMap.delete(key);
472
+ this.animation.onfinish = () => {
473
+ if (!pseudoElement) {
474
+ style.set(element, name, getFinalKeyframe$1(keyframes, transition));
475
+ }
476
+ else {
477
+ this.commitStyles();
478
+ }
479
+ this.cancel();
480
+ };
481
+ /**
482
+ * TODO: Check for VisualElement before using animation state.
483
+ */
484
+ animationMap.set(key, this);
485
+ }
486
+ play() {
487
+ this.animation.play();
488
+ }
489
+ pause() {
490
+ this.animation.pause();
491
+ }
492
+ complete() {
493
+ this.animation.finish();
494
+ }
495
+ cancel() {
496
+ try {
497
+ this.animation.cancel();
498
+ }
499
+ catch (e) { }
500
+ this.removeAnimation();
501
+ }
502
+ stop() {
503
+ const { state } = this;
504
+ if (state === "idle" || state === "finished") {
505
+ return;
506
+ }
507
+ this.commitStyles();
508
+ this.cancel();
509
+ }
510
+ /**
511
+ * WAAPI doesn't natively have any interruption capabilities.
512
+ *
513
+ * In this method, we commit styles back to the DOM before cancelling
514
+ * the animation.
515
+ *
516
+ * This is designed to be overridden by NativeAnimationExtended, which
517
+ * will create a renderless JS animation and sample it twice to calculate
518
+ * its current value, "previous" value, and therefore allow
519
+ * Motion to also correctly calculate velocity for any subsequent animation
520
+ * while deferring the commit until the next animation frame.
521
+ */
522
+ commitStyles() {
523
+ this.animation.commitStyles?.();
524
+ }
525
+ get duration() {
526
+ console.log(this.animation.effect?.getComputedTiming());
527
+ const duration = this.animation.effect?.getComputedTiming().duration || 0;
528
+ return millisecondsToSeconds(Number(duration));
529
+ }
530
+ get time() {
531
+ return millisecondsToSeconds(Number(this.animation.currentTime) || 0);
532
+ }
533
+ set time(newTime) {
534
+ this.animation.currentTime = secondsToMilliseconds(newTime);
535
+ }
536
+ /**
537
+ * The playback speed of the animation.
538
+ * 1 = normal speed, 2 = double speed, 0.5 = half speed.
539
+ */
540
+ get speed() {
541
+ return this.animation.playbackRate;
542
+ }
543
+ set speed(newSpeed) {
544
+ this.animation.playbackRate = newSpeed;
545
+ }
546
+ get state() {
547
+ return this.animation.playState;
548
+ }
549
+ get startTime() {
550
+ return Number(this.animation.startTime);
551
+ }
552
+ get finished() {
553
+ return this.animation.finished;
554
+ }
555
+ flatten() {
556
+ if (this.allowFlatten) {
557
+ this.animation.effect?.updateTiming({ easing: "linear" });
558
+ }
559
+ }
560
+ /**
561
+ * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
562
+ */
563
+ attachTimeline(timeline) {
564
+ this.animation.timeline = timeline;
565
+ this.animation.onfinish = null;
566
+ return noop;
567
+ }
568
+ /**
569
+ * Allows the animation to be awaited.
570
+ *
571
+ * @deprecated Use `finished` instead.
572
+ */
573
+ then(onResolve, onReject) {
574
+ return this.finished.then(onResolve).catch(onReject);
575
+ }
576
+ }
577
+
578
+ function getValueTransition$1(transition, key) {
579
+ return (transition?.[key] ??
580
+ transition?.["default"] ??
581
+ transition);
582
+ }
583
+
584
+ /**
585
+ * Implement a practical max duration for keyframe generation
586
+ * to prevent infinite loops
587
+ */
588
+ const maxGeneratorDuration = 20000;
589
+ function calcGeneratorDuration(generator) {
590
+ let duration = 0;
591
+ const timeStep = 50;
592
+ let state = generator.next(duration);
593
+ while (!state.done && duration < maxGeneratorDuration) {
594
+ duration += timeStep;
595
+ state = generator.next(duration);
596
+ }
597
+ return duration >= maxGeneratorDuration ? Infinity : duration;
598
+ }
599
+
600
+ /**
601
+ * Create a progress => progress easing function from a generator.
602
+ */
603
+ function createGeneratorEasing(options, scale = 100, createGenerator) {
604
+ const generator = createGenerator({ ...options, keyframes: [0, scale] });
605
+ const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
606
+ return {
607
+ type: "keyframes",
608
+ ease: (progress) => {
609
+ return generator.next(duration * progress).value / scale;
610
+ },
611
+ duration: millisecondsToSeconds(duration),
612
+ };
613
+ }
614
+
615
+ function isWaapiSupportedEasing(easing) {
616
+ return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
617
+ !easing ||
618
+ (typeof easing === "string" &&
619
+ (easing in supportedWaapiEasing || supportsLinearEasing())) ||
620
+ isBezierDefinition(easing) ||
621
+ (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
622
+ }
623
+
624
+ function attachTimeline(animation, timeline) {
625
+ animation.timeline = timeline;
626
+ animation.onfinish = null;
627
+ }
628
+
429
629
  const stepsOrder = [
430
630
  "read", // Read
431
631
  "resolveKeyframes", // Write/Read/Write/Read
@@ -435,11 +635,6 @@ const stepsOrder = [
435
635
  "postRender", // Compute
436
636
  ];
437
637
 
438
- const statsBuffer = {
439
- value: null,
440
- addProjectionMetrics: null,
441
- };
442
-
443
638
  function createRenderStep(runNextFrame, stepName) {
444
639
  /**
445
640
  * We create and reuse two queues, one to queue jobs for the current frame
@@ -629,21 +824,16 @@ function isDragActive() {
629
824
  }
630
825
 
631
826
  function resolveElements(elementOrSelector, scope, selectorCache) {
632
- var _a;
633
827
  if (elementOrSelector instanceof EventTarget) {
634
828
  return [elementOrSelector];
635
829
  }
636
830
  else if (typeof elementOrSelector === "string") {
637
831
  let root = document;
638
832
  if (scope) {
639
- // TODO: Refactor to utils package
640
- // invariant(
641
- // Boolean(scope.current),
642
- // "Scope provided, but no element detected."
643
- // )
644
833
  root = scope.current;
645
834
  }
646
- const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
835
+ const elements = selectorCache?.[elementOrSelector] ??
836
+ root.querySelectorAll(elementOrSelector);
647
837
  return elements ? Array.from(elements) : [];
648
838
  }
649
839
  return Array.from(elementOrSelector);
@@ -842,7 +1032,7 @@ function press(targetOrSelector, onPressStart, options = {}) {
842
1032
  if (target instanceof HTMLElement) {
843
1033
  target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
844
1034
  if (!isElementKeyboardAccessible(target) &&
845
- target.tabIndex === null) {
1035
+ !target.hasAttribute("tabindex")) {
846
1036
  target.tabIndex = 0;
847
1037
  }
848
1038
  }
@@ -875,7 +1065,7 @@ class MotionValue {
875
1065
  * This will be replaced by the build step with the latest version number.
876
1066
  * When MotionValues are provided to motion components, warn if versions are mixed.
877
1067
  */
878
- this.version = "12.6.3-alpha.0";
1068
+ this.version = "12.6.3";
879
1069
  /**
880
1070
  * Tracks whether this value can output a velocity. Currently this is only true
881
1071
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1424,9 +1614,17 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
1424
1614
  const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
1425
1615
  return calculatedDuration + "ms " + easing;
1426
1616
  },
1617
+ toTransition: () => { },
1427
1618
  };
1428
1619
  return generator;
1429
1620
  }
1621
+ spring.applyToOptions = (options) => {
1622
+ const generatorOptions = createGeneratorEasing(options, 100, spring);
1623
+ options.ease = supportsLinearEasing() ? generatorOptions.ease : "easeOut";
1624
+ options.duration = secondsToMilliseconds(generatorOptions.duration);
1625
+ options.type = "keyframes";
1626
+ return options;
1627
+ };
1430
1628
 
1431
1629
  const wrap = (min, max, v) => {
1432
1630
  const rangeSize = max - min;
@@ -1510,7 +1708,6 @@ function calculateRepeatDuration(duration, repeat, _repeatDelay) {
1510
1708
  * calculate an absolute time for the next keyframes.
1511
1709
  */
1512
1710
  function calcNextTime(current, next, prev, labels) {
1513
- var _a;
1514
1711
  if (typeof next === "number") {
1515
1712
  return next;
1516
1713
  }
@@ -1521,7 +1718,7 @@ function calcNextTime(current, next, prev, labels) {
1521
1718
  return prev;
1522
1719
  }
1523
1720
  else {
1524
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
1721
+ return labels.get(next) ?? current;
1525
1722
  }
1526
1723
  }
1527
1724
 
@@ -1634,7 +1831,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
1634
1831
  const numKeyframes = valueKeyframesAsList.length;
1635
1832
  const createGenerator = isGenerator(type)
1636
1833
  ? type
1637
- : generators === null || generators === void 0 ? void 0 : generators[type];
1834
+ : generators?.[type];
1638
1835
  if (numKeyframes <= 2 && createGenerator) {
1639
1836
  /**
1640
1837
  * As we're creating an easing function from a spring,
@@ -1656,7 +1853,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
1656
1853
  ease = springEasing.ease;
1657
1854
  duration = springEasing.duration;
1658
1855
  }
1659
- duration !== null && duration !== void 0 ? duration : (duration = defaultDuration);
1856
+ duration ?? (duration = defaultDuration);
1660
1857
  const startTime = currentTime + calculatedDelay;
1661
1858
  /**
1662
1859
  * If there's only one time offset of 0, fill in a second with length 1
@@ -1865,7 +2062,7 @@ const resolveFinalValueInKeyframes = (v) => {
1865
2062
 
1866
2063
  function getValueState(visualElement) {
1867
2064
  const state = [{}, {}];
1868
- visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
2065
+ visualElement?.values.forEach((value, key) => {
1869
2066
  state[0][key] = value.get();
1870
2067
  state[1][key] = value.getVelocity();
1871
2068
  });
@@ -1938,11 +2135,6 @@ function addValueToWillChange(visualElement, key) {
1938
2135
  if (isWillChangeMotionValue(willChange)) {
1939
2136
  return willChange.add(key);
1940
2137
  }
1941
- else if (!willChange && MotionGlobalConfig.WillChange) {
1942
- const newWillChange = new MotionGlobalConfig.WillChange("auto");
1943
- visualElement.addValue("willChange", newWillChange);
1944
- newWillChange.add(key);
1945
- }
1946
2138
  }
1947
2139
 
1948
2140
  /**
@@ -2202,11 +2394,10 @@ const color = {
2202
2394
  const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
2203
2395
 
2204
2396
  function test(v) {
2205
- var _a, _b;
2206
2397
  return (isNaN(v) &&
2207
2398
  typeof v === "string" &&
2208
- (((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
2209
- (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
2399
+ (v.match(floatRegex)?.length || 0) +
2400
+ (v.match(colorRegex)?.length || 0) >
2210
2401
  0);
2211
2402
  }
2212
2403
  const NUMBER_TOKEN = "number";
@@ -2594,8 +2785,7 @@ function measureAllKeyframes() {
2594
2785
  const restore = transformsToRestore.get(element);
2595
2786
  if (restore) {
2596
2787
  restore.forEach(([key, value]) => {
2597
- var _a;
2598
- (_a = element.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(value);
2788
+ element.getValue(key)?.set(value);
2599
2789
  });
2600
2790
  }
2601
2791
  });
@@ -2682,7 +2872,7 @@ class KeyframeResolver {
2682
2872
  * If the first keyframe is null, we need to find its value by sampling the element
2683
2873
  */
2684
2874
  if (i === 0) {
2685
- const currentValue = motionValue === null || motionValue === void 0 ? void 0 : motionValue.get();
2875
+ const currentValue = motionValue?.get();
2686
2876
  const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
2687
2877
  if (currentValue !== undefined) {
2688
2878
  unresolvedKeyframes[0] = currentValue;
@@ -2763,7 +2953,7 @@ function parseCSSVariable(current) {
2763
2953
  if (!match)
2764
2954
  return [,];
2765
2955
  const [, token1, token2, fallback] = match;
2766
- return [`--${token1 !== null && token1 !== void 0 ? token1 : token2}`, fallback];
2956
+ return [`--${token1 ?? token2}`, fallback];
2767
2957
  }
2768
2958
  const maxDepth = 4;
2769
2959
  function getVariableValue(current, element, depth = 1) {
@@ -2902,7 +3092,6 @@ class DOMKeyframesResolver extends KeyframeResolver {
2902
3092
  }
2903
3093
  }
2904
3094
  measureEndState() {
2905
- var _a;
2906
3095
  const { element, name, unresolvedKeyframes } = this;
2907
3096
  if (!element || !element.current)
2908
3097
  return;
@@ -2915,7 +3104,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
2915
3104
  this.finalKeyframe = finalKeyframe;
2916
3105
  }
2917
3106
  // If we removed transform values, reapply them before the next render
2918
- if ((_a = this.removedTransforms) === null || _a === void 0 ? void 0 : _a.length) {
3107
+ if (this.removedTransforms?.length) {
2919
3108
  this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
2920
3109
  element
2921
3110
  .getValue(unsetTransformName)
@@ -3271,13 +3460,12 @@ function mixObject(a, b) {
3271
3460
  };
3272
3461
  }
3273
3462
  function matchOrder(origin, target) {
3274
- var _a;
3275
3463
  const orderedOrigin = [];
3276
3464
  const pointers = { color: 0, var: 0, number: 0 };
3277
3465
  for (let i = 0; i < target.values.length; i++) {
3278
3466
  const type = target.types[i];
3279
3467
  const originIndex = origin.indexes[type][pointers[type]];
3280
- const originValue = (_a = origin.values[originIndex]) !== null && _a !== void 0 ? _a : 0;
3468
+ const originValue = origin.values[originIndex] ?? 0;
3281
3469
  orderedOrigin[i] = originValue;
3282
3470
  pointers[type]++;
3283
3471
  }
@@ -3504,7 +3692,7 @@ function convertOffsetToTimes(offset, duration) {
3504
3692
  return offset.map((o) => o * duration);
3505
3693
  }
3506
3694
 
3507
- function defaultEasing$1(values, easing) {
3695
+ function defaultEasing(values, easing) {
3508
3696
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
3509
3697
  }
3510
3698
  function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
@@ -3535,7 +3723,7 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
3535
3723
  const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
3536
3724
  ease: Array.isArray(easingFunctions)
3537
3725
  ? easingFunctions
3538
- : defaultEasing$1(keyframeValues, easingFunctions),
3726
+ : defaultEasing(keyframeValues, easingFunctions),
3539
3727
  });
3540
3728
  return {
3541
3729
  calculatedDuration: duration,
@@ -3617,7 +3805,7 @@ class MainThreadAnimation extends BaseAnimation {
3617
3805
  onStop && onStop();
3618
3806
  };
3619
3807
  const { name, motionValue, element, keyframes } = this.options;
3620
- const KeyframeResolver$1 = (element === null || element === void 0 ? void 0 : element.KeyframeResolver) || KeyframeResolver;
3808
+ const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
3621
3809
  const onResolved = (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe);
3622
3810
  this.resolver = new KeyframeResolver$1(keyframes, onResolved, name, motionValue, element);
3623
3811
  this.resolver.scheduleResolve();
@@ -3866,7 +4054,7 @@ class MainThreadAnimation extends BaseAnimation {
3866
4054
  this.startTime = now - this.holdTime;
3867
4055
  }
3868
4056
  else if (!this.startTime) {
3869
- this.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4057
+ this.startTime = startTime ?? this.calcStartTime();
3870
4058
  }
3871
4059
  else if (this.state === "finished") {
3872
4060
  this.startTime = now;
@@ -3884,13 +4072,12 @@ class MainThreadAnimation extends BaseAnimation {
3884
4072
  this.driver.start();
3885
4073
  }
3886
4074
  pause() {
3887
- var _a;
3888
4075
  if (!this._resolved) {
3889
4076
  this.pendingPlayState = "paused";
3890
4077
  return;
3891
4078
  }
3892
4079
  this.state = "paused";
3893
- this.holdTime = (_a = this.currentTime) !== null && _a !== void 0 ? _a : 0;
4080
+ this.holdTime = this.currentTime ?? 0;
3894
4081
  }
3895
4082
  complete() {
3896
4083
  if (this.state !== "running") {
@@ -3930,6 +4117,9 @@ class MainThreadAnimation extends BaseAnimation {
3930
4117
  this.startTime = 0;
3931
4118
  return this.tick(time, true);
3932
4119
  }
4120
+ get finished() {
4121
+ return this.currentFinishedPromise;
4122
+ }
3933
4123
  }
3934
4124
 
3935
4125
  /**
@@ -3945,27 +4135,6 @@ const acceleratedValues = new Set([
3945
4135
  // "background-color"
3946
4136
  ]);
3947
4137
 
3948
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
3949
- const keyframeOptions = { [valueName]: keyframes };
3950
- if (times)
3951
- keyframeOptions.offset = times;
3952
- const easing = mapEasingToNativeEasing(ease, duration);
3953
- /**
3954
- * If this is an easing array, apply to keyframes, not animation as a whole
3955
- */
3956
- if (Array.isArray(easing))
3957
- keyframeOptions.easing = easing;
3958
- const animation = element.animate(keyframeOptions, {
3959
- delay,
3960
- duration,
3961
- easing: !Array.isArray(easing) ? easing : "linear",
3962
- fill: "both",
3963
- iterations: repeat + 1,
3964
- direction: repeatType === "reverse" ? "alternate" : "normal",
3965
- });
3966
- return animation;
3967
- }
3968
-
3969
4138
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
3970
4139
 
3971
4140
  /**
@@ -4076,7 +4245,7 @@ class AcceleratedAnimation extends BaseAnimation {
4076
4245
  const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
4077
4246
  // Override the browser calculated startTime with one synchronised to other JS
4078
4247
  // and WAAPI animations starting this event loop.
4079
- animation.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4248
+ animation.startTime = startTime ?? this.calcStartTime();
4080
4249
  if (this.pendingTimeline) {
4081
4250
  attachTimeline(animation, this.pendingTimeline);
4082
4251
  this.pendingTimeline = undefined;
@@ -4135,6 +4304,9 @@ class AcceleratedAnimation extends BaseAnimation {
4135
4304
  const { animation } = resolved;
4136
4305
  return animation.playbackRate;
4137
4306
  }
4307
+ get finished() {
4308
+ return this.resolved.animation.finished;
4309
+ }
4138
4310
  set speed(newSpeed) {
4139
4311
  const { resolved } = this;
4140
4312
  if (!resolved)
@@ -4400,7 +4572,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
4400
4572
  });
4401
4573
  // We still want to return some animation controls here rather
4402
4574
  // than returning undefined
4403
- return new GroupPlaybackControls([]);
4575
+ return new GroupAnimationWithThen([]);
4404
4576
  }
4405
4577
  }
4406
4578
  /**
@@ -4428,7 +4600,6 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
4428
4600
  return shouldBlock;
4429
4601
  }
4430
4602
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
4431
- var _a;
4432
4603
  let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
4433
4604
  if (transitionOverride)
4434
4605
  transition = transitionOverride;
@@ -4437,7 +4608,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
4437
4608
  visualElement.animationState &&
4438
4609
  visualElement.animationState.getState()[type];
4439
4610
  for (const key in target) {
4440
- const value = visualElement.getValue(key, (_a = visualElement.latestValues[key]) !== null && _a !== void 0 ? _a : null);
4611
+ const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
4441
4612
  const valueTarget = target[key];
4442
4613
  if (valueTarget === undefined ||
4443
4614
  (animationTypeState &&
@@ -4596,7 +4767,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4596
4767
  * and warn against mismatches.
4597
4768
  */
4598
4769
  if (process.env.NODE_ENV === "development") {
4599
- warnOnce(nextValue.version === "12.6.3-alpha.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.3-alpha.0 may not work as expected.`);
4770
+ warnOnce(nextValue.version === "12.6.3", `Attempting to mix Motion versions ${nextValue.version} with 12.6.3 may not work as expected.`);
4600
4771
  }
4601
4772
  }
4602
4773
  else if (isMotionValue(prevValue)) {
@@ -5020,10 +5191,10 @@ class VisualElement {
5020
5191
  * directly from the instance (which might have performance implications).
5021
5192
  */
5022
5193
  readValue(key, target) {
5023
- var _a;
5024
5194
  let value = this.latestValues[key] !== undefined || !this.current
5025
5195
  ? this.latestValues[key]
5026
- : (_a = this.getBaseTargetFromProps(this.props, key)) !== null && _a !== void 0 ? _a : this.readValueFromInstance(this.current, key, this.options);
5196
+ : this.getBaseTargetFromProps(this.props, key) ??
5197
+ this.readValueFromInstance(this.current, key, this.options);
5027
5198
  if (value !== undefined && value !== null) {
5028
5199
  if (typeof value === "string" &&
5029
5200
  (isNumericalString(value) || isZeroValueString(value))) {
@@ -5049,11 +5220,10 @@ class VisualElement {
5049
5220
  * props.
5050
5221
  */
5051
5222
  getBaseTarget(key) {
5052
- var _a;
5053
5223
  const { initial } = this.props;
5054
5224
  let valueFromInitial;
5055
5225
  if (typeof initial === "string" || typeof initial === "object") {
5056
- const variant = resolveVariantFromProps(this.props, initial, (_a = this.presenceContext) === null || _a === void 0 ? void 0 : _a.custom);
5226
+ const variant = resolveVariantFromProps(this.props, initial, this.presenceContext?.custom);
5057
5227
  if (variant) {
5058
5228
  valueFromInitial = variant[key];
5059
5229
  }
@@ -5420,7 +5590,6 @@ function isForcedMotionValue(key, { layout, layoutId }) {
5420
5590
  }
5421
5591
 
5422
5592
  function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5423
- var _a;
5424
5593
  const { style } = props;
5425
5594
  const newValues = {};
5426
5595
  for (const key in style) {
@@ -5428,7 +5597,7 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5428
5597
  (prevProps.style &&
5429
5598
  isMotionValue(prevProps.style[key])) ||
5430
5599
  isForcedMotionValue(key, props) ||
5431
- ((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
5600
+ visualElement?.getValue(key)?.liveStyle !== undefined) {
5432
5601
  newValues[key] = style[key];
5433
5602
  }
5434
5603
  }
@@ -5707,7 +5876,7 @@ function createScopedAnimate(scope) {
5707
5876
  else {
5708
5877
  animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
5709
5878
  }
5710
- const animation = new GroupPlaybackControls(animations);
5879
+ const animation = new GroupAnimationWithThen(animations);
5711
5880
  if (scope) {
5712
5881
  scope.animations.push(animation);
5713
5882
  }
@@ -5717,125 +5886,6 @@ function createScopedAnimate(scope) {
5717
5886
  }
5718
5887
  const animate = createScopedAnimate();
5719
5888
 
5720
- function setCSSVar(element, name, value) {
5721
- element.style.setProperty(name, value);
5722
- }
5723
- function setStyle(element, name, value) {
5724
- element.style[name] = value;
5725
- }
5726
-
5727
- const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
5728
- try {
5729
- document.createElement("div").animate({ opacity: [1] });
5730
- }
5731
- catch (e) {
5732
- return false;
5733
- }
5734
- return true;
5735
- });
5736
-
5737
- const state = new WeakMap();
5738
- function hydrateKeyframes(valueName, keyframes, read) {
5739
- for (let i = 0; i < keyframes.length; i++) {
5740
- if (keyframes[i] === null) {
5741
- keyframes[i] = i === 0 ? read() : keyframes[i - 1];
5742
- }
5743
- if (typeof keyframes[i] === "number" &&
5744
- browserNumberValueTypes[valueName]) {
5745
- keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
5746
- }
5747
- }
5748
- if (!supportsPartialKeyframes() && keyframes.length < 2) {
5749
- keyframes.unshift(read());
5750
- }
5751
- }
5752
- const defaultEasing = "easeOut";
5753
- function getElementAnimationState(element) {
5754
- const animationState = state.get(element) || new Map();
5755
- state.set(element, animationState);
5756
- return state.get(element);
5757
- }
5758
- class NativeAnimation extends NativeAnimationControls {
5759
- constructor(element, valueName, valueKeyframes, options) {
5760
- const isCSSVar = valueName.startsWith("--");
5761
- exports.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
5762
- const existingAnimation = getElementAnimationState(element).get(valueName);
5763
- existingAnimation && existingAnimation.stop();
5764
- const readInitialKeyframe = () => {
5765
- return valueName.startsWith("--")
5766
- ? element.style.getPropertyValue(valueName)
5767
- : window.getComputedStyle(element)[valueName];
5768
- };
5769
- if (!Array.isArray(valueKeyframes)) {
5770
- valueKeyframes = [valueKeyframes];
5771
- }
5772
- hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
5773
- // TODO: Replace this with toString()?
5774
- if (isGenerator(options.type)) {
5775
- const generatorOptions = createGeneratorEasing(options, 100, options.type);
5776
- options.ease = supportsLinearEasing()
5777
- ? generatorOptions.ease
5778
- : defaultEasing;
5779
- options.duration = secondsToMilliseconds(generatorOptions.duration);
5780
- options.type = "keyframes";
5781
- }
5782
- else {
5783
- options.ease = options.ease || defaultEasing;
5784
- }
5785
- const onFinish = () => {
5786
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
5787
- this.cancel();
5788
- this.resolveFinishedPromise();
5789
- };
5790
- const init = () => {
5791
- this.setValue = isCSSVar ? setCSSVar : setStyle;
5792
- this.options = options;
5793
- this.updateFinishedPromise();
5794
- this.removeAnimation = () => {
5795
- const elementState = state.get(element);
5796
- elementState && elementState.delete(valueName);
5797
- };
5798
- };
5799
- if (!supportsWaapi()) {
5800
- super();
5801
- init();
5802
- onFinish();
5803
- }
5804
- else {
5805
- super(startWaapiAnimation(element, valueName, valueKeyframes, options));
5806
- init();
5807
- if (options.autoplay === false) {
5808
- this.animation.pause();
5809
- }
5810
- this.animation.onfinish = onFinish;
5811
- getElementAnimationState(element).set(valueName, this);
5812
- }
5813
- }
5814
- /**
5815
- * Allows the returned animation to be awaited or promise-chained. Currently
5816
- * resolves when the animation finishes at all but in a future update could/should
5817
- * reject if its cancels.
5818
- */
5819
- then(resolve, reject) {
5820
- return this.currentFinishedPromise.then(resolve, reject);
5821
- }
5822
- updateFinishedPromise() {
5823
- this.currentFinishedPromise = new Promise((resolve) => {
5824
- this.resolveFinishedPromise = resolve;
5825
- });
5826
- }
5827
- play() {
5828
- if (this.state === "finished") {
5829
- this.updateFinishedPromise();
5830
- }
5831
- super.play();
5832
- }
5833
- cancel() {
5834
- this.removeAnimation();
5835
- super.cancel();
5836
- }
5837
- }
5838
-
5839
5889
  function animateElements(elementOrSelector, keyframes, options, scope) {
5840
5890
  const elements = resolveElements(elementOrSelector, scope);
5841
5891
  const numElements = elements.length;
@@ -5855,13 +5905,15 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
5855
5905
  const valueOptions = {
5856
5906
  ...getValueTransition$1(elementTransition, valueName),
5857
5907
  };
5858
- valueOptions.duration = valueOptions.duration
5859
- ? secondsToMilliseconds(valueOptions.duration)
5860
- : valueOptions.duration;
5861
- valueOptions.delay = secondsToMilliseconds(valueOptions.delay || 0);
5862
- valueOptions.allowFlatten =
5863
- !elementTransition.type && !elementTransition.ease;
5864
- animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
5908
+ valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));
5909
+ valueOptions.delay && (valueOptions.delay = secondsToMilliseconds(valueOptions.delay));
5910
+ animations.push(new NativeAnimation({
5911
+ element,
5912
+ name: valueName,
5913
+ keyframes: valueKeyframes,
5914
+ transition: valueOptions,
5915
+ allowFlatten: !elementTransition.type && !elementTransition.ease,
5916
+ }));
5865
5917
  }
5866
5918
  }
5867
5919
  return animations;
@@ -5869,7 +5921,7 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
5869
5921
 
5870
5922
  const createScopedWaapiAnimate = (scope) => {
5871
5923
  function scopedAnimate(elementOrSelector, keyframes, options) {
5872
- return new GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
5924
+ return new GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
5873
5925
  }
5874
5926
  return scopedAnimate;
5875
5927
  };
@@ -5908,8 +5960,7 @@ function getElementSize(target, borderBoxSize) {
5908
5960
  }
5909
5961
  }
5910
5962
  function notifyTarget({ target, contentRect, borderBoxSize, }) {
5911
- var _a;
5912
- (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
5963
+ resizeHandlers.get(target)?.forEach((handler) => {
5913
5964
  handler({
5914
5965
  target,
5915
5966
  contentSize: contentRect,
@@ -5938,14 +5989,14 @@ function resizeElement(target, handler) {
5938
5989
  resizeHandlers.set(element, elementHandlers);
5939
5990
  }
5940
5991
  elementHandlers.add(handler);
5941
- observer === null || observer === void 0 ? void 0 : observer.observe(element);
5992
+ observer?.observe(element);
5942
5993
  });
5943
5994
  return () => {
5944
5995
  elements.forEach((element) => {
5945
5996
  const elementHandlers = resizeHandlers.get(element);
5946
- elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
5947
- if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
5948
- observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
5997
+ elementHandlers?.delete(handler);
5998
+ if (!elementHandlers?.size) {
5999
+ observer?.unobserve(element);
5949
6000
  }
5950
6001
  });
5951
6002
  };
@@ -6324,7 +6375,6 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
6324
6375
  const listener = scrollListeners.get(container);
6325
6376
  frame.read(listener, false, true);
6326
6377
  return () => {
6327
- var _a;
6328
6378
  cancelFrame(listener);
6329
6379
  /**
6330
6380
  * Check if we even have any handlers for this container.
@@ -6342,7 +6392,7 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
6342
6392
  scrollListeners.delete(container);
6343
6393
  if (scrollListener) {
6344
6394
  getEventTarget(container).removeEventListener("scroll", scrollListener);
6345
- (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
6395
+ resizeListeners.get(container)?.();
6346
6396
  window.removeEventListener("resize", scrollListener);
6347
6397
  }
6348
6398
  };