postcss-color-functional-notation 4.2.3 → 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,9 @@
1
1
  # Changes to PostCSS Color Functional Notation
2
2
 
3
+ ### 4.2.4 (July 8, 2022)
4
+
5
+ - Fix case insensitive matching.
6
+
3
7
  ### 4.2.3 (May 19, 2022)
4
8
 
5
9
  - Handle modern channel values in legacy notation (comma separated)
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 t(e){const t=e.value;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 l=0;l<a.length;l++){const o=a[l];if("word"===o.type&&"from"===o.value)return!1;"div"!==o.type||","!==o.value?e&&"word"===o.type&&o.value.endsWith("%")?u=!0:l===r.length-1&&"word"===o.type&&o.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(!o(e))return!1;const t=r.default.unit(e.value);if(!t)return!1;return!!t.number&&("deg"===t.unit||"grad"===t.unit||"rad"===t.unit||"turn"===t.unit||""===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){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,l(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);l(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||"hsla"===e.value?e.value="hsl":"rgb"!==e.value&&"rgba"!==e.value||(e.value="rgb");if(!t||!n)return;"hsl"===e.value?e.value="hsla":e.value="rgba";if(t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!o(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(!o(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}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 n="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(e,{result:u,postcss:a})=>{if(n&&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||t(e))}));const i=String(o);if(i!==l)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 l=r,o=r.next();for(;l&&o&&"atrule"===o.type&&"supports"===o.name&&o.params===t;)l=o,o=o.next();l.after(n),e.value=i}else n?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;if(!function(e,r){let n=!1,t=!1,u=!1;const a=r.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));for(let l=0;l<a.length;l++){const o=a[l];if("word"===o.type&&"from"===o.value)return!1;"div"!==o.type||","!==o.value?e&&"word"===o.type&&o.value.endsWith("%")?u=!0:l===r.length-1&&"word"===o.type&&o.value.endsWith("%")&&(t=!0):n=!0}if(n&&(t||u))return!0;if(n)return!1;return!0}("rgb"===o||"rgba"===o,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"===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,7 +1,7 @@
1
1
  {
2
2
  "name": "postcss-color-functional-notation",
3
3
  "description": "Use space and slash separated color notation in CSS",
4
- "version": "4.2.3",
4
+ "version": "4.2.4",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
7
7
  "funding": {
@@ -31,7 +31,7 @@
31
31
  "postcss-value-parser": "^4.2.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "postcss": "^8.4"
34
+ "postcss": "^8.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "rollup -c ../../rollup/default.js",