html-react-parser 6.1.5 → 6.1.7

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;
@@ -65,7 +473,13 @@
65
473
  function requireConstants () {
66
474
  if (hasRequiredConstants) return constants;
67
475
  hasRequiredConstants = 1;
68
- const CASE_SENSITIVE_TAG_NAMES_MAP = [
476
+ //#region src/client/constants.ts
477
+ /**
478
+ * SVG elements are case-sensitive.
479
+ *
480
+ * @see https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z
481
+ */
482
+ const CASE_SENSITIVE_TAG_NAMES = [
69
483
  "animateMotion",
70
484
  "animateTransform",
71
485
  "clipPath",
@@ -97,621 +511,26 @@
97
511
  "linearGradient",
98
512
  "radialGradient",
99
513
  "textPath"
100
- ].reduce((accumulator, tagName) => {
514
+ ];
515
+ const CASE_SENSITIVE_TAG_NAMES_MAP = CASE_SENSITIVE_TAG_NAMES.reduce((accumulator, tagName) => {
101
516
  accumulator[tagName.toLowerCase()] = tagName;
102
517
  return accumulator;
103
518
  }, {});
104
519
  //#endregion
520
+ constants.CASE_SENSITIVE_TAG_NAMES = CASE_SENSITIVE_TAG_NAMES;
105
521
  constants.CASE_SENSITIVE_TAG_NAMES_MAP = CASE_SENSITIVE_TAG_NAMES_MAP;
106
522
 
107
523
 
108
524
  return constants;
109
525
  }
110
526
 
111
- /** Types of elements found in htmlparser2's DOM */
112
- var ElementType;
113
- (function (ElementType) {
114
- /** Type for the root element of a document */
115
- ElementType["Root"] = "root";
116
- /** Type for Text */
117
- ElementType["Text"] = "text";
118
- /** Type for <? ... ?> */
119
- ElementType["Directive"] = "directive";
120
- /** Type for <!-- ... --> */
121
- ElementType["Comment"] = "comment";
122
- /** Type for <script> tags */
123
- ElementType["Script"] = "script";
124
- /** Type for <style> tags */
125
- ElementType["Style"] = "style";
126
- /** Type for Any tag */
127
- ElementType["Tag"] = "tag";
128
- /** Type for <![CDATA[ ... ]]> */
129
- ElementType["CDATA"] = "cdata";
130
- /** Type for <!doctype ...> */
131
- ElementType["Doctype"] = "doctype";
132
- })(ElementType || (ElementType = {}));
133
- /**
134
- * Tests whether an element is a tag or not.
135
- * @param element Element to test
136
- * @param element.type Node type discriminator to check.
137
- */
138
- function isTag$1(element) {
139
- return (element.type === ElementType.Tag ||
140
- element.type === ElementType.Script ||
141
- element.type === ElementType.Style);
142
- }
143
- // Exports for backwards compatibility
144
- /** Type for the root element of a document */
145
- // eslint-disable-next-line prefer-destructuring
146
- ElementType.Root;
147
- /** Type for Text */
148
- // eslint-disable-next-line prefer-destructuring
149
- ElementType.Text;
150
- /** Type for <? ... ?> */
151
- // eslint-disable-next-line prefer-destructuring
152
- ElementType.Directive;
153
- /** Type for <!-- ... --> */
154
- // eslint-disable-next-line prefer-destructuring
155
- ElementType.Comment;
156
- /** Type for <script> tags */
157
- // eslint-disable-next-line prefer-destructuring
158
- ElementType.Script;
159
- /** Type for <style> tags */
160
- // eslint-disable-next-line prefer-destructuring
161
- ElementType.Style;
162
- /** Type for Any tag */
163
- // eslint-disable-next-line prefer-destructuring
164
- ElementType.Tag;
165
- /** Type for <![CDATA[ ... ]]> */
166
- // eslint-disable-next-line prefer-destructuring
167
- ElementType.CDATA;
168
- /** Type for <!doctype ...> */
169
- // eslint-disable-next-line prefer-destructuring
170
- ElementType.Doctype;
171
-
172
- /**
173
- * This object will be used as the prototype for Nodes when creating a
174
- * DOM-Level-1-compliant structure.
175
- */
176
- class Node {
177
- /** Parent of the node */
178
- parent = null;
179
- /** Previous sibling */
180
- prev = null;
181
- /** Next sibling */
182
- next = null;
183
- /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
184
- startIndex = null;
185
- /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
186
- endIndex = null;
187
- // Read-write aliases for properties
188
- /**
189
- * Same as {@link parent}.
190
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
191
- */
192
- get parentNode() {
193
- return this.parent;
194
- }
195
- set parentNode(parent) {
196
- this.parent = parent;
197
- }
198
- /**
199
- * Same as {@link prev}.
200
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
201
- */
202
- get previousSibling() {
203
- return this.prev;
204
- }
205
- set previousSibling(previous) {
206
- this.prev = previous;
207
- }
208
- /**
209
- * Same as {@link next}.
210
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
211
- */
212
- get nextSibling() {
213
- return this.next;
214
- }
215
- set nextSibling(next) {
216
- this.next = next;
217
- }
218
- /**
219
- * Clone this node, and optionally its children.
220
- * @param recursive Clone child nodes as well.
221
- * @returns A clone of the node.
222
- */
223
- cloneNode(recursive = false) {
224
- return cloneNode(this, recursive);
225
- }
226
- }
227
- /**
228
- * A node that contains some data.
229
- */
230
- class DataNode extends Node {
231
- data;
232
- /**
233
- * @param data The content of the data node
234
- */
235
- constructor(data) {
236
- super();
237
- this.data = data;
238
- }
239
- /**
240
- * Same as {@link data}.
241
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
242
- */
243
- get nodeValue() {
244
- return this.data;
245
- }
246
- set nodeValue(data) {
247
- this.data = data;
248
- }
249
- }
250
- /**
251
- * Text within the document.
252
- */
253
- class Text extends DataNode {
254
- type = ElementType.Text;
255
- get nodeType() {
256
- return 3;
257
- }
258
- }
259
- /**
260
- * Comments within the document.
261
- */
262
- class Comment extends DataNode {
263
- type = ElementType.Comment;
264
- get nodeType() {
265
- return 8;
266
- }
267
- }
268
- /**
269
- * Processing instructions, including doc types.
270
- */
271
- class ProcessingInstruction extends DataNode {
272
- type = ElementType.Directive;
273
- name;
274
- constructor(name, data) {
275
- super(data);
276
- this.name = name;
277
- }
278
- get nodeType() {
279
- return 1;
280
- }
281
- /** If this is a doctype, the document type name (parse5 only). */
282
- "x-name";
283
- /** If this is a doctype, the document type public identifier (parse5 only). */
284
- "x-publicId";
285
- /** If this is a doctype, the document type system identifier (parse5 only). */
286
- "x-systemId";
287
- }
288
- /**
289
- * A node that can have children.
290
- */
291
- class NodeWithChildren extends Node {
292
- children;
293
- /**
294
- * @param children Children of the node. Only certain node types can have children.
295
- */
296
- constructor(children) {
297
- super();
298
- this.children = children;
299
- }
300
- // Aliases
301
- /** First child of the node. */
302
- get firstChild() {
303
- return this.children[0] ?? null;
304
- }
305
- /** Last child of the node. */
306
- get lastChild() {
307
- return this.children.length > 0
308
- ? this.children[this.children.length - 1]
309
- : null;
310
- }
311
- /**
312
- * Same as {@link children}.
313
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
314
- */
315
- get childNodes() {
316
- return this.children;
317
- }
318
- set childNodes(children) {
319
- this.children = children;
320
- }
321
- }
322
- /**
323
- * CDATA nodes.
324
- */
325
- class CDATA extends NodeWithChildren {
326
- type = ElementType.CDATA;
327
- get nodeType() {
328
- return 4;
329
- }
330
- }
331
- /**
332
- * The root node of the document.
333
- */
334
- class Document extends NodeWithChildren {
335
- type = ElementType.Root;
336
- get nodeType() {
337
- return 9;
338
- }
339
- }
340
- /**
341
- * An element within the DOM.
342
- */
343
- class Element extends NodeWithChildren {
344
- name;
345
- attribs;
346
- type;
347
- /**
348
- * @param name Name of the tag, eg. `div`, `span`.
349
- * @param attribs Object mapping attribute names to attribute values.
350
- * @param children Children of the node.
351
- * @param type Node type used for the new node instance.
352
- */
353
- constructor(name, attribs, children = [], type = name === "script"
354
- ? ElementType.Script
355
- : name === "style"
356
- ? ElementType.Style
357
- : ElementType.Tag) {
358
- super(children);
359
- this.name = name;
360
- this.attribs = attribs;
361
- this.type = type;
362
- }
363
- get nodeType() {
364
- return 1;
365
- }
366
- // DOM Level 1 aliases
367
- /**
368
- * Same as {@link name}.
369
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
370
- */
371
- get tagName() {
372
- return this.name;
373
- }
374
- set tagName(name) {
375
- this.name = name;
376
- }
377
- get attributes() {
378
- return Object.keys(this.attribs).map((name) => ({
379
- name,
380
- value: this.attribs[name],
381
- namespace: this["x-attribsNamespace"]?.[name],
382
- prefix: this["x-attribsPrefix"]?.[name],
383
- }));
384
- }
385
- /** Element namespace (parse5 only). */
386
- namespace;
387
- /** Element attribute namespaces (parse5 only). */
388
- "x-attribsNamespace";
389
- /** Element attribute namespace-related prefixes (parse5 only). */
390
- "x-attribsPrefix";
391
- }
392
- /**
393
- * Checks if `node` is an element node.
394
- * @param node Node to check.
395
- * @returns `true` if the node is an element node.
396
- */
397
- function isTag(node) {
398
- return isTag$1(node);
399
- }
400
- /**
401
- * Checks if `node` is a CDATA node.
402
- * @param node Node to check.
403
- * @returns `true` if the node is a CDATA node.
404
- */
405
- function isCDATA(node) {
406
- return node.type === ElementType.CDATA;
407
- }
408
- /**
409
- * Checks if `node` is a text node.
410
- * @param node Node to check.
411
- * @returns `true` if the node is a text node.
412
- */
413
- function isText(node) {
414
- return node.type === ElementType.Text;
415
- }
416
- /**
417
- * Checks if `node` is a comment node.
418
- * @param node Node to check.
419
- * @returns `true` if the node is a comment node.
420
- */
421
- function isComment(node) {
422
- return node.type === ElementType.Comment;
423
- }
424
- /**
425
- * Checks if `node` is a directive node.
426
- * @param node Node to check.
427
- * @returns `true` if the node is a directive node.
428
- */
429
- function isDirective(node) {
430
- return node.type === ElementType.Directive;
431
- }
432
- /**
433
- * Checks if `node` is a document node.
434
- * @param node Node to check.
435
- * @returns `true` if the node is a document node.
436
- */
437
- function isDocument(node) {
438
- return node.type === ElementType.Root;
439
- }
440
- /**
441
- * Checks if `node` has children.
442
- * @param node Node to check.
443
- * @returns `true` if the node has children.
444
- */
445
- function hasChildren(node) {
446
- return Object.hasOwn(node, "children");
447
- }
448
- /**
449
- * Clone a node, and optionally its children.
450
- * @param node Node to clone.
451
- * @param recursive Clone child nodes as well.
452
- * @returns A clone of the node.
453
- */
454
- function cloneNode(node, recursive = false) {
455
- let result;
456
- if (isText(node)) {
457
- result = new Text(node.data);
458
- }
459
- else if (isComment(node)) {
460
- result = new Comment(node.data);
461
- }
462
- else if (isTag(node)) {
463
- const children = recursive ? cloneChildren(node.children) : [];
464
- const clone = new Element(node.name, { ...node.attribs }, children);
465
- for (const child of children) {
466
- child.parent = clone;
467
- }
468
- if (node.namespace != null) {
469
- clone.namespace = node.namespace;
470
- }
471
- if (node["x-attribsNamespace"]) {
472
- clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
473
- }
474
- if (node["x-attribsPrefix"]) {
475
- clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
476
- }
477
- result = clone;
478
- }
479
- else if (isCDATA(node)) {
480
- const children = recursive ? cloneChildren(node.children) : [];
481
- const clone = new CDATA(children);
482
- for (const child of children) {
483
- child.parent = clone;
484
- }
485
- result = clone;
486
- }
487
- else if (isDocument(node)) {
488
- const children = recursive ? cloneChildren(node.children) : [];
489
- const clone = new Document(children);
490
- for (const child of children) {
491
- child.parent = clone;
492
- }
493
- if (node["x-mode"]) {
494
- clone["x-mode"] = node["x-mode"];
495
- }
496
- result = clone;
497
- }
498
- else if (isDirective(node)) {
499
- const instruction = new ProcessingInstruction(node.name, node.data);
500
- if (node["x-name"] != null) {
501
- instruction["x-name"] = node["x-name"];
502
- instruction["x-publicId"] = node["x-publicId"];
503
- instruction["x-systemId"] = node["x-systemId"];
504
- }
505
- result = instruction;
506
- }
507
- else {
508
- throw new Error(`Not implemented yet: ${node.type}`);
509
- }
510
- result.startIndex = node.startIndex;
511
- result.endIndex = node.endIndex;
512
- if (node.sourceCodeLocation != null) {
513
- result.sourceCodeLocation = node.sourceCodeLocation;
514
- }
515
- return result;
516
- }
517
- /**
518
- * Clone a list of child nodes.
519
- * @param childs The child nodes to clone.
520
- * @returns A list of cloned child nodes.
521
- */
522
- function cloneChildren(childs) {
523
- const children = childs.map((child) => cloneNode(child, true));
524
- for (let index = 1; index < children.length; index++) {
525
- children[index].prev = children[index - 1];
526
- children[index - 1].next = children[index];
527
- }
528
- return children;
529
- }
530
-
531
- // Default options
532
- const defaultOptions = {
533
- withStartIndices: false,
534
- withEndIndices: false,
535
- xmlMode: false,
536
- };
537
- /**
538
- * Event-based handler that builds a DOM tree from parser callbacks.
539
- */
540
- class DomHandler {
541
- /** The elements of the DOM */
542
- dom = [];
543
- /** The root element for the DOM */
544
- root = new Document(this.dom);
545
- /** Called once parsing has completed. */
546
- callback;
547
- /** Settings for the handler. */
548
- options;
549
- /** Callback whenever a tag is closed. */
550
- elementCB;
551
- /** Indicated whether parsing has been completed. */
552
- done = false;
553
- /** Stack of open tags. */
554
- tagStack = [this.root];
555
- /** A data node that is still being written to. */
556
- lastNode = null;
557
- /** Reference to the parser instance. Used for location information. */
558
- parser = null;
559
- /**
560
- * @param callback Called once parsing has completed.
561
- * @param options Settings for the handler.
562
- * @param elementCB Callback whenever a tag is closed.
563
- */
564
- constructor(callback, options, elementCB) {
565
- // Make it possible to skip arguments, for backwards-compatibility
566
- if (typeof options === "function") {
567
- elementCB = options;
568
- options = defaultOptions;
569
- }
570
- if (typeof callback === "object") {
571
- options = callback;
572
- callback = undefined;
573
- }
574
- this.callback = callback ?? null;
575
- this.options = options ?? defaultOptions;
576
- this.elementCB = elementCB ?? null;
577
- }
578
- onparserinit(parser) {
579
- this.parser = parser;
580
- }
581
- // Resets the handler back to starting state
582
- onreset() {
583
- this.dom = [];
584
- this.root = new Document(this.dom);
585
- this.done = false;
586
- this.tagStack = [this.root];
587
- this.lastNode = null;
588
- this.parser = null;
589
- }
590
- // Signals the handler that parsing is done
591
- onend() {
592
- if (this.done)
593
- return;
594
- this.done = true;
595
- this.parser = null;
596
- this.handleCallback(null);
597
- }
598
- onerror(error) {
599
- this.handleCallback(error);
600
- }
601
- onclosetag() {
602
- this.lastNode = null;
603
- const element = this.tagStack.pop();
604
- if (this.options.withEndIndices && this.parser) {
605
- element.endIndex = this.parser.endIndex;
606
- }
607
- if (this.elementCB)
608
- this.elementCB(element);
609
- }
610
- onopentag(name, attribs) {
611
- const type = this.options.xmlMode ? ElementType.Tag : undefined;
612
- const element = new Element(name, attribs, undefined, type);
613
- this.addNode(element);
614
- this.tagStack.push(element);
615
- }
616
- ontext(data) {
617
- const { lastNode } = this;
618
- if (lastNode && lastNode.type === ElementType.Text) {
619
- lastNode.data += data;
620
- if (this.options.withEndIndices && this.parser) {
621
- lastNode.endIndex = this.parser.endIndex;
622
- }
623
- }
624
- else {
625
- const node = new Text(data);
626
- this.addNode(node);
627
- this.lastNode = node;
628
- }
629
- }
630
- oncomment(data) {
631
- if (this.lastNode && this.lastNode.type === ElementType.Comment) {
632
- this.lastNode.data += data;
633
- return;
634
- }
635
- const node = new Comment(data);
636
- this.addNode(node);
637
- this.lastNode = node;
638
- }
639
- oncommentend() {
640
- this.lastNode = null;
641
- }
642
- oncdatastart() {
643
- const text = new Text("");
644
- const node = new CDATA([text]);
645
- this.addNode(node);
646
- text.parent = node;
647
- this.lastNode = text;
648
- }
649
- oncdataend() {
650
- this.lastNode = null;
651
- }
652
- onprocessinginstruction(name, data) {
653
- const node = new ProcessingInstruction(name, data);
654
- this.addNode(node);
655
- }
656
- handleCallback(error) {
657
- if (typeof this.callback === "function") {
658
- this.callback(error, this.dom);
659
- }
660
- else if (error) {
661
- throw error;
662
- }
663
- }
664
- addNode(node) {
665
- const parent = this.tagStack[this.tagStack.length - 1];
666
- const previousSibling = parent.children[parent.children.length - 1];
667
- if (this.options.withStartIndices && this.parser) {
668
- node.startIndex = this.parser.startIndex;
669
- }
670
- if (this.options.withEndIndices && this.parser) {
671
- node.endIndex = this.parser.endIndex;
672
- }
673
- parent.children.push(node);
674
- if (previousSibling) {
675
- node.prev = previousSibling;
676
- previousSibling.next = node;
677
- }
678
- node.parent = parent;
679
- this.lastNode = null;
680
- }
681
- }
682
-
683
- var dist$1 = /*#__PURE__*/Object.freeze({
684
- __proto__: null,
685
- CDATA: CDATA,
686
- Comment: Comment,
687
- DataNode: DataNode,
688
- Document: Document,
689
- DomHandler: DomHandler,
690
- Element: Element,
691
- Node: Node,
692
- NodeWithChildren: NodeWithChildren,
693
- ProcessingInstruction: ProcessingInstruction,
694
- Text: Text,
695
- cloneNode: cloneNode,
696
- default: DomHandler,
697
- hasChildren: hasChildren,
698
- isCDATA: isCDATA,
699
- isComment: isComment,
700
- isDirective: isDirective,
701
- isDocument: isDocument,
702
- isTag: isTag,
703
- isText: isText
704
- });
705
-
706
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(dist$1);
707
-
708
- var hasRequiredUtilities$1;
527
+ var hasRequiredUtilities$1;
709
528
 
710
529
  function requireUtilities$1 () {
711
530
  if (hasRequiredUtilities$1) return utilities$1;
712
531
  hasRequiredUtilities$1 = 1;
532
+ const require_node = requireNode();
713
533
  const require_constants = requireConstants();
714
- let domhandler = require$$3;
715
534
  //#region src/client/utilities.ts
716
535
  const CARRIAGE_RETURN = "\r";
717
536
  const CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, "g");
@@ -805,16 +624,16 @@
805
624
  switch (node.nodeType) {
806
625
  case 1: {
807
626
  const tagName = formatTagName(node.nodeName);
808
- current = new domhandler.Element(tagName, formatAttributes(node.attributes));
627
+ current = new require_node.Element(tagName, formatAttributes(node.attributes));
809
628
  current.children = formatDOM(tagName === "template" ? node.content.childNodes : node.childNodes, current);
810
629
  break;
811
630
  }
812
631
  /* v8 ignore start */
813
632
  case 3:
814
- current = new domhandler.Text(revertEscapedCharacters(node.nodeValue ?? ""));
633
+ current = new require_node.Text(revertEscapedCharacters(node.nodeValue ?? ""));
815
634
  break;
816
635
  case 8:
817
- current = new domhandler.Comment(node.nodeValue ?? "");
636
+ current = new require_node.Comment(node.nodeValue ?? "");
818
637
  break;
819
638
  /* v8 ignore stop */
820
639
  default: continue;
@@ -827,7 +646,7 @@
827
646
  domNodes.push(current);
828
647
  }
829
648
  if (directive) {
830
- current = new domhandler.ProcessingInstruction(directive.substring(0, directive.indexOf(" ")).toLowerCase(), directive);
649
+ current = new require_node.ProcessingInstruction(directive.substring(0, directive.indexOf(" ")).toLowerCase(), directive);
831
650
  current.next = domNodes[0] ?? null;
832
651
  current.parent = parent;
833
652
  domNodes.unshift(current);
@@ -839,6 +658,7 @@
839
658
  utilities$1.escapeSpecialCharacters = escapeSpecialCharacters;
840
659
  utilities$1.formatDOM = formatDOM;
841
660
  utilities$1.hasOpenTag = hasOpenTag;
661
+ utilities$1.revertEscapedCharacters = revertEscapedCharacters;
842
662
 
843
663
 
844
664
  return utilities$1;
@@ -971,6 +791,7 @@
971
791
  }
972
792
  //#endregion
973
793
  domparser.default = domparser$1;
794
+ domparser.getHTMLForInnerHTML = getHTMLForInnerHTML;
974
795
 
975
796
 
976
797
  return domparser;
@@ -2247,398 +2068,995 @@
2247
2068
  function declaration() {
2248
2069
  var pos = position();
2249
2070
 
2250
- // prop
2251
- var prop = match(PROPERTY_REGEX);
2252
- if (!prop) return;
2253
- comment();
2071
+ // prop
2072
+ var prop = match(PROPERTY_REGEX);
2073
+ if (!prop) return;
2074
+ comment();
2075
+
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;
2254
2127
 
2255
- // :
2256
- if (!match(COLON_REGEX)) return error("property missing ':'");
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;
2257
2188
 
2258
- // val
2259
- var val = match(VALUE_REGEX);
2189
+
2190
+ return cjs;
2191
+ }
2260
2192
 
2261
- var ret = pos({
2262
- type: TYPE_DECLARATION,
2263
- property: prop[0].replace(COMMENT_REGEX, EMPTY_STRING).trim(),
2264
- value: val
2265
- ? val[0].replace(COMMENT_REGEX, EMPTY_STRING).trim()
2266
- : EMPTY_STRING
2267
- });
2193
+ var dist$1;
2194
+ var hasRequiredDist;
2268
2195
 
2269
- // ;
2270
- 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;
2271
2266
 
2272
- return ret;
2273
- }
2267
+
2268
+ return dist$1;
2269
+ }
2274
2270
 
