postcss-colormin 5.2.5 → 5.3.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/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "postcss-colormin",
3
- "version": "5.2.5",
3
+ "version": "5.3.0",
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",
@@ -37,6 +39,7 @@
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": {
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.nodes && bubble !== false) {
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(index + 1, 0, {
52
- type: 'space',
53
- value: ' ',
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,
@@ -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 - object with colord.minify() 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);
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ declare function _exports(input: string, options?: Record<string, boolean>): string;
2
+ export = _exports;