html-react-parser 5.2.16 → 6.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.
@@ -23,7 +23,36 @@
23
23
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
24
24
  }
25
25
 
26
- var lib$3 = {};
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
+ }
54
+
55
+ var lib$1 = {};
27
56
 
28
57
  var htmlToDom = {};
29
58
 
@@ -31,731 +60,603 @@
31
60
 
32
61
  var utilities$2 = {};
33
62
 
34
- var lib$2 = {};
35
-
36
- var lib$1 = {};
37
-
38
- var hasRequiredLib$3;
39
-
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;
63
+ /** Types of elements found in htmlparser2's DOM */
64
+ var ElementType;
65
+ (function (ElementType) {
66
+ /** Type for the root element of a document */
67
+ ElementType["Root"] = "root";
68
+ /** Type for Text */
69
+ ElementType["Text"] = "text";
70
+ /** Type for <? ... ?> */
71
+ ElementType["Directive"] = "directive";
72
+ /** Type for <!-- ... --> */
73
+ ElementType["Comment"] = "comment";
74
+ /** Type for <script> tags */
75
+ ElementType["Script"] = "script";
76
+ /** Type for <style> tags */
77
+ ElementType["Style"] = "style";
78
+ /** Type for Any tag */
79
+ ElementType["Tag"] = "tag";
80
+ /** Type for <![CDATA[ ... ]]> */
81
+ ElementType["CDATA"] = "cdata";
82
+ /** Type for <!doctype ...> */
83
+ ElementType["Doctype"] = "doctype";
84
+ })(ElementType || (ElementType = {}));
85
+ /**
86
+ * Tests whether an element is a tag or not.
87
+ * @param element Element to test
88
+ * @param element.type Node type discriminator to check.
89
+ */
90
+ function isTag$1(element) {
91
+ return (element.type === ElementType.Tag ||
92
+ element.type === ElementType.Script ||
93
+ element.type === ElementType.Style);
100
94
  }
