html-minifier-next 8.5.3 → 8.6.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/README.md +10 -9
- package/cli.js +1 -1
- package/dist/types/htmlminifier.d.ts +10 -0
- package/dist/types/htmlminifier.d.ts.map +1 -1
- package/dist/types/lib/option-definitions.d.ts.map +1 -1
- package/dist/types/lib/options.d.ts.map +1 -1
- package/dist/types/lib/whitespace.d.ts +9 -1
- package/dist/types/lib/whitespace.d.ts.map +1 -1
- package/html-minifier-next.schema.json +4 -0
- package/package.json +3 -3
- package/src/htmlminifier.js +13 -0
- package/src/lib/option-definitions.js +4 -0
- package/src/lib/options.js +1 -0
- package/src/lib/unused-css.js +1 -1
- package/src/lib/whitespace.js +39 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Your web page optimization precision tool: HTML Minifier Next (HMN) is a **highly effective, super-configurable, well-tested HTML minifier**, written in JavaScript, that also handles in-document CSS, JavaScript, and SVG minification.
|
|
6
6
|
|
|
7
|
-
The project was based on [HTML Minifier Terser (HMT)](https://github.com/terser/html-minifier-terser), which in turn had been based on [Juriy “kangax” Zaytsev’s HTML Minifier (HM)](https://github.com/kangax/html-minifier). HMN is **the official successor to HTML Minifier**: It’s actively maintained, richer in features, easier to use, and significantly faster. Note that HMN is largely compatible with HM and HMT but isn’t fully drop-in—find [migration guidance in the changelog](https://github.com/j9t/html-minifier-next/blob/main/CHANGELOG.md).
|
|
7
|
+
The project was based on [HTML Minifier Terser (HMT)](https://github.com/terser/html-minifier-terser), which in turn had been based on [Juriy “kangax” Zaytsev’s HTML Minifier (HM)](https://github.com/kangax/html-minifier). HMN is **the official successor to HTML Minifier**: It’s actively maintained, richer in features, easier to use, and significantly faster ([HMN engineering philosophy](https://meiert.com/blog/html-minifier-next-engineering-philosophy/)). Note that HMN is largely compatible with HM and HMT but isn’t fully drop-in—find [migration guidance in the changelog](https://github.com/j9t/html-minifier-next/blob/main/CHANGELOG.md).
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -32,7 +32,7 @@ Use `npx html-minifier-next --help` to check all available options:
|
|
|
32
32
|
|
|
33
33
|
| Option | Description | Example |
|
|
34
34
|
| --- | --- | --- |
|
|
35
|
-
| `--zero`, `-z` | Minify all HTML files in the current folder and its subfolders in place (except node_modules), using comprehensive settings (standalone—flag is ignored when combined with other options) | `npx html-minifier-next --zero` |
|
|
35
|
+
| `--zero`, `-z` | Minify all HTML files in the current folder and its subfolders in place (except node_modules), using comprehensive settings (standalone—the flag is ignored when combined with other options) | `npx html-minifier-next --zero` |
|
|
36
36
|
| `--input-dir <dir>`, `-I <dir>` | Specify an input directory | `--input-dir=src` |
|
|
37
37
|
| `--ignore-dir <patterns>`, `-X <patterns>` | Exclude directories—relative to input directory—from processing (comma-separated, overrides config file setting) | `--ignore-dir=libs`, `--ignore-dir=libs,vendor,node_modules` |
|
|
38
38
|
| `--output-dir <dir>`, `-O <dir>` | Specify an output directory | `--output-dir=dist` |
|
|
@@ -141,6 +141,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
|
|
|
141
141
|
| `collapseAttributeWhitespace`<br>`--collapse-attribute-whitespace` | Trim and collapse whitespace characters within attribute values | `false` |
|
|
142
142
|
| `collapseBooleanAttributes`<br>`--collapse-boolean-attributes` | [Omit attribute values from boolean attributes](https://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes) | `false` |
|
|
143
143
|
| `collapseInlineTagWhitespace`<br>`--collapse-inline-tag-whitespace` | Collapse whitespace more aggressively between inline elements—use with [`collapseWhitespace`](#combining-whitespace-options) | `false` |
|
|
144
|
+
| `collapseNoBreakSpaces`<br>`--collapse-no-break-spaces` | Remove whitespace next to no-break spaces, narrow no-break spaces, and figure spaces in text (e.g., `a b` → `a b`), keeping runs of them—use with [`collapseWhitespace`](#combining-whitespace-options) | `false` |
|
|
144
145
|
| `collapseWhitespace`<br>`--collapse-whitespace` | [Collapse whitespace that contributes to text nodes in a document tree](https://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace); [enable other whitespace options](#combining-whitespace-options) | `false` |
|
|
145
146
|
| `conservativeCollapse`<br>`--conservative-collapse` | Always collapse to one space (never remove it entirely)—use with [`collapseWhitespace`](#combining-whitespace-options) | `false` |
|
|
146
147
|
| `continueOnMinifyError`<br>`--continue-on-minify-error`<br>`--no-continue-on-minify-error` | Continue on minification errors; when `false`, minification errors throw and abort processing | `true` |
|
|
@@ -211,6 +212,7 @@ HTML Minifier Next: Ignoring `conservativeCollapse`—use with `collapseWhitespa
|
|
|
211
212
|
| `canMinifyJS` | `minifyJS`, and not [a function of your own](#javascript-minification) |
|
|
212
213
|
| `canMinifySVG` | `minifySVG`, and not [a function of your own](#svg-minification) |
|
|
213
214
|
| `collapseInlineTagWhitespace` | `collapseWhitespace` |
|
|
215
|
+
| `collapseNoBreakSpaces` | `collapseWhitespace` |
|
|
214
216
|
| `conservativeCollapse` | `collapseWhitespace` |
|
|
215
217
|
| `customEventAttributes` | `minifyJS` |
|
|
216
218
|
| `inlineCustomElements` | `collapseWhitespace` |
|
|
@@ -220,11 +222,11 @@ HTML Minifier Next: Ignoring `conservativeCollapse`—use with `collapseWhitespa
|
|
|
220
222
|
| `removeUnusedCSS` | `minifyCSS`, and not [a function of your own](#unused-css-removal) |
|
|
221
223
|
| `trimCustomFragments` | `collapseWhitespace` |
|
|
222
224
|
|
|
223
|
-
Passing the option `false`, or an empty array, asks for nothing and is not reported. `cacheCSS`, `cacheJS`, and `cacheSVG` are not
|
|
225
|
+
Passing the option `false`, or an empty array, asks for nothing and is not reported. `cacheCSS`, `cacheJS`, and `cacheSVG` are not included because they size a cache rather than transform markup, and therefore don’t change output.
|
|
224
226
|
|
|
225
227
|
### Combining whitespace options
|
|
226
228
|
|
|
227
|
-
`collapseInlineTagWhitespace`, `conservativeCollapse`, and `preserveLineBreaks` are modifiers: They do nothing on their own, and only take effect when `collapseWhitespace` is enabled.
|
|
229
|
+
`collapseInlineTagWhitespace`, `collapseNoBreakSpaces`, `conservativeCollapse`, and `preserveLineBreaks` are modifiers: They do nothing on their own, and only take effect when `collapseWhitespace` is enabled.
|
|
228
230
|
|
|
229
231
|
Given input
|
|
230
232
|
|
|
@@ -503,12 +505,11 @@ HTML Minifier Next uses in-memory caches to improve performance when processing
|
|
|
503
505
|
```js
|
|
504
506
|
const result = await minify(html, {
|
|
505
507
|
minifyCSS: true,
|
|
508
|
+
cacheCSS: 750, // CSS cache size, default: 500
|
|
506
509
|
minifyJS: true,
|
|
510
|
+
cacheJS: 250, // JS cache size, default: 500
|
|
507
511
|
minifySVG: true,
|
|
508
|
-
//
|
|
509
|
-
cacheCSS: 750, // CSS cache size, default: 500
|
|
510
|
-
cacheJS: 250, // JS cache size, default: 500
|
|
511
|
-
cacheSVG: 100 // SVG cache size, default: 500
|
|
512
|
+
cacheSVG: 100 // SVG cache size, default: 500
|
|
512
513
|
});
|
|
513
514
|
```
|
|
514
515
|
|
|
@@ -855,7 +856,7 @@ This writes a .cpuprofile file to the working directory. Load it with `npx speed
|
|
|
855
856
|
|
|
856
857
|
## Acknowledgements
|
|
857
858
|
|
|
858
|
-
With many thanks to the previous authors of and contributors to HTML Minifier, especially [Juriy “kangax” Zaytsev](https://github.com/kangax), and to everyone who helped make this new edition better, particularly [Daniel Ruf](https://github.com/DanielRuf), [Jonas Geiler](https://github.com/jonasgeiler),
|
|
859
|
+
With many thanks to the previous authors of and contributors to HTML Minifier, especially [Juriy “kangax” Zaytsev](https://github.com/kangax), and to everyone who helped make this new edition better, particularly [Daniel Ruf](https://github.com/DanielRuf), [Jonas Geiler](https://github.com/jonasgeiler), [Chris Morgan](https://github.com/chris-morgan), and [Andreas Borutta](https://github.com/fermiongithub)!
|
|
859
860
|
|
|
860
861
|
***
|
|
861
862
|
|
package/cli.js
CHANGED
|
@@ -330,7 +330,7 @@ function normalizeConfig(config) {
|
|
|
330
330
|
|
|
331
331
|
/** @type {Record<string, any>} */
|
|
332
332
|
let config = {};
|
|
333
|
-
program.option('-z, --zero', 'Minify all HTML files in the current folder and its subfolders in place (except node_modules), using comprehensive settings (standalone—flag is ignored when combined with other options)');
|
|
333
|
+
program.option('-z, --zero', 'Minify all HTML files in the current folder and its subfolders in place (except node_modules), using comprehensive settings (standalone—the flag is ignored when combined with other options)');
|
|
334
334
|
program.option('-I --input-dir <dir>', 'Specify an input directory');
|
|
335
335
|
program.option('-X --ignore-dir <patterns>', 'Exclude directories—relative to input directory—from processing (comma-separated, overrides config file setting)');
|
|
336
336
|
program.option('-O --output-dir <dir>', 'Specify an output directory');
|
|
@@ -113,6 +113,16 @@ export type MinifierOptions = {
|
|
|
113
113
|
* Default: `false`
|
|
114
114
|
*/
|
|
115
115
|
collapseInlineTagWhitespace?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Remove whitespace next to a no-break space (`U+00A0`), narrow no-break
|
|
118
|
+
* space (`U+202F`), or figure space (`U+2007`) in text (for example
|
|
119
|
+
* `a b` → `a b`), which changes how the text renders. Runs of
|
|
120
|
+
* no-break spaces are kept.
|
|
121
|
+
* Must also enable `collapseWhitespace` to have effect.
|
|
122
|
+
*
|
|
123
|
+
* Default: `false`
|
|
124
|
+
*/
|
|
125
|
+
collapseNoBreakSpaces?: boolean;
|
|
116
126
|
/**
|
|
117
127
|
* Collapse multiple whitespace characters into one where allowed. Also
|
|
118
128
|
* controls trimming behaviour in several code paths.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,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O,CAQd;;;;;;;IAAiB,eAAe,AAAhC,CAKF,EALS,OAAO,CAKhB;CAAA,CAAA;AA0EE,YAAkB,UAAU,GAG5B;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,IAAI,EAAZ,MAAM,CACb;;;;IAAe,KAAK,EAAb,MAAM,CACf;CAAA,CAAA;AAssDD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAFhB;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,CAQhE;AA2FD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UAJR,MAAM,YACN,eAAe,KACb,OAAO,CAAC,MAAM,CAsE1B,CAAC;AAIF,OAAO,EACL,OAAO,EACP,SAAS,EACT,cAAc,EACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-definitions.d.ts","sourceRoot":"","sources":["../../../src/lib/option-definitions.js"],"names":[],"mappings":"AAAA;;GAEG;AAGA,YAAkB,gBAAgB,GAClC;;;;IAAmB,WAAW,EAAnB,MAAM,CACjB;;;;IAAoB,sBAAsB,AAA1C,CACA,EADW,MAAM,CACjB;;;;IAAmB,IAAI,EAAZ,MAAM,CACnB;CAAA,CAAA;AALD;;;;;GAKG;AAEH,+CAA+C;AAC/C,QAAA,MAAM,iBAAiB,EADZ,MAAM,CAAC,MAAM,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"option-definitions.d.ts","sourceRoot":"","sources":["../../../src/lib/option-definitions.js"],"names":[],"mappings":"AAAA;;GAEG;AAGA,YAAkB,gBAAgB,GAClC;;;;IAAmB,WAAW,EAAnB,MAAM,CACjB;;;;IAAoB,sBAAsB,AAA1C,CACA,EADW,MAAM,CACjB;;;;IAAmB,IAAI,EAAZ,MAAM,CACnB;CAAA,CAAA;AALD;;;;;GAKG;AAEH,+CAA+C;AAC/C,Q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C,EAAE,GAAG,GAAG,SAAS,CAAA;CAAC,KAC5O,gBAukBZ,CAAC;AAIF,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACf,CAAC"}
|
|
@@ -7,6 +7,14 @@ declare const trimWhitespace: (str: string) => string;
|
|
|
7
7
|
declare function endsWithWhitespace(str: string): boolean;
|
|
8
8
|
/** @param {string} str */
|
|
9
9
|
declare function collapseWhitespaceAll(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} str
|
|
12
|
+
* @param {{decodeEntities?: boolean | undefined, preserveLineBreaks?: boolean | undefined}} options
|
|
13
|
+
*/
|
|
14
|
+
declare function collapseNoBreakSpaces(str: string, options: {
|
|
15
|
+
decodeEntities?: boolean | undefined;
|
|
16
|
+
preserveLineBreaks?: boolean | undefined;
|
|
17
|
+
}): string;
|
|
10
18
|
/**
|
|
11
19
|
* @param {string} str
|
|
12
20
|
* @param {{preserveLineBreaks?: boolean | undefined, conservativeCollapse?: boolean | undefined}} options
|
|
@@ -81,5 +89,5 @@ declare function collapseWhitespaceSmart(str: string, prevTag: string, nextTag:
|
|
|
81
89
|
declare function canCollapseWhitespace(tag: string): boolean;
|
|
82
90
|
/** @param {string} tag */
|
|
83
91
|
declare function canTrimWhitespace(tag: string): boolean;
|
|
84
|
-
export { buildInlineSets, defaultInlineSets, endsWithWhitespace, trimWhitespace, collapseWhitespaceAll, collapseWhitespace, collapseWhitespaceSmart, canCollapseWhitespace, canTrimWhitespace };
|
|
92
|
+
export { buildInlineSets, defaultInlineSets, endsWithWhitespace, trimWhitespace, collapseWhitespaceAll, collapseNoBreakSpaces, collapseWhitespace, collapseWhitespaceSmart, canCollapseWhitespace, canTrimWhitespace };
|
|
85
93
|
//# sourceMappingURL=whitespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whitespace.d.ts","sourceRoot":"","sources":["../../../src/lib/whitespace.js"],"names":[],"mappings":"AAAA;;GAEG;A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;;;;IAAoB,YAAY,EAAzB,GAAG,CAAC,MAAM,CAAC,CACpB;CAAA,CAAA;AAPD;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,iBAAS,eAAe,CAAC,MAAM,EAJpB,GAAG,CAAC,MAAM,CAIU,EAAE,MAAM,EAH5B,GAAG,CAAC,MAAM,CAGkB,GAF1B,UAAU,CAWtB;AAGD,QAAA,MAAM,iBAAiB,YAA8F,CAAC;AAiBtH;;;;;;;;GAQG;AACH,iBAAS,uBAAuB,CAAC,GAAG,EARzB,MAQyB,EAAE,OAAO,EAPlC,MAOkC,EAAE,OAAO,EAN3C,MAM2C,EAAE,SAAS,EALtD,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAKkB,EAAE,SAAS,EAJjE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAI6B,EAAE,OAAO,EAH1E;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAAC,2BAA2B,CAAC,EAAE,OAAO,CAAA;CAG1B,EAAE,UAAU,EAFtF,UAEsF,UA6DhG;AASD,0BAA0B;AAC1B,iBAAS,qBAAqB,CAAC,GAAG,EADtB,MACsB,WAEjC;AAED,0BAA0B;AAC1B,iBAAS,iBAAiB,CAAC,GAAG,EADlB,MACkB,WAE7B;AAID,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EAClB,CAAC"}
|
|
@@ -67,6 +67,10 @@
|
|
|
67
67
|
"description": "Collapse whitespace more aggressively between inline elements—use with `--collapse-whitespace`",
|
|
68
68
|
"type": "boolean"
|
|
69
69
|
},
|
|
70
|
+
"collapseNoBreakSpaces": {
|
|
71
|
+
"description": "Remove whitespace next to no-break spaces, narrow no-break spaces, and figure spaces in text (e.g., `a b` → `a b`), keeping runs of them—use with `--collapse-whitespace`",
|
|
72
|
+
"type": "boolean"
|
|
73
|
+
},
|
|
70
74
|
"collapseWhitespace": {
|
|
71
75
|
"description": "Collapse whitespace that contributes to text nodes in a document tree",
|
|
72
76
|
"type": "boolean"
|
package/package.json
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"@commitlint/cli": "^21.2.3",
|
|
18
18
|
"@eslint/js": "^10.0.1",
|
|
19
19
|
"@swc/core": "^1.16.2",
|
|
20
|
-
"@types/node": "^26.6.
|
|
20
|
+
"@types/node": "^26.6.3",
|
|
21
21
|
"eslint": "^10.11.0",
|
|
22
22
|
"globals": "^17.12.0",
|
|
23
23
|
"typescript": "^7.0.2",
|
|
24
|
-
"vite": "^8.3.
|
|
24
|
+
"vite": "^8.3.1"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=22.13"
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
},
|
|
96
96
|
"type": "module",
|
|
97
97
|
"types": "dist/types/htmlminifier.d.ts",
|
|
98
|
-
"version": "8.
|
|
98
|
+
"version": "8.6.0"
|
|
99
99
|
}
|
package/src/htmlminifier.js
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
endsWithWhitespace,
|
|
38
38
|
trimWhitespace,
|
|
39
39
|
collapseWhitespaceAll,
|
|
40
|
+
collapseNoBreakSpaces,
|
|
40
41
|
collapseWhitespace,
|
|
41
42
|
collapseWhitespaceSmart,
|
|
42
43
|
canCollapseWhitespace as defaultCanCollapseWhitespace,
|
|
@@ -185,6 +186,15 @@ import { toFragment, replaceCustomFragments } from './lib/fragments.js';
|
|
|
185
186
|
*
|
|
186
187
|
* Default: `false`
|
|
187
188
|
*
|
|
189
|
+
* @prop {boolean} [collapseNoBreakSpaces]
|
|
190
|
+
* Remove whitespace next to a no-break space (`U+00A0`), narrow no-break
|
|
191
|
+
* space (`U+202F`), or figure space (`U+2007`) in text (for example
|
|
192
|
+
* `a b` → `a b`), which changes how the text renders. Runs of
|
|
193
|
+
* no-break spaces are kept.
|
|
194
|
+
* Must also enable `collapseWhitespace` to have effect.
|
|
195
|
+
*
|
|
196
|
+
* Default: `false`
|
|
197
|
+
*
|
|
188
198
|
* @prop {boolean} [collapseWhitespace]
|
|
189
199
|
* Collapse multiple whitespace characters into one where allowed. Also
|
|
190
200
|
* controls trimming behaviour in several code paths.
|
|
@@ -1511,6 +1521,9 @@ async function minifyHTML(value, options, partialMarkup) {
|
|
|
1511
1521
|
if (!stackNoCollapseWhitespace.length && textNextTag !== 'html' && !(textPrevTag && textNextTag)) {
|
|
1512
1522
|
text = collapseWhitespace(text, options, false, false, true);
|
|
1513
1523
|
}
|
|
1524
|
+
if (options.collapseNoBreakSpaces && !stackNoCollapseWhitespace.length && !holdsRawText()) {
|
|
1525
|
+
text = collapseNoBreakSpaces(text, options);
|
|
1526
|
+
}
|
|
1514
1527
|
}
|
|
1515
1528
|
return text;
|
|
1516
1529
|
}
|
|
@@ -39,6 +39,10 @@ const optionDefinitions = {
|
|
|
39
39
|
description: 'Collapse whitespace more aggressively between inline elements—use with `--collapse-whitespace`',
|
|
40
40
|
type: 'boolean'
|
|
41
41
|
},
|
|
42
|
+
collapseNoBreakSpaces: {
|
|
43
|
+
description: 'Remove whitespace next to no-break spaces, narrow no-break spaces, and figure spaces in text (e.g., `a b` → `a b`), keeping runs of them—use with `--collapse-whitespace`',
|
|
44
|
+
type: 'boolean'
|
|
45
|
+
},
|
|
42
46
|
collapseWhitespace: {
|
|
43
47
|
description: 'Collapse whitespace that contributes to text nodes in a document tree',
|
|
44
48
|
type: 'boolean'
|
package/src/lib/options.js
CHANGED
|
@@ -138,6 +138,7 @@ const optionDependencies = [
|
|
|
138
138
|
{ option: 'canMinifyJS', requires: 'minifyJS', unusable: replacedByOwnFunction('minifyJS'), clear: true },
|
|
139
139
|
{ option: 'canMinifySVG', requires: 'minifySVG', unusable: replacedByOwnFunction('minifySVG'), clear: true },
|
|
140
140
|
{ option: 'collapseInlineTagWhitespace', requires: 'collapseWhitespace' },
|
|
141
|
+
{ option: 'collapseNoBreakSpaces', requires: 'collapseWhitespace' },
|
|
141
142
|
{ option: 'conservativeCollapse', requires: 'collapseWhitespace' },
|
|
142
143
|
{ option: 'customEventAttributes', requires: 'minifyJS' },
|
|
143
144
|
{ option: 'inlineCustomElements', requires: 'collapseWhitespace' },
|
package/src/lib/unused-css.js
CHANGED
|
@@ -70,7 +70,7 @@ function unescapeIdentifier(identifier) {
|
|
|
70
70
|
if (!hex) {
|
|
71
71
|
return literal;
|
|
72
72
|
}
|
|
73
|
-
// Per CSS Syntax spec, a null, surrogate, or out-of-range escape becomes U+FFFD
|
|
73
|
+
// Per CSS Syntax spec, a null, surrogate, or out-of-range escape becomes `U+FFFD`
|
|
74
74
|
const code = parseInt(hex, 16);
|
|
75
75
|
return (code === 0 || code > 0x10FFFF || (code >= 0xD800 && code <= 0xDFFF))
|
|
76
76
|
? '\uFFFD'
|
package/src/lib/whitespace.js
CHANGED
|
@@ -88,6 +88,44 @@ function collapseWhitespaceAllKnown(str) {
|
|
|
88
88
|
return str.replace(RE_ALL_WS_NBSP, collapseRun);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// Collapse whitespace into adjacent no-break spaces
|
|
92
|
+
|
|
93
|
+
// A no-break space (`U+00A0`), narrow no-break space (`U+202F`), or figure space (`U+2007`),
|
|
94
|
+
// literal or as a character reference; numeric references and ` ` also work without
|
|
95
|
+
// the semicolon in text
|
|
96
|
+
const RE_NO_BREAK_SPACE_WS = /([ \n\r\t\f]*)(\xA0|\u202F|\u2007|&(?:nbsp;?|NonBreakingSpace;|numsp;|#0*(?:160|8239|8199)(?![0-9]);?|#[xX]0*(?:[aA]0|202[fF]|2007)(?![0-9a-fA-F]);?))([ \n\r\t\f]*)/g;
|
|
97
|
+
// Decoded text holds references only as text, so there the characters alone count
|
|
98
|
+
const RE_NO_BREAK_SPACE_CHAR_WS = /([ \n\r\t\f]*)([\xA0\u202F\u2007])([ \n\r\t\f]*)/g;
|
|
99
|
+
const RE_LINE_BREAK = /[\n\r]/;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} _match
|
|
103
|
+
* @param {string} before
|
|
104
|
+
* @param {string} noBreakSpace
|
|
105
|
+
* @param {string} after
|
|
106
|
+
*/
|
|
107
|
+
function keepLineBreaks(_match, before, noBreakSpace, after) {
|
|
108
|
+
return (RE_LINE_BREAK.test(before) ? before : '') + noBreakSpace + (RE_LINE_BREAK.test(after) ? after : '');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Callers pass text whose whitespace runs are already collapsed, as each match
|
|
112
|
+
// rescans the run in front of it
|
|
113
|
+
/**
|
|
114
|
+
* @param {string} str
|
|
115
|
+
* @param {{decodeEntities?: boolean | undefined, preserveLineBreaks?: boolean | undefined}} options
|
|
116
|
+
*/
|
|
117
|
+
function collapseNoBreakSpaces(str, options) {
|
|
118
|
+
const decoded = Boolean(options.decodeEntities);
|
|
119
|
+
if (!str || (str.indexOf('\xA0') === -1 && str.indexOf('\u202F') === -1 && str.indexOf('\u2007') === -1 && (decoded || str.indexOf('&') === -1))) {
|
|
120
|
+
return str;
|
|
121
|
+
}
|
|
122
|
+
const pattern = decoded ? RE_NO_BREAK_SPACE_CHAR_WS : RE_NO_BREAK_SPACE_WS;
|
|
123
|
+
if (options.preserveLineBreaks) {
|
|
124
|
+
return str.replace(pattern, keepLineBreaks);
|
|
125
|
+
}
|
|
126
|
+
return str.replace(pattern, '$2');
|
|
127
|
+
}
|
|
128
|
+
|
|
91
129
|
// Collapse whitespace with options
|
|
92
130
|
|
|
93
131
|
/**
|
|
@@ -356,6 +394,7 @@ export {
|
|
|
356
394
|
endsWithWhitespace,
|
|
357
395
|
trimWhitespace,
|
|
358
396
|
collapseWhitespaceAll,
|
|
397
|
+
collapseNoBreakSpaces,
|
|
359
398
|
collapseWhitespace,
|
|
360
399
|
collapseWhitespaceSmart,
|
|
361
400
|
canCollapseWhitespace,
|