mobile-web-bridge 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +163 -2
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/dist/apiManifest.d.ts +1 -0
- package/dist/assembleMWB.d.ts +15 -0
- package/dist/bridge.d.ts +17 -0
- package/dist/browser.d.ts +1 -0
- package/dist/createMWB.d.ts +14 -0
- package/dist/eventHub.d.ts +13 -0
- package/dist/events.d.ts +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +847 -0
- package/dist/mwb.iife.js +831 -0
- package/dist/nativePlugins.d.ts +37 -0
- package/dist/plugins/basic.d.ts +37 -0
- package/dist/plugins/container.d.ts +18 -0
- package/dist/plugins/device.d.ts +15 -0
- package/dist/plugins/media.d.ts +13 -0
- package/dist/plugins/storage.d.ts +10 -0
- package/dist/types.d.ts +550 -0
- package/package.json +53 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gaoxiao228
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mobile Web Bridge JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MWB 为 iOS 和 Android 的 Web 容器提供统一 JS API。原生通信由 DSBridge 3.x 完成。
|
|
4
|
+
|
|
5
|
+
已公开发布 `0.1.1-beta.1`,当前仍处于 Beta 阶段。正式仓库:[gaoxiao228/MobileWebBridge](https://github.com/gaoxiao228/MobileWebBridge)。npm 的 `latest`/`next` 目前均为 Beta,建议固定精确版本;原生接入与支持范围见 [项目 README](https://github.com/gaoxiao228/MobileWebBridge#readme)。
|
|
6
|
+
|
|
7
|
+
## 安装和使用
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install mobile-web-bridge@0.1.1-beta.1
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { mwb } from "mobile-web-bridge";
|
|
15
|
+
|
|
16
|
+
const info = mwb.getAppInfoSync();
|
|
17
|
+
await mwb.toast({ msg: `App: ${info.appId}` });
|
|
18
|
+
// basic 命名空间与根兼容入口共享函数;同步方法仍同步返回。
|
|
19
|
+
const sameInfo = mwb.basic.getAppInfoSync();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
右上角文字按钮由当前 Web 页面设置,点击回调仍在当前页面执行:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
await mwb.setNavigationBarTheme({
|
|
26
|
+
actionTxt: "保存",
|
|
27
|
+
actionExt: "draft-42",
|
|
28
|
+
onActionClick: ({ actionExt }) => console.log("保存按钮被点击", actionExt)
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
再次设置会替换原回调;传入 `actionTxt: ""` 可移除按钮。`onActionClick` 不会序列化传给原生,原生点击时只回传 `actionExt`。目前 iOS、Android 均支持文字按钮,`actionIcon` 尚不支持。
|
|
33
|
+
|
|
34
|
+
网页也可直接引入发布包中的 `dist/mwb.iife.js`,通过 `window.mwb` 调用。应在 MWB 原生容器内加载;普通浏览器中的原生调用会给出“桥未就绪”错误。
|
|
35
|
+
|
|
36
|
+
完整的 H5 方法示例由 [`MWB-Demo-Web`](https://github.com/gaoxiao228/MobileWebBridge/tree/main/MWB-Demo-Web) 维护,可构建为静态站点并同步到 iOS、Android 示例 App。SDK 面向浏览器,不提供 SSR/Node 服务端或 CommonJS 入口;Nuxt 等环境只在客户端导入。
|
|
37
|
+
|
|
38
|
+
## 首屏就绪通知
|
|
39
|
+
|
|
40
|
+
当前源码新增 `await mwb.basic.notifyPageReady()`(也可用根入口 `mwb.notifyPageReady()`),用于 H5 主动通知当前原生容器首屏准备完成。无需注册业务插件,重复调用幂等。成功表示原生接受通知,不代表宿主已完成展示。
|
|
41
|
+
|
|
42
|
+
已发布的 JS `0.1.1-beta.1` 不包含此能力,H5 须使用当前 JS 源码,并搭配 Android Maven `0.1.1` 或当前 iOS 源码;旧原生 `0.1.0` 不支持此能力。此方法走文档身份网关,等待上限 30000ms;旧原生和普通浏览器明确失败。调用时机、原生回调和重载规则见 [接入说明](https://github.com/gaoxiao228/MobileWebBridge/blob/main/docs/page-lifecycle.md)。
|
|
43
|
+
|
|
44
|
+
## 同步与异步调用
|
|
45
|
+
|
|
46
|
+
调用方式由 SDK 的方法声明和对应原生实现共同决定。`mwb.basic.xxx()` 与 `mwb.xxx()` 是同一实现;TypeScript 返回非 Promise 的方法直接使用,返回 Promise 的方法使用 `await` 或 `.then/.catch`。
|
|
47
|
+
|
|
48
|
+
### basic 同步方法
|
|
49
|
+
|
|
50
|
+
basic 中有 9 个同步原生入口:
|
|
51
|
+
|
|
52
|
+
- 信息读取:`getAppInfoSync`、`getDeviceInfoSync`、`getClipboardDataSync`、`getNetworkTypeSync`。
|
|
53
|
+
- 本地存储:`setStorageSync`、`getStorageSync`、`removeStorageSync`、`clearStorageSync`。
|
|
54
|
+
- 调试设置:`setEnableDebug`,立即返回 `void`,名称没有 `Sync` 后缀。
|
|
55
|
+
|
|
56
|
+
同步调用直接返回业务值或 `void`,不会返回 `{errCode, result}` 包装;失败会抛错。桥必须已在当前 MWB 容器中可用(相关错误为 `-1000`),`getAppInfoSync` 还要求宿主配置应用信息;同步不代表无需权限或平台支持。
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { mwb, MWBBridgeError } from "mobile-web-bridge";
|
|
60
|
+
|
|
61
|
+
// 同步读取少量本地数据;不存在的键返回 undefined。
|
|
62
|
+
try {
|
|
63
|
+
mwb.basic.setStorageSync("theme", "dark", "settings");
|
|
64
|
+
const theme = mwb.basic.getStorageSync<string>("theme", "settings");
|
|
65
|
+
console.log(theme);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof MWBBridgeError) console.error(error.errCode, error.errorMsg);
|
|
68
|
+
else console.error(error);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
同步调用仍有跨桥、序列化和系统访问成本;避免在循环、滚动或动画回调中反复调用,也不要在同步原生路径中等待异步任务。`await mwb.getAppInfoSync()` 会先执行同步工作再等待其返回值,不会解除同步阻塞。
|
|
73
|
+
|
|
74
|
+
### basic 异步方法
|
|
75
|
+
|
|
76
|
+
既有 21 个 basic 异步原生入口(例如 `toast`、`navigateTo`、`chooseImage`、`scanCode`)返回 `Promise<GenericAsyncResult<T>>`。成功为 `{errCode: 0, result?: T}`;失败拒绝 Promise,不应只在 `.then` 中检查 errCode。
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { mwb, MWBBridgeError } from "mobile-web-bridge";
|
|
80
|
+
|
|
81
|
+
// 在页面按钮等业务入口中调用;await 保证后续代码在本次响应之后执行。
|
|
82
|
+
async function copyMessage() {
|
|
83
|
+
try {
|
|
84
|
+
await mwb.basic.setClipboardData({ data: "Hello MWB" });
|
|
85
|
+
await mwb.basic.toast({ msg: "已复制" });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error instanceof MWBBridgeError) console.error(error.errCode, error.errorMsg);
|
|
88
|
+
else console.error(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Promise 完成仅表示该方法约定的操作完成:`navigateTo` 成功不等于新页面首屏完成,`toast` 成功不等于提示已消失。具体结果仍以各方法契约为准。
|
|
94
|
+
|
|
95
|
+
除新增 `notifyPageReady()` 外,既有 basic 异步调用没有统一超时及文档失效兜底;原生未回调时可能持续等待。业务添加等待超时只会停止自己的等待,不代表原生操作已取消;支付等操作尤其不能据超时推断业务失败或直接重试。
|
|
96
|
+
|
|
97
|
+
### 事件与自定义插件
|
|
98
|
+
|
|
99
|
+
18 个 JS 句柄/事件方法不属于上述 30 个原生入口。`onAppShow`、`registerHandler` 等注册方法立即返回,回调后续触发;`await mwb.onAppShow(handler)` 不会等待应用进入前台。使用对应 `off` / `unRegister` 方法解绑;插件 `.on()` 返回解绑函数。
|
|
100
|
+
|
|
101
|
+
通过 `defineNativePlugin` 声明的业务方法**只支持 `Promise<GenericAsyncResult<T>>`**。即便原生立即调用 `responder.success`,JS 仍应使用异步契约;不能声明普通对象返回值,也没有 `sync: true` 配置。`hasPlugin` 同样返回 Promise。
|
|
102
|
+
|
|
103
|
+
自定义插件默认超时 30000ms,可配置 `timeoutMs` 为 1..120000 的整数;超时、文档失效和迟到结果按插件 Core 规则处理,这项保证不能套用到其他 basic 方法。取消能否终止实际业务取决于宿主服务;支付等不可撤销的操作还需独立查询最终状态。完整 Swift/Kotlin/H5 实现和同步读取替代方案见 [插件调用方式与线程约定](https://github.com/gaoxiao228/MobileWebBridge/blob/main/docs/native-plugins.md#调用方式与线程约定)。
|
|
104
|
+
|
|
105
|
+
## 插件组合与构建
|
|
106
|
+
|
|
107
|
+
当前源码默认提供 basic 的 49 个方法;已发布包为原有 48 个。源码分为 `container`、`device`、`media`、`storage` 四组;事件和 JS 句柄始终包含在 SDK 内。`basicPlugin` 为完整组合,`--plugins=basic` 可构建全量 basic;与旧分组混用时去重。原有 `createMWB(legacyPlugins)` 数组裁剪入口保留,只在 basic 下映射选中的方法。重复方法或覆盖 Core/事件入口的配置直接报错。
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pnpm install
|
|
111
|
+
pnpm build
|
|
112
|
+
pnpm build:composition --plugins=container,device
|
|
113
|
+
npm pack --dry-run
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
组合脚本在 `dist` 输出 `mwb.container-device.iife.js`。组合产物只暴露选中的功能方法,适合按应用需求自行部署;npm 默认入口仍提供全量接口。`npm pack` 会通过 prepack 自动重新构建并检查入口、声明和许可,防止空包或旧产物。构建和打包命令不执行公开发布。
|
|
117
|
+
|
|
118
|
+
## 自定义原生插件
|
|
119
|
+
|
|
120
|
+
原生 App 必须先安装对应 Swift/Kotlin 插件;JS 描述不会生成原生业务代码。`createMWB({plugins: [...]})` 默认包含完整 basic,并增加插件命名空间:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { createMWB, defineNativePlugin, type GenericAsyncResult } from "mobile-web-bridge";
|
|
124
|
+
|
|
125
|
+
interface NetworkMethods {
|
|
126
|
+
// 实际请求由宿主原生网络服务执行。
|
|
127
|
+
request(params: { url: string; method: "GET" | "POST"; headers?: Record<string, string>; body?: string }):
|
|
128
|
+
Promise<GenericAsyncResult<{ status: number; headers: Record<string, string>; body: string }>>;
|
|
129
|
+
}
|
|
130
|
+
type NetworkEvents = { requestFinished: { url: string; status: number } };
|
|
131
|
+
|
|
132
|
+
const network = defineNativePlugin<NetworkMethods, NetworkEvents>()({
|
|
133
|
+
name: "network", timeoutMs: 30000
|
|
134
|
+
});
|
|
135
|
+
const sdk = createMWB({ plugins: [network] });
|
|
136
|
+
if (await sdk.hasPlugin("network")) {
|
|
137
|
+
const off = sdk.network.on("requestFinished", event => console.log(event));
|
|
138
|
+
const response = await sdk.network.request({ url: "https://example.com", method: "GET" });
|
|
139
|
+
console.log(response.result); // 保留统一 envelope,不自动解包。
|
|
140
|
+
off(); // 组件卸载时也应解绑。
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
没有 `version` 或运行时 `methods` 数组。两阶段 builder 保留插件名字面量及方法/事件类型。新插件只支持异步 Promise;`hasPlugin` 查询原生注册且不创建实例,不代表所有方法都存在;首版不提供 hasMethod。默认 ESM/IIFE 仍只含 basic,使用业务插件时应构建自己的入口脚本。完整 Swift/Kotlin 接入、生命周期及浏览器构建见 [接入文档](https://github.com/gaoxiao228/MobileWebBridge/blob/main/docs/native-plugins.md);可运行入口见 Demo 的 `src/plugins-sdk.ts`。
|
|
145
|
+
|
|
146
|
+
调用参数、成功结果和事件只接受 JSON:拒绝循环、函数、undefined 字段、非有限数字、非普通对象或 getter/setter。省略参数按 null 处理;显式结果 null 保留。超时默认 30000ms,允许整数 1..120000ms,超时以 `MWBBridgeError(-1103)` 拒绝。缺插件/方法分别为 `-1100/-1101`,旧壳无网关为 `-1106`,完整错误表见接入文档。
|
|
147
|
+
|
|
148
|
+
名称采用 `[a-z][a-zA-Z0-9_]*`。插件名不得占用当前 49 个根方法、basic/version/hasPlugin、pluginSession/pluginInfo/invokePlugin/pluginEvent、dispatchEvent/backBtnPressed 或以下探测名。业务方法和事件禁止 `on/then/catch/finally/toJSON/inspect/constructor/prototype/__proto__`;`on` 专用于订阅。读取方法属性不发请求,Proxy 的 Promise/JSON/Symbol 探测不会调用原生。不要通过 `typeof sdk.network.someMethod` 判断原生是否支持该方法,原生才会根据标记方法返回 `-1101`。
|
|
149
|
+
|
|
150
|
+
## 接口约定
|
|
151
|
+
|
|
152
|
+
- 异步方法返回 `{ errCode, errorMsg?, result? }`;`errCode === 0` 表示成功,非零错误通过 Promise 拒绝并保留错误码。
|
|
153
|
+
- 同步方法直接返回附件声明的数据;桥未就绪或方法不可用时抛出 `MWBBridgeError`。
|
|
154
|
+
- `clearStorageSync(groupName?)` 清空指定分组,参数已根据旧实现修正。
|
|
155
|
+
- iOS 的 `exitApp()` 默认返回不支持;Android 默认只关闭当前 MWB 容器。
|
|
156
|
+
- 应用信息、角标、推送和原生页面能力需要宿主应用配置;未配置会返回明确错误。
|
|
157
|
+
|
|
158
|
+
完整参数、返回类型和方法列表见本包 TypeScript 声明。浏览器可通过 `mwb.onPageShow(handler)` 等方法订阅事件,用对应 `off` 方法解绑。宿主使用 `mwb.dispatchEvent`、`mwb.backBtnPressed` 及 `mwb.<handlerName>` 调用 JS。
|
|
159
|
+
|
|
160
|
+
## 来源
|
|
161
|
+
|
|
162
|
+
MWB 的通信底层基于 [DSBridge](https://github.com/wendux/DSBridge-Android)(MIT)。接口能力参考当前工作区的旧项目,MWB 不依赖 Cordova。
|
|
163
|
+
|
|
164
|
+
包内包含 LICENSE 和 THIRD_PARTY_NOTICES.md,ESM/IIFE/组合脚本保留完整许可注释;单独分发 bundle 时也不要移除这些注释。
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# DSBridge third-party notice
|
|
2
|
+
|
|
3
|
+
DSBridge JavaScript 3.1.4: https://www.npmjs.com/package/dsbridge/v/3.1.4
|
|
4
|
+
DSBridge Android 3.0.0: https://github.com/wendux/DSBridge-Android/tree/d3e5ebc6ca8170f97e420f2f482680c8e149b471
|
|
5
|
+
DSBridge iOS 3.0.6: https://github.com/wendux/DSBridge-IOS/tree/f0e3c724dd362800528f8b6c788bdad7006cc187
|
|
6
|
+
|
|
7
|
+
Author: wendux (杜文 / Du Wen), as identified by upstream package metadata and source.
|
|
8
|
+
The upstream npm metadata, Android readme.md and iOS podspec declare MIT.
|
|
9
|
+
The pinned native trees do not provide a separate LICENSE file; the MIT terms
|
|
10
|
+
are reproduced below without inventing an absent upstream copyright notice.
|
|
11
|
+
Original iOS source notices are retained verbatim:
|
|
12
|
+
|
|
13
|
+
Copyright © 2016年 杜文. All rights reserved.
|
|
14
|
+
Copyright © 2018年 杜文. All rights reserved.
|
|
15
|
+
|
|
16
|
+
MIT License
|
|
17
|
+
|
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
in the Software without restriction, including without limitation the rights
|
|
21
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
furnished to do so, subject to the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const apiMethods: readonly ["notifyPageReady", "setEnableDebug", "openAppAuthorizeSetting", "toast", "getAppInfoSync", "setBadgeCount", "navigateTo", "navigateBack", "navigateBackToRoot", "openExternalBrowser", "setNavigationBarTheme", "getDeviceInfoSync", "getClipboardDataSync", "setClipboardData", "makePhoneCall", "getNetworkTypeSync", "getNotificationSwitchStatus", "cleanWebviewCache", "compressImage", "scanCode", "saveImageToPhotosAlbum", "chooseImage", "setStorageSync", "getStorageSync", "removeStorageSync", "clearStorageSync", "openFile", "exitApp", "checkRequestCameraPermissions", "convertImagePathToBase64", "openNativePage", "registerHandler", "unRegisterHandlers", "unRegisterHandler", "checkHandlerExist", "onNetworkStatusChange", "offNetworkStatusChange", "onAppShow", "offAppShow", "onAppHide", "offAppHide", "onRemoteNotificationReceive", "offRemoteNotificationReceive", "onPageShow", "offPageShow", "onPageHide", "offPageHide", "onBackBtnPressed", "offBackBtnPressed"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type MWBJSSDK } from "./types";
|
|
2
|
+
/** 插件描述只包含所选功能,供浏览器组合包静态裁剪。 */
|
|
3
|
+
export interface MWBPlugin {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly methods: Record<string, (...args: never[]) => unknown>;
|
|
6
|
+
}
|
|
7
|
+
/** basic 的根兼容入口与命名空间始终共享同一份函数和事件状态。 */
|
|
8
|
+
export type MWBBasic = Omit<MWBJSSDK, "version">;
|
|
9
|
+
export type MWBSDK = MWBJSSDK & {
|
|
10
|
+
readonly basic: MWBBasic;
|
|
11
|
+
};
|
|
12
|
+
export type MWBPartialSDK = Partial<MWBJSSDK> & {
|
|
13
|
+
readonly basic: Partial<MWBBasic>;
|
|
14
|
+
};
|
|
15
|
+
export declare function assembleMWB(plugins: MWBPlugin[]): MWBPartialSDK;
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GenericAsyncResult } from "./types";
|
|
2
|
+
/** DSBridge 的最小接口,便于把原生通信限制在一个文件内。 */
|
|
3
|
+
export interface DSBridgeLike {
|
|
4
|
+
call(method: string, args?: unknown, callback?: (value: unknown) => void): unknown;
|
|
5
|
+
register?(name: string, handler: (...args: unknown[]) => unknown): void;
|
|
6
|
+
hasNativeMethod?(name: string, type?: string): boolean;
|
|
7
|
+
}
|
|
8
|
+
/** MWB 传输及原生错误统一使用的异常。 */
|
|
9
|
+
export declare class MWBBridgeError extends Error {
|
|
10
|
+
readonly errCode: number;
|
|
11
|
+
readonly errorMsg: string;
|
|
12
|
+
constructor(errCode: number, errorMsg: string);
|
|
13
|
+
}
|
|
14
|
+
/** 只在调用时读取桥,避免服务端渲染或页面初始化阶段直接访问 window。 */
|
|
15
|
+
export declare function getBridge(): DSBridgeLike;
|
|
16
|
+
export declare function callSync<T>(method: string, args?: unknown): T;
|
|
17
|
+
export declare function callAsync<T>(method: string, args?: unknown): Promise<GenericAsyncResult<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MWBPlugin, type MWBSDK, type MWBPartialSDK } from "./assembleMWB";
|
|
2
|
+
import { type MWBNativePlugin, type NativePluginNamespaces } from "./nativePlugins";
|
|
3
|
+
export type { MWBPlugin } from "./assembleMWB";
|
|
4
|
+
export type { MWBSDK, MWBBasic } from "./assembleMWB";
|
|
5
|
+
export { defineNativePlugin } from "./nativePlugins";
|
|
6
|
+
export type { MWBNativePlugin } from "./nativePlugins";
|
|
7
|
+
export type MWBClient = MWBSDK & {
|
|
8
|
+
hasPlugin(name: string): Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createMWB(): MWBClient;
|
|
11
|
+
export declare function createMWB<const Plugins extends readonly MWBNativePlugin[]>(options: {
|
|
12
|
+
plugins: Plugins;
|
|
13
|
+
}): MWBClient & NativePluginNamespaces<Plugins>;
|
|
14
|
+
export declare function createMWB(plugins: MWBPlugin[]): MWBPartialSDK;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DSBridgeLike } from "./bridge";
|
|
2
|
+
type Handler = (...args: unknown[]) => unknown;
|
|
3
|
+
/** 同一 bridge 只注册一次原生接收器,避免默认 SDK 和业务组合实例相互覆盖。 */
|
|
4
|
+
declare class EventHub {
|
|
5
|
+
private readonly bridge;
|
|
6
|
+
private readonly listeners;
|
|
7
|
+
private back?;
|
|
8
|
+
constructor(bridge: DSBridgeLike);
|
|
9
|
+
on(name: string, handler: Handler): () => void;
|
|
10
|
+
setBack(owner: object, handler?: () => boolean): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function getEventHub(bridge: DSBridgeLike): EventHub;
|
|
13
|
+
export {};
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MWBJSSDK } from "./types";
|
|
2
|
+
/** DSBridge 只保留一个注册函数;多监听器和解绑由这一层管理。 */
|
|
3
|
+
export declare function createEvents(): Pick<MWBJSSDK, "registerHandler" | "unRegisterHandlers" | "unRegisterHandler" | "checkHandlerExist" | "onNetworkStatusChange" | "offNetworkStatusChange" | "onAppShow" | "offAppShow" | "onAppHide" | "offAppHide" | "onRemoteNotificationReceive" | "offRemoteNotificationReceive" | "onPageShow" | "offPageShow" | "onPageHide" | "offPageHide" | "onBackBtnPressed" | "offBackBtnPressed">;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** 默认入口组合全部能力,同时保留按功能组合的构造函数。 */
|
|
2
|
+
import "dsbridge";
|
|
3
|
+
export { createMWB, defineNativePlugin } from "./createMWB";
|
|
4
|
+
export type { MWBPlugin, MWBNativePlugin, MWBClient, MWBSDK, MWBBasic } from "./createMWB";
|
|
5
|
+
export { MWBBridgeError } from "./bridge";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
export { containerPlugin } from "./plugins/container";
|
|
8
|
+
export { devicePlugin } from "./plugins/device";
|
|
9
|
+
export { mediaPlugin } from "./plugins/media";
|
|
10
|
+
export { storagePlugin } from "./plugins/storage";
|
|
11
|
+
export { basicPlugin } from "./plugins/basic";
|
|
12
|
+
import type { MWBClient } from "./createMWB";
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
mwb: MWBClient;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const mwb: MWBClient;
|
|
19
|
+
export default mwb;
|