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
@@ -14,11 +14,8 @@
14
14
  arr.splice(index, 1);
15
15
  }
16
16
 
17
- /*#__NO_SIDE_EFFECTS__*/
18
- const noop = (any) => any;
19
-
20
- let warning = noop;
21
- exports.invariant = noop;
17
+ let warning = () => { };
18
+ exports.invariant = () => { };
22
19
  {
23
20
  warning = (check, message) => {
24
21
  if (!check && typeof console !== "undefined") {
@@ -47,6 +44,9 @@
47
44
  };
48
45
  }
49
46
 
47
+ /*#__NO_SIDE_EFFECTS__*/
48
+ const noop = (any) => any;
49
+
50
50
  /*
51
51
  Progress within given range
52
52
 
@@ -135,15 +135,14 @@
135
135
 
136
136
  const supportsScrollTimeline = /* @__PURE__ */ memo(() => window.ScrollTimeline !== undefined);
137
137
 
138
- class BaseGroupPlaybackControls {
138
+ class GroupAnimation {
139
139
  constructor(animations) {
140
140
  // Bound to accomodate common `return animation.stop` pattern
141
141
  this.stop = () => this.runAll("stop");
142
142
  this.animations = animations.filter(Boolean);
143
143
  }
144
144
  get finished() {
145
- // Support for new finished Promise and legacy thennable API
146
- return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
145
+ return Promise.all(this.animations.map((animation) => animation.finished));
147
146
  }
148
147
  /**
149
148
  * TODO: Filter out cancelled or stopped animations before returning
@@ -214,156 +213,122 @@
214
213
  }
215
214
  }
216
215
 
217
- /**
218
- * TODO: This is a temporary class to support the legacy
219
- * thennable API
220
- */
221
- class GroupPlaybackControls extends BaseGroupPlaybackControls {
222
- then(onResolve, onReject) {
223
- return Promise.all(this.animations).then(onResolve).catch(onReject);
216
+ class GroupAnimationWithThen extends GroupAnimation {
217
+ then(onResolve, _onReject) {
218
+ return this.finished.finally(onResolve).then(() => { });
224
219
  }
225
220
  }
226
221
 
227
- function getValueTransition$1(transition, key) {
228
- return transition
229
- ? transition[key] ||
230
- transition["default"] ||
231
- transition
232
- : undefined;
233
- }
234
-
235
- /**
236
- * Implement a practical max duration for keyframe generation
237
- * to prevent infinite loops
238
- */
239
- const maxGeneratorDuration = 20000;
240
- function calcGeneratorDuration(generator) {
241
- let duration = 0;
242
- const timeStep = 50;
243
- let state = generator.next(duration);
244
- while (!state.done && duration < maxGeneratorDuration) {
245
- duration += timeStep;
246
- state = generator.next(duration);
247
- }
248
- return duration >= maxGeneratorDuration ? Infinity : duration;
249
- }
250
-
251
- /**
252
- * Create a progress => progress easing function from a generator.
253
- */
254
- function createGeneratorEasing(options, scale = 100, createGenerator) {
255
- const generator = createGenerator({ ...options, keyframes: [0, scale] });
256
- const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
257
- return {
258
- type: "keyframes",
259
- ease: (progress) => {
260
- return generator.next(duration * progress).value / scale;
261
- },
262
- duration: millisecondsToSeconds(duration),
263
- };
264
- }
265
-
266
- function isGenerator(type) {
267
- return typeof type === "function";
268
- }
222
+ const isCSSVar = (name) => name.startsWith("--");
223
+ const style = {
224
+ set: (element, name, value) => {
225
+ isCSSVar(name)
226
+ ? element.style.setProperty(name, value)
227
+ : (element.style[name] = value);
228
+ },
229
+ get: (element, name) => {
230
+ return isCSSVar(name)
231
+ ? element.style.getPropertyValue(name)
232
+ : element.style[name];
233
+ },
234
+ };
269
235
 
270
- function attachTimeline(animation, timeline) {
271
- animation.timeline = timeline;
272
- animation.onfinish = null;
236
+ const isNotNull$1 = (value) => value !== null;
237
+ function getFinalKeyframe$1(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
238
+ const resolvedKeyframes = keyframes.filter(isNotNull$1);
239
+ const index = repeat && repeatType !== "loop" && repeat % 2 === 1
240
+ ? 0
241
+ : resolvedKeyframes.length - 1;
242
+ return !index || finalKeyframe === undefined
243
+ ? resolvedKeyframes[index]
244
+ : finalKeyframe;
273
245
  }
274
246
 
275
- class NativeAnimationControls {
276
- constructor(animation) {
277
- this.animation = animation;
278
- }
279
- get duration() {
280
- var _a, _b, _c;
281
- const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
282
- ((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
283
- 300;
284
- return millisecondsToSeconds(Number(durationInMs));
285
- }
286
- get time() {
287
- var _a;
288
- if (this.animation) {
289
- return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
290
- }
291
- return 0;
292
- }
293
- set time(newTime) {
294
- if (this.animation) {
295
- this.animation.currentTime = secondsToMilliseconds(newTime);
296
- }
297
- }
298
- get speed() {
299
- return this.animation ? this.animation.playbackRate : 1;
300
- }
301
- set speed(newSpeed) {
302
- if (this.animation) {
303
- this.animation.playbackRate = newSpeed;
304
- }
305
- }
306
- get state() {
307
- return this.animation ? this.animation.playState : "finished";
308
- }
309
- get startTime() {
310
- return this.animation ? this.animation.startTime : null;
311
- }
312
- get finished() {
313
- return this.animation ? this.animation.finished : Promise.resolve();
247
+ const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
248
+ try {
249
+ document.createElement("div").animate({ opacity: [1] });
314
250
  }
315
- play() {
316
- this.animation && this.animation.play();
251
+ catch (e) {
252
+ return false;
317
253
  }
318
- pause() {
319
- this.animation && this.animation.pause();
254
+ return true;
255
+ });
256
+
257
+ const pxValues = new Set([
258
+ // Border props
259
+ "borderWidth",
260
+ "borderTopWidth",
261
+ "borderRightWidth",
262
+ "borderBottomWidth",
263
+ "borderLeftWidth",
264
+ "borderRadius",
265
+ "radius",
266
+ "borderTopLeftRadius",
267
+ "borderTopRightRadius",
268
+ "borderBottomRightRadius",
269
+ "borderBottomLeftRadius",
270
+ // Positioning props
271
+ "width",
272
+ "maxWidth",
273
+ "height",
274
+ "maxHeight",
275
+ "top",
276
+ "right",
277
+ "bottom",
278
+ "left",
279
+ // Spacing props
280
+ "padding",
281
+ "paddingTop",
282
+ "paddingRight",
283
+ "paddingBottom",
284
+ "paddingLeft",
285
+ "margin",
286
+ "marginTop",
287
+ "marginRight",
288
+ "marginBottom",
289
+ "marginLeft",
290
+ // Misc
291
+ "backgroundPositionX",
292
+ "backgroundPositionY",
293
+ ]);
294
+
295
+ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
296
+ if (!Array.isArray(keyframes)) {
297
+ keyframes = [keyframes];
320
298
  }
321
- stop() {
322
- if (!this.animation ||
323
- this.state === "idle" ||
324
- this.state === "finished") {
325
- return;
299
+ for (let i = 0; i < keyframes.length; i++) {
300
+ if (keyframes[i] === null) {
301
+ keyframes[i] =
302
+ i === 0 && !pseudoElement
303
+ ? style.get(element, name)
304
+ : keyframes[i - 1];
326
305
  }
327
- if (this.animation.commitStyles) {
328
- this.animation.commitStyles();
306
+ if (typeof keyframes[i] === "number" && pxValues.has(name)) {
307
+ keyframes[i] = keyframes[i] + "px";
329
308
  }
330
- this.cancel();
331
- }
332
- flatten() {
333
- var _a, _b;
334
- if (!this.animation || !((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowFlatten))
335
- return;
336
- (_b = this.animation.effect) === null || _b === void 0 ? void 0 : _b.updateTiming({ easing: "linear" });
337
- }
338
- attachTimeline(timeline) {
339
- if (this.animation)
340
- attachTimeline(this.animation, timeline);
341
- return noop;
342
309
  }
343
- complete() {
344
- this.animation && this.animation.finish();
345
- }
346
- cancel() {
347
- try {
348
- this.animation && this.animation.cancel();
349
- }
350
- catch (e) { }
310
+ if (!pseudoElement && !supportsPartialKeyframes() && keyframes.length < 2) {
311
+ keyframes.unshift(style.get(element, name));
351
312
  }
313
+ return keyframes;
352
314
  }
353
315
 
316
+ const statsBuffer = {
317
+ value: null,
318
+ addProjectionMetrics: null,
319
+ };
320
+
354
321
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
355
322
 
356
323
  /**
357
324
  * Add the ability for test suites to manually set support flags
358
325
  * to better test more environments.
359
326
  */
360
- const supportsFlags = {
361
- linearEasing: undefined,
362
- };
327
+ const supportsFlags = {};
363
328
 
364
329
  function memoSupports(callback, supportsFlag) {
365
330
  const memoized = memo(callback);
366
- return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
331
+ return () => supportsFlags[supportsFlag] ?? memoized();
367
332
  }
368
333
 
369
334
  const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
@@ -384,20 +349,13 @@
384
349
  let points = "";
385
350
  const numPoints = Math.max(Math.round(duration / resolution), 2);
386
351
  for (let i = 0; i < numPoints; i++) {
387
- points += easing(progress(0, numPoints - 1, i)) + ", ";
352
+ points += easing(i / (numPoints - 1)) + ", ";
388
353
  }
389
354
  return `linear(${points.substring(0, points.length - 2)})`;
390
355
  };
391
356
 
392
- function isWaapiSupportedEasing(easing) {
393
- return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
394
- !easing ||
395
- (typeof easing === "string" &&
396
- (easing in supportedWaapiEasing || supportsLinearEasing())) ||
397
- isBezierDefinition(easing) ||
398
- (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
399
- }
400
357
  const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
358
+
401
359
  const supportedWaapiEasing = {
402
360
  linear: "linear",
403
361
  ease: "ease",
@@ -409,6 +367,7 @@
409
367
  backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
410
368
  backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
411
369
  };
370
+
412
371
  function mapEasingToNativeEasing(easing, duration) {
413
372
  if (!easing) {
414
373
  return undefined;
@@ -428,6 +387,247 @@
428
387
  }
429
388
  }
430
389
 
390
+ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
391
+ const keyframeOptions = {
392
+ [valueName]: keyframes,
393
+ };
394
+ if (times)
395
+ keyframeOptions.offset = times;
396
+ const easing = mapEasingToNativeEasing(ease, duration);
397
+ /**
398
+ * If this is an easing array, apply to keyframes, not animation as a whole
399
+ */
400
+ if (Array.isArray(easing))
401
+ keyframeOptions.easing = easing;
402
+ const animation = element.animate(keyframeOptions, {
403
+ delay,
404
+ duration,
405
+ easing: !Array.isArray(easing) ? easing : "linear",
406
+ fill: "both",
407
+ iterations: repeat + 1,
408
+ direction: repeatType === "reverse" ? "alternate" : "normal",
409
+ pseudoElement,
410
+ });
411
+ return animation;
412
+ }
413
+
414
+ function isGenerator(type) {
415
+ return typeof type === "function" && "applyToOptions" in type;
416
+ }
417
+
418
+ function applyGeneratorOptions({ type, ...options }) {
419
+ if (isGenerator(type)) {
420
+ return type.applyToOptions(options);
421
+ }
422
+ else {
423
+ options.duration ?? (options.duration = 300);
424
+ options.ease ?? (options.ease = "easeOut");
425
+ }
426
+ return options;
427
+ }
428
+
429
+ const animationMaps = new WeakMap();
430
+ const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
431
+ function getAnimationMap(element) {
432
+ const map = animationMaps.get(element) || new Map();
433
+ animationMaps.set(element, map);
434
+ return map;
435
+ }
436
+ /**
437
+ * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
438
+ */
439
+ class NativeAnimation {
440
+ constructor(options) {
441
+ /**
442
+ * If we already have an animation, we don't need to instantiate one
443
+ * and can just use this as a controls interface.
444
+ */
445
+ if ("animation" in options) {
446
+ this.animation = options.animation;
447
+ return;
448
+ }
449
+ const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
450
+ let { transition } = options;
451
+ this.allowFlatten = allowFlatten;
452
+ /**
453
+ * Stop any existing animations on the element before reading existing keyframes.
454
+ *
455
+ * TODO: Check for VisualElement before using animation state. This is a fallback
456
+ * for mini animate(). Do this when implementing NativeAnimationExtended.
457
+ */
458
+ const animationMap = getAnimationMap(element);
459
+ const key = animationMapKey(name, pseudoElement || "");
460
+ const currentAnimation = animationMap.get(key);
461
+ currentAnimation && currentAnimation.stop();
462
+ /**
463
+ * TODO: If these keyframes aren't correctly hydrated then we want to throw
464
+ * run an instant animation.
465
+ */
466
+ const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
467
+ exports.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
468
+ transition = applyGeneratorOptions(transition);
469
+ this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
470
+ if (transition.autoplay === false) {
471
+ this.animation.pause();
472
+ }
473
+ this.removeAnimation = () => animationMap.delete(key);
474
+ this.animation.onfinish = () => {
475
+ if (!pseudoElement) {
476
+ style.set(element, name, getFinalKeyframe$1(keyframes, transition));
477
+ }
478
+ else {
479
+ this.commitStyles();
480
+ }
481
+ this.cancel();
482
+ };
483
+ /**
484
+ * TODO: Check for VisualElement before using animation state.
485
+ */
486
+ animationMap.set(key, this);
487
+ }
488
+ play() {
489
+ this.animation.play();
490
+ }
491
+ pause() {
492
+ this.animation.pause();
493
+ }
494
+ complete() {
495
+ this.animation.finish();
496
+ }
497
+ cancel() {
498
+ try {
499
+ this.animation.cancel();
500
+ }
501
+ catch (e) { }
502
+ this.removeAnimation();
503
+ }
504
+ stop() {
505
+ const { state } = this;
506
+ if (state === "idle" || state === "finished") {
507
+ return;
508
+ }
509
+ this.commitStyles();
510
+ this.cancel();
511
+ }
512
+ /**
513
+ * WAAPI doesn't natively have any interruption capabilities.
514
+ *
515
+ * In this method, we commit styles back to the DOM before cancelling
516
+ * the animation.
517
+ *
518
+ * This is designed to be overridden by NativeAnimationExtended, which
519
+ * will create a renderless JS animation and sample it twice to calculate
520
+ * its current value, "previous" value, and therefore allow
521
+ * Motion to also correctly calculate velocity for any subsequent animation
522
+ * while deferring the commit until the next animation frame.
523
+ */
524
+ commitStyles() {
525
+ this.animation.commitStyles?.();
526
+ }
527
+ get duration() {
528
+ console.log(this.animation.effect?.getComputedTiming());
529
+ const duration = this.animation.effect?.getComputedTiming().duration || 0;
530
+ return millisecondsToSeconds(Number(duration));
531
+ }
532
+ get time() {
533
+ return millisecondsToSeconds(Number(this.animation.currentTime) || 0);
534
+ }
535
+ set time(newTime) {
536
+ this.animation.currentTime = secondsToMilliseconds(newTime);
537
+ }
538
+ /**
539
+ * The playback speed of the animation.
540
+ * 1 = normal speed, 2 = double speed, 0.5 = half speed.
541
+ */
542
+ get speed() {
543
+ return this.animation.playbackRate;
544
+ }
545
+ set speed(newSpeed) {
546
+ this.animation.playbackRate = newSpeed;
547
+ }
548
+ get state() {
549
+ return this.animation.playState;
550
+ }
551
+ get startTime() {
552
+ return Number(this.animation.startTime);
553
+ }
554
+ get finished() {
555
+ return this.animation.finished;
556
+ }
557
+ flatten() {
558
+ if (this.allowFlatten) {
559
+ this.animation.effect?.updateTiming({ easing: "linear" });
560
+ }
561
+ }
562
+ /**
563
+ * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
564
+ */
565
+ attachTimeline(timeline) {
566
+ this.animation.timeline = timeline;
567
+ this.animation.onfinish = null;
568
+ return noop;
569
+ }
570
+ /**
571
+ * Allows the animation to be awaited.
572
+ *
573
+ * @deprecated Use `finished` instead.
574
+ */
575
+ then(onResolve, onReject) {
576
+ return this.finished.then(onResolve).catch(onReject);
577
+ }
578
+ }
579
+
580
+ function getValueTransition$1(transition, key) {
581
+ return (transition?.[key] ??
582
+ transition?.["default"] ??
583
+ transition);
584
+ }
585
+
586
+ /**
587
+ * Implement a practical max duration for keyframe generation
588
+ * to prevent infinite loops
589
+ */
590
+ const maxGeneratorDuration = 20000;
591
+ function calcGeneratorDuration(generator) {
592
+ let duration = 0;
593
+ const timeStep = 50;
594
+ let state = generator.next(duration);
595
+ while (!state.done && duration < maxGeneratorDuration) {
596
+ duration += timeStep;
597
+ state = generator.next(duration);
598
+ }
599
+ return duration >= maxGeneratorDuration ? Infinity : duration;
600
+ }
601
+
602
+ /**
603
+ * Create a progress => progress easing function from a generator.
604
+ */
605
+ function createGeneratorEasing(options, scale = 100, createGenerator) {
606
+ const generator = createGenerator({ ...options, keyframes: [0, scale] });
607
+ const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
608
+ return {
609
+ type: "keyframes",
610
+ ease: (progress) => {
611
+ return generator.next(duration * progress).value / scale;
612
+ },
613
+ duration: millisecondsToSeconds(duration),
614
+ };
615
+ }
616
+
617
+ function isWaapiSupportedEasing(easing) {
618
+ return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
619
+ !easing ||
620
+ (typeof easing === "string" &&
621
+ (easing in supportedWaapiEasing || supportsLinearEasing())) ||
622
+ isBezierDefinition(easing) ||
623
+ (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
624
+ }
625
+
626
+ function attachTimeline(animation, timeline) {
627
+ animation.timeline = timeline;
628
+ animation.onfinish = null;
629
+ }
630
+
431
631
  const stepsOrder = [
432
632
  "read", // Read
433
633
  "resolveKeyframes", // Write/Read/Write/Read
@@ -437,11 +637,6 @@
437
637
  "postRender", // Compute
438
638
  ];
439
639
 
440
- const statsBuffer = {
441
- value: null,
442
- addProjectionMetrics: null,
443
- };
444
-
445
640
  function createRenderStep(runNextFrame, stepName) {
446
641
  /**
447
642
  * We create and reuse two queues, one to queue jobs for the current frame
@@ -631,21 +826,16 @@
631
826
  }
632
827
 
633
828
  function resolveElements(elementOrSelector, scope, selectorCache) {
634
- var _a;
635
829
  if (elementOrSelector instanceof EventTarget) {
636
830
  return [elementOrSelector];
637
831
  }
638
832
  else if (typeof elementOrSelector === "string") {
639
833
  let root = document;
640
834
  if (scope) {
641
- // TODO: Refactor to utils package
642
- // invariant(
643
- // Boolean(scope.current),
644
- // "Scope provided, but no element detected."
645
- // )
646
835
  root = scope.current;
647
836
  }
648
- const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
837
+ const elements = selectorCache?.[elementOrSelector] ??
838
+ root.querySelectorAll(elementOrSelector);
649
839
  return elements ? Array.from(elements) : [];
650
840
  }
651
841
  return Array.from(elementOrSelector);
@@ -844,7 +1034,7 @@
844
1034
  if (target instanceof HTMLElement) {
845
1035
  target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
846
1036
  if (!isElementKeyboardAccessible(target) &&
847
- target.tabIndex === null) {
1037
+ !target.hasAttribute("tabindex")) {
848
1038
  target.tabIndex = 0;
849
1039
  }
850
1040
  }
@@ -877,7 +1067,7 @@
877
1067
  * This will be replaced by the build step with the latest version number.
878
1068
  * When MotionValues are provided to motion components, warn if versions are mixed.
879
1069
  */
880
- this.version = "12.6.1";
1070
+ this.version = "12.6.3";
881
1071
  /**
882
1072
  * Tracks whether this value can output a velocity. Currently this is only true
883
1073
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1426,9 +1616,17 @@
1426
1616
  const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
1427
1617
  return calculatedDuration + "ms " + easing;
1428
1618
  },
1619
+ toTransition: () => { },
1429
1620
  };
1430
1621
  return generator;
1431
1622
  }
1623
+ spring.applyToOptions = (options) => {
1624
+ const generatorOptions = createGeneratorEasing(options, 100, spring);
1625
+ options.ease = supportsLinearEasing() ? generatorOptions.ease : "easeOut";
1626
+ options.duration = secondsToMilliseconds(generatorOptions.duration);
1627
+ options.type = "keyframes";
1628
+ return options;
1629
+ };
1432
1630
 
1433
1631
  const wrap = (min, max, v) => {
1434
1632
  const rangeSize = max - min;
@@ -1512,7 +1710,6 @@
1512
1710
  * calculate an absolute time for the next keyframes.
1513
1711
  */
1514
1712
  function calcNextTime(current, next, prev, labels) {
1515
- var _a;
1516
1713
  if (typeof next === "number") {
1517
1714
  return next;
1518
1715
  }
@@ -1523,7 +1720,7 @@
1523
1720
  return prev;
1524
1721
  }
1525
1722
  else {
1526
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
1723
+ return labels.get(next) ?? current;
1527
1724
  }
1528
1725
  }
1529
1726
 
@@ -1636,7 +1833,7 @@
1636
1833
  const numKeyframes = valueKeyframesAsList.length;
1637
1834
  const createGenerator = isGenerator(type)
1638
1835
  ? type
1639
- : generators === null || generators === void 0 ? void 0 : generators[type];
1836
+ : generators?.[type];
1640
1837
  if (numKeyframes <= 2 && createGenerator) {
1641
1838
  /**
1642
1839
  * As we're creating an easing function from a spring,
@@ -1658,7 +1855,7 @@
1658
1855
  ease = springEasing.ease;
1659
1856
  duration = springEasing.duration;
1660
1857
  }
1661
- duration !== null && duration !== void 0 ? duration : (duration = defaultDuration);
1858
+ duration ?? (duration = defaultDuration);
1662
1859
  const startTime = currentTime + calculatedDelay;
1663
1860
  /**
1664
1861
  * If there's only one time offset of 0, fill in a second with length 1
@@ -1867,7 +2064,7 @@
1867
2064
 
1868
2065
  function getValueState(visualElement) {
1869
2066
  const state = [{}, {}];
1870
- visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
2067
+ visualElement?.values.forEach((value, key) => {
1871
2068
  state[0][key] = value.get();
1872
2069
  state[1][key] = value.getVelocity();
1873
2070
  });
@@ -2199,11 +2396,10 @@
2199
2396
  const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
2200
2397
 
2201
2398
  function test(v) {
2202
- var _a, _b;
2203
2399
  return (isNaN(v) &&
2204
2400
  typeof v === "string" &&
2205
- (((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
2206
- (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
2401
+ (v.match(floatRegex)?.length || 0) +
2402
+ (v.match(colorRegex)?.length || 0) >
2207
2403
  0);
2208
2404
  }
2209
2405
  const NUMBER_TOKEN = "number";
@@ -2591,8 +2787,7 @@
2591
2787
  const restore = transformsToRestore.get(element);
2592
2788
  if (restore) {
2593
2789
  restore.forEach(([key, value]) => {
2594
- var _a;
2595
- (_a = element.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(value);
2790
+ element.getValue(key)?.set(value);
2596
2791
  });
2597
2792
  }
2598
2793
  });
@@ -2679,7 +2874,7 @@
2679
2874
  * If the first keyframe is null, we need to find its value by sampling the element
2680
2875
  */
2681
2876
  if (i === 0) {
2682
- const currentValue = motionValue === null || motionValue === void 0 ? void 0 : motionValue.get();
2877
+ const currentValue = motionValue?.get();
2683
2878
  const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
2684
2879
  if (currentValue !== undefined) {
2685
2880
  unresolvedKeyframes[0] = currentValue;
@@ -2760,7 +2955,7 @@
2760
2955
  if (!match)
2761
2956
  return [,];
2762
2957
  const [, token1, token2, fallback] = match;
2763
- return [`--${token1 !== null && token1 !== void 0 ? token1 : token2}`, fallback];
2958
+ return [`--${token1 ?? token2}`, fallback];
2764
2959
  }
2765
2960
  const maxDepth = 4;
2766
2961
  function getVariableValue(current, element, depth = 1) {
@@ -2899,7 +3094,6 @@
2899
3094
  }
2900
3095
  }
2901
3096
  measureEndState() {
2902
- var _a;
2903
3097
  const { element, name, unresolvedKeyframes } = this;
2904
3098
  if (!element || !element.current)
2905
3099
  return;
@@ -2912,7 +3106,7 @@
2912
3106
  this.finalKeyframe = finalKeyframe;
2913
3107
  }
2914
3108
  // If we removed transform values, reapply them before the next render
2915
- if ((_a = this.removedTransforms) === null || _a === void 0 ? void 0 : _a.length) {
3109
+ if (this.removedTransforms?.length) {
2916
3110
  this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
2917
3111
  element
2918
3112
  .getValue(unsetTransformName)
@@ -3268,13 +3462,12 @@
3268
3462
  };
3269
3463
  }
3270
3464
  function matchOrder(origin, target) {
3271
- var _a;
3272
3465
  const orderedOrigin = [];
3273
3466
  const pointers = { color: 0, var: 0, number: 0 };
3274
3467
  for (let i = 0; i < target.values.length; i++) {
3275
3468
  const type = target.types[i];
3276
3469
  const originIndex = origin.indexes[type][pointers[type]];
3277
- const originValue = (_a = origin.values[originIndex]) !== null && _a !== void 0 ? _a : 0;
3470
+ const originValue = origin.values[originIndex] ?? 0;
3278
3471
  orderedOrigin[i] = originValue;
3279
3472
  pointers[type]++;
3280
3473
  }
@@ -3501,7 +3694,7 @@
3501
3694
  return offset.map((o) => o * duration);
3502
3695
  }
3503
3696
 
3504
- function defaultEasing$1(values, easing) {
3697
+ function defaultEasing(values, easing) {
3505
3698
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
3506
3699
  }
3507
3700
  function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
@@ -3532,7 +3725,7 @@
3532
3725
  const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
3533
3726
  ease: Array.isArray(easingFunctions)
3534
3727
  ? easingFunctions
3535
- : defaultEasing$1(keyframeValues, easingFunctions),
3728
+ : defaultEasing(keyframeValues, easingFunctions),
3536
3729
  });
3537
3730
  return {
3538
3731
  calculatedDuration: duration,
@@ -3614,7 +3807,7 @@
3614
3807
  onStop && onStop();
3615
3808
  };
3616
3809
  const { name, motionValue, element, keyframes } = this.options;
3617
- const KeyframeResolver$1 = (element === null || element === void 0 ? void 0 : element.KeyframeResolver) || KeyframeResolver;
3810
+ const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
3618
3811
  const onResolved = (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe);
3619
3812
  this.resolver = new KeyframeResolver$1(keyframes, onResolved, name, motionValue, element);
3620
3813
  this.resolver.scheduleResolve();
@@ -3862,7 +4055,7 @@
3862
4055
  this.startTime = now - this.holdTime;
3863
4056
  }
3864
4057
  else if (!this.startTime) {
3865
- this.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4058
+ this.startTime = startTime ?? this.calcStartTime();
3866
4059
  }
3867
4060
  else if (this.state === "finished") {
3868
4061
  this.startTime = now;
@@ -3880,13 +4073,12 @@
3880
4073
  this.driver.start();
3881
4074
  }
3882
4075
  pause() {
3883
- var _a;
3884
4076
  if (!this._resolved) {
3885
4077
  this.pendingPlayState = "paused";
3886
4078
  return;
3887
4079
  }
3888
4080
  this.state = "paused";
3889
- this.holdTime = (_a = this.currentTime) !== null && _a !== void 0 ? _a : 0;
4081
+ this.holdTime = this.currentTime ?? 0;
3890
4082
  }
3891
4083
  complete() {
3892
4084
  if (this.state !== "running") {
@@ -3926,6 +4118,9 @@
3926
4118
  this.startTime = 0;
3927
4119
  return this.tick(time, true);
3928
4120
  }
4121
+ get finished() {
4122
+ return this.currentFinishedPromise;
4123
+ }
3929
4124
  }
3930
4125
 
3931
4126
  /**
@@ -3941,27 +4136,6 @@
3941
4136
  // "background-color"
3942
4137
  ]);
3943
4138
 
3944
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
3945
- const keyframeOptions = { [valueName]: keyframes };
3946
- if (times)
3947
- keyframeOptions.offset = times;
3948
- const easing = mapEasingToNativeEasing(ease, duration);
3949
- /**
3950
- * If this is an easing array, apply to keyframes, not animation as a whole
3951
- */
3952
- if (Array.isArray(easing))
3953
- keyframeOptions.easing = easing;
3954
- const animation = element.animate(keyframeOptions, {
3955
- delay,
3956
- duration,
3957
- easing: !Array.isArray(easing) ? easing : "linear",
3958
- fill: "both",
3959
- iterations: repeat + 1,
3960
- direction: repeatType === "reverse" ? "alternate" : "normal",
3961
- });
3962
- return animation;
3963
- }
3964
-
3965
4139
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
3966
4140
 
3967
4141
  /**
@@ -4072,7 +4246,7 @@
4072
4246
  const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
4073
4247
  // Override the browser calculated startTime with one synchronised to other JS
4074
4248
  // and WAAPI animations starting this event loop.
4075
- animation.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4249
+ animation.startTime = startTime ?? this.calcStartTime();
4076
4250
  if (this.pendingTimeline) {
4077
4251
  attachTimeline(animation, this.pendingTimeline);
4078
4252
  this.pendingTimeline = undefined;
@@ -4131,6 +4305,9 @@
4131
4305
  const { animation } = resolved;
4132
4306
  return animation.playbackRate;
4133
4307
  }
4308
+ get finished() {
4309
+ return this.resolved.animation.finished;
4310
+ }
4134
4311
  set speed(newSpeed) {
4135
4312
  const { resolved } = this;
4136
4313
  if (!resolved)
@@ -4396,7 +4573,7 @@
4396
4573
  });
4397
4574
  // We still want to return some animation controls here rather
4398
4575
  // than returning undefined
4399
- return new GroupPlaybackControls([]);
4576
+ return new GroupAnimationWithThen([]);
4400
4577
  }
4401
4578
  }
4402
4579
  /**
@@ -4424,7 +4601,6 @@
4424
4601
  return shouldBlock;
4425
4602
  }
4426
4603
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
4427
- var _a;
4428
4604
  let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
4429
4605
  if (transitionOverride)
4430
4606
  transition = transitionOverride;
@@ -4433,7 +4609,7 @@
4433
4609
  visualElement.animationState &&
4434
4610
  visualElement.animationState.getState()[type];
4435
4611
  for (const key in target) {
4436
- const value = visualElement.getValue(key, (_a = visualElement.latestValues[key]) !== null && _a !== void 0 ? _a : null);
4612
+ const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
4437
4613
  const valueTarget = target[key];
4438
4614
  if (valueTarget === undefined ||
4439
4615
  (animationTypeState &&
@@ -4592,7 +4768,7 @@
4592
4768
  * and warn against mismatches.
4593
4769
  */
4594
4770
  {
4595
- warnOnce(nextValue.version === "12.6.2", `Attempting to mix Motion versions ${nextValue.version} with 12.6.2 may not work as expected.`);
4771
+ warnOnce(nextValue.version === "12.6.3", `Attempting to mix Motion versions ${nextValue.version} with 12.6.3 may not work as expected.`);
4596
4772
  }
4597
4773
  }
4598
4774
  else if (isMotionValue(prevValue)) {
@@ -5016,10 +5192,10 @@
5016
5192
  * directly from the instance (which might have performance implications).
5017
5193
  */
5018
5194
  readValue(key, target) {
5019
- var _a;
5020
5195
  let value = this.latestValues[key] !== undefined || !this.current
5021
5196
  ? this.latestValues[key]
5022
- : (_a = this.getBaseTargetFromProps(this.props, key)) !== null && _a !== void 0 ? _a : this.readValueFromInstance(this.current, key, this.options);
5197
+ : this.getBaseTargetFromProps(this.props, key) ??
5198
+ this.readValueFromInstance(this.current, key, this.options);
5023
5199
  if (value !== undefined && value !== null) {
5024
5200
  if (typeof value === "string" &&
5025
5201
  (isNumericalString(value) || isZeroValueString(value))) {
@@ -5045,11 +5221,10 @@
5045
5221
  * props.
5046
5222
  */
5047
5223
  getBaseTarget(key) {
5048
- var _a;
5049
5224
  const { initial } = this.props;
5050
5225
  let valueFromInitial;
5051
5226
  if (typeof initial === "string" || typeof initial === "object") {
5052
- const variant = resolveVariantFromProps(this.props, initial, (_a = this.presenceContext) === null || _a === void 0 ? void 0 : _a.custom);
5227
+ const variant = resolveVariantFromProps(this.props, initial, this.presenceContext?.custom);
5053
5228
  if (variant) {
5054
5229
  valueFromInitial = variant[key];
5055
5230
  }
@@ -5416,7 +5591,6 @@
5416
5591
  }
5417
5592
 
5418
5593
  function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5419
- var _a;
5420
5594
  const { style } = props;
5421
5595
  const newValues = {};
5422
5596
  for (const key in style) {
@@ -5424,7 +5598,7 @@
5424
5598
  (prevProps.style &&
5425
5599
  isMotionValue(prevProps.style[key])) ||
5426
5600
  isForcedMotionValue(key, props) ||
5427
- ((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
5601
+ visualElement?.getValue(key)?.liveStyle !== undefined) {
5428
5602
  newValues[key] = style[key];
5429
5603
  }
5430
5604
  }
@@ -5703,7 +5877,7 @@
5703
5877
  else {
5704
5878
  animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
5705
5879
  }
5706
- const animation = new GroupPlaybackControls(animations);
5880
+ const animation = new GroupAnimationWithThen(animations);
5707
5881
  if (scope) {
5708
5882
  scope.animations.push(animation);
5709
5883
  }
@@ -5713,125 +5887,6 @@
5713
5887
  }
5714
5888
  const animate = createScopedAnimate();
5715
5889
 
5716
- function setCSSVar(element, name, value) {
5717
- element.style.setProperty(name, value);
5718
- }
5719
- function setStyle(element, name, value) {
5720
- element.style[name] = value;
5721
- }
5722
-
5723
- const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
5724
- try {
5725
- document.createElement("div").animate({ opacity: [1] });
5726
- }
5727
- catch (e) {
5728
- return false;
5729
- }
5730
- return true;
5731
- });
5732
-
5733
- const state = new WeakMap();
5734
- function hydrateKeyframes(valueName, keyframes, read) {
5735
- for (let i = 0; i < keyframes.length; i++) {
5736
- if (keyframes[i] === null) {
5737
- keyframes[i] = i === 0 ? read() : keyframes[i - 1];
5738
- }
5739
- if (typeof keyframes[i] === "number" &&
5740
- browserNumberValueTypes[valueName]) {
5741
- keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
5742
- }
5743
- }
5744
- if (!supportsPartialKeyframes() && keyframes.length < 2) {
5745
- keyframes.unshift(read());
5746
- }
5747
- }
5748
- const defaultEasing = "easeOut";
5749
- function getElementAnimationState(element) {
5750
- const animationState = state.get(element) || new Map();
5751
- state.set(element, animationState);
5752
- return state.get(element);
5753
- }
5754
- class NativeAnimation extends NativeAnimationControls {
5755
- constructor(element, valueName, valueKeyframes, options) {
5756
- const isCSSVar = valueName.startsWith("--");
5757
- exports.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
5758
- const existingAnimation = getElementAnimationState(element).get(valueName);
5759
- existingAnimation && existingAnimation.stop();
5760
- const readInitialKeyframe = () => {
5761
- return valueName.startsWith("--")
5762
- ? element.style.getPropertyValue(valueName)
5763
- : window.getComputedStyle(element)[valueName];
5764
- };
5765
- if (!Array.isArray(valueKeyframes)) {
5766
- valueKeyframes = [valueKeyframes];
5767
- }
5768
- hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
5769
- // TODO: Replace this with toString()?
5770
- if (isGenerator(options.type)) {
5771
- const generatorOptions = createGeneratorEasing(options, 100, options.type);
5772
- options.ease = supportsLinearEasing()
5773
- ? generatorOptions.ease
5774
- : defaultEasing;
5775
- options.duration = secondsToMilliseconds(generatorOptions.duration);
5776
- options.type = "keyframes";
5777
- }
5778
- else {
5779
- options.ease = options.ease || defaultEasing;
5780
- }
5781
- const onFinish = () => {
5782
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
5783
- this.cancel();
5784
- this.resolveFinishedPromise();
5785
- };
5786
- const init = () => {
5787
- this.setValue = isCSSVar ? setCSSVar : setStyle;
5788
- this.options = options;
5789
- this.updateFinishedPromise();
5790
- this.removeAnimation = () => {
5791
- const elementState = state.get(element);
5792
- elementState && elementState.delete(valueName);
5793
- };
5794
- };
5795
- if (!supportsWaapi()) {
5796
- super();
5797
- init();
5798
- onFinish();
5799
- }
5800
- else {
5801
- super(startWaapiAnimation(element, valueName, valueKeyframes, options));
5802
- init();
5803
- if (options.autoplay === false) {
5804
- this.animation.pause();
5805
- }
5806
- this.animation.onfinish = onFinish;
5807
- getElementAnimationState(element).set(valueName, this);
5808
- }
5809
- }
5810
- /**
5811
- * Allows the returned animation to be awaited or promise-chained. Currently
5812
- * resolves when the animation finishes at all but in a future update could/should
5813
- * reject if its cancels.
5814
- */
5815
- then(resolve, reject) {
5816
- return this.currentFinishedPromise.then(resolve, reject);
5817
- }
5818
- updateFinishedPromise() {
5819
- this.currentFinishedPromise = new Promise((resolve) => {
5820
- this.resolveFinishedPromise = resolve;
5821
- });
5822
- }
5823
- play() {
5824
- if (this.state === "finished") {
5825
- this.updateFinishedPromise();
5826
- }
5827
- super.play();
5828
- }
5829
- cancel() {
5830
- this.removeAnimation();
5831
- super.cancel();
5832
- }
5833
- }
5834
-
5835
5890
  function animateElements(elementOrSelector, keyframes, options, scope) {
5836
5891
  const elements = resolveElements(elementOrSelector, scope);
5837
5892
  const numElements = elements.length;
@@ -5851,13 +5906,15 @@
5851
5906
  const valueOptions = {
5852
5907
  ...getValueTransition$1(elementTransition, valueName),
5853
5908
  };
5854
- valueOptions.duration = valueOptions.duration
5855
- ? secondsToMilliseconds(valueOptions.duration)
5856
- : valueOptions.duration;
5857
- valueOptions.delay = secondsToMilliseconds(valueOptions.delay || 0);
5858
- valueOptions.allowFlatten =
5859
- !elementTransition.type && !elementTransition.ease;
5860
- animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
5909
+ valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));
5910
+ valueOptions.delay && (valueOptions.delay = secondsToMilliseconds(valueOptions.delay));
5911
+ animations.push(new NativeAnimation({
5912
+ element,
5913
+ name: valueName,
5914
+ keyframes: valueKeyframes,
5915
+ transition: valueOptions,
5916
+ allowFlatten: !elementTransition.type && !elementTransition.ease,
5917
+ }));
5861
5918
  }
5862
5919
  }
5863
5920
  return animations;
@@ -5865,7 +5922,7 @@
5865
5922
 
5866
5923
  const createScopedWaapiAnimate = (scope) => {
5867
5924
  function scopedAnimate(elementOrSelector, keyframes, options) {
5868
- return new GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
5925
+ return new GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
5869
5926
  }
5870
5927
  return scopedAnimate;
5871
5928
  };
@@ -5904,8 +5961,7 @@
5904
5961
  }
5905
5962
  }
5906
5963
  function notifyTarget({ target, contentRect, borderBoxSize, }) {
5907
- var _a;
5908
- (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
5964
+ resizeHandlers.get(target)?.forEach((handler) => {
5909
5965
  handler({
5910
5966
  target,
5911
5967
  contentSize: contentRect,
@@ -5934,14 +5990,14 @@
5934
5990
  resizeHandlers.set(element, elementHandlers);
5935
5991
  }
5936
5992
  elementHandlers.add(handler);
5937
- observer === null || observer === void 0 ? void 0 : observer.observe(element);
5993
+ observer?.observe(element);
5938
5994
  });
5939
5995
  return () => {
5940
5996
  elements.forEach((element) => {
5941
5997
  const elementHandlers = resizeHandlers.get(element);
5942
- elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
5943
- if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
5944
- observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
5998
+ elementHandlers?.delete(handler);
5999
+ if (!elementHandlers?.size) {
6000
+ observer?.unobserve(element);
5945
6001
  }
5946
6002
  });
5947
6003
  };
@@ -6320,7 +6376,6 @@
6320
6376
  const listener = scrollListeners.get(container);
6321
6377
  frame.read(listener, false, true);
6322
6378
  return () => {
6323
- var _a;
6324
6379
  cancelFrame(listener);
6325
6380
  /**
6326
6381
  * Check if we even have any handlers for this container.
@@ -6338,7 +6393,7 @@
6338
6393
  scrollListeners.delete(container);
6339
6394
  if (scrollListener) {
6340
6395
  getEventTarget(container).removeEventListener("scroll", scrollListener);
6341
- (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
6396
+ resizeListeners.get(container)?.();
6342
6397
  window.removeEventListener("resize", scrollListener);
6343
6398
  }
6344
6399
  };