html-react-parser 5.2.17 → 6.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.
@@ -23,498 +23,384 @@
23
23
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
24
24
  }
25
25
 
26
- var lib$3 = {};
27
-
28
- var htmlToDom = {};
29
-
30
- var domparser = {};
31
-
32
- var utilities$2 = {};
33
-
34
- var lib$2 = {};
26
+ function getAugmentedNamespace(n) {
27
+ if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
28
+ var f = n.default;
29
+ if (typeof f == "function") {
30
+ var a = function a () {
31
+ var isInstance = false;
32
+ try {
33
+ isInstance = this instanceof a;
34
+ } catch {}
35
+ if (isInstance) {
36
+ return Reflect.construct(f, arguments, this.constructor);
37
+ }
38
+ return f.apply(this, arguments);
39
+ };
40
+ a.prototype = f.prototype;
41
+ } else a = {};
42
+ Object.defineProperty(a, '__esModule', {value: true});
43
+ Object.keys(n).forEach(function (k) {
44
+ var d = Object.getOwnPropertyDescriptor(n, k);
45
+ Object.defineProperty(a, k, d.get ? d : {
46
+ enumerable: true,
47
+ get: function () {
48
+ return n[k];
49
+ }
50
+ });
51
+ });
52
+ return a;
53
+ }
35
54
 
36
55
  var lib$1 = {};
37
56
 
38
- var hasRequiredLib$3;
57
+ var htmlToDom = {};
39
58
 
40
- function requireLib$3 () {
41
- if (hasRequiredLib$3) return lib$1;
42
- hasRequiredLib$3 = 1;
43
- (function (exports$1) {
44
- Object.defineProperty(exports$1, "__esModule", { value: true });
45
- exports$1.Doctype = exports$1.CDATA = exports$1.Tag = exports$1.Style = exports$1.Script = exports$1.Comment = exports$1.Directive = exports$1.Text = exports$1.Root = exports$1.isTag = exports$1.ElementType = void 0;
46
- /** Types of elements found in htmlparser2's DOM */
47
- var ElementType;
48
- (function (ElementType) {
49
- /** Type for the root element of a document */
50
- ElementType["Root"] = "root";
51
- /** Type for Text */
52
- ElementType["Text"] = "text";
53
- /** Type for <? ... ?> */
54
- ElementType["Directive"] = "directive";
55
- /** Type for <!-- ... --> */
56
- ElementType["Comment"] = "comment";
57
- /** Type for <script> tags */
58
- ElementType["Script"] = "script";
59
- /** Type for <style> tags */
60
- ElementType["Style"] = "style";
61
- /** Type for Any tag */
62
- ElementType["Tag"] = "tag";
63
- /** Type for <![CDATA[ ... ]]> */
64
- ElementType["CDATA"] = "cdata";
65
- /** Type for <!doctype ...> */
66
- ElementType["Doctype"] = "doctype";
67
- })(ElementType = exports$1.ElementType || (exports$1.ElementType = {}));
68
- /**
69
- * Tests whether an element is a tag or not.
70
- *
71
- * @param elem Element to test
72
- */
73
- function isTag(elem) {
74
- return (elem.type === ElementType.Tag ||
75
- elem.type === ElementType.Script ||
76
- elem.type === ElementType.Style);
77
- }
78
- exports$1.isTag = isTag;
79
- // Exports for backwards compatibility
80
- /** Type for the root element of a document */
81
- exports$1.Root = ElementType.Root;
82
- /** Type for Text */
83
- exports$1.Text = ElementType.Text;
84
- /** Type for <? ... ?> */
85
- exports$1.Directive = ElementType.Directive;
86
- /** Type for <!-- ... --> */
87
- exports$1.Comment = ElementType.Comment;
88
- /** Type for <script> tags */
89
- exports$1.Script = ElementType.Script;
90
- /** Type for <style> tags */
91
- exports$1.Style = ElementType.Style;
92
- /** Type for Any tag */
93
- exports$1.Tag = ElementType.Tag;
94
- /** Type for <![CDATA[ ... ]]> */
95
- exports$1.CDATA = ElementType.CDATA;
96
- /** Type for <!doctype ...> */
97
- exports$1.Doctype = ElementType.Doctype;
98
- } (lib$1));
99
- return lib$1;
100
- }
59
+ var hasRequiredHtmlToDom;
101
60
 
