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