@csstools/postcss-hwb-function 1.0.0

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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changes to PostCSS HWB Function
2
+
3
+ ### 1.0.0 (January 22, 2022)
4
+
5
+ - Initial version
package/INSTALL.md ADDED
@@ -0,0 +1,164 @@
1
+ # Installing PostCSS HWB Function
2
+
3
+ [PostCSS HWB Function] runs in all Node environments, with special
4
+ instructions for:
5
+
6
+ | [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
7
+ | --- | --- | --- | --- | --- | --- |
8
+
9
+ ## Node
10
+
11
+ Add [PostCSS HWB Function] to your project:
12
+
13
+ ```bash
14
+ npm install postcss @csstools/postcss-hwb-function --save-dev
15
+ ```
16
+
17
+ Use it as a [PostCSS] plugin:
18
+
19
+ ```js
20
+ const postcss = require('postcss');
21
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
22
+
23
+ postcss([
24
+ postcssHWBFunction(/* pluginOptions */)
25
+ ]).process(YOUR_CSS /*, processOptions */);
26
+ ```
27
+
28
+ ## PostCSS CLI
29
+
30
+ Add [PostCSS CLI] to your project:
31
+
32
+ ```bash
33
+ npm install postcss-cli --save-dev
34
+ ```
35
+
36
+ Use [PostCSS HWB Function] in your `postcss.config.js` configuration
37
+ file:
38
+
39
+ ```js
40
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
41
+
42
+ module.exports = {
43
+ plugins: [
44
+ postcssHWBFunction(/* pluginOptions */)
45
+ ]
46
+ }
47
+ ```
48
+
49
+ ## Webpack
50
+
51
+ Add [PostCSS Loader] to your project:
52
+
53
+ ```bash
54
+ npm install postcss-loader --save-dev
55
+ ```
56
+
57
+ Use [PostCSS HWB Function] in your Webpack configuration:
58
+
59
+ ```js
60
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
61
+
62
+ module.exports = {
63
+ module: {
64
+ rules: [
65
+ {
66
+ test: /\.css$/,
67
+ use: [
68
+ 'style-loader',
69
+ { loader: 'css-loader', options: { importLoaders: 1 } },
70
+ { loader: 'postcss-loader', options: {
71
+ ident: 'postcss',
72
+ plugins: () => [
73
+ postcssHWBFunction(/* pluginOptions */)
74
+ ]
75
+ } }
76
+ ]
77
+ }
78
+ ]
79
+ }
80
+ }
81
+ ```
82
+
83
+ ## Create React App
84
+
85
+ Add [React App Rewired] and [React App Rewire PostCSS] to your project:
86
+
87
+ ```bash
88
+ npm install react-app-rewired react-app-rewire-postcss --save-dev
89
+ ```
90
+
91
+ Use [React App Rewire PostCSS] and [PostCSS HWB Function] in your
92
+ `config-overrides.js` file:
93
+
94
+ ```js
95
+ const reactAppRewirePostcss = require('react-app-rewire-postcss');
96
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
97
+
98
+ module.exports = config => reactAppRewirePostcss(config, {
99
+ plugins: () => [
100
+ postcssHWBFunction(/* pluginOptions */)
101
+ ]
102
+ });
103
+ ```
104
+
105
+ ## Gulp
106
+
107
+ Add [Gulp PostCSS] to your project:
108
+
109
+ ```bash
110
+ npm install gulp-postcss --save-dev
111
+ ```
112
+
113
+ Use [PostCSS HWB Function] in your Gulpfile:
114
+
115
+ ```js
116
+ const postcss = require('gulp-postcss');
117
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
118
+
119
+ gulp.task('css', () => gulp.src('./src/*.css').pipe(
120
+ postcss([
121
+ postcssHWBFunction(/* pluginOptions */)
122
+ ])
123
+ ).pipe(
124
+ gulp.dest('.')
125
+ ));
126
+ ```
127
+
128
+ ## Grunt
129
+
130
+ Add [Grunt PostCSS] to your project:
131
+
132
+ ```bash
133
+ npm install grunt-postcss --save-dev
134
+ ```
135
+
136
+ Use [PostCSS HWB Function] in your Gruntfile:
137
+
138
+ ```js
139
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
140
+
141
+ grunt.loadNpmTasks('grunt-postcss');
142
+
143
+ grunt.initConfig({
144
+ postcss: {
145
+ options: {
146
+ use: [
147
+ postcssHWBFunction(/* pluginOptions */)
148
+ ]
149
+ },
150
+ dist: {
151
+ src: '*.css'
152
+ }
153
+ }
154
+ });
155
+ ```
156
+
157
+ [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
158
+ [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
159
+ [PostCSS]: https://github.com/postcss/postcss
160
+ [PostCSS CLI]: https://github.com/postcss/postcss-cli
161
+ [PostCSS Loader]: https://github.com/postcss/postcss-loader
162
+ [PostCSS HWB Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-hwb-function
163
+ [React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
164
+ [React App Rewired]: https://github.com/timarney/react-app-rewired
package/LICENSE.md ADDED
@@ -0,0 +1,108 @@
1
+ # CC0 1.0 Universal
2
+
3
+ ## Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an “owner”) of an original work of
8
+ authorship and/or a database (each, a “Work”).
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific works
12
+ (“Commons”) that the public can reliably and without fear of later claims of
13
+ infringement build upon, modify, incorporate in other works, reuse and
14
+ redistribute as freely as possible in any form whatsoever and for any purposes,
15
+ including without limitation commercial purposes. These owners may contribute
16
+ to the Commons to promote the ideal of a free culture and the further
17
+ production of creative, cultural and scientific works, or to gain reputation or
18
+ greater distribution for their Work in part through the use and efforts of
19
+ others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation of
22
+ additional consideration or compensation, the person associating CC0 with a
23
+ Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
25
+ publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights (“Copyright and
31
+ Related Rights”). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+ 1. the right to reproduce, adapt, distribute, perform, display, communicate,
34
+ and translate a Work;
35
+ 2. moral rights retained by the original author(s) and/or performer(s);
36
+ 3. publicity and privacy rights pertaining to a person’s image or likeness
37
+ depicted in a Work;
38
+ 4. rights protecting against unfair competition in regards to a Work,
39
+ subject to the limitations in paragraph 4(i), below;
40
+ 5. rights protecting the extraction, dissemination, use and reuse of data in
41
+ a Work;
42
+ 6. database rights (such as those arising under Directive 96/9/EC of the
43
+ European Parliament and of the Council of 11 March 1996 on the legal
44
+ protection of databases, and under any national implementation thereof,
45
+ including any amended or successor version of such directive); and
46
+ 7. other similar, equivalent or corresponding rights throughout the world
47
+ based on applicable law or treaty, and any national implementations
48
+ thereof.
49
+
50
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
51
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
52
+ unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
53
+ and Related Rights and associated claims and causes of action, whether now
54
+ known or unknown (including existing as well as future claims and causes of
55
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
56
+ duration provided by applicable law or treaty (including future time
57
+ extensions), (iii) in any current or future medium and for any number of
58
+ copies, and (iv) for any purpose whatsoever, including without limitation
59
+ commercial, advertising or promotional purposes (the “Waiver”). Affirmer
60
+ makes the Waiver for the benefit of each member of the public at large and
61
+ to the detriment of Affirmer’s heirs and successors, fully intending that
62
+ such Waiver shall not be subject to revocation, rescission, cancellation,
63
+ termination, or any other legal or equitable action to disrupt the quiet
64
+ enjoyment of the Work by the public as contemplated by Affirmer’s express
65
+ Statement of Purpose.
66
+
67
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
68
+ judged legally invalid or ineffective under applicable law, then the Waiver
69
+ shall be preserved to the maximum extent permitted taking into account
70
+ Affirmer’s express Statement of Purpose. In addition, to the extent the
71
+ Waiver is so judged Affirmer hereby grants to each affected person a
72
+ royalty-free, non transferable, non sublicensable, non exclusive,
73
+ irrevocable and unconditional license to exercise Affirmer’s Copyright and
74
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
75
+ maximum duration provided by applicable law or treaty (including future time
76
+ extensions), (iii) in any current or future medium and for any number of
77
+ copies, and (iv) for any purpose whatsoever, including without limitation
78
+ commercial, advertising or promotional purposes (the “License”). The License
79
+ shall be deemed effective as of the date CC0 was applied by Affirmer to the
80
+ Work. Should any part of the License for any reason be judged legally
81
+ invalid or ineffective under applicable law, such partial invalidity or
82
+ ineffectiveness shall not invalidate the remainder of the License, and in
83
+ such case Affirmer hereby affirms that he or she will not (i) exercise any
84
+ of his or her remaining Copyright and Related Rights in the Work or (ii)
85
+ assert any associated claims and causes of action with respect to the Work,
86
+ in either case contrary to Affirmer’s express Statement of Purpose.
87
+
88
+ 4. Limitations and Disclaimers.
89
+ 1. No trademark or patent rights held by Affirmer are waived, abandoned,
90
+ surrendered, licensed or otherwise affected by this document.
91
+ 2. Affirmer offers the Work as-is and makes no representations or warranties
92
+ of any kind concerning the Work, express, implied, statutory or
93
+ otherwise, including without limitation warranties of title,
94
+ merchantability, fitness for a particular purpose, non infringement, or
95
+ the absence of latent or other defects, accuracy, or the present or
96
+ absence of errors, whether or not discoverable, all to the greatest
97
+ extent permissible under applicable law.
98
+ 3. Affirmer disclaims responsibility for clearing rights of other persons
99
+ that may apply to the Work or any use thereof, including without
100
+ limitation any person’s Copyright and Related Rights in the Work.
101
+ Further, Affirmer disclaims responsibility for obtaining any necessary
102
+ consents, permissions or other rights required for any use of the Work.
103
+ 4. Affirmer understands and acknowledges that Creative Commons is not a
104
+ party to this document and has no duty or obligation with respect to this
105
+ CC0 or use of the Work.
106
+
107
+ For more information, please see
108
+ http://creativecommons.org/publicdomain/zero/1.0/.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # PostCSS HWB Function [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
2
+
3
+ [<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/postcss-hwb-function.svg" height="20">][npm-url]
4
+ [<img alt="CSS Standard Status" src="https://cssdb.org/badge/hwb-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="support chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
7
+
8
+
9
+ [PostCSS HWB Function] lets you use `hwb` color functions in
10
+ CSS, following the [CSS Color] specification.
11
+
12
+ ```pcss
13
+ a {
14
+ color: hwb(194 0% 0%);
15
+ color: hwb(194 0% 0% / .5);
16
+ }
17
+
18
+ /* becomes */
19
+
20
+ a {
21
+ color: rgb(0, 195, 255);
22
+ color: rgba(0, 195, 255, .5);
23
+ }
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Add [PostCSS HWB Function] to your project:
29
+
30
+ ```bash
31
+ npm install postcss @csstools/postcss-hwb-function --save-dev
32
+ ```
33
+
34
+ Use it as a [PostCSS] plugin:
35
+
36
+ ```js
37
+ const postcss = require('postcss');
38
+ const postcssHWBFunction = require('@csstools/postcss-hwb-function');
39
+
40
+ postcss([
41
+ postcssHWBFunction(/* pluginOptions */)
42
+ ]).process(YOUR_CSS /*, processOptions */);
43
+ ```
44
+
45
+ [PostCSS HWB Function] runs in all Node environments, with special
46
+ instructions for:
47
+
48
+ | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
49
+ | --- | --- | --- | --- | --- | --- |
50
+
51
+ ## Options
52
+
53
+ ### preserve
54
+
55
+ The `preserve` option determines whether the original functional color notation
56
+ is preserved. By default, it is not preserved.
57
+
58
+ ```js
59
+ postcssHWBFunction({ preserve: true })
60
+ ```
61
+
62
+ ```pcss
63
+ a {
64
+ color: hwb(194 0% 0%);
65
+ color: hwb(194 0% 0% / .5);
66
+ }
67
+
68
+ /* becomes */
69
+
70
+ a {
71
+ color: rgb(0, 195, 255);
72
+ color: hwb(194 0% 0%);
73
+ color: rgba(0, 195, 255, .5);
74
+ color: hwb(194 0% 0% / .5);
75
+ }
76
+ ```
77
+
78
+ [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
79
+ [css-url]: https://cssdb.org/#hwb-function
80
+ [git-url]: https://gitter.im/postcss/postcss
81
+ [npm-url]: https://www.npmjs.com/package/@csstools/postcss-hwb-function
82
+
83
+ [CSS Color]: https://drafts.csswg.org/css-color/#the-hwb-notation
84
+ [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
85
+ [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
86
+ [PostCSS]: https://github.com/postcss/postcss
87
+ [PostCSS Loader]: https://github.com/postcss/postcss-loader
88
+ [PostCSS HWB Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-hwb-function
@@ -0,0 +1,2 @@
1
+ import type { Node } from 'postcss';
2
+ export declare function hasSupportsAtRuleAncestor(node: Node): boolean;
package/dist/hwb.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare type color = [number, number, number];
2
+ export declare function hwbToRgb(hwb: color): color;
3
+ export {};
package/dist/index.cjs ADDED
@@ -0,0 +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]}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;
@@ -0,0 +1,6 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ /** Transform hwb() functions in CSS. */
3
+ declare const postcssPlugin: PluginCreator<{
4
+ preserve: boolean;
5
+ }>;
6
+ export default postcssPlugin;
package/dist/index.mjs ADDED
@@ -0,0 +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]}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,i=t*Math.min(r,1-r);return r-i*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(!o(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;i(t.w),i(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(!o(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(!o(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 i(n){if("%"!==n.unit)return n.unit="%",void(n.number=(100*parseFloat(n.number)).toString())}function o(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:i})=>{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 o=e.value;if(!o.includes("hwb"))return;const a=function(e,r,u){let i;try{i=n(e)}catch(n){r.warn(u,`Failed to parse value '${e}' as a hwb function. Leaving the original value intact.`)}if(void 0===i)return;i.walk((n=>{n.type&&"function"===n.type&&"hwb"===n.value&&t(n)}));const o=String(i);if(o===e)return;return o}(o,e,u);if(void 0!==a)if(e.variable&&r){const n=e.parent,t=i.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};
@@ -0,0 +1,2 @@
1
+ import type { FunctionNode } from 'postcss-value-parser';
2
+ export declare function onCSSFunctionSRgb(node: FunctionNode): void;
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@csstools/postcss-hwb-function",
3
+ "version": "1.0.0",
4
+ "description": "Use hwb() color functions 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-hwb-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
+ },
19
+ "files": [
20
+ "CHANGELOG.md",
21
+ "INSTALL.md",
22
+ "LICENSE.md",
23
+ "README.md",
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "rollup -c ../../rollup/default.js",
28
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
29
+ "lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
30
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
31
+ "stryker": "stryker run --logLevel error",
32
+ "test": "node .tape.mjs && npm run test:exports",
33
+ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
34
+ },
35
+ "engines": {
36
+ "node": "^12 || ^14 || >=16"
37
+ },
38
+ "dependencies": {
39
+ "postcss-value-parser": "^4.2.0"
40
+ },
41
+ "peerDependencies": {
42
+ "postcss": "^8.3"
43
+ },
44
+ "keywords": [
45
+ "postcss",
46
+ "css",
47
+ "postcss-plugin",
48
+ "color",
49
+ "colors",
50
+ "rgb",
51
+ "rgba",
52
+ "hsl",
53
+ "hsla",
54
+ "hwb",
55
+ "functional",
56
+ "notation",
57
+ "design",
58
+ "syntax",
59
+ "space",
60
+ "comma"
61
+ ],
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://github.com/csstools/postcss-plugins.git",
65
+ "directory": "plugins/postcss-hwb-function"
66
+ },
67
+ "volta": {
68
+ "extends": "../../package.json"
69
+ }
70
+ }