@sarmal/core 0.17.3 → 0.19.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.
Files changed (76) hide show
  1. package/README.md +1 -12
  2. package/dist/auto-init.cjs +124 -92
  3. package/dist/auto-init.cjs.map +1 -1
  4. package/dist/auto-init.js +123 -91
  5. package/dist/auto-init.js.map +1 -1
  6. package/dist/curves/artemis2.cjs +10 -7
  7. package/dist/curves/artemis2.d.cts +1 -1
  8. package/dist/curves/artemis2.d.ts +1 -1
  9. package/dist/curves/artemis2.js +9 -6
  10. package/dist/curves/astroid.cjs +4 -4
  11. package/dist/curves/astroid.d.cts +1 -1
  12. package/dist/curves/astroid.d.ts +1 -1
  13. package/dist/curves/astroid.js +3 -3
  14. package/dist/curves/deltoid.cjs +4 -4
  15. package/dist/curves/deltoid.d.cts +1 -1
  16. package/dist/curves/deltoid.d.ts +1 -1
  17. package/dist/curves/deltoid.js +3 -3
  18. package/dist/curves/epicycloid3.cjs +4 -4
  19. package/dist/curves/epicycloid3.d.cts +1 -1
  20. package/dist/curves/epicycloid3.d.ts +1 -1
  21. package/dist/curves/epicycloid3.js +3 -3
  22. package/dist/curves/epitrochoid7.cjs +5 -5
  23. package/dist/curves/epitrochoid7.d.cts +1 -1
  24. package/dist/curves/epitrochoid7.d.ts +1 -1
  25. package/dist/curves/epitrochoid7.js +4 -4
  26. package/dist/curves/index.cjs +53 -40
  27. package/dist/curves/index.d.cts +29 -29
  28. package/dist/curves/index.d.ts +29 -29
  29. package/dist/curves/index.js +69 -40
  30. package/dist/curves/lame.cjs +6 -5
  31. package/dist/curves/lame.d.cts +1 -1
  32. package/dist/curves/lame.d.ts +1 -1
  33. package/dist/curves/lame.js +5 -4
  34. package/dist/curves/lissajous32.cjs +4 -4
  35. package/dist/curves/lissajous32.d.cts +1 -1
  36. package/dist/curves/lissajous32.d.ts +1 -1
  37. package/dist/curves/lissajous32.js +3 -3
  38. package/dist/curves/lissajous43.cjs +4 -4
  39. package/dist/curves/lissajous43.d.cts +1 -1
  40. package/dist/curves/lissajous43.d.ts +1 -1
  41. package/dist/curves/lissajous43.js +3 -3
  42. package/dist/curves/rose3.cjs +4 -4
  43. package/dist/curves/rose3.d.cts +1 -1
  44. package/dist/curves/rose3.d.ts +1 -1
  45. package/dist/curves/rose3.js +3 -3
  46. package/dist/curves/rose5.cjs +4 -4
  47. package/dist/curves/rose5.d.cts +1 -1
  48. package/dist/curves/rose5.d.ts +1 -1
  49. package/dist/curves/rose5.js +3 -3
  50. package/dist/curves/rose52.cjs +5 -5
  51. package/dist/curves/rose52.d.cts +1 -1
  52. package/dist/curves/rose52.d.ts +1 -1
  53. package/dist/curves/rose52.js +4 -4
  54. package/dist/curves/star.cjs +8 -5
  55. package/dist/curves/star.d.cts +1 -1
  56. package/dist/curves/star.d.ts +1 -1
  57. package/dist/curves/star.js +7 -4
  58. package/dist/curves/star4.cjs +8 -5
  59. package/dist/curves/star4.d.cts +1 -1
  60. package/dist/curves/star4.d.ts +1 -1
  61. package/dist/curves/star4.js +7 -4
  62. package/dist/curves/star7.cjs +8 -5
  63. package/dist/curves/star7.d.cts +1 -1
  64. package/dist/curves/star7.d.ts +1 -1
  65. package/dist/curves/star7.js +7 -4
  66. package/dist/index.cjs +159 -118
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +78 -37
  69. package/dist/index.d.ts +78 -37
  70. package/dist/index.js +177 -118
  71. package/dist/index.js.map +1 -1
  72. package/dist/types-frtEoAq6.d.cts +317 -0
  73. package/dist/types-frtEoAq6.d.ts +317 -0
  74. package/package.json +1 -1
  75. package/dist/types-BL9HhEmk.d.cts +0 -299
  76. package/dist/types-BL9HhEmk.d.ts +0 -299
