html-react-parser 6.1.6 → 6.1.8

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.
@@ -58,6 +58,414 @@
58
58
 
59
59
  var utilities$1 = {};
60
60
 
61
+ var node = {};
62
+
63
+ var dist$2 = {};
64
+
65
+ var hasRequiredDist$1;
66
+
67
+ function requireDist$1 () {
68
+ if (hasRequiredDist$1) return dist$2;
69
+ hasRequiredDist$1 = 1;
70
+ (function (exports) {
71
+ //#region node_modules/domelementtype/dist/index.js
72
+ /** Types of elements found in htmlparser2's DOM */
73
+ var ElementType;
74
+ (function(ElementType) {
75
+ /** Type for the root element of a document */
76
+ ElementType["Root"] = "root";
77
+ /** Type for Text */
78
+ ElementType["Text"] = "text";
79
+ /** Type for <? ... ?> */
80
+ ElementType["Directive"] = "directive";
81
+ /** Type for <!-- ... --> */
82
+ ElementType["Comment"] = "comment";
83
+ /** Type for <script> tags */
84
+ ElementType["Script"] = "script";
85
+ /** Type for <style> tags */
86
+ ElementType["Style"] = "style";
87
+ /** Type for Any tag */
88
+ ElementType["Tag"] = "tag";
89
+ /** Type for <![CDATA[ ... ]]> */
90
+ ElementType["CDATA"] = "cdata";
91
+ /** Type for <!doctype ...> */
92
+ ElementType["Doctype"] = "doctype";
93
+ })(ElementType || (ElementType = {}));
94
+ /**
95
+ * Tests whether an element is a tag or not.
96
+ * @param element Element to test
97
+ * @param element.type Node type discriminator to check.
98
+ */
99
+ function isTag(element) {
100
+ return element.type === ElementType.Tag || element.type === ElementType.Script || element.type === ElementType.Style;
101
+ }
102
+ ElementType.Root;
103
+ ElementType.Text;
104
+ ElementType.Directive;
105
+ ElementType.Comment;
106
+ ElementType.Script;
107
+ ElementType.Style;
108
+ ElementType.Tag;
109
+ ElementType.CDATA;
110
+ ElementType.Doctype;
111
+ //#endregion
112
+ Object.defineProperty(exports, "ElementType", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return ElementType;
116
+ }
117
+ });
118
+ exports.isTag = isTag;
119
+
120
+
121
+ } (dist$2));
122
+ return dist$2;
123
+ }
124
+
125
+ var hasRequiredNode;
126
+
127
+ function requireNode () {
128
+ if (hasRequiredNode) return node;
129
+ hasRequiredNode = 1;
130
+ const require_index = requireDist$1();
131
+ //#region node_modules/domhandler/dist/node.js
132
+ /**
133
+ * This object will be used as the prototype for Nodes when creating a
134
+ * DOM-Level-1-compliant structure.
135
+ */
136
+ var Node = class {
137
+ /** Parent of the node */
138
+ parent = null;
139
+ /** Previous sibling */
140
+ prev = null;
141
+ /** Next sibling */
142
+ next = null;
143
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
144
+ startIndex = null;
145
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
146
+ endIndex = null;
147
+ /**
148
+ * Same as {@link parent}.
149
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
150
+ */
151
+ get parentNode() {
152
+ return this.parent;
153
+ }
154
+ set parentNode(parent) {
155
+ this.parent = parent;
156
+ }
157
+ /**
158
+ * Same as {@link prev}.
159
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
160
+ */
161
+ get previousSibling() {
162
+ return this.prev;
163
+ }
164
+ set previousSibling(previous) {
165
+ this.prev = previous;
166
+ }
167
+ /**
168
+ * Same as {@link next}.
169
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
170
+ */
171
+ get nextSibling() {
172
+ return this.next;
173
+ }
174
+ set nextSibling(next) {
175
+ this.next = next;
176
+ }
177
+ /**
178
+ * Clone this node, and optionally its children.
179
+ * @param recursive Clone child nodes as well.
180
+ * @returns A clone of the node.
181
+ */
182
+ cloneNode(recursive = false) {
183
+ return cloneNode(this, recursive);
184
+ }
185
+ };
186
+ /**
187
+ * A node that contains some data.
188
+ */
189
+ var DataNode = class extends Node {
190
+ data;
191
+ /**
192
+ * @param data The content of the data node
193
+ */
194
+ constructor(data) {
195
+ super();
196
+ this.data = data;
197
+ }
198
+ /**
199
+ * Same as {@link data}.
200
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
201
+ */
202
+ get nodeValue() {
203
+ return this.data;
204
+ }
205
+ set nodeValue(data) {
206
+ this.data = data;
207
+ }
208
+ };
209
+ /**
210
+ * Text within the document.
211
+ */
212
+ var Text = class extends DataNode {
213
+ type = require_index.ElementType.Text;
214
+ get nodeType() {
215
+ return 3;
216
+ }
217
+ };
218
+ /**
219
+ * Comments within the document.
220
+ */
221
+ var Comment = class extends DataNode {
222
+ type = require_index.ElementType.Comment;
223
+ get nodeType() {
224
+ return 8;
225
+ }
226
+ };
227
+ /**
228
+ * Processing instructions, including doc types.
229
+ */
230
+ var ProcessingInstruction = class extends DataNode {
231
+ type = require_index.ElementType.Directive;
232
+ name;
233
+ constructor(name, data) {
234
+ super(data);
235
+ this.name = name;
236
+ }
237
+ get nodeType() {
238
+ return 1;
239
+ }
240
+ /** If this is a doctype, the document type name (parse5 only). */
241
+ "x-name";
242
+ /** If this is a doctype, the document type public identifier (parse5 only). */
243
+ "x-publicId";
244
+ /** If this is a doctype, the document type system identifier (parse5 only). */
245
+ "x-systemId";
246
+ };
247
+ /**
248
+ * A node that can have children.
249
+ */
250
+ var NodeWithChildren = class extends Node {
251
+ children;
252
+ /**
253
+ * @param children Children of the node. Only certain node types can have children.
254
+ */
255
+ constructor(children) {
256
+ super();
257
+ this.children = children;
258
+ }
259
+ /** First child of the node. */
260
+ get firstChild() {
261
+ return this.children[0] ?? null;
262
+ }
263
+ /** Last child of the node. */
264
+ get lastChild() {
265
+ return this.children.length > 0 ? this.children[this.children.length - 1] : null;
266
+ }
267
+ /**
268
+ * Same as {@link children}.
269
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
270
+ */
271
+ get childNodes() {
272
+ return this.children;
273
+ }
274
+ set childNodes(children) {
275
+ this.children = children;
276
+ }
277
+ };
278
+ /**
279
+ * CDATA nodes.
280
+ */
281
+ var CDATA = class extends NodeWithChildren {
282
+ type = require_index.ElementType.CDATA;
283
+ get nodeType() {
284
+ return 4;
285
+ }
286
+ };
287
+ /**
288
+ * The root node of the document.
289
+ */
290
+ var Document = class extends NodeWithChildren {
291
+ type = require_index.ElementType.Root;
292
+ get nodeType() {
293
+ return 9;
294
+ }
295
+ };
296
+ /**
297
+ * An element within the DOM.
298
+ */
299
+ var Element = class extends NodeWithChildren {
300
+ name;
301
+ attribs;
302
+ type;
303
+ /**
304
+ * @param name Name of the tag, eg. `div`, `span`.
305
+ * @param attribs Object mapping attribute names to attribute values.
306
+ * @param children Children of the node.
307
+ * @param type Node type used for the new node instance.
308
+ */
309
+ constructor(name, attribs, children = [], type = name === "script" ? require_index.ElementType.Script : name === "style" ? require_index.ElementType.Style : require_index.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
+ /**
319
+ * Same as {@link name}.
320
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
321
+ */
322
+ get tagName() {
323
+ return this.name;
324
+ }
325
+ set tagName(name) {
326
+ this.name = name;
327
+ }
328
+ get attributes() {
329
+ return Object.keys(this.attribs).map((name) => ({
330
+ name,
331
+ value: this.attribs[name],
332
+ namespace: this["x-attribsNamespace"]?.[name],
333
+ prefix: this["x-attribsPrefix"]?.[name]
334
+ }));
335
+ }
336
+ /** Element namespace (parse5 only). */
337
+ namespace;
338
+ /** Element attribute namespaces (parse5 only). */
339
+ "x-attribsNamespace";
340
+ /** Element attribute namespace-related prefixes (parse5 only). */
341
+ "x-attribsPrefix";
342
+ };
343
+ /**
344
+ * Checks if `node` is an element node.
345
+ * @param node Node to check.
346
+ * @returns `true` if the node is an element node.
347
+ */
348
+ function isTag(node) {
349
+ return require_index.isTag(node);
350
+ }
351
+ /**
352
+ * Checks if `node` is a CDATA node.
353
+ * @param node Node to check.
354
+ * @returns `true` if the node is a CDATA node.
355
+ */
356
+ function isCDATA(node) {
357
+ return node.type === require_index.ElementType.CDATA;
358
+ }
359
+ /**
360
+ * Checks if `node` is a text node.
361
+ * @param node Node to check.
362
+ * @returns `true` if the node is a text node.
363
+ */
364
+ function isText(node) {
365
+ return node.type === require_index.ElementType.Text;
366
+ }
367
+ /**
368
+ * Checks if `node` is a comment node.
369
+ * @param node Node to check.
370
+ * @returns `true` if the node is a comment node.
371
+ */
372
+ function isComment(node) {
373
+ return node.type === require_index.ElementType.Comment;
374
+ }
375
+ /**
376
+ * Checks if `node` is a directive node.
377
+ * @param node Node to check.
378
+ * @returns `true` if the node is a directive node.
379
+ */
380
+ function isDirective(node) {
381
+ return node.type === require_index.ElementType.Directive;
382
+ }
383
+ /**
384
+ * Checks if `node` is a document node.
385
+ * @param node Node to check.
386
+ * @returns `true` if the node is a document node.
387
+ */
388
+ function isDocument(node) {
389
+ return node.type === require_index.ElementType.Root;
390
+ }
391
+ /**
392
+ * Clone a node, and optionally its children.
393
+ * @param node Node to clone.
394
+ * @param recursive Clone child nodes as well.
395
+ * @returns A clone of the node.
396
+ */
397
+ function cloneNode(node, recursive = false) {
398
+ let result;
399
+ if (isText(node)) result = new Text(node.data);
400
+ else if (isComment(node)) result = new Comment(node.data);
401
+ else if (isTag(node)) {
402
+ const children = recursive ? cloneChildren(node.children) : [];
403
+ const clone = new Element(node.name, { ...node.attribs }, children);
404
+ for (const child of children) child.parent = clone;
405
+ if (node.namespace != null) clone.namespace = node.namespace;
406
+ if (node["x-attribsNamespace"]) clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
407
+ if (node["x-attribsPrefix"]) clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
408
+ result = clone;
409
+ } else if (isCDATA(node)) {
410
+ const children = recursive ? cloneChildren(node.children) : [];
411
+ const clone = new CDATA(children);
412
+ for (const child of children) child.parent = clone;
413
+ result = clone;
414
+ } else if (isDocument(node)) {
415
+ const children = recursive ? cloneChildren(node.children) : [];
416
+ const clone = new Document(children);
417
+ for (const child of children) child.parent = clone;
418
+ if (node["x-mode"]) clone["x-mode"] = node["x-mode"];
419
+ result = clone;
420
+ } else if (isDirective(node)) {
421
+ const instruction = new ProcessingInstruction(node.name, node.data);
422
+ if (node["x-name"] != null) {
423
+ instruction["x-name"] = node["x-name"];
424
+ instruction["x-publicId"] = node["x-publicId"];
425
+ instruction["x-systemId"] = node["x-systemId"];
426
+ }
427
+ result = instruction;
428
+ } else throw new Error(`Not implemented yet: ${node.type}`);
429
+ result.startIndex = node.startIndex;
430
+ result.endIndex = node.endIndex;
431
+ if (node.sourceCodeLocation != null) result.sourceCodeLocation = node.sourceCodeLocation;
432
+ return result;
433
+ }
434
+ /**
435
+ * Clone a list of child nodes.
436
+ * @param childs The child nodes to clone.
437
+ * @returns A list of cloned child nodes.
438
+ */
439
+ function cloneChildren(childs) {
440
+ const children = childs.map((child) => cloneNode(child, true));
441
+ for (let index = 1; index < children.length; index++) {
442
+ children[index].prev = children[index - 1];
443
+ children[index - 1].next = children[index];
444
+ }
445
+ return children;
446
+ }
447
+ //#endregion
448
+ node.CDATA = CDATA;
449
+ node.Comment = Comment;
450
+ node.DataNode = DataNode;
451
+ node.Document = Document;
452
+ node.Element = Element;
453
+ node.Node = Node;
454
+ node.NodeWithChildren = NodeWithChildren;
455
+ node.ProcessingInstruction = ProcessingInstruction;
456
+ node.Text = Text;
457
+ node.cloneNode = cloneNode;
458
+ node.isCDATA = isCDATA;
459
+ node.isComment = isComment;
460
+ node.isDirective = isDirective;
461
+ node.isDocument = isDocument;
462
+ node.isTag = isTag;
463
+ node.isText = isText;
464
+
465
+
466
+ return node;
467
+ }
468
+
61
469
  var constants = {};
62
470
 
63
471
  var hasRequiredConstants;
@@ -116,610 +524,13 @@
116
524
  return constants;
117
525
  }
