/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
const require_getIconStyles = require("../../../tailwind-internal/dist/components/getIconStyles.cjs");
const require_tailwindPlugin = require("../../../tailwind-internal/dist/tailwindPlugin.cjs");
const require_entryPoints = require("../../../tailwind-internal/dist/utils/entryPoints.cjs");
const require_postcssPreserveVars = require("../../../tailwind-internal/dist/utils/postcssPreserveVars.cjs");
const require_safelist = require("../purger/optimized/utils/safelist.cjs");
const require_runner_helpers = require("./runner.helpers.cjs");
const require_utils = require("./utils.cjs");
const require_safelist$1 = require("../packages/icons/src/safelist.cjs");
const require_optimizeCSS = require("../utils/optimizeCSS.cjs");
const require_postcss = require("./postcss.cjs");
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path, 1);
let node_url = require("node:url");
let node_fs = require("node:fs");
node_fs = require_runtime.__toESM(node_fs, 1);
let postcss = require("postcss");
postcss = require_runtime.__toESM(postcss, 1);
let autoprefixer = require("autoprefixer");
autoprefixer = require_runtime.__toESM(autoprefixer, 1);
let postcss_prune_var = require("postcss-prune-var");
postcss_prune_var = require_runtime.__toESM(postcss_prune_var, 1);
let postcss_scope = require("postcss-scope");
postcss_scope = require_runtime.__toESM(postcss_scope, 1);
//#region ../css/dist/css/generate.helpers.mjs
/*! © 2026 Yahoo, Inc. UDS CSS v0.0.0-development */
const getPruneVarSafelist = (cssOptions) => {
	const pruneVars = cssOptions?.optimization?.pruneVars;
	const configuredSafelist = pruneVars && typeof pruneVars === "object" ? pruneVars.safelist ?? [] : [];
	return [...require_safelist$1.iconPruneVarsSafelist, ...configuredSafelist];
};
const getCssFeatureFlags = (cssOptions) => {
	const optimizationConfig = cssOptions?.optimization;
	const shouldOptimize = optimizationConfig?.enabled !== false;
	const pruneVars = optimizationConfig?.pruneVars;
	return {
		enablePreflight: cssOptions?.preflight !== false,
		enableFontFaceDeclarations: cssOptions?.fontFaceDeclarations !== false,
		shouldOptimize,
		shouldPruneVars: shouldOptimize && pruneVars !== false
	};
};
const getContentGlobs = (contentDir) => {
	return (Array.isArray(contentDir) ? contentDir : [contentDir]).map((dir) => require_entryPoints.hasAllowedEntryFileExtension(dir) ? dir : node_path.default.join(dir, "**/*.{js,jsx,mjs,cjs,ts,tsx}"));
};
const getRawContentEntries = (rawContents) => rawContents.map((rawContent) => ({
	raw: rawContent,
	extension: "html"
}));
const getTailwindEntrypointCandidates = () => [new URL("../../../tailwind-internal/dist/vendor/tailwindcss/lib/index.js", require("url").pathToFileURL(__filename).href), new URL("../vendor/tailwindcss/lib/index.js", require("url").pathToFileURL(__filename).href)];
const loadTailwindcss = async () => {
	for (const candidate of getTailwindEntrypointCandidates()) {
		if (!node_fs.default.existsSync((0, node_url.fileURLToPath)(candidate))) continue;
		const module = await import(candidate.href);
		return module.default ?? module;
	}
	throw new Error("Unable to locate a Tailwind CSS runtime for UDS CSS generation.");
};
const getInternalSafelistRawContent = (safelist) => {
	const internalClasses = new Set(require_safelist.getInternalSafelistClasses());
	const matchedInternalClasses = safelist.filter((entry) => typeof entry === "string" && internalClasses.has(entry));
	if (matchedInternalClasses.length === 0) return [];
	return [`<div class="${matchedInternalClasses.join(" ")}"></div>`];
};
const getInternalIconModeCss = (scopeClass) => {
	const iconStyles = require_getIconStyles.getIconStyles();
	return Object.entries(iconStyles).map(([selector, declarations]) => {
		return `${scopeClass ? `${scopeClass} ${selector}` : selector} { ${Object.entries(declarations).map(([property, value]) => `${property}: ${value};`).join(" ")} }`;
	}).join(" ");
};
const createTailwindPlugin = async (options) => {
	return (await loadTailwindcss())({
		content: [
			...getContentGlobs(options.contentDir),
			...getRawContentEntries(getInternalSafelistRawContent(options.safelist)),
			...getRawContentEntries(options.rawContents ?? [])
		],
		safelist: options.safelist,
		corePlugins: { preflight: options.enablePreflight },
		plugins: [require_tailwindPlugin.tailwindPlugin({
			config: options.config,
			disableFontFaceDeclarations: !options.enableFontFaceDeclarations,
			ignorePluginSafelists: true
		})]
	});
};
const getPruneVarPlugins = (safeVarPrefixes) => {
	if (safeVarPrefixes.length === 0) return [(0, postcss_prune_var.default)()];
	return [
		require_postcssPreserveVars.preserveVars({ preserve: safeVarPrefixes }),
		(0, postcss_prune_var.default)(),
		require_postcssPreserveVars.preserveVarsCleanup()
	];
};
const buildPostcssPlugins = (options) => {
	const plugins = [options.tailwindPlugin, (0, autoprefixer.default)()];
	if (options.shouldPruneVars) plugins.push(...getPruneVarPlugins(options.safeVarPrefixes));
	if (options.scopeClass) plugins.push((0, postcss_scope.default)(options.scopeClass));
	return plugins;
};
const applyScopedColorModeFix = async (css, scopeClass) => {
	if (!scopeClass) return css;
	return (await (0, postcss.default)([require_postcss.fixScopedSelfOrParentSelectorsPlugin(scopeClass), require_postcss.fixScopedColorModeSelectorsPlugin(scopeClass)]).process(css, { from: void 0 })).css;
};
const optimizeGeneratedCss = async (options) => {
	if (!options.shouldOptimize) return { css: options.css };
	const optimizationOptions = {
		removeUnusedFonts: options.optimizationConfig?.removeUnusedFonts,
		removeEmptyRules: options.optimizationConfig?.removeEmptyRules,
		aggregateDuplicateSelectors: options.optimizationConfig?.aggregateDuplicateSelectors,
		referenceCss: options.referenceCss,
		scopeClass: options.scopeClass
	};
	const optimized = await require_optimizeCSS.optimizeCSS(options.css, optimizationOptions);
	return {
		css: optimized.css,
		optimizationStats: {
			originalSize: optimized.stats.originalSize,
			originalSizeGzip: optimized.stats.originalSizeGzip,
			fontFacesRemoved: optimized.stats.fontFacesRemoved,
			emptyRulesRemoved: optimized.stats.emptyRulesRemoved,
			validationErrors: optimized.validation.errors
		}
	};
};
const printSimpleModeStats = (options) => {
	const { print, magenta, cyan, yellow } = options;
	const getDisplayPath = (targetPath) => {
		const relativePath = node_path.default.relative(options.cwd, targetPath);
		return relativePath.length === 0 ? "." : relativePath;
	};
	print("");
	print(`${magenta("Output:")} ${cyan(getDisplayPath(options.outputPath))}`);
	print(`${magenta("Stats:")}`);
	print(`   Files scanned: ${options.totalFilesScanned}`);
	if (options.verbose && options.scannedFilePaths && options.scannedFilePaths.length > 0) [...new Set(options.scannedFilePaths)].sort((left, right) => left.localeCompare(right)).forEach((filePath) => print(`      • ${cyan(getDisplayPath(filePath))}`));
	print(`   Classes: ${options.classCount}`);
	print(`   Size: ${require_utils.formatBytes(options.sizeBytes)} (${require_utils.formatBytes(options.sizeGzipBytes)} gzipped)`);
	const optimizationStats = options.optimizationStats;
	if (optimizationStats) {
		if (optimizationStats.originalSizeGzip - options.sizeGzipBytes > 0) {
			if (optimizationStats.fontFacesRemoved > 0) print(`      • removed ${optimizationStats.fontFacesRemoved} unused @font-face`);
			if (optimizationStats.emptyRulesRemoved > 0) print(`      • removed ${optimizationStats.emptyRulesRemoved} empty rules`);
		}
		if (optimizationStats.validationErrors.length > 0) {
			print(`   ${yellow("Validation warnings:")}`);
			optimizationStats.validationErrors.forEach((error) => print(`      ${yellow("•")} ${error}`));
		}
	}
	print(`   Time: ${require_runner_helpers.formatCssDuration(options.duration)}`);
	if (options.scope) print(`   Scope: ${cyan(options.scope)}`);
};
//#endregion
exports.applyScopedColorModeFix = applyScopedColorModeFix;
exports.buildPostcssPlugins = buildPostcssPlugins;
exports.createTailwindPlugin = createTailwindPlugin;
exports.getCssFeatureFlags = getCssFeatureFlags;
exports.getInternalIconModeCss = getInternalIconModeCss;
exports.getPruneVarSafelist = getPruneVarSafelist;
exports.optimizeGeneratedCss = optimizeGeneratedCss;
exports.printSimpleModeStats = printSimpleModeStats;
