@csstools/postcss-hwb-function 1.0.1 → 1.0.2

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,6 +1,10 @@
1
1
  # Changes to PostCSS HWB Function
2
2
 
3
- ### 1.0.01 (May 18, 2022)
3
+ ### 1.0.2 (July 8, 2022)
4
+
5
+ - Fix case insensitive matching.
6
+
7
+ ### 1.0.1 (May 18, 2022)
4
8
 
5
9
  - Fix grayscale conversions.
6
10
 
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 n=e(require("postcss-value-parser"));function t(e){const n=e[0];let t=e[1],r=e[2];if(t/=100,r/=100,t+r>=1){const e=t/(t+r);return[e,e,e].map((e=>Math.round(255*e)))}const u=function(e){let n=e[0],t=e[1],r=e[2];n%=360,n<0&&(n+=360);function u(e){const u=(e+n/30)%12,a=t*Math.min(r,1-r);return r-a*Math.max(-1,Math.min(u-3,9-u,1))}return t/=100,r/=100,[u(0),u(8),u(4)]}([n,100,50]);for(let e=0;e<3;e++)u[e]*=1-t-r,u[e]+=t;return u.map((e=>Math.round(255*e)))}function r(e){const r=e.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type)),l=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=n.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(!u(e[1]))return null;if(!u(e[2]))return null;const t={h:n.default.unit(e[0].value),hNode:e[0],w:n.default.unit(e[1].value),wNode:e[1],b:n.default.unit(e[2].value),bNode:e[2]};if(function(e){switch(e.unit){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=(360*parseFloat(e.number)).toString()}}(t.h),""!==t.h.unit)return null;i(t.w),i(t.b),function(e){return e&&"div"===e.type&&"/"===e.value}(e[3])&&(t.slash=e[3]);(u(e[4])||function(e){return e&&"function"===e.type&&"calc"===e.value}(e[4])||function(e){return e&&"function"===e.type&&"var"===e.value}(e[4]))&&(t.alpha=e[4]);return t}(r);if(!l)return;if(r.length>3&&(!l.slash||!l.alpha))return;e.value="rgb",function(e,t,r){if(!t||!r)return;if(e.value="rgba",t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=n.default.unit(e.value);if(!t)return!1;return!!t.number}(r))return;const u=n.default.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(e,l.slash,l.alpha);const[s,c,f]=[(d=l).hNode,d.wNode,d.bNode];var d;const[p,v,b]=function(e){return[e.h,e.w,e.b]}(l),m=t([p.number,v.number,b.number].map((e=>parseFloat(e))));e.nodes.splice(e.nodes.indexOf(s)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),a(e.nodes,s,{...s,value:String(m[0])}),a(e.nodes,c,{...c,value:String(m[1])}),a(e.nodes,f,{...f,value:String(m[2])})}function u(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=n.default.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function a(e,n,t){const r=e.indexOf(n);e[r]=t}function i(e){if("%"!==e.unit)return e.unit="%",void(e.number=(100*parseFloat(e.number)).toString())}function o(e){if(!e||!e.value)return!1;try{return!1!==n.default.unit(e.value)}catch(e){return!1}}const l=e=>{const t="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(e,{result:u,postcss:a})=>{if(t&&function(e){let n=e.parent;for(;n;)if("atrule"===n.type){if("supports"===n.name&&-1!==n.params.indexOf("(color: hwb(0% 0 0))"))return!0;n=n.parent}else n=n.parent;return!1}(e))return;const i=e.value;if(!i.includes("hwb"))return;const o=function(e,t,u){let a;try{a=n.default(e)}catch(n){t.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===a)return;a.walk((e=>{e.type&&"function"===e.type&&"hwb"===e.value&&r(e)}));const i=String(a);if(i===e)return;return i}(i,e,u);if(void 0!==o)if(e.variable&&t){const n=e.parent,t=a.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:e.source}),r=n.clone();r.removeAll(),r.append(e.clone()),t.append(r),function(e,n,t){let r=n,u=n.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name&&u.params===t;)r=u,u=u.next();r.after(e)}(t,n,"(color: hwb(0% 0 0))"),e.value=o}else t?e.cloneBefore({value:o}):e.value=o}}};l.postcss=!0,module.exports=l;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-value-parser"));function n(e){const t=e[0];let n=e[1],r=e[2];if(n/=100,r/=100,n+r>=1){const e=n/(n+r);return[e,e,e].map((e=>Math.round(255*e)))}const u=function(e){let t=e[0],n=e[1],r=e[2];t%=360,t<0&&(t+=360);function u(e){const u=(e+t/30)%12,o=n*Math.min(r,1-r);return r-o*Math.max(-1,Math.min(u-3,9-u,1))}return n/=100,r/=100,[u(0),u(8),u(4)]}([t,100,50]);for(let e=0;e<3;e++)u[e]*=1-n-r,u[e]+=n;return u.map((e=>Math.round(255*e)))}function r(e){const r=e.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type)),s=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);if(!n)return!1;const r=n.unit.toLowerCase();return!!n.number&&("deg"===r||"grad"===r||"rad"===r||"turn"===r||""===r)}(e[0]))return null;if(!u(e[1]))return null;if(!u(e[2]))return null;const n={h:t.default.unit(e[0].value),hNode:e[0],w:t.default.unit(e[1].value),wNode:e[1],b:t.default.unit(e[2].value),bNode:e[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=(360*parseFloat(e.number)).toString()}}(n.h),""!==n.h.unit)return null;a(n.w),a(n.b),function(e){return e&&"div"===e.type&&"/"===e.value}(e[3])&&(n.slash=e[3]);(u(e[4])||function(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}(e[4])||function(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}(e[4]))&&(n.alpha=e[4]);return n}(r);if(!s)return;if(r.length>3&&(!s.slash||!s.alpha))return;e.value="rgb",function(e,n,r){if(!n||!r)return;if(e.value="rgba",n.value=",",n.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);if(!n)return!1;return!!n.number}(r))return;const u=t.default.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(e,s.slash,s.alpha);const[l,c,f]=[(d=s).hNode,d.wNode,d.bNode];var d;const[p,v,b]=function(e){return[e.h,e.w,e.b]}(s),h=n([p.number,v.number,b.number].map((e=>parseFloat(e))));e.nodes.splice(e.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),o(e.nodes,l,{...l,value:String(h[0])}),o(e.nodes,c,{...c,value:String(h[1])}),o(e.nodes,f,{...f,value:String(h[2])})}function u(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const n=t.default.unit(e.value);return!!n&&("%"===n.unit||""===n.unit)}function o(e,t,n){const r=e.indexOf(t);e[r]=n}function a(e){if("%"!==e.unit)return e.unit="%",void(e.number=(100*parseFloat(e.number)).toString())}function i(e){if(!e||!e.value)return!1;try{return!1!==t.default.unit(e.value)}catch(e){return!1}}const s=e=>{const n="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(e,{result:u,postcss:o})=>{if(n&&function(e){let t=e.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name.toLowerCase()&&-1!==t.params.toLowerCase().indexOf("(color: hwb(0% 0 0))"))return!0;t=t.parent}else t=t.parent;return!1}(e))return;const a=e.value;if(!a.toLowerCase().includes("hwb"))return;const i=function(e,n,u){let o;try{o=t.default(e)}catch(t){n.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&"hwb"===e.value.toLowerCase()&&r(e)}));const a=String(o);if(a===e)return;return a}(a,e,u);if(void 0!==i)if(e.variable&&n){const t=e.parent,n=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:e.source}),r=t.clone();r.removeAll(),r.append(e.clone()),n.append(r),function(e,t,n){let r=t,u=t.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name.toLowerCase()&&u.params===n;)r=u,u=u.next();r.after(e)}(n,t,"(color: hwb(0% 0 0))"),e.replaceWith(e.clone({value:i}))}else n?e.cloneBefore({value:i}):e.replaceWith(e.clone({value:i}))}}};s.postcss=!0,module.exports=s;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import n from"postcss-value-parser";function e(n){const e=n[0];let t=n[1],r=n[2];if(t/=100,r/=100,t+r>=1){const n=t/(t+r);return[n,n,n].map((n=>Math.round(255*n)))}const u=function(n){let e=n[0],t=n[1],r=n[2];e%=360,e<0&&(e+=360);function u(n){const u=(n+e/30)%12,o=t*Math.min(r,1-r);return r-o*Math.max(-1,Math.min(u-3,9-u,1))}return t/=100,r/=100,[u(0),u(8),u(4)]}([e,100,50]);for(let n=0;n<3;n++)u[n]*=1-t-r,u[n]+=t;return u.map((n=>Math.round(255*n)))}function t(t){const a=t.nodes.slice().filter((n=>"comment"!==n.type&&"space"!==n.type)),s=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.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(!r(e[1]))return null;if(!r(e[2]))return null;const t={h:n.unit(e[0].value),hNode:e[0],w:n.unit(e[1].value),wNode:e[1],b:n.unit(e[2].value),bNode:e[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()}}(t.h),""!==t.h.unit)return null;o(t.w),o(t.b),function(n){return n&&"div"===n.type&&"/"===n.value}(e[3])&&(t.slash=e[3]);(r(e[4])||function(n){return n&&"function"===n.type&&"calc"===n.value}(e[4])||function(n){return n&&"function"===n.type&&"var"===n.value}(e[4]))&&(t.alpha=e[4]);return t}(a);if(!s)return;if(a.length>3&&(!s.slash||!s.alpha))return;t.value="rgb",function(e,t,r){if(!t||!r)return;if(e.value="rgba",t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.unit(e.value);if(!t)return!1;return!!t.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))}(t,s.slash,s.alpha);const[l,c,f]=[(p=s).hNode,p.wNode,p.bNode];var p;const[d,v,b]=function(n){return[n.h,n.w,n.b]}(s),m=e([d.number,v.number,b.number].map((n=>parseFloat(n))));t.nodes.splice(t.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.splice(t.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),u(t.nodes,l,{...l,value:String(m[0])}),u(t.nodes,c,{...c,value:String(m[1])}),u(t.nodes,f,{...f,value:String(m[2])})}function r(e){if(!e||"word"!==e.type)return!1;if(!i(e))return!1;const t=n.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function u(n,e,t){const r=n.indexOf(e);n[r]=t}function o(n){if("%"!==n.unit)return n.unit="%",void(n.number=(100*parseFloat(n.number)).toString())}function i(e){if(!e||!e.value)return!1;try{return!1!==n.unit(e.value)}catch(n){return!1}}const a=e=>{const r="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(e,{result:u,postcss:o})=>{if(r&&function(n){let e=n.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("(color: hwb(0% 0 0))"))return!0;e=e.parent}else e=e.parent;return!1}(e))return;const i=e.value;if(!i.includes("hwb"))return;const a=function(e,r,u){let o;try{o=n(e)}catch(n){r.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((n=>{n.type&&"function"===n.type&&"hwb"===n.value&&t(n)}));const i=String(o);if(i===e)return;return i}(i,e,u);if(void 0!==a)if(e.variable&&r){const n=e.parent,t=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:e.source}),r=n.clone();r.removeAll(),r.append(e.clone()),t.append(r),function(n,e,t){let r=e,u=e.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name&&u.params===t;)r=u,u=u.next();r.after(n)}(t,n,"(color: hwb(0% 0 0))"),e.value=a}else r?e.cloneBefore({value:a}):e.value=a}}};a.postcss=!0;export{a as default};
1
+ import e from"postcss-value-parser";function n(e){const n=e[0];let t=e[1],r=e[2];if(t/=100,r/=100,t+r>=1){const e=t/(t+r);return[e,e,e].map((e=>Math.round(255*e)))}const u=function(e){let n=e[0],t=e[1],r=e[2];n%=360,n<0&&(n+=360);function u(e){const u=(e+n/30)%12,o=t*Math.min(r,1-r);return r-o*Math.max(-1,Math.min(u-3,9-u,1))}return t/=100,r/=100,[u(0),u(8),u(4)]}([n,100,50]);for(let e=0;e<3;e++)u[e]*=1-t-r,u[e]+=t;return u.map((e=>Math.round(255*e)))}function t(t){const i=t.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type)),s=function(n){if(!function(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);if(!t)return!1;const r=t.unit.toLowerCase();return!!t.number&&("deg"===r||"grad"===r||"rad"===r||"turn"===r||""===r)}(n[0]))return null;if(!r(n[1]))return null;if(!r(n[2]))return null;const t={h:e.unit(n[0].value),hNode:n[0],w:e.unit(n[1].value),wNode:n[1],b:e.unit(n[2].value),bNode:n[2]};if(function(e){switch(e.unit.toLowerCase()){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=(360*parseFloat(e.number)).toString()}}(t.h),""!==t.h.unit)return null;o(t.w),o(t.b),function(e){return e&&"div"===e.type&&"/"===e.value}(n[3])&&(t.slash=n[3]);(r(n[4])||function(e){return e&&"function"===e.type&&"calc"===e.value.toLowerCase()}(n[4])||function(e){return e&&"function"===e.type&&"var"===e.value.toLowerCase()}(n[4]))&&(t.alpha=n[4]);return t}(i);if(!s)return;if(i.length>3&&(!s.slash||!s.alpha))return;t.value="rgb",function(n,t,r){if(!t||!r)return;if(n.value="rgba",t.value=",",t.before="",!function(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);if(!t)return!1;return!!t.number}(r))return;const u=e.unit(r.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),r.value=String(u.number))}(t,s.slash,s.alpha);const[l,c,f]=[(p=s).hNode,p.wNode,p.bNode];var p;const[d,v,b]=function(e){return[e.h,e.w,e.b]}(s),m=n([d.number,v.number,b.number].map((e=>parseFloat(e))));t.nodes.splice(t.nodes.indexOf(l)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.splice(t.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),u(t.nodes,l,{...l,value:String(m[0])}),u(t.nodes,c,{...c,value:String(m[1])}),u(t.nodes,f,{...f,value:String(m[2])})}function r(n){if(!n||"word"!==n.type)return!1;if(!a(n))return!1;const t=e.unit(n.value);return!!t&&("%"===t.unit||""===t.unit)}function u(e,n,t){const r=e.indexOf(n);e[r]=t}function o(e){if("%"!==e.unit)return e.unit="%",void(e.number=(100*parseFloat(e.number)).toString())}function a(n){if(!n||!n.value)return!1;try{return!1!==e.unit(n.value)}catch(e){return!1}}const i=n=>{const r="preserve"in Object(n)&&Boolean(n.preserve);return{postcssPlugin:"postcss-hwb-function",Declaration:(n,{result:u,postcss:o})=>{if(r&&function(e){let n=e.parent;for(;n;)if("atrule"===n.type){if("supports"===n.name.toLowerCase()&&-1!==n.params.toLowerCase().indexOf("(color: hwb(0% 0 0))"))return!0;n=n.parent}else n=n.parent;return!1}(n))return;const a=n.value;if(!a.toLowerCase().includes("hwb"))return;const i=function(n,r,u){let o;try{o=e(n)}catch(e){r.warn(u,`Failed to parse value '${n}' as a hwb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&"hwb"===e.value.toLowerCase()&&t(e)}));const a=String(o);if(a===n)return;return a}(a,n,u);if(void 0!==i)if(n.variable&&r){const e=n.parent,t=o.atRule({name:"supports",params:"(color: hwb(0% 0 0))",source:n.source}),r=e.clone();r.removeAll(),r.append(n.clone()),t.append(r),function(e,n,t){let r=n,u=n.next();for(;r&&u&&"atrule"===u.type&&"supports"===u.name.toLowerCase()&&u.params===t;)r=u,u=u.next();r.after(e)}(t,e,"(color: hwb(0% 0 0))"),n.replaceWith(n.clone({value:i}))}else r?n.cloneBefore({value:i}):n.replaceWith(n.clone({value:i}))}}};i.postcss=!0;export{i as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@csstools/postcss-hwb-function",
3
3
  "description": "Use hwb() color functions in CSS",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
7
7
  "funding": {
@@ -32,7 +32,7 @@
32
32
  "postcss-value-parser": "^4.2.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "postcss": "^8.4"
35
+ "postcss": "^8.2"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "rollup -c ../../rollup/default.js",