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