@csstools/postcss-color-mix-variadic-function-arguments 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,10 @@
1
+ # Changes to PostCSS Color Mix Variadic Function Arguments
2
+
3
+ ### 1.0.0
4
+
5
+ _May 27, 2025_
6
+
7
+ - Initial version
8
+ - Updated [`@csstools/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`3.0.5`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#305) (patch)
9
+ - Updated [`@csstools/css-color-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser) to [`3.0.10`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-color-parser/CHANGELOG.md#3010) (patch)
10
+
package/LICENSE.md ADDED
@@ -0,0 +1,18 @@
1
+ MIT No Attribution (MIT-0)
2
+
3
+ Copyright © CSSTools Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the “Software”), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # PostCSS Color Mix Variadic Function Arguments [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
2
+
3
+ `npm install @csstools/postcss-color-mix-variadic-function-arguments --save-dev`
4
+
5
+ [PostCSS Color Mix Variadic Function Arguments] lets you use the `color-mix()` function with any number of arguments following the [CSS Color 5 Specification].
6
+
7
+ ```css
8
+ .red {
9
+ color: color-mix(in srgb, red);
10
+ }
11
+
12
+ .grey {
13
+ color: color-mix(in srgb, red, lime, blue);
14
+ }
15
+
16
+ /* becomes */
17
+
18
+ .red {
19
+ color: rgb(255, 0, 0);
20
+ }
21
+
22
+ .grey {
23
+ color: rgb(85, 85, 85);
24
+ }
25
+ ```
26
+
27
+ > [!NOTE]
28
+ > We can not dynamically resolve `var()` arguments in `color-mix()`, only static values will work.
29
+
30
+ ## Usage
31
+
32
+ Add [PostCSS Color Mix Variadic Function Arguments] to your project:
33
+
34
+ ```bash
35
+ npm install postcss @csstools/postcss-color-mix-variadic-function-arguments --save-dev
36
+ ```
37
+
38
+ Use it as a [PostCSS] plugin:
39
+
40
+ ```js
41
+ const postcss = require('postcss');
42
+ const postcssColorMixVariadicFunctionArguments = require('@csstools/postcss-color-mix-variadic-function-arguments');
43
+
44
+ postcss([
45
+ postcssColorMixVariadicFunctionArguments(/* pluginOptions */)
46
+ ]).process(YOUR_CSS /*, processOptions */);
47
+ ```
48
+
49
+
50
+
51
+ ## Options
52
+
53
+ ### preserve
54
+
55
+ The `preserve` option determines whether the original notation
56
+ is preserved. By default, it is not preserved.
57
+
58
+ ```js
59
+ postcssColorMixVariadicFunctionArguments({ preserve: true })
60
+ ```
61
+
62
+ ```css
63
+ .red {
64
+ color: color-mix(in srgb, red);
65
+ }
66
+
67
+ .grey {
68
+ color: color-mix(in srgb, red, lime, blue);
69
+ }
70
+
71
+ /* becomes */
72
+
73
+ .red {
74
+ color: rgb(255, 0, 0);
75
+ color: color-mix(in srgb, red);
76
+ }
77
+
78
+ .grey {
79
+ color: rgb(85, 85, 85);
80
+ color: color-mix(in srgb, red, lime, blue);
81
+ }
82
+ ```
83
+
84
+ [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
85
+ [css-url]: https://cssdb.org/#color-mix-variadic-function-arguments
86
+ [discord]: https://discord.gg/bUadyRwkJS
87
+ [npm-url]: https://www.npmjs.com/package/@csstools/postcss-color-mix-variadic-function-arguments
88
+
89
+ [PostCSS]: https://github.com/postcss/postcss
90
+ [PostCSS Color Mix Variadic Function Arguments]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-mix-variadic-function-arguments
91
+ [CSS Color 5 Specification]: https://www.w3.org/TR/css-color-5/#color-mix
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var s=require("@csstools/postcss-progressive-custom-properties"),e=require("@csstools/css-color-parser"),r=require("@csstools/utilities"),t=require("@csstools/css-parser-algorithms"),o=require("@csstools/css-tokenizer");const a=/\bcolor-mix\(/i,i=/^color-mix$/i,basePlugin=s=>({postcssPlugin:"color-mix-variadic-function-arguments",Declaration(n){const l=n.value;if(!a.test(l))return;if(r.hasFallback(n))return;if(r.hasSupportsAtRuleAncestor(n,a))return;const u=o.tokenize({css:l}),c=t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!i.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)&&r.syntaxFlags.has(e.SyntaxFlag.ColorMixVariadic)?e.serializeRGB(r):void 0})),p=t.stringify(c);if(p===l)return;let m=p;s?.subFeatures.displayP3&&(m=t.stringify(t.replaceComponentValues(t.parseCommaSeparatedListOfComponentValues(u),(s=>{if(!t.isFunctionNode(s)||!i.test(s.getName()))return;const r=e.color(s);return r&&!r.syntaxFlags.has(e.SyntaxFlag.Experimental)?e.colorDataFitsRGB_Gamut(r)?e.serializeRGB(r):e.serializeP3(r):void 0})))),n.cloneBefore({value:p}),s?.subFeatures.displayP3&&m!==p&&n.cloneBefore({value:m}),s?.preserve||n.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"color-mix-variadic-function-arguments",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;
@@ -0,0 +1,19 @@
1
+ import type { PluginCreator } from 'postcss';
2
+
3
+ /** color-mix-variadic-function-arguments plugin options */
4
+ export declare type pluginOptions = {
5
+ /** Preserve the original notation. default: false */
6
+ preserve?: boolean;
7
+ /** Enable "@csstools/postcss-progressive-custom-properties". default: true */
8
+ enableProgressiveCustomProperties?: boolean;
9
+ /** Toggle sub features. default: { displayP3: true } */
10
+ subFeatures?: {
11
+ /** Enable displayP3 fallbacks. default: true */
12
+ displayP3?: boolean;
13
+ };
14
+ };
15
+
16
+ declare const postcssPlugin: PluginCreator<pluginOptions>;
17
+ export default postcssPlugin;
18
+
19
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import s from"@csstools/postcss-progressive-custom-properties";import{color as e,SyntaxFlag as r,serializeRGB as t,colorDataFitsRGB_Gamut as o,serializeP3 as i}from"@csstools/css-color-parser";import{hasFallback as a,hasSupportsAtRuleAncestor as n}from"@csstools/utilities";import{replaceComponentValues as c,parseCommaSeparatedListOfComponentValues as l,isFunctionNode as u,stringify as p}from"@csstools/css-parser-algorithms";import{tokenize as m}from"@csstools/css-tokenizer";const f=/\bcolor-mix\(/i,g=/^color-mix$/i,basePlugin=s=>({postcssPlugin:"color-mix-variadic-function-arguments",Declaration(v){const b=v.value;if(!f.test(b))return;if(a(v))return;if(n(v,f))return;const d=m({css:b}),x=c(l(d),(s=>{if(!u(s)||!g.test(s.getName()))return;const o=e(s);return o&&!o.syntaxFlags.has(r.Experimental)&&o.syntaxFlags.has(r.ColorMixVariadic)?t(o):void 0})),P=p(x);if(P===b)return;let F=P;s?.subFeatures.displayP3&&(F=p(c(l(d),(s=>{if(!u(s)||!g.test(s.getName()))return;const a=e(s);return a&&!a.syntaxFlags.has(r.Experimental)?o(a)?t(a):i(a):void 0})))),v.cloneBefore({value:P}),s?.subFeatures.displayP3&&F!==P&&v.cloneBefore({value:F}),s?.preserve||v.remove()}});basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!1,subFeatures:{displayP3:!0}},e);return r.subFeatures=Object.assign({displayP3:!0},r.subFeatures),r.enableProgressiveCustomProperties&&(r.preserve||r.subFeatures.displayP3)?{postcssPlugin:"color-mix-variadic-function-arguments",plugins:[s(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0;export{postcssPlugin as default};
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@csstools/postcss-color-mix-variadic-function-arguments",
3
+ "description": "Mix any number of colors with the color-mix function in CSS",
4
+ "version": "1.0.0",
5
+ "contributors": [
6
+ {
7
+ "name": "Antonio Laguna",
8
+ "email": "antonio@laguna.es",
9
+ "url": "https://antonio.laguna.es"
10
+ },
11
+ {
12
+ "name": "Romain Menke",
13
+ "email": "romainmenke@gmail.com"
14
+ }
15
+ ],
16
+ "license": "MIT-0",
17
+ "funding": [
18
+ {
19
+ "type": "github",
20
+ "url": "https://github.com/sponsors/csstools"
21
+ },
22
+ {
23
+ "type": "opencollective",
24
+ "url": "https://opencollective.com/csstools"
25
+ }
26
+ ],
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "type": "module",
31
+ "main": "dist/index.cjs",
32
+ "module": "dist/index.mjs",
33
+ "exports": {
34
+ ".": {
35
+ "import": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.mjs"
38
+ },
39
+ "require": {
40
+ "default": "./dist/index.cjs"
41
+ }
42
+ }
43
+ },
44
+ "files": [
45
+ "CHANGELOG.md",
46
+ "LICENSE.md",
47
+ "README.md",
48
+ "dist"
49
+ ],
50
+ "dependencies": {
51
+ "@csstools/css-color-parser": "^3.0.10",
52
+ "@csstools/css-parser-algorithms": "^3.0.5",
53
+ "@csstools/css-tokenizer": "^3.0.4",
54
+ "@csstools/postcss-progressive-custom-properties": "^4.1.0",
55
+ "@csstools/utilities": "^2.0.0"
56
+ },
57
+ "peerDependencies": {
58
+ "postcss": "^8.4"
59
+ },
60
+ "scripts": {},
61
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-mix-variadic-function-arguments#readme",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/csstools/postcss-plugins.git",
65
+ "directory": "plugins/postcss-color-mix-variadic-function-arguments"
66
+ },
67
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
68
+ "keywords": [
69
+ "color-mix",
70
+ "css",
71
+ "interpolation",
72
+ "postcss-plugin",
73
+ "syntax",
74
+ "variadic"
75
+ ]
76
+ }