zcw-shared 1.38.1 → 1.39.0
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/dist/constants/hybridConstants.d.ts +37 -0
- package/dist/constants/hybridConstants.js +38 -0
- package/dist/constants/hybridConstants.js.map +1 -0
- package/dist/functions/android/configureLaunchScreen.d.ts +17 -0
- package/dist/functions/android/configureLaunchScreen.js +233 -0
- package/dist/functions/android/configureLaunchScreen.js.map +1 -0
- package/dist/functions/hybrid/createBridgeMessage.d.ts +25 -0
- package/dist/functions/hybrid/createBridgeMessage.js +33 -0
- package/dist/functions/hybrid/createBridgeMessage.js.map +1 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.d.ts +11 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.js +26 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.js.map +1 -0
- package/dist/functions/hybrid/generateBridgeMessageId.d.ts +10 -0
- package/dist/functions/hybrid/generateBridgeMessageId.js +11 -0
- package/dist/functions/hybrid/generateBridgeMessageId.js.map +1 -0
- package/dist/functions/hybrid/postBridgeMessage.d.ts +16 -0
- package/dist/functions/hybrid/postBridgeMessage.js +68 -0
- package/dist/functions/hybrid/postBridgeMessage.js.map +1 -0
- package/dist/functions/hybrid/validateBridgeMessage.d.ts +5 -0
- package/dist/functions/hybrid/validateBridgeMessage.js +55 -0
- package/dist/functions/hybrid/validateBridgeMessage.js.map +1 -0
- package/dist/functions/ios/configureLaunchScreen.d.ts +17 -0
- package/dist/functions/ios/configureLaunchScreen.js +137 -0
- package/dist/functions/ios/configureLaunchScreen.js.map +1 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.d.ts +2 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js +26 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.d.ts +4 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.js +363 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.js.map +1 -1
- package/dist/hybrid/constants.d.ts +37 -0
- package/dist/hybrid/constants.js +38 -0
- package/dist/hybrid/constants.js.map +1 -0
- package/dist/hybrid/createBridgeMessage.d.ts +17 -0
- package/dist/hybrid/createBridgeMessage.js +81 -0
- package/dist/hybrid/createBridgeMessage.js.map +1 -0
- package/dist/hybrid/types.d.ts +88 -0
- package/dist/hybrid/types.js +2 -0
- package/dist/hybrid/types.js.map +1 -0
- package/dist/vue-hooks/browser/useBridgeMessage.d.ts +34 -0
- package/dist/vue-hooks/browser/useBridgeMessage.js +87 -0
- package/dist/vue-hooks/browser/useBridgeMessage.js.map +1 -0
- package/dist/vue-hooks/browser/useWechatJSSDK.d.ts +2 -0
- package/dist/vue-hooks/browser/useWechatJSSDK.js +16 -1
- package/dist/vue-hooks/browser/useWechatJSSDK.js.map +1 -1
- package/package.json +11 -3
- package/references/hybrid.d.ts +83 -0
- package/references/sharp.d.ts +1 -1
- package/types/hybrid.d.ts +119 -0
- package/types/uniapp-android-build.d.ts +2 -0
- package/types/uniapp-ios-build.d.ts +46 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const DEFAULT_TIMEOUT = 5000;
|
|
2
|
+
export declare const DEFAULT_RETRY = 0;
|
|
3
|
+
export declare const DEFAULT_ENABLE_LOG = false;
|
|
4
|
+
export declare const MESSAGE_TYPES: {
|
|
5
|
+
readonly REQUEST: "request";
|
|
6
|
+
readonly RESPONSE: "response";
|
|
7
|
+
readonly EVENT: "event";
|
|
8
|
+
readonly ERROR: "error";
|
|
9
|
+
};
|
|
10
|
+
export declare const ACTIONS: {
|
|
11
|
+
readonly SHARE: "share";
|
|
12
|
+
readonly LOGIN: "login";
|
|
13
|
+
readonly PAY: "pay";
|
|
14
|
+
readonly LOCATION: "location";
|
|
15
|
+
readonly FILE: "file";
|
|
16
|
+
readonly SCAN: "scan";
|
|
17
|
+
readonly USER_INFO: "userInfo";
|
|
18
|
+
readonly CUSTOM: "custom";
|
|
19
|
+
};
|
|
20
|
+
export declare const ERROR_CODES: {
|
|
21
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
22
|
+
readonly NOT_AVAILABLE: "NOT_AVAILABLE";
|
|
23
|
+
readonly INVALID_MESSAGE: "INVALID_MESSAGE";
|
|
24
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
25
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
26
|
+
readonly TARGET_NOT_FOUND: "TARGET_NOT_FOUND";
|
|
27
|
+
readonly METHOD_NOT_SUPPORTED: "METHOD_NOT_SUPPORTED";
|
|
28
|
+
};
|
|
29
|
+
export declare const ERROR_MESSAGES: {
|
|
30
|
+
readonly TIMEOUT: "请求超时";
|
|
31
|
+
readonly NOT_AVAILABLE: "当前环境不支持此功能";
|
|
32
|
+
readonly INVALID_MESSAGE: "无效的消息格式";
|
|
33
|
+
readonly NETWORK_ERROR: "网络错误";
|
|
34
|
+
readonly UNKNOWN_ERROR: "未知错误";
|
|
35
|
+
readonly TARGET_NOT_FOUND: "目标环境未找到";
|
|
36
|
+
readonly METHOD_NOT_SUPPORTED: "不支持的方法";
|
|
37
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const DEFAULT_TIMEOUT = 5000;
|
|
2
|
+
export const DEFAULT_RETRY = 0;
|
|
3
|
+
export const DEFAULT_ENABLE_LOG = false;
|
|
4
|
+
export const MESSAGE_TYPES = {
|
|
5
|
+
REQUEST: 'request',
|
|
6
|
+
RESPONSE: 'response',
|
|
7
|
+
EVENT: 'event',
|
|
8
|
+
ERROR: 'error'
|
|
9
|
+
};
|
|
10
|
+
export const ACTIONS = {
|
|
11
|
+
SHARE: 'share',
|
|
12
|
+
LOGIN: 'login',
|
|
13
|
+
PAY: 'pay',
|
|
14
|
+
LOCATION: 'location',
|
|
15
|
+
FILE: 'file',
|
|
16
|
+
SCAN: 'scan',
|
|
17
|
+
USER_INFO: 'userInfo',
|
|
18
|
+
CUSTOM: 'custom'
|
|
19
|
+
};
|
|
20
|
+
export const ERROR_CODES = {
|
|
21
|
+
TIMEOUT: 'TIMEOUT',
|
|
22
|
+
NOT_AVAILABLE: 'NOT_AVAILABLE',
|
|
23
|
+
INVALID_MESSAGE: 'INVALID_MESSAGE',
|
|
24
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
25
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
26
|
+
TARGET_NOT_FOUND: 'TARGET_NOT_FOUND',
|
|
27
|
+
METHOD_NOT_SUPPORTED: 'METHOD_NOT_SUPPORTED'
|
|
28
|
+
};
|
|
29
|
+
export const ERROR_MESSAGES = {
|
|
30
|
+
[ERROR_CODES.TIMEOUT]: '请求超时',
|
|
31
|
+
[ERROR_CODES.NOT_AVAILABLE]: '当前环境不支持此功能',
|
|
32
|
+
[ERROR_CODES.INVALID_MESSAGE]: '无效的消息格式',
|
|
33
|
+
[ERROR_CODES.NETWORK_ERROR]: '网络错误',
|
|
34
|
+
[ERROR_CODES.UNKNOWN_ERROR]: '未知错误',
|
|
35
|
+
[ERROR_CODES.TARGET_NOT_FOUND]: '目标环境未找到',
|
|
36
|
+
[ERROR_CODES.METHOD_NOT_SUPPORTED]: '不支持的方法'
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=hybridConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hybridConstants.js","sourceRoot":"","sources":["../../src/constants/hybridConstants.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAA;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA;AAC9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;CACN,CAAA;AAEV,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,QAAQ;CACR,CAAA;AAEV,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,kBAAkB;IACpC,oBAAoB,EAAE,sBAAsB;CACpC,CAAA;AAEV,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM;IAC7B,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY;IACzC,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,SAAS;IACxC,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM;IACnC,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM;IACnC,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,SAAS;IACzC,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,QAAQ;CACpC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FileSystem, Path } from '../../../references/node.d';
|
|
2
|
+
import type { Sharp } from '../../../references/sharp.d';
|
|
3
|
+
export interface ConfigureLaunchScreenAndroidDeps {
|
|
4
|
+
existsSync: FileSystem['existsSync'];
|
|
5
|
+
readFileSync: FileSystem['readFileSync'];
|
|
6
|
+
writeFileSync: FileSystem['writeFileSync'];
|
|
7
|
+
mkdirSync: FileSystem['mkdirSync'];
|
|
8
|
+
join: Path['join'];
|
|
9
|
+
dirname: Path['dirname'];
|
|
10
|
+
sharp: Sharp;
|
|
11
|
+
}
|
|
12
|
+
export interface ConfigureLaunchScreenAndroidResult {
|
|
13
|
+
success: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
logs: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function configureLaunchScreenAndroid(imagePath: string, projectPath: string, moduleDir: string, deps: ConfigureLaunchScreenAndroidDeps): Promise<ConfigureLaunchScreenAndroidResult>;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const ANDROID_LAUNCH_SCREEN_SIZES = [
|
|
2
|
+
{ density: 'ldpi', width: 240, height: 400 },
|
|
3
|
+
{ density: 'mdpi', width: 320, height: 480 },
|
|
4
|
+
{ density: 'hdpi', width: 480, height: 800 },
|
|
5
|
+
{ density: 'xhdpi', width: 720, height: 1280 },
|
|
6
|
+
{ density: 'xxhdpi', width: 1080, height: 1920 },
|
|
7
|
+
{ density: 'xxxhdpi', width: 1440, height: 2560 }
|
|
8
|
+
];
|
|
9
|
+
export async function configureLaunchScreenAndroid(imagePath, projectPath, moduleDir, deps) {
|
|
10
|
+
const logs = [];
|
|
11
|
+
try {
|
|
12
|
+
if (!deps.existsSync(imagePath)) {
|
|
13
|
+
return {
|
|
14
|
+
success: false,
|
|
15
|
+
error: `原始图片不存在: ${imagePath}`,
|
|
16
|
+
logs
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
logs.push(`找到原始图片: ${imagePath}`);
|
|
20
|
+
const imageBuffer = deps.readFileSync(imagePath);
|
|
21
|
+
logs.push('成功读取原始图片');
|
|
22
|
+
const sharpInstance = deps.sharp(imageBuffer);
|
|
23
|
+
const metadata = await sharpInstance.metadata();
|
|
24
|
+
const originalWidth = metadata.width || 1080;
|
|
25
|
+
const originalHeight = metadata.height || 1920;
|
|
26
|
+
logs.push(`原图尺寸: ${originalWidth}x${originalHeight}`);
|
|
27
|
+
const resPath = deps.join(projectPath, moduleDir, 'src', 'main', 'res');
|
|
28
|
+
if (!deps.existsSync(resPath)) {
|
|
29
|
+
return {
|
|
30
|
+
success: false,
|
|
31
|
+
error: `资源目录不存在: ${resPath}`,
|
|
32
|
+
logs
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
logs.push('开始生成不同密度的启动屏图片...');
|
|
36
|
+
for (const sizeConfig of ANDROID_LAUNCH_SCREEN_SIZES) {
|
|
37
|
+
const drawableDir = deps.join(resPath, `drawable-${sizeConfig.density}`);
|
|
38
|
+
if (!deps.existsSync(drawableDir)) {
|
|
39
|
+
deps.mkdirSync(drawableDir, { recursive: true });
|
|
40
|
+
logs.push(`创建目录: drawable-${sizeConfig.density}`);
|
|
41
|
+
}
|
|
42
|
+
const resizedImage = await deps.sharp(imageBuffer)
|
|
43
|
+
.resize(sizeConfig.width, sizeConfig.height, {
|
|
44
|
+
fit: 'contain',
|
|
45
|
+
position: 'center'
|
|
46
|
+
})
|
|
47
|
+
.png()
|
|
48
|
+
.toBuffer();
|
|
49
|
+
const imagePath = deps.join(drawableDir, 'splash.png');
|
|
50
|
+
deps.writeFileSync(imagePath, resizedImage);
|
|
51
|
+
logs.push(`已生成 ${sizeConfig.density} 版本 (${sizeConfig.width}x${sizeConfig.height})`);
|
|
52
|
+
}
|
|
53
|
+
const drawableDir = deps.join(resPath, 'drawable');
|
|
54
|
+
if (!deps.existsSync(drawableDir)) {
|
|
55
|
+
deps.mkdirSync(drawableDir, { recursive: true });
|
|
56
|
+
logs.push('创建 drawable 目录');
|
|
57
|
+
}
|
|
58
|
+
const splashScreenXml = generateSplashScreenXml();
|
|
59
|
+
const splashScreenXmlPath = deps.join(drawableDir, 'splash_screen.xml');
|
|
60
|
+
deps.writeFileSync(splashScreenXmlPath, splashScreenXml, 'utf8');
|
|
61
|
+
logs.push('已创建 splash_screen.xml');
|
|
62
|
+
const launchBackgroundXml = generateLaunchBackgroundXml();
|
|
63
|
+
const launchBackgroundXmlPath = deps.join(drawableDir, 'launch_background.xml');
|
|
64
|
+
deps.writeFileSync(launchBackgroundXmlPath, launchBackgroundXml, 'utf8');
|
|
65
|
+
logs.push('已创建 launch_background.xml(用于解决启动白屏)');
|
|
66
|
+
const valuesDir = deps.join(resPath, 'values');
|
|
67
|
+
if (!deps.existsSync(valuesDir)) {
|
|
68
|
+
deps.mkdirSync(valuesDir, { recursive: true });
|
|
69
|
+
logs.push('创建 values 目录');
|
|
70
|
+
}
|
|
71
|
+
const colorsXmlPath = deps.join(valuesDir, 'colors.xml');
|
|
72
|
+
if (!deps.existsSync(colorsXmlPath)) {
|
|
73
|
+
const colorsXml = generateColorsXml();
|
|
74
|
+
deps.writeFileSync(colorsXmlPath, colorsXml, 'utf8');
|
|
75
|
+
logs.push('已创建 colors.xml');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logs.push('colors.xml 已存在,跳过创建');
|
|
79
|
+
}
|
|
80
|
+
const stylesXmlPath = deps.join(valuesDir, 'styles.xml');
|
|
81
|
+
let stylesXmlContent;
|
|
82
|
+
if (deps.existsSync(stylesXmlPath)) {
|
|
83
|
+
stylesXmlContent = deps.readFileSync(stylesXmlPath, 'utf8');
|
|
84
|
+
logs.push('读取现有的 styles.xml');
|
|
85
|
+
let modified = false;
|
|
86
|
+
if (!stylesXmlContent.includes('name="LaunchTheme"')) {
|
|
87
|
+
const launchThemeStyle = generateLaunchThemeStyle();
|
|
88
|
+
stylesXmlContent = stylesXmlContent.replace('</resources>', ` ${launchThemeStyle}\n</resources>`);
|
|
89
|
+
modified = true;
|
|
90
|
+
logs.push('已添加 LaunchTheme 到 styles.xml');
|
|
91
|
+
}
|
|
92
|
+
if (!stylesXmlContent.includes('name="TranslucentTheme"')) {
|
|
93
|
+
const translucentThemeStyle = generateTranslucentThemeStyle();
|
|
94
|
+
stylesXmlContent = stylesXmlContent.replace('</resources>', ` ${translucentThemeStyle}\n</resources>`);
|
|
95
|
+
modified = true;
|
|
96
|
+
logs.push('已添加 TranslucentTheme 到 styles.xml(修复启动白屏)');
|
|
97
|
+
}
|
|
98
|
+
if (!stylesXmlContent.includes('name="SplashTheme"')) {
|
|
99
|
+
const splashThemeStyle = generateSplashThemeStyle();
|
|
100
|
+
stylesXmlContent = stylesXmlContent.replace('</resources>', ` ${splashThemeStyle}\n</resources>`);
|
|
101
|
+
modified = true;
|
|
102
|
+
logs.push('已添加 SplashTheme 到 styles.xml');
|
|
103
|
+
}
|
|
104
|
+
if (!stylesXmlContent.includes('name="DCloudTheme"')) {
|
|
105
|
+
const dcloudThemeStyle = generateDCloudThemeStyle();
|
|
106
|
+
stylesXmlContent = stylesXmlContent.replace('</resources>', ` ${dcloudThemeStyle}\n</resources>`);
|
|
107
|
+
modified = true;
|
|
108
|
+
logs.push('已添加 DCloudTheme 到 styles.xml');
|
|
109
|
+
}
|
|
110
|
+
if (modified) {
|
|
111
|
+
deps.writeFileSync(stylesXmlPath, stylesXmlContent, 'utf8');
|
|
112
|
+
logs.push('styles.xml 更新完成');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
logs.push('所有主题已存在,无需更新');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
stylesXmlContent = generateStylesXml();
|
|
120
|
+
deps.writeFileSync(stylesXmlPath, stylesXmlContent, 'utf8');
|
|
121
|
+
logs.push('已创建 styles.xml 并添加所有启动主题');
|
|
122
|
+
}
|
|
123
|
+
logs.push('Android 启动屏配置完成');
|
|
124
|
+
logs.push('');
|
|
125
|
+
logs.push('📝 提示:');
|
|
126
|
+
logs.push(' 1. 如果 AndroidManifest.xml 中启动 Activity 使用 @style/TranslucentTheme');
|
|
127
|
+
logs.push(' 无需修改,已自动配置启动屏背景,不会出现白屏');
|
|
128
|
+
logs.push(' 2. 或者将启动 Activity 的主题改为 @style/LaunchTheme');
|
|
129
|
+
logs.push(' 3. 在 Activity 的 onCreate 中记得恢复正常主题:');
|
|
130
|
+
logs.push(' setTheme(R.style.AppTheme);');
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
logs
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
error: `配置 Android 启动屏时出错: ${errorMessage}`,
|
|
141
|
+
logs
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function generateSplashScreenXml() {
|
|
146
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
147
|
+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
148
|
+
<!-- 背景颜色 -->
|
|
149
|
+
<item android:drawable="@color/splash_background"/>
|
|
150
|
+
|
|
151
|
+
<!-- 启动图片,居中显示 -->
|
|
152
|
+
<item>
|
|
153
|
+
<bitmap
|
|
154
|
+
android:gravity="center"
|
|
155
|
+
android:src="@drawable/splash"/>
|
|
156
|
+
</item>
|
|
157
|
+
</layer-list>
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
function generateLaunchBackgroundXml() {
|
|
161
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
162
|
+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
163
|
+
<!-- 背景颜色 -->
|
|
164
|
+
<item android:drawable="@color/splash_background"/>
|
|
165
|
+
|
|
166
|
+
<!-- 启动图片,居中显示 -->
|
|
167
|
+
<item>
|
|
168
|
+
<bitmap
|
|
169
|
+
android:gravity="center"
|
|
170
|
+
android:src="@drawable/splash"/>
|
|
171
|
+
</item>
|
|
172
|
+
</layer-list>
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
function generateColorsXml() {
|
|
176
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
177
|
+
<resources>
|
|
178
|
+
<!-- 启动屏背景颜色 -->
|
|
179
|
+
<color name="splash_background">#FFFFFF</color>
|
|
180
|
+
</resources>
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function generateLaunchThemeStyle() {
|
|
184
|
+
return `<!-- 启动主题(推荐) -->
|
|
185
|
+
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
186
|
+
<item name="android:windowBackground">@drawable/launch_background</item>
|
|
187
|
+
<item name="android:windowNoTitle">true</item>
|
|
188
|
+
<item name="android:windowFullscreen">false</item>
|
|
189
|
+
<item name="android:windowContentOverlay">@null</item>
|
|
190
|
+
<item name="android:windowIsTranslucent">false</item>
|
|
191
|
+
</style>`;
|
|
192
|
+
}
|
|
193
|
+
function generateTranslucentThemeStyle() {
|
|
194
|
+
return `<!-- TranslucentTheme(修复启动白屏) -->
|
|
195
|
+
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
196
|
+
<item name="android:windowBackground">@drawable/launch_background</item>
|
|
197
|
+
<item name="android:windowNoTitle">true</item>
|
|
198
|
+
<item name="android:windowFullscreen">false</item>
|
|
199
|
+
<item name="android:windowContentOverlay">@null</item>
|
|
200
|
+
<item name="android:windowIsTranslucent">false</item>
|
|
201
|
+
</style>`;
|
|
202
|
+
}
|
|
203
|
+
function generateSplashThemeStyle() {
|
|
204
|
+
return `<!-- 启动屏主题(向后兼容) -->
|
|
205
|
+
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
206
|
+
<item name="android:windowBackground">@drawable/splash_screen</item>
|
|
207
|
+
<item name="android:windowNoTitle">true</item>
|
|
208
|
+
<item name="android:windowFullscreen">true</item>
|
|
209
|
+
<item name="android:windowContentOverlay">@null</item>
|
|
210
|
+
</style>`;
|
|
211
|
+
}
|
|
212
|
+
function generateDCloudThemeStyle() {
|
|
213
|
+
return `<!-- DCloud 主题 -->
|
|
214
|
+
<style name="DCloudTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
215
|
+
<item name="android:windowBackground">@drawable/launch_background</item>
|
|
216
|
+
<item name="android:windowNoTitle">true</item>
|
|
217
|
+
<item name="android:windowContentOverlay">@null</item>
|
|
218
|
+
</style>`;
|
|
219
|
+
}
|
|
220
|
+
function generateStylesXml() {
|
|
221
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
222
|
+
<resources>
|
|
223
|
+
${generateLaunchThemeStyle()}
|
|
224
|
+
|
|
225
|
+
${generateTranslucentThemeStyle()}
|
|
226
|
+
|
|
227
|
+
${generateSplashThemeStyle()}
|
|
228
|
+
|
|
229
|
+
${generateDCloudThemeStyle()}
|
|
230
|
+
</resources>
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=configureLaunchScreen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureLaunchScreen.js","sourceRoot":"","sources":["../../../src/functions/android/configureLaunchScreen.ts"],"names":[],"mappings":"AAgCA,MAAM,2BAA2B,GAAG;IAClC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5C,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5C,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5C,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAC9C,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAChD,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;CAClD,CAAA;AAoCD,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,SAAiB,EACjB,WAAmB,EACnB,SAAiB,EACjB,IAAsC;IAEtC,MAAM,IAAI,GAAa,EAAE,CAAA;IAEzB,IAAI,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,OAA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;AACD,CAAC;AAMD,SAAS,2BAA2B;IAClC,OAAO;;;;;;;;;;;;CAYR,CAAA;AACD,CAAC;AAKD,SAAS,iBAAiB;IACxB,OAAO;;;;;CAKR,CAAA;AACD,CAAC;AAKD,SAAS,wBAAwB;IAC/B,OAAO;;;;;;;aAOI,CAAA;AACb,CAAC;AAKD,SAAS,6BAA6B;IACpC,OAAO;;;;;;;aAOI,CAAA;AACb,CAAC;AAKD,SAAS,wBAAwB;IAC/B,OAAO;;;;;;aAMI,CAAA;AACb,CAAC;AAKD,SAAS,wBAAwB;IAC/B,OAAO;;;;;aAKI,CAAA;AACb,CAAC;AAKD,SAAS,iBAAiB;IACxB,OAAO;;MAEH,wBAAwB,EAAE;;MAE1B,6BAA6B,EAAE;;MAE/B,wBAAwB,EAAE;;MAE1B,wBAAwB,EAAE;;CAE/B,CAAA;AACD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestMessage, ResponseMessage, EventMessage } from '../../../types/hybrid';
|
|
2
|
+
import type { GenerateBridgeMessageIdDeps } from './generateBridgeMessageId';
|
|
3
|
+
export interface CreateBridgeMessageDeps extends GenerateBridgeMessageIdDeps {
|
|
4
|
+
}
|
|
5
|
+
export interface CreateRequestMessageOptions {
|
|
6
|
+
method: string;
|
|
7
|
+
params?: any;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateResponseMessageOptions {
|
|
10
|
+
requestId: string;
|
|
11
|
+
success: boolean;
|
|
12
|
+
data?: any;
|
|
13
|
+
error?: {
|
|
14
|
+
code: string | number;
|
|
15
|
+
message: string;
|
|
16
|
+
details?: any;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface CreateEventMessageOptions {
|
|
20
|
+
event: string;
|
|
21
|
+
data?: any;
|
|
22
|
+
}
|
|
23
|
+
export declare function createRequestMessage(action: string, deps: CreateBridgeMessageDeps, options: CreateRequestMessageOptions): RequestMessage;
|
|
24
|
+
export declare function createResponseMessage(action: string, deps: CreateBridgeMessageDeps, options: CreateResponseMessageOptions): ResponseMessage;
|
|
25
|
+
export declare function createEventMessage(action: string, deps: CreateBridgeMessageDeps, options: CreateEventMessageOptions): EventMessage;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { generateBridgeMessageId } from './generateBridgeMessageId';
|
|
2
|
+
export function createRequestMessage(action, deps, options) {
|
|
3
|
+
return {
|
|
4
|
+
id: generateBridgeMessageId(deps),
|
|
5
|
+
type: 'request',
|
|
6
|
+
action,
|
|
7
|
+
method: options.method,
|
|
8
|
+
params: options.params,
|
|
9
|
+
timestamp: deps.Date.now()
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function createResponseMessage(action, deps, options) {
|
|
13
|
+
return {
|
|
14
|
+
id: options.requestId,
|
|
15
|
+
type: 'response',
|
|
16
|
+
action,
|
|
17
|
+
success: options.success,
|
|
18
|
+
data: options.data,
|
|
19
|
+
error: options.error,
|
|
20
|
+
timestamp: deps.Date.now()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function createEventMessage(action, deps, options) {
|
|
24
|
+
return {
|
|
25
|
+
id: generateBridgeMessageId(deps),
|
|
26
|
+
type: 'event',
|
|
27
|
+
action,
|
|
28
|
+
event: options.event,
|
|
29
|
+
data: options.data,
|
|
30
|
+
timestamp: deps.Date.now()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=createBridgeMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBridgeMessage.js","sourceRoot":"","sources":["../../../src/functions/hybrid/createBridgeMessage.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AAgDnE,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,IAA6B,EAC7B,OAAoC;IAEpC,OAAO;QACL,EAAE,EAAE,uBAAuB,CAAC,IAAI,CAAC;QACjC,IAAI,EAAE,SAAS;QACf,MAAM;QACN,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;KAC3B,CAAA;AACH,CAAC;AAKD,MAAM,UAAU,qBAAqB,CACnC,MAAc,EACd,IAA6B,EAC7B,OAAqC;IAErC,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,SAAS;QACrB,IAAI,EAAE,UAAU;QAChB,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;KAC3B,CAAA;AACH,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,IAA6B,EAC7B,OAAkC;IAElC,OAAO;QACL,EAAE,EAAE,uBAAuB,CAAC,IAAI,CAAC;QACjC,IAAI,EAAE,OAAO;QACb,MAAM;QACN,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;KAC3B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Environment } from '../../../types/hybrid';
|
|
2
|
+
import type { WxJsSdk, UniWindow } from '../../../references/hybrid.d';
|
|
3
|
+
export interface PlatformDetectionDeps {
|
|
4
|
+
isServer: () => boolean;
|
|
5
|
+
getWindow: () => UniWindow | null;
|
|
6
|
+
getNavigator: () => {
|
|
7
|
+
userAgent: string;
|
|
8
|
+
} | null;
|
|
9
|
+
getWx: () => WxJsSdk | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function detectBridgeEnvironment(deps: PlatformDetectionDeps): Environment;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function detectBridgeEnvironment(deps) {
|
|
2
|
+
if (deps.isServer()) {
|
|
3
|
+
return 'unknown';
|
|
4
|
+
}
|
|
5
|
+
const window = deps.getWindow();
|
|
6
|
+
if (!window) {
|
|
7
|
+
return 'unknown';
|
|
8
|
+
}
|
|
9
|
+
const wx = deps.getWx();
|
|
10
|
+
if (wx && wx.miniProgram) {
|
|
11
|
+
return 'miniapp';
|
|
12
|
+
}
|
|
13
|
+
const navigator = deps.getNavigator();
|
|
14
|
+
const ua = navigator?.userAgent?.toLowerCase() || '';
|
|
15
|
+
if (window.uni && (window.uni.postMessage || window.uni.webView)) {
|
|
16
|
+
return 'app';
|
|
17
|
+
}
|
|
18
|
+
if (window.plus && window.plus.webview) {
|
|
19
|
+
return 'app';
|
|
20
|
+
}
|
|
21
|
+
if (ua.includes('app-webview') || ua.includes('uniapp')) {
|
|
22
|
+
return 'app';
|
|
23
|
+
}
|
|
24
|
+
return 'h5';
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=detectBridgeEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectBridgeEnvironment.js","sourceRoot":"","sources":["../../../src/functions/hybrid/detectBridgeEnvironment.ts"],"names":[],"mappings":"AA4CA,MAAM,UAAU,uBAAuB,CAAC,IAA2B;IAEjE,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QACpB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC;IAGD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;IACvB,IAAI,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACzB,OAAO,SAAS,CAAA;IAClB,CAAC;IAGD,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;IACrC,MAAM,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IAGpD,IAAK,MAAc,CAAC,GAAG,IAAI,CAAE,MAAc,CAAC,GAAG,CAAC,WAAW,IAAK,MAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5F,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,IAAK,MAAc,CAAC,IAAI,IAAK,MAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACzD,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,IAAI,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface GenerateBridgeMessageIdDeps {
|
|
2
|
+
Date: {
|
|
3
|
+
now: typeof Date.now;
|
|
4
|
+
};
|
|
5
|
+
Math: {
|
|
6
|
+
random: typeof Math.random;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function generateBridgeMessageId(deps: GenerateBridgeMessageIdDeps): string;
|
|
10
|
+
export declare function resetBridgeMessageIdCounter(): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let messageIdCounter = 0;
|
|
2
|
+
export function generateBridgeMessageId(deps) {
|
|
3
|
+
messageIdCounter++;
|
|
4
|
+
const timestamp = deps.Date.now();
|
|
5
|
+
const random = deps.Math.random().toString(36).substring(2, 9);
|
|
6
|
+
return `msg_${timestamp}_${messageIdCounter}_${random}`;
|
|
7
|
+
}
|
|
8
|
+
export function resetBridgeMessageIdCounter() {
|
|
9
|
+
messageIdCounter = 0;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=generateBridgeMessageId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateBridgeMessageId.js","sourceRoot":"","sources":["../../../src/functions/hybrid/generateBridgeMessageId.ts"],"names":[],"mappings":"AAqCA,IAAI,gBAAgB,GAAG,CAAC,CAAA;AAKxB,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,gBAAgB,EAAE,CAAA;IAClB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9D,OAAO,OAAO,SAAS,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAA;AACzD,CAAC;AAKD,MAAM,UAAU,2BAA2B;IACzC,gBAAgB,GAAG,CAAC,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RequestMessage } from '../../../types/hybrid';
|
|
2
|
+
import type { WxJsSdk, UniWindow } from '../../../references/hybrid.d';
|
|
3
|
+
import type { Window } from '../../../references/browser.d';
|
|
4
|
+
import type { setTimeout } from '../../../references/timer.d';
|
|
5
|
+
export interface PostBridgeMessageOptions {
|
|
6
|
+
useTransferPage?: boolean;
|
|
7
|
+
autoNavigateBack?: boolean;
|
|
8
|
+
navigateBackDelay?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface PostBridgeMessageDeps {
|
|
11
|
+
isServer: () => boolean;
|
|
12
|
+
getWindow: () => Window | UniWindow | null;
|
|
13
|
+
getWx: () => WxJsSdk | null;
|
|
14
|
+
setTimeout: typeof setTimeout;
|
|
15
|
+
}
|
|
16
|
+
export declare function postBridgeMessage(message: RequestMessage, direction: 'h5-to-miniapp' | 'h5-to-app', deps: PostBridgeMessageDeps, options?: PostBridgeMessageOptions): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export async function postBridgeMessage(message, direction, deps, options = {}) {
|
|
2
|
+
if (deps.isServer()) {
|
|
3
|
+
throw new Error('服务端环境不支持发送 Bridge 消息');
|
|
4
|
+
}
|
|
5
|
+
const window = deps.getWindow();
|
|
6
|
+
if (!window) {
|
|
7
|
+
throw new Error('window 对象不存在');
|
|
8
|
+
}
|
|
9
|
+
const messageData = {
|
|
10
|
+
...message,
|
|
11
|
+
from: 'h5',
|
|
12
|
+
direction
|
|
13
|
+
};
|
|
14
|
+
if (direction === 'h5-to-miniapp') {
|
|
15
|
+
const wx = deps.getWx();
|
|
16
|
+
if (!wx || !wx.miniProgram) {
|
|
17
|
+
throw new Error('wx.miniProgram 不可用');
|
|
18
|
+
}
|
|
19
|
+
if (options.useTransferPage) {
|
|
20
|
+
const h5BaseUrl = window.location.origin;
|
|
21
|
+
const messageParam = encodeURIComponent(JSON.stringify(messageData));
|
|
22
|
+
const transferH5Url = `${h5BaseUrl}/bridge-transfer?message=${messageParam}`;
|
|
23
|
+
const miniprogramUrl = `/pages/webview/webview?url=${encodeURIComponent(transferH5Url)}`;
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
wx.miniProgram.navigateTo({
|
|
26
|
+
url: miniprogramUrl,
|
|
27
|
+
success: () => resolve(),
|
|
28
|
+
fail: (err) => reject(new Error(err.errMsg || '跳转失败'))
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
wx.miniProgram.postMessage({ data: messageData });
|
|
33
|
+
if (options.autoNavigateBack) {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
deps.setTimeout(() => {
|
|
36
|
+
wx.miniProgram.navigateBack();
|
|
37
|
+
resolve();
|
|
38
|
+
}, options.navigateBackDelay || 300);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (direction === 'h5-to-app') {
|
|
44
|
+
const uniWindow = window;
|
|
45
|
+
if (uniWindow.uni && uniWindow.uni.postMessage) {
|
|
46
|
+
uniWindow.uni.postMessage(messageData);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (uniWindow.uni && uniWindow.uni.webView && uniWindow.uni.webView.postMessage) {
|
|
50
|
+
uniWindow.uni.webView.postMessage(messageData);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (uniWindow.plus && uniWindow.plus.webview) {
|
|
54
|
+
const currentWebview = uniWindow.plus.webview.currentWebview();
|
|
55
|
+
if (currentWebview && currentWebview.parent) {
|
|
56
|
+
currentWebview.parent().evalJS(`
|
|
57
|
+
if (window.handleH5Message) {
|
|
58
|
+
window.handleH5Message(${JSON.stringify(messageData)});
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw new Error('无法找到可用的 App 通信方式');
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`不支持的通信方向: ${direction}`);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=postBridgeMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postBridgeMessage.js","sourceRoot":"","sources":["../../../src/functions/hybrid/postBridgeMessage.ts"],"names":[],"mappings":"AAoEA,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAuB,EACvB,SAAwC,EACxC,IAA2B,EAC3B,UAAoC,EAAE;IAEtC,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;IACjC,CAAC;IAED,MAAM,WAAW,GAAG;QAClB,GAAG,OAAO;QACV,IAAI,EAAE,IAAI;QACV,SAAS;KACV,CAAA;IAGD,IAAI,SAAS,KAAK,eAAe,EAAE,CAAC;QAClC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;QACvB,I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,CAAC;IAGD,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,MAAmB,CAAA;QAGrC,IAAI,SAAS,CAAC,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YAC/C,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;YACtC,OAAM;QACR,CAAC;QAGD,IAAI,SAAS,CAAC,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAChF,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;YAC9C,OAAM;QACR,CAAC;QAGD,IAAI,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7C,MAAM,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;YAC9D,IAAI,cAAc,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;gBAC5C,cAAc,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC;;qCAEF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;SAEvD,CAAC,CAAA;gBACF,OAAM;YACR,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,EAAE,CAAC,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BridgeMessage, RequestMessage, ResponseMessage, EventMessage } from '../../../types/hybrid';
|
|
2
|
+
export declare function validateBridgeMessage(message: any): message is BridgeMessage;
|
|
3
|
+
export declare function validateRequestMessage(message: any): message is RequestMessage;
|
|
4
|
+
export declare function validateResponseMessage(message: any): message is ResponseMessage;
|
|
5
|
+
export declare function validateEventMessage(message: any): message is EventMessage;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function validateBridgeMessage(message) {
|
|
2
|
+
if (!message || typeof message !== 'object') {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (!message.id || typeof message.id !== 'string') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (!message.type || typeof message.type !== 'string') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (!message.action || typeof message.action !== 'string') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (typeof message.timestamp !== 'number') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
export function validateRequestMessage(message) {
|
|
20
|
+
if (!validateBridgeMessage(message)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (message.type !== 'request') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!message.method || typeof message.method !== 'string') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
export function validateResponseMessage(message) {
|
|
32
|
+
if (!validateBridgeMessage(message)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (message.type !== 'response') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (typeof message.success !== 'boolean') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
export function validateEventMessage(message) {
|
|
44
|
+
if (!validateBridgeMessage(message)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (message.type !== 'event') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!message.event || typeof message.event !== 'string') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=validateBridgeMessage.js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