118
526
 
119
- /** Types of elements found in htmlparser2's DOM */
120
- var ElementType;
121
- (function (ElementType) {
122
- /** Type for the root element of a document */
123
- ElementType["Root"] = "root";
124
- /** Type for Text */
125
- ElementType["Text"] = "text";
126
- /** Type for <? ... ?> */
127
- ElementType["Directive"] = "directive";
128
- /** Type for <!-- ... --> */
129
- ElementType["Comment"] = "comment";
130
- /** Type for <script> tags */
131
- ElementType["Script"] = "script";
132
- /** Type for <style> tags */
133
- ElementType["Style"] = "style";
134
- /** Type for Any tag */
135
- ElementType["Tag"] = "tag";
136
- /** Type for <![CDATA[ ... ]]> */
137
- ElementType["CDATA"] = "cdata";
138
- /** Type for <!doctype ...> */
139
- ElementType["Doctype"] = "doctype";
140
- })(ElementType || (ElementType = {}));
141
- /**
142
- * Tests whether an element is a tag or not.
143
- * @param element Element to test
144
- * @param element.type Node type discriminator to check.
145
- */
146
- function isTag$1(element) {
147
- return (element.type === ElementType.Tag ||
148
- element.type === ElementType.Script ||
149
- element.type === ElementType.Style);
150
- }
151
- // Exports for backwards compatibility
152
- /** Type for the root element of a document */
153
- // eslint-disable-next-line prefer-destructuring
154
- ElementType.Root;
155
- /** Type for Text */
156
- // eslint-disable-next-line prefer-destructuring
157
- ElementType.Text;
158
- /** Type for <? ... ?> */
159
- // eslint-disable-next-line prefer-destructuring
160
- ElementType.Directive;
161
- /** Type for <!-- ... --> */
162
- // eslint-disable-next-line prefer-destructuring
163
- ElementType.Comment;
164
- /** Type for <script> tags */
165
- // eslint-disable-next-line prefer-destructuring
166
- ElementType.Script;
167
- /** Type for <style> tags */
168
- // eslint-disable-next-line prefer-destructuring
169
- ElementType.Style;
170
- /** Type for Any tag */
171
- // eslint-disable-next-line prefer-destructuring
172
- ElementType.Tag;
173
- /** Type for <![CDATA[ ... ]]> */
174
- // eslint-disable-next-line prefer-destructuring
175
- ElementType.CDATA;
176
- /** Type for <!doctype ...> */
177
- // eslint-disable-next-line prefer-destructuring
178
- ElementType.Doctype;
179
-
180
- /**
181
- * This object will be used as the prototype for Nodes when creating a
182
- * DOM-Level-1-compliant structure.
183
- */
184
- class Node {
185
- /** Parent of the node */
186
- parent = null;
187
- /** Previous sibling */
188
- prev = null;
189
- /** Next sibling */
190
- next = null;
191
- /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
192
- startIndex = null;
193
- /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
194
- endIndex = null;
195
- // Read-write aliases for properties
196
- /**
197
- * Same as {@link parent}.
198
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
199
- */
200
- get parentNode() {
201
- return this.parent;
202
- }
203
- set parentNode(parent) {
204
- this.parent = parent;
205
- }
206
- /**
207
- * Same as {@link prev}.
208
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
209
- */
210
- get previousSibling() {
211
- return this.prev;
212
- }
213
- set previousSibling(previous) {
214
- this.prev = previous;
215
- }
216
- /**
217
- * Same as {@link next}.
218
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
219
- */
220
- get nextSibling() {
221
- return this.next;
222
- }
223
- set nextSibling(next) {
224
- this.next = next;
225
- }
226
- /**
227
- * Clone this node, and optionally its children.
228
- * @param recursive Clone child nodes as well.
229
- * @returns A clone of the node.
230
- */
231
- cloneNode(recursive = false) {
232
- return cloneNode(this, recursive);
233
- }
234
- }
235
- /**
236
- * A node that contains some data.
237
- */
238
- class DataNode extends Node {
239
- data;
240
- /**
241
- * @param data The content of the data node
242
- */
243
- constructor(data) {
244
- super();
245
- this.data = data;
246
- }
247
- /**
248
- * Same as {@link data}.
249
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
250
- */
251
- get nodeValue() {
252
- return this.data;
253
- }
254
- set nodeValue(data) {
255
- this.data = data;
256
- }
257
- }
258
- /**
259
- * Text within the document.
260
- */
261
- class Text extends DataNode {
262
- type = ElementType.Text;
263
- get nodeType() {
264
- return 3;
265
- }
266
- }
267
- /**
268
- * Comments within the document.
269
- */
270
- class Comment extends DataNode {
271
- type = ElementType.Comment;
272
- get nodeType() {
273
- return 8;
274
- }
275
- }
276
- /**
277
- * Processing instructions, including doc types.
278
- */
279
- class ProcessingInstruction extends DataNode {
280
- type = ElementType.Directive;
281
- name;
282
- constructor(name, data) {
283
- super(data);
284
- this.name = name;
285
- }
286
- get nodeType() {
287
- return 1;
288
- }
289
- /** If this is a doctype, the document type name (parse5 only). */
290
- "x-name";
291
- /** If this is a doctype, the document type public identifier (parse5 only). */
292
- "x-publicId";
293
- /** If this is a doctype, the document type system identifier (parse5 only). */
294
- "x-systemId";
295
- }
296
- /**
297
- * A node that can have children.
298
- */
299
- class NodeWithChildren extends Node {
300
- children;
301
- /**
302
- * @param children Children of the node. Only certain node types can have children.
303
- */
304
- constructor(children) {
305
- super();
306
- this.children = children;
307
- }
308
- // Aliases
309
- /** First child of the node. */
310
- get firstChild() {
311
- return this.children[0] ?? null;
312
- }
313
- /** Last child of the node. */
314
- get lastChild() {
315
- return this.children.length > 0
316
- ? this.children[this.children.length - 1]
317
- : null;
318
- }
319
- /**
320
- * Same as {@link children}.
321
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
322
- */
323
- get childNodes() {
324
- return this.children;
325
- }
326
- set childNodes(children) {
327
- this.children = children;
328
- }
329
- }
330
- /**
331
- * CDATA nodes.
332
- */
333
- class CDATA extends NodeWithChildren {
334
- type = ElementType.CDATA;
335
- get nodeType() {
336
- return 4;
337
- }
338
- }
339
- /**
340
- * The root node of the document.
341
- */
342
- class Document extends NodeWithChildren {
343
- type = ElementType.Root;
344
- get nodeType() {
345
- return 9;
346
- }
347
- }
348
- /**
349
- * An element within the DOM.
350
- */
351
- class Element extends NodeWithChildren {
352
- name;
353
- attribs;
354
- type;
355
- /**
356
- * @param name Name of the tag, eg. `div`, `span`.
357
- * @param attribs Object mapping attribute names to attribute values.
358
- * @param children Children of the node.
359
- * @param type Node type used for the new node instance.
360
- */
361
- constructor(name, attribs, children = [], type = name === "script"
362
- ? ElementType.Script
363
- : name === "style"
364
- ? ElementType.Style
365
- : ElementType.Tag) {
366
- super(children);
367
- this.name = name;
368
- this.attribs = attribs;
369
- this.type = type;
370
- }
371
- get nodeType() {
372
- return 1;
373
- }
374
- // DOM Level 1 aliases
375
- /**
376
- * Same as {@link name}.
377
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
378
- */
379
- get tagName() {
380
- return this.name;
381
- }
382
- set tagName(name) {
383
- this.name = name;
384
- }
385
- get attributes() {
386
- return Object.keys(this.attribs).map((name) => ({
387
- name,
388
- value: this.attribs[name],
389
- namespace: this["x-attribsNamespace"]?.[name],
390
- prefix: this["x-attribsPrefix"]?.[name],
391
- }));
392
- }
393
- /** Element namespace (parse5 only). */
394
- namespace;
395
- /** Element attribute namespaces (parse5 only). */
396
- "x-attribsNamespace";
397
- /** Element attribute namespace-related prefixes (parse5 only). */
398
- "x-attribsPrefix";
399
- }
400
- /**
401
- * Checks if `node` is an element node.
402
- * @param node Node to check.
403
- * @returns `true` if the node is an element node.
404
- */
405
- function isTag(node) {
406
- return isTag$1(node);
407
- }
408
- /**
409
- * Checks if `node` is a CDATA node.
410
- * @param node Node to check.
411
- * @returns `true` if the node is a CDATA node.
412
- */
413
- function isCDATA(node) {
414
- return node.type === ElementType.CDATA;
415
- }
416
- /**
417
- * Checks if `node` is a text node.
418
- * @param node Node to check.
419
- * @returns `true` if the node is a text node.
420
- */
421
- function isText(node) {
422
- return node.type === ElementType.Text;
423
- }
424
- /**
425
- * Checks if `node` is a comment node.
426
- * @param node Node to check.
427
- * @returns `true` if the node is a comment node.
428
- */
429
- function isComment(node) {
430
- return node.type === ElementType.Comment;
431
- }
432
- /**
433
- * Checks if `node` is a directive node.
434
- * @param node Node to check.
435
- * @returns `true` if the node is a directive node.
436
- */
437
- function isDirective(node) {
438
- return node.type === ElementType.Directive;
439
- }
440
- /**
441
- * Checks if `node` is a document node.
442
- * @param node Node to check.
443
- * @returns `true` if the node is a document node.
444
- */
445
- function isDocument(node) {
446
- return node.type === ElementType.Root;
447
- }
448
- /**
449
- * Checks if `node` has children.
450
- * @param node Node to check.
451
- * @returns `true` if the node has children.
452
- */
453
- function hasChildren(node) {
454
- return Object.hasOwn(node, "children");
455
- }
456
- /**
457
- * Clone a node, and optionally its children.
458
- * @param node Node to clone.
459
- * @param recursive Clone child nodes as well.
460
- * @returns A clone of the node.
461
- */
462
- function cloneNode(node, recursive = false) {
463
- let result;
464
- if (isText(node)) {
465
- result = new Text(node.data);
466
- }
467
- else if (isComment(node)) {
468
- result = new Comment(node.data);
469
- }
470
- else if (isTag(node)) {
471
- const children = recursive ? cloneChildren(node.children) : [];
472
- const clone = new Element(node.name, { ...node.attribs }, children);
473
- for (const child of children) {
474
- child.parent = clone;
475
- }
476
- if (node.namespace != null) {
477
- clone.namespace = node.namespace;
478
- }
479
- if (node["x-attribsNamespace"]) {
480
- clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
481
- }
482
- if (node["x-attribsPrefix"]) {
483
- clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
484
- }
485
- result = clone;
486
- }
487
- else if (isCDATA(node)) {
488
- const children = recursive ? cloneChildren(node.children) : [];
489
- const clone = new CDATA(children);
490
- for (const child of children) {
491
- child.parent = clone;
492
- }
493
- result = clone;
494
- }
495
- else if (isDocument(node)) {
496
- const children = recursive ? cloneChildren(node.children) : [];
497
- const clone = new Document(children);
498
- for (const child of children) {
499
- child.parent = clone;
500
- }
501
- if (node["x-mode"]) {
502
- clone["x-mode"] = node["x-mode"];
503
- }
504
- result = clone;
505
- }
506
- else if (isDirective(node)) {
507
- const instruction = new ProcessingInstruction(node.name, node.data);
508
- if (node["x-name"] != null) {
509
- instruction["x-name"] = node["x-name"];
510
- instruction["x-publicId"] = node["x-publicId"];
511
- instruction["x-systemId"] = node["x-systemId"];
512
- }
513
- result = instruction;
514
- }
515
- else {
516
- throw new Error(`Not implemented yet: ${node.type}`);
517
- }
518
- result.startIndex = node.startIndex;
519
- result.endIndex = node.endIndex;
520
- if (node.sourceCodeLocation != null) {
521
- result.sourceCodeLocation = node.sourceCodeLocation;
522
- }
523
- return result;
524
- }
525
- /**
526
- * Clone a list of child nodes.
527
- * @param childs The child nodes to clone.
528
- * @returns A list of cloned child nodes.
529
- */
530
- function cloneChildren(childs) {
531
- const children = childs.map((child) => cloneNode(child, true));
532
- for (let index = 1; index < children.length; index++) {
533
- children[index].prev = children[index - 1];
534
- children[index - 1].next = children[index];
535
- }
536
- return children;
537
- }
538
-
539
- // Default options
540
- const defaultOptions = {
541
- withStartIndices: false,
542
- withEndIndices: false,
543
- xmlMode: false,
544
- };
545
- /**
546
- * Event-based handler that builds a DOM tree from parser callbacks.
547
- */
548
- class DomHandler {
549
- /** The elements of the DOM */
550
- dom = [];
551
- /** The root element for the DOM */
552
- root = new Document(this.dom);
553
- /** Called once parsing has completed. */
554
- callback;
555
- /** Settings for the handler. */
556
- options;
557
- /** Callback whenever a tag is closed. */
558
- elementCB;
559
- /** Indicated whether parsing has been completed. */
560
- done = false;
561
- /** Stack of open tags. */
562
- tagStack = [this.root];
563
- /** A data node that is still being written to. */
564
- lastNode = null;
565
- /** Reference to the parser instance. Used for location information. */
566
- parser = null;
567
- /**
568
- * @param callback Called once parsing has completed.
569
- * @param options Settings for the handler.
570
- * @param elementCB Callback whenever a tag is closed.
571
- */
572
- constructor(callback, options, elementCB) {
573
- // Make it possible to skip arguments, for backwards-compatibility
574
- if (typeof options === "function") {
575
- elementCB = options;
576
- options = defaultOptions;
577
- }
578
- if (typeof callback === "object") {
579
- options = callback;
580
- callback = undefined;
581
- }
582
- this.callback = callback ?? null;
583
- this.options = options ?? defaultOptions;
584
- this.elementCB = elementCB ?? null;
585
- }
586
- onparserinit(parser) {
587
- this.parser = parser;
588
- }
589
- // Resets the handler back to starting state
590
- onreset() {
591
- this.dom = [];
592
- this.root = new Document(this.dom);
593
- this.done = false;
594
- this.tagStack = [this.root];
595
- this.lastNode = null;
596
- this.parser = null;
597
- }
598
- // Signals the handler that parsing is done
599
- onend() {
600
- if (this.done)
601
- return;
602
- this.done = true;
603
- this.parser = null;
604
- this.handleCallback(null);
605
- }
606
- onerror(error) {
607
- this.handleCallback(error);
608
- }
609
- onclosetag() {
610
- this.lastNode = null;
611
- const element = this.tagStack.pop();
612
- if (this.options.withEndIndices && this.parser) {
613
- element.endIndex = this.parser.endIndex;
614
- }
615
- if (this.elementCB)
616
- this.elementCB(element);
617
- }
618
- onopentag(name, attribs) {
619
- const type = this.options.xmlMode ? ElementType.Tag : undefined;
620
- const element = new Element(name, attribs, undefined, type);
621
- this.addNode(element);
622
- this.tagStack.push(element);
623
- }
624
- ontext(data) {
625
- const { lastNode } = this;
626
- if (lastNode && lastNode.type === ElementType.Text) {
627
- lastNode.data += data;
628
- if (this.options.withEndIndices && this.parser) {
629
- lastNode.endIndex = this.parser.endIndex;
630
- }
631
- }
632
- else {
633
- const node = new Text(data);
634
- this.addNode(node);
635
- this.lastNode = node;
636
- }
637
- }
638
- oncomment(data) {
639
- if (this.lastNode && this.lastNode.type === ElementType.Comment) {
640
- this.lastNode.data += data;
641
- return;
642
- }
643
- const node = new Comment(data);
644
- this.addNode(node);
645
- this.lastNode = node;
646
- }
647
- oncommentend() {
648
- this.lastNode = null;
649
- }
650
- oncdatastart() {
651
- const text = new Text("");
652
- const node = new CDATA([text]);
653
- this.addNode(node);
654
- text.parent = node;
655
- this.lastNode = text;
656
- }
657
- oncdataend() {
658
- this.lastNode = null;
659
- }
660
- onprocessinginstruction(name, data) {
661
- const node = new ProcessingInstruction(name, data);
662
- this.addNode(node);
663
- }
664
- handleCallback(error) {
665
- if (typeof this.callback === "function") {
666
- this.callback(error, this.dom);
667
- }
668
- else if (error) {
669
- throw error;
670
- }
671
- }
672
- addNode(node) {
673
- const parent = this.tagStack[this.tagStack.length - 1];
674
- const previousSibling = parent.children[parent.children.length - 1];
675
- if (this.options.withStartIndices && this.parser) {
676
- node.startIndex = this.parser.startIndex;
677
- }
678
- if (this.options.withEndIndices && this.parser) {
679
- node.endIndex = this.parser.endIndex;
680
- }
681
- parent.children.push(node);
682
- if (previousSibling) {
683
- node.prev = previousSibling;
684
- previousSibling.next = node;
685
- }
686
- node.parent = parent;
687
- this.lastNode = null;
688
- }
689
- }
690
-
691
- var dist$1 = /*#__PURE__*/Object.freeze({
692
- __proto__: null,
693
- CDATA: CDATA,
694
- Comment: Comment,
695
- DataNode: DataNode,
696
- Document: Document,
697
- DomHandler: DomHandler,
698
- Element: Element,
699
- Node: Node,
700
- NodeWithChildren: NodeWithChildren,
701
- ProcessingInstruction: ProcessingInstruction,
702
- Text: Text,
703
- cloneNode: cloneNode,
704
- default: DomHandler,
705
- hasChildren: hasChildren,
706
- isCDATA: isCDATA,
707
- isComment: isComment,
708
- isDirective: isDirective,
709
- isDocument: isDocument,
710
- isTag: isTag,
711
- isText: isText
712
- });
713
-
714
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(dist$1);
715
-
716
- var hasRequiredUtilities$1;
527
+ var hasRequiredUtilities$1;
717
528
 
