@tma.js/sdk 0.11.6 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) 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 +290 -304
  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 +7 -4
  23. package/src/components/MainButton/MainButton.ts +1 -1
  24. package/src/components/ThemeParams/ThemeParams.ts +3 -3
  25. package/src/components/ThemeParams/types.ts +5 -5
  26. package/src/components/WebApp/WebApp.ts +2 -1
  27. package/src/index.ts +2 -3
  28. package/src/init/creators/createBackButton.ts +7 -2
  29. package/src/init/creators/createClosingBehavior.ts +6 -2
  30. package/src/init/creators/createMainButton.ts +3 -1
  31. package/src/init/creators/{createSyncedThemeParams.ts → createThemeParams.ts} +3 -3
  32. package/src/init/creators/createViewport.ts +8 -4
  33. package/src/init/creators/createWebApp.ts +5 -2
  34. package/src/init/creators/index.ts +1 -1
  35. package/src/init/init.ts +67 -20
  36. package/src/init/types.ts +5 -5
  37. package/src/launch-params.ts +14 -55
  38. package/src/storage.ts +1 -2
  39. package/src/types.ts +0 -15
  40. package/dist/dts/init/creators/createSyncedThemeParams.d.ts +0 -7
  41. package/dist/dts/theme-params.d.ts +0 -18
  42. 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 d, 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 = d) {
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 = d) {
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 = d) {
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 = d) {
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,25 @@ 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
+ user: a = null,
262
+ queryId: c = null,
263
+ receiver: h = null,
264
+ startParam: p = null
264
265
  } = o;
265
- this.state = new b({
266
+ this.state = new f({
266
267
  authDate: t,
267
268
  canSendAfter: n,
268
269
  chat: r,
269
- user: c,
270
- queryId: a,
271
- receiver: p,
272
- startParam: h,
270
+ user: a,
271
+ queryId: c,
272
+ receiver: h,
273
+ startParam: p,
273
274
  hash: e
274
275
  });
275
276
  }
@@ -334,9 +335,9 @@ class Et {
334
335
  return this.state.get("user");
335
336
  }
336
337
  }