2275
- /**
2276
- * Parse declarations.
2277
- *
2278
- * @return {Object[]}
2279
- */
2280
- function declarations() {
2281
- 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
+ }
2282
2381
 
2283
- comments(decls);
2382
+ var hasRequiredAttributesToProps;
2284
2383
 
2285
- // declarations
2286
- var decl;
2287
- while ((decl = declaration())) {
2288
- decls.push(decl);
2289
- 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
+ }
2290
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
+ }
2291
2461
 
2292
- return decls;
2293
- }
2462
+ var domToReact = {};
2294
2463
 
2295
- whitespace();
2296
- return declarations();
2297
- }
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;
2298
2524
 
2299
- cjs$1 = index;
2300
-
2301
- 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
+ }
2302
2620
  }
2303
-
2304
- var cjs;
2305
- var hasRequiredCjs;
2306
-
2307
- function requireCjs () {
2308
- if (hasRequiredCjs) return cjs;
2309
- hasRequiredCjs = 1;
2310
- //#region \0rolldown/runtime.js
2311
- var __create = Object.create;
2312
- var __defProp = Object.defineProperty;
2313
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2314
- var __getOwnPropNames = Object.getOwnPropertyNames;
2315
- var __getProtoOf = Object.getPrototypeOf;
2316
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2317
- var __copyProps = (to, from, except, desc) => {
2318
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2319
- key = keys[i];
2320
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2321
- get: ((k) => from[k]).bind(null, key),
2322
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2323
- });
2324
- }
2325
- return to;
2326
- };
2327
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2328
- value: mod,
2329
- enumerable: true
2330
- }) : target, mod));
2331
- //#endregion
2332
- let inline_style_parser = requireCjs$1();
2333
- inline_style_parser = __toESM(inline_style_parser);
2334
- //#region src/index.ts
2335
- /**
2336
- * Parses inline style to object.
2337
- *
2338
- * @param style - Inline style.
2339
- * @param iterator - Iterator.
2340
- * @returns - Style object or null.
2341
- *
2342
- * @example Parsing inline style to object:
2343
- *
2344
- * ```js
2345
- * import parse from 'style-to-object';
2346
- * parse('line-height: 42;'); // { 'line-height': '42' }
2347
- * ```
2348
- */
2349
- function StyleToObject(style, iterator) {
2350
- let styleObject = null;
2351
- if (!style || typeof style !== "string") return styleObject;
2352
- const declarations = (0, inline_style_parser.default)(style);
2353
- const hasIterator = typeof iterator === "function";
2354
- declarations.forEach((declaration) => {
2355
- if (declaration.type !== "declaration") return;
2356
- const { property, value } = declaration;
2357
- if (hasIterator) iterator(property, value, declaration);
2358
- else if (value) {
2359
- styleObject = styleObject ?? {};
2360
- styleObject[property] = value;
2361
- }
2362
- });
2363
- return styleObject;
2364
- }
2365
- //#endregion
2366
- cjs = StyleToObject;
2367
-
2368
-
2369
- 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";
2370
2640
  }
