@tma.js/sdk 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +1 -1
  2. package/dist/dts/bridge/index.d.ts +1 -0
  3. package/dist/dts/bridge/invoke-custom-method.d.ts +18 -0
  4. package/dist/dts/bridge/methods/custom-methods.d.ts +56 -0
  5. package/dist/dts/bridge/methods/index.d.ts +1 -1
  6. package/dist/dts/bridge/methods/methods.d.ts +1 -1
  7. package/dist/dts/bridge/request.d.ts +3 -12
  8. package/dist/dts/cloud-storage/CloudStorage.d.ts +7 -16
  9. package/dist/dts/index.d.ts +8 -6
  10. package/dist/dts/init/creators/createMiniApp.d.ts +3 -1
  11. package/dist/dts/init/creators/createSettingsButton.d.ts +10 -0
  12. package/dist/dts/init/creators/index.d.ts +1 -0
  13. package/dist/dts/init/init.d.ts +1 -0
  14. package/dist/dts/init/types.d.ts +2 -0
  15. package/dist/dts/mini-app/MiniApp.d.ts +34 -4
  16. package/dist/dts/mini-app/contactParser.d.ts +2 -0
  17. package/dist/dts/mini-app/types.d.ts +12 -0
  18. package/dist/dts/settings-button/SettingsButton.d.ts +42 -0
  19. package/dist/dts/settings-button/index.d.ts +2 -0
  20. package/dist/dts/settings-button/types.d.ts +10 -0
  21. package/dist/dts/storage.d.ts +3 -0
  22. package/dist/dts/timeout/index.d.ts +1 -0
  23. package/dist/dts/timeout/sleep.d.ts +5 -0
  24. package/dist/dts/timeout/withTimeout.d.ts +5 -12
  25. package/dist/dts/types/index.d.ts +1 -0
  26. package/dist/dts/types/methods.d.ts +15 -0
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.iife.js +1 -1
  30. package/dist/index.iife.js.map +1 -1
  31. package/dist/index.mjs +854 -670
  32. package/dist/index.mjs.map +1 -1
  33. package/package.json +1 -1
  34. package/src/bridge/events/parsers/phoneRequested.ts +1 -1
  35. package/src/bridge/index.ts +1 -0
  36. package/src/bridge/invoke-custom-method.ts +56 -0
  37. package/src/bridge/methods/custom-methods.ts +68 -0
  38. package/src/bridge/methods/index.ts +1 -1
  39. package/src/bridge/methods/methods.ts +3 -5
  40. package/src/bridge/request.ts +35 -44
  41. package/src/cloud-storage/CloudStorage.ts +36 -53
  42. package/src/index.ts +14 -20
  43. package/src/init/creators/createMiniApp.ts +4 -0
  44. package/src/init/creators/createSettingsButton.ts +25 -0
  45. package/src/init/creators/createViewport.ts +16 -5
  46. package/src/init/creators/index.ts +1 -0
  47. package/src/init/init.ts +9 -5
  48. package/src/init/types.ts +2 -0
  49. package/src/mini-app/MiniApp.ts +131 -20
  50. package/src/mini-app/contactParser.ts +29 -0
  51. package/src/mini-app/types.ts +13 -0
  52. package/src/settings-button/SettingsButton.ts +85 -0
  53. package/src/settings-button/index.ts +2 -0
  54. package/src/settings-button/types.ts +15 -0
  55. package/src/storage.ts +3 -0
  56. package/src/timeout/index.ts +1 -0
  57. package/src/timeout/sleep.ts +10 -0
  58. package/src/timeout/withTimeout.ts +10 -22
  59. package/src/types/index.ts +1 -0
  60. package/src/types/methods.ts +18 -0
  61. package/dist/dts/bridge/methods/invoke-custom-method.d.ts +0 -24
  62. package/src/bridge/methods/invoke-custom-method.ts +0 -25
package/dist/index.mjs CHANGED
@@ -1,46 +1,46 @@
1
1
  var $t = Object.defineProperty;
