@flare-engine/animation 0.2.1 → 0.3.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/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +8 -3
- package/dist/index.d.mts +139 -132
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +139 -132
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +286 -287
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -232
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { EasingFn } from "@flare-engine/math";
|
|
2
|
+
import { SpriteFrame, SpriteSheet } from "@flare-engine/assets";
|
|
3
|
+
//#region src/periodic.d.ts
|
|
4
|
+
/** Oscillating tween that ping-pongs between `from` and `to` indefinitely. */
|
|
5
|
+
interface PeriodicTween {
|
|
6
|
+
/** Start value. */
|
|
7
|
+
readonly from: number;
|
|
8
|
+
/** End value. */
|
|
9
|
+
readonly to: number;
|
|
10
|
+
/** Full cycle period in seconds (from → to → from). */
|
|
11
|
+
readonly period: number;
|
|
12
|
+
/** Easing function (default: easeInOutSine). */
|
|
13
|
+
readonly easing: EasingFn;
|
|
14
|
+
/** Elapsed time in seconds — mutable, advanced by updatePeriodicTween. */
|
|
15
|
+
elapsed: number;
|
|
16
|
+
/** Current interpolated value — written by updatePeriodicTween. */
|
|
17
|
+
value: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a periodic oscillating tween.
|
|
21
|
+
*
|
|
22
|
+
* @param from Start value.
|
|
23
|
+
* @param to End value.
|
|
24
|
+
* @param period Full cycle duration in seconds (must be > 0).
|
|
25
|
+
* @param easing Easing function. Defaults to easeInOutSine.
|
|
26
|
+
*/
|
|
27
|
+
declare function periodicTween(from: number, to: number, period: number, easing?: EasingFn): PeriodicTween;
|
|
28
|
+
/**
|
|
29
|
+
* Advance a periodic tween by `dt` seconds. Wraps elapsed modulo period,
|
|
30
|
+
* computes ping-pong t, applies easing, writes `value`, returns it.
|
|
31
|
+
*/
|
|
32
|
+
declare function updatePeriodicTween(tw: PeriodicTween, dt: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Reset a periodic tween: zero elapsed, restore value to `from`.
|
|
35
|
+
*/
|
|
36
|
+
declare function resetPeriodicTween(tw: PeriodicTween): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/spring.d.ts
|
|
39
|
+
/** Spring configuration. */
|
|
40
|
+
interface SpringConfig {
|
|
41
|
+
/** Spring stiffness (higher = faster oscillation). Default: 100. */
|
|
42
|
+
stiffness: number;
|
|
43
|
+
/** Damping coefficient (higher = less oscillation). Default: 10. */
|
|
44
|
+
damping: number;
|
|
45
|
+
/** Mass of the spring body. Default: 1. */
|
|
46
|
+
mass: number;
|
|
47
|
+
}
|
|
48
|
+
/** Spring state. */
|
|
49
|
+
interface Spring {
|
|
50
|
+
/** Current value. */
|
|
51
|
+
value: number;
|
|
52
|
+
/** Current velocity. */
|
|
53
|
+
velocity: number;
|
|
54
|
+
/** Target value. */
|
|
55
|
+
target: number;
|
|
56
|
+
/** Configuration. */
|
|
57
|
+
config: SpringConfig;
|
|
58
|
+
/** Whether the spring has settled (within rest threshold). */
|
|
59
|
+
atRest: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** Create a spring with initial value. */
|
|
62
|
+
declare function spring(value: number, target: number, config?: Partial<SpringConfig>): Spring;
|
|
63
|
+
/**
|
|
64
|
+
* Update a spring by dt seconds. Returns the current value.
|
|
65
|
+
* Uses semi-implicit Euler integration for stability.
|
|
66
|
+
*/
|
|
67
|
+
declare function updateSpring(s: Spring, dt: number): number;
|
|
68
|
+
/** Set a new target for the spring. Wakes it if at rest. */
|
|
69
|
+
declare function setSpringTarget(s: Spring, target: number): void;
|
|
70
|
+
/** Reset both value and target, zeroing velocity. */
|
|
71
|
+
declare function resetSpring(s: Spring, value: number): void;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/sprite-animator.d.ts
|
|
4
74
|
/** State of a sprite animator. */
|
|
5
75
|
interface SpriteAnimatorState {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
76
|
+
/** The sprite sheet data source. */
|
|
77
|
+
sheet: SpriteSheet;
|
|
78
|
+
/** Current animation name, or null if none. */
|
|
79
|
+
currentAnimation: string | null;
|
|
80
|
+
/** Current frame index within the animation sequence. */
|
|
81
|
+
frameIndex: number;
|
|
82
|
+
/** Accumulated time within current frame (seconds). */
|
|
83
|
+
elapsed: number;
|
|
84
|
+
/** Whether animation is paused. */
|
|
85
|
+
paused: boolean;
|
|
86
|
+
/** Whether the current sequence has finished (non-looping). */
|
|
87
|
+
finished: boolean;
|
|
18
88
|
}
|
|
19
89
|
/** Create a sprite animator state bound to a sprite sheet. */
|
|
20
90
|
declare function createSpriteAnimator(sheet: SpriteSheet): SpriteAnimatorState;
|
|
@@ -33,27 +103,56 @@ declare function resumeAnimation(state: SpriteAnimatorState): void;
|
|
|
33
103
|
declare function updateAnimator(state: SpriteAnimatorState, dt: number): SpriteFrame | null;
|
|
34
104
|
/** Get the current SpriteFrame without advancing time. */
|
|
35
105
|
declare function getCurrentFrame(state: SpriteAnimatorState): SpriteFrame | null;
|
|
36
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/step-sequence.d.ts
|
|
108
|
+
interface StepSequenceStep {
|
|
109
|
+
readonly duration: number;
|
|
110
|
+
}
|
|
111
|
+
interface StepSequence {
|
|
112
|
+
readonly steps: readonly StepSequenceStep[];
|
|
113
|
+
current: number;
|
|
114
|
+
elapsed: number;
|
|
115
|
+
}
|
|
116
|
+
declare function createStepSequence(steps: readonly StepSequenceStep[]): StepSequence;
|
|
117
|
+
declare function tickStepSequence(seq: StepSequence, dt: number): number;
|
|
118
|
+
declare function resetStepSequence(seq: StepSequence): void;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/timed-modifier.d.ts
|
|
121
|
+
interface TimedModifier<T> {
|
|
122
|
+
readonly value: T;
|
|
123
|
+
readonly combine: (base: T, modifier: T) => T;
|
|
124
|
+
remaining: number;
|
|
125
|
+
}
|
|
126
|
+
declare function createTimedModifier<T>(value: T, duration: number, combine: (base: T, modifier: T) => T): TimedModifier<T>;
|
|
127
|
+
declare function tickModifier<T>(mod: TimedModifier<T>, dt: number): void;
|
|
128
|
+
declare function isModifierActive<T>(mod: TimedModifier<T>): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Returns combine(base, mod.value) when active, base otherwise.
|
|
131
|
+
* Zero-alloc only when T is number and combine is pure arithmetic.
|
|
132
|
+
*/
|
|
133
|
+
declare function applyModifier<T>(base: T, mod: TimedModifier<T>): T;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/tween.d.ts
|
|
37
136
|
/** Tween state. */
|
|
38
137
|
interface Tween {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
138
|
+
/** Start value. */
|
|
139
|
+
from: number;
|
|
140
|
+
/** End value. */
|
|
141
|
+
to: number;
|
|
142
|
+
/** Duration in seconds. */
|
|
143
|
+
duration: number;
|
|
144
|
+
/** Easing function. */
|
|
145
|
+
easing: EasingFn;
|
|
146
|
+
/** Elapsed time in seconds. */
|
|
147
|
+
elapsed: number;
|
|
148
|
+
/** Current interpolated value. */
|
|
149
|
+
value: number;
|
|
150
|
+
/** Whether the tween is complete. */
|
|
151
|
+
done: boolean;
|
|
152
|
+
/** Optional callback when tween completes. */
|
|
153
|
+
onComplete: (() => void) | null;
|
|
154
|
+
/** Chained tween to start after this one completes. */
|
|
155
|
+
next: Tween | null;
|
|
57
156
|
}
|
|
58
157
|
/** Create a tween. */
|
|
59
158
|
declare function tween(from: number, to: number, duration: number, easing?: EasingFn): Tween;
|
|
@@ -66,48 +165,15 @@ declare function updateTween(tw: Tween, dt: number): number;
|
|
|
66
165
|
declare function chainTween(tw: Tween, next: Tween): Tween;
|
|
67
166
|
/** Reset a tween to its initial state. */
|
|
68
167
|
declare function resetTween(tw: Tween): void;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
interface SpringConfig {
|
|
72
|
-
/** Spring stiffness (higher = faster oscillation). Default: 100. */
|
|
73
|
-
stiffness: number;
|
|
74
|
-
/** Damping coefficient (higher = less oscillation). Default: 10. */
|
|
75
|
-
damping: number;
|
|
76
|
-
/** Mass of the spring body. Default: 1. */
|
|
77
|
-
mass: number;
|
|
78
|
-
}
|
|
79
|
-
/** Spring state. */
|
|
80
|
-
interface Spring {
|
|
81
|
-
/** Current value. */
|
|
82
|
-
value: number;
|
|
83
|
-
/** Current velocity. */
|
|
84
|
-
velocity: number;
|
|
85
|
-
/** Target value. */
|
|
86
|
-
target: number;
|
|
87
|
-
/** Configuration. */
|
|
88
|
-
config: SpringConfig;
|
|
89
|
-
/** Whether the spring has settled (within rest threshold). */
|
|
90
|
-
atRest: boolean;
|
|
91
|
-
}
|
|
92
|
-
/** Create a spring with initial value. */
|
|
93
|
-
declare function spring(value: number, target: number, config?: Partial<SpringConfig>): Spring;
|
|
94
|
-
/**
|
|
95
|
-
* Update a spring by dt seconds. Returns the current value.
|
|
96
|
-
* Uses semi-implicit Euler integration for stability.
|
|
97
|
-
*/
|
|
98
|
-
declare function updateSpring(s: Spring, dt: number): number;
|
|
99
|
-
/** Set a new target for the spring. Wakes it if at rest. */
|
|
100
|
-
declare function setSpringTarget(s: Spring, target: number): void;
|
|
101
|
-
/** Reset both value and target, zeroing velocity. */
|
|
102
|
-
declare function resetSpring(s: Spring, value: number): void;
|
|
103
|
-
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/tween-manager.d.ts
|
|
104
170
|
/**
|
|
105
171
|
* Manages a collection of active tweens.
|
|
106
172
|
* Automatically removes completed tweens (or advances to chained tweens).
|
|
107
173
|
*/
|
|
108
174
|
interface TweenManager {
|
|
109
|
-
|
|
110
|
-
|
|
175
|
+
/** Active tweens. */
|
|
176
|
+
readonly tweens: Tween[];
|
|
111
177
|
}
|
|
112
178
|
/** Create a new TweenManager. */
|
|
113
179
|
declare function createTweenManager(): TweenManager;
|
|
@@ -120,65 +186,6 @@ declare function addTween(mgr: TweenManager, tw: Tween): void;
|
|
|
120
186
|
declare function updateTweens(mgr: TweenManager, dt: number): void;
|
|
121
187
|
/** Remove all tweens. */
|
|
122
188
|
declare function clearTweens(mgr: TweenManager): void;
|
|
123
|
-
|
|
124
|
-
/** Oscillating tween that ping-pongs between `from` and `to` indefinitely. */
|
|
125
|
-
interface PeriodicTween {
|
|
126
|
-
/** Start value. */
|
|
127
|
-
readonly from: number;
|
|
128
|
-
/** End value. */
|
|
129
|
-
readonly to: number;
|
|
130
|
-
/** Full cycle period in seconds (from → to → from). */
|
|
131
|
-
readonly period: number;
|
|
132
|
-
/** Easing function (default: easeInOutSine). */
|
|
133
|
-
readonly easing: EasingFn;
|
|
134
|
-
/** Elapsed time in seconds — mutable, advanced by updatePeriodicTween. */
|
|
135
|
-
elapsed: number;
|
|
136
|
-
/** Current interpolated value — written by updatePeriodicTween. */
|
|
137
|
-
value: number;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Create a periodic oscillating tween.
|
|
141
|
-
*
|
|
142
|
-
* @param from Start value.
|
|
143
|
-
* @param to End value.
|
|
144
|
-
* @param period Full cycle duration in seconds (must be > 0).
|
|
145
|
-
* @param easing Easing function. Defaults to easeInOutSine.
|
|
146
|
-
*/
|
|
147
|
-
declare function periodicTween(from: number, to: number, period: number, easing?: EasingFn): PeriodicTween;
|
|
148
|
-
/**
|
|
149
|
-
* Advance a periodic tween by `dt` seconds. Wraps elapsed modulo period,
|
|
150
|
-
* computes ping-pong t, applies easing, writes `value`, returns it.
|
|
151
|
-
*/
|
|
152
|
-
declare function updatePeriodicTween(tw: PeriodicTween, dt: number): number;
|
|
153
|
-
/**
|
|
154
|
-
* Reset a periodic tween: zero elapsed, restore value to `from`.
|
|
155
|
-
*/
|
|
156
|
-
declare function resetPeriodicTween(tw: PeriodicTween): void;
|
|
157
|
-
|
|
158
|
-
interface StepSequenceStep {
|
|
159
|
-
readonly duration: number;
|
|
160
|
-
}
|
|
161
|
-
interface StepSequence {
|
|
162
|
-
readonly steps: readonly StepSequenceStep[];
|
|
163
|
-
current: number;
|
|
164
|
-
elapsed: number;
|
|
165
|
-
}
|
|
166
|
-
declare function createStepSequence(steps: readonly StepSequenceStep[]): StepSequence;
|
|
167
|
-
declare function tickStepSequence(seq: StepSequence, dt: number): number;
|
|
168
|
-
declare function resetStepSequence(seq: StepSequence): void;
|
|
169
|
-
|
|
170
|
-
interface TimedModifier<T> {
|
|
171
|
-
readonly value: T;
|
|
172
|
-
readonly combine: (base: T, modifier: T) => T;
|
|
173
|
-
remaining: number;
|
|
174
|
-
}
|
|
175
|
-
declare function createTimedModifier<T>(value: T, duration: number, combine: (base: T, modifier: T) => T): TimedModifier<T>;
|
|
176
|
-
declare function tickModifier<T>(mod: TimedModifier<T>, dt: number): void;
|
|
177
|
-
declare function isModifierActive<T>(mod: TimedModifier<T>): boolean;
|
|
178
|
-
/**
|
|
179
|
-
* Returns combine(base, mod.value) when active, base otherwise.
|
|
180
|
-
* Zero-alloc only when T is number and combine is pure arithmetic.
|
|
181
|
-
*/
|
|
182
|
-
declare function applyModifier<T>(base: T, mod: TimedModifier<T>): T;
|
|
183
|
-
|
|
189
|
+
//#endregion
|
|
184
190
|
export { type PeriodicTween, type Spring, type SpringConfig, type SpriteAnimatorState, type StepSequence, type StepSequenceStep, type TimedModifier, type Tween, type TweenManager, addTween, applyModifier, chainTween, clearTweens, createSpriteAnimator, createStepSequence, createTimedModifier, createTweenManager, getCurrentFrame, isModifierActive, pauseAnimation, periodicTween, playAnimation, resetPeriodicTween, resetSpring, resetStepSequence, resetTween, resumeAnimation, setSpringTarget, spring, stopAnimation, tickModifier, tickStepSequence, tween, updateAnimator, updatePeriodicTween, updateSpring, updateTween, updateTweens };
|
|
191
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/periodic.ts","../src/spring.ts","../src/sprite-animator.ts","../src/step-sequence.ts","../src/timed-modifier.ts","../src/tween.ts","../src/tween-manager.ts"],"mappings":";;;;UAGiB;;WAEN;;WAEA;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA;;;;;;;;;;iBAWc,cACd,cACA,YACA,gBACA,SAAQ,WACP;;;;;iBASa,oBAAoB,IAAI,eAAe;;;;iBAavC,mBAAmB,IAAI;;;;UCpDtB;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA;;EAEA,QAAQ;;EAER;;;iBAOc,OAAO,eAAe,gBAAgB,SAAS,QAAQ,gBAAgB;;;;;iBAkBvE,aAAa,GAAG,QAAQ;;iBAwBxB,gBAAgB,GAAG,QAAQ;;iBAM3B,YAAY,GAAG,QAAQ;;;;UCzEtB;;EAEf,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;EAEA;;;iBAIc,qBAAqB,OAAO,cAAc;;iBAY1C,cAAc,OAAO,qBAAqB;;iBAW1C,cAAc,OAAO;;iBASrB,eAAe,OAAO;;iBAKtB,gBAAgB,OAAO;;;;;iBAQvB,eAAe,OAAO,qBAAqB,aAAa;;iBA+BxD,gBAAgB,OAAO,sBAAsB;;;UC/F5C;WACN;;UAGM;WACN,gBAAgB;EACzB;EACA;;iBAGc,mBAAmB,gBAAgB,qBAAqB;iBASxD,iBAAiB,KAAK,cAAc;iBASpC,kBAAkB,KAAK;;;UC5BtB,cAAc;WACpB,OAAO;WACP,UAAU,MAAM,GAAG,UAAU,MAAM;EAC5C;;iBAGc,oBAAoB,GAClC,OAAO,GACP,kBACA,UAAU,MAAM,GAAG,UAAU,MAAM,IAClC,cAAc;iBAKD,aAAa,GAAG,KAAK,cAAc,IAAI;iBAIvC,iBAAiB,GAAG,KAAK,cAAc;;;;;iBAQvC,cAAc,GAAG,MAAM,GAAG,KAAK,cAAc,KAAK;;;;UCxBjD;;EAEf;;EAEA;;EAEA;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA,MAAM;;;iBASQ,MAAM,cAAc,YAAY,kBAAkB,SAAS,WAAW;;;;;iBAkBtE,YAAY,IAAI,OAAO;;iBAmBvB,WAAW,IAAI,OAAO,MAAM,QAAQ;;iBAMpC,WAAW,IAAI;;;;;;;UClEd;;WAEN,QAAQ;;;iBAIH,sBAAsB;;iBAKtB,SAAS,KAAK,cAAc,IAAI;;;;;iBAQhC,aAAa,KAAK,cAAc;;iBAuBhC,YAAY,KAAK"}
|