@wiajs/core 1.1.32 → 1.2.1

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/core.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.32
2
+ * wia core v1.2.1
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.32
2
+ * wia core v1.2.1
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/core.min.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * wia core v1.1.32
2
+ * wia core v1.2.1
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  /*!
7
- * wia core v1.1.32
7
+ * wia core v1.2.1
8
8
  * (c) 2015-2025 Sibyl Yu and contributors
9
9
  * Released under the MIT License.
10
10
  */
package/dist/core.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.32
2
+ * wia core v1.2.1
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.32
2
+ * wia core v1.2.1
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -10,6 +10,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
10
10
  var jsxRuntime = {};
11
11
 
12
12
  // runtime: 'automatic', // automatic or classic automatic 使用 JSX 运行时(在React 17 中引入)
13
+ // HTML 属性值转义函数
14
+ function escapeAttrValue(value) {
15
+ return String(value)
16
+ .replace(/&/g, "&")
17
+ .replace(/"/g, """)
18
+ .replace(/</g, "&lt;")
19
+ .replace(/>/g, "&gt;");
20
+ }
21
+
13
22
  function jsx(tag, {children, ...props} = {}) {
14
23
  let R = '';
15
24
 
@@ -20,15 +29,38 @@ function jsx(tag, {children, ...props} = {}) {
20
29
 
21
30
  // 特殊处理 className 和 htmlFor
22
31
  if (attrs.className) {
23
- attrsArray.push(`class="${attrs.className}"`);
32
+ attrsArray.push(`class="${escapeAttrValue(attrs.className)}"`);
24
33
  delete attrs.className;
25
34
  }
26
35
 
27
36
  if (attrs.htmlFor) {
28
- attrsArray.push(`for="${attrs.htmlFor}"`);
37
+ attrsArray.push(`for="${escapeAttrValue(attrs.htmlFor)}"`);
29
38
  delete attrs.htmlFor;
30
39
  }
31
40
 
41
+ // 处理 style 对象
42
+ if (attrs.style && typeof attrs.style === 'object') {
43
+ const styleArray = [];
44
+ for (const [key, value] of Object.entries(attrs.style)) {
45
+ if (value == null) continue;
46
+
47
+ // 转换驼峰式属性为CSS属性(backgroundColor -> background-color)
48
+ const cssProp = key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
49
+
50
+ // 处理数值属性(添加px单位)
51
+ let cssValue = value;
52
+ if (typeof value === 'number' &&
53
+ // 这些属性不需要单位
54
+ !['zIndex', 'opacity', 'fontWeight', 'flex', 'order', 'zoom'].includes(key)) {
55
+ cssValue = `${value}px`;
56
+ }
57
+
58
+ styleArray.push(`${cssProp}:${cssValue}`);
59
+ }
60
+ attrsArray.push(`style="${escapeAttrValue(styleArray.join(';'))}"`);
61
+ delete attrs.style;
62
+ }
63
+
32
64
  // 处理其他属性
33
65
  for (const [key, value] of Object.entries(attrs)) {
34
66
  // 跳过特殊处理的属性
@@ -36,13 +68,11 @@ function jsx(tag, {children, ...props} = {}) {
36
68
 
37
69
  // 处理布尔属性(如 disabled, checked 等)
38
70
  if (typeof value === 'boolean') {
39
- if (value) {
40
- attrsArray.push(key);
41
- }
71
+ if (value) attrsArray.push(key);
42
72
  }
43
73
  // 处理动态值属性
44
74
  else if (value != null) {
45
- attrsArray.push(`${key}="${value}"`);
75
+ attrsArray.push(`${key}="${escapeAttrValue(value)}"`);
46
76
  }
47
77
  }
48
78
 
@@ -62,16 +92,25 @@ function jsx(tag, {children, ...props} = {}) {
62
92
  // 自闭合标签处理
63
93
  const voidElements = ['input', 'img', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'param', 'source', 'track', 'wbr', 'path', 'circle', 'polygon', 'line', 'rect', 'ellipse', 'use', 'stop'];
64
94
  if (voidElements.includes(tag))
65
- R = `<${tag} ${attrsString} />`.trim();
95
+ R = `<${tag}${attrsString ? ' ' + attrsString : ''} />`;
66
96
  else {
67
97
  const childrenContent = Array.isArray(children)
68
98
  ? children
69
- .filter(c => c != null)
70
- .map(c => (Array.isArray(c) ? c.join('') : c))
99
+ .filter(c => c != null) // 只过滤 null/undefined
100
+ .map(c => {
101
+ if (Array.isArray(c)) return c.join('');
102
+
103
+ // 特殊处理布尔值(不渲染)
104
+ if (typeof c === 'boolean') return '';
105
+
106
+ return c;
107
+ })
71
108
  .join('')
72
- : children || '';
109
+ : children != null
110
+ ? (typeof children === 'boolean' ? '' : children)
111
+ : '';
73
112
 
74
- R = `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
113
+ R = `<${tag}${attrsString ? ' ' + attrsString : ''}>${childrenContent}</${tag}>`;
75
114
  }
76
115
  }
77
116
 
@@ -81,10 +120,16 @@ function jsx(tag, {children, ...props} = {}) {
81
120
  function Fragment({children} = {}) {
82
121
  const R = Array.isArray(children)
83
122
  ? children
84
- .filter(c => c != null)
85
- .map(c => (Array.isArray(c) ? c.join('') : c))
123
+ .filter(c => c != null) // 只过滤 null/undefined
124
+ .map(c => {
125
+ if (Array.isArray(c)) return c.join('');
126
+ if (typeof c === 'boolean') return '';
127
+ return c;
128
+ })
86
129
  .join('')
87
- : children || '';
130
+ : children != null
131
+ ? (typeof children === 'boolean' ? '' : children)
132
+ : '';
88
133
 
89
134
  return R;
90
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiajs/core",
3
- "version": "1.1.32",
3
+ "version": "1.2.1",
4
4
  "description": "wia app core package",
5
5
  "main": "./dist/core.cjs",
6
6
  "module": "./dist/core.mjs",