@sarmal/core 0.24.0 → 0.25.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.
Files changed (79) hide show
  1. package/dist/auto-init.cjs +245 -141
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.js +244 -140
  4. package/dist/auto-init.js.map +1 -1
  5. package/dist/curves/artemis2.cjs +87 -14
  6. package/dist/curves/artemis2.cjs.map +1 -1
  7. package/dist/curves/artemis2.d.cts +1 -5
  8. package/dist/curves/artemis2.d.ts +1 -5
  9. package/dist/curves/artemis2.js +86 -13
  10. package/dist/curves/artemis2.js.map +1 -1
  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 +154 -71
  28. package/dist/curves/index.cjs.map +1 -1
  29. package/dist/curves/index.d.cts +29 -29
  30. package/dist/curves/index.d.ts +29 -29
  31. package/dist/curves/index.js +170 -71
  32. package/dist/curves/index.js.map +1 -1
  33. package/dist/curves/lame.cjs +6 -5
  34. package/dist/curves/lame.d.cts +1 -1
  35. package/dist/curves/lame.d.ts +1 -1
  36. package/dist/curves/lame.js +5 -4
  37. package/dist/curves/lissajous32.cjs +4 -4
  38. package/dist/curves/lissajous32.d.cts +1 -1
  39. package/dist/curves/lissajous32.d.ts +1 -1
  40. package/dist/curves/lissajous32.js +3 -3
  41. package/dist/curves/lissajous43.cjs +4 -4
  42. package/dist/curves/lissajous43.d.cts +1 -1
  43. package/dist/curves/lissajous43.d.ts +1 -1
  44. package/dist/curves/lissajous43.js +3 -3
  45. package/dist/curves/rose3.cjs +4 -4
  46. package/dist/curves/rose3.d.cts +1 -1
  47. package/dist/curves/rose3.d.ts +1 -1
  48. package/dist/curves/rose3.js +3 -3
  49. package/dist/curves/rose5.cjs +4 -4
  50. package/dist/curves/rose5.d.cts +1 -1
  51. package/dist/curves/rose5.d.ts +1 -1
  52. package/dist/curves/rose5.js +3 -3
  53. package/dist/curves/rose52.cjs +5 -5
  54. package/dist/curves/rose52.d.cts +1 -1
  55. package/dist/curves/rose52.d.ts +1 -1
  56. package/dist/curves/rose52.js +4 -4
  57. package/dist/curves/star.cjs +8 -5
  58. package/dist/curves/star.d.cts +1 -1
  59. package/dist/curves/star.d.ts +1 -1
  60. package/dist/curves/star.js +7 -4
  61. package/dist/curves/star4.cjs +8 -5
  62. package/dist/curves/star4.d.cts +1 -1
  63. package/dist/curves/star4.d.ts +1 -1
  64. package/dist/curves/star4.js +7 -4
  65. package/dist/curves/star7.cjs +8 -5
  66. package/dist/curves/star7.d.cts +1 -1
  67. package/dist/curves/star7.d.ts +1 -1
  68. package/dist/curves/star7.js +7 -4
  69. package/dist/index.cjs +232 -172
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts +106 -36
  72. package/dist/index.d.ts +106 -36
  73. package/dist/index.js +252 -172
  74. package/dist/index.js.map +1 -1
  75. package/dist/types-Z9i1_AQZ.d.cts +339 -0
  76. package/dist/types-Z9i1_AQZ.d.ts +339 -0
  77. package/package.json +1 -1
  78. package/dist/types-CknrlCAf.d.cts +0 -314
  79. package/dist/types-CknrlCAf.d.ts +0 -314
