postcss-minify-gradients 4.0.0-nightly.2020.9.3 → 4.0.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/CHANGELOG.md +34 -0
- package/dist/index.js +114 -152
- package/package.json +12 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 4.0.0-rc.0
|
|
2
|
+
|
|
3
|
+
* Breaking: Drops support for Node 0.12, we now require at least Node 4.
|
|
4
|
+
* Breaking: Update PostCSS to 6.0.0.
|
|
5
|
+
* Better handling of color stop positions in radial gradients, the module now
|
|
6
|
+
correctly accounts for the first set of parameters potentially being
|
|
7
|
+
directional and not stop values.
|
|
8
|
+
|
|
9
|
+
# 1.0.5
|
|
10
|
+
|
|
11
|
+
* Resolves a crash on empty `linear-gradient()` functions.
|
|
12
|
+
|
|
13
|
+
# 1.0.4
|
|
14
|
+
|
|
15
|
+
* Resolves an issue where `0` was being removed from intermediate colour stops
|
|
16
|
+
if preceding colour stops contained `calc()` (thanks to @jaybekster).
|
|
17
|
+
|
|
18
|
+
# 1.0.3
|
|
19
|
+
|
|
20
|
+
* Resolves an issue where `0` was being incorrectly stripped from the final
|
|
21
|
+
colour stop value.
|
|
22
|
+
|
|
23
|
+
# 1.0.2
|
|
24
|
+
|
|
25
|
+
* Resolves an issue where the module would incorrectly parse floating
|
|
26
|
+
point numbers.
|
|
27
|
+
|
|
28
|
+
# 1.0.1
|
|
29
|
+
|
|
30
|
+
* Reduce function iterations (thanks to @TrySound).
|
|
31
|
+
|
|
32
|
+
# 1.0.0
|
|
33
|
+
|
|
34
|
+
* Initial release.
|
package/dist/index.js
CHANGED
|
@@ -1,179 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
7
6
|
|
|
8
|
-
var _postcss =
|
|
7
|
+
var _postcss = require('postcss');
|
|
9
8
|
|
|
10
|
-
var
|
|
9
|
+
var _postcss2 = _interopRequireDefault(_postcss);
|
|
11
10
|
|
|
12
|
-
var
|
|
11
|
+
var _postcssValueParser = require('postcss-value-parser');
|
|
13
12
|
|
|
14
|
-
var
|
|
13
|
+
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
|
|
18
|
+
|
|
19
|
+
var _isColorStop = require('is-color-stop');
|
|
20
|
+
|
|
21
|
+
var _isColorStop2 = _interopRequireDefault(_isColorStop);
|
|
19
22
|
|
|
20
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
24
|
|
|
22
25
|
const angles = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
top: '0deg',
|
|
27
|
+
right: '90deg',
|
|
28
|
+
bottom: '180deg',
|
|
29
|
+
left: '270deg'
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
function isLessThan(a, b) {
|
|
30
|
-
|
|
33
|
+
return a.unit === b.unit && parseFloat(a.number) >= parseFloat(b.number);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
function optimise(decl) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!value) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const normalizedValue = value.toLowerCase();
|
|
41
|
-
|
|
42
|
-
if (normalizedValue.includes('var(') || normalizedValue.includes('env(')) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!normalizedValue.includes('gradient')) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
decl.value = (0, _postcssValueParser.default)(value).walk(node => {
|
|
51
|
-
if (node.type !== 'function' || !node.nodes.length) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const lowerCasedValue = node.value.toLowerCase();
|
|
56
|
-
|
|
57
|
-
if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
|
|
58
|
-
let args = (0, _cssnanoUtils.getArguments)(node);
|
|
59
|
-
|
|
60
|
-
if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
|
|
61
|
-
node.nodes = node.nodes.slice(2);
|
|
62
|
-
node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let lastStop = null;
|
|
66
|
-
args.forEach((arg, index) => {
|
|
67
|
-
if (!arg[2]) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let isFinalStop = index === args.length - 1;
|
|
72
|
-
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
73
|
-
|
|
74
|
-
if (lastStop === null) {
|
|
75
|
-
lastStop = thisStop;
|
|
76
|
-
|
|
77
|
-
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
|
|
78
|
-
arg[1].value = arg[2].value = '';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
85
|
-
arg[2].value = 0;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
lastStop = thisStop;
|
|
89
|
-
|
|
90
|
-
if (isFinalStop && arg[2].value === '100%') {
|
|
91
|
-
arg[1].value = arg[2].value = '';
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return false;
|
|
37
|
+
if (!~decl.value.toLowerCase().indexOf('gradient')) {
|
|
38
|
+
return;
|
|
95
39
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let lastStop;
|
|
100
|
-
const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
|
|
101
|
-
args.forEach((arg, index) => {
|
|
102
|
-
if (!arg[2] || !index && hasAt) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
107
|
-
|
|
108
|
-
if (!lastStop) {
|
|
109
|
-
lastStop = thisStop;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
114
|
-
arg[2].value = 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
lastStop = thisStop;
|
|
118
|
-
});
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
|
|
123
|
-
let args = (0, _cssnanoUtils.getArguments)(node);
|
|
124
|
-
let lastStop;
|
|
125
|
-
args.forEach(arg => {
|
|
126
|
-
let color;
|
|
127
|
-
let stop;
|
|
128
|
-
|
|
129
|
-
if (arg[2] !== undefined) {
|
|
130
|
-
if (arg[0].type === 'function') {
|
|
131
|
-
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
132
|
-
} else {
|
|
133
|
-
color = arg[0].value;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (arg[2].type === 'function') {
|
|
137
|
-
stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
|
|
138
|
-
} else {
|
|
139
|
-
stop = arg[2].value;
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
if (arg[0].type === 'function') {
|
|
143
|
-
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
color = arg[0].value;
|
|
40
|
+
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
|
|
41
|
+
if (node.type !== 'function' || !node.nodes.length) {
|
|
42
|
+
return false;
|
|
147
43
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
44
|
+
const lowerCasedValue = node.value.toLowerCase();
|
|
45
|
+
if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
|
|
46
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
47
|
+
if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
|
|
48
|
+
node.nodes = node.nodes.slice(2);
|
|
49
|
+
node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
|
|
50
|
+
}
|
|
51
|
+
let lastStop = null;
|
|
52
|
+
args.forEach((arg, index) => {
|
|
53
|
+
if (!arg[2]) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let isFinalStop = index === args.length - 1;
|
|
57
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
58
|
+
if (lastStop === null) {
|
|
59
|
+
lastStop = thisStop;
|
|
60
|
+
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
|
|
61
|
+
arg[1].value = arg[2].value = '';
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (isLessThan(lastStop, thisStop)) {
|
|
66
|
+
arg[2].value = 0;
|
|
67
|
+
}
|
|
68
|
+
lastStop = thisStop;
|
|
69
|
+
if (isFinalStop && arg[2].value === '100%') {
|
|
70
|
+
arg[1].value = arg[2].value = '';
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return false;
|
|
154
74
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
75
|
+
if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
|
|
76
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
77
|
+
let lastStop;
|
|
78
|
+
const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
|
|
79
|
+
args.forEach((arg, index) => {
|
|
80
|
+
if (!arg[2] || !index && hasAt) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
84
|
+
if (!lastStop) {
|
|
85
|
+
lastStop = thisStop;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (isLessThan(lastStop, thisStop)) {
|
|
89
|
+
arg[2].value = 0;
|
|
90
|
+
}
|
|
91
|
+
lastStop = thisStop;
|
|
92
|
+
});
|
|
93
|
+
return false;
|
|
161
94
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
95
|
+
if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
|
|
96
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
97
|
+
let lastStop;
|
|
98
|
+
args.forEach(arg => {
|
|
99
|
+
let color;
|
|
100
|
+
let stop;
|
|
101
|
+
if (arg[2] !== undefined) {
|
|
102
|
+
if (arg[0].type === 'function') {
|
|
103
|
+
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
104
|
+
} else {
|
|
105
|
+
color = arg[0].value;
|
|
106
|
+
}
|
|
107
|
+
if (arg[2].type === 'function') {
|
|
108
|
+
stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
|
|
109
|
+
} else {
|
|
110
|
+
stop = arg[2].value;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
if (arg[0].type === 'function') {
|
|
114
|
+
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
115
|
+
}
|
|
116
|
+
color = arg[0].value;
|
|
117
|
+
}
|
|
118
|
+
const colorStop = stop || stop === 0 ? (0, _isColorStop2.default)(color, stop) : (0, _isColorStop2.default)(color);
|
|
119
|
+
|
|
120
|
+
if (!colorStop || !arg[2]) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
124
|
+
if (!lastStop) {
|
|
125
|
+
lastStop = thisStop;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (isLessThan(lastStop, thisStop)) {
|
|
129
|
+
arg[2].value = 0;
|
|
130
|
+
}
|
|
131
|
+
lastStop = thisStop;
|
|
132
|
+
});
|
|
133
|
+
return false;
|
|
165
134
|
}
|
|
166
|
-
|
|
167
|
-
lastStop = thisStop;
|
|
168
|
-
});
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
}).toString();
|
|
135
|
+
}).toString();
|
|
172
136
|
}
|
|
173
137
|
|
|
174
|
-
|
|
175
|
-
|
|
138
|
+
exports.default = _postcss2.default.plugin('postcss-minify-gradients', () => {
|
|
139
|
+
return css => css.walkDecls(optimise);
|
|
176
140
|
});
|
|
177
|
-
|
|
178
|
-
exports.default = _default;
|
|
179
|
-
module.exports = exports.default;
|
|
141
|
+
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-minify-gradients",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Minify gradient parameters with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
9
|
-
"prepublish": ""
|
|
7
|
+
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
|
|
10
8
|
},
|
|
11
9
|
"files": [
|
|
12
10
|
"LICENSE-MIT",
|
|
@@ -18,6 +16,10 @@
|
|
|
18
16
|
"postcss-plugin"
|
|
19
17
|
],
|
|
20
18
|
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"babel-cli": "^6.0.0",
|
|
21
|
+
"cross-env": "^5.0.0"
|
|
22
|
+
},
|
|
21
23
|
"homepage": "https://github.com/cssnano/cssnano",
|
|
22
24
|
"author": {
|
|
23
25
|
"name": "Ben Briggs",
|
|
@@ -26,15 +28,15 @@
|
|
|
26
28
|
},
|
|
27
29
|
"repository": "cssnano/cssnano",
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"cssnano-
|
|
30
|
-
"is-color-stop": "^1.
|
|
31
|
-
"postcss": "^
|
|
32
|
-
"postcss-value-parser": "^3.
|
|
31
|
+
"cssnano-util-get-arguments": "^4.0.0",
|
|
32
|
+
"is-color-stop": "^1.0.0",
|
|
33
|
+
"postcss": "^6.0.0",
|
|
34
|
+
"postcss-value-parser": "^3.0.0"
|
|
33
35
|
},
|
|
34
36
|
"bugs": {
|
|
35
37
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
36
38
|
},
|
|
37
39
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
40
|
+
"node": ">=6.9.0"
|
|
39
41
|
}
|
|
40
|
-
}
|
|
42
|
+
}
|