@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/index.d.cts
CHANGED
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
R as RendererOptions,
|
|
7
7
|
P as Point,
|
|
8
8
|
a as SarmalOptions,
|
|
9
|
-
} from "./types-
|
|
9
|
+
} from "./types-C0b4MPtI.cjs";
|
|
10
10
|
export {
|
|
11
11
|
J as JumpOptions,
|
|
12
12
|
b as RuntimeRenderOptions,
|
|
13
13
|
c as SeekOptions,
|
|
14
14
|
T as TrailColor,
|
|
15
15
|
d as TrailStyle,
|
|
16
|
-
} from "./types-
|
|
16
|
+
} from "./types-C0b4MPtI.cjs";
|
|
17
17
|
export { CurveName, curves } from "./curves/index.cjs";
|
|
18
18
|
export { artemis2 } from "./curves/artemis2.cjs";
|
|
19
19
|
export { astroid } from "./curves/astroid.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
R as RendererOptions,
|
|
7
7
|
P as Point,
|
|
8
8
|
a as SarmalOptions,
|
|
9
|
-
} from "./types-
|
|
9
|
+
} from "./types-C0b4MPtI.js";
|
|
10
10
|
export {
|
|
11
11
|
J as JumpOptions,
|
|
12
12
|
b as RuntimeRenderOptions,
|
|
13
13
|
c as SeekOptions,
|
|
14
14
|
T as TrailColor,
|
|
15
15
|
d as TrailStyle,
|
|
16
|
-
} from "./types-
|
|
16
|
+
} from "./types-C0b4MPtI.js";
|
|
17
17
|
export { CurveName, curves } from "./curves/index.js";
|
|
18
18
|
export { artemis2 } from "./curves/artemis2.js";
|
|
19
19
|
export { astroid } from "./curves/astroid.js";
|
package/dist/index.js
CHANGED
|
@@ -426,6 +426,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
426
426
|
"headColor",
|
|
427
427
|
"skeletonColor",
|
|
428
428
|
"trailStyle",
|
|
429
|
+
"headRadius",
|
|
429
430
|
]);
|
|
430
431
|
function validateRenderOptions(partial) {
|
|
431
432
|
for (const key of Object.keys(partial)) {
|
|
@@ -445,6 +446,9 @@ function validateRenderOptions(partial) {
|
|
|
445
446
|
if (partial.trailStyle !== void 0) {
|
|
446
447
|
assertTrailStyle(partial.trailStyle);
|
|
447
448
|
}
|
|
449
|
+
if (partial.headRadius !== void 0) {
|
|
450
|
+
assertHeadRadius(partial.headRadius);
|
|
451
|
+
}
|
|
448
452
|
}
|
|
449
453
|
function assertTrailColor(value) {
|
|
450
454
|
if (typeof value === "string") {
|
|
@@ -502,6 +506,18 @@ function assertTrailStyle(value) {
|
|
|
502
506
|
);
|
|
503
507
|
}
|
|
504
508
|
}
|
|
509
|
+
function assertHeadRadius(value) {
|
|
510
|
+
if (typeof value !== "number") {
|
|
511
|
+
throw new TypeError(
|
|
512
|
+
`[sarmal] setRenderOptions: headRadius must be a number, got ${JSON.stringify(value)}`,
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
516
|
+
throw new TypeError(
|
|
517
|
+
`[sarmal] setRenderOptions: headRadius must be a finite positive number, got ${value}`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
505
521
|
function resolveTrailMainColor(trailColor) {
|
|
506
522
|
return typeof trailColor === "string" ? trailColor : trailColor[0];
|
|
507
523
|
}
|
|
@@ -530,9 +546,9 @@ function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
|
530
546
|
);
|
|
531
547
|
}
|
|
532
548
|
}
|
|
533
|
-
var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
|
|
534
549
|
|
|
535
550
|
// src/renderer.ts
|
|
551
|
+
var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
|
|
536
552
|
var WHITE_HEX = "#ffffff";
|
|
537
553
|
function hexToRgbComponents(hex) {
|
|
538
554
|
const n = parseInt(hex.slice(1), 16);
|
|
@@ -569,6 +585,7 @@ function createRenderer(options) {
|
|
|
569
585
|
setupCanvas();
|
|
570
586
|
let logicalWidth = canvas.width / dpr;
|
|
571
587
|
let logicalHeight = canvas.height / dpr;
|
|
588
|
+
let headRadius = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
|
|
572
589
|
let skeleton = [];
|
|
573
590
|
let skeletonCanvas = null;
|
|
574
591
|
let trail = [];
|
|
@@ -685,7 +702,7 @@ function createRenderer(options) {
|
|
|
685
702
|
}
|
|
686
703
|
const x = head.x * scale + offsetX;
|
|
687
704
|
const y = head.y * scale + offsetY;
|
|
688
|
-
const r =
|
|
705
|
+
const r = headRadius;
|
|
689
706
|
ctx.fillStyle = headColor;
|
|
690
707
|
ctx.beginPath();
|
|
691
708
|
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
@@ -814,6 +831,9 @@ function createRenderer(options) {
|
|
|
814
831
|
if (partial.headColor !== void 0) {
|
|
815
832
|
userHeadColor = partial.headColor;
|
|
816
833
|
}
|
|
834
|
+
if (partial.headRadius !== void 0) {
|
|
835
|
+
headRadius = partial.headRadius;
|
|
836
|
+
}
|
|
817
837
|
if (userHeadColor === null) {
|
|
818
838
|
headColor = resolveHeadColor(trailColor, trailStyle);
|
|
819
839
|
} else {
|
|
@@ -832,6 +852,8 @@ function createRenderer(options) {
|
|
|
832
852
|
|
|
833
853
|
// src/renderer-svg.ts
|
|
834
854
|
var EMPTY_PARAMS2 = {};
|
|
855
|
+
var SVG_DEFAULT_HEAD_RADIUS = 0.5;
|
|
856
|
+
var SKELETON_STROKE_WIDTH_PX = 1.5;
|
|
835
857
|
var HIGH_TRAIL_LENGTH_THRESHOLD = 5e3;
|
|
836
858
|
function pointsToPathString(pts, scale, offsetX, offsetY) {
|
|
837
859
|
if (pts.length < 2) {
|
|
@@ -871,15 +893,21 @@ function createSVGRenderer(options) {
|
|
|
871
893
|
let skeletonColor = options.skeletonColor ?? "#ffffff";
|
|
872
894
|
let userHeadColor = options.headColor ?? null;
|
|
873
895
|
let headColor = userHeadColor ?? resolveHeadColor(trailColor, trailStyle);
|
|
896
|
+
let headRadius;
|
|
874
897
|
let trailSolid = resolveTrailMainColor(trailColor);
|
|
875
898
|
let trailPalette = resolveTrailPalette(trailColor);
|
|
876
899
|
const ariaLabel = options.ariaLabel ?? "Loading";
|
|
877
900
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
878
901
|
const viewSize = 100;
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
902
|
+
function getContainerPixelSize() {
|
|
903
|
+
const rect = container.getBoundingClientRect();
|
|
904
|
+
return rect.width && rect.height ? Math.min(rect.width, rect.height) : 200;
|
|
905
|
+
}
|
|
906
|
+
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);
|
|
910
|
+
headRadius = options.headRadius ?? SVG_DEFAULT_HEAD_RADIUS;
|
|
883
911
|
container.setAttribute("viewBox", `0 0 ${viewSize} ${viewSize}`);
|
|
884
912
|
container.setAttribute("role", "img");
|
|
885
913
|
container.setAttribute("aria-label", ariaLabel);
|
|
@@ -1152,6 +1180,10 @@ function createSVGRenderer(options) {
|
|
|
1152
1180
|
if (partial.headColor !== void 0) {
|
|
1153
1181
|
userHeadColor = partial.headColor;
|
|
1154
1182
|
}
|
|
1183
|
+
if (partial.headRadius !== void 0) {
|
|
1184
|
+
headRadius = partial.headRadius;
|
|
1185
|
+
headCircle.setAttribute("r", String(headRadius));
|
|
1186
|
+
}
|
|
1155
1187
|
if (userHeadColor === null) {
|
|
1156
1188
|
headColor = resolveHeadColor(trailColor, trailStyle);
|
|
1157
1189
|
} else {
|