@skillbuilder/miniapp-simulator 0.0.0-stage → 0.2.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.
Files changed (229) hide show
  1. package/README.md +263 -2
  2. package/assets/phones/Nexus-5X.png +0 -0
  3. package/assets/phones/iPhone-14ProMax.png +0 -0
  4. package/assets/rednote-preview/cover/homebar-1439.jpg +0 -0
  5. package/assets/rednote-preview/cover/homebar-1679.jpg +0 -0
  6. package/assets/rednote-preview/cover/homebar-1919.jpg +0 -0
  7. package/assets/rednote-preview/cover/homebar-2284.jpg +0 -0
  8. package/assets/rednote-preview/cover/homebar-2285.jpg +0 -0
  9. package/assets/rednote-preview/cover/like.png +0 -0
  10. package/assets/rednote-preview/cover/play.png +0 -0
  11. package/assets/rednote-preview/cover/topbar-1439.jpg +0 -0
  12. package/assets/rednote-preview/cover/topbar-1679.jpg +0 -0
  13. package/assets/rednote-preview/cover/topbar-1919.jpg +0 -0
  14. package/assets/rednote-preview/cover/topbar-2284.jpg +0 -0
  15. package/assets/rednote-preview/cover/topbar-2285.jpg +0 -0
  16. package/assets/workbench/index.html +77 -0
  17. package/dist/sw/miniapp-simulator-service-worker.js +971 -0
  18. package/dist/sw/miniapp-simulator-service-worker.min.js +1 -0
  19. package/docs/consumer-guide.md +143 -0
  20. package/docs/electron-review.md +21 -0
  21. package/docs/external-cli-workbench.md +195 -0
  22. package/docs/file-system-design.md +334 -0
  23. package/docs/host-external-api.md +235 -0
  24. package/docs/iframe-service-worker.md +190 -0
  25. package/docs/local-dev.md +106 -0
  26. package/docs/npm-integration-verification.md +35 -0
  27. package/docs/remote-architecture.md +404 -0
  28. package/docs/remote-load-observability.md +268 -0
  29. package/docs/remote-usage.md +371 -0
  30. package/docs/request-design.md +247 -0
  31. package/docs/sdk-usage.md +260 -0
  32. package/docs/server-playground-https-debugging.md +150 -0
  33. package/docs/storage-api-design.md +275 -0
  34. package/docs/tracker.md +339 -0
  35. package/docs/worker-runtime.md +62 -0
  36. package/lib/business-line-CMb3ehRn.mjs +15 -0
  37. package/lib/client-CO-UjIY3.mjs +775 -0
  38. package/lib/index-B5oixYXr.mjs +574 -0
  39. package/lib/index.js +10763 -0
  40. package/lib/preload/webview-preload.js +37 -0
  41. package/lib/remote-client.js +11 -0
  42. package/lib/types/business-line.d.ts +7 -0
  43. package/lib/types/capabilities/constants.d.ts +29 -0
  44. package/lib/types/capabilities/csp-snippet.d.ts +34 -0
  45. package/lib/types/capabilities/launch-options.d.ts +7 -0
  46. package/lib/types/capabilities/performance-policy.d.ts +5 -0
  47. package/lib/types/capabilities/security-head-snippet.d.ts +21 -0
  48. package/lib/types/capabilities/security.d.ts +25 -0
  49. package/lib/types/capabilities/style-snippet.d.ts +2 -0
  50. package/lib/types/core/controllers/game-playtest.d.ts +9 -0
  51. package/lib/types/core/controllers/gesture.d.ts +8 -0
  52. package/lib/types/core/controllers/host-api.d.ts +19 -0
  53. package/lib/types/core/controllers/index.d.ts +11 -0
  54. package/lib/types/core/controllers/inspector.d.ts +20 -0
  55. package/lib/types/core/controllers/note-preview.d.ts +9 -0
  56. package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
  57. package/lib/types/core/controllers/widget-cover.d.ts +12 -0
  58. package/lib/types/core/lifecycle.d.ts +7 -0
  59. package/lib/types/core/options.d.ts +33 -0
  60. package/lib/types/core/simulator.d.ts +9 -0
  61. package/lib/types/errors.d.ts +11 -0
  62. package/lib/types/event-bus.d.ts +15 -0
  63. package/lib/types/gesture/host-bus.d.ts +113 -0
  64. package/lib/types/gesture/index.d.ts +27 -0
  65. package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
  66. package/lib/types/gesture/plugins/index.d.ts +27 -0
  67. package/lib/types/gesture/plugins/long-press.d.ts +13 -0
  68. package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
  69. package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
  70. package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
  71. package/lib/types/gesture/plugins/tap.d.ts +11 -0
  72. package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
  73. package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
  74. package/lib/types/gesture/receiver-runtime.d.ts +10 -0
  75. package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
  76. package/lib/types/gesture/touch-cursor.d.ts +78 -0
  77. package/lib/types/gesture/touch-dot.d.ts +12 -0
  78. package/lib/types/gesture/types.d.ts +206 -0
  79. package/lib/types/host/shadow-host.d.ts +40 -0
  80. package/lib/types/index.d.ts +56 -0
  81. package/lib/types/injection/guest-log-mark.d.ts +7 -0
  82. package/lib/types/injection/head-builder.d.ts +4 -0
  83. package/lib/types/injection/index.d.ts +19 -0
  84. package/lib/types/injection/modules/console-forward.d.ts +2 -0
  85. package/lib/types/injection/modules/gesture.d.ts +6 -0
  86. package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
  87. package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
  88. package/lib/types/injection/modules/inspector.d.ts +8 -0
  89. package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
  90. package/lib/types/injection/modules/jsapi.d.ts +22 -0
  91. package/lib/types/injection/modules/render-done.d.ts +2 -0
  92. package/lib/types/injection/modules/resource-guard.d.ts +7 -0
  93. package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
  94. package/lib/types/injection/modules/security.d.ts +3 -0
  95. package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
  96. package/lib/types/injection/preload-builder.d.ts +41 -0
  97. package/lib/types/injection/registry.d.ts +20 -0
  98. package/lib/types/injection/types.d.ts +45 -0
  99. package/lib/types/inspector/host-inspector.d.ts +108 -0
  100. package/lib/types/inspector/index.d.ts +8 -0
  101. package/lib/types/inspector/selector.d.ts +18 -0
  102. package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
  103. package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
  104. package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
  105. package/lib/types/native-ui/devtools/dom.d.ts +40 -0
  106. package/lib/types/native-ui/devtools/index.d.ts +19 -0
  107. package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
  108. package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
  109. package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
  110. package/lib/types/native-ui/devtools/types.d.ts +51 -0
  111. package/lib/types/native-ui/index.d.ts +17 -0
  112. package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
  113. package/lib/types/native-ui/note-publish/index.d.ts +2 -0
  114. package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
  115. package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
  116. package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
  117. package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
  118. package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
  119. package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
  120. package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
  121. package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
  122. package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
  123. package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
  124. package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
  125. package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
  126. package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
  127. package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
  128. package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
  129. package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
  130. package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
  131. package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
  132. package/lib/types/native-ui/toast/index.d.ts +19 -0
  133. package/lib/types/presets.d.ts +11 -0
  134. package/lib/types/remote/client.d.ts +89 -0
  135. package/lib/types/remote/jsapi-config.d.ts +9 -0
  136. package/lib/types/remote/load-timing.d.ts +46 -0
  137. package/lib/types/remote/protocol.d.ts +165 -0
  138. package/lib/types/remote/review-launch.d.ts +6 -0
  139. package/lib/types/remote/runtime-entry.d.ts +1 -0
  140. package/lib/types/remote/runtime.d.ts +14 -0
  141. package/lib/types/remote/simulator-prompt.d.ts +9 -0
  142. package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
  143. package/lib/types/remote-client.d.ts +5 -0
  144. package/lib/types/renderer/base.d.ts +8 -0
  145. package/lib/types/renderer/content-host/iframe-content-host.d.ts +84 -0
  146. package/lib/types/renderer/content-host/index.d.ts +3 -0
  147. package/lib/types/renderer/content-host/types.d.ts +89 -0
  148. package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
  149. package/lib/types/renderer/iframe.d.ts +93 -0
  150. package/lib/types/renderer/index.d.ts +2 -0
  151. package/lib/types/renderer/rednote-shell.d.ts +73 -0
  152. package/lib/types/renderer/webview.d.ts +59 -0
  153. package/lib/types/runtime/context.d.ts +31 -0
  154. package/lib/types/runtime/jsapi-modules/context.d.ts +19 -0
  155. package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
  156. package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
  157. package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
  158. package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
  159. package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
  160. package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
  161. package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
  162. package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
  163. package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
  164. package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
  165. package/lib/types/runtime/request/host-request.d.ts +13 -0
  166. package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
  167. package/lib/types/runtime/request/request-runtime.d.ts +26 -0
  168. package/lib/types/runtime/request/request-types.d.ts +26 -0
  169. package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
  170. package/lib/types/seal-config.d.ts +134 -0
  171. package/lib/types/sw/index.d.ts +9 -0
  172. package/lib/types/sw/parse-raw.d.ts +34 -0
  173. package/lib/types/sw/protocol.d.ts +19 -0
  174. package/lib/types/sw/served-entry.d.ts +9 -0
  175. package/lib/types/sw/service-worker-content-host.d.ts +11 -0
  176. package/lib/types/sw/service-worker-host.d.ts +74 -0
  177. package/lib/types/sw/service-worker-renderer.d.ts +10 -0
  178. package/lib/types/sw/worker/fs-codec.d.ts +23 -0
  179. package/lib/types/sw/worker/fs-ops.d.ts +22 -0
  180. package/lib/types/sw/worker/fs-store.d.ts +29 -0
  181. package/lib/types/sw/worker/globals.d.ts +50 -0
  182. package/lib/types/sw/worker/main.d.ts +6 -0
  183. package/lib/types/sw/worker/mime.d.ts +2 -0
  184. package/lib/types/sw/worker/mount-store.d.ts +48 -0
  185. package/lib/types/sw/worker/paths.d.ts +4 -0
  186. package/lib/types/sw/worker/serve.d.ts +13 -0
  187. package/lib/types/tracker/constants.d.ts +14 -0
  188. package/lib/types/tracker/default-tracker.d.ts +19 -0
  189. package/lib/types/tracker/index.d.ts +70 -0
  190. package/lib/types/transport/bridge-protocol.d.ts +78 -0
  191. package/lib/types/transport/iframe-transport.d.ts +39 -0
  192. package/lib/types/transport/index.d.ts +14 -0
  193. package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
  194. package/lib/types/transport/types.d.ts +48 -0
  195. package/lib/types/transport/webview-transport.d.ts +52 -0
  196. package/lib/types/types/events.d.ts +130 -0
  197. package/lib/types/types/index.d.ts +11 -0
  198. package/lib/types/types/inspector.d.ts +172 -0
  199. package/lib/types/types/jsapi.d.ts +18 -0
  200. package/lib/types/types/options.d.ts +851 -0
  201. package/lib/types/types/renderer.d.ts +145 -0
  202. package/lib/types/utils/ancestor-scroll.d.ts +11 -0
  203. package/lib/types/utils/error-svg.d.ts +12 -0
  204. package/lib/types/utils/frameless-shell.d.ts +114 -0
  205. package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
  206. package/lib/types/utils/package-constants.d.ts +8 -0
  207. package/lib/types/utils/screenshot.d.ts +14 -0
  208. package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
  209. package/lib/types/utils/stage-fit.d.ts +6 -0
  210. package/lib/types/utils/touch-emulate.d.ts +26 -0
  211. package/lib/types/utils/zip-entry.d.ts +13 -0
  212. package/lib/types/workbench/index.d.ts +63 -0
  213. package/lib/types/workbench/preview-transition.d.ts +8 -0
  214. package/lib/types/workbench/server/artifact.d.ts +8 -0
  215. package/lib/types/workbench/server/index.d.ts +19 -0
  216. package/lib/types/workbench/server/watch.d.ts +6 -0
  217. package/lib/types/workbench/view.d.ts +36 -0
  218. package/lib/types/worker/adapters/csp-policy.d.ts +7 -0
  219. package/lib/types/worker/adapters/host-lifecycle.d.ts +5 -0
  220. package/lib/types/worker/adapters/mount-recovery.d.ts +2 -0
  221. package/lib/types/worker/adapters/package-policy.d.ts +12 -0
  222. package/lib/types/worker/adapters/page-lifecycle.d.ts +1 -0
  223. package/lib/types/worker/adapters/protocol.d.ts +49 -0
  224. package/lib/types/worker/adapters/scripts.d.ts +2 -0
  225. package/lib/types/worker/adapters/service-worker.d.ts +2 -0
  226. package/lib/workbench-server.mjs +183 -0
  227. package/lib/workbench.js +1404 -0
  228. package/package.json +61 -4
  229. package/scripts/mock-cli-dev.mjs +52 -0
