@voila.dev/motion 0.0.0-stage → 5.0.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.
- package/README.md +105 -2
- package/dist/accessibility/reduced-motion.d.ts +13 -0
- package/dist/accessibility/reduced-motion.d.ts.map +1 -0
- package/dist/accessibility/reduced-motion.js +56 -0
- package/dist/accessibility/reduced-motion.js.map +7 -0
- package/dist/animate/animate.d.ts +21 -0
- package/dist/animate/animate.d.ts.map +1 -0
- package/dist/animate/animate.js +76 -0
- package/dist/animate/animate.js.map +7 -0
- package/dist/animate/controls.d.ts +16 -0
- package/dist/animate/controls.d.ts.map +1 -0
- package/dist/animate/controls.js +62 -0
- package/dist/animate/controls.js.map +7 -0
- package/dist/animate/dom.d.ts +11 -0
- package/dist/animate/dom.d.ts.map +1 -0
- package/dist/animate/dom.js +112 -0
- package/dist/animate/dom.js.map +7 -0
- package/dist/animate/js-animation.d.ts +25 -0
- package/dist/animate/js-animation.d.ts.map +1 -0
- package/dist/animate/js-animation.js +117 -0
- package/dist/animate/js-animation.js.map +7 -0
- package/dist/animate/plan.d.ts +17 -0
- package/dist/animate/plan.d.ts.map +1 -0
- package/dist/animate/plan.js +48 -0
- package/dist/animate/plan.js.map +7 -0
- package/dist/animate/style.d.ts +27 -0
- package/dist/animate/style.d.ts.map +1 -0
- package/dist/animate/style.js +96 -0
- package/dist/animate/style.js.map +7 -0
- package/dist/animate/types.d.ts +62 -0
- package/dist/animate/types.d.ts.map +1 -0
- package/dist/animate/types.js +1 -0
- package/dist/animate/types.js.map +7 -0
- package/dist/animate/value.d.ts +13 -0
- package/dist/animate/value.d.ts.map +1 -0
- package/dist/animate/value.js +71 -0
- package/dist/animate/value.js.map +7 -0
- package/dist/animate/waapi.d.ts +20 -0
- package/dist/animate/waapi.d.ts.map +1 -0
- package/dist/animate/waapi.js +152 -0
- package/dist/animate/waapi.js.map +7 -0
- package/dist/dom.d.ts +12 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +17 -0
- package/dist/dom.js.map +7 -0
- package/dist/easing/cubic-bezier.d.ts +4 -0
- package/dist/easing/cubic-bezier.d.ts.map +1 -0
- package/dist/easing/cubic-bezier.js +54 -0
- package/dist/easing/cubic-bezier.js.map +7 -0
- package/dist/easing/linear-css.d.ts +9 -0
- package/dist/easing/linear-css.d.ts.map +1 -0
- package/dist/easing/linear-css.js +30 -0
- package/dist/easing/linear-css.js.map +7 -0
- package/dist/easing/named.d.ts +16 -0
- package/dist/easing/named.d.ts.map +1 -0
- package/dist/easing/named.js +82 -0
- package/dist/easing/named.js.map +7 -0
- package/dist/easing/spring.d.ts +11 -0
- package/dist/easing/spring.d.ts.map +1 -0
- package/dist/easing/spring.js +18 -0
- package/dist/easing/spring.js.map +7 -0
- package/dist/easing/steps.d.ts +4 -0
- package/dist/easing/steps.d.ts.map +1 -0
- package/dist/easing/steps.js +14 -0
- package/dist/easing/steps.js.map +7 -0
- package/dist/easing/types.d.ts +5 -0
- package/dist/easing/types.d.ts.map +1 -0
- package/dist/easing/types.js +1 -0
- package/dist/easing/types.js.map +7 -0
- package/dist/frame/driver.d.ts +13 -0
- package/dist/frame/driver.d.ts.map +1 -0
- package/dist/frame/driver.js +42 -0
- package/dist/frame/driver.js.map +7 -0
- package/dist/frame/frame.d.ts +20 -0
- package/dist/frame/frame.d.ts.map +1 -0
- package/dist/frame/frame.js +77 -0
- package/dist/frame/frame.js.map +7 -0
- package/dist/generators/inertia.d.ts +20 -0
- package/dist/generators/inertia.d.ts.map +1 -0
- package/dist/generators/inertia.js +59 -0
- package/dist/generators/inertia.js.map +7 -0
- package/dist/generators/spring.d.ts +17 -0
- package/dist/generators/spring.d.ts.map +1 -0
- package/dist/generators/spring.js +87 -0
- package/dist/generators/spring.js.map +7 -0
- package/dist/generators/tween.d.ts +15 -0
- package/dist/generators/tween.d.ts.map +1 -0
- package/dist/generators/tween.js +51 -0
- package/dist/generators/tween.js.map +7 -0
- package/dist/generators/types.d.ts +30 -0
- package/dist/generators/types.d.ts.map +1 -0
- package/dist/generators/types.js +1 -0
- package/dist/generators/types.js.map +7 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +7 -0
- package/dist/interpolate/array.d.ts +3 -0
- package/dist/interpolate/array.d.ts.map +1 -0
- package/dist/interpolate/array.js +12 -0
- package/dist/interpolate/array.js.map +7 -0
- package/dist/interpolate/color-parse.d.ts +14 -0
- package/dist/interpolate/color-parse.d.ts.map +1 -0
- package/dist/interpolate/color-parse.js +111 -0
- package/dist/interpolate/color-parse.js.map +7 -0
- package/dist/interpolate/color.d.ts +11 -0
- package/dist/interpolate/color.d.ts.map +1 -0
- package/dist/interpolate/color.js +74 -0
- package/dist/interpolate/color.js.map +7 -0
- package/dist/interpolate/complex.d.ts +7 -0
- package/dist/interpolate/complex.d.ts.map +1 -0
- package/dist/interpolate/complex.js +56 -0
- package/dist/interpolate/complex.js.map +7 -0
- package/dist/interpolate/interpolate.d.ts +16 -0
- package/dist/interpolate/interpolate.d.ts.map +1 -0
- package/dist/interpolate/interpolate.js +39 -0
- package/dist/interpolate/interpolate.js.map +7 -0
- package/dist/interpolate/mix.d.ts +8 -0
- package/dist/interpolate/mix.d.ts.map +1 -0
- package/dist/interpolate/mix.js +48 -0
- package/dist/interpolate/mix.js.map +7 -0
- package/dist/interpolate/number.d.ts +2 -0
- package/dist/interpolate/number.d.ts.map +1 -0
- package/dist/interpolate/number.js +7 -0
- package/dist/interpolate/number.js.map +7 -0
- package/dist/interpolate/object.d.ts +5 -0
- package/dist/interpolate/object.d.ts.map +1 -0
- package/dist/interpolate/object.js +17 -0
- package/dist/interpolate/object.js.map +7 -0
- package/dist/interpolate/path/flatten.d.ts +10 -0
- package/dist/interpolate/path/flatten.d.ts.map +1 -0
- package/dist/interpolate/path/flatten.js +135 -0
- package/dist/interpolate/path/flatten.js.map +7 -0
- package/dist/interpolate/path/morph.d.ts +9 -0
- package/dist/interpolate/path/morph.d.ts.map +1 -0
- package/dist/interpolate/path/morph.js +72 -0
- package/dist/interpolate/path/morph.js.map +7 -0
- package/dist/interpolate/path/parse.d.ts +24 -0
- package/dist/interpolate/path/parse.d.ts.map +1 -0
- package/dist/interpolate/path/parse.js +125 -0
- package/dist/interpolate/path/parse.js.map +7 -0
- package/dist/interpolate/path/rings.d.ts +13 -0
- package/dist/interpolate/path/rings.d.ts.map +1 -0
- package/dist/interpolate/path/rings.js +117 -0
- package/dist/interpolate/path/rings.js.map +7 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +19 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/presence.d.ts +27 -0
- package/dist/react/presence.d.ts.map +1 -0
- package/dist/react/presence.js +135 -0
- package/dist/react/presence.js.map +7 -0
- package/dist/react/use-animate.d.ts +17 -0
- package/dist/react/use-animate.d.ts.map +1 -0
- package/dist/react/use-animate.js +34 -0
- package/dist/react/use-animate.js.map +7 -0
- package/dist/react/use-motion-value.d.ts +4 -0
- package/dist/react/use-motion-value.d.ts.map +1 -0
- package/dist/react/use-motion-value.js +11 -0
- package/dist/react/use-motion-value.js.map +7 -0
- package/dist/react/use-reduced-motion.d.ts +7 -0
- package/dist/react/use-reduced-motion.d.ts.map +1 -0
- package/dist/react/use-reduced-motion.js +19 -0
- package/dist/react/use-reduced-motion.js.map +7 -0
- package/dist/react/use-spring.d.ts +9 -0
- package/dist/react/use-spring.d.ts.map +1 -0
- package/dist/react/use-spring.js +27 -0
- package/dist/react/use-spring.js.map +7 -0
- package/dist/react/use-transform.d.ts +13 -0
- package/dist/react/use-transform.d.ts.map +1 -0
- package/dist/react/use-transform.js +44 -0
- package/dist/react/use-transform.js.map +7 -0
- package/dist/sequence/sequence.d.ts +25 -0
- package/dist/sequence/sequence.d.ts.map +1 -0
- package/dist/sequence/sequence.js +68 -0
- package/dist/sequence/sequence.js.map +7 -0
- package/dist/stagger/stagger.d.ts +12 -0
- package/dist/stagger/stagger.d.ts.map +1 -0
- package/dist/stagger/stagger.js +21 -0
- package/dist/stagger/stagger.js.map +7 -0
- package/dist/testing/manual-frames.d.ts +11 -0
- package/dist/testing/manual-frames.d.ts.map +1 -0
- package/dist/testing/manual-frames.js +40 -0
- package/dist/testing/manual-frames.js.map +7 -0
- package/dist/value/motion-value.d.ts +27 -0
- package/dist/value/motion-value.d.ts.map +1 -0
- package/dist/value/motion-value.js +88 -0
- package/dist/value/motion-value.js.map +7 -0
- package/dist/value/transform.d.ts +16 -0
- package/dist/value/transform.d.ts.map +1 -0
- package/dist/value/transform.js +28 -0
- package/dist/value/transform.js.map +7 -0
- package/dist/view/in-view.d.ts +19 -0
- package/dist/view/in-view.d.ts.map +1 -0
- package/dist/view/in-view.js +46 -0
- package/dist/view/in-view.js.map +7 -0
- package/dist/view/resize.d.ts +13 -0
- package/dist/view/resize.d.ts.map +1 -0
- package/dist/view/resize.js +72 -0
- package/dist/view/resize.js.map +7 -0
- package/dist/view/resolve-elements.d.ts +3 -0
- package/dist/view/resolve-elements.d.ts.map +1 -0
- package/dist/view/resolve-elements.js +10 -0
- package/dist/view/resolve-elements.js.map +7 -0
- package/dist/view/scroll-measure.d.ts +16 -0
- package/dist/view/scroll-measure.d.ts.map +1 -0
- package/dist/view/scroll-measure.js +51 -0
- package/dist/view/scroll-measure.js.map +7 -0
- package/dist/view/scroll-offset.d.ts +28 -0
- package/dist/view/scroll-offset.d.ts.map +1 -0
- package/dist/view/scroll-offset.js +55 -0
- package/dist/view/scroll-offset.js.map +7 -0
- package/dist/view/scroll.d.ts +34 -0
- package/dist/view/scroll.d.ts.map +1 -0
- package/dist/view/scroll.js +83 -0
- package/dist/view/scroll.js.map +7 -0
- package/package.json +57 -5
- package/src/accessibility/reduced-motion.ts +75 -0
- package/src/animate/animate.ts +155 -0
- package/src/animate/controls.ts +76 -0
- package/src/animate/dom.ts +166 -0
- package/src/animate/js-animation.ts +151 -0
- package/src/animate/plan.ts +74 -0
- package/src/animate/style.ts +131 -0
- package/src/animate/types.ts +69 -0
- package/src/animate/value.ts +93 -0
- package/src/animate/waapi.ts +212 -0
- package/src/dom.ts +35 -0
- package/src/easing/cubic-bezier.ts +64 -0
- package/src/easing/linear-css.ts +41 -0
- package/src/easing/named.ts +88 -0
- package/src/easing/spring.ts +25 -0
- package/src/easing/steps.ts +16 -0
- package/src/easing/types.ts +18 -0
- package/src/frame/driver.ts +56 -0
- package/src/frame/frame.ts +102 -0
- package/src/generators/inertia.ts +88 -0
- package/src/generators/spring.ts +117 -0
- package/src/generators/tween.ts +74 -0
- package/src/generators/types.ts +31 -0
- package/src/index.ts +91 -0
- package/src/interpolate/array.ts +13 -0
- package/src/interpolate/color-parse.ts +136 -0
- package/src/interpolate/color.ts +97 -0
- package/src/interpolate/complex.ts +80 -0
- package/src/interpolate/interpolate.ts +60 -0
- package/src/interpolate/mix.ts +74 -0
- package/src/interpolate/number.ts +3 -0
- package/src/interpolate/object.ts +20 -0
- package/src/interpolate/path/flatten.ts +185 -0
- package/src/interpolate/path/morph.ts +100 -0
- package/src/interpolate/path/parse.ts +162 -0
- package/src/interpolate/path/rings.ts +151 -0
- package/src/react/index.ts +11 -0
- package/src/react/presence.tsx +194 -0
- package/src/react/use-animate.ts +46 -0
- package/src/react/use-motion-value.ts +9 -0
- package/src/react/use-reduced-motion.ts +22 -0
- package/src/react/use-spring.ts +35 -0
- package/src/react/use-transform.ts +73 -0
- package/src/sequence/sequence.ts +129 -0
- package/src/stagger/stagger.ts +36 -0
- package/src/testing/browser-commands.d.ts +11 -0
- package/src/testing/manual-frames.ts +49 -0
- package/src/value/motion-value.ts +131 -0
- package/src/value/transform.ts +61 -0
- package/src/view/in-view.ts +74 -0
- package/src/view/resize.ts +101 -0
- package/src/view/resolve-elements.ts +11 -0
- package/src/view/scroll-measure.ts +83 -0
- package/src/view/scroll-offset.ts +100 -0
- package/src/view/scroll.ts +143 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { thenable } from "./controls.js";
|
|
2
|
+
import { iterationTime, planGenerator } from "./plan.js";
|
|
3
|
+
import { cssName } from "./style.js";
|
|
4
|
+
import { linearEasing, supportsLinearEasing } from "../easing/linear-css.js";
|
|
5
|
+
import { easingToCss, resolveEasing } from "../easing/named.js";
|
|
6
|
+
const SAMPLE_STEP = 1 / 60;
|
|
7
|
+
function cssEasing(definition, duration) {
|
|
8
|
+
return easingToCss(definition) ?? linearEasing(resolveEasing(definition), duration);
|
|
9
|
+
}
|
|
10
|
+
function browserKeyframes(config, generator, positional) {
|
|
11
|
+
const { keyframes, format, property, options } = config;
|
|
12
|
+
const duration = generator.duration;
|
|
13
|
+
const [from, to] = keyframes;
|
|
14
|
+
const springs = options.type !== "tween" && keyframes.length === 2 && !options.ease;
|
|
15
|
+
const span = typeof from === "number" && typeof to === "number" ? to - from : 1;
|
|
16
|
+
if (springs && span !== 0 && supportsLinearEasing()) {
|
|
17
|
+
const progress = (t) => {
|
|
18
|
+
const { value } = generator.at(t * duration);
|
|
19
|
+
return positional ? value : (value - from) / span;
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
keyframes: keyframes.map((frame) => ({ [property]: format(frame) })),
|
|
23
|
+
easing: linearEasing(progress, duration)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (springs && !positional) {
|
|
27
|
+
const count = Math.max(2, Math.ceil(duration / SAMPLE_STEP) + 1);
|
|
28
|
+
return {
|
|
29
|
+
keyframes: Array.from({ length: count }, (_unused, index) => {
|
|
30
|
+
const offset = index / (count - 1);
|
|
31
|
+
return {
|
|
32
|
+
[property]: format(generator.at(offset * duration).value),
|
|
33
|
+
offset
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
easing: "linear"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const ease = options.ease ?? "easeOut";
|
|
40
|
+
return {
|
|
41
|
+
keyframes: keyframes.map((frame, index) => ({
|
|
42
|
+
[property]: format(frame),
|
|
43
|
+
offset: options.times?.[index] ?? index / (keyframes.length - 1),
|
|
44
|
+
easing: cssEasing(
|
|
45
|
+
Array.isArray(ease) && typeof ease[0] !== "number" ? ease[index] ?? "linear" : ease,
|
|
46
|
+
duration
|
|
47
|
+
)
|
|
48
|
+
})),
|
|
49
|
+
easing: "linear"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const STATES = {
|
|
53
|
+
running: "running",
|
|
54
|
+
paused: "paused",
|
|
55
|
+
finished: "finished",
|
|
56
|
+
idle: "finished"
|
|
57
|
+
};
|
|
58
|
+
function waapiAnimation(config) {
|
|
59
|
+
const { element, keyframes, options, delay, commit } = config;
|
|
60
|
+
const { generator, positional } = planGenerator(
|
|
61
|
+
keyframes,
|
|
62
|
+
options,
|
|
63
|
+
config.velocity
|
|
64
|
+
);
|
|
65
|
+
const iterations = (options.repeat ?? 0) + 1;
|
|
66
|
+
const { keyframes: frames, easing } = browserKeyframes(
|
|
67
|
+
config,
|
|
68
|
+
generator,
|
|
69
|
+
positional
|
|
70
|
+
);
|
|
71
|
+
const animation = element.animate(frames, {
|
|
72
|
+
duration: generator.duration * 1e3,
|
|
73
|
+
delay: delay * 1e3,
|
|
74
|
+
iterations,
|
|
75
|
+
direction: options.repeatType === "reverse" ? "alternate" : "normal",
|
|
76
|
+
easing,
|
|
77
|
+
fill: "both",
|
|
78
|
+
composite: config.composite
|
|
79
|
+
});
|
|
80
|
+
const last = keyframes[options.repeatType === "reverse" && iterations % 2 === 0 ? 0 : keyframes.length - 1];
|
|
81
|
+
let settled = false;
|
|
82
|
+
let held = keyframes[0];
|
|
83
|
+
let resolve = () => {
|
|
84
|
+
};
|
|
85
|
+
const finished = new Promise((done) => {
|
|
86
|
+
resolve = done;
|
|
87
|
+
});
|
|
88
|
+
function current() {
|
|
89
|
+
if (settled) return { value: held, velocity: 0 };
|
|
90
|
+
const elapsed = (Number(animation.currentTime) || 0) / 1e3 - delay;
|
|
91
|
+
if (elapsed <= 0)
|
|
92
|
+
return { value: keyframes[0], velocity: 0 };
|
|
93
|
+
const state = generator.at(
|
|
94
|
+
iterationTime(elapsed, generator.duration, options)
|
|
95
|
+
);
|
|
96
|
+
if (!positional) return state;
|
|
97
|
+
const painted = config.composite === "replace" ? getComputedStyle(element).getPropertyValue(cssName(config.property)) : "";
|
|
98
|
+
return { value: painted || last, velocity: 0 };
|
|
99
|
+
}
|
|
100
|
+
function settle(value) {
|
|
101
|
+
if (settled) return;
|
|
102
|
+
settled = true;
|
|
103
|
+
if (value !== void 0) {
|
|
104
|
+
held = value;
|
|
105
|
+
commit(value);
|
|
106
|
+
}
|
|
107
|
+
animation.cancel();
|
|
108
|
+
resolve();
|
|
109
|
+
}
|
|
110
|
+
animation.finished.then(
|
|
111
|
+
() => {
|
|
112
|
+
if (settled) return;
|
|
113
|
+
settle(last);
|
|
114
|
+
config.onComplete?.();
|
|
115
|
+
},
|
|
116
|
+
() => settle(void 0)
|
|
117
|
+
);
|
|
118
|
+
return {
|
|
119
|
+
...thenable(finished),
|
|
120
|
+
get time() {
|
|
121
|
+
return (Number(animation.currentTime) || 0) / 1e3;
|
|
122
|
+
},
|
|
123
|
+
set time(seconds) {
|
|
124
|
+
animation.currentTime = seconds * 1e3;
|
|
125
|
+
},
|
|
126
|
+
get speed() {
|
|
127
|
+
return animation.playbackRate;
|
|
128
|
+
},
|
|
129
|
+
set speed(rate) {
|
|
130
|
+
animation.playbackRate = rate;
|
|
131
|
+
},
|
|
132
|
+
duration: delay + generator.duration * iterations,
|
|
133
|
+
get state() {
|
|
134
|
+
return settled ? "finished" : STATES[animation.playState];
|
|
135
|
+
},
|
|
136
|
+
play: () => animation.play(),
|
|
137
|
+
pause: () => animation.pause(),
|
|
138
|
+
stop: () => settle(current().value),
|
|
139
|
+
cancel: () => settle(keyframes[0]),
|
|
140
|
+
// The browser refuses to finish an endless animation: settle on its last frame instead.
|
|
141
|
+
complete: () => iterations === Number.POSITIVE_INFINITY ? settle(last) : animation.finish(),
|
|
142
|
+
attachTimeline(timeline) {
|
|
143
|
+
animation.timeline = timeline;
|
|
144
|
+
return true;
|
|
145
|
+
},
|
|
146
|
+
current
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
waapiAnimation
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=waapi.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/animate/waapi.ts"],
|
|
4
|
+
"sourcesContent": ["import { thenable } from \"#/animate/controls.ts\";\nimport type { JsAnimation } from \"#/animate/js-animation.ts\";\nimport { iterationTime, planGenerator } from \"#/animate/plan.ts\";\nimport { cssName } from \"#/animate/style.ts\";\nimport type {\n\tAnimationOptions,\n\tAnimationState,\n\tKeyframeValue,\n} from \"#/animate/types.ts\";\nimport { linearEasing, supportsLinearEasing } from \"#/easing/linear-css.ts\";\nimport { easingToCss, resolveEasing } from \"#/easing/named.ts\";\nimport type { EasingDefinition } from \"#/easing/types.ts\";\nimport type { Generator } from \"#/generators/types.ts\";\n\nexport interface WaapiConfig {\n\treadonly element: Element;\n\t/** The CSS property the browser animates. */\n\treadonly property: string;\n\treadonly keyframes: readonly KeyframeValue[];\n\t/** A keyframe as the property's CSS value. */\n\tformat(value: KeyframeValue): string;\n\treadonly options: AnimationOptions;\n\treadonly delay: number;\n\treadonly velocity: number;\n\treadonly composite: CompositeOperation;\n\t/** Writes the value that stays once the animation is gone. */\n\tcommit(value: KeyframeValue): void;\n\tonComplete?(): void;\n}\n\nconst SAMPLE_STEP = 1 / 60;\n\nfunction cssEasing(definition: EasingDefinition, duration: number): string {\n\treturn (\n\t\teasingToCss(definition) ?? linearEasing(resolveEasing(definition), duration)\n\t);\n}\n\n/**\n * The browser keyframes and easing. Two keyframes on a spring become one\n * `linear()` easing sampled from the spring, so the compositor plays the\n * exact curve. Without `linear()`, or when the spring starts and ends at the\n * same value (a flick of velocity), the spring is sampled into keyframes.\n */\nfunction browserKeyframes(\n\tconfig: WaapiConfig,\n\tgenerator: Generator,\n\tpositional: boolean,\n): { keyframes: Keyframe[]; easing: string } {\n\tconst { keyframes, format, property, options } = config;\n\tconst duration = generator.duration;\n\tconst [from, to] = keyframes;\n\tconst springs =\n\t\toptions.type !== \"tween\" && keyframes.length === 2 && !options.ease;\n\tconst span =\n\t\ttypeof from === \"number\" && typeof to === \"number\" ? to - from : 1;\n\tif (springs && span !== 0 && supportsLinearEasing()) {\n\t\tconst progress = (t: number) => {\n\t\t\tconst { value } = generator.at(t * duration);\n\t\t\treturn positional ? value : (value - (from as number)) / span;\n\t\t};\n\t\treturn {\n\t\t\tkeyframes: keyframes.map((frame) => ({ [property]: format(frame) })),\n\t\t\teasing: linearEasing(progress, duration),\n\t\t};\n\t}\n\tif (springs && !positional) {\n\t\tconst count = Math.max(2, Math.ceil(duration / SAMPLE_STEP) + 1);\n\t\treturn {\n\t\t\tkeyframes: Array.from({ length: count }, (_unused, index) => {\n\t\t\t\tconst offset = index / (count - 1);\n\t\t\t\treturn {\n\t\t\t\t\t[property]: format(generator.at(offset * duration).value),\n\t\t\t\t\toffset,\n\t\t\t\t};\n\t\t\t}),\n\t\t\teasing: \"linear\",\n\t\t};\n\t}\n\tconst ease = options.ease ?? \"easeOut\";\n\treturn {\n\t\tkeyframes: keyframes.map((frame, index) => ({\n\t\t\t[property]: format(frame),\n\t\t\toffset: options.times?.[index] ?? index / (keyframes.length - 1),\n\t\t\teasing: cssEasing(\n\t\t\t\tArray.isArray(ease) && typeof ease[0] !== \"number\"\n\t\t\t\t\t? ((ease as readonly EasingDefinition[])[index] ?? \"linear\")\n\t\t\t\t\t: (ease as EasingDefinition),\n\t\t\t\tduration,\n\t\t\t),\n\t\t})),\n\t\teasing: \"linear\",\n\t};\n}\n\nconst STATES: Record<AnimationPlayState, AnimationState> = {\n\trunning: \"running\",\n\tpaused: \"paused\",\n\tfinished: \"finished\",\n\tidle: \"finished\",\n};\n\n/** One CSS property of one element, played by the Web Animations API. */\nexport function waapiAnimation(\n\tconfig: WaapiConfig,\n): JsAnimation<KeyframeValue> {\n\tconst { element, keyframes, options, delay, commit } = config;\n\tconst { generator, positional } = planGenerator(\n\t\tkeyframes,\n\t\toptions,\n\t\tconfig.velocity,\n\t);\n\tconst iterations = (options.repeat ?? 0) + 1;\n\tconst { keyframes: frames, easing } = browserKeyframes(\n\t\tconfig,\n\t\tgenerator,\n\t\tpositional,\n\t);\n\tconst animation = element.animate(frames, {\n\t\tduration: generator.duration * 1000,\n\t\tdelay: delay * 1000,\n\t\titerations,\n\t\tdirection: options.repeatType === \"reverse\" ? \"alternate\" : \"normal\",\n\t\teasing,\n\t\tfill: \"both\",\n\t\tcomposite: config.composite,\n\t});\n\tconst last = keyframes[\n\t\toptions.repeatType === \"reverse\" && iterations % 2 === 0\n\t\t\t? 0\n\t\t\t: keyframes.length - 1\n\t] as KeyframeValue;\n\n\tlet settled = false;\n\t/** What stayed on screen when it settled: where a following animation starts. */\n\tlet held: KeyframeValue = keyframes[0] as KeyframeValue;\n\tlet resolve: () => void = () => {};\n\tconst finished = new Promise<void>((done) => {\n\t\tresolve = done;\n\t});\n\n\tfunction current() {\n\t\tif (settled) return { value: held, velocity: 0 };\n\t\tconst elapsed = (Number(animation.currentTime) || 0) / 1000 - delay;\n\t\tif (elapsed <= 0)\n\t\t\treturn { value: keyframes[0] as KeyframeValue, velocity: 0 };\n\t\tconst state = generator.at(\n\t\t\titerationTime(elapsed, generator.duration, options),\n\t\t);\n\t\tif (!positional) return state;\n\t\t// The browser mixes colours and strings itself: ask it what it painted.\n\t\tconst painted =\n\t\t\tconfig.composite === \"replace\"\n\t\t\t\t? getComputedStyle(element).getPropertyValue(cssName(config.property))\n\t\t\t\t: \"\";\n\t\treturn { value: painted || last, velocity: 0 };\n\t}\n\n\tfunction settle(value: KeyframeValue | undefined) {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\tif (value !== undefined) {\n\t\t\theld = value;\n\t\t\tcommit(value);\n\t\t}\n\t\tanimation.cancel();\n\t\tresolve();\n\t}\n\n\tanimation.finished.then(\n\t\t() => {\n\t\t\tif (settled) return;\n\t\t\tsettle(last);\n\t\t\tconfig.onComplete?.();\n\t\t},\n\t\t() => settle(undefined),\n\t);\n\n\treturn {\n\t\t...thenable(finished),\n\t\tget time() {\n\t\t\treturn (Number(animation.currentTime) || 0) / 1000;\n\t\t},\n\t\tset time(seconds) {\n\t\t\tanimation.currentTime = seconds * 1000;\n\t\t},\n\t\tget speed() {\n\t\t\treturn animation.playbackRate;\n\t\t},\n\t\tset speed(rate) {\n\t\t\tanimation.playbackRate = rate;\n\t\t},\n\t\tduration: delay + generator.duration * iterations,\n\t\tget state() {\n\t\t\treturn settled ? \"finished\" : STATES[animation.playState];\n\t\t},\n\t\tplay: () => animation.play(),\n\t\tpause: () => animation.pause(),\n\t\tstop: () => settle(current().value),\n\t\tcancel: () => settle(keyframes[0]),\n\t\t// The browser refuses to finish an endless animation: settle on its last frame instead.\n\t\tcomplete: () =>\n\t\t\titerations === Number.POSITIVE_INFINITY\n\t\t\t\t? settle(last)\n\t\t\t\t: animation.finish(),\n\t\tattachTimeline(timeline) {\n\t\t\tanimation.timeline = timeline;\n\t\t\treturn true;\n\t\t},\n\t\tcurrent,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnimationControls, AnimationOptions, DOMKeyframes, ElementTarget } from "./animate/types.js";
|
|
2
|
+
export type { AnimationControls, AnimationOptions, DOMKeyframes, ElementTarget, } from "./animate/types.js";
|
|
3
|
+
export { spring } from "./generators/spring.js";
|
|
4
|
+
export { stagger } from "./stagger/stagger.js";
|
|
5
|
+
/**
|
|
6
|
+
* `animate` for elements only, every property played by the browser: CSS
|
|
7
|
+
* properties and the independent transforms, with springs as `linear()`.
|
|
8
|
+
* What it can't hand to the browser (SVG attributes, CSS variables) jumps to
|
|
9
|
+
* its last keyframe: use the full `animate` for those.
|
|
10
|
+
*/
|
|
11
|
+
export declare function animate(target: ElementTarget, keyframes: DOMKeyframes, options?: AnimationOptions): AnimationControls;
|
|
12
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,OAAO,CACtB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,YAAY,EACvB,OAAO,GAAE,gBAAqB,GAC5B,iBAAiB,CAMnB"}
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { animateElements } from "./animate/dom.js";
|
|
2
|
+
import { resolveElements } from "./view/resolve-elements.js";
|
|
3
|
+
import { spring } from "./generators/spring.js";
|
|
4
|
+
import { stagger } from "./stagger/stagger.js";
|
|
5
|
+
function animate(target, keyframes, options = {}) {
|
|
6
|
+
return animateElements(
|
|
7
|
+
resolveElements(target),
|
|
8
|
+
keyframes,
|
|
9
|
+
options
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
animate,
|
|
14
|
+
spring,
|
|
15
|
+
stagger
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/dom.ts"],
|
|
4
|
+
"sourcesContent": ["import { animateElements } from \"#/animate/dom.ts\";\nimport type {\n\tAnimationControls,\n\tAnimationOptions,\n\tDOMKeyframes,\n\tElementTarget,\n} from \"#/animate/types.ts\";\nimport { resolveElements } from \"#/view/resolve-elements.ts\";\n\nexport type {\n\tAnimationControls,\n\tAnimationOptions,\n\tDOMKeyframes,\n\tElementTarget,\n} from \"#/animate/types.ts\";\nexport { spring } from \"#/generators/spring.ts\";\nexport { stagger } from \"#/stagger/stagger.ts\";\n\n/**\n * `animate` for elements only, every property played by the browser: CSS\n * properties and the independent transforms, with springs as `linear()`.\n * What it can't hand to the browser (SVG attributes, CSS variables) jumps to\n * its last keyframe: use the full `animate` for those.\n */\nexport function animate(\n\ttarget: ElementTarget,\n\tkeyframes: DOMKeyframes,\n\toptions: AnimationOptions = {},\n): AnimationControls {\n\treturn animateElements(\n\t\tresolveElements(target as Element | string | readonly Element[]),\n\t\tkeyframes,\n\t\toptions,\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAOhC,SAAS,uBAAuB;AAQhC,SAAS,cAAc;AACvB,SAAS,eAAe;AAQjB,SAAS,QACf,QACA,WACA,UAA4B,CAAC,GACT;AACpB,SAAO;AAAA,IACN,gBAAgB,MAA+C;AAAA,IAC/D;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cubic-bezier.d.ts","sourceRoot":"","sources":["../../src/easing/cubic-bezier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AA+ChD,wDAAwD;AACxD,wBAAgB,WAAW,CAC1B,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,GACR,MAAM,CAUR"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function linear(progress) {
|
|
2
|
+
return progress;
|
|
3
|
+
}
|
|
4
|
+
function coordinate(t, p1, p2) {
|
|
5
|
+
return ((1 - 3 * p2 + 3 * p1) * t + (3 * p2 - 6 * p1)) * t * t + 3 * p1 * t;
|
|
6
|
+
}
|
|
7
|
+
function slope(t, p1, p2) {
|
|
8
|
+
return 3 * (1 - 3 * p2 + 3 * p1) * t * t + 2 * (3 * p2 - 6 * p1) * t + 3 * p1;
|
|
9
|
+
}
|
|
10
|
+
function solveT(x, x1, x2) {
|
|
11
|
+
let t = x;
|
|
12
|
+
for (let iteration = 0; iteration < 8; iteration += 1) {
|
|
13
|
+
const error = coordinate(t, x1, x2) - x;
|
|
14
|
+
if (Math.abs(error) < 1e-7) {
|
|
15
|
+
return t;
|
|
16
|
+
}
|
|
17
|
+
const derivative = slope(t, x1, x2);
|
|
18
|
+
if (Math.abs(derivative) < 1e-6) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
t -= error / derivative;
|
|
22
|
+
}
|
|
23
|
+
let low = 0;
|
|
24
|
+
let high = 1;
|
|
25
|
+
t = x;
|
|
26
|
+
for (let iteration = 0; iteration < 24; iteration += 1) {
|
|
27
|
+
const value = coordinate(t, x1, x2);
|
|
28
|
+
if (Math.abs(value - x) < 1e-7) {
|
|
29
|
+
return t;
|
|
30
|
+
}
|
|
31
|
+
if (value < x) {
|
|
32
|
+
low = t;
|
|
33
|
+
} else {
|
|
34
|
+
high = t;
|
|
35
|
+
}
|
|
36
|
+
t = (low + high) / 2;
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
41
|
+
if (x1 === y1 && x2 === y2) {
|
|
42
|
+
return linear;
|
|
43
|
+
}
|
|
44
|
+
return function bezier(progress) {
|
|
45
|
+
if (progress <= 0 || progress >= 1) {
|
|
46
|
+
return progress <= 0 ? 0 : 1;
|
|
47
|
+
}
|
|
48
|
+
return coordinate(solveT(progress, x1, x2), y1, y2);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
cubicBezier
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=cubic-bezier.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/easing/cubic-bezier.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Easing } from \"#/easing/types.ts\";\n\nfunction linear(progress: number): number {\n\treturn progress;\n}\n\n/** One coordinate of the curve at parameter `t`, with P0 = 0 and P3 = 1. */\nfunction coordinate(t: number, p1: number, p2: number): number {\n\treturn ((1 - 3 * p2 + 3 * p1) * t + (3 * p2 - 6 * p1)) * t * t + 3 * p1 * t;\n}\n\nfunction slope(t: number, p1: number, p2: number): number {\n\treturn 3 * (1 - 3 * p2 + 3 * p1) * t * t + 2 * (3 * p2 - 6 * p1) * t + 3 * p1;\n}\n\n/** The curve's parameter whose x is `x`: Newton first, bisection when the slope flattens. */\nfunction solveT(x: number, x1: number, x2: number): number {\n\tlet t = x;\n\tfor (let iteration = 0; iteration < 8; iteration += 1) {\n\t\tconst error = coordinate(t, x1, x2) - x;\n\t\tif (Math.abs(error) < 1e-7) {\n\t\t\treturn t;\n\t\t}\n\t\tconst derivative = slope(t, x1, x2);\n\t\tif (Math.abs(derivative) < 1e-6) {\n\t\t\tbreak;\n\t\t}\n\t\tt -= error / derivative;\n\t}\n\tlet low = 0;\n\tlet high = 1;\n\tt = x;\n\tfor (let iteration = 0; iteration < 24; iteration += 1) {\n\t\tconst value = coordinate(t, x1, x2);\n\t\tif (Math.abs(value - x) < 1e-7) {\n\t\t\treturn t;\n\t\t}\n\t\tif (value < x) {\n\t\t\tlow = t;\n\t\t} else {\n\t\t\thigh = t;\n\t\t}\n\t\tt = (low + high) / 2;\n\t}\n\treturn t;\n}\n\n/** CSS `cubic-bezier(x1, y1, x2, y2)` as a function. */\nexport function cubicBezier(\n\tx1: number,\n\ty1: number,\n\tx2: number,\n\ty2: number,\n): Easing {\n\tif (x1 === y1 && x2 === y2) {\n\t\treturn linear;\n\t}\n\treturn function bezier(progress) {\n\t\tif (progress <= 0 || progress >= 1) {\n\t\t\treturn progress <= 0 ? 0 : 1;\n\t\t}\n\t\treturn coordinate(solveT(progress, x1, x2), y1, y2);\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,OAAO,UAA0B;AACzC,SAAO;AACR;AAGA,SAAS,WAAW,GAAW,IAAY,IAAoB;AAC9D,WAAS,IAAI,IAAI,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK;AAC3E;AAEA,SAAS,MAAM,GAAW,IAAY,IAAoB;AACzD,SAAO,KAAK,IAAI,IAAI,KAAK,IAAI,MAAM,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,IAAI;AAC5E;AAGA,SAAS,OAAO,GAAW,IAAY,IAAoB;AAC1D,MAAI,IAAI;AACR,WAAS,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG;AACtD,UAAM,QAAQ,WAAW,GAAG,IAAI,EAAE,IAAI;AACtC,QAAI,KAAK,IAAI,KAAK,IAAI,MAAM;AAC3B,aAAO;AAAA,IACR;AACA,UAAM,aAAa,MAAM,GAAG,IAAI,EAAE;AAClC,QAAI,KAAK,IAAI,UAAU,IAAI,MAAM;AAChC;AAAA,IACD;AACA,SAAK,QAAQ;AAAA,EACd;AACA,MAAI,MAAM;AACV,MAAI,OAAO;AACX,MAAI;AACJ,WAAS,YAAY,GAAG,YAAY,IAAI,aAAa,GAAG;AACvD,UAAM,QAAQ,WAAW,GAAG,IAAI,EAAE;AAClC,QAAI,KAAK,IAAI,QAAQ,CAAC,IAAI,MAAM;AAC/B,aAAO;AAAA,IACR;AACA,QAAI,QAAQ,GAAG;AACd,YAAM;AAAA,IACP,OAAO;AACN,aAAO;AAAA,IACR;AACA,SAAK,MAAM,QAAQ;AAAA,EACpB;AACA,SAAO;AACR;AAGO,SAAS,YACf,IACA,IACA,IACA,IACS;AACT,MAAI,OAAO,MAAM,OAAO,IAAI;AAC3B,WAAO;AAAA,EACR;AACA,SAAO,SAAS,OAAO,UAAU;AAChC,QAAI,YAAY,KAAK,YAAY,GAAG;AACnC,aAAO,YAAY,IAAI,IAAI;AAAA,IAC5B;AACA,WAAO,WAAW,OAAO,UAAU,IAAI,EAAE,GAAG,IAAI,EAAE;AAAA,EACnD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Easing } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Any easing as a CSS `linear()` string, so the browser plays a spring or a
|
|
4
|
+
* custom curve off the main thread. `duration` and `step` are in seconds:
|
|
5
|
+
* longer motions need more points to stay smooth.
|
|
6
|
+
*/
|
|
7
|
+
export declare function linearEasing(sample: Easing, duration: number, step?: number): string;
|
|
8
|
+
export declare function supportsLinearEasing(): boolean;
|
|
9
|
+
//# sourceMappingURL=linear-css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-css.d.ts","sourceRoot":"","sources":["../../src/easing/linear-css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAShD;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,SAAO,GACT,MAAM,CAUR;AAID,wBAAgB,oBAAoB,IAAI,OAAO,CAQ9C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const MAX_POINTS = 200;
|
|
2
|
+
function round(value) {
|
|
3
|
+
return String(Math.round(value * 1e4) / 1e4);
|
|
4
|
+
}
|
|
5
|
+
function linearEasing(sample, duration, step = 0.01) {
|
|
6
|
+
const intervals = Math.min(
|
|
7
|
+
MAX_POINTS - 1,
|
|
8
|
+
Math.max(1, Math.ceil(duration / step))
|
|
9
|
+
);
|
|
10
|
+
const points = [];
|
|
11
|
+
for (let index = 0; index <= intervals; index += 1) {
|
|
12
|
+
points.push(round(sample(index / intervals)));
|
|
13
|
+
}
|
|
14
|
+
return `linear(${points.join(", ")})`;
|
|
15
|
+
}
|
|
16
|
+
let supported;
|
|
17
|
+
function supportsLinearEasing() {
|
|
18
|
+
if (supported === void 0) {
|
|
19
|
+
if (typeof CSS === "undefined" || typeof CSS.supports !== "function") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
supported = CSS.supports("animation-timing-function", "linear(0, 1)");
|
|
23
|
+
}
|
|
24
|
+
return supported;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
linearEasing,
|
|
28
|
+
supportsLinearEasing
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=linear-css.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/easing/linear-css.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Easing } from \"#/easing/types.ts\";\n\n/** Past this many points the string grows with no visible gain. */\nconst MAX_POINTS = 200;\n\nfunction round(value: number): string {\n\treturn String(Math.round(value * 10_000) / 10_000);\n}\n\n/**\n * Any easing as a CSS `linear()` string, so the browser plays a spring or a\n * custom curve off the main thread. `duration` and `step` are in seconds:\n * longer motions need more points to stay smooth.\n */\nexport function linearEasing(\n\tsample: Easing,\n\tduration: number,\n\tstep = 0.01,\n): string {\n\tconst intervals = Math.min(\n\t\tMAX_POINTS - 1,\n\t\tMath.max(1, Math.ceil(duration / step)),\n\t);\n\tconst points: string[] = [];\n\tfor (let index = 0; index <= intervals; index += 1) {\n\t\tpoints.push(round(sample(index / intervals)));\n\t}\n\treturn `linear(${points.join(\", \")})`;\n}\n\nlet supported: boolean | undefined;\n\nexport function supportsLinearEasing(): boolean {\n\tif (supported === undefined) {\n\t\tif (typeof CSS === \"undefined\" || typeof CSS.supports !== \"function\") {\n\t\t\treturn false;\n\t\t}\n\t\tsupported = CSS.supports(\"animation-timing-function\", \"linear(0, 1)\");\n\t}\n\treturn supported;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,MAAM,aAAa;AAEnB,SAAS,MAAM,OAAuB;AACrC,SAAO,OAAO,KAAK,MAAM,QAAQ,GAAM,IAAI,GAAM;AAClD;AAOO,SAAS,aACf,QACA,UACA,OAAO,MACE;AACT,QAAM,YAAY,KAAK;AAAA,IACtB,aAAa;AAAA,IACb,KAAK,IAAI,GAAG,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,EACvC;AACA,QAAM,SAAmB,CAAC;AAC1B,WAAS,QAAQ,GAAG,SAAS,WAAW,SAAS,GAAG;AACnD,WAAO,KAAK,MAAM,OAAO,QAAQ,SAAS,CAAC,CAAC;AAAA,EAC7C;AACA,SAAO,UAAU,OAAO,KAAK,IAAI,CAAC;AACnC;AAEA,IAAI;AAEG,SAAS,uBAAgC;AAC/C,MAAI,cAAc,QAAW;AAC5B,QAAI,OAAO,QAAQ,eAAe,OAAO,IAAI,aAAa,YAAY;AACrE,aAAO;AAAA,IACR;AACA,gBAAY,IAAI,SAAS,6BAA6B,cAAc;AAAA,EACrE;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Easing, EasingDefinition } from "./types.js";
|
|
2
|
+
export declare const linear: Easing;
|
|
3
|
+
export declare const easeIn: Easing;
|
|
4
|
+
export declare const easeOut: Easing;
|
|
5
|
+
export declare const easeInOut: Easing;
|
|
6
|
+
export declare const circIn: Easing;
|
|
7
|
+
export declare const circOut: Easing;
|
|
8
|
+
export declare const circInOut: Easing;
|
|
9
|
+
export declare const backIn: Easing;
|
|
10
|
+
export declare const backOut: Easing;
|
|
11
|
+
export declare const backInOut: Easing;
|
|
12
|
+
export declare const anticipate: Easing;
|
|
13
|
+
export declare function resolveEasing(definition: EasingDefinition): Easing;
|
|
14
|
+
/** A CSS `<easing-function>` for the definition, or undefined when only sampling can express it. */
|
|
15
|
+
export declare function easingToCss(definition: EasingDefinition): string | undefined;
|
|
16
|
+
//# sourceMappingURL=named.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named.d.ts","sourceRoot":"","sources":["../../src/easing/named.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,MAAM,EACN,gBAAgB,EAEhB,MAAM,mBAAmB,CAAC;AAsB3B,eAAO,MAAM,MAAM,EAAE,MAA+B,CAAC;AACrD,eAAO,MAAM,MAAM,QAA6B,CAAC;AACjD,eAAO,MAAM,OAAO,QAA6B,CAAC;AAClD,eAAO,MAAM,SAAS,QAAgC,CAAC;AACvD,eAAO,MAAM,MAAM,EAAE,MACuC,CAAC;AAC7D,eAAO,MAAM,OAAO,QAAkB,CAAC;AACvC,eAAO,MAAM,SAAS,QAAiB,CAAC;AACxC,eAAO,MAAM,MAAM,QAAuC,CAAC;AAC3D,eAAO,MAAM,OAAO,QAAsC,CAAC;AAC3D,eAAO,MAAM,SAAS,QAAiB,CAAC;AACxC,eAAO,MAAM,UAAU,EAAE,MAKxB,CAAC;AAgBF,wBAAgB,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM,CAQlE;AAMD,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAY5E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { cubicBezier } from "./cubic-bezier.js";
|
|
2
|
+
function reverse(easing) {
|
|
3
|
+
return (progress) => 1 - easing(1 - progress);
|
|
4
|
+
}
|
|
5
|
+
function mirror(easing) {
|
|
6
|
+
return (progress) => progress <= 0.5 ? easing(2 * progress) / 2 : (2 - easing(2 * (1 - progress))) / 2;
|
|
7
|
+
}
|
|
8
|
+
const BEZIERS = {
|
|
9
|
+
easeIn: [0.42, 0, 1, 1],
|
|
10
|
+
easeOut: [0, 0, 0.58, 1],
|
|
11
|
+
easeInOut: [0.42, 0, 0.58, 1],
|
|
12
|
+
backIn: [0.31, 0.01, 0.66, -0.59],
|
|
13
|
+
backOut: [0.33, 1.53, 0.69, 0.99]
|
|
14
|
+
};
|
|
15
|
+
const linear = (progress) => progress;
|
|
16
|
+
const easeIn = cubicBezier(0.42, 0, 1, 1);
|
|
17
|
+
const easeOut = cubicBezier(0, 0, 0.58, 1);
|
|
18
|
+
const easeInOut = cubicBezier(0.42, 0, 0.58, 1);
|
|
19
|
+
const circIn = (progress) => 1 - Math.sin(Math.acos(Math.min(1, Math.max(0, progress))));
|
|
20
|
+
const circOut = reverse(circIn);
|
|
21
|
+
const circInOut = mirror(circIn);
|
|
22
|
+
const backIn = cubicBezier(0.31, 0.01, 0.66, -0.59);
|
|
23
|
+
const backOut = cubicBezier(0.33, 1.53, 0.69, 0.99);
|
|
24
|
+
const backInOut = mirror(backIn);
|
|
25
|
+
const anticipate = (progress) => {
|
|
26
|
+
const doubled = progress * 2;
|
|
27
|
+
return doubled < 1 ? 0.5 * backIn(doubled) : 0.5 * (2 - 2 ** (-10 * (doubled - 1)));
|
|
28
|
+
};
|
|
29
|
+
const NAMED = {
|
|
30
|
+
linear,
|
|
31
|
+
easeIn,
|
|
32
|
+
easeOut,
|
|
33
|
+
easeInOut,
|
|
34
|
+
circIn,
|
|
35
|
+
circOut,
|
|
36
|
+
circInOut,
|
|
37
|
+
backIn,
|
|
38
|
+
backOut,
|
|
39
|
+
backInOut,
|
|
40
|
+
anticipate
|
|
41
|
+
};
|
|
42
|
+
function resolveEasing(definition) {
|
|
43
|
+
if (typeof definition === "function") {
|
|
44
|
+
return definition;
|
|
45
|
+
}
|
|
46
|
+
if (typeof definition === "string") {
|
|
47
|
+
return NAMED[definition];
|
|
48
|
+
}
|
|
49
|
+
return cubicBezier(...definition);
|
|
50
|
+
}
|
|
51
|
+
function bezierCss([x1, y1, x2, y2]) {
|
|
52
|
+
return `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`;
|
|
53
|
+
}
|
|
54
|
+
function easingToCss(definition) {
|
|
55
|
+
if (typeof definition === "function") {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
if (typeof definition !== "string") {
|
|
59
|
+
return bezierCss(definition);
|
|
60
|
+
}
|
|
61
|
+
if (definition === "linear") {
|
|
62
|
+
return "linear";
|
|
63
|
+
}
|
|
64
|
+
const bezier = BEZIERS[definition];
|
|
65
|
+
return bezier === void 0 ? void 0 : bezierCss(bezier);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
anticipate,
|
|
69
|
+
backIn,
|
|
70
|
+
backInOut,
|
|
71
|
+
backOut,
|
|
72
|
+
circIn,
|
|
73
|
+
circInOut,
|
|
74
|
+
circOut,
|
|
75
|
+
easeIn,
|
|
76
|
+
easeInOut,
|
|
77
|
+
easeOut,
|
|
78
|
+
easingToCss,
|
|
79
|
+
linear,
|
|
80
|
+
resolveEasing
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=named.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/easing/named.ts"],
|
|
4
|
+
"sourcesContent": ["import { cubicBezier } from \"#/easing/cubic-bezier.ts\";\nimport type {\n\tCubicBezier,\n\tEasing,\n\tEasingDefinition,\n\tEasingName,\n} from \"#/easing/types.ts\";\n\nfunction reverse(easing: Easing): Easing {\n\treturn (progress) => 1 - easing(1 - progress);\n}\n\nfunction mirror(easing: Easing): Easing {\n\treturn (progress) =>\n\t\tprogress <= 0.5\n\t\t\t? easing(2 * progress) / 2\n\t\t\t: (2 - easing(2 * (1 - progress))) / 2;\n}\n\n/** The named easings that are plain CSS curves, so WAAPI plays them natively. */\nconst BEZIERS: Partial<Record<EasingName, CubicBezier>> = {\n\teaseIn: [0.42, 0, 1, 1],\n\teaseOut: [0, 0, 0.58, 1],\n\teaseInOut: [0.42, 0, 0.58, 1],\n\tbackIn: [0.31, 0.01, 0.66, -0.59],\n\tbackOut: [0.33, 1.53, 0.69, 0.99],\n};\n\nexport const linear: Easing = (progress) => progress;\nexport const easeIn = cubicBezier(0.42, 0, 1, 1);\nexport const easeOut = cubicBezier(0, 0, 0.58, 1);\nexport const easeInOut = cubicBezier(0.42, 0, 0.58, 1);\nexport const circIn: Easing = (progress) =>\n\t1 - Math.sin(Math.acos(Math.min(1, Math.max(0, progress))));\nexport const circOut = reverse(circIn);\nexport const circInOut = mirror(circIn);\nexport const backIn = cubicBezier(0.31, 0.01, 0.66, -0.59);\nexport const backOut = cubicBezier(0.33, 1.53, 0.69, 0.99);\nexport const backInOut = mirror(backIn);\nexport const anticipate: Easing = (progress) => {\n\tconst doubled = progress * 2;\n\treturn doubled < 1\n\t\t? 0.5 * backIn(doubled)\n\t\t: 0.5 * (2 - 2 ** (-10 * (doubled - 1)));\n};\n\nconst NAMED: Record<EasingName, Easing> = {\n\tlinear,\n\teaseIn,\n\teaseOut,\n\teaseInOut,\n\tcircIn,\n\tcircOut,\n\tcircInOut,\n\tbackIn,\n\tbackOut,\n\tbackInOut,\n\tanticipate,\n};\n\nexport function resolveEasing(definition: EasingDefinition): Easing {\n\tif (typeof definition === \"function\") {\n\t\treturn definition;\n\t}\n\tif (typeof definition === \"string\") {\n\t\treturn NAMED[definition];\n\t}\n\treturn cubicBezier(...definition);\n}\n\nfunction bezierCss([x1, y1, x2, y2]: CubicBezier): string {\n\treturn `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`;\n}\n\n/** A CSS `<easing-function>` for the definition, or undefined when only sampling can express it. */\nexport function easingToCss(definition: EasingDefinition): string | undefined {\n\tif (typeof definition === \"function\") {\n\t\treturn undefined;\n\t}\n\tif (typeof definition !== \"string\") {\n\t\treturn bezierCss(definition);\n\t}\n\tif (definition === \"linear\") {\n\t\treturn \"linear\";\n\t}\n\tconst bezier = BEZIERS[definition];\n\treturn bezier === undefined ? undefined : bezierCss(bezier);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAQ5B,SAAS,QAAQ,QAAwB;AACxC,SAAO,CAAC,aAAa,IAAI,OAAO,IAAI,QAAQ;AAC7C;AAEA,SAAS,OAAO,QAAwB;AACvC,SAAO,CAAC,aACP,YAAY,MACT,OAAO,IAAI,QAAQ,IAAI,KACtB,IAAI,OAAO,KAAK,IAAI,SAAS,KAAK;AACxC;AAGA,MAAM,UAAoD;AAAA,EACzD,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;AAAA,EACtB,SAAS,CAAC,GAAG,GAAG,MAAM,CAAC;AAAA,EACvB,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC;AAAA,EAC5B,QAAQ,CAAC,MAAM,MAAM,MAAM,KAAK;AAAA,EAChC,SAAS,CAAC,MAAM,MAAM,MAAM,IAAI;AACjC;AAEO,MAAM,SAAiB,CAAC,aAAa;AACrC,MAAM,SAAS,YAAY,MAAM,GAAG,GAAG,CAAC;AACxC,MAAM,UAAU,YAAY,GAAG,GAAG,MAAM,CAAC;AACzC,MAAM,YAAY,YAAY,MAAM,GAAG,MAAM,CAAC;AAC9C,MAAM,SAAiB,CAAC,aAC9B,IAAI,KAAK,IAAI,KAAK,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC;AACpD,MAAM,UAAU,QAAQ,MAAM;AAC9B,MAAM,YAAY,OAAO,MAAM;AAC/B,MAAM,SAAS,YAAY,MAAM,MAAM,MAAM,KAAK;AAClD,MAAM,UAAU,YAAY,MAAM,MAAM,MAAM,IAAI;AAClD,MAAM,YAAY,OAAO,MAAM;AAC/B,MAAM,aAAqB,CAAC,aAAa;AAC/C,QAAM,UAAU,WAAW;AAC3B,SAAO,UAAU,IACd,MAAM,OAAO,OAAO,IACpB,OAAO,IAAI,MAAM,OAAO,UAAU;AACtC;AAEA,MAAM,QAAoC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,SAAS,cAAc,YAAsC;AACnE,MAAI,OAAO,eAAe,YAAY;AACrC,WAAO;AAAA,EACR;AACA,MAAI,OAAO,eAAe,UAAU;AACnC,WAAO,MAAM,UAAU;AAAA,EACxB;AACA,SAAO,YAAY,GAAG,UAAU;AACjC;AAEA,SAAS,UAAU,CAAC,IAAI,IAAI,IAAI,EAAE,GAAwB;AACzD,SAAO,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;AAC/C;AAGO,SAAS,YAAY,YAAkD;AAC7E,MAAI,OAAO,eAAe,YAAY;AACrC,WAAO;AAAA,EACR;AACA,MAAI,OAAO,eAAe,UAAU;AACnC,WAAO,UAAU,UAAU;AAAA,EAC5B;AACA,MAAI,eAAe,UAAU;AAC5B,WAAO;AAAA,EACR;AACA,QAAM,SAAS,QAAQ,UAAU;AACjC,SAAO,WAAW,SAAY,SAAY,UAAU,MAAM;AAC3D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Easing } from "./types.js";
|
|
2
|
+
import type { SpringOptions } from "../generators/types.js";
|
|
3
|
+
export interface SpringEasing {
|
|
4
|
+
/** Seconds until the spring settles: the WAAPI duration to play `easing` over. */
|
|
5
|
+
readonly duration: number;
|
|
6
|
+
readonly easing: string;
|
|
7
|
+
readonly at: Easing;
|
|
8
|
+
}
|
|
9
|
+
/** A spring from 0 to 1 as an easing: what WAAPI plays for a DOM spring. */
|
|
10
|
+
export declare function springEasing(options?: SpringOptions): SpringEasing;
|
|
11
|
+
//# sourceMappingURL=spring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring.d.ts","sourceRoot":"","sources":["../../src/easing/spring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACpB;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,YAAY,CAWtE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { linearEasing } from "./linear-css.js";
|
|
2
|
+
import { spring } from "../generators/spring.js";
|
|
3
|
+
function springEasing(options = {}) {
|
|
4
|
+
const generator = spring({ ...options, from: 0, to: 1 });
|
|
5
|
+
const duration = generator.duration;
|
|
6
|
+
function at(progress) {
|
|
7
|
+
return generator.at(progress * duration).value;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
duration,
|
|
11
|
+
easing: duration > 0 ? linearEasing(at, duration) : "linear(0, 1)",
|
|
12
|
+
at
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
springEasing
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=spring.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/easing/spring.ts"],
|
|
4
|
+
"sourcesContent": ["import { linearEasing } from \"#/easing/linear-css.ts\";\nimport type { Easing } from \"#/easing/types.ts\";\nimport { spring } from \"#/generators/spring.ts\";\nimport type { SpringOptions } from \"#/generators/types.ts\";\n\nexport interface SpringEasing {\n\t/** Seconds until the spring settles: the WAAPI duration to play `easing` over. */\n\treadonly duration: number;\n\treadonly easing: string;\n\treadonly at: Easing;\n}\n\n/** A spring from 0 to 1 as an easing: what WAAPI plays for a DOM spring. */\nexport function springEasing(options: SpringOptions = {}): SpringEasing {\n\tconst generator = spring({ ...options, from: 0, to: 1 });\n\tconst duration = generator.duration;\n\tfunction at(progress: number): number {\n\t\treturn generator.at(progress * duration).value;\n\t}\n\treturn {\n\t\tduration,\n\t\teasing: duration > 0 ? linearEasing(at, duration) : \"linear(0, 1)\",\n\t\tat,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,cAAc;AAWhB,SAAS,aAAa,UAAyB,CAAC,GAAiB;AACvE,QAAM,YAAY,OAAO,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,EAAE,CAAC;AACvD,QAAM,WAAW,UAAU;AAC3B,WAAS,GAAG,UAA0B;AACrC,WAAO,UAAU,GAAG,WAAW,QAAQ,EAAE;AAAA,EAC1C;AACA,SAAO;AAAA,IACN;AAAA,IACA,QAAQ,WAAW,IAAI,aAAa,IAAI,QAAQ,IAAI;AAAA,IACpD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/easing/steps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,iDAAiD;AACjD,wBAAgB,KAAK,CACpB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,OAAO,GAAG,KAAa,GAChC,MAAM,CASR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function steps(count, direction = "end") {
|
|
2
|
+
const jump = direction === "start" ? 1 : 0;
|
|
3
|
+
return function stepped(progress) {
|
|
4
|
+
if (progress >= 1) {
|
|
5
|
+
return 1;
|
|
6
|
+
}
|
|
7
|
+
const clamped = Math.max(0, progress);
|
|
8
|
+
return Math.min(1, (Math.floor(clamped * count) + jump) / count);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
steps
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=steps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/easing/steps.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Easing } from \"#/easing/types.ts\";\n\n/** CSS `steps(count, jump-start | jump-end)`. */\nexport function steps(\n\tcount: number,\n\tdirection: \"start\" | \"end\" = \"end\",\n): Easing {\n\tconst jump = direction === \"start\" ? 1 : 0;\n\treturn function stepped(progress) {\n\t\tif (progress >= 1) {\n\t\t\treturn 1;\n\t\t}\n\t\tconst clamped = Math.max(0, progress);\n\t\treturn Math.min(1, (Math.floor(clamped * count) + jump) / count);\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGO,SAAS,MACf,OACA,YAA6B,OACpB;AACT,QAAM,OAAO,cAAc,UAAU,IAAI;AACzC,SAAO,SAAS,QAAQ,UAAU;AACjC,QAAI,YAAY,GAAG;AAClB,aAAO;AAAA,IACR;AACA,UAAM,UAAU,KAAK,IAAI,GAAG,QAAQ;AACpC,WAAO,KAAK,IAAI,IAAI,KAAK,MAAM,UAAU,KAAK,IAAI,QAAQ,KAAK;AAAA,EAChE;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Easing = (progress: number) => number;
|
|
2
|
+
export type CubicBezier = readonly [number, number, number, number];
|
|
3
|
+
export type EasingName = "linear" | "easeIn" | "easeOut" | "easeInOut" | "circIn" | "circOut" | "circInOut" | "backIn" | "backOut" | "backInOut" | "anticipate";
|
|
4
|
+
export type EasingDefinition = EasingName | CubicBezier | Easing;
|
|
5
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/easing/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpE,MAAM,MAAM,UAAU,GACnB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,GACT,WAAW,GACX,YAAY,CAAC;AAEhB,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What ticks the frame loop: the browser's frames by default, a test clock when injected. */
|
|
2
|
+
export interface FrameDriver {
|
|
3
|
+
request(tick: (timestamp: number) => void): void;
|
|
4
|
+
cancel(): void;
|
|
5
|
+
/** Milliseconds, on the same clock as the timestamps handed to `tick`. */
|
|
6
|
+
now(): number;
|
|
7
|
+
}
|
|
8
|
+
export declare function frameDriver(): FrameDriver;
|
|
9
|
+
/** `undefined` restores the browser's frames. */
|
|
10
|
+
export declare function setFrameDriver(driver: FrameDriver | undefined): void;
|
|
11
|
+
/** The loop listens so a driver swapped mid-animation carries the pending frame over. */
|
|
12
|
+
export declare function onFrameDriverChange(listener: (previous: FrameDriver) => void): () => void;
|
|
13
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/frame/driver.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IACjD,MAAM,IAAI,IAAI,CAAC;IACf,0EAA0E;IAC1E,GAAG,IAAI,MAAM,CAAC;CACd;AA8BD,wBAAgB,WAAW,IAAI,WAAW,CAIzC;AAED,iDAAiD;AACjD,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAIpE;AAED,yFAAyF;AACzF,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,GACvC,MAAM,IAAI,CAGZ"}
|