/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

//#region src/utils/parseShadow.ts
/**
* Splits a CSS multi-shadow value (comma-separated) into individual
* shadow strings, correctly handling commas nested inside color functions
* like `rgb()`, `rgba()`, `hsl()`, etc.
*/
function splitShadows(value) {
	const shadows = [];
	let current = "";
	let depth = 0;
	for (let i = 0; i < value.length; i++) {
		const char = value[i];
		if (char === "(") {
			depth++;
			current += char;
		} else if (char === ")") {
			depth--;
			current += char;
		} else if (char === "," && depth === 0) {
			if (current.trim()) shadows.push(current.trim());
			current = "";
		} else current += char;
	}
	if (current.trim()) shadows.push(current.trim());
	return shadows;
}
/**
* Returns `true` if the token is a CSS color value.
*
* In a box-shadow context (after filtering `inset`), every token is either a
* length or a color. Colors always start with `#` (hex), a letter (named
* colors like `red`, `transparent`, `currentcolor`), or are a CSS function
* containing `(` (e.g. `rgb(…)`, `hsl(…)`, `oklch(…)`).
*/
function isColorToken(token) {
	const ch = token[0];
	return ch !== "-" && ch !== "." && (ch < "0" || ch > "9");
}
/**
* Splits a CSS value on whitespace, but keeps parenthesized groups
* (e.g. `rgb(0, 0, 0)`) together as single tokens.
*/
function tokenizeCSSValue(value) {
	const tokens = [];
	let current = "";
	let depth = 0;
	for (const char of value) {
		if (char === "(") depth++;
		if (char === ")") depth--;
		if (char === " " && depth === 0) {
			if (current) tokens.push(current);
			current = "";
		} else current += char;
	}
	if (current) tokens.push(current);
	return tokens;
}
/**
* Parses a single CSS shadow value string into its constituent parts.
*
* Handles all standard CSS box-shadow / drop-shadow permutations:
* - Color before or after length values (`red 0 4px 8px` or `0 4px 8px red`)
* - Optional blur and spread radii (defaults to 0)
* - `inset` keyword at any position (silently ignored)
* - All color formats: named, hex (3/4/6/8-digit), rgb/rgba, hsl/hsla, oklch,
*   oklab, lab, lch, color(), color-mix(), light-dark(), etc.
* - `none` / empty values → zeroed-out result with `transparent` color
*/
function parseSingleShadow(shadow) {
	const value = shadow.trim();
	if (!value || value.toLowerCase() === "none") return {
		x: 0,
		y: 0,
		blur: 0,
		spread: 0,
		color: "transparent"
	};
	const tokens = tokenizeCSSValue(value);
	const lengths = [];
	const colorParts = [];
	for (const token of tokens) {
		if (token.toLowerCase() === "inset") continue;
		if (isColorToken(token)) colorParts.push(token);
		else lengths.push(token);
	}
	return {
		x: lengths.length > 0 ? parseFloat(lengths[0]) : 0,
		y: lengths.length > 1 ? parseFloat(lengths[1]) : 0,
		blur: lengths.length > 2 ? parseFloat(lengths[2]) : 0,
		spread: lengths.length > 3 ? parseFloat(lengths[3]) : 0,
		color: colorParts.length > 0 ? colorParts.join(" ") : "rgb(0 0 0 / 1)"
	};
}
/**
* Parses a CSS shadow value — which may contain multiple comma-separated
* layers — into an array of {@link ParsedShadow} objects.
*
* @example
* ```ts
* parseShadow('0px 4px 8px 0px rgb(0 0 0 / 0.12)')
* // → [{ x: 0, y: 4, blur: 8, spread: 0, color: 'rgb(0 0 0 / 0.12)' }]
*
* parseShadow('0px 4px 8px rgb(0 0 0 / 0.12), 0px 1px 2px rgba(0, 0, 0, 0.08)')
* // → [
* //     { x: 0, y: 4, blur: 8, spread: 0, color: 'rgb(0 0 0 / 0.12)' },
* //     { x: 0, y: 1, blur: 2, spread: 0, color: 'rgba(0, 0, 0, 0.08)' },
* //   ]
* ```
*/
function parseShadow(shadowValue) {
	const trimmed = shadowValue.trim();
	if (!trimmed || trimmed.toLowerCase() === "none") return [];
	return splitShadows(trimmed).map(parseSingleShadow);
}

//#endregion
exports.parseShadow = parseShadow;