@@ -0,0 +1,317 @@
1
+ interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ interface CurveDef {
6
+ name: string;
7
+ /**
8
+ * The parametric function that defines the curve shape.
9
+ * @param t Current position along the curve, in [0, period)
10
+ * @param time Elapsed actual time in seconds. It is always increasing, and never resets on period wrap
11
+ * @param params Named parameter overrides. intentional forward-compatible parameter
12
+ */
13
+ fn: (t: number, time: number, params: Record<string, number>) => Point;
14
+ /**
15
+ * @default (Math.PI * 2)
16
+ */
17
+ period?: number;
18
+ /**
19
+ * @default 1
20
+ */
21
+ speed?: number;
22
+ /**
23
+ * To indicate a compatible library version when providing the curve definitions
24
+ * Intended for potential backwards compatibility scenarios and futureproofing
25
+ */
26
+ version?: number;
27
+ /**
28
+ * Skeleton rendering mode:
29
+ * - 'static': Skeleton is computed once at init from `fn(t, 0)` and cached
30
+ * - 'live': Skeleton is recomputed each frame using `fn(t, actualTime)` specifically for curves whose shape drifts *over time*
31
+ * @default "static"
32
+ */
33
+ skeleton?: "static" | "live";
34
+ /**
35
+ * An **override** function for computing a skeleton independent of `fn`
36
+ * If provided, this function is used instead of `fn` to sample the skeleton,
37
+ * and the result is cached just like like 'static' mode
38
+ * @param t The parametric time value from `0` to `period`
39
+ * @returns The point on the skeleton at time `t`
40
+ */
41
+ skeletonFn?: (t: number) => Point;
42
+ }
43
+ type JumpOptions = {
44
+ /**
45
+ * When true, clears the trail on jump. When false (default), the trail is left as-is.
46
+ * @default false
47
+ */
48
+ clearTrail?: boolean;
49
+ };
50
+ type SeekOptions = {
51
+ /**
52
+ * When true, the trail wraps around the period boundary,
53
+ * which results in a full trail even near `t=0`
54
+ * By default, the trail stops at `t=0`, which results in a partial trail near the start
55
+ * @default false
56
+ */
57
+ wrap?: boolean;
58
+ /**
59
+ * Time gap between each trail point (in same units as `t`)
60
+ * Smaller value means a trail that is more dense
61
+ * @default period / trailLength
62
+ */
63
+ step?: number;
64
+ };
65
+ type MorpStrategy = "raw" | "normalized";
66
+ /**
67
+ * The shared animation state types
68
+ * Both `Engine` and `SarmalInstance` extend this
69
+ * In the renderer, these are passthroughs
70
+ */
71
+ interface AnimationControls {
72
+ /**
73
+ * Resets the simulation state, clearing the trail and reverting internal time `t` to 0
74
+ * The next call to `tick` will start fresh from the beginning of the curve
75
+ */
76
+ reset(): void;
77
+ /**
78
+ * Instantly moves the head to position `t`.
79
+ *
80
+ * ! Does NOT update `actualTime`.
81
+ *
82
+ * Trail is left untouched by default. You can pass `clearTrail: true` to wipe it.
83
+ * Use for morphing mid-flight or any time you don't need trail context.
84
+ * @param t The position to jump to (will be wrapped into [0, period))
85
+ */
86
+ jump(t: number, options?: JumpOptions): void;
87
+ /**
88
+ * Moves to `t` AND reconstructs the trail as if the animation naturally arrived there from `t=0`
89
+ * Also updates `actualTime` to match. Trail is always rebuilt from scratch
90
+ * Use for initialisation or any jump where you want the trail to look meaningful
91
+ * @param t The position to seek to (will be wrapped into [0, period))
92
+ */
93
+ seek(t: number, options?: SeekOptions): void;
94
+ /**
95
+ * Overrides the animation speed at runtime
96
+ * `0` freezes `t` but the loop keeps running
97
+ * Negative values reverse traversal.
98
+ *
99
+ * ! Does NOT affect a curve's inherent speed given in CurveDef
100
+ * @param speed 0 = freeze, negative = reverse, no upper bound
101
+ */
102
+ setSpeed(speed: number): void;
103
+ /**
104
+ * Returns the *effective speed* the engine is currently using:
105
+ * `userSpeedOverride` if set, otherwise the curve's default speed.
106
+ * This is what `tick()` actually uses
107
+ */
108
+ getSpeed(): number;
109
+ /**
110
+ * Drops the speed override and defers back to the curve's inherent default speed.
111
+ * ! Sets `userSpeedOverride` to `null`
112
+ */
113
+ resetSpeed(): void;
114
+ /**
115
+ * Transitions to the target speed over `duration` milliseconds using linear interpolation.
116
+ * Resolves when the transition completes.
117
+ *
118
+ * Calling this while a transition is already in progress cancels the old transition
119
+ * (rejecting its Promise) and starts a new one from the current interpolated speed.
120
+ *
121
+ * @param speed Target speed
122
+ * @param duration Transition duration in milliseconds (must be > 0)
123
+ */
124
+ setSpeedOver(speed: number, duration: number): Promise<void>;
125
+ }
126
+ type MorphOptions = {
127
+ /**
128
+ * Duration of the morph transition in milliseconds
129
+ * @default 300
130
+ */
131
+ duration?: number;
132
+ /**
133
+ * Strategy for lerping between curves with different periods:
134
+ * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
135
+ * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
136
+ * @default 'normalized'
137
+ */
138
+ morphStrategy?: MorpStrategy;
139
+ };
140
+ interface Engine extends AnimationControls {
141
+ /**
142
+ * Advances the Sarmal simulation by the given delta time (dt) in seconds.
143
+ * Internally, this increases the simulation time `t` by `speed * dt`,
144
+ * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
145
+ * and appends the new point to the trail.
146
+ * Returns the pre-allocated trail buffer, which has the *same* reference every call
147
+ * ! Do not use `Array.length` to determine size
148
+ * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
149
+ */
150
+ tick(deltaTime: number): Array<Point>;
151
+ /**
152
+ * Number of valid points in the trail buffer returned by the last `tick()` call
153
+ * ! Use this instead of `trail.length`
154
+ */
155
+ readonly trailCount: number;
156
+ /**
157
+ * The maximum capacity of the trail buffer, which is set at engine creation
158
+ * This is the upper bound for `trailCount`
159
+ */
160
+ readonly trailLength: number;
161
+ /**
162
+ * Returns the *skeleton* of the curve.
163
+ * In technicality, it just represents the complete traversal of the curve over one full period,
164
+ * which is sampled at points from `t=0` to `t=period`
165
+ *
166
+ * For "static" skeletons, this returns the same array on every call
167
+ * For "live" skeletons, this returns a different array each frame
168
+ * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
169
+ *
170
+ * The number of sample points is automatically derived from the curve's period.
171
+ */
172
+ getSarmalSkeleton(): Array<Point>;
173
+ readonly isLiveSkeleton: boolean;
174
+ /**
175
+ * Begins a smooth transition from the current curve to `target`
176
+ * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
177
+ *
178
+ * If called while a morph is already in progress,
179
+ * the interpolated state is frozen and becomes the new `curveA`
180
+ * @param target The curve to transition to
181
+ * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
182
+ */
183
+ startMorph(target: CurveDef, strategy?: MorpStrategy): void;
184
+ /**
185
+ * Sets the interpolation amount between `curveA` and `curveB`.
186
+ * 0 = full curveA
187
+ * 1 = full curveB
188
+ * Called by the renderer each frame as `actualTime` advances
189
+ * @param alpha A value in [0, 1]
190
+ */
191
+ setMorphAlpha(alpha: number): void;
192
+ /**
193
+ * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
194
+ * ! Called by the renderer when alpha reaches `1`
195
+ */
196
+ completeMorph(): void;
197
+ /**
198
+ * Current interpolation progress between `curveA` and `curveB`
199
+ * `null` when no morph is in progress
200
+ */
201
+ readonly morphAlpha: number | null;
202
+ /**
203
+ * Cancels any in-progress speed transition initiated by `setSpeedOver()`.
204
+ * Called internally by the renderer's `stop()` method.
205
+ */
206
+ cancelSpeedTransition(): void;
207
+ }
208
+ interface SarmalInstance extends AnimationControls {
209
+ /** Starts the animation loop (requestAnimationFrame). If already running, does nothing. */
210
+ play(): void;
211
+ /** Pauses the animation loop (cancelAnimationFrame) and cancels any speed transition. Preserves state. */
212
+ pause(): void;
213
+ /** Stops the animation and cleans up resources */
214
+ destroy(): void;
215
+ /**
216
+ * Smoothly transitions from the current curve to `target`.
217
+ * The trail naturally reflects the new curve as new points are added.
218
+ * @param target The curve to transition to
219
+ * @param options.duration How long the morph takes in milliseconds (default: 300)
220
+ * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
221
+ * @returns Promise that resolves when the morph is complete
222
+ */
223
+ morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
224
+ /**
225
+ * Changes render options on a live SarmalInstance without destroying and recreating it.
226
+ *
227
+ * ! Validation fails the operation completely if any of the fields fail the chceck.
228
+ */
229
+ setRenderOptions(partial: RuntimeRenderOptions): void;
230
+ }
231
+ /**
232
+ * With 'gradient-animated' the colors cycle along the trail over time
233
+ */
234
+ type TrailStyle = "default" | "gradient-static" | "gradient-animated";
235
+ /**
236
+ * The value must be a single hex string or an array of hex strings.
237
+ *
238
+ * ! Named colors, shorthand hex, `rgb()`, and `hsl()` notations are not yet supported.
239
+ */
240
+ type TrailColor = string | string[];
241
+ /**
242
+ * Runtime-renderable options that can be changed on a live instance without destroying and recreating it.
243
+ *
244
+ * Passing `null` for `headColor`makes the head color derive its color from the current `trailColor` and `trailStyle`
245
+ * Passing a hex string locks the head color until overridden.
246
+ *
247
+ * Passing `"transparent"` for `skeletonColor` hides the skeleton. Any other value must be a valid {@link TrailColor}.
248
+ */
249
+ interface RuntimeRenderOptions {
250
+ trailColor?: TrailColor;
251
+ /** 6-digit hex string to override, or `null` to make it automatic */
252
+ headColor?: string | null;
253
+ /** 6-digit hex string, or `"transparent"` to hide the skeleton. */
254
+ skeletonColor?: string;
255
+ trailStyle?: TrailStyle;
256
+ }
257
+ /**
258
+ * Common renderer options shared between canvas and SVG renderers.
259
+ * Extracted to avoid duplication and ensure consistency.
260
+ */
261
+ interface BaseRendererOptions {
262
+ /**
263
+ * Whether to start the animation loop automatically on creation.
264
+ * @default true
265
+ */
266
+ autoStart?: boolean;
267
+ /**
268
+ * Initial position along the curve (t value). If provided, seek(initialT) is called before the first frame.
269
+ * @default undefined (no seek performed, starts at t=0)
270
+ */
271
+ initialT?: number;
272
+ /**
273
+ * @default '#ffffff'
274
+ */
275
+ skeletonColor?: string;
276
+ /**
277
+ * Single hex color for default trails, or an array of hex colors for gradient trails.
278
+ * @default '#ffffff'
279
+ */
280
+ trailColor?: TrailColor;
281
+ /**
282
+ * Hex color for the head dot.
283
+ * If omitted, the color is derived from the trail
284
+ */
285
+ headColor?: string;
286
+ /** @default 4 */
287
+ headRadius?: number;
288
+ /**
289
+ * Trail rendering style
290
+ * @default 'default'
291
+ */
292
+ trailStyle?: TrailStyle;
293
+ }
294
+ interface RendererOptions extends BaseRendererOptions {
295
+ /** Target canvas element that will contain the Sarmal */
296
+ canvas: HTMLCanvasElement;
297
+ engine: Engine;
298
+ }
299
+ interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
300
+ /** @default 120 */
301
+ trailLength?: number;
302
+ }
303
+
304
+ export type {
305
+ BaseRendererOptions as B,
306
+ CurveDef as C,
307
+ Engine as E,
308
+ JumpOptions as J,
309
+ Point as P,
310
+ RendererOptions as R,
311
+ SarmalInstance as S,
312
+ TrailColor as T,
313
+ SarmalOptions as a,
314
+ RuntimeRenderOptions as b,
315
+ SeekOptions as c,
316
+ TrailStyle as d,
317
+ };
@@ -0,0 +1,317 @@
1
+ interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ interface CurveDef {
6
+ name: string;
7
+ /**
8
+ * The parametric function that defines the curve shape.
9
+ * @param t Current position along the curve, in [0, period)
10
+ * @param time Elapsed actual time in seconds. It is always increasing, and never resets on period wrap
11
+ * @param params Named parameter overrides. intentional forward-compatible parameter
12
+ */
13
+ fn: (t: number, time: number, params: Record<string, number>) => Point;
14
+ /**
15
+ * @default (Math.PI * 2)
16
+ */
17
+ period?: number;
18
+ /**
19
+ * @default 1
20
+ */
21
+ speed?: number;
22
+ /**
23
+ * To indicate a compatible library version when providing the curve definitions
24
+ * Intended for potential backwards compatibility scenarios and futureproofing
25
+ */
26
+ version?: number;
27
+ /**
28
+ * Skeleton rendering mode:
29
+ * - 'static': Skeleton is computed once at init from `fn(t, 0)` and cached
30
+ * - 'live': Skeleton is recomputed each frame using `fn(t, actualTime)` specifically for curves whose shape drifts *over time*
31
+ * @default "static"
32
+ */
33
+ skeleton?: "static" | "live";
34
+ /**
35
+ * An **override** function for computing a skeleton independent of `fn`
36
+ * If provided, this function is used instead of `fn` to sample the skeleton,
37
+ * and the result is cached just like like 'static' mode
38
+ * @param t The parametric time value from `0` to `period`
39
+ * @returns The point on the skeleton at time `t`
40
+ */
41
+ skeletonFn?: (t: number) => Point;
42
+ }
43
+ type JumpOptions = {
44
+ /**
45
+ * When true, clears the trail on jump. When false (default), the trail is left as-is.
46
+ * @default false
47
+ */
48
+ clearTrail?: boolean;
49
+ };
50
+ type SeekOptions = {
51
+ /**
52
+ * When true, the trail wraps around the period boundary,
53
+ * which results in a full trail even near `t=0`
54
+ * By default, the trail stops at `t=0`, which results in a partial trail near the start
55
+ * @default false
56
+ */
57
+ wrap?: boolean;
58
+ /**
59
+ * Time gap between each trail point (in same units as `t`)
60
+ * Smaller value means a trail that is more dense
61
+ * @default period / trailLength
62
+ */
63
+ step?: number;
64
+ };
65
+ type MorpStrategy = "raw" | "normalized";
66
+ /**
67
+ * The shared animation state types
68
+ * Both `Engine` and `SarmalInstance` extend this
69
+ * In the renderer, these are passthroughs
70
+ */
71
+ interface AnimationControls {
72
+ /**
73
+ * Resets the simulation state, clearing the trail and reverting internal time `t` to 0
74
+ * The next call to `tick` will start fresh from the beginning of the curve
75
+ */
76
+ reset(): void;
77
+ /**
78
+ * Instantly moves the head to position `t`.
79
+ *
80
+ * ! Does NOT update `actualTime`.
81
+ *
82
+ * Trail is left untouched by default. You can pass `clearTrail: true` to wipe it.
83
+ * Use for morphing mid-flight or any time you don't need trail context.
84
+ * @param t The position to jump to (will be wrapped into [0, period))
85
+ */
86
+ jump(t: number, options?: JumpOptions): void;
87
+ /**
88
+ * Moves to `t` AND reconstructs the trail as if the animation naturally arrived there from `t=0`
89
+ * Also updates `actualTime` to match. Trail is always rebuilt from scratch
90
+ * Use for initialisation or any jump where you want the trail to look meaningful
91
+ * @param t The position to seek to (will be wrapped into [0, period))
92
+ */
93
+ seek(t: number, options?: SeekOptions): void;
94
+ /**
95
+ * Overrides the animation speed at runtime
96
+ * `0` freezes `t` but the loop keeps running
97
+ * Negative values reverse traversal.
98
+ *
99
+ * ! Does NOT affect a curve's inherent speed given in CurveDef
100
+ * @param speed 0 = freeze, negative = reverse, no upper bound
101
+ */
102
+ setSpeed(speed: number): void;
103
+ /**
104
+ * Returns the *effective speed* the engine is currently using:
105
+ * `userSpeedOverride` if set, otherwise the curve's default speed.
106
+ * This is what `tick()` actually uses
107
+ */
108
+ getSpeed(): number;
109
+ /**
110
+ * Drops the speed override and defers back to the curve's inherent default speed.
111
+ * ! Sets `userSpeedOverride` to `null`
112
+ */
113
+ resetSpeed(): void;
114
+ /**
115
+ * Transitions to the target speed over `duration` milliseconds using linear interpolation.
116
+ * Resolves when the transition completes.
117
+ *
118
+ * Calling this while a transition is already in progress cancels the old transition
119
+ * (rejecting its Promise) and starts a new one from the current interpolated speed.
120
+ *
121
+ * @param speed Target speed
122
+ * @param duration Transition duration in milliseconds (must be > 0)
123
+ */
124
+ setSpeedOver(speed: number, duration: number): Promise<void>;
125
+ }
126
+ type MorphOptions = {
127
+ /**
128
+ * Duration of the morph transition in milliseconds
129
+ * @default 300
130
+ */
131
+ duration?: number;
132
+ /**
133
+ * Strategy for lerping between curves with different periods:
134
+ * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
135
+ * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
136
+ * @default 'normalized'
137
+ */
138
+ morphStrategy?: MorpStrategy;
139
+ };
140
+ interface Engine extends AnimationControls {
141
+ /**
142
+ * Advances the Sarmal simulation by the given delta time (dt) in seconds.
143
+ * Internally, this increases the simulation time `t` by `speed * dt`,
144
+ * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
145
+ * and appends the new point to the trail.
146
+ * Returns the pre-allocated trail buffer, which has the *same* reference every call
147
+ * ! Do not use `Array.length` to determine size
148
+ * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
149
+ */
150
+ tick(deltaTime: number): Array<Point>;
151
+ /**
152
+ * Number of valid points in the trail buffer returned by the last `tick()` call
153
+ * ! Use this instead of `trail.length`
154
+ */
155
+ readonly trailCount: number;
156
+ /**
157
+ * The maximum capacity of the trail buffer, which is set at engine creation
158
+ * This is the upper bound for `trailCount`
159
+ */
160
+ readonly trailLength: number;
161
+ /**
162
+ * Returns the *skeleton* of the curve.
163
+ * In technicality, it just represents the complete traversal of the curve over one full period,
164
+ * which is sampled at points from `t=0` to `t=period`
165
+ *
166
+ * For "static" skeletons, this returns the same array on every call
167
+ * For "live" skeletons, this returns a different array each frame
168
+ * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
169
+ *
170
+ * The number of sample points is automatically derived from the curve's period.
171
+ */
172
+ getSarmalSkeleton(): Array<Point>;
173
+ readonly isLiveSkeleton: boolean;
174
+ /**
175
+ * Begins a smooth transition from the current curve to `target`
176
+ * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
177
+ *
178
+ * If called while a morph is already in progress,
179
+ * the interpolated state is frozen and becomes the new `curveA`
180
+ * @param target The curve to transition to
181
+ * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
182
+ */
183
+ startMorph(target: CurveDef, strategy?: MorpStrategy): void;
184
+ /**
185
+ * Sets the interpolation amount between `curveA` and `curveB`.
186
+ * 0 = full curveA
187
+ * 1 = full curveB
188
+ * Called by the renderer each frame as `actualTime` advances
189
+ * @param alpha A value in [0, 1]
190
+ */
191
+ setMorphAlpha(alpha: number): void;
192
+ /**
193
+ * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
194
+ * ! Called by the renderer when alpha reaches `1`
195
+ */
196
+ completeMorph(): void;
197
+ /**
198
+ * Current interpolation progress between `curveA` and `curveB`
199
+ * `null` when no morph is in progress
200
+ */
201
+ readonly morphAlpha: number | null;
202
+ /**
203
+ * Cancels any in-progress speed transition initiated by `setSpeedOver()`.
204
+ * Called internally by the renderer's `stop()` method.
205
+ */
206
+ cancelSpeedTransition(): void;
207
+ }
208
+ interface SarmalInstance extends AnimationControls {
209
+ /** Starts the animation loop (requestAnimationFrame). If already running, does nothing. */
210
+ play(): void;
211
+ /** Pauses the animation loop (cancelAnimationFrame) and cancels any speed transition. Preserves state. */
212
+ pause(): void;
213
+ /** Stops the animation and cleans up resources */
214
+ destroy(): void;
215
+ /**
216
+ * Smoothly transitions from the current curve to `target`.
217
+ * The trail naturally reflects the new curve as new points are added.
218
+ * @param target The curve to transition to
219
+ * @param options.duration How long the morph takes in milliseconds (default: 300)
220
+ * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
221
+ * @returns Promise that resolves when the morph is complete
222
+ */
223
+ morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
224
+ /**
225
+ * Changes render options on a live SarmalInstance without destroying and recreating it.
226
+ *
227
+ * ! Validation fails the operation completely if any of the fields fail the chceck.
228
+ */
229
+ setRenderOptions(partial: RuntimeRenderOptions): void;
230
+ }
231
+ /**
232
+ * With 'gradient-animated' the colors cycle along the trail over time
233
+ */
234
+ type TrailStyle = "default" | "gradient-static" | "gradient-animated";
235
+ /**
236
+ * The value must be a single hex string or an array of hex strings.
237
+ *
238
+ * ! Named colors, shorthand hex, `rgb()`, and `hsl()` notations are not yet supported.
239
+ */
240
+ type TrailColor = string | string[];
241
+ /**
242
+ * Runtime-renderable options that can be changed on a live instance without destroying and recreating it.
243
+ *
244
+ * Passing `null` for `headColor`makes the head color derive its color from the current `trailColor` and `trailStyle`
245
+ * Passing a hex string locks the head color until overridden.
246
+ *
247
+ * Passing `"transparent"` for `skeletonColor` hides the skeleton. Any other value must be a valid {@link TrailColor}.
248
+ */
249
+ interface RuntimeRenderOptions {
250
+ trailColor?: TrailColor;
251
+ /** 6-digit hex string to override, or `null` to make it automatic */
252
+ headColor?: string | null;
253
+ /** 6-digit hex string, or `"transparent"` to hide the skeleton. */
254
+ skeletonColor?: string;
255
+ trailStyle?: TrailStyle;
256
+ }
257
+ /**
258
+ * Common renderer options shared between canvas and SVG renderers.
259
+ * Extracted to avoid duplication and ensure consistency.
260
+ */
261
+ interface BaseRendererOptions {
262
+ /**
263
+ * Whether to start the animation loop automatically on creation.
264
+ * @default true
265
+ */
266
+ autoStart?: boolean;
267
+ /**
268
+ * Initial position along the curve (t value). If provided, seek(initialT) is called before the first frame.
269
+ * @default undefined (no seek performed, starts at t=0)
270
+ */
271
+ initialT?: number;
272
+ /**
273
+ * @default '#ffffff'
274
+ */
275
+ skeletonColor?: string;
276
+ /**
277
+ * Single hex color for default trails, or an array of hex colors for gradient trails.
278
+ * @default '#ffffff'
279
+ */
280
+ trailColor?: TrailColor;
281
+ /**
282
+ * Hex color for the head dot.
283
+ * If omitted, the color is derived from the trail
284
+ */
285
+ headColor?: string;
286
+ /** @default 4 */
287
+ headRadius?: number;
288
+ /**
289
+ * Trail rendering style
290
+ * @default 'default'
291
+ */
292
+ trailStyle?: TrailStyle;
293
+ }
294
+ interface RendererOptions extends BaseRendererOptions {
295
+ /** Target canvas element that will contain the Sarmal */
296
+ canvas: HTMLCanvasElement;
297
+ engine: Engine;
298
+ }
299
+ interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
300
+ /** @default 120 */
301
+ trailLength?: number;
302
+ }
303
+
304
+ export type {
305
+ BaseRendererOptions as B,
306
+ CurveDef as C,
307
+ Engine as E,
308
+ JumpOptions as J,
309
+ Point as P,
310
+ RendererOptions as R,
311
+ SarmalInstance as S,
312
+ TrailColor as T,
313
+ SarmalOptions as a,
314
+ RuntimeRenderOptions as b,
315
+ SeekOptions as c,
316
+ TrailStyle as d,
317
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarmal/core",
3
- "version": "0.17.3",
3
+ "version": "0.19.0",
4
4
  "description": "Curve path based loading indicators and their renderer",
5
5
  "keywords": [
6
6
  "animation",