@sarmal/core 0.9.7 → 0.10.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 +171 -166
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.d.cts +2 -1
  4. package/dist/auto-init.d.ts +2 -1
  5. package/dist/auto-init.js +170 -165
  6. package/dist/auto-init.js.map +1 -1
  7. package/dist/curves/artemis2.cjs +7 -10
  8. package/dist/curves/artemis2.d.cts +1 -1
  9. package/dist/curves/artemis2.d.ts +1 -1
  10. package/dist/curves/artemis2.js +6 -9
  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 +28 -32
  28. package/dist/curves/index.d.cts +11 -11
  29. package/dist/curves/index.d.ts +11 -11
  30. package/dist/curves/index.js +28 -44
  31. package/dist/curves/lame.cjs +5 -6
  32. package/dist/curves/lame.d.cts +1 -1
  33. package/dist/curves/lame.d.ts +1 -1
  34. package/dist/curves/lame.js +4 -5
  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 +211 -283
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +31 -64
  54. package/dist/index.d.ts +31 -64
  55. package/dist/index.js +211 -300
  56. package/dist/index.js.map +1 -1
  57. package/dist/types-DcyISvnH.d.cts +230 -0
  58. package/dist/types-DcyISvnH.d.ts +230 -0
  59. package/package.json +2 -1
  60. package/dist/types-cR2xOewv.d.cts +0 -234
  61. package/dist/types-cR2xOewv.d.ts +0 -234