package/dist/index.d.cts CHANGED
@@ -1,31 +1,46 @@
1
- import { B as BaseRendererOptions, E as Engine, S as SarmalInstance, C as CurveDef, R as RendererOptions, P as Point, a as SarmalOptions } from './types-CknrlCAf.cjs';
2
- export { J as JumpOptions, b as RuntimeRenderOptions, c as SeekOptions, T as TrailColor, d as TrailStyle } from './types-CknrlCAf.cjs';
3
- export { CurveName, curves } from './curves/index.cjs';
4
- export { artemis2 } from './curves/artemis2.cjs';
5
- export { astroid } from './curves/astroid.cjs';
6
- export { deltoid } from './curves/deltoid.cjs';
7
- export { epicycloid3 } from './curves/epicycloid3.cjs';
8
- export { epitrochoid7 } from './curves/epitrochoid7.cjs';
9
- export { lame } from './curves/lame.cjs';
10
- export { lissajous32 } from './curves/lissajous32.cjs';
11
- export { lissajous43 } from './curves/lissajous43.cjs';
12
- export { rose3 } from './curves/rose3.cjs';
13
- export { rose5 } from './curves/rose5.cjs';
14
- import './curves/rose52.cjs';
15
- import './curves/star.cjs';
16
- import './curves/star4.cjs';
17
- import './curves/star7.cjs';
1
+ import {
2
+ B as BaseRendererOptions,
3
+ E as Engine,
4
+ S as SarmalInstance,
5
+ C as CurveDef,
6
+ P as Point,
7
+ R as RendererOptions,
8
+ a as ControlPoint,
9
+ b as SarmalOptions,
10
+ } from "./types-Z9i1_AQZ.cjs";
11
+ export {
12
+ J as JumpOptions,
13
+ c as RuntimeRenderOptions,
14
+ d as SeekOptions,
15
+ T as TrailColor,
16
+ e as TrailStyle,
17
+ } from "./types-Z9i1_AQZ.cjs";
18
+ export { CurveName, curves } from "./curves/index.cjs";
19
+ export { artemis2 } from "./curves/artemis2.cjs";
20
+ export { astroid } from "./curves/astroid.cjs";
21
+ export { deltoid } from "./curves/deltoid.cjs";
22
+ export { epicycloid3 } from "./curves/epicycloid3.cjs";
23
+ export { epitrochoid7 } from "./curves/epitrochoid7.cjs";
24
+ export { lame } from "./curves/lame.cjs";
25
+ export { lissajous32 } from "./curves/lissajous32.cjs";
26
+ export { lissajous43 } from "./curves/lissajous43.cjs";
27
+ export { rose3 } from "./curves/rose3.cjs";
28
+ export { rose5 } from "./curves/rose5.cjs";
29
+ import "./curves/rose52.cjs";
30
+ import "./curves/star.cjs";
31
+ import "./curves/star4.cjs";
32
+ import "./curves/star7.cjs";
18
33
 
19
34
  interface SVGRendererOptions extends BaseRendererOptions {
20
- /** SVG element the renderer draws into directly */
21
- container: SVGSVGElement;
22
- engine: Engine;
23
- /** @default 'Loading' */
24
- ariaLabel?: string;
35
+ /** SVG element the renderer draws into directly */
36
+ container: SVGSVGElement;
37
+ engine: Engine;
38
+ /** @default 'Loading' */
39
+ ariaLabel?: string;
25
40
  }
26
41
  interface SVGSarmalOptions extends Omit<SVGRendererOptions, "container" | "engine"> {
27
- /** @default 120 */
28
- trailLength?: number;
42
+ /** @default 120 */
43
+ trailLength?: number;
29
44
  }
30
45
  /**
31
46
  * Creates a live SVG renderer for sarmal animations
@@ -50,19 +65,43 @@ declare function createSVGRenderer(options: SVGRendererOptions): SarmalInstance;
50
65
  * controlled.pause() // Pause later
51
66
  * ```
52
67
  */
53
- declare function createSarmalSVG(container: SVGSVGElement, curveDef: CurveDef, options?: SVGSarmalOptions): SarmalInstance;
68
+ declare function createSarmalSVG(
69
+ container: SVGSVGElement,
70
+ curveDef: CurveDef,
71
+ options?: SVGSarmalOptions,
72
+ ): SarmalInstance;
54
73
 
