postcss-colormin 4.0.0-rc.0 → 4.0.2
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/README.md +1 -1
- package/dist/colours.js +8 -12
- package/dist/index.js +13 -14
- package/dist/lib/toShorthand.js +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
package/dist/colours.js
CHANGED
|
@@ -18,26 +18,22 @@ var _toShorthand2 = _interopRequireDefault(_toShorthand);
|
|
|
18
18
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
return (a && a.length < b.length ? a : b).toLowerCase();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.default = function (colour) {
|
|
26
|
-
var legacy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
21
|
+
const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase();
|
|
27
22
|
|
|
23
|
+
exports.default = (colour, legacy = false) => {
|
|
28
24
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const parsed = (0, _color2.default)(colour.toLowerCase());
|
|
26
|
+
const alpha = parsed.alpha();
|
|
31
27
|
if (alpha === 1) {
|
|
32
|
-
|
|
28
|
+
const toHex = (0, _toShorthand2.default)(parsed.hex().toLowerCase());
|
|
33
29
|
return shorter(_keywords2.default[toHex], toHex);
|
|
34
30
|
} else {
|
|
35
|
-
|
|
31
|
+
const rgb = parsed.rgb();
|
|
36
32
|
if (!legacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) {
|
|
37
33
|
return 'transparent';
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
let hsla = parsed.hsl().string();
|
|
36
|
+
let rgba = rgb.string();
|
|
41
37
|
return hsla.length < rgba.length ? hsla : rgba;
|
|
42
38
|
}
|
|
43
39
|
} catch (e) {
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var _colours2 = _interopRequireDefault(_colours);
|
|
|
23
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
24
|
|
|
25
25
|
function walk(parent, callback) {
|
|
26
|
-
parent.nodes.forEach(
|
|
27
|
-
|
|
26
|
+
parent.nodes.forEach((node, index) => {
|
|
27
|
+
const bubble = callback(node, index, parent);
|
|
28
28
|
if (node.nodes && bubble !== false) {
|
|
29
29
|
walk(node, callback);
|
|
30
30
|
}
|
|
@@ -35,19 +35,18 @@ function transform(legacy, decl) {
|
|
|
35
35
|
if (/^(composes|font|filter|-webkit-tap-highlight-color)/i.test(decl.prop)) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
walk(ast,
|
|
38
|
+
const ast = (0, _postcssValueParser2.default)(decl.value);
|
|
39
|
+
walk(ast, (node, index, parent) => {
|
|
40
40
|
if (node.type === 'function') {
|
|
41
|
-
if (/^(rgb|hsl)a
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (/^(rgb|hsl)a?$/i.test(node.value)) {
|
|
42
|
+
const { value } = node;
|
|
44
43
|
node.value = (0, _colours2.default)((0, _postcssValueParser.stringify)(node), legacy);
|
|
45
44
|
node.type = 'word';
|
|
46
|
-
|
|
47
|
-
if (node.value !== value && next && next.type === 'word') {
|
|
45
|
+
const next = parent.nodes[index + 1];
|
|
46
|
+
if (node.value !== value && next && (next.type === 'word' || next.type === 'function')) {
|
|
48
47
|
parent.nodes.splice(index + 1, 0, { type: 'space', value: ' ' });
|
|
49
48
|
}
|
|
50
|
-
} else if (node.value === 'calc') {
|
|
49
|
+
} else if (node.value.toLowerCase() === 'calc') {
|
|
51
50
|
return false;
|
|
52
51
|
}
|
|
53
52
|
} else if (node.type === 'word') {
|
|
@@ -68,10 +67,10 @@ function hasTransparentBug(browser) {
|
|
|
68
67
|
return ~['ie 8', 'ie 9'].indexOf(browser);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
exports.default = _postcss2.default.plugin('postcss-colormin',
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
exports.default = _postcss2.default.plugin('postcss-colormin', () => {
|
|
71
|
+
return (css, result) => {
|
|
72
|
+
const resultOpts = result.opts || {};
|
|
73
|
+
const browsers = (0, _browserslist2.default)(null, {
|
|
75
74
|
stats: resultOpts.stats,
|
|
76
75
|
path: __dirname,
|
|
77
76
|
env: resultOpts.env
|
package/dist/lib/toShorthand.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-colormin",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Minify colors in your CSS files with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,28 +22,28 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"babel-cli": "^6.0.0",
|
|
25
|
-
"cross-env": "^
|
|
25
|
+
"cross-env": "^5.0.0",
|
|
26
26
|
"css-color-names": "0.0.4",
|
|
27
27
|
"write-file": "^1.0.0"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/
|
|
29
|
+
"homepage": "https://github.com/cssnano/cssnano",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Ben Briggs",
|
|
32
32
|
"email": "beneb.info@gmail.com",
|
|
33
33
|
"url": "http://beneb.info"
|
|
34
34
|
},
|
|
35
|
-
"repository": "
|
|
35
|
+
"repository": "cssnano/cssnano",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"browserslist": "^
|
|
38
|
-
"color": "^
|
|
37
|
+
"browserslist": "^4.0.0",
|
|
38
|
+
"color": "^3.0.0",
|
|
39
39
|
"has": "^1.0.0",
|
|
40
|
-
"postcss": "^
|
|
40
|
+
"postcss": "^7.0.0",
|
|
41
41
|
"postcss-value-parser": "^3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"bugs": {
|
|
44
|
-
"url": "https://github.com/
|
|
44
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=6.9.0"
|
|
48
48
|
}
|
|
49
49
|
}
|