html-minifier 4.0.0 → 5.0.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.
Files changed (55) hide show
  1. package/LICENSE.txt +23 -0
  2. package/README.md +851 -110
  3. package/cli.js +991 -207
  4. package/dist/types/htmlminifier.d.ts +629 -0
  5. package/dist/types/htmlminifier.d.ts.map +1 -0
  6. package/dist/types/htmlparser.d.ts +28 -0
  7. package/dist/types/htmlparser.d.ts.map +1 -0
  8. package/dist/types/lib/attributes.d.ts +87 -0
  9. package/dist/types/lib/attributes.d.ts.map +1 -0
  10. package/dist/types/lib/constants.d.ts +421 -0
  11. package/dist/types/lib/constants.d.ts.map +1 -0
  12. package/dist/types/lib/content.d.ts +44 -0
  13. package/dist/types/lib/content.d.ts.map +1 -0
  14. package/dist/types/lib/elements.d.ts +48 -0
  15. package/dist/types/lib/elements.d.ts.map +1 -0
  16. package/dist/types/lib/fragments.d.ts +47 -0
  17. package/dist/types/lib/fragments.d.ts.map +1 -0
  18. package/dist/types/lib/option-definitions.d.ts +33 -0
  19. package/dist/types/lib/option-definitions.d.ts.map +1 -0
  20. package/dist/types/lib/options.d.ts +93 -0
  21. package/dist/types/lib/options.d.ts.map +1 -0
  22. package/dist/types/lib/unused-css.d.ts +76 -0
  23. package/dist/types/lib/unused-css.d.ts.map +1 -0
  24. package/dist/types/lib/urls.d.ts +15 -0
  25. package/dist/types/lib/urls.d.ts.map +1 -0
  26. package/dist/types/lib/utils.d.ts +132 -0
  27. package/dist/types/lib/utils.d.ts.map +1 -0
  28. package/dist/types/lib/whitespace.d.ts +97 -0
  29. package/dist/types/lib/whitespace.d.ts.map +1 -0
  30. package/dist/types/presets.d.ts +50 -0
  31. package/dist/types/presets.d.ts.map +1 -0
  32. package/dist/types/tokenchain.d.ts +36 -0
  33. package/dist/types/tokenchain.d.ts.map +1 -0
  34. package/html-minifier.schema.json +322 -0
  35. package/package.json +71 -60
  36. package/src/htmlminifier.js +2862 -1106
  37. package/src/htmlparser.js +1163 -452
  38. package/src/lib/attributes.js +1196 -0
  39. package/src/lib/constants.js +521 -0
  40. package/src/lib/content.js +237 -0
  41. package/src/lib/elements.js +268 -0
  42. package/src/lib/file-pool.js +193 -0
  43. package/src/lib/file-write.js +87 -0
  44. package/src/lib/fragments.js +340 -0
  45. package/src/lib/option-definitions.js +246 -0
  46. package/src/lib/options.js +841 -0
  47. package/src/lib/unused-css.js +499 -0
  48. package/src/lib/urls.js +146 -0
  49. package/src/lib/utils.js +1026 -0
  50. package/src/lib/whitespace.js +431 -0
  51. package/src/presets.js +58 -0
  52. package/src/tokenchain.js +142 -56
  53. package/LICENSE +0 -22
  54. package/sample-cli-config-file.conf +0 -40
  55. package/src/utils.js +0 -18
