UNPKG

72.4 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
3 typeof define === 'function' && define.amd ? define(['react'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLReactParser = factory(global.React));
5})(this, (function (require$$0) { 'use strict';
6
7 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
9 var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
10
11 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
12
13 var htmlReactParser$1 = {exports: {}};
14
15 var lib$1 = {};
16
17 var possibleStandardNamesOptimized$1 = {};
18
19 // An attribute in which the DOM/SVG standard name is the same as the React prop name (e.g., 'accept').
20 var SAME$1 = 0;
21 possibleStandardNamesOptimized$1.SAME = SAME$1;
22
23 // An attribute in which the React prop name is the camelcased version of the DOM/SVG standard name (e.g., 'acceptCharset').
24 var CAMELCASE$1 = 1;
25 possibleStandardNamesOptimized$1.CAMELCASE = CAMELCASE$1;
26
27 possibleStandardNamesOptimized$1.possibleStandardNames = {
28 accept: 0,
29 acceptCharset: 1,
30 'accept-charset': 'acceptCharset',
31 accessKey: 1,
32 action: 0,
33 allowFullScreen: 1,
34 alt: 0,
35 as: 0,
36 async: 0,
37 autoCapitalize: 1,
38 autoComplete: 1,
39 autoCorrect: 1,
40 autoFocus: 1,
41 autoPlay: 1,
42 autoSave: 1,
43 capture: 0,
44 cellPadding: 1,
45 cellSpacing: 1,
46 challenge: 0,
47 charSet: 1,
48 checked: 0,
49 children: 0,
50 cite: 0,
51 class: 'className',
52 classID: 1,
53 className: 1,
54 cols: 0,
55 colSpan: 1,
56 content: 0,
57 contentEditable: 1,
58 contextMenu: 1,
59 controls: 0,
60 controlsList: 1,
61 coords: 0,
62 crossOrigin: 1,
63 dangerouslySetInnerHTML: 1,
64 data: 0,
65 dateTime: 1,
66 default: 0,
67 defaultChecked: 1,
68 defaultValue: 1,
69 defer: 0,
70 dir: 0,
71 disabled: 0,
72 disablePictureInPicture: 1,
73 disableRemotePlayback: 1,
74 download: 0,
75 draggable: 0,
76 encType: 1,
77 enterKeyHint: 1,
78 for: 'htmlFor',
79 form: 0,
80 formMethod: 1,
81 formAction: 1,
82 formEncType: 1,
83 formNoValidate: 1,
84 formTarget: 1,
85 frameBorder: 1,
86 headers: 0,
87 height: 0,
88 hidden: 0,
89 high: 0,
90 href: 0,
91 hrefLang: 1,
92 htmlFor: 1,
93 httpEquiv: 1,
94 'http-equiv': 'httpEquiv',
95 icon: 0,
96 id: 0,
97 innerHTML: 1,
98 inputMode: 1,
99 integrity: 0,
100 is: 0,
101 itemID: 1,
102 itemProp: 1,
103 itemRef: 1,
104 itemScope: 1,
105 itemType: 1,
106 keyParams: 1,
107 keyType: 1,
108 kind: 0,
109 label: 0,
110 lang: 0,
111 list: 0,
112 loop: 0,
113 low: 0,
114 manifest: 0,
115 marginWidth: 1,
116 marginHeight: 1,
117 max: 0,
118 maxLength: 1,
119 media: 0,
120 mediaGroup: 1,
121 method: 0,
122 min: 0,
123 minLength: 1,
124 multiple: 0,
125 muted: 0,
126 name: 0,
127 noModule: 1,
128 nonce: 0,
129 noValidate: 1,
130 open: 0,
131 optimum: 0,
132 pattern: 0,
133 placeholder: 0,
134 playsInline: 1,
135 poster: 0,
136 preload: 0,
137 profile: 0,
138 radioGroup: 1,
139 readOnly: 1,
140 referrerPolicy: 1,
141 rel: 0,
142 required: 0,
143 reversed: 0,
144 role: 0,
145 rows: 0,
146 rowSpan: 1,
147 sandbox: 0,
148 scope: 0,
149 scoped: 0,
150 scrolling: 0,
151 seamless: 0,
152 selected: 0,
153 shape: 0,
154 size: 0,
155 sizes: 0,
156 span: 0,
157 spellCheck: 1,
158 src: 0,
159 srcDoc: 1,
160 srcLang: 1,
161 srcSet: 1,
162 start: 0,
163 step: 0,
164 style: 0,
165 summary: 0,
166 tabIndex: 1,
167 target: 0,
168 title: 0,
169 type: 0,
170 useMap: 1,
171 value: 0,
172 width: 0,
173 wmode: 0,
174 wrap: 0,
175 about: 0,
176 accentHeight: 1,
177 'accent-height': 'accentHeight',
178 accumulate: 0,
179 additive: 0,
180 alignmentBaseline: 1,
181 'alignment-baseline': 'alignmentBaseline',
182 allowReorder: 1,
183 alphabetic: 0,
184 amplitude: 0,
185 arabicForm: 1,
186 'arabic-form': 'arabicForm',
187 ascent: 0,
188 attributeName: 1,
189 attributeType: 1,
190 autoReverse: 1,
191 azimuth: 0,
192 baseFrequency: 1,
193 baselineShift: 1,
194 'baseline-shift': 'baselineShift',
195 baseProfile: 1,
196 bbox: 0,
197 begin: 0,
198 bias: 0,
199 by: 0,
200 calcMode: 1,
201 capHeight: 1,
202 'cap-height': 'capHeight',
203 clip: 0,
204 clipPath: 1,
205 'clip-path': 'clipPath',
206 clipPathUnits: 1,
207 clipRule: 1,
208 'clip-rule': 'clipRule',
209 color: 0,
210 colorInterpolation: 1,
211 'color-interpolation': 'colorInterpolation',
212 colorInterpolationFilters: 1,
213 'color-interpolation-filters': 'colorInterpolationFilters',
214 colorProfile: 1,
215 'color-profile': 'colorProfile',
216 colorRendering: 1,
217 'color-rendering': 'colorRendering',
218 contentScriptType: 1,
219 contentStyleType: 1,
220 cursor: 0,
221 cx: 0,
222 cy: 0,
223 d: 0,
224 datatype: 0,
225 decelerate: 0,
226 descent: 0,
227 diffuseConstant: 1,
228 direction: 0,
229 display: 0,
230 divisor: 0,
231 dominantBaseline: 1,
232 'dominant-baseline': 'dominantBaseline',
233 dur: 0,
234 dx: 0,
235 dy: 0,
236 edgeMode: 1,
237 elevation: 0,
238 enableBackground: 1,
239 'enable-background': 'enableBackground',
240 end: 0,
241 exponent: 0,
242 externalResourcesRequired: 1,
243 fill: 0,
244 fillOpacity: 1,
245 'fill-opacity': 'fillOpacity',
246 fillRule: 1,
247 'fill-rule': 'fillRule',
248 filter: 0,
249 filterRes: 1,
250 filterUnits: 1,
251 floodOpacity: 1,
252 'flood-opacity': 'floodOpacity',
253 floodColor: 1,
254 'flood-color': 'floodColor',
255 focusable: 0,
256 fontFamily: 1,
257 'font-family': 'fontFamily',
258 fontSize: 1,
259 'font-size': 'fontSize',
260 fontSizeAdjust: 1,
261 'font-size-adjust': 'fontSizeAdjust',
262 fontStretch: 1,
263 'font-stretch': 'fontStretch',
264 fontStyle: 1,
265 'font-style': 'fontStyle',
266 fontVariant: 1,
267 'font-variant': 'fontVariant',
268 fontWeight: 1,
269 'font-weight': 'fontWeight',
270 format: 0,
271 from: 0,
272 fx: 0,
273 fy: 0,
274 g1: 0,
275 g2: 0,
276 glyphName: 1,
277 'glyph-name': 'glyphName',
278 glyphOrientationHorizontal: 1,
279 'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
280 glyphOrientationVertical: 1,
281 'glyph-orientation-vertical': 'glyphOrientationVertical',
282 glyphRef: 1,
283 gradientTransform: 1,
284 gradientUnits: 1,
285 hanging: 0,
286 horizAdvX: 1,
287 'horiz-adv-x': 'horizAdvX',
288 horizOriginX: 1,
289 'horiz-origin-x': 'horizOriginX',
290 ideographic: 0,
291 imageRendering: 1,
292 'image-rendering': 'imageRendering',
293 in2: 0,
294 in: 0,
295 inlist: 0,
296 intercept: 0,
297 k1: 0,
298 k2: 0,
299 k3: 0,
300 k4: 0,
301 k: 0,
302 kernelMatrix: 1,
303 kernelUnitLength: 1,
304 kerning: 0,
305 keyPoints: 1,
306 keySplines: 1,
307 keyTimes: 1,
308 lengthAdjust: 1,
309 letterSpacing: 1,
310 'letter-spacing': 'letterSpacing',
311 lightingColor: 1,
312 'lighting-color': 'lightingColor',
313 limitingConeAngle: 1,
314 local: 0,
315 markerEnd: 1,
316 'marker-end': 'markerEnd',
317 markerHeight: 1,
318 markerMid: 1,
319 'marker-mid': 'markerMid',
320 markerStart: 1,
321 'marker-start': 'markerStart',
322 markerUnits: 1,
323 markerWidth: 1,
324 mask: 0,
325 maskContentUnits: 1,
326 maskUnits: 1,
327 mathematical: 0,
328 mode: 0,
329 numOctaves: 1,
330 offset: 0,
331 opacity: 0,
332 operator: 0,
333 order: 0,
334 orient: 0,
335 orientation: 0,
336 origin: 0,
337 overflow: 0,
338 overlinePosition: 1,
339 'overline-position': 'overlinePosition',
340 overlineThickness: 1,
341 'overline-thickness': 'overlineThickness',
342 paintOrder: 1,
343 'paint-order': 'paintOrder',
344 panose1: 0,
345 'panose-1': 'panose1',
346 pathLength: 1,
347 patternContentUnits: 1,
348 patternTransform: 1,
349 patternUnits: 1,
350 pointerEvents: 1,
351 'pointer-events': 'pointerEvents',
352 points: 0,
353 pointsAtX: 1,
354 pointsAtY: 1,
355 pointsAtZ: 1,
356 prefix: 0,
357 preserveAlpha: 1,
358 preserveAspectRatio: 1,
359 primitiveUnits: 1,
360 property: 0,
361 r: 0,
362 radius: 0,
363 refX: 1,
364 refY: 1,
365 renderingIntent: 1,
366 'rendering-intent': 'renderingIntent',
367 repeatCount: 1,
368 repeatDur: 1,
369 requiredExtensions: 1,
370 requiredFeatures: 1,
371 resource: 0,
372 restart: 0,
373 result: 0,
374 results: 0,
375 rotate: 0,
376 rx: 0,
377 ry: 0,
378 scale: 0,
379 security: 0,
380 seed: 0,
381 shapeRendering: 1,
382 'shape-rendering': 'shapeRendering',
383 slope: 0,
384 spacing: 0,
385 specularConstant: 1,
386 specularExponent: 1,
387 speed: 0,
388 spreadMethod: 1,
389 startOffset: 1,
390 stdDeviation: 1,
391 stemh: 0,
392 stemv: 0,
393 stitchTiles: 1,
394 stopColor: 1,
395 'stop-color': 'stopColor',
396 stopOpacity: 1,
397 'stop-opacity': 'stopOpacity',
398 strikethroughPosition: 1,
399 'strikethrough-position': 'strikethroughPosition',
400 strikethroughThickness: 1,
401 'strikethrough-thickness': 'strikethroughThickness',
402 string: 0,
403 stroke: 0,
404 strokeDasharray: 1,
405 'stroke-dasharray': 'strokeDasharray',
406 strokeDashoffset: 1,
407 'stroke-dashoffset': 'strokeDashoffset',
408 strokeLinecap: 1,
409 'stroke-linecap': 'strokeLinecap',
410 strokeLinejoin: 1,
411 'stroke-linejoin': 'strokeLinejoin',
412 strokeMiterlimit: 1,
413 'stroke-miterlimit': 'strokeMiterlimit',
414 strokeWidth: 1,
415 'stroke-width': 'strokeWidth',
416 strokeOpacity: 1,
417 'stroke-opacity': 'strokeOpacity',
418 suppressContentEditableWarning: 1,
419 suppressHydrationWarning: 1,
420 surfaceScale: 1,
421 systemLanguage: 1,
422 tableValues: 1,
423 targetX: 1,
424 targetY: 1,
425 textAnchor: 1,
426 'text-anchor': 'textAnchor',
427 textDecoration: 1,
428 'text-decoration': 'textDecoration',
429 textLength: 1,
430 textRendering: 1,
431 'text-rendering': 'textRendering',
432 to: 0,
433 transform: 0,
434 typeof: 0,
435 u1: 0,
436 u2: 0,
437 underlinePosition: 1,
438 'underline-position': 'underlinePosition',
439 underlineThickness: 1,
440 'underline-thickness': 'underlineThickness',
441 unicode: 0,
442 unicodeBidi: 1,
443 'unicode-bidi': 'unicodeBidi',
444 unicodeRange: 1,
445 'unicode-range': 'unicodeRange',
446 unitsPerEm: 1,
447 'units-per-em': 'unitsPerEm',
448 unselectable: 0,
449 vAlphabetic: 1,
450 'v-alphabetic': 'vAlphabetic',
451 values: 0,
452 vectorEffect: 1,
453 'vector-effect': 'vectorEffect',
454 version: 0,
455 vertAdvY: 1,
456 'vert-adv-y': 'vertAdvY',
457 vertOriginX: 1,
458 'vert-origin-x': 'vertOriginX',
459 vertOriginY: 1,
460 'vert-origin-y': 'vertOriginY',
461 vHanging: 1,
462 'v-hanging': 'vHanging',
463 vIdeographic: 1,
464 'v-ideographic': 'vIdeographic',
465 viewBox: 1,
466 viewTarget: 1,
467 visibility: 0,
468 vMathematical: 1,
469 'v-mathematical': 'vMathematical',
470 vocab: 0,
471 widths: 0,
472 wordSpacing: 1,
473 'word-spacing': 'wordSpacing',
474 writingMode: 1,
475 'writing-mode': 'writingMode',
476 x1: 0,
477 x2: 0,
478 x: 0,
479 xChannelSelector: 1,
480 xHeight: 1,
481 'x-height': 'xHeight',
482 xlinkActuate: 1,
483 'xlink:actuate': 'xlinkActuate',
484 xlinkArcrole: 1,
485 'xlink:arcrole': 'xlinkArcrole',
486 xlinkHref: 1,
487 'xlink:href': 'xlinkHref',
488 xlinkRole: 1,
489 'xlink:role': 'xlinkRole',
490 xlinkShow: 1,
491 'xlink:show': 'xlinkShow',
492 xlinkTitle: 1,
493 'xlink:title': 'xlinkTitle',
494 xlinkType: 1,
495 'xlink:type': 'xlinkType',
496 xmlBase: 1,
497 'xml:base': 'xmlBase',
498 xmlLang: 1,
499 'xml:lang': 'xmlLang',
500 xmlns: 0,
501 'xml:space': 'xmlSpace',
502 xmlnsXlink: 1,
503 'xmlns:xlink': 'xmlnsXlink',
504 xmlSpace: 1,
505 y1: 0,
506 y2: 0,
507 y: 0,
508 yChannelSelector: 1,
509 z: 0,
510 zoomAndPan: 1
511 };
512
513 Object.defineProperty(lib$1, '__esModule', { value: true });
514
515 function _slicedToArray(arr, i) {
516 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
517 }
518
519 function _arrayWithHoles(arr) {
520 if (Array.isArray(arr)) return arr;
521 }
522
523 function _iterableToArrayLimit(arr, i) {
524 var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
525
526 if (_i == null) return;
527 var _arr = [];
528 var _n = true;
529 var _d = false;
530
531 var _s, _e;
532
533 try {
534 for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
535 _arr.push(_s.value);
536
537 if (i && _arr.length === i) break;
538 }
539 } catch (err) {
540 _d = true;
541 _e = err;
542 } finally {
543 try {
544 if (!_n && _i["return"] != null) _i["return"]();
545 } finally {
546 if (_d) throw _e;
547 }
548 }
549
550 return _arr;
551 }
552
553 function _unsupportedIterableToArray(o, minLen) {
554 if (!o) return;
555 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
556 var n = Object.prototype.toString.call(o).slice(8, -1);
557 if (n === "Object" && o.constructor) n = o.constructor.name;
558 if (n === "Map" || n === "Set") return Array.from(o);
559 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
560 }
561
562 function _arrayLikeToArray(arr, len) {
563 if (len == null || len > arr.length) len = arr.length;
564
565 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
566
567 return arr2;
568 }
569
570 function _nonIterableRest() {
571 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
572 }
573
574 // A reserved attribute.
575 // It is handled by React separately and shouldn't be written to the DOM.
576 var RESERVED = 0; // A simple string attribute.
577 // Attributes that aren't in the filter are presumed to have this type.
578
579 var STRING = 1; // A string attribute that accepts booleans in React. In HTML, these are called
580 // "enumerated" attributes with "true" and "false" as possible values.
581 // When true, it should be set to a "true" string.
582 // When false, it should be set to a "false" string.
583
584 var BOOLEANISH_STRING = 2; // A real boolean attribute.
585 // When true, it should be present (set either to an empty string or its name).
586 // When false, it should be omitted.
587
588 var BOOLEAN = 3; // An attribute that can be used as a flag as well as with a value.
589 // When true, it should be present (set either to an empty string or its name).
590 // When false, it should be omitted.
591 // For any other value, should be present with that value.
592
593 var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a numeric.
594 // When falsy, it should be removed.
595
596 var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
597 // When falsy, it should be removed.
598
599 var POSITIVE_NUMERIC = 6;
600 function getPropertyInfo(name) {
601 return properties.hasOwnProperty(name) ? properties[name] : null;
602 }
603
604 function PropertyInfoRecord(name, type, mustUseProperty, attributeName, attributeNamespace, sanitizeURL, removeEmptyString) {
605 this.acceptsBooleans = type === BOOLEANISH_STRING || type === BOOLEAN || type === OVERLOADED_BOOLEAN;
606 this.attributeName = attributeName;
607 this.attributeNamespace = attributeNamespace;
608 this.mustUseProperty = mustUseProperty;
609 this.propertyName = name;
610 this.type = type;
611 this.sanitizeURL = sanitizeURL;
612 this.removeEmptyString = removeEmptyString;
613 } // When adding attributes to this list, be sure to also add them to
614 // the `possibleStandardNames` module to ensure casing and incorrect
615 // name warnings.
616
617
618 var properties = {}; // These props are reserved by React. They shouldn't be written to the DOM.
619
620 var reservedProps = ['children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular
621 // elements (not just inputs). Now that ReactDOMInput assigns to the
622 // defaultValue property -- do we need this?
623 'defaultValue', 'defaultChecked', 'innerHTML', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style'];
624 reservedProps.forEach(function (name) {
625 properties[name] = new PropertyInfoRecord(name, RESERVED, false, // mustUseProperty
626 name, // attributeName
627 null, // attributeNamespace
628 false, // sanitizeURL
629 false);
630 }); // A few React string attributes have a different name.
631 // This is a mapping from React prop names to the attribute names.
632
633 [['acceptCharset', 'accept-charset'], ['className', 'class'], ['htmlFor', 'for'], ['httpEquiv', 'http-equiv']].forEach(function (_ref) {
634 var _ref2 = _slicedToArray(_ref, 2),
635 name = _ref2[0],
636 attributeName = _ref2[1];
637
638 properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
639 attributeName, // attributeName
640 null, // attributeNamespace
641 false, // sanitizeURL
642 false);
643 }); // These are "enumerated" HTML attributes that accept "true" and "false".
644 // In React, we let users pass `true` and `false` even though technically
645 // these aren't boolean attributes (they are coerced to strings).
646
647 ['contentEditable', 'draggable', 'spellCheck', 'value'].forEach(function (name) {
648 properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
649 name.toLowerCase(), // attributeName
650 null, // attributeNamespace
651 false, // sanitizeURL
652 false);
653 }); // These are "enumerated" SVG attributes that accept "true" and "false".
654 // In React, we let users pass `true` and `false` even though technically
655 // these aren't boolean attributes (they are coerced to strings).
656 // Since these are SVG attributes, their attribute names are case-sensitive.
657
658 ['autoReverse', 'externalResourcesRequired', 'focusable', 'preserveAlpha'].forEach(function (name) {
659 properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
660 name, // attributeName
661 null, // attributeNamespace
662 false, // sanitizeURL
663 false);
664 }); // These are HTML boolean attributes.
665
666 ['allowFullScreen', 'async', // Note: there is a special case that prevents it from being written to the DOM
667 // on the client side because the browsers are inconsistent. Instead we call focus().
668 'autoFocus', 'autoPlay', 'controls', 'default', 'defer', 'disabled', 'disablePictureInPicture', 'disableRemotePlayback', 'formNoValidate', 'hidden', 'loop', 'noModule', 'noValidate', 'open', 'playsInline', 'readOnly', 'required', 'reversed', 'scoped', 'seamless', // Microdata
669 'itemScope'].forEach(function (name) {
670 properties[name] = new PropertyInfoRecord(name, BOOLEAN, false, // mustUseProperty
671 name.toLowerCase(), // attributeName
672 null, // attributeNamespace
673 false, // sanitizeURL
674 false);
675 }); // These are the few React props that we set as DOM properties
676 // rather than attributes. These are all booleans.
677
678 ['checked', // Note: `option.selected` is not updated if `select.multiple` is
679 // disabled with `removeAttribute`. We have special logic for handling this.
680 'multiple', 'muted', 'selected' // NOTE: if you add a camelCased prop to this list,
681 // you'll need to set attributeName to name.toLowerCase()
682 // instead in the assignment below.
683 ].forEach(function (name) {
684 properties[name] = new PropertyInfoRecord(name, BOOLEAN, true, // mustUseProperty
685 name, // attributeName
686 null, // attributeNamespace
687 false, // sanitizeURL
688 false);
689 }); // These are HTML attributes that are "overloaded booleans": they behave like
690 // booleans, but can also accept a string value.
691
692 ['capture', 'download' // NOTE: if you add a camelCased prop to this list,
693 // you'll need to set attributeName to name.toLowerCase()
694 // instead in the assignment below.
695 ].forEach(function (name) {
696 properties[name] = new PropertyInfoRecord(name, OVERLOADED_BOOLEAN, false, // mustUseProperty
697 name, // attributeName
698 null, // attributeNamespace
699 false, // sanitizeURL
700 false);
701 }); // These are HTML attributes that must be positive numbers.
702
703 ['cols', 'rows', 'size', 'span' // NOTE: if you add a camelCased prop to this list,
704 // you'll need to set attributeName to name.toLowerCase()
705 // instead in the assignment below.
706 ].forEach(function (name) {
707 properties[name] = new PropertyInfoRecord(name, POSITIVE_NUMERIC, false, // mustUseProperty
708 name, // attributeName
709 null, // attributeNamespace
710 false, // sanitizeURL
711 false);
712 }); // These are HTML attributes that must be numbers.
713
714 ['rowSpan', 'start'].forEach(function (name) {
715 properties[name] = new PropertyInfoRecord(name, NUMERIC, false, // mustUseProperty
716 name.toLowerCase(), // attributeName
717 null, // attributeNamespace
718 false, // sanitizeURL
719 false);
720 });
721 var CAMELIZE = /[\-\:]([a-z])/g;
722
723 var capitalize$1 = function capitalize(token) {
724 return token[1].toUpperCase();
725 }; // This is a list of all SVG attributes that need special casing, namespacing,
726 // or boolean value assignment. Regular attributes that just accept strings
727 // and have the same names are omitted, just like in the HTML attribute filter.
728 // Some of these attributes can be hard to find. This list was created by
729 // scraping the MDN documentation.
730
731
732 ['accent-height', 'alignment-baseline', 'arabic-form', 'baseline-shift', 'cap-height', 'clip-path', 'clip-rule', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'dominant-baseline', 'enable-background', 'fill-opacity', 'fill-rule', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-name', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'horiz-adv-x', 'horiz-origin-x', 'image-rendering', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'overline-position', 'overline-thickness', 'paint-order', 'panose-1', 'pointer-events', 'rendering-intent', 'shape-rendering', 'stop-color', 'stop-opacity', 'strikethrough-position', 'strikethrough-thickness', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'underline-position', 'underline-thickness', 'unicode-bidi', 'unicode-range', 'units-per-em', 'v-alphabetic', 'v-hanging', 'v-ideographic', 'v-mathematical', 'vector-effect', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'word-spacing', 'writing-mode', 'xmlns:xlink', 'x-height' // NOTE: if you add a camelCased prop to this list,
733 // you'll need to set attributeName to name.toLowerCase()
734 // instead in the assignment below.
735 ].forEach(function (attributeName) {
736 var name = attributeName.replace(CAMELIZE, capitalize$1);
737 properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
738 attributeName, null, // attributeNamespace
739 false, // sanitizeURL
740 false);
741 }); // String SVG attributes with the xlink namespace.
742
743 ['xlink:actuate', 'xlink:arcrole', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type' // NOTE: if you add a camelCased prop to this list,
744 // you'll need to set attributeName to name.toLowerCase()
745 // instead in the assignment below.
746 ].forEach(function (attributeName) {
747 var name = attributeName.replace(CAMELIZE, capitalize$1);
748 properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
749 attributeName, 'http://www.w3.org/1999/xlink', false, // sanitizeURL
750 false);
751 }); // String SVG attributes with the xml namespace.
752
753 ['xml:base', 'xml:lang', 'xml:space' // NOTE: if you add a camelCased prop to this list,
754 // you'll need to set attributeName to name.toLowerCase()
755 // instead in the assignment below.
756 ].forEach(function (attributeName) {
757 var name = attributeName.replace(CAMELIZE, capitalize$1);
758 properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
759 attributeName, 'http://www.w3.org/XML/1998/namespace', false, // sanitizeURL
760 false);
761 }); // These attribute exists both in HTML and SVG.
762 // The attribute name is case-sensitive in SVG so we can't just use
763 // the React name like we do for attributes that exist only in HTML.
764
765 ['tabIndex', 'crossOrigin'].forEach(function (attributeName) {
766 properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
767 attributeName.toLowerCase(), // attributeName
768 null, // attributeNamespace
769 false, // sanitizeURL
770 false);
771 }); // These attributes accept URLs. These must not allow javascript: URLS.
772 // These will also need to accept Trusted Types object in the future.
773
774 var xlinkHref = 'xlinkHref';
775 properties[xlinkHref] = new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
776 'xlink:href', 'http://www.w3.org/1999/xlink', true, // sanitizeURL
777 false);
778 ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
779 properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
780 attributeName.toLowerCase(), // attributeName
781 null, // attributeNamespace
782 true, // sanitizeURL
783 true);
784 });
785
786 var _require = possibleStandardNamesOptimized$1,
787 CAMELCASE = _require.CAMELCASE,
788 SAME = _require.SAME,
789 possibleStandardNamesOptimized = _require.possibleStandardNames;
790
791 var ATTRIBUTE_NAME_START_CHAR = ":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
792 var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + "\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
793 /**
794 * Checks whether a property name is a custom attribute.
795 *
796 * @see {@link https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L23-L25}
797 *
798 * @param {string}
799 * @return {boolean}
800 */
801
802 var isCustomAttribute = RegExp.prototype.test.bind( // eslint-disable-next-line no-misleading-character-class
803 new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$'));
804 var possibleStandardNames = Object.keys(possibleStandardNamesOptimized).reduce(function (accumulator, standardName) {
805 var propName = possibleStandardNamesOptimized[standardName];
806
807 if (propName === SAME) {
808 accumulator[standardName] = standardName;
809 } else if (propName === CAMELCASE) {
810 accumulator[standardName.toLowerCase()] = standardName;
811 } else {
812 accumulator[standardName] = propName;
813 }
814
815 return accumulator;
816 }, {});
817
818 lib$1.BOOLEAN = BOOLEAN;
819 lib$1.BOOLEANISH_STRING = BOOLEANISH_STRING;
820 lib$1.NUMERIC = NUMERIC;
821 lib$1.OVERLOADED_BOOLEAN = OVERLOADED_BOOLEAN;
822 lib$1.POSITIVE_NUMERIC = POSITIVE_NUMERIC;
823 lib$1.RESERVED = RESERVED;
824 lib$1.STRING = STRING;
825 lib$1.getPropertyInfo = getPropertyInfo;
826 lib$1.isCustomAttribute = isCustomAttribute;
827 lib$1.possibleStandardNames = possibleStandardNames;
828
829 var cjs = {};
830
831 // http://www.w3.org/TR/CSS21/grammar.html
832 // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
833 var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
834
835 var NEWLINE_REGEX = /\n/g;
836 var WHITESPACE_REGEX = /^\s*/;
837
838 // declaration
839 var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
840 var COLON_REGEX = /^:\s*/;
841 var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
842 var SEMICOLON_REGEX = /^[;\s]*/;
843
844 // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
845 var TRIM_REGEX = /^\s+|\s+$/g;
846
847 // strings
848 var NEWLINE = '\n';
849 var FORWARD_SLASH = '/';
850 var ASTERISK = '*';
851 var EMPTY_STRING = '';
852
853 // types
854 var TYPE_COMMENT = 'comment';
855 var TYPE_DECLARATION = 'declaration';
856
857 /**
858 * @param {String} style
859 * @param {Object} [options]
860 * @return {Object[]}
861 * @throws {TypeError}
862 * @throws {Error}
863 */
864 var inlineStyleParser = function(style, options) {
865 if (typeof style !== 'string') {
866 throw new TypeError('First argument must be a string');
867 }
868
869 if (!style) return [];
870
871 options = options || {};
872
873 /**
874 * Positional.
875 */
876 var lineno = 1;
877 var column = 1;
878
879 /**
880 * Update lineno and column based on `str`.
881 *
882 * @param {String} str
883 */
884 function updatePosition(str) {
885 var lines = str.match(NEWLINE_REGEX);
886 if (lines) lineno += lines.length;
887 var i = str.lastIndexOf(NEWLINE);
888 column = ~i ? str.length - i : column + str.length;
889 }
890
891 /**
892 * Mark position and patch `node.position`.
893 *
894 * @return {Function}
895 */
896 function position() {
897 var start = { line: lineno, column: column };
898 return function(node) {
899 node.position = new Position(start);
900 whitespace();
901 return node;
902 };
903 }
904
905 /**
906 * Store position information for a node.
907 *
908 * @constructor
909 * @property {Object} start
910 * @property {Object} end
911 * @property {undefined|String} source
912 */
913 function Position(start) {
914 this.start = start;
915 this.end = { line: lineno, column: column };
916 this.source = options.source;
917 }
918
919 /**
920 * Non-enumerable source string.
921 */
922 Position.prototype.content = style;
923
924 /**
925 * Error `msg`.
926 *
927 * @param {String} msg
928 * @throws {Error}
929 */
930 function error(msg) {
931 var err = new Error(
932 options.source + ':' + lineno + ':' + column + ': ' + msg
933 );
934 err.reason = msg;
935 err.filename = options.source;
936 err.line = lineno;
937 err.column = column;
938 err.source = style;
939
940 if (options.silent) ; else {
941 throw err;
942 }
943 }
944
945 /**
946 * Match `re` and return captures.
947 *
948 * @param {RegExp} re
949 * @return {undefined|Array}
950 */
951 function match(re) {
952 var m = re.exec(style);
953 if (!m) return;
954 var str = m[0];
955 updatePosition(str);
956 style = style.slice(str.length);
957 return m;
958 }
959
960 /**
961 * Parse whitespace.
962 */
963 function whitespace() {
964 match(WHITESPACE_REGEX);
965 }
966
967 /**
968 * Parse comments.
969 *
970 * @param {Object[]} [rules]
971 * @return {Object[]}
972 */
973 function comments(rules) {
974 var c;
975 rules = rules || [];
976 while ((c = comment())) {
977 if (c !== false) {
978 rules.push(c);
979 }
980 }
981 return rules;
982 }
983
984 /**
985 * Parse comment.
986 *
987 * @return {Object}
988 * @throws {Error}
989 */
990 function comment() {
991 var pos = position();
992 if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
993
994 var i = 2;
995 while (
996 EMPTY_STRING != style.charAt(i) &&
997 (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
998 ) {
999 ++i;
1000 }
1001 i += 2;
1002
1003 if (EMPTY_STRING === style.charAt(i - 1)) {
1004 return error('End of comment missing');
1005 }
1006
1007 var str = style.slice(2, i - 2);
1008 column += 2;
1009 updatePosition(str);
1010 style = style.slice(i);
1011 column += 2;
1012
1013 return pos({
1014 type: TYPE_COMMENT,
1015 comment: str
1016 });
1017 }
1018
1019 /**
1020 * Parse declaration.
1021 *
1022 * @return {Object}
1023 * @throws {Error}
1024 */
1025 function declaration() {
1026 var pos = position();
1027
1028 // prop
1029 var prop = match(PROPERTY_REGEX);
1030 if (!prop) return;
1031 comment();
1032
1033 // :
1034 if (!match(COLON_REGEX)) return error("property missing ':'");
1035
1036 // val
1037 var val = match(VALUE_REGEX);
1038
1039 var ret = pos({
1040 type: TYPE_DECLARATION,
1041 property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
1042 value: val
1043 ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
1044 : EMPTY_STRING
1045 });
1046
1047 // ;
1048 match(SEMICOLON_REGEX);
1049
1050 return ret;
1051 }
1052
1053 /**
1054 * Parse declarations.
1055 *
1056 * @return {Object[]}
1057 */
1058 function declarations() {
1059 var decls = [];
1060
1061 comments(decls);
1062
1063 // declarations
1064 var decl;
1065 while ((decl = declaration())) {
1066 if (decl !== false) {
1067 decls.push(decl);
1068 comments(decls);
1069 }
1070 }
1071
1072 return decls;
1073 }
1074
1075 whitespace();
1076 return declarations();
1077 };
1078
1079 /**
1080 * Trim `str`.
1081 *
1082 * @param {String} str
1083 * @return {String}
1084 */
1085 function trim(str) {
1086 return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
1087 }
1088
1089 var parse = inlineStyleParser;
1090
1091 /**
1092 * Parses inline style to object.
1093 *
1094 * @example
1095 * // returns { 'line-height': '42' }
1096 * StyleToObject('line-height: 42;');
1097 *
1098 * @param {String} style - The inline style.
1099 * @param {Function} [iterator] - The iterator function.
1100 * @return {null|Object}
1101 */
1102 function StyleToObject(style, iterator) {
1103 var output = null;
1104 if (!style || typeof style !== 'string') {
1105 return output;
1106 }
1107
1108 var declaration;
1109 var declarations = parse(style);
1110 var hasIterator = typeof iterator === 'function';
1111 var property;
1112 var value;
1113
1114 for (var i = 0, len = declarations.length; i < len; i++) {
1115 declaration = declarations[i];
1116 property = declaration.property;
1117 value = declaration.value;
1118
1119 if (hasIterator) {
1120 iterator(property, value, declaration);
1121 } else if (value) {
1122 output || (output = {});
1123 output[property] = value;
1124 }
1125 }
1126
1127 return output;
1128 }
1129
1130 var styleToObject = StyleToObject;
1131
1132 var utilities$4 = {};
1133
1134 utilities$4.__esModule = true;
1135 utilities$4.camelCase = void 0;
1136 var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
1137 var HYPHEN_REGEX = /-([a-z])/g;
1138 var NO_HYPHEN_REGEX = /^[^-]+$/;
1139 var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
1140 var skipCamelCase = function (property) {
1141 return !property ||
1142 NO_HYPHEN_REGEX.test(property) ||
1143 CUSTOM_PROPERTY_REGEX.test(property);
1144 };
1145 var capitalize = function (match, character) {
1146 return character.toUpperCase();
1147 };
1148 var trimHyphen = function (match, prefix) { return prefix + "-"; };
1149 var camelCase = function (property, options) {
1150 if (options === void 0) { options = {}; }
1151 if (skipCamelCase(property)) {
1152 return property;
1153 }
1154 property = property.toLowerCase();
1155 if (!options.reactCompat) {
1156 property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
1157 }
1158 return property.replace(HYPHEN_REGEX, capitalize);
1159 };
1160 utilities$4.camelCase = camelCase;
1161
1162 (function (exports) {
1163 var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1164 return (mod && mod.__esModule) ? mod : { "default": mod };
1165 };
1166 exports.__esModule = true;
1167 var style_to_object_1 = __importDefault(styleToObject);
1168 var utilities_1 = utilities$4;
1169 function StyleToJS(style, options) {
1170 var output = {};
1171 if (!style || typeof style !== 'string') {
1172 return output;
1173 }
1174 style_to_object_1["default"](style, function (property, value) {
1175 if (property && value) {
1176 output[utilities_1.camelCase(property, options)] = value;
1177 }
1178 });
1179 return output;
1180 }
1181 exports["default"] = StyleToJS;
1182 }(cjs));
1183
1184 var React$1 = require$$0__default["default"];
1185 var styleToJS = cjs.default;
1186
1187 /**
1188 * Swap key with value in an object.
1189 *
1190 * @param {Object} obj - The object.
1191 * @param {Function} [override] - The override method.
1192 * @return {Object} - The inverted object.
1193 */
1194 function invertObject(obj, override) {
1195 if (!obj || typeof obj !== 'object') {
1196 throw new TypeError('First argument must be an object');
1197 }
1198
1199 var key;
1200 var value;
1201 var isOverridePresent = typeof override === 'function';
1202 var overrides = {};
1203 var result = {};
1204
1205 for (key in obj) {
1206 value = obj[key];
1207
1208 if (isOverridePresent) {
1209 overrides = override(key, value);
1210 if (overrides && overrides.length === 2) {
1211 result[overrides[0]] = overrides[1];
1212 continue;
1213 }
1214 }
1215
1216 if (typeof value === 'string') {
1217 result[value] = key;
1218 }
1219 }
1220
1221 return result;
1222 }
1223
1224 /**
1225 * Check if a given tag is a custom component.
1226 *
1227 * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
1228 *
1229 * @param {string} tagName - The name of the html tag.
1230 * @param {Object} props - The props being passed to the element.
1231 * @return {boolean}
1232 */
1233 function isCustomComponent(tagName, props) {
1234 if (tagName.indexOf('-') === -1) {
1235 return props && typeof props.is === 'string';
1236 }
1237
1238 switch (tagName) {
1239 // These are reserved SVG and MathML elements.
1240 // We don't mind this whitelist too much because we expect it to never grow.
1241 // The alternative is to track the namespace in a few places which is convoluted.
1242 // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
1243 case 'annotation-xml':
1244 case 'color-profile':
1245 case 'font-face':
1246 case 'font-face-src':
1247 case 'font-face-uri':
1248 case 'font-face-format':
1249 case 'font-face-name':
1250 case 'missing-glyph':
1251 return false;
1252 default:
1253 return true;
1254 }
1255 }
1256
1257 var styleToJSOptions = { reactCompat: true };
1258
1259 /**
1260 * Sets style prop.
1261 *
1262 * @param {null|undefined|string} style
1263 * @param {object} props
1264 */
1265 function setStyleProp$1(style, props) {
1266 if (style === null || style === undefined) {
1267 return;
1268 }
1269 try {
1270 props.style = styleToJS(style, styleToJSOptions);
1271 } catch (err) {
1272 props.style = {};
1273 }
1274 }
1275
1276 /**
1277 * @constant {boolean}
1278 * @see {@link https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html}
1279 */
1280 var PRESERVE_CUSTOM_ATTRIBUTES = React$1.version.split('.')[0] >= 16;
1281
1282 // Taken from
1283 // https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
1284 var elementsWithNoTextChildren = new Set([
1285 'tr',
1286 'tbody',
1287 'thead',
1288 'tfoot',
1289 'colgroup',
1290 'table',
1291 'head',
1292 'html',
1293 'frameset'
1294 ]);
1295
1296 /**
1297 * Checks if the given node can contain text nodes
1298 *
1299 * @param {DomElement} node
1300 * @returns {boolean}
1301 */
1302 function canTextBeChildOfNode$1(node) {
1303 return !elementsWithNoTextChildren.has(node.name);
1304 }
1305
1306 var utilities$3 = {
1307 PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
1308 invertObject: invertObject,
1309 isCustomComponent: isCustomComponent,
1310 setStyleProp: setStyleProp$1,
1311 canTextBeChildOfNode: canTextBeChildOfNode$1,
1312 elementsWithNoTextChildren: elementsWithNoTextChildren
1313 };
1314
1315 var reactProperty = lib$1;
1316 var utilities$2 = utilities$3;
1317
1318 /**
1319 * Converts HTML/SVG DOM attributes to React props.
1320 *
1321 * @param {object} [attributes={}] - HTML/SVG DOM attributes.
1322 * @return {object} - React props.
1323 */
1324 var attributesToProps$2 = function attributesToProps(attributes) {
1325 attributes = attributes || {};
1326
1327 var valueOnlyInputs = {
1328 reset: true,
1329 submit: true
1330 };
1331
1332 var attributeName;
1333 var attributeNameLowerCased;
1334 var attributeValue;
1335 var propName;
1336 var propertyInfo;
1337 var props = {};
1338 var inputIsValueOnly = attributes.type && valueOnlyInputs[attributes.type];
1339
1340 for (attributeName in attributes) {
1341 attributeValue = attributes[attributeName];
1342
1343 // ARIA (aria-*) or custom data (data-*) attribute
1344 if (reactProperty.isCustomAttribute(attributeName)) {
1345 props[attributeName] = attributeValue;
1346 continue;
1347 }
1348
1349 // convert HTML/SVG attribute to React prop
1350 attributeNameLowerCased = attributeName.toLowerCase();
1351 propName = getPropName(attributeNameLowerCased);
1352
1353 if (propName) {
1354 propertyInfo = reactProperty.getPropertyInfo(propName);
1355
1356 // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
1357 // https://reactjs.org/docs/uncontrolled-components.html
1358 if (
1359 (propName === 'checked' || propName === 'value') &&
1360 !inputIsValueOnly
1361 ) {
1362 propName = getPropName('default' + attributeNameLowerCased);
1363 }
1364
1365 props[propName] = attributeValue;
1366
1367 switch (propertyInfo && propertyInfo.type) {
1368 case reactProperty.BOOLEAN:
1369 props[propName] = true;
1370 break;
1371 case reactProperty.OVERLOADED_BOOLEAN:
1372 if (attributeValue === '') {
1373 props[propName] = true;
1374 }
1375 break;
1376 }
1377 continue;
1378 }
1379
1380 // preserve custom attribute if React >=16
1381 if (utilities$2.PRESERVE_CUSTOM_ATTRIBUTES) {
1382 props[attributeName] = attributeValue;
1383 }
1384 }
1385
1386 // transform inline style to object
1387 utilities$2.setStyleProp(attributes.style, props);
1388
1389 return props;
1390 };
1391
1392 /**
1393 * Gets prop name from lowercased attribute name.
1394 *
1395 * @param {string} attributeName - Lowercased attribute name.
1396 * @return {string}
1397 */
1398 function getPropName(attributeName) {
1399 return reactProperty.possibleStandardNames[attributeName];
1400 }
1401
1402 var React = require$$0__default["default"];
1403 var attributesToProps$1 = attributesToProps$2;
1404 var utilities$1 = utilities$3;
1405
1406 var setStyleProp = utilities$1.setStyleProp;
1407 var canTextBeChildOfNode = utilities$1.canTextBeChildOfNode;
1408
1409 /**
1410 * Converts DOM nodes to JSX element(s).
1411 *
1412 * @param {DomElement[]} nodes - DOM nodes.
1413 * @param {object} [options={}] - Options.
1414 * @param {Function} [options.replace] - Replacer.
1415 * @param {object} [options.library] - Library (React/Preact/etc.).
1416 * @return {string|JSX.Element|JSX.Element[]}
1417 */
1418 function domToReact$1(nodes, options) {
1419 options = options || {};
1420
1421 var library = options.library || React;
1422 var cloneElement = library.cloneElement;
1423 var createElement = library.createElement;
1424 var isValidElement = library.isValidElement;
1425
1426 var result = [];
1427 var node;
1428 var isWhitespace;
1429 var hasReplace = typeof options.replace === 'function';
1430 var replaceElement;
1431 var props;
1432 var children;
1433 var trim = options.trim;
1434
1435 for (var i = 0, len = nodes.length; i < len; i++) {
1436 node = nodes[i];
1437
1438 // replace with custom React element (if present)
1439 if (hasReplace) {
1440 replaceElement = options.replace(node);
1441
1442 if (isValidElement(replaceElement)) {
1443 // set "key" prop for sibling elements
1444 // https://fb.me/react-warning-keys
1445 if (len > 1) {
1446 replaceElement = cloneElement(replaceElement, {
1447 key: replaceElement.key || i
1448 });
1449 }
1450 result.push(replaceElement);
1451 continue;
1452 }
1453 }
1454
1455 if (node.type === 'text') {
1456 isWhitespace = !node.data.trim().length;
1457
1458 if (isWhitespace && node.parent && !canTextBeChildOfNode(node.parent)) {
1459 // We have a whitespace node that can't be nested in its parent
1460 // so skip it
1461 continue;
1462 }
1463
1464 if (trim && isWhitespace) {
1465 // Trim is enabled and we have a whitespace node
1466 // so skip it
1467 continue;
1468 }
1469
1470 // We have a text node that's not whitespace and it can be nested
1471 // in its parent so add it to the results
1472 result.push(node.data);
1473 continue;
1474 }
1475
1476 props = node.attribs;
1477 if (skipAttributesToProps(node)) {
1478 setStyleProp(props.style, props);
1479 } else if (props) {
1480 props = attributesToProps$1(props);
1481 }
1482
1483 children = null;
1484
1485 switch (node.type) {
1486 case 'script':
1487 case 'style':
1488 // prevent text in <script> or <style> from being escaped
1489 // https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
1490 if (node.children[0]) {
1491 props.dangerouslySetInnerHTML = {
1492 __html: node.children[0].data
1493 };
1494 }
1495 break;
1496
1497 case 'tag':
1498 // setting textarea value in children is an antipattern in React
1499 // https://reactjs.org/docs/forms.html#the-textarea-tag
1500 if (node.name === 'textarea' && node.children[0]) {
1501 props.defaultValue = node.children[0].data;
1502 } else if (node.children && node.children.length) {
1503 // continue recursion of creating React elements (if applicable)
1504 children = domToReact$1(node.children, options);
1505 }
1506 break;
1507
1508 // skip all other cases (e.g., comment)
1509 default:
1510 continue;
1511 }
1512
1513 // set "key" prop for sibling elements
1514 // https://fb.me/react-warning-keys
1515 if (len > 1) {
1516 props.key = i;
1517 }
1518
1519 result.push(createElement(node.name, props, children));
1520 }
1521
1522 return result.length === 1 ? result[0] : result;
1523 }
1524
1525 /**
1526 * Determines whether DOM element attributes should be transformed to props.
1527 * Web Components should not have their attributes transformed except for `style`.
1528 *
1529 * @param {DomElement} node
1530 * @return {boolean}
1531 */
1532 function skipAttributesToProps(node) {
1533 return (
1534 utilities$1.PRESERVE_CUSTOM_ATTRIBUTES &&
1535 node.type === 'tag' &&
1536 utilities$1.isCustomComponent(node.name, node.attribs)
1537 );
1538 }
1539
1540 var domToReact_1 = domToReact$1;
1541
1542 /**
1543 * SVG elements are case-sensitive.
1544 *
1545 * @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
1546 */
1547
1548 var CASE_SENSITIVE_TAG_NAMES$1 = [
1549 'animateMotion',
1550 'animateTransform',
1551 'clipPath',
1552 'feBlend',
1553 'feColorMatrix',
1554 'feComponentTransfer',
1555 'feComposite',
1556 'feConvolveMatrix',
1557 'feDiffuseLighting',
1558 'feDisplacementMap',
1559 'feDropShadow',
1560 'feFlood',
1561 'feFuncA',
1562 'feFuncB',
1563 'feFuncG',
1564 'feFuncR',
1565 'feGaussainBlur',
1566 'feImage',
1567 'feMerge',
1568 'feMergeNode',
1569 'feMorphology',
1570 'feOffset',
1571 'fePointLight',
1572 'feSpecularLighting',
1573 'feSpotLight',
1574 'feTile',
1575 'feTurbulence',
1576 'foreignObject',
1577 'linearGradient',
1578 'radialGradient',
1579 'textPath'
1580 ];
1581
1582 var constants$1 = {
1583 CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES$1
1584 };
1585
1586 var node = {};
1587
1588 var lib = {};
1589
1590 (function (exports) {
1591 Object.defineProperty(exports, "__esModule", { value: true });
1592 exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
1593 /** Types of elements found in htmlparser2's DOM */
1594 var ElementType;
1595 (function (ElementType) {
1596 /** Type for the root element of a document */
1597 ElementType["Root"] = "root";
1598 /** Type for Text */
1599 ElementType["Text"] = "text";
1600 /** Type for <? ... ?> */
1601 ElementType["Directive"] = "directive";
1602 /** Type for <!-- ... --> */
1603 ElementType["Comment"] = "comment";
1604 /** Type for <script> tags */
1605 ElementType["Script"] = "script";
1606 /** Type for <style> tags */
1607 ElementType["Style"] = "style";
1608 /** Type for Any tag */
1609 ElementType["Tag"] = "tag";
1610 /** Type for <![CDATA[ ... ]]> */
1611 ElementType["CDATA"] = "cdata";
1612 /** Type for <!doctype ...> */
1613 ElementType["Doctype"] = "doctype";
1614 })(ElementType = exports.ElementType || (exports.ElementType = {}));
1615 /**
1616 * Tests whether an element is a tag or not.
1617 *
1618 * @param elem Element to test
1619 */
1620 function isTag(elem) {
1621 return (elem.type === ElementType.Tag ||
1622 elem.type === ElementType.Script ||
1623 elem.type === ElementType.Style);
1624 }
1625 exports.isTag = isTag;
1626 // Exports for backwards compatibility
1627 /** Type for the root element of a document */
1628 exports.Root = ElementType.Root;
1629 /** Type for Text */
1630 exports.Text = ElementType.Text;
1631 /** Type for <? ... ?> */
1632 exports.Directive = ElementType.Directive;
1633 /** Type for <!-- ... --> */
1634 exports.Comment = ElementType.Comment;
1635 /** Type for <script> tags */
1636 exports.Script = ElementType.Script;
1637 /** Type for <style> tags */
1638 exports.Style = ElementType.Style;
1639 /** Type for Any tag */
1640 exports.Tag = ElementType.Tag;
1641 /** Type for <![CDATA[ ... ]]> */
1642 exports.CDATA = ElementType.CDATA;
1643 /** Type for <!doctype ...> */
1644 exports.Doctype = ElementType.Doctype;
1645 }(lib));
1646
1647 var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
1648 var extendStatics = function (d, b) {
1649 extendStatics = Object.setPrototypeOf ||
1650 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1651 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1652 return extendStatics(d, b);
1653 };
1654 return function (d, b) {
1655 if (typeof b !== "function" && b !== null)
1656 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1657 extendStatics(d, b);
1658 function __() { this.constructor = d; }
1659 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1660 };
1661 })();
1662 var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1663 __assign = Object.assign || function(t) {
1664 for (var s, i = 1, n = arguments.length; i < n; i++) {
1665 s = arguments[i];
1666 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1667 t[p] = s[p];
1668 }
1669 return t;
1670 };
1671 return __assign.apply(this, arguments);
1672 };
1673 Object.defineProperty(node, "__esModule", { value: true });
1674 node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
1675 var domelementtype_1 = lib;
1676 var nodeTypes = new Map([
1677 [domelementtype_1.ElementType.Tag, 1],
1678 [domelementtype_1.ElementType.Script, 1],
1679 [domelementtype_1.ElementType.Style, 1],
1680 [domelementtype_1.ElementType.Directive, 1],
1681 [domelementtype_1.ElementType.Text, 3],
1682 [domelementtype_1.ElementType.CDATA, 4],
1683 [domelementtype_1.ElementType.Comment, 8],
1684 [domelementtype_1.ElementType.Root, 9],
1685 ]);
1686 /**
1687 * This object will be used as the prototype for Nodes when creating a
1688 * DOM-Level-1-compliant structure.
1689 */
1690 var Node = /** @class */ (function () {
1691 /**
1692 *
1693 * @param type The type of the node.
1694 */
1695 function Node(type) {
1696 this.type = type;
1697 /** Parent of the node */
1698 this.parent = null;
1699 /** Previous sibling */
1700 this.prev = null;
1701 /** Next sibling */
1702 this.next = null;
1703 /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
1704 this.startIndex = null;
1705 /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
1706 this.endIndex = null;
1707 }
1708 Object.defineProperty(Node.prototype, "nodeType", {
1709 // Read-only aliases
1710 /**
1711 * [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
1712 * node {@link type}.
1713 */
1714 get: function () {
1715 var _a;
1716 return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
1717 },
1718 enumerable: false,
1719 configurable: true
1720 });
1721 Object.defineProperty(Node.prototype, "parentNode", {
1722 // Read-write aliases for properties
1723 /**
1724 * Same as {@link parent}.
1725 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1726 */
1727 get: function () {
1728 return this.parent;
1729 },
1730 set: function (parent) {
1731 this.parent = parent;
1732 },
1733 enumerable: false,
1734 configurable: true
1735 });
1736 Object.defineProperty(Node.prototype, "previousSibling", {
1737 /**
1738 * Same as {@link prev}.
1739 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1740 */
1741 get: function () {
1742 return this.prev;
1743 },
1744 set: function (prev) {
1745 this.prev = prev;
1746 },
1747 enumerable: false,
1748 configurable: true
1749 });
1750 Object.defineProperty(Node.prototype, "nextSibling", {
1751 /**
1752 * Same as {@link next}.
1753 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1754 */
1755 get: function () {
1756 return this.next;
1757 },
1758 set: function (next) {
1759 this.next = next;
1760 },
1761 enumerable: false,
1762 configurable: true
1763 });
1764 /**
1765 * Clone this node, and optionally its children.
1766 *
1767 * @param recursive Clone child nodes as well.
1768 * @returns A clone of the node.
1769 */
1770 Node.prototype.cloneNode = function (recursive) {
1771 if (recursive === void 0) { recursive = false; }
1772 return cloneNode(this, recursive);
1773 };
1774 return Node;
1775 }());
1776 node.Node = Node;
1777 /**
1778 * A node that contains some data.
1779 */
1780 var DataNode = /** @class */ (function (_super) {
1781 __extends(DataNode, _super);
1782 /**
1783 * @param type The type of the node
1784 * @param data The content of the data node
1785 */
1786 function DataNode(type, data) {
1787 var _this = _super.call(this, type) || this;
1788 _this.data = data;
1789 return _this;
1790 }
1791 Object.defineProperty(DataNode.prototype, "nodeValue", {
1792 /**
1793 * Same as {@link data}.
1794 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1795 */
1796 get: function () {
1797 return this.data;
1798 },
1799 set: function (data) {
1800 this.data = data;
1801 },
1802 enumerable: false,
1803 configurable: true
1804 });
1805 return DataNode;
1806 }(Node));
1807 node.DataNode = DataNode;
1808 /**
1809 * Text within the document.
1810 */
1811 var Text$1 = /** @class */ (function (_super) {
1812 __extends(Text, _super);
1813 function Text(data) {
1814 return _super.call(this, domelementtype_1.ElementType.Text, data) || this;
1815 }
1816 return Text;
1817 }(DataNode));
1818 node.Text = Text$1;
1819 /**
1820 * Comments within the document.
1821 */
1822 var Comment$1 = /** @class */ (function (_super) {
1823 __extends(Comment, _super);
1824 function Comment(data) {
1825 return _super.call(this, domelementtype_1.ElementType.Comment, data) || this;
1826 }
1827 return Comment;
1828 }(DataNode));
1829 node.Comment = Comment$1;
1830 /**
1831 * Processing instructions, including doc types.
1832 */
1833 var ProcessingInstruction$1 = /** @class */ (function (_super) {
1834 __extends(ProcessingInstruction, _super);
1835 function ProcessingInstruction(name, data) {
1836 var _this = _super.call(this, domelementtype_1.ElementType.Directive, data) || this;
1837 _this.name = name;
1838 return _this;
1839 }
1840 return ProcessingInstruction;
1841 }(DataNode));
1842 node.ProcessingInstruction = ProcessingInstruction$1;
1843 /**
1844 * A `Node` that can have children.
1845 */
1846 var NodeWithChildren = /** @class */ (function (_super) {
1847 __extends(NodeWithChildren, _super);
1848 /**
1849 * @param type Type of the node.
1850 * @param children Children of the node. Only certain node types can have children.
1851 */
1852 function NodeWithChildren(type, children) {
1853 var _this = _super.call(this, type) || this;
1854 _this.children = children;
1855 return _this;
1856 }
1857 Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
1858 // Aliases
1859 /** First child of the node. */
1860 get: function () {
1861 var _a;
1862 return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
1863 },
1864 enumerable: false,
1865 configurable: true
1866 });
1867 Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
1868 /** Last child of the node. */
1869 get: function () {
1870 return this.children.length > 0
1871 ? this.children[this.children.length - 1]
1872 : null;
1873 },
1874 enumerable: false,
1875 configurable: true
1876 });
1877 Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
1878 /**
1879 * Same as {@link children}.
1880 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1881 */
1882 get: function () {
1883 return this.children;
1884 },
1885 set: function (children) {
1886 this.children = children;
1887 },
1888 enumerable: false,
1889 configurable: true
1890 });
1891 return NodeWithChildren;
1892 }(Node));
1893 node.NodeWithChildren = NodeWithChildren;
1894 /**
1895 * The root node of the document.
1896 */
1897 var Document = /** @class */ (function (_super) {
1898 __extends(Document, _super);
1899 function Document(children) {
1900 return _super.call(this, domelementtype_1.ElementType.Root, children) || this;
1901 }
1902 return Document;
1903 }(NodeWithChildren));
1904 node.Document = Document;
1905 /**
1906 * An element within the DOM.
1907 */
1908 var Element$1 = /** @class */ (function (_super) {
1909 __extends(Element, _super);
1910 /**
1911 * @param name Name of the tag, eg. `div`, `span`.
1912 * @param attribs Object mapping attribute names to attribute values.
1913 * @param children Children of the node.
1914 */
1915 function Element(name, attribs, children, type) {
1916 if (children === void 0) { children = []; }
1917 if (type === void 0) { type = name === "script"
1918 ? domelementtype_1.ElementType.Script
1919 : name === "style"
1920 ? domelementtype_1.ElementType.Style
1921 : domelementtype_1.ElementType.Tag; }
1922 var _this = _super.call(this, type, children) || this;
1923 _this.name = name;
1924 _this.attribs = attribs;
1925 return _this;
1926 }
1927 Object.defineProperty(Element.prototype, "tagName", {
1928 // DOM Level 1 aliases
1929 /**
1930 * Same as {@link name}.
1931 * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1932 */
1933 get: function () {
1934 return this.name;
1935 },
1936 set: function (name) {
1937 this.name = name;
1938 },
1939 enumerable: false,
1940 configurable: true
1941 });
1942 Object.defineProperty(Element.prototype, "attributes", {
1943 get: function () {
1944 var _this = this;
1945 return Object.keys(this.attribs).map(function (name) {
1946 var _a, _b;
1947 return ({
1948 name: name,
1949 value: _this.attribs[name],
1950 namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
1951 prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
1952 });
1953 });
1954 },
1955 enumerable: false,
1956 configurable: true
1957 });
1958 return Element;
1959 }(NodeWithChildren));
1960 node.Element = Element$1;
1961 /**
1962 * @param node Node to check.
1963 * @returns `true` if the node is a `Element`, `false` otherwise.
1964 */
1965 function isTag(node) {
1966 return (0, domelementtype_1.isTag)(node);
1967 }
1968 node.isTag = isTag;
1969 /**
1970 * @param node Node to check.
1971 * @returns `true` if the node has the type `CDATA`, `false` otherwise.
1972 */
1973 function isCDATA(node) {
1974 return node.type === domelementtype_1.ElementType.CDATA;
1975 }
1976 node.isCDATA = isCDATA;
1977 /**
1978 * @param node Node to check.
1979 * @returns `true` if the node has the type `Text`, `false` otherwise.
1980 */
1981 function isText(node) {
1982 return node.type === domelementtype_1.ElementType.Text;
1983 }
1984 node.isText = isText;
1985 /**
1986 * @param node Node to check.
1987 * @returns `true` if the node has the type `Comment`, `false` otherwise.
1988 */
1989 function isComment(node) {
1990 return node.type === domelementtype_1.ElementType.Comment;
1991 }
1992 node.isComment = isComment;
1993 /**
1994 * @param node Node to check.
1995 * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
1996 */
1997 function isDirective(node) {
1998 return node.type === domelementtype_1.ElementType.Directive;
1999 }
2000 node.isDirective = isDirective;
2001 /**
2002 * @param node Node to check.
2003 * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
2004 */
2005 function isDocument(node) {
2006 return node.type === domelementtype_1.ElementType.Root;
2007 }
2008 node.isDocument = isDocument;
2009 /**
2010 * @param node Node to check.
2011 * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
2012 */
2013 function hasChildren(node) {
2014 return Object.prototype.hasOwnProperty.call(node, "children");
2015 }
2016 node.hasChildren = hasChildren;
2017 /**
2018 * Clone a node, and optionally its children.
2019 *
2020 * @param recursive Clone child nodes as well.
2021 * @returns A clone of the node.
2022 */
2023 function cloneNode(node, recursive) {
2024 if (recursive === void 0) { recursive = false; }
2025 var result;
2026 if (isText(node)) {
2027 result = new Text$1(node.data);
2028 }
2029 else if (isComment(node)) {
2030 result = new Comment$1(node.data);
2031 }
2032 else if (isTag(node)) {
2033 var children = recursive ? cloneChildren(node.children) : [];
2034 var clone_1 = new Element$1(node.name, __assign({}, node.attribs), children);
2035 children.forEach(function (child) { return (child.parent = clone_1); });
2036 if (node.namespace != null) {
2037 clone_1.namespace = node.namespace;
2038 }
2039 if (node["x-attribsNamespace"]) {
2040 clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
2041 }
2042 if (node["x-attribsPrefix"]) {
2043 clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
2044 }
2045 result = clone_1;
2046 }
2047 else if (isCDATA(node)) {
2048 var children = recursive ? cloneChildren(node.children) : [];
2049 var clone_2 = new NodeWithChildren(domelementtype_1.ElementType.CDATA, children);
2050 children.forEach(function (child) { return (child.parent = clone_2); });
2051 result = clone_2;
2052 }
2053 else if (isDocument(node)) {
2054 var children = recursive ? cloneChildren(node.children) : [];
2055 var clone_3 = new Document(children);
2056 children.forEach(function (child) { return (child.parent = clone_3); });
2057 if (node["x-mode"]) {
2058 clone_3["x-mode"] = node["x-mode"];
2059 }
2060 result = clone_3;
2061 }
2062 else if (isDirective(node)) {
2063 var instruction = new ProcessingInstruction$1(node.name, node.data);
2064 if (node["x-name"] != null) {
2065 instruction["x-name"] = node["x-name"];
2066 instruction["x-publicId"] = node["x-publicId"];
2067 instruction["x-systemId"] = node["x-systemId"];
2068 }
2069 result = instruction;
2070 }
2071 else {
2072 throw new Error("Not implemented yet: ".concat(node.type));
2073 }
2074 result.startIndex = node.startIndex;
2075 result.endIndex = node.endIndex;
2076 if (node.sourceCodeLocation != null) {
2077 result.sourceCodeLocation = node.sourceCodeLocation;
2078 }
2079 return result;
2080 }
2081 node.cloneNode = cloneNode;
2082 function cloneChildren(childs) {
2083 var children = childs.map(function (child) { return cloneNode(child, true); });
2084 for (var i = 1; i < children.length; i++) {
2085 children[i].prev = children[i - 1];
2086 children[i - 1].next = children[i];
2087 }
2088 return children;
2089 }
2090
2091 var constants = constants$1;
2092 var domhandler = node;
2093
2094 var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
2095
2096 var Comment = domhandler.Comment;
2097 var Element = domhandler.Element;
2098 var ProcessingInstruction = domhandler.ProcessingInstruction;
2099 var Text = domhandler.Text;
2100
2101 var caseSensitiveTagNamesMap = {};
2102 var tagName;
2103
2104 for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
2105 tagName = CASE_SENSITIVE_TAG_NAMES[i];
2106 caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
2107 }
2108
2109 /**
2110 * Gets case-sensitive tag name.
2111 *
2112 * @param {string} tagName - Tag name in lowercase.
2113 * @return {string|undefined} - Case-sensitive tag name.
2114 */
2115 function getCaseSensitiveTagName(tagName) {
2116 return caseSensitiveTagNamesMap[tagName];
2117 }
2118
2119 /**
2120 * Formats DOM attributes to a hash map.
2121 *
2122 * @param {NamedNodeMap} attributes - List of attributes.
2123 * @return {object} - Map of attribute name to value.
2124 */
2125 function formatAttributes(attributes) {
2126 var result = {};
2127 var attribute;
2128 // `NamedNodeMap` is array-like
2129 for (var i = 0, len = attributes.length; i < len; i++) {
2130 attribute = attributes[i];
2131 result[attribute.name] = attribute.value;
2132 }
2133 return result;
2134 }
2135
2136 /**
2137 * Corrects the tag name if it is case-sensitive (SVG).
2138 * Otherwise, returns the lowercase tag name (HTML).
2139 *
2140 * @param {string} tagName - Lowercase tag name.
2141 * @return {string} - Formatted tag name.
2142 */
2143 function formatTagName(tagName) {
2144 tagName = tagName.toLowerCase();
2145 var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
2146 if (caseSensitiveTagName) {
2147 return caseSensitiveTagName;
2148 }
2149 return tagName;
2150 }
2151
2152 /**
2153 * Transforms DOM nodes to `domhandler` nodes.
2154 *
2155 * @param {NodeList} nodes - DOM nodes.
2156 * @param {Element|null} [parent=null] - Parent node.
2157 * @param {string} [directive] - Directive.
2158 * @return {Array<Comment|Element|ProcessingInstruction|Text>}
2159 */
2160 function formatDOM$1(nodes, parent, directive) {
2161 parent = parent || null;
2162 var result = [];
2163
2164 for (var index = 0, len = nodes.length; index < len; index++) {
2165 var node = nodes[index];
2166 var current;
2167
2168 // set the node data given the type
2169 switch (node.nodeType) {
2170 case 1:
2171 // script, style, or tag
2172 current = new Element(
2173 formatTagName(node.nodeName),
2174 formatAttributes(node.attributes)
2175 );
2176 current.children = formatDOM$1(node.childNodes, current);
2177 break;
2178
2179 case 3:
2180 current = new Text(node.nodeValue);
2181 break;
2182
2183 case 8:
2184 current = new Comment(node.nodeValue);
2185 break;
2186
2187 default:
2188 continue;
2189 }
2190
2191 // set previous node next
2192 var prev = result[index - 1] || null;
2193 if (prev) {
2194 prev.next = current;
2195 }
2196
2197 // set properties for current node
2198 current.parent = parent;
2199 current.prev = prev;
2200 current.next = null;
2201
2202 result.push(current);
2203 }
2204
2205 if (directive) {
2206 current = new ProcessingInstruction(
2207 directive.substring(0, directive.indexOf(' ')).toLowerCase(),
2208 directive
2209 );
2210 current.next = result[0] || null;
2211 current.parent = parent;
2212 result.unshift(current);
2213
2214 if (result[1]) {
2215 result[1].prev = result[0];
2216 }
2217 }
2218
2219 return result;
2220 }
2221
2222 /**
2223 * Detects if browser is Internet Explorer.
2224 *
2225 * @return {boolean} - Whether IE is detected.
2226 */
2227 function isIE$1() {
2228 return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
2229 }
2230
2231 var utilities = {
2232 formatAttributes: formatAttributes,
2233 formatDOM: formatDOM$1,
2234 isIE: isIE$1
2235 };
2236
2237 // constants
2238 var HTML = 'html';
2239 var HEAD = 'head';
2240 var BODY = 'body';
2241 var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
2242 var HEAD_TAG_REGEX = /<head.*>/i;
2243 var BODY_TAG_REGEX = /<body.*>/i;
2244
2245 // falls back to `parseFromString` if `createHTMLDocument` cannot be used
2246 var parseFromDocument = function () {
2247 throw new Error(
2248 'This browser does not support `document.implementation.createHTMLDocument`'
2249 );
2250 };
2251
2252 var parseFromString = function () {
2253 throw new Error(
2254 'This browser does not support `DOMParser.prototype.parseFromString`'
2255 );
2256 };
2257
2258 /**
2259 * DOMParser (performance: slow).
2260 *
2261 * @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
2262 */
2263 if (typeof window.DOMParser === 'function') {
2264 var domParser = new window.DOMParser();
2265 var mimeType = 'text/html';
2266
2267 /**
2268 * Creates an HTML document using `DOMParser.parseFromString`.
2269 *
2270 * @param {string} html - The HTML string.
2271 * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
2272 * @return {HTMLDocument}
2273 */
2274 parseFromString = function (html, tagName) {
2275 if (tagName) {
2276 html = '<' + tagName + '>' + html + '</' + tagName + '>';
2277 }
2278
2279 return domParser.parseFromString(html, mimeType);
2280 };
2281
2282 parseFromDocument = parseFromString;
2283 }
2284
2285 /**
2286 * DOMImplementation (performance: fair).
2287 *
2288 * @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
2289 */
2290 if (document.implementation) {
2291 var isIE = utilities.isIE;
2292
2293 // title parameter is required in IE
2294 // https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
2295 var doc = document.implementation.createHTMLDocument(
2296 isIE() ? 'html-dom-parser' : undefined
2297 );
2298
2299 /**
2300 * Use HTML document created by `document.implementation.createHTMLDocument`.
2301 *
2302 * @param {string} html - The HTML string.
2303 * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
2304 * @return {HTMLDocument}
2305 */
2306 parseFromDocument = function (html, tagName) {
2307 if (tagName) {
2308 doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
2309 return doc;
2310 }
2311
2312 doc.documentElement.innerHTML = html;
2313 return doc;
2314 };
2315 }
2316
2317 /**
2318 * Template (performance: fast).
2319 *
2320 * @see https://developer.mozilla.org/docs/Web/HTML/Element/template
2321 */
2322 var template = document.createElement('template');
2323 var parseFromTemplate;
2324
2325 if (template.content) {
2326 /**
2327 * Uses a template element (content fragment) to parse HTML.
2328 *
2329 * @param {string} html - The HTML string.
2330 * @return {NodeList}
2331 */
2332 parseFromTemplate = function (html) {
2333 template.innerHTML = html;
2334 return template.content.childNodes;
2335 };
2336 }
2337
2338 /**
2339 * Parses HTML string to DOM nodes.
2340 *
2341 * @param {string} html - HTML markup.
2342 * @return {NodeList}
2343 */
2344 function domparser$1(html) {
2345 var firstTagName;
2346 var match = html.match(FIRST_TAG_REGEX);
2347
2348 if (match && match[1]) {
2349 firstTagName = match[1].toLowerCase();
2350 }
2351
2352 var doc;
2353 var element;
2354 var elements;
2355
2356 switch (firstTagName) {
2357 case HTML:
2358 doc = parseFromString(html);
2359
2360 // the created document may come with filler head/body elements,
2361 // so make sure to remove them if they don't actually exist
2362 if (!HEAD_TAG_REGEX.test(html)) {
2363 element = doc.getElementsByTagName(HEAD)[0];
2364 if (element) {
2365 element.parentNode.removeChild(element);
2366 }
2367 }
2368
2369 if (!BODY_TAG_REGEX.test(html)) {
2370 element = doc.getElementsByTagName(BODY)[0];
2371 if (element) {
2372 element.parentNode.removeChild(element);
2373 }
2374 }
2375
2376 return doc.getElementsByTagName(HTML);
2377
2378 case HEAD:
2379 case BODY:
2380 elements = parseFromDocument(html).getElementsByTagName(firstTagName);
2381
2382 // if there's a sibling element, then return both elements
2383 if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
2384 return elements[0].parentNode.childNodes;
2385 }
2386 return elements;
2387
2388 // low-level tag or text
2389 default:
2390 if (parseFromTemplate) {
2391 return parseFromTemplate(html);
2392 }
2393
2394 return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
2395 .childNodes;
2396 }
2397 }
2398
2399 var domparser_1 = domparser$1;
2400
2401 var domparser = domparser_1;
2402 var formatDOM = utilities.formatDOM;
2403
2404 var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
2405
2406 /**
2407 * Parses HTML string to DOM nodes in browser.
2408 *
2409 * @param {string} html - HTML markup.
2410 * @return {DomElement[]} - DOM elements.
2411 */
2412 function HTMLDOMParser(html) {
2413 if (typeof html !== 'string') {
2414 throw new TypeError('First argument must be a string');
2415 }
2416
2417 if (html === '') {
2418 return [];
2419 }
2420
2421 // match directive
2422 var match = html.match(DIRECTIVE_REGEX);
2423 var directive;
2424
2425 if (match && match[1]) {
2426 directive = match[1];
2427 }
2428
2429 return formatDOM(domparser(html), null, directive);
2430 }
2431
2432 var htmlToDom = HTMLDOMParser;
2433
2434 var domToReact = domToReact_1;
2435 var attributesToProps = attributesToProps$2;
2436 var htmlToDOM = htmlToDom;
2437
2438 // support backwards compatibility for ES Module
2439 htmlToDOM =
2440 /* istanbul ignore next */
2441 typeof htmlToDOM.default === 'function' ? htmlToDOM.default : htmlToDOM;
2442
2443 var domParserOptions = { lowerCaseAttributeNames: false };
2444
2445 /**
2446 * Converts HTML string to React elements.
2447 *
2448 * @param {String} html - HTML string.
2449 * @param {Object} [options] - Parser options.
2450 * @param {Object} [options.htmlparser2] - htmlparser2 options.
2451 * @param {Object} [options.library] - Library for React, Preact, etc.
2452 * @param {Function} [options.replace] - Replace method.
2453 * @return {JSX.Element|JSX.Element[]|String} - React element(s), empty array, or string.
2454 */
2455 function HTMLReactParser(html, options) {
2456 if (typeof html !== 'string') {
2457 throw new TypeError('First argument must be a string');
2458 }
2459 if (html === '') {
2460 return [];
2461 }
2462 options = options || {};
2463 return domToReact(
2464 htmlToDOM(html, options.htmlparser2 || domParserOptions),
2465 options
2466 );
2467 }
2468
2469 HTMLReactParser.domToReact = domToReact;
2470 HTMLReactParser.htmlToDOM = htmlToDOM;
2471 HTMLReactParser.attributesToProps = attributesToProps;
2472 HTMLReactParser.Element = node.Element;
2473
2474 // support CommonJS and ES Modules
2475 htmlReactParser$1.exports = HTMLReactParser;
2476 htmlReactParser$1.exports.default = HTMLReactParser;
2477
2478 var htmlReactParser = htmlReactParser$1.exports;
2479
2480 return htmlReactParser;
2481
2482}));
2483//# sourceMappingURL=html-react-parser.js.map