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