@wsxjs/wsx-core 0.0.19 → 0.0.20
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/dist/{chunk-UH5BDYGI.mjs → chunk-7FXISNME.mjs} +181 -2
- package/dist/index.js +181 -2
- package/dist/index.mjs +1 -1
- package/dist/jsx-runtime.js +181 -2
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx.js +181 -2
- package/dist/jsx.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
- package/src/jsx-factory.ts +265 -4
|
@@ -125,6 +125,186 @@ function parseHTMLToNodes(html) {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// src/jsx-factory.ts
|
|
128
|
+
function isStandardHTMLAttribute(key) {
|
|
129
|
+
const standardAttributes = /* @__PURE__ */ new Set([
|
|
130
|
+
// 全局属性
|
|
131
|
+
"id",
|
|
132
|
+
"class",
|
|
133
|
+
"className",
|
|
134
|
+
"style",
|
|
135
|
+
"title",
|
|
136
|
+
"lang",
|
|
137
|
+
"dir",
|
|
138
|
+
"hidden",
|
|
139
|
+
"tabindex",
|
|
140
|
+
"accesskey",
|
|
141
|
+
"contenteditable",
|
|
142
|
+
"draggable",
|
|
143
|
+
"spellcheck",
|
|
144
|
+
"translate",
|
|
145
|
+
"autocapitalize",
|
|
146
|
+
"autocorrect",
|
|
147
|
+
// 表单属性
|
|
148
|
+
"name",
|
|
149
|
+
"value",
|
|
150
|
+
"type",
|
|
151
|
+
"placeholder",
|
|
152
|
+
"required",
|
|
153
|
+
"disabled",
|
|
154
|
+
"readonly",
|
|
155
|
+
"checked",
|
|
156
|
+
"selected",
|
|
157
|
+
"multiple",
|
|
158
|
+
"min",
|
|
159
|
+
"max",
|
|
160
|
+
"step",
|
|
161
|
+
"autocomplete",
|
|
162
|
+
"autofocus",
|
|
163
|
+
"form",
|
|
164
|
+
"formaction",
|
|
165
|
+
"formenctype",
|
|
166
|
+
"formmethod",
|
|
167
|
+
"formnovalidate",
|
|
168
|
+
"formtarget",
|
|
169
|
+
// 链接属性
|
|
170
|
+
"href",
|
|
171
|
+
"target",
|
|
172
|
+
"rel",
|
|
173
|
+
"download",
|
|
174
|
+
"hreflang",
|
|
175
|
+
"ping",
|
|
176
|
+
// 媒体属性
|
|
177
|
+
"src",
|
|
178
|
+
"alt",
|
|
179
|
+
"width",
|
|
180
|
+
"height",
|
|
181
|
+
"poster",
|
|
182
|
+
"preload",
|
|
183
|
+
"controls",
|
|
184
|
+
"autoplay",
|
|
185
|
+
"loop",
|
|
186
|
+
"muted",
|
|
187
|
+
"playsinline",
|
|
188
|
+
"crossorigin",
|
|
189
|
+
// ARIA 属性(部分常见)
|
|
190
|
+
"role"
|
|
191
|
+
]);
|
|
192
|
+
const lowerKey = key.toLowerCase();
|
|
193
|
+
if (standardAttributes.has(lowerKey)) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (lowerKey.startsWith("data-")) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (lowerKey.startsWith("aria-")) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (key.startsWith("xml:") || key.startsWith("xlink:")) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function isSpecialProperty(key, value) {
|
|
208
|
+
return key === "ref" || key === "className" || key === "class" || key === "style" || key.startsWith("on") && typeof value === "function" || typeof value === "boolean" || key === "value";
|
|
209
|
+
}
|
|
210
|
+
function setSmartProperty(element, key, value, isSVG = false) {
|
|
211
|
+
if (isSpecialProperty(key, value)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (isStandardHTMLAttribute(key)) {
|
|
215
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
216
|
+
if (typeof value === "object" && value !== null) {
|
|
217
|
+
try {
|
|
218
|
+
const serialized = JSON.stringify(value);
|
|
219
|
+
if (serialized.length > 1024 * 1024) {
|
|
220
|
+
console.warn(
|
|
221
|
+
`[WSX] Attribute "${key}" value too large, consider using a non-standard property name instead`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
element.setAttribute(attributeName, serialized);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.warn(`[WSX] Cannot serialize attribute "${key}":`, error);
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
element.setAttribute(attributeName, String(value));
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (element instanceof SVGElement) {
|
|
234
|
+
const attributeName = getSVGAttributeName(key);
|
|
235
|
+
if (typeof value === "object" && value !== null) {
|
|
236
|
+
try {
|
|
237
|
+
const serialized = JSON.stringify(value);
|
|
238
|
+
element.setAttribute(attributeName, serialized);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.warn(`[WSX] Cannot serialize SVG attribute "${key}":`, error);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
element.setAttribute(attributeName, String(value));
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const hasProperty = key in element || Object.prototype.hasOwnProperty.call(element, key);
|
|
248
|
+
if (hasProperty) {
|
|
249
|
+
let isReadOnly = false;
|
|
250
|
+
try {
|
|
251
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), key);
|
|
252
|
+
if (descriptor) {
|
|
253
|
+
isReadOnly = descriptor.get !== void 0 && descriptor.set === void 0 || descriptor.writable === false && descriptor.set === void 0;
|
|
254
|
+
}
|
|
255
|
+
} catch {
|
|
256
|
+
}
|
|
257
|
+
if (isReadOnly) {
|
|
258
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
259
|
+
if (typeof value === "object" && value !== null) {
|
|
260
|
+
try {
|
|
261
|
+
const serialized = JSON.stringify(value);
|
|
262
|
+
element.setAttribute(attributeName, serialized);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.warn(`[WSX] Cannot serialize readonly property "${key}":`, error);
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
element.setAttribute(attributeName, String(value));
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
try {
|
|
271
|
+
element[key] = value;
|
|
272
|
+
} catch {
|
|
273
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
274
|
+
if (typeof value === "object" && value !== null) {
|
|
275
|
+
try {
|
|
276
|
+
const serialized = JSON.stringify(value);
|
|
277
|
+
element.setAttribute(attributeName, serialized);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.warn(
|
|
280
|
+
`[WSX] Cannot serialize property "${key}" for attribute:`,
|
|
281
|
+
error
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
element.setAttribute(attributeName, String(value));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
291
|
+
if (typeof value === "object" && value !== null) {
|
|
292
|
+
try {
|
|
293
|
+
const serialized = JSON.stringify(value);
|
|
294
|
+
if (serialized.length > 1024 * 1024) {
|
|
295
|
+
console.warn(
|
|
296
|
+
`[WSX] Property "${key}" value too large for attribute, consider using a JavaScript property instead`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
element.setAttribute(attributeName, serialized);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.warn(`[WSX] Cannot serialize property "${key}" for attribute:`, error);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
element.setAttribute(attributeName, String(value));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
128
308
|
function h(tag, props = {}, ...children) {
|
|
129
309
|
if (typeof tag === "function") {
|
|
130
310
|
return tag(props, children);
|
|
@@ -161,8 +341,7 @@ function h(tag, props = {}, ...children) {
|
|
|
161
341
|
element.setAttribute(attributeName, String(value));
|
|
162
342
|
}
|
|
163
343
|
} else {
|
|
164
|
-
|
|
165
|
-
element.setAttribute(attributeName, String(value));
|
|
344
|
+
setSmartProperty(element, key, value, isSVG);
|
|
166
345
|
}
|
|
167
346
|
});
|
|
168
347
|
}
|
package/dist/index.js
CHANGED
|
@@ -164,6 +164,186 @@ function parseHTMLToNodes(html) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/jsx-factory.ts
|
|
167
|
+
function isStandardHTMLAttribute(key) {
|
|
168
|
+
const standardAttributes = /* @__PURE__ */ new Set([
|
|
169
|
+
// 全局属性
|
|
170
|
+
"id",
|
|
171
|
+
"class",
|
|
172
|
+
"className",
|
|
173
|
+
"style",
|
|
174
|
+
"title",
|
|
175
|
+
"lang",
|
|
176
|
+
"dir",
|
|
177
|
+
"hidden",
|
|
178
|
+
"tabindex",
|
|
179
|
+
"accesskey",
|
|
180
|
+
"contenteditable",
|
|
181
|
+
"draggable",
|
|
182
|
+
"spellcheck",
|
|
183
|
+
"translate",
|
|
184
|
+
"autocapitalize",
|
|
185
|
+
"autocorrect",
|
|
186
|
+
// 表单属性
|
|
187
|
+
"name",
|
|
188
|
+
"value",
|
|
189
|
+
"type",
|
|
190
|
+
"placeholder",
|
|
191
|
+
"required",
|
|
192
|
+
"disabled",
|
|
193
|
+
"readonly",
|
|
194
|
+
"checked",
|
|
195
|
+
"selected",
|
|
196
|
+
"multiple",
|
|
197
|
+
"min",
|
|
198
|
+
"max",
|
|
199
|
+
"step",
|
|
200
|
+
"autocomplete",
|
|
201
|
+
"autofocus",
|
|
202
|
+
"form",
|
|
203
|
+
"formaction",
|
|
204
|
+
"formenctype",
|
|
205
|
+
"formmethod",
|
|
206
|
+
"formnovalidate",
|
|
207
|
+
"formtarget",
|
|
208
|
+
// 链接属性
|
|
209
|
+
"href",
|
|
210
|
+
"target",
|
|
211
|
+
"rel",
|
|
212
|
+
"download",
|
|
213
|
+
"hreflang",
|
|
214
|
+
"ping",
|
|
215
|
+
// 媒体属性
|
|
216
|
+
"src",
|
|
217
|
+
"alt",
|
|
218
|
+
"width",
|
|
219
|
+
"height",
|
|
220
|
+
"poster",
|
|
221
|
+
"preload",
|
|
222
|
+
"controls",
|
|
223
|
+
"autoplay",
|
|
224
|
+
"loop",
|
|
225
|
+
"muted",
|
|
226
|
+
"playsinline",
|
|
227
|
+
"crossorigin",
|
|
228
|
+
// ARIA 属性(部分常见)
|
|
229
|
+
"role"
|
|
230
|
+
]);
|
|
231
|
+
const lowerKey = key.toLowerCase();
|
|
232
|
+
if (standardAttributes.has(lowerKey)) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
if (lowerKey.startsWith("data-")) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (lowerKey.startsWith("aria-")) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (key.startsWith("xml:") || key.startsWith("xlink:")) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
function isSpecialProperty(key, value) {
|
|
247
|
+
return key === "ref" || key === "className" || key === "class" || key === "style" || key.startsWith("on") && typeof value === "function" || typeof value === "boolean" || key === "value";
|
|
248
|
+
}
|
|
249
|
+
function setSmartProperty(element, key, value, isSVG = false) {
|
|
250
|
+
if (isSpecialProperty(key, value)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (isStandardHTMLAttribute(key)) {
|
|
254
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
255
|
+
if (typeof value === "object" && value !== null) {
|
|
256
|
+
try {
|
|
257
|
+
const serialized = JSON.stringify(value);
|
|
258
|
+
if (serialized.length > 1024 * 1024) {
|
|
259
|
+
console.warn(
|
|
260
|
+
`[WSX] Attribute "${key}" value too large, consider using a non-standard property name instead`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
element.setAttribute(attributeName, serialized);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
console.warn(`[WSX] Cannot serialize attribute "${key}":`, error);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
element.setAttribute(attributeName, String(value));
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (element instanceof SVGElement) {
|
|
273
|
+
const attributeName = getSVGAttributeName(key);
|
|
274
|
+
if (typeof value === "object" && value !== null) {
|
|
275
|
+
try {
|
|
276
|
+
const serialized = JSON.stringify(value);
|
|
277
|
+
element.setAttribute(attributeName, serialized);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.warn(`[WSX] Cannot serialize SVG attribute "${key}":`, error);
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
element.setAttribute(attributeName, String(value));
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const hasProperty = key in element || Object.prototype.hasOwnProperty.call(element, key);
|
|
287
|
+
if (hasProperty) {
|
|
288
|
+
let isReadOnly = false;
|
|
289
|
+
try {
|
|
290
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), key);
|
|
291
|
+
if (descriptor) {
|
|
292
|
+
isReadOnly = descriptor.get !== void 0 && descriptor.set === void 0 || descriptor.writable === false && descriptor.set === void 0;
|
|
293
|
+
}
|
|
294
|
+
} catch {
|
|
295
|
+
}
|
|
296
|
+
if (isReadOnly) {
|
|
297
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
298
|
+
if (typeof value === "object" && value !== null) {
|
|
299
|
+
try {
|
|
300
|
+
const serialized = JSON.stringify(value);
|
|
301
|
+
element.setAttribute(attributeName, serialized);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.warn(`[WSX] Cannot serialize readonly property "${key}":`, error);
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
element.setAttribute(attributeName, String(value));
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
try {
|
|
310
|
+
element[key] = value;
|
|
311
|
+
} catch {
|
|
312
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
313
|
+
if (typeof value === "object" && value !== null) {
|
|
314
|
+
try {
|
|
315
|
+
const serialized = JSON.stringify(value);
|
|
316
|
+
element.setAttribute(attributeName, serialized);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
console.warn(
|
|
319
|
+
`[WSX] Cannot serialize property "${key}" for attribute:`,
|
|
320
|
+
error
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
element.setAttribute(attributeName, String(value));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
330
|
+
if (typeof value === "object" && value !== null) {
|
|
331
|
+
try {
|
|
332
|
+
const serialized = JSON.stringify(value);
|
|
333
|
+
if (serialized.length > 1024 * 1024) {
|
|
334
|
+
console.warn(
|
|
335
|
+
`[WSX] Property "${key}" value too large for attribute, consider using a JavaScript property instead`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
element.setAttribute(attributeName, serialized);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.warn(`[WSX] Cannot serialize property "${key}" for attribute:`, error);
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
element.setAttribute(attributeName, String(value));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
167
347
|
function h(tag, props = {}, ...children) {
|
|
168
348
|
if (typeof tag === "function") {
|
|
169
349
|
return tag(props, children);
|
|
@@ -200,8 +380,7 @@ function h(tag, props = {}, ...children) {
|
|
|
200
380
|
element.setAttribute(attributeName, String(value));
|
|
201
381
|
}
|
|
202
382
|
} else {
|
|
203
|
-
|
|
204
|
-
element.setAttribute(attributeName, String(value));
|
|
383
|
+
setSmartProperty(element, key, value, isSVG);
|
|
205
384
|
}
|
|
206
385
|
});
|
|
207
386
|
}
|
package/dist/index.mjs
CHANGED
package/dist/jsx-runtime.js
CHANGED
|
@@ -153,6 +153,186 @@ function parseHTMLToNodes(html) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// src/jsx-factory.ts
|
|
156
|
+
function isStandardHTMLAttribute(key) {
|
|
157
|
+
const standardAttributes = /* @__PURE__ */ new Set([
|
|
158
|
+
// 全局属性
|
|
159
|
+
"id",
|
|
160
|
+
"class",
|
|
161
|
+
"className",
|
|
162
|
+
"style",
|
|
163
|
+
"title",
|
|
164
|
+
"lang",
|
|
165
|
+
"dir",
|
|
166
|
+
"hidden",
|
|
167
|
+
"tabindex",
|
|
168
|
+
"accesskey",
|
|
169
|
+
"contenteditable",
|
|
170
|
+
"draggable",
|
|
171
|
+
"spellcheck",
|
|
172
|
+
"translate",
|
|
173
|
+
"autocapitalize",
|
|
174
|
+
"autocorrect",
|
|
175
|
+
// 表单属性
|
|
176
|
+
"name",
|
|
177
|
+
"value",
|
|
178
|
+
"type",
|
|
179
|
+
"placeholder",
|
|
180
|
+
"required",
|
|
181
|
+
"disabled",
|
|
182
|
+
"readonly",
|
|
183
|
+
"checked",
|
|
184
|
+
"selected",
|
|
185
|
+
"multiple",
|
|
186
|
+
"min",
|
|
187
|
+
"max",
|
|
188
|
+
"step",
|
|
189
|
+
"autocomplete",
|
|
190
|
+
"autofocus",
|
|
191
|
+
"form",
|
|
192
|
+
"formaction",
|
|
193
|
+
"formenctype",
|
|
194
|
+
"formmethod",
|
|
195
|
+
"formnovalidate",
|
|
196
|
+
"formtarget",
|
|
197
|
+
// 链接属性
|
|
198
|
+
"href",
|
|
199
|
+
"target",
|
|
200
|
+
"rel",
|
|
201
|
+
"download",
|
|
202
|
+
"hreflang",
|
|
203
|
+
"ping",
|
|
204
|
+
// 媒体属性
|
|
205
|
+
"src",
|
|
206
|
+
"alt",
|
|
207
|
+
"width",
|
|
208
|
+
"height",
|
|
209
|
+
"poster",
|
|
210
|
+
"preload",
|
|
211
|
+
"controls",
|
|
212
|
+
"autoplay",
|
|
213
|
+
"loop",
|
|
214
|
+
"muted",
|
|
215
|
+
"playsinline",
|
|
216
|
+
"crossorigin",
|
|
217
|
+
// ARIA 属性(部分常见)
|
|
218
|
+
"role"
|
|
219
|
+
]);
|
|
220
|
+
const lowerKey = key.toLowerCase();
|
|
221
|
+
if (standardAttributes.has(lowerKey)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
if (lowerKey.startsWith("data-")) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (lowerKey.startsWith("aria-")) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
if (key.startsWith("xml:") || key.startsWith("xlink:")) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
function isSpecialProperty(key, value) {
|
|
236
|
+
return key === "ref" || key === "className" || key === "class" || key === "style" || key.startsWith("on") && typeof value === "function" || typeof value === "boolean" || key === "value";
|
|
237
|
+
}
|
|
238
|
+
function setSmartProperty(element, key, value, isSVG = false) {
|
|
239
|
+
if (isSpecialProperty(key, value)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (isStandardHTMLAttribute(key)) {
|
|
243
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
244
|
+
if (typeof value === "object" && value !== null) {
|
|
245
|
+
try {
|
|
246
|
+
const serialized = JSON.stringify(value);
|
|
247
|
+
if (serialized.length > 1024 * 1024) {
|
|
248
|
+
console.warn(
|
|
249
|
+
`[WSX] Attribute "${key}" value too large, consider using a non-standard property name instead`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
element.setAttribute(attributeName, serialized);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.warn(`[WSX] Cannot serialize attribute "${key}":`, error);
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
element.setAttribute(attributeName, String(value));
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (element instanceof SVGElement) {
|
|
262
|
+
const attributeName = getSVGAttributeName(key);
|
|
263
|
+
if (typeof value === "object" && value !== null) {
|
|
264
|
+
try {
|
|
265
|
+
const serialized = JSON.stringify(value);
|
|
266
|
+
element.setAttribute(attributeName, serialized);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.warn(`[WSX] Cannot serialize SVG attribute "${key}":`, error);
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
element.setAttribute(attributeName, String(value));
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const hasProperty = key in element || Object.prototype.hasOwnProperty.call(element, key);
|
|
276
|
+
if (hasProperty) {
|
|
277
|
+
let isReadOnly = false;
|
|
278
|
+
try {
|
|
279
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), key);
|
|
280
|
+
if (descriptor) {
|
|
281
|
+
isReadOnly = descriptor.get !== void 0 && descriptor.set === void 0 || descriptor.writable === false && descriptor.set === void 0;
|
|
282
|
+
}
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
if (isReadOnly) {
|
|
286
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
287
|
+
if (typeof value === "object" && value !== null) {
|
|
288
|
+
try {
|
|
289
|
+
const serialized = JSON.stringify(value);
|
|
290
|
+
element.setAttribute(attributeName, serialized);
|
|
291
|
+
} catch (error) {
|
|
292
|
+
console.warn(`[WSX] Cannot serialize readonly property "${key}":`, error);
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
element.setAttribute(attributeName, String(value));
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
try {
|
|
299
|
+
element[key] = value;
|
|
300
|
+
} catch {
|
|
301
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
302
|
+
if (typeof value === "object" && value !== null) {
|
|
303
|
+
try {
|
|
304
|
+
const serialized = JSON.stringify(value);
|
|
305
|
+
element.setAttribute(attributeName, serialized);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
console.warn(
|
|
308
|
+
`[WSX] Cannot serialize property "${key}" for attribute:`,
|
|
309
|
+
error
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
element.setAttribute(attributeName, String(value));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
319
|
+
if (typeof value === "object" && value !== null) {
|
|
320
|
+
try {
|
|
321
|
+
const serialized = JSON.stringify(value);
|
|
322
|
+
if (serialized.length > 1024 * 1024) {
|
|
323
|
+
console.warn(
|
|
324
|
+
`[WSX] Property "${key}" value too large for attribute, consider using a JavaScript property instead`
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
element.setAttribute(attributeName, serialized);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.warn(`[WSX] Cannot serialize property "${key}" for attribute:`, error);
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
element.setAttribute(attributeName, String(value));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
156
336
|
function h(tag, props = {}, ...children) {
|
|
157
337
|
if (typeof tag === "function") {
|
|
158
338
|
return tag(props, children);
|
|
@@ -189,8 +369,7 @@ function h(tag, props = {}, ...children) {
|
|
|
189
369
|
element.setAttribute(attributeName, String(value));
|
|
190
370
|
}
|
|
191
371
|
} else {
|
|
192
|
-
|
|
193
|
-
element.setAttribute(attributeName, String(value));
|
|
372
|
+
setSmartProperty(element, key, value, isSVG);
|
|
194
373
|
}
|
|
195
374
|
});
|
|
196
375
|
}
|
package/dist/jsx-runtime.mjs
CHANGED
package/dist/jsx.js
CHANGED
|
@@ -152,6 +152,186 @@ function parseHTMLToNodes(html) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
// src/jsx-factory.ts
|
|
155
|
+
function isStandardHTMLAttribute(key) {
|
|
156
|
+
const standardAttributes = /* @__PURE__ */ new Set([
|
|
157
|
+
// 全局属性
|
|
158
|
+
"id",
|
|
159
|
+
"class",
|
|
160
|
+
"className",
|
|
161
|
+
"style",
|
|
162
|
+
"title",
|
|
163
|
+
"lang",
|
|
164
|
+
"dir",
|
|
165
|
+
"hidden",
|
|
166
|
+
"tabindex",
|
|
167
|
+
"accesskey",
|
|
168
|
+
"contenteditable",
|
|
169
|
+
"draggable",
|
|
170
|
+
"spellcheck",
|
|
171
|
+
"translate",
|
|
172
|
+
"autocapitalize",
|
|
173
|
+
"autocorrect",
|
|
174
|
+
// 表单属性
|
|
175
|
+
"name",
|
|
176
|
+
"value",
|
|
177
|
+
"type",
|
|
178
|
+
"placeholder",
|
|
179
|
+
"required",
|
|
180
|
+
"disabled",
|
|
181
|
+
"readonly",
|
|
182
|
+
"checked",
|
|
183
|
+
"selected",
|
|
184
|
+
"multiple",
|
|
185
|
+
"min",
|
|
186
|
+
"max",
|
|
187
|
+
"step",
|
|
188
|
+
"autocomplete",
|
|
189
|
+
"autofocus",
|
|
190
|
+
"form",
|
|
191
|
+
"formaction",
|
|
192
|
+
"formenctype",
|
|
193
|
+
"formmethod",
|
|
194
|
+
"formnovalidate",
|
|
195
|
+
"formtarget",
|
|
196
|
+
// 链接属性
|
|
197
|
+
"href",
|
|
198
|
+
"target",
|
|
199
|
+
"rel",
|
|
200
|
+
"download",
|
|
201
|
+
"hreflang",
|
|
202
|
+
"ping",
|
|
203
|
+
// 媒体属性
|
|
204
|
+
"src",
|
|
205
|
+
"alt",
|
|
206
|
+
"width",
|
|
207
|
+
"height",
|
|
208
|
+
"poster",
|
|
209
|
+
"preload",
|
|
210
|
+
"controls",
|
|
211
|
+
"autoplay",
|
|
212
|
+
"loop",
|
|
213
|
+
"muted",
|
|
214
|
+
"playsinline",
|
|
215
|
+
"crossorigin",
|
|
216
|
+
// ARIA 属性(部分常见)
|
|
217
|
+
"role"
|
|
218
|
+
]);
|
|
219
|
+
const lowerKey = key.toLowerCase();
|
|
220
|
+
if (standardAttributes.has(lowerKey)) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
if (lowerKey.startsWith("data-")) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
if (lowerKey.startsWith("aria-")) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
if (key.startsWith("xml:") || key.startsWith("xlink:")) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
function isSpecialProperty(key, value) {
|
|
235
|
+
return key === "ref" || key === "className" || key === "class" || key === "style" || key.startsWith("on") && typeof value === "function" || typeof value === "boolean" || key === "value";
|
|
236
|
+
}
|
|
237
|
+
function setSmartProperty(element, key, value, isSVG = false) {
|
|
238
|
+
if (isSpecialProperty(key, value)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (isStandardHTMLAttribute(key)) {
|
|
242
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
243
|
+
if (typeof value === "object" && value !== null) {
|
|
244
|
+
try {
|
|
245
|
+
const serialized = JSON.stringify(value);
|
|
246
|
+
if (serialized.length > 1024 * 1024) {
|
|
247
|
+
console.warn(
|
|
248
|
+
`[WSX] Attribute "${key}" value too large, consider using a non-standard property name instead`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
element.setAttribute(attributeName, serialized);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.warn(`[WSX] Cannot serialize attribute "${key}":`, error);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
element.setAttribute(attributeName, String(value));
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (element instanceof SVGElement) {
|
|
261
|
+
const attributeName = getSVGAttributeName(key);
|
|
262
|
+
if (typeof value === "object" && value !== null) {
|
|
263
|
+
try {
|
|
264
|
+
const serialized = JSON.stringify(value);
|
|
265
|
+
element.setAttribute(attributeName, serialized);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.warn(`[WSX] Cannot serialize SVG attribute "${key}":`, error);
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
element.setAttribute(attributeName, String(value));
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const hasProperty = key in element || Object.prototype.hasOwnProperty.call(element, key);
|
|
275
|
+
if (hasProperty) {
|
|
276
|
+
let isReadOnly = false;
|
|
277
|
+
try {
|
|
278
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), key);
|
|
279
|
+
if (descriptor) {
|
|
280
|
+
isReadOnly = descriptor.get !== void 0 && descriptor.set === void 0 || descriptor.writable === false && descriptor.set === void 0;
|
|
281
|
+
}
|
|
282
|
+
} catch {
|
|
283
|
+
}
|
|
284
|
+
if (isReadOnly) {
|
|
285
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
286
|
+
if (typeof value === "object" && value !== null) {
|
|
287
|
+
try {
|
|
288
|
+
const serialized = JSON.stringify(value);
|
|
289
|
+
element.setAttribute(attributeName, serialized);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.warn(`[WSX] Cannot serialize readonly property "${key}":`, error);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
element.setAttribute(attributeName, String(value));
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
try {
|
|
298
|
+
element[key] = value;
|
|
299
|
+
} catch {
|
|
300
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
301
|
+
if (typeof value === "object" && value !== null) {
|
|
302
|
+
try {
|
|
303
|
+
const serialized = JSON.stringify(value);
|
|
304
|
+
element.setAttribute(attributeName, serialized);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.warn(
|
|
307
|
+
`[WSX] Cannot serialize property "${key}" for attribute:`,
|
|
308
|
+
error
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
element.setAttribute(attributeName, String(value));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
318
|
+
if (typeof value === "object" && value !== null) {
|
|
319
|
+
try {
|
|
320
|
+
const serialized = JSON.stringify(value);
|
|
321
|
+
if (serialized.length > 1024 * 1024) {
|
|
322
|
+
console.warn(
|
|
323
|
+
`[WSX] Property "${key}" value too large for attribute, consider using a JavaScript property instead`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
element.setAttribute(attributeName, serialized);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
console.warn(`[WSX] Cannot serialize property "${key}" for attribute:`, error);
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
element.setAttribute(attributeName, String(value));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
155
335
|
function h(tag, props = {}, ...children) {
|
|
156
336
|
if (typeof tag === "function") {
|
|
157
337
|
return tag(props, children);
|
|
@@ -188,8 +368,7 @@ function h(tag, props = {}, ...children) {
|
|
|
188
368
|
element.setAttribute(attributeName, String(value));
|
|
189
369
|
}
|
|
190
370
|
} else {
|
|
191
|
-
|
|
192
|
-
element.setAttribute(attributeName, String(value));
|
|
371
|
+
setSmartProperty(element, key, value, isSVG);
|
|
193
372
|
}
|
|
194
373
|
});
|
|
195
374
|
}
|
package/dist/jsx.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fileNames":["../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/utils/svg-utils.ts","../src/utils/dom-utils.ts","../src/jsx-factory.ts","../src/styles/style-manager.ts","../../../node_modules/.pnpm/loglevel@1.9.2/node_modules/loglevel/index.d.ts","../../logger/dist/index.d.ts","../src/utils/reactive.ts","../src/base-component.ts","../src/web-component.ts","../src/light-component.ts","../src/reactive-decorator.ts","../src/index.ts","../types/wsx-types.d.ts","../types/jsx.d.ts","../types/jsx-runtime.d.ts","../src/auto-register.ts","../src/jsx-runtime.ts","../src/jsx.ts","../src/utils/logger.ts","../__tests__/jsx-factory.test.ts","../__tests__/light-component.test.ts","../__tests__/rerender-scheduling.test.ts","../__tests__/smart-property-assignment.test.ts","../__tests__/web-component.test.ts","../../../node_modules/.pnpm/@jest+expect-utils@29.7.0/node_modules/@jest/expect-utils/build/index.d.ts","../../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/index.d.ts","../../../node_modules/.pnpm/@sinclair+typebox@0.27.8/node_modules/@sinclair/typebox/typebox.d.ts","../../../node_modules/.pnpm/@jest+schemas@29.6.3/node_modules/@jest/schemas/build/index.d.ts","../../../node_modules/.pnpm/pretty-format@29.7.0/node_modules/pretty-format/build/index.d.ts","../../../node_modules/.pnpm/jest-diff@29.7.0/node_modules/jest-diff/build/index.d.ts","../../../node_modules/.pnpm/jest-matcher-utils@29.7.0/node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/.pnpm/expect@29.7.0/node_modules/expect/build/index.d.ts","../../../node_modules/.pnpm/@types+jest@29.5.14/node_modules/@types/jest/index.d.ts"],"fileIdsList":[[74],[76,79],[72,78],[76],[73,77],[75],[49,50,62],[50,57,62],[50,56,57,62],[50,62],[50,56,62],[62],[54,62],[50,51,53,54,56,57,58,62,63],[48,49,62],[50,53,55,62],[53,62],[50,51,53,55,62],[60,61],[60],[59],[52]],"fileInfos":[{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedFormat":1},{"version":"07f073f19d67f74d732b1adea08e1dc66b1b58d77cb5b43931dee3d798a2fd53","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"fef8cfad2e2dc5f5b3d97a6f4f2e92848eb1b88e897bb7318cef0e2820bceaab","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},"a2d11f94d9a2763a19430da7aa846ed2bddd53c76fa3f14d13d88bb4934f2579","d9378f1d2add3a8ef09a80ceb45c7538f791e4814486f6f87c1f75b8770f0087","19ecfd858f27b7e87d132d22bd2575f68018976e8c5eec44b7557660a54e08e1","752a4c5da1ed657428bfe7047a43b9166d20ac19c33d840eabce154f9f5df55b",{"version":"4aa7fdc017a0a097c71ada2ca187e1475c987b4f933960c0792eb143997e4709","impliedFormat":1},"65f3f541c306088b14dfde53f7f67f2eb6234597ba74801ee5a2e44df7f9d860","3bbe77bad784daab0ac850c6f8c2b023b3710db3060a3aeabe21c596dc5f0a4e","a06838dad2d7796480c030cb18248fcc2426fd4d375815605f11c541e8fae335","43b40612ad49a6037dd0ba70ff6756a2061c43a222b7662857aa2b050463b9b1","cdf1b6ea25f550c5b3a30c3586e2022659e21854056af3bca69206b4a74265f9","a53adc49fae50b1d885d47272fd7aea88ff0b94ad9a09a2a65974f5fe471850d","f33cac031ee04cafbc468177540c251ba1630f0e6f5f4eeeae2103b7ef7b4758","2261a58ed7f7ced3c20de3753f86aaf4cb80ca718340d532083f9dd8febe6a87","884a9ee6ee9ff94877b6819c427264ce8abd52a279707df0981e0beb520d08f7","3738a73aea7d44b8dc355a1d9412abe6a0493a22edb29a5f08e9b02667134b41","464b245ec63af0bc42fef5f74fc475b115fc9e93512fb0d13779ccf25f292a99","4c5dad0fedb9673bc9b978f89d8c735d822ab75dede69b2bff8f20675c06d5de",{"version":"a8b4590bd7202b0be959940994ef48c7e691c9b27d801b6a2ccf9cf9465343bf","affectsGlobalScope":true},"89fa01b584a104cc2e17900f8bcabaffbcab38908c8acc6422e24e27a7dbca5b","8873e9704caaf70f835f8394d09859b7543cb424cf30fb1d1949193f0d57da03","0417587f3573e747db27c92410d078affb8b8bbb9d74edf38209ec563bb1dcd5","084104d236d7263594343ab8be09e1472dfa8bc4a6787d7c73c8e362ae62b3c1","ee4d984eff6c775b61d5b0e50c9ba9b989a84d36929959d4b68ca5b33dae6310","b0c84003af094406e722c9519bb83d54e0609f488fa529fe430b1378a8c9db42",{"version":"cdcc132f207d097d7d3aa75615ab9a2e71d6a478162dde8b67f88ea19f3e54de","impliedFormat":1},{"version":"0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","impliedFormat":1},{"version":"c085e9aa62d1ae1375794c1fb927a445fa105fed891a7e24edbb1c3300f7384a","impliedFormat":1},{"version":"f315e1e65a1f80992f0509e84e4ae2df15ecd9ef73df975f7c98813b71e4c8da","impliedFormat":1},{"version":"5b9586e9b0b6322e5bfbd2c29bd3b8e21ab9d871f82346cb71020e3d84bae73e","impliedFormat":1},{"version":"3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","impliedFormat":1},{"version":"ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","impliedFormat":1},{"version":"d96cc6598148bf1a98fb2e8dcf01c63a4b3558bdaec6ef35e087fd0562eb40ec","impliedFormat":1},{"version":"f8db4fea512ab759b2223b90ecbbe7dae919c02f8ce95ec03f7fb1cf757cfbeb","affectsGlobalScope":true,"impliedFormat":1}],"root":[[48,51],[54,60],[63,71]],"options":{"allowImportingTsExtensions":true,"composite":true,"declaration":true,"declarationMap":true,"emitDecoratorMetadata":true,"experimentalDecorators":true,"jsx":4,"jsxImportSource":"@wsxjs/wsx-core","module":99,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"target":7,"useDefineForClassFields":false},"referencedMap":[[75,1],[80,2],[79,3],[77,4],[78,5],[76,6],[67,7],[68,8],[69,9],[70,10],[71,11],[63,12],[55,13],[59,14],[50,15],[64,10],[65,10],[57,16],[58,12],[51,12],[49,12],[66,12],[54,17],[48,12],[56,18],[62,19],[61,20],[60,21],[53,22]],"affectedFilesPendingEmit":[[67,51],[68,51],[69,51],[70,51],[71,51],[63,51],[55,51],[59,51],[50,51],[64,51],[65,51],[57,51],[58,51],[51,51],[49,51],[66,51],[54,51],[48,51],[56,51]],"emitSignatures":[48,49,50,51,54,55,56,57,58,59,63,64,65,66,67,68,69,70,71],"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsxjs/wsx-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Core WSXJS - Web Components with JSX syntax",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"custom-elements"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@wsxjs/wsx-logger": "0.0.
|
|
51
|
+
"@wsxjs/wsx-logger": "0.0.20"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsup": "^8.0.0",
|
package/src/jsx-factory.ts
CHANGED
|
@@ -14,6 +14,269 @@
|
|
|
14
14
|
import { createElement, shouldUseSVGNamespace, getSVGAttributeName } from "./utils/svg-utils";
|
|
15
15
|
import { parseHTMLToNodes } from "./utils/dom-utils";
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* 检查是否是 HTML 标准属性
|
|
19
|
+
* HTML First 策略的核心:优先识别标准属性
|
|
20
|
+
*
|
|
21
|
+
* @param key - 属性名
|
|
22
|
+
* @returns 是否是标准 HTML 属性
|
|
23
|
+
*/
|
|
24
|
+
function isStandardHTMLAttribute(key: string): boolean {
|
|
25
|
+
// 标准 HTML 属性集合(常见属性)
|
|
26
|
+
const standardAttributes = new Set([
|
|
27
|
+
// 全局属性
|
|
28
|
+
"id",
|
|
29
|
+
"class",
|
|
30
|
+
"className",
|
|
31
|
+
"style",
|
|
32
|
+
"title",
|
|
33
|
+
"lang",
|
|
34
|
+
"dir",
|
|
35
|
+
"hidden",
|
|
36
|
+
"tabindex",
|
|
37
|
+
"accesskey",
|
|
38
|
+
"contenteditable",
|
|
39
|
+
"draggable",
|
|
40
|
+
"spellcheck",
|
|
41
|
+
"translate",
|
|
42
|
+
"autocapitalize",
|
|
43
|
+
"autocorrect",
|
|
44
|
+
// 表单属性
|
|
45
|
+
"name",
|
|
46
|
+
"value",
|
|
47
|
+
"type",
|
|
48
|
+
"placeholder",
|
|
49
|
+
"required",
|
|
50
|
+
"disabled",
|
|
51
|
+
"readonly",
|
|
52
|
+
"checked",
|
|
53
|
+
"selected",
|
|
54
|
+
"multiple",
|
|
55
|
+
"min",
|
|
56
|
+
"max",
|
|
57
|
+
"step",
|
|
58
|
+
"autocomplete",
|
|
59
|
+
"autofocus",
|
|
60
|
+
"form",
|
|
61
|
+
"formaction",
|
|
62
|
+
"formenctype",
|
|
63
|
+
"formmethod",
|
|
64
|
+
"formnovalidate",
|
|
65
|
+
"formtarget",
|
|
66
|
+
// 链接属性
|
|
67
|
+
"href",
|
|
68
|
+
"target",
|
|
69
|
+
"rel",
|
|
70
|
+
"download",
|
|
71
|
+
"hreflang",
|
|
72
|
+
"ping",
|
|
73
|
+
// 媒体属性
|
|
74
|
+
"src",
|
|
75
|
+
"alt",
|
|
76
|
+
"width",
|
|
77
|
+
"height",
|
|
78
|
+
"poster",
|
|
79
|
+
"preload",
|
|
80
|
+
"controls",
|
|
81
|
+
"autoplay",
|
|
82
|
+
"loop",
|
|
83
|
+
"muted",
|
|
84
|
+
"playsinline",
|
|
85
|
+
"crossorigin",
|
|
86
|
+
// ARIA 属性(部分常见)
|
|
87
|
+
"role",
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
const lowerKey = key.toLowerCase();
|
|
91
|
+
|
|
92
|
+
// 检查是否是标准属性
|
|
93
|
+
if (standardAttributes.has(lowerKey)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 检查是否是 data-* 属性(必须使用连字符)
|
|
98
|
+
// 注意:单独的 "data" 不是标准属性,不在这个列表中
|
|
99
|
+
// data 可以检查 JavaScript 属性,data-* 只使用 setAttribute
|
|
100
|
+
if (lowerKey.startsWith("data-")) {
|
|
101
|
+
return true; // 标准属性,只使用 setAttribute,不检查对象属性
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 检查是否是 aria-* 属性
|
|
105
|
+
if (lowerKey.startsWith("aria-")) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 检查是否是 SVG 命名空间属性
|
|
110
|
+
if (key.startsWith("xml:") || key.startsWith("xlink:")) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 检查是否是特殊属性(已有专门处理逻辑的属性)
|
|
119
|
+
* 这些属性不应该进入通用属性处理流程
|
|
120
|
+
*/
|
|
121
|
+
function isSpecialProperty(key: string, value: unknown): boolean {
|
|
122
|
+
return (
|
|
123
|
+
key === "ref" ||
|
|
124
|
+
key === "className" ||
|
|
125
|
+
key === "class" ||
|
|
126
|
+
key === "style" ||
|
|
127
|
+
(key.startsWith("on") && typeof value === "function") ||
|
|
128
|
+
typeof value === "boolean" ||
|
|
129
|
+
key === "value"
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 智能属性设置函数
|
|
135
|
+
* HTML First 策略:优先使用 HTML 属性,避免与标准属性冲突
|
|
136
|
+
*
|
|
137
|
+
* @param element - DOM 元素
|
|
138
|
+
* @param key - 属性名
|
|
139
|
+
* @param value - 属性值
|
|
140
|
+
* @param isSVG - 是否是 SVG 元素
|
|
141
|
+
*/
|
|
142
|
+
function setSmartProperty(
|
|
143
|
+
element: HTMLElement | SVGElement,
|
|
144
|
+
key: string,
|
|
145
|
+
value: unknown,
|
|
146
|
+
isSVG: boolean = false
|
|
147
|
+
): void {
|
|
148
|
+
// 1. 检查是否是特殊属性(已有处理逻辑的属性)
|
|
149
|
+
if (isSpecialProperty(key, value)) {
|
|
150
|
+
return; // 由现有逻辑处理
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 2. HTML First: 优先检查是否是 HTML 标准属性
|
|
154
|
+
if (isStandardHTMLAttribute(key)) {
|
|
155
|
+
// 标准 HTML 属性:直接使用 setAttribute,不检查 JavaScript 属性
|
|
156
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
157
|
+
|
|
158
|
+
// 对于复杂类型,尝试序列化
|
|
159
|
+
if (typeof value === "object" && value !== null) {
|
|
160
|
+
try {
|
|
161
|
+
const serialized = JSON.stringify(value);
|
|
162
|
+
// 检查长度限制(保守估计 1MB)
|
|
163
|
+
if (serialized.length > 1024 * 1024) {
|
|
164
|
+
console.warn(
|
|
165
|
+
`[WSX] Attribute "${key}" value too large, ` +
|
|
166
|
+
`consider using a non-standard property name instead`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
element.setAttribute(attributeName, serialized);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
// 无法序列化(如循环引用),警告并跳过
|
|
172
|
+
console.warn(`[WSX] Cannot serialize attribute "${key}":`, error);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
element.setAttribute(attributeName, String(value));
|
|
176
|
+
}
|
|
177
|
+
// 重要:标准属性只使用 setAttribute,不使用 JavaScript 属性
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 3. SVG 元素特殊处理:对于 SVG 元素,很多属性应该直接使用 setAttribute
|
|
182
|
+
// 因为 SVG 元素的很多属性是只读的(如 viewBox)
|
|
183
|
+
if (element instanceof SVGElement) {
|
|
184
|
+
const attributeName = getSVGAttributeName(key);
|
|
185
|
+
// 对于复杂类型,尝试序列化
|
|
186
|
+
if (typeof value === "object" && value !== null) {
|
|
187
|
+
try {
|
|
188
|
+
const serialized = JSON.stringify(value);
|
|
189
|
+
element.setAttribute(attributeName, serialized);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.warn(`[WSX] Cannot serialize SVG attribute "${key}":`, error);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
element.setAttribute(attributeName, String(value));
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 4. 非标准属性:检查元素是否有该 JavaScript 属性
|
|
200
|
+
const hasProperty = key in element || Object.prototype.hasOwnProperty.call(element, key);
|
|
201
|
+
|
|
202
|
+
if (hasProperty) {
|
|
203
|
+
// 检查是否是只读属性
|
|
204
|
+
let isReadOnly = false;
|
|
205
|
+
try {
|
|
206
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), key);
|
|
207
|
+
if (descriptor) {
|
|
208
|
+
isReadOnly =
|
|
209
|
+
(descriptor.get !== undefined && descriptor.set === undefined) ||
|
|
210
|
+
(descriptor.writable === false && descriptor.set === undefined);
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
// 忽略错误,继续尝试设置
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (isReadOnly) {
|
|
217
|
+
// 只读属性使用 setAttribute
|
|
218
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
219
|
+
// 对于复杂类型,尝试序列化
|
|
220
|
+
if (typeof value === "object" && value !== null) {
|
|
221
|
+
try {
|
|
222
|
+
const serialized = JSON.stringify(value);
|
|
223
|
+
element.setAttribute(attributeName, serialized);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.warn(`[WSX] Cannot serialize readonly property "${key}":`, error);
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
element.setAttribute(attributeName, String(value));
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
// 使用 JavaScript 属性赋值(支持任意类型)
|
|
232
|
+
try {
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
|
+
(element as any)[key] = value;
|
|
235
|
+
} catch {
|
|
236
|
+
// 如果赋值失败,回退到 setAttribute
|
|
237
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
238
|
+
// 对于复杂类型,尝试序列化
|
|
239
|
+
if (typeof value === "object" && value !== null) {
|
|
240
|
+
try {
|
|
241
|
+
const serialized = JSON.stringify(value);
|
|
242
|
+
element.setAttribute(attributeName, serialized);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.warn(
|
|
245
|
+
`[WSX] Cannot serialize property "${key}" for attribute:`,
|
|
246
|
+
error
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
element.setAttribute(attributeName, String(value));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
// 没有 JavaScript 属性,使用 setAttribute
|
|
256
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
257
|
+
|
|
258
|
+
// 对于复杂类型,尝试序列化
|
|
259
|
+
if (typeof value === "object" && value !== null) {
|
|
260
|
+
try {
|
|
261
|
+
const serialized = JSON.stringify(value);
|
|
262
|
+
// 检查长度限制
|
|
263
|
+
if (serialized.length > 1024 * 1024) {
|
|
264
|
+
console.warn(
|
|
265
|
+
`[WSX] Property "${key}" value too large for attribute, ` +
|
|
266
|
+
`consider using a JavaScript property instead`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
element.setAttribute(attributeName, serialized);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// 无法序列化,警告并跳过
|
|
272
|
+
console.warn(`[WSX] Cannot serialize property "${key}" for attribute:`, error);
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
element.setAttribute(attributeName, String(value));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
17
280
|
// JSX子元素类型
|
|
18
281
|
export type JSXChildren =
|
|
19
282
|
| string
|
|
@@ -105,11 +368,9 @@ export function h(
|
|
|
105
368
|
element.setAttribute(attributeName, String(value));
|
|
106
369
|
}
|
|
107
370
|
}
|
|
108
|
-
// 处理其他属性
|
|
371
|
+
// 处理其他属性 - 使用智能属性设置函数
|
|
109
372
|
else {
|
|
110
|
-
|
|
111
|
-
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
112
|
-
element.setAttribute(attributeName, String(value));
|
|
373
|
+
setSmartProperty(element, key, value, isSVG);
|
|
113
374
|
}
|
|
114
375
|
});
|
|
115
376
|
}
|