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.cjs CHANGED
@@ -622,6 +622,34 @@ function resolveInvert(invert) {
622
622
  if (invert !== "auto") return invert;
623
623
  return typeof window !== "undefined" && !window.matchMedia("(prefers-color-scheme: dark)").matches;
624
624
  }
625
+ function cssValueToHex(val) {
626
+ const hexMatch = val.match(/^#([0-9a-fA-F]{3,6})$/);
627
+ if (hexMatch) {
628
+ let h = hexMatch[1];
629
+ if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
630
+ if (h.length === 6) return h;
631
+ }
632
+ const rgbMatch = val.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/);
633
+ if (rgbMatch) {
634
+ return [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((n) => parseInt(n).toString(16).padStart(2, "0")).join("");
635
+ }
636
+ return null;
637
+ }
638
+ function resolveAccentHex(accentColor) {
639
+ const v = accentColor || "auto";
640
+ if (v !== "auto") return v.replace("#", "");
641
+ if (typeof document !== "undefined") {
642
+ const rootStyle = getComputedStyle(document.documentElement);
643
+ for (const prop of ["--accent-color", "--color-accent", "--accent", "--color-primary", "--primary", "--brand-color"]) {
644
+ const hex = cssValueToHex(rootStyle.getPropertyValue(prop).trim());
645
+ if (hex) return hex;
646
+ }
647
+ const native = cssValueToHex(getComputedStyle(document.body).accentColor ?? "");
648
+ if (native) return native;
649
+ }
650
+ const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
651
+ return isDark ? "faf9f7" : "0d0d0d";
652
+ }
625
653
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
626
654
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
627
655
  const srcHeight = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
@@ -786,7 +814,7 @@ async function gifToAsciiFrames(buffer, options, targetWidth, targetHeight, onPr
786
814
  function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, time = 0, hoverPos) {
787
815
  if (options.animationStyle === "waveField") {
788
816
  const mouseNorm = hoverPos ? { x: hoverPos.x, y: hoverPos.y } : { x: 0.5, y: 0.5 };
789
- const acHexWF = (options.accentColor || "#d4ff00").replace("#", "");
817
+ const acHexWF = options.accentColor ? resolveAccentHex(options.accentColor) : "d4ff00";
790
818
  renderWaveBackground(ctx, canvasWidth, canvasHeight, time, mouseNorm, {
791
819
  accentColor: `#${acHexWF}`,
792
820
  accentThreshold: 0.52,
@@ -831,7 +859,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
831
859
  const hcR = parseInt(hc.slice(1, 3), 16) || 255;
832
860
  const hcG = parseInt(hc.slice(3, 5), 16) || 255;
833
861
  const hcB = parseInt(hc.slice(5, 7), 16) || 255;
834
- const acHex = (options.accentColor || "#ffffff").replace("#", "");
862
+ const acHex = resolveAccentHex(options.accentColor);
835
863
  const acR = parseInt(acHex.substring(0, 2), 16) || 255;
836
864
  const acG = parseInt(acHex.substring(2, 4), 16) || 255;
837
865
  const acB = parseInt(acHex.substring(4, 6), 16) || 255;