718
529
  function requireUtilities$1 () {
719
530
  if (hasRequiredUtilities$1) return utilities$1;
720
531
  hasRequiredUtilities$1 = 1;
532
+ const require_node = requireNode();
721
533
  const require_constants = requireConstants();
722
- let domhandler = require$$3;
723
534
  //#region src/client/utilities.ts
724
535
  const CARRIAGE_RETURN = "\r";
725
536
  const CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, "g");
@@ -813,16 +624,16 @@
813
624
  switch (node.nodeType) {
814
625
  case 1: {
815
626
  const tagName = formatTagName(node.nodeName);
816
- current = new domhandler.Element(tagName, formatAttributes(node.attributes));
627
+ current = new require_node.Element(tagName, formatAttributes(node.attributes));
817
628
  current.children = formatDOM(tagName === "template" ? node.content.childNodes : node.childNodes, current);
818
629
  break;
819
630
  }
820
631
  /* v8 ignore start */
821
632
  case 3:
822
- current = new domhandler.Text(revertEscapedCharacters(node.nodeValue ?? ""));
633
+ current = new require_node.Text(revertEscapedCharacters(node.nodeValue ?? ""));
823
634
  break;
824
635
  case 8:
825
- current = new domhandler.Comment(node.nodeValue ?? "");
636
+ current = new require_node.Comment(node.nodeValue ?? "");
826
637
  break;
827
638
  /* v8 ignore stop */
828
639
  default: continue;
@@ -835,7 +646,7 @@
835
646
  domNodes.push(current);
836
647
  }
