@sarmal/core 0.15.0 → 0.15.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 (59) hide show
  1. package/dist/auto-init.cjs +86 -94
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.d.cts +3 -1
  4. package/dist/auto-init.d.ts +3 -1
  5. package/dist/auto-init.js +85 -93
  6. package/dist/auto-init.js.map +1 -1
  7. package/dist/curves/artemis2.cjs +7 -10
  8. package/dist/curves/artemis2.d.cts +1 -1
  9. package/dist/curves/artemis2.d.ts +1 -1
  10. package/dist/curves/artemis2.js +6 -9
  11. package/dist/curves/astroid.cjs +4 -4
  12. package/dist/curves/astroid.d.cts +1 -1
  13. package/dist/curves/astroid.d.ts +1 -1
  14. package/dist/curves/astroid.js +3 -3
  15. package/dist/curves/deltoid.cjs +4 -4
  16. package/dist/curves/deltoid.d.cts +1 -1
  17. package/dist/curves/deltoid.d.ts +1 -1
  18. package/dist/curves/deltoid.js +3 -3
  19. package/dist/curves/epicycloid3.cjs +4 -4
  20. package/dist/curves/epicycloid3.d.cts +1 -1
  21. package/dist/curves/epicycloid3.d.ts +1 -1
  22. package/dist/curves/epicycloid3.js +3 -3
  23. package/dist/curves/epitrochoid7.cjs +5 -5
  24. package/dist/curves/epitrochoid7.d.cts +1 -1
  25. package/dist/curves/epitrochoid7.d.ts +1 -1
  26. package/dist/curves/epitrochoid7.js +4 -4
  27. package/dist/curves/index.cjs +28 -32
  28. package/dist/curves/index.d.cts +21 -21
  29. package/dist/curves/index.d.ts +21 -21
  30. package/dist/curves/index.js +28 -44
  31. package/dist/curves/lame.cjs +5 -6
  32. package/dist/curves/lame.d.cts +1 -1
  33. package/dist/curves/lame.d.ts +1 -1
  34. package/dist/curves/lame.js +4 -5
  35. package/dist/curves/lissajous32.cjs +4 -4
  36. package/dist/curves/lissajous32.d.cts +1 -1
  37. package/dist/curves/lissajous32.d.ts +1 -1
  38. package/dist/curves/lissajous32.js +3 -3
  39. package/dist/curves/lissajous43.cjs +4 -4
  40. package/dist/curves/lissajous43.d.cts +1 -1
  41. package/dist/curves/lissajous43.d.ts +1 -1
  42. package/dist/curves/lissajous43.js +3 -3
  43. package/dist/curves/rose3.cjs +4 -4
  44. package/dist/curves/rose3.d.cts +1 -1
  45. package/dist/curves/rose3.d.ts +1 -1
  46. package/dist/curves/rose3.js +3 -3
  47. package/dist/curves/rose5.cjs +4 -4
  48. package/dist/curves/rose5.d.cts +1 -1
  49. package/dist/curves/rose5.d.ts +1 -1
  50. package/dist/curves/rose5.js +3 -3
  51. package/dist/index.cjs +78 -94
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +29 -66
  54. package/dist/index.d.ts +29 -66
  55. package/dist/index.js +78 -112
  56. package/dist/index.js.map +1 -1
  57. package/dist/types-BL9HhEmk.d.cts +246 -259
  58. package/dist/types-BL9HhEmk.d.ts +246 -259
  59. package/package.json +1 -1
package/dist/auto-init.js CHANGED
@@ -61,13 +61,13 @@ function resolveCurve(curveDef) {
61
61
  period,
62
62
  speed,
63
63
  skeleton: curveDef.skeleton,
64
- skeletonFn: curveDef.skeletonFn,
64
+ skeletonFn: curveDef.skeletonFn
65
65
  };
66
66
  }
