@sarmal/core 0.9.10 → 0.12.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.
@@ -42,13 +42,14 @@ interface CurveDef {
42
42
  */
43
43
  skeletonFn?: (t: number) => Point;
44
44
  }
45
- type SeekOptions = {
45
+ type JumpOptions = {
46
46
  /**
47
- * Decides whether the sarmal trail should be cleared when `seek` is called
47
+ * When true, clears the trail on jump. When false (default), the trail is left as-is.
48
+ * @default false
48
49
  */
49
50
  clearTrail?: boolean;
50
51
  };
51
- type SeekWithTrailOptions = {
52
+ type SeekOptions = {
52
53
  /**
53
54
  * When true, the trail wraps around the period boundary,
54
55
  * which results in a full trail even near `t=0`
@@ -64,6 +65,66 @@ type SeekWithTrailOptions = {
64
65
  step?: number;
65
66
  };
66
67
  type MorpStrategy = "raw" | "normalized";
68
+ /**
69
+ * The shared animation state types
70
+ * Both `Engine` and `SarmalInstance` extend this
71
+ * In the renderer, these are passthroughs
72
+ */
73
+ interface AnimationControls {
74
+ /**
75
+ * Resets the simulation state, clearing the trail and reverting internal time `t` to 0
76
+ * The next call to `tick` will start fresh from the beginning of the curve
77
+ */
78
+ reset(): void;
79
+ /**
80
+ * Instantly moves the head to position `t`.
81
+ *
82
+ * ! Does NOT update `actualTime`.
83
+ *
84
+ * Trail is left untouched by default. You can pass `clearTrail: true` to wipe it.
85
+ * Use for morphing mid-flight or any time you don't need trail context.
86
+ * @param t The position to jump to (will be wrapped into [0, period))
87
+ */
88
+ jump(t: number, options?: JumpOptions): void;
89
+ /**
90
+ * Moves to `t` AND reconstructs the trail as if the animation naturally arrived there from `t=0`
91
+ * Also updates `actualTime` to match. Trail is always rebuilt from scratch
92
+ * Use for initialisation or any jump where you want the trail to look meaningful
93
+ * @param t The position to seek to (will be wrapped into [0, period))
94
+ */
95
+ seek(t: number, options?: SeekOptions): void;
96
+ /**
97
+ * Overrides the animation speed at runtime
98
+ * `0` freezes `t` but the loop keeps running
99
+ * Negative values reverse traversal.
100
+ *
101
+ * ! Does NOT affect a curve's inherent speed given in CurveDef
102
+ * @param speed 0 = freeze, negative = reverse, no upper bound
103
+ */
104
+ setSpeed(speed: number): void;
105
+ /**
106
+ * Returns the *effective speed* the engine is currently using:
107
+ * `userSpeedOverride` if set, otherwise the curve's default speed.
108
+ * This is what `tick()` actually uses
109
+ */
110
+ getSpeed(): number;
111
+ /**
112
+ * Drops the speed override and defers back to the curve's inherent default speed.
113
+ * ! Sets `userSpeedOverride` to `null`
114
+ */
115
+ resetSpeed(): void;
116
+ /**
117
+ * Transitions to the target speed over `duration` milliseconds using linear interpolation.
118
+ * Resolves when the transition completes.
119
+ *
120
+ * Calling this while a transition is already in progress cancels the old transition
121
+ * (rejecting its Promise) and starts a new one from the current interpolated speed.
122
+ *
123
+ * @param speed Target speed
124
+ * @param duration Transition duration in milliseconds (must be > 0)
125
+ */
126
+ setSpeedOver(speed: number, duration: number): Promise<void>;
127
+ }
67
128
  type MorphOptions = {
68
129
  /**
69
130
  * Duration of the morph transition in milliseconds
@@ -78,7 +139,7 @@ type MorphOptions = {
78
139
  */
79
140
  morphStrategy?: MorpStrategy;
80
141
  };
81
- interface Engine {
142
+ interface Engine extends AnimationControls {
82
143
  /**
83
144
  * Advances the Sarmal simulation by the given delta time (dt) in seconds.
84
145
  * Internally, this increases the simulation time `t` by `speed * dt`,
@@ -94,11 +155,6 @@ interface Engine {
94
155
  * ! Use this instead of `trail.length`
95
156
  */
96
157
  readonly trailCount: number;
97
- /**
98
- * Resets the simulation state, by clearing the trail and reverting internal time `t` to 0.
99
- * The next call to `tick` will start fresh from the beginning of the curve.
100
- */
101
- reset(): void;
102
158
  /**
103
159
  * Returns the *skeleton* of the curve.
104
160
  * In technicality, it just represents the complete traversal of the curve over one full period,
@@ -112,17 +168,6 @@ interface Engine {
112
168
  */
113
169
  getSarmalSkeleton(): Array<Point>;
114
170
  readonly isLiveSkeleton: boolean;
115
- /**
116
- * Sets the simulation time `t` directly to the specified value.
117
- * By default, the trail is preserved
118
- * @param t The time value to seek to (will be wrapped into [0, period))
119
- */
120
- seek(t: number, options?: SeekOptions): void;
121
- /**
122
- * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
123
- * @param t The time value to seek to (will be wrapped into [0, period))
124
- */
125
- seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
126
171
  /**
127
172
  * Begins a smooth transition from the current curve to `target`
128
173
  * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
@@ -151,25 +196,17 @@ interface Engine {
151
196
  * `null` when no morph is in progress
152
197
  */
153
198
  readonly morphAlpha: number | null;
199
+ /**
200
+ * Cancels any in-progress speed transition initiated by `setSpeedOver()`.
201
+ * Called internally by the renderer's `stop()` method.
202
+ */
203
+ cancelSpeedTransition(): void;
154
204
  }
155
- interface SarmalInstance {
205
+ interface SarmalInstance extends AnimationControls {
156
206
  start(): void;
157
207
  stop(): void;
158
- /** Resets the engine and clears the trail */
159
- reset(): void;
160
208
  /** Stops the animation and cleans up resources */
161
209
  destroy(): void;
162
- /**
163
- * Sets the simulation time `t` directly to the specified value.
164
- * By default, the trail is preserved
165
- * @param t The time value to seek to (will be wrapped into [0, period))
166
- */
167
- seek(t: number, options?: SeekOptions): void;
168
- /**
169
- * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
170
- * @param t The time value to seek to (will be wrapped into [0, period))
171
- */
172
- seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
173
210
  /**
174
211
  * Smoothly transitions from the current curve to `target`.
175
212
  * The trail naturally reflects the new curve as new points are added.
@@ -220,4 +257,4 @@ interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
220
257
  trailLength?: number;
221
258
  }
222
259
 
223
- export type { CurveDef as C, Engine as E, PalettePreset as P, RendererOptions as R, SarmalInstance as S, TrailStyle as T, SarmalOptions as a, Point as b, SeekOptions as c, SeekWithTrailOptions as d };
260
+ export type { CurveDef as C, Engine as E, JumpOptions as J, PalettePreset as P, RendererOptions as R, SarmalInstance as S, TrailStyle as T, SarmalOptions as a, Point as b, SeekOptions as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarmal/core",
3
- "version": "0.9.10",
3
+ "version": "0.12.0",
4
4
  "description": "Curve path based loading indicators and their renderer",
5
5
  "keywords": [
6
6
  "animation",