postcss-colormin 5.2.5 → 5.3.1
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/package.json +7 -5
- package/src/index.js +36 -8
- package/src/minifyColor.js +3 -2
- package/types/index.d.ts +10 -0
- package/types/minifyColor.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-colormin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "Minify colors in your CSS files with PostCSS.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"src",
|
|
8
|
-
"LICENSE-MIT"
|
|
9
|
+
"LICENSE-MIT",
|
|
10
|
+
"types"
|
|
9
11
|
],
|
|
10
12
|
"keywords": [
|
|
11
13
|
"color",
|
|
@@ -25,7 +27,7 @@
|
|
|
25
27
|
},
|
|
26
28
|
"repository": "cssnano/cssnano",
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"browserslist": "^4.
|
|
30
|
+
"browserslist": "^4.21.4",
|
|
29
31
|
"caniuse-api": "^3.0.0",
|
|
30
32
|
"colord": "^2.9.1",
|
|
31
33
|
"postcss-value-parser": "^4.2.0"
|
|
@@ -37,10 +39,10 @@
|
|
|
37
39
|
"node": "^10 || ^12 || >=14.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
42
|
+
"@types/caniuse-api": "^3.0.2",
|
|
40
43
|
"postcss": "^8.2.15"
|
|
41
44
|
},
|
|
42
45
|
"peerDependencies": {
|
|
43
46
|
"postcss": "^8.2.15"
|
|
44
|
-
}
|
|
45
|
-
"readme": "# [postcss][postcss]-colormin\n\n> Minify colors in your CSS files with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-colormin) do:\n\n```\nnpm install postcss-colormin --save\n```\n\n\n## Example\n\n```js\nvar postcss = require('postcss')\nvar colormin = require('postcss-colormin');\n\nvar css = 'h1 {color: rgba(255, 0, 0, 1)}';\nconsole.log(postcss(colormin()).process(css).css);\n\n// => 'h1 {color:red}'\n```\n\nFor more examples see the [tests](src/__tests__/index.js).\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
47
|
+
}
|
|
46
48
|
}
|
package/src/index.js
CHANGED
|
@@ -4,11 +4,16 @@ const { isSupported } = require('caniuse-api');
|
|
|
4
4
|
const valueParser = require('postcss-value-parser');
|
|
5
5
|
const minifyColor = require('./minifyColor');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @param {{nodes: valueParser.Node[]}} parent
|
|
9
|
+
* @param {(node: valueParser.Node, index: number, parent: {nodes: valueParser.Node[]}) => false | undefined} callback
|
|
10
|
+
* @return {void}
|
|
11
|
+
*/
|
|
7
12
|
function walk(parent, callback) {
|
|
8
13
|
parent.nodes.forEach((node, index) => {
|
|
9
14
|
const bubble = callback(node, index, parent);
|
|
10
15
|
|
|
11
|
-
if (node.
|
|
16
|
+
if (node.type === 'function' && bubble !== false) {
|
|
12
17
|
walk(node, callback);
|
|
13
18
|
}
|
|
14
19
|
});
|
|
@@ -23,6 +28,10 @@ function walk(parent, callback) {
|
|
|
23
28
|
const browsersWithTransparentBug = new Set(['ie 8', 'ie 9']);
|
|
24
29
|
const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);
|
|
25
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @param {valueParser.Node} node
|
|
33
|
+
* @return {boolean}
|
|
34
|
+
*/
|
|
26
35
|
function isMathFunctionNode(node) {
|
|
27
36
|
if (node.type !== 'function') {
|
|
28
37
|
return false;
|
|
@@ -30,6 +39,11 @@ function isMathFunctionNode(node) {
|
|
|
30
39
|
return mathFunctions.has(node.value.toLowerCase());
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} value
|
|
44
|
+
* @param {Record<string, boolean>} options
|
|
45
|
+
* @return {string}
|
|
46
|
+
*/
|
|
33
47
|
function transform(value, options) {
|
|
34
48
|
const parsed = valueParser(value);
|
|
35
49
|
|
|
@@ -39,7 +53,7 @@ function transform(value, options) {
|
|
|
39
53
|
const { value: originalValue } = node;
|
|
40
54
|
|
|
41
55
|
node.value = minifyColor(valueParser.stringify(node), options);
|
|
42
|
-
node.type = 'word';
|
|
56
|
+
/** @type {string} */ (node.type) = 'word';
|
|
43
57
|
|
|
44
58
|
const next = parent.nodes[index + 1];
|
|
45
59
|
|
|
@@ -48,10 +62,14 @@ function transform(value, options) {
|
|
|
48
62
|
next &&
|
|
49
63
|
(next.type === 'word' || next.type === 'function')
|
|
50
64
|
) {
|
|
51
|
-
parent.nodes.splice(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
parent.nodes.splice(
|
|
66
|
+
index + 1,
|
|
67
|
+
0,
|
|
68
|
+
/** @type {valueParser.SpaceNode} */ ({
|
|
69
|
+
type: 'space',
|
|
70
|
+
value: ' ',
|
|
71
|
+
})
|
|
72
|
+
);
|
|
55
73
|
}
|
|
56
74
|
} else if (isMathFunctionNode(node)) {
|
|
57
75
|
return false;
|
|
@@ -64,6 +82,11 @@ function transform(value, options) {
|
|
|
64
82
|
return parsed.toString();
|
|
65
83
|
}
|
|
66
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @param {Record<string, boolean>} options
|
|
87
|
+
* @param {string[]} browsers
|
|
88
|
+
* @return {Record<string, boolean>}
|
|
89
|
+
*/
|
|
67
90
|
function addPluginDefaults(options, browsers) {
|
|
68
91
|
const defaults = {
|
|
69
92
|
// Does the browser support 4 & 8 character hex notation
|
|
@@ -75,12 +98,17 @@ function addPluginDefaults(options, browsers) {
|
|
|
75
98
|
};
|
|
76
99
|
return { ...defaults, ...options };
|
|
77
100
|
}
|
|
78
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @type {import('postcss').PluginCreator<Record<string, boolean>>}
|
|
103
|
+
* @param {Record<string, boolean>} config
|
|
104
|
+
* @return {import('postcss').Plugin}
|
|
105
|
+
*/
|
|
79
106
|
function pluginCreator(config = {}) {
|
|
80
107
|
return {
|
|
81
108
|
postcssPlugin: 'postcss-colormin',
|
|
82
109
|
|
|
83
110
|
prepare(result) {
|
|
111
|
+
/** @type {typeof result.opts & browserslist.Options} */
|
|
84
112
|
const resultOptions = result.opts || {};
|
|
85
113
|
const browsers = browserslist(null, {
|
|
86
114
|
stats: resultOptions.stats,
|
|
@@ -95,7 +123,7 @@ function pluginCreator(config = {}) {
|
|
|
95
123
|
OnceExit(css) {
|
|
96
124
|
css.walkDecls((decl) => {
|
|
97
125
|
if (
|
|
98
|
-
/^(composes|font|filter|-webkit-tap-highlight-color)/i.test(
|
|
126
|
+
/^(composes|font|src$|filter|-webkit-tap-highlight-color)/i.test(
|
|
99
127
|
decl.prop
|
|
100
128
|
)
|
|
101
129
|
) {
|
package/src/minifyColor.js
CHANGED
|
@@ -3,13 +3,14 @@ const { colord, extend } = require('colord');
|
|
|
3
3
|
const namesPlugin = require('colord/plugins/names');
|
|
4
4
|
const minifierPlugin = require('colord/plugins/minify');
|
|
5
5
|
|
|
6
|
-
extend([namesPlugin, minifierPlugin]);
|
|
6
|
+
extend(/** @type {any[]} */ ([namesPlugin, minifierPlugin]));
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Performs color value minification
|
|
10
10
|
*
|
|
11
11
|
* @param {string} input - CSS value
|
|
12
|
-
* @param {boolean} options
|
|
12
|
+
* @param {Record<string, boolean>} options object with colord.minify() options
|
|
13
|
+
* @return {string}
|
|
13
14
|
*/
|
|
14
15
|
module.exports = function minifyColor(input, options = {}) {
|
|
15
16
|
const instance = colord(input);
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export = pluginCreator;
|
|
2
|
+
/**
|
|
3
|
+
* @type {import('postcss').PluginCreator<Record<string, boolean>>}
|
|
4
|
+
* @param {Record<string, boolean>} config
|
|
5
|
+
* @return {import('postcss').Plugin}
|
|
6
|
+
*/
|
|
7
|
+
declare function pluginCreator(config?: Record<string, boolean>): import('postcss').Plugin;
|
|
8
|
+
declare namespace pluginCreator {
|
|
9
|
+
const postcss: true;
|
|
10
|
+
}
|