@sarmal/core 0.3.0 → 0.4.1

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/dist/index.d.cts CHANGED
@@ -1,112 +1,155 @@
1
1
  interface Point {
2
- x: number;
3
- y: number;
2
+ x: number;
3
+ y: number;
4
4
  }
5
5
  interface CurveDef {
6
- name: string;
7
- fn: (t: number, time: number, params: Record<string, number>) => Point;
8
- /**
9
- * @default (Math.PI * 2)
10
- */
11
- period?: number;
12
- /**
13
- * @default 1
14
- */
15
- speed?: number;
16
- /**
17
- * To indicate a compatible library version when providing the curve definitions
18
- * Intended for potential backwards compatibility scenarios and futureproofing
19
- */
20
- version?: number;
6
+ name: string;
7
+ fn: (t: number, time: number, params: Record<string, number>) => Point;
8
+ /**
9
+ * @default (Math.PI * 2)
10
+ */
11
+ period?: number;
12
+ /**
13
+ * @default 1
14
+ */
15
+ speed?: number;
16
+ /**
17
+ * To indicate a compatible library version when providing the curve definitions
18
+ * Intended for potential backwards compatibility scenarios and futureproofing
19
+ */
20
+ version?: number;
21
21
  }
22
+ type SeekOptions = {
23
+ /**
24
+ * Decides whether the sarmal trail should be cleared when `seek` is called
25
+ */
26
+ clearTrail?: boolean;
27
+ };
28
+ type SeekWithTrailOptions = {
29
+ /**
30
+ * When true, the trail wraps around the period boundary,
31
+ * which results in a full trail even near `t=0`
32
+ * By default, the trail stops at `t=0`, which results in a partial trail near the start
33
+ * @default false
34
+ */
35
+ wrap?: boolean;
36
+ /**
37
+ * Time gap between each trail point (in same units as `t`)
38
+ * Smaller value means a trail that is more dense
39
+ * @default period / trailLength
40
+ */
41
+ step?: number;
42
+ };
22
43
  interface Engine {
23
- /**
24
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
25
- * Internally, this increases the simulation time `t` by `speed * dt`,
26
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
27
- * and appends the new point to the trail.
28
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
29
- * ! Do not use `Array.length` to determine size
30
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
31
- */
32
- tick(deltaTime: number): Array<Point>;
33
- /**
34
- * Number of valid points in the trail buffer returned by the last `tick()` call
35
- * ! Use this instead of `trail.length`
36
- */
37
- readonly trailCount: number;
38
- /**
39
- * Resets the simulation state, by clearing the trail and reverting internal time `t` to 0.
40
- * The next call to `tick` will start fresh from the beginning of the curve.
41
- */
42
- reset(): void;
43
- /**
44
- * Returns the *skeleton* of the curve.
45
- * In technicality, it just represents the complete traversal of the curve over one full period,
46
- * which is sampled at points from `t=0` to `t=period`
47
- *
48
- * The skeleton is always derived from the curve's state at `t=0` using `fn(t, 0)`
49
- * This represents the full path the sarmal would trace on its first complete cycle,
50
- * rendered as a static background reference.
51
- *
52
- * The number of sample points is automatically derived from the curve's period.
53
- */
54
- getSarmalSkeleton(): Array<Point>;
44
+ /**
45
+ * Advances the Sarmal simulation by the given delta time (dt) in seconds.
46
+ * Internally, this increases the simulation time `t` by `speed * dt`,
47
+ * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
48
+ * and appends the new point to the trail.
49
+ * Returns the pre-allocated trail buffer, which has the *same* reference every call
50
+ * ! Do not use `Array.length` to determine size
51
+ * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
52
+ */
53
+ tick(deltaTime: number): Array<Point>;
54
+ /**
55
+ * Number of valid points in the trail buffer returned by the last `tick()` call
56
+ * ! Use this instead of `trail.length`
57
+ */
58
+ readonly trailCount: number;
59
+ /**
60
+ * Resets the simulation state, by clearing the trail and reverting internal time `t` to 0.
61
+ * The next call to `tick` will start fresh from the beginning of the curve.
62
+ */
63
+ reset(): void;
64
+ /**
65
+ * Returns the *skeleton* of the curve.
66
+ * In technicality, it just represents the complete traversal of the curve over one full period,
67
+ * which is sampled at points from `t=0` to `t=period`
68
+ *
69
+ * The skeleton is always derived from the curve's state at `t=0` using `fn(t, 0)`
70
+ * This represents the full path the sarmal would trace on its first complete cycle,
71
+ * rendered as a static background reference.
72
+ *
73
+ * The number of sample points is automatically derived from the curve's period.
74
+ */
75
+ getSarmalSkeleton(): Array<Point>;
76
+ /**
77
+ * Sets the simulation time `t` directly to the specified value.
78
+ * By default, the trail is preserved
79
+ * @param t The time value to seek to (will be wrapped into [0, period))
80
+ */
81
+ seek(t: number, options?: SeekOptions): void;
82
+ /**
83
+ * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
84
+ * @param t The time value to seek to (will be wrapped into [0, period))
85
+ */
86
+ seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
55
87
  }