74
+ interface BoundaryResult {
75
+ scale: number;
76
+ offsetX: number;
77
+ offsetY: number;
78
+ }
79
+ /**
80
+ * Computes how to map engine coordinates into a viewport of the given logical size.
81
+ * ! Returns `null` if `pts` is empty
82
+ * ! Throws if all points are identical
83
+ *
84
+ * Padding per side is `max(FIT_PADDING * dim, minPaddingPx)`, so the stricter constraint wins.
85
+ * `minPaddingPx` defaults to `FIT_PADDING_MIN` (4px) for pixel-space callers.
86
+ * Pass `0` when the logical space is itself a normalized viewBox (e.g. SVG export).
87
+ */
88
+ declare function computeBoundaries(
89
+ pts: Point[],
90
+ logicalWidth: number,
91
+ logicalHeight: number,
92
+ minPaddingPx?: number,
93
+ ): BoundaryResult | null;
55
94
  /**
56
95
  * Can be passed directly to `trailColor`,
57
96
  * or can be mixed/sliced before passing as a prop.
58
97
  */
59
98
  declare const palettes: {
60
- readonly bard: ["#a855f7", "#3b82f6", "#14b8a6", "#ec4899"];
61
- readonly sunset: ["#f97316", "#dc2626", "#9333ea", "#f472b6"];
62
- readonly ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"];
63
- readonly ice: ["#1e3a8a", "#67e8f9"];
64
- readonly fire: ["#7f1d1d", "#fbbf24"];
65
- readonly forest: ["#14532d", "#86efac"];
99
+ readonly bard: ["#a855f7", "#3b82f6", "#14b8a6", "#ec4899"];
100
+ readonly sunset: ["#f97316", "#dc2626", "#9333ea", "#f472b6"];
101
+ readonly ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"];
102
+ readonly ice: ["#1e3a8a", "#67e8f9"];
103
+ readonly fire: ["#7f1d1d", "#fbbf24"];
104
+ readonly forest: ["#14532d", "#86efac"];
66
105
  };
67
106
  type SarmalPalette = keyof typeof palettes;
68
107
 
@@ -86,7 +125,7 @@ declare function createRenderer(options: RendererOptions): SarmalInstance;
86
125
  * @param t Parametric position along the closed loop. Wraps into `[0, 2π)` automatically, so values outside that range are remapped rather than rejected
87
126
  * @returns The `(x, y)` position on the spline at time `t`
88
127
  */
89
- declare function evaluateCatmullRom(points: Array<[number, number]>, t: number): Point;
128
+ declare function evaluateCatmullRom(points: Array<ControlPoint>, t: number): Point;
90
129
  /**
91
130
  * The returned curve definition produces a closed Catmull-Rom spline that
92
131
  * passes through every point in order, looping back from the last point to the first.
@@ -94,8 +133,9 @@ declare function evaluateCatmullRom(points: Array<[number, number]>, t: number):
94
133
  * @param points Array of control points in **normalized `[−1, 1]` space**,
95
134
  * matching the playground's draw-mode coordinate system.
96
135
  * ! Must contain at least 3 points.
136
+ * @param opts Optional overrides for the returned `CurveDef`.
137
+ * @param opts.name Display name for the curve. Defaults to `"drawn"`.
97
138
  * @returns A `CurveDef` with `period: 2π` and the spline evaluator as its `fn`.
98
- * `name` is set to `"custom"`.
99
139
  * @throws If `points` has fewer than 3 entries.
100
140
  *
101
141
  * @example
@@ -111,7 +151,12 @@ declare function evaluateCatmullRom(points: Array<[number, number]>, t: number):
111
151
  * createSarmal(canvas, curve)
112
152
  * ```
113
153
  */
