"use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-tokenizer"),r=require("@csstools/css-color-parser"),t=require("@csstools/css-parser-algorithms");function hasFallback(s){const e=s.parent;if(!e)return!1;const r=s.prop.toLowerCase(),t=e.index(s);for(let s=0;s<t;s++){const t=e.nodes[s];if("decl"===t.type&&t.prop.toLowerCase()===r)return!0}return!1}function hasSupportsAtRuleAncestor(s){let e=s.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("color("))return!0;e=e.parent}else e=e.parent;return!1}const o=/(color)\(/i,n=/^(color)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration:a=>{const c=a.value;if(!o.test(c))return;if(hasFallback(a))return;if(hasSupportsAtRuleAncestor(a))return;const l=e.tokenize({css:c}),i=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(l),(s=>{if(!t.isFunctionNode(s)||!n.test(s.getName()))return;const e=r.color(s);return e&&!(e.syntaxFlags.has(r.SyntaxFlag.Experimental)||e.syntaxFlags.has(r.SyntaxFlag.HasNoneKeywords)||e.syntaxFlags.has(r.SyntaxFlag.RelativeColorSyntax))?r.serializeRGB(e):void 0})),p=t.stringify(i);p!==c&&(a.cloneBefore({value:p}),s?.preserve||a.remove())}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},e);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;