837
648
  if (directive) {
838
- current = new domhandler.ProcessingInstruction(directive.substring(0, directive.indexOf(" ")).toLowerCase(), directive);
649
+ current = new require_node.ProcessingInstruction(directive.substring(0, directive.indexOf(" ")).toLowerCase(), directive);
839
650
  current.next = domNodes[0] ?? null;
840
651
  current.parent = parent;
841
652
  domNodes.unshift(current);
@@ -2262,393 +2073,990 @@
2262
2073
  if (!prop) return;
2263
2074
  comment();
2264
2075
 
2265
- // :
2266
- if (!match(COLON_REGEX)) return error("property missing ':'");
2076
+ // :
2077
+ if (!match(COLON_REGEX)) return error("property missing ':'");
2078
+
2079
+ // val
2080
+ var val = match(VALUE_REGEX);
2081
+
2082
+ var ret = pos({
2083
+ type: TYPE_DECLARATION,
2084
+ property: prop[0].replace(COMMENT_REGEX, EMPTY_STRING).trim(),
2085
+ value: val
2086
+ ? val[0].replace(COMMENT_REGEX, EMPTY_STRING).trim()
2087
+ : EMPTY_STRING
2088
+ });
2089
+
2090
+ // ;
2091
+ match(SEMICOLON_REGEX);
2092
+
2093
+ return ret;
2094
+ }
2095
+
2096
+ /**
2097
+ * Parse declarations.
2098
+ *
2099
+ * @return {Object[]}
2100
+ */
2101
+ function declarations() {
2102
+ var decls = [];
2103
+
2104
+ comments(decls);
2105
+
2106
+ // declarations
2107
+ var decl;
2108
+ while ((decl = declaration())) {
2109
+ decls.push(decl);
2110
+ comments(decls);
2111
+ }
2112
+
2113
+ return decls;
2114
+ }
2115
+
2116
+ whitespace();
2117
+ return declarations();
2118
+ }
2119
+
2120
+ cjs$1 = index;
2121
+
2122
+ return cjs$1;
2123
+ }
2124
+
2125
+ var cjs;
2126
+ var hasRequiredCjs;
2127
+
2128
+ function requireCjs () {
2129
+ if (hasRequiredCjs) return cjs;
2130
+ hasRequiredCjs = 1;
2131
+ //#region \0rolldown/runtime.js
2132
+ var __create = Object.create;
2133
+ var __defProp = Object.defineProperty;
2134
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2135
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2136
+ var __getProtoOf = Object.getPrototypeOf;
2137
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2138
+ var __copyProps = (to, from, except, desc) => {
2139
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2140
+ key = keys[i];
2141
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2142
+ get: ((k) => from[k]).bind(null, key),
2143
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2144
+ });
2145
+ }
2146
+ return to;
2147
+ };
2148
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2149
+ value: mod,
2150
+ enumerable: true
2151
+ }) : target, mod));
2152
+ //#endregion
2153
+ let inline_style_parser = requireCjs$1();
2154
+ inline_style_parser = __toESM(inline_style_parser);
2155
+ //#region src/index.ts
2156
+ /**
2157
+ * Parses inline style to object.
2158
+ *
2159
+ * @param style - Inline style.
2160
+ * @param iterator - Iterator.
2161
+ * @returns - Style object or null.
2162
+ *
2163
+ * @example Parsing inline style to object:
2164
+ *
2165
+ * ```js
2166
+ * import parse from 'style-to-object';
2167
+ * parse('line-height: 42;'); // { 'line-height': '42' }
2168
+ * ```
2169
+ */
2170
+ function StyleToObject(style, iterator) {
2171
+ let styleObject = null;
2172
+ if (!style || typeof style !== "string") return styleObject;
2173
+ const declarations = (0, inline_style_parser.default)(style);
2174
+ const hasIterator = typeof iterator === "function";
2175
+ declarations.forEach((declaration) => {
2176
+ if (declaration.type !== "declaration") return;
2177
+ const { property, value } = declaration;
2178
+ if (hasIterator) iterator(property, value, declaration);
2179
+ else if (value) {
2180
+ styleObject = styleObject ?? {};
2181
+ styleObject[property] = value;
2182
+ }
2183
+ });
2184
+ return styleObject;
2185
+ }
2186
+ //#endregion
2187
+ cjs = StyleToObject;
2267
2188
 
2268
- // val
2269
- var val = match(VALUE_REGEX);
2189
+
2190
+ return cjs;
2191
+ }
2270
2192
 
2271
- var ret = pos({
2272
- type: TYPE_DECLARATION,
2273
- property: prop[0].replace(COMMENT_REGEX, EMPTY_STRING).trim(),
2274
- value: val
2275
- ? val[0].replace(COMMENT_REGEX, EMPTY_STRING).trim()
2276
- : EMPTY_STRING
2277
- });
2193
+ var dist$1;
2194
+ var hasRequiredDist;
2278
2195
 
2279
- // ;
2280
- match(SEMICOLON_REGEX);
2196
+ function requireDist () {
2197
+ if (hasRequiredDist) return dist$1;
2198
+ hasRequiredDist = 1;
2199
+ //#region \0rolldown/runtime.js
2200
+ var __create = Object.create;
2201
+ var __defProp = Object.defineProperty;
2202
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2203
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2204
+ var __getProtoOf = Object.getPrototypeOf;
2205
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2206
+ var __copyProps = (to, from, except, desc) => {
2207
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2208
+ key = keys[i];
2209
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2210
+ get: ((k) => from[k]).bind(null, key),
2211
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2212
+ });
2213
+ }
2214
+ return to;
2215
+ };
2216
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2217
+ value: mod,
2218
+ enumerable: true
2219
+ }) : target, mod));
2220
+ //#endregion
2221
+ let style_to_object = requireCjs();
2222
+ style_to_object = __toESM(style_to_object);
2223
+ //#region src/utilities.ts
2224
+ const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
2225
+ const HYPHEN_REGEX = /-([a-z])/g;
2226
+ const NO_HYPHEN_REGEX = /^[^-]+$/;
2227
+ const VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
2228
+ const MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
2229
+ /**
2230
+ * Checks whether to skip camelCase.
2231
+ */
2232
+ const skipCamelCase = (property) => !property || NO_HYPHEN_REGEX.test(property) || CUSTOM_PROPERTY_REGEX.test(property);
2233
+ /**
2234
+ * Replacer that capitalizes first character.
2235
+ */
2236
+ const capitalize = (match, character) => character.toUpperCase();
2237
+ /**
2238
+ * Replacer that removes beginning hyphen of vendor prefix property.
2239
+ */
2240
+ const trimHyphen = (match, prefix) => `${prefix}-`;
2241
+ /**
2242
+ * CamelCases a CSS property.
2243
+ */
2244
+ const camelCase = (property, options = {}) => {
2245
+ if (skipCamelCase(property)) return property;
2246
+ property = property.toLowerCase();
2247
+ if (options.reactCompat) property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
2248
+ else property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
2249
+ return property.replace(HYPHEN_REGEX, capitalize);
2250
+ };
2251
+ //#endregion
2252
+ //#region src/index.ts
2253
+ /**
2254
+ * Parses CSS inline style to JavaScript object (camelCased).
2255
+ */
2256
+ function StyleToJS(style, options) {
2257
+ const output = {};
2258
+ if (!style || typeof style !== "string") return output;
2259
+ (0, style_to_object.default)(style, (property, value) => {
2260
+ if (property && value) output[camelCase(property, options)] = value;
2261
+ });
2262
+ return output;
2263
+ }
2264
+ //#endregion
2265
+ dist$1 = StyleToJS;
2281
2266
 
2282
- return ret;
2283
- }
2267
+
2268
+ return dist$1;
2269
+ }
2284
2270
 
