"use strict";var e=require("@csstools/css-color-parser"),t=require("@csstools/css-parser-algorithms"),r=require("@csstools/css-tokenizer");const s="(color: hwb(0 0% 0%))";function hasSupportsAtRuleAncestor(e){let t=e.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name.toLowerCase()&&t.params.includes(s))return!0;t=t.parent}else t=t.parent;return!1}function hasFallback(e){const t=e.parent;if(!t)return!1;const r=e.prop.toLowerCase(),s=t.index(e);for(let e=0;e<s;e++){const s=t.nodes[e];if("decl"===s.type&&s.prop.toLowerCase()===r)return!0}return!1}const o=/hwb\(/i,n=/^hwb$/i,postcssPlugin=a=>{const l="preserve"in Object(a)&&Boolean(null==a?void 0:a.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(a,{postcss:c})=>{const p=a.value;if(!o.test(p))return;if(l&&hasSupportsAtRuleAncestor(a))return;if(hasFallback(a))return;const u=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(r.tokenize({css:p})),(r=>{if(t.isFunctionNode(r)&&n.test(r.getName())){const t=e.color(r);if(!t)return;if(t.syntaxFlags.has(e.SyntaxFlag.HasNoneKeywords))return;if(t.syntaxFlags.has(e.SyntaxFlag.RelativeColorSyntax))return;return e.serializeRGB(t)}})),i=t.stringify(u);if(i!==p)if(a.variable&&l&&a.parent){const e=a.parent,t=c.atRule({name:"supports",params:s,source:a.source}),r=e.clone();r.removeAll(),r.append(a.clone()),t.append(r),insertAtSupportsAfterCorrectRule(t,e,s),a.replaceWith(a.clone({value:i}))}else l?a.cloneBefore({value:i}):a.replaceWith(a.clone({value:i}))}}};function insertAtSupportsAfterCorrectRule(e,t,r){let s=t,o=t.next();for(;s&&o&&"atrule"===o.type&&"supports"===o.name.toLowerCase()&&o.params===r;)s=o,o=o.next();s.after(e)}postcssPlugin.postcss=!0,module.exports=postcssPlugin;
