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 (React) { 'use strict';
|
6 |
|
7 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
8 |
|
9 | var React__default = _interopDefaultLegacy(React);
|
10 |
|
11 | var HTMLDOMPropertyConfig = {
|
12 | Properties: {
|
13 | autoFocus: 4,
|
14 | accept: 0,
|
15 | acceptCharset: 0,
|
16 | accessKey: 0,
|
17 | action: 0,
|
18 | allowFullScreen: 4,
|
19 | allowTransparency: 0,
|
20 | alt: 0,
|
21 | as: 0,
|
22 | async: 4,
|
23 | autoComplete: 0,
|
24 | autoPlay: 4,
|
25 | capture: 4,
|
26 | cellPadding: 0,
|
27 | cellSpacing: 0,
|
28 | charSet: 0,
|
29 | challenge: 0,
|
30 | checked: 5,
|
31 | cite: 0,
|
32 | classID: 0,
|
33 | className: 0,
|
34 | cols: 24,
|
35 | colSpan: 0,
|
36 | content: 0,
|
37 | contentEditable: 0,
|
38 | contextMenu: 0,
|
39 | controls: 4,
|
40 | controlsList: 0,
|
41 | coords: 0,
|
42 | crossOrigin: 0,
|
43 | data: 0,
|
44 | dateTime: 0,
|
45 | default: 4,
|
46 | defer: 4,
|
47 | dir: 0,
|
48 | disabled: 4,
|
49 | download: 32,
|
50 | draggable: 0,
|
51 | encType: 0,
|
52 | form: 0,
|
53 | formAction: 0,
|
54 | formEncType: 0,
|
55 | formMethod: 0,
|
56 | formNoValidate: 4,
|
57 | formTarget: 0,
|
58 | frameBorder: 0,
|
59 | headers: 0,
|
60 | height: 0,
|
61 | hidden: 4,
|
62 | high: 0,
|
63 | href: 0,
|
64 | hrefLang: 0,
|
65 | htmlFor: 0,
|
66 | httpEquiv: 0,
|
67 | icon: 0,
|
68 | id: 0,
|
69 | inputMode: 0,
|
70 | integrity: 0,
|
71 | is: 0,
|
72 | keyParams: 0,
|
73 | keyType: 0,
|
74 | kind: 0,
|
75 | label: 0,
|
76 | lang: 0,
|
77 | list: 0,
|
78 | loop: 4,
|
79 | low: 0,
|
80 | manifest: 0,
|
81 | marginHeight: 0,
|
82 | marginWidth: 0,
|
83 | max: 0,
|
84 | maxLength: 0,
|
85 | media: 0,
|
86 | mediaGroup: 0,
|
87 | method: 0,
|
88 | min: 0,
|
89 | minLength: 0,
|
90 | multiple: 5,
|
91 | muted: 5,
|
92 | name: 0,
|
93 | nonce: 0,
|
94 | noValidate: 4,
|
95 | open: 4,
|
96 | optimum: 0,
|
97 | pattern: 0,
|
98 | placeholder: 0,
|
99 | playsInline: 4,
|
100 | poster: 0,
|
101 | preload: 0,
|
102 | profile: 0,
|
103 | radioGroup: 0,
|
104 | readOnly: 4,
|
105 | referrerPolicy: 0,
|
106 | rel: 0,
|
107 | required: 4,
|
108 | reversed: 4,
|
109 | role: 0,
|
110 | rows: 24,
|
111 | rowSpan: 8,
|
112 | sandbox: 0,
|
113 | scope: 0,
|
114 | scoped: 4,
|
115 | scrolling: 0,
|
116 | seamless: 4,
|
117 | selected: 5,
|
118 | shape: 0,
|
119 | size: 24,
|
120 | sizes: 0,
|
121 | span: 24,
|
122 | spellCheck: 0,
|
123 | src: 0,
|
124 | srcDoc: 0,
|
125 | srcLang: 0,
|
126 | srcSet: 0,
|
127 | start: 8,
|
128 | step: 0,
|
129 | style: 0,
|
130 | summary: 0,
|
131 | tabIndex: 0,
|
132 | target: 0,
|
133 | title: 0,
|
134 | type: 0,
|
135 | useMap: 0,
|
136 | value: 0,
|
137 | width: 0,
|
138 | wmode: 0,
|
139 | wrap: 0,
|
140 | about: 0,
|
141 | datatype: 0,
|
142 | inlist: 0,
|
143 | prefix: 0,
|
144 | property: 0,
|
145 | resource: 0,
|
146 | typeof: 0,
|
147 | vocab: 0,
|
148 | autoCapitalize: 0,
|
149 | autoCorrect: 0,
|
150 | autoSave: 0,
|
151 | color: 0,
|
152 | itemProp: 0,
|
153 | itemScope: 4,
|
154 | itemType: 0,
|
155 | itemID: 0,
|
156 | itemRef: 0,
|
157 | results: 0,
|
158 | security: 0,
|
159 | unselectable: 0
|
160 | },
|
161 | DOMAttributeNames: {
|
162 | acceptCharset: 'accept-charset',
|
163 | className: 'class',
|
164 | htmlFor: 'for',
|
165 | httpEquiv: 'http-equiv'
|
166 | }
|
167 | };
|
168 |
|
169 | var SVGDOMPropertyConfig = {
|
170 | Properties: {
|
171 | accentHeight: 0,
|
172 | accumulate: 0,
|
173 | additive: 0,
|
174 | alignmentBaseline: 0,
|
175 | allowReorder: 0,
|
176 | alphabetic: 0,
|
177 | amplitude: 0,
|
178 | arabicForm: 0,
|
179 | ascent: 0,
|
180 | attributeName: 0,
|
181 | attributeType: 0,
|
182 | autoReverse: 0,
|
183 | azimuth: 0,
|
184 | baseFrequency: 0,
|
185 | baseProfile: 0,
|
186 | baselineShift: 0,
|
187 | bbox: 0,
|
188 | begin: 0,
|
189 | bias: 0,
|
190 | by: 0,
|
191 | calcMode: 0,
|
192 | capHeight: 0,
|
193 | clip: 0,
|
194 | clipPath: 0,
|
195 | clipRule: 0,
|
196 | clipPathUnits: 0,
|
197 | colorInterpolation: 0,
|
198 | colorInterpolationFilters: 0,
|
199 | colorProfile: 0,
|
200 | colorRendering: 0,
|
201 | contentScriptType: 0,
|
202 | contentStyleType: 0,
|
203 | cursor: 0,
|
204 | cx: 0,
|
205 | cy: 0,
|
206 | d: 0,
|
207 | decelerate: 0,
|
208 | descent: 0,
|
209 | diffuseConstant: 0,
|
210 | direction: 0,
|
211 | display: 0,
|
212 | divisor: 0,
|
213 | dominantBaseline: 0,
|
214 | dur: 0,
|
215 | dx: 0,
|
216 | dy: 0,
|
217 | edgeMode: 0,
|
218 | elevation: 0,
|
219 | enableBackground: 0,
|
220 | end: 0,
|
221 | exponent: 0,
|
222 | externalResourcesRequired: 0,
|
223 | fill: 0,
|
224 | fillOpacity: 0,
|
225 | fillRule: 0,
|
226 | filter: 0,
|
227 | filterRes: 0,
|
228 | filterUnits: 0,
|
229 | floodColor: 0,
|
230 | floodOpacity: 0,
|
231 | focusable: 0,
|
232 | fontFamily: 0,
|
233 | fontSize: 0,
|
234 | fontSizeAdjust: 0,
|
235 | fontStretch: 0,
|
236 | fontStyle: 0,
|
237 | fontVariant: 0,
|
238 | fontWeight: 0,
|
239 | format: 0,
|
240 | from: 0,
|
241 | fx: 0,
|
242 | fy: 0,
|
243 | g1: 0,
|
244 | g2: 0,
|
245 | glyphName: 0,
|
246 | glyphOrientationHorizontal: 0,
|
247 | glyphOrientationVertical: 0,
|
248 | glyphRef: 0,
|
249 | gradientTransform: 0,
|
250 | gradientUnits: 0,
|
251 | hanging: 0,
|
252 | horizAdvX: 0,
|
253 | horizOriginX: 0,
|
254 | ideographic: 0,
|
255 | imageRendering: 0,
|
256 | in: 0,
|
257 | in2: 0,
|
258 | intercept: 0,
|
259 | k: 0,
|
260 | k1: 0,
|
261 | k2: 0,
|
262 | k3: 0,
|
263 | k4: 0,
|
264 | kernelMatrix: 0,
|
265 | kernelUnitLength: 0,
|
266 | kerning: 0,
|
267 | keyPoints: 0,
|
268 | keySplines: 0,
|
269 | keyTimes: 0,
|
270 | lengthAdjust: 0,
|
271 | letterSpacing: 0,
|
272 | lightingColor: 0,
|
273 | limitingConeAngle: 0,
|
274 | local: 0,
|
275 | markerEnd: 0,
|
276 | markerMid: 0,
|
277 | markerStart: 0,
|
278 | markerHeight: 0,
|
279 | markerUnits: 0,
|
280 | markerWidth: 0,
|
281 | mask: 0,
|
282 | maskContentUnits: 0,
|
283 | maskUnits: 0,
|
284 | mathematical: 0,
|
285 | mode: 0,
|
286 | numOctaves: 0,
|
287 | offset: 0,
|
288 | opacity: 0,
|
289 | operator: 0,
|
290 | order: 0,
|
291 | orient: 0,
|
292 | orientation: 0,
|
293 | origin: 0,
|
294 | overflow: 0,
|
295 | overlinePosition: 0,
|
296 | overlineThickness: 0,
|
297 | paintOrder: 0,
|
298 | panose1: 0,
|
299 | pathLength: 0,
|
300 | patternContentUnits: 0,
|
301 | patternTransform: 0,
|
302 | patternUnits: 0,
|
303 | pointerEvents: 0,
|
304 | points: 0,
|
305 | pointsAtX: 0,
|
306 | pointsAtY: 0,
|
307 | pointsAtZ: 0,
|
308 | preserveAlpha: 0,
|
309 | preserveAspectRatio: 0,
|
310 | primitiveUnits: 0,
|
311 | r: 0,
|
312 | radius: 0,
|
313 | refX: 0,
|
314 | refY: 0,
|
315 | renderingIntent: 0,
|
316 | repeatCount: 0,
|
317 | repeatDur: 0,
|
318 | requiredExtensions: 0,
|
319 | requiredFeatures: 0,
|
320 | restart: 0,
|
321 | result: 0,
|
322 | rotate: 0,
|
323 | rx: 0,
|
324 | ry: 0,
|
325 | scale: 0,
|
326 | seed: 0,
|
327 | shapeRendering: 0,
|
328 | slope: 0,
|
329 | spacing: 0,
|
330 | specularConstant: 0,
|
331 | specularExponent: 0,
|
332 | speed: 0,
|
333 | spreadMethod: 0,
|
334 | startOffset: 0,
|
335 | stdDeviation: 0,
|
336 | stemh: 0,
|
337 | stemv: 0,
|
338 | stitchTiles: 0,
|
339 | stopColor: 0,
|
340 | stopOpacity: 0,
|
341 | strikethroughPosition: 0,
|
342 | strikethroughThickness: 0,
|
343 | string: 0,
|
344 | stroke: 0,
|
345 | strokeDasharray: 0,
|
346 | strokeDashoffset: 0,
|
347 | strokeLinecap: 0,
|
348 | strokeLinejoin: 0,
|
349 | strokeMiterlimit: 0,
|
350 | strokeOpacity: 0,
|
351 | strokeWidth: 0,
|
352 | surfaceScale: 0,
|
353 | systemLanguage: 0,
|
354 | tableValues: 0,
|
355 | targetX: 0,
|
356 | targetY: 0,
|
357 | textAnchor: 0,
|
358 | textDecoration: 0,
|
359 | textRendering: 0,
|
360 | textLength: 0,
|
361 | to: 0,
|
362 | transform: 0,
|
363 | u1: 0,
|
364 | u2: 0,
|
365 | underlinePosition: 0,
|
366 | underlineThickness: 0,
|
367 | unicode: 0,
|
368 | unicodeBidi: 0,
|
369 | unicodeRange: 0,
|
370 | unitsPerEm: 0,
|
371 | vAlphabetic: 0,
|
372 | vHanging: 0,
|
373 | vIdeographic: 0,
|
374 | vMathematical: 0,
|
375 | values: 0,
|
376 | vectorEffect: 0,
|
377 | version: 0,
|
378 | vertAdvY: 0,
|
379 | vertOriginX: 0,
|
380 | vertOriginY: 0,
|
381 | viewBox: 0,
|
382 | viewTarget: 0,
|
383 | visibility: 0,
|
384 | widths: 0,
|
385 | wordSpacing: 0,
|
386 | writingMode: 0,
|
387 | x: 0,
|
388 | xHeight: 0,
|
389 | x1: 0,
|
390 | x2: 0,
|
391 | xChannelSelector: 0,
|
392 | xlinkActuate: 0,
|
393 | xlinkArcrole: 0,
|
394 | xlinkHref: 0,
|
395 | xlinkRole: 0,
|
396 | xlinkShow: 0,
|
397 | xlinkTitle: 0,
|
398 | xlinkType: 0,
|
399 | xmlBase: 0,
|
400 | xmlns: 0,
|
401 | xmlnsXlink: 0,
|
402 | xmlLang: 0,
|
403 | xmlSpace: 0,
|
404 | y: 0,
|
405 | y1: 0,
|
406 | y2: 0,
|
407 | yChannelSelector: 0,
|
408 | z: 0,
|
409 | zoomAndPan: 0
|
410 | },
|
411 | DOMAttributeNames: {
|
412 | accentHeight: 'accent-height',
|
413 | alignmentBaseline: 'alignment-baseline',
|
414 | arabicForm: 'arabic-form',
|
415 | baselineShift: 'baseline-shift',
|
416 | capHeight: 'cap-height',
|
417 | clipPath: 'clip-path',
|
418 | clipRule: 'clip-rule',
|
419 | colorInterpolation: 'color-interpolation',
|
420 | colorInterpolationFilters: 'color-interpolation-filters',
|
421 | colorProfile: 'color-profile',
|
422 | colorRendering: 'color-rendering',
|
423 | dominantBaseline: 'dominant-baseline',
|
424 | enableBackground: 'enable-background',
|
425 | fillOpacity: 'fill-opacity',
|
426 | fillRule: 'fill-rule',
|
427 | floodColor: 'flood-color',
|
428 | floodOpacity: 'flood-opacity',
|
429 | fontFamily: 'font-family',
|
430 | fontSize: 'font-size',
|
431 | fontSizeAdjust: 'font-size-adjust',
|
432 | fontStretch: 'font-stretch',
|
433 | fontStyle: 'font-style',
|
434 | fontVariant: 'font-variant',
|
435 | fontWeight: 'font-weight',
|
436 | glyphName: 'glyph-name',
|
437 | glyphOrientationHorizontal: 'glyph-orientation-horizontal',
|
438 | glyphOrientationVertical: 'glyph-orientation-vertical',
|
439 | horizAdvX: 'horiz-adv-x',
|
440 | horizOriginX: 'horiz-origin-x',
|
441 | imageRendering: 'image-rendering',
|
442 | letterSpacing: 'letter-spacing',
|
443 | lightingColor: 'lighting-color',
|
444 | markerEnd: 'marker-end',
|
445 | markerMid: 'marker-mid',
|
446 | markerStart: 'marker-start',
|
447 | overlinePosition: 'overline-position',
|
448 | overlineThickness: 'overline-thickness',
|
449 | paintOrder: 'paint-order',
|
450 | panose1: 'panose-1',
|
451 | pointerEvents: 'pointer-events',
|
452 | renderingIntent: 'rendering-intent',
|
453 | shapeRendering: 'shape-rendering',
|
454 | stopColor: 'stop-color',
|
455 | stopOpacity: 'stop-opacity',
|
456 | strikethroughPosition: 'strikethrough-position',
|
457 | strikethroughThickness: 'strikethrough-thickness',
|
458 | strokeDasharray: 'stroke-dasharray',
|
459 | strokeDashoffset: 'stroke-dashoffset',
|
460 | strokeLinecap: 'stroke-linecap',
|
461 | strokeLinejoin: 'stroke-linejoin',
|
462 | strokeMiterlimit: 'stroke-miterlimit',
|
463 | strokeOpacity: 'stroke-opacity',
|
464 | strokeWidth: 'stroke-width',
|
465 | textAnchor: 'text-anchor',
|
466 | textDecoration: 'text-decoration',
|
467 | textRendering: 'text-rendering',
|
468 | underlinePosition: 'underline-position',
|
469 | underlineThickness: 'underline-thickness',
|
470 | unicodeBidi: 'unicode-bidi',
|
471 | unicodeRange: 'unicode-range',
|
472 | unitsPerEm: 'units-per-em',
|
473 | vAlphabetic: 'v-alphabetic',
|
474 | vHanging: 'v-hanging',
|
475 | vIdeographic: 'v-ideographic',
|
476 | vMathematical: 'v-mathematical',
|
477 | vectorEffect: 'vector-effect',
|
478 | vertAdvY: 'vert-adv-y',
|
479 | vertOriginX: 'vert-origin-x',
|
480 | vertOriginY: 'vert-origin-y',
|
481 | wordSpacing: 'word-spacing',
|
482 | writingMode: 'writing-mode',
|
483 | xHeight: 'x-height',
|
484 | xlinkActuate: 'xlink:actuate',
|
485 | xlinkArcrole: 'xlink:arcrole',
|
486 | xlinkHref: 'xlink:href',
|
487 | xlinkRole: 'xlink:role',
|
488 | xlinkShow: 'xlink:show',
|
489 | xlinkTitle: 'xlink:title',
|
490 | xlinkType: 'xlink:type',
|
491 | xmlBase: 'xml:base',
|
492 | xmlnsXlink: 'xmlns:xlink',
|
493 | xmlLang: 'xml:lang',
|
494 | xmlSpace: 'xml:space'
|
495 | }
|
496 | };
|
497 |
|
498 | var injection = {
|
499 | MUST_USE_PROPERTY: 1,
|
500 | HAS_BOOLEAN_VALUE: 4,
|
501 | HAS_NUMERIC_VALUE: 8,
|
502 | HAS_POSITIVE_NUMERIC_VALUE: 24,
|
503 | HAS_OVERLOADED_BOOLEAN_VALUE: 32
|
504 | };
|
505 |
|
506 | var MUST_USE_PROPERTY = injection.MUST_USE_PROPERTY;
|
507 | var HAS_BOOLEAN_VALUE = injection.HAS_BOOLEAN_VALUE;
|
508 | var HAS_NUMERIC_VALUE = injection.HAS_NUMERIC_VALUE;
|
509 | var HAS_POSITIVE_NUMERIC_VALUE = injection.HAS_POSITIVE_NUMERIC_VALUE;
|
510 | var HAS_OVERLOADED_BOOLEAN_VALUE = injection.HAS_OVERLOADED_BOOLEAN_VALUE;
|
511 |
|
512 | |
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 | function checkMask(value, bitmask) {
|
520 | return (value & bitmask) === bitmask;
|
521 | }
|
522 |
|
523 | |
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 | function injectDOMPropertyConfig(domPropertyConfig, config, isSVG) {
|
531 | var Properties = domPropertyConfig.Properties;
|
532 | var DOMAttributeNames = domPropertyConfig.DOMAttributeNames;
|
533 | var attributeName;
|
534 | var propertyName;
|
535 | var propConfig;
|
536 |
|
537 | for (propertyName in Properties) {
|
538 | attributeName =
|
539 | DOMAttributeNames[propertyName] ||
|
540 | (isSVG ? propertyName : propertyName.toLowerCase());
|
541 | propConfig = Properties[propertyName];
|
542 |
|
543 | config[attributeName] = {
|
544 | attributeName: attributeName,
|
545 | propertyName: propertyName,
|
546 | mustUseProperty: checkMask(propConfig, MUST_USE_PROPERTY),
|
547 | hasBooleanValue: checkMask(propConfig, HAS_BOOLEAN_VALUE),
|
548 | hasNumericValue: checkMask(propConfig, HAS_NUMERIC_VALUE),
|
549 | hasPositiveNumericValue: checkMask(
|
550 | propConfig,
|
551 | HAS_POSITIVE_NUMERIC_VALUE
|
552 | ),
|
553 | hasOverloadedBooleanValue: checkMask(
|
554 | propConfig,
|
555 | HAS_OVERLOADED_BOOLEAN_VALUE
|
556 | )
|
557 | };
|
558 | }
|
559 | }
|
560 |
|
561 | |
562 |
|
563 |
|
564 |
|
565 |
|
566 | var html = {};
|
567 | injectDOMPropertyConfig(HTMLDOMPropertyConfig, html);
|
568 |
|
569 | |
570 |
|
571 |
|
572 |
|
573 |
|
574 | var svg = {};
|
575 | injectDOMPropertyConfig(SVGDOMPropertyConfig, svg, true);
|
576 |
|
577 | |
578 |
|
579 |
|
580 |
|
581 |
|
582 | var properties = {};
|
583 | injectDOMPropertyConfig(HTMLDOMPropertyConfig, properties);
|
584 | injectDOMPropertyConfig(SVGDOMPropertyConfig, properties, true);
|
585 |
|
586 | var ATTRIBUTE_NAME_START_CHAR =
|
587 | ':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';
|
588 | var ATTRIBUTE_NAME_CHAR =
|
589 | ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
590 |
|
591 | var reactProperty = {
|
592 | html: html,
|
593 | svg: svg,
|
594 | properties: properties,
|
595 |
|
596 | |
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 | isCustomAttribute: RegExp.prototype.test.bind(
|
605 | new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$')
|
606 | )
|
607 | };
|
608 |
|
609 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
610 |
|
611 | function createCommonjsModule(fn) {
|
612 | var module = { exports: {} };
|
613 | return fn(module, module.exports), module.exports;
|
614 | }
|
615 |
|
616 |
|
617 |
|
618 | var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
619 |
|
620 | var NEWLINE_REGEX = /\n/g;
|
621 | var WHITESPACE_REGEX = /^\s*/;
|
622 |
|
623 |
|
624 | var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
|
625 | var COLON_REGEX = /^:\s*/;
|
626 | var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
|
627 | var SEMICOLON_REGEX = /^[;\s]*/;
|
628 |
|
629 |
|
630 | var TRIM_REGEX = /^\s+|\s+$/g;
|
631 |
|
632 |
|
633 | var NEWLINE = '\n';
|
634 | var FORWARD_SLASH = '/';
|
635 | var ASTERISK = '*';
|
636 | var EMPTY_STRING = '';
|
637 |
|
638 |
|
639 | var TYPE_COMMENT = 'comment';
|
640 | var TYPE_DECLARATION = 'declaration';
|
641 |
|
642 | |
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 | var inlineStyleParser = function(style, options) {
|
650 | if (typeof style !== 'string') {
|
651 | throw new TypeError('First argument must be a string');
|
652 | }
|
653 |
|
654 | if (!style) return [];
|
655 |
|
656 | options = options || {};
|
657 |
|
658 | |
659 |
|
660 |
|
661 | var lineno = 1;
|
662 | var column = 1;
|
663 |
|
664 | |
665 |
|
666 |
|
667 |
|
668 |
|
669 | function updatePosition(str) {
|
670 | var lines = str.match(NEWLINE_REGEX);
|
671 | if (lines) lineno += lines.length;
|
672 | var i = str.lastIndexOf(NEWLINE);
|
673 | column = ~i ? str.length - i : column + str.length;
|
674 | }
|
675 |
|
676 | |
677 |
|
678 |
|
679 |
|
680 |
|
681 | function position() {
|
682 | var start = { line: lineno, column: column };
|
683 | return function(node) {
|
684 | node.position = new Position(start);
|
685 | whitespace();
|
686 | return node;
|
687 | };
|
688 | }
|
689 |
|
690 | |
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 | function Position(start) {
|
699 | this.start = start;
|
700 | this.end = { line: lineno, column: column };
|
701 | this.source = options.source;
|
702 | }
|
703 |
|
704 | |
705 |
|
706 |
|
707 | Position.prototype.content = style;
|
708 |
|
709 | |
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | function error(msg) {
|
716 | var err = new Error(
|
717 | options.source + ':' + lineno + ':' + column + ': ' + msg
|
718 | );
|
719 | err.reason = msg;
|
720 | err.filename = options.source;
|
721 | err.line = lineno;
|
722 | err.column = column;
|
723 | err.source = style;
|
724 |
|
725 | if (options.silent) ; else {
|
726 | throw err;
|
727 | }
|
728 | }
|
729 |
|
730 | |
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 | function match(re) {
|
737 | var m = re.exec(style);
|
738 | if (!m) return;
|
739 | var str = m[0];
|
740 | updatePosition(str);
|
741 | style = style.slice(str.length);
|
742 | return m;
|
743 | }
|
744 |
|
745 | |
746 |
|
747 |
|
748 | function whitespace() {
|
749 | match(WHITESPACE_REGEX);
|
750 | }
|
751 |
|
752 | |
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 | function comments(rules) {
|
759 | var c;
|
760 | rules = rules || [];
|
761 | while ((c = comment())) {
|
762 | if (c !== false) {
|
763 | rules.push(c);
|
764 | }
|
765 | }
|
766 | return rules;
|
767 | }
|
768 |
|
769 | |
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 | function comment() {
|
776 | var pos = position();
|
777 | if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
|
778 |
|
779 | var i = 2;
|
780 | while (
|
781 | EMPTY_STRING != style.charAt(i) &&
|
782 | (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
|
783 | ) {
|
784 | ++i;
|
785 | }
|
786 | i += 2;
|
787 |
|
788 | if (EMPTY_STRING === style.charAt(i - 1)) {
|
789 | return error('End of comment missing');
|
790 | }
|
791 |
|
792 | var str = style.slice(2, i - 2);
|
793 | column += 2;
|
794 | updatePosition(str);
|
795 | style = style.slice(i);
|
796 | column += 2;
|
797 |
|
798 | return pos({
|
799 | type: TYPE_COMMENT,
|
800 | comment: str
|
801 | });
|
802 | }
|
803 |
|
804 | |
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | function declaration() {
|
811 | var pos = position();
|
812 |
|
813 |
|
814 | var prop = match(PROPERTY_REGEX);
|
815 | if (!prop) return;
|
816 | comment();
|
817 |
|
818 |
|
819 | if (!match(COLON_REGEX)) return error("property missing ':'");
|
820 |
|
821 |
|
822 | var val = match(VALUE_REGEX);
|
823 |
|
824 | var ret = pos({
|
825 | type: TYPE_DECLARATION,
|
826 | property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
|
827 | value: val
|
828 | ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
|
829 | : EMPTY_STRING
|
830 | });
|
831 |
|
832 |
|
833 | match(SEMICOLON_REGEX);
|
834 |
|
835 | return ret;
|
836 | }
|
837 |
|
838 | |
839 |
|
840 |
|
841 |
|
842 |
|
843 | function declarations() {
|
844 | var decls = [];
|
845 |
|
846 | comments(decls);
|
847 |
|
848 |
|
849 | var decl;
|
850 | while ((decl = declaration())) {
|
851 | if (decl !== false) {
|
852 | decls.push(decl);
|
853 | comments(decls);
|
854 | }
|
855 | }
|
856 |
|
857 | return decls;
|
858 | }
|
859 |
|
860 | whitespace();
|
861 | return declarations();
|
862 | };
|
863 |
|
864 | |
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 | function trim(str) {
|
871 | return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
872 | }
|
873 |
|
874 | |
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 | function StyleToObject(style, iterator) {
|
886 | var output = null;
|
887 | if (!style || typeof style !== 'string') {
|
888 | return output;
|
889 | }
|
890 |
|
891 | var declaration;
|
892 | var declarations = inlineStyleParser(style);
|
893 | var hasIterator = typeof iterator === 'function';
|
894 | var property;
|
895 | var value;
|
896 |
|
897 | for (var i = 0, len = declarations.length; i < len; i++) {
|
898 | declaration = declarations[i];
|
899 | property = declaration.property;
|
900 | value = declaration.value;
|
901 |
|
902 | if (hasIterator) {
|
903 | iterator(property, value, declaration);
|
904 | } else if (value) {
|
905 | output || (output = {});
|
906 | output[property] = value;
|
907 | }
|
908 | }
|
909 |
|
910 | return output;
|
911 | }
|
912 |
|
913 | var styleToObject = StyleToObject;
|
914 |
|
915 | var utilities = createCommonjsModule(function (module, exports) {
|
916 | exports.__esModule = true;
|
917 | exports.camelCase = void 0;
|
918 | var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
|
919 | var HYPHEN_REGEX = /-([a-z])/g;
|
920 | var NO_HYPHEN_REGEX = /^[^-]+$/;
|
921 | var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
|
922 | var skipCamelCase = function (property) {
|
923 | return !property ||
|
924 | NO_HYPHEN_REGEX.test(property) ||
|
925 | CUSTOM_PROPERTY_REGEX.test(property);
|
926 | };
|
927 | var capitalize = function (match, character) {
|
928 | return character.toUpperCase();
|
929 | };
|
930 | var trimHyphen = function (match, prefix) { return prefix + "-"; };
|
931 | var camelCase = function (property, options) {
|
932 | if (options === void 0) { options = {}; }
|
933 | if (skipCamelCase(property)) {
|
934 | return property;
|
935 | }
|
936 | property = property.toLowerCase();
|
937 | if (!options.reactCompat) {
|
938 | property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
|
939 | }
|
940 | return property.replace(HYPHEN_REGEX, capitalize);
|
941 | };
|
942 | exports.camelCase = camelCase;
|
943 | });
|
944 |
|
945 | var cjs = createCommonjsModule(function (module, exports) {
|
946 | var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
947 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
948 | };
|
949 | exports.__esModule = true;
|
950 | var style_to_object_1 = __importDefault(styleToObject);
|
951 |
|
952 | function StyleToJS(style, options) {
|
953 | var output = {};
|
954 | if (!style || typeof style !== 'string') {
|
955 | return output;
|
956 | }
|
957 | style_to_object_1["default"](style, function (property, value) {
|
958 | if (property && value) {
|
959 | output[utilities.camelCase(property, options)] = value;
|
960 | }
|
961 | });
|
962 | return output;
|
963 | }
|
964 | exports["default"] = StyleToJS;
|
965 | });
|
966 |
|
967 | var styleToJS = cjs.default;
|
968 |
|
969 | |
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 | function invertObject(obj, override) {
|
977 | if (!obj || typeof obj !== 'object') {
|
978 | throw new TypeError('First argument must be an object');
|
979 | }
|
980 |
|
981 | var key;
|
982 | var value;
|
983 | var isOverridePresent = typeof override === 'function';
|
984 | var overrides = {};
|
985 | var result = {};
|
986 |
|
987 | for (key in obj) {
|
988 | value = obj[key];
|
989 |
|
990 | if (isOverridePresent) {
|
991 | overrides = override(key, value);
|
992 | if (overrides && overrides.length === 2) {
|
993 | result[overrides[0]] = overrides[1];
|
994 | continue;
|
995 | }
|
996 | }
|
997 |
|
998 | if (typeof value === 'string') {
|
999 | result[value] = key;
|
1000 | }
|
1001 | }
|
1002 |
|
1003 | return result;
|
1004 | }
|
1005 |
|
1006 | |
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 | function isCustomComponent(tagName, props) {
|
1016 | if (tagName.indexOf('-') === -1) {
|
1017 | return props && typeof props.is === 'string';
|
1018 | }
|
1019 |
|
1020 | switch (tagName) {
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 | case 'annotation-xml':
|
1026 | case 'color-profile':
|
1027 | case 'font-face':
|
1028 | case 'font-face-src':
|
1029 | case 'font-face-uri':
|
1030 | case 'font-face-format':
|
1031 | case 'font-face-name':
|
1032 | case 'missing-glyph':
|
1033 | return false;
|
1034 | default:
|
1035 | return true;
|
1036 | }
|
1037 | }
|
1038 |
|
1039 | var styleToJSOptions = { reactCompat: true };
|
1040 |
|
1041 | |
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | function setStyleProp(style, props) {
|
1048 | if (style === null || style === undefined) {
|
1049 | return;
|
1050 | }
|
1051 | props.style = styleToJS(style, styleToJSOptions);
|
1052 | }
|
1053 |
|
1054 | |
1055 |
|
1056 |
|
1057 |
|
1058 | var PRESERVE_CUSTOM_ATTRIBUTES = React__default['default'].version.split('.')[0] >= 16;
|
1059 |
|
1060 | var utilities$1 = {
|
1061 | PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
1062 | invertObject: invertObject,
|
1063 | isCustomComponent: isCustomComponent,
|
1064 | setStyleProp: setStyleProp
|
1065 | };
|
1066 |
|
1067 | var setStyleProp$1 = utilities$1.setStyleProp;
|
1068 |
|
1069 | var htmlProperties = reactProperty.html;
|
1070 | var svgProperties = reactProperty.svg;
|
1071 | var isCustomAttribute = reactProperty.isCustomAttribute;
|
1072 |
|
1073 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
1074 |
|
1075 | |
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 | function attributesToProps(attributes) {
|
1082 | attributes = attributes || {};
|
1083 |
|
1084 | var attributeName;
|
1085 | var attributeNameLowerCased;
|
1086 | var attributeValue;
|
1087 | var property;
|
1088 | var props = {};
|
1089 |
|
1090 | for (attributeName in attributes) {
|
1091 | attributeValue = attributes[attributeName];
|
1092 |
|
1093 |
|
1094 | if (isCustomAttribute(attributeName)) {
|
1095 | props[attributeName] = attributeValue;
|
1096 | continue;
|
1097 | }
|
1098 |
|
1099 |
|
1100 | attributeNameLowerCased = attributeName.toLowerCase();
|
1101 | if (hasOwnProperty.call(htmlProperties, attributeNameLowerCased)) {
|
1102 | property = htmlProperties[attributeNameLowerCased];
|
1103 | props[property.propertyName] =
|
1104 | property.hasBooleanValue ||
|
1105 | (property.hasOverloadedBooleanValue && !attributeValue)
|
1106 | ? true
|
1107 | : attributeValue;
|
1108 | continue;
|
1109 | }
|
1110 |
|
1111 |
|
1112 | if (hasOwnProperty.call(svgProperties, attributeName)) {
|
1113 | property = svgProperties[attributeName];
|
1114 | props[property.propertyName] = attributeValue;
|
1115 | continue;
|
1116 | }
|
1117 |
|
1118 |
|
1119 | if (utilities$1.PRESERVE_CUSTOM_ATTRIBUTES) {
|
1120 | props[attributeName] = attributeValue;
|
1121 | }
|
1122 | }
|
1123 |
|
1124 |
|
1125 | setStyleProp$1(attributes.style, props);
|
1126 |
|
1127 | return props;
|
1128 | }
|
1129 |
|
1130 | var attributesToProps_1 = attributesToProps;
|
1131 |
|
1132 | var setStyleProp$2 = utilities$1.setStyleProp;
|
1133 |
|
1134 | |
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | function domToReact(nodes, options) {
|
1144 | options = options || {};
|
1145 |
|
1146 | var library = options.library || React__default['default'];
|
1147 | var cloneElement = library.cloneElement;
|
1148 | var createElement = library.createElement;
|
1149 | var isValidElement = library.isValidElement;
|
1150 |
|
1151 | var result = [];
|
1152 | var node;
|
1153 | var hasReplace = typeof options.replace === 'function';
|
1154 | var replaceElement;
|
1155 | var props;
|
1156 | var children;
|
1157 | var data;
|
1158 | var trim = options.trim;
|
1159 |
|
1160 | for (var i = 0, len = nodes.length; i < len; i++) {
|
1161 | node = nodes[i];
|
1162 |
|
1163 |
|
1164 | if (hasReplace) {
|
1165 | replaceElement = options.replace(node);
|
1166 |
|
1167 | if (isValidElement(replaceElement)) {
|
1168 |
|
1169 |
|
1170 | if (len > 1) {
|
1171 | replaceElement = cloneElement(replaceElement, {
|
1172 | key: replaceElement.key || i
|
1173 | });
|
1174 | }
|
1175 | result.push(replaceElement);
|
1176 | continue;
|
1177 | }
|
1178 | }
|
1179 |
|
1180 | if (node.type === 'text') {
|
1181 |
|
1182 | if (trim) {
|
1183 | data = node.data.trim();
|
1184 | if (data) {
|
1185 | result.push(node.data);
|
1186 | }
|
1187 | } else {
|
1188 | result.push(node.data);
|
1189 | }
|
1190 | continue;
|
1191 | }
|
1192 |
|
1193 | props = node.attribs;
|
1194 | if (skipAttributesToProps(node)) {
|
1195 | setStyleProp$2(props.style, props);
|
1196 | } else if (props) {
|
1197 | props = attributesToProps_1(props);
|
1198 | }
|
1199 |
|
1200 | children = null;
|
1201 |
|
1202 | switch (node.type) {
|
1203 | case 'script':
|
1204 | case 'style':
|
1205 |
|
1206 |
|
1207 | if (node.children[0]) {
|
1208 | props.dangerouslySetInnerHTML = {
|
1209 | __html: node.children[0].data
|
1210 | };
|
1211 | }
|
1212 | break;
|
1213 |
|
1214 | case 'tag':
|
1215 |
|
1216 |
|
1217 | if (node.name === 'textarea' && node.children[0]) {
|
1218 | props.defaultValue = node.children[0].data;
|
1219 | } else if (node.children && node.children.length) {
|
1220 |
|
1221 | children = domToReact(node.children, options);
|
1222 | }
|
1223 | break;
|
1224 |
|
1225 |
|
1226 | default:
|
1227 | continue;
|
1228 | }
|
1229 |
|
1230 |
|
1231 |
|
1232 | if (len > 1) {
|
1233 | props.key = i;
|
1234 | }
|
1235 |
|
1236 | result.push(createElement(node.name, props, children));
|
1237 | }
|
1238 |
|
1239 | return result.length === 1 ? result[0] : result;
|
1240 | }
|
1241 |
|
1242 | |
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 | function skipAttributesToProps(node) {
|
1250 | return (
|
1251 | utilities$1.PRESERVE_CUSTOM_ATTRIBUTES &&
|
1252 | node.type === 'tag' &&
|
1253 | utilities$1.isCustomComponent(node.name, node.attribs)
|
1254 | );
|
1255 | }
|
1256 |
|
1257 | var domToReact_1 = domToReact;
|
1258 |
|
1259 | |
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 | var CASE_SENSITIVE_TAG_NAMES = [
|
1265 | 'animateMotion',
|
1266 | 'animateTransform',
|
1267 | 'clipPath',
|
1268 | 'feBlend',
|
1269 | 'feColorMatrix',
|
1270 | 'feComponentTransfer',
|
1271 | 'feComposite',
|
1272 | 'feConvolveMatrix',
|
1273 | 'feDiffuseLighting',
|
1274 | 'feDisplacementMap',
|
1275 | 'feDropShadow',
|
1276 | 'feFlood',
|
1277 | 'feFuncA',
|
1278 | 'feFuncB',
|
1279 | 'feFuncG',
|
1280 | 'feFuncR',
|
1281 | 'feGaussainBlur',
|
1282 | 'feImage',
|
1283 | 'feMerge',
|
1284 | 'feMergeNode',
|
1285 | 'feMorphology',
|
1286 | 'feOffset',
|
1287 | 'fePointLight',
|
1288 | 'feSpecularLighting',
|
1289 | 'feSpotLight',
|
1290 | 'feTile',
|
1291 | 'feTurbulence',
|
1292 | 'foreignObject',
|
1293 | 'linearGradient',
|
1294 | 'radialGradient',
|
1295 | 'textPath'
|
1296 | ];
|
1297 |
|
1298 | var constants = {
|
1299 | CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
|
1300 | };
|
1301 |
|
1302 | var node = createCommonjsModule(function (module, exports) {
|
1303 | var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
1304 | var extendStatics = function (d, b) {
|
1305 | extendStatics = Object.setPrototypeOf ||
|
1306 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
1307 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
1308 | return extendStatics(d, b);
|
1309 | };
|
1310 | return function (d, b) {
|
1311 | extendStatics(d, b);
|
1312 | function __() { this.constructor = d; }
|
1313 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
1314 | };
|
1315 | })();
|
1316 | var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
1317 | __assign = Object.assign || function(t) {
|
1318 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
1319 | s = arguments[i];
|
1320 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
1321 | t[p] = s[p];
|
1322 | }
|
1323 | return t;
|
1324 | };
|
1325 | return __assign.apply(this, arguments);
|
1326 | };
|
1327 | Object.defineProperty(exports, "__esModule", { value: true });
|
1328 | exports.cloneNode = exports.Element = exports.Document = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0;
|
1329 | var nodeTypes = new Map([
|
1330 | ["tag" , 1],
|
1331 | ["script" , 1],
|
1332 | ["style" , 1],
|
1333 | ["directive" , 1],
|
1334 | ["text" , 3],
|
1335 | ["cdata" , 4],
|
1336 | ["comment" , 8],
|
1337 | ["root" , 9],
|
1338 | ]);
|
1339 | |
1340 |
|
1341 |
|
1342 |
|
1343 | var Node = (function () {
|
1344 | |
1345 |
|
1346 |
|
1347 |
|
1348 | function Node(type) {
|
1349 | this.type = type;
|
1350 |
|
1351 | this.parent = null;
|
1352 |
|
1353 | this.prev = null;
|
1354 |
|
1355 | this.next = null;
|
1356 |
|
1357 | this.startIndex = null;
|
1358 |
|
1359 | this.endIndex = null;
|
1360 | }
|
1361 | Object.defineProperty(Node.prototype, "nodeType", {
|
1362 |
|
1363 | get: function () {
|
1364 | var _a;
|
1365 | return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
|
1366 | },
|
1367 | enumerable: false,
|
1368 | configurable: true
|
1369 | });
|
1370 | Object.defineProperty(Node.prototype, "parentNode", {
|
1371 |
|
1372 | get: function () {
|
1373 | return this.parent;
|
1374 | },
|
1375 | set: function (parent) {
|
1376 | this.parent = parent;
|
1377 | },
|
1378 | enumerable: false,
|
1379 | configurable: true
|
1380 | });
|
1381 | Object.defineProperty(Node.prototype, "previousSibling", {
|
1382 | get: function () {
|
1383 | return this.prev;
|
1384 | },
|
1385 | set: function (prev) {
|
1386 | this.prev = prev;
|
1387 | },
|
1388 | enumerable: false,
|
1389 | configurable: true
|
1390 | });
|
1391 | Object.defineProperty(Node.prototype, "nextSibling", {
|
1392 | get: function () {
|
1393 | return this.next;
|
1394 | },
|
1395 | set: function (next) {
|
1396 | this.next = next;
|
1397 | },
|
1398 | enumerable: false,
|
1399 | configurable: true
|
1400 | });
|
1401 | |
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 | Node.prototype.cloneNode = function (recursive) {
|
1408 | if (recursive === void 0) { recursive = false; }
|
1409 | return cloneNode(this, recursive);
|
1410 | };
|
1411 | return Node;
|
1412 | }());
|
1413 | exports.Node = Node;
|
1414 | var DataNode = (function (_super) {
|
1415 | __extends(DataNode, _super);
|
1416 | |
1417 |
|
1418 |
|
1419 |
|
1420 | function DataNode(type, data) {
|
1421 | var _this = _super.call(this, type) || this;
|
1422 | _this.data = data;
|
1423 | return _this;
|
1424 | }
|
1425 | Object.defineProperty(DataNode.prototype, "nodeValue", {
|
1426 | get: function () {
|
1427 | return this.data;
|
1428 | },
|
1429 | set: function (data) {
|
1430 | this.data = data;
|
1431 | },
|
1432 | enumerable: false,
|
1433 | configurable: true
|
1434 | });
|
1435 | return DataNode;
|
1436 | }(Node));
|
1437 | exports.DataNode = DataNode;
|
1438 | var Text = (function (_super) {
|
1439 | __extends(Text, _super);
|
1440 | function Text(data) {
|
1441 | return _super.call(this, "text" , data) || this;
|
1442 | }
|
1443 | return Text;
|
1444 | }(DataNode));
|
1445 | exports.Text = Text;
|
1446 | var Comment = (function (_super) {
|
1447 | __extends(Comment, _super);
|
1448 | function Comment(data) {
|
1449 | return _super.call(this, "comment" , data) || this;
|
1450 | }
|
1451 | return Comment;
|
1452 | }(DataNode));
|
1453 | exports.Comment = Comment;
|
1454 | var ProcessingInstruction = (function (_super) {
|
1455 | __extends(ProcessingInstruction, _super);
|
1456 | function ProcessingInstruction(name, data) {
|
1457 | var _this = _super.call(this, "directive" , data) || this;
|
1458 | _this.name = name;
|
1459 | return _this;
|
1460 | }
|
1461 | return ProcessingInstruction;
|
1462 | }(DataNode));
|
1463 | exports.ProcessingInstruction = ProcessingInstruction;
|
1464 | |
1465 |
|
1466 |
|
1467 | var NodeWithChildren = (function (_super) {
|
1468 | __extends(NodeWithChildren, _super);
|
1469 | |
1470 |
|
1471 |
|
1472 |
|
1473 | function NodeWithChildren(type, children) {
|
1474 | var _this = _super.call(this, type) || this;
|
1475 | _this.children = children;
|
1476 | return _this;
|
1477 | }
|
1478 | Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
|
1479 |
|
1480 | get: function () {
|
1481 | var _a;
|
1482 | return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
|
1483 | },
|
1484 | enumerable: false,
|
1485 | configurable: true
|
1486 | });
|
1487 | Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
|
1488 | get: function () {
|
1489 | return this.children.length > 0
|
1490 | ? this.children[this.children.length - 1]
|
1491 | : null;
|
1492 | },
|
1493 | enumerable: false,
|
1494 | configurable: true
|
1495 | });
|
1496 | Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
|
1497 | get: function () {
|
1498 | return this.children;
|
1499 | },
|
1500 | set: function (children) {
|
1501 | this.children = children;
|
1502 | },
|
1503 | enumerable: false,
|
1504 | configurable: true
|
1505 | });
|
1506 | return NodeWithChildren;
|
1507 | }(Node));
|
1508 | exports.NodeWithChildren = NodeWithChildren;
|
1509 | var Document = (function (_super) {
|
1510 | __extends(Document, _super);
|
1511 | function Document(children) {
|
1512 | return _super.call(this, "root" , children) || this;
|
1513 | }
|
1514 | return Document;
|
1515 | }(NodeWithChildren));
|
1516 | exports.Document = Document;
|
1517 | var Element = (function (_super) {
|
1518 | __extends(Element, _super);
|
1519 | |
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | function Element(name, attribs, children) {
|
1525 | if (children === void 0) { children = []; }
|
1526 | var _this = _super.call(this, name === "script"
|
1527 | ? "script"
|
1528 | : name === "style"
|
1529 | ? "style"
|
1530 | : "tag" , children) || this;
|
1531 | _this.name = name;
|
1532 | _this.attribs = attribs;
|
1533 | _this.attribs = attribs;
|
1534 | return _this;
|
1535 | }
|
1536 | Object.defineProperty(Element.prototype, "tagName", {
|
1537 |
|
1538 | get: function () {
|
1539 | return this.name;
|
1540 | },
|
1541 | set: function (name) {
|
1542 | this.name = name;
|
1543 | },
|
1544 | enumerable: false,
|
1545 | configurable: true
|
1546 | });
|
1547 | Object.defineProperty(Element.prototype, "attributes", {
|
1548 | get: function () {
|
1549 | var _this = this;
|
1550 | return Object.keys(this.attribs).map(function (name) {
|
1551 | var _a, _b;
|
1552 | return ({
|
1553 | name: name,
|
1554 | value: _this.attribs[name],
|
1555 | namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
|
1556 | prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
|
1557 | });
|
1558 | });
|
1559 | },
|
1560 | enumerable: false,
|
1561 | configurable: true
|
1562 | });
|
1563 | return Element;
|
1564 | }(NodeWithChildren));
|
1565 | exports.Element = Element;
|
1566 | |
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 | function cloneNode(node, recursive) {
|
1573 | if (recursive === void 0) { recursive = false; }
|
1574 | var result;
|
1575 | switch (node.type) {
|
1576 | case "text" :
|
1577 | result = new Text(node.data);
|
1578 | break;
|
1579 | case "directive" : {
|
1580 | var instr = node;
|
1581 | result = new ProcessingInstruction(instr.name, instr.data);
|
1582 | if (instr["x-name"] != null) {
|
1583 | result["x-name"] = instr["x-name"];
|
1584 | result["x-publicId"] = instr["x-publicId"];
|
1585 | result["x-systemId"] = instr["x-systemId"];
|
1586 | }
|
1587 | break;
|
1588 | }
|
1589 | case "comment" :
|
1590 | result = new Comment(node.data);
|
1591 | break;
|
1592 | case "tag" :
|
1593 | case "script" :
|
1594 | case "style" : {
|
1595 | var elem = node;
|
1596 | var children = recursive ? cloneChildren(elem.children) : [];
|
1597 | var clone_1 = new Element(elem.name, __assign({}, elem.attribs), children);
|
1598 | children.forEach(function (child) { return (child.parent = clone_1); });
|
1599 | if (elem["x-attribsNamespace"]) {
|
1600 | clone_1["x-attribsNamespace"] = __assign({}, elem["x-attribsNamespace"]);
|
1601 | }
|
1602 | if (elem["x-attribsPrefix"]) {
|
1603 | clone_1["x-attribsPrefix"] = __assign({}, elem["x-attribsPrefix"]);
|
1604 | }
|
1605 | result = clone_1;
|
1606 | break;
|
1607 | }
|
1608 | case "cdata" : {
|
1609 | var cdata = node;
|
1610 | var children = recursive ? cloneChildren(cdata.children) : [];
|
1611 | var clone_2 = new NodeWithChildren(node.type, children);
|
1612 | children.forEach(function (child) { return (child.parent = clone_2); });
|
1613 | result = clone_2;
|
1614 | break;
|
1615 | }
|
1616 | case "root" : {
|
1617 | var doc = node;
|
1618 | var children = recursive ? cloneChildren(doc.children) : [];
|
1619 | var clone_3 = new Document(children);
|
1620 | children.forEach(function (child) { return (child.parent = clone_3); });
|
1621 | if (doc["x-mode"]) {
|
1622 | clone_3["x-mode"] = doc["x-mode"];
|
1623 | }
|
1624 | result = clone_3;
|
1625 | break;
|
1626 | }
|
1627 | case "doctype" : {
|
1628 |
|
1629 | throw new Error("Not implemented yet: ElementType.Doctype case");
|
1630 | }
|
1631 | }
|
1632 | result.startIndex = node.startIndex;
|
1633 | result.endIndex = node.endIndex;
|
1634 | return result;
|
1635 | }
|
1636 | exports.cloneNode = cloneNode;
|
1637 | function cloneChildren(childs) {
|
1638 | var children = childs.map(function (child) { return cloneNode(child, true); });
|
1639 | for (var i = 1; i < children.length; i++) {
|
1640 | children[i].prev = children[i - 1];
|
1641 | children[i - 1].next = children[i];
|
1642 | }
|
1643 | return children;
|
1644 | }
|
1645 | });
|
1646 |
|
1647 | var CASE_SENSITIVE_TAG_NAMES$1 = constants.CASE_SENSITIVE_TAG_NAMES;
|
1648 |
|
1649 | var Comment = node.Comment;
|
1650 | var Element = node.Element;
|
1651 | var ProcessingInstruction = node.ProcessingInstruction;
|
1652 | var Text = node.Text;
|
1653 |
|
1654 | var caseSensitiveTagNamesMap = {};
|
1655 | var tagName;
|
1656 |
|
1657 | for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES$1.length; i < len; i++) {
|
1658 | tagName = CASE_SENSITIVE_TAG_NAMES$1[i];
|
1659 | caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
1660 | }
|
1661 |
|
1662 | |
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 | function getCaseSensitiveTagName(tagName) {
|
1669 | return caseSensitiveTagNamesMap[tagName];
|
1670 | }
|
1671 |
|
1672 | |
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 | function formatAttributes(attributes) {
|
1679 | var result = {};
|
1680 | var attribute;
|
1681 |
|
1682 | for (var i = 0, len = attributes.length; i < len; i++) {
|
1683 | attribute = attributes[i];
|
1684 | result[attribute.name] = attribute.value;
|
1685 | }
|
1686 | return result;
|
1687 | }
|
1688 |
|
1689 | |
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 | function formatTagName(tagName) {
|
1697 | tagName = tagName.toLowerCase();
|
1698 | var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
1699 | if (caseSensitiveTagName) {
|
1700 | return caseSensitiveTagName;
|
1701 | }
|
1702 | return tagName;
|
1703 | }
|
1704 |
|
1705 | |
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 | function formatDOM(nodes, parent, directive) {
|
1714 | parent = parent || null;
|
1715 | var result = [];
|
1716 |
|
1717 | for (var index = 0, len = nodes.length; index < len; index++) {
|
1718 | var node = nodes[index];
|
1719 | var current;
|
1720 |
|
1721 |
|
1722 | switch (node.nodeType) {
|
1723 | case 1:
|
1724 |
|
1725 | current = new Element(
|
1726 | formatTagName(node.nodeName),
|
1727 | formatAttributes(node.attributes)
|
1728 | );
|
1729 | current.children = formatDOM(node.childNodes, current);
|
1730 | break;
|
1731 |
|
1732 | case 3:
|
1733 | current = new Text(node.nodeValue);
|
1734 | break;
|
1735 |
|
1736 | case 8:
|
1737 | current = new Comment(node.nodeValue);
|
1738 | break;
|
1739 |
|
1740 | default:
|
1741 | continue;
|
1742 | }
|
1743 |
|
1744 |
|
1745 | var prev = result[index - 1] || null;
|
1746 | if (prev) {
|
1747 | prev.next = current;
|
1748 | }
|
1749 |
|
1750 |
|
1751 | current.parent = parent;
|
1752 | current.prev = prev;
|
1753 | current.next = null;
|
1754 |
|
1755 | result.push(current);
|
1756 | }
|
1757 |
|
1758 | if (directive) {
|
1759 | current = new ProcessingInstruction(
|
1760 | directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
1761 | directive
|
1762 | );
|
1763 | current.next = result[0] || null;
|
1764 | current.parent = parent;
|
1765 | result.unshift(current);
|
1766 |
|
1767 | if (result[1]) {
|
1768 | result[1].prev = result[0];
|
1769 | }
|
1770 | }
|
1771 |
|
1772 | return result;
|
1773 | }
|
1774 |
|
1775 | |
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 | function isIE() {
|
1781 | return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
|
1782 | }
|
1783 |
|
1784 | var utilities$2 = {
|
1785 | formatAttributes: formatAttributes,
|
1786 | formatDOM: formatDOM,
|
1787 | isIE: isIE
|
1788 | };
|
1789 |
|
1790 |
|
1791 | var HTML = 'html';
|
1792 | var HEAD = 'head';
|
1793 | var BODY = 'body';
|
1794 | var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/;
|
1795 | var HEAD_TAG_REGEX = /<head.*>/i;
|
1796 | var BODY_TAG_REGEX = /<body.*>/i;
|
1797 |
|
1798 |
|
1799 | var parseFromDocument = function () {
|
1800 | throw new Error(
|
1801 | 'This browser does not support `document.implementation.createHTMLDocument`'
|
1802 | );
|
1803 | };
|
1804 |
|
1805 | var parseFromString = function () {
|
1806 | throw new Error(
|
1807 | 'This browser does not support `DOMParser.prototype.parseFromString`'
|
1808 | );
|
1809 | };
|
1810 |
|
1811 | |
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 | if (typeof window.DOMParser === 'function') {
|
1817 | var domParser = new window.DOMParser();
|
1818 | var mimeType = 'text/html';
|
1819 |
|
1820 | |
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 | parseFromString = function (html, tagName) {
|
1828 | if (tagName) {
|
1829 | html = '<' + tagName + '>' + html + '</' + tagName + '>';
|
1830 | }
|
1831 |
|
1832 | return domParser.parseFromString(html, mimeType);
|
1833 | };
|
1834 |
|
1835 | parseFromDocument = parseFromString;
|
1836 | }
|
1837 |
|
1838 | |
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 | if (document.implementation) {
|
1844 | var isIE$1 = utilities$2.isIE;
|
1845 |
|
1846 |
|
1847 |
|
1848 | var doc = document.implementation.createHTMLDocument(
|
1849 | isIE$1() ? 'html-dom-parser' : undefined
|
1850 | );
|
1851 |
|
1852 | |
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 | parseFromDocument = function (html, tagName) {
|
1860 | if (tagName) {
|
1861 | doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
|
1862 | return doc;
|
1863 | }
|
1864 |
|
1865 | doc.documentElement.innerHTML = html;
|
1866 | return doc;
|
1867 | };
|
1868 | }
|
1869 |
|
1870 | |
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 | var template = document.createElement('template');
|
1876 | var parseFromTemplate;
|
1877 |
|
1878 | if (template.content) {
|
1879 | |
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 | parseFromTemplate = function (html) {
|
1886 | template.innerHTML = html;
|
1887 | return template.content.childNodes;
|
1888 | };
|
1889 | }
|
1890 |
|
1891 | |
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 |
|
1897 | function domparser(html) {
|
1898 | var firstTagName;
|
1899 | var match = html.match(FIRST_TAG_REGEX);
|
1900 |
|
1901 | if (match && match[1]) {
|
1902 | firstTagName = match[1].toLowerCase();
|
1903 | }
|
1904 |
|
1905 | var doc;
|
1906 | var element;
|
1907 | var elements;
|
1908 |
|
1909 | switch (firstTagName) {
|
1910 | case HTML:
|
1911 | doc = parseFromString(html);
|
1912 |
|
1913 |
|
1914 |
|
1915 | if (!HEAD_TAG_REGEX.test(html)) {
|
1916 | element = doc.getElementsByTagName(HEAD)[0];
|
1917 | if (element) {
|
1918 | element.parentNode.removeChild(element);
|
1919 | }
|
1920 | }
|
1921 |
|
1922 | if (!BODY_TAG_REGEX.test(html)) {
|
1923 | element = doc.getElementsByTagName(BODY)[0];
|
1924 | if (element) {
|
1925 | element.parentNode.removeChild(element);
|
1926 | }
|
1927 | }
|
1928 |
|
1929 | return doc.getElementsByTagName(HTML);
|
1930 |
|
1931 | case HEAD:
|
1932 | case BODY:
|
1933 | elements = parseFromDocument(html).getElementsByTagName(firstTagName);
|
1934 |
|
1935 |
|
1936 | if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
1937 | return elements[0].parentNode.childNodes;
|
1938 | }
|
1939 | return elements;
|
1940 |
|
1941 |
|
1942 | default:
|
1943 | if (parseFromTemplate) {
|
1944 | return parseFromTemplate(html);
|
1945 | }
|
1946 |
|
1947 | return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
|
1948 | .childNodes;
|
1949 | }
|
1950 | }
|
1951 |
|
1952 | var domparser_1 = domparser;
|
1953 |
|
1954 | var formatDOM$1 = utilities$2.formatDOM;
|
1955 |
|
1956 | var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/;
|
1957 |
|
1958 | |
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 | function HTMLDOMParser(html) {
|
1965 | if (typeof html !== 'string') {
|
1966 | throw new TypeError('First argument must be a string');
|
1967 | }
|
1968 |
|
1969 | if (html === '') {
|
1970 | return [];
|
1971 | }
|
1972 |
|
1973 |
|
1974 | var match = html.match(DIRECTIVE_REGEX);
|
1975 | var directive;
|
1976 |
|
1977 | if (match && match[1]) {
|
1978 | directive = match[1];
|
1979 | }
|
1980 |
|
1981 | return formatDOM$1(domparser_1(html), null, directive);
|
1982 | }
|
1983 |
|
1984 | var htmlToDom = HTMLDOMParser;
|
1985 |
|
1986 | var domParserOptions = { lowerCaseAttributeNames: false };
|
1987 |
|
1988 | |
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 | function HTMLReactParser(html, options) {
|
1999 | if (typeof html !== 'string') {
|
2000 | throw new TypeError('First argument must be a string');
|
2001 | }
|
2002 | if (html === '') {
|
2003 | return [];
|
2004 | }
|
2005 | options = options || {};
|
2006 | return domToReact_1(
|
2007 | htmlToDom(html, options.htmlparser2 || domParserOptions),
|
2008 | options
|
2009 | );
|
2010 | }
|
2011 |
|
2012 | HTMLReactParser.domToReact = domToReact_1;
|
2013 | HTMLReactParser.htmlToDOM = htmlToDom;
|
2014 | HTMLReactParser.attributesToProps = attributesToProps_1;
|
2015 |
|
2016 |
|
2017 | var htmlReactParser = HTMLReactParser;
|
2018 | var _default = HTMLReactParser;
|
2019 | htmlReactParser.default = _default;
|
2020 |
|
2021 | return htmlReactParser;
|
2022 |
|
2023 | })));
|
2024 |
|