import { T as l } from "./index.C1chwzNp.js";
var k = /* @__PURE__ */ ((r) => (r.Cmyk = "cmyk", r.Hex = "hex", r.Rgb = "rgb", r.Unknown = "unknown", r))(k || {});
const p = /^#([0-9A-Fa-f]{3}){1,2}$/, $ = /^(\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\s*,){2}\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\s*$/, x = /^(\s*(100|[1-9]?\d)\s*,){3}\s*(100|[1-9]?\d)\s*$/, y = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
function b(r) {
  return p.test(r) ? "hex" : $.test(r) ? "rgb" : x.test(r) ? "cmyk" : "unknown";
}
function d(r, c, n) {
  return "#" + [r, c, n].map((a) => a.toString(16).padStart(2, "0")).join("").toUpperCase();
}
function g(r) {
  r = r.trim().replace(/^#/, ""), r.length === 8 && (r = r.slice(0, 6)), r.length === 3 && (r = r.split("").map((n) => n + n).join(""));
  const c = parseInt(r, 16);
  return {
    b: c & 255,
    g: c >> 8 & 255,
    r: c >> 16 & 255
  };
}
function h(r, c, n) {
  const a = 1 - r / 255, t = 1 - c / 255, e = 1 - n / 255, s = Math.min(a, t, e);
  return s === 1 ? { c: 0, k: 100, m: 0, y: 0 } : {
    c: Math.round((a - s) / (1 - s) * 100),
    k: Math.round(s * 100),
    m: Math.round((t - s) / (1 - s) * 100),
    y: Math.round((e - s) / (1 - s) * 100)
  };
}
function m(r, c, n, a) {
  const t = 255 * (1 - r / 100) * (1 - a / 100), e = 255 * (1 - c / 100) * (1 - a / 100), s = 255 * (1 - n / 100) * (1 - a / 100);
  return { b: Math.round(s), g: Math.round(e), r: Math.round(t) };
}
function I(r) {
  switch (r = r.trim(), b(r)) {
    case "hex":
      return { hex: r };
    case "rgb": {
      const n = r.split(",").map((a) => a.trim());
      return {
        blue: parseInt(n[2], 10),
        green: parseInt(n[1], 10),
        red: parseInt(n[0], 10)
      };
    }
    case "cmyk": {
      const n = r.split(",").map((a) => a.trim());
      return {
        c: parseInt(n[0], 10),
        k: parseInt(n[3], 10),
        m: parseInt(n[1], 10),
        y: parseInt(n[2], 10)
      };
    }
    default:
      return {};
  }
}
function C(r, c, n) {
  const a = b(r), t = I(r);
  let e = {};
  if (a === "unknown")
    return "";
  if (a === c && !n)
    return r;
  switch (c) {
    case "hex":
      if (a === "rgb")
        e.hex = d(t.red, t.green, t.blue);
      else if (a === "cmyk") {
        const s = m(t.c, t.m, t.y, t.k);
        e.hex = d(s.r, s.g, s.b);
      } else
        e.hex = t.hex;
      break;
    case "rgb":
      if (a === "hex") {
        const s = g(t.hex);
        e.red = s.r, e.green = s.g, e.blue = s.b;
      } else if (a === "cmyk") {
        const s = m(t.c, t.m, t.y, t.k);
        e.red = s.r, e.green = s.g, e.blue = s.b;
      } else
        Object.assign(e, t);
      break;
    case "cmyk":
      if (a === "rgb")
        e = h(t.red, t.green, t.blue);
      else if (a === "hex") {
        const s = g(t.hex);
        e = h(s.r, s.g, s.b);
      } else
        Object.assign(e, t);
      break;
    default:
      return r;
  }
  return n ? n.replace(/\$\{(.*?)\}/g, (s, i) => i in e ? String(e[i]) : "") : c === "hex" ? e.hex : c === "rgb" ? `${e.red}, ${e.green}, ${e.blue}` : c === "cmyk" ? `${e.c}, ${e.m}, ${e.y}, ${e.k}` : r;
}
function E(r, c = "#000", n = "#FFF") {
  if (!((u) => y.test(u))(r))
    return r;
  const { b: t, g: e, r: s } = g(r);
  return 0.299 * s + 0.587 * e + 0.114 * t > 186 ? c : n;
}
function A(r) {
  const c = "light-dark", n = r.toLowerCase().indexOf(c + "(");
  if (n === -1)
    return "";
  const a = r.indexOf("(", n + c.length);
  if (a === -1)
    return "";
  let t = 0, e = -1, s = -1;
  for (let o = a; o < r.length; o++) {
    const f = r[o];
    if (f === "(") {
      t++;
      continue;
    }
    if (f === ")") {
      if (t--, t === 0) {
        s = o;
        break;
      }
      continue;
    }
    f === "," && t === 1 && e === -1 && (e = o);
  }
  if (e === -1 || s === -1)
    return "";
  const i = r.slice(a + 1, e).trim(), u = r.slice(e + 1, s).trim();
  return `${i} ${u}`;
}
function M(r, c) {
  const n = new l(r), a = new l(c), t = n.isValid ? r : "transparent", e = a.isValid ? c : "transparent";
  return `light-dark(${t}, ${e})`;
}
function _(r) {
  const c = A(r);
  if (!c)
    return null;
  const n = r.replace(/light-dark\([^()]*(?:\([^()]*\)[^()]*)*\)/i, "").trim();
  return `${c} ${n}`;
}
function L(r) {
  const c = r.match(/([a-zA-Z-]+\([^)]*\))/);
  if (!c)
    return "";
  const n = c[1], a = n.replace(/^[a-zA-Z-]+\(|\)$/g, "").trim(), t = r.replace(n, "").trim(), e = a.replace(/,/g, "").trim();
  return `${t} ${e}`;
}
export {
  k as C,
  p as H,
  $ as R,
  A as a,
  L as b,
  C as c,
  x as d,
  y as e,
  b as f,
  M as g,
  I as h,
  E as l,
  _ as p
};