2285
- /**
2286
- * Parse declarations.
2287
- *
2288
- * @return {Object[]}
2289
- */
2290
- function declarations() {
2291
- var decls = [];
2271
+ var hasRequiredUtilities;
2272
+
2273
+ function requireUtilities () {
2274
+ if (hasRequiredUtilities) return utilities;
2275
+ hasRequiredUtilities = 1;
2276
+ (function (exports) {
2277
+ var __importDefault = (utilities && utilities.__importDefault) || function (mod) {
2278
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2279
+ };
2280
+ Object.defineProperty(exports, "__esModule", { value: true });
2281
+ exports.returnFirstArg = exports.canTextBeChildOfNode = exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2282
+ exports.isCustomComponent = isCustomComponent;
2283
+ exports.setStyleProp = setStyleProp;
2284
+ const react_1 = require$$0;
2285
+ const style_to_js_1 = __importDefault(requireDist());
2286
+ const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2287
+ 'annotation-xml',
2288
+ 'color-profile',
2289
+ 'font-face',
2290
+ 'font-face-src',
2291
+ 'font-face-uri',
2292
+ 'font-face-format',
2293
+ 'font-face-name',
2294
+ 'missing-glyph',
2295
+ ]);
2296
+ /**
2297
+ * Check if a tag is a custom component.
2298
+ *
2299
+ * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
2300
+ *
2301
+ * @param tagName - Tag name.
2302
+ * @param props - Props passed to the element.
2303
+ * @returns - Whether the tag is custom component.
2304
+ */
2305
+ function isCustomComponent(tagName, props) {
2306
+ if (!tagName.includes('-')) {
2307
+ return Boolean(props && typeof props.is === 'string');
2308
+ }
2309
+ // These are reserved SVG and MathML elements.
2310
+ // We don't mind this whitelist too much because we expect it to never grow.
2311
+ // The alternative is to track the namespace in a few places which is convoluted.
2312
+ // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
2313
+ if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
2314
+ return false;
2315
+ }
2316
+ return true;
2317
+ }
2318
+ const styleOptions = {
2319
+ reactCompat: true,
2320
+ };
2321
+ /**
2322
+ * Sets style prop.
2323
+ *
2324
+ * @param style - Inline style.
2325
+ * @param props - Props object.
2326
+ */
2327
+ function setStyleProp(style, props) {
2328
+ if (typeof style !== 'string') {
2329
+ return;
2330
+ }
2331
+ if (!style.trim()) {
2332
+ props.style = {};
2333
+ return;
2334
+ }
2335
+ try {
2336
+ props.style = (0, style_to_js_1.default)(style, styleOptions);
2337
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2338
+ }
2339
+ catch (error) {
2340
+ props.style = {};
2341
+ }
2342
+ }
2343
+ /**
2344
+ * @see https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
2345
+ */
2346
+ exports.PRESERVE_CUSTOM_ATTRIBUTES = Number(react_1.version.split('.')[0]) >= 16;
2347
+ /**
2348
+ * @see https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
2349
+ */
2350
+ exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
2351
+ 'tr',
2352
+ 'tbody',
2353
+ 'thead',
2354
+ 'tfoot',
2355
+ 'colgroup',
2356
+ 'table',
2357
+ 'head',
2358
+ 'html',
2359
+ 'frameset',
2360
+ ]);
2361
+ /**
2362
+ * Checks if the given node can contain text nodes
2363
+ *
2364
+ * @param node - Element node.
2365
+ * @returns - Whether the node can contain text nodes.
2366
+ */
2367
+ const canTextBeChildOfNode = (node) => !exports.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2368
+ exports.canTextBeChildOfNode = canTextBeChildOfNode;
2369
+ /**
2370
+ * Returns the first argument as is.
2371
+ *
2372
+ * @param arg - The argument to be returned.
2373
+ * @returns - The input argument `arg`.
2374
+ */
2375
+ const returnFirstArg = (arg) => arg;
2376
+ exports.returnFirstArg = returnFirstArg;
2377
+
2378
+ } (utilities));
2379
+ return utilities;
2380
+ }
2292
2381
 
2293
- comments(decls);
2382
+ var hasRequiredAttributesToProps;
2294
2383
 
2295
- // declarations
2296
- var decl;
2297
- while ((decl = declaration())) {
2298
- decls.push(decl);
2299
- comments(decls);
2384
+ function requireAttributesToProps () {
2385
+ if (hasRequiredAttributesToProps) return attributesToProps;
2386
+ hasRequiredAttributesToProps = 1;
2387
+ Object.defineProperty(attributesToProps, "__esModule", { value: true });
2388
+ attributesToProps.default = attributesToProps$1;
2389
+ const react_property_1 = requireLib$1();
2390
+ const utilities_1 = requireUtilities();
2391
+ // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2392
+ // https://developer.mozilla.org/docs/Web/HTML/Attributes
2393
+ const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2394
+ const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2395
+ const valueOnlyInputs = {
2396
+ reset: true,
2397
+ submit: true,
2398
+ };
2399
+ /**
2400
+ * Converts HTML/SVG DOM attributes to React props.
2401
+ *
2402
+ * @param attributes - HTML/SVG DOM attributes.
2403
+ * @param nodeName - DOM node name.
2404
+ * @returns - React props.
2405
+ */
2406
+ function attributesToProps$1(attributes = {}, nodeName) {
2407
+ const props = {};
2408
+ const isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2409
+ for (const attributeName in attributes) {
2410
+ const attributeValue = attributes[attributeName];
2411
+ // ARIA (aria-*) or custom data (data-*) attribute
2412
+ if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2413
+ props[attributeName] = attributeValue;
2414
+ continue;
2415
+ }
2416
+ // convert HTML/SVG attribute to React prop
2417
+ const attributeNameLowerCased = attributeName.toLowerCase();
2418
+ let propName = getPropName(attributeNameLowerCased);
2419
+ if (propName) {
2420
+ const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2421
+ // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2422
+ if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2423
+ UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
2424
+ !isInputValueOnly) {
2425
+ propName = getPropName('default' + attributeNameLowerCased);
2426
+ }
2427
+ props[propName] = attributeValue;
2428
+ switch (propertyInfo === null || propertyInfo === void 0 ? void 0 : propertyInfo.type) {
2429
+ case react_property_1.BOOLEAN:
2430
+ props[propName] = true;
2431
+ break;
2432
+ case react_property_1.OVERLOADED_BOOLEAN:
2433
+ if (attributeValue === '') {
2434
+ props[propName] = true;
2435
+ }
2436
+ break;
2437
+ }
2438
+ continue;
2439
+ }
2440
+ // preserve custom attribute if React >=16
2441
+ if (utilities_1.PRESERVE_CUSTOM_ATTRIBUTES) {
2442
+ props[attributeName] = attributeValue;
2443
+ }
2300
2444
  }
2445
+ // transform inline style to object
2446
+ (0, utilities_1.setStyleProp)(attributes.style, props);
2447
+ return props;
2448
+ }
2449
+ /**
2450
+ * Gets prop name from lowercased attribute name.
2451
+ *
2452
+ * @param attributeName - Lowercased attribute name.
2453
+ * @returns - Prop name.
2454
+ */
2455
+ function getPropName(attributeName) {
2456
+ return react_property_1.possibleStandardNames[attributeName];
2457
+ }
2458
+
2459
+ return attributesToProps;
2460
+ }
2301
2461
 
2302
- return decls;
2303
- }
2462
+ var domToReact = {};
2304
2463
 
2305
- whitespace();
2306
- return declarations();
2307
- }
2464
+ /** Types of elements found in htmlparser2's DOM */
2465
+ var ElementType;
2466
+ (function (ElementType) {
2467
+ /** Type for the root element of a document */
2468
+ ElementType["Root"] = "root";
2469
+ /** Type for Text */
2470
+ ElementType["Text"] = "text";
2471
+ /** Type for <? ... ?> */
2472
+ ElementType["Directive"] = "directive";
2473
+ /** Type for <!-- ... --> */
2474
+ ElementType["Comment"] = "comment";
2475
+ /** Type for <script> tags */
2476
+ ElementType["Script"] = "script";
2477
+ /** Type for <style> tags */
2478
+ ElementType["Style"] = "style";
2479
+ /** Type for Any tag */
2480
+ ElementType["Tag"] = "tag";
2481
+ /** Type for <![CDATA[ ... ]]> */
2482
+ ElementType["CDATA"] = "cdata";
2483
+ /** Type for <!doctype ...> */
2484
+ ElementType["Doctype"] = "doctype";
2485
+ })(ElementType || (ElementType = {}));
2486
+ /**
2487
+ * Tests whether an element is a tag or not.
2488
+ * @param element Element to test
2489
+ * @param element.type Node type discriminator to check.
2490
+ */
2491
+ function isTag$1(element) {
2492
+ return (element.type === ElementType.Tag ||
2493
+ element.type === ElementType.Script ||
2494
+ element.type === ElementType.Style);
2495
+ }
2496
+ // Exports for backwards compatibility
2497
+ /** Type for the root element of a document */
2498
+ // eslint-disable-next-line prefer-destructuring
2499
+ ElementType.Root;
2500
+ /** Type for Text */
2501
+ // eslint-disable-next-line prefer-destructuring
2502
+ ElementType.Text;
2503
+ /** Type for <? ... ?> */
2504
+ // eslint-disable-next-line prefer-destructuring
2505
+ ElementType.Directive;
2506
+ /** Type for <!-- ... --> */
2507
+ // eslint-disable-next-line prefer-destructuring
2508
+ ElementType.Comment;
2509
+ /** Type for <script> tags */
2510
+ // eslint-disable-next-line prefer-destructuring
2511
+ ElementType.Script;
2512
+ /** Type for <style> tags */
2513
+ // eslint-disable-next-line prefer-destructuring
2514
+ ElementType.Style;
2515
+ /** Type for Any tag */
2516
+ // eslint-disable-next-line prefer-destructuring
2517
+ ElementType.Tag;
2518
+ /** Type for <![CDATA[ ... ]]> */
2519
+ // eslint-disable-next-line prefer-destructuring
2520
+ ElementType.CDATA;
2521
+ /** Type for <!doctype ...> */
2522
+ // eslint-disable-next-line prefer-destructuring
2523
+ ElementType.Doctype;
2308
2524
 
