@sarmal/core 0.12.0 → 0.13.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 (61) hide show
  1. package/dist/auto-init.cjs +114 -82
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.d.cts +1 -2
  4. package/dist/auto-init.d.ts +1 -2
  5. package/dist/auto-init.js +113 -81
  6. package/dist/auto-init.js.map +1 -1
  7. package/dist/curves/artemis2.cjs +10 -7
  8. package/dist/curves/artemis2.d.cts +1 -1
  9. package/dist/curves/artemis2.d.ts +1 -1
  10. package/dist/curves/artemis2.js +9 -6
  11. package/dist/curves/astroid.cjs +4 -4
  12. package/dist/curves/astroid.d.cts +1 -1
  13. package/dist/curves/astroid.d.ts +1 -1
  14. package/dist/curves/astroid.js +3 -3
  15. package/dist/curves/deltoid.cjs +4 -4
  16. package/dist/curves/deltoid.d.cts +1 -1
  17. package/dist/curves/deltoid.d.ts +1 -1
  18. package/dist/curves/deltoid.js +3 -3
  19. package/dist/curves/epicycloid3.cjs +4 -4
  20. package/dist/curves/epicycloid3.d.cts +1 -1
  21. package/dist/curves/epicycloid3.d.ts +1 -1
  22. package/dist/curves/epicycloid3.js +3 -3
  23. package/dist/curves/epitrochoid7.cjs +5 -5
  24. package/dist/curves/epitrochoid7.d.cts +1 -1
  25. package/dist/curves/epitrochoid7.d.ts +1 -1
  26. package/dist/curves/epitrochoid7.js +4 -4
  27. package/dist/curves/index.cjs +32 -28
  28. package/dist/curves/index.d.cts +21 -21
  29. package/dist/curves/index.d.ts +21 -21
  30. package/dist/curves/index.js +44 -28
  31. package/dist/curves/lame.cjs +6 -5
  32. package/dist/curves/lame.d.cts +1 -1
  33. package/dist/curves/lame.d.ts +1 -1
  34. package/dist/curves/lame.js +5 -4
  35. package/dist/curves/lissajous32.cjs +4 -4
  36. package/dist/curves/lissajous32.d.cts +1 -1
  37. package/dist/curves/lissajous32.d.ts +1 -1
  38. package/dist/curves/lissajous32.js +3 -3
  39. package/dist/curves/lissajous43.cjs +4 -4
  40. package/dist/curves/lissajous43.d.cts +1 -1
  41. package/dist/curves/lissajous43.d.ts +1 -1
  42. package/dist/curves/lissajous43.js +3 -3
  43. package/dist/curves/rose3.cjs +4 -4
  44. package/dist/curves/rose3.d.cts +1 -1
  45. package/dist/curves/rose3.d.ts +1 -1
  46. package/dist/curves/rose3.js +3 -3
  47. package/dist/curves/rose5.cjs +4 -4
  48. package/dist/curves/rose5.d.cts +1 -1
  49. package/dist/curves/rose5.d.ts +1 -1
  50. package/dist/curves/rose5.js +3 -3
  51. package/dist/index.cjs +135 -87
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +69 -34
  54. package/dist/index.d.ts +69 -34
  55. package/dist/index.js +152 -87
  56. package/dist/index.js.map +1 -1
  57. package/dist/types-BW0bpL1Z.d.cts +290 -0
  58. package/dist/types-BW0bpL1Z.d.ts +290 -0
  59. package/package.json +1 -1
  60. package/dist/types-BzgdhxE0.d.cts +0 -260
  61. package/dist/types-BzgdhxE0.d.ts +0 -260
