@tma.js/sdk-solid 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/dts/SDKProvider/SDKContext.d.ts +8 -0
  2. package/dist/dts/SDKProvider/SDKProvider.d.ts +8 -0
  3. package/dist/dts/SDKProvider/SDKProvider.types.d.ts +37 -0
  4. package/dist/dts/createHOC.d.ts +15 -0
  5. package/dist/dts/createHook.d.ts +11 -12
  6. package/dist/dts/hooks-hocs/back-button.d.ts +8 -0
  7. package/dist/dts/hooks-hocs/biometry-manager.d.ts +8 -0
  8. package/dist/dts/hooks-hocs/closing-behavior.d.ts +8 -0
  9. package/dist/dts/hooks-hocs/cloud-storage.d.ts +8 -0
  10. package/dist/dts/hooks-hocs/haptic-feedback.d.ts +8 -0
  11. package/dist/dts/hooks-hocs/init-data.d.ts +8 -0
  12. package/dist/dts/hooks-hocs/invoice.d.ts +8 -0
  13. package/dist/dts/hooks-hocs/main-button.d.ts +8 -0
  14. package/dist/dts/hooks-hocs/mini-app.d.ts +8 -0
  15. package/dist/dts/hooks-hocs/popup.d.ts +8 -0
  16. package/dist/dts/hooks-hocs/qr-scanner.d.ts +8 -0
  17. package/dist/dts/hooks-hocs/settings-button.d.ts +8 -0
  18. package/dist/dts/hooks-hocs/theme-params.d.ts +8 -0
  19. package/dist/dts/hooks-hocs/utils.d.ts +8 -0
  20. package/dist/dts/hooks-hocs/viewport.d.ts +8 -0
  21. package/dist/dts/index.d.ts +19 -4
  22. package/dist/index.cjs +2 -1
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.js +2939 -0
  25. package/dist/index.js.map +1 -0
  26. package/package.json +8 -8
  27. package/dist/dts/DisplayGate.d.ts +0 -24
  28. package/dist/dts/provider/SDKContext.d.ts +0 -2
  29. package/dist/dts/provider/SDKProvider.d.ts +0 -2
  30. package/dist/dts/provider/index.d.ts +0 -6
  31. package/dist/dts/provider/types.d.ts +0 -22
  32. package/dist/dts/provider/useInitResultDynamicValue.d.ts +0 -3
  33. package/dist/dts/provider/useInitResultValue.d.ts +0 -8
  34. package/dist/dts/provider/useSDKContext.d.ts +0 -5
  35. package/dist/dts/tools/back-button.d.ts +0 -4
  36. package/dist/dts/tools/closing-behavior.d.ts +0 -4
  37. package/dist/dts/tools/cloud-storage.d.ts +0 -4
  38. package/dist/dts/tools/haptic-feedback.d.ts +0 -4
  39. package/dist/dts/tools/index.d.ts +0 -17
  40. package/dist/dts/tools/init-data-raw.d.ts +0 -4
  41. package/dist/dts/tools/init-data.d.ts +0 -4
  42. package/dist/dts/tools/invoice.d.ts +0 -4
  43. package/dist/dts/tools/launch-params.d.ts +0 -5
  44. package/dist/dts/tools/main-button.d.ts +0 -4
  45. package/dist/dts/tools/mini-app.d.ts +0 -4
  46. package/dist/dts/tools/popup.d.ts +0 -4
  47. package/dist/dts/tools/post-event.d.ts +0 -4
  48. package/dist/dts/tools/qr-scanner.d.ts +0 -4
  49. package/dist/dts/tools/settings-button.d.ts +0 -4
  50. package/dist/dts/tools/theme-params.d.ts +0 -4
  51. package/dist/dts/tools/utils.d.ts +0 -4
  52. package/dist/dts/tools/viewport.d.ts +0 -4
  53. package/dist/dts/types.d.ts +0 -23
  54. package/dist/index.mjs +0 -115
