@wordpress/element 6.32.0 → 6.32.1-next.47f435fc9.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/build/create-interpolate-element.js +79 -183
- package/build/create-interpolate-element.js.map +7 -1
- package/build/index.js +52 -74
- package/build/index.js.map +7 -1
- package/build/platform.android.js +29 -16
- package/build/platform.android.js.map +7 -1
- package/build/platform.ios.js +29 -16
- package/build/platform.ios.js.map +7 -1
- package/build/platform.js +25 -40
- package/build/platform.js.map +7 -1
- package/build/raw-html.js +28 -47
- package/build/raw-html.js.map +7 -1
- package/build/react-platform.js +43 -55
- package/build/react-platform.js.map +7 -1
- package/build/react.js +114 -411
- package/build/react.js.map +7 -1
- package/build/serialize.js +418 -325
- package/build/serialize.js.map +7 -1
- package/build/utils.js +29 -15
- package/build/utils.js.map +7 -1
- package/build-module/create-interpolate-element.js +63 -175
- package/build-module/create-interpolate-element.js.map +7 -1
- package/build-module/index.js +14 -8
- package/build-module/index.js.map +7 -1
- package/build-module/platform.android.js +10 -10
- package/build-module/platform.android.js.map +7 -1
- package/build-module/platform.ios.js +10 -10
- package/build-module/platform.ios.js.map +7 -1
- package/build-module/platform.js +7 -36
- package/build-module/platform.js.map +7 -1
- package/build-module/raw-html.js +11 -44
- package/build-module/raw-html.js.map +7 -1
- package/build-module/react-platform.js +20 -71
- package/build-module/react-platform.js.map +7 -1
- package/build-module/react.js +91 -255
- package/build-module/react.js.map +7 -1
- package/build-module/serialize.js +382 -311
- package/build-module/serialize.js.map +7 -1
- package/build-module/utils.js +7 -10
- package/build-module/utils.js.map +7 -1
- package/package.json +11 -4
- package/build/react-platform.native.js +0 -22
- package/build/react-platform.native.js.map +0 -1
- package/build-module/react-platform.native.js +0 -15
- package/build-module/react-platform.native.js.map +0 -1
|
@@ -1,322 +1,421 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
15
|
-
*
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in
|
|
17
|
-
* all copies or substantial portions of the Software.
|
|
18
|
-
*
|
|
19
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
-
* THE SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* External dependencies
|
|
30
|
-
*/
|
|
31
|
-
import { isPlainObject } from 'is-plain-object';
|
|
32
|
-
import { paramCase as kebabCase } from 'change-case';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* WordPress dependencies
|
|
36
|
-
*/
|
|
37
|
-
import { escapeHTML, escapeAttribute, isValidAttributeName } from '@wordpress/escape-html';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Internal dependencies
|
|
41
|
-
*/
|
|
42
|
-
import { createContext, Fragment, StrictMode, forwardRef } from './react';
|
|
43
|
-
import RawHTML from './raw-html';
|
|
44
|
-
|
|
45
|
-
/** @typedef {import('react').ReactElement} ReactElement */
|
|
46
|
-
|
|
47
|
-
const Context = createContext(undefined);
|
|
48
|
-
Context.displayName = 'ElementContext';
|
|
49
|
-
const {
|
|
50
|
-
Provider,
|
|
51
|
-
Consumer
|
|
52
|
-
} = Context;
|
|
1
|
+
import { isPlainObject } from "is-plain-object";
|
|
2
|
+
import { paramCase as kebabCase } from "change-case";
|
|
3
|
+
import {
|
|
4
|
+
escapeHTML,
|
|
5
|
+
escapeAttribute,
|
|
6
|
+
isValidAttributeName
|
|
7
|
+
} from "@wordpress/escape-html";
|
|
8
|
+
import { createContext, Fragment, StrictMode, forwardRef } from "./react";
|
|
9
|
+
import RawHTML from "./raw-html";
|
|
10
|
+
const Context = createContext(void 0);
|
|
11
|
+
Context.displayName = "ElementContext";
|
|
12
|
+
const { Provider, Consumer } = Context;
|
|
53
13
|
const ForwardRef = forwardRef(() => {
|
|
54
14
|
return null;
|
|
55
15
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
16
|
+
const ATTRIBUTES_TYPES = /* @__PURE__ */ new Set(["string", "boolean", "number"]);
|
|
17
|
+
const SELF_CLOSING_TAGS = /* @__PURE__ */ new Set([
|
|
18
|
+
"area",
|
|
19
|
+
"base",
|
|
20
|
+
"br",
|
|
21
|
+
"col",
|
|
22
|
+
"command",
|
|
23
|
+
"embed",
|
|
24
|
+
"hr",
|
|
25
|
+
"img",
|
|
26
|
+
"input",
|
|
27
|
+
"keygen",
|
|
28
|
+
"link",
|
|
29
|
+
"meta",
|
|
30
|
+
"param",
|
|
31
|
+
"source",
|
|
32
|
+
"track",
|
|
33
|
+
"wbr"
|
|
34
|
+
]);
|
|
35
|
+
const BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
36
|
+
"allowfullscreen",
|
|
37
|
+
"allowpaymentrequest",
|
|
38
|
+
"allowusermedia",
|
|
39
|
+
"async",
|
|
40
|
+
"autofocus",
|
|
41
|
+
"autoplay",
|
|
42
|
+
"checked",
|
|
43
|
+
"controls",
|
|
44
|
+
"default",
|
|
45
|
+
"defer",
|
|
46
|
+
"disabled",
|
|
47
|
+
"download",
|
|
48
|
+
"formnovalidate",
|
|
49
|
+
"hidden",
|
|
50
|
+
"ismap",
|
|
51
|
+
"itemscope",
|
|
52
|
+
"loop",
|
|
53
|
+
"multiple",
|
|
54
|
+
"muted",
|
|
55
|
+
"nomodule",
|
|
56
|
+
"novalidate",
|
|
57
|
+
"open",
|
|
58
|
+
"playsinline",
|
|
59
|
+
"readonly",
|
|
60
|
+
"required",
|
|
61
|
+
"reversed",
|
|
62
|
+
"selected",
|
|
63
|
+
"typemustmatch"
|
|
64
|
+
]);
|
|
65
|
+
const ENUMERATED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
66
|
+
"autocapitalize",
|
|
67
|
+
"autocomplete",
|
|
68
|
+
"charset",
|
|
69
|
+
"contenteditable",
|
|
70
|
+
"crossorigin",
|
|
71
|
+
"decoding",
|
|
72
|
+
"dir",
|
|
73
|
+
"draggable",
|
|
74
|
+
"enctype",
|
|
75
|
+
"formenctype",
|
|
76
|
+
"formmethod",
|
|
77
|
+
"http-equiv",
|
|
78
|
+
"inputmode",
|
|
79
|
+
"kind",
|
|
80
|
+
"method",
|
|
81
|
+
"preload",
|
|
82
|
+
"scope",
|
|
83
|
+
"shape",
|
|
84
|
+
"spellcheck",
|
|
85
|
+
"translate",
|
|
86
|
+
"type",
|
|
87
|
+
"wrap"
|
|
88
|
+
]);
|
|
89
|
+
const CSS_PROPERTIES_SUPPORTS_UNITLESS = /* @__PURE__ */ new Set([
|
|
90
|
+
"animation",
|
|
91
|
+
"animationIterationCount",
|
|
92
|
+
"baselineShift",
|
|
93
|
+
"borderImageOutset",
|
|
94
|
+
"borderImageSlice",
|
|
95
|
+
"borderImageWidth",
|
|
96
|
+
"columnCount",
|
|
97
|
+
"cx",
|
|
98
|
+
"cy",
|
|
99
|
+
"fillOpacity",
|
|
100
|
+
"flexGrow",
|
|
101
|
+
"flexShrink",
|
|
102
|
+
"floodOpacity",
|
|
103
|
+
"fontWeight",
|
|
104
|
+
"gridColumnEnd",
|
|
105
|
+
"gridColumnStart",
|
|
106
|
+
"gridRowEnd",
|
|
107
|
+
"gridRowStart",
|
|
108
|
+
"lineHeight",
|
|
109
|
+
"opacity",
|
|
110
|
+
"order",
|
|
111
|
+
"orphans",
|
|
112
|
+
"r",
|
|
113
|
+
"rx",
|
|
114
|
+
"ry",
|
|
115
|
+
"shapeImageThreshold",
|
|
116
|
+
"stopOpacity",
|
|
117
|
+
"strokeDasharray",
|
|
118
|
+
"strokeDashoffset",
|
|
119
|
+
"strokeMiterlimit",
|
|
120
|
+
"strokeOpacity",
|
|
121
|
+
"strokeWidth",
|
|
122
|
+
"tabSize",
|
|
123
|
+
"widows",
|
|
124
|
+
"x",
|
|
125
|
+
"y",
|
|
126
|
+
"zIndex",
|
|
127
|
+
"zoom"
|
|
128
|
+
]);
|
|
129
|
+
function hasPrefix(string, prefixes) {
|
|
130
|
+
return prefixes.some((prefix) => string.indexOf(prefix) === 0);
|
|
128
131
|
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Returns true if the given prop name should be ignored in attributes
|
|
132
|
-
* serialization, or false otherwise.
|
|
133
|
-
* @param attribute
|
|
134
|
-
*/
|
|
135
132
|
function isInternalAttribute(attribute) {
|
|
136
|
-
return
|
|
133
|
+
return "key" === attribute || "children" === attribute;
|
|
137
134
|
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Returns the normal form of the element's attribute value for HTML.
|
|
141
|
-
* @param attribute
|
|
142
|
-
* @param value
|
|
143
|
-
*/
|
|
144
135
|
function getNormalAttributeValue(attribute, value) {
|
|
145
136
|
switch (attribute) {
|
|
146
|
-
case
|
|
137
|
+
case "style":
|
|
147
138
|
return renderStyle(value);
|
|
148
139
|
}
|
|
149
140
|
return value;
|
|
150
141
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
142
|
+
const SVG_ATTRIBUTE_WITH_DASHES_LIST = [
|
|
143
|
+
"accentHeight",
|
|
144
|
+
"alignmentBaseline",
|
|
145
|
+
"arabicForm",
|
|
146
|
+
"baselineShift",
|
|
147
|
+
"capHeight",
|
|
148
|
+
"clipPath",
|
|
149
|
+
"clipRule",
|
|
150
|
+
"colorInterpolation",
|
|
151
|
+
"colorInterpolationFilters",
|
|
152
|
+
"colorProfile",
|
|
153
|
+
"colorRendering",
|
|
154
|
+
"dominantBaseline",
|
|
155
|
+
"enableBackground",
|
|
156
|
+
"fillOpacity",
|
|
157
|
+
"fillRule",
|
|
158
|
+
"floodColor",
|
|
159
|
+
"floodOpacity",
|
|
160
|
+
"fontFamily",
|
|
161
|
+
"fontSize",
|
|
162
|
+
"fontSizeAdjust",
|
|
163
|
+
"fontStretch",
|
|
164
|
+
"fontStyle",
|
|
165
|
+
"fontVariant",
|
|
166
|
+
"fontWeight",
|
|
167
|
+
"glyphName",
|
|
168
|
+
"glyphOrientationHorizontal",
|
|
169
|
+
"glyphOrientationVertical",
|
|
170
|
+
"horizAdvX",
|
|
171
|
+
"horizOriginX",
|
|
172
|
+
"imageRendering",
|
|
173
|
+
"letterSpacing",
|
|
174
|
+
"lightingColor",
|
|
175
|
+
"markerEnd",
|
|
176
|
+
"markerMid",
|
|
177
|
+
"markerStart",
|
|
178
|
+
"overlinePosition",
|
|
179
|
+
"overlineThickness",
|
|
180
|
+
"paintOrder",
|
|
181
|
+
"panose1",
|
|
182
|
+
"pointerEvents",
|
|
183
|
+
"renderingIntent",
|
|
184
|
+
"shapeRendering",
|
|
185
|
+
"stopColor",
|
|
186
|
+
"stopOpacity",
|
|
187
|
+
"strikethroughPosition",
|
|
188
|
+
"strikethroughThickness",
|
|
189
|
+
"strokeDasharray",
|
|
190
|
+
"strokeDashoffset",
|
|
191
|
+
"strokeLinecap",
|
|
192
|
+
"strokeLinejoin",
|
|
193
|
+
"strokeMiterlimit",
|
|
194
|
+
"strokeOpacity",
|
|
195
|
+
"strokeWidth",
|
|
196
|
+
"textAnchor",
|
|
197
|
+
"textDecoration",
|
|
198
|
+
"textRendering",
|
|
199
|
+
"underlinePosition",
|
|
200
|
+
"underlineThickness",
|
|
201
|
+
"unicodeBidi",
|
|
202
|
+
"unicodeRange",
|
|
203
|
+
"unitsPerEm",
|
|
204
|
+
"vAlphabetic",
|
|
205
|
+
"vHanging",
|
|
206
|
+
"vIdeographic",
|
|
207
|
+
"vMathematical",
|
|
208
|
+
"vectorEffect",
|
|
209
|
+
"vertAdvY",
|
|
210
|
+
"vertOriginX",
|
|
211
|
+
"vertOriginY",
|
|
212
|
+
"wordSpacing",
|
|
213
|
+
"writingMode",
|
|
214
|
+
"xmlnsXlink",
|
|
215
|
+
"xHeight"
|
|
216
|
+
].reduce(
|
|
217
|
+
(map, attribute) => {
|
|
218
|
+
map[attribute.toLowerCase()] = attribute;
|
|
219
|
+
return map;
|
|
220
|
+
},
|
|
221
|
+
{}
|
|
222
|
+
);
|
|
223
|
+
const CASE_SENSITIVE_SVG_ATTRIBUTES = [
|
|
224
|
+
"allowReorder",
|
|
225
|
+
"attributeName",
|
|
226
|
+
"attributeType",
|
|
227
|
+
"autoReverse",
|
|
228
|
+
"baseFrequency",
|
|
229
|
+
"baseProfile",
|
|
230
|
+
"calcMode",
|
|
231
|
+
"clipPathUnits",
|
|
232
|
+
"contentScriptType",
|
|
233
|
+
"contentStyleType",
|
|
234
|
+
"diffuseConstant",
|
|
235
|
+
"edgeMode",
|
|
236
|
+
"externalResourcesRequired",
|
|
237
|
+
"filterRes",
|
|
238
|
+
"filterUnits",
|
|
239
|
+
"glyphRef",
|
|
240
|
+
"gradientTransform",
|
|
241
|
+
"gradientUnits",
|
|
242
|
+
"kernelMatrix",
|
|
243
|
+
"kernelUnitLength",
|
|
244
|
+
"keyPoints",
|
|
245
|
+
"keySplines",
|
|
246
|
+
"keyTimes",
|
|
247
|
+
"lengthAdjust",
|
|
248
|
+
"limitingConeAngle",
|
|
249
|
+
"markerHeight",
|
|
250
|
+
"markerUnits",
|
|
251
|
+
"markerWidth",
|
|
252
|
+
"maskContentUnits",
|
|
253
|
+
"maskUnits",
|
|
254
|
+
"numOctaves",
|
|
255
|
+
"pathLength",
|
|
256
|
+
"patternContentUnits",
|
|
257
|
+
"patternTransform",
|
|
258
|
+
"patternUnits",
|
|
259
|
+
"pointsAtX",
|
|
260
|
+
"pointsAtY",
|
|
261
|
+
"pointsAtZ",
|
|
262
|
+
"preserveAlpha",
|
|
263
|
+
"preserveAspectRatio",
|
|
264
|
+
"primitiveUnits",
|
|
265
|
+
"refX",
|
|
266
|
+
"refY",
|
|
267
|
+
"repeatCount",
|
|
268
|
+
"repeatDur",
|
|
269
|
+
"requiredExtensions",
|
|
270
|
+
"requiredFeatures",
|
|
271
|
+
"specularConstant",
|
|
272
|
+
"specularExponent",
|
|
273
|
+
"spreadMethod",
|
|
274
|
+
"startOffset",
|
|
275
|
+
"stdDeviation",
|
|
276
|
+
"stitchTiles",
|
|
277
|
+
"suppressContentEditableWarning",
|
|
278
|
+
"suppressHydrationWarning",
|
|
279
|
+
"surfaceScale",
|
|
280
|
+
"systemLanguage",
|
|
281
|
+
"tableValues",
|
|
282
|
+
"targetX",
|
|
283
|
+
"targetY",
|
|
284
|
+
"textLength",
|
|
285
|
+
"viewBox",
|
|
286
|
+
"viewTarget",
|
|
287
|
+
"xChannelSelector",
|
|
288
|
+
"yChannelSelector"
|
|
289
|
+
].reduce(
|
|
290
|
+
(map, attribute) => {
|
|
291
|
+
map[attribute.toLowerCase()] = attribute;
|
|
292
|
+
return map;
|
|
293
|
+
},
|
|
294
|
+
{}
|
|
295
|
+
);
|
|
296
|
+
const SVG_ATTRIBUTES_WITH_COLONS = [
|
|
297
|
+
"xlink:actuate",
|
|
298
|
+
"xlink:arcrole",
|
|
299
|
+
"xlink:href",
|
|
300
|
+
"xlink:role",
|
|
301
|
+
"xlink:show",
|
|
302
|
+
"xlink:title",
|
|
303
|
+
"xlink:type",
|
|
304
|
+
"xml:base",
|
|
305
|
+
"xml:lang",
|
|
306
|
+
"xml:space",
|
|
307
|
+
"xmlns:xlink"
|
|
308
|
+
].reduce(
|
|
309
|
+
(map, attribute) => {
|
|
310
|
+
map[attribute.replace(":", "").toLowerCase()] = attribute;
|
|
311
|
+
return map;
|
|
312
|
+
},
|
|
313
|
+
{}
|
|
314
|
+
);
|
|
189
315
|
function getNormalAttributeName(attribute) {
|
|
190
316
|
switch (attribute) {
|
|
191
|
-
case
|
|
192
|
-
return
|
|
193
|
-
case
|
|
194
|
-
return
|
|
317
|
+
case "htmlFor":
|
|
318
|
+
return "for";
|
|
319
|
+
case "className":
|
|
320
|
+
return "class";
|
|
195
321
|
}
|
|
196
322
|
const attributeLowerCase = attribute.toLowerCase();
|
|
197
323
|
if (CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase]) {
|
|
198
324
|
return CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase];
|
|
199
325
|
} else if (SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]) {
|
|
200
|
-
return kebabCase(
|
|
326
|
+
return kebabCase(
|
|
327
|
+
SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]
|
|
328
|
+
);
|
|
201
329
|
} else if (SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase]) {
|
|
202
330
|
return SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase];
|
|
203
331
|
}
|
|
204
332
|
return attributeLowerCase;
|
|
205
333
|
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Returns the normal form of the style property name for HTML.
|
|
209
|
-
*
|
|
210
|
-
* - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'
|
|
211
|
-
* - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'
|
|
212
|
-
* - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'
|
|
213
|
-
* @param property
|
|
214
|
-
*/
|
|
215
334
|
function getNormalStylePropertyName(property) {
|
|
216
|
-
if (property.startsWith(
|
|
335
|
+
if (property.startsWith("--")) {
|
|
217
336
|
return property;
|
|
218
337
|
}
|
|
219
|
-
if (hasPrefix(property, [
|
|
220
|
-
return
|
|
338
|
+
if (hasPrefix(property, ["ms", "O", "Moz", "Webkit"])) {
|
|
339
|
+
return "-" + kebabCase(property);
|
|
221
340
|
}
|
|
222
341
|
return kebabCase(property);
|
|
223
342
|
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Returns the normal form of the style property value for HTML. Appends a
|
|
227
|
-
* default pixel unit if numeric, not a unitless property, and not zero.
|
|
228
|
-
* @param property
|
|
229
|
-
* @param value
|
|
230
|
-
*/
|
|
231
343
|
function getNormalStylePropertyValue(property, value) {
|
|
232
|
-
if (typeof value ===
|
|
233
|
-
return value +
|
|
344
|
+
if (typeof value === "number" && 0 !== value && !hasPrefix(property, ["--"]) && !CSS_PROPERTIES_SUPPORTS_UNITLESS.has(property)) {
|
|
345
|
+
return value + "px";
|
|
234
346
|
}
|
|
235
347
|
return value;
|
|
236
348
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
* @param element
|
|
241
|
-
* @param context
|
|
242
|
-
* @param legacyContext
|
|
243
|
-
*/
|
|
244
|
-
export function renderElement(element, context, legacyContext = {}) {
|
|
245
|
-
if (null === element || undefined === element || false === element) {
|
|
246
|
-
return '';
|
|
349
|
+
function renderElement(element, context, legacyContext = {}) {
|
|
350
|
+
if (null === element || void 0 === element || false === element) {
|
|
351
|
+
return "";
|
|
247
352
|
}
|
|
248
353
|
if (Array.isArray(element)) {
|
|
249
354
|
return renderChildren(element, context, legacyContext);
|
|
250
355
|
}
|
|
251
356
|
switch (typeof element) {
|
|
252
|
-
case
|
|
357
|
+
case "string":
|
|
253
358
|
return escapeHTML(element);
|
|
254
|
-
case
|
|
359
|
+
case "number":
|
|
255
360
|
return element.toString();
|
|
256
361
|
}
|
|
257
|
-
const {
|
|
258
|
-
type,
|
|
259
|
-
props
|
|
260
|
-
} = element;
|
|
362
|
+
const { type, props } = element;
|
|
261
363
|
switch (type) {
|
|
262
364
|
case StrictMode:
|
|
263
365
|
case Fragment:
|
|
264
366
|
return renderChildren(props.children, context, legacyContext);
|
|
265
367
|
case RawHTML:
|
|
266
|
-
const {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
368
|
+
const { children, ...wrapperProps } = props;
|
|
369
|
+
return renderNativeComponent(
|
|
370
|
+
!Object.keys(wrapperProps).length ? null : "div",
|
|
371
|
+
{
|
|
372
|
+
...wrapperProps,
|
|
373
|
+
dangerouslySetInnerHTML: { __html: children }
|
|
374
|
+
},
|
|
375
|
+
context,
|
|
376
|
+
legacyContext
|
|
377
|
+
);
|
|
276
378
|
}
|
|
277
379
|
switch (typeof type) {
|
|
278
|
-
case
|
|
380
|
+
case "string":
|
|
279
381
|
return renderNativeComponent(type, props, context, legacyContext);
|
|
280
|
-
case
|
|
281
|
-
if (type.prototype && typeof type.prototype.render ===
|
|
382
|
+
case "function":
|
|
383
|
+
if (type.prototype && typeof type.prototype.render === "function") {
|
|
282
384
|
return renderComponent(type, props, context, legacyContext);
|
|
283
385
|
}
|
|
284
|
-
return renderElement(
|
|
386
|
+
return renderElement(
|
|
387
|
+
type(props, legacyContext),
|
|
388
|
+
context,
|
|
389
|
+
legacyContext
|
|
390
|
+
);
|
|
285
391
|
}
|
|
286
392
|
switch (type && type.$$typeof) {
|
|
287
393
|
case Provider.$$typeof:
|
|
288
394
|
return renderChildren(props.children, props.value, legacyContext);
|
|
289
395
|
case Consumer.$$typeof:
|
|
290
|
-
return renderElement(
|
|
396
|
+
return renderElement(
|
|
397
|
+
props.children(context || type._currentValue),
|
|
398
|
+
context,
|
|
399
|
+
legacyContext
|
|
400
|
+
);
|
|
291
401
|
case ForwardRef.$$typeof:
|
|
292
|
-
return renderElement(
|
|
402
|
+
return renderElement(
|
|
403
|
+
type.render(props),
|
|
404
|
+
context,
|
|
405
|
+
legacyContext
|
|
406
|
+
);
|
|
293
407
|
}
|
|
294
|
-
return
|
|
408
|
+
return "";
|
|
295
409
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
* @param type
|
|
300
|
-
* @param props
|
|
301
|
-
* @param context
|
|
302
|
-
* @param legacyContext
|
|
303
|
-
*/
|
|
304
|
-
export function renderNativeComponent(type, props, context, legacyContext = {}) {
|
|
305
|
-
let content = '';
|
|
306
|
-
if (type === 'textarea' && props.hasOwnProperty('value')) {
|
|
307
|
-
// Textarea children can be assigned as value prop. If it is, render in
|
|
308
|
-
// place of children. Ensure to omit so it is not assigned as attribute
|
|
309
|
-
// as well.
|
|
410
|
+
function renderNativeComponent(type, props, context, legacyContext = {}) {
|
|
411
|
+
let content = "";
|
|
412
|
+
if (type === "textarea" && props.hasOwnProperty("value")) {
|
|
310
413
|
content = renderChildren(props.value, context, legacyContext);
|
|
311
|
-
const {
|
|
312
|
-
value,
|
|
313
|
-
...restProps
|
|
314
|
-
} = props;
|
|
414
|
+
const { value, ...restProps } = props;
|
|
315
415
|
props = restProps;
|
|
316
|
-
} else if (props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML.__html ===
|
|
317
|
-
// Dangerous content is left unescaped.
|
|
416
|
+
} else if (props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML.__html === "string") {
|
|
318
417
|
content = props.dangerouslySetInnerHTML.__html;
|
|
319
|
-
} else if (typeof props.children !==
|
|
418
|
+
} else if (typeof props.children !== "undefined") {
|
|
320
419
|
content = renderChildren(props.children, context, legacyContext);
|
|
321
420
|
}
|
|
322
421
|
if (!type) {
|
|
@@ -324,35 +423,20 @@ export function renderNativeComponent(type, props, context, legacyContext = {})
|
|
|
324
423
|
}
|
|
325
424
|
const attributes = renderAttributes(props);
|
|
326
425
|
if (SELF_CLOSING_TAGS.has(type)) {
|
|
327
|
-
return
|
|
426
|
+
return "<" + type + attributes + "/>";
|
|
328
427
|
}
|
|
329
|
-
return
|
|
428
|
+
return "<" + type + attributes + ">" + content + "</" + type + ">";
|
|
330
429
|
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Serializes a non-native component type to string.
|
|
334
|
-
* @param Component
|
|
335
|
-
* @param props
|
|
336
|
-
* @param context
|
|
337
|
-
* @param legacyContext
|
|
338
|
-
*/
|
|
339
|
-
export function renderComponent(Component, props, context, legacyContext = {}) {
|
|
430
|
+
function renderComponent(Component, props, context, legacyContext = {}) {
|
|
340
431
|
const instance = new Component(props, legacyContext);
|
|
341
|
-
if (typeof instance.getChildContext ===
|
|
432
|
+
if (typeof instance.getChildContext === "function") {
|
|
342
433
|
Object.assign(legacyContext, instance.getChildContext());
|
|
343
434
|
}
|
|
344
435
|
const html = renderElement(instance.render(), context, legacyContext);
|
|
345
436
|
return html;
|
|
346
437
|
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Serializes an array of children to string.
|
|
350
|
-
* @param children
|
|
351
|
-
* @param context
|
|
352
|
-
* @param legacyContext
|
|
353
|
-
*/
|
|
354
438
|
function renderChildren(children, context, legacyContext = {}) {
|
|
355
|
-
let result =
|
|
439
|
+
let result = "";
|
|
356
440
|
const childrenArray = Array.isArray(children) ? children : [children];
|
|
357
441
|
for (let i = 0; i < childrenArray.length; i++) {
|
|
358
442
|
const child = childrenArray[i];
|
|
@@ -360,62 +444,40 @@ function renderChildren(children, context, legacyContext = {}) {
|
|
|
360
444
|
}
|
|
361
445
|
return result;
|
|
362
446
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
* Renders a props object as a string of HTML attributes.
|
|
366
|
-
* @param props
|
|
367
|
-
*/
|
|
368
|
-
export function renderAttributes(props) {
|
|
369
|
-
let result = '';
|
|
447
|
+
function renderAttributes(props) {
|
|
448
|
+
let result = "";
|
|
370
449
|
for (const key in props) {
|
|
371
450
|
const attribute = getNormalAttributeName(key);
|
|
372
451
|
if (!isValidAttributeName(attribute)) {
|
|
373
452
|
continue;
|
|
374
453
|
}
|
|
375
454
|
let value = getNormalAttributeValue(key, props[key]);
|
|
376
|
-
|
|
377
|
-
// If value is not of serializable type, skip.
|
|
378
455
|
if (!ATTRIBUTES_TYPES.has(typeof value)) {
|
|
379
456
|
continue;
|
|
380
457
|
}
|
|
381
|
-
|
|
382
|
-
// Don't render internal attribute names.
|
|
383
458
|
if (isInternalAttribute(key)) {
|
|
384
459
|
continue;
|
|
385
460
|
}
|
|
386
461
|
const isBooleanAttribute = BOOLEAN_ATTRIBUTES.has(attribute);
|
|
387
|
-
|
|
388
|
-
// Boolean attribute should be omitted outright if its value is false.
|
|
389
462
|
if (isBooleanAttribute && value === false) {
|
|
390
463
|
continue;
|
|
391
464
|
}
|
|
392
|
-
const isMeaningfulAttribute = isBooleanAttribute || hasPrefix(key, [
|
|
393
|
-
|
|
394
|
-
// Only write boolean value as attribute if meaningful.
|
|
395
|
-
if (typeof value === 'boolean' && !isMeaningfulAttribute) {
|
|
465
|
+
const isMeaningfulAttribute = isBooleanAttribute || hasPrefix(key, ["data-", "aria-"]) || ENUMERATED_ATTRIBUTES.has(attribute);
|
|
466
|
+
if (typeof value === "boolean" && !isMeaningfulAttribute) {
|
|
396
467
|
continue;
|
|
397
468
|
}
|
|
398
|
-
result +=
|
|
399
|
-
|
|
400
|
-
// Boolean attributes should write attribute name, but without value.
|
|
401
|
-
// Mere presence of attribute name is effective truthiness.
|
|
469
|
+
result += " " + attribute;
|
|
402
470
|
if (isBooleanAttribute) {
|
|
403
471
|
continue;
|
|
404
472
|
}
|
|
405
|
-
if (typeof value ===
|
|
473
|
+
if (typeof value === "string") {
|
|
406
474
|
value = escapeAttribute(value);
|
|
407
475
|
}
|
|
408
476
|
result += '="' + value + '"';
|
|
409
477
|
}
|
|
410
478
|
return result;
|
|
411
479
|
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Renders a style object as a string attribute value.
|
|
415
|
-
* @param style
|
|
416
|
-
*/
|
|
417
|
-
export function renderStyle(style) {
|
|
418
|
-
// Only generate from object, e.g. tolerate string value.
|
|
480
|
+
function renderStyle(style) {
|
|
419
481
|
if (!isPlainObject(style)) {
|
|
420
482
|
return style;
|
|
421
483
|
}
|
|
@@ -423,19 +485,28 @@ export function renderStyle(style) {
|
|
|
423
485
|
const styleObj = style;
|
|
424
486
|
for (const property in styleObj) {
|
|
425
487
|
const value = styleObj[property];
|
|
426
|
-
if (null === value ||
|
|
488
|
+
if (null === value || void 0 === value) {
|
|
427
489
|
continue;
|
|
428
490
|
}
|
|
429
491
|
if (result) {
|
|
430
|
-
result +=
|
|
492
|
+
result += ";";
|
|
431
493
|
} else {
|
|
432
|
-
result =
|
|
494
|
+
result = "";
|
|
433
495
|
}
|
|
434
496
|
const normalName = getNormalStylePropertyName(property);
|
|
435
497
|
const normalValue = getNormalStylePropertyValue(property, value);
|
|
436
|
-
result += normalName +
|
|
498
|
+
result += normalName + ":" + normalValue;
|
|
437
499
|
}
|
|
438
500
|
return result;
|
|
439
501
|
}
|
|
440
|
-
|
|
441
|
-
|
|
502
|
+
var serialize_default = renderElement;
|
|
503
|
+
export {
|
|
504
|
+
serialize_default as default,
|
|
505
|
+
hasPrefix,
|
|
506
|
+
renderAttributes,
|
|
507
|
+
renderComponent,
|
|
508
|
+
renderElement,
|
|
509
|
+
renderNativeComponent,
|
|
510
|
+
renderStyle
|
|
511
|
+
};
|
|
512
|
+
//# sourceMappingURL=serialize.js.map
|