html-minifier-next 1.4.3 → 2.0.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.
@@ -80,7 +80,7 @@ const fillAttrs = new CaseInsensitiveSet(['checked', 'compact', 'declare', 'defe
80
80
  // Special elements (can contain anything)
81
81
  const special = new CaseInsensitiveSet(['script', 'style']);
82
82
 
83
- // HTML5 elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
83
+ // HTML elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
84
84
  // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
85
85
  const nonPhrasing = new CaseInsensitiveSet(['address', 'article', 'aside', 'base', 'blockquote', 'body', 'caption', 'col', 'colgroup', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'li', 'menuitem', 'meta', 'ol', 'optgroup', 'option', 'param', 'rp', 'rt', 'source', 'style', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']);
86
86
 
@@ -60172,7 +60172,7 @@ const fillAttrs = new CaseInsensitiveSet(['checked', 'compact', 'declare', 'defe
60172
60172
  // Special elements (can contain anything)
60173
60173
  const special = new CaseInsensitiveSet(['script', 'style']);
60174
60174
 
60175
- // HTML5 elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
60175
+ // HTML elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
60176
60176
  // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
60177
60177
  const nonPhrasing = new CaseInsensitiveSet(['address', 'article', 'aside', 'base', 'blockquote', 'body', 'caption', 'col', 'colgroup', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'li', 'menuitem', 'meta', 'ol', 'optgroup', 'option', 'param', 'rp', 'rt', 'source', 'style', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']);
60178
60178
 
@@ -60178,7 +60178,7 @@
60178
60178
  // Special elements (can contain anything)
60179
60179
  const special = new CaseInsensitiveSet(['script', 'style']);
60180
60180
 
60181
- // HTML5 elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
60181
+ // HTML elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
60182
60182
  // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
60183
60183
  const nonPhrasing = new CaseInsensitiveSet(['address', 'article', 'aside', 'base', 'blockquote', 'body', 'caption', 'col', 'colgroup', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'li', 'menuitem', 'meta', 'ol', 'optgroup', 'option', 'param', 'rp', 'rt', 'source', 'style', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']);
60184
60184
 
package/package.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
16
16
  "devDependencies": {
17
17
  "@commitlint/cli": "^19.8.1",
18
+ "@eslint/js": "^9.33.0",
18
19
  "@jest/globals": "^30.1.2",
19
20
  "@rollup/plugin-commonjs": "^28.0.6",
20
21
  "@rollup/plugin-json": "^6.1.0",
@@ -24,9 +25,7 @@
24
25
  "commitlint-config-non-conventional": "^1.0.1",
25
26
  "eslint": "^9.33.0",
26
27
  "husky": "^9.1.7",
27
- "is-ci": "^4.1.0",
28
28
  "jest": "^30.1.3",
29
- "lint-staged": "^16.1.5",
30
29
  "rollup": "^4.50.0",
31
30
  "rollup-plugin-polyfill-node": "^0.13.0",
32
31
  "vite": "^7.1.5"
@@ -89,5 +88,5 @@
89
88
  "test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --watch"
90
89
  },
91
90
  "type": "module",
92
- "version": "1.4.3"
91
+ "version": "2.0.0"
93
92
  }
package/src/htmlparser.js CHANGED
@@ -13,21 +13,8 @@
13
13
  * chars: function(text) {},
14
14
  * comment: function(text) {}
15
15
  * });
16
- *
17
- * // or to get an XML string:
18
- * HTMLtoXML(htmlString);
19
- *
20
- * // or to get an XML DOM Document
21
- * HTMLtoDOM(htmlString);
22
- *
23
- * // or to inject into an existing document/DOM node
24
- * HTMLtoDOM(htmlString, document);
25
- * HTMLtoDOM(htmlString, document.body);
26
- *
27
16
  */
28
17
 
29
- /* global ActiveXObject, DOMDocument */
30
-
31
18
  import { replaceAsync } from './utils.js';
32
19
 
33
20
  class CaseInsensitiveSet extends Set {
@@ -83,7 +70,7 @@ const fillAttrs = new CaseInsensitiveSet(['checked', 'compact', 'declare', 'defe
83
70
  // Special elements (can contain anything)
84
71
  const special = new CaseInsensitiveSet(['script', 'style']);
85
72
 
86
- // HTML5 elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
73
+ // HTML elements https://html.spec.whatwg.org/multipage/indices.html#elements-3
87
74
  // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
88
75
  const nonPhrasing = new CaseInsensitiveSet(['address', 'article', 'aside', 'base', 'blockquote', 'body', 'caption', 'col', 'colgroup', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'li', 'menuitem', 'meta', 'ol', 'optgroup', 'option', 'param', 'rp', 'rt', 'source', 'style', 'summary', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']);
89
76
 
@@ -430,136 +417,4 @@ export class HTMLParser {
430
417
  }
431
418
  }
432
419
  }
433
- }
434
-
435
- export const HTMLtoXML = (html) => {
436
- let results = '';
437
-
438
- const parser = new HTMLParser(html, {
439
- start: function (tag, attrs, unary) {
440
- results += '<' + tag;
441
-
442
- for (let i = 0, len = attrs.length; i < len; i++) {
443
- results += ' ' + attrs[i].name + '="' + (attrs[i].value || '').replace(/"/g, '&#34;') + '"';
444
- }
445
-
446
- results += (unary ? '/' : '') + '>';
447
- },
448
- end: function (tag) {
449
- results += '</' + tag + '>';
450
- },
451
- chars: function (text) {
452
- results += text;
453
- },
454
- comment: function (text) {
455
- results += '<!--' + text + '-->';
456
- },
457
- ignore: function (text) {
458
- results += text;
459
- }
460
- });
461
-
462
- parser.parse();
463
-
464
- return results;
465
- };
466
-
467
- export const HTMLtoDOM = (html, doc) => {
468
- // There can be only one of these elements
469
- const one = {
470
- html: true,
471
- head: true,
472
- body: true,
473
- title: true
474
- };
475
-
476
- // Enforce a structure for the document
477
- const structure = {
478
- link: 'head',
479
- base: 'head'
480
- };
481
-
482
- if (doc) {
483
- doc = doc.ownerDocument || (doc.getOwnerDocument && doc.getOwnerDocument()) || doc;
484
- } else if (typeof DOMDocument !== 'undefined') {
485
- doc = new DOMDocument();
486
- } else if (typeof document !== 'undefined' && document.implementation && document.implementation.createDocument) {
487
- doc = document.implementation.createDocument('', '', null);
488
- } else if (typeof ActiveX !== 'undefined') {
489
- doc = new ActiveXObject('Msxml.DOMDocument');
490
- }
491
-
492
- const elems = [];
493
- const documentElement = doc.documentElement || (doc.getDocumentElement && doc.getDocumentElement());
494
-
495
- // If we're dealing with an empty document then we
496
- // need to pre-populate it with the HTML document structure
497
- if (!documentElement && doc.createElement) {
498
- (function () {
499
- const html = doc.createElement('html');
500
- const head = doc.createElement('head');
501
- head.appendChild(doc.createElement('title'));
502
- html.appendChild(head);
503
- html.appendChild(doc.createElement('body'));
504
- doc.appendChild(html);
505
- })();
506
- }
507
-
508
- // Find all the unique elements
509
- if (doc.getElementsByTagName) {
510
- for (const i in one) {
511
- one[i] = doc.getElementsByTagName(i)[0];
512
- }
513
- }
514
-
515
- // If we’re working with a document, inject contents into
516
- // the `body` element
517
- let curParentNode = one.body;
518
-
519
- const parser = new HTMLParser(html, {
520
- start: function (tagName, attrs, unary) {
521
- // If it’s a pre-built element, then we can ignore
522
- // its construction
523
- if (one[tagName]) {
524
- curParentNode = one[tagName];
525
- return;
526
- }
527
-
528
- const elem = doc.createElement(tagName);
529
-
530
- for (const attr in attrs) {
531
- elem.setAttribute(attrs[attr].name, attrs[attr].value);
532
- }
533
-
534
- if (structure[tagName] && typeof one[structure[tagName]] !== 'boolean') {
535
- one[structure[tagName]].appendChild(elem);
536
- } else if (curParentNode && curParentNode.appendChild) {
537
- curParentNode.appendChild(elem);
538
- }
539
-
540
- if (!unary) {
541
- elems.push(elem);
542
- curParentNode = elem;
543
- }
544
- },
545
- end: function (/* tag */) {
546
- elems.length -= 1;
547
-
548
- // Init the new parentNode
549
- curParentNode = elems[elems.length - 1];
550
- },
551
- chars: function (text) {
552
- curParentNode.appendChild(doc.createTextNode(text));
553
- },
554
- comment: function (/* text */) {
555
- // Create comment node
556
- },
557
- ignore: function (/* text */) {
558
- // What to do here?
559
- }
560
- });
561
-
562
- parser.parse();
563
-
564
- return doc;
565
- };
420
+ }