import utils_default from "../utils/index.js";
import reusable_default from "../channels/reusable.js";
var HSL = {
	re: /^hsla?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(?:deg|grad|rad|turn)?)\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,
	hueRe: /^(.+?)(deg|grad|rad|turn)$/i,
	_hue2deg: (t) => {
		let r = t.match(HSL.hueRe);
		if (r) {
			let [, t, n] = r;
			switch (n) {
				case "grad": return utils_default.channel.clamp.h(parseFloat(t) * .9);
				case "rad": return utils_default.channel.clamp.h(parseFloat(t) * 180 / Math.PI);
				case "turn": return utils_default.channel.clamp.h(parseFloat(t) * 360);
			}
		}
		return utils_default.channel.clamp.h(parseFloat(t));
	},
	parse: (r) => {
		let i = r.charCodeAt(0);
		if (i !== 104 && i !== 72) return;
		let a = r.match(HSL.re);
		if (!a) return;
		let [, o, s, c, l, u] = a;
		return reusable_default.set({
			h: HSL._hue2deg(o),
			s: utils_default.channel.clamp.s(parseFloat(s)),
			l: utils_default.channel.clamp.l(parseFloat(c)),
			a: l ? utils_default.channel.clamp.a(u ? parseFloat(l) / 100 : parseFloat(l)) : 1
		}, r);
	},
	stringify: (t) => {
		let { h: n, s: r, l: i, a } = t;
		return a < 1 ? `hsla(${utils_default.lang.round(n)}, ${utils_default.lang.round(r)}%, ${utils_default.lang.round(i)}%, ${a})` : `hsl(${utils_default.lang.round(n)}, ${utils_default.lang.round(r)}%, ${utils_default.lang.round(i)}%)`;
	}
}, hsl_default = HSL;
export { hsl_default as default };
