"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),t=require("postcss-value-parser"),s=require("@csstools/utilities");const r=/(?:repeating-)?(?:conic|linear|radial)-gradient\(/i,o=/^(?:repeating-)?(?:conic|linear|radial)-gradient$/i,i=["at","bottom","center","circle","closest-corner","closest-side","ellipse","farthest-corner","farthest-side","from","in","left","right","to","top"];function isPunctuationCommaNode(e){return!!e&&"div"===e.type&&","===e.value}function isNumericNode(e){if(!e)return!1;try{return!1!==t.unit(e.value)}catch{return!1}}const basePlugin=e=>({postcssPlugin:"postcss-double-position-gradients",Declaration(n,{result:a}){if(!r.test(n.value))return;if(s.hasFallback(n))return;if(s.hasSupportsAtRuleAncestor(n,r))return;let u;try{u=t(n.value)}catch{n.warn(a,`Failed to parse value '${n.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===u)return;u.walk((e=>{if("function"!==e.type||!o.test(e.value))return;const t=e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));let s=!1;t.forEach(((t,r,o)=>{if("word"===t.type&&i.includes(t.value.toLowerCase())&&(s=!0),"div"===t.type&&","===t.value&&(s=!1),s)return;const n=o[r-1],a=o[r-2],u=o[r+1];if(a&&a.type&&isNumericNode(n)&&isNumericNode(t)){const s=a,r={type:"div",value:",",before:isPunctuationCommaNode(u)?u.before:"",after:isPunctuationCommaNode(u)?"":" ",sourceIndex:0,sourceEndIndex:0};e.nodes.splice(e.nodes.indexOf(t)-1,0,r,s)}}))}));const c=u.toString();c!==n.value&&(n.cloneBefore({value:c}),e?.preserve||n.remove())}});basePlugin.postcss=!0;const postcssPlugin=t=>{const s=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},t);return s.enableProgressiveCustomProperties&&s.preserve?{postcssPlugin:"postcss-double-position-gradients",plugins:[e(),basePlugin(s)]}:basePlugin(s)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;