56
88
  interface SarmalInstance {
57
- start(): void;
58
- stop(): void;
59
- /** Resets the engine and clears the trail */
60
- reset(): void;
61
- /** Stops the animation and cleans up resources */
62
- destroy(): void;
89
+ start(): void;
90
+ stop(): void;
91
+ /** Resets the engine and clears the trail */
92
+ reset(): void;
93
+ /** Stops the animation and cleans up resources */
94
+ destroy(): void;
95
+ /**
96
+ * Sets the simulation time `t` directly to the specified value.
97
+ * By default, the trail is preserved
98
+ * @param t The time value to seek to (will be wrapped into [0, period))
99
+ */
100
+ seek(t: number, options?: SeekOptions): void;
101
+ /**
102
+ * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
103
+ * @param t The time value to seek to (will be wrapped into [0, period))
104
+ */
105
+ seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
63
106
  }
64
107
  interface RendererOptions {
65
- /** Target canvas element that will contain the Sarmal */
66
- canvas: HTMLCanvasElement;
67
- engine: Engine;
68
- /**
69
- * @default '#ffffff'
70
- */
71
- skeletonColor?: string;
72
- /**
73
- * @default '#ffffff'
74
- */
75
- trailColor?: string;
76
- /**
77
- * @default '#ffffff'
78
- */
79
- headColor?: string;
80
- /** @default 4 */
81
- headRadius?: number;
82
- /** @default 20 */
83
- glowSize?: number;
108
+ /** Target canvas element that will contain the Sarmal */
109
+ canvas: HTMLCanvasElement;
110
+ engine: Engine;
111
+ /**
112
+ * @default '#ffffff'
113
+ */
114
+ skeletonColor?: string;
115
+ /**
116
+ * @default '#ffffff'
117
+ */
118
+ trailColor?: string;
119
+ /**
120
+ * @default '#ffffff'
121
+ */
122
+ headColor?: string;
123
+ /** @default 4 */
124
+ headRadius?: number;
125
+ /** @default 20 */
126
+ glowSize?: number;
84
127
  }
85
128
  interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
86
- /** @default 120 */
87
- trailLength?: number;
129
+ /** @default 120 */
130
+ trailLength?: number;
88
131
  }
89
132
 
90
133
  interface SVGRendererOptions {
91
- /** Container element that will contain the SVG */
92
- container: Element;
93
- engine: Engine;
94
- /** @default '#ffffff' */
95
- skeletonColor?: string;
96
- /** @default '#ffffff' */
97
- trailColor?: string;
98
- /** @default '#ffffff' */
99
- headColor?: string;
100
- /** @default 4 */
101
- headRadius?: number;
102
- /** @default 20 */
103
- glowSize?: number;
104
- /** @default 'Loading' */
105
- ariaLabel?: string;
134
+ /** Container element that will contain the SVG */
135
+ container: Element;
136
+ engine: Engine;
137
+ /** @default '#ffffff' */
138
+ skeletonColor?: string;
139
+ /** @default '#ffffff' */
140
+ trailColor?: string;
141
+ /** @default '#ffffff' */
142
+ headColor?: string;
143
+ /** @default 4 */
144
+ headRadius?: number;
145
+ /** @default 20 */
146
+ glowSize?: number;
147
+ /** @default 'Loading' */
148
+ ariaLabel?: string;
106
149
  }
107
150
  interface SVGSarmalOptions extends Omit<SVGRendererOptions, "container" | "engine"> {
108
- /** @default 120 */
109
- trailLength?: number;
151
+ /** @default 120 */
152
+ trailLength?: number;
110
153
  }
