@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,495 @@
1
+ import { createLocalStorageFallback, callNativeOrFallback, safeInvoke, fullscreenFallback, orientationLockFallback, vibrateFallback, readClipboardFallback, scanQrFallback, shareTextFallback, downloadFileFallback, getLocationFallback, isDevModeActive } from '../chunk-JXK5HCDV.mjs';
2
+ export { safeInvoke } from '../chunk-JXK5HCDV.mjs';
3
+ import { bootstrapTelegramWebApp } from '../chunk-FPWYSKK2.mjs';
4
+ import '../chunk-7AARTHNW.mjs';
5
+
6
+ // src/core/index.ts
7
+ var cachedWebApp = null;
8
+ function getWebApp() {
9
+ if (typeof window === "undefined") return null;
10
+ if (!cachedWebApp) {
11
+ cachedWebApp = bootstrapTelegramWebApp().webApp;
12
+ }
13
+ return cachedWebApp;
14
+ }
15
+ function isInTelegram() {
16
+ const wa = getWebApp();
17
+ return Boolean(wa && wa.initData && wa.initData.length > 0);
18
+ }
19
+ function isVersionAtLeast(version) {
20
+ var _a, _b;
21
+ return (_b = (_a = getWebApp()) == null ? void 0 : _a.isVersionAtLeast(version)) != null ? _b : false;
22
+ }
23
+ function nativeReady(version) {
24
+ if (!isInTelegram()) return false;
25
+ if (isDevModeActive()) return false;
26
+ if (version && !isVersionAtLeast(version)) return false;
27
+ return true;
28
+ }
29
+ function getRawUserData() {
30
+ var _a, _b, _c;
31
+ return (_c = (_b = (_a = getWebApp()) == null ? void 0 : _a.initDataUnsafe) == null ? void 0 : _b.user) != null ? _c : null;
32
+ }
33
+ function getUserDisplayName(user) {
34
+ var _a, _b;
35
+ if (!user) return "User";
36
+ const fullName = `${(_a = user.first_name) != null ? _a : ""} ${(_b = user.last_name) != null ? _b : ""}`.trim();
37
+ if (fullName) return fullName;
38
+ if (user.username) return `@${user.username}`;
39
+ return `User_${user.id}`;
40
+ }
41
+ function getUserIdentifier(user) {
42
+ if (user == null ? void 0 : user.username) return user.username;
43
+ if (user == null ? void 0 : user.id) return String(user.id);
44
+ return "unknown";
45
+ }
46
+ function getUserAvatarUrl(user, fallback = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjNjY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZvbnQtc2l6ZT0iNDAiIGZpbGw9IndoaXRlIj4/PC90ZXh0Pjwvc3ZnPg==") {
47
+ var _a, _b;
48
+ if (user == null ? void 0 : user.photo_url) return user.photo_url;
49
+ if (user == null ? void 0 : user.id) {
50
+ const name = `${(_a = user.first_name) != null ? _a : ""} ${(_b = user.last_name) != null ? _b : ""}`.trim() || user.username || `user_${user.id}`;
51
+ const initials = name.split(/\s+/).slice(0, 2).map((part) => {
52
+ var _a2, _b2;
53
+ return (_b2 = (_a2 = part[0]) == null ? void 0 : _a2.toUpperCase()) != null ? _b2 : "";
54
+ }).join("");
55
+ const svg = `
56
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
57
+ <rect width="100%" height="100%" rx="50" fill="#4F46E5"/>
58
+ <text
59
+ x="50%"
60
+ y="50%"
61
+ dominant-baseline="middle"
62
+ text-anchor="middle"
63
+ font-family="Arial,sans-serif"
64
+ font-size="40"
65
+ font-weight="bold"
66
+ fill="white"
67
+ >
68
+ ${initials}
69
+ </text>
70
+ </svg>
71
+ `;
72
+ const base64 = typeof Buffer !== "undefined" ? Buffer.from(svg).toString("base64") : btoa(svg);
73
+ return `data:image/svg+xml;base64,${base64}`;
74
+ }
75
+ return fallback;
76
+ }
77
+ function getUserInfoWithAvatar() {
78
+ var _a;
79
+ const user = (_a = getRawUserData()) != null ? _a : void 0;
80
+ return {
81
+ user,
82
+ avatarUrl: getUserAvatarUrl(user),
83
+ displayName: getUserDisplayName(user),
84
+ identifier: getUserIdentifier(user)
85
+ };
86
+ }
87
+ function openExternalLink(url, tryInstantView = false) {
88
+ const wa = getWebApp();
89
+ if (!wa) {
90
+ if (typeof window !== "undefined") window.open(url, "_blank", "noopener");
91
+ return;
92
+ }
93
+ wa.openLink(url, { try_instant_view: tryInstantView });
94
+ }
95
+ function openTelegramLink(url) {
96
+ const wa = getWebApp();
97
+ if (!wa) {
98
+ if (typeof window !== "undefined") window.open(url, "_blank", "noopener");
99
+ return;
100
+ }
101
+ wa.openTelegramLink(url);
102
+ }
103
+ function openInvoice(url) {
104
+ return callNativeOrFallback({
105
+ ready: nativeReady("6.1"),
106
+ native: () => new Promise((resolve) => getWebApp().openInvoice(url, (status) => resolve(status))),
107
+ fallback: () => {
108
+ throw new Error("openInvoice requires the Telegram app (Bot API 6.1+).");
109
+ }
110
+ });
111
+ }
112
+ function switchInlineQuery(query, chooseChatTypes) {
113
+ if (!nativeReady("6.6")) return;
114
+ safeInvoke(() => getWebApp().switchInlineQuery(query, chooseChatTypes));
115
+ }
116
+ function hideKeyboard() {
117
+ safeInvoke(() => {
118
+ var _a;
119
+ return (_a = getWebApp()) == null ? void 0 : _a.hideKeyboard();
120
+ });
121
+ }
122
+ function getTheme() {
123
+ var _a, _b;
124
+ const wa = getWebApp();
125
+ return { colorScheme: (_a = wa == null ? void 0 : wa.colorScheme) != null ? _a : "dark", themeParams: (_b = wa == null ? void 0 : wa.themeParams) != null ? _b : {} };
126
+ }
127
+ function getViewport() {
128
+ var _a, _b, _c;
129
+ const wa = getWebApp();
130
+ return {
131
+ height: (_a = wa == null ? void 0 : wa.viewportHeight) != null ? _a : typeof window !== "undefined" ? window.innerHeight : 0,
132
+ stableHeight: (_b = wa == null ? void 0 : wa.viewportStableHeight) != null ? _b : typeof window !== "undefined" ? window.innerHeight : 0,
133
+ isExpanded: (_c = wa == null ? void 0 : wa.isExpanded) != null ? _c : true
134
+ };
135
+ }
136
+ function expand() {
137
+ safeInvoke(() => {
138
+ var _a;
139
+ return (_a = getWebApp()) == null ? void 0 : _a.expand();
140
+ });
141
+ }
142
+ function ready() {
143
+ safeInvoke(() => {
144
+ var _a;
145
+ return (_a = getWebApp()) == null ? void 0 : _a.ready();
146
+ });
147
+ }
148
+ function close() {
149
+ safeInvoke(() => {
150
+ var _a;
151
+ return (_a = getWebApp()) == null ? void 0 : _a.close();
152
+ });
153
+ }
154
+ var fullscreen = {
155
+ enter: () => {
156
+ if (nativeReady("8.0")) {
157
+ safeInvoke(() => getWebApp().requestFullscreen());
158
+ return Promise.resolve(true);
159
+ }
160
+ return fullscreenFallback(true);
161
+ },
162
+ exit: () => {
163
+ if (nativeReady("8.0")) {
164
+ safeInvoke(() => getWebApp().exitFullscreen());
165
+ return Promise.resolve(true);
166
+ }
167
+ return fullscreenFallback(false);
168
+ }
169
+ };
170
+ var orientation = {
171
+ lock: () => {
172
+ if (nativeReady("8.0")) {
173
+ safeInvoke(() => getWebApp().lockOrientation());
174
+ return Promise.resolve(true);
175
+ }
176
+ return orientationLockFallback(true);
177
+ },
178
+ unlock: () => {
179
+ if (nativeReady("8.0")) {
180
+ safeInvoke(() => getWebApp().unlockOrientation());
181
+ return Promise.resolve(true);
182
+ }
183
+ return orientationLockFallback(false);
184
+ }
185
+ };
186
+ function enableClosingConfirmation() {
187
+ safeInvoke(() => {
188
+ var _a;
189
+ return (_a = getWebApp()) == null ? void 0 : _a.enableClosingConfirmation();
190
+ });
191
+ }
192
+ function disableClosingConfirmation() {
193
+ safeInvoke(() => {
194
+ var _a;
195
+ return (_a = getWebApp()) == null ? void 0 : _a.disableClosingConfirmation();
196
+ });
197
+ }
198
+ function enableVerticalSwipes() {
199
+ safeInvoke(() => {
200
+ var _a;
201
+ return (_a = getWebApp()) == null ? void 0 : _a.enableVerticalSwipes();
202
+ });
203
+ }
204
+ function disableVerticalSwipes() {
205
+ safeInvoke(() => {
206
+ var _a;
207
+ return (_a = getWebApp()) == null ? void 0 : _a.disableVerticalSwipes();
208
+ });
209
+ }
210
+ function setHeaderColor(color) {
211
+ safeInvoke(() => {
212
+ var _a;
213
+ return (_a = getWebApp()) == null ? void 0 : _a.setHeaderColor(color);
214
+ });
215
+ }
216
+ function setBackgroundColor(color) {
217
+ safeInvoke(() => {
218
+ var _a;
219
+ return (_a = getWebApp()) == null ? void 0 : _a.setBackgroundColor(color);
220
+ });
221
+ }
222
+ function setBottomBarColor(color) {
223
+ safeInvoke(() => {
224
+ var _a;
225
+ return (_a = getWebApp()) == null ? void 0 : _a.setBottomBarColor(color);
226
+ });
227
+ }
228
+ function addToHomeScreen() {
229
+ if (!nativeReady("8.0")) return;
230
+ safeInvoke(() => getWebApp().addToHomeScreen());
231
+ }
232
+ function checkHomeScreenStatus() {
233
+ return callNativeOrFallback({
234
+ ready: nativeReady("8.0"),
235
+ native: () => new Promise((resolve) => getWebApp().checkHomeScreenStatus((status) => resolve(status))),
236
+ fallback: () => "unsupported"
237
+ });
238
+ }
239
+ var haptic = {
240
+ light: () => nativeReady("6.1") ? getWebApp().HapticFeedback.impactOccurred("light") : vibrateFallback("light"),
241
+ medium: () => nativeReady("6.1") ? getWebApp().HapticFeedback.impactOccurred("medium") : vibrateFallback("medium"),
242
+ heavy: () => nativeReady("6.1") ? getWebApp().HapticFeedback.impactOccurred("heavy") : vibrateFallback("heavy"),
243
+ rigid: () => nativeReady("6.1") ? getWebApp().HapticFeedback.impactOccurred("rigid") : vibrateFallback("rigid"),
244
+ soft: () => nativeReady("6.1") ? getWebApp().HapticFeedback.impactOccurred("soft") : vibrateFallback("soft"),
245
+ success: () => nativeReady("6.1") ? getWebApp().HapticFeedback.notificationOccurred("success") : vibrateFallback("success"),
246
+ warning: () => nativeReady("6.1") ? getWebApp().HapticFeedback.notificationOccurred("warning") : vibrateFallback("warning"),
247
+ error: () => nativeReady("6.1") ? getWebApp().HapticFeedback.notificationOccurred("error") : vibrateFallback("error"),
248
+ selection: () => nativeReady("6.1") ? getWebApp().HapticFeedback.selectionChanged() : vibrateFallback("selection")
249
+ };
250
+ var cloudStorageFallback = createLocalStorageFallback("cloud");
251
+ var deviceStorageFallback = createLocalStorageFallback("device");
252
+ var secureStorageFallback = createLocalStorageFallback("secure");
253
+ var cloudStorage = {
254
+ setItem: (key, value) => callNativeOrFallback({
255
+ ready: nativeReady("6.9"),
256
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.setItem(key, value, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
257
+ fallback: () => cloudStorageFallback.setItem(key, value)
258
+ }),
259
+ getItem: (key) => callNativeOrFallback({
260
+ ready: nativeReady("6.9"),
261
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.getItem(key, (e, v) => e ? reject(new Error(e)) : resolve(v))),
262
+ fallback: () => cloudStorageFallback.getItem(key)
263
+ }),
264
+ getItems: (keys) => callNativeOrFallback({
265
+ ready: nativeReady("6.9"),
266
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.getItems(keys, (e, v) => e ? reject(new Error(e)) : resolve(v != null ? v : {}))),
267
+ fallback: () => cloudStorageFallback.getItems(keys)
268
+ }),
269
+ removeItem: (key) => callNativeOrFallback({
270
+ ready: nativeReady("6.9"),
271
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.removeItem(key, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
272
+ fallback: () => cloudStorageFallback.removeItem(key)
273
+ }),
274
+ removeItems: (keys) => callNativeOrFallback({
275
+ ready: nativeReady("6.9"),
276
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.removeItems(keys, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
277
+ fallback: () => cloudStorageFallback.removeItems(keys)
278
+ }),
279
+ getKeys: () => callNativeOrFallback({
280
+ ready: nativeReady("6.9"),
281
+ native: () => new Promise((resolve, reject) => getWebApp().CloudStorage.getKeys((e, keys) => e ? reject(new Error(e)) : resolve(keys != null ? keys : []))),
282
+ fallback: () => cloudStorageFallback.getKeys()
283
+ })
284
+ };
285
+ var deviceStorage = {
286
+ setItem: (key, value) => callNativeOrFallback({
287
+ ready: nativeReady("9.0"),
288
+ native: () => new Promise((resolve, reject) => getWebApp().DeviceStorage.setItem(key, value, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
289
+ fallback: () => deviceStorageFallback.setItem(key, value)
290
+ }),
291
+ getItem: (key) => callNativeOrFallback({
292
+ ready: nativeReady("9.0"),
293
+ native: () => new Promise((resolve, reject) => getWebApp().DeviceStorage.getItem(key, (e, v) => e ? reject(new Error(e)) : resolve(v))),
294
+ fallback: () => deviceStorageFallback.getItem(key)
295
+ }),
296
+ removeItem: (key) => callNativeOrFallback({
297
+ ready: nativeReady("9.0"),
298
+ native: () => new Promise((resolve, reject) => getWebApp().DeviceStorage.removeItem(key, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
299
+ fallback: () => deviceStorageFallback.removeItem(key)
300
+ }),
301
+ clear: () => callNativeOrFallback({
302
+ ready: nativeReady("9.0"),
303
+ native: () => new Promise((resolve, reject) => getWebApp().DeviceStorage.clear((e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
304
+ fallback: () => deviceStorageFallback.clear()
305
+ })
306
+ };
307
+ var secureStorage = {
308
+ setItem: (key, value) => callNativeOrFallback({
309
+ ready: nativeReady("9.0"),
310
+ native: () => new Promise((resolve, reject) => getWebApp().SecureStorage.setItem(key, value, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
311
+ fallback: () => secureStorageFallback.setItem(key, value)
312
+ }),
313
+ getItem: (key) => callNativeOrFallback({
314
+ ready: nativeReady("9.0"),
315
+ native: () => new Promise(
316
+ (resolve, reject) => getWebApp().SecureStorage.getItem(key, (e, v, canRestore) => e ? reject(new Error(e)) : resolve({ value: v, canRestore: canRestore != null ? canRestore : false }))
317
+ ),
318
+ fallback: async () => ({ value: await secureStorageFallback.getItem(key), canRestore: false })
319
+ }),
320
+ removeItem: (key) => callNativeOrFallback({
321
+ ready: nativeReady("9.0"),
322
+ native: () => new Promise((resolve, reject) => getWebApp().SecureStorage.removeItem(key, (e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
323
+ fallback: () => secureStorageFallback.removeItem(key)
324
+ }),
325
+ clear: () => callNativeOrFallback({
326
+ ready: nativeReady("9.0"),
327
+ native: () => new Promise((resolve, reject) => getWebApp().SecureStorage.clear((e, ok) => e ? reject(new Error(e)) : resolve(ok != null ? ok : false))),
328
+ fallback: () => secureStorageFallback.clear()
329
+ }),
330
+ restoreItem: (key) => callNativeOrFallback({
331
+ ready: nativeReady("9.0"),
332
+ native: () => new Promise((resolve, reject) => getWebApp().SecureStorage.restoreItem(key, (e, v) => e ? reject(new Error(e)) : resolve(v))),
333
+ fallback: () => secureStorageFallback.getItem(key)
334
+ })
335
+ };
336
+ var dialog = {
337
+ alert: (message) => callNativeOrFallback({
338
+ ready: nativeReady("6.2"),
339
+ native: () => new Promise((resolve) => getWebApp().showAlert(message, resolve)),
340
+ fallback: () => {
341
+ if (typeof window !== "undefined") window.alert(message);
342
+ }
343
+ }),
344
+ confirm: (message) => callNativeOrFallback({
345
+ ready: nativeReady("6.2"),
346
+ native: () => new Promise((resolve) => getWebApp().showConfirm(message, resolve)),
347
+ fallback: () => typeof window !== "undefined" && window.confirm(message)
348
+ }),
349
+ popup: (params) => callNativeOrFallback({
350
+ ready: nativeReady("6.2"),
351
+ native: () => new Promise((resolve) => getWebApp().showPopup(params, (buttonId) => resolve(buttonId != null ? buttonId : null))),
352
+ fallback: () => {
353
+ var _a;
354
+ if (typeof window === "undefined") return null;
355
+ const okButton = (_a = params.buttons) == null ? void 0 : _a.find((b) => b.type === "ok" || b.type === "default");
356
+ const okButtonId = (okButton == null ? void 0 : okButton.id) != null ? String(okButton.id) : null;
357
+ if (params.buttons && params.buttons.length > 1) {
358
+ const ok = window.confirm(`${params.title ? params.title + "\n" : ""}${params.message}`);
359
+ return ok ? okButtonId != null ? okButtonId : "ok" : null;
360
+ }
361
+ window.alert(`${params.title ? params.title + "\n" : ""}${params.message}`);
362
+ return okButtonId;
363
+ }
364
+ }),
365
+ prompt: (message, defaultValue = "") => Promise.resolve(typeof window === "undefined" ? null : window.prompt(message, defaultValue))
366
+ };
367
+ function readClipboard() {
368
+ return callNativeOrFallback({
369
+ ready: nativeReady("6.4"),
370
+ native: () => new Promise((resolve) => getWebApp().readTextFromClipboard((text) => resolve(text != null ? text : null))),
371
+ fallback: () => readClipboardFallback()
372
+ });
373
+ }
374
+ function scanQr(text) {
375
+ return callNativeOrFallback({
376
+ ready: nativeReady("6.4"),
377
+ native: () => new Promise((resolve) => {
378
+ const wa = getWebApp();
379
+ wa.showScanQrPopup({ text }, (result) => {
380
+ wa.closeScanQrPopup();
381
+ resolve(result);
382
+ return true;
383
+ });
384
+ }),
385
+ fallback: () => scanQrFallback(text)
386
+ });
387
+ }
388
+ function shareToStory(mediaUrl, params) {
389
+ if (!nativeReady("7.8")) return;
390
+ safeInvoke(() => getWebApp().shareToStory(mediaUrl, params));
391
+ }
392
+ function shareMessage(msgId) {
393
+ return callNativeOrFallback({
394
+ ready: nativeReady("8.0"),
395
+ native: () => new Promise((resolve) => getWebApp().shareMessage(msgId, resolve)),
396
+ fallback: () => shareTextFallback(msgId)
397
+ });
398
+ }
399
+ function downloadFile(params) {
400
+ return callNativeOrFallback({
401
+ ready: nativeReady("8.0"),
402
+ native: () => new Promise((resolve) => getWebApp().downloadFile(params, resolve)),
403
+ fallback: () => downloadFileFallback(params.url, params.file_name)
404
+ });
405
+ }
406
+ function setEmojiStatus(customEmojiId, params) {
407
+ return callNativeOrFallback({
408
+ ready: nativeReady("8.0"),
409
+ native: () => new Promise((resolve) => getWebApp().setEmojiStatus(customEmojiId, params, resolve)),
410
+ fallback: () => false
411
+ });
412
+ }
413
+ function requestEmojiStatusAccess() {
414
+ return callNativeOrFallback({
415
+ ready: nativeReady("8.0"),
416
+ native: () => new Promise((resolve) => getWebApp().requestEmojiStatusAccess(resolve)),
417
+ fallback: () => false
418
+ });
419
+ }
420
+ function requestWriteAccess() {
421
+ return callNativeOrFallback({
422
+ ready: nativeReady("6.9"),
423
+ native: () => new Promise((resolve) => getWebApp().requestWriteAccess(resolve)),
424
+ fallback: () => false
425
+ });
426
+ }
427
+ function requestContact() {
428
+ return callNativeOrFallback({
429
+ ready: nativeReady("6.9"),
430
+ native: () => new Promise((resolve) => getWebApp().requestContact(resolve)),
431
+ fallback: () => false
432
+ });
433
+ }
434
+ function requestChat(reqId) {
435
+ return callNativeOrFallback({
436
+ ready: nativeReady("9.6"),
437
+ native: () => new Promise((resolve) => getWebApp().requestChat(reqId, resolve)),
438
+ fallback: () => false
439
+ });
440
+ }
441
+ function invokeCustomMethod(method, params = {}) {
442
+ return callNativeOrFallback({
443
+ ready: nativeReady("6.9"),
444
+ native: () => new Promise((resolve, reject) => getWebApp().invokeCustomMethod(method, params, (e, r) => e ? reject(new Error(e)) : resolve(r))),
445
+ fallback: () => {
446
+ throw new Error("invokeCustomMethod requires the Telegram app (Bot API 6.9+).");
447
+ }
448
+ });
449
+ }
450
+ var biometric = {
451
+ init: () => callNativeOrFallback({
452
+ ready: nativeReady("7.2"),
453
+ native: () => new Promise((resolve) => getWebApp().BiometricManager.init(resolve)),
454
+ fallback: () => void 0
455
+ }),
456
+ requestAccess: (reason) => callNativeOrFallback({
457
+ ready: nativeReady("7.2"),
458
+ native: () => new Promise((resolve) => getWebApp().BiometricManager.requestAccess({ reason }, resolve)),
459
+ fallback: () => false
460
+ }),
461
+ authenticate: (reason) => callNativeOrFallback({
462
+ ready: nativeReady("7.2"),
463
+ native: () => new Promise(
464
+ (resolve) => getWebApp().BiometricManager.authenticate({ reason }, (authenticated, token) => resolve({ authenticated, token: token != null ? token : void 0 }))
465
+ ),
466
+ fallback: () => ({ authenticated: false })
467
+ }),
468
+ updateBiometricToken: (token) => callNativeOrFallback({
469
+ ready: nativeReady("7.2"),
470
+ native: () => new Promise((resolve) => getWebApp().BiometricManager.updateBiometricToken(token, resolve)),
471
+ fallback: () => false
472
+ }),
473
+ openSettings: () => {
474
+ if (!nativeReady("7.2")) return;
475
+ safeInvoke(() => getWebApp().BiometricManager.openSettings());
476
+ }
477
+ };
478
+ var location = {
479
+ init: () => callNativeOrFallback({
480
+ ready: nativeReady("8.0"),
481
+ native: () => new Promise((resolve) => getWebApp().LocationManager.init(() => resolve())),
482
+ fallback: () => void 0
483
+ }),
484
+ getLocation: () => callNativeOrFallback({
485
+ ready: nativeReady("8.0"),
486
+ native: () => new Promise((resolve) => getWebApp().LocationManager.getLocation((data) => resolve(data))),
487
+ fallback: () => getLocationFallback()
488
+ }),
489
+ openSettings: () => {
490
+ if (!nativeReady("8.0")) return;
491
+ safeInvoke(() => getWebApp().LocationManager.openSettings());
492
+ }
493
+ };
494
+
495
+ export { addToHomeScreen, biometric, checkHomeScreenStatus, close, cloudStorage, deviceStorage, dialog, disableClosingConfirmation, disableVerticalSwipes, downloadFile, enableClosingConfirmation, enableVerticalSwipes, expand, fullscreen, getRawUserData, getTheme, getUserAvatarUrl, getUserDisplayName, getUserIdentifier, getUserInfoWithAvatar, getViewport, getWebApp, haptic, hideKeyboard, invokeCustomMethod, isInTelegram, isVersionAtLeast, location, openExternalLink, openInvoice, openTelegramLink, orientation, readClipboard, ready, requestChat, requestContact, requestEmojiStatusAccess, requestWriteAccess, scanQr, secureStorage, setBackgroundColor, setBottomBarColor, setEmojiStatus, setHeaderColor, shareMessage, shareToStory, switchInlineQuery };
@@ -0,0 +1,77 @@
1
+ import '../webapp-BDi9q3-a.mjs';
2
+ import { W as WebAppUser } from '../webapp-B-3_74nK.mjs';
3
+
4
+ /**
5
+ * `@core-ease/telegram-kit/dev`
6
+ *
7
+ * Dev mode used to work by building a large plain-object mock that
8
+ * re-implemented (and had to keep in sync with) the entire `TgWebApp`
9
+ * surface by hand. That duplication is gone: `installDevMode()` now seeds
10
+ * fake `tgWebAppData` / `tgWebAppThemeParams` / `tgWebAppVersion` /
11
+ * `tgWebAppPlatform` into the exact session-storage slot the bundled SDK
12
+ * reads on bootstrap (`sdk/_internal/core/webview.ts`), so the *real*
13
+ * `WebApp` class boots up thinking it's talking to a (very quiet) native
14
+ * client - no parallel implementation to maintain.
15
+ *
16
+ * Because there's no real native client behind it, response-required
17
+ * calls (storage, biometrics, location, popups, clipboard, ...) would
18
+ * naturally time out. `core/index.ts` already knows this: it marks the
19
+ * session as dev-mode-active (see `isDevModeActive()` in `./fallback`) so
20
+ * those calls skip straight to their fast browser-native fallback
21
+ * (`localStorage`, `window.confirm`, `navigator.geolocation`, ...)
22
+ * instead of waiting out a timeout. Fire-and-forget calls (buttons, theme
23
+ * colors, haptics, ...) flow through the real SDK either way and simply
24
+ * no-op harmlessly.
25
+ *
26
+ * **Call `installDevMode()` first thing** in your app's entry point,
27
+ * before any other `@core-ease/telegram-kit` import touches
28
+ * `getWebApp()` (hooks, `<TelegramProvider>`, `core/index.ts` functions,
29
+ * ...) - the SDK bootstraps once and caches the result, so seeding after
30
+ * that point has no effect.
31
+ */
32
+
33
+ interface DevModeOptions {
34
+ /** Defaults to a generic "Dev User". */
35
+ user?: Partial<WebAppUser>;
36
+ /** Forces light/dark theme. Defaults to reading the host page's CSS variables (see `getAppTheme()`), falling back to dark. */
37
+ colorScheme?: 'light' | 'dark';
38
+ /** Simulated `Telegram.WebApp.platform`. Defaults to `'tdesktop'`. */
39
+ platform?: string;
40
+ /** Simulated Bot API version. Defaults to `'8.0'`. */
41
+ version?: string;
42
+ /** Simulated `start_param` (deep-link payload). */
43
+ startParam?: string;
44
+ /** Shows a small "dev mode" badge in the corner of the page. Defaults to `true`. */
45
+ showIndicator?: boolean;
46
+ }
47
+ interface InstallDevModeOptions extends DevModeOptions {
48
+ /** Seed fake data even if this looks like it's already running inside real Telegram. */
49
+ force?: boolean;
50
+ }
51
+ /**
52
+ * Seeds fake Telegram init data (a fake user, theme, platform, and Bot API
53
+ * version) so the bundled SDK bootstraps exactly as it would inside real
54
+ * Telegram - just talking to a client that never answers. Every
55
+ * `@core-ease/telegram-kit` feature keeps working through its browser
56
+ * fallback (see `core/fallback.ts`).
57
+ *
58
+ * Call this **before** anything else touches `getWebApp()` (any hook, the
59
+ * `<TelegramProvider>`, or any `core/index.ts` function) - the SDK
60
+ * bootstraps once and caches the result.
61
+ *
62
+ * Returns `false` (and does nothing) if it looks like the app is already
63
+ * running inside real Telegram, unless `options.force` is set.
64
+ */
65
+ declare function installDevMode(options?: InstallDevModeOptions): boolean;
66
+ /**
67
+ * Environment heuristic (NOT the same as "dev mode is active" - see
68
+ * `isDevModeActive()` in `./fallback` for that) you can use to decide
69
+ * *whether* to call `installDevMode()` at all, e.g.:
70
+ *
71
+ * ```ts
72
+ * if (isDevMode()) installDevMode();
73
+ * ```
74
+ */
75
+ declare function isDevMode(): boolean;
76
+
77
+ export { type DevModeOptions, type InstallDevModeOptions, installDevMode, isDevMode };
@@ -0,0 +1,77 @@
1
+ import '../webapp-YvmwFYUQ.js';
2
+ import { W as WebAppUser } from '../webapp-B-3_74nK.js';
3
+
4
+ /**
5
+ * `@core-ease/telegram-kit/dev`
6
+ *
7
+ * Dev mode used to work by building a large plain-object mock that
8
+ * re-implemented (and had to keep in sync with) the entire `TgWebApp`
9
+ * surface by hand. That duplication is gone: `installDevMode()` now seeds
10
+ * fake `tgWebAppData` / `tgWebAppThemeParams` / `tgWebAppVersion` /
11
+ * `tgWebAppPlatform` into the exact session-storage slot the bundled SDK
12
+ * reads on bootstrap (`sdk/_internal/core/webview.ts`), so the *real*
13
+ * `WebApp` class boots up thinking it's talking to a (very quiet) native
14
+ * client - no parallel implementation to maintain.
15
+ *
16
+ * Because there's no real native client behind it, response-required
17
+ * calls (storage, biometrics, location, popups, clipboard, ...) would
18
+ * naturally time out. `core/index.ts` already knows this: it marks the
19
+ * session as dev-mode-active (see `isDevModeActive()` in `./fallback`) so
20
+ * those calls skip straight to their fast browser-native fallback
21
+ * (`localStorage`, `window.confirm`, `navigator.geolocation`, ...)
22
+ * instead of waiting out a timeout. Fire-and-forget calls (buttons, theme
23
+ * colors, haptics, ...) flow through the real SDK either way and simply
24
+ * no-op harmlessly.
25
+ *
26
+ * **Call `installDevMode()` first thing** in your app's entry point,
27
+ * before any other `@core-ease/telegram-kit` import touches
28
+ * `getWebApp()` (hooks, `<TelegramProvider>`, `core/index.ts` functions,
29
+ * ...) - the SDK bootstraps once and caches the result, so seeding after
30
+ * that point has no effect.
31
+ */
32
+
33
+ interface DevModeOptions {
34
+ /** Defaults to a generic "Dev User". */
35
+ user?: Partial<WebAppUser>;
36
+ /** Forces light/dark theme. Defaults to reading the host page's CSS variables (see `getAppTheme()`), falling back to dark. */
37
+ colorScheme?: 'light' | 'dark';
38
+ /** Simulated `Telegram.WebApp.platform`. Defaults to `'tdesktop'`. */
39
+ platform?: string;
40
+ /** Simulated Bot API version. Defaults to `'8.0'`. */
41
+ version?: string;
42
+ /** Simulated `start_param` (deep-link payload). */
43
+ startParam?: string;
44
+ /** Shows a small "dev mode" badge in the corner of the page. Defaults to `true`. */
45
+ showIndicator?: boolean;
46
+ }
47
+ interface InstallDevModeOptions extends DevModeOptions {
48
+ /** Seed fake data even if this looks like it's already running inside real Telegram. */
49
+ force?: boolean;
50
+ }
51
+ /**
52
+ * Seeds fake Telegram init data (a fake user, theme, platform, and Bot API
53
+ * version) so the bundled SDK bootstraps exactly as it would inside real
54
+ * Telegram - just talking to a client that never answers. Every
55
+ * `@core-ease/telegram-kit` feature keeps working through its browser
56
+ * fallback (see `core/fallback.ts`).
57
+ *
58
+ * Call this **before** anything else touches `getWebApp()` (any hook, the
59
+ * `<TelegramProvider>`, or any `core/index.ts` function) - the SDK
60
+ * bootstraps once and caches the result.
61
+ *
62
+ * Returns `false` (and does nothing) if it looks like the app is already
63
+ * running inside real Telegram, unless `options.force` is set.
64
+ */
65
+ declare function installDevMode(options?: InstallDevModeOptions): boolean;
66
+ /**
67
+ * Environment heuristic (NOT the same as "dev mode is active" - see
68
+ * `isDevModeActive()` in `./fallback` for that) you can use to decide
69
+ * *whether* to call `installDevMode()` at all, e.g.:
70
+ *
71
+ * ```ts
72
+ * if (isDevMode()) installDevMode();
73
+ * ```
74
+ */
75
+ declare function isDevMode(): boolean;
76
+
77
+ export { type DevModeOptions, type InstallDevModeOptions, installDevMode, isDevMode };