/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_postcss_helpers = require('./postcss.helpers.cjs');

//#region src/css/postcss.ts
/**
* PostCSS plugin to fix color mode selectors for scoped CSS.
*
* postcss-scope converts selectors like:
*   `.uds-color-mode-dark .foo` → `.scope .uds-color-mode-dark .foo`
*
* But the color mode class is typically on <html> or <body>, which is an
* ANCESTOR of the scope, not a descendant. This plugin adds alternative
* selectors so color modes work correctly:
*
*   `.scope .uds-color-mode-dark .foo` → `.scope .uds-color-mode-dark .foo, .uds-color-mode-dark .scope .foo, .uds-color-mode-dark.scope .foo`
*
* This ensures styles apply whether the color mode class is inside or outside the scope.
*/
const fixScopedColorModeSelectorsPlugin = (scopeClass) => {
	const colorModePattern = /\.(uds-color-mode-(?:dark|light))/;
	return {
		postcssPlugin: "fix-scoped-color-mode-selectors",
		Once(root) {
			root.walkRules((rule) => {
				if (!rule.selector.includes(scopeClass) || !colorModePattern.test(rule.selector)) return;
				const nextSelector = require_postcss_helpers.buildScopedColorModeSelectorList(rule.selector, scopeClass);
				if (nextSelector !== rule.selector) rule.selector = nextSelector;
			});
		}
	};
};

//#endregion
exports.fixScopedColorModeSelectorsPlugin = fixScopedColorModeSelectorsPlugin;