postcss-color-functional-notation 4.2.1 → 4.2.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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changes to PostCSS Color Functional Notation
2
2
 
3
+ ### 4.2.4 (July 8, 2022)
4
+
5
+ - Fix case insensitive matching.
6
+
7
+ ### 4.2.3 (May 19, 2022)
8
+
9
+ - Handle modern channel values in legacy notation (comma separated)
10
+
11
+ ```css
12
+ .color {
13
+ color: rgba(0, 255, 0, 50%);
14
+ }
15
+
16
+ /* becomes */
17
+
18
+ .color {
19
+ color: rgba(0, 255, 0, 0.5);
20
+ }
21
+ ```
22
+
23
+ ### 4.2.2 (February 5, 2022)
24
+
25
+ - Improved `es module` and `commonjs` compatibility
26
+
3
27
  ### 4.2.1 (January 2, 2022)
4
28
 
5
29
  - Removed Sourcemaps from package tarball.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # PostCSS Color Functional Notation [<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-color-functional-notation.svg" height="20">][npm-url]
4
- [<img alt="CSS Standard Status" src="https://cssdb.org/badge/lab-function.svg" height="20">][css-url]
4
+ [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/lab-function.svg" height="20">][css-url]
5
5
  [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
6
- [<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
6
+ [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
7
7
 
8
8
  [PostCSS Color Functional Notation] lets you use space and slash separated
9
9
  color notation in CSS, following the [CSS Color] specification.
@@ -85,7 +85,7 @@ postcssImageSetFunction({ preserve: true })
85
85
 
86
86
  [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
87
87
  [css-url]: https://cssdb.org/#color-functional-notation
88
- [git-url]: https://gitter.im/postcss/postcss
88
+ [discord]: https://discord.gg/bUadyRwkJS
89
89
  [npm-url]: https://www.npmjs.com/package/postcss-color-functional-notation
90
90
 
91
91
  [CSS Color]: https://drafts.csswg.org/css-color/#ref-for-funcdef-rgb%E2%91%A1%E2%91%A0
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=e(require("postcss-value-parser"));function n(e){const n=e.value;let i=e.nodes;"rgb"!==n&&"hsl"!==n||(i=function(e){let r=0;for(let n=0;n<e.length;n++){const t=e[n];if("div"===t.type&&","===t.value){if(r<2&&(t.value=" ",t.type="space"),2===r&&(t.value="/"),r>2)return;r++}}return e}(i));const s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let f=null;if("hsl"===n||"hsla"===n?f=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const n=r.default.unit(e.value);if(!n)return!1;return!!n.number&&("deg"===n.unit||"grad"===n.unit||"rad"===n.unit||"turn"===n.unit||""===n.unit)}(e[0]))return null;if(!t(e[1]))return null;if(!t(e[2]))return null;const n={h:r.default.unit(e[0].value),hNode:e[0],s:r.default.unit(e[1].value),sNode:e[1],l:r.default.unit(e[2].value),lNode:e[2]};if(function(e){switch(e.unit){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(n.h),""!==n.h.unit)return null;n.hNode.value=n.h.number,l(e[3])&&(n.slash=e[3]);(t(e[4])||u(e[4])||a(e[4]))&&(n.alpha=e[4]);return n}(s):"rgb"!==n&&"rgba"!==n||(f=function(e){if(!t(e[0]))return null;if(!t(e[1]))return null;if(!t(e[2]))return null;const n={r:r.default.unit(e[0].value),rNode:e[0],g:r.default.unit(e[1].value),gNode:e[1],b:r.default.unit(e[2].value),bNode:e[2]};"%"===n.r.unit&&(n.r.number=String(Math.floor(Number(n.r.number)/100*255)),n.rNode.value=n.r.number);"%"===n.g.unit&&(n.g.number=String(Math.floor(Number(n.g.number)/100*255)),n.gNode.value=n.g.number);"%"===n.b.unit&&(n.b.number=String(Math.floor(Number(n.b.number)/100*255)),n.bNode.value=n.b.number);l(e[3])&&(n.slash=e[3]);(t(e[4])||u(e[4])||a(e[4]))&&(n.alpha=e[4]);return n}(s)),!f)return;if(s.length>3&&(!f.slash||!f.alpha))return;!function(e,n,t){"hsl"===e.value||"hsla"===e.value?e.value="hsl":"rgb"!==e.value&&"rgba"!==e.value||(e.value="rgb");if(!n||!t)return;"hsl"===e.value?e.value="hsla":e.value="rgba";if(n.value=",",n.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const n=r.default.unit(e.value);if(!n)return!1;return!!n.number}(t))return;const u=r.default.unit(t.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),t.value=String(u.number))}(e,f.slash,f.alpha);const[c,d]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(f);e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(d)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function t(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const n=r.default.unit(e.value);return!!n&&("%"===n.unit||""===n.unit)}function u(e){return e&&"function"===e.type&&"calc"===e.value}function a(e){return e&&"function"===e.type&&"var"===e.value}function l(e){return e&&"div"===e.type&&"/"===e.value}function o(e){if(!e||!e.value)return!1;try{return!1!==r.default.unit(e.value)}catch(e){return!1}}const i=e=>{const t="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(e,{result:u,postcss:a})=>{if(t&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(e))return;const l=e.value;if(!/(^|[^\w-])(hsla?|rgba?)\(/i.test(l))return;let o;try{o=r.default(l)}catch(r){e.warn(u,`Failed to parse value '${l}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&("hsl"!==e.value&&"hsla"!==e.value&&"rgb"!==e.value&&"rgba"!==e.value||n(e))}));const i=String(o);if(i!==l)if(t&&e.variable){const r=e.parent,n="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",t=a.atRule({name:"supports",params:n,source:e.source}),u=r.clone();u.removeAll(),u.append(e.clone()),t.append(u);let l=r,o=r.next();for(;l&&o&&"atrule"===o.type&&"supports"===o.name&&o.params===n;)l=o,o=o.next();l.after(t),e.value=i}else t?e.cloneBefore({value:i}):e.value=i}}};i.postcss=!0,module.exports=i;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=e(require("postcss-value-parser"));function t(e){const t=e.value.toLowerCase();if(!function(e,r){let t=!1,n=!1,u=!1;const a=r.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));for(let o=0;o<a.length;o++){const l=a[o];if("word"===l.type&&"from"===l.value.toLowerCase())return!1;"div"!==l.type||","!==l.value?e&&"word"===l.type&&l.value.endsWith("%")?u=!0:o===r.length-1&&"word"===l.type&&l.value.endsWith("%")&&(n=!0):t=!0}if(t&&(n||u))return!0;if(t)return!1;return!0}("rgb"===t||"rgba"===t,e.nodes))return;const i=function(e){let r=0;for(let t=0;t<e.length;t++){const n=e[t];if("div"===n.type&&","===n.value){if(r<2&&(n.value=" ",n.type="space"),2===r&&(n.value="/"),r>2)return;r++}}return e}(e.nodes),s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let f=null;if("hsl"===t||"hsla"===t?f=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!l(e))return!1;const t=r.default.unit(e.value);if(!t)return!1;const n=t.unit.toLowerCase();return!!t.number&&("deg"===n||"grad"===n||"rad"===n||"turn"===n||""===t.unit)}(e[0]))return null;if(!n(e[1]))return null;if(!n(e[2]))return null;const t={h:r.default.unit(e[0].value),hNode:e[0],s:r.default.unit(e[1].value),sNode:e[1],l:r.default.unit(e[2].value),lNode:e[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(t.h),""!==t.h.unit)return null;t.hNode.value=t.h.number,o(e[3])&&(t.slash=e[3]);(n(e[4])||u(e[4])||a(e[4]))&&(t.alpha=e[4]);return t}(s):"rgb"!==t&&"rgba"!==t||(f=function(e){if(!n(e[0]))return null;if(!n(e[1]))return null;if(!n(e[2]))return null;const t={r:r.default.unit(e[0].value),rNode:e[0],g:r.default.unit(e[1].value),gNode:e[1],b:r.default.unit(e[2].value),bNode:e[2]};"%"===t.r.unit&&(t.r.number=String(Math.floor(Number(t.r.number)/100*255)),t.rNode.value=t.r.number);"%"===t.g.unit&&(t.g.number=String(Math.floor(Number(t.g.number)/100*255)),t.gNode.value=t.g.number);"%"===t.b.unit&&(t.b.number=String(Math.floor(Number(t.b.number)/100*255)),t.bNode.value=t.b.number);o(e[3])&&(t.slash=e[3]);(n(e[4])||u(e[4])||a(e[4]))&&(t.alpha=e[4]);return t}(s)),!f)return;if(s.length>3&&(!f.slash||!f.alpha))return;!function(e,t,n){"hsl"===e.value.toLowerCase()||"hsla"===e.value.toLowerCase()?e.value="hsl":"rgb"!==e.value.toLowerCase()&&"rgba"!==e.value.toLowerCase()||(e.value="rgb");if(!t||!n)return;"hsl"===e.value.toLowerCase()?e.value="hsla":e.value="rgba";if(t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!l(e))return!1;const t=r.default.unit(e.value);if(!t)return!1;return!!t.number}(n))return;const u=r.default.unit(n.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),n.value=String(u.number))}(e,f.slash,f.alpha);const[c,d]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(f);e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(d)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function n(e){if(!e||"word"!==e.type)return!1;if(!l(e))return!1;const t=r.default.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function u(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}function a(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}function o(e){return e&&"div"===e.type&&"/"===e.value}function l(e){if(!e||!e.value)return!1;try{return!1!==r.default.unit(e.value)}catch(e){return!1}}const i=e=>{const n="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(e,{result:u,postcss:a})=>{if(function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.toLowerCase().indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(e))return;const o=e.value,l=o.toLowerCase();if(!(l.includes("rgb")||l.includes("rgba")||l.includes("hsl")||l.includes("hsla")))return;let i;try{i=r.default(o)}catch(r){e.warn(u,`Failed to parse value '${o}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===i)return;i.walk((e=>{if(!e.type||"function"!==e.type)return;const r=e.value.toLowerCase();"hsl"!==r&&"hsla"!==r&&"rgb"!==r&&"rgba"!==r||t(e)}));const s=String(i);if(s!==o)if(n&&e.variable){const r=e.parent,t="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",n=a.atRule({name:"supports",params:t,source:e.source}),u=r.clone();u.removeAll(),u.append(e.clone()),n.append(u);let o=r,l=r.next();for(;o&&l&&"atrule"===l.type&&"supports"===l.name&&l.params===t;)o=l,l=l.next();o.after(n),e.replaceWith(e.clone({value:s}))}else n?e.cloneBefore({value:s}):e.replaceWith(e.clone({value:s}))}}};i.postcss=!0,module.exports=i;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"postcss-value-parser";function r(r){const o=r.value;let i=r.nodes;"rgb"!==o&&"hsl"!==o||(i=function(e){let r=0;for(let n=0;n<e.length;n++){const t=e[n];if("div"===t.type&&","===t.value){if(r<2&&(t.value=" ",t.type="space"),2===r&&(t.value="/"),r>2)return;r++}}return e}(i));const s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let c=null;if("hsl"===o||"hsla"===o?c=function(r){if(!function(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);if(!n)return!1;return!!n.number&&("deg"===n.unit||"grad"===n.unit||"rad"===n.unit||"turn"===n.unit||""===n.unit)}(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const o={h:e.unit(r[0].value),hNode:r[0],s:e.unit(r[1].value),sNode:r[1],l:e.unit(r[2].value),lNode:r[2]};if(function(e){switch(e.unit){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(o.h),""!==o.h.unit)return null;o.hNode.value=o.h.number,a(r[3])&&(o.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(o.alpha=r[4]);return o}(s):"rgb"!==o&&"rgba"!==o||(c=function(r){if(!n(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const l={r:e.unit(r[0].value),rNode:r[0],g:e.unit(r[1].value),gNode:r[1],b:e.unit(r[2].value),bNode:r[2]};"%"===l.r.unit&&(l.r.number=String(Math.floor(Number(l.r.number)/100*255)),l.rNode.value=l.r.number);"%"===l.g.unit&&(l.g.number=String(Math.floor(Number(l.g.number)/100*255)),l.gNode.value=l.g.number);"%"===l.b.unit&&(l.b.number=String(Math.floor(Number(l.b.number)/100*255)),l.bNode.value=l.b.number);a(r[3])&&(l.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(l.alpha=r[4]);return l}(s)),!c)return;if(s.length>3&&(!c.slash||!c.alpha))return;!function(r,n,t){"hsl"===r.value||"hsla"===r.value?r.value="hsl":"rgb"!==r.value&&"rgba"!==r.value||(r.value="rgb");if(!n||!t)return;"hsl"===r.value?r.value="hsla":r.value="rgba";if(n.value=",",n.before="",!function(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);if(!n)return!1;return!!n.number}(t))return;const u=e.unit(t.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),t.value=String(u.number))}(r,c.slash,c.alpha);const[f,v]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(c);r.nodes.splice(r.nodes.indexOf(f)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),r.nodes.splice(r.nodes.indexOf(v)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function n(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);return!!n&&("%"===n.unit||""===n.unit)}function t(e){return e&&"function"===e.type&&"calc"===e.value}function u(e){return e&&"function"===e.type&&"var"===e.value}function a(e){return e&&"div"===e.type&&"/"===e.value}function l(r){if(!r||!r.value)return!1;try{return!1!==e.unit(r.value)}catch(e){return!1}}const o=n=>{const t="preserve"in Object(n)&&Boolean(n.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(n,{result:u,postcss:a})=>{if(t&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(n))return;const l=n.value;if(!/(^|[^\w-])(hsla?|rgba?)\(/i.test(l))return;let o;try{o=e(l)}catch(e){n.warn(u,`Failed to parse value '${l}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&("hsl"!==e.value&&"hsla"!==e.value&&"rgb"!==e.value&&"rgba"!==e.value||r(e))}));const i=String(o);if(i!==l)if(t&&n.variable){const e=n.parent,r="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",t=a.atRule({name:"supports",params:r,source:n.source}),u=e.clone();u.removeAll(),u.append(n.clone()),t.append(u);let l=e,o=e.next();for(;l&&o&&"atrule"===o.type&&"supports"===o.name&&o.params===r;)l=o,o=o.next();l.after(t),n.value=i}else t?n.cloneBefore({value:i}):n.value=i}}};o.postcss=!0;export{o as default};
1
+ import e from"postcss-value-parser";function r(r){const l=r.value.toLowerCase();if(!function(e,r){let n=!1,t=!1,u=!1;const o=r.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));for(let a=0;a<o.length;a++){const l=o[a];if("word"===l.type&&"from"===l.value.toLowerCase())return!1;"div"!==l.type||","!==l.value?e&&"word"===l.type&&l.value.endsWith("%")?u=!0:a===r.length-1&&"word"===l.type&&l.value.endsWith("%")&&(t=!0):n=!0}if(n&&(t||u))return!0;if(n)return!1;return!0}("rgb"===l||"rgba"===l,r.nodes))return;const i=function(e){let r=0;for(let n=0;n<e.length;n++){const t=e[n];if("div"===t.type&&","===t.value){if(r<2&&(t.value=" ",t.type="space"),2===r&&(t.value="/"),r>2)return;r++}}return e}(r.nodes),s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let c=null;if("hsl"===l||"hsla"===l?c=function(r){if(!function(r){if(!r||"word"!==r.type)return!1;if(!a(r))return!1;const n=e.unit(r.value);if(!n)return!1;const t=n.unit.toLowerCase();return!!n.number&&("deg"===t||"grad"===t||"rad"===t||"turn"===t||""===n.unit)}(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const l={h:e.unit(r[0].value),hNode:r[0],s:e.unit(r[1].value),sNode:r[1],l:e.unit(r[2].value),lNode:r[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(l.h),""!==l.h.unit)return null;l.hNode.value=l.h.number,o(r[3])&&(l.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(l.alpha=r[4]);return l}(s):"rgb"!==l&&"rgba"!==l||(c=function(r){if(!n(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const a={r:e.unit(r[0].value),rNode:r[0],g:e.unit(r[1].value),gNode:r[1],b:e.unit(r[2].value),bNode:r[2]};"%"===a.r.unit&&(a.r.number=String(Math.floor(Number(a.r.number)/100*255)),a.rNode.value=a.r.number);"%"===a.g.unit&&(a.g.number=String(Math.floor(Number(a.g.number)/100*255)),a.gNode.value=a.g.number);"%"===a.b.unit&&(a.b.number=String(Math.floor(Number(a.b.number)/100*255)),a.bNode.value=a.b.number);o(r[3])&&(a.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(a.alpha=r[4]);return a}(s)),!c)return;if(s.length>3&&(!c.slash||!c.alpha))return;!function(r,n,t){"hsl"===r.value.toLowerCase()||"hsla"===r.value.toLowerCase()?r.value="hsl":"rgb"!==r.value.toLowerCase()&&"rgba"!==r.value.toLowerCase()||(r.value="rgb");if(!n||!t)return;"hsl"===r.value.toLowerCase()?r.value="hsla":r.value="rgba";if(n.value=",",n.before="",!function(r){if(!r||"word"!==r.type)return!1;if(!a(r))return!1;const n=e.unit(r.value);if(!n)return!1;return!!n.number}(t))return;const u=e.unit(t.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),t.value=String(u.number))}(r,c.slash,c.alpha);const[f,d]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(c);r.nodes.splice(r.nodes.indexOf(f)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),r.nodes.splice(r.nodes.indexOf(d)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function n(r){if(!r||"word"!==r.type)return!1;if(!a(r))return!1;const n=e.unit(r.value);return!!n&&("%"===n.unit||""===n.unit)}function t(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}function u(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}function o(e){return e&&"div"===e.type&&"/"===e.value}function a(r){if(!r||!r.value)return!1;try{return!1!==e.unit(r.value)}catch(e){return!1}}const l=n=>{const t="preserve"in Object(n)&&Boolean(n.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(n,{result:u,postcss:o})=>{if(function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.toLowerCase().indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(n))return;const a=n.value,l=a.toLowerCase();if(!(l.includes("rgb")||l.includes("rgba")||l.includes("hsl")||l.includes("hsla")))return;let i;try{i=e(a)}catch(e){n.warn(u,`Failed to parse value '${a}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===i)return;i.walk((e=>{if(!e.type||"function"!==e.type)return;const n=e.value.toLowerCase();"hsl"!==n&&"hsla"!==n&&"rgb"!==n&&"rgba"!==n||r(e)}));const s=String(i);if(s!==a)if(t&&n.variable){const e=n.parent,r="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",t=o.atRule({name:"supports",params:r,source:n.source}),u=e.clone();u.removeAll(),u.append(n.clone()),t.append(u);let a=e,l=e.next();for(;a&&l&&"atrule"===l.type&&"supports"===l.name&&l.params===r;)a=l,l=l.next();a.after(t),n.replaceWith(n.clone({value:s}))}else t?n.cloneBefore({value:s}):n.replaceWith(n.clone({value:s}))}}};l.postcss=!0;export{l as default};
package/package.json CHANGED
@@ -1,66 +1,80 @@
1
1
  {
2
- "name": "postcss-color-functional-notation",
3
- "version": "4.2.1",
4
- "description": "Use space and slash separated color notation in CSS",
5
- "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
- "license": "CC0-1.0",
7
- "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-functional-notation#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
- "files": [
13
- "CHANGELOG.md",
14
- "LICENSE.md",
15
- "README.md",
16
- "dist"
17
- ],
18
- "scripts": {
19
- "build": "rollup -c ../../rollup/default.js",
20
- "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
21
- "lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
22
- "prepublishOnly": "npm run clean && npm run build && npm run test",
23
- "stryker": "stryker run --logLevel error",
24
- "test": "postcss-tape --ci && npm run test:exports",
25
- "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
26
- },
27
- "engines": {
28
- "node": "^12 || ^14 || >=16"
29
- },
30
- "dependencies": {
31
- "postcss-value-parser": "^4.2.0"
32
- },
33
- "devDependencies": {
34
- "postcss": "^8.3.6",
35
- "postcss-tape": "^6.0.1"
36
- },
37
- "peerDependencies": {
38
- "postcss": "^8.3"
39
- },
40
- "keywords": [
41
- "postcss",
42
- "css",
43
- "postcss-plugin",
44
- "color",
45
- "colors",
46
- "rgb",
47
- "rgba",
48
- "hsl",
49
- "hsla",
50
- "hwb",
51
- "functional",
52
- "notation",
53
- "design",
54
- "syntax",
55
- "space",
56
- "comma"
57
- ],
58
- "repository": {
59
- "type": "git",
60
- "url": "https://github.com/csstools/postcss-plugins.git",
61
- "directory": "plugins/postcss-color-functional-notation"
62
- },
63
- "volta": {
64
- "extends": "../../package.json"
65
- }
2
+ "name": "postcss-color-functional-notation",
3
+ "description": "Use space and slash separated color notation in CSS",
4
+ "version": "4.2.4",
5
+ "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
+ "license": "CC0-1.0",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/csstools"
10
+ },
11
+ "engines": {
12
+ "node": "^12 || ^14 || >=16"
13
+ },
14
+ "main": "dist/index.cjs",
15
+ "module": "dist/index.mjs",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs",
21
+ "default": "./dist/index.mjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "CHANGELOG.md",
26
+ "LICENSE.md",
27
+ "README.md",
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "postcss-value-parser": "^4.2.0"
32
+ },
33
+ "peerDependencies": {
34
+ "postcss": "^8.2"
35
+ },
36
+ "scripts": {
37
+ "build": "rollup -c ../../rollup/default.js",
38
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
39
+ "docs": "node ../../.github/bin/generate-docs/install.mjs",
40
+ "lint": "npm run lint:eslint && npm run lint:package-json",
41
+ "lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
42
+ "lint:package-json": "node ../../.github/bin/format-package-json.mjs",
43
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
44
+ "test": "node .tape.mjs && npm run test:exports",
45
+ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
46
+ "test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
47
+ },
48
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-functional-notation#readme",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/csstools/postcss-plugins.git",
52
+ "directory": "plugins/postcss-color-functional-notation"
53
+ },
54
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
55
+ "keywords": [
56
+ "color",
57
+ "colors",
58
+ "comma",
59
+ "css",
60
+ "design",
61
+ "functional",
62
+ "hsl",
63
+ "hsla",
64
+ "hwb",
65
+ "notation",
66
+ "postcss",
67
+ "postcss-plugin",
68
+ "rgb",
69
+ "rgba",
70
+ "space",
71
+ "syntax"
72
+ ],
73
+ "csstools": {
74
+ "exportName": "postcssColorFunctionalNotation",
75
+ "humanReadableName": "PostCSS Color Functional Notation"
76
+ },
77
+ "volta": {
78
+ "extends": "../../package.json"
79
+ }
66
80
  }