@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/src/types.ts ADDED
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Riffle Bridge Web SDK 类型定义
3
+ */
4
+
5
+ // ============================================
6
+ // 基础类型
7
+ // ============================================
8
+
9
+ export type HapticFeedbackType =
10
+ | 'light'
11
+ | 'medium'
12
+ | 'heavy'
13
+ | 'selection'
14
+ | 'success'
15
+ | 'warning'
16
+ | 'error';
17
+
18
+ export type SensorType =
19
+ | 'accelerometer'
20
+ | 'gyroscope'
21
+ | 'magnetometer'
22
+ | 'barometer';
23
+
24
+ export type CameraFacing = 'front' | 'back';
25
+
26
+ export type CameraFilter =
27
+ | 'none'
28
+ | 'grayscale'
29
+ | 'sepia'
30
+ | 'invert'
31
+ | Record<string, unknown>;
32
+
33
+ export type TiltDirection =
34
+ | 'forward'
35
+ | 'backward'
36
+ | 'left'
37
+ | 'right'
38
+ | 'center';
39
+
40
+ export type ShakeIntensity =
41
+ | 'none'
42
+ | 'light'
43
+ | 'medium'
44
+ | 'strong';
45
+
46
+ // ============================================
47
+ // 数据接口
48
+ // ============================================
49
+
50
+ export interface SensorData {
51
+ x: number;
52
+ y: number;
53
+ z: number;
54
+ timestamp?: number;
55
+ }
56
+
57
+ export interface BarometerData {
58
+ pressure: number;
59
+ relativeAltitude?: number;
60
+ timestamp?: number;
61
+ }
62
+
63
+ export interface VolumeData {
64
+ metering: number;
65
+ normalizedVolume: number;
66
+ durationMillis: number;
67
+ timestamp?: number;
68
+ }
69
+
70
+ export interface AudioStatus {
71
+ isLoaded: boolean;
72
+ isPlaying: boolean;
73
+ volume: number;
74
+ rate: number;
75
+ }
76
+
77
+ export interface DeviceInfo {
78
+ brand: string | null;
79
+ manufacturer: string | null;
80
+ modelName: string | null;
81
+ modelId: string | null;
82
+ designName: string | null;
83
+ productName: string | null;
84
+ deviceYearClass: number | null;
85
+ totalMemory: number | null;
86
+ supportedCpuArchitectures: string[] | null;
87
+ deviceType: number | null;
88
+ isDevice: boolean;
89
+ }
90
+
91
+ export interface BatteryInfo {
92
+ level: number;
93
+ state: number;
94
+ isLowPowerMode: boolean;
95
+ lowPowerModeSupported: boolean;
96
+ }
97
+
98
+ export interface NetworkInfo {
99
+ isConnected: boolean;
100
+ isInternetReachable: boolean | null;
101
+ type: string;
102
+ ipAddress: string | null;
103
+ isAirplaneMode: boolean | null;
104
+ }
105
+
106
+ export interface SystemInfo {
107
+ osName: string | null;
108
+ osVersion: string | null;
109
+ osBuildId: string | null;
110
+ osInternalBuildId: string | null;
111
+ platformApiLevel: number | null;
112
+ platform: string;
113
+ platformVersion: string | number;
114
+ expoVersion: string | null;
115
+ expoRuntimeVersion: string | null;
116
+ sdkVersion: string | null;
117
+ appOwnership: string | null;
118
+ executionEnvironment: string;
119
+ locale: string;
120
+ locales: string[];
121
+ timezone: string;
122
+ isRTL: boolean;
123
+ region: string;
124
+ }
125
+
126
+ export interface AppInfo {
127
+ appName: string | null;
128
+ appId: string | null;
129
+ nativeAppVersion: string | null;
130
+ nativeBuildVersion: string | null;
131
+ }
132
+
133
+ export interface ScreenInfo {
134
+ screenWidth: number;
135
+ screenHeight: number;
136
+ pixelRatio: number;
137
+ fontScale: number;
138
+ }
139
+
140
+ export interface StorageStats {
141
+ totalFiles: number;
142
+ totalSize: number;
143
+ totalSizeFormatted: string;
144
+ subfolders: Record<string, { files: number; size: number }>;
145
+ }
146
+
147
+ export interface FileInfo {
148
+ filename: string;
149
+ uri: string;
150
+ size: number;
151
+ sizeFormatted: string;
152
+ width?: number;
153
+ height?: number;
154
+ cancelled?: boolean;
155
+ }
156
+
157
+ export interface CachedFileInfo {
158
+ exists: boolean;
159
+ uri?: string;
160
+ size?: number;
161
+ sizeFormatted?: string;
162
+ }
163
+
164
+ export interface DownloadResult {
165
+ cached: boolean;
166
+ uri: string;
167
+ size?: number;
168
+ sizeFormatted?: string;
169
+ }
170
+
171
+ export interface Base64Result {
172
+ base64: string;
173
+ mimeType: string;
174
+ dataUrl: string;
175
+ }
176
+
177
+ export interface PhotoResult {
178
+ cancelled: boolean;
179
+ filename?: string;
180
+ uri?: string;
181
+ size?: number;
182
+ sizeFormatted?: string;
183
+ width?: number;
184
+ height?: number;
185
+ facing?: CameraFacing;
186
+ }
187
+
188
+ export interface RecordingResult {
189
+ isRecording: boolean;
190
+ uri?: string;
191
+ durationMillis?: number;
192
+ }
193
+
194
+ export interface PermissionResult {
195
+ granted: boolean;
196
+ canAskAgain: boolean;
197
+ status: string;
198
+ }
199
+
200
+ // ============================================
201
+ // Tweaks 配置类型
202
+ // ============================================
203
+
204
+ export type TweakType = 'color' | 'number' | 'boolean' | 'string' | 'select';
205
+
206
+ export interface SelectOption {
207
+ label: string;
208
+ value: string;
209
+ }
210
+
211
+ export interface TweakConfigBase {
212
+ name: string;
213
+ type: TweakType;
214
+ group?: string;
215
+ description?: string;
216
+ }
217
+
218
+ export interface ColorTweakConfig extends TweakConfigBase {
219
+ type: 'color';
220
+ value: string;
221
+ }
222
+
223
+ export interface NumberTweakConfig extends TweakConfigBase {
224
+ type: 'number';
225
+ value: number;
226
+ min?: number;
227
+ max?: number;
228
+ step?: number;
229
+ }
230
+
231
+ export interface BooleanTweakConfig extends TweakConfigBase {
232
+ type: 'boolean';
233
+ value: boolean;
234
+ }
235
+
236
+ export interface StringTweakConfig extends TweakConfigBase {
237
+ type: 'string';
238
+ value: string;
239
+ }
240
+
241
+ export interface SelectTweakConfig extends TweakConfigBase {
242
+ type: 'select';
243
+ value: string;
244
+ options: (string | SelectOption)[];
245
+ }
246
+
247
+ export type TweakConfig =
248
+ | ColorTweakConfig
249
+ | NumberTweakConfig
250
+ | BooleanTweakConfig
251
+ | StringTweakConfig
252
+ | SelectTweakConfig;
253
+
254
+ export type TweaksConfig = Record<string, TweakConfig>;
255
+
256
+ // ============================================
257
+ // Bridge 消息类型
258
+ // ============================================
259
+
260
+ export interface BridgeMessage {
261
+ id: string;
262
+ module: string;
263
+ method: string;
264
+ params: Record<string, unknown>;
265
+ timestamp: number;
266
+ }
267
+
268
+ export interface BridgeResponse {
269
+ id: string;
270
+ module: string;
271
+ method: string;
272
+ success: boolean;
273
+ error: string | null;
274
+ data: unknown;
275
+ timestamp: number;
276
+ }
277
+
278
+ // ============================================
279
+ // 全局声明
280
+ // ============================================
281
+
282
+ declare global {
283
+ interface Window {
284
+ ReactNativeWebView?: {
285
+ postMessage: (message: string) => void;
286
+ };
287
+ __RIFFLE_CALLBACKS__?: Map<string, (response: BridgeResponse) => void>;
288
+ __RIFFLE_READY__?: boolean;
289
+ __RIFFLE_SENSOR_HANDLERS__?: Map<string, Set<(data: unknown[]) => void>>;
290
+ handleNativeResponse?: (responseStr: string) => void;
291
+ handleSensorData?: (data: { sensor: string; values: unknown[] }) => void;
292
+ }
293
+ }
294
+
295
+ export {};