@tma.js/sdk 1.1.0 → 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 (46) 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 +7 -6
  10. package/dist/dts/init/creators/createMiniApp.d.ts +3 -1
  11. package/dist/dts/mini-app/MiniApp.d.ts +34 -4
  12. package/dist/dts/mini-app/contactParser.d.ts +2 -0
  13. package/dist/dts/mini-app/types.d.ts +12 -0
  14. package/dist/dts/timeout/index.d.ts +1 -0
  15. package/dist/dts/timeout/sleep.d.ts +5 -0
  16. package/dist/dts/timeout/withTimeout.d.ts +5 -12
  17. package/dist/dts/types/index.d.ts +1 -0
  18. package/dist/dts/types/methods.d.ts +15 -0
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.iife.js +1 -1
  22. package/dist/index.iife.js.map +1 -1
  23. package/dist/index.mjs +610 -484
  24. package/dist/index.mjs.map +1 -1
  25. package/package.json +1 -1
  26. package/src/bridge/events/parsers/phoneRequested.ts +1 -1
  27. package/src/bridge/index.ts +1 -0
  28. package/src/bridge/invoke-custom-method.ts +56 -0
  29. package/src/bridge/methods/custom-methods.ts +68 -0
  30. package/src/bridge/methods/index.ts +1 -1
  31. package/src/bridge/methods/methods.ts +3 -5
  32. package/src/bridge/request.ts +35 -44
  33. package/src/cloud-storage/CloudStorage.ts +36 -53
  34. package/src/index.ts +8 -20
  35. package/src/init/creators/createMiniApp.ts +4 -0
  36. package/src/init/init.ts +1 -0
  37. package/src/mini-app/MiniApp.ts +131 -20
  38. package/src/mini-app/contactParser.ts +29 -0
  39. package/src/mini-app/types.ts +13 -0
  40. package/src/timeout/index.ts +1 -0
  41. package/src/timeout/sleep.ts +10 -0
  42. package/src/timeout/withTimeout.ts +10 -22
  43. package/src/types/index.ts +1 -0
  44. package/src/types/methods.ts +18 -0
  45. package/dist/dts/bridge/methods/invoke-custom-method.d.ts +0 -24
  46. package/src/bridge/methods/invoke-custom-method.ts +0 -25
package/dist/index.mjs CHANGED
@@ -1,30 +1,30 @@
1
1
  var $t = Object.defineProperty;