111
154
  /**
112
155
  * Creates a live SVG renderer for sarmal animations
@@ -124,7 +167,11 @@ declare function createSVGRenderer(options: SVGRendererOptions): SarmalInstance;
124
167
  * sarmal.start()
125
168
  * ```
126
169
  */
127
- declare function createSarmalSVG(container: Element, curveDef: CurveDef, options?: SVGSarmalOptions): SarmalInstance;
170
+ declare function createSarmalSVG(
171
+ container: Element,
172
+ curveDef: CurveDef,
173
+ options?: SVGSarmalOptions,
174
+ ): SarmalInstance;
128
175
 
129
176
  /**
130
177
  * Creates the core simulation engine for a sarmal
@@ -158,6 +205,27 @@ declare const curves: Record<string, CurveDef>;
158
205
  * sarmal.start()
159
206
  * ```
160
207
  */
161
- declare function createSarmal(canvas: HTMLCanvasElement, curveDef: CurveDef, options?: SarmalOptions): SarmalInstance;
208
+ declare function createSarmal(
209
+ canvas: HTMLCanvasElement,
210
+ curveDef: CurveDef,
211
+ options?: SarmalOptions,
212
+ ): SarmalInstance;
162
213
 
163
- export { type CurveDef, type Engine, type Point, type RendererOptions, type SVGRendererOptions, type SVGSarmalOptions, type SarmalInstance, type SarmalOptions, createEngine, createRenderer, createSVGRenderer, createSarmal, createSarmalSVG, curves };
214
+ export {
215
+ type CurveDef,
216
+ type Engine,
217
+ type Point,
218
+ type RendererOptions,
219
+ type SVGRendererOptions,
220
+ type SVGSarmalOptions,
221
+ type SarmalInstance,
222
+ type SarmalOptions,
223
+ type SeekOptions,
224
+ type SeekWithTrailOptions,
225
+ createEngine,
226
+ createRenderer,
227
+ createSVGRenderer,
228
+ createSarmal,
229
+ createSarmalSVG,
230
+ curves,
231
+ };
package/dist/index.d.ts CHANGED
@@ -1,112 +1,155 @@
1
1
  interface Point {
2
- x: number;
3
- y: number;
2
+ x: number;
3
+ y: number;
4
4
  }
5
5
  interface CurveDef {
6
- name: string;
7
- fn: (t: number, time: number, params: Record<string, number>) => Point;
8
- /**
9
- * @default (Math.PI * 2)
10
- */
11
- period?: number;
12
- /**
13
- * @default 1
14
- */
15
- speed?: number;
16
- /**
17
- * To indicate a compatible library version when providing the curve definitions
18
- * Intended for potential backwards compatibility scenarios and futureproofing
19
- */
20
- version?: number;
6
+ name: string;
7
+ fn: (t: number, time: number, params: Record<string, number>) => Point;
8
+ /**
9
+ * @default (Math.PI * 2)
10
+ */
11
+ period?: number;
12
+ /**
13
+ * @default 1
14
+ */
15
+ speed?: number;
16
+ /**
17
+ * To indicate a compatible library version when providing the curve definitions
18
+ * Intended for potential backwards compatibility scenarios and futureproofing
19
+ */
20
+ version?: number;
21
21
  }
