import { z } from "zod";
//#region src/v2/features/editor/helpers/theme/load-css-variables.ts
/**
* Extracts CSS custom properties (variables) from a given CSS string
* for .light-mode and .dark-mode selectors and returns an object
* with 'light' and 'dark' keys containing the filtered variables.
* Only variables matching hex color values (#RRGGBB or #RRGGBBAA) are accepted.
*
* @param css - The CSS string to parse.
* @returns An object with `light` and `dark` properties containing the extracted CSS variables.
*/
var loadCssVariables = async (css) => {
	const sheet = new CSSStyleSheet();
	await sheet.replace(css);
	return Array.from(sheet.cssRules).reduce((acc, cur) => {
		if (!(cur instanceof CSSStyleRule)) return acc;
		const styles = Object.values(cur.style).reduce((style, name) => {
			if (!name.startsWith("--")) return style;
			const value = z.string().regex(/^(?:#(?:[0-9A-F]{6}|[0-9A-F]{8}))$/i).safeParse(cur.style.getPropertyValue(name).toUpperCase().trim());
			if (value.error) return style;
			style[name] = value.data;
			return style;
		}, {});
		if (cur.selectorText.includes(".light-mode")) acc.light = {
			...acc.light,
			...styles
		};
		if (cur.selectorText.includes(".dark-mode")) acc.dark = {
			...acc.dark,
			...styles
		};
		return acc;
	}, {
		light: {},
		dark: {}
	});
};
//#endregion
export { loadCssVariables };

//# sourceMappingURL=load-css-variables.js.map