html-minifier-next 4.0.2 → 4.1.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.
@@ -41023,6 +41023,11 @@ function joinResultSegments(results, options, restoreCustom, restoreIgnore) {
41023
41023
  return options.collapseWhitespace ? collapseWhitespace(str, options, true, true) : str;
41024
41024
  }
41025
41025
 
41026
+ /**
41027
+ * @param {string} value
41028
+ * @param {MinifierOptions} [options]
41029
+ * @returns {Promise<string>}
41030
+ */
41026
41031
  const minify = async function (value, options) {
41027
41032
  const start = Date.now();
41028
41033
  options = processOptions(options || {});
@@ -41033,4 +41038,335 @@ const minify = async function (value, options) {
41033
41038
 
41034
41039
  var htmlminifier = { minify };
41035
41040
 
41041
+ /**
41042
+ * @typedef {Object} HTMLAttribute
41043
+ * Representation of an attribute from the HTML parser.
41044
+ *
41045
+ * @prop {string} name
41046
+ * @prop {string} [value]
41047
+ * @prop {string} [quote]
41048
+ * @prop {string} [customAssign]
41049
+ * @prop {string} [customOpen]
41050
+ * @prop {string} [customClose]
41051
+ */
41052
+
41053
+ /**
41054
+ * @typedef {Object} MinifierOptions
41055
+ * Options that control how HTML is minified. All of these are optional
41056
+ * and usually default to a disabled/safe value unless noted.
41057
+ *
41058
+ * @prop {(tag: string, attrs: HTMLAttribute[], canCollapseWhitespace: (tag: string) => boolean) => boolean} [canCollapseWhitespace]
41059
+ * Predicate that determines whether whitespace inside a given element
41060
+ * can be collapsed.
41061
+ *
41062
+ * Default: Built-in `canCollapseWhitespace` function
41063
+ *
41064
+ * @prop {(tag: string | null, attrs: HTMLAttribute[] | undefined, canTrimWhitespace: (tag: string) => boolean) => boolean} [canTrimWhitespace]
41065
+ * Predicate that determines whether leading/trailing whitespace around
41066
+ * the element may be trimmed.
41067
+ *
41068
+ * Default: Built-in `canTrimWhitespace` function
41069
+ *
41070
+ * @prop {boolean} [caseSensitive]
41071
+ * When true, tag and attribute names are treated as case-sensitive.
41072
+ * Useful for custom HTML tags.
41073
+ * If false (default) names are lower-cased via the `name` function.
41074
+ *
41075
+ * Default: `false`
41076
+ *
41077
+ * @prop {boolean} [collapseBooleanAttributes]
41078
+ * Collapse boolean attributes to their name only (for example
41079
+ * `disabled="disabled"` -> `disabled`).
41080
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes
41081
+ *
41082
+ * Default: `false`
41083
+ *
41084
+ * @prop {boolean} [collapseInlineTagWhitespace]
41085
+ * When false (default) whitespace around `inline` tags is preserved in
41086
+ * more cases. When true, whitespace around inline tags may be collapsed.
41087
+ * Must also enable `collapseWhitespace` to have effect.
41088
+ *
41089
+ * Default: `false`
41090
+ *
41091
+ * @prop {boolean} [collapseWhitespace]
41092
+ * Collapse multiple whitespace characters into one where allowed. Also
41093
+ * controls trimming behaviour in several code paths.
41094
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
41095
+ *
41096
+ * Default: `false`
41097
+ *
41098
+ * @prop {boolean} [conservativeCollapse]
41099
+ * If true, be conservative when collapsing whitespace (preserve more
41100
+ * whitespace in edge cases). Affects collapse algorithms.
41101
+ * Must also enable `collapseWhitespace` to have effect.
41102
+ *
41103
+ * Default: `false`
41104
+ *
41105
+ * @prop {boolean} [continueOnParseError]
41106
+ * When true, the parser will attempt to continue on recoverable parse
41107
+ * errors. Otherwise, parsing errors may throw.
41108
+ *
41109
+ * Default: `false`
41110
+ *
41111
+ * @prop {RegExp[]} [customAttrAssign]
41112
+ * Array of regexes used to recognise custom attribute assignment
41113
+ * operators (e.g. `'<div flex?="{{mode != cover}}"></div>'`).
41114
+ * These are concatenated with the built-in assignment patterns.
41115
+ *
41116
+ * Default: `[]`
41117
+ *
41118
+ * @prop {RegExp} [customAttrCollapse]
41119
+ * Regex matching attribute names whose values should be collapsed.
41120
+ * Basically used to remove newlines and excess spaces inside attribute values,
41121
+ * e.g. `/ng-class/`.
41122
+ *
41123
+ * @prop {[RegExp, RegExp][]} [customAttrSurround]
41124
+ * Array of `[openRegExp, closeRegExp]` pairs used by the parser to
41125
+ * detect custom attribute surround patterns (for non-standard syntaxes,
41126
+ * e.g. `<input {{#if value}}checked="checked"{{/if}}>`).
41127
+ *
41128
+ * @prop {RegExp[]} [customEventAttributes]
41129
+ * Array of regexes used to detect event handler attributes for `minifyJS`
41130
+ * (e.g. `ng-click`). The default matches standard `on…` event attributes.
41131
+ *
41132
+ * Default: `[/^on[a-z]{3,}$/]`
41133
+ *
41134
+ * @prop {number} [customFragmentQuantifierLimit]
41135
+ * Limits the quantifier used when building a safe regex for custom
41136
+ * fragments to avoid ReDoS. See source use for details.
41137
+ *
41138
+ * Default: `200`
41139
+ *
41140
+ * @prop {boolean} [decodeEntities]
41141
+ * When true, decodes HTML entities in text and attributes before
41142
+ * processing, and re-encodes ambiguous ampersands when outputting.
41143
+ *
41144
+ * Default: `false`
41145
+ *
41146
+ * @prop {boolean} [html5]
41147
+ * Parse and emit using HTML5 rules. Set to `false` to use non-HTML5
41148
+ * parsing behavior.
41149
+ *
41150
+ * Default: `true`
41151
+ *
41152
+ * @prop {RegExp[]} [ignoreCustomComments]
41153
+ * Comments matching any pattern in this array of regexes will be
41154
+ * preserved when `removeComments` is enabled. The default preserves
41155
+ * “bang” comments and comments starting with `#`.
41156
+ *
41157
+ * Default: `[/^!/, /^\s*#/]`
41158
+ *
41159
+ * @prop {RegExp[]} [ignoreCustomFragments]
41160
+ * Array of regexes used to identify fragments that should be
41161
+ * preserved (for example server templates). These fragments are temporarily
41162
+ * replaced during minification to avoid corrupting template code.
41163
+ * The default preserves ASP/PHP-style tags.
41164
+ *
41165
+ * Default: `[/<%[\s\S]*?%>/, /<\?[\s\S]*?\?>/]`
41166
+ *
41167
+ * @prop {boolean} [includeAutoGeneratedTags]
41168
+ * If false, tags marked as auto-generated by the parser will be omitted
41169
+ * from output. Useful to skip injected tags.
41170
+ *
41171
+ * Default: `true`
41172
+ *
41173
+ * @prop {ArrayLike<string>} [inlineCustomElements]
41174
+ * Collection of custom element tag names that should be treated as inline
41175
+ * elements for white-space handling, alongside the built-in inline elements.
41176
+ *
41177
+ * Default: `[]`
41178
+ *
41179
+ * @prop {boolean} [keepClosingSlash]
41180
+ * Preserve the trailing slash in self-closing tags when present.
41181
+ *
41182
+ * Default: `false`
41183
+ *
41184
+ * @prop {(message: unknown) => void} [log]
41185
+ * Logging function used by the minifier for warnings/errors/info.
41186
+ * You can directly provide `console.log`, but `message` may also be an `Error`
41187
+ * object or other non-string value.
41188
+ *
41189
+ * Default: `() => {}` (no-op function)
41190
+ *
41191
+ * @prop {number} [maxInputLength]
41192
+ * The maximum allowed input length. Used as a guard against ReDoS via
41193
+ * pathological inputs. If the input exceeds this length an error is
41194
+ * thrown.
41195
+ *
41196
+ * Default: No limit
41197
+ *
41198
+ * @prop {number} [maxLineLength]
41199
+ * Maximum line length for the output. When set the minifier will wrap
41200
+ * output to the given number of characters where possible.
41201
+ *
41202
+ * Default: No limit
41203
+ *
41204
+ * @prop {boolean | import("lightningcss").TransformOptions<import("lightningcss").CustomAtRules> | ((text: string, type?: string) => Promise<string> | string)} [minifyCSS]
41205
+ * When true, enables CSS minification for inline `<style>` tags or
41206
+ * `style` attributes. If an object is provided, it is passed to
41207
+ * [Lightning CSS](https://www.npmjs.com/package/lightningcss)
41208
+ * as transform options. If a function is provided, it will be used to perform
41209
+ * custom CSS minification. If disabled, CSS is not minified.
41210
+ *
41211
+ * Default: `false`
41212
+ *
41213
+ * @prop {boolean | import("terser").MinifyOptions | ((text: string, inline?: boolean) => Promise<string> | string)} [minifyJS]
41214
+ * When true, enables JS minification for `<script>` contents and
41215
+ * event handler attributes. If an object is provided, it is passed to
41216
+ * [terser](https://www.npmjs.com/package/terser) as minify options.
41217
+ * If a function is provided, it will be used to perform
41218
+ * custom JS minification. If disabled, JS is not minified.
41219
+ *
41220
+ * Default: `false`
41221
+ *
41222
+ * @prop {boolean | string | import("relateurl").Options | ((text: string) => Promise<string> | string)} [minifyURLs]
41223
+ * When true, enables URL rewriting/minification. If an object is provided,
41224
+ * it is passed to [relateurl](https://www.npmjs.com/package/relateurl)
41225
+ * as options. If a string is provided, it is treated as an `{ site: string }`
41226
+ * options object. If a function is provided, it will be used to perform
41227
+ * custom URL minification. If disabled, URLs are not minified.
41228
+ *
41229
+ * Default: `false`
41230
+ *
41231
+ * @prop {(name: string) => string} [name]
41232
+ * Function used to normalise tag/attribute names. By default, this lowercases
41233
+ * names, unless `caseSensitive` is enabled.
41234
+ *
41235
+ * Default: `(name) => name.toLowerCase()`,
41236
+ * or `(name) => name` (no-op function) if `caseSensitive` is enabled.
41237
+ *
41238
+ * @prop {boolean} [noNewlinesBeforeTagClose]
41239
+ * When wrapping lines, prevent inserting a newline directly before a
41240
+ * closing tag (useful to keep tags like `</a>` on the same line).
41241
+ *
41242
+ * Default: `false`
41243
+ *
41244
+ * @prop {boolean} [preserveLineBreaks]
41245
+ * Preserve a single line break at the start/end of text nodes when
41246
+ * collapsing/trimming whitespace.
41247
+ * Must also enable `collapseWhitespace` to have effect.
41248
+ *
41249
+ * Default: `false`
41250
+ *
41251
+ * @prop {boolean} [preventAttributesEscaping]
41252
+ * When true, attribute values will not be HTML-escaped (dangerous for
41253
+ * untrusted input). By default, attributes are escaped.
41254
+ *
41255
+ * Default: `false`
41256
+ *
41257
+ * @prop {boolean} [processConditionalComments]
41258
+ * When true, conditional comments (for example `<!--[if IE]> … <![endif]-->`)
41259
+ * will have their inner content processed by the minifier.
41260
+ * Useful to minify HTML that appears inside conditional comments.
41261
+ *
41262
+ * Default: `false`
41263
+ *
41264
+ * @prop {string[]} [processScripts]
41265
+ * Array of `type` attribute values for `<script>` elements whose contents
41266
+ * should be processed as HTML
41267
+ * (e.g. `text/ng-template`, `text/x-handlebars-template`, etc.).
41268
+ * When present, the contents of matching script tags are recursively minified,
41269
+ * like normal HTML content.
41270
+ *
41271
+ * Default: `[]`
41272
+ *
41273
+ * @prop {"\"" | "'"} [quoteCharacter]
41274
+ * Preferred quote character for attribute values. If unspecified the
41275
+ * minifier picks the safest quote based on the attribute value.
41276
+ *
41277
+ * Default: Auto-detected
41278
+ *
41279
+ * @prop {boolean} [removeAttributeQuotes]
41280
+ * Remove quotes around attribute values where it is safe to do so.
41281
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes
41282
+ *
41283
+ * Default: `false`
41284
+ *
41285
+ * @prop {boolean} [removeComments]
41286
+ * Remove HTML comments. Comments that match `ignoreCustomComments` will
41287
+ * still be preserved.
41288
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_comments
41289
+ *
41290
+ * Default: `false`
41291
+ *
41292
+ * @prop {boolean | ((attrName: string, tag: string) => boolean)} [removeEmptyAttributes]
41293
+ * If true, removes attributes whose values are empty (some attributes
41294
+ * are excluded by name). Can also be a function to customise which empty
41295
+ * attributes are removed.
41296
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes
41297
+ *
41298
+ * Default: `false`
41299
+ *
41300
+ * @prop {boolean} [removeEmptyElements]
41301
+ * Remove elements that are empty and safe to remove (for example
41302
+ * `<script />` without `src`).
41303
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements
41304
+ *
41305
+ * Default: `false`
41306
+ *
41307
+ * @prop {boolean} [removeOptionalTags]
41308
+ * Drop optional start/end tags where the HTML specification permits it
41309
+ * (for example `</li>`, optional `<html>` etc.).
41310
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags
41311
+ *
41312
+ * Default: `false`
41313
+ *
41314
+ * @prop {boolean} [removeRedundantAttributes]
41315
+ * Remove attributes that are redundant because they match the element's
41316
+ * default values (for example `<button type="submit">`).
41317
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes
41318
+ *
41319
+ * Default: `false`
41320
+ *
41321
+ * @prop {boolean} [removeScriptTypeAttributes]
41322
+ * Remove `type` attributes from `<script>` when they are unnecessary
41323
+ * (e.g. `type="text/javascript"`).
41324
+ *
41325
+ * Default: `false`
41326
+ *
41327
+ * @prop {boolean} [removeStyleLinkTypeAttributes]
41328
+ * Remove `type` attributes from `<style>` and `<link>` elements when
41329
+ * they are unnecessary (e.g. `type="text/css"`).
41330
+ *
41331
+ * Default: `false`
41332
+ *
41333
+ * @prop {boolean} [removeTagWhitespace]
41334
+ * **Note that this will currently result in invalid HTML!**
41335
+ *
41336
+ * When true, extra whitespace between tag name and attributes (or before
41337
+ * the closing bracket) will be removed where possible. Affects output spacing
41338
+ * such as the space used in the short doctype representation.
41339
+ *
41340
+ * Default: `false`
41341
+ *
41342
+ * @prop {boolean | ((tag: string, attrs: HTMLAttribute[]) => void)} [sortAttributes]
41343
+ * When true, enables sorting of attributes. If a function is provided it
41344
+ * will be used as a custom attribute sorter, which should mutate `attrs`
41345
+ * in-place to the desired order. If disabled, the minifier will attempt to
41346
+ * preserve the order from the input.
41347
+ *
41348
+ * Default: `false`
41349
+ *
41350
+ * @prop {boolean | ((value: string) => string)} [sortClassName]
41351
+ * When true, enables sorting of class names inside `class` attributes.
41352
+ * If a function is provided it will be used to transform/sort the class
41353
+ * name string. If disabled, the minifier will attempt to preserve the
41354
+ * class-name order from the input.
41355
+ *
41356
+ * Default: `false`
41357
+ *
41358
+ * @prop {boolean} [trimCustomFragments]
41359
+ * When true, whitespace around ignored custom fragments may be trimmed
41360
+ * more aggressively. This affects how preserved fragments interact with
41361
+ * surrounding whitespace collapse.
41362
+ *
41363
+ * Default: `false`
41364
+ *
41365
+ * @prop {boolean} [useShortDoctype]
41366
+ * Replace the HTML doctype with the short `<!doctype html>` form.
41367
+ * See also: https://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype
41368
+ *
41369
+ * Default: `false`
41370
+ */
41371
+
41036
41372
  export { htmlminifier as default, minify };