114
- declare function drawCurve(points: Array<[number, number]>): CurveDef;
154
+ declare function drawCurve(
155
+ points: Array<ControlPoint>,
156
+ opts?: {
157
+ name?: string;
158
+ },
159
+ ): CurveDef;
115
160
 
116
161
  /**
117
162
  * Creates a sarmal animation on a canvas element
@@ -127,6 +172,31 @@ declare function drawCurve(points: Array<[number, number]>): CurveDef;
127
172
  * controlled.pause() // Pause later
128
173
  * ```
129
174
  */
130
- declare function createSarmal(canvas: HTMLCanvasElement, curveDef: CurveDef, options?: SarmalOptions): SarmalInstance;
175
+ declare function createSarmal(
176
+ canvas: HTMLCanvasElement,
177
+ curveDef: CurveDef,
178
+ options?: SarmalOptions,
179
+ ): SarmalInstance;
131
180
 
132
- export { BaseRendererOptions, CurveDef, Engine, Point, RendererOptions, type SVGRendererOptions, type SVGSarmalOptions, SarmalInstance, SarmalOptions, type SarmalPalette, createEngine, createRenderer, createSVGRenderer, createSarmal, createSarmalSVG, drawCurve, evaluateCatmullRom, palettes };
181
+ export {
182
+ BaseRendererOptions,
183
+ type BoundaryResult,
184
+ CurveDef,
185
+ Engine,
186
+ Point,
187
+ RendererOptions,
188
+ type SVGRendererOptions,
189
+ type SVGSarmalOptions,
190
+ SarmalInstance,
191
+ SarmalOptions,
192
+ type SarmalPalette,
193
+ computeBoundaries,
194
+ createEngine,
195
+ createRenderer,
196
+ createSVGRenderer,
197
+ createSarmal,
198
+ createSarmalSVG,
199
+ drawCurve,
200
+ evaluateCatmullRom,
201
+ palettes,
202
+ };
package/dist/index.d.ts CHANGED
@@ -1,31 +1,46 @@
1
- import { B as BaseRendererOptions, E as Engine, S as SarmalInstance, C as CurveDef, R as RendererOptions, P as Point, a as SarmalOptions } from './types-CknrlCAf.js';
2
- export { J as JumpOptions, b as RuntimeRenderOptions, c as SeekOptions, T as TrailColor, d as TrailStyle } from './types-CknrlCAf.js';
3
- export { CurveName, curves } from './curves/index.js';
4
- export { artemis2 } from './curves/artemis2.js';
5
- export { astroid } from './curves/astroid.js';
6
- export { deltoid } from './curves/deltoid.js';
7
- export { epicycloid3 } from './curves/epicycloid3.js';
8
- export { epitrochoid7 } from './curves/epitrochoid7.js';
9
- export { lame } from './curves/lame.js';
10
- export { lissajous32 } from './curves/lissajous32.js';
11
- export { lissajous43 } from './curves/lissajous43.js';
12
- export { rose3 } from './curves/rose3.js';
13
- export { rose5 } from './curves/rose5.js';
14
- import './curves/rose52.js';
15
- import './curves/star.js';
16
- import './curves/star4.js';
17
- import './curves/star7.js';
1
+ import {
2
+ B as BaseRendererOptions,
3
+ E as Engine,
4
+ S as SarmalInstance,
5
+ C as CurveDef,
6
+ P as Point,
7
+ R as RendererOptions,
8
+ a as ControlPoint,
9
+ b as SarmalOptions,
10
+ } from "./types-Z9i1_AQZ.js";
11
+ export {
12
+ J as JumpOptions,
13
+ c as RuntimeRenderOptions,
14
+ d as SeekOptions,
15
+ T as TrailColor,
16
+ e as TrailStyle,
17
+ } from "./types-Z9i1_AQZ.js";
18
+ export { CurveName, curves } from "./curves/index.js";
19
+ export { artemis2 } from "./curves/artemis2.js";
20
+ export { astroid } from "./curves/astroid.js";
21
+ export { deltoid } from "./curves/deltoid.js";
22
+ export { epicycloid3 } from "./curves/epicycloid3.js";
23
+ export { epitrochoid7 } from "./curves/epitrochoid7.js";
24
+ export { lame } from "./curves/lame.js";
25
+ export { lissajous32 } from "./curves/lissajous32.js";
26
+ export { lissajous43 } from "./curves/lissajous43.js";
27
+ export { rose3 } from "./curves/rose3.js";
28
+ export { rose5 } from "./curves/rose5.js";
29
+ import "./curves/rose52.js";
30
+ import "./curves/star.js";
31
+ import "./curves/star4.js";
32
+ import "./curves/star7.js";
18
33
 
