@tma.js/sdk 1.0.0 → 1.0.2

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
@@ -122,7 +122,7 @@ const C = $((r) => {
122
122
  return t;
123
123
  }
124
124
  throw L();
125
- }, "number"), Dt = A(), Ht = $((r) => r instanceof Date ? r : new Date(Dt.parse(r) * 1e3), "Date");
125
+ }, "number"), Dt = $((r) => r instanceof Date ? r : new Date(A().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))
@@ -138,14 +138,14 @@ function g(r, t) {
138
138
  function ut(r) {
139
139
  return /^#[\da-f]{6}$/i.test(r);
140
140
  }
141
- function Nt(r) {
141
+ function Ht(r) {
142
142
  return /^#[\da-f]{3}$/i.test(r);
143
143
  }
144
144
  function pt(r) {
145
145
  const t = r.replace(/\s/g, "").toLowerCase();
146
146
  if (ut(t))
147
147
  return t;
148
- if (Nt(t)) {
148
+ if (Ht(t)) {
149
149
  let n = "#";
150
150
  for (let s = 0; s < 3; s += 1)
151
151
  n += t[1 + s].repeat(2);
@@ -172,7 +172,7 @@ const h = $((r) => {
172
172
  if (typeof r == "string" || typeof r == "number")
173
173
  return r.toString();
174
174
  throw L();
175
- }, "string"), Ot = h(), dt = $((r) => pt(Ot.parse(r)), "rgb");
175
+ }, "string"), dt = $((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))
@@ -184,7 +184,7 @@ function ft(r, t) {
184
184
  });
185
185
  }, !1, t);
186
186
  }