@@ -1,260 +0,0 @@
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 wall-clock time in seconds — always increasing, never resets on period wrap
11
- * @param params Named parameter overrides.
12
- * Always `{}` today — reserved for the upcoming parameterized-curves feature.
13
- * Do NOT remove this parameter; it is intentional forward-compatible plumbing.
14
- */
15
- fn: (t: number, time: number, params: Record<string, number>) => Point;
16
- /**
17
- * @default (Math.PI * 2)
18
- */
19
- period?: number;
20
- /**
21
- * @default 1
22
- */
23
- speed?: number;
24
- /**
25
- * To indicate a compatible library version when providing the curve definitions
26
- * Intended for potential backwards compatibility scenarios and futureproofing
27
- */
28
- version?: number;
29
- /**
30
- * Skeleton rendering mode:
31
- * - 'static': Skeleton is computed once at init from `fn(t, 0)` and cached
32
- * - 'live': Skeleton is recomputed each frame using `fn(t, actualTime)` specifically for curves whose shape drifts *over time*
33
- * @default "static"
34
- */
35
- skeleton?: "static" | "live";
36
- /**
37
- * An **override** function for computing a skeleton independent of `fn`
38
- * If provided, this function is used instead of `fn` to sample the skeleton,
39
- * and the result is cached just like like 'static' mode
40
- * @param t The parametric time value from `0` to `period`
41
- * @returns The point on the skeleton at time `t`
42
- */
43
- skeletonFn?: (t: number) => Point;
44
- }
45
- type JumpOptions = {
46
- /**
47
- * When true, clears the trail on jump. When false (default), the trail is left as-is.
48
- * @default false
49
- */
50
- clearTrail?: boolean;
51
- };
52
- type SeekOptions = {
53
- /**
54
- * When true, the trail wraps around the period boundary,
55
- * which results in a full trail even near `t=0`
56
- * By default, the trail stops at `t=0`, which results in a partial trail near the start
57
- * @default false
58
- */
59
- wrap?: boolean;
60
- /**
61
- * Time gap between each trail point (in same units as `t`)
62
- * Smaller value means a trail that is more dense
63
- * @default period / trailLength
64
- */
65
- step?: number;
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
- }
128
- type MorphOptions = {
129
- /**
130
- * Duration of the morph transition in milliseconds
131
- * @default 300
132
- */
133
- duration?: number;
134
- /**
135
- * Strategy for lerping between curves with different periods:
136
- * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
137
- * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
138
- * @default 'normalized'
139
- */
140
- morphStrategy?: MorpStrategy;
141
- };
142
- interface Engine extends AnimationControls {
143
- /**
144
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
145
- * Internally, this increases the simulation time `t` by `speed * dt`,
146
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
147
- * and appends the new point to the trail.
148
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
149
- * ! Do not use `Array.length` to determine size
150
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
151
- */
152
- tick(deltaTime: number): Array<Point>;
153
- /**
154
- * Number of valid points in the trail buffer returned by the last `tick()` call
155
- * ! Use this instead of `trail.length`
156
- */
157
- readonly trailCount: number;
158
- /**
159
- * Returns the *skeleton* of the curve.
160
- * In technicality, it just represents the complete traversal of the curve over one full period,
161
- * which is sampled at points from `t=0` to `t=period`
162
- *
163
- * For "static" skeletons, this returns the same array on every call
164
- * For "live" skeletons, this returns a different array each frame
165
- * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
166
- *
167
- * The number of sample points is automatically derived from the curve's period.
168
- */
169
- getSarmalSkeleton(): Array<Point>;
170
- readonly isLiveSkeleton: boolean;
171
- /**
172
- * Begins a smooth transition from the current curve to `target`
173
- * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
174
- *
175
- * If called while a morph is already in progress,
176
- * the interpolated state is frozen and becomes the new `curveA`
177
- * @param target The curve to transition to
178
- * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
179
- */
180
- startMorph(target: CurveDef, strategy?: MorpStrategy): void;
181
- /**
182
- * Sets the interpolation amount between `curveA` and `curveB`.
183
- * 0 = full curveA
184
- * 1 = full curveB
185
- * Called by the renderer each frame as `actualTime` advances
186
- * @param alpha A value in [0, 1]
187
- */
188
- setMorphAlpha(alpha: number): void;
189
- /**
190
- * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
191
- * ! Called by the renderer when alpha reaches `1`
192
- */
193
- completeMorph(): void;
194
- /**
195
- * Current interpolation progress between `curveA` and `curveB`
196
- * `null` when no morph is in progress
197
- */
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;
204
- }
205
- interface SarmalInstance extends AnimationControls {
206
- start(): void;
207
- stop(): void;
208
- /** Stops the animation and cleans up resources */
209
- destroy(): void;
210
- /**
211
- * Smoothly transitions from the current curve to `target`.
212
- * The trail naturally reflects the new curve as new points are added.
213
- * @param target The curve to transition to
214
- * @param options.duration How long the morph takes in milliseconds (default: 300)
215
- * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
216
- * @returns Promise that resolves when the morph is complete
217
- */
218
- morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
219
- }
220
- /**
221
- * With 'gradient-animated' the colors cycle along the trail over time
222
- */
223
- type TrailStyle = "default" | "gradient-static" | "gradient-animated";
224
- type PalettePreset = "bard" | "sunset" | "ocean" | "ice" | "fire" | "forest";
225
- interface RendererOptions {
226
- /** Target canvas element that will contain the Sarmal */
227
- canvas: HTMLCanvasElement;
228
- engine: Engine;
229
- /**
230
- * @default '#ffffff'
231
- */
232
- skeletonColor?: string;
233
- /**
234
- * @default '#ffffff'
235
- */
236
- trailColor?: string;
237
- /**
238
- * @default '#ffffff'
239
- */
240
- headColor?: string;
241
- /** @default 4 */
242
- headRadius?: number;
243
- /**
244
- * Trail rendering style
245
- * @default 'default'
246
- */
247
- trailStyle?: TrailStyle;
248
- /**
249
- * Color palette for gradient trails
250
- * Can be a preset name or custom array of hex colors.
251
- * @default 'bard' for animated, 'ice' for static
252
- */
253
- palette?: PalettePreset | string[];
254
- }
255
- interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
256
- /** @default 120 */
257
- trailLength?: number;
258
- }
259
-
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 };
@@ -1,260 +0,0 @@
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 wall-clock time in seconds — always increasing, never resets on period wrap
11
- * @param params Named parameter overrides.
12
- * Always `{}` today — reserved for the upcoming parameterized-curves feature.
13
- * Do NOT remove this parameter; it is intentional forward-compatible plumbing.
14
- */
15
- fn: (t: number, time: number, params: Record<string, number>) => Point;
16
- /**
17
- * @default (Math.PI * 2)
18
- */
19
- period?: number;
20
- /**
21
- * @default 1
22
- */
23
- speed?: number;
24
- /**
25
- * To indicate a compatible library version when providing the curve definitions
26
- * Intended for potential backwards compatibility scenarios and futureproofing
27
- */
28
- version?: number;
29
- /**
30
- * Skeleton rendering mode:
31
- * - 'static': Skeleton is computed once at init from `fn(t, 0)` and cached
32
- * - 'live': Skeleton is recomputed each frame using `fn(t, actualTime)` specifically for curves whose shape drifts *over time*
33
- * @default "static"
34
- */
35
- skeleton?: "static" | "live";
36
- /**
37
- * An **override** function for computing a skeleton independent of `fn`
38
- * If provided, this function is used instead of `fn` to sample the skeleton,
39
- * and the result is cached just like like 'static' mode
40
- * @param t The parametric time value from `0` to `period`
41
- * @returns The point on the skeleton at time `t`
42
- */
43
- skeletonFn?: (t: number) => Point;
44
- }
45
- type JumpOptions = {
46
- /**
47
- * When true, clears the trail on jump. When false (default), the trail is left as-is.
48
- * @default false
49
- */
50
- clearTrail?: boolean;
51
- };
52
- type SeekOptions = {
53
- /**
54
- * When true, the trail wraps around the period boundary,
55
- * which results in a full trail even near `t=0`
56
- * By default, the trail stops at `t=0`, which results in a partial trail near the start
57
- * @default false
58
- */
59
- wrap?: boolean;
60
- /**
61
- * Time gap between each trail point (in same units as `t`)
62
- * Smaller value means a trail that is more dense
63
- * @default period / trailLength
64
- */
65
- step?: number;
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
- }
128
- type MorphOptions = {
129
- /**
130
- * Duration of the morph transition in milliseconds
131
- * @default 300
132
- */
133
- duration?: number;
134
- /**
135
- * Strategy for lerping between curves with different periods:
136
- * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
137
- * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
138
- * @default 'normalized'
139
- */
140
- morphStrategy?: MorpStrategy;
141
- };
142
- interface Engine extends AnimationControls {
143
- /**
144
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
145
- * Internally, this increases the simulation time `t` by `speed * dt`,
146
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
147
- * and appends the new point to the trail.
148
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
149
- * ! Do not use `Array.length` to determine size
150
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
151
- */
152
- tick(deltaTime: number): Array<Point>;
153
- /**
154
- * Number of valid points in the trail buffer returned by the last `tick()` call
155
- * ! Use this instead of `trail.length`
156
- */
157
- readonly trailCount: number;
158
- /**
159
- * Returns the *skeleton* of the curve.
160
- * In technicality, it just represents the complete traversal of the curve over one full period,
161
- * which is sampled at points from `t=0` to `t=period`
162
- *
163
- * For "static" skeletons, this returns the same array on every call
164
- * For "live" skeletons, this returns a different array each frame
165
- * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
166
- *
167
- * The number of sample points is automatically derived from the curve's period.
168
- */
169
- getSarmalSkeleton(): Array<Point>;
170
- readonly isLiveSkeleton: boolean;
171
- /**
172
- * Begins a smooth transition from the current curve to `target`
173
- * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
174
- *
175
- * If called while a morph is already in progress,
176
- * the interpolated state is frozen and becomes the new `curveA`
177
- * @param target The curve to transition to
178
- * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
179
- */
180
- startMorph(target: CurveDef, strategy?: MorpStrategy): void;
181
- /**
182
- * Sets the interpolation amount between `curveA` and `curveB`.
183
- * 0 = full curveA
184
- * 1 = full curveB
185
- * Called by the renderer each frame as `actualTime` advances
186
- * @param alpha A value in [0, 1]
187
- */
188
- setMorphAlpha(alpha: number): void;
189
- /**
190
- * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
191
- * ! Called by the renderer when alpha reaches `1`
192
- */
193
- completeMorph(): void;
194
- /**
195
- * Current interpolation progress between `curveA` and `curveB`
196
- * `null` when no morph is in progress
197
- */
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;
204
- }
205
- interface SarmalInstance extends AnimationControls {
206
- start(): void;
207
- stop(): void;
208
- /** Stops the animation and cleans up resources */
209
- destroy(): void;
210
- /**
211
- * Smoothly transitions from the current curve to `target`.
212
- * The trail naturally reflects the new curve as new points are added.
213
- * @param target The curve to transition to
214
- * @param options.duration How long the morph takes in milliseconds (default: 300)
215
- * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
216
- * @returns Promise that resolves when the morph is complete
217
- */
218
- morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
219
- }
220
- /**
221
- * With 'gradient-animated' the colors cycle along the trail over time
222
- */
223
- type TrailStyle = "default" | "gradient-static" | "gradient-animated";
224
- type PalettePreset = "bard" | "sunset" | "ocean" | "ice" | "fire" | "forest";
225
- interface RendererOptions {
226
- /** Target canvas element that will contain the Sarmal */
227
- canvas: HTMLCanvasElement;
228
- engine: Engine;
229
- /**
230
- * @default '#ffffff'
231
- */
232
- skeletonColor?: string;
233
- /**
234
- * @default '#ffffff'
235
- */
236
- trailColor?: string;
237
- /**
238
- * @default '#ffffff'
239
- */
240
- headColor?: string;
241
- /** @default 4 */
242
- headRadius?: number;
243
- /**
244
- * Trail rendering style
245
- * @default 'default'
246
- */
247
- trailStyle?: TrailStyle;
248
- /**
249
- * Color palette for gradient trails
250
- * Can be a preset name or custom array of hex colors.
251
- * @default 'bard' for animated, 'ice' for static
252
- */
253
- palette?: PalettePreset | string[];
254
- }
255
- interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
256
- /** @default 120 */
257
- trailLength?: number;
258
- }
259
-
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 };