@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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SelectionDisablerPlugin — 在 iframe 内禁用文本选中,模拟移动端体感。
|
|
3
|
+
*
|
|
4
|
+
* 移动端 long-press 默认是选中文本,但小程序场景一般不希望出现选中蓝条。
|
|
5
|
+
* 本 plugin 在 iframe ready 时 send `mini-app:selection` { enabled: false },
|
|
6
|
+
* receiver 注入 body { user-select: none }。
|
|
7
|
+
*
|
|
8
|
+
* 可通过 `simulator.gesture.remove("selection-disabler")` 关闭,恢复文本选中。
|
|
9
|
+
*/
|
|
10
|
+
import type { GestureHostPlugin } from "../types";
|
|
11
|
+
export declare function createSelectionDisablerPlugin(): GestureHostPlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TapPlugin — 短按 tap 检测。
|
|
3
|
+
*
|
|
4
|
+
* 监听 down/up,根据时长 + 距离判定为 tap,向 iframe 发送 `mini-app:tap` 消息
|
|
5
|
+
* (receiver 端的 ClickSynthesizerPlugin 会派发 mousedown / mouseup / click)。
|
|
6
|
+
*
|
|
7
|
+
* 协议逻辑事件:
|
|
8
|
+
* - emit "tap" { point, modifiers } —— DoubleTapPlugin 依赖此事件计数双击
|
|
9
|
+
*/
|
|
10
|
+
import type { GestureHostPlugin } from "../types";
|
|
11
|
+
export declare function createTapPlugin(): GestureHostPlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TouchEmitterPlugin — 核心 touch 派发器。
|
|
3
|
+
*
|
|
4
|
+
* 监听 PointerSnapshot 的 down/move/up/leave/blur,转换为 `mini-app:touch` 消息发到 iframe。
|
|
5
|
+
* 根据 state.isMultiTouch + state.multiTouchMode 决定派 1 / 2 个触点及其几何算法:
|
|
6
|
+
* - "mirror":副触点 = 主触点关于 base 对称 + MULTI_TOUCH_OFFSET 外推(默认双指)
|
|
7
|
+
* - "pinch":副触点 = 主触点关于 base 真实对称(无偏移,模拟捏合)
|
|
8
|
+
* - "rotate":副触点 = 主触点关于 base 旋转 180°
|
|
9
|
+
*/
|
|
10
|
+
import type { GestureHostPlugin } from "../types";
|
|
11
|
+
export declare function createTouchEmitterPlugin(): GestureHostPlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WheelScrollPlugin — 鼠标滚轮 → iframe 内滚动。
|
|
3
|
+
*
|
|
4
|
+
* overlay z-index:2 完全吞掉了 wheel 事件,造成 PC 用户无法用滚轮滚动 iframe 内长列表。
|
|
5
|
+
* 本 plugin 监听 overlay 的 wheel 事件,转发到 iframe 内(receiver 端 WheelDispatchPlugin
|
|
6
|
+
* 派发原生 WheelEvent + scrollBy fallback)。
|
|
7
|
+
*
|
|
8
|
+
* 注意:Alt + wheel 不在本 plugin 处理(由 PinchPlugin 拦截作为缩放)。
|
|
9
|
+
*/
|
|
10
|
+
import type { GestureHostPlugin } from "../types";
|
|
11
|
+
export declare function createWheelScrollPlugin(): GestureHostPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 手势 receiver 注入。逻辑源在 receiver-runtime.impl.ts,经 gen:receiver 编成
|
|
3
|
+
* receiver-runtime.impl.built.js,这里以 ?raw 内联为注入字符串。改逻辑改 impl.ts。
|
|
4
|
+
*/
|
|
5
|
+
export declare const RECEIVER_RUNTIME_SOURCE: string;
|
|
6
|
+
/**
|
|
7
|
+
* 把 receiver runtime 注入到目标 iframe 内。
|
|
8
|
+
* 需要 iframe 已 onload + 父页面与 iframe 同源(SW 直供的同源 URL)。
|
|
9
|
+
*/
|
|
10
|
+
export declare function injectGestureReceiver(iframe: HTMLIFrameElement): boolean;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TouchCursor —— 模拟器内置的「手指指针」。
|
|
3
|
+
*
|
|
4
|
+
* 设计取舍(见 issue 排查):
|
|
5
|
+
* 早期把它做成 hover gesture plugin,圆点的显示依赖 host-bus 的事件管线
|
|
6
|
+
* (rect 命中判定 + isPressed 闸门 + dispatch("move") + plugin 订阅)。
|
|
7
|
+
* 任一环节静默不触发,圆点就出不来——实际表现为「按压才出现,移入即消失」。
|
|
8
|
+
*
|
|
9
|
+
* touch 指针是触摸模拟的核心视觉,不属于可插拔行为。这里抽成独立类,
|
|
10
|
+
* 由 gesture 核心(GestureHostBus)直接持有,圆点元素**即时创建**,
|
|
11
|
+
* 显示/跟随完全走自己的原始鼠标监听,不经过任何闸门,确保稳定。
|
|
12
|
+
*
|
|
13
|
+
* 三态(设计走查:指针只用白色,不随状态变蓝/变红):
|
|
14
|
+
* idle 白色玻璃质感空心圆 24px(普通区域)
|
|
15
|
+
* hot 与 idle 同(指向 cursor=pointer/grab 的元素,仅描边略加重反馈)
|
|
16
|
+
* pressed 白色实心圆 22px(按下中,长宽 -2px 给反馈)
|
|
17
|
+
*
|
|
18
|
+
* hot 判定需要 iframe 与父页面同源(读 elementFromPoint 的 computed cursor)。
|
|
19
|
+
*/
|
|
20
|
+
export interface TouchCursorOptions {
|
|
21
|
+
/** 圆点的「可视区域」:判定指针是否在模拟器内(用稳定的 light DOM 元素,如 shadow host) */
|
|
22
|
+
region: HTMLElement;
|
|
23
|
+
/** 内容载体元素(iframe 或 webview),仅用于 hot 命中范围判定 */
|
|
24
|
+
element: HTMLElement;
|
|
25
|
+
/** 载体区域遮罩:用于按压检测,并同步隐藏系统鼠标 */
|
|
26
|
+
overlay: HTMLElement;
|
|
27
|
+
/**
|
|
28
|
+
* 读 host 视口坐标下 guest 元素的 computed cursor(hot 判定)。
|
|
29
|
+
* iframe 同源可同步读取;webview 跨进程返回 undefined → hot 降级(恒不高亮)。
|
|
30
|
+
*/
|
|
31
|
+
readCursor?: (hostX: number, hostY: number) => string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export declare class TouchCursor {
|
|
34
|
+
private readonly region;
|
|
35
|
+
private readonly element;
|
|
36
|
+
private readonly overlay;
|
|
37
|
+
private readonly readCursor?;
|
|
38
|
+
private readonly dot;
|
|
39
|
+
private destroyed;
|
|
40
|
+
/** DevTools 审查等场景暂时禁止显示/跟随,避免挡住 Elements 选点 */
|
|
41
|
+
private suppressed;
|
|
42
|
+
private visible;
|
|
43
|
+
private pressed;
|
|
44
|
+
private hot;
|
|
45
|
+
/** 当前宿主视口坐标 */
|
|
46
|
+
private hostX;
|
|
47
|
+
private hostY;
|
|
48
|
+
private rafId;
|
|
49
|
+
/** 进入触摸模拟前 region 的内联 cursor,销毁时还原 */
|
|
50
|
+
private readonly savedRegionCursor;
|
|
51
|
+
private readonly savedOverlayCursor;
|
|
52
|
+
constructor(options: TouchCursorOptions);
|
|
53
|
+
/**
|
|
54
|
+
* 指针下的「最顶层」元素是否属于模拟器(穿过 shadow 边界判定)。
|
|
55
|
+
*
|
|
56
|
+
* 不能只用 region 矩形几何判定:消费方在模拟器之上叠加的弹窗(如扫码预览模态)
|
|
57
|
+
* 虽落在 region 矩形内,但它才是指针下的真实命中元素。圆点是 z-index 99999 的
|
|
58
|
+
* fixed 层,若仅靠几何就会画到弹窗之上(视觉「穿透」)。
|
|
59
|
+
* 改用事件 composedPath:仅当模拟器自身元素(shadow host / overlay / 载体)在命中
|
|
60
|
+
* 链上,才认为指针确实落在模拟器、且模拟器是最顶层,圆点才显示。
|
|
61
|
+
*/
|
|
62
|
+
private isTopmostSimulator;
|
|
63
|
+
private applyMode;
|
|
64
|
+
private place;
|
|
65
|
+
private refreshMode;
|
|
66
|
+
private show;
|
|
67
|
+
private hide;
|
|
68
|
+
/** hot 判定:经介质通道读指针下元素的 computed cursor(RAF 节流,跨边界 getComputedStyle 昂贵) */
|
|
69
|
+
private tickHot;
|
|
70
|
+
/** DevTools 审查 / 权限弹窗 / 元素选取等场景:隐藏圆点并暂停跟随,避免干扰上层交互 */
|
|
71
|
+
setSuppressed(suppressed: boolean): void;
|
|
72
|
+
private onMove;
|
|
73
|
+
private onLeave;
|
|
74
|
+
private onDown;
|
|
75
|
+
private onUp;
|
|
76
|
+
private onBlur;
|
|
77
|
+
destroy(): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 触点圆点工具:在父窗口上画固定定位的圆点,用于可视化触摸位置。
|
|
3
|
+
* 多个 plugin 共享(SingleTouch 主触点、MultiTouchHint 副触点、Pinch 双指等)。
|
|
4
|
+
*/
|
|
5
|
+
export declare class TouchDotManager {
|
|
6
|
+
private readonly dots;
|
|
7
|
+
private readonly parent;
|
|
8
|
+
constructor(parent?: HTMLElement);
|
|
9
|
+
place(id: number, clientX: number, clientY: number, color?: string): void;
|
|
10
|
+
remove(id: number): void;
|
|
11
|
+
clear(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gesture 模块的核心类型。
|
|
3
|
+
*
|
|
4
|
+
* 设计目标:
|
|
5
|
+
* - 把"宿主鼠标 → iframe 内 touch/click/wheel 等"全部抽成插件化协议
|
|
6
|
+
* - host 端 plugin 监听原始事件并 send 给 iframe,receiver 端 plugin 派发对应 DOM 事件
|
|
7
|
+
* - 跨 plugin 通过共享状态 + 逻辑事件 emit/on 协作
|
|
8
|
+
*/
|
|
9
|
+
export interface GesturePoint {
|
|
10
|
+
identifier: number;
|
|
11
|
+
clientX: number;
|
|
12
|
+
clientY: number;
|
|
13
|
+
pageX: number;
|
|
14
|
+
pageY: number;
|
|
15
|
+
screenX: number;
|
|
16
|
+
screenY: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ModifierKeys {
|
|
19
|
+
altKey: boolean;
|
|
20
|
+
ctrlKey: boolean;
|
|
21
|
+
metaKey: boolean;
|
|
22
|
+
shiftKey: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 原始指针事件快照(在 host 端已转换为 iframe CSS 坐标 + host 坐标双坐标空间)。
|
|
26
|
+
* 所有 host plugin 看到的都是这种统一格式,不直接接触 DOM Event。
|
|
27
|
+
*/
|
|
28
|
+
export interface PointerSnapshot {
|
|
29
|
+
kind: "down" | "move" | "up" | "leave" | "wheel" | "blur";
|
|
30
|
+
/** iframe CSS 坐标空间(已做 transform scale 修正) */
|
|
31
|
+
iframeX: number;
|
|
32
|
+
iframeY: number;
|
|
33
|
+
/** 宿主视口坐标(用于 overlay 上画 UI) */
|
|
34
|
+
hostX: number;
|
|
35
|
+
hostY: number;
|
|
36
|
+
/** screen 坐标(透传给合成事件) */
|
|
37
|
+
screenX: number;
|
|
38
|
+
screenY: number;
|
|
39
|
+
modifiers: ModifierKeys;
|
|
40
|
+
/** 0=left, 1=middle, 2=right;wheel/blur 时为 0 */
|
|
41
|
+
button: number;
|
|
42
|
+
/** 仅 wheel 时有值 */
|
|
43
|
+
wheelDeltaX?: number;
|
|
44
|
+
wheelDeltaY?: number;
|
|
45
|
+
wheelDeltaMode?: number;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
/** 原始 DOM 事件,plugin 可用其 preventDefault;blur 时为 null */
|
|
48
|
+
raw: MouseEvent | WheelEvent | null;
|
|
49
|
+
}
|
|
50
|
+
/** 宿主侧可回放的通用手势输入,坐标使用 guest CSS 像素。 */
|
|
51
|
+
export type GestureDispatchAction = "tap" | "doubleTap" | "longPress" | "scroll" | "swipe";
|
|
52
|
+
export interface GestureDispatchInput {
|
|
53
|
+
action: GestureDispatchAction;
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
toX?: number;
|
|
57
|
+
toY?: number;
|
|
58
|
+
deltaX?: number;
|
|
59
|
+
deltaY?: number;
|
|
60
|
+
duration?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface GestureDispatchResult {
|
|
63
|
+
action: GestureDispatchAction;
|
|
64
|
+
from: {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
};
|
|
68
|
+
to?: {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
};
|
|
72
|
+
segments?: number;
|
|
73
|
+
durationMs?: number;
|
|
74
|
+
}
|
|
75
|
+
export type GestureBusMessage = TouchMessage | WheelMessage | TapMessage | LongPressMessage | DoubleTapMessage | CursorQueryMessage | SelectionMessage;
|
|
76
|
+
export interface TouchMessage {
|
|
77
|
+
type: "mini-app:touch";
|
|
78
|
+
eventName: "touchstart" | "touchmove" | "touchend" | "touchcancel";
|
|
79
|
+
touches: GesturePoint[];
|
|
80
|
+
changedTouches: GesturePoint[];
|
|
81
|
+
modifiers: ModifierKeys;
|
|
82
|
+
}
|
|
83
|
+
export interface WheelMessage {
|
|
84
|
+
type: "mini-app:wheel";
|
|
85
|
+
iframeX: number;
|
|
86
|
+
iframeY: number;
|
|
87
|
+
deltaX: number;
|
|
88
|
+
deltaY: number;
|
|
89
|
+
deltaZ: number;
|
|
90
|
+
deltaMode: number;
|
|
91
|
+
modifiers: ModifierKeys;
|
|
92
|
+
}
|
|
93
|
+
export interface TapMessage {
|
|
94
|
+
type: "mini-app:tap";
|
|
95
|
+
point: GesturePoint;
|
|
96
|
+
modifiers: ModifierKeys;
|
|
97
|
+
}
|
|
98
|
+
export interface LongPressMessage {
|
|
99
|
+
type: "mini-app:longpress";
|
|
100
|
+
point: GesturePoint;
|
|
101
|
+
modifiers: ModifierKeys;
|
|
102
|
+
}
|
|
103
|
+
export interface DoubleTapMessage {
|
|
104
|
+
type: "mini-app:dblclick";
|
|
105
|
+
point: GesturePoint;
|
|
106
|
+
modifiers: ModifierKeys;
|
|
107
|
+
}
|
|
108
|
+
export interface CursorQueryMessage {
|
|
109
|
+
type: "mini-app:cursor-query";
|
|
110
|
+
iframeX: number;
|
|
111
|
+
iframeY: number;
|
|
112
|
+
/** 关联 ID,回包用同样 ID 携带 cursor 字符串 */
|
|
113
|
+
queryId: number;
|
|
114
|
+
}
|
|
115
|
+
export interface CursorReplyMessage {
|
|
116
|
+
type: "mini-app:cursor-reply";
|
|
117
|
+
queryId: number;
|
|
118
|
+
cursor: string;
|
|
119
|
+
}
|
|
120
|
+
export interface SelectionMessage {
|
|
121
|
+
type: "mini-app:selection";
|
|
122
|
+
enabled: boolean;
|
|
123
|
+
}
|
|
124
|
+
/** guest → host 回包(receiver 主动上报,如 focus-editable / cursor-reply) */
|
|
125
|
+
export interface GestureInboundMessage {
|
|
126
|
+
type?: string;
|
|
127
|
+
[key: string]: unknown;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 手势「介质通道」——封装 host↔guest 的发送/回包/聚焦/cursor 读取差异。
|
|
131
|
+
*
|
|
132
|
+
* - iframe:`send` 走 `contentWindow.postMessage`;`subscribe` 监听 `window.message`
|
|
133
|
+
* (source 过滤);`readCursorAt` 同步读 `contentDocument` 的 computed cursor。
|
|
134
|
+
* - webview:`send` 走 `WebviewTransport`(IPC `mas:msg` → preload 转成 guest
|
|
135
|
+
* `window.message` 喂给 receiver);`subscribe` 走 `transport.onMessage`;
|
|
136
|
+
* `readCursorAt` 跨进程无法同步读取 → 返回 `undefined`(hot 高亮降级)。
|
|
137
|
+
*/
|
|
138
|
+
export interface GestureGuestChannel {
|
|
139
|
+
/** host → guest 发送手势协议消息 */
|
|
140
|
+
send(msg: GestureBusMessage): void;
|
|
141
|
+
/** 订阅 guest → host 回包;返回取消订阅 */
|
|
142
|
+
subscribe(handler: (msg: GestureInboundMessage) => void): () => void;
|
|
143
|
+
/** guest 内表单聚焦后,把宿主焦点切到 guest(键盘输入可达) */
|
|
144
|
+
focusGuest(): void;
|
|
145
|
+
/** 读 host 视口坐标下 guest 元素的 computed cursor(hot 判定);不支持返回 undefined */
|
|
146
|
+
readCursorAt(hostX: number, hostY: number): string | undefined;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 双指模式下的副触点几何算法。
|
|
150
|
+
* - "mirror":副触点为主触点关于 base 的对称点(再外推固定偏移)—— 经典 shift 双指
|
|
151
|
+
* - "pinch":副触点为主触点关于 base 的真实对称点(无偏移)—— 模拟捏合
|
|
152
|
+
* - "rotate":副触点为主触点关于 base 旋转 180° 后的点 —— 模拟双指旋转
|
|
153
|
+
*/
|
|
154
|
+
export type MultiTouchMode = "mirror" | "pinch" | "rotate";
|
|
155
|
+
export interface GestureSharedState {
|
|
156
|
+
/** 鼠标主按键是否处于按下态 */
|
|
157
|
+
isPressed: boolean;
|
|
158
|
+
/** 是否进入多指模式(任意 MultiTouchSwitch/Pinch/Rotate plugin 控制) */
|
|
159
|
+
isMultiTouch: boolean;
|
|
160
|
+
/** 双指模式时的算法,single touch 时为 null */
|
|
161
|
+
multiTouchMode: MultiTouchMode | null;
|
|
162
|
+
/** 多指基点:双指对称中心 */
|
|
163
|
+
multiTouchBase: {
|
|
164
|
+
hostX: number;
|
|
165
|
+
hostY: number;
|
|
166
|
+
iframeX: number;
|
|
167
|
+
iframeY: number;
|
|
168
|
+
} | null;
|
|
169
|
+
/** 当前按下起点(用于 tap/longpress 距离阈值判定) */
|
|
170
|
+
pressStartPoint: {
|
|
171
|
+
iframeX: number;
|
|
172
|
+
iframeY: number;
|
|
173
|
+
hostX: number;
|
|
174
|
+
hostY: number;
|
|
175
|
+
} | null;
|
|
176
|
+
pressStartedAt: number;
|
|
177
|
+
}
|
|
178
|
+
export type RawEventName = PointerSnapshot["kind"];
|
|
179
|
+
export type RawEventHandler = (ev: PointerSnapshot) => void;
|
|
180
|
+
export type LogicEventHandler = (...args: unknown[]) => void;
|
|
181
|
+
export interface GestureHostContext {
|
|
182
|
+
/** 订阅原始指针事件 */
|
|
183
|
+
on(event: RawEventName, handler: RawEventHandler): () => void;
|
|
184
|
+
/** 跨 plugin 协作:触发逻辑事件 */
|
|
185
|
+
emit(event: string, ...args: unknown[]): void;
|
|
186
|
+
/** 订阅逻辑事件(例如 'tap' / 'longpress' / 'pinch' / 'rotate') */
|
|
187
|
+
hook(event: string, handler: LogicEventHandler): () => void;
|
|
188
|
+
/** 把消息发到 guest 内(介质相关:postMessage / IPC 包装) */
|
|
189
|
+
send(msg: GestureBusMessage): void;
|
|
190
|
+
/** 共享状态(跨 plugin 读写) */
|
|
191
|
+
readonly state: GestureSharedState;
|
|
192
|
+
/** overlay DOM 节点,plugin 可往里加触点圆点 / 状态条等 UI */
|
|
193
|
+
readonly overlay: HTMLDivElement;
|
|
194
|
+
/** 目标内容载体元素(iframe 或 webview,仅用于坐标/聚焦,与介质无关) */
|
|
195
|
+
readonly iframe: HTMLElement;
|
|
196
|
+
/** 设置 overlay 的 cursor(HoverIndicatorPlugin 主要用,默认隐藏成 "none") */
|
|
197
|
+
setCursor(cursor: string): void;
|
|
198
|
+
/** debug 开关 */
|
|
199
|
+
readonly debug: boolean;
|
|
200
|
+
}
|
|
201
|
+
export interface GestureHostPlugin {
|
|
202
|
+
readonly name: string;
|
|
203
|
+
install(ctx: GestureHostContext): void;
|
|
204
|
+
/** 可选清理钩子,bus.dispose 时调用 */
|
|
205
|
+
uninstall?(): void;
|
|
206
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shadow Host:把模拟器核心渲染在消费方提供的 root 节点内部,并用 Shadow DOM 隔离样式。
|
|
3
|
+
*
|
|
4
|
+
* DOM 结构:
|
|
5
|
+
* root(消费方传入,如 #preview)
|
|
6
|
+
* host(SDK 创建的宿主元素,撑满 root)
|
|
7
|
+
* #shadow-root(shadow=true 时)
|
|
8
|
+
* <style> base reset </style>
|
|
9
|
+
* bounds(.dms-bounds,stageFit 的可用区域 / 默认 bounds)
|
|
10
|
+
* stage(.dms-stage,渲染器实际挂载点,等价于旧的 container)
|
|
11
|
+
*
|
|
12
|
+
* shadow=false 时不创建 shadow root,bounds/stage 直接挂在 host 的 light DOM 下,
|
|
13
|
+
* 仅依赖内联样式(手机壳 / 内容层 / 手柄本身就是内联样式,自定义元素自带 :host 样式)。
|
|
14
|
+
*/
|
|
15
|
+
/** 挂载目标:CSS 选择器字符串或 HTMLElement */
|
|
16
|
+
export type MiniAppMountTarget = string | HTMLElement;
|
|
17
|
+
export interface CreateShadowHostOptions {
|
|
18
|
+
/** 是否启用 Shadow DOM 隔离,默认 true */
|
|
19
|
+
shadow?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface MiniAppShadowHost {
|
|
22
|
+
/** 消费方提供的 root 节点 */
|
|
23
|
+
root: HTMLElement;
|
|
24
|
+
/** SDK 在 root 内创建的宿主元素 */
|
|
25
|
+
host: HTMLElement;
|
|
26
|
+
/** Shadow Root;shadow=false 时为 null */
|
|
27
|
+
shadowRoot: ShadowRoot | null;
|
|
28
|
+
/** stageFit 的默认可用区域(bounds) */
|
|
29
|
+
bounds: HTMLElement;
|
|
30
|
+
/** 渲染器实际挂载点(等价于旧 container) */
|
|
31
|
+
stage: HTMLElement;
|
|
32
|
+
/** 宿主侧 overlay(如 toast)应挂载到的根:shadowRoot 或 host */
|
|
33
|
+
overlayRoot: ShadowRoot | HTMLElement;
|
|
34
|
+
/** 销毁:移除创建的宿主元素 */
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
/** 解析挂载目标为 HTMLElement(字符串走 querySelector) */
|
|
38
|
+
export declare function resolveMountRoot(target: MiniAppMountTarget): HTMLElement;
|
|
39
|
+
/** 在 root 内创建宿主元素 + (可选)Shadow Root + bounds + stage */
|
|
40
|
+
export declare function createShadowHost(root: HTMLElement, options?: CreateShadowHostOptions): MiniAppShadowHost;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export { createMiniAppSimulator } from "./core/simulator";
|
|
2
|
+
export { BusinessLine } from "./business-line";
|
|
3
|
+
export { MiniAppSimulatorError } from "./errors";
|
|
4
|
+
export { MiniAppJsApiErrorCode } from "./types";
|
|
5
|
+
export { WORKER_CONTENT_SECURITY_POLICY } from "./worker/adapters/protocol";
|
|
6
|
+
export type { WorkerGuardConfig } from "./worker/adapters/protocol";
|
|
7
|
+
export declare const WORKER_RUNTIME_METADATA: Readonly<import("./worker/adapters/protocol").WorkerRuntimeMetadata>;
|
|
8
|
+
export { WORKER_RUNTIME_PROTOCOL_VERSION } from "./worker/adapters/protocol";
|
|
9
|
+
export type { MiniAppWorkerOptions } from "./worker/adapters/package-policy";
|
|
10
|
+
export type { WorkerCspPolicy } from "./worker/adapters/csp-policy";
|
|
11
|
+
export { detectEnvironment, getSimulatorContext, type SimulatorEnvironment, type SimulatorRuntimeContext, } from "./runtime/context";
|
|
12
|
+
/**
|
|
13
|
+
* 设备能力白名单枚举与元数据,供 `security.sealAllow` 配置 / UI 枚举渲染 / 校验。
|
|
14
|
+
* 由模拟器维护,供消费方一处引入。
|
|
15
|
+
*/
|
|
16
|
+
export { ALL_MINI_APP_CAPABILITIES, HOST_CONTROLLED_CAPABILITIES, MINI_APP_CAPABILITIES, MiniAppCapability, type MiniAppCapabilityControlledBy, type MiniAppCapabilityDescriptor, SEAL_CONTROLLED_CAPABILITIES, isMiniAppCapability, sanitizeCapabilityList, } from "./seal-config";
|
|
17
|
+
export type {
|
|
18
|
+
/** 创建参数 */
|
|
19
|
+
MiniAppSimulatorOptions,
|
|
20
|
+
/** 实例类型(含 loadZip / on / notePreview 等) */
|
|
21
|
+
MiniAppSimulator, MiniAppGamePlaytestController,
|
|
22
|
+
/** switchContentMode / contentMode 字段 */
|
|
23
|
+
MiniAppContentMode,
|
|
24
|
+
/** shell 字段:rednote 笔记壳 / none 无壳纯面板 */
|
|
25
|
+
MiniAppShellMode,
|
|
26
|
+
/** renderer 字段:webview / iframe-service-worker */
|
|
27
|
+
MiniAppRendererType,
|
|
28
|
+
/** REDNote 壳层笔记数据(notePreview.update / updateUser / updateAppCard) */
|
|
29
|
+
XhsNotePreviewData,
|
|
30
|
+
/** 壳层顶栏用户信息(notePreview.updateUser) */
|
|
31
|
+
XhsNotePreviewUser,
|
|
32
|
+
/** 笔记内小工具入口卡片信息(notePreview.updateAppCard) */
|
|
33
|
+
XhsNoteAppCardData,
|
|
34
|
+
/** 小工具封面(widgetCover.update;笔记尾卡 + 个人页卡片两处生效) */
|
|
35
|
+
XhsWidgetCoverData,
|
|
36
|
+
/** 页面路由:redirectTo / getCurrentRoute / routerChange 事件 */
|
|
37
|
+
MiniAppSimulatorRoute, MiniAppRedirectOptions,
|
|
38
|
+
/** 截图:screenShot() 结果 */
|
|
39
|
+
MiniAppScreenShotResult, MiniAppScreenShotErrorCode,
|
|
40
|
+
/** simulator.on / once / off 事件名与 payload */
|
|
41
|
+
MiniAppEventName, MiniAppEventHandler, MiniAppEventMap, MiniAppGestureController, GestureDispatchAction, GestureDispatchInput, GestureDispatchResult,
|
|
42
|
+
/** 可视化元素选取:控制器 / 选区描述 / 状态事件 */
|
|
43
|
+
MiniAppInspectorController, ElementSelection, ElementPathSegment, MiniAppInspectorSelectionMode, MiniAppElementSelectionChangeEvent, MiniAppVisualSelectionChangeEvent, VisualSelection, SceneSelection, MiniAppSceneNode, MiniAppScenePathSegment, MiniAppSceneProviderTree, MiniAppSceneSourceHint, MiniAppSceneTreeSnapshot, MiniAppInspectorChangeEvent,
|
|
44
|
+
/** loadZip 入参 / 返回值 */
|
|
45
|
+
MiniAppLoadZipOptions, MiniAppLoadZipResult, MiniAppPackageLimits, MiniAppRuntimeLimits,
|
|
46
|
+
/** loadFiles 入参 / 选项 / 返回值(AI 出码目录产物加载) */
|
|
47
|
+
MiniAppFileContent, MiniAppFileMap, MiniAppLoadFilesOptions, MiniAppLoadFilesResult,
|
|
48
|
+
/** options.hostApi 单条定制项:函数 handler / `{ toast }` 占位覆盖 */
|
|
49
|
+
MiniAppHostApiHandler, MiniAppHostApiStub, MiniAppHostApiEntry, MiniAppHostApiRequest, MiniAppHostRequest, MiniAppHostRequestOptions, MiniAppHostRequestResponse,
|
|
50
|
+
/** options.tracker:输入 / 选项 / 上报事件 / 业务线 / region */
|
|
51
|
+
MiniAppTrackerInput, MiniAppTrackerOptions, MiniAppDefaultTrackerOptions, MiniAppTrackerEvent, MiniAppTrackerUserInfo, MiniAppBusinessLine, MiniAppApmRegion, } from "./types";
|
|
52
|
+
/** DOM 元素结构化定位工具,供同源预览宿主复用 */
|
|
53
|
+
export { buildElementSelection, computeSelector } from "./inspector";
|
|
54
|
+
/** `screenShot` 失败码常量(notLoaded / renderFailed / timeout / unsupported) */
|
|
55
|
+
export { MINIAPP_SCREENSHOT_ERROR_CODE } from "./types";
|
|
56
|
+
export type { WorkerTerminateFlag, WorkerTerminateCallback, WorkerRuntimeState, } from "./worker/adapters/protocol";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** guest 内框架注入脚本的日志前缀;host 据此把 console 的 source 标为 `sdk` */
|
|
2
|
+
export declare const MINIAPP_SDK_LOG_MARK = "[mini-app-sdk]";
|
|
3
|
+
/** 按框架标记判定 console 来源;sdk 日志剥掉前缀 */
|
|
4
|
+
export declare function classifyConsoleMessage(raw: string): {
|
|
5
|
+
message: string;
|
|
6
|
+
source: "sdk" | "user";
|
|
7
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InjectionRegistry } from "./registry";
|
|
2
|
+
import type { InjectionContext } from "./types";
|
|
3
|
+
/** 装配 head:meta/style 在前,内部模块脚本收口进单个(带 nonce 的)`<script>`,逐段 try/catch。 */
|
|
4
|
+
export declare function assembleHeadInjection(injection: InjectionRegistry, ctx: InjectionContext): Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection 层统一出口(注入模块清单 + builders + 内置模块)。
|
|
3
|
+
*
|
|
4
|
+
* Kernel 与 Plugin 内部使用本文件统一导入;不对宿主暴露。
|
|
5
|
+
*/
|
|
6
|
+
export { InjectionRegistry } from "./registry";
|
|
7
|
+
export type { InjectionContext, InjectionModule } from "./types";
|
|
8
|
+
export { assembleHeadInjection } from "./head-builder";
|
|
9
|
+
export { buildWebviewPreloadSource, materializePreloadFile, materializeWebviewPreload, } from "./preload-builder";
|
|
10
|
+
export type { BuildWebviewPreloadOptions } from "./preload-builder";
|
|
11
|
+
export { renderDoneInjection } from "./modules/render-done";
|
|
12
|
+
export { jsapiInjection } from "./modules/jsapi";
|
|
13
|
+
export { securityInjection } from "./modules/security";
|
|
14
|
+
export { consoleForwardInjection } from "./modules/console-forward";
|
|
15
|
+
export { inspectorInjection } from "./modules/inspector";
|
|
16
|
+
export { resourceGuardInjection } from "./modules/resource-guard";
|
|
17
|
+
export { gestureReceiverInjection } from "./modules/gesture";
|
|
18
|
+
export { scrollContainmentInjection } from "./modules/scroll-containment";
|
|
19
|
+
export { widgetSnapshotInjection } from "./modules/widget-snapshot";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InjectionModule } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Visual Inspector guest bridge。
|
|
4
|
+
*
|
|
5
|
+
* 逻辑实现在可独立类型检查的 inspector-guest-runtime.ts 中;Vite 构建时通过
|
|
6
|
+
* `?injected-runtime` 将其编译成 classic-script 字符串,避免在宿主源码里维护转义代码。
|
|
7
|
+
*/
|
|
8
|
+
export declare const inspectorInjection: InjectionModule;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guest-side bridge source injected before the client JS API UMD.
|
|
3
|
+
*
|
|
4
|
+
* iframe guests post directly to their parent. A top-level Electron webview
|
|
5
|
+
* posts to itself, which the simulator's webview preload forwards over IPC.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SIMULATOR_JSAPI_CHANNEL_SOURCE: string;
|
|
8
|
+
/** Signal readiness only after the client JS API UMD has installed successfully. */
|
|
9
|
+
export declare const SIMULATOR_JSAPI_CHANNEL_READY_SOURCE: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InjectionModule } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* jsapi 注入模块:按启动参数→模拟器通道→客户端 jsapi 的顺序注入到子文档执行环境。
|
|
4
|
+
*
|
|
5
|
+
* 注入策略:
|
|
6
|
+
* - `mode: 'auto'`:若检测到原 HTML 已自带 jsapi(meta 或 script),跳过;
|
|
7
|
+
* 否则注入启动参数、模拟器通道和客户端 UMD
|
|
8
|
+
* - `mode: 'external'`:注入容器启动参数和模拟器通道,JS SDK 由业务自管
|
|
9
|
+
* - `mode: 'off'` / `jsapi.enabled = false`:仅注入容器启动参数
|
|
10
|
+
*
|
|
11
|
+
* 介质适配:
|
|
12
|
+
* - iframe/SW:作为 head 合并 `<script>` 的一段
|
|
13
|
+
* - webview:写入 preload 体内(preload 在 document-start 执行,等同时机)
|
|
14
|
+
*
|
|
15
|
+
* 注:detect external 仅在 iframe 路径生效(webview 拿不到原 HTML);
|
|
16
|
+
* webview 默认按 enabled 决定。
|
|
17
|
+
*/
|
|
18
|
+
/** 与客户端共用的 JS API UMD,不包含模拟器通道实现。 */
|
|
19
|
+
export declare const BUNDLED_CLIENT_JSAPI_SCRIPT: string;
|
|
20
|
+
/** 检测原 HTML 是否已自带 jsapi(meta 显式声明或 script 引入) */
|
|
21
|
+
export declare function detectExternalJsApi(rawHtml: string): boolean;
|
|
22
|
+
export declare const jsapiInjection: InjectionModule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { InjectionModule } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Guest 资源保护:不改写任何浏览器内置 API;卸载时做 best-effort 媒体/Canvas 清理,
|
|
4
|
+
* 并对既有 WebGL 上下文调用标准的 WEBGL_lose_context 主动归还显存(显存不经 V8 GC 回收)。
|
|
5
|
+
* Chromium 可提供 performance.memory 时,按 renderer 总 JS heap 绝对水位熔断失控业务。
|
|
6
|
+
*/
|
|
7
|
+
export declare const resourceGuardInjection: InjectionModule;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InjectionModule } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 小工具截图与首次绘制回报注入模块。
|
|
4
|
+
*
|
|
5
|
+
* head 合并脚本内执行:
|
|
6
|
+
* - 监听宿主 `mini-app:widget-snapshot-request`,用 html-to-image 在 guest 上下文
|
|
7
|
+
* 截取自身文档(抓取 SW 虚拟资源),回传 blob
|
|
8
|
+
* - 观察 FCP / LCP(已绘制的立即回报),首次绘制后向宿主回报
|
|
9
|
+
* `mini-app:widget-first-paint-report`,宿主(远程 Runtime)据此触发自动截图
|
|
10
|
+
*
|
|
11
|
+
* 介质适配:仅 iframe(html-to-image 依赖 guest DOM);webview 截图走原生 capture。
|
|
12
|
+
*/
|
|
13
|
+
export declare const widgetSnapshotInjection: InjectionModule;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { NormalizedMiniAppSimulatorOptions } from "../types";
|
|
2
|
+
import type { InjectionRegistry } from "./registry";
|
|
3
|
+
/**
|
|
4
|
+
* webview preload 拼装入口。
|
|
5
|
+
*
|
|
6
|
+
* 拼接逻辑:
|
|
7
|
+
* 1. **通道桥接 IIFE**(固定,来自 `transport/webview-preload.js`):
|
|
8
|
+
* 建立 `window.message ↔ ipcRenderer.sendToHost` 双向转发。
|
|
9
|
+
* 2. **业务注入**(按当前 options 烤进去):遍历 InjectionRegistry 的
|
|
10
|
+
* `buildPreloadSource`,包含 jsapi UMD / seal IIFE / render-done 等。
|
|
11
|
+
*
|
|
12
|
+
* 两段拼好后写入临时 `file://`,挂到 `<webview preload="...">`。
|
|
13
|
+
* Electron 在 webview 进程 document-start 阶段加载执行——
|
|
14
|
+
* **完全不依赖** `webview.executeJavaScript`(webview 业务能力**不存在** dom-ready 后注入这种路径)。
|
|
15
|
+
*
|
|
16
|
+
* 时序:每次 simulator load 都重新 materialize,options 变更会自动反映到下一次 preload。
|
|
17
|
+
*/
|
|
18
|
+
export interface BuildWebviewPreloadOptions {
|
|
19
|
+
options: NormalizedMiniAppSimulatorOptions;
|
|
20
|
+
injection: InjectionRegistry;
|
|
21
|
+
/** 已知 url(如有,供 base 等场景;preload 不直接需要) */
|
|
22
|
+
appUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 一站式:拼装 preload 源码 + 写入临时 file,返回 `file://` URL。
|
|
26
|
+
* 仅 Electron renderer 环境可用;其它环境返回 null。
|
|
27
|
+
*/
|
|
28
|
+
export declare function materializeWebviewPreload(buildOptions: BuildWebviewPreloadOptions): Promise<string | null>;
|
|
29
|
+
/**
|
|
30
|
+
* 拼接完整 preload 源码(通道桥接 + 业务注入),不写文件。
|
|
31
|
+
* 单独导出便于测试 / debug 输出。
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildWebviewPreloadSource(buildOptions: BuildWebviewPreloadOptions): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* 把 preload 源串物化为 `file://` URL。
|
|
36
|
+
*
|
|
37
|
+
* - 写入 `os.tmpdir()/miniapp-simulator-preload/preload-<sha1>.js`
|
|
38
|
+
* - sha1 取自源码内容,便于幂等复用
|
|
39
|
+
* - 不可用环境(无 require)返回 null
|
|
40
|
+
*/
|
|
41
|
+
export declare function materializePreloadFile(source: string): Promise<string | null>;
|