@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.
- package/dist/auto-init.cjs +38 -6
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.d.cts +1 -1
- package/dist/auto-init.d.ts +1 -1
- package/dist/auto-init.js +38 -6
- package/dist/auto-init.js.map +1 -1
- package/dist/curves/artemis2.d.cts +1 -1
- package/dist/curves/artemis2.d.ts +1 -1
- package/dist/curves/astroid.d.cts +1 -1
- package/dist/curves/astroid.d.ts +1 -1
- package/dist/curves/deltoid.d.cts +1 -1
- package/dist/curves/deltoid.d.ts +1 -1
- package/dist/curves/epicycloid3.d.cts +1 -1
- package/dist/curves/epicycloid3.d.ts +1 -1
- package/dist/curves/epitrochoid7.d.cts +1 -1
- package/dist/curves/epitrochoid7.d.ts +1 -1
- package/dist/curves/index.d.cts +1 -1
- package/dist/curves/index.d.ts +1 -1
- package/dist/curves/lame.d.cts +1 -1
- package/dist/curves/lame.d.ts +1 -1
- package/dist/curves/lissajous32.d.cts +1 -1
- package/dist/curves/lissajous32.d.ts +1 -1
- package/dist/curves/lissajous43.d.cts +1 -1
- package/dist/curves/lissajous43.d.ts +1 -1
- package/dist/curves/rose3.d.cts +1 -1
- package/dist/curves/rose3.d.ts +1 -1
- package/dist/curves/rose5.d.cts +1 -1
- package/dist/curves/rose5.d.ts +1 -1
- package/dist/curves/rose52.d.cts +1 -1
- package/dist/curves/rose52.d.ts +1 -1
- package/dist/curves/star.d.cts +1 -1
- package/dist/curves/star.d.ts +1 -1
- package/dist/curves/star4.d.cts +1 -1
- package/dist/curves/star4.d.ts +1 -1
- package/dist/curves/star7.d.cts +1 -1
- package/dist/curves/star7.d.ts +1 -1
- package/dist/index.cjs +38 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +38 -6
- package/dist/index.js.map +1 -1
- package/dist/{types-frtEoAq6.d.cts → types-C0b4MPtI.d.cts} +4 -0
- package/dist/{types-frtEoAq6.d.ts → types-C0b4MPtI.d.ts} +4 -0
- package/package.json +1 -1
package/dist/auto-init.cjs
CHANGED
|
@@ -420,6 +420,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
420
420
|
"headColor",
|
|
421
421
|
"skeletonColor",
|
|
422
422
|
"trailStyle",
|
|
423
|
+
"headRadius",
|
|
423
424
|
]);
|
|
424
425
|
function validateRenderOptions(partial) {
|
|
425
426
|
for (const key of Object.keys(partial)) {
|
|
@@ -439,6 +440,9 @@ function validateRenderOptions(partial) {
|
|
|
439
440
|
if (partial.trailStyle !== void 0) {
|
|
440
441
|
assertTrailStyle(partial.trailStyle);
|
|
441
442
|
}
|
|
443
|
+
if (partial.headRadius !== void 0) {
|
|
444
|
+
assertHeadRadius(partial.headRadius);
|
|
445
|
+
}
|
|
442
446
|
}
|
|
443
447
|
function assertTrailColor(value) {
|
|
444
448
|
if (typeof value === "string") {
|
|
@@ -496,6 +500,18 @@ function assertTrailStyle(value) {
|
|
|
496
500
|
);
|
|
497
501
|
}
|
|
498
502
|
}
|
|
503
|
+
function assertHeadRadius(value) {
|
|
504
|
+
if (typeof value !== "number") {
|
|
505
|
+
throw new TypeError(
|
|
506
|
+
`[sarmal] setRenderOptions: headRadius must be a number, got ${JSON.stringify(value)}`,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
510
|
+
throw new TypeError(
|
|
511
|
+
`[sarmal] setRenderOptions: headRadius must be a finite positive number, got ${value}`,
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
499
515
|
function resolveTrailMainColor(trailColor) {
|
|
500
516
|
return typeof trailColor === "string" ? trailColor : trailColor[0];
|
|
501
517
|
}
|
|
@@ -524,9 +540,9 @@ function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
|
524
540
|
);
|
|
525
541
|
}
|
|
526
542
|
}
|
|
527
|
-
var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
|
|
528
543
|
|
|
529
544
|
// src/renderer.ts
|
|
545
|
+
var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
|
|
530
546
|
var WHITE_HEX = "#ffffff";
|
|
531
547
|
function hexToRgbComponents(hex) {
|
|
532
548
|
const n = parseInt(hex.slice(1), 16);
|
|
@@ -563,6 +579,7 @@ function createRenderer(options) {
|
|
|
563
579
|
setupCanvas();
|
|
564
580
|
let logicalWidth = canvas.width / dpr;
|
|
565
581
|
let logicalHeight = canvas.height / dpr;
|
|
582
|
+
let headRadius = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
|
|
566
583
|
let skeleton = [];
|
|
567
584
|
let skeletonCanvas = null;
|
|
568
585
|
let trail = [];
|
|
@@ -679,7 +696,7 @@ function createRenderer(options) {
|
|
|
679
696
|
}
|
|
680
697
|
const x = head.x * scale + offsetX;
|
|
681
698
|
const y = head.y * scale + offsetY;
|
|
682
|
-
const r =
|
|
699
|
+
const r = headRadius;
|
|
683
700
|
ctx.fillStyle = headColor;
|
|
684
701
|
ctx.beginPath();
|
|
685
702
|
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
@@ -808,6 +825,9 @@ function createRenderer(options) {
|
|
|
808
825
|
if (partial.headColor !== void 0) {
|
|
809
826
|
userHeadColor = partial.headColor;
|
|
810
827
|
}
|
|
828
|
+
if (partial.headRadius !== void 0) {
|
|
829
|
+
headRadius = partial.headRadius;
|
|
830
|
+
}
|
|
811
831
|
if (userHeadColor === null) {
|
|
812
832
|
headColor = resolveHeadColor(trailColor, trailStyle);
|
|
813
833
|
} else {
|
|
@@ -826,6 +846,8 @@ function createRenderer(options) {
|
|
|
826
846
|
|
|
827
847
|
// src/renderer-svg.ts
|
|
828
848
|
var EMPTY_PARAMS2 = {};
|
|
849
|
+
var SVG_DEFAULT_HEAD_RADIUS = 0.5;
|
|
850
|
+
var SKELETON_STROKE_WIDTH_PX = 1.5;
|
|
829
851
|
var HIGH_TRAIL_LENGTH_THRESHOLD = 5e3;
|
|
830
852
|
function pointsToPathString(pts, scale, offsetX, offsetY) {
|
|
831
853
|
if (pts.length < 2) {
|
|
@@ -865,15 +887,21 @@ function createSVGRenderer(options) {
|
|
|
865
887
|
let skeletonColor = options.skeletonColor ?? "#ffffff";
|
|
866
888
|
let userHeadColor = options.headColor ?? null;
|
|
867
889
|
let headColor = userHeadColor ?? resolveHeadColor(trailColor, trailStyle);
|
|
890
|
+
let headRadius;
|
|
868
891
|
let trailSolid = resolveTrailMainColor(trailColor);
|
|
869
892
|
let trailPalette = resolveTrailPalette(trailColor);
|
|
870
893
|
const ariaLabel = options.ariaLabel ?? "Loading";
|
|
871
894
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
872
895
|
const viewSize = 100;
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
896
|
+
function getContainerPixelSize() {
|
|
897
|
+
const rect = container.getBoundingClientRect();
|
|
898
|
+
return rect.width && rect.height ? Math.min(rect.width, rect.height) : 200;
|
|
899
|
+
}
|
|
900
|
+
const containerPx = getContainerPixelSize();
|
|
901
|
+
const svgTrailMinWidth = (TRAIL_MIN_WIDTH * viewSize) / containerPx;
|
|
902
|
+
const svgTrailMaxWidth = (TRAIL_MAX_WIDTH * viewSize) / containerPx;
|
|
903
|
+
const svgSkeletonStrokeWidth = String((SKELETON_STROKE_WIDTH_PX * viewSize) / containerPx);
|
|
904
|
+
headRadius = options.headRadius ?? SVG_DEFAULT_HEAD_RADIUS;
|
|
877
905
|
container.setAttribute("viewBox", `0 0 ${viewSize} ${viewSize}`);
|
|
878
906
|
container.setAttribute("role", "img");
|
|
879
907
|
container.setAttribute("aria-label", ariaLabel);
|
|
@@ -1146,6 +1174,10 @@ function createSVGRenderer(options) {
|
|
|
1146
1174
|
if (partial.headColor !== void 0) {
|
|
1147
1175
|
userHeadColor = partial.headColor;
|
|
1148
1176
|
}
|
|
1177
|
+
if (partial.headRadius !== void 0) {
|
|
1178
|
+
headRadius = partial.headRadius;
|
|
1179
|
+
headCircle.setAttribute("r", String(headRadius));
|
|
1180
|
+
}
|
|
1149
1181
|
if (userHeadColor === null) {
|
|
1150
1182
|
headColor = resolveHeadColor(trailColor, trailStyle);
|
|
1151
1183
|
} else {
|