html-react-parser 4.2.10 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -55
- package/dist/html-react-parser.js +491 -514
- package/dist/html-react-parser.js.map +1 -1
- package/dist/html-react-parser.min.js +1 -1
- package/dist/html-react-parser.min.js.map +1 -1
- package/esm/attributes-to-props.mjs +3 -0
- package/esm/dom-to-react.mjs +3 -0
- package/esm/index.mjs +13 -0
- package/esm/utilities.mjs +8 -0
- package/lib/attributes-to-props.d.ts +8 -11
- package/lib/attributes-to-props.d.ts.map +1 -0
- package/lib/attributes-to-props.js +58 -75
- package/lib/attributes-to-props.js.map +1 -0
- package/lib/dom-to-react.d.ts +7 -13
- package/lib/dom-to-react.d.ts.map +1 -0
- package/lib/dom-to-react.js +104 -123
- package/lib/dom-to-react.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utilities.d.ts +42 -0
- package/lib/utilities.d.ts.map +1 -0
- package/lib/utilities.js +77 -79
- package/lib/utilities.js.map +1 -0
- package/package.json +27 -21
- package/src/attributes-to-props.ts +108 -0
- package/src/dom-to-react.ts +156 -0
- package/src/index.ts +37 -0
- package/src/types.ts +29 -0
- package/src/utilities.ts +108 -0
- package/index.d.ts +0 -60
- package/index.js +0 -50
- package/index.mjs +0 -13
|
@@ -4,12 +4,172 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLReactParser = factory(global.React));
|
|
5
5
|
})(this, (function (require$$0) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function _mergeNamespaces(n, m) {
|
|
8
|
+
m.forEach(function (e) {
|
|
9
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !(k in n)) {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
23
|
|
|
9
24
|
function getDefaultExportFromCjs (x) {
|
|
10
25
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
11
26
|
}
|
|
12
27
|
|
|
28
|
+
var lib$3 = {};
|
|
29
|
+
|
|
30
|
+
var htmlToDom = {};
|
|
31
|
+
|
|
32
|
+
var domparser$1 = {};
|
|
33
|
+
|
|
34
|
+
Object.defineProperty(domparser$1, "__esModule", { value: true });
|
|
35
|
+
// constants
|
|
36
|
+
var HTML = 'html';
|
|
37
|
+
var HEAD = 'head';
|
|
38
|
+
var BODY = 'body';
|
|
39
|
+
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
|
|
40
|
+
// match-all-characters in case of newlines (DOTALL)
|
|
41
|
+
var HEAD_TAG_REGEX = /<head[^]*>/i;
|
|
42
|
+
var BODY_TAG_REGEX = /<body[^]*>/i;
|
|
43
|
+
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
var parseFromDocument = function (html, tagName) {
|
|
46
|
+
/* istanbul ignore next */
|
|
47
|
+
throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
|
|
48
|
+
};
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
var parseFromString = function (html, tagName) {
|
|
51
|
+
/* istanbul ignore next */
|
|
52
|
+
throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
|
|
53
|
+
};
|
|
54
|
+
var DOMParser = typeof window === 'object' && window.DOMParser;
|
|
55
|
+
/**
|
|
56
|
+
* DOMParser (performance: slow).
|
|
57
|
+
*
|
|
58
|
+
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
59
|
+
*/
|
|
60
|
+
if (typeof DOMParser === 'function') {
|
|
61
|
+
var domParser_1 = new DOMParser();
|
|
62
|
+
var mimeType_1 = 'text/html';
|
|
63
|
+
/**
|
|
64
|
+
* Creates an HTML document using `DOMParser.parseFromString`.
|
|
65
|
+
*
|
|
66
|
+
* @param html - The HTML string.
|
|
67
|
+
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
68
|
+
* @returns - Document.
|
|
69
|
+
*/
|
|
70
|
+
parseFromString = function (html, tagName) {
|
|
71
|
+
if (tagName) {
|
|
72
|
+
/* istanbul ignore next */
|
|
73
|
+
html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
|
|
74
|
+
}
|
|
75
|
+
return domParser_1.parseFromString(html, mimeType_1);
|
|
76
|
+
};
|
|
77
|
+
parseFromDocument = parseFromString;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* DOMImplementation (performance: fair).
|
|
81
|
+
*
|
|
82
|
+
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
83
|
+
*/
|
|
84
|
+
if (typeof document === 'object' && document.implementation) {
|
|
85
|
+
var htmlDocument_1 = document.implementation.createHTMLDocument();
|
|
86
|
+
/**
|
|
87
|
+
* Use HTML document created by `document.implementation.createHTMLDocument`.
|
|
88
|
+
*
|
|
89
|
+
* @param html - The HTML string.
|
|
90
|
+
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
91
|
+
* @returns - Document
|
|
92
|
+
*/
|
|
93
|
+
parseFromDocument = function (html, tagName) {
|
|
94
|
+
if (tagName) {
|
|
95
|
+
var element = htmlDocument_1.documentElement.querySelector(tagName);
|
|
96
|
+
if (element) {
|
|
97
|
+
element.innerHTML = html;
|
|
98
|
+
}
|
|
99
|
+
return htmlDocument_1;
|
|
100
|
+
}
|
|
101
|
+
htmlDocument_1.documentElement.innerHTML = html;
|
|
102
|
+
return htmlDocument_1;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Template (performance: fast).
|
|
107
|
+
*
|
|
108
|
+
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
109
|
+
*/
|
|
110
|
+
var template = typeof document === 'object' && document.createElement('template');
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
112
|
+
var parseFromTemplate;
|
|
113
|
+
if (template && template.content) {
|
|
114
|
+
/**
|
|
115
|
+
* Uses a template element (content fragment) to parse HTML.
|
|
116
|
+
*
|
|
117
|
+
* @param html - HTML string.
|
|
118
|
+
* @returns - Nodes.
|
|
119
|
+
*/
|
|
120
|
+
parseFromTemplate = function (html) {
|
|
121
|
+
template.innerHTML = html;
|
|
122
|
+
return template.content.childNodes;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parses HTML string to DOM nodes.
|
|
127
|
+
*
|
|
128
|
+
* @param html - HTML markup.
|
|
129
|
+
* @returns - DOM nodes.
|
|
130
|
+
*/
|
|
131
|
+
function domparser(html) {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
var match = html.match(FIRST_TAG_REGEX);
|
|
134
|
+
var firstTagName = match && match[1] ? match[1].toLowerCase() : '';
|
|
135
|
+
switch (firstTagName) {
|
|
136
|
+
case HTML: {
|
|
137
|
+
var doc = parseFromString(html);
|
|
138
|
+
// the created document may come with filler head/body elements,
|
|
139
|
+
// so make sure to remove them if they don't actually exist
|
|
140
|
+
if (!HEAD_TAG_REGEX.test(html)) {
|
|
141
|
+
var element = doc.querySelector(HEAD);
|
|
142
|
+
(_a = element === null || element === void 0 ? void 0 : element.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(element);
|
|
143
|
+
}
|
|
144
|
+
if (!BODY_TAG_REGEX.test(html)) {
|
|
145
|
+
var element = doc.querySelector(BODY);
|
|
146
|
+
(_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
|
|
147
|
+
}
|
|
148
|
+
return doc.querySelectorAll(HTML);
|
|
149
|
+
}
|
|
150
|
+
case HEAD:
|
|
151
|
+
case BODY: {
|
|
152
|
+
var elements = parseFromDocument(html).querySelectorAll(firstTagName);
|
|
153
|
+
// if there's a sibling element, then return both elements
|
|
154
|
+
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
155
|
+
return elements[0].parentNode.childNodes;
|
|
156
|
+
}
|
|
157
|
+
return elements;
|
|
158
|
+
}
|
|
159
|
+
// low-level tag or text
|
|
160
|
+
default: {
|
|
161
|
+
if (parseFromTemplate) {
|
|
162
|
+
return parseFromTemplate(html);
|
|
163
|
+
}
|
|
164
|
+
var element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
165
|
+
return element.childNodes;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
domparser$1.default = domparser;
|
|
170
|
+
|
|
171
|
+
var utilities$2 = {};
|
|
172
|
+
|
|
13
173
|
var lib$2 = {};
|
|
14
174
|
|
|
15
175
|
var lib$1 = {};
|
|
@@ -714,149 +874,6 @@
|
|
|
714
874
|
exports.default = DomHandler;
|
|
715
875
|
} (lib$2));
|
|
716
876
|
|
|
717
|
-
var htmlToDom = {};
|
|
718
|
-
|
|
719
|
-
var domparser$1 = {};
|
|
720
|
-
|
|
721
|
-
Object.defineProperty(domparser$1, "__esModule", { value: true });
|
|
722
|
-
// constants
|
|
723
|
-
var HTML = 'html';
|
|
724
|
-
var HEAD = 'head';
|
|
725
|
-
var BODY = 'body';
|
|
726
|
-
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
|
|
727
|
-
// match-all-characters in case of newlines (DOTALL)
|
|
728
|
-
var HEAD_TAG_REGEX = /<head[^]*>/i;
|
|
729
|
-
var BODY_TAG_REGEX = /<body[^]*>/i;
|
|
730
|
-
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
731
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
732
|
-
var parseFromDocument = function (html, tagName) {
|
|
733
|
-
/* istanbul ignore next */
|
|
734
|
-
throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
|
|
735
|
-
};
|
|
736
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
737
|
-
var parseFromString = function (html, tagName) {
|
|
738
|
-
/* istanbul ignore next */
|
|
739
|
-
throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
|
|
740
|
-
};
|
|
741
|
-
var DOMParser = typeof window === 'object' && window.DOMParser;
|
|
742
|
-
/**
|
|
743
|
-
* DOMParser (performance: slow).
|
|
744
|
-
*
|
|
745
|
-
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
746
|
-
*/
|
|
747
|
-
if (typeof DOMParser === 'function') {
|
|
748
|
-
var domParser_1 = new DOMParser();
|
|
749
|
-
var mimeType_1 = 'text/html';
|
|
750
|
-
/**
|
|
751
|
-
* Creates an HTML document using `DOMParser.parseFromString`.
|
|
752
|
-
*
|
|
753
|
-
* @param html - The HTML string.
|
|
754
|
-
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
755
|
-
* @returns - Document.
|
|
756
|
-
*/
|
|
757
|
-
parseFromString = function (html, tagName) {
|
|
758
|
-
if (tagName) {
|
|
759
|
-
/* istanbul ignore next */
|
|
760
|
-
html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
|
|
761
|
-
}
|
|
762
|
-
return domParser_1.parseFromString(html, mimeType_1);
|
|
763
|
-
};
|
|
764
|
-
parseFromDocument = parseFromString;
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* DOMImplementation (performance: fair).
|
|
768
|
-
*
|
|
769
|
-
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
770
|
-
*/
|
|
771
|
-
if (typeof document === 'object' && document.implementation) {
|
|
772
|
-
var htmlDocument_1 = document.implementation.createHTMLDocument();
|
|
773
|
-
/**
|
|
774
|
-
* Use HTML document created by `document.implementation.createHTMLDocument`.
|
|
775
|
-
*
|
|
776
|
-
* @param html - The HTML string.
|
|
777
|
-
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
778
|
-
* @returns - Document
|
|
779
|
-
*/
|
|
780
|
-
parseFromDocument = function (html, tagName) {
|
|
781
|
-
if (tagName) {
|
|
782
|
-
var element = htmlDocument_1.documentElement.querySelector(tagName);
|
|
783
|
-
if (element) {
|
|
784
|
-
element.innerHTML = html;
|
|
785
|
-
}
|
|
786
|
-
return htmlDocument_1;
|
|
787
|
-
}
|
|
788
|
-
htmlDocument_1.documentElement.innerHTML = html;
|
|
789
|
-
return htmlDocument_1;
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
* Template (performance: fast).
|
|
794
|
-
*
|
|
795
|
-
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
796
|
-
*/
|
|
797
|
-
var template = typeof document === 'object' && document.createElement('template');
|
|
798
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
799
|
-
var parseFromTemplate;
|
|
800
|
-
if (template && template.content) {
|
|
801
|
-
/**
|
|
802
|
-
* Uses a template element (content fragment) to parse HTML.
|
|
803
|
-
*
|
|
804
|
-
* @param html - HTML string.
|
|
805
|
-
* @returns - Nodes.
|
|
806
|
-
*/
|
|
807
|
-
parseFromTemplate = function (html) {
|
|
808
|
-
template.innerHTML = html;
|
|
809
|
-
return template.content.childNodes;
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Parses HTML string to DOM nodes.
|
|
814
|
-
*
|
|
815
|
-
* @param html - HTML markup.
|
|
816
|
-
* @returns - DOM nodes.
|
|
817
|
-
*/
|
|
818
|
-
function domparser(html) {
|
|
819
|
-
var _a, _b;
|
|
820
|
-
var match = html.match(FIRST_TAG_REGEX);
|
|
821
|
-
var firstTagName = match && match[1] ? match[1].toLowerCase() : '';
|
|
822
|
-
switch (firstTagName) {
|
|
823
|
-
case HTML: {
|
|
824
|
-
var doc = parseFromString(html);
|
|
825
|
-
// the created document may come with filler head/body elements,
|
|
826
|
-
// so make sure to remove them if they don't actually exist
|
|
827
|
-
if (!HEAD_TAG_REGEX.test(html)) {
|
|
828
|
-
var element = doc.querySelector(HEAD);
|
|
829
|
-
(_a = element === null || element === void 0 ? void 0 : element.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(element);
|
|
830
|
-
}
|
|
831
|
-
if (!BODY_TAG_REGEX.test(html)) {
|
|
832
|
-
var element = doc.querySelector(BODY);
|
|
833
|
-
(_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
|
|
834
|
-
}
|
|
835
|
-
return doc.querySelectorAll(HTML);
|
|
836
|
-
}
|
|
837
|
-
case HEAD:
|
|
838
|
-
case BODY: {
|
|
839
|
-
var elements = parseFromDocument(html).querySelectorAll(firstTagName);
|
|
840
|
-
// if there's a sibling element, then return both elements
|
|
841
|
-
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
842
|
-
return elements[0].parentNode.childNodes;
|
|
843
|
-
}
|
|
844
|
-
return elements;
|
|
845
|
-
}
|
|
846
|
-
// low-level tag or text
|
|
847
|
-
default: {
|
|
848
|
-
if (parseFromTemplate) {
|
|
849
|
-
return parseFromTemplate(html);
|
|
850
|
-
}
|
|
851
|
-
var element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
852
|
-
return element.childNodes;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
domparser$1.default = domparser;
|
|
857
|
-
|
|
858
|
-
var utilities$4 = {};
|
|
859
|
-
|
|
860
877
|
var constants = {};
|
|
861
878
|
|
|
862
879
|
(function (exports) {
|
|
@@ -907,8 +924,8 @@
|
|
|
907
924
|
|
|
908
925
|
} (constants));
|
|
909
926
|
|
|
910
|
-
Object.defineProperty(utilities$
|
|
911
|
-
utilities$
|
|
927
|
+
Object.defineProperty(utilities$2, "__esModule", { value: true });
|
|
928
|
+
utilities$2.formatDOM = utilities$2.formatAttributes = void 0;
|
|
912
929
|
var domhandler_1 = lib$2;
|
|
913
930
|
var constants_1 = constants;
|
|
914
931
|
/**
|
|
@@ -937,7 +954,7 @@
|
|
|
937
954
|
}
|
|
938
955
|
return map;
|
|
939
956
|
}
|
|
940
|
-
utilities$
|
|
957
|
+
utilities$2.formatAttributes = formatAttributes;
|
|
941
958
|
/**
|
|
942
959
|
* Corrects the tag name if it is case-sensitive (SVG).
|
|
943
960
|
* Otherwise, returns the lowercase tag name (HTML).
|
|
@@ -1013,14 +1030,14 @@
|
|
|
1013
1030
|
}
|
|
1014
1031
|
return domNodes;
|
|
1015
1032
|
}
|
|
1016
|
-
utilities$
|
|
1033
|
+
utilities$2.formatDOM = formatDOM;
|
|
1017
1034
|
|
|
1018
|
-
var __importDefault$
|
|
1035
|
+
var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
1019
1036
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1020
1037
|
};
|
|
1021
1038
|
Object.defineProperty(htmlToDom, "__esModule", { value: true });
|
|
1022
|
-
var domparser_1 = __importDefault$
|
|
1023
|
-
var utilities_1$
|
|
1039
|
+
var domparser_1 = __importDefault$3(domparser$1);
|
|
1040
|
+
var utilities_1$3 = utilities$2;
|
|
1024
1041
|
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
1025
1042
|
/**
|
|
1026
1043
|
* Parses HTML string to DOM nodes in browser.
|
|
@@ -1038,10 +1055,12 @@
|
|
|
1038
1055
|
// match directive
|
|
1039
1056
|
var match = html.match(DIRECTIVE_REGEX);
|
|
1040
1057
|
var directive = match ? match[1] : undefined;
|
|
1041
|
-
return (0, utilities_1$
|
|
1058
|
+
return (0, utilities_1$3.formatDOM)((0, domparser_1.default)(html), null, directive);
|
|
1042
1059
|
}
|
|
1043
1060
|
htmlToDom.default = HTMLDOMParser;
|
|
1044
1061
|
|
|
1062
|
+
var attributesToProps$1 = {};
|
|
1063
|
+
|
|
1045
1064
|
var lib = {};
|
|
1046
1065
|
|
|
1047
1066
|
var possibleStandardNamesOptimized$1 = {};
|
|
@@ -2059,6 +2078,8 @@
|
|
|
2059
2078
|
lib.isCustomAttribute = isCustomAttribute;
|
|
2060
2079
|
lib.possibleStandardNames = possibleStandardNames;
|
|
2061
2080
|
|
|
2081
|
+
var utilities$1 = {};
|
|
2082
|
+
|
|
2062
2083
|
var cjs$1 = {};
|
|
2063
2084
|
|
|
2064
2085
|
var cjs = {};
|
|
@@ -2321,11 +2342,11 @@
|
|
|
2321
2342
|
return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
|
2322
2343
|
}
|
|
2323
2344
|
|
|
2324
|
-
var __importDefault$
|
|
2345
|
+
var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2325
2346
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2326
2347
|
};
|
|
2327
2348
|
Object.defineProperty(cjs, "__esModule", { value: true });
|
|
2328
|
-
var inline_style_parser_1 = __importDefault$
|
|
2349
|
+
var inline_style_parser_1 = __importDefault$2(inlineStyleParser);
|
|
2329
2350
|
/**
|
|
2330
2351
|
* Parses inline style to object.
|
|
2331
2352
|
*
|
|
@@ -2364,10 +2385,10 @@
|
|
|
2364
2385
|
}
|
|
2365
2386
|
cjs.default = StyleToObject;
|
|
2366
2387
|
|
|
2367
|
-
var utilities
|
|
2388
|
+
var utilities = {};
|
|
2368
2389
|
|
|
2369
|
-
Object.defineProperty(utilities
|
|
2370
|
-
utilities
|
|
2390
|
+
Object.defineProperty(utilities, "__esModule", { value: true });
|
|
2391
|
+
utilities.camelCase = void 0;
|
|
2371
2392
|
var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
|
|
2372
2393
|
var HYPHEN_REGEX = /-([a-z])/g;
|
|
2373
2394
|
var NO_HYPHEN_REGEX = /^[^-]+$/;
|
|
@@ -2410,14 +2431,14 @@
|
|
|
2410
2431
|
}
|
|
2411
2432
|
return property.replace(HYPHEN_REGEX, capitalize);
|
|
2412
2433
|
};
|
|
2413
|
-
utilities
|
|
2434
|
+
utilities.camelCase = camelCase;
|
|
2414
2435
|
|
|
2415
|
-
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2436
|
+
var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2416
2437
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2417
2438
|
};
|
|
2418
2439
|
Object.defineProperty(cjs$1, "__esModule", { value: true });
|
|
2419
|
-
var style_to_object_1 = __importDefault(cjs);
|
|
2420
|
-
var utilities_1 = utilities
|
|
2440
|
+
var style_to_object_1 = __importDefault$1(cjs);
|
|
2441
|
+
var utilities_1$2 = utilities;
|
|
2421
2442
|
/**
|
|
2422
2443
|
* Parses CSS inline style to JavaScript object (camelCased).
|
|
2423
2444
|
*/
|
|
@@ -2429,408 +2450,364 @@
|
|
|
2429
2450
|
(0, style_to_object_1.default)(style, function (property, value) {
|
|
2430
2451
|
// skip CSS comment
|
|
2431
2452
|
if (property && value) {
|
|
2432
|
-
output[(0, utilities_1.camelCase)(property, options)] = value;
|
|
2453
|
+
output[(0, utilities_1$2.camelCase)(property, options)] = value;
|
|
2433
2454
|
}
|
|
2434
2455
|
});
|
|
2435
2456
|
return output;
|
|
2436
2457
|
}
|
|
2437
2458
|
cjs$1.default = StyleToJS;
|
|
2438
2459
|
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
var reactProperty = lib;
|
|
2546
|
-
var utilities$1 = utilities$2;
|
|
2460
|
+
(function (exports) {
|
|
2461
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2462
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2463
|
+
};
|
|
2464
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2465
|
+
exports.returnFirstArg = exports.canTextBeChildOfNode = exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = exports.PRESERVE_CUSTOM_ATTRIBUTES = exports.setStyleProp = exports.isCustomComponent = void 0;
|
|
2466
|
+
var react_1 = require$$0;
|
|
2467
|
+
var style_to_js_1 = __importDefault(cjs$1);
|
|
2468
|
+
var RESERVED_SVG_MATHML_ELEMENTS = new Set([
|
|
2469
|
+
'annotation-xml',
|
|
2470
|
+
'color-profile',
|
|
2471
|
+
'font-face',
|
|
2472
|
+
'font-face-src',
|
|
2473
|
+
'font-face-uri',
|
|
2474
|
+
'font-face-format',
|
|
2475
|
+
'font-face-name',
|
|
2476
|
+
'missing-glyph',
|
|
2477
|
+
]);
|
|
2478
|
+
/**
|
|
2479
|
+
* Check if a tag is a custom component.
|
|
2480
|
+
*
|
|
2481
|
+
* @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
|
|
2482
|
+
*
|
|
2483
|
+
* @param tagName - Tag name.
|
|
2484
|
+
* @param props - Props passed to the element.
|
|
2485
|
+
* @returns - Whether the tag is custom component.
|
|
2486
|
+
*/
|
|
2487
|
+
function isCustomComponent(tagName, props) {
|
|
2488
|
+
if (tagName.indexOf('-') === -1) {
|
|
2489
|
+
return Boolean(props && typeof props.is === 'string');
|
|
2490
|
+
}
|
|
2491
|
+
// These are reserved SVG and MathML elements.
|
|
2492
|
+
// We don't mind this whitelist too much because we expect it to never grow.
|
|
2493
|
+
// The alternative is to track the namespace in a few places which is convoluted.
|
|
2494
|
+
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
|
|
2495
|
+
if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
|
|
2496
|
+
return false;
|
|
2497
|
+
}
|
|
2498
|
+
return true;
|
|
2499
|
+
}
|
|
2500
|
+
exports.isCustomComponent = isCustomComponent;
|
|
2501
|
+
var styleOptions = {
|
|
2502
|
+
reactCompat: true,
|
|
2503
|
+
};
|
|
2504
|
+
/**
|
|
2505
|
+
* Sets style prop.
|
|
2506
|
+
*
|
|
2507
|
+
* @param style - Inline style.
|
|
2508
|
+
* @param props - Props object.
|
|
2509
|
+
*/
|
|
2510
|
+
function setStyleProp(style, props) {
|
|
2511
|
+
if (typeof style !== 'string') {
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
if (!style.trim()) {
|
|
2515
|
+
props.style = {};
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
try {
|
|
2519
|
+
props.style = (0, style_to_js_1.default)(style, styleOptions);
|
|
2520
|
+
}
|
|
2521
|
+
catch (error) {
|
|
2522
|
+
props.style = {};
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
exports.setStyleProp = setStyleProp;
|
|
2526
|
+
/**
|
|
2527
|
+
* @see https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
|
|
2528
|
+
*/
|
|
2529
|
+
exports.PRESERVE_CUSTOM_ATTRIBUTES = Number(react_1.version.split('.')[0]) >= 16;
|
|
2530
|
+
/**
|
|
2531
|
+
* @see https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
|
|
2532
|
+
*/
|
|
2533
|
+
exports.ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
|
|
2534
|
+
'tr',
|
|
2535
|
+
'tbody',
|
|
2536
|
+
'thead',
|
|
2537
|
+
'tfoot',
|
|
2538
|
+
'colgroup',
|
|
2539
|
+
'table',
|
|
2540
|
+
'head',
|
|
2541
|
+
'html',
|
|
2542
|
+
'frameset',
|
|
2543
|
+
]);
|
|
2544
|
+
/**
|
|
2545
|
+
* Checks if the given node can contain text nodes
|
|
2546
|
+
*
|
|
2547
|
+
* @param node - Element node.
|
|
2548
|
+
* @returns - Whether the node can contain text nodes.
|
|
2549
|
+
*/
|
|
2550
|
+
var canTextBeChildOfNode = function (node) {
|
|
2551
|
+
return !exports.ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
|
|
2552
|
+
};
|
|
2553
|
+
exports.canTextBeChildOfNode = canTextBeChildOfNode;
|
|
2554
|
+
/**
|
|
2555
|
+
* Returns the first argument as is.
|
|
2556
|
+
*
|
|
2557
|
+
* @param arg - The argument to be returned.
|
|
2558
|
+
* @returns - The input argument `arg`.
|
|
2559
|
+
*/
|
|
2560
|
+
var returnFirstArg = function (arg) { return arg; };
|
|
2561
|
+
exports.returnFirstArg = returnFirstArg;
|
|
2562
|
+
|
|
2563
|
+
} (utilities$1));
|
|
2547
2564
|
|
|
2548
|
-
|
|
2565
|
+
Object.defineProperty(attributesToProps$1, "__esModule", { value: true });
|
|
2566
|
+
var react_property_1 = lib;
|
|
2567
|
+
var utilities_1$1 = utilities$1;
|
|
2568
|
+
// https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
|
|
2549
2569
|
// https://developer.mozilla.org/docs/Web/HTML/Attributes
|
|
2550
2570
|
var UNCONTROLLED_COMPONENT_ATTRIBUTES = ['checked', 'value'];
|
|
2551
2571
|
var UNCONTROLLED_COMPONENT_NAMES = ['input', 'select', 'textarea'];
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
submit: true
|
|
2572
|
+
var valueOnlyInputs = {
|
|
2573
|
+
reset: true,
|
|
2574
|
+
submit: true,
|
|
2556
2575
|
};
|
|
2557
|
-
|
|
2558
2576
|
/**
|
|
2559
2577
|
* Converts HTML/SVG DOM attributes to React props.
|
|
2560
2578
|
*
|
|
2561
|
-
* @param
|
|
2562
|
-
* @param
|
|
2579
|
+
* @param attributes - HTML/SVG DOM attributes.
|
|
2580
|
+
* @param nodeName - DOM node name.
|
|
2563
2581
|
* @returns - React props.
|
|
2564
2582
|
*/
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
props[propName] = true;
|
|
2606
|
-
break;
|
|
2607
|
-
case reactProperty.OVERLOADED_BOOLEAN:
|
|
2608
|
-
if (attributeValue === '') {
|
|
2609
|
-
props[propName] = true;
|
|
2610
|
-
}
|
|
2611
|
-
break;
|
|
2612
|
-
}
|
|
2613
|
-
continue;
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
// preserve custom attribute if React >=16
|
|
2617
|
-
if (utilities$1.PRESERVE_CUSTOM_ATTRIBUTES) {
|
|
2618
|
-
props[attributeName] = attributeValue;
|
|
2583
|
+
function attributesToProps(attributes, nodeName) {
|
|
2584
|
+
if (attributes === void 0) { attributes = {}; }
|
|
2585
|
+
var props = {};
|
|
2586
|
+
var isInputValueOnly = Boolean(attributes.type &&
|
|
2587
|
+
valueOnlyInputs[attributes.type]);
|
|
2588
|
+
for (var attributeName in attributes) {
|
|
2589
|
+
var attributeValue = attributes[attributeName];
|
|
2590
|
+
// ARIA (aria-*) or custom data (data-*) attribute
|
|
2591
|
+
if ((0, react_property_1.isCustomAttribute)(attributeName)) {
|
|
2592
|
+
props[attributeName] = attributeValue;
|
|
2593
|
+
continue;
|
|
2594
|
+
}
|
|
2595
|
+
// convert HTML/SVG attribute to React prop
|
|
2596
|
+
var attributeNameLowerCased = attributeName.toLowerCase();
|
|
2597
|
+
var propName = getPropName(attributeNameLowerCased);
|
|
2598
|
+
if (propName) {
|
|
2599
|
+
var propertyInfo = (0, react_property_1.getPropertyInfo)(propName);
|
|
2600
|
+
// convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
|
|
2601
|
+
if (UNCONTROLLED_COMPONENT_ATTRIBUTES.indexOf(propName) !== -1 &&
|
|
2602
|
+
UNCONTROLLED_COMPONENT_NAMES.indexOf(nodeName) !== -1 &&
|
|
2603
|
+
!isInputValueOnly) {
|
|
2604
|
+
propName = getPropName('default' + attributeNameLowerCased);
|
|
2605
|
+
}
|
|
2606
|
+
props[propName] = attributeValue;
|
|
2607
|
+
switch (propertyInfo && propertyInfo.type) {
|
|
2608
|
+
case react_property_1.BOOLEAN:
|
|
2609
|
+
props[propName] = true;
|
|
2610
|
+
break;
|
|
2611
|
+
case react_property_1.OVERLOADED_BOOLEAN:
|
|
2612
|
+
if (attributeValue === '') {
|
|
2613
|
+
props[propName] = true;
|
|
2614
|
+
}
|
|
2615
|
+
break;
|
|
2616
|
+
}
|
|
2617
|
+
continue;
|
|
2618
|
+
}
|
|
2619
|
+
// preserve custom attribute if React >=16
|
|
2620
|
+
if (utilities_1$1.PRESERVE_CUSTOM_ATTRIBUTES) {
|
|
2621
|
+
props[attributeName] = attributeValue;
|
|
2622
|
+
}
|
|
2619
2623
|
}
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
return props;
|
|
2626
|
-
};
|
|
2627
|
-
|
|
2624
|
+
// transform inline style to object
|
|
2625
|
+
(0, utilities_1$1.setStyleProp)(attributes.style, props);
|
|
2626
|
+
return props;
|
|
2627
|
+
}
|
|
2628
|
+
attributesToProps$1.default = attributesToProps;
|
|
2628
2629
|
/**
|
|
2629
2630
|
* Gets prop name from lowercased attribute name.
|
|
2630
2631
|
*
|
|
2631
|
-
* @param
|
|
2632
|
+
* @param attributeName - Lowercased attribute name.
|
|
2632
2633
|
* @returns - Prop name.
|
|
2633
2634
|
*/
|
|
2634
2635
|
function getPropName(attributeName) {
|
|
2635
|
-
|
|
2636
|
+
return react_property_1.possibleStandardNames[attributeName];
|
|
2636
2637
|
}
|
|
2637
2638
|
|
|
2638
|
-
var
|
|
2639
|
-
var attributesToProps$1 = attributesToProps$2;
|
|
2640
|
-
var utilities = utilities$2;
|
|
2641
|
-
|
|
2642
|
-
var setStyleProp = utilities.setStyleProp;
|
|
2643
|
-
var canTextBeChildOfNode = utilities.canTextBeChildOfNode;
|
|
2639
|
+
var domToReact$1 = {};
|
|
2644
2640
|
|
|
2641
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2642
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2643
|
+
};
|
|
2644
|
+
Object.defineProperty(domToReact$1, "__esModule", { value: true });
|
|
2645
|
+
var react_1 = require$$0;
|
|
2646
|
+
var attributes_to_props_1 = __importDefault(attributesToProps$1);
|
|
2647
|
+
var utilities_1 = utilities$1;
|
|
2648
|
+
var React = {
|
|
2649
|
+
cloneElement: react_1.cloneElement,
|
|
2650
|
+
createElement: react_1.createElement,
|
|
2651
|
+
isValidElement: react_1.isValidElement,
|
|
2652
|
+
};
|
|
2645
2653
|
/**
|
|
2646
2654
|
* Converts DOM nodes to JSX element(s).
|
|
2647
2655
|
*
|
|
2648
|
-
* @param
|
|
2649
|
-
* @param
|
|
2650
|
-
* @param {Function} [options.replace] - Replacer.
|
|
2651
|
-
* @param {Function} [options.transform] - Transform.
|
|
2652
|
-
* @param {object} [options.library] - Library (React, Preact, etc.).
|
|
2656
|
+
* @param nodes - DOM nodes.
|
|
2657
|
+
* @param options - Options.
|
|
2653
2658
|
* @returns - String or JSX element(s).
|
|
2654
2659
|
*/
|
|
2655
|
-
function domToReact
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
replaceElement = options.replace(node);
|
|
2679
|
-
|
|
2680
|
-
if (isValidElement(replaceElement)) {
|
|
2681
|
-
// set "key" prop for sibling elements
|
|
2682
|
-
// https://fb.me/react-warning-keys
|
|
2683
|
-
if (len > 1) {
|
|
2684
|
-
replaceElement = cloneElement(replaceElement, {
|
|
2685
|
-
key: replaceElement.key || i
|
|
2686
|
-
});
|
|
2660
|
+
function domToReact(nodes, options) {
|
|
2661
|
+
var reactElements = [];
|
|
2662
|
+
var hasReplace = typeof (options === null || options === void 0 ? void 0 : options.replace) === 'function';
|
|
2663
|
+
var transform = (options === null || options === void 0 ? void 0 : options.transform) || utilities_1.returnFirstArg;
|
|
2664
|
+
var _a = (options === null || options === void 0 ? void 0 : options.library) || React, cloneElement = _a.cloneElement, createElement = _a.createElement, isValidElement = _a.isValidElement;
|
|
2665
|
+
var index = 0;
|
|
2666
|
+
var nodesLength = nodes.length;
|
|
2667
|
+
for (; index < nodesLength; index++) {
|
|
2668
|
+
var node = nodes[index];
|
|
2669
|
+
// replace with custom React element (if present)
|
|
2670
|
+
if (hasReplace) {
|
|
2671
|
+
var replaceElement = options.replace(node);
|
|
2672
|
+
if (isValidElement(replaceElement)) {
|
|
2673
|
+
// set "key" prop for sibling elements
|
|
2674
|
+
// https://react.dev/learn/rendering-lists#rules-of-keys
|
|
2675
|
+
if (nodesLength > 1) {
|
|
2676
|
+
replaceElement = cloneElement(replaceElement, {
|
|
2677
|
+
key: replaceElement.key || index,
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
reactElements.push(transform(replaceElement, node, index));
|
|
2681
|
+
continue;
|
|
2682
|
+
}
|
|
2687
2683
|
}
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
// We have a text node that's not whitespace and it can be nested
|
|
2709
|
-
// in its parent so add it to the results
|
|
2710
|
-
result.push(transform(node.data, node, i));
|
|
2711
|
-
continue;
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
props = node.attribs;
|
|
2715
|
-
if (skipAttributesToProps(node)) {
|
|
2716
|
-
setStyleProp(props.style, props);
|
|
2717
|
-
} else if (props) {
|
|
2718
|
-
props = attributesToProps$1(props, node.name);
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
children = null;
|
|
2722
|
-
|
|
2723
|
-
switch (node.type) {
|
|
2724
|
-
case 'script':
|
|
2725
|
-
case 'style':
|
|
2726
|
-
// prevent text in <script> or <style> from being escaped
|
|
2727
|
-
// https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
|
|
2728
|
-
if (node.children[0]) {
|
|
2729
|
-
props.dangerouslySetInnerHTML = {
|
|
2730
|
-
__html: node.children[0].data
|
|
2731
|
-
};
|
|
2684
|
+
if (node.type === 'text') {
|
|
2685
|
+
var isWhitespace = !node.data.trim().length;
|
|
2686
|
+
// We have a whitespace node that can't be nested in its parent
|
|
2687
|
+
// so skip it
|
|
2688
|
+
if (isWhitespace &&
|
|
2689
|
+
node.parent &&
|
|
2690
|
+
!(0, utilities_1.canTextBeChildOfNode)(node.parent)) {
|
|
2691
|
+
continue;
|
|
2692
|
+
}
|
|
2693
|
+
// Trim is enabled and we have a whitespace node
|
|
2694
|
+
// so skip it
|
|
2695
|
+
if ((options === null || options === void 0 ? void 0 : options.trim) && isWhitespace) {
|
|
2696
|
+
continue;
|
|
2697
|
+
}
|
|
2698
|
+
// We have a text node that's not whitespace and it can be nested
|
|
2699
|
+
// in its parent so add it to the results
|
|
2700
|
+
reactElements.push(transform(node.data, node, index));
|
|
2701
|
+
continue;
|
|
2732
2702
|
}
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
if (node.name === 'textarea' && node.children[0]) {
|
|
2739
|
-
props.defaultValue = node.children[0].data;
|
|
2740
|
-
} else if (node.children && node.children.length) {
|
|
2741
|
-
// continue recursion of creating React elements (if applicable)
|
|
2742
|
-
children = domToReact$1(node.children, options);
|
|
2703
|
+
var element = node;
|
|
2704
|
+
var props = {};
|
|
2705
|
+
if (skipAttributesToProps(element)) {
|
|
2706
|
+
(0, utilities_1.setStyleProp)(element.attribs.style, element.attribs);
|
|
2707
|
+
props = element.attribs;
|
|
2743
2708
|
}
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2709
|
+
else if (element.attribs) {
|
|
2710
|
+
props = (0, attributes_to_props_1.default)(element.attribs, element.name);
|
|
2711
|
+
}
|
|
2712
|
+
var children = null;
|
|
2713
|
+
switch (node.type) {
|
|
2714
|
+
case 'script':
|
|
2715
|
+
case 'style':
|
|
2716
|
+
// prevent text in <script> or <style> from being escaped
|
|
2717
|
+
// https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html
|
|
2718
|
+
if (node.children[0]) {
|
|
2719
|
+
props.dangerouslySetInnerHTML = {
|
|
2720
|
+
__html: node.children[0].data,
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
break;
|
|
2724
|
+
case 'tag':
|
|
2725
|
+
// setting textarea value in children is an antipattern in React
|
|
2726
|
+
// https://react.dev/reference/react-dom/components/textarea#caveats
|
|
2727
|
+
if (node.name === 'textarea' && node.children[0]) {
|
|
2728
|
+
props.defaultValue = node.children[0].data;
|
|
2729
|
+
}
|
|
2730
|
+
else if (node.children && node.children.length) {
|
|
2731
|
+
// continue recursion of creating React elements (if applicable)
|
|
2732
|
+
children = domToReact(node.children, options);
|
|
2733
|
+
}
|
|
2734
|
+
break;
|
|
2735
|
+
// skip all other cases (e.g., comment)
|
|
2736
|
+
default:
|
|
2737
|
+
continue;
|
|
2738
|
+
}
|
|
2739
|
+
// set "key" prop for sibling elements
|
|
2740
|
+
// https://react.dev/learn/rendering-lists#rules-of-keys
|
|
2741
|
+
if (nodesLength > 1) {
|
|
2742
|
+
props.key = index;
|
|
2743
|
+
}
|
|
2744
|
+
reactElements.push(transform(createElement(node.name, props, children), node, index));
|
|
2755
2745
|
}
|
|
2756
|
-
|
|
2757
|
-
result.push(transform(createElement(node.name, props, children), node, i));
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
return result.length === 1 ? result[0] : result;
|
|
2746
|
+
return reactElements.length === 1 ? reactElements[0] : reactElements;
|
|
2761
2747
|
}
|
|
2762
|
-
|
|
2748
|
+
domToReact$1.default = domToReact;
|
|
2763
2749
|
/**
|
|
2764
2750
|
* Determines whether DOM element attributes should be transformed to props.
|
|
2765
2751
|
* Web Components should not have their attributes transformed except for `style`.
|
|
2766
2752
|
*
|
|
2767
|
-
* @param
|
|
2768
|
-
* @returns - Whether node attributes should be converted to props.
|
|
2753
|
+
* @param node - Element node.
|
|
2754
|
+
* @returns - Whether the node attributes should be converted to props.
|
|
2769
2755
|
*/
|
|
2770
2756
|
function skipAttributesToProps(node) {
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
utilities.isCustomComponent(node.name, node.attribs)
|
|
2775
|
-
);
|
|
2776
|
-
}
|
|
2777
|
-
|
|
2778
|
-
var domToReact_1 = domToReact$1;
|
|
2779
|
-
|
|
2780
|
-
var domhandler = lib$2;
|
|
2781
|
-
var htmlToDOM = htmlToDom.default;
|
|
2782
|
-
|
|
2783
|
-
var attributesToProps = attributesToProps$2;
|
|
2784
|
-
var domToReact = domToReact_1;
|
|
2785
|
-
|
|
2786
|
-
// support backwards compatibility for ES Module
|
|
2787
|
-
htmlToDOM =
|
|
2788
|
-
/* istanbul ignore next */
|
|
2789
|
-
typeof htmlToDOM.default === 'function' ? htmlToDOM.default : htmlToDOM;
|
|
2790
|
-
|
|
2791
|
-
var domParserOptions = { lowerCaseAttributeNames: false };
|
|
2792
|
-
|
|
2793
|
-
/**
|
|
2794
|
-
* Converts HTML string to React elements.
|
|
2795
|
-
*
|
|
2796
|
-
* @param {string} html - HTML string.
|
|
2797
|
-
* @param {object} [options] - Parser options.
|
|
2798
|
-
* @param {object} [options.htmlparser2] - htmlparser2 options.
|
|
2799
|
-
* @param {object} [options.library] - Library for React, Preact, etc.
|
|
2800
|
-
* @param {Function} [options.replace] - Replace method.
|
|
2801
|
-
* @returns {JSX.Element|JSX.Element[]|string} - React element(s), empty array, or string.
|
|
2802
|
-
*/
|
|
2803
|
-
function HTMLReactParser(html, options) {
|
|
2804
|
-
if (typeof html !== 'string') {
|
|
2805
|
-
throw new TypeError('First argument must be a string');
|
|
2806
|
-
}
|
|
2807
|
-
if (html === '') {
|
|
2808
|
-
return [];
|
|
2809
|
-
}
|
|
2810
|
-
options = options || {};
|
|
2811
|
-
return domToReact(
|
|
2812
|
-
htmlToDOM(html, options.htmlparser2 || domParserOptions),
|
|
2813
|
-
options
|
|
2814
|
-
);
|
|
2757
|
+
return (utilities_1.PRESERVE_CUSTOM_ATTRIBUTES &&
|
|
2758
|
+
node.type === 'tag' &&
|
|
2759
|
+
(0, utilities_1.isCustomComponent)(node.name, node.attribs));
|
|
2815
2760
|
}
|
|
2816
2761
|
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2762
|
+
(function (exports) {
|
|
2763
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2764
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2765
|
+
};
|
|
2766
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2767
|
+
exports.htmlToDOM = exports.domToReact = exports.attributesToProps = exports.Text = exports.ProcessingInstruction = exports.Element = exports.Comment = void 0;
|
|
2768
|
+
var html_dom_parser_1 = __importDefault(htmlToDom);
|
|
2769
|
+
exports.htmlToDOM = html_dom_parser_1.default;
|
|
2770
|
+
var attributes_to_props_1 = __importDefault(attributesToProps$1);
|
|
2771
|
+
exports.attributesToProps = attributes_to_props_1.default;
|
|
2772
|
+
var dom_to_react_1 = __importDefault(domToReact$1);
|
|
2773
|
+
exports.domToReact = dom_to_react_1.default;
|
|
2774
|
+
var domhandler_1 = lib$2;
|
|
2775
|
+
Object.defineProperty(exports, "Comment", { enumerable: true, get: function () { return domhandler_1.Comment; } });
|
|
2776
|
+
Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return domhandler_1.Element; } });
|
|
2777
|
+
Object.defineProperty(exports, "ProcessingInstruction", { enumerable: true, get: function () { return domhandler_1.ProcessingInstruction; } });
|
|
2778
|
+
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return domhandler_1.Text; } });
|
|
2779
|
+
var domParserOptions = { lowerCaseAttributeNames: false };
|
|
2780
|
+
/**
|
|
2781
|
+
* Converts HTML string to React elements.
|
|
2782
|
+
*
|
|
2783
|
+
* @param html - HTML string.
|
|
2784
|
+
* @param options - Parser options.
|
|
2785
|
+
* @returns - React element(s), empty array, or string.
|
|
2786
|
+
*/
|
|
2787
|
+
function HTMLReactParser(html, options) {
|
|
2788
|
+
if (typeof html !== 'string') {
|
|
2789
|
+
throw new TypeError('First argument must be a string');
|
|
2790
|
+
}
|
|
2791
|
+
if (!html) {
|
|
2792
|
+
return [];
|
|
2793
|
+
}
|
|
2794
|
+
return (0, dom_to_react_1.default)((0, html_dom_parser_1.default)(html, (options === null || options === void 0 ? void 0 : options.htmlparser2) || domParserOptions), options);
|
|
2795
|
+
}
|
|
2796
|
+
exports.default = HTMLReactParser;
|
|
2797
|
+
|
|
2798
|
+
} (lib$3));
|
|
2820
2799
|
|
|
2821
|
-
|
|
2822
|
-
HTMLReactParser.Comment = domhandler.Comment;
|
|
2823
|
-
HTMLReactParser.Element = domhandler.Element;
|
|
2824
|
-
HTMLReactParser.ProcessingInstruction = domhandler.ProcessingInstruction;
|
|
2825
|
-
HTMLReactParser.Text = domhandler.Text;
|
|
2800
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(lib$3);
|
|
2826
2801
|
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2802
|
+
var HTMLReactParser = /*#__PURE__*/_mergeNamespaces({
|
|
2803
|
+
__proto__: null,
|
|
2804
|
+
default: index
|
|
2805
|
+
}, [lib$3]);
|
|
2830
2806
|
|
|
2831
|
-
|
|
2807
|
+
const parse = index;
|
|
2808
|
+
Object.assign(parse, HTMLReactParser);
|
|
2832
2809
|
|
|
2833
|
-
return
|
|
2810
|
+
return parse;
|
|
2834
2811
|
|
|
2835
2812
|
}));
|
|
2836
2813
|
//# sourceMappingURL=html-react-parser.js.map
|