67
67
  function createEngine(curveDef, trailLength = 120) {
68
68
  if (!Number.isFinite(trailLength) || trailLength <= 0) {
69
69
  throw new RangeError(
70
- `[sarmal] trailLength must be a positive finite number, got ${trailLength}`,
70
+ `[sarmal] trailLength must be a positive finite number, got ${trailLength}`
71
71
  );
72
72
  }
73
73
  let curve = resolveCurve(curveDef);
@@ -108,7 +108,7 @@ function createEngine(curveDef, trailLength = 120) {
108
108
  actualTime += deltaTime;
109
109
  if (morphCurveB !== null && _morphAlpha !== null) {
110
110
  const a = curve.fn(t, actualTime, EMPTY_PARAMS);
111
- const tB = _morphStrategy === "normalized" ? (t / curve.period) * morphCurveB.period : t;
111
+ const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
112
112
  const b = morphCurveB.fn(tB, actualTime, EMPTY_PARAMS);
113
113
  trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
114
114
  } else {
@@ -132,14 +132,14 @@ function createEngine(curveDef, trailLength = 120) {
132
132
  trail.clear();
133
133
  },
134
134
  jump(newT, { clearTrail = false } = {}) {
135
- t = ((newT % curve.period) + curve.period) % curve.period;
135
+ t = (newT % curve.period + curve.period) % curve.period;
136
136
  if (clearTrail) {
137
137
  trail.clear();
138
138
  }
139
139
  },
140
140
  seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
141
141
  const advance = curve.speed * step;
142
- const target = ((targetT % curve.period) + curve.period) % curve.period;
142
+ const target = (targetT % curve.period + curve.period) % curve.period;
143
143
  const targetTime = target / curve.speed;
144
144
  t = target;
145
145
  actualTime = targetTime;
@@ -148,7 +148,7 @@ function createEngine(curveDef, trailLength = 120) {
148
148
  const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
149
149
  for (let i = count - 1; i >= 0; i--) {
150
150
  const sampleT = target - i * advance;
151
- const wrappedT = ((sampleT % curve.period) + curve.period) % curve.period;
151
+ const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
152
152
  const time = targetTime - i * step;
153
153
  const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
154
154
  trail.push(point.x, point.y);
@@ -165,16 +165,13 @@ function createEngine(curveDef, trailLength = 120) {
165
165
  ...frozenB,
166
166
  fn: (sampleT, time, params) => {
167
167
  const a = frozenA.fn(sampleT, time, params);
168
- const tB =
169
- frozenStrategy === "normalized"
170
- ? (sampleT / frozenA.period) * frozenB.period
171
- : sampleT;
168
+ const tB = frozenStrategy === "normalized" ? sampleT / frozenA.period * frozenB.period : sampleT;
172
169
  const b = frozenB.fn(tB, time, params);
173
170
  return {
174
171
  x: a.x + (b.x - a.x) * frozenAlpha,
175
- y: a.y + (b.y - a.y) * frozenAlpha,
172
+ y: a.y + (b.y - a.y) * frozenAlpha
176
173
  };
177
- },
174
+ }
178
175
  };
179
176
  }
180
177
  _morphStrategy = strategy;
@@ -187,7 +184,7 @@ function createEngine(curveDef, trailLength = 120) {
187
184
  completeMorph() {
188
185
  if (morphCurveB !== null) {
189
186
  if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
190
- t = (t / curve.period) * morphCurveB.period;
187
+ t = t / curve.period * morphCurveB.period;
191
188
  }
192
189
  curve = morphCurveB;
193
190
  }
@@ -199,22 +196,19 @@ function createEngine(curveDef, trailLength = 120) {
199
196
  const points = new Array(steps);
200
197
  if (morphCurveB !== null && _morphAlpha !== null) {
201
198
  for (let i = 0; i < steps; i++) {
202
- const sampleT = (i / (steps - 1)) * curve.period;
199
+ const sampleT = i / (steps - 1) * curve.period;
203
200
  const a = sampleSkeleton(curve, sampleT);
204
- const tB =
205
- _morphStrategy === "normalized"
206
- ? (sampleT / curve.period) * morphCurveB.period
207
- : sampleT;
201
+ const tB = _morphStrategy === "normalized" ? sampleT / curve.period * morphCurveB.period : sampleT;
208
202
  const b = sampleSkeleton(morphCurveB, tB);
209
203
  points[i] = {
210
204
  x: a.x + (b.x - a.x) * _morphAlpha,
211
- y: a.y + (b.y - a.y) * _morphAlpha,
205
+ y: a.y + (b.y - a.y) * _morphAlpha
212
206
  };
213
207
  }
214
208
  return points;
215
209
  }
216
210
  for (let i = 0; i < steps; i++) {
217
- const sampleT = (i / (steps - 1)) * curve.period;
211
+ const sampleT = i / (steps - 1) * curve.period;
218
212
  points[i] = sampleSkeleton(curve, sampleT);
219
213
  }
220
214
  return points;
@@ -256,7 +250,7 @@ function createEngine(curveDef, trailLength = 120) {
256
250
  _speedTransition.reject(new Error("Speed transition cancelled"));
257
251
  _speedTransition = null;
258
252
  }
259
- },
253
+ }
260
254
  };
261
255
  }
262
256
 
@@ -319,16 +313,13 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
319
313
  r1x: nx - n1.x * w1,
320
314
  r1y: ny - n1.y * w1,
321
315
  opacity,
322
- progress,
316
+ progress
323
317
  };
