html-minifier-next 1.1.5 → 1.2.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/package.json CHANGED
@@ -15,22 +15,21 @@
15
15
  "description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
16
16
  "devDependencies": {
17
17
  "@commitlint/cli": "^19.8.1",
18
- "@jest/globals": "^30.0.4",
18
+ "@jest/globals": "^30.0.5",
19
19
  "@rollup/plugin-commonjs": "^28.0.6",
20
20
  "@rollup/plugin-json": "^6.1.0",
21
21
  "@rollup/plugin-node-resolve": "^16.0.1",
22
22
  "@rollup/plugin-terser": "^0.4.4",
23
23
  "alpinejs": "^3.14.9",
24
24
  "commitlint-config-non-conventional": "^1.0.1",
25
- "eslint": "^9.30.1",
25
+ "eslint": "^9.32.0",
26
26
  "husky": "^9.1.7",
27
27
  "is-ci": "^4.1.0",
28
- "jest": "^30.0.4",
29
- "jest-environment-jsdom": "^30.0.4",
30
- "lint-staged": "^16.1.2",
31
- "rollup": "^4.44.1",
28
+ "jest": "^30.0.5",
29
+ "lint-staged": "^16.1.5",
30
+ "rollup": "^4.45.1",
32
31
  "rollup-plugin-polyfill-node": "^0.13.0",
33
- "vite": "^7.0.0"
32
+ "vite": "^7.0.5"
34
33
  },
35
34
  "exports": {
36
35
  ".": {
@@ -80,11 +79,9 @@
80
79
  "lint": "eslint .",
81
80
  "prepare": "husky",
82
81
  "serve": "npm run build && vite",
83
- "test": "npm run test:node",
84
- "test:node": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --verbose",
85
- "test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest verbose --watch",
86
- "test:web": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --verbose --environment=jsdom"
82
+ "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
83
+ "test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --watch"
87
84
  },
88
85
  "type": "module",
89
- "version": "1.1.5"
86
+ "version": "1.2.0"
90
87
  }
@@ -59,14 +59,14 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) {
59
59
  return lineBreakBefore + str + lineBreakAfter;
60
60
  }
61
61
 
62
- // non-empty tags that will maintain whitespace around them
63
- const inlineTags = new Set(['a', 'abbr', 'acronym', 'b', 'bdi', 'bdo', 'big', 'button', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd', 'label', 'mark', 'math', 'nobr', 'object', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'select', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'svg', 'textarea', 'time', 'tt', 'u', 'var']);
64
- // non-empty tags that will maintain whitespace within them
62
+ // non-empty elements that will maintain whitespace around them
63
+ const inlineHtmlElements = ['a', 'abbr', 'acronym', 'b', 'bdi', 'bdo', 'big', 'button', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'mark', 'math', 'meter', 'nobr', 'object', 'output', 'progress', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'select', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'svg', 'textarea', 'time', 'tt', 'u', 'var', 'wbr'];
64
+ // non-empty elements that will maintain whitespace within them
65
65
  const inlineTextTags = new Set(['a', 'abbr', 'acronym', 'b', 'big', 'del', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 'nobr', 'rp', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var']);
66
- // self-closing tags that will maintain whitespace around them
66
+ // self-closing elements that will maintain whitespace around them
67
67
  const selfClosingInlineTags = new Set(['comment', 'img', 'input', 'wbr']);
68
68
 
69
- function collapseWhitespaceSmart(str, prevTag, nextTag, options) {
69
+ function collapseWhitespaceSmart(str, prevTag, nextTag, options, inlineTags) {
70
70
  let trimLeft = prevTag && !selfClosingInlineTags.has(prevTag);
71
71
  if (trimLeft && !options.collapseInlineTagWhitespace) {
72
72
  trimLeft = prevTag.charAt(0) === '/' ? !inlineTags.has(prevTag.slice(1)) : !inlineTextTags.has(prevTag);
@@ -866,6 +866,10 @@ async function minifyHTML(value, options, partialMarkup) {
866
866
  let uidIgnore;
867
867
  let uidAttr;
868
868
  let uidPattern;
869
+ // Create inline tags set with backward compatibility for inlineCustomTags
870
+ const customElements = options.inlineCustomElements ?? options.inlineCustomTags ?? [];
871
+ const normalizedCustomElements = customElements.map(name => options.name(name));
872
+ let inlineTags = new Set([...inlineHtmlElements, ...normalizedCustomElements]);
869
873
 
870
874
  // temporarily replace ignored chunks with comments,
871
875
  // so that we don't have to worry what's there.
@@ -997,7 +1001,7 @@ async function minifyHTML(value, options, partialMarkup) {
997
1001
  const match = str.match(/^<\/([\w:-]+)>$/);
998
1002
  if (match) {
999
1003
  endTag = match[1];
1000
- } else if (/>$/.test(str) || (buffer[index] = collapseWhitespaceSmart(str, null, nextTag, options))) {
1004
+ } else if (/>$/.test(str) || (buffer[index] = collapseWhitespaceSmart(str, null, nextTag, options, inlineTags))) {
1001
1005
  break;
1002
1006
  }
1003
1007
  }
@@ -1208,7 +1212,7 @@ async function minifyHTML(value, options, partialMarkup) {
1208
1212
  }
1209
1213
  }
1210
1214
  if (prevTag || nextTag) {
1211
- text = collapseWhitespaceSmart(text, prevTag, nextTag, options);
1215
+ text = collapseWhitespaceSmart(text, prevTag, nextTag, options, inlineTags);
1212
1216
  } else {
1213
1217
  text = collapseWhitespace(text, options, true, true);
1214
1218
  }