motion 12.6.3-alpha.0 → 12.6.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/cjs/debug.js +18 -14
  2. package/dist/cjs/index.js +414 -359
  3. package/dist/cjs/mini.js +339 -352
  4. package/dist/cjs/react-client.js +180 -188
  5. package/dist/cjs/react-m.js +24 -24
  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/interpolate.mjs +2 -1
  40. package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -2
  41. package/dist/es/framer-motion/dist/es/value/types/complex/index.mjs +2 -3
  42. package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +2 -2
  43. package/dist/es/framer-motion/dist/es/value/use-will-change/add-will-change.mjs +0 -7
  44. package/dist/es/motion/lib/index.mjs +1 -0
  45. package/dist/es/motion/lib/react.mjs +1 -1
  46. package/dist/es/motion-dom/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
  47. package/dist/es/motion-dom/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
  48. package/dist/es/motion-dom/dist/es/animation/NativeAnimation.mjs +161 -0
  49. package/dist/es/motion-dom/dist/es/animation/generators/utils/is-generator.mjs +1 -1
  50. package/dist/es/motion-dom/dist/es/animation/keyframes/get-final.mjs +12 -0
  51. package/dist/es/motion-dom/dist/es/animation/keyframes/hydrate.mjs +26 -0
  52. package/dist/es/motion-dom/dist/es/animation/utils/get-value-transition.mjs +3 -5
  53. package/dist/es/motion-dom/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
  54. package/dist/es/motion-dom/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
  55. package/dist/es/motion-dom/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
  56. package/dist/es/motion-dom/dist/es/animation/waapi/easing/supported.mjs +15 -0
  57. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/index.mjs → motion-dom/dist/es/animation/waapi/start-waapi-animation.mjs} +8 -6
  58. 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
  59. package/dist/es/motion-dom/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
  60. package/dist/es/motion-dom/dist/es/animation/waapi/utils/linear.mjs +1 -4
  61. package/dist/es/motion-dom/dist/es/animation/waapi/utils/px-values.mjs +39 -0
  62. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +1 -1
  63. package/dist/es/motion-dom/dist/es/render/dom/style.mjs +15 -0
  64. package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +2 -7
  65. package/dist/es/motion-dom/dist/es/utils/supports/flags.mjs +1 -3
  66. package/dist/es/motion-dom/dist/es/utils/supports/memo.mjs +1 -1
  67. package/dist/es/motion-dom/dist/es/value/index.mjs +1 -1
  68. package/dist/es/motion-utils/dist/es/errors.mjs +2 -4
  69. package/dist/es/motion-utils/dist/es/global-config.mjs +1 -4
  70. package/dist/motion.dev.js +414 -359
  71. package/dist/motion.js +1 -1
  72. package/package.json +3 -3
  73. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -116
  74. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
  75. package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +0 -13
  76. package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -85
  77. 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") {
@@ -32,10 +29,7 @@
32
29
  };
33
30
  }
34
31
 
35
- const MotionGlobalConfig = {
36
- skipAnimations: false,
37
- useManualTiming: false,
38
- };
32
+ const MotionGlobalConfig = {};
39
33
 
40
34
  /*#__NO_SIDE_EFFECTS__*/
41
35
  function memo(callback) {
@@ -47,6 +41,9 @@
47
41
  };
48
42
  }
49
43
 
44
+ /*#__NO_SIDE_EFFECTS__*/
45
+ const noop = (any) => any;
46
+
50
47
  /*
51
48
  Progress within given range
52
49
 
@@ -135,15 +132,14 @@
135
132
 
136
133
  const supportsScrollTimeline = /* @__PURE__ */ memo(() => window.ScrollTimeline !== undefined);
137
134
 
138
- class BaseGroupPlaybackControls {
135
+ class GroupAnimation {
139
136
  constructor(animations) {
140
137
  // Bound to accomodate common `return animation.stop` pattern
141
138
  this.stop = () => this.runAll("stop");
142
139
  this.animations = animations.filter(Boolean);
143
140
  }
144
141
  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));
142
+ return Promise.all(this.animations.map((animation) => animation.finished));
147
143
  }
