@core-ease/telegram-kit 3.0.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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +299 -0
  3. package/dist/animation/index.d.mts +4 -0
  4. package/dist/animation/index.d.ts +4 -0
  5. package/dist/animation/index.js +2413 -0
  6. package/dist/animation/index.mjs +5 -0
  7. package/dist/animation/lottie/index.d.mts +10 -0
  8. package/dist/animation/lottie/index.d.ts +10 -0
  9. package/dist/animation/lottie/index.js +2313 -0
  10. package/dist/animation/lottie/index.mjs +4 -0
  11. package/dist/animation/tgs/index.d.mts +18 -0
  12. package/dist/animation/tgs/index.d.ts +18 -0
  13. package/dist/animation/tgs/index.js +2402 -0
  14. package/dist/animation/tgs/index.mjs +4 -0
  15. package/dist/bot/index.d.mts +477 -0
  16. package/dist/bot/index.d.ts +477 -0
  17. package/dist/bot/index.js +870 -0
  18. package/dist/bot/index.mjs +847 -0
  19. package/dist/bot-D8BnLWIi.d.mts +2041 -0
  20. package/dist/bot-D8BnLWIi.d.ts +2041 -0
  21. package/dist/browser.global.js +23 -0
  22. package/dist/chunk-7AARTHNW.mjs +40 -0
  23. package/dist/chunk-7CVYPKAL.mjs +15 -0
  24. package/dist/chunk-B3PWALX5.mjs +4418 -0
  25. package/dist/chunk-BQEUEAVK.mjs +2262 -0
  26. package/dist/chunk-FPWYSKK2.mjs +3089 -0
  27. package/dist/chunk-JXK5HCDV.mjs +254 -0
  28. package/dist/chunk-OMH2JGOH.mjs +88 -0
  29. package/dist/chunk-PXO36YTU.mjs +38 -0
  30. package/dist/core/index.d.mts +151 -0
  31. package/dist/core/index.d.ts +151 -0
  32. package/dist/core/index.js +3837 -0
  33. package/dist/core/index.mjs +495 -0
  34. package/dist/dev/index.d.mts +77 -0
  35. package/dist/dev/index.d.ts +77 -0
  36. package/dist/dev/index.js +3214 -0
  37. package/dist/dev/index.mjs +151 -0
  38. package/dist/engine-BDm1_hzn.d.mts +382 -0
  39. package/dist/engine-BDm1_hzn.d.ts +382 -0
  40. package/dist/format/index.d.mts +61 -0
  41. package/dist/format/index.d.ts +61 -0
  42. package/dist/format/index.js +121 -0
  43. package/dist/format/index.mjs +112 -0
  44. package/dist/hooks/index.d.mts +1 -0
  45. package/dist/hooks/index.d.ts +1 -0
  46. package/dist/hooks/index.js +4234 -0
  47. package/dist/hooks/index.mjs +3 -0
  48. package/dist/hooks-C5Per70R.d.mts +1066 -0
  49. package/dist/hooks-C5Per70R.d.ts +1066 -0
  50. package/dist/index.d.mts +849 -0
  51. package/dist/index.d.ts +849 -0
  52. package/dist/index.js +5026 -0
  53. package/dist/index.mjs +478 -0
  54. package/dist/keyboards/index.d.mts +50 -0
  55. package/dist/keyboards/index.d.ts +50 -0
  56. package/dist/keyboards/index.js +127 -0
  57. package/dist/keyboards/index.mjs +124 -0
  58. package/dist/links/index.d.mts +53 -0
  59. package/dist/links/index.d.ts +53 -0
  60. package/dist/links/index.js +139 -0
  61. package/dist/links/index.mjs +133 -0
  62. package/dist/lottie/index.d.mts +3 -0
  63. package/dist/lottie/index.d.ts +3 -0
  64. package/dist/lottie/index.js +2313 -0
  65. package/dist/lottie/index.mjs +4 -0
  66. package/dist/qr/index.d.mts +75 -0
  67. package/dist/qr/index.d.ts +75 -0
  68. package/dist/qr/index.js +983 -0
  69. package/dist/qr/index.mjs +946 -0
  70. package/dist/sdk/index.d.mts +322 -0
  71. package/dist/sdk/index.d.ts +322 -0
  72. package/dist/sdk/index.js +3138 -0
  73. package/dist/sdk/index.mjs +2 -0
  74. package/dist/server/index.d.mts +28 -0
  75. package/dist/server/index.d.ts +28 -0
  76. package/dist/server/index.js +254 -0
  77. package/dist/server/index.mjs +246 -0
  78. package/dist/tgs/index.d.mts +3 -0
  79. package/dist/tgs/index.d.ts +3 -0
  80. package/dist/tgs/index.js +2402 -0
  81. package/dist/tgs/index.mjs +4 -0
  82. package/dist/webapp-B-3_74nK.d.mts +842 -0
  83. package/dist/webapp-B-3_74nK.d.ts +842 -0
  84. package/dist/webapp-BDi9q3-a.d.mts +42 -0
  85. package/dist/webapp-YvmwFYUQ.d.ts +42 -0
  86. package/package.json +165 -0
