@wsxjs/wsx-core 0.0.5
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 +21 -0
- package/dist/chunk-3CJEWYVF.mjs +197 -0
- package/dist/chunk-5JVEHB6H.mjs +197 -0
- package/dist/chunk-7E7KJQSW.mjs +210 -0
- package/dist/chunk-A5GYVTI3.mjs +222 -0
- package/dist/chunk-A5GYVTI3.mjs.map +1 -0
- package/dist/chunk-BV2V6BVN.mjs +221 -0
- package/dist/chunk-K6N3JDTI.mjs +216 -0
- package/dist/chunk-RVGKV4GP.mjs +79 -0
- package/dist/chunk-S3O776FY.mjs +173 -0
- package/dist/chunk-VNK4B3FW.mjs +217 -0
- package/dist/chunk-YNUVFDKT.mjs +222 -0
- package/dist/chunk-YNUVFDKT.mjs.map +1 -0
- package/dist/index.d.mts +235 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +755 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +524 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jsx-factory-pFUwL2Dz.d.mts +26 -0
- package/dist/jsx-factory-pFUwL2Dz.d.ts +26 -0
- package/dist/jsx-pFUwL2Dz.d.mts +26 -0
- package/dist/jsx-pFUwL2Dz.d.ts +26 -0
- package/dist/jsx-runtime-pFUwL2Dz.d.mts +26 -0
- package/dist/jsx-runtime-pFUwL2Dz.d.ts +26 -0
- package/dist/jsx-runtime.d.mts +1 -0
- package/dist/jsx-runtime.d.ts +1 -0
- package/dist/jsx-runtime.js +248 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/jsx-runtime.mjs +10 -0
- package/dist/jsx-runtime.mjs.map +1 -0
- package/dist/jsx.d.mts +66 -0
- package/dist/jsx.d.ts +66 -0
- package/dist/jsx.js +224 -0
- package/dist/jsx.js.map +1 -0
- package/dist/jsx.mjs +8 -0
- package/dist/jsx.mjs.map +1 -0
- package/package.json +49 -0
- package/src/auto-register.ts +149 -0
- package/src/index.ts +17 -0
- package/src/jsx-factory.ts +222 -0
- package/src/jsx-runtime.ts +6 -0
- package/src/jsx.ts +90 -0
- package/src/reactive-component.ts +171 -0
- package/src/styles/style-manager.ts +54 -0
- package/src/utils/logger.ts +69 -0
- package/src/utils/reactive.ts +214 -0
- package/src/utils/svg-utils.ts +184 -0
- package/src/web-component.ts +250 -0
- package/types/css-inline.d.ts +4 -0
- package/types/index.d.ts +32 -0
- package/types/jsx-runtime.d.ts +2 -0
- package/types/jsx.d.ts +28 -0
- package/types/wsx-types.d.ts +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 WSX Framework Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// src/svg-utils.ts
|
|
2
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
3
|
+
var SVG_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
|
+
"text",
|
|
20
|
+
"textPath",
|
|
21
|
+
"tspan",
|
|
22
|
+
// 渐变和模式 (Gradients and patterns)
|
|
23
|
+
"linearGradient",
|
|
24
|
+
"radialGradient",
|
|
25
|
+
"stop",
|
|
26
|
+
"pattern",
|
|
27
|
+
// 滤镜 (Filter elements)
|
|
28
|
+
"filter",
|
|
29
|
+
"feBlend",
|
|
30
|
+
"feColorMatrix",
|
|
31
|
+
"feComponentTransfer",
|
|
32
|
+
"feComposite",
|
|
33
|
+
"feConvolveMatrix",
|
|
34
|
+
"feDiffuseLighting",
|
|
35
|
+
"feDisplacementMap",
|
|
36
|
+
"feDistantLight",
|
|
37
|
+
"feDropShadow",
|
|
38
|
+
"feFlood",
|
|
39
|
+
"feFuncA",
|
|
40
|
+
"feFuncB",
|
|
41
|
+
"feFuncG",
|
|
42
|
+
"feFuncR",
|
|
43
|
+
"feGaussianBlur",
|
|
44
|
+
"feImage",
|
|
45
|
+
"feMerge",
|
|
46
|
+
"feMergeNode",
|
|
47
|
+
"feMorphology",
|
|
48
|
+
"feOffset",
|
|
49
|
+
"fePointLight",
|
|
50
|
+
"feSpecularLighting",
|
|
51
|
+
"feSpotLight",
|
|
52
|
+
"feTile",
|
|
53
|
+
"feTurbulence",
|
|
54
|
+
// 动画元素 (Animation elements)
|
|
55
|
+
"animate",
|
|
56
|
+
"animateMotion",
|
|
57
|
+
"animateTransform",
|
|
58
|
+
"set",
|
|
59
|
+
// 其他元素 (Other elements)
|
|
60
|
+
"clipPath",
|
|
61
|
+
"foreignObject",
|
|
62
|
+
"image",
|
|
63
|
+
"marker",
|
|
64
|
+
"mask",
|
|
65
|
+
"metadata",
|
|
66
|
+
"style",
|
|
67
|
+
"switch",
|
|
68
|
+
"title",
|
|
69
|
+
"desc",
|
|
70
|
+
"a"
|
|
71
|
+
]);
|
|
72
|
+
function isSVGElement(tagName) {
|
|
73
|
+
return SVG_ELEMENTS.has(tagName);
|
|
74
|
+
}
|
|
75
|
+
function createElement(tagName) {
|
|
76
|
+
if (isSVGElement(tagName)) {
|
|
77
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
78
|
+
}
|
|
79
|
+
return document.createElement(tagName);
|
|
80
|
+
}
|
|
81
|
+
var SVG_ATTRIBUTE_MAP = /* @__PURE__ */ new Map([
|
|
82
|
+
["className", "class"],
|
|
83
|
+
["htmlFor", "for"]
|
|
84
|
+
]);
|
|
85
|
+
function getSVGAttributeName(attributeName) {
|
|
86
|
+
return SVG_ATTRIBUTE_MAP.get(attributeName) || attributeName;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/jsx-factory.ts
|
|
90
|
+
function h(tag, props = {}, ...children) {
|
|
91
|
+
if (typeof tag === "function") {
|
|
92
|
+
return tag(props, children);
|
|
93
|
+
}
|
|
94
|
+
const element = createElement(tag);
|
|
95
|
+
if (props) {
|
|
96
|
+
const isSVG = isSVGElement(tag);
|
|
97
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
98
|
+
if (value === null || value === void 0 || value === false) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (key === "ref" && typeof value === "function") {
|
|
102
|
+
value(element);
|
|
103
|
+
} else if (key === "className" || key === "class") {
|
|
104
|
+
if (isSVG) {
|
|
105
|
+
element.setAttribute("class", value);
|
|
106
|
+
} else {
|
|
107
|
+
element.className = value;
|
|
108
|
+
}
|
|
109
|
+
} else if (key === "style" && typeof value === "string") {
|
|
110
|
+
element.setAttribute("style", value);
|
|
111
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
112
|
+
const eventName = key.slice(2).toLowerCase();
|
|
113
|
+
element.addEventListener(eventName, value);
|
|
114
|
+
} else if (typeof value === "boolean") {
|
|
115
|
+
if (value) {
|
|
116
|
+
element.setAttribute(key, "");
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
120
|
+
element.setAttribute(attributeName, String(value));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const flatChildren = flattenChildren(children);
|
|
125
|
+
flatChildren.forEach((child) => {
|
|
126
|
+
if (child === null || child === void 0 || child === false) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
130
|
+
element.appendChild(document.createTextNode(String(child)));
|
|
131
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
132
|
+
element.appendChild(child);
|
|
133
|
+
} else if (child instanceof DocumentFragment) {
|
|
134
|
+
element.appendChild(child);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return element;
|
|
138
|
+
}
|
|
139
|
+
function flattenChildren(children) {
|
|
140
|
+
const result = [];
|
|
141
|
+
for (const child of children) {
|
|
142
|
+
if (child === null || child === void 0 || child === false) {
|
|
143
|
+
continue;
|
|
144
|
+
} else if (Array.isArray(child)) {
|
|
145
|
+
result.push(...flattenChildren(child));
|
|
146
|
+
} else {
|
|
147
|
+
result.push(child);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function Fragment(_props, children) {
|
|
153
|
+
const fragment = document.createDocumentFragment();
|
|
154
|
+
const flatChildren = flattenChildren(children);
|
|
155
|
+
flatChildren.forEach((child) => {
|
|
156
|
+
if (child === null || child === void 0 || child === false) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
160
|
+
fragment.appendChild(document.createTextNode(String(child)));
|
|
161
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
162
|
+
fragment.appendChild(child);
|
|
163
|
+
} else if (child instanceof DocumentFragment) {
|
|
164
|
+
fragment.appendChild(child);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return fragment;
|
|
168
|
+
}
|
|
169
|
+
function jsx(tag, props) {
|
|
170
|
+
if (!props) {
|
|
171
|
+
return h(tag, null);
|
|
172
|
+
}
|
|
173
|
+
const { children, ...restProps } = props;
|
|
174
|
+
if (children !== void 0) {
|
|
175
|
+
return h(tag, restProps, children);
|
|
176
|
+
}
|
|
177
|
+
return h(tag, restProps);
|
|
178
|
+
}
|
|
179
|
+
function jsxs(tag, props) {
|
|
180
|
+
if (!props) {
|
|
181
|
+
return h(tag, null);
|
|
182
|
+
}
|
|
183
|
+
const { children, ...restProps } = props;
|
|
184
|
+
if (Array.isArray(children)) {
|
|
185
|
+
return h(tag, restProps, ...children);
|
|
186
|
+
} else if (children !== void 0) {
|
|
187
|
+
return h(tag, restProps, children);
|
|
188
|
+
}
|
|
189
|
+
return h(tag, restProps);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
h,
|
|
194
|
+
Fragment,
|
|
195
|
+
jsx,
|
|
196
|
+
jsxs
|
|
197
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// src/utils/svg-utils.ts
|
|
2
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
3
|
+
var SVG_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
|
+
"text",
|
|
20
|
+
"textPath",
|
|
21
|
+
"tspan",
|
|
22
|
+
// 渐变和模式 (Gradients and patterns)
|
|
23
|
+
"linearGradient",
|
|
24
|
+
"radialGradient",
|
|
25
|
+
"stop",
|
|
26
|
+
"pattern",
|
|
27
|
+
// 滤镜 (Filter elements)
|
|
28
|
+
"filter",
|
|
29
|
+
"feBlend",
|
|
30
|
+
"feColorMatrix",
|
|
31
|
+
"feComponentTransfer",
|
|
32
|
+
"feComposite",
|
|
33
|
+
"feConvolveMatrix",
|
|
34
|
+
"feDiffuseLighting",
|
|
35
|
+
"feDisplacementMap",
|
|
36
|
+
"feDistantLight",
|
|
37
|
+
"feDropShadow",
|
|
38
|
+
"feFlood",
|
|
39
|
+
"feFuncA",
|
|
40
|
+
"feFuncB",
|
|
41
|
+
"feFuncG",
|
|
42
|
+
"feFuncR",
|
|
43
|
+
"feGaussianBlur",
|
|
44
|
+
"feImage",
|
|
45
|
+
"feMerge",
|
|
46
|
+
"feMergeNode",
|
|
47
|
+
"feMorphology",
|
|
48
|
+
"feOffset",
|
|
49
|
+
"fePointLight",
|
|
50
|
+
"feSpecularLighting",
|
|
51
|
+
"feSpotLight",
|
|
52
|
+
"feTile",
|
|
53
|
+
"feTurbulence",
|
|
54
|
+
// 动画元素 (Animation elements)
|
|
55
|
+
"animate",
|
|
56
|
+
"animateMotion",
|
|
57
|
+
"animateTransform",
|
|
58
|
+
"set",
|
|
59
|
+
// 其他元素 (Other elements)
|
|
60
|
+
"clipPath",
|
|
61
|
+
"foreignObject",
|
|
62
|
+
"image",
|
|
63
|
+
"marker",
|
|
64
|
+
"mask",
|
|
65
|
+
"metadata",
|
|
66
|
+
"style",
|
|
67
|
+
"switch",
|
|
68
|
+
"title",
|
|
69
|
+
"desc",
|
|
70
|
+
"a"
|
|
71
|
+
]);
|
|
72
|
+
function isSVGElement(tagName) {
|
|
73
|
+
return SVG_ELEMENTS.has(tagName);
|
|
74
|
+
}
|
|
75
|
+
function createElement(tagName) {
|
|
76
|
+
if (isSVGElement(tagName)) {
|
|
77
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
78
|
+
}
|
|
79
|
+
return document.createElement(tagName);
|
|
80
|
+
}
|
|
81
|
+
var SVG_ATTRIBUTE_MAP = /* @__PURE__ */ new Map([
|
|
82
|
+
["className", "class"],
|
|
83
|
+
["htmlFor", "for"]
|
|
84
|
+
]);
|
|
85
|
+
function getSVGAttributeName(attributeName) {
|
|
86
|
+
return SVG_ATTRIBUTE_MAP.get(attributeName) || attributeName;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/jsx-factory.ts
|
|
90
|
+
function h(tag, props = {}, ...children) {
|
|
91
|
+
if (typeof tag === "function") {
|
|
92
|
+
return tag(props, children);
|
|
93
|
+
}
|
|
94
|
+
const element = createElement(tag);
|
|
95
|
+
if (props) {
|
|
96
|
+
const isSVG = isSVGElement(tag);
|
|
97
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
98
|
+
if (value === null || value === void 0 || value === false) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (key === "ref" && typeof value === "function") {
|
|
102
|
+
value(element);
|
|
103
|
+
} else if (key === "className" || key === "class") {
|
|
104
|
+
if (isSVG) {
|
|
105
|
+
element.setAttribute("class", value);
|
|
106
|
+
} else {
|
|
107
|
+
element.className = value;
|
|
108
|
+
}
|
|
109
|
+
} else if (key === "style" && typeof value === "string") {
|
|
110
|
+
element.setAttribute("style", value);
|
|
111
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
112
|
+
const eventName = key.slice(2).toLowerCase();
|
|
113
|
+
element.addEventListener(eventName, value);
|
|
114
|
+
} else if (typeof value === "boolean") {
|
|
115
|
+
if (value) {
|
|
116
|
+
element.setAttribute(key, "");
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
120
|
+
element.setAttribute(attributeName, String(value));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const flatChildren = flattenChildren(children);
|
|
125
|
+
flatChildren.forEach((child) => {
|
|
126
|
+
if (child === null || child === void 0 || child === false) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
130
|
+
element.appendChild(document.createTextNode(String(child)));
|
|
131
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
132
|
+
element.appendChild(child);
|
|
133
|
+
} else if (child instanceof DocumentFragment) {
|
|
134
|
+
element.appendChild(child);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return element;
|
|
138
|
+
}
|
|
139
|
+
function flattenChildren(children) {
|
|
140
|
+
const result = [];
|
|
141
|
+
for (const child of children) {
|
|
142
|
+
if (child === null || child === void 0 || child === false) {
|
|
143
|
+
continue;
|
|
144
|
+
} else if (Array.isArray(child)) {
|
|
145
|
+
result.push(...flattenChildren(child));
|
|
146
|
+
} else {
|
|
147
|
+
result.push(child);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function Fragment(_props, children) {
|
|
153
|
+
const fragment = document.createDocumentFragment();
|
|
154
|
+
const flatChildren = flattenChildren(children);
|
|
155
|
+
flatChildren.forEach((child) => {
|
|
156
|
+
if (child === null || child === void 0 || child === false) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
160
|
+
fragment.appendChild(document.createTextNode(String(child)));
|
|
161
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
162
|
+
fragment.appendChild(child);
|
|
163
|
+
} else if (child instanceof DocumentFragment) {
|
|
164
|
+
fragment.appendChild(child);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return fragment;
|
|
168
|
+
}
|
|
169
|
+
function jsx(tag, props) {
|
|
170
|
+
if (!props) {
|
|
171
|
+
return h(tag, null);
|
|
172
|
+
}
|
|
173
|
+
const { children, ...restProps } = props;
|
|
174
|
+
if (children !== void 0) {
|
|
175
|
+
return h(tag, restProps, children);
|
|
176
|
+
}
|
|
177
|
+
return h(tag, restProps);
|
|
178
|
+
}
|
|
179
|
+
function jsxs(tag, props) {
|
|
180
|
+
if (!props) {
|
|
181
|
+
return h(tag, null);
|
|
182
|
+
}
|
|
183
|
+
const { children, ...restProps } = props;
|
|
184
|
+
if (Array.isArray(children)) {
|
|
185
|
+
return h(tag, restProps, ...children);
|
|
186
|
+
} else if (children !== void 0) {
|
|
187
|
+
return h(tag, restProps, children);
|
|
188
|
+
}
|
|
189
|
+
return h(tag, restProps);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
h,
|
|
194
|
+
Fragment,
|
|
195
|
+
jsx,
|
|
196
|
+
jsxs
|
|
197
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
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(["a", "image", "style", "title", "text"]);
|
|
68
|
+
var SVG_ELEMENTS = /* @__PURE__ */ new Set([...SVG_ONLY_ELEMENTS, ...DUAL_ELEMENTS]);
|
|
69
|
+
var svgContext = false;
|
|
70
|
+
function isSVGOnlyElement(tagName) {
|
|
71
|
+
return SVG_ONLY_ELEMENTS.has(tagName);
|
|
72
|
+
}
|
|
73
|
+
function isDualElement(tagName) {
|
|
74
|
+
return DUAL_ELEMENTS.has(tagName);
|
|
75
|
+
}
|
|
76
|
+
function setSVGContext(inSVG) {
|
|
77
|
+
svgContext = inSVG;
|
|
78
|
+
}
|
|
79
|
+
function createElement(tagName) {
|
|
80
|
+
if (isSVGOnlyElement(tagName)) {
|
|
81
|
+
setSVGContext(true);
|
|
82
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
83
|
+
}
|
|
84
|
+
if (isDualElement(tagName)) {
|
|
85
|
+
if (svgContext) {
|
|
86
|
+
return document.createElementNS(SVG_NAMESPACE, tagName);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return document.createElement(tagName);
|
|
90
|
+
}
|
|
91
|
+
function shouldUseSVGNamespace(tagName) {
|
|
92
|
+
return isSVGOnlyElement(tagName) || isDualElement(tagName) && svgContext;
|
|
93
|
+
}
|
|
94
|
+
var SVG_ATTRIBUTE_MAP = /* @__PURE__ */ new Map([
|
|
95
|
+
["className", "class"],
|
|
96
|
+
["htmlFor", "for"]
|
|
97
|
+
]);
|
|
98
|
+
function getSVGAttributeName(attributeName) {
|
|
99
|
+
return SVG_ATTRIBUTE_MAP.get(attributeName) || attributeName;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/jsx-factory.ts
|
|
103
|
+
function h(tag, props = {}, ...children) {
|
|
104
|
+
if (typeof tag === "function") {
|
|
105
|
+
return tag(props, children);
|
|
106
|
+
}
|
|
107
|
+
const element = createElement(tag);
|
|
108
|
+
if (props) {
|
|
109
|
+
const isSVG = shouldUseSVGNamespace(tag);
|
|
110
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
111
|
+
if (value === null || value === void 0 || value === false) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (key === "ref" && typeof value === "function") {
|
|
115
|
+
value(element);
|
|
116
|
+
} else if (key === "className" || key === "class") {
|
|
117
|
+
if (isSVG) {
|
|
118
|
+
element.setAttribute("class", value);
|
|
119
|
+
} else {
|
|
120
|
+
element.className = value;
|
|
121
|
+
}
|
|
122
|
+
} else if (key === "style" && typeof value === "string") {
|
|
123
|
+
element.setAttribute("style", value);
|
|
124
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
125
|
+
const eventName = key.slice(2).toLowerCase();
|
|
126
|
+
element.addEventListener(eventName, value);
|
|
127
|
+
} else if (typeof value === "boolean") {
|
|
128
|
+
if (value) {
|
|
129
|
+
element.setAttribute(key, "");
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
133
|
+
element.setAttribute(attributeName, String(value));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const flatChildren = flattenChildren(children);
|
|
138
|
+
flatChildren.forEach((child) => {
|
|
139
|
+
if (child === null || child === void 0 || child === false) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
143
|
+
element.appendChild(document.createTextNode(String(child)));
|
|
144
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
145
|
+
element.appendChild(child);
|
|
146
|
+
} else if (child instanceof DocumentFragment) {
|
|
147
|
+
element.appendChild(child);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return element;
|
|
151
|
+
}
|
|
152
|
+
function flattenChildren(children) {
|
|
153
|
+
const result = [];
|
|
154
|
+
for (const child of children) {
|
|
155
|
+
if (child === null || child === void 0 || child === false) {
|
|
156
|
+
continue;
|
|
157
|
+
} else if (Array.isArray(child)) {
|
|
158
|
+
result.push(...flattenChildren(child));
|
|
159
|
+
} else {
|
|
160
|
+
result.push(child);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
function Fragment(_props, children) {
|
|
166
|
+
const fragment = document.createDocumentFragment();
|
|
167
|
+
const flatChildren = flattenChildren(children);
|
|
168
|
+
flatChildren.forEach((child) => {
|
|
169
|
+
if (child === null || child === void 0 || child === false) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
173
|
+
fragment.appendChild(document.createTextNode(String(child)));
|
|
174
|
+
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
175
|
+
fragment.appendChild(child);
|
|
176
|
+
} else if (child instanceof DocumentFragment) {
|
|
177
|
+
fragment.appendChild(child);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return fragment;
|
|
181
|
+
}
|
|
182
|
+
function jsx(tag, props) {
|
|
183
|
+
if (!props) {
|
|
184
|
+
return h(tag, null);
|
|
185
|
+
}
|
|
186
|
+
const { children, ...restProps } = props;
|
|
187
|
+
if (children !== void 0) {
|
|
188
|
+
return h(tag, restProps, children);
|
|
189
|
+
}
|
|
190
|
+
return h(tag, restProps);
|
|
191
|
+
}
|
|
192
|
+
function jsxs(tag, props) {
|
|
193
|
+
if (!props) {
|
|
194
|
+
return h(tag, null);
|
|
195
|
+
}
|
|
196
|
+
const { children, ...restProps } = props;
|
|
197
|
+
if (Array.isArray(children)) {
|
|
198
|
+
return h(tag, restProps, ...children);
|
|
199
|
+
} else if (children !== void 0) {
|
|
200
|
+
return h(tag, restProps, children);
|
|
201
|
+
}
|
|
202
|
+
return h(tag, restProps);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export {
|
|
206
|
+
h,
|
|
207
|
+
Fragment,
|
|
208
|
+
jsx,
|
|
209
|
+
jsxs
|
|
210
|
+
};
|