@tma.js/sdk-react 2.2.8 → 3.0.1

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