2371
-
2372
- var dist;
2373
- var hasRequiredDist;
2374
-
2375
- function requireDist () {
2376
- if (hasRequiredDist) return dist;
2377
- hasRequiredDist = 1;
2378
- //#region \0rolldown/runtime.js
2379
- var __create = Object.create;
2380
- var __defProp = Object.defineProperty;
2381
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2382
- var __getOwnPropNames = Object.getOwnPropertyNames;
2383
- var __getProtoOf = Object.getPrototypeOf;
2384
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2385
- var __copyProps = (to, from, except, desc) => {
2386
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
2387
- key = keys[i];
2388
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
2389
- get: ((k) => from[k]).bind(null, key),
2390
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
2391
- });
2392
- }
2393
- return to;
2394
- };
2395
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(!mod || !mod.__esModule ? __defProp(target, "default", {
2396
- value: mod,
2397
- enumerable: true
2398
- }) : target, mod));
2399
- //#endregion
2400
- let style_to_object = requireCjs();
2401
- style_to_object = __toESM(style_to_object);
2402
- //#region src/utilities.ts
2403
- const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
2404
- const HYPHEN_REGEX = /-([a-z])/g;
2405
- const NO_HYPHEN_REGEX = /^[^-]+$/;
2406
- const VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
2407
- const MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
2408
- /**
2409
- * Checks whether to skip camelCase.
2410
- */
2411
- const skipCamelCase = (property) => !property || NO_HYPHEN_REGEX.test(property) || CUSTOM_PROPERTY_REGEX.test(property);
2412
- /**
2413
- * Replacer that capitalizes first character.
2414
- */
2415
- const capitalize = (match, character) => character.toUpperCase();
2416
- /**
2417
- * Replacer that removes beginning hyphen of vendor prefix property.
2418
- */
2419
- const trimHyphen = (match, prefix) => `${prefix}-`;
2420
- /**
2421
- * CamelCases a CSS property.
2422
- */
2423
- const camelCase = (property, options = {}) => {
2424
- if (skipCamelCase(property)) return property;
2425
- property = property.toLowerCase();
2426
- if (options.reactCompat) property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
2427
- else property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
2428
- return property.replace(HYPHEN_REGEX, capitalize);
2429
- };
2430
- //#endregion
2431
- //#region src/index.ts
2432
- /**
2433
- * Parses CSS inline style to JavaScript object (camelCased).
2434
- */
2435
- function StyleToJS(style, options) {
2436
- const output = {};
2437
- if (!style || typeof style !== "string") return output;
2438
- (0, style_to_object.default)(style, (property, value) => {
2439
- if (property && value) output[camelCase(property, options)] = value;
2440
- });
2441
- return output;
2442
- }
2443
- //#endregion
2444
- dist = StyleToJS;
2445
-
2446
-
2447
- 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";
2448
2744
  }