2
2
  var Tt = (r, t, e) => t in r ? $t(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var o = (r, t, e) => (Tt(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- function O(r) {
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 It() {
11
- const r = ct();
10
+ function Bt() {
11
+ const r = ht();
12
12
  return r ? r.type === "reload" : null;
13
13
  }
14
- function q() {
14
+ function R() {
15
15
  return new TypeError("Value has unexpected type");
16
16
  }
17
- class G extends Error {
17
+ class F extends Error {
18
18
  constructor(e, { cause: s, type: n } = {}) {
19
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 = n;
24
+ this.value = e, Object.setPrototypeOf(this, F.prototype), this.type = n;
25
25
  }
26
26
  }
27
- class F {
27
+ class z {
28
28
  constructor(t, e, s) {
29
29
  this.parser = t, this.isOptional = e, this.type = s;
30
30
  }
@@ -33,14 +33,14 @@ class F {
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 Rt(r) {
43
+ function Dt(r) {
44
44
  if (Array.isArray(r))
45
45
  return r;
46
46
  if (typeof r == "string")
@@ -50,11 +50,11 @@ function Rt(r) {
50
50
  return t;
51
51
  } catch {
52
52
  }
53
- throw q();
53
+ throw R();
54
54
  }
55
- class Bt extends F {
55
+ class Wt extends z {
56
56
  constructor(e, s, n) {
57
- super(Rt, 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
  }
@@ -66,15 +66,15 @@ class Bt extends F {
66
66
  return this.itemParser = typeof e == "function" ? e : e.parse.bind(e), this;
67
67
  }
68
68
  }
69
- function L(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 {
72
+ class j extends Error {
73
73
  constructor(t, { cause: e, type: s } = {}) {
74
- super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, U.prototype);
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
79
  for (const s in r) {
80
80
  const n = r[s];
@@ -84,27 +84,27 @@ function ht(r, t) {
84
84
  if (typeof n == "function" || "parse" in n)
85
85
  i = s, a = typeof n == "function" ? n : n.parse.bind(n);
86
86
  else {
87
- const { type: d } = n;
88
- i = n.from || s, a = typeof d == "function" ? d : d.parse.bind(d);
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 (d) {
95
- throw d instanceof G ? new U(i, {
96
- type: d.type,
97
- cause: d
98
- }) : new U(i, { cause: d });
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
100
  c !== void 0 && (e[s] = c);
101
101
  }
102
102
  return e;
103
103
  }
104
- function Dt(r) {
105
- return new Bt((t) => t, !1, r);
104
+ function Nt(r) {
105
+ return new Wt((t) => t, !1, r);
106
106
  }
107
- const k = L((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 k = L((r) => {
112
112
  return !0;
113
113
  if (t === "0" || t === "false")
114
114
  return !1;
115
- throw q();
116
- }, "boolean"), V = L((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,31 +121,31 @@ const k = L((r) => {
121
121
  if (!Number.isNaN(t))
122
122
  return t;
123
123
  }
124
- throw q();
125
- }, "number"), Ht = L((r) => r instanceof Date ? r : new Date(V().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 q();
129
+ throw R();
130
130
  return t;
131
131
  }
132
132
  function g(r, t) {
133
- return new F((e) => {
134
- const s = Z(e);
135
- return ht(r, (n) => s[n]);
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 Nt(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 (Nt(t)) {
148
+ if (Ot(t)) {
149
149
  let s = "#";
150
150
  for (let n = 0; n < 3; n += 1)
151
151
  s += t[1 + n].repeat(2);
@@ -159,8 +159,8 @@ function pt(r) {
159
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
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);
@@ -168,25 +168,25 @@ function lt(r) {
168
168
  }, 0)
169
169
  ) < 120;
170
170
  }
171
- const h = L((r) => {
171
+ const h = V((r) => {
172
172
  if (typeof r == "string" || typeof r == "number")
173
173
  return r.toString();
174
- throw q();
175
- }, "string"), dt = L((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 q();
179
+ throw R();
180
180
  const s = typeof e == "string" ? new URLSearchParams(e) : e;
181
- return ht(r, (n) => {
181
+ return ut(r, (n) => {
182
182
  const i = s.get(n);
183
183
  return i === null ? void 0 : i;
184
184
  });
185
185
  }, !1, t);
186
186
  }
187
- function Ot() {
187
+ function Ht() {
188
188
  return g({
189
- id: V(),
189
+ id: k(),
190
190
  type: h(),
191
191
  title: h(),
192
192
  photoUrl: {
@@ -196,7 +196,7 @@ function Ot() {
196
196
  username: h().optional()
197
197
  }, "Chat");
198
198
  }
199
- class Wt {
199
+ class Ut {
200
200
  constructor(t) {
201
201
  this.initData = t;
202
202
  }
@@ -269,27 +269,27 @@ class Wt {
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: k().optional(),
275
+ type: P().optional(),
276
276
  from: "added_to_attachment_menu"
277
277
  },
278
278
  allowsWriteToPm: {
279
- type: k().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: V(),
286
+ id: k(),
287
287
  isBot: {
288
- type: k().optional(),
288
+ type: P().optional(),
289
289
  from: "is_bot"
290
290
  },
291
291
  isPremium: {
292
- type: k().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: Ht(),
313
+ type: pt(),
314
314
  from: "auth_date"
315
315
  },
316
316
  canSendAfter: {
317
- type: V().optional(),
317
+ type: k().optional(),
318
318
  from: "can_send_after"
319
319
  },
320
- chat: Ot().optional(),
320
+ chat: Ht().optional(),
321
321
  chatInstance: {
322
322
  type: h().optional(),
323
323
  from: "chat_instance"
@@ -331,42 +331,42 @@ 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 Ye(r) {
343
- return gt().parse(r);
342
+ function er(r) {
343
+ return wt().parse(r);
344
344
  }
345
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 Ut(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 _t = L(
351
+ const _t = V(
352
352
  (r) => {
353
- const t = dt().optional();
354
- return Object.entries(Z(r)).reduce((e, [s, n]) => (e[Mt(s)] = t.parse(n), 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 wt(r) {
358
+ function bt(r) {
359
359
  return _t().parse(r);
360
360
  }
361
- function Xe(r = {}) {
362
- return b("web_app_request_theme", "theme_changed", r).then(wt);
361
+ function rr(r = {}) {
362
+ return m("web_app_request_theme", "theme_changed", r).then(bt);
363
363
  }
364
- function jt(r) {
364
+ function Gt(r) {
365
365
  return JSON.stringify(
366
- Object.entries(r).reduce((t, [e, s]) => (s && (t[Ut(e)] = s), t), {})
366
+ Object.entries(r).reduce((t, [e, s]) => (s && (t[jt(e)] = s), t), {})
367
367
  );
368
368
  }
369
- class _ {
369
+ class w {
370
370
  constructor() {
371
371
  o(this, "listeners", /* @__PURE__ */ new Map());
372
372
  o(this, "subscribeListeners", []);
@@ -448,7 +448,7 @@ class _ {
448
448
  }
449
449
  }
450
450
  }
451
- class w {
451
+ class _ {
452
452
  constructor(t, e) {
453
453
  this.state = t, this.ee = e;
454
454
  }
@@ -478,9 +478,9 @@ class w {
478
478
  return this.state[t];
479
479
  }
480
480
  }
481
- class Gt {
481
+ class Ft {
482
482
  constructor(t) {
483
- o(this, "ee", new _());
483
+ o(this, "ee", new w());
484
484
  o(this, "state");
485
485
  /**
486
486
  * Adds new event listener.
@@ -490,7 +490,7 @@ class Gt {
490
490
  * Removes event listener.
491
491
  */
492
492
  o(this, "off", this.ee.off.bind(this.ee));
493
- this.state = new w(t, this.ee);
493
+ this.state = new _(t, this.ee);
494
494
  }
495
495
  /**
496
496
  * @since v6.10
@@ -537,7 +537,7 @@ class Gt {
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 Gt {
562
562
  * @returns Function to stop listening.
563
563
  */
564
564
  listen() {
565
- return m("theme_changed", (t) => {
566
- this.state.set(wt(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 Gt {
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: k().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,7 +595,7 @@ function bt() {
595
595
  from: "tgWebAppPlatform"
596
596
  },
597
597
  showSettings: {
598
- type: k().optional(),
598
+ type: P().optional(),
599
599
  from: "tgWebAppShowSettings"
600
600
  },
601
601
  themeParams: {
@@ -608,33 +608,33 @@ function bt() {
608
608
  }
609
609
  }, "LaunchParams");
610
610
  }
611
- function mt(r) {
612
- return bt().parse(r);
613
- }
614
- function Ft() {
615
- return mt(window.location.hash.slice(1));
611
+ function yt(r) {
612
+ return mt().parse(r);
616
613
  }
617
614
  function zt() {
618
- const r = ct();
615
+ return yt(window.location.hash.slice(1));
616
+ }
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 Jt() {
626
+ function Qt() {
627
627
  try {
628
- return zt();
628
+ return Jt();
629
629
  } catch {
630
630
  }
631
631
  try {
632
- return Ft();
632
+ return zt();
633
633
  } catch {
634
634
  }
635
635
  return null;
636
636
  }
637
- function Qt(r) {
637
+ function Zt(r) {
638
638
  const {
639
639
  initDataRaw: t,
640
640
  themeParams: e,
@@ -643,30 +643,30 @@ function Qt(r) {
643
643
  showSettings: i,
644
644
  botInline: a
645
645
  } = r, c = new URLSearchParams();
646
- return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", s), c.set("tgWebAppThemeParams", jt(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();
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 Zt() {
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 Kt(r) {
654
- sessionStorage.setItem(yt, Qt(r));
653
+ function Yt(r) {
654
+ sessionStorage.setItem(Et, Zt(r));
655
655
  }
656
- function Yt() {
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 Xt() {
664
- const r = Zt(), t = Jt(), e = It();
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: Yt() ? 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 Xt() {
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 = Xt();
691
- return window[et] = t, Kt(t.launchParams), t;
690
+ const t = te();
691
+ return window[st] = t, Yt(t.launchParams), t;
692
692
  }
693
- function tr() {
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 te(r) {
701
- return "external" in r && O(r.external) && "notify" in r.external && typeof r.external.notify == "function";
702
- }
703
700
  function ee(r) {
704
- return "TelegramWebviewProxy" in r && O(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
701
+ return "external" in r && H(r.external) && "notify" in r.external && typeof r.external.notify == "function";
705
702
  }
706
- function Ct() {
703
+ function re(r) {
704
+ return "TelegramWebviewProxy" in r && H(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
705
+ }
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 {
718
+ class et extends Error {
719
719
  constructor(t, e, s) {
720
- super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, Y.prototype);
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
  }
@@ -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 er(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 rr(r) {
788
- kt = r;
787
+ function ir(r) {
788
+ St = r;
789
789
  }
790
- function re() {
791
- return kt;
790
+ function se() {
791
+ return St;
792
792
  }
793
- const se = 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 ie() {
802
+ function oe() {
803
803
  const r = window;
804
804
  "TelegramGameProxy_receiveEvent" in r || [
805
805
  ["TelegramGameProxy_receiveEvent"],
@@ -812,76 +812,76 @@ function ie() {
812
812
  let e = r;
813
813
  t.forEach((s, n, i) => {
814
814
  if (n === i.length - 1) {
815
- e[s] = ne;
815
+ e[s] = ie;
816
816
  return;
817
817
  }
818
818
  s in e || (e[s] = {}), e = e[s];
819
819
  });
820
820
  });
821
821
  }
822
- function oe(r) {
823
- ie(), window.addEventListener("message", (t) => {
822
+ function ae(r) {
823
+ oe(), window.addEventListener("message", (t) => {
824
824
  try {
825
- const { eventType: e, eventData: s } = se.parse(t.data);
825
+ const { eventType: e, eventData: s } = ne.parse(t.data);
826
826
  r(e, s);
827
827
  } catch {
828
828
  }
829
829
  });
830
830
  }
831
- function ae() {
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 ce() {
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 he() {
844
+ function ue() {
845
845
  return g({
846
846
  slug: h(),
847
847
  status: h()
848
848
  });
849
849
  }
850
- function ue() {
850
+ function pe() {
851
851
  return g({ status: h() });
852
852
  }
853
- function pe() {
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 le() {
858
+ function de() {
859
859
  return g({
860
860
  data: h().optional()
861
861
  });
862
862
  }
863
- function de() {
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, [s, n]) => (e[s] = t.parse(n), 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 fe() {
871
+ function ge() {
872
872
  return g({
873
- height: V(),
874
- width: (r) => r == null ? window.innerWidth : V().parse(r),
875
- is_state_stable: k(),
876
- is_expanded: k()
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 ge() {
879
+ function we() {
880
880
  return g({ status: h() });
881
881
  }
882
882
  function _e() {
883
- const r = new _(), t = (e, ...s) => {
884
- P.log("Emitting processed event:", e, ...s), r.emit(e, ...s);
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 _e() {
890
890
  is_state_stable: !0,
891
891
  is_expanded: !0
892
892
  });
893
- }), oe((e, s) => {
894
- P.log("Received raw event:", e, s);
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, fe().parse(s));
898
+ return t(e, ge().parse(s));
899
899
  case "theme_changed":
900
- return t(e, de().parse(s));
900
+ return t(e, fe().parse(s));
901
901
  case "popup_closed":
902
902
  return (
903
903
  // Sent on desktop.
904
- s == null ? t(e, {}) : t(e, pe().parse(s))
904
+ s == null ? t(e, {}) : t(e, le().parse(s))
905
905
  );
906
906
  case "set_custom_style":
907
907
  return t(e, h().parse(s));
908
908
  case "qr_text_received":
909
- return t(e, le().parse(s));
909
+ return t(e, de().parse(s));
910
910
  case "clipboard_text_received":
911
- return t(e, ae().parse(s));
911
+ return t(e, ce().parse(s));
912
912
  case "invoice_closed":
913
- return t(e, he().parse(s));
913
+ return t(e, ue().parse(s));
914
914
  case "phone_requested":
915
- return t("phone_requested", ue().parse(s));
915
+ return t("phone_requested", pe().parse(s));
916
916
  case "custom_method_invoked":
917
- return t("custom_method_invoked", ce().parse(s));
917
+ return t("custom_method_invoked", he().parse(s));
918
918
  case "write_access_requested":
919
- return t("write_access_requested", ge().parse(s));
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":
@@ -927,31 +927,31 @@ function _e() {
927
927
  return t(e, s);
928
928
  }
929
929
  } catch (n) {
930
- P.error("Error processing event:", 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 W() {
934
+ const Q = "telegram-mini-apps-cached-emitter";
935
+ function U() {
936
936
  const r = window;
937
- return r[z] === void 0 && (r[z] = _e()), r[z];
937
+ return r[Q] === void 0 && (r[Q] = _e()), r[Q];
938
938
  }
939
- function $(r, t) {
940
- W().off(r, t);
939
+ function I(r, t) {
940
+ U().off(r, t);
941
941
  }
942
- function m(r, t) {
943
- return W().on(r, t), () => $(r, t);
942
+ function y(r, t) {
943
+ return U().on(r, t), () => I(r, t);
944
944
  }
945
- function sr(r, t) {
946
- return W().once(r, t), () => $(r, t);
945
+ function or(r, t) {
946
+ return U().once(r, t), () => I(r, t);
947
947
  }
948
- function we(r) {
949
- W().unsubscribe(r);
948
+ function be(r) {
949
+ U().unsubscribe(r);
950
950
  }
951
- function nr(r) {
952
- return W().subscribe(r), () => we(r);
951
+ function ar(r) {
952
+ return U().subscribe(r), () => be(r);
953
953
  }
954
- function be(r, t) {
954
+ function me(r, t) {
955
955
  const e = r.split("."), s = t.split("."), n = Math.max(e.length, s.length);
956
956
  for (let i = 0; i < n; i += 1) {
957
957
  const a = parseInt(e[i] || "0", 10), c = parseInt(s[i] || "0", 10);
@@ -961,7 +961,7 @@ function be(r, t) {
961
961
  return 0;
962
962
  }
963
963
  function v(r, t) {
964
- return be(r, t) <= 0;
964
+ return me(r, t) <= 0;
965
965
  }
966
966
  function A(r, t, e) {
967
967
  if (typeof e == "string") {
@@ -996,10 +996,10 @@ function A(r, t, e) {
996
996
  return !0;
997
997
  }
998
998
  }
999
- function y(r, t) {
999
+ function E(r, t) {
1000
1000
  return (e) => A(t[e], r);
1001
1001
  }
1002
- function St(r, t) {
1002
+ function kt(r, t) {
1003
1003
  return (e) => {
1004
1004
  const [s, n] = t[e];
1005
1005
  return A(s, n, r);
@@ -1008,19 +1008,19 @@ function St(r, t) {
1008
1008
  function f(r, t, e) {
1009
1009
  let s = {}, n;
1010
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 = re() } = s;
1012
- if (P.log(`Calling method "${r}"`, n), Ct()) {
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
1015
  eventData: n
1016
1016
  }), i);
1017
1017
  return;
1018
1018
  }
1019
- if (te(window)) {
1019
+ if (ee(window)) {
1020
1020
  window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
1021
1021
  return;
1022
1022
  }
1023
- if (ee(window)) {
1023
+ if (re(window)) {
1024
1024
  window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
1025
1025
  return;
1026
1026
  }
@@ -1028,70 +1028,93 @@ function f(r, t, e) {
1028
1028
  "Unable to determine current environment and possible way to send event."
1029
1029
  );
1030
1030
  }
1031
- function me(r) {
1031
+ function ye(r) {
1032
1032
  return (t, e) => {
1033
1033
  if (!A(t, r))
1034
- throw new K(t, r);
1035
- if (O(e)) {
1034
+ throw new tt(t, r);
1035
+ if (H(e)) {
1036
1036
  let s;
1037
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 Y(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 ye(r, t) {
1054
- return typeof r == "function" ? (...e) => Promise.race([
1055
- r(...e),
1056
- rt(t)
1057
- ]) : Promise.race([r, rt(t)]);
1061
+ function xt(r, t) {
1062
+ return Promise.race([
1063
+ r(),
1064
+ Ce(t)
1065
+ ]);
1058
1066
  }
1059
- function b(r, t, e, s) {
1067
+ function m(r, t, e, s) {
1060
1068
  let n, i, a, c;
1061
- typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t], n = e) : (i = t, a = Array.isArray(e) ? e : [e], n = s), O(i) && typeof i.req_id == "string" && (c = i.req_id);
1062
- const { postEvent: u = f, timeout: d } = n || {}, p = n && "capture" in n ? n.capture : null, E = new Promise((l, C) => {
1063
- const x = a.map((B) => m(B, (M) => {
1064
- typeof c == "string" && (!O(M) || M.req_id !== c) || typeof p == "function" && !p(M) || (R(), l(M));
1065
- })), R = () => x.forEach((B) => B());
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
1076
  } catch (B) {
1069
- R(), C(B);
1077
+ T(), C(B);
1070
1078
  }
1071
1079
  });
1072
- return typeof d == "number" ? ye(E, d) : E;
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 Ee {
1097
+ class ve {
1075
1098
  constructor(t, e, s = f) {
1076
- o(this, "ee", new _());
1099
+ o(this, "ee", new w());
1077
1100
  o(this, "state");
1078
1101
  /**
1079
1102
  * Adds event listener.
1080
1103
  * @param event - event name.
1081
1104
  * @param listener - event listener.
1082
1105
  */
1083
- o(this, "on", (t, e) => t === "click" ? m("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" ? $("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 = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(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
  });
@@ -1118,27 +1141,27 @@ class Ee {
1118
1141
  this.isVisible = !0;
1119
1142
  }
1120
1143
  }
1121
- function st(r, t) {
1144
+ function nt(r, t) {
1122
1145
  return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
1123
1146
  }
1124
- function Ce(...r) {
1147
+ function Pe(...r) {
1125
1148
  return r.reduce((t, e) => {
1126
1149
  let s = "";
1127
- return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? st(n, i) : n, "")), st(t, 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 ve(r) {
1153
+ function Se(r) {
1131
1154
  return typeof r == "object" && r !== null && !Array.isArray(null);
1132
1155
  }
1133
- function ir(...r) {
1134
- return r.reduce((t, e) => (ve(e) && Object.entries(e).forEach(([s, n]) => {
1135
- const i = Ce(t[s], n);
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);
1136
1159
  i.length > 0 && (t[s] = i);
1137
1160
  }), t), {});
1138
1161
  }
1139
1162
  class ke {
1140
1163
  constructor(t, e = f) {
1141
- o(this, "ee", new _());
1164
+ o(this, "ee", new w());
1142
1165
  o(this, "state");
1143
1166
  /**
1144
1167
  * Adds new event listener.
@@ -1148,7 +1171,7 @@ class ke {
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 w({ 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 ke {
1175
1198
  this.isConfirmationNeeded = !0;
1176
1199
  }
1177
1200
  }
1178
- function nt(r, t) {
1201
+ function it(r, t) {
1179
1202
  return r.reduce((e, s) => (e[s] = t, e), {});
1180
1203
  }
1181
- class Se {
1204
+ class xe {
1182
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 = s, this.supports = y(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, s = {}) {
1201
- const { result: n, error: i } = await b(
1202
- "web_app_invoke_custom_method",
1203
- { method: t, params: e, req_id: this.createRequestId() },
1204
- "custom_method_invoked",
1205
- { ...s, postEvent: this.postEvent }
1206
- );
1207
- if (i)
1208
- throw new Error(i);
1209
- return n;
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) {
1222
+ async delete(t, e = {}) {
1217
1223
  const s = Array.isArray(t) ? t : [t];
1218
- s.length !== 0 && await this.invokeCustomMethod("deleteStorageValues", { keys: s }, e);
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 Dt().of(h()).parse(e);
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);
1227
1243
  }
1228
- async get(t, e) {
1244
+ async get(t, e = {}) {
1229
1245
  const s = Array.isArray(t) ? t : [t];
1230
1246
  if (s.length === 0)
1231
- return nt(s, "");
1247
+ return it(s, "");
1232
1248
  const n = g(
1233
- nt(s, h())
1234
- ), i = await this.invokeCustomMethod("getStorageValues", { keys: s }, e).then((a) => n.parse(a));
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 Se {
1240
1261
  * @param value - storage value.
1241
1262
  * @param options - request execution options.
1242
1263
  */
1243
- async set(t, e, s) {
1244
- await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, s);
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 xe {
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 = y(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,37 +1316,37 @@ class xe {
1290
1316
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1291
1317
  }
1292
1318
  }
1293
- function Pe() {
1319
+ function Ae() {
1294
1320
  const r = document.createElement("style");
1295
- r.id = "telegram-custom-styles", document.head.appendChild(r), m("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 T(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 I(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 Ve(r, t, e) {
1310
- const { isVisible: s = !1 } = r ? I("back-button") || {} : {}, n = new Ee(s, t, e);
1335
+ function Re(r, t, e) {
1336
+ const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new ve(s, t, e);
1311
1337
  return n.on("change", () => {
1312
- T("back-button", { isVisible: n.isVisible });
1338
+ L("back-button", { isVisible: n.isVisible });
1313
1339
  }), n;
1314
1340
  }
1315
- function Ae(r, t) {
1316
- const { isConfirmationNeeded: e = !1 } = r ? I("closing-behavior") || {} : {}, s = new ke(e, t);
1317
- return s.on("change", () => T("closing-behavior", {
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", {
1318
1344
  isConfirmationNeeded: s.isConfirmationNeeded
1319
1345
  })), s;
1320
1346
  }
1321
- class qe {
1347
+ class Ie {
1322
1348
  constructor(t) {
1323
- o(this, "ee", new _());
1349
+ o(this, "ee", new w());
1324
1350
  o(this, "state");
1325
1351
  o(this, "postEvent");
1326
1352
  /**
@@ -1332,14 +1358,14 @@ 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" ? m("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" ? $("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
1371
  text: s,
@@ -1349,7 +1375,7 @@ class qe {
1349
1375
  isVisible: c,
1350
1376
  isLoaderVisible: u
1351
1377
  } = t;
1352
- this.postEvent = e, this.state = new w({
1378
+ this.postEvent = e, this.state = new _({
1353
1379
  backgroundColor: i,
1354
1380
  isEnabled: a,
1355
1381
  isVisible: c,
@@ -1490,31 +1516,59 @@ function Le(r, t, e, s) {
1490
1516
  isVisible: a = !1,
1491
1517
  isLoaderVisible: c = !1,
1492
1518
  textColor: u = e,
1493
- text: d = ""
1494
- } = r ? I("main-button") || {} : {}, p = new qe({
1519
+ text: p = ""
1520
+ } = r ? $("main-button") || {} : {}, l = new Ie({
1495
1521
  backgroundColor: n,
1496
1522
  isEnabled: i,
1497
1523
  isLoaderVisible: c,
1498
1524
  isVisible: a,
1499
1525
  postEvent: s,
1500
- text: d,
1526
+ text: p,
1501
1527
  textColor: u
1502
- }), E = () => T("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", E), 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
- o(this, "ee", new _());
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
  */
@@ -1536,18 +1590,33 @@ class $e {
1536
1590
  headerColor: s,
1537
1591
  backgroundColor: n,
1538
1592
  version: i,
1539
- botInline: a
1540
- } = t, c = y(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 w({ backgroundColor: n, headerColor: s }, 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 b(
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 b(
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,47 +1778,48 @@ class $e {
1658
1778
  });
1659
1779
  }
1660
1780
  }
1661
- function Te(r, t, e, s, n) {
1781
+ function Be(r, t, e, s, n, i) {
1662
1782
  const {
1663
- backgroundColor: i = t,
1664
- headerColor: a = "bg_color"
1665
- } = r ? I("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
1789
  botInline: s,
1670
- postEvent: n
1671
- }), u = () => T("mini-app", {
1672
- backgroundColor: c.backgroundColor,
1673
- headerColor: c.headerColor
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 Ie() {
1798
+ function De() {
1678
1799
  let r = 0;
1679
1800
  return () => (r += 1, r.toString());
1680
1801
  }
1681
- class Re {
1802
+ class We {
1682
1803
  constructor(t, e, s = f) {
1683
- o(this, "ee", new _());
1804
+ o(this, "ee", new w());
1684
1805
  o(this, "state");
1685
1806
  /**
1686
1807
  * Adds event listener.
1687
1808
  * @param event - event name.
1688
1809
  * @param listener - event listener.
1689
1810
  */
1690
- o(this, "on", (t, e) => t === "click" ? m("settings_button_pressed", e) : this.ee.on(t, e));
1811
+ o(this, "on", (t, e) => t === "click" ? y("settings_button_pressed", e) : this.ee.on(t, e));
1691
1812
  /**
1692
1813
  * Removes event listener.
1693
1814
  * @param event - event name.
1694
1815
  * @param listener - event listener.
1695
1816
  */
1696
- o(this, "off", (t, e) => t === "click" ? $("settings_button_pressed", e) : this.ee.off(t, e));
1817
+ o(this, "off", (t, e) => t === "click" ? I("settings_button_pressed", e) : this.ee.off(t, e));
1697
1818
  /**
1698
1819
  * Checks if specified method is supported by current component.
1699
1820
  */
1700
1821
  o(this, "supports");
1701
- this.postEvent = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(e, {
1822
+ this.postEvent = s, this.state = new _({ isVisible: t }, this.ee), this.supports = E(e, {
1702
1823
  show: "web_app_setup_settings_button",
1703
1824
  hide: "web_app_setup_settings_button"
1704
1825
  });
@@ -1725,18 +1846,18 @@ class Re {
1725
1846
  this.isVisible = !0;
1726
1847
  }
1727
1848
  }
1728
- function Be(r, t, e) {
1729
- const { isVisible: s = !1 } = r ? I("settings-button") || {} : {}, n = new Re(s, t, e);
1849
+ function Ne(r, t, e) {
1850
+ const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new We(s, t, e);
1730
1851
  return n.on("change", () => {
1731
- T("settings-button", { isVisible: n.isVisible });
1852
+ L("settings-button", { isVisible: n.isVisible });
1732
1853
  }), n;
1733
1854
  }
1734
- function De(r) {
1735
- const t = new Gt(r);
1855
+ function Oe(r) {
1856
+ const t = new Ft(r);
1736
1857
  return t.listen(), t;
1737
1858
  }
1738
- async function Pt(r) {
1739
- const t = await b("web_app_request_viewport", "viewport_changed", r);
1859
+ async function At(r) {
1860
+ const t = await m("web_app_request_viewport", "viewport_changed", r);
1740
1861
  return {
1741
1862
  height: t.height,
1742
1863
  width: t.width,
@@ -1747,9 +1868,9 @@ async function Pt(r) {
1747
1868
  function D(r) {
1748
1869
  return r < 0 ? 0 : r;
1749
1870
  }
1750
- class j {
1871
+ class G {
1751
1872
  constructor(t) {
1752
- o(this, "ee", new _());
1873
+ o(this, "ee", new w());
1753
1874
  o(this, "state");
1754
1875
  o(this, "postEvent");
1755
1876
  /**
@@ -1767,7 +1888,7 @@ class j {
1767
1888
  stableHeight: i,
1768
1889
  postEvent: a = f
1769
1890
  } = t;
1770
- this.postEvent = a, this.state = new w({
1891
+ this.postEvent = a, this.state = new _({
1771
1892
  height: D(e),
1772
1893
  isExpanded: s,
1773
1894
  stableHeight: D(i),
@@ -1780,7 +1901,7 @@ class j {
1780
1901
  * @param options - options to request fresh data.
1781
1902
  */
1782
1903
  sync(t) {
1783
- return Pt(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
1904
+ return At(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
1784
1905
  this.state.set({
1785
1906
  height: e,
1786
1907
  width: n,
@@ -1830,7 +1951,7 @@ class j {
1830
1951
  * @returns Function to stop listening.
1831
1952
  */
1832
1953
  listen() {
1833
- return m("viewport_changed", (t) => {
1954
+ return y("viewport_changed", (t) => {
1834
1955
  const {
1835
1956
  height: e,
1836
1957
  width: s,
@@ -1876,23 +1997,23 @@ class j {
1876
1997
  return this.stableHeight === this.height;
1877
1998
  }
1878
1999
  }
1879
- function Vt(r) {
2000
+ function Rt(r) {
1880
2001
  return !["macos", "web", "weba"].includes(r);
1881
2002
  }
1882
- function At(r, t, e) {
1883
- if (r || !Vt(t))
1884
- return new j({
2003
+ function Vt(r, t, e) {
2004
+ if (r || !Rt(t))
2005
+ return new G({
1885
2006
  height: window.innerHeight,
1886
2007
  isExpanded: !0,
1887
2008
  postEvent: e,
1888
2009
  stableHeight: window.innerHeight,
1889
2010
  width: window.innerWidth
1890
2011
  });
1891
- const s = I("viewport");
1892
- return s ? new j({ ...s, postEvent: e }) : null;
2012
+ const s = $("viewport");
2013
+ return s ? new G({ ...s, postEvent: e }) : null;
1893
2014
  }
1894
- function qt(r) {
1895
- return r.listen(), r.on("change", () => T("viewport", {
2015
+ function It(r) {
2016
+ return r.listen(), r.on("change", () => L("viewport", {
1896
2017
  height: r.height,
1897
2018
  isExpanded: r.isExpanded,
1898
2019
  stableHeight: r.stableHeight,
@@ -1900,8 +2021,8 @@ function qt(r) {
1900
2021
  })), r;
1901
2022
  }
1902
2023
  function He(r, t, e) {
1903
- const s = qt(
1904
- At(r, t, e) || new j({
2024
+ const s = It(
2025
+ Vt(r, t, e) || new G({
1905
2026
  width: 0,
1906
2027
  height: 0,
1907
2028
  isExpanded: !1,
@@ -1909,13 +2030,13 @@ function He(r, t, e) {
1909
2030
  stableHeight: 0
1910
2031
  })
1911
2032
  );
1912
- return Vt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
2033
+ return Rt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
1913
2034
  console.error("Unable to actualize viewport state", n);
1914
2035
  }), s;
1915
2036
  }
1916
- async function Ne(r, t, e) {
1917
- return qt(
1918
- At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: s, isStateStable: n, ...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({
1919
2040
  ...i,
1920
2041
  height: s,
1921
2042
  stableHeight: n ? s : 0
@@ -1925,7 +2046,7 @@ async function Ne(r, t, e) {
1925
2046
  function S(r, t) {
1926
2047
  document.documentElement.style.setProperty(r, t);
1927
2048
  }
1928
- function Oe(r, t) {
2049
+ function Me(r, t) {
1929
2050
  const e = () => {
1930
2051
  S("--tg-background-color", r.backgroundColor);
1931
2052
  }, s = () => {
@@ -1937,7 +2058,7 @@ function Oe(r, t) {
1937
2058
  };
1938
2059
  t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
1939
2060
  }
1940
- function We(r) {
2061
+ function je(r) {
1941
2062
  const t = () => {
1942
2063
  const e = r.getState();
1943
2064
  Object.entries(e).forEach(([s, n]) => {
@@ -1949,22 +2070,22 @@ function We(r) {
1949
2070
  };
1950
2071
  r.on("change", t), t();
1951
2072
  }
1952
- function it(r) {
2073
+ function ot(r) {
1953
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`);
1954
2075
  r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
1955
2076
  }
1956
- function Me(r) {
2077
+ function Ge(r) {
1957
2078
  return typeof r == "object" ? r : r ? {
1958
2079
  themeParams: !0,
1959
2080
  viewport: !0,
1960
2081
  miniApp: !0
1961
2082
  } : {};
1962
2083
  }
1963
- function ot(r, t, e, s) {
1964
- const n = Me(r);
1965
- n.miniApp && Oe(t, e), n.themeParams && We(e), n.viewport && (s instanceof Promise ? s.then(it) : it(s));
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));
1966
2087
  }
1967
- function Ue(r) {
2088
+ function Fe(r) {
1968
2089
  const { hostname: t, pathname: e } = new URL(r, window.location.href);
1969
2090
  if (t !== "t.me")
1970
2091
  throw new Error(`Incorrect hostname: ${t}`);
@@ -1973,9 +2094,9 @@ function Ue(r) {
1973
2094
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1974
2095
  return s[2];
1975
2096
  }
1976
- class je {
2097
+ class ze {
1977
2098
  constructor(t, e = f) {
1978
- o(this, "ee", new _());
2099
+ o(this, "ee", new w());
1979
2100
  o(this, "state");
1980
2101
  /**
1981
2102
  * Adds new event listener.
@@ -1989,7 +2110,7 @@ class je {
1989
2110
  * Checks if specified method is supported by current component.
1990
2111
  */
1991
2112
  o(this, "supports");
1992
- this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(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" });
1993
2114
  }
1994
2115
  set isOpened(t) {
1995
2116
  this.state.set("isOpened", t);
@@ -2003,10 +2124,10 @@ class je {
2003
2124
  async open(t, e) {
2004
2125
  if (this.isOpened)
2005
2126
  throw new Error("Invoice is already opened");
2006
- const s = e ? Ue(t) : t;
2127
+ const s = e ? Fe(t) : t;
2007
2128
  this.isOpened = !0;
2008
2129
  try {
2009
- return (await b(
2130
+ return (await m(
2010
2131
  "web_app_open_invoice",
2011
2132
  { slug: s },
2012
2133
  "invoice_closed",
@@ -2022,7 +2143,7 @@ class je {
2022
2143
  }
2023
2144
  }
2024
2145
  }
2025
- function Ge(r) {
2146
+ function Je(r) {
2026
2147
  const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
2027
2148
  let n;
2028
2149
  if (e.length > 64)
@@ -2046,9 +2167,9 @@ function Ge(r) {
2046
2167
  return { ...i, id: a };
2047
2168
  }), { title: e, message: t, buttons: n };
2048
2169
  }
2049
- class Fe {
2170
+ class Qe {
2050
2171
  constructor(t, e = f) {
2051
- o(this, "ee", new _());
2172
+ o(this, "ee", new w());
2052
2173
  o(this, "state");
2053
2174
  /**
2054
2175
  * Adds new event listener.
@@ -2062,7 +2183,7 @@ class Fe {
2062
2183
  * Checks if specified method is supported by current component.
2063
2184
  */
2064
2185
  o(this, "supports");
2065
- this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(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" });
2066
2187
  }
2067
2188
  set isOpened(t) {
2068
2189
  this.state.set("isOpened", t);
@@ -2089,9 +2210,9 @@ class Fe {
2089
2210
  open(t) {
2090
2211
  if (this.isOpened)
2091
2212
  throw new Error("Popup is already opened.");
2092
- return this.isOpened = !0, b(
2213
+ return this.isOpened = !0, m(
2093
2214
  "web_app_open_popup",
2094
- Ge(t),
2215
+ Je(t),
2095
2216
  "popup_closed",
2096
2217
  { postEvent: this.postEvent }
2097
2218
  ).then(({ button_id: e = null }) => e).finally(() => {
@@ -2099,9 +2220,9 @@ class Fe {
2099
2220
  });
2100
2221
  }
2101
2222
  }
2102
- class ze {
2223
+ class Ze {
2103
2224
  constructor(t, e = f) {
2104
- o(this, "ee", new _());
2225
+ o(this, "ee", new w());
2105
2226
  o(this, "state");
2106
2227
  /**
2107
2228
  * Adds new event listener.
@@ -2115,7 +2236,7 @@ class ze {
2115
2236
  * Checks if specified method is supported by current component.
2116
2237
  */
2117
2238
  o(this, "supports");
2118
- this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, {
2239
+ this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, {
2119
2240
  close: "web_app_close_scan_qr_popup",
2120
2241
  open: "web_app_open_scan_qr_popup"
2121
2242
  });
@@ -2146,7 +2267,7 @@ class ze {
2146
2267
  throw new Error("QR scanner is already opened.");
2147
2268
  this.isOpened = !0;
2148
2269
  try {
2149
- const e = await b(
2270
+ const e = await m(
2150
2271
  "web_app_open_scan_qr_popup",
2151
2272
  { text: t },
2152
2273
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -2158,7 +2279,7 @@ class ze {
2158
2279
  }
2159
2280
  }
2160
2281
  }
2161
- class Je {
2282
+ class Ke {
2162
2283
  constructor(t, e, s = f) {
2163
2284
  /**
2164
2285
  * Checks if specified method is supported by current component.
@@ -2168,9 +2289,9 @@ class Je {
2168
2289
  * Checks if specified method parameter is supported by current component.
2169
2290
  */
2170
2291
  o(this, "supportsParam");
2171
- this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = y(t, {
2292
+ this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = E(t, {
2172
2293
  readTextFromClipboard: "web_app_read_text_from_clipboard"
2173
- }), this.supportsParam = St(t, {
2294
+ }), this.supportsParam = kt(t, {
2174
2295
  "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
2175
2296
  });
2176
2297
  }
@@ -2221,7 +2342,7 @@ class Je {
2221
2342
  * - Access to clipboard is not allowed
2222
2343
  */
2223
2344
  readTextFromClipboard() {
2224
- return b(
2345
+ return m(
2225
2346
  "web_app_read_text_from_clipboard",
2226
2347
  { req_id: this.createRequestId() },
2227
2348
  "clipboard_text_received",
@@ -2229,7 +2350,7 @@ class Je {
2229
2350
  ).then(({ data: t = null }) => t);
2230
2351
  }
2231
2352
  }
2232
- function or(r = {}) {
2353
+ function ur(r = {}) {
2233
2354
  const {
2234
2355
  async: t = !1,
2235
2356
  cssVars: e = !1,
@@ -2243,51 +2364,52 @@ function or(r = {}) {
2243
2364
  version: a,
2244
2365
  platform: c,
2245
2366
  themeParams: u,
2246
- botInline: d = !1
2367
+ botInline: p = !1
2247
2368
  },
2248
- isPageReload: p
2249
- } = Et(), E = Ie(), l = me(a);
2250
- Ct() && (s && Pe(), l("iframe_ready", { reload_supported: !0 }), m("reload_iframe", () => window.location.reload()));
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()));
2251
2372
  const C = {
2252
- backButton: Ve(p, a, l),
2253
- closingBehavior: Ae(p, l),
2254
- cloudStorage: new Se(a, E, l),
2255
- createRequestId: E,
2256
- hapticFeedback: new xe(a, l),
2257
- invoice: new je(a, l),
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),
2258
2379
  mainButton: Le(
2259
- p,
2380
+ l,
2260
2381
  u.buttonColor || "#000000",
2261
2382
  u.buttonTextColor || "#ffffff",
2262
- l
2383
+ d
2263
2384
  ),
2264
- miniApp: Te(
2265
- p,
2385
+ miniApp: Be(
2386
+ l,
2266
2387
  u.backgroundColor || "#ffffff",
2267
2388
  a,
2268
- d,
2269
- l
2389
+ p,
2390
+ b,
2391
+ d
2270
2392
  ),
2271
- popup: new Fe(a, l),
2272
- postEvent: l,
2273
- qrScanner: new ze(a, l),
2274
- settingsButton: Be(p, a, l),
2275
- themeParams: De(u),
2276
- utils: new Je(a, E, l),
2393
+ popup: new Qe(a, d),
2394
+ postEvent: d,
2395
+ qrScanner: new Ze(a, d),
2396
+ settingsButton: Ne(l, a, d),
2397
+ themeParams: Oe(u),
2398
+ utils: new Ke(a, b, d),
2277
2399
  ...n ? {
2278
- initData: new Wt(n),
2400
+ initData: new Ut(n),
2279
2401
  initDataRaw: i
2280
2402
  } : {}
2281
- }, x = t ? Ne(p, c, l) : He(p, c, l);
2282
- return x instanceof Promise ? x.then((R) => (ot(
2403
+ }, x = t ? Ue(l, c, d) : He(l, c, d);
2404
+ return x instanceof Promise ? x.then((T) => (at(
2283
2405
  e,
2284
2406
  C.miniApp,
2285
2407
  C.themeParams,
2286
- R
2408
+ T
2287
2409
  ), {
2288
2410
  ...C,
2289
- viewport: R
2290
- })) : (ot(
2411
+ viewport: T
2412
+ })) : (at(
2291
2413
  e,
2292
2414
  C.miniApp,
2293
2415
  C.themeParams,
@@ -2299,14 +2421,14 @@ function or(r = {}) {
2299
2421
  throw n;
2300
2422
  }
2301
2423
  }
2302
- function H(r, t) {
2424
+ function W(r, t) {
2303
2425
  return r.startsWith(t) ? r : `${t}${r}`;
2304
2426
  }
2305
- function ar(r) {
2427
+ function pr(r) {
2306
2428
  const t = r.match(/#(.+)/);
2307
2429
  return t ? t[1] : null;
2308
2430
  }
2309
- async function N(r) {
2431
+ async function O(r) {
2310
2432
  return r === 0 ? !0 : Promise.race([
2311
2433
  new Promise((t) => {
2312
2434
  window.addEventListener("popstate", function e() {
@@ -2319,14 +2441,14 @@ async function N(r) {
2319
2441
  })
2320
2442
  ]);
2321
2443
  }
2322
- async function Qe() {
2323
- if (window.history.length <= 1 || (window.history.pushState(null, ""), await N(1 - window.history.length)))
2444
+ async function Ye() {
2445
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await O(1 - window.history.length)))
2324
2446
  return;
2325
- let t = await N(-1);
2447
+ let t = await O(-1);
2326
2448
  for (; t; )
2327
- t = await N(-1);
2449
+ t = await O(-1);
2328
2450
  }
2329
- class Ze {
2451
+ class Xe {
2330
2452
  constructor(t, e, {
2331
2453
  debug: s = !1,
2332
2454
  loggerPrefix: n = "Navigator"
@@ -2341,11 +2463,11 @@ class Ze {
2341
2463
  if (!i.startsWith("/") && i.length > 0)
2342
2464
  throw new Error('Pathname should start with "/"');
2343
2465
  return {
2344
- pathname: H(i, "/"),
2345
- search: a ? H(a, "?") : "",
2346
- hash: c ? H(c, "#") : ""
2466
+ pathname: W(i, "/"),
2467
+ search: a ? W(a, "?") : "",
2468
+ hash: c ? W(c, "#") : ""
2347
2469
  };
2348
- }), this.logger = new vt(`[${n}]`, s);
2470
+ }), this.logger = new Pt(`[${n}]`, s);
2349
2471
  }
2350
2472
  /**
2351
2473
  * Converts entry to the navigation entry.
@@ -2361,7 +2483,7 @@ class Ze {
2361
2483
  search: c,
2362
2484
  hash: u
2363
2485
  } = t;
2364
- e = a + (c ? H(c, "?") : "") + (u ? H(u, "#") : "");
2486
+ e = a + (c ? W(c, "?") : "") + (u ? W(u, "#") : "");
2365
2487
  }
2366
2488
  const {
2367
2489
  pathname: s,
@@ -2525,14 +2647,14 @@ class Ze {
2525
2647
  return this.entry.search;
2526
2648
  }
2527
2649
  }
2528
- const at = 0, J = 1, Q = 2;
2529
- class Lt extends Ze {
2650
+ const ct = 0, Z = 1, K = 2;
2651
+ class Lt extends Xe {
2530
2652
  constructor(e, s, n = {}) {
2531
2653
  super(e, s, {
2532
2654
  ...n,
2533
2655
  loggerPrefix: "HashNavigator"
2534
2656
  });
2535
- o(this, "ee", new _());
2657
+ o(this, "ee", new w());
2536
2658
  o(this, "attached", !1);
2537
2659
  /**
2538
2660
  * Handles window "popstate" event.
@@ -2541,13 +2663,13 @@ class Lt extends Ze {
2541
2663
  o(this, "onPopState", async ({ state: e }) => {
2542
2664
  if (this.logger.log('"popstate" event received. State:', e), e === null)
2543
2665
  return this.push(window.location.hash.slice(1));
2544
- if (e === at) {
2666
+ if (e === ct) {
2545
2667
  this.logger.log("Void reached. Moving history forward"), window.history.forward();
2546
2668
  return;
2547
2669
  }
2548
- if (e === J)
2670
+ if (e === Z)
2549
2671
  return this.back();
2550
- if (e === Q)
2672
+ if (e === K)
2551
2673
  return this.forward();
2552
2674
  });
2553
2675
  o(this, "back", () => super.back());
@@ -2590,7 +2712,7 @@ class Lt extends Ze {
2590
2712
  async syncHistory() {
2591
2713
  window.removeEventListener("popstate", this.onPopState);
2592
2714
  const e = `#${this.path}`;
2593
- await Qe(), 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 N(-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 N(-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);
2594
2716
  }
2595
2717
  emitChanged(e, s) {
2596
2718
  this.ee.emit("change", {
@@ -2604,69 +2726,73 @@ class Lt extends Ze {
2604
2726
  */
2605
2727
  async attach() {
2606
2728
  if (!this.attached)
2607
- return this.logger.log("Attaching", this), this.attached = !0, m("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();
2608
2730
  }
2609
2731
  /**
2610
2732
  * Detaches current navigator from the browser history.
2611
2733
  */
2612
2734
  detach() {
2613
- this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), $("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));
2614
2736
  }
2615
2737
  }
2616
2738
  export {
2617
- Ee as BackButton,
2739
+ ve as BackButton,
2618
2740
  ke as ClosingBehavior,
2619
- Se as CloudStorage,
2620
- xe as HapticFeedback,
2741
+ xe as CloudStorage,
2742
+ qe as HapticFeedback,
2621
2743
  Lt as HashNavigator,
2622
- Wt as InitData,
2623
- je as Invoice,
2624
- qe as MainButton,
2625
- K as MethodUnsupportedError,
2626
- $e as MiniApp,
2627
- Ze as Navigator,
2628
- Y as ParameterUnsupportedError,
2629
- Fe as Popup,
2630
- ze as QRScanner,
2631
- Re as SettingsButton,
2632
- Gt as ThemeParams,
2633
- Je as Utils,
2634
- j as Viewport,
2635
- Ot as chatParser,
2636
- Ce as classNames,
2637
- be as compareVersions,
2638
- me as createPostEvent,
2639
- ar as getHash,
2640
- or as init,
2641
- gt as initDataParser,
2642
- lt as isColorDark,
2643
- Ct as isIframe,
2644
- ut as isRGB,
2645
- Nt as isRGBShort,
2646
- O as isRecord,
2647
- tr as isTMA,
2648
- bt as launchParamsParser,
2649
- ir as mergeClassNames,
2650
- $ as off,
2651
- m as on,
2652
- sr as once,
2653
- Ye as parseInitData,
2654
- mt as parseLaunchParams,
2655
- wt 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,
2656
2781
  f as postEvent,
2657
- b as request,
2658
- Xe as requestThemeParams,
2659
- Pt as requestViewport,
2660
- Et as retrieveLaunchData,
2661
- Qt as serializeLaunchParams,
2662
- jt as serializeThemeParams,
2663
- er as setDebug,
2664
- rr as setTargetOrigin,
2665
- nr as subscribe,
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,
2666
2791
  A as supports,
2667
2792
  _t as themeParamsParser,
2668
- pt as toRGB,
2669
- we as unsubscribe,
2670
- tt as userParser
2793
+ dt as toRGB,
2794
+ be as unsubscribe,
2795
+ rt as userParser,
2796
+ xt as withTimeout
2671
2797
  };
2672
2798
  //# sourceMappingURL=index.mjs.map