2309
- cjs$1 = index;
2310
-
2311
- return cjs$1;
2525
+ /**
2526
+ * This object will be used as the prototype for Nodes when creating a
2527
+ * DOM-Level-1-compliant structure.
2528
+ */
2529
+ class Node {
2530
+ /** Parent of the node */
2531
+ parent = null;
2532
+ /** Previous sibling */
2533
+ prev = null;
2534
+ /** Next sibling */
2535
+ next = null;
2536
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
2537
+ startIndex = null;
2538
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
2539
+ endIndex = null;
2540
+ // Read-write aliases for properties
2541
+ /**
2542
+ * Same as {@link parent}.
2543
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2544
+ */
2545
+ get parentNode() {
2546
+ return this.parent;
2547
+ }
2548
+ set parentNode(parent) {
2549
+ this.parent = parent;
2550
+ }
2551
+ /**
2552
+ * Same as {@link prev}.
2553
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2554
+ */
2555
+ get previousSibling() {
2556
+ return this.prev;
2557
+ }
2558
+ set previousSibling(previous) {
2559
+ this.prev = previous;
2560
+ }
2561
+ /**
2562
+ * Same as {@link next}.
2563
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2564
+ */
2565
+ get nextSibling() {
2566
+ return this.next;
2567
+ }
2568
+ set nextSibling(next) {
2569
+ this.next = next;
2570
+ }
2571
+ /**
2572
+ * Clone this node, and optionally its children.
2573
+ * @param recursive Clone child nodes as well.
2574
+ * @returns A clone of the node.
2575
+ */
2576
+ cloneNode(recursive = false) {
2577
+ return cloneNode(this, recursive);
2578
+ }
2579
+ }
2580
+ /**
2581
+ * A node that contains some data.
2582
+ */
2583
+ class DataNode extends Node {
2584
+ data;
2585
+ /**
2586
+ * @param data The content of the data node
2587
+ */
2588
+ constructor(data) {
2589
+ super();
2590
+ this.data = data;
2591
+ }
2592
+ /**
2593
+ * Same as {@link data}.
2594
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2595
+ */
2596
+ get nodeValue() {
2597
+ return this.data;
2598
+ }
2599
+ set nodeValue(data) {
2600
+ this.data = data;
2601
+ }
2602
+ }
2603
+ /**
2604
+ * Text within the document.
2605
+ */
2606
+ class Text extends DataNode {
2607
+ type = ElementType.Text;
2608
+ get nodeType() {
2609
+ return 3;
2610
+ }
2611
+ }
2612
+ /**
2613
+ * Comments within the document.
2614
+ */
2615
+ class Comment extends DataNode {
2616
+ type = ElementType.Comment;
2617
+ get nodeType() {
2618
+ return 8;
2619
+ }
2312
2620
  }
2313
-
2314
- var cjs;
2315
- var hasRequiredCjs;
2316
-
2317
- function requireCjs () {
2318
- if (hasRequiredCjs) return cjs;
2319
- hasRequiredCjs = 1;
2320
- //#region \0rolldown/runtime.js
2321
- var __create = Object.create;
2322
- var __defProp = Object.defineProperty;
2323
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2324
- var __getOwnPropNames = Object.getOwnPropertyNames;
2325
- var __getProtoOf = Object.getPrototypeOf;
2326
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2327
- var __copyProps = (to, from, except, desc) => {
2328
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2329
- key = keys[i];
2330
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2331
- get: ((k) => from[k]).bind(null, key),
2332
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2333
- });
2334
- }
2335
- return to;
2336
- };
2337
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2338
- value: mod,
2339
- enumerable: true
2340
- }) : target, mod));
2341
- //#endregion
2342
- let inline_style_parser = requireCjs$1();
2343
- inline_style_parser = __toESM(inline_style_parser);
2344
- //#region src/index.ts
2345
- /**
2346
- * Parses inline style to object.
2347
- *
2348
- * @param style - Inline style.
2349
- * @param iterator - Iterator.
2350
- * @returns - Style object or null.
2351
- *
2352
- * @example Parsing inline style to object:
2353
- *
2354
- * ```js
2355
- * import parse from 'style-to-object';
2356
- * parse('line-height: 42;'); // { 'line-height': '42' }
2357
- * ```
2358
- */
2359
- function StyleToObject(style, iterator) {
2360
- let styleObject = null;
2361
- if (!style || typeof style !== "string") return styleObject;
2362
- const declarations = (0, inline_style_parser.default)(style);
2363
- const hasIterator = typeof iterator === "function";
2364
- declarations.forEach((declaration) => {
2365
- if (declaration.type !== "declaration") return;
2366
- const { property, value } = declaration;
2367
- if (hasIterator) iterator(property, value, declaration);
2368
- else if (value) {
2369
- styleObject = styleObject ?? {};
2370
- styleObject[property] = value;
2371
- }
2372
- });
2373
- return styleObject;
2374
- }
2375
- //#endregion
2376
- cjs = StyleToObject;
2377
-
2378
-
2379
- return cjs;
2621
+ /**
2622
+ * Processing instructions, including doc types.
2623
+ */
2624
+ class ProcessingInstruction extends DataNode {
2625
+ type = ElementType.Directive;
2626
+ name;
2627
+ constructor(name, data) {
2628
+ super(data);
2629
+ this.name = name;
2630
+ }
2631
+ get nodeType() {
2632
+ return 1;
2633
+ }
2634
+ /** If this is a doctype, the document type name (parse5 only). */
2635
+ "x-name";
2636
+ /** If this is a doctype, the document type public identifier (parse5 only). */
2637
+ "x-publicId";
2638
+ /** If this is a doctype, the document type system identifier (parse5 only). */
2639
+ "x-systemId";
2380
2640
  }
2381
-
2382
- var dist;
2383
- var hasRequiredDist;
2384
-
2385
- function requireDist () {
2386
- if (hasRequiredDist) return dist;
2387
- hasRequiredDist = 1;
2388
- //#region \0rolldown/runtime.js
2389
- var __create = Object.create;
2390
- var __defProp = Object.defineProperty;
2391
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2392
- var __getOwnPropNames = Object.getOwnPropertyNames;
2393
- var __getProtoOf = Object.getPrototypeOf;
2394
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2395
- var __copyProps = (to, from, except, desc) => {
2396
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2397
- key = keys[i];
2398
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2399
- get: ((k) => from[k]).bind(null, key),
2400
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2401
- });
2402
- }
2403
- return to;
2404
- };
2405
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2406
- value: mod,
2407
- enumerable: true
2408
- }) : target, mod));
2409
- //#endregion
2410
- let style_to_object = requireCjs();
2411
- style_to_object = __toESM(style_to_object);
2412
- //#region src/utilities.ts
2413
- const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
2414
- const HYPHEN_REGEX = /-([a-z])/g;
2415
- const NO_HYPHEN_REGEX = /^[^-]+$/;
2416
- const VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
2417
- const MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
2418
- /**
2419
- * Checks whether to skip camelCase.
2420
- */
2421
- const skipCamelCase = (property) => !property || NO_HYPHEN_REGEX.test(property) || CUSTOM_PROPERTY_REGEX.test(property);
2422
- /**
2423
- * Replacer that capitalizes first character.
2424
- */
2425
- const capitalize = (match, character) => character.toUpperCase();
2426
- /**
2427
- * Replacer that removes beginning hyphen of vendor prefix property.
2428
- */
2429
- const trimHyphen = (match, prefix) => `${prefix}-`;
2430
- /**
2431
- * CamelCases a CSS property.
2432
- */
2433
- const camelCase = (property, options = {}) => {
2434
- if (skipCamelCase(property)) return property;
2435
- property = property.toLowerCase();
2436
- if (options.reactCompat) property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
2437
- else property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
2438
- return property.replace(HYPHEN_REGEX, capitalize);
2439
- };
2440
- //#endregion
2441
- //#region src/index.ts
2442
- /**
2443
- * Parses CSS inline style to JavaScript object (camelCased).
2444
- */
2445
- function StyleToJS(style, options) {
2446
- const output = {};
2447
- if (!style || typeof style !== "string") return output;
2448
- (0, style_to_object.default)(style, (property, value) => {
2449
- if (property && value) output[camelCase(property, options)] = value;
2450
- });
2451
- return output;
2452
- }
2453
- //#endregion
2454
- dist = StyleToJS;
2455
-
2456
-
2457
- return dist;
2641
+ /**
2642
+ * A node that can have children.
2643
+ */
2644
+ class NodeWithChildren extends Node {
2645
+ children;
2646
+ /**
2647
+ * @param children Children of the node. Only certain node types can have children.
2648
+ */
2649
+ constructor(children) {
2650
+ super();
2651
+ this.children = children;
2652
+ }
2653
+ // Aliases
2654
+ /** First child of the node. */
2655
+ get firstChild() {
2656
+ return this.children[0] ?? null;
2657
+ }
2658
+ /** Last child of the node. */
2659
+ get lastChild() {
2660
+ return this.children.length > 0
2661
+ ? this.children[this.children.length - 1]
2662
+ : null;
2663
+ }
2664
+ /**
2665
+ * Same as {@link children}.
2666
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2667
+ */
2668
+ get childNodes() {
2669
+ return this.children;
2670
+ }
2671
+ set childNodes(children) {
2672
+ this.children = children;
2673
+ }
2674
+ }
2675
+ /**
2676
+ * CDATA nodes.
2677
+ */
2678
+ class CDATA extends NodeWithChildren {
2679
+ type = ElementType.CDATA;
2680
+ get nodeType() {
2681
+ return 4;
2682
+ }
2683
+ }
2684
+ /**
2685
+ * The root node of the document.
2686
+ */
2687
+ class Document extends NodeWithChildren {
2688
+ type = ElementType.Root;
2689
+ get nodeType() {
2690
+ return 9;
2691
+ }
2692
+ }
2693
+ /**
2694
+ * An element within the DOM.
2695
+ */
2696
+ class Element extends NodeWithChildren {
2697
+ name;
2698
+ attribs;
2699
+ type;
2700
+ /**
2701
+ * @param name Name of the tag, eg. `div`, `span`.
2702
+ * @param attribs Object mapping attribute names to attribute values.
2703
+ * @param children Children of the node.
2704
+ * @param type Node type used for the new node instance.
2705
+ */
2706
+ constructor(name, attribs, children = [], type = name === "script"
2707
+ ? ElementType.Script
2708
+ : name === "style"
2709
+ ? ElementType.Style
2710
+ : ElementType.Tag) {
2711
+ super(children);
2712
+ this.name = name;
2713
+ this.attribs = attribs;
2714
+ this.type = type;
2715
+ }
2716
+ get nodeType() {
2717
+ return 1;
2718
+ }
2719
+ // DOM Level 1 aliases
2720
+ /**
2721
+ * Same as {@link name}.
2722
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2723
+ */
2724
+ get tagName() {
2725
+ return this.name;
2726
+ }
2727
+ set tagName(name) {
2728
+ this.name = name;
2729
+ }
2730
+ get attributes() {
2731
+ return Object.keys(this.attribs).map((name) => ({
2732
+ name,
2733
+ value: this.attribs[name],
2734
+ namespace: this["x-attribsNamespace"]?.[name],
2735
+ prefix: this["x-attribsPrefix"]?.[name],
2736
+ }));
2737
+ }
2738
+ /** Element namespace (parse5 only). */
2739
+ namespace;
2740
+ /** Element attribute namespaces (parse5 only). */
2741
+ "x-attribsNamespace";
2742
+ /** Element attribute namespace-related prefixes (parse5 only). */
2743
+ "x-attribsPrefix";
2458
2744
  }
