/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { iconPruneVarsSafelist } from "../packages/icons/src/safelist.js";
import { getConfigurableCssVariables } from "../css/utils.js";
import { preserveVars, preserveVarsCleanup } from "../../../tailwind-internal/dist/utils/postcssPreserveVars.js";
import pruneVar from "postcss-prune-var";
//#region ../css/dist/postcss/pruneVars.mjs
/*! © 2026 Yahoo, Inc. UDS CSS v0.0.0-development */
/**
* Build the preserve → prune → cleanup PostCSS plugin sequence used to remove
* unused CSS variables. Used internally by the `uds css` command; consumers
* should use {@link udsPruneVars} instead.
*/
const getPruneVarPlugins = (safeVarPrefixes) => {
	if (safeVarPrefixes.length === 0) return [pruneVar()];
	return [
		preserveVars({ preserve: safeVarPrefixes }),
		pruneVar(),
		preserveVarsCleanup()
	];
};
/**
* Ready-to-use PostCSS plugin that removes unused UDS token CSS variables
* (and any other unused CSS variables) from generated CSS.
*
* Runtime-configurable UDS variables and icon color variables are always
* preserved. Additional variables can be preserved via the `safelist` option
* using string prefixes or regular expressions.
*
* Must run after all CSS has been generated (e.g. after Tailwind).
*
* @example
* ```js
* // postcss.config.js
* const { udsPruneVars } = require('@yahoo/uds/postcss');
*
* module.exports = {
*   plugins: [udsPruneVars({ safelist: ['--app-theme-'] })],
* };
* ```
*/
const udsPruneVars = (options = {}) => ({
	postcssPlugin: "uds-prune-vars",
	plugins: getPruneVarPlugins([
		...getConfigurableCssVariables(),
		...iconPruneVarsSafelist,
		...options.safelist ?? []
	])
});
//#endregion
export { getPruneVarPlugins, udsPruneVars };