102
- var node = {};
61
+ function requireHtmlToDom () {
62
+ if (hasRequiredHtmlToDom) return htmlToDom;
63
+ hasRequiredHtmlToDom = 1;
103
64
 
104
- var hasRequiredNode;
65
+ Object.defineProperty(htmlToDom, '__esModule', { value: true });
66
+
67
+ /** Types of elements found in htmlparser2's DOM */
68
+ var ElementType;
69
+ (function (ElementType) {
70
+ /** Type for the root element of a document */
71
+ ElementType["Root"] = "root";
72
+ /** Type for Text */
73
+ ElementType["Text"] = "text";
74
+ /** Type for <? ... ?> */
75
+ ElementType["Directive"] = "directive";
76
+ /** Type for <!-- ... --> */
77
+ ElementType["Comment"] = "comment";
78
+ /** Type for <script> tags */
79
+ ElementType["Script"] = "script";
80
+ /** Type for <style> tags */
81
+ ElementType["Style"] = "style";
82
+ /** Type for Any tag */
83
+ ElementType["Tag"] = "tag";
84
+ /** Type for <![CDATA[ ... ]]> */
85
+ ElementType["CDATA"] = "cdata";
86
+ /** Type for <!doctype ...> */
87
+ ElementType["Doctype"] = "doctype";
88
+ })(ElementType || (ElementType = {}));
89
+ /**
90
+ * Tests whether an element is a tag or not.
91
+ * @param element Element to test
92
+ * @param element.type Node type discriminator to check.
93
+ */
94
+ function isTag$1(element) {
95
+ return (element.type === ElementType.Tag ||
96
+ element.type === ElementType.Script ||
97
+ element.type === ElementType.Style);
98
+ }
99
+ // Exports for backwards compatibility
100
+ /** Type for the root element of a document */
101
+ // eslint-disable-next-line prefer-destructuring
102
+ ElementType.Root;
103
+ /** Type for Text */
104
+ // eslint-disable-next-line prefer-destructuring
105
+ ElementType.Text;
106
+ /** Type for <? ... ?> */
107
+ // eslint-disable-next-line prefer-destructuring
108
+ ElementType.Directive;
109
+ /** Type for <!-- ... --> */
110
+ // eslint-disable-next-line prefer-destructuring
111
+ ElementType.Comment;
112
+ /** Type for <script> tags */
113
+ // eslint-disable-next-line prefer-destructuring
114
+ ElementType.Script;
115
+ /** Type for <style> tags */
116
+ // eslint-disable-next-line prefer-destructuring
117
+ ElementType.Style;
118
+ /** Type for Any tag */
119
+ // eslint-disable-next-line prefer-destructuring
120
+ ElementType.Tag;
121
+ /** Type for <![CDATA[ ... ]]> */
122
+ // eslint-disable-next-line prefer-destructuring
123
+ ElementType.CDATA;
124
+ /** Type for <!doctype ...> */
125
+ // eslint-disable-next-line prefer-destructuring
126
+ ElementType.Doctype;
105
127
 
106
- function requireNode () {
107
- if (hasRequiredNode) return node;
108
- hasRequiredNode = 1;
109
- var __extends = (node && node.__extends) || (function () {
110
- var extendStatics = function (d, b) {
111
- extendStatics = Object.setPrototypeOf ||
112
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
113
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
114
- return extendStatics(d, b);
115
- };
116
- return function (d, b) {
117
- if (typeof b !== "function" && b !== null)
118
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
119
- extendStatics(d, b);
120
- function __() { this.constructor = d; }
121
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
122
- };
123
- })();
124
- var __assign = (node && node.__assign) || function () {
125
- __assign = Object.assign || function(t) {
126
- for (var s, i = 1, n = arguments.length; i < n; i++) {
127
- s = arguments[i];
128
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
129
- t[p] = s[p];
130
- }
131
- return t;
132
- };
133
- return __assign.apply(this, arguments);
134
- };
135
- Object.defineProperty(node, "__esModule", { value: true });
136
- node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.CDATA = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
137
- var domelementtype_1 = /*@__PURE__*/ requireLib$3();
138
128
  /**
139
129
  * This object will be used as the prototype for Nodes when creating a
140
130
  * DOM-Level-1-compliant structure.
141
131
  */
142
- var Node = /** @class */ (function () {
143
- function Node() {
144
- /** Parent of the node */
145
- this.parent = null;
146
- /** Previous sibling */
147
- this.prev = null;
148
- /** Next sibling */
149
- this.next = null;
150
- /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
151
- this.startIndex = null;
152
- /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
153
- this.endIndex = null;
132
+ class Node {
133
+ /** Parent of the node */
134
+ parent = null;
135
+ /** Previous sibling */
136
+ prev = null;
137
+ /** Next sibling */
138
+ next = null;
139
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
140
+ startIndex = null;
141
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
142
+ endIndex = null;
143
+ // Read-write aliases for properties
144
+ /**
145
+ * Same as {@link parent}.
146
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
147
+ */
148
+ get parentNode() {
149
+ return this.parent;
150
+ }
151
+ set parentNode(parent) {
152
+ this.parent = parent;
153
+ }
154
+ /**
155
+ * Same as {@link prev}.
156
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
157
+ */
158
+ get previousSibling() {
159
+ return this.prev;
160
+ }
161
+ set previousSibling(previous) {
162
+ this.prev = previous;
163
+ }
164
+ /**
165
+ * Same as {@link next}.
166
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
167
+ */
168
+ get nextSibling() {
169
+ return this.next;
170
+ }
171
+ set nextSibling(next) {
172
+ this.next = next;
154
173
  }
155
- Object.defineProperty(Node.prototype, "parentNode", {
156
- // Read-write aliases for properties
157
- /**
158
- * Same as {@link parent}.
159
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
160
- */
161
- get: function () {
162
- return this.parent;
163
- },
164
- set: function (parent) {
165
- this.parent = parent;
166
- },
167
- enumerable: false,
168
- configurable: true
169
- });
170
- Object.defineProperty(Node.prototype, "previousSibling", {
171
- /**
172
- * Same as {@link prev}.
173
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
174
- */
175
- get: function () {
176
- return this.prev;
177
- },
178
- set: function (prev) {
179
- this.prev = prev;
180
- },
181
- enumerable: false,
182
- configurable: true
183
- });
184
- Object.defineProperty(Node.prototype, "nextSibling", {
185
- /**
186
- * Same as {@link next}.
187
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
188
- */
189
- get: function () {
190
- return this.next;
191
- },
192
- set: function (next) {
193
- this.next = next;
194
- },
195
- enumerable: false,
196
- configurable: true
197
- });
198
174
  /**
199
175
  * Clone this node, and optionally its children.
200
- *
201
176
  * @param recursive Clone child nodes as well.
202
177
  * @returns A clone of the node.
203
178
  */
204
- Node.prototype.cloneNode = function (recursive) {
205
- if (recursive === void 0) { recursive = false; }
179
+ cloneNode(recursive = false) {
206
180
  return cloneNode(this, recursive);
207
- };
208
- return Node;
209
- }());
210
- node.Node = Node;
181
+ }
182
+ }
211
183
  /**
212
184
  * A node that contains some data.
213
185
  */
214
- var DataNode = /** @class */ (function (_super) {
215
- __extends(DataNode, _super);
186
+ class DataNode extends Node {
187
+ data;
216
188
  /**
217
189
  * @param data The content of the data node
218
190
  */
219
- function DataNode(data) {
220
- var _this = _super.call(this) || this;
221
- _this.data = data;
222
- return _this;
191
+ constructor(data) {
192
+ super();
193
+ this.data = data;
223
194
  }
224
- Object.defineProperty(DataNode.prototype, "nodeValue", {
225
- /**
226
- * Same as {@link data}.
227
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
228
- */
229
- get: function () {
230
- return this.data;
231
- },
232
- set: function (data) {
233
- this.data = data;
234
- },
235
- enumerable: false,
236
- configurable: true
237
- });
238
- return DataNode;
239
- }(Node));
240
- node.DataNode = DataNode;
195
+ /**
196
+ * Same as {@link data}.
197
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
198
+ */
199
+ get nodeValue() {
200
+ return this.data;
201
+ }
202
+ set nodeValue(data) {
203
+ this.data = data;
204
+ }
205
+ }
241
206
  /**
242
207
  * Text within the document.
243
208
  */
244
- var Text = /** @class */ (function (_super) {
245
- __extends(Text, _super);
246
- function Text() {
247
- var _this = _super !== null && _super.apply(this, arguments) || this;
248
- _this.type = domelementtype_1.ElementType.Text;
249
- return _this;
209
+ class Text extends DataNode {
210
+ type = ElementType.Text;
211
+ get nodeType() {
212
+ return 3;
250
213
  }
251
- Object.defineProperty(Text.prototype, "nodeType", {
252
- get: function () {
253
- return 3;
254
- },
255
- enumerable: false,
256
- configurable: true
257
- });
258
- return Text;
259
- }(DataNode));
260
- node.Text = Text;
214
+ }
261
215
  /**
262
216
  * Comments within the document.
263
217
  */
264
- var Comment = /** @class */ (function (_super) {
265
- __extends(Comment, _super);
266
- function Comment() {
267
- var _this = _super !== null && _super.apply(this, arguments) || this;
268
- _this.type = domelementtype_1.ElementType.Comment;
269
- return _this;
218
+ class Comment extends DataNode {
219
+ type = ElementType.Comment;
220
+ get nodeType() {
221
+ return 8;
270
222
  }
271
- Object.defineProperty(Comment.prototype, "nodeType", {
272
- get: function () {
273
- return 8;
274
- },
275
- enumerable: false,
276
- configurable: true
277
- });
278
- return Comment;
279
- }(DataNode));
280
- node.Comment = Comment;
223
+ }
281
224
  /**
282
225
  * Processing instructions, including doc types.
283
226
  */
284
- var ProcessingInstruction = /** @class */ (function (_super) {
285
- __extends(ProcessingInstruction, _super);
286
- function ProcessingInstruction(name, data) {
287
- var _this = _super.call(this, data) || this;
288
- _this.name = name;
289
- _this.type = domelementtype_1.ElementType.Directive;
290
- return _this;
227
+ class ProcessingInstruction extends DataNode {
228
+ type = ElementType.Directive;
229
+ name;
230
+ constructor(name, data) {
231
+ super(data);
232
+ this.name = name;
291
233
  }
292
- Object.defineProperty(ProcessingInstruction.prototype, "nodeType", {
293
- get: function () {
294
- return 1;
295
- },
296
- enumerable: false,
297
- configurable: true
298
- });
299
- return ProcessingInstruction;
300
- }(DataNode));
301
- node.ProcessingInstruction = ProcessingInstruction;
234
+ get nodeType() {
235
+ return 1;
236
+ }
237
+ /** If this is a doctype, the document type name (parse5 only). */
238
+ "x-name";
239
+ /** If this is a doctype, the document type public identifier (parse5 only). */
240
+ "x-publicId";
241
+ /** If this is a doctype, the document type system identifier (parse5 only). */
242
+ "x-systemId";
243
+ }
302
244
  /**
303
- * A `Node` that can have children.
245
+ * A node that can have children.
304
246
  */
305
- var NodeWithChildren = /** @class */ (function (_super) {
306
- __extends(NodeWithChildren, _super);
247
+ class NodeWithChildren extends Node {
248
+ children;
307
249
  /**
308
250
  * @param children Children of the node. Only certain node types can have children.
309
251
  */
310
- function NodeWithChildren(children) {
311
- var _this = _super.call(this) || this;
312
- _this.children = children;
313
- return _this;
252
+ constructor(children) {
253
+ super();
254
+ this.children = children;
314
255
  }
315
- Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
316
- // Aliases
317
- /** First child of the node. */
318
- get: function () {
319
- var _a;
320
- return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
321
- },
322
- enumerable: false,
323
- configurable: true
324
- });
325
- Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
326
- /** Last child of the node. */
327
- get: function () {
328
- return this.children.length > 0
329
- ? this.children[this.children.length - 1]
330
- : null;
331
- },
332
- enumerable: false,
333
- configurable: true
334
- });
335
- Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
336
- /**
337
- * Same as {@link children}.
338
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
339
- */
340
- get: function () {
341
- return this.children;
342
- },
343
- set: function (children) {
344
- this.children = children;
345
- },
346
- enumerable: false,
347
- configurable: true
348
- });
349
- return NodeWithChildren;
350
- }(Node));
351
- node.NodeWithChildren = NodeWithChildren;
352
- var CDATA = /** @class */ (function (_super) {
353
- __extends(CDATA, _super);
354
- function CDATA() {
355
- var _this = _super !== null && _super.apply(this, arguments) || this;
356
- _this.type = domelementtype_1.ElementType.CDATA;
357
- return _this;
256
+ // Aliases
257
+ /** First child of the node. */
258
+ get firstChild() {
259
+ return this.children[0] ?? null;
358
260
  }
359
- Object.defineProperty(CDATA.prototype, "nodeType", {
360
- get: function () {
361
- return 4;
362
- },
363
- enumerable: false,
364
- configurable: true
365
- });
366
- return CDATA;
367
- }(NodeWithChildren));
368
- node.CDATA = CDATA;
261
+ /** Last child of the node. */
262
+ get lastChild() {
263
+ return this.children.length > 0
264
+ ? this.children[this.children.length - 1]
265
+ : null;
266
+ }
267
+ /**
268
+ * Same as {@link children}.
269
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
270
+ */
271
+ get childNodes() {
272
+ return this.children;
273
+ }
274
+ set childNodes(children) {
275
+ this.children = children;
276
+ }
277
+ }
278
+ /**
279
+ * CDATA nodes.
280
+ */
281
+ class CDATA extends NodeWithChildren {
282
+ type = ElementType.CDATA;
283
+ get nodeType() {
284
+ return 4;
285
+ }
286
+ }
369
287
  /**
370
288
  * The root node of the document.
371
289
  */
372
- var Document = /** @class */ (function (_super) {
373
- __extends(Document, _super);
374
- function Document() {
375
- var _this = _super !== null && _super.apply(this, arguments) || this;
376
- _this.type = domelementtype_1.ElementType.Root;
377
- return _this;
290
+ class Document extends NodeWithChildren {
291
+ type = ElementType.Root;
292
+ get nodeType() {
293
+ return 9;
378
294
  }
379
- Object.defineProperty(Document.prototype, "nodeType", {
380
- get: function () {
381
- return 9;
382
- },
383
- enumerable: false,
384
- configurable: true
385
- });
386
- return Document;
387
- }(NodeWithChildren));
388
- node.Document = Document;
295
+ }
389
296
  /**
390
297
  * An element within the DOM.
391
298
  */
392
- var Element = /** @class */ (function (_super) {
393
- __extends(Element, _super);
299
+ class Element extends NodeWithChildren {
300
+ name;
301
+ attribs;
302
+ type;
394
303
  /**
395
304
  * @param name Name of the tag, eg. `div`, `span`.
396
305
  * @param attribs Object mapping attribute names to attribute values.
397
306
  * @param children Children of the node.
307
+ * @param type Node type used for the new node instance.
398
308
  */
399
- function Element(name, attribs, children, type) {
400
- if (children === void 0) { children = []; }
401
- if (type === void 0) { type = name === "script"
402
- ? domelementtype_1.ElementType.Script
403
- : name === "style"
404
- ? domelementtype_1.ElementType.Style
405
- : domelementtype_1.ElementType.Tag; }
406
- var _this = _super.call(this, children) || this;
407
- _this.name = name;
408
- _this.attribs = attribs;
409
- _this.type = type;
410
- return _this;
309
+ constructor(name, attribs, children = [], type = name === "script"
310
+ ? ElementType.Script
311
+ : name === "style"
312
+ ? ElementType.Style
313
+ : ElementType.Tag) {
314
+ super(children);
315
+ this.name = name;
316
+ this.attribs = attribs;
317
+ this.type = type;
411
318
  }
412
- Object.defineProperty(Element.prototype, "nodeType", {
413
- get: function () {
414
- return 1;
415
- },
416
- enumerable: false,
417
- configurable: true
418
- });
419
- Object.defineProperty(Element.prototype, "tagName", {
420
- // DOM Level 1 aliases
421
- /**
422
- * Same as {@link name}.
423
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
424
- */
425
- get: function () {
426
- return this.name;
427
- },
428
- set: function (name) {
429
- this.name = name;
430
- },
431
- enumerable: false,
432
- configurable: true
433
- });
434
- Object.defineProperty(Element.prototype, "attributes", {
435
- get: function () {
436
- var _this = this;
437
- return Object.keys(this.attribs).map(function (name) {
438
- var _a, _b;
439
- return ({
440
- name: name,
441
- value: _this.attribs[name],
442
- namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
443
- prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
444
- });
445
- });
446
- },
447
- enumerable: false,
448
- configurable: true
449
- });
450
- return Element;
451
- }(NodeWithChildren));
452
- node.Element = Element;
319
+ get nodeType() {
320
+ return 1;
321
+ }
322
+ // DOM Level 1 aliases
323
+ /**
324
+ * Same as {@link name}.
325
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
326
+ */
327
+ get tagName() {
328
+ return this.name;
329
+ }
330
+ set tagName(name) {
331
+ this.name = name;
332
+ }
333
+ get attributes() {
334
+ return Object.keys(this.attribs).map((name) => ({
335
+ name,
336
+ value: this.attribs[name],
337
+ namespace: this["x-attribsNamespace"]?.[name],
338
+ prefix: this["x-attribsPrefix"]?.[name],
339
+ }));
340
+ }
341
+ /** Element namespace (parse5 only). */
342
+ namespace;
343
+ /** Element attribute namespaces (parse5 only). */
344
+ "x-attribsNamespace";
345
+ /** Element attribute namespace-related prefixes (parse5 only). */
346
+ "x-attribsPrefix";
347
+ }
453
348
  /**
349
+ * Checks if `node` is an element node.
454
350
  * @param node Node to check.
455
- * @returns `true` if the node is a `Element`, `false` otherwise.
351
+ * @returns `true` if the node is an element node.
456
352
  */
457
353
  function isTag(node) {
458
- return (0, domelementtype_1.isTag)(node);
354
+ return isTag$1(node);
459
355
  }
460
- node.isTag = isTag;
461
356
  /**
357
+ * Checks if `node` is a CDATA node.
462
358
  * @param node Node to check.
463
- * @returns `true` if the node has the type `CDATA`, `false` otherwise.
359
+ * @returns `true` if the node is a CDATA node.
464
360
  */
465
361
  function isCDATA(node) {
466
- return node.type === domelementtype_1.ElementType.CDATA;
362
+ return node.type === ElementType.CDATA;
467
363
  }
468
- node.isCDATA = isCDATA;
469
364
  /**
365
+ * Checks if `node` is a text node.
470
366
  * @param node Node to check.
471
- * @returns `true` if the node has the type `Text`, `false` otherwise.
367
+ * @returns `true` if the node is a text node.
472
368
  */
473
369
  function isText(node) {
474
- return node.type === domelementtype_1.ElementType.Text;
370
+ return node.type === ElementType.Text;
475
371
  }
476
- node.isText = isText;
477
372
  /**
373
+ * Checks if `node` is a comment node.
478
374
  * @param node Node to check.
479
- * @returns `true` if the node has the type `Comment`, `false` otherwise.
375
+ * @returns `true` if the node is a comment node.
480
376
  */
481
377
  function isComment(node) {
482
- return node.type === domelementtype_1.ElementType.Comment;
378
+ return node.type === ElementType.Comment;
483
379
  }
484
- node.isComment = isComment;
485
380
  /**
381
+ * Checks if `node` is a directive node.
486
382
  * @param node Node to check.
487
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
383
+ * @returns `true` if the node is a directive node.
488
384
  */
489
385
  function isDirective(node) {
490
- return node.type === domelementtype_1.ElementType.Directive;
386
+ return node.type === ElementType.Directive;
491
387
  }
492
- node.isDirective = isDirective;
493
388
  /**
389
+ * Checks if `node` is a document node.
494
390
  * @param node Node to check.
495
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
391
+ * @returns `true` if the node is a document node.
496
392
  */
497
393
  function isDocument(node) {
498
- return node.type === domelementtype_1.ElementType.Root;
394
+ return node.type === ElementType.Root;
499
395
  }
500
- node.isDocument = isDocument;
501
- /**
502
- * @param node Node to check.
503
- * @returns `true` if the node has children, `false` otherwise.
504
- */
505
- function hasChildren(node) {
506
- return Object.prototype.hasOwnProperty.call(node, "children");
507
- }
508
- node.hasChildren = hasChildren;
509
396
  /**
510
397
  * Clone a node, and optionally its children.
511
- *
398
+ * @param node Node to clone.
512
399
  * @param recursive Clone child nodes as well.
513
400
  * @returns A clone of the node.
514
401
  */
515
- function cloneNode(node, recursive) {
516
- if (recursive === void 0) { recursive = false; }
517
- var result;
402
+ function cloneNode(node, recursive = false) {
403
+ let result;
518
404
  if (isText(node)) {
519
405
  result = new Text(node.data);
520
406
  }
@@ -522,37 +408,43 @@
522
408
  result = new Comment(node.data);
523
409
  }
524
410
  else if (isTag(node)) {
525
- var children = recursive ? cloneChildren(node.children) : [];
526
- var clone_1 = new Element(node.name, __assign({}, node.attribs), children);
527
- children.forEach(function (child) { return (child.parent = clone_1); });
411
+ const children = recursive ? cloneChildren(node.children) : [];
412
+ const clone = new Element(node.name, { ...node.attribs }, children);
413
+ for (const child of children) {
414
+ child.parent = clone;
415
+ }
528
416
  if (node.namespace != null) {
529
- clone_1.namespace = node.namespace;
417
+ clone.namespace = node.namespace;
530
418
  }
531
419
  if (node["x-attribsNamespace"]) {
532
- clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
420
+ clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
533
421
  }
534
422
  if (node["x-attribsPrefix"]) {
535
- clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
423
+ clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
536
424
  }
537
- result = clone_1;
425
+ result = clone;
538
426
  }
539
427
  else if (isCDATA(node)) {
540
- var children = recursive ? cloneChildren(node.children) : [];
541
- var clone_2 = new CDATA(children);
542
- children.forEach(function (child) { return (child.parent = clone_2); });
543
- result = clone_2;
428
+ const children = recursive ? cloneChildren(node.children) : [];
429
+ const clone = new CDATA(children);
430
+ for (const child of children) {
431
+ child.parent = clone;
432
+ }
433
+ result = clone;
544
434
  }
545
435
  else if (isDocument(node)) {
546
- var children = recursive ? cloneChildren(node.children) : [];
547
- var clone_3 = new Document(children);
548
- children.forEach(function (child) { return (child.parent = clone_3); });
436
+ const children = recursive ? cloneChildren(node.children) : [];
437
+ const clone = new Document(children);
438
+ for (const child of children) {
439
+ child.parent = clone;
440
+ }
549
441
  if (node["x-mode"]) {
550
- clone_3["x-mode"] = node["x-mode"];
442
+ clone["x-mode"] = node["x-mode"];
551
443
  }
552
- result = clone_3;
444
+ result = clone;
553
445
  }
554
446
  else if (isDirective(node)) {
555
- var instruction = new ProcessingInstruction(node.name, node.data);
447
+ const instruction = new ProcessingInstruction(node.name, node.data);
556
448
  if (node["x-name"] != null) {
557
449
  instruction["x-name"] = node["x-name"];
558
450
  instruction["x-publicId"] = node["x-publicId"];
@@ -561,7 +453,7 @@
561
453
  result = instruction;
562
454
  }
563
455
  else {
564
- throw new Error("Not implemented yet: ".concat(node.type));
456
+ throw new Error(`Not implemented yet: ${node.type}`);
565
457
  }
566
458
  result.startIndex = node.startIndex;
567
459
  result.endIndex = node.endIndex;
@@ -570,266 +462,67 @@
570
462
  }
571
463
  return result;
572
464
  }
573
- node.cloneNode = cloneNode;
465
+ /**
466
+ * Clone a list of child nodes.
467
+ * @param childs The child nodes to clone.
468
+ * @returns A list of cloned child nodes.
469
+ */
574
470
  function cloneChildren(childs) {
575
- var children = childs.map(function (child) { return cloneNode(child, true); });
576
- for (var i = 1; i < children.length; i++) {
577
- children[i].prev = children[i - 1];
578
- children[i - 1].next = children[i];
471
+ const children = childs.map((child) => cloneNode(child, true));
472
+ for (let index = 1; index < children.length; index++) {
473
+ children[index].prev = children[index - 1];
474
+ children[index - 1].next = children[index];
579
475
  }
580
476
  return children;
581
477
  }
582
- return node;
583
- }
584
-
585
- var hasRequiredLib$2;
586
478
 
587
- function requireLib$2 () {
588
- if (hasRequiredLib$2) return lib$2;
589
- hasRequiredLib$2 = 1;
590
- (function (exports$1) {
591
- var __createBinding = (lib$2 && lib$2.__createBinding) || (Object.create ? (function(o, m, k, k2) {
592
- if (k2 === undefined) k2 = k;
593
- var desc = Object.getOwnPropertyDescriptor(m, k);
594
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
595
- desc = { enumerable: true, get: function() { return m[k]; } };
596
- }
597
- Object.defineProperty(o, k2, desc);
598
- }) : (function(o, m, k, k2) {
599
- if (k2 === undefined) k2 = k;
600
- o[k2] = m[k];
601
- }));
602
- var __exportStar = (lib$2 && lib$2.__exportStar) || function(m, exports$1) {
603
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
604
- };
605
- Object.defineProperty(exports$1, "__esModule", { value: true });
606
- exports$1.DomHandler = void 0;
607
- var domelementtype_1 = /*@__PURE__*/ requireLib$3();
608
- var node_js_1 = /*@__PURE__*/ requireNode();
609
- __exportStar(/*@__PURE__*/ requireNode(), exports$1);
610
- // Default options
611
- var defaultOpts = {
612
- withStartIndices: false,
613
- withEndIndices: false,
614
- xmlMode: false,
615
- };
616
- var DomHandler = /** @class */ (function () {
617
- /**
618
- * @param callback Called once parsing has completed.
619
- * @param options Settings for the handler.
620
- * @param elementCB Callback whenever a tag is closed.
621
- */
622
- function DomHandler(callback, options, elementCB) {
623
- /** The elements of the DOM */
624
- this.dom = [];
625
- /** The root element for the DOM */
626
- this.root = new node_js_1.Document(this.dom);
627
- /** Indicated whether parsing has been completed. */
628
- this.done = false;
629
- /** Stack of open tags. */
630
- this.tagStack = [this.root];
631
- /** A data node that is still being written to. */
632
- this.lastNode = null;
633
- /** Reference to the parser instance. Used for location information. */
634
- this.parser = null;
635
- // Make it possible to skip arguments, for backwards-compatibility
636
- if (typeof options === "function") {
637
- elementCB = options;
638
- options = defaultOpts;
639
- }
640
- if (typeof callback === "object") {
641
- options = callback;
642
- callback = undefined;
643
- }
644
- this.callback = callback !== null && callback !== void 0 ? callback : null;
645
- this.options = options !== null && options !== void 0 ? options : defaultOpts;
646
- this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
647
- }
648
- DomHandler.prototype.onparserinit = function (parser) {
649
- this.parser = parser;
650
- };
651
- // Resets the handler back to starting state
652
- DomHandler.prototype.onreset = function () {
653
- this.dom = [];
654
- this.root = new node_js_1.Document(this.dom);
655
- this.done = false;
656
- this.tagStack = [this.root];
657
- this.lastNode = null;
658
- this.parser = null;
659
- };
660
- // Signals the handler that parsing is done
661
- DomHandler.prototype.onend = function () {
662
- if (this.done)
663
- return;
664
- this.done = true;
665
- this.parser = null;
666
- this.handleCallback(null);
667
- };
668
- DomHandler.prototype.onerror = function (error) {
669
- this.handleCallback(error);
670
- };
671
- DomHandler.prototype.onclosetag = function () {
672
- this.lastNode = null;
673
- var elem = this.tagStack.pop();
674
- if (this.options.withEndIndices) {
675
- elem.endIndex = this.parser.endIndex;
676
- }
677
- if (this.elementCB)
678
- this.elementCB(elem);
679
- };
680
- DomHandler.prototype.onopentag = function (name, attribs) {
681
- var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined;
682
- var element = new node_js_1.Element(name, attribs, undefined, type);
683
- this.addNode(element);
684
- this.tagStack.push(element);
685
- };
686
- DomHandler.prototype.ontext = function (data) {
687
- var lastNode = this.lastNode;
688
- if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) {
689
- lastNode.data += data;
690
- if (this.options.withEndIndices) {
691
- lastNode.endIndex = this.parser.endIndex;
692
- }
693
- }
694
- else {
695
- var node = new node_js_1.Text(data);
696
- this.addNode(node);
697
- this.lastNode = node;
698
- }
699
- };
700
- DomHandler.prototype.oncomment = function (data) {
701
- if (this.lastNode && this.lastNode.type === domelementtype_1.ElementType.Comment) {
702
- this.lastNode.data += data;
703
- return;
704
- }
705
- var node = new node_js_1.Comment(data);
706
- this.addNode(node);
707
- this.lastNode = node;
708
- };
709
- DomHandler.prototype.oncommentend = function () {
710
- this.lastNode = null;
711
- };
712
- DomHandler.prototype.oncdatastart = function () {
713
- var text = new node_js_1.Text("");
714
- var node = new node_js_1.CDATA([text]);
715
- this.addNode(node);
716
- text.parent = node;
717
- this.lastNode = text;
718
- };
719
- DomHandler.prototype.oncdataend = function () {
720
- this.lastNode = null;
721
- };
722
- DomHandler.prototype.onprocessinginstruction = function (name, data) {
723
- var node = new node_js_1.ProcessingInstruction(name, data);
724
- this.addNode(node);
725
- };
726
- DomHandler.prototype.handleCallback = function (error) {
727
- if (typeof this.callback === "function") {
728
- this.callback(error, this.dom);
729
- }
730
- else if (error) {
731
- throw error;
732
- }
733
- };
734
- DomHandler.prototype.addNode = function (node) {
735
- var parent = this.tagStack[this.tagStack.length - 1];
736
- var previousSibling = parent.children[parent.children.length - 1];
737
- if (this.options.withStartIndices) {
738
- node.startIndex = this.parser.startIndex;
739
- }
740
- if (this.options.withEndIndices) {
741
- node.endIndex = this.parser.endIndex;
742
- }
743
- parent.children.push(node);
744
- if (previousSibling) {
745
- node.prev = previousSibling;
746
- previousSibling.next = node;
747
- }
748
- node.parent = parent;
749
- this.lastNode = null;
750
- };
751
- return DomHandler;
752
- }());
753
- exports$1.DomHandler = DomHandler;
754
- exports$1.default = DomHandler;
755
- } (lib$2));
756
- return lib$2;
757
- }
758
-
759
- var constants = {};
760
-
761
- var hasRequiredConstants;
762
-
763
- function requireConstants () {
764
- if (hasRequiredConstants) return constants;
765
- hasRequiredConstants = 1;
766
- (function (exports$1) {
767
- Object.defineProperty(exports$1, "__esModule", { value: true });
768
- exports$1.CARRIAGE_RETURN_PLACEHOLDER_REGEX = exports$1.CARRIAGE_RETURN_PLACEHOLDER = exports$1.CARRIAGE_RETURN_REGEX = exports$1.CARRIAGE_RETURN = exports$1.CASE_SENSITIVE_TAG_NAMES_MAP = exports$1.CASE_SENSITIVE_TAG_NAMES = void 0;
769
- /**
770
- * SVG elements are case-sensitive.
771
- *
772
- * @see https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z
773
- */
774
- exports$1.CASE_SENSITIVE_TAG_NAMES = [
775
- 'animateMotion',
776
- 'animateTransform',
777
- 'clipPath',
778
- 'feBlend',
779
- 'feColorMatrix',
780
- 'feComponentTransfer',
781
- 'feComposite',
782
- 'feConvolveMatrix',
783
- 'feDiffuseLighting',
784
- 'feDisplacementMap',
785
- 'feDropShadow',
786
- 'feFlood',
787
- 'feFuncA',
788
- 'feFuncB',
789
- 'feFuncG',
790
- 'feFuncR',
791
- 'feGaussianBlur',
792
- 'feImage',
793
- 'feMerge',
794
- 'feMergeNode',
795
- 'feMorphology',
796
- 'feOffset',
797
- 'fePointLight',
798
- 'feSpecularLighting',
799
- 'feSpotLight',
800
- 'feTile',
801
- 'feTurbulence',
802
- 'foreignObject',
803
- 'linearGradient',
804
- 'radialGradient',
805
- 'textPath',
806
- ];
807
- exports$1.CASE_SENSITIVE_TAG_NAMES_MAP = exports$1.CASE_SENSITIVE_TAG_NAMES.reduce(function (accumulator, tagName) {
808
- accumulator[tagName.toLowerCase()] = tagName;
809
- return accumulator;
810
- }, {});
811
- exports$1.CARRIAGE_RETURN = '\r';
812
- exports$1.CARRIAGE_RETURN_REGEX = new RegExp(exports$1.CARRIAGE_RETURN, 'g');
813
- exports$1.CARRIAGE_RETURN_PLACEHOLDER = "__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now().toString(), "__");
814
- exports$1.CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(exports$1.CARRIAGE_RETURN_PLACEHOLDER, 'g');
815
-
816
- } (constants));
817
- return constants;
818
- }
479
+ /**
480
+ * SVG elements are case-sensitive.
481
+ *
482
+ * @see https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z
483
+ */
484
+ var CASE_SENSITIVE_TAG_NAMES = [
485
+ 'animateMotion',
486
+ 'animateTransform',
487
+ 'clipPath',
488
+ 'feBlend',
489
+ 'feColorMatrix',
490
+ 'feComponentTransfer',
491
+ 'feComposite',
492
+ 'feConvolveMatrix',
493
+ 'feDiffuseLighting',
494
+ 'feDisplacementMap',
495
+ 'feDropShadow',
496
+ 'feFlood',
497
+ 'feFuncA',
498
+ 'feFuncB',
499
+ 'feFuncG',
500
+ 'feFuncR',
501
+ 'feGaussianBlur',
502
+ 'feImage',
503
+ 'feMerge',
504
+ 'feMergeNode',
505
+ 'feMorphology',
506
+ 'feOffset',
507
+ 'fePointLight',
508
+ 'feSpecularLighting',
509
+ 'feSpotLight',
510
+ 'feTile',
511
+ 'feTurbulence',
512
+ 'foreignObject',
513
+ 'linearGradient',
514
+ 'radialGradient',
515
+ 'textPath',
516
+ ];
517
+ var CASE_SENSITIVE_TAG_NAMES_MAP = CASE_SENSITIVE_TAG_NAMES.reduce(function (accumulator, tagName) {
518
+ accumulator[tagName.toLowerCase()] = tagName;
519
+ return accumulator;
520
+ }, {});
819
521
 
820
- var hasRequiredUtilities$2;
821
-
822
- function requireUtilities$2 () {
823
- if (hasRequiredUtilities$2) return utilities$2;
824
- hasRequiredUtilities$2 = 1;
825
- Object.defineProperty(utilities$2, "__esModule", { value: true });
826
- utilities$2.formatAttributes = formatAttributes;
827
- utilities$2.hasOpenTag = hasOpenTag;
828
- utilities$2.escapeSpecialCharacters = escapeSpecialCharacters;
829
- utilities$2.revertEscapedCharacters = revertEscapedCharacters;
830
- utilities$2.formatDOM = formatDOM;
831
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
832
- var constants_1 = requireConstants();
522
+ var CARRIAGE_RETURN = '\r';
523
+ var CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, 'g');
524
+ var CARRIAGE_RETURN_PLACEHOLDER = "__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now().toString(), "__");
525
+ var CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(CARRIAGE_RETURN_PLACEHOLDER, 'g');
833
526
  /**
834
527
  * Gets case-sensitive tag name.
835
528
  *
@@ -837,7 +530,7 @@
837
530
  * @returns - Case-sensitive tag name.
838
531
  */
839
532
  function getCaseSensitiveTagName(tagName) {
840
- return constants_1.CASE_SENSITIVE_TAG_NAMES_MAP[tagName];
533
+ return CASE_SENSITIVE_TAG_NAMES_MAP[tagName];
841
534
  }
842
535
  /**
843
536
  * Formats DOM attributes to a hash map.
@@ -900,7 +593,7 @@
900
593
  * @returns - HTML string with escaped special characters.
901
594
  */
902
595
  function escapeSpecialCharacters(html) {
903
- return html.replace(constants_1.CARRIAGE_RETURN_REGEX, constants_1.CARRIAGE_RETURN_PLACEHOLDER);
596
+ return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
904
597
  }
905
598
  /**
906
599
  * Reverts escaped special characters back to actual characters.
@@ -909,7 +602,7 @@
909
602
  * @returns - Text with escaped characters reverted.
910
603
  */
911
604
  function revertEscapedCharacters(text) {
912
- return text.replace(constants_1.CARRIAGE_RETURN_PLACEHOLDER_REGEX, constants_1.CARRIAGE_RETURN);
605
+ return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
913
606
  }
914
607
  /**
915
608
  * Transforms DOM nodes to `domhandler` nodes.
@@ -933,7 +626,7 @@
933
626
  case 1: {
934
627
  var tagName = formatTagName(node.nodeName);
935
628
  // script, style, or tag
936
- current = new domhandler_1.Element(tagName, formatAttributes(node.attributes));
629
+ current = new Element(tagName, formatAttributes(node.attributes));
937
630
  current.children = formatDOM(
938
631
  // template children are on content
939
632
  tagName === 'template'
@@ -941,12 +634,14 @@
941
634
  : node.childNodes, current);
942
635
  break;
943
636
  }
637
+ /* v8 ignore start */
944
638
  case 3:
945
- current = new domhandler_1.Text(revertEscapedCharacters((_a = node.nodeValue) !== null && _a !== void 0 ? _a : ''));
639
+ current = new Text(revertEscapedCharacters((_a = node.nodeValue) !== null && _a !== void 0 ? _a : ''));
946
640
  break;
947
641
  case 8:
948
- current = new domhandler_1.Comment((_b = node.nodeValue) !== null && _b !== void 0 ? _b : '');
642
+ current = new Comment((_b = node.nodeValue) !== null && _b !== void 0 ? _b : '');
949
643
  break;
644
+ /* v8 ignore stop */
950
645
  default:
951
646
  continue;
952
647
  }
@@ -963,7 +658,7 @@
963
658
  domNodes.push(current);
964
659
  }
965
660
  if (directive) {
966
- current = new domhandler_1.ProcessingInstruction(directive.substring(0, directive.indexOf(' ')).toLowerCase(), directive);
661
+ current = new ProcessingInstruction(directive.substring(0, directive.indexOf(' ')).toLowerCase(), directive);
967
662
  current.next = (_d = domNodes[0]) !== null && _d !== void 0 ? _d : null;
968
663
  current.parent = parent;
969
664
  domNodes.unshift(current);
@@ -973,18 +668,7 @@
973
668
  }
974
669
  return domNodes;
975
670
  }