148
144
  /**
149
145
  * TODO: Filter out cancelled or stopped animations before returning
@@ -214,156 +210,122 @@
214
210
  }
215
211
  }
216
212
 
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);
224
- }
225
- }
226
-
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);
213
+ class GroupAnimationWithThen extends GroupAnimation {
214
+ then(onResolve, _onReject) {
215
+ return this.finished.finally(onResolve).then(() => { });
247
216
  }
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
217
  }
265
218
 
266
- function isGenerator(type) {
267
- return typeof type === "function";
268
- }
219
+ const isCSSVar = (name) => name.startsWith("--");
220
+ const style = {
221
+ set: (element, name, value) => {
222
+ isCSSVar(name)
223
+ ? element.style.setProperty(name, value)
224
+ : (element.style[name] = value);
225
+ },
226
+ get: (element, name) => {
227
+ return isCSSVar(name)
228
+ ? element.style.getPropertyValue(name)
229
+ : element.style[name];
230
+ },
231
+ };
269
232
 
270
- function attachTimeline(animation, timeline) {
271
- animation.timeline = timeline;
272
- animation.onfinish = null;
233
+ const isNotNull$1 = (value) => value !== null;
234
+ function getFinalKeyframe$1(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
235
+ const resolvedKeyframes = keyframes.filter(isNotNull$1);
236
+ const index = repeat && repeatType !== "loop" && repeat % 2 === 1
237
+ ? 0
238
+ : resolvedKeyframes.length - 1;
239
+ return !index || finalKeyframe === undefined
240
+ ? resolvedKeyframes[index]
241
+ : finalKeyframe;
273
242
  }
274
243
 
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();
244
+ const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
245
+ try {
246
+ document.createElement("div").animate({ opacity: [1] });
314
247
  }
315
- play() {
316
- this.animation && this.animation.play();
248
+ catch (e) {
249
+ return false;
317
250
  }
318
- pause() {
319
- this.animation && this.animation.pause();
251
+ return true;
252
+ });
253
+
254
+ const pxValues = new Set([
255
+ // Border props
256
+ "borderWidth",
257
+ "borderTopWidth",
258
+ "borderRightWidth",
259
+ "borderBottomWidth",
260
+ "borderLeftWidth",
261
+ "borderRadius",
262
+ "radius",
263
+ "borderTopLeftRadius",
264
+ "borderTopRightRadius",
265
+ "borderBottomRightRadius",
266
+ "borderBottomLeftRadius",
267
+ // Positioning props
268
+ "width",
269
+ "maxWidth",
270
+ "height",
271
+ "maxHeight",
272
+ "top",
273
+ "right",
274
+ "bottom",
275
+ "left",
276
+ // Spacing props
277
+ "padding",
278
+ "paddingTop",
279
+ "paddingRight",
280
+ "paddingBottom",
281
+ "paddingLeft",
282
+ "margin",
283
+ "marginTop",
284
+ "marginRight",
285
+ "marginBottom",
286
+ "marginLeft",
287
+ // Misc
288
+ "backgroundPositionX",
289
+ "backgroundPositionY",
290
+ ]);
291
+
292
+ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
293
+ if (!Array.isArray(keyframes)) {
294
+ keyframes = [keyframes];
320
295
  }
321
- stop() {
322
- if (!this.animation ||
323
- this.state === "idle" ||
324
- this.state === "finished") {
325
- return;
296
+ for (let i = 0; i < keyframes.length; i++) {
297
+ if (keyframes[i] === null) {
298
+ keyframes[i] =
299
+ i === 0 && !pseudoElement
300
+ ? style.get(element, name)
301
+ : keyframes[i - 1];
326
302
  }
327
- if (this.animation.commitStyles) {
328
- this.animation.commitStyles();
303
+ if (typeof keyframes[i] === "number" && pxValues.has(name)) {
304
+ keyframes[i] = keyframes[i] + "px";
329
305
  }
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
- }
343
- complete() {
344
- this.animation && this.animation.finish();
345
306
  }
346
- cancel() {
347
- try {
348
- this.animation && this.animation.cancel();
349
- }
350
- catch (e) { }
307
+ if (!pseudoElement && !supportsPartialKeyframes() && keyframes.length < 2) {
308
+ keyframes.unshift(style.get(element, name));
351
309
  }
310
+ return keyframes;
352
311
  }
353
312
 
313
+ const statsBuffer = {
314
+ value: null,
315
+ addProjectionMetrics: null,
316
+ };
317
+
354
318
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
355
319
 
356
320
  /**
357
321
  * Add the ability for test suites to manually set support flags
358
322
  * to better test more environments.
359
323
  */
360
- const supportsFlags = {
361
- linearEasing: undefined,
362
- };
324
+ const supportsFlags = {};
363
325
 
364
326
  function memoSupports(callback, supportsFlag) {
365
327
  const memoized = memo(callback);
366
- return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
328
+ return () => supportsFlags[supportsFlag] ?? memoized();
367
329
  }
368
330
 
369
331
  const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
@@ -384,20 +346,13 @@
384
346
  let points = "";
385
347
  const numPoints = Math.max(Math.round(duration / resolution), 2);
386
348
  for (let i = 0; i < numPoints; i++) {
387
- points += easing(progress(0, numPoints - 1, i)) + ", ";
349
+ points += easing(i / (numPoints - 1)) + ", ";
388
350
  }
389
351
  return `linear(${points.substring(0, points.length - 2)})`;
390
352
  };
391
353
 
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
354
  const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
355
+
401
356
  const supportedWaapiEasing = {
402
357
  linear: "linear",
403
358
  ease: "ease",
@@ -409,6 +364,7 @@
409
364
  backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
410
365
  backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
411
366
  };
367
+
412
368
  function mapEasingToNativeEasing(easing, duration) {
413
369
  if (!easing) {
414
370
  return undefined;
@@ -428,6 +384,247 @@
428
384
  }
429
385
  }
430
386
 
