@tma.js/sdk 0.11.6 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/dts/components/CloudStorage/CloudStorage.d.ts +2 -2
  2. package/dist/dts/components/ThemeParams/ThemeParams.d.ts +4 -3
  3. package/dist/dts/components/ThemeParams/types.d.ts +2 -2
  4. package/dist/dts/components/WebApp/WebApp.d.ts +5 -4
  5. package/dist/dts/index.d.ts +2 -3
  6. package/dist/dts/init/creators/createBackButton.d.ts +2 -1
  7. package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -1
  8. package/dist/dts/init/creators/createMainButton.d.ts +2 -1
  9. package/dist/dts/init/creators/createThemeParams.d.ts +7 -0
  10. package/dist/dts/init/creators/createViewport.d.ts +3 -2
  11. package/dist/dts/init/creators/createWebApp.d.ts +4 -2
  12. package/dist/dts/init/creators/index.d.ts +1 -1
  13. package/dist/dts/init/types.d.ts +5 -5
  14. package/dist/dts/launch-params.d.ts +3 -17
  15. package/dist/dts/state/State.d.ts +1 -1
  16. package/dist/dts/storage.d.ts +0 -1
  17. package/dist/dts/types.d.ts +0 -4
  18. package/dist/index.js +288 -298
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.umd.cjs +1 -1
  21. package/dist/index.umd.cjs.map +1 -1
  22. package/package.json +10 -7
  23. package/src/components/InitData/InitData.ts +14 -6
  24. package/src/components/MainButton/MainButton.ts +1 -1
  25. package/src/components/ThemeParams/ThemeParams.ts +3 -3
  26. package/src/components/ThemeParams/types.ts +5 -5
  27. package/src/components/WebApp/WebApp.ts +2 -1
  28. package/src/index.ts +2 -3
  29. package/src/init/creators/createBackButton.ts +7 -2
  30. package/src/init/creators/createClosingBehavior.ts +6 -2
  31. package/src/init/creators/createMainButton.ts +3 -1
  32. package/src/init/creators/{createSyncedThemeParams.ts → createThemeParams.ts} +3 -3
  33. package/src/init/creators/createViewport.ts +8 -4
  34. package/src/init/creators/createWebApp.ts +5 -2
  35. package/src/init/creators/index.ts +1 -1
  36. package/src/init/init.ts +67 -20
  37. package/src/init/types.ts +5 -5
  38. package/src/launch-params.ts +14 -55
  39. package/src/storage.ts +1 -2
  40. package/src/types.ts +0 -15
  41. package/dist/dts/init/creators/createSyncedThemeParams.d.ts +0 -7
  42. package/dist/dts/theme-params.d.ts +0 -18
  43. package/src/theme-params.ts +0 -34
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
- var nt = Object.defineProperty;
2
- var it = (s, t, e) => t in s ? nt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var i = (s, t, e) => (it(s, typeof t != "symbol" ? t + "" : t, e), e);
4
- import { array as at, string as P, json as j, rgb as w, searchParams as ct } from "@tma.js/parsing";
5
- import { initData as ht } from "@tma.js/init-data";
6
- import { supports as C, postEvent as l, on as S, off as F, request as g, detectSupportParams as pt, setDebug as ut, setTargetOrigin as lt, isIframe as dt } from "@tma.js/bridge";
7
- import { compareVersions as gt, isRecord as bt, withTimeout as _t } from "@tma.js/utils";
8
- import { EventEmitter as f } from "@tma.js/event-emitter";
9
- import { isColorDark as J, isRGB as ft } from "@tma.js/colors";
10
- function y(s, t) {
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 U, 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";
11
+ function v(s, t) {
11
12
  return (e) => C(t[e], s);
12
13
  }
13
14
  function mt(s, t) {
@@ -16,7 +17,7 @@ function mt(s, t) {
16
17
  return C(o, r, s);
17
18
  };
18
19
  }
19
- class b {
20
+ class f {
20
21
  constructor(t, e) {
21
22
  this.state = t, this.ee = e;
22
23
  }
@@ -39,9 +40,9 @@ class b {
39
40
  return this.state[t];
40
41
  }
41
42
  }
42
- class wt {
43
- constructor(t, e, o = l) {
44
- i(this, "ee", new f());
43
+ class Ct {
44
+ constructor(t, e, o = g) {
45
+ i(this, "ee", new w());
45
46
  i(this, "state");
46
47
  /**
47
48
  * Adds event listener.
@@ -50,7 +51,7 @@ class wt {
50
51
  */
51
52
  i(this, "on", (t, e) => {
52
53
  if (t === "click")
53
- return S("back_button_pressed", e);
54
+ return x("back_button_pressed", e);
54
55
  this.ee.on(t, e);
55
56
  });
56
57
  /**
@@ -60,14 +61,14 @@ class wt {
60
61
  */
61
62
  i(this, "off", (t, e) => {
62
63
  if (t === "click")
63
- return F("back_button_pressed", e);
64
+ return K("back_button_pressed", e);
64
65
  this.ee.off(t, e);
65
66
  });
66
67
  /**
67
68
  * Checks if specified method is supported by current component.
68
69
  */
69
70
  i(this, "supports");
70
- this.postEvent = o, this.state = new b({ isVisible: t }, this.ee), this.supports = y(e, {
71
+ this.postEvent = o, this.state = new f({ isVisible: t }, this.ee), this.supports = v(e, {
71
72
  show: "web_app_setup_back_button",
72
73
  hide: "web_app_setup_back_button"
73
74
  });
@@ -94,9 +95,9 @@ class wt {
94
95
  this.isVisible = !0;
95
96
  }
96
97
  }
97
- class Ct {
98
- constructor(t, e = l) {
99
- i(this, "ee", new f());
98
+ class vt {
99
+ constructor(t, e = g) {
100
+ i(this, "ee", new w());
100
101
  i(this, "state");
101
102
  /**
102
103
  * Adds new event listener.
@@ -106,7 +107,7 @@ class Ct {
106
107
  * Removes event listener.
107
108
  */
108
109
  i(this, "off", this.ee.off.bind(this.ee));
109
- this.postEvent = e, this.state = new b({ isConfirmationNeeded: t }, this.ee);
110
+ this.postEvent = e, this.state = new f({ isConfirmationNeeded: t }, this.ee);
110
111
  }
111
112
  set isConfirmationNeeded(t) {
112
113
  this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
@@ -133,17 +134,17 @@ class Ct {
133
134
  this.isConfirmationNeeded = !0;
134
135
  }
135
136
  }
136
- const yt = at().of(P());
137
- function M(s, t) {
137
+ const yt = dt().of(j());
138
+ function z(s, t) {
138
139
  return s.reduce((e, o) => (e[o] = t, e), {});
139
140
  }
140
- class vt {
141
- constructor(t, e, o = l) {
141
+ class Et {
142
+ constructor(t, e, o = g) {
142
143
  /**
143
144
  * Checks if specified method is supported by current component.
144
145
  */
145
146
  i(this, "supports");
146
- this.createRequestId = e, this.postEvent = o, this.supports = y(t, {
147
+ this.createRequestId = e, this.postEvent = o, this.supports = v(t, {
147
148
  deleteKeys: "web_app_invoke_custom_method",
148
149
  getKeys: "web_app_invoke_custom_method",
149
150
  getValues: "web_app_invoke_custom_method",
@@ -157,7 +158,7 @@ class vt {
157
158
  * @param options - execution options.
158
159
  */
159
160
  async invokeCustomMethod(t, e, o = {}) {
160
- const { result: r, error: n } = await g(
161
+ const { result: r, error: n } = await _(
161
162
  "web_app_invoke_custom_method",
162
163
  { method: t, params: e, req_id: this.createRequestId() },
163
164
  "custom_method_invoked",
@@ -191,9 +192,9 @@ class vt {
191
192
  */
192
193
  async getValues(t, e) {
193
194
  if (t.length === 0)
194
- return M(t, "");
195
- const o = j(
196
- M(t, P())
195
+ return z(t, "");
196
+ const o = gt(
197
+ z(t, j())
197
198
  // fixme
198
199
  ), r = await this.invokeCustomMethod("getStorageValues", { keys: t }, e);
199
200
  return o.parse(r);
@@ -209,12 +210,12 @@ class vt {
209
210
  }
210
211
  }
211
212
  class kt {
212
- constructor(t, e = l) {
213
+ constructor(t, e = g) {
213
214
  /**
214
215
  * Checks if specified method is supported by current component.
215
216
  */
216
217
  i(this, "supports");
217
- this.postEvent = e, this.supports = y(t, {
218
+ this.postEvent = e, this.supports = v(t, {
218
219
  impactOccurred: "web_app_trigger_haptic_feedback",
219
220
  notificationOccurred: "web_app_trigger_haptic_feedback",
220
221
  selectionChanged: "web_app_trigger_haptic_feedback"
@@ -251,25 +252,29 @@ class kt {
251
252
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
252
253
  }
253
254
  }
254
- class Et {
255
+ class xt {
255
256
  constructor(t, e, o = {}) {
256
257
  i(this, "state");
257
258
  const {
258
259
  chat: r = null,
259
260
  canSendAfter: n = null,
260
- user: c = null,
261
- queryId: a = null,
262
- receiver: p = null,
263
- startParam: h = null
261
+ chatType: a = null,
262
+ chatInstance: c = null,
263
+ user: u = null,
264
+ queryId: p = null,
265
+ receiver: h = null,
266
+ startParam: l = null
264
267
  } = o;
265
- this.state = new b({
268
+ this.state = new f({
266
269
  authDate: t,
267
- canSendAfter: n,
270
+ canSendAfter: n === null ? null : new Date(t.getTime() + n * 1e3),
268
271
  chat: r,
269
- user: c,
270
- queryId: a,
271
- receiver: p,
272
- startParam: h,
272
+ chatType: a,
273
+ chatInstance: c,
274
+ user: u,
275
+ queryId: p,
276
+ receiver: h,
277
+ startParam: l,
273
278
  hash: e
274
279
  });
275
280
  }
@@ -334,9 +339,9 @@ class Et {
334
339
  return this.state.get("user");
335
340
  }
336
341
  }
337
- class xt {
338
- constructor(t, e, o, r, n, c, a = l) {
339
- i(this, "ee", new f());
342
+ class Vt {
343
+ constructor(t, e, o, r, n, a, c = g) {
344
+ i(this, "ee", new w());
340
345
  i(this, "state");
341
346
  /**
342
347
  * Adds new event listener.
@@ -348,7 +353,7 @@ class xt {
348
353
  */
349
354
  i(this, "on", (t, e) => {
350
355
  if (t === "click")
351
- return S("main_button_pressed", e);
356
+ return x("main_button_pressed", e);
352
357
  this.ee.on(t, e);
353
358
  });
354
359
  /**
@@ -358,16 +363,16 @@ class xt {
358
363
  */
359
364
  i(this, "off", (t, e) => {
360
365
  if (t === "click")
361
- return F("main_button_pressed", e);
366
+ return K("main_button_pressed", e);
362
367
  this.ee.off(t, e);
363
368
  });
364
- this.postEvent = a, this.state = new b({
369
+ this.postEvent = c, this.state = new f({
365
370
  backgroundColor: t,
366
371
  isEnabled: e,
367
372
  isVisible: o,
368
373
  isProgressVisible: r,
369
374
  text: n,
370
- textColor: c
375
+ textColor: a
371
376
  }, this.ee);
372
377
  }
373
378
  set isEnabled(t) {
@@ -503,7 +508,7 @@ class xt {
503
508
  return this.state.set("backgroundColor", t), this.commit(), this;
504
509
  }
505
510
  }
506
- function Pt(s) {
511
+ function St(s) {
507
512
  const t = s.message.trim(), e = (s.title || "").trim(), o = s.buttons || [];
508
513
  let r;
509
514
  if (e.length > 64)
@@ -513,23 +518,23 @@ function Pt(s) {
513
518
  if (o.length > 3)
514
519
  throw new Error(`Buttons have incorrect size: ${o.length}`);
515
520
  return o.length === 0 ? r = [{ type: "close", id: "" }] : r = o.map((n) => {
516
- const { id: c = "" } = n;
517
- if (c.length > 64)
518
- throw new Error(`Button ID has incorrect size: ${c}`);
521
+ const { id: a = "" } = n;
522
+ if (a.length > 64)
523
+ throw new Error(`Button ID has incorrect size: ${a}`);
519
524
  if (n.type === void 0 || n.type === "default" || n.type === "destructive") {
520
- const a = n.text.trim();
521
- if (a.length === 0 || a.length > 64) {
522
- const p = n.type || "default";
523
- throw new Error(`Button text with type "${p}" has incorrect size: ${n.text.length}`);
525
+ const c = n.text.trim();
526
+ if (c.length === 0 || c.length > 64) {
527
+ const u = n.type || "default";
528
+ throw new Error(`Button text with type "${u}" has incorrect size: ${n.text.length}`);
524
529
  }
525
- return { ...n, text: a, id: c };
530
+ return { ...n, text: c, id: a };
526
531
  }
527
- return { ...n, id: c };
532
+ return { ...n, id: a };
528
533
  }), { title: e, message: t, buttons: r };
529
534
  }
530
- class Vt {
531
- constructor(t, e = l) {
532
- i(this, "ee", new f());
535
+ class Pt {
536
+ constructor(t, e = g) {
537
+ i(this, "ee", new w());
533
538
  i(this, "state");
534
539
  /**
535
540
  * Adds new event listener.
@@ -543,7 +548,7 @@ class Vt {
543
548
  * Checks if specified method is supported by current component.
544
549
  */
545
550
  i(this, "supports");
546
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_popup" });
551
+ this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, { open: "web_app_open_popup" });
547
552
  }
548
553
  /**
549
554
  * Shows whether popup is currently opened.
@@ -569,9 +574,9 @@ class Vt {
569
574
  throw new Error("Popup is already opened.");
570
575
  this.state.set("isOpened", !0);
571
576
  try {
572
- const { button_id: e = null } = await g(
577
+ const { button_id: e = null } = await _(
573
578
  "web_app_open_popup",
574
- Pt(t),
579
+ St(t),
575
580
  "popup_closed",
576
581
  { postEvent: this.postEvent }
577
582
  );
@@ -581,9 +586,9 @@ class Vt {
581
586
  }
582
587
  }
583
588
  }
584
- class St {
585
- constructor(t, e = l) {
586
- i(this, "ee", new f());
589
+ class qt {
590
+ constructor(t, e = g) {
591
+ i(this, "ee", new w());
587
592
  i(this, "state");
588
593
  /**
589
594
  * Adds new event listener.
@@ -597,7 +602,7 @@ class St {
597
602
  * Checks if specified method is supported by current component.
598
603
  */
599
604
  i(this, "supports");
600
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = y(t, {
605
+ this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, {
601
606
  close: "web_app_close_scan_qr_popup",
602
607
  open: "web_app_open_scan_qr_popup"
603
608
  });
@@ -628,7 +633,7 @@ class St {
628
633
  throw new Error("QR scanner is already opened.");
629
634
  this.isOpened = !0;
630
635
  try {
631
- const e = await g(
636
+ const e = await _(
632
637
  "web_app_open_scan_qr_popup",
633
638
  { text: t },
634
639
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -640,27 +645,15 @@ class St {
640
645
  }
641
646
  }
642
647
  }
643
- const qt = j({
644
- backgroundColor: { type: w().optional(), from: "bg_color" },
645
- buttonColor: { type: w().optional(), from: "button_color" },
646
- buttonTextColor: { type: w().optional(), from: "button_text_color" },
647
- hintColor: { type: w().optional(), from: "hint_color" },
648
- linkColor: { type: w().optional(), from: "link_color" },
649
- textColor: { type: w().optional(), from: "text_color" },
650
- secondaryBackgroundColor: { type: w().optional(), from: "secondary_bg_color" }
651
- });
652
- function $(s) {
653
- return qt.parse(s);
654
- }
655
- function U(s) {
648
+ function M(s) {
656
649
  const {
657
650
  backgroundColor: t = null,
658
651
  buttonTextColor: e = null,
659
652
  buttonColor: o = null,
660
653
  hintColor: r = null,
661
654
  linkColor: n = null,
662
- textColor: c = null,
663
- secondaryBackgroundColor: a = null
655
+ textColor: a = null,
656
+ secondaryBackgroundColor: c = null
664
657
  } = s;
665
658
  return {
666
659
  backgroundColor: t,
@@ -668,13 +661,13 @@ function U(s) {
668
661
  buttonColor: o,
669
662
  hintColor: r,
670
663
  linkColor: n,
671
- textColor: c,
672
- secondaryBackgroundColor: a
664
+ textColor: a,
665
+ secondaryBackgroundColor: c
673
666
  };
674
667
  }
675
- class q {
668
+ class P {
676
669
  constructor(t) {
677
- i(this, "ee", new f());
670
+ i(this, "ee", new w());
678
671
  i(this, "state");
679
672
  /**
680
673
  * Adds new event listener.
@@ -684,7 +677,7 @@ class q {
684
677
  * Removes event listener.
685
678
  */
686
679
  i(this, "off", this.ee.off.bind(this.ee));
687
- this.state = new b(U(t), this.ee);
680
+ this.state = new f(M(t), this.ee);
688
681
  }
689
682
  /**
690
683
  * Requests fresh information about current theme.
@@ -693,11 +686,11 @@ class q {
693
686
  * @param options - method options.
694
687
  */
695
688
  static async request(t = {}) {
696
- const { timeout: e = 1e3, ...o } = t, r = await g("web_app_request_theme", "theme_changed", {
689
+ const { timeout: e = 1e3, ...o } = t, r = await _("web_app_request_theme", "theme_changed", {
697
690
  ...o,
698
691
  timeout: e
699
692
  });
700
- return $(r.theme_params);
693
+ return N(r.theme_params);
701
694
  }
702
695
  /**
703
696
  * Synchronizes specified instance of ThemeParams with the actual value in the native
@@ -705,8 +698,8 @@ class q {
705
698
  * @param themeParams - ThemeParams instance.
706
699
  */
707
700
  static sync(t) {
708
- S("theme_changed", (e) => {
709
- t.state.set(U($(e.theme_params)));
701
+ x("theme_changed", (e) => {
702
+ t.state.set(M(N(e.theme_params)));
710
703
  });
711
704
  }
712
705
  /**
@@ -715,7 +708,7 @@ class q {
715
708
  * @param options - method options.
716
709
  */
717
710
  static async synced(t) {
718
- const e = await this.request(t), o = new q(e);
711
+ const e = await this.request(t), o = new P(e);
719
712
  return this.sync(o), o;
720
713
  }
721
714
  /**
@@ -768,12 +761,12 @@ class q {
768
761
  return this.state.get("textColor");
769
762
  }
770
763
  }
771
- function x(s) {
764
+ function E(s) {
772
765
  return s < 0 ? 0 : s;
773
766
  }
774
- class V {
775
- constructor(t, e, o, r, n = l) {
776
- i(this, "ee", new f());
767
+ class k {
768
+ constructor(t, e, o, r, n = g) {
769
+ i(this, "ee", new w());
777
770
  i(this, "state");
778
771
  /**
779
772
  * Adds new event listener.
@@ -783,11 +776,11 @@ class V {
783
776
  * Removes event listener.
784
777
  */
785
778
  i(this, "off", this.ee.off.bind(this.ee));
786
- this.postEvent = n, this.state = new b({
787
- height: x(t),
779
+ this.postEvent = n, this.state = new f({
780
+ height: E(t),
788
781
  isExpanded: r,
789
- stableHeight: x(o),
790
- width: x(e)
782
+ stableHeight: E(o),
783
+ width: E(e)
791
784
  }, this.ee);
792
785
  }
793
786
  /**
@@ -801,12 +794,12 @@ class V {
801
794
  const { timeout: e = 1e3, ...o } = t, {
802
795
  is_expanded: r,
803
796
  is_state_stable: n,
804
- ...c
805
- } = await g("web_app_request_viewport", "viewport_changed", {
797
+ ...a
798
+ } = await _("web_app_request_viewport", "viewport_changed", {
806
799
  ...o,
807
800
  timeout: e
808
801
  });
809
- return { ...c, isExpanded: r, isStateStable: n };
802
+ return { ...a, isExpanded: r, isStateStable: n };
810
803
  }
811
804
  /**
812
805
  * Synchronizes specified instance of Viewport with the actual value in the native
@@ -814,18 +807,18 @@ class V {
814
807
  * @param viewport - Viewport instance.
815
808
  */
816
809
  static sync(t) {
817
- S("viewport_changed", (e) => {
810
+ x("viewport_changed", (e) => {
818
811
  const {
819
812
  height: o,
820
813
  width: r,
821
814
  is_expanded: n,
822
- is_state_stable: c
823
- } = e, a = x(o);
815
+ is_state_stable: a
816
+ } = e, c = E(o);
824
817
  t.state.set({
825
- height: a,
818
+ height: c,
826
819
  isExpanded: n,
827
- width: x(r),
828
- stableHeight: c ? a : void 0
820
+ width: E(r),
821
+ stableHeight: a ? c : void 0
829
822
  });
830
823
  });
831
824
  }
@@ -835,7 +828,7 @@ class V {
835
828
  * @param options - method options.
836
829
  */
837
830
  static async synced(t = {}) {
838
- const { height: e, isExpanded: o, width: r } = await this.request(t), n = new V(e, r, e, o, t.postEvent);
831
+ const { height: e, isExpanded: o, width: r } = await this.request(t), n = new k(e, r, e, o, t.postEvent);
839
832
  return this.sync(n), n;
840
833
  }
841
834
  /**
@@ -923,8 +916,8 @@ function T(s) {
923
916
  return t.href;
924
917
  }
925
918
  class Ot {
926
- constructor(t, e, o, r, n, c = l) {
927
- i(this, "ee", new f());
919
+ constructor(t, e, o, r, n, a = g) {
920
+ i(this, "ee", new w());
928
921
  i(this, "state");
929
922
  /**
930
923
  * Adds new event listener.
@@ -942,10 +935,10 @@ class Ot {
942
935
  * Checks if specified method parameter is supported by current component.
943
936
  */
944
937
  i(this, "supportsParam");
945
- this.currentVersion = o, this.currentPlatform = r, this.createRequestId = n, this.postEvent = c, this.state = new b({
938
+ this.currentVersion = o, this.currentPlatform = r, this.createRequestId = n, this.postEvent = a, this.state = new f({
946
939
  backgroundColor: e,
947
940
  headerColor: t
948
- }, this.ee), this.supports = y(o, {
941
+ }, this.ee), this.supports = v(o, {
949
942
  openInvoice: "web_app_open_invoice",
950
943
  readTextFromClipboard: "web_app_read_text_from_clipboard",
951
944
  setHeaderColor: "web_app_set_header_color",
@@ -988,7 +981,7 @@ class Ot {
988
981
  * @param version - compared version.
989
982
  */
990
983
  isVersionAtLeast(t) {
991
- return gt(t, this.version) >= 0;
984
+ return _t(t, this.version) >= 0;
992
985
  }
993
986
  /**
994
987
  * Opens a link in an external browser. The Web App will not be closed.
@@ -1039,9 +1032,9 @@ class Ot {
1039
1032
  if (r === null)
1040
1033
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');
1041
1034
  const [, , n] = r;
1042
- return (await g("web_app_open_invoice", { slug: n }, "invoice_closed", {
1035
+ return (await _("web_app_open_invoice", { slug: n }, "invoice_closed", {
1043
1036
  postEvent: this.postEvent,
1044
- capture: ({ slug: a }) => n === a
1037
+ capture: ({ slug: c }) => n === c
1045
1038
  })).status;
1046
1039
  }
1047
1040
  /**
@@ -1070,7 +1063,7 @@ class Ot {
1070
1063
  * - Access to clipboard is not allowed
1071
1064
  */
1072
1065
  async readTextFromClipboard() {
1073
- const { data: t = null } = await g(
1066
+ const { data: t = null } = await _(
1074
1067
  "web_app_read_text_from_clipboard",
1075
1068
  { req_id: this.createRequestId() },
1076
1069
  "clipboard_text_received",
@@ -1082,7 +1075,7 @@ class Ot {
1082
1075
  * Requests current user phone access.
1083
1076
  */
1084
1077
  async requestPhoneAccess() {
1085
- const { status: t } = await g("web_app_request_phone", "phone_requested", {
1078
+ const { status: t } = await _("web_app_request_phone", "phone_requested", {
1086
1079
  postEvent: this.postEvent
1087
1080
  });
1088
1081
  return t;
@@ -1091,7 +1084,7 @@ class Ot {
1091
1084
  * Requests write message access to current user.
1092
1085
  */
1093
1086
  async requestWriteAccess() {
1094
- const { status: t } = await g("web_app_request_write_access", "write_access_requested", {
1087
+ const { status: t } = await _("web_app_request_write_access", "write_access_requested", {
1095
1088
  postEvent: this.postEvent
1096
1089
  });
1097
1090
  return t;
@@ -1121,7 +1114,7 @@ class Ot {
1121
1114
  * @param color - color key or RGB color.
1122
1115
  */
1123
1116
  setHeaderColor(t) {
1124
- this.postEvent("web_app_set_header_color", ft(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1117
+ this.postEvent("web_app_set_header_color", bt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1125
1118
  }
1126
1119
  /**
1127
1120
  * Updates current application background color.
@@ -1142,117 +1135,99 @@ class Ot {
1142
1135
  return this.currentVersion;
1143
1136
  }
1144
1137
  }
1145
- function G(s) {
1146
- return `telegram-web-apps-${s}`;
1147
- }
1148
- function v(s, t) {
1149
- sessionStorage.setItem(G(s), JSON.stringify(t));
1150
- }
1151
- function k(s) {
1152
- const t = sessionStorage.getItem(G(s));
1153
- return t ? JSON.parse(t) : null;
1154
- }
1155
- const Bt = ct({
1156
- version: { type: P(), from: "tgWebAppVersion" },
1157
- initData: { type: ht.optional(), from: "tgWebAppData" },
1158
- initDataRaw: { type: P().optional(), from: "tgWebAppData" },
1159
- platform: { type: P(), from: "tgWebAppPlatform" },
1160
- themeParams: { type: $, from: "tgWebAppThemeParams" }
1161
- });
1162
- function R(s) {
1163
- return Bt.parse(s);
1138
+ class $ extends Error {
1139
+ constructor(t, e) {
1140
+ super(`Method "${t}" is not supported in the Web Apps version ${e}.`), Object.setPrototypeOf(this, $.prototype);
1141
+ }
1164
1142
  }
1165
- function Q() {
1166
- const s = [];
1167
- try {
1168
- const t = window.location.hash.slice(1), e = R(t);
1169
- return v("launch-params", t), e;
1170
- } catch (t) {
1171
- s.push(t instanceof Error ? t.message : "unknown error");
1143
+ class I extends Error {
1144
+ constructor(t, e, o) {
1145
+ super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`), Object.setPrototypeOf(this, I.prototype);
1172
1146
  }
1173
- try {
1174
- const t = k("launch-params");
1175
- if (t)
1176
- return R(t);
1177
- s.push("Launch params are missing in local storage");
1178
- } catch (t) {
1179
- s.push(t instanceof Error ? t.message : "unknown error");
1180
- }
1181
- throw new Error(`Unable to extract launch params. Errors: "${s.join('", "')}"`);
1182
1147
  }
1183
- function Z(s, t) {
1148
+ function G(s, t) {
1184
1149
  document.documentElement.style.setProperty(s, t);
1185
1150
  }
1186
- function d(s, t) {
1187
- t !== null && Z(s, t);
1151
+ function b(s, t) {
1152
+ t !== null && G(s, t);
1188
1153
  }
1189
- function K(s, t) {
1190
- Z(s, `${t}px`);
1154
+ function W(s, t) {
1155
+ G(s, `${t}px`);
1191
1156
  }
1192
- function At(s) {
1157
+ function Bt(s) {
1193
1158
  const {
1194
1159
  backgroundColor: t,
1195
1160
  buttonTextColor: e,
1196
1161
  secondaryBackgroundColor: o,
1197
1162
  hintColor: r,
1198
1163
  buttonColor: n,
1199
- linkColor: c,
1200
- textColor: a
1164
+ linkColor: a,
1165
+ textColor: c
1201
1166
  } = s;
1202
- d("--tg-theme-bg-color", t), d("--tg-theme-button-color", n), d("--tg-theme-button-text-color", e), d("--tg-theme-hint-color", r), d("--tg-theme-link-color", c), d("--tg-theme-secondary-bg-color", o), d("--tg-theme-text-color", a);
1167
+ b("--tg-theme-bg-color", t), b("--tg-theme-button-color", n), b("--tg-theme-button-text-color", e), b("--tg-theme-hint-color", r), b("--tg-theme-link-color", a), b("--tg-theme-secondary-bg-color", o), b("--tg-theme-text-color", c);
1203
1168
  }
1204
1169
  function Tt(s, t) {
1205
1170
  const { backgroundColor: e, secondaryBackgroundColor: o } = t, { backgroundColor: r, headerColor: n } = s;
1206
- d("--tg-bg-color", r), d("--tg-header-color", n === "bg_color" ? e : o);
1171
+ b("--tg-bg-color", r), b("--tg-header-color", n === "bg_color" ? e : o);
1207
1172
  }
1208
1173
  function $t(s) {
1209
- const t = () => At(s);
1174
+ const t = () => Bt(s);
1210
1175
  s.on("changed", t), t();
1211
1176
  }
1212
- function Rt(s, t) {
1177
+ function It(s, t) {
1213
1178
  const e = () => Tt(s, t);
1214
1179
  t.on("changed", e), s.on("backgroundColorChanged", e), s.on("headerColorChanged", e), e();
1215
1180
  }
1216
- function Ht(s) {
1181
+ function At(s) {
1217
1182
  const t = () => {
1218
- K("--tg-viewport-height", s.height);
1183
+ W("--tg-viewport-height", s.height);
1219
1184
  }, e = () => {
1220
- K("--tg-viewport-stable-height", s.stableHeight);
1185
+ W("--tg-viewport-stable-height", s.stableHeight);
1221
1186
  };
1222
1187
  s.on("heightChanged", t), s.on("stableHeightChanged", e), t(), e();
1223
1188
  }
1224
- function It(s) {
1189
+ function Ht(s) {
1225
1190
  return typeof s == "boolean" ? s ? { themeParams: !0, viewport: !0, webApp: !0 } : {} : s;
1226
1191
  }
1227
- function Dt(s, t) {
1228
- const { isVisible: e = !1 } = k("back-button") || {}, o = new wt(e, s, t);
1229
- return o.on("isVisibleChanged", () => {
1230
- v("back-button", { isVisible: o.isVisible });
1231
- }), o;
1192
+ function Q(s) {
1193
+ return `telegram-mini-apps-${s}`;
1194
+ }
1195
+ function V(s, t) {
1196
+ sessionStorage.setItem(Q(s), JSON.stringify(t));
1197
+ }
1198
+ function S(s) {
1199
+ const t = sessionStorage.getItem(Q(s));
1200
+ return t ? JSON.parse(t) : null;
1232
1201
  }
1233
- function Wt(s) {
1234
- const { isConfirmationNeeded: t = !1 } = k("closing-behavior") || {}, e = new Ct(t, s);
1235
- return e.on("isConfirmationNeededChanged", () => v("closing-behavior", {
1236
- isConfirmationNeeded: e.isConfirmationNeeded
1237
- })), e;
1202
+ function Rt(s, t, e) {
1203
+ const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, r = new Ct(o, t, e);
1204
+ return r.on("isVisibleChanged", () => {
1205
+ V("back-button", { isVisible: r.isVisible });
1206
+ }), r;
1238
1207
  }
1239
- function Lt(s, t, e) {
1208
+ function Dt(s, t) {
1209
+ const { isConfirmationNeeded: e = !1 } = s ? S("closing-behavior") || {} : {}, o = new vt(e, t);
1210
+ return o.on("isConfirmationNeededChanged", () => V("closing-behavior", {
1211
+ isConfirmationNeeded: o.isConfirmationNeeded
1212
+ })), o;
1213
+ }
1214
+ function Lt(s, t, e, o) {
1240
1215
  const {
1241
- backgroundColor: o = s,
1242
- isEnabled: r = !1,
1243
- isVisible: n = !1,
1216
+ backgroundColor: r = t,
1217
+ isEnabled: n = !1,
1218
+ isVisible: a = !1,
1244
1219
  isProgressVisible: c = !1,
1245
- textColor: a = t,
1220
+ textColor: u = e,
1246
1221
  text: p = ""
1247
- } = k("main-button") || {}, h = new xt(
1248
- o,
1222
+ } = s ? S("main-button") || {} : {}, h = new Vt(
1249
1223
  r,
1250
1224
  n,
1225
+ a,
1251
1226
  c,
1252
1227
  p,
1253
- a,
1254
- e
1255
- ), _ = () => v("main-button", {
1228
+ u,
1229
+ o
1230
+ ), l = () => V("main-button", {
1256
1231
  backgroundColor: h.backgroundColor,
1257
1232
  isEnabled: h.isEnabled,
1258
1233
  isVisible: h.isVisible,
@@ -1260,69 +1235,78 @@ function Lt(s, t, e) {
1260
1235
  text: h.text,
1261
1236
  textColor: h.textColor
1262
1237
  });
1263
- return h.on("backgroundColorChanged", _), h.on("isEnabledChanged", _), h.on("isVisibleChanged", _), h.on("isProgressVisibleChanged", _), h.on("textColorChanged", _), h.on("textChanged", _), h;
1264
- }
1265
- class H extends Error {
1266
- constructor(t, e) {
1267
- super(`Method "${t}" is not supported in the Web Apps version ${e}.`), Object.setPrototypeOf(this, H.prototype);
1268
- }
1269
- }
1270
- class I extends Error {
1271
- constructor(t, e, o) {
1272
- super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`), Object.setPrototypeOf(this, I.prototype);
1273
- }
1238
+ 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;
1274
1239
  }
1275
1240
  function Nt(s, t) {
1276
1241
  return s ? (e, o) => {
1277
1242
  if (!C(e, t))
1278
- throw new H(e, t);
1279
- return bt(o) && pt(e, o).forEach((r) => {
1243
+ throw new $(e, t);
1244
+ return ft(o) && ht(e, o).forEach((r) => {
1280
1245
  if (!C(e, r, t))
1281
1246
  throw new I(e, r, t);
1282
- }), l(e, o);
1283
- } : l;
1247
+ }), g(e, o);
1248
+ } : g;
1284
1249
  }
1285
1250
  function zt() {
1286
1251
  let s = 0;
1287
1252
  return () => (s += 1, s.toString());
1288
1253
  }
1289
1254
  function Mt(s) {
1290
- const t = new q(s);
1291
- return q.sync(t), t;
1255
+ const t = new P(s);
1256
+ return P.sync(t), t;
1292
1257
  }
1293
- async function Ut(s, t) {
1258
+ async function Wt(s, t, e) {
1294
1259
  const {
1295
- height: e = window.innerHeight,
1296
- stableHeight: o = window.innerHeight,
1297
- width: r = window.innerWidth,
1298
- isExpanded: n = !1
1299
- } = k("viewport") || {}, a = s === "macos" || s === "web" ? (() => {
1300
- const h = new V(e, r, o, n, t);
1301
- return V.sync(h), h;
1302
- })() : await V.synced({ postEvent: t }), p = () => v("viewport", {
1303
- height: a.height,
1304
- isExpanded: a.isExpanded,
1305
- stableHeight: a.stableHeight,
1306
- width: a.width
1260
+ height: o = window.innerHeight,
1261
+ stableHeight: r = window.innerHeight,
1262
+ width: n = window.innerWidth,
1263
+ isExpanded: a = !1
1264
+ } = s ? S("viewport") || {} : {}, u = t === "macos" || t === "web" ? (() => {
1265
+ const h = new k(o, n, r, a, e);
1266
+ return k.sync(h), h;
1267
+ })() : await k.synced({ postEvent: e }), p = () => V("viewport", {
1268
+ height: u.height,
1269
+ isExpanded: u.isExpanded,
1270
+ stableHeight: u.stableHeight,
1271
+ width: u.width
1307
1272
  });
1308
- return a.on("heightChanged", p), a.on("isExpandedChanged", p), a.on("stableHeightChanged", p), a.on("widthChanged", p), a;
1273
+ return u.on("heightChanged", p), u.on("isExpandedChanged", p), u.on("stableHeightChanged", p), u.on("widthChanged", p), u;
1309
1274
  }
1310
- function Kt(s, t, e, o, r) {
1275
+ function Ut(s, t, e, o, r, n) {
1311
1276
  const {
1312
- backgroundColor: n = s,
1277
+ backgroundColor: a = t,
1313
1278
  headerColor: c = "bg_color"
1314
- } = k("web-app") || {}, a = new Ot(
1279
+ } = s ? S("web-app") || {} : {}, u = new Ot(
1315
1280
  c,
1316
- n,
1317
- t,
1281
+ a,
1318
1282
  e,
1319
1283
  o,
1320
- r
1321
- ), p = () => v("web-app", {
1322
- backgroundColor: a.backgroundColor,
1323
- headerColor: a.headerColor
1284
+ r,
1285
+ n
1286
+ ), p = () => V("web-app", {
1287
+ backgroundColor: u.backgroundColor,
1288
+ headerColor: u.headerColor
1324
1289
  });
1325
- return a.on("backgroundColorChanged", p), a.on("headerColorChanged", p), a;
1290
+ return u.on("backgroundColorChanged", p), u.on("headerColorChanged", p), u;
1291
+ }
1292
+ function Z() {
1293
+ let s;
1294
+ try {
1295
+ return U(window.location.hash.slice(1));
1296
+ } catch (e) {
1297
+ s = e;
1298
+ }
1299
+ const t = F();
1300
+ if (t)
1301
+ return t;
1302
+ throw new Error("Unable to extract launch params", { cause: s });
1303
+ }
1304
+ function Ft() {
1305
+ return window.performance.getEntriesByType("navigation").some((s) => s.type === "reload");
1306
+ }
1307
+ function Kt(s, t) {
1308
+ var e, o;
1309
+ return s ? ((e = s.initData) == null ? void 0 : e.hash) === ((o = t.initData) == null ? void 0 : o.hash) : !1;
1326
1310
  }
1327
1311
  async function jt(s = {}) {
1328
1312
  const {
@@ -1331,82 +1315,88 @@ async function jt(s = {}) {
1331
1315
  acceptScrollbarStyle: o = !0,
1332
1316
  acceptCustomStyles: r = o,
1333
1317
  targetOrigin: n,
1334
- debug: c = !1,
1335
- launchParams: a
1318
+ debug: a = !1,
1319
+ launchParams: c = Z()
1336
1320
  } = s;
1337
- c && ut(c), typeof n == "string" && lt(n);
1338
- let p;
1339
- a ? p = a instanceof URLSearchParams || typeof a == "string" ? R(a) : a : p = Q();
1340
- const {
1341
- initData: h,
1342
- initDataRaw: _,
1321
+ a && ut(a), typeof n == "string" && pt(n);
1322
+ const u = F(), p = c instanceof URLSearchParams || typeof c == "string" ? U(c) : c;
1323
+ ct(p);
1324
+ const h = Ft() || Kt(u, p), {
1325
+ initData: l,
1326
+ initDataRaw: X,
1343
1327
  version: m,
1344
- platform: D,
1345
- themeParams: W
1328
+ platform: A,
1329
+ themeParams: H
1346
1330
  } = p, {
1347
- backgroundColor: X = "#ffffff",
1348
- buttonColor: Y = "#000000",
1349
- buttonTextColor: tt = "#ffffff"
1350
- } = W, L = zt(), u = Nt(t, m), O = Mt(W), N = Kt(X, m, D, L, u), {
1351
- themeParams: et,
1352
- viewport: st,
1353
- webApp: ot
1354
- } = It(e);
1355
- ot && Rt(N, O), et && $t(O);
1356
- const z = await Ut(D, u);
1357
- if (st && Ht(z), r && dt()) {
1358
- const E = document.createElement("style");
1359
- E.id = "telegram-custom-styles", document.head.appendChild(E), S("set_custom_style", (A) => {
1360
- E.innerHTML = A;
1361
- }), u("iframe_ready");
1362
- }
1363
- const B = {
1364
- backButton: Dt(m, u),
1365
- closingBehavior: Wt(u),
1366
- cloudStorage: new vt(m, L, u),
1367
- haptic: new kt(m, u),
1368
- mainButton: Lt(Y, tt, u),
1369
- popup: new Vt(m, u),
1370
- postEvent: u,
1371
- qrScanner: new St(m, u),
1372
- themeParams: O,
1373
- viewport: z,
1374
- webApp: N
1331
+ backgroundColor: Y = "#ffffff",
1332
+ buttonColor: tt = "#000000",
1333
+ buttonTextColor: et = "#ffffff"
1334
+ } = H, R = zt(), d = Nt(t, m), q = Mt(H), D = Ut(
1335
+ h,
1336
+ Y,
1337
+ m,
1338
+ A,
1339
+ R,
1340
+ d
1341
+ ), {
1342
+ themeParams: st,
1343
+ viewport: ot,
1344
+ webApp: rt
1345
+ } = Ht(e);
1346
+ rt && It(D, q), st && $t(q);
1347
+ const L = await Wt(h, A, d);
1348
+ if (ot && At(L), r && lt()) {
1349
+ const y = document.createElement("style");
1350
+ y.id = "telegram-custom-styles", document.head.appendChild(y), x("set_custom_style", (B) => {
1351
+ y.innerHTML = B;
1352
+ }), d("iframe_ready");
1353
+ }
1354
+ const O = {
1355
+ backButton: Rt(h, m, d),
1356
+ closingBehavior: Dt(h, d),
1357
+ cloudStorage: new Et(m, R, d),
1358
+ haptic: new kt(m, d),
1359
+ mainButton: Lt(h, tt, et, d),
1360
+ popup: new Pt(m, d),
1361
+ postEvent: d,
1362
+ qrScanner: new qt(m, d),
1363
+ themeParams: q,
1364
+ viewport: L,
1365
+ webApp: D
1375
1366
  };
1376
- if (h !== void 0) {
1377
- const { authDate: E, hash: A, ...rt } = h;
1378
- B.initData = new Et(E, A, rt), B.initDataRaw = _;
1367
+ if (l !== void 0) {
1368
+ const { authDate: y, hash: B, ...nt } = l;
1369
+ O.initData = new xt(y, B, nt), O.initDataRaw = X;
1379
1370
  }
1380
- return B;
1371
+ return O;
1381
1372
  }
1382
- function te(s = {}) {
1383
- return _t(jt(s), s.timeout || 1e3);
1373
+ function se(s = {}) {
1374
+ return wt(jt(s), s.timeout || 1e3);
1384
1375
  }
1385
- function ee() {
1376
+ function oe() {
1386
1377
  try {
1387
- return Q(), !0;
1378
+ return Z(), !0;
1388
1379
  } catch {
1389
1380
  return !1;
1390
1381
  }
1391
1382
  }
1392
1383
  export {
1393
- wt as BackButton,
1394
- Ct as ClosingBehaviour,
1395
- vt as CloudStorage,
1384
+ Ct as BackButton,
1385
+ vt as ClosingBehaviour,
1386
+ Et as CloudStorage,
1396
1387
  kt as HapticFeedback,
1397
- Et as InitData,
1398
- xt as MainButton,
1399
- H as MethodNotSupportedError,
1400
- Vt as Popup,
1401
- St as QRScanner,
1402
- q as ThemeParams,
1403
- V as Viewport,
1388
+ xt as InitData,
1389
+ Vt as MainButton,
1390
+ $ as MethodNotSupportedError,
1391
+ I as ParameterUnsupportedError,
1392
+ Pt as Popup,
1393
+ qt as QRScanner,
1394
+ P as ThemeParams,
1395
+ k as Viewport,
1404
1396
  Ot as WebApp,
1405
1397
  T as formatURL,
1406
- te as init,
1407
- ee as isTWA,
1408
- R as parseLaunchParams,
1409
- $ as parseThemeParams,
1410
- Q as retrieveLaunchParams
1398
+ se as init,
1399
+ oe as isTWA,
1400
+ Z as retrieveLaunchParams
1411
1401
  };
1412
1402
  //# sourceMappingURL=index.js.map