@open-wxa/wxa-runner-core 0.2.5 → 0.3.0
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/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/runtime/host.js +69 -19
- package/dist/runtime/host.js.map +1 -1
- package/dist/{setup-COzZ6vzS.d.mts → setup-Cv340Lvj.d.mts} +7 -3
- package/dist/{setup-COzZ6vzS.d.ts → setup-Cv340Lvj.d.ts} +7 -3
- package/dist/setup.d.mts +1 -1
- package/dist/setup.d.ts +1 -1
- package/dist/setup.js.map +1 -1
- package/dist/setup.mjs.map +1 -1
- package/dist/test-api.d.mts +2 -2
- package/dist/test-api.d.ts +2 -2
- package/dist/{testApi-CbBoHXdN.d.mts → testApi-DO2FyR78.d.mts} +1 -1
- package/dist/{testApi-DRZ-hXpC.d.ts → testApi-nKsjjEhz.d.ts} +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResolvedBaseLib } from '@open-wxa/wxa-runner-extractor';
|
|
2
|
-
import { D as DeviceProfile } from './setup-
|
|
3
|
-
export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-
|
|
4
|
-
export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-
|
|
2
|
+
import { D as DeviceProfile } from './setup-Cv340Lvj.mjs';
|
|
3
|
+
export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-Cv340Lvj.mjs';
|
|
4
|
+
export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-DO2FyR78.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 小程序项目结构解析
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResolvedBaseLib } from '@open-wxa/wxa-runner-extractor';
|
|
2
|
-
import { D as DeviceProfile } from './setup-
|
|
3
|
-
export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-
|
|
4
|
-
export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-
|
|
2
|
+
import { D as DeviceProfile } from './setup-Cv340Lvj.js';
|
|
3
|
+
export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-Cv340Lvj.js';
|
|
4
|
+
export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-nKsjjEhz.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 小程序项目结构解析
|
package/dist/runtime/host.js
CHANGED
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
return { ...extra, errMsg: `${api}:fail ${reason2}` };
|
|
77
77
|
}
|
|
78
78
|
function normalize(api, result) {
|
|
79
|
+
if (typeof result === "string") return result;
|
|
79
80
|
if (!result) return { errMsg: `${api}:ok` };
|
|
80
81
|
return result.errMsg ? result : { ...result, errMsg: `${api}:ok` };
|
|
81
82
|
}
|
|
@@ -238,6 +239,44 @@
|
|
|
238
239
|
return { loadLibFiles, loadLibFilesSync: loadLibFiles };
|
|
239
240
|
}
|
|
240
241
|
|
|
242
|
+
// src/runtime/host/api/map.ts
|
|
243
|
+
function createMapApis({ registry, operations }) {
|
|
244
|
+
return {
|
|
245
|
+
private_geolocation: async (_args, context) => {
|
|
246
|
+
const location2 = await registry.invoke("getLocation", { type: "gcj02" }, { ...context, api: "getLocation" });
|
|
247
|
+
if (location2.errMsg !== "getLocation:ok") return JSON.stringify({ message: location2.errMsg });
|
|
248
|
+
return JSON.stringify({ result: { location: { lat: location2.latitude, lng: location2.longitude } } });
|
|
249
|
+
},
|
|
250
|
+
// 开发者工具上没有原生地图,照基础库的格式转给当前页的 map 组件
|
|
251
|
+
moveToMapLocation: (args, { webviewId }) => operations.send(webviewId, { ...args, method: "moveToMapLocation" })
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
var MapOperations = class {
|
|
255
|
+
/** @param publish 发给渲染层,渲染层的 WeixinJSBridge.subscribe 收到 */
|
|
256
|
+
constructor(publish) {
|
|
257
|
+
this.publish = publish;
|
|
258
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
259
|
+
this.seq = 0;
|
|
260
|
+
}
|
|
261
|
+
/** map 组件做完才返回;页面上没有这个 map 时一直不返回,同基础库自己发的操作 */
|
|
262
|
+
send(webviewId, operation) {
|
|
263
|
+
const callbackId = `wxa_${++this.seq}`;
|
|
264
|
+
return new Promise((resolve) => {
|
|
265
|
+
this.pending.set(callbackId, resolve);
|
|
266
|
+
this.publish(webviewId, "operateMap", { data: { ...operation, callbackId }, options: { timestamp: Date.now() } });
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/** map 组件发回的 operateMapCallback:是宿主发的操作时收下并返回 true,不再交给逻辑层 */
|
|
270
|
+
receive(message) {
|
|
271
|
+
const reply = message?.data;
|
|
272
|
+
const resolve = this.pending.get(reply?.callbackId);
|
|
273
|
+
if (!resolve) return false;
|
|
274
|
+
this.pending.delete(reply.callbackId);
|
|
275
|
+
resolve({ errMsg: reply.errMsg });
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
241
280
|
// src/runtime/host/api/tempFiles.ts
|
|
242
281
|
var TEMP_DIR = "/__wxa__/tmp";
|
|
243
282
|
async function saveTempFile(data, type) {
|
|
@@ -467,7 +506,11 @@
|
|
|
467
506
|
return { tempFilePath: await saveTempFile(bytes, String(args.fileType || "png")) };
|
|
468
507
|
},
|
|
469
508
|
// 基础库经这两个接口向后台拉各种配置和小程序信息
|
|
470
|
-
operateWXData: (args, { api }) =>
|
|
509
|
+
operateWXData: (args, { api }) => {
|
|
510
|
+
if (args.data?.api_name === "webapi_getwxanetwork") return bizDomainUnavailable(api);
|
|
511
|
+
if (args.data?.api_name === "webapi_getwxauserprivacyauthinfo") return ok(api, { data: { data: JSON.stringify(PRIVACY_AUTH_INFO) } });
|
|
512
|
+
return ok(api);
|
|
513
|
+
},
|
|
471
514
|
getAppContact: (args, { api }) => args.keyPath === "WxaAppInfo.Network.BizDomain" ? bizDomainUnavailable(api) : ok(api),
|
|
472
515
|
// 真实登录失败时明确返回 fail,不退回假数据:配置或登录态的问题要让开发者马上发现
|
|
473
516
|
login: options?.realLogin ? async (_args, { api }) => ok(api, { code: (await realLogin(api, "/__wxa__/api/login")).code }) : (_args, { api }) => ok(api, { code: `wxa_mock_code_${Date.now().toString(36)}` }),
|
|
@@ -514,6 +557,7 @@
|
|
|
514
557
|
function mockUser() {
|
|
515
558
|
return { nickName: "wxa-runner", avatarUrl: "", gender: 0, country: "", province: "", city: "", language: "zh_CN" };
|
|
516
559
|
}
|
|
560
|
+
var PRIVACY_AUTH_INFO = { action_code: 0, need_popup_scope_list: [], unauth_scope_list: [], wording: {} };
|
|
517
561
|
function bizDomainUnavailable(api) {
|
|
518
562
|
return fail(api, "not available in wxa-runner");
|
|
519
563
|
}
|
|
@@ -565,7 +609,7 @@
|
|
|
565
609
|
const requestTaskId = startTask(args, async (signal, id) => {
|
|
566
610
|
try {
|
|
567
611
|
const mocked = route && await route.respond(signal);
|
|
568
|
-
const res = mocked ? { statusCode: mocked.statusCode, header: mocked.header, cookies: [],
|
|
612
|
+
const res = mocked ? { statusCode: mocked.statusCode, header: mocked.header, cookies: [], response: new Response(mocked.body) } : await proxyFetch(request.url, { method: request.method, header: args.header, body: args.data, signal });
|
|
569
613
|
emit("onRequestTaskStateChange", {
|
|
570
614
|
requestTaskId: id,
|
|
571
615
|
state: "headersReceived",
|
|
@@ -573,7 +617,7 @@
|
|
|
573
617
|
statusCode: res.statusCode,
|
|
574
618
|
cookies: res.cookies
|
|
575
619
|
});
|
|
576
|
-
const data = await res.text();
|
|
620
|
+
const data = args.responseType === "arraybuffer" ? await res.response.arrayBuffer() : await res.response.text();
|
|
577
621
|
emit("onRequestTaskStateChange", {
|
|
578
622
|
requestTaskId: id,
|
|
579
623
|
state: "success",
|
|
@@ -652,11 +696,7 @@
|
|
|
652
696
|
socket.binaryType = "arraybuffer";
|
|
653
697
|
sockets.set(socketTaskId, socket);
|
|
654
698
|
socket.onopen = () => emit("onSocketTaskStateChange", { socketTaskId, state: "open", header: {}, profile: {} });
|
|
655
|
-
socket.onmessage = (event) => emit("onSocketTaskStateChange", {
|
|
656
|
-
socketTaskId,
|
|
657
|
-
state: "message",
|
|
658
|
-
data: typeof event.data === "string" ? event.data : "[binary message not supported]"
|
|
659
|
-
});
|
|
699
|
+
socket.onmessage = (event) => emit("onSocketTaskStateChange", { socketTaskId, state: "message", data: event.data });
|
|
660
700
|
socket.onerror = () => emit("onSocketTaskStateChange", { socketTaskId, state: "error", errMsg: "connectSocket:fail" });
|
|
661
701
|
socket.onclose = (event) => {
|
|
662
702
|
sockets.delete(socketTaskId);
|
|
@@ -991,11 +1031,11 @@
|
|
|
991
1031
|
checkDelay(response.delay);
|
|
992
1032
|
if (response.delay) await sleep(response.delay, signal);
|
|
993
1033
|
const { body } = response;
|
|
994
|
-
const
|
|
1034
|
+
const isJson = body !== void 0 && typeof body !== "string" && !isBinary(body);
|
|
995
1035
|
return {
|
|
996
1036
|
statusCode: response.status ?? 200,
|
|
997
|
-
header: { ...
|
|
998
|
-
|
|
1037
|
+
header: { ...isJson ? { "Content-Type": "application/json" } : {}, ...response.header },
|
|
1038
|
+
body: body === void 0 ? "" : isJson ? JSON.stringify(body) : body
|
|
999
1039
|
};
|
|
1000
1040
|
}
|
|
1001
1041
|
};
|
|
@@ -1010,6 +1050,9 @@
|
|
|
1010
1050
|
const regexp = globToRegExp(url);
|
|
1011
1051
|
return (request) => (!method || method === request.method) && regexp.test(String(request.url).replace(/[?#].*$/, ""));
|
|
1012
1052
|
}
|
|
1053
|
+
function isBinary(value) {
|
|
1054
|
+
return ArrayBuffer.isView(value) || Object.prototype.toString.call(value) === "[object ArrayBuffer]";
|
|
1055
|
+
}
|
|
1013
1056
|
function checkDelay(delay) {
|
|
1014
1057
|
if (delay !== void 0 && !(typeof delay === "number" && delay >= 0 && Number.isFinite(delay))) {
|
|
1015
1058
|
throw new Error(`delay \u9700\u8981\u662F\u4E0D\u5C0F\u4E8E 0 \u7684\u6BEB\u79D2\u6570\uFF0C\u5B9E\u9645\u662F ${String(delay)}`);
|
|
@@ -2096,6 +2139,7 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2096
2139
|
this.api = new ApiRegistry((context) => this.reportUnimplemented(context));
|
|
2097
2140
|
/** setup 和测试 API 声明的请求拦截 */
|
|
2098
2141
|
this.routes = new RequestRoutes();
|
|
2142
|
+
this.mapOperations = new MapOperations((webviewId, event, data) => this.publishToPages(event, data, [webviewId]));
|
|
2099
2143
|
this.service = null;
|
|
2100
2144
|
/** 新版基础库的业务子上下文;旧版基础库业务代码直接在逻辑层 iframe 里 */
|
|
2101
2145
|
this.appContext = null;
|
|
@@ -2164,22 +2208,27 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2164
2208
|
}
|
|
2165
2209
|
publish(kind, win, event, data, webviewIds) {
|
|
2166
2210
|
if (kind === "service") {
|
|
2167
|
-
|
|
2168
|
-
const message = event === "canvasActionsChanged" ? withDrawableImages(data) : data;
|
|
2169
|
-
for (const page of targets) {
|
|
2170
|
-
page?.dispatch((bridge, target) => {
|
|
2171
|
-
const payload2 = cloneInto(target, message);
|
|
2172
|
-
queueMicrotask(() => bridge.__dispatchSub(event, payload2, 0));
|
|
2173
|
-
});
|
|
2174
|
-
}
|
|
2211
|
+
this.publishToPages(event, data, webviewIds);
|
|
2175
2212
|
return;
|
|
2176
2213
|
}
|
|
2214
|
+
if (event === "operateMapCallback" && this.mapOperations.receive(data)) return;
|
|
2177
2215
|
const fromId = this.webviewIdOf(win);
|
|
2178
2216
|
const service = this.service;
|
|
2179
2217
|
if (!service) return;
|
|
2180
2218
|
const payload = this.cloneForService(data);
|
|
2181
2219
|
queueMicrotask(() => service.bridge.__dispatchSub(event, payload, fromId));
|
|
2182
2220
|
}
|
|
2221
|
+
/** 不指定目标时发给所有页面:旧版 canvas 的绘制指令就是这样发的,由 canvasNumber 找到对应画布 */
|
|
2222
|
+
publishToPages(event, data, webviewIds) {
|
|
2223
|
+
const targets = webviewIds?.length ? webviewIds.map((id) => this.pages.get(Number(id))) : this.livePages();
|
|
2224
|
+
const message = event === "canvasActionsChanged" ? withDrawableImages(data) : data;
|
|
2225
|
+
for (const page of targets) {
|
|
2226
|
+
page?.dispatch((bridge, target) => {
|
|
2227
|
+
const payload = cloneInto(target, message);
|
|
2228
|
+
queueMicrotask(() => bridge.__dispatchSub(event, payload, 0));
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2183
2232
|
reportError(kind, webviewId, error) {
|
|
2184
2233
|
const err = typeof error?.message === "string" ? error : null;
|
|
2185
2234
|
this.errors.push({
|
|
@@ -2430,6 +2479,7 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2430
2479
|
onRequest: (request) => this.requests.add(request)
|
|
2431
2480
|
}),
|
|
2432
2481
|
...createAudioApis({ emit: (event, data) => this.emitToService(event, data) }),
|
|
2482
|
+
...createMapApis({ registry: this.api, operations: this.mapOperations }),
|
|
2433
2483
|
...createLibFileApis({ windowOf: (webviewId) => this.pages.get(webviewId)?.win }),
|
|
2434
2484
|
...createUiApis({ shell: this.shell, updateNavigation: (state) => this.updateNavigation(state) }),
|
|
2435
2485
|
...createMediaApis({
|