motion-dom 11.14.3 → 11.16.1

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 (29) hide show
  1. package/dist/cjs/index.js +665 -31
  2. package/dist/es/animation/controls/BaseGroup.mjs +82 -0
  3. package/dist/es/animation/controls/Group.mjs +13 -0
  4. package/dist/es/animation/generators/utils/calc-duration.mjs +17 -0
  5. package/dist/es/animation/generators/utils/create-generator-easing.mjs +19 -0
  6. package/dist/es/animation/generators/utils/is-generator.mjs +5 -0
  7. package/dist/es/animation/utils/get-value-transition.mjs +9 -0
  8. package/dist/es/animation/waapi/NativeAnimationControls.mjs +83 -0
  9. package/dist/es/animation/waapi/PseudoAnimation.mjs +15 -0
  10. package/dist/es/animation/waapi/utils/attach-timeline.mjs +6 -0
  11. package/dist/es/animation/waapi/utils/convert-options.mjs +55 -0
  12. package/dist/es/animation/waapi/utils/easing.mjs +44 -0
  13. package/dist/es/animation/waapi/utils/linear.mjs +14 -0
  14. package/dist/es/gestures/press/index.mjs +4 -3
  15. package/dist/es/index.mjs +15 -1
  16. package/dist/es/utils/is-bezier-definition.mjs +3 -0
  17. package/dist/es/utils/supports/flags.mjs +9 -0
  18. package/dist/es/utils/supports/linear-easing.mjs +15 -0
  19. package/dist/es/utils/supports/memo.mjs +9 -0
  20. package/dist/es/utils/supports/scroll-timeline.mjs +5 -0
  21. package/dist/es/view/index.mjs +65 -0
  22. package/dist/es/view/start.mjs +146 -0
  23. package/dist/es/view/utils/choose-layer-type.mjs +11 -0
  24. package/dist/es/view/utils/css.mjs +32 -0
  25. package/dist/es/view/utils/get-layer-name.mjs +8 -0
  26. package/dist/es/view/utils/get-view-animations.mjs +13 -0
  27. package/dist/es/view/utils/has-target.mjs +5 -0
  28. package/dist/index.d.ts +648 -3
  29. package/package.json +5 -2
