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