postcss-colormin 5.0.0-rc.1 → 5.1.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/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.1.1] (2021-05-21)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **postcss-colormin:** Strict color parsing ([#1122](https://github.com/cssnano/cssnano/issues/1122)) ([32771da](https://github.com/cssnano/cssnano/commit/32771da46ee94f07a6907ec47701189f90ad2ec0))
12
+ * **postcss-colormin:** fix ERR_PACKAGE_PATH_NOT_EXPORTED ([#1110](https://github.com/cssnano/cssnano/issues/1110)) ([8a31ca38796](https://github.com/cssnano/cssnano/commit/8a31ca38796e12e6fe52620cf8a545cb058fe295))
13
+
14
+ # [5.1.0](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0...postcss-colormin@5.1.0) (2021-05-19)
15
+
16
+
17
+ ### Features
18
+
19
+ * **postcss-colormin:** switch to colord and solve multiple issues ([#1107](https://github.com/cssnano/cssnano/issues/1107)) ([a7f0be4](https://github.com/cssnano/cssnano/commit/a7f0be4acc640aab89cace53a720b3d59b6f7b4f)), closes [#819](https://github.com/cssnano/cssnano/issues/819) [#1042](https://github.com/cssnano/cssnano/issues/1042) [#819](https://github.com/cssnano/cssnano/issues/819) [#771](https://github.com/cssnano/cssnano/issues/771)
20
+
21
+
22
+
23
+
24
+
25
+ # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0-rc.2...postcss-colormin@5.0.0) (2021-04-06)
26
+
27
+ **Note:** Version bump only for package postcss-colormin
28
+
29
+
30
+
31
+
32
+
33
+ # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0-rc.1...postcss-colormin@5.0.0-rc.2) (2021-03-15)
34
+
35
+ **Note:** Version bump only for package postcss-colormin
36
+
37
+
38
+
39
+
40
+
6
41
  # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0-rc.0...postcss-colormin@5.0.0-rc.1) (2021-03-04)
7
42
 
8
43
  **Note:** Version bump only for package postcss-colormin
package/dist/colours.js CHANGED
@@ -5,68 +5,54 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _color = _interopRequireDefault(require("color"));
8
+ var _colord = require("colord");
9
9
 
10
- var _keywords = _interopRequireDefault(require("./keywords.json"));
10
+ var _names = _interopRequireDefault(require("colord/plugins/names"));
11
11
 
12
12
  var _toShorthand = _interopRequireDefault(require("./lib/toShorthand"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase();
16
+ (0, _colord.extend)([_names.default]);
17
17
 
18
- var _default = (colour, isLegacy = false, cache = false) => {
19
- const key = colour + '|' + isLegacy;
18
+ var _default = (colour, isLegacy = false) => {
19
+ const parsed = (0, _colord.colord)(colour);
20
20
 
21
- if (cache && cache[key]) {
22
- return cache[key];
23
- }
24
-
25
- try {
26
- const parsed = (0, _color.default)(colour.toLowerCase());
21
+ if (parsed.isValid()) {
27
22
  const alpha = parsed.alpha();
28
23
 
29
24
  if (alpha === 1) {
30
- const toHex = (0, _toShorthand.default)(parsed.hex().toLowerCase());
31
- const result = shorter(_keywords.default[toHex], toHex);
25
+ const toHex = (0, _toShorthand.default)(parsed.toHex());
26
+ const toName = parsed.toName();
32
27
 
33
- if (cache) {
34
- cache[key] = result;
28
+ if (toName && toName.length < toHex.length) {
29
+ return toName;
30
+ } else {
31
+ return toHex;
35
32
  }
36
-
37
- return result;
38
33
  } else {
39
- const rgb = parsed.rgb();
40
-
41
- if (!isLegacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) {
42
- const result = 'transparent';
34
+ const rgb = parsed.toRgb();
43
35
 
44
- if (cache) {
45
- cache[key] = result;
46
- }
47
-
48
- return result;
36
+ if (!isLegacy && !rgb.r && !rgb.g && !rgb.b && !alpha) {
37
+ return 'transparent';
49
38
  }
50
39
 
51
- let hsla = parsed.hsl().string();
52
- let rgba = rgb.string();
53
- let result = hsla.length < rgba.length ? hsla : rgba;
40
+ let hsla = parsed.toHslString();
41
+ let rgba = parsed.toRgbString();
42
+ const shortestConversion = hsla.length < rgba.length ? hsla : rgba;
43
+ let result;
54
44
 
55
- if (cache) {
56
- cache[key] = result;
45
+ if (colour.length < shortestConversion.length) {
46
+ result = colour;
47
+ } else {
48
+ result = shortestConversion;
57
49
  }
58
50
 
59
51
  return result;
60
52
  }
61
- } catch (e) {
53
+ } else {
62
54
  // Possibly malformed, so pass through
63
- const result = colour;
64
-
65
- if (cache) {
66
- cache[key] = result;
67
- }
68
-
69
- return result;
55
+ return colour;
70
56
  }
71
57
  };
72
58
 
package/dist/index.js CHANGED
@@ -11,9 +11,9 @@ var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"
11
11
 
12
12
  var _colours = _interopRequireDefault(require("./colours"));
13
13
 
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
 
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
@@ -46,7 +46,7 @@ function isMathFunctionNode(node) {
46
46
  return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
47
47
  }
48
48
 
49
- function transform(value, isLegacy, colorminCache) {
49
+ function transform(value, isLegacy) {
50
50
  const parsed = (0, _postcssValueParser.default)(value);
51
51
  walk(parsed, (node, index, parent) => {
52
52
  if (node.type === 'function') {
@@ -54,7 +54,7 @@ function transform(value, isLegacy, colorminCache) {
54
54
  const {
55
55
  value: originalValue
56
56
  } = node;
57
- node.value = (0, _colours.default)((0, _postcssValueParser.stringify)(node), isLegacy, colorminCache);
57
+ node.value = (0, _colours.default)((0, _postcssValueParser.stringify)(node), isLegacy);
58
58
  node.type = 'word';
59
59
  const next = parent.nodes[index + 1];
60
60
 
@@ -68,7 +68,7 @@ function transform(value, isLegacy, colorminCache) {
68
68
  return false;
69
69
  }
70
70
  } else if (node.type === 'word') {
71
- node.value = (0, _colours.default)(node.value, isLegacy, colorminCache);
71
+ node.value = (0, _colours.default)(node.value, isLegacy);
72
72
  }
73
73
  });
74
74
  return parsed.toString();
@@ -86,7 +86,6 @@ function pluginCreator() {
86
86
  env: resultOpts.env
87
87
  });
88
88
  const isLegacy = browsers.some(hasTransparentBug);
89
- const colorminCache = {};
90
89
  const cache = {};
91
90
  return {
92
91
  OnceExit(css) {
@@ -101,14 +100,14 @@ function pluginCreator() {
101
100
  return;
102
101
  }
103
102
 
104
- const cacheKey = `${decl.prop}|${decl.value}`;
103
+ const cacheKey = value + '|' + isLegacy;
105
104
 
106
105
  if (cache[cacheKey]) {
107
106
  decl.value = cache[cacheKey];
108
107
  return;
109
108
  }
110
109
 
111
- const newValue = transform(value, isLegacy, colorminCache);
110
+ const newValue = transform(value, isLegacy);
112
111
  decl.value = newValue;
113
112
  cache[cacheKey] = newValue;
114
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-colormin",
3
- "version": "5.0.0-rc.1",
3
+ "version": "5.1.1",
4
4
  "description": "Minify colors in your CSS files with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "prebuild": "del-cli dist",
12
- "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\" && babel-node script/generate",
12
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
13
13
  "prepublish": "yarn build"
14
14
  },
15
15
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "repository": "cssnano/cssnano",
32
32
  "dependencies": {
33
33
  "browserslist": "^4.16.0",
34
- "color": "^3.1.1",
34
+ "colord": "^2.0.0",
35
35
  "postcss-value-parser": "^4.1.0"
36
36
  },
37
37
  "bugs": {
@@ -41,10 +41,10 @@
41
41
  "node": "^10 || ^12 || >=14.0"
42
42
  },
43
43
  "devDependencies": {
44
- "postcss": "^8.2.1"
44
+ "postcss": "^8.2.15"
45
45
  },
46
46
  "peerDependencies": {
47
- "postcss": "^8.2.1"
47
+ "postcss": "^8.2.15"
48
48
  },
49
- "gitHead": "114efb0092fff944dd4c8a28d184add24d8fde3e"
49
+ "gitHead": "08ec284f116d1ce2605deb55dfe17ffe2835b38a"
50
50
  }
@@ -1,33 +0,0 @@
1
- {
2
- "#f0ffff": "azure",
3
- "#f5f5dc": "beige",
4
- "#ffe4c4": "bisque",
5
- "#a52a2a": "brown",
6
- "#ff7f50": "coral",
7
- "#ffd700": "gold",
8
- "#808080": "grey",
9
- "#008000": "green",
10
- "#4b0082": "indigo",
11
- "#fffff0": "ivory",
12
- "#f0e68c": "khaki",
13
- "#faf0e6": "linen",
14
- "#800000": "maroon",
15
- "#000080": "navy",
16
- "#808000": "olive",
17
- "#ffa500": "orange",
18
- "#da70d6": "orchid",
19
- "#cd853f": "peru",
20
- "#ffc0cb": "pink",
21
- "#dda0dd": "plum",
22
- "#800080": "purple",
23
- "#f00": "red",
24
- "#fa8072": "salmon",
25
- "#a0522d": "sienna",
26
- "#c0c0c0": "silver",
27
- "#fffafa": "snow",
28
- "#d2b48c": "tan",
29
- "#008080": "teal",
30
- "#ff6347": "tomato",
31
- "#ee82ee": "violet",
32
- "#f5deb3": "wheat"
33
- }