@starweb-libs/tween 0.0.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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/easing.d.ts +17 -0
- package/dist/easing.d.ts.map +1 -0
- package/dist/easing.js +46 -0
- package/dist/easing.js.map +1 -0
- package/dist/manager.d.ts +9 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +151 -0
- package/dist/manager.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Starweb Libraries, Mason L'Etoile
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Starweb Tween
|
|
2
|
+
|
|
3
|
+
Frame-driven tween manager with easing for the browser, built with TypeScript.
|
|
4
|
+
|
|
5
|
+
## Tech Stack
|
|
6
|
+
<p align="left">
|
|
7
|
+
<img height="35" src="https://img.shields.io/badge/TypeScript-%23007ACC?logo=typescript&logoColor=white&style=for-the-badge"/>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
## Modules
|
|
11
|
+
| Module | Description |
|
|
12
|
+
| ------ | ----------- |
|
|
13
|
+
| `easing` | Easing functions and lookup table |
|
|
14
|
+
| `manager` | Frame-driven tween manager |
|
|
15
|
+
| `types` | Tween config, handle, and target types |
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
```bash
|
|
19
|
+
npm install github:starweb-libs/tween
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
MIT — see [LICENSE](./LICENSE) for details.
|
package/dist/easing.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Easing function name. */
|
|
2
|
+
export type EasingName = 'linear' | 'sine.in' | 'sine.out' | 'sine.inOut' | 'quad.in' | 'quad.out' | 'quad.inOut' | 'cubic.in' | 'cubic.out' | 'cubic.inOut' | 'expo.in' | 'expo.out' | 'expo.inOut';
|
|
3
|
+
/** A function that maps a linear progress value (0-1) to an eased value (0-1).*/
|
|
4
|
+
export type EasingFunction = (t: number) => number;
|
|
5
|
+
/** Flips an ease-in function into its ease-out equivalent. */
|
|
6
|
+
export declare const easeOut: (f: EasingFunction) => EasingFunction;
|
|
7
|
+
/** Combines an ease-in function with its inverse for a symmetric ease-in-out curve. */
|
|
8
|
+
export declare const easeInOut: (f: EasingFunction) => EasingFunction;
|
|
9
|
+
/** Generates in/out/inOut easing functions for a given exponent. */
|
|
10
|
+
export declare const makePowerEase: (exponent: number) => {
|
|
11
|
+
in: EasingFunction;
|
|
12
|
+
out: EasingFunction;
|
|
13
|
+
inOut: EasingFunction;
|
|
14
|
+
};
|
|
15
|
+
/** Lookup table of easing functions keyed by name. */
|
|
16
|
+
export declare const TWEEN_EASING: Readonly<Record<EasingName, EasingFunction>>;
|
|
17
|
+
//# sourceMappingURL=easing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.d.ts","sourceRoot":"","sources":["../src/easing.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,MAAM,MAAM,UAAU,GAAG,QAAQ,GACL,SAAS,GAAK,UAAU,GAAK,YAAY,GACzC,SAAS,GAAK,UAAU,GAAK,YAAY,GACzC,UAAU,GAAI,WAAW,GAAI,aAAa,GAC1C,SAAS,GAAK,UAAU,GAAK,YAAY,CAAC;AAEtE,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAEnD,8DAA8D;AAC9D,eAAO,MAAM,OAAO,GAAI,GAAG,cAAc,KAAG,cACzB,CAAC;AAEpB,uFAAuF;AACvF,eAAO,MAAM,SAAS,GAAI,GAAG,cAAc,KAAG,cACK,CAAC;AAEpD,oEAAoE;AACpE,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM;;;;CAG7C,CAAC;AAqBF,sDAAsD;AACtD,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAsBrE,CAAA"}
|
package/dist/easing.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Flips an ease-in function into its ease-out equivalent. */
|
|
2
|
+
export const easeOut = (f) => t => 1 - f(1 - t);
|
|
3
|
+
/** Combines an ease-in function with its inverse for a symmetric ease-in-out curve. */
|
|
4
|
+
export const easeInOut = (f) => t => t < 0.5 ? f(2 * t) / 2 : 1 - f(-2 * t + 2) / 2;
|
|
5
|
+
/** Generates in/out/inOut easing functions for a given exponent. */
|
|
6
|
+
export const makePowerEase = (exponent) => {
|
|
7
|
+
const i = t => t ** exponent;
|
|
8
|
+
return { in: i, out: easeOut(i), inOut: easeInOut(i) };
|
|
9
|
+
};
|
|
10
|
+
/** Sine ease-in base curve. */
|
|
11
|
+
const sineIn = t => 1 - Math.cos(t * Math.PI / 2);
|
|
12
|
+
/** Sine ease-out. */
|
|
13
|
+
const sineOut = easeOut(sineIn);
|
|
14
|
+
/** Sine ease-in-out. */
|
|
15
|
+
const sineInOut = easeInOut(sineIn);
|
|
16
|
+
/** Quadratic easing curves. */
|
|
17
|
+
const quad = makePowerEase(2);
|
|
18
|
+
/** Cubic easing curves.*/
|
|
19
|
+
const cubic = makePowerEase(3);
|
|
20
|
+
/** Exponential ease-in with edge case guards. */
|
|
21
|
+
const expoIn = t => t === 0 ? 0 : t === 1 ? 1 : 2 ** (10 * t - 10);
|
|
22
|
+
/** Exponential ease-out. */
|
|
23
|
+
const expoOut = easeOut(expoIn);
|
|
24
|
+
/** Exponential ease-in-out. */
|
|
25
|
+
const expoInOut = easeInOut(expoIn);
|
|
26
|
+
/** Lookup table of easing functions keyed by name. */
|
|
27
|
+
export const TWEEN_EASING = {
|
|
28
|
+
'linear': t => t,
|
|
29
|
+
// Sine
|
|
30
|
+
'sine.in': sineIn,
|
|
31
|
+
'sine.out': sineOut,
|
|
32
|
+
'sine.inOut': sineInOut,
|
|
33
|
+
// Quad
|
|
34
|
+
'quad.in': quad.in,
|
|
35
|
+
'quad.out': quad.out,
|
|
36
|
+
'quad.inOut': quad.inOut,
|
|
37
|
+
// Cubic
|
|
38
|
+
'cubic.in': cubic.in,
|
|
39
|
+
'cubic.out': cubic.out,
|
|
40
|
+
'cubic.inOut': cubic.inOut,
|
|
41
|
+
// Exponential
|
|
42
|
+
'expo.in': expoIn,
|
|
43
|
+
'expo.out': expoOut,
|
|
44
|
+
'expo.inOut': expoInOut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IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAC9B,0BAA0B;AAC1B,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAE/B,iDAAiD;AACjD,MAAM,MAAM,GAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;AACnF,4BAA4B;AAC5B,MAAM,OAAO,GAAqB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClD,+BAA+B;AAC/B,MAAM,SAAS,GAAmB,SAAS,CAAC,MAAM,CAAC,CAAC;AAEpD,sDAAsD;AACtD,MAAM,CAAC,MAAM,YAAY,GAAiD;IACxE,QAAQ,EAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAErB,OAAO;IACP,SAAS,EAAM,MAAM;IACrB,UAAU,EAAK,OAAO;IACtB,YAAY,EAAG,SAAS;IAExB,OAAO;IACP,SAAS,EAAM,IAAI,CAAC,EAAE;IACtB,UAAU,EAAK,IAAI,CAAC,GAAG;IACvB,YAAY,EAAG,IAAI,CAAC,KAAK;IAEzB,QAAQ;IACR,UAAU,EAAK,KAAK,CAAC,EAAE;IACvB,WAAW,EAAI,KAAK,CAAC,GAAG;IACxB,aAAa,EAAE,KAAK,CAAC,KAAK;IAE1B,cAAc;IACd,SAAS,EAAM,MAAM;IACrB,UAAU,EAAK,OAAO;IACtB,YAAY,EAAG,SAAS;CACzB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TweenManager } from "./types.js";
|
|
2
|
+
/** Creates a tween manager that drives property animations each frame.
|
|
3
|
+
*
|
|
4
|
+
* Call `update` once per frame with the frame delta in **ms**.
|
|
5
|
+
*
|
|
6
|
+
* @returns A {@link TweenManager} with `add`, `update`, and `stopAll`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createTweenManager(): TweenManager;
|
|
9
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyC,YAAY,EAAE,MAAM,YAAY,CAAC;AAmCtF;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAmJjD"}
|
package/dist/manager.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { TWEEN_EASING } from "./easing.js";
|
|
2
|
+
/** Creates a tween manager that drives property animations each frame.
|
|
3
|
+
*
|
|
4
|
+
* Call `update` once per frame with the frame delta in **ms**.
|
|
5
|
+
*
|
|
6
|
+
* @returns A {@link TweenManager} with `add`, `update`, and `stopAll`.
|
|
7
|
+
*/
|
|
8
|
+
export function createTweenManager() {
|
|
9
|
+
const tweens = new Set();
|
|
10
|
+
/** Adds and starts a tween from the given config.
|
|
11
|
+
* @returns A {@link TweenHandle} to control the tween.
|
|
12
|
+
*/
|
|
13
|
+
function add(config) {
|
|
14
|
+
const targetArray = Array.isArray(config.targets) ? [...config.targets] : [config.targets];
|
|
15
|
+
const easeFn = TWEEN_EASING[config.ease ?? 'linear'];
|
|
16
|
+
const resolvedTargets = targetArray.map(obj => {
|
|
17
|
+
const props = {};
|
|
18
|
+
const keys = [];
|
|
19
|
+
for (const [key, val] of Object.entries(config.props)) {
|
|
20
|
+
if (val === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
props[key] = typeof val === 'number' ? { from: obj[key] ?? 0, to: val } : val;
|
|
23
|
+
keys.push(key);
|
|
24
|
+
}
|
|
25
|
+
return { obj, props, keys };
|
|
26
|
+
});
|
|
27
|
+
const tween = {
|
|
28
|
+
targets: resolvedTargets,
|
|
29
|
+
duration: config.duration,
|
|
30
|
+
ease: easeFn,
|
|
31
|
+
yoyo: config.yoyo ?? false,
|
|
32
|
+
repeat: config.repeat ?? 0,
|
|
33
|
+
delay: config.delay ?? 0,
|
|
34
|
+
elapsed: 0,
|
|
35
|
+
delayElapsed: 0,
|
|
36
|
+
direction: 1,
|
|
37
|
+
repeatsDone: 0,
|
|
38
|
+
started: false,
|
|
39
|
+
paused: false,
|
|
40
|
+
stopped: false,
|
|
41
|
+
onStart: config.onStart,
|
|
42
|
+
onUpdate: config.onUpdate,
|
|
43
|
+
onComplete: config.onComplete,
|
|
44
|
+
onYoyo: config.onYoyo,
|
|
45
|
+
onRepeat: config.onRepeat,
|
|
46
|
+
};
|
|
47
|
+
tweens.add(tween);
|
|
48
|
+
return {
|
|
49
|
+
stop: () => { if (!tween.stopped) {
|
|
50
|
+
tween.stopped = true;
|
|
51
|
+
tweens.delete(tween);
|
|
52
|
+
} },
|
|
53
|
+
pause: () => { if (!tween.stopped)
|
|
54
|
+
tween.paused = true; },
|
|
55
|
+
resume: () => { if (!tween.stopped)
|
|
56
|
+
tween.paused = false; },
|
|
57
|
+
get isPlaying() { return !tween.paused && !tween.stopped; },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Advances all active tweens by `deltaMs` **milliseconds**. Call once per frame. */
|
|
61
|
+
function update(deltaMs) {
|
|
62
|
+
for (const tween of [...tweens]) {
|
|
63
|
+
if (tween.paused || tween.stopped)
|
|
64
|
+
continue;
|
|
65
|
+
let step = deltaMs;
|
|
66
|
+
if (tween.delayElapsed < tween.delay) {
|
|
67
|
+
const remaining = tween.delay - tween.delayElapsed;
|
|
68
|
+
if (step <= remaining) {
|
|
69
|
+
tween.delayElapsed += step;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
tween.delayElapsed = tween.delay;
|
|
73
|
+
step -= remaining;
|
|
74
|
+
}
|
|
75
|
+
if (!tween.started) {
|
|
76
|
+
tween.started = true;
|
|
77
|
+
tween.onStart?.();
|
|
78
|
+
}
|
|
79
|
+
if (tween.duration <= 0) {
|
|
80
|
+
for (const { obj, props, keys } of tween.targets) {
|
|
81
|
+
for (const key of keys) {
|
|
82
|
+
const resolved = props[key];
|
|
83
|
+
if (resolved)
|
|
84
|
+
obj[key] = resolved.to;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
tween.onUpdate?.(1);
|
|
88
|
+
tween.onComplete?.();
|
|
89
|
+
tweens.delete(tween);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
while (step > 0 && !tween.stopped) {
|
|
93
|
+
const next = tween.elapsed + step;
|
|
94
|
+
const overflow = Math.max(0, next - tween.duration);
|
|
95
|
+
tween.elapsed = Math.min(next, tween.duration);
|
|
96
|
+
const raw = tween.elapsed / tween.duration;
|
|
97
|
+
const t = tween.direction === 1 ? tween.ease(raw) : tween.ease(1 - raw);
|
|
98
|
+
for (const { obj, props, keys } of tween.targets) {
|
|
99
|
+
for (const key of keys) {
|
|
100
|
+
const resolved = props[key];
|
|
101
|
+
if (resolved)
|
|
102
|
+
obj[key] = resolved.from + (resolved.to - resolved.from) * t;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
tween.onUpdate?.(t);
|
|
106
|
+
if (tween.elapsed >= tween.duration) {
|
|
107
|
+
if (tween.yoyo) {
|
|
108
|
+
if (tween.direction === 1) {
|
|
109
|
+
tween.direction = -1;
|
|
110
|
+
tween.onYoyo?.();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
tween.direction = 1;
|
|
114
|
+
if (tween.repeat === -1 || tween.repeatsDone < tween.repeat) {
|
|
115
|
+
tween.repeatsDone++;
|
|
116
|
+
tween.onRepeat?.();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
tween.onComplete?.();
|
|
120
|
+
tweens.delete(tween);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (tween.repeat === -1 || tween.repeatsDone < tween.repeat) {
|
|
127
|
+
tween.repeatsDone++;
|
|
128
|
+
tween.onRepeat?.();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
tween.onComplete?.();
|
|
132
|
+
tweens.delete(tween);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
tween.elapsed = overflow;
|
|
137
|
+
step = overflow;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
step = 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Immediately stops and removes all active tweens. */
|
|
146
|
+
function stopAll() {
|
|
147
|
+
tweens.clear();
|
|
148
|
+
}
|
|
149
|
+
return { add, update, stopAll };
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAyB,MAAM,aAAa,CAAC;AAoCvF;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAe,CAAC;IAEtC;;OAEG;IACH,SAAS,GAAG,CAAC,MAAmB;QAC9B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3F,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC;QAErD,MAAM,eAAe,GAAqB,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC9D,MAAM,KAAK,GAAqD,EAAE,CAAC;YACnE,MAAM,IAAI,GAA0B,EAAE,CAAC;YACvC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAA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AAE,CAAC;4BACrB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;4BACrB,MAAM;wBACR,CAAC;oBACH,CAAC;oBACD,KAAK,CAAC,OAAO,GAAG,QAAQ,CAAC;oBACzB,IAAI,GAAG,QAAQ,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACN,IAAI,GAAG,CAAC,CAAC;gBACX,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,SAAS,OAAO;QACd,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type EasingName } from "./easing.js";
|
|
2
|
+
/** An object whose properties can be animated by the tween system. */
|
|
3
|
+
export type TweenTarget = {
|
|
4
|
+
alpha?: number;
|
|
5
|
+
y?: number;
|
|
6
|
+
};
|
|
7
|
+
/** A single target, or an array of targets to animate in parallel. */
|
|
8
|
+
export type TweenTargets = TweenTarget | readonly TweenTarget[];
|
|
9
|
+
/** A target value: number (tweens from current) or explicit from/to. */
|
|
10
|
+
export type TweenPropValue = number | {
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
};
|
|
14
|
+
/** Map of supported property names to target values. */
|
|
15
|
+
export type TweenProps = Partial<Record<keyof TweenTarget, TweenPropValue>>;
|
|
16
|
+
/** Configuration for a tween animation. */
|
|
17
|
+
export interface TweenConfig {
|
|
18
|
+
/** Target or array of targets whose properties will be animated. */
|
|
19
|
+
targets: TweenTargets;
|
|
20
|
+
/** Map of supported property names to target values. */
|
|
21
|
+
props: TweenProps;
|
|
22
|
+
/** Duration of one pass in milliseconds. */
|
|
23
|
+
duration: number;
|
|
24
|
+
/** Delay before starting in milliseconds. Default: 0. */
|
|
25
|
+
delay?: number;
|
|
26
|
+
/** Easing function. Default: 'linear'. */
|
|
27
|
+
ease?: EasingName;
|
|
28
|
+
/** Reverse the animation at the end of each pass. Default: false. */
|
|
29
|
+
yoyo?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Additional repeat count after the first play. 0 = play once, -1 = infinite.
|
|
32
|
+
* With yoyo, each forward+backward pair counts as one repeat.
|
|
33
|
+
* Default: 0.
|
|
34
|
+
*/
|
|
35
|
+
repeat?: number;
|
|
36
|
+
/** Called once when the tween starts (after any delay). */
|
|
37
|
+
onStart?: () => void;
|
|
38
|
+
/** Called every frame with the eased progress value (0–1). */
|
|
39
|
+
onUpdate?: (progress: number) => void;
|
|
40
|
+
/** Called each time a yoyo reverses direction (forward → backward). */
|
|
41
|
+
onYoyo?: () => void;
|
|
42
|
+
/** Called at the start of each new repeat cycle (backward → forward). */
|
|
43
|
+
onRepeat?: () => void;
|
|
44
|
+
/** Called when the tween fully completes. Not called for infinite repeats. */
|
|
45
|
+
onComplete?: () => void;
|
|
46
|
+
}
|
|
47
|
+
/** A handle to control a running tween returned by {@link TweenManager.add}.*/
|
|
48
|
+
export interface TweenHandle {
|
|
49
|
+
/** Immediately stop and remove the tween. */
|
|
50
|
+
stop(): void;
|
|
51
|
+
/** Pause without removing. */
|
|
52
|
+
pause(): void;
|
|
53
|
+
/** Resume a paused tween. */
|
|
54
|
+
resume(): void;
|
|
55
|
+
/** `true` if the tween is active and not paused. */
|
|
56
|
+
readonly isPlaying: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** Manages a collection of active tweens, advancing them each frame. */
|
|
59
|
+
export interface TweenManager {
|
|
60
|
+
/** Adds and starts a tween from the given config.
|
|
61
|
+
* @returns A {@link TweenHandle} to control the tween.
|
|
62
|
+
*/
|
|
63
|
+
add(config: TweenConfig): TweenHandle;
|
|
64
|
+
/** Advances all active tweens by `deltaMs` **ms**. Call once per frame. */
|
|
65
|
+
update(deltaMs: number): void;
|
|
66
|
+
/** Immediately stops and removes all active tweens. */
|
|
67
|
+
stopAll(): void;
|
|
68
|
+
}
|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E,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,IAAI,IAAI,IAAI,CAAC;IACb,8BAA8B;IAC9B,KAAK,IAAI,IAAI,CAAC;IACd,6BAA6B;IAC7B,MAAM,IAAI,IAAI,CAAC;IACf,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAAC;IAEtC,2EAA2E;IAC3E,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,uDAAuD;IACvD,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starweb-libs/tween",
|
|
3
|
+
"description": "Frame-driven tween manager with easing for the browser",
|
|
4
|
+
"author": "Mason L'Etoile",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/starweb-libs/tween.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/starweb-libs/tween#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/starweb-libs/tween/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["tween", "animation", "easing", "typescript", "browser", "starweb"],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"devDependencies": { "typescript": "~6.0.2" },
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"prepare": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist"],
|
|
23
|
+
"exports": {
|
|
24
|
+
"./easing.js": {
|
|
25
|
+
"types": "./dist/easing.d.ts",
|
|
26
|
+
"import": "./dist/easing.js"
|
|
27
|
+
},
|
|
28
|
+
"./manager.js": {
|
|
29
|
+
"types": "./dist/manager.d.ts",
|
|
30
|
+
"import": "./dist/manager.js"
|
|
31
|
+
},
|
|
32
|
+
"./types.js": {
|
|
33
|
+
"types": "./dist/types.d.ts",
|
|
34
|
+
"import": "./dist/types.js"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|