@csstools/postcss-gradients-interpolation-method 4.0.15 → 4.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -10
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
# Changes to PostCSS Gradients Interpolation Method
|
|
2
2
|
|
|
3
|
-
### 4.0.
|
|
3
|
+
### 4.0.17
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
_May 4, 2024_
|
|
6
6
|
|
|
7
|
-
- Updated [`@csstools/css-
|
|
7
|
+
- Updated [`@csstools/css-tokenizer`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer) to [`2.3.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer/CHANGELOG.md#231) (patch)
|
|
8
|
+
- Updated [`@csstools/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`2.6.3`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#263) (patch)
|
|
9
|
+
- Updated [`@csstools/css-color-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser) to [`2.0.2`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser/CHANGELOG.md#202) (patch)
|
|
8
10
|
|
|
9
|
-
### 4.0.
|
|
11
|
+
### 4.0.16
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
_May 4, 2024_
|
|
12
14
|
|
|
13
|
-
- Updated [`@csstools/
|
|
14
|
-
- Updated [`@csstools/css-
|
|
15
|
+
- Updated [`@csstools/css-tokenizer`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer) to [`2.3.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer/CHANGELOG.md#230) (minor)
|
|
16
|
+
- Updated [`@csstools/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`2.6.2`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#262) (patch)
|
|
17
|
+
- Updated [`@csstools/css-color-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser) to [`2.0.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser/CHANGELOG.md#201) (patch)
|
|
15
18
|
|
|
16
|
-
### 4.0.
|
|
19
|
+
### 4.0.15
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
_April 21, 2024_
|
|
19
22
|
|
|
20
|
-
- Updated [`@csstools/css-color-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser) to [`
|
|
23
|
+
- Updated [`@csstools/css-color-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser) to [`2.0.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser/CHANGELOG.md#200) (major)
|
|
21
24
|
|
|
22
25
|
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-gradients-interpolation-method/CHANGELOG.md)
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),o=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),
|
|
1
|
+
"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),o=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),i=require("@csstools/css-tokenizer"),n=require("@csstools/css-color-parser");const s=/(repeating-)?(linear|radial|conic)-gradient\(/i,r=/\bin\b/i,a={test:e=>s.test(e)&&r.test(e)},l=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(e,o,s,r=!1){const a=[],l=[];for(let r=0;r<e.length-1;r++){const a=e[r],c=e[r+1];if(l.push(a),s||n.serializeP3(a.colorData,!1).toString()!==n.serializeP3(c.colorData,!1).toString()&&a.position.toString()!==c.position.toString())for(let e=1;e<=9;e++){const r=10*e;let u=[];s&&(u=[new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),s,new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),new t.TokenNode([i.TokenType.Ident,"hue",-1,-1,{value:"hue"}])]);const p=new t.FunctionNode([i.TokenType.Function,"color-mix(",-1,-1,{value:"color-mix"}],[i.TokenType.CloseParen,")",-1,-1,void 0],[new t.TokenNode([i.TokenType.Ident,"in",-1,-1,{value:"in"}]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),o,...u,new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),a.color,new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),new t.TokenNode([i.TokenType.Percentage,100-r+"%",-1,-1,{value:100-r}]),new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),c.color,new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),new t.TokenNode([i.TokenType.Percentage,`${r}%`,-1,-1,{value:r}])]),d=n.color(p);if(!d)return!1;l.push({colorData:d})}r===e.length-2&&l.push(c)}for(let e=0;e<l.length;e++)r&&!n.colorDataFitsRGB_Gamut(l[e].colorData)?l[e].color=n.serializeP3(l[e].colorData,!1):l[e].color=n.serializeRGB(l[e].colorData,!1);for(let e=0;e<l.length;e++){const o=l[e];o.position?a.push(o.color,new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]),o.position):a.push(o.color),e!==l.length-1&&a.push(new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]]))}return a}function parseColorStops(e){const o=[];let s={};for(let r=0;r<e.length;r++){const a=e[r];if(t.isCommentNode(a)||t.isWhitespaceNode(a))continue;if(t.isTokenNode(a)&&i.isTokenComma(a.value)){if(s.color&&s.colorData&&s.positionA){o.push({color:s.color,colorData:s.colorData,position:s.positionA}),s.positionB&&o.push({color:s.color,colorData:s.colorData,position:s.positionB}),s={};continue}return!1}const l=n.color(a);if(l){if(s.color)return!1;if(l.syntaxFlags.has(n.SyntaxFlag.Experimental))return!1;s.color=a,s.colorData=l}else{if(!s.color)return!1;if(s.positionA){if(!s.positionA||s.positionB)return!1;s.positionB=a}else s.positionA=a}}return!(!s.color||!s.positionA)&&(s.color&&s.colorData&&s.positionA&&(o.push({color:s.color,colorData:s.colorData,position:s.positionA}),s.positionB&&o.push({color:s.color,colorData:s.colorData,position:s.positionB})),!(o.length<2)&&o)}const c=/^(srgb|srgb-linear|lab|oklab|xyz|xyz-d50|xyz-d65|hsl|hwb|lch|oklch)$/i,u=/^(hsl|hwb|lch|oklch)$/i,p=/^(shorter|longer|increasing|decreasing)$/i,d=/^in$/i,v=/^hue$/i;function modifyGradientFunctionComponentValues(e,o=!1){const n=e.getName();if(!l.test(n))return!1;let s="srgb",r=null,a=null,h=null,T=null,f=null,m=[];{let o=0,n=e.value[o];for(;n&&!(t.isTokenNode(n)&&i.isTokenIdent(n.value)&&d.test(n.value[4].value));){if(t.isTokenNode(n)&&i.isTokenComma(n.value))return!1;o++,n=e.value[o]}for(r=n,o++,n=e.value[o];t.isCommentNode(n)||t.isWhitespaceNode(n);)o++,n=e.value[o];if(t.isTokenNode(n)&&i.isTokenIdent(n.value)&&c.test(n.value[4].value)){if(a)return!1;a=n,s=n.value[4].value,o++,n=e.value[o]}for(;t.isCommentNode(n)||t.isWhitespaceNode(n);)o++,n=e.value[o];if(t.isTokenNode(n)&&i.isTokenIdent(n.value)&&p.test(n.value[4].value)&&u.test(s)){if(h||!a)return!1;h=n,o++,n=e.value[o]}for(;t.isCommentNode(n)||t.isWhitespaceNode(n);)o++,n=e.value[o];if(t.isTokenNode(n)&&i.isTokenIdent(n.value)&&v.test(n.value[4].value)){if(T||!a||!h)return!1;T=n,o++,n=e.value[o]}for(;n&&(!t.isTokenNode(n)||!i.isTokenComma(n.value));)o++,n=e.value[o];if(f=n,!f)return!1;m=e.value.slice(o+1)}if(!a)return!1;if(h&&!T)return!1;if(T&&!h)return!1;const k=parseColorStops(m);if(!k)return!1;const g=interpolateColorsInColorStopsList(k,a,h,o);if(!g)return!1;const N=trim([...e.value.slice(0,e.value.indexOf(r)),...e.value.slice(e.value.indexOf(T||a)+1,e.value.indexOf(f))]);return N.length>0&&N.some((e=>!t.isCommentNode(e)))&&N.push(new t.TokenNode([i.TokenType.Comma,",",-1,-1,void 0]),new t.WhitespaceNode([[i.TokenType.Whitespace," ",-1,-1,void 0]])),trim([...N,...trim(g)])}function trim(e){let o=0,i=e.length-1;for(let i=0;i<e.length;i++)if(!t.isWhitespaceNode(e[i])){o=i;break}for(let o=e.length-1;o>=0;o--)if(!t.isWhitespaceNode(e[o])){i=o;break}return e.slice(o,i+1)}const basePlugin=e=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(n){if(!a.test(n.value))return;if(o.hasFallback(n))return;if(o.hasSupportsAtRuleAncestor(n,a))return;const s=i.tokenize({css:n.value}),r=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e);o&&(e.value=o)})));if(r===n.value)return;const l=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(s),(e=>{if(!t.isFunctionNode(e))return;const o=modifyGradientFunctionComponentValues(e,!0);o&&(e.value=o)})));n.cloneBefore({value:r}),r!==l&&n.cloneBefore({value:l}),e?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=o=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},o);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[e(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"@csstools/postcss-progressive-custom-properties";import{hasFallback as e,hasSupportsAtRuleAncestor as t}from"@csstools/utilities";import{WhitespaceNode as i,TokenNode as r,FunctionNode as n,isCommentNode as s,isWhitespaceNode as l,isTokenNode as a,stringify as c,replaceComponentValues as u,parseCommaSeparatedListOfComponentValues as p,isFunctionNode as v}from"@csstools/css-parser-algorithms";import{TokenType as f,tokenize as
|
|
1
|
+
import o from"@csstools/postcss-progressive-custom-properties";import{hasFallback as e,hasSupportsAtRuleAncestor as t}from"@csstools/utilities";import{WhitespaceNode as i,TokenNode as r,FunctionNode as n,isCommentNode as s,isWhitespaceNode as l,isTokenNode as a,stringify as c,replaceComponentValues as u,parseCommaSeparatedListOfComponentValues as p,isFunctionNode as v}from"@csstools/css-parser-algorithms";import{TokenType as f,isTokenComma as h,isTokenIdent as m,tokenize as g}from"@csstools/css-tokenizer";import{serializeP3 as d,color as w,colorDataFitsRGB_Gamut as D,serializeRGB as C,SyntaxFlag as b}from"@csstools/css-color-parser";const x=/(repeating-)?(linear|radial|conic)-gradient\(/i,W=/\bin\b/i,P={test:o=>x.test(o)&&W.test(o)},A=/^(repeating-)?(linear|radial|conic)-gradient$/i;function interpolateColorsInColorStopsList(o,e,t,s=!1){const l=[],a=[];for(let s=0;s<o.length-1;s++){const l=o[s],c=o[s+1];if(a.push(l),t||d(l.colorData,!1).toString()!==d(c.colorData,!1).toString()&&l.position.toString()!==c.position.toString())for(let o=1;o<=9;o++){const s=10*o;let u=[];t&&(u=[new i([[f.Whitespace," ",-1,-1,void 0]]),t,new i([[f.Whitespace," ",-1,-1,void 0]]),new r([f.Ident,"hue",-1,-1,{value:"hue"}])]);const p=new n([f.Function,"color-mix(",-1,-1,{value:"color-mix"}],[f.CloseParen,")",-1,-1,void 0],[new r([f.Ident,"in",-1,-1,{value:"in"}]),new i([[f.Whitespace," ",-1,-1,void 0]]),e,...u,new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]]),l.color,new i([[f.Whitespace," ",-1,-1,void 0]]),new r([f.Percentage,100-s+"%",-1,-1,{value:100-s}]),new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]]),c.color,new i([[f.Whitespace," ",-1,-1,void 0]]),new r([f.Percentage,`${s}%`,-1,-1,{value:s}])]),v=w(p);if(!v)return!1;a.push({colorData:v})}s===o.length-2&&a.push(c)}for(let o=0;o<a.length;o++)s&&!D(a[o].colorData)?a[o].color=d(a[o].colorData,!1):a[o].color=C(a[o].colorData,!1);for(let o=0;o<a.length;o++){const e=a[o];e.position?l.push(e.color,new i([[f.Whitespace," ",-1,-1,void 0]]),e.position):l.push(e.color),o!==a.length-1&&l.push(new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]]))}return l}function parseColorStops(o){const e=[];let t={};for(let i=0;i<o.length;i++){const r=o[i];if(s(r)||l(r))continue;if(a(r)&&h(r.value)){if(t.color&&t.colorData&&t.positionA){e.push({color:t.color,colorData:t.colorData,position:t.positionA}),t.positionB&&e.push({color:t.color,colorData:t.colorData,position:t.positionB}),t={};continue}return!1}const n=w(r);if(n){if(t.color)return!1;if(n.syntaxFlags.has(b.Experimental))return!1;t.color=r,t.colorData=n}else{if(!t.color)return!1;if(t.positionA){if(!t.positionA||t.positionB)return!1;t.positionB=r}else t.positionA=r}}return!(!t.color||!t.positionA)&&(t.color&&t.colorData&&t.positionA&&(e.push({color:t.color,colorData:t.colorData,position:t.positionA}),t.positionB&&e.push({color:t.color,colorData:t.colorData,position:t.positionB})),!(e.length<2)&&e)}const B=/^(srgb|srgb-linear|lab|oklab|xyz|xyz-d50|xyz-d65|hsl|hwb|lch|oklch)$/i,S=/^(hsl|hwb|lch|oklch)$/i,y=/^(shorter|longer|increasing|decreasing)$/i,$=/^in$/i,k=/^hue$/i;function modifyGradientFunctionComponentValues(o,e=!1){const t=o.getName();if(!A.test(t))return!1;let n="srgb",c=null,u=null,p=null,v=null,g=null,d=[];{let e=0,t=o.value[e];for(;t&&!(a(t)&&m(t.value)&&$.test(t.value[4].value));){if(a(t)&&h(t.value))return!1;e++,t=o.value[e]}for(c=t,e++,t=o.value[e];s(t)||l(t);)e++,t=o.value[e];if(a(t)&&m(t.value)&&B.test(t.value[4].value)){if(u)return!1;u=t,n=t.value[4].value,e++,t=o.value[e]}for(;s(t)||l(t);)e++,t=o.value[e];if(a(t)&&m(t.value)&&y.test(t.value[4].value)&&S.test(n)){if(p||!u)return!1;p=t,e++,t=o.value[e]}for(;s(t)||l(t);)e++,t=o.value[e];if(a(t)&&m(t.value)&&k.test(t.value[4].value)){if(v||!u||!p)return!1;v=t,e++,t=o.value[e]}for(;t&&(!a(t)||!h(t.value));)e++,t=o.value[e];if(g=t,!g)return!1;d=o.value.slice(e+1)}if(!u)return!1;if(p&&!v)return!1;if(v&&!p)return!1;const w=parseColorStops(d);if(!w)return!1;const D=interpolateColorsInColorStopsList(w,u,p,e);if(!D)return!1;const C=trim([...o.value.slice(0,o.value.indexOf(c)),...o.value.slice(o.value.indexOf(v||u)+1,o.value.indexOf(g))]);return C.length>0&&C.some((o=>!s(o)))&&C.push(new r([f.Comma,",",-1,-1,void 0]),new i([[f.Whitespace," ",-1,-1,void 0]])),trim([...C,...trim(D)])}function trim(o){let e=0,t=o.length-1;for(let t=0;t<o.length;t++)if(!l(o[t])){e=t;break}for(let e=o.length-1;e>=0;e--)if(!l(o[e])){t=e;break}return o.slice(e,t+1)}const basePlugin=o=>({postcssPlugin:"postcss-gradients-interpolation-method",Declaration(i){if(!P.test(i.value))return;if(e(i))return;if(t(i,P))return;const r=g({css:i.value}),n=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o);e&&(o.value=e)})));if(n===i.value)return;const s=c(u(p(r),(o=>{if(!v(o))return;const e=modifyGradientFunctionComponentValues(o,!0);e&&(o.value=e)})));i.cloneBefore({value:n}),n!==s&&i.cloneBefore({value:s}),o?.preserve||i.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},e);return t.enableProgressiveCustomProperties?{postcssPlugin:"postcss-gradients-interpolation-method",plugins:[o(),basePlugin(t)]}:basePlugin(t)};postcssPlugin.postcss=!0;export{postcssPlugin as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csstools/postcss-gradients-interpolation-method",
|
|
3
3
|
"description": "Use interpolation methods in CSS gradient functions",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.17",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "MIT-0",
|
|
7
7
|
"funding": [
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@csstools/css-color-parser": "^2.0.
|
|
42
|
-
"@csstools/css-parser-algorithms": "^2.6.
|
|
43
|
-
"@csstools/css-tokenizer": "^2.
|
|
41
|
+
"@csstools/css-color-parser": "^2.0.2",
|
|
42
|
+
"@csstools/css-parser-algorithms": "^2.6.3",
|
|
43
|
+
"@csstools/css-tokenizer": "^2.3.1",
|
|
44
44
|
"@csstools/postcss-progressive-custom-properties": "^3.2.0",
|
|
45
45
|
"@csstools/utilities": "^1.0.0"
|
|
46
46
|
},
|