import { categoricalColors as c } from "./palette.js";
function s(t, r, e, n = 1) {
  return new class {
    constructor(o, i, a, l = 1) {
      this.r = o, this.g = i, this.b = a, this.a = l;
    }
    get hex() {
      const o = t.toString(16).padStart(2, "0"), i = r.toString(16).padStart(2, "0"), a = e.toString(16).padStart(2, "0"), l = Math.round(n * 255).toString(16).padStart(2, "0");
      return `#${o}${i}${a}${l}`;
    }
    get rgba() {
      return `rgb(${t}, ${r}, ${e}, ${n})`;
    }
    toString() {
      return this.hex;
    }
    toJSON() {
      return this.hex;
    }
  }(t, r, e, n);
}
s.fromHex = (t) => {
  t = t.replace("#", "");
  let r, e, n, o = 1;
  if (t.length === 6)
    r = parseInt(t.slice(0, 2), 16), e = parseInt(t.slice(2, 4), 16), n = parseInt(t.slice(4, 6), 16);
  else if (t.length === 8)
    r = parseInt(t.slice(0, 2), 16), e = parseInt(t.slice(2, 4), 16), n = parseInt(t.slice(4, 6), 16), o = parseInt(t.slice(6, 8), 16) / 255;
  else
    throw new Error("Invalid HEX color format.");
  return s(r, e, n, o);
};
s.fromString = (t) => {
  if (t.startsWith("#"))
    return s.fromHex(t);
  throw Error("TODO: implement rgb(a), hsl");
};
s.categorical = (t) => s.fromHex(c[t]);
export {
  s as Color
};
//# sourceMappingURL=color.js.map
