/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_index = require('../../../css-tokens/dist/index.cjs');
let node_fs = require("node:fs");
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);

//#region src/purger/optimized/utils/safelist.ts
const colorModeToClass = {
	dark: require_index.DARK_COLOR_MODE_CLASSNAME,
	light: require_index.LIGHT_COLOR_MODE_CLASSNAME
};
/**
* Deduplicate and clean a safelist
*/
const deduplicateSafelist = (safelist) => {
	const deduped = safelist.map((cls) => cls.replaceAll("\\", "").trim()).filter((cleaned) => cleaned && isValidClassName(cleaned));
	return Array.from(new Set(deduped));
};
/**
* Check if a class name is valid (not malformed from CSS escape sequences)
*/
const isValidClassName = (cls) => {
	if (cls.match(/^[0-9]/)) return false;
	if (cls.match(/[0-9][a-z]$/)) return false;
	if (cls.includes("2c")) return false;
	return true;
};
/**
* Get classes for enabled color modes.
* Note: Light mode is not included by default since :root already defines light mode styles.
* Only dark mode class is needed to enable dark mode switching.
*/
const getThemeAndScaleClasses = (colorModes) => {
	if (!colorModes || colorModes.length === 0) return [colorModeToClass.dark];
	return colorModes.map((mode) => colorModeToClass[mode]).filter((className) => Boolean(className));
};
/**
* Save safelist to a file
*/
const saveSafelistToFile = async (safelist, outputPath) => {
	const content = `
//! This file is generated by the optimized purger from @yahoo/uds
//! Do not edit directly
//! If there is issue with this file please report to #ask-uds
export const safelist = ${JSON.stringify(safelist)};
`;
	(0, node_fs.mkdirSync)(node_path.default.dirname(outputPath), { recursive: true });
	(0, node_fs.writeFileSync)(outputPath, content);
};

//#endregion
exports.deduplicateSafelist = deduplicateSafelist;
exports.getThemeAndScaleClasses = getThemeAndScaleClasses;
exports.saveSafelistToFile = saveSafelistToFile;