postcss-colormin 5.1.1 → 5.2.3
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 +34 -15
- package/dist/minifyColor.js +38 -0
- package/package.json +11 -11
- package/CHANGELOG.md +0 -89
- package/dist/colours.js +0 -60
- package/dist/lib/toShorthand.js +0 -17
package/dist/index.js
CHANGED
|
@@ -7,9 +7,11 @@ 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
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
|
|
|
@@ -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) {
|
|
|
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,25 +70,38 @@ function transform(value, isLegacy) {
|
|
|
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();
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
function
|
|
79
|
+
function addPluginDefaults(options, browsers) {
|
|
80
|
+
const defaults = {
|
|
81
|
+
transparent: browsers.some(hasTransparentBug) === false,
|
|
82
|
+
// Does the browser support 4 & 8 character hex notation
|
|
83
|
+
alphaHex: (0, _caniuseApi.isSupported)('css-rrggbbaa', browsers),
|
|
84
|
+
// Does the browser support "transparent" value properly
|
|
85
|
+
name: true
|
|
86
|
+
};
|
|
87
|
+
return { ...defaults,
|
|
88
|
+
...options
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pluginCreator(config = {}) {
|
|
78
93
|
return {
|
|
79
94
|
postcssPlugin: 'postcss-colormin',
|
|
80
95
|
|
|
81
96
|
prepare(result) {
|
|
82
|
-
const
|
|
97
|
+
const resultOptions = result.opts || {};
|
|
83
98
|
const browsers = (0, _browserslist.default)(null, {
|
|
84
|
-
stats:
|
|
99
|
+
stats: resultOptions.stats,
|
|
85
100
|
path: __dirname,
|
|
86
|
-
env:
|
|
101
|
+
env: resultOptions.env
|
|
87
102
|
});
|
|
88
|
-
const
|
|
89
|
-
const
|
|
103
|
+
const cache = new Map();
|
|
104
|
+
const options = addPluginDefaults(config, browsers);
|
|
90
105
|
return {
|
|
91
106
|
OnceExit(css) {
|
|
92
107
|
css.walkDecls(decl => {
|
|
@@ -100,16 +115,20 @@ function pluginCreator() {
|
|
|
100
115
|
return;
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
const cacheKey =
|
|
118
|
+
const cacheKey = JSON.stringify({
|
|
119
|
+
value,
|
|
120
|
+
options,
|
|
121
|
+
browsers
|
|
122
|
+
});
|
|
104
123
|
|
|
105
|
-
if (cache
|
|
106
|
-
decl.value = cache
|
|
124
|
+
if (cache.has(cacheKey)) {
|
|
125
|
+
decl.value = cache.get(cacheKey);
|
|
107
126
|
return;
|
|
108
127
|
}
|
|
109
128
|
|
|
110
|
-
const newValue = transform(value,
|
|
129
|
+
const newValue = transform(value, options);
|
|
111
130
|
decl.value = newValue;
|
|
112
|
-
cache
|
|
131
|
+
cache.set(cacheKey, newValue);
|
|
113
132
|
});
|
|
114
133
|
}
|
|
115
134
|
|
|
@@ -0,0 +1,38 @@
|
|
|
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 - object with colord.minify() options
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function minifyColor(input, options = {}) {
|
|
25
|
+
const instance = (0, _colord.colord)(input);
|
|
26
|
+
|
|
27
|
+
if (instance.isValid()) {
|
|
28
|
+
// Try to shorten the string if it is a valid CSS color value
|
|
29
|
+
const minified = instance.minify(options); // Fall back to the original input if it's smaller or has equal length
|
|
30
|
+
|
|
31
|
+
return minified.length < input.length ? minified : input.toLowerCase();
|
|
32
|
+
} else {
|
|
33
|
+
// Possibly malformed, so pass through
|
|
34
|
+
return input;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = exports.default;
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-colormin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.3",
|
|
4
4
|
"description": "Minify colors in your CSS files with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"color",
|
|
17
12
|
"colors",
|
|
@@ -30,9 +25,10 @@
|
|
|
30
25
|
},
|
|
31
26
|
"repository": "cssnano/cssnano",
|
|
32
27
|
"dependencies": {
|
|
33
|
-
"browserslist": "^4.16.
|
|
34
|
-
"
|
|
35
|
-
"
|
|
28
|
+
"browserslist": "^4.16.6",
|
|
29
|
+
"caniuse-api": "^3.0.0",
|
|
30
|
+
"colord": "^2.9.1",
|
|
31
|
+
"postcss-value-parser": "^4.2.0"
|
|
36
32
|
},
|
|
37
33
|
"bugs": {
|
|
38
34
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -46,5 +42,9 @@
|
|
|
46
42
|
"peerDependencies": {
|
|
47
43
|
"postcss": "^8.2.15"
|
|
48
44
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
45
|
+
"scripts": {
|
|
46
|
+
"prebuild": "rimraf dist",
|
|
47
|
+
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
48
|
+
},
|
|
49
|
+
"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"
|
|
50
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,89 +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.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
|
-
|
|
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)
|
|
42
|
-
|
|
43
|
-
**Note:** Version bump only for package postcss-colormin
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### Bug Fixes
|
|
53
|
-
|
|
54
|
-
* **postcss-colormin:** fixed plugin running error ([#856](https://github.com/cssnano/cssnano/issues/856)) ([eb37dd5](https://github.com/cssnano/cssnano/commit/eb37dd570a916ce7d6080a782a24d951082c5497))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### chore
|
|
58
|
-
|
|
59
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
### Features
|
|
63
|
-
|
|
64
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
### BREAKING CHANGES
|
|
68
|
-
|
|
69
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
70
|
-
* minimum require version of node is 10.13
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## 4.1.9 (2019-02-12)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
### Performance Improvements
|
|
78
|
-
|
|
79
|
-
* **postcss-colormin:** increase ([#682](https://github.com/cssnano/cssnano/issues/682)) ([73e021e](https://github.com/cssnano/cssnano/commit/73e021e0fd02ab44c8726ae0719c5669a29bc8dc))
|
|
80
|
-
* **postcss-colormin:** increase perf ([#696](https://github.com/cssnano/cssnano/issues/696)) ([88c2f2e](https://github.com/cssnano/cssnano/commit/88c2f2e0c20fcd3f3be20b10501e0cec9e453aeb))
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## 4.1.1 (2018-09-24)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
### Bug Fixes
|
|
88
|
-
|
|
89
|
-
* **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,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _colord = require("colord");
|
|
9
|
-
|
|
10
|
-
var _names = _interopRequireDefault(require("colord/plugins/names"));
|
|
11
|
-
|
|
12
|
-
var _toShorthand = _interopRequireDefault(require("./lib/toShorthand"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
(0, _colord.extend)([_names.default]);
|
|
17
|
-
|
|
18
|
-
var _default = (colour, isLegacy = false) => {
|
|
19
|
-
const parsed = (0, _colord.colord)(colour);
|
|
20
|
-
|
|
21
|
-
if (parsed.isValid()) {
|
|
22
|
-
const alpha = parsed.alpha();
|
|
23
|
-
|
|
24
|
-
if (alpha === 1) {
|
|
25
|
-
const toHex = (0, _toShorthand.default)(parsed.toHex());
|
|
26
|
-
const toName = parsed.toName();
|
|
27
|
-
|
|
28
|
-
if (toName && toName.length < toHex.length) {
|
|
29
|
-
return toName;
|
|
30
|
-
} else {
|
|
31
|
-
return toHex;
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
const rgb = parsed.toRgb();
|
|
35
|
-
|
|
36
|
-
if (!isLegacy && !rgb.r && !rgb.g && !rgb.b && !alpha) {
|
|
37
|
-
return 'transparent';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let hsla = parsed.toHslString();
|
|
41
|
-
let rgba = parsed.toRgbString();
|
|
42
|
-
const shortestConversion = hsla.length < rgba.length ? hsla : rgba;
|
|
43
|
-
let result;
|
|
44
|
-
|
|
45
|
-
if (colour.length < shortestConversion.length) {
|
|
46
|
-
result = colour;
|
|
47
|
-
} else {
|
|
48
|
-
result = shortestConversion;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
// Possibly malformed, so pass through
|
|
55
|
-
return colour;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
exports.default = _default;
|
|
60
|
-
module.exports = exports.default;
|
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;
|