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.js CHANGED
@@ -620,13 +620,33 @@ 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
+ }
623
636
  function resolveAccentHex(accentColor) {
624
637
  const v = accentColor || "auto";
625
- if (v === "auto") {
626
- const isDark = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
627
- return isDark ? "faf9f7" : "0d0d0d";
628
- }
629
- return v.replace("#", "");
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";
630
650
  }
631
651
  function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
632
652
  const srcWidth = source instanceof HTMLVideoElement ? source.videoWidth : source.width;