@@ -0,0 +1,59 @@
1
+ import { BridgeProtocol } from "../transport";
2
+ import type { GestureHostPluginLike, MiniAppSimulatorRoute, MiniAppViewport, NormalizedRednoteDetailSheetOptions, RendererAdapter, RendererAdapterContext, XhsNotePreviewData, XhsProfilePreviewData, XhsWidgetCoverData } from "../types";
3
+ import { BaseRendererAdapter } from "./base";
4
+ /**
5
+ * webview 渲染器:负责设备外壳布局(与 iframe 渲染器同构),通过 RednoteShellMount 挂载
6
+ * rednote 外壳、通过 WebviewContentHost 承载 Electron `<webview>` 载体。
7
+ *
8
+ * 与 iframe 渲染器的差异仅在「内容载体」:webview 为独立 webContents,额外支持
9
+ * setZoomFactor / DevTools / webContents id / 截屏。
10
+ */
11
+ export declare class WebviewRendererAdapter extends BaseRendererAdapter implements RendererAdapter {
12
+ private frame;
13
+ private overlay;
14
+ private container;
15
+ private contentRoot;
16
+ private rednoteShell;
17
+ private contentHost;
18
+ private currentUrl;
19
+ private desiredZoom;
20
+ private get transport();
21
+ bridge: BridgeProtocol | null;
22
+ private frameToastHost;
23
+ private detachFramelessShellWindowSync;
24
+ private viewport;
25
+ private detachContentPcGuard;
26
+ private readonly context;
27
+ private readonly forwardEmit;
28
+ constructor(context: RendererAdapterContext);
29
+ mount(container: HTMLElement): Promise<void>;
30
+ private setupGesture;
31
+ private attachFramelessShellIfNeeded;
32
+ private setupBridge;
33
+ load(url: string): Promise<void>;
34
+ reload(): Promise<void>;
35
+ unload(): void;
36
+ invokeGamePlaytest(method: "manifest" | "snapshot" | "act" | "step" | "reset" | "isAvailable", args?: unknown[]): Promise<unknown>;
37
+ syncRednotePreviewContext(notePreview: XhsNotePreviewData, rednoteDetail: NormalizedRednoteDetailSheetOptions): void;
38
+ syncProfilePreviewContext(profilePreview: XhsProfilePreviewData): void;
39
+ syncWidgetCoverContext(widgetCover: XhsWidgetCoverData): void;
40
+ setActivePage(page: Extract<MiniAppSimulatorRoute, "note" | "profile">): void;
41
+ openContent(sheetMode: "half" | "full"): void;
42
+ closeContent(): Promise<void>;
43
+ resize(viewport: MiniAppViewport): void;
44
+ setZoomFactor(factor: number): void;
45
+ setDevtools(open: boolean): void;
46
+ setGestureOverlayInteractionEnabled(enabled: boolean): void;
47
+ isDevtoolsOpen(): boolean;
48
+ getWebContentsId(): number | null;
49
+ capture(): Promise<Blob>;
50
+ showToast(text: string, options?: {
51
+ duration?: number;
52
+ }): void;
53
+ useGesturePlugin(plugin: GestureHostPluginLike): void;
54
+ removeGesturePlugin(name: string): boolean;
55
+ hasGesturePlugin(name: string): boolean;
56
+ listGesturePlugins(): string[];
57
+ destroy(): void;
58
+ private createMountTarget;
59
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 全局运行时 context —— 记录当前模拟器以何种 renderer / 运行环境工作,
3
+ * 方便宿主与包内各模块识别「web(iframe)」与「electron(webview)」两种模式。
4
+ *
5
+ * renderer 由模拟器入口显式传入(见 `createMiniAppSimulator({ renderer })`),
6
+ * 本模块只负责把它与探测到的运行环境一并存为可全局读取的快照,
7
+ * 并镜像到 `window.__MINIAPP_SIMULATOR_CONTEXT__` 供 DevTools / 宿主直接查看。
8
+ */
9
+ import type { MiniAppRendererType } from "../types";
10
+ /** 运行环境:浏览器 web 或 Electron 桌面端 */
11
+ export type SimulatorEnvironment = "web" | "electron";
12
+ export interface SimulatorRuntimeContext {
13
+ /** 当前激活的渲染器类型(由入口显式传入) */
14
+ renderer: MiniAppRendererType;
15
+ /** 探测到的运行环境 */
16
+ environment: SimulatorEnvironment;
17
+ }
18
+ /**
19
+ * 探测当前运行环境:
20
+ * - `window.process.versions.electron` 存在,或 UA 含 `Electron` → electron
21
+ * - 否则 → web
22
+ */
23
+ export declare function detectEnvironment(): SimulatorEnvironment;
24
+ /**
25
+ * 写入全局运行时 context(由 simulator 创建时调用),并镜像到 window。
26
+ */
27
+ export declare function setSimulatorContext(context: SimulatorRuntimeContext): void;
28
+ /**
29
+ * 读取当前全局运行时 context;尚未创建任何 simulator 时返回 null。
30
+ */
31
+ export declare function getSimulatorContext(): SimulatorRuntimeContext | null;
@@ -0,0 +1,19 @@
1
+ import type { NotePublishResult, NotePublishViewData } from "../../native-ui/note-publish";
2
+ import type { ServiceWorkerHostLike } from "../../sw";
3
+ import type { MiniAppViewport } from "../../types";
4
+ import type { RequestRuntime } from "../request/request-runtime";
5
+ /** Read-only live state shared by simulator JSAPI domain modules. */
6
+ export interface SimulatorJsapiContext {
7
+ readonly fileSystemHost: ServiceWorkerHostLike | null;
8
+ readonly fileSystemMountId: string | null;
9
+ readonly loadedUrl: string;
10
+ readonly appId: string | undefined;
11
+ readonly storageScope: string;
12
+ readonly userDataPath: string | undefined;
13
+ readonly gateways: Record<string, string> | undefined;
14
+ readonly businessLine: string | undefined;
15
+ readonly viewport: MiniAppViewport;
16
+ readonly requestRuntime: RequestRuntime;
17
+ readonly overlayRoot: ShadowRoot | HTMLElement;
18
+ showNotePublish(data: NotePublishViewData): Promise<NotePublishResult> | undefined;
19
+ }
@@ -0,0 +1,19 @@
1
+ import type { ServiceWorkerFileSystemArgs, ServiceWorkerFileSystemOperation } from "../../sw";
2
+ import { type MiniAppHostApiHandler } from "../../types";
3
+ import type { SimulatorJsapiContext } from "./context";
4
+ import type { SimulatorJsapiModule } from "./types";
5
+ export type SimulatorFileSystemContext = Pick<SimulatorJsapiContext, "fileSystemHost" | "fileSystemMountId" | "appId">;
6
+ export declare const FILESYSTEM_API_OPERATIONS: {
7
+ readonly saveFile: "fsSaveFile";
8
+ readonly writeFile: "fsWriteFile";
9
+ readonly appendFile: "fsAppendFile";
10
+ readonly readFile: "fsReadFile";
11
+ readonly readDir: "fsReadDir";
12
+ readonly statFile: "fsStatFile";
13
+ readonly unlink: "fsUnlink";
14
+ readonly mkdir: "fsMkdir";
15
+ readonly getFileStorageInfo: "fsGetStorageInfo";
16
+ };
17
+ export declare function createFilesystemJsapiModule(context: SimulatorFileSystemContext): SimulatorJsapiModule;
18
+ export declare function createFilesystemApiHandlers(invoke: (operation: ServiceWorkerFileSystemOperation, args: ServiceWorkerFileSystemArgs) => Promise<unknown>): Record<string, MiniAppHostApiHandler>;
19
+ export declare function invokeSimulatorFileSystem(context: SimulatorFileSystemContext, operation: ServiceWorkerFileSystemOperation, args: ServiceWorkerFileSystemArgs): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ export type { SimulatorJsapiContext } from "./context";
2
+ export { createFilesystemJsapiModule } from "./filesystem";
3
+ export { createInteractionJsapiModule } from "./interaction";
4
+ export { createLocationJsapiModule } from "./location";
5
+ export { createMediaJsapiModule } from "./media";
6
+ export { createNetworkJsapiModule } from "./network";
7
+ export { createSystemJsapiModule } from "./system";
8
+ export { createStorageJsapiModule } from "./storage";
9
+ export { registerSimulatorJsapiModules } from "./types";
@@ -0,0 +1,4 @@
1
+ import type { SimulatorJsapiContext } from "./context";
2
+ import type { SimulatorJsapiModule } from "./types";
3
+ export type InteractionJsapiModuleContext = Pick<SimulatorJsapiContext, "overlayRoot" | "showNotePublish">;
4
+ export declare function createInteractionJsapiModule(context: InteractionJsapiModuleContext): SimulatorJsapiModule;
@@ -0,0 +1,3 @@
1
+ import type { SimulatorJsapiModule } from "./types";
2
+ /** Browser-backed single-shot location APIs. */
3
+ export declare function createLocationJsapiModule(): SimulatorJsapiModule;
@@ -0,0 +1,13 @@
1
+ import { type MiniAppHostApiHandler } from "../../types";
2
+ import { type SimulatorFileSystemContext } from "./filesystem";
3
+ import type { SimulatorJsapiModule } from "./types";
4
+ /** The simulator state used by browser media APIs. */
5
+ export interface MediaJsapiModuleContext extends SimulatorFileSystemContext {
6
+ readonly loadedUrl: string;
7
+ readonly fetch?: typeof globalThis.fetch;
8
+ readonly download?: (blob: Blob, filename: string) => void;
9
+ }
10
+ /** Browser media APIs. */
11
+ export declare function createMediaJsapiModule(context: MediaJsapiModuleContext): SimulatorJsapiModule;
12
+ /** Simulates saving an image to the system album by downloading it from the browser. */
13
+ export declare function createSaveImageToPhotosAlbumHandler(context: MediaJsapiModuleContext): MiniAppHostApiHandler;
@@ -0,0 +1,3 @@
1
+ import type { SimulatorJsapiContext } from "./context";
2
+ import type { SimulatorJsapiModule } from "./types";
3
+ export declare function createNetworkJsapiModule(context: Pick<SimulatorJsapiContext, "requestRuntime">): SimulatorJsapiModule;
@@ -0,0 +1,26 @@
1
+ import { type MiniAppHostApiHandler } from "../../types";
2
+ import type { SimulatorJsapiContext } from "./context";
3
+ import type { SimulatorJsapiModule } from "./types";
4
+ export declare const STORAGE_LIMIT_BYTES: number;
5
+ export declare const STORAGE_ITEM_LIMIT_BYTES: number;
6
+ export interface SimulatorStorageRecord {
7
+ scope: string;
8
+ key: string;
9
+ data: unknown;
10
+ sizeBytes: number;
11
+ encrypted: boolean;
12
+ }
13
+ export interface SimulatorStorageRepository {
14
+ list(scope: string): Promise<SimulatorStorageRecord[]>;
15
+ get(scope: string, key: string): Promise<SimulatorStorageRecord | undefined>;
16
+ put(record: SimulatorStorageRecord): Promise<void>;
17
+ remove(scope: string, key: string): Promise<void>;
18
+ clear(scope: string): Promise<void>;
19
+ }
20
+ export interface SimulatorStorageApiOptions {
21
+ scope: string;
22
+ repository?: SimulatorStorageRepository;
23
+ }
24
+ export declare function createStorageJsapiModule(context: Pick<SimulatorJsapiContext, "storageScope">): SimulatorJsapiModule;
25
+ /** IndexedDB-backed simulator implementation of the Storage JSAPIs. */
26
+ export declare function createSimulatorStorageApi(options: SimulatorStorageApiOptions): Record<string, MiniAppHostApiHandler>;
@@ -0,0 +1,4 @@
1
+ import type { SimulatorJsapiContext } from "./context";
2
+ import type { SimulatorJsapiModule } from "./types";
3
+ export type SystemJsapiModuleContext = Pick<SimulatorJsapiContext, "appId" | "userDataPath" | "gateways" | "businessLine" | "viewport">;
4
+ export declare function createSystemJsapiModule(context: SystemJsapiModuleContext): SimulatorJsapiModule;
@@ -0,0 +1,21 @@
1
+ import type { BridgeHandler, BridgeProtocol } from "../../transport/bridge-protocol";
2
+ import type { MiniAppHostApiEntry } from "../../types";
3
+ export type HostOverridePolicy = "allow" | "function-only" | "forbid";
4
+ export interface SimulatorJsapiHandler {
5
+ handler: BridgeHandler;
6
+ hostOverride?: HostOverridePolicy;
7
+ }
8
+ /** A cohesive group of simulator-side JSAPI implementations. */
9
+ export interface SimulatorJsapiModule {
10
+ name: string;
11
+ handlers: Readonly<Record<string, SimulatorJsapiHandler>>;
12
+ }
13
+ export interface RegisterSimulatorJsapiModulesOptions {
14
+ hostApiMap: Record<string, MiniAppHostApiEntry>;
15
+ runHostEntry(entry: MiniAppHostApiEntry, request: Parameters<BridgeHandler>[0]): unknown;
16
+ }
17
+ /**
18
+ * Registers domain modules in one place and keeps the host override policy uniform.
19
+ * Modules may not claim the same event, preventing accidental implementation shadowing.
20
+ */
21
+ export declare function registerSimulatorJsapiModules(bridge: BridgeProtocol, modules: readonly SimulatorJsapiModule[], options: RegisterSimulatorJsapiModulesOptions): void;
@@ -0,0 +1,43 @@
1
+ /** The only viewport measurements required by the getWindowInfo bridge. */
2
+ interface SimulatorWindowInfoViewport {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ interface SimulatorWindowRect {
7
+ left: number;
8
+ top: number;
9
+ right: number;
10
+ bottom: number;
11
+ width: number;
12
+ height: number;
13
+ }
14
+ interface SimulatorWindowInfo {
15
+ pixelRatio: number;
16
+ screenWidth: number;
17
+ screenHeight: number;
18
+ windowWidth: number;
19
+ windowHeight: number;
20
+ statusBarHeight: number;
21
+ screenTop: number;
22
+ safeArea: SimulatorWindowRect;
23
+ gestureInsets: {
24
+ left: number;
25
+ right: number;
26
+ top: number;
27
+ bottom: number;
28
+ };
29
+ menuButtons: {
30
+ back: SimulatorWindowRect | null;
31
+ me: SimulatorWindowRect | null;
32
+ share: SimulatorWindowRect | null;
33
+ };
34
+ }
35
+ /**
36
+ * 构造模拟器侧 `getWindowInfo` 的只读窗口度量。
37
+ *
38
+ * 口径:视模拟器设备为「全屏容器」,宽高直接取逻辑视口;状态栏高复用外壳常量,
39
+ * 底部安全区减掉 home indicator;`menuButtons` 按全屏顶栏 chrome 映射(back/share,
40
+ * `me` 无对应按钮恒为 null);侧滑关闭热区只有顶部 grip/status-drag 一档。
41
+ */
42
+ export declare function buildSimulatorWindowInfo(viewport: SimulatorWindowInfoViewport): SimulatorWindowInfo;
43
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type MiniAppHostRequest } from "../../types";
2
+ import type { ManagedRequestChunk, ManagedRequestHeaders, ManagedRequestOptions, ManagedRequestResult } from "./request-types";
3
+ export interface HostRequestHooks {
4
+ signal: AbortSignal;
5
+ onHeaders(data: ManagedRequestHeaders): void;
6
+ onChunk(data: ManagedRequestChunk): void;
7
+ }
8
+ type ManagedHostRequestRunner = (options: ManagedRequestOptions, hooks: HostRequestHooks) => Promise<ManagedRequestResult>;
9
+ /** 仅供远程 Runtime 将宿主请求透传到外层页面。 */
10
+ export declare function createManagedHostRequest(runner: ManagedHostRequestRunner): MiniAppHostRequest;
11
+ /** 消费宿主已经适配为统一契约的响应,并生成 simulator 内部请求事件。 */
12
+ export declare function executeHostRequest(request: MiniAppHostRequest, options: ManagedRequestOptions, hooks: HostRequestHooks): Promise<ManagedRequestResult>;
13
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { ManagedRequestChunk, ManagedRequestHeaders, ManagedRequestOptions, ManagedRequestResult } from "./request-types";
2
+ export interface IsolatedRequestManagerOptions {
3
+ mount: HTMLElement;
4
+ frameUrl?: string;
5
+ onHeaders(data: ManagedRequestHeaders): void;
6
+ onChunk(data: ManagedRequestChunk): void;
7
+ }
8
+ /**
9
+ * 在独立 opaque-origin iframe 中执行公开 request。
10
+ *
11
+ * manager iframe 不带 `allow-same-origin`,且 fetch 固定 `credentials: "omit"`,因此不会
12
+ * 继承宿主 Cookie;它也不复用带严格 connect-src 的渲染 iframe。
13
+ */
14
+ export declare class IsolatedRequestManager {
15
+ private readonly iframe;
16
+ private readonly pending;
17
+ private readonly onHeaders;
18
+ private readonly onChunk;
19
+ private readyResolve;
20
+ private readonly ready;
21
+ private destroyed;
22
+ constructor(options: IsolatedRequestManagerOptions);
23
+ execute(options: ManagedRequestOptions): Promise<ManagedRequestResult>;
24
+ abort(taskId: string): boolean;
25
+ abortAll(): void;
26
+ destroy(): void;
27
+ private readonly handleMessage;
28
+ }
29
+ export declare function startIsolatedRequestManagerRuntime(): void;
@@ -0,0 +1,26 @@
1
+ import type { BridgeRequest } from "../../transport/bridge-protocol";
2
+ import { type MiniAppHostRequest } from "../../types";
3
+ import type { ManagedRequestOptions } from "./request-types";
4
+ export interface RequestRuntimeOptions {
5
+ mount: HTMLElement;
6
+ requestManagerFrameUrl?: string;
7
+ getHostRequest(): MiniAppHostRequest | undefined;
8
+ emit(method: "onHeadersReceivedRequest" | "onEventStream", payload: unknown): void;
9
+ }
10
+ /** request / xhsRequest / abortRequest 的模拟器侧执行层。 */
11
+ export declare class RequestRuntime {
12
+ private readonly options;
13
+ private isolatedRequest;
14
+ private readonly hostRequests;
15
+ constructor(options: RequestRuntimeOptions);
16
+ executePublic(req: BridgeRequest): Promise<unknown>;
17
+ executeInternal(req: BridgeRequest): Promise<unknown>;
18
+ abort(req: BridgeRequest): {
19
+ taskId: string;
20
+ };
21
+ abortAll(): void;
22
+ destroy(): void;
23
+ private getIsolatedRequest;
24
+ }
25
+ export declare function readTaskId(value: unknown): string;
26
+ export declare function readRequestOptions(req: BridgeRequest): ManagedRequestOptions;
@@ -0,0 +1,26 @@
1
+ export interface ManagedRequestOptions {
2
+ taskId: string;
3
+ url: string;
4
+ method: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS";
5
+ header?: Record<string, string>;
6
+ data?: unknown;
7
+ dataType: "json" | "text";
8
+ responseType: "text";
9
+ timeout: number;
10
+ enableChunked: boolean;
11
+ }
12
+ export interface ManagedRequestResult {
13
+ taskId: string;
14
+ statusCode: number;
15
+ data: unknown;
16
+ header: Record<string, string>;
17
+ }
18
+ export interface ManagedRequestHeaders {
19
+ taskId: string;
20
+ statusCode: number;
21
+ header: Record<string, string>;
22
+ }
23
+ export interface ManagedRequestChunk {
24
+ taskId: string;
25
+ chunk: string;
26
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 只负责 SSE 文本分帧,不解析 event/data/id/retry 字段。
3
+ *
4
+ * 网络层的 chunk 边界与 SSE 消息边界无关;这里缓存跨 chunk 的半帧,并在遇到
5
+ * 空行后返回包含原始换行符的完整 SSE 文本块。
6
+ */
7
+ export declare class SseTextFramer {
8
+ private buffer;
9
+ push(chunk: string): string[];
10
+ /** SSE 末尾没有空行时属于未完成帧,不向调用方发送。 */
11
+ finish(): string[];
12
+ private drain;
13
+ }
14
+ /** 可序列化进隔离 request manager 的无依赖 SSE 分帧器。 */
15
+ export declare function createSseTextFramer(): Pick<SseTextFramer, "push" | "finish">;
16
+ export declare function isEventStreamContentType(contentType: string | undefined | null): boolean;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * 设备能力封印(seal)的运行时配置:以「白名单 allow」语义控制哪些能力放开。
3
+ *
4
+ * 设计要点:
5
+ * - 跨端共用:同一份 IIFE 同时供 PC iframe / iOS WKWebView / Android WebView 注入;通过宿主在 IIFE 之前
6
+ * 写入 `window.__MINI_APP_SEAL_CONFIG__ = { allow: [...] }` 传配置。
7
+ * - 字符串字面量值:避免 TS enum 的 runtime 体积;同时让 Swift / Java 可直接使用相同字符串。
8
+ * - **职责边界**:
9
+ * - `Camera` / `Microphone` / `PhotoLibrary` 不属于 seal 直接 forbid 范畴
10
+ * (getUserMedia 与 input[type=file] 由宿主层 iframe.allow / WKWebView 权限控制);
11
+ * 枚举中保留它们,是为了让 Permissions API stub 与 host 配置在同一份「业务声明」中表达。
12
+ * - 其余项与 `seal-runtime/{API}-forbid.ts` 一一对应。
13
+ *
14
+ * 注:本文件由 `@skillbuilder/miniapp-simulator` 自维护(源自 `@skillbuilder/miniapp-secure-runtime`)。
15
+ */
16
+ /** 业务能力枚举(字符串字面量值)。 */
17
+ export declare const MiniAppCapability: {
18
+ /** 相机:getUserMedia({ video: true });seal 不直接拦截,由宿主层控制。 */
19
+ readonly Camera: "camera";
20
+ /** 麦克风:getUserMedia({ audio: true });seal 不直接拦截,由宿主层控制。 */
21
+ readonly Microphone: "microphone";
22
+ /** 相册 / 文件选择:input[type=file];seal 不直接拦截,由 sandbox 与 host 配置控制。 */
23
+ readonly PhotoLibrary: "photo-library";
24
+ /** 定位:navigator.geolocation。 */
25
+ readonly Geolocation: "geolocation";
26
+ /** 剪贴板:navigator.clipboard + execCommand copy/cut/paste。 */
27
+ readonly Clipboard: "clipboard";
28
+ /** 蓝牙:navigator.bluetooth。 */
29
+ readonly Bluetooth: "bluetooth";
30
+ /** USB:navigator.usb。 */
31
+ readonly Usb: "usb";
32
+ /** HID:navigator.hid。 */
33
+ readonly Hid: "hid";
34
+ /** 串口:navigator.serial。 */
35
+ readonly Serial: "serial";
36
+ /** Generic Sensor 构造器:Accelerometer / Gyroscope / Magnetometer 等。 */
37
+ readonly GenericSensor: "generic-sensor";
38
+ /** 设备运动:DeviceMotionEvent + addEventListener('devicemotion')。 */
39
+ readonly DeviceMotion: "device-motion";
40
+ /** 设备方向:DeviceOrientationEvent + addEventListener('deviceorientation'/'deviceorientationabsolute')。 */
41
+ readonly DeviceOrientation: "device-orientation";
42
+ /** WebRTC 直连:RTCPeerConnection / RTCDataChannel。 */
43
+ readonly Webrtc: "webrtc";
44
+ /** 屏幕共享:mediaDevices.getDisplayMedia。 */
45
+ readonly ScreenShare: "screen-share";
46
+ /** 媒体设备枚举:mediaDevices.enumerateDevices。 */
47
+ readonly MediaDeviceEnumeration: "media-device-enumeration";
48
+ /** 电池:navigator.getBattery。 */
49
+ readonly Battery: "battery";
50
+ /** 网络信息:navigator.connection。 */
51
+ readonly Connection: "connection";
52
+ /** 持久化存储:navigator.storage.persist。 */
53
+ readonly PersistentStorage: "persistent-storage";
54
+ /** 跨域存储访问:document.requestStorageAccess。 */
55
+ readonly StorageAccess: "storage-access";
56
+ /** 凭据 / WebAuthn:navigator.credentials。 */
57
+ readonly Credentials: "credentials";
58
+ /** Web Locks:navigator.locks。 */
59
+ readonly Locks: "locks";
60
+ /** 全屏:Element.requestFullscreen 及前缀实现。 */
61
+ readonly Fullscreen: "fullscreen";
62
+ /** input[capture] 直调相机:DOM 扫除 + MutationObserver。 */
63
+ readonly InputCapture: "input-capture";
64
+ /** 弹出新窗口:window.open。 */
65
+ readonly WindowOpen: "window-open";
66
+ /** 系统输入对话框:window.prompt。 */
67
+ readonly WindowPrompt: "window-prompt";
68
+ };
69
+ export type MiniAppCapability = (typeof MiniAppCapability)[keyof typeof MiniAppCapability];
70
+ /** 宿主向 seal IIFE 传配置用的全局变量名;必须在 IIFE 之前赋值。 */
71
+ export declare const SEAL_CONFIG_GLOBAL_KEY = "__MINI_APP_SEAL_CONFIG__";
72
+ export interface SealRuntimeConfig {
73
+ /**
74
+ * 显式放开的能力列表(白名单)。未列出的能力按 seal 默认策略禁用。
75
+ * 不传 / 不是数组时,使用 {@link DEFAULT_ALLOW}(保持现行默认:放行 camera / microphone / photo-library)。
76
+ */
77
+ allow?: ReadonlyArray<MiniAppCapability>;
78
+ }
79
+ /**
80
+ * 默认放行的能力 —— 与现行 seal-runtime 行为对齐:
81
+ * 不主动拦截 getUserMedia 与 input[type=file],其余 §3 项全部封印。
82
+ */
83
+ export declare const DEFAULT_ALLOW: ReadonlyArray<MiniAppCapability>;
84
+ /**
85
+ * 从全局读取宿主注入的 seal 配置。
86
+ *
87
+ * @returns 一个 Set,宿主未配置或配置非法时退化为 {@link DEFAULT_ALLOW}。
88
+ */
89
+ export declare function readSealConfig(): {
90
+ allow: Set<MiniAppCapability>;
91
+ };
92
+ /**
93
+ * Permissions API 名称 → 业务 capability 的映射(仅可映射部分;
94
+ * 不在表中的 permission name 永久 denied,例如 push、notifications 等)。
95
+ */
96
+ export declare const PERMISSION_TO_CAPABILITY: Readonly<Record<string, MiniAppCapability>>;
97
+ /** 永远拒绝的 permission name(不论 allow 怎样,业务无入口拿到这些能力)。 */
98
+ export declare const ALWAYS_DENIED_PERMISSIONS: ReadonlyArray<string>;
99
+ /**
100
+ * 能力的受控方:
101
+ * - `seal`:由本包 IIFE 直接拦截,受 `allow` 白名单控制(不在 allow → 被封印)。
102
+ * - `host`:seal 不直接拦截,由宿主层控制(PC iframe `allow` / WKWebView 权限 / Android 权限 / sandbox)。
103
+ * 枚举中保留 host 能力,是为了让宿主配置与 Permissions API stub 在同一份「业务声明」里表达。
104
+ */
105
+ export type MiniAppCapabilityControlledBy = "seal" | "host";
106
+ /** 单个能力的对外元数据描述。 */
107
+ export interface MiniAppCapabilityDescriptor {
108
+ /** 枚举值(与 {@link MiniAppCapability} 的字符串字面量一致)。 */
109
+ value: MiniAppCapability;
110
+ /** 受控方,决定 `allow` 是否真正影响该能力。 */
111
+ controlledBy: MiniAppCapabilityControlledBy;
112
+ /** 人类可读说明(对应底层 Web API)。 */
113
+ description: string;
114
+ /** 关联的 Permissions API name(无则为空数组)。 */
115
+ permissionNames: ReadonlyArray<string>;
116
+ }
117
+ /**
118
+ * 全量能力元数据表 —— 「支持的能力」唯一事实源。
119
+ * 顺序与 README 能力表保持一致,便于 UI / 文档直接枚举渲染。
120
+ */
121
+ export declare const MINI_APP_CAPABILITIES: ReadonlyArray<MiniAppCapabilityDescriptor>;
122
+ /** 全量能力枚举值列表(顺序同 {@link MINI_APP_CAPABILITIES})。 */
123
+ export declare const ALL_MINI_APP_CAPABILITIES: ReadonlyArray<MiniAppCapability>;
124
+ /** seal IIFE 直接拦截、受 `allow` 控制的能力(白名单实际生效范围)。 */
125
+ export declare const SEAL_CONTROLLED_CAPABILITIES: ReadonlyArray<MiniAppCapability>;
126
+ /** 由宿主层(iframe.allow / WKWebView / sandbox)控制、seal 不直接拦截的能力。 */
127
+ export declare const HOST_CONTROLLED_CAPABILITIES: ReadonlyArray<MiniAppCapability>;
128
+ /** 判断任意值是否为合法的 {@link MiniAppCapability} 枚举取值。 */
129
+ export declare function isMiniAppCapability(value: unknown): value is MiniAppCapability;
130
+ /**
131
+ * 清洗外部传入的 allow 列表:剔除非枚举项并去重,得到稳定可用的白名单。
132
+ * 用于宿主把「可能不可信 / 含历史拼写」的配置归一化后再交给 IIFE / snippet。
133
+ */
134
+ export declare function sanitizeCapabilityList(input: ReadonlyArray<unknown> | null | undefined): MiniAppCapability[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * SW 渲染方式(`renderer: "iframe-service-worker"`)子系统入口。
3
+ */
4
+ export { ServiceWorkerHost, type ServiceWorkerHostLike, type ServiceWorkerMountInput, isServiceWorkerHostSupported, } from "./service-worker-host";
5
+ export type { ServiceWorkerFileSystemArgs, ServiceWorkerFileSystemOperation } from "./protocol";
6
+ export { parseRawZip, parseRawFiles, type RawParseResult } from "./parse-raw";
7
+ export { buildSwInjectionPayload, type SwInjectionPayload } from "./served-entry";
8
+ export { ServiceWorkerContentHost } from "./service-worker-content-host";
9
+ export { ServiceWorkerRendererAdapter } from "./service-worker-renderer";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * SW 模式原始解压 —— 把 zip / 文件表解析为原始文件表(路径 → 原始字节 + 入口 HTML),
3
+ * 供 Service Worker 当虚拟服务器按真实路径直供,相对路径 / ESM / fetch 原生可用。
4
+ *
5
+ * `loadZip` / `loadFiles` 的包解析入口。
6
+ */
7
+ import type { MiniAppFileMap, MiniAppLoadZipJsZip, MiniAppLoadZipSource, MiniAppPackageLimits } from "../types";
8
+ export declare const DEFAULT_MINIAPP_PACKAGE_LIMITS: MiniAppPackageLimits;
9
+ export interface RawParseResult {
10
+ /** 入口文件包内路径(已归一化)。 */
11
+ entryPath: string;
12
+ /** 入口 HTML 原始文本(尚未注入 head)。 */
13
+ entryHtml: string;
14
+ /** 除入口外的全部文件:路径 → 原始字节(可 transfer 给 SW)。 */
15
+ rawFiles: Record<string, ArrayBuffer>;
16
+ /** 文件清单(供 loadZip/loadFiles meta 复用)。 */
17
+ files: Array<{
18
+ path: string;
19
+ size: number;
20
+ }>;
21
+ }
22
+ type PackageLimitInput = Partial<MiniAppPackageLimits> | false | undefined;
23
+ /** 解析 zip → 原始文件表(SW 模式)。 */
24
+ export declare function parseRawZip(source: MiniAppLoadZipSource, options?: {
25
+ jszip?: MiniAppLoadZipJsZip;
26
+ entry?: string;
27
+ limits?: PackageLimitInput;
28
+ }): Promise<RawParseResult>;
29
+ /** 解析「目录文件表」→ 原始文件表(SW 模式)。 */
30
+ export declare function parseRawFiles(fileMap: MiniAppFileMap, options?: {
31
+ entry?: string;
32
+ limits?: PackageLimitInput;
33
+ }): RawParseResult;
34
+ export {};
@@ -0,0 +1,19 @@
1
+ /** Runtime 与 Service Worker 随同一 release 发布,协议版本必须精确一致。 */
2
+ export declare const SERVICE_WORKER_PROTOCOL_VERSION = 5;
3
+ /** 资源 SW 重启后,向持有包快照的可信宿主请求恢复 Worker 挂载。 */
4
+ export declare const SW_WORKER_MOUNT_RECOVERY = "miniapp:restore-worker-mount";
5
+ /** 当前 Service Worker 提供的文件系统操作。 */
6
+ export declare const SW_FS_OPS: readonly ["fsWriteTempFile", "fsSaveFile", "fsWriteFile", "fsAppendFile", "fsReadFile", "fsReadDir", "fsStatFile", "fsUnlink", "fsMkdir", "fsGetStorageInfo"];
7
+ export type ServiceWorkerFileSystemOperation = (typeof SW_FS_OPS)[number];
8
+ export interface ServiceWorkerFileSystemArgs {
9
+ fsScope?: string;
10
+ tempFilePath?: unknown;
11
+ filePath?: unknown;
12
+ dirPath?: unknown;
13
+ data?: unknown;
14
+ mime?: unknown;
15
+ encoding?: unknown;
16
+ position?: unknown;
17
+ length?: unknown;
18
+ recursive?: unknown;
19
+ }
@@ -0,0 +1,9 @@
1
+ import type { InjectionRegistry } from "../injection/registry";
2
+ import type { NormalizedMiniAppSimulatorOptions } from "../types";
3
+ export interface SwInjectionPayload {
4
+ /** 注入到 `<head>` 的片段(meta + `<style>` + 带 nonce 的 `<script>`)。 */
5
+ head: string;
6
+ /** SW 响应头下发的 CSP。 */
7
+ csp: string;
8
+ }
9
+ export declare function buildSwInjectionPayload(options: NormalizedMiniAppSimulatorOptions, injection: InjectionRegistry, appUrl: string, rawHtml: string, extraOrigins?: string[], frameAncestors?: string[], userDataPath?: string, gateways?: Record<string, string>, businessLine?: string, workerGuard?: import("../worker/adapters/protocol").WorkerGuardConfig): Promise<SwInjectionPayload>;
@@ -0,0 +1,11 @@
1
+ import { IframeContentHost } from "../renderer/content-host/iframe-content-host";
2
+ /**
3
+ * SW 模式 iframe 载体:复用 IframeContentHost 的全部能力(gesture / inspector /
4
+ * transport / onload→markReady),仅一处差异:
5
+ *
6
+ * SW 直供的「同源虚拟 URL」在 load 前先恢复 SW 注册与内存挂载(壳层收起后再唤起场景),
7
+ * 其余加载逻辑(`iframe.src = 虚拟URL`)复用父类。head 注入已由 SW 在响应中完成。
8
+ */
9
+ export declare class ServiceWorkerContentHost extends IframeContentHost {
10
+ load(url: string): Promise<void>;
11
+ }