2459
-
2460
- var hasRequiredUtilities;
2461
-
2462
- function requireUtilities () {
2463
- if (hasRequiredUtilities) return utilities;
2464
- hasRequiredUtilities = 1;
2465
- (function (exports) {
2466
- var __importDefault = (utilities && utilities.__importDefault) || function (mod) {
2467
- return (mod && mod.__esModule) ? mod : { "default": mod };
2468
- };
2469
- Object.defineProperty(exports, "__esModule", { value: true });
2470
- exports.returnFirstArg = exports.canTextBeChildOfNode = exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2471
- exports.isCustomComponent = isCustomComponent;
2472
- exports.setStyleProp = setStyleProp;
2473
- const react_1 = require$$0;
2474
- const style_to_js_1 = __importDefault(requireDist());
2475
- const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2476
- 'annotation-xml',
2477
- 'color-profile',
2478
- 'font-face',
2479
- 'font-face-src',
2480
- 'font-face-uri',
2481
- 'font-face-format',
2482
- 'font-face-name',
2483
- 'missing-glyph',
2484
- ]);
2485
- /**
2486
- * Check if a tag is a custom component.
2487
- *
2488
- * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
2489
- *
2490
- * @param tagName - Tag name.
2491
- * @param props - Props passed to the element.
2492
- * @returns - Whether the tag is custom component.
2493
- */
2494
- function isCustomComponent(tagName, props) {
2495
- if (!tagName.includes('-')) {
2496
- return Boolean(props && typeof props.is === 'string');
2497
- }
2498
- // These are reserved SVG and MathML elements.
2499
- // We don't mind this whitelist too much because we expect it to never grow.
2500
- // The alternative is to track the namespace in a few places which is convoluted.
2501
- // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
2502
- if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
2503
- return false;
2504
- }
2505
- return true;
2506
- }
2507
- const styleOptions = {
2508
- reactCompat: true,
2509
- };
2510
- /**
2511
- * Sets style prop.
2512
- *
2513
- * @param style - Inline style.
2514
- * @param props - Props object.
2515
- */
2516
- function setStyleProp(style, props) {
2517
- if (typeof style !== 'string') {
2518
- return;
2519
- }
2520
- if (!style.trim()) {
2521
- props.style = {};
2522
- return;
2523
- }
2524
- try {
2525
- props.style = (0, style_to_js_1.default)(style, styleOptions);
2526
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2527
- }
2528
- catch (error) {
2529
- props.style = {};
2530
- }
2531
- }
2532
- /**
2533
- * @see https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
2534
- */
2535
- exports.PRESERVE_CUSTOM_ATTRIBUTES = Number(react_1.version.split('.')[0]) >= 16;
2536
- /**
2537
- * @see https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
2538
- */
2539
- exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
2540
- 'tr',
2541
- 'tbody',
2542
- 'thead',
2543
- 'tfoot',
2544
- 'colgroup',
2545
- 'table',
2546
- 'head',
2547
- 'html',
2548
- 'frameset',
2549
- ]);
2550
- /**
2551
- * Checks if the given node can contain text nodes
2552
- *
2553
- * @param node - Element node.
2554
- * @returns - Whether the node can contain text nodes.
2555
- */
2556
- const canTextBeChildOfNode = (node) => !exports.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2557
- exports.canTextBeChildOfNode = canTextBeChildOfNode;
2558
- /**
2559
- * Returns the first argument as is.
2560
- *
2561
- * @param arg - The argument to be returned.
2562
- * @returns - The input argument `arg`.
2563
- */
2564
- const returnFirstArg = (arg) => arg;
2565
- exports.returnFirstArg = returnFirstArg;
2566
-
2567
- } (utilities));
2568
- return utilities;
2745
+ /**
2746
+ * Checks if `node` is an element node.
2747
+ * @param node Node to check.
2748
+ * @returns `true` if the node is an element node.
2749
+ */
2750
+ function isTag(node) {
2751
+ return isTag$1(node);
2752
+ }
2753
+ /**
2754
+ * Checks if `node` is a CDATA node.
2755
+ * @param node Node to check.
2756
+ * @returns `true` if the node is a CDATA node.
2757
+ */
2758
+ function isCDATA(node) {
2759
+ return node.type === ElementType.CDATA;
2760
+ }
2761
+ /**
2762
+ * Checks if `node` is a text node.
2763
+ * @param node Node to check.
2764
+ * @returns `true` if the node is a text node.
2765
+ */
2766
+ function isText(node) {
2767
+ return node.type === ElementType.Text;
2768
+ }
2769
+ /**
2770
+ * Checks if `node` is a comment node.
2771
+ * @param node Node to check.
2772
+ * @returns `true` if the node is a comment node.
2773
+ */
2774
+ function isComment(node) {
2775
+ return node.type === ElementType.Comment;
2776
+ }
2777
+ /**
2778
+ * Checks if `node` is a directive node.
2779
+ * @param node Node to check.
2780
+ * @returns `true` if the node is a directive node.
2781
+ */
2782
+ function isDirective(node) {
2783
+ return node.type === ElementType.Directive;
2784
+ }
2785
+ /**
2786
+ * Checks if `node` is a document node.
2787
+ * @param node Node to check.
2788
+ * @returns `true` if the node is a document node.
2789
+ */
2790
+ function isDocument(node) {
2791
+ return node.type === ElementType.Root;
2792
+ }
2793
+ /**
2794
+ * Checks if `node` has children.
2795
+ * @param node Node to check.
2796
+ * @returns `true` if the node has children.
2797
+ */
2798
+ function hasChildren(node) {
2799
+ return Object.hasOwn(node, "children");
2800
+ }
2801
+ /**
2802
+ * Clone a node, and optionally its children.
2803
+ * @param node Node to clone.
2804
+ * @param recursive Clone child nodes as well.
2805
+ * @returns A clone of the node.
2806
+ */
2807
+ function cloneNode(node, recursive = false) {
2808
+ let result;
2809
+ if (isText(node)) {
2810
+ result = new Text(node.data);
2811
+ }
2812
+ else if (isComment(node)) {
2813
+ result = new Comment(node.data);
2814
+ }
2815
+ else if (isTag(node)) {
2816
+ const children = recursive ? cloneChildren(node.children) : [];
2817
+ const clone = new Element(node.name, { ...node.attribs }, children);
2818
+ for (const child of children) {
2819
+ child.parent = clone;
2820
+ }
2821
+ if (node.namespace != null) {
2822
+ clone.namespace = node.namespace;
2823
+ }
2824
+ if (node["x-attribsNamespace"]) {
2825
+ clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
2826
+ }
2827
+ if (node["x-attribsPrefix"]) {
2828
+ clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
2829
+ }
2830
+ result = clone;
2831
+ }
2832
+ else if (isCDATA(node)) {
2833
+ const children = recursive ? cloneChildren(node.children) : [];
2834
+ const clone = new CDATA(children);
2835
+ for (const child of children) {
2836
+ child.parent = clone;
2837
+ }
2838
+ result = clone;
2839
+ }
2840
+ else if (isDocument(node)) {
2841
+ const children = recursive ? cloneChildren(node.children) : [];
2842
+ const clone = new Document(children);
2843
+ for (const child of children) {
2844
+ child.parent = clone;
2845
+ }
2846
+ if (node["x-mode"]) {
2847
+ clone["x-mode"] = node["x-mode"];
2848
+ }
2849
+ result = clone;
2850
+ }
2851
+ else if (isDirective(node)) {
2852
+ const instruction = new ProcessingInstruction(node.name, node.data);
2853
+ if (node["x-name"] != null) {
2854
+ instruction["x-name"] = node["x-name"];
2855
+ instruction["x-publicId"] = node["x-publicId"];
2856
+ instruction["x-systemId"] = node["x-systemId"];
2857
+ }
2858
+ result = instruction;
2859
+ }
2860
+ else {
2861
+ throw new Error(`Not implemented yet: ${node.type}`);
2862
+ }
2863
+ result.startIndex = node.startIndex;
2864
+ result.endIndex = node.endIndex;
2865
+ if (node.sourceCodeLocation != null) {
2866
+ result.sourceCodeLocation = node.sourceCodeLocation;
2867
+ }
2868
+ return result;
2869
+ }
2870
+ /**
2871
+ * Clone a list of child nodes.
2872
+ * @param childs The child nodes to clone.
2873
+ * @returns A list of cloned child nodes.
2874
+ */
2875
+ function cloneChildren(childs) {
2876
+ const children = childs.map((child) => cloneNode(child, true));
2877
+ for (let index = 1; index < children.length; index++) {
2878
+ children[index].prev = children[index - 1];
2879
+ children[index - 1].next = children[index];
2880
+ }
2881
+ return children;
2569
2882
  }
2570
2883
 
