@apiteam/twa-bridge 7.0.0-beta.1 → 7.0.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apiteam/twa-bridge",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.3",
4
4
  "description": "Telegram bridge",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",
@@ -0,0 +1,956 @@
1
+ type Close = () => {
2
+ status: boolean | typeof NOT_SUPPORTED;
3
+ };
4
+ /**
5
+ * Closes Mini App.
6
+ *
7
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close
8
+ */
9
+ declare const close: Close;
10
+ /**
11
+ * Method support check
12
+ */
13
+ declare const supportClose: () => boolean;
14
+
15
+ type CloseScanQrPopup = () => {
16
+ status: boolean | typeof NOT_SUPPORTED;
17
+ };
18
+ /**
19
+ * Closes a QR scanner. The Telegram application creates the scan_qr_popup_closed event.
20
+ *
21
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close-scan-qr-popup
22
+ */
23
+ declare const closeScanQrPopup: CloseScanQrPopup;
24
+ /**
25
+ * Method support check
26
+ */
27
+ declare const supportCloseScanQrPopup: () => boolean;
28
+
29
+ type DataSend = (eventData: {
30
+ /**
31
+ * Data to send to a bot. Should not have size of more than 4096 bytes.
32
+ */
33
+ data: string;
34
+ }) => {
35
+ status: boolean | typeof NOT_SUPPORTED;
36
+ };
37
+ /**
38
+ * Sends data to the bot. When this method is called, a service message is sent to the bot containing the data of the length up to 4096 bytes.
39
+ *
40
+ * Then, Mini App will be closed.
41
+ *
42
+ * To get more information, take a look at web_app_data field in the class Message.
43
+ *
44
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-data-send
45
+ */
46
+ declare const dataSend: DataSend;
47
+ /**
48
+ * Method support check
49
+ */
50
+ declare const supportDataSend: () => boolean;
51
+
52
+ type Expand = () => {
53
+ status: boolean | typeof NOT_SUPPORTED;
54
+ };
55
+ /**
56
+ * Closes Mini App.
57
+ */
58
+ declare const expand: Expand;
59
+ /**
60
+ * Method support check
61
+ */
62
+ declare const supportExpand: () => boolean;
63
+
64
+ type IframeReady = (eventData: {
65
+ /**
66
+ * Optional. True, if current Mini App supports native reloading.
67
+ */
68
+ reload_supported?: boolean;
69
+ }) => {
70
+ status: boolean | typeof NOT_SUPPORTED;
71
+ };
72
+ /**
73
+ * Notifies parent iframe about the current frame is ready.
74
+ * This method is only used in the Web version of Telegram.
75
+ * As a result, Mini App will receive set_custom_style event.
76
+ *
77
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-ready
78
+ */
79
+ declare const iframeReady: IframeReady;
80
+ /**
81
+ * Method support check
82
+ */
83
+ declare const supportIframeReady: () => boolean;
84
+
85
+ type IframeWillReload = () => {
86
+ status: boolean | typeof NOT_SUPPORTED;
87
+ };
88
+ /**
89
+ * Notifies parent iframe about the current iframe is going to reload.
90
+ *
91
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-will-reload
92
+ */
93
+ declare const iframeWillReload: IframeWillReload;
94
+ /**
95
+ * Method support check
96
+ */
97
+ declare const supportIframeWillReload: () => boolean;
98
+
99
+ type InvokeCustomMethod = (eventData: {
100
+ /**
101
+ * Current invocation unique identifier.
102
+ *
103
+ * Default: () => randomReqId
104
+ */
105
+ req_id?: string;
106
+ /**
107
+ * Method name.
108
+ */
109
+ method: string;
110
+ /**
111
+ * Parameters according to method.
112
+ */
113
+ params: unknown;
114
+ }) => Promise<{
115
+ status: boolean | typeof NOT_SUPPORTED;
116
+ data?: EventsData[typeof EventCustomMethodInvoked];
117
+ }>;
118
+ /**
119
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-invoke-custom-method
120
+ */
121
+ declare const invokeCustomMethod: InvokeCustomMethod;
122
+ /**
123
+ * Method support check
124
+ */
125
+ declare const supportInvokeCustomMethod: () => boolean;
126
+
127
+ type OpenInvoice = (eventData: {
128
+ /**
129
+ * Invoice unique identifier.
130
+ */
131
+ slug: string;
132
+ }) => {
133
+ status: boolean | typeof NOT_SUPPORTED;
134
+ };
135
+ /**
136
+ * Opens an invoice by its specified slug.
137
+ *
138
+ * More information about invoices in this documentation.
139
+ *
140
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-invoice
141
+ */
142
+ declare const openInvoice: OpenInvoice;
143
+ /**
144
+ * Method support check
145
+ */
146
+ declare const supportOpenInvoice: () => boolean;
147
+
148
+ type OpenLink = (eventData: {
149
+ /**
150
+ * URL to be opened by Telegram application. Should be a full path with https protocol.
151
+ */
152
+ url: string;
153
+ /**
154
+ * Optional. Link will be opened in Instant View mode if possible.
155
+ */
156
+ try_instant_view?: boolean;
157
+ }) => {
158
+ status: boolean | typeof NOT_SUPPORTED;
159
+ };
160
+ /**
161
+ * Opens link in the default browser.
162
+ *
163
+ * Mini App will not be closed.
164
+ *
165
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-link
166
+ */
167
+ declare const openLink: OpenLink;
168
+ /**
169
+ * Method support check
170
+ */
171
+ declare const supportOpenLink: () => boolean;
172
+
173
+ type PopupButton = {
174
+ /**
175
+ * Identifier of the button, 0-64 characters.
176
+ */
177
+ id: string;
178
+ type: 'default' | 'destructive' | 'ok' | 'close' | 'cancel';
179
+ /**
180
+ * The text to be displayed on the button, 0-64 characters. Ignored when type is ok, close or cancel.
181
+ */
182
+ text: string;
183
+ };
184
+ type OpenPopup = (eventData: {
185
+ /**
186
+ * The text to be displayed in the popup title, 0-64 characters
187
+ */
188
+ title: string;
189
+ /**
190
+ * The message to be displayed in the body of the popup, 1-256 characters
191
+ */
192
+ message: string;
193
+ /**
194
+ * List of buttons to be displayed in the popup, 1-3 buttons
195
+ */
196
+ buttons: PopupButton[];
197
+ }) => Promise<{
198
+ status: boolean | typeof NOT_SUPPORTED;
199
+ data?: EventsData['popup_closed'];
200
+ }>;
201
+ /**
202
+ * Opens a new popup. When user closes the popup, Telegram creates the popup_closed event.
203
+ *
204
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-popup
205
+ */
206
+ declare const openPopup: OpenPopup;
207
+ /**
208
+ * Method support check
209
+ */
210
+ declare const supportOpenPopup: () => boolean;
211
+
212
+ type OpenScanQrPopup = (eventData: {
213
+ /**
214
+ * Optional. Text to be displayed in the QR scanner.
215
+ */
216
+ text?: string;
217
+ /**
218
+ * [Custom] Optional. Сlose QR scanner after receiving data
219
+ */
220
+ is_close?: boolean;
221
+ }) => Promise<{
222
+ status: boolean | typeof NOT_SUPPORTED | 'closed';
223
+ data?: EventsData[typeof EventQrTextReceived];
224
+ }>;
225
+ /**
226
+ * Opens a QR scanner.
227
+ *
228
+ * When the scanner was closed, the Telegram application creates the scan_qr_popup_closed event.
229
+ *
230
+ * When the scanner reads QR, Telegram creates the qr_text_received event.
231
+ *
232
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close-scan-qr-popup
233
+ */
234
+ declare const openScanQrPopup: OpenScanQrPopup;
235
+ /**
236
+ * Method support check
237
+ */
238
+ declare const supportOpenScanQrPopup: () => boolean;
239
+
240
+ type OpenTgLink = (eventData: {
241
+ /**
242
+ * Should be a value taken from the link of this format: https://t.me/{path_full}.
243
+ *
244
+ * Can additionally contain query parameters.
245
+ */
246
+ path_full: string;
247
+ }) => {
248
+ status: boolean | typeof NOT_SUPPORTED;
249
+ };
250
+ /**
251
+ * Opens the Telegram link by its pathname and query parameters.
252
+ *
253
+ * The link will be opened in the Telegram app, Mini App will be closed.
254
+ *
255
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-tg-link
256
+ */
257
+ declare const openTgLink: OpenTgLink;
258
+ /**
259
+ * Method support check
260
+ */
261
+ declare const supportOpenTgLink: () => boolean;
262
+
263
+ type ReadTextFromClipboard = (eventData: {
264
+ /**
265
+ * Unique request identifier. Should be any unique string to handle the generated event appropriately.
266
+ *
267
+ * Default: () => randomReqId
268
+ */
269
+ req_id?: string;
270
+ }) => Promise<{
271
+ status: boolean | typeof NOT_SUPPORTED;
272
+ data?: EventsData[typeof EventClipboardTextReceived];
273
+ }>;
274
+ /**
275
+ * Reads text from the clipboard.
276
+ *
277
+ * The method accepts a request identifier which is used to appropriately retrieve the method execution result from the clipboard_text_received event.
278
+ *
279
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-read-text-from-clipboard
280
+ */
281
+ declare const readTextFromClipboard: ReadTextFromClipboard;
282
+ /**
283
+ * Method support check
284
+ */
285
+ declare const supportReadTextFromClipboard: () => boolean;
286
+
287
+ type Ready = () => {
288
+ status: boolean | typeof NOT_SUPPORTED;
289
+ };
290
+ /**
291
+ * Notifies Telegram about current application is ready to be shown.
292
+ *
293
+ * This method will make Telegram to remove application loader and display Mini App.
294
+ *
295
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-ready
296
+ */
297
+ declare const ready: Ready;
298
+ /**
299
+ * Method support check
300
+ */
301
+ declare const supportReady: () => boolean;
302
+
303
+ type RequestPhone = () => Promise<{
304
+ status: boolean | typeof NOT_SUPPORTED;
305
+ }>;
306
+ /**
307
+ * Requests access to current user's phone.
308
+ *
309
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-phone
310
+ */
311
+ declare const requestPhone: RequestPhone;
312
+ /**
313
+ * Method support check
314
+ */
315
+ declare const supportRequestPhone: () => boolean;
316
+
317
+ type RequestTheme = () => {
318
+ status: boolean | typeof NOT_SUPPORTED;
319
+ };
320
+ /**
321
+ * Requests current theme from Telegram.
322
+ *
323
+ * As a result, Telegram will create theme_changed event.
324
+ *
325
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-theme
326
+ */
327
+ declare const requestTheme: RequestTheme;
328
+ /**
329
+ * Method support check
330
+ */
331
+ declare const supportRequestTheme: () => boolean;
332
+
333
+ type RequestViewport = () => {
334
+ status: boolean | typeof NOT_SUPPORTED;
335
+ };
336
+ /**
337
+ * Requests current viewport information from Telegram.
338
+ *
339
+ * As a result, Telegram will create viewport_changed event.
340
+ *
341
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-viewport
342
+ */
343
+ declare const requestViewport: RequestViewport;
344
+ /**
345
+ * Method support check
346
+ */
347
+ declare const supportRequestViewport: () => boolean;
348
+
349
+ type RequestWriteAccess = () => {
350
+ status: boolean | typeof NOT_SUPPORTED;
351
+ };
352
+ /**
353
+ * Requests write message access to current user.
354
+ *
355
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-viewport
356
+ */
357
+ declare const requestWriteAccess: RequestWriteAccess;
358
+ /**
359
+ * Method support check
360
+ */
361
+ declare const supportRequestWriteAccess: () => boolean;
362
+
363
+ type SetBackgroundColor = (eventData: {
364
+ /**
365
+ * The Mini App background color in #RRGGBB format.
366
+ */
367
+ color: string;
368
+ }) => {
369
+ status: boolean | typeof NOT_SUPPORTED;
370
+ };
371
+ /**
372
+ * Updates the Mini App background color.
373
+ *
374
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-background-color
375
+ */
376
+ declare const setBackgroundColor: SetBackgroundColor;
377
+ /**
378
+ * Method support check
379
+ */
380
+ declare const supportSetBackgroundColor: () => boolean;
381
+
382
+ type SetHeaderColor = (eventData: {
383
+ /**
384
+ * The Mini App header color key. Could be either bg_color or secondary_bg_color.
385
+ */
386
+ color_key: 'bg_color' | 'secondary_bg_color';
387
+ /**
388
+ * Color in RGB format.
389
+ */
390
+ color: string;
391
+ }) => {
392
+ status: boolean | typeof NOT_SUPPORTED;
393
+ };
394
+ /**
395
+ * Updates the Mini App header color. This method should accept color_key or color property.
396
+ *
397
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-header-color
398
+ */
399
+ declare const setHeaderColor: SetHeaderColor;
400
+ /**
401
+ * Method support check
402
+ */
403
+ declare const supportSetHeaderColor: () => boolean;
404
+
405
+ type SetupBackButton = (eventData: {
406
+ /**
407
+ * Should the Back Button be visible.
408
+ */
409
+ is_visible: boolean;
410
+ }) => {
411
+ status: boolean | typeof NOT_SUPPORTED;
412
+ };
413
+ /**
414
+ * Updates the Back Button settings.
415
+ *
416
+ * https://docs.telegram-mini-apps.com/platform/ui/back-button
417
+ */
418
+ declare const setupBackButton: SetupBackButton;
419
+ /**
420
+ * Method support check
421
+ */
422
+ declare const supportSetupBackButton: () => boolean;
423
+
424
+ type SetupClosingBehavior = (eventData: {
425
+ /**
426
+ * Will user be prompted in case, an application is going to be closed.
427
+ */
428
+ need_confirmation: boolean;
429
+ }) => {
430
+ status: boolean | typeof NOT_SUPPORTED;
431
+ };
432
+ /**
433
+ * Updates current closing behavior.
434
+ *
435
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-closing-behavior
436
+ */
437
+ declare const setupClosingBehavior: SetupClosingBehavior;
438
+ /**
439
+ * Method support check
440
+ */
441
+ declare const supportSetupClosingBehavior: () => boolean;
442
+
443
+ type SetupMainButton = (eventData: {
444
+ /**
445
+ * Optional. Should the Main Button be displayed.
446
+ */
447
+ is_visible?: boolean;
448
+ /**
449
+ * Optional. Should the Main Button be enabled.
450
+ */
451
+ is_active?: boolean;
452
+ /**
453
+ * Optional. Should loader inside the Main Button be displayed. Use this property in case, some operation takes time. This loader will make user notified about it.
454
+ */
455
+ is_progress_visible?: boolean;
456
+ /**
457
+ * Optional. Text inside the Main Button.
458
+ */
459
+ text?: string;
460
+ /**
461
+ * Optional. The Main Button background color in #RRGGBB format.
462
+ */
463
+ color?: string;
464
+ /**
465
+ * Optional. The Main Button text color in #RRGGBB format.
466
+ */
467
+ text_color?: string;
468
+ }) => {
469
+ status: boolean | typeof NOT_SUPPORTED;
470
+ };
471
+ /**
472
+ * Updates the Main Button settings.
473
+ *
474
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-main-button
475
+ */
476
+ declare const setupMainButton: SetupMainButton;
477
+ /**
478
+ * Method support check
479
+ */
480
+ declare const supportSetupMainButton: () => boolean;
481
+
482
+ type SetupSettingsButton = (eventData: {
483
+ /**
484
+ * Should the Settings Button be displayed.
485
+ */
486
+ is_visible: boolean;
487
+ }) => {
488
+ status: boolean | typeof NOT_SUPPORTED;
489
+ };
490
+ /**
491
+ * Updates current state of Settings Button.
492
+ *
493
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-settings-button
494
+ */
495
+ declare const setupSettingsButton: SetupSettingsButton;
496
+ /**
497
+ * Method support check
498
+ */
499
+ declare const supportSetupSettingsButton: () => boolean;
500
+
501
+ type SwitchInlineQuery = (eventData: {
502
+ /**
503
+ * Text which should be inserted in the input after the current bot name. Max length is 256 symbols.
504
+ */
505
+ query: string;
506
+ /**
507
+ * List of chat types which could be chosen to send the message. Could be empty list. Values:
508
+ *
509
+ * users, bots, groups, channels
510
+ */
511
+ chat_types: ['users', 'bots', 'groups', 'channels'];
512
+ }) => {
513
+ status: boolean | typeof NOT_SUPPORTED;
514
+ };
515
+ /**
516
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
517
+ *
518
+ * Query may be empty, in which case only the bot's username will be inserted.
519
+ *
520
+ * The client prompts the user to choose a specific chat, then opens that chat and inserts the bot's username and the specified inline query in the input field.
521
+ *
522
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-switch-inline-query
523
+ */
524
+ declare const switchInlineQuery: SwitchInlineQuery;
525
+ /**
526
+ * Method support check
527
+ */
528
+ declare const supportSwitchInlineQuery: () => boolean;
529
+
530
+ type TriggerHapticFeedback = (eventData: {
531
+ /**
532
+ * Type of haptic event. Values:
533
+ *
534
+ * impact - when there's a collision involving UI components.
535
+ *
536
+ * notification - when some action execution has been completed.
537
+ *
538
+ * selection_change - when the user changes their selection.
539
+ */
540
+ type: 'impact' | 'notification' | 'selection_change';
541
+ /**
542
+ * Required when type is impact. Values:
543
+ *
544
+ * light - indicates a collision between small or lightweight UI objects
545
+ *
546
+ * medium - indicates a collision between medium-sized or medium-weight UI objects
547
+ *
548
+ * heavy - indicates a collision between large or heavyweight UI objects
549
+ *
550
+ * rigid - indicates a collision between hard or inflexible UI objects
551
+ *
552
+ * soft - indicates a collision between soft or flexible UI objects
553
+ */
554
+ impact_style: 'light' | 'medium' | 'heavy' | 'rigid' | 'soft';
555
+ /**
556
+ * Required when type is notification. Values:
557
+ *
558
+ * error - indicates that a task or action has failed
559
+ *
560
+ * success - indicates that a task or action has completed successfully
561
+ *
562
+ * warning - indicates that a task or action produced a warning
563
+ */
564
+ notification_type: 'error' | 'success' | 'warning';
565
+ }) => {
566
+ status: boolean | typeof NOT_SUPPORTED;
567
+ };
568
+ /**
569
+ * Generates the haptic feedback event.
570
+ *
571
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-trigger-haptic-feedback
572
+ */
573
+ declare const triggerHapticFeedback: TriggerHapticFeedback;
574
+ /**
575
+ * Method support check
576
+ */
577
+ declare const supportTriggerHapticFeedback: () => boolean;
578
+
579
+ type User = {
580
+ /**
581
+ * Optional. True, if this user added the bot to the attachment menu.
582
+ */
583
+ added_to_attachment_menu?: boolean;
584
+ /**
585
+ * Optional. True, if this user allowed the bot to message them.
586
+ */
587
+ allows_write_to_pm?: boolean;
588
+ /**
589
+ * Optional. Has the user purchased Telegram Premium.
590
+ */
591
+ is_premium?: boolean;
592
+ /**
593
+ * Bot or user name.
594
+ */
595
+ first_name: string;
596
+ /**
597
+ * Bot or user ID.
598
+ */
599
+ id: number;
600
+ /**
601
+ * Optional. Is the user a bot.
602
+ */
603
+ is_bot?: boolean;
604
+ /**
605
+ * Optional. User's last name.
606
+ */
607
+ last_name?: string;
608
+ /**
609
+ * Optional. IETF user's language.
610
+ */
611
+ language_code: string;
612
+ /**
613
+ * Optional. Link to the user's or bot's photo.
614
+ *
615
+ * Photos can have formats .jpeg and .svg.
616
+ *
617
+ * It is returned only for Mini Apps opened through the attachment menu.
618
+ */
619
+ photo_url?: string;
620
+ /**
621
+ * Optional. Login of the bot or user.
622
+ */
623
+ username?: string;
624
+ };
625
+ type Chat = {
626
+ /**
627
+ * Unique chat ID.
628
+ */
629
+ id: number;
630
+ /**
631
+ * Chat type. Values:
632
+ *
633
+ * group, supergroup, channel
634
+ */
635
+ type: 'group' | 'supergroup' | 'channel';
636
+ /**
637
+ * Chat title.
638
+ */
639
+ title: string;
640
+ /**
641
+ * Optional. Chat photo link. The photo can have .jpeg and .svg formats.
642
+ *
643
+ * It is returned only for Mini Apps opened through the attachments menu.
644
+ */
645
+ photo_url?: string;
646
+ /**
647
+ * Optional. Chat user login.
648
+ */
649
+ username?: string;
650
+ };
651
+ type GetInitData = () => null | {
652
+ /**
653
+ * The date the initialization data was created.
654
+ *
655
+ * Is a number representing a Unix timestamp.
656
+ */
657
+ auth_date: number;
658
+ /**
659
+ * Optional. The number of seconds after which a message can be sent via the method answerWebAppQuery.
660
+ */
661
+ can_send_after?: number;
662
+ /**
663
+ * Optional. An object containing information about the chat with the bot in which the Mini Apps was launched.
664
+ *
665
+ * It is returned only for Mini Apps opened through the attachments menu.
666
+ */
667
+ chat?: Chat;
668
+ /**
669
+ * Optional. The type of chat from which the Mini Apps was opened. Values:
670
+ *
671
+ * sender, private, group, supergroup, channel
672
+ *
673
+ * Returned only for applications opened by direct link.
674
+ */
675
+ chat_type?: 'sender' | 'private' | 'group' | 'supergroup' | 'channel';
676
+ /**
677
+ * Optional. A global identifier indicating the chat from which the Mini Apps was opened.
678
+ *
679
+ * Returned only for applications opened by direct link.
680
+ */
681
+ chat_instance?: string;
682
+ /**
683
+ * Initialization data signature.
684
+ */
685
+ hash: string;
686
+ /**
687
+ * Optional. The unique session ID of the Mini App. Used in the process of sending a message via the method answerWebAppQuery.
688
+ */
689
+ query_id?: string;
690
+ /**
691
+ * Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu.
692
+ *
693
+ * Returned only for private chats and only for Mini Apps launched via the attachment menu.
694
+ */
695
+ receiver?: User;
696
+ /**
697
+ * Optional. The value of the startattach or startapp query parameter specified in the link. It is returned only for Mini Apps opened through the attachment menu.
698
+ */
699
+ start_param?: string;
700
+ /**
701
+ * Optional. An object containing information about the current user.
702
+ */
703
+ user?: User;
704
+ };
705
+ /**
706
+ * In the list of launch parameters, initialization data is located in the tgWebAppData parameter.
707
+ *
708
+ * It is a set of data mostly related to a specific user who launched the Mini App.
709
+ *
710
+ * Original: https://docs.telegram-mini-apps.com/platform/launch-parameters/init-data#init-data
711
+ */
712
+ declare const getInitData: GetInitData;
713
+
714
+ type Sender = (eventType: string, eventData?: any) => void;
715
+ /**
716
+ * EDIT
717
+ *
718
+ * window.parent.postMessage(JSON.stringify({ eventType, eventData }), 'https://web.telegram.org');
719
+ * window['TelegramWebviewProxy'].postEvent(eventType, JSON.stringify(eventData));
720
+ */
721
+ declare const sender: Sender;
722
+
723
+ type Debug = (methondName: string, errorId: number) => void;
724
+ declare const debug: Debug;
725
+
726
+ type EventsData = {
727
+ /**
728
+ * User clicked the Back Button.
729
+ */
730
+ "back_button_pressed": undefined;
731
+ /**
732
+ * Telegram application attempted to extract text from clipboard.
733
+ */
734
+ "clipboard_text_received": {
735
+ /**
736
+ * Passed during the web_app_read_text_from_clipboard method invocation req_id value.
737
+ */
738
+ req_id: string;
739
+ /**
740
+ * Optional. Data extracted from the clipboard. The returned value will have the type string only in the case, application has access to the clipboard.
741
+ */
742
+ data?: string | null;
743
+ };
744
+ /**
745
+ * Custom method invocation completed.
746
+ */
747
+ "custom_method_invoked": {
748
+ /**
749
+ * Unique identifier of this invocation.
750
+ */
751
+ req_id: string;
752
+ /**
753
+ * Optional. Method invocation successful result.
754
+ */
755
+ result?: unknown;
756
+ /**
757
+ * Optional. Method invocation error code.
758
+ */
759
+ error?: string;
760
+ };
761
+ /**
762
+ * An invoice was closed.
763
+ */
764
+ "invoice_closed": {
765
+ /**
766
+ * Passed during the web_app_open_invoice method invocation slug value.
767
+ */
768
+ slug: string;
769
+ /**
770
+ * Invoice status. Values:
771
+ *
772
+ * paid - invoice was paid
773
+ *
774
+ * failed - invoice failed
775
+ *
776
+ * pending - invoice is currently pending
777
+ *
778
+ * cancelled - invoice was cancelled
779
+ */
780
+ status: 'paid' | 'failed' | 'pending' | 'cancelled';
781
+ };
782
+ /**
783
+ * User clicked the Main Button.
784
+ */
785
+ "main_button_pressed": undefined;
786
+ /**
787
+ * Application received phone access request status.
788
+ */
789
+ "phone_requested": {
790
+ /**
791
+ * Request status. Can only be sent
792
+ */
793
+ status: 'sent';
794
+ };
795
+ /**
796
+ * Popup was closed.
797
+ */
798
+ "popup_closed": {
799
+ /**
800
+ * Optional. Identifier of the clicked button.
801
+ *
802
+ * In case, the popup was closed without clicking any button, this property will be omitted.
803
+ */
804
+ button_id?: string;
805
+ };
806
+ /**
807
+ * Parent iframe requested current iframe reload.
808
+ */
809
+ "reload_iframe": undefined;
810
+ /**
811
+ * The QR scanner scanned some QR and extracted its content.
812
+ */
813
+ "qr_text_received": {
814
+ /**
815
+ * Optional. Data extracted from the QR.
816
+ */
817
+ data?: string;
818
+ };
819
+ /**
820
+ * QR scanner was closed.
821
+ */
822
+ "scan_qr_popup_closed": undefined;
823
+ /**
824
+ * The event which is usually sent by the Telegram web application.
825
+ *
826
+ * Its payload represents <style/> tag html content, a developer could use. The stylesheet described in the payload will help the developer to stylize the app scrollbar (but he is still able to do it himself).
827
+ */
828
+ "set_custom_style": undefined;
829
+ /**
830
+ * Occurs when the Settings Button was pressed.
831
+ */
832
+ "settings_button_pressed": undefined;
833
+ /**
834
+ * Occurs whenever the theme was changed in the user's Telegram app ( including switching to night mode).
835
+ */
836
+ "theme_changed": {
837
+ /**
838
+ * Map where the key is a theme stylesheet key and value is the corresponding color in #RRGGBB format.
839
+ */
840
+ theme_params: Record<string, string>;
841
+ };
842
+ /**
843
+ * Occurs whenever the viewport has been changed.
844
+ *
845
+ * For example, when the user started dragging the application or called the expansion method.
846
+ */
847
+ "viewport_changed": {
848
+ /**
849
+ * The viewport height.
850
+ */
851
+ height: number;
852
+ /**
853
+ * Optional. The viewport width.
854
+ */
855
+ width?: number;
856
+ /**
857
+ * Is the viewport currently expanded.
858
+ */
859
+ is_expanded: boolean;
860
+ /**
861
+ * Is the viewport current state stable and not going to change in the next moment.
862
+ */
863
+ is_state_stable: boolean;
864
+ };
865
+ /**
866
+ * Application received write access request status.
867
+ */
868
+ "write_access_requested": {
869
+ /**
870
+ * Request status. Can only be allowed.
871
+ */
872
+ status: 'allowed';
873
+ };
874
+ };
875
+ interface TelegramGameProxy {
876
+ receiveEvent: (event: string, data: string) => void;
877
+ }
878
+ interface TelegramWebviewProxy {
879
+ postEvent: (event: string, data: string) => void;
880
+ }
881
+ declare global {
882
+ interface External {
883
+ notify: (event: string) => void;
884
+ }
885
+ interface Window {
886
+ TelegramWebviewProxy: TelegramWebviewProxy;
887
+ TelegramGameProxy: TelegramGameProxy;
888
+ TelegramGameProxy_receiveEvent: TelegramGameProxy["receiveEvent"];
889
+ Telegram: {
890
+ WebView: TelegramGameProxy;
891
+ };
892
+ }
893
+ }
894
+ type Listened = <T extends EventsData, E extends keyof T, D extends T[E]>(eventName: E, callback: (eventData: D) => void) => void;
895
+ declare const on: Listened;
896
+ declare const off: Listened;
897
+ declare const once: Listened;
898
+
899
+ type listener_EventsData = EventsData;
900
+ declare const listener_off: typeof off;
901
+ declare const listener_on: typeof on;
902
+ declare const listener_once: typeof once;
903
+ declare namespace listener {
904
+ export { type listener_EventsData as EventsData, listener_off as off, listener_on as on, listener_once as once };
905
+ }
906
+
907
+ declare const TG_WEB = "web";
908
+ declare const TG_PHONE = "phone";
909
+ declare const TG_DESKTOP = "desktop";
910
+
911
+ declare const NOT_SUPPORTED = "not_supported";
912
+
913
+ declare const MethodInvokeCustomMethod = "web_app_invoke_custom_method";
914
+ declare const MethodOpenScanQrPopup = "web_app_open_scan_qr_popup";
915
+ declare const MethodReadTextFromClipboard = "web_app_read_text_from_clipboard";
916
+ declare const MethodRequestPhone = "web_app_request_phone";
917
+ declare const MethodClose = "web_app_close";
918
+ declare const MethodCloseScanQrPopup = "web_app_close_scan_qr_popup";
919
+ declare const MethodDataSend = "web_app_data_send";
920
+ declare const MethodExpand = "web_app_expand";
921
+ declare const MethodIframeReady = "iframe_ready";
922
+ declare const MethodIframeWillReload = "iframe_will_reload";
923
+ declare const MethodOpenInvoice = "web_app_open_invoice";
924
+ declare const MethodOpenLink = "web_app_open_link";
925
+ declare const MethodOpenPopup = "web_app_open_popup";
926
+ declare const MethodOpenTgLink = "web_app_open_tg_link";
927
+ declare const MethodReady = "web_app_ready";
928
+ declare const MethodRequestTheme = "web_app_request_theme";
929
+ declare const MethodRequestViewport = "web_app_request_viewport";
930
+ declare const MethodRequestWriteAccess = "web_app_request_write_access";
931
+ declare const MethodSetBackgroundColor = "web_app_set_background_color";
932
+ declare const MethodSetHeaderColor = "web_app_set_header_color";
933
+ declare const MethodSetupBackButton = "web_app_setup_back_button";
934
+ declare const MethodSetupClosingBehavior = "web_app_setup_closing_behavior";
935
+ declare const MethodSetupMainButton = "web_app_setup_main_button";
936
+ declare const MethodSetupSettingsButton = "web_app_setup_settings_button";
937
+ declare const MethodSwitchInlineQuery = "web_app_switch_inline_query";
938
+ declare const MethodTriggerHapticFeedback = "web_app_trigger_haptic_feedback";
939
+
940
+ declare const EventBackButtonPressed = "back_button_pressed";
941
+ declare const EventClipboardTextReceived = "clipboard_text_received";
942
+ declare const EventCustomMethodInvoked = "custom_method_invoked";
943
+ declare const EventInvoiceClosed = "invoice_closed";
944
+ declare const EventMainButtonPressed = "main_button_pressed";
945
+ declare const EventPhoneRequested = "phone_requested";
946
+ declare const EventPopupClosed = "popup_closed";
947
+ declare const EventReloadIframe = "reload_iframe";
948
+ declare const EventQrTextReceived = "qr_text_received";
949
+ declare const EventScanQrPopupClosed = "scan_qr_popup_closed";
950
+ declare const EventSetCustomStyle = "set_custom_style";
951
+ declare const EventSettingsButtonPressed = "settings_button_pressed";
952
+ declare const EventThemeChanged = "theme_changed";
953
+ declare const EventViewportChanged = "viewport_changed";
954
+ declare const EventWriteAccessRequested = "write_access_requested";
955
+
956
+ export { EventBackButtonPressed, EventClipboardTextReceived, EventCustomMethodInvoked, EventInvoiceClosed, EventMainButtonPressed, EventPhoneRequested, EventPopupClosed, EventQrTextReceived, EventReloadIframe, EventScanQrPopupClosed, EventSetCustomStyle, EventSettingsButtonPressed, EventThemeChanged, EventViewportChanged, EventWriteAccessRequested, type EventsData, MethodClose, MethodCloseScanQrPopup, MethodDataSend, MethodExpand, MethodIframeReady, MethodIframeWillReload, MethodInvokeCustomMethod, MethodOpenInvoice, MethodOpenLink, MethodOpenPopup, MethodOpenScanQrPopup, MethodOpenTgLink, MethodReadTextFromClipboard, MethodReady, MethodRequestPhone, MethodRequestTheme, MethodRequestViewport, MethodRequestWriteAccess, MethodSetBackgroundColor, MethodSetHeaderColor, MethodSetupBackButton, MethodSetupClosingBehavior, MethodSetupMainButton, MethodSetupSettingsButton, MethodSwitchInlineQuery, MethodTriggerHapticFeedback, NOT_SUPPORTED, TG_DESKTOP, TG_PHONE, TG_WEB, close as bridgeClose, closeScanQrPopup as bridgeCloseScanQrPopup, dataSend as bridgeDataSend, expand as bridgeExpand, getInitData as bridgeGetInitData, iframeReady as bridgeIframeReady, iframeWillReload as bridgeIframeWillReload, invokeCustomMethod as bridgeInvokeCustomMethod, openInvoice as bridgeOpenInvoice, openLink as bridgeOpenLink, openPopup as bridgeOpenPopup, openScanQrPopup as bridgeOpenScanQrPopup, openTgLink as bridgeOpenTgLink, readTextFromClipboard as bridgeReadTextFromClipboard, ready as bridgeReady, requestPhone as bridgeRequestPhone, requestTheme as bridgeRequestTheme, requestViewport as bridgeRequestViewport, requestWriteAccess as bridgeRequestWriteAccess, setBackgroundColor as bridgeSetBackgroundColor, setHeaderColor as bridgeSetHeaderColor, setupBackButton as bridgeSetupBackButton, setupClosingBehavior as bridgeSetupClosingBehavior, setupMainButton as bridgeSetupMainButton, setupSettingsButton as bridgeSetupSettingsButton, switchInlineQuery as bridgeSwitchInlineQuery, triggerHapticFeedback as bridgeTriggerHapticFeedback, debug, listener, sender, supportClose, supportCloseScanQrPopup, supportDataSend, supportExpand, supportIframeReady, supportIframeWillReload, supportInvokeCustomMethod, supportOpenInvoice, supportOpenLink, supportOpenPopup, supportOpenScanQrPopup, supportOpenTgLink, supportReadTextFromClipboard, supportReady, supportRequestPhone, supportRequestTheme, supportRequestViewport, supportRequestWriteAccess, supportSetBackgroundColor, supportSetHeaderColor, supportSetupBackButton, supportSetupClosingBehavior, supportSetupMainButton, supportSetupSettingsButton, supportSwitchInlineQuery, supportTriggerHapticFeedback };
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("utils");const t="web",s="phone",o="desktop",r="not_supported",p=(e,r)=>{const p=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(p)>=e&&-1!==r.indexOf((()=>{const e=window.location.hash.slice(1),r=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(r)?s:["tdesktop","macos"].includes(r)?o:t})())},a=()=>Math.random().toString(36).substring(3,9),n=()=>p(0,[t,o,s]),u=()=>i()?(Q(Z),{status:!0}):(W(Z,1),{status:r}),i=()=>p(6.4,[s]),d=()=>p(0,[t,o,s]),_=()=>p(0,[s]),c=()=>p(0,[t]),x=()=>p(0,[t]),l="web_app_invoke_custom_method",g=()=>p(6.9,[t,o,s]),h=()=>p(6.1,[t,o,s]),b=()=>p(6.4,[t,o,s]),w=()=>p(6.2,[t,o,s]),m=()=>p(6.4,[s]),v=()=>p(7,[t,o,s]),S=()=>p(6.4,[t,o,s]),f=()=>p(6.9,[t,o,s]),P=()=>p(6.9,[t,o,s]),M=()=>p(0,[t,o,s]),q=()=>p(0,[t,o,s]),R=()=>p(6.9,[t,o,s]),k=()=>p(6.1,[t,o,s]),y=()=>p(6.1,[t,o,s]),C=()=>p(6.1,[t,o,s]),E=()=>p(0,[t,o,s]),T=()=>p(0,[t,o,s]),O=()=>p(6.1,[t,o,s]),B=()=>p(6.7,[t,o,s]),I=()=>p(6.1,[s]);var W=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var Q=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const D="clipboard_text_received",L="custom_method_invoked",N="phone_requested",A="popup_closed",H="qr_text_received",V="scan_qr_popup_closed",F="theme_changed",G=((e=new Map)=>({once:(t,s,o=e.get(t),r=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(r):e.set(t,[r]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))();(()=>{function t(t,s){t===F&&(s.theme_params=e.getThemeParams(s.theme_params)),G.emit(t,s),G.emit("*",{name:t,data:s})}window.TelegramGameProxy_receiveEvent=t,window.Telegram={WebView:{receiveEvent:t}},window.TelegramGameProxy={receiveEvent:t}})();const U=(e,t)=>{G.on(e,t)},$=(e,t)=>{G.off(e,t)},J=(e,t)=>{G.once(e,t)};var j=Object.freeze({__proto__:null,off:$,on:U,once:J});const z="web_app_open_scan_qr_popup",K="web_app_read_text_from_clipboard",X="web_app_request_phone",Y="web_app_close",Z="web_app_close_scan_qr_popup",ee="web_app_data_send",te="web_app_expand",se="iframe_ready",oe="web_app_open_invoice",re="web_app_open_link",pe="web_app_open_popup",ae="web_app_open_tg_link",ne="web_app_ready",ue="web_app_request_theme",ie="web_app_request_viewport",de="web_app_request_write_access",_e="web_app_set_background_color",ce="web_app_set_header_color",xe="web_app_setup_back_button",le="web_app_setup_closing_behavior",ge="web_app_setup_main_button",he="web_app_setup_settings_button",be="web_app_switch_inline_query",we="web_app_trigger_haptic_feedback";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=D,exports.EventCustomMethodInvoked=L,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=N,exports.EventPopupClosed=A,exports.EventQrTextReceived=H,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=V,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged=F,exports.EventViewportChanged="viewport_changed",exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=Y,exports.MethodCloseScanQrPopup=Z,exports.MethodDataSend=ee,exports.MethodExpand=te,exports.MethodIframeReady=se,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=oe,exports.MethodOpenLink=re,exports.MethodOpenPopup=pe,exports.MethodOpenScanQrPopup=z,exports.MethodOpenTgLink=ae,exports.MethodReadTextFromClipboard=K,exports.MethodReady=ne,exports.MethodRequestPhone=X,exports.MethodRequestTheme=ue,exports.MethodRequestViewport=ie,exports.MethodRequestWriteAccess=de,exports.MethodSetBackgroundColor=_e,exports.MethodSetHeaderColor=ce,exports.MethodSetupBackButton=xe,exports.MethodSetupClosingBehavior=le,exports.MethodSetupMainButton=ge,exports.MethodSetupSettingsButton=he,exports.MethodSwitchInlineQuery=be,exports.MethodTriggerHapticFeedback=we,exports.NOT_SUPPORTED=r,exports.TG_DESKTOP=o,exports.TG_PHONE=s,exports.TG_WEB=t,exports.bridgeClose=()=>n()?(Q(Y),{status:!0}):(W(Y,1),{status:r}),exports.bridgeCloseScanQrPopup=u,exports.bridgeDataSend=e=>d()?(Q(ee,e),{status:!0}):(W(ee,1),{status:r}),exports.bridgeExpand=()=>_()?(Q(te),{status:!0}):(W(te,1),{status:r}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return W("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>c()?(Q(se,e),{status:!0}):(W(se,1),{status:r}),exports.bridgeIframeWillReload=()=>x()?(Q(se),{status:!0}):(W(se,1),{status:r}),exports.bridgeInvokeCustomMethod=async e=>g()?(void 0===e.req_id&&(e.req_id=a()),Q(l,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),$(L,o))};U(L,o)}))):(W(l,1),{status:r}),exports.bridgeOpenInvoice=e=>h()?(Q(oe,e),{status:!0}):(W(oe,1),{status:r}),exports.bridgeOpenLink=e=>b()?(Q(re,e),{status:!0}):(W(re,1),{status:r}),exports.bridgeOpenPopup=async e=>w()?(e.title.length>64&&W(pe,3),e.message.length<1&&W(pe,4),e.message.length>256&&W(pe,5),e.buttons.length<1&&W(pe,6),e.buttons.length>3&&W(pe,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&W(pe,8),Q(pe,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),$(A,o)};U(A,o)}))):(W(pe,1),{status:r}),exports.bridgeOpenScanQrPopup=async e=>m()?(Q(z,e),new Promise(((t,s)=>{J(H,(s=>{e.is_close&&u(),t({status:!0,data:s})})),J(V,(()=>{t({status:"closed"})}))}))):(W(z,1),{status:r}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),v()?(Q(ae,e),{status:!0}):(W(ae,1),{status:r})),exports.bridgeReadTextFromClipboard=async e=>S()?(void 0===e.req_id&&(e.req_id=a()),Q(K,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),$(D,o))};U(D,o)}))):(W(K,1),{status:r}),exports.bridgeReady=()=>f()?(Q(ne),{status:!0}):(W(ne,1),{status:r}),exports.bridgeRequestPhone=async()=>P()?(Q(X),new Promise(((e,t)=>{J(N,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(W(X,1),{status:r}),exports.bridgeRequestTheme=()=>M()?(Q(ue),{status:!0}):(W(ue,1),{status:r}),exports.bridgeRequestViewport=()=>q()?(Q(ie),{status:!0}):(W(ie,1),{status:r}),exports.bridgeRequestWriteAccess=()=>R()?(Q(de),{status:!0}):(W(de,1),{status:r}),exports.bridgeSetBackgroundColor=e=>k()?(Q(_e,e),{status:!0}):(W(_e,1),{status:r}),exports.bridgeSetHeaderColor=e=>y()?(Q(ce,e),{status:!0}):(W(ce,1),{status:r}),exports.bridgeSetupBackButton=e=>C()?(Q(xe,e),{status:!0}):(W(xe,1),{status:r}),exports.bridgeSetupClosingBehavior=e=>E()?(Q(le,e),{status:!0}):(W(le,1),{status:r}),exports.bridgeSetupMainButton=e=>T()?(Q(ge,e),{status:!0}):(W(ge,1),{status:r}),exports.bridgeSetupSettingsButton=e=>O()?(Q(he,e),{status:!0}):(W(he,1),{status:r}),exports.bridgeSwitchInlineQuery=e=>B()?(e.query.length>256&&W(be,9),Q(be,e),{status:!0}):(W(be,1),{status:r}),exports.bridgeTriggerHapticFeedback=e=>I()?(Q(we,e),{status:!0}):(W(we,1),{status:r}),exports.debug=W,exports.listener=j,exports.sender=Q,exports.supportClose=n,exports.supportCloseScanQrPopup=i,exports.supportDataSend=d,exports.supportExpand=_,exports.supportIframeReady=c,exports.supportIframeWillReload=x,exports.supportInvokeCustomMethod=g,exports.supportOpenInvoice=h,exports.supportOpenLink=b,exports.supportOpenPopup=w,exports.supportOpenScanQrPopup=m,exports.supportOpenTgLink=v,exports.supportReadTextFromClipboard=S,exports.supportReady=f,exports.supportRequestPhone=P,exports.supportRequestTheme=M,exports.supportRequestViewport=q,exports.supportRequestWriteAccess=R,exports.supportSetBackgroundColor=k,exports.supportSetHeaderColor=y,exports.supportSetupBackButton=C,exports.supportSetupClosingBehavior=E,exports.supportSetupMainButton=T,exports.supportSetupSettingsButton=O,exports.supportSwitchInlineQuery=B,exports.supportTriggerHapticFeedback=I;
@@ -0,0 +1 @@
1
+ import{getThemeParams as e}from"utils";const t="web",s="phone",a="desktop",n="not_supported",o=(e,n)=>{const o=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(o)>=e&&-1!==n.indexOf((()=>{const e=window.location.hash.slice(1),n=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(n)?s:["tdesktop","macos"].includes(n)?a:t})())},r=()=>Math.random().toString(36).substring(3,9),i=()=>_()?(_e(Ie),{status:!0}):(re(Ie,1),{status:n}),_=()=>o(0,[t,a,s]),p=()=>u()?(_e(Be),{status:!0}):(re(Be,1),{status:n}),u=()=>o(6.4,[s]),d=e=>c()?(_e(De,e),{status:!0}):(re(De,1),{status:n}),c=()=>o(0,[t,a,s]),b=()=>g()?(_e(Le),{status:!0}):(re(Le,1),{status:n}),g=()=>o(0,[s]),l=e=>w()?(_e(Ne,e),{status:!0}):(re(Ne,1),{status:n}),w=()=>o(0,[t]),m=()=>h()?(_e(Ne),{status:!0}):(re(Ne,1),{status:n}),h=()=>o(0,[t]),f="web_app_invoke_custom_method",v=async e=>q()?(void 0===e.req_id&&(e.req_id=r()),_e(f,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),xe(de,a))};ke(de,a)}))):(re(f,1),{status:n}),q=()=>o(6.9,[t,a,s]),y=e=>P()?(_e(Me,e),{status:!0}):(re(Me,1),{status:n}),P=()=>o(6.1,[t,a,s]),S=e=>k()?(_e(Ue,e),{status:!0}):(re(Ue,1),{status:n}),k=()=>o(6.4,[t,a,s]),x=async e=>O()?(e.title.length>64&&re(Ve,3),e.message.length<1&&re(Ve,4),e.message.length>256&&re(Ve,5),e.buttons.length<1&&re(Ve,6),e.buttons.length>3&&re(Ve,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&re(Ve,8),_e(Ve,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),xe(le,a)};ke(le,a)}))):(re(Ve,1),{status:n}),O=()=>o(6.2,[t,a,s]),R=async e=>T()?(_e(Ee,e),new Promise(((t,s)=>{Oe(me,(s=>{e.is_close&&p(),t({status:!0,data:s})})),Oe(he,(()=>{t({status:"closed"})}))}))):(re(Ee,1),{status:n}),T=()=>o(6.4,[s]),E=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),W()?(_e($e,e),{status:!0}):(re($e,1),{status:n})),W=()=>o(7,[t,a,s]),C=async e=>I()?(void 0===e.req_id&&(e.req_id=r()),_e(We,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),xe(ue,a))};ke(ue,a)}))):(re(We,1),{status:n}),I=()=>o(6.4,[t,a,s]),B=()=>D()?(_e(Ge),{status:!0}):(re(Ge,1),{status:n}),D=()=>o(6.9,[t,a,s]),L=async()=>N()?(_e(Ce),new Promise(((e,t)=>{Oe(ge,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(re(Ce,1),{status:n}),N=()=>o(6.9,[t,a,s]),A=()=>M()?(_e(Je),{status:!0}):(re(Je,1),{status:n}),M=()=>o(0,[t,a,s]),U=()=>V()?(_e(Qe),{status:!0}):(re(Qe,1),{status:n}),V=()=>o(0,[t,a,s]),$=()=>G()?(_e(Fe),{status:!0}):(re(Fe,1),{status:n}),G=()=>o(6.9,[t,a,s]),J=e=>Q()?(_e(He,e),{status:!0}):(re(He,1),{status:n}),Q=()=>o(6.1,[t,a,s]),F=e=>H()?(_e(je,e),{status:!0}):(re(je,1),{status:n}),H=()=>o(6.1,[t,a,s]),j=e=>z()?(_e(ze,e),{status:!0}):(re(ze,1),{status:n}),z=()=>o(6.1,[t,a,s]),K=e=>X()?(_e(Ke,e),{status:!0}):(re(Ke,1),{status:n}),X=()=>o(0,[t,a,s]),Y=e=>Z()?(_e(Xe,e),{status:!0}):(re(Xe,1),{status:n}),Z=()=>o(0,[t,a,s]),ee=e=>te()?(_e(Ye,e),{status:!0}):(re(Ye,1),{status:n}),te=()=>o(6.1,[t,a,s]),se=e=>ae()?(e.query.length>256&&re(Ze,9),_e(Ze,e),{status:!0}):(re(Ze,1),{status:n}),ae=()=>o(6.7,[t,a,s]),ne=e=>oe()?(_e(et,e),{status:!0}):(re(et,1),{status:n}),oe=()=>o(6.1,[s]);var re=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const ie=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return re("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var _e=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const pe="back_button_pressed",ue="clipboard_text_received",de="custom_method_invoked",ce="invoice_closed",be="main_button_pressed",ge="phone_requested",le="popup_closed",we="reload_iframe",me="qr_text_received",he="scan_qr_popup_closed",fe="set_custom_style",ve="settings_button_pressed",qe="theme_changed",ye="viewport_changed",Pe="write_access_requested",Se=((e=new Map)=>({once:(t,s,a=e.get(t),n=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(n):e.set(t,[n]),on:(t,s,a=e.get(t))=>a?a.push(s):e.set(t,[s]),off:(t,s,a=e.get(t))=>a&&s?a.splice(a.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,a=e.get(t)||[])=>{for(const e of a)e(s)}}))();(()=>{function t(t,s){t===qe&&(s.theme_params=e(s.theme_params)),Se.emit(t,s),Se.emit("*",{name:t,data:s})}window.TelegramGameProxy_receiveEvent=t,window.Telegram={WebView:{receiveEvent:t}},window.TelegramGameProxy={receiveEvent:t}})();const ke=(e,t)=>{Se.on(e,t)},xe=(e,t)=>{Se.off(e,t)},Oe=(e,t)=>{Se.once(e,t)};var Re=Object.freeze({__proto__:null,off:xe,on:ke,once:Oe});const Te="web_app_invoke_custom_method",Ee="web_app_open_scan_qr_popup",We="web_app_read_text_from_clipboard",Ce="web_app_request_phone",Ie="web_app_close",Be="web_app_close_scan_qr_popup",De="web_app_data_send",Le="web_app_expand",Ne="iframe_ready",Ae="iframe_will_reload",Me="web_app_open_invoice",Ue="web_app_open_link",Ve="web_app_open_popup",$e="web_app_open_tg_link",Ge="web_app_ready",Je="web_app_request_theme",Qe="web_app_request_viewport",Fe="web_app_request_write_access",He="web_app_set_background_color",je="web_app_set_header_color",ze="web_app_setup_back_button",Ke="web_app_setup_closing_behavior",Xe="web_app_setup_main_button",Ye="web_app_setup_settings_button",Ze="web_app_switch_inline_query",et="web_app_trigger_haptic_feedback";export{pe as EventBackButtonPressed,ue as EventClipboardTextReceived,de as EventCustomMethodInvoked,ce as EventInvoiceClosed,be as EventMainButtonPressed,ge as EventPhoneRequested,le as EventPopupClosed,me as EventQrTextReceived,we as EventReloadIframe,he as EventScanQrPopupClosed,fe as EventSetCustomStyle,ve as EventSettingsButtonPressed,qe as EventThemeChanged,ye as EventViewportChanged,Pe as EventWriteAccessRequested,Ie as MethodClose,Be as MethodCloseScanQrPopup,De as MethodDataSend,Le as MethodExpand,Ne as MethodIframeReady,Ae as MethodIframeWillReload,Te as MethodInvokeCustomMethod,Me as MethodOpenInvoice,Ue as MethodOpenLink,Ve as MethodOpenPopup,Ee as MethodOpenScanQrPopup,$e as MethodOpenTgLink,We as MethodReadTextFromClipboard,Ge as MethodReady,Ce as MethodRequestPhone,Je as MethodRequestTheme,Qe as MethodRequestViewport,Fe as MethodRequestWriteAccess,He as MethodSetBackgroundColor,je as MethodSetHeaderColor,ze as MethodSetupBackButton,Ke as MethodSetupClosingBehavior,Xe as MethodSetupMainButton,Ye as MethodSetupSettingsButton,Ze as MethodSwitchInlineQuery,et as MethodTriggerHapticFeedback,n as NOT_SUPPORTED,a as TG_DESKTOP,s as TG_PHONE,t as TG_WEB,i as bridgeClose,p as bridgeCloseScanQrPopup,d as bridgeDataSend,b as bridgeExpand,ie as bridgeGetInitData,l as bridgeIframeReady,m as bridgeIframeWillReload,v as bridgeInvokeCustomMethod,y as bridgeOpenInvoice,S as bridgeOpenLink,x as bridgeOpenPopup,R as bridgeOpenScanQrPopup,E as bridgeOpenTgLink,C as bridgeReadTextFromClipboard,B as bridgeReady,L as bridgeRequestPhone,A as bridgeRequestTheme,U as bridgeRequestViewport,$ as bridgeRequestWriteAccess,J as bridgeSetBackgroundColor,F as bridgeSetHeaderColor,j as bridgeSetupBackButton,K as bridgeSetupClosingBehavior,Y as bridgeSetupMainButton,ee as bridgeSetupSettingsButton,se as bridgeSwitchInlineQuery,ne as bridgeTriggerHapticFeedback,re as debug,Re as listener,_e as sender,_ as supportClose,u as supportCloseScanQrPopup,c as supportDataSend,g as supportExpand,w as supportIframeReady,h as supportIframeWillReload,q as supportInvokeCustomMethod,P as supportOpenInvoice,k as supportOpenLink,O as supportOpenPopup,T as supportOpenScanQrPopup,W as supportOpenTgLink,I as supportReadTextFromClipboard,D as supportReady,N as supportRequestPhone,M as supportRequestTheme,V as supportRequestViewport,G as supportRequestWriteAccess,Q as supportSetBackgroundColor,H as supportSetHeaderColor,z as supportSetupBackButton,X as supportSetupClosingBehavior,Z as supportSetupMainButton,te as supportSetupSettingsButton,ae as supportSwitchInlineQuery,oe as supportTriggerHapticFeedback};
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@apiteam/twa-bridge/react",
3
+ "main": "index.js",
4
+ "module": "index.mjs",
5
+ "typings": "index.d.ts",
6
+ "browser": {
7
+ "./index.cjs": "index.cjs",
8
+ "./index.js": "index.js"
9
+ },
10
+ "unpkg": "index.cjs",
11
+ "types": "index.d.ts",
12
+ "type": "module",
13
+ "peerDependencies": {
14
+ "react": "^18.0.0",
15
+ "react-dom": "^18.0.0"
16
+ }
17
+ }
package/solid/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("solid-js");const t="web",s="phone",o="desktop",r="not_supported",p=(e,r)=>{const p=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(p)>=e&&-1!==r.indexOf((()=>{const e=window.location.hash.slice(1),r=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(r)?s:["tdesktop","macos"].includes(r)?o:t})())},a=()=>Math.random().toString(36).substring(3,9),n=()=>p(0,[t,o,s]),u=()=>i()?(Q($),{status:!0}):(W($,1),{status:r}),i=()=>p(6.4,[s]),d=()=>p(0,[t,o,s]),_=()=>p(0,[s]),c=()=>p(0,[t]),x=()=>p(0,[t]),l="web_app_invoke_custom_method",g=()=>p(6.9,[t,o,s]),b=()=>p(6.1,[t,o,s]),h=()=>p(6.4,[t,o,s]),w=()=>p(6.2,[t,o,s]),m=()=>p(6.4,[s]),v=()=>p(7,[t,o,s]),S=()=>p(6.4,[t,o,s]),f=()=>p(6.9,[t,o,s]),M=()=>p(6.9,[t,o,s]),P=()=>p(0,[t,o,s]),q=()=>p(0,[t,o,s]),R=()=>p(6.9,[t,o,s]),k=()=>p(6.1,[t,o,s]),C=()=>p(6.1,[t,o,s]),y=()=>p(6.1,[t,o,s]),E=()=>p(0,[t,o,s]),O=()=>p(0,[t,o,s]),T=()=>p(6.1,[t,o,s]),B=()=>p(6.7,[t,o,s]),I=()=>p(6.1,[s]);var W=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var Q=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const D=((e=new Map)=>({once:(t,s,o=e.get(t),r=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(r):e.set(t,[r]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))();(()=>{function e(e,t){D.emit(e,t),D.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const L=(e,t)=>{D.on(e,t)},N=(e,t)=>{D.off(e,t)},V=(e,t)=>{D.once(e,t)};var A=Object.freeze({__proto__:null,off:N,on:L,once:V});const H="web_app_open_scan_qr_popup",F="web_app_read_text_from_clipboard",G="web_app_request_phone",U="web_app_close",$="web_app_close_scan_qr_popup",J="web_app_data_send",j="web_app_expand",z="iframe_ready",K="web_app_open_invoice",X="web_app_open_link",Y="web_app_open_popup",Z="web_app_open_tg_link",ee="web_app_ready",te="web_app_request_theme",se="web_app_request_viewport",oe="web_app_request_write_access",re="web_app_set_background_color",pe="web_app_set_header_color",ae="web_app_setup_back_button",ne="web_app_setup_closing_behavior",ue="web_app_setup_main_button",ie="web_app_setup_settings_button",de="web_app_switch_inline_query",_e="web_app_trigger_haptic_feedback",ce="clipboard_text_received",xe="custom_method_invoked",le="phone_requested",ge="popup_closed",be="qr_text_received",he="scan_qr_popup_closed",we="viewport_changed";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=ce,exports.EventCustomMethodInvoked=xe,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=le,exports.EventPopupClosed=ge,exports.EventQrTextReceived=be,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=he,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged="theme_changed",exports.EventViewportChanged=we,exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=U,exports.MethodCloseScanQrPopup=$,exports.MethodDataSend=J,exports.MethodExpand=j,exports.MethodIframeReady=z,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=K,exports.MethodOpenLink=X,exports.MethodOpenPopup=Y,exports.MethodOpenScanQrPopup=H,exports.MethodOpenTgLink=Z,exports.MethodReadTextFromClipboard=F,exports.MethodReady=ee,exports.MethodRequestPhone=G,exports.MethodRequestTheme=te,exports.MethodRequestViewport=se,exports.MethodRequestWriteAccess=oe,exports.MethodSetBackgroundColor=re,exports.MethodSetHeaderColor=pe,exports.MethodSetupBackButton=ae,exports.MethodSetupClosingBehavior=ne,exports.MethodSetupMainButton=ue,exports.MethodSetupSettingsButton=ie,exports.MethodSwitchInlineQuery=de,exports.MethodTriggerHapticFeedback=_e,exports.NOT_SUPPORTED=r,exports.TG_DESKTOP=o,exports.TG_PHONE=s,exports.TG_WEB=t,exports.bridgeClose=()=>n()?(Q(U),{status:!0}):(W(U,1),{status:r}),exports.bridgeCloseScanQrPopup=u,exports.bridgeDataSend=e=>d()?(Q(J,e),{status:!0}):(W(J,1),{status:r}),exports.bridgeExpand=()=>_()?(Q(j),{status:!0}):(W(j,1),{status:r}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return W("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>c()?(Q(z,e),{status:!0}):(W(z,1),{status:r}),exports.bridgeIframeWillReload=()=>x()?(Q(z),{status:!0}):(W(z,1),{status:r}),exports.bridgeInvokeCustomMethod=async e=>g()?(void 0===e.req_id&&(e.req_id=a()),Q(l,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),N(xe,o))};L(xe,o)}))):(W(l,1),{status:r}),exports.bridgeOpenInvoice=e=>b()?(Q(K,e),{status:!0}):(W(K,1),{status:r}),exports.bridgeOpenLink=e=>h()?(Q(X,e),{status:!0}):(W(X,1),{status:r}),exports.bridgeOpenPopup=async e=>w()?(e.title.length>64&&W(Y,3),e.message.length<1&&W(Y,4),e.message.length>256&&W(Y,5),e.buttons.length<1&&W(Y,6),e.buttons.length>3&&W(Y,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&W(Y,8),Q(Y,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),N(ge,o)};L(ge,o)}))):(W(Y,1),{status:r}),exports.bridgeOpenScanQrPopup=async e=>m()?(Q(H,e),new Promise(((t,s)=>{V(be,(s=>{e.is_close&&u(),t({status:!0,data:s})})),V(he,(()=>{t({status:"closed"})}))}))):(W(H,1),{status:r}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),v()?(Q(Z,e),{status:!0}):(W(Z,1),{status:r})),exports.bridgeReadTextFromClipboard=async e=>S()?(void 0===e.req_id&&(e.req_id=a()),Q(F,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),N(ce,o))};L(ce,o)}))):(W(F,1),{status:r}),exports.bridgeReady=()=>f()?(Q(ee),{status:!0}):(W(ee,1),{status:r}),exports.bridgeRequestPhone=async()=>M()?(Q(G),new Promise(((e,t)=>{V(le,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(W(G,1),{status:r}),exports.bridgeRequestTheme=()=>P()?(Q(te),{status:!0}):(W(te,1),{status:r}),exports.bridgeRequestViewport=()=>q()?(Q(se),{status:!0}):(W(se,1),{status:r}),exports.bridgeRequestWriteAccess=()=>R()?(Q(oe),{status:!0}):(W(oe,1),{status:r}),exports.bridgeSetBackgroundColor=e=>k()?(Q(re,e),{status:!0}):(W(re,1),{status:r}),exports.bridgeSetHeaderColor=e=>C()?(Q(pe,e),{status:!0}):(W(pe,1),{status:r}),exports.bridgeSetupBackButton=e=>y()?(Q(ae,e),{status:!0}):(W(ae,1),{status:r}),exports.bridgeSetupClosingBehavior=e=>E()?(Q(ne,e),{status:!0}):(W(ne,1),{status:r}),exports.bridgeSetupMainButton=e=>O()?(Q(ue,e),{status:!0}):(W(ue,1),{status:r}),exports.bridgeSetupSettingsButton=e=>T()?(Q(ie,e),{status:!0}):(W(ie,1),{status:r}),exports.bridgeSwitchInlineQuery=e=>B()?(e.query.length>256&&W(de,9),Q(de,e),{status:!0}):(W(de,1),{status:r}),exports.bridgeTriggerHapticFeedback=e=>I()?(Q(_e,e),{status:!0}):(W(_e,1),{status:r}),exports.createIsViewportChanged=()=>{const[t,s]=e.createSignal({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>s(e);return e.onMount((()=>{L(we,o),Q(se)})),e.onCleanup((()=>{N(we,o)})),t},exports.debug=W,exports.listener=A,exports.sender=Q,exports.supportClose=n,exports.supportCloseScanQrPopup=i,exports.supportDataSend=d,exports.supportExpand=_,exports.supportIframeReady=c,exports.supportIframeWillReload=x,exports.supportInvokeCustomMethod=g,exports.supportOpenInvoice=b,exports.supportOpenLink=h,exports.supportOpenPopup=w,exports.supportOpenScanQrPopup=m,exports.supportOpenTgLink=v,exports.supportReadTextFromClipboard=S,exports.supportReady=f,exports.supportRequestPhone=M,exports.supportRequestTheme=P,exports.supportRequestViewport=q,exports.supportRequestWriteAccess=R,exports.supportSetBackgroundColor=k,exports.supportSetHeaderColor=C,exports.supportSetupBackButton=y,exports.supportSetupClosingBehavior=E,exports.supportSetupMainButton=O,exports.supportSetupSettingsButton=T,exports.supportSwitchInlineQuery=B,exports.supportTriggerHapticFeedback=I;
1
+ "use strict";var e=require("utils"),t=require("solid-js");const s="web",o="phone",r="desktop",p="not_supported",a=(e,t)=>{const p=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(p)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?o:["tdesktop","macos"].includes(t)?r:s})())},n=()=>Math.random().toString(36).substring(3,9),u=()=>a(0,[s,r,o]),i=()=>d()?(D(te),{status:!0}):(Q(te,1),{status:p}),d=()=>a(6.4,[o]),_=()=>a(0,[s,r,o]),c=()=>a(0,[o]),x=()=>a(0,[s]),l=()=>a(0,[s]),g="web_app_invoke_custom_method",h=()=>a(6.9,[s,r,o]),b=()=>a(6.1,[s,r,o]),w=()=>a(6.4,[s,r,o]),m=()=>a(6.2,[s,r,o]),v=()=>a(6.4,[o]),S=()=>a(7,[s,r,o]),f=()=>a(6.4,[s,r,o]),M=()=>a(6.9,[s,r,o]),P=()=>a(6.9,[s,r,o]),q=()=>a(0,[s,r,o]),R=()=>a(0,[s,r,o]),k=()=>a(6.9,[s,r,o]),C=()=>a(6.1,[s,r,o]),y=()=>a(6.1,[s,r,o]),E=()=>a(6.1,[s,r,o]),T=()=>a(0,[s,r,o]),O=()=>a(0,[s,r,o]),B=()=>a(6.1,[s,r,o]),I=()=>a(6.7,[s,r,o]),W=()=>a(6.1,[o]);var Q=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var D=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const L="clipboard_text_received",N="custom_method_invoked",V="phone_requested",A="popup_closed",H="qr_text_received",F="scan_qr_popup_closed",G="theme_changed",U="viewport_changed",$=((e=new Map)=>({once:(t,s,o=e.get(t),r=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(r):e.set(t,[r]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))();(()=>{function t(t,s){t===G&&(s.theme_params=e.getThemeParams(s.theme_params)),$.emit(t,s),$.emit("*",{name:t,data:s})}window.TelegramGameProxy_receiveEvent=t,window.Telegram={WebView:{receiveEvent:t}},window.TelegramGameProxy={receiveEvent:t}})();const J=(e,t)=>{$.on(e,t)},j=(e,t)=>{$.off(e,t)},z=(e,t)=>{$.once(e,t)};var K=Object.freeze({__proto__:null,off:j,on:J,once:z});const X="web_app_open_scan_qr_popup",Y="web_app_read_text_from_clipboard",Z="web_app_request_phone",ee="web_app_close",te="web_app_close_scan_qr_popup",se="web_app_data_send",oe="web_app_expand",re="iframe_ready",pe="web_app_open_invoice",ae="web_app_open_link",ne="web_app_open_popup",ue="web_app_open_tg_link",ie="web_app_ready",de="web_app_request_theme",_e="web_app_request_viewport",ce="web_app_request_write_access",xe="web_app_set_background_color",le="web_app_set_header_color",ge="web_app_setup_back_button",he="web_app_setup_closing_behavior",be="web_app_setup_main_button",we="web_app_setup_settings_button",me="web_app_switch_inline_query",ve="web_app_trigger_haptic_feedback";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=L,exports.EventCustomMethodInvoked=N,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=V,exports.EventPopupClosed=A,exports.EventQrTextReceived=H,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=F,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged=G,exports.EventViewportChanged=U,exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=ee,exports.MethodCloseScanQrPopup=te,exports.MethodDataSend=se,exports.MethodExpand=oe,exports.MethodIframeReady=re,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=pe,exports.MethodOpenLink=ae,exports.MethodOpenPopup=ne,exports.MethodOpenScanQrPopup=X,exports.MethodOpenTgLink=ue,exports.MethodReadTextFromClipboard=Y,exports.MethodReady=ie,exports.MethodRequestPhone=Z,exports.MethodRequestTheme=de,exports.MethodRequestViewport=_e,exports.MethodRequestWriteAccess=ce,exports.MethodSetBackgroundColor=xe,exports.MethodSetHeaderColor=le,exports.MethodSetupBackButton=ge,exports.MethodSetupClosingBehavior=he,exports.MethodSetupMainButton=be,exports.MethodSetupSettingsButton=we,exports.MethodSwitchInlineQuery=me,exports.MethodTriggerHapticFeedback=ve,exports.NOT_SUPPORTED=p,exports.TG_DESKTOP=r,exports.TG_PHONE=o,exports.TG_WEB=s,exports.bridgeClose=()=>u()?(D(ee),{status:!0}):(Q(ee,1),{status:p}),exports.bridgeCloseScanQrPopup=i,exports.bridgeDataSend=e=>_()?(D(se,e),{status:!0}):(Q(se,1),{status:p}),exports.bridgeExpand=()=>c()?(D(oe),{status:!0}):(Q(oe,1),{status:p}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return Q("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>x()?(D(re,e),{status:!0}):(Q(re,1),{status:p}),exports.bridgeIframeWillReload=()=>l()?(D(re),{status:!0}):(Q(re,1),{status:p}),exports.bridgeInvokeCustomMethod=async e=>h()?(void 0===e.req_id&&(e.req_id=n()),D(g,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),j(N,o))};J(N,o)}))):(Q(g,1),{status:p}),exports.bridgeOpenInvoice=e=>b()?(D(pe,e),{status:!0}):(Q(pe,1),{status:p}),exports.bridgeOpenLink=e=>w()?(D(ae,e),{status:!0}):(Q(ae,1),{status:p}),exports.bridgeOpenPopup=async e=>m()?(e.title.length>64&&Q(ne,3),e.message.length<1&&Q(ne,4),e.message.length>256&&Q(ne,5),e.buttons.length<1&&Q(ne,6),e.buttons.length>3&&Q(ne,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&Q(ne,8),D(ne,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),j(A,o)};J(A,o)}))):(Q(ne,1),{status:p}),exports.bridgeOpenScanQrPopup=async e=>v()?(D(X,e),new Promise(((t,s)=>{z(H,(s=>{e.is_close&&i(),t({status:!0,data:s})})),z(F,(()=>{t({status:"closed"})}))}))):(Q(X,1),{status:p}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),S()?(D(ue,e),{status:!0}):(Q(ue,1),{status:p})),exports.bridgeReadTextFromClipboard=async e=>f()?(void 0===e.req_id&&(e.req_id=n()),D(Y,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),j(L,o))};J(L,o)}))):(Q(Y,1),{status:p}),exports.bridgeReady=()=>M()?(D(ie),{status:!0}):(Q(ie,1),{status:p}),exports.bridgeRequestPhone=async()=>P()?(D(Z),new Promise(((e,t)=>{z(V,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(Q(Z,1),{status:p}),exports.bridgeRequestTheme=()=>q()?(D(de),{status:!0}):(Q(de,1),{status:p}),exports.bridgeRequestViewport=()=>R()?(D(_e),{status:!0}):(Q(_e,1),{status:p}),exports.bridgeRequestWriteAccess=()=>k()?(D(ce),{status:!0}):(Q(ce,1),{status:p}),exports.bridgeSetBackgroundColor=e=>C()?(D(xe,e),{status:!0}):(Q(xe,1),{status:p}),exports.bridgeSetHeaderColor=e=>y()?(D(le,e),{status:!0}):(Q(le,1),{status:p}),exports.bridgeSetupBackButton=e=>E()?(D(ge,e),{status:!0}):(Q(ge,1),{status:p}),exports.bridgeSetupClosingBehavior=e=>T()?(D(he,e),{status:!0}):(Q(he,1),{status:p}),exports.bridgeSetupMainButton=e=>O()?(D(be,e),{status:!0}):(Q(be,1),{status:p}),exports.bridgeSetupSettingsButton=e=>B()?(D(we,e),{status:!0}):(Q(we,1),{status:p}),exports.bridgeSwitchInlineQuery=e=>I()?(e.query.length>256&&Q(me,9),D(me,e),{status:!0}):(Q(me,1),{status:p}),exports.bridgeTriggerHapticFeedback=e=>W()?(D(ve,e),{status:!0}):(Q(ve,1),{status:p}),exports.createIsViewportChanged=()=>{const[e,s]=t.createSignal({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>s(e);return t.onMount((()=>{J(U,o),D(_e)})),t.onCleanup((()=>{j(U,o)})),e},exports.debug=Q,exports.listener=K,exports.sender=D,exports.supportClose=u,exports.supportCloseScanQrPopup=d,exports.supportDataSend=_,exports.supportExpand=c,exports.supportIframeReady=x,exports.supportIframeWillReload=l,exports.supportInvokeCustomMethod=h,exports.supportOpenInvoice=b,exports.supportOpenLink=w,exports.supportOpenPopup=m,exports.supportOpenScanQrPopup=v,exports.supportOpenTgLink=S,exports.supportReadTextFromClipboard=f,exports.supportReady=M,exports.supportRequestPhone=P,exports.supportRequestTheme=q,exports.supportRequestViewport=R,exports.supportRequestWriteAccess=k,exports.supportSetBackgroundColor=C,exports.supportSetHeaderColor=y,exports.supportSetupBackButton=E,exports.supportSetupClosingBehavior=T,exports.supportSetupMainButton=O,exports.supportSetupSettingsButton=B,exports.supportSwitchInlineQuery=I,exports.supportTriggerHapticFeedback=W;
package/solid/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createSignal as e,onMount as t,onCleanup as s}from"solid-js";const a=()=>{const[a,n]=e({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>n(e);return t((()=>{be(st,o),de(Ie)})),s((()=>{le(st,o)})),a},n="web",o="phone",r="desktop",i="not_supported",_=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?o:["tdesktop","macos"].includes(t)?r:n})())},p=()=>Math.random().toString(36).substring(3,9),u=()=>d()?(de(qe),{status:!0}):(pe(qe,1),{status:i}),d=()=>_(0,[n,r,o]),c=()=>b()?(de(ye),{status:!0}):(pe(ye,1),{status:i}),b=()=>_(6.4,[o]),l=e=>g()?(de(xe,e),{status:!0}):(pe(xe,1),{status:i}),g=()=>_(0,[n,r,o]),w=()=>m()?(de(Se),{status:!0}):(pe(Se,1),{status:i}),m=()=>_(0,[o]),h=e=>f()?(de(ke,e),{status:!0}):(pe(ke,1),{status:i}),f=()=>_(0,[n]),v=()=>q()?(de(ke),{status:!0}):(pe(ke,1),{status:i}),q=()=>_(0,[n]),y="web_app_invoke_custom_method",x=async e=>S()?(void 0===e.req_id&&(e.req_id=p()),de(y,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),le(Qe,a))};be(Qe,a)}))):(pe(y,1),{status:i}),S=()=>_(6.9,[n,r,o]),k=e=>P()?(de(Oe,e),{status:!0}):(pe(Oe,1),{status:i}),P=()=>_(6.1,[n,r,o]),O=e=>R()?(de(Re,e),{status:!0}):(pe(Re,1),{status:i}),R=()=>_(6.4,[n,r,o]),T=async e=>E()?(e.title.length>64&&pe(Te,3),e.message.length<1&&pe(Te,4),e.message.length>256&&pe(Te,5),e.buttons.length<1&&pe(Te,6),e.buttons.length>3&&pe(Te,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&pe(Te,8),de(Te,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),le(ze,a)};be(ze,a)}))):(pe(Te,1),{status:i}),E=()=>_(6.2,[n,r,o]),W=async e=>C()?(de(he,e),new Promise(((t,s)=>{ge(Xe,(s=>{e.is_close&&c(),t({status:!0,data:s})})),ge(Ye,(()=>{t({status:"closed"})}))}))):(pe(he,1),{status:i}),C=()=>_(6.4,[o]),I=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),B()?(de(Ee,e),{status:!0}):(pe(Ee,1),{status:i})),B=()=>_(7,[n,r,o]),D=async e=>L()?(void 0===e.req_id&&(e.req_id=p()),de(fe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),le(Je,a))};be(Je,a)}))):(pe(fe,1),{status:i}),L=()=>_(6.4,[n,r,o]),N=()=>A()?(de(We),{status:!0}):(pe(We,1),{status:i}),A=()=>_(6.9,[n,r,o]),M=async()=>U()?(de(ve),new Promise(((e,t)=>{ge(He,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(pe(ve,1),{status:i}),U=()=>_(6.9,[n,r,o]),V=()=>$()?(de(Ce),{status:!0}):(pe(Ce,1),{status:i}),$=()=>_(0,[n,r,o]),G=()=>J()?(de(Ie),{status:!0}):(pe(Ie,1),{status:i}),J=()=>_(0,[n,r,o]),Q=()=>j()?(de(Be),{status:!0}):(pe(Be,1),{status:i}),j=()=>_(6.9,[n,r,o]),F=e=>H()?(de(De,e),{status:!0}):(pe(De,1),{status:i}),H=()=>_(6.1,[n,r,o]),z=e=>K()?(de(Le,e),{status:!0}):(pe(Le,1),{status:i}),K=()=>_(6.1,[n,r,o]),X=e=>Y()?(de(Ne,e),{status:!0}):(pe(Ne,1),{status:i}),Y=()=>_(6.1,[n,r,o]),Z=e=>ee()?(de(Ae,e),{status:!0}):(pe(Ae,1),{status:i}),ee=()=>_(0,[n,r,o]),te=e=>se()?(de(Me,e),{status:!0}):(pe(Me,1),{status:i}),se=()=>_(0,[n,r,o]),ae=e=>ne()?(de(Ue,e),{status:!0}):(pe(Ue,1),{status:i}),ne=()=>_(6.1,[n,r,o]),oe=e=>re()?(e.query.length>256&&pe(Ve,9),de(Ve,e),{status:!0}):(pe(Ve,1),{status:i}),re=()=>_(6.7,[n,r,o]),ie=e=>_e()?(de($e,e),{status:!0}):(pe($e,1),{status:i}),_e=()=>_(6.1,[o]);var pe=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const ue=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return pe("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var de=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const ce=((e=new Map)=>({once:(t,s,a=e.get(t),n=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(n):e.set(t,[n]),on:(t,s,a=e.get(t))=>a?a.push(s):e.set(t,[s]),off:(t,s,a=e.get(t))=>a&&s?a.splice(a.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,a=e.get(t)||[])=>{for(const e of a)e(s)}}))();(()=>{function e(e,t){ce.emit(e,t),ce.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const be=(e,t)=>{ce.on(e,t)},le=(e,t)=>{ce.off(e,t)},ge=(e,t)=>{ce.once(e,t)};var we=Object.freeze({__proto__:null,off:le,on:be,once:ge});const me="web_app_invoke_custom_method",he="web_app_open_scan_qr_popup",fe="web_app_read_text_from_clipboard",ve="web_app_request_phone",qe="web_app_close",ye="web_app_close_scan_qr_popup",xe="web_app_data_send",Se="web_app_expand",ke="iframe_ready",Pe="iframe_will_reload",Oe="web_app_open_invoice",Re="web_app_open_link",Te="web_app_open_popup",Ee="web_app_open_tg_link",We="web_app_ready",Ce="web_app_request_theme",Ie="web_app_request_viewport",Be="web_app_request_write_access",De="web_app_set_background_color",Le="web_app_set_header_color",Ne="web_app_setup_back_button",Ae="web_app_setup_closing_behavior",Me="web_app_setup_main_button",Ue="web_app_setup_settings_button",Ve="web_app_switch_inline_query",$e="web_app_trigger_haptic_feedback",Ge="back_button_pressed",Je="clipboard_text_received",Qe="custom_method_invoked",je="invoice_closed",Fe="main_button_pressed",He="phone_requested",ze="popup_closed",Ke="reload_iframe",Xe="qr_text_received",Ye="scan_qr_popup_closed",Ze="set_custom_style",et="settings_button_pressed",tt="theme_changed",st="viewport_changed",at="write_access_requested";export{Ge as EventBackButtonPressed,Je as EventClipboardTextReceived,Qe as EventCustomMethodInvoked,je as EventInvoiceClosed,Fe as EventMainButtonPressed,He as EventPhoneRequested,ze as EventPopupClosed,Xe as EventQrTextReceived,Ke as EventReloadIframe,Ye as EventScanQrPopupClosed,Ze as EventSetCustomStyle,et as EventSettingsButtonPressed,tt as EventThemeChanged,st as EventViewportChanged,at as EventWriteAccessRequested,qe as MethodClose,ye as MethodCloseScanQrPopup,xe as MethodDataSend,Se as MethodExpand,ke as MethodIframeReady,Pe as MethodIframeWillReload,me as MethodInvokeCustomMethod,Oe as MethodOpenInvoice,Re as MethodOpenLink,Te as MethodOpenPopup,he as MethodOpenScanQrPopup,Ee as MethodOpenTgLink,fe as MethodReadTextFromClipboard,We as MethodReady,ve as MethodRequestPhone,Ce as MethodRequestTheme,Ie as MethodRequestViewport,Be as MethodRequestWriteAccess,De as MethodSetBackgroundColor,Le as MethodSetHeaderColor,Ne as MethodSetupBackButton,Ae as MethodSetupClosingBehavior,Me as MethodSetupMainButton,Ue as MethodSetupSettingsButton,Ve as MethodSwitchInlineQuery,$e as MethodTriggerHapticFeedback,i as NOT_SUPPORTED,r as TG_DESKTOP,o as TG_PHONE,n as TG_WEB,u as bridgeClose,c as bridgeCloseScanQrPopup,l as bridgeDataSend,w as bridgeExpand,ue as bridgeGetInitData,h as bridgeIframeReady,v as bridgeIframeWillReload,x as bridgeInvokeCustomMethod,k as bridgeOpenInvoice,O as bridgeOpenLink,T as bridgeOpenPopup,W as bridgeOpenScanQrPopup,I as bridgeOpenTgLink,D as bridgeReadTextFromClipboard,N as bridgeReady,M as bridgeRequestPhone,V as bridgeRequestTheme,G as bridgeRequestViewport,Q as bridgeRequestWriteAccess,F as bridgeSetBackgroundColor,z as bridgeSetHeaderColor,X as bridgeSetupBackButton,Z as bridgeSetupClosingBehavior,te as bridgeSetupMainButton,ae as bridgeSetupSettingsButton,oe as bridgeSwitchInlineQuery,ie as bridgeTriggerHapticFeedback,a as createIsViewportChanged,pe as debug,we as listener,de as sender,d as supportClose,b as supportCloseScanQrPopup,g as supportDataSend,m as supportExpand,f as supportIframeReady,q as supportIframeWillReload,S as supportInvokeCustomMethod,P as supportOpenInvoice,R as supportOpenLink,E as supportOpenPopup,C as supportOpenScanQrPopup,B as supportOpenTgLink,L as supportReadTextFromClipboard,A as supportReady,U as supportRequestPhone,$ as supportRequestTheme,J as supportRequestViewport,j as supportRequestWriteAccess,H as supportSetBackgroundColor,K as supportSetHeaderColor,Y as supportSetupBackButton,ee as supportSetupClosingBehavior,se as supportSetupMainButton,ne as supportSetupSettingsButton,re as supportSwitchInlineQuery,_e as supportTriggerHapticFeedback};
1
+ import{getThemeParams as e}from"utils";import{createSignal as t,onMount as s,onCleanup as a}from"solid-js";const o=()=>{const[e,o]=t({height:0,is_expanded:!1,is_state_stable:!1}),n=e=>o(e);return s((()=>{Te(ke,n),ce(ze)})),a((()=>{Ee(ke,n)})),e},n="web",r="phone",i="desktop",_="not_supported",p=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?r:["tdesktop","macos"].includes(t)?i:n})())},u=()=>Math.random().toString(36).substring(3,9),d=()=>c()?(ce(Ne),{status:!0}):(ue(Ne,1),{status:_}),c=()=>p(0,[n,i,r]),b=()=>l()?(ce(Ae),{status:!0}):(ue(Ae,1),{status:_}),l=()=>p(6.4,[r]),g=e=>w()?(ce(Me,e),{status:!0}):(ue(Me,1),{status:_}),w=()=>p(0,[n,i,r]),m=()=>h()?(ce(Ue),{status:!0}):(ue(Ue,1),{status:_}),h=()=>p(0,[r]),f=e=>v()?(ce(Ve,e),{status:!0}):(ue(Ve,1),{status:_}),v=()=>p(0,[n]),q=()=>y()?(ce(Ve),{status:!0}):(ue(Ve,1),{status:_}),y=()=>p(0,[n]),x="web_app_invoke_custom_method",P=async e=>S()?(void 0===e.req_id&&(e.req_id=u()),ce(x,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),Ee(ge,a))};Te(ge,a)}))):(ue(x,1),{status:_}),S=()=>p(6.9,[n,i,r]),k=e=>O()?(ce(Ge,e),{status:!0}):(ue(Ge,1),{status:_}),O=()=>p(6.1,[n,i,r]),R=e=>T()?(ce(Je,e),{status:!0}):(ue(Je,1),{status:_}),T=()=>p(6.4,[n,i,r]),E=async e=>W()?(e.title.length>64&&ue(Qe,3),e.message.length<1&&ue(Qe,4),e.message.length>256&&ue(Qe,5),e.buttons.length<1&&ue(Qe,6),e.buttons.length>3&&ue(Qe,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&ue(Qe,8),ce(Qe,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),Ee(fe,a)};Te(fe,a)}))):(ue(Qe,1),{status:_}),W=()=>p(6.2,[n,i,r]),C=async e=>I()?(ce(Be,e),new Promise(((t,s)=>{We(qe,(s=>{e.is_close&&b(),t({status:!0,data:s})})),We(ye,(()=>{t({status:"closed"})}))}))):(ue(Be,1),{status:_}),I=()=>p(6.4,[r]),B=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),D()?(ce(je,e),{status:!0}):(ue(je,1),{status:_})),D=()=>p(7,[n,i,r]),L=async e=>N()?(void 0===e.req_id&&(e.req_id=u()),ce(De,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),Ee(le,a))};Te(le,a)}))):(ue(De,1),{status:_}),N=()=>p(6.4,[n,i,r]),A=()=>M()?(ce(Fe),{status:!0}):(ue(Fe,1),{status:_}),M=()=>p(6.9,[n,i,r]),U=async()=>V()?(ce(Le),new Promise(((e,t)=>{We(he,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(ue(Le,1),{status:_}),V=()=>p(6.9,[n,i,r]),$=()=>G()?(ce(He),{status:!0}):(ue(He,1),{status:_}),G=()=>p(0,[n,i,r]),J=()=>Q()?(ce(ze),{status:!0}):(ue(ze,1),{status:_}),Q=()=>p(0,[n,i,r]),j=()=>F()?(ce(Ke),{status:!0}):(ue(Ke,1),{status:_}),F=()=>p(6.9,[n,i,r]),H=e=>z()?(ce(Xe,e),{status:!0}):(ue(Xe,1),{status:_}),z=()=>p(6.1,[n,i,r]),K=e=>X()?(ce(Ye,e),{status:!0}):(ue(Ye,1),{status:_}),X=()=>p(6.1,[n,i,r]),Y=e=>Z()?(ce(Ze,e),{status:!0}):(ue(Ze,1),{status:_}),Z=()=>p(6.1,[n,i,r]),ee=e=>te()?(ce(et,e),{status:!0}):(ue(et,1),{status:_}),te=()=>p(0,[n,i,r]),se=e=>ae()?(ce(tt,e),{status:!0}):(ue(tt,1),{status:_}),ae=()=>p(0,[n,i,r]),oe=e=>ne()?(ce(st,e),{status:!0}):(ue(st,1),{status:_}),ne=()=>p(6.1,[n,i,r]),re=e=>ie()?(e.query.length>256&&ue(at,9),ce(at,e),{status:!0}):(ue(at,1),{status:_}),ie=()=>p(6.7,[n,i,r]),_e=e=>pe()?(ce(ot,e),{status:!0}):(ue(ot,1),{status:_}),pe=()=>p(6.1,[r]);var ue=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const de=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return ue("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var ce=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const be="back_button_pressed",le="clipboard_text_received",ge="custom_method_invoked",we="invoice_closed",me="main_button_pressed",he="phone_requested",fe="popup_closed",ve="reload_iframe",qe="qr_text_received",ye="scan_qr_popup_closed",xe="set_custom_style",Pe="settings_button_pressed",Se="theme_changed",ke="viewport_changed",Oe="write_access_requested",Re=((e=new Map)=>({once:(t,s,a=e.get(t),o=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(o):e.set(t,[o]),on:(t,s,a=e.get(t))=>a?a.push(s):e.set(t,[s]),off:(t,s,a=e.get(t))=>a&&s?a.splice(a.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,a=e.get(t)||[])=>{for(const e of a)e(s)}}))();(()=>{function t(t,s){t===Se&&(s.theme_params=e(s.theme_params)),Re.emit(t,s),Re.emit("*",{name:t,data:s})}window.TelegramGameProxy_receiveEvent=t,window.Telegram={WebView:{receiveEvent:t}},window.TelegramGameProxy={receiveEvent:t}})();const Te=(e,t)=>{Re.on(e,t)},Ee=(e,t)=>{Re.off(e,t)},We=(e,t)=>{Re.once(e,t)};var Ce=Object.freeze({__proto__:null,off:Ee,on:Te,once:We});const Ie="web_app_invoke_custom_method",Be="web_app_open_scan_qr_popup",De="web_app_read_text_from_clipboard",Le="web_app_request_phone",Ne="web_app_close",Ae="web_app_close_scan_qr_popup",Me="web_app_data_send",Ue="web_app_expand",Ve="iframe_ready",$e="iframe_will_reload",Ge="web_app_open_invoice",Je="web_app_open_link",Qe="web_app_open_popup",je="web_app_open_tg_link",Fe="web_app_ready",He="web_app_request_theme",ze="web_app_request_viewport",Ke="web_app_request_write_access",Xe="web_app_set_background_color",Ye="web_app_set_header_color",Ze="web_app_setup_back_button",et="web_app_setup_closing_behavior",tt="web_app_setup_main_button",st="web_app_setup_settings_button",at="web_app_switch_inline_query",ot="web_app_trigger_haptic_feedback";export{be as EventBackButtonPressed,le as EventClipboardTextReceived,ge as EventCustomMethodInvoked,we as EventInvoiceClosed,me as EventMainButtonPressed,he as EventPhoneRequested,fe as EventPopupClosed,qe as EventQrTextReceived,ve as EventReloadIframe,ye as EventScanQrPopupClosed,xe as EventSetCustomStyle,Pe as EventSettingsButtonPressed,Se as EventThemeChanged,ke as EventViewportChanged,Oe as EventWriteAccessRequested,Ne as MethodClose,Ae as MethodCloseScanQrPopup,Me as MethodDataSend,Ue as MethodExpand,Ve as MethodIframeReady,$e as MethodIframeWillReload,Ie as MethodInvokeCustomMethod,Ge as MethodOpenInvoice,Je as MethodOpenLink,Qe as MethodOpenPopup,Be as MethodOpenScanQrPopup,je as MethodOpenTgLink,De as MethodReadTextFromClipboard,Fe as MethodReady,Le as MethodRequestPhone,He as MethodRequestTheme,ze as MethodRequestViewport,Ke as MethodRequestWriteAccess,Xe as MethodSetBackgroundColor,Ye as MethodSetHeaderColor,Ze as MethodSetupBackButton,et as MethodSetupClosingBehavior,tt as MethodSetupMainButton,st as MethodSetupSettingsButton,at as MethodSwitchInlineQuery,ot as MethodTriggerHapticFeedback,_ as NOT_SUPPORTED,i as TG_DESKTOP,r as TG_PHONE,n as TG_WEB,d as bridgeClose,b as bridgeCloseScanQrPopup,g as bridgeDataSend,m as bridgeExpand,de as bridgeGetInitData,f as bridgeIframeReady,q as bridgeIframeWillReload,P as bridgeInvokeCustomMethod,k as bridgeOpenInvoice,R as bridgeOpenLink,E as bridgeOpenPopup,C as bridgeOpenScanQrPopup,B as bridgeOpenTgLink,L as bridgeReadTextFromClipboard,A as bridgeReady,U as bridgeRequestPhone,$ as bridgeRequestTheme,J as bridgeRequestViewport,j as bridgeRequestWriteAccess,H as bridgeSetBackgroundColor,K as bridgeSetHeaderColor,Y as bridgeSetupBackButton,ee as bridgeSetupClosingBehavior,se as bridgeSetupMainButton,oe as bridgeSetupSettingsButton,re as bridgeSwitchInlineQuery,_e as bridgeTriggerHapticFeedback,o as createIsViewportChanged,ue as debug,Ce as listener,ce as sender,c as supportClose,l as supportCloseScanQrPopup,w as supportDataSend,h as supportExpand,v as supportIframeReady,y as supportIframeWillReload,S as supportInvokeCustomMethod,O as supportOpenInvoice,T as supportOpenLink,W as supportOpenPopup,I as supportOpenScanQrPopup,D as supportOpenTgLink,N as supportReadTextFromClipboard,M as supportReady,V as supportRequestPhone,G as supportRequestTheme,Q as supportRequestViewport,F as supportRequestWriteAccess,z as supportSetBackgroundColor,X as supportSetHeaderColor,Z as supportSetupBackButton,te as supportSetupClosingBehavior,ae as supportSetupMainButton,ne as supportSetupSettingsButton,ie as supportSwitchInlineQuery,pe as supportTriggerHapticFeedback};
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "twa_sdk",
2
+ "name": "@apiteam/twa-bridge/solid",
3
3
  "main": "index.js",
4
4
  "module": "index.mjs",
5
5
  "typings": "index.d.ts",