package/dist/cjs/index.js CHANGED
@@ -2,6 +2,303 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var motionUtils = require('motion-utils');
6
+
7
+ const supportsScrollTimeline = motionUtils.memo(() => window.ScrollTimeline !== undefined);
8
+
9
+ class BaseGroupPlaybackControls {
10
+ constructor(animations) {
11
+ // Bound to accomodate common `return animation.stop` pattern
12
+ this.stop = () => this.runAll("stop");
13
+ this.animations = animations.filter(Boolean);
14
+ }
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));
18
+ }
19
+ /**
20
+ * TODO: Filter out cancelled or stopped animations before returning
21
+ */
22
+ getAll(propName) {
23
+ return this.animations[0][propName];
24
+ }
25
+ setAll(propName, newValue) {
26
+ for (let i = 0; i < this.animations.length; i++) {
27
+ this.animations[i][propName] = newValue;
28
+ }
29
+ }
30
+ attachTimeline(timeline, fallback) {
31
+ const subscriptions = this.animations.map((animation) => {
32
+ if (supportsScrollTimeline() && animation.attachTimeline) {
33
+ return animation.attachTimeline(timeline);
34
+ }
35
+ else {
36
+ return fallback(animation);
37
+ }
38
+ });
39
+ return () => {
40
+ subscriptions.forEach((cancel, i) => {
41
+ cancel && cancel();
42
+ this.animations[i].stop();
43
+ });
44
+ };
45
+ }
46
+ get time() {
47
+ return this.getAll("time");
48
+ }
49
+ set time(time) {
50
+ this.setAll("time", time);
51
+ }
52
+ get speed() {
53
+ return this.getAll("speed");
54
+ }
55
+ set speed(speed) {
56
+ this.setAll("speed", speed);
57
+ }
58
+ get startTime() {
59
+ return this.getAll("startTime");
60
+ }
61
+ get duration() {
62
+ let max = 0;
63
+ for (let i = 0; i < this.animations.length; i++) {
64
+ max = Math.max(max, this.animations[i].duration);
65
+ }
66
+ return max;
67
+ }
68
+ runAll(methodName) {
69
+ this.animations.forEach((controls) => controls[methodName]());
70
+ }
71
+ flatten() {
72
+ this.runAll("flatten");
73
+ }
74
+ play() {
75
+ this.runAll("play");
76
+ }
77
+ pause() {
78
+ this.runAll("pause");
79
+ }
80
+ cancel() {
81
+ this.runAll("cancel");
82
+ }
83
+ complete() {
84
+ this.runAll("complete");
85
+ }
86
+ }
87
+
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);
95
+ }
96
+ }
97
+
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
+ }
140
+
141
+ function attachTimeline(animation, timeline) {
142
+ animation.timeline = timeline;
143
+ animation.onfinish = null;
144
+ }
145
+
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();
188
+ }
189
+ pause() {
190
+ this.animation && this.animation.pause();
191
+ }
192
+ stop() {
193
+ if (!this.animation ||
194
+ this.state === "idle" ||
195
+ this.state === "finished") {
196
+ return;
197
+ }
198
+ if (this.animation.commitStyles) {
199
+ this.animation.commitStyles();
200
+ }
201
+ this.cancel();
202
+ }
203
+ flatten() {
204
+ var _a;
205
+ if (!this.animation)
206
+ return;
207
+ (_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
208
+ }
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) { }
222
+ }
223
+ }
224
+
225
+ const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
226
+
227
+ /**
228
+ * Add the ability for test suites to manually set support flags
229
+ * to better test more environments.
230
+ */
231
+ const supportsFlags = {
232
+ linearEasing: undefined,
233
+ };
234
+
235
+ function memoSupports(callback, supportsFlag) {
236
+ const memoized = motionUtils.memo(callback);
237
+ return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
238
+ }
239
+
240
+ const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
241
+ try {
242
+ document
243
+ .createElement("div")
244
+ .animate({ opacity: 0 }, { easing: "linear(0, 1)" });
245
+ }
246
+ catch (e) {
247
+ return false;
248
+ }
249
+ return true;
250
+ }, "linearEasing");
251
+
252
+ const generateLinearEasing = (easing, duration, // as milliseconds
253
+ resolution = 10 // as milliseconds
254
+ ) => {
255
+ let points = "";
256
+ const numPoints = Math.max(Math.round(duration / resolution), 2);
257
+ for (let i = 0; i < numPoints; i++) {
258
+ points += easing(motionUtils.progress(0, numPoints - 1, i)) + ", ";
259
+ }
260
+ return `linear(${points.substring(0, points.length - 2)})`;
261
+ };
262
+
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
+ const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
272
+ const supportedWaapiEasing = {
273
+ linear: "linear",
274
+ ease: "ease",
275
+ easeIn: "ease-in",
276
+ easeOut: "ease-out",
277
+ easeInOut: "ease-in-out",
278
+ circIn: /*@__PURE__*/ cubicBezierAsString([0, 0.65, 0.55, 1]),
279
+ circOut: /*@__PURE__*/ cubicBezierAsString([0.55, 0, 1, 0.45]),
280
+ backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
281
+ backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
282
+ };
283
+ function mapEasingToNativeEasing(easing, duration) {
284
+ if (!easing) {
285
+ return undefined;
286
+ }
287
+ else if (typeof easing === "function" && supportsLinearEasing()) {
288
+ return generateLinearEasing(easing, duration);
289
+ }
290
+ else if (isBezierDefinition(easing)) {
291
+ return cubicBezierAsString(easing);
292
+ }
293
+ else if (Array.isArray(easing)) {
294
+ return easing.map((segmentEasing) => mapEasingToNativeEasing(segmentEasing, duration) ||
295
+ supportedWaapiEasing.easeOut);
296
+ }
297
+ else {
298
+ return supportedWaapiEasing[easing];
299
+ }
300
+ }
301
+
5
302
  const isDragging = {
6
303
  x: false,
7
304
  y: false,
@@ -80,6 +377,25 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
80
377
  return cancel;
81
378
  }
82
379
 
