@sarmal/core 0.25.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 +140 -105
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.js +139 -104
  4. package/dist/auto-init.js.map +1 -1
  5. package/dist/curves/artemis2.cjs +15 -10
  6. package/dist/curves/artemis2.cjs.map +1 -1
  7. package/dist/curves/artemis2.d.cts +1 -1
  8. package/dist/curves/artemis2.d.ts +1 -1
  9. package/dist/curves/artemis2.js +14 -9
  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 +58 -43
  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 +74 -43
  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 +126 -93
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts +92 -40
  72. package/dist/index.d.ts +92 -40
  73. package/dist/index.js +147 -93
  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-BZpzgNau.d.cts +0 -332
  79. package/dist/types-BZpzgNau.d.ts +0 -332
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  // src/engine.ts
4
4
  var TWO_PI = Math.PI * 2;
@@ -63,13 +63,13 @@ function resolveCurve(curveDef) {
63
63
  period,
64
64
  speed,
65
65
  skeleton: curveDef.skeleton,
66
- skeletonFn: curveDef.skeletonFn
66
+ skeletonFn: curveDef.skeletonFn,
67
67
  };
68
68
  }
69
69
  function createEngine(curveDef, trailLength = 120) {
70
70
  if (!Number.isFinite(trailLength) || trailLength <= 0) {
71
71
  throw new RangeError(
72
- `[sarmal] trailLength must be a positive finite number, got ${trailLength}`
72
+ `[sarmal] trailLength must be a positive finite number, got ${trailLength}`,
73
73
  );
74
74
  }
75
75
  let curve = resolveCurve(curveDef);
@@ -110,7 +110,7 @@ function createEngine(curveDef, trailLength = 120) {
110
110
  actualTime += deltaTime;
111
111
  if (morphCurveB !== null && _morphAlpha !== null) {
112
112
  const a = curve.fn(t, actualTime, EMPTY_PARAMS);
113
- const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
113
+ const tB = _morphStrategy === "normalized" ? (t / curve.period) * morphCurveB.period : t;
114
114
  const b = morphCurveB.fn(tB, actualTime, EMPTY_PARAMS);
115
115
  trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
116
116
  } else {
@@ -137,14 +137,14 @@ function createEngine(curveDef, trailLength = 120) {
137
137
  trail.clear();
138
138
  },
139
139
  jump(newT, { clearTrail = false } = {}) {
140
- t = (newT % curve.period + curve.period) % curve.period;
140
+ t = ((newT % curve.period) + curve.period) % curve.period;
141
141
  if (clearTrail) {
142
142
  trail.clear();
143
143
  }
144
144
  },
145
145
  seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
146
146
  const advance = curve.speed * step;
147
- const target = (targetT % curve.period + curve.period) % curve.period;
147
+ const target = ((targetT % curve.period) + curve.period) % curve.period;
148
148
  const targetTime = target / curve.speed;
149
149
  t = target;
150
150
  actualTime = targetTime;
@@ -153,7 +153,7 @@ function createEngine(curveDef, trailLength = 120) {
153
153
  const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
154
154
  for (let i = count - 1; i >= 0; i--) {
155
155
  const sampleT = target - i * advance;
156
- const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
156
+ const wrappedT = ((sampleT % curve.period) + curve.period) % curve.period;
157
157
  const time = targetTime - i * step;
158
158
  const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
159
159
  trail.push(point.x, point.y);
@@ -170,13 +170,16 @@ function createEngine(curveDef, trailLength = 120) {
170
170
  ...frozenB,
171
171
  fn: (sampleT, time, params) => {
172
172
  const a = frozenA.fn(sampleT, time, params);
173
- const tB = frozenStrategy === "normalized" ? sampleT / frozenA.period * frozenB.period : sampleT;
173
+ const tB =
174
+ frozenStrategy === "normalized"
175
+ ? (sampleT / frozenA.period) * frozenB.period
176
+ : sampleT;
174
177
  const b = frozenB.fn(tB, time, params);
175
178
  return {
176
179
  x: a.x + (b.x - a.x) * frozenAlpha,
177
- y: a.y + (b.y - a.y) * frozenAlpha
180
+ y: a.y + (b.y - a.y) * frozenAlpha,
178
181
  };
179
- }
182
+ },
180
183
  };
181
184
  }
182
185
  _morphStrategy = strategy;
@@ -189,7 +192,7 @@ function createEngine(curveDef, trailLength = 120) {
189
192
  completeMorph() {
190
193
  if (morphCurveB !== null) {
191
194
  if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
192
- t = t / curve.period * morphCurveB.period;
195
+ t = (t / curve.period) * morphCurveB.period;
193
196
  }
194
197
  curve = morphCurveB;
195
198
  }
@@ -201,19 +204,22 @@ function createEngine(curveDef, trailLength = 120) {
201
204
  const points2 = new Array(steps);
202
205
  if (morphCurveB !== null && _morphAlpha !== null) {
203
206
  for (let i = 0; i < steps; i++) {
204
- const sampleT = i / (steps - 1) * curve.period;
207
+ const sampleT = (i / (steps - 1)) * curve.period;
205
208
  const a = sampleSkeleton(curve, sampleT);
206
- const tB = _morphStrategy === "normalized" ? sampleT / curve.period * morphCurveB.period : sampleT;
209
+ const tB =
210
+ _morphStrategy === "normalized"
211
+ ? (sampleT / curve.period) * morphCurveB.period
212
+ : sampleT;
207
213
  const b = sampleSkeleton(morphCurveB, tB);
208
214
  points2[i] = {
209
215
  x: a.x + (b.x - a.x) * _morphAlpha,
210
- y: a.y + (b.y - a.y) * _morphAlpha
216
+ y: a.y + (b.y - a.y) * _morphAlpha,
211
217
  };
212
218
  }
213
219
  return points2;
214
220
  }
215
221
  for (let i = 0; i < steps; i++) {
216
- const sampleT = i / (steps - 1) * curve.period;
222
+ const sampleT = (i / (steps - 1)) * curve.period;
217
223
  points2[i] = sampleSkeleton(curve, sampleT);
218
224
  }
219
225
  return points2;
@@ -255,7 +261,7 @@ function createEngine(curveDef, trailLength = 120) {
255
261
  _speedTransition.reject(new Error("Speed transition cancelled"));
256
262
  _speedTransition = null;
257
263
  }
258
- }
264
+ },
259
265
  };
260
266
  }
261
267
 
@@ -294,7 +300,15 @@ function computeNormal(trail, i) {
294
300
  const tangent = computeTangent(trail, i);
295
301
  return { x: -tangent.y, y: tangent.x };
296
302
  }
297
- function computeTrailQuad(trail, i, trailCount, toX, toY, minWidth = TRAIL_MIN_WIDTH, maxWidth = TRAIL_MAX_WIDTH) {
303
+ function computeTrailQuad(
304
+ trail,
305
+ i,
306
+ trailCount,
307
+ toX,
308
+ toY,
309
+ minWidth = TRAIL_MIN_WIDTH,
310
+ maxWidth = TRAIL_MAX_WIDTH,
311
+ ) {
298
312
  const progress = i / (trailCount - 1);
299
313
  const nextProgress = (i + 1) / (trailCount - 1);
300
314
  const opacity = Math.pow(progress, TRAIL_FADE_CURVE) * TRAIL_MAX_OPACITY;
@@ -318,13 +332,16 @@ function computeTrailQuad(trail, i, trailCount, toX, toY, minWidth = TRAIL_MIN_W
318
332
  r1x: nx - n1.x * w1,
319
333
  r1y: ny - n1.y * w1,
320
334
  opacity,
321
- progress
335
+ progress,
322
336
  };
323
337
  }
324
338
  function computeBoundaries(pts, logicalWidth, logicalHeight, minPaddingPx = FIT_PADDING_MIN) {
325
339
  if (pts.length === 0) return null;
326
340
  const first = pts[0];
327
- let minX = first.x, maxX = first.x, minY = first.y, maxY = first.y;
341
+ let minX = first.x,
342
+ maxX = first.x,
343
+ minY = first.y,
344
+ maxY = first.y;
328
345
  for (const p of pts) {
329
346
  if (p.x < minX) {
330
347
  minX = p.x;
@@ -343,7 +360,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight, minPaddingPx = FIT_
343
360
  const h = maxY - minY;
344
361
  if (w === 0 && h === 0) {
345
362
  throw new Error(
346
- "[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
363
+ "[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t.",
347
364
  );
348
365
  }
349
366
  const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
@@ -354,12 +371,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight, minPaddingPx = FIT_
354
371
  scaleXProportional,
355
372
  scaleYProportional,
356
373
  scaleXMinPadding,
357
- scaleYMinPadding
374
+ scaleYMinPadding,
358
375
  );
359
376
  return {
360
377
  scale,
361
378
  offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
362
- offsetY: (logicalHeight - h * scale) / 2 - minY * scale
379
+ offsetY: (logicalHeight - h * scale) / 2 - minY * scale,
363
380
  };
364
381
  }
365
382
  function enginePassthroughs(engine) {
@@ -370,17 +387,17 @@ function enginePassthroughs(engine) {
370
387
  getSpeed: engine.getSpeed,
371
388
  resetSpeed: engine.resetSpeed,
372
389
  setSpeedOver: engine.setSpeedOver,
373
- getSarmalSkeleton: engine.getSarmalSkeleton
390
+ getSarmalSkeleton: engine.getSarmalSkeleton,
374
391
  };
375
392
  }
376
393
  function hexToRgb(hex) {
377
394
  const n = parseInt(hex.slice(1), 16);
378
- return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
395
+ return { r: n >> 16, g: (n >> 8) & 255, b: n & 255 };
379
396
  }
380
397
  var lerpRgb = (a, b, t) => ({
381
398
  r: Math.round(a.r + (b.r - a.r) * t),
382
399
  g: Math.round(a.g + (b.g - a.g) * t),
383
- b: Math.round(a.b + (b.b - a.b) * t)
400
+ b: Math.round(a.b + (b.b - a.b) * t),
384
401
  });
385
402
  function getPaletteColor(palette, position, timeOffset = 0) {
386
403
  if (palette.length === 0) {
@@ -389,7 +406,7 @@ function getPaletteColor(palette, position, timeOffset = 0) {
389
406
  if (palette.length === 1) {
390
407
  return hexToRgb(palette[0]);
391
408
  }
392
- const cyclePos = ((position + timeOffset) % 1 + 1) % 1;
409
+ const cyclePos = (((position + timeOffset) % 1) + 1) % 1;
393
410
  const scaled = cyclePos * palette.length;
394
411
  const idx = Math.floor(scaled);
395
412
  const t = scaled - idx;
@@ -404,7 +421,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
404
421
  "headColor",
405
422
  "skeletonColor",
406
423
  "trailStyle",
407
- "headRadius"
424
+ "headRadius",
408
425
  ]);
409
426
  function validateRenderOptions(partial) {
410
427
  for (const key of Object.keys(partial)) {
@@ -432,7 +449,7 @@ function assertTrailColor(value) {
432
449
  if (typeof value === "string") {
433
450
  if (!HEX_COLOR_RE.test(value)) {
434
451
  throw new TypeError(
435
- `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`
452
+ `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`,
436
453
  );
437
454
  }
438
455
  return;
@@ -440,21 +457,21 @@ function assertTrailColor(value) {
440
457
  if (Array.isArray(value)) {
441
458
  if (value.length < 2) {
442
459
  throw new RangeError(
443
- `[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`
460
+ `[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`,
444
461
  );
445
462
  }
446
463
  for (let i = 0; i < value.length; i++) {
447
464
  const entry = value[i];
448
465
  if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
449
466
  throw new TypeError(
450
- `[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`
467
+ `[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`,
451
468
  );
452
469
  }
453
470
  }
454
471
  return;
455
472
  }
456
473
  throw new TypeError(
457
- `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`
474
+ `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`,
458
475
  );
459
476
  }
460
477
  function assertHeadColor(value) {
@@ -463,7 +480,7 @@ function assertHeadColor(value) {
463
480
  }
464
481
  if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
465
482
  throw new TypeError(
466
- `[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`
483
+ `[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`,
467
484
  );
468
485
  }
469
486
  }
@@ -473,26 +490,26 @@ function assertSkeletonColor(value) {
473
490
  }
474
491
  if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
475
492
  throw new TypeError(
476
- `[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`
493
+ `[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`,
477
494
  );
478
495
  }
479
496
  }
480
497
  function assertTrailStyle(value) {
481
498
  if (!TRAIL_STYLES.includes(value)) {
482
499
  throw new RangeError(
483
- `[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`
500
+ `[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`,
484
501
  );
485
502
  }
486
503
  }
487
504
  function assertHeadRadius(value) {
488
505
  if (typeof value !== "number") {
489
506
  throw new TypeError(
490
- `[sarmal] setRenderOptions: headRadius must be a number, got ${JSON.stringify(value)}`
507
+ `[sarmal] setRenderOptions: headRadius must be a number, got ${JSON.stringify(value)}`,
491
508
  );
492
509
  }
493
510
  if (!Number.isFinite(value) || value <= 0) {
494
511
  throw new TypeError(
495
- `[sarmal] setRenderOptions: headRadius must be a finite positive number, got ${value}`
512
+ `[sarmal] setRenderOptions: headRadius must be a finite positive number, got ${value}`,
496
513
  );
497
514
  }
498
515
  }
@@ -514,13 +531,13 @@ function resolveHeadColor(trailColor, trailStyle) {
514
531
  function warnIfTrailColorMismatch(trailColor, trailStyle) {
515
532
  if (trailStyle === "default" && Array.isArray(trailColor)) {
516
533
  console.warn(
517
- '[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.'
534
+ '[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.',
518
535
  );
519
536
  return;
520
537
  }
521
538
  if (trailStyle !== "default" && typeof trailColor === "string") {
522
539
  console.warn(
523
- `[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient.`
540
+ `[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient.`,
524
541
  );
525
542
  }
526
543
  }
@@ -530,7 +547,7 @@ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160)
530
547
  var WHITE_HEX = "#ffffff";
531
548
  function hexToRgbComponents(hex) {
532
549
  const n = parseInt(hex.slice(1), 16);
533
- return `${n >> 16},${n >> 8 & 255},${n & 255}`;
550
+ return `${n >> 16},${(n >> 8) & 255},${n & 255}`;
534
551
  }
535
552
  function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
536
553
  target.style.width = `${logicalWidth}px`;
@@ -657,7 +674,7 @@ function createRenderer(options) {
657
674
  i,
658
675
  trailCount,
659
676
  toX,
660
- toY
677
+ toY,
661
678
  );
662
679
  if (trailStyle === "default") {
663
680
  ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
@@ -822,7 +839,7 @@ function createRenderer(options) {
822
839
  if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
823
840
  warnIfTrailColorMismatch(trailColor, trailStyle);
824
841
  }
825
- }
842
+ },
826
843
  };
827
844
  const pauseOnHidden = options.pauseOnHidden !== false;
828
845
  function handleVisibilityChange() {
@@ -872,7 +889,7 @@ function sampleCurveSkeleton(curveDef) {
872
889
  const samples = Math.ceil(period * 50);
873
890
  const pts = Array.from({ length: samples });
874
891
  for (let i = 0; i < samples; i++) {
875
- const t = i / (samples - 1) * period;
892
+ const t = (i / (samples - 1)) * period;
876
893
  pts[i] = curveDef.skeletonFn ? curveDef.skeletonFn(t) : curveDef.fn(t, 0, EMPTY_PARAMS2);
877
894
  }
878
895
  return pts;
@@ -885,7 +902,7 @@ function createSVGRenderer(options) {
885
902
  const poolSize = engine.trailLength;
886
903
  if (poolSize > HIGH_TRAIL_LENGTH_THRESHOLD) {
887
904
  console.warn(
888
- `[sarmal] High trailLength in SVG renderer (${poolSize}). Consider using the canvas renderer for long trails.`
905
+ `[sarmal] High trailLength in SVG renderer (${poolSize}). Consider using the canvas renderer for long trails.`,
889
906
  );
890
907
  }
891
908
  let trailStyle = options.trailStyle ?? "default";
@@ -904,9 +921,9 @@ function createSVGRenderer(options) {
904
921
  return rect.width && rect.height ? Math.min(rect.width, rect.height) : 200;
905
922
  }
906
923
  const containerPx = getContainerPixelSize();
907
- const svgTrailMinWidth = TRAIL_MIN_WIDTH * viewSize / containerPx;
908
- const svgTrailMaxWidth = TRAIL_MAX_WIDTH * viewSize / containerPx;
909
- const svgSkeletonStrokeWidth = String(SKELETON_STROKE_WIDTH_PX * viewSize / containerPx);
924
+ const svgTrailMinWidth = (TRAIL_MIN_WIDTH * viewSize) / containerPx;
925
+ const svgTrailMaxWidth = (TRAIL_MAX_WIDTH * viewSize) / containerPx;
926
+ const svgSkeletonStrokeWidth = String((SKELETON_STROKE_WIDTH_PX * viewSize) / containerPx);
910
927
  headRadius = options.headRadius ?? SVG_DEFAULT_HEAD_RADIUS;
911
928
  container.setAttribute("viewBox", `0 0 ${viewSize} ${viewSize}`);
912
929
  container.setAttribute("role", "img");
@@ -994,7 +1011,7 @@ function createSVGRenderer(options) {
994
1011
  px,
995
1012
  py,
996
1013
  svgTrailMinWidth,
997
- svgTrailMaxWidth
1014
+ svgTrailMaxWidth,
998
1015
  );
999
1016
  const d = `M${l0x.toFixed(2)} ${l0y.toFixed(2)} L${l1x.toFixed(2)} ${l1y.toFixed(2)} L${r1x.toFixed(2)} ${r1y.toFixed(2)} L${r0x.toFixed(2)} ${r0y.toFixed(2)} Z`;
1000
1017
  trailPaths[i].setAttribute("d", d);
@@ -1022,7 +1039,8 @@ function createSVGRenderer(options) {
1022
1039
  let animationId = null;
1023
1040
  let lastTime = 0;
1024
1041
  let pausedByVisibility = false;
1025
- const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1042
+ const prefersReducedMotion =
1043
+ typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1026
1044
  let morphResolve = null;
1027
1045
  let morphReject = null;
1028
1046
  let morphDurationMs = DEFAULT_MORPH_DURATION_MS;
@@ -1040,7 +1058,7 @@ function createSVGRenderer(options) {
1040
1058
  skeletonPathA.setAttribute("visibility", "visible");
1041
1059
  skeletonPathA.setAttribute(
1042
1060
  "stroke-opacity",
1043
- String((1 - morphAlpha) * DEFAULT_SKELETON_OPACITY)
1061
+ String((1 - morphAlpha) * DEFAULT_SKELETON_OPACITY),
1044
1062
  );
1045
1063
  }
1046
1064
  if (morphPathBBuilt) {
@@ -1194,7 +1212,7 @@ function createSVGRenderer(options) {
1194
1212
  if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
1195
1213
  warnIfTrailColorMismatch(trailColor, trailStyle);
1196
1214
  }
1197
- }
1215
+ },
1198
1216
  };
1199
1217
  const pauseOnHidden = options.pauseOnHidden !== false;
1200
1218
  function handleVisibilityChange() {
@@ -1232,7 +1250,13 @@ var PERIOD = 2 * Math.PI;
1232
1250
  function catmullRom1D(p0, p1, p2, p3, u) {
1233
1251
  const u2 = u * u;
1234
1252
  const u3 = u2 * u;
1235
- return 0.5 * (2 * p1 + (-p0 + p2) * u + (2 * p0 - 5 * p1 + 4 * p2 - p3) * u2 + (-p0 + 3 * p1 - 3 * p2 + p3) * u3);
1253
+ return (
1254
+ 0.5 *
1255
+ (2 * p1 +
1256
+ (-p0 + p2) * u +
1257
+ (2 * p0 - 5 * p1 + 4 * p2 - p3) * u2 +
1258
+ (-p0 + 3 * p1 - 3 * p2 + p3) * u3)
1259
+ );
1236
1260
  }
1237
1261
  function evaluateCatmullRom(points2, t) {
1238
1262
  const N = points2.length;
@@ -1242,7 +1266,7 @@ function evaluateCatmullRom(points2, t) {
1242
1266
  if (N === 1) {
1243
1267
  return { x: points2[0][0], y: points2[0][1] };
1244
1268
  }
1245
- t = (t % PERIOD + PERIOD) % PERIOD;
1269
+ t = ((t % PERIOD) + PERIOD) % PERIOD;
1246
1270
  const segmentSize = PERIOD / N;
1247
1271
  let i = Math.floor(t / segmentSize);
1248
1272
  if (i >= N) {
@@ -1256,7 +1280,7 @@ function evaluateCatmullRom(points2, t) {
1256
1280
  const p3 = points2[(i + 2) % N];
1257
1281
  return {
1258
1282
  x: catmullRom1D(p0[0], p1[0], p2[0], p3[0], u),
1259
- y: catmullRom1D(p0[1], p1[1], p2[1], p3[1], u)
1283
+ y: catmullRom1D(p0[1], p1[1], p2[1], p3[1], u),
1260
1284
  };
1261
1285
  }
1262
1286
  function drawCurve(points2, opts) {
@@ -1266,13 +1290,13 @@ function drawCurve(points2, opts) {
1266
1290
  const first = points2[0];
1267
1291
  if (points2.every((p) => p[0] === first[0] && p[1] === first[1])) {
1268
1292
  console.warn(
1269
- "[sarmal].drawCurve: all control points are identical. The curve will be a single point."
1293
+ "[sarmal].drawCurve: all control points are identical. The curve will be a single point.",
1270
1294
  );
1271
1295
  }
1272
1296
  const maxAbs = points2.reduce((m, p) => Math.max(m, Math.abs(p[0]), Math.abs(p[1])), 0);
1273
1297
  if (maxAbs > 2) {
1274
1298
  console.warn(
1275
- `[sarmal].drawCurve: control points extend to \xB1${maxAbs.toFixed(1)}, which may render off-screen. Coordinates should be in [-1, 1].`
1299
+ `[sarmal].drawCurve: control points extend to \xB1${maxAbs.toFixed(1)}, which may render off-screen. Coordinates should be in [-1, 1].`,
1276
1300
  );
1277
1301
  }
1278
1302
  const pts = points2.map(([x, y]) => [x, y]);
@@ -1280,7 +1304,6 @@ function drawCurve(points2, opts) {
1280
1304
  name: opts?.name ?? "drawn",
1281
1305
  fn: (t) => evaluateCatmullRom(pts, t),
1282
1306
  period: PERIOD,
1283
- kind: "drawn"
1284
1307
  };
1285
1308
  }
1286
1309
 
@@ -1306,11 +1329,11 @@ var points = [
1306
1329
  [-0.69, -0.84],
1307
1330
  [-0.87, -0.66],
1308
1331
  [-0.9, -0.47],
1309
- [-0.76, -0.35]
1332
+ [-0.76, -0.35],
1310
1333
  ];
1311
1334
  var artemis2 = {
1312
1335
  ...drawCurve(points, { name: "Artemis II" }),
1313
- speed: 0.7
1336
+ speed: 0.7,
1314
1337
  };
1315
1338
 
1316
1339
  // src/curves/astroid.ts
@@ -1320,14 +1343,14 @@ function astroidFn(t, _time, _params) {
1320
1343
  const s = Math.sin(t);
1321
1344
  return {
1322
1345
  x: c * c * c,
1323
- y: s * s * s
1346
+ y: s * s * s,
1324
1347
  };
1325
1348
  }
1326
1349
  var astroid = {
1327
1350
  name: "Astroid",
1328
1351
  fn: astroidFn,
1329
1352
  period: TWO_PI2,
1330
- speed: 1.1
1353
+ speed: 1.1,
1331
1354
  };
1332
1355
 
1333
1356
  // src/curves/deltoid.ts
@@ -1335,14 +1358,14 @@ var TWO_PI3 = Math.PI * 2;
1335
1358
  function deltoidFn(t, _time, _params) {
1336
1359
  return {
1337
1360
  x: 2 * Math.cos(t) + Math.cos(2 * t),
1338
- y: 2 * Math.sin(t) - Math.sin(2 * t)
1361
+ y: 2 * Math.sin(t) - Math.sin(2 * t),
1339
1362
  };
1340
1363
  }
1341
1364
  var deltoid = {
1342
1365
  name: "Deltoid",
1343
1366
  fn: deltoidFn,
1344
1367
  period: TWO_PI3,
1345
- speed: 0.9
1368
+ speed: 0.9,
1346
1369
  };
1347
1370
 
1348
1371
  // src/curves/epicycloid3.ts
@@ -1350,14 +1373,14 @@ var TWO_PI4 = Math.PI * 2;
1350
1373
  function epicycloid3Fn(t, _time, _params) {
1351
1374
  return {
1352
1375
  x: 4 * Math.cos(t) - Math.cos(4 * t),
1353
- y: 4 * Math.sin(t) - Math.sin(4 * t)
1376
+ y: 4 * Math.sin(t) - Math.sin(4 * t),
1354
1377
  };
1355
1378
  }
1356
1379
  var epicycloid3 = {
1357
1380
  name: "Epicycloid (n=3)",
1358
1381
  fn: epicycloid3Fn,
1359
1382
  period: TWO_PI4,
1360
- speed: 0.75
1383
+ speed: 0.75,
1361
1384
  };
1362
1385
 
1363
1386
  // src/curves/epitrochoid7.ts
@@ -1366,14 +1389,14 @@ function epitrochoid7Fn(t, _time, _params) {
1366
1389
  const d = 1 + 0.55 * Math.sin(t * 0.5);
1367
1390
  return {
1368
1391
  x: 7 * Math.cos(t) - d * Math.cos(7 * t),
1369
- y: 7 * Math.sin(t) - d * Math.sin(7 * t)
1392
+ y: 7 * Math.sin(t) - d * Math.sin(7 * t),
1370
1393
  };
1371
1394
  }
1372
1395
  function epitrochoid7SkeletonFn(t) {
1373
1396
  const d = 1.275;
1374
1397
  return {
1375
1398
  x: 7 * Math.cos(t) - d * Math.cos(7 * t),
1376
- y: 7 * Math.sin(t) - d * Math.sin(7 * t)
1399
+ y: 7 * Math.sin(t) - d * Math.sin(7 * t),
1377
1400
  };
1378
1401
  }
1379
1402
  var epitrochoid7 = {
@@ -1381,7 +1404,7 @@ var epitrochoid7 = {
1381
1404
  fn: epitrochoid7Fn,
1382
1405
  period: TWO_PI5,
1383
1406
  speed: 1.4,
1384
- skeletonFn: epitrochoid7SkeletonFn
1407
+ skeletonFn: epitrochoid7SkeletonFn,
1385
1408
  };
1386
1409
 
1387
1410
  // src/curves/lissajous32.ts
@@ -1390,7 +1413,7 @@ function lissajous32Fn(t, time, _params) {
1390
1413
  const phi = time * 0.45;
1391
1414
  return {
1392
1415
  x: Math.sin(3 * t + phi),
1393
- y: Math.sin(2 * t)
1416
+ y: Math.sin(2 * t),
1394
1417
  };
1395
1418
  }
1396
1419
  var lissajous32 = {
@@ -1398,7 +1421,7 @@ var lissajous32 = {
1398
1421
  fn: lissajous32Fn,
1399
1422
  period: TWO_PI6,
1400
1423
  speed: 2,
1401
- skeleton: "live"
1424
+ skeleton: "live",
1402
1425
  };
1403
1426
 
1404
1427
  // src/curves/lissajous43.ts
@@ -1407,7 +1430,7 @@ function lissajous43Fn(t, time, _params) {
1407
1430
  const phi = time * 0.38;
1408
1431
  return {
1409
1432
  x: Math.sin(4 * t + phi),
1410
- y: Math.sin(3 * t)
1433
+ y: Math.sin(3 * t),
1411
1434
  };
1412
1435
  }
1413
1436
  var lissajous43 = {
@@ -1415,17 +1438,18 @@ var lissajous43 = {
1415
1438
  fn: lissajous43Fn,
1416
1439
  period: TWO_PI7,
1417
1440
  speed: 1.8,
1418
- skeleton: "live"
1441
+ skeleton: "live",
1419
1442
  };
1420
1443
 
1421
1444
  // src/curves/lame.ts
1422
1445
  var TWO_PI8 = Math.PI * 2;
1423
1446
  function lameFn(t, time, _params) {
1424
1447
  const p = 1.75 + 1.25 * Math.sin(time * 0.48);
1425
- const c = Math.cos(t), s = Math.sin(t);
1448
+ const c = Math.cos(t),
1449
+ s = Math.sin(t);
1426
1450
  return {
1427
1451
  x: Math.sign(c) * Math.pow(Math.abs(c), p),
1428
- y: Math.sign(s) * Math.pow(Math.abs(s), p)
1452
+ y: Math.sign(s) * Math.pow(Math.abs(s), p),
1429
1453
  };
1430
1454
  }
1431
1455
  var lame = {
@@ -1433,7 +1457,7 @@ var lame = {
1433
1457
  fn: lameFn,
1434
1458
  period: TWO_PI8,
1435
1459
  speed: 1,
1436
- skeleton: "live"
1460
+ skeleton: "live",
1437
1461
  };
1438
1462
 
1439
1463
  // src/curves/rose3.ts
@@ -1442,14 +1466,14 @@ function rose3Fn(t, _time, _params) {
1442
1466
  const r = Math.cos(3 * t);
1443
1467
  return {
1444
1468
  x: r * Math.cos(t),
1445
- y: r * Math.sin(t)
1469
+ y: r * Math.sin(t),
1446
1470
  };
1447
1471
  }
1448
1472
  var rose3 = {
1449
1473
  name: "Rose (n=3)",
1450
1474
  fn: rose3Fn,
1451
1475
  period: TWO_PI9,
1452
- speed: 1.15
1476
+ speed: 1.15,
1453
1477
  };
1454
1478
 
1455
1479
  // src/curves/rose5.ts
@@ -1458,78 +1482,87 @@ function rose5Fn(t, _time, _params) {
1458
1482
  const r = Math.cos(5 * t);
1459
1483
  return {
1460
1484
  x: r * Math.cos(t),
1461
- y: r * Math.sin(t)
1485
+ y: r * Math.sin(t),
1462
1486
  };
1463
1487
  }
1464
1488
  var rose5 = {
1465
1489
  name: "Rose (n=5)",
1466
1490
  fn: rose5Fn,
1467
1491
  period: TWO_PI10,
1468
- speed: 1
1492
+ speed: 1,
1469
1493
  };
1470
1494
 
1471
1495
  // src/curves/rose52.ts
1472
1496
  var FOUR_PI = Math.PI * 4;
1473
1497
  function rose52Fn(t, _time, _params) {
1474
- const r = Math.cos(5 / 2 * t);
1498
+ const r = Math.cos((5 / 2) * t);
1475
1499
  return {
1476
1500
  x: r * Math.cos(t),
1477
- y: r * Math.sin(t)
1501
+ y: r * Math.sin(t),
1478
1502
  };
1479
1503
  }
1480
1504
  var rose52 = {
1481
1505
  name: "Rose (n=5/2)",
1482
1506
  fn: rose52Fn,
1483
1507
  period: FOUR_PI,
1484
- speed: 0.8
1508
+ speed: 0.8,
1485
1509
  };
1486
1510
 
1487
1511
  // src/curves/star.ts
1488
1512
  var TWO_PI11 = Math.PI * 2;
1489
1513
  function starFn(t, _time, _params) {
1490
- const r = Math.abs(Math.cos(5 / 2 * t)) + 0.35 * Math.abs(Math.cos(15 / 2 * t)) + 0.15 * Math.abs(Math.cos(25 / 2 * t));
1514
+ const r =
1515
+ Math.abs(Math.cos((5 / 2) * t)) +
1516
+ 0.35 * Math.abs(Math.cos((15 / 2) * t)) +
1517
+ 0.15 * Math.abs(Math.cos((25 / 2) * t));
1491
1518
  return {
1492
1519
  x: r * Math.cos(t),
1493
- y: r * Math.sin(t)
1520
+ y: r * Math.sin(t),
1494
1521
  };
1495
1522
  }
1496
1523
  var star = {
1497
1524
  name: "Star",
1498
1525
  fn: starFn,
1499
1526
  period: TWO_PI11,
1500
- speed: 1
1527
+ speed: 1,
1501
1528
  };
1502
1529
 
1503
1530
  // src/curves/star4.ts
1504
1531
  var TWO_PI12 = Math.PI * 2;
1505
1532
  function star4Fn(t, _time, _params) {
1506
- const r = Math.abs(Math.cos(2 * t)) + 0.35 * Math.abs(Math.cos(6 * t)) + 0.15 * Math.abs(Math.cos(10 * t));
1533
+ const r =
1534
+ Math.abs(Math.cos(2 * t)) +
1535
+ 0.35 * Math.abs(Math.cos(6 * t)) +
1536
+ 0.15 * Math.abs(Math.cos(10 * t));
1507
1537
  return {
1508
1538
  x: r * Math.cos(t),
1509
- y: r * Math.sin(t)
1539
+ y: r * Math.sin(t),
1510
1540
  };
1511
1541
  }
1512
1542
  var star4 = {
1513
1543
  name: "Star (4-arm)",
1514
1544
  fn: star4Fn,
1515
1545
  period: TWO_PI12,
1516
- speed: 1
1546
+ speed: 1,
1517
1547
  };
1518
1548
 
1519
1549
  // src/curves/star7.ts
1520
1550
  var TWO_PI13 = Math.PI * 2;
1521
1551
  function star7Fn(t, _time, _params) {
1522
- const r = Math.abs(Math.cos(7 / 2 * t)) + 0.35 * Math.abs(Math.cos(21 / 2 * t)) + 0.15 * Math.abs(Math.cos(35 / 2 * t));
1552
+ const r =
1553
+ Math.abs(Math.cos((7 / 2) * t)) +
1554
+ 0.35 * Math.abs(Math.cos((21 / 2) * t)) +
1555
+ 0.15 * Math.abs(Math.cos((35 / 2) * t));
1523
1556
  return {
1524
1557
  x: r * Math.cos(t),
1525
- y: r * Math.sin(t)
1558
+ y: r * Math.sin(t),
1526
1559
  };
1527
1560
  }
1528
1561
  var star7 = {
1529
1562
  name: "Star (7-arm)",
1530
1563
  fn: star7Fn,
1531
1564
  period: TWO_PI13,
1532
- speed: 1
1565
+ speed: 1,
1533
1566
  };
1534
1567
 
1535
1568
  // src/curves/index.ts
@@ -1547,7 +1580,7 @@ var curves = {
1547
1580
  lissajous32,
1548
1581
  lissajous43,
1549
1582
  epicycloid3,
1550
- lame
1583
+ lame,
1551
1584
  };
1552
1585
 
1553
1586
  // src/index.ts
@@ -1564,22 +1597,21 @@ function parseTrailColor(value) {
1564
1597
  if (Array.isArray(parsed)) {
1565
1598
  return parsed;
1566
1599
  }
1567
- } catch {
1568
- }
1600
+ } catch {}
1569
1601
  return value;
1570
1602
  }
1571
1603
  function buildOptions(el2) {
1572
1604
  return {
1573
- ...el2.dataset.trailColor && {
1574
- trailColor: parseTrailColor(el2.dataset.trailColor)
1575
- },
1576
- ...el2.dataset.skeletonColor && { skeletonColor: el2.dataset.skeletonColor },
1577
- ...el2.dataset.headColor && { headColor: el2.dataset.headColor },
1578
- ...el2.dataset.headRadius && { headRadius: parseFloat(el2.dataset.headRadius) },
1579
- ...el2.dataset.trailLength && { trailLength: parseInt(el2.dataset.trailLength, 10) },
1580
- ...el2.dataset.trailStyle && {
1581
- trailStyle: el2.dataset.trailStyle
1582
- }
1605
+ ...(el2.dataset.trailColor && {
1606
+ trailColor: parseTrailColor(el2.dataset.trailColor),
1607
+ }),
1608
+ ...(el2.dataset.skeletonColor && { skeletonColor: el2.dataset.skeletonColor }),
1609
+ ...(el2.dataset.headColor && { headColor: el2.dataset.headColor }),
1610
+ ...(el2.dataset.headRadius && { headRadius: parseFloat(el2.dataset.headRadius) }),
1611
+ ...(el2.dataset.trailLength && { trailLength: parseInt(el2.dataset.trailLength, 10) }),
1612
+ ...(el2.dataset.trailStyle && {
1613
+ trailStyle: el2.dataset.trailStyle,
1614
+ }),
1583
1615
  };
1584
1616
  }
1585
1617
  function init() {
@@ -1594,7 +1626,10 @@ function init() {
1594
1626
  return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
1595
1627
  }
1596
1628
  const options = buildOptions(el2);
1597
- const instance = el2 instanceof HTMLCanvasElement ? createSarmal(el2, curveDef, options) : createSarmalSVG(el2, curveDef, options);
1629
+ const instance =
1630
+ el2 instanceof HTMLCanvasElement
1631
+ ? createSarmal(el2, curveDef, options)
1632
+ : createSarmalSVG(el2, curveDef, options);
1598
1633
  if (el2.dataset.speed) {
1599
1634
  instance.setSpeed(parseFloat(el2.dataset.speed));
1600
1635
  }
@@ -1610,4 +1645,4 @@ if (document.readyState === "loading") {
1610
1645
 
1611
1646
  exports.init = init;
1612
1647
  //# sourceMappingURL=auto-init.cjs.map
1613
- //# sourceMappingURL=auto-init.cjs.map
1648
+ //# sourceMappingURL=auto-init.cjs.map