22
+ type SeekOptions = {
23
+ /**
24
+ * Decides whether the sarmal trail should be cleared when `seek` is called
25
+ */
26
+ clearTrail?: boolean;
27
+ };
28
+ type SeekWithTrailOptions = {
29
+ /**
30
+ * When true, the trail wraps around the period boundary,
31
+ * which results in a full trail even near `t=0`
32
+ * By default, the trail stops at `t=0`, which results in a partial trail near the start
33
+ * @default false
34
+ */
35
+ wrap?: boolean;
36
+ /**
37
+ * Time gap between each trail point (in same units as `t`)
38
+ * Smaller value means a trail that is more dense
39
+ * @default period / trailLength
40
+ */
41
+ step?: number;
42
+ };
22
43
  interface Engine {
23
- /**
24
- * Advances the Sarmal simulation by the given delta time (dt) in seconds.
25
- * Internally, this increases the simulation time `t` by `speed * dt`,
26
- * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
27
- * and appends the new point to the trail.
28
- * Returns the pre-allocated trail buffer, which has the *same* reference every call
29
- * ! Do not use `Array.length` to determine size
30
- * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
31
- */
32
- tick(deltaTime: number): Array<Point>;
33
- /**
34
- * Number of valid points in the trail buffer returned by the last `tick()` call
35
- * ! Use this instead of `trail.length`
36
- */
37
- readonly trailCount: number;
38
- /**
39
- * Resets the simulation state, by clearing the trail and reverting internal time `t` to 0.
40
- * The next call to `tick` will start fresh from the beginning of the curve.
41
- */
42
- reset(): void;
43
- /**
44
- * Returns the *skeleton* of the curve.
45
- * In technicality, it just represents the complete traversal of the curve over one full period,
46
- * which is sampled at points from `t=0` to `t=period`
47
- *
48
- * The skeleton is always derived from the curve's state at `t=0` using `fn(t, 0)`
49
- * This represents the full path the sarmal would trace on its first complete cycle,
50
- * rendered as a static background reference.
51
- *
52
- * The number of sample points is automatically derived from the curve's period.
53
- */
54
- getSarmalSkeleton(): Array<Point>;
44
+ /**
45
+ * Advances the Sarmal simulation by the given delta time (dt) in seconds.
46
+ * Internally, this increases the simulation time `t` by `speed * dt`,
47
+ * wraps `t` at `period`, evaluates the curve's parametric function `fn(t)`,
48
+ * and appends the new point to the trail.
49
+ * Returns the pre-allocated trail buffer, which has the *same* reference every call
50
+ * ! Do not use `Array.length` to determine size
51
+ * @param deltaTime Delta time in seconds (typically frame time from **requestAnimationFrame** or similar)
52
+ */
53
+ tick(deltaTime: number): Array<Point>;
54
+ /**
55
+ * Number of valid points in the trail buffer returned by the last `tick()` call
56
+ * ! Use this instead of `trail.length`
57
+ */
58
+ readonly trailCount: number;
59
+ /**
60
+ * Resets the simulation state, by clearing the trail and reverting internal time `t` to 0.
61
+ * The next call to `tick` will start fresh from the beginning of the curve.
62
+ */
63
+ reset(): void;
64
+ /**
65
+ * Returns the *skeleton* of the curve.
66
+ * In technicality, it just represents the complete traversal of the curve over one full period,
67
+ * which is sampled at points from `t=0` to `t=period`
68
+ *
69
+ * The skeleton is always derived from the curve's state at `t=0` using `fn(t, 0)`
70
+ * This represents the full path the sarmal would trace on its first complete cycle,
71
+ * rendered as a static background reference.
72
+ *
73
+ * The number of sample points is automatically derived from the curve's period.
74
+ */
75
+ getSarmalSkeleton(): Array<Point>;
76
+ /**
77
+ * Sets the simulation time `t` directly to the specified value.
78
+ * By default, the trail is preserved
79
+ * @param t The time value to seek to (will be wrapped into [0, period))
80
+ */
81
+ seek(t: number, options?: SeekOptions): void;
82
+ /**
83
+ * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
84
+ * @param t The time value to seek to (will be wrapped into [0, period))
85
+ */
86
+ seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
55
87
  }
56
88
  interface SarmalInstance {
57
- start(): void;
58
- stop(): void;
59
- /** Resets the engine and clears the trail */
60
- reset(): void;
61
- /** Stops the animation and cleans up resources */
62
- destroy(): void;
89
+ start(): void;
90
+ stop(): void;
91
+ /** Resets the engine and clears the trail */
92
+ reset(): void;
93
+ /** Stops the animation and cleans up resources */
94
+ destroy(): void;
95
+ /**
96
+ * Sets the simulation time `t` directly to the specified value.
97
+ * By default, the trail is preserved
98
+ * @param t The time value to seek to (will be wrapped into [0, period))
99
+ */
100
+ seek(t: number, options?: SeekOptions): void;
101
+ /**
102
+ * Seeks to `t` and rebuilds the trail as if the animation naturally arrived there from `t=0`
103
+ * @param t The time value to seek to (will be wrapped into [0, period))
104
+ */
105
+ seekWithTrail(t: number, options?: SeekWithTrailOptions): void;
63
106
  }
