import { DEC2HEX } from "../constants.js";
import reusable_default from "../channels/reusable.js";
var Hex = {
	re: /^#((?:[a-f0-9]{2}){2,4}|[a-f0-9]{3})$/i,
	parse: (e) => {
		if (e.charCodeAt(0) !== 35) return;
		let r = e.match(Hex.re);
		if (!r) return;
		let i = r[1], a = parseInt(i, 16), o = i.length, s = o % 4 == 0, c = o > 4, l = c ? 1 : 17, u = c ? 8 : 4, d = s ? 0 : -1, f = c ? 255 : 15;
		return reusable_default.set({
			r: (a >> u * (d + 3) & f) * l,
			g: (a >> u * (d + 2) & f) * l,
			b: (a >> u * (d + 1) & f) * l,
			a: s ? (a & f) * l / 255 : 1
		}, e);
	},
	stringify: (t) => {
		let { r: n, g: r, b: i, a } = t;
		return a < 1 ? `#${DEC2HEX[Math.round(n)]}${DEC2HEX[Math.round(r)]}${DEC2HEX[Math.round(i)]}${DEC2HEX[Math.round(a * 255)]}` : `#${DEC2HEX[Math.round(n)]}${DEC2HEX[Math.round(r)]}${DEC2HEX[Math.round(i)]}`;
	}
}, hex_default = Hex;
export { hex_default as default };
