Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Nov 25, 2024
1 parent 8599a7f commit 09d32fc
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import{stringify as e,replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as t,isFunctionNode as a,isTokenNode as r,isCommentNode as s,TokenNode as o,FunctionNode as i,WhitespaceNode as c}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,isTokenDelim as v,isTokenNumeric as m,TokenType as f,NumberType as d}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 l=u({css:i.value});if(!l.find((e=>v(e)&&"+"===e[4].value)))return;const m=e(n(t(l),(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(;s(e.value[n+1]);)n++;if(n++,isZeroOrNegative(e.value[n])){const t=new o([f.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)}else(isNumericLargerThanZero(i)||a(i)&&h.test(i.getName()))&&(t=maxOfLastAndCurrentLengthNode(t,i))}})));m!==i.value&&(i.cloneBefore({value:m}),c?.preserve||i.remove())}}};function isNumericLargerThanZero(e){return!!(r(e)&&m(e.value)&&e.value[4].value>0)}function isZeroOrNegative(e){return!!(r(e)&&m(e.value)&&e.value[4].value<=0)}function incrementLengthNode(e,n,t){if(!e)return t;const a=new i([f.Function,"calc(",-1,-1,{value:"calc"}],[f.CloseParen,")",-1,-1,void 0],[e,new c([[f.Whitespace," ",-1,-1,void 0]]),n,new c([[f.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=l([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new i([f.Function,"max(",-1,-1,{value:"max"}],[f.CloseParen,")",-1,-1,void 0],[e,new o([f.Comma,",",-1,-1,void 0]),new c([[f.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}creator.postcss=!0;export{creator as default};
import{stringify as e,replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as t,isFunctionNode as a,isTokenNode as r,isCommentNode as s,TokenNode as o,FunctionNode as i,WhitespaceNode as c}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,isTokenDelim as v,TokenType as m,NumberType as f,isTokenNumeric as d}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 l=u({css:i.value});if(!l.find((e=>v(e)&&"+"===e[4].value)))return;const d=e(n(t(l),(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(;s(e.value[n+1]);)n++;if(n++,isZeroOrNegative(e.value[n])){const t=new o([m.Number,"0",-1,-1,{value:0,type:f.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)}else(isNumericLargerThanZero(i)||a(i)&&h.test(i.getName()))&&(t=maxOfLastAndCurrentLengthNode(t,i))}})));d!==i.value&&(i.cloneBefore({value:d}),c?.preserve||i.remove())}}};function isNumericLargerThanZero(e){return!!(r(e)&&d(e.value)&&e.value[4].value>0)}function isZeroOrNegative(e){return!!(r(e)&&d(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]]=l([[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 o([m.Comma,",",-1,-1,void 0]),new c([[m.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}creator.postcss=!0;export{creator as default};
Loading

0 comments on commit 09d32fc

Please sign in to comment.