@tma.js/sdk 0.12.8 → 0.13.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,23 +1,23 @@
1
- var it = Object.defineProperty;
2
- var at = (s, t, e) => t in s ? it(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var i = (s, t, e) => (at(s, typeof t != "symbol" ? t + "" : t, e), e);
4
- import { parse as W, retrieveFromStorage as F, saveToStorage as ct } from "@tma.js/launch-params";
5
- import { EventEmitter as w } from "@tma.js/event-emitter";
6
- import { supports as C, postEvent as g, on as x, off as K, request as _, detectSupportParams as ht, setDebug as ut, setTargetOrigin as pt, isIframe as lt } from "@tma.js/bridge";
7
- import { array as dt, string as j, json as gt } from "@tma.js/parsing";
8
- import { parse as N } from "@tma.js/theme-params";
9
- import { isColorDark as J, isRGB as bt } from "@tma.js/colors";
10
- import { compareVersions as _t, isRecord as ft, withTimeout as wt } from "@tma.js/utils";
1
+ var ot = Object.defineProperty;
2
+ var nt = (s, t, e) => t in s ? ot(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var i = (s, t, e) => (nt(s, typeof t != "symbol" ? t + "" : t, e), e);
4
+ import { retrieveLaunchData as U, parse as rt } from "@tma.js/launch-params";
5
+ import { EventEmitter as m } from "@tma.js/event-emitter";
6
+ import { supports as C, postEvent as g, on as x, off as K, request as f, detectSupportParams as it, setDebug as at, setTargetOrigin as ct, isIframe as ht } from "@tma.js/bridge";
7
+ import { array as ut, string as F, json as lt } from "@tma.js/parsing";
8
+ import { parse as M } from "@tma.js/theme-params";
9
+ import { isColorDark as j, isRGB as pt } from "@tma.js/colors";
10
+ import { compareVersions as dt, isRecord as gt, withTimeout as bt } from "@tma.js/utils";
11
11
  function v(s, t) {
12
12
  return (e) => C(t[e], s);
13
13
  }
14
- function mt(s, t) {
14
+ function _t(s, t) {
15
15
  return (e) => {
16
16
  const [o, n] = t[e];
17
17
  return C(o, n, s);
18
18
  };
19
19
  }
20
- class f {
20
+ class w {
21
21
  constructor(t, e) {
22
22
  this.state = t, this.ee = e;
23
23
  }
@@ -40,9 +40,9 @@ class f {
40
40
  return this.state[t];
41
41
  }
42
42
  }
43
- class Ct {
43
+ class ft {
44
44
  constructor(t, e, o = g) {
45
- i(this, "ee", new w());
45
+ i(this, "ee", new m());
46
46
  i(this, "state");
47
47
  /**
48
48
  * Adds event listener.
@@ -64,7 +64,7 @@ class Ct {
64
64
  * Checks if specified method is supported by current component.
65
65
  */
66
66
  i(this, "supports");
67
- this.postEvent = o, this.state = new f({ isVisible: t }, this.ee), this.supports = v(e, {
67
+ this.postEvent = o, this.state = new w({ isVisible: t }, this.ee), this.supports = v(e, {
68
68
  show: "web_app_setup_back_button",
69
69
  hide: "web_app_setup_back_button"
70
70
  });
@@ -91,9 +91,9 @@ class Ct {
91
91
  this.isVisible = !0;
92
92
  }
93
93
  }
94
- class vt {
94
+ class wt {
95
95
  constructor(t, e = g) {
96
- i(this, "ee", new w());
96
+ i(this, "ee", new m());
97
97
  i(this, "state");
98
98
  /**
99
99
  * Adds new event listener.
@@ -103,7 +103,7 @@ class vt {
103
103
  * Removes event listener.
104
104
  */
105
105
  i(this, "off", this.ee.off.bind(this.ee));
106
- this.postEvent = e, this.state = new f({ isConfirmationNeeded: t }, this.ee);
106
+ this.postEvent = e, this.state = new w({ isConfirmationNeeded: t }, this.ee);
107
107
  }
108
108
  set isConfirmationNeeded(t) {
109
109
  this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
@@ -130,11 +130,11 @@ class vt {
130
130
  this.isConfirmationNeeded = !0;
131
131
  }
132
132
  }
133
- const yt = dt().of(j());
134
- function M(s, t) {
133
+ const mt = ut().of(F());
134
+ function N(s, t) {
135
135
  return s.reduce((e, o) => (e[o] = t, e), {});
136
136
  }
137
- class Et {
137
+ class Ct {
138
138
  constructor(t, e, o = g) {
139
139
  /**
140
140
  * Checks if specified method is supported by current component.
@@ -154,7 +154,7 @@ class Et {
154
154
  * @param options - execution options.
155
155
  */
156
156
  async invokeCustomMethod(t, e, o = {}) {
157
- const { result: n, error: r } = await _(
157
+ const { result: n, error: r } = await f(
158
158
  "web_app_invoke_custom_method",
159
159
  { method: t, params: e, req_id: this.createRequestId() },
160
160
  "custom_method_invoked",
@@ -178,7 +178,7 @@ class Et {
178
178
  */
179
179
  async getKeys(t) {
180
180
  const e = await this.invokeCustomMethod("getStorageKeys", {}, t);
181
- return yt.parse(e);
181
+ return mt.parse(e);
182
182
  }
183
183
  /**
184
184
  * Returns map, where key is one of the specified in keys argument, and value is according
@@ -188,9 +188,9 @@ class Et {
188
188
  */
189
189
  async getValues(t, e) {
190
190
  if (t.length === 0)
191
- return M(t, "");
192
- const o = gt(
193
- M(t, j())
191
+ return N(t, "");
192
+ const o = lt(
193
+ N(t, F())
194
194
  // fixme
195
195
  ), n = await this.invokeCustomMethod("getStorageValues", { keys: t }, e);
196
196
  return o.parse(n);
@@ -205,7 +205,7 @@ class Et {
205
205
  await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, o);
206
206
  }
207
207
  }
208
- class kt {
208
+ class vt {
209
209
  constructor(t, e = g) {
210
210
  /**
211
211
  * Checks if specified method is supported by current component.
@@ -248,29 +248,29 @@ class kt {
248
248
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
249
249
  }
250
250
  }
251
- class xt {
251
+ class yt {
252
252
  constructor(t, e, o = {}) {
253
253
  i(this, "state");
254
254
  const {
255
255
  chat: n = null,
256
256
  canSendAfter: r = null,
257
257
  chatType: a = null,
258
- chatInstance: c = null,
259
- user: u = null,
260
- queryId: p = null,
261
- receiver: h = null,
262
- startParam: l = null
258
+ chatInstance: h = null,
259
+ user: c = null,
260
+ queryId: l = null,
261
+ receiver: u = null,
262
+ startParam: p = null
263
263
  } = o;
264
- this.state = new f({
264
+ this.state = new w({
265
265
  authDate: t,
266
266
  canSendAfter: r === null ? null : new Date(t.getTime() + r * 1e3),
267
267
  chat: n,
268
268
  chatType: a,
269
- chatInstance: c,
270
- user: u,
271
- queryId: p,
272
- receiver: h,
273
- startParam: l,
269
+ chatInstance: h,
270
+ user: c,
271
+ queryId: l,
272
+ receiver: u,
273
+ startParam: p,
274
274
  hash: e
275
275
  });
276
276
  }
@@ -347,9 +347,9 @@ class xt {
347
347
  return this.state.get("user");
348
348
  }
349
349
  }
350
- class Vt {
351
- constructor(t, e, o, n, r, a, c = g) {
352
- i(this, "ee", new w());
350
+ class kt {
351
+ constructor(t, e, o, n, r, a, h = g) {
352
+ i(this, "ee", new m());
353
353
  i(this, "state");
354
354
  /**
355
355
  * Adds new event listener.
@@ -370,7 +370,7 @@ class Vt {
370
370
  return K("main_button_pressed", e);
371
371
  this.ee.off(t, e);
372
372
  });
373
- this.postEvent = c, this.state = new f({
373
+ this.postEvent = h, this.state = new w({
374
374
  backgroundColor: t,
375
375
  isEnabled: e,
376
376
  isVisible: o,
@@ -512,7 +512,7 @@ class Vt {
512
512
  return this.state.set("backgroundColor", t), this.commit(), this;
513
513
  }
514
514
  }
515
- function St(s) {
515
+ function Et(s) {
516
516
  const t = s.message.trim(), e = (s.title || "").trim(), o = s.buttons || [];
517
517
  let n;
518
518
  if (e.length > 64)
@@ -526,19 +526,19 @@ function St(s) {
526
526
  if (a.length > 64)
527
527
  throw new Error(`Button ID has incorrect size: ${a}`);
528
528
  if (r.type === void 0 || r.type === "default" || r.type === "destructive") {
529
- const c = r.text.trim();
530
- if (c.length === 0 || c.length > 64) {
531
- const u = r.type || "default";
532
- throw new Error(`Button text with type "${u}" has incorrect size: ${r.text.length}`);
529
+ const h = r.text.trim();
530
+ if (h.length === 0 || h.length > 64) {
531
+ const c = r.type || "default";
532
+ throw new Error(`Button text with type "${c}" has incorrect size: ${r.text.length}`);
533
533
  }
534
- return { ...r, text: c, id: a };
534
+ return { ...r, text: h, id: a };
535
535
  }
536
536
  return { ...r, id: a };
537
537
  }), { title: e, message: t, buttons: n };
538
538
  }
539
- class Pt {
539
+ class xt {
540
540
  constructor(t, e = g) {
541
- i(this, "ee", new w());
541
+ i(this, "ee", new m());
542
542
  i(this, "state");
543
543
  /**
544
544
  * Adds new event listener.
@@ -552,7 +552,7 @@ class Pt {
552
552
  * Checks if specified method is supported by current component.
553
553
  */
554
554
  i(this, "supports");
555
- this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, { open: "web_app_open_popup" });
555
+ this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = v(t, { open: "web_app_open_popup" });
556
556
  }
557
557
  /**
558
558
  * Shows whether popup is currently opened.
@@ -578,9 +578,9 @@ class Pt {
578
578
  throw new Error("Popup is already opened.");
579
579
  this.state.set("isOpened", !0);
580
580
  try {
581
- const { button_id: e = null } = await _(
581
+ const { button_id: e = null } = await f(
582
582
  "web_app_open_popup",
583
- St(t),
583
+ Et(t),
584
584
  "popup_closed",
585
585
  { postEvent: this.postEvent }
586
586
  );
@@ -590,9 +590,9 @@ class Pt {
590
590
  }
591
591
  }
592
592
  }
593
- class qt {
593
+ class Vt {
594
594
  constructor(t, e = g) {
595
- i(this, "ee", new w());
595
+ i(this, "ee", new m());
596
596
  i(this, "state");
597
597
  /**
598
598
  * Adds new event listener.
@@ -606,7 +606,7 @@ class qt {
606
606
  * Checks if specified method is supported by current component.
607
607
  */
608
608
  i(this, "supports");
609
- this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, {
609
+ this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = v(t, {
610
610
  close: "web_app_close_scan_qr_popup",
611
611
  open: "web_app_open_scan_qr_popup"
612
612
  });
@@ -637,7 +637,7 @@ class qt {
637
637
  throw new Error("QR scanner is already opened.");
638
638
  this.isOpened = !0;
639
639
  try {
640
- const e = await _(
640
+ const e = await f(
641
641
  "web_app_open_scan_qr_popup",
642
642
  { text: t },
643
643
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -651,27 +651,39 @@ class qt {
651
651
  }
652
652
  function z(s) {
653
653
  const {
654
- backgroundColor: t = null,
655
- buttonTextColor: e = null,
654
+ accentTextColor: t = null,
655
+ backgroundColor: e = null,
656
656
  buttonColor: o = null,
657
- hintColor: n = null,
658
- linkColor: r = null,
659
- textColor: a = null,
660
- secondaryBackgroundColor: c = null
657
+ buttonTextColor: n = null,
658
+ destructiveTextColor: r = null,
659
+ headerBackgroundColor: a = null,
660
+ hintColor: h = null,
661
+ linkColor: c = null,
662
+ secondaryBackgroundColor: l = null,
663
+ sectionBackgroundColor: u = null,
664
+ sectionHeaderTextColor: p = null,
665
+ subtitleTextColor: b = null,
666
+ textColor: P = null
661
667
  } = s;
662
668
  return {
663
- backgroundColor: t,
664
- buttonTextColor: e,
669
+ accentTextColor: t,
670
+ backgroundColor: e,
665
671
  buttonColor: o,
666
- hintColor: n,
667
- linkColor: r,
668
- textColor: a,
669
- secondaryBackgroundColor: c
672
+ buttonTextColor: n,
673
+ destructiveTextColor: r,
674
+ headerBackgroundColor: a,
675
+ hintColor: h,
676
+ linkColor: c,
677
+ secondaryBackgroundColor: l,
678
+ sectionBackgroundColor: u,
679
+ sectionHeaderTextColor: p,
680
+ subtitleTextColor: b,
681
+ textColor: P
670
682
  };
671
683
  }
672
- class P {
684
+ class q {
673
685
  constructor(t) {
674
- i(this, "ee", new w());
686
+ i(this, "ee", new m());
675
687
  i(this, "state");
676
688
  /**
677
689
  * Adds new event listener.
@@ -681,7 +693,7 @@ class P {
681
693
  * Removes event listener.
682
694
  */
683
695
  i(this, "off", this.ee.off.bind(this.ee));
684
- this.state = new f(z(t), this.ee);
696
+ this.state = new w(z(t), this.ee);
685
697
  }
686
698
  /**
687
699
  * Requests fresh information about current theme.
@@ -690,11 +702,11 @@ class P {
690
702
  * @param options - method options.
691
703
  */
692
704
  static async request(t = {}) {
693
- const { timeout: e = 1e3, ...o } = t, n = await _("web_app_request_theme", "theme_changed", {
705
+ const { timeout: e = 1e3, ...o } = t, n = await f("web_app_request_theme", "theme_changed", {
694
706
  ...o,
695
707
  timeout: e
696
708
  });
697
- return N(n.theme_params);
709
+ return M(n.theme_params);
698
710
  }
699
711
  /**
700
712
  * Synchronizes specified instance of ThemeParams with the actual value in the native
@@ -703,7 +715,7 @@ class P {
703
715
  */
704
716
  static sync(t) {
705
717
  x("theme_changed", (e) => {
706
- t.state.set(z(N(e.theme_params)));
718
+ t.state.set(z(M(e.theme_params)));
707
719
  });
708
720
  }
709
721
  /**
@@ -712,7 +724,7 @@ class P {
712
724
  * @param options - method options.
713
725
  */
714
726
  static async synced(t) {
715
- const e = await this.request(t), o = new P(e);
727
+ const e = await this.request(t), o = new q(e);
716
728
  return this.sync(o), o;
717
729
  }
718
730
  /**
@@ -744,7 +756,7 @@ class P {
744
756
  * value is calculated according to theme background color.
745
757
  */
746
758
  get isDark() {
747
- return this.backgroundColor === null || J(this.backgroundColor);
759
+ return this.backgroundColor === null || j(this.backgroundColor);
748
760
  }
749
761
  /**
750
762
  * Returns current link color.
@@ -765,12 +777,12 @@ class P {
765
777
  return this.state.get("textColor");
766
778
  }
767
779
  }
768
- function E(s) {
780
+ function k(s) {
769
781
  return s < 0 ? 0 : s;
770
782
  }
771
- class k {
783
+ class E {
772
784
  constructor(t, e, o, n, r = g) {
773
- i(this, "ee", new w());
785
+ i(this, "ee", new m());
774
786
  i(this, "state");
775
787
  /**
776
788
  * Adds new event listener.
@@ -780,11 +792,11 @@ class k {
780
792
  * Removes event listener.
781
793
  */
782
794
  i(this, "off", this.ee.off.bind(this.ee));
783
- this.postEvent = r, this.state = new f({
784
- height: E(t),
795
+ this.postEvent = r, this.state = new w({
796
+ height: k(t),
785
797
  isExpanded: n,
786
- stableHeight: E(o),
787
- width: E(e)
798
+ stableHeight: k(o),
799
+ width: k(e)
788
800
  }, this.ee);
789
801
  }
790
802
  /**
@@ -799,7 +811,7 @@ class k {
799
811
  is_expanded: n,
800
812
  is_state_stable: r,
801
813
  ...a
802
- } = await _("web_app_request_viewport", "viewport_changed", {
814
+ } = await f("web_app_request_viewport", "viewport_changed", {
803
815
  ...o,
804
816
  timeout: e
805
817
  });
@@ -817,12 +829,12 @@ class k {
817
829
  width: n,
818
830
  is_expanded: r,
819
831
  is_state_stable: a
820
- } = e, c = E(o);
832
+ } = e, h = k(o);
821
833
  t.state.set({
822
- height: c,
834
+ height: h,
823
835
  isExpanded: r,
824
- width: E(n),
825
- stableHeight: a ? c : void 0
836
+ width: k(n),
837
+ stableHeight: a ? h : void 0
826
838
  });
827
839
  });
828
840
  }
@@ -832,7 +844,7 @@ class k {
832
844
  * @param options - method options.
833
845
  */
834
846
  static async synced(t = {}) {
835
- const { height: e, isExpanded: o, width: n } = await this.request(t), r = new k(e, n, e, o, t.postEvent);
847
+ const { height: e, isExpanded: o, width: n } = await this.request(t), r = new E(e, n, e, o, t.postEvent);
836
848
  return this.sync(r), r;
837
849
  }
838
850
  /**
@@ -911,7 +923,7 @@ class k {
911
923
  return this.stableHeight === this.height;
912
924
  }
913
925
  }
914
- function T(s) {
926
+ function I(s) {
915
927
  const t = document.createElement("a");
916
928
  if (t.href = s, t.protocol !== "http:" && t.protocol !== "https:")
917
929
  throw Error(
@@ -919,9 +931,9 @@ function T(s) {
919
931
  );
920
932
  return t.href;
921
933
  }
922
- class Ot {
934
+ class St {
923
935
  constructor(t, e, o, n, r, a = g) {
924
- i(this, "ee", new w());
936
+ i(this, "ee", new m());
925
937
  i(this, "state");
926
938
  /**
927
939
  * Adds new event listener.
@@ -939,7 +951,7 @@ class Ot {
939
951
  * Checks if specified method parameter is supported by current component.
940
952
  */
941
953
  i(this, "supportsParam");
942
- this.currentVersion = o, this.currentPlatform = n, this.createRequestId = r, this.postEvent = a, this.state = new f({
954
+ this.currentVersion = o, this.currentPlatform = n, this.createRequestId = r, this.postEvent = a, this.state = new w({
943
955
  backgroundColor: e,
944
956
  headerColor: t
945
957
  }, this.ee), this.supports = v(o, {
@@ -949,7 +961,7 @@ class Ot {
949
961
  setBackgroundColor: "web_app_set_background_color",
950
962
  requestPhoneAccess: "web_app_request_phone",
951
963
  requestWriteAccess: "web_app_request_write_access"
952
- }), this.supportsParam = mt(o, {
964
+ }), this.supportsParam = _t(o, {
953
965
  "setHeaderColor.color": ["web_app_set_header_color", "color"],
954
966
  "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
955
967
  });
@@ -965,7 +977,7 @@ class Ot {
965
977
  * computed based on the current background color.
966
978
  */
967
979
  get colorScheme() {
968
- return J(this.backgroundColor) ? "dark" : "light";
980
+ return j(this.backgroundColor) ? "dark" : "light";
969
981
  }
970
982
  /**
971
983
  * Closes the Mini App.
@@ -985,7 +997,7 @@ class Ot {
985
997
  * @param version - compared version.
986
998
  */
987
999
  isVersionAtLeast(t) {
988
- return _t(t, this.version) >= 0;
1000
+ return dt(t, this.version) >= 0;
989
1001
  }
990
1002
  /**
991
1003
  * Opens a link in an external browser. The Mini App will not be closed.
@@ -997,7 +1009,7 @@ class Ot {
997
1009
  * @param tryInstantView
998
1010
  */
999
1011
  openLink(t, e) {
1000
- const o = T(t);
1012
+ const o = I(t);
1001
1013
  if (!C("web_app_open_link", this.version)) {
1002
1014
  window.open(o, "_blank");
1003
1015
  return;
@@ -1014,7 +1026,7 @@ class Ot {
1014
1026
  * @throws {Error} URL has not allowed hostname.
1015
1027
  */
1016
1028
  openTelegramLink(t) {
1017
- const { hostname: e, pathname: o, search: n } = new URL(T(t));
1029
+ const { hostname: e, pathname: o, search: n } = new URL(I(t));
1018
1030
  if (e !== "t.me")
1019
1031
  throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
1020
1032
  if (!C("web_app_open_tg_link", this.version)) {
@@ -1029,16 +1041,16 @@ class Ot {
1029
1041
  * @param url - invoice URL.
1030
1042
  */
1031
1043
  async openInvoice(t) {
1032
- const { hostname: e, pathname: o } = new URL(T(t));
1044
+ const { hostname: e, pathname: o } = new URL(I(t));
1033
1045
  if (e !== "t.me")
1034
1046
  throw new Error(`Incorrect hostname: ${e}`);
1035
1047
  const n = o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1036
1048
  if (n === null)
1037
1049
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');
1038
1050
  const [, , r] = n;
1039
- return (await _("web_app_open_invoice", { slug: r }, "invoice_closed", {
1051
+ return (await f("web_app_open_invoice", { slug: r }, "invoice_closed", {
1040
1052
  postEvent: this.postEvent,
1041
- capture: ({ slug: c }) => r === c
1053
+ capture: ({ slug: h }) => r === h
1042
1054
  })).status;
1043
1055
  }
1044
1056
  /**
@@ -1067,7 +1079,7 @@ class Ot {
1067
1079
  * - Access to clipboard is not allowed
1068
1080
  */
1069
1081
  async readTextFromClipboard() {
1070
- const { data: t = null } = await _(
1082
+ const { data: t = null } = await f(
1071
1083
  "web_app_read_text_from_clipboard",
1072
1084
  { req_id: this.createRequestId() },
1073
1085
  "clipboard_text_received",
@@ -1079,7 +1091,7 @@ class Ot {
1079
1091
  * Requests current user phone access.
1080
1092
  */
1081
1093
  async requestPhoneAccess() {
1082
- const { status: t } = await _("web_app_request_phone", "phone_requested", {
1094
+ const { status: t } = await f("web_app_request_phone", "phone_requested", {
1083
1095
  postEvent: this.postEvent
1084
1096
  });
1085
1097
  return t;
@@ -1088,7 +1100,7 @@ class Ot {
1088
1100
  * Requests write message access to current user.
1089
1101
  */
1090
1102
  async requestWriteAccess() {
1091
- const { status: t } = await _("web_app_request_write_access", "write_access_requested", {
1103
+ const { status: t } = await f("web_app_request_write_access", "write_access_requested", {
1092
1104
  postEvent: this.postEvent
1093
1105
  });
1094
1106
  return t;
@@ -1118,7 +1130,7 @@ class Ot {
1118
1130
  * @param color - color key or RGB color.
1119
1131
  */
1120
1132
  setHeaderColor(t) {
1121
- this.postEvent("web_app_set_header_color", bt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1133
+ this.postEvent("web_app_set_header_color", pt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1122
1134
  }
1123
1135
  /**
1124
1136
  * Updates current application background color.
@@ -1139,26 +1151,26 @@ class Ot {
1139
1151
  return this.currentVersion;
1140
1152
  }
1141
1153
  }
1142
- class I extends Error {
1154
+ class $ extends Error {
1143
1155
  constructor(t, e) {
1144
- super(`Method "${t}" is not supported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, I.prototype);
1156
+ super(`Method "${t}" is not supported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, $.prototype);
1145
1157
  }
1146
1158
  }
1147
- class $ extends Error {
1159
+ class A extends Error {
1148
1160
  constructor(t, e, o) {
1149
- super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`), Object.setPrototypeOf(this, $.prototype);
1161
+ super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`), Object.setPrototypeOf(this, A.prototype);
1150
1162
  }
1151
1163
  }
1152
- function G(s, t) {
1164
+ function J(s, t) {
1153
1165
  document.documentElement.style.setProperty(s, t);
1154
1166
  }
1155
- function b(s, t) {
1156
- t !== null && G(s, t);
1167
+ function _(s, t) {
1168
+ t !== null && J(s, t);
1157
1169
  }
1158
- function U(s, t) {
1159
- G(s, `${t}px`);
1170
+ function W(s, t) {
1171
+ J(s, `${t}px`);
1160
1172
  }
1161
- function Bt(s) {
1173
+ function Pt(s) {
1162
1174
  const {
1163
1175
  backgroundColor: t,
1164
1176
  buttonTextColor: e,
@@ -1166,241 +1178,225 @@ function Bt(s) {
1166
1178
  hintColor: n,
1167
1179
  buttonColor: r,
1168
1180
  linkColor: a,
1169
- textColor: c
1181
+ textColor: h
1170
1182
  } = s;
1171
- b("--tg-theme-bg-color", t), b("--tg-theme-button-color", r), b("--tg-theme-button-text-color", e), b("--tg-theme-hint-color", n), b("--tg-theme-link-color", a), b("--tg-theme-secondary-bg-color", o), b("--tg-theme-text-color", c);
1183
+ _("--tg-theme-bg-color", t), _("--tg-theme-button-color", r), _("--tg-theme-button-text-color", e), _("--tg-theme-hint-color", n), _("--tg-theme-link-color", a), _("--tg-theme-secondary-bg-color", o), _("--tg-theme-text-color", h);
1172
1184
  }
1173
- function Tt(s, t) {
1185
+ function qt(s, t) {
1174
1186
  const { backgroundColor: e, secondaryBackgroundColor: o } = t, { backgroundColor: n, headerColor: r } = s;
1175
- b("--tg-bg-color", n), b("--tg-header-color", r === "bg_color" ? e : o);
1187
+ _("--tg-bg-color", n), _("--tg-header-color", r === "bg_color" ? e : o);
1176
1188
  }
1177
- function It(s) {
1178
- const t = () => Bt(s);
1189
+ function Ot(s) {
1190
+ const t = () => Pt(s);
1179
1191
  s.on("changed", t), t();
1180
1192
  }
1181
- function $t(s, t) {
1182
- const e = () => Tt(s, t);
1193
+ function Tt(s, t) {
1194
+ const e = () => qt(s, t);
1183
1195
  t.on("changed", e), s.on("backgroundColorChanged", e), s.on("headerColorChanged", e), e();
1184
1196
  }
1185
- function At(s) {
1197
+ function Bt(s) {
1186
1198
  const t = () => {
1187
- U("--tg-viewport-height", s.height);
1199
+ W("--tg-viewport-height", s.height);
1188
1200
  }, e = () => {
1189
- U("--tg-viewport-stable-height", s.stableHeight);
1201
+ W("--tg-viewport-stable-height", s.stableHeight);
1190
1202
  };
1191
1203
  s.on("heightChanged", t), s.on("stableHeightChanged", e), t(), e();
1192
1204
  }
1193
- function Ht(s) {
1205
+ function It(s) {
1194
1206
  return typeof s == "boolean" ? s ? { themeParams: !0, viewport: !0, webApp: !0 } : {} : s;
1195
1207
  }
1196
- function Q(s) {
1208
+ function G(s) {
1197
1209
  return `telegram-mini-apps-${s}`;
1198
1210
  }
1199
1211
  function V(s, t) {
1200
- sessionStorage.setItem(Q(s), JSON.stringify(t));
1212
+ sessionStorage.setItem(G(s), JSON.stringify(t));
1201
1213
  }
1202
1214
  function S(s) {
1203
- const t = sessionStorage.getItem(Q(s));
1215
+ const t = sessionStorage.getItem(G(s));
1204
1216
  return t ? JSON.parse(t) : null;
1205
1217
  }
1206
- function Rt(s, t, e) {
1207
- const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, n = new Ct(o, t, e);
1218
+ function $t(s, t, e) {
1219
+ const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, n = new ft(o, t, e);
1208
1220
  return n.on("isVisibleChanged", () => {
1209
1221
  V("back-button", { isVisible: n.isVisible });
1210
1222
  }), n;
1211
1223
  }
1212
- function Dt(s, t) {
1213
- const { isConfirmationNeeded: e = !1 } = s ? S("closing-behavior") || {} : {}, o = new vt(e, t);
1224
+ function At(s, t) {
1225
+ const { isConfirmationNeeded: e = !1 } = s ? S("closing-behavior") || {} : {}, o = new wt(e, t);
1214
1226
  return o.on("isConfirmationNeededChanged", () => V("closing-behavior", {
1215
1227
  isConfirmationNeeded: o.isConfirmationNeeded
1216
1228
  })), o;
1217
1229
  }
1218
- function Lt(s, t, e, o) {
1230
+ function Ht(s, t, e, o) {
1219
1231
  const {
1220
1232
  backgroundColor: n = t,
1221
1233
  isEnabled: r = !1,
1222
1234
  isVisible: a = !1,
1223
- isProgressVisible: c = !1,
1224
- textColor: u = e,
1225
- text: p = ""
1226
- } = s ? S("main-button") || {} : {}, h = new Vt(
1235
+ isProgressVisible: h = !1,
1236
+ textColor: c = e,
1237
+ text: l = ""
1238
+ } = s ? S("main-button") || {} : {}, u = new kt(
1227
1239
  n,
1228
1240
  r,
1229
1241
  a,
1242
+ h,
1243
+ l,
1230
1244
  c,
1231
- p,
1232
- u,
1233
1245
  o
1234
- ), l = () => V("main-button", {
1235
- backgroundColor: h.backgroundColor,
1236
- isEnabled: h.isEnabled,
1237
- isVisible: h.isVisible,
1238
- isProgressVisible: h.isProgressVisible,
1239
- text: h.text,
1240
- textColor: h.textColor
1246
+ ), p = () => V("main-button", {
1247
+ backgroundColor: u.backgroundColor,
1248
+ isEnabled: u.isEnabled,
1249
+ isVisible: u.isVisible,
1250
+ isProgressVisible: u.isProgressVisible,
1251
+ text: u.text,
1252
+ textColor: u.textColor
1241
1253
  });
1242
- return h.on("backgroundColorChanged", l), h.on("isEnabledChanged", l), h.on("isVisibleChanged", l), h.on("isProgressVisibleChanged", l), h.on("textColorChanged", l), h.on("textChanged", l), h;
1254
+ return u.on("backgroundColorChanged", p), u.on("isEnabledChanged", p), u.on("isVisibleChanged", p), u.on("isProgressVisibleChanged", p), u.on("textColorChanged", p), u.on("textChanged", p), u;
1243
1255
  }
1244
- function Nt(s, t) {
1256
+ function Rt(s, t) {
1245
1257
  return s ? (e, o) => {
1246
1258
  if (!C(e, t))
1247
- throw new I(e, t);
1248
- return ft(o) && ht(e, o).forEach((n) => {
1259
+ throw new $(e, t);
1260
+ return gt(o) && it(e, o).forEach((n) => {
1249
1261
  if (!C(e, n, t))
1250
- throw new $(e, n, t);
1262
+ throw new A(e, n, t);
1251
1263
  }), g(e, o);
1252
1264
  } : g;
1253
1265
  }
1254
- function Mt() {
1266
+ function Dt() {
1255
1267
  let s = 0;
1256
1268
  return () => (s += 1, s.toString());
1257
1269
  }
1258
- function zt(s) {
1259
- const t = new P(s);
1260
- return P.sync(t), t;
1270
+ function Lt(s) {
1271
+ const t = new q(s);
1272
+ return q.sync(t), t;
1261
1273
  }
1262
- async function Ut(s, t, e) {
1274
+ async function Mt(s, t, e) {
1263
1275
  const {
1264
1276
  height: o = window.innerHeight,
1265
1277
  stableHeight: n = window.innerHeight,
1266
1278
  width: r = window.innerWidth,
1267
1279
  isExpanded: a = !1
1268
- } = s ? S("viewport") || {} : {}, u = t === "macos" || t === "web" ? (() => {
1269
- const h = new k(o, r, n, a, e);
1270
- return k.sync(h), h;
1271
- })() : await k.synced({ postEvent: e }), p = () => V("viewport", {
1272
- height: u.height,
1273
- isExpanded: u.isExpanded,
1274
- stableHeight: u.stableHeight,
1275
- width: u.width
1280
+ } = s ? S("viewport") || {} : {}, c = t === "macos" || t === "web" ? (() => {
1281
+ const u = new E(o, r, n, a, e);
1282
+ return E.sync(u), u;
1283
+ })() : await E.synced({ postEvent: e }), l = () => V("viewport", {
1284
+ height: c.height,
1285
+ isExpanded: c.isExpanded,
1286
+ stableHeight: c.stableHeight,
1287
+ width: c.width
1276
1288
  });
1277
- return u.on("heightChanged", p), u.on("isExpandedChanged", p), u.on("stableHeightChanged", p), u.on("widthChanged", p), u;
1289
+ return c.on("heightChanged", l), c.on("isExpandedChanged", l), c.on("stableHeightChanged", l), c.on("widthChanged", l), c;
1278
1290
  }
1279
- function Wt(s, t, e, o, n, r) {
1291
+ function Nt(s, t, e, o, n, r) {
1280
1292
  const {
1281
1293
  backgroundColor: a = t,
1282
- headerColor: c = "bg_color"
1283
- } = s ? S("web-app") || {} : {}, u = new Ot(
1284
- c,
1294
+ headerColor: h = "bg_color"
1295
+ } = s ? S("web-app") || {} : {}, c = new St(
1296
+ h,
1285
1297
  a,
1286
1298
  e,
1287
1299
  o,
1288
1300
  n,
1289
1301
  r
1290
- ), p = () => V("web-app", {
1291
- backgroundColor: u.backgroundColor,
1292
- headerColor: u.headerColor
1302
+ ), l = () => V("web-app", {
1303
+ backgroundColor: c.backgroundColor,
1304
+ headerColor: c.headerColor
1293
1305
  });
1294
- return u.on("backgroundColorChanged", p), u.on("headerColorChanged", p), u;
1306
+ return c.on("backgroundColorChanged", l), c.on("headerColorChanged", l), c;
1295
1307
  }
1296
- function Z() {
1297
- let s;
1298
- try {
1299
- return W(window.location.hash.slice(1));
1300
- } catch (e) {
1301
- s = e;
1302
- }
1303
- const t = F();
1304
- if (t)
1305
- return t;
1306
- throw new Error("Unable to extract launch params", { cause: s });
1307
- }
1308
- function Ft() {
1309
- return window.performance.getEntriesByType("navigation").some((s) => s.type === "reload");
1310
- }
1311
- function Kt(s, t) {
1312
- var e, o;
1313
- return s ? ((e = s.initData) == null ? void 0 : e.hash) === ((o = t.initData) == null ? void 0 : o.hash) : !1;
1314
- }
1315
- async function jt(s = {}) {
1308
+ async function zt(s = {}) {
1316
1309
  const {
1317
1310
  checkCompat: t = !0,
1318
1311
  cssVars: e = !1,
1319
1312
  acceptScrollbarStyle: o = !0,
1320
1313
  acceptCustomStyles: n = o,
1321
1314
  targetOrigin: r,
1322
- debug: a = !1,
1323
- launchParams: c
1315
+ launchParams: a,
1316
+ debug: h = !1
1324
1317
  } = s;
1325
- a && ut(a), typeof r == "string" && pt(r);
1326
- const u = F(), p = c instanceof URLSearchParams || typeof c == "string" ? W(c) : Z();
1327
- ct(p);
1328
- const h = Ft() || Kt(u, p), {
1329
- initData: l,
1330
- initDataRaw: X,
1331
- version: m,
1332
- platform: A,
1318
+ h && at(h), typeof r == "string" && ct(r);
1319
+ const { launchParams: c, isPageReload: l } = U({
1320
+ currentLaunchParams: typeof a == "string" || a instanceof URLSearchParams ? rt(a) : a
1321
+ }), {
1322
+ initData: u,
1323
+ initDataRaw: p,
1324
+ version: b,
1325
+ platform: P,
1333
1326
  themeParams: H
1334
- } = p, {
1335
- backgroundColor: Y = "#ffffff",
1336
- buttonColor: tt = "#000000",
1337
- buttonTextColor: et = "#ffffff"
1338
- } = H, R = Mt(), d = Nt(t, m), q = zt(H), D = Wt(
1339
- h,
1340
- Y,
1341
- m,
1342
- A,
1327
+ } = c, {
1328
+ backgroundColor: Q = "#ffffff",
1329
+ buttonColor: Z = "#000000",
1330
+ buttonTextColor: X = "#ffffff"
1331
+ } = H, R = Dt(), d = Rt(t, b), O = Lt(H), D = Nt(
1332
+ l,
1333
+ Q,
1334
+ b,
1335
+ P,
1343
1336
  R,
1344
1337
  d
1345
1338
  ), {
1346
- themeParams: st,
1347
- viewport: ot,
1348
- webApp: nt
1349
- } = Ht(e);
1350
- nt && $t(D, q), st && It(q);
1351
- const L = await Ut(h, A, d);
1352
- if (ot && At(L), n && lt()) {
1339
+ themeParams: Y,
1340
+ viewport: tt,
1341
+ webApp: et
1342
+ } = It(e);
1343
+ et && Tt(D, O), Y && Ot(O);
1344
+ const L = await Mt(l, P, d);
1345
+ if (tt && Bt(L), n && ht()) {
1353
1346
  const y = document.createElement("style");
1354
1347
  y.id = "telegram-custom-styles", document.head.appendChild(y), x("set_custom_style", (B) => {
1355
1348
  y.innerHTML = B;
1356
1349
  }), d("iframe_ready");
1357
1350
  }
1358
- const O = {
1359
- backButton: Rt(h, m, d),
1360
- closingBehavior: Dt(h, d),
1361
- cloudStorage: new Et(m, R, d),
1362
- haptic: new kt(m, d),
1363
- mainButton: Lt(h, tt, et, d),
1364
- popup: new Pt(m, d),
1351
+ const T = {
1352
+ backButton: $t(l, b, d),
1353
+ closingBehavior: At(l, d),
1354
+ cloudStorage: new Ct(b, R, d),
1355
+ haptic: new vt(b, d),
1356
+ mainButton: Ht(l, Z, X, d),
1357
+ popup: new xt(b, d),
1365
1358
  postEvent: d,
1366
- qrScanner: new qt(m, d),
1367
- themeParams: q,
1359
+ qrScanner: new Vt(b, d),
1360
+ themeParams: O,
1368
1361
  viewport: L,
1369
1362
  webApp: D
1370
1363
  };
1371
- if (l !== void 0) {
1372
- const { authDate: y, hash: B, ...rt } = l;
1373
- O.initData = new xt(y, B, rt), O.initDataRaw = X;
1364
+ if (u !== void 0) {
1365
+ const { authDate: y, hash: B, ...st } = u;
1366
+ T.initData = new yt(y, B, st), T.initDataRaw = p;
1374
1367
  }
1375
- return O;
1368
+ return T;
1376
1369
  }
1377
- function se(s = {}) {
1378
- return wt(jt(s), s.timeout || 1e3);
1370
+ function Xt(s = {}) {
1371
+ return bt(zt(s), s.timeout || 1e3);
1379
1372
  }
1380
- function oe() {
1373
+ function Wt() {
1381
1374
  try {
1382
- return Z(), !0;
1375
+ return U(), !0;
1383
1376
  } catch {
1384
1377
  return !1;
1385
1378
  }
1386
1379
  }
1380
+ function Yt() {
1381
+ return Wt();
1382
+ }
1387
1383
  export {
1388
- Ct as BackButton,
1389
- vt as ClosingBehaviour,
1390
- Et as CloudStorage,
1391
- kt as HapticFeedback,
1392
- xt as InitData,
1393
- Vt as MainButton,
1394
- I as MethodNotSupportedError,
1395
- $ as ParameterUnsupportedError,
1396
- Pt as Popup,
1397
- qt as QRScanner,
1398
- P as ThemeParams,
1399
- k as Viewport,
1400
- Ot as WebApp,
1401
- T as formatURL,
1402
- se as init,
1403
- oe as isTWA,
1404
- Z as retrieveLaunchParams
1384
+ ft as BackButton,
1385
+ wt as ClosingBehaviour,
1386
+ Ct as CloudStorage,
1387
+ vt as HapticFeedback,
1388
+ yt as InitData,
1389
+ kt as MainButton,
1390
+ $ as MethodNotSupportedError,
1391
+ A as ParameterUnsupportedError,
1392
+ xt as Popup,
1393
+ Vt as QRScanner,
1394
+ q as ThemeParams,
1395
+ E as Viewport,
1396
+ St as WebApp,
1397
+ I as formatURL,
1398
+ Xt as init,
1399
+ Wt as isTMA,
1400
+ Yt as isTWA
1405
1401
  };
1406
1402
  //# sourceMappingURL=index.mjs.map