@@ -1,234 +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 SeekOptions = {
46
- /**
47
- * Decides whether the sarmal trail should be cleared when `seek` is called
48
- */
49
- clearTrail?: boolean;
50
- };
51
- type SeekWithTrailOptions = {
52
- /**
53
- * When true, the trail wraps around the period boundary,
54
- * which results in a full trail even near `t=0`
55
- * By default, the trail stops at `t=0`, which results in a partial trail near the start
56
- * @default false
57
- */
58
- wrap?: boolean;
59
- /**
60
- * Time gap between each trail point (in same units as `t`)
61
- * Smaller value means a trail that is more dense
62
- * @default period / trailLength
63
- */
64
- step?: number;
65
- };
66
- type MorpStrategy = "raw" | "normalized";
67
- type MorphOptions = {
68
- /**
69
- * Duration of the morph transition in milliseconds
70
- * @default 300
71
- */
72
- duration?: number;
73
- /**
74
- * Strategy for lerping between curves with different periods:
75
- * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
76
- * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
77
- * @default 'normalized'
78
- */
79
- morphStrategy?: MorpStrategy;
80
- };
81
- interface Engine {
82
- /**
83
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
84
- * Internally, this increases the simulation time `t` by `speed * dt`,
85
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
86
- * and appends the new point to the trail.
87
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
88
- * ! Do not use `Array.length` to determine size
89
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
90
- */
91
- tick(deltaTime: number): Array<Point>;
92
- /**
93
- * Number of valid points in the trail buffer returned by the last `tick()` call
94
- * ! Use this instead of `trail.length`
95
- */
96
- 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
- /**
103
- * Returns the *skeleton* of the curve.
104
- * In technicality, it just represents the complete traversal of the curve over one full period,
105
- * which is sampled at points from `t=0` to `t=period`
106
- *
107
- * For "static" skeletons, this returns the same array on every call
108
- * For "live" skeletons, this returns a different array each frame
109
- * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
110
- *
111
- * The number of sample points is automatically derived from the curve's period.
112
- */
113
- getSarmalSkeleton(): Array<Point>;
114
- 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
- /**
127
- * Begins a smooth transition from the current curve to `target`
128
- * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
129
- *
130
- * If called while a morph is already in progress,
131
- * the interpolated state is frozen and becomes the new `curveA`
132
- * @param target The curve to transition to
133
- * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
134
- */
135
- startMorph(target: CurveDef, strategy?: MorpStrategy): void;
136
- /**
137
- * Sets the interpolation amount between `curveA` and `curveB`.
138
- * 0 = full curveA
139
- * 1 = full curveB
140
- * Called by the renderer each frame as `actualTime` advances
141
- * @param alpha A value in [0, 1]
142
- */
143
- setMorphAlpha(alpha: number): void;
144
- /**
145
- * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
146
- * ! Called by the renderer when alpha reaches `1`
147
- */
148
- completeMorph(): void;
149
- /**
150
- * Current interpolation progress between `curveA` and `curveB`
151
- * `null` when no morph is in progress
152
- */
153
- readonly morphAlpha: number | null;
154
- }
155
- interface SarmalInstance {
156
- start(): void;
157
- stop(): void;
158
- /** Resets the engine and clears the trail */
159
- reset(): void;
160
- /** Stops the animation and cleans up resources */
161
- 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
- /**
174
- * Smoothly transitions from the current curve to `target`.
175
- * The trail naturally reflects the new curve as new points are added.
176
- * @param target The curve to transition to
177
- * @param options.duration How long the morph takes in milliseconds (default: 300)
178
- * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
179
- * @returns Promise that resolves when the morph is complete
180
- */
181
- morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
182
- }
183
- /**
184
- * With 'gradient-animated' the colors cycle along the trail over time
185
- */
186
- type TrailStyle = "default" | "gradient-static" | "gradient-animated";
187
- type PalettePreset = "bard" | "sunset" | "ocean" | "ice" | "fire" | "forest";
188
- interface RendererOptions {
189
- /** Target canvas element that will contain the Sarmal */
190
- canvas: HTMLCanvasElement;
191
- engine: Engine;
192
- /**
193
- * @default '#ffffff'
194
- */
195
- skeletonColor?: string;
196
- /**
197
- * @default '#ffffff'
198
- */
199
- trailColor?: string;
200
- /**
201
- * @default '#ffffff'
202
- */
203
- headColor?: string;
204
- /** @default 4 */
205
- headRadius?: number;
206
- /**
207
- * Trail rendering style
208
- * @default 'default'
209
- */
210
- trailStyle?: TrailStyle;
211
- /**
212
- * Color palette for gradient trails
213
- * Can be a preset name or custom array of hex colors.
214
- * @default 'bard' for animated, 'ice' for static
215
- */
216
- palette?: PalettePreset | string[];
217
- }
218
- interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
219
- /** @default 120 */
220
- trailLength?: number;
221
- }
222
-
223
- export type {
224
- CurveDef as C,
225
- Engine as E,
226
- PalettePreset as P,
227
- RendererOptions as R,
228
- SarmalInstance as S,
229
- TrailStyle as T,
230
- SarmalOptions as a,
231
- Point as b,
232
- SeekOptions as c,
233
- SeekWithTrailOptions as d,
234
- };
@@ -1,234 +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 SeekOptions = {
46
- /**
47
- * Decides whether the sarmal trail should be cleared when `seek` is called
48
- */
49
- clearTrail?: boolean;
50
- };
51
- type SeekWithTrailOptions = {
52
- /**
53
- * When true, the trail wraps around the period boundary,
54
- * which results in a full trail even near `t=0`
55
- * By default, the trail stops at `t=0`, which results in a partial trail near the start
56
- * @default false
57
- */
58
- wrap?: boolean;
59
- /**
60
- * Time gap between each trail point (in same units as `t`)
61
- * Smaller value means a trail that is more dense
62
- * @default period / trailLength
63
- */
64
- step?: number;
65
- };
66
- type MorpStrategy = "raw" | "normalized";
67
- type MorphOptions = {
68
- /**
69
- * Duration of the morph transition in milliseconds
70
- * @default 300
71
- */
72
- duration?: number;
73
- /**
74
- * Strategy for lerping between curves with different periods:
75
- * - 'normalized': maps `t` proportionally into each curve's period (smooth for all period ratios)
76
- * - 'raw': uses the same `t` for both curves (can produce incoherent results for mismatched periods)
77
- * @default 'normalized'
78
- */
79
- morphStrategy?: MorpStrategy;
80
- };
81
- interface Engine {
82
- /**
83
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
84
- * Internally, this increases the simulation time `t` by `speed * dt`,
85
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
86
- * and appends the new point to the trail.
87
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
88
- * ! Do not use `Array.length` to determine size
89
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
90
- */
91
- tick(deltaTime: number): Array<Point>;
92
- /**
93
- * Number of valid points in the trail buffer returned by the last `tick()` call
94
- * ! Use this instead of `trail.length`
95
- */
96
- 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
- /**
103
- * Returns the *skeleton* of the curve.
104
- * In technicality, it just represents the complete traversal of the curve over one full period,
105
- * which is sampled at points from `t=0` to `t=period`
106
- *
107
- * For "static" skeletons, this returns the same array on every call
108
- * For "live" skeletons, this returns a different array each frame
109
- * For `skeletonFn` overrides, this returns the skeleton from that function, which is *always* static
110
- *
111
- * The number of sample points is automatically derived from the curve's period.
112
- */
113
- getSarmalSkeleton(): Array<Point>;
114
- 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
- /**
127
- * Begins a smooth transition from the current curve to `target`
128
- * Saves the current curve as `curveA`, registers `target` as `curveB`, and resets `morphAlpha` to `0`
129
- *
130
- * If called while a morph is already in progress,
131
- * the interpolated state is frozen and becomes the new `curveA`
132
- * @param target The curve to transition to
133
- * @param strategy 'normalized' maps t proportionally into each curve's period (default), 'raw' uses the same t
134
- */
135
- startMorph(target: CurveDef, strategy?: MorpStrategy): void;
136
- /**
137
- * Sets the interpolation amount between `curveA` and `curveB`.
138
- * 0 = full curveA
139
- * 1 = full curveB
140
- * Called by the renderer each frame as `actualTime` advances
141
- * @param alpha A value in [0, 1]
142
- */
143
- setMorphAlpha(alpha: number): void;
144
- /**
145
- * Finalises the morph: `curveB` becomes the new active curve and `morphAlpha` is reset to `null`
146
- * ! Called by the renderer when alpha reaches `1`
147
- */
148
- completeMorph(): void;
149
- /**
150
- * Current interpolation progress between `curveA` and `curveB`
151
- * `null` when no morph is in progress
152
- */
153
- readonly morphAlpha: number | null;
154
- }
155
- interface SarmalInstance {
156
- start(): void;
157
- stop(): void;
158
- /** Resets the engine and clears the trail */
159
- reset(): void;
160
- /** Stops the animation and cleans up resources */
161
- 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
- /**
174
- * Smoothly transitions from the current curve to `target`.
175
- * The trail naturally reflects the new curve as new points are added.
176
- * @param target The curve to transition to
177
- * @param options.duration How long the morph takes in milliseconds (default: 300)
178
- * @param options.morphStrategy 'normalized' uses proportional t mapping (default), 'raw' uses same t
179
- * @returns Promise that resolves when the morph is complete
180
- */
181
- morphTo(target: CurveDef, options?: MorphOptions): Promise<void>;
182
- }
183
- /**
184
- * With 'gradient-animated' the colors cycle along the trail over time
185
- */
186
- type TrailStyle = "default" | "gradient-static" | "gradient-animated";
187
- type PalettePreset = "bard" | "sunset" | "ocean" | "ice" | "fire" | "forest";
188
- interface RendererOptions {
189
- /** Target canvas element that will contain the Sarmal */
190
- canvas: HTMLCanvasElement;
191
- engine: Engine;
192
- /**
193
- * @default '#ffffff'
194
- */
195
- skeletonColor?: string;
196
- /**
197
- * @default '#ffffff'
198
- */
199
- trailColor?: string;
200
- /**
201
- * @default '#ffffff'
202
- */
203
- headColor?: string;
204
- /** @default 4 */
205
- headRadius?: number;
206
- /**
207
- * Trail rendering style
208
- * @default 'default'
209
- */
210
- trailStyle?: TrailStyle;
211
- /**
212
- * Color palette for gradient trails
213
- * Can be a preset name or custom array of hex colors.
214
- * @default 'bard' for animated, 'ice' for static
215
- */
216
- palette?: PalettePreset | string[];
217
- }
218
- interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
219
- /** @default 120 */
220
- trailLength?: number;
221
- }
222
-
223
- export type {
224
- CurveDef as C,
225
- Engine as E,
226
- PalettePreset as P,
227
- RendererOptions as R,
228
- SarmalInstance as S,
229
- TrailStyle as T,
230
- SarmalOptions as a,
231
- Point as b,
232
- SeekOptions as c,
233
- SeekWithTrailOptions as d,
234
- };