import { categoricalColors as e } from "./palette.js";
/**
* Represents a color with red, green, blue, and alpha channels.
* Provides methods to convert to HEX and RGBA formats.
*
* @param {number} r - Red channel (0-255).
* @param {number} g - Green channel (0-255).
* @param {number} b - Blue channel (0-255).
* @param {number} [a=1] - Alpha channel (0-1).
*/
function t(e, t, n, r = 1) {
	return new class {
		constructor(e, t, n, r = 1) {
			this.r = e, this.g = t, this.b = n, this.a = r;
		}
		get hex() {
			return `#${e.toString(16).padStart(2, "0")}${t.toString(16).padStart(2, "0")}${n.toString(16).padStart(2, "0")}${Math.round(r * 255).toString(16).padStart(2, "0")}`;
		}
		get rgba() {
			return `rgb(${e}, ${t}, ${n}, ${r})`;
		}
		toString() {
			return this.hex;
		}
		toJSON() {
			return this.hex;
		}
	}(e, t, n, r);
}
t.fromHex = (e) => {
	e = e.replace("#", "");
	let n, r, i, a = 1;
	if (e.length === 6) n = parseInt(e.slice(0, 2), 16), r = parseInt(e.slice(2, 4), 16), i = parseInt(e.slice(4, 6), 16);
	else if (e.length === 8) n = parseInt(e.slice(0, 2), 16), r = parseInt(e.slice(2, 4), 16), i = parseInt(e.slice(4, 6), 16), a = parseInt(e.slice(6, 8), 16) / 255;
	else throw Error("Invalid HEX color format.");
	return t(n, r, i, a);
}, t.fromString = (e) => {
	if (e.startsWith("#")) return t.fromHex(e);
	throw Error("TODO: implement rgb(a), hsl");
}, t.categorical = (n) => t.fromHex(e[n]);
export { t as Color };

//# sourceMappingURL=color.js.map