html-minifier-next 6.2.0 → 6.2.1
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/htmlminifier.cjs +12 -6
- package/dist/types/lib/attributes.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/lib/attributes.js +8 -2
- package/src/lib/whitespace.js +4 -4
package/README.md
CHANGED
|
@@ -603,7 +603,7 @@ Parameters:
|
|
|
603
603
|
|
|
604
604
|
## Acknowledgements
|
|
605
605
|
|
|
606
|
-
With many thanks to
|
|
606
|
+
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), and [Chris Morgan](https://github.com/chris-morgan)!
|
|
607
607
|
|
|
608
608
|
***
|
|
609
609
|
|
package/dist/htmlminifier.cjs
CHANGED
|
@@ -1429,15 +1429,15 @@ function collapseWhitespaceSmart(str, prevTag, nextTag, prevAttrs, nextAttrs, op
|
|
|
1429
1429
|
|
|
1430
1430
|
// Collapse/trim whitespace for given tag
|
|
1431
1431
|
|
|
1432
|
-
const
|
|
1433
|
-
const
|
|
1432
|
+
const noCollapseWhitespaceTags = new Set(['script', 'style', 'pre', 'textarea']);
|
|
1433
|
+
const noTrimWhitespaceTags = new Set(['pre', 'textarea']);
|
|
1434
1434
|
|
|
1435
1435
|
function canCollapseWhitespace(tag) {
|
|
1436
|
-
return !
|
|
1436
|
+
return !noCollapseWhitespaceTags.has(tag);
|
|
1437
1437
|
}
|
|
1438
1438
|
|
|
1439
1439
|
function canTrimWhitespace(tag) {
|
|
1440
|
-
return !
|
|
1440
|
+
return !noTrimWhitespaceTags.has(tag);
|
|
1441
1441
|
}
|
|
1442
1442
|
|
|
1443
1443
|
/**
|
|
@@ -2366,12 +2366,18 @@ function hasAttrName(name, attrs) {
|
|
|
2366
2366
|
|
|
2367
2367
|
// Cleaners
|
|
2368
2368
|
|
|
2369
|
+
const collapseAttributeWhitespaceExempt = new Set(['pattern', 'placeholder', 'title']);
|
|
2370
|
+
// `value` whitespace matters only on form-submission and machine-readable elements
|
|
2371
|
+
const valueWhitespaceExemptElements = new Set(['button', 'data', 'input', 'option', 'param']);
|
|
2372
|
+
|
|
2369
2373
|
// Returns the cleaned attribute value directly (sync) or as a Promise (async);
|
|
2370
2374
|
// callers must handle both cases—use `isThenable()` to distinguish
|
|
2371
2375
|
function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTMLSelf) {
|
|
2376
|
+
const isEventAttr = isEventAttribute(attrName, options);
|
|
2377
|
+
|
|
2372
2378
|
// Apply early whitespace normalization if enabled
|
|
2373
2379
|
// Preserves special spaces (no-break space, hair space, etc.) for consistency with `collapseWhitespace`
|
|
2374
|
-
if (options.collapseAttributeWhitespace) {
|
|
2380
|
+
if (options.collapseAttributeWhitespace && !collapseAttributeWhitespaceExempt.has(attrName) && !(attrName === 'value' && valueWhitespaceExemptElements.has(tag)) && !isEventAttr) {
|
|
2375
2381
|
// Fast path: Only process if whitespace exists (avoids regex overhead on clean values)
|
|
2376
2382
|
if (RE_ATTR_WS_CHECK.test(attrValue)) {
|
|
2377
2383
|
// Two-pass approach (faster than single-pass with callback)
|
|
@@ -2381,7 +2387,7 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTM
|
|
|
2381
2387
|
}
|
|
2382
2388
|
}
|
|
2383
2389
|
|
|
2384
|
-
if (
|
|
2390
|
+
if (isEventAttr) {
|
|
2385
2391
|
attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, '');
|
|
2386
2392
|
const result = options.minifyJS(attrValue, true);
|
|
2387
2393
|
if (isThenable(result)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/lib/attributes.js"],"names":[],"mappings":"AAmCA,mEAOC;AAED,uEAWC;AAED,8DAGC;AAED,4EAOC;AAgCD,mGAuCC;AAED,mEAGC;AAED,qEAGC;AAED,kEAWC;AAED,sEAGC;AAED,8DAWC;AAED,2EAIC;AAmBD,qEAGC;AAgBD,wEAGC;AAED,sEAUC;AAED,2EAEC;AAED,2DAEC;AAED,8DAUC;AAED,uEAUC;AAED,oGASC;AAED,4DAOC;
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/lib/attributes.js"],"names":[],"mappings":"AAmCA,mEAOC;AAED,uEAWC;AAED,8DAGC;AAED,4EAOC;AAgCD,mGAuCC;AAED,mEAGC;AAED,qEAGC;AAED,kEAWC;AAED,sEAGC;AAED,8DAWC;AAED,2EAIC;AAmBD,qEAGC;AAgBD,wEAGC;AAED,sEAUC;AAED,2EAEC;AAED,2DAEC;AAED,8DAUC;AAED,uEAUC;AAED,oGASC;AAED,4DAOC;AAUD,iIA4KC;AAwBD,mGAYC;AA0CD,6GAuHC;AAxlBD;;;;;;;GAOG;AACH,mEAHW,OAAO,SAuBjB"}
|
package/package.json
CHANGED
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
19
19
|
"@rollup/plugin-json": "^6.1.0",
|
|
20
20
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
21
|
-
"@swc/core": "^1.15.
|
|
21
|
+
"@swc/core": "^1.15.30",
|
|
22
22
|
"eslint": "^10.2.0",
|
|
23
|
-
"rollup": "^4.60.
|
|
23
|
+
"rollup": "^4.60.2",
|
|
24
24
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
25
|
-
"typescript": "^6.0.
|
|
25
|
+
"typescript": "^6.0.3",
|
|
26
26
|
"vite": "^8.0.8"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
},
|
|
97
97
|
"type": "module",
|
|
98
98
|
"types": "./dist/types/htmlminifier.d.ts",
|
|
99
|
-
"version": "6.2.
|
|
99
|
+
"version": "6.2.1"
|
|
100
100
|
}
|
package/src/lib/attributes.js
CHANGED
|
@@ -294,12 +294,18 @@ function hasAttrName(name, attrs) {
|
|
|
294
294
|
|
|
295
295
|
// Cleaners
|
|
296
296
|
|
|
297
|
+
const collapseAttributeWhitespaceExempt = new Set(['pattern', 'placeholder', 'title']);
|
|
298
|
+
// `value` whitespace matters only on form-submission and machine-readable elements
|
|
299
|
+
const valueWhitespaceExemptElements = new Set(['button', 'data', 'input', 'option', 'param']);
|
|
300
|
+
|
|
297
301
|
// Returns the cleaned attribute value directly (sync) or as a Promise (async);
|
|
298
302
|
// callers must handle both cases—use `isThenable()` to distinguish
|
|
299
303
|
function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTMLSelf) {
|
|
304
|
+
const isEventAttr = isEventAttribute(attrName, options);
|
|
305
|
+
|
|
300
306
|
// Apply early whitespace normalization if enabled
|
|
301
307
|
// Preserves special spaces (no-break space, hair space, etc.) for consistency with `collapseWhitespace`
|
|
302
|
-
if (options.collapseAttributeWhitespace) {
|
|
308
|
+
if (options.collapseAttributeWhitespace && !collapseAttributeWhitespaceExempt.has(attrName) && !(attrName === 'value' && valueWhitespaceExemptElements.has(tag)) && !isEventAttr) {
|
|
303
309
|
// Fast path: Only process if whitespace exists (avoids regex overhead on clean values)
|
|
304
310
|
if (RE_ATTR_WS_CHECK.test(attrValue)) {
|
|
305
311
|
// Two-pass approach (faster than single-pass with callback)
|
|
@@ -309,7 +315,7 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTM
|
|
|
309
315
|
}
|
|
310
316
|
}
|
|
311
317
|
|
|
312
|
-
if (
|
|
318
|
+
if (isEventAttr) {
|
|
313
319
|
attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, '');
|
|
314
320
|
const result = options.minifyJS(attrValue, true);
|
|
315
321
|
if (isThenable(result)) {
|
package/src/lib/whitespace.js
CHANGED
|
@@ -211,15 +211,15 @@ function collapseWhitespaceSmart(str, prevTag, nextTag, prevAttrs, nextAttrs, op
|
|
|
211
211
|
|
|
212
212
|
// Collapse/trim whitespace for given tag
|
|
213
213
|
|
|
214
|
-
const
|
|
215
|
-
const
|
|
214
|
+
const noCollapseWhitespaceTags = new Set(['script', 'style', 'pre', 'textarea']);
|
|
215
|
+
const noTrimWhitespaceTags = new Set(['pre', 'textarea']);
|
|
216
216
|
|
|
217
217
|
function canCollapseWhitespace(tag) {
|
|
218
|
-
return !
|
|
218
|
+
return !noCollapseWhitespaceTags.has(tag);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
function canTrimWhitespace(tag) {
|
|
222
|
-
return !
|
|
222
|
+
return !noTrimWhitespaceTags.has(tag);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
// Exports
|