asciify-engine 1.0.52 → 1.0.54

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.d.cts CHANGED
@@ -51,6 +51,11 @@ interface AsciiOptions {
51
51
  * The accent colour used when `colorMode` is `'accent'` or `'matrix'`.
52
52
  * Any CSS colour string. Default: `'#d4ff00'`
53
53
  */
54
+ /**
55
+ * Hex color string used when `colorMode` is `'accent'`.
56
+ * Set to `'auto'` to let the engine pick contrasting ink automatically:
57
+ * dark ink (`#0d0d0d`) in light mode, light ink (`#faf9f7`) in dark mode.
58
+ */
54
59
  accentColor: string;
55
60
  /**
56
61
  * Invert luminance mapping (light pixels → dense chars). Default: `false`
package/dist/index.d.ts CHANGED
@@ -51,6 +51,11 @@ interface AsciiOptions {
51
51
  * The accent colour used when `colorMode` is `'accent'` or `'matrix'`.
52
52
  * Any CSS colour string. Default: `'#d4ff00'`
53
53
  */
54
+ /**
55
+ * Hex color string used when `colorMode` is `'accent'`.
56
+ * Set to `'auto'` to let the engine pick contrasting ink automatically:
57
+ * dark ink (`#0d0d0d`) in light mode, light ink (`#faf9f7`) in dark mode.
58
+ */
54
59
  accentColor: string;
55
60
  /**
56
61
  * Invert luminance mapping (light pixels → dense chars). Default: `false`
package/dist/index.js CHANGED
@@ -620,6 +620,34 @@ function resolveInvert(invert) {
620
620
  if (invert !== "auto") return invert;
621
621
  return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
622
622
  }
623
+ function cssValueToHex(val) {
624
+ const hexMatch = val.match(/^#([0-9a-fA-F]{3,6})$/);
625
+ if (hexMatch) {
626
+ let h = hexMatch[1];
627
+ if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
628
+ if (h.length === 6) return h;
629
+ }
630
+ const rgbMatch = val.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/);
631
+ if (rgbMatch) {
632
+ return [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((n) => parseInt(n).toString(16).padStart(2, "0")).join("");
633
+ }
634
+ return null;
635
+ }
636
+ function resolveAccentHex(accentColor) {
637
+ const v = accentColor || "auto";
638
+ if (v !== "auto") return v.replace("#", "");
639
+ if (typeof document !== "undefined") {
640
+ const rootStyle = getComputedStyle(document.documentElement);
641
+ for (const prop of ["--accent-color", "--color-accent", "--accent", "--color-primary", "--primary", "--brand-color"]) {
642
+ const hex = cssValueToHex(rootStyle.getPropertyValue(prop).trim());
643
+ if (hex) return hex;
644
+ }
645
+ const native = cssValueToHex(getComputedStyle(document.body).accentColor ?? "");
646
+ if (native) return native;
647
+ }
648
+ const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
649
+ return isDark ? "faf9f7" : "0d0d0d";
650
+ }
623
651
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
624
652
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
625
653
  const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
@@ -784,7 +812,7 @@ async function gifToAsciiFrames(buffer, options, targetWidth, targetHeight, onPr
784
812
  function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, time = 0, hoverPos) {
785
813
  if (options.animationStyle === "waveField") {
786
814
  const mouseNorm = hoverPos ? { x: hoverPos.x, y: hoverPos.y } : { x: 0.5, y: 0.5 };
787
- const acHexWF = (options.accentColor || "#d4ff00").replace("#", "");
815
+ const acHexWF = options.accentColor ? resolveAccentHex(options.accentColor) : "d4ff00";
788
816
  renderWaveBackground(ctx, canvasWidth, canvasHeight, time, mouseNorm, {
789
817
  accentColor: `#${acHexWF}`,
790
818
  accentThreshold: 0.52,
@@ -829,7 +857,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
829
857
  const hcR = parseInt(hc.slice(1, 3), 16) || 255;
830
858
  const hcG = parseInt(hc.slice(3, 5), 16) || 255;
831
859
  const hcB = parseInt(hc.slice(5, 7), 16) || 255;
832
- const acHex = (options.accentColor || "#ffffff").replace("#", "");
860
+ const acHex = resolveAccentHex(options.accentColor);
833
861
  const acR = parseInt(acHex.substring(0, 2), 16) || 255;
834
862
  const acG = parseInt(acHex.substring(2, 4), 16) || 255;
835
863
  const acB = parseInt(acHex.substring(4, 6), 16) || 255;