@@ -0,0 +1,322 @@
1
+ import { b as WebAppKernel, c as SafeAreaInset, P as PopupParams, d as ScanQrPopupParams, e as HomeScreenStatus, D as DownloadFileParams, S as ShareToStoryParams, I as InitParams, O as OpenLinkOptions, f as OpenTelegramLinkOptions, g as TelegramWebView, a as WebApp } from '../webapp-B-3_74nK.mjs';
2
+ export { A as Accelerometer, h as AnyRecord, B as BackButton, i as BiometricAuthenticateParams, j as BiometricManager, k as BiometricRequestAccessParams, l as BiometricType, m as BottomButton, n as BottomButtonParams, o as BottomButtonPosition, p as CloseOptions, q as CloudStorage, C as ColorScheme, r as DebugBottomBar, s as DefaultColors, t as DeviceOrientation, u as DeviceOrientationStartParams, v as DeviceStorage, E as ErrCallback, w as EventHandler, G as Gyroscope, H as HapticFeedback, x as HapticImpactStyle, y as HapticNotificationType, z as ItemsCallback, L as LocationData, F as LocationManager, M as MotionSensorStartParams, J as PopupButton, K as PopupButtonType, N as SecureStorage, Q as SettingsButton, R as ShareToStoryWidgetLink, U as ThemeManager, T as ThemeParams, V as Utils, X as VoidCallback, Y as WebAppChat, Z as WebAppInitDataUnsafe, W as WebAppUser } from '../webapp-B-3_74nK.mjs';
3
+
4
+ /**
5
+ * The original SDK throws plain `Error('SomeName')` objects. We keep the
6
+ * exact same string names (so existing error-handling code that matches on
7
+ * `error.message` keeps working) but expose them as a typed enum plus a
8
+ * small helper so call sites read better than magic strings.
9
+ */
10
+ declare enum WebAppErrorName {
11
+ MethodUnsupported = "WebAppMethodUnsupported",
12
+ DataInvalid = "WebAppDataInvalid",
13
+ InlineModeDisabled = "WebAppInlineModeDisabled",
14
+ InlineQueryInvalid = "WebAppInlineQueryInvalid",
15
+ InlineChooseChatTypesInvalid = "WebAppInlineChooseChatTypesInvalid",
16
+ InlineChooseChatTypeInvalid = "WebAppInlineChooseChatTypeInvalid",
17
+ TgUrlInvalid = "WebAppTgUrlInvalid",
18
+ InvoiceUrlInvalid = "WebAppInvoiceUrlInvalid",
19
+ InvoiceOpened = "WebAppInvoiceOpened",
20
+ PopupOpened = "WebAppPopupOpened",
21
+ PopupParamInvalid = "WebAppPopupParamInvalid",
22
+ ScanQrPopupOpened = "WebAppScanQrPopupOpened",
23
+ ScanQrPopupParamInvalid = "WebAppScanQrPopupParamInvalid",
24
+ WriteAccessRequested = "WebAppWriteAccessRequested",
25
+ ContactRequested = "WebAppContactRequested",
26
+ DownloadFilePopupOpened = "WebAppDownloadFilePopupOpened",
27
+ DownloadFileParamInvalid = "WebAppDownloadFileParamInvalid",
28
+ MediaUrlInvalid = "WebAppMediaUrlInvalid",
29
+ ShareToStoryParamInvalid = "WebAppShareToStoryParamInvalid",
30
+ ShareMessageOpened = "WebAppShareMessageOpened",
31
+ RequestChatOpened = "WebAppRequestChatOpened",
32
+ EmojiStatusRequested = "WebAppEmojiStatusRequested",
33
+ EmojiStatusAccessRequested = "WebAppEmojiStatusAccessRequested",
34
+ HeaderColorInvalid = "WebAppHeaderColorInvalid",
35
+ HeaderColorKeyInvalid = "WebAppHeaderColorKeyInvalid",
36
+ BackgroundColorInvalid = "WebAppBackgroundColorInvalid",
37
+ BottomBarColorInvalid = "WebAppBottomBarColorInvalid",
38
+ BottomButtonParamInvalid = "WebAppBottomButtonParamInvalid",
39
+ HapticImpactStyleInvalid = "WebAppHapticImpactStyleInvalid",
40
+ HapticNotificationTypeInvalid = "WebAppHapticNotificationTypeInvalid",
41
+ HapticFeedbackTypeInvalid = "WebAppHapticFeedbackTypeInvalid",
42
+ BiometricManagerNotInited = "WebAppBiometricManagerNotInited",
43
+ BiometricManagerBiometricsNotAvailable = "WebAppBiometricManagerBiometricsNotAvailable",
44
+ BiometricManagerAccessRequested = "WebAppBiometricManagerAccessRequested",
45
+ BiometricManagerBiometricAccessNotGranted = "WebAppBiometricManagerBiometricAccessNotGranted",
46
+ BiometricManagerAuthenticationRequested = "WebAppBiometricManagerAuthenticationRequested",
47
+ BiometricManagerTokenInvalid = "WebAppBiometricManagerTokenInvalid",
48
+ BiometricManagerTokenUpdateRequested = "WebAppBiometricManagerTokenUpdateRequested",
49
+ BiometricManagerBiometricsAccessNotRequested = "WebAppBiometricManagerBiometricsAccessNotRequested",
50
+ BiometricRequestAccessParamInvalid = "WebAppBiometricRequestAccessParamInvalid",
51
+ LocationManagerNotInited = "WebAppLocationManagerNotInited",
52
+ LocationManagerLocationNotAvailable = "WebAppLocationManagerLocationNotAvailable",
53
+ LocationManagerLocationAccessNotRequested = "WebAppLocationManagerLocationAccessNotRequested",
54
+ CallbackIdGenerateFailed = "WebAppCallbackIdGenerateFailed"
55
+ }
56
+ declare class WebAppError extends Error {
57
+ constructor(name: WebAppErrorName);
58
+ }
59
+
60
+ /**
61
+ * Viewport & window-chrome manager.
62
+ *
63
+ * Covers everything related to the app's visible area and window behavior:
64
+ * viewport height/expansion, safe-area insets, fullscreen state,
65
+ * orientation lock, the closing confirmation dialog and vertical swipe
66
+ * toggling. All of it was interleaved with theme code in the original
67
+ * single closure; split out here since it is a clearly separate concern.
68
+ */
69
+
70
+ declare class ViewportManager {
71
+ private readonly kernel;
72
+ private viewportHeightPx;
73
+ private viewportStableHeightPx;
74
+ private _isExpanded;
75
+ private _safeAreaInset;
76
+ private _contentSafeAreaInset;
77
+ private _isFullscreen;
78
+ private _isOrientationLocked;
79
+ private _isClosingConfirmationEnabled;
80
+ private _isVerticalSwipesEnabled;
81
+ private lastWindowHeight;
82
+ constructor(kernel: WebAppKernel);
83
+ get isExpanded(): boolean;
84
+ get viewportHeight(): number;
85
+ get viewportStableHeight(): number;
86
+ get safeAreaInset(): SafeAreaInset;
87
+ get contentSafeAreaInset(): SafeAreaInset;
88
+ get isFullscreen(): boolean;
89
+ get isOrientationLocked(): boolean;
90
+ get isClosingConfirmationEnabled(): boolean;
91
+ get isVerticalSwipesEnabled(): boolean;
92
+ /** Re-applies the current viewport CSS vars; call after bottom-bar height changes too. */
93
+ setViewportHeight(data?: {
94
+ height: number;
95
+ is_expanded?: boolean;
96
+ is_state_stable?: boolean;
97
+ }): void;
98
+ handleViewportChanged: (_eventType: string, eventData: any) => void;
99
+ onWindowResize(): void;
100
+ setSafeAreaInset(data?: Partial<SafeAreaInset>): void;
101
+ handleSafeAreaChanged: (_eventType: string, eventData: any) => void;
102
+ setContentSafeAreaInset(data?: Partial<SafeAreaInset>): void;
103
+ handleContentSafeAreaChanged: (_eventType: string, eventData: any) => void;
104
+ setClosingConfirmation(needConfirmation: boolean): void;
105
+ toggleVerticalSwipes(enableSwipes: boolean): void;
106
+ private setFullscreen;
107
+ handleFullscreenChanged: (_eventType: string, eventData: any) => void;
108
+ handleFullscreenFailed: (_eventType: string, eventData: any) => void;
109
+ requestFullscreen(): void;
110
+ exitFullscreen(): void;
111
+ private setOrientationLock;
112
+ toggleOrientationLock(locked: boolean): void;
113
+ }
114
+
115
+ /**
116
+ * `WebApp.showPopup` / `showAlert` / `showConfirm`.
117
+ */
118
+
119
+ type PopupCallback = (buttonId: string | null) => void;
120
+ type AlertCallback = () => void;
121
+ type ConfirmCallback = (ok: boolean) => void;
122
+ declare class PopupManager {
123
+ private readonly kernel;
124
+ private pending;
125
+ constructor(kernel: WebAppKernel);
126
+ private handlePopupClosed;
127
+ showPopup(params: PopupParams, callback?: PopupCallback): void;
128
+ showAlert(message: string, callback?: AlertCallback): void;
129
+ showConfirm(message: string, callback?: ConfirmCallback): void;
130
+ }
131
+
132
+ /**
133
+ * `WebApp.showScanQrPopup` / `closeScanQrPopup`.
134
+ */
135
+
136
+ /** Return `true` from the callback to close the popup automatically. */
137
+ type ScanQrCallback = (data: string | null) => boolean | void;
138
+ declare class ScanQrManager {
139
+ private readonly kernel;
140
+ private pending;
141
+ constructor(kernel: WebAppKernel);
142
+ private handleQrTextReceived;
143
+ private handleScanQrPopupClosed;
144
+ showScanQrPopup(params: ScanQrPopupParams, callback?: ScanQrCallback): void;
145
+ closeScanQrPopup(): void;
146
+ }
147
+
148
+ /**
149
+ * `WebApp.openInvoice`.
150
+ */
151
+
152
+ type InvoiceStatus = 'paid' | 'cancelled' | 'failed' | 'pending';
153
+ type InvoiceCallback = (status: InvoiceStatus) => void;
154
+ declare class InvoiceManager {
155
+ private readonly kernel;
156
+ private openInvoices;
157
+ constructor(kernel: WebAppKernel);
158
+ private handleInvoiceClosed;
159
+ openInvoice(url: string, callback?: InvoiceCallback): void;
160
+ }
161
+
162
+ /**
163
+ * `WebApp.readTextFromClipboard`.
164
+ */
165
+
166
+ type ClipboardCallback = (data: string | null) => void;
167
+ declare class ClipboardManager {
168
+ private readonly kernel;
169
+ constructor(kernel: WebAppKernel);
170
+ private handleClipboardTextReceived;
171
+ readTextFromClipboard(callback?: ClipboardCallback): void;
172
+ }
173
+
174
+ /**
175
+ * `WebApp.requestWriteAccess` / `WebApp.requestContact`.
176
+ */
177
+
178
+ type WriteAccessCallback = (granted: boolean) => void;
179
+ type ContactCallback = (sent: boolean, eventPayload: Record<string, any>) => void;
180
+ declare class ContactManager {
181
+ private readonly kernel;
182
+ private writeAccessRequested;
183
+ private contactRequested;
184
+ constructor(kernel: WebAppKernel);
185
+ private handleWriteAccessRequested;
186
+ private handlePhoneRequested;
187
+ requestWriteAccess(callback?: WriteAccessCallback): void;
188
+ requestContact(callback?: ContactCallback): void;
189
+ }
190
+
191
+ /**
192
+ * `WebApp.addToHomeScreen` / `WebApp.checkHomeScreenStatus`.
193
+ */
194
+
195
+ type StatusCallback = (status: HomeScreenStatus) => void;
196
+ declare class HomeScreenManager {
197
+ private readonly kernel;
198
+ private statusCallbacks;
199
+ constructor(kernel: WebAppKernel);
200
+ private handleAdded;
201
+ private handleChecked;
202
+ addToHomeScreen(): void;
203
+ checkHomeScreenStatus(callback?: StatusCallback): void;
204
+ }
205
+
206
+ /**
207
+ * `WebApp.downloadFile`.
208
+ */
209
+
210
+ type DownloadCallback = (isDownloading: boolean) => void;
211
+ declare class DownloadFileManager {
212
+ private readonly kernel;
213
+ private requested;
214
+ constructor(kernel: WebAppKernel);
215
+ private handleFileDownloadRequested;
216
+ downloadFile(params: DownloadFileParams, callback?: DownloadCallback): void;
217
+ }
218
+
219
+ /**
220
+ * Sharing-related surface: `shareToStory`, `shareMessage`, `requestChat`,
221
+ * `switchInlineQuery`.
222
+ */
223
+
224
+ type SentCallback = (sent: boolean) => void;
225
+ declare class SharingManager {
226
+ private readonly kernel;
227
+ private shareMessageOpened;
228
+ private requestChatOpened;
229
+ constructor(kernel: WebAppKernel);
230
+ private handlePreparedMessageSent;
231
+ private handlePreparedMessageFailed;
232
+ private handleRequestedChatSent;
233
+ private handleRequestedChatFailed;
234
+ shareToStory(mediaUrl: string, params?: ShareToStoryParams): void;
235
+ shareMessage(msgId: string, callback?: SentCallback): void;
236
+ requestChat(reqId: string, callback?: SentCallback): void;
237
+ switchInlineQuery(query: string, chooseChatTypes: string[] | undefined, initParams: InitParams): void;
238
+ }
239
+
240
+ /**
241
+ * `WebApp.setEmojiStatus` / `WebApp.requestEmojiStatusAccess`.
242
+ */
243
+
244
+ type SetStatusCallback = (applied: boolean) => void;
245
+ type AccessCallback = (granted: boolean) => void;
246
+ declare class EmojiStatusManager {
247
+ private readonly kernel;
248
+ private setRequested;
249
+ private accessRequested;
250
+ constructor(kernel: WebAppKernel);
251
+ private handleSet;
252
+ private handleFailed;
253
+ private handleAccessRequested;
254
+ setEmojiStatus(customEmojiId: string, params?: {
255
+ duration?: number;
256
+ }, callback?: SetStatusCallback): void;
257
+ requestEmojiStatusAccess(callback?: AccessCallback): void;
258
+ }
259
+
260
+ /**
261
+ * `WebApp.openLink` / `WebApp.openTelegramLink` + the iframe `<a href="t.me/...">`
262
+ * click interception (`linkHandler` in the original script).
263
+ */
264
+
265
+ declare class LinkManager {
266
+ private readonly kernel;
267
+ constructor(kernel: WebAppKernel);
268
+ openLink(url: string, options?: OpenLinkOptions): void;
269
+ openTelegramLink(url: string, options?: OpenTelegramLinkOptions): void;
270
+ /**
271
+ * Intercepts clicks on in-page `t.me` links while running inside an
272
+ * iframe (web.telegram.org) and routes them through `openTelegramLink`
273
+ * instead of letting the browser navigate directly.
274
+ */
275
+ handleDocumentClick: (e: MouseEvent) => void;
276
+ }
277
+
278
+ /**
279
+ * `@core-ease/telegram-kit/sdk` - public entry point of the bundled Mini
280
+ * Apps SDK.
281
+ *
282
+ * Everything that actually implements the protocol lives under
283
+ * `./_internal/` (transport, kernel, theme, ui, features, sensors) and is
284
+ * considered an implementation detail - import from here, not from
285
+ * `./_internal/*` directly.
286
+ *
287
+ * Calling {@link bootstrapTelegramWebApp} reproduces exactly what the
288
+ * original `telegram-web-app.js` did when loaded as a `<script>` tag:
289
+ * 1. Set up `window.Telegram.WebView` (transport + event bus) and
290
+ * `window.Telegram.Utils`.
291
+ * 2. Set up `window.Telegram.WebApp` (the full public API).
292
+ *
293
+ * Unlike the very first version of this SDK, bootstrapping is **lazy**
294
+ * (it does not run automatically just from importing this module). This
295
+ * lets `core/dev.ts` seed fake init data into session storage *before* the
296
+ * bridge is constructed, so local/dev-mode "just works" through the exact
297
+ * same code path as running inside real Telegram - no parallel mock
298
+ * implementation needed. In practice you never have to think about this:
299
+ * `getWebApp()` in `core/index.ts` calls {@link bootstrapTelegramWebApp}
300
+ * for you on first use.
301
+ */
302
+
303
+ declare const SDK_NAME = "@core-ease/telegram-kit";
304
+ /**
305
+ * Runs the SDK bootstrap exactly once (idempotent) and exposes
306
+ * `window.Telegram.{WebView,Utils,WebApp}`. Safe to call in non-browser
307
+ * contexts (returns nothing useful but never throws), so it's safe to wire
308
+ * into SSR code paths.
309
+ *
310
+ * This is normally called for you by `getWebApp()` in `core/index.ts` the
311
+ * first time any @core-ease/telegram-kit function is used - you only need to call it
312
+ * yourself if you want direct, typed access to the `WebApp`/`TelegramWebView`
313
+ * instances instead of going through the `core`/`hooks` convenience layer.
314
+ */
315
+ declare function bootstrapTelegramWebApp(): {
316
+ webView: TelegramWebView;
317
+ webApp: WebApp;
318
+ };
319
+ /** True once {@link bootstrapTelegramWebApp} has run at least once. */
320
+ declare function isBootstrapped(): boolean;
321
+
322
+ export { ClipboardManager, ContactManager, DownloadFileManager, DownloadFileParams, EmojiStatusManager, HomeScreenManager, HomeScreenStatus, InitParams, InvoiceManager, LinkManager, OpenLinkOptions, OpenTelegramLinkOptions, PopupManager, PopupParams, SDK_NAME, SafeAreaInset, ScanQrManager, ScanQrPopupParams, ShareToStoryParams, SharingManager, TelegramWebView, ViewportManager, WebApp, WebAppError, WebAppErrorName, WebAppKernel, bootstrapTelegramWebApp, isBootstrapped };
@@ -0,0 +1,322 @@
1
+ import { b as WebAppKernel, c as SafeAreaInset, P as PopupParams, d as ScanQrPopupParams, e as HomeScreenStatus, D as DownloadFileParams, S as ShareToStoryParams, I as InitParams, O as OpenLinkOptions, f as OpenTelegramLinkOptions, g as TelegramWebView, a as WebApp } from '../webapp-B-3_74nK.js';
2
+ export { A as Accelerometer, h as AnyRecord, B as BackButton, i as BiometricAuthenticateParams, j as BiometricManager, k as BiometricRequestAccessParams, l as BiometricType, m as BottomButton, n as BottomButtonParams, o as BottomButtonPosition, p as CloseOptions, q as CloudStorage, C as ColorScheme, r as DebugBottomBar, s as DefaultColors, t as DeviceOrientation, u as DeviceOrientationStartParams, v as DeviceStorage, E as ErrCallback, w as EventHandler, G as Gyroscope, H as HapticFeedback, x as HapticImpactStyle, y as HapticNotificationType, z as ItemsCallback, L as LocationData, F as LocationManager, M as MotionSensorStartParams, J as PopupButton, K as PopupButtonType, N as SecureStorage, Q as SettingsButton, R as ShareToStoryWidgetLink, U as ThemeManager, T as ThemeParams, V as Utils, X as VoidCallback, Y as WebAppChat, Z as WebAppInitDataUnsafe, W as WebAppUser } from '../webapp-B-3_74nK.js';
3
+
4
+ /**
5
+ * The original SDK throws plain `Error('SomeName')` objects. We keep the
6
+ * exact same string names (so existing error-handling code that matches on
7
+ * `error.message` keeps working) but expose them as a typed enum plus a
8
+ * small helper so call sites read better than magic strings.
9
+ */
10
+ declare enum WebAppErrorName {
11
+ MethodUnsupported = "WebAppMethodUnsupported",
12
+ DataInvalid = "WebAppDataInvalid",
13
+ InlineModeDisabled = "WebAppInlineModeDisabled",
14
+ InlineQueryInvalid = "WebAppInlineQueryInvalid",
15
+ InlineChooseChatTypesInvalid = "WebAppInlineChooseChatTypesInvalid",
16
+ InlineChooseChatTypeInvalid = "WebAppInlineChooseChatTypeInvalid",
17
+ TgUrlInvalid = "WebAppTgUrlInvalid",
18
+ InvoiceUrlInvalid = "WebAppInvoiceUrlInvalid",
19
+ InvoiceOpened = "WebAppInvoiceOpened",
20
+ PopupOpened = "WebAppPopupOpened",
21
+ PopupParamInvalid = "WebAppPopupParamInvalid",
22
+ ScanQrPopupOpened = "WebAppScanQrPopupOpened",
23
+ ScanQrPopupParamInvalid = "WebAppScanQrPopupParamInvalid",
24
+ WriteAccessRequested = "WebAppWriteAccessRequested",
25
+ ContactRequested = "WebAppContactRequested",
26
+ DownloadFilePopupOpened = "WebAppDownloadFilePopupOpened",
27
+ DownloadFileParamInvalid = "WebAppDownloadFileParamInvalid",
28
+ MediaUrlInvalid = "WebAppMediaUrlInvalid",
29
+ ShareToStoryParamInvalid = "WebAppShareToStoryParamInvalid",
30
+ ShareMessageOpened = "WebAppShareMessageOpened",
31
+ RequestChatOpened = "WebAppRequestChatOpened",
32
+ EmojiStatusRequested = "WebAppEmojiStatusRequested",
33
+ EmojiStatusAccessRequested = "WebAppEmojiStatusAccessRequested",
34
+ HeaderColorInvalid = "WebAppHeaderColorInvalid",
35
+ HeaderColorKeyInvalid = "WebAppHeaderColorKeyInvalid",
36
+ BackgroundColorInvalid = "WebAppBackgroundColorInvalid",
37
+ BottomBarColorInvalid = "WebAppBottomBarColorInvalid",
38
+ BottomButtonParamInvalid = "WebAppBottomButtonParamInvalid",
39
+ HapticImpactStyleInvalid = "WebAppHapticImpactStyleInvalid",
40
+ HapticNotificationTypeInvalid = "WebAppHapticNotificationTypeInvalid",
41
+ HapticFeedbackTypeInvalid = "WebAppHapticFeedbackTypeInvalid",
42
+ BiometricManagerNotInited = "WebAppBiometricManagerNotInited",
43
+ BiometricManagerBiometricsNotAvailable = "WebAppBiometricManagerBiometricsNotAvailable",
44
+ BiometricManagerAccessRequested = "WebAppBiometricManagerAccessRequested",
45
+ BiometricManagerBiometricAccessNotGranted = "WebAppBiometricManagerBiometricAccessNotGranted",
46
+ BiometricManagerAuthenticationRequested = "WebAppBiometricManagerAuthenticationRequested",
47
+ BiometricManagerTokenInvalid = "WebAppBiometricManagerTokenInvalid",
48
+ BiometricManagerTokenUpdateRequested = "WebAppBiometricManagerTokenUpdateRequested",
49
+ BiometricManagerBiometricsAccessNotRequested = "WebAppBiometricManagerBiometricsAccessNotRequested",
50
+ BiometricRequestAccessParamInvalid = "WebAppBiometricRequestAccessParamInvalid",
51
+ LocationManagerNotInited = "WebAppLocationManagerNotInited",
52
+ LocationManagerLocationNotAvailable = "WebAppLocationManagerLocationNotAvailable",
53
+ LocationManagerLocationAccessNotRequested = "WebAppLocationManagerLocationAccessNotRequested",
54
+ CallbackIdGenerateFailed = "WebAppCallbackIdGenerateFailed"
55
+ }
56
+ declare class WebAppError extends Error {
57
+ constructor(name: WebAppErrorName);
58
+ }
59
+
60
+ /**
61
+ * Viewport & window-chrome manager.
62
+ *
63
+ * Covers everything related to the app's visible area and window behavior:
64
+ * viewport height/expansion, safe-area insets, fullscreen state,
65
+ * orientation lock, the closing confirmation dialog and vertical swipe
66
+ * toggling. All of it was interleaved with theme code in the original
67
+ * single closure; split out here since it is a clearly separate concern.
68
+ */
69
+
70
+ declare class ViewportManager {
71
+ private readonly kernel;
72
+ private viewportHeightPx;
73
+ private viewportStableHeightPx;
74
+ private _isExpanded;
75
+ private _safeAreaInset;
76
+ private _contentSafeAreaInset;
77
+ private _isFullscreen;
78
+ private _isOrientationLocked;
79
+ private _isClosingConfirmationEnabled;
80
+ private _isVerticalSwipesEnabled;
81
+ private lastWindowHeight;
82
+ constructor(kernel: WebAppKernel);
83
+ get isExpanded(): boolean;
84
+ get viewportHeight(): number;
85
+ get viewportStableHeight(): number;
86
+ get safeAreaInset(): SafeAreaInset;
87
+ get contentSafeAreaInset(): SafeAreaInset;
88
+ get isFullscreen(): boolean;
89
+ get isOrientationLocked(): boolean;
90
+ get isClosingConfirmationEnabled(): boolean;
91
+ get isVerticalSwipesEnabled(): boolean;
92
+ /** Re-applies the current viewport CSS vars; call after bottom-bar height changes too. */
93
+ setViewportHeight(data?: {
94
+ height: number;
95
+ is_expanded?: boolean;
96
+ is_state_stable?: boolean;
97
+ }): void;
98
+ handleViewportChanged: (_eventType: string, eventData: any) => void;
99
+ onWindowResize(): void;
100
+ setSafeAreaInset(data?: Partial<SafeAreaInset>): void;
101
+ handleSafeAreaChanged: (_eventType: string, eventData: any) => void;
102
+ setContentSafeAreaInset(data?: Partial<SafeAreaInset>): void;
103
+ handleContentSafeAreaChanged: (_eventType: string, eventData: any) => void;
104
+ setClosingConfirmation(needConfirmation: boolean): void;
105
+ toggleVerticalSwipes(enableSwipes: boolean): void;
106
+ private setFullscreen;
107
+ handleFullscreenChanged: (_eventType: string, eventData: any) => void;
108
+ handleFullscreenFailed: (_eventType: string, eventData: any) => void;
109
+ requestFullscreen(): void;
110
+ exitFullscreen(): void;
111
+ private setOrientationLock;
112
+ toggleOrientationLock(locked: boolean): void;
113
+ }
114
+
115
+ /**
116
+ * `WebApp.showPopup` / `showAlert` / `showConfirm`.
117
+ */
118
+
119
+ type PopupCallback = (buttonId: string | null) => void;
120
+ type AlertCallback = () => void;
121
+ type ConfirmCallback = (ok: boolean) => void;
122
+ declare class PopupManager {
123
+ private readonly kernel;
124
+ private pending;
125
+ constructor(kernel: WebAppKernel);
126
+ private handlePopupClosed;
127
+ showPopup(params: PopupParams, callback?: PopupCallback): void;
128
+ showAlert(message: string, callback?: AlertCallback): void;
129
+ showConfirm(message: string, callback?: ConfirmCallback): void;
130
+ }
131
+
132
+ /**
133
+ * `WebApp.showScanQrPopup` / `closeScanQrPopup`.
134
+ */
135
+
136
+ /** Return `true` from the callback to close the popup automatically. */
137
+ type ScanQrCallback = (data: string | null) => boolean | void;
138
+ declare class ScanQrManager {
139
+ private readonly kernel;
140
+ private pending;
141
+ constructor(kernel: WebAppKernel);
142
+ private handleQrTextReceived;
143
+ private handleScanQrPopupClosed;
144
+ showScanQrPopup(params: ScanQrPopupParams, callback?: ScanQrCallback): void;
145
+ closeScanQrPopup(): void;
146
+ }
147
+
148
+ /**
149
+ * `WebApp.openInvoice`.
150
+ */
151
+
152
+ type InvoiceStatus = 'paid' | 'cancelled' | 'failed' | 'pending';
153
+ type InvoiceCallback = (status: InvoiceStatus) => void;
154
+ declare class InvoiceManager {
155
+ private readonly kernel;
156
+ private openInvoices;
157
+ constructor(kernel: WebAppKernel);
158
+ private handleInvoiceClosed;
159
+ openInvoice(url: string, callback?: InvoiceCallback): void;
160
+ }
161
+
162
+ /**
163
+ * `WebApp.readTextFromClipboard`.
164
+ */
165
+
166
+ type ClipboardCallback = (data: string | null) => void;
167
+ declare class ClipboardManager {
168
+ private readonly kernel;
169
+ constructor(kernel: WebAppKernel);
170
+ private handleClipboardTextReceived;
171
+ readTextFromClipboard(callback?: ClipboardCallback): void;
172
+ }
173
+
174
+ /**
175
+ * `WebApp.requestWriteAccess` / `WebApp.requestContact`.
176
+ */
177
+
178
+ type WriteAccessCallback = (granted: boolean) => void;
179
+ type ContactCallback = (sent: boolean, eventPayload: Record<string, any>) => void;
180
+ declare class ContactManager {
181
+ private readonly kernel;
182
+ private writeAccessRequested;
183
+ private contactRequested;
184
+ constructor(kernel: WebAppKernel);
185
+ private handleWriteAccessRequested;
186
+ private handlePhoneRequested;
187
+ requestWriteAccess(callback?: WriteAccessCallback): void;
188
+ requestContact(callback?: ContactCallback): void;
189
+ }
190
+
191
+ /**
192
+ * `WebApp.addToHomeScreen` / `WebApp.checkHomeScreenStatus`.
193
+ */
194
+
195
+ type StatusCallback = (status: HomeScreenStatus) => void;
196
+ declare class HomeScreenManager {
197
+ private readonly kernel;
198
+ private statusCallbacks;
199
+ constructor(kernel: WebAppKernel);
200
+ private handleAdded;
201
+ private handleChecked;
202
+ addToHomeScreen(): void;
203
+ checkHomeScreenStatus(callback?: StatusCallback): void;
204
+ }
205
+
206
+ /**
207
+ * `WebApp.downloadFile`.
208
+ */
209
+
210
+ type DownloadCallback = (isDownloading: boolean) => void;
211
+ declare class DownloadFileManager {
212
+ private readonly kernel;
213
+ private requested;
214
+ constructor(kernel: WebAppKernel);
215
+ private handleFileDownloadRequested;
216
+ downloadFile(params: DownloadFileParams, callback?: DownloadCallback): void;
217
+ }
218
+
219
+ /**
220
+ * Sharing-related surface: `shareToStory`, `shareMessage`, `requestChat`,
221
+ * `switchInlineQuery`.
222
+ */
223
+
224
+ type SentCallback = (sent: boolean) => void;
225
+ declare class SharingManager {
226
+ private readonly kernel;
227
+ private shareMessageOpened;
228
+ private requestChatOpened;
229
+ constructor(kernel: WebAppKernel);
230
+ private handlePreparedMessageSent;
231
+ private handlePreparedMessageFailed;
232
+ private handleRequestedChatSent;
233
+ private handleRequestedChatFailed;
234
+ shareToStory(mediaUrl: string, params?: ShareToStoryParams): void;
235
+ shareMessage(msgId: string, callback?: SentCallback): void;
236
+ requestChat(reqId: string, callback?: SentCallback): void;
237
+ switchInlineQuery(query: string, chooseChatTypes: string[] | undefined, initParams: InitParams): void;
238
+ }
239
+
240
+ /**
241
+ * `WebApp.setEmojiStatus` / `WebApp.requestEmojiStatusAccess`.
242
+ */
243
+
244
+ type SetStatusCallback = (applied: boolean) => void;
245
+ type AccessCallback = (granted: boolean) => void;
246
+ declare class EmojiStatusManager {
247
+ private readonly kernel;
248
+ private setRequested;
249
+ private accessRequested;
250
+ constructor(kernel: WebAppKernel);
251
+ private handleSet;
252
+ private handleFailed;
253
+ private handleAccessRequested;
254
+ setEmojiStatus(customEmojiId: string, params?: {
255
+ duration?: number;
256
+ }, callback?: SetStatusCallback): void;
257
+ requestEmojiStatusAccess(callback?: AccessCallback): void;
258
+ }
259
+
260
+ /**
261
+ * `WebApp.openLink` / `WebApp.openTelegramLink` + the iframe `<a href="t.me/...">`
262
+ * click interception (`linkHandler` in the original script).
263
+ */
264
+
265
+ declare class LinkManager {
266
+ private readonly kernel;
267
+ constructor(kernel: WebAppKernel);
268
+ openLink(url: string, options?: OpenLinkOptions): void;
269
+ openTelegramLink(url: string, options?: OpenTelegramLinkOptions): void;
270
+ /**
271
+ * Intercepts clicks on in-page `t.me` links while running inside an
272
+ * iframe (web.telegram.org) and routes them through `openTelegramLink`
273
+ * instead of letting the browser navigate directly.
274
+ */
275
+ handleDocumentClick: (e: MouseEvent) => void;
276
+ }
277
+
278
+ /**
279
+ * `@core-ease/telegram-kit/sdk` - public entry point of the bundled Mini
280
+ * Apps SDK.
281
+ *
282
+ * Everything that actually implements the protocol lives under
283
+ * `./_internal/` (transport, kernel, theme, ui, features, sensors) and is
284
+ * considered an implementation detail - import from here, not from
285
+ * `./_internal/*` directly.
286
+ *
287
+ * Calling {@link bootstrapTelegramWebApp} reproduces exactly what the
288
+ * original `telegram-web-app.js` did when loaded as a `<script>` tag:
289
+ * 1. Set up `window.Telegram.WebView` (transport + event bus) and
290
+ * `window.Telegram.Utils`.
291
+ * 2. Set up `window.Telegram.WebApp` (the full public API).
292
+ *
293
+ * Unlike the very first version of this SDK, bootstrapping is **lazy**
294
+ * (it does not run automatically just from importing this module). This
295
+ * lets `core/dev.ts` seed fake init data into session storage *before* the
296
+ * bridge is constructed, so local/dev-mode "just works" through the exact
297
+ * same code path as running inside real Telegram - no parallel mock
298
+ * implementation needed. In practice you never have to think about this:
299
+ * `getWebApp()` in `core/index.ts` calls {@link bootstrapTelegramWebApp}
300
+ * for you on first use.
301
+ */
302
+
303
+ declare const SDK_NAME = "@core-ease/telegram-kit";
304
+ /**
305
+ * Runs the SDK bootstrap exactly once (idempotent) and exposes
306
+ * `window.Telegram.{WebView,Utils,WebApp}`. Safe to call in non-browser
307
+ * contexts (returns nothing useful but never throws), so it's safe to wire
308
+ * into SSR code paths.
309
+ *
310
+ * This is normally called for you by `getWebApp()` in `core/index.ts` the
311
+ * first time any @core-ease/telegram-kit function is used - you only need to call it
312
+ * yourself if you want direct, typed access to the `WebApp`/`TelegramWebView`
313
+ * instances instead of going through the `core`/`hooks` convenience layer.
314
+ */
315
+ declare function bootstrapTelegramWebApp(): {
316
+ webView: TelegramWebView;
317
+ webApp: WebApp;
318
+ };
319
+ /** True once {@link bootstrapTelegramWebApp} has run at least once. */
320
+ declare function isBootstrapped(): boolean;
321
+
322
+ export { ClipboardManager, ContactManager, DownloadFileManager, DownloadFileParams, EmojiStatusManager, HomeScreenManager, HomeScreenStatus, InitParams, InvoiceManager, LinkManager, OpenLinkOptions, OpenTelegramLinkOptions, PopupManager, PopupParams, SDK_NAME, SafeAreaInset, ScanQrManager, ScanQrPopupParams, ShareToStoryParams, SharingManager, TelegramWebView, ViewportManager, WebApp, WebAppError, WebAppErrorName, WebAppKernel, bootstrapTelegramWebApp, isBootstrapped };