@wsxjs/wsx-core 0.0.16 → 0.0.18
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/LICENSE +2 -2
- package/dist/chunk-7AUYPTR5.mjs +277 -0
- package/dist/chunk-7WRSZQC3.mjs +256 -0
- package/dist/chunk-CBCT3PYF.mjs +250 -0
- package/dist/chunk-G23NXAPQ.mjs +237 -0
- package/dist/chunk-GOIGP2BR.mjs +271 -0
- package/dist/chunk-H6LR3P4O.mjs +256 -0
- package/dist/chunk-JV57DWHH.mjs +265 -0
- package/dist/chunk-UH5BDYGI.mjs +283 -0
- package/dist/index.js +170 -71
- package/dist/index.mjs +113 -69
- package/dist/jsx-runtime.js +56 -2
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx.js +56 -2
- package/dist/jsx.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +15 -2
- package/src/base-component.ts +60 -11
- package/src/index.ts +3 -2
- package/src/jsx-factory.ts +80 -2
- package/src/light-component.ts +93 -28
- package/src/utils/dom-utils.ts +48 -0
- package/src/utils/logger.ts +2 -2
- package/src/utils/reactive.ts +1 -1
- package/src/web-component.ts +37 -22
- package/types/index.d.ts +6 -3
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// src/utils/svg-utils.ts
|
|
2
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
3
|
+
var SVG_ONLY_ELEMENTS = /* @__PURE__ */ new Set([
|
|
4
|
+
// 结构元素 (Structural elements)
|
|
5
|
+
"svg",
|
|
6
|
+
"defs",
|
|
7
|
+
"g",
|
|
8
|
+
"symbol",
|
|
9
|
+
"use",
|
|
10
|
+
// 图形元素 (Graphics elements)
|
|
11
|
+
"circle",
|
|
12
|
+
"ellipse",
|
|
13
|
+
"line",
|
|
14
|
+
"path",
|
|
15
|
+
"polygon",
|
|
16
|
+
"polyline",
|
|
17
|
+
"rect",
|
|
18
|
+
// 文本元素 (Text elements)
|
|
19
|
+
"textPath",
|
|
20
|
+
"tspan",
|
|
21
|
+
// 渐变和模式 (Gradients and patterns)
|
|
22
|
+
"linearGradient",
|
|
23
|
+
"radialGradient",
|
|
24
|
+
"stop",
|
|
25
|
+
"pattern",
|
|
26
|
+
// 滤镜 (Filter elements)
|
|
27
|
+
"filter",
|
|
28
|
+
"feBlend",
|
|
29
|
+
"feColorMatrix",
|
|
30
|
+
"feComponentTransfer",
|
|
31
|
+
"feComposite",
|
|
32
|
+
"feConvolveMatrix",
|
|
33
|
+
"feDiffuseLighting",
|
|
34
|
+
"feDisplacementMap",
|
|
35
|
+
"feDistantLight",
|
|
36
|
+
"feDropShadow",
|
|
37
|
+
"feFlood",
|
|
38
|
+
"feFuncA",
|
|
39
|
+
"feFuncB",
|
|
40
|
+
"feFuncG",
|
|
41
|
+
"feFuncR",
|
|
42
|
+
"feGaussianBlur",
|
|
43
|
+
"feImage",
|
|
44
|
+
"feMerge",
|
|
45
|
+
"feMergeNode",
|
|
46
|
+
"feMorphology",
|
|
47
|
+
"feOffset",
|
|
48
|
+
"fePointLight",
|
|
49
|
+
"feSpecularLighting",
|
|
50
|
+
"feSpotLight",
|
|
51
|
+
"feTile",
|
|
52
|
+
"feTurbulence",
|
|
53
|
+
// 动画元素 (Animation elements)
|
|
54
|
+
"animate",
|
|
55
|
+
"animateMotion",
|
|
56
|
+
"animateTransform",
|
|
57
|
+
"set",
|
|
58
|
+
// 其他元素 (Other elements)
|
|
59
|
+
"clipPath",
|
|
60
|
+
"foreignObject",
|
|
61
|
+
"marker",
|
|
62
|
+
"mask",
|
|
63
|
+
"metadata",
|
|
64
|
+
"switch",
|
|
65
|
+
"desc"
|
|
66
|
+
]);
|
|
67
|
+
var DUAL_ELEMENTS = /* @__PURE__ */ new Set(["image", "style", "title", "text"]);
|
|
68
|
+
var FORCE_HTML_ELEMENTS = /* @__PURE__ */ new Set(["a"]);
|
|
69
|
+
var SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
70
|
+
...SVG_ONLY_ELEMENTS,
|
|
71
|
+
...DUAL_ELEMENTS,
|
|
72
|
+
...FORCE_HTML_ELEMENTS
|
|
73
|
+
]);
|
|
74
|
+
var svgContext = false;
|
|
75
|
+
function isSVGOnlyElement(tagName) {
|
|
76
|
+
return SVG_ONLY_ELEMENTS.has(tagName);
|
|
77
|
+
}
|
|
78
|
+
function isDualElement(tagName) {
|
|
79
|
+
return DUAL_ELEMENTS.has(tagName);
|
|
80
|
+
}
|
|
81
|
+
function isForceHTMLElement(tagName) {
|
|
82
|
+
return FORCE_HTML_ELEMENTS.has(tagName);
|
|
83
|
+
}
|
|
84
|
+
function setSVGContext(inSVG) {
|
|
85
|
+
svgContext = inSVG;
|
|
86
|
+
}
|
|
87
|
+
function createElement(tagName) {
|
|
88
|
+
if (isForceHTMLElement(tagName)) {
|
|
89
|
+
return document.createElement(tagName);
|
|
90
|
+
}
|
|
91
|
+
if (isSVGOnlyElement(tagName)) {
|
|
92
|
+
setSVGContext(true);
|
|
93
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
94
|
+
}
|
|
95
|
+
if (isDualElement(tagName)) {
|
|
96
|
+
if (svgContext) {
|
|
97
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return document.createElement(tagName);
|
|
101
|
+
}
|
|
102
|
+
function shouldUseSVGNamespace(tagName) {
|
|
103
|
+
return isSVGOnlyElement(tagName) || isDualElement(tagName) && svgContext;
|
|
104
|
+
}
|
|
105
|
+
var SVG_ATTRIBUTE_MAP = /* @__PURE__ */ new Map([
|
|
106
|
+
["className", "class"],
|
|
107
|
+
["htmlFor", "for"]
|
|
108
|
+
]);
|
|
109
|
+
function getSVGAttributeName(attributeName) {
|
|
110
|
+
return SVG_ATTRIBUTE_MAP.get(attributeName) || attributeName;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/utils/dom-utils.ts
|
|
114
|
+
function parseHTMLToNodes(html) {
|
|
115
|
+
if (!html) return [];
|
|
116
|
+
const temp = document.createElement("div");
|
|
117
|
+
temp.innerHTML = html;
|
|
118
|
+
return Array.from(temp.childNodes).map((node) => {
|
|
119
|
+
if (node instanceof HTMLElement || node instanceof SVGElement) {
|
|
120
|
+
return node;
|
|
121
|
+
} else {
|
|
122
|
+
return node.textContent || "";
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/jsx-factory.ts
|
|
128
|
+
function h(tag, props = {}, ...children) {
|
|
129
|
+
if (typeof tag === "function") {
|
|
130
|
+
return tag(props, children);
|
|
131
|
+
}
|
|
132
|
+
const element = createElement(tag);
|
|
133
|
+
if (props) {
|
|
134
|
+
const isSVG = shouldUseSVGNamespace(tag);
|
|
135
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
136
|
+
if (value === null || value === void 0 || value === false) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (key === "ref" && typeof value === "function") {
|
|
140
|
+
value(element);
|
|
141
|
+
} else if (key === "className" || key === "class") {
|
|
142
|
+
if (isSVG) {
|
|
143
|
+
element.setAttribute("class", value);
|
|
144
|
+
} else {
|
|
145
|
+
element.className = value;
|
|
146
|
+
}
|
|
147
|
+
} else if (key === "style" && typeof value === "string") {
|
|
148
|
+
element.setAttribute("style", value);
|
|
149
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
150
|
+
const eventName = key.slice(2).toLowerCase();
|
|
151
|
+
element.addEventListener(eventName, value);
|
|
152
|
+
} else if (typeof value === "boolean") {
|
|
153
|
+
if (value) {
|
|
154
|
+
element.setAttribute(key, "");
|
|
155
|
+
}
|
|
156
|
+
} else if (key === "value") {
|
|
157
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
|
|
158
|
+
element.value = String(value);
|
|
159
|
+
} else {
|
|
160
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
161
|
+
element.setAttribute(attributeName, String(value));
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
165
|
+
element.setAttribute(attributeName, String(value));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const flatChildren = flattenChildren(children);
|
|
170
|
+
flatChildren.forEach((child) => {
|
|
171
|
+
if (child === null || child === void 0 || child === false) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
175
|
+
element.appendChild(document.createTextNode(String(child)));
|
|
176
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
177
|
+
element.appendChild(child);
|
|
178
|
+
} else if (child instanceof DocumentFragment) {
|
|
179
|
+
element.appendChild(child);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return element;
|
|
183
|
+
}
|
|
184
|
+
function isHTMLString(str) {
|
|
185
|
+
const htmlTagPattern = /<[a-z][\s\S]*>/i;
|
|
186
|
+
return htmlTagPattern.test(str.trim());
|
|
187
|
+
}
|
|
188
|
+
function flattenChildren(children, skipHTMLDetection = false, depth = 0) {
|
|
189
|
+
if (depth > 10) {
|
|
190
|
+
console.warn("[WSX] flattenChildren: Maximum depth exceeded, treating remaining children as text");
|
|
191
|
+
return children.filter(
|
|
192
|
+
(child) => typeof child === "string" || typeof child === "number"
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
const result = [];
|
|
196
|
+
for (const child of children) {
|
|
197
|
+
if (child === null || child === void 0 || child === false) {
|
|
198
|
+
continue;
|
|
199
|
+
} else if (Array.isArray(child)) {
|
|
200
|
+
result.push(...flattenChildren(child, skipHTMLDetection, depth + 1));
|
|
201
|
+
} else if (typeof child === "string") {
|
|
202
|
+
if (skipHTMLDetection) {
|
|
203
|
+
result.push(child);
|
|
204
|
+
} else if (isHTMLString(child)) {
|
|
205
|
+
try {
|
|
206
|
+
const nodes = parseHTMLToNodes(child);
|
|
207
|
+
if (nodes.length > 0) {
|
|
208
|
+
result.push(...flattenChildren(nodes, true, depth + 1));
|
|
209
|
+
} else {
|
|
210
|
+
result.push(child);
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.warn("[WSX] Failed to parse HTML string, treating as text:", error);
|
|
214
|
+
result.push(child);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
result.push(child);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
result.push(child);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function Fragment(_props, children) {
|
|
226
|
+
const fragment = document.createDocumentFragment();
|
|
227
|
+
const flatChildren = flattenChildren(children);
|
|
228
|
+
flatChildren.forEach((child) => {
|
|
229
|
+
if (child === null || child === void 0 || child === false) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
233
|
+
fragment.appendChild(document.createTextNode(String(child)));
|
|
234
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
235
|
+
fragment.appendChild(child);
|
|
236
|
+
} else if (child instanceof DocumentFragment) {
|
|
237
|
+
fragment.appendChild(child);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return fragment;
|
|
241
|
+
}
|
|
242
|
+
function jsx(tag, props) {
|
|
243
|
+
if (!props) {
|
|
244
|
+
return h(tag, null);
|
|
245
|
+
}
|
|
246
|
+
const { children, ...restProps } = props;
|
|
247
|
+
if (children !== void 0 && children !== null) {
|
|
248
|
+
const childrenArray = Array.isArray(children) ? children : [children];
|
|
249
|
+
return h(tag, restProps, ...childrenArray);
|
|
250
|
+
}
|
|
251
|
+
return h(tag, restProps);
|
|
252
|
+
}
|
|
253
|
+
function jsxs(tag, props) {
|
|
254
|
+
if (!props) {
|
|
255
|
+
return h(tag, null);
|
|
256
|
+
}
|
|
257
|
+
const { children, ...restProps } = props;
|
|
258
|
+
if (Array.isArray(children)) {
|
|
259
|
+
return h(tag, restProps, ...children);
|
|
260
|
+
} else if (children !== void 0 && children !== null) {
|
|
261
|
+
return h(tag, restProps, children);
|
|
262
|
+
}
|
|
263
|
+
return h(tag, restProps);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export {
|
|
267
|
+
h,
|
|
268
|
+
Fragment,
|
|
269
|
+
jsx,
|
|
270
|
+
jsxs
|
|
271
|
+
};
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// src/utils/svg-utils.ts
|
|
2
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
3
|
+
var SVG_ONLY_ELEMENTS = /* @__PURE__ */ new Set([
|
|
4
|
+
// 结构元素 (Structural elements)
|
|
5
|
+
"svg",
|
|
6
|
+
"defs",
|
|
7
|
+
"g",
|
|
8
|
+
"symbol",
|
|
9
|
+
"use",
|
|
10
|
+
// 图形元素 (Graphics elements)
|
|
11
|
+
"circle",
|
|
12
|
+
"ellipse",
|
|
13
|
+
"line",
|
|
14
|
+
"path",
|
|
15
|
+
"polygon",
|
|
16
|
+
"polyline",
|
|
17
|
+
"rect",
|
|
18
|
+
// 文本元素 (Text elements)
|
|
19
|
+
"textPath",
|
|
20
|
+
"tspan",
|
|
21
|
+
// 渐变和模式 (Gradients and patterns)
|
|
22
|
+
"linearGradient",
|
|
23
|
+
"radialGradient",
|
|
24
|
+
"stop",
|
|
25
|
+
"pattern",
|
|
26
|
+
// 滤镜 (Filter elements)
|
|
27
|
+
"filter",
|
|
28
|
+
"feBlend",
|
|
29
|
+
"feColorMatrix",
|
|
30
|
+
"feComponentTransfer",
|
|
31
|
+
"feComposite",
|
|
32
|
+
"feConvolveMatrix",
|
|
33
|
+
"feDiffuseLighting",
|
|
34
|
+
"feDisplacementMap",
|
|
35
|
+
"feDistantLight",
|
|
36
|
+
"feDropShadow",
|
|
37
|
+
"feFlood",
|
|
38
|
+
"feFuncA",
|
|
39
|
+
"feFuncB",
|
|
40
|
+
"feFuncG",
|
|
41
|
+
"feFuncR",
|
|
42
|
+
"feGaussianBlur",
|
|
43
|
+
"feImage",
|
|
44
|
+
"feMerge",
|
|
45
|
+
"feMergeNode",
|
|
46
|
+
"feMorphology",
|
|
47
|
+
"feOffset",
|
|
48
|
+
"fePointLight",
|
|
49
|
+
"feSpecularLighting",
|
|
50
|
+
"feSpotLight",
|
|
51
|
+
"feTile",
|
|
52
|
+
"feTurbulence",
|
|
53
|
+
// 动画元素 (Animation elements)
|
|
54
|
+
"animate",
|
|
55
|
+
"animateMotion",
|
|
56
|
+
"animateTransform",
|
|
57
|
+
"set",
|
|
58
|
+
// 其他元素 (Other elements)
|
|
59
|
+
"clipPath",
|
|
60
|
+
"foreignObject",
|
|
61
|
+
"marker",
|
|
62
|
+
"mask",
|
|
63
|
+
"metadata",
|
|
64
|
+
"switch",
|
|
65
|
+
"desc"
|
|
66
|
+
]);
|
|
67
|
+
var DUAL_ELEMENTS = /* @__PURE__ */ new Set(["image", "style", "title", "text"]);
|
|
68
|
+
var FORCE_HTML_ELEMENTS = /* @__PURE__ */ new Set(["a"]);
|
|
69
|
+
var SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
70
|
+
...SVG_ONLY_ELEMENTS,
|
|
71
|
+
...DUAL_ELEMENTS,
|
|
72
|
+
...FORCE_HTML_ELEMENTS
|
|
73
|
+
]);
|
|
74
|
+
var svgContext = false;
|
|
75
|
+
function isSVGOnlyElement(tagName) {
|
|
76
|
+
return SVG_ONLY_ELEMENTS.has(tagName);
|
|
77
|
+
}
|
|
78
|
+
function isDualElement(tagName) {
|
|
79
|
+
return DUAL_ELEMENTS.has(tagName);
|
|
80
|
+
}
|
|
81
|
+
function isForceHTMLElement(tagName) {
|
|
82
|
+
return FORCE_HTML_ELEMENTS.has(tagName);
|
|
83
|
+
}
|
|
84
|
+
function setSVGContext(inSVG) {
|
|
85
|
+
svgContext = inSVG;
|
|
86
|
+
}
|
|
87
|
+
function createElement(tagName) {
|
|
88
|
+
if (isForceHTMLElement(tagName)) {
|
|
89
|
+
return document.createElement(tagName);
|
|
90
|
+
}
|
|
91
|
+
if (isSVGOnlyElement(tagName)) {
|
|
92
|
+
setSVGContext(true);
|
|
93
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
94
|
+
}
|
|
95
|
+
if (isDualElement(tagName)) {
|
|
96
|
+
if (svgContext) {
|
|
97
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return document.createElement(tagName);
|
|
101
|
+
}
|
|
102
|
+
function shouldUseSVGNamespace(tagName) {
|
|
103
|
+
return isSVGOnlyElement(tagName) || isDualElement(tagName) && svgContext;
|
|
104
|
+
}
|
|
105
|
+
var SVG_ATTRIBUTE_MAP = /* @__PURE__ */ new Map([
|
|
106
|
+
["className", "class"],
|
|
107
|
+
["htmlFor", "for"]
|
|
108
|
+
]);
|
|
109
|
+
function getSVGAttributeName(attributeName) {
|
|
110
|
+
return SVG_ATTRIBUTE_MAP.get(attributeName) || attributeName;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/utils/dom-utils.ts
|
|
114
|
+
function parseHTMLToNodes(html) {
|
|
115
|
+
if (!html) return [];
|
|
116
|
+
const temp = document.createElement("div");
|
|
117
|
+
temp.innerHTML = html;
|
|
118
|
+
return Array.from(temp.childNodes).map((node) => {
|
|
119
|
+
if (node instanceof HTMLElement || node instanceof SVGElement) {
|
|
120
|
+
return node;
|
|
121
|
+
} else {
|
|
122
|
+
return node.textContent || "";
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/jsx-factory.ts
|
|
128
|
+
function h(tag, props = {}, ...children) {
|
|
129
|
+
if (typeof tag === "function") {
|
|
130
|
+
return tag(props, children);
|
|
131
|
+
}
|
|
132
|
+
const element = createElement(tag);
|
|
133
|
+
if (props) {
|
|
134
|
+
const isSVG = shouldUseSVGNamespace(tag);
|
|
135
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
136
|
+
if (value === null || value === void 0 || value === false) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (key === "ref" && typeof value === "function") {
|
|
140
|
+
value(element);
|
|
141
|
+
} else if (key === "className" || key === "class") {
|
|
142
|
+
if (isSVG) {
|
|
143
|
+
element.setAttribute("class", value);
|
|
144
|
+
} else {
|
|
145
|
+
element.className = value;
|
|
146
|
+
}
|
|
147
|
+
} else if (key === "style" && typeof value === "string") {
|
|
148
|
+
element.setAttribute("style", value);
|
|
149
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
150
|
+
const eventName = key.slice(2).toLowerCase();
|
|
151
|
+
element.addEventListener(eventName, value);
|
|
152
|
+
} else if (typeof value === "boolean") {
|
|
153
|
+
if (value) {
|
|
154
|
+
element.setAttribute(key, "");
|
|
155
|
+
}
|
|
156
|
+
} else if (key === "value") {
|
|
157
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
|
|
158
|
+
element.value = String(value);
|
|
159
|
+
} else {
|
|
160
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
161
|
+
element.setAttribute(attributeName, String(value));
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
165
|
+
element.setAttribute(attributeName, String(value));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const flatChildren = flattenChildren(children);
|
|
170
|
+
flatChildren.forEach((child) => {
|
|
171
|
+
if (child === null || child === void 0 || child === false) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
175
|
+
element.appendChild(document.createTextNode(String(child)));
|
|
176
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
177
|
+
element.appendChild(child);
|
|
178
|
+
} else if (child instanceof DocumentFragment) {
|
|
179
|
+
element.appendChild(child);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return element;
|
|
183
|
+
}
|
|
184
|
+
function isHTMLString(str) {
|
|
185
|
+
const htmlTagPattern = /<[a-z][\s\S]*>/i;
|
|
186
|
+
return htmlTagPattern.test(str.trim());
|
|
187
|
+
}
|
|
188
|
+
function flattenChildren(children, skipHTMLDetection = false) {
|
|
189
|
+
const result = [];
|
|
190
|
+
for (const child of children) {
|
|
191
|
+
if (child === null || child === void 0 || child === false) {
|
|
192
|
+
continue;
|
|
193
|
+
} else if (Array.isArray(child)) {
|
|
194
|
+
result.push(...flattenChildren(child, skipHTMLDetection));
|
|
195
|
+
} else if (typeof child === "string") {
|
|
196
|
+
if (skipHTMLDetection) {
|
|
197
|
+
result.push(child);
|
|
198
|
+
} else if (isHTMLString(child)) {
|
|
199
|
+
const nodes = parseHTMLToNodes(child);
|
|
200
|
+
result.push(...flattenChildren(nodes, true));
|
|
201
|
+
} else {
|
|
202
|
+
result.push(child);
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
result.push(child);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
function Fragment(_props, children) {
|
|
211
|
+
const fragment = document.createDocumentFragment();
|
|
212
|
+
const flatChildren = flattenChildren(children);
|
|
213
|
+
flatChildren.forEach((child) => {
|
|
214
|
+
if (child === null || child === void 0 || child === false) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
218
|
+
fragment.appendChild(document.createTextNode(String(child)));
|
|
219
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
220
|
+
fragment.appendChild(child);
|
|
221
|
+
} else if (child instanceof DocumentFragment) {
|
|
222
|
+
fragment.appendChild(child);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return fragment;
|
|
226
|
+
}
|
|
227
|
+
function jsx(tag, props) {
|
|
228
|
+
if (!props) {
|
|
229
|
+
return h(tag, null);
|
|
230
|
+
}
|
|
231
|
+
const { children, ...restProps } = props;
|
|
232
|
+
if (children !== void 0 && children !== null) {
|
|
233
|
+
const childrenArray = Array.isArray(children) ? children : [children];
|
|
234
|
+
return h(tag, restProps, ...childrenArray);
|
|
235
|
+
}
|
|
236
|
+
return h(tag, restProps);
|
|
237
|
+
}
|
|
238
|
+
function jsxs(tag, props) {
|
|
239
|
+
if (!props) {
|
|
240
|
+
return h(tag, null);
|
|
241
|
+
}
|
|
242
|
+
const { children, ...restProps } = props;
|
|
243
|
+
if (Array.isArray(children)) {
|
|
244
|
+
return h(tag, restProps, ...children);
|
|
245
|
+
} else if (children !== void 0 && children !== null) {
|
|
246
|
+
return h(tag, restProps, children);
|
|
247
|
+
}
|
|
248
|
+
return h(tag, restProps);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export {
|
|
252
|
+
h,
|
|
253
|
+
Fragment,
|
|
254
|
+
jsx,
|
|
255
|
+
jsxs
|
|
256
|
+
};
|