cssnano 3.8.1 → 3.10.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 CHANGED
@@ -1,3 +1,32 @@
1
+ # 3.10.0
2
+
3
+ * cssnano will no longer `console.warn` any messages when using deprecated
4
+ options; these are now sent to PostCSS. You will be able to see them if you
5
+ use a PostCSS runner with built-in messages support, or alternately by
6
+ loading `postcss-reporter` or `postcss-browser-reporter` in your plugins list.
7
+ * Prepares support for `grid` identifier reduction by adding it to the list
8
+ of optimisations turned off when `options.safe` is set to `true`.
9
+ * Adds support for normalizing `unicode-range` descriptors. Values will
10
+ be converted when the code matches `0` & `f` in the same place on both sides
11
+ of the range. So, `u+2000-2fff` can be converted to `u+2???`, but
12
+ `u+2100-2fff` will be left as it is.
13
+
14
+ # 3.9.1
15
+
16
+ * Resolves an integration issue with `v3.9.0`, where `undefined` values
17
+ would attempt to be parsed.
18
+
19
+ # 3.9.0
20
+
21
+ * Adds a new option to normalize wrapping quotes for strings & joining
22
+ multiple-line strings into a single line. This optimisation can potentially
23
+ reduce the final gzipped size of your CSS file.
24
+
25
+ # 3.8.2
26
+
27
+ * Resolves an issue where `display: list-item inline flow` would be normalized
28
+ to `inline list-item` rather than `inline-list-item` (thanks to @mattbasta).
29
+
1
30
  # 3.8.1
2
31
 
3
32
  * Adds a quick start file for easy integration with Runkit. Try cssnano online
package/dist/index.js CHANGED
@@ -130,6 +130,14 @@ var _filterOptimiser = require('./lib/filterOptimiser');
130
130
 
131
131
  var _filterOptimiser2 = _interopRequireDefault(_filterOptimiser);
132
132
 
133
+ var _normalizeString = require('./lib/normalizeString');
134
+
135
+ var _normalizeString2 = _interopRequireDefault(_normalizeString);
136
+
137
+ var _normalizeUnicode = require('./lib/normalizeUnicode');
138
+
139
+ var _normalizeUnicode2 = _interopRequireDefault(_normalizeUnicode);
140
+
133
141
  var _reduceDisplayValues = require('./lib/reduceDisplayValues');
134
142
 
135
143
  var _reduceDisplayValues2 = _interopRequireDefault(_reduceDisplayValues);
@@ -154,12 +162,9 @@ var _styleCache = require('./lib/styleCache');
154
162
 
155
163
  var _styleCache2 = _interopRequireDefault(_styleCache);
156
164
 
157
- var _warnOnce = require('./lib/warnOnce');
158
-
159
- var _warnOnce2 = _interopRequireDefault(_warnOnce);
160
-
161
165
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
162
166
 
