import{stringify as e,replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as t,isFunctionNode as a,isTokenNode as r,isCommentNode as o,TokenNode as s,FunctionNode as i,WhitespaceNode as c}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as u}from"@csstools/css-calc";import{tokenize as l,isTokenDelim as v,TokenType as m,NumberType as d,isTokenNumeric as f}from"@csstools/css-tokenizer";const p=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,g=/^(?:repeating-)?(?:linear|radial|conic)-gradient$/i,h=/^(?:abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=i=>{const c=Object.assign({preserve:!1},i);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(i){if(!p.test(i.value))return;const u=l({css:i.value});if(!u.find(e=>v(e)&&"+"===e[4].value))return;const f=e(n(t(u),e=>{if(!a(e))return;const n=e.getName();if(!g.test(n))return;let t=null;for(let n=0;n<e.value.length;n++){const i=e.value[n];if(r(i)&&v(i.value)&&"+"===i.value[4].value){const a=i,r=n;for(;o(e.value[n+1]);)n++;if(n++,isZeroOrNegative(e.value[n])){const t=new s([m.Number,"0",-1,-1,{value:0,type:d.Integer}]);e.value.splice(r,n-r+1,t),n=e.value.indexOf(t);continue}const c=incrementLengthNode(t,a,e.value[n]);e.value.splice(r,n-r+1,c),t=c,n=e.value.indexOf(c);continue}isNumericLargerThanZero(i)?t=maxOfLastAndCurrentLengthNode(t,i):a(i)&&h.test(i.getName())&&(t=maxOfLastAndCurrentLengthNode(t,i))}}));f!==i.value&&(i.cloneBefore({value:f}),c?.preserve||i.remove())}}};function isNumericLargerThanZero(e){return!!(r(e)&&f(e.value)&&e.value[4].value>0)}function isZeroOrNegative(e){return!!(r(e)&&f(e.value)&&e.value[4].value<=0)}function incrementLengthNode(e,n,t){if(!e)return t;const a=new i([m.Function,"calc(",-1,-1,{value:"calc"}],[m.CloseParen,")",-1,-1,void 0],[e,new c([[m.Whitespace," ",-1,-1,void 0]]),n,new c([[m.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=u([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new i([m.Function,"max(",-1,-1,{value:"max"}],[m.CloseParen,")",-1,-1,void 0],[e,new s([m.Comma,",",-1,-1,void 0]),new c([[m.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=u([[t]]);return a}creator.postcss=!0;export{creator as default,creator as"module.exports"};