387
+ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
388
+ const keyframeOptions = {
389
+ [valueName]: keyframes,
390
+ };
391
+ if (times)
392
+ keyframeOptions.offset = times;
393
+ const easing = mapEasingToNativeEasing(ease, duration);
394
+ /**
395
+ * If this is an easing array, apply to keyframes, not animation as a whole
396
+ */
397
+ if (Array.isArray(easing))
398
+ keyframeOptions.easing = easing;
399
+ const animation = element.animate(keyframeOptions, {
400
+ delay,
401
+ duration,
402
+ easing: !Array.isArray(easing) ? easing : "linear",
403
+ fill: "both",
404
+ iterations: repeat + 1,
405
+ direction: repeatType === "reverse" ? "alternate" : "normal",
406
+ pseudoElement,
407
+ });
408
+ return animation;
409
+ }
410
+
411
+ function isGenerator(type) {
412
+ return typeof type === "function" && "applyToOptions" in type;
413
+ }
414
+
415
+ function applyGeneratorOptions({ type, ...options }) {
416
+ if (isGenerator(type)) {
417
+ return type.applyToOptions(options);
418
+ }
419
+ else {
420
+ options.duration ?? (options.duration = 300);
421
+ options.ease ?? (options.ease = "easeOut");
422
+ }
423
+ return options;
424
+ }
425
+
426
+ const animationMaps = new WeakMap();
427
+ const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
428
+ function getAnimationMap(element) {
429
+ const map = animationMaps.get(element) || new Map();
430
+ animationMaps.set(element, map);
431
+ return map;
432
+ }
433
+ /**
434
+ * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
435
+ */
436
+ class NativeAnimation {
437
+ constructor(options) {
438
+ /**
439
+ * If we already have an animation, we don't need to instantiate one
440
+ * and can just use this as a controls interface.
441
+ */
442
+ if ("animation" in options) {
443
+ this.animation = options.animation;
444
+ return;
445
+ }
446
+ const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
447
+ let { transition } = options;
448
+ this.allowFlatten = allowFlatten;
449
+ /**
450
+ * Stop any existing animations on the element before reading existing keyframes.
451
+ *
452
+ * TODO: Check for VisualElement before using animation state. This is a fallback
453
+ * for mini animate(). Do this when implementing NativeAnimationExtended.
454
+ */
455
+ const animationMap = getAnimationMap(element);
456
+ const key = animationMapKey(name, pseudoElement || "");
457
+ const currentAnimation = animationMap.get(key);
458
+ currentAnimation && currentAnimation.stop();
459
+ /**
460
+ * TODO: If these keyframes aren't correctly hydrated then we want to throw
461
+ * run an instant animation.
462
+ */
463
+ const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
464
+ exports.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
465
+ transition = applyGeneratorOptions(transition);
466
+ this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
467
+ if (transition.autoplay === false) {
468
+ this.animation.pause();
469
+ }
470
+ this.removeAnimation = () => animationMap.delete(key);
471
+ this.animation.onfinish = () => {
472
+ if (!pseudoElement) {
473
+ style.set(element, name, getFinalKeyframe$1(keyframes, transition));
474
+ }
475
+ else {
476
+ this.commitStyles();
477
+ }
478
+ this.cancel();
479
+ };
480
+ /**
481
+ * TODO: Check for VisualElement before using animation state.
482
+ */
483
+ animationMap.set(key, this);
484
+ }
485
+ play() {
486
+ this.animation.play();
487
+ }
488
+ pause() {
489
+ this.animation.pause();
490
+ }
491
+ complete() {
492
+ this.animation.finish();
493
+ }
494
+ cancel() {
495
+ try {
496
+ this.animation.cancel();
497
+ }
498
+ catch (e) { }
499
+ this.removeAnimation();
500
+ }
501
+ stop() {
502
+ const { state } = this;
503
+ if (state === "idle" || state === "finished") {
504
+ return;
505
+ }
506
+ this.commitStyles();
507
+ this.cancel();
508
+ }
509
+ /**
510
+ * WAAPI doesn't natively have any interruption capabilities.
511
+ *
512
+ * In this method, we commit styles back to the DOM before cancelling
513
+ * the animation.
514
+ *
515
+ * This is designed to be overridden by NativeAnimationExtended, which
516
+ * will create a renderless JS animation and sample it twice to calculate
517
+ * its current value, "previous" value, and therefore allow
518
+ * Motion to also correctly calculate velocity for any subsequent animation
519
+ * while deferring the commit until the next animation frame.
520
+ */
521
+ commitStyles() {
522
+ this.animation.commitStyles?.();
523
+ }
524
+ get duration() {
525
+ console.log(this.animation.effect?.getComputedTiming());
526
+ const duration = this.animation.effect?.getComputedTiming().duration || 0;
527
+ return millisecondsToSeconds(Number(duration));
528
+ }
529
+ get time() {
530
+ return millisecondsToSeconds(Number(this.animation.currentTime) || 0);
531
+ }
532
+ set time(newTime) {
533
+ this.animation.currentTime = secondsToMilliseconds(newTime);
534
+ }
535
+ /**
536
+ * The playback speed of the animation.
537
+ * 1 = normal speed, 2 = double speed, 0.5 = half speed.
538
+ */
539
+ get speed() {
540
+ return this.animation.playbackRate;
541
+ }
542
+ set speed(newSpeed) {
543
+ this.animation.playbackRate = newSpeed;
544
+ }
545
+ get state() {
546
+ return this.animation.playState;
547
+ }
548
+ get startTime() {
549
+ return Number(this.animation.startTime);
550
+ }
551
+ get finished() {
552
+ return this.animation.finished;
553
+ }
554
+ flatten() {
555
+ if (this.allowFlatten) {
556
+ this.animation.effect?.updateTiming({ easing: "linear" });
557
+ }
558
+ }
559
+ /**
560
+ * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
561
+ */
562
+ attachTimeline(timeline) {
563
+ this.animation.timeline = timeline;
564
+ this.animation.onfinish = null;
565
+ return noop;
566
+ }
567
+ /**
568
+ * Allows the animation to be awaited.
569
+ *
570
+ * @deprecated Use `finished` instead.
571
+ */
572
+ then(onResolve, onReject) {
573
+ return this.finished.then(onResolve).catch(onReject);
574
+ }
575
+ }
576
+
577
+ function getValueTransition$1(transition, key) {
578
+ return (transition?.[key] ??
579
+ transition?.["default"] ??
580
+ transition);
581
+ }
582
+
583
+ /**
584
+ * Implement a practical max duration for keyframe generation
585
+ * to prevent infinite loops
586
+ */
587
+ const maxGeneratorDuration = 20000;
588
+ function calcGeneratorDuration(generator) {
589
+ let duration = 0;
590
+ const timeStep = 50;
591
+ let state = generator.next(duration);
592
+ while (!state.done && duration < maxGeneratorDuration) {
593
+ duration += timeStep;
594
+ state = generator.next(duration);
595
+ }
596
+ return duration >= maxGeneratorDuration ? Infinity : duration;
597
+ }
598
+
599
+ /**
600
+ * Create a progress => progress easing function from a generator.
601
+ */
602
+ function createGeneratorEasing(options, scale = 100, createGenerator) {
603
+ const generator = createGenerator({ ...options, keyframes: [0, scale] });
604
+ const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
605
+ return {
606
+ type: "keyframes",
607
+ ease: (progress) => {
608
+ return generator.next(duration * progress).value / scale;
609
+ },
610
+ duration: millisecondsToSeconds(duration),
611
+ };
612
+ }
613
+
614
+ function isWaapiSupportedEasing(easing) {
615
+ return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
616
+ !easing ||
617
+ (typeof easing === "string" &&
618
+ (easing in supportedWaapiEasing || supportsLinearEasing())) ||
619
+ isBezierDefinition(easing) ||
620
+ (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
621
+ }
622
+
623
+ function attachTimeline(animation, timeline) {
624
+ animation.timeline = timeline;
625
+ animation.onfinish = null;
626
+ }
627
+
431
628
  const stepsOrder = [
432
629
  "read", // Read
433
630
  "resolveKeyframes", // Write/Read/Write/Read
@@ -437,11 +634,6 @@
437
634
  "postRender", // Compute
438
635
  ];
439
636
 
440
- const statsBuffer = {
441
- value: null,
442
- addProjectionMetrics: null,
443
- };
444
-
445
637
  function createRenderStep(runNextFrame, stepName) {
446
638
  /**
447
639
  * We create and reuse two queues, one to queue jobs for the current frame
@@ -547,9 +739,11 @@
547
739
  }, {});
548
740
  const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
549
741
  const processBatch = () => {
550
- const timestamp = performance.now();
742
+ const timestamp = MotionGlobalConfig.useManualTiming
743
+ ? state.timestamp
744
+ : performance.now();
551
745
  runNextFrame = false;
552
- {
746
+ if (!MotionGlobalConfig.useManualTiming) {
553
747
  state.delta = useDefaultElapsed
554
748
  ? 1000 / 60
555
749
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed$1), 1);
@@ -631,21 +825,16 @@
631
825
  }
632
826
 
633
827
  function resolveElements(elementOrSelector, scope, selectorCache) {
634
- var _a;
635
828
  if (elementOrSelector instanceof EventTarget) {
636
829
  return [elementOrSelector];
637
830
  }
638
831
  else if (typeof elementOrSelector === "string") {
639
832
  let root = document;
640
833
  if (scope) {
641
- // TODO: Refactor to utils package
642
- // invariant(
643
- // Boolean(scope.current),
644
- // "Scope provided, but no element detected."
645
- // )
646
834
  root = scope.current;
647
835
  }
648
- const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
836
+ const elements = selectorCache?.[elementOrSelector] ??
837
+ root.querySelectorAll(elementOrSelector);
649
838
  return elements ? Array.from(elements) : [];
650
839
  }
651
840
  return Array.from(elementOrSelector);
@@ -844,7 +1033,7 @@
844
1033
  if (target instanceof HTMLElement) {
845
1034
  target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
846
1035
  if (!isElementKeyboardAccessible(target) &&
847
- target.tabIndex === null) {
1036
+ !target.hasAttribute("tabindex")) {
848
1037
  target.tabIndex = 0;
849
1038
  }
850
1039
  }
@@ -877,7 +1066,7 @@
877
1066
  * This will be replaced by the build step with the latest version number.
878
1067
  * When MotionValues are provided to motion components, warn if versions are mixed.
879
1068
  */
880
- this.version = "12.6.3-alpha.0";
1069
+ this.version = "12.6.4-alpha.0";
881
1070
  /**
882
1071
  * Tracks whether this value can output a velocity. Currently this is only true
883
1072
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1426,9 +1615,17 @@
1426
1615
  const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
1427
1616
  return calculatedDuration + "ms " + easing;
1428
1617
  },
1618
+ toTransition: () => { },
1429
1619
  };
1430
1620
  return generator;
1431
1621
  }
1622
+ spring.applyToOptions = (options) => {
1623
+ const generatorOptions = createGeneratorEasing(options, 100, spring);
1624
+ options.ease = supportsLinearEasing() ? generatorOptions.ease : "easeOut";
1625
+ options.duration = secondsToMilliseconds(generatorOptions.duration);
1626
+ options.type = "keyframes";
1627
+ return options;
1628
+ };
1432
1629
 
1433
1630
  const wrap = (min, max, v) => {
1434
1631
  const rangeSize = max - min;
@@ -1512,7 +1709,6 @@
1512
1709
  * calculate an absolute time for the next keyframes.
1513
1710
  */
1514
1711
  function calcNextTime(current, next, prev, labels) {
1515
- var _a;
1516
1712
  if (typeof next === "number") {
1517
1713
  return next;
1518
1714
  }
@@ -1523,7 +1719,7 @@
1523
1719
  return prev;
1524
1720
  }
1525
1721
  else {
1526
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
1722
+ return labels.get(next) ?? current;
1527
1723
  }
1528
1724
  }
1529
1725
 
@@ -1636,7 +1832,7 @@
1636
1832
  const numKeyframes = valueKeyframesAsList.length;
1637
1833
  const createGenerator = isGenerator(type)
1638
1834
  ? type
1639
- : generators === null || generators === void 0 ? void 0 : generators[type];
1835
+ : generators?.[type];
1640
1836
  if (numKeyframes <= 2 && createGenerator) {
1641
1837
  /**
1642
1838
  * As we're creating an easing function from a spring,
@@ -1658,7 +1854,7 @@
1658
1854
  ease = springEasing.ease;
1659
1855
  duration = springEasing.duration;
1660
1856
  }
1661
- duration !== null && duration !== void 0 ? duration : (duration = defaultDuration);
1857
+ duration ?? (duration = defaultDuration);
1662
1858
  const startTime = currentTime + calculatedDelay;
1663
1859
  /**
1664
1860
  * If there's only one time offset of 0, fill in a second with length 1
@@ -1867,7 +2063,7 @@
1867
2063
 
1868
2064
  function getValueState(visualElement) {
1869
2065
  const state = [{}, {}];
1870
- visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
2066
+ visualElement?.values.forEach((value, key) => {
1871
2067
  state[0][key] = value.get();
1872
2068
  state[1][key] = value.getVelocity();
1873
2069
  });
@@ -1940,11 +2136,6 @@
1940
2136
  if (isWillChangeMotionValue(willChange)) {
1941
2137
  return willChange.add(key);
1942
2138
  }
1943
- else if (!willChange && MotionGlobalConfig.WillChange) {
1944
- const newWillChange = new MotionGlobalConfig.WillChange("auto");
1945
- visualElement.addValue("willChange", newWillChange);
1946
- newWillChange.add(key);
1947
- }
1948
2139
  }
1949
2140
 
1950
2141
  /**
@@ -2204,11 +2395,10 @@
2204
2395
  const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
2205
2396
 
2206
2397
  function test(v) {
2207
- var _a, _b;
2208
2398
  return (isNaN(v) &&
2209
2399
  typeof v === "string" &&
2210
- (((_a = v.match(floatRegex)) === null || _a === void 0 ? void 0 : _a.length) || 0) +
2211
- (((_b = v.match(colorRegex)) === null || _b === void 0 ? void 0 : _b.length) || 0) >
2400
+ (v.match(floatRegex)?.length || 0) +
2401
+ (v.match(colorRegex)?.length || 0) >
2212
2402
  0);
2213
2403
  }
2214
2404
  const NUMBER_TOKEN = "number";
@@ -2596,8 +2786,7 @@
2596
2786
  const restore = transformsToRestore.get(element);
2597
2787
  if (restore) {
2598
2788
  restore.forEach(([key, value]) => {
2599
- var _a;
2600
- (_a = element.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(value);
2789
+ element.getValue(key)?.set(value);
2601
2790
  });
2602
2791
  }
2603
2792
  });
@@ -2684,7 +2873,7 @@
2684
2873
  * If the first keyframe is null, we need to find its value by sampling the element
2685
2874
  */
2686
2875
  if (i === 0) {
2687
- const currentValue = motionValue === null || motionValue === void 0 ? void 0 : motionValue.get();
2876
+ const currentValue = motionValue?.get();
2688
2877
  const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
2689
2878
  if (currentValue !== undefined) {
2690
2879
  unresolvedKeyframes[0] = currentValue;
@@ -2765,7 +2954,7 @@
2765
2954
  if (!match)
2766
2955
  return [,];
2767
2956
  const [, token1, token2, fallback] = match;
2768
- return [`--${token1 !== null && token1 !== void 0 ? token1 : token2}`, fallback];
2957
+ return [`--${token1 ?? token2}`, fallback];
2769
2958
  }
2770
2959
  const maxDepth = 4;
2771
2960
  function getVariableValue(current, element, depth = 1) {
@@ -2904,7 +3093,6 @@
2904
3093
  }
2905
3094
  }
2906
3095
  measureEndState() {
2907
- var _a;
2908
3096
  const { element, name, unresolvedKeyframes } = this;
2909
3097
  if (!element || !element.current)
2910
3098
  return;
@@ -2917,7 +3105,7 @@
2917
3105
  this.finalKeyframe = finalKeyframe;
2918
3106
  }
2919
3107
  // If we removed transform values, reapply them before the next render
2920
- if ((_a = this.removedTransforms) === null || _a === void 0 ? void 0 : _a.length) {
3108
+ if (this.removedTransforms?.length) {
2921
3109
  this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
2922
3110
  element
2923
3111
  .getValue(unsetTransformName)
@@ -3273,13 +3461,12 @@
3273
3461
  };
3274
3462
  }
3275
3463
  function matchOrder(origin, target) {
3276
- var _a;
3277
3464
  const orderedOrigin = [];
3278
3465
  const pointers = { color: 0, var: 0, number: 0 };
3279
3466
  for (let i = 0; i < target.values.length; i++) {
3280
3467
  const type = target.types[i];
3281
3468
  const originIndex = origin.indexes[type][pointers[type]];
3282
- const originValue = (_a = origin.values[originIndex]) !== null && _a !== void 0 ? _a : 0;
3469
+ const originValue = origin.values[originIndex] ?? 0;
3283
3470
  orderedOrigin[i] = originValue;
3284
3471
  pointers[type]++;
3285
3472
  }
@@ -3434,7 +3621,7 @@
3434
3621
 
3435
3622
  function createMixers(output, ease, customMixer) {
3436
3623
  const mixers = [];
3437
- const mixerFactory = customMixer || mix;
3624
+ const mixerFactory = customMixer || MotionGlobalConfig.mix || mix;
3438
3625
  const numMixers = output.length - 1;
3439
3626
  for (let i = 0; i < numMixers; i++) {
3440
3627
  let mixer = mixerFactory(output[i], output[i + 1]);
@@ -3506,7 +3693,7 @@
3506
3693
  return offset.map((o) => o * duration);
3507
3694
  }
3508
3695
 
3509
- function defaultEasing$1(values, easing) {
3696
+ function defaultEasing(values, easing) {
3510
3697
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
3511
3698
  }
3512
3699
  function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
@@ -3537,7 +3724,7 @@
3537
3724
  const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
3538
3725
  ease: Array.isArray(easingFunctions)
3539
3726
  ? easingFunctions
3540
- : defaultEasing$1(keyframeValues, easingFunctions),
3727
+ : defaultEasing(keyframeValues, easingFunctions),
3541
3728
  });
3542
3729
  return {
3543
3730
  calculatedDuration: duration,
@@ -3619,7 +3806,7 @@
3619
3806
  onStop && onStop();
3620
3807
  };
3621
3808
  const { name, motionValue, element, keyframes } = this.options;
3622
- const KeyframeResolver$1 = (element === null || element === void 0 ? void 0 : element.KeyframeResolver) || KeyframeResolver;
3809
+ const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
3623
3810
  const onResolved = (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe);
3624
3811
  this.resolver = new KeyframeResolver$1(keyframes, onResolved, name, motionValue, element);
3625
3812
  this.resolver.scheduleResolve();
@@ -3867,7 +4054,7 @@
3867
4054
  this.startTime = now - this.holdTime;
3868
4055
  }
3869
4056
  else if (!this.startTime) {
3870
- this.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4057
+ this.startTime = startTime ?? this.calcStartTime();
3871
4058
  }
3872
4059
  else if (this.state === "finished") {
3873
4060
  this.startTime = now;
@@ -3885,13 +4072,12 @@
3885
4072
  this.driver.start();
3886
4073
  }
3887
4074
  pause() {
3888
- var _a;
3889
4075
  if (!this._resolved) {
3890
4076
  this.pendingPlayState = "paused";
3891
4077
  return;
3892
4078
  }
3893
4079
  this.state = "paused";
3894
- this.holdTime = (_a = this.currentTime) !== null && _a !== void 0 ? _a : 0;
4080
+ this.holdTime = this.currentTime ?? 0;
3895
4081
  }
3896
4082
  complete() {
3897
4083
  if (this.state !== "running") {
@@ -3931,6 +4117,9 @@
3931
4117
  this.startTime = 0;
3932
4118
  return this.tick(time, true);
3933
4119
  }
4120
+ get finished() {
4121
+ return this.currentFinishedPromise;
4122
+ }
3934
4123
  }
3935
4124
 
3936
4125
  /**
@@ -3946,27 +4135,6 @@
3946
4135
  // "background-color"
3947
4136
  ]);
3948
4137
 
3949
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
3950
- const keyframeOptions = { [valueName]: keyframes };
3951
- if (times)
3952
- keyframeOptions.offset = times;
3953
- const easing = mapEasingToNativeEasing(ease, duration);
3954
- /**
3955
- * If this is an easing array, apply to keyframes, not animation as a whole
3956
- */
3957
- if (Array.isArray(easing))
3958
- keyframeOptions.easing = easing;
3959
- const animation = element.animate(keyframeOptions, {
3960
- delay,
3961
- duration,
3962
- easing: !Array.isArray(easing) ? easing : "linear",
3963
- fill: "both",
3964
- iterations: repeat + 1,
3965
- direction: repeatType === "reverse" ? "alternate" : "normal",
3966
- });
3967
- return animation;
3968
- }
3969
-
3970
4138
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
3971
4139
 
3972
4140
  /**
@@ -4077,7 +4245,7 @@
4077
4245
  const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
4078
4246
  // Override the browser calculated startTime with one synchronised to other JS
4079
4247
  // and WAAPI animations starting this event loop.
4080
- animation.startTime = startTime !== null && startTime !== void 0 ? startTime : this.calcStartTime();
4248
+ animation.startTime = startTime ?? this.calcStartTime();
4081
4249
  if (this.pendingTimeline) {
4082
4250
  attachTimeline(animation, this.pendingTimeline);
4083
4251
  this.pendingTimeline = undefined;
@@ -4136,6 +4304,9 @@
4136
4304
  const { animation } = resolved;
4137
4305
  return animation.playbackRate;
4138
4306
  }
4307
+ get finished() {
4308
+ return this.resolved.animation.finished;
4309
+ }
4139
4310
  set speed(newSpeed) {
4140
4311
  const { resolved } = this;
4141
4312
  if (!resolved)
@@ -4382,6 +4553,11 @@
4382
4553
  shouldSkip = true;
4383
4554
  }
4384
4555
  }
4556
+ if (MotionGlobalConfig.skipAnimations) {
4557
+ shouldSkip = true;
4558
+ options.duration = 0;
4559
+ options.delay = 0;
4560
+ }
4385
4561
  /**
4386
4562
  * If the transition type or easing has been explicitly set by the user
4387
4563
  * then we don't want to allow flattening the animation.
@@ -4401,7 +4577,7 @@
4401
4577
  });
4402
4578
  // We still want to return some animation controls here rather
4403
4579
  // than returning undefined
4404
- return new GroupPlaybackControls([]);
4580
+ return new GroupAnimationWithThen([]);
4405
4581
  }
4406
4582
  }
4407
4583
  /**
@@ -4429,7 +4605,6 @@
4429
4605
  return shouldBlock;
4430
4606
  }
4431
4607
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
4432
- var _a;
4433
4608
  let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
4434
4609
  if (transitionOverride)
4435
4610
  transition = transitionOverride;
@@ -4438,7 +4613,7 @@
4438
4613
  visualElement.animationState &&
4439
4614
  visualElement.animationState.getState()[type];
4440
4615
  for (const key in target) {
4441
- const value = visualElement.getValue(key, (_a = visualElement.latestValues[key]) !== null && _a !== void 0 ? _a : null);
4616
+ const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
4442
4617
  const valueTarget = target[key];
4443
4618
  if (valueTarget === undefined ||
4444
4619
  (animationTypeState &&
@@ -4597,7 +4772,7 @@
4597
4772
  * and warn against mismatches.
4598
4773
  */
4599
4774
  {
4600
- warnOnce(nextValue.version === "12.6.3-alpha.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.3-alpha.0 may not work as expected.`);
4775
+ warnOnce(nextValue.version === "12.6.4-alpha.0", `Attempting to mix Motion versions ${nextValue.version} with 12.6.4-alpha.0 may not work as expected.`);
4601
4776
  }
4602
4777
  }
4603
4778
  else if (isMotionValue(prevValue)) {
@@ -5021,10 +5196,10 @@
5021
5196
  * directly from the instance (which might have performance implications).
5022
5197
  */
5023
5198
  readValue(key, target) {
5024
- var _a;
5025
5199
  let value = this.latestValues[key] !== undefined || !this.current
5026
5200
  ? this.latestValues[key]
5027
- : (_a = this.getBaseTargetFromProps(this.props, key)) !== null && _a !== void 0 ? _a : this.readValueFromInstance(this.current, key, this.options);
5201
+ : this.getBaseTargetFromProps(this.props, key) ??
5202
+ this.readValueFromInstance(this.current, key, this.options);
5028
5203
  if (value !== undefined && value !== null) {
5029
5204
  if (typeof value === "string" &&
5030
5205
  (isNumericalString(value) || isZeroValueString(value))) {
@@ -5050,11 +5225,10 @@
5050
5225
  * props.
5051
5226
  */
5052
5227
  getBaseTarget(key) {
5053
- var _a;
5054
5228
  const { initial } = this.props;
5055
5229
  let valueFromInitial;
5056
5230
  if (typeof initial === "string" || typeof initial === "object") {
5057
- const variant = resolveVariantFromProps(this.props, initial, (_a = this.presenceContext) === null || _a === void 0 ? void 0 : _a.custom);
5231
+ const variant = resolveVariantFromProps(this.props, initial, this.presenceContext?.custom);
5058
5232
  if (variant) {
5059
5233
  valueFromInitial = variant[key];
5060
5234
  }
@@ -5421,7 +5595,6 @@
5421
5595
  }
5422
5596
 
5423
5597
  function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
5424
- var _a;
5425
5598
  const { style } = props;
5426
5599
  const newValues = {};
5427
5600
  for (const key in style) {
@@ -5429,7 +5602,7 @@
5429
5602
  (prevProps.style &&
5430
5603
  isMotionValue(prevProps.style[key])) ||
5431
5604
  isForcedMotionValue(key, props) ||
5432
- ((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
5605
+ visualElement?.getValue(key)?.liveStyle !== undefined) {
5433
5606
  newValues[key] = style[key];
5434
5607
  }
5435
5608
  }
@@ -5708,7 +5881,7 @@
5708
5881
  else {
5709
5882
  animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
5710
5883
  }
5711
- const animation = new GroupPlaybackControls(animations);
5884
+ const animation = new GroupAnimationWithThen(animations);
5712
5885
  if (scope) {
5713
5886
  scope.animations.push(animation);
5714
5887
  }
@@ -5718,125 +5891,6 @@
5718
5891
  }
5719
5892
  const animate = createScopedAnimate();
5720
5893
 
5721
- function setCSSVar(element, name, value) {
5722
- element.style.setProperty(name, value);
5723
- }
5724
- function setStyle(element, name, value) {
5725
- element.style[name] = value;
5726
- }
5727
-
5728
- const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
5729
- try {
5730
- document.createElement("div").animate({ opacity: [1] });
5731
- }
5732
- catch (e) {
5733
- return false;
5734
- }
5735
- return true;
5736
- });
5737
-
5738
- const state = new WeakMap();
5739
- function hydrateKeyframes(valueName, keyframes, read) {
5740
- for (let i = 0; i < keyframes.length; i++) {
5741
- if (keyframes[i] === null) {
5742
- keyframes[i] = i === 0 ? read() : keyframes[i - 1];
5743
- }
5744
- if (typeof keyframes[i] === "number" &&
5745
- browserNumberValueTypes[valueName]) {
5746
- keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
5747
- }
5748
- }
5749
- if (!supportsPartialKeyframes() && keyframes.length < 2) {
5750
- keyframes.unshift(read());
5751
- }
5752
- }
5753
- const defaultEasing = "easeOut";
5754
- function getElementAnimationState(element) {
5755
- const animationState = state.get(element) || new Map();
5756
- state.set(element, animationState);
5757
- return state.get(element);
5758
- }
5759
- class NativeAnimation extends NativeAnimationControls {
5760
- constructor(element, valueName, valueKeyframes, options) {
5761
- const isCSSVar = valueName.startsWith("--");
5762
- exports.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
5763
- const existingAnimation = getElementAnimationState(element).get(valueName);
5764
- existingAnimation && existingAnimation.stop();
5765
- const readInitialKeyframe = () => {
5766
- return valueName.startsWith("--")
5767
- ? element.style.getPropertyValue(valueName)
5768
- : window.getComputedStyle(element)[valueName];
5769
- };
5770
- if (!Array.isArray(valueKeyframes)) {
5771
- valueKeyframes = [valueKeyframes];
5772
- }
5773
- hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
5774
- // TODO: Replace this with toString()?
5775
- if (isGenerator(options.type)) {
5776
- const generatorOptions = createGeneratorEasing(options, 100, options.type);
5777
- options.ease = supportsLinearEasing()
5778
- ? generatorOptions.ease
5779
- : defaultEasing;
5780
- options.duration = secondsToMilliseconds(generatorOptions.duration);
5781
- options.type = "keyframes";
5782
- }
5783
- else {
5784
- options.ease = options.ease || defaultEasing;
5785
- }
5786
- const onFinish = () => {
5787
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
5788
- this.cancel();
5789
- this.resolveFinishedPromise();
5790
- };
5791
- const init = () => {
5792
- this.setValue = isCSSVar ? setCSSVar : setStyle;
5793
- this.options = options;
5794
- this.updateFinishedPromise();
5795
- this.removeAnimation = () => {
5796
- const elementState = state.get(element);
5797
- elementState && elementState.delete(valueName);
5798
- };
5799
- };
5800
- if (!supportsWaapi()) {
5801
- super();
5802
- init();
5803
- onFinish();
5804
- }
5805
- else {
5806
- super(startWaapiAnimation(element, valueName, valueKeyframes, options));
5807
- init();
5808
- if (options.autoplay === false) {
5809
- this.animation.pause();
5810
- }
5811
- this.animation.onfinish = onFinish;
5812
- getElementAnimationState(element).set(valueName, this);
5813
- }
5814
- }
5815
- /**
5816
- * Allows the returned animation to be awaited or promise-chained. Currently
5817
- * resolves when the animation finishes at all but in a future update could/should
5818
- * reject if its cancels.
5819
- */
5820
- then(resolve, reject) {
5821
- return this.currentFinishedPromise.then(resolve, reject);
5822
- }
5823
- updateFinishedPromise() {
5824
- this.currentFinishedPromise = new Promise((resolve) => {
5825
- this.resolveFinishedPromise = resolve;
5826
- });
5827
- }
5828
- play() {
5829
- if (this.state === "finished") {
5830
- this.updateFinishedPromise();
5831
- }
5832
- super.play();
5833
- }
5834
- cancel() {
5835
- this.removeAnimation();
5836
- super.cancel();
5837
- }
5838
- }
5839
-
5840
5894
  function animateElements(elementOrSelector, keyframes, options, scope) {
5841
5895
  const elements = resolveElements(elementOrSelector, scope);
5842
5896
  const numElements = elements.length;
@@ -5856,13 +5910,15 @@
5856
5910
  const valueOptions = {
5857
5911
  ...getValueTransition$1(elementTransition, valueName),
5858
5912
  };
5859
- valueOptions.duration = valueOptions.duration
5860
- ? secondsToMilliseconds(valueOptions.duration)
5861
- : valueOptions.duration;
5862
- valueOptions.delay = secondsToMilliseconds(valueOptions.delay || 0);
5863
- valueOptions.allowFlatten =
5864
- !elementTransition.type && !elementTransition.ease;
5865
- animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
5913
+ valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));
5914
+ valueOptions.delay && (valueOptions.delay = secondsToMilliseconds(valueOptions.delay));
5915
+ animations.push(new NativeAnimation({
5916
+ element,
5917
+ name: valueName,
5918
+ keyframes: valueKeyframes,
5919
+ transition: valueOptions,
5920
+ allowFlatten: !elementTransition.type && !elementTransition.ease,
5921
+ }));
5866
5922
  }
5867
5923
  }
5868
5924
  return animations;
@@ -5870,7 +5926,7 @@
5870
5926
 
5871
5927
  const createScopedWaapiAnimate = (scope) => {
5872
5928
  function scopedAnimate(elementOrSelector, keyframes, options) {
5873
- return new GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
5929
+ return new GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
5874
5930
  }
5875
5931
  return scopedAnimate;
5876
5932
  };
@@ -5909,8 +5965,7 @@
5909
5965
  }