101
-
102
- var node = {};
103
-
104
- var hasRequiredNode;
105
-
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
- /**
139
- * This object will be used as the prototype for Nodes when creating a
140
- * DOM-Level-1-compliant structure.
141
- */
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;
154
- }
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
- /**
199
- * Clone this node, and optionally its children.
200
- *
201
- * @param recursive Clone child nodes as well.
202
- * @returns A clone of the node.
203
- */
204
- Node.prototype.cloneNode = function (recursive) {
205
- if (recursive === void 0) { recursive = false; }
206
- return cloneNode(this, recursive);
207
- };
208
- return Node;
209
- }());
210
- node.Node = Node;
211
- /**
212
- * A node that contains some data.
213
- */
214
- var DataNode = /** @class */ (function (_super) {
215
- __extends(DataNode, _super);
216
- /**
217
- * @param data The content of the data node
218
- */
219
- function DataNode(data) {
220
- var _this = _super.call(this) || this;
221
- _this.data = data;
222
- return _this;
223
- }
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;
241
- /**
242
- * Text within the document.
243
- */
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;
250
- }
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;
261
- /**
262
- * Comments within the document.
263
- */
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;
270
- }
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;
281
- /**
282
- * Processing instructions, including doc types.
283
- */
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;
291
- }
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;
302
- /**
303
- * A `Node` that can have children.
304
- */
305
- var NodeWithChildren = /** @class */ (function (_super) {
306
- __extends(NodeWithChildren, _super);
307
- /**
308
- * @param children Children of the node. Only certain node types can have children.
309
- */
310
- function NodeWithChildren(children) {
311
- var _this = _super.call(this) || this;
312
- _this.children = children;
313
- return _this;
314
- }
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;
358
- }
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;
369
- /**
370
- * The root node of the document.
371
- */
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;
378
- }
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;
389
- /**
390
- * An element within the DOM.
391
- */
392
- var Element = /** @class */ (function (_super) {
393
- __extends(Element, _super);
394
- /**
395
- * @param name Name of the tag, eg. `div`, `span`.
396
- * @param attribs Object mapping attribute names to attribute values.
397
- * @param children Children of the node.
398
- */
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;
411
- }
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;
453
- /**
454
- * @param node Node to check.
455
- * @returns `true` if the node is a `Element`, `false` otherwise.
456
- */
457
- function isTag(node) {
458
- return (0, domelementtype_1.isTag)(node);
459
- }
460
- node.isTag = isTag;
461
- /**
462
- * @param node Node to check.
463
- * @returns `true` if the node has the type `CDATA`, `false` otherwise.
464
- */
465
- function isCDATA(node) {
466
- return node.type === domelementtype_1.ElementType.CDATA;
467
- }
468
- node.isCDATA = isCDATA;
469
- /**
470
- * @param node Node to check.
471
- * @returns `true` if the node has the type `Text`, `false` otherwise.
472
- */
473
- function isText(node) {
474
- return node.type === domelementtype_1.ElementType.Text;
475
- }
476
- node.isText = isText;
477
- /**
478
- * @param node Node to check.
479
- * @returns `true` if the node has the type `Comment`, `false` otherwise.
480
- */
481
- function isComment(node) {
482
- return node.type === domelementtype_1.ElementType.Comment;
483
- }
484
- node.isComment = isComment;
485
- /**
486
- * @param node Node to check.
487
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
488
- */
489
- function isDirective(node) {
490
- return node.type === domelementtype_1.ElementType.Directive;
491
- }
492
- node.isDirective = isDirective;
493
- /**
494
- * @param node Node to check.
495
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
496
- */
497
- function isDocument(node) {
498
- return node.type === domelementtype_1.ElementType.Root;
499
- }
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
- /**
510
- * Clone a node, and optionally its children.
511
- *
512
- * @param recursive Clone child nodes as well.
513
- * @returns A clone of the node.
514
- */
515
- function cloneNode(node, recursive) {
516
- if (recursive === void 0) { recursive = false; }
517
- var result;
518
- if (isText(node)) {
519
- result = new Text(node.data);
520
- }
521
- else if (isComment(node)) {
522
- result = new Comment(node.data);
523
- }
524
- 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); });
528
- if (node.namespace != null) {
529
- clone_1.namespace = node.namespace;
530
- }
531
- if (node["x-attribsNamespace"]) {
532
- clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
533
- }
534
- if (node["x-attribsPrefix"]) {
535
- clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
536
- }
537
- result = clone_1;
538
- }
539
- 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;
544
- }
545
- 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); });
549
- if (node["x-mode"]) {
550
- clone_3["x-mode"] = node["x-mode"];
551
- }
552
- result = clone_3;
553
- }
554
- else if (isDirective(node)) {
555
- var instruction = new ProcessingInstruction(node.name, node.data);
556
- if (node["x-name"] != null) {
557
- instruction["x-name"] = node["x-name"];
558
- instruction["x-publicId"] = node["x-publicId"];
559
- instruction["x-systemId"] = node["x-systemId"];
560
- }
561
- result = instruction;
562
- }
563
- else {
564
- throw new Error("Not implemented yet: ".concat(node.type));
565
- }
566
- result.startIndex = node.startIndex;
567
- result.endIndex = node.endIndex;
568
- if (node.sourceCodeLocation != null) {
569
- result.sourceCodeLocation = node.sourceCodeLocation;
570
- }
571
- return result;
572
- }
573
- node.cloneNode = cloneNode;
574
- 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];
579
- }
580
- return children;
581
- }
582
- return node;
95
+ // Exports for backwards compatibility
96
+ /** Type for the root element of a document */
97
+ // eslint-disable-next-line prefer-destructuring
98
+ ElementType.Root;
99
+ /** Type for Text */
100
+ // eslint-disable-next-line prefer-destructuring
101
+ ElementType.Text;
102
+ /** Type for <? ... ?> */
103
+ // eslint-disable-next-line prefer-destructuring
104
+ ElementType.Directive;
105
+ /** Type for <!-- ... --> */
106
+ // eslint-disable-next-line prefer-destructuring
107
+ ElementType.Comment;
108
+ /** Type for <script> tags */
109
+ // eslint-disable-next-line prefer-destructuring
110
+ ElementType.Script;
111
+ /** Type for <style> tags */
112
+ // eslint-disable-next-line prefer-destructuring
113
+ ElementType.Style;
114
+ /** Type for Any tag */
115
+ // eslint-disable-next-line prefer-destructuring
116
+ ElementType.Tag;
117
+ /** Type for <![CDATA[ ... ]]> */
118
+ // eslint-disable-next-line prefer-destructuring
119
+ ElementType.CDATA;
120
+ /** Type for <!doctype ...> */
121
+ // eslint-disable-next-line prefer-destructuring
122
+ ElementType.Doctype;
123
+
124
+ /**
125
+ * This object will be used as the prototype for Nodes when creating a
126
+ * DOM-Level-1-compliant structure.
127
+ */
128
+ class Node {
129
+ /** Parent of the node */
130
+ parent = null;
131
+ /** Previous sibling */
132
+ prev = null;
133
+ /** Next sibling */
134
+ next = null;
135
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
136
+ startIndex = null;
137
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
138
+ endIndex = null;
139
+ // Read-write aliases for properties
140
+ /**
141
+ * Same as {@link parent}.
142
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
143
+ */
144
+ get parentNode() {
145
+ return this.parent;
146
+ }
147
+ set parentNode(parent) {
148
+ this.parent = parent;
149
+ }
150
+ /**
151
+ * Same as {@link prev}.
152
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
153
+ */
154
+ get previousSibling() {
155
+ return this.prev;
156
+ }
157
+ set previousSibling(previous) {
158
+ this.prev = previous;
159
+ }
160
+ /**
161
+ * Same as {@link next}.
162
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
163
+ */
164
+ get nextSibling() {
165
+ return this.next;
166
+ }
167
+ set nextSibling(next) {
168
+ this.next = next;
169
+ }
170
+ /**
171
+ * Clone this node, and optionally its children.
172
+ * @param recursive Clone child nodes as well.
173
+ * @returns A clone of the node.
174
+ */
175
+ cloneNode(recursive = false) {
176
+ return cloneNode(this, recursive);
177
+ }
178
+ }
179
+ /**
180
+ * A node that contains some data.
181
+ */
182
+ class DataNode extends Node {
183
+ data;
184
+ /**
185
+ * @param data The content of the data node
186
+ */
187
+ constructor(data) {
188
+ super();
189
+ this.data = data;
190
+ }
191
+ /**
192
+ * Same as {@link data}.
193
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
194
+ */
195
+ get nodeValue() {
196
+ return this.data;
197
+ }
198
+ set nodeValue(data) {
199
+ this.data = data;
200
+ }
201
+ }
202
+ /**
203
+ * Text within the document.
204
+ */
205
+ class Text extends DataNode {
206
+ type = ElementType.Text;
207
+ get nodeType() {
208
+ return 3;
209
+ }
210
+ }
211
+ /**
212
+ * Comments within the document.
213
+ */
214
+ class Comment extends DataNode {
215
+ type = ElementType.Comment;
216
+ get nodeType() {
217
+ return 8;
218
+ }
219
+ }
220
+ /**
221
+ * Processing instructions, including doc types.
222
+ */
223
+ class ProcessingInstruction extends DataNode {
224
+ type = ElementType.Directive;
225
+ name;
226
+ constructor(name, data) {
227
+ super(data);
228
+ this.name = name;
229
+ }
230
+ get nodeType() {
231
+ return 1;
232
+ }
233
+ /** If this is a doctype, the document type name (parse5 only). */
234
+ "x-name";
235
+ /** If this is a doctype, the document type public identifier (parse5 only). */
236
+ "x-publicId";
237
+ /** If this is a doctype, the document type system identifier (parse5 only). */
238
+ "x-systemId";
239
+ }
240
+ /**
241
+ * A node that can have children.
242
+ */
243
+ class NodeWithChildren extends Node {
244
+ children;
245
+ /**
246
+ * @param children Children of the node. Only certain node types can have children.
247
+ */
248
+ constructor(children) {
249
+ super();
250
+ this.children = children;
251
+ }
252
+ // Aliases
253
+ /** First child of the node. */
254
+ get firstChild() {
255
+ return this.children[0] ?? null;
256
+ }
257
+ /** Last child of the node. */
258
+ get lastChild() {
259
+ return this.children.length > 0
260
+ ? this.children[this.children.length - 1]
261
+ : null;
262
+ }
263
+ /**
264
+ * Same as {@link children}.
265
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
266
+ */
267
+ get childNodes() {
268
+ return this.children;
269
+ }
270
+ set childNodes(children) {
271
+ this.children = children;
272
+ }
273
+ }
274
+ /**
275
+ * CDATA nodes.
276
+ */
277
+ class CDATA extends NodeWithChildren {
278
+ type = ElementType.CDATA;
279
+ get nodeType() {
280
+ return 4;
281
+ }
282
+ }
283
+ /**
284
+ * The root node of the document.
285
+ */
286
+ class Document extends NodeWithChildren {
287
+ type = ElementType.Root;
288
+ get nodeType() {
289
+ return 9;
290
+ }
291
+ }
292
+ /**
293
+ * An element within the DOM.
294
+ */
295
+ class Element extends NodeWithChildren {
296
+ name;
297
+ attribs;
298
+ type;
299
+ /**
300
+ * @param name Name of the tag, eg. `div`, `span`.
301
+ * @param attribs Object mapping attribute names to attribute values.
302
+ * @param children Children of the node.
303
+ * @param type Node type used for the new node instance.
304
+ */
305
+ constructor(name, attribs, children = [], type = name === "script"
306
+ ? ElementType.Script
307
+ : name === "style"
308
+ ? ElementType.Style
309
+ : ElementType.Tag) {
310
+ super(children);
311
+ this.name = name;
312
+ this.attribs = attribs;
313
+ this.type = type;
314
+ }
315
+ get nodeType() {
316
+ return 1;
317
+ }
318
+ // DOM Level 1 aliases
319
+ /**
320
+ * Same as {@link name}.
321
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
322
+ */
323
+ get tagName() {
324
+ return this.name;
325
+ }
326
+ set tagName(name) {
327
+ this.name = name;
328
+ }
329
+ get attributes() {
330
+ return Object.keys(this.attribs).map((name) => ({
331
+ name,
332
+ value: this.attribs[name],
333
+ namespace: this["x-attribsNamespace"]?.[name],
334
+ prefix: this["x-attribsPrefix"]?.[name],
335
+ }));
336
+ }
337
+ /** Element namespace (parse5 only). */
338
+ namespace;
339
+ /** Element attribute namespaces (parse5 only). */
340
+ "x-attribsNamespace";
341
+ /** Element attribute namespace-related prefixes (parse5 only). */
342
+ "x-attribsPrefix";
343
+ }
344
+ /**
345
+ * Checks if `node` is an element node.
346
+ * @param node Node to check.
347
+ * @returns `true` if the node is an element node.
348
+ */
349
+ function isTag(node) {
350
+ return isTag$1(node);
351
+ }
352
+ /**
353
+ * Checks if `node` is a CDATA node.
354
+ * @param node Node to check.
355
+ * @returns `true` if the node is a CDATA node.
356
+ */
357
+ function isCDATA(node) {
358
+ return node.type === ElementType.CDATA;
359
+ }
360
+ /**
361
+ * Checks if `node` is a text node.
362
+ * @param node Node to check.
363
+ * @returns `true` if the node is a text node.
364
+ */
365
+ function isText(node) {
366
+ return node.type === ElementType.Text;
367
+ }
368
+ /**
369
+ * Checks if `node` is a comment node.
370
+ * @param node Node to check.
371
+ * @returns `true` if the node is a comment node.
372
+ */
373
+ function isComment(node) {
374
+ return node.type === ElementType.Comment;
375
+ }
376
+ /**
377
+ * Checks if `node` is a directive node.
378
+ * @param node Node to check.
379
+ * @returns `true` if the node is a directive node.
380
+ */
381
+ function isDirective(node) {
382
+ return node.type === ElementType.Directive;
383
+ }
384
+ /**
385
+ * Checks if `node` is a document node.
386
+ * @param node Node to check.
387
+ * @returns `true` if the node is a document node.
388
+ */
389
+ function isDocument(node) {
390
+ return node.type === ElementType.Root;
391
+ }
392
+ /**
393
+ * Checks if `node` has children.
394
+ * @param node Node to check.
395
+ * @returns `true` if the node has children.
396
+ */
397
+ function hasChildren(node) {
398
+ return Object.hasOwn(node, "children");
399
+ }
400
+ /**
401
+ * Clone a node, and optionally its children.
402
+ * @param node Node to clone.
403
+ * @param recursive Clone child nodes as well.
404
+ * @returns A clone of the node.
405
+ */
406
+ function cloneNode(node, recursive = false) {
407
+ let result;
408
+ if (isText(node)) {
409
+ result = new Text(node.data);
410
+ }
411
+ else if (isComment(node)) {
412
+ result = new Comment(node.data);
413
+ }
414
+ else if (isTag(node)) {
415
+ const children = recursive ? cloneChildren(node.children) : [];
416
+ const clone = new Element(node.name, { ...node.attribs }, children);
417
+ for (const child of children) {
418
+ child.parent = clone;
419
+ }
420
+ if (node.namespace != null) {
421
+ clone.namespace = node.namespace;
422
+ }
423
+ if (node["x-attribsNamespace"]) {
424
+ clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
425
+ }
426
+ if (node["x-attribsPrefix"]) {
427
+ clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
428
+ }
429
+ result = clone;
430
+ }
431
+ else if (isCDATA(node)) {
432
+ const children = recursive ? cloneChildren(node.children) : [];
433
+ const clone = new CDATA(children);
434
+ for (const child of children) {
435
+ child.parent = clone;
436
+ }
437
+ result = clone;
438
+ }
439
+ else if (isDocument(node)) {
440
+ const children = recursive ? cloneChildren(node.children) : [];
441
+ const clone = new Document(children);
442
+ for (const child of children) {
443
+ child.parent = clone;
444
+ }
445
+ if (node["x-mode"]) {
446
+ clone["x-mode"] = node["x-mode"];
447
+ }
448
+ result = clone;
449
+ }
450
+ else if (isDirective(node)) {
451
+ const instruction = new ProcessingInstruction(node.name, node.data);
452
+ if (node["x-name"] != null) {
453
+ instruction["x-name"] = node["x-name"];
454
+ instruction["x-publicId"] = node["x-publicId"];
455
+ instruction["x-systemId"] = node["x-systemId"];
456
+ }
457
+ result = instruction;
458
+ }
459
+ else {
460
+ throw new Error(`Not implemented yet: ${node.type}`);
461
+ }
462
+ result.startIndex = node.startIndex;
463
+ result.endIndex = node.endIndex;
464
+ if (node.sourceCodeLocation != null) {
465
+ result.sourceCodeLocation = node.sourceCodeLocation;
466
+ }
467
+ return result;
468
+ }
469
+ /**
470
+ * Clone a list of child nodes.
471
+ * @param childs The child nodes to clone.
472
+ * @returns A list of cloned child nodes.
473
+ */
474
+ function cloneChildren(childs) {
475
+ const children = childs.map((child) => cloneNode(child, true));
476
+ for (let index = 1; index < children.length; index++) {
477
+ children[index].prev = children[index - 1];
478
+ children[index - 1].next = children[index];
479
+ }
480
+ return children;
583
481
  }