19
34
  interface SVGRendererOptions extends BaseRendererOptions {
20
- /** SVG element the renderer draws into directly */
21
- container: SVGSVGElement;
22
- engine: Engine;
23
- /** @default 'Loading' */
24
- ariaLabel?: string;
35
+ /** SVG element the renderer draws into directly */
36
+ container: SVGSVGElement;
37
+ engine: Engine;
38
+ /** @default 'Loading' */
39
+ ariaLabel?: string;
25
40
  }
26
41
  interface SVGSarmalOptions extends Omit<SVGRendererOptions, "container" | "engine"> {
27
- /** @default 120 */
28
- trailLength?: number;
42
+ /** @default 120 */
43
+ trailLength?: number;
29
44
  }
30
45
  /**
31
46
  * Creates a live SVG renderer for sarmal animations
@@ -50,19 +65,43 @@ declare function createSVGRenderer(options: SVGRendererOptions): SarmalInstance;
50
65
  * controlled.pause() // Pause later
51
66
  * ```
52
67
  */
53
- declare function createSarmalSVG(container: SVGSVGElement, curveDef: CurveDef, options?: SVGSarmalOptions): SarmalInstance;
68
+ declare function createSarmalSVG(
69
+ container: SVGSVGElement,
70
+ curveDef: CurveDef,
71
+ options?: SVGSarmalOptions,
72
+ ): SarmalInstance;
54
73
 
74
+ interface BoundaryResult {
75
+ scale: number;
76
+ offsetX: number;
77
+ offsetY: number;
78
+ }
79
+ /**
80
+ * Computes how to map engine coordinates into a viewport of the given logical size.
81
+ * ! Returns `null` if `pts` is empty
82
+ * ! Throws if all points are identical
83
+ *
84
+ * Padding per side is `max(FIT_PADDING * dim, minPaddingPx)`, so the stricter constraint wins.
85
+ * `minPaddingPx` defaults to `FIT_PADDING_MIN` (4px) for pixel-space callers.
86
+ * Pass `0` when the logical space is itself a normalized viewBox (e.g. SVG export).
87
+ */
88
+ declare function computeBoundaries(
89
+ pts: Point[],
90
+ logicalWidth: number,
91
+ logicalHeight: number,
92
+ minPaddingPx?: number,
93
+ ): BoundaryResult | null;
55
94
  /**
56
95
  * Can be passed directly to `trailColor`,
57
96
  * or can be mixed/sliced before passing as a prop.
58
97
  */
59
98
  declare const palettes: {
60
- readonly bard: ["#a855f7", "#3b82f6", "#14b8a6", "#ec4899"];
61
- readonly sunset: ["#f97316", "#dc2626", "#9333ea", "#f472b6"];
62
- readonly ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"];
63
- readonly ice: ["#1e3a8a", "#67e8f9"];
64
- readonly fire: ["#7f1d1d", "#fbbf24"];
65
- readonly forest: ["#14532d", "#86efac"];
99
+ readonly bard: ["#a855f7", "#3b82f6", "#14b8a6", "#ec4899"];
100
+ readonly sunset: ["#f97316", "#dc2626", "#9333ea", "#f472b6"];
101
+ readonly ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"];
102
+ readonly ice: ["#1e3a8a", "#67e8f9"];
103
+ readonly fire: ["#7f1d1d", "#fbbf24"];
104
+ readonly forest: ["#14532d", "#86efac"];
66
105
  };
