postcss-colormin 6.0.2 → 6.1.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,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-colormin",
3
- "version": "6.0.2",
3
+ "version": "6.1.0",
4
4
  "description": "Minify colors in your CSS files with PostCSS.",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "repository": "cssnano/cssnano",
29
29
  "dependencies": {
30
- "browserslist": "^4.22.2",
30
+ "browserslist": "^4.23.0",
31
31
  "caniuse-api": "^3.0.0",
32
- "colord": "^2.9.1",
32
+ "colord": "^2.9.3",
33
33
  "postcss-value-parser": "^4.2.0"
34
34
  },
35
35
  "bugs": {
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/caniuse-api": "^3.0.6",
43
- "postcss": "^8.4.32"
43
+ "postcss": "^8.4.35"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "postcss": "^8.4.31"
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ const { dirname } = require('path');
2
3
  const browserslist = require('browserslist');
3
4
  const { isSupported } = require('caniuse-api');
4
5
  const valueParser = require('postcss-value-parser');
@@ -41,7 +42,7 @@ function isMathFunctionNode(node) {
41
42
 
42
43
  /**
43
44
  * @param {string} value
44
- * @param {Record<string, boolean>} options
45
+ * @param {Options} options
45
46
  * @return {string}
46
47
  */
47
48
  function transform(value, options) {
@@ -83,9 +84,9 @@ function transform(value, options) {
83
84
  }
84
85
 
85
86
  /**
86
- * @param {Record<string, boolean>} options
87
+ * @param {Options} options
87
88
  * @param {string[]} browsers
88
- * @return {Record<string, boolean>}
89
+ * @return {Options}
89
90
  */
90
91
  function addPluginDefaults(options, browsers) {
91
92
  const defaults = {
@@ -98,22 +99,41 @@ function addPluginDefaults(options, browsers) {
98
99
  };
99
100
  return { ...defaults, ...options };
100
101
  }
102
+
103
+ /**
104
+ * @typedef {object} MinifyColorOptions
105
+ * @property {boolean} [hex]
106
+ * @property {boolean} [alphaHex]
107
+ * @property {boolean} [rgb]
108
+ * @property {boolean} [hsl]
109
+ * @property {boolean} [name]
110
+ * @property {boolean} [transparent]
111
+ */
112
+
113
+ /**
114
+ * @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
115
+ * @typedef {Pick<browserslist.Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
116
+ * @typedef {MinifyColorOptions & AutoprefixerOptions & BrowserslistOptions} Options
117
+ */
118
+
101
119
  /**
102
- * @type {import('postcss').PluginCreator<Record<string, boolean>>}
103
- * @param {Record<string, boolean>} config
120
+ * @type {import('postcss').PluginCreator<Options>}
121
+ * @param {Options} config
104
122
  * @return {import('postcss').Plugin}
105
123
  */
106
124
  function pluginCreator(config = {}) {
107
125
  return {
108
126
  postcssPlugin: 'postcss-colormin',
109
127
 
128
+ /**
129
+ * @param {import('postcss').Result & {opts: BrowserslistOptions & {file?: string}}} result
130
+ */
110
131
  prepare(result) {
111
- /** @type {typeof result.opts & browserslist.Options} */
112
- const resultOptions = result.opts || {};
113
- const browsers = browserslist(null, {
114
- stats: resultOptions.stats,
115
- path: __dirname,
116
- env: resultOptions.env,
132
+ const { stats, env, from, file } = result.opts || {};
133
+ const browsers = browserslist(config.overrideBrowserslist, {
134
+ stats: config.stats || stats,
135
+ path: config.path || dirname(from || file || __filename),
136
+ env: config.env || env,
117
137
  });
118
138
 
119
139
  const cache = new Map();
@@ -9,7 +9,7 @@ extend(/** @type {any[]} */ ([namesPlugin, minifierPlugin]));
9
9
  * Performs color value minification
10
10
  *
11
11
  * @param {string} input - CSS value
12
- * @param {Record<string, boolean>} options object with colord.minify() options
12
+ * @param {import('./index.js').MinifyColorOptions} options - object with colord.minify() options
13
13
  * @return {string}
14
14
  */
15
15
  module.exports = function minifyColor(input, options = {}) {
package/types/index.d.ts CHANGED
@@ -1,10 +1,40 @@
1
1
  export = pluginCreator;
2
2
  /**
3
- * @type {import('postcss').PluginCreator<Record<string, boolean>>}
4
- * @param {Record<string, boolean>} config
3
+ * @typedef {object} MinifyColorOptions
4
+ * @property {boolean} [hex]
5
+ * @property {boolean} [alphaHex]
6
+ * @property {boolean} [rgb]
7
+ * @property {boolean} [hsl]
8
+ * @property {boolean} [name]
9
+ * @property {boolean} [transparent]
10
+ */
11
+ /**
12
+ * @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
13
+ * @typedef {Pick<browserslist.Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
14
+ * @typedef {MinifyColorOptions & AutoprefixerOptions & BrowserslistOptions} Options
15
+ */
16
+ /**
17
+ * @type {import('postcss').PluginCreator<Options>}
18
+ * @param {Options} config
5
19
  * @return {import('postcss').Plugin}
6
20
  */
7
- declare function pluginCreator(config?: Record<string, boolean>): import('postcss').Plugin;
21
+ declare function pluginCreator(config?: Options): import('postcss').Plugin;
8
22
  declare namespace pluginCreator {
9
- let postcss: true;
23
+ export { postcss, MinifyColorOptions, AutoprefixerOptions, BrowserslistOptions, Options };
10
24
  }
25
+ type Options = MinifyColorOptions & AutoprefixerOptions & BrowserslistOptions;
26
+ declare var postcss: true;
27
+ type MinifyColorOptions = {
28
+ hex?: boolean | undefined;
29
+ alphaHex?: boolean | undefined;
30
+ rgb?: boolean | undefined;
31
+ hsl?: boolean | undefined;
32
+ name?: boolean | undefined;
33
+ transparent?: boolean | undefined;
34
+ };
35
+ type AutoprefixerOptions = {
36
+ overrideBrowserslist?: string | string[];
37
+ };
38
+ type BrowserslistOptions = Pick<browserslist.Options, 'stats' | 'path' | 'env'>;
39
+ import browserslist = require("browserslist");
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAsGA;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;GAIG;AACH,wCAHW,OAAO,GACN,OAAO,SAAS,EAAE,MAAM,CAsDnC;;;;eA5DY,kBAAkB,GAAG,mBAAmB,GAAG,mBAAmB;;;;;;;;;;2BAF9D;IAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE;2BAC5C,KAAK,oBAAoB,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC"}
@@ -1,2 +1,3 @@
1
- declare function _exports(input: string, options?: Record<string, boolean>): string;
1
+ declare function _exports(input: string, options?: import('./index.js').MinifyColorOptions): string;
2
2
  export = _exports;
3
+ //# sourceMappingURL=minifyColor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minifyColor.d.ts","sourceRoot":"","sources":["../src/minifyColor.js"],"names":[],"mappings":"AAciB,iCAJN,MAAM,YACN,OAAO,YAAY,EAAE,kBAAkB,GACtC,MAAM,CAejB"}