2449
-
2450
- var hasRequiredUtilities;
2451
-
2452
- function requireUtilities () {
2453
- if (hasRequiredUtilities) return utilities;
2454
- hasRequiredUtilities = 1;
2455
- (function (exports) {
2456
- var __importDefault = (utilities && utilities.__importDefault) || function (mod) {
2457
- return (mod && mod.__esModule) ? mod : { "default": mod };
2458
- };
2459
- Object.defineProperty(exports, "__esModule", { value: true });
2460
- exports.returnFirstArg = exports.canTextBeChildOfNode = exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports.PRESERVE_CUSTOM_ATTRIBUTES = void 0;
2461
- exports.isCustomComponent = isCustomComponent;
2462
- exports.setStyleProp = setStyleProp;
2463
- const react_1 = require$$0;
2464
- const style_to_js_1 = __importDefault(requireDist());
2465
- const RESERVED_SVG_MATHML_ELEMENTS = new Set([
2466
- 'annotation-xml',
2467
- 'color-profile',
2468
- 'font-face',
2469
- 'font-face-src',
2470
- 'font-face-uri',
2471
- 'font-face-format',
2472
- 'font-face-name',
2473
- 'missing-glyph',
2474
- ]);
2475
- /**
2476
- * Check if a tag is a custom component.
2477
- *
2478
- * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
2479
- *
2480
- * @param tagName - Tag name.
2481
- * @param props - Props passed to the element.
2482
- * @returns - Whether the tag is custom component.
2483
- */
2484
- function isCustomComponent(tagName, props) {
2485
- if (!tagName.includes('-')) {
2486
- return Boolean(props && typeof props.is === 'string');
2487
- }
2488
- // These are reserved SVG and MathML elements.
2489
- // We don't mind this whitelist too much because we expect it to never grow.
2490
- // The alternative is to track the namespace in a few places which is convoluted.
2491
- // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
2492
- if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
2493
- return false;
2494
- }
2495
- return true;
2496
- }
2497
- const styleOptions = {
2498
- reactCompat: true,
2499
- };
2500
- /**
2501
- * Sets style prop.
2502
- *
2503
- * @param style - Inline style.
2504
- * @param props - Props object.
2505
- */
2506
- function setStyleProp(style, props) {
2507
- if (typeof style !== 'string') {
2508
- return;
2509
- }
2510
- if (!style.trim()) {
2511
- props.style = {};
2512
- return;
2513
- }
2514
- try {
2515
- props.style = (0, style_to_js_1.default)(style, styleOptions);
2516
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2517
- }
2518
- catch (error) {
2519
- props.style = {};
2520
- }
2521
- }
2522
- /**
2523
- * @see https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
2524
- */
2525
- exports.PRESERVE_CUSTOM_ATTRIBUTES = Number(react_1.version.split('.')[0]) >= 16;
2526
- /**
2527
- * @see https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
2528
- */
2529
- exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
2530
- 'tr',
2531
- 'tbody',
2532
- 'thead',
2533
- 'tfoot',
2534
- 'colgroup',
2535
- 'table',
2536
- 'head',
2537
- 'html',
2538
- 'frameset',
2539
- ]);
2540
- /**
2541
- * Checks if the given node can contain text nodes
2542
- *
2543
- * @param node - Element node.
2544
- * @returns - Whether the node can contain text nodes.
2545
- */
2546
- const canTextBeChildOfNode = (node) => !exports.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
2547
- exports.canTextBeChildOfNode = canTextBeChildOfNode;
2548
- /**
2549
- * Returns the first argument as is.
2550
- *
2551
- * @param arg - The argument to be returned.
2552
- * @returns - The input argument `arg`.
2553
- */
2554
- const returnFirstArg = (arg) => arg;
2555
- exports.returnFirstArg = returnFirstArg;
2556
-
2557
- } (utilities));
2558
- 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;
2559
2882
  }
