postcss-lab-function 4.0.0 → 4.0.4
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 +72 -0
- package/README.md +6 -6
- package/dist/color.d.ts +3 -0
- package/dist/has-supports-at-rule-ancestor.d.ts +2 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +1 -0
- package/dist/on-css-function.d.ts +3 -0
- package/package.json +38 -47
- package/dist/index.cjs.js +0 -194
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -192
- package/dist/index.esm.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Changes to PostCSS Lab Function
|
|
2
|
+
|
|
3
|
+
### 4.0.4 (February 5, 2022)
|
|
4
|
+
|
|
5
|
+
- Improved `es module` and `commonjs` compatibility
|
|
6
|
+
|
|
7
|
+
### 4.0.3 (January 2, 2022)
|
|
8
|
+
|
|
9
|
+
- Removed Sourcemaps from package tarball.
|
|
10
|
+
- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
|
|
11
|
+
|
|
12
|
+
### 4.0.2 (December 13, 2021)
|
|
13
|
+
|
|
14
|
+
- Changed: now uses `postcss-value-parser` for parsing.
|
|
15
|
+
- Updated: documentation
|
|
16
|
+
- Added: support for CSS variables with `preserve: true` option.
|
|
17
|
+
- Fixed: Hue values with units in `lch` functions are now correctly handled.
|
|
18
|
+
- Fixed: Rounding of values to match current browser behavior.
|
|
19
|
+
|
|
20
|
+
### 4.0.1 (November 18, 2021)
|
|
21
|
+
|
|
22
|
+
- Added: Safeguards against postcss-values-parser potentially throwing an error.
|
|
23
|
+
- Updated: postcss-value-parser to 6.0.1 (patch)
|
|
24
|
+
|
|
25
|
+
### 4.0.0 (September 17, 2021)
|
|
26
|
+
|
|
27
|
+
- Updated: Support for PostCS 8+ (major).
|
|
28
|
+
- Updated: Support for Node 12+ (major).
|
|
29
|
+
|
|
30
|
+
### 3.1.2 (April 25, 2020)
|
|
31
|
+
|
|
32
|
+
- Updated: Publish
|
|
33
|
+
|
|
34
|
+
### 3.1.1 (April 25, 2020)
|
|
35
|
+
|
|
36
|
+
- Updated: Using `walkType` to evade walker bug in `postcss-values-parser`
|
|
37
|
+
|
|
38
|
+
### 3.1.0 (April 25, 2020)
|
|
39
|
+
|
|
40
|
+
- Updated: `postcss-values-parser` to 3.2.0 (minor).
|
|
41
|
+
|
|
42
|
+
### 3.0.1 (April 12, 2020)
|
|
43
|
+
|
|
44
|
+
- Updated: Ownership moved to CSSTools.
|
|
45
|
+
|
|
46
|
+
### 3.0.0 (April 12, 2020)
|
|
47
|
+
|
|
48
|
+
- Updated: `postcss-values-parser` to 3.1.1 (major).
|
|
49
|
+
- Updated: Node support to 10.0.0 (major).
|
|
50
|
+
- Updated: Feature to use new percentage syntax.
|
|
51
|
+
- Removed: Support for the removed `gray()` function.
|
|
52
|
+
|
|
53
|
+
### 2.0.1 (September 18, 2018)
|
|
54
|
+
|
|
55
|
+
- Updated: PostCSS Values Parser 2.0.0
|
|
56
|
+
|
|
57
|
+
### 2.0.0 (September 17, 2018)
|
|
58
|
+
|
|
59
|
+
- Updated: Support for PostCSS 7+
|
|
60
|
+
- Updated: Support for Node 6+
|
|
61
|
+
|
|
62
|
+
### 1.1.0 (July 24, 2018)
|
|
63
|
+
|
|
64
|
+
- Added: Support for `gray(a / b)` as `lab(a 0 0 / b)`
|
|
65
|
+
|
|
66
|
+
### 1.0.1 (May 11, 2018)
|
|
67
|
+
|
|
68
|
+
- Fixed: Values beyond the acceptable 0-255 RGB range
|
|
69
|
+
|
|
70
|
+
### 1.0.0 (May 11, 2018)
|
|
71
|
+
|
|
72
|
+
- Initial version
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# PostCSS Lab Function [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|
2
2
|
|
|
3
3
|
[<img alt="npm version" src="https://img.shields.io/npm/v/postcss-lab-function.svg" height="20">][npm-url]
|
|
4
|
-
[<img alt="CSS Standard Status" src="https://cssdb.org/
|
|
5
|
-
[<img alt="Build Status" src="https://github.com/csstools/postcss-
|
|
6
|
-
[<img alt="
|
|
4
|
+
[<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/lab-function.svg" height="20">][css-url]
|
|
5
|
+
[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
|
|
6
|
+
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
[PostCSS Lab Function] lets you use `lab` and `lch` color functions in
|
|
@@ -75,9 +75,9 @@ postcssLabFunction({ preserve: true })
|
|
|
75
75
|
}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
[cli-url]: https://github.com/csstools/postcss-
|
|
78
|
+
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|
79
79
|
[css-url]: https://cssdb.org/#lab-function
|
|
80
|
-
[
|
|
80
|
+
[discord]: https://discord.gg/bUadyRwkJS
|
|
81
81
|
[npm-url]: https://www.npmjs.com/package/postcss-lab-function
|
|
82
82
|
|
|
83
83
|
[CSS Color]: https://drafts.csswg.org/css-color/#specifying-lab-lch
|
|
@@ -85,4 +85,4 @@ postcssLabFunction({ preserve: true })
|
|
|
85
85
|
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|
86
86
|
[PostCSS]: https://github.com/postcss/postcss
|
|
87
87
|
[PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|
88
|
-
[PostCSS Lab Function]: https://github.com/csstools/postcss-lab-function
|
|
88
|
+
[PostCSS Lab Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-lab-function
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function labToSRgb(lab: [number, number, number]): [number, number, number];
|
|
2
|
+
export declare function lchToSRgb(lch: [number, number, number]): [number, number, number];
|
|
3
|
+
export declare function xyz2rgb(xyz: [number, number, number]): [number, number, number];
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=t(require("postcss-value-parser"));function n(t){return a(u(t,!0))}function r(t){return a(u(function(t){return[t[0],t[1]*Math.cos(t[2]*Math.PI/180),t[1]*Math.sin(t[2]*Math.PI/180)]}(t),!1))}function u(t,e){const[n,r,u]=t,a=Math.min(Math.max(n,0),100);let l=0,p=0;e?(l=Math.min(Math.max(r,-127),128),p=Math.min(Math.max(u,-127),128)):(l=r,p=u);const v=(a+16)/116,h=l/500+v,b=v-p/200,[m,M,g]=[Math.pow(h,3)>s?Math.pow(h,3):(116*h-16)/d,a>d*s?Math.pow((a+16)/116,3):a/d,Math.pow(b,3)>s?Math.pow(b,3):(116*b-16)/d],[w,y,x]=o([m*i,M*c,g*f],[[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]]);return[w,y,x]}function a(t){const[e,n,r]=t,[u,a,l]=o([e,n,r],[[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]]),[i,c,f]=[u,a,l].map((t=>t>.31308?1.055*Math.pow(t/100,1/2.4)*100-5.5:12.92*t));return[i,c,f]}function o(t,e){return e.map((e=>e.reduce(((e,n,r)=>e+t[r]*l*(n*l)/l/l),0)))}const l=1e8,[i,c,f]=[96.422,100,82.521],s=Math.pow(6,3)/Math.pow(29,3),d=Math.pow(29,3)/Math.pow(3,3);function p(t){const u=t.value,a=t.nodes.slice().filter((t=>"comment"!==t.type&&"space"!==t.type));let o=null;if("lab"===u?o=function(t){if(!h(t[0]))return null;if(!v(t[1]))return null;if(!v(t[2]))return null;const n={l:e.default.unit(t[0].value),lNode:t[0],a:e.default.unit(t[1].value),aNode:t[1],b:e.default.unit(t[2].value),bNode:t[2]};M(t[3])&&(n.slash=t[3]);(b(t[4])||m(t[4]))&&(n.alpha=t[4]);return n}(a):"lch"===u&&(o=function(t){if(!h(t[0]))return null;if(!v(t[1]))return null;if(!function(t){if(!t||"word"!==t.type)return!1;if(!y(t))return!1;const n=e.default.unit(t.value);if(!n)return!1;return!!n.number&&("deg"===n.unit||"grad"===n.unit||"rad"===n.unit||"turn"===n.unit||""===n.unit)}(t[2]))return null;const n={l:e.default.unit(t[0].value),lNode:t[0],c:e.default.unit(t[1].value),cNode:t[1],h:e.default.unit(t[2].value),hNode:t[2]};if(function(t){switch(t.unit){case"deg":return void(t.unit="");case"rad":return t.unit="",void(t.number=(180*parseFloat(t.number)/Math.PI).toString());case"grad":return t.unit="",void(t.number=(.9*parseFloat(t.number)).toString());case"turn":t.unit="",t.number=(360*parseFloat(t.number)).toString()}}(n.h),""!==n.h.unit)return null;M(t[3])&&(n.slash=t[3]);(b(t[4])||m(t[4])||function(t){return t&&"function"===t.type&&"var"===t.value}(t[4]))&&(n.alpha=t[4]);return n}(a)),!o)return;if(a.length>3&&(!o.slash||!o.alpha))return;t.value="rgb",function(t,n,r){if(!n||!r)return;if(t.value="rgba",n.value=",",n.before="",!function(t){if(!t||"word"!==t.type)return!1;if(!y(t))return!1;const n=e.default.unit(t.value);if(!n)return!1;return!!n.number}(r))return;const u=e.default.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(t,o.slash,o.alpha);const[l,i,c]=function(t){if(g(t))return[t.lNode,t.aNode,t.bNode];return[t.lNode,t.cNode,t.hNode]}(o),[f,s,d]=function(t){if(g(t))return[t.l,t.a,t.b];return[t.l,t.c,t.h]}(o),p=("lab"===u?n:r)([f.number,s.number,d.number].map((t=>parseFloat(t)))).map((t=>Math.max(Math.min(Math.round(2.55*t),255),0)));t.nodes.splice(t.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.splice(t.nodes.indexOf(i)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),w(t.nodes,l,{...l,value:String(p[0])}),w(t.nodes,i,{...i,value:String(p[1])}),w(t.nodes,c,{...c,value:String(p[2])})}function v(t){if(!t||"word"!==t.type)return!1;if(!y(t))return!1;const n=e.default.unit(t.value);return!!n&&(!!n.number&&""===n.unit)}function h(t){if(!t||"word"!==t.type)return!1;if(!y(t))return!1;const n=e.default.unit(t.value);return!!n&&"%"===n.unit}function b(t){if(!t||"word"!==t.type)return!1;if(!y(t))return!1;const n=e.default.unit(t.value);return!!n&&("%"===n.unit||""===n.unit)}function m(t){return t&&"function"===t.type&&"calc"===t.value}function M(t){return t&&"div"===t.type&&"/"===t.value}function g(t){return void 0!==t.a}function w(t,e,n){const r=t.indexOf(e);t[r]=n}function y(t){if(!t||!t.value)return!1;try{return!1!==e.default.unit(t.value)}catch(t){return!1}}const x=t=>{const n="preserve"in Object(t)&&Boolean(t.preserve);return{postcssPlugin:"postcss-lab-function",Declaration:(t,{result:r,postcss:u})=>{if(n&&function(t){let e=t.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("(color: lab(0% 0 0)) and (color: lch(0% 0 0))"))return!0;e=e.parent}else e=e.parent;return!1}(t))return;const a=t.value;if(!/(^|[^\w-])(lab|lch)\(/i.test(a))return;let o;try{o=e.default(a)}catch(e){t.warn(r,`Failed to parse value '${a}' as a lab or hcl function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((t=>{t.type&&"function"===t.type&&("lab"!==t.value&&"lch"!==t.value||p(t))}));const l=String(o);if(l!==a)if(n&&t.variable){const e=t.parent,n="(color: lab(0% 0 0)) and (color: lch(0% 0 0))",r=u.atRule({name:"supports",params:n,source:t.source}),a=e.clone();a.removeAll(),a.append(t.clone()),r.append(a);let o=e,i=e.next();for(;o&&i&&"atrule"===i.type&&"supports"===i.name&&i.params===n;)o=i,i=i.next();o.after(r),t.value=l}else n?t.cloneBefore({value:l}):t.value=l}}};x.postcss=!0,x._labToSRgb=n,x._lchToSRgb=r,module.exports=x;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import n from"postcss-value-parser";function t(n){return u(r(n,!0))}function e(n){return u(r(function(n){return[n[0],n[1]*Math.cos(n[2]*Math.PI/180),n[1]*Math.sin(n[2]*Math.PI/180)]}(n),!1))}function r(n,t){const[e,r,u]=n,o=Math.min(Math.max(e,0),100);let p=0,d=0;t?(p=Math.min(Math.max(r,-127),128),d=Math.min(Math.max(u,-127),128)):(p=r,d=u);const h=(o+16)/116,v=p/500+h,m=h-d/200,[b,M,g]=[Math.pow(v,3)>s?Math.pow(v,3):(116*v-16)/f,o>f*s?Math.pow((o+16)/116,3):o/f,Math.pow(m,3)>s?Math.pow(m,3):(116*m-16)/f],[w,y,x]=a([b*i,M*l,g*c],[[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]]);return[w,y,x]}function u(n){const[t,e,r]=n,[u,o,i]=a([t,e,r],[[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]]),[l,c,s]=[u,o,i].map((n=>n>.31308?1.055*Math.pow(n/100,1/2.4)*100-5.5:12.92*n));return[l,c,s]}function a(n,t){return t.map((t=>t.reduce(((t,e,r)=>t+n[r]*o*(e*o)/o/o),0)))}const o=1e8,[i,l,c]=[96.422,100,82.521],s=Math.pow(6,3)/Math.pow(29,3),f=Math.pow(29,3)/Math.pow(3,3);function p(r){const u=r.value,a=r.nodes.slice().filter((n=>"comment"!==n.type&&"space"!==n.type));let o=null;if("lab"===u?o=function(t){if(!h(t[0]))return null;if(!d(t[1]))return null;if(!d(t[2]))return null;const e={l:n.unit(t[0].value),lNode:t[0],a:n.unit(t[1].value),aNode:t[1],b:n.unit(t[2].value),bNode:t[2]};b(t[3])&&(e.slash=t[3]);(v(t[4])||m(t[4]))&&(e.alpha=t[4]);return e}(a):"lch"===u&&(o=function(t){if(!h(t[0]))return null;if(!d(t[1]))return null;if(!function(t){if(!t||"word"!==t.type)return!1;if(!w(t))return!1;const e=n.unit(t.value);if(!e)return!1;return!!e.number&&("deg"===e.unit||"grad"===e.unit||"rad"===e.unit||"turn"===e.unit||""===e.unit)}(t[2]))return null;const e={l:n.unit(t[0].value),lNode:t[0],c:n.unit(t[1].value),cNode:t[1],h:n.unit(t[2].value),hNode:t[2]};if(function(n){switch(n.unit){case"deg":return void(n.unit="");case"rad":return n.unit="",void(n.number=(180*parseFloat(n.number)/Math.PI).toString());case"grad":return n.unit="",void(n.number=(.9*parseFloat(n.number)).toString());case"turn":n.unit="",n.number=(360*parseFloat(n.number)).toString()}}(e.h),""!==e.h.unit)return null;b(t[3])&&(e.slash=t[3]);(v(t[4])||m(t[4])||function(n){return n&&"function"===n.type&&"var"===n.value}(t[4]))&&(e.alpha=t[4]);return e}(a)),!o)return;if(a.length>3&&(!o.slash||!o.alpha))return;r.value="rgb",function(t,e,r){if(!e||!r)return;if(t.value="rgba",e.value=",",e.before="",!function(t){if(!t||"word"!==t.type)return!1;if(!w(t))return!1;const e=n.unit(t.value);if(!e)return!1;return!!e.number}(r))return;const u=n.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(r,o.slash,o.alpha);const[i,l,c]=function(n){if(M(n))return[n.lNode,n.aNode,n.bNode];return[n.lNode,n.cNode,n.hNode]}(o),[s,f,p]=function(n){if(M(n))return[n.l,n.a,n.b];return[n.l,n.c,n.h]}(o),y=("lab"===u?t:e)([s.number,f.number,p.number].map((n=>parseFloat(n)))).map((n=>Math.max(Math.min(Math.round(2.55*n),255),0)));r.nodes.splice(r.nodes.indexOf(i)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),r.nodes.splice(r.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),g(r.nodes,i,{...i,value:String(y[0])}),g(r.nodes,l,{...l,value:String(y[1])}),g(r.nodes,c,{...c,value:String(y[2])})}function d(t){if(!t||"word"!==t.type)return!1;if(!w(t))return!1;const e=n.unit(t.value);return!!e&&(!!e.number&&""===e.unit)}function h(t){if(!t||"word"!==t.type)return!1;if(!w(t))return!1;const e=n.unit(t.value);return!!e&&"%"===e.unit}function v(t){if(!t||"word"!==t.type)return!1;if(!w(t))return!1;const e=n.unit(t.value);return!!e&&("%"===e.unit||""===e.unit)}function m(n){return n&&"function"===n.type&&"calc"===n.value}function b(n){return n&&"div"===n.type&&"/"===n.value}function M(n){return void 0!==n.a}function g(n,t,e){const r=n.indexOf(t);n[r]=e}function w(t){if(!t||!t.value)return!1;try{return!1!==n.unit(t.value)}catch(n){return!1}}const y=t=>{const e="preserve"in Object(t)&&Boolean(t.preserve);return{postcssPlugin:"postcss-lab-function",Declaration:(t,{result:r,postcss:u})=>{if(e&&function(n){let t=n.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name&&-1!==t.params.indexOf("(color: lab(0% 0 0)) and (color: lch(0% 0 0))"))return!0;t=t.parent}else t=t.parent;return!1}(t))return;const a=t.value;if(!/(^|[^\w-])(lab|lch)\(/i.test(a))return;let o;try{o=n(a)}catch(n){t.warn(r,`Failed to parse value '${a}' as a lab or hcl function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((n=>{n.type&&"function"===n.type&&("lab"!==n.value&&"lch"!==n.value||p(n))}));const i=String(o);if(i!==a)if(e&&t.variable){const n=t.parent,e="(color: lab(0% 0 0)) and (color: lch(0% 0 0))",r=u.atRule({name:"supports",params:e,source:t.source}),a=n.clone();a.removeAll(),a.append(t.clone()),r.append(a);let o=n,l=n.next();for(;o&&l&&"atrule"===l.type&&"supports"===l.name&&l.params===e;)o=l,l=l.next();o.after(r),t.value=i}else e?t.cloneBefore({value:i}):t.value=i}}};y.postcss=!0,y._labToSRgb=t,y._lchToSRgb=e;export{y as default};
|
package/package.json
CHANGED
|
@@ -1,65 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-lab-function",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Use lab() and lch() color functions in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
7
|
+
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-lab-function#readme",
|
|
8
|
+
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
9
|
+
"main": "dist/index.cjs",
|
|
10
|
+
"module": "dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
12
19
|
"files": [
|
|
20
|
+
"CHANGELOG.md",
|
|
21
|
+
"LICENSE.md",
|
|
22
|
+
"README.md",
|
|
13
23
|
"dist"
|
|
14
24
|
],
|
|
15
25
|
"scripts": {
|
|
16
|
-
"build": "
|
|
17
|
-
"
|
|
18
|
-
"lint": "
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"test": "
|
|
22
|
-
"
|
|
23
|
-
"prepublishOnly": "npm test"
|
|
26
|
+
"build": "rollup -c ../../rollup/default.js",
|
|
27
|
+
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
|
|
28
|
+
"lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
|
|
29
|
+
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
30
|
+
"stryker": "stryker run --logLevel error",
|
|
31
|
+
"test": "node ./test/color/test.mjs && postcss-tape --ci && npm run test:exports",
|
|
32
|
+
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
|
|
24
33
|
},
|
|
25
34
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
35
|
+
"node": "^12 || ^14 || >=16"
|
|
27
36
|
},
|
|
28
37
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"postcss-values-parser": "6.0.0"
|
|
31
|
-
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"postcss": "^8.3"
|
|
38
|
+
"postcss-value-parser": "^4.2.0"
|
|
34
39
|
},
|
|
35
40
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"@rollup/plugin-babel": "5.3.0",
|
|
39
|
-
"eslint": "7.32.0",
|
|
40
|
-
"postcss": "8.3.6",
|
|
41
|
-
"postcss-tape": "6.0.1",
|
|
42
|
-
"rollup": "2.56.3"
|
|
43
|
-
},
|
|
44
|
-
"babel": {
|
|
45
|
-
"presets": [
|
|
46
|
-
[
|
|
47
|
-
"@babel/env",
|
|
48
|
-
{
|
|
49
|
-
"targets": "maintained node versions"
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
]
|
|
41
|
+
"postcss": "^8.3.6",
|
|
42
|
+
"postcss-tape": "^6.0.1"
|
|
53
43
|
},
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"es6": true,
|
|
57
|
-
"node": true
|
|
58
|
-
},
|
|
59
|
-
"extends": "eslint:recommended",
|
|
60
|
-
"parserOptions": {
|
|
61
|
-
"sourceType": "module"
|
|
62
|
-
}
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"postcss": "^8.4"
|
|
63
46
|
},
|
|
64
47
|
"keywords": [
|
|
65
48
|
"postcss",
|
|
@@ -78,5 +61,13 @@
|
|
|
78
61
|
"syntax",
|
|
79
62
|
"space",
|
|
80
63
|
"comma"
|
|
81
|
-
]
|
|
64
|
+
],
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
68
|
+
"directory": "plugins/postcss-lab-function"
|
|
69
|
+
},
|
|
70
|
+
"volta": {
|
|
71
|
+
"extends": "../../package.json"
|
|
72
|
+
}
|
|
82
73
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var postcssValuesParser = require('postcss-values-parser');
|
|
4
|
-
var convertColors = require('@csstools/convert-colors');
|
|
5
|
-
|
|
6
|
-
/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */
|
|
7
|
-
|
|
8
|
-
const onCSSFunction = node => {
|
|
9
|
-
/** @type {{ name: string, nodes: CSSNode[] }} */
|
|
10
|
-
const {
|
|
11
|
-
name,
|
|
12
|
-
nodes
|
|
13
|
-
} = node;
|
|
14
|
-
|
|
15
|
-
if (isColorFunctionName(name)) {
|
|
16
|
-
if (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {
|
|
17
|
-
// rename the Color function to `rgb`
|
|
18
|
-
Object.assign(node, {
|
|
19
|
-
name: 'rgb'
|
|
20
|
-
});
|
|
21
|
-
/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */
|
|
22
|
-
|
|
23
|
-
const slashNode = nodes[3];
|
|
24
|
-
/** @type {CSSNumber} Alpha channel. */
|
|
25
|
-
|
|
26
|
-
const alphaNode = nodes[4];
|
|
27
|
-
|
|
28
|
-
if (alphaNode) {
|
|
29
|
-
if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
|
|
30
|
-
// transform the Alpha channel from a Percentage to (0-1) Number
|
|
31
|
-
Object.assign(alphaNode, {
|
|
32
|
-
value: String(alphaNode.value / 100),
|
|
33
|
-
unit: ''
|
|
34
|
-
});
|
|
35
|
-
} // if the color is fully opaque (i.e. the Alpha channel is `1`)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (alphaNode.value === '1') {
|
|
39
|
-
// remove the Slash and Alpha channel
|
|
40
|
-
slashNode.remove();
|
|
41
|
-
alphaNode.remove();
|
|
42
|
-
} else {
|
|
43
|
-
// otherwise, rename the Color function to `rgba`
|
|
44
|
-
Object.assign(node, {
|
|
45
|
-
name: 'rgba'
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
} // replace a remaining Slash with a Comma
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (slashNode && isSlash(slashNode)) {
|
|
52
|
-
slashNode.replaceWith(commaNode.clone());
|
|
53
|
-
}
|
|
54
|
-
/** Extracted Color channels. */
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const [channelNode1, channelNode2, channelNode3] = nodes;
|
|
58
|
-
/** Corresponding Color transformer. */
|
|
59
|
-
|
|
60
|
-
const toRGB = isLabColorFunctionName(name) ? convertColors.lab2rgb : convertColors.lch2rgb;
|
|
61
|
-
/** RGB channels from the source color. */
|
|
62
|
-
|
|
63
|
-
const rgbValues = toRGB(...[channelNode1.value, channelNode2.value, channelNode3.value].map(channelNumber => parseFloat(channelNumber))).map(channelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0));
|
|
64
|
-
channelNode3.replaceWith(channelNode3.clone({
|
|
65
|
-
value: String(rgbValues[2])
|
|
66
|
-
}));
|
|
67
|
-
channelNode2.replaceWith(channelNode2.clone({
|
|
68
|
-
value: String(rgbValues[1])
|
|
69
|
-
}), commaNode.clone());
|
|
70
|
-
channelNode1.replaceWith(channelNode1.clone({
|
|
71
|
-
value: String(rgbValues[0]),
|
|
72
|
-
unit: ''
|
|
73
|
-
}), commaNode.clone());
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const commaNode = postcssValuesParser.parse(',').first;
|
|
78
|
-
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
79
|
-
|
|
80
|
-
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
81
|
-
/** Return whether the function name is `lab` or `lch`. */
|
|
82
|
-
|
|
83
|
-
const isColorFunctionName = createRegExpTest$1(/^(lab|lch)$/i);
|
|
84
|
-
/** Return whether the function name is `calc`. */
|
|
85
|
-
|
|
86
|
-
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
87
|
-
/** Return whether the function name is `lab`. */
|
|
88
|
-
|
|
89
|
-
const isLabColorFunctionName = createRegExpTest$1(/^lab$/i);
|
|
90
|
-
/** Return whether the unit is alpha-like. */
|
|
91
|
-
|
|
92
|
-
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
93
|
-
/** Return whether the unit is hue-like. */
|
|
94
|
-
|
|
95
|
-
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
96
|
-
/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */
|
|
97
|
-
|
|
98
|
-
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
99
|
-
/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const isCalc = node => node.type === 'func' && isCalcFunctionName(node.name);
|
|
103
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit);
|
|
107
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === '';
|
|
111
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%';
|
|
115
|
-
/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const isSlash = node => node.type === 'operator' && node.value === '/';
|
|
119
|
-
/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const isLabFunctionContents = nodes => nodes.every((node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node));
|
|
123
|
-
/** Set of nodes in a lab() function. */
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue];
|
|
127
|
-
/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */
|
|
128
|
-
|
|
129
|
-
const isLchFunctionContents = nodes => nodes.every((node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node));
|
|
130
|
-
/** Set of nodes in a lch() function. */
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue];
|
|
134
|
-
/** @typedef {import('postcss-values-parser').Func} CSSFunction */
|
|
135
|
-
|
|
136
|
-
/** @typedef {import('postcss-values-parser').Node} CSSNode */
|
|
137
|
-
|
|
138
|
-
/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */
|
|
139
|
-
|
|
140
|
-
/** @typedef {import('postcss-values-parser').Operator} CSSOperator */
|
|
141
|
-
|
|
142
|
-
/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */
|
|
143
|
-
|
|
144
|
-
var options = {
|
|
145
|
-
/** Whether to preserve the original functional color declaration. */
|
|
146
|
-
preserve: false
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */
|
|
150
|
-
|
|
151
|
-
const onCSSDeclaration = decl => {
|
|
152
|
-
const {
|
|
153
|
-
value: originalValue
|
|
154
|
-
} = decl;
|
|
155
|
-
|
|
156
|
-
if (hasAnyColorFunction(originalValue)) {
|
|
157
|
-
const valueAST = postcssValuesParser.parse(originalValue);
|
|
158
|
-
valueAST.walkType('func', onCSSFunction);
|
|
159
|
-
const modifiedValue = String(valueAST);
|
|
160
|
-
|
|
161
|
-
if (modifiedValue !== originalValue) {
|
|
162
|
-
if (options.preserve) decl.cloneBefore({
|
|
163
|
-
value: modifiedValue
|
|
164
|
-
});else decl.value = modifiedValue;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
169
|
-
|
|
170
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
171
|
-
/** Return whether the value has a lab() or lch() function. */
|
|
172
|
-
|
|
173
|
-
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(lab|lch)\(/i);
|
|
174
|
-
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
175
|
-
|
|
176
|
-
/** Transform lab() and lch() functions in CSS. */
|
|
177
|
-
|
|
178
|
-
const postcssPlugin =
|
|
179
|
-
/** @type {PostCSSPluginInitializer} */
|
|
180
|
-
opts => {
|
|
181
|
-
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
182
|
-
return {
|
|
183
|
-
postcssPlugin: 'postcss-lab-function',
|
|
184
|
-
Declaration: onCSSDeclaration
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
postcssPlugin.postcss = true;
|
|
189
|
-
/** @typedef {import('postcss').Plugin} PostCSSPlugin */
|
|
190
|
-
|
|
191
|
-
/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */
|
|
192
|
-
|
|
193
|
-
module.exports = postcssPlugin;
|
|
194
|
-
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/onCSSFunction.js","../src/options.js","../src/onCSSDeclaration.js","../src/index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors'\nimport { parse } from 'postcss-values-parser'\n\n/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */\nconst onCSSFunction = node => {\n\t/** @type {{ name: string, nodes: CSSNode[] }} */\n\tconst { name, nodes } = node\n\n\tif (isColorFunctionName(name)) {\n\t\tif (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {\n\t\t\t// rename the Color function to `rgb`\n\t\t\tObject.assign(node, { name: 'rgb' })\n\n\t\t\t/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */\n\t\t\tconst slashNode = nodes[3]\n\n\t\t\t/** @type {CSSNumber} Alpha channel. */\n\t\t\tconst alphaNode = nodes[4]\n\n\t\t\tif (alphaNode) {\n\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t// transform the Alpha channel from a Percentage to (0-1) Number\n\t\t\t\t\tObject.assign(alphaNode, { value: String(alphaNode.value / 100), unit: '' })\n\t\t\t\t}\n\n\t\t\t\t// if the color is fully opaque (i.e. the Alpha channel is `1`)\n\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t// remove the Slash and Alpha channel\n\t\t\t\t\tslashNode.remove()\n\t\t\t\t\talphaNode.remove()\n\t\t\t\t} else {\n\t\t\t\t\t// otherwise, rename the Color function to `rgba`\n\t\t\t\t\tObject.assign(node, { name: 'rgba' })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// replace a remaining Slash with a Comma\n\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\tslashNode.replaceWith(commaNode.clone())\n\t\t\t}\n\n\t\t\t/** Extracted Color channels. */\n\t\t\tconst [channelNode1, channelNode2, channelNode3] = nodes\n\n\t\t\t/** Corresponding Color transformer. */\n\t\t\tconst toRGB = isLabColorFunctionName(name) ? lab2rgb : lch2rgb\n\n\t\t\t/** RGB channels from the source color. */\n\t\t\tconst rgbValues = toRGB(\n\t\t\t\t...[\n\t\t\t\t\tchannelNode1.value,\n\t\t\t\t\tchannelNode2.value,\n\t\t\t\t\tchannelNode3.value\n\t\t\t\t].map(\n\t\t\t\t\tchannelNumber => parseFloat(channelNumber)\n\t\t\t\t)\n\t\t\t).map(\n\t\t\t\tchannelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0)\n\t\t\t)\n\n\t\t\tchannelNode3.replaceWith(\n\t\t\t\tchannelNode3.clone({ value: String(rgbValues[2]) })\n\t\t\t)\n\n\t\t\tchannelNode2.replaceWith(\n\t\t\t\tchannelNode2.clone({ value: String(rgbValues[1]) }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\n\t\t\tchannelNode1.replaceWith(\n\t\t\t\tchannelNode1.clone({ value: String(rgbValues[0]), unit: '' }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\t\t}\n\t}\n}\n\nexport default onCSSFunction\n\nconst commaNode = parse(',').first\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the function name is `lab` or `lch`. */\nconst isColorFunctionName = createRegExpTest(/^(lab|lch)$/i)\n\n/** Return whether the function name is `calc`. */\nconst isCalcFunctionName = createRegExpTest(/^calc$/i)\n\n/** Return whether the function name is `lab`. */\nconst isLabColorFunctionName = createRegExpTest(/^lab$/i)\n\n/** Return whether the unit is alpha-like. */\nconst isAlphaLikeUnit = createRegExpTest(/^%?$/i)\n\n/** Return whether the unit is hue-like. */\nconst isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */\nconst isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */\nconst isCalc = node => node.type === 'func' && isCalcFunctionName(node.name)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */\nconst isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */\nconst isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === ''\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */\nconst isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%'\n\n/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */\nconst isSlash = node => node.type === 'operator' && node.value === '/'\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */\nconst isLabFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node)\n)\n\n/** Set of nodes in a lab() function. */\nconst labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue]\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */\nconst isLchFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node)\n)\n\n/** Set of nodes in a lch() function. */\nconst lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue]\n\n/** @typedef {import('postcss-values-parser').Func} CSSFunction */\n/** @typedef {import('postcss-values-parser').Node} CSSNode */\n/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */\n/** @typedef {import('postcss-values-parser').Operator} CSSOperator */\n/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */\n","export default {\n\t/** Whether to preserve the original functional color declaration. */\n\tpreserve: false\n}\n","import { parse } from 'postcss-values-parser'\nimport onCSSFunction from './onCSSFunction'\nimport options from './options'\n\n/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */\nconst onCSSDeclaration = decl => {\n\tconst { value: originalValue } = decl\n\n\tif (hasAnyColorFunction(originalValue)) {\n\t\tconst valueAST = parse(originalValue)\n\n\t\tvalueAST.walkType('func', onCSSFunction)\n\n\t\tconst modifiedValue = String(valueAST)\n\n\t\tif (modifiedValue !== originalValue) {\n\t\t\tif (options.preserve) decl.cloneBefore({ value: modifiedValue })\n\t\t\telse decl.value = modifiedValue\n\t\t}\n\t}\n}\n\nexport default onCSSDeclaration\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the value has a lab() or lch() function. */\nconst hasAnyColorFunction = createRegExpTest(/(^|[^\\w-])(lab|lch)\\(/i)\n\n/** @typedef {import('postcss').Declaration} CSSDeclaration */\n","import onCSSDeclaration from './onCSSDeclaration'\nimport options from './options'\n\n/** Transform lab() and lch() functions in CSS. */\nconst postcssPlugin = /** @type {PostCSSPluginInitializer} */ opts => {\n\toptions.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false\n\n\treturn {\n\t\tpostcssPlugin: 'postcss-lab-function',\n\t\tDeclaration: onCSSDeclaration,\n\t}\n}\n\npostcssPlugin.postcss = true\n\nexport default postcssPlugin\n\n/** @typedef {import('postcss').Plugin} PostCSSPlugin */\n/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */\n"],"names":["onCSSFunction","node","name","nodes","isColorFunctionName","isLabFunctionContents","isLchFunctionContents","Object","assign","slashNode","alphaNode","isPercentage","isCalc","value","String","unit","remove","isSlash","replaceWith","commaNode","clone","channelNode1","channelNode2","channelNode3","toRGB","isLabColorFunctionName","lab2rgb","lch2rgb","rgbValues","map","channelNumber","parseFloat","channelValue","Math","max","min","parseInt","parse","first","createRegExpTest","Function","bind","RegExp","prototype","test","isCalcFunctionName","isAlphaLikeUnit","isHueLikeUnit","isAlphaValue","type","isHue","isNumber","every","index","labFunctionContents","lchFunctionContents","preserve","onCSSDeclaration","decl","originalValue","hasAnyColorFunction","valueAST","walkType","modifiedValue","options","cloneBefore","postcssPlugin","opts","Boolean","Declaration","postcss"],"mappings":";;;;;AAGA;;AACA,MAAMA,aAAa,GAAGC,IAAI,IAAI;AAC7B;AACA,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBF,IAAxB;;AAEA,MAAIG,mBAAmB,CAACF,IAAD,CAAvB,EAA+B;AAC9B,QAAIG,qBAAqB,CAACF,KAAD,CAArB,IAAgCG,qBAAqB,CAACH,KAAD,CAAzD,EAAkE;AACjE;AACAI,MAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,QAAAA,IAAI,EAAE;AAAR,OAApB;AAEA;;AACA,YAAMO,SAAS,GAAGN,KAAK,CAAC,CAAD,CAAvB;AAEA;;AACA,YAAMO,SAAS,GAAGP,KAAK,CAAC,CAAD,CAAvB;;AAEA,UAAIO,SAAJ,EAAe;AACd,YAAIC,YAAY,CAACD,SAAD,CAAZ,IAA2B,CAACE,MAAM,CAACF,SAAD,CAAtC,EAAmD;AAClD;AACAH,UAAAA,MAAM,CAACC,MAAP,CAAcE,SAAd,EAAyB;AAAEG,YAAAA,KAAK,EAAEC,MAAM,CAACJ,SAAS,CAACG,KAAV,GAAkB,GAAnB,CAAf;AAAwCE,YAAAA,IAAI,EAAE;AAA9C,WAAzB;AACA,SAJa;;;AAOd,YAAIL,SAAS,CAACG,KAAV,KAAoB,GAAxB,EAA6B;AAC5B;AACAJ,UAAAA,SAAS,CAACO,MAAV;AACAN,UAAAA,SAAS,CAACM,MAAV;AACA,SAJD,MAIO;AACN;AACAT,UAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,YAAAA,IAAI,EAAE;AAAR,WAApB;AACA;AACD,OAzBgE;;;AA4BjE,UAAIO,SAAS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A5B;;AAEA,QAAIE,aAAa,KAAKJ,aAAtB,EAAqC;AACpC,UAAIK,OAAO,CAACR,QAAZ,EAAsBE,IAAI,CAACO,WAAL,CAAiB;AAAEpD,QAAAA,KAAK,EAAEkD;AAAT,OAAjB,EAAtB,KACKL,IAAI,CAAC7C,KAAL,GAAakD,aAAb;AACL;AACD;AACD,CAfD;AAmBA;;AACA,MAAMxB,gBAAgB,GAAGC,QAAQ,CAACC,IAAT,CAAcA,IAAd,CAAmBC,MAAM,CAACC,SAAP,CAAiBC,IAApC,CAAzB;AAEA;;AACA,MAAMgB,mBAAmB,GAAGrB,gBAAgB,CAAC,wBAAD,CAA5C;AAEA;;AC3BA;;MACM2B,aAAa;AAAG;AAAwCC,IAAI,IAAI;AACrEH,EAAAA,OAAO,CAACR,QAAR,GAAmB,cAAcjD,MAAM,CAAC4D,IAAD,CAApB,GAA6BC,OAAO,CAACD,IAAI,CAACX,QAAN,CAApC,GAAsD,KAAzE;AAEA,SAAO;AACNU,IAAAA,aAAa,EAAE,sBADT;AAENG,IAAAA,WAAW,EAAEZ;AAFP,GAAP;AAIA;;AAEDS,aAAa,CAACI,OAAd,GAAwB,IAAxB;AAIA;;AACA;;;;"}
|
package/dist/index.esm.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { parse } from 'postcss-values-parser';
|
|
2
|
-
import { lab2rgb, lch2rgb } from '@csstools/convert-colors';
|
|
3
|
-
|
|
4
|
-
/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */
|
|
5
|
-
|
|
6
|
-
const onCSSFunction = node => {
|
|
7
|
-
/** @type {{ name: string, nodes: CSSNode[] }} */
|
|
8
|
-
const {
|
|
9
|
-
name,
|
|
10
|
-
nodes
|
|
11
|
-
} = node;
|
|
12
|
-
|
|
13
|
-
if (isColorFunctionName(name)) {
|
|
14
|
-
if (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {
|
|
15
|
-
// rename the Color function to `rgb`
|
|
16
|
-
Object.assign(node, {
|
|
17
|
-
name: 'rgb'
|
|
18
|
-
});
|
|
19
|
-
/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */
|
|
20
|
-
|
|
21
|
-
const slashNode = nodes[3];
|
|
22
|
-
/** @type {CSSNumber} Alpha channel. */
|
|
23
|
-
|
|
24
|
-
const alphaNode = nodes[4];
|
|
25
|
-
|
|
26
|
-
if (alphaNode) {
|
|
27
|
-
if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
|
|
28
|
-
// transform the Alpha channel from a Percentage to (0-1) Number
|
|
29
|
-
Object.assign(alphaNode, {
|
|
30
|
-
value: String(alphaNode.value / 100),
|
|
31
|
-
unit: ''
|
|
32
|
-
});
|
|
33
|
-
} // if the color is fully opaque (i.e. the Alpha channel is `1`)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (alphaNode.value === '1') {
|
|
37
|
-
// remove the Slash and Alpha channel
|
|
38
|
-
slashNode.remove();
|
|
39
|
-
alphaNode.remove();
|
|
40
|
-
} else {
|
|
41
|
-
// otherwise, rename the Color function to `rgba`
|
|
42
|
-
Object.assign(node, {
|
|
43
|
-
name: 'rgba'
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
} // replace a remaining Slash with a Comma
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (slashNode && isSlash(slashNode)) {
|
|
50
|
-
slashNode.replaceWith(commaNode.clone());
|
|
51
|
-
}
|
|
52
|
-
/** Extracted Color channels. */
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const [channelNode1, channelNode2, channelNode3] = nodes;
|
|
56
|
-
/** Corresponding Color transformer. */
|
|
57
|
-
|
|
58
|
-
const toRGB = isLabColorFunctionName(name) ? lab2rgb : lch2rgb;
|
|
59
|
-
/** RGB channels from the source color. */
|
|
60
|
-
|
|
61
|
-
const rgbValues = toRGB(...[channelNode1.value, channelNode2.value, channelNode3.value].map(channelNumber => parseFloat(channelNumber))).map(channelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0));
|
|
62
|
-
channelNode3.replaceWith(channelNode3.clone({
|
|
63
|
-
value: String(rgbValues[2])
|
|
64
|
-
}));
|
|
65
|
-
channelNode2.replaceWith(channelNode2.clone({
|
|
66
|
-
value: String(rgbValues[1])
|
|
67
|
-
}), commaNode.clone());
|
|
68
|
-
channelNode1.replaceWith(channelNode1.clone({
|
|
69
|
-
value: String(rgbValues[0]),
|
|
70
|
-
unit: ''
|
|
71
|
-
}), commaNode.clone());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const commaNode = parse(',').first;
|
|
76
|
-
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
77
|
-
|
|
78
|
-
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
79
|
-
/** Return whether the function name is `lab` or `lch`. */
|
|
80
|
-
|
|
81
|
-
const isColorFunctionName = createRegExpTest$1(/^(lab|lch)$/i);
|
|
82
|
-
/** Return whether the function name is `calc`. */
|
|
83
|
-
|
|
84
|
-
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
85
|
-
/** Return whether the function name is `lab`. */
|
|
86
|
-
|
|
87
|
-
const isLabColorFunctionName = createRegExpTest$1(/^lab$/i);
|
|
88
|
-
/** Return whether the unit is alpha-like. */
|
|
89
|
-
|
|
90
|
-
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
91
|
-
/** Return whether the unit is hue-like. */
|
|
92
|
-
|
|
93
|
-
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
94
|
-
/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */
|
|
95
|
-
|
|
96
|
-
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
97
|
-
/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const isCalc = node => node.type === 'func' && isCalcFunctionName(node.name);
|
|
101
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit);
|
|
105
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === '';
|
|
109
|
-
/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%';
|
|
113
|
-
/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const isSlash = node => node.type === 'operator' && node.value === '/';
|
|
117
|
-
/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const isLabFunctionContents = nodes => nodes.every((node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node));
|
|
121
|
-
/** Set of nodes in a lab() function. */
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue];
|
|
125
|
-
/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */
|
|
126
|
-
|
|
127
|
-
const isLchFunctionContents = nodes => nodes.every((node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node));
|
|
128
|
-
/** Set of nodes in a lch() function. */
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue];
|
|
132
|
-
/** @typedef {import('postcss-values-parser').Func} CSSFunction */
|
|
133
|
-
|
|
134
|
-
/** @typedef {import('postcss-values-parser').Node} CSSNode */
|
|
135
|
-
|
|
136
|
-
/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */
|
|
137
|
-
|
|
138
|
-
/** @typedef {import('postcss-values-parser').Operator} CSSOperator */
|
|
139
|
-
|
|
140
|
-
/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */
|
|
141
|
-
|
|
142
|
-
var options = {
|
|
143
|
-
/** Whether to preserve the original functional color declaration. */
|
|
144
|
-
preserve: false
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */
|
|
148
|
-
|
|
149
|
-
const onCSSDeclaration = decl => {
|
|
150
|
-
const {
|
|
151
|
-
value: originalValue
|
|
152
|
-
} = decl;
|
|
153
|
-
|
|
154
|
-
if (hasAnyColorFunction(originalValue)) {
|
|
155
|
-
const valueAST = parse(originalValue);
|
|
156
|
-
valueAST.walkType('func', onCSSFunction);
|
|
157
|
-
const modifiedValue = String(valueAST);
|
|
158
|
-
|
|
159
|
-
if (modifiedValue !== originalValue) {
|
|
160
|
-
if (options.preserve) decl.cloneBefore({
|
|
161
|
-
value: modifiedValue
|
|
162
|
-
});else decl.value = modifiedValue;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
167
|
-
|
|
168
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
169
|
-
/** Return whether the value has a lab() or lch() function. */
|
|
170
|
-
|
|
171
|
-
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(lab|lch)\(/i);
|
|
172
|
-
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
173
|
-
|
|
174
|
-
/** Transform lab() and lch() functions in CSS. */
|
|
175
|
-
|
|
176
|
-
const postcssPlugin =
|
|
177
|
-
/** @type {PostCSSPluginInitializer} */
|
|
178
|
-
opts => {
|
|
179
|
-
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
180
|
-
return {
|
|
181
|
-
postcssPlugin: 'postcss-lab-function',
|
|
182
|
-
Declaration: onCSSDeclaration
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
postcssPlugin.postcss = true;
|
|
187
|
-
/** @typedef {import('postcss').Plugin} PostCSSPlugin */
|
|
188
|
-
|
|
189
|
-
/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */
|
|
190
|
-
|
|
191
|
-
export { postcssPlugin as default };
|
|
192
|
-
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/onCSSFunction.js","../src/options.js","../src/onCSSDeclaration.js","../src/index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors'\nimport { parse } from 'postcss-values-parser'\n\n/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */\nconst onCSSFunction = node => {\n\t/** @type {{ name: string, nodes: CSSNode[] }} */\n\tconst { name, nodes } = node\n\n\tif (isColorFunctionName(name)) {\n\t\tif (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {\n\t\t\t// rename the Color function to `rgb`\n\t\t\tObject.assign(node, { name: 'rgb' })\n\n\t\t\t/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */\n\t\t\tconst slashNode = nodes[3]\n\n\t\t\t/** @type {CSSNumber} Alpha channel. */\n\t\t\tconst alphaNode = nodes[4]\n\n\t\t\tif (alphaNode) {\n\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t// transform the Alpha channel from a Percentage to (0-1) Number\n\t\t\t\t\tObject.assign(alphaNode, { value: String(alphaNode.value / 100), unit: '' })\n\t\t\t\t}\n\n\t\t\t\t// if the color is fully opaque (i.e. the Alpha channel is `1`)\n\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t// remove the Slash and Alpha channel\n\t\t\t\t\tslashNode.remove()\n\t\t\t\t\talphaNode.remove()\n\t\t\t\t} else {\n\t\t\t\t\t// otherwise, rename the Color function to `rgba`\n\t\t\t\t\tObject.assign(node, { name: 'rgba' })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// replace a remaining Slash with a Comma\n\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\tslashNode.replaceWith(commaNode.clone())\n\t\t\t}\n\n\t\t\t/** Extracted Color channels. */\n\t\t\tconst [channelNode1, channelNode2, channelNode3] = nodes\n\n\t\t\t/** Corresponding Color transformer. */\n\t\t\tconst toRGB = isLabColorFunctionName(name) ? lab2rgb : lch2rgb\n\n\t\t\t/** RGB channels from the source color. */\n\t\t\tconst rgbValues = toRGB(\n\t\t\t\t...[\n\t\t\t\t\tchannelNode1.value,\n\t\t\t\t\tchannelNode2.value,\n\t\t\t\t\tchannelNode3.value\n\t\t\t\t].map(\n\t\t\t\t\tchannelNumber => parseFloat(channelNumber)\n\t\t\t\t)\n\t\t\t).map(\n\t\t\t\tchannelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0)\n\t\t\t)\n\n\t\t\tchannelNode3.replaceWith(\n\t\t\t\tchannelNode3.clone({ value: String(rgbValues[2]) })\n\t\t\t)\n\n\t\t\tchannelNode2.replaceWith(\n\t\t\t\tchannelNode2.clone({ value: String(rgbValues[1]) }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\n\t\t\tchannelNode1.replaceWith(\n\t\t\t\tchannelNode1.clone({ value: String(rgbValues[0]), unit: '' }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\t\t}\n\t}\n}\n\nexport default onCSSFunction\n\nconst commaNode = parse(',').first\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the function name is `lab` or `lch`. */\nconst isColorFunctionName = createRegExpTest(/^(lab|lch)$/i)\n\n/** Return whether the function name is `calc`. */\nconst isCalcFunctionName = createRegExpTest(/^calc$/i)\n\n/** Return whether the function name is `lab`. */\nconst isLabColorFunctionName = createRegExpTest(/^lab$/i)\n\n/** Return whether the unit is alpha-like. */\nconst isAlphaLikeUnit = createRegExpTest(/^%?$/i)\n\n/** Return whether the unit is hue-like. */\nconst isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */\nconst isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */\nconst isCalc = node => node.type === 'func' && isCalcFunctionName(node.name)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */\nconst isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */\nconst isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === ''\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */\nconst isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%'\n\n/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */\nconst isSlash = node => node.type === 'operator' && node.value === '/'\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */\nconst isLabFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node)\n)\n\n/** Set of nodes in a lab() function. */\nconst labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue]\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */\nconst isLchFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node)\n)\n\n/** Set of nodes in a lch() function. */\nconst lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue]\n\n/** @typedef {import('postcss-values-parser').Func} CSSFunction */\n/** @typedef {import('postcss-values-parser').Node} CSSNode */\n/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */\n/** @typedef {import('postcss-values-parser').Operator} CSSOperator */\n/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */\n","export default {\n\t/** Whether to preserve the original functional color declaration. */\n\tpreserve: false\n}\n","import { parse } from 'postcss-values-parser'\nimport onCSSFunction from './onCSSFunction'\nimport options from './options'\n\n/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */\nconst onCSSDeclaration = decl => {\n\tconst { value: originalValue } = decl\n\n\tif (hasAnyColorFunction(originalValue)) {\n\t\tconst valueAST = parse(originalValue)\n\n\t\tvalueAST.walkType('func', onCSSFunction)\n\n\t\tconst modifiedValue = String(valueAST)\n\n\t\tif (modifiedValue !== originalValue) {\n\t\t\tif (options.preserve) decl.cloneBefore({ value: modifiedValue })\n\t\t\telse decl.value = modifiedValue\n\t\t}\n\t}\n}\n\nexport default onCSSDeclaration\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the value has a lab() or lch() function. */\nconst hasAnyColorFunction = createRegExpTest(/(^|[^\\w-])(lab|lch)\\(/i)\n\n/** @typedef {import('postcss').Declaration} CSSDeclaration */\n","import onCSSDeclaration from './onCSSDeclaration'\nimport options from './options'\n\n/** Transform lab() and lch() functions in CSS. */\nconst postcssPlugin = /** @type {PostCSSPluginInitializer} */ opts => {\n\toptions.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false\n\n\treturn {\n\t\tpostcssPlugin: 'postcss-lab-function',\n\t\tDeclaration: onCSSDeclaration,\n\t}\n}\n\npostcssPlugin.postcss = true\n\nexport default postcssPlugin\n\n/** @typedef {import('postcss').Plugin} PostCSSPlugin */\n/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */\n"],"names":["onCSSFunction","node","name","nodes","isColorFunctionName","isLabFunctionContents","isLchFunctionContents","Object","assign","slashNode","alphaNode","isPercentage","isCalc","value","String","unit","remove","isSlash","replaceWith","commaNode","clone","channelNode1","channelNode2","channelNode3","toRGB","isLabColorFunctionName","lab2rgb","lch2rgb","rgbValues","map","channelNumber","parseFloat","channelValue","Math","max","min","parseInt","parse","first","createRegExpTest","Function","bind","RegExp","prototype","test","isCalcFunctionName","isAlphaLikeUnit","isHueLikeUnit","isAlphaValue","type","isHue","isNumber","every","index","labFunctionContents","lchFunctionContents","preserve","onCSSDeclaration","decl","originalValue","hasAnyColorFunction","valueAST","walkType","modifiedValue","options","cloneBefore","postcssPlugin","opts","Boolean","Declaration","postcss"],"mappings":";;;AAGA;;AACA,MAAMA,aAAa,GAAGC,IAAI,IAAI;AAC7B;AACA,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBF,IAAxB;;AAEA,MAAIG,mBAAmB,CAACF,IAAD,CAAvB,EAA+B;AAC9B,QAAIG,qBAAqB,CAACF,KAAD,CAArB,IAAgCG,qBAAqB,CAACH,KAAD,CAAzD,EAAkE;AACjE;AACAI,MAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,QAAAA,IAAI,EAAE;AAAR,OAApB;AAEA;;AACA,YAAMO,SAAS,GAAGN,KAAK,CAAC,CAAD,CAAvB;AAEA;;AACA,YAAMO,SAAS,GAAGP,KAAK,CAAC,CAAD,CAAvB;;AAEA,UAAIO,SAAJ,EAAe;AACd,YAAIC,YAAY,CAACD,SAAD,CAAZ,IAA2B,CAACE,MAAM,CAACF,SAAD,CAAtC,EAAmD;AAClD;AACAH,UAAAA,MAAM,CAACC,MAAP,CAAcE,SAAd,EAAyB;AAAEG,YAAAA,KAAK,EAAEC,MAAM,CAACJ,SAAS,CAACG,KAAV,GAAkB,GAAnB,CAAf;AAAwCE,YAAAA,IAAI,EAAE;AAA9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