584
482
 
585
- var hasRequiredLib$2;
586
-
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;
483
+ // Default options
484
+ const defaultOptions = {
485
+ withStartIndices: false,
486
+ withEndIndices: false,
487
+ xmlMode: false,
488
+ };
489
+ /**
490
+ * Event-based handler that builds a DOM tree from parser callbacks.
491
+ */
492
+ class DomHandler {
493
+ /** The elements of the DOM */
494
+ dom = [];
495
+ /** The root element for the DOM */
496
+ root = new Document(this.dom);
497
+ /** Called once parsing has completed. */
498
+ callback;
499
+ /** Settings for the handler. */
500
+ options;
501
+ /** Callback whenever a tag is closed. */
502
+ elementCB;
503
+ /** Indicated whether parsing has been completed. */
504
+ done = false;
505
+ /** Stack of open tags. */
506
+ tagStack = [this.root];
507
+ /** A data node that is still being written to. */
508
+ lastNode = null;
509
+ /** Reference to the parser instance. Used for location information. */
510
+ parser = null;
511
+ /**
512
+ * @param callback Called once parsing has completed.
513
+ * @param options Settings for the handler.
514
+ * @param elementCB Callback whenever a tag is closed.
515
+ */
516
+ constructor(callback, options, elementCB) {
517
+ // Make it possible to skip arguments, for backwards-compatibility
518
+ if (typeof options === "function") {
519
+ elementCB = options;
520
+ options = defaultOptions;
521
+ }
522
+ if (typeof callback === "object") {
523
+ options = callback;
524
+ callback = undefined;
525
+ }
526
+ this.callback = callback ?? null;
527
+ this.options = options ?? defaultOptions;
528
+ this.elementCB = elementCB ?? null;
529
+ }
530
+ onparserinit(parser) {
531
+ this.parser = parser;
532
+ }
533
+ // Resets the handler back to starting state
534
+ onreset() {
535
+ this.dom = [];
536
+ this.root = new Document(this.dom);
537
+ this.done = false;
538
+ this.tagStack = [this.root];
539
+ this.lastNode = null;
540
+ this.parser = null;
541
+ }
542
+ // Signals the handler that parsing is done
543
+ onend() {
544
+ if (this.done)
545
+ return;
546
+ this.done = true;
547
+ this.parser = null;
548
+ this.handleCallback(null);
549
+ }
550
+ onerror(error) {
551
+ this.handleCallback(error);
552
+ }
553
+ onclosetag() {
554
+ this.lastNode = null;
555
+ const element = this.tagStack.pop();
556
+ if (this.options.withEndIndices && this.parser) {
557
+ element.endIndex = this.parser.endIndex;
558
+ }
559
+ if (this.elementCB)
560
+ this.elementCB(element);
561
+ }
562
+ onopentag(name, attribs) {
563
+ const type = this.options.xmlMode ? ElementType.Tag : undefined;
564
+ const element = new Element(name, attribs, undefined, type);
565
+ this.addNode(element);
566
+ this.tagStack.push(element);
567
+ }
568
+ ontext(data) {
569
+ const { lastNode } = this;
570
+ if (lastNode && lastNode.type === ElementType.Text) {
571
+ lastNode.data += data;
572
+ if (this.options.withEndIndices && this.parser) {
573
+ lastNode.endIndex = this.parser.endIndex;
574
+ }
575
+ }
576
+ else {
577
+ const node = new Text(data);
578
+ this.addNode(node);
579
+ this.lastNode = node;
580
+ }
581
+ }
582
+ oncomment(data) {
583
+ if (this.lastNode && this.lastNode.type === ElementType.Comment) {
584
+ this.lastNode.data += data;
585
+ return;
586
+ }
587
+ const node = new Comment(data);
588
+ this.addNode(node);
589
+ this.lastNode = node;
590
+ }
591
+ oncommentend() {
592
+ this.lastNode = null;
593
+ }
594
+ oncdatastart() {
595
+ const text = new Text("");
596
+ const node = new CDATA([text]);
597
+ this.addNode(node);
598
+ text.parent = node;
599
+ this.lastNode = text;
600
+ }
601
+ oncdataend() {
602
+ this.lastNode = null;
603
+ }
604
+ onprocessinginstruction(name, data) {
605
+ const node = new ProcessingInstruction(name, data);
606
+ this.addNode(node);
607
+ }
608
+ handleCallback(error) {
609
+ if (typeof this.callback === "function") {
610
+ this.callback(error, this.dom);
611
+ }
612
+ else if (error) {
613
+ throw error;
614
+ }
615
+ }
616
+ addNode(node) {
617
+ const parent = this.tagStack[this.tagStack.length - 1];
618
+ const previousSibling = parent.children[parent.children.length - 1];
619
+ if (this.options.withStartIndices && this.parser) {
620
+ node.startIndex = this.parser.startIndex;
621
+ }
622
+ if (this.options.withEndIndices && this.parser) {
623
+ node.endIndex = this.parser.endIndex;
624
+ }
625
+ parent.children.push(node);
626
+ if (previousSibling) {
627
+ node.prev = previousSibling;
628
+ previousSibling.next = node;
629
+ }
630
+ node.parent = parent;
631
+ this.lastNode = null;
632
+ }
757
633
  }