324
318
  }
325
319
  function computeBoundaries(pts, logicalWidth, logicalHeight) {
326
320
  if (pts.length === 0) return null;
327
321
  const first = pts[0];
328
- let minX = first.x,
329
- maxX = first.x,
330
- minY = first.y,
331
- maxY = first.y;
322
+ let minX = first.x, maxX = first.x, minY = first.y, maxY = first.y;
332
323
  for (const p of pts) {
333
324
  if (p.x < minX) {
334
325
  minX = p.x;
@@ -347,7 +338,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
347
338
  const h = maxY - minY;
348
339
  if (w === 0 && h === 0) {
349
340
  throw new Error(
350
- "[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t.",
341
+ "[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
351
342
  );
352
343
  }
353
344
  const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
@@ -358,12 +349,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
358
349
  scaleXProportional,
359
350
  scaleYProportional,
360
351
  scaleXMinPadding,
361
- scaleYMinPadding,
352
+ scaleYMinPadding
362
353
  );
363
354
  return {
364
355
  scale,
365
356
  offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
366
- offsetY: (logicalHeight - h * scale) / 2 - minY * scale,
357
+ offsetY: (logicalHeight - h * scale) / 2 - minY * scale
367
358
  };
368
359
  }
369
360
  function enginePassthroughs(engine) {
@@ -373,17 +364,17 @@ function enginePassthroughs(engine) {
373
364
  setSpeed: engine.setSpeed,
374
365
  getSpeed: engine.getSpeed,
375
366
  resetSpeed: engine.resetSpeed,
376
- setSpeedOver: engine.setSpeedOver,
367
+ setSpeedOver: engine.setSpeedOver
377
368
  };
378
369
  }
379
370
  function hexToRgb(hex) {
380
371
  const n = parseInt(hex.slice(1), 16);
381
- return { r: n >> 16, g: (n >> 8) & 255, b: n & 255 };
372
+ return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
382
373
  }
383
374
  var lerpRgb = (a, b, t) => ({
384
375
  r: Math.round(a.r + (b.r - a.r) * t),
385
376
  g: Math.round(a.g + (b.g - a.g) * t),
386
- b: Math.round(a.b + (b.b - a.b) * t),
377
+ b: Math.round(a.b + (b.b - a.b) * t)
387
378
  });
388
379
  function getPaletteColor(palette, position, timeOffset = 0) {
389
380
  if (palette.length === 0) {
@@ -406,7 +397,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
406
397
  "trailColor",
407
398
  "headColor",
408
399
  "skeletonColor",
409
- "trailStyle",
400
+ "trailStyle"
410
401
  ]);
411
402
  function validateRenderOptions(partial) {
412
403
  for (const key of Object.keys(partial)) {
@@ -431,7 +422,7 @@ function assertTrailColor(value) {
431
422
  if (typeof value === "string") {
432
423
  if (!HEX_COLOR_RE.test(value)) {
433
424
  throw new TypeError(
434
- `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`,
425
+ `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`
435
426
  );
436
427
  }
437
428
  return;
@@ -439,21 +430,21 @@ function assertTrailColor(value) {
439
430
  if (Array.isArray(value)) {
440
431
  if (value.length < 2) {
441
432
  throw new RangeError(
442
- `[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`,
433
+ `[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`
443
434
  );
444
435
  }
445
436
  for (let i = 0; i < value.length; i++) {
446
437
  const entry = value[i];
447
438
  if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
448
439
  throw new TypeError(
449
- `[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`,
440
+ `[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`
450
441
  );
451
442
  }
452
443
  }
453
444
  return;
454
445
  }
455
446
  throw new TypeError(
456
- `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`,
447
+ `[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`
457
448
  );
458
449
  }
459
450
  function assertHeadColor(value) {
@@ -462,7 +453,7 @@ function assertHeadColor(value) {
462
453
  }
463
454
  if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
464
455
  throw new TypeError(
465
- `[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`,
456
+ `[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`
466
457
  );
467
458
  }
468
459
  }
@@ -472,14 +463,14 @@ function assertSkeletonColor(value) {
472
463
  }
473
464
  if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
474
465
  throw new TypeError(
475
- `[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`,
466
+ `[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`
476
467
  );
477
468
  }
478
469
  }
479
470
  function assertTrailStyle(value) {
480
471
  if (!TRAIL_STYLES.includes(value)) {
481
472
  throw new RangeError(
482
- `[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`,
473
+ `[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`
483
474
  );
484
475
  }
485
476
  }
@@ -501,22 +492,23 @@ function resolveHeadColor(trailColor, trailStyle) {
501
492
  function warnIfTrailColorMismatch(trailColor, trailStyle) {
502
493
  if (trailStyle === "default" && Array.isArray(trailColor)) {
503
494
  console.warn(
504
- '[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.',
495
+ '[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.'
505
496
  );
506
497
  return;
507
498
  }
508
499
  if (trailStyle !== "default" && typeof trailColor === "string") {
509
500
  console.warn(
510
- `[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.`,
501
+ `[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.`
511
502
  );
512
503
  }
513
504
  }
505
+ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
514
506
 
515
507
  // src/renderer.ts
516
508
  var WHITE_HEX = "#ffffff";
517
509
  function hexToRgbComponents(hex) {
518
510
  const n = parseInt(hex.slice(1), 16);
519
- return `${n >> 16},${(n >> 8) & 255},${n & 255}`;
511
+ return `${n >> 16},${n >> 8 & 255},${n & 255}`;
520
512
  }
521
513
  function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
522
514
  target.style.width = `${logicalWidth}px`;
@@ -541,9 +533,8 @@ function createRenderer(options) {
541
533
  warnIfTrailColorMismatch(trailColor, trailStyle);
542
534
  const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
543
535
  function setupCanvas() {
544
- const rect = canvas.getBoundingClientRect();
545
- const lw = rect.width || 200;
546
- const lh = rect.height || 200;
536
+ const lw = canvas.offsetWidth || 200;
537
+ const lh = canvas.offsetHeight || 200;
547
538
  applyDprSizing(canvas, lw, lh, dpr);
548
539
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
549
540
  }
@@ -641,7 +632,7 @@ function createRenderer(options) {
641
632
  i,
642
633
  trailCount,
643
634
  toX,
644
- toY,
635
+ toY
645
636
  );
646
637
  if (trailStyle === "default") {
647
638
  ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
@@ -665,8 +656,7 @@ function createRenderer(options) {
665
656
  }
666
657
  const x = head.x * scale + offsetX;
667
658
  const y = head.y * scale + offsetY;
668
- const r =
669
- options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(logicalWidth, logicalHeight) / 160));
659
+ const r = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
670
660
  ctx.fillStyle = headColor;
671
661
  ctx.beginPath();
672
662
  ctx.arc(x, y, r, 0, Math.PI * 2);
@@ -795,7 +785,7 @@ function createRenderer(options) {
795
785
  if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
796
786
  warnIfTrailColorMismatch(trailColor, trailStyle);
797
787
  }
798
- },
788
+ }
799
789
  };
