anim-engine 0.3.2 → 0.5.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 +283 -499
- package/dist/animation/create-animation.d.ts +12 -0
- package/dist/animation/create-animation.js +19 -23
- package/dist/animation/create-single-tween.d.ts +1 -2
- package/dist/animation/index.d.ts +1 -0
- package/dist/animation/runner.d.ts +1 -1
- package/dist/animation/runner.js +22 -22
- package/dist/animation/update.d.ts +1 -1
- package/dist/animation/update.js +4 -4
- package/dist/domain/animation.d.ts +118 -3
- package/dist/domain/color.d.ts +14 -0
- package/dist/domain/easing.d.ts +12 -0
- package/dist/domain/easing.js +9 -35
- package/dist/domain/index.d.ts +4 -4
- package/dist/domain/interpolation.d.ts +153 -5
- package/dist/domain/resolve-value.d.ts +13 -0
- package/dist/domain/resolve-value.js +8 -0
- package/dist/domain/ticker.d.ts +26 -14
- package/dist/domain/timeline.d.ts +47 -2
- package/dist/index.d.ts +10 -13
- package/dist/index.js +8 -7
- package/dist/lerp/create-lerp.d.ts +14 -9
- package/dist/lerp/create-lerp.js +21 -18
- package/dist/lerp/index.d.ts +1 -0
- package/dist/lerp-rgba/hex-to-rgba.d.ts +13 -0
- package/dist/lerp-rgba/hex-to-rgba.js +48 -0
- package/dist/lerp-rgba/index.d.ts +2 -0
- package/dist/lerp-rgba/lerp-rgba.d.ts +13 -0
- package/dist/{color/lerp-oklab.js → lerp-rgba/lerp-rgba.js} +3 -48
- package/dist/smooth-clamp/{smooth-clamp.js → create-smooth-clamp.js} +1 -1
- package/dist/smooth-clamp/index.d.ts +1 -0
- package/dist/smooth-damp/create-smooth-damp.d.ts +16 -10
- package/dist/smooth-damp/create-smooth-damp.js +34 -29
- package/dist/smooth-damp/index.d.ts +1 -0
- package/dist/spring/create-spring.d.ts +13 -11
- package/dist/spring/create-spring.js +17 -19
- package/dist/spring/index.d.ts +1 -0
- package/dist/ticker/get-ticker.d.ts +25 -0
- package/dist/{domain/ticker.js → ticker/get-ticker.js} +10 -2
- package/dist/ticker/index.d.ts +1 -0
- package/dist/timeline/create-timeline.d.ts +16 -6
- package/dist/timeline/create-timeline.js +41 -13
- package/dist/timeline/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/color/lerp-oklab.d.ts +0 -26
- /package/dist/smooth-clamp/{smooth-clamp.d.ts → create-smooth-clamp.d.ts} +0 -0
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import { AnimationOptions, Animation } from '../domain';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an animation instance that can be played, paused, stopped,
|
|
4
|
+
* and queried for its current state.
|
|
5
|
+
*
|
|
6
|
+
* Accepts either a single tween configuration (from → to over a duration)
|
|
7
|
+
* or a keyframe animation with multiple keyframes, each with optional
|
|
8
|
+
* easing and gaps.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The animation configuration, either {@link SingleTweenOptions}
|
|
11
|
+
* or {@link KeyframeAnimationOptions}.
|
|
12
|
+
* @returns An {@link Animation} instance for controlling the animation.
|
|
13
|
+
*/
|
|
2
14
|
export declare const createAnimation: (options: AnimationOptions) => Animation;
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { resolveEasing } from "../domain/easing.js";
|
|
2
|
-
import { getTicker } from "../domain/ticker.js";
|
|
3
2
|
import { resolveValue } from "../domain/resolve-value.js";
|
|
3
|
+
import { getTicker } from "../ticker/get-ticker.js";
|
|
4
4
|
import { createKeyframeRunner, createTweenRunner } from "./runner.js";
|
|
5
5
|
//#region src/animation/create-animation.ts
|
|
6
6
|
var isKeyframeMode = (options) => {
|
|
7
7
|
return "keyframes" in options && Array.isArray(options.keyframes);
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates an animation instance that can be played, paused, stopped,
|
|
11
|
+
* and queried for its current state.
|
|
12
|
+
*
|
|
13
|
+
* Accepts either a single tween configuration (from → to over a duration)
|
|
14
|
+
* or a keyframe animation with multiple keyframes, each with optional
|
|
15
|
+
* easing and gaps.
|
|
16
|
+
*
|
|
17
|
+
* @param options - The animation configuration, either {@link SingleTweenOptions}
|
|
18
|
+
* or {@link KeyframeAnimationOptions}.
|
|
19
|
+
* @returns An {@link Animation} instance for controlling the animation.
|
|
20
|
+
*/
|
|
9
21
|
var createAnimation = (options) => {
|
|
10
22
|
if (isKeyframeMode(options)) return createKeyframeAnimation(options);
|
|
11
23
|
return createSingleTween(options);
|
|
12
24
|
};
|
|
13
|
-
var createSingleTween = ({
|
|
25
|
+
var createSingleTween = ({ from: rawFrom, to: rawTo, durationMs: rawDurationMs, ease: easeName = "inOutSine", onStarted, onUpdate, onProgress, onEnded, ticker = getTicker() }) => {
|
|
14
26
|
let cachedDurationMs = resolveValue(rawDurationMs);
|
|
15
27
|
let status = "stopped";
|
|
16
28
|
const hasDynamicProperty = typeof rawFrom === "function" || typeof rawTo === "function" || typeof rawDurationMs === "function";
|
|
17
29
|
let resolvePromise;
|
|
18
|
-
const ticker = getTicker();
|
|
19
30
|
const handleEnded = () => {
|
|
20
31
|
status = "stopped";
|
|
21
32
|
ticker.remove(runner);
|
|
@@ -41,7 +52,6 @@ var createSingleTween = ({ onStarted, onUpdate, onProgress, onEnded, from: rawFr
|
|
|
41
52
|
};
|
|
42
53
|
runner = buildRunner();
|
|
43
54
|
const play = () => {
|
|
44
|
-
if (status === "dead") throw new Error("Cannot play a dead animation");
|
|
45
55
|
if (hasDynamicProperty) runner = buildRunner();
|
|
46
56
|
else runner.reset();
|
|
47
57
|
const promise = new Promise((resolve) => {
|
|
@@ -76,11 +86,6 @@ var createSingleTween = ({ onStarted, onUpdate, onProgress, onEnded, from: rawFr
|
|
|
76
86
|
resolvePromise?.();
|
|
77
87
|
resolvePromise = void 0;
|
|
78
88
|
};
|
|
79
|
-
const kill = () => {
|
|
80
|
-
status = "dead";
|
|
81
|
-
ticker.remove(runner);
|
|
82
|
-
resolvePromise = void 0;
|
|
83
|
-
};
|
|
84
89
|
const setProgress = (value) => {
|
|
85
90
|
if (status === "playing") pause();
|
|
86
91
|
runner.evaluate(Math.max(0, Math.min(1, value)));
|
|
@@ -91,9 +96,8 @@ var createSingleTween = ({ onStarted, onUpdate, onProgress, onEnded, from: rawFr
|
|
|
91
96
|
resume,
|
|
92
97
|
stop,
|
|
93
98
|
skipToEnd,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return runner.currentValue;
|
|
99
|
+
get value() {
|
|
100
|
+
return runner.value;
|
|
97
101
|
},
|
|
98
102
|
get velocity() {
|
|
99
103
|
return runner.velocity;
|
|
@@ -110,7 +114,7 @@ var createSingleTween = ({ onStarted, onUpdate, onProgress, onEnded, from: rawFr
|
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
116
|
};
|
|
113
|
-
var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, onProgress, onEnded }) => {
|
|
117
|
+
var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, onProgress, onEnded, ticker = getTicker() }) => {
|
|
114
118
|
const resolveKeyframeGaps = () => {
|
|
115
119
|
let total = 0;
|
|
116
120
|
for (let i = 1; i < rawKeyframes.length; i++) total += resolveValue(rawKeyframes[i].gap ?? 0);
|
|
@@ -120,7 +124,6 @@ var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, o
|
|
|
120
124
|
let status = "stopped";
|
|
121
125
|
let resolvePromise;
|
|
122
126
|
const hasDynamicProperty = rawKeyframes.some((kf) => typeof kf.value === "function" || typeof kf.gap === "function");
|
|
123
|
-
const ticker = getTicker();
|
|
124
127
|
const handleEnded = () => {
|
|
125
128
|
status = "stopped";
|
|
126
129
|
ticker.remove(runner);
|
|
@@ -144,7 +147,6 @@ var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, o
|
|
|
144
147
|
};
|
|
145
148
|
runner = buildRunner();
|
|
146
149
|
const play = () => {
|
|
147
|
-
if (status === "dead") throw new Error("Cannot play a dead animation");
|
|
148
150
|
if (hasDynamicProperty) {
|
|
149
151
|
runner = buildRunner();
|
|
150
152
|
cachedDurationMs = resolveKeyframeGaps();
|
|
@@ -181,11 +183,6 @@ var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, o
|
|
|
181
183
|
resolvePromise?.();
|
|
182
184
|
resolvePromise = void 0;
|
|
183
185
|
};
|
|
184
|
-
const kill = () => {
|
|
185
|
-
status = "dead";
|
|
186
|
-
ticker.remove(runner);
|
|
187
|
-
resolvePromise = void 0;
|
|
188
|
-
};
|
|
189
186
|
const setProgress = (value) => {
|
|
190
187
|
if (status === "playing") pause();
|
|
191
188
|
runner.evaluate(Math.max(0, Math.min(1, value)));
|
|
@@ -196,9 +193,8 @@ var createKeyframeAnimation = ({ keyframes: rawKeyframes, onStarted, onUpdate, o
|
|
|
196
193
|
resume,
|
|
197
194
|
stop,
|
|
198
195
|
skipToEnd,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return runner.currentValue;
|
|
196
|
+
get value() {
|
|
197
|
+
return runner.value;
|
|
202
198
|
},
|
|
203
199
|
get velocity() {
|
|
204
200
|
return runner.velocity;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createAnimation } from './create-animation';
|
package/dist/animation/runner.js
CHANGED
|
@@ -4,13 +4,13 @@ var noOp = () => {};
|
|
|
4
4
|
var createTweenRunner = ({ from, to, durationMs, easeFn, onStarted, onUpdate = noOp, onProgress = noOp, onEnded }) => {
|
|
5
5
|
const state = {
|
|
6
6
|
progress: 0,
|
|
7
|
-
|
|
7
|
+
value: from,
|
|
8
8
|
velocity: 0
|
|
9
9
|
};
|
|
10
10
|
let runner;
|
|
11
11
|
const step = (deltaMs) => {
|
|
12
12
|
const completed = updateTween(state, deltaMs, durationMs, easeFn, from, to);
|
|
13
|
-
onUpdate(state.
|
|
13
|
+
onUpdate(state.value, state.velocity);
|
|
14
14
|
onProgress(state.progress);
|
|
15
15
|
if (completed) onEnded();
|
|
16
16
|
return completed;
|
|
@@ -19,26 +19,26 @@ var createTweenRunner = ({ from, to, durationMs, easeFn, onStarted, onUpdate = n
|
|
|
19
19
|
const clamped = Math.max(0, Math.min(1, progress));
|
|
20
20
|
state.progress = clamped;
|
|
21
21
|
if (clamped >= 1) {
|
|
22
|
-
state.
|
|
22
|
+
state.value = to;
|
|
23
23
|
state.velocity = 0;
|
|
24
24
|
} else {
|
|
25
25
|
const range = to - from;
|
|
26
|
-
state.
|
|
26
|
+
state.value = from + range * easeFn(clamped);
|
|
27
27
|
state.velocity = 0;
|
|
28
28
|
}
|
|
29
|
-
onUpdate(state.
|
|
30
|
-
return state.
|
|
29
|
+
onUpdate(state.value, state.velocity);
|
|
30
|
+
return state.value;
|
|
31
31
|
};
|
|
32
32
|
const reset = () => {
|
|
33
33
|
state.progress = 0;
|
|
34
|
-
state.
|
|
34
|
+
state.value = from;
|
|
35
35
|
state.velocity = 0;
|
|
36
36
|
};
|
|
37
37
|
runner = step;
|
|
38
38
|
runner.evaluate = evaluate;
|
|
39
39
|
runner.reset = reset;
|
|
40
|
-
Object.defineProperty(runner, "
|
|
41
|
-
get: () => state.
|
|
40
|
+
Object.defineProperty(runner, "value", {
|
|
41
|
+
get: () => state.value,
|
|
42
42
|
configurable: true
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(runner, "velocity", {
|
|
@@ -71,7 +71,7 @@ var createKeyframeRunner = ({ keyframes, onStarted, onUpdate = noOp, onProgress
|
|
|
71
71
|
for (let i = 0; i < segments.length; i++) prefixSum.push(prefixSum[i] + segments[i].durationMs);
|
|
72
72
|
const totalDurationMs = prefixSum[prefixSum.length - 1];
|
|
73
73
|
const invTotalDuration = totalDurationMs > 0 ? 1 / totalDurationMs : 1;
|
|
74
|
-
let
|
|
74
|
+
let value = keyframes[0].value;
|
|
75
75
|
let velocity = 0;
|
|
76
76
|
let globalProgress = 0;
|
|
77
77
|
let currentSegmentIndex = 0;
|
|
@@ -83,22 +83,22 @@ var createKeyframeRunner = ({ keyframes, onStarted, onUpdate = noOp, onProgress
|
|
|
83
83
|
segmentElapsed += deltaMs;
|
|
84
84
|
segmentProgress += deltaMs / segment.durationMs;
|
|
85
85
|
if (segmentProgress >= 1) segmentProgress = 1;
|
|
86
|
-
const previousValue =
|
|
86
|
+
const previousValue = value;
|
|
87
87
|
const eased = segment.easeFn(segmentProgress);
|
|
88
|
-
|
|
88
|
+
value = segment.from + segment.range * eased;
|
|
89
89
|
if (segmentProgress >= 1) {
|
|
90
|
-
|
|
90
|
+
value = segment.to;
|
|
91
91
|
velocity = 0;
|
|
92
|
-
} else velocity = (
|
|
92
|
+
} else velocity = (value - previousValue) / (deltaMs / 1e3);
|
|
93
93
|
const elapsedTotal = prefixSum[currentSegmentIndex] + segmentElapsed;
|
|
94
94
|
globalProgress = Math.min(elapsedTotal * invTotalDuration, 1);
|
|
95
95
|
onProgress(globalProgress);
|
|
96
|
-
onUpdate(
|
|
96
|
+
onUpdate(value, velocity);
|
|
97
97
|
if (segmentProgress >= 1) if (currentSegmentIndex < segments.length - 1) {
|
|
98
98
|
currentSegmentIndex++;
|
|
99
99
|
segmentElapsed = 0;
|
|
100
100
|
segmentProgress = 0;
|
|
101
|
-
|
|
101
|
+
value = segments[currentSegmentIndex].from;
|
|
102
102
|
velocity = 0;
|
|
103
103
|
globalProgress = Math.min(prefixSum[currentSegmentIndex] * invTotalDuration, 1);
|
|
104
104
|
onProgress(globalProgress);
|
|
@@ -125,18 +125,18 @@ var createKeyframeRunner = ({ keyframes, onStarted, onUpdate = noOp, onProgress
|
|
|
125
125
|
const segProgress = segDuration > 0 ? (elapsed - segStart) / segDuration : 1;
|
|
126
126
|
const clampedSegProgress = Math.max(0, Math.min(1, segProgress));
|
|
127
127
|
const eased = segment.easeFn(clampedSegProgress);
|
|
128
|
-
|
|
128
|
+
value = segment.from + segment.range * eased;
|
|
129
129
|
velocity = 0;
|
|
130
130
|
globalProgress = clamped;
|
|
131
131
|
currentSegmentIndex = segIdx;
|
|
132
132
|
segmentElapsed = elapsed - segStart;
|
|
133
133
|
segmentProgress = clampedSegProgress;
|
|
134
|
-
onUpdate(
|
|
134
|
+
onUpdate(value, velocity);
|
|
135
135
|
onProgress(clamped);
|
|
136
|
-
return
|
|
136
|
+
return value;
|
|
137
137
|
};
|
|
138
138
|
const reset = () => {
|
|
139
|
-
|
|
139
|
+
value = keyframes[0].value;
|
|
140
140
|
velocity = 0;
|
|
141
141
|
globalProgress = 0;
|
|
142
142
|
currentSegmentIndex = 0;
|
|
@@ -146,8 +146,8 @@ var createKeyframeRunner = ({ keyframes, onStarted, onUpdate = noOp, onProgress
|
|
|
146
146
|
runner = update;
|
|
147
147
|
runner.evaluate = evaluate;
|
|
148
148
|
runner.reset = reset;
|
|
149
|
-
Object.defineProperty(runner, "
|
|
150
|
-
get: () =>
|
|
149
|
+
Object.defineProperty(runner, "value", {
|
|
150
|
+
get: () => value,
|
|
151
151
|
configurable: true
|
|
152
152
|
});
|
|
153
153
|
Object.defineProperty(runner, "velocity", {
|
package/dist/animation/update.js
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
var updateTween = (state, deltaMs, durationMs, easeFn, from, to) => {
|
|
8
8
|
const thisFrameProgress = deltaMs / durationMs;
|
|
9
9
|
state.progress = Math.min(state.progress + thisFrameProgress, 1);
|
|
10
|
-
const previousValue = state.
|
|
10
|
+
const previousValue = state.value;
|
|
11
11
|
if (state.progress >= 1) {
|
|
12
|
-
state.
|
|
12
|
+
state.value = to;
|
|
13
13
|
state.velocity = 0;
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
16
|
const eased = easeFn(state.progress);
|
|
17
|
-
state.
|
|
18
|
-
state.velocity = (state.
|
|
17
|
+
state.value = from + (to - from) * eased;
|
|
18
|
+
state.velocity = (state.value - previousValue) / (deltaMs / 1e3);
|
|
19
19
|
return false;
|
|
20
20
|
};
|
|
21
21
|
//#endregion
|
|
@@ -1,40 +1,155 @@
|
|
|
1
1
|
import { EaseFunction, EaseName } from './easing';
|
|
2
2
|
import { DynamicValue } from './resolve-value';
|
|
3
|
-
|
|
3
|
+
import { ExternalTicker } from './ticker';
|
|
4
|
+
/**
|
|
5
|
+
* The status of an animation, which can be "playing", "paused", or "stopped".
|
|
6
|
+
* - "playing": The animation is currently running.
|
|
7
|
+
* - "paused": The animation is temporarily halted but can be resumed.
|
|
8
|
+
* - "stopped": The animation has finished or has been stopped and is available for garbage collection if no external references remain.
|
|
9
|
+
*/
|
|
10
|
+
export type AnimationStatus = "playing" | "paused" | "stopped";
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a single tween animation, which interpolates between a starting and ending value over a specified duration with optional easing.
|
|
13
|
+
*/
|
|
4
14
|
export type SingleTweenOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* The starting value of the animation. Can be a number or a function that returns a number.
|
|
17
|
+
*/
|
|
5
18
|
from: DynamicValue;
|
|
19
|
+
/**
|
|
20
|
+
* The ending value of the animation. Can be a number or a function that returns a number.
|
|
21
|
+
*/
|
|
6
22
|
to: DynamicValue;
|
|
23
|
+
/**
|
|
24
|
+
* The duration of the animation in milliseconds. Can be a number or a function that returns a number.
|
|
25
|
+
*/
|
|
7
26
|
durationMs: DynamicValue;
|
|
27
|
+
/**
|
|
28
|
+
* The easing function or name to use for the animation.
|
|
29
|
+
*/
|
|
8
30
|
ease?: EaseName | EaseFunction;
|
|
31
|
+
/**
|
|
32
|
+
* Callback fired when the animation starts.
|
|
33
|
+
*/
|
|
9
34
|
onStarted?: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Callback fired on each animation update with the current value and velocity.
|
|
37
|
+
*/
|
|
10
38
|
onUpdate?: (value: number, velocity: number) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Callback fired on each animation update with the current progress (0 to 1).
|
|
41
|
+
*/
|
|
11
42
|
onProgress?: (progress: number) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Callback fired when the animation ends.
|
|
45
|
+
*/
|
|
12
46
|
onEnded?: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Optional external ticker to drive the animation.
|
|
49
|
+
*/
|
|
50
|
+
ticker?: ExternalTicker;
|
|
13
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Object for describing a single keyframe.
|
|
54
|
+
*/
|
|
14
55
|
export type Keyframe = {
|
|
56
|
+
/**
|
|
57
|
+
* The value of the keyframe. Can be a number or a function that returns a number.
|
|
58
|
+
*/
|
|
15
59
|
value: DynamicValue;
|
|
60
|
+
/**
|
|
61
|
+
* The easing function or name to use for the keyframe.
|
|
62
|
+
*/
|
|
16
63
|
ease?: EaseName | EaseFunction;
|
|
64
|
+
/**
|
|
65
|
+
* The gap before the keyframe in milliseconds. Can be a number or a function that returns a number.
|
|
66
|
+
*/
|
|
17
67
|
gap?: DynamicValue;
|
|
18
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Options for creating a keyframe animation, which consists of multiple keyframes each with their own value, easing, and optional gap.
|
|
71
|
+
*/
|
|
19
72
|
export type KeyframeAnimationOptions = {
|
|
73
|
+
/**
|
|
74
|
+
* The keyframes for the animation. Each keyframe defines a value, optional easing, and optional gap in milliseconds.
|
|
75
|
+
*/
|
|
20
76
|
keyframes: Keyframe[];
|
|
77
|
+
/**
|
|
78
|
+
* Callback fired when the animation starts.
|
|
79
|
+
*/
|
|
21
80
|
onStarted?: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback fired on each animation update with the current value and velocity.
|
|
83
|
+
*/
|
|
22
84
|
onUpdate?: (value: number, velocity: number) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Callback fired on each animation update with the current progress (0 to 1).
|
|
87
|
+
*/
|
|
23
88
|
onProgress?: (progress: number) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Callback fired when the animation ends.
|
|
91
|
+
*/
|
|
24
92
|
onEnded?: () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Optional external ticker to drive the animation.
|
|
95
|
+
*/
|
|
96
|
+
ticker?: ExternalTicker;
|
|
25
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Options for creating an animation, which can be either a single tween or a keyframe animation type.
|
|
100
|
+
*/
|
|
26
101
|
export type AnimationOptions = SingleTweenOptions | KeyframeAnimationOptions;
|
|
102
|
+
/**
|
|
103
|
+
* Represents an animation instance that can be controlled and queried for its state.
|
|
104
|
+
*/
|
|
27
105
|
export type Animation = {
|
|
106
|
+
/**
|
|
107
|
+
* Plays the animation from the current state and returns a promise that resolves when the animation ends.
|
|
108
|
+
*/
|
|
28
109
|
play: () => Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Pauses the animation if it is currently playing.
|
|
112
|
+
*/
|
|
29
113
|
pause: () => void;
|
|
114
|
+
/**
|
|
115
|
+
* Resumes the animation if it is currently paused.
|
|
116
|
+
*/
|
|
30
117
|
resume: () => void;
|
|
118
|
+
/**
|
|
119
|
+
* Stops the animation and resets its state.
|
|
120
|
+
*/
|
|
31
121
|
stop: () => void;
|
|
122
|
+
/**
|
|
123
|
+
* Skips the animation to its end state immediately.
|
|
124
|
+
*/
|
|
32
125
|
skipToEnd: () => void;
|
|
33
|
-
|
|
34
|
-
|
|
126
|
+
/**
|
|
127
|
+
* The current value of the animation.
|
|
128
|
+
*/
|
|
129
|
+
value: number;
|
|
130
|
+
/**
|
|
131
|
+
* The current velocity of the animation.
|
|
132
|
+
*/
|
|
35
133
|
velocity: number;
|
|
134
|
+
/**
|
|
135
|
+
* The current progress of the animation, represented as a number between 0 and 1.
|
|
136
|
+
*/
|
|
36
137
|
progress: number;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the progress of the animation to a specific value between 0 and 1. If the animation is playing, it will be paused.
|
|
140
|
+
*/
|
|
37
141
|
setProgress: (value: number) => void;
|
|
142
|
+
/**
|
|
143
|
+
* The current status of the animation, which can be "playing", "paused", or "stopped".
|
|
144
|
+
* - "playing": The animation is currently running.
|
|
145
|
+
* - "paused": The animation is temporarily halted but can be resumed.
|
|
146
|
+
* - "stopped": The animation has finished or has been stopped and is available for garbage collection if no external references remain.
|
|
147
|
+
*/
|
|
38
148
|
status: AnimationStatus;
|
|
149
|
+
/**
|
|
150
|
+
* The total duration of the animation in milliseconds. This value is determined by the animation's configuration and keyframes.
|
|
151
|
+
* For single tween animations, this is the specified duration. For keyframe animations, this is the sum of all keyframe gaps and durations.
|
|
152
|
+
* Note that if the animation has dynamic values for duration or gaps, this value may change when the animation is played and the dynamic values are read.
|
|
153
|
+
*/
|
|
39
154
|
durationMs: number;
|
|
40
155
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tuple representing an RGBA color with each channel as a float in the range [0, 1].
|
|
3
|
+
* Ordered as [red, green, blue, alpha].
|
|
4
|
+
*/
|
|
5
|
+
export type RgbaTuple = readonly [number, number, number, number];
|
|
6
|
+
/**
|
|
7
|
+
* A function that linearly interpolates between two RGBA colors in Oklab color space.
|
|
8
|
+
*
|
|
9
|
+
* @param from - The starting color as an RgbaTuple.
|
|
10
|
+
* @param to - The ending color as an RgbaTuple.
|
|
11
|
+
* @param progress - A number between 0 and 1 representing the interpolation progress.
|
|
12
|
+
* @returns The interpolated color as an RgbaTuple.
|
|
13
|
+
*/
|
|
14
|
+
export type LerpRgba = (from: RgbaTuple, to: RgbaTuple, progress: number) => RgbaTuple;
|
package/dist/domain/easing.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that maps a progress value `t` in [0, 1] to an eased output value.
|
|
3
|
+
* Values outside [0, 1] may be returned for overshooting easings like elastic or back.
|
|
4
|
+
*/
|
|
1
5
|
export type EaseFunction = (t: number) => number;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves an easing identifier or function into a concrete {@link EaseFunction}.
|
|
8
|
+
* If a function is passed, it is returned as-is. If a name is passed, the
|
|
9
|
+
* corresponding built-in easing function is looked up.
|
|
10
|
+
*
|
|
11
|
+
* @param ease - An easing name or a custom easing function.
|
|
12
|
+
* @returns The resolved easing function.
|
|
13
|
+
*/
|
|
2
14
|
export declare const resolveEasing: (ease: EaseName | EaseFunction) => EaseFunction;
|
|
3
15
|
/** All 31 named easing identifiers, ordered by type. */
|
|
4
16
|
export declare const EASE_NAMES: readonly ["linear", "inQuad", "outQuad", "inOutQuad", "inCubic", "outCubic", "inOutCubic", "inQuart", "outQuart", "inOutQuart", "inQuint", "outQuint", "inOutQuint", "inSine", "outSine", "inOutSine", "inExpo", "outExpo", "inOutExpo", "inCirc", "outCirc", "inOutCirc", "inBack", "outBack", "inOutBack", "inElastic", "outElastic", "inOutElastic", "inBounce", "outBounce", "inOutBounce"];
|
package/dist/domain/easing.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
//#region src/domain/easing.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves an easing identifier or function into a concrete {@link EaseFunction}.
|
|
4
|
+
* If a function is passed, it is returned as-is. If a name is passed, the
|
|
5
|
+
* corresponding built-in easing function is looked up.
|
|
6
|
+
*
|
|
7
|
+
* @param ease - An easing name or a custom easing function.
|
|
8
|
+
* @returns The resolved easing function.
|
|
9
|
+
*/
|
|
2
10
|
var resolveEasing = (ease) => typeof ease === "function" ? ease : EASING_FUNCTIONS[ease];
|
|
3
11
|
var pow = Math.pow;
|
|
4
12
|
var sqrt = Math.sqrt;
|
|
@@ -18,40 +26,6 @@ var bounceOut = (x) => {
|
|
|
18
26
|
else if (x < 2.5 / d1) return n1 * (x -= 2.25 / d1) * x + .9375;
|
|
19
27
|
else return n1 * (x -= 2.625 / d1) * x + .984375;
|
|
20
28
|
};
|
|
21
|
-
/** All 31 named easing identifiers, ordered by type. */
|
|
22
|
-
var EASE_NAMES = [
|
|
23
|
-
"linear",
|
|
24
|
-
"inQuad",
|
|
25
|
-
"outQuad",
|
|
26
|
-
"inOutQuad",
|
|
27
|
-
"inCubic",
|
|
28
|
-
"outCubic",
|
|
29
|
-
"inOutCubic",
|
|
30
|
-
"inQuart",
|
|
31
|
-
"outQuart",
|
|
32
|
-
"inOutQuart",
|
|
33
|
-
"inQuint",
|
|
34
|
-
"outQuint",
|
|
35
|
-
"inOutQuint",
|
|
36
|
-
"inSine",
|
|
37
|
-
"outSine",
|
|
38
|
-
"inOutSine",
|
|
39
|
-
"inExpo",
|
|
40
|
-
"outExpo",
|
|
41
|
-
"inOutExpo",
|
|
42
|
-
"inCirc",
|
|
43
|
-
"outCirc",
|
|
44
|
-
"inOutCirc",
|
|
45
|
-
"inBack",
|
|
46
|
-
"outBack",
|
|
47
|
-
"inOutBack",
|
|
48
|
-
"inElastic",
|
|
49
|
-
"outElastic",
|
|
50
|
-
"inOutElastic",
|
|
51
|
-
"inBounce",
|
|
52
|
-
"outBounce",
|
|
53
|
-
"inOutBounce"
|
|
54
|
-
];
|
|
55
29
|
var EASING_FUNCTIONS = {
|
|
56
30
|
linear: (x) => x,
|
|
57
31
|
inQuad: (x) => x * x,
|
|
@@ -152,4 +126,4 @@ var cubicBezier = (p1x, p1y, p2x, p2y) => {
|
|
|
152
126
|
};
|
|
153
127
|
};
|
|
154
128
|
//#endregion
|
|
155
|
-
export {
|
|
129
|
+
export { EASING_FUNCTIONS, cubicBezier, resolveEasing };
|
package/dist/domain/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { AnimationStatus } from './animation';
|
|
2
|
-
export type { InterpolationStatus, Interpolation } from './interpolation';
|
|
2
|
+
export type { InterpolationStatus, Interpolation, LerpOptions, SmoothDampOptions, SpringOptions, } from './interpolation';
|
|
3
3
|
export type { EaseName, EaseFunction } from './easing';
|
|
4
4
|
export { EASE_NAMES, cubicBezier, EASING_FUNCTIONS, resolveEasing } from './easing';
|
|
5
|
-
export {
|
|
6
|
-
export type { Ticker, TickHandler } from './ticker';
|
|
5
|
+
export type { Ticker, TickHandler, ExternalTicker } from './ticker';
|
|
7
6
|
export { resolveValue } from './resolve-value';
|
|
8
7
|
export type { DynamicValue } from './resolve-value';
|
|
9
8
|
export type { Animation, AnimationOptions, SingleTweenOptions, KeyframeAnimationOptions, Keyframe, } from './animation';
|
|
10
|
-
export type { TimelineLayer, Timeline } from './timeline';
|
|
9
|
+
export type { TimelineLayer, Timeline, TimelineCallbacks } from './timeline';
|
|
10
|
+
export type { RgbaTuple, LerpRgba } from './color';
|