motion 12.6.2 → 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 (72) hide show
  1. package/dist/cjs/debug.js +12 -12
  2. package/dist/cjs/index.js +402 -347
  3. package/dist/cjs/mini.js +339 -352
  4. package/dist/cjs/react-client.js +169 -176
  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/motion-dom/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
  43. package/dist/es/motion-dom/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
  44. package/dist/es/motion-dom/dist/es/animation/NativeAnimation.mjs +161 -0
  45. package/dist/es/motion-dom/dist/es/animation/generators/utils/is-generator.mjs +1 -1
  46. package/dist/es/motion-dom/dist/es/animation/keyframes/get-final.mjs +12 -0
  47. package/dist/es/motion-dom/dist/es/animation/keyframes/hydrate.mjs +26 -0
  48. package/dist/es/motion-dom/dist/es/animation/utils/get-value-transition.mjs +3 -5
  49. package/dist/es/motion-dom/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
  50. package/dist/es/motion-dom/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
  51. package/dist/es/motion-dom/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
  52. package/dist/es/motion-dom/dist/es/animation/waapi/easing/supported.mjs +15 -0
  53. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/index.mjs → motion-dom/dist/es/animation/waapi/start-waapi-animation.mjs} +8 -6
  54. 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
  55. package/dist/es/motion-dom/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
  56. package/dist/es/motion-dom/dist/es/animation/waapi/utils/linear.mjs +1 -4
  57. package/dist/es/motion-dom/dist/es/animation/waapi/utils/px-values.mjs +39 -0
  58. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +1 -1
  59. package/dist/es/motion-dom/dist/es/render/dom/style.mjs +15 -0
  60. package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +2 -7
  61. package/dist/es/motion-dom/dist/es/utils/supports/flags.mjs +1 -3
  62. package/dist/es/motion-dom/dist/es/utils/supports/memo.mjs +1 -1
  63. package/dist/es/motion-dom/dist/es/value/index.mjs +1 -1
  64. package/dist/es/motion-utils/dist/es/errors.mjs +2 -4
  65. package/dist/motion.dev.js +402 -347
  66. package/dist/motion.js +1 -1
  67. package/package.json +3 -3
  68. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -116
  69. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
  70. package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +0 -13
  71. package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -85
  72. 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.1";
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
  });
