@wevu/api 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -9
- package/dist/index.cjs +503 -8
- package/dist/index.d.cts +196 -6
- package/dist/index.d.mts +196 -6
- package/dist/index.mjs +501 -7
- package/package.json +17 -7
- package/types/index.d.ts +54 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,201 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/core/types.d.ts
|
|
2
|
+
type WeapiAdapter = Record<string, any>;
|
|
3
|
+
/**
|
|
4
|
+
* @description 微信小程序 API 原始适配器类型
|
|
5
|
+
*/
|
|
6
|
+
type WeapiWxRawAdapter = WechatMiniprogram.Wx;
|
|
7
|
+
/**
|
|
8
|
+
* @description 支付宝小程序 API 原始适配器类型
|
|
9
|
+
*/
|
|
10
|
+
type WeapiAlipayRawAdapter = typeof my;
|
|
11
|
+
/**
|
|
12
|
+
* @description 抖音小程序 API 原始适配器类型
|
|
13
|
+
*/
|
|
14
|
+
type WeapiDouyinRawAdapter = typeof tt;
|
|
15
|
+
type MergeAdapters<Primary extends WeapiAdapter, Secondary extends WeapiAdapter> = Primary & Omit<Secondary, keyof Primary>;
|
|
16
|
+
/**
|
|
17
|
+
* @description weapi 对齐后的跨平台原始 API 类型
|
|
18
|
+
*
|
|
19
|
+
* @generated weapi-platform-matrix:start
|
|
20
|
+
* | 平台 | 全局对象 | 类型来源 | 对齐状态 |
|
|
21
|
+
* | --- | --- | --- | --- |
|
|
22
|
+
* | 微信小程序 | `wx` | `miniprogram-api-typings` | ✅ 全量 |
|
|
23
|
+
* | 支付宝小程序 | `my` | `@mini-types/alipay` | ✅ 全量 |
|
|
24
|
+
* | 抖音小程序 | `tt` | `@douyin-microapp/typings` | ✅ 全量 |
|
|
25
|
+
* | 其他平台(swan/jd/xhs 等) | 运行时宿主对象 | 运行时透传 | ⚠️ 按宿主能力支持 |
|
|
26
|
+
* @generated weapi-platform-matrix:end
|
|
27
|
+
*/
|
|
28
|
+
type WeapiCrossPlatformRawAdapter = MergeAdapters<MergeAdapters<WeapiWxRawAdapter, WeapiAlipayRawAdapter>, WeapiDouyinRawAdapter>;
|
|
29
|
+
type HasCallbackKey<T> = T extends object ? 'success' extends keyof T ? true : 'fail' extends keyof T ? true : 'complete' extends keyof T ? true : false : false;
|
|
30
|
+
type HasCallbackOption<T> = T extends {
|
|
31
|
+
success: unknown;
|
|
32
|
+
} ? true : T extends {
|
|
33
|
+
fail: unknown;
|
|
34
|
+
} ? true : T extends {
|
|
35
|
+
complete: unknown;
|
|
36
|
+
} ? true : false;
|
|
37
|
+
type ExtractSuccessResult<T> = T extends {
|
|
38
|
+
success?: (...args: infer A) => unknown;
|
|
39
|
+
} ? A[0] : void;
|
|
40
|
+
type PromisifyOptionMethod<Prefix extends any[], Option extends object, Result, IsOptional extends boolean> = IsOptional extends true ? {
|
|
41
|
+
<TOption extends Option>(...args: [...Prefix, TOption]): HasCallbackOption<TOption> extends true ? Result : Promise<ExtractSuccessResult<Option>>;
|
|
42
|
+
(...args: Prefix): Promise<ExtractSuccessResult<Option>>;
|
|
43
|
+
} : {
|
|
44
|
+
<TOption extends Option>(...args: [...Prefix, TOption]): HasCallbackOption<TOption> extends true ? Result : Promise<ExtractSuccessResult<Option>>;
|
|
45
|
+
};
|
|
46
|
+
type NormalizePromisifyReturn<T> = T extends Promise<any> ? T : Promise<T>;
|
|
47
|
+
type PromisifyMethod<TMethod> = TMethod extends ((...args: infer Args) => infer Result) ? Args extends [] ? (...args: Args) => NormalizePromisifyReturn<Result> : Args extends [...infer Prefix, infer Last] ? true extends HasCallbackKey<NonNullable<Last>> ? PromisifyOptionMethod<Prefix, NonNullable<Last>, Result, undefined extends Last ? true : false> : (...args: Args) => NormalizePromisifyReturn<Result> : (...args: Args) => NormalizePromisifyReturn<Result> : TMethod;
|
|
48
|
+
type WeapiPromisify<TAdapter extends WeapiAdapter> = { [Key in keyof TAdapter]: Key extends string ? Key extends `${string}Sync` ? TAdapter[Key] : Key extends `on${Capitalize<string>}` | `off${Capitalize<string>}` ? TAdapter[Key] : PromisifyMethod<TAdapter[Key]> : TAdapter[Key] };
|
|
49
|
+
/**
|
|
50
|
+
* @description 微信小程序 API 适配器类型
|
|
51
|
+
*/
|
|
52
|
+
type WeapiWxAdapter = WeapiPromisify<WeapiWxRawAdapter>;
|
|
2
53
|
/**
|
|
3
|
-
* @description
|
|
54
|
+
* @description 支付宝小程序 API 适配器类型
|
|
4
55
|
*/
|
|
5
|
-
|
|
56
|
+
type WeapiAlipayAdapter = WeapiPromisify<WeapiAlipayRawAdapter>;
|
|
57
|
+
/**
|
|
58
|
+
* @description 抖音小程序 API 适配器类型
|
|
59
|
+
*/
|
|
60
|
+
type WeapiDouyinAdapter = WeapiPromisify<WeapiDouyinRawAdapter>;
|
|
61
|
+
/**
|
|
62
|
+
* @description weapi 默认导出的跨平台 API 适配器类型
|
|
63
|
+
*/
|
|
64
|
+
type WeapiCrossPlatformAdapter = WeapiPromisify<WeapiCrossPlatformRawAdapter>;
|
|
65
|
+
/**
|
|
66
|
+
* @description weapi 核心映射 API 的平台支持度说明
|
|
67
|
+
*/
|
|
68
|
+
interface WeapiCrossPlatformMethodDocs {
|
|
69
|
+
/**
|
|
70
|
+
* 显示消息提示框。
|
|
71
|
+
*
|
|
72
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
73
|
+
* | --- | --- | --- |
|
|
74
|
+
* | 微信 | 直连 `wx.showToast` | ✅ |
|
|
75
|
+
* | 支付宝 | `title/icon` 映射到 `content/type` 后调用 `my.showToast` | ✅ |
|
|
76
|
+
* | 抖音 | `icon=error` 映射为 `fail` 后调用 `tt.showToast` | ✅ |
|
|
77
|
+
*/
|
|
78
|
+
showToast: WeapiCrossPlatformAdapter['showToast'];
|
|
79
|
+
/**
|
|
80
|
+
* 显示 loading 提示框。
|
|
81
|
+
*
|
|
82
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
83
|
+
* | --- | --- | --- |
|
|
84
|
+
* | 微信 | 直连 `wx.showLoading` | ✅ |
|
|
85
|
+
* | 支付宝 | `title` 映射到 `content` 后调用 `my.showLoading` | ✅ |
|
|
86
|
+
* | 抖音 | 直连 `tt.showLoading` | ✅ |
|
|
87
|
+
*/
|
|
88
|
+
showLoading: WeapiCrossPlatformAdapter['showLoading'];
|
|
89
|
+
/**
|
|
90
|
+
* 显示操作菜单。
|
|
91
|
+
*
|
|
92
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
93
|
+
* | --- | --- | --- |
|
|
94
|
+
* | 微信 | 直连 `wx.showActionSheet` | ✅ |
|
|
95
|
+
* | 支付宝 | `itemList` ↔ `items`、`index` ↔ `tapIndex` 双向对齐 | ✅ |
|
|
96
|
+
* | 抖音 | 直连 `tt.showActionSheet`,并兼容 `index` → `tapIndex` | ✅ |
|
|
97
|
+
*/
|
|
98
|
+
showActionSheet: WeapiCrossPlatformAdapter['showActionSheet'];
|
|
99
|
+
/**
|
|
100
|
+
* 显示模态弹窗。
|
|
101
|
+
*
|
|
102
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
103
|
+
* | --- | --- | --- |
|
|
104
|
+
* | 微信 | 直连 `wx.showModal` | ✅ |
|
|
105
|
+
* | 支付宝 | 调用 `my.confirm` 并对齐按钮字段与 `cancel` 结果 | ✅ |
|
|
106
|
+
* | 抖音 | 直连 `tt.showModal` | ✅ |
|
|
107
|
+
*/
|
|
108
|
+
showModal: WeapiCrossPlatformAdapter['showModal'];
|
|
109
|
+
/**
|
|
110
|
+
* 选择图片。
|
|
111
|
+
*
|
|
112
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
113
|
+
* | --- | --- | --- |
|
|
114
|
+
* | 微信 | 直连 `wx.chooseImage` | ✅ |
|
|
115
|
+
* | 支付宝 | 返回值 `apFilePaths` 映射到 `tempFilePaths` | ✅ |
|
|
116
|
+
* | 抖音 | `tempFilePaths` 字符串转数组,缺失时从 `tempFiles.path` 兜底 | ✅ |
|
|
117
|
+
*/
|
|
118
|
+
chooseImage: WeapiCrossPlatformAdapter['chooseImage'];
|
|
119
|
+
/**
|
|
120
|
+
* 保存文件。
|
|
121
|
+
*
|
|
122
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
123
|
+
* | --- | --- | --- |
|
|
124
|
+
* | 微信 | 直连 `wx.saveFile` | ✅ |
|
|
125
|
+
* | 支付宝 | 请求参数 `tempFilePath` ↔ `apFilePath`、结果映射为 `savedFilePath` | ✅ |
|
|
126
|
+
* | 抖音 | 直连 `tt.saveFile`,并在缺失时用 `filePath` 兜底 `savedFilePath` | ✅ |
|
|
127
|
+
*/
|
|
128
|
+
saveFile: WeapiCrossPlatformAdapter['saveFile'];
|
|
129
|
+
/**
|
|
130
|
+
* 设置剪贴板内容。
|
|
131
|
+
*
|
|
132
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
133
|
+
* | --- | --- | --- |
|
|
134
|
+
* | 微信 | 直连 `wx.setClipboardData` | ✅ |
|
|
135
|
+
* | 支付宝 | 转调 `my.setClipboard` 并映射 `data` → `text` | ✅ |
|
|
136
|
+
* | 抖音 | 直连 `tt.setClipboardData` | ✅ |
|
|
137
|
+
*/
|
|
138
|
+
setClipboardData: WeapiCrossPlatformAdapter['setClipboardData'];
|
|
139
|
+
/**
|
|
140
|
+
* 获取剪贴板内容。
|
|
141
|
+
*
|
|
142
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
143
|
+
* | --- | --- | --- |
|
|
144
|
+
* | 微信 | 直连 `wx.getClipboardData` | ✅ |
|
|
145
|
+
* | 支付宝 | 转调 `my.getClipboard` 并映射 `text` → `data` | ✅ |
|
|
146
|
+
* | 抖音 | 直连 `tt.getClipboardData` | ✅ |
|
|
147
|
+
*/
|
|
148
|
+
getClipboardData: WeapiCrossPlatformAdapter['getClipboardData'];
|
|
149
|
+
}
|
|
150
|
+
type WeapiMethodDocOverlay<TAdapter extends WeapiAdapter> = TAdapter extends WeapiCrossPlatformRawAdapter ? WeapiCrossPlatformMethodDocs : object;
|
|
151
|
+
interface CreateWeapiOptions<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter> {
|
|
152
|
+
/**
|
|
153
|
+
* @description 手动指定平台适配器(优先级高于自动探测)
|
|
154
|
+
*/
|
|
155
|
+
adapter?: TAdapter;
|
|
156
|
+
/**
|
|
157
|
+
* @description 手动指定平台名称
|
|
158
|
+
*/
|
|
159
|
+
platform?: string;
|
|
160
|
+
}
|
|
161
|
+
type WeapiInstance<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter> = WeapiPromisify<TAdapter> & TAdapter & WeapiMethodDocOverlay<TAdapter> & {
|
|
162
|
+
/**
|
|
163
|
+
* @description 当前平台标识
|
|
164
|
+
*/
|
|
165
|
+
readonly platform?: string;
|
|
166
|
+
/**
|
|
167
|
+
* @description 获取当前适配器实例
|
|
168
|
+
*/
|
|
169
|
+
getAdapter: () => TAdapter | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* @description 手动替换平台适配器
|
|
172
|
+
*/
|
|
173
|
+
setAdapter: (adapter?: TAdapter, platform?: string) => void;
|
|
174
|
+
/**
|
|
175
|
+
* @description 获取原始平台对象
|
|
176
|
+
*/
|
|
177
|
+
readonly raw?: TAdapter;
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/core/createWeapi.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* @description 创建跨平台 API 实例
|
|
183
|
+
*/
|
|
184
|
+
declare function createWeapi<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter>(options?: CreateWeapiOptions<TAdapter>): WeapiInstance<TAdapter>;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/index.d.ts
|
|
6
187
|
/**
|
|
7
|
-
* @description
|
|
188
|
+
* @description 默认跨平台 API 实例(推荐使用)
|
|
189
|
+
*
|
|
190
|
+
* @generated weapi-platform-matrix:start
|
|
191
|
+
* | 平台 | 类型来源 | 支持度 |
|
|
192
|
+
* | --- | --- | --- |
|
|
193
|
+
* | 微信小程序 (`wx`) | `miniprogram-api-typings` | ✅ 全量 |
|
|
194
|
+
* | 支付宝小程序 (`my`) | `@mini-types/alipay` | ✅ 全量 |
|
|
195
|
+
* | 抖音小程序 (`tt`) | `@douyin-microapp/typings` | ✅ 全量 |
|
|
196
|
+
* | 其他平台对象 (`swan/jd/xhs/...`) | 运行时对象透传 | ⚠️ 按宿主能力支持 |
|
|
197
|
+
* @generated weapi-platform-matrix:end
|
|
8
198
|
*/
|
|
9
|
-
declare const
|
|
199
|
+
declare const wpi: WeapiInstance<WeapiCrossPlatformRawAdapter>;
|
|
10
200
|
//#endregion
|
|
11
|
-
export {
|
|
201
|
+
export { type CreateWeapiOptions, type WeapiAdapter, type WeapiAlipayAdapter, type WeapiAlipayRawAdapter, type WeapiCrossPlatformAdapter, type WeapiCrossPlatformRawAdapter, type WeapiDouyinAdapter, type WeapiDouyinRawAdapter, type WeapiInstance, type WeapiPromisify, type WeapiWxAdapter, type WeapiWxRawAdapter, createWeapi, wpi };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,201 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/core/types.d.ts
|
|
2
|
+
type WeapiAdapter = Record<string, any>;
|
|
3
|
+
/**
|
|
4
|
+
* @description 微信小程序 API 原始适配器类型
|
|
5
|
+
*/
|
|
6
|
+
type WeapiWxRawAdapter = WechatMiniprogram.Wx;
|
|
7
|
+
/**
|
|
8
|
+
* @description 支付宝小程序 API 原始适配器类型
|
|
9
|
+
*/
|
|
10
|
+
type WeapiAlipayRawAdapter = typeof my;
|
|
11
|
+
/**
|
|
12
|
+
* @description 抖音小程序 API 原始适配器类型
|
|
13
|
+
*/
|
|
14
|
+
type WeapiDouyinRawAdapter = typeof tt;
|
|
15
|
+
type MergeAdapters<Primary extends WeapiAdapter, Secondary extends WeapiAdapter> = Primary & Omit<Secondary, keyof Primary>;
|
|
16
|
+
/**
|
|
17
|
+
* @description weapi 对齐后的跨平台原始 API 类型
|
|
18
|
+
*
|
|
19
|
+
* @generated weapi-platform-matrix:start
|
|
20
|
+
* | 平台 | 全局对象 | 类型来源 | 对齐状态 |
|
|
21
|
+
* | --- | --- | --- | --- |
|
|
22
|
+
* | 微信小程序 | `wx` | `miniprogram-api-typings` | ✅ 全量 |
|
|
23
|
+
* | 支付宝小程序 | `my` | `@mini-types/alipay` | ✅ 全量 |
|
|
24
|
+
* | 抖音小程序 | `tt` | `@douyin-microapp/typings` | ✅ 全量 |
|
|
25
|
+
* | 其他平台(swan/jd/xhs 等) | 运行时宿主对象 | 运行时透传 | ⚠️ 按宿主能力支持 |
|
|
26
|
+
* @generated weapi-platform-matrix:end
|
|
27
|
+
*/
|
|
28
|
+
type WeapiCrossPlatformRawAdapter = MergeAdapters<MergeAdapters<WeapiWxRawAdapter, WeapiAlipayRawAdapter>, WeapiDouyinRawAdapter>;
|
|
29
|
+
type HasCallbackKey<T> = T extends object ? 'success' extends keyof T ? true : 'fail' extends keyof T ? true : 'complete' extends keyof T ? true : false : false;
|
|
30
|
+
type HasCallbackOption<T> = T extends {
|
|
31
|
+
success: unknown;
|
|
32
|
+
} ? true : T extends {
|
|
33
|
+
fail: unknown;
|
|
34
|
+
} ? true : T extends {
|
|
35
|
+
complete: unknown;
|
|
36
|
+
} ? true : false;
|
|
37
|
+
type ExtractSuccessResult<T> = T extends {
|
|
38
|
+
success?: (...args: infer A) => unknown;
|
|
39
|
+
} ? A[0] : void;
|
|
40
|
+
type PromisifyOptionMethod<Prefix extends any[], Option extends object, Result, IsOptional extends boolean> = IsOptional extends true ? {
|
|
41
|
+
<TOption extends Option>(...args: [...Prefix, TOption]): HasCallbackOption<TOption> extends true ? Result : Promise<ExtractSuccessResult<Option>>;
|
|
42
|
+
(...args: Prefix): Promise<ExtractSuccessResult<Option>>;
|
|
43
|
+
} : {
|
|
44
|
+
<TOption extends Option>(...args: [...Prefix, TOption]): HasCallbackOption<TOption> extends true ? Result : Promise<ExtractSuccessResult<Option>>;
|
|
45
|
+
};
|
|
46
|
+
type NormalizePromisifyReturn<T> = T extends Promise<any> ? T : Promise<T>;
|
|
47
|
+
type PromisifyMethod<TMethod> = TMethod extends ((...args: infer Args) => infer Result) ? Args extends [] ? (...args: Args) => NormalizePromisifyReturn<Result> : Args extends [...infer Prefix, infer Last] ? true extends HasCallbackKey<NonNullable<Last>> ? PromisifyOptionMethod<Prefix, NonNullable<Last>, Result, undefined extends Last ? true : false> : (...args: Args) => NormalizePromisifyReturn<Result> : (...args: Args) => NormalizePromisifyReturn<Result> : TMethod;
|
|
48
|
+
type WeapiPromisify<TAdapter extends WeapiAdapter> = { [Key in keyof TAdapter]: Key extends string ? Key extends `${string}Sync` ? TAdapter[Key] : Key extends `on${Capitalize<string>}` | `off${Capitalize<string>}` ? TAdapter[Key] : PromisifyMethod<TAdapter[Key]> : TAdapter[Key] };
|
|
49
|
+
/**
|
|
50
|
+
* @description 微信小程序 API 适配器类型
|
|
51
|
+
*/
|
|
52
|
+
type WeapiWxAdapter = WeapiPromisify<WeapiWxRawAdapter>;
|
|
2
53
|
/**
|
|
3
|
-
* @description
|
|
54
|
+
* @description 支付宝小程序 API 适配器类型
|
|
4
55
|
*/
|
|
5
|
-
|
|
56
|
+
type WeapiAlipayAdapter = WeapiPromisify<WeapiAlipayRawAdapter>;
|
|
57
|
+
/**
|
|
58
|
+
* @description 抖音小程序 API 适配器类型
|
|
59
|
+
*/
|
|
60
|
+
type WeapiDouyinAdapter = WeapiPromisify<WeapiDouyinRawAdapter>;
|
|
61
|
+
/**
|
|
62
|
+
* @description weapi 默认导出的跨平台 API 适配器类型
|
|
63
|
+
*/
|
|
64
|
+
type WeapiCrossPlatformAdapter = WeapiPromisify<WeapiCrossPlatformRawAdapter>;
|
|
65
|
+
/**
|
|
66
|
+
* @description weapi 核心映射 API 的平台支持度说明
|
|
67
|
+
*/
|
|
68
|
+
interface WeapiCrossPlatformMethodDocs {
|
|
69
|
+
/**
|
|
70
|
+
* 显示消息提示框。
|
|
71
|
+
*
|
|
72
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
73
|
+
* | --- | --- | --- |
|
|
74
|
+
* | 微信 | 直连 `wx.showToast` | ✅ |
|
|
75
|
+
* | 支付宝 | `title/icon` 映射到 `content/type` 后调用 `my.showToast` | ✅ |
|
|
76
|
+
* | 抖音 | `icon=error` 映射为 `fail` 后调用 `tt.showToast` | ✅ |
|
|
77
|
+
*/
|
|
78
|
+
showToast: WeapiCrossPlatformAdapter['showToast'];
|
|
79
|
+
/**
|
|
80
|
+
* 显示 loading 提示框。
|
|
81
|
+
*
|
|
82
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
83
|
+
* | --- | --- | --- |
|
|
84
|
+
* | 微信 | 直连 `wx.showLoading` | ✅ |
|
|
85
|
+
* | 支付宝 | `title` 映射到 `content` 后调用 `my.showLoading` | ✅ |
|
|
86
|
+
* | 抖音 | 直连 `tt.showLoading` | ✅ |
|
|
87
|
+
*/
|
|
88
|
+
showLoading: WeapiCrossPlatformAdapter['showLoading'];
|
|
89
|
+
/**
|
|
90
|
+
* 显示操作菜单。
|
|
91
|
+
*
|
|
92
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
93
|
+
* | --- | --- | --- |
|
|
94
|
+
* | 微信 | 直连 `wx.showActionSheet` | ✅ |
|
|
95
|
+
* | 支付宝 | `itemList` ↔ `items`、`index` ↔ `tapIndex` 双向对齐 | ✅ |
|
|
96
|
+
* | 抖音 | 直连 `tt.showActionSheet`,并兼容 `index` → `tapIndex` | ✅ |
|
|
97
|
+
*/
|
|
98
|
+
showActionSheet: WeapiCrossPlatformAdapter['showActionSheet'];
|
|
99
|
+
/**
|
|
100
|
+
* 显示模态弹窗。
|
|
101
|
+
*
|
|
102
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
103
|
+
* | --- | --- | --- |
|
|
104
|
+
* | 微信 | 直连 `wx.showModal` | ✅ |
|
|
105
|
+
* | 支付宝 | 调用 `my.confirm` 并对齐按钮字段与 `cancel` 结果 | ✅ |
|
|
106
|
+
* | 抖音 | 直连 `tt.showModal` | ✅ |
|
|
107
|
+
*/
|
|
108
|
+
showModal: WeapiCrossPlatformAdapter['showModal'];
|
|
109
|
+
/**
|
|
110
|
+
* 选择图片。
|
|
111
|
+
*
|
|
112
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
113
|
+
* | --- | --- | --- |
|
|
114
|
+
* | 微信 | 直连 `wx.chooseImage` | ✅ |
|
|
115
|
+
* | 支付宝 | 返回值 `apFilePaths` 映射到 `tempFilePaths` | ✅ |
|
|
116
|
+
* | 抖音 | `tempFilePaths` 字符串转数组,缺失时从 `tempFiles.path` 兜底 | ✅ |
|
|
117
|
+
*/
|
|
118
|
+
chooseImage: WeapiCrossPlatformAdapter['chooseImage'];
|
|
119
|
+
/**
|
|
120
|
+
* 保存文件。
|
|
121
|
+
*
|
|
122
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
123
|
+
* | --- | --- | --- |
|
|
124
|
+
* | 微信 | 直连 `wx.saveFile` | ✅ |
|
|
125
|
+
* | 支付宝 | 请求参数 `tempFilePath` ↔ `apFilePath`、结果映射为 `savedFilePath` | ✅ |
|
|
126
|
+
* | 抖音 | 直连 `tt.saveFile`,并在缺失时用 `filePath` 兜底 `savedFilePath` | ✅ |
|
|
127
|
+
*/
|
|
128
|
+
saveFile: WeapiCrossPlatformAdapter['saveFile'];
|
|
129
|
+
/**
|
|
130
|
+
* 设置剪贴板内容。
|
|
131
|
+
*
|
|
132
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
133
|
+
* | --- | --- | --- |
|
|
134
|
+
* | 微信 | 直连 `wx.setClipboardData` | ✅ |
|
|
135
|
+
* | 支付宝 | 转调 `my.setClipboard` 并映射 `data` → `text` | ✅ |
|
|
136
|
+
* | 抖音 | 直连 `tt.setClipboardData` | ✅ |
|
|
137
|
+
*/
|
|
138
|
+
setClipboardData: WeapiCrossPlatformAdapter['setClipboardData'];
|
|
139
|
+
/**
|
|
140
|
+
* 获取剪贴板内容。
|
|
141
|
+
*
|
|
142
|
+
* | 平台 | 对齐策略 | 支持度 |
|
|
143
|
+
* | --- | --- | --- |
|
|
144
|
+
* | 微信 | 直连 `wx.getClipboardData` | ✅ |
|
|
145
|
+
* | 支付宝 | 转调 `my.getClipboard` 并映射 `text` → `data` | ✅ |
|
|
146
|
+
* | 抖音 | 直连 `tt.getClipboardData` | ✅ |
|
|
147
|
+
*/
|
|
148
|
+
getClipboardData: WeapiCrossPlatformAdapter['getClipboardData'];
|
|
149
|
+
}
|
|
150
|
+
type WeapiMethodDocOverlay<TAdapter extends WeapiAdapter> = TAdapter extends WeapiCrossPlatformRawAdapter ? WeapiCrossPlatformMethodDocs : object;
|
|
151
|
+
interface CreateWeapiOptions<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter> {
|
|
152
|
+
/**
|
|
153
|
+
* @description 手动指定平台适配器(优先级高于自动探测)
|
|
154
|
+
*/
|
|
155
|
+
adapter?: TAdapter;
|
|
156
|
+
/**
|
|
157
|
+
* @description 手动指定平台名称
|
|
158
|
+
*/
|
|
159
|
+
platform?: string;
|
|
160
|
+
}
|
|
161
|
+
type WeapiInstance<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter> = WeapiPromisify<TAdapter> & TAdapter & WeapiMethodDocOverlay<TAdapter> & {
|
|
162
|
+
/**
|
|
163
|
+
* @description 当前平台标识
|
|
164
|
+
*/
|
|
165
|
+
readonly platform?: string;
|
|
166
|
+
/**
|
|
167
|
+
* @description 获取当前适配器实例
|
|
168
|
+
*/
|
|
169
|
+
getAdapter: () => TAdapter | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* @description 手动替换平台适配器
|
|
172
|
+
*/
|
|
173
|
+
setAdapter: (adapter?: TAdapter, platform?: string) => void;
|
|
174
|
+
/**
|
|
175
|
+
* @description 获取原始平台对象
|
|
176
|
+
*/
|
|
177
|
+
readonly raw?: TAdapter;
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/core/createWeapi.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* @description 创建跨平台 API 实例
|
|
183
|
+
*/
|
|
184
|
+
declare function createWeapi<TAdapter extends WeapiAdapter = WeapiCrossPlatformRawAdapter>(options?: CreateWeapiOptions<TAdapter>): WeapiInstance<TAdapter>;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/index.d.ts
|
|
6
187
|
/**
|
|
7
|
-
* @description
|
|
188
|
+
* @description 默认跨平台 API 实例(推荐使用)
|
|
189
|
+
*
|
|
190
|
+
* @generated weapi-platform-matrix:start
|
|
191
|
+
* | 平台 | 类型来源 | 支持度 |
|
|
192
|
+
* | --- | --- | --- |
|
|
193
|
+
* | 微信小程序 (`wx`) | `miniprogram-api-typings` | ✅ 全量 |
|
|
194
|
+
* | 支付宝小程序 (`my`) | `@mini-types/alipay` | ✅ 全量 |
|
|
195
|
+
* | 抖音小程序 (`tt`) | `@douyin-microapp/typings` | ✅ 全量 |
|
|
196
|
+
* | 其他平台对象 (`swan/jd/xhs/...`) | 运行时对象透传 | ⚠️ 按宿主能力支持 |
|
|
197
|
+
* @generated weapi-platform-matrix:end
|
|
8
198
|
*/
|
|
9
|
-
declare const
|
|
199
|
+
declare const wpi: WeapiInstance<WeapiCrossPlatformRawAdapter>;
|
|
10
200
|
//#endregion
|
|
11
|
-
export {
|
|
201
|
+
export { type CreateWeapiOptions, type WeapiAdapter, type WeapiAlipayAdapter, type WeapiAlipayRawAdapter, type WeapiCrossPlatformAdapter, type WeapiCrossPlatformRawAdapter, type WeapiDouyinAdapter, type WeapiDouyinRawAdapter, type WeapiInstance, type WeapiPromisify, type WeapiWxAdapter, type WeapiWxRawAdapter, createWeapi, wpi };
|