2571
- var hasRequiredAttributesToProps;
2572
-
2573
- function requireAttributesToProps () {
2574
- if (hasRequiredAttributesToProps) return attributesToProps;
2575
- hasRequiredAttributesToProps = 1;
2576
- Object.defineProperty(attributesToProps, "__esModule", { value: true });
2577
- attributesToProps.default = attributesToProps$1;
2578
- const react_property_1 = requireLib$1();
2579
- const utilities_1 = requireUtilities();
2580
- // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2581
- // https://developer.mozilla.org/docs/Web/HTML/Attributes
2582
- const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2583
- const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2584
- const valueOnlyInputs = {
2585
- reset: true,
2586
- submit: true,
2587
- };
2588
- /**
2589
- * Converts HTML/SVG DOM attributes to React props.
2590
- *
2591
- * @param attributes - HTML/SVG DOM attributes.
2592
- * @param nodeName - DOM node name.
2593
- * @returns - React props.
2594
- */
2595
- function attributesToProps$1(attributes = {}, nodeName) {
2596
- const props = {};
2597
- const isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2598
- for (const attributeName in attributes) {
2599
- const attributeValue = attributes[attributeName];
2600
- // ARIA (aria-*) or custom data (data-*) attribute
2601
- if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2602
- props[attributeName] = attributeValue;
2603
- continue;
2604
- }
2605
- // convert HTML/SVG attribute to React prop
2606
- const attributeNameLowerCased = attributeName.toLowerCase();
2607
- let propName = getPropName(attributeNameLowerCased);
2608
- if (propName) {
2609
- const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2610
- // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2611
- if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2612
- UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
2613
- !isInputValueOnly) {
2614
- propName = getPropName('default' + attributeNameLowerCased);
2615
- }
2616
- props[propName] = attributeValue;
2617
- switch (propertyInfo === null || propertyInfo === void 0 ? void 0 : propertyInfo.type) {
2618
- case react_property_1.BOOLEAN:
2619
- props[propName] = true;
2620
- break;
2621
- case react_property_1.OVERLOADED_BOOLEAN:
2622
- if (attributeValue === '') {
2623
- props[propName] = true;
2624
- }
2625
- break;
2626
- }
2627
- continue;
2628
- }
2629
- // preserve custom attribute if React >=16
2630
- if (utilities_1.PRESERVE_CUSTOM_ATTRIBUTES) {
2631
- props[attributeName] = attributeValue;
2632
- }
2633
- }
2634
- // transform inline style to object
2635
- (0, utilities_1.setStyleProp)(attributes.style, props);
2636
- return props;
2637
- }
2638
- /**
2639
- * Gets prop name from lowercased attribute name.
2640
- *
2641
- * @param attributeName - Lowercased attribute name.
2642
- * @returns - Prop name.
2643
- */
2644
- function getPropName(attributeName) {
2645
- return react_property_1.possibleStandardNames[attributeName];
2646
- }
2647
-
2648
- return attributesToProps;
2884
+ // Default options
2885
+ const defaultOptions = {
2886
+ withStartIndices: false,
2887
+ withEndIndices: false,
2888
+ xmlMode: false,
2889
+ };
2890
+ /**
2891
+ * Event-based handler that builds a DOM tree from parser callbacks.
2892
+ */
2893
+ class DomHandler {
2894
+ /** The elements of the DOM */
2895
+ dom = [];
2896
+ /** The root element for the DOM */
2897
+ root = new Document(this.dom);
2898
+ /** Called once parsing has completed. */
2899
+ callback;
2900
+ /** Settings for the handler. */
2901
+ options;
2902
+ /** Callback whenever a tag is closed. */
2903
+ elementCB;
2904
+ /** Indicated whether parsing has been completed. */
2905
+ done = false;
2906
+ /** Stack of open tags. */
2907
+ tagStack = [this.root];
2908
+ /** A data node that is still being written to. */
2909
+ lastNode = null;
2910
+ /** Reference to the parser instance. Used for location information. */
2911
+ parser = null;
2912
+ /**
2913
+ * @param callback Called once parsing has completed.
2914
+ * @param options Settings for the handler.
2915
+ * @param elementCB Callback whenever a tag is closed.
2916
+ */
2917
+ constructor(callback, options, elementCB) {
2918
+ // Make it possible to skip arguments, for backwards-compatibility
2919
+ if (typeof options === "function") {
2920
+ elementCB = options;
2921
+ options = defaultOptions;
2922
+ }
2923
+ if (typeof callback === "object") {
2924
+ options = callback;
2925
+ callback = undefined;
2926
+ }
2927
+ this.callback = callback ?? null;
2928
+ this.options = options ?? defaultOptions;
2929
+ this.elementCB = elementCB ?? null;
2930
+ }
2931
+ onparserinit(parser) {
2932
+ this.parser = parser;
2933
+ }
2934
+ // Resets the handler back to starting state
2935
+ onreset() {
2936
+ this.dom = [];
2937
+ this.root = new Document(this.dom);
2938
+ this.done = false;
2939
+ this.tagStack = [this.root];
2940
+ this.lastNode = null;
2941
+ this.parser = null;
2942
+ }
2943
+ // Signals the handler that parsing is done
2944
+ onend() {
2945
+ if (this.done)
2946
+ return;
2947
+ this.done = true;
2948
+ this.parser = null;
2949
+ this.handleCallback(null);
2950
+ }
2951
+ onerror(error) {
2952
+ this.handleCallback(error);
2953
+ }
2954
+ onclosetag() {
2955
+ this.lastNode = null;
2956
+ const element = this.tagStack.pop();
2957
+ if (this.options.withEndIndices && this.parser) {
2958
+ element.endIndex = this.parser.endIndex;
2959
+ }
2960
+ if (this.elementCB)
2961
+ this.elementCB(element);
2962
+ }
2963
+ onopentag(name, attribs) {
2964
+ const type = this.options.xmlMode ? ElementType.Tag : undefined;
2965
+ const element = new Element(name, attribs, undefined, type);
2966
+ this.addNode(element);
2967
+ this.tagStack.push(element);
2968
+ }
2969
+ ontext(data) {
2970
+ const { lastNode } = this;
2971
+ if (lastNode && lastNode.type === ElementType.Text) {
2972
+ lastNode.data += data;
2973
+ if (this.options.withEndIndices && this.parser) {
2974
+ lastNode.endIndex = this.parser.endIndex;
2975
+ }
2976
+ }
2977
+ else {
2978
+ const node = new Text(data);
2979
+ this.addNode(node);
2980
+ this.lastNode = node;
2981
+ }
2982
+ }
2983
+ oncomment(data) {
2984
+ if (this.lastNode && this.lastNode.type === ElementType.Comment) {
2985
+ this.lastNode.data += data;
2986
+ return;
2987
+ }
2988
+ const node = new Comment(data);
2989
+ this.addNode(node);
2990
+ this.lastNode = node;
2991
+ }
2992
+ oncommentend() {
2993
+ this.lastNode = null;
2994
+ }
2995
+ oncdatastart() {
2996
+ const text = new Text("");
2997
+ const node = new CDATA([text]);
2998
+ this.addNode(node);
2999
+ text.parent = node;
3000
+ this.lastNode = text;
3001
+ }
3002
+ oncdataend() {
3003
+ this.lastNode = null;
3004
+ }
3005
+ onprocessinginstruction(name, data) {
3006
+ const node = new ProcessingInstruction(name, data);
3007
+ this.addNode(node);
3008
+ }
3009
+ handleCallback(error) {
3010
+ if (typeof this.callback === "function") {
3011
+ this.callback(error, this.dom);
3012
+ }
3013
+ else if (error) {
3014
+ throw error;
3015
+ }
3016
+ }
3017
+ addNode(node) {
3018
+ const parent = this.tagStack[this.tagStack.length - 1];
3019
+ const previousSibling = parent.children[parent.children.length - 1];
3020
+ if (this.options.withStartIndices && this.parser) {
3021
+ node.startIndex = this.parser.startIndex;
3022
+ }
3023
+ if (this.options.withEndIndices && this.parser) {
3024
+ node.endIndex = this.parser.endIndex;
3025
+ }
3026
+ parent.children.push(node);
3027
+ if (previousSibling) {
3028
+ node.prev = previousSibling;
3029
+ previousSibling.next = node;
3030
+ }
3031
+ node.parent = parent;
3032
+ this.lastNode = null;
3033
+ }
2649
3034
  }
2650
3035
 
2651
- var domToReact = {};
3036
+ var dist = /*#__PURE__*/Object.freeze({
3037
+ __proto__: null,
3038
+ CDATA: CDATA,
3039
+ Comment: Comment,
3040
+ DataNode: DataNode,
3041
+ Document: Document,
3042
+ DomHandler: DomHandler,
3043
+ Element: Element,
3044
+ Node: Node,
3045
+ NodeWithChildren: NodeWithChildren,
3046
+ ProcessingInstruction: ProcessingInstruction,
3047
+ Text: Text,
3048
+ cloneNode: cloneNode,
3049
+ default: DomHandler,
3050
+ hasChildren: hasChildren,
3051
+ isCDATA: isCDATA,
3052
+ isComment: isComment,
3053
+ isDirective: isDirective,
3054
+ isDocument: isDocument,
3055
+ isTag: isTag,
3056
+ isText: isText
3057
+ });
3058
+
3059
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(dist);
2652
3060
 
2653
3061
  var hasRequiredDomToReact;
2654
3062
 
@@ -2770,11 +3178,19 @@
2770
3178
  }
2771
3179
  function normalizeDOMNodes(nodes) {
2772
3180
  for (const node of nodes) {
2773
- if (node.type === 'tag' ||
2774
- node.type === 'script' ||
2775
- node.type === 'style') {
2776
- Object.setPrototypeOf(node, domhandler_1.Element.prototype);
2777
- normalizeDOMNodes(node.children);
3181
+ switch (node.type) {
3182
+ case 'tag':
3183
+ case 'script':
3184
+ case 'style':
3185
+ Object.setPrototypeOf(node, domhandler_1.Element.prototype);
3186
+ normalizeDOMNodes(node.children);
3187
+ break;
3188
+ case 'text':
3189
+ Object.setPrototypeOf(node, domhandler_1.Text.prototype);
3190
+ break;
3191
+ case 'comment':
3192
+ Object.setPrototypeOf(node, domhandler_1.Comment.prototype);
3193
+ break;
2778
3194
  }
2779
3195
  }
2780
3196
  }