@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.js CHANGED
@@ -1449,11 +1449,11 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1449
1449
  const cellW = W / cols;
1450
1450
  const cellH = H / rows;
1451
1451
  const dotR = Math.min(cellW, cellH) * 0.36;
1452
- let gradientOklab = null;
1452
+ let gradientOklab = [];
1453
1453
  let colorRgb = { r: 255, g: 255, b: 255 };
1454
- let currentTrailStyle = initialTrailStyle;
1455
- let animTime = 0;
1456
- const ANIM_PERIOD = 6;
1454
+ let trailStyle = initialTrailStyle;
1455
+ let trailColor = initialColor;
1456
+ let gradientAnimTime = 0;
1457
1457
  const grid = new Float32Array(cols * rows);
1458
1458
  let scale = 1;
1459
1459
  let offsetX = 0;
@@ -1542,13 +1542,8 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1542
1542
  }
1543
1543
  }
1544
1544
  function applyColor(color) {
1545
- if (Array.isArray(color)) {
1546
- gradientOklab = color.map((c) => parseColorToOklab(c));
1547
- colorRgb = oklabToRgb(gradientOklab[0]);
1548
- } else {
1549
- gradientOklab = null;
1550
- colorRgb = colorToRgb(color);
1551
- }
1545
+ colorRgb = colorToRgb(resolveTrailMainColor(color));
1546
+ gradientOklab = resolveTrailPalette(color).map((c) => parseColorToOklab(c));
1552
1547
  }
1553
1548
  function applySkeletonColor(color) {
1554
1549
  skeletonColorOklab = color === "transparent" ? null : parseColorToOklab(color);
@@ -1650,7 +1645,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1650
1645
  frameImageData.data.set(bgImageData.data);
1651
1646
  const { data } = frameImageData;
1652
1647
  writeSkeletonPixels(data);
1653
- const timeOffset = currentTrailStyle === "gradient-animated" ? animTime / ANIM_PERIOD : 0;
1648
+ const timeOffset = trailStyle === "gradient-animated" ? gradientAnimTime * 5e-4 : 0;
1654
1649
  const n = cols * rows;
1655
1650
  for (let dotIdx = 0; dotIdx < n; dotIdx++) {
1656
1651
  const intensity = grid[dotIdx];
@@ -1658,7 +1653,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1658
1653
  continue;
1659
1654
  }
1660
1655
  let r, g, b;
1661
- if (currentTrailStyle !== "default" && gradientOklab !== null) {
1656
+ if (trailStyle !== "default") {
1662
1657
  ({ r, g, b } = oklabToRgb(getPaletteColor(gradientOklab, intensity, timeOffset)));
1663
1658
  } else {
1664
1659
  ({ r, g, b } = colorRgb);
@@ -1699,8 +1694,8 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1699
1694
  calculateBoundaries(engine.getSarmalSkeleton());
1700
1695
  computeSkeletonGrid(engine.getSarmalSkeleton());
1701
1696
  }
1702
- if (currentTrailStyle === "gradient-animated") {
1703
- animTime += deltaTime;
1697
+ if (trailStyle === "gradient-animated") {
1698
+ gradientAnimTime += deltaTime * 1e3;
1704
1699
  }
1705
1700
  buildGrid(deltaTime);
1706
1701
  draw();
@@ -1714,6 +1709,7 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1714
1709
  validateBaseRenderOptions({ trailColor: initialColor, skeletonColor: skeletonColorOpt });
1715
1710
  applyColor(initialColor);
1716
1711
  applySkeletonColor(skeletonColorOpt);
1712
+ warnIfTrailColorMismatch(trailColor, trailStyle);
1717
1713
  calculateBoundaries(engine.getSarmalSkeleton());
1718
1714
  computePixelMask();
1719
1715
  computeSkeletonGrid(engine.getSarmalSkeleton());
@@ -1788,29 +1784,24 @@ function createSarmalDotMatrix(canvas, curveDef, options) {
1788
1784
  validateBaseRenderOptions(partial);
1789
1785
  let needsRebuildBg = false;
1790
1786
  if (partial.trailColor !== void 0) {
1791
- applyColor(partial.trailColor);
1787
+ trailColor = partial.trailColor;
1788
+ applyColor(trailColor);
1792
1789
  needsRebuildBg = true;
1793
1790
  }
1794
1791
  if (partial.skeletonColor !== void 0) {
1795
1792
  applySkeletonColor(partial.skeletonColor);
1796
1793
  }
1797
1794
  if (partial.trailStyle !== void 0) {
1798
- currentTrailStyle = partial.trailStyle;
1799
- if (currentTrailStyle === "default") {
1800
- animTime = 0;
1795
+ trailStyle = partial.trailStyle;
1796
+ if (trailStyle === "default") {
1797
+ gradientAnimTime = 0;
1801
1798
  }
1802
1799
  }
1803
1800
  if (needsRebuildBg) {
1804
1801
  buildBgImageData();
1805
1802
  }
1806
- if (currentTrailStyle !== "default" && gradientOklab === null) {
1807
- console.warn(
1808
- `[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.`
1809
- );
1810
- } else if (currentTrailStyle === "default" && gradientOklab !== null) {
1811
- console.warn(
1812
- '[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.'
1813
- );
1803
+ if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
1804
+ warnIfTrailColorMismatch(trailColor, trailStyle);
1814
1805
  }
1815
1806
  }
1816
1807
  };