-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathindex.cjs
More file actions
1 lines (1 loc) · 2.37 KB
/
index.cjs
File metadata and controls
1 lines (1 loc) · 2.37 KB
1
"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer");const t=/(?:repeating-)?(?:linear|radial|conic)-gradient\(/i,a=/^(?:repeating-)?(?:linear|radial|conic)-gradient$/i,i=/^(?:abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const s=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!t.test(n.value))return;const r=o.tokenize({css:n.value});if(!r.find(e=>o.isTokenDelim(e)&&"+"===e[4].value))return;const c=e.stringify(e.replaceComponentValues(e.parseCommaSeparatedListOfComponentValues(r),n=>{if(!e.isFunctionNode(n))return;const t=n.getName();if(!a.test(t))return;let s=null;for(let t=0;t<n.value.length;t++){const a=n.value[t];if(e.isTokenNode(a)&&o.isTokenDelim(a.value)&&"+"===a.value[4].value){const i=a,r=t;for(;e.isCommentNode(n.value[t+1]);)t++;if(t++,isZeroOrNegative(n.value[t])){const a=new e.TokenNode([o.TokenType.Number,"0",-1,-1,{value:0,type:o.NumberType.Integer}]);n.value.splice(r,t-r+1,a),t=n.value.indexOf(a);continue}const c=incrementLengthNode(s,i,n.value[t]);n.value.splice(r,t-r+1,c),s=c,t=n.value.indexOf(c);continue}isNumericLargerThanZero(a)?s=maxOfLastAndCurrentLengthNode(s,a):e.isFunctionNode(a)&&i.test(a.getName())&&(s=maxOfLastAndCurrentLengthNode(s,a))}}));c!==n.value&&(n.cloneBefore({value:c}),s?.preserve||n.remove())}}};function isNumericLargerThanZero(n){return!!(e.isTokenNode(n)&&o.isTokenNumeric(n.value)&&n.value[4].value>0)}function isZeroOrNegative(n){return!!(e.isTokenNode(n)&&o.isTokenNumeric(n.value)&&n.value[4].value<=0)}function incrementLengthNode(t,a,i){if(!t)return i;const s=new e.FunctionNode([o.TokenType.Function,"calc(",-1,-1,{value:"calc"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i]),[[r]]=n.calcFromComponentValues([[s]]);return r}function maxOfLastAndCurrentLengthNode(t,a){if(!t)return a;const i=new e.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a]),[[s]]=n.calcFromComponentValues([[i]]);return s}creator.postcss=!0,module.exports=creator;