@ayden-fc2/riffle-bridge-web 1.0.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/README.md +264 -0
- package/dist/index.d.mts +719 -0
- package/dist/index.d.ts +719 -0
- package/dist/index.js +942 -0
- package/dist/index.mjs +899 -0
- package/package.json +47 -0
- package/src/bridge.ts +157 -0
- package/src/controllers/index.ts +527 -0
- package/src/core.ts +236 -0
- package/src/index.ts +94 -0
- package/src/tweaks.ts +383 -0
- package/src/types.ts +295 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Riffle Bridge 核心通信模块
|
|
5
|
+
*
|
|
6
|
+
* 处理 WebView 与 Native 之间的消息收发
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Bridge 核心类 - 处理消息收发
|
|
10
|
+
*/
|
|
11
|
+
declare class BridgeCore {
|
|
12
|
+
private messageId;
|
|
13
|
+
private initialized;
|
|
14
|
+
private sensorHandlers;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* 初始化 Bridge
|
|
18
|
+
*/
|
|
19
|
+
private init;
|
|
20
|
+
/**
|
|
21
|
+
* 检查是否在 React Native WebView 环境中
|
|
22
|
+
*/
|
|
23
|
+
isAvailable(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* 等待 Bridge 就绪
|
|
26
|
+
*/
|
|
27
|
+
waitForReady(timeout?: number): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* 确保在 React Native WebView 环境中运行
|
|
30
|
+
* @throws Error 如果不在 RN WebView 环境中
|
|
31
|
+
*/
|
|
32
|
+
private ensureAvailable;
|
|
33
|
+
/**
|
|
34
|
+
* 发送消息到 Native
|
|
35
|
+
* @throws Error 如果不在 RN WebView 环境中
|
|
36
|
+
*/
|
|
37
|
+
send<T = unknown>(module: string, method: string, params?: Record<string, unknown>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 处理 Native 响应
|
|
40
|
+
*/
|
|
41
|
+
private handleResponse;
|
|
42
|
+
/**
|
|
43
|
+
* 处理传感器数据
|
|
44
|
+
*/
|
|
45
|
+
private handleSensorData;
|
|
46
|
+
/**
|
|
47
|
+
* 订阅传感器数据
|
|
48
|
+
*/
|
|
49
|
+
onSensorData(sensor: string, callback: (data: unknown[]) => void): () => void;
|
|
50
|
+
/**
|
|
51
|
+
* 清除所有传感器订阅
|
|
52
|
+
*/
|
|
53
|
+
clearSensorSubscriptions(): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 获取 BridgeCore 单例
|
|
57
|
+
*/
|
|
58
|
+
declare function getBridgeCore(): BridgeCore;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Riffle Bridge Web SDK 类型定义
|
|
62
|
+
*/
|
|
63
|
+
type HapticFeedbackType = 'light' | 'medium' | 'heavy' | 'selection' | 'success' | 'warning' | 'error';
|
|
64
|
+
type SensorType = 'accelerometer' | 'gyroscope' | 'magnetometer' | 'barometer';
|
|
65
|
+
type CameraFacing = 'front' | 'back';
|
|
66
|
+
type CameraFilter = 'none' | 'grayscale' | 'sepia' | 'invert' | Record<string, unknown>;
|
|
67
|
+
type TiltDirection = 'forward' | 'backward' | 'left' | 'right' | 'center';
|
|
68
|
+
type ShakeIntensity = 'none' | 'light' | 'medium' | 'strong';
|
|
69
|
+
interface SensorData {
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
z: number;
|
|
73
|
+
timestamp?: number;
|
|
74
|
+
}
|
|
75
|
+
interface BarometerData {
|
|
76
|
+
pressure: number;
|
|
77
|
+
relativeAltitude?: number;
|
|
78
|
+
timestamp?: number;
|
|
79
|
+
}
|
|
80
|
+
interface VolumeData {
|
|
81
|
+
metering: number;
|
|
82
|
+
normalizedVolume: number;
|
|
83
|
+
durationMillis: number;
|
|
84
|
+
timestamp?: number;
|
|
85
|
+
}
|
|
86
|
+
interface AudioStatus {
|
|
87
|
+
isLoaded: boolean;
|
|
88
|
+
isPlaying: boolean;
|
|
89
|
+
volume: number;
|
|
90
|
+
rate: number;
|
|
91
|
+
}
|
|
92
|
+
interface DeviceInfo {
|
|
93
|
+
brand: string | null;
|
|
94
|
+
manufacturer: string | null;
|
|
95
|
+
modelName: string | null;
|
|
96
|
+
modelId: string | null;
|
|
97
|
+
designName: string | null;
|
|
98
|
+
productName: string | null;
|
|
99
|
+
deviceYearClass: number | null;
|
|
100
|
+
totalMemory: number | null;
|
|
101
|
+
supportedCpuArchitectures: string[] | null;
|
|
102
|
+
deviceType: number | null;
|
|
103
|
+
isDevice: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface BatteryInfo {
|
|
106
|
+
level: number;
|
|
107
|
+
state: number;
|
|
108
|
+
isLowPowerMode: boolean;
|
|
109
|
+
lowPowerModeSupported: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface NetworkInfo {
|
|
112
|
+
isConnected: boolean;
|
|
113
|
+
isInternetReachable: boolean | null;
|
|
114
|
+
type: string;
|
|
115
|
+
ipAddress: string | null;
|
|
116
|
+
isAirplaneMode: boolean | null;
|
|
117
|
+
}
|
|
118
|
+
interface SystemInfo {
|
|
119
|
+
osName: string | null;
|
|
120
|
+
osVersion: string | null;
|
|
121
|
+
osBuildId: string | null;
|
|
122
|
+
osInternalBuildId: string | null;
|
|
123
|
+
platformApiLevel: number | null;
|
|
124
|
+
platform: string;
|
|
125
|
+
platformVersion: string | number;
|
|
126
|
+
expoVersion: string | null;
|
|
127
|
+
expoRuntimeVersion: string | null;
|
|
128
|
+
sdkVersion: string | null;
|
|
129
|
+
appOwnership: string | null;
|
|
130
|
+
executionEnvironment: string;
|
|
131
|
+
locale: string;
|
|
132
|
+
locales: string[];
|
|
133
|
+
timezone: string;
|
|
134
|
+
isRTL: boolean;
|
|
135
|
+
region: string;
|
|
136
|
+
}
|
|
137
|
+
interface AppInfo {
|
|
138
|
+
appName: string | null;
|
|
139
|
+
appId: string | null;
|
|
140
|
+
nativeAppVersion: string | null;
|
|
141
|
+
nativeBuildVersion: string | null;
|
|
142
|
+
}
|
|
143
|
+
interface ScreenInfo {
|
|
144
|
+
screenWidth: number;
|
|
145
|
+
screenHeight: number;
|
|
146
|
+
pixelRatio: number;
|
|
147
|
+
fontScale: number;
|
|
148
|
+
}
|
|
149
|
+
interface StorageStats {
|
|
150
|
+
totalFiles: number;
|
|
151
|
+
totalSize: number;
|
|
152
|
+
totalSizeFormatted: string;
|
|
153
|
+
subfolders: Record<string, {
|
|
154
|
+
files: number;
|
|
155
|
+
size: number;
|
|
156
|
+
}>;
|
|
157
|
+
}
|
|
158
|
+
interface FileInfo {
|
|
159
|
+
filename: string;
|
|
160
|
+
uri: string;
|
|
161
|
+
size: number;
|
|
162
|
+
sizeFormatted: string;
|
|
163
|
+
width?: number;
|
|
164
|
+
height?: number;
|
|
165
|
+
cancelled?: boolean;
|
|
166
|
+
}
|
|
167
|
+
interface CachedFileInfo {
|
|
168
|
+
exists: boolean;
|
|
169
|
+
uri?: string;
|
|
170
|
+
size?: number;
|
|
171
|
+
sizeFormatted?: string;
|
|
172
|
+
}
|
|
173
|
+
interface DownloadResult {
|
|
174
|
+
cached: boolean;
|
|
175
|
+
uri: string;
|
|
176
|
+
size?: number;
|
|
177
|
+
sizeFormatted?: string;
|
|
178
|
+
}
|
|
179
|
+
interface Base64Result {
|
|
180
|
+
base64: string;
|
|
181
|
+
mimeType: string;
|
|
182
|
+
dataUrl: string;
|
|
183
|
+
}
|
|
184
|
+
interface PhotoResult {
|
|
185
|
+
cancelled: boolean;
|
|
186
|
+
filename?: string;
|
|
187
|
+
uri?: string;
|
|
188
|
+
size?: number;
|
|
189
|
+
sizeFormatted?: string;
|
|
190
|
+
width?: number;
|
|
191
|
+
height?: number;
|
|
192
|
+
facing?: CameraFacing;
|
|
193
|
+
}
|
|
194
|
+
interface RecordingResult {
|
|
195
|
+
isRecording: boolean;
|
|
196
|
+
uri?: string;
|
|
197
|
+
durationMillis?: number;
|
|
198
|
+
}
|
|
199
|
+
interface PermissionResult {
|
|
200
|
+
granted: boolean;
|
|
201
|
+
canAskAgain: boolean;
|
|
202
|
+
status: string;
|
|
203
|
+
}
|
|
204
|
+
type TweakType = 'color' | 'number' | 'boolean' | 'string' | 'select';
|
|
205
|
+
interface SelectOption {
|
|
206
|
+
label: string;
|
|
207
|
+
value: string;
|
|
208
|
+
}
|
|
209
|
+
interface TweakConfigBase {
|
|
210
|
+
name: string;
|
|
211
|
+
type: TweakType;
|
|
212
|
+
group?: string;
|
|
213
|
+
description?: string;
|
|
214
|
+
}
|
|
215
|
+
interface ColorTweakConfig extends TweakConfigBase {
|
|
216
|
+
type: 'color';
|
|
217
|
+
value: string;
|
|
218
|
+
}
|
|
219
|
+
interface NumberTweakConfig extends TweakConfigBase {
|
|
220
|
+
type: 'number';
|
|
221
|
+
value: number;
|
|
222
|
+
min?: number;
|
|
223
|
+
max?: number;
|
|
224
|
+
step?: number;
|
|
225
|
+
}
|
|
226
|
+
interface BooleanTweakConfig extends TweakConfigBase {
|
|
227
|
+
type: 'boolean';
|
|
228
|
+
value: boolean;
|
|
229
|
+
}
|
|
230
|
+
interface StringTweakConfig extends TweakConfigBase {
|
|
231
|
+
type: 'string';
|
|
232
|
+
value: string;
|
|
233
|
+
}
|
|
234
|
+
interface SelectTweakConfig extends TweakConfigBase {
|
|
235
|
+
type: 'select';
|
|
236
|
+
value: string;
|
|
237
|
+
options: (string | SelectOption)[];
|
|
238
|
+
}
|
|
239
|
+
type TweakConfig = ColorTweakConfig | NumberTweakConfig | BooleanTweakConfig | StringTweakConfig | SelectTweakConfig;
|
|
240
|
+
type TweaksConfig = Record<string, TweakConfig>;
|
|
241
|
+
interface BridgeMessage {
|
|
242
|
+
id: string;
|
|
243
|
+
module: string;
|
|
244
|
+
method: string;
|
|
245
|
+
params: Record<string, unknown>;
|
|
246
|
+
timestamp: number;
|
|
247
|
+
}
|
|
248
|
+
interface BridgeResponse {
|
|
249
|
+
id: string;
|
|
250
|
+
module: string;
|
|
251
|
+
method: string;
|
|
252
|
+
success: boolean;
|
|
253
|
+
error: string | null;
|
|
254
|
+
data: unknown;
|
|
255
|
+
timestamp: number;
|
|
256
|
+
}
|
|
257
|
+
declare global {
|
|
258
|
+
interface Window {
|
|
259
|
+
ReactNativeWebView?: {
|
|
260
|
+
postMessage: (message: string) => void;
|
|
261
|
+
};
|
|
262
|
+
__RIFFLE_CALLBACKS__?: Map<string, (response: BridgeResponse) => void>;
|
|
263
|
+
__RIFFLE_READY__?: boolean;
|
|
264
|
+
__RIFFLE_SENSOR_HANDLERS__?: Map<string, Set<(data: unknown[]) => void>>;
|
|
265
|
+
handleNativeResponse?: (responseStr: string) => void;
|
|
266
|
+
handleSensorData?: (data: {
|
|
267
|
+
sensor: string;
|
|
268
|
+
values: unknown[];
|
|
269
|
+
}) => void;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Riffle Bridge 控制器模块
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
declare class HapticController {
|
|
278
|
+
private core;
|
|
279
|
+
constructor(core: BridgeCore);
|
|
280
|
+
light(): Promise<void>;
|
|
281
|
+
medium(): Promise<void>;
|
|
282
|
+
heavy(): Promise<void>;
|
|
283
|
+
success(): Promise<void>;
|
|
284
|
+
warning(): Promise<void>;
|
|
285
|
+
error(): Promise<void>;
|
|
286
|
+
selection(): Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* 播放震动序列
|
|
289
|
+
*/
|
|
290
|
+
sequence(types: HapticFeedbackType[], interval?: number): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* 根据强度震动
|
|
293
|
+
*/
|
|
294
|
+
intensity(level: number): Promise<void>;
|
|
295
|
+
}
|
|
296
|
+
interface SensorStartOptions {
|
|
297
|
+
types?: SensorType[];
|
|
298
|
+
interval?: number;
|
|
299
|
+
}
|
|
300
|
+
declare class SensorController {
|
|
301
|
+
private core;
|
|
302
|
+
private isActive;
|
|
303
|
+
private activeTypes;
|
|
304
|
+
constructor(core: BridgeCore);
|
|
305
|
+
/**
|
|
306
|
+
* 启动传感器
|
|
307
|
+
*/
|
|
308
|
+
start(options?: SensorStartOptions): Promise<{
|
|
309
|
+
started: SensorType[];
|
|
310
|
+
updateInterval: number;
|
|
311
|
+
}>;
|
|
312
|
+
/**
|
|
313
|
+
* 停止传感器
|
|
314
|
+
*/
|
|
315
|
+
stop(): Promise<{
|
|
316
|
+
stopped: boolean;
|
|
317
|
+
}>;
|
|
318
|
+
/**
|
|
319
|
+
* 监听加速度计数据
|
|
320
|
+
*/
|
|
321
|
+
onAccelerometer(callback: (data: SensorData[]) => void): () => void;
|
|
322
|
+
/**
|
|
323
|
+
* 监听陀螺仪数据
|
|
324
|
+
*/
|
|
325
|
+
onGyroscope(callback: (data: SensorData[]) => void): () => void;
|
|
326
|
+
/**
|
|
327
|
+
* 监听磁力计数据
|
|
328
|
+
*/
|
|
329
|
+
onMagnetometer(callback: (data: SensorData[]) => void): () => void;
|
|
330
|
+
/**
|
|
331
|
+
* 监听气压计数据
|
|
332
|
+
*/
|
|
333
|
+
onBarometer(callback: (data: BarometerData[]) => void): () => void;
|
|
334
|
+
/**
|
|
335
|
+
* 获取当前状态
|
|
336
|
+
*/
|
|
337
|
+
getStatus(): {
|
|
338
|
+
isActive: boolean;
|
|
339
|
+
activeTypes: SensorType[];
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
declare class DeviceController {
|
|
343
|
+
private core;
|
|
344
|
+
constructor(core: BridgeCore);
|
|
345
|
+
getDeviceInfo(): Promise<DeviceInfo>;
|
|
346
|
+
getBatteryInfo(): Promise<BatteryInfo>;
|
|
347
|
+
getNetworkInfo(): Promise<NetworkInfo>;
|
|
348
|
+
getSystemInfo(): Promise<SystemInfo>;
|
|
349
|
+
getAppInfo(): Promise<AppInfo>;
|
|
350
|
+
getScreenInfo(): Promise<ScreenInfo>;
|
|
351
|
+
getAllInfo(): Promise<{
|
|
352
|
+
device: Partial<DeviceInfo>;
|
|
353
|
+
battery: Partial<BatteryInfo>;
|
|
354
|
+
network: Partial<NetworkInfo>;
|
|
355
|
+
system: Partial<SystemInfo>;
|
|
356
|
+
app: Partial<AppInfo>;
|
|
357
|
+
}>;
|
|
358
|
+
}
|
|
359
|
+
declare class FileStorageController {
|
|
360
|
+
private core;
|
|
361
|
+
constructor(core: BridgeCore);
|
|
362
|
+
init(): Promise<{
|
|
363
|
+
initialized: boolean;
|
|
364
|
+
}>;
|
|
365
|
+
getStorageStats(): Promise<StorageStats>;
|
|
366
|
+
takePhoto(): Promise<FileInfo>;
|
|
367
|
+
pickFromGallery(): Promise<FileInfo>;
|
|
368
|
+
saveFile(sourceUri: string, filename: string, subfolder?: string): Promise<FileInfo>;
|
|
369
|
+
listFiles(subfolder?: string): Promise<FileInfo[]>;
|
|
370
|
+
downloadAndSave(url: string, filename: string, subfolder?: string): Promise<FileInfo>;
|
|
371
|
+
getLocalFileByUrl(url: string): Promise<CachedFileInfo>;
|
|
372
|
+
clearAppFiles(): Promise<{
|
|
373
|
+
cleared: boolean;
|
|
374
|
+
}>;
|
|
375
|
+
deleteFile(filename: string, subfolder?: string): Promise<{
|
|
376
|
+
deleted: boolean;
|
|
377
|
+
}>;
|
|
378
|
+
loadUrlMappings(): Promise<Array<{
|
|
379
|
+
url: string;
|
|
380
|
+
filename: string;
|
|
381
|
+
path: string;
|
|
382
|
+
}>>;
|
|
383
|
+
downloadWithCache(url: string, checkCache?: boolean): Promise<DownloadResult>;
|
|
384
|
+
clearUrlMappings(): Promise<{
|
|
385
|
+
cleared: boolean;
|
|
386
|
+
}>;
|
|
387
|
+
removeUrlMapping(url: string): Promise<{
|
|
388
|
+
removed: boolean;
|
|
389
|
+
}>;
|
|
390
|
+
addCustomFileMapping(customKey: string, localUri: string): Promise<{
|
|
391
|
+
added: boolean;
|
|
392
|
+
}>;
|
|
393
|
+
readAsBase64(uriOrKey: string): Promise<Base64Result>;
|
|
394
|
+
}
|
|
395
|
+
interface PlayOptions {
|
|
396
|
+
uri: string;
|
|
397
|
+
volume?: number;
|
|
398
|
+
rate?: number;
|
|
399
|
+
isLooping?: boolean;
|
|
400
|
+
}
|
|
401
|
+
declare class AudioController {
|
|
402
|
+
private core;
|
|
403
|
+
private fileStorage;
|
|
404
|
+
constructor(core: BridgeCore, fileStorage: FileStorageController);
|
|
405
|
+
/**
|
|
406
|
+
* 解析 URI,返回可播放的实际路径
|
|
407
|
+
*/
|
|
408
|
+
private resolveUri;
|
|
409
|
+
/**
|
|
410
|
+
* 播放音频(智能解析 URI)
|
|
411
|
+
*/
|
|
412
|
+
playOnline(options: PlayOptions): Promise<{
|
|
413
|
+
playing: boolean;
|
|
414
|
+
uri: string;
|
|
415
|
+
}>;
|
|
416
|
+
pause(): Promise<{
|
|
417
|
+
paused: boolean;
|
|
418
|
+
}>;
|
|
419
|
+
resume(): Promise<{
|
|
420
|
+
resumed: boolean;
|
|
421
|
+
}>;
|
|
422
|
+
stop(): Promise<{
|
|
423
|
+
stopped: boolean;
|
|
424
|
+
}>;
|
|
425
|
+
setVolume(volume: number): Promise<{
|
|
426
|
+
volume: number;
|
|
427
|
+
}>;
|
|
428
|
+
setRate(rate: number): Promise<{
|
|
429
|
+
rate: number;
|
|
430
|
+
}>;
|
|
431
|
+
getStatus(): Promise<AudioStatus>;
|
|
432
|
+
}
|
|
433
|
+
declare class CameraController {
|
|
434
|
+
private core;
|
|
435
|
+
constructor(core: BridgeCore);
|
|
436
|
+
open(options?: {
|
|
437
|
+
facing?: CameraFacing;
|
|
438
|
+
}): Promise<{
|
|
439
|
+
isOpen: boolean;
|
|
440
|
+
facing: CameraFacing;
|
|
441
|
+
}>;
|
|
442
|
+
close(): Promise<{
|
|
443
|
+
isOpen: boolean;
|
|
444
|
+
}>;
|
|
445
|
+
toggleFacing(): Promise<{
|
|
446
|
+
facing: CameraFacing;
|
|
447
|
+
}>;
|
|
448
|
+
takePhoto(): Promise<PhotoResult>;
|
|
449
|
+
setFilter(filter: CameraFilter): Promise<{
|
|
450
|
+
filter: string;
|
|
451
|
+
customStyles?: Record<string, unknown>;
|
|
452
|
+
}>;
|
|
453
|
+
setFlash(enabled: boolean): Promise<{
|
|
454
|
+
flash: boolean;
|
|
455
|
+
}>;
|
|
456
|
+
toggleFlash(): Promise<{
|
|
457
|
+
flash: boolean;
|
|
458
|
+
}>;
|
|
459
|
+
}
|
|
460
|
+
declare class MicrophoneController {
|
|
461
|
+
private core;
|
|
462
|
+
private isRecording;
|
|
463
|
+
constructor(core: BridgeCore);
|
|
464
|
+
requestPermission(): Promise<PermissionResult>;
|
|
465
|
+
start(options?: {
|
|
466
|
+
enableMonitoring?: boolean;
|
|
467
|
+
}): Promise<RecordingResult>;
|
|
468
|
+
stop(): Promise<RecordingResult>;
|
|
469
|
+
pause(): Promise<{
|
|
470
|
+
paused: boolean;
|
|
471
|
+
}>;
|
|
472
|
+
resume(): Promise<{
|
|
473
|
+
resumed: boolean;
|
|
474
|
+
}>;
|
|
475
|
+
getStatus(): Promise<{
|
|
476
|
+
isRecording: boolean;
|
|
477
|
+
isDoneRecording?: boolean;
|
|
478
|
+
durationMillis?: number;
|
|
479
|
+
canRecord: boolean;
|
|
480
|
+
}>;
|
|
481
|
+
/**
|
|
482
|
+
* 监听音量数据
|
|
483
|
+
*/
|
|
484
|
+
onVolumeData(callback: (data: VolumeData[]) => void): () => void;
|
|
485
|
+
getRecordingState(): boolean;
|
|
486
|
+
}
|
|
487
|
+
declare class ConfigController {
|
|
488
|
+
private core;
|
|
489
|
+
private currentConfig;
|
|
490
|
+
constructor(core: BridgeCore);
|
|
491
|
+
updateParams(configData: Record<string, unknown>): Promise<{
|
|
492
|
+
received: boolean;
|
|
493
|
+
configId: number;
|
|
494
|
+
dataKeys: string[];
|
|
495
|
+
message: string;
|
|
496
|
+
}>;
|
|
497
|
+
getCurrentConfig(): Record<string, unknown> | null;
|
|
498
|
+
resetToDefaults(): Promise<{
|
|
499
|
+
reset: boolean;
|
|
500
|
+
}>;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Riffle Bridge 主类
|
|
505
|
+
*
|
|
506
|
+
* 提供完整的 WebView Bridge API
|
|
507
|
+
*/
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* 工具函数类
|
|
511
|
+
*/
|
|
512
|
+
declare class Utils {
|
|
513
|
+
/**
|
|
514
|
+
* 计算向量模长
|
|
515
|
+
*/
|
|
516
|
+
static magnitude(x: number, y: number, z: number): number;
|
|
517
|
+
/**
|
|
518
|
+
* 获取倾斜方向
|
|
519
|
+
*/
|
|
520
|
+
static getTiltDirection(x: number, y: number, threshold?: number): TiltDirection;
|
|
521
|
+
/**
|
|
522
|
+
* 获取摇晃强度
|
|
523
|
+
*/
|
|
524
|
+
static getShakeIntensity(x: number, y: number, z: number): ShakeIntensity;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* RiffleBridge 主类
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* import { RiffleBridge } from '@riffle/bridge-web';
|
|
532
|
+
*
|
|
533
|
+
* const bridge = new RiffleBridge();
|
|
534
|
+
*
|
|
535
|
+
* // 检查是否可用
|
|
536
|
+
* if (bridge.isAvailable()) {
|
|
537
|
+
* // 震动
|
|
538
|
+
* await bridge.vibrate('success');
|
|
539
|
+
*
|
|
540
|
+
* // 使用传感器
|
|
541
|
+
* await bridge.sensor.start({ types: ['accelerometer'] });
|
|
542
|
+
* bridge.sensor.onAccelerometer((data) => {
|
|
543
|
+
* console.log(data);
|
|
544
|
+
* });
|
|
545
|
+
* }
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
declare class RiffleBridge {
|
|
549
|
+
private core;
|
|
550
|
+
/** 震动控制器 */
|
|
551
|
+
readonly haptic: HapticController;
|
|
552
|
+
/** 传感器控制器 */
|
|
553
|
+
readonly sensor: SensorController;
|
|
554
|
+
/** 设备信息控制器 */
|
|
555
|
+
readonly device: DeviceController;
|
|
556
|
+
/** 文件存储控制器 */
|
|
557
|
+
readonly fileStorage: FileStorageController;
|
|
558
|
+
/** 音频控制器 */
|
|
559
|
+
readonly audio: AudioController;
|
|
560
|
+
/** 相机控制器 */
|
|
561
|
+
readonly camera: CameraController;
|
|
562
|
+
/** 麦克风控制器 */
|
|
563
|
+
readonly microphone: MicrophoneController;
|
|
564
|
+
/** 配置控制器 */
|
|
565
|
+
readonly config: ConfigController;
|
|
566
|
+
/** 工具函数 */
|
|
567
|
+
readonly utils: typeof Utils;
|
|
568
|
+
constructor();
|
|
569
|
+
/**
|
|
570
|
+
* 检查 Bridge 是否可用
|
|
571
|
+
*/
|
|
572
|
+
isAvailable(): boolean;
|
|
573
|
+
/**
|
|
574
|
+
* 等待 Bridge 就绪
|
|
575
|
+
*/
|
|
576
|
+
waitForReady(timeout?: number): Promise<boolean>;
|
|
577
|
+
/**
|
|
578
|
+
* 获取 SDK 版本
|
|
579
|
+
*/
|
|
580
|
+
getVersion(): string;
|
|
581
|
+
/**
|
|
582
|
+
* 便捷方法:震动
|
|
583
|
+
*/
|
|
584
|
+
vibrate(type?: HapticFeedbackType): Promise<void>;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* 获取 RiffleBridge 单例
|
|
588
|
+
*/
|
|
589
|
+
declare function getRiffleBridge(): RiffleBridge;
|
|
590
|
+
|
|
591
|
+
type ReactType = typeof react;
|
|
592
|
+
/**
|
|
593
|
+
* 单个配置项的值包装器
|
|
594
|
+
*/
|
|
595
|
+
declare class TweakValue<T> {
|
|
596
|
+
private _key;
|
|
597
|
+
private _config;
|
|
598
|
+
private _value;
|
|
599
|
+
private _listeners;
|
|
600
|
+
private _syncCallback;
|
|
601
|
+
constructor(_key: string, _config: TweakConfig, syncCallback?: (() => void) | null);
|
|
602
|
+
/** 获取当前值 */
|
|
603
|
+
get value(): T;
|
|
604
|
+
/** 获取配置 */
|
|
605
|
+
get config(): TweakConfig;
|
|
606
|
+
/** 获取键名 */
|
|
607
|
+
get key(): string;
|
|
608
|
+
/**
|
|
609
|
+
* 设置值
|
|
610
|
+
* @param newValue 新值
|
|
611
|
+
* @param skipSync 是否跳过同步到 Native
|
|
612
|
+
*/
|
|
613
|
+
set(newValue: T, skipSync?: boolean): void;
|
|
614
|
+
/**
|
|
615
|
+
* 内部设置(不触发同步,用于接收 Native 更新)
|
|
616
|
+
*/
|
|
617
|
+
_setInternal(newValue: T): void;
|
|
618
|
+
/**
|
|
619
|
+
* 订阅值变化
|
|
620
|
+
*/
|
|
621
|
+
subscribe(listener: () => void): () => void;
|
|
622
|
+
/**
|
|
623
|
+
* 监听值变化
|
|
624
|
+
*/
|
|
625
|
+
onChange(callback: (value: T) => void): () => void;
|
|
626
|
+
/**
|
|
627
|
+
* React Hook: 获取响应式值
|
|
628
|
+
* 需要传入 React 实例或使用 createTweaks 时传入
|
|
629
|
+
*/
|
|
630
|
+
useState(react?: ReactType): T;
|
|
631
|
+
private _notifyListeners;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Tweaks 配置管理器
|
|
635
|
+
*/
|
|
636
|
+
declare class RiffleBridgeTweaks<T extends TweaksConfig> {
|
|
637
|
+
private _config;
|
|
638
|
+
private _tweaks;
|
|
639
|
+
private _syncDebounceTimer;
|
|
640
|
+
constructor(config: T);
|
|
641
|
+
/**
|
|
642
|
+
* 获取指定键的配置项
|
|
643
|
+
*/
|
|
644
|
+
get<K extends keyof T>(key: K): TweakValue<T[K]['value']>;
|
|
645
|
+
/**
|
|
646
|
+
* 获取所有值
|
|
647
|
+
*/
|
|
648
|
+
getData(): Record<string, unknown>;
|
|
649
|
+
/**
|
|
650
|
+
* 获取完整配置(含元数据)
|
|
651
|
+
*/
|
|
652
|
+
toJSON(): Record<string, {
|
|
653
|
+
name: string;
|
|
654
|
+
type: string;
|
|
655
|
+
value: unknown;
|
|
656
|
+
[k: string]: unknown;
|
|
657
|
+
}>;
|
|
658
|
+
/**
|
|
659
|
+
* 批量更新值
|
|
660
|
+
*/
|
|
661
|
+
update(updates: Partial<Record<keyof T, unknown>>): void;
|
|
662
|
+
/**
|
|
663
|
+
* 重置为默认值
|
|
664
|
+
*/
|
|
665
|
+
reset(): void;
|
|
666
|
+
/**
|
|
667
|
+
* 获取所有配置键名
|
|
668
|
+
*/
|
|
669
|
+
keys(): string[];
|
|
670
|
+
/**
|
|
671
|
+
* 监听任意参数变化
|
|
672
|
+
*/
|
|
673
|
+
onAnyChange(callback: (key: string, value: unknown) => void): () => void;
|
|
674
|
+
/**
|
|
675
|
+
* 设置消息监听
|
|
676
|
+
*/
|
|
677
|
+
private _setupMessageListener;
|
|
678
|
+
/**
|
|
679
|
+
* 设置全局回调函数(兼容旧版 Native 调用方式)
|
|
680
|
+
*/
|
|
681
|
+
private _setupGlobalCallbacks;
|
|
682
|
+
/**
|
|
683
|
+
* 同步配置到 Native
|
|
684
|
+
*/
|
|
685
|
+
private _syncToNative;
|
|
686
|
+
}
|
|
687
|
+
type TweaksProxy<T extends TweaksConfig> = RiffleBridgeTweaks<T> & {
|
|
688
|
+
[K in keyof T]: TweakValue<T[K]['value']>;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* 创建 Tweaks 配置实例
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```typescript
|
|
695
|
+
* import React from 'react';
|
|
696
|
+
* import { createTweaks } from '@riffle/bridge-web';
|
|
697
|
+
*
|
|
698
|
+
* const tweaks = createTweaks({
|
|
699
|
+
* color: { name: '颜色', type: 'color', value: '#667eea' },
|
|
700
|
+
* size: { name: '大小', type: 'number', value: 150, min: 50, max: 300 },
|
|
701
|
+
* enabled: { name: '启用', type: 'boolean', value: true },
|
|
702
|
+
* }, { React });
|
|
703
|
+
*
|
|
704
|
+
* function Demo() {
|
|
705
|
+
* const color = tweaks.color.useState();
|
|
706
|
+
* const size = tweaks.size.useState();
|
|
707
|
+
*
|
|
708
|
+
* return <div style={{ backgroundColor: color, width: size, height: size }} />;
|
|
709
|
+
* }
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
declare function createTweaks<T extends TweaksConfig>(config: T, options?: {
|
|
713
|
+
React?: ReactType;
|
|
714
|
+
}): TweaksProxy<T>;
|
|
715
|
+
declare function riffleBridgeTweaks<T extends TweaksConfig>(config: T, options?: {
|
|
716
|
+
React?: ReactType;
|
|
717
|
+
}): TweaksProxy<T>;
|
|
718
|
+
|
|
719
|
+
export { type AppInfo, AudioController, type AudioStatus, type BarometerData, type Base64Result, type BatteryInfo, type BooleanTweakConfig, BridgeCore, type BridgeMessage, type BridgeResponse, type CachedFileInfo, CameraController, type CameraFacing, type CameraFilter, type ColorTweakConfig, ConfigController, DeviceController, type DeviceInfo, type DownloadResult, type FileInfo, FileStorageController, HapticController, type HapticFeedbackType, MicrophoneController, type NetworkInfo, type NumberTweakConfig, type PermissionResult, type PhotoResult, type PlayOptions, type RecordingResult, RiffleBridge, RiffleBridgeTweaks, type ScreenInfo, type SelectOption, type SelectTweakConfig, SensorController, type SensorData, type SensorStartOptions, type SensorType, type ShakeIntensity, type StorageStats, type StringTweakConfig, type SystemInfo, type TiltDirection, type TweakConfig, type TweakType, TweakValue, type TweaksConfig, Utils, type VolumeData, createTweaks, getBridgeCore, getRiffleBridge, riffleBridgeTweaks };
|