@skillbuilder/miniapp-simulator 0.2.8 → 0.2.9
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/sw/miniapp-simulator-service-worker.js +725 -375
- package/dist/sw/miniapp-simulator-service-worker.min.js +2 -1
- package/lib/{client-C59iNO5u.mjs → client-CX13jDtT.mjs} +1 -1
- package/lib/{index-BSj1bmle.mjs → index-DwepISqo.mjs} +1 -1
- package/lib/index.js +1058 -1012
- package/lib/remote-client.js +2 -2
- package/lib/types/core/simulator.d.ts +240 -2
- package/lib/types/host/shadow-host.d.ts +5 -0
- package/lib/types/offload/manifest.d.ts +12 -0
- package/lib/types/offload/resource-session.d.ts +33 -0
- package/lib/types/remote/client.d.ts +2 -0
- package/lib/types/remote/protocol.d.ts +6 -1
- package/lib/types/sw/protocol.d.ts +2 -1
- package/lib/types/sw/service-worker-host.d.ts +1 -0
- package/lib/types/sw/worker/mount-store.d.ts +7 -4
- package/lib/types/sw/worker/offloaded.d.ts +3 -0
- package/lib/types/utils/stage-fit.d.ts +7 -1
- package/lib/workbench.js +1 -1
- package/package.json +2 -1
package/lib/remote-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as r, a as O, c as e } from "./client-
|
|
1
|
+
import { R as r, a as O, c as e } from "./client-CX13jDtT.mjs";
|
|
2
2
|
import { B as s, M as _ } from "./options-B34ipLmF.mjs";
|
|
3
|
-
import { M } from "./index-
|
|
3
|
+
import { M } from "./index-DwepISqo.mjs";
|
|
4
4
|
export {
|
|
5
5
|
s as BusinessLine,
|
|
6
6
|
_ as MINIAPP_SCREENSHOT_ERROR_CODE,
|
|
@@ -1,5 +1,242 @@
|
|
|
1
1
|
import type { KeyboardPanelHost } from "../gesture/keyboard-panel";
|
|
2
|
-
import type {
|
|
2
|
+
import type { OffloadedResourceSession } from "../offload/resource-session";
|
|
3
|
+
import type { InjectionModule } from "../injection";
|
|
4
|
+
import type { MiniAppContentMode, MiniAppEventHandler, MiniAppEventName, MiniAppFileMap, MiniAppGamePlaytestController, MiniAppGestureController, MiniAppHostApiController, MiniAppInspectorController, MiniAppLoadFilesOptions, MiniAppLoadFilesResult, MiniAppLoadZipOptions, MiniAppLoadZipResult, MiniAppLoadZipSource, MiniAppNotePreviewController, MiniAppPermissionSheetController, MiniAppPhoneFrame, MiniAppRedirectOptions, MiniAppScreenShotResult, MiniAppSimulator as MiniAppSimulatorInterface, MiniAppSimulatorOptions, MiniAppSimulatorRoute, MiniAppSimulatorStatus, MiniAppViewport, MiniAppWidgetCoverController } from "../types";
|
|
5
|
+
declare class MiniAppSimulatorImpl implements MiniAppSimulatorInterface {
|
|
6
|
+
private readonly runtimeOptions;
|
|
7
|
+
private readonly lifecycle;
|
|
8
|
+
private readonly events;
|
|
9
|
+
/** SDK 在消费方 root 内创建的 shadow 宿主(含 stage / bounds) */
|
|
10
|
+
private readonly shadowHost;
|
|
11
|
+
private readonly phoneVibration;
|
|
12
|
+
/**
|
|
13
|
+
* 注入清单:security / jsapi / render-done 三个内置模块在 constructor 注册,
|
|
14
|
+
* 跨 reload 持久存在;后续可由 plugin 追加自定义注入。
|
|
15
|
+
*/
|
|
16
|
+
private readonly injection;
|
|
17
|
+
private options;
|
|
18
|
+
private renderer;
|
|
19
|
+
/** 只允许最新一次加载继续提交状态;快速切版本时旧解析/挂载会被静默回收。 */
|
|
20
|
+
private loadGeneration;
|
|
21
|
+
private loadedUrl;
|
|
22
|
+
/** 当前 load 的触发来源,供 beforeLoad 事件标记 */
|
|
23
|
+
private loadSource;
|
|
24
|
+
/** SW 渲染模式:当前生效的 SW 宿主与已挂载 id(下次加载 / 销毁时 UNMOUNT 回收) */
|
|
25
|
+
private swHost;
|
|
26
|
+
private swMountedId;
|
|
27
|
+
/**
|
|
28
|
+
* 重算 head 注入所需的入参快照。SW 直供下 head 是 mount 时算好交给 worker 的,
|
|
29
|
+
* reload 只是重导航虚拟 URL,不会重新走注入装配;运行期新增注入模块(评测探针)
|
|
30
|
+
* 必须靠这份快照重算并 remount 才能生效。
|
|
31
|
+
*/
|
|
32
|
+
private swInjectionContext;
|
|
33
|
+
/**
|
|
34
|
+
* setHeapLimitOverride 生效前的原值,供恢复用。undefined 表示当前没有覆盖。
|
|
35
|
+
* 只记一次:评测期间反复改值也只能回到最初的线上限值。
|
|
36
|
+
*/
|
|
37
|
+
private baseHeapLimit;
|
|
38
|
+
/** 同步注入与 getLaunchOptions 共用的当前 usr 根路径。 */
|
|
39
|
+
private userDataPath;
|
|
40
|
+
/** SW 注册失败后置位:远程 appUrl 后续以真实 URL 直连(跳过 SW 代理) */
|
|
41
|
+
private serviceWorkerUnavailable;
|
|
42
|
+
private detachStageFit;
|
|
43
|
+
/** request / xhsRequest / abortRequest 的独立执行层。 */
|
|
44
|
+
private readonly requestRuntime;
|
|
45
|
+
private readonly storageScope;
|
|
46
|
+
/**
|
|
47
|
+
* 宿主能力 map:构造时来自 `options.hostApi`,运行时通过 `simulator.hostApi.set` 增删。
|
|
48
|
+
* **不会**自动注册到 bridge.handlers;只供内置 bridge handler 按需调用,
|
|
49
|
+
* 即"bridge 实现自己决定是调宿主能力还是 native-ui"。
|
|
50
|
+
*/
|
|
51
|
+
private readonly hostApiMap;
|
|
52
|
+
private readonly showJsApiAlert;
|
|
53
|
+
/** 持久化的用户自定义 gesture plugin:跨 reload / renderer 重建保留 */
|
|
54
|
+
private readonly gesturePlugins;
|
|
55
|
+
/** 持久化的选取模式开启状态:跨 reload / renderer 重建后自动重应用 */
|
|
56
|
+
private inspectorEnabled;
|
|
57
|
+
/** 可视化选取的单选 / 多选模式:跨 renderer 重建保留 */
|
|
58
|
+
private inspectorSelectionMode;
|
|
59
|
+
private readonly tracker;
|
|
60
|
+
/** Debug 调试面板(仅 options.debug 时实例化);跨 reload 持久存在 */
|
|
61
|
+
private devtoolsPanel;
|
|
62
|
+
/** Debug 面板唤起快捷键卸载函数 */
|
|
63
|
+
private detachDevtoolsShortcut;
|
|
64
|
+
/** 当前页面路由(note / minitool / profile) */
|
|
65
|
+
private currentRoute;
|
|
66
|
+
/** 小工具收起后回落的活动页(note 笔记页 / profile 个人页) */
|
|
67
|
+
private activePage;
|
|
68
|
+
/** JSAPI 模块共用的只读运行态视图;字段访问始终读取最新模拟器状态。 */
|
|
69
|
+
private get jsapiContext();
|
|
70
|
+
readonly hostApi: MiniAppHostApiController;
|
|
71
|
+
readonly gesture: MiniAppGestureController;
|
|
72
|
+
readonly gamePlaytest: MiniAppGamePlaytestController;
|
|
73
|
+
readonly inspector: MiniAppInspectorController;
|
|
74
|
+
readonly notePreview: MiniAppNotePreviewController;
|
|
75
|
+
readonly widgetCover: MiniAppWidgetCoverController;
|
|
76
|
+
readonly permissionSheet: MiniAppPermissionSheetController;
|
|
77
|
+
constructor(options: MiniAppSimulatorOptions, runtimeOptions?: {
|
|
78
|
+
keyboardPanelHost?: KeyboardPanelHost;
|
|
79
|
+
requestManagerFrameUrl?: string;
|
|
80
|
+
gateways?: Record<string, string>;
|
|
81
|
+
businessLine?: string;
|
|
82
|
+
trackerContext?: () => Record<string, string | number | undefined>;
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* 初始化 Debug 调试面板:以 fixed 停靠窗口右侧(挂 document.body,不遮挡模拟器舞台),
|
|
86
|
+
* 注册 Shift+Cmd/Ctrl+U 唤起快捷键。能力开关仅供内部调试并触发整页 reload。
|
|
87
|
+
*/
|
|
88
|
+
private initDevtools;
|
|
89
|
+
/** 从当前归一化选项构造调试面板快照 */
|
|
90
|
+
private buildDevtoolsSnapshot;
|
|
91
|
+
/** device 作为渲染容器,bounds 作为 stageFit 默认边界 */
|
|
92
|
+
private normalizeContext;
|
|
93
|
+
/** 去掉仅在创建期使用、normalize 不需要的 host / 回调字段 */
|
|
94
|
+
private stripHostOptions;
|
|
95
|
+
/** 实例创建时把 option 级回调绑定到对应事件 */
|
|
96
|
+
private bindLifecycleCallbacks;
|
|
97
|
+
/**
|
|
98
|
+
* 合并补丁并重新归一化(深合并 notePreview / security / review,与 updateConfig 一致)。
|
|
99
|
+
* 入参允许是已归一化形态(来自 this.options)+ 局部覆盖。
|
|
100
|
+
*/
|
|
101
|
+
private mergeOptions;
|
|
102
|
+
get status(): MiniAppSimulatorStatus;
|
|
103
|
+
/**
|
|
104
|
+
* 尝试调用宿主注册的 getUserInfo handler 获取用户信息,
|
|
105
|
+
* 用于更新笔记页导航栏与个人页(资料区 / 卡片作者行)的头像和昵称。
|
|
106
|
+
* 未注册或调用失败时静默保留默认值。
|
|
107
|
+
*/
|
|
108
|
+
private tryResolveHostUserInfo;
|
|
109
|
+
private syncRendererRednoteContext;
|
|
110
|
+
private syncRendererProfileContext;
|
|
111
|
+
/** 小工具封面:同步到 renderer 壳层(笔记尾卡 + 个人页卡片两处生效) */
|
|
112
|
+
private syncRendererWidgetCover;
|
|
113
|
+
/** 更新当前路由;变化时统一发出 routerChange 事件(宿主调用与内部跳转共用) */
|
|
114
|
+
private setRoute;
|
|
115
|
+
/** 壳层路由变化:note/profile(头像 / 返回 / 宿主跳转)、minitool(sheet 唤起)、back(sheet 收起回落活动页) */
|
|
116
|
+
private handleShellRouteChange;
|
|
117
|
+
getCurrentRoute(): MiniAppSimulatorRoute;
|
|
118
|
+
redirectTo(route: MiniAppSimulatorRoute, options?: MiniAppRedirectOptions): Promise<void>;
|
|
119
|
+
load(): Promise<void>;
|
|
120
|
+
private isCurrentLoad;
|
|
121
|
+
/** 终止当前 guest,并回收其 renderer 与 SW 挂载。 */
|
|
122
|
+
private interruptCurrentGuest;
|
|
123
|
+
private loadCurrent;
|
|
124
|
+
unload(): void;
|
|
125
|
+
/**
|
|
126
|
+
* 执行宿主定制项:函数则直接调用;`{ toast }` 则弹该文案并回成功。
|
|
127
|
+
*/
|
|
128
|
+
private runHostEntry;
|
|
129
|
+
private runUnsupportedJsApi;
|
|
130
|
+
/** 注册模拟器 JSAPI 领域模块;未声明事件仍由 fallback 分发。 */
|
|
131
|
+
private registerBuiltinBridgeHandlers;
|
|
132
|
+
reload(): Promise<void>;
|
|
133
|
+
resize(viewport: MiniAppViewport): void;
|
|
134
|
+
/** @deprecated 创建实例时传入完整配置;配置变化时销毁并重新创建实例。 */
|
|
135
|
+
updateConfig(options: Partial<Omit<MiniAppSimulatorOptions, "mount" | "shadow">>): void;
|
|
136
|
+
setViewport(viewport: MiniAppViewport): void;
|
|
137
|
+
setZoomFactor(factor: number): void;
|
|
138
|
+
switchMode(mode: MiniAppContentMode): Promise<void>;
|
|
139
|
+
switchContentMode(mode: MiniAppContentMode): Promise<void>;
|
|
140
|
+
switchPhoneFrame(frame: string | MiniAppPhoneFrame | false): Promise<void>;
|
|
141
|
+
switchDevice(device: string): void;
|
|
142
|
+
loadApp(appUrl: string, options?: {
|
|
143
|
+
query?: MiniAppSimulatorOptions["query"];
|
|
144
|
+
}): Promise<void>;
|
|
145
|
+
loadZip(source: MiniAppLoadZipSource, options?: MiniAppLoadZipOptions): Promise<MiniAppLoadZipResult>;
|
|
146
|
+
loadFiles(files: MiniAppFileMap, options?: MiniAppLoadFilesOptions, offloaded?: OffloadedResourceSession): Promise<MiniAppLoadFilesResult>;
|
|
147
|
+
/**
|
|
148
|
+
* loadZip / loadFiles 走 `iframe-service-worker`(Web 运行时):把包文件挂载给
|
|
149
|
+
* Service Worker 当同源虚拟服务器直供。使用前请把 renderer 设为 `iframe-service-worker`。
|
|
150
|
+
*/
|
|
151
|
+
private assertServiceWorkerLoader;
|
|
152
|
+
/** SW 模式前置校验:环境/配置不满足直接抛(宿主据此提示加载失败)。 */
|
|
153
|
+
private assertServiceWorkerUsable;
|
|
154
|
+
private toLoadMeta;
|
|
155
|
+
/** 注册 + 激活 SW(打点注册结果 / 耗时);注册失败置 serviceWorkerUnavailable,后续跳过 SW。 */
|
|
156
|
+
private acquireServiceWorkerHost;
|
|
157
|
+
/** SW 路径:算注入载荷 → 挂载原始文件到 SW → 以同源虚拟 URL 直连(SW 改写 HTML + 下发 CSP)。 */
|
|
158
|
+
private loadViaServiceWorker;
|
|
159
|
+
/** 是否对当前远程 appUrl 启用 SW 代理:SW 渲染器 + 配了 scriptUrl + 环境支持 + 未注册失败 + appUrl 为跨域 http(s)。 */
|
|
160
|
+
private shouldProxyRemoteViaServiceWorker;
|
|
161
|
+
/** load() 内调用:远程 appUrl 满足条件时挂进 SW 走同源代理;失败经 error 事件暴露并抛出。 */
|
|
162
|
+
private maybeMountRemoteViaServiceWorker;
|
|
163
|
+
/** 半屏/全屏壳层收起后再次唤起时,先恢复 SW 注册与内存挂载表,再加载虚拟 URL。 */
|
|
164
|
+
private restoreServiceWorkerMount;
|
|
165
|
+
/** 远程 SW 代理:fetch 远程入口 HTML(需开 CORS)→ 注入 → 仅挂入口+remoteBase → appUrl 改写为同源虚拟 URL,子资源由 SW 回源。 */
|
|
166
|
+
private mountRemoteViaServiceWorker;
|
|
167
|
+
setTouchEmulation(enabled: boolean): Promise<void>;
|
|
168
|
+
/** 回收 SW 模式的挂载。 */
|
|
169
|
+
private unmountServiceWorkerContent;
|
|
170
|
+
private resolveLoadUrl;
|
|
171
|
+
private isCurrentServiceWorkerMountUrl;
|
|
172
|
+
/**
|
|
173
|
+
* 开关小应用 DevTools。仅 webview 渲染器实现(独立 webContents);
|
|
174
|
+
* iframe 渲染器无该能力时为 no-op(DevTools 由宿主整窗负责)。
|
|
175
|
+
*/
|
|
176
|
+
setDevtools(open: boolean): void;
|
|
177
|
+
/**
|
|
178
|
+
* 开关手势 overlay 的 pointer-events(touchEmulation 时生效)。
|
|
179
|
+
* 宿主嵌入 DevTools 做 Elements 审查时应设为 false,让点击穿透到 guest。
|
|
180
|
+
*/
|
|
181
|
+
setGestureOverlayInteractionEnabled(enabled: boolean): void;
|
|
182
|
+
/**
|
|
183
|
+
* 返回小应用渲染容器的 webContents id(仅 webview 渲染器,dom-ready 后可用,否则 null)。
|
|
184
|
+
* 不做 lifecycle 断言:宿主可能在 load 完成后立即轮询。
|
|
185
|
+
*/
|
|
186
|
+
getWebContentsId(): number | null;
|
|
187
|
+
/**
|
|
188
|
+
* 注册宿主侧扩展注入模块(评测探针等)。下次 load / reload 生效。
|
|
189
|
+
*
|
|
190
|
+
* 注册后会把 security 重新移回末位:seal 锁定内置原型,探针必须在它之前安装,
|
|
191
|
+
* 否则 hook 目标属性已不可配置,采集静默归零。
|
|
192
|
+
*/
|
|
193
|
+
registerInjection(module: InjectionModule): void;
|
|
194
|
+
/** 注销扩展注入模块;下次 load / reload 生效。返回是否命中。 */
|
|
195
|
+
unregisterInjection(id: string): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* 打开评测面板等内容的独立容器:竖直摆放时在设备右侧,旋转时在设备下方。
|
|
198
|
+
*
|
|
199
|
+
* 右侧面板在 width 与 maxWidth 之间适度扩展,底部面板占满挂载区宽度。
|
|
200
|
+
* 设备由 stageFit 在剩余区域内等比适配,桌面操作模式下靠上摆放。
|
|
201
|
+
*/
|
|
202
|
+
openSidePanel(width: number, maxWidth?: number): HTMLElement;
|
|
203
|
+
/** 收起侧栏并清空其内容;设备恢复占满整个挂载区。 */
|
|
204
|
+
closeSidePanel(): void;
|
|
205
|
+
/** 整块模拟器容器,包含设备、侧栏及容器内留白。 */
|
|
206
|
+
getInteractionRegions(): readonly HTMLElement[];
|
|
207
|
+
/**
|
|
208
|
+
* 临时调整 guest 堆熔断线,供体验评测使用;传 null 恢复建实例时的值。
|
|
209
|
+
*
|
|
210
|
+
* 熔断会把整个 iframe 换成 about:blank,注入的探针随 Realm 一起消失,本次采集
|
|
211
|
+
* 只能作废——而"内存占用大"正是评测最该测出来的事。改值后须调 refreshInjection
|
|
212
|
+
* 并 reload 才会重新下发 resource-guard 的新阈值。
|
|
213
|
+
*/
|
|
214
|
+
setHeapLimitOverride(maxHeapUsedBytes: number | false | null): void;
|
|
215
|
+
/**
|
|
216
|
+
* 重算 head 注入并就地替换 SW 已挂载实例的注入载荷。
|
|
217
|
+
*
|
|
218
|
+
* SW 直供路径下 head 是 mount 时一次性算好交给 worker 的,reload 只重导航虚拟 URL,
|
|
219
|
+
* 拿到的仍是旧 HTML。运行期通过 registerInjection 新增的模块必须调一次本方法,
|
|
220
|
+
* 之后的 reload 才会带上新注入。
|
|
221
|
+
*
|
|
222
|
+
* 返回 false 表示当前不是 SW 直供状态(无快照),调用方应改走完整 load。
|
|
223
|
+
*/
|
|
224
|
+
refreshInjection(): Promise<boolean>;
|
|
225
|
+
capture(): Promise<Blob>;
|
|
226
|
+
/**
|
|
227
|
+
* 主动截取小工具运行画面(完整画面):成功返回 base64 dataURL,失败返回 code + reason(不抛异常)。
|
|
228
|
+
* 结果同时以 `screenShot` 事件(source: "manual")对外发出。
|
|
229
|
+
*/
|
|
230
|
+
screenShot(): Promise<MiniAppScreenShotResult>;
|
|
231
|
+
destroy(reason?: string): void;
|
|
232
|
+
on<E extends MiniAppEventName>(event: E, handler: MiniAppEventHandler<E>): () => void;
|
|
233
|
+
once<E extends MiniAppEventName>(event: E, handler: MiniAppEventHandler<E>): () => void;
|
|
234
|
+
off<E extends MiniAppEventName>(event: E, handler: MiniAppEventHandler<E>): void;
|
|
235
|
+
/** 根据渲染器类型创建对应的 Transport;webview 手势 IPC 与 jsapi bridge 共用通道 */
|
|
236
|
+
private createTransport;
|
|
237
|
+
private createRenderer;
|
|
238
|
+
private bindRendererEvents;
|
|
239
|
+
}
|
|
3
240
|
export declare function createMiniAppSimulator(options: MiniAppSimulatorOptions): MiniAppSimulatorInterface;
|
|
4
241
|
/** @internal 远程 Runtime 注入服务端托管资源;不属于接入方配置。 */
|
|
5
242
|
export declare function createRuntimeMiniAppSimulator(options: MiniAppSimulatorOptions, runtimeOptions: {
|
|
@@ -8,4 +245,5 @@ export declare function createRuntimeMiniAppSimulator(options: MiniAppSimulatorO
|
|
|
8
245
|
gateways?: Record<string, string>;
|
|
9
246
|
businessLine?: string;
|
|
10
247
|
trackerContext?: () => Record<string, string | number | undefined>;
|
|
11
|
-
}):
|
|
248
|
+
}): MiniAppSimulatorImpl;
|
|
249
|
+
export {};
|
|
@@ -45,6 +45,11 @@ export interface MiniAppShadowHost {
|
|
|
45
45
|
sidePanel: HTMLElement;
|
|
46
46
|
/** 设置竖直摆放时侧栏最小/最大宽度;传 0 收起。bounds 自动让出面板空间。 */
|
|
47
47
|
setSidePanelWidth(width: number, maxWidth?: number): void;
|
|
48
|
+
/** 同一宿主内,整台手机转过 90° 后可用于显示的区域。 */
|
|
49
|
+
getQuarterTurnBounds(bounds: HTMLElement): {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
};
|
|
48
53
|
/** 桌面工具栏的空间只影响宿主布局。 */
|
|
49
54
|
setDesktopControls(enabled: boolean): void;
|
|
50
55
|
/** 整台设备每次按指定方向旋转 90°,四次回到原位,不改变 guest 逻辑尺寸。 */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const RESOURCE_MANIFEST_PATH = "__xhs_offload__/resources.json";
|
|
2
|
+
export interface OffloadedResource {
|
|
3
|
+
fileId: string;
|
|
4
|
+
size: number;
|
|
5
|
+
sha256: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ResourceManifest {
|
|
9
|
+
artifactId: string;
|
|
10
|
+
resources: Map<string, OffloadedResource>;
|
|
11
|
+
}
|
|
12
|
+
export declare function parseResourceManifest(bytes: ArrayBuffer | undefined): ResourceManifest;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BusinessLine } from "../business-line";
|
|
2
|
+
import type { MiniAppHostRequest } from "../types";
|
|
3
|
+
import type { ResourceManifest } from "./manifest";
|
|
4
|
+
export interface OffloadedResourceContext {
|
|
5
|
+
url: string;
|
|
6
|
+
params: Record<string, string>;
|
|
7
|
+
creatorId: string;
|
|
8
|
+
request: MiniAppHostRequest;
|
|
9
|
+
}
|
|
10
|
+
export declare function getOffloadedResourceRoute(businessLine: BusinessLine, { edith, appId, contentId }: {
|
|
11
|
+
edith: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
contentId: string;
|
|
14
|
+
}): Pick<OffloadedResourceContext, "url" | "params"> | undefined;
|
|
15
|
+
/** 一个精简包的签名表。SW 只能按已登记的包内路径查询。 */
|
|
16
|
+
export declare class OffloadedResourceSession {
|
|
17
|
+
readonly manifest: ResourceManifest;
|
|
18
|
+
private readonly context;
|
|
19
|
+
private readonly onUnavailable;
|
|
20
|
+
private readonly lifetime;
|
|
21
|
+
private readonly addresses;
|
|
22
|
+
private readonly ids;
|
|
23
|
+
private pending?;
|
|
24
|
+
private retryAfter;
|
|
25
|
+
private refreshAfter;
|
|
26
|
+
private refreshCount;
|
|
27
|
+
constructor(manifest: ResourceManifest, context: OffloadedResourceContext, onUnavailable: (count: number) => void);
|
|
28
|
+
dispose(): void;
|
|
29
|
+
resolve(path: string, rejectedUrl?: string): Promise<string>;
|
|
30
|
+
prepare(): Promise<void>;
|
|
31
|
+
private unresolvedIds;
|
|
32
|
+
private exchange;
|
|
33
|
+
}
|
|
@@ -44,6 +44,8 @@ export interface RemoteMiniAppSimulator {
|
|
|
44
44
|
load(): Promise<void>;
|
|
45
45
|
loadZip(source: Blob | ArrayBuffer | Uint8Array, options?: {
|
|
46
46
|
entry?: string;
|
|
47
|
+
offloaded?: boolean;
|
|
48
|
+
creatorId?: string;
|
|
47
49
|
}): Promise<MiniAppLoadZipResult>;
|
|
48
50
|
loadFiles(files: RemoteMethodArgumentMap["loadFiles"][0]["files"], options?: RemoteMethodArgumentMap["loadFiles"][0]["options"]): Promise<MiniAppLoadFilesResult>;
|
|
49
51
|
loadApp(url: string, options?: RemoteMethodArgumentMap["loadApp"][1]): Promise<void>;
|
|
@@ -15,6 +15,8 @@ export declare const REMOTE_INSPECTOR_PAUSE_RUNTIME_CAPABILITY = "inspectorPause
|
|
|
15
15
|
* 版本不一致会让老 runtime 直接握手失败,而评测是可选能力,缺失只应降级。
|
|
16
16
|
*/
|
|
17
17
|
export declare const REMOTE_AUDIT_CAPABILITY = "audit";
|
|
18
|
+
/** 当前会话支持加载带外移资源清单的精简包。 */
|
|
19
|
+
export declare const REMOTE_OFFLOADED_PACKAGE_CAPABILITY = "offloadedPackage";
|
|
18
20
|
/** Client 可在外层页面承载 Runtime 的键位编辑浮窗。 */
|
|
19
21
|
export declare const REMOTE_KEYBOARD_PANEL_CAPABILITY = "keyboardPanelPortal";
|
|
20
22
|
export declare const REMOTE_SIMULATOR_CAPABILITIES: string[];
|
|
@@ -159,7 +161,10 @@ export type RemoteSimulatorPortMessage = {
|
|
|
159
161
|
export type RemoteSimulatorMethod = "load" | "loadZip" | "loadFiles" | "loadApp" | "unload" | "reload" | "setViewport" | "switchContentMode" | "switchPhoneFrame" | "switchDevice" | "setTouchEmulation" | "permissionSheet.show" | "permissionSheet.hide" | "notePreview.update" | "notePreview.updateUser" | "notePreview.updateAppCard" | "widgetCover.update" | "router.redirectTo" | "router.getRoute" | "inspector.enable" | "inspector.disable" | "inspector.toggle" | "inspector.clear" | "inspector.setSelectionMode" | "inspector.getSelectionMode" | "inspector.getSceneTree" | "inspector.selectByRef" | "capture" | "screenShot" | "setAutoScreenShot" | "hostApi.sync" | "hostApi.emit" | "audit.start" | "audit.stop" | "audit.status" | "audit.report" | "audit.setPolicy" | "destroy";
|
|
160
162
|
export interface RemoteLoadZipArgs {
|
|
161
163
|
buffer: ArrayBuffer;
|
|
162
|
-
options?: Omit<MiniAppLoadZipOptions, "jszip"
|
|
164
|
+
options?: Omit<MiniAppLoadZipOptions, "jszip"> & {
|
|
165
|
+
offloaded?: boolean;
|
|
166
|
+
creatorId?: string;
|
|
167
|
+
};
|
|
163
168
|
}
|
|
164
169
|
export interface RemoteLoadFilesArgs {
|
|
165
170
|
files: MiniAppFileMap;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Runtime 与 Service Worker 随同一 release 发布,协议版本必须精确一致。 */
|
|
2
|
-
export declare const SERVICE_WORKER_PROTOCOL_VERSION =
|
|
2
|
+
export declare const SERVICE_WORKER_PROTOCOL_VERSION = 6;
|
|
3
|
+
export declare const SW_OFFLOADED_URL = "miniapp:offloaded-resource-url";
|
|
3
4
|
/** 资源 SW 重启后,向持有包快照的可信宿主请求恢复 Worker 挂载。 */
|
|
4
5
|
export declare const SW_WORKER_MOUNT_RECOVERY = "miniapp:restore-worker-mount";
|
|
5
6
|
/** 当前 Service Worker 提供的文件系统操作。 */
|
|
@@ -8,6 +8,7 @@ import { type ServiceWorkerFileSystemArgs, type ServiceWorkerFileSystemOperation
|
|
|
8
8
|
/** 是否具备启用 SW 模式的运行环境(API 可用 + 安全上下文)。 */
|
|
9
9
|
export declare function isServiceWorkerHostSupported(): boolean;
|
|
10
10
|
export interface ServiceWorkerMountInput {
|
|
11
|
+
offloaded?: import("../offload/resource-session").OffloadedResourceSession;
|
|
11
12
|
worker?: import("../worker/adapters/package-policy").WorkerMountPolicy;
|
|
12
13
|
id: string;
|
|
13
14
|
/** 入口文件包内路径(如 `index.html`),用于生成虚拟 URL。 */
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* 挂载表 —— id → 已挂载小工具实例。多预览实例 / 多 iframe 共用一个 SW,按 id 前缀隔离。
|
|
3
|
-
* 负责 MOUNT/UNMOUNT 的存储,以及请求路径 → 实例的两级归属查找(`/<id>/` 标记 + clientId 反查)。
|
|
4
|
-
*/
|
|
1
|
+
import type { OffloadedResource } from "../../offload/manifest";
|
|
5
2
|
import type { WorkerMountPolicy } from "../../worker/adapters/package-policy";
|
|
6
3
|
export interface MountedFile {
|
|
7
4
|
bytes: ArrayBuffer;
|
|
8
5
|
mime: string;
|
|
9
6
|
}
|
|
10
7
|
export interface MountedApp {
|
|
8
|
+
offloaded?: {
|
|
9
|
+
id: string;
|
|
10
|
+
resources: Map<string, OffloadedResource>;
|
|
11
|
+
lifetime: AbortController;
|
|
12
|
+
};
|
|
11
13
|
worker?: WorkerMountPolicy;
|
|
12
14
|
/** 以包内文件路径为键缓存原始字节及独立 CSP 响应。 */
|
|
13
15
|
workerResponses: Map<string, Response>;
|
|
@@ -25,6 +27,7 @@ export interface MountedApp {
|
|
|
25
27
|
}
|
|
26
28
|
export declare const STORE: Map<string, MountedApp>;
|
|
27
29
|
export interface MountInput {
|
|
30
|
+
offloaded?: Map<string, OffloadedResource>;
|
|
28
31
|
worker?: WorkerMountPolicy;
|
|
29
32
|
id: string;
|
|
30
33
|
files: Record<string, ArrayBuffer>;
|
|
@@ -3,4 +3,10 @@ import type { NormalizedMiniAppStageFitOptions } from "../types";
|
|
|
3
3
|
* 在 bounds 内对 container 做自适应缩放(默认 100% 撑满;可选右上角拖拽调整 scaleMultiplier)。
|
|
4
4
|
* 卸载时恢复挂载前的内联样式。
|
|
5
5
|
*/
|
|
6
|
-
export declare function attachMiniAppStageFit(container: HTMLElement, config: NormalizedMiniAppStageFitOptions
|
|
6
|
+
export declare function attachMiniAppStageFit(container: HTMLElement, config: NormalizedMiniAppStageFitOptions, rotation?: {
|
|
7
|
+
host: HTMLElement;
|
|
8
|
+
getQuarterTurnBounds(bounds: HTMLElement): {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
}): () => void;
|
package/lib/workbench.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillbuilder/miniapp-simulator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Designable Miniapp Simulator - 技术栈无关的小应用 PC 预览与审核模拟器 SDK",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@koa/router": "^15.7.0",
|
|
57
57
|
"@koa/send": "^6.0.0",
|
|
58
|
+
"@noble/hashes": "1.8.0",
|
|
58
59
|
"chokidar": "^4.0.3",
|
|
59
60
|
"html-to-image": "^1.11.13",
|
|
60
61
|
"jszip": "^3.10.1",
|