@@ -2197,11 +2394,10 @@ const color = {
2197
2394
  const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
2198
2395
 
2199
2396
  function test(v) {
2200
- var _a, _b;
2201
2397
  return (isNaN(v) &&
2202
2398
  typeof v === "string" &&
2203
- (((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
2204
- (((_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) >
2205
2401
  0);
2206
2402
  }
2207
2403
  const NUMBER_TOKEN = "number";
@@ -2589,8 +2785,7 @@ function measureAllKeyframes() {
2589
2785
  const restore = transformsToRestore.get(element);
2590
2786
  if (restore) {
2591
2787
  restore.forEach(([key, value]) => {
2592
- var _a;
2593
- (_a = element.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(value);
2788
+ element.getValue(key)?.set(value);
2594
2789
  });
2595
2790
  }
2596
2791
  });
@@ -2677,7 +2872,7 @@ class KeyframeResolver {
2677
2872
  * If the first keyframe is null, we need to find its value by sampling the element
2678
2873
  */
2679
2874
  if (i === 0) {
2680
- const currentValue = motionValue === null || motionValue === void 0 ? void 0 : motionValue.get();
2875
+ const currentValue = motionValue?.get();
2681
2876
  const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
2682
2877
  if (currentValue !== undefined) {
2683
2878
  unresolvedKeyframes[0] = currentValue;
@@ -2758,7 +2953,7 @@ function parseCSSVariable(current) {
2758
2953
  if (!match)
2759
2954
  return [,];
2760
2955
  const [, token1, token2, fallback] = match;
2761
- return [`--${token1 !== null && token1 !== void 0 ? token1 : token2}`, fallback];
2956
+ return [`--${token1 ?? token2}`, fallback];
2762
2957
  }
2763
2958
  const maxDepth = 4;
2764
2959
  function getVariableValue(current, element, depth = 1) {
@@ -2897,7 +3092,6 @@ class DOMKeyframesResolver extends KeyframeResolver {
2897
3092
  }
2898
3093
  }
2899
3094
  measureEndState() {
2900
- var _a;
2901
3095
  const { element, name, unresolvedKeyframes } = this;
2902
3096
  if (!element || !element.current)
2903
3097
  return;
@@ -2910,7 +3104,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
2910
3104
  this.finalKeyframe = finalKeyframe;
2911
3105
  }
2912
3106
  // If we removed transform values, reapply them before the next render
2913
- if ((_a = this.removedTransforms) === null || _a === void 0 ? void 0 : _a.length) {
3107
+ if (this.removedTransforms?.length) {
2914
3108
  this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
2915
3109
  element
2916
3110
  .getValue(unsetTransformName)
@@ -3266,13 +3460,12 @@ function mixObject(a, b) {
3266
3460
  };
3267
3461
  }
3268
3462
  function matchOrder(origin, target) {
3269
- var _a;
3270
3463
  const orderedOrigin = [];
3271
3464
  const pointers = { color: 0, var: 0, number: 0 };
3272
3465
  for (let i = 0; i < target.values.length; i++) {
3273
3466
  const type = target.types[i];
3274
3467
  const originIndex = origin.indexes[type][pointers[type]];
3275
- const originValue = (_a = origin.values[originIndex]) !== null && _a !== void 0 ? _a : 0;
3468
+ const originValue = origin.values[originIndex] ?? 0;
3276
3469
  orderedOrigin[i] = originValue;
3277
3470
  pointers[type]++;
3278
3471
  }
@@ -3499,7 +3692,7 @@ function convertOffsetToTimes(offset, duration) {
3499
3692
  return offset.map((o) => o * duration);
3500
3693
  }
3501
3694
 
3502
- function defaultEasing$1(values, easing) {
3695
+ function defaultEasing(values, easing) {
3503
3696
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
3504
3697
  }
3505
3698
  function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
@@ -3530,7 +3723,7 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
3530
3723
  const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
3531
3724
  ease: Array.isArray(easingFunctions)
3532
3725
  ? easingFunctions
3533
- : defaultEasing$1(keyframeValues, easingFunctions),
3726
+ : defaultEasing(keyframeValues, easingFunctions),
3534
3727
  });
3535
3728
  return {
3536
3729
  calculatedDuration: duration,
@@ -3612,7 +3805,7 @@ class MainThreadAnimation extends BaseAnimation {
3612
3805
  onStop && onStop();
3613
3806
  };
3614
3807
  const { name, motionValue, element, keyframes } = this.options;
3615
- const KeyframeResolver$1 = (element === null || element === void 0 ? void 0 : element.KeyframeResolver) || KeyframeResolver;
3808
+ const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
3616
3809
  const onResolved = (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe);
3617
3810
  this.resolver = new KeyframeResolver$1(keyframes, onResolved, name, motionValue, element);
3618
3811
  this.resolver.scheduleResolve();
@@ -3861,7 +4054,7 @@ class MainThreadAnimation extends BaseAnimation {
3861
4054
  this.startTime = now - this.holdTime;
3862
4055
  }
3863
4056
  else if (!this.startTime) {
3864
- this.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4057
+ this.startTime = startTime ?? this.calcStartTime();
3865
4058
  }
3866
4059
  else if (this.state === "finished") {
3867
4060
  this.startTime = now;
@@ -3879,13 +4072,12 @@ class MainThreadAnimation extends BaseAnimation {
3879
4072
  this.driver.start();
3880
4073
  }
3881
4074
  pause() {
3882
- var _a;
3883
4075
  if (!this._resolved) {
3884
4076
  this.pendingPlayState = "paused";
3885
4077
  return;
3886
4078
  }
3887
4079
  this.state = "paused";
3888
- this.holdTime = (_a = this.currentTime) !== null && _a !== void 0 ? _a : 0;
4080
+ this.holdTime = this.currentTime ?? 0;
3889
4081
  }
3890
4082
  complete() {
3891
4083
  if (this.state !== "running") {
@@ -3925,6 +4117,9 @@ class MainThreadAnimation extends BaseAnimation {
3925
4117
  this.startTime = 0;
3926
4118
  return this.tick(time, true);
3927
4119
  }
4120
+ get finished() {
4121
+ return this.currentFinishedPromise;
4122
+ }
3928
4123
  }
3929
4124
 
3930
4125
  /**
@@ -3940,27 +4135,6 @@ const acceleratedValues = new Set([
3940
4135
  // "background-color"
3941
4136
  ]);
3942
4137
 
3943
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
3944
- const keyframeOptions = { [valueName]: keyframes };
3945
- if (times)
3946
- keyframeOptions.offset = times;
3947
- const easing = mapEasingToNativeEasing(ease, duration);
3948
- /**
3949
- * If this is an easing array, apply to keyframes, not animation as a whole
3950
- */
3951
- if (Array.isArray(easing))
3952
- keyframeOptions.easing = easing;
3953
- const animation = element.animate(keyframeOptions, {
3954
- delay,
3955
- duration,
3956
- easing: !Array.isArray(easing) ? easing : "linear",
3957
- fill: "both",
3958
- iterations: repeat + 1,
3959
- direction: repeatType === "reverse" ? "alternate" : "normal",
3960
- });
3961
- return animation;
3962
- }
3963
-
3964
4138
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
3965
4139
 
3966
4140
  /**
@@ -4071,7 +4245,7 @@ class AcceleratedAnimation extends BaseAnimation {
4071
4245
  const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
4072
4246
  // Override the browser calculated startTime with one synchronised to other JS
4073
4247
  // and WAAPI animations starting this event loop.
4074
- animation.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4248
+ animation.startTime = startTime ?? this.calcStartTime();
4075
4249
  if (this.pendingTimeline) {
4076
4250
  attachTimeline(animation, this.pendingTimeline);
4077
4251
  this.pendingTimeline = undefined;
@@ -4130,6 +4304,9 @@ class AcceleratedAnimation extends BaseAnimation {
4130
4304
  const { animation } = resolved;
4131
4305
  return animation.playbackRate;
4132
4306
  }
4307
+ get finished() {
4308
+ return this.resolved.animation.finished;
4309
+ }
4133
4310
  set speed(newSpeed) {
4134
4311
  const { resolved } = this;
4135
4312
  if (!resolved)
@@ -4395,7 +4572,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
4395
4572
  });
4396
4573
  // We still want to return some animation controls here rather
4397
4574
  // than returning undefined
4398
- return new GroupPlaybackControls([]);
4575
+ return new GroupAnimationWithThen([]);
4399
4576
  }
4400
4577
  }
4401
4578
  /**
@@ -4423,7 +4600,6 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
4423
4600
  return shouldBlock;
4424
4601
  }
4425
4602
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
4426
- var _a;
4427
4603
  let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
4428
4604
  if (transitionOverride)
4429
4605
  transition = transitionOverride;
@@ -4432,7 +4608,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
4432
4608
  visualElement.animationState &&
4433
4609
  visualElement.animationState.getState()[type];
4434
4610
  for (const key in target) {
4435
- 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);
4436
4612
  const valueTarget = target[key];
4437
4613
  if (valueTarget === undefined ||
4438
4614
  (animationTypeState &&
@@ -4591,7 +4767,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4591
4767
  * and warn against mismatches.
4592
4768
  */
4593
4769
  if (process.env.NODE_ENV === "development") {
4594
- warnOnce(nextValue.version === "12.6.2", `Attempting to mix Motion versions ${nextValue.version} with 12.6.2 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.`);
4595
4771
  }
4596
4772
  }
4597
4773
  else if (isMotionValue(prevValue)) {
@@ -5015,10 +5191,10 @@ class VisualElement {
5015
5191
  * directly from the instance (which might have performance implications).
5016
5192
  */
5017
5193
  readValue(key, target) {
5018
- var _a;
5019
5194
  let value = this.latestValues[key] !== undefined || !this.current
5020
5195
  ? this.latestValues[key]
5021
- : (_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);
5022
5198
  if (value !== undefined && value !== null) {
5023
5199
  if (typeof value === "string" &&
5024
5200
  (isNumericalString(value) || isZeroValueString(value))) {
@@ -5044,11 +5220,10 @@ class VisualElement {
5044
5220
  * props.
5045
5221
  */
5046
5222
  getBaseTarget(key) {
5047
- var _a;
5048
5223
  const { initial } = this.props;
5049
5224
  let valueFromInitial;
5050
5225
  if (typeof initial === "string" || typeof initial === "object") {
5051
- 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);
5052
5227
  if (variant) {
5053
5228
  valueFromInitial = variant[key];
5054
5229
  }
@@ -5415,7 +5590,6 @@ function isForcedMotionValue(key, { layout, layoutId }) {
5415
5590
  }
5416
5591
 
5417
5592
  function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5418
- var _a;
5419
5593
  const { style } = props;
5420
5594
  const newValues = {};
5421
5595
  for (const key in style) {
@@ -5423,7 +5597,7 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5423
5597
  (prevProps.style &&
5424
5598
  isMotionValue(prevProps.style[key])) ||
5425
5599
  isForcedMotionValue(key, props) ||
5426
- ((_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) {
5427
5601
  newValues[key] = style[key];
5428
5602
  }
5429
5603
  }
@@ -5702,7 +5876,7 @@ function createScopedAnimate(scope) {
5702
5876
  else {
5703
5877
  animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
5704
5878
  }
5705
- const animation = new GroupPlaybackControls(animations);
5879
+ const animation = new GroupAnimationWithThen(animations);
5706
5880
  if (scope) {
5707
5881
  scope.animations.push(animation);
5708
5882
  }
@@ -5712,125 +5886,6 @@ function createScopedAnimate(scope) {
5712
5886
  }
5713
5887
  const animate = createScopedAnimate();
5714
5888
 
5715
- function setCSSVar(element, name, value) {
5716
- element.style.setProperty(name, value);
5717
- }
5718
- function setStyle(element, name, value) {
5719
- element.style[name] = value;
5720
- }
5721
-
5722
- const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
5723
- try {
5724
- document.createElement("div").animate({ opacity: [1] });
5725
- }
5726
- catch (e) {
5727
- return false;
5728
- }
5729
- return true;
5730
- });
5731
-
5732
- const state = new WeakMap();
5733
- function hydrateKeyframes(valueName, keyframes, read) {
5734
- for (let i = 0; i < keyframes.length; i++) {
5735
- if (keyframes[i] === null) {
5736
- keyframes[i] = i === 0 ? read() : keyframes[i - 1];
5737
- }
5738
- if (typeof keyframes[i] === "number" &&
5739
- browserNumberValueTypes[valueName]) {
5740
- keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
5741
- }
5742
- }
5743
- if (!supportsPartialKeyframes() && keyframes.length < 2) {
5744
- keyframes.unshift(read());
5745
- }
5746
- }
5747
- const defaultEasing = "easeOut";
5748
- function getElementAnimationState(element) {
5749
- const animationState = state.get(element) || new Map();
5750
- state.set(element, animationState);
5751
- return state.get(element);
5752
- }
5753
- class NativeAnimation extends NativeAnimationControls {
5754
- constructor(element, valueName, valueKeyframes, options) {
5755
- const isCSSVar = valueName.startsWith("--");
5756
- exports.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
5757
- const existingAnimation = getElementAnimationState(element).get(valueName);
5758
- existingAnimation && existingAnimation.stop();
5759
- const readInitialKeyframe = () => {
5760
- return valueName.startsWith("--")
5761
- ? element.style.getPropertyValue(valueName)
5762
- : window.getComputedStyle(element)[valueName];
5763
- };
5764
- if (!Array.isArray(valueKeyframes)) {
5765
- valueKeyframes = [valueKeyframes];
5766
- }
5767
- hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
5768
- // TODO: Replace this with toString()?
5769
- if (isGenerator(options.type)) {
5770
- const generatorOptions = createGeneratorEasing(options, 100, options.type);
5771
- options.ease = supportsLinearEasing()
5772
- ? generatorOptions.ease
5773
- : defaultEasing;
5774
- options.duration = secondsToMilliseconds(generatorOptions.duration);
5775
- options.type = "keyframes";
5776
- }
5777
- else {
5778
- options.ease = options.ease || defaultEasing;
5779
- }
5780
- const onFinish = () => {
5781
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
5782
- this.cancel();
5783
- this.resolveFinishedPromise();
5784
- };
5785
- const init = () => {
5786
- this.setValue = isCSSVar ? setCSSVar : setStyle;
5787
- this.options = options;
5788
- this.updateFinishedPromise();
5789
- this.removeAnimation = () => {
5790
- const elementState = state.get(element);
5791
- elementState && elementState.delete(valueName);
5792
- };
5793
- };
5794
- if (!supportsWaapi()) {
5795
- super();
5796
- init();
5797
- onFinish();
5798
- }
5799
- else {
5800
- super(startWaapiAnimation(element, valueName, valueKeyframes, options));
5801
- init();
5802
- if (options.autoplay === false) {
5803
- this.animation.pause();
5804
- }
5805
- this.animation.onfinish = onFinish;
5806
- getElementAnimationState(element).set(valueName, this);
5807
- }
5808
- }
5809
- /**
5810
- * Allows the returned animation to be awaited or promise-chained. Currently
5811
- * resolves when the animation finishes at all but in a future update could/should
5812
- * reject if its cancels.
5813
- */
5814
- then(resolve, reject) {
5815
- return this.currentFinishedPromise.then(resolve, reject);
5816
- }
5817
- updateFinishedPromise() {
5818
- this.currentFinishedPromise = new Promise((resolve) => {
5819
- this.resolveFinishedPromise = resolve;
5820
- });
5821
- }
5822
- play() {
5823
- if (this.state === "finished") {
5824
- this.updateFinishedPromise();
5825
- }
5826
- super.play();
5827
- }
5828
- cancel() {
5829
- this.removeAnimation();
5830
- super.cancel();
5831
- }
5832
- }
5833
-
5834
5889
  function animateElements(elementOrSelector, keyframes, options, scope) {
5835
5890
  const elements = resolveElements(elementOrSelector, scope);
5836
5891
  const numElements = elements.length;
@@ -5850,13 +5905,15 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
5850
5905
  const valueOptions = {
5851
5906
  ...getValueTransition$1(elementTransition, valueName),
5852
5907
  };
5853
- valueOptions.duration = valueOptions.duration
5854
- ? secondsToMilliseconds(valueOptions.duration)
5855
- : valueOptions.duration;
5856
- valueOptions.delay = secondsToMilliseconds(valueOptions.delay || 0);
5857
- valueOptions.allowFlatten =
5858
- !elementTransition.type && !elementTransition.ease;
5859
- 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
+ }));
5860
5917
  }
5861
5918
  }
5862
5919
  return animations;
@@ -5864,7 +5921,7 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
5864
5921
 
5865
5922
  const createScopedWaapiAnimate = (scope) => {
5866
5923
  function scopedAnimate(elementOrSelector, keyframes, options) {
5867
- return new GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
5924
+ return new GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
5868
5925
  }
5869
5926
  return scopedAnimate;
5870
5927
  };
@@ -5903,8 +5960,7 @@ function getElementSize(target, borderBoxSize) {
5903
5960
  }
5904
5961
  }
5905
5962
  function notifyTarget({ target, contentRect, borderBoxSize, }) {
5906
- var _a;
5907
- (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
5963
+ resizeHandlers.get(target)?.forEach((handler) => {
5908
5964
  handler({
5909
5965
  target,
5910
5966
  contentSize: contentRect,
@@ -5933,14 +5989,14 @@ function resizeElement(target, handler) {
5933
5989
  resizeHandlers.set(element, elementHandlers);
5934
5990
  }
5935
5991
  elementHandlers.add(handler);
5936
- observer === null || observer === void 0 ? void 0 : observer.observe(element);
5992
+ observer?.observe(element);
5937
5993
  });
5938
5994
  return () => {
5939
5995
  elements.forEach((element) => {
5940
5996
  const elementHandlers = resizeHandlers.get(element);
5941
- elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
5942
- if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
5943
- observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
5997
+ elementHandlers?.delete(handler);
5998
+ if (!elementHandlers?.size) {
5999
+ observer?.unobserve(element);
5944
6000
  }
5945
6001
  });
5946
6002
  };
@@ -6319,7 +6375,6 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
6319
6375
  const listener = scrollListeners.get(container);
6320
6376
  frame.read(listener, false, true);
6321
6377
  return () => {
6322
- var _a;
6323
6378
  cancelFrame(listener);
6324
6379
  /**
6325
6380
  * Check if we even have any handlers for this container.
@@ -6337,7 +6392,7 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
6337
6392
  scrollListeners.delete(container);
6338
6393
  if (scrollListener) {
6339
6394
  getEventTarget(container).removeEventListener("scroll", scrollListener);
6340
- (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
6395
+ resizeListeners.get(container)?.();
6341
6396
  window.removeEventListener("resize", scrollListener);
6342
6397
  }
6343
6398
  };