@impui/imp 1.0.16-beta.0 → 1.0.16
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/axios/index.es.js +1 -143
- package/dist/config/index.es.js +1 -127
- package/dist/core/index.es.js +1 -34
- package/dist/gotool/go2/index.es.js +1 -510
- package/dist/gotool/index/index.es.js +1 -164
- package/dist/imph5/index.es.js +1 -324
- package/dist/index.es.js +1 -49
- package/dist/login/index.es.js +1 -711
- package/dist/node_modules/axios/index/index.es.js +1 -38
- package/dist/node_modules/axios/lib/adapters/adapters/index.es.js +1 -71
- package/dist/node_modules/axios/lib/adapters/fetch/index.es.js +1 -219
- package/dist/node_modules/axios/lib/adapters/xhr/index.es.js +1 -141
- package/dist/node_modules/axios/lib/axios/index.es.js +1 -50
- package/dist/node_modules/axios/lib/cancel/CancelToken/index.es.js +1 -99
- package/dist/node_modules/axios/lib/cancel/CanceledError/index.es.js +1 -12
- package/dist/node_modules/axios/lib/cancel/isCancel/index.es.js +1 -6
- package/dist/node_modules/axios/lib/core/Axios/index.es.js +1 -180
- package/dist/node_modules/axios/lib/core/AxiosError/index.es.js +1 -80
- package/dist/node_modules/axios/lib/core/AxiosHeaders/index.es.js +1 -231
- package/dist/node_modules/axios/lib/core/InterceptorManager/index.es.js +1 -65
- package/dist/node_modules/axios/lib/core/buildFullPath/index.es.js +1 -12
- package/dist/node_modules/axios/lib/core/dispatchRequest/index.es.js +1 -52
- package/dist/node_modules/axios/lib/core/mergeConfig/index.es.js +1 -83
- package/dist/node_modules/axios/lib/core/settle/index.es.js +1 -18
- package/dist/node_modules/axios/lib/core/transformData/index.es.js +1 -17
- package/dist/node_modules/axios/lib/defaults/index/index.es.js +1 -116
- package/dist/node_modules/axios/lib/defaults/transitional/index.es.js +1 -8
- package/dist/node_modules/axios/lib/env/data/index.es.js +1 -4
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams/index.es.js +1 -34
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode/index.es.js +1 -77
- package/dist/node_modules/axios/lib/helpers/bind/index.es.js +1 -8
- package/dist/node_modules/axios/lib/helpers/buildURL/index.es.js +1 -34
- package/dist/node_modules/axios/lib/helpers/combineURLs/index.es.js +1 -6
- package/dist/node_modules/axios/lib/helpers/composeSignals/index.es.js +1 -39
- package/dist/node_modules/axios/lib/helpers/cookies/index.es.js +1 -49
- package/dist/node_modules/axios/lib/helpers/formDataToJSON/index.es.js +1 -54
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL/index.es.js +1 -6
- package/dist/node_modules/axios/lib/helpers/isAxiosError/index.es.js +1 -7
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin/index.es.js +1 -11
- package/dist/node_modules/axios/lib/helpers/null/index.es.js +1 -4
- package/dist/node_modules/axios/lib/helpers/parseHeaders/index.es.js +1 -47
- package/dist/node_modules/axios/lib/helpers/parseProtocol/index.es.js +1 -7
- package/dist/node_modules/axios/lib/helpers/progressEventReducer/index.es.js +1 -41
- package/dist/node_modules/axios/lib/helpers/resolveConfig/index.es.js +1 -46
- package/dist/node_modules/axios/lib/helpers/speedometer/index.es.js +1 -36
- package/dist/node_modules/axios/lib/helpers/spread/index.es.js +1 -8
- package/dist/node_modules/axios/lib/helpers/throttle/index.es.js +1 -35
- package/dist/node_modules/axios/lib/helpers/toFormData/index.es.js +1 -117
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm/index.es.js +1 -18
- package/dist/node_modules/axios/lib/helpers/trackStream/index.es.js +1 -80
- package/dist/node_modules/axios/lib/helpers/validator/index.es.js +1 -67
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob/index.es.js +1 -4
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData/index.es.js +1 -4
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams/index.es.js +1 -5
- package/dist/node_modules/axios/lib/platform/browser/index/index.es.js +1 -15
- package/dist/node_modules/axios/lib/platform/common/utils/index.es.js +1 -15
- package/dist/node_modules/axios/lib/platform/index/index.es.js +1 -9
- package/dist/node_modules/axios/lib/utils/index.es.js +1 -387
- package/dist/packages/com/dist/cache/index.es/index.es.js +1 -145
- package/dist/packages/com/dist/core/index.es/index.es.js +1 -154
- package/dist/packages/com/dist/data/index.es/index.es.js +1 -26
- package/dist/packages/com/dist/date/index.es/index.es.js +2 -194
- package/dist/packages/com/dist/log/index.es/index.es.js +1 -110
- package/dist/packages/com/dist/message/index.es/index.es.js +1 -90
- package/dist/packages/com/dist/req/index.es/index.es.js +1 -35
- package/dist/packages/com/dist/str/index.es/index.es.js +1 -25
- package/dist/packages/com/dist/typetool/index.es/index.es.js +1 -53
- package/dist/packages/com/dist/url/index.es/index.es.js +1 -238
- package/dist/restool/index/index.es.js +1 -266
- package/dist/restool/index.css/index.es.js +1 -4
- package/package.json +5 -1
|
@@ -1,510 +1 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
const global = globalThis;
|
|
3
|
-
const enosys = () => {
|
|
4
|
-
const err = new Error("not implemented");
|
|
5
|
-
err.code = "ENOSYS";
|
|
6
|
-
return err;
|
|
7
|
-
};
|
|
8
|
-
if (!global.fs) {
|
|
9
|
-
let outputBuf = "";
|
|
10
|
-
global.fs = {
|
|
11
|
-
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
|
12
|
-
// unused
|
|
13
|
-
writeSync(fd, buf) {
|
|
14
|
-
outputBuf += decoder.decode(buf);
|
|
15
|
-
const nl = outputBuf.lastIndexOf("\n");
|
|
16
|
-
if (nl != -1) {
|
|
17
|
-
console.log(outputBuf.substr(0, nl));
|
|
18
|
-
outputBuf = outputBuf.substr(nl + 1);
|
|
19
|
-
}
|
|
20
|
-
return buf.length;
|
|
21
|
-
},
|
|
22
|
-
write(fd, buf, offset, length, position, callback) {
|
|
23
|
-
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
24
|
-
callback(enosys());
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const n = this.writeSync(fd, buf);
|
|
28
|
-
callback(null, n);
|
|
29
|
-
},
|
|
30
|
-
chmod(path, mode, callback) {
|
|
31
|
-
callback(enosys());
|
|
32
|
-
},
|
|
33
|
-
chown(path, uid, gid, callback) {
|
|
34
|
-
callback(enosys());
|
|
35
|
-
},
|
|
36
|
-
close(fd, callback) {
|
|
37
|
-
callback(enosys());
|
|
38
|
-
},
|
|
39
|
-
fchmod(fd, mode, callback) {
|
|
40
|
-
callback(enosys());
|
|
41
|
-
},
|
|
42
|
-
fchown(fd, uid, gid, callback) {
|
|
43
|
-
callback(enosys());
|
|
44
|
-
},
|
|
45
|
-
fstat(fd, callback) {
|
|
46
|
-
callback(enosys());
|
|
47
|
-
},
|
|
48
|
-
fsync(fd, callback) {
|
|
49
|
-
callback(null);
|
|
50
|
-
},
|
|
51
|
-
ftruncate(fd, length, callback) {
|
|
52
|
-
callback(enosys());
|
|
53
|
-
},
|
|
54
|
-
lchown(path, uid, gid, callback) {
|
|
55
|
-
callback(enosys());
|
|
56
|
-
},
|
|
57
|
-
link(path, link, callback) {
|
|
58
|
-
callback(enosys());
|
|
59
|
-
},
|
|
60
|
-
lstat(path, callback) {
|
|
61
|
-
callback(enosys());
|
|
62
|
-
},
|
|
63
|
-
mkdir(path, perm, callback) {
|
|
64
|
-
callback(enosys());
|
|
65
|
-
},
|
|
66
|
-
open(path, flags, mode, callback) {
|
|
67
|
-
callback(enosys());
|
|
68
|
-
},
|
|
69
|
-
read(fd, buffer, offset, length, position, callback) {
|
|
70
|
-
callback(enosys());
|
|
71
|
-
},
|
|
72
|
-
readdir(path, callback) {
|
|
73
|
-
callback(enosys());
|
|
74
|
-
},
|
|
75
|
-
readlink(path, callback) {
|
|
76
|
-
callback(enosys());
|
|
77
|
-
},
|
|
78
|
-
rename(from, to, callback) {
|
|
79
|
-
callback(enosys());
|
|
80
|
-
},
|
|
81
|
-
rmdir(path, callback) {
|
|
82
|
-
callback(enosys());
|
|
83
|
-
},
|
|
84
|
-
stat(path, callback) {
|
|
85
|
-
callback(enosys());
|
|
86
|
-
},
|
|
87
|
-
symlink(path, link, callback) {
|
|
88
|
-
callback(enosys());
|
|
89
|
-
},
|
|
90
|
-
truncate(path, length, callback) {
|
|
91
|
-
callback(enosys());
|
|
92
|
-
},
|
|
93
|
-
unlink(path, callback) {
|
|
94
|
-
callback(enosys());
|
|
95
|
-
},
|
|
96
|
-
utimes(path, atime, mtime, callback) {
|
|
97
|
-
callback(enosys());
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (!global.process) {
|
|
102
|
-
global.process = {
|
|
103
|
-
getuid() {
|
|
104
|
-
return -1;
|
|
105
|
-
},
|
|
106
|
-
getgid() {
|
|
107
|
-
return -1;
|
|
108
|
-
},
|
|
109
|
-
geteuid() {
|
|
110
|
-
return -1;
|
|
111
|
-
},
|
|
112
|
-
getegid() {
|
|
113
|
-
return -1;
|
|
114
|
-
},
|
|
115
|
-
getgroups() {
|
|
116
|
-
throw enosys();
|
|
117
|
-
},
|
|
118
|
-
pid: -1,
|
|
119
|
-
ppid: -1,
|
|
120
|
-
umask() {
|
|
121
|
-
throw enosys();
|
|
122
|
-
},
|
|
123
|
-
cwd() {
|
|
124
|
-
throw enosys();
|
|
125
|
-
},
|
|
126
|
-
chdir() {
|
|
127
|
-
throw enosys();
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
if (!global.crypto) {
|
|
132
|
-
const nodeCrypto = require("node:crypto");
|
|
133
|
-
global.crypto = {
|
|
134
|
-
getRandomValues(b) {
|
|
135
|
-
nodeCrypto.randomFillSync(b);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (!global.performance) {
|
|
140
|
-
global.performance = {
|
|
141
|
-
now() {
|
|
142
|
-
const [sec, nsec] = process.hrtime();
|
|
143
|
-
return sec * 1e3 + nsec / 1e6;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (!global.TextEncoder) {
|
|
148
|
-
global.TextEncoder = require("node:util").TextEncoder;
|
|
149
|
-
}
|
|
150
|
-
if (!global.TextDecoder) {
|
|
151
|
-
global.TextDecoder = require("node:util").TextDecoder;
|
|
152
|
-
}
|
|
153
|
-
const encoder = new TextEncoder("utf-8");
|
|
154
|
-
const decoder = new TextDecoder("utf-8");
|
|
155
|
-
let reinterpretBuf = new DataView(new ArrayBuffer(8));
|
|
156
|
-
var logLine = [];
|
|
157
|
-
const wasmExit = {};
|
|
158
|
-
global.Go = class {
|
|
159
|
-
constructor() {
|
|
160
|
-
this._callbackTimeouts = /* @__PURE__ */ new Map();
|
|
161
|
-
this._nextCallbackTimeoutID = 1;
|
|
162
|
-
const mem = () => {
|
|
163
|
-
return new DataView(this._inst.exports.memory.buffer);
|
|
164
|
-
};
|
|
165
|
-
const unboxValue = (v_ref) => {
|
|
166
|
-
reinterpretBuf.setBigInt64(0, v_ref, true);
|
|
167
|
-
const f = reinterpretBuf.getFloat64(0, true);
|
|
168
|
-
if (f === 0) {
|
|
169
|
-
return void 0;
|
|
170
|
-
}
|
|
171
|
-
if (!isNaN(f)) {
|
|
172
|
-
return f;
|
|
173
|
-
}
|
|
174
|
-
const id = v_ref & 0xffffffffn;
|
|
175
|
-
return this._values[id];
|
|
176
|
-
};
|
|
177
|
-
const loadValue = (addr) => {
|
|
178
|
-
let v_ref = mem().getBigUint64(addr, true);
|
|
179
|
-
return unboxValue(v_ref);
|
|
180
|
-
};
|
|
181
|
-
const boxValue = (v) => {
|
|
182
|
-
const nanHead = 0x7FF80000n;
|
|
183
|
-
if (typeof v === "number") {
|
|
184
|
-
if (isNaN(v)) {
|
|
185
|
-
return nanHead << 32n;
|
|
186
|
-
}
|
|
187
|
-
if (v === 0) {
|
|
188
|
-
return nanHead << 32n | 1n;
|
|
189
|
-
}
|
|
190
|
-
reinterpretBuf.setFloat64(0, v, true);
|
|
191
|
-
return reinterpretBuf.getBigInt64(0, true);
|
|
192
|
-
}
|
|
193
|
-
switch (v) {
|
|
194
|
-
case void 0:
|
|
195
|
-
return 0n;
|
|
196
|
-
case null:
|
|
197
|
-
return nanHead << 32n | 2n;
|
|
198
|
-
case true:
|
|
199
|
-
return nanHead << 32n | 3n;
|
|
200
|
-
case false:
|
|
201
|
-
return nanHead << 32n | 4n;
|
|
202
|
-
}
|
|
203
|
-
let id = this._ids.get(v);
|
|
204
|
-
if (id === void 0) {
|
|
205
|
-
id = this._idPool.pop();
|
|
206
|
-
if (id === void 0) {
|
|
207
|
-
id = BigInt(this._values.length);
|
|
208
|
-
}
|
|
209
|
-
this._values[id] = v;
|
|
210
|
-
this._goRefCounts[id] = 0;
|
|
211
|
-
this._ids.set(v, id);
|
|
212
|
-
}
|
|
213
|
-
this._goRefCounts[id]++;
|
|
214
|
-
let typeFlag = 1n;
|
|
215
|
-
switch (typeof v) {
|
|
216
|
-
case "string":
|
|
217
|
-
typeFlag = 2n;
|
|
218
|
-
break;
|
|
219
|
-
case "symbol":
|
|
220
|
-
typeFlag = 3n;
|
|
221
|
-
break;
|
|
222
|
-
case "function":
|
|
223
|
-
typeFlag = 4n;
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
return id | (nanHead | typeFlag) << 32n;
|
|
227
|
-
};
|
|
228
|
-
const storeValue = (addr, v) => {
|
|
229
|
-
let v_ref = boxValue(v);
|
|
230
|
-
mem().setBigUint64(addr, v_ref, true);
|
|
231
|
-
};
|
|
232
|
-
const loadSlice = (array, len, cap) => {
|
|
233
|
-
return new Uint8Array(this._inst.exports.memory.buffer, array, len);
|
|
234
|
-
};
|
|
235
|
-
const loadSliceOfValues = (array, len, cap) => {
|
|
236
|
-
const a = new Array(len);
|
|
237
|
-
for (let i = 0; i < len; i++) {
|
|
238
|
-
a[i] = loadValue(array + i * 8);
|
|
239
|
-
}
|
|
240
|
-
return a;
|
|
241
|
-
};
|
|
242
|
-
const loadString = (ptr, len) => {
|
|
243
|
-
return decoder.decode(new DataView(this._inst.exports.memory.buffer, ptr, len));
|
|
244
|
-
};
|
|
245
|
-
const timeOrigin = Date.now() - performance.now();
|
|
246
|
-
this.importObject = {
|
|
247
|
-
wasi_snapshot_preview1: {
|
|
248
|
-
// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_write
|
|
249
|
-
fd_write: function(fd, iovs_ptr, iovs_len, nwritten_ptr) {
|
|
250
|
-
let nwritten = 0;
|
|
251
|
-
if (fd == 1) {
|
|
252
|
-
for (let iovs_i = 0; iovs_i < iovs_len; iovs_i++) {
|
|
253
|
-
let iov_ptr = iovs_ptr + iovs_i * 8;
|
|
254
|
-
let ptr = mem().getUint32(iov_ptr + 0, true);
|
|
255
|
-
let len = mem().getUint32(iov_ptr + 4, true);
|
|
256
|
-
nwritten += len;
|
|
257
|
-
for (let i = 0; i < len; i++) {
|
|
258
|
-
let c = mem().getUint8(ptr + i);
|
|
259
|
-
if (c == 13) ;
|
|
260
|
-
else if (c == 10) {
|
|
261
|
-
let line = decoder.decode(new Uint8Array(logLine));
|
|
262
|
-
logLine = [];
|
|
263
|
-
console.log(line);
|
|
264
|
-
} else {
|
|
265
|
-
logLine.push(c);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
console.error("invalid file descriptor:", fd);
|
|
271
|
-
}
|
|
272
|
-
mem().setUint32(nwritten_ptr, nwritten, true);
|
|
273
|
-
return 0;
|
|
274
|
-
},
|
|
275
|
-
fd_close: () => 0,
|
|
276
|
-
// dummy
|
|
277
|
-
fd_fdstat_get: () => 0,
|
|
278
|
-
// dummy
|
|
279
|
-
fd_seek: () => 0,
|
|
280
|
-
// dummy
|
|
281
|
-
proc_exit: (code) => {
|
|
282
|
-
this.exited = true;
|
|
283
|
-
this.exitCode = code;
|
|
284
|
-
this._resolveExitPromise();
|
|
285
|
-
throw wasmExit;
|
|
286
|
-
},
|
|
287
|
-
random_get: (bufPtr, bufLen) => {
|
|
288
|
-
crypto.getRandomValues(loadSlice(bufPtr, bufLen));
|
|
289
|
-
return 0;
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
gojs: {
|
|
293
|
-
// func ticks() int64
|
|
294
|
-
"runtime.ticks": () => {
|
|
295
|
-
return BigInt((timeOrigin + performance.now()) * 1e6);
|
|
296
|
-
},
|
|
297
|
-
// func sleepTicks(timeout int64)
|
|
298
|
-
"runtime.sleepTicks": (timeout) => {
|
|
299
|
-
setTimeout(() => {
|
|
300
|
-
if (this.exited) return;
|
|
301
|
-
try {
|
|
302
|
-
this._inst.exports.go_scheduler();
|
|
303
|
-
} catch (e) {
|
|
304
|
-
if (e !== wasmExit) throw e;
|
|
305
|
-
}
|
|
306
|
-
}, Number(timeout) / 1e6);
|
|
307
|
-
},
|
|
308
|
-
// func finalizeRef(v ref)
|
|
309
|
-
"syscall/js.finalizeRef": (v_ref) => {
|
|
310
|
-
const id = v_ref & 0xffffffffn;
|
|
311
|
-
if (this._goRefCounts?.[id] !== void 0) {
|
|
312
|
-
this._goRefCounts[id]--;
|
|
313
|
-
if (this._goRefCounts[id] === 0) {
|
|
314
|
-
const v = this._values[id];
|
|
315
|
-
this._values[id] = null;
|
|
316
|
-
this._ids.delete(v);
|
|
317
|
-
this._idPool.push(id);
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
console.error("syscall/js.finalizeRef: unknown id", id);
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
// func stringVal(value string) ref
|
|
324
|
-
"syscall/js.stringVal": (value_ptr, value_len) => {
|
|
325
|
-
value_ptr >>>= 0;
|
|
326
|
-
const s = loadString(value_ptr, value_len);
|
|
327
|
-
return boxValue(s);
|
|
328
|
-
},
|
|
329
|
-
// func valueGet(v ref, p string) ref
|
|
330
|
-
"syscall/js.valueGet": (v_ref, p_ptr, p_len) => {
|
|
331
|
-
let prop = loadString(p_ptr, p_len);
|
|
332
|
-
let v = unboxValue(v_ref);
|
|
333
|
-
let result = Reflect.get(v, prop);
|
|
334
|
-
return boxValue(result);
|
|
335
|
-
},
|
|
336
|
-
// func valueSet(v ref, p string, x ref)
|
|
337
|
-
"syscall/js.valueSet": (v_ref, p_ptr, p_len, x_ref) => {
|
|
338
|
-
const v = unboxValue(v_ref);
|
|
339
|
-
const p = loadString(p_ptr, p_len);
|
|
340
|
-
const x = unboxValue(x_ref);
|
|
341
|
-
Reflect.set(v, p, x);
|
|
342
|
-
},
|
|
343
|
-
// func valueDelete(v ref, p string)
|
|
344
|
-
"syscall/js.valueDelete": (v_ref, p_ptr, p_len) => {
|
|
345
|
-
const v = unboxValue(v_ref);
|
|
346
|
-
const p = loadString(p_ptr, p_len);
|
|
347
|
-
Reflect.deleteProperty(v, p);
|
|
348
|
-
},
|
|
349
|
-
// func valueIndex(v ref, i int) ref
|
|
350
|
-
"syscall/js.valueIndex": (v_ref, i) => {
|
|
351
|
-
return boxValue(Reflect.get(unboxValue(v_ref), i));
|
|
352
|
-
},
|
|
353
|
-
// valueSetIndex(v ref, i int, x ref)
|
|
354
|
-
"syscall/js.valueSetIndex": (v_ref, i, x_ref) => {
|
|
355
|
-
Reflect.set(unboxValue(v_ref), i, unboxValue(x_ref));
|
|
356
|
-
},
|
|
357
|
-
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
358
|
-
"syscall/js.valueCall": (ret_addr, v_ref, m_ptr, m_len, args_ptr, args_len, args_cap) => {
|
|
359
|
-
const v = unboxValue(v_ref);
|
|
360
|
-
const name = loadString(m_ptr, m_len);
|
|
361
|
-
const args = loadSliceOfValues(args_ptr, args_len);
|
|
362
|
-
try {
|
|
363
|
-
const m = Reflect.get(v, name);
|
|
364
|
-
storeValue(ret_addr, Reflect.apply(m, v, args));
|
|
365
|
-
mem().setUint8(ret_addr + 8, 1);
|
|
366
|
-
} catch (err) {
|
|
367
|
-
storeValue(ret_addr, err);
|
|
368
|
-
mem().setUint8(ret_addr + 8, 0);
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
372
|
-
"syscall/js.valueInvoke": (ret_addr, v_ref, args_ptr, args_len, args_cap) => {
|
|
373
|
-
try {
|
|
374
|
-
const v = unboxValue(v_ref);
|
|
375
|
-
const args = loadSliceOfValues(args_ptr, args_len, args_cap);
|
|
376
|
-
storeValue(ret_addr, Reflect.apply(v, void 0, args));
|
|
377
|
-
mem().setUint8(ret_addr + 8, 1);
|
|
378
|
-
} catch (err) {
|
|
379
|
-
storeValue(ret_addr, err);
|
|
380
|
-
mem().setUint8(ret_addr + 8, 0);
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
// func valueNew(v ref, args []ref) (ref, bool)
|
|
384
|
-
"syscall/js.valueNew": (ret_addr, v_ref, args_ptr, args_len, args_cap) => {
|
|
385
|
-
const v = unboxValue(v_ref);
|
|
386
|
-
const args = loadSliceOfValues(args_ptr, args_len);
|
|
387
|
-
try {
|
|
388
|
-
storeValue(ret_addr, Reflect.construct(v, args));
|
|
389
|
-
mem().setUint8(ret_addr + 8, 1);
|
|
390
|
-
} catch (err) {
|
|
391
|
-
storeValue(ret_addr, err);
|
|
392
|
-
mem().setUint8(ret_addr + 8, 0);
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
// func valueLength(v ref) int
|
|
396
|
-
"syscall/js.valueLength": (v_ref) => {
|
|
397
|
-
return unboxValue(v_ref).length;
|
|
398
|
-
},
|
|
399
|
-
// valuePrepareString(v ref) (ref, int)
|
|
400
|
-
"syscall/js.valuePrepareString": (ret_addr, v_ref) => {
|
|
401
|
-
const s = String(unboxValue(v_ref));
|
|
402
|
-
const str = encoder.encode(s);
|
|
403
|
-
storeValue(ret_addr, str);
|
|
404
|
-
mem().setInt32(ret_addr + 8, str.length, true);
|
|
405
|
-
},
|
|
406
|
-
// valueLoadString(v ref, b []byte)
|
|
407
|
-
"syscall/js.valueLoadString": (v_ref, slice_ptr, slice_len, slice_cap) => {
|
|
408
|
-
const str = unboxValue(v_ref);
|
|
409
|
-
loadSlice(slice_ptr, slice_len).set(str);
|
|
410
|
-
},
|
|
411
|
-
// func valueInstanceOf(v ref, t ref) bool
|
|
412
|
-
"syscall/js.valueInstanceOf": (v_ref, t_ref) => {
|
|
413
|
-
return unboxValue(v_ref) instanceof unboxValue(t_ref);
|
|
414
|
-
},
|
|
415
|
-
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
416
|
-
"syscall/js.copyBytesToGo": (ret_addr, dest_addr, dest_len, dest_cap, src_ref) => {
|
|
417
|
-
let num_bytes_copied_addr = ret_addr;
|
|
418
|
-
let returned_status_addr = ret_addr + 4;
|
|
419
|
-
const dst = loadSlice(dest_addr, dest_len);
|
|
420
|
-
const src = unboxValue(src_ref);
|
|
421
|
-
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
422
|
-
mem().setUint8(returned_status_addr, 0);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const toCopy = src.subarray(0, dst.length);
|
|
426
|
-
dst.set(toCopy);
|
|
427
|
-
mem().setUint32(num_bytes_copied_addr, toCopy.length, true);
|
|
428
|
-
mem().setUint8(returned_status_addr, 1);
|
|
429
|
-
},
|
|
430
|
-
// copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
431
|
-
// Originally copied from upstream Go project, then modified:
|
|
432
|
-
// https://github.com/golang/go/blob/3f995c3f3b43033013013e6c7ccc93a9b1411ca9/misc/wasm/wasm_exec.js#L404-L416
|
|
433
|
-
"syscall/js.copyBytesToJS": (ret_addr, dst_ref, src_addr, src_len, src_cap) => {
|
|
434
|
-
let num_bytes_copied_addr = ret_addr;
|
|
435
|
-
let returned_status_addr = ret_addr + 4;
|
|
436
|
-
const dst = unboxValue(dst_ref);
|
|
437
|
-
const src = loadSlice(src_addr, src_len);
|
|
438
|
-
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
439
|
-
mem().setUint8(returned_status_addr, 0);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
const toCopy = src.subarray(0, dst.length);
|
|
443
|
-
dst.set(toCopy);
|
|
444
|
-
mem().setUint32(num_bytes_copied_addr, toCopy.length, true);
|
|
445
|
-
mem().setUint8(returned_status_addr, 1);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
this.importObject.env = this.importObject.gojs;
|
|
450
|
-
}
|
|
451
|
-
async run(instance) {
|
|
452
|
-
this._inst = instance;
|
|
453
|
-
this._values = [
|
|
454
|
-
// JS values that Go currently has references to, indexed by reference id
|
|
455
|
-
NaN,
|
|
456
|
-
0,
|
|
457
|
-
null,
|
|
458
|
-
true,
|
|
459
|
-
false,
|
|
460
|
-
global,
|
|
461
|
-
this
|
|
462
|
-
];
|
|
463
|
-
this._goRefCounts = [];
|
|
464
|
-
this._ids = /* @__PURE__ */ new Map();
|
|
465
|
-
this._idPool = [];
|
|
466
|
-
this.exited = false;
|
|
467
|
-
this.exitCode = 0;
|
|
468
|
-
if (this._inst.exports._start) {
|
|
469
|
-
let exitPromise = new Promise((resolve, reject) => {
|
|
470
|
-
this._resolveExitPromise = resolve;
|
|
471
|
-
});
|
|
472
|
-
try {
|
|
473
|
-
this._inst.exports._start();
|
|
474
|
-
} catch (e) {
|
|
475
|
-
if (e !== wasmExit) throw e;
|
|
476
|
-
}
|
|
477
|
-
await exitPromise;
|
|
478
|
-
return this.exitCode;
|
|
479
|
-
} else {
|
|
480
|
-
this._inst.exports._initialize();
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
_resume() {
|
|
484
|
-
if (this.exited) {
|
|
485
|
-
throw new Error("Go program has already exited");
|
|
486
|
-
}
|
|
487
|
-
try {
|
|
488
|
-
this._inst.exports.resume();
|
|
489
|
-
} catch (e) {
|
|
490
|
-
if (e !== wasmExit) throw e;
|
|
491
|
-
}
|
|
492
|
-
if (this.exited) {
|
|
493
|
-
this._resolveExitPromise();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
_makeFuncWrapper(id) {
|
|
497
|
-
const go = this;
|
|
498
|
-
return function() {
|
|
499
|
-
const event = { id, this: this, args: arguments };
|
|
500
|
-
go._pendingEvent = event;
|
|
501
|
-
go._resume();
|
|
502
|
-
return event.result;
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
})();
|
|
507
|
-
const Go$1 = Go;
|
|
508
|
-
export {
|
|
509
|
-
Go$1 as default
|
|
510
|
-
};
|
|
1
|
+
(()=>{const t=globalThis,e=()=>{const t=new Error("not implemented");return t.code="ENOSYS",t};if(!t.fs){let s="";t.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(t,e){s+=n.decode(e);const i=s.lastIndexOf("\n");return-1!=i&&(console.log(s.substr(0,i)),s=s.substr(i+1)),e.length},write(t,s,n,i,r,o){if(0!==n||i!==s.length||null!==r)return void o(e());o(null,this.writeSync(t,s))},chmod(t,s,n){n(e())},chown(t,s,n,i){i(e())},close(t,s){s(e())},fchmod(t,s,n){n(e())},fchown(t,s,n,i){i(e())},fstat(t,s){s(e())},fsync(t,e){e(null)},ftruncate(t,s,n){n(e())},lchown(t,s,n,i){i(e())},link(t,s,n){n(e())},lstat(t,s){s(e())},mkdir(t,s,n){n(e())},open(t,s,n,i){i(e())},read(t,s,n,i,r,o){o(e())},readdir(t,s){s(e())},readlink(t,s){s(e())},rename(t,s,n){n(e())},rmdir(t,s){s(e())},stat(t,s){s(e())},symlink(t,s,n){n(e())},truncate(t,s,n){n(e())},unlink(t,s){s(e())},utimes(t,s,n,i){i(e())}}}if(t.process||(t.process={getuid:()=>-1,getgid:()=>-1,geteuid:()=>-1,getegid:()=>-1,getgroups(){throw e()},pid:-1,ppid:-1,umask(){throw e()},cwd(){throw e()},chdir(){throw e()}}),!t.crypto){const e=require("node:crypto");t.crypto={getRandomValues(t){e.randomFillSync(t)}}}t.performance||(t.performance={now(){const[t,e]=process.hrtime();return 1e3*t+e/1e6}}),t.TextEncoder||(t.TextEncoder=require("node:util").TextEncoder),t.TextDecoder||(t.TextDecoder=require("node:util").TextDecoder);const s=new TextEncoder("utf-8"),n=new TextDecoder("utf-8");let i=new DataView(new ArrayBuffer(8));var r=[];const o={};t.Go=class{constructor(){this._callbackTimeouts=/* @__PURE__ */new Map,this._nextCallbackTimeoutID=1;const t=()=>new DataView(this._inst.exports.memory.buffer),e=t=>{i.setBigInt64(0,t,!0);const e=i.getFloat64(0,!0);if(0===e)return;if(!isNaN(e))return e;const s=0xffffffffn&t;return this._values[s]},l=s=>{let n=t().getBigUint64(s,!0);return e(n)},c=t=>{const e=0x7FF80000n;if("number"==typeof t)return isNaN(t)?e<<32n:0===t?e<<32n|1n:(i.setFloat64(0,t,!0),i.getBigInt64(0,!0));switch(t){case void 0:return 0n;case null:return e<<32n|2n;case!0:return e<<32n|3n;case!1:return e<<32n|4n}let s=this._ids.get(t);void 0===s&&(s=this._idPool.pop(),void 0===s&&(s=BigInt(this._values.length)),this._values[s]=t,this._goRefCounts[s]=0,this._ids.set(t,s)),this._goRefCounts[s]++;let n=1n;switch(typeof t){case"string":n=2n;break;case"symbol":n=3n;break;case"function":n=4n}return s|(e|n)<<32n},a=(e,s)=>{let n=c(s);t().setBigUint64(e,n,!0)},u=(t,e,s)=>new Uint8Array(this._inst.exports.memory.buffer,t,e),f=(t,e,s)=>{const n=new Array(e);for(let i=0;i<e;i++)n[i]=l(t+8*i);return n},h=(t,e)=>n.decode(new DataView(this._inst.exports.memory.buffer,t,e)),d=Date.now()-performance.now();this.importObject={wasi_snapshot_preview1:{fd_write:function(e,s,i,o){let l=0;if(1==e)for(let c=0;c<i;c++){let e=s+8*c,i=t().getUint32(e+0,!0),o=t().getUint32(e+4,!0);l+=o;for(let s=0;s<o;s++){let e=t().getUint8(i+s);if(13==e);else if(10==e){let t=n.decode(new Uint8Array(r));r=[],console.log(t)}else r.push(e)}}else console.error("invalid file descriptor:",e);return t().setUint32(o,l,!0),0},fd_close:()=>0,fd_fdstat_get:()=>0,fd_seek:()=>0,proc_exit:t=>{throw this.exited=!0,this.exitCode=t,this._resolveExitPromise(),o},random_get:(t,e)=>(crypto.getRandomValues(u(t,e)),0)},gojs:{"runtime.ticks":()=>BigInt(1e6*(d+performance.now())),"runtime.sleepTicks":t=>{setTimeout(()=>{if(!this.exited)try{this._inst.exports.go_scheduler()}catch(t){if(t!==o)throw t}},Number(t)/1e6)},"syscall/js.finalizeRef":t=>{const e=0xffffffffn&t;if(void 0!==this._goRefCounts?.[e]){if(this._goRefCounts[e]--,0===this._goRefCounts[e]){const t=this._values[e];this._values[e]=null,this._ids.delete(t),this._idPool.push(e)}}else console.error("syscall/js.finalizeRef: unknown id",e)},"syscall/js.stringVal":(t,e)=>{const s=h(t>>>=0,e);return c(s)},"syscall/js.valueGet":(t,s,n)=>{let i=h(s,n),r=e(t),o=Reflect.get(r,i);return c(o)},"syscall/js.valueSet":(t,s,n,i)=>{const r=e(t),o=h(s,n),l=e(i);Reflect.set(r,o,l)},"syscall/js.valueDelete":(t,s,n)=>{const i=e(t),r=h(s,n);Reflect.deleteProperty(i,r)},"syscall/js.valueIndex":(t,s)=>c(Reflect.get(e(t),s)),"syscall/js.valueSetIndex":(t,s,n)=>{Reflect.set(e(t),s,e(n))},"syscall/js.valueCall":(s,n,i,r,o,l,c)=>{const u=e(n),d=h(i,r),g=f(o,l);try{const e=Reflect.get(u,d);a(s,Reflect.apply(e,u,g)),t().setUint8(s+8,1)}catch(y){a(s,y),t().setUint8(s+8,0)}},"syscall/js.valueInvoke":(s,n,i,r,o)=>{try{const o=e(n),l=f(i,r);a(s,Reflect.apply(o,void 0,l)),t().setUint8(s+8,1)}catch(l){a(s,l),t().setUint8(s+8,0)}},"syscall/js.valueNew":(s,n,i,r,o)=>{const l=e(n),c=f(i,r);try{a(s,Reflect.construct(l,c)),t().setUint8(s+8,1)}catch(u){a(s,u),t().setUint8(s+8,0)}},"syscall/js.valueLength":t=>e(t).length,"syscall/js.valuePrepareString":(n,i)=>{const r=String(e(i)),o=s.encode(r);a(n,o),t().setInt32(n+8,o.length,!0)},"syscall/js.valueLoadString":(t,s,n,i)=>{const r=e(t);u(s,n).set(r)},"syscall/js.valueInstanceOf":(t,s)=>e(t)instanceof e(s),"syscall/js.copyBytesToGo":(s,n,i,r,o)=>{let l=s,c=s+4;const a=u(n,i),f=e(o);if(!(f instanceof Uint8Array||f instanceof Uint8ClampedArray))return void t().setUint8(c,0);const h=f.subarray(0,a.length);a.set(h),t().setUint32(l,h.length,!0),t().setUint8(c,1)},"syscall/js.copyBytesToJS":(s,n,i,r,o)=>{let l=s,c=s+4;const a=e(n),f=u(i,r);if(!(a instanceof Uint8Array||a instanceof Uint8ClampedArray))return void t().setUint8(c,0);const h=f.subarray(0,a.length);a.set(h),t().setUint32(l,h.length,!0),t().setUint8(c,1)}}},this.importObject.env=this.importObject.gojs}async run(e){if(this._inst=e,this._values=[NaN,0,null,!0,!1,t,this],this._goRefCounts=[],this._ids=/* @__PURE__ */new Map,this._idPool=[],this.exited=!1,this.exitCode=0,this._inst.exports._start){let t=new Promise((t,e)=>{this._resolveExitPromise=t});try{this._inst.exports._start()}catch(s){if(s!==o)throw s}return await t,this.exitCode}this._inst.exports._initialize()}_resume(){if(this.exited)throw new Error("Go program has already exited");try{this._inst.exports.resume()}catch(t){if(t!==o)throw t}this.exited&&this._resolveExitPromise()}_makeFuncWrapper(t){const e=this;return function(){const s={id:t,this:this,args:arguments};return e._pendingEvent=s,e._resume(),s.result}}}})();const t=Go;export{t as default};
|
|
@@ -1,164 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getConfig, getCodeVer, getApiurl } from "../../config/index.es.js";
|
|
3
|
-
import "../../packages/com/dist/core/index.es/index.es.js";
|
|
4
|
-
import { getLog } from "../../packages/com/dist/log/index.es/index.es.js";
|
|
5
|
-
import "../../packages/com/dist/browser/index.es/index.es.js";
|
|
6
|
-
import { bufferToBase64, base64ToBuffer } from "../../packages/com/dist/data/index.es/index.es.js";
|
|
7
|
-
import "../../packages/com/dist/str/index.es/index.es.js";
|
|
8
|
-
import { getAndWaitCache } from "../../packages/com/dist/req/index.es/index.es.js";
|
|
9
|
-
import "../../packages/com/dist/message/index.es/index.es.js";
|
|
10
|
-
const goModelCache = {};
|
|
11
|
-
const config = await getConfig();
|
|
12
|
-
const baseWasm = config.allsr + "/plug/gotool/lib/imptool.wasm";
|
|
13
|
-
const debug2 = await getLog();
|
|
14
|
-
const loadGoWasm = async function(wasmUrl, vertxt, isbase = false) {
|
|
15
|
-
try {
|
|
16
|
-
const go = new Go();
|
|
17
|
-
debug2("=== WASM加载调试开始 ===");
|
|
18
|
-
debug2("URL:", wasmUrl);
|
|
19
|
-
debug2("UserAgent:", navigator.userAgent);
|
|
20
|
-
const base64 = await getAndWaitCache(wasmUrl, async () => {
|
|
21
|
-
const response = await fetch(wasmUrl + vertxt);
|
|
22
|
-
debug2("✅ 响应状态:", response.status);
|
|
23
|
-
const buffer2 = await response.arrayBuffer();
|
|
24
|
-
debug2("✅ ArrayBuffer大小:", buffer2.byteLength, "bytes");
|
|
25
|
-
return bufferToBase64(buffer2, { type: "application/wasm" });
|
|
26
|
-
});
|
|
27
|
-
const buffer = await base64ToBuffer(base64);
|
|
28
|
-
const header = new Uint8Array(buffer.slice(0, 4));
|
|
29
|
-
debug2("🔍 WASM文件头:", Array.from(header));
|
|
30
|
-
debug2("🔍 Go importObject结构:", Object.keys(go.importObject));
|
|
31
|
-
if (go.importObject.go) {
|
|
32
|
-
debug2("🔍 GoJS导入键:", Object.keys(go.importObject.go));
|
|
33
|
-
}
|
|
34
|
-
debug2("🚀 开始WebAssembly.instantiate...");
|
|
35
|
-
const result = await WebAssembly.instantiate(buffer, go.importObject);
|
|
36
|
-
debug2("✅ WebAssembly实例化成功");
|
|
37
|
-
debug2("🚀 开始go.run...");
|
|
38
|
-
go.run(result.instance);
|
|
39
|
-
debug2("✅ go.run执行完成");
|
|
40
|
-
if (window.goCrypto) {
|
|
41
|
-
const goCrypto = window.goCrypto;
|
|
42
|
-
delete window.goCrypto;
|
|
43
|
-
debug2("✅ goCrypto加载成功");
|
|
44
|
-
return goCrypto;
|
|
45
|
-
} else if (isbase) {
|
|
46
|
-
return await CreateGoCrypto();
|
|
47
|
-
} else {
|
|
48
|
-
console.warn("❌ window.goCrypto未定义,进入诊断模式");
|
|
49
|
-
await loadGoWasmWithDiagnosis(wasmUrl);
|
|
50
|
-
throw new Error("❌ window.goCrypto未定义");
|
|
51
|
-
}
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("💥 完整错误堆栈:", error);
|
|
54
|
-
console.error("错误名称:", error.name);
|
|
55
|
-
console.error("错误信息:", error.message);
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const CreateGoCrypto = async function() {
|
|
60
|
-
console.warn("⚠️ 降级方案已启用");
|
|
61
|
-
return {
|
|
62
|
-
encrypt: function() {
|
|
63
|
-
throw new Error("❌ 降级方案未实现:encrypt方法");
|
|
64
|
-
},
|
|
65
|
-
/**
|
|
66
|
-
* 解密降级方案(为兼容部分不支持wasm的机型,使用接口请求解密的方案)
|
|
67
|
-
* @param {any} _req
|
|
68
|
-
* @param {any} config
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
parseRes: async function(_res, config2) {
|
|
72
|
-
try {
|
|
73
|
-
if (_res.headers["res-encrypt"] !== "true") {
|
|
74
|
-
return _res;
|
|
75
|
-
}
|
|
76
|
-
const req = {
|
|
77
|
-
data: _res.data
|
|
78
|
-
};
|
|
79
|
-
const apiurl = await getApiurl();
|
|
80
|
-
const res = await axios.post(apiurl.parseRes, { res: encodeURIComponent(JSON.stringify(req)), config: null });
|
|
81
|
-
_res.data = JSON.parse(res.data);
|
|
82
|
-
return _res;
|
|
83
|
-
} catch (e) {
|
|
84
|
-
console.error("❌ 降级方案请求接口失败:", e);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
/**
|
|
88
|
-
* 降级方案
|
|
89
|
-
*/
|
|
90
|
-
parseServer: function() {
|
|
91
|
-
throw new Error("❌ 降级方案未实现:parseServer方法");
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
class GoTool {
|
|
96
|
-
constructor(wasmUrl) {
|
|
97
|
-
this.isbase = wasmUrl === baseWasm;
|
|
98
|
-
this.url = wasmUrl;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* 获取wasm路径
|
|
102
|
-
* @returns
|
|
103
|
-
*/
|
|
104
|
-
async #getWasmUrl() {
|
|
105
|
-
if (!this.url) {
|
|
106
|
-
const config2 = await getConfig();
|
|
107
|
-
this.url = config2.allsr + "plug/gotool/lib/imptool.wasm";
|
|
108
|
-
}
|
|
109
|
-
return this.url;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* 加载一个go wasm
|
|
113
|
-
* @param {any} wasmUrl wasm路径
|
|
114
|
-
* @param {any} vertxt 后缀,如:?d=202512021513
|
|
115
|
-
* @returns
|
|
116
|
-
*/
|
|
117
|
-
async #loadGoWasm(wasmUrl, vertxt) {
|
|
118
|
-
wasmUrl = wasmUrl || await this.#getWasmUrl();
|
|
119
|
-
return loadGoWasm(wasmUrl, vertxt, this.isbase);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 创建一个go模型对象(返回的go wasm的工具库)
|
|
123
|
-
* @param {any} wasmUrl
|
|
124
|
-
* @param {any} isRefresh
|
|
125
|
-
* @returns
|
|
126
|
-
*/
|
|
127
|
-
async getRunTimes(isRefresh = false) {
|
|
128
|
-
const wasmUrl = await this.#getWasmUrl();
|
|
129
|
-
if (!isRefresh && goModelCache[wasmUrl]) {
|
|
130
|
-
return goModelCache[wasmUrl];
|
|
131
|
-
}
|
|
132
|
-
const ver = getCodeVer();
|
|
133
|
-
const vertxt = ver.config ? "?d=" + ver.config : "";
|
|
134
|
-
const goCrypto = await this.#loadGoWasm(wasmUrl, vertxt);
|
|
135
|
-
const tool = {};
|
|
136
|
-
if (goCrypto) {
|
|
137
|
-
for (let key in goCrypto) {
|
|
138
|
-
tool[key] = goCrypto[key];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
goModelCache[wasmUrl] = tool;
|
|
142
|
-
return tool;
|
|
143
|
-
}
|
|
144
|
-
async init() {
|
|
145
|
-
return this.getRunTimes();
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* 运行默认的wasm中的方法
|
|
149
|
-
* @param {any} FnName 方法名
|
|
150
|
-
* @param {Array} args 需要传递的参数
|
|
151
|
-
* @returns
|
|
152
|
-
*/
|
|
153
|
-
async run(FnName, args) {
|
|
154
|
-
const tool = await this.getRunTimes();
|
|
155
|
-
if (!tool[FnName]) {
|
|
156
|
-
console.error(`[${FnName}] 方法不在默认wasm中!`);
|
|
157
|
-
}
|
|
158
|
-
return tool[FnName].apply(null, args);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const gotool = new GoTool(baseWasm);
|
|
162
|
-
export {
|
|
163
|
-
gotool
|
|
164
|
-
};
|
|
1
|
+
import e from"../go2/index.es.js";import{getConfig as t,getCodeVer as s,getApiurl as r}from"../../config/index.es.js";import"../../packages/com/dist/core/index.es/index.es.js";import{getLog as o}from"../../packages/com/dist/log/index.es/index.es.js";import"../../packages/com/dist/browser/index.es/index.es.js";import{bufferToBase64 as a,base64ToBuffer as n}from"../../packages/com/dist/data/index.es/index.es.js";import"../../packages/com/dist/str/index.es/index.es.js";import{getAndWaitCache as i}from"../../packages/com/dist/req/index.es/index.es.js";import"../../packages/com/dist/message/index.es/index.es.js";const c={},m=(await t()).allsr+"/plug/gotool/lib/imptool.wasm",p=await o(),g=async function(){return console.warn("⚠️ 降级方案已启用"),{encrypt:function(){throw new Error("❌ 降级方案未实现:encrypt方法")},parseRes:async function(e,t){try{if("true"!==e.headers["res-encrypt"])return e;const t={data:e.data},s=await r(),o=await axios.post(s.parseRes,{res:encodeURIComponent(JSON.stringify(t)),config:null});return e.data=JSON.parse(o.data),e}catch(s){console.error("❌ 降级方案请求接口失败:",s)}},parseServer:function(){throw new Error("❌ 降级方案未实现:parseServer方法")}}};const l=new class{constructor(e){this.isbase=e===m,this.url=e}async#e(){if(!this.url){const e=await t();this.url=e.allsr+"plug/gotool/lib/imptool.wasm"}return this.url}async#t(t,s){return async function(t,s,r=!1){try{const o=new e;p("=== WASM加载调试开始 ==="),p("URL:",t),p("UserAgent:",navigator.userAgent);const c=await i(t,async()=>{const e=await fetch(t+s);p("✅ 响应状态:",e.status);const r=await e.arrayBuffer();return p("✅ ArrayBuffer大小:",r.byteLength,"bytes"),a(r,{type:"application/wasm"})}),m=await n(c),l=new Uint8Array(m.slice(0,4));p("🔍 WASM文件头:",Array.from(l)),p("🔍 Go importObject结构:",Object.keys(o.importObject)),o.importObject.go&&p("🔍 GoJS导入键:",Object.keys(o.importObject.go)),p("🚀 开始WebAssembly.instantiate...");const w=await WebAssembly.instantiate(m,o.importObject);if(p("✅ WebAssembly实例化成功"),p("🚀 开始go.run..."),o.run(w.instance),p("✅ go.run执行完成"),window.goCrypto){const e=window.goCrypto;return delete window.goCrypto,p("✅ goCrypto加载成功"),e}if(r)return await g();throw console.warn("❌ window.goCrypto未定义,进入诊断模式"),await loadGoWasmWithDiagnosis(t),new Error("❌ window.goCrypto未定义")}catch(o){throw console.error("💥 完整错误堆栈:",o),console.error("错误名称:",o.name),console.error("错误信息:",o.message),o}}(t=t||await this.#e(),s,this.isbase)}async getRunTimes(e=!1){const t=await this.#e();if(!e&&c[t])return c[t];const r=s(),o=r.config?"?d="+r.config:"",a=await this.#t(t,o),n={};if(a)for(let s in a)n[s]=a[s];return c[t]=n,n}async init(){return this.getRunTimes()}async run(e,t){const s=await this.getRunTimes();return s[e]||console.error(`[${e}] 方法不在默认wasm中!`),s[e].apply(null,t)}}(m);export{l as gotool};
|