380
+ /**
381
+ * Recursively traverse up the tree to check whether the provided child node
382
+ * is the parent or a descendant of it.
383
+ *
384
+ * @param parent - Element to find
385
+ * @param child - Element to test against parent
386
+ */
387
+ const isNodeOrChild = (parent, child) => {
388
+ if (!child) {
389
+ return false;
390
+ }
391
+ else if (parent === child) {
392
+ return true;
393
+ }
394
+ else {
395
+ return isNodeOrChild(parent, child.parentElement);
396
+ }
397
+ };
398
+
83
399
  const isPrimaryPointer = (event) => {
84
400
  if (event.pointerType === "mouse") {
85
401
  return typeof event.button !== "number" || event.button <= 0;
@@ -97,6 +413,17 @@ const isPrimaryPointer = (event) => {
97
413
  }
98
414
  };
99
415
 
416
+ const focusableElements = new Set([
417
+ "BUTTON",
418
+ "INPUT",
419
+ "SELECT",
420
+ "TEXTAREA",
421
+ "A",
422
+ ]);
423
+ function isElementKeyboardAccessible(element) {
424
+ return focusableElements.has(element.tagName) || element.tabIndex !== -1;
425
+ }
426
+
100
427
  const isPressing = new WeakSet();
101
428
 
102
429
  /**
@@ -134,36 +461,6 @@ const enableKeyboardPress = (focusEvent, eventOptions) => {
134
461
  element.addEventListener("blur", () => element.removeEventListener("keydown", handleKeydown), eventOptions);
135
462
  };
136
463
 
137
- const focusableElements = new Set([
138
- "BUTTON",
139
- "INPUT",
140
- "SELECT",
141
- "TEXTAREA",
142
- "A",
143
- ]);
144
- function isElementKeyboardAccessible(element) {
145
- return focusableElements.has(element.tagName) || element.tabIndex !== -1;
146
- }
147
-
148
- /**
149
- * Recursively traverse up the tree to check whether the provided child node
150
- * is the parent or a descendant of it.
151
- *
152
- * @param parent - Element to find
153
- * @param child - Element to test against parent
154
- */
155
- const isNodeOrChild = (parent, child) => {
156
- if (!child) {
157
- return false;
158
- }
159
- else if (parent === child) {
160
- return true;
161
- }
162
- else {
163
- return isNodeOrChild(parent, child.parentElement);
164
- }
165
- };
166
-
167
464
  /**
168
465
  * Filter out events that are not primary pointer events, or are triggering
169
466
  * while a Motion gesture is active.
@@ -220,7 +517,8 @@ function press(elementOrSelector, onPressStart, options = {}) {
220
517
  window.addEventListener("pointercancel", onPointerCancel, eventOptions);
221
518
  };
222
519
  elements.forEach((element) => {
223
- if (!isElementKeyboardAccessible(element)) {
520
+ if (!isElementKeyboardAccessible(element) &&
521
+ element.getAttribute("tabindex") === null) {
224
522
  element.tabIndex = 0;
225
523
  }
226
524
  const target = options.useGlobalTarget ? window : element;
@@ -230,6 +528,323 @@ function press(elementOrSelector, onPressStart, options = {}) {
230
528
  return cancelEvents;
231
529
  }
232
530
 
531
+ const defaultEasing = "easeOut";
532
+ function applyGeneratorOptions(options) {
533
+ var _a;
534
+ if (isGenerator(options.type)) {
535
+ const generatorOptions = createGeneratorEasing(options, 100, options.type);
536
+ options.ease = supportsLinearEasing()
537
+ ? generatorOptions.ease
538
+ : defaultEasing;
539
+ options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
540
+ options.type = "keyframes";
541
+ }
542
+ else {
543
+ options.duration = motionUtils.secondsToMilliseconds((_a = options.duration) !== null && _a !== void 0 ? _a : 0.3);
544
+ options.ease = options.ease || defaultEasing;
545
+ }
546
+ }
547
+ // TODO: Reuse for NativeAnimation
548
+ function convertMotionOptionsToNative(valueName, keyframes, options) {
549
+ var _a;
550
+ const nativeKeyframes = {};
551
+ const nativeOptions = {
552
+ fill: "both",
553
+ easing: "linear",
554
+ composite: "replace",
555
+ };
556
+ nativeOptions.delay = motionUtils.secondsToMilliseconds((_a = options.delay) !== null && _a !== void 0 ? _a : 0);
557
+ applyGeneratorOptions(options);
558
+ nativeOptions.duration = options.duration;
559
+ const { ease, times } = options;
560
+ if (times)
561
+ nativeKeyframes.offset = times;
562
+ nativeKeyframes[valueName] = keyframes;
563
+ const easing = mapEasingToNativeEasing(ease, options.duration);
564
+ /**
565
+ * If this is an easing array, apply to keyframes, not animation as a whole
566
+ */
567
+ if (Array.isArray(easing)) {
568
+ nativeKeyframes.easing = easing;
569
+ }
570
+ else {
571
+ nativeOptions.easing = easing;
572
+ }
573
+ return {
574
+ keyframes: nativeKeyframes,
575
+ options: nativeOptions,
576
+ };
577
+ }
578
+
579
+ class PseudoAnimation extends NativeAnimationControls {
580
+ constructor(target, pseudoElement, valueName, keyframes, options) {
581
+ const animationOptions = convertMotionOptionsToNative(valueName, keyframes, options);
582
+ const animation = target.animate(animationOptions.keyframes, {
583
+ pseudoElement,
584
+ ...animationOptions.options,
585
+ });
586
+ super(animation);
587
+ }
588
+ }
589
+
590
+ function chooseLayerType(valueName) {
591
+ if (valueName === "layout")
592
+ return "group";
593
+ if (valueName === "enter" || valueName === "new")
594
+ return "new";
595
+ if (valueName === "exit" || valueName === "old")
596
+ return "old";
597
+ return "group";
598
+ }
599
+
600
+ let pendingRules = {};
601
+ let style = null;
602
+ const css = {
603
+ set: (selector, values) => {
604
+ pendingRules[selector] = values;
605
+ },
606
+ commit: () => {
607
+ if (!style) {
608
+ style = document.createElement("style");
609
+ style.id = "motion-view";
610
+ }
611
+ let cssText = "";
612
+ for (const selector in pendingRules) {
613
+ const rule = pendingRules[selector];
614
+ cssText += `${selector} {\n`;
615
+ for (const [property, value] of Object.entries(rule)) {
616
+ cssText += ` ${property}: ${value};\n`;
617
+ }
618
+ cssText += "}\n";
619
+ }
620
+ style.textContent = cssText;
621
+ document.head.appendChild(style);
622
+ pendingRules = {};
623
+ },
624
+ remove: () => {
625
+ if (style && style.parentElement) {
626
+ style.parentElement.removeChild(style);
627
+ }
628
+ },
629
+ };
630
+
631
+ function getLayerName(pseudoElement) {
632
+ const match = pseudoElement.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);
633
+ if (!match)
634
+ return null;
635
+ return { layer: match[2], type: match[1] };
636
+ }
637
+
638
+ function filterViewAnimations(animation) {
639
+ var _a;
640
+ const { effect } = animation;
641
+ if (!effect)
642
+ return false;
643
+ return (effect.target === document.documentElement &&
644
+ ((_a = effect.pseudoElement) === null || _a === void 0 ? void 0 : _a.startsWith("::view-transition")));
645
+ }
646
+ function getViewAnimations() {
647
+ return document.getAnimations().filter(filterViewAnimations);
648
+ }
649
+
650
+ function hasTarget(target, targets) {
651
+ return targets.has(target) && Object.keys(targets.get(target)).length > 0;
652
+ }
653
+
654
+ const definitionNames = ["layout", "enter", "exit", "new", "old"];
655
+ function startViewAnimation(update, defaultOptions, targets) {
656
+ if (!document.startViewTransition) {
657
+ return new Promise(async (resolve) => {
658
+ await update();
659
+ resolve(new BaseGroupPlaybackControls([]));
660
+ });
661
+ }
662
+ // TODO: Go over existing targets and ensure they all have ids
663
+ /**
664
+ * If we don't have any animations defined for the root target,
665
+ * remove it from being captured.
666
+ */
667
+ if (!hasTarget("root", targets)) {
668
+ css.set(":root", {
669
+ "view-transition-name": "none",
670
+ });
671
+ }
672
+ /**
673
+ * Set the timing curve to linear for all view transition layers.
674
+ * This gets baked into the keyframes, which can't be changed
675
+ * without breaking the generated animation.
676
+ *
677
+ * This allows us to set easing via updateTiming - which can be changed.
678
+ */
679
+ css.set("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)", { "animation-timing-function": "linear !important" });
680
+ css.commit(); // Write
681
+ const transition = document.startViewTransition(async () => {
682
+ await update();
683
+ // TODO: Go over new targets and ensure they all have ids
684
+ });
685
+ transition.finished.finally(() => {
686
+ css.remove(); // Write
687
+ });
688
+ return new Promise((resolve) => {
689
+ transition.ready.then(() => {
690
+ var _a;
691
+ const generatedViewAnimations = getViewAnimations();
692
+ const animations = [];
693
+ /**
694
+ * Create animations for our definitions
695
+ */
696
+ targets.forEach((definition, target) => {
697
+ // TODO: If target is not "root", resolve elements
698
+ // and iterate over each
699
+ for (const key of definitionNames) {
700
+ if (!definition[key])
701
+ continue;
702
+ const { keyframes, options } = definition[key];
703
+ for (let [valueName, valueKeyframes] of Object.entries(keyframes)) {
704
+ if (!valueKeyframes)
705
+ continue;
706
+ const valueOptions = {
707
+ ...getValueTransition(defaultOptions, valueName),
708
+ ...getValueTransition(options, valueName),
709
+ };
710
+ const type = chooseLayerType(key);
711
+ /**
712
+ * If this is an opacity animation, and keyframes are not an array,
713
+ * we need to convert them into an array and set an initial value.
714
+ */
715
+ if (valueName === "opacity" &&
716
+ !Array.isArray(valueKeyframes)) {
717
+ const initialValue = type === "new" ? 0 : 1;
718
+ valueKeyframes = [initialValue, valueKeyframes];
719
+ }
720
+ /**
721
+ * Resolve stagger function if provided.
722
+ */
723
+ if (typeof valueOptions.delay === "function") {
724
+ valueOptions.delay = valueOptions.delay(0, 1);
725
+ }
726
+ const animation = new PseudoAnimation(document.documentElement, `::view-transition-${type}(${target})`, valueName, valueKeyframes, valueOptions);
727
+ animations.push(animation);
728
+ }
729
+ }
730
+ });
731
+ /**
732
+ * Handle browser generated animations
733
+ */
734
+ for (const animation of generatedViewAnimations) {
735
+ if (animation.playState === "finished")
736
+ continue;
737
+ const { effect } = animation;
738
+ if (!effect || !(effect instanceof KeyframeEffect))
739
+ continue;
740
+ const { pseudoElement } = effect;
741
+ if (!pseudoElement)
742
+ continue;
743
+ const name = getLayerName(pseudoElement);
744
+ if (!name)
745
+ continue;
746
+ const targetDefinition = targets.get(name.layer);
747
+ if (!targetDefinition) {
748
+ /**
749
+ * If transition name is group then update the timing of the animation
750
+ * whereas if it's old or new then we could possibly replace it using
751
+ * the above method.
752
+ */
753
+ const transitionName = name.type === "group" ? "layout" : "";
754
+ const animationTransition = {
755
+ ...getValueTransition(defaultOptions, transitionName),
756
+ };
757
+ applyGeneratorOptions(animationTransition);
758
+ const easing = mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
759
+ effect.updateTiming({
760
+ delay: motionUtils.secondsToMilliseconds((_a = animationTransition.delay) !== null && _a !== void 0 ? _a : 0),
761
+ duration: animationTransition.duration,
762
+ easing,
763
+ });
764
+ animations.push(new NativeAnimationControls(animation));
765
+ }
766
+ else if (hasOpacity(targetDefinition, "enter") &&
767
+ hasOpacity(targetDefinition, "exit") &&
768
+ effect
769
+ .getKeyframes()
770
+ .some((keyframe) => keyframe.mixBlendMode)) {
771
+ animations.push(new NativeAnimationControls(animation));
772
+ }
773
+ else {
774
+ animation.cancel();
775
+ }
776
+ }
777
+ resolve(new BaseGroupPlaybackControls(animations));
778
+ });
779
+ });
780
+ }
781
+ function hasOpacity(target, key) {
782
+ var _a;
783
+ return (_a = target === null || target === void 0 ? void 0 : target[key]) === null || _a === void 0 ? void 0 : _a.keyframes.opacity;
784
+ }
785
+
786
+ /**
787
+ * TODO:
788
+ * - Create view transition on next tick
789
+ * - Replace animations with Motion animations
790
+ * - Return GroupAnimation on next tick
791
+ */
792
+ class ViewTransitionBuilder {
793
+ constructor(update, options = {}) {
794
+ this.currentTarget = "root";
795
+ this.targets = new Map();
796
+ this.readyPromise = new Promise((resolve) => {
797
+ this.notifyReady = resolve;
798
+ });
799
+ queueMicrotask(() => {
800
+ startViewAnimation(update, options, this.targets).then((animation) => this.notifyReady(animation));
801
+ });
802
+ }
803
+ get(selector) {
804
+ this.currentTarget = selector;
805
+ return this;
806
+ }
807
+ layout(keyframes, options) {
808
+ this.updateTarget("layout", keyframes, options);
809
+ return this;
810
+ }
811
+ new(keyframes, options) {
812
+ this.updateTarget("new", keyframes, options);
813
+ return this;
814
+ }
815
+ old(keyframes, options) {
816
+ this.updateTarget("old", keyframes, options);
817
+ return this;
818
+ }
819
+ enter(keyframes, options) {
820
+ this.updateTarget("enter", keyframes, options);
821
+ return this;
822
+ }
823
+ exit(keyframes, options) {
824
+ this.updateTarget("exit", keyframes, options);
825
+ return this;
826
+ }
827
+ crossfade(options) {
828
+ this.updateTarget("enter", { opacity: 1 }, options);
829
+ this.updateTarget("exit", { opacity: 0 }, options);
830
+ return this;
831
+ }
832
+ updateTarget(target, keyframes, options = {}) {
833
+ const { currentTarget, targets } = this;
834
+ if (!targets.has(currentTarget)) {
835
+ targets.set(currentTarget, {});
836
+ }
837
+ const targetData = targets.get(currentTarget);
838
+ targetData[target] = { keyframes, options };
839
+ }
840
+ then(resolve, reject) {
841
+ return this.readyPromise.then(resolve, reject);
842
+ }
843
+ }
844
+ function view(update, defaultOptions = {}) {
845
+ return new ViewTransitionBuilder(update, defaultOptions);
846
+ }
847
+
233
848
  function setDragLock(axis) {
234
849
  if (axis === "x" || axis === "y") {
235
850
  if (isDragging[axis]) {
@@ -255,11 +870,30 @@ function setDragLock(axis) {
255
870
  }
256
871
  }
257
872
 
873
+ exports.GroupPlaybackControls = GroupPlaybackControls;
874
+ exports.NativeAnimationControls = NativeAnimationControls;
875
+ exports.ViewTransitionBuilder = ViewTransitionBuilder;
876
+ exports.attachTimeline = attachTimeline;
877
+ exports.calcGeneratorDuration = calcGeneratorDuration;
878
+ exports.createGeneratorEasing = createGeneratorEasing;
879
+ exports.cubicBezierAsString = cubicBezierAsString;
880
+ exports.generateLinearEasing = generateLinearEasing;
881
+ exports.getValueTransition = getValueTransition;
258
882
  exports.hover = hover;
883
+ exports.isBezierDefinition = isBezierDefinition;
259
884
  exports.isDragActive = isDragActive;
260
885
  exports.isDragging = isDragging;
886
+ exports.isGenerator = isGenerator;
261
887
  exports.isNodeOrChild = isNodeOrChild;
262
888
  exports.isPrimaryPointer = isPrimaryPointer;
889
+ exports.isWaapiSupportedEasing = isWaapiSupportedEasing;
890
+ exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
891
+ exports.maxGeneratorDuration = maxGeneratorDuration;
263
892
  exports.press = press;
264
893
  exports.resolveElements = resolveElements;
265
894
  exports.setDragLock = setDragLock;
895
+ exports.supportedWaapiEasing = supportedWaapiEasing;
896
+ exports.supportsFlags = supportsFlags;
897
+ exports.supportsLinearEasing = supportsLinearEasing;
898
+ exports.supportsScrollTimeline = supportsScrollTimeline;
899
+ exports.view = view;