@sarmal/core 0.20.0 → 0.23.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 (45) hide show
  1. package/dist/auto-init.cjs +38 -6
  2. package/dist/auto-init.cjs.map +1 -1
  3. package/dist/auto-init.d.cts +1 -1
  4. package/dist/auto-init.d.ts +1 -1
  5. package/dist/auto-init.js +38 -6
  6. package/dist/auto-init.js.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/astroid.d.cts +1 -1
  10. package/dist/curves/astroid.d.ts +1 -1
  11. package/dist/curves/deltoid.d.cts +1 -1
  12. package/dist/curves/deltoid.d.ts +1 -1
  13. package/dist/curves/epicycloid3.d.cts +1 -1
  14. package/dist/curves/epicycloid3.d.ts +1 -1
  15. package/dist/curves/epitrochoid7.d.cts +1 -1
  16. package/dist/curves/epitrochoid7.d.ts +1 -1
  17. package/dist/curves/index.d.cts +1 -1
  18. package/dist/curves/index.d.ts +1 -1
  19. package/dist/curves/lame.d.cts +1 -1
  20. package/dist/curves/lame.d.ts +1 -1
  21. package/dist/curves/lissajous32.d.cts +1 -1
  22. package/dist/curves/lissajous32.d.ts +1 -1
  23. package/dist/curves/lissajous43.d.cts +1 -1
  24. package/dist/curves/lissajous43.d.ts +1 -1
  25. package/dist/curves/rose3.d.cts +1 -1
  26. package/dist/curves/rose3.d.ts +1 -1
  27. package/dist/curves/rose5.d.cts +1 -1
  28. package/dist/curves/rose5.d.ts +1 -1
  29. package/dist/curves/rose52.d.cts +1 -1
  30. package/dist/curves/rose52.d.ts +1 -1
  31. package/dist/curves/star.d.cts +1 -1
  32. package/dist/curves/star.d.ts +1 -1
  33. package/dist/curves/star4.d.cts +1 -1
  34. package/dist/curves/star4.d.ts +1 -1
  35. package/dist/curves/star7.d.cts +1 -1
  36. package/dist/curves/star7.d.ts +1 -1
  37. package/dist/index.cjs +38 -6
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +2 -2
  40. package/dist/index.d.ts +2 -2
  41. package/dist/index.js +38 -6
  42. package/dist/index.js.map +1 -1
  43. package/dist/{types-frtEoAq6.d.cts → types-C0b4MPtI.d.cts} +4 -0
  44. package/dist/{types-frtEoAq6.d.ts → types-C0b4MPtI.d.ts} +4 -0
  45. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Scans for `<canvas data-sarmal="curveName">` and `<svg data-sarmal="curveName">`
3
- * when DOMContentLoaded is triggered, and creates a Sarmal instance for each one.
3
+ * when **DOMContentLoaded** is triggered, and creates a Sarmal instance for each one.
4
4
  */
5
5
  declare function init(): void;
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Scans for `<canvas data-sarmal="curveName">` and `<svg data-sarmal="curveName">`
3
- * when DOMContentLoaded is triggered, and creates a Sarmal instance for each one.
3
+ * when **DOMContentLoaded** is triggered, and creates a Sarmal instance for each one.
4
4
  */
5
5
  declare function init(): void;
6
6
 
package/dist/auto-init.js CHANGED
@@ -418,6 +418,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
418
418
  "headColor",
419
419
  "skeletonColor",
420
420
  "trailStyle",
421
+ "headRadius",
421
422
  ]);
422
423
  function validateRenderOptions(partial) {
423
424
  for (const key of Object.keys(partial)) {
@@ -437,6 +438,9 @@ function validateRenderOptions(partial) {
437
438
  if (partial.trailStyle !== void 0) {
438
439
  assertTrailStyle(partial.trailStyle);
439
440
  }
441
+ if (partial.headRadius !== void 0) {
442
+ assertHeadRadius(partial.headRadius);
443
+ }
440
444
  }
441
445
  function assertTrailColor(value) {
442
446
  if (typeof value === "string") {
@@ -494,6 +498,18 @@ function assertTrailStyle(value) {
494
498
  );
495
499
  }
496
500
  }
501
+ function assertHeadRadius(value) {
502
+ if (typeof value !== "number") {
503
+ throw new TypeError(
504
+ `[sarmal] setRenderOptions: headRadius must be a number, got ${JSON.stringify(value)}`,
505
+ );
506
+ }
507
+ if (!Number.isFinite(value) || value <= 0) {
508
+ throw new TypeError(
509
+ `[sarmal] setRenderOptions: headRadius must be a finite positive number, got ${value}`,
510
+ );
511
+ }
512
+ }
497
513
  function resolveTrailMainColor(trailColor) {
498
514
  return typeof trailColor === "string" ? trailColor : trailColor[0];
499
515
  }
@@ -522,9 +538,9 @@ function warnIfTrailColorMismatch(trailColor, trailStyle) {
522
538
  );
523
539
  }
524
540
  }
