@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,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顶部 chrome(状态栏时间/信号 + 半屏全屏态返回/分享/更多)底色自适应探测。
|
|
3
|
+
*
|
|
4
|
+
* 背景:小工具半屏拖全后做沉浸式导航,顶部 svg / 状态栏浮于小程序内容之上。
|
|
5
|
+
* 若小程序底色偏深,默认的白色图标尚可见;若底色偏亮,白色图标几乎不可见。
|
|
6
|
+
* 故对 iframe(同源 srcdoc)内容顶部区域采样底色,按通用亮度公式判定明暗,
|
|
7
|
+
* 自动切换 chrome 前景明暗,保证任意底色下都有足够对比度。
|
|
8
|
+
*
|
|
9
|
+
* tone 语义(描述「前景应使用的明暗」,与背景相反):
|
|
10
|
+
* - "light" → 浅色前景(白图标 / 白拖杆),适配深色背景
|
|
11
|
+
* - "dark" → 深色前景(黑图标 / 深拖杆),适配浅色背景
|
|
12
|
+
*/
|
|
13
|
+
export type ChromeTone = "light" | "dark";
|
|
14
|
+
/** 默认 tone:深色前景对应浅底,但模拟器默认底色未知,按设计稿默认浅色前景(深底) */
|
|
15
|
+
export declare const DEFAULT_CHROME_TONE: ChromeTone;
|
|
16
|
+
/** 通用亮度阈值:Y > 128 视为亮底(用深色前景),Y ≤ 128 视为暗底(用浅色前景) */
|
|
17
|
+
export declare const LUMINANCE_THRESHOLD = 128;
|
|
18
|
+
interface Rgb {
|
|
19
|
+
r: number;
|
|
20
|
+
g: number;
|
|
21
|
+
b: number;
|
|
22
|
+
}
|
|
23
|
+
/** 通用亮度公式 Y = 0.299R + 0.587G + 0.114B(0–255) */
|
|
24
|
+
export declare function relativeLuminance({ r, g, b }: Rgb): number;
|
|
25
|
+
/** 亮度转 tone:亮底用深前景,暗底用浅前景 */
|
|
26
|
+
export declare function luminanceToTone(luminance: number): ChromeTone;
|
|
27
|
+
/**
|
|
28
|
+
* 解析 getComputedStyle 返回的背景色(仅 rgb()/rgba(),浏览器计算值恒为此形式)。
|
|
29
|
+
* 返回含 alpha;无法解析或全透明返回 null。
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseCssColor(value: string | null | undefined): (Rgb & {
|
|
32
|
+
a: number;
|
|
33
|
+
}) | null;
|
|
34
|
+
/**
|
|
35
|
+
* 自元素向上回溯祖先链,取第一个不透明(alpha ≥ 0.5)的背景色。
|
|
36
|
+
* 全链透明时回退到浏览器默认白底。
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveBackgroundColor(el: Element | null, view: Window & typeof globalThis): Rgb;
|
|
39
|
+
/**
|
|
40
|
+
* 探测同源 iframe 顶部内容底色对应的 chrome tone。
|
|
41
|
+
* 跨域或文档未就绪时返回 null(调用方据此保留当前 tone)。
|
|
42
|
+
*/
|
|
43
|
+
export declare function detectChromeToneFromIframe(iframe: HTMLIFrameElement): ChromeTone | null;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { XhsNotePreviewData } from "../../types";
|
|
2
|
+
/** REDNote 壳层默认用户头像(导航栏兜底) */
|
|
3
|
+
export declare const DEFAULT_AVATAR = "https://picasso-static.xiaohongshu.com/fe-platform/6544a4b19792523b3a9c97aa0fec738f821381cf.png";
|
|
4
|
+
/**
|
|
5
|
+
* REDNote 详情半屏 Sheet 的默认 resting 高度比例。
|
|
6
|
+
* 外部 `createMiniAppSimulator({ rednoteDetail: { heightRatio } })` 传入可覆盖;
|
|
7
|
+
* 取值范围 `[0.5, 0.95]`,超出会被 clamp。
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_REDNOTE_HALF_SHEET_HEIGHT_RATIO = 0.75;
|
|
10
|
+
/** 小工具入口卡片默认文案 */
|
|
11
|
+
export declare const DEFAULT_APP_CARD_NAME = "\u5C0F\u5DE5\u5177\u6A21\u62DF\u5668";
|
|
12
|
+
export declare const DEFAULT_APP_CARD_DESC = "\u70B9\u51FB\u300C\u7528\u4E00\u7528\u300D\u6253\u5F00\u5C0F\u5DE5\u5177\u9884\u89C8";
|
|
13
|
+
/** 轮播图片页数,也是分页徽标里的数字总数 */
|
|
14
|
+
export declare const NOTE_GALLERY_IMAGE_COUNT = 2;
|
|
15
|
+
/** 轮播总页数:图片页 + 末尾的小工具尾卡,尾卡同样占一个圆点 */
|
|
16
|
+
export declare const NOTE_GALLERY_TOTAL: number;
|
|
17
|
+
/** 占位页插画(设计稿 placeholder/笔记) */
|
|
18
|
+
export declare const NOTE_GALLERY_PLACEHOLDER_ICON = "https://fe-platform.xhscdn.com/platform/104101l0324qamsiqgo06277180ac7t8006ptl0ev7ed16.png";
|
|
19
|
+
/** 占位页提示文案 */
|
|
20
|
+
export declare const NOTE_GALLERY_PLACEHOLDER_TEXT = "\u6B64\u5904\u4E3A\u53D1\u5E03\u9875\u4E0A\u4F20\u7684\u56FE\u7247";
|
|
21
|
+
/** 个人页小工具卡片右上角「笔记类型」角标(设计稿原图:深灰半透明圆底 + 白色图形) */
|
|
22
|
+
export declare const PROFILE_CARD_TYPE_ICON_URL = "https://fe-platform.xhscdn.com/platform/104101l0325aul06cl006277180ac7t8006ptl09n4ess6.png";
|
|
23
|
+
/**
|
|
24
|
+
* 各占位页底色(设计稿)。第一张比后续更深,否则相邻两张纯色占位切换时看不出差别。
|
|
25
|
+
* 页数超出数组长度时复用最后一档。
|
|
26
|
+
*/
|
|
27
|
+
export declare const NOTE_GALLERY_PLACEHOLDER_BG: string[];
|
|
28
|
+
export declare const DEFAULT_NOTE_PREVIEW: XhsNotePreviewData;
|
|
29
|
+
export declare function mergeNotePreview(partial?: XhsNotePreviewData): XhsNotePreviewData;
|
|
30
|
+
export declare function formatRatio(ratio: number): number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REDNote 半屏 Sheet 拖拽吸附(iOS bottom sheet 风格)。
|
|
3
|
+
*
|
|
4
|
+
* 实现要点(解耦 Web Component,便于单测/复用):
|
|
5
|
+
* - sheet 底部锚定(bottom:0),通过**改变自身高度**向上增高露出
|
|
6
|
+
* → iframe 填满 sheet,视口高度 = 可见高度,随高度变化而回流
|
|
7
|
+
* (H5 的 `position:fixed; bottom:0` 元素始终贴在可见底部,对齐真机半屏 webview resize)
|
|
8
|
+
* - 手指位移 1px === 高度变化 1px(顶边跟手),按下与拖动位置严格一致
|
|
9
|
+
* - 松手按阈值吸附到 half / full
|
|
10
|
+
*
|
|
11
|
+
* 坐标约定(visible = sheet 当前高度):
|
|
12
|
+
* visible = bounds → 全屏,sheet 铺满
|
|
13
|
+
* visible = halfVisiblePx → 半屏,露出屏幕高度的 halfRatio
|
|
14
|
+
* visible = 0 → 关闭,高度归零
|
|
15
|
+
* visibleRatio = visible / bounds
|
|
16
|
+
*/
|
|
17
|
+
export type HalfSheetSnapState = "closed" | "half" | "full";
|
|
18
|
+
export interface HalfSheetDragConfig {
|
|
19
|
+
/** 半屏 resting 时的可见比例,[0.5, 0.95],默认由宿主提供 */
|
|
20
|
+
halfHeightRatio: number;
|
|
21
|
+
/** visible ≥ 此值 → 进入全屏。默认 = half + (1 - half) * 0.55 */
|
|
22
|
+
expandThresholdRatio?: number;
|
|
23
|
+
/** visible ≤ 此值 → 回到半屏。默认 = half + (1 - half) * 0.35 */
|
|
24
|
+
collapseThresholdRatio?: number;
|
|
25
|
+
/** 半屏向下拖拽,可见比例 ≤ 此值(即 sheet 进入屏幕底部 20% 区域)→ 关闭。默认 0.2 */
|
|
26
|
+
closeThresholdRatio?: number;
|
|
27
|
+
/** 全屏态下,sheet 顶部多少比例区域可触发下拖。默认 0.08 */
|
|
28
|
+
topDragZoneRatio?: number;
|
|
29
|
+
/** snap 动画时长(ms),默认 280 */
|
|
30
|
+
snapTransitionMs?: number;
|
|
31
|
+
/** 初始吸附态,默认 `half` */
|
|
32
|
+
initialState?: HalfSheetSnapState;
|
|
33
|
+
/** 锁定拖拽:为 true 时禁止一切指针拖拽(程序化 snapTo 仍可用) */
|
|
34
|
+
locked?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface HalfSheetDragAttachOptions extends HalfSheetDragConfig {
|
|
37
|
+
sheet: HTMLElement;
|
|
38
|
+
handle: HTMLElement;
|
|
39
|
+
/** bounds 高度(一般是 sheet 的父容器 clientHeight) */
|
|
40
|
+
getBoundsHeight: () => number;
|
|
41
|
+
/**
|
|
42
|
+
* 整机屏幕高度(用于半屏 resting 高度按「屏幕高度」计算,而非 bounds)。
|
|
43
|
+
* bounds 通常已扣除顶部状态栏,若半屏比例要对齐「屏幕高度的 N%」需用此值。
|
|
44
|
+
* 不提供时回退用 bounds。
|
|
45
|
+
*/
|
|
46
|
+
getViewportHeight?: () => number;
|
|
47
|
+
/** 全屏态附加可拖拽区域(status + nav 顶栏,用于下拖返回半屏) */
|
|
48
|
+
fullScreenDragZone?: HTMLElement;
|
|
49
|
+
onStateChange?: (state: HalfSheetSnapState) => void;
|
|
50
|
+
}
|
|
51
|
+
export interface HalfSheetDragController {
|
|
52
|
+
getState(): HalfSheetSnapState;
|
|
53
|
+
/** 外部更新半屏 resting 比例(如 attribute 变更) */
|
|
54
|
+
setHalfHeightRatio(ratio: number): void;
|
|
55
|
+
/** 程序化吸附 */
|
|
56
|
+
snapTo(state: HalfSheetSnapState, animate?: boolean): void;
|
|
57
|
+
/** 窗口尺寸变化后重算 offset(保持当前 state) */
|
|
58
|
+
refresh(): void;
|
|
59
|
+
destroy(): void;
|
|
60
|
+
}
|
|
61
|
+
export declare function attachHalfSheetDrag(options: HalfSheetDragAttachOptions): HalfSheetDragController;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** 注册小红书笔记预览相关 Web Components(幂等) */
|
|
2
|
+
export declare function registerRednotePreviewElements(): void;
|
|
3
|
+
export { XHS_NOTE_DETAIL_SHELL_TAG, XhsNoteDetailShell, } from "./xhs-note-detail-shell";
|
|
4
|
+
export { XHS_NOTE_HALF_SHEET_TAG, XhsNoteHalfSheet, } from "./xhs-note-half-sheet";
|
|
5
|
+
export { XHS_PROFILE_SHELL_TAG, XhsProfileShell, } from "./xhs-profile-shell";
|
|
6
|
+
export { DEFAULT_NOTE_PREVIEW, DEFAULT_REDNOTE_HALF_SHEET_HEIGHT_RATIO, mergeNotePreview, } from "./defaults";
|
|
7
|
+
export { attachHalfSheetDrag, type HalfSheetDragAttachOptions, type HalfSheetDragConfig, type HalfSheetDragController, type HalfSheetSnapState, } from "./half-sheet-drag";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** 共享 design token(基于创作者发布页 ImagePreview / CoverPreview) */
|
|
2
|
+
/** 手机顶部状态栏高度(390 逻辑宽 iOS 模拟器) */
|
|
3
|
+
export declare const STATUS_BAR_HEIGHT = 44;
|
|
4
|
+
export declare const REDNOTE_CSS_VARS = "\n :host {\n --xhs-red: #ff2442;\n --xhs-title: rgba(0, 0, 0, 0.8);\n --xhs-paragraph: rgba(0, 0, 0, 0.62);\n --xhs-fill: #f5f5f5;\n --xhs-bg: #ffffff;\n --xhs-sheet-radius: 16px;\n --xhs-status-bar-height: 44px;\n font-family: \"PingFang SC\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n display: block;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n user-select: none;\n -webkit-user-select: none;\n -webkit-touch-callout: none;\n }\n *, *::before, *::after {\n box-sizing: border-box;\n user-select: none;\n -webkit-user-select: none;\n -webkit-touch-callout: none;\n }\n img, a, svg {\n -webkit-user-drag: none;\n user-drag: none;\n }\n";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { MiniAppContentMode, NormalizedRednoteDetailSheetOptions, XhsNotePreviewData } from "../../types";
|
|
2
|
+
declare const TAG = "xhs-note-detail-shell";
|
|
3
|
+
export declare class XhsNoteDetailShell extends HTMLElement {
|
|
4
|
+
private _data;
|
|
5
|
+
private _sheetOptions;
|
|
6
|
+
private _halfSheet;
|
|
7
|
+
/** 启动模式:half(下滑收起)/ fullscreen(右侧滑入、初始全屏、锁定拖拽) */
|
|
8
|
+
private _launchMode;
|
|
9
|
+
/** 状态栏时钟定时器,组件卸载时清理 */
|
|
10
|
+
private _statusTimeTimer;
|
|
11
|
+
/** 轮播当前停留位;默认停在最后一档(小工具聚焦) */
|
|
12
|
+
private _galleryIndex;
|
|
13
|
+
/** 壳层内容收起回调(下滑 / 全屏返回 → snap "closed") */
|
|
14
|
+
onContentClose?: () => void;
|
|
15
|
+
/** 壳层内容重新唤起回调(从 closed 再次打开) */
|
|
16
|
+
onContentOpen?: () => void;
|
|
17
|
+
/** 点击入口时先判断是否允许唤起;拒绝时保持笔记页,不展示空内容容器。 */
|
|
18
|
+
onContentOpenRequest?: () => boolean;
|
|
19
|
+
/** 导航栏头像点击 → 跳转个人页 */
|
|
20
|
+
onAvatarClick?: () => void;
|
|
21
|
+
set notePreview(value: XhsNotePreviewData | null);
|
|
22
|
+
get notePreview(): XhsNotePreviewData | null;
|
|
23
|
+
set sheetOptions(value: NormalizedRednoteDetailSheetOptions);
|
|
24
|
+
set launchMode(value: MiniAppContentMode);
|
|
25
|
+
get launchMode(): MiniAppContentMode;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
disconnectedCallback(): void;
|
|
28
|
+
/** 半屏内的内容载体挂载点(载体可为 <iframe> 或 <webview>,与具体渲染器无关) */
|
|
29
|
+
getContentMountTarget(): HTMLElement;
|
|
30
|
+
setHasAppUrl(hasApp: boolean): void;
|
|
31
|
+
/** 收起小工具页,等待半屏/全屏退场结束后回到笔记详情页。 */
|
|
32
|
+
closeContent(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* 外部唤起小工具内容(先过准入检查);`sheetMode` 指定半屏 / 全屏吸附态。
|
|
35
|
+
* 供 `redirectTo("minitool", { sheetMode })` 与个人页卡片点击使用。
|
|
36
|
+
*/
|
|
37
|
+
openContent(sheetMode?: "half" | "full"): void;
|
|
38
|
+
/**
|
|
39
|
+
* 模拟触摸时隐藏系统光标(改由 gesture 的「手指圆点」表示指针)。
|
|
40
|
+
* shadow DOM 内部各元素自带 cursor 规则会覆盖外部继承的 `none`,
|
|
41
|
+
* 故需向 shadowRoot 注入 `cursor: none` 强制规则,并向半屏透传。
|
|
42
|
+
*/
|
|
43
|
+
setSimulatedCursorHidden(hidden: boolean): void;
|
|
44
|
+
private render;
|
|
45
|
+
private requestContentOpen;
|
|
46
|
+
/**
|
|
47
|
+
* 轮播页 DOM:前 NOTE_GALLERY_IMAGE_COUNT 页是发布图(缺图时按页取色占位),
|
|
48
|
+
* 末页是小工具尾卡。尾卡与图片同在 track 内,因此切换共用同一段位移过渡。
|
|
49
|
+
*/
|
|
50
|
+
private buildGalleryPages;
|
|
51
|
+
/** 绑定左右翻页箭头,以及点击「小工具」tag 直接跳到尾卡 */
|
|
52
|
+
private bindGalleryArrows;
|
|
53
|
+
private goToGalleryPage;
|
|
54
|
+
/** 同步轮播位移、分页徽标焦点、圆点与箭头可用态 */
|
|
55
|
+
private renderGallery;
|
|
56
|
+
/** 外链头像加载失败时回退到内置默认图 */
|
|
57
|
+
private bindAvatarFallback;
|
|
58
|
+
/** 刷新状态栏时间为当前本地时间 */
|
|
59
|
+
private updateStatusTime;
|
|
60
|
+
/** 启动状态栏时钟:立即显示并在每分钟整点刷新 */
|
|
61
|
+
private startStatusTimeClock;
|
|
62
|
+
/** 停止状态栏时钟,避免组件卸载后仍更新 DOM */
|
|
63
|
+
private stopStatusTimeClock;
|
|
64
|
+
/** 仅增量更新顶栏用户信息、封面与小工具卡片(标题/正文为骨架占位,无需更新) */
|
|
65
|
+
private renderChrome;
|
|
66
|
+
/** 增量更新笔记内小工具入口卡片(名称 / 描述 / 图标) */
|
|
67
|
+
private renderAppCard;
|
|
68
|
+
}
|
|
69
|
+
export declare function defineXhsNoteDetailShell(): void;
|
|
70
|
+
export { TAG as XHS_NOTE_DETAIL_SHELL_TAG };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type ChromeTone } from "./chrome-tone";
|
|
2
|
+
import { type HalfSheetSnapState } from "./half-sheet-drag";
|
|
3
|
+
declare const TAG = "xhs-note-half-sheet";
|
|
4
|
+
export declare class XhsNoteHalfSheet extends HTMLElement {
|
|
5
|
+
static get observedAttributes(): string[];
|
|
6
|
+
private _bodyEl;
|
|
7
|
+
private _placeholderEl;
|
|
8
|
+
private _sheetEl;
|
|
9
|
+
private _handleEl;
|
|
10
|
+
private _fullChromeEl;
|
|
11
|
+
private _fullScreenDragZoneEl;
|
|
12
|
+
private _backBtn;
|
|
13
|
+
private _drag;
|
|
14
|
+
private _resizeObserver;
|
|
15
|
+
/** 监听 body 内 iframe 的挂载/替换,挂载后绑定 load/scroll 触发底色探测 */
|
|
16
|
+
private _iframeObserver;
|
|
17
|
+
/** 当前被探测的内容载体(iframe),用于解绑事件 */
|
|
18
|
+
private _watchedIframe;
|
|
19
|
+
private _detachIframeListeners;
|
|
20
|
+
/** 底色探测节流句柄(rAF),避免 scroll 高频触发 */
|
|
21
|
+
private _toneRafId;
|
|
22
|
+
/** 当前 chrome tone(默认浅色前景,适配深底) */
|
|
23
|
+
private _chromeTone;
|
|
24
|
+
/** 吸附态变化回调(供详情壳同步背景遮罩等外层 chrome) */
|
|
25
|
+
onSnapStateChange?: (state: HalfSheetSnapState) => void;
|
|
26
|
+
/** chrome 底色明暗变化回调(供详情壳同步状态栏时间/信号明暗) */
|
|
27
|
+
onChromeToneChange?: (tone: ChromeTone) => void;
|
|
28
|
+
/** 内部状态,勿用 attribute(改 attribute 会触发 render 并清掉已挂载的 iframe) */
|
|
29
|
+
private _hasApp;
|
|
30
|
+
connectedCallback(): void;
|
|
31
|
+
disconnectedCallback(): void;
|
|
32
|
+
private attachResizeObserver;
|
|
33
|
+
/**
|
|
34
|
+
* 监听 body 内载体变化:渲染器会向 .body 挂载 / 替换 iframe,
|
|
35
|
+
* 每次有 iframe 出现都重新绑定 load/scroll 并探测底色。
|
|
36
|
+
*/
|
|
37
|
+
private attachIframeObserver;
|
|
38
|
+
/** 找到当前 body 内的 iframe;若与已监听的不同则重新绑定 */
|
|
39
|
+
private syncWatchedIframe;
|
|
40
|
+
private unwatchIframe;
|
|
41
|
+
/** rAF 节流的底色探测 */
|
|
42
|
+
private scheduleToneDetection;
|
|
43
|
+
private detectAndApplyTone;
|
|
44
|
+
/** 应用 chrome tone:驱动顶栏 icon 圆底/前景色与拖杆明暗,并向详情壳透传 */
|
|
45
|
+
private applyChromeTone;
|
|
46
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
47
|
+
/** 是否全屏模式(launch-mode="fullscreen"):初始即 full、锁定拖拽、右侧滑入/滑出 */
|
|
48
|
+
private isFullscreenMode;
|
|
49
|
+
/** 内容载体挂载容器(半屏 body 区域;载体可为 iframe 或 webview) */
|
|
50
|
+
getSheetBody(): HTMLDivElement;
|
|
51
|
+
/** 当前 sheet 吸附态(closed / half / full) */
|
|
52
|
+
getSnapState(): HalfSheetSnapState;
|
|
53
|
+
/** 唤起壳层内容:全屏模式从右侧滑入 full,半屏模式向上升起到 half(由详情页「使用」按钮触发) */
|
|
54
|
+
open(animate?: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* 以指定吸附态唤起内容:全屏模式恒为 full(右侧滑入);
|
|
57
|
+
* 半屏模式可指定 half / full(供宿主 `redirectTo("minitool", { sheetMode })` 使用)。
|
|
58
|
+
*/
|
|
59
|
+
openAtSnap(snap: "half" | "full", animate?: boolean): void;
|
|
60
|
+
/** 关闭壳层内容,回到详情页背景(全屏模式向右滑出,半屏模式向下收起) */
|
|
61
|
+
close(animate?: boolean): void;
|
|
62
|
+
/**
|
|
63
|
+
* 收起并等待退场动画结束。用于资源超限等必须先回到笔记页、再展示宿主提示的流程。
|
|
64
|
+
* 以超时兜底处理 display/transition 被外部样式关闭的情况,保证不会阻塞主流程。
|
|
65
|
+
*/
|
|
66
|
+
closeAndWait(animate?: boolean): Promise<void>;
|
|
67
|
+
/** 程序化回到半屏 */
|
|
68
|
+
collapseToHalf(animate?: boolean): void;
|
|
69
|
+
/** 模拟触摸时隐藏系统光标(与详情壳层一致,由「手指圆点」表示指针) */
|
|
70
|
+
setSimulatedCursorHidden(hidden: boolean): void;
|
|
71
|
+
setHasApp(hasApp: boolean): void;
|
|
72
|
+
setPlaceholderText(text: string): void;
|
|
73
|
+
private syncHalfHeightRatio;
|
|
74
|
+
/** 外部容器尺寸变化后调用,重新对齐 translate 偏移 */
|
|
75
|
+
refreshDragLayout(): void;
|
|
76
|
+
private applyPlaceholderText;
|
|
77
|
+
private readHeightRatio;
|
|
78
|
+
/**
|
|
79
|
+
* placeholder 与 body 都常驻 DOM 但层叠:
|
|
80
|
+
* - body 始终 display:block,里面 iframe 永远在线(gesture overlay 也挂在这里,
|
|
81
|
+
* 若隐藏 body 会导致 hover-indicator 圆点消失)
|
|
82
|
+
* - placeholder absolute 覆盖在 body 之上;未挂载 app 时显示,挂载后隐藏
|
|
83
|
+
*/
|
|
84
|
+
private updatePlaceholderVisibility;
|
|
85
|
+
private mountDragController;
|
|
86
|
+
/** 全屏入场:sheet 从右侧屏外滑入到 0 */
|
|
87
|
+
private slideInFromRight;
|
|
88
|
+
/** 全屏退场:sheet 向右滑出后再收起高度(露出详情页背景) */
|
|
89
|
+
private slideOutToRight;
|
|
90
|
+
/**
|
|
91
|
+
* 半屏 / 全屏 chrome 切换(class 由 drag 控制器统一维护,这里仅做语义钩子位)。
|
|
92
|
+
* 半屏只有 handle;全屏显示返回按钮(status 由 detail-shell 提供)。
|
|
93
|
+
*/
|
|
94
|
+
private applySnapChrome;
|
|
95
|
+
private bindFullChromeActions;
|
|
96
|
+
/** 仅首次构建 DOM;后续增量更新,避免 innerHTML 清掉 iframe */
|
|
97
|
+
private render;
|
|
98
|
+
}
|
|
99
|
+
export declare function defineXhsNoteHalfSheet(): void;
|
|
100
|
+
export { TAG as XHS_NOTE_HALF_SHEET_TAG };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { XhsProfilePreviewData, XhsWidgetCoverData } from "../../types";
|
|
2
|
+
declare const TAG = "xhs-profile-shell";
|
|
3
|
+
/**
|
|
4
|
+
* 个人页壳层(Web Component):深色资料区(头像 / 统计 / 简介 / 组件占位)
|
|
5
|
+
* + 白色内容区(笔记/作品 tab、小工具 subtab、两列卡片瀑布流)。
|
|
6
|
+
* 「作品 → 小工具」首个卡片由 widgetCover(title / cover)驱动,用户信息来自 profilePreview.user。
|
|
7
|
+
*/
|
|
8
|
+
export declare class XhsProfileShell extends HTMLElement {
|
|
9
|
+
private _data;
|
|
10
|
+
private _cover;
|
|
11
|
+
private _statusTimeTimer;
|
|
12
|
+
/** 返回按钮(导航栏左侧图标)点击 → 回笔记页 */
|
|
13
|
+
onBackClick?: () => void;
|
|
14
|
+
/** 首个小工具卡片角标点击 → 唤起小工具内容 */
|
|
15
|
+
onWidgetCardClick?: () => void;
|
|
16
|
+
set widgetCover(value: XhsWidgetCoverData | null);
|
|
17
|
+
get widgetCover(): XhsWidgetCoverData | null;
|
|
18
|
+
set profilePreview(value: XhsProfilePreviewData | null);
|
|
19
|
+
get profilePreview(): XhsProfilePreviewData | null;
|
|
20
|
+
connectedCallback(): void;
|
|
21
|
+
disconnectedCallback(): void;
|
|
22
|
+
private render;
|
|
23
|
+
/** 增量更新首个小工具卡片(widgetCover)与用户名;未注入数据时首个卡片保持占位态 */
|
|
24
|
+
private renderDynamic;
|
|
25
|
+
/** 刷新状态栏时间为当前本地时间 */
|
|
26
|
+
private updateStatusTime;
|
|
27
|
+
private startStatusTimeClock;
|
|
28
|
+
private stopStatusTimeClock;
|
|
29
|
+
}
|
|
30
|
+
export declare function defineXhsProfileShell(): void;
|
|
31
|
+
export { TAG as XHS_PROFILE_SHELL_TAG };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 手机框内 toast 控制器:挂载在 renderer 的 contentRoot 上(覆盖手机框视口,随缩放层一起缩放),
|
|
3
|
+
* 用 `position: absolute` 相对手机屏幕居中——区别于 `showHostToast` 的 `position: fixed`(相对整页视口)。
|
|
4
|
+
*
|
|
5
|
+
* 用于「假 jsapi」在手机壳内给出提示(如 openRedPage → 请前往真机调试)。
|
|
6
|
+
*/
|
|
7
|
+
export interface FrameToastOptions {
|
|
8
|
+
duration?: number;
|
|
9
|
+
}
|
|
10
|
+
/** 手机框内 toast 控制器,挂载在 contentRoot 上。 */
|
|
11
|
+
export declare class FrameToastHost {
|
|
12
|
+
private readonly mountEl;
|
|
13
|
+
private container;
|
|
14
|
+
constructor(mountEl: HTMLElement);
|
|
15
|
+
private ensureContainer;
|
|
16
|
+
show(text: string, options?: FrameToastOptions): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 简单的宿主侧 toast 工具。
|
|
3
|
+
*
|
|
4
|
+
* - 默认挂在 `document.body`;传入 `root`(如 shadow root / shadow host)时挂到该根内,
|
|
5
|
+
* 保证 Shadow DOM 隔离下样式仍生效、不逸出宿主页面
|
|
6
|
+
* - 使用 `position: fixed`,不受手机壳遮罩与 iframe 沙盒影响
|
|
7
|
+
* - 多条消息纵向堆叠,自动淡入淡出
|
|
8
|
+
* - 每个挂载根共用一个容器,避免重复创建
|
|
9
|
+
*/
|
|
10
|
+
/** 挂载根:document.body(默认)/ shadow root / 普通元素 */
|
|
11
|
+
type ToastRoot = ShadowRoot | HTMLElement;
|
|
12
|
+
export interface HostToastOptions {
|
|
13
|
+
duration?: number;
|
|
14
|
+
/** 挂载根;默认 `document.body`,Shadow DOM 隔离时传 shadow root / host */
|
|
15
|
+
root?: ToastRoot;
|
|
16
|
+
}
|
|
17
|
+
export type HostToastFn = (text: string, options?: HostToastOptions) => void;
|
|
18
|
+
export declare function showHostToast(text: string, options?: HostToastOptions): void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 静态预设资源:设备 viewport 与手机壳贴图(原 utils/{device-presets,phone-frames}.ts 合并)。
|
|
3
|
+
*/
|
|
4
|
+
import type { MiniAppPhoneFrame, MiniAppViewport } from "./types";
|
|
5
|
+
export declare const DEFAULT_VIEWPORT: MiniAppViewport;
|
|
6
|
+
export declare const DEVICE_PRESETS: Record<string, MiniAppViewport>;
|
|
7
|
+
export declare function resolveViewport(device?: string, viewport?: MiniAppViewport): MiniAppViewport;
|
|
8
|
+
export declare const DEFAULT_PHONE_FRAME_ID = "iphone-14-pro-max";
|
|
9
|
+
export declare const PHONE_FRAME_PRESETS: Record<string, MiniAppPhoneFrame>;
|
|
10
|
+
export declare function resolvePhoneFrame(frame?: string | MiniAppPhoneFrame | false): MiniAppPhoneFrame | undefined;
|
|
11
|
+
export declare function listPhoneFrames(): MiniAppPhoneFrame[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { BusinessLine } from "../business-line";
|
|
2
|
+
import type { MiniAppEventMap, MiniAppHostApiController, MiniAppHostApiEntry, MiniAppInspectorSelectionMode, MiniAppLoadFilesResult, MiniAppLoadZipResult, MiniAppPhoneFrame, MiniAppRedirectOptions, MiniAppSceneTreeSnapshot, MiniAppScreenShotResult, MiniAppSimulatorOptions, MiniAppSimulatorRoute, MiniAppViewport, VisualSelection, XhsNoteAppCardData, XhsNotePreviewData, XhsNotePreviewUser, XhsWidgetCoverData } from "../types";
|
|
3
|
+
import { type RemoteLoadTiming } from "./load-timing";
|
|
4
|
+
import { type RemoteMethodArgumentMap, type RemoteSimulatorGatewayOptions, type RemoteSimulatorMethod, type RemoteSimulatorReadyMessage, type RemoteSimulatorSerializableOptions } from "./protocol";
|
|
5
|
+
export interface RemoteMiniAppSimulatorOptions {
|
|
6
|
+
mount: string | HTMLElement;
|
|
7
|
+
/** 模拟器服务入口;SDK 会先请求 `/runtime-manifest` 选择协议对应的 Runtime。 */
|
|
8
|
+
serviceUrl: string;
|
|
9
|
+
/** 主服务不可用时按顺序尝试的备用服务入口。 */
|
|
10
|
+
fallbackServiceUrls?: string[];
|
|
11
|
+
/** 小工具 ID;与业务线同属远端 Runtime 的基础上下文。 */
|
|
12
|
+
appId: string;
|
|
13
|
+
/** 接入平台标识;远端 Runtime 据此选择平台默认行为并写入 APM 公共字段。 */
|
|
14
|
+
businessLine: BusinessLine;
|
|
15
|
+
/** 是否启用远端 Runtime APM,默认启用。 */
|
|
16
|
+
tracker?: boolean;
|
|
17
|
+
/** 注入到 launchOptions.miniToolEnv.gateways 的宿主网关配置。 */
|
|
18
|
+
gateway?: RemoteSimulatorGatewayOptions;
|
|
19
|
+
/** 宿主自定义 bridge 行为;优先于 Runtime 按 businessLine 提供的默认行为。 */
|
|
20
|
+
hostApi?: Record<string, MiniAppHostApiEntry>;
|
|
21
|
+
/**
|
|
22
|
+
* 传给远端 Runtime 的模拟器选项(可序列化部分)。
|
|
23
|
+
* `onRouterChange` / `onScreenShot` 回调留在宿主侧绑定,事件经协议转发触发。
|
|
24
|
+
*/
|
|
25
|
+
options?: RemoteSimulatorSerializableOptions & Pick<MiniAppSimulatorOptions, "onRouterChange" | "onScreenShot">;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
className?: string;
|
|
28
|
+
iframeAllow?: string;
|
|
29
|
+
}
|
|
30
|
+
export type RemoteSimulatorEventHandler = (payload: unknown) => void;
|
|
31
|
+
export interface RemoteMiniAppSimulator {
|
|
32
|
+
readonly iframe: HTMLIFrameElement;
|
|
33
|
+
readonly ready: Promise<RemoteSimulatorReadyMessage>;
|
|
34
|
+
load(): Promise<void>;
|
|
35
|
+
loadZip(source: Blob | ArrayBuffer | Uint8Array, options?: {
|
|
36
|
+
entry?: string;
|
|
37
|
+
}): Promise<MiniAppLoadZipResult>;
|
|
38
|
+
loadFiles(files: RemoteMethodArgumentMap["loadFiles"][0]["files"], options?: RemoteMethodArgumentMap["loadFiles"][0]["options"]): Promise<MiniAppLoadFilesResult>;
|
|
39
|
+
loadApp(url: string, options?: RemoteMethodArgumentMap["loadApp"][1]): Promise<void>;
|
|
40
|
+
unload(): void;
|
|
41
|
+
reload(): Promise<void>;
|
|
42
|
+
capture(options?: {
|
|
43
|
+
fullPage?: boolean;
|
|
44
|
+
}): Promise<Blob>;
|
|
45
|
+
setViewport(viewport: MiniAppViewport): void;
|
|
46
|
+
switchContentMode(mode: "half" | "fullscreen"): Promise<void>;
|
|
47
|
+
switchPhoneFrame(frame: string | MiniAppPhoneFrame | false): Promise<void>;
|
|
48
|
+
permissionSheet: {
|
|
49
|
+
show(kinds?: string[]): Promise<unknown>;
|
|
50
|
+
hide(): void;
|
|
51
|
+
};
|
|
52
|
+
notePreview: {
|
|
53
|
+
update(data: Partial<XhsNotePreviewData>): void;
|
|
54
|
+
updateUser(user: Partial<XhsNotePreviewUser>): void;
|
|
55
|
+
updateAppCard(appCard: Partial<XhsNoteAppCardData>): void;
|
|
56
|
+
};
|
|
57
|
+
/** 更新小工具封面:笔记尾卡 + 个人页卡片两处生效 */
|
|
58
|
+
widgetCover: {
|
|
59
|
+
update(data: Partial<XhsWidgetCoverData>): void;
|
|
60
|
+
};
|
|
61
|
+
redirectTo(route: MiniAppSimulatorRoute, options?: MiniAppRedirectOptions): Promise<void>;
|
|
62
|
+
getCurrentRoute(): Promise<MiniAppSimulatorRoute>;
|
|
63
|
+
/** 主动截图(完整画面);结果同时经 screenShot 事件(source: "manual")回调 */
|
|
64
|
+
screenShot(): Promise<MiniAppScreenShotResult>;
|
|
65
|
+
/**
|
|
66
|
+
* 控制部署完成后是否自动截图并更新小工具封面。默认开启。
|
|
67
|
+
* 已有手动或历史封面时,传入 `false` 可在后续部署中保留当前封面。
|
|
68
|
+
*/
|
|
69
|
+
setAutoScreenShot(flag: boolean): Promise<void>;
|
|
70
|
+
inspector: {
|
|
71
|
+
enable(): void;
|
|
72
|
+
disable(): void;
|
|
73
|
+
toggle(): void;
|
|
74
|
+
isEnabled(): boolean;
|
|
75
|
+
clear(): void;
|
|
76
|
+
setSelectionMode(mode: MiniAppInspectorSelectionMode): void;
|
|
77
|
+
getSelectionMode(): MiniAppInspectorSelectionMode;
|
|
78
|
+
getSceneTree(): Promise<MiniAppSceneTreeSnapshot>;
|
|
79
|
+
selectByRef(ref: string): Promise<VisualSelection | null>;
|
|
80
|
+
};
|
|
81
|
+
hostApi: MiniAppHostApiController;
|
|
82
|
+
invoke<M extends RemoteSimulatorMethod>(method: M, ...args: RemoteMethodArgumentMap[M]): Promise<unknown>;
|
|
83
|
+
on<E extends keyof MiniAppEventMap>(event: E, handler: (payload: MiniAppEventMap[E]) => void): () => void;
|
|
84
|
+
on(event: string, handler: RemoteSimulatorEventHandler): () => void;
|
|
85
|
+
destroy(reason?: string): void;
|
|
86
|
+
}
|
|
87
|
+
export declare function createRemoteMiniAppSimulator(input: RemoteMiniAppSimulatorOptions): RemoteMiniAppSimulator;
|
|
88
|
+
/** @internal Exported for deterministic retry tests; not part of the package public entry. */
|
|
89
|
+
export declare function resolveRuntimeUrl(serviceUrls: URL[], loadTiming: RemoteLoadTiming): Promise<URL>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MiniAppHostApiEntry, MiniAppUnsupportedJsApiBehavior } from "../types";
|
|
2
|
+
type RemoteJsApiNotice = MiniAppUnsupportedJsApiBehavior;
|
|
3
|
+
export type RemoteJsApiConfig = Record<string, RemoteJsApiNotice>;
|
|
4
|
+
/** Server 透传通用 JSON;具体 JSAPI 提示语义只在 Runtime 解析。 */
|
|
5
|
+
export declare function parseRemoteJsApiConfig(input: unknown): RemoteJsApiConfig | undefined;
|
|
6
|
+
export declare function getUnsupportedJsApiBehavior(config?: RemoteJsApiConfig): MiniAppUnsupportedJsApiBehavior | undefined;
|
|
7
|
+
/** `unsupported` 是统一兜底,其余 key 是可覆盖任意 API 的精确配置。 */
|
|
8
|
+
export declare function createConfiguredJsApiHostApi(config?: RemoteJsApiConfig, businessLine?: string): Record<string, MiniAppHostApiEntry>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BusinessLine } from "../business-line";
|
|
2
|
+
export interface RemoteLoadTiming {
|
|
3
|
+
report(stage: string, fields?: RemoteLoadTimingFields): void;
|
|
4
|
+
flush(): void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 加载点位只使用这一组通用字段,避免每增加一个阶段就登记一套字段。
|
|
8
|
+
* 阶段差异统一放在低基数的 stage 中。
|
|
9
|
+
*/
|
|
10
|
+
export interface RemoteLoadTimingFields {
|
|
11
|
+
result?: string;
|
|
12
|
+
duration?: number;
|
|
13
|
+
type?: string;
|
|
14
|
+
count?: number;
|
|
15
|
+
bytes?: number;
|
|
16
|
+
network_duration?: number;
|
|
17
|
+
dns_duration?: number;
|
|
18
|
+
connect_duration?: number;
|
|
19
|
+
ttfb_duration?: number;
|
|
20
|
+
runtime_version?: string;
|
|
21
|
+
request_id?: string;
|
|
22
|
+
code?: number;
|
|
23
|
+
error_name?: string;
|
|
24
|
+
message?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RemoteLoadTimingOptions {
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
businessLine: BusinessLine;
|
|
29
|
+
appId: string;
|
|
30
|
+
sessionId: string;
|
|
31
|
+
runtimeVersion?: string;
|
|
32
|
+
resolveUserId?: () => Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 远程模拟器启动链路复用统一加载点位,避免扩展 MessageChannel 消息并触发协议升级。
|
|
36
|
+
* client/runtime/core 通过协议中已有的 sessionId 关联,stage 用于按阶段聚合 P50/P95/P99。
|
|
37
|
+
*/
|
|
38
|
+
export declare function createRemoteLoadTiming(options: RemoteLoadTimingOptions): RemoteLoadTiming;
|
|
39
|
+
export declare function timingNow(): number;
|
|
40
|
+
export declare function elapsedMs(startedAt: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Resource Timing 可用时补齐通用网络分段字段。
|
|
43
|
+
* 没有 TAO 或浏览器拒绝读取时直接放弃,不影响主链路。
|
|
44
|
+
*/
|
|
45
|
+
export declare function reportResourceTiming(timing: RemoteLoadTiming, stage: string, url: string, fields?: RemoteLoadTimingFields): void;
|
|
46
|
+
export declare function navigationTimingFields(): RemoteLoadTimingFields;
|