html-react-parser 5.2.17 → 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,13 +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;
827
723
  utilities$2.hasOpenTag = hasOpenTag;
828
724
  utilities$2.escapeSpecialCharacters = escapeSpecialCharacters;
829
725
  utilities$2.revertEscapedCharacters = revertEscapedCharacters;
830
726
  utilities$2.formatDOM = formatDOM;
831
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
727
+ var domhandler_1 = require$$3;
832
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');
833
733
  /**
834
734
  * Gets case-sensitive tag name.
835
735
  *
@@ -900,7 +800,7 @@
900
800
  * @returns - HTML string with escaped special characters.
901
801
  */
902
802
  function escapeSpecialCharacters(html) {
903
- return html.replace(constants_1.CARRIAGE_RETURN_REGEX, constants_1.CARRIAGE_RETURN_PLACEHOLDER);
803
+ return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
904
804
  }
905
805
  /**
906
806
  * Reverts escaped special characters back to actual characters.
@@ -909,7 +809,7 @@
909
809
  * @returns - Text with escaped characters reverted.
910
810
  */
911
811
  function revertEscapedCharacters(text) {
912
- return text.replace(constants_1.CARRIAGE_RETURN_PLACEHOLDER_REGEX, constants_1.CARRIAGE_RETURN);
812
+ return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
913
813
  }
914
814
  /**
915
815
  * Transforms DOM nodes to `domhandler` nodes.
@@ -941,12 +841,14 @@
941
841
  : node.childNodes, current);
942
842
  break;
943
843
  }
844
+ /* v8 ignore start */
944
845
  case 3:
945
846
  current = new domhandler_1.Text(revertEscapedCharacters((_a = node.nodeValue) !== null && _a !== void 0 ? _a : ''));
946
847
  break;
947
848
  case 8:
948
849
  current = new domhandler_1.Comment((_b = node.nodeValue) !== null && _b !== void 0 ? _b : '');
949
850
  break;
851
+ /* v8 ignore stop */
950
852
  default:
951
853
  continue;
952
854
  }
@@ -992,15 +894,13 @@
992
894
  var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
993
895
  // falls back to `parseFromString` if `createHTMLDocument` cannot be used
994
896
  /* eslint-disable @typescript-eslint/no-unused-vars */
995
- /* istanbul ignore start */
897
+ /* v8 ignore start */
996
898
  var parseFromDocument = function (html, tagName) {
997
899
  throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
998
900
  };
999
901
  var parseFromString = function (html, tagName) {
1000
902
  throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
1001
903
  };
1002
- /* istanbul ignore stop */
1003
- /* eslint-enable @typescript-eslint/no-unused-vars */
1004
904
  var DOMParser = typeof window === 'object' && window.DOMParser;
1005
905
  /**
1006
906
  * DOMParser (performance: slow).
@@ -1018,11 +918,9 @@
1018
918
  * @returns - Document.
1019
919
  */
1020
920
  parseFromString = function (html, tagName) {
1021
- /* istanbul ignore start */
1022
921
  if (tagName) {
1023
922
  html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
1024
923
  }
1025
- /* istanbul ignore stop */
1026
924
  return domParser_1.parseFromString(html, mimeType_1);
1027
925
  };
1028
926
  parseFromDocument = parseFromString;
@@ -1043,7 +941,6 @@
1043
941
  * @returns - Document
1044
942
  */
1045
943
  parseFromDocument = function (html, tagName) {
1046
- /* istanbul ignore start */
1047
944
  if (tagName) {
1048
945
  var element = htmlDocument_1.documentElement.querySelector(tagName);
1049
946
  if (element) {
@@ -1051,7 +948,6 @@
1051
948
  }
1052
949
  return htmlDocument_1;
1053
950
  }
1054
- /* istanbul ignore stop */
1055
951
  htmlDocument_1.documentElement.innerHTML = html;
1056
952
  return htmlDocument_1;
1057
953
  };
@@ -1076,9 +972,8 @@
1076
972
  return template.content.childNodes;
1077
973
  };
1078
974
  }
1079
- var createNodeList = /* istanbul ignore next */ function () {
1080
- return document.createDocumentFragment().childNodes;
1081
- };
975
+ var createNodeList = function () { return document.createDocumentFragment().childNodes; };
976
+ /* v8 ignore stop */
1082
977
  /**
1083
978
  * Parses HTML string to DOM nodes.
1084
979
  *
@@ -1098,12 +993,10 @@
1098
993
  // so make sure to remove them if they don't actually exist
1099
994
  if (!(0, utilities_1.hasOpenTag)(html, HEAD)) {
1100
995
  var element = doc.querySelector(HEAD);
1101
- /* istanbul ignore next */
1102
996
  (_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
1103
997
  }
