@skillbuilder/miniapp-simulator 0.0.0-stage → 0.2.1
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/README.md +263 -2
- package/assets/phones/Nexus-5X.png +0 -0
- package/assets/phones/iPhone-14ProMax.png +0 -0
- package/assets/rednote-preview/cover/homebar-1439.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-1679.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-1919.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-2284.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-2285.jpg +0 -0
- package/assets/rednote-preview/cover/like.png +0 -0
- package/assets/rednote-preview/cover/play.png +0 -0
- package/assets/rednote-preview/cover/topbar-1439.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-1679.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-1919.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-2284.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-2285.jpg +0 -0
- package/assets/workbench/index.html +77 -0
- package/dist/sw/miniapp-simulator-service-worker.js +971 -0
- package/dist/sw/miniapp-simulator-service-worker.min.js +1 -0
- package/docs/consumer-guide.md +143 -0
- package/docs/electron-review.md +21 -0
- package/docs/external-cli-workbench.md +195 -0
- package/docs/file-system-design.md +334 -0
- package/docs/host-external-api.md +235 -0
- package/docs/iframe-service-worker.md +190 -0
- package/docs/local-dev.md +106 -0
- package/docs/npm-integration-verification.md +35 -0
- package/docs/remote-architecture.md +408 -0
- package/docs/remote-load-observability.md +268 -0
- package/docs/remote-usage.md +376 -0
- package/docs/request-design.md +247 -0
- package/docs/sdk-usage.md +260 -0
- package/docs/server-playground-https-debugging.md +150 -0
- package/docs/storage-api-design.md +275 -0
- package/docs/tracker.md +339 -0
- package/docs/worker-runtime.md +62 -0
- package/lib/client-BlQ9j4FW.mjs +775 -0
- package/lib/index-DI2oETZ_.mjs +574 -0
- package/lib/index.js +10831 -0
- package/lib/options-B34ipLmF.mjs +15 -0
- package/lib/preload/webview-preload.js +37 -0
- package/lib/remote-client.js +11 -0
- package/lib/types/business-line.d.ts +7 -0
- package/lib/types/capabilities/constants.d.ts +29 -0
- package/lib/types/capabilities/csp-snippet.d.ts +34 -0
- package/lib/types/capabilities/launch-options.d.ts +7 -0
- package/lib/types/capabilities/performance-policy.d.ts +5 -0
- package/lib/types/capabilities/security-head-snippet.d.ts +21 -0
- package/lib/types/capabilities/security.d.ts +25 -0
- package/lib/types/capabilities/style-snippet.d.ts +2 -0
- package/lib/types/core/controllers/game-playtest.d.ts +9 -0
- package/lib/types/core/controllers/gesture.d.ts +8 -0
- package/lib/types/core/controllers/host-api.d.ts +19 -0
- package/lib/types/core/controllers/index.d.ts +11 -0
- package/lib/types/core/controllers/inspector.d.ts +20 -0
- package/lib/types/core/controllers/note-preview.d.ts +9 -0
- package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
- package/lib/types/core/controllers/widget-cover.d.ts +12 -0
- package/lib/types/core/lifecycle.d.ts +7 -0
- package/lib/types/core/options.d.ts +33 -0
- package/lib/types/core/simulator.d.ts +9 -0
- package/lib/types/errors.d.ts +11 -0
- package/lib/types/event-bus.d.ts +15 -0
- package/lib/types/gesture/host-bus.d.ts +113 -0
- package/lib/types/gesture/index.d.ts +27 -0
- package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
- package/lib/types/gesture/plugins/index.d.ts +27 -0
- package/lib/types/gesture/plugins/long-press.d.ts +13 -0
- package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
- package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
- package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
- package/lib/types/gesture/plugins/tap.d.ts +11 -0
- package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
- package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
- package/lib/types/gesture/receiver-runtime.d.ts +10 -0
- package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
- package/lib/types/gesture/touch-cursor.d.ts +78 -0
- package/lib/types/gesture/touch-dot.d.ts +12 -0
- package/lib/types/gesture/types.d.ts +206 -0
- package/lib/types/host/shadow-host.d.ts +40 -0
- package/lib/types/index.d.ts +56 -0
- package/lib/types/injection/guest-log-mark.d.ts +7 -0
- package/lib/types/injection/head-builder.d.ts +4 -0
- package/lib/types/injection/index.d.ts +19 -0
- package/lib/types/injection/modules/console-forward.d.ts +2 -0
- package/lib/types/injection/modules/gesture.d.ts +6 -0
- package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
- package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
- package/lib/types/injection/modules/inspector.d.ts +8 -0
- package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
- package/lib/types/injection/modules/jsapi.d.ts +22 -0
- package/lib/types/injection/modules/render-done.d.ts +2 -0
- package/lib/types/injection/modules/resource-guard.d.ts +7 -0
- package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
- package/lib/types/injection/modules/security.d.ts +3 -0
- package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
- package/lib/types/injection/preload-builder.d.ts +41 -0
- package/lib/types/injection/registry.d.ts +20 -0
- package/lib/types/injection/types.d.ts +45 -0
- package/lib/types/inspector/host-inspector.d.ts +108 -0
- package/lib/types/inspector/index.d.ts +8 -0
- package/lib/types/inspector/selector.d.ts +18 -0
- package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
- package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
- package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
- package/lib/types/native-ui/devtools/dom.d.ts +40 -0
- package/lib/types/native-ui/devtools/index.d.ts +19 -0
- package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
- package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
- package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
- package/lib/types/native-ui/devtools/types.d.ts +51 -0
- package/lib/types/native-ui/index.d.ts +17 -0
- package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
- package/lib/types/native-ui/note-publish/index.d.ts +2 -0
- package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
- package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
- package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
- package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
- package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
- package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
- package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
- package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
- package/lib/types/native-ui/phone-vibration.d.ts +10 -0
- package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
- package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
- package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
- package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
- package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
- package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
- package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
- package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
- package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
- package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
- package/lib/types/native-ui/toast/index.d.ts +19 -0
- package/lib/types/presets.d.ts +11 -0
- package/lib/types/remote/client.d.ts +89 -0
- package/lib/types/remote/jsapi-config.d.ts +9 -0
- package/lib/types/remote/load-timing.d.ts +46 -0
- package/lib/types/remote/protocol.d.ts +165 -0
- package/lib/types/remote/review-launch.d.ts +6 -0
- package/lib/types/remote/runtime-entry.d.ts +1 -0
- package/lib/types/remote/runtime.d.ts +14 -0
- package/lib/types/remote/simulator-prompt.d.ts +9 -0
- package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
- package/lib/types/remote-client.d.ts +5 -0
- package/lib/types/renderer/base.d.ts +8 -0
- package/lib/types/renderer/content-host/iframe-content-host.d.ts +84 -0
- package/lib/types/renderer/content-host/index.d.ts +3 -0
- package/lib/types/renderer/content-host/types.d.ts +89 -0
- package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
- package/lib/types/renderer/iframe.d.ts +93 -0
- package/lib/types/renderer/index.d.ts +2 -0
- package/lib/types/renderer/rednote-shell.d.ts +73 -0
- package/lib/types/renderer/webview.d.ts +59 -0
- package/lib/types/runtime/context.d.ts +31 -0
- package/lib/types/runtime/jsapi-alert.d.ts +3 -0
- package/lib/types/runtime/jsapi-modules/context.d.ts +21 -0
- package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
- package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
- package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
- package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
- package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
- package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
- package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
- package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
- package/lib/types/runtime/request/host-request.d.ts +13 -0
- package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
- package/lib/types/runtime/request/request-runtime.d.ts +26 -0
- package/lib/types/runtime/request/request-types.d.ts +26 -0
- package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
- package/lib/types/seal-config.d.ts +134 -0
- package/lib/types/sw/index.d.ts +9 -0
- package/lib/types/sw/parse-raw.d.ts +34 -0
- package/lib/types/sw/protocol.d.ts +19 -0
- package/lib/types/sw/served-entry.d.ts +9 -0
- package/lib/types/sw/service-worker-content-host.d.ts +11 -0
- package/lib/types/sw/service-worker-host.d.ts +74 -0
- package/lib/types/sw/service-worker-renderer.d.ts +10 -0
- package/lib/types/sw/worker/fs-codec.d.ts +23 -0
- package/lib/types/sw/worker/fs-ops.d.ts +22 -0
- package/lib/types/sw/worker/fs-store.d.ts +29 -0
- package/lib/types/sw/worker/globals.d.ts +50 -0
- package/lib/types/sw/worker/main.d.ts +6 -0
- package/lib/types/sw/worker/mime.d.ts +2 -0
- package/lib/types/sw/worker/mount-store.d.ts +48 -0
- package/lib/types/sw/worker/paths.d.ts +4 -0
- package/lib/types/sw/worker/serve.d.ts +13 -0
- package/lib/types/tracker/constants.d.ts +14 -0
- package/lib/types/tracker/default-tracker.d.ts +19 -0
- package/lib/types/tracker/index.d.ts +70 -0
- package/lib/types/transport/bridge-protocol.d.ts +78 -0
- package/lib/types/transport/iframe-transport.d.ts +39 -0
- package/lib/types/transport/index.d.ts +14 -0
- package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
- package/lib/types/transport/types.d.ts +48 -0
- package/lib/types/transport/webview-transport.d.ts +52 -0
- package/lib/types/types/events.d.ts +130 -0
- package/lib/types/types/index.d.ts +11 -0
- package/lib/types/types/inspector.d.ts +172 -0
- package/lib/types/types/jsapi.d.ts +18 -0
- package/lib/types/types/options.d.ts +851 -0
- package/lib/types/types/renderer.d.ts +145 -0
- package/lib/types/utils/ancestor-scroll.d.ts +11 -0
- package/lib/types/utils/error-svg.d.ts +12 -0
- package/lib/types/utils/frameless-shell.d.ts +114 -0
- package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
- package/lib/types/utils/package-constants.d.ts +8 -0
- package/lib/types/utils/screenshot.d.ts +14 -0
- package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
- package/lib/types/utils/stage-fit.d.ts +6 -0
- package/lib/types/utils/touch-emulate.d.ts +26 -0
- package/lib/types/utils/zip-entry.d.ts +13 -0
- package/lib/types/workbench/index.d.ts +63 -0
- package/lib/types/workbench/preview-transition.d.ts +8 -0
- package/lib/types/workbench/server/artifact.d.ts +8 -0
- package/lib/types/workbench/server/index.d.ts +19 -0
- package/lib/types/workbench/server/watch.d.ts +6 -0
- package/lib/types/workbench/view.d.ts +36 -0
- package/lib/types/worker/adapters/csp-policy.d.ts +7 -0
- package/lib/types/worker/adapters/host-lifecycle.d.ts +5 -0
- package/lib/types/worker/adapters/mount-recovery.d.ts +2 -0
- package/lib/types/worker/adapters/package-policy.d.ts +12 -0
- package/lib/types/worker/adapters/page-lifecycle.d.ts +1 -0
- package/lib/types/worker/adapters/protocol.d.ts +49 -0
- package/lib/types/worker/adapters/scripts.d.ts +2 -0
- package/lib/types/worker/adapters/service-worker.d.ts +2 -0
- package/lib/workbench-server.mjs +183 -0
- package/lib/workbench.js +1404 -0
- package/package.json +61 -4
- package/scripts/mock-cli-dev.mjs +52 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Transport, TransportMessage } from "./types";
|
|
2
|
+
/** webview / preload 之间约定的 IPC 通道名 */
|
|
3
|
+
export declare const WEBVIEW_IPC_CHANNEL: "mas:msg";
|
|
4
|
+
/**
|
|
5
|
+
* WebviewTransport —— electron `<webview>` 介质的 Transport 实现。
|
|
6
|
+
*
|
|
7
|
+
* 数据流:
|
|
8
|
+
* 宿主(renderer 进程) → 小应用:
|
|
9
|
+
* webviewEl.send('mas:msg', message)
|
|
10
|
+
* → preload 收到后 dispatch 到 window
|
|
11
|
+
*
|
|
12
|
+
* 小应用 → 宿主(renderer 进程):
|
|
13
|
+
* 小应用执行 `window.postMessage(message, '*')`
|
|
14
|
+
* → preload 监听 window.message → `ipcRenderer.sendToHost('mas:msg', message)`
|
|
15
|
+
* → 当前类的 `ipc-message` 监听
|
|
16
|
+
*
|
|
17
|
+
* preload 脚本由 Step 5 的 `injection/preload-builder.ts` 产出,
|
|
18
|
+
* 当前阶段(Step 2)此类仅维护通道协议,与 preload 联调待 Step 5。
|
|
19
|
+
*/
|
|
20
|
+
export declare class WebviewTransport implements Transport {
|
|
21
|
+
readonly ready: Promise<void>;
|
|
22
|
+
private readyResolve;
|
|
23
|
+
private webview;
|
|
24
|
+
private readonly handlers;
|
|
25
|
+
private destroyed;
|
|
26
|
+
/**
|
|
27
|
+
* dom-ready 之前 `webview.send` 会抛 "The WebView must be attached to the DOM
|
|
28
|
+
* and the dom-ready event emitted..."。按 Transport 契约(types.ts),ready 前的
|
|
29
|
+
* post 缓冲到通道就绪后统一 flush,避免 gesture plugin 在 install 阶段(mount 期、
|
|
30
|
+
* 尚未 dom-ready)同步 send 直接抛错,阻断整个 load()。
|
|
31
|
+
*/
|
|
32
|
+
private isReady;
|
|
33
|
+
private readonly pending;
|
|
34
|
+
constructor();
|
|
35
|
+
/**
|
|
36
|
+
* 将 Transport 绑定到目标 webview 元素,并监听 ipc-message / dom-ready。
|
|
37
|
+
*/
|
|
38
|
+
attach(element: HTMLElement): void;
|
|
39
|
+
/**
|
|
40
|
+
* 兜底入口:宿主可显式触发 ready(例如基于 did-finish-load 而非 dom-ready)。
|
|
41
|
+
* 重复调用幂等。
|
|
42
|
+
*/
|
|
43
|
+
markReady(): void;
|
|
44
|
+
post(message: TransportMessage): void;
|
|
45
|
+
private sendNow;
|
|
46
|
+
/** 通道就绪:flush 缓冲队列并 resolve ready(dom-ready 事件或宿主显式触发) */
|
|
47
|
+
private markChannelReady;
|
|
48
|
+
onMessage(handler: (msg: TransportMessage) => void): () => void;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
private readonly handleDomReady;
|
|
51
|
+
private readonly handleIpcMessage;
|
|
52
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { ElementSelection, MiniAppElementSelectionChangeEvent, MiniAppInspectorChangeEvent, MiniAppVisualSelectionChangeEvent, VisualSelection } from "./inspector";
|
|
2
|
+
import type { MiniAppContentMode, MiniAppRendererType, MiniAppScreenShotResult, MiniAppSimulatorRoute, MiniAppViewport } from "./options";
|
|
3
|
+
/**
|
|
4
|
+
* 事件类型(原 types.ts 段落 2)。
|
|
5
|
+
*/
|
|
6
|
+
export type MiniAppEventName = "ready" | "beforeLoad" | "load" | "renderDone" | "error" | "navigation" | "console" | "guestError" | "network" | "performance" | "capture" | "destroy" | "routerChange" | "screenShot" | "elementHovered" | "elementSelected" | "elementSelectionChange" | "visualHovered" | "visualSelected" | "visualSelectionChange" | "inspectorChange";
|
|
7
|
+
export interface MiniAppReadyEvent {
|
|
8
|
+
renderer: MiniAppRendererType;
|
|
9
|
+
viewport: MiniAppViewport;
|
|
10
|
+
}
|
|
11
|
+
export interface MiniAppBeforeLoadEvent {
|
|
12
|
+
/** 即将加载的最终 URL(half / fullscreen 占位时为空串) */
|
|
13
|
+
url: string;
|
|
14
|
+
contentMode: MiniAppContentMode;
|
|
15
|
+
/** 触发来源:load / reload / switch-mode / switch-frame / load-app / load-zip / load-files 等 */
|
|
16
|
+
source: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MiniAppLoadEvent {
|
|
19
|
+
url: string;
|
|
20
|
+
duration: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MiniAppRenderDoneEvent {
|
|
23
|
+
/** 完成首屏渲染的 URL */
|
|
24
|
+
url: string;
|
|
25
|
+
/** 从加载开始到首帧渲染完毕的耗时(ms) */
|
|
26
|
+
duration: number;
|
|
27
|
+
}
|
|
28
|
+
export interface MiniAppErrorEvent {
|
|
29
|
+
code: MiniAppErrorCode;
|
|
30
|
+
message: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
cause?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface MiniAppNavigationEvent {
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
blocked: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface MiniAppConsoleEvent {
|
|
40
|
+
level: "debug" | "info" | "warn" | "error" | "log";
|
|
41
|
+
message: string;
|
|
42
|
+
/** 来源:`sdk`(框架注入脚本)/ `user`(业务代码) */
|
|
43
|
+
source: "sdk" | "user";
|
|
44
|
+
args?: unknown[];
|
|
45
|
+
}
|
|
46
|
+
export interface MiniAppGuestErrorEvent {
|
|
47
|
+
/** 错误来源:JS / Promise / CSP / fetch / AI SDK。 */
|
|
48
|
+
type: "error" | "unhandledrejection" | "securitypolicyviolation" | "fetch" | "ai";
|
|
49
|
+
name: string;
|
|
50
|
+
message?: string;
|
|
51
|
+
/** JS:filename:line:col;资源:标签名;fetch */
|
|
52
|
+
source?: string;
|
|
53
|
+
/** 出错脚本 / 失败资源 / 请求 URL */
|
|
54
|
+
url?: string;
|
|
55
|
+
/** 错误堆栈(JS / Promise / fetch 有) */
|
|
56
|
+
stack?: string;
|
|
57
|
+
disposition?: string;
|
|
58
|
+
effective_directive?: string;
|
|
59
|
+
violated_directive?: string;
|
|
60
|
+
blocked_uri?: string;
|
|
61
|
+
source_file?: string;
|
|
62
|
+
line_number?: number;
|
|
63
|
+
column_number?: number;
|
|
64
|
+
original_policy?: string;
|
|
65
|
+
code?: number;
|
|
66
|
+
request_id?: string;
|
|
67
|
+
model?: string;
|
|
68
|
+
operation?: "generateText" | "streamText";
|
|
69
|
+
details?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
export interface MiniAppNetworkEvent {
|
|
72
|
+
url: string;
|
|
73
|
+
method?: string;
|
|
74
|
+
status?: number;
|
|
75
|
+
duration?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface MiniAppPerformanceEvent {
|
|
78
|
+
loadDuration?: number;
|
|
79
|
+
domReady?: number;
|
|
80
|
+
firstPaint?: number;
|
|
81
|
+
domExecutionDuration?: number;
|
|
82
|
+
resourceDuration?: number;
|
|
83
|
+
resourceCount?: number;
|
|
84
|
+
transferSize?: number;
|
|
85
|
+
}
|
|
86
|
+
export interface MiniAppCaptureEvent {
|
|
87
|
+
blob: Blob;
|
|
88
|
+
}
|
|
89
|
+
export interface MiniAppDestroyEvent {
|
|
90
|
+
reason?: string;
|
|
91
|
+
}
|
|
92
|
+
/** 页面路由变化(宿主 redirectTo / 头像点击 / 卡片点击 / sheet 开合 / 内存回收等统一触发) */
|
|
93
|
+
export interface MiniAppRouterChangeEvent {
|
|
94
|
+
from: MiniAppSimulatorRoute;
|
|
95
|
+
to: MiniAppSimulatorRoute;
|
|
96
|
+
}
|
|
97
|
+
export interface MiniAppEventMap {
|
|
98
|
+
ready: MiniAppReadyEvent;
|
|
99
|
+
beforeLoad: MiniAppBeforeLoadEvent;
|
|
100
|
+
load: MiniAppLoadEvent;
|
|
101
|
+
renderDone: MiniAppRenderDoneEvent;
|
|
102
|
+
error: MiniAppErrorEvent;
|
|
103
|
+
navigation: MiniAppNavigationEvent;
|
|
104
|
+
console: MiniAppConsoleEvent;
|
|
105
|
+
guestError: MiniAppGuestErrorEvent;
|
|
106
|
+
network: MiniAppNetworkEvent;
|
|
107
|
+
performance: MiniAppPerformanceEvent;
|
|
108
|
+
capture: MiniAppCaptureEvent;
|
|
109
|
+
destroy: MiniAppDestroyEvent;
|
|
110
|
+
/** 页面切换(任意来源:宿主调用 / 模拟器内部交互) */
|
|
111
|
+
routerChange: MiniAppRouterChangeEvent;
|
|
112
|
+
/** 截图结果(auto 自动截图 + manual 主动截图均触发) */
|
|
113
|
+
screenShot: MiniAppScreenShotResult;
|
|
114
|
+
/** 选取模式下指针悬停到某元素(移出小应用区域时为 null) */
|
|
115
|
+
elementHovered: ElementSelection | null;
|
|
116
|
+
/** 选取模式下点击选中某元素 */
|
|
117
|
+
elementSelected: ElementSelection;
|
|
118
|
+
/** 单选 / 多选集合发生变化 */
|
|
119
|
+
elementSelectionChange: MiniAppElementSelectionChangeEvent;
|
|
120
|
+
/** DOM 与 Scene 统一悬停事件。 */
|
|
121
|
+
visualHovered: VisualSelection | null;
|
|
122
|
+
/** DOM 与 Scene 统一点击 / 反向选中事件。 */
|
|
123
|
+
visualSelected: VisualSelection;
|
|
124
|
+
/** DOM 与 Scene 混合选择集合变化事件。 */
|
|
125
|
+
visualSelectionChange: MiniAppVisualSelectionChangeEvent;
|
|
126
|
+
/** 选取模式开 / 关状态变化 */
|
|
127
|
+
inspectorChange: MiniAppInspectorChangeEvent;
|
|
128
|
+
}
|
|
129
|
+
export type MiniAppEventHandler<E extends MiniAppEventName> = (event: MiniAppEventMap[E]) => void;
|
|
130
|
+
export type MiniAppErrorCode = "INVALID_URL" | "URL_BLOCKED" | "INVALID_ROUTE" | "LOAD_TIMEOUT" | "LOAD_FAILED" | "RENDERER_ERROR" | "UNSUPPORTED_RENDERER" | "LOADER_UNSUPPORTED" | "CAPTURE_UNSUPPORTED" | "ZIP_LOAD_FAILED" | "ZIP_NO_ENTRY" | "FILES_NO_ENTRY" | "PACKAGE_LIMIT_EXCEEDED" | "RESOURCE_LIMIT_EXCEEDED" | "DESTROYED";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 公共类型 barrel —— 按领域拆分为 options / events / renderer 三个文件,
|
|
3
|
+
* 此处统一转出,保持 `from "../types"` 的导入路径不变。
|
|
4
|
+
*/
|
|
5
|
+
export type { MiniAppMountTarget } from "../host/shadow-host";
|
|
6
|
+
export type { MiniAppPermissionKind, MiniAppPermissionSheetResult } from "../native-ui/permission-sheet/types";
|
|
7
|
+
export * from "./options";
|
|
8
|
+
export * from "./events";
|
|
9
|
+
export * from "./renderer";
|
|
10
|
+
export * from "./inspector";
|
|
11
|
+
export * from "./jsapi";
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可视化元素选取(Visual Inspector)公开类型。
|
|
3
|
+
*
|
|
4
|
+
* 能力定位:在预览态的小应用里「悬停高亮 + 点击选中」DOM 元素,把被选元素的
|
|
5
|
+
* 结构化描述(selector / 文本 / outerHTML 片段 / 包围盒)抛给宿主,供宿主拼进
|
|
6
|
+
* AI 编辑指令的上下文(Lovable / v0 式「@选区」体验)。
|
|
7
|
+
*
|
|
8
|
+
* 该能力完全独立于手势模拟(touchEmulation):开启时在 iframe 之上盖一层独立
|
|
9
|
+
* overlay 接管指针,关闭时 overlay 不存在,**对现有渲染 / 手势 / jsapi 链路零影响**。
|
|
10
|
+
* 仅 iframe 渲染器 + 同源可访问(allowSameOrigin,默认随 touchEmulation 开启)时生效;
|
|
11
|
+
* webview / 跨源场景为 no-op。
|
|
12
|
+
*/
|
|
13
|
+
/** 被选中 / 悬停元素的结构化描述(坐标取 iframe 内容 CSS 像素空间) */
|
|
14
|
+
export interface ElementSelection {
|
|
15
|
+
/** 统一 Visual Inspector 判别字段;旧消费方可忽略。 */
|
|
16
|
+
kind?: "dom";
|
|
17
|
+
/** 统一选区引用;DOM 默认由 selector 派生。 */
|
|
18
|
+
ref?: string;
|
|
19
|
+
/** 面向用户 / 输入胶囊的短标签,例如 `button.primary · 提交` */
|
|
20
|
+
label: string;
|
|
21
|
+
/** 从文档根到该元素的稳定 CSS selector(优先 #id 锚点,回退 :nth-of-type 路径) */
|
|
22
|
+
selector: string;
|
|
23
|
+
/** 从近端稳定锚点到元素的结构化 DOM 路径,供源码检索时逐级匹配 */
|
|
24
|
+
domPath: ElementPathSegment[];
|
|
25
|
+
/** 标签名(小写) */
|
|
26
|
+
tagName: string;
|
|
27
|
+
/** element id,无则 null */
|
|
28
|
+
id: string | null;
|
|
29
|
+
/** class 列表 */
|
|
30
|
+
classList: string[];
|
|
31
|
+
/** 归一化后的 textContent(折叠空白并截断),供 AI 识别"改哪段文案" */
|
|
32
|
+
text: string;
|
|
33
|
+
/** outerHTML 预览(截断),供 AI 理解元素结构 */
|
|
34
|
+
outerHTMLPreview: string;
|
|
35
|
+
/** 元素属性表(name → value) */
|
|
36
|
+
attributes: Record<string, string>;
|
|
37
|
+
/** iframe 内容坐标系下的包围盒(CSS px,未经设备缩放) */
|
|
38
|
+
rect: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 宿主视口(屏幕)坐标系下的包围盒(CSS px,已含设备缩放)。
|
|
46
|
+
* 即元素在整个页面里的真实屏幕位置,宿主可据此把浮动工具条 / chip 锚到选中元素旁。
|
|
47
|
+
*/
|
|
48
|
+
viewportRect: {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** 场景节点源码定位提示;definitionKey 跨 reload 稳定,instanceKey 只描述当前实例。 */
|
|
56
|
+
export interface MiniAppSceneSourceHint {
|
|
57
|
+
file?: string;
|
|
58
|
+
symbol?: string;
|
|
59
|
+
definitionKey?: string;
|
|
60
|
+
instanceKey?: string;
|
|
61
|
+
}
|
|
62
|
+
/** 从场景根到当前节点的稳定语义路径。 */
|
|
63
|
+
export interface MiniAppScenePathSegment {
|
|
64
|
+
ref: string;
|
|
65
|
+
label: string;
|
|
66
|
+
nodeType: string;
|
|
67
|
+
}
|
|
68
|
+
/** PixiJS / Three.js / 自定义 Canvas Provider 返回的结构化场景选区。 */
|
|
69
|
+
export interface SceneSelection {
|
|
70
|
+
kind: "scene";
|
|
71
|
+
/** 单次预览会话内稳定、跨 Provider 唯一的节点引用。 */
|
|
72
|
+
ref: string;
|
|
73
|
+
providerId: string;
|
|
74
|
+
engine: string;
|
|
75
|
+
label: string;
|
|
76
|
+
nodeType: string;
|
|
77
|
+
nodePath: MiniAppScenePathSegment[];
|
|
78
|
+
/** 只读、可序列化的 Inspector 属性白名单。 */
|
|
79
|
+
properties: Record<string, unknown>;
|
|
80
|
+
source?: MiniAppSceneSourceHint;
|
|
81
|
+
/** iframe 内容坐标系下的包围盒。 */
|
|
82
|
+
rect: {
|
|
83
|
+
x: number;
|
|
84
|
+
y: number;
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
};
|
|
88
|
+
/** 宿主视口坐标系下的包围盒,由 Host Inspector 补齐。 */
|
|
89
|
+
viewportRect: {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** DOM 与场景对象在宿主侧汇聚后的统一选区。 */
|
|
97
|
+
export type VisualSelection = ElementSelection | SceneSelection;
|
|
98
|
+
/** Hierarchy / Outliner 使用的裁剪场景节点。 */
|
|
99
|
+
export interface MiniAppSceneNode {
|
|
100
|
+
ref: string;
|
|
101
|
+
label: string;
|
|
102
|
+
nodeType: string;
|
|
103
|
+
visible: boolean;
|
|
104
|
+
selectable: boolean;
|
|
105
|
+
source?: MiniAppSceneSourceHint;
|
|
106
|
+
children: MiniAppSceneNode[];
|
|
107
|
+
}
|
|
108
|
+
/** 单个已注册 Provider 的场景树。 */
|
|
109
|
+
export interface MiniAppSceneProviderTree {
|
|
110
|
+
providerId: string;
|
|
111
|
+
engine: string;
|
|
112
|
+
label: string;
|
|
113
|
+
roots: MiniAppSceneNode[];
|
|
114
|
+
}
|
|
115
|
+
/** `getSceneTree()` 的版本化只读快照。 */
|
|
116
|
+
export interface MiniAppSceneTreeSnapshot {
|
|
117
|
+
version: 1;
|
|
118
|
+
providers: MiniAppSceneProviderTree[];
|
|
119
|
+
}
|
|
120
|
+
/** selector 的结构化路径段;比仅传字符串更便于 Agent 关联 Vue/React 模板源码 */
|
|
121
|
+
export interface ElementPathSegment {
|
|
122
|
+
tagName: string;
|
|
123
|
+
id: string | null;
|
|
124
|
+
classList: string[];
|
|
125
|
+
/** 同标签兄弟中的 1-based 序号;唯一兄弟时为 1 */
|
|
126
|
+
nthOfType: number;
|
|
127
|
+
}
|
|
128
|
+
/** `inspectorChange` 事件载荷 */
|
|
129
|
+
export interface MiniAppInspectorChangeEvent {
|
|
130
|
+
/** 选取模式是否开启 */
|
|
131
|
+
enabled: boolean;
|
|
132
|
+
}
|
|
133
|
+
export type MiniAppInspectorSelectionMode = "single" | "multiple";
|
|
134
|
+
/** 多选集合变化事件;`elementSelected` 仍为单次新增事件以保持向后兼容 */
|
|
135
|
+
export interface MiniAppElementSelectionChangeEvent {
|
|
136
|
+
selections: ElementSelection[];
|
|
137
|
+
changed: ElementSelection | null;
|
|
138
|
+
action: "add" | "clear";
|
|
139
|
+
}
|
|
140
|
+
/** DOM 与 Scene 混合选择集合变化事件。 */
|
|
141
|
+
export interface MiniAppVisualSelectionChangeEvent {
|
|
142
|
+
selections: VisualSelection[];
|
|
143
|
+
changed: VisualSelection | null;
|
|
144
|
+
action: "add" | "clear" | "remove";
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 运行时可视化选取控制器,挂在 `simulator.inspector` 上。
|
|
148
|
+
*
|
|
149
|
+
* 与 `gesture` / `hostApi` 等控制器同级,提供实例方法控制选取模式开关;
|
|
150
|
+
* 选中 / 悬停结果通过 `simulator.on('elementSelected' | 'elementHovered', ...)` 订阅。
|
|
151
|
+
* 仅 iframe 渲染器 + 同源可访问时生效,其余场景所有方法为 no-op。
|
|
152
|
+
*/
|
|
153
|
+
export interface MiniAppInspectorController {
|
|
154
|
+
/** 进入选取模式:冻结应用帧时钟并在小应用之上盖一层 overlay 接管悬停 / 点击 */
|
|
155
|
+
enable(): void;
|
|
156
|
+
/** 退出选取模式:恢复应用时钟,移除 overlay,恢复正常预览 / 手势交互 */
|
|
157
|
+
disable(): void;
|
|
158
|
+
/** 切换选取模式 */
|
|
159
|
+
toggle(): void;
|
|
160
|
+
/** 当前是否处于选取模式 */
|
|
161
|
+
isEnabled(): boolean;
|
|
162
|
+
/** 清除当前选中高亮(保持选取模式开启) */
|
|
163
|
+
clear(): void;
|
|
164
|
+
/** 单选 / 多选模式;默认 single。切换模式时会清空已有高亮。 */
|
|
165
|
+
setSelectionMode(mode: MiniAppInspectorSelectionMode): void;
|
|
166
|
+
/** 当前选取模式 */
|
|
167
|
+
getSelectionMode(): MiniAppInspectorSelectionMode;
|
|
168
|
+
/** 获取所有已注册 Scene Provider 的只读层级树;不支持时返回空快照。 */
|
|
169
|
+
getSceneTree(): Promise<MiniAppSceneTreeSnapshot>;
|
|
170
|
+
/** 从 Hierarchy / Outliner 反向选中场景节点,并同步 Viewport 高亮。 */
|
|
171
|
+
selectByRef(ref: string): Promise<VisualSelection | null>;
|
|
172
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum MiniAppJsApiErrorCode {
|
|
2
|
+
INVALID_PARAM = 10001,
|
|
3
|
+
API_UNAVAILABLE = 10002,
|
|
4
|
+
URL_SCHEME_NOT_ALLOWED = 10003,
|
|
5
|
+
REQUEST_TIMEOUT = 10101,
|
|
6
|
+
REQUEST_ABORTED = 10102,
|
|
7
|
+
REQUEST_FAILED = 15201,
|
|
8
|
+
STORAGE_IO_ERROR = 50101,
|
|
9
|
+
STORAGE_QUOTA_EXCEEDED = 50201,
|
|
10
|
+
FILE_NOT_FOUND = 50202,
|
|
11
|
+
PATH_INVALID = 50203,
|
|
12
|
+
FILE_ALREADY_EXISTS = 50204,
|
|
13
|
+
NOT_A_FILE = 50205,
|
|
14
|
+
NOT_A_DIRECTORY = 50206
|
|
15
|
+
}
|
|
16
|
+
export declare function createMiniAppJsApiError(code: MiniAppJsApiErrorCode, message: string): Error & {
|
|
17
|
+
code: MiniAppJsApiErrorCode;
|
|
18
|
+
};
|