const s = (r) => {
  const t = r.match(/^var\((--[^)]+)\)$/);
  return t ? t[1] : null;
}, a = (r) => {
  const t = r.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
  if (!t) return null;
  const [, e, n, o] = t.map(Number);
  return [e, n, o].some((u) => u < 0 || u > 255) ? null : `#${[e, n, o].map((u) => u.toString(16).padStart(2, "0")).join("")}`;
}, l = (r) => {
  const t = r.trim().toLowerCase();
  if (/^#[0-9a-f]{6}$/.test(t)) return t;
  if (/^#[0-9a-f]{8}$/.test(t)) return t.slice(0, 7);
  if (/^#[0-9a-f]{3}$/.test(t) || /^#[0-9a-f]{4}$/.test(t)) {
    const [, e, n, o] = t;
    return `#${e}${e}${n}${n}${o}${o}`;
  }
  return t.startsWith("rgb") ? a(t) : null;
}, i = (r) => {
  const t = s(r);
  if (!t || typeof window > "u" || typeof document > "u" || typeof getComputedStyle > "u")
    return null;
  const e = getComputedStyle(document.documentElement).getPropertyValue(t).trim();
  return e ? l(e) : null;
};
export {
  i as default
};
//# sourceMappingURL=resolveCssVarToHex.js.map