5910
5966
  }
5911
5967
  function notifyTarget({ target, contentRect, borderBoxSize, }) {
5912
- var _a;
5913
- (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
5968
+ resizeHandlers.get(target)?.forEach((handler) => {
5914
5969
  handler({
5915
5970
  target,
5916
5971
  contentSize: contentRect,
@@ -5939,14 +5994,14 @@
5939
5994
  resizeHandlers.set(element, elementHandlers);
5940
5995
  }
5941
5996
  elementHandlers.add(handler);
5942
- observer === null || observer === void 0 ? void 0 : observer.observe(element);
5997
+ observer?.observe(element);
5943
5998
  });
5944
5999
  return () => {
5945
6000
  elements.forEach((element) => {
5946
6001
  const elementHandlers = resizeHandlers.get(element);
5947
- elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
5948
- if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
5949
- observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
6002
+ elementHandlers?.delete(handler);
6003
+ if (!elementHandlers?.size) {
6004
+ observer?.unobserve(element);
5950
6005
  }
5951
6006
  });
5952
6007
  };
@@ -6325,7 +6380,6 @@
6325
6380
  const listener = scrollListeners.get(container);
6326
6381
  frame.read(listener, false, true);
6327
6382
  return () => {
6328
- var _a;
6329
6383
  cancelFrame(listener);
6330
6384
  /**
6331
6385
  * Check if we even have any handlers for this container.
@@ -6343,7 +6397,7 @@
6343
6397
  scrollListeners.delete(container);
6344
6398
  if (scrollListener) {
6345
6399
  getEventTarget(container).removeEventListener("scroll", scrollListener);
6346
- (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
6400
+ resizeListeners.get(container)?.();
6347
6401
  window.removeEventListener("resize", scrollListener);
6348
6402
  }
6349
6403
  };
@@ -6573,6 +6627,7 @@
6573
6627
  exports.frame = frame;
6574
6628
  exports.frameData = frameData;
6575
6629
  exports.hover = hover;
6630
+ exports.hslaToRgba = hslaToRgba;
6576
6631
  exports.inView = inView;
6577
6632
  exports.inertia = inertia;
6578
6633
  exports.interpolate = interpolate;