800
790
  if (shouldAutoStart) {
801
791
  instance.play();
@@ -806,22 +796,19 @@ function createRenderer(options) {
806
796
  // src/curves/artemis2.ts
807
797
  var TWO_PI2 = Math.PI * 2;
808
798
  function artemis2Fn(t, _time, _params) {
809
- const a = 0.35,
810
- b = 0.15,
811
- ox = 0.175;
812
- const s = Math.sin(t),
813
- c = Math.cos(t);
799
+ const a = 0.35, b = 0.15, ox = 0.175;
800
+ const s = Math.sin(t), c = Math.cos(t);
814
801
  const denom = 1 + s * s;
815
802
  return {
816
- x: (c * (1 + a * c)) / denom - ox,
817
- y: (s * c * (1 + b * c)) / denom,
803
+ x: c * (1 + a * c) / denom - ox,
804
+ y: s * c * (1 + b * c) / denom
818
805
  };
819
806
  }
820
807
  var artemis2 = {
821
808
  name: "Artemis II",
822
809
  fn: artemis2Fn,
823
810
  period: TWO_PI2,
824
- speed: 0.7,
811
+ speed: 0.7
825
812
  };
826
813
 
827
814
  // src/curves/astroid.ts
@@ -831,14 +818,14 @@ function astroidFn(t, _time, _params) {
831
818
  const s = Math.sin(t);
832
819
  return {
833
820
  x: c * c * c,
834
- y: s * s * s,
821
+ y: s * s * s
835
822
  };
836
823
  }
837
824
  var astroid = {
838
825
  name: "Astroid",
839
826
  fn: astroidFn,
840
827
  period: TWO_PI3,
841
- speed: 1.1,
828
+ speed: 1.1
842
829
  };
843
830
 
844
831
  // src/curves/deltoid.ts
@@ -846,14 +833,14 @@ var TWO_PI4 = Math.PI * 2;
846
833
  function deltoidFn(t, _time, _params) {
847
834
  return {
848
835
  x: 2 * Math.cos(t) + Math.cos(2 * t),
849
- y: 2 * Math.sin(t) - Math.sin(2 * t),
836
+ y: 2 * Math.sin(t) - Math.sin(2 * t)
850
837
  };
851
838
  }
852
839
  var deltoid = {
853
840
  name: "Deltoid",
854
841
  fn: deltoidFn,
855
842
  period: TWO_PI4,
856
- speed: 0.9,
843
+ speed: 0.9
857
844
  };
858
845
 
859
846
  // src/curves/epicycloid3.ts
@@ -861,14 +848,14 @@ var TWO_PI5 = Math.PI * 2;
861
848
  function epicycloid3Fn(t, _time, _params) {
862
849
  return {
863
850
  x: 4 * Math.cos(t) - Math.cos(4 * t),
864
- y: 4 * Math.sin(t) - Math.sin(4 * t),
851
+ y: 4 * Math.sin(t) - Math.sin(4 * t)
865
852
  };
866
853
  }
867
854
  var epicycloid3 = {
868
855
  name: "Epicycloid (n=3)",
869
856
  fn: epicycloid3Fn,
870
857
  period: TWO_PI5,
871
- speed: 0.75,
858
+ speed: 0.75
872
859
  };
873
860
 
874
861
  // src/curves/epitrochoid7.ts
@@ -877,14 +864,14 @@ function epitrochoid7Fn(t, _time, _params) {
877
864
  const d = 1 + 0.55 * Math.sin(t * 0.5);
878
865
  return {
879
866
  x: 7 * Math.cos(t) - d * Math.cos(7 * t),
880
- y: 7 * Math.sin(t) - d * Math.sin(7 * t),
867
+ y: 7 * Math.sin(t) - d * Math.sin(7 * t)
881
868
  };
882
869
  }
883
870
  function epitrochoid7SkeletonFn(t) {
884
871
  const d = 1.275;
885
872
  return {
886
873
  x: 7 * Math.cos(t) - d * Math.cos(7 * t),
887
- y: 7 * Math.sin(t) - d * Math.sin(7 * t),
874
+ y: 7 * Math.sin(t) - d * Math.sin(7 * t)
888
875
  };
889
876
  }
890
877
  var epitrochoid7 = {
@@ -892,7 +879,7 @@ var epitrochoid7 = {
892
879
  fn: epitrochoid7Fn,
893
880
  period: TWO_PI6,
894
881
  speed: 1.4,
895
- skeletonFn: epitrochoid7SkeletonFn,
882
+ skeletonFn: epitrochoid7SkeletonFn
896
883
  };
897
884
 
898
885
  // src/curves/lissajous32.ts
@@ -901,7 +888,7 @@ function lissajous32Fn(t, time, _params) {
901
888
  const phi = time * 0.45;
902
889
  return {
903
890
  x: Math.sin(3 * t + phi),
904
- y: Math.sin(2 * t),
891
+ y: Math.sin(2 * t)
905
892
  };
906
893
  }
907
894
  var lissajous32 = {
@@ -909,7 +896,7 @@ var lissajous32 = {
909
896
  fn: lissajous32Fn,
910
897
  period: TWO_PI7,
911
898
  speed: 2,
912
- skeleton: "live",
899
+ skeleton: "live"
913
900
  };
914
901
 
915
902
  // src/curves/lissajous43.ts
@@ -918,7 +905,7 @@ function lissajous43Fn(t, time, _params) {
918
905
  const phi = time * 0.38;
919
906
  return {
920
907
  x: Math.sin(4 * t + phi),
921
- y: Math.sin(3 * t),
908
+ y: Math.sin(3 * t)
922
909
  };
923
910
  }
924
911
  var lissajous43 = {
@@ -926,18 +913,17 @@ var lissajous43 = {
926
913
  fn: lissajous43Fn,
927
914
  period: TWO_PI8,
928
915
  speed: 1.8,
929
- skeleton: "live",
916
+ skeleton: "live"
930
917
  };
931
918
 
932
919
  // src/curves/lame.ts
933
920
  var TWO_PI9 = Math.PI * 2;
934
921
  function lameFn(t, time, _params) {
935
922
  const p = 1.75 + 1.25 * Math.sin(time * 0.48);
936
- const c = Math.cos(t),
937
- s = Math.sin(t);
923
+ const c = Math.cos(t), s = Math.sin(t);
938
924
  return {
939
925
  x: Math.sign(c) * Math.pow(Math.abs(c), p),
940
- y: Math.sign(s) * Math.pow(Math.abs(s), p),
926
+ y: Math.sign(s) * Math.pow(Math.abs(s), p)
941
927
  };
942
928
  }
943
929
  var lame = {
@@ -945,7 +931,7 @@ var lame = {
945
931
  fn: lameFn,
946
932
  period: TWO_PI9,
947
933
  speed: 1,
948
- skeleton: "live",
934
+ skeleton: "live"
949
935
  };
950
936
 
951
937
  // src/curves/rose3.ts
@@ -954,14 +940,14 @@ function rose3Fn(t, _time, _params) {
954
940
  const r = Math.cos(3 * t);
955
941
  return {
956
942
  x: r * Math.cos(t),
957
- y: r * Math.sin(t),
943
+ y: r * Math.sin(t)
958
944
  };
959
945
  }
960
946
  var rose3 = {
961
947
  name: "Rose (n=3)",
962
948
  fn: rose3Fn,
963
949
  period: TWO_PI10,
964
- speed: 1.15,
950
+ speed: 1.15
965
951
  };
966
952
 
967
953
  // src/curves/rose5.ts
@@ -970,14 +956,14 @@ function rose5Fn(t, _time, _params) {
970
956
  const r = Math.cos(5 * t);
971
957
  return {
972
958
  x: r * Math.cos(t),
973
- y: r * Math.sin(t),
959
+ y: r * Math.sin(t)
974
960
  };
975
961
  }
976
962
  var rose5 = {
977
963
  name: "Rose (n=5)",
978
964
  fn: rose5Fn,
979
965
  period: TWO_PI11,
980
- speed: 1,
966
+ speed: 1
981
967
  };
982
968
 
983
969
  // src/curves/index.ts
@@ -991,7 +977,7 @@ var curves = {
991
977
  lissajous32,
992
978
  lissajous43,
993
979
  epicycloid3,
994
- lame,
980
+ lame
995
981
  };
996
982
 
997
983
  // src/index.ts
@@ -1008,7 +994,8 @@ function parseTrailColor(value) {
1008
994
  if (Array.isArray(parsed)) {
1009
995
  return parsed;
1010
996
  }
1011
- } catch {}
997
+ } catch {
998
+ }
1012
999
  return value;
1013
1000
  }
1014
1001
  function init() {
@@ -1022,18 +1009,21 @@ function init() {
1022
1009
  if (!curveDef) {
1023
1010
  return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
1024
1011
  }
1025
- createSarmal(canvas, curveDef, {
1026
- ...(canvas.dataset.trailColor && {
1027
- trailColor: parseTrailColor(canvas.dataset.trailColor),
1028
- }),
1029
- ...(canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor }),
1030
- ...(canvas.dataset.headColor && { headColor: canvas.dataset.headColor }),
1031
- ...(canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) }),
1032
- ...(canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) }),
1033
- ...(canvas.dataset.trailStyle && {
1034
- trailStyle: canvas.dataset.trailStyle,
1035
- }),
1012
+ const instance = createSarmal(canvas, curveDef, {
1013
+ ...canvas.dataset.trailColor && {
1014
+ trailColor: parseTrailColor(canvas.dataset.trailColor)
1015
+ },
1016
+ ...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
1017
+ ...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
1018
+ ...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
1019
+ ...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) },
1020
+ ...canvas.dataset.trailStyle && {
1021
+ trailStyle: canvas.dataset.trailStyle
1022
+ }
1036
1023
  });
1024
+ if (canvas.dataset.speed) {
1025
+ instance.setSpeed(parseFloat(canvas.dataset.speed));
1026
+ }
1037
1027
  });
1038
1028
  }
1039
1029
  if (document.readyState === "loading") {
@@ -1043,5 +1033,7 @@ if (document.readyState === "loading") {
1043
1033
  } else {
1044
1034
  requestAnimationFrame(init);
1045
1035
  }
1036
+
1037
+ export { init };
1046
1038
  //# sourceMappingURL=auto-init.js.map
1047
- //# sourceMappingURL=auto-init.js.map
1039
+ //# sourceMappingURL=auto-init.js.map