1104
998
  if (!(0, utilities_1.hasOpenTag)(html, BODY)) {
1105
999
  var element = doc.querySelector(BODY);
1106
- /* istanbul ignore next */
1107
1000
  (_c = element === null || element === void 0 ? void 0 : element.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(element);
1108
1001
  }
1109
1002
  return doc.querySelectorAll(HTML);
@@ -1112,23 +1005,23 @@
1112
1005
  case BODY: {
1113
1006
  var elements = parseFromDocument(html).querySelectorAll(firstTagName);
1114
1007
  // if there's a sibling element, then return both elements
1008
+ /* v8 ignore next */
1115
1009
  if ((0, utilities_1.hasOpenTag)(html, BODY) && (0, utilities_1.hasOpenTag)(html, HEAD)) {
1116
- /* istanbul ignore next */
1117
1010
  return (_e = (_d = elements[0].parentNode) === null || _d === void 0 ? void 0 : _d.childNodes) !== null && _e !== void 0 ? _e : createNodeList();
1118
1011
  }
1119
1012
  return elements;
1120
1013
  }
1121
1014
  // low-level tag or text
1015
+ /* v8 ignore start */
1122
1016
  default: {
1123
1017
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1124
1018
  if (parseFromTemplate) {
1125
1019
  return parseFromTemplate(html);
1126
1020
  }
1127
- /* istanbul ignore start */
1128
1021
  var element = parseFromDocument(html, BODY).querySelector(BODY);
1129
1022
  return (_f = element === null || element === void 0 ? void 0 : element.childNodes) !== null && _f !== void 0 ? _f : createNodeList();
1130
- /* istanbul ignore stop */
1131
1023
  }
1024
+ /* v8 ignore stop */
1132
1025
  }
1133
1026
  }
1134
1027
 
@@ -2631,9 +2524,9 @@
2631
2524
  exports$1.returnFirstArg = exports$1.canTextBeChildOfNode = exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports$1.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2632
2525
  exports$1.isCustomComponent = isCustomComponent;
2633
2526
  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([
2527
+ const react_1 = require$$0;
2528
+ const style_to_js_1 = __importDefault(requireCjs());
2529
+ const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2637
2530
  'annotation-xml',
2638
2531
  'color-profile',
2639
2532
  'font-face',
@@ -2665,7 +2558,7 @@
2665
2558
  }
2666
2559
  return true;
2667
2560
  }
2668
- var styleOptions = {
2561
+ const styleOptions = {
2669
2562
  reactCompat: true,
2670
2563
  };
2671
2564
  /**
@@ -2714,9 +2607,7 @@
2714
2607
  * @param node - Element node.
2715
2608
  * @returns - Whether the node can contain text nodes.
2716
2609
  */
2717
- var canTextBeChildOfNode = function (node) {
2718
- return !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2719
- };
2610
+ const canTextBeChildOfNode = (node) => !exports$1.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2720
2611
  exports$1.canTextBeChildOfNode = canTextBeChildOfNode;
2721
2612
  /**
2722
2613
  * Returns the first argument as is.
@@ -2724,7 +2615,7 @@
2724
2615
  * @param arg - The argument to be returned.
2725
2616
  * @returns - The input argument `arg`.
2726
2617
  */
2727
- var returnFirstArg = function (arg) { return arg; };
2618
+ const returnFirstArg = (arg) => arg;
2728
2619
  exports$1.returnFirstArg = returnFirstArg;
2729
2620
 
2730
2621
  } (utilities$1));
@@ -2738,13 +2629,13 @@
2738
2629
  hasRequiredAttributesToProps = 1;
2739
2630
  Object.defineProperty(attributesToProps, "__esModule", { value: true });
2740
2631
  attributesToProps.default = attributesToProps$1;
2741
- var react_property_1 = requireLib$1();
2742
- var utilities_1 = requireUtilities();
2632
+ const react_property_1 = requireLib$1();
2633
+ const utilities_1 = requireUtilities();
2743
2634
  // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2744
2635
  // 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 = {
2636
+ const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2637
+ const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2638
+ const valueOnlyInputs = {
2748
2639
  reset: true,
2749
2640
  submit: true,
2750
2641
  };
@@ -2755,22 +2646,21 @@
2755
2646
  * @param nodeName - DOM node name.
2756
2647
  * @returns - React props.
2757
2648
  */
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];
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];
2764
2654
  // ARIA (aria-*) or custom data (data-*) attribute
2765
2655
  if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2766
2656
  props[attributeName] = attributeValue;
2767
2657
  continue;
2768
2658
  }
2769
2659
  // convert HTML/SVG attribute to React prop
2770
- var attributeNameLowerCased = attributeName.toLowerCase();
2771
- var propName = getPropName(attributeNameLowerCased);
2660
+ const attributeNameLowerCased = attributeName.toLowerCase();
2661
+ let propName = getPropName(attributeNameLowerCased);
2772
2662
  if (propName) {
2773
- var propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2663
+ const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2774
2664
  // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2775
2665
  if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2776
2666
  UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
@@ -2825,10 +2715,10 @@
2825
2715
  };
2826
2716
  Object.defineProperty(domToReact, "__esModule", { value: true });