976
-
977
- return utilities$2;
978
- }
979
671
 
980
- var hasRequiredDomparser;
981
-
982
- function requireDomparser () {
983
- if (hasRequiredDomparser) return domparser;
984
- hasRequiredDomparser = 1;
985
- Object.defineProperty(domparser, "__esModule", { value: true });
986
- domparser.default = domparser$1;
987
- var utilities_1 = requireUtilities$2();
988
672
  // constants
989
673
  var HTML = 'html';
990
674
  var HEAD = 'head';
@@ -992,15 +676,13 @@
992
676
  var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
993
677
  // falls back to `parseFromString` if `createHTMLDocument` cannot be used
994
678
  /* eslint-disable @typescript-eslint/no-unused-vars */
995
- /* istanbul ignore start */
679
+ /* v8 ignore start */
996
680
  var parseFromDocument = function (html, tagName) {
997
681
  throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
998
682
  };
999
683
  var parseFromString = function (html, tagName) {
1000
684
  throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
1001
685
  };
1002
- /* istanbul ignore stop */
1003
- /* eslint-enable @typescript-eslint/no-unused-vars */
1004
686
  var DOMParser = typeof window === 'object' && window.DOMParser;
1005
687
  /**
1006
688
  * DOMParser (performance: slow).
@@ -1018,11 +700,9 @@
1018
700
  * @returns - Document.
1019
701
  */
1020
702
  parseFromString = function (html, tagName) {
1021
- /* istanbul ignore start */
1022
703
  if (tagName) {
1023
704
  html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
1024
705
  }
1025
- /* istanbul ignore stop */
1026
706
  return domParser_1.parseFromString(html, mimeType_1);
1027
707
  };
1028
708
  parseFromDocument = parseFromString;
@@ -1043,7 +723,6 @@
1043
723
  * @returns - Document
1044
724
  */
1045
725
  parseFromDocument = function (html, tagName) {
1046
- /* istanbul ignore start */
1047
726
  if (tagName) {
1048
727
  var element = htmlDocument_1.documentElement.querySelector(tagName);
1049
728
  if (element) {
@@ -1051,7 +730,6 @@
1051
730
  }
1052
731
  return htmlDocument_1;
1053
732
  }
1054
- /* istanbul ignore stop */
1055
733
  htmlDocument_1.documentElement.innerHTML = html;
1056
734
  return htmlDocument_1;
1057
735
  };
@@ -1076,19 +754,18 @@
1076
754
  return template.content.childNodes;
1077
755
  };
