@csstools/postcss-color-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 +5 -0
- package/LICENSE.md +108 -0
- package/README.md +141 -0
- package/dist/convert-a98-rgb-to-srgb.d.ts +3 -0
- package/dist/convert-cie-xyz-50-to-srgb.d.ts +3 -0
- package/dist/convert-cie-xyz-65-to-srgb.d.ts +3 -0
- package/dist/convert-display-p3-to-srgb.d.ts +3 -0
- package/dist/convert-prophoto-rgb-to-srgb.d.ts +3 -0
- package/dist/convert-rec2020-to-srgb.d.ts +3 -0
- package/dist/convert-srgb-linear-to-srgb.d.ts +3 -0
- package/dist/convert-srgb-to-srgb.d.ts +3 -0
- package/dist/css-color-4/conversions.d.ts +47 -0
- package/dist/css-color-4/deltaEOK.d.ts +11 -0
- package/dist/css-color-4/map-gamut.d.ts +5 -0
- package/dist/css-color-4/multiply-matrices.d.ts +13 -0
- package/dist/css-color-4/utilities.d.ts +25 -0
- package/dist/has-fallback-decl.d.ts +2 -0
- package/dist/has-supports-at-rule-ancestor.d.ts +2 -0
- package/dist/index.cjs +30 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +30 -0
- package/dist/modified-value.d.ts +2 -0
- package/dist/on-css-function.d.ts +3 -0
- package/package.json +73 -0
package/CHANGELOG.md
ADDED
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,141 @@
|
|
|
1
|
+
# PostCSS Color 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-color-function.svg" height="20">][npm-url]
|
|
4
|
+
[<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/color-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
|
+
|
|
8
|
+
|
|
9
|
+
[PostCSS Color Function] lets you use the `color` function in
|
|
10
|
+
CSS, following the [CSS Color] specification.
|
|
11
|
+
|
|
12
|
+
```pcss
|
|
13
|
+
.color {
|
|
14
|
+
color: color(display-p3 0.64331 0.19245 0.16771);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* becomes */
|
|
18
|
+
|
|
19
|
+
.color {
|
|
20
|
+
color: rgb(179,35,35);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Add [PostCSS Color Function] to your project:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install postcss @csstools/postcss-color-function --save-dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use it as a [PostCSS] plugin:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const postcss = require('postcss');
|
|
36
|
+
const postcssColorFunction = require('@csstools/postcss-color-function');
|
|
37
|
+
|
|
38
|
+
postcss([
|
|
39
|
+
postcssColorFunction(/* pluginOptions */)
|
|
40
|
+
]).process(YOUR_CSS /*, processOptions */);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
[PostCSS Color Function] runs in all Node environments, with special
|
|
44
|
+
instructions for:
|
|
45
|
+
|
|
46
|
+
| [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) |
|
|
47
|
+
| --- | --- | --- | --- | --- | --- |
|
|
48
|
+
|
|
49
|
+
## Options
|
|
50
|
+
|
|
51
|
+
### preserve
|
|
52
|
+
|
|
53
|
+
The `preserve` option determines whether the original notation
|
|
54
|
+
is preserved. By default, it is not preserved.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
postcssColorFunction({ preserve: true })
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```pcss
|
|
61
|
+
.color {
|
|
62
|
+
color: color(display-p3 0.64331 0.19245 0.16771);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* becomes */
|
|
66
|
+
|
|
67
|
+
.color {
|
|
68
|
+
color: rgb(179,35,35);
|
|
69
|
+
color: color(display-p3 0.64331 0.19245 0.16771);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### enableProgressiveCustomProperties
|
|
74
|
+
|
|
75
|
+
The `enableProgressiveCustomProperties` option determines whether the original notation
|
|
76
|
+
is wrapped with `@supports` when used in Custom Properties. By default, it is enabled.
|
|
77
|
+
|
|
78
|
+
⚠️ Only disabled this when you set `preserve` to `false` or if you bring your own fix for Custom Properties.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
postcssColorFunction({ enableProgressiveCustomProperties: false })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```pcss
|
|
85
|
+
:root {
|
|
86
|
+
--one: color(srgb 0.64331 0.19245 0.16771);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* becomes */
|
|
90
|
+
|
|
91
|
+
:root {
|
|
92
|
+
--one: rgb(164,49,43); /* will never be used, not even in older browser */
|
|
93
|
+
--one: color(srgb 0.64331 0.19245 0.16771);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Supported Color Spaces
|
|
98
|
+
|
|
99
|
+
```css
|
|
100
|
+
.color-spaces {
|
|
101
|
+
color: color(a98-rgb 0.803 0.484 0.944);
|
|
102
|
+
color: color(display-p3 0.8434 0.509 0.934);
|
|
103
|
+
color: color(prophoto-rgb 0.759 0.493 0.898);
|
|
104
|
+
color: color(rec2020 0.772 0.491 0.920);
|
|
105
|
+
color: color(srgb 0.897 0.488 0.959);
|
|
106
|
+
color: color(srgb-linear 0.783 0.203 0.910);
|
|
107
|
+
color: color(xyz 0.560 0.377 0.904);
|
|
108
|
+
color: color(xyz-d50 0.550 0.375 0.680);
|
|
109
|
+
color: color(xyz-d65 0.560 0.377 0.904);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Out of gamut colors
|
|
114
|
+
|
|
115
|
+
Depending on the browser implementation out of gamut colors may be clipped, resulting in a different color.<br>
|
|
116
|
+
Fallback values generated by [PostCSS Color Function] are always mapped to a close alternative in sRGB.
|
|
117
|
+
|
|
118
|
+
When setting `preserve` to `true` the original values will be used by some browsers and these may be clipped.<br>
|
|
119
|
+
Certain browsers will have an incorrect color if this occurs.
|
|
120
|
+
|
|
121
|
+
If the plugin detects out of gamut colors it will emit a warning :
|
|
122
|
+
|
|
123
|
+
> "color(srgb-linear -0.01656 0.23079 0.25298)" is out of gamut for "srgb-linear". When "preserve: true" is set this will lead to unexpected results in some browsers.
|
|
124
|
+
|
|
125
|
+
To resolve this warning pick a larger color space when declaring the original value.
|
|
126
|
+
|
|
127
|
+
## Copyright : color conversions
|
|
128
|
+
|
|
129
|
+
This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/tree/main/css-color-4. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
130
|
+
|
|
131
|
+
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|
132
|
+
[css-url]: https://cssdb.org/#color-function
|
|
133
|
+
[discord]: https://discord.gg/bUadyRwkJS
|
|
134
|
+
[npm-url]: https://www.npmjs.com/package/@csstools/postcss-color-function
|
|
135
|
+
|
|
136
|
+
[CSS Color]: https://www.w3.org/TR/css-color-4/#funcdef-color
|
|
137
|
+
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|
138
|
+
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|
139
|
+
[PostCSS]: https://github.com/postcss/postcss
|
|
140
|
+
[PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|
141
|
+
[PostCSS Color Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-function
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license W3C
|
|
3
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
4
|
+
*
|
|
5
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
|
|
8
|
+
*/
|
|
9
|
+
declare type color = [number, number, number];
|
|
10
|
+
export declare const D50: number[];
|
|
11
|
+
export declare const D65: number[];
|
|
12
|
+
export declare function lin_sRGB(RGB: color): color;
|
|
13
|
+
export declare function gam_sRGB(RGB: color): color;
|
|
14
|
+
export declare function lin_sRGB_to_XYZ(rgb: color): color;
|
|
15
|
+
export declare function XYZ_to_lin_sRGB(XYZ: color): color;
|
|
16
|
+
export declare function lin_P3(RGB: color): color;
|
|
17
|
+
export declare function gam_P3(RGB: color): color;
|
|
18
|
+
export declare function lin_P3_to_XYZ(rgb: color): color;
|
|
19
|
+
export declare function XYZ_to_lin_P3(XYZ: color): color;
|
|
20
|
+
export declare function lin_ProPhoto(RGB: color): color;
|
|
21
|
+
export declare function gam_ProPhoto(RGB: color): color;
|
|
22
|
+
export declare function lin_ProPhoto_to_XYZ(rgb: color): color;
|
|
23
|
+
export declare function XYZ_to_lin_ProPhoto(XYZ: color): color;
|
|
24
|
+
export declare function lin_a98rgb(RGB: color): color;
|
|
25
|
+
export declare function gam_a98rgb(RGB: color): color;
|
|
26
|
+
export declare function lin_a98rgb_to_XYZ(rgb: color): color;
|
|
27
|
+
export declare function XYZ_to_lin_a98rgb(XYZ: color): color;
|
|
28
|
+
export declare function lin_2020(RGB: color): color;
|
|
29
|
+
export declare function gam_2020(RGB: color): color;
|
|
30
|
+
export declare function lin_2020_to_XYZ(rgb: color): color;
|
|
31
|
+
export declare function XYZ_to_lin_2020(XYZ: color): color;
|
|
32
|
+
export declare function D65_to_D50(XYZ: color): color;
|
|
33
|
+
export declare function D50_to_D65(XYZ: color): color;
|
|
34
|
+
export declare function XYZ_to_Lab(XYZ: color): color;
|
|
35
|
+
export declare function Lab_to_XYZ(Lab: color): color;
|
|
36
|
+
export declare function Lab_to_LCH(Lab: color): color;
|
|
37
|
+
export declare function LCH_to_Lab(LCH: color): color;
|
|
38
|
+
export declare function XYZ_to_OKLab(XYZ: color): color;
|
|
39
|
+
export declare function OKLab_to_XYZ(OKLab: color): color;
|
|
40
|
+
export declare function OKLab_to_OKLCH(OKLab: color): color;
|
|
41
|
+
export declare function OKLCH_to_OKLab(OKLCH: color): color;
|
|
42
|
+
export declare function rectangular_premultiply(color: color, alpha: number): color;
|
|
43
|
+
export declare function rectangular_un_premultiply(color: color, alpha: number): color;
|
|
44
|
+
export declare function polar_premultiply(color: color, alpha: number, hueIndex: number): color;
|
|
45
|
+
export declare function polar_un_premultiply(color: color, alpha: number, hueIndex: number): color;
|
|
46
|
+
export declare function hsl_premultiply(color: color, alpha: number): color;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license W3C
|
|
3
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
4
|
+
*
|
|
5
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
|
|
8
|
+
*/
|
|
9
|
+
declare type color = [number, number, number];
|
|
10
|
+
export declare function deltaEOK(reference: color, sample: color): number;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type color = [number, number, number];
|
|
2
|
+
export declare function mapGamut(startOKLCH: color, toDestination: (x: color) => color, fromDestination: (x: color) => color): color;
|
|
3
|
+
export declare function clip(color: color): color;
|
|
4
|
+
export declare function inGamut(x: color): boolean;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple matrix (and vector) multiplication
|
|
3
|
+
* Warning: No error handling for incompatible dimensions!
|
|
4
|
+
* @author Lea Verou 2020 MIT License
|
|
5
|
+
*
|
|
6
|
+
* @license W3C
|
|
7
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
8
|
+
*
|
|
9
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
|
|
12
|
+
*/
|
|
13
|
+
export declare function multiplyMatrices(a: Array<Array<number>> | Array<number>, b: Array<Array<number>> | Array<number>): Array<Array<number>> | Array<number>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license W3C
|
|
3
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
4
|
+
*
|
|
5
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js
|
|
8
|
+
*/
|
|
9
|
+
declare type color = [number, number, number];
|
|
10
|
+
export declare function sRGB_to_luminance(RGB: color): number;
|
|
11
|
+
export declare function contrast(RGB1: color, RGB2: color): number;
|
|
12
|
+
export declare function sRGB_to_LCH(RGB: color): color;
|
|
13
|
+
export declare function P3_to_LCH(RGB: color): color;
|
|
14
|
+
export declare function r2020_to_LCH(RGB: color): color;
|
|
15
|
+
export declare function LCH_to_sRGB(LCH: color): color;
|
|
16
|
+
export declare function LCH_to_P3(LCH: color): color;
|
|
17
|
+
export declare function LCH_to_r2020(LCH: color): color;
|
|
18
|
+
export declare function hslToRgb(hsl: color): color;
|
|
19
|
+
export declare function hueToRgb(t1: number, t2: number, hue: number): number;
|
|
20
|
+
export declare function naive_CMYK_to_sRGB(CMYK: [number, number, number, number]): color;
|
|
21
|
+
export declare function naive_sRGB_to_CMYK(RGB: color): [number, number, number, number];
|
|
22
|
+
export declare function XYZ_to_xy(XYZ: color): [number, number];
|
|
23
|
+
export declare function xy_to_uv(xy: [number, number]): [number, number];
|
|
24
|
+
export declare function XYZ_to_uv(XYZ: color): [number, number];
|
|
25
|
+
export {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";var e=require("@csstools/postcss-progressive-custom-properties"),r=require("postcss-value-parser");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e),u=t(r);
|
|
2
|
+
/**
|
|
3
|
+
* Simple matrix (and vector) multiplication
|
|
4
|
+
* Warning: No error handling for incompatible dimensions!
|
|
5
|
+
* @author Lea Verou 2020 MIT License
|
|
6
|
+
*
|
|
7
|
+
* @license W3C
|
|
8
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
9
|
+
*
|
|
10
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
|
|
13
|
+
*/
|
|
14
|
+
function a(e,r){const t=e.length;let n,u;n=Array.isArray(e[0])?e:[e],Array.isArray(r[0])||(u=r.map((e=>[e])));const a=u[0].length,o=u[0].map(((e,r)=>u.map((e=>e[r]))));let s=n.map((e=>o.map((r=>Array.isArray(e)?e.reduce(((e,t,n)=>e+t*(r[n]||0)),0):r.reduce(((r,t)=>r+t*e),0)))));return 1===t&&(s=s[0]),1===a?s.map((e=>e[0])):s}
|
|
15
|
+
/**
|
|
16
|
+
* @license W3C
|
|
17
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
18
|
+
*
|
|
19
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
20
|
+
*
|
|
21
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
|
|
22
|
+
*/function o(e){return e.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return t<.04045?e/12.92:r*Math.pow((t+.055)/1.055,2.4)}))}function s(e){return e.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return t>.0031308?r*(1.055*Math.pow(t,1/2.4)-.055):12.92*e}))}function c(e){return a([[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],e)}function i(e){return a([[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],e)}function l(e){return a([[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]],e)}function p(e){const r=a([[.8190224432164319,.3619062562801221,-.12887378261216414],[.0329836671980271,.9292868468965546,.03614466816999844],[.048177199566046255,.26423952494422764,.6335478258136937]],e);return a([[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],r.map((e=>Math.cbrt(e))))}function f(e){const r=a([[.9999999984505198,.39633779217376786,.2158037580607588],[1.0000000088817609,-.10556134232365635,-.06385417477170591],[1.0000000546724108,-.08948418209496575,-1.2914855378640917]],e);return a([[1.2268798733741557,-.5578149965554813,.28139105017721583],[-.04057576262431372,1.1122868293970594,-.07171106666151701],[-.07637294974672142,-.4214933239627914,1.5869240244272418]],r.map((e=>e**3)))}function d(e){const r=180*Math.atan2(e[2],e[1])/Math.PI;return[e[0],Math.sqrt(e[1]**2+e[2]**2),r>=0?r:r+360]}function v(e){return[e[0],e[1]*Math.cos(e[2]*Math.PI/180),e[1]*Math.sin(e[2]*Math.PI/180)]}
|
|
23
|
+
/**
|
|
24
|
+
* @license W3C
|
|
25
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
26
|
+
*
|
|
27
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
28
|
+
*
|
|
29
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
|
|
30
|
+
*/function h(e,r){const[t,n,u]=e,[a,o,s]=r,c=t-a,i=n-o,l=u-s;return Math.sqrt(c**2+i**2+l**2)}function b(e,r,t){return function(e,r,t){let n=0,u=e[1];const a=e;for(;u-n>1e-4;){h(a,t(m(r(a))))-.02<1e-4?n=a[1]:u=a[1],a[1]=(u+n)/2}return m(r([...a]))}(e,r,t)}function m(e){return e.map((e=>e<0?0:e>1?1:e))}function y(e){const[r,t,n]=e;return r>=-1e-4&&r<=1.0001&&t>=-1e-4&&t<=1.0001&&n>=-1e-4&&n<=1.0001}function g(e){let r=e.slice();r=r.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return r*Math.pow(t,563/256)})),r=a([[.5766690429101305,.1855582379065463,.1882286462349947],[.29734497525053605,.6273635662554661,.07529145849399788],[.02703136138641234,.07068885253582723,.9913375368376388]],r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function x(e){let r=e.slice();r=l(r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function M(e){let r=e.slice(),t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function w(e){let r=e.slice();r=o(r),r=a([[.4865709486482162,.26566769316909306,.1982172852343625],[.2289745640697488,.6917385218365064,.079286914093745],[0,.04511338185890264,1.043944368900976]],r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function I(e){let r=e.slice();r=r.map((function(e){const r=e<0?-1:1;return Math.abs(e)<=.03125?e/16:r*Math.pow(e,1.8)})),r=a([[.7977604896723027,.13518583717574031,.0313493495815248],[.2880711282292934,.7118432178101014,8565396060525902e-20],[0,0,.8251046025104601]],r),r=l(r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function S(e){let r=e.slice();r=function(e){const r=1.09929682680944;return e.map((function(e){const t=e<0?-1:1,n=Math.abs(e);return n<.08124285829863151?e/4.5:t*Math.pow((n+r-1)/r,1/.45)}))}(r),r=a([[.6369580483012914,.14461690358620832,.1688809751641721],[.2627002120112671,.6779980715188708,.05930171646986196],[0,.028072693049087428,1.060985057710791]],r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function k(e){let r=e.slice();r=c(r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function P(e){let r=e.slice();r=o(r),r=c(r);let t=r.slice();return t=p(t),t=d(t),r=i(r),r=s(r),y(r)?m(r):b(t,(e=>s(e=i(e=f(e=v(e))))),(e=>d(e=p(e=c(e=o(e))))))}function E(e,r,t,n){const a=u.default.stringify(e),o=e.value,s=e.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let c,i=null;if("color"===o&&(i=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;switch(e.value){case"srgb":case"srgb-linear":case"display-p3":case"a98-rgb":case"prophoto-rgb":case"rec2020":case"xyz-d50":case"xyz-d65":case"xyz":return!0;default:return!1}}(e[0]))return null;const r={colorSpace:e[0].value,colorSpaceNode:e[0],parameters:[]};for(let t=1;t<e.length;t++)if(j(e[t]))r.slash=e[t];else{if(r.slash&&(z(e[t])||A(e[t])||O(e[t]))){r.alpha=e[t];break}if(!z(e[t]))return null;{const n=u.default.unit(e[t].value);"%"===n.unit&&(n.number=String(parseFloat(n.number)/100),n.unit="",e[t].value=String(n.number)),r.parameters.push({value:n,node:e[t]})}}if(0===r.parameters.length)return r;r.parameters.length<3&&(r.parameters=[...r.parameters,{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}},{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}}]);r.parameters.length>3&&(r.parameters=r.parameters.slice(0,3));return r}(s)),!i)return;switch(e.value="rgb",function(e,r,t){if(!r||!t)return;if(e.value="rgba",r.value=",",r.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!q(e))return!1;const r=u.default.unit(e.value);if(!r)return!1;return!!r.number}(t))return;const n=u.default.unit(t.value);if(!n)return;"%"===n.unit&&(n.number=String(parseFloat(n.number)/100),t.value=String(n.number))}(e,i.slash,i.alpha),i.colorSpace){case"srgb":c=P;break;case"srgb-linear":c=k;break;case"a98-rgb":c=g;break;case"prophoto-rgb":c=I;break;case"display-p3":c=w;break;case"rec2020":c=S;break;case"xyz-d50":c=x;break;case"xyz-d65":case"xyz":c=M;break;default:return}const l=(p=i,p.parameters.map((e=>e.value))).map((e=>parseFloat(e.number)));var p;const f=c(l);!y(l)&&n&&r.warn(t,`"${a}" is out of gamut for "${i.colorSpace}". When "preserve: true" is set this will lead to unexpected results in some browsers.`),e.nodes=[{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[0])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[1])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[2])),type:"word"}],i.alpha&&(e.nodes.push({sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.push(i.alpha))}function z(e){if(!e||"word"!==e.type)return!1;if(!q(e))return!1;const r=u.default.unit(e.value);return!!r&&("%"===r.unit||""===r.unit)}function A(e){return e&&"function"===e.type&&"calc"===e.value}function O(e){return e&&"function"===e.type&&"var"===e.value}function j(e){return e&&"div"===e.type&&"/"===e.value}function q(e){if(!e||!e.value)return!1;try{return!1!==u.default.unit(e.value)}catch(e){return!1}}const B=e=>{const r="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-function",Declaration:(e,{result:t})=>{if(function(e){const r=e.parent;if(!r)return!1;const t=r.index(e);for(let n=0;n<t;n++){const t=r.nodes[n];if("decl"===t.type&&t.prop===e.prop)return!0}return!1}(e))return;if(function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("color("))return!0;r=r.parent}else r=r.parent;return!1}(e))return;const n=e.value;if(-1===n.indexOf("color("))return;const a=function(e,r,t,n){let a;try{a=u.default(e)}catch(n){r.warn(t,`Failed to parse value '${e}' as a color function. Leaving the original value intact.`)}if(void 0===a)return;a.walk((e=>{e.type&&"function"===e.type&&"color"===e.value&&E(e,r,t,n)}));const o=String(a);return o!==e?o:void 0}(n,e,t,r);void 0!==a&&(r?e.cloneBefore({value:a}):e.value=a)}}};B.postcss=!0;const F=e=>{const r="preserve"in Object(e)&&Boolean(e.preserve);return(!("enableProgressiveCustomProperties"in Object(e))||Boolean(e.enableProgressiveCustomProperties))&&r?{postcssPlugin:"postcss-color-function",plugins:[n.default(),B({preserve:r})]}:B({preserve:r})};F.postcss=!0,module.exports=F;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginCreator } from 'postcss';
|
|
2
|
+
/** Dynamically include "postcssProgressiveCustomProperties" only when needed. */
|
|
3
|
+
declare const postcssPlugin: PluginCreator<{
|
|
4
|
+
preserve?: boolean;
|
|
5
|
+
enableProgressiveCustomProperties?: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
export default postcssPlugin;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import e from"@csstools/postcss-progressive-custom-properties";import r from"postcss-value-parser";
|
|
2
|
+
/**
|
|
3
|
+
* Simple matrix (and vector) multiplication
|
|
4
|
+
* Warning: No error handling for incompatible dimensions!
|
|
5
|
+
* @author Lea Verou 2020 MIT License
|
|
6
|
+
*
|
|
7
|
+
* @license W3C
|
|
8
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
9
|
+
*
|
|
10
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
|
|
13
|
+
*/
|
|
14
|
+
function t(e,r){const t=e.length;let n,u;n=Array.isArray(e[0])?e:[e],Array.isArray(r[0])||(u=r.map((e=>[e])));const o=u[0].length,a=u[0].map(((e,r)=>u.map((e=>e[r]))));let s=n.map((e=>a.map((r=>Array.isArray(e)?e.reduce(((e,t,n)=>e+t*(r[n]||0)),0):r.reduce(((r,t)=>r+t*e),0)))));return 1===t&&(s=s[0]),1===o?s.map((e=>e[0])):s}
|
|
15
|
+
/**
|
|
16
|
+
* @license W3C
|
|
17
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
18
|
+
*
|
|
19
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
20
|
+
*
|
|
21
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
|
|
22
|
+
*/function n(e){return e.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return t<.04045?e/12.92:r*Math.pow((t+.055)/1.055,2.4)}))}function u(e){return e.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return t>.0031308?r*(1.055*Math.pow(t,1/2.4)-.055):12.92*e}))}function o(e){return t([[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],e)}function a(e){return t([[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],e)}function s(e){return t([[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]],e)}function c(e){const r=t([[.8190224432164319,.3619062562801221,-.12887378261216414],[.0329836671980271,.9292868468965546,.03614466816999844],[.048177199566046255,.26423952494422764,.6335478258136937]],e);return t([[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],r.map((e=>Math.cbrt(e))))}function i(e){const r=t([[.9999999984505198,.39633779217376786,.2158037580607588],[1.0000000088817609,-.10556134232365635,-.06385417477170591],[1.0000000546724108,-.08948418209496575,-1.2914855378640917]],e);return t([[1.2268798733741557,-.5578149965554813,.28139105017721583],[-.04057576262431372,1.1122868293970594,-.07171106666151701],[-.07637294974672142,-.4214933239627914,1.5869240244272418]],r.map((e=>e**3)))}function l(e){const r=180*Math.atan2(e[2],e[1])/Math.PI;return[e[0],Math.sqrt(e[1]**2+e[2]**2),r>=0?r:r+360]}function p(e){return[e[0],e[1]*Math.cos(e[2]*Math.PI/180),e[1]*Math.sin(e[2]*Math.PI/180)]}
|
|
23
|
+
/**
|
|
24
|
+
* @license W3C
|
|
25
|
+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
|
|
26
|
+
*
|
|
27
|
+
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
|
|
28
|
+
*
|
|
29
|
+
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
|
|
30
|
+
*/function f(e,r){const[t,n,u]=e,[o,a,s]=r,c=t-o,i=n-a,l=u-s;return Math.sqrt(c**2+i**2+l**2)}function d(e,r,t){return function(e,r,t){let n=0,u=e[1];const o=e;for(;u-n>1e-4;){f(o,t(v(r(o))))-.02<1e-4?n=o[1]:u=o[1],o[1]=(u+n)/2}return v(r([...o]))}(e,r,t)}function v(e){return e.map((e=>e<0?0:e>1?1:e))}function m(e){const[r,t,n]=e;return r>=-1e-4&&r<=1.0001&&t>=-1e-4&&t<=1.0001&&n>=-1e-4&&n<=1.0001}function h(e){let r=e.slice();r=r.map((function(e){const r=e<0?-1:1,t=Math.abs(e);return r*Math.pow(t,563/256)})),r=t([[.5766690429101305,.1855582379065463,.1882286462349947],[.29734497525053605,.6273635662554661,.07529145849399788],[.02703136138641234,.07068885253582723,.9913375368376388]],r);let s=r.slice();return s=c(s),s=l(s),r=a(r),r=u(r),m(r)?v(r):d(s,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function b(e){let r=e.slice();r=s(r);let t=r.slice();return t=c(t),t=l(t),r=a(r),r=u(r),m(r)?v(r):d(t,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function y(e){let r=e.slice(),t=r.slice();return t=c(t),t=l(t),r=a(r),r=u(r),m(r)?v(r):d(t,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function g(e){let r=e.slice();r=n(r),r=t([[.4865709486482162,.26566769316909306,.1982172852343625],[.2289745640697488,.6917385218365064,.079286914093745],[0,.04511338185890264,1.043944368900976]],r);let s=r.slice();return s=c(s),s=l(s),r=a(r),r=u(r),m(r)?v(r):d(s,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function x(e){let r=e.slice();r=r.map((function(e){const r=e<0?-1:1;return Math.abs(e)<=.03125?e/16:r*Math.pow(e,1.8)})),r=t([[.7977604896723027,.13518583717574031,.0313493495815248],[.2880711282292934,.7118432178101014,8565396060525902e-20],[0,0,.8251046025104601]],r),r=s(r);let f=r.slice();return f=c(f),f=l(f),r=a(r),r=u(r),m(r)?v(r):d(f,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function M(e){let r=e.slice();r=function(e){const r=1.09929682680944;return e.map((function(e){const t=e<0?-1:1,n=Math.abs(e);return n<.08124285829863151?e/4.5:t*Math.pow((n+r-1)/r,1/.45)}))}(r),r=t([[.6369580483012914,.14461690358620832,.1688809751641721],[.2627002120112671,.6779980715188708,.05930171646986196],[0,.028072693049087428,1.060985057710791]],r);let s=r.slice();return s=c(s),s=l(s),r=a(r),r=u(r),m(r)?v(r):d(s,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function w(e){let r=e.slice();r=o(r);let t=r.slice();return t=c(t),t=l(t),r=a(r),r=u(r),m(r)?v(r):d(t,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function I(e){let r=e.slice();r=n(r),r=o(r);let t=r.slice();return t=c(t),t=l(t),r=a(r),r=u(r),m(r)?v(r):d(t,(e=>u(e=a(e=i(e=p(e))))),(e=>l(e=c(e=o(e=n(e))))))}function S(e,t,n,u){const o=r.stringify(e),a=e.value,s=e.nodes.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let c,i=null;if("color"===a&&(i=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;switch(e.value){case"srgb":case"srgb-linear":case"display-p3":case"a98-rgb":case"prophoto-rgb":case"rec2020":case"xyz-d50":case"xyz-d65":case"xyz":return!0;default:return!1}}(e[0]))return null;const t={colorSpace:e[0].value,colorSpaceNode:e[0],parameters:[]};for(let n=1;n<e.length;n++)if(z(e[n]))t.slash=e[n];else{if(t.slash&&(k(e[n])||P(e[n])||E(e[n]))){t.alpha=e[n];break}if(!k(e[n]))return null;{const u=r.unit(e[n].value);"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),u.unit="",e[n].value=String(u.number)),t.parameters.push({value:u,node:e[n]})}}if(0===t.parameters.length)return t;t.parameters.length<3&&(t.parameters=[...t.parameters,{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}},{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}}]);t.parameters.length>3&&(t.parameters=t.parameters.slice(0,3));return t}(s)),!i)return;switch(e.value="rgb",function(e,t,n){if(!t||!n)return;if(e.value="rgba",t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!A(e))return!1;const t=r.unit(e.value);if(!t)return!1;return!!t.number}(n))return;const u=r.unit(n.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),n.value=String(u.number))}(e,i.slash,i.alpha),i.colorSpace){case"srgb":c=I;break;case"srgb-linear":c=w;break;case"a98-rgb":c=h;break;case"prophoto-rgb":c=x;break;case"display-p3":c=g;break;case"rec2020":c=M;break;case"xyz-d50":c=b;break;case"xyz-d65":case"xyz":c=y;break;default:return}const l=(p=i,p.parameters.map((e=>e.value))).map((e=>parseFloat(e.number)));var p;const f=c(l);!m(l)&&u&&t.warn(n,`"${o}" is out of gamut for "${i.colorSpace}". When "preserve: true" is set this will lead to unexpected results in some browsers.`),e.nodes=[{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[0])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[1])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*f[2])),type:"word"}],i.alpha&&(e.nodes.push({sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.push(i.alpha))}function k(e){if(!e||"word"!==e.type)return!1;if(!A(e))return!1;const t=r.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function P(e){return e&&"function"===e.type&&"calc"===e.value}function E(e){return e&&"function"===e.type&&"var"===e.value}function z(e){return e&&"div"===e.type&&"/"===e.value}function A(e){if(!e||!e.value)return!1;try{return!1!==r.unit(e.value)}catch(e){return!1}}const O=e=>{const t="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-function",Declaration:(e,{result:n})=>{if(function(e){const r=e.parent;if(!r)return!1;const t=r.index(e);for(let n=0;n<t;n++){const t=r.nodes[n];if("decl"===t.type&&t.prop===e.prop)return!0}return!1}(e))return;if(function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("color("))return!0;r=r.parent}else r=r.parent;return!1}(e))return;const u=e.value;if(-1===u.indexOf("color("))return;const o=function(e,t,n,u){let o;try{o=r(e)}catch(r){t.warn(n,`Failed to parse value '${e}' as a color function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&"color"===e.value&&S(e,t,n,u)}));const a=String(o);return a!==e?a:void 0}(u,e,n,t);void 0!==o&&(t?e.cloneBefore({value:o}):e.value=o)}}};O.postcss=!0;const B=r=>{const t="preserve"in Object(r)&&Boolean(r.preserve);return(!("enableProgressiveCustomProperties"in Object(r))||Boolean(r.enableProgressiveCustomProperties))&&t?{postcssPlugin:"postcss-color-function",plugins:[e(),O({preserve:t})]}:O({preserve:t})};B.postcss=!0;export{B as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@csstools/postcss-color-function",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Use the color() function 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-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
|
+
"LICENSE.md",
|
|
22
|
+
"README.md",
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
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 .tape.mjs && npm run test:exports",
|
|
32
|
+
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
|
|
33
|
+
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": "^12 || ^14 || >=16"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@csstools/postcss-progressive-custom-properties": "^1.0.0",
|
|
40
|
+
"postcss-value-parser": "^4.2.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"postcss-lab-function": "^4.0.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"postcss": "^8.4"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"postcss",
|
|
50
|
+
"css",
|
|
51
|
+
"postcss-plugin",
|
|
52
|
+
"color",
|
|
53
|
+
"colors",
|
|
54
|
+
"rgb",
|
|
55
|
+
"rgba",
|
|
56
|
+
"color",
|
|
57
|
+
"display-p3",
|
|
58
|
+
"prophoto-rgb",
|
|
59
|
+
"xyz",
|
|
60
|
+
"rec2020",
|
|
61
|
+
"srgb-linear",
|
|
62
|
+
"design",
|
|
63
|
+
"syntax"
|
|
64
|
+
],
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
68
|
+
"directory": "plugins/postcss-color-function"
|
|
69
|
+
},
|
|
70
|
+
"volta": {
|
|
71
|
+
"extends": "../../package.json"
|
|
72
|
+
}
|
|
73
|
+
}
|