2827
2717
  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 = {
2718
+ const react_1 = require$$0;
2719
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2720
+ const utilities_1 = requireUtilities();
2721
+ const React = {
2832
2722
  cloneElement: react_1.cloneElement,
2833
2723
  createElement: react_1.createElement,
2834
2724
  isValidElement: react_1.isValidElement,
@@ -2840,19 +2730,18 @@
2840
2730
  * @param options - Options.
2841
2731
  * @returns - String or JSX element(s).
2842
2732
  */
2843
- function domToReact$1(nodes, options) {
2733
+ function domToReact$1(nodes, options = {}) {
2844
2734
  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];
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];
2853
2742
  // replace with custom React element (if present)
2854
2743
  if (hasReplace) {
2855
- 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);
2856
2745
  if (isValidElement(replaceElement)) {
2857
2746
  // set "key" prop for sibling elements
2858
2747
  // https://react.dev/learn/rendering-lists#rules-of-keys
@@ -2866,7 +2755,7 @@
2866
2755
  }
2867
2756
  }
2868
2757
  if (node.type === 'text') {
2869
- var isWhitespace = !node.data.trim().length;
2758
+ const isWhitespace = !node.data.trim().length;
2870
2759
  // We have a whitespace node that can't be nested in its parent
2871
2760
  // so skip it
2872
2761
  if (isWhitespace &&
@@ -2884,8 +2773,8 @@
2884
2773
  reactElements.push(transform(node.data, node, index));
2885
2774
  continue;
2886
2775
  }
2887
- var element = node;
2888
- var props = {};
2776
+ const element = node;
2777
+ let props = {};
2889
2778
  if (skipAttributesToProps(element)) {
2890
2779
  (0, utilities_1.setStyleProp)(element.attribs.style, element.attribs);
2891
2780
  props = element.attribs;
@@ -2894,7 +2783,7 @@
2894
2783
  else if (element.attribs) {
2895
2784
  props = (0, attributes_to_props_1.default)(element.attribs, element.name);
2896
2785
  }
2897
- var children = void 0;
2786
+ let children;
2898
2787
  switch (node.type) {
2899
2788
  case 'script':
2900
2789
  case 'style':
@@ -2950,27 +2839,27 @@
2950
2839
  var hasRequiredLib;
2951
2840
 
2952
2841
  function requireLib () {
2953
- if (hasRequiredLib) return lib$3;
2842
+ if (hasRequiredLib) return lib$1;
2954
2843
  hasRequiredLib = 1;
2955
2844
  (function (exports$1) {
2956
- var __importDefault = (lib$3 && lib$3.__importDefault) || function (mod) {
2845
+ var __importDefault = (lib$1 && lib$1.__importDefault) || function (mod) {
2957
2846
  return (mod && mod.__esModule) ? mod : { "default": mod };
2958
2847
  };
2959
2848
  Object.defineProperty(exports$1, "__esModule", { value: true });
2960
2849
  exports$1.htmlToDOM = exports$1.domToReact = exports$1.attributesToProps = exports$1.Text = exports$1.ProcessingInstruction = exports$1.Element = exports$1.Comment = void 0;
2961
2850
  exports$1.default = HTMLReactParser;
2962
- var html_dom_parser_1 = __importDefault(requireHtmlToDom());
2851
+ const html_dom_parser_1 = __importDefault(requireHtmlToDom());
2963
2852
  exports$1.htmlToDOM = html_dom_parser_1.default;
2964
- var attributes_to_props_1 = __importDefault(requireAttributesToProps());
2853
+ const attributes_to_props_1 = __importDefault(requireAttributesToProps());
2965
2854
  exports$1.attributesToProps = attributes_to_props_1.default;
2966
- var dom_to_react_1 = __importDefault(requireDomToReact());
2855
+ const dom_to_react_1 = __importDefault(requireDomToReact());
2967
2856
  exports$1.domToReact = dom_to_react_1.default;
2968
- var domhandler_1 = /*@__PURE__*/ requireLib$2();
2857
+ var domhandler_1 = require$$3;
2969
2858
  Object.defineProperty(exports$1, "Comment", { enumerable: true, get: function () { return domhandler_1.Comment; } });
2970
2859
  Object.defineProperty(exports$1, "Element", { enumerable: true, get: function () { return domhandler_1.Element; } });
2971
2860
  Object.defineProperty(exports$1, "ProcessingInstruction", { enumerable: true, get: function () { return domhandler_1.ProcessingInstruction; } });
2972
2861
  Object.defineProperty(exports$1, "Text", { enumerable: true, get: function () { return domhandler_1.Text; } });
2973
- var domParserOptions = { lowerCaseAttributeNames: false };
2862
+ const domParserOptions = { lowerCaseAttributeNames: false };
2974
2863
  /**
2975
2864
  * Converts HTML string to React elements.
2976
2865
  *
@@ -2989,8 +2878,8 @@
2989
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);
2990
2879
  }
2991
2880
 
2992
- } (lib$3));
2993
- return lib$3;
2881
+ } (lib$1));
2882
+ return lib$1;
2994
2883
  }
2995
2884
 
2996
2885
  var libExports = requireLib();