package/dist/index.js ADDED
@@ -0,0 +1,2939 @@
1
+ import { createComponent as mt, mergeProps as ht, createContext as Qt, useContext as Ft, createEffect as pt, onCleanup as Yt, createResource as Zt, createMemo as ut, from as Xt } from "solid-js";
2
+ var te = Object.defineProperty, ee = (e, t, s) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, c = (e, t, s) => (ee(e, typeof t != "symbol" ? t + "" : t, s), s);
3
+ function wt(e, t) {
4
+ let s;
5
+ const n = () => {
6
+ s !== void 0 && t && t(s), s = void 0;
7
+ };
8
+ return [() => s === void 0 ? s = e(n) : s, n];
9
+ }
10
+ function bt(e) {
11
+ const t = W(), { count: s } = t;
12
+ t.unsubscribe(e), s && !t.count && Se();
13
+ }
14
+ function se(e) {
15
+ return W().subscribe(e), () => bt(e);
16
+ }
17
+ class ne {
18
+ constructor(t, s = {}) {
19
+ this.scope = t, this.options = s;
20
+ }
21
+ /**
22
+ * Prints message into a console in case, logger is currently enabled.
23
+ * @param level - log level.
24
+ * @param args - arguments.
25
+ */
26
+ print(t, ...s) {
27
+ const n = /* @__PURE__ */ new Date(), r = Intl.DateTimeFormat("en-GB", {
28
+ hour: "2-digit",
29
+ minute: "2-digit",
30
+ second: "2-digit",
31
+ fractionalSecondDigits: 3,
32
+ timeZone: "UTC"
33
+ }).format(n), { textColor: i, bgColor: o } = this.options, a = "font-weight: bold;padding: 0 5px;border-radius:5px";
34
+ console[t](
35
+ `%c${r}%c / %c${this.scope}`,
36
+ `${a};background-color: lightblue;color:black`,
37
+ "",
38
+ `${a};${i ? `color:${i};` : ""}${o ? `background-color:${o}` : ""}`,
39
+ ...s
40
+ );
41
+ }
42
+ /**
43
+ * Prints error message into a console.
44
+ * @param args
45
+ */
46
+ error(...t) {
47
+ this.print("error", ...t);
48
+ }
49
+ /**
50
+ * Prints log message into a console.
51
+ * @param args
52
+ */
53
+ log(...t) {
54
+ this.print("log", ...t);
55
+ }
56
+ }
57
+ const $ = new ne("SDK", {
58
+ bgColor: "forestgreen",
59
+ textColor: "white"
60
+ });
61
+ let Y = !1;
62
+ const dt = ({ event: e, args: [t] }) => {
63
+ $.log("Event received:", t === void 0 ? { name: e } : { name: e, data: t });
64
+ };
65
+ function re(e) {
66
+ Y !== e && (Y = e, e ? se(dt) : bt(dt));
67
+ }
68
+ function ie(...e) {
69
+ Y && $.log(...e);
70
+ }
71
+ class L {
72
+ constructor() {
73
+ c(this, "listeners", /* @__PURE__ */ new Map()), c(this, "listenersCount", 0), c(this, "subscribeListeners", []);
74
+ }
75
+ /**
76
+ * Removes all event listeners.
77
+ */
78
+ clear() {
79
+ this.listeners.clear(), this.subscribeListeners = [];
80
+ }
81
+ /**
82
+ * Returns count of bound listeners.
83
+ */
84
+ get count() {
85
+ return this.listenersCount + this.subscribeListeners.length;
86
+ }
87
+ emit(t, ...s) {
88
+ this.subscribeListeners.forEach((n) => n({
89
+ event: t,
90
+ args: s
91
+ })), (this.listeners.get(t) || []).forEach(([n, r]) => {
92
+ n(...s), r && this.off(t, n);
93
+ });
94
+ }
95
+ /**
96
+ * Adds new event listener.
97
+ * @param event - event name.
98
+ * @param listener - event listener.
99
+ * @param once - should listener be called only once.
100
+ * @returns Function to remove bound event listener.
101
+ */
102
+ on(t, s, n) {
103
+ let r = this.listeners.get(t);
104
+ return r || this.listeners.set(t, r = []), r.push([s, n]), this.listenersCount += 1, () => this.off(t, s);
105
+ }
106
+ /**
107
+ * Removes event listener. In case, specified listener was bound several times, it removes
108
+ * only a single one.
109
+ * @param event - event name.
110
+ * @param listener - event listener.
111
+ */
112
+ off(t, s) {
113
+ const n = this.listeners.get(t) || [];
114
+ for (let r = 0; r < n.length; r += 1)
115
+ if (s === n[r][0]) {
116
+ n.splice(r, 1), this.listenersCount -= 1;
117
+ return;
118
+ }
119
+ }
120
+ /**
121
+ * Adds a new event listener for all events.
122
+ * @param listener - event listener.
123
+ * @returns Function to remove event listener.
124
+ */
125
+ subscribe(t) {
126
+ return this.subscribeListeners.push(t), () => this.unsubscribe(t);
127
+ }
128
+ /**
129
+ * Removes global event listener. In case, specified listener was bound several times, it removes
130
+ * only a single one.
131
+ * @param listener - event listener.
132
+ */
133
+ unsubscribe(t) {
134
+ for (let s = 0; s < this.subscribeListeners.length; s += 1)
135
+ if (this.subscribeListeners[s] === t) {
136
+ this.subscribeListeners.splice(s, 1);
137
+ return;
138
+ }
139
+ }
140
+ }
141
+ function Z(e, t, s) {
142
+ return window.addEventListener(e, t, s), () => window.removeEventListener(e, t, s);
143
+ }
144
+ class U extends Error {
145
+ constructor(t, s, n) {
146
+ super(s, { cause: n }), this.type = t, Object.setPrototypeOf(this, U.prototype);
147
+ }
148
+ }
149
+ function d(e, t, s) {
150
+ return new U(e, t, s);
151
+ }
152
+ const oe = "ERR_METHOD_UNSUPPORTED", ae = "ERR_METHOD_PARAMETER_UNSUPPORTED", ce = "ERR_UNKNOWN_ENV", he = "ERR_INVOKE_CUSTOM_METHOD_RESPONSE", pe = "ERR_TIMED_OUT", ue = "ERR_UNEXPECTED_TYPE", vt = "ERR_PARSE", de = "ERR_NAVIGATION_LIST_EMPTY", le = "ERR_NAVIGATION_CURSOR_INVALID", Fs = "ERR_NAVIGATION_ITEM_INVALID", tt = "ERR_SSR_INIT", _e = "ERR_SSR_POST_EVENT", ge = "ERR_INVALID_PATH_BASE";
153
+ function C() {
154
+ return d(ue, "Value has unexpected type");
155
+ }
156
+ class H {
157
+ constructor(t, s, n) {
158
+ this.parser = t, this.isOptional = s, this.type = n;
159
+ }
160
+ /**
161
+ * Attempts to parse passed value
162
+ * @param value - value to parse.
163
+ * @throws {SDKError} ERR_PARSE
164
+ * @see ERR_PARSE
165
+ */
166
+ parse(t) {
167
+ if (!(this.isOptional && t === void 0))
168
+ try {
169
+ return this.parser(t);
170
+ } catch (s) {
171
+ throw d(
172
+ vt,
173
+ `Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
174
+ s
175
+ );
176
+ }
177
+ }
178
+ optional() {
179
+ return this.isOptional = !0, this;
180
+ }
181
+ }
182
+ function R(e, t) {
183
+ return () => new H(e, !1, t);
184
+ }
185
+ const v = R((e) => {
186
+ if (typeof e == "boolean")
187
+ return e;
188
+ const t = String(e);
189
+ if (t === "1" || t === "true")
190
+ return !0;
191
+ if (t === "0" || t === "false")
192
+ return !1;
193
+ throw C();
194
+ }, "boolean");
195
+ function yt(e, t) {
196
+ const s = {};
197
+ for (const n in e) {
198
+ const r = e[n];
199
+ if (!r)
200
+ continue;
201
+ let i, o;
202
+ if (typeof r == "function" || "parse" in r)
203
+ i = n, o = typeof r == "function" ? r : r.parse.bind(r);
204
+ else {
205
+ const { type: a } = r;
206
+ i = r.from || n, o = typeof a == "function" ? a : a.parse.bind(a);
207
+ }
208
+ try {
209
+ const a = o(t(i));
210
+ a !== void 0 && (s[n] = a);
211
+ } catch (a) {
212
+ throw d(vt, `Unable to parse field "${n}"`, a);
213
+ }
214
+ }
215
+ return s;
216
+ }
217
+ function et(e) {
218
+ let t = e;
219
+ if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
220
+ throw C();
221
+ return t;
222
+ }
223
+ function f(e, t) {
224
+ return new H((s) => {
225
+ const n = et(s);
226
+ return yt(e, (r) => n[r]);
227
+ }, !1, t);
228
+ }
229
+ const E = R((e) => {
230
+ if (typeof e == "number")
231
+ return e;
232
+ if (typeof e == "string") {
233
+ const t = Number(e);
234
+ if (!Number.isNaN(t))
235
+ return t;
236
+ }
237
+ throw C();
238
+ }, "number");
239
+ function st(e) {
240
+ return /^#[\da-f]{6}$/i.test(e);
241
+ }
242
+ function fe(e) {
243
+ return /^#[\da-f]{3}$/i.test(e);
244
+ }
245
+ function Et(e) {
246
+ const t = e.replace(/\s/g, "").toLowerCase();
247
+ if (st(t))
248
+ return t;
249
+ if (fe(t)) {
250
+ let n = "#";
251
+ for (let r = 0; r < 3; r += 1)
252
+ n += t[1 + r].repeat(2);
253
+ return n;
254
+ }
255
+ const s = t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
256
+ if (!s)
257
+ throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);
258
+ return s.slice(1).reduce((n, r) => {
259
+ const i = parseInt(r, 10).toString(16);
260
+ return n + (i.length === 1 ? "0" : "") + i;
261
+ }, "#");
262
+ }
263
+ const p = R((e) => {
264
+ if (typeof e == "string" || typeof e == "number")
265
+ return e.toString();
266
+ throw C();
267
+ }, "string"), Pt = R((e) => Et(p().parse(e)), "rgb");
268
+ function me(e) {
269
+ return f({
270
+ eventType: p(),
271
+ eventData: (t) => t
272
+ }).parse(e);
273
+ }
274
+ function we() {
275
+ ["TelegramGameProxy_receiveEvent", "TelegramGameProxy", "Telegram"].forEach((e) => {
276
+ delete window[e];
277
+ });
278
+ }
279
+ function be(e, t) {
280
+ window.dispatchEvent(new MessageEvent("message", {
281
+ data: JSON.stringify({ eventType: e, eventData: t }),
282
+ // We specify window.parent to imitate the case, the parent iframe sent us this event.
283
+ source: window.parent
284
+ }));
285
+ }
286
+ function ve() {
287
+ [
288
+ ["TelegramGameProxy_receiveEvent"],
289
+ // Windows Phone.
290
+ ["TelegramGameProxy", "receiveEvent"],
291
+ // Desktop.
292
+ ["Telegram", "WebView", "receiveEvent"]
293
+ // Android and iOS.
294
+ ].forEach((e) => {
295
+ let t = window;
296
+ e.forEach((s, n, r) => {
297
+ if (n === r.length - 1) {
298
+ t[s] = be;
299
+ return;
300
+ }
301
+ s in t || (t[s] = {}), t = t[s];
302
+ });
303
+ });
304
+ }
305
+ const ye = f({
306
+ button_id: (e) => e == null ? void 0 : p().parse(e)
307
+ }), Ee = {
308
+ clipboard_text_received: f({
309
+ req_id: p(),
310
+ data: (e) => e === null ? e : p().optional().parse(e)
311
+ }),
312
+ custom_method_invoked: f({
313
+ req_id: p(),
314
+ result: (e) => e,
315
+ error: p().optional()
316
+ }),
317
+ invoice_closed: f({
318
+ slug: p(),
319
+ status: p()
320
+ }),
321
+ phone_requested: f({
322
+ status: p()
323
+ }),
324
+ popup_closed: {
325
+ parse: (e) => ye.parse(e ?? {})
326
+ },
327
+ qr_text_received: f({
328
+ data: p().optional()
329
+ }),
330
+ theme_changed: f({
331
+ theme_params: (e) => {
332
+ const t = Pt().optional();
333
+ return Object.entries(et(e)).reduce((s, [n, r]) => (s[n] = t.parse(r), s), {});
334
+ }
335
+ }),
336
+ viewport_changed: f({
337
+ height: E(),
338
+ width: (e) => e == null ? window.innerWidth : E().parse(e),
339
+ is_state_stable: v(),
340
+ is_expanded: v()
341
+ }),
342
+ write_access_requested: f({
343
+ status: p()
344
+ })
345
+ };
346
+ function Pe() {
347
+ const e = new L();
348
+ ve();
349
+ let t = [
350
+ // Don't forget to remove created handlers.
351
+ we,
352
+ // Add "resize" event listener to make sure, we always have fresh viewport information.
353
+ // Desktop version of Telegram is sometimes not sending the viewport_changed
354
+ // event. For example, when the MainButton is shown. That's why we should
355
+ // add our own listener to make sure, viewport information is always fresh.
356
+ // Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/10
357
+ Z("resize", () => {
358
+ e.emit("viewport_changed", {
359
+ width: window.innerWidth,
360
+ height: window.innerHeight,
361
+ is_state_stable: !0,
362
+ is_expanded: !0
363
+ });
364
+ }),
365
+ // Add listener, which handles events sent from the Telegram web application and also events
366
+ // generated by the local emitEvent function.
367
+ Z("message", (s) => {
368
+ if (s.source !== window.parent)
369
+ return;
370
+ let n;
371
+ try {
372
+ n = me(s.data);
373
+ } catch {
374
+ return;
375
+ }
376
+ const { eventType: r, eventData: i } = n, o = Ee[r];
377
+ try {
378
+ const a = o ? o.parse(i) : i;
379
+ e.emit(...a ? [r, a] : [r]);
380
+ } catch (a) {
381
+ $.error(
382
+ `An error occurred processing the "${r}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,
383
+ n,
384
+ a
385
+ );
386
+ }
387
+ }),
388
+ // Clear emitter bound events.
389
+ () => e.clear()
390
+ ];
391
+ return [e, () => {
392
+ t.forEach((s) => s()), t = [];
393
+ }];
394
+ }
395
+ const [xe, Se] = wt(
396
+ (e) => {
397
+ const [t, s] = Pe(), n = t.off.bind(t);
398
+ return t.off = (r, i) => {
399
+ const { count: o } = t;
400
+ n(r, i), o && !t.count && e();
401
+ }, [t, s];
402
+ },
403
+ ([, e]) => e()
404
+ );
405
+ function W() {
406
+ return xe()[0];
407
+ }
408
+ function j(e, t) {
409
+ W().off(e, t);
410
+ }
411
+ function b(e, t, s) {
412
+ return W().on(e, t, s);
413
+ }
414
+ function q(e) {
415
+ return typeof e == "object" && e !== null && !Array.isArray(e);
416
+ }
417
+ function Ce(e, t) {
418
+ const s = e.split("."), n = t.split("."), r = Math.max(s.length, n.length);
419
+ for (let i = 0; i < r; i += 1) {
420
+ const o = parseInt(s[i] || "0", 10), a = parseInt(n[i] || "0", 10);
421
+ if (o !== a)
422
+ return o > a ? 1 : -1;
423
+ }
424
+ return 0;
425
+ }
426
+ function w(e, t) {
427
+ return Ce(e, t) <= 0;
428
+ }
429
+ function x(e, t, s) {
430
+ if (typeof s == "string") {
431
+ if (e === "web_app_open_link" && t === "try_instant_view")
432
+ return w("6.4", s);
433
+ if (e === "web_app_set_header_color" && t === "color")
434
+ return w("6.9", s);
435
+ }
436
+ switch (e) {
437
+ case "web_app_open_tg_link":
438
+ case "web_app_open_invoice":
439
+ case "web_app_setup_back_button":
440
+ case "web_app_set_background_color":
441
+ case "web_app_set_header_color":
442
+ case "web_app_trigger_haptic_feedback":
443
+ return w("6.1", t);
444
+ case "web_app_open_popup":
445
+ return w("6.2", t);
446
+ case "web_app_close_scan_qr_popup":
447
+ case "web_app_open_scan_qr_popup":
448
+ case "web_app_read_text_from_clipboard":
449
+ return w("6.4", t);
450
+ case "web_app_switch_inline_query":
451
+ return w("6.7", t);
452
+ case "web_app_invoke_custom_method":
453
+ case "web_app_request_write_access":
454
+ case "web_app_request_phone":
455
+ return w("6.9", t);
456
+ case "web_app_setup_settings_button":
457
+ return w("6.10", t);
458
+ case "web_app_biometry_get_info":
459
+ case "web_app_biometry_open_settings":
460
+ case "web_app_biometry_request_access":
461
+ case "web_app_biometry_request_auth":
462
+ case "web_app_biometry_update_token":
463
+ return w("7.2", t);
464
+ default:
465
+ return [
466
+ "iframe_ready",
467
+ "iframe_will_reload",
468
+ "web_app_close",
469
+ "web_app_data_send",
470
+ "web_app_expand",
471
+ "web_app_open_link",
472
+ "web_app_ready",
473
+ "web_app_request_theme",
474
+ "web_app_request_viewport",
475
+ "web_app_setup_main_button",
476
+ "web_app_setup_closing_behavior"
477
+ ].includes(e);
478
+ }
479
+ }
480
+ function Re(e) {
481
+ return "external" in e && q(e.external) && "notify" in e.external && typeof e.external.notify == "function";
482
+ }
483
+ function Te(e) {
484
+ return "TelegramWebviewProxy" in e && q(e.TelegramWebviewProxy) && "postEvent" in e.TelegramWebviewProxy && typeof e.TelegramWebviewProxy.postEvent == "function";
485
+ }
486
+ function xt() {
487
+ try {
488
+ return window.self !== window.top;
489
+ } catch {
490
+ return !0;
491
+ }
492
+ }
493
+ let St = "https://web.telegram.org";
494
+ function Ys(e) {
495
+ St = e;
496
+ }
497
+ function Ae() {
498
+ return St;
499
+ }
500
+ function k(e, t, s) {
501
+ let n = {}, r;
502
+ t === void 0 && s === void 0 ? n = {} : t !== void 0 && s !== void 0 ? (n = s, r = t) : t !== void 0 && ("targetOrigin" in t ? n = t : r = t);
503
+ const { targetOrigin: i = Ae() } = n;
504
+ if (ie("Posting event:", r ? { event: e, data: r } : { event: e }), xt()) {
505
+ window.parent.postMessage(JSON.stringify({ eventType: e, eventData: r }), i);
506
+ return;
507
+ }
508
+ if (Re(window)) {
509
+ window.external.notify(JSON.stringify({ eventType: e, eventData: r }));
510
+ return;
511
+ }
512
+ if (Te(window)) {
513
+ window.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
514
+ return;
515
+ }
516
+ throw d(
517
+ ce,
518
+ "Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment."
519
+ );
520
+ }
521
+ function Ie(e) {
522
+ return (t, s) => {
523
+ if (!x(t, e))
524
+ throw d(oe, `Method "${t}" is unsupported in Mini Apps version ${e}`);
525
+ if (q(s)) {
526
+ let n;
527
+ if (t === "web_app_open_link" && "try_instant_view" in s ? n = "try_instant_view" : t === "web_app_set_header_color" && "color" in s && (n = "color"), n && !x(t, n, e))
528
+ throw d(
529
+ ae,
530
+ `Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`
531
+ );
532
+ }
533
+ return k(t, s);
534
+ };
535
+ }
536
+ function Ct(e) {
537
+ return ({ req_id: t }) => t === e;
538
+ }
539
+ function Rt(e) {
540
+ return d(pe, `Timeout reached: ${e}ms`);
541
+ }
542
+ function Tt(e, t) {
543
+ return Promise.race([
544
+ typeof e == "function" ? e() : e,
545
+ new Promise((s, n) => {
546
+ setTimeout(() => {
547
+ n(Rt(t));
548
+ }, t);
549
+ })
550
+ ]);
551
+ }
552
+ async function m(e) {
553
+ let t;
554
+ const s = new Promise((u) => {
555
+ t = u;
556
+ }), {
557
+ method: n,
558
+ event: r,
559
+ capture: i,
560
+ postEvent: o = k,
561
+ timeout: a
562
+ } = e, h = (Array.isArray(r) ? r : [r]).map(
563
+ (u) => b(u, (D) => (!i || i(D)) && t(D))
564
+ );
565
+ try {
566
+ return o(n, e.params), await (a ? Tt(s, a) : s);
567
+ } finally {
568
+ h.forEach((u) => u());
569
+ }
570
+ }
571
+ async function A(e, t, s, n = {}) {
572
+ const {
573
+ result: r,
574
+ error: i
575
+ } = await m({
576
+ ...n,
577
+ method: "web_app_invoke_custom_method",
578
+ event: "custom_method_invoked",
579
+ params: {
580
+ method: e,
581
+ params: t,
582
+ req_id: s
583
+ },
584
+ capture: Ct(s)
585
+ });
586
+ if (i)
587
+ throw d(he, i);
588
+ return r;
589
+ }
590
+ function X(...e) {
591
+ return e.map((t) => {
592
+ if (typeof t == "string")
593
+ return t;
594
+ if (q(t))
595
+ return X(Object.entries(t).map((s) => s[1] && s[0]));
596
+ if (Array.isArray(t))
597
+ return X(...t);
598
+ }).filter(Boolean).join(" ");
599
+ }
600
+ function Zs(...e) {
601
+ return e.reduce((t, s) => (q(s) && Object.entries(s).forEach(([n, r]) => {
602
+ const i = X(t[n], r);
603
+ i.length && (t[n] = i);
604
+ }), t), {});
605
+ }
606
+ function At(e) {
607
+ const t = Et(e);
608
+ return Math.sqrt(
609
+ [0.299, 0.587, 0.114].reduce((s, n, r) => {
610
+ const i = parseInt(t.slice(1 + r * 2, 1 + (r + 1) * 2), 16);
611
+ return s + i * i * n;
612
+ }, 0)
613
+ ) < 120;
614
+ }
615
+ class ke {
616
+ constructor(t) {
617
+ c(this, "ee", new L()), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this.state = t;
618
+ }
619
+ /**
620
+ * Clones current state and returns its copy.
621
+ */
622
+ clone() {
623
+ return { ...this.state };
624
+ }
625
+ set(t, s) {
626
+ Object.entries(typeof t == "string" ? { [t]: s } : t).reduce((n, [r, i]) => this.state[r] === i || i === void 0 ? n : (this.state[r] = i, this.ee.emit(`change:${r}`, i), !0), !1) && this.ee.emit("change", this.state);
627
+ }
628
+ /**
629
+ * Returns value by specified key.
630
+ * @param key - state key.
631
+ */
632
+ get(t) {
633
+ return this.state[t];
634
+ }
635
+ }
636
+ class nt {
637
+ constructor(t) {
638
+ c(this, "state"), c(this, "get"), c(this, "set"), c(this, "clone"), this.state = new ke(t), this.set = this.state.set.bind(this.state), this.get = this.state.get.bind(this.state), this.clone = this.state.clone.bind(this.state);
639
+ }
640
+ }
641
+ function It(e, t) {
642
+ return (s) => x(t[s], e);
643
+ }
644
+ class rt extends nt {
645
+ constructor(t, s, n) {
646
+ super(t), c(this, "supports"), this.supports = It(s, n);
647
+ }
648
+ }
649
+ class Oe extends rt {
650
+ constructor(t, s, n) {
651
+ super({ isVisible: t }, s, {
652
+ show: "web_app_setup_back_button",
653
+ hide: "web_app_setup_back_button"
654
+ }), c(this, "on", (r, i) => r === "click" ? b("back_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? j("back_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
655
+ }
656
+ set isVisible(t) {
657
+ this.set("isVisible", t), this.postEvent("web_app_setup_back_button", { is_visible: t });
658
+ }
659
+ /**
660
+ * True if BackButton is currently visible.
661
+ */
662
+ get isVisible() {
663
+ return this.get("isVisible");
664
+ }
665
+ /**
666
+ * Hides the BackButton.
667
+ */
668
+ hide() {
669
+ this.isVisible = !1;
670
+ }
671
+ /**
672
+ * Shows the BackButton.
673
+ */
674
+ show() {
675
+ this.isVisible = !0;
676
+ }
677
+ }
678
+ function S() {
679
+ return typeof window > "u";
680
+ }
681
+ const kt = R((e) => e instanceof Date ? e : new Date(E().parse(e) * 1e3), "Date");
682
+ function it(e, t) {
683
+ return new H((s) => {
684
+ if (typeof s != "string" && !(s instanceof URLSearchParams))
685
+ throw C();
686
+ const n = typeof s == "string" ? new URLSearchParams(s) : s;
687
+ return yt(e, (r) => {
688
+ const i = n.get(r);
689
+ return i === null ? void 0 : i;
690
+ });
691
+ }, !1, t);
692
+ }
693
+ const qe = f({
694
+ id: E(),
695
+ type: p(),
696
+ title: p(),
697
+ photoUrl: {
698
+ type: p().optional(),
699
+ from: "photo_url"
700
+ },
701
+ username: p().optional()
702
+ }, "Chat").optional(), lt = f({
703
+ addedToAttachmentMenu: {
704
+ type: v().optional(),
705
+ from: "added_to_attachment_menu"
706
+ },
707
+ allowsWriteToPm: {
708
+ type: v().optional(),
709
+ from: "allows_write_to_pm"
710
+ },
711
+ firstName: {
712
+ type: p(),
713
+ from: "first_name"
714
+ },
715
+ id: E(),
716
+ isBot: {
717
+ type: v().optional(),
718
+ from: "is_bot"
719
+ },
720
+ isPremium: {
721
+ type: v().optional(),
722
+ from: "is_premium"
723
+ },
724
+ languageCode: {
725
+ type: p().optional(),
726
+ from: "language_code"
727
+ },
728
+ lastName: {
729
+ type: p().optional(),
730
+ from: "last_name"
731
+ },
732
+ photoUrl: {
733
+ type: p().optional(),
734
+ from: "photo_url"
735
+ },
736
+ username: p().optional()
737
+ }, "User").optional();
738
+ function Ot() {
739
+ return it({
740
+ authDate: {
741
+ type: kt(),
742
+ from: "auth_date"
743
+ },
744
+ canSendAfter: {
745
+ type: E().optional(),
746
+ from: "can_send_after"
747
+ },
748
+ chat: qe,
749
+ chatInstance: {
750
+ type: p().optional(),
751
+ from: "chat_instance"
752
+ },
753
+ chatType: {
754
+ type: p().optional(),
755
+ from: "chat_type"
756
+ },
757
+ hash: p(),
758
+ queryId: {
759
+ type: p().optional(),
760
+ from: "query_id"
761
+ },
762
+ receiver: lt,
763
+ startParam: {
764
+ type: p().optional(),
765
+ from: "start_param"
766
+ },
767
+ user: lt
768
+ }, "InitData");
769
+ }
770
+ function Ne(e) {
771
+ return e.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
772
+ }
773
+ function De(e) {
774
+ return e.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
775
+ }
776
+ const qt = R(
777
+ (e) => {
778
+ const t = Pt().optional();
779
+ return Object.entries(et(e)).reduce((s, [n, r]) => (s[Ne(n)] = t.parse(r), s), {});
780
+ },
781
+ "ThemeParams"
782
+ );
783
+ function Nt(e) {
784
+ return it({
785
+ botInline: {
786
+ type: v().optional(),
787
+ from: "tgWebAppBotInline"
788
+ },
789
+ initData: {
790
+ type: Ot().optional(),
791
+ from: "tgWebAppData"
792
+ },
793
+ initDataRaw: {
794
+ type: p().optional(),
795
+ from: "tgWebAppData"
796
+ },
797
+ platform: {
798
+ type: p(),
799
+ from: "tgWebAppPlatform"
800
+ },
801
+ showSettings: {
802
+ type: v().optional(),
803
+ from: "tgWebAppShowSettings"
804
+ },
805
+ startParam: {
806
+ type: p().optional(),
807
+ from: "tgWebAppStartParam"
808
+ },
809
+ themeParams: {
810
+ type: qt(),
811
+ from: "tgWebAppThemeParams"
812
+ },
813
+ version: {
814
+ type: p(),
815
+ from: "tgWebAppVersion"
816
+ }
817
+ }).parse(e);
818
+ }
819
+ function Dt(e) {
820
+ return Nt(
821
+ e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&")
822
+ );
823
+ }
824
+ function Ve() {
825
+ return Dt(window.location.href);
826
+ }
827
+ function Vt() {
828
+ return performance.getEntriesByType("navigation")[0];
829
+ }
830
+ function Me() {
831
+ const e = Vt();
832
+ if (!e)
833
+ throw new Error("Unable to get first navigation entry.");
834
+ return Dt(e.name);
835
+ }
836
+ function Mt(e) {
837
+ return `tma.js/${e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`)}`;
838
+ }
839
+ function Bt(e, t) {
840
+ sessionStorage.setItem(Mt(e), JSON.stringify(t));
841
+ }
842
+ function $t(e) {
843
+ const t = sessionStorage.getItem(Mt(e));
844
+ try {
845
+ return t ? JSON.parse(t) : void 0;
846
+ } catch {
847
+ }
848
+ }
849
+ function Be() {
850
+ return Nt($t("launchParams") || "");
851
+ }
852
+ function $e(e) {
853
+ return JSON.stringify(
854
+ Object.fromEntries(
855
+ Object.entries(e).map(([t, s]) => [De(t), s])
856
+ )
857
+ );
858
+ }
859
+ function Le(e) {
860
+ const {
861
+ initDataRaw: t,
862
+ themeParams: s,
863
+ platform: n,
864
+ version: r,
865
+ showSettings: i,
866
+ startParam: o,
867
+ botInline: a
868
+ } = e, h = new URLSearchParams();
869
+ return h.set("tgWebAppPlatform", n), h.set("tgWebAppThemeParams", $e(s)), h.set("tgWebAppVersion", r), t && h.set("tgWebAppData", t), o && h.set("tgWebAppStartParam", o), typeof i == "boolean" && h.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && h.set("tgWebAppBotInline", a ? "1" : "0"), h.toString();
870
+ }
871
+ function Ue(e) {
872
+ Bt("launchParams", Le(e));
873
+ }
874
+ function He() {
875
+ for (const e of [
876
+ // Try to retrieve launch parameters from the current location. This method can return
877
+ // nothing in case, location was changed and then page was reloaded.
878
+ Ve,
879
+ // Then, try using the lower level API - window.performance.
880
+ Me,
881
+ // Finally, try to extract launch parameters from the session storage.
882
+ Be
883
+ ])
884
+ try {
885
+ const t = e();
886
+ return Ue(t), t;
887
+ } catch {
888
+ }
889
+ throw new Error("Unable to retrieve launch parameters from any known source.");
890
+ }
891
+ function Lt() {
892
+ const e = Vt();
893
+ return !!(e && e.type === "reload");
894
+ }
895
+ function We() {
896
+ let e = 0;
897
+ return () => (e += 1).toString();
898
+ }
899
+ const [je] = wt(We);
900
+ function l(e, t) {
901
+ return ({ ssr: s } = {}) => {
902
+ let n;
903
+ if (S()) {
904
+ if (!s)
905
+ throw d(
906
+ tt,
907
+ "ssr.options must be specified to initialize component on the server side"
908
+ );
909
+ n = s;
910
+ } else
911
+ n = He();
912
+ const r = {
913
+ ...n,
914
+ postEvent: "version" in n ? Ie(n.version) : () => {
915
+ throw d(
916
+ _e,
917
+ "postEvent function is forbidden to be called on the server side."
918
+ );
919
+ },
920
+ createRequestId: je()
921
+ };
922
+ if (S() || typeof e == "function")
923
+ return typeof e == "function" ? e(r) : t(r);
924
+ const i = t({
925
+ ...r,
926
+ state: Lt() ? $t(e) : void 0
927
+ }), o = (a) => (a.on("change", (h) => {
928
+ Bt(e, h);
929
+ }), a);
930
+ return i instanceof Promise ? i.then(o) : o(i);
931
+ };
932
+ }
933
+ const Ge = l("backButton", ({
934
+ postEvent: e,
935
+ version: t,
936
+ state: s = { isVisible: !1 }
937
+ }) => new Oe(s.isVisible, t, e));
938
+ class N extends rt {
939
+ constructor() {
940
+ super(...arguments), c(this, "on", this.state.on.bind(this.state)), c(this, "off", this.state.off.bind(this.state));
941
+ }
942
+ }
943
+ function Ut(e) {
944
+ const t = e.available ? e : {
945
+ available: !1,
946
+ device_id: "",
947
+ token_saved: !1,
948
+ access_requested: !1,
949
+ access_granted: !1,
950
+ type: ""
951
+ };
952
+ return {
953
+ available: !0,
954
+ type: t.type,
955
+ deviceId: t.device_id,
956
+ tokenSaved: t.token_saved,
957
+ accessRequested: t.access_requested,
958
+ accessGranted: t.access_granted
959
+ };
960
+ }
961
+ class _t extends N {
962
+ constructor({ postEvent: t, version: s, ...n }) {
963
+ super(n, s, {
964
+ auth: "web_app_biometry_request_auth",
965
+ openSettings: "web_app_biometry_open_settings",
966
+ requestAccess: "web_app_biometry_request_access",
967
+ updateToken: "web_app_biometry_update_token"
968
+ }), c(this, "postEvent"), c(this, "authPromise"), c(this, "accessPromise"), this.postEvent = t;
969
+ }
970
+ /**
971
+ * Shows whether biometry is available.
972
+ */
973
+ get available() {
974
+ return this.get("available");
975
+ }
976
+ /**
977
+ * Shows whether permission to use biometrics has been granted.
978
+ */
979
+ get accessGranted() {
980
+ return this.get("accessGranted");
981
+ }
982
+ /**
983
+ * Shows whether if permission to use biometrics has been requested.
984
+ */
985
+ get accessRequested() {
986
+ return this.get("accessRequested");
987
+ }
988
+ /**
989
+ * Authenticates the user using biometrics.
990
+ * @param options - method options.
991
+ * @since 7.2
992
+ * @returns Token from the local secure storage, if authentication was successful.
993
+ */
994
+ async authenticate({
995
+ reason: t,
996
+ ...s
997
+ }) {
998
+ return this.authPromise || (this.authPromise = m({
999
+ ...s,
1000
+ method: "web_app_biometry_request_auth",
1001
+ event: "biometry_auth_requested",
1002
+ postEvent: this.postEvent,
1003
+ params: {
1004
+ // TODO: Check if reason is empty works fine.
1005
+ reason: (t || "").trim()
1006
+ }
1007
+ }).then(({ token: n }) => n).finally(() => this.authPromise = void 0)), this.authPromise;
1008
+ }
1009
+ /**
1010
+ * A unique device identifier that can be used to match the token to the device.
1011
+ */
1012
+ get deviceId() {
1013
+ return this.get("deviceId");
1014
+ }
1015
+ /**
1016
+ * Opens the biometric access settings for bots. Useful when you need to request biometrics
1017
+ * access to users who haven't granted it yet.
1018
+ *
1019
+ * _Note that this method can be called only in response to user interaction with the Mini App
1020
+ * interface (e.g. a click inside the Mini App or on the main button)_.
1021
+ * @since 7.2
1022
+ */
1023
+ openSettings() {
1024
+ this.postEvent("web_app_biometry_open_settings");
1025
+ }
1026
+ /**
1027
+ * Requests permission to use biometrics.
1028
+ * @since 7.2
1029
+ * @returns Promise with true, if access was granted.
1030
+ */
1031
+ requestAccess({ reason: t, ...s } = {}) {
1032
+ return this.accessPromise || (this.accessPromise = m({
1033
+ ...s,
1034
+ postEvent: this.postEvent,
1035
+ method: "web_app_biometry_request_access",
1036
+ event: "biometry_info_received",
1037
+ params: { reason: t || "" }
1038
+ }).then((n) => {
1039
+ const r = Ut(n);
1040
+ return this.set(r), r.accessGranted;
1041
+ }).finally(() => this.accessPromise = void 0)), this.accessPromise;
1042
+ }
1043
+ /**
1044
+ * The type of biometrics currently available on the device.
1045
+ */
1046
+ get biometryType() {
1047
+ return this.get("biometryType");
1048
+ }
1049
+ /**
1050
+ * Shows whether token was saved previously in the local secure storage.
1051
+ */
1052
+ get tokenSaved() {
1053
+ return this.get("tokenSaved");
1054
+ }
1055
+ /**
1056
+ * Updates the biometric token in a secure storage on the device.
1057
+ * @returns Promise with `true`, if token was updated.
1058
+ */
1059
+ async updateToken({ token: t, ...s } = {}) {
1060
+ return ["removed", "updated"].includes(
1061
+ (await m({
1062
+ ...s,
1063
+ postEvent: this.postEvent,
1064
+ method: "web_app_biometry_update_token",
1065
+ event: "biometry_token_updated",
1066
+ params: { token: t || "" }
1067
+ })).status
1068
+ );
1069
+ }
1070
+ }
1071
+ async function ze(e) {
1072
+ return Ut(
1073
+ await m({
1074
+ ...e || {},
1075
+ method: "web_app_biometry_get_info",
1076
+ event: "biometry_info_received"
1077
+ })
1078
+ );
1079
+ }
1080
+ const Ke = l("biometryManager", async ({ postEvent: e, version: t, state: s }) => {
1081
+ if (s)
1082
+ return new _t({ ...s, version: t, postEvent: e });
1083
+ if (S())
1084
+ throw d(
1085
+ tt,
1086
+ "BiometryManager cannot be instantiated on the server side without passing the ssr.state object."
1087
+ );
1088
+ return new _t({
1089
+ ...await ze({ timeout: 1e3 }),
1090
+ version: t,
1091
+ postEvent: e
1092
+ });
1093
+ });
1094
+ class ot extends nt {
1095
+ constructor() {
1096
+ super(...arguments), c(this, "on", this.state.on.bind(this.state)), c(this, "off", this.state.off.bind(this.state));
1097
+ }
1098
+ }
1099
+ class Je extends ot {
1100
+ constructor(t, s) {
1101
+ super({ isConfirmationNeeded: t }), this.postEvent = s;
1102
+ }
1103
+ set isConfirmationNeeded(t) {
1104
+ this.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
1105
+ }
1106
+ /**
1107
+ * True, if the confirmation dialog should be shown while the user is trying to close
1108
+ * the Mini App.
1109
+ */
1110
+ get isConfirmationNeeded() {
1111
+ return this.get("isConfirmationNeeded");
1112
+ }
1113
+ /**
1114
+ * Disables the confirmation dialog when closing the Mini App.
1115
+ */
1116
+ disableConfirmation() {
1117
+ this.isConfirmationNeeded = !1;
1118
+ }
1119
+ /**
1120
+ * Enables the confirmation dialog when closing the Mini App.
1121
+ */
1122
+ enableConfirmation() {
1123
+ this.isConfirmationNeeded = !0;
1124
+ }
1125
+ }
1126
+ const Qe = l("closingBehavior", ({
1127
+ postEvent: e,
1128
+ state: t = { isConfirmationNeeded: !1 }
1129
+ }) => new Je(t.isConfirmationNeeded, e));
1130
+ class at {
1131
+ constructor(t, s) {
1132
+ c(this, "supports"), this.supports = It(t, s);
1133
+ }
1134
+ }
1135
+ function Fe(e) {
1136
+ if (Array.isArray(e))
1137
+ return e;
1138
+ if (typeof e == "string")
1139
+ try {
1140
+ const t = JSON.parse(e);
1141
+ if (Array.isArray(t))
1142
+ return t;
1143
+ } catch {
1144
+ }
1145
+ throw C();
1146
+ }
1147
+ class Ye extends H {
1148
+ constructor(t, s, n) {
1149
+ super(Fe, s, n), c(this, "itemParser"), this.itemParser = typeof t == "function" ? t : t.parse.bind(t);
1150
+ }
1151
+ /**
1152
+ * Attempts to parse passed value
1153
+ * @param value - value to parse.
1154
+ * @throws {SDKError} ERR_PARSE
1155
+ * @see ERR_PARSE
1156
+ */
1157
+ parse(t) {
1158
+ const s = super.parse(t);
1159
+ return s === void 0 ? s : s.map(this.itemParser);
1160
+ }
1161
+ of(t) {
1162
+ return this.itemParser = typeof t == "function" ? t : t.parse.bind(t), this;
1163
+ }
1164
+ }
1165
+ function Ze(e) {
1166
+ return new Ye((t) => t, !1, e);
1167
+ }
1168
+ function gt(e, t) {
1169
+ return Object.fromEntries(e.map((s) => [s, t]));
1170
+ }
1171
+ class Xe extends at {
1172
+ constructor(t, s, n) {
1173
+ super(t, {
1174
+ delete: "web_app_invoke_custom_method",
1175
+ get: "web_app_invoke_custom_method",
1176
+ getKeys: "web_app_invoke_custom_method",
1177
+ set: "web_app_invoke_custom_method"
1178
+ }), this.createRequestId = s, this.postEvent = n;
1179
+ }
1180
+ /**
1181
+ * Deletes specified key or keys from the cloud storage.
1182
+ * @param keyOrKeys - key or keys to delete.
1183
+ * @param options - request execution options.
1184
+ */
1185
+ async delete(t, s = {}) {
1186
+ const n = Array.isArray(t) ? t : [t];
1187
+ n.length && await A(
1188
+ "deleteStorageValues",
1189
+ { keys: n },
1190
+ this.createRequestId(),
1191
+ { ...s, postEvent: this.postEvent }
1192
+ );
1193
+ }
1194
+ /**
1195
+ * Returns list of all keys presented in the cloud storage.
1196
+ * @param options - request execution options.
1197
+ */
1198
+ async getKeys(t = {}) {
1199
+ return Ze().of(p()).parse(
1200
+ await A(
1201
+ "getStorageKeys",
1202
+ {},
1203
+ this.createRequestId(),
1204
+ { ...t, postEvent: this.postEvent }
1205
+ )
1206
+ );
1207
+ }
1208
+ async get(t, s = {}) {
1209
+ const n = Array.isArray(t) ? t : [t];
1210
+ if (!n.length)
1211
+ return gt(n, "");
1212
+ const r = await A(
1213
+ "getStorageValues",
1214
+ { keys: n },
1215
+ this.createRequestId(),
1216
+ { ...s, postEvent: this.postEvent }
1217
+ ), i = f(gt(n, p()), "CloudStorageData").parse(r);
1218
+ return Array.isArray(t) ? i : i[t];
1219
+ }
1220
+ /**
1221
+ * Saves specified value by key.
1222
+ * @param key - storage key.
1223
+ * @param value - storage value.
1224
+ * @param options - request execution options.
1225
+ */
1226
+ async set(t, s, n = {}) {
1227
+ await A(
1228
+ "saveStorageValue",
1229
+ { key: t, value: s },
1230
+ this.createRequestId(),
1231
+ { ...n, postEvent: this.postEvent }
1232
+ );
1233
+ }
1234
+ }
1235
+ const ts = l(
1236
+ ({ createRequestId: e, postEvent: t, version: s }) => new Xe(s, e, t)
1237
+ );
1238
+ class es extends at {
1239
+ constructor(t, s) {
1240
+ super(t, {
1241
+ impactOccurred: "web_app_trigger_haptic_feedback",
1242
+ notificationOccurred: "web_app_trigger_haptic_feedback",
1243
+ selectionChanged: "web_app_trigger_haptic_feedback"
1244
+ }), this.postEvent = s;
1245
+ }
1246
+ /**
1247
+ * A method tells that an impact occurred. The Telegram app may play the
1248
+ * appropriate haptics based on style value passed.
1249
+ * @param style - impact style.
1250
+ */
1251
+ impactOccurred(t) {
1252
+ this.postEvent("web_app_trigger_haptic_feedback", {
1253
+ type: "impact",
1254
+ impact_style: t
1255
+ });
1256
+ }
1257
+ /**
1258
+ * A method tells that a task or action has succeeded, failed, or produced
1259
+ * a warning. The Telegram app may play the appropriate haptics based on
1260
+ * type value passed.
1261
+ * @param type - notification type.
1262
+ */
1263
+ notificationOccurred(t) {
1264
+ this.postEvent("web_app_trigger_haptic_feedback", {
1265
+ type: "notification",
1266
+ notification_type: t
1267
+ });
1268
+ }
1269
+ /**
1270
+ * A method tells that the user has changed a selection. The Telegram app
1271
+ * may play the appropriate haptics.
1272
+ *
1273
+ * Do not use this feedback when the user makes or confirms a selection;
1274
+ * use it only when the selection changes.
1275
+ */
1276
+ selectionChanged() {
1277
+ this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1278
+ }
1279
+ }
1280
+ const ss = l(
1281
+ ({ version: e, postEvent: t }) => new es(e, t)
1282
+ );
1283
+ class ns {
1284
+ constructor(t) {
1285
+ this.initData = t;
1286
+ }
1287
+ /**
1288
+ * @see InitDataParsed.authDate
1289
+ */
1290
+ get authDate() {
1291
+ return this.initData.authDate;
1292
+ }
1293
+ /**
1294
+ * @see InitDataParsed.canSendAfter
1295
+ */
1296
+ get canSendAfter() {
1297
+ return this.initData.canSendAfter;
1298
+ }
1299
+ /**
1300
+ * Date after which it is allowed to call
1301
+ * the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
1302
+ */
1303
+ get canSendAfterDate() {
1304
+ const { canSendAfter: t } = this;
1305
+ return t ? new Date(this.authDate.getTime() + t * 1e3) : void 0;
1306
+ }
1307
+ /**
1308
+ * @see InitDataParsed.chat
1309
+ */
1310
+ get chat() {
1311
+ return this.initData.chat;
1312
+ }
1313
+ /**
1314
+ * @see InitDataParsed.chatType
1315
+ */
1316
+ get chatType() {
1317
+ return this.initData.chatType;
1318
+ }
1319
+ /**
1320
+ * @see InitDataParsed.chatInstance
1321
+ */
1322
+ get chatInstance() {
1323
+ return this.initData.chatInstance;
1324
+ }
1325
+ /**
1326
+ * @see InitDataParsed.hash
1327
+ */
1328
+ get hash() {
1329
+ return this.initData.hash;
1330
+ }
1331
+ /**
1332
+ * @see InitDataParsed.queryId
1333
+ */
1334
+ get queryId() {
1335
+ return this.initData.queryId;
1336
+ }
1337
+ /**
1338
+ * @see InitDataParsed.receiver
1339
+ */
1340
+ get receiver() {
1341
+ return this.initData.receiver;
1342
+ }
1343
+ /**
1344
+ * @see InitDataParsed.startParam
1345
+ */
1346
+ get startParam() {
1347
+ return this.initData.startParam;
1348
+ }
1349
+ /**
1350
+ * @see InitDataParsed.user
1351
+ */
1352
+ get user() {
1353
+ return this.initData.user;
1354
+ }
1355
+ }
1356
+ const rs = l(
1357
+ ({ initData: e }) => e ? new ns(e) : void 0
1358
+ );
1359
+ function Xs(e) {
1360
+ return Ot().parse(e);
1361
+ }
1362
+ class is extends N {
1363
+ constructor(t, s, n) {
1364
+ super({ isOpened: t }, s, { open: "web_app_open_invoice" }), this.postEvent = n;
1365
+ }
1366
+ set isOpened(t) {
1367
+ this.set("isOpened", t);
1368
+ }
1369
+ /**
1370
+ * True if invoice is currently opened.
1371
+ */
1372
+ get isOpened() {
1373
+ return this.get("isOpened");
1374
+ }
1375
+ async open(t, s) {
1376
+ if (this.isOpened)
1377
+ throw new Error("Invoice is already opened");
1378
+ let n;
1379
+ if (!s)
1380
+ n = t;
1381
+ else {
1382
+ const { hostname: r, pathname: i } = new URL(t, window.location.href);
1383
+ if (r !== "t.me")
1384
+ throw new Error(`Incorrect hostname: ${r}`);
1385
+ const o = i.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1386
+ if (!o)
1387
+ throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1388
+ [, , n] = o;
1389
+ }
1390
+ this.isOpened = !0;
1391
+ try {
1392
+ return (await m({
1393
+ method: "web_app_open_invoice",
1394
+ event: "invoice_closed",
1395
+ params: { slug: n },
1396
+ postEvent: this.postEvent,
1397
+ capture(r) {
1398
+ return n === r.slug;
1399
+ }
1400
+ })).status;
1401
+ } finally {
1402
+ this.isOpened = !1;
1403
+ }
1404
+ }
1405
+ }
1406
+ const os = l(
1407
+ ({ version: e, postEvent: t }) => new is(!1, e, t)
1408
+ );
1409
+ class as extends nt {
1410
+ constructor({ postEvent: t, ...s }) {
1411
+ super(s), c(this, "postEvent"), c(this, "on", (n, r) => n === "click" ? b("main_button_pressed", r) : this.state.on(n, r)), c(this, "off", (n, r) => n === "click" ? j("main_button_pressed", r) : this.state.off(n, r)), this.postEvent = t;
1412
+ }
1413
+ /**
1414
+ * Sends current local state to the Telegram application.
1415
+ */
1416
+ commit() {
1417
+ this.text !== "" && this.postEvent("web_app_setup_main_button", {
1418
+ is_visible: this.isVisible,
1419
+ is_active: this.isEnabled,
1420
+ is_progress_visible: this.isLoaderVisible,
1421
+ text: this.text,
1422
+ color: this.backgroundColor,
1423
+ text_color: this.textColor
1424
+ });
1425
+ }
1426
+ set isEnabled(t) {
1427
+ this.setParams({ isEnabled: t });
1428
+ }
1429
+ /**
1430
+ * True if the MainButton is enabled.
1431
+ */
1432
+ get isEnabled() {
1433
+ return this.get("isEnabled");
1434
+ }
1435
+ set isLoaderVisible(t) {
1436
+ this.setParams({ isLoaderVisible: t });
1437
+ }
1438
+ /**
1439
+ * True if the MainButton loader is visible.
1440
+ */
1441
+ get isLoaderVisible() {
1442
+ return this.get("isLoaderVisible");
1443
+ }
1444
+ set isVisible(t) {
1445
+ this.setParams({ isVisible: t });
1446
+ }
1447
+ /**
1448
+ * True if the MainButton is visible.
1449
+ */
1450
+ get isVisible() {
1451
+ return this.get("isVisible");
1452
+ }
1453
+ /**
1454
+ * The MainButton background color.
1455
+ */
1456
+ get backgroundColor() {
1457
+ return this.get("backgroundColor");
1458
+ }
1459
+ /**
1460
+ * The MainButton text.
1461
+ */
1462
+ get text() {
1463
+ return this.get("text");
1464
+ }
1465
+ /**
1466
+ * The MainButton text color.
1467
+ */
1468
+ get textColor() {
1469
+ return this.get("textColor");
1470
+ }
1471
+ /**
1472
+ * Disables the MainButton.
1473
+ * @see Does not work on Android: https://github.com/Telegram-Mini-Apps/issues/issues/1
1474
+ */
1475
+ disable() {
1476
+ return this.isEnabled = !1, this;
1477
+ }
1478
+ /**
1479
+ * Enables the MainButton.
1480
+ */
1481
+ enable() {
1482
+ return this.isEnabled = !0, this;
1483
+ }
1484
+ /**
1485
+ * Hides the MainButton.
1486
+ */
1487
+ hide() {
1488
+ return this.isVisible = !1, this;
1489
+ }
1490
+ /**
1491
+ * Hides the MainButton loading indicator.
1492
+ */
1493
+ hideLoader() {
1494
+ return this.isLoaderVisible = !1, this;
1495
+ }
1496
+ /**
1497
+ * Shows the MainButton.
1498
+ *
1499
+ * Note that opening the Mini App from the attachment menu hides the main button until the
1500
+ * user interacts with the Mini App interface.
1501
+ */
1502
+ show() {
1503
+ return this.isVisible = !0, this;
1504
+ }
1505
+ /**
1506
+ * Shows a loading indicator on the Main Button.
1507
+ */
1508
+ showLoader() {
1509
+ return this.isLoaderVisible = !0, this;
1510
+ }
1511
+ /**
1512
+ * Sets a new MainButton text. Minimal length for the text is 1 symbol, and maximum is 64 symbols.
1513
+ * @param text - a new text.
1514
+ */
1515
+ setText(t) {
1516
+ return this.setParams({ text: t });
1517
+ }
1518
+ /**
1519
+ * Sets a new Main Button text color.
1520
+ * @param textColor - new text color.
1521
+ */
1522
+ setTextColor(t) {
1523
+ return this.setParams({ textColor: t });
1524
+ }
1525
+ /**
1526
+ * Updates current Main Button color.
1527
+ * @param backgroundColor - color to set.
1528
+ */
1529
+ setBackgroundColor(t) {
1530
+ return this.setParams({ backgroundColor: t });
1531
+ }
1532
+ /**
1533
+ * Allows setting multiple Main Button parameters.
1534
+ * @param params - Main Button parameters.
1535
+ */
1536
+ setParams(t) {
1537
+ return this.set(t), this.commit(), this;
1538
+ }
1539
+ }
1540
+ const cs = l("mainButton", ({
1541
+ postEvent: e,
1542
+ themeParams: t,
1543
+ state: s = {
1544
+ isVisible: !1,
1545
+ isEnabled: !1,
1546
+ text: "",
1547
+ isLoaderVisible: !1,
1548
+ textColor: t.buttonTextColor || "#ffffff",
1549
+ backgroundColor: t.buttonColor || "#000000"
1550
+ }
1551
+ }) => new as({ ...s, postEvent: e }));
1552
+ function hs() {
1553
+ return it({
1554
+ contact: f({
1555
+ userId: {
1556
+ type: E(),
1557
+ from: "user_id"
1558
+ },
1559
+ phoneNumber: {
1560
+ type: p(),
1561
+ from: "phone_number"
1562
+ },
1563
+ firstName: {
1564
+ type: p(),
1565
+ from: "first_name"
1566
+ },
1567
+ lastName: {
1568
+ type: p().optional(),
1569
+ from: "last_name"
1570
+ }
1571
+ }),
1572
+ authDate: {
1573
+ type: kt(),
1574
+ from: "auth_date"
1575
+ },
1576
+ hash: p()
1577
+ }, "RequestedContact");
1578
+ }
1579
+ function Ht(e, t) {
1580
+ return (s) => {
1581
+ const [n, r] = t[s];
1582
+ return x(n, r, e);
1583
+ };
1584
+ }
1585
+ function ps(e) {
1586
+ return new Promise((t) => {
1587
+ setTimeout(t, e);
1588
+ });
1589
+ }
1590
+ class us extends N {
1591
+ constructor({ postEvent: t, createRequestId: s, version: n, botInline: r, ...i }) {
1592
+ super(i, n, {
1593
+ requestPhoneAccess: "web_app_request_phone",
1594
+ requestWriteAccess: "web_app_request_write_access",
1595
+ switchInlineQuery: "web_app_switch_inline_query",
1596
+ setHeaderColor: "web_app_set_header_color",
1597
+ setBackgroundColor: "web_app_set_background_color"
1598
+ }), c(this, "botInline"), c(this, "postEvent"), c(this, "createRequestId"), c(this, "requestPhoneAccessPromise"), c(this, "requestWriteAccessPromise"), c(this, "supportsParam"), this.createRequestId = s, this.postEvent = t, this.botInline = r;
1599
+ const o = this.supports.bind(this);
1600
+ this.supports = (a) => o(a) ? a !== "switchInlineQuery" || r : !1, this.supportsParam = Ht(n, {
1601
+ "setHeaderColor.color": ["web_app_set_header_color", "color"]
1602
+ });
1603
+ }
1604
+ /**
1605
+ * Attempts to get requested contact.
1606
+ * @param timeout - request timeout.
1607
+ */
1608
+ async getRequestedContact({
1609
+ timeout: t = 1e4
1610
+ } = {}) {
1611
+ return hs().parse(
1612
+ await A(
1613
+ "getRequestedContact",
1614
+ {},
1615
+ this.createRequestId(),
1616
+ { postEvent: this.postEvent, timeout: t }
1617
+ )
1618
+ );
1619
+ }
1620
+ /**
1621
+ * The Mini App background color.
1622
+ * @example "#ffaabb"
1623
+ */
1624
+ get bgColor() {
1625
+ return this.get("bgColor");
1626
+ }
1627
+ /**
1628
+ * Closes the Mini App.
1629
+ */
1630
+ close() {
1631
+ this.postEvent("web_app_close");
1632
+ }
1633
+ /**
1634
+ * The Mini App header color.
1635
+ * @example "#ffaabb"
1636
+ * @example "bg_color"
1637
+ */
1638
+ get headerColor() {
1639
+ return this.get("headerColor");
1640
+ }
1641
+ /**
1642
+ * True if the Mini App is currently launched in bot inline mode.
1643
+ */
1644
+ get isBotInline() {
1645
+ return this.botInline;
1646
+ }
1647
+ /**
1648
+ * True if current Mini App background color is recognized as dark.
1649
+ */
1650
+ get isDark() {
1651
+ return At(this.bgColor);
1652
+ }
1653
+ /**
1654
+ * Informs the Telegram app that the Mini App is ready to be displayed.
1655
+ *
1656
+ * It is recommended to call this method as early as possible, as soon as all essential
1657
+ * interface elements loaded. Once this method called, the loading placeholder is hidden
1658
+ * and the Mini App shown.
1659
+ *
1660
+ * If the method not called, the placeholder will be hidden only when the page fully loaded.
1661
+ */
1662
+ ready() {
1663
+ this.postEvent("web_app_ready");
1664
+ }
1665
+ /**
1666
+ * Requests current user contact information. In contrary to requestPhoneAccess, this method
1667
+ * returns promise with contact information that rejects in case, user denied access, or request
1668
+ * failed.
1669
+ * @param options - additional options.
1670
+ */
1671
+ async requestContact({ timeout: t = 5e3 } = {}) {
1672
+ try {
1673
+ return await this.getRequestedContact();
1674
+ } catch {
1675
+ }
1676
+ if (await this.requestPhoneAccess() !== "sent")
1677
+ throw new Error("Access denied.");
1678
+ const s = Date.now() + t;
1679
+ let n = 50;
1680
+ return Tt(async () => {
1681
+ for (; Date.now() < s; ) {
1682
+ try {
1683
+ return await this.getRequestedContact();
1684
+ } catch {
1685
+ }
1686
+ await ps(n), n += 50;
1687
+ }
1688
+ throw Rt(t);
1689
+ }, t);
1690
+ }
1691
+ /**
1692
+ * Requests current user phone access. Method returns promise, which resolves
1693
+ * status of the request. In case, user accepted the request, Mini App bot will receive
1694
+ * the according notification.
1695
+ *
1696
+ * To obtain the retrieved information instead, utilize the `requestContact` method.
1697
+ * @param options - additional options.
1698
+ * @see requestContact
1699
+ */
1700
+ async requestPhoneAccess(t = {}) {
1701
+ return this.requestPhoneAccessPromise || (this.requestPhoneAccessPromise = m({
1702
+ ...t,
1703
+ method: "web_app_request_phone",
1704
+ event: "phone_requested",
1705
+ postEvent: this.postEvent
1706
+ }).then(({ status: s }) => s).finally(() => this.requestPhoneAccessPromise = void 0)), this.requestPhoneAccessPromise;
1707
+ }
1708
+ /**
1709
+ * Requests write message access to current user.
1710
+ * @param options - additional options.
1711
+ */
1712
+ async requestWriteAccess(t = {}) {
1713
+ return this.requestWriteAccessPromise || (this.requestWriteAccessPromise = m({
1714
+ ...t,
1715
+ method: "web_app_request_write_access",
1716
+ event: "write_access_requested",
1717
+ postEvent: this.postEvent
1718
+ }).then(({ status: s }) => s).finally(() => this.requestWriteAccessPromise = void 0)), this.requestWriteAccessPromise;
1719
+ }
1720
+ /**
1721
+ * A method used to send data to the bot. When this method called, a service message sent to
1722
+ * the bot containing the data of the length up to 4096 bytes, and the Mini App closed. See the
1723
+ * field `web_app_data` in the class [Message](https://core.telegram.org/bots/api#message).
1724
+ *
1725
+ * This method is only available for Mini Apps launched via a Keyboard button.
1726
+ * @param data - data to send to bot.
1727
+ * @throws {Error} data has incorrect size.
1728
+ */
1729
+ sendData(t) {
1730
+ const { size: s } = new Blob([t]);
1731
+ if (!s || s > 4096)
1732
+ throw new Error(`Passed data has incorrect size: ${s}`);
1733
+ this.postEvent("web_app_data_send", { data: t });
1734
+ }
1735
+ /**
1736
+ * Updates current Mini App header color.
1737
+ *
1738
+ * @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
1739
+ * @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
1740
+ * @param color - color key or RGB color.
1741
+ */
1742
+ setHeaderColor(t) {
1743
+ this.postEvent("web_app_set_header_color", st(t) ? { color: t } : { color_key: t }), this.set("headerColor", t);
1744
+ }
1745
+ /**
1746
+ * Updates current Mini App background color.
1747
+ *
1748
+ * @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
1749
+ * @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
1750
+ * @param color - RGB color.
1751
+ */
1752
+ setBgColor(t) {
1753
+ this.postEvent("web_app_set_background_color", { color: t }), this.set("bgColor", t);
1754
+ }
1755
+ /**
1756
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
1757
+ * Query may be empty, in which case only the bot's username will be inserted. The client prompts
1758
+ * the user to choose a specific chat, then opens that chat and inserts the bot's username and
1759
+ * the specified inline query in the input field.
1760
+ * @param text - text which should be inserted in the input after the current bot name. Max
1761
+ * length is 256 symbols.
1762
+ * @param chatTypes - List of chat types which could be chosen to send the message. Could be
1763
+ * empty list.
1764
+ */
1765
+ switchInlineQuery(t, s = []) {
1766
+ if (!this.supports("switchInlineQuery") && !this.isBotInline)
1767
+ throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
1768
+ this.postEvent("web_app_switch_inline_query", { query: t, chat_types: s });
1769
+ }
1770
+ }
1771
+ const ds = l("miniApp", ({
1772
+ themeParams: e,
1773
+ botInline: t = !1,
1774
+ state: s = {
1775
+ bgColor: e.bgColor || "#ffffff",
1776
+ headerColor: e.headerBgColor || "#000000"
1777
+ },
1778
+ ...n
1779
+ }) => new us({ ...n, ...s, botInline: t }));
1780
+ function ls(e) {
1781
+ const t = e.message.trim(), s = (e.title || "").trim(), n = e.buttons || [];
1782
+ let r;
1783
+ if (s.length > 64)
1784
+ throw new Error(`Title has incorrect size: ${s.length}`);
1785
+ if (!t.length || t.length > 256)
1786
+ throw new Error(`Message has incorrect size: ${t.length}`);
1787
+ if (n.length > 3)
1788
+ throw new Error(`Buttons have incorrect size: ${n.length}`);
1789
+ return n.length ? r = n.map((i) => {
1790
+ const { id: o = "" } = i;
1791
+ if (o.length > 64)
1792
+ throw new Error(`Button ID has incorrect size: ${o}`);
1793
+ if (!i.type || i.type === "default" || i.type === "destructive") {
1794
+ const a = i.text.trim();
1795
+ if (!a.length || a.length > 64) {
1796
+ const h = i.type || "default";
1797
+ throw new Error(`Button text with type "${h}" has incorrect size: ${i.text.length}`);
1798
+ }
1799
+ return { ...i, text: a, id: o };
1800
+ }
1801
+ return { ...i, id: o };
1802
+ }) : r = [{ type: "close", id: "" }], { title: s, message: t, buttons: r };
1803
+ }
1804
+ class _s extends N {
1805
+ constructor(t, s, n) {
1806
+ super({ isOpened: t }, s, { open: "web_app_open_popup" }), this.postEvent = n;
1807
+ }
1808
+ set isOpened(t) {
1809
+ this.set("isOpened", t);
1810
+ }
1811
+ /**
1812
+ * True if the Popup is opened.
1813
+ */
1814
+ get isOpened() {
1815
+ return this.get("isOpened");
1816
+ }
1817
+ /**
1818
+ * A method that shows a native popup described by the `params` argument.
1819
+ * Promise will be resolved when popup is closed. Resolved value will have
1820
+ * an identifier of pressed button.
1821
+ *
1822
+ * In case, user clicked outside the popup or clicked top right popup close
1823
+ * button, null will be returned.
1824
+ *
1825
+ * @param options - popup parameters.
1826
+ * @throws {Error} Popup is already opened.
1827
+ */
1828
+ async open(t) {
1829
+ if (this.isOpened)
1830
+ throw new Error("Popup is already opened.");
1831
+ this.isOpened = !0;
1832
+ try {
1833
+ const { button_id: s = null } = await m({
1834
+ event: "popup_closed",
1835
+ method: "web_app_open_popup",
1836
+ postEvent: this.postEvent,
1837
+ params: ls(t)
1838
+ });
1839
+ return s;
1840
+ } finally {
1841
+ this.isOpened = !1;
1842
+ }
1843
+ }
1844
+ }
1845
+ const gs = l(
1846
+ ({ postEvent: e, version: t }) => new _s(!1, t, e)
1847
+ );
1848
+ class fs extends N {
1849
+ constructor(t, s, n) {
1850
+ super({ isOpened: t }, s, {
1851
+ close: "web_app_close_scan_qr_popup",
1852
+ open: "web_app_open_scan_qr_popup"
1853
+ }), this.postEvent = n;
1854
+ }
1855
+ /**
1856
+ * Closes scanner.
1857
+ */
1858
+ close() {
1859
+ this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
1860
+ }
1861
+ set isOpened(t) {
1862
+ this.set("isOpened", t);
1863
+ }
1864
+ /**
1865
+ * Returns true in case, QR scanner is currently opened.
1866
+ */
1867
+ get isOpened() {
1868
+ return this.get("isOpened");
1869
+ }
1870
+ /**
1871
+ * Opens scanner with specified title shown to user. Method returns promise
1872
+ * with scanned QR content in case, it was scanned. It will contain null in
1873
+ * case, scanner was closed.
1874
+ * @param text - title to display.
1875
+ */
1876
+ async open(t) {
1877
+ if (this.isOpened)
1878
+ throw new Error("QR scanner is already opened.");
1879
+ this.isOpened = !0;
1880
+ try {
1881
+ return (await m({
1882
+ method: "web_app_open_scan_qr_popup",
1883
+ event: ["qr_text_received", "scan_qr_popup_closed"],
1884
+ postEvent: this.postEvent,
1885
+ params: { text: t }
1886
+ }) || {}).data || null;
1887
+ } finally {
1888
+ this.isOpened = !1;
1889
+ }
1890
+ }
1891
+ }
1892
+ const ms = l(
1893
+ ({ version: e, postEvent: t }) => new fs(!1, e, t)
1894
+ );
1895
+ class ws extends rt {
1896
+ constructor(t, s, n) {
1897
+ super({ isVisible: t }, s, {
1898
+ show: "web_app_setup_settings_button",
1899
+ hide: "web_app_setup_settings_button"
1900
+ }), c(this, "on", (r, i) => r === "click" ? b("settings_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? j("settings_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
1901
+ }
1902
+ set isVisible(t) {
1903
+ this.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
1904
+ }
1905
+ /**
1906
+ * True if the SettingsButton is visible.
1907
+ */
1908
+ get isVisible() {
1909
+ return this.get("isVisible");
1910
+ }
1911
+ /**
1912
+ * Hides the SettingsButton.
1913
+ */
1914
+ hide() {
1915
+ this.isVisible = !1;
1916
+ }
1917
+ /**
1918
+ * Shows the SettingsButton.
1919
+ */
1920
+ show() {
1921
+ this.isVisible = !0;
1922
+ }
1923
+ }
1924
+ const bs = l("settingsButton", ({
1925
+ version: e,
1926
+ postEvent: t,
1927
+ state: s = { isVisible: !1 }
1928
+ }) => new ws(s.isVisible, e, t));
1929
+ function Wt(e) {
1930
+ return qt().parse(e);
1931
+ }
1932
+ class vs extends ot {
1933
+ /**
1934
+ * @since v6.10
1935
+ */
1936
+ get accentTextColor() {
1937
+ return this.get("accentTextColor");
1938
+ }
1939
+ get bgColor() {
1940
+ return this.get("bgColor");
1941
+ }
1942
+ get buttonColor() {
1943
+ return this.get("buttonColor");
1944
+ }
1945
+ get buttonTextColor() {
1946
+ return this.get("buttonTextColor");
1947
+ }
1948
+ get destructiveTextColor() {
1949
+ return this.get("destructiveTextColor");
1950
+ }
1951
+ /**
1952
+ * Returns the copy of the internal state of the current component instance.
1953
+ */
1954
+ getState() {
1955
+ return this.clone();
1956
+ }
1957
+ /**
1958
+ * @since v6.10
1959
+ */
1960
+ get headerBgColor() {
1961
+ return this.get("headerBgColor");
1962
+ }
1963
+ get hintColor() {
1964
+ return this.get("hintColor");
1965
+ }
1966
+ /**
1967
+ * @returns True in case, current color scheme is recognized as dark. This
1968
+ * value is calculated according to theme bg color.
1969
+ */
1970
+ get isDark() {
1971
+ return !this.bgColor || At(this.bgColor);
1972
+ }
1973
+ get linkColor() {
1974
+ return this.get("linkColor");
1975
+ }
1976
+ get secondaryBgColor() {
1977
+ return this.get("secondaryBgColor");
1978
+ }
1979
+ /**
1980
+ * @since v6.10
1981
+ */
1982
+ get sectionBgColor() {
1983
+ return this.get("sectionBgColor");
1984
+ }
1985
+ /**
1986
+ * @since v6.10
1987
+ */
1988
+ get sectionHeaderTextColor() {
1989
+ return this.get("sectionHeaderTextColor");
1990
+ }
1991
+ /**
1992
+ * Starts listening to the external theme changes and applies them.
1993
+ * @returns Function to stop listening.
1994
+ */
1995
+ listen() {
1996
+ return b("theme_changed", (t) => {
1997
+ this.set(Wt(t.theme_params));
1998
+ });
1999
+ }
2000
+ /**
2001
+ * @since v6.10
2002
+ */
2003
+ get subtitleTextColor() {
2004
+ return this.get("subtitleTextColor");
2005
+ }
2006
+ get textColor() {
2007
+ return this.get("textColor");
2008
+ }
2009
+ }
2010
+ const ys = l("themeParams", ({ themeParams: e, state: t = e }) => {
2011
+ const s = new vs(t);
2012
+ return S() || s.listen(), s;
2013
+ });
2014
+ function tn(e = {}) {
2015
+ return m({
2016
+ ...e,
2017
+ method: "web_app_request_theme",
2018
+ event: "theme_changed"
2019
+ }).then(Wt);
2020
+ }
2021
+ class Es extends at {
2022
+ constructor(t, s, n) {
2023
+ super(t, { readTextFromClipboard: "web_app_read_text_from_clipboard" }), c(this, "supportsParam"), this.version = t, this.createRequestId = s, this.postEvent = n, this.supportsParam = Ht(t, {
2024
+ "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
2025
+ });
2026
+ }
2027
+ /**
2028
+ * Opens a link in an external browser. The Mini App will not be closed.
2029
+ *
2030
+ * Note that this method can be called only in response to the user
2031
+ * interaction with the Mini App interface (e.g. click inside the Mini App
2032
+ * or on the main button).
2033
+ * @param url - URL to be opened.
2034
+ * @param tryInstantView
2035
+ */
2036
+ openLink(t, s) {
2037
+ const n = new URL(t, window.location.href).toString();
2038
+ if (!x("web_app_open_link", this.version)) {
2039
+ window.open(n, "_blank");
2040
+ return;
2041
+ }
2042
+ this.postEvent("web_app_open_link", {
2043
+ url: n,
2044
+ ...typeof s == "boolean" ? { try_instant_view: s } : {}
2045
+ });
2046
+ }
2047
+ /**
2048
+ * Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
2049
+ * link in full format, with hostname "t.me".
2050
+ * @param url - URL to be opened.
2051
+ * @throws {Error} URL has not allowed hostname.
2052
+ */
2053
+ openTelegramLink(t) {
2054
+ const { hostname: s, pathname: n, search: r } = new URL(t, window.location.href);
2055
+ if (s !== "t.me")
2056
+ throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);
2057
+ if (!x("web_app_open_tg_link", this.version)) {
2058
+ window.location.href = t;
2059
+ return;
2060
+ }
2061
+ this.postEvent("web_app_open_tg_link", { path_full: n + r });
2062
+ }
2063
+ /**
2064
+ * Reads text from clipboard and returns string or null. null is returned
2065
+ * in cases:
2066
+ * - Value in clipboard is not text
2067
+ * - Access to clipboard is not allowed
2068
+ */
2069
+ async readTextFromClipboard() {
2070
+ const t = this.createRequestId(), {
2071
+ data: s = null
2072
+ } = await m({
2073
+ method: "web_app_read_text_from_clipboard",
2074
+ event: "clipboard_text_received",
2075
+ postEvent: this.postEvent,
2076
+ params: { req_id: t },
2077
+ capture: Ct(t)
2078
+ });
2079
+ return s;
2080
+ }
2081
+ }
2082
+ const Ps = l(
2083
+ ({ version: e, postEvent: t, createRequestId: s }) => new Es(e, s, t)
2084
+ );
2085
+ async function jt(e = {}) {
2086
+ const {
2087
+ is_expanded: t,
2088
+ is_state_stable: s,
2089
+ ...n
2090
+ } = await m({
2091
+ ...e,
2092
+ method: "web_app_request_viewport",
2093
+ event: "viewport_changed"
2094
+ });
2095
+ return { ...n, isExpanded: t, isStateStable: s };
2096
+ }
2097
+ function T(e) {
2098
+ return e < 0 ? 0 : e;
2099
+ }
2100
+ class Gt extends ot {
2101
+ constructor({ postEvent: t, stableHeight: s, height: n, width: r, isExpanded: i }) {
2102
+ super({
2103
+ height: T(n),
2104
+ isExpanded: i,
2105
+ stableHeight: T(s),
2106
+ width: T(r)
2107
+ }), c(this, "postEvent"), this.postEvent = t;
2108
+ }
2109
+ /**
2110
+ * Requests viewport information from the Telegram application and updates current Viewport
2111
+ * instance.
2112
+ * @param options - options to request fresh data.
2113
+ */
2114
+ async sync(t) {
2115
+ const { isStateStable: s, ...n } = await jt(t);
2116
+ this.set({
2117
+ ...n,
2118
+ stableHeight: s ? n.height : this.get("stableHeight")
2119
+ });
2120
+ }
2121
+ /**
2122
+ * The current height of the **visible area** of the Mini App.
2123
+ *
2124
+ * The application can display just the top part of the Mini App, with its lower part remaining
2125
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
2126
+ * maximum height, while the bot can do the same by calling `expand` method. As the position of
2127
+ * the Mini App changes, the current height value of the visible area will be updated in real
2128
+ * time.
2129
+ *
2130
+ * Please note that the refresh rate of this value is not sufficient to smoothly follow the
2131
+ * lower border of the window. It should not be used to pin interface elements to the bottom
2132
+ * of the visible area. It's more appropriate to use the value of the `stableHeight`
2133
+ * field for this purpose.
2134
+ *
2135
+ * @see stableHeight
2136
+ */
2137
+ get height() {
2138
+ return this.get("height");
2139
+ }
2140
+ /**
2141
+ * The height of the visible area of the Mini App in its last stable state.
2142
+ *
2143
+ * The application can display just the top part of the Mini App, with its lower part remaining
2144
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
2145
+ * maximum height, while the application can do the same by calling `expand` method.
2146
+ *
2147
+ * Unlike the value of `height`, the value of `stableHeight` does not change as the position
2148
+ * of the Mini App changes with user gestures or during animations. The value of `stableHeight`
2149
+ * will be updated after all gestures and animations are completed and
2150
+ * the Mini App reaches its final size.
2151
+ *
2152
+ * @see height
2153
+ */
2154
+ get stableHeight() {
2155
+ return this.get("stableHeight");
2156
+ }
2157
+ /**
2158
+ * Starts listening to viewport changes and applies them.
2159
+ * @returns Function to stop listening.
2160
+ */
2161
+ listen() {
2162
+ return b("viewport_changed", (t) => {
2163
+ const {
2164
+ height: s,
2165
+ width: n,
2166
+ is_expanded: r,
2167
+ is_state_stable: i
2168
+ } = t, o = T(s);
2169
+ this.set({
2170
+ height: o,
2171
+ isExpanded: r,
2172
+ width: T(n),
2173
+ ...i ? { stableHeight: o } : {}
2174
+ });
2175
+ });
2176
+ }
2177
+ /**
2178
+ * True if the Mini App is expanded to the maximum available height. Otherwise, if
2179
+ * the Mini App occupies part of the screen and can be expanded to the full height using
2180
+ * `expand` method.
2181
+ * @see expand
2182
+ */
2183
+ get isExpanded() {
2184
+ return this.get("isExpanded");
2185
+ }
2186
+ /**
2187
+ * Current visible area width.
2188
+ */
2189
+ get width() {
2190
+ return this.get("width");
2191
+ }
2192
+ /**
2193
+ * A method that expands the Mini App to the maximum available height. To find out if the Mini
2194
+ * App is expanded to the maximum height, refer to the value of the `isExpanded`.
2195
+ * @see isExpanded
2196
+ */
2197
+ expand() {
2198
+ this.postEvent("web_app_expand"), this.set("isExpanded", !0);
2199
+ }
2200
+ /**
2201
+ * True if the current viewport height is stable and is not going to change in the next moment.
2202
+ */
2203
+ get isStable() {
2204
+ return this.stableHeight === this.height;
2205
+ }
2206
+ }
2207
+ async function xs(e, t = {}) {
2208
+ const {
2209
+ height: s,
2210
+ width: n,
2211
+ isExpanded: r,
2212
+ isStateStable: i
2213
+ } = await jt({ ...t, postEvent: e });
2214
+ return new Gt({
2215
+ postEvent: e,
2216
+ height: s,
2217
+ width: n,
2218
+ isExpanded: r,
2219
+ stableHeight: i ? s : 0
2220
+ });
2221
+ }
2222
+ function Ss({
2223
+ state: e,
2224
+ platform: t,
2225
+ postEvent: s
2226
+ }) {
2227
+ let n = !1, r = 0, i = 0, o = 0;
2228
+ return e ? (n = e.isExpanded, r = e.height, i = e.width, o = e.stableHeight) : ["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(t) && (n = !0, r = window.innerHeight, i = window.innerWidth, o = window.innerHeight), new Gt({
2229
+ postEvent: s,
2230
+ height: r,
2231
+ width: i,
2232
+ stableHeight: o,
2233
+ isExpanded: n
2234
+ });
2235
+ }
2236
+ const Cs = l(
2237
+ "viewport",
2238
+ async (e) => {
2239
+ if (S() && !e.state)
2240
+ throw d(
2241
+ tt,
2242
+ "Viewport cannot be instantiated on the server side without passing the ssr.state object."
2243
+ );
2244
+ let t = Ss(e);
2245
+ return S() || (t.width === 0 && await xs(e.postEvent, { timeout: 1e3 }).then((s) => t = s).catch((s) => $.error("Unable to sync viewport state", s)), t.listen()), t;
2246
+ }
2247
+ );
2248
+ function y(e, t) {
2249
+ document.documentElement.style.setProperty(e, t);
2250
+ }
2251
+ function en(e, t, s) {
2252
+ s || (s = (a) => `--tg-${a}-color`);
2253
+ const n = s("header"), r = s("bg"), i = () => {
2254
+ const { headerColor: a } = e;
2255
+ if (st(a))
2256
+ y(n, a);
2257
+ else {
2258
+ const { bgColor: h, secondaryBgColor: u } = t;
2259
+ a === "bg_color" && h ? y(n, h) : a === "secondary_bg_color" && u && y(n, u);
2260
+ }
2261
+ y(r, e.bgColor);
2262
+ }, o = [
2263
+ t.on("change", i),
2264
+ e.on("change", i)
2265
+ ];
2266
+ return i(), () => o.forEach((a) => a());
2267
+ }
2268
+ function sn(e, t) {
2269
+ t || (t = (n) => `--tg-theme-${n.replace(/[A-Z]/g, (r) => `-${r.toLowerCase()}`)}`);
2270
+ const s = () => {
2271
+ Object.entries(e.getState()).forEach(([n, r]) => {
2272
+ r && y(t(n), r);
2273
+ });
2274
+ };
2275
+ return s(), e.on("change", s);
2276
+ }
2277
+ function nn(e, t) {
2278
+ t || (t = (u) => `--tg-viewport-${u}`);
2279
+ const [
2280
+ s,
2281
+ n,
2282
+ r
2283
+ ] = ["height", "width", "stable-height"].map((u) => t(u)), i = () => y(s, `${e.height}px`), o = () => y(n, `${e.width}px`), a = () => y(r, `${e.stableHeight}px`), h = [
2284
+ e.on("change:height", i),
2285
+ e.on("change:width", o),
2286
+ e.on("change:stableHeight", a)
2287
+ ];
2288
+ return i(), o(), a(), () => h.forEach((u) => u());
2289
+ }
2290
+ function Rs(e = !0) {
2291
+ const t = [
2292
+ b("reload_iframe", () => {
2293
+ k("iframe_will_reload"), window.location.reload();
2294
+ })
2295
+ ], s = () => t.forEach((n) => n());
2296
+ if (e) {
2297
+ const n = document.createElement("style");
2298
+ n.id = "telegram-custom-styles", document.head.appendChild(n), t.push(
2299
+ b("set_custom_style", (r) => {
2300
+ n.innerHTML = r;
2301
+ }),
2302
+ () => document.head.removeChild(n)
2303
+ );
2304
+ }
2305
+ return k("iframe_ready", { reload_supported: !0 }), s;
2306
+ }
2307
+ async function rn() {
2308
+ try {
2309
+ return await m({ method: "web_app_request_theme", event: "theme_changed", timeout: 100 }), !0;
2310
+ } catch {
2311
+ return !1;
2312
+ }
2313
+ }
2314
+ function Ts(e) {
2315
+ return e instanceof U;
2316
+ }
2317
+ function on(e, t) {
2318
+ return Ts(e) && e.type === t;
2319
+ }
2320
+ function z(e, t) {
2321
+ let s, n, r;
2322
+ return typeof e == "string" ? s = e : (s = e.pathname === void 0 ? t : e.pathname, n = e.params, r = e.id), Object.freeze({
2323
+ id: r || (Math.random() * 2 ** 14 | 0).toString(16),
2324
+ pathname: s,
2325
+ params: n
2326
+ });
2327
+ }
2328
+ class As {
2329
+ constructor(t, s, n = k) {
2330
+ if (c(this, "history"), c(this, "ee", new L()), c(this, "attached", !1), c(this, "back", () => this.go(-1)), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this._index = s, this.postEvent = n, t.length === 0)
2331
+ throw d(de, "History should not be empty.");
2332
+ if (s < 0 || s >= t.length)
2333
+ throw d(
2334
+ le,
2335
+ "Index should not be zero and higher or equal than history size."
2336
+ );
2337
+ this.history = t.map((r) => z(r, ""));
2338
+ }
2339
+ /**
2340
+ * Allows this navigator to control the `BackButton` visibility state. It also tracks the
2341
+ * `BackButton` clicks and calls the `back` method.
2342
+ */
2343
+ attach() {
2344
+ this.attached || (this.attached = !0, this.sync(), b("back_button_pressed", this.back));
2345
+ }
2346
+ /**
2347
+ * Currently active history item.
2348
+ */
2349
+ get current() {
2350
+ return this.history[this.index];
2351
+ }
2352
+ /**
2353
+ * Prevents current navigator from controlling the BackButton visibility state.
2354
+ */
2355
+ detach() {
2356
+ this.attached = !1, j("back_button_pressed", this.back);
2357
+ }
2358
+ /**
2359
+ * Goes to the next history item.
2360
+ */
2361
+ forward() {
2362
+ this.go(1);
2363
+ }
2364
+ /**
2365
+ * Changes currently active history item index by the specified delta. This method doesn't
2366
+ * change index in case, the updated index points to the non-existing history item. This behavior
2367
+ * is preserved until the `fit` argument is specified.
2368
+ * @param delta - index delta.
2369
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
2370
+ */
2371
+ go(t, s) {
2372
+ const n = this.index + t, r = Math.min(
2373
+ Math.max(0, n),
2374
+ this.history.length - 1
2375
+ );
2376
+ (n === r || s) && this.replaceAndMove(r, this.history[r]);
2377
+ }
2378
+ /**
2379
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
2380
+ *
2381
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
2382
+ * bound.
2383
+ * @param index - target index.
2384
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
2385
+ */
2386
+ goTo(t, s) {
2387
+ this.go(t - this.index, s);
2388
+ }
2389
+ /**
2390
+ * True if navigator has items before the current item.
2391
+ */
2392
+ get hasPrev() {
2393
+ return this.index > 0;
2394
+ }
2395
+ /**
2396
+ * True if navigator has items after the current item.
2397
+ */
2398
+ get hasNext() {
2399
+ return this.index !== this.history.length - 1;
2400
+ }
2401
+ /**
2402
+ * Currently active history item index.
2403
+ */
2404
+ get index() {
2405
+ return this._index;
2406
+ }
2407
+ /**
2408
+ * Adds a new history item removing all after the current one.
2409
+ * @param item - item to add.
2410
+ */
2411
+ push(t) {
2412
+ this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, z(t, this.current.pathname));
2413
+ }
2414
+ /**
2415
+ * Replaces the current history item.
2416
+ * @param item - item to replace the current item with.
2417
+ */
2418
+ replace(t) {
2419
+ this.replaceAndMove(this.index, z(t, this.current.pathname));
2420
+ }
2421
+ /**
2422
+ * Sets history item by the specified index.
2423
+ * @param index - history item index to replace.
2424
+ * @param historyItem - history item to set.
2425
+ */
2426
+ replaceAndMove(t, s) {
2427
+ const n = t - this.index;
2428
+ if (!n && this.current === s)
2429
+ return;
2430
+ const r = this.current;
2431
+ if (this.index !== t) {
2432
+ const i = this._index;
2433
+ this._index = t, this.attached && i > 0 != t > 0 && this.sync();
2434
+ }
2435
+ this.history[t] = s, this.ee.emit("change", {
2436
+ navigator: this,
2437
+ from: r,
2438
+ to: this.current,
2439
+ delta: n
2440
+ });
2441
+ }
2442
+ /**
2443
+ * Actualizes the `BackButton` visibility state.
2444
+ */
2445
+ sync() {
2446
+ this.postEvent("web_app_setup_back_button", { is_visible: !!this.index });
2447
+ }
2448
+ }
2449
+ function K({
2450
+ params: e,
2451
+ ...t
2452
+ }) {
2453
+ return { ...e || { hash: "", search: "" }, ...t };
2454
+ }
2455
+ function O(e, t) {
2456
+ return e.startsWith(t) ? e : `${t}${e}`;
2457
+ }
2458
+ function M(e) {
2459
+ return new URL(
2460
+ typeof e == "string" ? e : `${e.pathname || ""}${O(e.search || "", "?")}${O(e.hash || "", "#")}`,
2461
+ "http://a"
2462
+ );
2463
+ }
2464
+ function B(e) {
2465
+ const t = typeof e == "string" ? e.startsWith("/") : !!(e.pathname && e.pathname.startsWith("/")), s = M(e);
2466
+ return `${t ? s.pathname : s.pathname.slice(1)}${s.search}${s.hash}`;
2467
+ }
2468
+ function J(e, t, s) {
2469
+ let n, r;
2470
+ typeof e == "string" ? n = e : (n = B(e), s = e.state, r = e.id);
2471
+ const { pathname: i, search: o, hash: a } = new URL(n, `http://a${O(t, "/")}`);
2472
+ return { id: r, pathname: i, params: { hash: a, search: o, state: s } };
2473
+ }
2474
+ async function I(e) {
2475
+ return e === 0 ? !0 : Promise.race([
2476
+ new Promise((t) => {
2477
+ const s = Z("popstate", () => {
2478
+ s(), t(!0);
2479
+ });
2480
+ window.history.go(e);
2481
+ }),
2482
+ // Usually, it takes about 1ms to emit this event, but we use some buffer.
2483
+ new Promise((t) => {
2484
+ setTimeout(t, 50, !1);
2485
+ })
2486
+ ]);
2487
+ }
2488
+ async function Is() {
2489
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await I(1 - window.history.length)))
2490
+ return;
2491
+ let e = await I(-1);
2492
+ for (; e; )
2493
+ e = await I(-1);
2494
+ }
2495
+ function zt(e) {
2496
+ return M(e).pathname;
2497
+ }
2498
+ const ft = 0, Q = 1, F = 2;
2499
+ class Kt {
2500
+ constructor(t, s, { postEvent: n, hashMode: r, base: i } = {}) {
2501
+ c(this, "navigator"), c(this, "ee", new L()), c(this, "hashMode"), c(this, "base"), c(this, "attached", !1), c(this, "onPopState", ({ state: o }) => {
2502
+ if (o === null)
2503
+ return this.push(this.parsePath(window.location.href));
2504
+ o === ft ? window.history.forward() : o === Q && this.back(), o === F && this.forward();
2505
+ }), c(this, "onNavigatorChange", async ({
2506
+ to: o,
2507
+ from: a,
2508
+ delta: h
2509
+ }) => {
2510
+ this.attached && await this.syncHistory(), this.ee.emit("change", {
2511
+ delta: h,
2512
+ from: K(a),
2513
+ to: K(o),
2514
+ navigator: this
2515
+ });
2516
+ }), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this.navigator = new As(
2517
+ t.map((o) => J(o, "/")),
2518
+ s,
2519
+ n
2520
+ ), this.navigator.on("change", this.onNavigatorChange), this.hashMode = r, this.base = zt(i || "");
2521
+ }
2522
+ /**
2523
+ * Attaches current navigator to the browser history allowing navigator to manipulate it.
2524
+ */
2525
+ async attach() {
2526
+ this.attached || (this.attached = !0, this.navigator.attach(), window.addEventListener("popstate", this.onPopState), await this.syncHistory());
2527
+ }
2528
+ /**
2529
+ * Goes back in history by 1.
2530
+ */
2531
+ back() {
2532
+ this.navigator.back();
2533
+ }
2534
+ /**
2535
+ * Detaches current navigator from the browser history.
2536
+ */
2537
+ detach() {
2538
+ this.attached = !1, this.navigator.detach(), window.removeEventListener("popstate", this.onPopState);
2539
+ }
2540
+ /**
2541
+ * Goes forward in history.
2542
+ */
2543
+ forward() {
2544
+ return this.navigator.forward();
2545
+ }
2546
+ /**
2547
+ * Current history cursor.
2548
+ */
2549
+ get index() {
2550
+ return this.navigator.index;
2551
+ }
2552
+ /**
2553
+ * Current history item identifier.
2554
+ */
2555
+ get id() {
2556
+ return this.navigator.current.id;
2557
+ }
2558
+ /**
2559
+ * Changes currently active history item index by the specified delta. This method doesn't
2560
+ * change index in case, the updated index points to the non-existing history item. This behavior
2561
+ * is preserved until the `fit` argument is specified.
2562
+ * @param delta - index delta.
2563
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
2564
+ */
2565
+ go(t, s) {
2566
+ return this.navigator.go(t, s);
2567
+ }
2568
+ /**
2569
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
2570
+ *
2571
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
2572
+ * bound.
2573
+ * @param index - target index.
2574
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
2575
+ */
2576
+ goTo(t, s) {
2577
+ this.navigator.goTo(t, s);
2578
+ }
2579
+ /**
2580
+ * Current history item hash.
2581
+ * @see URL.hash
2582
+ * @example
2583
+ * "", "#my-hash"
2584
+ */
2585
+ get hash() {
2586
+ return (this.navigator.current.params || {}).hash || "";
2587
+ }
2588
+ /**
2589
+ * True if navigator has items before the current item.
2590
+ */
2591
+ get hasPrev() {
2592
+ return this.navigator.hasPrev;
2593
+ }
2594
+ /**
2595
+ * True if navigator has items after the current item.
2596
+ */
2597
+ get hasNext() {
2598
+ return this.navigator.hasNext;
2599
+ }
2600
+ /**
2601
+ * Navigation history.
2602
+ */
2603
+ get history() {
2604
+ return this.navigator.history.map(K);
2605
+ }
2606
+ /**
2607
+ * Path, including pathname, search and hash.
2608
+ * @example Pathname only.
2609
+ * "/pathname"
2610
+ * @example Pathname + search.
2611
+ * "/pathname?search"
2612
+ * @example Pathname + hash.
2613
+ * "/pathname#hash"
2614
+ * @example Pathname + search + hash.
2615
+ * "/pathname?search#hash"
2616
+ */
2617
+ get path() {
2618
+ return B(this);
2619
+ }
2620
+ /**
2621
+ * Current pathname. Always starts with the slash.
2622
+ * @see URL.pathname
2623
+ * @example
2624
+ * "/", "/abc"
2625
+ */
2626
+ get pathname() {
2627
+ return this.navigator.current.pathname;
2628
+ }
2629
+ /**
2630
+ * Depending on the current navigation type, parses incoming path and returns it presented as
2631
+ * an object. In other words, this method parses the passed path and returns object, describing
2632
+ * how the navigator "sees" it.
2633
+ *
2634
+ * @example Hash mode is omitted.
2635
+ * parsePath('/abc?a=1#hash');
2636
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
2637
+ * parsePath('http://example.com/abc?a=1#hash');
2638
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
2639
+ *
2640
+ * @example Hash mode is enabled.
2641
+ * parsePath('/abc?a=1#tma?is=cool#yeah');
2642
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2643
+ * parsePath('http://example.com/abc?a=1#tma?is=cool#yeah');
2644
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2645
+ */
2646
+ parsePath(t) {
2647
+ let s = M(t);
2648
+ return this.hashMode && (s = M(s.hash.slice(1))), {
2649
+ pathname: s.pathname,
2650
+ search: s.search,
2651
+ hash: s.hash
2652
+ };
2653
+ }
2654
+ push(t, s) {
2655
+ const n = J(t, this.path), { state: r = s } = n.params;
2656
+ this.navigator.push({ ...n, params: { ...n.params, state: r } });
2657
+ }
2658
+ replace(t, s) {
2659
+ const n = J(t, this.path), { state: r = s } = n.params;
2660
+ this.navigator.replace({ ...n, params: { ...n.params, state: r } });
2661
+ }
2662
+ /**
2663
+ * Combines the navigator `base` property with the passed path data applying the navigator
2664
+ * navigation mode.
2665
+ * @param value - path presented as string or URLLike.
2666
+ */
2667
+ renderPath(t) {
2668
+ const s = (this.base.length === 1 ? "" : this.base) + O(B(t), "/");
2669
+ return this.hashMode ? O(s.slice(1), this.hashMode === "default" ? "#" : "#/") : s;
2670
+ }
2671
+ /**
2672
+ * Synchronizes current navigator state with browser history.
2673
+ */
2674
+ async syncHistory() {
2675
+ window.removeEventListener("popstate", this.onPopState);
2676
+ const { state: t } = this, s = this.renderPath(this);
2677
+ await Is(), this.hasPrev && this.hasNext ? (window.history.replaceState(Q, ""), window.history.pushState(t, "", s), window.history.pushState(F, ""), await I(-1)) : this.hasPrev ? (window.history.replaceState(Q, ""), window.history.pushState(t, "", s)) : this.hasNext ? (window.history.replaceState(t, s), window.history.pushState(F, ""), await I(-1)) : (window.history.replaceState(ft, ""), window.history.pushState(t, "", s)), window.addEventListener("popstate", this.onPopState);
2678
+ }
2679
+ /**
2680
+ * Current query parameters.
2681
+ * @see URL.search
2682
+ * @example
2683
+ * "", "?", "?a=1"
2684
+ */
2685
+ get search() {
2686
+ return (this.navigator.current.params || {}).search || "";
2687
+ }
2688
+ /**
2689
+ * Current history item state.
2690
+ */
2691
+ get state() {
2692
+ return (this.navigator.current.params || {}).state;
2693
+ }
2694
+ }
2695
+ function ks(e) {
2696
+ e || (e = {});
2697
+ const { href: t, hash: s } = window.location;
2698
+ let n = B(
2699
+ e.hashMode ? s.includes("?") ? s.slice(1) : `?${s.slice(1)}` : t
2700
+ );
2701
+ const r = e.base ? zt(e.base) : void 0;
2702
+ if (r) {
2703
+ if (!n.startsWith(r))
2704
+ throw d(
2705
+ ge,
2706
+ `Path "${n}" expected to be starting with "${r}"`
2707
+ );
2708
+ n = n.slice(r.length);
2709
+ }
2710
+ return new Kt([n], 0, e);
2711
+ }
2712
+ function an(e) {
2713
+ const t = e.match(/#(.+)/);
2714
+ return t ? t[1] : null;
2715
+ }
2716
+ function Os(e, t) {
2717
+ if (Lt()) {
2718
+ const s = sessionStorage.getItem(e);
2719
+ if (s)
2720
+ try {
2721
+ const { index: n, history: r } = JSON.parse(s);
2722
+ return new Kt(r, n, t);
2723
+ } catch (n) {
2724
+ console.error("Unable to restore hash navigator state.", n);
2725
+ }
2726
+ }
2727
+ return ks(t);
2728
+ }
2729
+ function cn(e, t) {
2730
+ const s = Os(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
2731
+ index: s.index,
2732
+ history: s.history
2733
+ }));
2734
+ return s.on("change", n), n(), s;
2735
+ }
2736
+ function _(e) {
2737
+ return (t, s, ...n) => (r) => mt(s, ht(() => ht({
2738
+ [t]: e(...n)
2739
+ }, r)));
2740
+ }
2741
+ const Jt = Qt();
2742
+ function qs() {
2743
+ const e = Ft(Jt);
2744
+ if (!e)
2745
+ throw new Error("useSDK was used outside of SDKProvider.");
2746
+ return e;
2747
+ }
2748
+ function g(e) {
2749
+ return (...t) => qs()(e, ...t);
2750
+ }
2751
+ const Ns = g(Ge), hn = _(Ns), Ds = g(Ke), pn = _(Ds), Vs = g(Qe), un = _(Vs), Ms = g(ts), dn = _(Ms), Bs = g(ss), ln = _(Bs), $s = g(rs), _n = _($s), Ls = g(os), gn = _(Ls), Us = g(cs), fn = _(Us), Hs = g(ds), mn = _(Hs), Ws = g(gs), wn = _(Ws), js = g(ms), bn = _(js), Gs = g(bs), vn = _(Gs), zs = g(ys), yn = _(zs), Ks = g(Ps), En = _(Ks), Js = g(Cs), Pn = _(Js), xn = (e) => {
2752
+ const t = /* @__PURE__ */ new Map(), s = (n, ...r) => {
2753
+ if (t.has(n))
2754
+ return t.get(n);
2755
+ const [i] = Zt(() => {
2756
+ try {
2757
+ return n(...r);
2758
+ } catch (h) {
2759
+ return [h];
2760
+ }
2761
+ }), o = ut(() => {
2762
+ if (i.error)
2763
+ return [i.error];
2764
+ if (i.state !== "ready")
2765
+ return;
2766
+ const h = i();
2767
+ if (Array.isArray(h) || !h || !("on" in h))
2768
+ return h;
2769
+ const u = Xt((V) => (V(h), h.on("change", () => V(h)))), D = Object.getPrototypeOf(h), G = {};
2770
+ return new Proxy(h, {
2771
+ get(V, P) {
2772
+ if (!(P in G)) {
2773
+ const ct = Reflect.getOwnPropertyDescriptor(D, P);
2774
+ G[P] = ct && "get" in ct ? ut(() => u()[P]) : () => Reflect.get(V, P);
2775
+ }
2776
+ return G[P]();
2777
+ }
2778
+ });
2779
+ });
2780
+ function a() {
2781
+ const h = o();
2782
+ if (Array.isArray(h))
2783
+ throw h[0];
2784
+ return h;
2785
+ }
2786
+ return Object.defineProperty(a, "error", {
2787
+ get() {
2788
+ const h = o();
2789
+ return Array.isArray(h) ? h[0] : void 0;
2790
+ }
2791
+ }), t.set(n, a), a;
2792
+ };
2793
+ return pt(() => {
2794
+ re(e.debug || !1);
2795
+ }), pt(() => {
2796
+ xt() && Yt(Rs(e.acceptCustomStyles));
2797
+ }), mt(Jt.Provider, {
2798
+ value: s,
2799
+ get children() {
2800
+ return e.children;
2801
+ }
2802
+ });
2803
+ };
2804
+ export {
2805
+ Oe as BackButton,
2806
+ As as BasicNavigator,
2807
+ _t as BiometryManager,
2808
+ Kt as BrowserNavigator,
2809
+ Je as ClosingBehavior,
2810
+ Xe as CloudStorage,
2811
+ ge as ERR_INVALID_PATH_BASE,
2812
+ he as ERR_INVOKE_CUSTOM_METHOD_RESPONSE,
2813
+ ae as ERR_METHOD_PARAMETER_UNSUPPORTED,
2814
+ oe as ERR_METHOD_UNSUPPORTED,
2815
+ de as ERR_NAVIGATION_HISTORY_EMPTY,
2816
+ le as ERR_NAVIGATION_INDEX_INVALID,
2817
+ Fs as ERR_NAVIGATION_ITEM_INVALID,
2818
+ vt as ERR_PARSE,
2819
+ tt as ERR_SSR_INIT,
2820
+ _e as ERR_SSR_POST_EVENT,
2821
+ pe as ERR_TIMED_OUT,
2822
+ ue as ERR_UNEXPECTED_TYPE,
2823
+ ce as ERR_UNKNOWN_ENV,
2824
+ L as EventEmitter,
2825
+ es as HapticFeedback,
2826
+ ns as InitData,
2827
+ is as Invoice,
2828
+ as as MainButton,
2829
+ us as MiniApp,
2830
+ _s as Popup,
2831
+ fs as QRScanner,
2832
+ U as SDKError,
2833
+ xn as SDKProvider,
2834
+ ws as SettingsButton,
2835
+ vs as ThemeParams,
2836
+ Es as Utils,
2837
+ Gt as Viewport,
2838
+ Ze as array,
2839
+ en as bindMiniAppCSSVars,
2840
+ sn as bindThemeParamsCSSVars,
2841
+ nn as bindViewportCSSVars,
2842
+ v as boolean,
2843
+ Ct as captureSameReq,
2844
+ X as classNames,
2845
+ Ce as compareVersions,
2846
+ ks as createBrowserNavigatorFromLocation,
2847
+ Ie as createPostEvent,
2848
+ M as createSafeURL,
2849
+ kt as date,
2850
+ an as getHash,
2851
+ zt as getPathname,
2852
+ Ge as initBackButton,
2853
+ Ke as initBiometryManager,
2854
+ Qe as initClosingBehavior,
2855
+ ts as initCloudStorage,
2856
+ ss as initHapticFeedback,
2857
+ rs as initInitData,
2858
+ os as initInvoice,
2859
+ cs as initMainButton,
2860
+ ds as initMiniApp,
2861
+ cn as initNavigator,
2862
+ gs as initPopup,
2863
+ ms as initQRScanner,
2864
+ bs as initSettingsButton,
2865
+ ys as initThemeParams,
2866
+ Ps as initUtils,
2867
+ Cs as initViewport,
2868
+ Rs as initWeb,
2869
+ A as invokeCustomMethod,
2870
+ At as isColorDark,
2871
+ xt as isIframe,
2872
+ Lt as isPageReload,
2873
+ st as isRGB,
2874
+ fe as isRGBShort,
2875
+ Ts as isSDKError,
2876
+ on as isSDKErrorOfType,
2877
+ rn as isTMA,
2878
+ f as json,
2879
+ Zs as mergeClassNames,
2880
+ E as number,
2881
+ j as off,
2882
+ b as on,
2883
+ Xs as parseInitData,
2884
+ Nt as parseLaunchParams,
2885
+ Wt as parseThemeParams,
2886
+ k as postEvent,
2887
+ m as request,
2888
+ ze as requestBiometryInfo,
2889
+ tn as requestThemeParams,
2890
+ jt as requestViewport,
2891
+ He as retrieveLaunchParams,
2892
+ Pt as rgb,
2893
+ it as searchParams,
2894
+ Le as serializeLaunchParams,
2895
+ $e as serializeThemeParams,
2896
+ y as setCSSVar,
2897
+ re as setDebug,
2898
+ Ys as setTargetOrigin,
2899
+ p as string,
2900
+ se as subscribe,
2901
+ x as supports,
2902
+ Ae as targetOrigin,
2903
+ Et as toRGB,
2904
+ bt as unsubscribe,
2905
+ B as urlToPath,
2906
+ Ns as useBackButton,
2907
+ Ds as useBiometryManager,
2908
+ Vs as useClosingBehavior,
2909
+ Ms as useCloudStorage,
2910
+ Bs as useHapticFeedback,
2911
+ $s as useInitData,
2912
+ Ls as useInvoice,
2913
+ Us as useMainButton,
2914
+ Hs as useMiniApp,
2915
+ Ws as usePopup,
2916
+ js as useQRScanner,
2917
+ qs as useSDK,
2918
+ Gs as useSettingsButton,
2919
+ zs as useThemeParams,
2920
+ Ks as useUtils,
2921
+ Js as useViewport,
2922
+ hn as withBackButton,
2923
+ pn as withBiometryManager,
2924
+ un as withClosingBehavior,
2925
+ dn as withCloudStorage,
2926
+ ln as withHapticFeedback,
2927
+ _n as withInitData,
2928
+ gn as withInvoice,
2929
+ fn as withMainButton,
2930
+ mn as withMiniApp,
2931
+ wn as withPopup,
2932
+ bn as withQRScanner,
2933
+ vn as withSettingsButton,
2934
+ yn as withThemeParams,
2935
+ Tt as withTimeout,
2936
+ En as withUtils,
2937
+ Pn as withViewport
2938
+ };
2939
+ //# sourceMappingURL=index.js.map