@tma.js/sdk 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,32 +1,32 @@
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 O(r) {
5
5
  return typeof r == "object" && r !== null && !Array.isArray(r);
6
6
  }
7
7
  function ct() {
8
8
  return performance.getEntriesByType("navigation")[0] || null;
9
9
  }
10
- function Tt() {
10
+ function It() {
11
11
  const r = ct();
12
12
  return r ? r.type === "reload" : null;
13
13
  }
14
- function L() {
14
+ function q() {
15
15
  return new TypeError("Value has unexpected type");
16
16
  }
17
17
  class G extends Error {
18
- constructor(e, { cause: n, type: s } = {}) {
19
- super(`Unable to parse value${s ? ` as ${s}` : ""}`, { cause: n });
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, G.prototype), this.type = n;
25
25
  }
26
26
  }
27
27
  class F {
28
- constructor(t, e, n) {
29
- this.parser = t, this.isOptional = e, this.type = n;
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))
@@ -40,7 +40,7 @@ class F {
40
40
  return this.isOptional = !0, this;
41
41
  }
42
42
  }
43
- function It(r) {
43
+ function Rt(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 q();
54
54
  }
55
- class Rt extends F {
56
- constructor(e, n, s) {
57
- super(It, n, s);
55
+ class Bt extends F {
56
+ constructor(e, s, n) {
57
+ super(Rt, 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) {
69
+ function L(r, t) {
70
70
  return () => new F(r, !1, t);
71
71
  }
72
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);
73
+ constructor(t, { cause: e, type: s } = {}) {
74
+ super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, U.prototype);
75
75
  }
76
76
  }
77
77
  function ht(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: d } = n;
88
+ i = n.from || s, a = typeof d == "function" ? d : d.parse.bind(d);
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 (d) {
95
+ throw d instanceof G ? new U(i, {
96
+ type: d.type,
97
+ cause: d
98
+ }) : new U(i, { cause: d });
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 Dt(r) {
105
+ return new Bt((t) => t, !1, r);
106
106
  }
107
- const C = $((r) => {
107
+ const k = L((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 q();
116
+ }, "boolean"), V = L((r) => {
117
117
  if (typeof r == "number")
118
118
  return r;
119
119
  if (typeof r == "string") {
@@ -121,18 +121,18 @@ const C = $((r) => {
121
121
  if (!Number.isNaN(t))
122
122
  return t;
123
123
  }
124
- throw L();
125
- }, "number"), Dt = A(), Ht = $((r) => r instanceof Date ? r : new Date(Dt.parse(r) * 1e3), "Date");
124
+ throw q();
125
+ }, "number"), Ht = L((r) => r instanceof Date ? r : new Date(V().parse(r) * 1e3), "Date");
126
126
  function Z(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 q();
130
130
  return t;
131
131
  }
132
132
  function g(r, t) {
133
133
  return new F((e) => {
134
- const n = Z(e);
135
- return ht(r, (s) => n[s]);
134
+ const s = Z(e);
135
+ return ht(r, (n) => s[n]);
136
136
  }, !1, t);
137
137
  }
138
138
  function ut(r) {
@@ -146,47 +146,47 @@ function pt(r) {
146
146
  if (ut(t))
147
147
  return t;
148
148
  if (Nt(t)) {
149
- let n = "#";
150
- for (let s = 0; s < 3; s += 1)
151
- n += t[1 + s].repeat(2);
152
- return n;
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
162
  function lt(r) {
163
163
  const t = pt(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 = L((r) => {
172
172
  if (typeof r == "string" || typeof r == "number")
173
173
  return r.toString();
174
- throw L();
175
- }, "string"), Ot = h(), dt = $((r) => pt(Ot.parse(r)), "rgb");
174
+ throw q();
175
+ }, "string"), dt = L((r) => pt(h().parse(r)), "rgb");
176
176
  function ft(r, t) {
177
177
  return new F((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 q();
180
+ const s = typeof e == "string" ? new URLSearchParams(e) : e;
181
+ return ht(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 Wt() {
187
+ function Ot() {
188
188
  return g({
189
- id: A(),
189
+ id: V(),
190
190
  type: h(),
191
191
  title: h(),
192
192
  photoUrl: {
@@ -196,7 +196,7 @@ function Wt() {
196
196
  username: h().optional()
197
197
  }, "Chat");
198
198
  }
199
- class Mt {
199
+ class Wt {
200
200
  constructor(t) {
201
201
  this.initData = t;
202
202
  }
@@ -272,24 +272,24 @@ class Mt {
272
272
  function tt() {
273
273
  return g({
274
274
  addedToAttachmentMenu: {
275
- type: C().optional(),
275
+ type: k().optional(),
276
276
  from: "added_to_attachment_menu"
277
277
  },
278
278
  allowsWriteToPm: {
279
- type: C().optional(),
279
+ type: k().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: V(),
287
287
  isBot: {
288
- type: C().optional(),
288
+ type: k().optional(),
289
289
  from: "is_bot"
290
290
  },
291
291
  isPremium: {
292
- type: C().optional(),
292
+ type: k().optional(),
293
293
  from: "is_premium"
294
294
  },
295
295
  languageCode: {
@@ -314,10 +314,10 @@ function gt() {
314
314
  from: "auth_date"
315
315
  },
316
316
  canSendAfter: {
317
- type: A().optional(),
317
+ type: V().optional(),
318
318
  from: "can_send_after"
319
319
  },
320
- chat: Wt().optional(),
320
+ chat: Ot().optional(),
321
321
  chatInstance: {
322
322
  type: h().optional(),
323
323
  from: "chat_instance"
@@ -339,31 +339,34 @@ function gt() {
339
339
  user: tt().optional()
340
340
  }, "InitData");
341
341
  }
342
- function Xe(r) {
342
+ function Ye(r) {
343
343
  return gt().parse(r);
344
344
  }
345
- function Ut(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 jt(r) {
348
+ function Ut(r) {
349
349
  return r.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`).replace(/(^|_)background/, (t, e) => `${e}bg`);
350
350
  }
351
- const Gt = dt().optional(), wt = $(
352
- (r) => Object.entries(Z(r)).reduce((t, [e, n]) => (t[Ut(e)] = Gt.parse(n), t), {}),
351
+ const _t = L(
352
+ (r) => {
353
+ const t = dt().optional();
354
+ return Object.entries(Z(r)).reduce((e, [s, n]) => (e[Mt(s)] = t.parse(n), e), {});
355
+ },
353
356
  "ThemeParams"
354
357
  );
355
- function _t(r) {
356
- return wt().parse(r);
358
+ function wt(r) {
359
+ return _t().parse(r);
357
360
  }
358
- function tr(r = {}) {
359
- return _("web_app_request_theme", "theme_changed", r).then(_t);
361
+ function Xe(r = {}) {
362
+ return b("web_app_request_theme", "theme_changed", r).then(wt);
360
363
  }
361
- function Ft(r) {
364
+ function jt(r) {
362
365
  return JSON.stringify(
363
- Object.entries(r).reduce((t, [e, n]) => (n && (t[jt(e)] = n), t), {})
366
+ Object.entries(r).reduce((t, [e, s]) => (s && (t[Ut(e)] = s), t), {})
364
367
  );
365
368
  }
366
- class w {
369
+ class _ {
367
370
  constructor() {
368
371
  o(this, "listeners", /* @__PURE__ */ new Map());
369
372
  o(this, "subscribeListeners", []);
@@ -374,15 +377,15 @@ class w {
374
377
  * @param listener - event listener.
375
378
  * @param once - should listener called only once.
376
379
  */
377
- addListener(t, e, n) {
378
- let s = this.listeners.get(t);
379
- 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);
380
383
  }
381
384
  emit(t, ...e) {
382
- this.subscribeListeners.forEach((s) => s(t, ...e));
383
- const n = this.listeners.get(t);
384
- n && n.forEach(([s, i], a) => {
385
- 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);
386
389
  });
387
390
  }
388
391
  /**
@@ -412,11 +415,11 @@ class w {
412
415
  * @param listener - event listener.
413
416
  */
414
417
  off(t, e) {
415
- const n = this.listeners.get(t);
416
- if (n) {
417
- for (let s = 0; s < n.length; s += 1)
418
- if (e === n[s][0]) {
419
- 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);
420
423
  return;
421
424
  }
422
425
  }
@@ -445,7 +448,7 @@ class w {
445
448
  }
446
449
  }
447
450
  }
448
- class b {
451
+ class w {
449
452
  constructor(t, e) {
450
453
  this.state = t, this.ee = e;
451
454
  }
@@ -459,13 +462,13 @@ class b {
459
462
  return { ...this.state };
460
463
  }
461
464
  set(t, e) {
462
- let n = !1;
465
+ let s = !1;
463
466
  if (typeof t == "string")
464
- n = this.internalSet(t, e);
467
+ s = this.internalSet(t, e);
465
468
  else
466
- for (const s in t)
467
- this.internalSet(s, t[s]) && (n = !0);
468
- 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");
469
472
  }
470
473
  /**
471
474
  * Returns value by specified key.
@@ -475,9 +478,9 @@ class b {
475
478
  return this.state[t];
476
479
  }
477
480
  }
478
- class zt {
481
+ class Gt {
479
482
  constructor(t) {
480
- o(this, "ee", new w());
483
+ o(this, "ee", new _());
481
484
  o(this, "state");
482
485
  /**
483
486
  * Adds new event listener.
@@ -487,7 +490,7 @@ class zt {
487
490
  * Removes event listener.
488
491
  */
489
492
  o(this, "off", this.ee.off.bind(this.ee));
490
- this.state = new b(t, this.ee);
493
+ this.state = new w(t, this.ee);
491
494
  }
492
495
  /**
493
496
  * @since v6.10
@@ -559,8 +562,8 @@ class zt {
559
562
  * @returns Function to stop listening.
560
563
  */
561
564
  listen() {
562
- return k("theme_changed", (t) => {
563
- this.state.set(_t(t.theme_params));
565
+ return m("theme_changed", (t) => {
566
+ this.state.set(wt(t.theme_params));
564
567
  });
565
568
  }
566
569
  /**
@@ -576,7 +579,7 @@ class zt {
576
579
  function bt() {
577
580
  return ft({
578
581
  botInline: {
579
- type: C().optional(),
582
+ type: k().optional(),
580
583
  from: "tgWebAppBotInline"
581
584
  },
582
585
  initData: {
@@ -592,11 +595,11 @@ function bt() {
592
595
  from: "tgWebAppPlatform"
593
596
  },
594
597
  showSettings: {
595
- type: C().optional(),
598
+ type: k().optional(),
596
599
  from: "tgWebAppShowSettings"
597
600
  },
598
601
  themeParams: {
599
- type: wt(),
602
+ type: _t(),
600
603
  from: "tgWebAppThemeParams"
601
604
  },
602
605
  version: {
@@ -608,10 +611,10 @@ function bt() {
608
611
  function mt(r) {
609
612
  return bt().parse(r);
610
613
  }
611
- function Jt() {
614
+ function Ft() {
612
615
  return mt(window.location.hash.slice(1));
613
616
  }
614
- function Qt() {
617
+ function zt() {
615
618
  const r = ct();
616
619
  if (!r)
617
620
  throw new Error("Unable to get first navigation entry.");
@@ -620,50 +623,50 @@ function Qt() {
620
623
  throw new Error("First navigation entry does not contain hash part.");
621
624
  return mt(t[1]);
622
625
  }
623
- function Zt() {
626
+ function Jt() {
624
627
  try {
625
- return Qt();
628
+ return zt();
626
629
  } catch {
627
630
  }
628
631
  try {
629
- return Jt();
632
+ return Ft();
630
633
  } catch {
631
634
  }
632
635
  return null;
633
636
  }
634
- function Kt(r) {
637
+ function Qt(r) {
635
638
  const {
636
639
  initDataRaw: t,
637
640
  themeParams: e,
638
- platform: n,
639
- version: s,
641
+ platform: s,
642
+ version: n,
640
643
  showSettings: i,
641
644
  botInline: a
642
645
  } = r, c = new URLSearchParams();
643
- return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", n), c.set("tgWebAppThemeParams", Ft(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", 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();
644
647
  }
645
648
  const yt = "telegram-mini-apps-launch-params";
646
- function Yt() {
649
+ function Zt() {
647
650
  const r = sessionStorage.getItem(yt);
648
651
  return r ? bt().parse(r) : null;
649
652
  }
650
- function Xt(r) {
651
- sessionStorage.setItem(yt, Kt(r));
653
+ function Kt(r) {
654
+ sessionStorage.setItem(yt, Qt(r));
652
655
  }
653
- function te() {
656
+ function Yt() {
654
657
  try {
655
658
  return window.self !== window.top;
656
659
  } catch {
657
660
  return !0;
658
661
  }
659
662
  }
660
- function ee() {
661
- const r = Yt(), t = Zt(), e = Tt();
663
+ function Xt() {
664
+ const r = Zt(), t = Jt(), e = It();
662
665
  if (r) {
663
666
  if (t)
664
667
  return {
665
668
  launchParams: t,
666
- isPageReload: te() ? e || r.initDataRaw === t.initDataRaw : !0
669
+ isPageReload: Yt() ? e || r.initDataRaw === t.initDataRaw : !0
667
670
  };
668
671
  if (e)
669
672
  return {
@@ -684,21 +687,21 @@ function Et() {
684
687
  const r = window[et];
685
688
  if (r)
686
689
  return r;
687
- const t = ee();
688
- return window[et] = t, Xt(t.launchParams), t;
690
+ const t = Xt();
691
+ return window[et] = t, Kt(t.launchParams), t;
689
692
  }
690
- function er() {
693
+ function tr() {
691
694
  try {
692
695
  return Et(), !0;
693
696
  } catch {
694
697
  return !1;
695
698
  }
696
699
  }
697
- function re(r) {
698
- return "external" in r && D(r.external) && "notify" in r.external && typeof r.external.notify == "function";
700
+ function te(r) {
701
+ return "external" in r && O(r.external) && "notify" in r.external && typeof r.external.notify == "function";
699
702
  }
700
- function ne(r) {
701
- return "TelegramWebviewProxy" in r && D(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
703
+ function ee(r) {
704
+ return "TelegramWebviewProxy" in r && O(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
702
705
  }
703
706
  function Ct() {
704
707
  try {
@@ -713,8 +716,8 @@ class K extends Error {
713
716
  }
714
717
  }
715
718
  class Y extends Error {
716
- constructor(t, e, n) {
717
- super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${n}.`), Object.setPrototypeOf(this, Y.prototype);
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);
718
721
  }
719
722
  }
720
723
  class vt {
@@ -729,14 +732,14 @@ class vt {
729
732
  print(t, ...e) {
730
733
  if (!this.enabled)
731
734
  return;
732
- const n = /* @__PURE__ */ new Date(), s = Intl.DateTimeFormat("en-GB", {
735
+ const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
733
736
  hour: "2-digit",
734
737
  minute: "2-digit",
735
738
  second: "2-digit",
736
739
  fractionalSecondDigits: 3,
737
740
  timeZone: "UTC"
738
- }).format(n);
739
- console[t](`[${s}]`, this.prefix, ...e);
741
+ }).format(s);
742
+ console[t](`[${n}]`, this.prefix, ...e);
740
743
  }
741
744
  /**
742
745
  * Disables the logger.
@@ -774,29 +777,29 @@ class vt {
774
777
  }
775
778
  let kt = "https://web.telegram.org";
776
779
  const P = new vt("[SDK]", !1);
777
- function rr(r) {
780
+ function er(r) {
778
781
  if (r) {
779
782
  P.enable();
780
783
  return;
781
784
  }
782
785
  P.disable();
783
786
  }
784
- function nr(r) {
787
+ function rr(r) {
785
788
  kt = r;
786
789
  }
787
- function se() {
790
+ function re() {
788
791
  return kt;
789
792
  }
790
- const ie = g({
793
+ const se = g({
791
794
  eventType: h(),
792
795
  eventData: (r) => r
793
796
  });
794
- function oe(r, t) {
797
+ function ne(r, t) {
795
798
  window.dispatchEvent(new MessageEvent("message", {
796
799
  data: JSON.stringify({ eventType: r, eventData: t })
797
800
  }));
798
801
  }
799
- function ae() {
802
+ function ie() {
800
803
  const r = window;
801
804
  "TelegramGameProxy_receiveEvent" in r || [
802
805
  ["TelegramGameProxy_receiveEvent"],
@@ -807,78 +810,78 @@ function ae() {
807
810
  // Android and iOS.
808
811
  ].forEach((t) => {
809
812
  let e = r;
810
- t.forEach((n, s, i) => {
811
- if (s === i.length - 1) {
812
- e[n] = oe;
813
+ t.forEach((s, n, i) => {
814
+ if (n === i.length - 1) {
815
+ e[s] = ne;
813
816
  return;
814
817
  }
815
- n in e || (e[n] = {}), e = e[n];
818
+ s in e || (e[s] = {}), e = e[s];
816
819
  });
817
820
  });
818
821
  }
819
- function ce(r) {
820
- ae(), window.addEventListener("message", (t) => {
822
+ function oe(r) {
823
+ ie(), window.addEventListener("message", (t) => {
821
824
  try {
822
- const { eventType: e, eventData: n } = ie.parse(t.data);
823
- r(e, n);
825
+ const { eventType: e, eventData: s } = se.parse(t.data);
826
+ r(e, s);
824
827
  } catch {
825
828
  }
826
829
  });
827
830
  }
828
- function he() {
831
+ function ae() {
829
832
  return g({
830
833
  req_id: h(),
831
834
  data: (r) => r === null ? r : h().optional().parse(r)
832
835
  });
833
836
  }
834
- function ue() {
837
+ function ce() {
835
838
  return g({
836
839
  req_id: h(),
837
840
  result: (r) => r,
838
841
  error: h().optional()
839
842
  });
840
843
  }
841
- function pe() {
844
+ function he() {
842
845
  return g({
843
846
  slug: h(),
844
847
  status: h()
845
848
  });
846
849
  }
847
- function le() {
850
+ function ue() {
848
851
  return g({ status: h() });
849
852
  }
850
- function de() {
853
+ function pe() {
851
854
  return g({
852
855
  button_id: (r) => r == null ? void 0 : h().parse(r)
853
856
  });
854
857
  }
855
- function fe() {
858
+ function le() {
856
859
  return g({
857
860
  data: h().optional()
858
861
  });
859
862
  }
860
- function ge() {
863
+ function de() {
861
864
  return g({
862
865
  theme_params: (r) => {
863
866
  const t = dt().optional();
864
- return Object.entries(Z(r)).reduce((e, [n, s]) => (e[n] = t.parse(s), e), {});
867
+ return Object.entries(Z(r)).reduce((e, [s, n]) => (e[s] = t.parse(n), e), {});
865
868
  }
866
869
  });
867
870
  }
868
- function we() {
871
+ function fe() {
869
872
  return g({
870
- height: A(),
871
- width: (r) => r == null ? window.innerWidth : A().parse(r),
872
- is_state_stable: C(),
873
- is_expanded: C()
873
+ height: V(),
874
+ width: (r) => r == null ? window.innerWidth : V().parse(r),
875
+ is_state_stable: k(),
876
+ is_expanded: k()
874
877
  });
875
878
  }
876
- function _e() {
879
+ function ge() {
877
880
  return g({ status: h() });
878
881
  }
879
- function be() {
880
- const r = new w(), t = (e, ...n) => {
881
- P.log("Emitting processed event:", e, ...n), r.emit(e, ...n);
882
+ function _e() {
883
+ const r = new _(), t = (e, ...s) => {
884
+ P.log("Emitting processed event:", e, ...s), r.emit(e, ...s);
882
885
  };
883
886
  return window.addEventListener("resize", () => {
884
887
  t("viewport_changed", {
@@ -887,33 +890,33 @@ function be() {
887
890
  is_state_stable: !0,
888
891
  is_expanded: !0
889
892
  });
890
- }), ce((e, n) => {
891
- P.log("Received raw event:", e, n);
893
+ }), oe((e, s) => {
894
+ P.log("Received raw event:", e, s);
892
895
  try {
893
896
  switch (e) {
894
897
  case "viewport_changed":
895
- return t(e, we().parse(n));
898
+ return t(e, fe().parse(s));
896
899
  case "theme_changed":
897
- return t(e, ge().parse(n));
900
+ return t(e, de().parse(s));
898
901
  case "popup_closed":
899
902
  return (
900
903
  // Sent on desktop.
901
- n == null ? t(e, {}) : t(e, de().parse(n))
904
+ s == null ? t(e, {}) : t(e, pe().parse(s))
902
905
  );
903
906
  case "set_custom_style":
904
- return t(e, h().parse(n));
907
+ return t(e, h().parse(s));
905
908
  case "qr_text_received":
906
- return t(e, fe().parse(n));
909
+ return t(e, le().parse(s));
907
910
  case "clipboard_text_received":
908
- return t(e, he().parse(n));
911
+ return t(e, ae().parse(s));
909
912
  case "invoice_closed":
910
- return t(e, pe().parse(n));
913
+ return t(e, he().parse(s));
911
914
  case "phone_requested":
912
- return t("phone_requested", le().parse(n));
915
+ return t("phone_requested", ue().parse(s));
913
916
  case "custom_method_invoked":
914
- return t("custom_method_invoked", ue().parse(n));
917
+ return t("custom_method_invoked", ce().parse(s));
915
918
  case "write_access_requested":
916
- return t("write_access_requested", _e().parse(n));
919
+ return t("write_access_requested", ge().parse(s));
917
920
  case "main_button_pressed":
918
921
  case "back_button_pressed":
919
922
  case "settings_button_pressed":
@@ -921,51 +924,51 @@ function be() {
921
924
  case "reload_iframe":
922
925
  return t(e);
923
926
  default:
924
- return t(e, n);
927
+ return t(e, s);
925
928
  }
926
- } catch (s) {
927
- P.error("Error processing event:", s);
929
+ } catch (n) {
930
+ P.error("Error processing event:", n);
928
931
  }
929
932
  }), r;
930
933
  }
931
934
  const z = "telegram-mini-apps-cached-emitter";
932
- function H() {
935
+ function W() {
933
936
  const r = window;
934
- return r[z] === void 0 && (r[z] = be()), r[z];
937
+ return r[z] === void 0 && (r[z] = _e()), r[z];
935
938
  }
936
- function N(r, t) {
937
- H().off(r, t);
939
+ function $(r, t) {
940
+ W().off(r, t);
938
941
  }
939
- function k(r, t) {
940
- return H().on(r, t), () => N(r, t);
942
+ function m(r, t) {
943
+ return W().on(r, t), () => $(r, t);
941
944
  }
942
945
  function sr(r, t) {
943
- return H().once(r, t), () => N(r, t);
946
+ return W().once(r, t), () => $(r, t);
944
947
  }
945
- function me(r) {
946
- H().unsubscribe(r);
948
+ function we(r) {
949
+ W().unsubscribe(r);
947
950
  }
948
- function ir(r) {
949
- return H().subscribe(r), () => me(r);
951
+ function nr(r) {
952
+ return W().subscribe(r), () => we(r);
950
953
  }
951
- function ye(r, t) {
952
- const e = r.split("."), n = t.split("."), s = Math.max(e.length, n.length);
953
- for (let i = 0; i < s; i += 1) {
954
- const a = parseInt(e[i] || "0", 10), c = parseInt(n[i] || "0", 10);
954
+ function be(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);
955
958
  if (a !== c)
956
959
  return a > c ? 1 : -1;
957
960
  }
958
961
  return 0;
959
962
  }
960
- function E(r, t) {
961
- return ye(r, t) <= 0;
963
+ function v(r, t) {
964
+ return be(r, t) <= 0;
962
965
  }
963
- function q(r, t, e) {
966
+ function A(r, t, e) {
964
967
  if (typeof e == "string") {
965
968
  if (r === "web_app_open_link" && t === "try_instant_view")
966
- return E("6.4", e);
969
+ return v("6.4", e);
967
970
  if (r === "web_app_set_header_color" && t === "color")
968
- return E("6.9", e);
971
+ return v("6.9", e);
969
972
  }
970
973
  switch (r) {
971
974
  case "web_app_open_tg_link":
@@ -974,65 +977,65 @@ function q(r, t, e) {
974
977
  case "web_app_set_background_color":
975
978
  case "web_app_set_header_color":
976
979
  case "web_app_trigger_haptic_feedback":
977
- return E("6.1", t);
980
+ return v("6.1", t);
978
981
  case "web_app_open_popup":
979
- return E("6.2", t);
982
+ return v("6.2", t);
980
983
  case "web_app_close_scan_qr_popup":
981
984
  case "web_app_open_scan_qr_popup":
982
985
  case "web_app_read_text_from_clipboard":
983
- return E("6.4", t);
986
+ return v("6.4", t);
984
987
  case "web_app_switch_inline_query":
985
- return E("6.7", t);
988
+ return v("6.7", t);
986
989
  case "web_app_invoke_custom_method":
987
990
  case "web_app_request_write_access":
988
991
  case "web_app_request_phone":
989
- return E("6.9", t);
992
+ return v("6.9", t);
990
993
  case "web_app_setup_settings_button":
991
- return E("6.10", t);
994
+ return v("6.10", t);
992
995
  default:
993
996
  return !0;
994
997
  }
995
998
  }
996
- function S(r, t) {
997
- return (e) => q(t[e], r);
999
+ function y(r, t) {
1000
+ return (e) => A(t[e], r);
998
1001
  }
999
1002
  function St(r, t) {
1000
1003
  return (e) => {
1001
- const [n, s] = t[e];
1002
- return q(n, s, r);
1004
+ const [s, n] = t[e];
1005
+ return A(s, n, r);
1003
1006
  };
1004
1007
  }
1005
1008
  function f(r, t, e) {
1006
- let n = {}, s;
1007
- 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);
1008
- const { targetOrigin: i = se() } = n;
1009
- 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 = re() } = s;
1012
+ if (P.log(`Calling method "${r}"`, n), Ct()) {
1010
1013
  window.parent.postMessage(JSON.stringify({
1011
1014
  eventType: r,
1012
- eventData: s
1015
+ eventData: n
1013
1016
  }), i);
1014
1017
  return;
1015
1018
  }
1016
- if (re(window)) {
1017
- window.external.notify(JSON.stringify({ eventType: r, eventData: s }));
1019
+ if (te(window)) {
1020
+ window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
1018
1021
  return;
1019
1022
  }
1020
- if (ne(window)) {
1021
- window.TelegramWebviewProxy.postEvent(r, JSON.stringify(s));
1023
+ if (ee(window)) {
1024
+ window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
1022
1025
  return;
1023
1026
  }
1024
1027
  throw new Error(
1025
1028
  "Unable to determine current environment and possible way to send event."
1026
1029
  );
1027
1030
  }
1028
- function Ee(r) {
1031
+ function me(r) {
1029
1032
  return (t, e) => {
1030
- if (!q(t, r))
1033
+ if (!A(t, r))
1031
1034
  throw new K(t, r);
1032
- if (D(e)) {
1033
- let n;
1034
- 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))
1035
- throw new Y(t, n, r);
1035
+ if (O(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 Y(t, s, r);
1036
1039
  }
1037
1040
  return f(t, e);
1038
1041
  };
@@ -1047,48 +1050,48 @@ function rt(r) {
1047
1050
  setTimeout(e, r, new X(r));
1048
1051
  });
1049
1052
  }
1050
- function Ce(r, t) {
1053
+ function ye(r, t) {
1051
1054
  return typeof r == "function" ? (...e) => Promise.race([
1052
1055
  r(...e),
1053
1056
  rt(t)
1054
1057
  ]) : Promise.race([r, rt(t)]);
1055
1058
  }
1056
- function _(r, t, e, n) {
1057
- let s, i, a, c;
1058
- 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);
1059
- const { postEvent: u = f, timeout: l } = s || {}, p = s && "capture" in s ? s.capture : null, m = new Promise((d, y) => {
1060
- const x = a.map((T) => k(T, (M) => {
1061
- typeof c == "string" && (!D(M) || M.req_id !== c) || typeof p == "function" && !p(M) || (V(), d(M));
1062
- })), V = () => x.forEach((T) => T());
1059
+ function b(r, t, e, s) {
1060
+ 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());
1063
1066
  try {
1064
1067
  u(r, i);
1065
- } catch (T) {
1066
- V(), y(T);
1068
+ } catch (B) {
1069
+ R(), C(B);
1067
1070
  }
1068
1071
  });
1069
- return typeof l == "number" ? Ce(m, l) : m;
1072
+ return typeof d == "number" ? ye(E, d) : E;
1070
1073
  }
1071
- class ve {
1072
- constructor(t, e, n = f) {
1073
- o(this, "ee", new w());
1074
+ class Ee {
1075
+ constructor(t, e, s = f) {
1076
+ o(this, "ee", new _());
1074
1077
  o(this, "state");
1075
1078
  /**
1076
1079
  * Adds event listener.
1077
1080
  * @param event - event name.
1078
1081
  * @param listener - event listener.
1079
1082
  */
1080
- o(this, "on", (t, e) => t === "click" ? k("back_button_pressed", e) : this.ee.on(t, e));
1083
+ o(this, "on", (t, e) => t === "click" ? m("back_button_pressed", e) : this.ee.on(t, e));
1081
1084
  /**
1082
1085
  * Removes event listener.
1083
1086
  * @param event - event name.
1084
1087
  * @param listener - event listener.
1085
1088
  */
1086
- o(this, "off", (t, e) => t === "click" ? N("back_button_pressed", e) : this.ee.off(t, e));
1089
+ o(this, "off", (t, e) => t === "click" ? $("back_button_pressed", e) : this.ee.off(t, e));
1087
1090
  /**
1088
1091
  * Checks if specified method is supported by current component.
1089
1092
  */
1090
1093
  o(this, "supports");
1091
- this.postEvent = n, this.state = new b({ isVisible: t }, this.ee), this.supports = S(e, {
1094
+ this.postEvent = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(e, {
1092
1095
  show: "web_app_setup_back_button",
1093
1096
  hide: "web_app_setup_back_button"
1094
1097
  });
@@ -1115,27 +1118,27 @@ class ve {
1115
1118
  this.isVisible = !0;
1116
1119
  }
1117
1120
  }
1118
- function nt(r, t) {
1121
+ function st(r, t) {
1119
1122
  return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
1120
1123
  }
1121
- function ke(...r) {
1124
+ function Ce(...r) {
1122
1125
  return r.reduce((t, e) => {
1123
- let n = "";
1124
- 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);
1126
+ 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);
1125
1128
  }, "");
1126
1129
  }
1127
- function Se(r) {
1130
+ function ve(r) {
1128
1131
  return typeof r == "object" && r !== null && !Array.isArray(null);
1129
1132
  }
1130
- function or(...r) {
1131
- return r.reduce((t, e) => (Se(e) && Object.entries(e).forEach(([n, s]) => {
1132
- const i = ke(t[n], s);
1133
- i.length > 0 && (t[n] = i);
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);
1136
+ i.length > 0 && (t[s] = i);
1134
1137
  }), t), {});
1135
1138
  }
1136
- class xe {
1139
+ class ke {
1137
1140
  constructor(t, e = f) {
1138
- o(this, "ee", new w());
1141
+ o(this, "ee", new _());
1139
1142
  o(this, "state");
1140
1143
  /**
1141
1144
  * Adds new event listener.
@@ -1145,7 +1148,7 @@ class xe {
1145
1148
  * Removes event listener.
1146
1149
  */
1147
1150
  o(this, "off", this.ee.off.bind(this.ee));
1148
- this.postEvent = e, this.state = new b({ isConfirmationNeeded: t }, this.ee);
1151
+ this.postEvent = e, this.state = new w({ isConfirmationNeeded: t }, this.ee);
1149
1152
  }
1150
1153
  set isConfirmationNeeded(t) {
1151
1154
  this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
@@ -1172,17 +1175,16 @@ class xe {
1172
1175
  this.isConfirmationNeeded = !0;
1173
1176
  }
1174
1177
  }
1175
- const Pe = Bt().of(h());
1176
- function st(r, t) {
1177
- return r.reduce((e, n) => (e[n] = t, e), {});
1178
+ function nt(r, t) {
1179
+ return r.reduce((e, s) => (e[s] = t, e), {});
1178
1180
  }
1179
- class Ae {
1180
- constructor(t, e, n = f) {
1181
+ class Se {
1182
+ constructor(t, e, s = f) {
1181
1183
  /**
1182
1184
  * Checks if specified method is supported by current component.
1183
1185
  */
1184
1186
  o(this, "supports");
1185
- this.createRequestId = e, this.postEvent = n, this.supports = S(t, {
1187
+ this.createRequestId = e, this.postEvent = s, this.supports = y(t, {
1186
1188
  delete: "web_app_invoke_custom_method",
1187
1189
  get: "web_app_invoke_custom_method",
1188
1190
  getKeys: "web_app_invoke_custom_method",
@@ -1195,16 +1197,16 @@ class Ae {
1195
1197
  * @param params - method parameters.
1196
1198
  * @param options - execution options.
1197
1199
  */
1198
- async invokeCustomMethod(t, e, n = {}) {
1199
- const { result: s, error: i } = await _(
1200
+ async invokeCustomMethod(t, e, s = {}) {
1201
+ const { result: n, error: i } = await b(
1200
1202
  "web_app_invoke_custom_method",
1201
1203
  { method: t, params: e, req_id: this.createRequestId() },
1202
1204
  "custom_method_invoked",
1203
- { ...n, postEvent: this.postEvent }
1205
+ { ...s, postEvent: this.postEvent }
1204
1206
  );
1205
1207
  if (i)
1206
1208
  throw new Error(i);
1207
- return s;
1209
+ return n;
1208
1210
  }
1209
1211
  /**
1210
1212
  * Deletes specified key or keys from the cloud storage.
@@ -1212,8 +1214,8 @@ class Ae {
1212
1214
  * @param options - request execution options.
1213
1215
  */
1214
1216
  async delete(t, e) {
1215
- const n = Array.isArray(t) ? t : [t];
1216
- n.length !== 0 && await this.invokeCustomMethod("deleteStorageValues", { keys: n }, e);
1217
+ const s = Array.isArray(t) ? t : [t];
1218
+ s.length !== 0 && await this.invokeCustomMethod("deleteStorageValues", { keys: s }, e);
1217
1219
  }
1218
1220
  /**
1219
1221
  * Returns list of all keys presented in the cloud storage.
@@ -1221,15 +1223,15 @@ class Ae {
1221
1223
  */
1222
1224
  async getKeys(t) {
1223
1225
  const e = await this.invokeCustomMethod("getStorageKeys", {}, t);
1224
- return Pe.parse(e);
1226
+ return Dt().of(h()).parse(e);
1225
1227
  }
1226
1228
  async get(t, e) {
1227
- const n = Array.isArray(t) ? t : [t];
1228
- if (n.length === 0)
1229
- return st(n, "");
1230
- const s = g(
1231
- st(n, h())
1232
- ), i = await this.invokeCustomMethod("getStorageValues", { keys: n }, e).then((a) => s.parse(a));
1229
+ const s = Array.isArray(t) ? t : [t];
1230
+ if (s.length === 0)
1231
+ return nt(s, "");
1232
+ const n = g(
1233
+ nt(s, h())
1234
+ ), i = await this.invokeCustomMethod("getStorageValues", { keys: s }, e).then((a) => n.parse(a));
1233
1235
  return Array.isArray(t) ? i : i[t];
1234
1236
  }
1235
1237
  /**
@@ -1238,17 +1240,17 @@ class Ae {
1238
1240
  * @param value - storage value.
1239
1241
  * @param options - request execution options.
1240
1242
  */
1241
- async set(t, e, n) {
1242
- await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, n);
1243
+ async set(t, e, s) {
1244
+ await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, s);
1243
1245
  }
1244
1246
  }
1245
- class qe {
1247
+ class xe {
1246
1248
  constructor(t, e = f) {
1247
1249
  /**
1248
1250
  * Checks if specified method is supported by current component.
1249
1251
  */
1250
1252
  o(this, "supports");
1251
- this.postEvent = e, this.supports = S(t, {
1253
+ this.postEvent = e, this.supports = y(t, {
1252
1254
  impactOccurred: "web_app_trigger_haptic_feedback",
1253
1255
  notificationOccurred: "web_app_trigger_haptic_feedback",
1254
1256
  selectionChanged: "web_app_trigger_haptic_feedback"
@@ -1288,37 +1290,37 @@ class qe {
1288
1290
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1289
1291
  }
1290
1292
  }
1291
- function Le() {
1293
+ function Pe() {
1292
1294
  const r = document.createElement("style");
1293
- r.id = "telegram-custom-styles", document.head.appendChild(r), k("set_custom_style", (t) => {
1295
+ r.id = "telegram-custom-styles", document.head.appendChild(r), m("set_custom_style", (t) => {
1294
1296
  r.innerHTML = t;
1295
1297
  });
1296
1298
  }
1297
1299
  function xt(r) {
1298
1300
  return `telegram-mini-apps-${r}`;
1299
1301
  }
1300
- function O(r, t) {
1302
+ function T(r, t) {
1301
1303
  sessionStorage.setItem(xt(r), JSON.stringify(t));
1302
1304
  }
1303
- function W(r) {
1305
+ function I(r) {
1304
1306
  const t = sessionStorage.getItem(xt(r));
1305
1307
  return t ? JSON.parse(t) : null;
1306
1308
  }
1307
- function $e(r, t, e) {
1308
- const { isVisible: n = !1 } = r ? W("back-button") || {} : {}, s = new ve(n, t, e);
1309
- return s.on("change", () => {
1310
- O("back-button", { isVisible: s.isVisible });
1311
- }), s;
1309
+ function Ve(r, t, e) {
1310
+ const { isVisible: s = !1 } = r ? I("back-button") || {} : {}, n = new Ee(s, t, e);
1311
+ return n.on("change", () => {
1312
+ T("back-button", { isVisible: n.isVisible });
1313
+ }), n;
1312
1314
  }
1313
- function Ve(r, t) {
1314
- const { isConfirmationNeeded: e = !1 } = r ? W("closing-behavior") || {} : {}, n = new xe(e, t);
1315
- return n.on("change", () => O("closing-behavior", {
1316
- isConfirmationNeeded: n.isConfirmationNeeded
1317
- })), n;
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", {
1318
+ isConfirmationNeeded: s.isConfirmationNeeded
1319
+ })), s;
1318
1320
  }
1319
- class Te {
1321
+ class qe {
1320
1322
  constructor(t) {
1321
- o(this, "ee", new w());
1323
+ o(this, "ee", new _());
1322
1324
  o(this, "state");
1323
1325
  o(this, "postEvent");
1324
1326
  /**
@@ -1330,30 +1332,30 @@ class Te {
1330
1332
  // FIXME: Event 'main_button_pressed' is still being received on Android
1331
1333
  // even if the main button is disabled.
1332
1334
  // Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
1333
- t === "click" ? k("main_button_pressed", e) : this.ee.on(t, e)
1335
+ t === "click" ? m("main_button_pressed", e) : this.ee.on(t, e)
1334
1336
  ));
1335
1337
  /**
1336
1338
  * Removes event listener.
1337
1339
  * @param event - event name.
1338
1340
  * @param listener - event listener.
1339
1341
  */
1340
- o(this, "off", (t, e) => t === "click" ? N("main_button_pressed", e) : this.ee.off(t, e));
1342
+ o(this, "off", (t, e) => t === "click" ? $("main_button_pressed", e) : this.ee.off(t, e));
1341
1343
  const {
1342
1344
  postEvent: e = f,
1343
- text: n,
1344
- textColor: s,
1345
+ text: s,
1346
+ textColor: n,
1345
1347
  backgroundColor: i,
1346
1348
  isEnabled: a,
1347
1349
  isVisible: c,
1348
1350
  isLoaderVisible: u
1349
1351
  } = t;
1350
- this.postEvent = e, this.state = new b({
1352
+ this.postEvent = e, this.state = new w({
1351
1353
  backgroundColor: i,
1352
1354
  isEnabled: a,
1353
1355
  isVisible: c,
1354
1356
  isLoaderVisible: u,
1355
- text: n,
1356
- textColor: s
1357
+ text: s,
1358
+ textColor: n
1357
1359
  }, this.ee);
1358
1360
  }
1359
1361
  /**
@@ -1481,23 +1483,23 @@ class Te {
1481
1483
  return this.state.set(t), this.commit(), this;
1482
1484
  }
1483
1485
  }
1484
- function Ie(r, t, e, n) {
1486
+ function Le(r, t, e, s) {
1485
1487
  const {
1486
- backgroundColor: s = t,
1488
+ backgroundColor: n = t,
1487
1489
  isEnabled: i = !1,
1488
1490
  isVisible: a = !1,
1489
1491
  isLoaderVisible: c = !1,
1490
1492
  textColor: u = e,
1491
- text: l = ""
1492
- } = r ? W("main-button") || {} : {}, p = new Te({
1493
- backgroundColor: s,
1493
+ text: d = ""
1494
+ } = r ? I("main-button") || {} : {}, p = new qe({
1495
+ backgroundColor: n,
1494
1496
  isEnabled: i,
1495
1497
  isLoaderVisible: c,
1496
1498
  isVisible: a,
1497
- postEvent: n,
1498
- text: l,
1499
+ postEvent: s,
1500
+ text: d,
1499
1501
  textColor: u
1500
- }), m = () => O("main-button", {
1502
+ }), E = () => T("main-button", {
1501
1503
  backgroundColor: p.backgroundColor,
1502
1504
  isEnabled: p.isEnabled,
1503
1505
  isLoaderVisible: p.isLoaderVisible,
@@ -1505,11 +1507,11 @@ function Ie(r, t, e, n) {
1505
1507
  text: p.text,
1506
1508
  textColor: p.textColor
1507
1509
  });
1508
- return p.on("change", m), p;
1510
+ return p.on("change", E), p;
1509
1511
  }
1510
- class Re {
1512
+ class $e {
1511
1513
  constructor(t) {
1512
- o(this, "ee", new w());
1514
+ o(this, "ee", new _());
1513
1515
  o(this, "state");
1514
1516
  o(this, "botInline");
1515
1517
  o(this, "postEvent");
@@ -1531,18 +1533,18 @@ class Re {
1531
1533
  o(this, "supportsParam");
1532
1534
  const {
1533
1535
  postEvent: e = f,
1534
- headerColor: n,
1535
- backgroundColor: s,
1536
+ headerColor: s,
1537
+ backgroundColor: n,
1536
1538
  version: i,
1537
1539
  botInline: a
1538
- } = t, c = S(i, {
1540
+ } = t, c = y(i, {
1539
1541
  requestPhoneAccess: "web_app_request_phone",
1540
1542
  requestWriteAccess: "web_app_request_write_access",
1541
1543
  switchInlineQuery: "web_app_switch_inline_query",
1542
1544
  setHeaderColor: "web_app_set_header_color",
1543
1545
  setBackgroundColor: "web_app_set_background_color"
1544
1546
  });
1545
- 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, {
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, {
1546
1548
  "setHeaderColor.color": ["web_app_set_header_color", "color"]
1547
1549
  });
1548
1550
  }
@@ -1592,7 +1594,7 @@ class Re {
1592
1594
  * Requests current user phone access.
1593
1595
  */
1594
1596
  requestPhoneAccess() {
1595
- return _(
1597
+ return b(
1596
1598
  "web_app_request_phone",
1597
1599
  "phone_requested",
1598
1600
  { postEvent: this.postEvent }
@@ -1602,7 +1604,7 @@ class Re {
1602
1604
  * Requests write message access to current user.
1603
1605
  */
1604
1606
  requestWriteAccess() {
1605
- return _(
1607
+ return b(
1606
1608
  "web_app_request_write_access",
1607
1609
  "write_access_requested",
1608
1610
  { postEvent: this.postEvent }
@@ -1656,32 +1658,85 @@ class Re {
1656
1658
  });
1657
1659
  }
1658
1660
  }
1659
- function Be(r, t, e, n, s) {
1661
+ function Te(r, t, e, s, n) {
1660
1662
  const {
1661
1663
  backgroundColor: i = t,
1662
1664
  headerColor: a = "bg_color"
1663
- } = r ? W("mini-app") || {} : {}, c = new Re({
1665
+ } = r ? I("mini-app") || {} : {}, c = new $e({
1664
1666
  headerColor: a,
1665
1667
  backgroundColor: i,
1666
1668
  version: e,
1667
- botInline: n,
1668
- postEvent: s
1669
- }), u = () => O("mini-app", {
1669
+ botInline: s,
1670
+ postEvent: n
1671
+ }), u = () => T("mini-app", {
1670
1672
  backgroundColor: c.backgroundColor,
1671
1673
  headerColor: c.headerColor
1672
1674
  });
1673
1675
  return c.on("change", u), c;
1674
1676
  }
1675
- function De() {
1677
+ function Ie() {
1676
1678
  let r = 0;
1677
1679
  return () => (r += 1, r.toString());
1678
1680
  }
1679
- function He(r) {
1680
- const t = new zt(r);
1681
+ class Re {
1682
+ constructor(t, e, s = f) {
1683
+ o(this, "ee", new _());
1684
+ o(this, "state");
1685
+ /**
1686
+ * Adds event listener.
1687
+ * @param event - event name.
1688
+ * @param listener - event listener.
1689
+ */
1690
+ o(this, "on", (t, e) => t === "click" ? m("settings_button_pressed", e) : this.ee.on(t, e));
1691
+ /**
1692
+ * Removes event listener.
1693
+ * @param event - event name.
1694
+ * @param listener - event listener.
1695
+ */
1696
+ o(this, "off", (t, e) => t === "click" ? $("settings_button_pressed", e) : this.ee.off(t, e));
1697
+ /**
1698
+ * Checks if specified method is supported by current component.
1699
+ */
1700
+ o(this, "supports");
1701
+ this.postEvent = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(e, {
1702
+ show: "web_app_setup_settings_button",
1703
+ hide: "web_app_setup_settings_button"
1704
+ });
1705
+ }
1706
+ set isVisible(t) {
1707
+ this.state.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
1708
+ }
1709
+ /**
1710
+ * True if SettingsButton is currently visible.
1711
+ */
1712
+ get isVisible() {
1713
+ return this.state.get("isVisible");
1714
+ }
1715
+ /**
1716
+ * Hides the SettingsButton.
1717
+ */
1718
+ hide() {
1719
+ this.isVisible = !1;
1720
+ }
1721
+ /**
1722
+ * Shows the SettingsButton.
1723
+ */
1724
+ show() {
1725
+ this.isVisible = !0;
1726
+ }
1727
+ }
1728
+ function Be(r, t, e) {
1729
+ const { isVisible: s = !1 } = r ? I("settings-button") || {} : {}, n = new Re(s, t, e);
1730
+ return n.on("change", () => {
1731
+ T("settings-button", { isVisible: n.isVisible });
1732
+ }), n;
1733
+ }
1734
+ function De(r) {
1735
+ const t = new Gt(r);
1681
1736
  return t.listen(), t;
1682
1737
  }
1683
1738
  async function Pt(r) {
1684
- const t = await _("web_app_request_viewport", "viewport_changed", r);
1739
+ const t = await b("web_app_request_viewport", "viewport_changed", r);
1685
1740
  return {
1686
1741
  height: t.height,
1687
1742
  width: t.width,
@@ -1689,12 +1744,12 @@ async function Pt(r) {
1689
1744
  isStateStable: t.is_state_stable
1690
1745
  };
1691
1746
  }
1692
- function I(r) {
1747
+ function D(r) {
1693
1748
  return r < 0 ? 0 : r;
1694
1749
  }
1695
1750
  class j {
1696
1751
  constructor(t) {
1697
- o(this, "ee", new w());
1752
+ o(this, "ee", new _());
1698
1753
  o(this, "state");
1699
1754
  o(this, "postEvent");
1700
1755
  /**
@@ -1707,16 +1762,16 @@ class j {
1707
1762
  o(this, "off", this.ee.off.bind(this.ee));
1708
1763
  const {
1709
1764
  height: e,
1710
- isExpanded: n,
1711
- width: s,
1765
+ isExpanded: s,
1766
+ width: n,
1712
1767
  stableHeight: i,
1713
1768
  postEvent: a = f
1714
1769
  } = t;
1715
- this.postEvent = a, this.state = new b({
1716
- height: I(e),
1717
- isExpanded: n,
1718
- stableHeight: I(i),
1719
- width: I(s)
1770
+ this.postEvent = a, this.state = new w({
1771
+ height: D(e),
1772
+ isExpanded: s,
1773
+ stableHeight: D(i),
1774
+ width: D(n)
1720
1775
  }, this.ee);
1721
1776
  }
1722
1777
  /**
@@ -1725,11 +1780,11 @@ class j {
1725
1780
  * @param options - options to request fresh data.
1726
1781
  */
1727
1782
  sync(t) {
1728
- return Pt(t).then(({ height: e, isExpanded: n, width: s, isStateStable: i }) => {
1783
+ return Pt(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
1729
1784
  this.state.set({
1730
1785
  height: e,
1731
- width: s,
1732
- isExpanded: n,
1786
+ width: n,
1787
+ isExpanded: s,
1733
1788
  stableHeight: i ? e : this.state.get("stableHeight")
1734
1789
  });
1735
1790
  });
@@ -1775,16 +1830,16 @@ class j {
1775
1830
  * @returns Function to stop listening.
1776
1831
  */
1777
1832
  listen() {
1778
- return k("viewport_changed", (t) => {
1833
+ return m("viewport_changed", (t) => {
1779
1834
  const {
1780
1835
  height: e,
1781
- width: n,
1782
- is_expanded: s,
1836
+ width: s,
1837
+ is_expanded: n,
1783
1838
  is_state_stable: i
1784
1839
  } = t, a = {
1785
- height: I(e),
1786
- isExpanded: s,
1787
- width: I(n)
1840
+ height: D(e),
1841
+ isExpanded: n,
1842
+ width: D(s)
1788
1843
  };
1789
1844
  i && (a.stableHeight = a.height), this.state.set(a);
1790
1845
  });
@@ -1821,8 +1876,11 @@ class j {
1821
1876
  return this.stableHeight === this.height;
1822
1877
  }
1823
1878
  }
1879
+ function Vt(r) {
1880
+ return !["macos", "web", "weba"].includes(r);
1881
+ }
1824
1882
  function At(r, t, e) {
1825
- if (r || t === "macos" || t === "web" || t === "weba")
1883
+ if (r || !Vt(t))
1826
1884
  return new j({
1827
1885
  height: window.innerHeight,
1828
1886
  isExpanded: !0,
@@ -1830,19 +1888,19 @@ function At(r, t, e) {
1830
1888
  stableHeight: window.innerHeight,
1831
1889
  width: window.innerWidth
1832
1890
  });
1833
- const n = W("viewport");
1834
- return n ? new j({ ...n, postEvent: e }) : null;
1891
+ const s = I("viewport");
1892
+ return s ? new j({ ...s, postEvent: e }) : null;
1835
1893
  }
1836
1894
  function qt(r) {
1837
- return r.listen(), r.on("change", () => O("viewport", {
1895
+ return r.listen(), r.on("change", () => T("viewport", {
1838
1896
  height: r.height,
1839
1897
  isExpanded: r.isExpanded,
1840
1898
  stableHeight: r.stableHeight,
1841
1899
  width: r.width
1842
1900
  })), r;
1843
1901
  }
1844
- function Ne(r, t, e) {
1845
- const n = qt(
1902
+ function He(r, t, e) {
1903
+ const s = qt(
1846
1904
  At(r, t, e) || new j({
1847
1905
  width: 0,
1848
1906
  height: 0,
@@ -1851,73 +1909,73 @@ function Ne(r, t, e) {
1851
1909
  stableHeight: 0
1852
1910
  })
1853
1911
  );
1854
- return n.sync({ postEvent: e, timeout: 100 }).catch((s) => {
1855
- console.error("Unable to actualize viewport state", s);
1856
- }), n;
1912
+ return Vt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
1913
+ console.error("Unable to actualize viewport state", n);
1914
+ }), s;
1857
1915
  }
1858
- async function Oe(r, t, e) {
1916
+ async function Ne(r, t, e) {
1859
1917
  return qt(
1860
- At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: n, isStateStable: s, ...i }) => new j({
1918
+ At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: s, isStateStable: n, ...i }) => new j({
1861
1919
  ...i,
1862
- height: n,
1863
- stableHeight: s ? n : 0
1920
+ height: s,
1921
+ stableHeight: n ? s : 0
1864
1922
  }))
1865
1923
  );
1866
1924
  }
1867
- function v(r, t) {
1925
+ function S(r, t) {
1868
1926
  document.documentElement.style.setProperty(r, t);
1869
1927
  }
1870
- function We(r, t) {
1928
+ function Oe(r, t) {
1871
1929
  const e = () => {
1872
- v("--tg-background-color", r.backgroundColor);
1873
- }, n = () => {
1930
+ S("--tg-background-color", r.backgroundColor);
1931
+ }, s = () => {
1874
1932
  const {
1875
- backgroundColor: s,
1933
+ backgroundColor: n,
1876
1934
  secondaryBackgroundColor: i
1877
1935
  } = t;
1878
- 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);
1936
+ 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);
1879
1937
  };
1880
- t.on("change", n), r.on("change:backgroundColor", e), r.on("change:headerColor", n), e(), n();
1938
+ t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
1881
1939
  }
1882
- function Me(r) {
1940
+ function We(r) {
1883
1941
  const t = () => {
1884
1942
  const e = r.getState();
1885
- Object.entries(e).forEach(([n, s]) => {
1886
- if (s) {
1887
- const i = n.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
1888
- v(`--tg-theme-${i}`, s);
1943
+ Object.entries(e).forEach(([s, n]) => {
1944
+ if (n) {
1945
+ const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
1946
+ S(`--tg-theme-${i}`, n);
1889
1947
  }
1890
1948
  });
1891
1949
  };
1892
1950
  r.on("change", t), t();
1893
1951
  }
1894
1952
  function it(r) {
1895
- 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`);
1896
- r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", n), t(), e(), n();
1953
+ 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
+ r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
1897
1955
  }
1898
- function Ue(r) {
1956
+ function Me(r) {
1899
1957
  return typeof r == "object" ? r : r ? {
1900
1958
  themeParams: !0,
1901
1959
  viewport: !0,
1902
1960
  miniApp: !0
1903
1961
  } : {};
1904
1962
  }
1905
- function ot(r, t, e, n) {
1906
- const s = Ue(r);
1907
- s.miniApp && We(t, e), s.themeParams && Me(e), s.viewport && (n instanceof Promise ? n.then(it) : it(n));
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));
1908
1966
  }
1909
- function je(r) {
1967
+ function Ue(r) {
1910
1968
  const { hostname: t, pathname: e } = new URL(r, window.location.href);
1911
1969
  if (t !== "t.me")
1912
1970
  throw new Error(`Incorrect hostname: ${t}`);
1913
- const n = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1914
- if (n === null)
1971
+ const s = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1972
+ if (s === null)
1915
1973
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1916
- return n[2];
1974
+ return s[2];
1917
1975
  }
1918
- class Ge {
1976
+ class je {
1919
1977
  constructor(t, e = f) {
1920
- o(this, "ee", new w());
1978
+ o(this, "ee", new _());
1921
1979
  o(this, "state");
1922
1980
  /**
1923
1981
  * Adds new event listener.
@@ -1931,7 +1989,7 @@ class Ge {
1931
1989
  * Checks if specified method is supported by current component.
1932
1990
  */
1933
1991
  o(this, "supports");
1934
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, { open: "web_app_open_invoice" });
1992
+ this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_invoice" });
1935
1993
  }
1936
1994
  set isOpened(t) {
1937
1995
  this.state.set("isOpened", t);
@@ -1945,17 +2003,17 @@ class Ge {
1945
2003
  async open(t, e) {
1946
2004
  if (this.isOpened)
1947
2005
  throw new Error("Invoice is already opened");
1948
- const n = e ? je(t) : t;
2006
+ const s = e ? Ue(t) : t;
1949
2007
  this.isOpened = !0;
1950
2008
  try {
1951
- return (await _(
2009
+ return (await b(
1952
2010
  "web_app_open_invoice",
1953
- { slug: n },
2011
+ { slug: s },
1954
2012
  "invoice_closed",
1955
2013
  {
1956
2014
  postEvent: this.postEvent,
1957
2015
  capture(i) {
1958
- return n === i.slug;
2016
+ return s === i.slug;
1959
2017
  }
1960
2018
  }
1961
2019
  )).status;
@@ -1964,16 +2022,16 @@ class Ge {
1964
2022
  }
1965
2023
  }
1966
2024
  }
1967
- function Fe(r) {
1968
- const t = r.message.trim(), e = (r.title || "").trim(), n = r.buttons || [];
1969
- let s;
2025
+ function Ge(r) {
2026
+ const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
2027
+ let n;
1970
2028
  if (e.length > 64)
1971
2029
  throw new Error(`Title has incorrect size: ${e.length}`);
1972
2030
  if (t.length === 0 || t.length > 256)
1973
2031
  throw new Error(`Message has incorrect size: ${t.length}`);
1974
- if (n.length > 3)
1975
- throw new Error(`Buttons have incorrect size: ${n.length}`);
1976
- return n.length === 0 ? s = [{ type: "close", id: "" }] : s = n.map((i) => {
2032
+ if (s.length > 3)
2033
+ throw new Error(`Buttons have incorrect size: ${s.length}`);
2034
+ return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
1977
2035
  const { id: a = "" } = i;
1978
2036
  if (a.length > 64)
1979
2037
  throw new Error(`Button ID has incorrect size: ${a}`);
@@ -1986,11 +2044,11 @@ function Fe(r) {
1986
2044
  return { ...i, text: c, id: a };
1987
2045
  }
1988
2046
  return { ...i, id: a };
1989
- }), { title: e, message: t, buttons: s };
2047
+ }), { title: e, message: t, buttons: n };
1990
2048
  }
1991
- class ze {
2049
+ class Fe {
1992
2050
  constructor(t, e = f) {
1993
- o(this, "ee", new w());
2051
+ o(this, "ee", new _());
1994
2052
  o(this, "state");
1995
2053
  /**
1996
2054
  * Adds new event listener.
@@ -2004,7 +2062,7 @@ class ze {
2004
2062
  * Checks if specified method is supported by current component.
2005
2063
  */
2006
2064
  o(this, "supports");
2007
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, { open: "web_app_open_popup" });
2065
+ this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_popup" });
2008
2066
  }
2009
2067
  set isOpened(t) {
2010
2068
  this.state.set("isOpened", t);
@@ -2031,9 +2089,9 @@ class ze {
2031
2089
  open(t) {
2032
2090
  if (this.isOpened)
2033
2091
  throw new Error("Popup is already opened.");
2034
- return this.isOpened = !0, _(
2092
+ return this.isOpened = !0, b(
2035
2093
  "web_app_open_popup",
2036
- Fe(t),
2094
+ Ge(t),
2037
2095
  "popup_closed",
2038
2096
  { postEvent: this.postEvent }
2039
2097
  ).then(({ button_id: e = null }) => e).finally(() => {
@@ -2041,9 +2099,9 @@ class ze {
2041
2099
  });
2042
2100
  }
2043
2101
  }
2044
- class Je {
2102
+ class ze {
2045
2103
  constructor(t, e = f) {
2046
- o(this, "ee", new w());
2104
+ o(this, "ee", new _());
2047
2105
  o(this, "state");
2048
2106
  /**
2049
2107
  * Adds new event listener.
@@ -2057,7 +2115,7 @@ class Je {
2057
2115
  * Checks if specified method is supported by current component.
2058
2116
  */
2059
2117
  o(this, "supports");
2060
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = S(t, {
2118
+ this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, {
2061
2119
  close: "web_app_close_scan_qr_popup",
2062
2120
  open: "web_app_open_scan_qr_popup"
2063
2121
  });
@@ -2088,7 +2146,7 @@ class Je {
2088
2146
  throw new Error("QR scanner is already opened.");
2089
2147
  this.isOpened = !0;
2090
2148
  try {
2091
- const e = await _(
2149
+ const e = await b(
2092
2150
  "web_app_open_scan_qr_popup",
2093
2151
  { text: t },
2094
2152
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -2100,8 +2158,8 @@ class Je {
2100
2158
  }
2101
2159
  }
2102
2160
  }
2103
- class Qe {
2104
- constructor(t, e, n = f) {
2161
+ class Je {
2162
+ constructor(t, e, s = f) {
2105
2163
  /**
2106
2164
  * Checks if specified method is supported by current component.
2107
2165
  */
@@ -2110,7 +2168,7 @@ class Qe {
2110
2168
  * Checks if specified method parameter is supported by current component.
2111
2169
  */
2112
2170
  o(this, "supportsParam");
2113
- this.version = t, this.createRequestId = e, this.postEvent = n, this.supports = S(t, {
2171
+ this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = y(t, {
2114
2172
  readTextFromClipboard: "web_app_read_text_from_clipboard"
2115
2173
  }), this.supportsParam = St(t, {
2116
2174
  "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
@@ -2126,13 +2184,13 @@ class Qe {
2126
2184
  * @param tryInstantView
2127
2185
  */
2128
2186
  openLink(t, e) {
2129
- const n = new URL(t, window.location.href).toString();
2130
- if (!q("web_app_open_link", this.version)) {
2131
- window.open(n, "_blank");
2187
+ const s = new URL(t, window.location.href).toString();
2188
+ if (!A("web_app_open_link", this.version)) {
2189
+ window.open(s, "_blank");
2132
2190
  return;
2133
2191
  }
2134
2192
  this.postEvent("web_app_open_link", {
2135
- url: n,
2193
+ url: s,
2136
2194
  ...typeof e == "boolean" ? { try_instant_view: e } : {}
2137
2195
  });
2138
2196
  }
@@ -2145,16 +2203,16 @@ class Qe {
2145
2203
  openTelegramLink(t) {
2146
2204
  const {
2147
2205
  hostname: e,
2148
- pathname: n,
2149
- search: s
2206
+ pathname: s,
2207
+ search: n
2150
2208
  } = new URL(t, window.location.href);
2151
2209
  if (e !== "t.me")
2152
2210
  throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
2153
- if (!q("web_app_open_tg_link", this.version)) {
2211
+ if (!A("web_app_open_tg_link", this.version)) {
2154
2212
  window.location.href = t;
2155
2213
  return;
2156
2214
  }
2157
- this.postEvent("web_app_open_tg_link", { path_full: n + s });
2215
+ this.postEvent("web_app_open_tg_link", { path_full: s + n });
2158
2216
  }
2159
2217
  /**
2160
2218
  * Reads text from clipboard and returns string or null. null is returned
@@ -2163,7 +2221,7 @@ class Qe {
2163
2221
  * - Access to clipboard is not allowed
2164
2222
  */
2165
2223
  readTextFromClipboard() {
2166
- return _(
2224
+ return b(
2167
2225
  "web_app_read_text_from_clipboard",
2168
2226
  { req_id: this.createRequestId() },
2169
2227
  "clipboard_text_received",
@@ -2171,83 +2229,84 @@ class Qe {
2171
2229
  ).then(({ data: t = null }) => t);
2172
2230
  }
2173
2231
  }
2174
- function ar(r) {
2232
+ function or(r = {}) {
2175
2233
  const {
2176
2234
  async: t = !1,
2177
2235
  cssVars: e = !1,
2178
- acceptCustomStyles: n = !1
2236
+ acceptCustomStyles: s = !1
2179
2237
  } = r;
2180
2238
  try {
2181
2239
  const {
2182
2240
  launchParams: {
2183
- initData: s,
2241
+ initData: n,
2184
2242
  initDataRaw: i,
2185
2243
  version: a,
2186
2244
  platform: c,
2187
2245
  themeParams: u,
2188
- botInline: l = !1
2246
+ botInline: d = !1
2189
2247
  },
2190
2248
  isPageReload: p
2191
- } = Et(), m = De(), d = Ee(a);
2192
- Ct() && (n && Le(), d("iframe_ready", { reload_supported: !0 }), k("reload_iframe", () => window.location.reload()));
2193
- const y = {
2194
- backButton: $e(p, a, d),
2195
- closingBehavior: Ve(p, d),
2196
- cloudStorage: new Ae(a, m, d),
2197
- createRequestId: m,
2198
- hapticFeedback: new qe(a, d),
2199
- invoice: new Ge(a, d),
2200
- mainButton: Ie(
2249
+ } = Et(), E = Ie(), l = me(a);
2250
+ Ct() && (s && Pe(), l("iframe_ready", { reload_supported: !0 }), m("reload_iframe", () => window.location.reload()));
2251
+ 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),
2258
+ mainButton: Le(
2201
2259
  p,
2202
2260
  u.buttonColor || "#000000",
2203
2261
  u.buttonTextColor || "#ffffff",
2204
- d
2262
+ l
2205
2263
  ),
2206
- miniApp: Be(
2264
+ miniApp: Te(
2207
2265
  p,
2208
2266
  u.backgroundColor || "#ffffff",
2209
2267
  a,
2210
- l,
2211
- d
2268
+ d,
2269
+ l
2212
2270
  ),
2213
- popup: new ze(a, d),
2214
- postEvent: d,
2215
- qrScanner: new Je(a, d),
2216
- themeParams: He(u),
2217
- utils: new Qe(a, m, d),
2218
- ...s ? {
2219
- initData: new Mt(s),
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),
2277
+ ...n ? {
2278
+ initData: new Wt(n),
2220
2279
  initDataRaw: i
2221
2280
  } : {}
2222
- }, x = t ? Oe(p, c, d) : Ne(p, c, d);
2223
- return x instanceof Promise ? x.then((V) => (ot(
2281
+ }, x = t ? Ne(p, c, l) : He(p, c, l);
2282
+ return x instanceof Promise ? x.then((R) => (ot(
2224
2283
  e,
2225
- y.miniApp,
2226
- y.themeParams,
2227
- V
2284
+ C.miniApp,
2285
+ C.themeParams,
2286
+ R
2228
2287
  ), {
2229
- ...y,
2230
- viewport: V
2288
+ ...C,
2289
+ viewport: R
2231
2290
  })) : (ot(
2232
2291
  e,
2233
- y.miniApp,
2234
- y.themeParams,
2292
+ C.miniApp,
2293
+ C.themeParams,
2235
2294
  x
2236
- ), { ...y, viewport: x });
2237
- } catch (s) {
2295
+ ), { ...C, viewport: x });
2296
+ } catch (n) {
2238
2297
  if (t)
2239
- return Promise.reject(s);
2240
- throw s;
2298
+ return Promise.reject(n);
2299
+ throw n;
2241
2300
  }
2242
2301
  }
2243
- function R(r, t) {
2302
+ function H(r, t) {
2244
2303
  return r.startsWith(t) ? r : `${t}${r}`;
2245
2304
  }
2246
- function cr(r) {
2305
+ function ar(r) {
2247
2306
  const t = r.match(/#(.+)/);
2248
2307
  return t ? t[1] : null;
2249
2308
  }
2250
- async function B(r) {
2309
+ async function N(r) {
2251
2310
  return r === 0 ? !0 : Promise.race([
2252
2311
  new Promise((t) => {
2253
2312
  window.addEventListener("popstate", function e() {
@@ -2260,17 +2319,17 @@ async function B(r) {
2260
2319
  })
2261
2320
  ]);
2262
2321
  }
2263
- async function Ze() {
2264
- if (window.history.length <= 1 || (window.history.pushState(null, ""), await B(1 - window.history.length)))
2322
+ async function Qe() {
2323
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await N(1 - window.history.length)))
2265
2324
  return;
2266
- let t = await B(-1);
2325
+ let t = await N(-1);
2267
2326
  for (; t; )
2268
- t = await B(-1);
2327
+ t = await N(-1);
2269
2328
  }
2270
- class Ke {
2329
+ class Ze {
2271
2330
  constructor(t, e, {
2272
- debug: n = !1,
2273
- loggerPrefix: s = "Navigator"
2331
+ debug: s = !1,
2332
+ loggerPrefix: n = "Navigator"
2274
2333
  }) {
2275
2334
  o(this, "logger");
2276
2335
  o(this, "entries");
@@ -2282,11 +2341,11 @@ class Ke {
2282
2341
  if (!i.startsWith("/") && i.length > 0)
2283
2342
  throw new Error('Pathname should start with "/"');
2284
2343
  return {
2285
- pathname: R(i, "/"),
2286
- search: a ? R(a, "?") : "",
2287
- hash: c ? R(c, "#") : ""
2344
+ pathname: H(i, "/"),
2345
+ search: a ? H(a, "?") : "",
2346
+ hash: c ? H(c, "#") : ""
2288
2347
  };
2289
- }), this.logger = new vt(`[${s}]`, n);
2348
+ }), this.logger = new vt(`[${n}]`, s);
2290
2349
  }
2291
2350
  /**
2292
2351
  * Converts entry to the navigation entry.
@@ -2302,16 +2361,16 @@ class Ke {
2302
2361
  search: c,
2303
2362
  hash: u
2304
2363
  } = t;
2305
- e = a + (c ? R(c, "?") : "") + (u ? R(u, "#") : "");
2364
+ e = a + (c ? H(c, "?") : "") + (u ? H(u, "#") : "");
2306
2365
  }
2307
2366
  const {
2308
- pathname: n,
2309
- search: s,
2367
+ pathname: s,
2368
+ search: n,
2310
2369
  hash: i
2311
2370
  } = new URL(e, `https://localhost${this.path}`);
2312
2371
  return {
2313
- pathname: n,
2314
- search: s,
2372
+ pathname: s,
2373
+ search: n,
2315
2374
  hash: i
2316
2375
  };
2317
2376
  }
@@ -2366,14 +2425,14 @@ class Ke {
2366
2425
  updated: !1,
2367
2426
  delta: t
2368
2427
  });
2369
- const n = this.entry;
2370
- this.entriesCursor = e;
2371
2428
  const s = this.entry;
2372
- return this.logger.log("State changed", { before: n, after: s }), this.performGo({
2429
+ this.entriesCursor = e;
2430
+ const n = this.entry;
2431
+ return this.logger.log("State changed", { before: s, after: n }), this.performGo({
2373
2432
  updated: !0,
2374
2433
  delta: t,
2375
- before: n,
2376
- after: s
2434
+ before: s,
2435
+ after: n
2377
2436
  });
2378
2437
  }
2379
2438
  /**
@@ -2413,12 +2472,12 @@ class Ke {
2413
2472
  */
2414
2473
  push(t) {
2415
2474
  this.entriesCursor !== this.entries.length - 1 && this.entries.splice(this.entriesCursor + 1);
2416
- const e = this.formatEntry(t), n = this.entry;
2475
+ const e = this.formatEntry(t), s = this.entry;
2417
2476
  this.entriesCursor += 1, this.entries[this.entriesCursor] = e;
2418
- const s = this.entry;
2419
- return this.logger.log("State changed", { before: n, after: s }), this.performPush({
2420
- before: n,
2421
- after: s
2477
+ const n = this.entry;
2478
+ return this.logger.log("State changed", { before: s, after: n }), this.performPush({
2479
+ before: s,
2480
+ after: n
2422
2481
  });
2423
2482
  }
2424
2483
  /**
@@ -2448,13 +2507,13 @@ class Ke {
2448
2507
  updated: !1,
2449
2508
  entry: e
2450
2509
  });
2451
- const n = this.entry;
2452
- this.entries[this.entriesCursor] = e;
2453
2510
  const s = this.entry;
2454
- return this.logger.log("State changed", { before: n, after: s }), this.performReplace({
2511
+ this.entries[this.entriesCursor] = e;
2512
+ const n = this.entry;
2513
+ return this.logger.log("State changed", { before: s, after: n }), this.performReplace({
2455
2514
  updated: !0,
2456
- before: n,
2457
- after: s
2515
+ before: s,
2516
+ after: n
2458
2517
  });
2459
2518
  }
2460
2519
  /**
@@ -2467,13 +2526,13 @@ class Ke {
2467
2526
  }
2468
2527
  }
2469
2528
  const at = 0, J = 1, Q = 2;
2470
- class Lt extends Ke {
2471
- constructor(e, n, s = {}) {
2472
- super(e, n, {
2473
- ...s,
2529
+ class Lt extends Ze {
2530
+ constructor(e, s, n = {}) {
2531
+ super(e, s, {
2532
+ ...n,
2474
2533
  loggerPrefix: "HashNavigator"
2475
2534
  });
2476
- o(this, "ee", new w());
2535
+ o(this, "ee", new _());
2477
2536
  o(this, "attached", !1);
2478
2537
  /**
2479
2538
  * Handles window "popstate" event.
@@ -2507,20 +2566,20 @@ class Lt extends Ke {
2507
2566
  */
2508
2567
  static fromLocation(e) {
2509
2568
  const {
2510
- search: n,
2511
- pathname: s,
2569
+ search: s,
2570
+ pathname: n,
2512
2571
  hash: i
2513
2572
  } = new URL(
2514
2573
  window.location.hash.slice(1),
2515
2574
  window.location.href
2516
2575
  );
2517
- return new Lt([{ search: n, pathname: s, hash: i }], 0, e);
2576
+ return new Lt([{ search: s, pathname: n, hash: i }], 0, e);
2518
2577
  }
2519
2578
  async performGo(e) {
2520
2579
  e.updated && (this.attached && await this.syncHistory(), this.emitChanged(e.before, e.after));
2521
2580
  }
2522
- async performPush({ before: e, after: n }) {
2523
- this.attached && await this.syncHistory(), this.emitChanged(e, n);
2581
+ async performPush({ before: e, after: s }) {
2582
+ this.attached && await this.syncHistory(), this.emitChanged(e, s);
2524
2583
  }
2525
2584
  async performReplace(e) {
2526
2585
  e.updated && (this.attached && window.history.replaceState(null, "", `#${this.path}`), this.emitChanged(e.before, e.after));
@@ -2531,13 +2590,13 @@ class Lt extends Ke {
2531
2590
  async syncHistory() {
2532
2591
  window.removeEventListener("popstate", this.onPopState);
2533
2592
  const e = `#${this.path}`;
2534
- await Ze(), 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);
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);
2535
2594
  }
2536
- emitChanged(e, n) {
2595
+ emitChanged(e, s) {
2537
2596
  this.ee.emit("change", {
2538
2597
  navigator: this,
2539
2598
  from: e,
2540
- to: n
2599
+ to: s
2541
2600
  });
2542
2601
  }
2543
2602
  /**
@@ -2545,68 +2604,69 @@ class Lt extends Ke {
2545
2604
  */
2546
2605
  async attach() {
2547
2606
  if (!this.attached)
2548
- return this.logger.log("Attaching", this), this.attached = !0, k("back_button_pressed", this.back), this.syncHistory();
2607
+ return this.logger.log("Attaching", this), this.attached = !0, m("back_button_pressed", this.back), this.syncHistory();
2549
2608
  }
2550
2609
  /**
2551
2610
  * Detaches current navigator from the browser history.
2552
2611
  */
2553
2612
  detach() {
2554
- this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), N("back_button_pressed", this.back));
2613
+ this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), $("back_button_pressed", this.back));
2555
2614
  }
2556
2615
  }
2557
2616
  export {
2558
- ve as BackButton,
2559
- xe as ClosingBehavior,
2560
- Ae as CloudStorage,
2561
- qe as HapticFeedback,
2617
+ Ee as BackButton,
2618
+ ke as ClosingBehavior,
2619
+ Se as CloudStorage,
2620
+ xe as HapticFeedback,
2562
2621
  Lt as HashNavigator,
2563
- Mt as InitData,
2564
- Ge as Invoice,
2565
- Te as MainButton,
2622
+ Wt as InitData,
2623
+ je as Invoice,
2624
+ qe as MainButton,
2566
2625
  K as MethodUnsupportedError,
2567
- Re as MiniApp,
2568
- Ke as Navigator,
2626
+ $e as MiniApp,
2627
+ Ze as Navigator,
2569
2628
  Y as ParameterUnsupportedError,
2570
- ze as Popup,
2571
- Je as QRScanner,
2572
- zt as ThemeParams,
2573
- Qe as Utils,
2629
+ Fe as Popup,
2630
+ ze as QRScanner,
2631
+ Re as SettingsButton,
2632
+ Gt as ThemeParams,
2633
+ Je as Utils,
2574
2634
  j as Viewport,
2575
- Wt as chatParser,
2576
- ke as classNames,
2577
- ye as compareVersions,
2578
- Ee as createPostEvent,
2579
- cr as getHash,
2580
- ar as init,
2635
+ Ot as chatParser,
2636
+ Ce as classNames,
2637
+ be as compareVersions,
2638
+ me as createPostEvent,
2639
+ ar as getHash,
2640
+ or as init,
2581
2641
  gt as initDataParser,
2582
2642
  lt as isColorDark,
2583
2643
  Ct as isIframe,
2584
2644
  ut as isRGB,
2585
2645
  Nt as isRGBShort,
2586
- D as isRecord,
2587
- er as isTMA,
2646
+ O as isRecord,
2647
+ tr as isTMA,
2588
2648
  bt as launchParamsParser,
2589
- or as mergeClassNames,
2590
- N as off,
2591
- k as on,
2649
+ ir as mergeClassNames,
2650
+ $ as off,
2651
+ m as on,
2592
2652
  sr as once,
2593
- Xe as parseInitData,
2653
+ Ye as parseInitData,
2594
2654
  mt as parseLaunchParams,
2595
- _t as parseThemeParams,
2655
+ wt as parseThemeParams,
2596
2656
  f as postEvent,
2597
- _ as request,
2598
- tr as requestThemeParams,
2657
+ b as request,
2658
+ Xe as requestThemeParams,
2599
2659
  Pt as requestViewport,
2600
2660
  Et as retrieveLaunchData,
2601
- Kt as serializeLaunchParams,
2602
- Ft as serializeThemeParams,
2603
- rr as setDebug,
2604
- nr as setTargetOrigin,
2605
- ir as subscribe,
2606
- q as supports,
2607
- wt as themeParamsParser,
2661
+ Qt as serializeLaunchParams,
2662
+ jt as serializeThemeParams,
2663
+ er as setDebug,
2664
+ rr as setTargetOrigin,
2665
+ nr as subscribe,
2666
+ A as supports,
2667
+ _t as themeParamsParser,
2608
2668
  pt as toRGB,
2609
- me as unsubscribe,
2669
+ we as unsubscribe,
2610
2670
  tt as userParser
2611
2671
  };
2612
2672
  //# sourceMappingURL=index.mjs.map