motion-dom 12.6.1 → 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 (36) hide show
  1. package/dist/cjs/index.js +381 -236
  2. package/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
  3. package/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
  4. package/dist/es/animation/NativeAnimation.mjs +159 -0
  5. package/dist/es/animation/generators/utils/is-generator.mjs +1 -1
  6. package/dist/es/animation/keyframes/get-final.mjs +12 -0
  7. package/dist/es/animation/keyframes/hydrate.mjs +26 -0
  8. package/dist/es/animation/utils/get-value-transition.mjs +3 -5
  9. package/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
  10. package/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
  11. package/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
  12. package/dist/es/animation/waapi/easing/supported.mjs +15 -0
  13. package/dist/es/animation/waapi/start-waapi-animation.mjs +37 -0
  14. package/dist/es/animation/waapi/supports/partial-keyframes.mjs +13 -0
  15. package/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
  16. package/dist/es/animation/waapi/utils/linear.mjs +1 -3
  17. package/dist/es/animation/waapi/utils/px-values.mjs +39 -0
  18. package/dist/es/gestures/press/index.mjs +1 -1
  19. package/dist/es/index.mjs +8 -3
  20. package/dist/es/render/dom/style.mjs +15 -0
  21. package/dist/es/utils/resolve-elements.mjs +2 -7
  22. package/dist/es/utils/supports/flags.mjs +1 -3
  23. package/dist/es/utils/supports/memo.mjs +1 -1
  24. package/dist/es/value/index.mjs +1 -1
  25. package/dist/es/view/queue.mjs +1 -2
  26. package/dist/es/view/start.mjs +22 -17
  27. package/dist/es/view/utils/get-view-animations.mjs +1 -2
  28. package/dist/index.d.ts +90 -43
  29. package/dist/motion-dom.dev.js +381 -236
  30. package/dist/motion-dom.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/es/animation/controls/Group.mjs +0 -13
  33. package/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -83
  34. package/dist/es/animation/waapi/PseudoAnimation.mjs +0 -15
  35. package/dist/es/animation/waapi/utils/convert-options.mjs +0 -55
  36. package/dist/es/animation/waapi/utils/easing.mjs +0 -44
@@ -6,15 +6,14 @@
6
6
 
7
7
  const supportsScrollTimeline = /* @__PURE__ */ motionUtils.memo(() => window.ScrollTimeline !== undefined);
8
8
 
