/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
const require_runtime = require("../../../../_virtual/_rolldown/runtime.cjs");
const require_entryPoints = require("../../../../tailwind-internal/dist/utils/entryPoints.cjs");
const require_purgeFromCode = require("./purgeFromCode.cjs");
const require_files = require("./utils/files.cjs");
const require_safelist = require("./utils/safelist.cjs");
let node_fs = require("node:fs");
node_fs = require_runtime.__toESM(node_fs, 1);
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path, 1);
//#region ../css/dist/purger/optimized/purge.mjs
/*! © 2026 Yahoo, Inc. UDS CSS v0.0.0-development */
const warnedLocations = /* @__PURE__ */ new Set();
/**
* Clear warned locations (call at start of new purge run)
*/
const clearWarnings = () => {
	warnedLocations.clear();
};
/**
* Main purge function - optimized version
*
* Uses purgeFromCodeOptimized internally to ensure consistent behavior
* between CLI and playground.
*/
const purgeOptimized = async (options) => {
	const { entry = require_entryPoints.DEFAULT_ENTRY, output = "dist/safelist.ts", colorModes = ["dark"], ignoreDevFiles = true, ignore = [], includeStories = false, variants, autoVariants, componentData } = options;
	const startTime = performance.now();
	clearWarnings();
	const workspaceDir = process.env.PWD ?? process.cwd();
	const files = await require_files.scanForFiles(entry, ignoreDevFiles && !includeStories, ignoreDevFiles && includeStories ? [...ignore, ...require_files.TEST_FILE_IGNORE_GLOBS] : ignore);
	const allClasses = [];
	const allImports = /* @__PURE__ */ new Set();
	const allComponents = /* @__PURE__ */ new Set();
	const stats = {
		filesScanned: files.length,
		timeMs: 0,
		classesGenerated: 0,
		spreadsTraced: 0,
		spreadsUnresolved: 0,
		expressionsResolved: 0
	};
	const fileContents = files.map((filePath) => node_fs.default.readFileSync(filePath, "utf-8"));
	const results = await Promise.all(fileContents.map(async (code) => {
		return require_purgeFromCode.purgeFromCodeOptimized(code, {
			colorModes,
			variants,
			autoVariants,
			componentData,
			deferWrapperSpreadResolution: true
		});
	}));
	results.forEach((result) => {
		allClasses.push(...result.safelist);
		result.imports.forEach((imp) => allImports.add(imp));
		result.components.forEach((comp) => allComponents.add(comp));
		stats.spreadsTraced += result.stats.spreadsTraced;
		stats.spreadsUnresolved += result.stats.spreadsUnresolved;
		stats.expressionsResolved += result.stats.expressionsResolved;
	});
	allClasses.push(...require_purgeFromCode.resolveWrapperSpreadSafelist(results.flatMap((result) => result.unresolvedWrapperSpreads), fileContents, variants));
	allClasses.push(...require_safelist.getThemeAndScaleClasses(colorModes));
	allClasses.push(...require_safelist.getInternalSafelistClasses());
	const finalSafelist = require_safelist.deduplicateSafelist(allClasses).sort();
	await require_safelist.saveSafelistToFile(finalSafelist, node_path.default.isAbsolute(output) ? output : node_path.default.join(workspaceDir, output));
	stats.timeMs = Math.round(performance.now() - startTime);
	stats.classesGenerated = finalSafelist.length;
	return {
		safelist: finalSafelist,
		imports: [...allImports],
		components: [...allComponents],
		stats
	};
};
//#endregion
exports.purgeOptimized = purgeOptimized;
