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.
- package/dist/cjs/index.js +665 -31
- package/dist/es/animation/controls/BaseGroup.mjs +82 -0
- package/dist/es/animation/controls/Group.mjs +13 -0
- package/dist/es/animation/generators/utils/calc-duration.mjs +17 -0
- package/dist/es/animation/generators/utils/create-generator-easing.mjs +19 -0
- package/dist/es/animation/generators/utils/is-generator.mjs +5 -0
- package/dist/es/animation/utils/get-value-transition.mjs +9 -0
- package/dist/es/animation/waapi/NativeAnimationControls.mjs +83 -0
- package/dist/es/animation/waapi/PseudoAnimation.mjs +15 -0
- package/dist/es/animation/waapi/utils/attach-timeline.mjs +6 -0
- package/dist/es/animation/waapi/utils/convert-options.mjs +55 -0
- package/dist/es/animation/waapi/utils/easing.mjs +44 -0
- package/dist/es/animation/waapi/utils/linear.mjs +14 -0
- package/dist/es/gestures/press/index.mjs +4 -3
- package/dist/es/index.mjs +15 -1
- package/dist/es/utils/is-bezier-definition.mjs +3 -0
- package/dist/es/utils/supports/flags.mjs +9 -0
- package/dist/es/utils/supports/linear-easing.mjs +15 -0
- package/dist/es/utils/supports/memo.mjs +9 -0
- package/dist/es/utils/supports/scroll-timeline.mjs +5 -0
- package/dist/es/view/index.mjs +65 -0
- package/dist/es/view/start.mjs +146 -0
- package/dist/es/view/utils/choose-layer-type.mjs +11 -0
- package/dist/es/view/utils/css.mjs +32 -0
- package/dist/es/view/utils/get-layer-name.mjs +8 -0
- package/dist/es/view/utils/get-view-animations.mjs +13 -0
- package/dist/es/view/utils/has-target.mjs +5 -0
- package/dist/index.d.ts +648 -3
- package/package.json +5 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { supportsScrollTimeline } from '../../utils/supports/scroll-timeline.mjs';
|
|
2
|
+
|
|
3
|
+
class BaseGroupPlaybackControls {
|
|
4
|
+
constructor(animations) {
|
|
5
|
+
// Bound to accomodate common `return animation.stop` pattern
|
|
6
|
+
this.stop = () => this.runAll("stop");
|
|
7
|
+
this.animations = animations.filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
get finished() {
|
|
10
|
+
// Support for new finished Promise and legacy thennable API
|
|
11
|
+
return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* TODO: Filter out cancelled or stopped animations before returning
|
|
15
|
+
*/
|
|
16
|
+
getAll(propName) {
|
|
17
|
+
return this.animations[0][propName];
|
|
18
|
+
}
|
|
19
|
+
setAll(propName, newValue) {
|
|
20
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
21
|
+
this.animations[i][propName] = newValue;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
attachTimeline(timeline, fallback) {
|
|
25
|
+
const subscriptions = this.animations.map((animation) => {
|
|
26
|
+
if (supportsScrollTimeline() && animation.attachTimeline) {
|
|
27
|
+
return animation.attachTimeline(timeline);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return fallback(animation);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
subscriptions.forEach((cancel, i) => {
|
|
35
|
+
cancel && cancel();
|
|
36
|
+
this.animations[i].stop();
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
get time() {
|
|
41
|
+
return this.getAll("time");
|
|
42
|
+
}
|
|
43
|
+
set time(time) {
|
|
44
|
+
this.setAll("time", time);
|
|
45
|
+
}
|
|
46
|
+
get speed() {
|
|
47
|
+
return this.getAll("speed");
|
|
48
|
+
}
|
|
49
|
+
set speed(speed) {
|
|
50
|
+
this.setAll("speed", speed);
|
|
51
|
+
}
|
|
52
|
+
get startTime() {
|
|
53
|
+
return this.getAll("startTime");
|
|
54
|
+
}
|
|
55
|
+
get duration() {
|
|
56
|
+
let max = 0;
|
|
57
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
58
|
+
max = Math.max(max, this.animations[i].duration);
|
|
59
|
+
}
|
|
60
|
+
return max;
|
|
61
|
+
}
|
|
62
|
+
runAll(methodName) {
|
|
63
|
+
this.animations.forEach((controls) => controls[methodName]());
|
|
64
|
+
}
|
|
65
|
+
flatten() {
|
|
66
|
+
this.runAll("flatten");
|
|
67
|
+
}
|
|
68
|
+
play() {
|
|
69
|
+
this.runAll("play");
|
|
70
|
+
}
|
|
71
|
+
pause() {
|
|
72
|
+
this.runAll("pause");
|
|
73
|
+
}
|
|
74
|
+
cancel() {
|
|
75
|
+
this.runAll("cancel");
|
|
76
|
+
}
|
|
77
|
+
complete() {
|
|
78
|
+
this.runAll("complete");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { BaseGroupPlaybackControls };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseGroupPlaybackControls } from './BaseGroup.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TODO: This is a temporary class to support the legacy
|
|
5
|
+
* thennable API
|
|
6
|
+
*/
|
|
7
|
+
class GroupPlaybackControls extends BaseGroupPlaybackControls {
|
|
8
|
+
then(onResolve, onReject) {
|
|
9
|
+
return Promise.all(this.animations).then(onResolve).catch(onReject);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { GroupPlaybackControls };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implement a practical max duration for keyframe generation
|
|
3
|
+
* to prevent infinite loops
|
|
4
|
+
*/
|
|
5
|
+
const maxGeneratorDuration = 20000;
|
|
6
|
+
function calcGeneratorDuration(generator) {
|
|
7
|
+
let duration = 0;
|
|
8
|
+
const timeStep = 50;
|
|
9
|
+
let state = generator.next(duration);
|
|
10
|
+
while (!state.done && duration < maxGeneratorDuration) {
|
|
11
|
+
duration += timeStep;
|
|
12
|
+
state = generator.next(duration);
|
|
13
|
+
}
|
|
14
|
+
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { calcGeneratorDuration, maxGeneratorDuration };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { millisecondsToSeconds } from 'motion-utils';
|
|
2
|
+
import { calcGeneratorDuration, maxGeneratorDuration } from './calc-duration.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a progress => progress easing function from a generator.
|
|
6
|
+
*/
|
|
7
|
+
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
8
|
+
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
9
|
+
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
10
|
+
return {
|
|
11
|
+
type: "keyframes",
|
|
12
|
+
ease: (progress) => {
|
|
13
|
+
return generator.next(duration * progress).value / scale;
|
|
14
|
+
},
|
|
15
|
+
duration: millisecondsToSeconds(duration),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { createGeneratorEasing };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { millisecondsToSeconds, secondsToMilliseconds, noop } from 'motion-utils';
|
|
2
|
+
import { attachTimeline } from './utils/attach-timeline.mjs';
|
|
3
|
+
|
|
4
|
+
class NativeAnimationControls {
|
|
5
|
+
constructor(animation) {
|
|
6
|
+
this.animation = animation;
|
|
7
|
+
}
|
|
8
|
+
get duration() {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
|
|
11
|
+
((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
|
|
12
|
+
300;
|
|
13
|
+
return millisecondsToSeconds(Number(durationInMs));
|
|
14
|
+
}
|
|
15
|
+
get time() {
|
|
16
|
+
var _a;
|
|
17
|
+
if (this.animation) {
|
|
18
|
+
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
19
|
+
}
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
set time(newTime) {
|
|
23
|
+
if (this.animation) {
|
|
24
|
+
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get speed() {
|
|
28
|
+
return this.animation ? this.animation.playbackRate : 1;
|
|
29
|
+
}
|
|
30
|
+
set speed(newSpeed) {
|
|
31
|
+
if (this.animation) {
|
|
32
|
+
this.animation.playbackRate = newSpeed;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get state() {
|
|
36
|
+
return this.animation ? this.animation.playState : "finished";
|
|
37
|
+
}
|
|
38
|
+
get startTime() {
|
|
39
|
+
return this.animation ? this.animation.startTime : null;
|
|
40
|
+
}
|
|
41
|
+
get finished() {
|
|
42
|
+
return this.animation ? this.animation.finished : Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
play() {
|
|
45
|
+
this.animation && this.animation.play();
|
|
46
|
+
}
|
|
47
|
+
pause() {
|
|
48
|
+
this.animation && this.animation.pause();
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
if (!this.animation ||
|
|
52
|
+
this.state === "idle" ||
|
|
53
|
+
this.state === "finished") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (this.animation.commitStyles) {
|
|
57
|
+
this.animation.commitStyles();
|
|
58
|
+
}
|
|
59
|
+
this.cancel();
|
|
60
|
+
}
|
|
61
|
+
flatten() {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!this.animation)
|
|
64
|
+
return;
|
|
65
|
+
(_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
|
|
66
|
+
}
|
|
67
|
+
attachTimeline(timeline) {
|
|
68
|
+
if (this.animation)
|
|
69
|
+
attachTimeline(this.animation, timeline);
|
|
70
|
+
return noop;
|
|
71
|
+
}
|
|
72
|
+
complete() {
|
|
73
|
+
this.animation && this.animation.finish();
|
|
74
|
+
}
|
|
75
|
+
cancel() {
|
|
76
|
+
try {
|
|
77
|
+
this.animation && this.animation.cancel();
|
|
78
|
+
}
|
|
79
|
+
catch (e) { }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { NativeAnimationControls };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NativeAnimationControls } from './NativeAnimationControls.mjs';
|
|
2
|
+
import { convertMotionOptionsToNative } from './utils/convert-options.mjs';
|
|
3
|
+
|
|
4
|
+
class PseudoAnimation extends NativeAnimationControls {
|
|
5
|
+
constructor(target, pseudoElement, valueName, keyframes, options) {
|
|
6
|
+
const animationOptions = convertMotionOptionsToNative(valueName, keyframes, options);
|
|
7
|
+
const animation = target.animate(animationOptions.keyframes, {
|
|
8
|
+
pseudoElement,
|
|
9
|
+
...animationOptions.options,
|
|
10
|
+
});
|
|
11
|
+
super(animation);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { PseudoAnimation };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { secondsToMilliseconds } from 'motion-utils';
|
|
2
|
+
import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
|
|
3
|
+
import { createGeneratorEasing } from '../../generators/utils/create-generator-easing.mjs';
|
|
4
|
+
import { isGenerator } from '../../generators/utils/is-generator.mjs';
|
|
5
|
+
import { mapEasingToNativeEasing } from './easing.mjs';
|
|
6
|
+
|
|
7
|
+
const defaultEasing = "easeOut";
|
|
8
|
+
function applyGeneratorOptions(options) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (isGenerator(options.type)) {
|
|
11
|
+
const generatorOptions = createGeneratorEasing(options, 100, options.type);
|
|
12
|
+
options.ease = supportsLinearEasing()
|
|
13
|
+
? generatorOptions.ease
|
|
14
|
+
: defaultEasing;
|
|
15
|
+
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
16
|
+
options.type = "keyframes";
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
options.duration = secondsToMilliseconds((_a = options.duration) !== null && _a !== void 0 ? _a : 0.3);
|
|
20
|
+
options.ease = options.ease || defaultEasing;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// TODO: Reuse for NativeAnimation
|
|
24
|
+
function convertMotionOptionsToNative(valueName, keyframes, options) {
|
|
25
|
+
var _a;
|
|
26
|
+
const nativeKeyframes = {};
|
|
27
|
+
const nativeOptions = {
|
|
28
|
+
fill: "both",
|
|
29
|
+
easing: "linear",
|
|
30
|
+
composite: "replace",
|
|
31
|
+
};
|
|
32
|
+
nativeOptions.delay = secondsToMilliseconds((_a = options.delay) !== null && _a !== void 0 ? _a : 0);
|
|
33
|
+
applyGeneratorOptions(options);
|
|
34
|
+
nativeOptions.duration = options.duration;
|
|
35
|
+
const { ease, times } = options;
|
|
36
|
+
if (times)
|
|
37
|
+
nativeKeyframes.offset = times;
|
|
38
|
+
nativeKeyframes[valueName] = keyframes;
|
|
39
|
+
const easing = mapEasingToNativeEasing(ease, options.duration);
|
|
40
|
+
/**
|
|
41
|
+
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
42
|
+
*/
|
|
43
|
+
if (Array.isArray(easing)) {
|
|
44
|
+
nativeKeyframes.easing = easing;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
nativeOptions.easing = easing;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
keyframes: nativeKeyframes,
|
|
51
|
+
options: nativeOptions,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { applyGeneratorOptions, convertMotionOptionsToNative };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isBezierDefinition } from '../../../utils/is-bezier-definition.mjs';
|
|
2
|
+
import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
|
|
3
|
+
import { generateLinearEasing } from './linear.mjs';
|
|
4
|
+
|
|
5
|
+
function isWaapiSupportedEasing(easing) {
|
|
6
|
+
return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
|
|
7
|
+
!easing ||
|
|
8
|
+
(typeof easing === "string" &&
|
|
9
|
+
(easing in supportedWaapiEasing || supportsLinearEasing())) ||
|
|
10
|
+
isBezierDefinition(easing) ||
|
|
11
|
+
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
12
|
+
}
|
|
13
|
+
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
14
|
+
const supportedWaapiEasing = {
|
|
15
|
+
linear: "linear",
|
|
16
|
+
ease: "ease",
|
|
17
|
+
easeIn: "ease-in",
|
|
18
|
+
easeOut: "ease-out",
|
|
19
|
+
easeInOut: "ease-in-out",
|
|
20
|
+
circIn: /*@__PURE__*/ cubicBezierAsString([0, 0.65, 0.55, 1]),
|
|
21
|
+
circOut: /*@__PURE__*/ cubicBezierAsString([0.55, 0, 1, 0.45]),
|
|
22
|
+
backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
|
|
23
|
+
backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
|
|
24
|
+
};
|
|
25
|
+
function mapEasingToNativeEasing(easing, duration) {
|
|
26
|
+
if (!easing) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
else if (typeof easing === "function" && supportsLinearEasing()) {
|
|
30
|
+
return generateLinearEasing(easing, duration);
|
|
31
|
+
}
|
|
32
|
+
else if (isBezierDefinition(easing)) {
|
|
33
|
+
return cubicBezierAsString(easing);
|
|
34
|
+
}
|
|
35
|
+
else if (Array.isArray(easing)) {
|
|
36
|
+
return easing.map((segmentEasing) => mapEasingToNativeEasing(segmentEasing, duration) ||
|
|
37
|
+
supportedWaapiEasing.easeOut);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return supportedWaapiEasing[easing];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { cubicBezierAsString, isWaapiSupportedEasing, mapEasingToNativeEasing, supportedWaapiEasing };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { progress } from 'motion-utils';
|
|
2
|
+
|
|
3
|
+
const generateLinearEasing = (easing, duration, // as milliseconds
|
|
4
|
+
resolution = 10 // as milliseconds
|
|
5
|
+
) => {
|
|
6
|
+
let points = "";
|
|
7
|
+
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
8
|
+
for (let i = 0; i < numPoints; i++) {
|
|
9
|
+
points += easing(progress(0, numPoints - 1, i)) + ", ";
|
|
10
|
+
}
|
|
11
|
+
return `linear(${points.substring(0, points.length - 2)})`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { generateLinearEasing };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isDragActive } from '../drag/state/is-active.mjs';
|
|
2
|
+
import { isNodeOrChild } from '../utils/is-node-or-child.mjs';
|
|
2
3
|
import { isPrimaryPointer } from '../utils/is-primary-pointer.mjs';
|
|
3
4
|
import { setupGesture } from '../utils/setup.mjs';
|
|
4
|
-
import { enableKeyboardPress } from './utils/keyboard.mjs';
|
|
5
5
|
import { isElementKeyboardAccessible } from './utils/is-keyboard-accessible.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { enableKeyboardPress } from './utils/keyboard.mjs';
|
|
7
7
|
import { isPressing } from './utils/state.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -62,7 +62,8 @@ function press(elementOrSelector, onPressStart, options = {}) {
|
|
|
62
62
|
window.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
63
63
|
};
|
|
64
64
|
elements.forEach((element) => {
|
|
65
|
-
if (!isElementKeyboardAccessible(element)
|
|
65
|
+
if (!isElementKeyboardAccessible(element) &&
|
|
66
|
+
element.getAttribute("tabindex") === null) {
|
|
66
67
|
element.tabIndex = 0;
|
|
67
68
|
}
|
|
68
69
|
const target = options.useGlobalTarget ? window : element;
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
export { GroupPlaybackControls } from './animation/controls/Group.mjs';
|
|
2
|
+
export { getValueTransition } from './animation/utils/get-value-transition.mjs';
|
|
3
|
+
export { calcGeneratorDuration, maxGeneratorDuration } from './animation/generators/utils/calc-duration.mjs';
|
|
4
|
+
export { createGeneratorEasing } from './animation/generators/utils/create-generator-easing.mjs';
|
|
5
|
+
export { isGenerator } from './animation/generators/utils/is-generator.mjs';
|
|
6
|
+
export { NativeAnimationControls } from './animation/waapi/NativeAnimationControls.mjs';
|
|
7
|
+
export { attachTimeline } from './animation/waapi/utils/attach-timeline.mjs';
|
|
8
|
+
export { cubicBezierAsString, isWaapiSupportedEasing, mapEasingToNativeEasing, supportedWaapiEasing } from './animation/waapi/utils/easing.mjs';
|
|
9
|
+
export { generateLinearEasing } from './animation/waapi/utils/linear.mjs';
|
|
1
10
|
export { hover } from './gestures/hover.mjs';
|
|
2
11
|
export { press } from './gestures/press/index.mjs';
|
|
12
|
+
export { isBezierDefinition } from './utils/is-bezier-definition.mjs';
|
|
3
13
|
export { resolveElements } from './utils/resolve-elements.mjs';
|
|
14
|
+
export { supportsFlags } from './utils/supports/flags.mjs';
|
|
15
|
+
export { supportsLinearEasing } from './utils/supports/linear-easing.mjs';
|
|
16
|
+
export { supportsScrollTimeline } from './utils/supports/scroll-timeline.mjs';
|
|
17
|
+
export { ViewTransitionBuilder, view } from './view/index.mjs';
|
|
4
18
|
export { isDragActive, isDragging } from './gestures/drag/state/is-active.mjs';
|
|
5
19
|
export { setDragLock } from './gestures/drag/state/set-active.mjs';
|
|
6
|
-
export { isPrimaryPointer } from './gestures/utils/is-primary-pointer.mjs';
|
|
7
20
|
export { isNodeOrChild } from './gestures/utils/is-node-or-child.mjs';
|
|
21
|
+
export { isPrimaryPointer } from './gestures/utils/is-primary-pointer.mjs';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { memoSupports } from './memo.mjs';
|
|
2
|
+
|
|
3
|
+
const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
|
|
4
|
+
try {
|
|
5
|
+
document
|
|
6
|
+
.createElement("div")
|
|
7
|
+
.animate({ opacity: 0 }, { easing: "linear(0, 1)" });
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}, "linearEasing");
|
|
14
|
+
|
|
15
|
+
export { supportsLinearEasing };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { memo } from 'motion-utils';
|
|
2
|
+
import { supportsFlags } from './flags.mjs';
|
|
3
|
+
|
|
4
|
+
function memoSupports(callback, supportsFlag) {
|
|
5
|
+
const memoized = memo(callback);
|
|
6
|
+
return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { memoSupports };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { startViewAnimation } from './start.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TODO:
|
|
5
|
+
* - Create view transition on next tick
|
|
6
|
+
* - Replace animations with Motion animations
|
|
7
|
+
* - Return GroupAnimation on next tick
|
|
8
|
+
*/
|
|
9
|
+
class ViewTransitionBuilder {
|
|
10
|
+
constructor(update, options = {}) {
|
|
11
|
+
this.currentTarget = "root";
|
|
12
|
+
this.targets = new Map();
|
|
13
|
+
this.readyPromise = new Promise((resolve) => {
|
|
14
|
+
this.notifyReady = resolve;
|
|
15
|
+
});
|
|
16
|
+
queueMicrotask(() => {
|
|
17
|
+
startViewAnimation(update, options, this.targets).then((animation) => this.notifyReady(animation));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
get(selector) {
|
|
21
|
+
this.currentTarget = selector;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
layout(keyframes, options) {
|
|
25
|
+
this.updateTarget("layout", keyframes, options);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
new(keyframes, options) {
|
|
29
|
+
this.updateTarget("new", keyframes, options);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
old(keyframes, options) {
|
|
33
|
+
this.updateTarget("old", keyframes, options);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
enter(keyframes, options) {
|
|
37
|
+
this.updateTarget("enter", keyframes, options);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
exit(keyframes, options) {
|
|
41
|
+
this.updateTarget("exit", keyframes, options);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
crossfade(options) {
|
|
45
|
+
this.updateTarget("enter", { opacity: 1 }, options);
|
|
46
|
+
this.updateTarget("exit", { opacity: 0 }, options);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
updateTarget(target, keyframes, options = {}) {
|
|
50
|
+
const { currentTarget, targets } = this;
|
|
51
|
+
if (!targets.has(currentTarget)) {
|
|
52
|
+
targets.set(currentTarget, {});
|
|
53
|
+
}
|
|
54
|
+
const targetData = targets.get(currentTarget);
|
|
55
|
+
targetData[target] = { keyframes, options };
|
|
56
|
+
}
|
|
57
|
+
then(resolve, reject) {
|
|
58
|
+
return this.readyPromise.then(resolve, reject);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function view(update, defaultOptions = {}) {
|
|
62
|
+
return new ViewTransitionBuilder(update, defaultOptions);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ViewTransitionBuilder, view };
|