525
- var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
526
541
 
527
542
  // src/renderer.ts
543
+ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
528
544
  var WHITE_HEX = "#ffffff";
529
545
  function hexToRgbComponents(hex) {
530
546
  const n = parseInt(hex.slice(1), 16);
@@ -561,6 +577,7 @@ function createRenderer(options) {
561
577
  setupCanvas();
562
578
  let logicalWidth = canvas.width / dpr;
563
579
  let logicalHeight = canvas.height / dpr;
580
+ let headRadius = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
564
581
  let skeleton = [];
565
582
  let skeletonCanvas = null;
566
583
  let trail = [];
@@ -677,7 +694,7 @@ function createRenderer(options) {
677
694
  }
678
695
  const x = head.x * scale + offsetX;
679
696
  const y = head.y * scale + offsetY;
680
- const r = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
697
+ const r = headRadius;
681
698
  ctx.fillStyle = headColor;
682
699
  ctx.beginPath();
683
700
  ctx.arc(x, y, r, 0, Math.PI * 2);
@@ -806,6 +823,9 @@ function createRenderer(options) {
806
823
  if (partial.headColor !== void 0) {
807
824
  userHeadColor = partial.headColor;
808
825
  }
826
+ if (partial.headRadius !== void 0) {
827
+ headRadius = partial.headRadius;
828
+ }
809
829
  if (userHeadColor === null) {
810
830
  headColor = resolveHeadColor(trailColor, trailStyle);
811
831
  } else {
@@ -824,6 +844,8 @@ function createRenderer(options) {
824
844
 
825
845
  // src/renderer-svg.ts
826
846
  var EMPTY_PARAMS2 = {};
847
+ var SVG_DEFAULT_HEAD_RADIUS = 0.5;
848
+ var SKELETON_STROKE_WIDTH_PX = 1.5;
827
849
  var HIGH_TRAIL_LENGTH_THRESHOLD = 5e3;
828
850
  function pointsToPathString(pts, scale, offsetX, offsetY) {
829
851
  if (pts.length < 2) {
@@ -863,15 +885,21 @@ function createSVGRenderer(options) {
863
885
  let skeletonColor = options.skeletonColor ?? "#ffffff";
864
886
  let userHeadColor = options.headColor ?? null;
865
887
  let headColor = userHeadColor ?? resolveHeadColor(trailColor, trailStyle);
888
+ let headRadius;
866
889
  let trailSolid = resolveTrailMainColor(trailColor);
867
890
  let trailPalette = resolveTrailPalette(trailColor);
868
891
  const ariaLabel = options.ariaLabel ?? "Loading";
869
892
  warnIfTrailColorMismatch(trailColor, trailStyle);
870
893
  const viewSize = 100;
871
- const headRadius = options.headRadius ?? 1.5;
872
- const svgTrailMinWidth = 0.25;
873
- const svgTrailMaxWidth = 1.25;
874
- const svgSkeletonStrokeWidth = "0.75";
894
+ function getContainerPixelSize() {
895
+ const rect = container.getBoundingClientRect();
896
+ return rect.width && rect.height ? Math.min(rect.width, rect.height) : 200;
897
+ }
898
+ const containerPx = getContainerPixelSize();
899
+ const svgTrailMinWidth = (TRAIL_MIN_WIDTH * viewSize) / containerPx;
900
+ const svgTrailMaxWidth = (TRAIL_MAX_WIDTH * viewSize) / containerPx;
901
+ const svgSkeletonStrokeWidth = String((SKELETON_STROKE_WIDTH_PX * viewSize) / containerPx);
902
+ headRadius = options.headRadius ?? SVG_DEFAULT_HEAD_RADIUS;
875
903
  container.setAttribute("viewBox", `0 0 ${viewSize} ${viewSize}`);
876
904
  container.setAttribute("role", "img");
877
905
  container.setAttribute("aria-label", ariaLabel);
@@ -1144,6 +1172,10 @@ function createSVGRenderer(options) {
1144
1172
  if (partial.headColor !== void 0) {
1145
1173
  userHeadColor = partial.headColor;
1146
1174
  }
1175
+ if (partial.headRadius !== void 0) {
1176
+ headRadius = partial.headRadius;
1177
+ headCircle.setAttribute("r", String(headRadius));
1178
+ }
1147
1179
  if (userHeadColor === null) {
1148
1180
  headColor = resolveHeadColor(trailColor, trailStyle);
1149
1181
  } else {