9
- class BaseGroupPlaybackControls {
9
+ class GroupAnimation {
10
10
  constructor(animations) {
11
11
  // Bound to accomodate common `return animation.stop` pattern
12
12
  this.stop = () => this.runAll("stop");
13
13
  this.animations = animations.filter(Boolean);
14
14
  }
15
15
  get finished() {
16
- // Support for new finished Promise and legacy thennable API
17
- return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
16
+ return Promise.all(this.animations.map((animation) => animation.finished));
18
17
  }
19
18
  /**
20
19
  * TODO: Filter out cancelled or stopped animations before returning
@@ -85,156 +84,128 @@
85
84
  }
86
85
  }
87
86
 
88
- /**
89
- * TODO: This is a temporary class to support the legacy
90
- * thennable API
91
- */
92
- class GroupPlaybackControls extends BaseGroupPlaybackControls {
93
- then(onResolve, onReject) {
94
- return Promise.all(this.animations).then(onResolve).catch(onReject);
87
+ class GroupAnimationWithThen extends GroupAnimation {
88
+ then(onResolve, _onReject) {
89
+ return this.finished.finally(onResolve).then(() => { });
95
90
  }
96
91
  }
97
92
 
98
- function getValueTransition(transition, key) {
99
- return transition
100
- ? transition[key] ||
101
- transition["default"] ||
102
- transition
103
- : undefined;
104
- }
105
-
106
- /**
107
- * Implement a practical max duration for keyframe generation
108
- * to prevent infinite loops
109
- */
110
- const maxGeneratorDuration = 20000;
111
- function calcGeneratorDuration(generator) {
112
- let duration = 0;
113
- const timeStep = 50;
114
- let state = generator.next(duration);
115
- while (!state.done && duration < maxGeneratorDuration) {
116
- duration += timeStep;
117
- state = generator.next(duration);
118
- }
119
- return duration >= maxGeneratorDuration ? Infinity : duration;
120
- }
121
-
122
- /**
123
- * Create a progress => progress easing function from a generator.
124
- */
125
- function createGeneratorEasing(options, scale = 100, createGenerator) {
126
- const generator = createGenerator({ ...options, keyframes: [0, scale] });
127
- const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
128
- return {
129
- type: "keyframes",
130
- ease: (progress) => {
131
- return generator.next(duration * progress).value / scale;
132
- },
133
- duration: motionUtils.millisecondsToSeconds(duration),
134
- };
135
- }
136
-
137
- function isGenerator(type) {
138
- return typeof type === "function";
139
- }
93
+ const isCSSVar = (name) => name.startsWith("--");
94
+ const style$1 = {
95
+ set: (element, name, value) => {
96
+ isCSSVar(name)
97
+ ? element.style.setProperty(name, value)
98
+ : (element.style[name] = value);
99
+ },
100
+ get: (element, name) => {
101
+ return isCSSVar(name)
102
+ ? element.style.getPropertyValue(name)
103
+ : element.style[name];
104
+ },
105
+ };
140
106
 
141
- function attachTimeline(animation, timeline) {
142
- animation.timeline = timeline;
143
- animation.onfinish = null;
107
+ const isNotNull = (value) => value !== null;
108
+ function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
109
+ const resolvedKeyframes = keyframes.filter(isNotNull);
110
+ const index = repeat && repeatType !== "loop" && repeat % 2 === 1
111
+ ? 0
112
+ : resolvedKeyframes.length - 1;
113
+ return !index || finalKeyframe === undefined
114
+ ? resolvedKeyframes[index]
115
+ : finalKeyframe;
144
116
  }
145
117
 
146
- class NativeAnimationControls {
147
- constructor(animation) {
148
- this.animation = animation;
149
- }
150
- get duration() {
151
- var _a, _b, _c;
152
- const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
153
- ((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
154
- 300;
155
- return motionUtils.millisecondsToSeconds(Number(durationInMs));
156
- }
157
- get time() {
158
- var _a;
159
- if (this.animation) {
160
- return motionUtils.millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
161
- }
162
- return 0;
163
- }
164
- set time(newTime) {
165
- if (this.animation) {
166
- this.animation.currentTime = motionUtils.secondsToMilliseconds(newTime);
167
- }
168
- }
169
- get speed() {
170
- return this.animation ? this.animation.playbackRate : 1;
171
- }
172
- set speed(newSpeed) {
173
- if (this.animation) {
174
- this.animation.playbackRate = newSpeed;
175
- }
176
- }
177
- get state() {
178
- return this.animation ? this.animation.playState : "finished";
179
- }
180
- get startTime() {
181
- return this.animation ? this.animation.startTime : null;
182
- }
183
- get finished() {
184
- return this.animation ? this.animation.finished : Promise.resolve();
185
- }
186
- play() {
187
- this.animation && this.animation.play();
118
+ const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
119
+ try {
120
+ document.createElement("div").animate({ opacity: [1] });
188
121
  }
189
- pause() {
190
- this.animation && this.animation.pause();
122
+ catch (e) {
123
+ return false;
191
124
  }
192
- stop() {
193
- if (!this.animation ||
194
- this.state === "idle" ||
195
- this.state === "finished") {
196
- return;
125
+ return true;
126
+ });
127
+
128
+ const pxValues = new Set([
129
+ // Border props
130
+ "borderWidth",
131
+ "borderTopWidth",
132
+ "borderRightWidth",
133
+ "borderBottomWidth",
134
+ "borderLeftWidth",
135
+ "borderRadius",
136
+ "radius",
137
+ "borderTopLeftRadius",
138
+ "borderTopRightRadius",
139
+ "borderBottomRightRadius",
140
+ "borderBottomLeftRadius",
141
+ // Positioning props
142
+ "width",
143
+ "maxWidth",
144
+ "height",
145
+ "maxHeight",
146
+ "top",
147
+ "right",
148
+ "bottom",
149
+ "left",
150
+ // Spacing props
151
+ "padding",
152
+ "paddingTop",
153
+ "paddingRight",
154
+ "paddingBottom",
155
+ "paddingLeft",
156
+ "margin",
157
+ "marginTop",
158
+ "marginRight",
159
+ "marginBottom",
160
+ "marginLeft",
161
+ // Misc
162
+ "backgroundPositionX",
163
+ "backgroundPositionY",
164
+ ]);
165
+
166
+ function hydrateKeyframes(element, name, keyframes, pseudoElement) {
167
+ if (!Array.isArray(keyframes)) {
168
+ keyframes = [keyframes];
169
+ }
170
+ for (let i = 0; i < keyframes.length; i++) {
171
+ if (keyframes[i] === null) {
172
+ keyframes[i] =
173
+ i === 0 && !pseudoElement
174
+ ? style$1.get(element, name)
175
+ : keyframes[i - 1];
197
176
  }
198
- if (this.animation.commitStyles) {
199
- this.animation.commitStyles();
177
+ if (typeof keyframes[i] === "number" && pxValues.has(name)) {
178
+ keyframes[i] = keyframes[i] + "px";
200
179
  }
201
- this.cancel();
202
- }
203
- flatten() {
204
- var _a, _b;
205
- if (!this.animation || !((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowFlatten))
206
- return;
207
- (_b = this.animation.effect) === null || _b === void 0 ? void 0 : _b.updateTiming({ easing: "linear" });
208
180
  }
209
- attachTimeline(timeline) {
210
- if (this.animation)
211
- attachTimeline(this.animation, timeline);
212
- return motionUtils.noop;
213
- }
214
- complete() {
215
- this.animation && this.animation.finish();
216
- }
217
- cancel() {
218
- try {
219
- this.animation && this.animation.cancel();
220
- }
221
- catch (e) { }
181
+ if (!pseudoElement && !supportsPartialKeyframes() && keyframes.length < 2) {
182
+ keyframes.unshift(style$1.get(element, name));
222
183
  }
184
+ return keyframes;
223
185
  }
224
186
 
187
+ const activeAnimations = {
188
+ layout: 0,
189
+ mainThread: 0,
190
+ waapi: 0,
191
+ };
192
+
193
+ const statsBuffer = {
194
+ value: null,
195
+ addProjectionMetrics: null,
196
+ };
197
+
225
198
  const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
226
199
 
227
200
  /**
228
201
  * Add the ability for test suites to manually set support flags
229
202
  * to better test more environments.
230
203
  */
231
- const supportsFlags = {
232
- linearEasing: undefined,
233
- };
204
+ const supportsFlags = {};
234
205
 
235
206
  function memoSupports(callback, supportsFlag) {
236
207
  const memoized = motionUtils.memo(callback);
237
- return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
208
+ return () => supportsFlags[supportsFlag] ?? memoized();
238
209
  }
239
210
 
240
211
  const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
@@ -255,20 +226,13 @@
255
226
  let points = "";
256
227
  const numPoints = Math.max(Math.round(duration / resolution), 2);
257
228
  for (let i = 0; i < numPoints; i++) {
258
- points += easing(motionUtils.progress(0, numPoints - 1, i)) + ", ";
229
+ points += easing(i / (numPoints - 1)) + ", ";
259
230
  }
260
231
  return `linear(${points.substring(0, points.length - 2)})`;
261
232
  };
262
233
 
263
- function isWaapiSupportedEasing(easing) {
264
- return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
265
- !easing ||
266
- (typeof easing === "string" &&
267
- (easing in supportedWaapiEasing || supportsLinearEasing())) ||
268
- isBezierDefinition(easing) ||
269
- (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
270
- }
271
234
  const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
235
+
272
236
  const supportedWaapiEasing = {
273
237
  linear: "linear",
274
238
  ease: "ease",
@@ -280,6 +244,7 @@
280
244
  backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
281
245
  backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
282
246
  };
247
+
283
248
  function mapEasingToNativeEasing(easing, duration) {
284
249
  if (!easing) {
285
250
  return undefined;
@@ -299,6 +264,255 @@
299
264
  }
300
265
  }
301
266
 
267
+ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
268
+ const keyframeOptions = {
269
+ [valueName]: keyframes,
270
+ };
271
+ if (times)
272
+ keyframeOptions.offset = times;
273
+ const easing = mapEasingToNativeEasing(ease, duration);
274
+ /**
275
+ * If this is an easing array, apply to keyframes, not animation as a whole
276
+ */
277
+ if (Array.isArray(easing))
278
+ keyframeOptions.easing = easing;
279
+ if (statsBuffer.value) {
280
+ activeAnimations.waapi++;
281
+ }
282
+ const animation = element.animate(keyframeOptions, {
283
+ delay,
284
+ duration,
285
+ easing: !Array.isArray(easing) ? easing : "linear",
286
+ fill: "both",
287
+ iterations: repeat + 1,
288
+ direction: repeatType === "reverse" ? "alternate" : "normal",
289
+ pseudoElement,
290
+ });
291
+ if (statsBuffer.value) {
292
+ animation.finished.finally(() => {
293
+ activeAnimations.waapi--;
294
+ });
295
+ }
296
+ return animation;
297
+ }
298
+
299
+ function isGenerator(type) {
300
+ return typeof type === "function" && "applyToOptions" in type;
301
+ }
302
+
303
+ function applyGeneratorOptions({ type, ...options }) {
304
+ if (isGenerator(type)) {
305
+ return type.applyToOptions(options);
306
+ }
307
+ else {
308
+ options.duration ?? (options.duration = 300);
309
+ options.ease ?? (options.ease = "easeOut");
310
+ }
311
+ return options;
312
+ }
313
+
314
+ const animationMaps = new WeakMap();
315
+ const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
316
+ function getAnimationMap(element) {
317
+ const map = animationMaps.get(element) || new Map();
318
+ animationMaps.set(element, map);
319
+ return map;
320
+ }
321
+ /**
322
+ * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
323
+ */
324
+ class NativeAnimation {
325
+ constructor(options) {
326
+ /**
327
+ * If we already have an animation, we don't need to instantiate one
328
+ * and can just use this as a controls interface.
329
+ */
330
+ if ("animation" in options) {
331
+ this.animation = options.animation;
332
+ return;
333
+ }
334
+ const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
335
+ let { transition } = options;
336
+ this.allowFlatten = allowFlatten;
337
+ /**
338
+ * Stop any existing animations on the element before reading existing keyframes.
339
+ *
340
+ * TODO: Check for VisualElement before using animation state. This is a fallback
341
+ * for mini animate(). Do this when implementing NativeAnimationExtended.
342
+ */
343
+ const animationMap = getAnimationMap(element);
344
+ const key = animationMapKey(name, pseudoElement || "");
345
+ const currentAnimation = animationMap.get(key);
346
+ currentAnimation && currentAnimation.stop();
347
+ /**
348
+ * TODO: If these keyframes aren't correctly hydrated then we want to throw
349
+ * run an instant animation.
350
+ */
351
+ const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
352
+ motionUtils.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
353
+ transition = applyGeneratorOptions(transition);
354
+ this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
355
+ if (transition.autoplay === false) {
356
+ this.animation.pause();
357
+ }
358
+ this.removeAnimation = () => animationMap.delete(key);
359
+ this.animation.onfinish = () => {
360
+ if (!pseudoElement) {
361
+ style$1.set(element, name, getFinalKeyframe(keyframes, transition));
362
+ }
363
+ else {
364
+ this.commitStyles();
365
+ }
366
+ this.cancel();
367
+ };
368
+ /**
369
+ * TODO: Check for VisualElement before using animation state.
370
+ */
371
+ animationMap.set(key, this);
372
+ }
373
+ play() {
374
+ this.animation.play();
375
+ }
376
+ pause() {
377
+ this.animation.pause();
378
+ }
379
+ complete() {
380
+ this.animation.finish();
381
+ }
382
+ cancel() {
383
+ try {
384
+ this.animation.cancel();
385
+ }
386
+ catch (e) { }
387
+ this.removeAnimation();
388
+ }
389
+ stop() {
390
+ const { state } = this;
391
+ if (state === "idle" || state === "finished") {
392
+ return;
393
+ }
394
+ this.commitStyles();
395
+ this.cancel();
396
+ }
397
+ /**
398
+ * WAAPI doesn't natively have any interruption capabilities.
399
+ *
400
+ * In this method, we commit styles back to the DOM before cancelling
401
+ * the animation.
402
+ *
403
+ * This is designed to be overridden by NativeAnimationExtended, which
404
+ * will create a renderless JS animation and sample it twice to calculate
405
+ * its current value, "previous" value, and therefore allow
406
+ * Motion to also correctly calculate velocity for any subsequent animation
407
+ * while deferring the commit until the next animation frame.
408
+ */
409
+ commitStyles() {
410
+ this.animation.commitStyles?.();
411
+ }
412
+ get duration() {
413
+ console.log(this.animation.effect?.getComputedTiming());
414
+ const duration = this.animation.effect?.getComputedTiming().duration || 0;
415
+ return motionUtils.millisecondsToSeconds(Number(duration));
416
+ }
417
+ get time() {
418
+ return motionUtils.millisecondsToSeconds(Number(this.animation.currentTime) || 0);
419
+ }
420
+ set time(newTime) {
421
+ this.animation.currentTime = motionUtils.secondsToMilliseconds(newTime);
422
+ }
423
+ /**
424
+ * The playback speed of the animation.
425
+ * 1 = normal speed, 2 = double speed, 0.5 = half speed.
426
+ */
427
+ get speed() {
428
+ return this.animation.playbackRate;
429
+ }
430
+ set speed(newSpeed) {
431
+ this.animation.playbackRate = newSpeed;
432
+ }
433
+ get state() {
434
+ return this.animation.playState;
435
+ }
436
+ get startTime() {
437
+ return Number(this.animation.startTime);
438
+ }
439
+ get finished() {
440
+ return this.animation.finished;
441
+ }
442
+ flatten() {
443
+ if (this.allowFlatten) {
444
+ this.animation.effect?.updateTiming({ easing: "linear" });
445
+ }
446
+ }
447
+ /**
448
+ * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
449
+ */
450
+ attachTimeline(timeline) {
451
+ this.animation.timeline = timeline;
452
+ this.animation.onfinish = null;
453
+ return motionUtils.noop;
454
+ }
455
+ /**
456
+ * Allows the animation to be awaited.
457
+ *
458
+ * @deprecated Use `finished` instead.
459
+ */
460
+ then(onResolve, onReject) {
461
+ return this.finished.then(onResolve).catch(onReject);
462
+ }
463
+ }
464
+
465
+ function getValueTransition(transition, key) {
466
+ return (transition?.[key] ??
467
+ transition?.["default"] ??
468
+ transition);
469
+ }
470
+
471
+ /**
472
+ * Implement a practical max duration for keyframe generation
473
+ * to prevent infinite loops
474
+ */
475
+ const maxGeneratorDuration = 20000;
476
+ function calcGeneratorDuration(generator) {
477
+ let duration = 0;
478
+ const timeStep = 50;
479
+ let state = generator.next(duration);
480
+ while (!state.done && duration < maxGeneratorDuration) {
481
+ duration += timeStep;
482
+ state = generator.next(duration);
483
+ }
484
+ return duration >= maxGeneratorDuration ? Infinity : duration;
485
+ }
486
+
487
+ /**
488
+ * Create a progress => progress easing function from a generator.
489
+ */
490
+ function createGeneratorEasing(options, scale = 100, createGenerator) {
491
+ const generator = createGenerator({ ...options, keyframes: [0, scale] });
492
+ const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
493
+ return {
494
+ type: "keyframes",
495
+ ease: (progress) => {
496
+ return generator.next(duration * progress).value / scale;
497
+ },
498
+ duration: motionUtils.millisecondsToSeconds(duration),
499
+ };
500
+ }
501
+
502
+ function isWaapiSupportedEasing(easing) {
503
+ return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
504
+ !easing ||
505
+ (typeof easing === "string" &&
506
+ (easing in supportedWaapiEasing || supportsLinearEasing())) ||
507
+ isBezierDefinition(easing) ||
508
+ (Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
509
+ }
510
+
511
+ function attachTimeline(animation, timeline) {
512
+ animation.timeline = timeline;
513
+ animation.onfinish = null;
514
+ }
515
+
302
516
  const stepsOrder = [
303
517
  "read", // Read
304
518
  "resolveKeyframes", // Write/Read/Write/Read
@@ -308,11 +522,6 @@
308
522
  "postRender", // Compute
309
523
  ];
310
524
 
311
- const statsBuffer = {
312
- value: null,
313
- addProjectionMetrics: null,
314
- };
315
-
316
525
  function createRenderStep(runNextFrame, stepName) {
317
526
  /**
318
527
  * We create and reuse two queues, one to queue jobs for the current frame
@@ -532,21 +741,16 @@
532
741
  }
533
742
 
534
743
  function resolveElements(elementOrSelector, scope, selectorCache) {
535
- var _a;
536
744
  if (elementOrSelector instanceof EventTarget) {
537
745
  return [elementOrSelector];
538
746
  }
539
747
  else if (typeof elementOrSelector === "string") {
540
748
  let root = document;
541
749
  if (scope) {
542
- // TODO: Refactor to utils package
543
- // invariant(
544
- // Boolean(scope.current),
545
- // "Scope provided, but no element detected."
546
- // )
547
750
  root = scope.current;
548
751
  }
549
- const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
752
+ const elements = selectorCache?.[elementOrSelector] ??
753
+ root.querySelectorAll(elementOrSelector);
550
754
  return elements ? Array.from(elements) : [];
551
755
  }
552
756
  return Array.from(elementOrSelector);
@@ -745,7 +949,7 @@
745
949
  if (target instanceof HTMLElement) {
746
950
  target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
747
951
  if (!isElementKeyboardAccessible(target) &&
748
- target.tabIndex === null) {
952
+ !target.hasAttribute("tabindex")) {
749
953
  target.tabIndex = 0;
750
954
  }
751
955
  }
@@ -753,12 +957,6 @@
753
957
  return cancelEvents;
754
958
  }
755
959
 
756
- const activeAnimations = {
757
- layout: 0,
758
- mainThread: 0,
759
- waapi: 0,
760
- };
761
-
762
960
  function record() {
763
961
  const { value } = statsBuffer;
764
962
  if (value === null) {
@@ -895,7 +1093,7 @@
895
1093
  * This will be replaced by the build step with the latest version number.
896
1094
  * When MotionValues are provided to motion components, warn if versions are mixed.
897
1095
  */
898
- this.version = "12.6.1";
1096
+ this.version = "12.6.3";
899
1097
  /**
900
1098
  * Tracks whether this value can output a velocity. Currently this is only true
901
1099
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1173,65 +1371,6 @@
1173
1371
  return new MotionValue(init, options);
1174
1372
  }
1175
1373
 
1176
- const defaultEasing = "easeOut";
1177
- function applyGeneratorOptions(options) {
1178
- var _a;
1179
- if (isGenerator(options.type)) {
1180
- const generatorOptions = createGeneratorEasing(options, 100, options.type);
1181
- options.ease = supportsLinearEasing()
1182
- ? generatorOptions.ease
1183
- : defaultEasing;
1184
- options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
1185
- options.type = "keyframes";
1186
- }
1187
- else {
1188
- options.duration = motionUtils.secondsToMilliseconds((_a = options.duration) !== null && _a !== void 0 ? _a : 0.3);
1189
- options.ease = options.ease || defaultEasing;
1190
- }
1191
- }
1192
- // TODO: Reuse for NativeAnimation
1193
- function convertMotionOptionsToNative(valueName, keyframes, options) {
1194
- var _a;
1195
- const nativeKeyframes = {};
1196
- const nativeOptions = {
1197
- fill: "both",
1198
- easing: "linear",
1199
- composite: "replace",
1200
- };
1201
- nativeOptions.delay = motionUtils.secondsToMilliseconds((_a = options.delay) !== null && _a !== void 0 ? _a : 0);
1202
- applyGeneratorOptions(options);
1203
- nativeOptions.duration = options.duration;
1204
- const { ease, times } = options;
1205
- if (times)
1206
- nativeKeyframes.offset = times;
1207
- nativeKeyframes[valueName] = keyframes;
1208
- const easing = mapEasingToNativeEasing(ease, options.duration);
1209
- /**
1210
- * If this is an easing array, apply to keyframes, not animation as a whole
1211
- */
1212
- if (Array.isArray(easing)) {
1213
- nativeKeyframes.easing = easing;
1214
- }
1215
- else {
1216
- nativeOptions.easing = easing;
1217
- }
1218
- return {
1219
- keyframes: nativeKeyframes,
1220
- options: nativeOptions,
1221
- };
1222
- }
1223
-
1224
- class PseudoAnimation extends NativeAnimationControls {
1225
- constructor(target, pseudoElement, valueName, keyframes, options) {
1226
- const animationOptions = convertMotionOptionsToNative(valueName, keyframes, options);
1227
- const animation = target.animate(animationOptions.keyframes, {
1228
- pseudoElement,
1229
- ...animationOptions.options,
1230
- });
1231
- super(animation);
1232
- }
1233
- }
1234
-
1235
1374
  function chooseLayerType(valueName) {
1236
1375
  if (valueName === "layout")
1237
1376
  return "group";
@@ -1281,12 +1420,11 @@
1281
1420
  }
1282
1421
 
1283
1422
  function filterViewAnimations(animation) {
1284
- var _a;
1285
1423
  const { effect } = animation;
1286
1424
  if (!effect)
1287
1425
  return false;
1288
1426
  return (effect.target === document.documentElement &&
1289
- ((_a = effect.pseudoElement) === null || _a === void 0 ? void 0 : _a.startsWith("::view-transition")));
1427
+ effect.pseudoElement?.startsWith("::view-transition"));
1290
1428
  }
1291
1429
  function getViewAnimations() {
1292
1430
  return document.getAnimations().filter(filterViewAnimations);
@@ -1302,7 +1440,7 @@
1302
1440
  if (!document.startViewTransition) {
1303
1441
  return new Promise(async (resolve) => {
1304
1442
  await update();
1305
- resolve(new BaseGroupPlaybackControls([]));
1443
+ resolve(new GroupAnimation([]));
1306
1444
  });
1307
1445
  }
1308
1446
  // TODO: Go over existing targets and ensure they all have ids
@@ -1333,11 +1471,10 @@
1333
1471
  });
1334
1472
  return new Promise((resolve) => {
1335
1473
  transition.ready.then(() => {
1336
- var _a;
1337
1474
  const generatedViewAnimations = getViewAnimations();
1338
1475
  const animations = [];
1339
1476
  /**
1340
- * Create animations for our definitions
1477
+ * Create animations for each of our explicitly-defined subjects.
1341
1478
  */
1342
1479
  targets.forEach((definition, target) => {
1343
1480
  // TODO: If target is not "root", resolve elements
@@ -1369,7 +1506,13 @@
1369
1506
  if (typeof valueOptions.delay === "function") {
1370
1507
  valueOptions.delay = valueOptions.delay(0, 1);
1371
1508
  }
1372
- const animation = new PseudoAnimation(document.documentElement, `::view-transition-${type}(${target})`, valueName, valueKeyframes, valueOptions);
1509
+ const animation = new NativeAnimation({
1510
+ element: document.documentElement,
1511
+ name: valueName,
1512
+ pseudoElement: `::view-transition-${type}(${target})`,
1513
+ keyframes: valueKeyframes,
1514
+ transition: valueOptions,
1515
+ });
1373
1516
  animations.push(animation);
1374
1517
  }
1375
1518
  }
@@ -1397,36 +1540,37 @@
1397
1540
  * the above method.
1398
1541
  */
1399
1542
  const transitionName = name.type === "group" ? "layout" : "";
1400
- const animationTransition = {
1543
+ let animationTransition = {
1401
1544
  ...getValueTransition(defaultOptions, transitionName),
1402
1545
  };
1403
- applyGeneratorOptions(animationTransition);
1546
+ animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
1547
+ animationTransition =
1548
+ applyGeneratorOptions(animationTransition);
1404
1549
  const easing = mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
1405
1550
  effect.updateTiming({
1406
- delay: motionUtils.secondsToMilliseconds((_a = animationTransition.delay) !== null && _a !== void 0 ? _a : 0),
1551
+ delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
1407
1552
  duration: animationTransition.duration,
1408
1553
  easing,
1409
1554
  });
1410
- animations.push(new NativeAnimationControls(animation));
1555
+ animations.push(new NativeAnimation({ animation }));
1411
1556
  }
1412
1557
  else if (hasOpacity(targetDefinition, "enter") &&
1413
1558
  hasOpacity(targetDefinition, "exit") &&
1414
1559
  effect
1415
1560
  .getKeyframes()
1416
1561
  .some((keyframe) => keyframe.mixBlendMode)) {
1417
- animations.push(new NativeAnimationControls(animation));
1562
+ animations.push(new NativeAnimation({ animation }));
1418
1563
  }
1419
1564
  else {
1420
1565
  animation.cancel();
1421
1566
  }
1422
1567
  }
1423
- resolve(new BaseGroupPlaybackControls(animations));
1568
+ resolve(new GroupAnimation(animations));
1424
1569
  });
1425
1570
  });
1426
1571
  }
1427
1572
  function hasOpacity(target, key) {
1428
- var _a;
1429
- return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
1573
+ return target?.[key]?.keyframes.opacity;
1430
1574
  }
1431
1575
 
1432
1576
  let builders = [];
@@ -1446,7 +1590,6 @@
1446
1590
  });
1447
1591
  }
1448
1592
  function processQueue() {
1449
- var _a;
1450
1593
  /**
1451
1594
  * Iterate backwards over the builders array. We can ignore the
1452
1595
  * "wait" animations. If we have an interrupting animation in the
@@ -1468,7 +1611,7 @@
1468
1611
  break;
1469
1612
  }
1470
1613
  }
1471
- if (!current || ((_a = builders[0]) === null || _a === void 0 ? void 0 : _a.options.interrupt) === "immediate") {
1614
+ if (!current || builders[0]?.options.interrupt === "immediate") {
1472
1615
  next();
1473
1616
  }
1474
1617
  }
@@ -1537,9 +1680,10 @@
1537
1680
  return new ViewTransitionBuilder(update, defaultOptions);
1538
1681
  }
1539
1682
 
1540
- exports.GroupPlaybackControls = GroupPlaybackControls;
1683
+ exports.GroupAnimation = GroupAnimation;
1684
+ exports.GroupAnimationWithThen = GroupAnimationWithThen;
1541
1685
  exports.MotionValue = MotionValue;
1542
- exports.NativeAnimationControls = NativeAnimationControls;
1686
+ exports.NativeAnimation = NativeAnimation;
1543
1687
  exports.ViewTransitionBuilder = ViewTransitionBuilder;
1544
1688
  exports.activeAnimations = activeAnimations;
1545
1689
  exports.animateView = animateView;
@@ -1572,6 +1716,7 @@
1572
1716
  exports.recordStats = recordStats;
1573
1717
  exports.resolveElements = resolveElements;
1574
1718
  exports.setDragLock = setDragLock;
1719
+ exports.startWaapiAnimation = startWaapiAnimation;
1575
1720
  exports.statsBuffer = statsBuffer;
1576
1721
  exports.supportedWaapiEasing = supportedWaapiEasing;
1577
1722
  exports.supportsFlags = supportsFlags;