UNPKG

42.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 = global || self, global.HTMLReactParser = factory(global.React));
5}(this, (function (react) { 'use strict';
6
7 react = react && react.hasOwnProperty('default') ? react['default'] : react;
8
9 var HTMLDOMPropertyConfig = {
10 Properties: {
11 autoFocus: 4,
12 accept: 0,
13 acceptCharset: 0,
14 accessKey: 0,
15 action: 0,
16 allowFullScreen: 4,
17 allowTransparency: 0,
18 alt: 0,
19 as: 0,
20 async: 4,
21 autoComplete: 0,
22 autoPlay: 4,
23 capture: 4,
24 cellPadding: 0,
25 cellSpacing: 0,
26 charSet: 0,
27 challenge: 0,
28 checked: 5,
29 cite: 0,
30 classID: 0,
31 className: 0,
32 cols: 24,
33 colSpan: 0,
34 content: 0,
35 contentEditable: 0,
36 contextMenu: 0,
37 controls: 4,
38 controlsList: 0,
39 coords: 0,
40 crossOrigin: 0,
41 data: 0,
42 dateTime: 0,
43 default: 4,
44 defer: 4,
45 dir: 0,
46 disabled: 4,
47 download: 32,
48 draggable: 0,
49 encType: 0,
50 form: 0,
51 formAction: 0,
52 formEncType: 0,
53 formMethod: 0,
54 formNoValidate: 4,
55 formTarget: 0,
56 frameBorder: 0,
57 headers: 0,
58 height: 0,
59 hidden: 4,
60 high: 0,
61 href: 0,
62 hrefLang: 0,
63 htmlFor: 0,
64 httpEquiv: 0,
65 icon: 0,
66 id: 0,
67 inputMode: 0,
68 integrity: 0,
69 is: 0,
70 keyParams: 0,
71 keyType: 0,
72 kind: 0,
73 label: 0,
74 lang: 0,
75 list: 0,
76 loop: 4,
77 low: 0,
78 manifest: 0,
79 marginHeight: 0,
80 marginWidth: 0,
81 max: 0,
82 maxLength: 0,
83 media: 0,
84 mediaGroup: 0,
85 method: 0,
86 min: 0,
87 minLength: 0,
88 multiple: 5,
89 muted: 5,
90 name: 0,
91 nonce: 0,
92 noValidate: 4,
93 open: 4,
94 optimum: 0,
95 pattern: 0,
96 placeholder: 0,
97 playsInline: 4,
98 poster: 0,
99 preload: 0,
100 profile: 0,
101 radioGroup: 0,
102 readOnly: 4,
103 referrerPolicy: 0,
104 rel: 0,
105 required: 4,
106 reversed: 4,
107 role: 0,
108 rows: 24,
109 rowSpan: 8,
110 sandbox: 0,
111 scope: 0,
112 scoped: 4,
113 scrolling: 0,
114 seamless: 4,
115 selected: 5,
116 shape: 0,
117 size: 24,
118 sizes: 0,
119 span: 24,
120 spellCheck: 0,
121 src: 0,
122 srcDoc: 0,
123 srcLang: 0,
124 srcSet: 0,
125 start: 8,
126 step: 0,
127 style: 0,
128 summary: 0,
129 tabIndex: 0,
130 target: 0,
131 title: 0,
132 type: 0,
133 useMap: 0,
134 value: 0,
135 width: 0,
136 wmode: 0,
137 wrap: 0,
138 about: 0,
139 datatype: 0,
140 inlist: 0,
141 prefix: 0,
142 property: 0,
143 resource: 0,
144 typeof: 0,
145 vocab: 0,
146 autoCapitalize: 0,
147 autoCorrect: 0,
148 autoSave: 0,
149 color: 0,
150 itemProp: 0,
151 itemScope: 4,
152 itemType: 0,
153 itemID: 0,
154 itemRef: 0,
155 results: 0,
156 security: 0,
157 unselectable: 0
158 },
159 DOMAttributeNames: {
160 acceptCharset: 'accept-charset',
161 className: 'class',
162 htmlFor: 'for',
163 httpEquiv: 'http-equiv'
164 }
165 };
166
167 var SVGDOMPropertyConfig = {
168 Properties: {
169 accentHeight: 0,
170 accumulate: 0,
171 additive: 0,
172 alignmentBaseline: 0,
173 allowReorder: 0,
174 alphabetic: 0,
175 amplitude: 0,
176 arabicForm: 0,
177 ascent: 0,
178 attributeName: 0,
179 attributeType: 0,
180 autoReverse: 0,
181 azimuth: 0,
182 baseFrequency: 0,
183 baseProfile: 0,
184 baselineShift: 0,
185 bbox: 0,
186 begin: 0,
187 bias: 0,
188 by: 0,
189 calcMode: 0,
190 capHeight: 0,
191 clip: 0,
192 clipPath: 0,
193 clipRule: 0,
194 clipPathUnits: 0,
195 colorInterpolation: 0,
196 colorInterpolationFilters: 0,
197 colorProfile: 0,
198 colorRendering: 0,
199 contentScriptType: 0,
200 contentStyleType: 0,
201 cursor: 0,
202 cx: 0,
203 cy: 0,
204 d: 0,
205 decelerate: 0,
206 descent: 0,
207 diffuseConstant: 0,
208 direction: 0,
209 display: 0,
210 divisor: 0,
211 dominantBaseline: 0,
212 dur: 0,
213 dx: 0,
214 dy: 0,
215 edgeMode: 0,
216 elevation: 0,
217 enableBackground: 0,
218 end: 0,
219 exponent: 0,
220 externalResourcesRequired: 0,
221 fill: 0,
222 fillOpacity: 0,
223 fillRule: 0,
224 filter: 0,
225 filterRes: 0,
226 filterUnits: 0,
227 floodColor: 0,
228 floodOpacity: 0,
229 focusable: 0,
230 fontFamily: 0,
231 fontSize: 0,
232 fontSizeAdjust: 0,
233 fontStretch: 0,
234 fontStyle: 0,
235 fontVariant: 0,
236 fontWeight: 0,
237 format: 0,
238 from: 0,
239 fx: 0,
240 fy: 0,
241 g1: 0,
242 g2: 0,
243 glyphName: 0,
244 glyphOrientationHorizontal: 0,
245 glyphOrientationVertical: 0,
246 glyphRef: 0,
247 gradientTransform: 0,
248 gradientUnits: 0,
249 hanging: 0,
250 horizAdvX: 0,
251 horizOriginX: 0,
252 ideographic: 0,
253 imageRendering: 0,
254 in: 0,
255 in2: 0,
256 intercept: 0,
257 k: 0,
258 k1: 0,
259 k2: 0,
260 k3: 0,
261 k4: 0,
262 kernelMatrix: 0,
263 kernelUnitLength: 0,
264 kerning: 0,
265 keyPoints: 0,
266 keySplines: 0,
267 keyTimes: 0,
268 lengthAdjust: 0,
269 letterSpacing: 0,
270 lightingColor: 0,
271 limitingConeAngle: 0,
272 local: 0,
273 markerEnd: 0,
274 markerMid: 0,
275 markerStart: 0,
276 markerHeight: 0,
277 markerUnits: 0,
278 markerWidth: 0,
279 mask: 0,
280 maskContentUnits: 0,
281 maskUnits: 0,
282 mathematical: 0,
283 mode: 0,
284 numOctaves: 0,
285 offset: 0,
286 opacity: 0,
287 operator: 0,
288 order: 0,
289 orient: 0,
290 orientation: 0,
291 origin: 0,
292 overflow: 0,
293 overlinePosition: 0,
294 overlineThickness: 0,
295 paintOrder: 0,
296 panose1: 0,
297 pathLength: 0,
298 patternContentUnits: 0,
299 patternTransform: 0,
300 patternUnits: 0,
301 pointerEvents: 0,
302 points: 0,
303 pointsAtX: 0,
304 pointsAtY: 0,
305 pointsAtZ: 0,
306 preserveAlpha: 0,
307 preserveAspectRatio: 0,
308 primitiveUnits: 0,
309 r: 0,
310 radius: 0,
311 refX: 0,
312 refY: 0,
313 renderingIntent: 0,
314 repeatCount: 0,
315 repeatDur: 0,
316 requiredExtensions: 0,
317 requiredFeatures: 0,
318 restart: 0,
319 result: 0,
320 rotate: 0,
321 rx: 0,
322 ry: 0,
323 scale: 0,
324 seed: 0,
325 shapeRendering: 0,
326 slope: 0,
327 spacing: 0,
328 specularConstant: 0,
329 specularExponent: 0,
330 speed: 0,
331 spreadMethod: 0,
332 startOffset: 0,
333 stdDeviation: 0,
334 stemh: 0,
335 stemv: 0,
336 stitchTiles: 0,
337 stopColor: 0,
338 stopOpacity: 0,
339 strikethroughPosition: 0,
340 strikethroughThickness: 0,
341 string: 0,
342 stroke: 0,
343 strokeDasharray: 0,
344 strokeDashoffset: 0,
345 strokeLinecap: 0,
346 strokeLinejoin: 0,
347 strokeMiterlimit: 0,
348 strokeOpacity: 0,
349 strokeWidth: 0,
350 surfaceScale: 0,
351 systemLanguage: 0,
352 tableValues: 0,
353 targetX: 0,
354 targetY: 0,
355 textAnchor: 0,
356 textDecoration: 0,
357 textRendering: 0,
358 textLength: 0,
359 to: 0,
360 transform: 0,
361 u1: 0,
362 u2: 0,
363 underlinePosition: 0,
364 underlineThickness: 0,
365 unicode: 0,
366 unicodeBidi: 0,
367 unicodeRange: 0,
368 unitsPerEm: 0,
369 vAlphabetic: 0,
370 vHanging: 0,
371 vIdeographic: 0,
372 vMathematical: 0,
373 values: 0,
374 vectorEffect: 0,
375 version: 0,
376 vertAdvY: 0,
377 vertOriginX: 0,
378 vertOriginY: 0,
379 viewBox: 0,
380 viewTarget: 0,
381 visibility: 0,
382 widths: 0,
383 wordSpacing: 0,
384 writingMode: 0,
385 x: 0,
386 xHeight: 0,
387 x1: 0,
388 x2: 0,
389 xChannelSelector: 0,
390 xlinkActuate: 0,
391 xlinkArcrole: 0,
392 xlinkHref: 0,
393 xlinkRole: 0,
394 xlinkShow: 0,
395 xlinkTitle: 0,
396 xlinkType: 0,
397 xmlBase: 0,
398 xmlns: 0,
399 xmlnsXlink: 0,
400 xmlLang: 0,
401 xmlSpace: 0,
402 y: 0,
403 y1: 0,
404 y2: 0,
405 yChannelSelector: 0,
406 z: 0,
407 zoomAndPan: 0
408 },
409 DOMAttributeNames: {
410 accentHeight: 'accent-height',
411 alignmentBaseline: 'alignment-baseline',
412 arabicForm: 'arabic-form',
413 baselineShift: 'baseline-shift',
414 capHeight: 'cap-height',
415 clipPath: 'clip-path',
416 clipRule: 'clip-rule',
417 colorInterpolation: 'color-interpolation',
418 colorInterpolationFilters: 'color-interpolation-filters',
419 colorProfile: 'color-profile',
420 colorRendering: 'color-rendering',
421 dominantBaseline: 'dominant-baseline',
422 enableBackground: 'enable-background',
423 fillOpacity: 'fill-opacity',
424 fillRule: 'fill-rule',
425 floodColor: 'flood-color',
426 floodOpacity: 'flood-opacity',
427 fontFamily: 'font-family',
428 fontSize: 'font-size',
429 fontSizeAdjust: 'font-size-adjust',
430 fontStretch: 'font-stretch',
431 fontStyle: 'font-style',
432 fontVariant: 'font-variant',
433 fontWeight: 'font-weight',
434 glyphName: 'glyph-name',
435 glyphOrientationHorizontal: 'glyph-orientation-horizontal',
436 glyphOrientationVertical: 'glyph-orientation-vertical',
437 horizAdvX: 'horiz-adv-x',
438 horizOriginX: 'horiz-origin-x',
439 imageRendering: 'image-rendering',
440 letterSpacing: 'letter-spacing',
441 lightingColor: 'lighting-color',
442 markerEnd: 'marker-end',
443 markerMid: 'marker-mid',
444 markerStart: 'marker-start',
445 overlinePosition: 'overline-position',
446 overlineThickness: 'overline-thickness',
447 paintOrder: 'paint-order',
448 panose1: 'panose-1',
449 pointerEvents: 'pointer-events',
450 renderingIntent: 'rendering-intent',
451 shapeRendering: 'shape-rendering',
452 stopColor: 'stop-color',
453 stopOpacity: 'stop-opacity',
454 strikethroughPosition: 'strikethrough-position',
455 strikethroughThickness: 'strikethrough-thickness',
456 strokeDasharray: 'stroke-dasharray',
457 strokeDashoffset: 'stroke-dashoffset',
458 strokeLinecap: 'stroke-linecap',
459 strokeLinejoin: 'stroke-linejoin',
460 strokeMiterlimit: 'stroke-miterlimit',
461 strokeOpacity: 'stroke-opacity',
462 strokeWidth: 'stroke-width',
463 textAnchor: 'text-anchor',
464 textDecoration: 'text-decoration',
465 textRendering: 'text-rendering',
466 underlinePosition: 'underline-position',
467 underlineThickness: 'underline-thickness',
468 unicodeBidi: 'unicode-bidi',
469 unicodeRange: 'unicode-range',
470 unitsPerEm: 'units-per-em',
471 vAlphabetic: 'v-alphabetic',
472 vHanging: 'v-hanging',
473 vIdeographic: 'v-ideographic',
474 vMathematical: 'v-mathematical',
475 vectorEffect: 'vector-effect',
476 vertAdvY: 'vert-adv-y',
477 vertOriginX: 'vert-origin-x',
478 vertOriginY: 'vert-origin-y',
479 wordSpacing: 'word-spacing',
480 writingMode: 'writing-mode',
481 xHeight: 'x-height',
482 xlinkActuate: 'xlink:actuate',
483 xlinkArcrole: 'xlink:arcrole',
484 xlinkHref: 'xlink:href',
485 xlinkRole: 'xlink:role',
486 xlinkShow: 'xlink:show',
487 xlinkTitle: 'xlink:title',
488 xlinkType: 'xlink:type',
489 xmlBase: 'xml:base',
490 xmlnsXlink: 'xmlns:xlink',
491 xmlLang: 'xml:lang',
492 xmlSpace: 'xml:space'
493 }
494 };
495
496 var injection = {
497 MUST_USE_PROPERTY: 1,
498 HAS_BOOLEAN_VALUE: 4,
499 HAS_NUMERIC_VALUE: 8,
500 HAS_POSITIVE_NUMERIC_VALUE: 24,
501 HAS_OVERLOADED_BOOLEAN_VALUE: 32
502 };
503
504 var MUST_USE_PROPERTY = injection.MUST_USE_PROPERTY;
505 var HAS_BOOLEAN_VALUE = injection.HAS_BOOLEAN_VALUE;
506 var HAS_NUMERIC_VALUE = injection.HAS_NUMERIC_VALUE;
507 var HAS_POSITIVE_NUMERIC_VALUE = injection.HAS_POSITIVE_NUMERIC_VALUE;
508 var HAS_OVERLOADED_BOOLEAN_VALUE = injection.HAS_OVERLOADED_BOOLEAN_VALUE;
509
510 /**
511 * @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L14-L16
512 *
513 * @param {Number} value
514 * @param {Number} bitmask
515 * @return {Boolean}
516 */
517 function checkMask(value, bitmask) {
518 return (value & bitmask) === bitmask;
519 }
520
521 /**
522 * @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L57
523 *
524 * @param {Object} domPropertyConfig - HTMLDOMPropertyConfig or SVGDOMPropertyConfig
525 * @param {Object} config - The object to be mutated
526 * @param {Boolean} isSVG - Whether the injected config is HTML or SVG (it assumes the default is HTML)
527 */
528 function injectDOMPropertyConfig(domPropertyConfig, config, isSVG) {
529 var Properties = domPropertyConfig.Properties;
530 var DOMAttributeNames = domPropertyConfig.DOMAttributeNames;
531 var attributeName;
532 var propertyName;
533 var propConfig;
534
535 for (propertyName in Properties) {
536 attributeName =
537 DOMAttributeNames[propertyName] ||
538 (isSVG ? propertyName : propertyName.toLowerCase());
539 propConfig = Properties[propertyName];
540
541 config[attributeName] = {
542 attributeName: attributeName,
543 propertyName: propertyName,
544 mustUseProperty: checkMask(propConfig, MUST_USE_PROPERTY),
545 hasBooleanValue: checkMask(propConfig, HAS_BOOLEAN_VALUE),
546 hasNumericValue: checkMask(propConfig, HAS_NUMERIC_VALUE),
547 hasPositiveNumericValue: checkMask(
548 propConfig,
549 HAS_POSITIVE_NUMERIC_VALUE
550 ),
551 hasOverloadedBooleanValue: checkMask(
552 propConfig,
553 HAS_OVERLOADED_BOOLEAN_VALUE
554 )
555 };
556 }
557 }
558
559 /**
560 * HTML properties config.
561 *
562 * @type {Object}
563 */
564 var html = {};
565 injectDOMPropertyConfig(HTMLDOMPropertyConfig, html);
566
567 /**
568 * SVG properties config.
569 *
570 * @type {Object}
571 */
572 var svg = {};
573 injectDOMPropertyConfig(SVGDOMPropertyConfig, svg, true);
574
575 /**
576 * HTML and SVG properties config.
577 *
578 * @type {Object}
579 */
580 var properties = {};
581 injectDOMPropertyConfig(HTMLDOMPropertyConfig, properties);
582 injectDOMPropertyConfig(SVGDOMPropertyConfig, properties, true);
583
584 var ATTRIBUTE_NAME_START_CHAR =
585 ':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';
586 var ATTRIBUTE_NAME_CHAR =
587 ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
588
589 var reactProperty = {
590 html: html,
591 svg: svg,
592 properties: properties,
593
594 /**
595 * Checks whether a property name is a custom attribute.
596 *
597 * @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L23-L25
598 *
599 * @param {String}
600 * @return {Boolean}
601 */
602 isCustomAttribute: RegExp.prototype.test.bind(
603 new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$')
604 )
605 };
606
607 // http://www.w3.org/TR/CSS21/grammar.html
608 // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
609 var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
610
611 var NEWLINE_REGEX = /\n/g;
612 var WHITESPACE_REGEX = /^\s*/;
613
614 // declaration
615 var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
616 var COLON_REGEX = /^:\s*/;
617 var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
618 var SEMICOLON_REGEX = /^[;\s]*/;
619
620 // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
621 var TRIM_REGEX = /^\s+|\s+$/g;
622
623 // strings
624 var NEWLINE = '\n';
625 var FORWARD_SLASH = '/';
626 var ASTERISK = '*';
627 var EMPTY_STRING = '';
628
629 // types
630 var TYPE_COMMENT = 'comment';
631 var TYPE_DECLARATION = 'declaration';
632
633 /**
634 * @param {String} style
635 * @param {Object} [options]
636 * @return {Object[]}
637 * @throws {TypeError}
638 * @throws {Error}
639 */
640 var inlineStyleParser = function(style, options) {
641 if (typeof style !== 'string') {
642 throw new TypeError('First argument must be a string');
643 }
644
645 if (!style) return [];
646
647 options = options || {};
648
649 /**
650 * Positional.
651 */
652 var lineno = 1;
653 var column = 1;
654
655 /**
656 * Update lineno and column based on `str`.
657 *
658 * @param {String} str
659 */
660 function updatePosition(str) {
661 var lines = str.match(NEWLINE_REGEX);
662 if (lines) lineno += lines.length;
663 var i = str.lastIndexOf(NEWLINE);
664 column = ~i ? str.length - i : column + str.length;
665 }
666
667 /**
668 * Mark position and patch `node.position`.
669 *
670 * @return {Function}
671 */
672 function position() {
673 var start = { line: lineno, column: column };
674 return function(node) {
675 node.position = new Position(start);
676 whitespace();
677 return node;
678 };
679 }
680
681 /**
682 * Store position information for a node.
683 *
684 * @constructor
685 * @property {Object} start
686 * @property {Object} end
687 * @property {undefined|String} source
688 */
689 function Position(start) {
690 this.start = start;
691 this.end = { line: lineno, column: column };
692 this.source = options.source;
693 }
694
695 /**
696 * Non-enumerable source string.
697 */
698 Position.prototype.content = style;
699
700 /**
701 * Error `msg`.
702 *
703 * @param {String} msg
704 * @throws {Error}
705 */
706 function error(msg) {
707 var err = new Error(
708 options.source + ':' + lineno + ':' + column + ': ' + msg
709 );
710 err.reason = msg;
711 err.filename = options.source;
712 err.line = lineno;
713 err.column = column;
714 err.source = style;
715
716 if (options.silent) ; else {
717 throw err;
718 }
719 }
720
721 /**
722 * Match `re` and return captures.
723 *
724 * @param {RegExp} re
725 * @return {undefined|Array}
726 */
727 function match(re) {
728 var m = re.exec(style);
729 if (!m) return;
730 var str = m[0];
731 updatePosition(str);
732 style = style.slice(str.length);
733 return m;
734 }
735
736 /**
737 * Parse whitespace.
738 */
739 function whitespace() {
740 match(WHITESPACE_REGEX);
741 }
742
743 /**
744 * Parse comments.
745 *
746 * @param {Object[]} [rules]
747 * @return {Object[]}
748 */
749 function comments(rules) {
750 var c;
751 rules = rules || [];
752 while ((c = comment())) {
753 if (c !== false) {
754 rules.push(c);
755 }
756 }
757 return rules;
758 }
759
760 /**
761 * Parse comment.
762 *
763 * @return {Object}
764 * @throws {Error}
765 */
766 function comment() {
767 var pos = position();
768 if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
769
770 var i = 2;
771 while (
772 EMPTY_STRING != style.charAt(i) &&
773 (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
774 ) {
775 ++i;
776 }
777 i += 2;
778
779 if (EMPTY_STRING === style.charAt(i - 1)) {
780 return error('End of comment missing');
781 }
782
783 var str = style.slice(2, i - 2);
784 column += 2;
785 updatePosition(str);
786 style = style.slice(i);
787 column += 2;
788
789 return pos({
790 type: TYPE_COMMENT,
791 comment: str
792 });
793 }
794
795 /**
796 * Parse declaration.
797 *
798 * @return {Object}
799 * @throws {Error}
800 */
801 function declaration() {
802 var pos = position();
803
804 // prop
805 var prop = match(PROPERTY_REGEX);
806 if (!prop) return;
807 comment();
808
809 // :
810 if (!match(COLON_REGEX)) return error("property missing ':'");
811
812 // val
813 var val = match(VALUE_REGEX);
814
815 var ret = pos({
816 type: TYPE_DECLARATION,
817 property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
818 value: val
819 ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
820 : EMPTY_STRING
821 });
822
823 // ;
824 match(SEMICOLON_REGEX);
825
826 return ret;
827 }
828
829 /**
830 * Parse declarations.
831 *
832 * @return {Object[]}
833 */
834 function declarations() {
835 var decls = [];
836
837 comments(decls);
838
839 // declarations
840 var decl;
841 while ((decl = declaration())) {
842 if (decl !== false) {
843 decls.push(decl);
844 comments(decls);
845 }
846 }
847
848 return decls;
849 }
850
851 whitespace();
852 return declarations();
853 };
854
855 /**
856 * Trim `str`.
857 *
858 * @param {String} str
859 * @return {String}
860 */
861 function trim(str) {
862 return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
863 }
864
865 /**
866 * Parses inline style to object.
867 *
868 * @example
869 * // returns { 'line-height': '42' }
870 * StyleToObject('line-height: 42;');
871 *
872 * @param {String} style - The inline style.
873 * @param {Function} [iterator] - The iterator function.
874 * @return {null|Object}
875 */
876 function StyleToObject(style, iterator) {
877 var output = null;
878 if (!style || typeof style !== 'string') {
879 return output;
880 }
881
882 var declaration;
883 var declarations = inlineStyleParser(style);
884 var hasIterator = typeof iterator === 'function';
885 var property;
886 var value;
887
888 for (var i = 0, len = declarations.length; i < len; i++) {
889 declaration = declarations[i];
890 property = declaration.property;
891 value = declaration.value;
892
893 if (hasIterator) {
894 iterator(property, value, declaration);
895 } else if (value) {
896 output || (output = {});
897 output[property] = value;
898 }
899 }
900
901 return output;
902 }
903
904 var styleToObject = StyleToObject;
905
906 var hyphenPatternRegex = /-([a-z])/g;
907 var CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX = /^--[a-zA-Z0-9-]+$|^[^-]+$/;
908
909 /**
910 * Converts a string to camelCase.
911 *
912 * @param {String} string - The string.
913 * @return {String}
914 */
915 function camelCase(string) {
916 if (typeof string !== 'string') {
917 throw new TypeError('First argument must be a string');
918 }
919
920 // custom property or no hyphen found
921 if (CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX.test(string)) {
922 return string;
923 }
924
925 // convert to camelCase
926 return string
927 .toLowerCase()
928 .replace(hyphenPatternRegex, function(_, character) {
929 return character.toUpperCase();
930 });
931 }
932
933 /**
934 * Swap key with value in an object.
935 *
936 * @param {Object} obj - The object.
937 * @param {Function} [override] - The override method.
938 * @return {Object} - The inverted object.
939 */
940 function invertObject(obj, override) {
941 if (!obj || typeof obj !== 'object') {
942 throw new TypeError('First argument must be an object');
943 }
944
945 var key;
946 var value;
947 var isOverridePresent = typeof override === 'function';
948 var overrides = {};
949 var result = {};
950
951 for (key in obj) {
952 value = obj[key];
953
954 if (isOverridePresent) {
955 overrides = override(key, value);
956 if (overrides && overrides.length === 2) {
957 result[overrides[0]] = overrides[1];
958 continue;
959 }
960 }
961
962 if (typeof value === 'string') {
963 result[value] = key;
964 }
965 }
966
967 return result;
968 }
969
970 /**
971 * Check if a given tag is a custom component.
972 *
973 * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
974 *
975 * @param {string} tagName - The name of the html tag.
976 * @param {Object} props - The props being passed to the element.
977 * @return {boolean}
978 */
979 function isCustomComponent(tagName, props) {
980 if (tagName.indexOf('-') === -1) {
981 return props && typeof props.is === 'string';
982 }
983
984 switch (tagName) {
985 // These are reserved SVG and MathML elements.
986 // We don't mind this whitelist too much because we expect it to never grow.
987 // The alternative is to track the namespace in a few places which is convoluted.
988 // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
989 case 'annotation-xml':
990 case 'color-profile':
991 case 'font-face':
992 case 'font-face-src':
993 case 'font-face-uri':
994 case 'font-face-format':
995 case 'font-face-name':
996 case 'missing-glyph':
997 return false;
998 default:
999 return true;
1000 }
1001 }
1002
1003 /**
1004 * @constant {Boolean}
1005 * @see {@link https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html}
1006 */
1007 var PRESERVE_CUSTOM_ATTRIBUTES = react.version.split('.')[0] >= 16;
1008
1009 var utilities = {
1010 PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
1011 camelCase: camelCase,
1012 invertObject: invertObject,
1013 isCustomComponent: isCustomComponent
1014 };
1015
1016 var camelCase$1 = utilities.camelCase;
1017
1018 var htmlProperties = reactProperty.html;
1019 var svgProperties = reactProperty.svg;
1020 var isCustomAttribute = reactProperty.isCustomAttribute;
1021
1022 var hasOwnProperty = Object.prototype.hasOwnProperty;
1023
1024 /**
1025 * Converts HTML/SVG DOM attributes to React props.
1026 *
1027 * @param {Object} [attributes={}] - The HTML/SVG DOM attributes.
1028 * @return {Object} - The React props.
1029 */
1030 function attributesToProps(attributes) {
1031 attributes = attributes || {};
1032
1033 var attributeName;
1034 var attributeNameLowerCased;
1035 var attributeValue;
1036 var property;
1037 var props = {};
1038
1039 for (attributeName in attributes) {
1040 attributeValue = attributes[attributeName];
1041
1042 // ARIA (aria-*) or custom data (data-*) attribute
1043 if (isCustomAttribute(attributeName)) {
1044 props[attributeName] = attributeValue;
1045 continue;
1046 }
1047
1048 // convert HTML attribute to React prop
1049 attributeNameLowerCased = attributeName.toLowerCase();
1050 if (hasOwnProperty.call(htmlProperties, attributeNameLowerCased)) {
1051 property = htmlProperties[attributeNameLowerCased];
1052 props[property.propertyName] =
1053 property.hasBooleanValue ||
1054 (property.hasOverloadedBooleanValue && !attributeValue)
1055 ? true
1056 : attributeValue;
1057 continue;
1058 }
1059
1060 // convert SVG attribute to React prop
1061 if (hasOwnProperty.call(svgProperties, attributeName)) {
1062 property = svgProperties[attributeName];
1063 props[property.propertyName] = attributeValue;
1064 continue;
1065 }
1066
1067 // preserve custom attribute if React >=16
1068 if (utilities.PRESERVE_CUSTOM_ATTRIBUTES) {
1069 props[attributeName] = attributeValue;
1070 }
1071 }
1072
1073 // convert inline style to object
1074 if (attributes.style != null) {
1075 props.style = cssToJs(attributes.style);
1076 }
1077
1078 return props;
1079 }
1080
1081 /**
1082 * Converts CSS style string to JS style object.
1083 *
1084 * @param {String} style - The CSS style.
1085 * @return {Object} - The JS style object.
1086 */
1087 function cssToJs(style) {
1088 if (typeof style !== 'string') {
1089 throw new TypeError('First argument must be a string.');
1090 }
1091
1092 var styleObj = {};
1093
1094 styleToObject(style, function(property, value) {
1095 // skip if it's a comment node
1096 if (property && value) {
1097 styleObj[camelCase$1(property)] = value;
1098 }
1099 });
1100
1101 return styleObj;
1102 }
1103
1104 var attributesToProps_1 = attributesToProps;
1105
1106 /**
1107 * Converts DOM nodes to React elements.
1108 *
1109 * @param {Array} nodes - The DOM nodes.
1110 * @param {Object} [options] - The additional options.
1111 * @param {Function} [options.replace] - The replace method.
1112 * @return {ReactElement|Array}
1113 */
1114 function domToReact(nodes, options) {
1115 options = options || {};
1116
1117 var React = options.library || react;
1118 var cloneElement = React.cloneElement;
1119 var createElement = React.createElement;
1120 var isValidElement = React.isValidElement;
1121
1122 var result = [];
1123 var node;
1124 var hasReplace = typeof options.replace === 'function';
1125 var replaceElement;
1126 var props;
1127 var children;
1128
1129 for (var i = 0, len = nodes.length; i < len; i++) {
1130 node = nodes[i];
1131
1132 // replace with custom React element (if present)
1133 if (hasReplace) {
1134 replaceElement = options.replace(node);
1135
1136 if (isValidElement(replaceElement)) {
1137 // specify a "key" prop if element has siblings
1138 // https://fb.me/react-warning-keys
1139 if (len > 1) {
1140 replaceElement = cloneElement(replaceElement, {
1141 key: replaceElement.key || i
1142 });
1143 }
1144 result.push(replaceElement);
1145 continue;
1146 }
1147 }
1148
1149 if (node.type === 'text') {
1150 result.push(node.data);
1151 continue;
1152 }
1153
1154 props = node.attribs;
1155 if (!shouldPassAttributesUnaltered(node)) {
1156 // update values
1157 props = attributesToProps_1(node.attribs);
1158 }
1159
1160 children = null;
1161
1162 // node type for <script> is "script"
1163 // node type for <style> is "style"
1164 if (node.type === 'script' || node.type === 'style') {
1165 // prevent text in <script> or <style> from being escaped
1166 // https://facebook.github.io/react/tips/dangerously-set-inner-html.html
1167 if (node.children[0]) {
1168 props.dangerouslySetInnerHTML = {
1169 __html: node.children[0].data
1170 };
1171 }
1172 } else if (node.type === 'tag') {
1173 // setting textarea value in children is an antipattern in React
1174 // https://reactjs.org/docs/forms.html#the-textarea-tag
1175 if (node.name === 'textarea' && node.children[0]) {
1176 props.defaultValue = node.children[0].data;
1177
1178 // continue recursion of creating React elements (if applicable)
1179 } else if (node.children && node.children.length) {
1180 children = domToReact(node.children, options);
1181 }
1182
1183 // skip all other cases (e.g., comment)
1184 } else {
1185 continue;
1186 }
1187
1188 // specify a "key" prop if element has siblings
1189 // https://fb.me/react-warning-keys
1190 if (len > 1) {
1191 props.key = i;
1192 }
1193
1194 result.push(createElement(node.name, props, children));
1195 }
1196
1197 return result.length === 1 ? result[0] : result;
1198 }
1199
1200 function shouldPassAttributesUnaltered(node) {
1201 return (
1202 utilities.PRESERVE_CUSTOM_ATTRIBUTES &&
1203 node.type === 'tag' &&
1204 utilities.isCustomComponent(node.name, node.attribs)
1205 );
1206 }
1207
1208 var domToReact_1 = domToReact;
1209
1210 /**
1211 * SVG elements are case-sensitive.
1212 *
1213 * @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
1214 */
1215 var CASE_SENSITIVE_TAG_NAMES = [
1216 'animateMotion',
1217 'animateTransform',
1218 'clipPath',
1219 'feBlend',
1220 'feColorMatrix',
1221 'feComponentTransfer',
1222 'feComposite',
1223 'feConvolveMatrix',
1224 'feDiffuseLighting',
1225 'feDisplacementMap',
1226 'feDropShadow',
1227 'feFlood',
1228 'feFuncA',
1229 'feFuncB',
1230 'feFuncG',
1231 'feFuncR',
1232 'feGaussainBlur',
1233 'feImage',
1234 'feMerge',
1235 'feMergeNode',
1236 'feMorphology',
1237 'feOffset',
1238 'fePointLight',
1239 'feSpecularLighting',
1240 'feSpotLight',
1241 'feTile',
1242 'feTurbulence',
1243 'foreignObject',
1244 'linearGradient',
1245 'radialGradient',
1246 'textPath'
1247 ];
1248
1249 var constants = {
1250 CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
1251 };
1252
1253 var CASE_SENSITIVE_TAG_NAMES$1 = constants.CASE_SENSITIVE_TAG_NAMES;
1254
1255 var caseSensitiveTagNamesMap = {};
1256 var tagName;
1257 for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES$1.length; i < len; i++) {
1258 tagName = CASE_SENSITIVE_TAG_NAMES$1[i];
1259 caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
1260 }
1261
1262 /**
1263 * Gets case-sensitive tag name.
1264 *
1265 * @param {String} tagName - The lowercase tag name.
1266 * @return {String|undefined}
1267 */
1268 function getCaseSensitiveTagName(tagName) {
1269 return caseSensitiveTagNamesMap[tagName];
1270 }
1271
1272 /**
1273 * Formats DOM attributes to a hash map.
1274 *
1275 * @param {NamedNodeMap} attributes - The list of attributes.
1276 * @return {Object} - A map of attribute name to value.
1277 */
1278 function formatAttributes(attributes) {
1279 var result = {};
1280 var attribute;
1281 // `NamedNodeMap` is array-like
1282 for (var i = 0, len = attributes.length; i < len; i++) {
1283 attribute = attributes[i];
1284 result[attribute.name] = attribute.value;
1285 }
1286 return result;
1287 }
1288
1289 /**
1290 * Corrects the tag name if it is case-sensitive (SVG).
1291 * Otherwise, returns the lowercase tag name (HTML).
1292 *
1293 * @param {String} tagName - The lowercase tag name.
1294 * @return {String} - The formatted tag name.
1295 */
1296 function formatTagName(tagName) {
1297 tagName = tagName.toLowerCase();
1298 var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
1299 if (caseSensitiveTagName) {
1300 return caseSensitiveTagName;
1301 }
1302 return tagName;
1303 }
1304
1305 /**
1306 * Formats the browser DOM nodes to mimic the output of `htmlparser2.parseDOM()`.
1307 *
1308 * @param {NodeList} nodes - The DOM nodes.
1309 * @param {Object} [parentObj] - The formatted parent node.
1310 * @param {String} [directive] - The directive.
1311 * @return {Object[]} - The formatted DOM object.
1312 */
1313 function formatDOM(nodes, parentObj, directive) {
1314 parentObj = parentObj || null;
1315
1316 var result = [];
1317 var node;
1318 var prevNode;
1319 var nodeObj;
1320
1321 // `NodeList` is array-like
1322 for (var i = 0, len = nodes.length; i < len; i++) {
1323 node = nodes[i];
1324 // reset
1325 nodeObj = {
1326 next: null,
1327 prev: result[i - 1] || null,
1328 parent: parentObj
1329 };
1330
1331 // set the next node for the previous node (if applicable)
1332 prevNode = result[i - 1];
1333 if (prevNode) {
1334 prevNode.next = nodeObj;
1335 }
1336
1337 // set the node name if it's not "#text" or "#comment"
1338 // e.g., "div"
1339 if (node.nodeName[0] !== '#') {
1340 nodeObj.name = formatTagName(node.nodeName);
1341 // also, nodes of type "tag" have "attribs"
1342 nodeObj.attribs = {}; // default
1343 if (node.attributes && node.attributes.length) {
1344 nodeObj.attribs = formatAttributes(node.attributes);
1345 }
1346 }
1347
1348 // set the node type
1349 // e.g., "tag"
1350 switch (node.nodeType) {
1351 // 1 = element
1352 case 1:
1353 if (nodeObj.name === 'script' || nodeObj.name === 'style') {
1354 nodeObj.type = nodeObj.name;
1355 } else {
1356 nodeObj.type = 'tag';
1357 }
1358 // recursively format the children
1359 nodeObj.children = formatDOM(node.childNodes, nodeObj);
1360 break;
1361 // 2 = attribute
1362 // 3 = text
1363 case 3:
1364 nodeObj.type = 'text';
1365 nodeObj.data = node.nodeValue;
1366 break;
1367 // 8 = comment
1368 case 8:
1369 nodeObj.type = 'comment';
1370 nodeObj.data = node.nodeValue;
1371 break;
1372 }
1373
1374 result.push(nodeObj);
1375 }
1376
1377 if (directive) {
1378 result.unshift({
1379 name: directive.substring(0, directive.indexOf(' ')).toLowerCase(),
1380 data: directive,
1381 type: 'directive',
1382 next: result[0] ? result[0] : null,
1383 prev: null,
1384 parent: parentObj
1385 });
1386
1387 if (result[1]) {
1388 result[1].prev = result[0];
1389 }
1390 }
1391
1392 return result;
1393 }
1394
1395 /**
1396 * Detects IE with or without version.
1397 *
1398 * @param {Number} [version] - The IE version to detect.
1399 * @return {Boolean} - Whether IE or the version has been detected.
1400 */
1401 function isIE(version) {
1402 if (version) {
1403 return document.documentMode === version;
1404 }
1405 return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
1406 }
1407
1408 var utilities$1 = {
1409 formatAttributes: formatAttributes,
1410 formatDOM: formatDOM,
1411 isIE: isIE
1412 };
1413
1414 // constants
1415 var HTML = 'html';
1416 var HEAD = 'head';
1417 var BODY = 'body';
1418 var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
1419 var HEAD_TAG_REGEX = /<head.*>/i;
1420 var BODY_TAG_REGEX = /<body.*>/i;
1421 // http://www.w3.org/TR/html/syntax.html#void-elements
1422 var VOID_ELEMENTS_REGEX = /<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\/?>/gi;
1423
1424 // detect IE browser
1425 var isIE9 = utilities$1.isIE(9);
1426 var isIE$1 = isIE9 || utilities$1.isIE();
1427
1428 /**
1429 * DOMParser (performance: slow).
1430 *
1431 * @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
1432 */
1433 var parseFromString;
1434
1435 if (typeof window.DOMParser === 'function') {
1436 var domParser = new window.DOMParser();
1437
1438 // IE9 does not support 'text/html' MIME type
1439 // https://msdn.microsoft.com/en-us/library/ff975278(v=vs.85).aspx
1440 var mimeType = isIE9 ? 'text/xml' : 'text/html';
1441
1442 /**
1443 * Creates an HTML document using `DOMParser.parseFromString`.
1444 *
1445 * @param {string} html - The HTML string.
1446 * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
1447 * @return {HTMLDocument}
1448 */
1449 parseFromString = function domStringParser(html, tagName) {
1450 if (tagName) {
1451 html = '<' + tagName + '>' + html + '</' + tagName + '>';
1452 }
1453
1454 // because IE9 only supports MIME type 'text/xml', void elements need to be self-closed
1455 if (isIE9) {
1456 html = html.replace(VOID_ELEMENTS_REGEX, '<$1$2$3/>');
1457 }
1458
1459 return domParser.parseFromString(html, mimeType);
1460 };
1461 }
1462
1463 /**
1464 * DOMImplementation (performance: fair).
1465 *
1466 * @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
1467 */
1468 var parseFromDocument;
1469
1470 if (typeof document.implementation === 'object') {
1471 // title parameter is required in IE
1472 // https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
1473 var doc = document.implementation.createHTMLDocument(
1474 isIE$1 ? 'HTML_DOM_PARSER_TITLE' : undefined
1475 );
1476
1477 /**
1478 * Use HTML document created by `document.implementation.createHTMLDocument`.
1479 *
1480 * @param {string} html - The HTML string.
1481 * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
1482 * @return {HTMLDocument}
1483 */
1484 parseFromDocument = function createHTMLDocument(html, tagName) {
1485 if (tagName) {
1486 doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
1487 return doc;
1488 }
1489
1490 try {
1491 doc.documentElement.innerHTML = html;
1492 return doc;
1493 // fallback when certain elements in `documentElement` are read-only (IE9)
1494 } catch (err) {
1495 if (parseFromString) {
1496 return parseFromString(html);
1497 }
1498 }
1499 };
1500 }
1501
1502 /**
1503 * Template (performance: fast).
1504 *
1505 * @see https://developer.mozilla.org/docs/Web/HTML/Element/template
1506 */
1507 var parseFromTemplate;
1508 var template = document.createElement('template');
1509
1510 if (template.content) {
1511 /**
1512 * Uses a template element (content fragment) to parse HTML.
1513 *
1514 * @param {string} html - The HTML string.
1515 * @return {NodeList}
1516 */
1517 parseFromTemplate = function templateParser(html) {
1518 template.innerHTML = html;
1519 return template.content.childNodes;
1520 };
1521 }
1522
1523 // fallback document parser
1524 var parseWithFallback = parseFromDocument || parseFromString;
1525
1526 /**
1527 * Parses HTML string to DOM nodes.
1528 *
1529 * @param {string} html - The HTML string.
1530 * @return {NodeList|Array}
1531 */
1532 function domparser(html) {
1533 var firstTagName;
1534 var match = html.match(FIRST_TAG_REGEX);
1535
1536 if (match && match[1]) {
1537 firstTagName = match[1].toLowerCase();
1538 }
1539
1540 var doc;
1541 var element;
1542 var elements;
1543
1544 switch (firstTagName) {
1545 case HTML:
1546 if (parseFromString) {
1547 doc = parseFromString(html);
1548
1549 // the created document may come with filler head/body elements,
1550 // so make sure to remove them if they don't actually exist
1551 if (!HEAD_TAG_REGEX.test(html)) {
1552 element = doc.getElementsByTagName(HEAD)[0];
1553 if (element) {
1554 element.parentNode.removeChild(element);
1555 }
1556 }
1557
1558 if (!BODY_TAG_REGEX.test(html)) {
1559 element = doc.getElementsByTagName(BODY)[0];
1560 if (element) {
1561 element.parentNode.removeChild(element);
1562 }
1563 }
1564
1565 return doc.getElementsByTagName(HTML);
1566 }
1567 break;
1568
1569 case HEAD:
1570 case BODY:
1571 if (parseWithFallback) {
1572 elements = parseWithFallback(html).getElementsByTagName(firstTagName);
1573
1574 // account for possibility of sibling
1575 if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
1576 return elements[0].parentNode.childNodes;
1577 }
1578
1579 return elements;
1580 }
1581 break;
1582
1583 // low-level tag or text
1584 default:
1585 if (parseFromTemplate) {
1586 return parseFromTemplate(html);
1587 }
1588
1589 if (parseWithFallback) {
1590 return parseWithFallback(html, BODY).getElementsByTagName(BODY)[0]
1591 .childNodes;
1592 }
1593
1594 break;
1595 }
1596
1597 return [];
1598 }
1599
1600 var domparser_1 = domparser;
1601
1602 var formatDOM$1 = utilities$1.formatDOM;
1603 var isIE9$1 = utilities$1.isIE(9);
1604
1605 var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
1606
1607 /**
1608 * Parses HTML and reformats DOM nodes output.
1609 *
1610 * @param {String} html - The HTML string.
1611 * @return {Array} - The formatted DOM nodes.
1612 */
1613 function parseDOM(html) {
1614 if (typeof html !== 'string') {
1615 throw new TypeError('First argument must be a string');
1616 }
1617
1618 if (!html) {
1619 return [];
1620 }
1621
1622 // match directive
1623 var match = html.match(DIRECTIVE_REGEX);
1624 var directive;
1625
1626 if (match && match[1]) {
1627 directive = match[1];
1628
1629 // remove directive in IE9 because DOMParser uses
1630 // MIME type 'text/xml' instead of 'text/html'
1631 if (isIE9$1) {
1632 html = html.replace(match[0], '');
1633 }
1634 }
1635
1636 return formatDOM$1(domparser_1(html), null, directive);
1637 }
1638
1639 var htmlToDomClient = parseDOM;
1640
1641 /**
1642 * Converts HTML string to React elements.
1643 *
1644 * @param {String} html - The HTML string to parse to React.
1645 * @param {Object} [options] - The parser options.
1646 * @param {Function} [options.replace] - The replace method.
1647 * @return {ReactElement|Array|String} - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
1648 */
1649 function HTMLReactParser(html, options) {
1650 if (typeof html !== 'string') {
1651 throw new TypeError('First argument must be a string');
1652 }
1653 return domToReact_1(htmlToDomClient(html), options);
1654 }
1655
1656 HTMLReactParser.domToReact = domToReact_1;
1657 HTMLReactParser.htmlToDOM = htmlToDomClient;
1658
1659 var htmlReactParser = HTMLReactParser;
1660
1661 return htmlReactParser;
1662
1663})));