@dino-dev/bridge-core-ts 0.0.2 → 0.0.4
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 +25 -2
- package/dist/generated/data_provider.d.ts +13 -0
- package/dist/generated/data_provider.d.ts.map +1 -0
- package/dist/generated/data_provider.js +6 -0
- package/dist/generated/data_provider.js.map +1 -0
- package/dist/generated/index.d.ts +16 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +16 -0
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/message_read.d.ts +18 -0
- package/dist/generated/message_read.d.ts.map +1 -0
- package/dist/generated/message_read.js +6 -0
- package/dist/generated/message_read.js.map +1 -0
- package/dist/generated/sound_effects.d.ts +25 -0
- package/dist/generated/sound_effects.d.ts.map +1 -0
- package/dist/generated/sound_effects.js +6 -0
- package/dist/generated/sound_effects.js.map +1 -0
- package/dist/generated/tts_player.d.ts +69 -0
- package/dist/generated/tts_player.d.ts.map +1 -0
- package/dist/generated/tts_player.js +6 -0
- package/dist/generated/tts_player.js.map +1 -0
- package/dist/src/adaptation.d.ts +19 -0
- package/dist/src/adaptation.d.ts.map +1 -0
- package/dist/src/adaptation.js +59 -0
- package/dist/src/adaptation.js.map +1 -0
- package/dist/src/content-protocol.d.ts +44 -1
- package/dist/src/content-protocol.d.ts.map +1 -1
- package/dist/src/content-protocol.js +36 -0
- package/dist/src/content-protocol.js.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/system-module.d.ts +17 -0
- package/dist/src/system-module.d.ts.map +1 -1
- package/dist/src/system-module.js.map +1 -1
- package/generated/data_provider.ts +17 -0
- package/generated/index.ts +34 -0
- package/generated/message_read.ts +21 -0
- package/generated/sound_effects.ts +69 -0
- package/generated/tts_player.ts +84 -0
- package/package.json +3 -2
- package/src/adaptation.ts +83 -0
- package/src/content-protocol.ts +69 -2
- package/src/index.ts +33 -20
- package/src/system-module.ts +34 -15
package/README.md
CHANGED
|
@@ -129,6 +129,29 @@ const { modules } = await system.getAvailableModules();
|
|
|
129
129
|
const info = await system.getContainerInfo();
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
## App 统一屏幕适配
|
|
133
|
+
|
|
134
|
+
在使用设计稿尺寸的 H5 中初始化一次,即可使用与 Flutter `.ar` 相同的缩放规则:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import {
|
|
138
|
+
ar,
|
|
139
|
+
getArScale,
|
|
140
|
+
initArAdaptation,
|
|
141
|
+
onArAdaptationChange,
|
|
142
|
+
} from '@h5-container/bridge-core-ts';
|
|
143
|
+
|
|
144
|
+
await initArAdaptation();
|
|
145
|
+
const style = { width: ar(120), fontSize: ar(18) };
|
|
146
|
+
|
|
147
|
+
// React 等框架可在回调中更新 state,触发使用 ar() 的样式重新计算。
|
|
148
|
+
const unsubscribe = onArAdaptationChange(() => {
|
|
149
|
+
setScale(getArScale());
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
App 横竖屏或窗口尺寸变化时,SDK 会自动更新比例并触发订阅回调。组件销毁时调用 `unsubscribe()`。当前工具覆盖 TS/TSX 数值样式;CSS 全局适配暂不自动修改页面根字号。
|
|
154
|
+
|
|
132
155
|
## 标准内容协议
|
|
133
156
|
|
|
134
157
|
SDK 为内容型 H5 固定定义以下协议域:
|
|
@@ -140,7 +163,7 @@ SDK 为内容型 H5 固定定义以下协议域:
|
|
|
140
163
|
| Flutter → H5 | `render` | `clear` | `{}` |
|
|
141
164
|
| H5 → Flutter | `render` | `ready` | 应用能力信息 |
|
|
142
165
|
| H5 → Flutter | `render` | `applied` | 已执行操作信息 |
|
|
143
|
-
| H5 → Flutter | `interaction` | 业务动作 | `{
|
|
166
|
+
| H5 → Flutter | `interaction` | 业务动作 | `{ source_id, value?, ... }` |
|
|
144
167
|
| H5 → Flutter | `error` | `report` | `{ source, code, message, details? }` |
|
|
145
168
|
|
|
146
169
|
H5 通过 `bindRenderProtocol()` 接收渲染消息,通过 `renderProtocol`、`interaction` 和 `bridgeError` 上报事件:
|
|
@@ -160,7 +183,7 @@ const unsubscribe = bindRenderProtocol({
|
|
|
160
183
|
});
|
|
161
184
|
|
|
162
185
|
await renderProtocol.ready({ supportedOrientations: ['portrait'] });
|
|
163
|
-
await interaction.send('submit', {
|
|
186
|
+
await interaction.send('submit', { source_id: 'choice-1', value: ['fast'] });
|
|
164
187
|
await bridgeError.report({
|
|
165
188
|
source: 'render',
|
|
166
189
|
code: 'INVALID_CONTENT',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 页面预置数据模块 */
|
|
2
|
+
export interface DataProvider {
|
|
3
|
+
/**
|
|
4
|
+
* 获取 App 预置的当前页面数据。
|
|
5
|
+
*
|
|
6
|
+
* App 端在加载 H5 前通过 `NlDataProviderModule.setPageData(data)` 预置,
|
|
7
|
+
* H5 通过本方法获取,不需要 key,永远只有一份当前页面数据。
|
|
8
|
+
*
|
|
9
|
+
* 返回类型由业务方自行约定;没有预置数据时返回 `null`。
|
|
10
|
+
*/
|
|
11
|
+
getPageData<T = unknown>(): Promise<T | null>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_provider.d.ts","sourceRoot":"","sources":["../../generated/data_provider.ts"],"names":[],"mappings":"AAKA,eAAe;AACf,MAAM,WAAW,YAAY;IACzB;;;;;;;OAOG;IACH,WAAW,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlDataProviderModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_data_provider_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=data_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_provider.js","sourceRoot":"","sources":["../../generated/data_provider.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4CAA4C;AAC5C,uEAAuE;AACvE,+DAA+D"}
|
|
@@ -2,10 +2,18 @@ import type { AiTutor } from './ai_tutor';
|
|
|
2
2
|
import type { Audio } from './audio';
|
|
3
3
|
import type { Device } from './device';
|
|
4
4
|
import type { User } from './user';
|
|
5
|
+
import type { SoundEffects } from './sound_effects';
|
|
6
|
+
import type { TtsPlayer } from './tts_player';
|
|
7
|
+
import type { DataProvider } from './data_provider';
|
|
8
|
+
import type { MessageRead } from './message_read';
|
|
5
9
|
export type { AiTutor } from './ai_tutor';
|
|
6
10
|
export type { Audio } from './audio';
|
|
7
11
|
export type { Device } from './device';
|
|
8
12
|
export type { User } from './user';
|
|
13
|
+
export type { SoundEffects, SoundId } from './sound_effects';
|
|
14
|
+
export type { TtsPlayer, TtsKind, TtsAccent, TtsPreset, TtsVoiceArgs, TtsSupportedVoices, } from './tts_player';
|
|
15
|
+
export type { DataProvider } from './data_provider';
|
|
16
|
+
export type { MessageRead, MarkReadResult } from './message_read';
|
|
9
17
|
/** 获取 ai_tutor 的类型安全代理 */
|
|
10
18
|
export declare function getAiTutor(): AiTutor;
|
|
11
19
|
/** 获取 audio 的类型安全代理 */
|
|
@@ -14,4 +22,12 @@ export declare function getAudio(): Audio;
|
|
|
14
22
|
export declare function getDevice(): Device;
|
|
15
23
|
/** 获取 user 的类型安全代理 */
|
|
16
24
|
export declare function getUser(): User;
|
|
25
|
+
/** 获取 soundEffects 的类型安全代理 */
|
|
26
|
+
export declare function getSoundEffects(): SoundEffects;
|
|
27
|
+
/** 获取 ttsPlayer 的类型安全代理 */
|
|
28
|
+
export declare function getTtsPlayer(): TtsPlayer;
|
|
29
|
+
/** 获取 dataProvider 的类型安全代理 */
|
|
30
|
+
export declare function getDataProvider(): DataProvider;
|
|
31
|
+
/** 获取 messageRead 的类型安全代理 */
|
|
32
|
+
export declare function getMessageRead(): MessageRead;
|
|
17
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC7D,YAAY,EACV,SAAS,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,YAAY,EACZ,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMlE,0BAA0B;AAC1B,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED,uBAAuB;AACvB,wBAAgB,QAAQ,IAAI,KAAK,CAEhC;AAED,wBAAwB;AACxB,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,sBAAsB;AACtB,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED,8BAA8B;AAC9B,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED,2BAA2B;AAC3B,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED,8BAA8B;AAC9B,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED,6BAA6B;AAC7B,wBAAgB,cAAc,IAAI,WAAW,CAE5C"}
|
package/dist/generated/index.js
CHANGED
|
@@ -22,4 +22,20 @@ export function getDevice() {
|
|
|
22
22
|
export function getUser() {
|
|
23
23
|
return bridge.module('user');
|
|
24
24
|
}
|
|
25
|
+
/** 获取 soundEffects 的类型安全代理 */
|
|
26
|
+
export function getSoundEffects() {
|
|
27
|
+
return bridge.module('soundEffects');
|
|
28
|
+
}
|
|
29
|
+
/** 获取 ttsPlayer 的类型安全代理 */
|
|
30
|
+
export function getTtsPlayer() {
|
|
31
|
+
return bridge.module('ttsPlayer');
|
|
32
|
+
}
|
|
33
|
+
/** 获取 dataProvider 的类型安全代理 */
|
|
34
|
+
export function getDataProvider() {
|
|
35
|
+
return bridge.module('dataProvider');
|
|
36
|
+
}
|
|
37
|
+
/** 获取 messageRead 的类型安全代理 */
|
|
38
|
+
export function getMessageRead() {
|
|
39
|
+
return bridge.module('messageRead');
|
|
40
|
+
}
|
|
25
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+CAA+C;AAC/C,yCAAyC;AACzC,+DAA+D;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+CAA+C;AAC/C,yCAAyC;AACzC,+DAA+D;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AA0B3C,+DAA+D;AAC/D,iBAAiB;AACjB,+DAA+D;AAE/D,0BAA0B;AAC1B,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC,MAAM,CAAU,UAAU,CAAC,CAAC;AAC5C,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,QAAQ;IACtB,OAAO,MAAM,CAAC,MAAM,CAAQ,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,wBAAwB;AACxB,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC,MAAM,CAAS,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,sBAAsB;AACtB,MAAM,UAAU,OAAO;IACrB,OAAO,MAAM,CAAC,MAAM,CAAO,MAAM,CAAC,CAAC;AACrC,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAe,cAAc,CAAC,CAAC;AACrD,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,YAAY;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAY,WAAW,CAAC,CAAC;AAC/C,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAe,cAAc,CAAC,CAAC;AACrD,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAc,aAAa,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 消息已读上报模块返回值 */
|
|
2
|
+
export interface MarkReadResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
errorMessage?: string;
|
|
5
|
+
}
|
|
6
|
+
/** 消息已读上报模块 */
|
|
7
|
+
export interface MessageRead {
|
|
8
|
+
/**
|
|
9
|
+
* 将指定消息标记为已读。
|
|
10
|
+
*
|
|
11
|
+
* 用于首页 webView 弹窗卡片:H5 通过 `getPageData()` 拿到 `messageId`,
|
|
12
|
+
* 在合适的时机(如"看完")调用本方法,由 H5 业务方决定何时算已读。
|
|
13
|
+
*/
|
|
14
|
+
markRead(args: {
|
|
15
|
+
messageId: number;
|
|
16
|
+
}): Promise<MarkReadResult>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=message_read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_read.d.ts","sourceRoot":"","sources":["../../generated/message_read.ts"],"names":[],"mappings":"AAKA,kBAAkB;AAClB,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAe;AACf,MAAM,WAAW,WAAW;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAClE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlMessageReadModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_data_provider_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=message_read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_read.js","sourceRoot":"","sources":["../../generated/message_read.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,2CAA2C;AAC3C,uEAAuE;AACvE,+DAA+D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** 支持的音效 ID 枚举(与 Flutter 端 _supportedSoundIds 保持一致) */
|
|
2
|
+
export type SoundId = 'bubbleRight' | 'bubbleWrong' | 'right1' | 'right2' | 'error1' | 'error2' | 'errorTip' | 'successTip' | 'writing' | 'recording' | 'pageTurning' | 'coinDrop' | 'countDown' | 'hangUp' | 'magicUsing' | 'magicStar' | 'giftProps' | 'chuxian' | 'du' | 'saHua' | 'starDown' | 'bubbleAppear' | 'flyAway' | 'letPlay' | 'letPractice' | 'letWatch' | 'good' | 'great' | 'excellent' | 'awesome' | 'cool' | 'fantastic' | 'comboFrenzy' | 'appear' | 'wxConnect' | 'homeBg' | 'summary' | 'transition' | 'baoxiangDown' | 'baoxiangOpen' | 'gemAddVoice' | 'oneStar' | 'twoStar';
|
|
3
|
+
/** 内置音效播放模块 */
|
|
4
|
+
export interface SoundEffects {
|
|
5
|
+
/** 按 soundId 播放内置音效 */
|
|
6
|
+
play(args: {
|
|
7
|
+
soundId: SoundId;
|
|
8
|
+
/** 是否等待播放完成再 resolve(仅部分音效支持) */
|
|
9
|
+
waitForCompletion?: boolean;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
soundId: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** 获取当前支持的 soundId 列表 */
|
|
15
|
+
supportedSounds(): Promise<string[]>;
|
|
16
|
+
/** 停止微信连接循环音效 */
|
|
17
|
+
stopWxConnect(): Promise<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
/** 停止首页背景音乐 */
|
|
21
|
+
stopHomeBg(): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=sound_effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sound_effects.d.ts","sourceRoot":"","sources":["../../generated/sound_effects.ts"],"names":[],"mappings":"AAKA,uDAAuD;AACvD,MAAM,MAAM,OAAO,GACf,aAAa,GACb,aAAa,GACb,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,SAAS,GACT,WAAW,GACX,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,WAAW,GACX,SAAS,GACT,IAAI,GACJ,OAAO,GACP,UAAU,GACV,cAAc,GACd,SAAS,GACT,SAAS,GACT,aAAa,GACb,UAAU,GACV,MAAM,GACN,OAAO,GACP,WAAW,GACX,SAAS,GACT,MAAM,GACN,WAAW,GACX,aAAa,GACb,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,cAAc,GACd,cAAc,GACd,aAAa,GACb,SAAS,GACT,SAAS,CAAC;AAEd,eAAe;AACf,MAAM,WAAW,YAAY;IAC3B,uBAAuB;IACvB,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,iCAAiC;QACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEnD,yBAAyB;IACzB,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAErC,iBAAiB;IACjB,aAAa,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAE/C,eAAe;IACf,UAAU,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlSoundEffectsModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_sound_effects_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=sound_effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sound_effects.js","sourceRoot":"","sources":["../../generated/sound_effects.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4CAA4C;AAC5C,uEAAuE;AACvE,+DAA+D"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** TTS 请求类型 */
|
|
2
|
+
export type TtsKind = 'sentence' | 'word' | 'tutor';
|
|
3
|
+
/** 口音简写 */
|
|
4
|
+
export type TtsAccent = 'uk' | 'us';
|
|
5
|
+
/** 预设语色速写(对应 Flutter 端 _presets) */
|
|
6
|
+
export type TtsPreset = 'sentence-default' | 'word-default' | 'sara-cheerful' | 'paige-supportive' | 'libby-uk' | 'nativeMentor-us';
|
|
7
|
+
/** 公共语色参数,play 与 getUrl 共享 */
|
|
8
|
+
export interface TtsVoiceArgs {
|
|
9
|
+
text: string;
|
|
10
|
+
kind?: TtsKind;
|
|
11
|
+
accent?: TtsAccent;
|
|
12
|
+
/** 指定 tutorId(白名单内),优先级高于 accent */
|
|
13
|
+
tutorId?: string;
|
|
14
|
+
/** 语气,如 newscast / cheerful / Supportive */
|
|
15
|
+
voiceStyle?: string;
|
|
16
|
+
/** 底层发音类型,如 BV503_streaming */
|
|
17
|
+
voiceType?: string;
|
|
18
|
+
/** 语速,如 '-20%' / '+10%' */
|
|
19
|
+
voiceRate?: string;
|
|
20
|
+
/** 仅 sentence 有效:是否按断句处理 */
|
|
21
|
+
isBreak?: 0 | 1;
|
|
22
|
+
/** 语色预设名 */
|
|
23
|
+
preset?: TtsPreset;
|
|
24
|
+
}
|
|
25
|
+
/** supportedVoices() 返回值 */
|
|
26
|
+
export interface TtsSupportedVoices {
|
|
27
|
+
kinds: TtsKind[];
|
|
28
|
+
tutors: string[];
|
|
29
|
+
styles: string[];
|
|
30
|
+
types: string[];
|
|
31
|
+
presets: TtsPreset[];
|
|
32
|
+
}
|
|
33
|
+
/** 文本朗读(TTS)播放模块:传入文本由 App 原生链路请求 TTS 并播放 */
|
|
34
|
+
export interface TtsPlayer {
|
|
35
|
+
/**
|
|
36
|
+
* 请求 TTS 音频并原生播放。
|
|
37
|
+
*
|
|
38
|
+
* 校验失败时 resolve `{ success:false, error, field }`,不会抛异常。
|
|
39
|
+
* 新一次 `play` 会自动打断本模块上一段音频。
|
|
40
|
+
*/
|
|
41
|
+
play(args: TtsVoiceArgs & {
|
|
42
|
+
/** 是否等待播放完成再 resolve */
|
|
43
|
+
waitForCompletion?: boolean;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
success: boolean;
|
|
46
|
+
/** 错误标识:noStudent / invalidText / invalidKind / invalidVoice / invalidPreset 等 */
|
|
47
|
+
error?: string;
|
|
48
|
+
/** 校验失败时指向的字段名(如 tutorId) */
|
|
49
|
+
field?: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** 停止本模块当前播放的音频(不影响音效/录音等其他音频) */
|
|
52
|
+
stop(): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
/** 暂停本模块当前播放的音频 */
|
|
56
|
+
pause(): Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* 仅请求 TTS 音频 URL,不播放。适用于 H5 希望自己用 `<audio>` 控制进度/波形的场景。
|
|
61
|
+
*/
|
|
62
|
+
getUrl(args: TtsVoiceArgs): Promise<{
|
|
63
|
+
/** 可直接给 `<audio>` 播放的 URL */
|
|
64
|
+
url: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** 查询当前支持的 kind / tutorId / voiceStyle / voiceType / preset 白名单 */
|
|
67
|
+
supportedVoices(): Promise<TtsSupportedVoices>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=tts_player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts_player.d.ts","sourceRoot":"","sources":["../../generated/tts_player.ts"],"names":[],"mappings":"AAKA,eAAe;AACf,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,WAAW;AACX,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpC,oCAAoC;AACpC,MAAM,MAAM,SAAS,GACjB,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,kBAAkB,GAClB,UAAU,GACV,iBAAiB,CAAC;AAEtB,8BAA8B;AAC9B,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,YAAY;IACZ,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,4BAA4B;AAC5B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAED,6CAA6C;AAC7C,MAAM,WAAW,SAAS;IACxB;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG;QACxB,wBAAwB;QACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GAAG,OAAO,CAAC;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,kFAAkF;QAClF,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,6BAA6B;QAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAEtC,mBAAmB;IACnB,KAAK,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAEvC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;QAClC,6BAA6B;QAC7B,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;IAEH,mEAAmE;IACnE,eAAe,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlTtsPlayerModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_tts_player_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=tts_player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts_player.js","sourceRoot":"","sources":["../../generated/tts_player.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,yCAAyC;AACzC,oEAAoE;AACpE,+DAA+D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 与 Flutter `.ar` 相同的屏幕适配工具。
|
|
3
|
+
*
|
|
4
|
+
* App 端以 812 作为设计稿最长边基准,将 adaptation 注入 system 模块。
|
|
5
|
+
*/
|
|
6
|
+
import { type ArAdaptationInfo, type SafeAreaInsets } from './system-module';
|
|
7
|
+
import { type Unsubscribe } from './mrp-bridge';
|
|
8
|
+
export type ArAdaptationListener = (adaptation: ArAdaptationInfo) => void;
|
|
9
|
+
/** 从容器读取初始适配信息,并注册横竖屏变化监听。 */
|
|
10
|
+
export declare function initArAdaptation(): Promise<ArAdaptationInfo | null>;
|
|
11
|
+
/** 将设计稿尺寸转换为当前 App 屏幕尺寸。 */
|
|
12
|
+
export declare function ar(value: number): number;
|
|
13
|
+
/** 获取当前适配比例,便于 Canvas 或自定义渲染使用。 */
|
|
14
|
+
export declare function getArScale(): number;
|
|
15
|
+
/** 获取 App 注入的设备安全区;不在容器内或 App 未注入时返回全 0。 */
|
|
16
|
+
export declare function getSafeArea(): SafeAreaInsets;
|
|
17
|
+
/** 监听 App 横竖屏或窗口尺寸变化,返回取消监听函数。 */
|
|
18
|
+
export declare function onArAdaptationChange(listener: ArAdaptationListener): Unsubscribe;
|
|
19
|
+
//# sourceMappingURL=adaptation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptation.d.ts","sourceRoot":"","sources":["../../src/adaptation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AASxD,MAAM,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAiC1E,8BAA8B;AAC9B,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAIzE;AAED,4BAA4B;AAC5B,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,mCAAmC;AACnC,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,IAAI,cAAc,CAE5C;AAED,kCAAkC;AAClC,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,oBAAoB,GAC5B,WAAW,CAIb"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 与 Flutter `.ar` 相同的屏幕适配工具。
|
|
3
|
+
*
|
|
4
|
+
* App 端以 812 作为设计稿最长边基准,将 adaptation 注入 system 模块。
|
|
5
|
+
*/
|
|
6
|
+
import { getSystemModule, } from './system-module';
|
|
7
|
+
import { bridge } from './mrp-bridge';
|
|
8
|
+
const ZERO_SAFE_AREA = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
9
|
+
let currentScale = 1;
|
|
10
|
+
let currentSafeArea = ZERO_SAFE_AREA;
|
|
11
|
+
let bridgeUnsubscribe = null;
|
|
12
|
+
const listeners = new Set();
|
|
13
|
+
function applyAdaptation(adaptation) {
|
|
14
|
+
if (!adaptation ||
|
|
15
|
+
!Number.isFinite(adaptation.scale) ||
|
|
16
|
+
adaptation.scale <= 0) {
|
|
17
|
+
currentScale = 1;
|
|
18
|
+
currentSafeArea = ZERO_SAFE_AREA;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
currentScale = adaptation.scale;
|
|
22
|
+
currentSafeArea = adaptation.safeArea ?? ZERO_SAFE_AREA;
|
|
23
|
+
for (const listener of listeners) {
|
|
24
|
+
listener(adaptation);
|
|
25
|
+
}
|
|
26
|
+
return adaptation;
|
|
27
|
+
}
|
|
28
|
+
function ensureAdaptationListener() {
|
|
29
|
+
if (bridgeUnsubscribe)
|
|
30
|
+
return;
|
|
31
|
+
bridgeUnsubscribe = bridge.on('adaptation', 'changed', (message) => {
|
|
32
|
+
applyAdaptation(message.payload);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** 从容器读取初始适配信息,并注册横竖屏变化监听。 */
|
|
36
|
+
export async function initArAdaptation() {
|
|
37
|
+
ensureAdaptationListener();
|
|
38
|
+
const info = await getSystemModule().getContainerInfo();
|
|
39
|
+
return applyAdaptation(info?.adaptation);
|
|
40
|
+
}
|
|
41
|
+
/** 将设计稿尺寸转换为当前 App 屏幕尺寸。 */
|
|
42
|
+
export function ar(value) {
|
|
43
|
+
return value * currentScale;
|
|
44
|
+
}
|
|
45
|
+
/** 获取当前适配比例,便于 Canvas 或自定义渲染使用。 */
|
|
46
|
+
export function getArScale() {
|
|
47
|
+
return currentScale;
|
|
48
|
+
}
|
|
49
|
+
/** 获取 App 注入的设备安全区;不在容器内或 App 未注入时返回全 0。 */
|
|
50
|
+
export function getSafeArea() {
|
|
51
|
+
return currentSafeArea;
|
|
52
|
+
}
|
|
53
|
+
/** 监听 App 横竖屏或窗口尺寸变化,返回取消监听函数。 */
|
|
54
|
+
export function onArAdaptationChange(listener) {
|
|
55
|
+
ensureAdaptationListener();
|
|
56
|
+
listeners.add(listener);
|
|
57
|
+
return () => listeners.delete(listener);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=adaptation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptation.js","sourceRoot":"","sources":["../../src/adaptation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,eAAe,GAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAoB,MAAM,cAAc,CAAC;AAExD,MAAM,cAAc,GAAmB,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEhF,IAAI,YAAY,GAAG,CAAC,CAAC;AACrB,IAAI,eAAe,GAAmB,cAAc,CAAC;AACrD,IAAI,iBAAiB,GAAuB,IAAI,CAAC;AACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAC;AAIlD,SAAS,eAAe,CACvB,UAA+C;IAE/C,IACC,CAAC,UAAU;QACX,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;QAClC,UAAU,CAAC,KAAK,IAAI,CAAC,EACpB,CAAC;QACF,YAAY,GAAG,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 +3,8 @@ export declare const bridgeMessageTypes: {
|
|
|
3
3
|
readonly render: "render";
|
|
4
4
|
readonly interaction: "interaction";
|
|
5
5
|
readonly error: "error";
|
|
6
|
+
/** 宿主镜像给 H5 的回合事件(单向:宿主 → H5)。 */
|
|
7
|
+
readonly agent: "agent";
|
|
6
8
|
};
|
|
7
9
|
export declare const renderActions: {
|
|
8
10
|
readonly set: "set";
|
|
@@ -21,7 +23,7 @@ export interface RenderHandlers<T = unknown> {
|
|
|
21
23
|
clear(message: BridgeMessage<Record<string, unknown>>): void;
|
|
22
24
|
}
|
|
23
25
|
export interface InteractionPayload<T = unknown> {
|
|
24
|
-
|
|
26
|
+
source_id: string;
|
|
25
27
|
value?: T;
|
|
26
28
|
[key: string]: unknown;
|
|
27
29
|
}
|
|
@@ -47,4 +49,45 @@ export declare const interaction: {
|
|
|
47
49
|
export declare const bridgeError: {
|
|
48
50
|
readonly report: (payload: BridgeErrorPayload) => Promise<unknown>;
|
|
49
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* 回合事件协议:宿主把「现在轮到谁、这一轮发生了什么」镜像给 H5。
|
|
54
|
+
*
|
|
55
|
+
* 用在 H5 页面**作为一个交互步骤**嵌在原生流程里的场景(AI 教学 / 问诊等):
|
|
56
|
+
* 原生题型能收到宿主的回合事件,H5 题型也应该能。宿主只负责把事实发下来,
|
|
57
|
+
* 怎么响应(放开作答、复位重做、演完反馈再收尾)由 H5 自己决定。
|
|
58
|
+
*
|
|
59
|
+
* 线格式:`{ type: 'agent', action, payload: { iid, ... } }`
|
|
60
|
+
*/
|
|
61
|
+
export declare const agentEvents: {
|
|
62
|
+
/** 作答权交回给用户(宿主的开场播报已结束)。 */
|
|
63
|
+
readonly startLearn: "start_learn";
|
|
64
|
+
/** 本题重做。 */
|
|
65
|
+
readonly retryLearn: "retry_learn";
|
|
66
|
+
/** 本题判过;若宿主把收尾交给了 H5,H5 需回发一次收尾动作,否则流程不推进。 */
|
|
67
|
+
readonly passLearn: "pass_learn";
|
|
68
|
+
/** 用户**绕过这块 H5** 上行了一次作答(原生输入栏、原生选择器等)。 */
|
|
69
|
+
readonly externalAnswer: "external_answer";
|
|
70
|
+
};
|
|
71
|
+
export interface AgentEventPayload {
|
|
72
|
+
/**
|
|
73
|
+
* 这条事件属于哪一屏。
|
|
74
|
+
*
|
|
75
|
+
* 内容(`render/set`)和事件通常来自宿主上游的两条独立消息,到达先后不保证。
|
|
76
|
+
* 拿它对齐「这条事件说的是不是我现在这一屏」,不匹配就先扣着。
|
|
77
|
+
*/
|
|
78
|
+
iid?: string;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
}
|
|
81
|
+
export interface ExternalAnswerPayload extends AgentEventPayload {
|
|
82
|
+
/** 那次绕过本页的上行负载(形态由宿主定义)。 */
|
|
83
|
+
answer?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
export interface AgentEventHandlers {
|
|
86
|
+
startLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
87
|
+
retryLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
88
|
+
passLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
89
|
+
externalAnswer?(payload: ExternalAnswerPayload, message: BridgeMessage<ExternalAnswerPayload>): void;
|
|
90
|
+
}
|
|
91
|
+
/** 只订阅传了 handler 的那几个事件;返回的函数一次性退订。 */
|
|
92
|
+
export declare function bindAgentProtocol(handlers: AgentEventHandlers, transport?: Pick<ProtocolTransport, 'on'>): Unsubscribe;
|
|
50
93
|
//# sourceMappingURL=content-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-protocol.d.ts","sourceRoot":"","sources":["../../src/content-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE5E,eAAO,MAAM,kBAAkB;;;;
|
|
1
|
+
{"version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UAAU,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IACzF,UAAU,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IACzF,SAAS,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IACxF,cAAc,CAAC,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,aAAa,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC;CACtG;AAED,uCAAuC;AACvC,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,kBAAkB,EAC5B,SAAS,GAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAU,GAChD,WAAW,CAgBb"}
|
|
@@ -3,6 +3,8 @@ export const bridgeMessageTypes = {
|
|
|
3
3
|
render: 'render',
|
|
4
4
|
interaction: 'interaction',
|
|
5
5
|
error: 'error',
|
|
6
|
+
/** 宿主镜像给 H5 的回合事件(单向:宿主 → H5)。 */
|
|
7
|
+
agent: 'agent',
|
|
6
8
|
};
|
|
7
9
|
export const renderActions = {
|
|
8
10
|
set: 'set',
|
|
@@ -43,4 +45,38 @@ export const bridgeError = {
|
|
|
43
45
|
return bridge.send(bridgeMessageTypes.error, 'report', payload);
|
|
44
46
|
},
|
|
45
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* 回合事件协议:宿主把「现在轮到谁、这一轮发生了什么」镜像给 H5。
|
|
50
|
+
*
|
|
51
|
+
* 用在 H5 页面**作为一个交互步骤**嵌在原生流程里的场景(AI 教学 / 问诊等):
|
|
52
|
+
* 原生题型能收到宿主的回合事件,H5 题型也应该能。宿主只负责把事实发下来,
|
|
53
|
+
* 怎么响应(放开作答、复位重做、演完反馈再收尾)由 H5 自己决定。
|
|
54
|
+
*
|
|
55
|
+
* 线格式:`{ type: 'agent', action, payload: { iid, ... } }`
|
|
56
|
+
*/
|
|
57
|
+
export const agentEvents = {
|
|
58
|
+
/** 作答权交回给用户(宿主的开场播报已结束)。 */
|
|
59
|
+
startLearn: 'start_learn',
|
|
60
|
+
/** 本题重做。 */
|
|
61
|
+
retryLearn: 'retry_learn',
|
|
62
|
+
/** 本题判过;若宿主把收尾交给了 H5,H5 需回发一次收尾动作,否则流程不推进。 */
|
|
63
|
+
passLearn: 'pass_learn',
|
|
64
|
+
/** 用户**绕过这块 H5** 上行了一次作答(原生输入栏、原生选择器等)。 */
|
|
65
|
+
externalAnswer: 'external_answer',
|
|
66
|
+
};
|
|
67
|
+
/** 只订阅传了 handler 的那几个事件;返回的函数一次性退订。 */
|
|
68
|
+
export function bindAgentProtocol(handlers, transport = bridge) {
|
|
69
|
+
const pairs = [
|
|
70
|
+
[agentEvents.startLearn, handlers.startLearn],
|
|
71
|
+
[agentEvents.retryLearn, handlers.retryLearn],
|
|
72
|
+
[agentEvents.passLearn, handlers.passLearn],
|
|
73
|
+
[agentEvents.externalAnswer, handlers.externalAnswer],
|
|
74
|
+
];
|
|
75
|
+
const subscriptions = pairs
|
|
76
|
+
.filter(([, handler]) => handler !== undefined)
|
|
77
|
+
.map(([action, handler]) => transport.on(bridgeMessageTypes.agent, action, (message) => {
|
|
78
|
+
handler(message.payload ?? {}, message);
|
|
79
|
+
}));
|
|
80
|
+
return () => subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
81
|
+
}
|
|
46
82
|
//# sourceMappingURL=content-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-protocol.js","sourceRoot":"","sources":["../../src/content-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwC,MAAM,cAAc,CAAC;AAE5E,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,aAAa;IAC1B,KAAK,EAA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AAG;IACzB,4BAA4B;IAC5B,UAAU,EAAE,aAAa;IACzB,YAAY;IACZ,UAAU,EAAE,aAAa;IACzB,8CAA8C;IAC9C,SAAS,EAAE,YAAY;IACvB,2CAA2C;IAC3C,cAAc,EAAE,iBAAiB;CACzB,CAAC;AAyBX,uCAAuC;AACvC,MAAM,UAAU,iBAAiB,CAC/B,QAA4B,EAC5B,YAA2C,MAAM;IAEjD,MAAM,KAAK,GAA4E;QACrF,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;QAC7C,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;QAC7C,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC;QAC3C,CAAC,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC;KACtD,CAAC;IACF,MAAM,aAAa,GAAG,KAAK;SACxB,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC;SAC9C,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CACzB,SAAS,CAAC,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,OAA2B,EAAE,EAAE;QAC5E,OAAwD,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5F,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACrE,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
* 所有 API 从此入口统一导出,消费者无需感知内部目录结构。
|
|
9
9
|
*/
|
|
10
10
|
export { bridge, MrpBridge } from './mrp-bridge';
|
|
11
|
-
export type { BridgeMessage, MessageHandler, Unsubscribe
|
|
11
|
+
export type { BridgeMessage, MessageHandler, Unsubscribe } from './mrp-bridge';
|
|
12
12
|
export { getSystemModule } from './system-module';
|
|
13
|
-
export type { SystemModule, ModuleAllowedResult, AvailableModulesResult, ContainerInfoResult, } from './system-module';
|
|
13
|
+
export type { SystemModule, ModuleAllowedResult, AvailableModulesResult, ContainerInfoResult, ArAdaptationInfo, SafeAreaInsets, } from './system-module';
|
|
14
|
+
export { ar, getArScale, getSafeArea, initArAdaptation, onArAdaptationChange, } from './adaptation';
|
|
15
|
+
export type { ArAdaptationListener } from './adaptation';
|
|
14
16
|
export * from '../generated/index';
|
|
15
17
|
export { lifecycle } from './lifecycle';
|
|
16
18
|
export type { RouteChangedPayload, AppMountedPayload } from './lifecycle';
|
|
17
|
-
export { bindRenderProtocol, bridgeError, bridgeMessageTypes, interaction, renderActions, renderProtocol, } from './content-protocol';
|
|
18
|
-
export type { BridgeErrorPayload, InteractionPayload, ProtocolTransport, RenderHandlers, RenderPayload, } from './content-protocol';
|
|
19
|
+
export { agentEvents, bindAgentProtocol, bindRenderProtocol, bridgeError, bridgeMessageTypes, interaction, renderActions, renderProtocol, } from './content-protocol';
|
|
20
|
+
export type { AgentEventHandlers, AgentEventPayload, BridgeErrorPayload, ExternalAnswerPayload, InteractionPayload, ProtocolTransport, RenderHandlers, RenderPayload, } from './content-protocol';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EACX,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,GACd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACN,EAAE,EACF,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,cAAc,oBAAoB,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG1E,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,GACb,MAAM,oBAAoB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
export { bridge, MrpBridge } from './mrp-bridge';
|
|
12
12
|
// 内置系统模块类型 + 工厂函数(容器核心契约)
|
|
13
13
|
export { getSystemModule } from './system-module';
|
|
14
|
+
// App/H5 统一屏幕适配
|
|
15
|
+
export { ar, getArScale, getSafeArea, initArAdaptation, onArAdaptationChange, } from './adaptation';
|
|
14
16
|
// Generated 模块:类型 + 工厂函数
|
|
15
17
|
export * from '../generated/index';
|
|
16
18
|
// 生命周期上报工具
|
|
17
19
|
export { lifecycle } from './lifecycle';
|
|
18
20
|
// 标准内容渲染、交互与错误协议
|
|
19
|
-
export { bindRenderProtocol, bridgeError, bridgeMessageTypes, interaction, renderActions, renderProtocol, } from './content-protocol';
|
|
21
|
+
export { agentEvents, bindAgentProtocol, bindRenderProtocol, bridgeError, bridgeMessageTypes, interaction, renderActions, renderProtocol, } from './content-protocol';
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY;AACZ,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY;AACZ,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjD,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUlD,gBAAgB;AAChB,OAAO,EACN,EAAE,EACF,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,cAAc,CAAC;AAGtB,yBAAyB;AACzB,cAAc,oBAAoB,CAAC;AAEnC,WAAW;AACX,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,iBAAiB;AACjB,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,cAAc,GACd,MAAM,oBAAoB,CAAC"}
|
|
@@ -29,8 +29,25 @@ export interface ContainerInfoResult {
|
|
|
29
29
|
packageId: string | null;
|
|
30
30
|
registeredModules: string[];
|
|
31
31
|
allowedModules: string[] | null;
|
|
32
|
+
adaptation?: ArAdaptationInfo;
|
|
32
33
|
[key: string]: unknown;
|
|
33
34
|
}
|
|
35
|
+
/** App 与 H5 共用的 `.ar` 屏幕适配信息。 */
|
|
36
|
+
export interface ArAdaptationInfo {
|
|
37
|
+
designLongSide: number;
|
|
38
|
+
screenWidth: number;
|
|
39
|
+
screenHeight: number;
|
|
40
|
+
scale: number;
|
|
41
|
+
/** 设备安全区(逻辑像素)。WebView 里 `env(safe-area-inset-*)` 常常拿不到,改由 App 注入。 */
|
|
42
|
+
safeArea?: SafeAreaInsets;
|
|
43
|
+
}
|
|
44
|
+
/** 设备四边的安全区尺寸,单位与 screenWidth/screenHeight 一致。 */
|
|
45
|
+
export interface SafeAreaInsets {
|
|
46
|
+
top: number;
|
|
47
|
+
bottom: number;
|
|
48
|
+
left: number;
|
|
49
|
+
right: number;
|
|
50
|
+
}
|
|
34
51
|
/**
|
|
35
52
|
* 容器内置系统模块接口。
|
|
36
53
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-module.d.ts","sourceRoot":"","sources":["../../src/system-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,0BAA0B;AAC1B,MAAM,WAAW,mBAAmB;
|
|
1
|
+
{"version":3,"file":"system-module.d.ts","sourceRoot":"","sources":["../../src/system-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,0BAA0B;AAC1B,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,8BAA8B;AAC9B,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,2BAA2B;AAC3B,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,cAAc,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,iCAAiC;AACjC,MAAM,WAAW,gBAAgB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAMD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,qBAAqB;IACrB,eAAe,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7E,yBAAyB;IACzB,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACvD,cAAc;IACd,gBAAgB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-module.js","sourceRoot":"","sources":["../../src/system-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"system-module.js","sourceRoot":"","sources":["../../src/system-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AA+DtC,+DAA+D;AAC/D,OAAO;AACP,+DAA+D;AAE/D;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,MAAM,CAAC,MAAM,CAAe,QAAQ,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlDataProviderModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_data_provider_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
|
|
6
|
+
/** 页面预置数据模块 */
|
|
7
|
+
export interface DataProvider {
|
|
8
|
+
/**
|
|
9
|
+
* 获取 App 预置的当前页面数据。
|
|
10
|
+
*
|
|
11
|
+
* App 端在加载 H5 前通过 `NlDataProviderModule.setPageData(data)` 预置,
|
|
12
|
+
* H5 通过本方法获取,不需要 key,永远只有一份当前页面数据。
|
|
13
|
+
*
|
|
14
|
+
* 返回类型由业务方自行约定;没有预置数据时返回 `null`。
|
|
15
|
+
*/
|
|
16
|
+
getPageData<T = unknown>(): Promise<T | null>;
|
|
17
|
+
}
|
package/generated/index.ts
CHANGED
|
@@ -8,11 +8,26 @@ import type { AiTutor } from './ai_tutor';
|
|
|
8
8
|
import type { Audio } from './audio';
|
|
9
9
|
import type { Device } from './device';
|
|
10
10
|
import type { User } from './user';
|
|
11
|
+
import type { SoundEffects } from './sound_effects';
|
|
12
|
+
import type { TtsPlayer } from './tts_player';
|
|
13
|
+
import type { DataProvider } from './data_provider';
|
|
14
|
+
import type { MessageRead } from './message_read';
|
|
11
15
|
|
|
12
16
|
export type { AiTutor } from './ai_tutor';
|
|
13
17
|
export type { Audio } from './audio';
|
|
14
18
|
export type { Device } from './device';
|
|
15
19
|
export type { User } from './user';
|
|
20
|
+
export type { SoundEffects, SoundId } from './sound_effects';
|
|
21
|
+
export type {
|
|
22
|
+
TtsPlayer,
|
|
23
|
+
TtsKind,
|
|
24
|
+
TtsAccent,
|
|
25
|
+
TtsPreset,
|
|
26
|
+
TtsVoiceArgs,
|
|
27
|
+
TtsSupportedVoices,
|
|
28
|
+
} from './tts_player';
|
|
29
|
+
export type { DataProvider } from './data_provider';
|
|
30
|
+
export type { MessageRead, MarkReadResult } from './message_read';
|
|
16
31
|
|
|
17
32
|
// ============================================================
|
|
18
33
|
// 工厂函数(适用于任何上下文)
|
|
@@ -38,3 +53,22 @@ export function getUser(): User {
|
|
|
38
53
|
return bridge.module<User>('user');
|
|
39
54
|
}
|
|
40
55
|
|
|
56
|
+
/** 获取 soundEffects 的类型安全代理 */
|
|
57
|
+
export function getSoundEffects(): SoundEffects {
|
|
58
|
+
return bridge.module<SoundEffects>('soundEffects');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 获取 ttsPlayer 的类型安全代理 */
|
|
62
|
+
export function getTtsPlayer(): TtsPlayer {
|
|
63
|
+
return bridge.module<TtsPlayer>('ttsPlayer');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 获取 dataProvider 的类型安全代理 */
|
|
67
|
+
export function getDataProvider(): DataProvider {
|
|
68
|
+
return bridge.module<DataProvider>('dataProvider');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 获取 messageRead 的类型安全代理 */
|
|
72
|
+
export function getMessageRead(): MessageRead {
|
|
73
|
+
return bridge.module<MessageRead>('messageRead');
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlMessageReadModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_data_provider_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
|
|
6
|
+
/** 消息已读上报模块返回值 */
|
|
7
|
+
export interface MarkReadResult {
|
|
8
|
+
success: boolean;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** 消息已读上报模块 */
|
|
13
|
+
export interface MessageRead {
|
|
14
|
+
/**
|
|
15
|
+
* 将指定消息标记为已读。
|
|
16
|
+
*
|
|
17
|
+
* 用于首页 webView 弹窗卡片:H5 通过 `getPageData()` 拿到 `messageId`,
|
|
18
|
+
* 在合适的时机(如"看完")调用本方法,由 H5 业务方决定何时算已读。
|
|
19
|
+
*/
|
|
20
|
+
markRead(args: { messageId: number }): Promise<MarkReadResult>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlSoundEffectsModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_sound_effects_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
|
|
6
|
+
/** 支持的音效 ID 枚举(与 Flutter 端 _supportedSoundIds 保持一致) */
|
|
7
|
+
export type SoundId =
|
|
8
|
+
| 'bubbleRight'
|
|
9
|
+
| 'bubbleWrong'
|
|
10
|
+
| 'right1'
|
|
11
|
+
| 'right2'
|
|
12
|
+
| 'error1'
|
|
13
|
+
| 'error2'
|
|
14
|
+
| 'errorTip'
|
|
15
|
+
| 'successTip'
|
|
16
|
+
| 'writing'
|
|
17
|
+
| 'recording'
|
|
18
|
+
| 'pageTurning'
|
|
19
|
+
| 'coinDrop'
|
|
20
|
+
| 'countDown'
|
|
21
|
+
| 'hangUp'
|
|
22
|
+
| 'magicUsing'
|
|
23
|
+
| 'magicStar'
|
|
24
|
+
| 'giftProps'
|
|
25
|
+
| 'chuxian'
|
|
26
|
+
| 'du'
|
|
27
|
+
| 'saHua'
|
|
28
|
+
| 'starDown'
|
|
29
|
+
| 'bubbleAppear'
|
|
30
|
+
| 'flyAway'
|
|
31
|
+
| 'letPlay'
|
|
32
|
+
| 'letPractice'
|
|
33
|
+
| 'letWatch'
|
|
34
|
+
| 'good'
|
|
35
|
+
| 'great'
|
|
36
|
+
| 'excellent'
|
|
37
|
+
| 'awesome'
|
|
38
|
+
| 'cool'
|
|
39
|
+
| 'fantastic'
|
|
40
|
+
| 'comboFrenzy'
|
|
41
|
+
| 'appear'
|
|
42
|
+
| 'wxConnect'
|
|
43
|
+
| 'homeBg'
|
|
44
|
+
| 'summary'
|
|
45
|
+
| 'transition'
|
|
46
|
+
| 'baoxiangDown'
|
|
47
|
+
| 'baoxiangOpen'
|
|
48
|
+
| 'gemAddVoice'
|
|
49
|
+
| 'oneStar'
|
|
50
|
+
| 'twoStar';
|
|
51
|
+
|
|
52
|
+
/** 内置音效播放模块 */
|
|
53
|
+
export interface SoundEffects {
|
|
54
|
+
/** 按 soundId 播放内置音效 */
|
|
55
|
+
play(args: {
|
|
56
|
+
soundId: SoundId;
|
|
57
|
+
/** 是否等待播放完成再 resolve(仅部分音效支持) */
|
|
58
|
+
waitForCompletion?: boolean;
|
|
59
|
+
}): Promise<{ success: boolean; soundId: string }>;
|
|
60
|
+
|
|
61
|
+
/** 获取当前支持的 soundId 列表 */
|
|
62
|
+
supportedSounds(): Promise<string[]>;
|
|
63
|
+
|
|
64
|
+
/** 停止微信连接循环音效 */
|
|
65
|
+
stopWxConnect(): Promise<{ success: boolean }>;
|
|
66
|
+
|
|
67
|
+
/** 停止首页背景音乐 */
|
|
68
|
+
stopHomeBg(): Promise<{ success: boolean }>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 手动维护:与 Flutter 端 NlTtsPlayerModule 对齐。
|
|
3
|
+
// Flutter 源:athena-xingqiu/lib/h5/modules/nl_tts_player_module.dart
|
|
4
|
+
// ============================================================
|
|
5
|
+
|
|
6
|
+
/** TTS 请求类型 */
|
|
7
|
+
export type TtsKind = 'sentence' | 'word' | 'tutor';
|
|
8
|
+
|
|
9
|
+
/** 口音简写 */
|
|
10
|
+
export type TtsAccent = 'uk' | 'us';
|
|
11
|
+
|
|
12
|
+
/** 预设语色速写(对应 Flutter 端 _presets) */
|
|
13
|
+
export type TtsPreset =
|
|
14
|
+
| 'sentence-default'
|
|
15
|
+
| 'word-default'
|
|
16
|
+
| 'sara-cheerful'
|
|
17
|
+
| 'paige-supportive'
|
|
18
|
+
| 'libby-uk'
|
|
19
|
+
| 'nativeMentor-us';
|
|
20
|
+
|
|
21
|
+
/** 公共语色参数,play 与 getUrl 共享 */
|
|
22
|
+
export interface TtsVoiceArgs {
|
|
23
|
+
text: string;
|
|
24
|
+
kind?: TtsKind;
|
|
25
|
+
accent?: TtsAccent;
|
|
26
|
+
/** 指定 tutorId(白名单内),优先级高于 accent */
|
|
27
|
+
tutorId?: string;
|
|
28
|
+
/** 语气,如 newscast / cheerful / Supportive */
|
|
29
|
+
voiceStyle?: string;
|
|
30
|
+
/** 底层发音类型,如 BV503_streaming */
|
|
31
|
+
voiceType?: string;
|
|
32
|
+
/** 语速,如 '-20%' / '+10%' */
|
|
33
|
+
voiceRate?: string;
|
|
34
|
+
/** 仅 sentence 有效:是否按断句处理 */
|
|
35
|
+
isBreak?: 0 | 1;
|
|
36
|
+
/** 语色预设名 */
|
|
37
|
+
preset?: TtsPreset;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** supportedVoices() 返回值 */
|
|
41
|
+
export interface TtsSupportedVoices {
|
|
42
|
+
kinds: TtsKind[];
|
|
43
|
+
tutors: string[];
|
|
44
|
+
styles: string[];
|
|
45
|
+
types: string[];
|
|
46
|
+
presets: TtsPreset[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 文本朗读(TTS)播放模块:传入文本由 App 原生链路请求 TTS 并播放 */
|
|
50
|
+
export interface TtsPlayer {
|
|
51
|
+
/**
|
|
52
|
+
* 请求 TTS 音频并原生播放。
|
|
53
|
+
*
|
|
54
|
+
* 校验失败时 resolve `{ success:false, error, field }`,不会抛异常。
|
|
55
|
+
* 新一次 `play` 会自动打断本模块上一段音频。
|
|
56
|
+
*/
|
|
57
|
+
play(args: TtsVoiceArgs & {
|
|
58
|
+
/** 是否等待播放完成再 resolve */
|
|
59
|
+
waitForCompletion?: boolean;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
/** 错误标识:noStudent / invalidText / invalidKind / invalidVoice / invalidPreset 等 */
|
|
63
|
+
error?: string;
|
|
64
|
+
/** 校验失败时指向的字段名(如 tutorId) */
|
|
65
|
+
field?: string;
|
|
66
|
+
}>;
|
|
67
|
+
|
|
68
|
+
/** 停止本模块当前播放的音频(不影响音效/录音等其他音频) */
|
|
69
|
+
stop(): Promise<{ success: boolean }>;
|
|
70
|
+
|
|
71
|
+
/** 暂停本模块当前播放的音频 */
|
|
72
|
+
pause(): Promise<{ success: boolean }>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 仅请求 TTS 音频 URL,不播放。适用于 H5 希望自己用 `<audio>` 控制进度/波形的场景。
|
|
76
|
+
*/
|
|
77
|
+
getUrl(args: TtsVoiceArgs): Promise<{
|
|
78
|
+
/** 可直接给 `<audio>` 播放的 URL */
|
|
79
|
+
url: string;
|
|
80
|
+
}>;
|
|
81
|
+
|
|
82
|
+
/** 查询当前支持的 kind / tutorId / voiceStyle / voiceType / preset 白名单 */
|
|
83
|
+
supportedVoices(): Promise<TtsSupportedVoices>;
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dino-dev/bridge-core-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Bridge Core SDK for h5_app_container — H5 ↔ Flutter 通信 + 原生模块类型安全调用(零框架依赖)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc",
|
|
25
25
|
"prepublishOnly": "npm run build",
|
|
26
|
+
"release": "npm publish --registry https://registry.npmjs.org",
|
|
26
27
|
"dev": "tsc --watch",
|
|
27
28
|
"clean": "rm -rf dist"
|
|
28
29
|
},
|
|
@@ -41,4 +42,4 @@
|
|
|
41
42
|
"url": "https://github.com/nengli/h5_app_container",
|
|
42
43
|
"directory": "packages/bridge_core_ts"
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 与 Flutter `.ar` 相同的屏幕适配工具。
|
|
3
|
+
*
|
|
4
|
+
* App 端以 812 作为设计稿最长边基准,将 adaptation 注入 system 模块。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getSystemModule,
|
|
9
|
+
type ArAdaptationInfo,
|
|
10
|
+
type SafeAreaInsets,
|
|
11
|
+
} from './system-module';
|
|
12
|
+
import { bridge, type Unsubscribe } from './mrp-bridge';
|
|
13
|
+
|
|
14
|
+
const ZERO_SAFE_AREA: SafeAreaInsets = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
15
|
+
|
|
16
|
+
let currentScale = 1;
|
|
17
|
+
let currentSafeArea: SafeAreaInsets = ZERO_SAFE_AREA;
|
|
18
|
+
let bridgeUnsubscribe: Unsubscribe | null = null;
|
|
19
|
+
const listeners = new Set<ArAdaptationListener>();
|
|
20
|
+
|
|
21
|
+
export type ArAdaptationListener = (adaptation: ArAdaptationInfo) => void;
|
|
22
|
+
|
|
23
|
+
function applyAdaptation(
|
|
24
|
+
adaptation: ArAdaptationInfo | null | undefined,
|
|
25
|
+
): ArAdaptationInfo | null {
|
|
26
|
+
if (
|
|
27
|
+
!adaptation ||
|
|
28
|
+
!Number.isFinite(adaptation.scale) ||
|
|
29
|
+
adaptation.scale <= 0
|
|
30
|
+
) {
|
|
31
|
+
currentScale = 1;
|
|
32
|
+
currentSafeArea = ZERO_SAFE_AREA;
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
currentScale = adaptation.scale;
|
|
36
|
+
currentSafeArea = adaptation.safeArea ?? ZERO_SAFE_AREA;
|
|
37
|
+
for (const listener of listeners) {
|
|
38
|
+
listener(adaptation);
|
|
39
|
+
}
|
|
40
|
+
return adaptation;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureAdaptationListener(): void {
|
|
44
|
+
if (bridgeUnsubscribe) return;
|
|
45
|
+
bridgeUnsubscribe = bridge.on<ArAdaptationInfo>(
|
|
46
|
+
'adaptation',
|
|
47
|
+
'changed',
|
|
48
|
+
(message) => {
|
|
49
|
+
applyAdaptation(message.payload);
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 从容器读取初始适配信息,并注册横竖屏变化监听。 */
|
|
55
|
+
export async function initArAdaptation(): Promise<ArAdaptationInfo | null> {
|
|
56
|
+
ensureAdaptationListener();
|
|
57
|
+
const info = await getSystemModule().getContainerInfo();
|
|
58
|
+
return applyAdaptation(info?.adaptation);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 将设计稿尺寸转换为当前 App 屏幕尺寸。 */
|
|
62
|
+
export function ar(value: number): number {
|
|
63
|
+
return value * currentScale;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 获取当前适配比例,便于 Canvas 或自定义渲染使用。 */
|
|
67
|
+
export function getArScale(): number {
|
|
68
|
+
return currentScale;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 获取 App 注入的设备安全区;不在容器内或 App 未注入时返回全 0。 */
|
|
72
|
+
export function getSafeArea(): SafeAreaInsets {
|
|
73
|
+
return currentSafeArea;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 监听 App 横竖屏或窗口尺寸变化,返回取消监听函数。 */
|
|
77
|
+
export function onArAdaptationChange(
|
|
78
|
+
listener: ArAdaptationListener,
|
|
79
|
+
): Unsubscribe {
|
|
80
|
+
ensureAdaptationListener();
|
|
81
|
+
listeners.add(listener);
|
|
82
|
+
return () => listeners.delete(listener);
|
|
83
|
+
}
|
package/src/content-protocol.ts
CHANGED
|
@@ -4,6 +4,8 @@ export const bridgeMessageTypes = {
|
|
|
4
4
|
render: 'render',
|
|
5
5
|
interaction: 'interaction',
|
|
6
6
|
error: 'error',
|
|
7
|
+
/** 宿主镜像给 H5 的回合事件(单向:宿主 → H5)。 */
|
|
8
|
+
agent: 'agent',
|
|
7
9
|
} as const;
|
|
8
10
|
|
|
9
11
|
export const renderActions = {
|
|
@@ -26,7 +28,7 @@ export interface RenderHandlers<T = unknown> {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface InteractionPayload<T = unknown> {
|
|
29
|
-
|
|
31
|
+
source_id: string;
|
|
30
32
|
value?: T;
|
|
31
33
|
[key: string]: unknown;
|
|
32
34
|
}
|
|
@@ -91,4 +93,69 @@ export const bridgeError = {
|
|
|
91
93
|
report(payload: BridgeErrorPayload): Promise<unknown> {
|
|
92
94
|
return bridge.send(bridgeMessageTypes.error, 'report', payload);
|
|
93
95
|
},
|
|
94
|
-
} as const;
|
|
96
|
+
} as const;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 回合事件协议:宿主把「现在轮到谁、这一轮发生了什么」镜像给 H5。
|
|
100
|
+
*
|
|
101
|
+
* 用在 H5 页面**作为一个交互步骤**嵌在原生流程里的场景(AI 教学 / 问诊等):
|
|
102
|
+
* 原生题型能收到宿主的回合事件,H5 题型也应该能。宿主只负责把事实发下来,
|
|
103
|
+
* 怎么响应(放开作答、复位重做、演完反馈再收尾)由 H5 自己决定。
|
|
104
|
+
*
|
|
105
|
+
* 线格式:`{ type: 'agent', action, payload: { iid, ... } }`
|
|
106
|
+
*/
|
|
107
|
+
export const agentEvents = {
|
|
108
|
+
/** 作答权交回给用户(宿主的开场播报已结束)。 */
|
|
109
|
+
startLearn: 'start_learn',
|
|
110
|
+
/** 本题重做。 */
|
|
111
|
+
retryLearn: 'retry_learn',
|
|
112
|
+
/** 本题判过;若宿主把收尾交给了 H5,H5 需回发一次收尾动作,否则流程不推进。 */
|
|
113
|
+
passLearn: 'pass_learn',
|
|
114
|
+
/** 用户**绕过这块 H5** 上行了一次作答(原生输入栏、原生选择器等)。 */
|
|
115
|
+
externalAnswer: 'external_answer',
|
|
116
|
+
} as const;
|
|
117
|
+
|
|
118
|
+
export interface AgentEventPayload {
|
|
119
|
+
/**
|
|
120
|
+
* 这条事件属于哪一屏。
|
|
121
|
+
*
|
|
122
|
+
* 内容(`render/set`)和事件通常来自宿主上游的两条独立消息,到达先后不保证。
|
|
123
|
+
* 拿它对齐「这条事件说的是不是我现在这一屏」,不匹配就先扣着。
|
|
124
|
+
*/
|
|
125
|
+
iid?: string;
|
|
126
|
+
[key: string]: unknown;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface ExternalAnswerPayload extends AgentEventPayload {
|
|
130
|
+
/** 那次绕过本页的上行负载(形态由宿主定义)。 */
|
|
131
|
+
answer?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface AgentEventHandlers {
|
|
135
|
+
startLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
136
|
+
retryLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
137
|
+
passLearn?(payload: AgentEventPayload, message: BridgeMessage<AgentEventPayload>): void;
|
|
138
|
+
externalAnswer?(payload: ExternalAnswerPayload, message: BridgeMessage<ExternalAnswerPayload>): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 只订阅传了 handler 的那几个事件;返回的函数一次性退订。 */
|
|
142
|
+
export function bindAgentProtocol(
|
|
143
|
+
handlers: AgentEventHandlers,
|
|
144
|
+
transport: Pick<ProtocolTransport, 'on'> = bridge,
|
|
145
|
+
): Unsubscribe {
|
|
146
|
+
const pairs: Array<[string, ((payload: never, message: never) => void) | undefined]> = [
|
|
147
|
+
[agentEvents.startLearn, handlers.startLearn],
|
|
148
|
+
[agentEvents.retryLearn, handlers.retryLearn],
|
|
149
|
+
[agentEvents.passLearn, handlers.passLearn],
|
|
150
|
+
[agentEvents.externalAnswer, handlers.externalAnswer],
|
|
151
|
+
];
|
|
152
|
+
const subscriptions = pairs
|
|
153
|
+
.filter(([, handler]) => handler !== undefined)
|
|
154
|
+
.map(([action, handler]) =>
|
|
155
|
+
transport.on(bridgeMessageTypes.agent, action, (message: BridgeMessage<any>) => {
|
|
156
|
+
(handler as (payload: unknown, message: unknown) => void)(message.payload ?? {}, message);
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return () => subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
161
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,21 +10,29 @@
|
|
|
10
10
|
|
|
11
11
|
// 核心 Bridge
|
|
12
12
|
export { bridge, MrpBridge } from './mrp-bridge';
|
|
13
|
-
export type {
|
|
14
|
-
BridgeMessage,
|
|
15
|
-
MessageHandler,
|
|
16
|
-
Unsubscribe,
|
|
17
|
-
} from './mrp-bridge';
|
|
13
|
+
export type { BridgeMessage, MessageHandler, Unsubscribe } from './mrp-bridge';
|
|
18
14
|
|
|
19
15
|
// 内置系统模块类型 + 工厂函数(容器核心契约)
|
|
20
16
|
export { getSystemModule } from './system-module';
|
|
21
17
|
export type {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
SystemModule,
|
|
19
|
+
ModuleAllowedResult,
|
|
20
|
+
AvailableModulesResult,
|
|
21
|
+
ContainerInfoResult,
|
|
22
|
+
ArAdaptationInfo,
|
|
23
|
+
SafeAreaInsets,
|
|
26
24
|
} from './system-module';
|
|
27
25
|
|
|
26
|
+
// App/H5 统一屏幕适配
|
|
27
|
+
export {
|
|
28
|
+
ar,
|
|
29
|
+
getArScale,
|
|
30
|
+
getSafeArea,
|
|
31
|
+
initArAdaptation,
|
|
32
|
+
onArAdaptationChange,
|
|
33
|
+
} from './adaptation';
|
|
34
|
+
export type { ArAdaptationListener } from './adaptation';
|
|
35
|
+
|
|
28
36
|
// Generated 模块:类型 + 工厂函数
|
|
29
37
|
export * from '../generated/index';
|
|
30
38
|
|
|
@@ -34,17 +42,22 @@ export type { RouteChangedPayload, AppMountedPayload } from './lifecycle';
|
|
|
34
42
|
|
|
35
43
|
// 标准内容渲染、交互与错误协议
|
|
36
44
|
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
agentEvents,
|
|
46
|
+
bindAgentProtocol,
|
|
47
|
+
bindRenderProtocol,
|
|
48
|
+
bridgeError,
|
|
49
|
+
bridgeMessageTypes,
|
|
50
|
+
interaction,
|
|
51
|
+
renderActions,
|
|
52
|
+
renderProtocol,
|
|
43
53
|
} from './content-protocol';
|
|
44
54
|
export type {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
AgentEventHandlers,
|
|
56
|
+
AgentEventPayload,
|
|
57
|
+
BridgeErrorPayload,
|
|
58
|
+
ExternalAnswerPayload,
|
|
59
|
+
InteractionPayload,
|
|
60
|
+
ProtocolTransport,
|
|
61
|
+
RenderHandlers,
|
|
62
|
+
RenderPayload,
|
|
50
63
|
} from './content-protocol';
|
package/src/system-module.ts
CHANGED
|
@@ -23,22 +23,41 @@ import { bridge } from './mrp-bridge';
|
|
|
23
23
|
|
|
24
24
|
/** isModuleAllowed 返回值 */
|
|
25
25
|
export interface ModuleAllowedResult {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
allowed: boolean;
|
|
27
|
+
namespace: string;
|
|
28
|
+
error?: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** getAvailableModules 返回值 */
|
|
32
32
|
export interface AvailableModulesResult {
|
|
33
|
-
|
|
33
|
+
modules: string[];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** getContainerInfo 返回值 */
|
|
37
37
|
export interface ContainerInfoResult {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
packageId: string | null;
|
|
39
|
+
registeredModules: string[];
|
|
40
|
+
allowedModules: string[] | null;
|
|
41
|
+
adaptation?: ArAdaptationInfo;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** App 与 H5 共用的 `.ar` 屏幕适配信息。 */
|
|
46
|
+
export interface ArAdaptationInfo {
|
|
47
|
+
designLongSide: number;
|
|
48
|
+
screenWidth: number;
|
|
49
|
+
screenHeight: number;
|
|
50
|
+
scale: number;
|
|
51
|
+
/** 设备安全区(逻辑像素)。WebView 里 `env(safe-area-inset-*)` 常常拿不到,改由 App 注入。 */
|
|
52
|
+
safeArea?: SafeAreaInsets;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 设备四边的安全区尺寸,单位与 screenWidth/screenHeight 一致。 */
|
|
56
|
+
export interface SafeAreaInsets {
|
|
57
|
+
top: number;
|
|
58
|
+
bottom: number;
|
|
59
|
+
left: number;
|
|
60
|
+
right: number;
|
|
42
61
|
}
|
|
43
62
|
|
|
44
63
|
// ============================================================
|
|
@@ -51,12 +70,12 @@ export interface ContainerInfoResult {
|
|
|
51
70
|
* 提供模块权限查询、可用模块列表、容器元信息获取等能力。
|
|
52
71
|
*/
|
|
53
72
|
export interface SystemModule {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
/** 查询指定模块是否被当前包授权 */
|
|
74
|
+
isModuleAllowed(params: { namespace: string }): Promise<ModuleAllowedResult>;
|
|
75
|
+
/** 获取当前包可用的所有模块命名空间列表 */
|
|
76
|
+
getAvailableModules(): Promise<AvailableModulesResult>;
|
|
77
|
+
/** 获取容器元信息 */
|
|
78
|
+
getContainerInfo(): Promise<ContainerInfoResult>;
|
|
60
79
|
}
|
|
61
80
|
|
|
62
81
|
// ============================================================
|
|
@@ -73,5 +92,5 @@ export interface SystemModule {
|
|
|
73
92
|
* ```
|
|
74
93
|
*/
|
|
75
94
|
export function getSystemModule(): SystemModule {
|
|
76
|
-
|
|
95
|
+
return bridge.module<SystemModule>('system');
|
|
77
96
|
}
|