@sarmal/core 0.36.3 → 0.36.5

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/index.cjs CHANGED
@@ -1451,11 +1451,11 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1451
1451
  const cellW = W / cols;
1452
1452
  const cellH = H / rows;
1453
1453
  const dotR = Math.min(cellW, cellH) * 0.36;
1454
- let gradientOklab = null;
1454
+ let gradientOklab = [];
1455
1455
  let colorRgb = { r: 255, g: 255, b: 255 };
1456
- let currentTrailStyle = initialTrailStyle;
1457
- let animTime = 0;
1458
- const ANIM_PERIOD = 6;
1456
+ let trailStyle = initialTrailStyle;
1457
+ let trailColor = initialColor;
1458
+ let gradientAnimTime = 0;
1459
1459
  const grid = new Float32Array(cols * rows);
1460
1460
  let scale = 1;
1461
1461
  let offsetX = 0;
@@ -1544,13 +1544,8 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1544
1544
  }
1545
1545
  }
1546
1546
  function applyColor(color) {
1547
- if (Array.isArray(color)) {
1548
- gradientOklab = color.map((c) => parseColorToOklab(c));
1549
- colorRgb = oklabToRgb(gradientOklab[0]);
1550
- } else {
1551
- gradientOklab = null;
1552
- colorRgb = colorToRgb(color);
1553
- }
1547
+ colorRgb = colorToRgb(resolveTrailMainColor(color));
1548
+ gradientOklab = resolveTrailPalette(color).map((c) => parseColorToOklab(c));
1554
1549
  }
1555
1550
  function applySkeletonColor(color) {
1556
1551
  skeletonColorOklab = color === "transparent" ? null : parseColorToOklab(color);
@@ -1652,7 +1647,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1652
1647
  frameImageData.data.set(bgImageData.data);
1653
1648
  const { data } = frameImageData;
1654
1649
  writeSkeletonPixels(data);
1655
- const timeOffset = currentTrailStyle === "gradient-animated" ? animTime / ANIM_PERIOD : 0;
1650
+ const timeOffset = trailStyle === "gradient-animated" ? gradientAnimTime * 5e-4 : 0;
1656
1651
  const n = cols * rows;
1657
1652
  for (let dotIdx = 0; dotIdx < n; dotIdx++) {
1658
1653
  const intensity = grid[dotIdx];
@@ -1660,7 +1655,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1660
1655
  continue;
1661
1656
  }
1662
1657
  let r, g, b;
1663
- if (currentTrailStyle !== "default" && gradientOklab !== null) {
1658
+ if (trailStyle !== "default") {
1664
1659
  ({ r, g, b } = oklabToRgb(getPaletteColor(gradientOklab, intensity, timeOffset)));
1665
1660
  } else {
1666
1661
  ({ r, g, b } = colorRgb);
@@ -1701,8 +1696,8 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1701
1696
  calculateBoundaries(engine.getSarmalSkeleton());
1702
1697
  computeSkeletonGrid(engine.getSarmalSkeleton());
1703
1698
  }
1704
- if (currentTrailStyle === "gradient-animated") {
1705
- animTime += deltaTime;
1699
+ if (trailStyle === "gradient-animated") {
1700
+ gradientAnimTime += deltaTime * 1e3;
1706
1701
  }
1707
1702
  buildGrid(deltaTime);
1708
1703
  draw();
@@ -1716,6 +1711,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1716
1711
  validateBaseRenderOptions({ trailColor: initialColor, skeletonColor: skeletonColorOpt });
1717
1712
  applyColor(initialColor);
1718
1713
  applySkeletonColor(skeletonColorOpt);
1714
+ warnIfTrailColorMismatch(trailColor, trailStyle);
1719
1715
  calculateBoundaries(engine.getSarmalSkeleton());
1720
1716
  computePixelMask();
1721
1717
  computeSkeletonGrid(engine.getSarmalSkeleton());
@@ -1790,29 +1786,24 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1790
1786
  validateBaseRenderOptions(partial);
1791
1787
  let needsRebuildBg = false;
1792
1788
  if (partial.trailColor !== void 0) {
1793
- applyColor(partial.trailColor);
1789
+ trailColor = partial.trailColor;
1790
+ applyColor(trailColor);
1794
1791
  needsRebuildBg = true;
1795
1792
  }
1796
1793
  if (partial.skeletonColor !== void 0) {
1797
1794
  applySkeletonColor(partial.skeletonColor);
1798
1795
  }
1799
1796
  if (partial.trailStyle !== void 0) {
1800
- currentTrailStyle = partial.trailStyle;
1801
- if (currentTrailStyle === "default") {
1802
- animTime = 0;
1797
+ trailStyle = partial.trailStyle;
1798
+ if (trailStyle === "default") {
1799
+ gradientAnimTime = 0;
1803
1800
  }
1804
1801
  }
1805
1802
  if (needsRebuildBg) {
1806
1803
  buildBgImageData();
1807
1804
  }
1808
- if (currentTrailStyle !== "default" && gradientOklab === null) {
1809
- console.warn(
1810
- `[sarmal] dot matrix: trailColor is a single color but trailStyle is "${currentTrailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient.`
1811
- );
1812
- } else if (currentTrailStyle === "default" && gradientOklab !== null) {
1813
- console.warn(
1814
- '[sarmal] dot matrix: trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.'
1815
- );
1805
+ if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
1806
+ warnIfTrailColorMismatch(trailColor, trailStyle);
1816
1807
  }
1817
1808
  }
1818
1809
  };