import s from"@csstools/postcss-progressive-custom-properties";import{color as o,SyntaxFlag as t,serializeHSL as e,serializeRGB as r}from"@csstools/css-color-parser";import{hasFallback as a,hasSupportsAtRuleAncestor as n}from"@csstools/utilities";import{replaceComponentValues as l,parseCommaSeparatedListOfComponentValues as c,isFunctionNode as i,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as g}from"@csstools/css-tokenizer";const u=/^(?:rgb|hsl)a?$/i,m=/\b(?:rgb|hsl)a?\(/i,basePlugin=s=>({postcssPlugin:"postcss-color-functional-notation",Declaration(f){const h=f.value;if(!m.test(h))return;if(a(f))return;if(n(f,m))return;const v=l(c(g({css:h})),(s=>{if(!i(s)||!u.test(s.getName()))return;const a=o(s);return!a||a.syntaxFlags.has(t.Experimental)||a.syntaxFlags.has(t.HasNoneKeywords)||a.syntaxFlags.has(t.RelativeColorSyntax)||(a.syntaxFlags.has(t.LegacyRGB)||a.syntaxFlags.has(t.LegacyHSL))&&!a.syntaxFlags.has(t.HasPercentageAlpha)?void 0:"hsl"===a.colorNotation?e(a):r(a)})),y=p(v);y!==h&&(f.cloneBefore({value:y}),s?.preserve||f.remove())}});basePlugin.postcss=!0;const postcssPlugin=o=>{const t=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},o);return t.enableProgressiveCustomProperties&&t.preserve?{postcssPlugin:"postcss-color-functional-notation",plugins:[s(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0;export{postcssPlugin as default};
