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