2560
2883
 
2561
- var hasRequiredAttributesToProps;
2562
-
2563
- function requireAttributesToProps () {
2564
- if (hasRequiredAttributesToProps) return attributesToProps;
2565
- hasRequiredAttributesToProps = 1;
2566
- Object.defineProperty(attributesToProps, "__esModule", { value: true });
2567
- attributesToProps.default = attributesToProps$1;
2568
- const react_property_1 = requireLib$1();
2569
- const utilities_1 = requireUtilities();
2570
- // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
2571
- // https://developer.mozilla.org/docs/Web/HTML/Attributes
2572
- const UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
2573
- const UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
2574
- const valueOnlyInputs = {
2575
- reset: true,
2576
- submit: true,
2577
- };
2578
- /**
2579
- * Converts HTML/SVG DOM attributes to React props.
2580
- *
2581
- * @param attributes - HTML/SVG DOM attributes.
2582
- * @param nodeName - DOM node name.
2583
- * @returns - React props.
2584
- */
2585
- function attributesToProps$1(attributes = {}, nodeName) {
2586
- const props = {};
2587
- const isInputValueOnly = Boolean(attributes.type && valueOnlyInputs[attributes.type]);
2588
- for (const attributeName in attributes) {
2589
- const attributeValue = attributes[attributeName];
2590
- // ARIA (aria-*) or custom data (data-*) attribute
2591
- if ((0, react_property_1.isCustomAttribute)(attributeName)) {
2592
- props[attributeName] = attributeValue;
2593
- continue;
2594
- }
2595
- // convert HTML/SVG attribute to React prop
2596
- const attributeNameLowerCased = attributeName.toLowerCase();
2597
- let propName = getPropName(attributeNameLowerCased);
2598
- if (propName) {
2599
- const propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
2600
- // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
2601
- if (UNCONTROLLED_COMPONENT_ATTRIBUTES.includes(propName) &&
2602
- UNCONTROLLED_COMPONENT_NAMES.includes(nodeName) &&
2603
- !isInputValueOnly) {
2604
- propName = getPropName('default' + attributeNameLowerCased);
2605
- }
2606
- props[propName] = attributeValue;
2607
- switch (propertyInfo === null || propertyInfo === void 0 ? void 0 : propertyInfo.type) {
2608
- case react_property_1.BOOLEAN:
2609
- props[propName] = true;
2610
- break;
2611
- case react_property_1.OVERLOADED_BOOLEAN:
2612
- if (attributeValue === '') {
2613
- props[propName] = true;
2614
- }
2615
- break;
2616
- }
2617
- continue;
2618
- }
2619
- // preserve custom attribute if React >=16
2620
- if (utilities_1.PRESERVE_CUSTOM_ATTRIBUTES) {
2621
- props[attributeName] = attributeValue;
2622
- }
2623
- }
2624
- // transform inline style to object
2625
- (0, utilities_1.setStyleProp)(attributes.style, props);
2626
- return props;
2627
- }
2628
- /**
2629
- * Gets prop name from lowercased attribute name.
2630
- *
2631
- * @param attributeName - Lowercased attribute name.
2632
- * @returns - Prop name.
2633
- */
2634
- function getPropName(attributeName) {
2635
- return react_property_1.possibleStandardNames[attributeName];
2636
- }
2637
-
2638
- 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
+ }
2639
3034
  }
2640
3035
 
2641
- 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);
2642
3060
 
2643
3061
  var hasRequiredDomToReact;
2644
3062