@apiteam/twa-bridge 7.1.11 → 7.1.13

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.1.11",
3
+ "version": "7.1.13",
4
4
  "description": "Telegram bridge",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",
package/solid/index.d.ts CHANGED
@@ -250,7 +250,7 @@ type ThemeParams = {
250
250
  subtitle_text_color: string;
251
251
  destructive_text_color: string;
252
252
  };
253
- declare const getThemeParams: (theme_params: ThemeParams) => Record<string, string>;
253
+ declare const getThemeParams: (theme_params?: ThemeParams) => ThemeParams;
254
254
 
255
255
  type Sender = (eventType: string, eventData?: any) => void;
256
256
  declare const sender: Sender;
@@ -470,6 +470,8 @@ declare namespace listener {
470
470
  export { type listener_EventsData as EventsData, listener_off as off, listener_on as on, listener_once as once };
471
471
  }
472
472
 
473
+ declare const getAppData: () => string | null;
474
+
473
475
  type Value = {
474
476
  viewport?: EventsData[typeof EventViewportChanged] & {
475
477
  safe_area_bottom: number;
@@ -498,4 +500,4 @@ declare const EventThemeChanged = "theme_changed";
498
500
  declare const EventViewportChanged = "viewport_changed";
499
501
  declare const EventWriteAccessRequested = "write_access_requested";
500
502
 
501
- export { ContextTwa, EventBackButtonPressed, EventClipboardTextReceived, EventCustomMethodInvoked, EventInvoiceClosed, EventMainButtonPressed, EventPhoneRequested, EventPopupClosed, EventQrTextReceived, EventReloadIframe, EventScanQrPopupClosed, EventSetCustomStyle, EventSettingsButtonPressed, EventThemeChanged, EventViewportChanged, EventWriteAccessRequested, type EventsData, type GetInitData, MethodClose, MethodCloseScanQrPopup, MethodDataSend, MethodExpand, MethodIframeReady, MethodIframeWillReload, MethodInvokeCustomMethod, MethodOpenInvoice, MethodOpenLink, MethodOpenPopup, MethodOpenScanQrPopup, MethodOpenTgLink, MethodReadTextFromClipboard, MethodReady, MethodRequestPhone, MethodRequestTheme, MethodRequestViewport, MethodRequestWriteAccess, MethodSetBackgroundColor, MethodSetBottomBarColor, MethodSetHeaderColor, MethodSetupBackButton, MethodSetupClosingBehavior, MethodSetupMainButton, MethodSetupSettingsButton, MethodSetupSwipeBehavior, MethodSwitchInlineQuery, MethodTriggerHapticFeedback, NOT_SUPPORTED, type PopupButton, ProviderTWA, type SenderData, TG_DESKTOP, TG_PHONE, TG_WEB, type ThemeParams, close as bridgeClose, closeScanQrPopup as bridgeCloseScanQrPopup, dataSend as bridgeDataSend, expand as bridgeExpand, getInitData as bridgeGetInitData, getThemeParams as bridgeGetThemeParams, 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, sender as bridgeSend, sessionStorageGet as bridgeSessionStorageGet, sessionStorageSet as bridgeSessionStorageSet, setBackgroundColor as bridgeSetBackgroundColor, setBottomBarColor as bridgeSetBottomBarColor, setHeaderColor as bridgeSetHeaderColor, setupBackButton as bridgeSetupBackButton, setupClosingBehavior as bridgeSetupClosingBehavior, setupMainButton as bridgeSetupMainButton, setupSettingsButton as bridgeSetupSettingsButton, setupSwipeBehavior as bridgeSetupSwipeBehavior, switchInlineQuery as bridgeSwitchInlineQuery, triggerHapticFeedback as bridgeTriggerHapticFeedback, createIsViewportChanged, debug, getPlatform, listener, sender, supportClose, supportCloseScanQrPopup, supportDataSend, supportExpand, supportIframeReady, supportIframeWillReload, supportInvokeCustomMethod, supportOpenInvoice, supportOpenLink, supportOpenPopup, supportOpenScanQrPopup, supportOpenTgLink, supportReadTextFromClipboard, supportReady, supportRequestPhone, supportRequestTheme, supportRequestViewport, supportRequestWriteAccess, supportSessionStorageGet, supportSessionStorageSet, supportSetBackgroundColor, supportSetBottomBarColor, supportSetHeaderColor, supportSetupBackButton, supportSetupClosingBehavior, supportSetupMainButton, supportSetupSettingsButton, supportSetupSwipeBehavior, supportSwitchInlineQuery, supportTriggerHapticFeedback };
503
+ export { ContextTwa, EventBackButtonPressed, EventClipboardTextReceived, EventCustomMethodInvoked, EventInvoiceClosed, EventMainButtonPressed, EventPhoneRequested, EventPopupClosed, EventQrTextReceived, EventReloadIframe, EventScanQrPopupClosed, EventSetCustomStyle, EventSettingsButtonPressed, EventThemeChanged, EventViewportChanged, EventWriteAccessRequested, type EventsData, type GetInitData, MethodClose, MethodCloseScanQrPopup, MethodDataSend, MethodExpand, MethodIframeReady, MethodIframeWillReload, MethodInvokeCustomMethod, MethodOpenInvoice, MethodOpenLink, MethodOpenPopup, MethodOpenScanQrPopup, MethodOpenTgLink, MethodReadTextFromClipboard, MethodReady, MethodRequestPhone, MethodRequestTheme, MethodRequestViewport, MethodRequestWriteAccess, MethodSetBackgroundColor, MethodSetBottomBarColor, MethodSetHeaderColor, MethodSetupBackButton, MethodSetupClosingBehavior, MethodSetupMainButton, MethodSetupSettingsButton, MethodSetupSwipeBehavior, MethodSwitchInlineQuery, MethodTriggerHapticFeedback, NOT_SUPPORTED, type PopupButton, ProviderTWA, type SenderData, TG_DESKTOP, TG_PHONE, TG_WEB, type ThemeParams, close as bridgeClose, closeScanQrPopup as bridgeCloseScanQrPopup, dataSend as bridgeDataSend, expand as bridgeExpand, getInitData as bridgeGetInitData, getThemeParams as bridgeGetThemeParams, 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, sender as bridgeSend, sessionStorageGet as bridgeSessionStorageGet, sessionStorageSet as bridgeSessionStorageSet, setBackgroundColor as bridgeSetBackgroundColor, setBottomBarColor as bridgeSetBottomBarColor, setHeaderColor as bridgeSetHeaderColor, setupBackButton as bridgeSetupBackButton, setupClosingBehavior as bridgeSetupClosingBehavior, setupMainButton as bridgeSetupMainButton, setupSettingsButton as bridgeSetupSettingsButton, setupSwipeBehavior as bridgeSetupSwipeBehavior, switchInlineQuery as bridgeSwitchInlineQuery, triggerHapticFeedback as bridgeTriggerHapticFeedback, createIsViewportChanged, debug, getAppData, getPlatform, listener, sender, supportClose, supportCloseScanQrPopup, supportDataSend, supportExpand, supportIframeReady, supportIframeWillReload, supportInvokeCustomMethod, supportOpenInvoice, supportOpenLink, supportOpenPopup, supportOpenScanQrPopup, supportOpenTgLink, supportReadTextFromClipboard, supportReady, supportRequestPhone, supportRequestTheme, supportRequestViewport, supportRequestWriteAccess, supportSessionStorageGet, supportSessionStorageSet, supportSetBackgroundColor, supportSetBottomBarColor, supportSetHeaderColor, supportSetupBackButton, supportSetupClosingBehavior, supportSetupMainButton, supportSetupSettingsButton, supportSetupSwipeBehavior, supportSwitchInlineQuery, supportTriggerHapticFeedback };
package/solid/index.js CHANGED
@@ -1,491 +1 @@
1
- 'use strict'
2
- var e = require('solid-js'),
3
- t = require('solid-js/store')
4
- const s = 'web',
5
- o = 'phone',
6
- r = 'desktop',
7
- p = () => {
8
- const e = window.location.hash.slice(1),
9
- t = new URLSearchParams(e).get('tgWebAppPlatform') ?? 'ios'
10
- return ['android', 'ios'].includes(t)
11
- ? o
12
- : ['tdesktop', 'macos'].includes(t)
13
- ? r
14
- : s
15
- },
16
- a = 'not_supported',
17
- n = (e, t) => {
18
- const s = new URLSearchParams(window.location.hash.slice(1)).get(
19
- 'tgWebAppVersion'
20
- )
21
- return (
22
- Number(s?.replace('.', '')) >= Number(String(e)?.replace('.', '')) &&
23
- -1 !== t.indexOf(p())
24
- )
25
- },
26
- i = () => Math.random().toString(36).substring(3, 9),
27
- u = e => {
28
- var t
29
- if ((t = /^\s*#([0-9a-f]{6})\s*$/i.exec((e += ''))))
30
- return '#' + t[1].toLowerCase()
31
- if ((t = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e)))
32
- return ('#' + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]).toLowerCase()
33
- if (
34
- (t =
35
- /^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(
36
- e
37
- ))
38
- ) {
39
- var s = parseInt(t[1]),
40
- o = parseInt(t[2]),
41
- r = parseInt(t[3])
42
- return (
43
- '#' +
44
- ((s < 16 ? '0' : '') + s.toString(16)) +
45
- ((o < 16 ? '0' : '') + o.toString(16)) +
46
- ((r < 16 ? '0' : '') + r.toString(16))
47
- )
48
- }
49
- return !1
50
- },
51
- d = e => {
52
- '#1c1c1d' == e.bg_color &&
53
- e.bg_color == e.secondary_bg_color &&
54
- (e.secondary_bg_color = '#2c2c2e')
55
- const t = window.location.hash.slice(1),
56
- s = new URLSearchParams(t)
57
- var o = JSON.parse(s.get('tgWebAppThemeParams') ?? '')
58
- for (var r of Object.keys(e)) {
59
- var p = u(e[r])
60
- 'string' == typeof p && (o[r] = p)
61
- }
62
- return o
63
- },
64
- _ = e => (c() ? (le(ve, e), { status: !0 }) : (xe(ve, 1), { status: a })),
65
- c = () => n(0, [s, r, o]),
66
- x = e => (g() ? (le(Se, e), { status: !0 }) : (xe(Se, 1), { status: a })),
67
- g = () => n(6.4, [o]),
68
- l = e => (h() ? (le(fe, e), { status: !0 }) : (xe(fe, 1), { status: a })),
69
- h = () => n(0, [s, r, o]),
70
- b = e => (w() ? (le(ye, e), { status: !0 }) : (xe(ye, 1), { status: a })),
71
- w = () => n(0, [o]),
72
- m = e => (v() ? (le(Me, e), { status: !0 }) : (xe(Me, 1), { status: a })),
73
- v = () => n(0, [s]),
74
- S = () => (f() ? (le(Me), { status: !0 }) : (xe(Me, 1), { status: a })),
75
- f = () => n(0, [s]),
76
- y = async e =>
77
- M()
78
- ? (void 0 === e.req_id && (e.req_id = i()),
79
- le(he, e),
80
- new Promise((t, s) => {
81
- const o = s => {
82
- s.req_id === e.req_id && (t({ status: !0, data: s }), et($e, o))
83
- }
84
- Ze($e, o)
85
- }))
86
- : (xe(he, 1), { status: a }),
87
- M = () => n(6.9, [s, r, o]),
88
- P = e => (C() ? (le(Ce, e), { status: !0 }) : (xe(Ce, 1), { status: a })),
89
- C = () => n(6.1, [s, r, o]),
90
- q = e => (R() ? (le(qe, e), { status: !0 }) : (xe(qe, 1), { status: a })),
91
- R = () => n(6.4, [s, r, o]),
92
- k = async e =>
93
- B()
94
- ? (e.title.length > 64 && xe(Re, 3),
95
- e.message.length < 1 && xe(Re, 4),
96
- e.message.length > 256 && xe(Re, 5),
97
- e.buttons.length < 1 && xe(Re, 6),
98
- e.buttons.length > 3 && xe(Re, 7),
99
- void 0 !== e.buttons.find(e => e.text?.match(/^(ok|close|cancel)$/g)) &&
100
- xe(Re, 8),
101
- le(Re, e),
102
- new Promise((t, s) => {
103
- const o = s => {
104
- t({
105
- status: !!e.buttons.find(e => e.id === s?.button_id),
106
- data: s,
107
- }),
108
- et(Fe, o)
109
- }
110
- Ze(Fe, o)
111
- }))
112
- : (xe(Re, 1), { status: a }),
113
- B = () => n(6.2, [s, r, o]),
114
- O = async e =>
115
- T()
116
- ? (le(be, e),
117
- new Promise((t, s) => {
118
- tt(Ue, s => {
119
- e.is_close && x(), t({ status: !0, data: s })
120
- }),
121
- tt(ze, () => {
122
- t({ status: 'closed' })
123
- })
124
- }))
125
- : (xe(be, 1), { status: a }),
126
- T = () => n(6.4, [o]),
127
- E = e => (
128
- '/' !== e.path_full[0] && (e.path_full = '/' + e.path_full),
129
- I() ? (le(ke, e), { status: !0 }) : (xe(ke, 1), { status: a })
130
- ),
131
- I = () => n(7, [s, r, o]),
132
- W = async e =>
133
- L()
134
- ? (e || (e = { req_id: void 0 }),
135
- void 0 === e.req_id && (e.req_id = i()),
136
- le(we, e),
137
- new Promise((t, s) => {
138
- const o = s => {
139
- s.req_id === e?.req_id && (t({ status: !0, data: s }), et(Je, o))
140
- }
141
- Ze(Je, o)
142
- }))
143
- : (xe(we, 1), { status: a }),
144
- L = () => n(6.4, [s, r, o]),
145
- N = e => (D() ? (le(Be, e), { status: !0 }) : (xe(Be, 1), { status: a })),
146
- D = () => n(6.9, [s, r, o]),
147
- Q = async () =>
148
- A()
149
- ? (le(me),
150
- new Promise((e, t) => {
151
- tt(je, t => {
152
- 'sent' === t.status && e({ status: !0 }), e({ status: !1 })
153
- })
154
- }))
155
- : (xe(me, 1), { status: a }),
156
- A = () => n(6.9, [s, r, o]),
157
- G = e => (H() ? (le(Oe, e), { status: !0 }) : (xe(Oe, 1), { status: a })),
158
- H = () => n(0, [s, r, o]),
159
- V = e => (J() ? (le(Te, e), { status: !0 }) : (xe(Te, 1), { status: a })),
160
- J = () => n(0, [s, r, o]),
161
- $ = () => (j() ? (le(Ee), { status: !0 }) : (xe(Ee, 1), { status: a })),
162
- j = () => n(6.9, [s, r, o]),
163
- F = e => (U() ? (le(Ie, e), { status: !0 }) : (xe(Ie, 1), { status: a })),
164
- U = () => n(6.1, [s, r, o]),
165
- z = e => (K() ? (le(We, e), { status: !0 }) : (xe(We, 1), { status: a })),
166
- K = () => n(6.1, [s, r, o]),
167
- X = e =>
168
- Y()
169
- ? (le(Le, { color: e?.color || e?.color_key }), { status: !0 })
170
- : (xe(Le, 1), { status: a }),
171
- Y = () => n(710, [s, r, o]),
172
- Z = e => (ee() ? (le(Ne, e), { status: !0 }) : (xe(Ne, 1), { status: a })),
173
- ee = () => n(6.1, [s, r, o]),
174
- te = e => (se() ? (le(De, e), { status: !0 }) : (xe(De, 1), { status: a })),
175
- se = () => n(0, [s, r, o]),
176
- oe = e => (re() ? (le(Qe, e), { status: !0 }) : (xe(Qe, 1), { status: a })),
177
- re = () => n(0, [s, r, o]),
178
- pe = e => (ae() ? (le(Ae, e), { status: !0 }) : (xe(Ae, 1), { status: a })),
179
- ae = () => n(6.1, [s, r, o]),
180
- ne = e =>
181
- ie()
182
- ? (e.query.length > 256 && xe(Ge, 9), le(Ge, e), { status: !0 })
183
- : (xe(Ge, 1), { status: a }),
184
- ie = () => n(6.7, [s, r, o]),
185
- ue = e => (de() ? (le(He, e), { status: !0 }) : (xe(He, 1), { status: a })),
186
- de = () => n(6.1, [o]),
187
- _e = e => (ce() ? (le(Ve, e), { status: !0 }) : (xe(Ve, 1), { status: a })),
188
- ce = () => n(7.7, [s, r, o])
189
- var xe = (e, t) => {
190
- 'development' === process.env.NODE_ENV &&
191
- console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)
192
- }
193
- const ge = () => {
194
- const e = window.location.hash.slice(1),
195
- t = new URLSearchParams(e).get('tgWebAppData')
196
- if (!t) return void xe('getInitData', 2)
197
- const s = new URLSearchParams(t)
198
- let o = {}
199
- return (
200
- s.forEach((e, t) => {
201
- if (((o[t] = e), void 0 !== t.match(/^(chat|receiver|user)$/g)))
202
- try {
203
- o[t] = JSON.parse(e)
204
- } catch {}
205
- }),
206
- o
207
- )
208
- }
209
- var le = (e, t) => {
210
- if (window.TelegramWebviewProxy)
211
- window.TelegramWebviewProxy.postEvent(e, JSON.stringify(t))
212
- else if (window.external && 'notify' in window.external)
213
- window.external.notify(JSON.stringify({ eventType: e, eventData: t }))
214
- else
215
- try {
216
- '*',
217
- window.parent.postMessage(
218
- JSON.stringify({ eventType: e, eventData: t }),
219
- '*'
220
- )
221
- } catch (e) {
222
- xe('postMessage Iframe', 10)
223
- }
224
- }
225
- const he = 'web_app_invoke_custom_method',
226
- be = 'web_app_open_scan_qr_popup',
227
- we = 'web_app_read_text_from_clipboard',
228
- me = 'web_app_request_phone',
229
- ve = 'web_app_close',
230
- Se = 'web_app_close_scan_qr_popup',
231
- fe = 'web_app_data_send',
232
- ye = 'web_app_expand',
233
- Me = 'iframe_ready',
234
- Pe = 'iframe_will_reload',
235
- Ce = 'web_app_open_invoice',
236
- qe = 'web_app_open_link',
237
- Re = 'web_app_open_popup',
238
- ke = 'web_app_open_tg_link',
239
- Be = 'web_app_ready',
240
- Oe = 'web_app_request_theme',
241
- Te = 'web_app_request_viewport',
242
- Ee = 'web_app_request_write_access',
243
- Ie = 'web_app_set_background_color',
244
- We = 'web_app_set_header_color',
245
- Le = 'web_app_set_bottom_bar_color',
246
- Ne = 'web_app_setup_back_button',
247
- De = 'web_app_setup_closing_behavior',
248
- Qe = 'web_app_setup_main_button',
249
- Ae = 'web_app_setup_settings_button',
250
- Ge = 'web_app_switch_inline_query',
251
- He = 'web_app_trigger_haptic_feedback',
252
- Ve = 'web_app_setup_swipe_behavior'
253
- const Je = 'clipboard_text_received',
254
- $e = 'custom_method_invoked',
255
- je = 'phone_requested',
256
- Fe = 'popup_closed',
257
- Ue = 'qr_text_received',
258
- ze = 'scan_qr_popup_closed',
259
- Ke = 'theme_changed',
260
- Xe = 'viewport_changed',
261
- Ye = ((e = new Map()) => ({
262
- once: (
263
- t,
264
- s,
265
- o = e.get(t),
266
- r = e => {
267
- s(e), o && o.splice(o.indexOf(s) >>> 0, 1)
268
- }
269
- ) => (o ? o.push(r) : e.set(t, [r])),
270
- on: (t, s, o = e.get(t)) => (o ? o.push(s) : e.set(t, [s])),
271
- off: (t, s, o = e.get(t)) =>
272
- o && s ? o.splice(o.indexOf(s) >>> 0, 1) : e.set(t, []),
273
- emit: (t, s, o = e.get(t) || []) => {
274
- for (const e of o) e(s)
275
- },
276
- }))()
277
- ;(() => {
278
- function e(e, t) {
279
- e === Ke && (t.theme_params = d(t.theme_params)),
280
- Ye.emit(e, t),
281
- Ye.emit('*', { name: e, data: t })
282
- }
283
- ;(window.TelegramGameProxy_receiveEvent = e),
284
- (window.Telegram = { WebView: { receiveEvent: e } }),
285
- (window.TelegramGameProxy = { receiveEvent: e })
286
- })()
287
- const Ze = (e, t) => {
288
- Ye.on(e, t)
289
- },
290
- et = (e, t) => {
291
- Ye.off(e, t)
292
- },
293
- tt = (e, t) => {
294
- Ye.once(e, t)
295
- }
296
- var st = Object.freeze({ __proto__: null, off: et, on: Ze, once: tt })
297
- const ot = e.createContext({ viewport: void 0, theme: void 0, init: void 0 })
298
- ;(exports.ContextTwa = ot),
299
- (exports.EventBackButtonPressed = 'back_button_pressed'),
300
- (exports.EventClipboardTextReceived = Je),
301
- (exports.EventCustomMethodInvoked = $e),
302
- (exports.EventInvoiceClosed = 'invoice_closed'),
303
- (exports.EventMainButtonPressed = 'main_button_pressed'),
304
- (exports.EventPhoneRequested = je),
305
- (exports.EventPopupClosed = Fe),
306
- (exports.EventQrTextReceived = Ue),
307
- (exports.EventReloadIframe = 'reload_iframe'),
308
- (exports.EventScanQrPopupClosed = ze),
309
- (exports.EventSetCustomStyle = 'set_custom_style'),
310
- (exports.EventSettingsButtonPressed = 'settings_button_pressed'),
311
- (exports.EventThemeChanged = Ke),
312
- (exports.EventViewportChanged = Xe),
313
- (exports.EventWriteAccessRequested = 'write_access_requested'),
314
- (exports.MethodClose = ve),
315
- (exports.MethodCloseScanQrPopup = Se),
316
- (exports.MethodDataSend = fe),
317
- (exports.MethodExpand = ye),
318
- (exports.MethodIframeReady = Me),
319
- (exports.MethodIframeWillReload = Pe),
320
- (exports.MethodInvokeCustomMethod = he),
321
- (exports.MethodOpenInvoice = Ce),
322
- (exports.MethodOpenLink = qe),
323
- (exports.MethodOpenPopup = Re),
324
- (exports.MethodOpenScanQrPopup = be),
325
- (exports.MethodOpenTgLink = ke),
326
- (exports.MethodReadTextFromClipboard = we),
327
- (exports.MethodReady = Be),
328
- (exports.MethodRequestPhone = me),
329
- (exports.MethodRequestTheme = Oe),
330
- (exports.MethodRequestViewport = Te),
331
- (exports.MethodRequestWriteAccess = Ee),
332
- (exports.MethodSetBackgroundColor = Ie),
333
- (exports.MethodSetBottomBarColor = Le),
334
- (exports.MethodSetHeaderColor = We),
335
- (exports.MethodSetupBackButton = Ne),
336
- (exports.MethodSetupClosingBehavior = De),
337
- (exports.MethodSetupMainButton = Qe),
338
- (exports.MethodSetupSettingsButton = Ae),
339
- (exports.MethodSetupSwipeBehavior = Ve),
340
- (exports.MethodSwitchInlineQuery = Ge),
341
- (exports.MethodTriggerHapticFeedback = He),
342
- (exports.NOT_SUPPORTED = a),
343
- (exports.ProviderTWA = s => {
344
- const [o, r] = t.createStore({
345
- viewport: void 0,
346
- theme: void 0,
347
- init: void 0,
348
- })
349
- return (
350
- e.onMount(() => {
351
- const t = () => {
352
- r('init', ge())
353
- }
354
- t()
355
- const s = e => {
356
- t(),
357
- r('viewport', {
358
- ...e,
359
- safe_area_bottom:
360
- e.is_expanded && e.is_state_stable
361
- ? window.outerHeight - e.height
362
- : 0,
363
- })
364
- }
365
- Ze(Xe, s), V()
366
- const o = e => {
367
- t(), r('theme', e)
368
- }
369
- Ze(Ke, o),
370
- V(),
371
- e.onCleanup(() => {
372
- et(Xe, s), et(Ke, o)
373
- })
374
- }),
375
- s.children
376
- )
377
- }),
378
- (exports.TG_DESKTOP = r),
379
- (exports.TG_PHONE = o),
380
- (exports.TG_WEB = s),
381
- (exports.bridgeClose = _),
382
- (exports.bridgeCloseScanQrPopup = x),
383
- (exports.bridgeDataSend = l),
384
- (exports.bridgeExpand = b),
385
- (exports.bridgeGetInitData = ge),
386
- (exports.bridgeGetThemeParams = d),
387
- (exports.bridgeIframeReady = m),
388
- (exports.bridgeIframeWillReload = S),
389
- (exports.bridgeInvokeCustomMethod = y),
390
- (exports.bridgeOpenInvoice = P),
391
- (exports.bridgeOpenLink = q),
392
- (exports.bridgeOpenPopup = k),
393
- (exports.bridgeOpenScanQrPopup = O),
394
- (exports.bridgeOpenTgLink = E),
395
- (exports.bridgeReadTextFromClipboard = W),
396
- (exports.bridgeReady = N),
397
- (exports.bridgeRequestPhone = Q),
398
- (exports.bridgeRequestTheme = G),
399
- (exports.bridgeRequestViewport = V),
400
- (exports.bridgeRequestWriteAccess = $),
401
- (exports.bridgeSend = le),
402
- (exports.bridgeSessionStorageGet = ({ key: e }) => {
403
- try {
404
- return {
405
- is_json: !0,
406
- value: JSON.parse(
407
- window.sessionStorage.getItem('__telegram__' + e) ?? ''
408
- ),
409
- status: !0,
410
- }
411
- } catch (t) {
412
- return {
413
- is_json: !1,
414
- value: window.sessionStorage.getItem('__telegram__' + e) ?? '',
415
- status: !0,
416
- }
417
- }
418
- }),
419
- (exports.bridgeSessionStorageSet = ({ key: e, value: t }) => {
420
- try {
421
- return (
422
- window.sessionStorage.setItem('__telegram__' + e, JSON.stringify(t)),
423
- { status: !0 }
424
- )
425
- } catch (s) {
426
- return (
427
- window.sessionStorage.setItem('__telegram__' + e, t), { status: !0 }
428
- )
429
- }
430
- }),
431
- (exports.bridgeSetBackgroundColor = F),
432
- (exports.bridgeSetBottomBarColor = X),
433
- (exports.bridgeSetHeaderColor = z),
434
- (exports.bridgeSetupBackButton = Z),
435
- (exports.bridgeSetupClosingBehavior = te),
436
- (exports.bridgeSetupMainButton = oe),
437
- (exports.bridgeSetupSettingsButton = pe),
438
- (exports.bridgeSetupSwipeBehavior = _e),
439
- (exports.bridgeSwitchInlineQuery = ne),
440
- (exports.bridgeTriggerHapticFeedback = ue),
441
- (exports.createIsViewportChanged = () => {
442
- const [t, s] = e.createSignal({
443
- height: 0,
444
- is_expanded: !1,
445
- is_state_stable: !1,
446
- }),
447
- o = e => s(e)
448
- return (
449
- e.onMount(() => {
450
- Ze(Xe, o), le(Te)
451
- }),
452
- e.onCleanup(() => {
453
- et(Xe, o)
454
- }),
455
- t
456
- )
457
- }),
458
- (exports.debug = xe),
459
- (exports.getPlatform = p),
460
- (exports.listener = st),
461
- (exports.sender = le),
462
- (exports.supportClose = c),
463
- (exports.supportCloseScanQrPopup = g),
464
- (exports.supportDataSend = h),
465
- (exports.supportExpand = w),
466
- (exports.supportIframeReady = v),
467
- (exports.supportIframeWillReload = f),
468
- (exports.supportInvokeCustomMethod = M),
469
- (exports.supportOpenInvoice = C),
470
- (exports.supportOpenLink = R),
471
- (exports.supportOpenPopup = B),
472
- (exports.supportOpenScanQrPopup = T),
473
- (exports.supportOpenTgLink = I),
474
- (exports.supportReadTextFromClipboard = L),
475
- (exports.supportReady = D),
476
- (exports.supportRequestPhone = A),
477
- (exports.supportRequestTheme = H),
478
- (exports.supportRequestViewport = J),
479
- (exports.supportRequestWriteAccess = j),
480
- (exports.supportSessionStorageGet = () => !0),
481
- (exports.supportSessionStorageSet = () => !0),
482
- (exports.supportSetBackgroundColor = U),
483
- (exports.supportSetBottomBarColor = Y),
484
- (exports.supportSetHeaderColor = K),
485
- (exports.supportSetupBackButton = ee),
486
- (exports.supportSetupClosingBehavior = se),
487
- (exports.supportSetupMainButton = re),
488
- (exports.supportSetupSettingsButton = ae),
489
- (exports.supportSetupSwipeBehavior = ce),
490
- (exports.supportSwitchInlineQuery = ie),
491
- (exports.supportTriggerHapticFeedback = de)
1
+ "use strict";var e=require("solid-js"),t=require("solid-js/store");const s="web",o="phone",r="desktop",p=()=>{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},a="not_supported",n=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s?.replace(".",""))>=Number(String(e)?.replace(".",""))&&-1!==t.indexOf(p())},i=()=>Math.random().toString(36).substring(3,9),u=e=>{var t;if(t=/^\s*#([0-9a-f]{6})\s*$/i.exec(e+=""))return"#"+t[1].toLowerCase();if(t=/^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e))return("#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]).toLowerCase();if(t=/^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(e)){var s=parseInt(t[1]),o=parseInt(t[2]),r=parseInt(t[3]);return"#"+((s<16?"0":"")+s.toString(16))+((o<16?"0":"")+o.toString(16))+((r<16?"0":"")+r.toString(16))}return!1},d=e=>{const t=window.location.hash.slice(1),s=new URLSearchParams(t),o=JSON.parse(s.get("tgWebAppThemeParams")??""),r=e||o;for(var p of Object.keys(r)){var a=u(r[p]);"string"==typeof a&&(r[p]=a)}return"#1c1c1d"==r?.bg_color&&r?.bg_color==r?.secondary_bg_color&&(r.secondary_bg_color="#2c2c2e"),r},_=e=>c()?(le(ve,e),{status:!0}):(xe(ve,1),{status:a}),c=()=>n(0,[s,r,o]),x=e=>g()?(le(Se,e),{status:!0}):(xe(Se,1),{status:a}),g=()=>n(6.4,[o]),l=e=>h()?(le(fe,e),{status:!0}):(xe(fe,1),{status:a}),h=()=>n(0,[s,r,o]),b=e=>w()?(le(ye,e),{status:!0}):(xe(ye,1),{status:a}),w=()=>n(0,[o]),m=e=>v()?(le(Pe,e),{status:!0}):(xe(Pe,1),{status:a}),v=()=>n(0,[s]),S=()=>f()?(le(Pe),{status:!0}):(xe(Pe,1),{status:a}),f=()=>n(0,[s]),y=async e=>P()?(void 0===e.req_id&&(e.req_id=i()),le(he,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),et(Ue,o))};Ze(Ue,o)}))):(xe(he,1),{status:a}),P=()=>n(6.9,[s,r,o]),M=e=>C()?(le(Ce,e),{status:!0}):(xe(Ce,1),{status:a}),C=()=>n(6.1,[s,r,o]),q=e=>R()?(le(qe,e),{status:!0}):(xe(qe,1),{status:a}),R=()=>n(6.4,[s,r,o]),k=async e=>B()?(e.title.length>64&&xe(Re,3),e.message.length<1&&xe(Re,4),e.message.length>256&&xe(Re,5),e.buttons.length<1&&xe(Re,6),e.buttons.length>3&&xe(Re,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&xe(Re,8),le(Re,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),et(je,o)};Ze(je,o)}))):(xe(Re,1),{status:a}),B=()=>n(6.2,[s,r,o]),O=async e=>T()?(le(be,e),new Promise(((t,s)=>{tt(Fe,(s=>{e.is_close&&x(),t({status:!0,data:s})})),tt(ze,(()=>{t({status:"closed"})}))}))):(xe(be,1),{status:a}),T=()=>n(6.4,[o]),E=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),I()?(le(ke,e),{status:!0}):(xe(ke,1),{status:a})),I=()=>n(7,[s,r,o]),W=async e=>L()?(e||(e={req_id:void 0}),void 0===e.req_id&&(e.req_id=i()),le(we,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e?.req_id&&(t({status:!0,data:s}),et(Je,o))};Ze(Je,o)}))):(xe(we,1),{status:a}),L=()=>n(6.4,[s,r,o]),D=e=>N()?(le(Be,e),{status:!0}):(xe(Be,1),{status:a}),N=()=>n(6.9,[s,r,o]),A=async()=>Q()?(le(me),new Promise(((e,t)=>{tt($e,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(xe(me,1),{status:a}),Q=()=>n(6.9,[s,r,o]),G=e=>H()?(le(Oe,e),{status:!0}):(xe(Oe,1),{status:a}),H=()=>n(0,[s,r,o]),V=e=>J()?(le(Te,e),{status:!0}):(xe(Te,1),{status:a}),J=()=>n(0,[s,r,o]),U=()=>$()?(le(Ee),{status:!0}):(xe(Ee,1),{status:a}),$=()=>n(6.9,[s,r,o]),j=e=>F()?(le(Ie,e),{status:!0}):(xe(Ie,1),{status:a}),F=()=>n(6.1,[s,r,o]),z=e=>K()?(le(We,e),{status:!0}):(xe(We,1),{status:a}),K=()=>n(6.1,[s,r,o]),X=e=>Y()?(le(Le,{color:e?.color||e?.color_key}),{status:!0}):(xe(Le,1),{status:a}),Y=()=>n(710,[s,r,o]),Z=e=>ee()?(le(De,e),{status:!0}):(xe(De,1),{status:a}),ee=()=>n(6.1,[s,r,o]),te=e=>se()?(le(Ne,e),{status:!0}):(xe(Ne,1),{status:a}),se=()=>n(0,[s,r,o]),oe=e=>re()?(le(Ae,e),{status:!0}):(xe(Ae,1),{status:a}),re=()=>n(0,[s,r,o]),pe=e=>ae()?(le(Qe,e),{status:!0}):(xe(Qe,1),{status:a}),ae=()=>n(6.1,[s,r,o]),ne=e=>ie()?(e.query.length>256&&xe(Ge,9),le(Ge,e),{status:!0}):(xe(Ge,1),{status:a}),ie=()=>n(6.7,[s,r,o]),ue=e=>de()?(le(He,e),{status:!0}):(xe(He,1),{status:a}),de=()=>n(6.1,[o]),_e=e=>ce()?(le(Ve,e),{status:!0}):(xe(Ve,1),{status:a}),ce=()=>n(7.7,[s,r,o]);var xe=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const ge=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppData");if(!t)return void xe("getInitData",2);const s=new URLSearchParams(t);let o={};return s.forEach(((e,t)=>{if(o[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{o[t]=JSON.parse(e)}catch{}})),o};var le=(e,t)=>{if(window.TelegramWebviewProxy)window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t));else if(window.external&&"notify"in window.external)window.external.notify(JSON.stringify({eventType:e,eventData:t}));else try{"*",window.parent.postMessage(JSON.stringify({eventType:e,eventData:t}),"*")}catch(e){xe("postMessage Iframe",10)}};const he="web_app_invoke_custom_method",be="web_app_open_scan_qr_popup",we="web_app_read_text_from_clipboard",me="web_app_request_phone",ve="web_app_close",Se="web_app_close_scan_qr_popup",fe="web_app_data_send",ye="web_app_expand",Pe="iframe_ready",Me="iframe_will_reload",Ce="web_app_open_invoice",qe="web_app_open_link",Re="web_app_open_popup",ke="web_app_open_tg_link",Be="web_app_ready",Oe="web_app_request_theme",Te="web_app_request_viewport",Ee="web_app_request_write_access",Ie="web_app_set_background_color",We="web_app_set_header_color",Le="web_app_set_bottom_bar_color",De="web_app_setup_back_button",Ne="web_app_setup_closing_behavior",Ae="web_app_setup_main_button",Qe="web_app_setup_settings_button",Ge="web_app_switch_inline_query",He="web_app_trigger_haptic_feedback",Ve="web_app_setup_swipe_behavior";const Je="clipboard_text_received",Ue="custom_method_invoked",$e="phone_requested",je="popup_closed",Fe="qr_text_received",ze="scan_qr_popup_closed",Ke="theme_changed",Xe="viewport_changed",Ye=((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){e===Ke&&(t.theme_params=d(t.theme_params)),Ye.emit(e,t),Ye.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const Ze=(e,t)=>{Ye.on(e,t)},et=(e,t)=>{Ye.off(e,t)},tt=(e,t)=>{Ye.once(e,t)};var st=Object.freeze({__proto__:null,off:et,on:Ze,once:tt});const ot=e.createContext({viewport:void 0,theme:void 0,init:void 0});exports.ContextTwa=ot,exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=Je,exports.EventCustomMethodInvoked=Ue,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=$e,exports.EventPopupClosed=je,exports.EventQrTextReceived=Fe,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=ze,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged=Ke,exports.EventViewportChanged=Xe,exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=ve,exports.MethodCloseScanQrPopup=Se,exports.MethodDataSend=fe,exports.MethodExpand=ye,exports.MethodIframeReady=Pe,exports.MethodIframeWillReload=Me,exports.MethodInvokeCustomMethod=he,exports.MethodOpenInvoice=Ce,exports.MethodOpenLink=qe,exports.MethodOpenPopup=Re,exports.MethodOpenScanQrPopup=be,exports.MethodOpenTgLink=ke,exports.MethodReadTextFromClipboard=we,exports.MethodReady=Be,exports.MethodRequestPhone=me,exports.MethodRequestTheme=Oe,exports.MethodRequestViewport=Te,exports.MethodRequestWriteAccess=Ee,exports.MethodSetBackgroundColor=Ie,exports.MethodSetBottomBarColor=Le,exports.MethodSetHeaderColor=We,exports.MethodSetupBackButton=De,exports.MethodSetupClosingBehavior=Ne,exports.MethodSetupMainButton=Ae,exports.MethodSetupSettingsButton=Qe,exports.MethodSetupSwipeBehavior=Ve,exports.MethodSwitchInlineQuery=Ge,exports.MethodTriggerHapticFeedback=He,exports.NOT_SUPPORTED=a,exports.ProviderTWA=s=>{const[o,r]=t.createStore({viewport:void 0,theme:void 0,init:void 0});return e.createEffect((()=>{const t=()=>{r("init",ge())};t();const s=e=>{t(),r("viewport",{...e,safe_area_bottom:e.is_expanded&&e.is_state_stable?window.outerHeight-e.height:0})};Ze(Xe,s),V();const o=e=>{t(),r("theme",e)};return Ze(Ke,o),V(),e.onCleanup((()=>{et(Xe,s),et(Ke,o)})),()=>{et(Xe,s),et(Ke,o)}})),ot.Provider({value:o,children:s.children})},exports.TG_DESKTOP=r,exports.TG_PHONE=o,exports.TG_WEB=s,exports.bridgeClose=_,exports.bridgeCloseScanQrPopup=x,exports.bridgeDataSend=l,exports.bridgeExpand=b,exports.bridgeGetInitData=ge,exports.bridgeGetThemeParams=d,exports.bridgeIframeReady=m,exports.bridgeIframeWillReload=S,exports.bridgeInvokeCustomMethod=y,exports.bridgeOpenInvoice=M,exports.bridgeOpenLink=q,exports.bridgeOpenPopup=k,exports.bridgeOpenScanQrPopup=O,exports.bridgeOpenTgLink=E,exports.bridgeReadTextFromClipboard=W,exports.bridgeReady=D,exports.bridgeRequestPhone=A,exports.bridgeRequestTheme=G,exports.bridgeRequestViewport=V,exports.bridgeRequestWriteAccess=U,exports.bridgeSend=le,exports.bridgeSessionStorageGet=({key:e})=>{try{return{is_json:!0,value:JSON.parse(window.sessionStorage.getItem("__telegram__"+e)??""),status:!0}}catch(t){return{is_json:!1,value:window.sessionStorage.getItem("__telegram__"+e)??"",status:!0}}},exports.bridgeSessionStorageSet=({key:e,value:t})=>{try{return window.sessionStorage.setItem("__telegram__"+e,JSON.stringify(t)),{status:!0}}catch(s){return window.sessionStorage.setItem("__telegram__"+e,t),{status:!0}}},exports.bridgeSetBackgroundColor=j,exports.bridgeSetBottomBarColor=X,exports.bridgeSetHeaderColor=z,exports.bridgeSetupBackButton=Z,exports.bridgeSetupClosingBehavior=te,exports.bridgeSetupMainButton=oe,exports.bridgeSetupSettingsButton=pe,exports.bridgeSetupSwipeBehavior=_e,exports.bridgeSwitchInlineQuery=ne,exports.bridgeTriggerHapticFeedback=ue,exports.createIsViewportChanged=()=>{const[t,s]=e.createSignal({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>s(e);return e.onMount((()=>{Ze(Xe,o),le(Te)})),e.onCleanup((()=>{et(Xe,o)})),t},exports.debug=xe,exports.getAppData=()=>{const e=window.location.hash.slice(1);return new URLSearchParams(e).get("tgWebAppData")},exports.getPlatform=p,exports.listener=st,exports.sender=le,exports.supportClose=c,exports.supportCloseScanQrPopup=g,exports.supportDataSend=h,exports.supportExpand=w,exports.supportIframeReady=v,exports.supportIframeWillReload=f,exports.supportInvokeCustomMethod=P,exports.supportOpenInvoice=C,exports.supportOpenLink=R,exports.supportOpenPopup=B,exports.supportOpenScanQrPopup=T,exports.supportOpenTgLink=I,exports.supportReadTextFromClipboard=L,exports.supportReady=N,exports.supportRequestPhone=Q,exports.supportRequestTheme=H,exports.supportRequestViewport=J,exports.supportRequestWriteAccess=$,exports.supportSessionStorageGet=()=>!0,exports.supportSessionStorageSet=()=>!0,exports.supportSetBackgroundColor=F,exports.supportSetBottomBarColor=Y,exports.supportSetHeaderColor=K,exports.supportSetupBackButton=ee,exports.supportSetupClosingBehavior=se,exports.supportSetupMainButton=re,exports.supportSetupSettingsButton=ae,exports.supportSetupSwipeBehavior=ce,exports.supportSwitchInlineQuery=ie,exports.supportTriggerHapticFeedback=de;
package/solid/index.mjs CHANGED
@@ -1,502 +1 @@
1
- import {
2
- createSignal as e,
3
- onMount as t,
4
- onCleanup as s,
5
- createContext as a,
6
- } from 'solid-js'
7
- import { createStore as r } from 'solid-js/store'
8
- const o = () => {
9
- const [a, r] = e({ height: 0, is_expanded: !1, is_state_stable: !1 }),
10
- o = e => r(e)
11
- return (
12
- t(() => {
13
- bt(ut, o), qe(je)
14
- }),
15
- s(() => {
16
- lt(ut, o)
17
- }),
18
- a
19
- )
20
- },
21
- i = 'web',
22
- n = 'phone',
23
- _ = 'desktop',
24
- p = () => {
25
- const e = window.location.hash.slice(1),
26
- t = new URLSearchParams(e).get('tgWebAppPlatform') ?? 'ios'
27
- return ['android', 'ios'].includes(t)
28
- ? n
29
- : ['tdesktop', 'macos'].includes(t)
30
- ? _
31
- : i
32
- },
33
- d = 'not_supported',
34
- u = (e, t) => {
35
- const s = new URLSearchParams(window.location.hash.slice(1)).get(
36
- 'tgWebAppVersion'
37
- )
38
- return (
39
- Number(s?.replace('.', '')) >= Number(String(e)?.replace('.', '')) &&
40
- -1 !== t.indexOf(p())
41
- )
42
- },
43
- c = () => Math.random().toString(36).substring(3, 9),
44
- g = e => {
45
- var t
46
- if ((t = /^\s*#([0-9a-f]{6})\s*$/i.exec((e += ''))))
47
- return '#' + t[1].toLowerCase()
48
- if ((t = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e)))
49
- return ('#' + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]).toLowerCase()
50
- if (
51
- (t =
52
- /^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(
53
- e
54
- ))
55
- ) {
56
- var s = parseInt(t[1]),
57
- a = parseInt(t[2]),
58
- r = parseInt(t[3])
59
- return (
60
- '#' +
61
- ((s < 16 ? '0' : '') + s.toString(16)) +
62
- ((a < 16 ? '0' : '') + a.toString(16)) +
63
- ((r < 16 ? '0' : '') + r.toString(16))
64
- )
65
- }
66
- return !1
67
- },
68
- b = e => {
69
- '#1c1c1d' == e.bg_color &&
70
- e.bg_color == e.secondary_bg_color &&
71
- (e.secondary_bg_color = '#2c2c2e')
72
- const t = window.location.hash.slice(1),
73
- s = new URLSearchParams(t)
74
- var a = JSON.parse(s.get('tgWebAppThemeParams') ?? '')
75
- for (var r of Object.keys(e)) {
76
- var o = g(e[r])
77
- 'string' == typeof o && (a[r] = o)
78
- }
79
- return a
80
- },
81
- l = e => (w() ? (qe(Ie, e), { status: !0 }) : (Se(Ie, 1), { status: d })),
82
- w = () => u(0, [i, _, n]),
83
- m = e => (h() ? (qe(Re, e), { status: !0 }) : (Se(Re, 1), { status: d })),
84
- h = () => u(6.4, [n]),
85
- v = e => (f() ? (qe(Te, e), { status: !0 }) : (Se(Te, 1), { status: d })),
86
- f = () => u(0, [i, _, n]),
87
- S = e => (y() ? (qe(Ne, e), { status: !0 }) : (Se(Ne, 1), { status: d })),
88
- y = () => u(0, [n]),
89
- q = e => (x() ? (qe(Ce, e), { status: !0 }) : (Se(Ce, 1), { status: d })),
90
- x = () => u(0, [i]),
91
- P = () => (k() ? (qe(Ce), { status: !0 }) : (Se(Ce, 1), { status: d })),
92
- k = () => u(0, [i]),
93
- O = async e =>
94
- I()
95
- ? (void 0 === e.req_id && (e.req_id = c()),
96
- qe(xe, e),
97
- new Promise((t, s) => {
98
- const a = s => {
99
- s.req_id === e.req_id && (t({ status: !0, data: s }), lt(et, a))
100
- }
101
- bt(et, a)
102
- }))
103
- : (Se(xe, 1), { status: d }),
104
- I = () => u(6.9, [i, _, n]),
105
- R = e => (T() ? (qe(Ee, e), { status: !0 }) : (Se(Ee, 1), { status: d })),
106
- T = () => u(6.1, [i, _, n]),
107
- N = e => (C() ? (qe(Le, e), { status: !0 }) : (Se(Le, 1), { status: d })),
108
- C = () => u(6.4, [i, _, n]),
109
- B = async e =>
110
- E()
111
- ? (e.title.length > 64 && Se(We, 3),
112
- e.message.length < 1 && Se(We, 4),
113
- e.message.length > 256 && Se(We, 5),
114
- e.buttons.length < 1 && Se(We, 6),
115
- e.buttons.length > 3 && Se(We, 7),
116
- void 0 !== e.buttons.find(e => e.text?.match(/^(ok|close|cancel)$/g)) &&
117
- Se(We, 8),
118
- qe(We, e),
119
- new Promise((t, s) => {
120
- const a = s => {
121
- t({
122
- status: !!e.buttons.find(e => e.id === s?.button_id),
123
- data: s,
124
- }),
125
- lt(rt, a)
126
- }
127
- bt(rt, a)
128
- }))
129
- : (Se(We, 1), { status: d }),
130
- E = () => u(6.2, [i, _, n]),
131
- L = async e =>
132
- W()
133
- ? (qe(Pe, e),
134
- new Promise((t, s) => {
135
- wt(it, s => {
136
- e.is_close && m(), t({ status: !0, data: s })
137
- }),
138
- wt(nt, () => {
139
- t({ status: 'closed' })
140
- })
141
- }))
142
- : (Se(Pe, 1), { status: d }),
143
- W = () => u(6.4, [n]),
144
- D = e => (
145
- '/' !== e.path_full[0] && (e.path_full = '/' + e.path_full),
146
- J() ? (qe(De, e), { status: !0 }) : (Se(De, 1), { status: d })
147
- ),
148
- J = () => u(7, [i, _, n]),
149
- $ = async e =>
150
- j()
151
- ? (e || (e = { req_id: void 0 }),
152
- void 0 === e.req_id && (e.req_id = c()),
153
- qe(ke, e),
154
- new Promise((t, s) => {
155
- const a = s => {
156
- s.req_id === e?.req_id && (t({ status: !0, data: s }), lt(Ze, a))
157
- }
158
- bt(Ze, a)
159
- }))
160
- : (Se(ke, 1), { status: d }),
161
- j = () => u(6.4, [i, _, n]),
162
- M = e => (A() ? (qe(Je, e), { status: !0 }) : (Se(Je, 1), { status: d })),
163
- A = () => u(6.9, [i, _, n]),
164
- G = async () =>
165
- U()
166
- ? (qe(Oe),
167
- new Promise((e, t) => {
168
- wt(at, t => {
169
- 'sent' === t.status && e({ status: !0 }), e({ status: !1 })
170
- })
171
- }))
172
- : (Se(Oe, 1), { status: d }),
173
- U = () => u(6.9, [i, _, n]),
174
- V = e => (H() ? (qe($e, e), { status: !0 }) : (Se($e, 1), { status: d })),
175
- H = () => u(0, [i, _, n]),
176
- Q = e => (F() ? (qe(je, e), { status: !0 }) : (Se(je, 1), { status: d })),
177
- F = () => u(0, [i, _, n]),
178
- z = () => (K() ? (qe(Me), { status: !0 }) : (Se(Me, 1), { status: d })),
179
- K = () => u(6.9, [i, _, n]),
180
- X = e => (Y() ? (qe(Ae, e), { status: !0 }) : (Se(Ae, 1), { status: d })),
181
- Y = () => u(6.1, [i, _, n]),
182
- Z = e => (ee() ? (qe(Ge, e), { status: !0 }) : (Se(Ge, 1), { status: d })),
183
- ee = () => u(6.1, [i, _, n]),
184
- te = e =>
185
- se()
186
- ? (qe(Ue, { color: e?.color || e?.color_key }), { status: !0 })
187
- : (Se(Ue, 1), { status: d }),
188
- se = () => u(710, [i, _, n]),
189
- ae = e => (re() ? (qe(Ve, e), { status: !0 }) : (Se(Ve, 1), { status: d })),
190
- re = () => u(6.1, [i, _, n]),
191
- oe = e => (ie() ? (qe(He, e), { status: !0 }) : (Se(He, 1), { status: d })),
192
- ie = () => u(0, [i, _, n]),
193
- ne = e => (_e() ? (qe(Qe, e), { status: !0 }) : (Se(Qe, 1), { status: d })),
194
- _e = () => u(0, [i, _, n]),
195
- pe = e => (de() ? (qe(Fe, e), { status: !0 }) : (Se(Fe, 1), { status: d })),
196
- de = () => u(6.1, [i, _, n]),
197
- ue = e =>
198
- ce()
199
- ? (e.query.length > 256 && Se(ze, 9), qe(ze, e), { status: !0 })
200
- : (Se(ze, 1), { status: d }),
201
- ce = () => u(6.7, [i, _, n]),
202
- ge = e => (be() ? (qe(Ke, e), { status: !0 }) : (Se(Ke, 1), { status: d })),
203
- be = () => u(6.1, [n]),
204
- le = ({ key: e, value: t }) => {
205
- try {
206
- return (
207
- window.sessionStorage.setItem('__telegram__' + e, JSON.stringify(t)),
208
- { status: !0 }
209
- )
210
- } catch (s) {
211
- return (
212
- window.sessionStorage.setItem('__telegram__' + e, t), { status: !0 }
213
- )
214
- }
215
- },
216
- we = () => !0,
217
- me = ({ key: e }) => {
218
- try {
219
- return {
220
- is_json: !0,
221
- value: JSON.parse(
222
- window.sessionStorage.getItem('__telegram__' + e) ?? ''
223
- ),
224
- status: !0,
225
- }
226
- } catch (t) {
227
- return {
228
- is_json: !1,
229
- value: window.sessionStorage.getItem('__telegram__' + e) ?? '',
230
- status: !0,
231
- }
232
- }
233
- },
234
- he = () => !0,
235
- ve = e => (fe() ? (qe(Xe, e), { status: !0 }) : (Se(Xe, 1), { status: d })),
236
- fe = () => u(7.7, [i, _, n])
237
- var Se = (e, t) => {
238
- 'development' === process.env.NODE_ENV &&
239
- console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)
240
- }
241
- const ye = () => {
242
- const e = window.location.hash.slice(1),
243
- t = new URLSearchParams(e).get('tgWebAppData')
244
- if (!t) return void Se('getInitData', 2)
245
- const s = new URLSearchParams(t)
246
- let a = {}
247
- return (
248
- s.forEach((e, t) => {
249
- if (((a[t] = e), void 0 !== t.match(/^(chat|receiver|user)$/g)))
250
- try {
251
- a[t] = JSON.parse(e)
252
- } catch {}
253
- }),
254
- a
255
- )
256
- }
257
- var qe = (e, t) => {
258
- if (window.TelegramWebviewProxy)
259
- window.TelegramWebviewProxy.postEvent(e, JSON.stringify(t))
260
- else if (window.external && 'notify' in window.external)
261
- window.external.notify(JSON.stringify({ eventType: e, eventData: t }))
262
- else
263
- try {
264
- '*',
265
- window.parent.postMessage(
266
- JSON.stringify({ eventType: e, eventData: t }),
267
- '*'
268
- )
269
- } catch (e) {
270
- Se('postMessage Iframe', 10)
271
- }
272
- }
273
- const xe = 'web_app_invoke_custom_method',
274
- Pe = 'web_app_open_scan_qr_popup',
275
- ke = 'web_app_read_text_from_clipboard',
276
- Oe = 'web_app_request_phone',
277
- Ie = 'web_app_close',
278
- Re = 'web_app_close_scan_qr_popup',
279
- Te = 'web_app_data_send',
280
- Ne = 'web_app_expand',
281
- Ce = 'iframe_ready',
282
- Be = 'iframe_will_reload',
283
- Ee = 'web_app_open_invoice',
284
- Le = 'web_app_open_link',
285
- We = 'web_app_open_popup',
286
- De = 'web_app_open_tg_link',
287
- Je = 'web_app_ready',
288
- $e = 'web_app_request_theme',
289
- je = 'web_app_request_viewport',
290
- Me = 'web_app_request_write_access',
291
- Ae = 'web_app_set_background_color',
292
- Ge = 'web_app_set_header_color',
293
- Ue = 'web_app_set_bottom_bar_color',
294
- Ve = 'web_app_setup_back_button',
295
- He = 'web_app_setup_closing_behavior',
296
- Qe = 'web_app_setup_main_button',
297
- Fe = 'web_app_setup_settings_button',
298
- ze = 'web_app_switch_inline_query',
299
- Ke = 'web_app_trigger_haptic_feedback',
300
- Xe = 'web_app_setup_swipe_behavior'
301
- const Ye = 'back_button_pressed',
302
- Ze = 'clipboard_text_received',
303
- et = 'custom_method_invoked',
304
- tt = 'invoice_closed',
305
- st = 'main_button_pressed',
306
- at = 'phone_requested',
307
- rt = 'popup_closed',
308
- ot = 'reload_iframe',
309
- it = 'qr_text_received',
310
- nt = 'scan_qr_popup_closed',
311
- _t = 'set_custom_style',
312
- pt = 'settings_button_pressed',
313
- dt = 'theme_changed',
314
- ut = 'viewport_changed',
315
- ct = 'write_access_requested',
316
- gt = ((e = new Map()) => ({
317
- once: (
318
- t,
319
- s,
320
- a = e.get(t),
321
- r = e => {
322
- s(e), a && a.splice(a.indexOf(s) >>> 0, 1)
323
- }
324
- ) => (a ? a.push(r) : e.set(t, [r])),
325
- on: (t, s, a = e.get(t)) => (a ? a.push(s) : e.set(t, [s])),
326
- off: (t, s, a = e.get(t)) =>
327
- a && s ? a.splice(a.indexOf(s) >>> 0, 1) : e.set(t, []),
328
- emit: (t, s, a = e.get(t) || []) => {
329
- for (const e of a) e(s)
330
- },
331
- }))()
332
- ;(() => {
333
- function e(e, t) {
334
- e === dt && (t.theme_params = b(t.theme_params)),
335
- gt.emit(e, t),
336
- gt.emit('*', { name: e, data: t })
337
- }
338
- ;(window.TelegramGameProxy_receiveEvent = e),
339
- (window.Telegram = { WebView: { receiveEvent: e } }),
340
- (window.TelegramGameProxy = { receiveEvent: e })
341
- })()
342
- const bt = (e, t) => {
343
- gt.on(e, t)
344
- },
345
- lt = (e, t) => {
346
- gt.off(e, t)
347
- },
348
- wt = (e, t) => {
349
- gt.once(e, t)
350
- }
351
- var mt = Object.freeze({ __proto__: null, off: lt, on: bt, once: wt })
352
- const ht = a({ viewport: void 0, theme: void 0, init: void 0 }),
353
- vt = e => {
354
- const [a, o] = r({ viewport: void 0, theme: void 0, init: void 0 })
355
- return (
356
- t(() => {
357
- const e = () => {
358
- o('init', ye())
359
- }
360
- e()
361
- const t = t => {
362
- e(),
363
- o('viewport', {
364
- ...t,
365
- safe_area_bottom:
366
- t.is_expanded && t.is_state_stable
367
- ? window.outerHeight - t.height
368
- : 0,
369
- })
370
- }
371
- bt(ut, t), Q()
372
- const a = t => {
373
- e(), o('theme', t)
374
- }
375
- bt(dt, a),
376
- Q(),
377
- s(() => {
378
- lt(ut, t), lt(dt, a)
379
- })
380
- }),
381
- e.children
382
- )
383
- }
384
- export {
385
- ht as ContextTwa,
386
- Ye as EventBackButtonPressed,
387
- Ze as EventClipboardTextReceived,
388
- et as EventCustomMethodInvoked,
389
- tt as EventInvoiceClosed,
390
- st as EventMainButtonPressed,
391
- at as EventPhoneRequested,
392
- rt as EventPopupClosed,
393
- it as EventQrTextReceived,
394
- ot as EventReloadIframe,
395
- nt as EventScanQrPopupClosed,
396
- _t as EventSetCustomStyle,
397
- pt as EventSettingsButtonPressed,
398
- dt as EventThemeChanged,
399
- ut as EventViewportChanged,
400
- ct as EventWriteAccessRequested,
401
- Ie as MethodClose,
402
- Re as MethodCloseScanQrPopup,
403
- Te as MethodDataSend,
404
- Ne as MethodExpand,
405
- Ce as MethodIframeReady,
406
- Be as MethodIframeWillReload,
407
- xe as MethodInvokeCustomMethod,
408
- Ee as MethodOpenInvoice,
409
- Le as MethodOpenLink,
410
- We as MethodOpenPopup,
411
- Pe as MethodOpenScanQrPopup,
412
- De as MethodOpenTgLink,
413
- ke as MethodReadTextFromClipboard,
414
- Je as MethodReady,
415
- Oe as MethodRequestPhone,
416
- $e as MethodRequestTheme,
417
- je as MethodRequestViewport,
418
- Me as MethodRequestWriteAccess,
419
- Ae as MethodSetBackgroundColor,
420
- Ue as MethodSetBottomBarColor,
421
- Ge as MethodSetHeaderColor,
422
- Ve as MethodSetupBackButton,
423
- He as MethodSetupClosingBehavior,
424
- Qe as MethodSetupMainButton,
425
- Fe as MethodSetupSettingsButton,
426
- Xe as MethodSetupSwipeBehavior,
427
- ze as MethodSwitchInlineQuery,
428
- Ke as MethodTriggerHapticFeedback,
429
- d as NOT_SUPPORTED,
430
- vt as ProviderTWA,
431
- _ as TG_DESKTOP,
432
- n as TG_PHONE,
433
- i as TG_WEB,
434
- l as bridgeClose,
435
- m as bridgeCloseScanQrPopup,
436
- v as bridgeDataSend,
437
- S as bridgeExpand,
438
- ye as bridgeGetInitData,
439
- b as bridgeGetThemeParams,
440
- q as bridgeIframeReady,
441
- P as bridgeIframeWillReload,
442
- O as bridgeInvokeCustomMethod,
443
- R as bridgeOpenInvoice,
444
- N as bridgeOpenLink,
445
- B as bridgeOpenPopup,
446
- L as bridgeOpenScanQrPopup,
447
- D as bridgeOpenTgLink,
448
- $ as bridgeReadTextFromClipboard,
449
- M as bridgeReady,
450
- G as bridgeRequestPhone,
451
- V as bridgeRequestTheme,
452
- Q as bridgeRequestViewport,
453
- z as bridgeRequestWriteAccess,
454
- qe as bridgeSend,
455
- me as bridgeSessionStorageGet,
456
- le as bridgeSessionStorageSet,
457
- X as bridgeSetBackgroundColor,
458
- te as bridgeSetBottomBarColor,
459
- Z as bridgeSetHeaderColor,
460
- ae as bridgeSetupBackButton,
461
- oe as bridgeSetupClosingBehavior,
462
- ne as bridgeSetupMainButton,
463
- pe as bridgeSetupSettingsButton,
464
- ve as bridgeSetupSwipeBehavior,
465
- ue as bridgeSwitchInlineQuery,
466
- ge as bridgeTriggerHapticFeedback,
467
- o as createIsViewportChanged,
468
- Se as debug,
469
- p as getPlatform,
470
- mt as listener,
471
- qe as sender,
472
- w as supportClose,
473
- h as supportCloseScanQrPopup,
474
- f as supportDataSend,
475
- y as supportExpand,
476
- x as supportIframeReady,
477
- k as supportIframeWillReload,
478
- I as supportInvokeCustomMethod,
479
- T as supportOpenInvoice,
480
- C as supportOpenLink,
481
- E as supportOpenPopup,
482
- W as supportOpenScanQrPopup,
483
- J as supportOpenTgLink,
484
- j as supportReadTextFromClipboard,
485
- A as supportReady,
486
- U as supportRequestPhone,
487
- H as supportRequestTheme,
488
- F as supportRequestViewport,
489
- K as supportRequestWriteAccess,
490
- he as supportSessionStorageGet,
491
- we as supportSessionStorageSet,
492
- Y as supportSetBackgroundColor,
493
- se as supportSetBottomBarColor,
494
- ee as supportSetHeaderColor,
495
- re as supportSetupBackButton,
496
- ie as supportSetupClosingBehavior,
497
- _e as supportSetupMainButton,
498
- de as supportSetupSettingsButton,
499
- fe as supportSetupSwipeBehavior,
500
- ce as supportSwitchInlineQuery,
501
- be as supportTriggerHapticFeedback,
502
- }
1
+ import{createSignal as e,onMount as t,onCleanup as s,createContext as a,createEffect as r}from"solid-js";import{createStore as o}from"solid-js/store";const i=()=>{const[a,r]=e({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>r(e);return t((()=>{lt(ct,o),xe(Ae)})),s((()=>{wt(ct,o)})),a},n="web",_="phone",p="desktop",d=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?_:["tdesktop","macos"].includes(t)?p:n},u="not_supported",c=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s?.replace(".",""))>=Number(String(e)?.replace(".",""))&&-1!==t.indexOf(d())},g=()=>Math.random().toString(36).substring(3,9),b=e=>{var t;if(t=/^\s*#([0-9a-f]{6})\s*$/i.exec(e+=""))return"#"+t[1].toLowerCase();if(t=/^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e))return("#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]).toLowerCase();if(t=/^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(e)){var s=parseInt(t[1]),a=parseInt(t[2]),r=parseInt(t[3]);return"#"+((s<16?"0":"")+s.toString(16))+((a<16?"0":"")+a.toString(16))+((r<16?"0":"")+r.toString(16))}return!1},l=e=>{const t=window.location.hash.slice(1),s=new URLSearchParams(t),a=JSON.parse(s.get("tgWebAppThemeParams")??""),r=e||a;for(var o of Object.keys(r)){var i=b(r[o]);"string"==typeof i&&(r[o]=i)}return"#1c1c1d"==r?.bg_color&&r?.bg_color==r?.secondary_bg_color&&(r.secondary_bg_color="#2c2c2e"),r},w=e=>m()?(xe(Re,e),{status:!0}):(ye(Re,1),{status:u}),m=()=>c(0,[n,p,_]),h=e=>v()?(xe(Te,e),{status:!0}):(ye(Te,1),{status:u}),v=()=>c(6.4,[_]),f=e=>S()?(xe(Ne,e),{status:!0}):(ye(Ne,1),{status:u}),S=()=>c(0,[n,p,_]),y=e=>q()?(xe(Ce,e),{status:!0}):(ye(Ce,1),{status:u}),q=()=>c(0,[_]),x=e=>P()?(xe(Le,e),{status:!0}):(ye(Le,1),{status:u}),P=()=>c(0,[n]),k=()=>O()?(xe(Le),{status:!0}):(ye(Le,1),{status:u}),O=()=>c(0,[n]),I=async e=>R()?(void 0===e.req_id&&(e.req_id=g()),xe(Pe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),wt(tt,a))};lt(tt,a)}))):(ye(Pe,1),{status:u}),R=()=>c(6.9,[n,p,_]),T=e=>N()?(xe(Be,e),{status:!0}):(ye(Be,1),{status:u}),N=()=>c(6.1,[n,p,_]),C=e=>L()?(xe(De,e),{status:!0}):(ye(De,1),{status:u}),L=()=>c(6.4,[n,p,_]),W=async e=>B()?(e.title.length>64&&ye(Ee,3),e.message.length<1&&ye(Ee,4),e.message.length>256&&ye(Ee,5),e.buttons.length<1&&ye(Ee,6),e.buttons.length>3&&ye(Ee,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&ye(Ee,8),xe(Ee,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),wt(ot,a)};lt(ot,a)}))):(ye(Ee,1),{status:u}),B=()=>c(6.2,[n,p,_]),D=async e=>E()?(xe(ke,e),new Promise(((t,s)=>{mt(nt,(s=>{e.is_close&&h(),t({status:!0,data:s})})),mt(_t,(()=>{t({status:"closed"})}))}))):(ye(ke,1),{status:u}),E=()=>c(6.4,[_]),J=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),$()?(xe(Je,e),{status:!0}):(ye(Je,1),{status:u})),$=()=>c(7,[n,p,_]),j=async e=>A()?(e||(e={req_id:void 0}),void 0===e.req_id&&(e.req_id=g()),xe(Oe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e?.req_id&&(t({status:!0,data:s}),wt(et,a))};lt(et,a)}))):(ye(Oe,1),{status:u}),A=()=>c(6.4,[n,p,_]),M=e=>U()?(xe($e,e),{status:!0}):(ye($e,1),{status:u}),U=()=>c(6.9,[n,p,_]),G=async()=>V()?(xe(Ie),new Promise(((e,t)=>{mt(rt,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(ye(Ie,1),{status:u}),V=()=>c(6.9,[n,p,_]),H=e=>Q()?(xe(je,e),{status:!0}):(ye(je,1),{status:u}),Q=()=>c(0,[n,p,_]),F=e=>z()?(xe(Ae,e),{status:!0}):(ye(Ae,1),{status:u}),z=()=>c(0,[n,p,_]),K=()=>X()?(xe(Me),{status:!0}):(ye(Me,1),{status:u}),X=()=>c(6.9,[n,p,_]),Y=e=>Z()?(xe(Ue,e),{status:!0}):(ye(Ue,1),{status:u}),Z=()=>c(6.1,[n,p,_]),ee=e=>te()?(xe(Ge,e),{status:!0}):(ye(Ge,1),{status:u}),te=()=>c(6.1,[n,p,_]),se=e=>ae()?(xe(Ve,{color:e?.color||e?.color_key}),{status:!0}):(ye(Ve,1),{status:u}),ae=()=>c(710,[n,p,_]),re=e=>oe()?(xe(He,e),{status:!0}):(ye(He,1),{status:u}),oe=()=>c(6.1,[n,p,_]),ie=e=>ne()?(xe(Qe,e),{status:!0}):(ye(Qe,1),{status:u}),ne=()=>c(0,[n,p,_]),_e=e=>pe()?(xe(Fe,e),{status:!0}):(ye(Fe,1),{status:u}),pe=()=>c(0,[n,p,_]),de=e=>ue()?(xe(ze,e),{status:!0}):(ye(ze,1),{status:u}),ue=()=>c(6.1,[n,p,_]),ce=e=>ge()?(e.query.length>256&&ye(Ke,9),xe(Ke,e),{status:!0}):(ye(Ke,1),{status:u}),ge=()=>c(6.7,[n,p,_]),be=e=>le()?(xe(Xe,e),{status:!0}):(ye(Xe,1),{status:u}),le=()=>c(6.1,[_]),we=({key:e,value:t})=>{try{return window.sessionStorage.setItem("__telegram__"+e,JSON.stringify(t)),{status:!0}}catch(s){return window.sessionStorage.setItem("__telegram__"+e,t),{status:!0}}},me=()=>!0,he=({key:e})=>{try{return{is_json:!0,value:JSON.parse(window.sessionStorage.getItem("__telegram__"+e)??""),status:!0}}catch(t){return{is_json:!1,value:window.sessionStorage.getItem("__telegram__"+e)??"",status:!0}}},ve=()=>!0,fe=e=>Se()?(xe(Ye,e),{status:!0}):(ye(Ye,1),{status:u}),Se=()=>c(7.7,[n,p,_]);var ye=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const qe=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppData");if(!t)return void ye("getInitData",2);const s=new URLSearchParams(t);let a={};return s.forEach(((e,t)=>{if(a[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{a[t]=JSON.parse(e)}catch{}})),a};var xe=(e,t)=>{if(window.TelegramWebviewProxy)window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t));else if(window.external&&"notify"in window.external)window.external.notify(JSON.stringify({eventType:e,eventData:t}));else try{"*",window.parent.postMessage(JSON.stringify({eventType:e,eventData:t}),"*")}catch(e){ye("postMessage Iframe",10)}};const Pe="web_app_invoke_custom_method",ke="web_app_open_scan_qr_popup",Oe="web_app_read_text_from_clipboard",Ie="web_app_request_phone",Re="web_app_close",Te="web_app_close_scan_qr_popup",Ne="web_app_data_send",Ce="web_app_expand",Le="iframe_ready",We="iframe_will_reload",Be="web_app_open_invoice",De="web_app_open_link",Ee="web_app_open_popup",Je="web_app_open_tg_link",$e="web_app_ready",je="web_app_request_theme",Ae="web_app_request_viewport",Me="web_app_request_write_access",Ue="web_app_set_background_color",Ge="web_app_set_header_color",Ve="web_app_set_bottom_bar_color",He="web_app_setup_back_button",Qe="web_app_setup_closing_behavior",Fe="web_app_setup_main_button",ze="web_app_setup_settings_button",Ke="web_app_switch_inline_query",Xe="web_app_trigger_haptic_feedback",Ye="web_app_setup_swipe_behavior";const Ze="back_button_pressed",et="clipboard_text_received",tt="custom_method_invoked",st="invoice_closed",at="main_button_pressed",rt="phone_requested",ot="popup_closed",it="reload_iframe",nt="qr_text_received",_t="scan_qr_popup_closed",pt="set_custom_style",dt="settings_button_pressed",ut="theme_changed",ct="viewport_changed",gt="write_access_requested",bt=((e=new Map)=>({once:(t,s,a=e.get(t),r=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(r):e.set(t,[r]),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){e===ut&&(t.theme_params=l(t.theme_params)),bt.emit(e,t),bt.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const lt=(e,t)=>{bt.on(e,t)},wt=(e,t)=>{bt.off(e,t)},mt=(e,t)=>{bt.once(e,t)};var ht=Object.freeze({__proto__:null,off:wt,on:lt,once:mt});const vt=()=>{const e=window.location.hash.slice(1);return new URLSearchParams(e).get("tgWebAppData")},ft=a({viewport:void 0,theme:void 0,init:void 0}),St=e=>{const[t,a]=o({viewport:void 0,theme:void 0,init:void 0});return r((()=>{const e=()=>{a("init",qe())};e();const t=t=>{e(),a("viewport",{...t,safe_area_bottom:t.is_expanded&&t.is_state_stable?window.outerHeight-t.height:0})};lt(ct,t),F();const r=t=>{e(),a("theme",t)};return lt(ut,r),F(),s((()=>{wt(ct,t),wt(ut,r)})),()=>{wt(ct,t),wt(ut,r)}})),ft.Provider({value:t,children:e.children})};export{ft as ContextTwa,Ze as EventBackButtonPressed,et as EventClipboardTextReceived,tt as EventCustomMethodInvoked,st as EventInvoiceClosed,at as EventMainButtonPressed,rt as EventPhoneRequested,ot as EventPopupClosed,nt as EventQrTextReceived,it as EventReloadIframe,_t as EventScanQrPopupClosed,pt as EventSetCustomStyle,dt as EventSettingsButtonPressed,ut as EventThemeChanged,ct as EventViewportChanged,gt as EventWriteAccessRequested,Re as MethodClose,Te as MethodCloseScanQrPopup,Ne as MethodDataSend,Ce as MethodExpand,Le as MethodIframeReady,We as MethodIframeWillReload,Pe as MethodInvokeCustomMethod,Be as MethodOpenInvoice,De as MethodOpenLink,Ee as MethodOpenPopup,ke as MethodOpenScanQrPopup,Je as MethodOpenTgLink,Oe as MethodReadTextFromClipboard,$e as MethodReady,Ie as MethodRequestPhone,je as MethodRequestTheme,Ae as MethodRequestViewport,Me as MethodRequestWriteAccess,Ue as MethodSetBackgroundColor,Ve as MethodSetBottomBarColor,Ge as MethodSetHeaderColor,He as MethodSetupBackButton,Qe as MethodSetupClosingBehavior,Fe as MethodSetupMainButton,ze as MethodSetupSettingsButton,Ye as MethodSetupSwipeBehavior,Ke as MethodSwitchInlineQuery,Xe as MethodTriggerHapticFeedback,u as NOT_SUPPORTED,St as ProviderTWA,p as TG_DESKTOP,_ as TG_PHONE,n as TG_WEB,w as bridgeClose,h as bridgeCloseScanQrPopup,f as bridgeDataSend,y as bridgeExpand,qe as bridgeGetInitData,l as bridgeGetThemeParams,x as bridgeIframeReady,k as bridgeIframeWillReload,I as bridgeInvokeCustomMethod,T as bridgeOpenInvoice,C as bridgeOpenLink,W as bridgeOpenPopup,D as bridgeOpenScanQrPopup,J as bridgeOpenTgLink,j as bridgeReadTextFromClipboard,M as bridgeReady,G as bridgeRequestPhone,H as bridgeRequestTheme,F as bridgeRequestViewport,K as bridgeRequestWriteAccess,xe as bridgeSend,he as bridgeSessionStorageGet,we as bridgeSessionStorageSet,Y as bridgeSetBackgroundColor,se as bridgeSetBottomBarColor,ee as bridgeSetHeaderColor,re as bridgeSetupBackButton,ie as bridgeSetupClosingBehavior,_e as bridgeSetupMainButton,de as bridgeSetupSettingsButton,fe as bridgeSetupSwipeBehavior,ce as bridgeSwitchInlineQuery,be as bridgeTriggerHapticFeedback,i as createIsViewportChanged,ye as debug,vt as getAppData,d as getPlatform,ht as listener,xe as sender,m as supportClose,v as supportCloseScanQrPopup,S as supportDataSend,q as supportExpand,P as supportIframeReady,O as supportIframeWillReload,R as supportInvokeCustomMethod,N as supportOpenInvoice,L as supportOpenLink,B as supportOpenPopup,E as supportOpenScanQrPopup,$ as supportOpenTgLink,A as supportReadTextFromClipboard,U as supportReady,V as supportRequestPhone,Q as supportRequestTheme,z as supportRequestViewport,X as supportRequestWriteAccess,ve as supportSessionStorageGet,me as supportSessionStorageSet,Z as supportSetBackgroundColor,ae as supportSetBottomBarColor,te as supportSetHeaderColor,oe as supportSetupBackButton,ne as supportSetupClosingBehavior,pe as supportSetupMainButton,ue as supportSetupSettingsButton,Se as supportSetupSwipeBehavior,ge as supportSwitchInlineQuery,le as supportTriggerHapticFeedback};