187
- function Wt() {
187
+ function Nt() {
188
188
  return g({
189
189
  id: A(),
190
190
  type: h(),
@@ -196,7 +196,7 @@ function Wt() {
196
196
  username: h().optional()
197
197
  }, "Chat");
198
198
  }
199
- class Mt {
199
+ class Ot {
200
200
  constructor(t) {
201
201
  this.initData = t;
202
202
  }
@@ -310,14 +310,14 @@ function tt() {
310
310
  function gt() {
311
311
  return ft({
312
312
  authDate: {
313
- type: Ht(),
313
+ type: Dt(),
314
314
  from: "auth_date"
315
315
  },
316
316
  canSendAfter: {
317
317
  type: A().optional(),
318
318
  from: "can_send_after"
319
319
  },
320
- chat: Wt().optional(),
320
+ chat: Nt().optional(),
321
321
  chatInstance: {
322
322
  type: h().optional(),
323
323
  from: "chat_instance"
@@ -339,28 +339,31 @@ function gt() {
339
339
  user: tt().optional()
340
340
  }, "InitData");
341
341
  }
342
- function Xe(r) {
342
+ function Qe(r) {
343
343
  return gt().parse(r);
344
344
  }
345
- function Ut(r) {
345
+ function Wt(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 Mt(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 wt = $(
352
+ (r) => {
353
+ const t = dt().optional();
354
+ return Object.entries(Z(r)).reduce((e, [n, s]) => (e[Wt(n)] = t.parse(s), e), {});
355
+ },
353
356
  "ThemeParams"
354
357
  );
355
358
  function _t(r) {
356
359
  return wt().parse(r);
357
360
  }
358
- function tr(r = {}) {
361
+ function Ze(r = {}) {
359
362
  return _("web_app_request_theme", "theme_changed", r).then(_t);
360
363
  }
361
- function Ft(r) {
364
+ function Ut(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, n]) => (n && (t[Mt(e)] = n), t), {})
364
367
  );
365
368
  }
366
369
  class w {
@@ -475,7 +478,7 @@ class b {
475
478
  return this.state[t];
476
479
  }
477
480
  }
478
- class zt {
481
+ class jt {
479
482
  constructor(t) {
480
483
  o(this, "ee", new w());
481
484
  o(this, "state");
@@ -608,10 +611,10 @@ function bt() {
608
611
  function mt(r) {
609
612
  return bt().parse(r);
610
613
  }
611
- function Jt() {
614
+ function Gt() {
612
615
  return mt(window.location.hash.slice(1));
613
616
  }
614
- function Qt() {
617
+ function Ft() {
615
618
  const r = ct();
616
619
  if (!r)
617
620
  throw new Error("Unable to get first navigation entry.");
@@ -620,18 +623,18 @@ 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 zt() {
624
627
  try {
625
- return Qt();
628
+ return Ft();
626
629
  } catch {
627
630
  }
628
631
  try {
629
- return Jt();
632
+ return Gt();
630
633
  } catch {
631
634
  }
632
635
  return null;
633
636
  }
634
- function Kt(r) {
637
+ function Jt(r) {
635
638
  const {
636
639
  initDataRaw: t,
637
640
  themeParams: e,
@@ -640,30 +643,30 @@ function Kt(r) {
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", n), c.set("tgWebAppThemeParams", Ut(e)), c.set("tgWebAppVersion", s), typeof i == "boolean" && c.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && c.set("tgWebAppBotInline", a ? "1" : "0"), c.toString();
644
647
  }
645
648
  const yt = "telegram-mini-apps-launch-params";
646
- function Yt() {
649
+ function Qt() {
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 Zt(r) {
654
+ sessionStorage.setItem(yt, Jt(r));
652
655
  }
653
- function te() {
656
+ function Kt() {
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 Yt() {
664
+ const r = Qt(), t = zt(), e = Tt();
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: Kt() ? e || r.initDataRaw === t.initDataRaw : !0
667
670
  };
668
671
  if (e)
669
672
  return {
@@ -684,20 +687,20 @@ 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 = Yt();
691
+ return window[et] = t, Zt(t.launchParams), t;
689
692
  }
690
- function er() {
693
+ function Ke() {
691
694
  try {
692
695
  return Et(), !0;
693
696
  } catch {
694
697
  return !1;
695
698
  }
696
699
  }
697
- function re(r) {
700
+ function Xt(r) {
698
701
  return "external" in r && D(r.external) && "notify" in r.external && typeof r.external.notify == "function";
699
702
  }
700
- function ne(r) {
703
+ function te(r) {
701
704
  return "TelegramWebviewProxy" in r && D(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
702
705
  }
703
706
  function Ct() {
@@ -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 Ye(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 Xe(r) {
785
788
  kt = r;
786
789
  }
787
- function se() {
790
+ function ee() {
788
791
  return kt;
789
792
  }
790
- const ie = g({
793
+ const re = 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 se() {
800
803
  const r = window;
801
804
  "TelegramGameProxy_receiveEvent" in r || [
802
805
  ["TelegramGameProxy_receiveEvent"],
@@ -809,55 +812,55 @@ function ae() {
809
812
  let e = r;
810
813
  t.forEach((n, s, i) => {
811
814
  if (s === i.length - 1) {
812
- e[n] = oe;
815
+ e[n] = ne;
813
816
  return;
814
817
  }
815
818
  n in e || (e[n] = {}), e = e[n];
816
819
  });
817
820
  });
818
821
  }
819
- function ce(r) {
820
- ae(), window.addEventListener("message", (t) => {
822
+ function ie(r) {
823
+ se(), window.addEventListener("message", (t) => {
821
824
  try {
822
- const { eventType: e, eventData: n } = ie.parse(t.data);
825
+ const { eventType: e, eventData: n } = re.parse(t.data);
823
826
  r(e, n);
824
827
  } catch {
825
828
  }
826
829
  });
827
830
  }
828
- function he() {
831
+ function oe() {
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 ae() {
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 ce() {
842
845
  return g({
843
846
  slug: h(),
844
847
  status: h()
845
848
  });
846
849
  }
847
- function le() {
850
+ function he() {
848
851
  return g({ status: h() });
849
852
  }
850
- function de() {
853
+ function ue() {
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 pe() {
856
859
  return g({
857
860
  data: h().optional()
858
861
  });
859
862
  }
860
- function ge() {
863
+ function le() {
861
864
  return g({
862
865
  theme_params: (r) => {
863
866
  const t = dt().optional();
@@ -865,7 +868,7 @@ function ge() {
865
868
  }
866
869
  });
867
870
  }
868
- function we() {
871
+ function de() {
869
872
  return g({
870
873
  height: A(),
871
874
  width: (r) => r == null ? window.innerWidth : A().parse(r),
@@ -873,10 +876,10 @@ function we() {
873
876
  is_expanded: C()
874
877
  });
875
878
  }
876
- function _e() {
879
+ function fe() {
877
880
  return g({ status: h() });
878
881
  }
879
- function be() {
882
+ function ge() {
880
883
  const r = new w(), t = (e, ...n) => {
881
884
  P.log("Emitting processed event:", e, ...n), r.emit(e, ...n);
882
885
  };
@@ -887,33 +890,33 @@ function be() {
887
890
  is_state_stable: !0,
888
891
  is_expanded: !0
889
892
  });
890
- }), ce((e, n) => {
893
+ }), ie((e, n) => {
891
894
  P.log("Received raw event:", e, n);
892
895
  try {
893
896
  switch (e) {
894
897
  case "viewport_changed":
895
- return t(e, we().parse(n));
898
+ return t(e, de().parse(n));
896
899
  case "theme_changed":
897
- return t(e, ge().parse(n));
900
+ return t(e, le().parse(n));
898
901
  case "popup_closed":
899
902
  return (
900
903
  // Sent on desktop.
901
- n == null ? t(e, {}) : t(e, de().parse(n))
904
+ n == null ? t(e, {}) : t(e, ue().parse(n))
902
905
  );
903
906
  case "set_custom_style":
904
907
  return t(e, h().parse(n));
905
908
  case "qr_text_received":
906
- return t(e, fe().parse(n));
909
+ return t(e, pe().parse(n));
907
910
  case "clipboard_text_received":
908
- return t(e, he().parse(n));
911
+ return t(e, oe().parse(n));
909
912
  case "invoice_closed":
910
- return t(e, pe().parse(n));
913
+ return t(e, ce().parse(n));
911
914
  case "phone_requested":
912
- return t("phone_requested", le().parse(n));
915
+ return t("phone_requested", he().parse(n));
913
916
  case "custom_method_invoked":
914
- return t("custom_method_invoked", ue().parse(n));
917
+ return t("custom_method_invoked", ae().parse(n));
915
918
  case "write_access_requested":
916
- return t("write_access_requested", _e().parse(n));
919
+ return t("write_access_requested", fe().parse(n));
917
920
  case "main_button_pressed":
918
921
  case "back_button_pressed":
919
922
  case "settings_button_pressed":
@@ -931,7 +934,7 @@ function be() {
931
934
  const z = "telegram-mini-apps-cached-emitter";
932
935
  function H() {
933
936
  const r = window;
934
- return r[z] === void 0 && (r[z] = be()), r[z];
937
+ return r[z] === void 0 && (r[z] = ge()), r[z];
935
938
  }
936
939
  function N(r, t) {
937
940
  H().off(r, t);
@@ -939,16 +942,16 @@ function N(r, t) {
939
942
  function k(r, t) {
940
943
  return H().on(r, t), () => N(r, t);
941
944
  }
942
- function sr(r, t) {
945
+ function tr(r, t) {
943
946
  return H().once(r, t), () => N(r, t);
944
947
  }
945
- function me(r) {
948
+ function we(r) {
946
949
  H().unsubscribe(r);
947
950
  }
948
- function ir(r) {
949
- return H().subscribe(r), () => me(r);
951
+ function er(r) {
952
+ return H().subscribe(r), () => we(r);
950
953
  }
951
- function ye(r, t) {
954
+ function _e(r, t) {
952
955
  const e = r.split("."), n = t.split("."), s = Math.max(e.length, n.length);
953
956
  for (let i = 0; i < s; i += 1) {
954
957
  const a = parseInt(e[i] || "0", 10), c = parseInt(n[i] || "0", 10);
@@ -958,7 +961,7 @@ function ye(r, t) {
958
961
  return 0;
959
962
  }
960
963
  function E(r, t) {
961
- return ye(r, t) <= 0;
964
+ return _e(r, t) <= 0;
962
965
  }
963
966
  function q(r, t, e) {
964
967
  if (typeof e == "string") {
@@ -1005,7 +1008,7 @@ function St(r, t) {
1005
1008
  function f(r, t, e) {
1006
1009
  let n = {}, s;
1007
1010
  t === void 0 && e === void 0 ? n = {} : t !== void 0 && e !== void 0 ? (n = e, s = t) : t !== void 0 && ("targetOrigin" in t ? n = t : s = t);
1008
- const { targetOrigin: i = se() } = n;
1011
+ const { targetOrigin: i = ee() } = n;
1009
1012
  if (P.log(`Calling method "${r}"`, s), Ct()) {
1010
1013
  window.parent.postMessage(JSON.stringify({
1011
1014
  eventType: r,
@@ -1013,11 +1016,11 @@ function f(r, t, e) {
1013
1016
  }), i);
1014
1017
  return;
1015
1018
  }
1016
- if (re(window)) {
1019
+ if (Xt(window)) {
1017
1020
  window.external.notify(JSON.stringify({ eventType: r, eventData: s }));
1018
1021
  return;
1019
1022
  }
1020
- if (ne(window)) {
1023
+ if (te(window)) {
1021
1024
  window.TelegramWebviewProxy.postEvent(r, JSON.stringify(s));
1022
1025
  return;
1023
1026
  }
@@ -1025,7 +1028,7 @@ function f(r, t, e) {
1025
1028
  "Unable to determine current environment and possible way to send event."
1026
1029
  );
1027
1030
  }
1028
- function Ee(r) {
1031
+ function be(r) {
1029
1032
  return (t, e) => {
1030
1033
  if (!q(t, r))
1031
1034
  throw new K(t, r);
@@ -1047,7 +1050,7 @@ function rt(r) {
1047
1050
  setTimeout(e, r, new X(r));
1048
1051
  });
1049
1052
  }
1050
- function Ce(r, t) {
1053
+ function me(r, t) {
1051
1054
  return typeof r == "function" ? (...e) => Promise.race([
1052
1055
  r(...e),
1053
1056
  rt(t)
@@ -1066,9 +1069,9 @@ function _(r, t, e, n) {
1066
1069
  V(), y(T);
1067
1070
  }
1068
1071
  });
1069
- return typeof l == "number" ? Ce(m, l) : m;
1072
+ return typeof l == "number" ? me(m, l) : m;
1070
1073
  }
1071
- class ve {
1074
+ class ye {
1072
1075
  constructor(t, e, n = f) {
1073
1076
  o(this, "ee", new w());
1074
1077
  o(this, "state");
@@ -1118,22 +1121,22 @@ class ve {
1118
1121
  function nt(r, t) {
1119
1122
  return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
1120
1123
  }
1121
- function ke(...r) {
1124
+ function Ee(...r) {
1122
1125
  return r.reduce((t, e) => {
1123
1126
  let n = "";
1124
1127
  return typeof e == "string" ? n = e : typeof e == "object" && e !== null && (n = Object.entries(e).reduce((s, [i, a]) => a ? nt(s, i) : s, "")), nt(t, n);
1125
1128
  }, "");
1126
1129
  }
1127
- function Se(r) {
1130
+ function Ce(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
+ function rr(...r) {
1134
+ return r.reduce((t, e) => (Ce(e) && Object.entries(e).forEach(([n, s]) => {
1135
+ const i = Ee(t[n], s);
1133
1136
  i.length > 0 && (t[n] = i);
1134
1137
  }), t), {});
1135
1138
  }
1136
- class xe {
1139
+ class ve {
1137
1140
  constructor(t, e = f) {
1138
1141
  o(this, "ee", new w());
1139
1142
  o(this, "state");
@@ -1172,11 +1175,10 @@ class xe {
1172
1175
  this.isConfirmationNeeded = !0;
1173
1176
  }
1174
1177
  }
1175
- const Pe = Bt().of(h());
1176
1178
  function st(r, t) {
1177
1179
  return r.reduce((e, n) => (e[n] = t, e), {});
1178
1180
  }
1179
- class Ae {
1181
+ class ke {
1180
1182
  constructor(t, e, n = f) {
1181
1183
  /**
1182
1184
  * Checks if specified method is supported by current component.
@@ -1221,7 +1223,7 @@ 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 Bt().of(h()).parse(e);
1225
1227
  }
1226
1228
  async get(t, e) {
1227
1229
  const n = Array.isArray(t) ? t : [t];
@@ -1242,7 +1244,7 @@ class Ae {
1242
1244
  await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, n);
1243
1245
  }
1244
1246
  }
1245
- class qe {
1247
+ class Se {
1246
1248
  constructor(t, e = f) {
1247
1249
  /**
1248
1250
  * Checks if specified method is supported by current component.
@@ -1288,7 +1290,7 @@ class qe {
1288
1290
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1289
1291
  }
1290
1292
  }
1291
- function Le() {
1293
+ function xe() {
1292
1294
  const r = document.createElement("style");
1293
1295
  r.id = "telegram-custom-styles", document.head.appendChild(r), k("set_custom_style", (t) => {
1294
1296
  r.innerHTML = t;
@@ -1304,19 +1306,19 @@ function W(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
+ function Pe(r, t, e) {
1310
+ const { isVisible: n = !1 } = r ? W("back-button") || {} : {}, s = new ye(n, t, e);
1309
1311
  return s.on("change", () => {
1310
1312
  O("back-button", { isVisible: s.isVisible });
1311
1313
  }), s;
1312
1314
  }
1313
- function Ve(r, t) {
1314
- const { isConfirmationNeeded: e = !1 } = r ? W("closing-behavior") || {} : {}, n = new xe(e, t);
1315
+ function Ae(r, t) {
1316
+ const { isConfirmationNeeded: e = !1 } = r ? W("closing-behavior") || {} : {}, n = new ve(e, t);
1315
1317
  return n.on("change", () => O("closing-behavior", {
1316
1318
  isConfirmationNeeded: n.isConfirmationNeeded
1317
1319
  })), n;
1318
1320
  }
1319
- class Te {
1321
+ class qe {
1320
1322
  constructor(t) {
1321
1323
  o(this, "ee", new w());
1322
1324
  o(this, "state");
@@ -1481,7 +1483,7 @@ 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, n) {
1485
1487
  const {
1486
1488
  backgroundColor: s = t,
1487
1489
  isEnabled: i = !1,
@@ -1489,7 +1491,7 @@ function Ie(r, t, e, n) {
1489
1491
  isLoaderVisible: c = !1,
1490
1492
  textColor: u = e,
1491
1493
  text: l = ""
1492
- } = r ? W("main-button") || {} : {}, p = new Te({
1494
+ } = r ? W("main-button") || {} : {}, p = new qe({
1493
1495
  backgroundColor: s,
1494
1496
  isEnabled: i,
1495
1497
  isLoaderVisible: c,
@@ -1507,7 +1509,7 @@ function Ie(r, t, e, n) {
1507
1509
  });
1508
1510
  return p.on("change", m), p;
1509
1511
  }
1510
- class Re {
1512
+ class $e {
1511
1513
  constructor(t) {
1512
1514
  o(this, "ee", new w());
1513
1515
  o(this, "state");
@@ -1656,11 +1658,11 @@ class Re {
1656
1658
  });
1657
1659
  }
1658
1660
  }
1659
- function Be(r, t, e, n, s) {
1661
+ function Ve(r, t, e, n, s) {
1660
1662
  const {
1661
1663
  backgroundColor: i = t,
1662
1664
  headerColor: a = "bg_color"
1663
- } = r ? W("mini-app") || {} : {}, c = new Re({
1665
+ } = r ? W("mini-app") || {} : {}, c = new $e({
1664
1666
  headerColor: a,
1665
1667
  backgroundColor: i,
1666
1668
  version: e,
@@ -1672,12 +1674,12 @@ function Be(r, t, e, n, s) {
1672
1674
  });
1673
1675
  return c.on("change", u), c;
1674
1676
  }
1675
- function De() {
1677
+ function Te() {
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
+ function Ie(r) {
1682
+ const t = new jt(r);
1681
1683
  return t.listen(), t;
1682
1684
  }
1683
1685
  async function Pt(r) {
@@ -1841,7 +1843,7 @@ function qt(r) {
1841
1843
  width: r.width
1842
1844
  })), r;
1843
1845
  }
1844
- function Ne(r, t, e) {
1846
+ function Re(r, t, e) {
1845
1847
  const n = qt(
1846
1848
  At(r, t, e) || new j({
1847
1849
  width: 0,
@@ -1855,7 +1857,7 @@ function Ne(r, t, e) {
1855
1857
  console.error("Unable to actualize viewport state", s);
1856
1858
  }), n;
1857
1859
  }
1858
- async function Oe(r, t, e) {
1860
+ async function Be(r, t, e) {
1859
1861
  return qt(
1860
1862
  At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: n, isStateStable: s, ...i }) => new j({
1861
1863
  ...i,
@@ -1867,7 +1869,7 @@ async function Oe(r, t, e) {
1867
1869
  function v(r, t) {
1868
1870
  document.documentElement.style.setProperty(r, t);
1869
1871
  }
1870
- function We(r, t) {
1872
+ function De(r, t) {
1871
1873
  const e = () => {
1872
1874
  v("--tg-background-color", r.backgroundColor);
1873
1875
  }, n = () => {
@@ -1879,7 +1881,7 @@ function We(r, t) {
1879
1881
  };
1880
1882
  t.on("change", n), r.on("change:backgroundColor", e), r.on("change:headerColor", n), e(), n();
1881
1883
  }
1882
- function Me(r) {
1884
+ function He(r) {
1883
1885
  const t = () => {
1884
1886
  const e = r.getState();
1885
1887
  Object.entries(e).forEach(([n, s]) => {
@@ -1895,7 +1897,7 @@ function it(r) {
1895
1897
  const t = () => v("--tg-viewport-height", `${r.height}px`), e = () => v("--tg-viewport-width", `${r.width}px`), n = () => v("--tg-viewport-height", `${r.stableHeight}px`);
1896
1898
  r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", n), t(), e(), n();
1897
1899
  }
1898
- function Ue(r) {
1900
+ function Ne(r) {
1899
1901
  return typeof r == "object" ? r : r ? {
1900
1902
  themeParams: !0,
1901
1903
  viewport: !0,
@@ -1903,10 +1905,10 @@ function Ue(r) {
1903
1905
  } : {};
1904
1906
  }
1905
1907
  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));
1908
+ const s = Ne(r);
1909
+ s.miniApp && De(t, e), s.themeParams && He(e), s.viewport && (n instanceof Promise ? n.then(it) : it(n));
1908
1910
  }
1909
- function je(r) {
1911
+ function Oe(r) {
1910
1912
  const { hostname: t, pathname: e } = new URL(r, window.location.href);
1911
1913
  if (t !== "t.me")
1912
1914
  throw new Error(`Incorrect hostname: ${t}`);
@@ -1915,7 +1917,7 @@ function je(r) {
1915
1917
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1916
1918
  return n[2];
1917
1919
  }
1918
- class Ge {
1920
+ class We {
1919
1921
  constructor(t, e = f) {
1920
1922
  o(this, "ee", new w());
1921
1923
  o(this, "state");
@@ -1945,7 +1947,7 @@ class Ge {
1945
1947
  async open(t, e) {
1946
1948
  if (this.isOpened)
1947
1949
  throw new Error("Invoice is already opened");
1948
- const n = e ? je(t) : t;
1950
+ const n = e ? Oe(t) : t;
1949
1951
  this.isOpened = !0;
1950
1952
  try {
1951
1953
  return (await _(
@@ -1964,7 +1966,7 @@ class Ge {
1964
1966
  }
1965
1967
  }
1966
1968
  }
1967
- function Fe(r) {
1969
+ function Me(r) {
1968
1970
  const t = r.message.trim(), e = (r.title || "").trim(), n = r.buttons || [];
1969
1971
  let s;
1970
1972
  if (e.length > 64)
@@ -1988,7 +1990,7 @@ function Fe(r) {
1988
1990
  return { ...i, id: a };
1989
1991
  }), { title: e, message: t, buttons: s };
1990
1992
  }
1991
- class ze {
1993
+ class Ue {
1992
1994
  constructor(t, e = f) {
1993
1995
  o(this, "ee", new w());
1994
1996
  o(this, "state");
@@ -2033,7 +2035,7 @@ class ze {
2033
2035
  throw new Error("Popup is already opened.");
2034
2036
  return this.isOpened = !0, _(
2035
2037
  "web_app_open_popup",
2036
- Fe(t),
2038
+ Me(t),
2037
2039
  "popup_closed",
2038
2040
  { postEvent: this.postEvent }
2039
2041
  ).then(({ button_id: e = null }) => e).finally(() => {
@@ -2041,7 +2043,7 @@ class ze {
2041
2043
  });
2042
2044
  }
2043
2045
  }
2044
- class Je {
2046
+ class je {
2045
2047
  constructor(t, e = f) {
2046
2048
  o(this, "ee", new w());
2047
2049
  o(this, "state");
@@ -2100,7 +2102,7 @@ class Je {
2100
2102
  }
2101
2103
  }
2102
2104
  }
2103
- class Qe {
2105
+ class Ge {
2104
2106
  constructor(t, e, n = f) {
2105
2107
  /**
2106
2108
  * Checks if specified method is supported by current component.
@@ -2171,72 +2173,79 @@ class Qe {
2171
2173
  ).then(({ data: t = null }) => t);
2172
2174
  }
2173
2175
  }
2174
- function ar(r) {
2176
+ function nr(r) {
2175
2177
  const {
2176
2178
  async: t = !1,
2177
2179
  cssVars: e = !1,
2178
2180
  acceptCustomStyles: n = !1
2179
- } = r, {
2180
- launchParams: {
2181
- initData: s,
2182
- initDataRaw: i,
2183
- version: a,
2184
- platform: c,
2185
- themeParams: u,
2186
- botInline: l = !1
2187
- },
2188
- isPageReload: p
2189
- } = Et(), m = De(), d = Ee(a);
2190
- Ct() && (n && Le(), d("iframe_ready", { reload_supported: !0 }), k("reload_iframe", () => window.location.reload()));
2191
- const y = {
2192
- backButton: $e(p, a, d),
2193
- closingBehavior: Ve(p, d),
2194
- cloudStorage: new Ae(a, m, d),
2195
- createRequestId: m,
2196
- hapticFeedback: new qe(a, d),
2197
- invoice: new Ge(a, d),
2198
- mainButton: Ie(
2199
- p,
2200
- u.buttonColor || "#000000",
2201
- u.buttonTextColor || "#ffffff",
2202
- d
2203
- ),
2204
- miniApp: Be(
2205
- p,
2206
- u.backgroundColor || "#ffffff",
2207
- a,
2208
- l,
2209
- d
2210
- ),
2211
- popup: new ze(a, d),
2212
- postEvent: d,
2213
- qrScanner: new Je(a, d),
2214
- themeParams: He(u),
2215
- utils: new Qe(a, m, d),
2216
- ...s ? {
2217
- initData: new Mt(s),
2218
- initDataRaw: i
2219
- } : {}
2220
- }, x = t ? Oe(p, c, d) : Ne(p, c, d);
2221
- return x instanceof Promise ? x.then((V) => (ot(
2222
- e,
2223
- y.miniApp,
2224
- y.themeParams,
2225
- V
2226
- ), {
2227
- ...y,
2228
- viewport: V
2229
- })) : (ot(
2230
- e,
2231
- y.miniApp,
2232
- y.themeParams,
2233
- x
2234
- ), { ...y, viewport: x });
2181
+ } = r;
2182
+ try {
2183
+ const {
2184
+ launchParams: {
2185
+ initData: s,
2186
+ initDataRaw: i,
2187
+ version: a,
2188
+ platform: c,
2189
+ themeParams: u,
2190
+ botInline: l = !1
2191
+ },
2192
+ isPageReload: p
2193
+ } = Et(), m = Te(), d = be(a);
2194
+ Ct() && (n && xe(), d("iframe_ready", { reload_supported: !0 }), k("reload_iframe", () => window.location.reload()));
2195
+ const y = {
2196
+ backButton: Pe(p, a, d),
2197
+ closingBehavior: Ae(p, d),
2198
+ cloudStorage: new ke(a, m, d),
2199
+ createRequestId: m,
2200
+ hapticFeedback: new Se(a, d),
2201
+ invoice: new We(a, d),
2202
+ mainButton: Le(
2203
+ p,
2204
+ u.buttonColor || "#000000",
2205
+ u.buttonTextColor || "#ffffff",
2206
+ d
2207
+ ),
2208
+ miniApp: Ve(
2209
+ p,
2210
+ u.backgroundColor || "#ffffff",
2211
+ a,
2212
+ l,
2213
+ d
2214
+ ),
2215
+ popup: new Ue(a, d),
2216
+ postEvent: d,
2217
+ qrScanner: new je(a, d),
2218
+ themeParams: Ie(u),
2219
+ utils: new Ge(a, m, d),
2220
+ ...s ? {
2221
+ initData: new Ot(s),
2222
+ initDataRaw: i
2223
+ } : {}
2224
+ }, x = t ? Be(p, c, d) : Re(p, c, d);
2225
+ return x instanceof Promise ? x.then((V) => (ot(
2226
+ e,
2227
+ y.miniApp,
2228
+ y.themeParams,
2229
+ V
2230
+ ), {
2231
+ ...y,
2232
+ viewport: V
2233
+ })) : (ot(
2234
+ e,
2235
+ y.miniApp,
2236
+ y.themeParams,
2237
+ x
2238
+ ), { ...y, viewport: x });
2239
+ } catch (s) {
2240
+ if (t)
2241
+ return Promise.reject(s);
2242
+ throw s;
2243
+ }
2235
2244
  }
2236
2245
  function R(r, t) {
2237
2246
  return r.startsWith(t) ? r : `${t}${r}`;
2238
2247
  }
2239
- function cr(r) {
2248
+ function sr(r) {
2240
2249
  const t = r.match(/#(.+)/);
2241
2250
  return t ? t[1] : null;
2242
2251
  }
@@ -2253,14 +2262,14 @@ async function B(r) {
2253
2262
  })
2254
2263
  ]);
2255
2264
  }
2256
- async function Ze() {
2265
+ async function Fe() {
2257
2266
  if (window.history.length <= 1 || (window.history.pushState(null, ""), await B(1 - window.history.length)))
2258
2267
  return;
2259
2268
  let t = await B(-1);
2260
2269
  for (; t; )
2261
2270
  t = await B(-1);
2262
2271
  }
2263
- class Ke {
2272
+ class ze {
2264
2273
  constructor(t, e, {
2265
2274
  debug: n = !1,
2266
2275
  loggerPrefix: s = "Navigator"
@@ -2460,7 +2469,7 @@ class Ke {
2460
2469
  }
2461
2470
  }
2462
2471
  const at = 0, J = 1, Q = 2;
2463
- class Lt extends Ke {
2472
+ class Lt extends ze {
2464
2473
  constructor(e, n, s = {}) {
2465
2474
  super(e, n, {
2466
2475
  ...s,
@@ -2524,7 +2533,7 @@ class Lt extends Ke {
2524
2533
  async syncHistory() {
2525
2534
  window.removeEventListener("popstate", this.onPopState);
2526
2535
  const e = `#${this.path}`;
2527
- 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);
2536
+ await Fe(), f("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e), window.history.pushState(Q, ""), await B(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(Q, ""), await B(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(at, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
2528
2537
  }
2529
2538
  emitChanged(e, n) {
2530
2539
  this.ee.emit("change", {
@@ -2548,58 +2557,58 @@ class Lt extends Ke {
2548
2557
  }
2549
2558
  }
2550
2559
  export {
2551
- ve as BackButton,
2552
- xe as ClosingBehavior,
2553
- Ae as CloudStorage,
2554
- qe as HapticFeedback,
2560
+ ye as BackButton,
2561
+ ve as ClosingBehavior,
2562
+ ke as CloudStorage,
2563
+ Se as HapticFeedback,
2555
2564
  Lt as HashNavigator,
2556
- Mt as InitData,
2557
- Ge as Invoice,
2558
- Te as MainButton,
2565
+ Ot as InitData,
2566
+ We as Invoice,
2567
+ qe as MainButton,
2559
2568
  K as MethodUnsupportedError,
2560
- Re as MiniApp,
2561
- Ke as Navigator,
2569
+ $e as MiniApp,
2570
+ ze as Navigator,
2562
2571
  Y as ParameterUnsupportedError,
2563
- ze as Popup,
2564
- Je as QRScanner,
2565
- zt as ThemeParams,
2566
- Qe as Utils,
2572
+ Ue as Popup,
2573
+ je as QRScanner,
2574
+ jt as ThemeParams,
2575
+ Ge as Utils,
2567
2576
  j as Viewport,
2568
- Wt as chatParser,
2569
- ke as classNames,
2570
- ye as compareVersions,
2571
- Ee as createPostEvent,
2572
- cr as getHash,
2573
- ar as init,
2577
+ Nt as chatParser,
2578
+ Ee as classNames,
2579
+ _e as compareVersions,
2580
+ be as createPostEvent,
2581
+ sr as getHash,
2582
+ nr as init,
2574
2583
  gt as initDataParser,
2575
2584
  lt as isColorDark,
2576
2585
  Ct as isIframe,
2577
2586
  ut as isRGB,
2578
- Nt as isRGBShort,
2587
+ Ht as isRGBShort,
2579
2588
  D as isRecord,
2580
- er as isTMA,
2589
+ Ke as isTMA,
2581
2590
  bt as launchParamsParser,
2582
- or as mergeClassNames,
2591
+ rr as mergeClassNames,
2583
2592
  N as off,
2584
2593
  k as on,
2585
- sr as once,
2586
- Xe as parseInitData,
2594
+ tr as once,
2595
+ Qe as parseInitData,
2587
2596
  mt as parseLaunchParams,
2588
2597
  _t as parseThemeParams,
2589
2598
  f as postEvent,
2590
2599
  _ as request,
2591
- tr as requestThemeParams,
2600
+ Ze as requestThemeParams,
2592
2601
  Pt as requestViewport,
2593
2602
  Et as retrieveLaunchData,
2594
- Kt as serializeLaunchParams,
2595
- Ft as serializeThemeParams,
2596
- rr as setDebug,
2597
- nr as setTargetOrigin,
2598
- ir as subscribe,
2603
+ Jt as serializeLaunchParams,
2604
+ Ut as serializeThemeParams,
2605
+ Ye as setDebug,
2606
+ Xe as setTargetOrigin,
2607
+ er as subscribe,
2599
2608
  q as supports,
2600
2609
  wt as themeParamsParser,
2601
2610
  pt as toRGB,
2602
- me as unsubscribe,
2611
+ we as unsubscribe,
2603
2612
  tt as userParser
2604
2613
  };
2605
2614
  //# sourceMappingURL=index.mjs.map