import utils_default from "../utils/index.js";
import reusable_default from "../channels/reusable.js";
var RGB = {
	re: /^rgba?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?)))?\s*?\)$/i,
	parse: (r) => {
		let i = r.charCodeAt(0);
		if (i !== 114 && i !== 82) return;
		let a = r.match(RGB.re);
		if (!a) return;
		let [, o, s, c, l, u, d, f, p] = a;
		return reusable_default.set({
			r: utils_default.channel.clamp.r(s ? parseFloat(o) * 2.55 : parseFloat(o)),
			g: utils_default.channel.clamp.g(l ? parseFloat(c) * 2.55 : parseFloat(c)),
			b: utils_default.channel.clamp.b(d ? parseFloat(u) * 2.55 : parseFloat(u)),
			a: f ? utils_default.channel.clamp.a(p ? parseFloat(f) / 100 : parseFloat(f)) : 1
		}, r);
	},
	stringify: (t) => {
		let { r: n, g: r, b: i, a } = t;
		return a < 1 ? `rgba(${utils_default.lang.round(n)}, ${utils_default.lang.round(r)}, ${utils_default.lang.round(i)}, ${utils_default.lang.round(a)})` : `rgb(${utils_default.lang.round(n)}, ${utils_default.lang.round(r)}, ${utils_default.lang.round(i)})`;
	}
}, rgb_default = RGB;
export { rgb_default as default };
