asciify-engine 1.0.53 → 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,13 +622,33 @@ 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
+ }
625
638
  function resolveAccentHex(accentColor) {
626
639
  const v = accentColor || "auto";
627
- if (v === "auto") {
628
- const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
629
- return isDark ? "faf9f7" : "0d0d0d";
630
- }
631
- return v.replace("#", "");
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";
632
652
  }
633
653
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
634
654
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;