@wiajs/core 1.1.30 → 1.1.32
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 +1 -1
- package/dist/core.js +1 -1
- package/dist/core.min.js +2 -2
- package/dist/core.mjs +1 -1
- package/dist/jsx-runtime.js +44 -10
- package/package.json +1 -1
- package/util/tool.js +40 -36
- package/util/wiapack.js +16 -19
package/dist/core.cjs
CHANGED
package/dist/core.js
CHANGED
package/dist/core.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia core v1.1.
|
|
2
|
+
* wia core v1.1.32
|
|
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.
|
|
7
|
+
* wia core v1.1.32
|
|
8
8
|
* (c) 2015-2025 Sibyl Yu and contributors
|
|
9
9
|
* Released under the MIT License.
|
|
10
10
|
*/
|
package/dist/core.mjs
CHANGED
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia core v1.1.
|
|
2
|
+
* wia core v1.1.32
|
|
3
3
|
* (c) 2015-2025 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -16,7 +16,39 @@ function jsx(tag, {children, ...props} = {}) {
|
|
|
16
16
|
if (typeof tag === 'function') R = tag({children, ...props});
|
|
17
17
|
else if (typeof tag === 'string') {
|
|
18
18
|
const attrs = props || {};
|
|
19
|
-
const
|
|
19
|
+
const attrsArray = [];
|
|
20
|
+
|
|
21
|
+
// 特殊处理 className 和 htmlFor
|
|
22
|
+
if (attrs.className) {
|
|
23
|
+
attrsArray.push(`class="${attrs.className}"`);
|
|
24
|
+
delete attrs.className;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (attrs.htmlFor) {
|
|
28
|
+
attrsArray.push(`for="${attrs.htmlFor}"`);
|
|
29
|
+
delete attrs.htmlFor;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 处理其他属性
|
|
33
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
34
|
+
// 跳过特殊处理的属性
|
|
35
|
+
if (key === 'children' || key === 'className' || key === 'htmlFor') continue;
|
|
36
|
+
|
|
37
|
+
// 处理布尔属性(如 disabled, checked 等)
|
|
38
|
+
if (typeof value === 'boolean') {
|
|
39
|
+
if (value) {
|
|
40
|
+
attrsArray.push(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// 处理动态值属性
|
|
44
|
+
else if (value != null) {
|
|
45
|
+
attrsArray.push(`${key}="${value}"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const attrsString = attrsArray.join(' ');
|
|
50
|
+
|
|
51
|
+
/* const attrsString = Object.keys(attrs)
|
|
20
52
|
.map(attr => {
|
|
21
53
|
if (attr[0] === '_') {
|
|
22
54
|
if (attrs[attr]) return attr.replace('_', '');
|
|
@@ -26,18 +58,20 @@ function jsx(tag, {children, ...props} = {}) {
|
|
|
26
58
|
})
|
|
27
59
|
.filter(attr => !!attr)
|
|
28
60
|
.join(' ');
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
*/
|
|
62
|
+
// 自闭合标签处理
|
|
63
|
+
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
|
+
if (voidElements.includes(tag))
|
|
31
65
|
R = `<${tag} ${attrsString} />`.trim();
|
|
32
66
|
else {
|
|
33
67
|
const childrenContent = Array.isArray(children)
|
|
34
68
|
? children
|
|
35
|
-
.filter(c =>
|
|
69
|
+
.filter(c => c != null)
|
|
36
70
|
.map(c => (Array.isArray(c) ? c.join('') : c))
|
|
37
71
|
.join('')
|
|
38
|
-
: children;
|
|
72
|
+
: children || '';
|
|
39
73
|
|
|
40
|
-
R = `<${tag} ${attrsString}>${childrenContent
|
|
74
|
+
R = `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
|
|
41
75
|
}
|
|
42
76
|
}
|
|
43
77
|
|
|
@@ -47,12 +81,12 @@ function jsx(tag, {children, ...props} = {}) {
|
|
|
47
81
|
function Fragment({children} = {}) {
|
|
48
82
|
const R = Array.isArray(children)
|
|
49
83
|
? children
|
|
50
|
-
.filter(c =>
|
|
84
|
+
.filter(c => c != null)
|
|
51
85
|
.map(c => (Array.isArray(c) ? c.join('') : c))
|
|
52
86
|
.join('')
|
|
53
|
-
: children;
|
|
87
|
+
: children || '';
|
|
54
88
|
|
|
55
|
-
return R
|
|
89
|
+
return R;
|
|
56
90
|
}
|
|
57
91
|
|
|
58
92
|
var Fragment_1 = jsxRuntime.Fragment = Fragment;
|
package/package.json
CHANGED
package/util/tool.js
CHANGED
|
@@ -130,43 +130,47 @@ function newFileName(len) {
|
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* 比较方法,用于对象数组排序,常用于数据表排序
|
|
133
|
-
* @param {
|
|
134
|
-
* @param {
|
|
135
|
-
* @param {
|
|
133
|
+
* @param {string} k 对象属性key
|
|
134
|
+
* @param {boolean} desc 升序、降序,默认升序
|
|
135
|
+
* @param {string} type 类型auto, number、date、string,缺省 auto
|
|
136
|
+
* @param {string} [sub] 子对象
|
|
136
137
|
*/
|
|
137
|
-
function compareObj(k, desc, type) {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
138
|
+
function compareObj(k, desc, type, sub) {
|
|
139
|
+
return (o1, o2) => {
|
|
140
|
+
let R = 0
|
|
141
|
+
try {
|
|
142
|
+
let v1 = sub ? o1[sub][k] : o1[k]
|
|
143
|
+
let v2 = sub ? o2[sub][k] : o2[k]
|
|
144
|
+
|
|
145
|
+
// log({v1, v2, type}, 'compareObj')
|
|
146
|
+
|
|
147
|
+
if (typeof v1 === 'string' || typeof v2 === 'string') {
|
|
148
|
+
// 数字、日期字符串,按数字、日期排序
|
|
149
|
+
// 金额可能有千字分隔符,需替换
|
|
150
|
+
if (type.toLowerCase() === 'number') {
|
|
151
|
+
if (typeof v1 === 'string') {
|
|
152
|
+
v1 = v1.replaceAll(',', '').replaceAll(/null|-|^$/g, '0')
|
|
153
|
+
v1 = Number(v1)
|
|
154
|
+
}
|
|
155
|
+
if (typeof v2 === 'string') {
|
|
156
|
+
v2 = v2.replaceAll(',', '').replaceAll(/null|-|^$/g, '0')
|
|
157
|
+
v2 = Number(v2)
|
|
158
|
+
}
|
|
159
|
+
} else if (type.toLowerCase() === 'date') {
|
|
160
|
+
v1 = Date.parse(v1)
|
|
161
|
+
v2 = Date.parse(v2)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (v1 < v2) R = desc ? 1 : -1
|
|
166
|
+
else if (v1 > v2) R = desc ? -1 : 1
|
|
167
|
+
|
|
168
|
+
// log({v1, v2, R}, 'compareObj')
|
|
169
|
+
} catch (ex) {
|
|
170
|
+
console.log('compareObj exp:', ex.message)
|
|
171
|
+
}
|
|
172
|
+
return R
|
|
173
|
+
}
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
/**
|
package/util/wiapack.js
CHANGED
|
@@ -15,8 +15,6 @@ import ld from 'lodash'
|
|
|
15
15
|
// const {minify, minify_sync} = require('terser')
|
|
16
16
|
import {parseSync, Compiler, minify} from '@swc/core' // acorn 替换为 swc
|
|
17
17
|
|
|
18
|
-
import cfg from './config.js'
|
|
19
|
-
|
|
20
18
|
const gzip = util.promisify(zlib.gzip)
|
|
21
19
|
|
|
22
20
|
/**
|
|
@@ -30,6 +28,7 @@ const gzip = util.promisify(zlib.gzip)
|
|
|
30
28
|
* @prop {string[]} [load] - 启动时需加载的模块,启动器需要,一般加载wia公用模块
|
|
31
29
|
* @prop {boolean} [press] - 压缩代码
|
|
32
30
|
* @prop {boolean} [gzip] - gzip打包
|
|
31
|
+
* @prop {*} [cfg] - 打包配置文件
|
|
33
32
|
*/
|
|
34
33
|
|
|
35
34
|
/**
|
|
@@ -43,6 +42,7 @@ const gzip = util.promisify(zlib.gzip)
|
|
|
43
42
|
* @prop {string} out
|
|
44
43
|
* @prop {boolean} press - 压缩代码
|
|
45
44
|
* @prop {boolean} gzip - gzip打包
|
|
45
|
+
* @prop {*} cfg - 打包配置文件
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
const def = {
|
|
@@ -50,10 +50,11 @@ const def = {
|
|
|
50
50
|
name: '',
|
|
51
51
|
ver: '1.0.0',
|
|
52
52
|
cos: 'https://cos.wia.pub', // 资源主机
|
|
53
|
-
dir:
|
|
53
|
+
dir: '',
|
|
54
54
|
out: 'dist', // 输出路径
|
|
55
55
|
press: true,
|
|
56
56
|
gzip: true,
|
|
57
|
+
cfg: {},
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
export default class WiaPack {
|
|
@@ -69,7 +70,10 @@ export default class WiaPack {
|
|
|
69
70
|
constructor(opts) {
|
|
70
71
|
/** @type {Opt} */
|
|
71
72
|
const opt = {...def, ...opts}
|
|
73
|
+
const {cfg} = opt
|
|
74
|
+
opt.dir = cfg.code.dir
|
|
72
75
|
this.opt = opt
|
|
76
|
+
this.cfg = cfg
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
/**
|
|
@@ -107,7 +111,7 @@ export default class WiaPack {
|
|
|
107
111
|
async process(uf, pf) {
|
|
108
112
|
const R = []
|
|
109
113
|
const _ = this
|
|
110
|
-
const {opt} = _
|
|
114
|
+
const {opt, cfg} = _
|
|
111
115
|
const {owner, name, ver, dir, out} = opt
|
|
112
116
|
|
|
113
117
|
console.log(`${owner}/${name} process ...`)
|
|
@@ -277,7 +281,7 @@ export default class WiaPack {
|
|
|
277
281
|
async procFile(u, rf, index, wia, page) {
|
|
278
282
|
let R = ''
|
|
279
283
|
const _ = this
|
|
280
|
-
const {opt} = _
|
|
284
|
+
const {opt, cfg} = _
|
|
281
285
|
|
|
282
286
|
try {
|
|
283
287
|
const js = {}
|
|
@@ -383,8 +387,10 @@ export default class WiaPack {
|
|
|
383
387
|
async procPgfile(u, rf, index, wia, page, load) {
|
|
384
388
|
let R = ''
|
|
385
389
|
|
|
390
|
+
const _ = this
|
|
391
|
+
|
|
386
392
|
try {
|
|
387
|
-
const {owner, name: app} =
|
|
393
|
+
const {cfg, owner, name: app} = _
|
|
388
394
|
// 页面引用模块,排除自己
|
|
389
395
|
const rg = new RegExp(cfg.code.wia.join('|'))
|
|
390
396
|
const ljs = u.pf.js
|
|
@@ -518,9 +524,7 @@ export default class WiaPack {
|
|
|
518
524
|
const buf = await gzip(wf)
|
|
519
525
|
await fs.ensureDir(path.dirname(f))
|
|
520
526
|
fs.writeFile(f, buf)
|
|
521
|
-
console.log(
|
|
522
|
-
`Build ${name} gzipped(${(wf.length / 1024).toFixed(2)}KB -> ${(buf.length / 1024).toFixed(2)}KB)`
|
|
523
|
-
)
|
|
527
|
+
console.log(`Build ${name} gzipped(${(wf.length / 1024).toFixed(2)}KB -> ${(buf.length / 1024).toFixed(2)}KB)`)
|
|
524
528
|
} catch (e) {
|
|
525
529
|
console.error(`pack exp:${e.message}`)
|
|
526
530
|
}
|
|
@@ -780,10 +784,7 @@ export default class WiaPack {
|
|
|
780
784
|
code = `${head}${body}}`
|
|
781
785
|
}
|
|
782
786
|
|
|
783
|
-
console.log(
|
|
784
|
-
{name, offset, span: v.span, start: code.slice(0, 50), tail: code.slice(-50)},
|
|
785
|
-
'getModule'
|
|
786
|
-
)
|
|
787
|
+
console.log({name, offset, span: v.span, start: code.slice(0, 50), tail: code.slice(-50)}, 'getModule')
|
|
787
788
|
|
|
788
789
|
// 路径替换,以最后一个 node_modules 路径为准
|
|
789
790
|
pos = name.lastIndexOf('/node_modules/')
|
|
@@ -792,16 +793,12 @@ export default class WiaPack {
|
|
|
792
793
|
// ../../node_modules/.pnpm/@wiajs+core@1.1.28/node_modules/@wiajs/core/dist/core.mjs
|
|
793
794
|
/** @type {string} */
|
|
794
795
|
const pre = name.slice(0, pos)
|
|
795
|
-
if (name.endsWith('.less') && pre.includes('/node_modules/less-loader/'))
|
|
796
|
-
name = `~~/${name.slice(pos + 14)}`
|
|
796
|
+
if (name.endsWith('.less') && pre.includes('/node_modules/less-loader/')) name = `~~/${name.slice(pos + 14)}`
|
|
797
797
|
else name = `~/${name.slice(pos + 14)}`
|
|
798
798
|
} else if (/^\.\/src\//.test(name)) {
|
|
799
799
|
name = name.replace(/^\.\/src\//, `${opt.owner}/${opt.name}/`)
|
|
800
800
|
} else if (/^\.\/wia\.config\.js/.test(name)) {
|
|
801
|
-
name = name.replace(
|
|
802
|
-
/^\.\/wia\.config\.js/,
|
|
803
|
-
`${opt.owner}/${opt.name}/wia.config.js`
|
|
804
|
-
)
|
|
801
|
+
name = name.replace(/^\.\/wia\.config\.js/, `${opt.owner}/${opt.name}/wia.config.js`)
|
|
805
802
|
}
|
|
806
803
|
|
|
807
804
|
// name = name.replace(/[.]{1,2}\/[./]*\/node_modules\//gi, '~/')
|