2
- var Vt = (r, t, e) => t in r ? $t(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var o = (r, t, e) => (Vt(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- function D(r) {
2
+ var Tt = (r, t, e) => t in r ? $t(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var o = (r, t, e) => (Tt(r, typeof t != "symbol" ? t + "" : t, e), e);
4
+ function H(r) {
5
5
  return typeof r == "object" && r !== null && !Array.isArray(r);
6
6
  }
7
- function ct() {
7
+ function ht() {
8
8
  return performance.getEntriesByType("navigation")[0] || null;
9
9
  }
10
- function Tt() {
11
- const r = ct();
10
+ function Bt() {
11
+ const r = ht();
12
12
  return r ? r.type === "reload" : null;
13
13
  }
14
- function L() {
14
+ function R() {
15
15
  return new TypeError("Value has unexpected type");
16
16
  }
17
- class G extends Error {
18
- constructor(e, { cause: n, type: s } = {}) {
19
- super(`Unable to parse value${s ? ` as ${s}` : ""}`, { cause: n });
17
+ class F extends Error {
18
+ constructor(e, { cause: s, type: n } = {}) {
19
+ super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
20
20
  /**
21
21
  * Parser name.
22
22
  */
23
23
  o(this, "type");
24
- this.value = e, Object.setPrototypeOf(this, G.prototype), this.type = s;
24
+ this.value = e, Object.setPrototypeOf(this, F.prototype), this.type = n;
25
25
  }
26
26
  }
27
- class F {
28
- constructor(t, e, n) {
29
- this.parser = t, this.isOptional = e, this.type = n;
27
+ class z {
28
+ constructor(t, e, s) {
29
+ this.parser = t, this.isOptional = e, this.type = s;
30
30
  }
31
31
  parse(t) {
32
32
  if (!(this.isOptional && t === void 0))
33
33
  try {
34
34
  return this.parser(t);
35
35
  } catch (e) {
36
- throw new G(t, { type: this.type, cause: e });
36
+ throw new F(t, { type: this.type, cause: e });
37
37
  }
38
38
  }
39
39
  optional() {
40
40
  return this.isOptional = !0, this;
41
41
  }
42
42
  }
43
- function It(r) {
43
+ function Dt(r) {
44
44
  if (Array.isArray(r))
45
45
  return r;
46
46
  if (typeof r == "string")
@@ -50,61 +50,61 @@ function It(r) {
50
50
  return t;
51
51
  } catch {
52
52
  }
53
- throw L();
53
+ throw R();
54
54
  }
55
- class Rt extends F {
56
- constructor(e, n, s) {
57
- super(It, n, s);
55
+ class Wt extends z {
56
+ constructor(e, s, n) {
57
+ super(Dt, s, n);
58
58
  o(this, "itemParser");
59
59
  this.itemParser = typeof e == "function" ? e : e.parse.bind(e);
60
60
  }
61
61
  parse(e) {
62
- const n = super.parse(e);
63
- return n === void 0 ? n : n.map(this.itemParser);
62
+ const s = super.parse(e);
63
+ return s === void 0 ? s : s.map(this.itemParser);
64
64
  }
65
65
  of(e) {
66
66
  return this.itemParser = typeof e == "function" ? e : e.parse.bind(e), this;
67
67
  }
68
68
  }
69
- function $(r, t) {
70
- return () => new F(r, !1, t);
69
+ function V(r, t) {
70
+ return () => new z(r, !1, t);
71
71
  }
72
- class U extends Error {
73
- constructor(t, { cause: e, type: n } = {}) {
74
- super(`Unable to parse field "${t}"${n ? ` as ${n}` : ""}`, { cause: e }), Object.setPrototypeOf(this, U.prototype);
72
+ class j extends Error {
73
+ constructor(t, { cause: e, type: s } = {}) {
74
+ super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, j.prototype);
75
75
  }
76
76
  }
77
- function ht(r, t) {
77
+ function ut(r, t) {
78
78
  const e = {};
79
- for (const n in r) {
80
- const s = r[n];
81
- if (!s)
79
+ for (const s in r) {
80
+ const n = r[s];
81
+ if (!n)
82
82
  continue;
83
83
  let i, a;
84
- if (typeof s == "function" || "parse" in s)
85
- i = n, a = typeof s == "function" ? s : s.parse.bind(s);
84
+ if (typeof n == "function" || "parse" in n)
85
+ i = s, a = typeof n == "function" ? n : n.parse.bind(n);
86
86
  else {
87
- const { type: l } = s;
88
- i = s.from || n, a = typeof l == "function" ? l : l.parse.bind(l);
87
+ const { type: p } = n;
88
+ i = n.from || s, a = typeof p == "function" ? p : p.parse.bind(p);
89
89
  }
90
90
  let c;
91
91
  const u = t(i);
92
92
  try {
93
93
  c = a(u);
94
- } catch (l) {
95
- throw l instanceof G ? new U(i, {
96
- type: l.type,
97
- cause: l
98
- }) : new U(i, { cause: l });
94
+ } catch (p) {
95
+ throw p instanceof F ? new j(i, {
96
+ type: p.type,
97
+ cause: p
98
+ }) : new j(i, { cause: p });
99
99
  }
100
- c !== void 0 && (e[n] = c);
100
+ c !== void 0 && (e[s] = c);
101
101
  }
102
102
  return e;
103
103
  }
104
- function Bt(r) {
105
- return new Rt((t) => t, !1, r);
104
+ function Nt(r) {
105
+ return new Wt((t) => t, !1, r);
106
106
  }
107
- const C = $((r) => {
107
+ const P = V((r) => {
108
108
  if (typeof r == "boolean")
109
109
  return r;
110
110
  const t = String(r);
@@ -112,8 +112,8 @@ const C = $((r) => {
112
112
  return !0;
113
113
  if (t === "0" || t === "false")
114
114
  return !1;
115
- throw L();
116
- }, "boolean"), A = $((r) => {
115
+ throw R();
116
+ }, "boolean"), k = V((r) => {
117
117
  if (typeof r == "number")
118
118
  return r;
119
119
  if (typeof r == "string") {
@@ -121,72 +121,72 @@ const C = $((r) => {
121
121
  if (!Number.isNaN(t))
122
122
  return t;
123
123
  }
124
- throw L();
125
- }, "number"), Dt = $((r) => r instanceof Date ? r : new Date(A().parse(r) * 1e3), "Date");
126
- function Z(r) {
124
+ throw R();
125
+ }, "number"), pt = V((r) => r instanceof Date ? r : new Date(k().parse(r) * 1e3), "Date");
126
+ function Y(r) {
127
127
  let t = r;
128
128
  if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
129
- throw L();
129
+ throw R();
130
130
  return t;
131
131
  }
132
132
  function g(r, t) {
133
- return new F((e) => {
134
- const n = Z(e);
135
- return ht(r, (s) => n[s]);
133
+ return new z((e) => {
134
+ const s = Y(e);
135
+ return ut(r, (n) => s[n]);
136
136
  }, !1, t);
137
137
  }
138
- function ut(r) {
138
+ function lt(r) {
139
139
  return /^#[\da-f]{6}$/i.test(r);
140
140
  }
141
- function Ht(r) {
141
+ function Ot(r) {
142
142
  return /^#[\da-f]{3}$/i.test(r);
143
143
  }
144
- function pt(r) {
144
+ function dt(r) {
145
145
  const t = r.replace(/\s/g, "").toLowerCase();
146
- if (ut(t))
146
+ if (lt(t))
147
147
  return t;
148
- if (Ht(t)) {
149
- let n = "#";
150
- for (let s = 0; s < 3; s += 1)
151
- n += t[1 + s].repeat(2);
152
- return n;
148
+ if (Ot(t)) {
149
+ let s = "#";
150
+ for (let n = 0; n < 3; n += 1)
151
+ s += t[1 + n].repeat(2);
152
+ return s;
153
153
  }
154
154
  const e = 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}\)$/);
155
155
  if (e === null)
156
156
  throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
157
- return e.slice(1).reduce((n, s) => {
158
- const i = parseInt(s, 10).toString(16);
159
- return n + (i.length === 1 ? "0" : "") + i;
157
+ return e.slice(1).reduce((s, n) => {
158
+ const i = parseInt(n, 10).toString(16);
159
+ return s + (i.length === 1 ? "0" : "") + i;
160
160
  }, "#");
161
161
  }
162
- function lt(r) {
163
- const t = pt(r);
162
+ function ft(r) {
163
+ const t = dt(r);
164
164
  return Math.sqrt(
165
- [0.299, 0.587, 0.114].reduce((n, s, i) => {
165
+ [0.299, 0.587, 0.114].reduce((s, n, i) => {
166
166
  const a = parseInt(t.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
167
- return n + a * a * s;
167
+ return s + a * a * n;
168
168
  }, 0)
169
169
  ) < 120;
170
170
  }
171
- const h = $((r) => {
171
+ const h = V((r) => {
172
172
  if (typeof r == "string" || typeof r == "number")
173
173
  return r.toString();
174
- throw L();
175
- }, "string"), dt = $((r) => pt(h().parse(r)), "rgb");
176
- function ft(r, t) {
177
- return new F((e) => {
174
+ throw R();
175
+ }, "string"), gt = V((r) => dt(h().parse(r)), "rgb");
176
+ function X(r, t) {
177
+ return new z((e) => {
178
178
  if (typeof e != "string" && !(e instanceof URLSearchParams))
179
- throw L();
180
- const n = typeof e == "string" ? new URLSearchParams(e) : e;
181
- return ht(r, (s) => {
182
- const i = n.get(s);
179
+ throw R();
180
+ const s = typeof e == "string" ? new URLSearchParams(e) : e;
181
+ return ut(r, (n) => {
182
+ const i = s.get(n);
183
183
  return i === null ? void 0 : i;
184
184
  });
185
185
  }, !1, t);
186
186
  }
187
- function Nt() {
187
+ function Ht() {
188
188
  return g({
189
- id: A(),
189
+ id: k(),
190
190
  type: h(),
191
191
  title: h(),
192
192
  photoUrl: {
@@ -196,7 +196,7 @@ function Nt() {
196
196
  username: h().optional()
197
197
  }, "Chat");
198
198
  }
199
- class Ot {
199
+ class Ut {
200
200
  constructor(t) {
201
201
  this.initData = t;
202
202
  }
@@ -269,27 +269,27 @@ class Ot {
269
269
  return this.initData.user;
270
270
  }
271
271
  }
272
- function tt() {
272
+ function rt() {
273
273
  return g({
274
274
  addedToAttachmentMenu: {
275
- type: C().optional(),
275
+ type: P().optional(),
276
276
  from: "added_to_attachment_menu"
277
277
  },
278
278
  allowsWriteToPm: {
279
- type: C().optional(),
279
+ type: P().optional(),
280
280
  from: "allows_write_to_pm"
281
281
  },
282
282
  firstName: {
283
283
  type: h(),
284
284
  from: "first_name"
285
285
  },
286
- id: A(),
286
+ id: k(),
287
287
  isBot: {
288
- type: C().optional(),
288
+ type: P().optional(),
289
289
  from: "is_bot"
290
290
  },
291
291
  isPremium: {
292
- type: C().optional(),
292
+ type: P().optional(),
293
293
  from: "is_premium"
294
294
  },
295
295
  languageCode: {
@@ -307,17 +307,17 @@ function tt() {
307
307
  username: h().optional()
308
308
  }, "User");
309
309
  }
310
- function gt() {
311
- return ft({
310
+ function wt() {
311
+ return X({
312
312
  authDate: {
313
- type: Dt(),
313
+ type: pt(),
314
314
  from: "auth_date"
315
315
  },
316
316
  canSendAfter: {
317
- type: A().optional(),
317
+ type: k().optional(),
318
318
  from: "can_send_after"
319
319
  },
320
- chat: Nt().optional(),
320
+ chat: Ht().optional(),
321
321
  chatInstance: {
322
322
  type: h().optional(),
323
323
  from: "chat_instance"
@@ -331,39 +331,39 @@ function gt() {
331
331
  type: h().optional(),
332
332
  from: "query_id"
333
333
  },
334
- receiver: tt().optional(),
334
+ receiver: rt().optional(),
335
335
  startParam: {
336
336
  type: h().optional(),
337
337
  from: "start_param"
338
338
  },
339
- user: tt().optional()
339
+ user: rt().optional()
340
340
  }, "InitData");
341
341
  }
342
- function Qe(r) {
343
- return gt().parse(r);
342
+ function er(r) {
343
+ return wt().parse(r);
344
344
  }
345
- function Wt(r) {
345
+ function Mt(r) {
346
346
  return r.replace(/(^|_)bg/, (t, e) => `${e}background`).replace(/_([a-z])/g, (t, e) => e.toUpperCase());
347
347
  }
348
- function Mt(r) {
348
+ function jt(r) {
349
349
  return r.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`).replace(/(^|_)background/, (t, e) => `${e}bg`);
350
350
  }
351
- const wt = $(
351
+ const _t = V(
352
352
  (r) => {
353
- const t = dt().optional();
354
- return Object.entries(Z(r)).reduce((e, [n, s]) => (e[Wt(n)] = t.parse(s), e), {});
353
+ const t = gt().optional();
354
+ return Object.entries(Y(r)).reduce((e, [s, n]) => (e[Mt(s)] = t.parse(n), e), {});
355
355
  },
356
356
  "ThemeParams"
357
357
  );
358
- function _t(r) {
359
- return wt().parse(r);
358
+ function bt(r) {
359
+ return _t().parse(r);
360
360
  }
361
- function Ze(r = {}) {
362
- return _("web_app_request_theme", "theme_changed", r).then(_t);
361
+ function rr(r = {}) {
362
+ return m("web_app_request_theme", "theme_changed", r).then(bt);
363
363
  }
364
- function Ut(r) {
364
+ function Gt(r) {
365
365
  return JSON.stringify(
366
- Object.entries(r).reduce((t, [e, n]) => (n && (t[Mt(e)] = n), t), {})
366
+ Object.entries(r).reduce((t, [e, s]) => (s && (t[jt(e)] = s), t), {})
367
367
  );
368
368
  }
369
369
  class w {
@@ -377,15 +377,15 @@ class w {
377
377
  * @param listener - event listener.
378
378
  * @param once - should listener called only once.
379
379
  */
380
- addListener(t, e, n) {
381
- let s = this.listeners.get(t);
382
- return s || (s = [], this.listeners.set(t, s)), s.push([e, n]), () => this.off(t, e);
380
+ addListener(t, e, s) {
381
+ let n = this.listeners.get(t);
382
+ return n || (n = [], this.listeners.set(t, n)), n.push([e, s]), () => this.off(t, e);
383
383
  }
384
384
  emit(t, ...e) {
385
- this.subscribeListeners.forEach((s) => s(t, ...e));
386
- const n = this.listeners.get(t);
387
- n && n.forEach(([s, i], a) => {
388
- s(...e), i && n.splice(a, 1);
385
+ this.subscribeListeners.forEach((n) => n(t, ...e));
386
+ const s = this.listeners.get(t);
387
+ s && s.forEach(([n, i], a) => {
388
+ n(...e), i && s.splice(a, 1);
389
389
  });
390
390
  }
391
391
  /**
@@ -415,11 +415,11 @@ class w {
415
415
  * @param listener - event listener.
416
416
  */
417
417
  off(t, e) {
418
- const n = this.listeners.get(t);
419
- if (n) {
420
- for (let s = 0; s < n.length; s += 1)
421
- if (e === n[s][0]) {
422
- n.splice(s, 1);
418
+ const s = this.listeners.get(t);
419
+ if (s) {
420
+ for (let n = 0; n < s.length; n += 1)
421
+ if (e === s[n][0]) {
422
+ s.splice(n, 1);
423
423
  return;
424
424
  }
425
425
  }
@@ -448,7 +448,7 @@ class w {
448
448
  }
449
449
  }
450
450
  }
451
- class b {
451
+ class _ {
452
452
  constructor(t, e) {
453
453
  this.state = t, this.ee = e;
454
454
  }
@@ -462,13 +462,13 @@ class b {
462
462
  return { ...this.state };
463
463
  }
464
464
  set(t, e) {
465
- let n = !1;
465
+ let s = !1;
466
466
  if (typeof t == "string")
467
- n = this.internalSet(t, e);
467
+ s = this.internalSet(t, e);
468
468
  else
469
- for (const s in t)
470
- this.internalSet(s, t[s]) && (n = !0);
471
- n && this.ee.emit("change");
469
+ for (const n in t)
470
+ this.internalSet(n, t[n]) && (s = !0);
471
+ s && this.ee.emit("change");
472
472
  }
473
473
  /**
474
474
  * Returns value by specified key.
@@ -478,7 +478,7 @@ class b {
478
478
  return this.state[t];
479
479
  }
480
480
  }
481
- class jt {
481
+ class Ft {
482
482
  constructor(t) {
483
483
  o(this, "ee", new w());
484
484
  o(this, "state");
@@ -490,7 +490,7 @@ class jt {
490
490
  * Removes event listener.
491
491
  */
492
492
  o(this, "off", this.ee.off.bind(this.ee));
493
- this.state = new b(t, this.ee);
493
+ this.state = new _(t, this.ee);
494
494
  }
495
495
  /**
496
496
  * @since v6.10
@@ -537,7 +537,7 @@ class jt {
537
537
  * value is calculated according to theme background color.
538
538
  */
539
539
  get isDark() {
540
- return !this.backgroundColor || lt(this.backgroundColor);
540
+ return !this.backgroundColor || ft(this.backgroundColor);
541
541
  }
542
542
  get linkColor() {
543
543
  return this.get("linkColor");
@@ -562,8 +562,8 @@ class jt {
562
562
  * @returns Function to stop listening.
563
563
  */
564
564
  listen() {
565
- return k("theme_changed", (t) => {
566
- this.state.set(_t(t.theme_params));
565
+ return y("theme_changed", (t) => {
566
+ this.state.set(bt(t.theme_params));
567
567
  });
568
568
  }
569
569
  /**
@@ -576,14 +576,14 @@ class jt {
576
576
  return this.get("textColor");
577
577
  }
578
578
  }
579
- function bt() {
580
- return ft({
579
+ function mt() {
580
+ return X({
581
581
  botInline: {
582
- type: C().optional(),
582
+ type: P().optional(),
583
583
  from: "tgWebAppBotInline"
584
584
  },
585
585
  initData: {
586
- type: gt().optional(),
586
+ type: wt().optional(),
587
587
  from: "tgWebAppData"
588
588
  },
589
589
  initDataRaw: {
@@ -595,11 +595,11 @@ function bt() {
595
595
  from: "tgWebAppPlatform"
596
596
  },
597
597
  showSettings: {
598
- type: C().optional(),
598
+ type: P().optional(),
599
599
  from: "tgWebAppShowSettings"
600
600
  },
601
601
  themeParams: {
602
- type: wt(),
602
+ type: _t(),
603
603
  from: "tgWebAppThemeParams"
604
604
  },
605
605
  version: {
@@ -608,65 +608,65 @@ function bt() {
608
608
  }
609
609
  }, "LaunchParams");
610
610
  }
611
- function mt(r) {
612
- return bt().parse(r);
611
+ function yt(r) {
612
+ return mt().parse(r);
613
613
  }
614
- function Gt() {
615
- return mt(window.location.hash.slice(1));
614
+ function zt() {
615
+ return yt(window.location.hash.slice(1));
616
616
  }
617
- function Ft() {
618
- const r = ct();
617
+ function Jt() {
618
+ const r = ht();
619
619
  if (!r)
620
620
  throw new Error("Unable to get first navigation entry.");
621
621
  const t = r.name.match(/#(.*)/);
622
622
  if (!t)
623
623
  throw new Error("First navigation entry does not contain hash part.");
624
- return mt(t[1]);
624
+ return yt(t[1]);
625
625
  }
626
- function zt() {
626
+ function Qt() {
627
627
  try {
628
- return Ft();
628
+ return Jt();
629
629
  } catch {
630
630
  }
631
631
  try {
632
- return Gt();
632
+ return zt();
633
633
  } catch {
634
634
  }
635
635
  return null;
636
636
  }
637
- function Jt(r) {
637
+ function Zt(r) {
638
638
  const {
639
639
  initDataRaw: t,
640
640
  themeParams: e,
641
- platform: n,
642
- version: s,
641
+ platform: s,
642
+ version: n,
643
643
  showSettings: i,
644
644
  botInline: a
645
645
  } = r, c = new URLSearchParams();
646
- return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", n), c.set("tgWebAppThemeParams", Ut(e)), c.set("tgWebAppVersion", s), typeof i == "boolean" && c.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && c.set("tgWebAppBotInline", a ? "1" : "0"), c.toString();
646
+ return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", s), c.set("tgWebAppThemeParams", Gt(e)), c.set("tgWebAppVersion", n), typeof i == "boolean" && c.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && c.set("tgWebAppBotInline", a ? "1" : "0"), c.toString();
647
647
  }
648
- const yt = "telegram-mini-apps-launch-params";
649
- function Qt() {
650
- const r = sessionStorage.getItem(yt);
651
- return r ? bt().parse(r) : null;
648
+ const Et = "telegram-mini-apps-launch-params";
649
+ function Kt() {
650
+ const r = sessionStorage.getItem(Et);
651
+ return r ? mt().parse(r) : null;
652
652
  }
653
- function Zt(r) {
654
- sessionStorage.setItem(yt, Jt(r));
653
+ function Yt(r) {
654
+ sessionStorage.setItem(Et, Zt(r));
655
655
  }
656
- function Kt() {
656
+ function Xt() {
657
657
  try {
658
658
  return window.self !== window.top;
659
659
  } catch {
660
660
  return !0;
661
661
  }
662
662
  }
663
- function Yt() {
664
- const r = Qt(), t = zt(), e = Tt();
663
+ function te() {
664
+ const r = Kt(), t = Qt(), e = Bt();
665
665
  if (r) {
666
666
  if (t)
667
667
  return {
668
668
  launchParams: t,
669
- isPageReload: Kt() ? e || r.initDataRaw === t.initDataRaw : !0
669
+ isPageReload: Xt() ? e || r.initDataRaw === t.initDataRaw : !0
670
670
  };
671
671
  if (e)
672
672
  return {
@@ -682,45 +682,45 @@ function Yt() {
682
682
  };
683
683
  throw new Error("Unable to retrieve any launch parameters.");
684
684
  }
685
- const et = "tmajsLaunchData";
686
- function Et() {
687
- const r = window[et];
685
+ const st = "tmajsLaunchData";
686
+ function Ct() {
687
+ const r = window[st];
688
688
  if (r)
689
689
  return r;
690
- const t = Yt();
691
- return window[et] = t, Zt(t.launchParams), t;
690
+ const t = te();
691
+ return window[st] = t, Yt(t.launchParams), t;
692
692
  }
693
- function Ke() {
693
+ function sr() {
694
694
  try {
695
- return Et(), !0;
695
+ return Ct(), !0;
696
696
  } catch {
697
697
  return !1;
698
698
  }
699
699
  }
700
- function Xt(r) {
701
- return "external" in r && D(r.external) && "notify" in r.external && typeof r.external.notify == "function";
700
+ function ee(r) {
701
+ return "external" in r && H(r.external) && "notify" in r.external && typeof r.external.notify == "function";
702
702
  }
703
- function te(r) {
704
- return "TelegramWebviewProxy" in r && D(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
703
+ function re(r) {
704
+ return "TelegramWebviewProxy" in r && H(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
705
705
  }
706
- function Ct() {
706
+ function vt() {
707
707
  try {
708
708
  return window.self !== window.top;
709
709
  } catch {
710
710
  return !0;
711
711
  }
712
712
  }
713
- class K extends Error {
713
+ class tt extends Error {
714
714
  constructor(t, e) {
715
- super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, K.prototype);
715
+ super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, tt.prototype);
716
716
  }
717
717
  }
718
- class Y extends Error {
719
- constructor(t, e, n) {
720
- super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${n}.`), Object.setPrototypeOf(this, Y.prototype);
718
+ class et extends Error {
719
+ constructor(t, e, s) {
720
+ super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, et.prototype);
721
721
  }
722
722
  }
723
- class vt {
723
+ class Pt {
724
724
  constructor(t, e) {
725
725
  this.prefix = t, this.enabled = e;
726
726
  }
@@ -732,14 +732,14 @@ class vt {
732
732
  print(t, ...e) {
733
733
  if (!this.enabled)
734
734
  return;
735
- const n = /* @__PURE__ */ new Date(), s = Intl.DateTimeFormat("en-GB", {
735
+ const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
736
736
  hour: "2-digit",
737
737
  minute: "2-digit",
738
738
  second: "2-digit",
739
739
  fractionalSecondDigits: 3,
740
740
  timeZone: "UTC"
741
- }).format(n);
742
- console[t](`[${s}]`, this.prefix, ...e);
741
+ }).format(s);
742
+ console[t](`[${n}]`, this.prefix, ...e);
743
743
  }
744
744
  /**
745
745
  * Disables the logger.
@@ -775,31 +775,31 @@ class vt {
775
775
  this.print("warn", ...t);
776
776
  }
777
777
  }
778
- let kt = "https://web.telegram.org";
779
- const P = new vt("[SDK]", !1);
780
- function Ye(r) {
778
+ let St = "https://web.telegram.org";
779
+ const q = new Pt("[SDK]", !1);
780
+ function nr(r) {
781
781
  if (r) {
782
- P.enable();
782
+ q.enable();
783
783
  return;
784
784
  }
785
- P.disable();
785
+ q.disable();
786
786
  }
787
- function Xe(r) {
788
- kt = r;
787
+ function ir(r) {
788
+ St = r;
789
789
  }
790
- function ee() {
791
- return kt;
790
+ function se() {
791
+ return St;
792
792
  }
793
- const re = g({
793
+ const ne = g({
794
794
  eventType: h(),
795
795
  eventData: (r) => r
796
796
  });
797
- function ne(r, t) {
797
+ function ie(r, t) {
798
798
  window.dispatchEvent(new MessageEvent("message", {
799
799
  data: JSON.stringify({ eventType: r, eventData: t })
800
800
  }));
801
801
  }
802
- function se() {
802
+ function oe() {
803
803
  const r = window;
804
804
  "TelegramGameProxy_receiveEvent" in r || [
805
805
  ["TelegramGameProxy_receiveEvent"],
@@ -810,78 +810,78 @@ function se() {
810
810
  // Android and iOS.
811
811
  ].forEach((t) => {
812
812
  let e = r;
813
- t.forEach((n, s, i) => {
814
- if (s === i.length - 1) {
815
- e[n] = ne;
813
+ t.forEach((s, n, i) => {
814
+ if (n === i.length - 1) {
815
+ e[s] = ie;
816
816
  return;
817
817
  }
818
- n in e || (e[n] = {}), e = e[n];
818
+ s in e || (e[s] = {}), e = e[s];
819
819
  });
820
820
  });
821
821
  }
822
- function ie(r) {
823
- se(), window.addEventListener("message", (t) => {
822
+ function ae(r) {
823
+ oe(), window.addEventListener("message", (t) => {
824
824
  try {
825
- const { eventType: e, eventData: n } = re.parse(t.data);
826
- r(e, n);
825
+ const { eventType: e, eventData: s } = ne.parse(t.data);
826
+ r(e, s);
827
827
  } catch {
828
828
  }
829
829
  });
830
830
  }
831
- function oe() {
831
+ function ce() {
832
832
  return g({
833
833
  req_id: h(),
834
834
  data: (r) => r === null ? r : h().optional().parse(r)
835
835
  });
836
836
  }
837
- function ae() {
837
+ function he() {
838
838
  return g({
839
839
  req_id: h(),
840
840
  result: (r) => r,
841
841
  error: h().optional()
842
842
  });
843
843
  }
844
- function ce() {
844
+ function ue() {
845
845
  return g({
846
846
  slug: h(),
847
847
  status: h()
848
848
  });
849
849
  }
850
- function he() {
850
+ function pe() {
851
851
  return g({ status: h() });
852
852
  }
853
- function ue() {
853
+ function le() {
854
854
  return g({
855
855
  button_id: (r) => r == null ? void 0 : h().parse(r)
856
856
  });
857
857
  }
858
- function pe() {
858
+ function de() {
859
859
  return g({
860
860
  data: h().optional()
861
861
  });
862
862
  }
863
- function le() {
863
+ function fe() {
864
864
  return g({
865
865
  theme_params: (r) => {
866
- const t = dt().optional();
867
- return Object.entries(Z(r)).reduce((e, [n, s]) => (e[n] = t.parse(s), e), {});
866
+ const t = gt().optional();
867
+ return Object.entries(Y(r)).reduce((e, [s, n]) => (e[s] = t.parse(n), e), {});
868
868
  }
869
869
  });
870
870
  }
871
- function de() {
871
+ function ge() {
872
872
  return g({
873
- height: A(),
874
- width: (r) => r == null ? window.innerWidth : A().parse(r),
875
- is_state_stable: C(),
876
- is_expanded: C()
873
+ height: k(),
874
+ width: (r) => r == null ? window.innerWidth : k().parse(r),
875
+ is_state_stable: P(),
876
+ is_expanded: P()
877
877
  });
878
878
  }
879
- function fe() {
879
+ function we() {
880
880
  return g({ status: h() });
881
881
  }
882
- function ge() {
883
- const r = new w(), t = (e, ...n) => {
884
- P.log("Emitting processed event:", e, ...n), r.emit(e, ...n);
882
+ function _e() {
883
+ const r = new w(), t = (e, ...s) => {
884
+ q.log("Emitting processed event:", e, ...s), r.emit(e, ...s);
885
885
  };
886
886
  return window.addEventListener("resize", () => {
887
887
  t("viewport_changed", {
@@ -890,33 +890,33 @@ function ge() {
890
890
  is_state_stable: !0,
891
891
  is_expanded: !0
892
892
  });
893
- }), ie((e, n) => {
894
- P.log("Received raw event:", e, n);
893
+ }), ae((e, s) => {
894
+ q.log("Received raw event:", e, s);
895
895
  try {
896
896
  switch (e) {
897
897
  case "viewport_changed":
898
- return t(e, de().parse(n));
898
+ return t(e, ge().parse(s));
899
899
  case "theme_changed":
900
- return t(e, le().parse(n));
900
+ return t(e, fe().parse(s));
901
901
  case "popup_closed":
902
902
  return (
903
903
  // Sent on desktop.
904
- n == null ? t(e, {}) : t(e, ue().parse(n))
904
+ s == null ? t(e, {}) : t(e, le().parse(s))
905
905
  );
906
906
  case "set_custom_style":
907
- return t(e, h().parse(n));
907
+ return t(e, h().parse(s));
908
908
  case "qr_text_received":
909
- return t(e, pe().parse(n));
909
+ return t(e, de().parse(s));
910
910
  case "clipboard_text_received":
911
- return t(e, oe().parse(n));
911
+ return t(e, ce().parse(s));
912
912
  case "invoice_closed":
913
- return t(e, ce().parse(n));
913
+ return t(e, ue().parse(s));
914
914
  case "phone_requested":
915
- return t("phone_requested", he().parse(n));
915
+ return t("phone_requested", pe().parse(s));
916
916
  case "custom_method_invoked":
917
- return t("custom_method_invoked", ae().parse(n));
917
+ return t("custom_method_invoked", he().parse(s));
918
918
  case "write_access_requested":
919
- return t("write_access_requested", fe().parse(n));
919
+ return t("write_access_requested", we().parse(s));
920
920
  case "main_button_pressed":
921
921
  case "back_button_pressed":
922
922
  case "settings_button_pressed":
@@ -924,51 +924,51 @@ function ge() {
924
924
  case "reload_iframe":
925
925
  return t(e);
926
926
  default:
927
- return t(e, n);
927
+ return t(e, s);
928
928
  }
929
- } catch (s) {
930
- P.error("Error processing event:", s);
929
+ } catch (n) {
930
+ q.error("Error processing event:", n);
931
931
  }
932
932
  }), r;
933
933
  }
934
- const z = "telegram-mini-apps-cached-emitter";
935
- function H() {
934
+ const Q = "telegram-mini-apps-cached-emitter";
935
+ function U() {
936
936
  const r = window;
937
- return r[z] === void 0 && (r[z] = ge()), r[z];
937
+ return r[Q] === void 0 && (r[Q] = _e()), r[Q];
938
938
  }
939
- function N(r, t) {
940
- H().off(r, t);
939
+ function I(r, t) {
940
+ U().off(r, t);
941
941
  }
942
- function k(r, t) {
943
- return H().on(r, t), () => N(r, t);
942
+ function y(r, t) {
943
+ return U().on(r, t), () => I(r, t);
944
944
  }
945
- function tr(r, t) {
946
- return H().once(r, t), () => N(r, t);
945
+ function or(r, t) {
946
+ return U().once(r, t), () => I(r, t);
947
947
  }
948
- function we(r) {
949
- H().unsubscribe(r);
948
+ function be(r) {
949
+ U().unsubscribe(r);
950
950
  }
951
- function er(r) {
952
- return H().subscribe(r), () => we(r);
951
+ function ar(r) {
952
+ return U().subscribe(r), () => be(r);
953
953
  }
954
- function _e(r, t) {
955
- const e = r.split("."), n = t.split("."), s = Math.max(e.length, n.length);
956
- for (let i = 0; i < s; i += 1) {
957
- const a = parseInt(e[i] || "0", 10), c = parseInt(n[i] || "0", 10);
954
+ function me(r, t) {
955
+ const e = r.split("."), s = t.split("."), n = Math.max(e.length, s.length);
956
+ for (let i = 0; i < n; i += 1) {
957
+ const a = parseInt(e[i] || "0", 10), c = parseInt(s[i] || "0", 10);
958
958
  if (a !== c)
959
959
  return a > c ? 1 : -1;
960
960
  }
961
961
  return 0;
962
962
  }
963
- function E(r, t) {
964
- return _e(r, t) <= 0;
963
+ function v(r, t) {
964
+ return me(r, t) <= 0;
965
965
  }
966
- function q(r, t, e) {
966
+ function A(r, t, e) {
967
967
  if (typeof e == "string") {
968
968
  if (r === "web_app_open_link" && t === "try_instant_view")
969
- return E("6.4", e);
969
+ return v("6.4", e);
970
970
  if (r === "web_app_set_header_color" && t === "color")
971
- return E("6.9", e);
971
+ return v("6.9", e);
972
972
  }
973
973
  switch (r) {
974
974
  case "web_app_open_tg_link":
@@ -977,102 +977,125 @@ function q(r, t, e) {
977
977
  case "web_app_set_background_color":
978
978
  case "web_app_set_header_color":
979
979
  case "web_app_trigger_haptic_feedback":
980
- return E("6.1", t);
980
+ return v("6.1", t);
981
981
  case "web_app_open_popup":
982
- return E("6.2", t);
982
+ return v("6.2", t);
983
983
  case "web_app_close_scan_qr_popup":
984
984
  case "web_app_open_scan_qr_popup":
985
985
  case "web_app_read_text_from_clipboard":
986
- return E("6.4", t);
986
+ return v("6.4", t);
987
987
  case "web_app_switch_inline_query":
988
- return E("6.7", t);
988
+ return v("6.7", t);
989
989
  case "web_app_invoke_custom_method":
990
990
  case "web_app_request_write_access":
991
991
  case "web_app_request_phone":
992
- return E("6.9", t);
992
+ return v("6.9", t);
993
993
  case "web_app_setup_settings_button":
994
- return E("6.10", t);
994
+ return v("6.10", t);
995
995
  default:
996
996
  return !0;
997
997
  }
998
998
  }
999
- function S(r, t) {
1000
- return (e) => q(t[e], r);
999
+ function E(r, t) {
1000
+ return (e) => A(t[e], r);
1001
1001
  }
1002
- function St(r, t) {
1002
+ function kt(r, t) {
1003
1003
  return (e) => {
1004
- const [n, s] = t[e];
1005
- return q(n, s, r);
1004
+ const [s, n] = t[e];
1005
+ return A(s, n, r);
1006
1006
  };
1007
1007
  }
1008
1008
  function f(r, t, e) {
1009
- let n = {}, s;
1010
- t === void 0 && e === void 0 ? n = {} : t !== void 0 && e !== void 0 ? (n = e, s = t) : t !== void 0 && ("targetOrigin" in t ? n = t : s = t);
1011
- const { targetOrigin: i = ee() } = n;
1012
- if (P.log(`Calling method "${r}"`, s), Ct()) {
1009
+ let s = {}, n;
1010
+ t === void 0 && e === void 0 ? s = {} : t !== void 0 && e !== void 0 ? (s = e, n = t) : t !== void 0 && ("targetOrigin" in t ? s = t : n = t);
1011
+ const { targetOrigin: i = se() } = s;
1012
+ if (q.log(`Calling method "${r}"`, n), vt()) {
1013
1013
  window.parent.postMessage(JSON.stringify({
1014
1014
  eventType: r,
1015
- eventData: s
1015
+ eventData: n
1016
1016
  }), i);
1017
1017
  return;
1018
1018
  }
1019
- if (Xt(window)) {
1020
- window.external.notify(JSON.stringify({ eventType: r, eventData: s }));
1019
+ if (ee(window)) {
1020
+ window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
1021
1021
  return;
1022
1022
  }
1023
- if (te(window)) {
1024
- window.TelegramWebviewProxy.postEvent(r, JSON.stringify(s));
1023
+ if (re(window)) {
1024
+ window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
1025
1025
  return;
1026
1026
  }
1027
1027
  throw new Error(
1028
1028
  "Unable to determine current environment and possible way to send event."
1029
1029
  );
1030
1030
  }
1031
- function be(r) {
1031
+ function ye(r) {
1032
1032
  return (t, e) => {
1033
- if (!q(t, r))
1034
- throw new K(t, r);
1035
- if (D(e)) {
1036
- let n;
1037
- if (t === "web_app_open_link" && "try_instant_view" in e ? n = "try_instant_view" : t === "web_app_set_header_color" && "color" in e && (n = "color"), n && !q(t, n, r))
1038
- throw new Y(t, n, r);
1033
+ if (!A(t, r))
1034
+ throw new tt(t, r);
1035
+ if (H(e)) {
1036
+ let s;
1037
+ if (t === "web_app_open_link" && "try_instant_view" in e ? s = "try_instant_view" : t === "web_app_set_header_color" && "color" in e && (s = "color"), s && !A(t, s, r))
1038
+ throw new et(t, s, r);
1039
1039
  }
1040
1040
  return f(t, e);
1041
1041
  };
1042
1042
  }
1043
- class X extends Error {
1043
+ class J extends Error {
1044
1044
  constructor(t) {
1045
- super(`Async call timeout exceeded. Timeout: ${t}`), Object.setPrototypeOf(this, X.prototype);
1045
+ super(`Async call timeout exceeded. Timeout: ${t}`), Object.setPrototypeOf(this, J.prototype);
1046
1046
  }
1047
1047
  }
1048
- function rt(r) {
1048
+ function cr(r) {
1049
+ return r instanceof J;
1050
+ }
1051
+ function Ee(r) {
1052
+ return new Promise((t) => {
1053
+ setTimeout(t, r);
1054
+ });
1055
+ }
1056
+ function Ce(r) {
1049
1057
  return new Promise((t, e) => {
1050
- setTimeout(e, r, new X(r));
1058
+ setTimeout(e, r, new J(r));
1051
1059
  });
1052
1060
  }
1053
- function me(r, t) {
1054
- return typeof r == "function" ? (...e) => Promise.race([
1055
- r(...e),
1056
- rt(t)
1057
- ]) : Promise.race([r, rt(t)]);
1058
- }
1059
- function _(r, t, e, n) {
1060
- let s, i, a, c;
1061
- typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t], s = e) : (i = t, a = Array.isArray(e) ? e : [e], s = n), D(i) && typeof i.req_id == "string" && (c = i.req_id);
1062
- const { postEvent: u = f, timeout: l } = s || {}, p = s && "capture" in s ? s.capture : null, m = new Promise((d, y) => {
1063
- const x = a.map((T) => k(T, (M) => {
1064
- typeof c == "string" && (!D(M) || M.req_id !== c) || typeof p == "function" && !p(M) || (V(), d(M));
1065
- })), V = () => x.forEach((T) => T());
1061
+ function xt(r, t) {
1062
+ return Promise.race([
1063
+ r(),
1064
+ Ce(t)
1065
+ ]);
1066
+ }
1067
+ function m(r, t, e, s) {
1068
+ let n, i, a, c;
1069
+ typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t], n = e) : (i = t, a = Array.isArray(e) ? e : [e], n = s), H(i) && typeof i.req_id == "string" && (c = i.req_id);
1070
+ const { postEvent: u = f, timeout: p } = n || {}, l = n && "capture" in n ? n.capture : null, b = () => new Promise((d, C) => {
1071
+ const x = a.map((B) => y(B, (M) => {
1072
+ c && (!H(M) || M.req_id !== c) || typeof l == "function" && !l(M) || (T(), d(M));
1073
+ })), T = () => x.forEach((B) => B());
1066
1074
  try {
1067
1075
  u(r, i);
1068
- } catch (T) {
1069
- V(), y(T);
1076
+ } catch (B) {
1077
+ T(), C(B);
1070
1078
  }
1071
1079
  });
1072
- return typeof l == "number" ? me(m, l) : m;
1080
+ return typeof p == "number" ? xt(b, p) : b();
1081
+ }
1082
+ async function N(r, t, e, s = {}) {
1083
+ const { result: n, error: i } = await m(
1084
+ "web_app_invoke_custom_method",
1085
+ {
1086
+ method: r,
1087
+ params: t,
1088
+ req_id: e
1089
+ },
1090
+ "custom_method_invoked",
1091
+ s
1092
+ );
1093
+ if (i)
1094
+ throw new Error(i);
1095
+ return n;
1073
1096
  }
1074
- class ye {
1075
- constructor(t, e, n = f) {
1097
+ class ve {
1098
+ constructor(t, e, s = f) {
1076
1099
  o(this, "ee", new w());
1077
1100
  o(this, "state");
1078
1101
  /**
@@ -1080,18 +1103,18 @@ class ye {
1080
1103
  * @param event - event name.
1081
1104
  * @param listener - event listener.
1082
1105
  */
1083
- o(this, "on", (t, e) => t === "click" ? k("back_button_pressed", e) : this.ee.on(t, e));
1106
+ o(this, "on", (t, e) => t === "click" ? y("back_button_pressed", e) : this.ee.on(t, e));
1084
1107
  /**
1085
1108
  * Removes event listener.
1086
1109
  * @param event - event name.
1087
1110
  * @param listener - event listener.
1088
1111
  */
1089
- o(this, "off", (t, e) => t === "click" ? N("back_button_pressed", e) : this.ee.off(t, e));
1112
+ o(this, "off", (t, e) => t === "click" ? I("back_button_pressed", e) : this.ee.off(t, e));
1090
1113
  /**
1091
1114
  * Checks if specified method is supported by current component.
1092
1115
  */
1093
1116
  o(this, "supports");
1094
- this.postEvent = n, this.state = new b({ isVisible: t }, this.ee), this.supports = S(e, {
1117
+ this.postEvent = s, this.state = new _({ isVisible: t }, this.ee), this.supports = E(e, {
1095
1118
  show: "web_app_setup_back_button",
1096
1119
  hide: "web_app_setup_back_button"
1097
1120
  });
@@ -1121,22 +1144,22 @@ class ye {
1121
1144
  function nt(r, t) {
1122
1145
  return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
1123
1146
  }
1124
- function Ee(...r) {
1147
+ function Pe(...r) {
1125
1148
  return r.reduce((t, e) => {
1126
- let n = "";
1127
- return typeof e == "string" ? n = e : typeof e == "object" && e !== null && (n = Object.entries(e).reduce((s, [i, a]) => a ? nt(s, i) : s, "")), nt(t, n);
1149
+ let s = "";
1150
+ return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? nt(n, i) : n, "")), nt(t, s);
1128
1151
  }, "");
1129
1152
  }
1130
- function Ce(r) {
1153
+ function Se(r) {
1131
1154
  return typeof r == "object" && r !== null && !Array.isArray(null);
1132
1155
  }
1133
- function rr(...r) {
1134
- return r.reduce((t, e) => (Ce(e) && Object.entries(e).forEach(([n, s]) => {
1135
- const i = Ee(t[n], s);
1136
- i.length > 0 && (t[n] = i);
1156
+ function hr(...r) {
1157
+ return r.reduce((t, e) => (Se(e) && Object.entries(e).forEach(([s, n]) => {
1158
+ const i = Pe(t[s], n);
1159
+ i.length > 0 && (t[s] = i);
1137
1160
  }), t), {});
1138
1161
  }
1139
- class ve {
1162
+ class ke {
1140
1163
  constructor(t, e = f) {
1141
1164
  o(this, "ee", new w());
1142
1165
  o(this, "state");
@@ -1148,7 +1171,7 @@ class ve {
1148
1171
  * Removes event listener.
1149
1172
  */
1150
1173
  o(this, "off", this.ee.off.bind(this.ee));
1151
- this.postEvent = e, this.state = new b({ isConfirmationNeeded: t }, this.ee);
1174
+ this.postEvent = e, this.state = new _({ isConfirmationNeeded: t }, this.ee);
1152
1175
  }
1153
1176
  set isConfirmationNeeded(t) {
1154
1177
  this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
@@ -1175,63 +1198,61 @@ class ve {
1175
1198
  this.isConfirmationNeeded = !0;
1176
1199
  }
1177
1200
  }
1178
- function st(r, t) {
1179
- return r.reduce((e, n) => (e[n] = t, e), {});
1201
+ function it(r, t) {
1202
+ return r.reduce((e, s) => (e[s] = t, e), {});
1180
1203
  }
1181
- class ke {
1182
- constructor(t, e, n = f) {
1204
+ class xe {
1205
+ constructor(t, e, s = f) {
1183
1206
  /**
1184
1207
  * Checks if specified method is supported by current component.
1185
1208
  */
1186
1209
  o(this, "supports");
1187
- this.createRequestId = e, this.postEvent = n, this.supports = S(t, {
1210
+ this.createRequestId = e, this.postEvent = s, this.supports = E(t, {
1188
1211
  delete: "web_app_invoke_custom_method",
1189
1212
  get: "web_app_invoke_custom_method",
1190
1213
  getKeys: "web_app_invoke_custom_method",
1191
1214
  set: "web_app_invoke_custom_method"
1192
1215
  });
1193
1216
  }
1194
- /**
1195
- * Invokes custom method related to CloudStorage.
1196
- * @param method - method name.
1197
- * @param params - method parameters.
1198
- * @param options - execution options.
1199
- */
1200
- async invokeCustomMethod(t, e, n = {}) {
1201
- const { result: s, error: i } = await _(
1202
- "web_app_invoke_custom_method",
1203
- { method: t, params: e, req_id: this.createRequestId() },
1204
- "custom_method_invoked",
1205
- { ...n, postEvent: this.postEvent }
1206
- );
1207
- if (i)
1208
- throw new Error(i);
1209
- return s;
1210
- }
1211
1217
  /**
1212
1218
  * Deletes specified key or keys from the cloud storage.
1213
1219
  * @param keyOrKeys - key or keys to delete.
1214
1220
  * @param options - request execution options.
1215
1221
  */
1216
- async delete(t, e) {
1217
- const n = Array.isArray(t) ? t : [t];
1218
- n.length !== 0 && await this.invokeCustomMethod("deleteStorageValues", { keys: n }, e);
1222
+ async delete(t, e = {}) {
1223
+ const s = Array.isArray(t) ? t : [t];
1224
+ s.length !== 0 && await N(
1225
+ "deleteStorageValues",
1226
+ { keys: s },
1227
+ this.createRequestId(),
1228
+ { ...e, postEvent: this.postEvent }
1229
+ );
1219
1230
  }
1220
1231
  /**
1221
1232
  * Returns list of all keys presented in the cloud storage.
1222
1233
  * @param options - request execution options.
1223
1234
  */
1224
- async getKeys(t) {
1225
- const e = await this.invokeCustomMethod("getStorageKeys", {}, t);
1226
- return Bt().of(h()).parse(e);
1227
- }
1228
- async get(t, e) {
1229
- const n = Array.isArray(t) ? t : [t];
1230
- if (n.length === 0)
1231
- return st(n, "");
1232
- const s = g(
1233
- st(n, h())
1234
- ), i = await this.invokeCustomMethod("getStorageValues", { keys: n }, e).then((a) => s.parse(a));
1235
+ async getKeys(t = {}) {
1236
+ const e = await N(
1237
+ "getStorageKeys",
1238
+ {},
1239
+ this.createRequestId(),
1240
+ { ...t, postEvent: this.postEvent }
1241
+ );
1242
+ return Nt().of(h()).parse(e);
1243
+ }
1244
+ async get(t, e = {}) {
1245
+ const s = Array.isArray(t) ? t : [t];
1246
+ if (s.length === 0)
1247
+ return it(s, "");
1248
+ const n = g(
1249
+ it(s, h())
1250
+ ), i = await N(
1251
+ "getStorageValues",
1252
+ { keys: s },
1253
+ this.createRequestId(),
1254
+ { ...e, postEvent: this.postEvent }
1255
+ ).then((a) => n.parse(a));
1235
1256
  return Array.isArray(t) ? i : i[t];
1236
1257
  }
1237
1258
  /**
@@ -1240,17 +1261,22 @@ class ke {
1240
1261
  * @param value - storage value.
1241
1262
  * @param options - request execution options.
1242
1263
  */
1243
- async set(t, e, n) {
1244
- await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, n);
1264
+ async set(t, e, s = {}) {
1265
+ await N(
1266
+ "saveStorageValue",
1267
+ { key: t, value: e },
1268
+ this.createRequestId(),
1269
+ { ...s, postEvent: this.postEvent }
1270
+ );
1245
1271
  }
1246
1272
  }
1247
- class Se {
1273
+ class qe {
1248
1274
  constructor(t, e = f) {
1249
1275
  /**
1250
1276
  * Checks if specified method is supported by current component.
1251
1277
  */
1252
1278
  o(this, "supports");
1253
- this.postEvent = e, this.supports = S(t, {
1279
+ this.postEvent = e, this.supports = E(t, {
1254
1280
  impactOccurred: "web_app_trigger_haptic_feedback",
1255
1281
  notificationOccurred: "web_app_trigger_haptic_feedback",
1256
1282
  selectionChanged: "web_app_trigger_haptic_feedback"
@@ -1290,35 +1316,35 @@ class Se {
1290
1316
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1291
1317
  }
1292
1318
  }
1293
- function xe() {
1319
+ function Ae() {
1294
1320
  const r = document.createElement("style");
1295
- r.id = "telegram-custom-styles", document.head.appendChild(r), k("set_custom_style", (t) => {
1321
+ r.id = "telegram-custom-styles", document.head.appendChild(r), y("set_custom_style", (t) => {
1296
1322
  r.innerHTML = t;
1297
1323
  });
1298
1324
  }
1299
- function xt(r) {
1325
+ function qt(r) {
1300
1326
  return `telegram-mini-apps-${r}`;
1301
1327
  }
1302
- function O(r, t) {
1303
- sessionStorage.setItem(xt(r), JSON.stringify(t));
1328
+ function L(r, t) {
1329
+ sessionStorage.setItem(qt(r), JSON.stringify(t));
1304
1330
  }
1305
- function W(r) {
1306
- const t = sessionStorage.getItem(xt(r));
1331
+ function $(r) {
1332
+ const t = sessionStorage.getItem(qt(r));
1307
1333
  return t ? JSON.parse(t) : null;
1308
1334
  }
1309
- function Pe(r, t, e) {
1310
- const { isVisible: n = !1 } = r ? W("back-button") || {} : {}, s = new ye(n, t, e);
1311
- return s.on("change", () => {
1312
- O("back-button", { isVisible: s.isVisible });
1313
- }), s;
1335
+ function Re(r, t, e) {
1336
+ const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new ve(s, t, e);
1337
+ return n.on("change", () => {
1338
+ L("back-button", { isVisible: n.isVisible });
1339
+ }), n;
1314
1340
  }
1315
- function Ae(r, t) {
1316
- const { isConfirmationNeeded: e = !1 } = r ? W("closing-behavior") || {} : {}, n = new ve(e, t);
1317
- return n.on("change", () => O("closing-behavior", {
1318
- isConfirmationNeeded: n.isConfirmationNeeded
1319
- })), n;
1341
+ function Ve(r, t) {
1342
+ const { isConfirmationNeeded: e = !1 } = r ? $("closing-behavior") || {} : {}, s = new ke(e, t);
1343
+ return s.on("change", () => L("closing-behavior", {
1344
+ isConfirmationNeeded: s.isConfirmationNeeded
1345
+ })), s;
1320
1346
  }
1321
- class qe {
1347
+ class Ie {
1322
1348
  constructor(t) {
1323
1349
  o(this, "ee", new w());
1324
1350
  o(this, "state");
@@ -1332,30 +1358,30 @@ class qe {
1332
1358
  // FIXME: Event 'main_button_pressed' is still being received on Android
1333
1359
  // even if the main button is disabled.
1334
1360
  // Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
1335
- t === "click" ? k("main_button_pressed", e) : this.ee.on(t, e)
1361
+ t === "click" ? y("main_button_pressed", e) : this.ee.on(t, e)
1336
1362
  ));
1337
1363
  /**
1338
1364
  * Removes event listener.
1339
1365
  * @param event - event name.
1340
1366
  * @param listener - event listener.
1341
1367
  */
1342
- o(this, "off", (t, e) => t === "click" ? N("main_button_pressed", e) : this.ee.off(t, e));
1368
+ o(this, "off", (t, e) => t === "click" ? I("main_button_pressed", e) : this.ee.off(t, e));
1343
1369
  const {
1344
1370
  postEvent: e = f,
1345
- text: n,
1346
- textColor: s,
1371
+ text: s,
1372
+ textColor: n,
1347
1373
  backgroundColor: i,
1348
1374
  isEnabled: a,
1349
1375
  isVisible: c,
1350
1376
  isLoaderVisible: u
1351
1377
  } = t;
1352
- this.postEvent = e, this.state = new b({
1378
+ this.postEvent = e, this.state = new _({
1353
1379
  backgroundColor: i,
1354
1380
  isEnabled: a,
1355
1381
  isVisible: c,
1356
1382
  isLoaderVisible: u,
1357
- text: n,
1358
- textColor: s
1383
+ text: s,
1384
+ textColor: n
1359
1385
  }, this.ee);
1360
1386
  }
1361
1387
  /**
@@ -1483,38 +1509,66 @@ class qe {
1483
1509
  return this.state.set(t), this.commit(), this;
1484
1510
  }
1485
1511
  }
1486
- function Le(r, t, e, n) {
1512
+ function Le(r, t, e, s) {
1487
1513
  const {
1488
- backgroundColor: s = t,
1514
+ backgroundColor: n = t,
1489
1515
  isEnabled: i = !1,
1490
1516
  isVisible: a = !1,
1491
1517
  isLoaderVisible: c = !1,
1492
1518
  textColor: u = e,
1493
- text: l = ""
1494
- } = r ? W("main-button") || {} : {}, p = new qe({
1495
- backgroundColor: s,
1519
+ text: p = ""
1520
+ } = r ? $("main-button") || {} : {}, l = new Ie({
1521
+ backgroundColor: n,
1496
1522
  isEnabled: i,
1497
1523
  isLoaderVisible: c,
1498
1524
  isVisible: a,
1499
- postEvent: n,
1500
- text: l,
1525
+ postEvent: s,
1526
+ text: p,
1501
1527
  textColor: u
1502
- }), m = () => O("main-button", {
1503
- backgroundColor: p.backgroundColor,
1504
- isEnabled: p.isEnabled,
1505
- isLoaderVisible: p.isLoaderVisible,
1506
- isVisible: p.isVisible,
1507
- text: p.text,
1508
- textColor: p.textColor
1528
+ }), b = () => L("main-button", {
1529
+ backgroundColor: l.backgroundColor,
1530
+ isEnabled: l.isEnabled,
1531
+ isLoaderVisible: l.isLoaderVisible,
1532
+ isVisible: l.isVisible,
1533
+ text: l.text,
1534
+ textColor: l.textColor
1509
1535
  });
1510
- return p.on("change", m), p;
1536
+ return l.on("change", b), l;
1511
1537
  }
1512
- class $e {
1538
+ const $e = X({
1539
+ contact: g({
1540
+ userId: {
1541
+ type: k(),
1542
+ from: "user_id"
1543
+ },
1544
+ phoneNumber: {
1545
+ type: h(),
1546
+ from: "phone_number"
1547
+ },
1548
+ firstName: {
1549
+ type: h(),
1550
+ from: "first_name"
1551
+ },
1552
+ lastName: {
1553
+ type: h(),
1554
+ from: "last_name"
1555
+ }
1556
+ }),
1557
+ authDate: {
1558
+ type: pt(),
1559
+ from: "auth_date"
1560
+ },
1561
+ hash: h()
1562
+ });
1563
+ class Te {
1513
1564
  constructor(t) {
1514
1565
  o(this, "ee", new w());
1515
1566
  o(this, "state");
1516
1567
  o(this, "botInline");
1517
1568
  o(this, "postEvent");
1569
+ o(this, "createRequestId");
1570
+ o(this, "requestingPhoneAccess", !1);
1571
+ o(this, "requestingWriteAccess", !1);
1518
1572
  /**
1519
1573
  * Adds new event listener.
1520
1574
  */
@@ -1533,21 +1587,36 @@ class $e {
1533
1587
  o(this, "supportsParam");
1534
1588
  const {
1535
1589
  postEvent: e = f,
1536
- headerColor: n,
1537
- backgroundColor: s,
1590
+ headerColor: s,
1591
+ backgroundColor: n,
1538
1592
  version: i,
1539
- botInline: a
1540
- } = t, c = S(i, {
1593
+ botInline: a,
1594
+ createRequestId: c
1595
+ } = t, u = E(i, {
1541
1596
  requestPhoneAccess: "web_app_request_phone",
1542
1597
  requestWriteAccess: "web_app_request_write_access",
1543
1598
  switchInlineQuery: "web_app_switch_inline_query",
1544
1599
  setHeaderColor: "web_app_set_header_color",
1545
1600
  setBackgroundColor: "web_app_set_background_color"
1546
1601
  });
1547
- this.postEvent = e, this.botInline = a, this.supports = (u) => !(!c(u) || u === "switchInlineQuery" && !a), this.state = new b({ backgroundColor: s, headerColor: n }, this.ee), this.supportsParam = St(i, {
1602
+ this.postEvent = e, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new _({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = kt(i, {
1548
1603
  "setHeaderColor.color": ["web_app_set_header_color", "color"]
1549
1604
  });
1550
1605
  }
1606
+ /**
1607
+ * Attempts to get requested contact.
1608
+ */
1609
+ async getRequestedContact() {
1610
+ return N(
1611
+ "getRequestedContact",
1612
+ {},
1613
+ this.createRequestId(),
1614
+ {
1615
+ postEvent: this.postEvent,
1616
+ timeout: 1e4
1617
+ }
1618
+ ).then((t) => $e.parse(t));
1619
+ }
1551
1620
  /**
1552
1621
  * The Mini App background color.
1553
1622
  */
@@ -1576,7 +1645,19 @@ class $e {
1576
1645
  * True if current Mini App background color recognized as dark.
1577
1646
  */
1578
1647
  get isDark() {
1579
- return lt(this.backgroundColor);
1648
+ return ft(this.backgroundColor);
1649
+ }
1650
+ /**
1651
+ * True if phone access is currently being requested.
1652
+ */
1653
+ get isRequestingPhoneAccess() {
1654
+ return this.requestingPhoneAccess;
1655
+ }
1656
+ /**
1657
+ * True if write access is currently being requested.
1658
+ */
1659
+ get isRequestingWriteAccess() {
1660
+ return this.requestingWriteAccess;
1580
1661
  }
1581
1662
  /**
1582
1663
  * Informs the Telegram app that the Mini App is ready to be displayed.
@@ -1591,24 +1672,63 @@ class $e {
1591
1672
  this.postEvent("web_app_ready");
1592
1673
  }
1593
1674
  /**
1594
- * Requests current user phone access.
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.
1595
1679
  */
1596
- requestPhoneAccess() {
1597
- return _(
1598
- "web_app_request_phone",
1599
- "phone_requested",
1600
- { postEvent: this.postEvent }
1601
- ).then((t) => t.status);
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 xt(async () => {
1690
+ for (; Date.now() < s; ) {
1691
+ try {
1692
+ return await this.getRequestedContact();
1693
+ } catch {
1694
+ }
1695
+ await Ee(n), n += 50;
1696
+ }
1697
+ throw new Error("Unable to retrieve requested contact.");
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
+ requestPhoneAccess(t = {}) {
1710
+ if (this.requestingPhoneAccess)
1711
+ throw new Error("Phone access is already being requested.");
1712
+ return this.requestingPhoneAccess = !0, m("web_app_request_phone", "phone_requested", {
1713
+ ...t,
1714
+ postEvent: this.postEvent
1715
+ }).then((e) => e.status).finally(() => {
1716
+ this.requestingPhoneAccess = !1;
1717
+ });
1602
1718
  }
1603
1719
  /**
1604
1720
  * Requests write message access to current user.
1605
- */
1606
- requestWriteAccess() {
1607
- return _(
1608
- "web_app_request_write_access",
1609
- "write_access_requested",
1610
- { postEvent: this.postEvent }
1611
- ).then((t) => t.status);
1721
+ * @param options - additional options.
1722
+ */
1723
+ requestWriteAccess(t = {}) {
1724
+ if (this.requestingWriteAccess)
1725
+ throw new Error("Write access is already being requested.");
1726
+ return this.requestingWriteAccess = !0, m("web_app_request_write_access", "write_access_requested", {
1727
+ ...t,
1728
+ postEvent: this.postEvent
1729
+ }).then((e) => e.status).finally(() => {
1730
+ this.requestingWriteAccess = !1;
1731
+ });
1612
1732
  }
1613
1733
  /**
1614
1734
  * A method used to send data to the bot. When this method called, a service message sent to
@@ -1630,7 +1750,7 @@ class $e {
1630
1750
  * @param color - color key or RGB color.
1631
1751
  */
1632
1752
  setHeaderColor(t) {
1633
- this.postEvent("web_app_set_header_color", ut(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1753
+ this.postEvent("web_app_set_header_color", lt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1634
1754
  }
1635
1755
  /**
1636
1756
  * Updates current Mini App background color.
@@ -1658,32 +1778,86 @@ class $e {
1658
1778
  });
1659
1779
  }
1660
1780
  }
1661
- function Ve(r, t, e, n, s) {
1781
+ function Be(r, t, e, s, n, i) {
1662
1782
  const {
1663
- backgroundColor: i = t,
1664
- headerColor: a = "bg_color"
1665
- } = r ? W("mini-app") || {} : {}, c = new $e({
1666
- headerColor: a,
1667
- backgroundColor: i,
1783
+ backgroundColor: a = t,
1784
+ headerColor: c = "bg_color"
1785
+ } = r ? $("mini-app") || {} : {}, u = new Te({
1786
+ headerColor: c,
1787
+ backgroundColor: a,
1668
1788
  version: e,
1669
- botInline: n,
1670
- postEvent: s
1671
- }), u = () => O("mini-app", {
1672
- backgroundColor: c.backgroundColor,
1673
- headerColor: c.headerColor
1789
+ botInline: s,
1790
+ createRequestId: n,
1791
+ postEvent: i
1792
+ }), p = () => L("mini-app", {
1793
+ backgroundColor: u.backgroundColor,
1794
+ headerColor: u.headerColor
1674
1795
  });
1675
- return c.on("change", u), c;
1796
+ return u.on("change", p), u;
1676
1797
  }
1677
- function Te() {
1798
+ function De() {
1678
1799
  let r = 0;
1679
1800
  return () => (r += 1, r.toString());
1680
1801
  }
1681
- function Ie(r) {
1682
- const t = new jt(r);
1802
+ class We {
1803
+ constructor(t, e, s = f) {
1804
+ o(this, "ee", new w());
1805
+ o(this, "state");
1806
+ /**
1807
+ * Adds event listener.
1808
+ * @param event - event name.
1809
+ * @param listener - event listener.
1810
+ */
1811
+ o(this, "on", (t, e) => t === "click" ? y("settings_button_pressed", e) : this.ee.on(t, e));
1812
+ /**
1813
+ * Removes event listener.
1814
+ * @param event - event name.
1815
+ * @param listener - event listener.
1816
+ */
1817
+ o(this, "off", (t, e) => t === "click" ? I("settings_button_pressed", e) : this.ee.off(t, e));
1818
+ /**
1819
+ * Checks if specified method is supported by current component.
1820
+ */
1821
+ o(this, "supports");
1822
+ this.postEvent = s, this.state = new _({ isVisible: t }, this.ee), this.supports = E(e, {
1823
+ show: "web_app_setup_settings_button",
1824
+ hide: "web_app_setup_settings_button"
1825
+ });
1826
+ }
1827
+ set isVisible(t) {
1828
+ this.state.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
1829
+ }
1830
+ /**
1831
+ * True if SettingsButton is currently visible.
1832
+ */
1833
+ get isVisible() {
1834
+ return this.state.get("isVisible");
1835
+ }
1836
+ /**
1837
+ * Hides the SettingsButton.
1838
+ */
1839
+ hide() {
1840
+ this.isVisible = !1;
1841
+ }
1842
+ /**
1843
+ * Shows the SettingsButton.
1844
+ */
1845
+ show() {
1846
+ this.isVisible = !0;
1847
+ }
1848
+ }
1849
+ function Ne(r, t, e) {
1850
+ const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new We(s, t, e);
1851
+ return n.on("change", () => {
1852
+ L("settings-button", { isVisible: n.isVisible });
1853
+ }), n;
1854
+ }
1855
+ function Oe(r) {
1856
+ const t = new Ft(r);
1683
1857
  return t.listen(), t;
1684
1858
  }
1685
- async function Pt(r) {
1686
- const t = await _("web_app_request_viewport", "viewport_changed", r);
1859
+ async function At(r) {
1860
+ const t = await m("web_app_request_viewport", "viewport_changed", r);
1687
1861
  return {
1688
1862
  height: t.height,
1689
1863
  width: t.width,
@@ -1691,10 +1865,10 @@ async function Pt(r) {
1691
1865
  isStateStable: t.is_state_stable
1692
1866
  };
1693
1867
  }
1694
- function I(r) {
1868
+ function D(r) {
1695
1869
  return r < 0 ? 0 : r;
1696
1870
  }
1697
- class j {
1871
+ class G {
1698
1872
  constructor(t) {
1699
1873
  o(this, "ee", new w());
1700
1874
  o(this, "state");
@@ -1709,16 +1883,16 @@ class j {
1709
1883
  o(this, "off", this.ee.off.bind(this.ee));
1710
1884
  const {
1711
1885
  height: e,
1712
- isExpanded: n,
1713
- width: s,
1886
+ isExpanded: s,
1887
+ width: n,
1714
1888
  stableHeight: i,
1715
1889
  postEvent: a = f
1716
1890
  } = t;
1717
- this.postEvent = a, this.state = new b({
1718
- height: I(e),
1719
- isExpanded: n,
1720
- stableHeight: I(i),
1721
- width: I(s)
1891
+ this.postEvent = a, this.state = new _({
1892
+ height: D(e),
1893
+ isExpanded: s,
1894
+ stableHeight: D(i),
1895
+ width: D(n)
1722
1896
  }, this.ee);
1723
1897
  }
1724
1898
  /**
@@ -1727,11 +1901,11 @@ class j {
1727
1901
  * @param options - options to request fresh data.
1728
1902
  */
1729
1903
  sync(t) {
1730
- return Pt(t).then(({ height: e, isExpanded: n, width: s, isStateStable: i }) => {
1904
+ return At(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
1731
1905
  this.state.set({
1732
1906
  height: e,
1733
- width: s,
1734
- isExpanded: n,
1907
+ width: n,
1908
+ isExpanded: s,
1735
1909
  stableHeight: i ? e : this.state.get("stableHeight")
1736
1910
  });
1737
1911
  });
@@ -1777,16 +1951,16 @@ class j {
1777
1951
  * @returns Function to stop listening.
1778
1952
  */
1779
1953
  listen() {
1780
- return k("viewport_changed", (t) => {
1954
+ return y("viewport_changed", (t) => {
1781
1955
  const {
1782
1956
  height: e,
1783
- width: n,
1784
- is_expanded: s,
1957
+ width: s,
1958
+ is_expanded: n,
1785
1959
  is_state_stable: i
1786
1960
  } = t, a = {
1787
- height: I(e),
1788
- isExpanded: s,
1789
- width: I(n)
1961
+ height: D(e),
1962
+ isExpanded: n,
1963
+ width: D(s)
1790
1964
  };
1791
1965
  i && (a.stableHeight = a.height), this.state.set(a);
1792
1966
  });
@@ -1823,29 +1997,32 @@ class j {
1823
1997
  return this.stableHeight === this.height;
1824
1998
  }
1825
1999
  }
1826
- function At(r, t, e) {
1827
- if (r || t === "macos" || t === "web" || t === "weba")
1828
- return new j({
2000
+ function Rt(r) {
2001
+ return !["macos", "web", "weba"].includes(r);
2002
+ }
2003
+ function Vt(r, t, e) {
2004
+ if (r || !Rt(t))
2005
+ return new G({
1829
2006
  height: window.innerHeight,
1830
2007
  isExpanded: !0,
1831
2008
  postEvent: e,
1832
2009
  stableHeight: window.innerHeight,
1833
2010
  width: window.innerWidth
1834
2011
  });
1835
- const n = W("viewport");
1836
- return n ? new j({ ...n, postEvent: e }) : null;
2012
+ const s = $("viewport");
2013
+ return s ? new G({ ...s, postEvent: e }) : null;
1837
2014
  }
1838
- function qt(r) {
1839
- return r.listen(), r.on("change", () => O("viewport", {
2015
+ function It(r) {
2016
+ return r.listen(), r.on("change", () => L("viewport", {
1840
2017
  height: r.height,
1841
2018
  isExpanded: r.isExpanded,
1842
2019
  stableHeight: r.stableHeight,
1843
2020
  width: r.width
1844
2021
  })), r;
1845
2022
  }
1846
- function Re(r, t, e) {
1847
- const n = qt(
1848
- At(r, t, e) || new j({
2023
+ function He(r, t, e) {
2024
+ const s = It(
2025
+ Vt(r, t, e) || new G({
1849
2026
  width: 0,
1850
2027
  height: 0,
1851
2028
  isExpanded: !1,
@@ -1853,71 +2030,71 @@ function Re(r, t, e) {
1853
2030
  stableHeight: 0
1854
2031
  })
1855
2032
  );
1856
- return n.sync({ postEvent: e, timeout: 100 }).catch((s) => {
1857
- console.error("Unable to actualize viewport state", s);
1858
- }), n;
2033
+ return Rt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
2034
+ console.error("Unable to actualize viewport state", n);
2035
+ }), s;
1859
2036
  }
1860
- async function Be(r, t, e) {
1861
- return qt(
1862
- At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: n, isStateStable: s, ...i }) => new j({
2037
+ async function Ue(r, t, e) {
2038
+ return It(
2039
+ Vt(r, t, e) || await At({ postEvent: e, timeout: 100 }).then(({ height: s, isStateStable: n, ...i }) => new G({
1863
2040
  ...i,
1864
- height: n,
1865
- stableHeight: s ? n : 0
2041
+ height: s,
2042
+ stableHeight: n ? s : 0
1866
2043
  }))
1867
2044
  );
1868
2045
  }
1869
- function v(r, t) {
2046
+ function S(r, t) {
1870
2047
  document.documentElement.style.setProperty(r, t);
1871
2048
  }
1872
- function De(r, t) {
2049
+ function Me(r, t) {
1873
2050
  const e = () => {
1874
- v("--tg-background-color", r.backgroundColor);
1875
- }, n = () => {
2051
+ S("--tg-background-color", r.backgroundColor);
2052
+ }, s = () => {
1876
2053
  const {
1877
- backgroundColor: s,
2054
+ backgroundColor: n,
1878
2055
  secondaryBackgroundColor: i
1879
2056
  } = t;
1880
- r.headerColor === "bg_color" ? s && v("--tg-header-color", s) : r.headerColor === "secondary_bg_color" ? i && v("--tg-header-color", i) : v("--tg-header-color", r.headerColor);
2057
+ r.headerColor === "bg_color" ? n && S("--tg-header-color", n) : r.headerColor === "secondary_bg_color" ? i && S("--tg-header-color", i) : S("--tg-header-color", r.headerColor);
1881
2058
  };
1882
- t.on("change", n), r.on("change:backgroundColor", e), r.on("change:headerColor", n), e(), n();
2059
+ t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
1883
2060
  }
1884
- function He(r) {
2061
+ function je(r) {
1885
2062
  const t = () => {
1886
2063
  const e = r.getState();
1887
- Object.entries(e).forEach(([n, s]) => {
1888
- if (s) {
1889
- const i = n.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
1890
- v(`--tg-theme-${i}`, s);
2064
+ Object.entries(e).forEach(([s, n]) => {
2065
+ if (n) {
2066
+ const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
2067
+ S(`--tg-theme-${i}`, n);
1891
2068
  }
1892
2069
  });
1893
2070
  };
1894
2071
  r.on("change", t), t();
1895
2072
  }
1896
- function it(r) {
1897
- const t = () => v("--tg-viewport-height", `${r.height}px`), e = () => v("--tg-viewport-width", `${r.width}px`), n = () => v("--tg-viewport-height", `${r.stableHeight}px`);
1898
- r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", n), t(), e(), n();
2073
+ function ot(r) {
2074
+ const t = () => S("--tg-viewport-height", `${r.height}px`), e = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-height", `${r.stableHeight}px`);
2075
+ r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
1899
2076
  }
1900
- function Ne(r) {
2077
+ function Ge(r) {
1901
2078
  return typeof r == "object" ? r : r ? {
1902
2079
  themeParams: !0,
1903
2080
  viewport: !0,
1904
2081
  miniApp: !0
1905
2082
  } : {};
1906
2083
  }
1907
- function ot(r, t, e, n) {
1908
- const s = Ne(r);
1909
- s.miniApp && De(t, e), s.themeParams && He(e), s.viewport && (n instanceof Promise ? n.then(it) : it(n));
2084
+ function at(r, t, e, s) {
2085
+ const n = Ge(r);
2086
+ n.miniApp && Me(t, e), n.themeParams && je(e), n.viewport && (s instanceof Promise ? s.then(ot) : ot(s));
1910
2087
  }
1911
- function Oe(r) {
2088
+ function Fe(r) {
1912
2089
  const { hostname: t, pathname: e } = new URL(r, window.location.href);
1913
2090
  if (t !== "t.me")
1914
2091
  throw new Error(`Incorrect hostname: ${t}`);
1915
- const n = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1916
- if (n === null)
2092
+ const s = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
2093
+ if (s === null)
1917
2094
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1918
- return n[2];
2095
+ return s[2];
1919
2096
  }
1920
- class We {
2097
+ class ze {
1921
2098
  constructor(t, e = f) {
1922
2099
  o(this, "ee", new w());
1923
2100
  o(this, "state");
@@ -1933,7 +2110,7 @@ class We {
1933
2110
  * Checks if specified method is supported by current component.
1934
2111
  */
1935
2112
  o(this, "supports");
1936
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, { open: "web_app_open_invoice" });
2113
+ this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, { open: "web_app_open_invoice" });
1937
2114
  }
1938
2115
  set isOpened(t) {
1939
2116
  this.state.set("isOpened", t);
@@ -1947,17 +2124,17 @@ class We {
1947
2124
  async open(t, e) {
1948
2125
  if (this.isOpened)
1949
2126
  throw new Error("Invoice is already opened");
1950
- const n = e ? Oe(t) : t;
2127
+ const s = e ? Fe(t) : t;
1951
2128
  this.isOpened = !0;
1952
2129
  try {
1953
- return (await _(
2130
+ return (await m(
1954
2131
  "web_app_open_invoice",
1955
- { slug: n },
2132
+ { slug: s },
1956
2133
  "invoice_closed",
1957
2134
  {
1958
2135
  postEvent: this.postEvent,
1959
2136
  capture(i) {
1960
- return n === i.slug;
2137
+ return s === i.slug;
1961
2138
  }
1962
2139
  }
1963
2140
  )).status;
@@ -1966,16 +2143,16 @@ class We {
1966
2143
  }
1967
2144
  }
1968
2145
  }
1969
- function Me(r) {
1970
- const t = r.message.trim(), e = (r.title || "").trim(), n = r.buttons || [];
1971
- let s;
2146
+ function Je(r) {
2147
+ const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
2148
+ let n;
1972
2149
  if (e.length > 64)
1973
2150
  throw new Error(`Title has incorrect size: ${e.length}`);
1974
2151
  if (t.length === 0 || t.length > 256)
1975
2152
  throw new Error(`Message has incorrect size: ${t.length}`);
1976
- if (n.length > 3)
1977
- throw new Error(`Buttons have incorrect size: ${n.length}`);
1978
- return n.length === 0 ? s = [{ type: "close", id: "" }] : s = n.map((i) => {
2153
+ if (s.length > 3)
2154
+ throw new Error(`Buttons have incorrect size: ${s.length}`);
2155
+ return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
1979
2156
  const { id: a = "" } = i;
1980
2157
  if (a.length > 64)
1981
2158
  throw new Error(`Button ID has incorrect size: ${a}`);
@@ -1988,9 +2165,9 @@ function Me(r) {
1988
2165
  return { ...i, text: c, id: a };
1989
2166
  }
1990
2167
  return { ...i, id: a };
1991
- }), { title: e, message: t, buttons: s };
2168
+ }), { title: e, message: t, buttons: n };
1992
2169
  }
1993
- class Ue {
2170
+ class Qe {
1994
2171
  constructor(t, e = f) {
1995
2172
  o(this, "ee", new w());
1996
2173
  o(this, "state");
@@ -2006,7 +2183,7 @@ class Ue {
2006
2183
  * Checks if specified method is supported by current component.
2007
2184
  */
2008
2185
  o(this, "supports");
2009
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, { open: "web_app_open_popup" });
2186
+ this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, { open: "web_app_open_popup" });
2010
2187
  }
2011
2188
  set isOpened(t) {
2012
2189
  this.state.set("isOpened", t);
@@ -2033,9 +2210,9 @@ class Ue {
2033
2210
  open(t) {
2034
2211
  if (this.isOpened)
2035
2212
  throw new Error("Popup is already opened.");
2036
- return this.isOpened = !0, _(
2213
+ return this.isOpened = !0, m(
2037
2214
  "web_app_open_popup",
2038
- Me(t),
2215
+ Je(t),
2039
2216
  "popup_closed",
2040
2217
  { postEvent: this.postEvent }
2041
2218
  ).then(({ button_id: e = null }) => e).finally(() => {
@@ -2043,7 +2220,7 @@ class Ue {
2043
2220
  });
2044
2221
  }
2045
2222
  }
2046
- class je {
2223
+ class Ze {
2047
2224
  constructor(t, e = f) {
2048
2225
  o(this, "ee", new w());
2049
2226
  o(this, "state");
@@ -2059,7 +2236,7 @@ class je {
2059
2236
  * Checks if specified method is supported by current component.
2060
2237
  */
2061
2238
  o(this, "supports");
2062
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, {
2239
+ this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, {
2063
2240
  close: "web_app_close_scan_qr_popup",
2064
2241
  open: "web_app_open_scan_qr_popup"
2065
2242
  });
@@ -2090,7 +2267,7 @@ class je {
2090
2267
  throw new Error("QR scanner is already opened.");
2091
2268
  this.isOpened = !0;
2092
2269
  try {
2093
- const e = await _(
2270
+ const e = await m(
2094
2271
  "web_app_open_scan_qr_popup",
2095
2272
  { text: t },
2096
2273
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -2102,8 +2279,8 @@ class je {
2102
2279
  }
2103
2280
  }
2104
2281
  }
2105
- class Ge {
2106
- constructor(t, e, n = f) {
2282
+ class Ke {
2283
+ constructor(t, e, s = f) {
2107
2284
  /**
2108
2285
  * Checks if specified method is supported by current component.
2109
2286
  */
@@ -2112,9 +2289,9 @@ class Ge {
2112
2289
  * Checks if specified method parameter is supported by current component.
2113
2290
  */
2114
2291
  o(this, "supportsParam");
2115
- this.version = t, this.createRequestId = e, this.postEvent = n, this.supports = S(t, {
2292
+ this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = E(t, {
2116
2293
  readTextFromClipboard: "web_app_read_text_from_clipboard"
2117
- }), this.supportsParam = St(t, {
2294
+ }), this.supportsParam = kt(t, {
2118
2295
  "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
2119
2296
  });
2120
2297
  }
@@ -2128,13 +2305,13 @@ class Ge {
2128
2305
  * @param tryInstantView
2129
2306
  */
2130
2307
  openLink(t, e) {
2131
- const n = new URL(t, window.location.href).toString();
2132
- if (!q("web_app_open_link", this.version)) {
2133
- window.open(n, "_blank");
2308
+ const s = new URL(t, window.location.href).toString();
2309
+ if (!A("web_app_open_link", this.version)) {
2310
+ window.open(s, "_blank");
2134
2311
  return;
2135
2312
  }
2136
2313
  this.postEvent("web_app_open_link", {
2137
- url: n,
2314
+ url: s,
2138
2315
  ...typeof e == "boolean" ? { try_instant_view: e } : {}
2139
2316
  });
2140
2317
  }
@@ -2147,16 +2324,16 @@ class Ge {
2147
2324
  openTelegramLink(t) {
2148
2325
  const {
2149
2326
  hostname: e,
2150
- pathname: n,
2151
- search: s
2327
+ pathname: s,
2328
+ search: n
2152
2329
  } = new URL(t, window.location.href);
2153
2330
  if (e !== "t.me")
2154
2331
  throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
2155
- if (!q("web_app_open_tg_link", this.version)) {
2332
+ if (!A("web_app_open_tg_link", this.version)) {
2156
2333
  window.location.href = t;
2157
2334
  return;
2158
2335
  }
2159
- this.postEvent("web_app_open_tg_link", { path_full: n + s });
2336
+ this.postEvent("web_app_open_tg_link", { path_full: s + n });
2160
2337
  }
2161
2338
  /**
2162
2339
  * Reads text from clipboard and returns string or null. null is returned
@@ -2165,7 +2342,7 @@ class Ge {
2165
2342
  * - Access to clipboard is not allowed
2166
2343
  */
2167
2344
  readTextFromClipboard() {
2168
- return _(
2345
+ return m(
2169
2346
  "web_app_read_text_from_clipboard",
2170
2347
  { req_id: this.createRequestId() },
2171
2348
  "clipboard_text_received",
@@ -2173,83 +2350,85 @@ class Ge {
2173
2350
  ).then(({ data: t = null }) => t);
2174
2351
  }
2175
2352
  }
2176
- function nr(r) {
2353
+ function ur(r = {}) {
2177
2354
  const {
2178
2355
  async: t = !1,
2179
2356
  cssVars: e = !1,
2180
- acceptCustomStyles: n = !1
2357
+ acceptCustomStyles: s = !1
2181
2358
  } = r;
2182
2359
  try {
2183
2360
  const {
2184
2361
  launchParams: {
2185
- initData: s,
2362
+ initData: n,
2186
2363
  initDataRaw: i,
2187
2364
  version: a,
2188
2365
  platform: c,
2189
2366
  themeParams: u,
2190
- botInline: l = !1
2367
+ botInline: p = !1
2191
2368
  },
2192
- isPageReload: p
2193
- } = Et(), m = Te(), d = be(a);
2194
- Ct() && (n && xe(), d("iframe_ready", { reload_supported: !0 }), k("reload_iframe", () => window.location.reload()));
2195
- const y = {
2196
- backButton: Pe(p, a, d),
2197
- closingBehavior: Ae(p, d),
2198
- cloudStorage: new ke(a, m, d),
2199
- createRequestId: m,
2200
- hapticFeedback: new Se(a, d),
2201
- invoice: new We(a, d),
2369
+ isPageReload: l
2370
+ } = Ct(), b = De(), d = ye(a);
2371
+ vt() && (s && Ae(), d("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => window.location.reload()));
2372
+ const C = {
2373
+ backButton: Re(l, a, d),
2374
+ closingBehavior: Ve(l, d),
2375
+ cloudStorage: new xe(a, b, d),
2376
+ createRequestId: b,
2377
+ hapticFeedback: new qe(a, d),
2378
+ invoice: new ze(a, d),
2202
2379
  mainButton: Le(
2203
- p,
2380
+ l,
2204
2381
  u.buttonColor || "#000000",
2205
2382
  u.buttonTextColor || "#ffffff",
2206
2383
  d
2207
2384
  ),
2208
- miniApp: Ve(
2209
- p,
2385
+ miniApp: Be(
2386
+ l,
2210
2387
  u.backgroundColor || "#ffffff",
2211
2388
  a,
2212
- l,
2389
+ p,
2390
+ b,
2213
2391
  d
2214
2392
  ),
2215
- popup: new Ue(a, d),
2393
+ popup: new Qe(a, d),
2216
2394
  postEvent: d,
2217
- qrScanner: new je(a, d),
2218
- themeParams: Ie(u),
2219
- utils: new Ge(a, m, d),
2220
- ...s ? {
2221
- initData: new Ot(s),
2395
+ qrScanner: new Ze(a, d),
2396
+ settingsButton: Ne(l, a, d),
2397
+ themeParams: Oe(u),
2398
+ utils: new Ke(a, b, d),
2399
+ ...n ? {
2400
+ initData: new Ut(n),
2222
2401
  initDataRaw: i
2223
2402
  } : {}
2224
- }, x = t ? Be(p, c, d) : Re(p, c, d);
2225
- return x instanceof Promise ? x.then((V) => (ot(
2403
+ }, x = t ? Ue(l, c, d) : He(l, c, d);
2404
+ return x instanceof Promise ? x.then((T) => (at(
2226
2405
  e,
2227
- y.miniApp,
2228
- y.themeParams,
2229
- V
2406
+ C.miniApp,
2407
+ C.themeParams,
2408
+ T
2230
2409
  ), {
2231
- ...y,
2232
- viewport: V
2233
- })) : (ot(
2410
+ ...C,
2411
+ viewport: T
2412
+ })) : (at(
2234
2413
  e,
2235
- y.miniApp,
2236
- y.themeParams,
2414
+ C.miniApp,
2415
+ C.themeParams,
2237
2416
  x
2238
- ), { ...y, viewport: x });
2239
- } catch (s) {
2417
+ ), { ...C, viewport: x });
2418
+ } catch (n) {
2240
2419
  if (t)
2241
- return Promise.reject(s);
2242
- throw s;
2420
+ return Promise.reject(n);
2421
+ throw n;
2243
2422
  }
2244
2423
  }
2245
- function R(r, t) {
2424
+ function W(r, t) {
2246
2425
  return r.startsWith(t) ? r : `${t}${r}`;
2247
2426
  }
2248
- function sr(r) {
2427
+ function pr(r) {
2249
2428
  const t = r.match(/#(.+)/);
2250
2429
  return t ? t[1] : null;
2251
2430
  }
2252
- async function B(r) {
2431
+ async function O(r) {
2253
2432
  return r === 0 ? !0 : Promise.race([
2254
2433
  new Promise((t) => {
2255
2434
  window.addEventListener("popstate", function e() {
@@ -2262,17 +2441,17 @@ async function B(r) {
2262
2441
  })
2263
2442
  ]);
2264
2443
  }
2265
- async function Fe() {
2266
- if (window.history.length <= 1 || (window.history.pushState(null, ""), await B(1 - window.history.length)))
2444
+ async function Ye() {
2445
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await O(1 - window.history.length)))
2267
2446
  return;
2268
- let t = await B(-1);
2447
+ let t = await O(-1);
2269
2448
  for (; t; )
2270
- t = await B(-1);
2449
+ t = await O(-1);
2271
2450
  }
2272
- class ze {
2451
+ class Xe {
2273
2452
  constructor(t, e, {
2274
- debug: n = !1,
2275
- loggerPrefix: s = "Navigator"
2453
+ debug: s = !1,
2454
+ loggerPrefix: n = "Navigator"
2276
2455
  }) {
2277
2456
  o(this, "logger");
2278
2457
  o(this, "entries");
@@ -2284,11 +2463,11 @@ class ze {
2284
2463
  if (!i.startsWith("/") && i.length > 0)
2285
2464
  throw new Error('Pathname should start with "/"');
2286
2465
  return {
2287
- pathname: R(i, "/"),
2288
- search: a ? R(a, "?") : "",
2289
- hash: c ? R(c, "#") : ""
2466
+ pathname: W(i, "/"),
2467
+ search: a ? W(a, "?") : "",
2468
+ hash: c ? W(c, "#") : ""
2290
2469
  };
2291
- }), this.logger = new vt(`[${s}]`, n);
2470
+ }), this.logger = new Pt(`[${n}]`, s);
2292
2471
  }
2293
2472
  /**
2294
2473
  * Converts entry to the navigation entry.
@@ -2304,16 +2483,16 @@ class ze {
2304
2483
  search: c,
2305
2484
  hash: u
2306
2485
  } = t;
2307
- e = a + (c ? R(c, "?") : "") + (u ? R(u, "#") : "");
2486
+ e = a + (c ? W(c, "?") : "") + (u ? W(u, "#") : "");
2308
2487
  }
2309
2488
  const {
2310
- pathname: n,
2311
- search: s,
2489
+ pathname: s,
2490
+ search: n,
2312
2491
  hash: i
2313
2492
  } = new URL(e, `https://localhost${this.path}`);
2314
2493
  return {
2315
- pathname: n,
2316
- search: s,
2494
+ pathname: s,
2495
+ search: n,
2317
2496
  hash: i
2318
2497
  };
2319
2498
  }
@@ -2368,14 +2547,14 @@ class ze {
2368
2547
  updated: !1,
2369
2548
  delta: t
2370
2549
  });
2371
- const n = this.entry;
2372
- this.entriesCursor = e;
2373
2550
  const s = this.entry;
2374
- return this.logger.log("State changed", { before: n, after: s }), this.performGo({
2551
+ this.entriesCursor = e;
2552
+ const n = this.entry;
2553
+ return this.logger.log("State changed", { before: s, after: n }), this.performGo({
2375
2554
  updated: !0,
2376
2555
  delta: t,
2377
- before: n,
2378
- after: s
2556
+ before: s,
2557
+ after: n
2379
2558
  });
2380
2559
  }
2381
2560
  /**
@@ -2415,12 +2594,12 @@ class ze {
2415
2594
  */
2416
2595
  push(t) {
2417
2596
  this.entriesCursor !== this.entries.length - 1 && this.entries.splice(this.entriesCursor + 1);
2418
- const e = this.formatEntry(t), n = this.entry;
2597
+ const e = this.formatEntry(t), s = this.entry;
2419
2598
  this.entriesCursor += 1, this.entries[this.entriesCursor] = e;
2420
- const s = this.entry;
2421
- return this.logger.log("State changed", { before: n, after: s }), this.performPush({
2422
- before: n,
2423
- after: s
2599
+ const n = this.entry;
2600
+ return this.logger.log("State changed", { before: s, after: n }), this.performPush({
2601
+ before: s,
2602
+ after: n
2424
2603
  });
2425
2604
  }
2426
2605
  /**
@@ -2450,13 +2629,13 @@ class ze {
2450
2629
  updated: !1,
2451
2630
  entry: e
2452
2631
  });
2453
- const n = this.entry;
2454
- this.entries[this.entriesCursor] = e;
2455
2632
  const s = this.entry;
2456
- return this.logger.log("State changed", { before: n, after: s }), this.performReplace({
2633
+ this.entries[this.entriesCursor] = e;
2634
+ const n = this.entry;
2635
+ return this.logger.log("State changed", { before: s, after: n }), this.performReplace({
2457
2636
  updated: !0,
2458
- before: n,
2459
- after: s
2637
+ before: s,
2638
+ after: n
2460
2639
  });
2461
2640
  }
2462
2641
  /**
@@ -2468,11 +2647,11 @@ class ze {
2468
2647
  return this.entry.search;
2469
2648
  }
2470
2649
  }
2471
- const at = 0, J = 1, Q = 2;
2472
- class Lt extends ze {
2473
- constructor(e, n, s = {}) {
2474
- super(e, n, {
2475
- ...s,
2650
+ const ct = 0, Z = 1, K = 2;
2651
+ class Lt extends Xe {
2652
+ constructor(e, s, n = {}) {
2653
+ super(e, s, {
2654
+ ...n,
2476
2655
  loggerPrefix: "HashNavigator"
2477
2656
  });
2478
2657
  o(this, "ee", new w());
@@ -2484,13 +2663,13 @@ class Lt extends ze {
2484
2663
  o(this, "onPopState", async ({ state: e }) => {
2485
2664
  if (this.logger.log('"popstate" event received. State:', e), e === null)
2486
2665
  return this.push(window.location.hash.slice(1));
2487
- if (e === at) {
2666
+ if (e === ct) {
2488
2667
  this.logger.log("Void reached. Moving history forward"), window.history.forward();
2489
2668
  return;
2490
2669
  }
2491
- if (e === J)
2670
+ if (e === Z)
2492
2671
  return this.back();
2493
- if (e === Q)
2672
+ if (e === K)
2494
2673
  return this.forward();
2495
2674
  });
2496
2675
  o(this, "back", () => super.back());
@@ -2509,20 +2688,20 @@ class Lt extends ze {
2509
2688
  */
2510
2689
  static fromLocation(e) {
2511
2690
  const {
2512
- search: n,
2513
- pathname: s,
2691
+ search: s,
2692
+ pathname: n,
2514
2693
  hash: i
2515
2694
  } = new URL(
2516
2695
  window.location.hash.slice(1),
2517
2696
  window.location.href
2518
2697
  );
2519
- return new Lt([{ search: n, pathname: s, hash: i }], 0, e);
2698
+ return new Lt([{ search: s, pathname: n, hash: i }], 0, e);
2520
2699
  }
2521
2700
  async performGo(e) {
2522
2701
  e.updated && (this.attached && await this.syncHistory(), this.emitChanged(e.before, e.after));
2523
2702
  }
2524
- async performPush({ before: e, after: n }) {
2525
- this.attached && await this.syncHistory(), this.emitChanged(e, n);
2703
+ async performPush({ before: e, after: s }) {
2704
+ this.attached && await this.syncHistory(), this.emitChanged(e, s);
2526
2705
  }
2527
2706
  async performReplace(e) {
2528
2707
  e.updated && (this.attached && window.history.replaceState(null, "", `#${this.path}`), this.emitChanged(e.before, e.after));
@@ -2533,13 +2712,13 @@ class Lt extends ze {
2533
2712
  async syncHistory() {
2534
2713
  window.removeEventListener("popstate", this.onPopState);
2535
2714
  const e = `#${this.path}`;
2536
- await Fe(), f("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e), window.history.pushState(Q, ""), await B(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(Q, ""), await B(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(at, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
2715
+ await Ye(), f("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e), window.history.pushState(K, ""), await O(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(K, ""), await O(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ct, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
2537
2716
  }
2538
- emitChanged(e, n) {
2717
+ emitChanged(e, s) {
2539
2718
  this.ee.emit("change", {
2540
2719
  navigator: this,
2541
2720
  from: e,
2542
- to: n
2721
+ to: s
2543
2722
  });
2544
2723
  }
2545
2724
  /**
@@ -2547,68 +2726,73 @@ class Lt extends ze {
2547
2726
  */
2548
2727
  async attach() {
2549
2728
  if (!this.attached)
2550
- return this.logger.log("Attaching", this), this.attached = !0, k("back_button_pressed", this.back), this.syncHistory();
2729
+ return this.logger.log("Attaching", this), this.attached = !0, y("back_button_pressed", this.back), this.syncHistory();
2551
2730
  }
2552
2731
  /**
2553
2732
  * Detaches current navigator from the browser history.
2554
2733
  */
2555
2734
  detach() {
2556
- this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), N("back_button_pressed", this.back));
2735
+ this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), I("back_button_pressed", this.back));
2557
2736
  }
2558
2737
  }
2559
2738
  export {
2560
- ye as BackButton,
2561
- ve as ClosingBehavior,
2562
- ke as CloudStorage,
2563
- Se as HapticFeedback,
2739
+ ve as BackButton,
2740
+ ke as ClosingBehavior,
2741
+ xe as CloudStorage,
2742
+ qe as HapticFeedback,
2564
2743
  Lt as HashNavigator,
2565
- Ot as InitData,
2566
- We as Invoice,
2567
- qe as MainButton,
2568
- K as MethodUnsupportedError,
2569
- $e as MiniApp,
2570
- ze as Navigator,
2571
- Y as ParameterUnsupportedError,
2572
- Ue as Popup,
2573
- je as QRScanner,
2574
- jt as ThemeParams,
2575
- Ge as Utils,
2576
- j as Viewport,
2577
- Nt as chatParser,
2578
- Ee as classNames,
2579
- _e as compareVersions,
2580
- be as createPostEvent,
2581
- sr as getHash,
2582
- nr as init,
2583
- gt as initDataParser,
2584
- lt as isColorDark,
2585
- Ct as isIframe,
2586
- ut as isRGB,
2587
- Ht as isRGBShort,
2588
- D as isRecord,
2589
- Ke as isTMA,
2590
- bt as launchParamsParser,
2591
- rr as mergeClassNames,
2592
- N as off,
2593
- k as on,
2594
- tr as once,
2595
- Qe as parseInitData,
2596
- mt as parseLaunchParams,
2597
- _t as parseThemeParams,
2744
+ Ut as InitData,
2745
+ ze as Invoice,
2746
+ Ie as MainButton,
2747
+ tt as MethodUnsupportedError,
2748
+ Te as MiniApp,
2749
+ Xe as Navigator,
2750
+ et as ParameterUnsupportedError,
2751
+ Qe as Popup,
2752
+ Ze as QRScanner,
2753
+ We as SettingsButton,
2754
+ Ft as ThemeParams,
2755
+ J as TimeoutError,
2756
+ Ke as Utils,
2757
+ G as Viewport,
2758
+ Ht as chatParser,
2759
+ Pe as classNames,
2760
+ me as compareVersions,
2761
+ ye as createPostEvent,
2762
+ pr as getHash,
2763
+ ur as init,
2764
+ wt as initDataParser,
2765
+ N as invokeCustomMethod,
2766
+ ft as isColorDark,
2767
+ vt as isIframe,
2768
+ lt as isRGB,
2769
+ Ot as isRGBShort,
2770
+ H as isRecord,
2771
+ sr as isTMA,
2772
+ cr as isTimeoutError,
2773
+ mt as launchParamsParser,
2774
+ hr as mergeClassNames,
2775
+ I as off,
2776
+ y as on,
2777
+ or as once,
2778
+ er as parseInitData,
2779
+ yt as parseLaunchParams,
2780
+ bt as parseThemeParams,
2598
2781
  f as postEvent,
2599
- _ as request,
2600
- Ze as requestThemeParams,
2601
- Pt as requestViewport,
2602
- Et as retrieveLaunchData,
2603
- Jt as serializeLaunchParams,
2604
- Ut as serializeThemeParams,
2605
- Ye as setDebug,
2606
- Xe as setTargetOrigin,
2607
- er as subscribe,
2608
- q as supports,
2609
- wt as themeParamsParser,
2610
- pt as toRGB,
2611
- we as unsubscribe,
2612
- tt as userParser
2782
+ m as request,
2783
+ rr as requestThemeParams,
2784
+ At as requestViewport,
2785
+ Ct as retrieveLaunchData,
2786
+ Zt as serializeLaunchParams,
2787
+ Gt as serializeThemeParams,
2788
+ nr as setDebug,
2789
+ ir as setTargetOrigin,
2790
+ ar as subscribe,
2791
+ A as supports,
2792
+ _t as themeParamsParser,
2793
+ dt as toRGB,
2794
+ be as unsubscribe,
2795
+ rt as userParser,
2796
+ xt as withTimeout
2613
2797
  };
2614
2798
  //# sourceMappingURL=index.mjs.map