@codexo/exojs 0.6.10 → 0.6.11
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/CHANGELOG.md +63 -0
- package/dist/esm/animation/Easing.d.ts +45 -0
- package/dist/esm/animation/Easing.js +112 -0
- package/dist/esm/animation/Easing.js.map +1 -0
- package/dist/esm/animation/Tween.d.ts +100 -0
- package/dist/esm/animation/Tween.js +270 -0
- package/dist/esm/animation/Tween.js.map +1 -0
- package/dist/esm/animation/TweenManager.d.ts +30 -0
- package/dist/esm/animation/TweenManager.js +65 -0
- package/dist/esm/animation/TweenManager.js.map +1 -0
- package/dist/esm/animation/index.d.ts +4 -0
- package/dist/esm/animation/types.d.ts +10 -0
- package/dist/esm/animation/types.js +11 -0
- package/dist/esm/animation/types.js.map +1 -0
- package/dist/esm/core/Application.d.ts +2 -0
- package/dist/esm/core/Application.js +4 -0
- package/dist/esm/core/Application.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/exo.esm.js +449 -1
- package/dist/exo.esm.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,69 @@ All notable changes to ExoJS are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.6.11] - 2026-05-02
|
|
8
|
+
|
|
9
|
+
Adds a fluent-builder Tween / Animation system. Pure addition — no
|
|
10
|
+
existing surface changes shape.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`Tween` class.** Fluent-builder API for animating numeric
|
|
15
|
+
properties on any target object:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
app.tweens.create(sprite)
|
|
19
|
+
.to({ x: 100, alpha: 0.5 }, 1.0) // 1 second
|
|
20
|
+
.easing(Ease.cubicOut)
|
|
21
|
+
.delay(0.2)
|
|
22
|
+
.onComplete(() => console.log('done'))
|
|
23
|
+
.start();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Lifecycle: `Idle → Active → Complete | Stopped` (with
|
|
27
|
+
`Paused` as an intermediate). Supports `delay()`, `repeat(N)`
|
|
28
|
+
with `repeat(-1)` for infinite, `yoyo()` to reverse on each
|
|
29
|
+
repeat, `chain(next)` to start another tween on completion,
|
|
30
|
+
and the standard `pause()` / `resume()` / `stop()` controls.
|
|
31
|
+
Lifecycle callbacks: `onStart` (after delay, on first
|
|
32
|
+
interpolation), `onUpdate` (per frame), `onRepeat` (cycle
|
|
33
|
+
boundaries), `onComplete` (final cycle ends naturally).
|
|
34
|
+
`stop()` does NOT fire `onComplete`.
|
|
35
|
+
- **`TweenManager` class.** Owns active tweens and ticks them
|
|
36
|
+
from `Application.update()`. Use `app.tweens.create(target)` to
|
|
37
|
+
spawn-and-register a tween in one call; `app.tweens.add(tween)`
|
|
38
|
+
for stand-alone constructions; `manager.update(dt)` /
|
|
39
|
+
`manager.clear()` / `manager.destroy()` for lifecycle. Tweens
|
|
40
|
+
self-remove on natural completion or `stop()`.
|
|
41
|
+
- **`Ease` namespace.** Robert Penner's standard library, 31
|
|
42
|
+
functions: `linear`, `quad{In,Out,InOut}`, `cubic{...}`,
|
|
43
|
+
`quart{...}`, `quint{...}`, `sine{...}`, `expo{...}`,
|
|
44
|
+
`circ{...}`, `back{...}`, `bounce{...}`, `elastic{...}`. Each
|
|
45
|
+
returns 0 at `t=0` and 1 at `t=1`. Use `Ease.cubicOut` (etc.) as
|
|
46
|
+
the argument to `.easing()`.
|
|
47
|
+
- **`Application.tweens: TweenManager`.** Pre-instantiated on
|
|
48
|
+
every Application; ticked automatically each frame between
|
|
49
|
+
`inputManager.update()` and `sceneManager.update()`. So
|
|
50
|
+
tween-driven sprite positions are visible during the same
|
|
51
|
+
frame's render.
|
|
52
|
+
- **Types: `EasingFunction`, `TweenLifecycleCallback`,
|
|
53
|
+
`TweenUpdateCallback`, `TweenState`** — all exported.
|
|
54
|
+
|
|
55
|
+
### Notes
|
|
56
|
+
|
|
57
|
+
- v1 supports **shallow numeric properties only**. Tweening
|
|
58
|
+
`{ x: 100 }` works; tweening `{ position: someVector }` does
|
|
59
|
+
not (use `{ x, y }` instead). Vector / Color / Matrix
|
|
60
|
+
interpolators are deferred to v2.
|
|
61
|
+
- Non-numeric target properties at start time emit a
|
|
62
|
+
`console.warn` and are skipped; they don't throw.
|
|
63
|
+
- Lazy snapshot of start values: `to()` records the END values;
|
|
64
|
+
the START values are captured on the FIRST `update()` after
|
|
65
|
+
`start()` (after any `delay`). Mutate the target between
|
|
66
|
+
`to()` and `start()` and the snapshot is correct.
|
|
67
|
+
- `chain()` only fires on natural completion. `stop()` does
|
|
68
|
+
not start chained tweens.
|
|
69
|
+
|
|
7
70
|
## [0.6.10] - 2026-05-02
|
|
8
71
|
|
|
9
72
|
ExoJS now ships with **zero runtime dependencies**. The single
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type EasingFunction = (t: number) => number;
|
|
2
|
+
/**
|
|
3
|
+
* Standard Robert Penner easing functions as static methods.
|
|
4
|
+
* Each function accepts a normalized time `t` in [0, 1] and returns a value
|
|
5
|
+
* that equals 0 at t=0 and 1 at t=1 (overshoot functions like back/elastic
|
|
6
|
+
* may exceed that range between the endpoints).
|
|
7
|
+
*
|
|
8
|
+
* Usage: `Ease.cubicOut`, `Ease.bounceIn`, etc.
|
|
9
|
+
*
|
|
10
|
+
* Note: only scalar numeric properties are supported in v1. Vector, Color, and
|
|
11
|
+
* Matrix interpolation are out of scope.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Ease {
|
|
14
|
+
static readonly linear: EasingFunction;
|
|
15
|
+
static readonly quadIn: EasingFunction;
|
|
16
|
+
static readonly quadOut: EasingFunction;
|
|
17
|
+
static readonly quadInOut: EasingFunction;
|
|
18
|
+
static readonly cubicIn: EasingFunction;
|
|
19
|
+
static readonly cubicOut: EasingFunction;
|
|
20
|
+
static readonly cubicInOut: EasingFunction;
|
|
21
|
+
static readonly quartIn: EasingFunction;
|
|
22
|
+
static readonly quartOut: EasingFunction;
|
|
23
|
+
static readonly quartInOut: EasingFunction;
|
|
24
|
+
static readonly quintIn: EasingFunction;
|
|
25
|
+
static readonly quintOut: EasingFunction;
|
|
26
|
+
static readonly quintInOut: EasingFunction;
|
|
27
|
+
static readonly sineIn: EasingFunction;
|
|
28
|
+
static readonly sineOut: EasingFunction;
|
|
29
|
+
static readonly sineInOut: EasingFunction;
|
|
30
|
+
static readonly expoIn: EasingFunction;
|
|
31
|
+
static readonly expoOut: EasingFunction;
|
|
32
|
+
static readonly expoInOut: EasingFunction;
|
|
33
|
+
static readonly circIn: EasingFunction;
|
|
34
|
+
static readonly circOut: EasingFunction;
|
|
35
|
+
static readonly circInOut: EasingFunction;
|
|
36
|
+
static readonly backIn: EasingFunction;
|
|
37
|
+
static readonly backOut: EasingFunction;
|
|
38
|
+
static readonly backInOut: EasingFunction;
|
|
39
|
+
static readonly bounceOut: EasingFunction;
|
|
40
|
+
static readonly bounceIn: EasingFunction;
|
|
41
|
+
static readonly bounceInOut: EasingFunction;
|
|
42
|
+
static readonly elasticIn: EasingFunction;
|
|
43
|
+
static readonly elasticOut: EasingFunction;
|
|
44
|
+
static readonly elasticInOut: EasingFunction;
|
|
45
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const bounceOutFn = (t) => {
|
|
2
|
+
const n1 = 7.5625;
|
|
3
|
+
const d1 = 2.75;
|
|
4
|
+
if (t < 1 / d1) {
|
|
5
|
+
return n1 * t * t;
|
|
6
|
+
}
|
|
7
|
+
else if (t < 2 / d1) {
|
|
8
|
+
return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
9
|
+
}
|
|
10
|
+
else if (t < 2.5 / d1) {
|
|
11
|
+
return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Standard Robert Penner easing functions as static methods.
|
|
19
|
+
* Each function accepts a normalized time `t` in [0, 1] and returns a value
|
|
20
|
+
* that equals 0 at t=0 and 1 at t=1 (overshoot functions like back/elastic
|
|
21
|
+
* may exceed that range between the endpoints).
|
|
22
|
+
*
|
|
23
|
+
* Usage: `Ease.cubicOut`, `Ease.bounceIn`, etc.
|
|
24
|
+
*
|
|
25
|
+
* Note: only scalar numeric properties are supported in v1. Vector, Color, and
|
|
26
|
+
* Matrix interpolation are out of scope.
|
|
27
|
+
*/
|
|
28
|
+
class Ease {
|
|
29
|
+
static linear = (t) => t;
|
|
30
|
+
static quadIn = (t) => t * t;
|
|
31
|
+
static quadOut = (t) => t * (2 - t);
|
|
32
|
+
static quadInOut = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
33
|
+
static cubicIn = (t) => t * t * t;
|
|
34
|
+
static cubicOut = (t) => (--t) * t * t + 1;
|
|
35
|
+
static cubicInOut = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
36
|
+
static quartIn = (t) => t * t * t * t;
|
|
37
|
+
static quartOut = (t) => 1 - (--t) * t * t * t;
|
|
38
|
+
static quartInOut = (t) => t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2;
|
|
39
|
+
static quintIn = (t) => t * t * t * t * t;
|
|
40
|
+
static quintOut = (t) => 1 + (--t) * t * t * t * t;
|
|
41
|
+
static quintInOut = (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 - Math.pow(-2 * t + 2, 5) / 2;
|
|
42
|
+
static sineIn = (t) => 1 - Math.cos((t * Math.PI) / 2);
|
|
43
|
+
static sineOut = (t) => Math.sin((t * Math.PI) / 2);
|
|
44
|
+
static sineInOut = (t) => -(Math.cos(Math.PI * t) - 1) / 2;
|
|
45
|
+
static expoIn = (t) => t === 0 ? 0 : Math.pow(2, 10 * t - 10);
|
|
46
|
+
static expoOut = (t) => t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
|
|
47
|
+
static expoInOut = (t) => {
|
|
48
|
+
if (t === 0)
|
|
49
|
+
return 0;
|
|
50
|
+
if (t === 1)
|
|
51
|
+
return 1;
|
|
52
|
+
return t < 0.5
|
|
53
|
+
? Math.pow(2, 20 * t - 10) / 2
|
|
54
|
+
: (2 - Math.pow(2, -20 * t + 10)) / 2;
|
|
55
|
+
};
|
|
56
|
+
static circIn = (t) => 1 - Math.sqrt(1 - Math.pow(t, 2));
|
|
57
|
+
static circOut = (t) => Math.sqrt(1 - Math.pow(t - 1, 2));
|
|
58
|
+
static circInOut = (t) => t < 0.5
|
|
59
|
+
? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2
|
|
60
|
+
: (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2;
|
|
61
|
+
static backIn = (t) => {
|
|
62
|
+
const c1 = 1.70158;
|
|
63
|
+
const c3 = c1 + 1;
|
|
64
|
+
return c3 * t * t * t - c1 * t * t;
|
|
65
|
+
};
|
|
66
|
+
static backOut = (t) => {
|
|
67
|
+
const c1 = 1.70158;
|
|
68
|
+
const c3 = c1 + 1;
|
|
69
|
+
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
|
|
70
|
+
};
|
|
71
|
+
static backInOut = (t) => {
|
|
72
|
+
const c1 = 1.70158;
|
|
73
|
+
const c2 = c1 * 1.525;
|
|
74
|
+
return t < 0.5
|
|
75
|
+
? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
|
|
76
|
+
: (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (2 * t - 2) + c2) + 2) / 2;
|
|
77
|
+
};
|
|
78
|
+
static bounceOut = bounceOutFn;
|
|
79
|
+
static bounceIn = (t) => 1 - bounceOutFn(1 - t);
|
|
80
|
+
static bounceInOut = (t) => t < 0.5
|
|
81
|
+
? (1 - bounceOutFn(1 - 2 * t)) / 2
|
|
82
|
+
: (1 + bounceOutFn(2 * t - 1)) / 2;
|
|
83
|
+
static elasticIn = (t) => {
|
|
84
|
+
if (t === 0)
|
|
85
|
+
return 0;
|
|
86
|
+
if (t === 1)
|
|
87
|
+
return 1;
|
|
88
|
+
const c4 = (2 * Math.PI) / 3;
|
|
89
|
+
return -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
|
|
90
|
+
};
|
|
91
|
+
static elasticOut = (t) => {
|
|
92
|
+
if (t === 0)
|
|
93
|
+
return 0;
|
|
94
|
+
if (t === 1)
|
|
95
|
+
return 1;
|
|
96
|
+
const c4 = (2 * Math.PI) / 3;
|
|
97
|
+
return Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
|
|
98
|
+
};
|
|
99
|
+
static elasticInOut = (t) => {
|
|
100
|
+
if (t === 0)
|
|
101
|
+
return 0;
|
|
102
|
+
if (t === 1)
|
|
103
|
+
return 1;
|
|
104
|
+
const c5 = (2 * Math.PI) / 4.5;
|
|
105
|
+
return t < 0.5
|
|
106
|
+
? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
|
|
107
|
+
: (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { Ease };
|
|
112
|
+
//# sourceMappingURL=Easing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Easing.js","sources":["../../../../src/animation/Easing.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,CAAC,CAAS,KAAY;IACtC,MAAM,EAAE,GAAG,MAAM;IACjB,MAAM,EAAE,GAAG,IAAI;AAEf,IA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GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,GAAG,CAAC;AACpE,IAAA,CAAC;AACM,IAAA,OAAgB,YAAY,GAAmB,CAAC,CAAS,KAAY;QACxE,IAAI,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,GAAG;QAE9B,OAAO,CAAC,GAAG;AACP,cAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG;AACnE,cAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;AAChF,IAAA,CAAC;;;;;"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { TweenState } from './types';
|
|
2
|
+
import type { EasingFunction, TweenLifecycleCallback, TweenUpdateCallback } from './types';
|
|
3
|
+
import type { TweenManager } from './TweenManager';
|
|
4
|
+
export declare class Tween<T extends object = object> {
|
|
5
|
+
private readonly _target;
|
|
6
|
+
private _state;
|
|
7
|
+
private _properties;
|
|
8
|
+
private _startValues;
|
|
9
|
+
private _duration;
|
|
10
|
+
private _delay;
|
|
11
|
+
private _easing;
|
|
12
|
+
private _elapsed;
|
|
13
|
+
private _delayElapsed;
|
|
14
|
+
/**
|
|
15
|
+
* Remaining repeat cycles. -1 = infinite.
|
|
16
|
+
* At start this is set to _repeatTotal. Decremented on each cycle boundary.
|
|
17
|
+
*/
|
|
18
|
+
private _repeatCount;
|
|
19
|
+
/** The value as configured by .repeat(). Preserved for reset. */
|
|
20
|
+
private _repeatTotal;
|
|
21
|
+
private _yoyo;
|
|
22
|
+
/** Current playback direction: 1 = forward, -1 = reverse. */
|
|
23
|
+
private _direction;
|
|
24
|
+
private _onStart;
|
|
25
|
+
private _onUpdate;
|
|
26
|
+
private _onComplete;
|
|
27
|
+
private _onRepeat;
|
|
28
|
+
private _chained;
|
|
29
|
+
private _manager;
|
|
30
|
+
/** Whether onStart has already fired this tween lifecycle. */
|
|
31
|
+
private _startFired;
|
|
32
|
+
constructor(target: T);
|
|
33
|
+
get target(): T;
|
|
34
|
+
get state(): TweenState;
|
|
35
|
+
/**
|
|
36
|
+
* Current eased progress in 0..1. Reflects the eased t after applying the
|
|
37
|
+
* easing function, not the raw elapsed/duration ratio.
|
|
38
|
+
*/
|
|
39
|
+
get progress(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Set target end-values and duration in seconds. Replaces any prior to().
|
|
42
|
+
* The starting values are captured lazily on first update() after start(),
|
|
43
|
+
* so mutating target between to() and start() is safe.
|
|
44
|
+
*/
|
|
45
|
+
to(properties: Partial<Record<keyof T, number>>, duration: number): this;
|
|
46
|
+
/** Delay in seconds before the tween begins interpolating. Default 0. */
|
|
47
|
+
delay(seconds: number): this;
|
|
48
|
+
/** Easing function applied to the normalized time. Default Ease.linear. */
|
|
49
|
+
easing(fn: EasingFunction): this;
|
|
50
|
+
/**
|
|
51
|
+
* Number of additional repeat cycles. -1 = infinite. Default 0 (runs once).
|
|
52
|
+
* Note: repeat(2) means the animation runs 3 times total.
|
|
53
|
+
*/
|
|
54
|
+
repeat(count: number): this;
|
|
55
|
+
/**
|
|
56
|
+
* Reverse playback direction on each repeat cycle. Only meaningful when
|
|
57
|
+
* combined with repeat(). Calling yoyo() without repeat() is a no-op.
|
|
58
|
+
*/
|
|
59
|
+
yoyo(enabled?: boolean): this;
|
|
60
|
+
onStart(callback: TweenLifecycleCallback): this;
|
|
61
|
+
onUpdate(callback: TweenUpdateCallback): this;
|
|
62
|
+
onComplete(callback: TweenLifecycleCallback): this;
|
|
63
|
+
onRepeat(callback: TweenLifecycleCallback): this;
|
|
64
|
+
/**
|
|
65
|
+
* Start the tween. If a manager owns this tween it is already tracked;
|
|
66
|
+
* otherwise this is a stand-alone tween driven by manual update() calls.
|
|
67
|
+
*/
|
|
68
|
+
start(): this;
|
|
69
|
+
/** Pause the tween. update() calls are ignored while paused. */
|
|
70
|
+
pause(): this;
|
|
71
|
+
/** Resume a paused tween from where it left off. */
|
|
72
|
+
resume(): this;
|
|
73
|
+
/**
|
|
74
|
+
* Stop the tween without finishing. Target properties stay at their
|
|
75
|
+
* current interpolated values. onComplete does NOT fire. The tween is
|
|
76
|
+
* removed from its manager if one is assigned.
|
|
77
|
+
*/
|
|
78
|
+
stop(): this;
|
|
79
|
+
/**
|
|
80
|
+
* When this tween completes naturally, automatically start `next`.
|
|
81
|
+
* Returns `next` for fluent chaining:
|
|
82
|
+
* `fadeIn.chain(moveOut).start()` — note that start() here starts moveOut,
|
|
83
|
+
* so typically you only call start() on the first tween.
|
|
84
|
+
*/
|
|
85
|
+
chain(next: Tween): Tween;
|
|
86
|
+
/**
|
|
87
|
+
* Attach this tween to a manager. Called by TweenManager.create() and
|
|
88
|
+
* TweenManager.add(). Not part of the public fluent API.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
_attachManager(manager: TweenManager): void;
|
|
92
|
+
/**
|
|
93
|
+
* Advance the tween by deltaSeconds. Called by TweenManager each frame, or
|
|
94
|
+
* manually for stand-alone usage. No-ops when Paused, Stopped, or Complete.
|
|
95
|
+
*/
|
|
96
|
+
update(deltaSeconds: number): void;
|
|
97
|
+
private _captureStartValues;
|
|
98
|
+
private _applyProgress;
|
|
99
|
+
private _complete;
|
|
100
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Ease } from './Easing.js';
|
|
2
|
+
import { TweenState } from './types.js';
|
|
3
|
+
|
|
4
|
+
class Tween {
|
|
5
|
+
_target;
|
|
6
|
+
_state = TweenState.Idle;
|
|
7
|
+
_properties = {};
|
|
8
|
+
_startValues = null;
|
|
9
|
+
_duration = 0;
|
|
10
|
+
_delay = 0;
|
|
11
|
+
_easing = Ease.linear;
|
|
12
|
+
_elapsed = 0;
|
|
13
|
+
_delayElapsed = 0;
|
|
14
|
+
/**
|
|
15
|
+
* Remaining repeat cycles. -1 = infinite.
|
|
16
|
+
* At start this is set to _repeatTotal. Decremented on each cycle boundary.
|
|
17
|
+
*/
|
|
18
|
+
_repeatCount = 0;
|
|
19
|
+
/** The value as configured by .repeat(). Preserved for reset. */
|
|
20
|
+
_repeatTotal = 0;
|
|
21
|
+
_yoyo = false;
|
|
22
|
+
/** Current playback direction: 1 = forward, -1 = reverse. */
|
|
23
|
+
_direction = 1;
|
|
24
|
+
_onStart = null;
|
|
25
|
+
_onUpdate = null;
|
|
26
|
+
_onComplete = null;
|
|
27
|
+
_onRepeat = null;
|
|
28
|
+
_chained = null;
|
|
29
|
+
_manager = null;
|
|
30
|
+
/** Whether onStart has already fired this tween lifecycle. */
|
|
31
|
+
_startFired = false;
|
|
32
|
+
constructor(target) {
|
|
33
|
+
this._target = target;
|
|
34
|
+
}
|
|
35
|
+
get target() {
|
|
36
|
+
return this._target;
|
|
37
|
+
}
|
|
38
|
+
get state() {
|
|
39
|
+
return this._state;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Current eased progress in 0..1. Reflects the eased t after applying the
|
|
43
|
+
* easing function, not the raw elapsed/duration ratio.
|
|
44
|
+
*/
|
|
45
|
+
get progress() {
|
|
46
|
+
if (this._duration === 0)
|
|
47
|
+
return 1;
|
|
48
|
+
const rawT = Math.min(this._elapsed / this._duration, 1);
|
|
49
|
+
const t = this._direction === 1 ? rawT : 1 - rawT;
|
|
50
|
+
return this._easing(t);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set target end-values and duration in seconds. Replaces any prior to().
|
|
54
|
+
* The starting values are captured lazily on first update() after start(),
|
|
55
|
+
* so mutating target between to() and start() is safe.
|
|
56
|
+
*/
|
|
57
|
+
to(properties, duration) {
|
|
58
|
+
this._properties = { ...properties };
|
|
59
|
+
this._duration = duration;
|
|
60
|
+
this._startValues = null;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/** Delay in seconds before the tween begins interpolating. Default 0. */
|
|
64
|
+
delay(seconds) {
|
|
65
|
+
this._delay = seconds;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/** Easing function applied to the normalized time. Default Ease.linear. */
|
|
69
|
+
easing(fn) {
|
|
70
|
+
this._easing = fn;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Number of additional repeat cycles. -1 = infinite. Default 0 (runs once).
|
|
75
|
+
* Note: repeat(2) means the animation runs 3 times total.
|
|
76
|
+
*/
|
|
77
|
+
repeat(count) {
|
|
78
|
+
this._repeatTotal = count;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reverse playback direction on each repeat cycle. Only meaningful when
|
|
83
|
+
* combined with repeat(). Calling yoyo() without repeat() is a no-op.
|
|
84
|
+
*/
|
|
85
|
+
yoyo(enabled = true) {
|
|
86
|
+
this._yoyo = enabled;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
onStart(callback) {
|
|
90
|
+
this._onStart = callback;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
onUpdate(callback) {
|
|
94
|
+
this._onUpdate = callback;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
onComplete(callback) {
|
|
98
|
+
this._onComplete = callback;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
onRepeat(callback) {
|
|
102
|
+
this._onRepeat = callback;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Start the tween. If a manager owns this tween it is already tracked;
|
|
107
|
+
* otherwise this is a stand-alone tween driven by manual update() calls.
|
|
108
|
+
*/
|
|
109
|
+
start() {
|
|
110
|
+
this._state = TweenState.Active;
|
|
111
|
+
this._elapsed = 0;
|
|
112
|
+
this._delayElapsed = 0;
|
|
113
|
+
this._startValues = null;
|
|
114
|
+
this._startFired = false;
|
|
115
|
+
this._direction = 1;
|
|
116
|
+
this._repeatCount = this._repeatTotal;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/** Pause the tween. update() calls are ignored while paused. */
|
|
120
|
+
pause() {
|
|
121
|
+
if (this._state === TweenState.Active) {
|
|
122
|
+
this._state = TweenState.Paused;
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/** Resume a paused tween from where it left off. */
|
|
127
|
+
resume() {
|
|
128
|
+
if (this._state === TweenState.Paused) {
|
|
129
|
+
this._state = TweenState.Active;
|
|
130
|
+
}
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Stop the tween without finishing. Target properties stay at their
|
|
135
|
+
* current interpolated values. onComplete does NOT fire. The tween is
|
|
136
|
+
* removed from its manager if one is assigned.
|
|
137
|
+
*/
|
|
138
|
+
stop() {
|
|
139
|
+
if (this._state === TweenState.Active || this._state === TweenState.Paused) {
|
|
140
|
+
this._state = TweenState.Stopped;
|
|
141
|
+
this._manager?.remove(this);
|
|
142
|
+
}
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* When this tween completes naturally, automatically start `next`.
|
|
147
|
+
* Returns `next` for fluent chaining:
|
|
148
|
+
* `fadeIn.chain(moveOut).start()` — note that start() here starts moveOut,
|
|
149
|
+
* so typically you only call start() on the first tween.
|
|
150
|
+
*/
|
|
151
|
+
chain(next) {
|
|
152
|
+
this._chained = next;
|
|
153
|
+
return next;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Attach this tween to a manager. Called by TweenManager.create() and
|
|
157
|
+
* TweenManager.add(). Not part of the public fluent API.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
_attachManager(manager) {
|
|
161
|
+
this._manager = manager;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Advance the tween by deltaSeconds. Called by TweenManager each frame, or
|
|
165
|
+
* manually for stand-alone usage. No-ops when Paused, Stopped, or Complete.
|
|
166
|
+
*/
|
|
167
|
+
update(deltaSeconds) {
|
|
168
|
+
if (this._state !== TweenState.Active)
|
|
169
|
+
return;
|
|
170
|
+
// Handle delay phase.
|
|
171
|
+
if (this._delayElapsed < this._delay) {
|
|
172
|
+
this._delayElapsed += deltaSeconds;
|
|
173
|
+
if (this._delayElapsed < this._delay)
|
|
174
|
+
return;
|
|
175
|
+
// Carry overflow past delay into elapsed.
|
|
176
|
+
const overflow = this._delayElapsed - this._delay;
|
|
177
|
+
this._delayElapsed = this._delay;
|
|
178
|
+
deltaSeconds = overflow;
|
|
179
|
+
}
|
|
180
|
+
// Lazy snapshot of start values on the first update after delay.
|
|
181
|
+
if (this._startValues === null) {
|
|
182
|
+
this._captureStartValues();
|
|
183
|
+
}
|
|
184
|
+
// Fire onStart once.
|
|
185
|
+
if (!this._startFired) {
|
|
186
|
+
this._startFired = true;
|
|
187
|
+
this._onStart?.();
|
|
188
|
+
}
|
|
189
|
+
this._elapsed += deltaSeconds;
|
|
190
|
+
// Clamp to duration for this cycle.
|
|
191
|
+
if (this._elapsed >= this._duration) {
|
|
192
|
+
this._elapsed = this._duration;
|
|
193
|
+
}
|
|
194
|
+
// Apply interpolation.
|
|
195
|
+
this._applyProgress();
|
|
196
|
+
if (this._elapsed >= this._duration) {
|
|
197
|
+
// Cycle complete.
|
|
198
|
+
const hasMoreRepeats = this._repeatCount === -1 || this._repeatCount > 0;
|
|
199
|
+
if (hasMoreRepeats) {
|
|
200
|
+
// Decrement repeat counter (skip for infinite).
|
|
201
|
+
if (this._repeatCount !== -1) {
|
|
202
|
+
this._repeatCount--;
|
|
203
|
+
}
|
|
204
|
+
this._onRepeat?.();
|
|
205
|
+
// Flip direction for yoyo.
|
|
206
|
+
if (this._yoyo) {
|
|
207
|
+
this._direction = this._direction === 1 ? -1 : 1;
|
|
208
|
+
}
|
|
209
|
+
// Reset elapsed for next cycle; carry overflow.
|
|
210
|
+
const overflow = this._elapsed - this._duration;
|
|
211
|
+
this._elapsed = overflow > 0 ? Math.min(overflow, this._duration) : 0;
|
|
212
|
+
this._startFired = false; // allow onStart to re-fire next cycle? No — spec says once.
|
|
213
|
+
// Actually spec says onStart fires when actual interpolation begins.
|
|
214
|
+
// For repeats it fires once total at the very first cycle.
|
|
215
|
+
// Re-reading spec: "onStart fires AFTER the delay (when actual interpolation begins)".
|
|
216
|
+
// We'll keep it as one-shot across the full lifecycle; don't reset _startFired.
|
|
217
|
+
this._startFired = true;
|
|
218
|
+
// Apply progress for any overflow.
|
|
219
|
+
if (overflow > 0) {
|
|
220
|
+
this._applyProgress();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// All cycles done.
|
|
225
|
+
this._complete();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
_captureStartValues() {
|
|
230
|
+
const snap = {};
|
|
231
|
+
const keys = Object.keys(this._properties);
|
|
232
|
+
for (const key of keys) {
|
|
233
|
+
const val = this._target[key];
|
|
234
|
+
if (typeof val !== 'number') {
|
|
235
|
+
console.warn(`Tween: property "${String(key)}" is not a number on target ` +
|
|
236
|
+
`(got ${typeof val}). It will be skipped.`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
snap[String(key)] = val;
|
|
240
|
+
}
|
|
241
|
+
this._startValues = snap;
|
|
242
|
+
}
|
|
243
|
+
_applyProgress() {
|
|
244
|
+
if (this._startValues === null)
|
|
245
|
+
return;
|
|
246
|
+
const rawT = this._duration === 0 ? 1 : Math.min(this._elapsed / this._duration, 1);
|
|
247
|
+
const t = this._direction === 1 ? rawT : 1 - rawT;
|
|
248
|
+
const easedT = this._easing(t);
|
|
249
|
+
const keys = Object.keys(this._startValues);
|
|
250
|
+
for (const key of keys) {
|
|
251
|
+
const start = this._startValues[key];
|
|
252
|
+
const end = this._properties[key];
|
|
253
|
+
this._target[key] = start + (end - start) * easedT;
|
|
254
|
+
}
|
|
255
|
+
this._onUpdate?.(easedT);
|
|
256
|
+
}
|
|
257
|
+
_complete() {
|
|
258
|
+
// Ensure the target is at its final interpolated position.
|
|
259
|
+
this._elapsed = this._duration;
|
|
260
|
+
this._applyProgress();
|
|
261
|
+
this._state = TweenState.Complete;
|
|
262
|
+
this._manager?.remove(this);
|
|
263
|
+
this._onComplete?.();
|
|
264
|
+
// Fire chained tween, if any.
|
|
265
|
+
this._chained?.start();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { Tween };
|
|
270
|
+
//# sourceMappingURL=Tween.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tween.js","sources":["../../../../src/animation/Tween.ts"],"sourcesContent":[null],"names":[],"mappings":";;;MAKa,KAAK,CAAA;AACG,IAAA,OAAO;AAChB,IAAA,MAAM,GAAe,UAAU,CAAC,IAAI;IAEpC,WAAW,GAAqC,EAAE;IAClD,YAAY,GAAkC,IAAI;IAClD,SAAS,GAAG,CAAC;IACb,MAAM,GAAG,CAAC;AACV,IAAA,OAAO,GAAmB,IAAI,CAAC,MAAM;IAErC,QAAQ,GAAG,CAAC;IACZ,aAAa,GAAG,CAAC;AAEzB;;;AAGG;IACK,YAAY,GAAG,CAAC;;IAEhB,YAAY,GAAG,CAAC;IAChB,KAAK,GAAG,KAAK;;IAEb,UAAU,GAAW,CAAC;IAEtB,QAAQ,GAAkC,IAAI;IAC9C,SAAS,GAA+B,IAAI;IAC5C,WAAW,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,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK,IAAI,MAAM;QACnF;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;IAC5B;IAEQ,SAAS,GAAA;;AAEb,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAC9B,IAAI,CAAC,cAAc,EAAE;AAErB,QAAA,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ;AACjC,QAAA,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC;AAC3B,QAAA,IAAI,CAAC,WAAW,IAAI;;AAGpB,QAAA,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE;IAC1B;AACH;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Tween } from './Tween';
|
|
2
|
+
export declare class TweenManager {
|
|
3
|
+
private _tweens;
|
|
4
|
+
private _destroyed;
|
|
5
|
+
/**
|
|
6
|
+
* Create a new Tween targeting `target`, register it with this manager, and
|
|
7
|
+
* return it. Call .to(...).start() on the result to begin animating.
|
|
8
|
+
*/
|
|
9
|
+
create<T extends object>(target: T): Tween<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Explicitly add a stand-alone Tween (created via `new Tween(target)`)
|
|
12
|
+
* to this manager so it participates in the update loop.
|
|
13
|
+
*/
|
|
14
|
+
add(tween: Tween): this;
|
|
15
|
+
/** Remove a tween from the manager. Called automatically on stop/complete. */
|
|
16
|
+
remove(tween: Tween): this;
|
|
17
|
+
/**
|
|
18
|
+
* Advance all active tweens by deltaSeconds. Called once per frame by
|
|
19
|
+
* Application.update(). Uses a snapshot of the list so that callbacks that
|
|
20
|
+
* add or remove tweens do not corrupt mid-iteration.
|
|
21
|
+
*/
|
|
22
|
+
update(deltaSeconds: number): this;
|
|
23
|
+
/**
|
|
24
|
+
* Remove all tweens immediately. No callbacks (onComplete etc.) fire.
|
|
25
|
+
* The tweens' states are left as-is; they are simply evicted from the list.
|
|
26
|
+
*/
|
|
27
|
+
clear(): this;
|
|
28
|
+
/** Tear down the manager. Clears tweens and makes subsequent updates no-ops. */
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|