167
+ // Processors
163
168
  var processors = {
164
169
  postcssFilterPlugins: function postcssFilterPlugins() {
165
170
  return (0, _postcssFilterPlugins3.default)({ silent: true });
@@ -181,6 +186,8 @@ var processors = {
181
186
  postcssMinifyParams: _postcssMinifyParams2.default,
182
187
  postcssNormalizeCharset: _postcssNormalizeCharset2.default,
183
188
  postcssDiscardOverridden: _postcssDiscardOverridden2.default,
189
+ normalizeString: _normalizeString2.default,
190
+ normalizeUnicode: _normalizeUnicode2.default,
184
191
  // minify-font-values should be run before discard-unused
185
192
  postcssMinifyFontValues: _postcssMinifyFontValues2.default,
186
193
  postcssDiscardUnused: _postcssDiscardUnused2.default,
@@ -202,13 +209,6 @@ var processors = {
202
209
  styleCache: _styleCache2.default
203
210
  };
204
211
 
205
- /**
206
- * Deprecation warnings
207
- */
208
-
209
- // Processors
210
-
211
-
212
212
  var defaultOptions = {
213
213
  autoprefixer: {
214
214
  add: false
@@ -233,6 +233,7 @@ var safeOptions = {
233
233
  },
234
234
  postcssReduceIdents: {
235
235
  counterStyle: false,
236
+ gridTemplate: false,
236
237
  keyframes: false
237
238
  },
238
239
  postcssNormalizeUrl: {
@@ -254,19 +255,30 @@ var cssnano = _postcss2.default.plugin('cssnano', function () {
254
255
 
255
256
  var safe = options.isSafe;
256
257
  var proc = (0, _postcss2.default)();
258
+ var warnings = [];
257
259
 
258
260
  if (typeof options.fontFamily !== 'undefined' || typeof options.minifyFontWeight !== 'undefined') {
259
- (0, _warnOnce2.default)('The fontFamily & minifyFontWeight options have been ' + 'consolidated into minifyFontValues, and are now deprecated.');
261
+ warnings.push('The fontFamily & minifyFontWeight options have been ' + 'consolidated into minifyFontValues, and are now deprecated.');
260
262
  if (!options.minifyFontValues) {
261
263
  options.minifyFontValues = options.fontFamily;
262
264
  }
263
265
  }
264
266
 
265
267
  if (typeof options.singleCharset !== 'undefined') {
266
- (0, _warnOnce2.default)('The singleCharset option has been renamed to ' + 'normalizeCharset, and is now deprecated.');
268
+ warnings.push('The singleCharset option has been renamed to ' + 'normalizeCharset, and is now deprecated.');
267
269
  options.normalizeCharset = options.singleCharset;
268
270
  }
269
271
 
272
+ if (warnings.length) {
273
+ proc.use(_postcss2.default.plugin('cssnano', function () {
274
+ return function (css, result) {
275
+ return warnings.forEach(function (w) {
276
+ return result.warn(w);
277
+ });
278
+ };
279
+ }));
280
+ }
281
+
270
282
  Object.keys(processors).forEach(function (plugin) {
271
283
  var shortName = plugin.replace('postcss', '');
272
284
  shortName = shortName.slice(0, 1).toLowerCase() + shortName.slice(1);
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
+
7
+ var postcss = require('postcss');
8
+ var valueParser = require('postcss-value-parser');
9
+
10
+ /*
11
+ * Constants (parser usage)
12
+ */
13
+
14
+ var SINGLE_QUOTE = 39;
15
+ var DOUBLE_QUOTE = 34;
16
+ var BACKSLASH = 92;
17
+ var NEWLINE = 10;
18
+ var SPACE = 32;
19
+ var FEED = 12;
20
+ var TAB = 9;
21
+ var CR = 13;
22
+
23
+ var WORD_END = /[ \n\t\r\f'"\\]/g;
24
+
25
+ /*
26
+ * Constants (node type strings)
27
+ */
28
+
29
+ var C_STRING = 'string';
30
+ var C_ESCAPED_SINGLE_QUOTE = 'escapedSingleQuote';
31
+ var C_ESCAPED_DOUBLE_QUOTE = 'escapedDoubleQuote';
32
+ var C_SINGLE_QUOTE = 'singleQuote';
33
+ var C_DOUBLE_QUOTE = 'doubleQuote';
34
+ var C_NEWLINE = 'newline';
35
+ var C_SINGLE = 'single';
36
+
37
+ /*
38
+ * Literals
39
+ */
40
+
41
+ var L_SINGLE_QUOTE = '\'';
42
+ var L_DOUBLE_QUOTE = '"';
43
+ var L_NEWLINE = '\\\n';
44
+
45
+ /*
46
+ * Parser nodes
47
+ */
48
+
49
+ var T_ESCAPED_SINGLE_QUOTE = { type: C_ESCAPED_SINGLE_QUOTE, value: '\\\'' };
50
+ var T_ESCAPED_DOUBLE_QUOTE = { type: C_ESCAPED_DOUBLE_QUOTE, value: '\\"' };
51
+ var T_SINGLE_QUOTE = { type: C_SINGLE_QUOTE, value: L_SINGLE_QUOTE };
52
+ var T_DOUBLE_QUOTE = { type: C_DOUBLE_QUOTE, value: L_DOUBLE_QUOTE };
53
+ var T_NEWLINE = { type: C_NEWLINE, value: L_NEWLINE };
54
+
55
+ function stringify(ast) {
56
+ return ast.nodes.reduce(function (str, _ref) {
57
+ var value = _ref.value;
58
+
59
+ // Collapse multiple line strings automatically
60
+ if (value === L_NEWLINE) {
61
+ return str;
62
+ }
63
+ return str + value;
64
+ }, '');
65
+ }
66
+
67
+ function parse(str) {
68
+ var code = void 0,
69
+ next = void 0,
70
+ value = void 0;
71
+ var pos = 0;
72
+ var len = str.length;
73
+
74
+ var ast = {
75
+ nodes: [],
76
+ types: {
77
+ escapedSingleQuote: 0,
78
+ escapedDoubleQuote: 0,
79
+ singleQuote: 0,
80
+ doubleQuote: 0
81
+ },
82
+ quotes: false
83
+ };
84
+
85
+ while (pos < len) {
86
+ code = str.charCodeAt(pos);
87
+ switch (code) {
88
+ case SPACE:
89
+ case TAB:
90
+ case CR:
91
+ case FEED:
92
+ next = pos;
93
+ do {
94
+ next += 1;
95
+ code = str.charCodeAt(next);
96
+ } while (code === SPACE || code === NEWLINE || code === TAB || code === CR || code === FEED);
97
+
98
+ ast.nodes.push({
99
+ type: 'space',
100
+ value: str.slice(pos, next)
101
+ });
102
+ pos = next - 1;
103
+ break;
104
+ case SINGLE_QUOTE:
105
+ ast.nodes.push(T_SINGLE_QUOTE);
106
+ ast.types[C_SINGLE_QUOTE]++;
107
+ ast.quotes = true;
108
+ break;
109
+ case DOUBLE_QUOTE:
110
+ ast.nodes.push(T_DOUBLE_QUOTE);
111
+ ast.types[C_DOUBLE_QUOTE]++;
112
+ ast.quotes = true;
113
+ break;
114
+ case BACKSLASH:
115
+ next = pos + 1;
116
+ if (str.charCodeAt(next) === SINGLE_QUOTE) {
117
+ ast.nodes.push(T_ESCAPED_SINGLE_QUOTE);
118
+ ast.types[C_ESCAPED_SINGLE_QUOTE]++;
119
+ ast.quotes = true;
120
+ pos = next;
121
+ break;
122
+ } else if (str.charCodeAt(next) === DOUBLE_QUOTE) {
123
+ ast.nodes.push(T_ESCAPED_DOUBLE_QUOTE);
124
+ ast.types[C_ESCAPED_DOUBLE_QUOTE]++;
125
+ ast.quotes = true;
126
+ pos = next;
127
+ break;
128
+ } else if (str.charCodeAt(next) === NEWLINE) {
129
+ ast.nodes.push(T_NEWLINE);
130
+ pos = next;
131
+ break;
132
+ }
133
+ /*
134
+ * We need to fall through here to handle the token as
135
+ * a whole word. The missing 'break' is intentional.
136
+ */
137
+ default:
138
+ WORD_END.lastIndex = pos + 1;
139
+ WORD_END.test(str);
140
+
141
+ if (WORD_END.lastIndex === 0) {
142
+ next = len - 1;
143
+ } else {
144
+ next = WORD_END.lastIndex - 2;
145
+ }
146
+
147
+ value = str.slice(pos, next + 1);
148
+
149
+ ast.nodes.push({
150
+ type: C_STRING,
151
+ value: value
152
+ });
153
+
154
+ pos = next;
155
+ }
156
+ pos++;
157
+ }
158
+
159
+ return ast;
160
+ }
161
+
162
+ function changeWrappingQuotes(node, ast) {
163
+ var types = ast.types;
164
+
165
+ if (types[C_SINGLE_QUOTE] || types[C_DOUBLE_QUOTE]) {
166
+ return;
167
+ }
168
+
169
+ if (node.quote === L_SINGLE_QUOTE && types[C_ESCAPED_SINGLE_QUOTE] > 0 && !types[C_ESCAPED_DOUBLE_QUOTE]) {
170
+ node.quote = L_DOUBLE_QUOTE;
171
+ }
172
+
173
+ if (node.quote === L_DOUBLE_QUOTE && types[C_ESCAPED_DOUBLE_QUOTE] > 0 && !types[C_ESCAPED_SINGLE_QUOTE]) {
174
+ node.quote = L_SINGLE_QUOTE;
175
+ }
176
+
177
+ ast.nodes = ast.nodes.reduce(function (newAst, child) {
178
+ if (child.type === C_ESCAPED_DOUBLE_QUOTE && node.quote === L_SINGLE_QUOTE) {
179
+ return [].concat(newAst, [T_DOUBLE_QUOTE]);
180
+ }
181
+ if (child.type === C_ESCAPED_SINGLE_QUOTE && node.quote === L_DOUBLE_QUOTE) {
182
+ return [].concat(newAst, [T_SINGLE_QUOTE]);
183
+ }
184
+ return [].concat(newAst, [child]);
185
+ }, []);
186
+ }
187
+
188
+ function normalize(value, preferredQuote) {
189
+ if (!value || !value.length) {
190
+ return value;
191
+ }
192
+ return valueParser(value).walk(function (child) {
193
+ if (child.type !== C_STRING) {
194
+ return;
195
+ }
196
+ var ast = parse(child.value);
197
+ if (ast.quotes) {
198
+ changeWrappingQuotes(child, ast);
199
+ } else if (preferredQuote === C_SINGLE) {
200
+ child.quote = L_SINGLE_QUOTE;
201
+ } else {
202
+ child.quote = L_DOUBLE_QUOTE;
203
+ }
204
+ child.value = stringify(ast);
205
+ }).toString();
206
+ }
207
+
208
+ exports.default = postcss.plugin('cssnano-normalize-string', function (opts) {
209
+ var _preferredQuote$opts = _extends({
210
+ preferredQuote: 'double'
211
+ }, opts),
212
+ preferredQuote = _preferredQuote$opts.preferredQuote;
213
+
214
+ return function (css) {
215
+ css.walk(function (node) {
216
+ if (node.type === 'rule') {
217
+ node.selector = normalize(node.selector, preferredQuote);
218
+ }
219
+ if (node.type === 'decl') {
220
+ node.value = normalize(node.value, preferredQuote);
221
+ }
222
+ if (node.type === 'atrule') {
223
+ node.params = normalize(node.params, preferredQuote);
224
+ }
225
+ });
226
+ };
227
+ });
228
+ module.exports = exports['default'];
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _postcss = require('postcss');
6
+
7
+ var _postcss2 = _interopRequireDefault(_postcss);
8
+
9
+ var _postcssValueParser = require('postcss-value-parser');
10
+
11
+ var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ function unicode(range) {
16
+ var values = range.slice(2).split('-');
17
+ if (values.length < 2) {
18
+ return range;
19
+ }
20
+ var left = values[0].split('');
21
+ var right = values[1].split('');
22
+
23
+ if (left.length !== right.length) {
24
+ return range;
25
+ }
26
+
27
+ var questionCounter = 0;
28
+
29
+ var merged = left.reduce(function (group, value, index) {
30
+ if (group === false) {
31
+ return false;
32
+ }
33
+ if (value === right[index] && !questionCounter) {
34
+ return group + value;
35
+ }
36
+ if (value === '0' && right[index] === 'f') {
37
+ questionCounter++;
38
+ return group + '?';
39
+ }
40
+ return false;
41
+ }, 'u+');
42
+
43
+ /*
44
+ * The maximum number of wildcard characters (?) for ranges is 5.
45
+ */
46
+
47
+ if (merged && questionCounter < 6) {
48
+ return merged;
49
+ }
50
+
51
+ return range;
52
+ }
53
+
54
+ exports.default = _postcss2.default.plugin('cssnano-normalize-unicode', function () {
55
+ return function (css) {
56
+ css.walkDecls(/^unicode-range$/i, function (node) {
57
+ node.prop = 'unicode-range';
58
+ node.value = (0, _postcssValueParser2.default)(node.value).walk(function (child) {
59
+ if (child.type === 'word') {
60
+ child.value = unicode(child.value.toLowerCase());
61
+ }
62
+ return false;
63
+ }).toString();
64
+ });
65
+ };
66
+ });
67
+ module.exports = exports['default'];
@@ -24,7 +24,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
24
  * Specification: https://drafts.csswg.org/css-display/#the-display-properties
25
25
  */
26
26
 
27
- var mappings = [['block', ['block', 'flow']], ['flow-root', ['block', 'flow-root']], ['inline', ['inline', 'flow']], ['inline-block', ['inline', 'flow-root']], ['run-in', ['run-in', 'flow']], ['list-item', ['list-item', 'block', 'flow']], ['inline list-item', ['list-item', 'inline', 'flow']], ['flex', ['block', 'flex']], ['inline-flex', ['inline', 'flex']], ['grid', ['block', 'grid']], ['inline-grid', ['inline', 'grid']], ['ruby', ['inline', 'ruby']], ['table', ['block', 'table']], ['inline-table', ['inline', 'table']], ['table-cell', ['table-cell', 'flow']], ['table-caption', ['table-caption', 'flow']], ['ruby-base', ['ruby-base', 'flow']], ['ruby-text', ['ruby-text', 'flow']]];
27
+ var mappings = [['block', ['block', 'flow']], ['flow-root', ['block', 'flow-root']], ['inline', ['inline', 'flow']], ['inline-block', ['inline', 'flow-root']], ['run-in', ['run-in', 'flow']], ['list-item', ['list-item', 'block', 'flow']], ['inline-list-item', ['list-item', 'inline', 'flow']], ['flex', ['block', 'flex']], ['inline-flex', ['inline', 'flex']], ['grid', ['block', 'grid']], ['inline-grid', ['inline', 'grid']], ['ruby', ['inline', 'ruby']], ['table', ['block', 'table']], ['inline-table', ['inline', 'table']], ['table-cell', ['table-cell', 'flow']], ['table-caption', ['table-caption', 'flow']], ['ruby-base', ['ruby-base', 'flow']], ['ruby-text', ['ruby-text', 'flow']]];
28
28
 
29
29
  var getMatch = (0, _getMatch2.default)(mappings);
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cssnano",
3
- "version": "3.8.1",
3
+ "version": "3.10.0",
4
4
  "description": "A modular minifier, built on top of the PostCSS ecosystem.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -63,6 +63,7 @@
63
63
  "babel-core": "^6.5.1",
64
64
  "babel-loader": "^6.2.4",
65
65
  "babel-plugin-add-module-exports": "^0.2.0",
66
+ "babel-plugin-precompile-charcodes": "^1.0.0",
66
67
  "babel-preset-es2015-loose": "^7.0.0",
67
68
  "babel-preset-stage-0": "^6.5.0",
68
69
  "coveralls": "^2.11.6",
@@ -75,10 +76,10 @@
75
76
  "eslint-plugin-babel": "^3.3.0",
76
77
  "eslint-plugin-import": "^2.0.1",
77
78
  "gh-pages": "^0.11.0",
78
- "hook-std": "^0.2.0",
79
79
  "json-loader": "^0.5.4",
80
80
  "ncp": "^2.0.0",
81
- "nyc": "^8.0.0",
81
+ "nyc": "^10.0.0",
82
+ "postcss-font-magician": "^1.5.0",
82
83
  "webpack": "^1.12.13",
83
84
  "webpack-bundle-size-analyzer": "^2.0.2"
84
85
  },
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- exports.__esModule = true;
4
- exports.default = warnOnce;
5
- var messages = {};
6
-
7
- function warnOnce(message) {
8
- if (messages[message]) {
9
- return;
10
- }
11
- messages[message] = true;
12
- if (typeof console !== 'undefined' && console.warn) {
13
- console.warn(message);
14
- }
15
- }
16
- module.exports = exports['default'];