67
106
  type SarmalPalette = keyof typeof palettes;
68
107
 
@@ -86,7 +125,7 @@ declare function createRenderer(options: RendererOptions): SarmalInstance;
86
125
  * @param t Parametric position along the closed loop. Wraps into `[0, 2π)` automatically, so values outside that range are remapped rather than rejected
87
126
  * @returns The `(x, y)` position on the spline at time `t`
88
127
  */
89
- declare function evaluateCatmullRom(points: Array<[number, number]>, t: number): Point;
128
+ declare function evaluateCatmullRom(points: Array<ControlPoint>, t: number): Point;
90
129
  /**
91
130
  * The returned curve definition produces a closed Catmull-Rom spline that
92
131
  * passes through every point in order, looping back from the last point to the first.
@@ -94,8 +133,9 @@ declare function evaluateCatmullRom(points: Array<[number, number]>, t: number):
94
133
  * @param points Array of control points in **normalized `[−1, 1]` space**,
95
134
  * matching the playground's draw-mode coordinate system.
96
135
  * ! Must contain at least 3 points.
136
+ * @param opts Optional overrides for the returned `CurveDef`.
137
+ * @param opts.name Display name for the curve. Defaults to `"drawn"`.
97
138
  * @returns A `CurveDef` with `period: 2π` and the spline evaluator as its `fn`.
98
- * `name` is set to `"custom"`.
99
139
  * @throws If `points` has fewer than 3 entries.
100
140
  *
101
141
  * @example
@@ -111,7 +151,12 @@ declare function evaluateCatmullRom(points: Array<[number, number]>, t: number):
111
151
  * createSarmal(canvas, curve)
112
152
  * ```
113
153
  */
114
- declare function drawCurve(points: Array<[number, number]>): CurveDef;
154
+ declare function drawCurve(
155
+ points: Array<ControlPoint>,
156
+ opts?: {
157
+ name?: string;
158
+ },
159
+ ): CurveDef;
115
160
 
116
161
  /**
117
162
  * Creates a sarmal animation on a canvas element
@@ -127,6 +172,31 @@ declare function drawCurve(points: Array<[number, number]>): CurveDef;
127
172
  * controlled.pause() // Pause later
128
173
  * ```
129
174
  */
130
- declare function createSarmal(canvas: HTMLCanvasElement, curveDef: CurveDef, options?: SarmalOptions): SarmalInstance;
175
+ declare function createSarmal(
176
+ canvas: HTMLCanvasElement,
177
+ curveDef: CurveDef,
178
+ options?: SarmalOptions,
179
+ ): SarmalInstance;
131
180
 
132
- export { BaseRendererOptions, CurveDef, Engine, Point, RendererOptions, type SVGRendererOptions, type SVGSarmalOptions, SarmalInstance, SarmalOptions, type SarmalPalette, createEngine, createRenderer, createSVGRenderer, createSarmal, createSarmalSVG, drawCurve, evaluateCatmullRom, palettes };
181
+ export {
182
+ BaseRendererOptions,
183
+ type BoundaryResult,
184
+ CurveDef,
185
+ Engine,
186
+ Point,
187
+ RendererOptions,
188
+ type SVGRendererOptions,
189
+ type SVGSarmalOptions,
190
+ SarmalInstance,
191
+ SarmalOptions,
192
+ type SarmalPalette,
193
+ computeBoundaries,
194
+ createEngine,
195
+ createRenderer,
196
+ createSVGRenderer,
197
+ createSarmal,
198
+ createSarmalSVG,
199
+ drawCurve,
200
+ evaluateCatmullRom,
201
+ palettes,
202
+ };