758
634
 
635
+ var dist = /*#__PURE__*/Object.freeze({
636
+ __proto__: null,
637
+ CDATA: CDATA,
638
+ Comment: Comment,
639
+ DataNode: DataNode,
640
+ Document: Document,
641
+ DomHandler: DomHandler,
642
+ Element: Element,
643
+ Node: Node,
644
+ NodeWithChildren: NodeWithChildren,
645
+ ProcessingInstruction: ProcessingInstruction,
646
+ Text: Text,
647
+ cloneNode: cloneNode,
648
+ default: DomHandler,
649
+ hasChildren: hasChildren,
650
+ isCDATA: isCDATA,
651
+ isComment: isComment,
652
+ isDirective: isDirective,
653
+ isDocument: isDocument,
654
+ isTag: isTag,
655
+ isText: isText
656
+ });
657
+
658
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(dist);
659
+
759
660
  var constants = {};
760
661
 
761
662
  var hasRequiredConstants;
@@ -765,7 +666,7 @@
765
666
  hasRequiredConstants = 1;
766
667
  (function (exports$1) {
767
668
  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;
669
+ exports$1.CASE_SENSITIVE_TAG_NAMES_MAP = exports$1.CASE_SENSITIVE_TAG_NAMES = void 0;
769
670
  /**
770
671
  * SVG elements are case-sensitive.
771
672
  *
@@ -808,10 +709,6 @@
808
709
  accumulator[tagName.toLowerCase()] = tagName;
809
710
  return accumulator;
810
711
  }, {});
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
712
 
816
713
  } (constants));
817
714
  return constants;
@@ -823,12 +720,16 @@
823
720
  if (hasRequiredUtilities$2) return utilities$2;
824
721
  hasRequiredUtilities$2 = 1;
825
722
  Object.defineProperty(utilities$2, "__esModule", { value: true });
826
- utilities$2.formatAttributes = formatAttributes;
723
+ utilities$2.hasOpenTag = hasOpenTag;
827
724
  utilities$2.escapeSpecialCharacters = escapeSpecialCharacters;
828
725
  utilities$2.revertEscapedCharacters = revertEscapedCharacters;
829
726
  utilities$2.formatDOM = formatDOM;
830
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
727
+ var domhandler_1 = require$$3;
831
728
  var constants_1 = requireConstants();
729
+ var CARRIAGE_RETURN = '\r';
730
+ var CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, 'g');
731
+ var CARRIAGE_RETURN_PLACEHOLDER = "__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now().toString(), "__");
732
+ var CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(CARRIAGE_RETURN_PLACEHOLDER, 'g');
832
733
  /**
833
734
  * Gets case-sensitive tag name.
834
735
  *
@@ -870,6 +771,28 @@
870
771
  }
871
772
  return tagName;
872
773
  }
774
+ /**
775
+ * Checks if an HTML string contains an opening tag (case-insensitive).
776
+ *
777
+ * @param html - HTML string.
778
+ * @param tagName - Tag name to search for (e.g., 'head' or 'body').
779
+ * @returns - Whether the tag is found.
780
+ */
781
+ function hasOpenTag(html, tagName) {
782
+ var openTag = '<' + tagName;
783
+ var index = html.toLowerCase().indexOf(openTag);
784
+ if (index === -1) {
785
+ return false;
786
+ }
787
+ var char = html[index + openTag.length];
788
+ // the character after the tag name must be '>' or whitespace (for attributes)
789
+ return (char === '>' ||
790
+ char === ' ' ||
791
+ char === '\t' ||
792
+ char === '\n' ||
793
+ char === '\r' ||
794
+ char === '/');
795
+ }
873
796
  /**
874
797
  * Escapes special characters before parsing.
875
798
  *
@@ -877,7 +800,7 @@
877
800
  * @returns - HTML string with escaped special characters.
878
801
  */
879
802
  function escapeSpecialCharacters(html) {
880
- return html.replace(constants_1.CARRIAGE_RETURN_REGEX, constants_1.CARRIAGE_RETURN_PLACEHOLDER);
803
+ return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
881
804
  }
882
805
  /**
883
806
  * Reverts escaped special characters back to actual characters.
@@ -886,7 +809,7 @@
886
809
  * @returns - Text with escaped characters reverted.
887
810
  */
888
811
  function revertEscapedCharacters(text) {
889
- return text.replace(constants_1.CARRIAGE_RETURN_PLACEHOLDER_REGEX, constants_1.CARRIAGE_RETURN);
812
+ return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
890
813
  }
891
814
  /**
892
815
  * Transforms DOM nodes to `domhandler` nodes.
@@ -918,14 +841,14 @@
918
841
  : node.childNodes, current);
919
842
  break;
920
843
  }
844
+ /* v8 ignore start */
921
845
  case 3:
922
- /* istanbul ignore next */
923
846
  current = new domhandler_1.Text(revertEscapedCharacters((_a = node.nodeValue) !== null && _a !== void 0 ? _a : ''));
924
847
  break;
925
848
  case 8:
926
- /* istanbul ignore next */
927
849
  current = new domhandler_1.Comment((_b = node.nodeValue) !== null && _b !== void 0 ? _b : '');
928
850
  break;
851
+ /* v8 ignore stop */
929
852
  default:
930
853
  continue;
931
854
  }
@@ -969,18 +892,13 @@
969
892
  var HEAD = 'head';
970
893
  var BODY = 'body';
971
894
  var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
972
- // match-all-characters in case of newlines (DOTALL)
973
- var HEAD_TAG_REGEX = /<head[^]*>/i;
974
- var BODY_TAG_REGEX = /<body[^]*>/i;
975
895
  // falls back to `parseFromString` if `createHTMLDocument` cannot be used
976
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
896
+ /* eslint-disable @typescript-eslint/no-unused-vars */
897
+ /* v8 ignore start */
977
898
  var parseFromDocument = function (html, tagName) {
978
- /* istanbul ignore next */
979
899
  throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
980
900
  };
981
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
982
901
  var parseFromString = function (html, tagName) {
983
- /* istanbul ignore next */
984
902
  throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
985
903
  };
986
904
  var DOMParser = typeof window === 'object' && window.DOMParser;
@@ -1000,7 +918,6 @@
1000
918
  * @returns - Document.
1001
919
  */
1002
920
  parseFromString = function (html, tagName) {
1003
- /* istanbul ignore if */
1004
921
  if (tagName) {
1005
922
  html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
1006
923
  }
@@ -1024,7 +941,6 @@
1024
941
  * @returns - Document
1025
942
  */
1026
943
  parseFromDocument = function (html, tagName) {
1027
- /* istanbul ignore if */
1028
944
  if (tagName) {
1029
945
  var element = htmlDocument_1.documentElement.querySelector(tagName);
1030
946
  if (element) {
@@ -1056,8 +972,8 @@
1056
972
  return template.content.childNodes;
1057
973
  };
1058
974
  }
1059
- /* istanbul ignore next */
1060
975
  var createNodeList = function () { return document.createDocumentFragment().childNodes; };
976
+ /* v8 ignore stop */
1061
977
  /**
1062
978
  * Parses HTML string to DOM nodes.
1063
979
  *
@@ -1075,14 +991,12 @@
1075
991
  var doc = parseFromString(html);
1076
992
  // the created document may come with filler head/body elements,
1077
993
  // so make sure to remove them if they don't actually exist
1078
- if (!HEAD_TAG_REGEX.test(html)) {
994
+ if (!(0, utilities_1.hasOpenTag)(html, HEAD)) {
1079
995
  var element = doc.querySelector(HEAD);
1080
- /* istanbul ignore next */
1081
996
  (_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
1082
997
  }
1083
- if (!BODY_TAG_REGEX.test(html)) {
998
+ if (!(0, utilities_1.hasOpenTag)(html, BODY)) {
1084
999
  var element = doc.querySelector(BODY);
1085
- /* istanbul ignore next */
1086
1000
  (_c = element === null || element === void 0 ? void 0 : element.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(element);
1087
1001
  }
1088
1002
  return doc.querySelectorAll(HTML);
@@ -1091,23 +1005,23 @@
1091
1005
  case BODY: {
1092
1006
  var elements = parseFromDocument(html).querySelectorAll(firstTagName);
1093
1007
  // if there's a sibling element, then return both elements
1094
- if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
1095
- /* istanbul ignore next */
1008
+ /* v8 ignore next */
1009
+ if ((0, utilities_1.hasOpenTag)(html, BODY) && (0, utilities_1.hasOpenTag)(html, HEAD)) {
1096
1010
  return (_e = (_d = elements[0].parentNode) === null || _d === void 0 ? void 0 : _d.childNodes) !== null && _e !== void 0 ? _e : createNodeList();
1097
1011
  }
1098
1012
  return elements;
1099
1013
  }
1100
1014
  // low-level tag or text
1015
+ /* v8 ignore start */
1101
1016
  default: {
1102
1017
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1103
1018
  if (parseFromTemplate) {
1104
1019
  return parseFromTemplate(html);
1105
1020
  }
1106
- /* istanbul ignore next */
1107
1021
  var element = parseFromDocument(html, BODY).querySelector(BODY);
1108
- /* istanbul ignore next */
1109
1022
  return (_f = element === null || element === void 0 ? void 0 : element.childNodes) !== null && _f !== void 0 ? _f : createNodeList();
1110
1023
  }
1024
+ /* v8 ignore stop */
1111
1025
  }
1112
1026
  }
1113
1027
 
@@ -2610,9 +2524,9 @@
2610
2524
  exports$1.returnFirstArg = exports$1.canTextBeChildOfNode = exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports$1.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2611
2525
  exports$1.isCustomComponent = isCustomComponent;
2612
2526
  exports$1.setStyleProp = setStyleProp;
2613
- var react_1 = require$$0;
2614
- var style_to_js_1 = __importDefault(requireCjs());
2615
- var RESERVED_SVG_MATHML_ELEMENTS = new Set([
2527
+ const react_1 = require$$0;
2528
+ const style_to_js_1 = __importDefault(requireCjs());
2529
+ const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2616
2530
  'annotation-xml',
2617
2531
  'color-profile',
2618
2532
  'font-face',
@@ -2644,7 +2558,7 @@
2644
2558
  }
2645
2559
  return true;
2646
2560
  }
2647
- var styleOptions = {
2561
+ const styleOptions = {
2648
2562
  reactCompat: true,
2649
2563
  };
2650
2564
  /**
@@ -2693,9 +2607,7 @@
2693
2607
  * @param node - Element node.
2694
2608
  * @returns - Whether the node can contain text nodes.
2695
2609
  */
2696
- var canTextBeChildOfNode = function (node) {
2697
- return !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2698
- };
2610
+ const canTextBeChildOfNode = (node) => !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2699
2611
  exports$1.canTextBeChildOfNode = canTextBeChildOfNode;
2700
2612
  /**
2701
2613
  * Returns the first argument as is.
@@ -2703,7 +2615,7 @@
2703
2615
  * @param arg - The argument to be returned.
2704
2616
  * @returns - The input argument `arg`.
2705
2617
  */
2706
- var returnFirstArg = function (arg) { return arg; };
2618
+ const returnFirstArg = (arg) => arg;
2707
2619
  exports$1.returnFirstArg = returnFirstArg;
2708
2620
 
2709
2621
  } (utilities$1));
@@ -2717,13 +2629,13 @@
2717
2629
  hasRequiredAttributesToProps = 1;
2718
2630
  Object.defineProperty(attributesToProps, "__esModule", { value: true });
2719
2631
  attributesToProps.default = attributesToProps$1;
2720
- var react_property_1 = requireLib$1();
2721
- var utilities_1 = requireUtilities();
2632
+ const react_property_1 = requireLib$1();
2633
+ const utilities_1 = requireUtilities();
2722
2634
  // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2723
2635
  // https://developer.mozilla.org/docs/Web/HTML/Attributes
2724
- var UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2725
- var UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2726
- var valueOnlyInputs = {
2636
+ const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2637
+ const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2638
+ const valueOnlyInputs = {
2727
2639
  reset: true,
2728
2640
  submit: true,
2729
2641
  };
@@ -2734,22 +2646,21 @@
2734
2646
  * @param nodeName - DOM node name.
2735
2647
  * @returns - React props.
2736
2648
  */
2737
- function attributesToProps$1(attributes, nodeName) {
2738
- if (attributes === void 0) { attributes = {}; }
2739
- var props = {};
2740
- var isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2741
- for (var attributeName in attributes) {
2742
- var attributeValue = attributes[attributeName];
2649
+ function attributesToProps$1(attributes = {}, nodeName) {
2650
+ const props = {};
2651
+ const isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2652
+ for (const attributeName in attributes) {
2653
+ const attributeValue = attributes[attributeName];
2743
2654
  // ARIA (aria-*) or custom data (data-*) attribute
2744
2655
  if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2745
2656
  props[attributeName] = attributeValue;
2746
2657
  continue;
2747
2658
  }
2748
2659
  // convert HTML/SVG attribute to React prop
2749
- var attributeNameLowerCased = attributeName.toLowerCase();
2750
- var propName = getPropName(attributeNameLowerCased);
2660
+ const attributeNameLowerCased = attributeName.toLowerCase();
2661
+ let propName = getPropName(attributeNameLowerCased);
2751
2662
  if (propName) {
2752
- var propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2663
+ const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2753
2664
  // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2754
2665
  if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2755
2666
  UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
@@ -2804,10 +2715,10 @@
2804
2715
  };
2805
2716
  Object.defineProperty(domToReact, "__esModule", { value: true });
2806
2717
  domToReact.default = domToReact$1;
2807
- var react_1 = require$$0;
2808
- var attributes_to_props_1 = __importDefault(requireAttributesToProps());
2809
- var utilities_1 = requireUtilities();
2810
- var React = {
2718
+ const react_1 = require$$0;
2719
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2720
+ const utilities_1 = requireUtilities();
2721
+ const React = {
2811
2722
  cloneElement: react_1.cloneElement,
2812
2723
  createElement: react_1.createElement,
2813
2724
  isValidElement: react_1.isValidElement,
@@ -2819,19 +2730,18 @@
2819
2730
  * @param options - Options.
2820
2731
  * @returns - String or JSX element(s).
2821
2732
  */
2822
- function domToReact$1(nodes, options) {
2733
+ function domToReact$1(nodes, options = {}) {
2823
2734
  var _a, _b, _c, _d, _e;
2824
- if (options === void 0) { options = {}; }
2825
- var reactElements = [];
2826
- var hasReplace = typeof options.replace === 'function';
2827
- var transform = (_a = options.transform) !== null && _a !== void 0 ? _a : utilities_1.returnFirstArg;
2828
- var _f = (_b = options.library) !== null && _b !== void 0 ? _b : React, cloneElement = _f.cloneElement, createElement = _f.createElement, isValidElement = _f.isValidElement;
2829
- var nodesLength = nodes.length;
2830
- for (var index = 0; index < nodesLength; index++) {
2831
- var node = nodes[index];
2735
+ const reactElements = [];
2736
+ const hasReplace = typeof options.replace === 'function';
2737
+ const transform = (_a = options.transform) !== null && _a !== void 0 ? _a : utilities_1.returnFirstArg;
2738
+ const { cloneElement, createElement, isValidElement } = (_b = options.library) !== null && _b !== void 0 ? _b : React;
2739
+ const nodesLength = nodes.length;
2740
+ for (let index = 0; index < nodesLength; index++) {
2741
+ const node = nodes[index];
2832
2742
  // replace with custom React element (if present)
2833
2743
  if (hasReplace) {
2834
- var replaceElement = (_c = options.replace) === null || _c === void 0 ? void 0 : _c.call(options, node, index);
2744
+ let replaceElement = (_c = options.replace) === null || _c === void 0 ? void 0 : _c.call(options, node, index);
2835
2745
  if (isValidElement(replaceElement)) {
2836
2746
  // set "key" prop for sibling elements
2837
2747
  // https://react.dev/learn/rendering-lists#rules-of-keys
@@ -2845,7 +2755,7 @@
2845
2755
  }
2846
2756
  }
2847
2757
  if (node.type === 'text') {
2848
- var isWhitespace = !node.data.trim().length;
2758
+ const isWhitespace = !node.data.trim().length;
2849
2759
  // We have a whitespace node that can't be nested in its parent
2850
2760
  // so skip it
2851
2761
  if (isWhitespace &&
@@ -2863,8 +2773,8 @@
2863
2773
  reactElements.push(transform(node.data, node, index));
2864
2774
  continue;
2865
2775
  }
2866
- var element = node;
2867
- var props = {};
2776
+ const element = node;
2777
+ let props = {};
2868
2778
  if (skipAttributesToProps(element)) {
2869
2779
  (0, utilities_1.setStyleProp)(element.attribs.style, element.attribs);
2870
2780
  props = element.attribs;
@@ -2873,7 +2783,7 @@
2873
2783
  else if (element.attribs) {
2874
2784
  props = (0, attributes_to_props_1.default)(element.attribs, element.name);
2875
2785
  }
2876
- var children = void 0;
2786
+ let children;
2877
2787
  switch (node.type) {
2878
2788
  case 'script':
2879
2789
  case 'style':
@@ -2929,27 +2839,27 @@
2929
2839
  var hasRequiredLib;
2930
2840
 
2931
2841
  function requireLib () {
2932
- if (hasRequiredLib) return lib$3;
2842
+ if (hasRequiredLib) return lib$1;
2933
2843
  hasRequiredLib = 1;
2934
2844
  (function (exports$1) {
2935
- var __importDefault = (lib$3 && lib$3.__importDefault) || function (mod) {
2845
+ var __importDefault = (lib$1 && lib$1.__importDefault) || function (mod) {
2936
2846
  return (mod && mod.__esModule) ? mod : { "default": mod };
2937
2847
  };
2938
2848
  Object.defineProperty(exports$1, "__esModule", { value: true });
2939
2849
  exports$1.htmlToDOM = exports$1.domToReact = exports$1.attributesToProps = exports$1.Text = exports$1.ProcessingInstruction = exports$1.Element = exports$1.Comment = void 0;
2940
2850
  exports$1.default = HTMLReactParser;
2941
- var html_dom_parser_1 = __importDefault(requireHtmlToDom());
2851
+ const html_dom_parser_1 = __importDefault(requireHtmlToDom());
2942
2852
  exports$1.htmlToDOM = html_dom_parser_1.default;
2943
- var attributes_to_props_1 = __importDefault(requireAttributesToProps());
2853
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2944
2854
  exports$1.attributesToProps = attributes_to_props_1.default;
2945
- var dom_to_react_1 = __importDefault(requireDomToReact());
2855
+ const dom_to_react_1 = __importDefault(requireDomToReact());
2946
2856
  exports$1.domToReact = dom_to_react_1.default;
2947
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
2857
+ var domhandler_1 = require$$3;
2948
2858
  Object.defineProperty(exports$1, "Comment", { enumerable: true, get: function () { return domhandler_1.Comment; } });
2949
2859
  Object.defineProperty(exports$1, "Element", { enumerable: true, get: function () { return domhandler_1.Element; } });
2950
2860
  Object.defineProperty(exports$1, "ProcessingInstruction", { enumerable: true, get: function () { return domhandler_1.ProcessingInstruction; } });
2951
2861
  Object.defineProperty(exports$1, "Text", { enumerable: true, get: function () { return domhandler_1.Text; } });
2952
- var domParserOptions = { lowerCaseAttributeNames: false };
2862
+ const domParserOptions = { lowerCaseAttributeNames: false };
2953
2863
  /**
2954
2864
  * Converts HTML string to React elements.
2955
2865
  *
@@ -2968,8 +2878,8 @@
2968
2878
  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);
2969
2879
  }
2970
2880
 
2971
- } (lib$3));
2972
- return lib$3;
2881
+ } (lib$1));
2882
+ return lib$1;
2973
2883
  }
2974
2884
 
2975
2885
  var libExports = requireLib();