1078
756
  }
1079
- var createNodeList = /* istanbul ignore next */ function () {
1080
- return document.createDocumentFragment().childNodes;
1081
- };
757
+ var createNodeList = function () { return document.createDocumentFragment().childNodes; };
758
+ /* v8 ignore stop */
1082
759
  /**
1083
760
  * Parses HTML string to DOM nodes.
1084
761
  *
1085
762
  * @param html - HTML markup.
1086
763
  * @returns - DOM nodes.
1087
764
  */
1088
- function domparser$1(html) {
765
+ function domparser(html) {
1089
766
  var _a, _b, _c, _d, _e, _f;
1090
767
  // Escape special characters before parsing
1091
- html = (0, utilities_1.escapeSpecialCharacters)(html);
768
+ html = escapeSpecialCharacters(html);
1092
769
  var match = FIRST_TAG_REGEX.exec(html);
1093
770
  var firstTagName = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1094
771
  switch (firstTagName) {
@@ -1096,14 +773,12 @@
1096
773
  var doc = parseFromString(html);
1097
774
  // the created document may come with filler head/body elements,
1098
775
  // so make sure to remove them if they don't actually exist
1099
- if (!(0, utilities_1.hasOpenTag)(html, HEAD)) {
776
+ if (!hasOpenTag(html, HEAD)) {
1100
777
  var element = doc.querySelector(HEAD);
1101
- /* istanbul ignore next */
1102
778
  (_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
1103
779
  }
1104
- if (!(0, utilities_1.hasOpenTag)(html, BODY)) {
780
+ if (!hasOpenTag(html, BODY)) {
1105
781
  var element = doc.querySelector(BODY);
1106
- /* istanbul ignore next */
1107
782
  (_c = element === null || element === void 0 ? void 0 : element.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(element);
1108
783
  }
1109
784
  return doc.querySelectorAll(HTML);
@@ -1112,41 +787,26 @@
1112
787
  case BODY: {
1113
788
  var elements = parseFromDocument(html).querySelectorAll(firstTagName);
1114
789
  // if there's a sibling element, then return both elements
1115
- if ((0, utilities_1.hasOpenTag)(html, BODY) && (0, utilities_1.hasOpenTag)(html, HEAD)) {
1116
- /* istanbul ignore next */
790
+ /* v8 ignore next */
791
+ if (hasOpenTag(html, BODY) && hasOpenTag(html, HEAD)) {
1117
792
  return (_e = (_d = elements[0].parentNode) === null || _d === void 0 ? void 0 : _d.childNodes) !== null && _e !== void 0 ? _e : createNodeList();
1118
793
  }
1119
794
  return elements;
1120
795
  }
1121
796
  // low-level tag or text
797
+ /* v8 ignore start */
1122
798
  default: {
1123
799
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1124
800
  if (parseFromTemplate) {
1125
801
  return parseFromTemplate(html);
1126
802
  }
1127
- /* istanbul ignore start */
1128
803
  var element = parseFromDocument(html, BODY).querySelector(BODY);
1129
804
  return (_f = element === null || element === void 0 ? void 0 : element.childNodes) !== null && _f !== void 0 ? _f : createNodeList();
1130
- /* istanbul ignore stop */
1131
805
  }
806
+ /* v8 ignore stop */
1132
807
  }
1133
808
  }
1134
-
1135
- return domparser;
1136
- }
1137
-
1138
- var hasRequiredHtmlToDom;
1139
809
 
1140
- function requireHtmlToDom () {
1141
- if (hasRequiredHtmlToDom) return htmlToDom;
1142
- hasRequiredHtmlToDom = 1;
1143
- var __importDefault = (htmlToDom && htmlToDom.__importDefault) || function (mod) {
1144
- return (mod && mod.__esModule) ? mod : { "default": mod };
1145
- };
1146
- Object.defineProperty(htmlToDom, "__esModule", { value: true });
1147
- htmlToDom.default = HTMLDOMParser;
1148
- var domparser_1 = __importDefault(requireDomparser());
1149
- var utilities_1 = requireUtilities$2();
1150
810
  var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
1151
811
  /**
1152
812
  * Parses HTML string to DOM nodes in browser.
@@ -1164,8 +824,10 @@
1164
824
  // match directive
1165
825
  var match = DIRECTIVE_REGEX.exec(html);
1166
826
  var directive = match ? match[1] : undefined;
1167
- return (0, utilities_1.formatDOM)((0, domparser_1.default)(html), null, directive);
827
+ return formatDOM(domparser(html), null, directive);
1168
828
  }
829
+
830
+ htmlToDom.default = HTMLDOMParser;
1169
831
 
1170
832
  return htmlToDom;
1171
833
  }
@@ -2631,9 +2293,9 @@
2631
2293
  exports$1.returnFirstArg = exports$1.canTextBeChildOfNode = exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports$1.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2632
2294
  exports$1.isCustomComponent = isCustomComponent;
2633
2295
  exports$1.setStyleProp = setStyleProp;
2634
- var react_1 = require$$0;
2635
- var style_to_js_1 = __importDefault(requireCjs());
2636
- var RESERVED_SVG_MATHML_ELEMENTS = new Set([
2296
+ const react_1 = require$$0;
2297
+ const style_to_js_1 = __importDefault(requireCjs());
2298
+ const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2637
2299
  'annotation-xml',
2638
2300
  'color-profile',
2639
2301
  'font-face',
@@ -2665,7 +2327,7 @@
2665
2327
  }
2666
2328
  return true;
2667
2329
  }
2668
- var styleOptions = {
2330
+ const styleOptions = {
2669
2331
  reactCompat: true,
2670
2332
  };
2671
2333
  /**
@@ -2714,9 +2376,7 @@
2714
2376
  * @param node - Element node.
2715
2377
  * @returns - Whether the node can contain text nodes.
2716
2378
  */
2717
- var canTextBeChildOfNode = function (node) {
2718
- return !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2719
- };
2379
+ const canTextBeChildOfNode = (node) => !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2720
2380
  exports$1.canTextBeChildOfNode = canTextBeChildOfNode;
2721
2381
  /**
2722
2382
  * Returns the first argument as is.
@@ -2724,7 +2384,7 @@
2724
2384
  * @param arg - The argument to be returned.
2725
2385
  * @returns - The input argument `arg`.
2726
2386
  */
2727
- var returnFirstArg = function (arg) { return arg; };
2387
+ const returnFirstArg = (arg) => arg;
2728
2388
  exports$1.returnFirstArg = returnFirstArg;
2729
2389
 
2730
2390
  } (utilities$1));
@@ -2738,13 +2398,13 @@
2738
2398
  hasRequiredAttributesToProps = 1;
2739
2399
  Object.defineProperty(attributesToProps, "__esModule", { value: true });
2740
2400
  attributesToProps.default = attributesToProps$1;
2741
- var react_property_1 = requireLib$1();
2742
- var utilities_1 = requireUtilities();
2401
+ const react_property_1 = requireLib$1();
2402
+ const utilities_1 = requireUtilities();
2743
2403
  // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2744
2404
  // https://developer.mozilla.org/docs/Web/HTML/Attributes
2745
- var UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2746
- var UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2747
- var valueOnlyInputs = {
2405
+ const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2406
+ const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2407
+ const valueOnlyInputs = {
2748
2408
  reset: true,
2749
2409
  submit: true,
2750
2410
  };
@@ -2755,22 +2415,21 @@
2755
2415
  * @param nodeName - DOM node name.
2756
2416
  * @returns - React props.
2757
2417
  */
2758
- function attributesToProps$1(attributes, nodeName) {
2759
- if (attributes === void 0) { attributes = {}; }
2760
- var props = {};
2761
- var isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2762
- for (var attributeName in attributes) {
2763
- var attributeValue = attributes[attributeName];
2418
+ function attributesToProps$1(attributes = {}, nodeName) {
2419
+ const props = {};
2420
+ const isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2421
+ for (const attributeName in attributes) {
2422
+ const attributeValue = attributes[attributeName];
2764
2423
  // ARIA (aria-*) or custom data (data-*) attribute
2765
2424
  if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2766
2425
  props[attributeName] = attributeValue;
2767
2426
  continue;
2768
2427
  }
2769
2428
  // convert HTML/SVG attribute to React prop
2770
- var attributeNameLowerCased = attributeName.toLowerCase();
2771
- var propName = getPropName(attributeNameLowerCased);
2429
+ const attributeNameLowerCased = attributeName.toLowerCase();
2430
+ let propName = getPropName(attributeNameLowerCased);
2772
2431
  if (propName) {
2773
- var propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2432
+ const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2774
2433
  // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2775
2434
  if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2776
2435
  UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
@@ -2825,10 +2484,10 @@
2825
2484
  };
2826
2485
  Object.defineProperty(domToReact, "__esModule", { value: true });
2827
2486
  domToReact.default = domToReact$1;
2828
- var react_1 = require$$0;
2829
- var attributes_to_props_1 = __importDefault(requireAttributesToProps());
2830
- var utilities_1 = requireUtilities();
2831
- var React = {
2487
+ const react_1 = require$$0;
2488
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2489
+ const utilities_1 = requireUtilities();
2490
+ const React = {
2832
2491
  cloneElement: react_1.cloneElement,
2833
2492
  createElement: react_1.createElement,
2834
2493
  isValidElement: react_1.isValidElement,
@@ -2840,19 +2499,18 @@
2840
2499
  * @param options - Options.
2841
2500
  * @returns - String or JSX element(s).
2842
2501
  */
2843
- function domToReact$1(nodes, options) {
2502
+ function domToReact$1(nodes, options = {}) {
2844
2503
  var _a, _b, _c, _d, _e;
2845
- if (options === void 0) { options = {}; }
2846
- var reactElements = [];
2847
- var hasReplace = typeof options.replace === 'function';
2848
- var transform = (_a = options.transform) !== null && _a !== void 0 ? _a : utilities_1.returnFirstArg;
2849
- var _f = (_b = options.library) !== null && _b !== void 0 ? _b : React, cloneElement = _f.cloneElement, createElement = _f.createElement, isValidElement = _f.isValidElement;
2850
- var nodesLength = nodes.length;
2851
- for (var index = 0; index < nodesLength; index++) {
2852
- var node = nodes[index];
2504
+ const reactElements = [];
2505
+ const hasReplace = typeof options.replace === 'function';
2506
+ const transform = (_a = options.transform) !== null && _a !== void 0 ? _a : utilities_1.returnFirstArg;
2507
+ const { cloneElement, createElement, isValidElement } = (_b = options.library) !== null && _b !== void 0 ? _b : React;
2508
+ const nodesLength = nodes.length;
2509
+ for (let index = 0; index < nodesLength; index++) {
2510
+ const node = nodes[index];
2853
2511
  // replace with custom React element (if present)
2854
2512
  if (hasReplace) {
2855
- var replaceElement = (_c = options.replace) === null || _c === void 0 ? void 0 : _c.call(options, node, index);
2513
+ let replaceElement = (_c = options.replace) === null || _c === void 0 ? void 0 : _c.call(options, node, index);
2856
2514
  if (isValidElement(replaceElement)) {
2857
2515
  // set "key" prop for sibling elements
2858
2516
  // https://react.dev/learn/rendering-lists#rules-of-keys
@@ -2866,7 +2524,7 @@
2866
2524
  }
2867
2525
  }
2868
2526
  if (node.type === 'text') {
2869
- var isWhitespace = !node.data.trim().length;
2527
+ const isWhitespace = !node.data.trim().length;
2870
2528
  // We have a whitespace node that can't be nested in its parent
2871
2529
  // so skip it
2872
2530
  if (isWhitespace &&
@@ -2884,8 +2542,8 @@
2884
2542
  reactElements.push(transform(node.data, node, index));
2885
2543
  continue;
2886
2544
  }
2887
- var element = node;
2888
- var props = {};
2545
+ const element = node;
2546
+ let props = {};
2889
2547
  if (skipAttributesToProps(element)) {
2890
2548
  (0, utilities_1.setStyleProp)(element.attribs.style, element.attribs);
2891
2549
  props = element.attribs;
@@ -2894,7 +2552,7 @@
2894
2552
  else if (element.attribs) {
2895
2553
  props = (0, attributes_to_props_1.default)(element.attribs, element.name);
2896
2554
  }
2897
- var children = void 0;
2555
+ let children;
2898
2556
  switch (node.type) {
2899
2557
  case 'script':
2900
2558
  case 'style':
@@ -2947,30 +2605,627 @@
2947
2605
  return domToReact;
2948
2606
  }
2949
2607
 
2608
+ /** Types of elements found in htmlparser2's DOM */
2609
+ var ElementType;
2610
+ (function (ElementType) {
2611
+ /** Type for the root element of a document */
2612
+ ElementType["Root"] = "root";
2613
+ /** Type for Text */
2614
+ ElementType["Text"] = "text";
2615
+ /** Type for <? ... ?> */
2616
+ ElementType["Directive"] = "directive";
2617
+ /** Type for <!-- ... --> */
2618
+ ElementType["Comment"] = "comment";
2619
+ /** Type for <script> tags */
2620
+ ElementType["Script"] = "script";
2621
+ /** Type for <style> tags */
2622
+ ElementType["Style"] = "style";
2623
+ /** Type for Any tag */
2624
+ ElementType["Tag"] = "tag";
2625
+ /** Type for <![CDATA[ ... ]]> */
2626
+ ElementType["CDATA"] = "cdata";
2627
+ /** Type for <!doctype ...> */
2628
+ ElementType["Doctype"] = "doctype";
2629
+ })(ElementType || (ElementType = {}));
2630
+ /**
2631
+ * Tests whether an element is a tag or not.
2632
+ * @param element Element to test
2633
+ * @param element.type Node type discriminator to check.
2634
+ */
2635
+ function isTag$1(element) {
2636
+ return (element.type === ElementType.Tag ||
2637
+ element.type === ElementType.Script ||
2638
+ element.type === ElementType.Style);
2639
+ }
2640
+ // Exports for backwards compatibility
2641
+ /** Type for the root element of a document */
2642
+ // eslint-disable-next-line prefer-destructuring
2643
+ ElementType.Root;
2644
+ /** Type for Text */
2645
+ // eslint-disable-next-line prefer-destructuring
2646
+ ElementType.Text;
2647
+ /** Type for <? ... ?> */
2648
+ // eslint-disable-next-line prefer-destructuring
2649
+ ElementType.Directive;
2650
+ /** Type for <!-- ... --> */
2651
+ // eslint-disable-next-line prefer-destructuring
2652
+ ElementType.Comment;
2653
+ /** Type for <script> tags */
2654
+ // eslint-disable-next-line prefer-destructuring
2655
+ ElementType.Script;
2656
+ /** Type for <style> tags */
2657
+ // eslint-disable-next-line prefer-destructuring
2658
+ ElementType.Style;
2659
+ /** Type for Any tag */
2660
+ // eslint-disable-next-line prefer-destructuring
2661
+ ElementType.Tag;
2662
+ /** Type for <![CDATA[ ... ]]> */
2663
+ // eslint-disable-next-line prefer-destructuring
2664
+ ElementType.CDATA;
2665
+ /** Type for <!doctype ...> */
2666
+ // eslint-disable-next-line prefer-destructuring
2667
+ ElementType.Doctype;
2668
+
2669
+ /**
2670
+ * This object will be used as the prototype for Nodes when creating a
2671
+ * DOM-Level-1-compliant structure.
2672
+ */
2673
+ class Node {
2674
+ /** Parent of the node */
2675
+ parent = null;
2676
+ /** Previous sibling */
2677
+ prev = null;
2678
+ /** Next sibling */
2679
+ next = null;
2680
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
2681
+ startIndex = null;
2682
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
2683
+ endIndex = null;
2684
+ // Read-write aliases for properties
2685
+ /**
2686
+ * Same as {@link parent}.
2687
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2688
+ */
2689
+ get parentNode() {
2690
+ return this.parent;
2691
+ }
2692
+ set parentNode(parent) {
2693
+ this.parent = parent;
2694
+ }
2695
+ /**
2696
+ * Same as {@link prev}.
2697
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2698
+ */
2699
+ get previousSibling() {
2700
+ return this.prev;
2701
+ }
2702
+ set previousSibling(previous) {
2703
+ this.prev = previous;
2704
+ }
2705
+ /**
2706
+ * Same as {@link next}.
2707
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2708
+ */
2709
+ get nextSibling() {
2710
+ return this.next;
2711
+ }
2712
+ set nextSibling(next) {
2713
+ this.next = next;
2714
+ }
2715
+ /**
2716
+ * Clone this node, and optionally its children.
2717
+ * @param recursive Clone child nodes as well.
2718
+ * @returns A clone of the node.
2719
+ */
2720
+ cloneNode(recursive = false) {
2721
+ return cloneNode(this, recursive);
2722
+ }
2723
+ }
2724
+ /**
2725
+ * A node that contains some data.
2726
+ */
2727
+ class DataNode extends Node {
2728
+ data;
2729
+ /**
2730
+ * @param data The content of the data node
2731
+ */
2732
+ constructor(data) {
2733
+ super();
2734
+ this.data = data;
2735
+ }
2736
+ /**
2737
+ * Same as {@link data}.
2738
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2739
+ */
2740
+ get nodeValue() {
2741
+ return this.data;
2742
+ }
2743
+ set nodeValue(data) {
2744
+ this.data = data;
2745
+ }
2746
+ }
2747
+ /**
2748
+ * Text within the document.
2749
+ */
2750
+ class Text extends DataNode {
2751
+ type = ElementType.Text;
2752
+ get nodeType() {
2753
+ return 3;
2754
+ }
2755
+ }
2756
+ /**
2757
+ * Comments within the document.
2758
+ */
2759
+ class Comment extends DataNode {
2760
+ type = ElementType.Comment;
2761
+ get nodeType() {
2762
+ return 8;
2763
+ }
2764
+ }
2765
+ /**
2766
+ * Processing instructions, including doc types.
2767
+ */
2768
+ class ProcessingInstruction extends DataNode {
2769
+ type = ElementType.Directive;
2770
+ name;
2771
+ constructor(name, data) {
2772
+ super(data);
2773
+ this.name = name;
2774
+ }
2775
+ get nodeType() {
2776
+ return 1;
2777
+ }
2778
+ /** If this is a doctype, the document type name (parse5 only). */
2779
+ "x-name";
2780
+ /** If this is a doctype, the document type public identifier (parse5 only). */
2781
+ "x-publicId";
2782
+ /** If this is a doctype, the document type system identifier (parse5 only). */
2783
+ "x-systemId";
2784
+ }
2785
+ /**
2786
+ * A node that can have children.
2787
+ */
2788
+ class NodeWithChildren extends Node {
2789
+ children;
2790
+ /**
2791
+ * @param children Children of the node. Only certain node types can have children.
2792
+ */
2793
+ constructor(children) {
2794
+ super();
2795
+ this.children = children;
2796
+ }
2797
+ // Aliases
2798
+ /** First child of the node. */
2799
+ get firstChild() {
2800
+ return this.children[0] ?? null;
2801
+ }
2802
+ /** Last child of the node. */
2803
+ get lastChild() {
2804
+ return this.children.length > 0
2805
+ ? this.children[this.children.length - 1]
2806
+ : null;
2807
+ }
2808
+ /**
2809
+ * Same as {@link children}.
2810
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2811
+ */
2812
+ get childNodes() {
2813
+ return this.children;
2814
+ }
2815
+ set childNodes(children) {
2816
+ this.children = children;
2817
+ }
2818
+ }
2819
+ /**
2820
+ * CDATA nodes.
2821
+ */
2822
+ class CDATA extends NodeWithChildren {
2823
+ type = ElementType.CDATA;
2824
+ get nodeType() {
2825
+ return 4;
2826
+ }
2827
+ }
2828
+ /**
2829
+ * The root node of the document.
2830
+ */
2831
+ class Document extends NodeWithChildren {
2832
+ type = ElementType.Root;
2833
+ get nodeType() {
2834
+ return 9;
2835
+ }
2836
+ }
2837
+ /**
2838
+ * An element within the DOM.
2839
+ */
2840
+ class Element extends NodeWithChildren {
2841
+ name;
2842
+ attribs;
2843
+ type;
2844
+ /**
2845
+ * @param name Name of the tag, eg. `div`, `span`.
2846
+ * @param attribs Object mapping attribute names to attribute values.
2847
+ * @param children Children of the node.
2848
+ * @param type Node type used for the new node instance.
2849
+ */
2850
+ constructor(name, attribs, children = [], type = name === "script"
2851
+ ? ElementType.Script
2852
+ : name === "style"
2853
+ ? ElementType.Style
2854
+ : ElementType.Tag) {
2855
+ super(children);
2856
+ this.name = name;
2857
+ this.attribs = attribs;
2858
+ this.type = type;
2859
+ }
2860
+ get nodeType() {
2861
+ return 1;
2862
+ }
2863
+ // DOM Level 1 aliases
2864
+ /**
2865
+ * Same as {@link name}.
2866
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2867
+ */
2868
+ get tagName() {
2869
+ return this.name;
2870
+ }
2871
+ set tagName(name) {
2872
+ this.name = name;
2873
+ }
2874
+ get attributes() {
2875
+ return Object.keys(this.attribs).map((name) => ({
2876
+ name,
2877
+ value: this.attribs[name],
2878
+ namespace: this["x-attribsNamespace"]?.[name],
2879
+ prefix: this["x-attribsPrefix"]?.[name],
2880
+ }));
2881
+ }
2882
+ /** Element namespace (parse5 only). */
2883
+ namespace;
2884
+ /** Element attribute namespaces (parse5 only). */
2885
+ "x-attribsNamespace";
2886
+ /** Element attribute namespace-related prefixes (parse5 only). */
2887
+ "x-attribsPrefix";
2888
+ }
2889
+ /**
2890
+ * Checks if `node` is an element node.
2891
+ * @param node Node to check.
2892
+ * @returns `true` if the node is an element node.
2893
+ */
2894
+ function isTag(node) {
2895
+ return isTag$1(node);
2896
+ }
2897
+ /**
2898
+ * Checks if `node` is a CDATA node.
2899
+ * @param node Node to check.
2900
+ * @returns `true` if the node is a CDATA node.
2901
+ */
2902
+ function isCDATA(node) {
2903
+ return node.type === ElementType.CDATA;
2904
+ }
2905
+ /**
2906
+ * Checks if `node` is a text node.
2907
+ * @param node Node to check.
2908
+ * @returns `true` if the node is a text node.
2909
+ */
2910
+ function isText(node) {
2911
+ return node.type === ElementType.Text;
2912
+ }
2913
+ /**
2914
+ * Checks if `node` is a comment node.
2915
+ * @param node Node to check.
2916
+ * @returns `true` if the node is a comment node.
2917
+ */
2918
+ function isComment(node) {
2919
+ return node.type === ElementType.Comment;
2920
+ }
2921
+ /**
2922
+ * Checks if `node` is a directive node.
2923
+ * @param node Node to check.
2924
+ * @returns `true` if the node is a directive node.
2925
+ */
2926
+ function isDirective(node) {
2927
+ return node.type === ElementType.Directive;
2928
+ }
2929
+ /**
2930
+ * Checks if `node` is a document node.
2931
+ * @param node Node to check.
2932
+ * @returns `true` if the node is a document node.
2933
+ */
2934
+ function isDocument(node) {
2935
+ return node.type === ElementType.Root;
2936
+ }
2937
+ /**
2938
+ * Checks if `node` has children.
2939
+ * @param node Node to check.
2940
+ * @returns `true` if the node has children.
2941
+ */
2942
+ function hasChildren(node) {
2943
+ return Object.hasOwn(node, "children");
2944
+ }
2945
+ /**
2946
+ * Clone a node, and optionally its children.
2947
+ * @param node Node to clone.
2948
+ * @param recursive Clone child nodes as well.
2949
+ * @returns A clone of the node.
2950
+ */
2951
+ function cloneNode(node, recursive = false) {
2952
+ let result;
2953
+ if (isText(node)) {
2954
+ result = new Text(node.data);
2955
+ }
2956
+ else if (isComment(node)) {
2957
+ result = new Comment(node.data);
2958
+ }
2959
+ else if (isTag(node)) {
2960
+ const children = recursive ? cloneChildren(node.children) : [];
2961
+ const clone = new Element(node.name, { ...node.attribs }, children);
2962
+ for (const child of children) {
2963
+ child.parent = clone;
2964
+ }
2965
+ if (node.namespace != null) {
2966
+ clone.namespace = node.namespace;
2967
+ }
2968
+ if (node["x-attribsNamespace"]) {
2969
+ clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
2970
+ }
2971
+ if (node["x-attribsPrefix"]) {
2972
+ clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
2973
+ }
2974
+ result = clone;
2975
+ }
2976
+ else if (isCDATA(node)) {
2977
+ const children = recursive ? cloneChildren(node.children) : [];
2978
+ const clone = new CDATA(children);
2979
+ for (const child of children) {
2980
+ child.parent = clone;
2981
+ }
2982
+ result = clone;
2983
+ }
2984
+ else if (isDocument(node)) {
2985
+ const children = recursive ? cloneChildren(node.children) : [];
2986
+ const clone = new Document(children);
2987
+ for (const child of children) {
2988
+ child.parent = clone;
2989
+ }
2990
+ if (node["x-mode"]) {
2991
+ clone["x-mode"] = node["x-mode"];
2992
+ }
2993
+ result = clone;
2994
+ }
2995
+ else if (isDirective(node)) {
2996
+ const instruction = new ProcessingInstruction(node.name, node.data);
2997
+ if (node["x-name"] != null) {
2998
+ instruction["x-name"] = node["x-name"];
2999
+ instruction["x-publicId"] = node["x-publicId"];
3000
+ instruction["x-systemId"] = node["x-systemId"];
3001
+ }
3002
+ result = instruction;
3003
+ }
3004
+ else {
3005
+ throw new Error(`Not implemented yet: ${node.type}`);
3006
+ }
3007
+ result.startIndex = node.startIndex;
3008
+ result.endIndex = node.endIndex;
3009
+ if (node.sourceCodeLocation != null) {
3010
+ result.sourceCodeLocation = node.sourceCodeLocation;
3011
+ }
3012
+ return result;
3013
+ }
3014
+ /**
3015
+ * Clone a list of child nodes.
3016
+ * @param childs The child nodes to clone.
3017
+ * @returns A list of cloned child nodes.
3018
+ */
3019
+ function cloneChildren(childs) {
3020
+ const children = childs.map((child) => cloneNode(child, true));
3021
+ for (let index = 1; index < children.length; index++) {
3022
+ children[index].prev = children[index - 1];
3023
+ children[index - 1].next = children[index];
3024
+ }
3025
+ return children;
3026
+ }
3027
+
3028
+ // Default options
3029
+ const defaultOptions = {
3030
+ withStartIndices: false,
3031
+ withEndIndices: false,
3032
+ xmlMode: false,
3033
+ };
3034
+ /**
3035
+ * Event-based handler that builds a DOM tree from parser callbacks.
3036
+ */
3037
+ class DomHandler {
3038
+ /** The elements of the DOM */
3039
+ dom = [];
3040
+ /** The root element for the DOM */
3041
+ root = new Document(this.dom);
3042
+ /** Called once parsing has completed. */
3043
+ callback;
3044
+ /** Settings for the handler. */
3045
+ options;
3046
+ /** Callback whenever a tag is closed. */
3047
+ elementCB;
3048
+ /** Indicated whether parsing has been completed. */
3049
+ done = false;
3050
+ /** Stack of open tags. */
3051
+ tagStack = [this.root];
3052
+ /** A data node that is still being written to. */
3053
+ lastNode = null;
3054
+ /** Reference to the parser instance. Used for location information. */
3055
+ parser = null;
3056
+ /**
3057
+ * @param callback Called once parsing has completed.
3058
+ * @param options Settings for the handler.
3059
+ * @param elementCB Callback whenever a tag is closed.
3060
+ */
3061
+ constructor(callback, options, elementCB) {
3062
+ // Make it possible to skip arguments, for backwards-compatibility
3063
+ if (typeof options === "function") {
3064
+ elementCB = options;
3065
+ options = defaultOptions;
3066
+ }
3067
+ if (typeof callback === "object") {
3068
+ options = callback;
3069
+ callback = undefined;
3070
+ }
3071
+ this.callback = callback ?? null;
3072
+ this.options = options ?? defaultOptions;
3073
+ this.elementCB = elementCB ?? null;
3074
+ }
3075
+ onparserinit(parser) {
3076
+ this.parser = parser;
3077
+ }
3078
+ // Resets the handler back to starting state
3079
+ onreset() {
3080
+ this.dom = [];
3081
+ this.root = new Document(this.dom);
3082
+ this.done = false;
3083
+ this.tagStack = [this.root];
3084
+ this.lastNode = null;
3085
+ this.parser = null;
3086
+ }
3087
+ // Signals the handler that parsing is done
3088
+ onend() {
3089
+ if (this.done)
3090
+ return;
3091
+ this.done = true;
3092
+ this.parser = null;
3093
+ this.handleCallback(null);
3094
+ }
3095
+ onerror(error) {
3096
+ this.handleCallback(error);
3097
+ }
3098
+ onclosetag() {
3099
+ this.lastNode = null;
3100
+ const element = this.tagStack.pop();
3101
+ if (this.options.withEndIndices && this.parser) {
3102
+ element.endIndex = this.parser.endIndex;
3103
+ }
3104
+ if (this.elementCB)
3105
+ this.elementCB(element);
3106
+ }
3107
+ onopentag(name, attribs) {
3108
+ const type = this.options.xmlMode ? ElementType.Tag : undefined;
3109
+ const element = new Element(name, attribs, undefined, type);
3110
+ this.addNode(element);
3111
+ this.tagStack.push(element);
3112
+ }
3113
+ ontext(data) {
3114
+ const { lastNode } = this;
3115
+ if (lastNode && lastNode.type === ElementType.Text) {
3116
+ lastNode.data += data;
3117
+ if (this.options.withEndIndices && this.parser) {
3118
+ lastNode.endIndex = this.parser.endIndex;
3119
+ }
3120
+ }
3121
+ else {
3122
+ const node = new Text(data);
3123
+ this.addNode(node);
3124
+ this.lastNode = node;
3125
+ }
3126
+ }
3127
+ oncomment(data) {
3128
+ if (this.lastNode && this.lastNode.type === ElementType.Comment) {
3129
+ this.lastNode.data += data;
3130
+ return;
3131
+ }
3132
+ const node = new Comment(data);
3133
+ this.addNode(node);
3134
+ this.lastNode = node;
3135
+ }
3136
+ oncommentend() {
3137
+ this.lastNode = null;
3138
+ }
3139
+ oncdatastart() {
3140
+ const text = new Text("");
3141
+ const node = new CDATA([text]);
3142
+ this.addNode(node);
3143
+ text.parent = node;
3144
+ this.lastNode = text;
3145
+ }
3146
+ oncdataend() {
3147
+ this.lastNode = null;
3148
+ }
3149
+ onprocessinginstruction(name, data) {
3150
+ const node = new ProcessingInstruction(name, data);
3151
+ this.addNode(node);
3152
+ }
3153
+ handleCallback(error) {
3154
+ if (typeof this.callback === "function") {
3155
+ this.callback(error, this.dom);
3156
+ }
3157
+ else if (error) {
3158
+ throw error;
3159
+ }
3160
+ }
3161
+ addNode(node) {
3162
+ const parent = this.tagStack[this.tagStack.length - 1];
3163
+ const previousSibling = parent.children[parent.children.length - 1];
3164
+ if (this.options.withStartIndices && this.parser) {
3165
+ node.startIndex = this.parser.startIndex;
3166
+ }
3167
+ if (this.options.withEndIndices && this.parser) {
3168
+ node.endIndex = this.parser.endIndex;
3169
+ }
3170
+ parent.children.push(node);
3171
+ if (previousSibling) {
3172
+ node.prev = previousSibling;
3173
+ previousSibling.next = node;
3174
+ }
3175
+ node.parent = parent;
3176
+ this.lastNode = null;
3177
+ }
3178
+ }
3179
+
3180
+ var dist = /*#__PURE__*/Object.freeze({
3181
+ __proto__: null,
3182
+ CDATA: CDATA,
3183
+ Comment: Comment,
3184
+ DataNode: DataNode,
3185
+ Document: Document,
3186
+ DomHandler: DomHandler,
3187
+ Element: Element,
3188
+ Node: Node,
3189
+ NodeWithChildren: NodeWithChildren,
3190
+ ProcessingInstruction: ProcessingInstruction,
3191
+ Text: Text,
3192
+ cloneNode: cloneNode,
3193
+ default: DomHandler,
3194
+ hasChildren: hasChildren,
3195
+ isCDATA: isCDATA,
3196
+ isComment: isComment,
3197
+ isDirective: isDirective,
3198
+ isDocument: isDocument,
3199
+ isTag: isTag,
3200
+ isText: isText
3201
+ });
3202
+
3203
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(dist);
3204
+
2950
3205
  var hasRequiredLib;
2951
3206
 
2952
3207
  function requireLib () {
2953
- if (hasRequiredLib) return lib$3;
3208
+ if (hasRequiredLib) return lib$1;
2954
3209
  hasRequiredLib = 1;
2955
3210
  (function (exports$1) {
2956
- var __importDefault = (lib$3 && lib$3.__importDefault) || function (mod) {
3211
+ var __importDefault = (lib$1 && lib$1.__importDefault) || function (mod) {
2957
3212
  return (mod && mod.__esModule) ? mod : { "default": mod };
2958
3213
  };
2959
3214
  Object.defineProperty(exports$1, "__esModule", { value: true });
2960
3215
  exports$1.htmlToDOM = exports$1.domToReact = exports$1.attributesToProps = exports$1.Text = exports$1.ProcessingInstruction = exports$1.Element = exports$1.Comment = void 0;
2961
3216
  exports$1.default = HTMLReactParser;
2962
- var html_dom_parser_1 = __importDefault(requireHtmlToDom());
3217
+ const html_dom_parser_1 = __importDefault(requireHtmlToDom());
2963
3218
  exports$1.htmlToDOM = html_dom_parser_1.default;
2964
- var attributes_to_props_1 = __importDefault(requireAttributesToProps());
3219
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2965
3220
  exports$1.attributesToProps = attributes_to_props_1.default;
2966
- var dom_to_react_1 = __importDefault(requireDomToReact());
3221
+ const dom_to_react_1 = __importDefault(requireDomToReact());
2967
3222
  exports$1.domToReact = dom_to_react_1.default;
2968
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
3223
+ var domhandler_1 = require$$3;
2969
3224
  Object.defineProperty(exports$1, "Comment", { enumerable: true, get: function () { return domhandler_1.Comment; } });
2970
3225
  Object.defineProperty(exports$1, "Element", { enumerable: true, get: function () { return domhandler_1.Element; } });
2971
3226
  Object.defineProperty(exports$1, "ProcessingInstruction", { enumerable: true, get: function () { return domhandler_1.ProcessingInstruction; } });
2972
3227
  Object.defineProperty(exports$1, "Text", { enumerable: true, get: function () { return domhandler_1.Text; } });
2973
- var domParserOptions = { lowerCaseAttributeNames: false };
3228
+ const domParserOptions = { lowerCaseAttributeNames: false };
2974
3229
  /**
2975
3230
  * Converts HTML string to React elements.
2976
3231
  *
@@ -2989,8 +3244,8 @@
2989
3244
  return (0, dom_to_react_1.default)((0, html_dom_parser_1.default)(html, (_a = options === null || options === void 0 ? void 0 : options.htmlparser2) !== null && _a !== void 0 ? _a : domParserOptions), options);
2990
3245
  }
2991
3246
 
2992
- } (lib$3));
2993
- return lib$3;
3247
+ } (lib$1));
3248
+ return lib$1;
2994
3249
  }
2995
3250
 
2996
3251
  var libExports = requireLib();