@mr-m/telegram-webapp-kit 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 +376 -0
- package/dist/index.d.mts +701 -0
- package/dist/index.d.ts +701 -0
- package/dist/index.js +1232 -0
- package/dist/index.mjs +1174 -0
- package/package.json +34 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface TgUser {
|
|
5
|
+
id: number;
|
|
6
|
+
first_name?: string;
|
|
7
|
+
last_name?: string;
|
|
8
|
+
username?: string;
|
|
9
|
+
language_code?: string;
|
|
10
|
+
photo_url?: string;
|
|
11
|
+
is_premium?: boolean;
|
|
12
|
+
allows_write_to_pm?: boolean;
|
|
13
|
+
added_to_attachment_menu?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface TgThemeParams {
|
|
16
|
+
bg_color?: string;
|
|
17
|
+
text_color?: string;
|
|
18
|
+
hint_color?: string;
|
|
19
|
+
link_color?: string;
|
|
20
|
+
button_color?: string;
|
|
21
|
+
button_text_color?: string;
|
|
22
|
+
secondary_bg_color?: string;
|
|
23
|
+
header_bg_color?: string;
|
|
24
|
+
bottom_bar_bg_color?: string;
|
|
25
|
+
accent_text_color?: string;
|
|
26
|
+
section_bg_color?: string;
|
|
27
|
+
section_header_text_color?: string;
|
|
28
|
+
section_separator_color?: string;
|
|
29
|
+
subtitle_text_color?: string;
|
|
30
|
+
destructive_text_color?: string;
|
|
31
|
+
}
|
|
32
|
+
interface BottomButtonParams {
|
|
33
|
+
text?: string;
|
|
34
|
+
color?: string;
|
|
35
|
+
text_color?: string;
|
|
36
|
+
is_visible?: boolean;
|
|
37
|
+
is_active?: boolean;
|
|
38
|
+
hasShineEffect?: boolean;
|
|
39
|
+
position?: 'left' | 'right' | 'top' | 'bottom';
|
|
40
|
+
}
|
|
41
|
+
interface BottomButton {
|
|
42
|
+
type: 'main' | 'secondary';
|
|
43
|
+
text: string;
|
|
44
|
+
color: string;
|
|
45
|
+
text_color: string;
|
|
46
|
+
is_visible: boolean;
|
|
47
|
+
is_active: boolean;
|
|
48
|
+
hasShineEffect: boolean;
|
|
49
|
+
isProgressVisible: boolean;
|
|
50
|
+
position?: 'left' | 'right' | 'top' | 'bottom';
|
|
51
|
+
setText: (text: string) => void;
|
|
52
|
+
onClick: (cb: () => void) => void;
|
|
53
|
+
offClick: (cb: () => void) => void;
|
|
54
|
+
show: () => void;
|
|
55
|
+
hide: () => void;
|
|
56
|
+
enable: () => void;
|
|
57
|
+
disable: () => void;
|
|
58
|
+
showProgress: (leaveActive?: boolean) => void;
|
|
59
|
+
hideProgress: () => void;
|
|
60
|
+
setParams: (params: BottomButtonParams) => void;
|
|
61
|
+
}
|
|
62
|
+
interface MainButton extends BottomButton {
|
|
63
|
+
type: 'main';
|
|
64
|
+
}
|
|
65
|
+
interface SecondaryButton extends BottomButton {
|
|
66
|
+
type: 'secondary';
|
|
67
|
+
position: 'left' | 'right' | 'top' | 'bottom';
|
|
68
|
+
}
|
|
69
|
+
interface SettingsButton {
|
|
70
|
+
isVisible: boolean;
|
|
71
|
+
show: () => void;
|
|
72
|
+
hide: () => void;
|
|
73
|
+
onClick: (cb: () => void) => void;
|
|
74
|
+
offClick: (cb: () => void) => void;
|
|
75
|
+
}
|
|
76
|
+
interface BackButton {
|
|
77
|
+
isVisible: boolean;
|
|
78
|
+
show: () => void;
|
|
79
|
+
hide: () => void;
|
|
80
|
+
onClick: (cb: () => void) => void;
|
|
81
|
+
offClick: (cb: () => void) => void;
|
|
82
|
+
}
|
|
83
|
+
interface HapticFeedback {
|
|
84
|
+
impactOccurred: (style: 'light' | 'medium' | 'heavy' | 'rigid' | 'soft') => void;
|
|
85
|
+
notificationOccurred: (type: 'error' | 'success' | 'warning') => void;
|
|
86
|
+
selectionChanged: () => void;
|
|
87
|
+
}
|
|
88
|
+
interface Accelerometer {
|
|
89
|
+
isStarted: boolean;
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
z: number;
|
|
93
|
+
start: (params?: {
|
|
94
|
+
refresh_rate?: number;
|
|
95
|
+
}, callback?: (error?: Error) => void) => void;
|
|
96
|
+
stop: (callback?: (error?: Error) => void) => void;
|
|
97
|
+
}
|
|
98
|
+
interface DeviceOrientation {
|
|
99
|
+
isStarted: boolean;
|
|
100
|
+
absolute: boolean;
|
|
101
|
+
alpha: number | null;
|
|
102
|
+
beta: number | null;
|
|
103
|
+
gamma: number | null;
|
|
104
|
+
start: (params?: {
|
|
105
|
+
refresh_rate?: number;
|
|
106
|
+
need_absolute?: boolean;
|
|
107
|
+
}, callback?: (error?: Error) => void) => void;
|
|
108
|
+
stop: (callback?: (error?: Error) => void) => void;
|
|
109
|
+
}
|
|
110
|
+
interface Gyroscope {
|
|
111
|
+
isStarted: boolean;
|
|
112
|
+
x: number;
|
|
113
|
+
y: number;
|
|
114
|
+
z: number;
|
|
115
|
+
start: (params?: {
|
|
116
|
+
refresh_rate?: number;
|
|
117
|
+
}, callback?: (error?: Error) => void) => void;
|
|
118
|
+
stop: (callback?: (error?: Error) => void) => void;
|
|
119
|
+
}
|
|
120
|
+
interface CloudStorage {
|
|
121
|
+
setItem: (key: string, value: string, callback?: (error: Error | null, success: boolean) => void) => void;
|
|
122
|
+
getItem: (key: string, callback: (error: Error | null, value: string) => void) => void;
|
|
123
|
+
getItems: (keys: string[], callback: (error: Error | null, values: Record<string, string>) => void) => void;
|
|
124
|
+
removeItem: (key: string, callback?: (error: Error | null, success: boolean) => void) => void;
|
|
125
|
+
removeItems: (keys: string[], callback?: (error: Error | null, success: boolean) => void) => void;
|
|
126
|
+
getKeys: (callback: (error: Error | null, keys: string[]) => void) => void;
|
|
127
|
+
}
|
|
128
|
+
interface LocationData {
|
|
129
|
+
latitude: number;
|
|
130
|
+
longitude: number;
|
|
131
|
+
altitude: number | null;
|
|
132
|
+
course: number | null;
|
|
133
|
+
speed: number | null;
|
|
134
|
+
horizontal_accuracy: number | null;
|
|
135
|
+
vertical_accuracy: number | null;
|
|
136
|
+
course_accuracy: number | null;
|
|
137
|
+
speed_accuracy: number | null;
|
|
138
|
+
}
|
|
139
|
+
interface LocationManager {
|
|
140
|
+
isInited: boolean;
|
|
141
|
+
isLocationAvailable: boolean;
|
|
142
|
+
isAccessRequested: boolean;
|
|
143
|
+
isAccessGranted: boolean;
|
|
144
|
+
init: (callback?: (error?: Error) => void) => void;
|
|
145
|
+
getLocation: (callback: (location: LocationData | null) => void) => void;
|
|
146
|
+
openSettings: () => void;
|
|
147
|
+
}
|
|
148
|
+
interface BiometricRequestAccessParams {
|
|
149
|
+
reason?: string;
|
|
150
|
+
}
|
|
151
|
+
interface BiometricAuthenticateParams {
|
|
152
|
+
reason?: string;
|
|
153
|
+
}
|
|
154
|
+
interface BiometricManager {
|
|
155
|
+
isInited: boolean;
|
|
156
|
+
isBiometricAvailable: boolean;
|
|
157
|
+
biometricType: 'finger' | 'face' | 'unknown';
|
|
158
|
+
isAccessRequested: boolean;
|
|
159
|
+
isAccessGranted: boolean;
|
|
160
|
+
isBiometricTokenSaved: boolean;
|
|
161
|
+
deviceId: string;
|
|
162
|
+
init: (callback?: () => void) => void;
|
|
163
|
+
requestAccess: (params: BiometricRequestAccessParams, callback?: (granted: boolean) => void) => void;
|
|
164
|
+
authenticate: (params: BiometricAuthenticateParams, callback?: (authenticated: boolean, token?: string) => void) => void;
|
|
165
|
+
updateBiometricToken: (token: string, callback?: (updated: boolean) => void) => void;
|
|
166
|
+
openSettings: () => void;
|
|
167
|
+
}
|
|
168
|
+
interface ChatAdministratorRights {
|
|
169
|
+
can_manage_chat?: boolean;
|
|
170
|
+
can_change_info?: boolean;
|
|
171
|
+
can_delete_messages?: boolean;
|
|
172
|
+
can_invite_users?: boolean;
|
|
173
|
+
can_restrict_members?: boolean;
|
|
174
|
+
can_pin_messages?: boolean;
|
|
175
|
+
can_promote_members?: boolean;
|
|
176
|
+
can_manage_video_chats?: boolean;
|
|
177
|
+
is_anonymous?: boolean;
|
|
178
|
+
can_manage_topics?: boolean;
|
|
179
|
+
can_post_stories?: boolean;
|
|
180
|
+
can_edit_stories?: boolean;
|
|
181
|
+
can_delete_stories?: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface RequestChatParams {
|
|
184
|
+
request_id: number;
|
|
185
|
+
chat_is_channel: boolean;
|
|
186
|
+
chat_is_forum?: boolean;
|
|
187
|
+
chat_has_username?: boolean;
|
|
188
|
+
chat_is_created?: boolean;
|
|
189
|
+
user_administrator_rights?: ChatAdministratorRights;
|
|
190
|
+
bot_administrator_rights?: ChatAdministratorRights;
|
|
191
|
+
bot_is_member?: boolean;
|
|
192
|
+
request_title?: boolean;
|
|
193
|
+
request_username?: boolean;
|
|
194
|
+
request_photo?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface PopupButton {
|
|
197
|
+
id?: string;
|
|
198
|
+
type?: 'default' | 'ok' | 'close' | 'cancel' | 'destructive';
|
|
199
|
+
text?: string;
|
|
200
|
+
}
|
|
201
|
+
interface PopupParams {
|
|
202
|
+
title?: string;
|
|
203
|
+
message: string;
|
|
204
|
+
buttons?: PopupButton[];
|
|
205
|
+
}
|
|
206
|
+
interface ScanQrPopupParams {
|
|
207
|
+
text?: string;
|
|
208
|
+
}
|
|
209
|
+
interface StoryShareParams {
|
|
210
|
+
text?: string;
|
|
211
|
+
widget_link?: {
|
|
212
|
+
url: string;
|
|
213
|
+
name?: string;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
interface EmojiStatusParams {
|
|
217
|
+
duration?: number;
|
|
218
|
+
}
|
|
219
|
+
interface DownloadFileParams {
|
|
220
|
+
url: string;
|
|
221
|
+
file_name: string;
|
|
222
|
+
}
|
|
223
|
+
interface SafeAreaInset {
|
|
224
|
+
top: number;
|
|
225
|
+
bottom: number;
|
|
226
|
+
left: number;
|
|
227
|
+
right: number;
|
|
228
|
+
}
|
|
229
|
+
interface TgWebApp {
|
|
230
|
+
initData: string;
|
|
231
|
+
initDataUnsafe: {
|
|
232
|
+
user?: TgUser;
|
|
233
|
+
receiver?: TgUser;
|
|
234
|
+
chat?: {
|
|
235
|
+
id: number;
|
|
236
|
+
type: string;
|
|
237
|
+
title: string;
|
|
238
|
+
username?: string;
|
|
239
|
+
photo_url?: string;
|
|
240
|
+
};
|
|
241
|
+
start_param?: string;
|
|
242
|
+
can_send_after?: number;
|
|
243
|
+
auth_date?: number;
|
|
244
|
+
hash?: string;
|
|
245
|
+
chat_type?: string;
|
|
246
|
+
chat_instance?: string;
|
|
247
|
+
signature?: string;
|
|
248
|
+
};
|
|
249
|
+
version: string;
|
|
250
|
+
platform: string;
|
|
251
|
+
colorScheme: 'light' | 'dark';
|
|
252
|
+
themeParams: TgThemeParams;
|
|
253
|
+
isExpanded: boolean;
|
|
254
|
+
viewportHeight: number;
|
|
255
|
+
viewportStableHeight: number;
|
|
256
|
+
headerColor: string;
|
|
257
|
+
backgroundColor: string;
|
|
258
|
+
bottomBarColor: string;
|
|
259
|
+
isActive?: boolean;
|
|
260
|
+
isFullscreen?: boolean;
|
|
261
|
+
isOrientationLocked?: boolean;
|
|
262
|
+
isClosingConfirmationEnabled: boolean;
|
|
263
|
+
isVerticalSwipesEnabled: boolean;
|
|
264
|
+
safeAreaInset?: SafeAreaInset;
|
|
265
|
+
contentSafeAreaInset?: SafeAreaInset;
|
|
266
|
+
MainButton: MainButton;
|
|
267
|
+
SecondaryButton?: SecondaryButton;
|
|
268
|
+
BackButton: BackButton;
|
|
269
|
+
SettingsButton?: SettingsButton;
|
|
270
|
+
HapticFeedback: HapticFeedback;
|
|
271
|
+
Accelerometer?: Accelerometer;
|
|
272
|
+
DeviceOrientation?: DeviceOrientation;
|
|
273
|
+
Gyroscope?: Gyroscope;
|
|
274
|
+
CloudStorage: CloudStorage;
|
|
275
|
+
DeviceStorage?: CloudStorage;
|
|
276
|
+
SecureStorage?: CloudStorage;
|
|
277
|
+
LocationManager?: LocationManager;
|
|
278
|
+
BiometricManager?: BiometricManager;
|
|
279
|
+
ready: () => void;
|
|
280
|
+
expand: () => void;
|
|
281
|
+
close: () => void;
|
|
282
|
+
setHeaderColor: (color: string) => void;
|
|
283
|
+
setBackgroundColor: (color: string) => void;
|
|
284
|
+
setBottomBarColor?: (color: string) => void;
|
|
285
|
+
enableVerticalSwipes?: () => void;
|
|
286
|
+
disableVerticalSwipes?: () => void;
|
|
287
|
+
enableClosingConfirmation?: () => void;
|
|
288
|
+
disableClosingConfirmation?: () => void;
|
|
289
|
+
requestFullscreen?: () => void;
|
|
290
|
+
exitFullscreen?: () => void;
|
|
291
|
+
sendData: (data: string) => void;
|
|
292
|
+
switchInlineQuery: (query: string, chooseChatTypes?: Array<'users' | 'bots' | 'groups' | 'channels'>) => void;
|
|
293
|
+
openLink: (url: string, options?: {
|
|
294
|
+
try_instant_view?: boolean;
|
|
295
|
+
try_browser?: boolean;
|
|
296
|
+
}) => void;
|
|
297
|
+
openTelegramLink: (url: string) => void;
|
|
298
|
+
openInvoice: (url: string, callback?: (status: 'paid' | 'cancelled' | 'failed' | 'pending') => void) => void;
|
|
299
|
+
shareToStory?: (mediaUrl: string, params?: StoryShareParams) => void;
|
|
300
|
+
shareMessage?: (msgId: string, callback?: (success: boolean) => void) => void;
|
|
301
|
+
setEmojiStatus?: (customEmojiId: string, params?: EmojiStatusParams, callback?: (success: boolean) => void) => void;
|
|
302
|
+
requestEmojiStatusAccess?: (callback?: (granted: boolean) => void) => void;
|
|
303
|
+
downloadFile?: (params: DownloadFileParams, callback?: (accepted: boolean) => void) => void;
|
|
304
|
+
hideKeyboard?: () => void;
|
|
305
|
+
showPopup: (params: PopupParams, callback?: (buttonId: string) => void) => void;
|
|
306
|
+
showAlert: (message: string, callback?: () => void) => void;
|
|
307
|
+
showConfirm: (message: string, callback?: (confirmed: boolean) => void) => void;
|
|
308
|
+
showScanQrPopup: (params: ScanQrPopupParams, callback?: (text: string) => void) => void;
|
|
309
|
+
closeScanQrPopup: () => void;
|
|
310
|
+
readTextFromClipboard?: (callback?: (text: string) => void) => void;
|
|
311
|
+
requestWriteAccess?: (callback?: (granted: boolean) => void) => void;
|
|
312
|
+
requestContact?: (callback?: (shared: boolean) => void) => void;
|
|
313
|
+
requestChat?: (params: RequestChatParams, callback?: (success: boolean) => void) => void;
|
|
314
|
+
addToHomeScreen?: () => void;
|
|
315
|
+
checkHomeScreenStatus?: (callback?: (status: 'unsupported' | 'unknown' | 'added' | 'missed') => void) => void;
|
|
316
|
+
requestWriteAccess2?: (callback?: (granted: boolean) => void) => void;
|
|
317
|
+
shareToStoryV2?: (params: StoryShareParams & {
|
|
318
|
+
media_url: string;
|
|
319
|
+
}) => void;
|
|
320
|
+
onEvent: (eventType: WebAppEventType | string, eventHandler: (...args: unknown[]) => void) => void;
|
|
321
|
+
offEvent: (eventType: WebAppEventType | string, eventHandler: (...args: unknown[]) => void) => void;
|
|
322
|
+
isVersionAtLeast: (version: string) => boolean;
|
|
323
|
+
}
|
|
324
|
+
type WebAppEventType = 'themeChanged' | 'mainButtonClicked' | 'secondaryButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked' | 'viewportChanged' | 'invoiceClosed' | 'popupClosed' | 'qrTextReceived' | 'scanQrPopupClosed' | 'clipboardTextReceived' | 'writeAccessRequested' | 'contactRequested' | 'chatBoostAdded' | 'activated' | 'deactivated' | 'safeAreaChanged' | 'contentSafeAreaChanged' | 'fullscreenChanged' | 'fullscreenFailed' | 'homeScreenAdded' | 'homeScreenChecked' | 'emojiStatusSet' | 'emojiStatusFailed' | 'emojiStatusAccessRequested' | 'shareMessageSent' | 'shareMessageFailed' | 'fileDownloadRequested' | 'locationManagerUpdated' | 'locationRequested' | 'accelerometerStarted' | 'accelerometerStopped' | 'accelerometerChanged' | 'accelerometerFailed' | 'deviceOrientationStarted' | 'deviceOrientationStopped' | 'deviceOrientationChanged' | 'deviceOrientationFailed' | 'gyroscopeStarted' | 'gyroscopeStopped' | 'gyroscopeChanged' | 'gyroscopeFailed' | 'biometricManagerUpdated' | 'biometricAuthRequested' | 'biometricTokenUpdated';
|
|
325
|
+
declare global {
|
|
326
|
+
interface Window {
|
|
327
|
+
Telegram?: {
|
|
328
|
+
WebApp?: TgWebApp;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
declare function getWebApp(): TgWebApp | null;
|
|
334
|
+
declare function isInTelegram(): boolean;
|
|
335
|
+
declare function isVersionAtLeast(version: string): boolean;
|
|
336
|
+
declare function tgLangToTmdb(code?: string): string;
|
|
337
|
+
declare function tgLangToUi(code?: string): string;
|
|
338
|
+
declare const RTL_LANGS: Set<string>;
|
|
339
|
+
declare function isRtlLang(lang?: string): boolean;
|
|
340
|
+
declare const SUPPORTED_LANGS: readonly [{
|
|
341
|
+
readonly code: "en";
|
|
342
|
+
readonly countryCode: "us";
|
|
343
|
+
readonly name: "English";
|
|
344
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/us.svg";
|
|
345
|
+
}, {
|
|
346
|
+
readonly code: "ar";
|
|
347
|
+
readonly countryCode: "sa";
|
|
348
|
+
readonly name: "العربية";
|
|
349
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/sa.svg";
|
|
350
|
+
}, {
|
|
351
|
+
readonly code: "es";
|
|
352
|
+
readonly countryCode: "es";
|
|
353
|
+
readonly name: "Español";
|
|
354
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/es.svg";
|
|
355
|
+
}, {
|
|
356
|
+
readonly code: "fr";
|
|
357
|
+
readonly countryCode: "fr";
|
|
358
|
+
readonly name: "Français";
|
|
359
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/fr.svg";
|
|
360
|
+
}, {
|
|
361
|
+
readonly code: "de";
|
|
362
|
+
readonly countryCode: "de";
|
|
363
|
+
readonly name: "Deutsch";
|
|
364
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/de.svg";
|
|
365
|
+
}, {
|
|
366
|
+
readonly code: "it";
|
|
367
|
+
readonly countryCode: "it";
|
|
368
|
+
readonly name: "Italiano";
|
|
369
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/it.svg";
|
|
370
|
+
}, {
|
|
371
|
+
readonly code: "pt";
|
|
372
|
+
readonly countryCode: "pt";
|
|
373
|
+
readonly name: "Português";
|
|
374
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/pt.svg";
|
|
375
|
+
}, {
|
|
376
|
+
readonly code: "ru";
|
|
377
|
+
readonly countryCode: "ru";
|
|
378
|
+
readonly name: "Русский";
|
|
379
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/ru.svg";
|
|
380
|
+
}, {
|
|
381
|
+
readonly code: "zh";
|
|
382
|
+
readonly countryCode: "cn";
|
|
383
|
+
readonly name: "中文";
|
|
384
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/cn.svg";
|
|
385
|
+
}, {
|
|
386
|
+
readonly code: "ja";
|
|
387
|
+
readonly countryCode: "jp";
|
|
388
|
+
readonly name: "日本語";
|
|
389
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/jp.svg";
|
|
390
|
+
}, {
|
|
391
|
+
readonly code: "ko";
|
|
392
|
+
readonly countryCode: "kr";
|
|
393
|
+
readonly name: "한국어";
|
|
394
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/kr.svg";
|
|
395
|
+
}, {
|
|
396
|
+
readonly code: "tr";
|
|
397
|
+
readonly countryCode: "tr";
|
|
398
|
+
readonly name: "Türkçe";
|
|
399
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/tr.svg";
|
|
400
|
+
}, {
|
|
401
|
+
readonly code: "hi";
|
|
402
|
+
readonly countryCode: "in";
|
|
403
|
+
readonly name: "हिन्दी";
|
|
404
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/in.svg";
|
|
405
|
+
}, {
|
|
406
|
+
readonly code: "id";
|
|
407
|
+
readonly countryCode: "id";
|
|
408
|
+
readonly name: "Indonesia";
|
|
409
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/id.svg";
|
|
410
|
+
}, {
|
|
411
|
+
readonly code: "nl";
|
|
412
|
+
readonly countryCode: "nl";
|
|
413
|
+
readonly name: "Nederlands";
|
|
414
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/nl.svg";
|
|
415
|
+
}, {
|
|
416
|
+
readonly code: "pl";
|
|
417
|
+
readonly countryCode: "pl";
|
|
418
|
+
readonly name: "Polski";
|
|
419
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/pl.svg";
|
|
420
|
+
}, {
|
|
421
|
+
readonly code: "sv";
|
|
422
|
+
readonly countryCode: "se";
|
|
423
|
+
readonly name: "Svenska";
|
|
424
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/se.svg";
|
|
425
|
+
}, {
|
|
426
|
+
readonly code: "uk";
|
|
427
|
+
readonly countryCode: "ua";
|
|
428
|
+
readonly name: "Українська";
|
|
429
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/ua.svg";
|
|
430
|
+
}, {
|
|
431
|
+
readonly code: "vi";
|
|
432
|
+
readonly countryCode: "vn";
|
|
433
|
+
readonly name: "Tiếng Việt";
|
|
434
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/vn.svg";
|
|
435
|
+
}, {
|
|
436
|
+
readonly code: "fa";
|
|
437
|
+
readonly countryCode: "ir";
|
|
438
|
+
readonly name: "فارسی";
|
|
439
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/ir.svg";
|
|
440
|
+
}, {
|
|
441
|
+
readonly code: "he";
|
|
442
|
+
readonly countryCode: "il";
|
|
443
|
+
readonly name: "עברית";
|
|
444
|
+
readonly flag: "https://raw.githubusercontent.com/mr-m-apps/icons/refs/heads/main/flags/il.svg";
|
|
445
|
+
}];
|
|
446
|
+
type Language = (typeof SUPPORTED_LANGS)[number];
|
|
447
|
+
declare function openExternalLink(url: string, tryInstantView?: boolean): void;
|
|
448
|
+
declare function openTelegramLink(url: string): void;
|
|
449
|
+
declare function getUserAvatarUrl(user?: TgUser, defaultAvatarUrl?: string): string;
|
|
450
|
+
declare function getUserIdentifier(user?: TgUser): string;
|
|
451
|
+
declare function getUserDisplayName(user?: TgUser): string;
|
|
452
|
+
declare function getUserInfoWithAvatar(): {
|
|
453
|
+
user: TgUser | undefined;
|
|
454
|
+
avatarUrl: string;
|
|
455
|
+
displayName: string;
|
|
456
|
+
identifier: string;
|
|
457
|
+
};
|
|
458
|
+
declare function getRawUserData(): TgUser | null;
|
|
459
|
+
declare const haptic: {
|
|
460
|
+
light: () => void | undefined;
|
|
461
|
+
medium: () => void | undefined;
|
|
462
|
+
heavy: () => void | undefined;
|
|
463
|
+
rigid: () => void | undefined;
|
|
464
|
+
soft: () => void | undefined;
|
|
465
|
+
success: () => void | undefined;
|
|
466
|
+
error: () => void | undefined;
|
|
467
|
+
warning: () => void | undefined;
|
|
468
|
+
selection: () => void | undefined;
|
|
469
|
+
};
|
|
470
|
+
declare const cloudStorage: {
|
|
471
|
+
setItem: (key: string, value: string) => Promise<boolean>;
|
|
472
|
+
getItem: (key: string) => Promise<string>;
|
|
473
|
+
getItems: (keys: string[]) => Promise<Record<string, string>>;
|
|
474
|
+
removeItem: (key: string) => Promise<boolean>;
|
|
475
|
+
getKeys: () => Promise<string[]>;
|
|
476
|
+
};
|
|
477
|
+
declare const dialog: {
|
|
478
|
+
alert: (message: string) => Promise<void>;
|
|
479
|
+
confirm: (message: string) => Promise<boolean>;
|
|
480
|
+
popup: (params: PopupParams) => Promise<string>;
|
|
481
|
+
};
|
|
482
|
+
declare function readClipboard(): Promise<string>;
|
|
483
|
+
declare function openInvoice(url: string): Promise<'paid' | 'cancelled' | 'failed' | 'pending'>;
|
|
484
|
+
declare function scanQr(text?: string): Promise<string>;
|
|
485
|
+
declare const biometric: {
|
|
486
|
+
init: () => Promise<void>;
|
|
487
|
+
requestAccess: (reason?: string) => Promise<boolean>;
|
|
488
|
+
authenticate: (reason?: string) => Promise<{
|
|
489
|
+
authenticated: boolean;
|
|
490
|
+
token?: string;
|
|
491
|
+
}>;
|
|
492
|
+
};
|
|
493
|
+
declare const location: {
|
|
494
|
+
init: () => Promise<void>;
|
|
495
|
+
getLocation: () => Promise<LocationData | null>;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Returns the raw Telegram WebApp instance.
|
|
500
|
+
* Null on server or outside Telegram.
|
|
501
|
+
*/
|
|
502
|
+
declare function useTelegramWebApp(): TgWebApp | null;
|
|
503
|
+
declare function useTelegramUser(): TgUser | null;
|
|
504
|
+
/**
|
|
505
|
+
* Subscribe to any Telegram WebApp event.
|
|
506
|
+
*/
|
|
507
|
+
declare function useTelegramEvent(eventType: WebAppEventType | string, handler: (...args: unknown[]) => void): void;
|
|
508
|
+
/**
|
|
509
|
+
* Automatically shows/hides the Telegram Back Button based on pathname.
|
|
510
|
+
* Pass `onBack` to override default browser history back behavior.
|
|
511
|
+
*/
|
|
512
|
+
declare function useTelegramBackButton(options?: {
|
|
513
|
+
pathname?: string;
|
|
514
|
+
onBack?: () => void;
|
|
515
|
+
hideOnRoot?: boolean;
|
|
516
|
+
}): void;
|
|
517
|
+
/**
|
|
518
|
+
* Control the Telegram Main Button declaratively.
|
|
519
|
+
*/
|
|
520
|
+
declare function useTelegramMainButton(options: {
|
|
521
|
+
text: string;
|
|
522
|
+
onClick: () => void;
|
|
523
|
+
isVisible?: boolean;
|
|
524
|
+
isActive?: boolean;
|
|
525
|
+
color?: string;
|
|
526
|
+
textColor?: string;
|
|
527
|
+
hasShineEffect?: boolean;
|
|
528
|
+
showProgress?: boolean;
|
|
529
|
+
}): void;
|
|
530
|
+
declare function useTelegramSecondaryButton(options: {
|
|
531
|
+
text: string;
|
|
532
|
+
onClick: () => void;
|
|
533
|
+
isVisible?: boolean;
|
|
534
|
+
isActive?: boolean;
|
|
535
|
+
position?: 'left' | 'right' | 'top' | 'bottom';
|
|
536
|
+
color?: string;
|
|
537
|
+
textColor?: string;
|
|
538
|
+
}): void;
|
|
539
|
+
declare function useTelegramSettingsButton(onSettings: () => void): void;
|
|
540
|
+
declare function useHapticFeedback(): {
|
|
541
|
+
impact: (style?: "light" | "medium" | "heavy" | "rigid" | "soft") => void;
|
|
542
|
+
notification: (type: "error" | "success" | "warning") => void;
|
|
543
|
+
selectionChanged: () => void;
|
|
544
|
+
};
|
|
545
|
+
declare function useTelegramTheme(): {
|
|
546
|
+
colorScheme: "light" | "dark";
|
|
547
|
+
themeParams: TgThemeParams;
|
|
548
|
+
isDark: boolean;
|
|
549
|
+
};
|
|
550
|
+
declare function useTelegramViewport(): {
|
|
551
|
+
expand: () => void | undefined;
|
|
552
|
+
height: number;
|
|
553
|
+
stableHeight: number;
|
|
554
|
+
isExpanded: boolean;
|
|
555
|
+
};
|
|
556
|
+
declare function useTelegramFullscreen(): {
|
|
557
|
+
isFullscreen: boolean;
|
|
558
|
+
error: {
|
|
559
|
+
error: string;
|
|
560
|
+
} | null;
|
|
561
|
+
enter: () => void;
|
|
562
|
+
exit: () => void;
|
|
563
|
+
toggle: () => void;
|
|
564
|
+
};
|
|
565
|
+
declare function useSafeArea(): {
|
|
566
|
+
safeArea: SafeAreaInset;
|
|
567
|
+
contentSafeArea: SafeAreaInset;
|
|
568
|
+
};
|
|
569
|
+
declare function useCloudStorage(): {
|
|
570
|
+
setItem: (key: string, value: string) => Promise<boolean>;
|
|
571
|
+
getItem: (key: string) => Promise<string>;
|
|
572
|
+
getItems: (keys: string[]) => Promise<Record<string, string>>;
|
|
573
|
+
removeItem: (key: string) => Promise<boolean>;
|
|
574
|
+
getKeys: () => Promise<string[]>;
|
|
575
|
+
};
|
|
576
|
+
declare function useAccelerometer(options?: {
|
|
577
|
+
refreshRate?: number;
|
|
578
|
+
autoStart?: boolean;
|
|
579
|
+
}): {
|
|
580
|
+
isStarted: boolean;
|
|
581
|
+
start: () => void;
|
|
582
|
+
stop: () => void;
|
|
583
|
+
x: number;
|
|
584
|
+
y: number;
|
|
585
|
+
z: number;
|
|
586
|
+
};
|
|
587
|
+
declare function useGyroscope(options?: {
|
|
588
|
+
refreshRate?: number;
|
|
589
|
+
autoStart?: boolean;
|
|
590
|
+
}): {
|
|
591
|
+
isStarted: boolean;
|
|
592
|
+
start: () => void;
|
|
593
|
+
stop: () => void;
|
|
594
|
+
x: number;
|
|
595
|
+
y: number;
|
|
596
|
+
z: number;
|
|
597
|
+
};
|
|
598
|
+
declare function useDeviceOrientation(options?: {
|
|
599
|
+
refreshRate?: number;
|
|
600
|
+
needAbsolute?: boolean;
|
|
601
|
+
autoStart?: boolean;
|
|
602
|
+
}): {
|
|
603
|
+
isStarted: boolean;
|
|
604
|
+
start: () => void;
|
|
605
|
+
stop: () => void;
|
|
606
|
+
alpha: number;
|
|
607
|
+
beta: number;
|
|
608
|
+
gamma: number;
|
|
609
|
+
absolute: boolean;
|
|
610
|
+
};
|
|
611
|
+
declare function useBiometric(): {
|
|
612
|
+
isInited: boolean;
|
|
613
|
+
isAvailable: boolean;
|
|
614
|
+
biometricType: "finger" | "face" | "unknown";
|
|
615
|
+
init: () => Promise<void>;
|
|
616
|
+
requestAccess: (reason?: string) => Promise<boolean>;
|
|
617
|
+
authenticate: (reason?: string) => Promise<{
|
|
618
|
+
authenticated: boolean;
|
|
619
|
+
token?: string;
|
|
620
|
+
}>;
|
|
621
|
+
};
|
|
622
|
+
declare function useLocation(): {
|
|
623
|
+
isAvailable: boolean;
|
|
624
|
+
isGranted: boolean;
|
|
625
|
+
init: () => Promise<void>;
|
|
626
|
+
getLocation: () => Promise<LocationData | null>;
|
|
627
|
+
openSettings: () => void;
|
|
628
|
+
};
|
|
629
|
+
declare function useHomeScreen(): {
|
|
630
|
+
addToHomeScreen: () => void;
|
|
631
|
+
checkStatus: () => Promise<"unsupported" | "unknown" | "added" | "missed">;
|
|
632
|
+
};
|
|
633
|
+
declare function useIsActive(): boolean;
|
|
634
|
+
declare function useTelegramStartParam(): string | null;
|
|
635
|
+
|
|
636
|
+
interface TelegramContextValue {
|
|
637
|
+
ready: boolean;
|
|
638
|
+
inTelegram: boolean;
|
|
639
|
+
/** true in dev mode when bypass=true in URL or NODE_ENV === 'development' */
|
|
640
|
+
bypass: boolean;
|
|
641
|
+
webApp: TgWebApp | null;
|
|
642
|
+
user: TgUser | null;
|
|
643
|
+
/** TMDB-style locale e.g. 'en-US' */
|
|
644
|
+
language: string;
|
|
645
|
+
/** Short UI lang code e.g. 'en' */
|
|
646
|
+
uiLang: string;
|
|
647
|
+
colorScheme: 'light' | 'dark';
|
|
648
|
+
startParam: string | null;
|
|
649
|
+
isRtl: boolean;
|
|
650
|
+
changeLanguage: (lang: string) => void;
|
|
651
|
+
}
|
|
652
|
+
interface TelegramProviderOptions {
|
|
653
|
+
/** localStorage key for saved language */
|
|
654
|
+
langStorageKey?: string;
|
|
655
|
+
/** Called when a user is found; use to sync to your backend */
|
|
656
|
+
onUserReady?: (user: TgUser) => void;
|
|
657
|
+
/** Called when the WebApp is initialized */
|
|
658
|
+
onReady?: (wa: TgWebApp) => void;
|
|
659
|
+
/** Custom i18n change function */
|
|
660
|
+
onLanguageChange?: (lang: string) => void;
|
|
661
|
+
/** Component shown while initializing */
|
|
662
|
+
loadingComponent?: ReactNode;
|
|
663
|
+
/** Component shown when not in Telegram (outside dev bypass) */
|
|
664
|
+
notInTelegramComponent?: ReactNode;
|
|
665
|
+
/** Allow rendering outside Telegram in all envs (not just dev) */
|
|
666
|
+
allowOutsideTelegram?: boolean;
|
|
667
|
+
}
|
|
668
|
+
declare function useTelegram(): TelegramContextValue;
|
|
669
|
+
declare function TelegramProvider({ children, options, }: {
|
|
670
|
+
children: ReactNode;
|
|
671
|
+
options?: TelegramProviderOptions;
|
|
672
|
+
}): react.JSX.Element;
|
|
673
|
+
|
|
674
|
+
interface FullscreenError {
|
|
675
|
+
error: 'UNSUPPORTED' | 'ALREADY_FULLSCREEN';
|
|
676
|
+
}
|
|
677
|
+
interface FullscreenContextValue {
|
|
678
|
+
isFullscreen: boolean;
|
|
679
|
+
isSupported: boolean;
|
|
680
|
+
isActive: boolean;
|
|
681
|
+
isOrientationLocked: boolean;
|
|
682
|
+
safeArea: SafeAreaInset;
|
|
683
|
+
contentSafeArea: SafeAreaInset;
|
|
684
|
+
lastFullscreenError: FullscreenError | null;
|
|
685
|
+
enterFullscreen: () => void;
|
|
686
|
+
exitFullscreen: () => void;
|
|
687
|
+
toggleFullscreen: () => void;
|
|
688
|
+
}
|
|
689
|
+
declare function useFullscreen(): FullscreenContextValue;
|
|
690
|
+
interface FullscreenProviderOptions {
|
|
691
|
+
/** localStorage key to persist user preference */
|
|
692
|
+
storageKey?: string;
|
|
693
|
+
/** Auto-restore fullscreen preference on mount */
|
|
694
|
+
persistPreference?: boolean;
|
|
695
|
+
}
|
|
696
|
+
declare function FullscreenProvider({ children, options, }: {
|
|
697
|
+
children: ReactNode;
|
|
698
|
+
options?: FullscreenProviderOptions;
|
|
699
|
+
}): react.JSX.Element;
|
|
700
|
+
|
|
701
|
+
export { type Accelerometer, type BackButton, type BiometricAuthenticateParams, type BiometricManager, type BiometricRequestAccessParams, type BottomButton, type BottomButtonParams, type ChatAdministratorRights, type CloudStorage, type DeviceOrientation, type DownloadFileParams, type EmojiStatusParams, FullscreenProvider, type FullscreenProviderOptions, type Gyroscope, type HapticFeedback, type Language, type LocationData, type LocationManager, type MainButton, type PopupButton, type PopupParams, RTL_LANGS, type RequestChatParams, SUPPORTED_LANGS, type SafeAreaInset, type ScanQrPopupParams, type SecondaryButton, type SettingsButton, type StoryShareParams, type TelegramContextValue, TelegramProvider, type TelegramProviderOptions, type TgThemeParams, type TgUser, type TgWebApp, type WebAppEventType, biometric, cloudStorage, dialog, getRawUserData, getUserAvatarUrl, getUserDisplayName, getUserIdentifier, getUserInfoWithAvatar, getWebApp, haptic, isInTelegram, isRtlLang, isVersionAtLeast, location, openExternalLink, openInvoice, openTelegramLink, readClipboard, scanQr, tgLangToTmdb, tgLangToUi, useAccelerometer, useBiometric, useCloudStorage, useDeviceOrientation, useFullscreen, useGyroscope, useHapticFeedback, useHomeScreen, useIsActive, useLocation, useSafeArea, useTelegram, useTelegramBackButton, useTelegramEvent, useTelegramFullscreen, useTelegramMainButton, useTelegramSecondaryButton, useTelegramSettingsButton, useTelegramStartParam, useTelegramTheme, useTelegramUser, useTelegramViewport, useTelegramWebApp };
|