@flare-engine/animation 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
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,29 @@
1
+ # @flare-engine/animation
2
+
3
+ Functional sprite animation, tweens, and springs. State-object + free-function design (no classes) — tree-shakeable and trivially poolable. `createSpriteAnimator` advances frames against a `SpriteSheet` from `@flare-engine/assets`; `tween` / `spring` produce immutable state mutated by `updateTween` / `updateSpring`; `TweenManager` handles auto-removal on completion.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @flare-engine/animation
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createSpriteAnimator, playAnimation, updateAnimator,
15
+ tween, updateTween, easeOutQuad } from '@flare-engine/animation';
16
+
17
+ const anim = createSpriteAnimator(sheet);
18
+ playAnimation(anim, 'walk');
19
+ updateAnimator(anim, dt);
20
+
21
+ const t = tween(0, 100, 0.5, easeOutQuad);
22
+ const value = updateTween(t, dt);
23
+ ```
24
+
25
+ See [API spec](../../docs/design/api-specs.md#flare-engineanimation--5kb-gzip) and [skill reference](../../.github/skills/flare-animation/SKILL.md).
26
+
27
+ ## License
28
+
29
+ MIT
@@ -0,0 +1,158 @@
1
+ import { SpriteSheet, SpriteFrame } from '@flare-engine/assets';
2
+ import { EasingFn } from '@flare-engine/math';
3
+
4
+ /** State of a sprite animator. */
5
+ interface SpriteAnimatorState {
6
+ /** The sprite sheet data source. */
7
+ sheet: SpriteSheet;
8
+ /** Current animation name, or null if none. */
9
+ currentAnimation: string | null;
10
+ /** Current frame index within the animation sequence. */
11
+ frameIndex: number;
12
+ /** Accumulated time within current frame (seconds). */
13
+ elapsed: number;
14
+ /** Whether animation is paused. */
15
+ paused: boolean;
16
+ /** Whether the current sequence has finished (non-looping). */
17
+ finished: boolean;
18
+ }
19
+ /** Create a sprite animator state bound to a sprite sheet. */
20
+ declare function createSpriteAnimator(sheet: SpriteSheet): SpriteAnimatorState;
21
+ /** Play a named animation. Resets to frame 0. */
22
+ declare function playAnimation(state: SpriteAnimatorState, name: string): void;
23
+ /** Stop the current animation. */
24
+ declare function stopAnimation(state: SpriteAnimatorState): void;
25
+ /** Pause the current animation. */
26
+ declare function pauseAnimation(state: SpriteAnimatorState): void;
27
+ /** Resume the current animation. */
28
+ declare function resumeAnimation(state: SpriteAnimatorState): void;
29
+ /**
30
+ * Tick the animator forward by dt seconds.
31
+ * Returns the current SpriteFrame, or null if no animation is playing.
32
+ */
33
+ declare function updateAnimator(state: SpriteAnimatorState, dt: number): SpriteFrame | null;
34
+ /** Get the current SpriteFrame without advancing time. */
35
+ declare function getCurrentFrame(state: SpriteAnimatorState): SpriteFrame | null;
36
+
37
+ /** Tween state. */
38
+ interface Tween {
39
+ /** Start value. */
40
+ from: number;
41
+ /** End value. */
42
+ to: number;
43
+ /** Duration in seconds. */
44
+ duration: number;
45
+ /** Easing function. */
46
+ easing: EasingFn;
47
+ /** Elapsed time in seconds. */
48
+ elapsed: number;
49
+ /** Current interpolated value. */
50
+ value: number;
51
+ /** Whether the tween is complete. */
52
+ done: boolean;
53
+ /** Optional callback when tween completes. */
54
+ onComplete: (() => void) | null;
55
+ /** Chained tween to start after this one completes. */
56
+ next: Tween | null;
57
+ }
58
+ /** Create a tween. */
59
+ declare function tween(from: number, to: number, duration: number, easing?: EasingFn): Tween;
60
+ /**
61
+ * Update a tween by dt seconds. Returns the current value.
62
+ * When complete, triggers onComplete callback and advances to chained tween.
63
+ */
64
+ declare function updateTween(tw: Tween, dt: number): number;
65
+ /** Chain another tween to run after this one completes. Returns the chained tween. */
66
+ declare function chainTween(tw: Tween, next: Tween): Tween;
67
+ /** Reset a tween to its initial state. */
68
+ declare function resetTween(tw: Tween): void;
69
+
70
+ /** Spring configuration. */
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
+
104
+ /**
105
+ * Manages a collection of active tweens.
106
+ * Automatically removes completed tweens (or advances to chained tweens).
107
+ */
108
+ interface TweenManager {
109
+ /** Active tweens. */
110
+ readonly tweens: Tween[];
111
+ }
112
+ /** Create a new TweenManager. */
113
+ declare function createTweenManager(): TweenManager;
114
+ /** Add a tween to the manager. */
115
+ declare function addTween(mgr: TweenManager, tw: Tween): void;
116
+ /**
117
+ * Update all managed tweens by dt seconds.
118
+ * Completed tweens are removed; chained tweens replace completed ones.
119
+ */
120
+ declare function updateTweens(mgr: TweenManager, dt: number): void;
121
+ /** Remove all tweens. */
122
+ 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
+ export { type PeriodicTween, type Spring, type SpringConfig, type SpriteAnimatorState, type Tween, type TweenManager, addTween, chainTween, clearTweens, createSpriteAnimator, createTweenManager, getCurrentFrame, pauseAnimation, periodicTween, playAnimation, resetPeriodicTween, resetSpring, resetTween, resumeAnimation, setSpringTarget, spring, stopAnimation, tween, updateAnimator, updatePeriodicTween, updateSpring, updateTween, updateTweens };
@@ -0,0 +1,158 @@
1
+ import { SpriteSheet, SpriteFrame } from '@flare-engine/assets';
2
+ import { EasingFn } from '@flare-engine/math';
3
+
4
+ /** State of a sprite animator. */
5
+ interface SpriteAnimatorState {
6
+ /** The sprite sheet data source. */
7
+ sheet: SpriteSheet;
8
+ /** Current animation name, or null if none. */
9
+ currentAnimation: string | null;
10
+ /** Current frame index within the animation sequence. */
11
+ frameIndex: number;
12
+ /** Accumulated time within current frame (seconds). */
13
+ elapsed: number;
14
+ /** Whether animation is paused. */
15
+ paused: boolean;
16
+ /** Whether the current sequence has finished (non-looping). */
17
+ finished: boolean;
18
+ }
19
+ /** Create a sprite animator state bound to a sprite sheet. */
20
+ declare function createSpriteAnimator(sheet: SpriteSheet): SpriteAnimatorState;
21
+ /** Play a named animation. Resets to frame 0. */
22
+ declare function playAnimation(state: SpriteAnimatorState, name: string): void;
23
+ /** Stop the current animation. */
24
+ declare function stopAnimation(state: SpriteAnimatorState): void;
25
+ /** Pause the current animation. */
26
+ declare function pauseAnimation(state: SpriteAnimatorState): void;
27
+ /** Resume the current animation. */
28
+ declare function resumeAnimation(state: SpriteAnimatorState): void;
29
+ /**
30
+ * Tick the animator forward by dt seconds.
31
+ * Returns the current SpriteFrame, or null if no animation is playing.
32
+ */
33
+ declare function updateAnimator(state: SpriteAnimatorState, dt: number): SpriteFrame | null;
34
+ /** Get the current SpriteFrame without advancing time. */
35
+ declare function getCurrentFrame(state: SpriteAnimatorState): SpriteFrame | null;
36
+
37
+ /** Tween state. */
38
+ interface Tween {
39
+ /** Start value. */
40
+ from: number;
41
+ /** End value. */
42
+ to: number;
43
+ /** Duration in seconds. */
44
+ duration: number;
45
+ /** Easing function. */
46
+ easing: EasingFn;
47
+ /** Elapsed time in seconds. */
48
+ elapsed: number;
49
+ /** Current interpolated value. */
50
+ value: number;
51
+ /** Whether the tween is complete. */
52
+ done: boolean;
53
+ /** Optional callback when tween completes. */
54
+ onComplete: (() => void) | null;
55
+ /** Chained tween to start after this one completes. */
56
+ next: Tween | null;
57
+ }
58
+ /** Create a tween. */
59
+ declare function tween(from: number, to: number, duration: number, easing?: EasingFn): Tween;
60
+ /**
61
+ * Update a tween by dt seconds. Returns the current value.
62
+ * When complete, triggers onComplete callback and advances to chained tween.
63
+ */
64
+ declare function updateTween(tw: Tween, dt: number): number;
65
+ /** Chain another tween to run after this one completes. Returns the chained tween. */
66
+ declare function chainTween(tw: Tween, next: Tween): Tween;
67
+ /** Reset a tween to its initial state. */
68
+ declare function resetTween(tw: Tween): void;
69
+
70
+ /** Spring configuration. */
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
+
104
+ /**
105
+ * Manages a collection of active tweens.
106
+ * Automatically removes completed tweens (or advances to chained tweens).
107
+ */
108
+ interface TweenManager {
109
+ /** Active tweens. */
110
+ readonly tweens: Tween[];
111
+ }
112
+ /** Create a new TweenManager. */
113
+ declare function createTweenManager(): TweenManager;
114
+ /** Add a tween to the manager. */
115
+ declare function addTween(mgr: TweenManager, tw: Tween): void;
116
+ /**
117
+ * Update all managed tweens by dt seconds.
118
+ * Completed tweens are removed; chained tweens replace completed ones.
119
+ */
120
+ declare function updateTweens(mgr: TweenManager, dt: number): void;
121
+ /** Remove all tweens. */
122
+ 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
+ export { type PeriodicTween, type Spring, type SpringConfig, type SpriteAnimatorState, type Tween, type TweenManager, addTween, chainTween, clearTweens, createSpriteAnimator, createTweenManager, getCurrentFrame, pauseAnimation, periodicTween, playAnimation, resetPeriodicTween, resetSpring, resetTween, resumeAnimation, setSpringTarget, spring, stopAnimation, tween, updateAnimator, updatePeriodicTween, updateSpring, updateTween, updateTweens };
package/dist/index.js ADDED
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ addTween: () => addTween,
24
+ chainTween: () => chainTween,
25
+ clearTweens: () => clearTweens,
26
+ createSpriteAnimator: () => createSpriteAnimator,
27
+ createTweenManager: () => createTweenManager,
28
+ getCurrentFrame: () => getCurrentFrame,
29
+ pauseAnimation: () => pauseAnimation,
30
+ periodicTween: () => periodicTween,
31
+ playAnimation: () => playAnimation,
32
+ resetPeriodicTween: () => resetPeriodicTween,
33
+ resetSpring: () => resetSpring,
34
+ resetTween: () => resetTween,
35
+ resumeAnimation: () => resumeAnimation,
36
+ setSpringTarget: () => setSpringTarget,
37
+ spring: () => spring,
38
+ stopAnimation: () => stopAnimation,
39
+ tween: () => tween,
40
+ updateAnimator: () => updateAnimator,
41
+ updatePeriodicTween: () => updatePeriodicTween,
42
+ updateSpring: () => updateSpring,
43
+ updateTween: () => updateTween,
44
+ updateTweens: () => updateTweens
45
+ });
46
+ module.exports = __toCommonJS(index_exports);
47
+
48
+ // src/sprite-animator.ts
49
+ function createSpriteAnimator(sheet) {
50
+ return {
51
+ sheet,
52
+ currentAnimation: null,
53
+ frameIndex: 0,
54
+ elapsed: 0,
55
+ paused: false,
56
+ finished: false
57
+ };
58
+ }
59
+ function playAnimation(state, name) {
60
+ const seq = state.sheet.animations.get(name);
61
+ if (!seq) return;
62
+ state.currentAnimation = name;
63
+ state.frameIndex = 0;
64
+ state.elapsed = 0;
65
+ state.paused = false;
66
+ state.finished = false;
67
+ }
68
+ function stopAnimation(state) {
69
+ state.currentAnimation = null;
70
+ state.frameIndex = 0;
71
+ state.elapsed = 0;
72
+ state.paused = false;
73
+ state.finished = false;
74
+ }
75
+ function pauseAnimation(state) {
76
+ state.paused = true;
77
+ }
78
+ function resumeAnimation(state) {
79
+ state.paused = false;
80
+ }
81
+ function updateAnimator(state, dt) {
82
+ if (!state.currentAnimation || state.paused || state.finished) {
83
+ return getCurrentFrame(state);
84
+ }
85
+ const seq = state.sheet.animations.get(state.currentAnimation);
86
+ if (!seq || seq.frameIndices.length === 0) return null;
87
+ state.elapsed += dt;
88
+ while (state.elapsed >= seq.frameDuration) {
89
+ state.elapsed -= seq.frameDuration;
90
+ state.frameIndex++;
91
+ if (state.frameIndex >= seq.frameIndices.length) {
92
+ if (seq.loop) {
93
+ state.frameIndex = 0;
94
+ } else {
95
+ state.frameIndex = seq.frameIndices.length - 1;
96
+ state.finished = true;
97
+ state.elapsed = 0;
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ return getCurrentFrame(state);
103
+ }
104
+ function getCurrentFrame(state) {
105
+ if (!state.currentAnimation) return null;
106
+ const seq = state.sheet.animations.get(state.currentAnimation);
107
+ if (!seq || seq.frameIndices.length === 0) return null;
108
+ const globalIdx = seq.frameIndices[state.frameIndex];
109
+ if (globalIdx === void 0) return null;
110
+ return state.sheet.frames[globalIdx] ?? null;
111
+ }
112
+
113
+ // src/tween.ts
114
+ function linearEasing(t) {
115
+ return t;
116
+ }
117
+ function tween(from, to, duration, easing) {
118
+ return {
119
+ from,
120
+ to,
121
+ duration,
122
+ easing: easing ?? linearEasing,
123
+ elapsed: 0,
124
+ value: from,
125
+ done: false,
126
+ onComplete: null,
127
+ next: null
128
+ };
129
+ }
130
+ function updateTween(tw, dt) {
131
+ if (tw.done) return tw.value;
132
+ tw.elapsed += dt;
133
+ if (tw.elapsed >= tw.duration) {
134
+ tw.elapsed = tw.duration;
135
+ tw.value = tw.to;
136
+ tw.done = true;
137
+ tw.onComplete?.();
138
+ return tw.value;
139
+ }
140
+ const t = tw.elapsed / tw.duration;
141
+ tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);
142
+ return tw.value;
143
+ }
144
+ function chainTween(tw, next) {
145
+ tw.next = next;
146
+ return next;
147
+ }
148
+ function resetTween(tw) {
149
+ tw.elapsed = 0;
150
+ tw.value = tw.from;
151
+ tw.done = false;
152
+ }
153
+
154
+ // src/spring.ts
155
+ var REST_THRESHOLD = 1e-3;
156
+ var VELOCITY_THRESHOLD = 1e-3;
157
+ function spring(value, target, config) {
158
+ return {
159
+ value,
160
+ velocity: 0,
161
+ target,
162
+ config: {
163
+ stiffness: config?.stiffness ?? 100,
164
+ damping: config?.damping ?? 10,
165
+ mass: config?.mass ?? 1
166
+ },
167
+ atRest: value === target
168
+ };
169
+ }
170
+ function updateSpring(s, dt) {
171
+ if (s.atRest) return s.value;
172
+ const { stiffness, damping, mass } = s.config;
173
+ const displacement = s.value - s.target;
174
+ const springForce = -stiffness * displacement;
175
+ const dampingForce = -damping * s.velocity;
176
+ const acceleration = (springForce + dampingForce) / mass;
177
+ s.velocity += acceleration * dt;
178
+ s.value += s.velocity * dt;
179
+ if (Math.abs(s.value - s.target) < REST_THRESHOLD && Math.abs(s.velocity) < VELOCITY_THRESHOLD) {
180
+ s.value = s.target;
181
+ s.velocity = 0;
182
+ s.atRest = true;
183
+ }
184
+ return s.value;
185
+ }
186
+ function setSpringTarget(s, target) {
187
+ s.target = target;
188
+ s.atRest = false;
189
+ }
190
+ function resetSpring(s, value) {
191
+ s.value = value;
192
+ s.target = value;
193
+ s.velocity = 0;
194
+ s.atRest = true;
195
+ }
196
+
197
+ // src/tween-manager.ts
198
+ function createTweenManager() {
199
+ return { tweens: [] };
200
+ }
201
+ function addTween(mgr, tw) {
202
+ mgr.tweens.push(tw);
203
+ }
204
+ function updateTweens(mgr, dt) {
205
+ const tweens = mgr.tweens;
206
+ let i = 0;
207
+ while (i < tweens.length) {
208
+ const tw = tweens[i];
209
+ updateTween(tw, dt);
210
+ if (tw.done) {
211
+ if (tw.next) {
212
+ tweens[i] = tw.next;
213
+ i++;
214
+ } else {
215
+ tweens[i] = tweens[tweens.length - 1];
216
+ tweens.pop();
217
+ }
218
+ } else {
219
+ i++;
220
+ }
221
+ }
222
+ }
223
+ function clearTweens(mgr) {
224
+ mgr.tweens.length = 0;
225
+ }
226
+
227
+ // src/periodic.ts
228
+ var import_math = require("@flare-engine/math");
229
+ function periodicTween(from, to, period, easing = import_math.easeInOutSine) {
230
+ if (period <= 0) throw new Error("periodicTween: period must be > 0");
231
+ return { from, to, period, easing, elapsed: 0, value: from };
232
+ }
233
+ function updatePeriodicTween(tw, dt) {
234
+ tw.elapsed = (tw.elapsed + dt) % tw.period;
235
+ const halfPeriod = tw.period * 0.5;
236
+ const halfPhase = tw.elapsed / halfPeriod;
237
+ const t = halfPhase <= 1 ? halfPhase : 2 - halfPhase;
238
+ tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);
239
+ return tw.value;
240
+ }
241
+ function resetPeriodicTween(tw) {
242
+ tw.elapsed = 0;
243
+ tw.value = tw.from;
244
+ }
245
+ // Annotate the CommonJS export names for ESM import in node:
246
+ 0 && (module.exports = {
247
+ addTween,
248
+ chainTween,
249
+ clearTweens,
250
+ createSpriteAnimator,
251
+ createTweenManager,
252
+ getCurrentFrame,
253
+ pauseAnimation,
254
+ periodicTween,
255
+ playAnimation,
256
+ resetPeriodicTween,
257
+ resetSpring,
258
+ resetTween,
259
+ resumeAnimation,
260
+ setSpringTarget,
261
+ spring,
262
+ stopAnimation,
263
+ tween,
264
+ updateAnimator,
265
+ updatePeriodicTween,
266
+ updateSpring,
267
+ updateTween,
268
+ updateTweens
269
+ });
270
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/sprite-animator.ts","../src/tween.ts","../src/spring.ts","../src/tween-manager.ts","../src/periodic.ts"],"sourcesContent":["export {\n type SpriteAnimatorState,\n createSpriteAnimator,\n playAnimation,\n stopAnimation,\n pauseAnimation,\n resumeAnimation,\n updateAnimator,\n getCurrentFrame,\n} from './sprite-animator.js';\n\nexport {\n type Tween,\n tween,\n updateTween,\n chainTween,\n resetTween,\n} from './tween.js';\n\nexport {\n type SpringConfig,\n type Spring,\n spring,\n updateSpring,\n setSpringTarget,\n resetSpring,\n} from './spring.js';\n\nexport {\n type TweenManager,\n createTweenManager,\n addTween,\n updateTweens,\n clearTweens,\n} from './tween-manager.js';\n\nexport {\n type PeriodicTween,\n periodicTween,\n updatePeriodicTween,\n resetPeriodicTween,\n} from './periodic.js';\n","import type { SpriteFrame, SpriteSheet } from '@flare-engine/assets';\n\n/** State of a sprite animator. */\nexport interface SpriteAnimatorState {\n /** The sprite sheet data source. */\n sheet: SpriteSheet;\n /** Current animation name, or null if none. */\n currentAnimation: string | null;\n /** Current frame index within the animation sequence. */\n frameIndex: number;\n /** Accumulated time within current frame (seconds). */\n elapsed: number;\n /** Whether animation is paused. */\n paused: boolean;\n /** Whether the current sequence has finished (non-looping). */\n finished: boolean;\n}\n\n/** Create a sprite animator state bound to a sprite sheet. */\nexport function createSpriteAnimator(sheet: SpriteSheet): SpriteAnimatorState {\n return {\n sheet,\n currentAnimation: null,\n frameIndex: 0,\n elapsed: 0,\n paused: false,\n finished: false,\n };\n}\n\n/** Play a named animation. Resets to frame 0. */\nexport function playAnimation(state: SpriteAnimatorState, name: string): void {\n const seq = state.sheet.animations.get(name);\n if (!seq) return;\n state.currentAnimation = name;\n state.frameIndex = 0;\n state.elapsed = 0;\n state.paused = false;\n state.finished = false;\n}\n\n/** Stop the current animation. */\nexport function stopAnimation(state: SpriteAnimatorState): void {\n state.currentAnimation = null;\n state.frameIndex = 0;\n state.elapsed = 0;\n state.paused = false;\n state.finished = false;\n}\n\n/** Pause the current animation. */\nexport function pauseAnimation(state: SpriteAnimatorState): void {\n state.paused = true;\n}\n\n/** Resume the current animation. */\nexport function resumeAnimation(state: SpriteAnimatorState): void {\n state.paused = false;\n}\n\n/**\n * Tick the animator forward by dt seconds.\n * Returns the current SpriteFrame, or null if no animation is playing.\n */\nexport function updateAnimator(state: SpriteAnimatorState, dt: number): SpriteFrame | null {\n if (!state.currentAnimation || state.paused || state.finished) {\n return getCurrentFrame(state);\n }\n\n const seq = state.sheet.animations.get(state.currentAnimation);\n if (!seq || seq.frameIndices.length === 0) return null;\n\n state.elapsed += dt;\n\n while (state.elapsed >= seq.frameDuration) {\n state.elapsed -= seq.frameDuration;\n state.frameIndex++;\n\n if (state.frameIndex >= seq.frameIndices.length) {\n if (seq.loop) {\n state.frameIndex = 0;\n } else {\n state.frameIndex = seq.frameIndices.length - 1;\n state.finished = true;\n state.elapsed = 0;\n break;\n }\n }\n }\n\n return getCurrentFrame(state);\n}\n\n/** Get the current SpriteFrame without advancing time. */\nexport function getCurrentFrame(state: SpriteAnimatorState): SpriteFrame | null {\n if (!state.currentAnimation) return null;\n const seq = state.sheet.animations.get(state.currentAnimation);\n if (!seq || seq.frameIndices.length === 0) return null;\n const globalIdx = seq.frameIndices[state.frameIndex];\n if (globalIdx === undefined) return null;\n return state.sheet.frames[globalIdx] ?? null;\n}\n","import type { EasingFn } from '@flare-engine/math';\n\n/** Tween state. */\nexport interface Tween {\n /** Start value. */\n from: number;\n /** End value. */\n to: number;\n /** Duration in seconds. */\n duration: number;\n /** Easing function. */\n easing: EasingFn;\n /** Elapsed time in seconds. */\n elapsed: number;\n /** Current interpolated value. */\n value: number;\n /** Whether the tween is complete. */\n done: boolean;\n /** Optional callback when tween completes. */\n onComplete: (() => void) | null;\n /** Chained tween to start after this one completes. */\n next: Tween | null;\n}\n\n/** Linear easing fallback. */\nfunction linearEasing(t: number): number {\n return t;\n}\n\n/** Create a tween. */\nexport function tween(from: number, to: number, duration: number, easing?: EasingFn): Tween {\n return {\n from,\n to,\n duration,\n easing: easing ?? linearEasing,\n elapsed: 0,\n value: from,\n done: false,\n onComplete: null,\n next: null,\n };\n}\n\n/**\n * Update a tween by dt seconds. Returns the current value.\n * When complete, triggers onComplete callback and advances to chained tween.\n */\nexport function updateTween(tw: Tween, dt: number): number {\n if (tw.done) return tw.value;\n\n tw.elapsed += dt;\n\n if (tw.elapsed >= tw.duration) {\n tw.elapsed = tw.duration;\n tw.value = tw.to;\n tw.done = true;\n tw.onComplete?.();\n return tw.value;\n }\n\n const t = tw.elapsed / tw.duration;\n tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);\n return tw.value;\n}\n\n/** Chain another tween to run after this one completes. Returns the chained tween. */\nexport function chainTween(tw: Tween, next: Tween): Tween {\n tw.next = next;\n return next;\n}\n\n/** Reset a tween to its initial state. */\nexport function resetTween(tw: Tween): void {\n tw.elapsed = 0;\n tw.value = tw.from;\n tw.done = false;\n}\n","/** Spring configuration. */\nexport interface SpringConfig {\n /** Spring stiffness (higher = faster oscillation). Default: 100. */\n stiffness: number;\n /** Damping coefficient (higher = less oscillation). Default: 10. */\n damping: number;\n /** Mass of the spring body. Default: 1. */\n mass: number;\n}\n\n/** Spring state. */\nexport interface Spring {\n /** Current value. */\n value: number;\n /** Current velocity. */\n velocity: number;\n /** Target value. */\n target: number;\n /** Configuration. */\n config: SpringConfig;\n /** Whether the spring has settled (within rest threshold). */\n atRest: boolean;\n}\n\nconst REST_THRESHOLD = 0.001;\nconst VELOCITY_THRESHOLD = 0.001;\n\n/** Create a spring with initial value. */\nexport function spring(value: number, target: number, config?: Partial<SpringConfig>): Spring {\n return {\n value,\n velocity: 0,\n target,\n config: {\n stiffness: config?.stiffness ?? 100,\n damping: config?.damping ?? 10,\n mass: config?.mass ?? 1,\n },\n atRest: value === target,\n };\n}\n\n/**\n * Update a spring by dt seconds. Returns the current value.\n * Uses semi-implicit Euler integration for stability.\n */\nexport function updateSpring(s: Spring, dt: number): number {\n if (s.atRest) return s.value;\n\n const { stiffness, damping, mass } = s.config;\n const displacement = s.value - s.target;\n const springForce = -stiffness * displacement;\n const dampingForce = -damping * s.velocity;\n const acceleration = (springForce + dampingForce) / mass;\n\n // Semi-implicit Euler: update velocity first, then position\n s.velocity += acceleration * dt;\n s.value += s.velocity * dt;\n\n // Check if settled\n if (Math.abs(s.value - s.target) < REST_THRESHOLD && Math.abs(s.velocity) < VELOCITY_THRESHOLD) {\n s.value = s.target;\n s.velocity = 0;\n s.atRest = true;\n }\n\n return s.value;\n}\n\n/** Set a new target for the spring. Wakes it if at rest. */\nexport function setSpringTarget(s: Spring, target: number): void {\n s.target = target;\n s.atRest = false;\n}\n\n/** Reset both value and target, zeroing velocity. */\nexport function resetSpring(s: Spring, value: number): void {\n s.value = value;\n s.target = value;\n s.velocity = 0;\n s.atRest = true;\n}\n","import type { Tween } from './tween.js';\nimport { updateTween } from './tween.js';\n\n/**\n * Manages a collection of active tweens.\n * Automatically removes completed tweens (or advances to chained tweens).\n */\nexport interface TweenManager {\n /** Active tweens. */\n readonly tweens: Tween[];\n}\n\n/** Create a new TweenManager. */\nexport function createTweenManager(): TweenManager {\n return { tweens: [] };\n}\n\n/** Add a tween to the manager. */\nexport function addTween(mgr: TweenManager, tw: Tween): void {\n (mgr.tweens as Tween[]).push(tw);\n}\n\n/**\n * Update all managed tweens by dt seconds.\n * Completed tweens are removed; chained tweens replace completed ones.\n */\nexport function updateTweens(mgr: TweenManager, dt: number): void {\n const tweens = mgr.tweens as Tween[];\n let i = 0;\n while (i < tweens.length) {\n const tw: Tween = tweens[i]!;\n updateTween(tw, dt);\n if (tw.done) {\n if (tw.next) {\n // Replace with chained tween\n tweens[i] = tw.next;\n i++;\n } else {\n // Swap-remove\n tweens[i] = tweens[tweens.length - 1]!;\n tweens.pop();\n }\n } else {\n i++;\n }\n }\n}\n\n/** Remove all tweens. */\nexport function clearTweens(mgr: TweenManager): void {\n (mgr.tweens as Tween[]).length = 0;\n}\n","import { type EasingFn, easeInOutSine } from '@flare-engine/math';\n\n/** Oscillating tween that ping-pongs between `from` and `to` indefinitely. */\nexport interface PeriodicTween {\n /** Start value. */\n readonly from: number;\n /** End value. */\n readonly to: number;\n /** Full cycle period in seconds (from → to → from). */\n readonly period: number;\n /** Easing function (default: easeInOutSine). */\n readonly easing: EasingFn;\n /** Elapsed time in seconds — mutable, advanced by updatePeriodicTween. */\n elapsed: number;\n /** Current interpolated value — written by updatePeriodicTween. */\n value: number;\n}\n\n/**\n * Create a periodic oscillating tween.\n *\n * @param from Start value.\n * @param to End value.\n * @param period Full cycle duration in seconds (must be > 0).\n * @param easing Easing function. Defaults to easeInOutSine.\n */\nexport function periodicTween(\n from: number,\n to: number,\n period: number,\n easing: EasingFn = easeInOutSine,\n): PeriodicTween {\n if (period <= 0) throw new Error('periodicTween: period must be > 0');\n return { from, to, period, easing, elapsed: 0, value: from };\n}\n\n/**\n * Advance a periodic tween by `dt` seconds. Wraps elapsed modulo period,\n * computes ping-pong t, applies easing, writes `value`, returns it.\n */\nexport function updatePeriodicTween(tw: PeriodicTween, dt: number): number {\n tw.elapsed = (tw.elapsed + dt) % tw.period;\n const halfPeriod = tw.period * 0.5;\n // t in [0,1] ping-pong: forward for first half, backward for second half.\n const halfPhase = tw.elapsed / halfPeriod;\n const t = halfPhase <= 1 ? halfPhase : 2 - halfPhase;\n tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);\n return tw.value;\n}\n\n/**\n * Reset a periodic tween: zero elapsed, restore value to `from`.\n */\nexport function resetPeriodicTween(tw: PeriodicTween): void {\n tw.el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IAAI;AACR,SAAO,IAAI,OAAO,QAAQ;AACxB,UAAM,KAAY,OAAO,CAAC;AAC1B,gBAAY,IAAI,EAAE;AAClB,QAAI,GAAG,MAAM;AACX,UAAI,GAAG,MAAM;AAEX,eAAO,CAAC,IAAI,GAAG;AACf;AAAA,MACF,OAAO;AAEL,eAAO,CAAC,IAAI,OAAO,OAAO,SAAS,CAAC;AACpC,eAAO,IAAI;AAAA,MACb;AAAA,IACF,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,YAAY,KAAyB;AACnD,EAAC,IAAI,OAAmB,SAAS;AACnC;;;ACnDA,kBAA6C;AA0BtC,SAAS,cACd,MACA,IACA,QACA,SAAmB,2BACJ;AACf,MAAI,UAAU,EAAG,OAAM,IAAI,MAAM,mCAAmC;AACpE,SAAO,EAAE,MAAM,IAAI,QAAQ,QAAQ,SAAS,GAAG,OAAO,KAAK;AAC7D;AAMO,SAAS,oBAAoB,IAAmB,IAAoB;AACzE,KAAG,WAAW,GAAG,UAAU,MAAM,GAAG;AACpC,QAAM,aAAa,GAAG,SAAS;AAE/B,QAAM,YAAY,GAAG,UAAU;AAC/B,QAAM,IAAI,aAAa,IAAI,YAAY,IAAI;AAC3C,KAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AACpD,SAAO,GAAG;AACZ;AAKO,SAAS,mBAAmB,IAAyB;AAC1D,KAAG,UAAU;AACb,KAAG,QAAQ,GAAG;AAChB;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,222 @@
1
+ // src/sprite-animator.ts
2
+ function createSpriteAnimator(sheet) {
3
+ return {
4
+ sheet,
5
+ currentAnimation: null,
6
+ frameIndex: 0,
7
+ elapsed: 0,
8
+ paused: false,
9
+ finished: false
10
+ };
11
+ }
12
+ function playAnimation(state, name) {
13
+ const seq = state.sheet.animations.get(name);
14
+ if (!seq) return;
15
+ state.currentAnimation = name;
16
+ state.frameIndex = 0;
17
+ state.elapsed = 0;
18
+ state.paused = false;
19
+ state.finished = false;
20
+ }
21
+ function stopAnimation(state) {
22
+ state.currentAnimation = null;
23
+ state.frameIndex = 0;
24
+ state.elapsed = 0;
25
+ state.paused = false;
26
+ state.finished = false;
27
+ }
28
+ function pauseAnimation(state) {
29
+ state.paused = true;
30
+ }
31
+ function resumeAnimation(state) {
32
+ state.paused = false;
33
+ }
34
+ function updateAnimator(state, dt) {
35
+ if (!state.currentAnimation || state.paused || state.finished) {
36
+ return getCurrentFrame(state);
37
+ }
38
+ const seq = state.sheet.animations.get(state.currentAnimation);
39
+ if (!seq || seq.frameIndices.length === 0) return null;
40
+ state.elapsed += dt;
41
+ while (state.elapsed >= seq.frameDuration) {
42
+ state.elapsed -= seq.frameDuration;
43
+ state.frameIndex++;
44
+ if (state.frameIndex >= seq.frameIndices.length) {
45
+ if (seq.loop) {
46
+ state.frameIndex = 0;
47
+ } else {
48
+ state.frameIndex = seq.frameIndices.length - 1;
49
+ state.finished = true;
50
+ state.elapsed = 0;
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ return getCurrentFrame(state);
56
+ }
57
+ function getCurrentFrame(state) {
58
+ if (!state.currentAnimation) return null;
59
+ const seq = state.sheet.animations.get(state.currentAnimation);
60
+ if (!seq || seq.frameIndices.length === 0) return null;
61
+ const globalIdx = seq.frameIndices[state.frameIndex];
62
+ if (globalIdx === void 0) return null;
63
+ return state.sheet.frames[globalIdx] ?? null;
64
+ }
65
+
66
+ // src/tween.ts
67
+ function linearEasing(t) {
68
+ return t;
69
+ }
70
+ function tween(from, to, duration, easing) {
71
+ return {
72
+ from,
73
+ to,
74
+ duration,
75
+ easing: easing ?? linearEasing,
76
+ elapsed: 0,
77
+ value: from,
78
+ done: false,
79
+ onComplete: null,
80
+ next: null
81
+ };
82
+ }
83
+ function updateTween(tw, dt) {
84
+ if (tw.done) return tw.value;
85
+ tw.elapsed += dt;
86
+ if (tw.elapsed >= tw.duration) {
87
+ tw.elapsed = tw.duration;
88
+ tw.value = tw.to;
89
+ tw.done = true;
90
+ tw.onComplete?.();
91
+ return tw.value;
92
+ }
93
+ const t = tw.elapsed / tw.duration;
94
+ tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);
95
+ return tw.value;
96
+ }
97
+ function chainTween(tw, next) {
98
+ tw.next = next;
99
+ return next;
100
+ }
101
+ function resetTween(tw) {
102
+ tw.elapsed = 0;
103
+ tw.value = tw.from;
104
+ tw.done = false;
105
+ }
106
+
107
+ // src/spring.ts
108
+ var REST_THRESHOLD = 1e-3;
109
+ var VELOCITY_THRESHOLD = 1e-3;
110
+ function spring(value, target, config) {
111
+ return {
112
+ value,
113
+ velocity: 0,
114
+ target,
115
+ config: {
116
+ stiffness: config?.stiffness ?? 100,
117
+ damping: config?.damping ?? 10,
118
+ mass: config?.mass ?? 1
119
+ },
120
+ atRest: value === target
121
+ };
122
+ }
123
+ function updateSpring(s, dt) {
124
+ if (s.atRest) return s.value;
125
+ const { stiffness, damping, mass } = s.config;
126
+ const displacement = s.value - s.target;
127
+ const springForce = -stiffness * displacement;
128
+ const dampingForce = -damping * s.velocity;
129
+ const acceleration = (springForce + dampingForce) / mass;
130
+ s.velocity += acceleration * dt;
131
+ s.value += s.velocity * dt;
132
+ if (Math.abs(s.value - s.target) < REST_THRESHOLD && Math.abs(s.velocity) < VELOCITY_THRESHOLD) {
133
+ s.value = s.target;
134
+ s.velocity = 0;
135
+ s.atRest = true;
136
+ }
137
+ return s.value;
138
+ }
139
+ function setSpringTarget(s, target) {
140
+ s.target = target;
141
+ s.atRest = false;
142
+ }
143
+ function resetSpring(s, value) {
144
+ s.value = value;
145
+ s.target = value;
146
+ s.velocity = 0;
147
+ s.atRest = true;
148
+ }
149
+
150
+ // src/tween-manager.ts
151
+ function createTweenManager() {
152
+ return { tweens: [] };
153
+ }
154
+ function addTween(mgr, tw) {
155
+ mgr.tweens.push(tw);
156
+ }
157
+ function updateTweens(mgr, dt) {
158
+ const tweens = mgr.tweens;
159
+ let i = 0;
160
+ while (i < tweens.length) {
161
+ const tw = tweens[i];
162
+ updateTween(tw, dt);
163
+ if (tw.done) {
164
+ if (tw.next) {
165
+ tweens[i] = tw.next;
166
+ i++;
167
+ } else {
168
+ tweens[i] = tweens[tweens.length - 1];
169
+ tweens.pop();
170
+ }
171
+ } else {
172
+ i++;
173
+ }
174
+ }
175
+ }
176
+ function clearTweens(mgr) {
177
+ mgr.tweens.length = 0;
178
+ }
179
+
180
+ // src/periodic.ts
181
+ import { easeInOutSine } from "@flare-engine/math";
182
+ function periodicTween(from, to, period, easing = easeInOutSine) {
183
+ if (period <= 0) throw new Error("periodicTween: period must be > 0");
184
+ return { from, to, period, easing, elapsed: 0, value: from };
185
+ }
186
+ function updatePeriodicTween(tw, dt) {
187
+ tw.elapsed = (tw.elapsed + dt) % tw.period;
188
+ const halfPeriod = tw.period * 0.5;
189
+ const halfPhase = tw.elapsed / halfPeriod;
190
+ const t = halfPhase <= 1 ? halfPhase : 2 - halfPhase;
191
+ tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);
192
+ return tw.value;
193
+ }
194
+ function resetPeriodicTween(tw) {
195
+ tw.elapsed = 0;
196
+ tw.value = tw.from;
197
+ }
198
+ export {
199
+ addTween,
200
+ chainTween,
201
+ clearTweens,
202
+ createSpriteAnimator,
203
+ createTweenManager,
204
+ getCurrentFrame,
205
+ pauseAnimation,
206
+ periodicTween,
207
+ playAnimation,
208
+ resetPeriodicTween,
209
+ resetSpring,
210
+ resetTween,
211
+ resumeAnimation,
212
+ setSpringTarget,
213
+ spring,
214
+ stopAnimation,
215
+ tween,
216
+ updateAnimator,
217
+ updatePeriodicTween,
218
+ updateSpring,
219
+ updateTween,
220
+ updateTweens
221
+ };
222
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sprite-animator.ts","../src/tween.ts","../src/spring.ts","../src/tween-manager.ts","../src/periodic.ts"],"sourcesContent":["import type { SpriteFrame, SpriteSheet } from '@flare-engine/assets';\n\n/** State of a sprite animator. */\nexport interface SpriteAnimatorState {\n /** The sprite sheet data source. */\n sheet: SpriteSheet;\n /** Current animation name, or null if none. */\n currentAnimation: string | null;\n /** Current frame index within the animation sequence. */\n frameIndex: number;\n /** Accumulated time within current frame (seconds). */\n elapsed: number;\n /** Whether animation is paused. */\n paused: boolean;\n /** Whether the current sequence has finished (non-looping). */\n finished: boolean;\n}\n\n/** Create a sprite animator state bound to a sprite sheet. */\nexport function createSpriteAnimator(sheet: SpriteSheet): SpriteAnimatorState {\n return {\n sheet,\n currentAnimation: null,\n frameIndex: 0,\n elapsed: 0,\n paused: false,\n finished: false,\n };\n}\n\n/** Play a named animation. Resets to frame 0. */\nexport function playAnimation(state: SpriteAnimatorState, name: string): void {\n const seq = state.sheet.animations.get(name);\n if (!seq) return;\n state.currentAnimation = name;\n state.frameIndex = 0;\n state.elapsed = 0;\n state.paused = false;\n state.finished = false;\n}\n\n/** Stop the current animation. */\nexport function stopAnimation(state: SpriteAnimatorState): void {\n state.currentAnimation = null;\n state.frameIndex = 0;\n state.elapsed = 0;\n state.paused = false;\n state.finished = false;\n}\n\n/** Pause the current animation. */\nexport function pauseAnimation(state: SpriteAnimatorState): void {\n state.paused = true;\n}\n\n/** Resume the current animation. */\nexport function resumeAnimation(state: SpriteAnimatorState): void {\n state.paused = false;\n}\n\n/**\n * Tick the animator forward by dt seconds.\n * Returns the current SpriteFrame, or null if no animation is playing.\n */\nexport function updateAnimator(state: SpriteAnimatorState, dt: number): SpriteFrame | null {\n if (!state.currentAnimation || state.paused || state.finished) {\n return getCurrentFrame(state);\n }\n\n const seq = state.sheet.animations.get(state.currentAnimation);\n if (!seq || seq.frameIndices.length === 0) return null;\n\n state.elapsed += dt;\n\n while (state.elapsed >= seq.frameDuration) {\n state.elapsed -= seq.frameDuration;\n state.frameIndex++;\n\n if (state.frameIndex >= seq.frameIndices.length) {\n if (seq.loop) {\n state.frameIndex = 0;\n } else {\n state.frameIndex = seq.frameIndices.length - 1;\n state.finished = true;\n state.elapsed = 0;\n break;\n }\n }\n }\n\n return getCurrentFrame(state);\n}\n\n/** Get the current SpriteFrame without advancing time. */\nexport function getCurrentFrame(state: SpriteAnimatorState): SpriteFrame | null {\n if (!state.currentAnimation) return null;\n const seq = state.sheet.animations.get(state.currentAnimation);\n if (!seq || seq.frameIndices.length === 0) return null;\n const globalIdx = seq.frameIndices[state.frameIndex];\n if (globalIdx === undefined) return null;\n return state.sheet.frames[globalIdx] ?? null;\n}\n","import type { EasingFn } from '@flare-engine/math';\n\n/** Tween state. */\nexport interface Tween {\n /** Start value. */\n from: number;\n /** End value. */\n to: number;\n /** Duration in seconds. */\n duration: number;\n /** Easing function. */\n easing: EasingFn;\n /** Elapsed time in seconds. */\n elapsed: number;\n /** Current interpolated value. */\n value: number;\n /** Whether the tween is complete. */\n done: boolean;\n /** Optional callback when tween completes. */\n onComplete: (() => void) | null;\n /** Chained tween to start after this one completes. */\n next: Tween | null;\n}\n\n/** Linear easing fallback. */\nfunction linearEasing(t: number): number {\n return t;\n}\n\n/** Create a tween. */\nexport function tween(from: number, to: number, duration: number, easing?: EasingFn): Tween {\n return {\n from,\n to,\n duration,\n easing: easing ?? linearEasing,\n elapsed: 0,\n value: from,\n done: false,\n onComplete: null,\n next: null,\n };\n}\n\n/**\n * Update a tween by dt seconds. Returns the current value.\n * When complete, triggers onComplete callback and advances to chained tween.\n */\nexport function updateTween(tw: Tween, dt: number): number {\n if (tw.done) return tw.value;\n\n tw.elapsed += dt;\n\n if (tw.elapsed >= tw.duration) {\n tw.elapsed = tw.duration;\n tw.value = tw.to;\n tw.done = true;\n tw.onComplete?.();\n return tw.value;\n }\n\n const t = tw.elapsed / tw.duration;\n tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);\n return tw.value;\n}\n\n/** Chain another tween to run after this one completes. Returns the chained tween. */\nexport function chainTween(tw: Tween, next: Tween): Tween {\n tw.next = next;\n return next;\n}\n\n/** Reset a tween to its initial state. */\nexport function resetTween(tw: Tween): void {\n tw.elapsed = 0;\n tw.value = tw.from;\n tw.done = false;\n}\n","/** Spring configuration. */\nexport interface SpringConfig {\n /** Spring stiffness (higher = faster oscillation). Default: 100. */\n stiffness: number;\n /** Damping coefficient (higher = less oscillation). Default: 10. */\n damping: number;\n /** Mass of the spring body. Default: 1. */\n mass: number;\n}\n\n/** Spring state. */\nexport interface Spring {\n /** Current value. */\n value: number;\n /** Current velocity. */\n velocity: number;\n /** Target value. */\n target: number;\n /** Configuration. */\n config: SpringConfig;\n /** Whether the spring has settled (within rest threshold). */\n atRest: boolean;\n}\n\nconst REST_THRESHOLD = 0.001;\nconst VELOCITY_THRESHOLD = 0.001;\n\n/** Create a spring with initial value. */\nexport function spring(value: number, target: number, config?: Partial<SpringConfig>): Spring {\n return {\n value,\n velocity: 0,\n target,\n config: {\n stiffness: config?.stiffness ?? 100,\n damping: config?.damping ?? 10,\n mass: config?.mass ?? 1,\n },\n atRest: value === target,\n };\n}\n\n/**\n * Update a spring by dt seconds. Returns the current value.\n * Uses semi-implicit Euler integration for stability.\n */\nexport function updateSpring(s: Spring, dt: number): number {\n if (s.atRest) return s.value;\n\n const { stiffness, damping, mass } = s.config;\n const displacement = s.value - s.target;\n const springForce = -stiffness * displacement;\n const dampingForce = -damping * s.velocity;\n const acceleration = (springForce + dampingForce) / mass;\n\n // Semi-implicit Euler: update velocity first, then position\n s.velocity += acceleration * dt;\n s.value += s.velocity * dt;\n\n // Check if settled\n if (Math.abs(s.value - s.target) < REST_THRESHOLD && Math.abs(s.velocity) < VELOCITY_THRESHOLD) {\n s.value = s.target;\n s.velocity = 0;\n s.atRest = true;\n }\n\n return s.value;\n}\n\n/** Set a new target for the spring. Wakes it if at rest. */\nexport function setSpringTarget(s: Spring, target: number): void {\n s.target = target;\n s.atRest = false;\n}\n\n/** Reset both value and target, zeroing velocity. */\nexport function resetSpring(s: Spring, value: number): void {\n s.value = value;\n s.target = value;\n s.velocity = 0;\n s.atRest = true;\n}\n","import type { Tween } from './tween.js';\nimport { updateTween } from './tween.js';\n\n/**\n * Manages a collection of active tweens.\n * Automatically removes completed tweens (or advances to chained tweens).\n */\nexport interface TweenManager {\n /** Active tweens. */\n readonly tweens: Tween[];\n}\n\n/** Create a new TweenManager. */\nexport function createTweenManager(): TweenManager {\n return { tweens: [] };\n}\n\n/** Add a tween to the manager. */\nexport function addTween(mgr: TweenManager, tw: Tween): void {\n (mgr.tweens as Tween[]).push(tw);\n}\n\n/**\n * Update all managed tweens by dt seconds.\n * Completed tweens are removed; chained tweens replace completed ones.\n */\nexport function updateTweens(mgr: TweenManager, dt: number): void {\n const tweens = mgr.tweens as Tween[];\n let i = 0;\n while (i < tweens.length) {\n const tw: Tween = tweens[i]!;\n updateTween(tw, dt);\n if (tw.done) {\n if (tw.next) {\n // Replace with chained tween\n tweens[i] = tw.next;\n i++;\n } else {\n // Swap-remove\n tweens[i] = tweens[tweens.length - 1]!;\n tweens.pop();\n }\n } else {\n i++;\n }\n }\n}\n\n/** Remove all tweens. */\nexport function clearTweens(mgr: TweenManager): void {\n (mgr.tweens as Tween[]).length = 0;\n}\n","import { type EasingFn, easeInOutSine } from '@flare-engine/math';\n\n/** Oscillating tween that ping-pongs between `from` and `to` indefinitely. */\nexport interface PeriodicTween {\n /** Start value. */\n readonly from: number;\n /** End value. */\n readonly to: number;\n /** Full cycle period in seconds (from → to → from). */\n readonly period: number;\n /** Easing function (default: easeInOutSine). */\n readonly easing: EasingFn;\n /** Elapsed time in seconds — mutable, advanced by updatePeriodicTween. */\n elapsed: number;\n /** Current interpolated value — written by updatePeriodicTween. */\n value: number;\n}\n\n/**\n * Create a periodic oscillating tween.\n *\n * @param from Start value.\n * @param to End value.\n * @param period Full cycle duration in seconds (must be > 0).\n * @param easing Easing function. Defaults to easeInOutSine.\n */\nexport function periodicTween(\n from: number,\n to: number,\n period: number,\n easing: EasingFn = easeInOutSine,\n): PeriodicTween {\n if (period <= 0) throw new Error('periodicTween: period must be > 0');\n return { from, to, period, easing, elapsed: 0, value: from };\n}\n\n/**\n * Advance a periodic tween by `dt` seconds. Wraps elapsed modulo period,\n * computes ping-pong t, applies easing, writes `value`, returns it.\n */\nexport function updatePeriodicTween(tw: PeriodicTween, dt: number): number {\n tw.elapsed = (tw.elapsed + dt) % tw.period;\n const halfPeriod = tw.period * 0.5;\n // t in [0,1] ping-pong: forward for first half, backward for second half.\n const halfPhase = tw.elapsed / halfPeriod;\n const t = halfPhase <= 1 ? halfPhase : 2 - halfPhase;\n tw.value = tw.from + (tw.to - tw.from) * tw.easing(t);\n return tw.value;\n}\n\n/**\n * Reset a periodic tween: zero elapsed, restore value to `from`.\n */\nexport function resetPeriodicTween(tw: PeriodicTween): void {\n tw.elapsed = 0;\n tw.value = tw.from;\n}\n"],"mappings":";AAmBO,SAAS,qBAAqB,OAAyC;AAC5E,SAAO;AAAA,IACL;AAAA,IACA,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;AAGO,SAAS,cAAc,OAA4B,MAAoB;AAC5E,QAAM,MAAM,MAAM,MAAM,WAAW,IAAI,IAAI;AAC3C,MAAI,CAAC,IAAK;AACV,QAAM,mBAAmB;AACzB,QAAM,aAAa;AACnB,QAAM,UAAU;AAChB,QAAM,SAAS;AACf,QAAM,WAAW;AACnB;AAGO,SAAS,cAAc,OAAkC;AAC9D,QAAM,mBAAmB;AACzB,QAAM,aAAa;AACnB,QAAM,UAAU;AAChB,QAAM,SAAS;AACf,QAAM,WAAW;AACnB;AAGO,SAAS,eAAe,OAAkC;AAC/D,QAAM,SAAS;AACjB;AAGO,SAAS,gBAAgB,OAAkC;AAChE,QAAM,SAAS;AACjB;AAMO,SAAS,eAAe,OAA4B,IAAgC;AACzF,MAAI,CAAC,MAAM,oBAAoB,MAAM,UAAU,MAAM,UAAU;AAC7D,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAEA,QAAM,MAAM,MAAM,MAAM,WAAW,IAAI,MAAM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 "name": "@flare-engine/animation",
3
+ "version": "0.1.0",
4
+ "description": "Sprite animation, tweens, springs, timeline",
5
+ "keywords": ["flare-engine", "animation", "tween", "spring"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/flare-engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/animation"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@flare-engine/assets": "^0.1.0",
36
+ "@flare-engine/math": "^0.1.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "restricted",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "sideEffects": false
43
+ }