337
- class xt {
338
- constructor(t, e, o, r, n, c, a = l) {
339
- i(this, "ee", new f());
338
+ class Vt {
339
+ constructor(t, e, o, r, n, a, c = d) {
340
+ i(this, "ee", new w());
340
341
  i(this, "state");
341
342
  /**
342
343
  * Adds new event listener.
@@ -348,7 +349,7 @@ class xt {
348
349
  */
349
350
  i(this, "on", (t, e) => {
350
351
  if (t === "click")
351
- return S("main_button_pressed", e);
352
+ return x("main_button_pressed", e);
352
353
  this.ee.on(t, e);
353
354
  });
354
355
  /**
@@ -358,16 +359,16 @@ class xt {
358
359
  */
359
360
  i(this, "off", (t, e) => {
360
361
  if (t === "click")
361
- return F("main_button_pressed", e);
362
+ return K("main_button_pressed", e);
362
363
  this.ee.off(t, e);
363
364
  });
364
- this.postEvent = a, this.state = new b({
365
+ this.postEvent = c, this.state = new f({
365
366
  backgroundColor: t,
366
367
  isEnabled: e,
367
368
  isVisible: o,
368
369
  isProgressVisible: r,
369
370
  text: n,
370
- textColor: c
371
+ textColor: a
371
372
  }, this.ee);
372
373
  }
373
374
  set isEnabled(t) {
@@ -503,7 +504,7 @@ class xt {
503
504
  return this.state.set("backgroundColor", t), this.commit(), this;
504
505
  }
505
506
  }
506
- function Pt(s) {
507
+ function St(s) {
507
508
  const t = s.message.trim(), e = (s.title || "").trim(), o = s.buttons || [];
508
509
  let r;
509
510
  if (e.length > 64)
@@ -513,23 +514,23 @@ function Pt(s) {
513
514
  if (o.length > 3)
514
515
  throw new Error(`Buttons have incorrect size: ${o.length}`);
515
516
  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}`);
517
+ const { id: a = "" } = n;
518
+ if (a.length > 64)
519
+ throw new Error(`Button ID has incorrect size: ${a}`);
519
520
  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}`);
521
+ const c = n.text.trim();
522
+ if (c.length === 0 || c.length > 64) {
523
+ const h = n.type || "default";
524
+ throw new Error(`Button text with type "${h}" has incorrect size: ${n.text.length}`);
524
525
  }
525
- return { ...n, text: a, id: c };
526
+ return { ...n, text: c, id: a };
526
527
  }
527
- return { ...n, id: c };
528
+ return { ...n, id: a };
528
529
  }), { title: e, message: t, buttons: r };
529
530
  }
530
- class Vt {
531
- constructor(t, e = l) {
532
- i(this, "ee", new f());
531
+ class Pt {
532
+ constructor(t, e = d) {
533
+ i(this, "ee", new w());
533
534
  i(this, "state");
534
535
  /**
535
536
  * Adds new event listener.
@@ -543,7 +544,7 @@ class Vt {
543
544
  * Checks if specified method is supported by current component.
544
545
  */
545
546
  i(this, "supports");
546
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_popup" });
547
+ this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, { open: "web_app_open_popup" });
547
548
  }
548
549
  /**
549
550
  * Shows whether popup is currently opened.
@@ -569,9 +570,9 @@ class Vt {
569
570
  throw new Error("Popup is already opened.");
570
571
  this.state.set("isOpened", !0);
571
572
  try {
572
- const { button_id: e = null } = await g(
573
+ const { button_id: e = null } = await _(
573
574
  "web_app_open_popup",
574
- Pt(t),
575
+ St(t),
575
576
  "popup_closed",
576
577
  { postEvent: this.postEvent }
577
578
  );
@@ -581,9 +582,9 @@ class Vt {
581
582
  }
582
583
  }
583
584
  }
584
- class St {
585
- constructor(t, e = l) {
586
- i(this, "ee", new f());
585
+ class qt {
586
+ constructor(t, e = d) {
587
+ i(this, "ee", new w());
587
588
  i(this, "state");
588
589
  /**
589
590
  * Adds new event listener.
@@ -597,7 +598,7 @@ class St {
597
598
  * Checks if specified method is supported by current component.
598
599
  */
599
600
  i(this, "supports");
600
- this.postEvent = e, this.state = new b({ isOpened: !1 }, this.ee), this.supports = y(t, {
601
+ this.postEvent = e, this.state = new f({ isOpened: !1 }, this.ee), this.supports = v(t, {
601
602
  close: "web_app_close_scan_qr_popup",
602
603
  open: "web_app_open_scan_qr_popup"
603
604
  });
@@ -628,7 +629,7 @@ class St {
628
629
  throw new Error("QR scanner is already opened.");
629
630
  this.isOpened = !0;
630
631
  try {
631
- const e = await g(
632
+ const e = await _(
632
633
  "web_app_open_scan_qr_popup",
633
634
  { text: t },
634
635
  ["qr_text_received", "scan_qr_popup_closed"],
@@ -640,27 +641,15 @@ class St {
640
641
  }
641
642
  }
642
643
  }
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) {
644
+ function M(s) {
656
645
  const {
657
646
  backgroundColor: t = null,
658
647
  buttonTextColor: e = null,
659
648
  buttonColor: o = null,
660
649
  hintColor: r = null,
661
650
  linkColor: n = null,
662
- textColor: c = null,
663
- secondaryBackgroundColor: a = null
651
+ textColor: a = null,
652
+ secondaryBackgroundColor: c = null
664
653
  } = s;
665
654
  return {
666
655
  backgroundColor: t,
@@ -668,13 +657,13 @@ function U(s) {
668
657
  buttonColor: o,
669
658
  hintColor: r,
670
659
  linkColor: n,
671
- textColor: c,
672
- secondaryBackgroundColor: a
660
+ textColor: a,
661
+ secondaryBackgroundColor: c
673
662
  };
674
663
  }
675
- class q {
664
+ class P {
676
665
  constructor(t) {
677
- i(this, "ee", new f());
666
+ i(this, "ee", new w());
678
667
  i(this, "state");
679
668
  /**
680
669
  * Adds new event listener.
@@ -684,7 +673,7 @@ class q {
684
673
  * Removes event listener.
685
674
  */
686
675
  i(this, "off", this.ee.off.bind(this.ee));
687
- this.state = new b(U(t), this.ee);
676
+ this.state = new f(M(t), this.ee);
688
677
  }
689
678
  /**
690
679
  * Requests fresh information about current theme.
@@ -693,11 +682,11 @@ class q {
693
682
  * @param options - method options.
694
683
  */
695
684
  static async request(t = {}) {
696
- const { timeout: e = 1e3, ...o } = t, r = await g("web_app_request_theme", "theme_changed", {
685
+ const { timeout: e = 1e3, ...o } = t, r = await _("web_app_request_theme", "theme_changed", {
697
686
  ...o,
698
687
  timeout: e
699
688
  });
700
- return $(r.theme_params);
689
+ return N(r.theme_params);
701
690
  }
702
691
  /**
703
692
  * Synchronizes specified instance of ThemeParams with the actual value in the native
@@ -705,8 +694,8 @@ class q {
705
694
  * @param themeParams - ThemeParams instance.
706
695
  */
707
696
  static sync(t) {
708
- S("theme_changed", (e) => {
709
- t.state.set(U($(e.theme_params)));
697
+ x("theme_changed", (e) => {
698
+ t.state.set(M(N(e.theme_params)));
710
699
  });
711
700
  }
712
701
  /**
@@ -715,7 +704,7 @@ class q {
715
704
  * @param options - method options.
716
705
  */
717
706
  static async synced(t) {
718
- const e = await this.request(t), o = new q(e);
707
+ const e = await this.request(t), o = new P(e);
719
708
  return this.sync(o), o;
720
709
  }
721
710
  /**
@@ -768,12 +757,12 @@ class q {
768
757
  return this.state.get("textColor");
769
758
  }
770
759
  }
771
- function x(s) {
760
+ function E(s) {
772
761
  return s < 0 ? 0 : s;
773
762
  }
774
- class V {
775
- constructor(t, e, o, r, n = l) {
776
- i(this, "ee", new f());
763
+ class k {
764
+ constructor(t, e, o, r, n = d) {
765
+ i(this, "ee", new w());
777
766
  i(this, "state");
778
767
  /**
779
768
  * Adds new event listener.
@@ -783,11 +772,11 @@ class V {
783
772
  * Removes event listener.
784
773
  */
785
774
  i(this, "off", this.ee.off.bind(this.ee));
786
- this.postEvent = n, this.state = new b({
787
- height: x(t),
775
+ this.postEvent = n, this.state = new f({
776
+ height: E(t),
788
777
  isExpanded: r,
789
- stableHeight: x(o),
790
- width: x(e)
778
+ stableHeight: E(o),
779
+ width: E(e)
791
780
  }, this.ee);
792
781
  }
793
782
  /**
@@ -801,12 +790,12 @@ class V {
801
790
  const { timeout: e = 1e3, ...o } = t, {
802
791
  is_expanded: r,
803
792
  is_state_stable: n,
804
- ...c
805
- } = await g("web_app_request_viewport", "viewport_changed", {
793
+ ...a
794
+ } = await _("web_app_request_viewport", "viewport_changed", {
806
795
  ...o,
807
796
  timeout: e
808
797
  });
809
- return { ...c, isExpanded: r, isStateStable: n };
798
+ return { ...a, isExpanded: r, isStateStable: n };
810
799
  }
811
800
  /**
812
801
  * Synchronizes specified instance of Viewport with the actual value in the native
@@ -814,18 +803,18 @@ class V {
814
803
  * @param viewport - Viewport instance.
815
804
  */
816
805
  static sync(t) {
817
- S("viewport_changed", (e) => {
806
+ x("viewport_changed", (e) => {
818
807
  const {
819
808
  height: o,
820
809
  width: r,
821
810
  is_expanded: n,
822
- is_state_stable: c
823
- } = e, a = x(o);
811
+ is_state_stable: a
812
+ } = e, c = E(o);
824
813
  t.state.set({
825
- height: a,
814
+ height: c,
826
815
  isExpanded: n,
827
- width: x(r),
828
- stableHeight: c ? a : void 0
816
+ width: E(r),
817
+ stableHeight: a ? c : void 0
829
818
  });
830
819
  });
831
820
  }
@@ -835,7 +824,7 @@ class V {
835
824
  * @param options - method options.
836
825
  */
837
826
  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);
827
+ const { height: e, isExpanded: o, width: r } = await this.request(t), n = new k(e, r, e, o, t.postEvent);
839
828
  return this.sync(n), n;
840
829
  }
841
830
  /**
@@ -923,8 +912,8 @@ function T(s) {
923
912
  return t.href;
924
913
  }
925
914
  class Ot {
926
- constructor(t, e, o, r, n, c = l) {
927
- i(this, "ee", new f());
915
+ constructor(t, e, o, r, n, a = d) {
916
+ i(this, "ee", new w());
928
917
  i(this, "state");
929
918
  /**
930
919
  * Adds new event listener.
@@ -942,10 +931,10 @@ class Ot {
942
931
  * Checks if specified method parameter is supported by current component.
943
932
  */
944
933
  i(this, "supportsParam");
945
- this.currentVersion = o, this.currentPlatform = r, this.createRequestId = n, this.postEvent = c, this.state = new b({
934
+ this.currentVersion = o, this.currentPlatform = r, this.createRequestId = n, this.postEvent = a, this.state = new f({
946
935
  backgroundColor: e,
947
936
  headerColor: t
948
- }, this.ee), this.supports = y(o, {
937
+ }, this.ee), this.supports = v(o, {
949
938
  openInvoice: "web_app_open_invoice",
950
939
  readTextFromClipboard: "web_app_read_text_from_clipboard",
951
940
  setHeaderColor: "web_app_set_header_color",
@@ -988,7 +977,7 @@ class Ot {
988
977
  * @param version - compared version.
989
978
  */
990
979
  isVersionAtLeast(t) {
991
- return gt(t, this.version) >= 0;
980
+ return _t(t, this.version) >= 0;
992
981
  }
993
982
  /**
994
983
  * Opens a link in an external browser. The Web App will not be closed.
@@ -1039,9 +1028,9 @@ class Ot {
1039
1028
  if (r === null)
1040
1029
  throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');
1041
1030
  const [, , n] = r;
1042
- return (await g("web_app_open_invoice", { slug: n }, "invoice_closed", {
1031
+ return (await _("web_app_open_invoice", { slug: n }, "invoice_closed", {
1043
1032
  postEvent: this.postEvent,
1044
- capture: ({ slug: a }) => n === a
1033
+ capture: ({ slug: c }) => n === c
1045
1034
  })).status;
1046
1035
  }
1047
1036
  /**
@@ -1070,7 +1059,7 @@ class Ot {
1070
1059
  * - Access to clipboard is not allowed
1071
1060
  */
1072
1061
  async readTextFromClipboard() {
1073
- const { data: t = null } = await g(
1062
+ const { data: t = null } = await _(
1074
1063
  "web_app_read_text_from_clipboard",
1075
1064
  { req_id: this.createRequestId() },
1076
1065
  "clipboard_text_received",
@@ -1082,7 +1071,7 @@ class Ot {
1082
1071
  * Requests current user phone access.
1083
1072
  */
1084
1073
  async requestPhoneAccess() {
1085
- const { status: t } = await g("web_app_request_phone", "phone_requested", {
1074
+ const { status: t } = await _("web_app_request_phone", "phone_requested", {
1086
1075
  postEvent: this.postEvent
1087
1076
  });
1088
1077
  return t;
@@ -1091,7 +1080,7 @@ class Ot {
1091
1080
  * Requests write message access to current user.
1092
1081
  */
1093
1082
  async requestWriteAccess() {
1094
- const { status: t } = await g("web_app_request_write_access", "write_access_requested", {
1083
+ const { status: t } = await _("web_app_request_write_access", "write_access_requested", {
1095
1084
  postEvent: this.postEvent
1096
1085
  });
1097
1086
  return t;
@@ -1121,7 +1110,7 @@ class Ot {
1121
1110
  * @param color - color key or RGB color.
1122
1111
  */
1123
1112
  setHeaderColor(t) {
1124
- this.postEvent("web_app_set_header_color", ft(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1113
+ this.postEvent("web_app_set_header_color", bt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1125
1114
  }
1126
1115
  /**
1127
1116
  * Updates current application background color.
@@ -1142,187 +1131,178 @@ class Ot {
1142
1131
  return this.currentVersion;
1143
1132
  }
1144
1133
  }
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);
1134
+ class $ extends Error {
1135
+ constructor(t, e) {
1136
+ super(`Method "${t}" is not supported in the Web Apps version ${e}.`), Object.setPrototypeOf(this, $.prototype);
1137
+ }
1164
1138
  }
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");
1139
+ class H extends Error {
1140
+ constructor(t, e, o) {
1141
+ super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`), Object.setPrototypeOf(this, H.prototype);
1172
1142
  }
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
1143
  }
1183
- function Z(s, t) {
1144
+ function G(s, t) {
1184
1145
  document.documentElement.style.setProperty(s, t);
1185
1146
  }
1186
- function d(s, t) {
1187
- t !== null && Z(s, t);
1147
+ function b(s, t) {
1148
+ t !== null && G(s, t);
1188
1149
  }
1189
- function K(s, t) {
1190
- Z(s, `${t}px`);
1150
+ function W(s, t) {
1151
+ G(s, `${t}px`);
1191
1152
  }
1192
- function At(s) {
1153
+ function Bt(s) {
1193
1154
  const {
1194
1155
  backgroundColor: t,
1195
1156
  buttonTextColor: e,
1196
1157
  secondaryBackgroundColor: o,
1197
1158
  hintColor: r,
1198
1159
  buttonColor: n,
1199
- linkColor: c,
1200
- textColor: a
1160
+ linkColor: a,
1161
+ textColor: c
1201
1162
  } = 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);
1163
+ 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
1164
  }
1204
1165
  function Tt(s, t) {
1205
1166
  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);
1167
+ b("--tg-bg-color", r), b("--tg-header-color", n === "bg_color" ? e : o);
1207
1168
  }
1208
1169
  function $t(s) {
1209
- const t = () => At(s);
1170
+ const t = () => Bt(s);
1210
1171
  s.on("changed", t), t();
1211
1172
  }
1212
- function Rt(s, t) {
1173
+ function Ht(s, t) {
1213
1174
  const e = () => Tt(s, t);
1214
1175
  t.on("changed", e), s.on("backgroundColorChanged", e), s.on("headerColorChanged", e), e();
1215
1176
  }
1216
- function Ht(s) {
1177
+ function It(s) {
1217
1178
  const t = () => {
1218
- K("--tg-viewport-height", s.height);
1179
+ W("--tg-viewport-height", s.height);
1219
1180
  }, e = () => {
1220
- K("--tg-viewport-stable-height", s.stableHeight);
1181
+ W("--tg-viewport-stable-height", s.stableHeight);
1221
1182
  };
1222
1183
  s.on("heightChanged", t), s.on("stableHeightChanged", e), t(), e();
1223
1184
  }
1224
- function It(s) {
1185
+ function Rt(s) {
1225
1186
  return typeof s == "boolean" ? s ? { themeParams: !0, viewport: !0, webApp: !0 } : {} : s;
1226
1187
  }
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;
1188
+ function Q(s) {
1189
+ return `telegram-mini-apps-${s}`;
1232
1190
  }
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;
1191
+ function V(s, t) {
1192
+ sessionStorage.setItem(Q(s), JSON.stringify(t));
1238
1193
  }
1239
- function Lt(s, t, e) {
1194
+ function S(s) {
1195
+ const t = sessionStorage.getItem(Q(s));
1196
+ return t ? JSON.parse(t) : null;
1197
+ }
1198
+ function At(s, t, e) {
1199
+ const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, r = new Ct(o, t, e);
1200
+ return r.on("isVisibleChanged", () => {
1201
+ V("back-button", { isVisible: r.isVisible });
1202
+ }), r;
1203
+ }
1204
+ function Dt(s, t) {
1205
+ const { isConfirmationNeeded: e = !1 } = s ? S("closing-behavior") || {} : {}, o = new vt(e, t);
1206
+ return o.on("isConfirmationNeededChanged", () => V("closing-behavior", {
1207
+ isConfirmationNeeded: o.isConfirmationNeeded
1208
+ })), o;
1209
+ }
1210
+ function Lt(s, t, e, o) {
1240
1211
  const {
1241
- backgroundColor: o = s,
1242
- isEnabled: r = !1,
1243
- isVisible: n = !1,
1212
+ backgroundColor: r = t,
1213
+ isEnabled: n = !1,
1214
+ isVisible: a = !1,
1244
1215
  isProgressVisible: c = !1,
1245
- textColor: a = t,
1216
+ textColor: h = e,
1246
1217
  text: p = ""
1247
- } = k("main-button") || {}, h = new xt(
1248
- o,
1218
+ } = s ? S("main-button") || {} : {}, u = new Vt(
1249
1219
  r,
1250
1220
  n,
1221
+ a,
1251
1222
  c,
1252
1223
  p,
1253
- a,
1254
- e
1255
- ), _ = () => v("main-button", {
1256
- backgroundColor: h.backgroundColor,
1257
- isEnabled: h.isEnabled,
1258
- isVisible: h.isVisible,
1259
- isProgressVisible: h.isProgressVisible,
1260
- text: h.text,
1261
- textColor: h.textColor
1224
+ h,
1225
+ o
1226
+ ), g = () => V("main-button", {
1227
+ backgroundColor: u.backgroundColor,
1228
+ isEnabled: u.isEnabled,
1229
+ isVisible: u.isVisible,
1230
+ isProgressVisible: u.isProgressVisible,
1231
+ text: u.text,
1232
+ textColor: u.textColor
1262
1233
  });
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
- }
1234
+ return u.on("backgroundColorChanged", g), u.on("isEnabledChanged", g), u.on("isVisibleChanged", g), u.on("isProgressVisibleChanged", g), u.on("textColorChanged", g), u.on("textChanged", g), u;
1274
1235
  }
1275
1236
  function Nt(s, t) {
1276
1237
  return s ? (e, o) => {
1277
1238
  if (!C(e, t))
1278
- throw new H(e, t);
1279
- return bt(o) && pt(e, o).forEach((r) => {
1239
+ throw new $(e, t);
1240
+ return ft(o) && ht(e, o).forEach((r) => {
1280
1241
  if (!C(e, r, t))
1281
- throw new I(e, r, t);
1282
- }), l(e, o);
1283
- } : l;
1242
+ throw new H(e, r, t);
1243
+ }), d(e, o);
1244
+ } : d;
1284
1245
  }
1285
1246
  function zt() {
1286
1247
  let s = 0;
1287
1248
  return () => (s += 1, s.toString());
1288
1249
  }
1289
1250
  function Mt(s) {
1290
- const t = new q(s);
1291
- return q.sync(t), t;
1251
+ const t = new P(s);
1252
+ return P.sync(t), t;
1292
1253
  }
1293
- async function Ut(s, t) {
1254
+ async function Wt(s, t, e) {
1294
1255
  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
1256
+ height: o = window.innerHeight,
1257
+ stableHeight: r = window.innerHeight,
1258
+ width: n = window.innerWidth,
1259
+ isExpanded: a = !1
1260
+ } = s ? S("viewport") || {} : {}, h = t === "macos" || t === "web" ? (() => {
1261
+ const u = new k(o, n, r, a, e);
1262
+ return k.sync(u), u;
1263
+ })() : await k.synced({ postEvent: e }), p = () => V("viewport", {
1264
+ height: h.height,
1265
+ isExpanded: h.isExpanded,
1266
+ stableHeight: h.stableHeight,
1267
+ width: h.width
1307
1268
  });
1308
- return a.on("heightChanged", p), a.on("isExpandedChanged", p), a.on("stableHeightChanged", p), a.on("widthChanged", p), a;
1269
+ return h.on("heightChanged", p), h.on("isExpandedChanged", p), h.on("stableHeightChanged", p), h.on("widthChanged", p), h;
1309
1270
  }
1310
- function Kt(s, t, e, o, r) {
1271
+ function Ut(s, t, e, o, r, n) {
1311
1272
  const {
1312
- backgroundColor: n = s,
1273
+ backgroundColor: a = t,
1313
1274
  headerColor: c = "bg_color"
1314
- } = k("web-app") || {}, a = new Ot(
1275
+ } = s ? S("web-app") || {} : {}, h = new Ot(
1315
1276
  c,
1316
- n,
1317
- t,
1277
+ a,
1318
1278
  e,
1319
1279
  o,
1320
- r
1321
- ), p = () => v("web-app", {
1322
- backgroundColor: a.backgroundColor,
1323
- headerColor: a.headerColor
1280
+ r,
1281
+ n
1282
+ ), p = () => V("web-app", {
1283
+ backgroundColor: h.backgroundColor,
1284
+ headerColor: h.headerColor
1324
1285
  });
1325
- return a.on("backgroundColorChanged", p), a.on("headerColorChanged", p), a;
1286
+ return h.on("backgroundColorChanged", p), h.on("headerColorChanged", p), h;
1287
+ }
1288
+ function Z() {
1289
+ let s;
1290
+ try {
1291
+ return U(window.location.hash.slice(1));
1292
+ } catch (e) {
1293
+ s = e;
1294
+ }
1295
+ const t = F();
1296
+ if (t)
1297
+ return t;
1298
+ throw new Error("Unable to extract launch params", { cause: s });
1299
+ }
1300
+ function Ft() {
1301
+ return window.performance.getEntriesByType("navigation").some((s) => s.type === "reload");
1302
+ }
1303
+ function Kt(s, t) {
1304
+ var e, o;
1305
+ return s ? ((e = s.initData) == null ? void 0 : e.hash) === ((o = t.initData) == null ? void 0 : o.hash) : !1;
1326
1306
  }
1327
1307
  async function jt(s = {}) {
1328
1308
  const {
@@ -1331,82 +1311,88 @@ async function jt(s = {}) {
1331
1311
  acceptScrollbarStyle: o = !0,
1332
1312
  acceptCustomStyles: r = o,
1333
1313
  targetOrigin: n,
1334
- debug: c = !1,
1335
- launchParams: a
1314
+ debug: a = !1,
1315
+ launchParams: c = Z()
1336
1316
  } = 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: _,
1317
+ a && ut(a), typeof n == "string" && pt(n);
1318
+ const h = F(), p = c instanceof URLSearchParams || typeof c == "string" ? U(c) : c;
1319
+ ct(p);
1320
+ const u = Ft() || Kt(h, p), {
1321
+ initData: g,
1322
+ initDataRaw: X,
1343
1323
  version: m,
1344
- platform: D,
1345
- themeParams: W
1324
+ platform: I,
1325
+ themeParams: R
1346
1326
  } = 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
1327
+ backgroundColor: Y = "#ffffff",
1328
+ buttonColor: tt = "#000000",
1329
+ buttonTextColor: et = "#ffffff"
1330
+ } = R, A = zt(), l = Nt(t, m), q = Mt(R), D = Ut(
1331
+ u,
1332
+ Y,
1333
+ m,
1334
+ I,
1335
+ A,
1336
+ l
1337
+ ), {
1338
+ themeParams: st,
1339
+ viewport: ot,
1340
+ webApp: rt
1341
+ } = Rt(e);
1342
+ rt && Ht(D, q), st && $t(q);
1343
+ const L = await Wt(u, I, l);
1344
+ if (ot && It(L), r && lt()) {
1345
+ const y = document.createElement("style");
1346
+ y.id = "telegram-custom-styles", document.head.appendChild(y), x("set_custom_style", (B) => {
1347
+ y.innerHTML = B;
1348
+ }), l("iframe_ready");
1349
+ }
1350
+ const O = {
1351
+ backButton: At(u, m, l),
1352
+ closingBehavior: Dt(u, l),
1353
+ cloudStorage: new Et(m, A, l),
1354
+ haptic: new kt(m, l),
1355
+ mainButton: Lt(u, tt, et, l),
1356
+ popup: new Pt(m, l),
1357
+ postEvent: l,
1358
+ qrScanner: new qt(m, l),
1359
+ themeParams: q,
1360
+ viewport: L,
1361
+ webApp: D
1375
1362
  };
1376
- if (h !== void 0) {
1377
- const { authDate: E, hash: A, ...rt } = h;
1378
- B.initData = new Et(E, A, rt), B.initDataRaw = _;
1363
+ if (g !== void 0) {
1364
+ const { authDate: y, hash: B, ...nt } = g;
1365
+ O.initData = new xt(y, B, nt), O.initDataRaw = X;
1379
1366
  }
1380
- return B;
1367
+ return O;
1381
1368
  }
1382
- function te(s = {}) {
1383
- return _t(jt(s), s.timeout || 1e3);
1369
+ function se(s = {}) {
1370
+ return wt(jt(s), s.timeout || 1e3);
1384
1371
  }
1385
- function ee() {
1372
+ function oe() {
1386
1373
  try {
1387
- return Q(), !0;
1374
+ return Z(), !0;
1388
1375
  } catch {
1389
1376
  return !1;
1390
1377
  }
1391
1378
  }
1392
1379
  export {
1393
- wt as BackButton,
1394
- Ct as ClosingBehaviour,
1395
- vt as CloudStorage,
1380
+ Ct as BackButton,
1381
+ vt as ClosingBehaviour,
1382
+ Et as CloudStorage,
1396
1383
  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,
1384
+ xt as InitData,
1385
+ Vt as MainButton,
1386
+ $ as MethodNotSupportedError,
1387
+ H as ParameterUnsupportedError,
1388
+ Pt as Popup,
1389
+ qt as QRScanner,
1390
+ P as ThemeParams,
1391
+ k as Viewport,
1404
1392
  Ot as WebApp,
1405
1393
  T as formatURL,
1406
- te as init,
1407
- ee as isTWA,
1408
- R as parseLaunchParams,
1409
- $ as parseThemeParams,
1410
- Q as retrieveLaunchParams
1394
+ se as init,
1395
+ oe as isTWA,
1396
+ Z as retrieveLaunchParams
1411
1397
  };
1412
1398
  //# sourceMappingURL=index.js.map