postcss-colormin 5.0.0 → 5.2.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/dist/index.js +18 -10
- package/dist/minifyColor.js +48 -0
- package/package.json +10 -9
- package/CHANGELOG.md +0 -70
- package/dist/colours.js +0 -74
- package/dist/keywords.json +0 -33
- package/dist/lib/toShorthand.js +0 -17
package/dist/index.js
CHANGED
|
@@ -7,13 +7,15 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _browserslist = _interopRequireDefault(require("browserslist"));
|
|
9
9
|
|
|
10
|
+
var _caniuseApi = require("caniuse-api");
|
|
11
|
+
|
|
10
12
|
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _minifyColor = _interopRequireDefault(require("./minifyColor"));
|
|
13
15
|
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
16
|
+
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
17
|
|
|
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; }
|
|
18
|
+
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
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
@@ -46,7 +48,7 @@ function isMathFunctionNode(node) {
|
|
|
46
48
|
return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
function transform(value,
|
|
51
|
+
function transform(value, options) {
|
|
50
52
|
const parsed = (0, _postcssValueParser.default)(value);
|
|
51
53
|
walk(parsed, (node, index, parent) => {
|
|
52
54
|
if (node.type === 'function') {
|
|
@@ -54,7 +56,7 @@ function transform(value, isLegacy, colorminCache) {
|
|
|
54
56
|
const {
|
|
55
57
|
value: originalValue
|
|
56
58
|
} = node;
|
|
57
|
-
node.value = (0,
|
|
59
|
+
node.value = (0, _minifyColor.default)((0, _postcssValueParser.stringify)(node), options);
|
|
58
60
|
node.type = 'word';
|
|
59
61
|
const next = parent.nodes[index + 1];
|
|
60
62
|
|
|
@@ -68,7 +70,7 @@ function transform(value, isLegacy, colorminCache) {
|
|
|
68
70
|
return false;
|
|
69
71
|
}
|
|
70
72
|
} else if (node.type === 'word') {
|
|
71
|
-
node.value = (0,
|
|
73
|
+
node.value = (0, _minifyColor.default)(node.value, options);
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
return parsed.toString();
|
|
@@ -85,8 +87,10 @@ function pluginCreator() {
|
|
|
85
87
|
path: __dirname,
|
|
86
88
|
env: resultOpts.env
|
|
87
89
|
});
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
+
const options = {
|
|
91
|
+
supportsTransparent: browsers.some(hasTransparentBug) === false,
|
|
92
|
+
supportsAlphaHex: (0, _caniuseApi.isSupported)('css-rrggbbaa', browsers)
|
|
93
|
+
};
|
|
90
94
|
const cache = {};
|
|
91
95
|
return {
|
|
92
96
|
OnceExit(css) {
|
|
@@ -101,14 +105,18 @@ function pluginCreator() {
|
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
const cacheKey =
|
|
108
|
+
const cacheKey = JSON.stringify({
|
|
109
|
+
value,
|
|
110
|
+
options,
|
|
111
|
+
browsers
|
|
112
|
+
});
|
|
105
113
|
|
|
106
114
|
if (cache[cacheKey]) {
|
|
107
115
|
decl.value = cache[cacheKey];
|
|
108
116
|
return;
|
|
109
117
|
}
|
|
110
118
|
|
|
111
|
-
const newValue = transform(value,
|
|
119
|
+
const newValue = transform(value, options);
|
|
112
120
|
decl.value = newValue;
|
|
113
121
|
cache[cacheKey] = newValue;
|
|
114
122
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = minifyColor;
|
|
7
|
+
|
|
8
|
+
var _colord = require("colord");
|
|
9
|
+
|
|
10
|
+
var _names = _interopRequireDefault(require("colord/plugins/names"));
|
|
11
|
+
|
|
12
|
+
var _minify = _interopRequireDefault(require("colord/plugins/minify"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
(0, _colord.extend)([_names.default, _minify.default]);
|
|
17
|
+
/**
|
|
18
|
+
* Performs color value minification
|
|
19
|
+
*
|
|
20
|
+
* @param {string} input - CSS value
|
|
21
|
+
* @param {boolean} options.supportsAlphaHex - Does the browser support 4 & 8 character hex notation
|
|
22
|
+
* @param {boolean} options.supportsTransparent – Does the browser support "transparent" value properly
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function minifyColor(input, options = {}) {
|
|
26
|
+
const settings = {
|
|
27
|
+
supportsAlphaHex: false,
|
|
28
|
+
supportsTransparent: true,
|
|
29
|
+
...options
|
|
30
|
+
};
|
|
31
|
+
const instance = (0, _colord.colord)(input);
|
|
32
|
+
|
|
33
|
+
if (instance.isValid()) {
|
|
34
|
+
// Try to shorten the string if it is a valid CSS color value
|
|
35
|
+
const minified = instance.minify({
|
|
36
|
+
alphaHex: settings.supportsAlphaHex,
|
|
37
|
+
transparent: settings.supportsTransparent,
|
|
38
|
+
name: true
|
|
39
|
+
}); // Fall back to the original input if it's smaller or has equal length
|
|
40
|
+
|
|
41
|
+
return minified.length < input.length ? minified : input.toLowerCase();
|
|
42
|
+
} else {
|
|
43
|
+
// Possibly malformed, so pass through
|
|
44
|
+
return input;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = exports.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-colormin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Minify colors in your CSS files with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"prebuild": "
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.
|
|
13
|
-
"
|
|
11
|
+
"prebuild": "rimraf dist",
|
|
12
|
+
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
+
"prepare": "yarn build"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"color",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"repository": "cssnano/cssnano",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"browserslist": "^4.16.
|
|
34
|
-
"
|
|
33
|
+
"browserslist": "^4.16.6",
|
|
34
|
+
"caniuse-api": "^3.0.0",
|
|
35
|
+
"colord": "^2.9.1",
|
|
35
36
|
"postcss-value-parser": "^4.1.0"
|
|
36
37
|
},
|
|
37
38
|
"bugs": {
|
|
@@ -41,10 +42,10 @@
|
|
|
41
42
|
"node": "^10 || ^12 || >=14.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"postcss": "^8.2.
|
|
45
|
+
"postcss": "^8.2.15"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"postcss": "^8.2.
|
|
48
|
+
"postcss": "^8.2.15"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "2d84646671c7075f8dae35de310351aac3436bc0"
|
|
50
51
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0-rc.2...postcss-colormin@5.0.0) (2021-04-06)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-colormin
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [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)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-colormin
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [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)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package postcss-colormin
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### Bug Fixes
|
|
34
|
-
|
|
35
|
-
* **postcss-colormin:** fixed plugin running error ([#856](https://github.com/cssnano/cssnano/issues/856)) ([eb37dd5](https://github.com/cssnano/cssnano/commit/eb37dd570a916ce7d6080a782a24d951082c5497))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### chore
|
|
39
|
-
|
|
40
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Features
|
|
44
|
-
|
|
45
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### BREAKING CHANGES
|
|
49
|
-
|
|
50
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
51
|
-
* minimum require version of node is 10.13
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## 4.1.9 (2019-02-12)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Performance Improvements
|
|
59
|
-
|
|
60
|
-
* **postcss-colormin:** increase ([#682](https://github.com/cssnano/cssnano/issues/682)) ([73e021e](https://github.com/cssnano/cssnano/commit/73e021e0fd02ab44c8726ae0719c5669a29bc8dc))
|
|
61
|
-
* **postcss-colormin:** increase perf ([#696](https://github.com/cssnano/cssnano/issues/696)) ([88c2f2e](https://github.com/cssnano/cssnano/commit/88c2f2e0c20fcd3f3be20b10501e0cec9e453aeb))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## 4.1.1 (2018-09-24)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### Bug Fixes
|
|
69
|
-
|
|
70
|
-
* **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
|
package/dist/colours.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _color = _interopRequireDefault(require("color"));
|
|
9
|
-
|
|
10
|
-
var _keywords = _interopRequireDefault(require("./keywords.json"));
|
|
11
|
-
|
|
12
|
-
var _toShorthand = _interopRequireDefault(require("./lib/toShorthand"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase();
|
|
17
|
-
|
|
18
|
-
var _default = (colour, isLegacy = false, cache = false) => {
|
|
19
|
-
const key = colour + '|' + isLegacy;
|
|
20
|
-
|
|
21
|
-
if (cache && cache[key]) {
|
|
22
|
-
return cache[key];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const parsed = (0, _color.default)(colour.toLowerCase());
|
|
27
|
-
const alpha = parsed.alpha();
|
|
28
|
-
|
|
29
|
-
if (alpha === 1) {
|
|
30
|
-
const toHex = (0, _toShorthand.default)(parsed.hex().toLowerCase());
|
|
31
|
-
const result = shorter(_keywords.default[toHex], toHex);
|
|
32
|
-
|
|
33
|
-
if (cache) {
|
|
34
|
-
cache[key] = result;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return result;
|
|
38
|
-
} else {
|
|
39
|
-
const rgb = parsed.rgb();
|
|
40
|
-
|
|
41
|
-
if (!isLegacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) {
|
|
42
|
-
const result = 'transparent';
|
|
43
|
-
|
|
44
|
-
if (cache) {
|
|
45
|
-
cache[key] = result;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let hsla = parsed.hsl().string();
|
|
52
|
-
let rgba = rgb.string();
|
|
53
|
-
let result = hsla.length < rgba.length ? hsla : rgba;
|
|
54
|
-
|
|
55
|
-
if (cache) {
|
|
56
|
-
cache[key] = result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
} catch (e) {
|
|
62
|
-
// Possibly malformed, so pass through
|
|
63
|
-
const result = colour;
|
|
64
|
-
|
|
65
|
-
if (cache) {
|
|
66
|
-
cache[key] = result;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
exports.default = _default;
|
|
74
|
-
module.exports = exports.default;
|
package/dist/keywords.json
DELETED
|
@@ -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
|
-
}
|
package/dist/lib/toShorthand.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _default = hex => {
|
|
9
|
-
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
|
|
10
|
-
return '#' + hex[2] + hex[4] + hex[6];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return hex;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
exports.default = _default;
|
|
17
|
-
module.exports = exports.default;
|