64
107
  interface RendererOptions {
65
- /** Target canvas element that will contain the Sarmal */
66
- canvas: HTMLCanvasElement;
67
- engine: Engine;
68
- /**
69
- * @default '#ffffff'
70
- */
71
- skeletonColor?: string;
72
- /**
73
- * @default '#ffffff'
74
- */
75
- trailColor?: string;
76
- /**
77
- * @default '#ffffff'
78
- */
79
- headColor?: string;
80
- /** @default 4 */
81
- headRadius?: number;
82
- /** @default 20 */
83
- glowSize?: number;
108
+ /** Target canvas element that will contain the Sarmal */
109
+ canvas: HTMLCanvasElement;
110
+ engine: Engine;
111
+ /**
112
+ * @default '#ffffff'
113
+ */
114
+ skeletonColor?: string;
115
+ /**
116
+ * @default '#ffffff'
117
+ */
118
+ trailColor?: string;
119
+ /**
120
+ * @default '#ffffff'
121
+ */
122
+ headColor?: string;
123
+ /** @default 4 */
124
+ headRadius?: number;
125
+ /** @default 20 */
126
+ glowSize?: number;
84
127
  }
85
128
  interface SarmalOptions extends Omit<RendererOptions, "canvas" | "engine"> {
86
- /** @default 120 */
87
- trailLength?: number;
129
+ /** @default 120 */
130
+ trailLength?: number;
88
131
  }
89
132
 
90
133
  interface SVGRendererOptions {
91
- /** Container element that will contain the SVG */
92
- container: Element;
93
- engine: Engine;
94
- /** @default '#ffffff' */
95
- skeletonColor?: string;
96
- /** @default '#ffffff' */
97
- trailColor?: string;
98
- /** @default '#ffffff' */
99
- headColor?: string;
100
- /** @default 4 */
101
- headRadius?: number;
102
- /** @default 20 */
103
- glowSize?: number;
104
- /** @default 'Loading' */
105
- ariaLabel?: string;
134
+ /** Container element that will contain the SVG */
135
+ container: Element;
136
+ engine: Engine;
137
+ /** @default '#ffffff' */
138
+ skeletonColor?: string;
139
+ /** @default '#ffffff' */
140
+ trailColor?: string;
141
+ /** @default '#ffffff' */
142
+ headColor?: string;
143
+ /** @default 4 */
144
+ headRadius?: number;
145
+ /** @default 20 */
146
+ glowSize?: number;
147
+ /** @default 'Loading' */
148
+ ariaLabel?: string;
106
149
  }
107
150
  interface SVGSarmalOptions extends Omit<SVGRendererOptions, "container" | "engine"> {
108
- /** @default 120 */
109
- trailLength?: number;
151
+ /** @default 120 */
152
+ trailLength?: number;
110
153
  }
111
154
  /**
112
155
  * Creates a live SVG renderer for sarmal animations
@@ -124,7 +167,11 @@ declare function createSVGRenderer(options: SVGRendererOptions): SarmalInstance;
124
167
  * sarmal.start()
125
168
  * ```
126
169
  */
127
- declare function createSarmalSVG(container: Element, curveDef: CurveDef, options?: SVGSarmalOptions): SarmalInstance;
170
+ declare function createSarmalSVG(
171
+ container: Element,
172
+ curveDef: CurveDef,
173
+ options?: SVGSarmalOptions,
174
+ ): SarmalInstance;
128
175
 
129
176
  /**
130
177
  * Creates the core simulation engine for a sarmal
@@ -158,6 +205,27 @@ declare const curves: Record<string, CurveDef>;
158
205
  * sarmal.start()
159
206
  * ```
160
207
  */
161
- declare function createSarmal(canvas: HTMLCanvasElement, curveDef: CurveDef, options?: SarmalOptions): SarmalInstance;
208
+ declare function createSarmal(
209
+ canvas: HTMLCanvasElement,
210
+ curveDef: CurveDef,
211
+ options?: SarmalOptions,
212
+ ): SarmalInstance;
162
213
 
163
- export { type CurveDef, type Engine, type Point, type RendererOptions, type SVGRendererOptions, type SVGSarmalOptions, type SarmalInstance, type SarmalOptions, createEngine, createRenderer, createSVGRenderer, createSarmal, createSarmalSVG, curves };
214
+ export {
215
+ type CurveDef,
216
+ type Engine,
217
+ type Point,
218
+ type RendererOptions,
219
+ type SVGRendererOptions,
220
+ type SVGSarmalOptions,
221
+ type SarmalInstance,
222
+ type SarmalOptions,
223
+ type SeekOptions,
224
+ type SeekWithTrailOptions,
225
+ createEngine,
226
+ createRenderer,
227
+ createSVGRenderer,
228
+ createSarmal,
229
+ createSarmalSVG,
230
+ curves,
231
+ };