@@ -0,0 +1,629 @@
1
+ import { presets, getPreset, getPresetNames } from './presets.js';
2
+ export type HTMLAttribute = {
3
+ name: string;
4
+ value?: string;
5
+ quote?: string;
6
+ customAssign?: string;
7
+ customOpen?: string;
8
+ customClose?: string;
9
+ };
10
+ export type MinifierOptions = {
11
+ /**
12
+ * Predicate that determines whether runs of whitespace inside a given element
13
+ * can be collapsed (whether its content may be trimmed is up to `canTrimWhitespace`).
14
+ *
15
+ * Default: Built-in `canCollapseWhitespace` function
16
+ */
17
+ canCollapseWhitespace?: (tag: string, attrs: HTMLAttribute[], canCollapseWhitespace: (tag: string) => boolean) => boolean;
18
+ /**
19
+ * Synchronous predicate that determines whether the built-in `minifyCSS` may
20
+ * process a given piece of CSS—`type` is `undefined` for `style` elements,
21
+ * `'inline'` for `style` attributes, and `'media'` for `media` attributes.
22
+ * Returning false leaves that CSS as if `minifyCSS` were off, including its URLs
23
+ * and unused rules (within `svg` elements, SVGO still minifies it under `minifySVG`).
24
+ *
25
+ * Default: `null` (all CSS is minified)
26
+ */
27
+ canMinifyCSS?: ((text: string, type?: 'inline' | 'media') => boolean) | null;
28
+ /**
29
+ * Synchronous predicate that determines whether the built-in `minifyJS` may
30
+ * process a given piece of JavaScript—`inline` is true for event handler
31
+ * attributes. Returning false leaves that JavaScript unminified (`mergeScripts`
32
+ * still applies).
33
+ *
34
+ * Default: `null` (all JavaScript is minified)
35
+ */
36
+ canMinifyJS?: ((text: string, inline?: boolean) => boolean) | null;
37
+ /**
38
+ * Synchronous predicate that determines whether the built-in `minifySVG` may
39
+ * pass a given outermost `svg` element, nested ones included, to SVGO. It
40
+ * receives the element as serialized by the HTML pass (e.g., without comments
41
+ * under `removeComments`); returning false leaves it as that pass wrote it.
42
+ *
43
+ * Default: `null` (all SVG is minified)
44
+ */
45
+ canMinifySVG?: ((text: string) => boolean) | null;
46
+ /**
47
+ * Predicate that determines whether whitespace inside the element may be
48
+ * trimmed; where not, it stays as written, as in `pre`.
49
+ *
50
+ * Default: Built-in `canTrimWhitespace` function
51
+ */
52
+ canTrimWhitespace?: (tag: string | null, attrs: HTMLAttribute[] | undefined, canTrimWhitespace: (tag: string) => boolean) => boolean;
53
+ /**
54
+ * The maximum number of entries for the CSS minification cache. Higher values
55
+ * improve performance for inputs with repeated CSS (e.g., batch processing).
56
+ * - Cache is created on first `minify()` call and persists for the process lifetime
57
+ * - Cache size is locked after first call—subsequent calls reuse the same cache
58
+ * - `0` switches the cache off; negative and non-finite values fall back to the default size
59
+ *
60
+ * Default: `500`
61
+ */
62
+ cacheCSS?: number;
63
+ /**
64
+ * The maximum number of entries for the JavaScript minification cache. Higher
65
+ * values improve performance for inputs with repeated JavaScript.
66
+ * - Cache is created on first `minify()` call and persists for the process lifetime
67
+ * - Cache size is locked after first call—subsequent calls reuse the same cache
68
+ * - `0` switches the cache off; negative and non-finite values fall back to the default size
69
+ *
70
+ * Default: `500`
71
+ */
72
+ cacheJS?: number;
73
+ /**
74
+ * The maximum number of entries for the SVG minification cache. Higher
75
+ * values improve performance for inputs with repeated SVG content.
76
+ * - Cache is created on first `minify()` call and persists for the process lifetime
77
+ * - Cache size is locked after first call—subsequent calls reuse the same cache
78
+ * - `0` switches the cache off; negative and non-finite values fall back to the default size
79
+ *
80
+ * Default: `500`
81
+ */
82
+ cacheSVG?: number;
83
+ /**
84
+ * When true, tag and attribute names are written as in the source rather than in lowercase.
85
+ * Useful for framework components like `<MyButton>`. HTML names are still read in any case,
86
+ * so every option applies to them as without it; hooks get names as written.
87
+ *
88
+ * Default: `false`
89
+ */
90
+ caseSensitive?: boolean;
91
+ /**
92
+ * Collapse multiple whitespace characters within attribute values into a
93
+ * single space. Also trims leading and trailing whitespace from attribute
94
+ * values. Applied as an early normalization step before special attribute
95
+ * handlers (CSS minification, class sorting, etc.) run.
96
+ *
97
+ * Default: `false`
98
+ */
99
+ collapseAttributeWhitespace?: boolean;
100
+ /**
101
+ * Collapse boolean attributes to their name only (for example
102
+ * `disabled="disabled"` → `disabled`).
103
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes
104
+ *
105
+ * Default: `false`
106
+ */
107
+ collapseBooleanAttributes?: boolean;
108
+ /**
109
+ * Collapse attributes with empty values to their name only (for example
110
+ * `alt=""` → `alt`), which the HTML parser reads the same way.
111
+ *
112
+ * Default: `false`
113
+ */
114
+ collapseEmptyAttributes?: boolean;
115
+ /**
116
+ * When false (default) whitespace around `inline` tags is preserved in
117
+ * more cases. When true, whitespace between inline tags may be collapsed,
118
+ * except around text-level elements (like `a`, `code`, or `em`); whitespace
119
+ * next to text is kept as without the option.
120
+ * Must also enable `collapseWhitespace` to have effect.
121
+ *
122
+ * Default: `false`
123
+ */
124
+ collapseInlineTagWhitespace?: boolean;
125
+ /**
126
+ * Remove whitespace next to a no-break space (`U+00A0`), narrow no-break
127
+ * space (`U+202F`), or figure space (`U+2007`) in text (for example
128
+ * `a &nbsp; b` → `a&nbsp;b`), which changes how the text renders. Runs of
129
+ * no-break spaces are kept.
130
+ * Must also enable `collapseWhitespace` to have effect.
131
+ *
132
+ * Default: `false`
133
+ */
134
+ collapseNoBreakSpaces?: boolean;
135
+ /**
136
+ * Collapse multiple whitespace characters into one where allowed. Also
137
+ * controls trimming behaviour in several code paths.
138
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
139
+ *
140
+ * Default: `false`
141
+ */
142
+ collapseWhitespace?: boolean;
143
+ /**
144
+ * If true, be conservative when collapsing whitespace (preserve more
145
+ * whitespace in edge cases). Affects collapse algorithms.
146
+ * Must also enable `collapseWhitespace` to have effect.
147
+ *
148
+ * Default: `false`
149
+ */
150
+ conservativeCollapse?: boolean;
151
+ /**
152
+ * When set to `false`, minification errors may throw.
153
+ * By default, the minifier will attempt to recover from minification
154
+ * errors, or ignore them and preserve the original content.
155
+ *
156
+ * Default: `true`
157
+ */
158
+ continueOnMinifyError?: boolean;
159
+ /**
160
+ * When true, the parser will attempt to continue on recoverable parse
161
+ * errors. Otherwise, parsing errors may throw.
162
+ *
163
+ * Default: `false`
164
+ */
165
+ continueOnParseError?: boolean;
166
+ /**
167
+ * Array of regexes used to recognise custom attribute assignment
168
+ * operators (e.g., `'<div flex?="{{mode != cover}}"></div>'`).
169
+ * These are concatenated with the built-in assignment patterns.
170
+ *
171
+ * Default: `[]`
172
+ */
173
+ customAttrAssign?: RegExp[];
174
+ /**
175
+ * Regex matching attribute names whose values should be collapsed.
176
+ * Basically used to remove newlines and excess spaces inside attribute values,
177
+ * e.g., `/ng-class/`.
178
+ */
179
+ customAttrCollapse?: RegExp;
180
+ /**
181
+ * Array of `[openRegExp, closeRegExp]` pairs used by the parser to
182
+ * detect custom attribute surround patterns (for non-standard syntaxes,
183
+ * e.g., `<input {{#if value}}checked="checked"{{/if}}>`).
184
+ */
185
+ customAttrSurround?: [RegExp, RegExp][];
186
+ /**
187
+ * Array of regexes used to detect event handler attributes for `minifyJS`
188
+ * (e.g., `ng-click`). The default matches standard `on…` event attributes.
189
+ *
190
+ * Default: `[/^on[a-z]{3,}$/]`
191
+ */
192
+ customEventAttributes?: RegExp[];
193
+ /**
194
+ * Rejects `ignoreCustomFragments` patterns that risk catastrophic backtracking,
195
+ * rather than warning about them: those that compound quantifiers or alternation
196
+ * (`(a+)+`, `(a|b)*`), those that repeat the same unbounded atom twice in a row
197
+ * (`.*.*`), and those too long or too deeply nested to analyze at all.
198
+ *
199
+ * Default: `false`
200
+ */
201
+ strictCustomFragments?: boolean;
202
+ /**
203
+ * When true, decodes HTML entities in text and attributes before
204
+ * processing, and re-encodes ambiguous ampersands when outputting.
205
+ *
206
+ * Default: `false`
207
+ */
208
+ decodeEntities?: boolean;
209
+ /**
210
+ * Comments matching any pattern in this array of regexes will be
211
+ * preserved when `removeComments` is enabled. The default preserves
212
+ * “bang” comments and comments starting with `#`.
213
+ *
214
+ * Default: `[/^!/, /^\s*#/]`
215
+ */
216
+ ignoreCustomComments?: RegExp[];
217
+ /**
218
+ * Array of regexes used to identify fragments that should be
219
+ * preserved (for example server templates). These fragments are temporarily
220
+ * replaced during minification to avoid corrupting template code.
221
+ * The default preserves ASP/PHP-style tags and XML declarations.
222
+ *
223
+ * Default: `[/<%[\s\S]*?%>/, /<\?(?:php[\t\n\r ]|=|\$|xml(?:-stylesheet)?(?![\w-])|\s)[\s\S]*?\?>/i]`
224
+ */
225
+ ignoreCustomFragments?: RegExp[];
226
+ /**
227
+ * If false, tags marked as auto-generated by the parser will be omitted
228
+ * from output. Useful to skip injected tags.
229
+ *
230
+ * Default: `false`
231
+ */
232
+ includeAutoGeneratedTags?: boolean;
233
+ /**
234
+ * Collection of custom element tag names that should be treated as inline
235
+ * elements for white-space handling, alongside the built-in inline elements.
236
+ *
237
+ * Default: `[]`
238
+ */
239
+ inlineCustomElements?: ArrayLike<string>;
240
+ /**
241
+ * Keep the trailing slash on void elements and other start tags that carry one, and read it
242
+ * as closing the element. The default drops the slash and ignores it, as HTML does; in SVG
243
+ * and MathML a slash closes the element either way.
244
+ *
245
+ * Default: `false`
246
+ */
247
+ keepClosingSlash?: boolean;
248
+ /**
249
+ * Logging function used by the minifier for warnings/errors/info.
250
+ * You can directly provide `console.log`, but `message` may also be an `Error`
251
+ * object or other non-string value.
252
+ *
253
+ * Default: `() => {}` (no-op function)
254
+ */
255
+ log?: (message: unknown) => void;
256
+ /**
257
+ * The maximum allowed input length. Used as a guard against ReDoS via
258
+ * pathological inputs. If the input exceeds this length an error is
259
+ * thrown.
260
+ *
261
+ * Default: No limit
262
+ */
263
+ maxInputLength?: number;
264
+ /**
265
+ * Maximum line length for the output. When set the minifier will wrap
266
+ * output to the given number of characters where possible, splitting
267
+ * lines only in tags—between attributes or before a tag’s `>`.
268
+ *
269
+ * Default: No limit
270
+ */
271
+ maxLineLength?: number;
272
+ /**
273
+ * When true, consecutive inline `<script>` elements are merged into one.
274
+ * Only merges compatible scripts (same `type`, matching `async`/`defer`/
275
+ * `nomodule`/`nonce` attributes). Does not merge external scripts (with `src`).
276
+ *
277
+ * Default: `false`
278
+ */
279
+ mergeScripts?: boolean;
280
+ /**
281
+ * When true, enables CSS minification for inline `<style>` tags or
282
+ * `style` attributes. If an object is provided, it is passed to
283
+ * [Lightning CSS](https://www.npmjs.com/package/lightningcss)
284
+ * as transform options. If a function is provided, it will be used to perform
285
+ * custom CSS minification. If disabled, CSS is not minified.
286
+ *
287
+ * Default: `false`
288
+ */
289
+ minifyCSS?: boolean | Partial<import("lightningcss").TransformOptions<import("lightningcss").CustomAtRules>> | ((text: string, type?: string) => Promise<string> | string);
290
+ /**
291
+ * When true, enables JS minification for `<script>` contents and
292
+ * event handler attributes. If an object is provided, it can include:
293
+ * - `engine`: The minifier to use (`terser` or `swc`). Default: `terser`.
294
+ * - Engine-specific options (e.g., Terser options if `engine: 'terser'`,
295
+ * SWC options if `engine: 'swc'`).
296
+ * If a function is provided, it will be used to perform
297
+ * custom JS minification. If disabled, JS is not minified.
298
+ *
299
+ * Default: `false`
300
+ */
301
+ minifyJS?: boolean | import("terser").MinifyOptions | {
302
+ engine?: 'terser' | 'swc';
303
+ [key: string]: any;
304
+ } | ((text: string, inline?: boolean) => Promise<string> | string);
305
+ /**
306
+ * When true, removes whitespace from the content of JSON `<script>` types
307
+ * (e.g., `application/ld+json`, `importmap`, `speculationrules`), leaving
308
+ * values as written. Malformed JSON is left as is.
309
+ *
310
+ * Default: `false`
311
+ */
312
+ minifyJSON?: boolean;
313
+ /**
314
+ * When true, enables URL rewriting/minification. If an object is provided,
315
+ * the `site` property sets the base URL for computing relative paths.
316
+ * If a string is provided, it is treated as an `{ site: string }` options
317
+ * object. If a function is provided, it will be used to perform custom URL
318
+ * minification. If disabled, URLs are not minified.
319
+ *
320
+ * Default: `false`
321
+ */
322
+ minifyURLs?: boolean | string | {
323
+ site?: string;
324
+ } | ((text: string) => Promise<string> | string);
325
+ /**
326
+ * When true, enables SVG minification using [SVGO](https://github.com/svg/svgo).
327
+ * Complete SVG subtrees are extracted and optimized as a block, with the SVGO
328
+ * plugins that assume a standalone SVG file turned off.
329
+ * If an object is provided, it is passed to SVGO as configuration options; unless
330
+ * it sets `plugins`, it keeps that plugin set.
331
+ * If disabled, SVG content is minified using standard HTML rules only.
332
+ *
333
+ * Default: `false`
334
+ */
335
+ minifySVG?: boolean | Object;
336
+ /**
337
+ * When wrapping lines, never split a line in an end tag (e.g., keeps
338
+ * `</a>` from becoming `</a` and `>` on two lines).
339
+ *
340
+ * Default: `false`
341
+ */
342
+ noNewlinesBeforeTagClose?: boolean;
343
+ /**
344
+ * When true, treat input as a partial HTML fragment rather than a complete
345
+ * document. This preserves stray end tags (closing tags without corresponding
346
+ * opening tags) and prevents auto-closing of unclosed tags at the end of input.
347
+ * Useful for minifying template fragments, SSI includes, or other partial HTML
348
+ * that will be combined with other fragments.
349
+ *
350
+ * Default: `false`
351
+ */
352
+ partialMarkup?: boolean;
353
+ /**
354
+ * Preserve a single line break at the start/end of text nodes when
355
+ * collapsing/trimming whitespace.
356
+ * Must also enable `collapseWhitespace` to have effect.
357
+ *
358
+ * Default: `false`
359
+ */
360
+ preserveLineBreaks?: boolean;
361
+ /**
362
+ * Name of a preset configuration to use as a base (`conservative` or
363
+ * `comprehensive`). Explicitly provided options take precedence over
364
+ * preset values. Unknown preset names are ignored (with a warning).
365
+ *
366
+ * Default: No preset
367
+ */
368
+ preset?: string;
369
+ /**
370
+ * When true, attribute values will not be HTML-escaped (dangerous for
371
+ * untrusted input). By default, attributes are escaped.
372
+ *
373
+ * Default: `false`
374
+ */
375
+ preventAttributesEscaping?: boolean;
376
+ /**
377
+ * Array of `type` attribute values for `<script>` elements whose contents
378
+ * should be processed as HTML
379
+ * (e.g., `text/ng-template`, `text/x-handlebars-template`, etc.).
380
+ * When present, the contents of matching script tags are recursively minified,
381
+ * like normal HTML content.
382
+ *
383
+ * Default: `[]`
384
+ */
385
+ processScripts?: string[];
386
+ /**
387
+ * Preferred quote character for attribute values. If unspecified the
388
+ * minifier picks the safest quote based on the attribute value.
389
+ *
390
+ * Default: Auto-detected
391
+ */
392
+ quoteCharacter?: "\"" | "'";
393
+ /**
394
+ * Remove quotes around attribute values where it is safe to do so.
395
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes
396
+ *
397
+ * Default: `false`
398
+ */
399
+ removeAttributeQuotes?: boolean;
400
+ /**
401
+ * Remove HTML comments. Comments that match `ignoreCustomComments` will
402
+ * still be preserved.
403
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_comments
404
+ *
405
+ * Default: `false`
406
+ */
407
+ removeComments?: boolean;
408
+ /**
409
+ * Remove default `type` attributes from `<style>`/`<link>` (e.g., `type="text/css"`)
410
+ * and `<script>` (e.g., `type="text/javascript"`) elements.
411
+ *
412
+ * Default: `false`
413
+ */
414
+ removeDefaultTypeAttributes?: boolean;
415
+ /**
416
+ * If true, removes attributes whose values are empty (some attributes
417
+ * are excluded by name). Can also be a function to customise which empty
418
+ * attributes are removed.
419
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes
420
+ *
421
+ * Default: `false`
422
+ */
423
+ removeEmptyAttributes?: boolean | ((attrName: string, tag: string) => boolean);
424
+ /**
425
+ * Remove elements that are empty and safe to remove (for example
426
+ * `<script />` without `src`), including elements left empty that way.
427
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements
428
+ *
429
+ * Default: `false`
430
+ */
431
+ removeEmptyElements?: boolean;
432
+ /**
433
+ * Specifies empty elements to preserve when `removeEmptyElements` is enabled.
434
+ * Has no effect unless `removeEmptyElements: true`.
435
+ *
436
+ * Accepts tag names or HTML-like element specifications:
437
+ *
438
+ * * Tag name only: `["td", "span"]`—preserves all empty elements of these types
439
+ * * With valued attributes: `["<i class='test'>"]`—preserves only when attribute values match
440
+ * * With boolean attributes: `["<input disabled>"]`—preserves only when the
441
+ * boolean attribute is present
442
+ * * Mixed: `["<button type='button' disabled>"]`—all specified attributes must match
443
+ *
444
+ * Attribute matching:
445
+ *
446
+ * * All specified attributes must be present and match (valued attributes must have exact values)
447
+ * * Additional attributes on the element are allowed
448
+ * * Element and attribute names match in any case
449
+ * * Supports double quotes, single quotes, and unquoted attribute values in specifications
450
+ *
451
+ * Limitations:
452
+ *
453
+ * * Self-closing syntax (e.g., `["<span/>"]`) is not supported; use `["span"]` instead
454
+ * * Definitions containing `>` within quoted attribute values (e.g.,
455
+ * `["<span title='a>b'>"]`) are not supported
456
+ *
457
+ * Default: `[]`
458
+ */
459
+ removeEmptyElementsExcept?: string[];
460
+ /**
461
+ * Drop optional start/end tags where the HTML specification permits it
462
+ * (for example `</li>`, optional `<html>` etc.).
463
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags
464
+ *
465
+ * Default: `false`
466
+ */
467
+ removeOptionalTags?: boolean;
468
+ /**
469
+ * Remove attributes that are redundant because they match the element’s
470
+ * default values (for example `<button type="submit">`) or have no effect
471
+ * (for example `xml:lang`), along with `meta` elements and `rel` keywords
472
+ * that have no effect.
473
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes
474
+ *
475
+ * Default: `false`
476
+ */
477
+ removeRedundantAttributes?: boolean;
478
+ /**
479
+ * **Note that this will result in invalid HTML!**
480
+ *
481
+ * When true, extra whitespace between tag name and attributes (or before
482
+ * the closing bracket) will be removed where possible. Affects output spacing
483
+ * such as the space used in the short doctype representation.
484
+ *
485
+ * Default: `false`
486
+ */
487
+ removeTagWhitespace?: boolean;
488
+ /**
489
+ * Remove selectors from `style` elements that name an element, class, or ID the
490
+ * document doesn’t reference, as well as rules that are left without selectors.
491
+ * Requires `minifyCSS` (removal runs through Lightning CSS) and has no effect on
492
+ * `style` or `media` attributes.
493
+ *
494
+ * Element, class, and ID names are collected from the markup and—unless `scripts`
495
+ * is set to `false`—from inline `script` elements; class names and IDs also from
496
+ * `data-*` attributes. Names that only ever appear in external scripts cannot
497
+ * be detected; list those under `safelist` (strings or regular expressions) to
498
+ * keep them.
499
+ *
500
+ * Default: `false`
501
+ */
502
+ removeUnusedCSS?: boolean | {
503
+ safelist?: Array<string | RegExp>;
504
+ scripts?: boolean;
505
+ };
506
+ /**
507
+ * When true, writes empty SVG and MathML elements as self-closing tags (for
508
+ * example `<path d="…"/>` for `<path d="…"></path>`), which HTML reads as the
509
+ * same element in foreign content; HTML elements, including those in
510
+ * `foreignObject` and `annotation-xml`, keep their end tags.
511
+ *
512
+ * Default: `false`
513
+ */
514
+ selfCloseForeignElements?: boolean;
515
+ /**
516
+ * When true, enables sorting of attributes. If a function is provided it
517
+ * will be used as a custom attribute sorter, which should mutate `attrs`
518
+ * in-place to the desired order. If disabled, the minifier will attempt to
519
+ * preserve the order from the input.
520
+ *
521
+ * Default: `false`
522
+ */
523
+ sortAttributes?: boolean | ((tag: string, attrs: HTMLAttribute[]) => void);
524
+ /**
525
+ * When true, enables sorting of class names inside `class` attributes.
526
+ * If a function is provided, it will be used to transform/sort the class
527
+ * name string. If disabled, the minifier will attempt to preserve the
528
+ * class-name order from the input.
529
+ *
530
+ * Default: `false`
531
+ */
532
+ sortClassNames?: boolean | ((value: string) => string);
533
+ /**
534
+ * When true, whitespace around ignored custom fragments is removed rather
535
+ * than collapsed where the minifier removes whitespace anyway (e.g., between
536
+ * block-level elements). Whitespace in tags, attribute values, CSS, and
537
+ * JavaScript is kept.
538
+ *
539
+ * Default: `false`
540
+ */
541
+ trimCustomFragments?: boolean;
542
+ /**
543
+ * Replace the HTML doctype with the short `<!doctype html>` form.
544
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype
545
+ *
546
+ * Default: `false`
547
+ */
548
+ useShortDoctype?: boolean;
549
+ };
550
+ export type CacheStats = {
551
+ /**
552
+ * Number of lookups attempted against the cache.
553
+ */
554
+ gets: number;
555
+ /**
556
+ * Number of lookups that found a cached entry.
557
+ */
558
+ hits: number;
559
+ /**
560
+ * Number of entries currently held in the cache.
561
+ */
562
+ size: number;
563
+ /**
564
+ * Maximum number of entries the cache can hold.
565
+ */
566
+ limit: number;
567
+ };
568
+ /**
569
+ * Get hit/miss statistics for the CSS, JavaScript, and SVG minification caches.
570
+ *
571
+ * Each cache is created lazily on the first `minify()` call (see `initCaches`); before
572
+ * that first call, or for a cache never exercised (e.g., `minifyCSS` disabled), its
573
+ * entry reports all-zero stats.
574
+ *
575
+ * @returns {{ css: CacheStats, js: CacheStats, svg: CacheStats }}
576
+ */
577
+ export declare function getCacheStats(): {
578
+ css: CacheStats;
579
+ js: CacheStats;
580
+ svg: CacheStats;
581
+ };
582
+ /**
583
+ * @param {string} value
584
+ * @param {MinifierOptions} [options]
585
+ * @returns {Promise<string>}
586
+ */
587
+ export declare const minify: (value: string, options?: MinifierOptions) => Promise<string>;
588
+ export { presets, getPreset, getPresetNames };
589
+ declare const _default: {
590
+ minify: typeof minify;
591
+ presets: {
592
+ conservative: {
593
+ caseSensitive: boolean;
594
+ collapseBooleanAttributes: boolean;
595
+ collapseWhitespace: boolean;
596
+ conservativeCollapse: boolean;
597
+ preserveLineBreaks: boolean;
598
+ removeComments: boolean;
599
+ removeDefaultTypeAttributes: boolean;
600
+ useShortDoctype: boolean;
601
+ };
602
+ comprehensive: {
603
+ collapseAttributeWhitespace: boolean;
604
+ collapseBooleanAttributes: boolean;
605
+ collapseEmptyAttributes: boolean;
606
+ collapseWhitespace: boolean;
607
+ decodeEntities: boolean;
608
+ mergeScripts: boolean;
609
+ minifyCSS: boolean;
610
+ minifyJS: boolean;
611
+ minifyJSON: boolean;
612
+ minifySVG: boolean;
613
+ minifyURLs: boolean;
614
+ removeAttributeQuotes: boolean;
615
+ removeComments: boolean;
616
+ removeDefaultTypeAttributes: boolean;
617
+ removeEmptyAttributes: boolean;
618
+ removeOptionalTags: boolean;
619
+ removeRedundantAttributes: boolean;
620
+ selfCloseForeignElements: boolean;
621
+ useShortDoctype: boolean;
622
+ };
623
+ };
624
+ getPreset: typeof getPreset;
625
+ getPresetNames: typeof getPresetNames;
626
+ getCacheStats: typeof getCacheStats;
627
+ };
628
+ export default _default;
629
+ //# sourceMappingURL=htmlminifier.d.ts.map
@@ -0,0 +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;AAmF/D,YAAkB,aAAa,GAI/B;IAAe,IAAI,EAAZ,MAAM,CACb;IAAgB,KAAK,AAArB,CACA,EADO,MAAM,CACb;IAAgB,KAAK,AAArB,CACA,EADO,MAAM,CACb;IAAgB,YAAY,AAA5B,CACA,EADO,MAAM,CACb;IAAgB,UAAU,AAA1B,CACA,EADO,MAAM,CACb;IAAgB,WAAW,AAA3B,CAA4B,EAArB,MAAM,CAAe;CAAA,CAAA;AAI5B,YAAkB,eAAe,GAIjC;;;;;;;IAA2G,qBAAqB,AAAhI,CAMA,EANO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,qBAAqB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,KAAK,OAAO,CAMxG;;;;;;;;;;IAAuE,YAAY,AAAnF,CASA,EATO,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,G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MAAM,MAAM,UAJR,MAAM,YACN,eAAe,KACb,OAAO,CAAC,MAAM,CAyE1B,CAAC;AAEF,OAAO,EACL,OAAO,EACP,SAAS,EACT,cAAc,EACf,CAAC"}
@@ -0,0 +1,28 @@
1
+ export type HTMLParserHandler = {
2
+ start?: Function;
3
+ end?: Function;
4
+ chars?: Function;
5
+ comment?: Function;
6
+ processingInstruction?: Function;
7
+ doctype?: Function;
8
+ strayEnd?: Function;
9
+ parseError?: Function | undefined;
10
+ continueOnParseError?: boolean | undefined;
11
+ partialMarkup?: boolean | undefined;
12
+ noQuirksMode?: boolean | undefined;
13
+ wantsNextTag?: boolean | undefined;
14
+ selfClosingSlash?: boolean | undefined;
15
+ customAttrSurround?: RegExp[][] | undefined;
16
+ customAttrAssign?: RegExp[] | undefined;
17
+ };
18
+ export declare class HTMLParser {
19
+ html: string;
20
+ handler: HTMLParserHandler;
21
+ /**
22
+ * @param {string} html
23
+ * @param {HTMLParserHandler} handler
24
+ */
25
+ constructor(html: string, handler: HTMLParserHandler);
26
+ parse(): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=htmlparser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"htmlparser.d.ts","sourceRoot":"","sources":["../../src/htmlparser.js"],"names":[],"mappings":"AAmBG,YAgBG,iBAAiB,GAhBV;IACR,KAAK,CAAC,WAAW;IACjB,GAAG,CAAC,WAAW;IACf,KAAK,CAAC,WAAW;IACjB,OAAO,CAAC,WAAW;IACnB,qBAAqB,CAAC,WAAW;IACjC,OAAO,CAAC,WAAW;IACnB,QAAQ,CAAC,WAAW;IACpB,UAAU,CAAC,EAAE,WAAW,SAAS,CAAC;IAClC,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,SAAS,CAAC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CACxC,CAAmB;AAuOvB,qBAAa,UAAU;IAMd,IAAI;IACJ,OAAO;IANd;;;OAGG;IACH,YAAY,IAAI,EAHL,MAGK,EAAE,OAAO,EAFd,iBAEc,EAGxB;IAEK,KAAK,kBAw+BV;CACF"}