@tma.js/sdk-react 2.2.5 → 2.2.6

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.js CHANGED
@@ -158,12 +158,12 @@ class W extends Error {
158
158
  super(s, { cause: n }), this.type = t, Object.setPrototypeOf(this, W.prototype);
159
159
  }
160
160
  }
161
- function m(e, t, s) {
161
+ function b(e, t, s) {
162
162
  return new W(e, t, s);
163
163
  }
164
164
  const _e = "ERR_METHOD_UNSUPPORTED", we = "ERR_METHOD_PARAMETER_UNSUPPORTED", ge = "ERR_UNKNOWN_ENV", fe = "ERR_INVOKE_CUSTOM_METHOD_RESPONSE", me = "ERR_TIMED_OUT", be = "ERR_UNEXPECTED_TYPE", St = "ERR_PARSE", ve = "ERR_NAVIGATION_LIST_EMPTY", ye = "ERR_NAVIGATION_CURSOR_INVALID", dn = "ERR_NAVIGATION_ITEM_INVALID", _n = "ERR_SSR_INIT", Ee = "ERR_INVALID_PATH_BASE";
165
165
  function T() {
166
- return m(be, "Value has unexpected type");
166
+ return b(be, "Value has unexpected type");
167
167
  }
168
168
  class G {
169
169
  constructor(t, s, n) {
@@ -180,7 +180,7 @@ class G {
180
180
  try {
181
181
  return this.parser(t);
182
182
  } catch (s) {
183
- throw m(
183
+ throw b(
184
184
  St,
185
185
  `Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
186
186
  s
@@ -221,7 +221,7 @@ function Tt(e, t) {
221
221
  const a = o(t(i));
222
222
  a !== void 0 && (s[n] = a);
223
223
  } catch (a) {
224
- throw m(St, `Unable to parse field "${n}"`, a);
224
+ throw b(St, `Unable to parse field "${n}"`, a);
225
225
  }
226
226
  }
227
227
  return s;
@@ -441,15 +441,21 @@ function Ie(e, t) {
441
441
  }
442
442
  return 0;
443
443
  }
444
- function v(e, t) {
444
+ function m(e, t) {
445
445
  return Ie(e, t) <= 0;
446
446
  }
447
447
  function C(e, t, s) {
448
448
  if (typeof s == "string") {
449
- if (e === "web_app_open_link" && t === "try_instant_view")
450
- return v("6.4", s);
449
+ if (e === "web_app_open_link") {
450
+ if (t === "try_instant_view")
451
+ return m("6.4", s);
452
+ if (t === "try_browser")
453
+ return m("7.6", s);
454
+ }
451
455
  if (e === "web_app_set_header_color" && t === "color")
452
- return v("6.9", s);
456
+ return m("6.9", s);
457
+ if (e === "web_app_close" && t === "return_back")
458
+ return m("7.6", s);
453
459
  }
454
460
  switch (e) {
455
461
  case "web_app_open_tg_link":
@@ -458,27 +464,27 @@ function C(e, t, s) {
458
464
  case "web_app_set_background_color":
459
465
  case "web_app_set_header_color":
460
466
  case "web_app_trigger_haptic_feedback":
461
- return v("6.1", t);
467
+ return m("6.1", t);
462
468
  case "web_app_open_popup":
463
- return v("6.2", t);
469
+ return m("6.2", t);
464
470
  case "web_app_close_scan_qr_popup":
465
471
  case "web_app_open_scan_qr_popup":
466
472
  case "web_app_read_text_from_clipboard":
467
- return v("6.4", t);
473
+ return m("6.4", t);
468
474
  case "web_app_switch_inline_query":
469
- return v("6.7", t);
475
+ return m("6.7", t);
470
476
  case "web_app_invoke_custom_method":
471
477
  case "web_app_request_write_access":
472
478
  case "web_app_request_phone":
473
- return v("6.9", t);
479
+ return m("6.9", t);
474
480
  case "web_app_setup_settings_button":
475
- return v("6.10", t);
481
+ return m("6.10", t);
476
482
  case "web_app_biometry_get_info":
477
483
  case "web_app_biometry_open_settings":
478
484
  case "web_app_biometry_request_access":
479
485
  case "web_app_biometry_request_auth":
480
486
  case "web_app_biometry_update_token":
481
- return v("7.2", t);
487
+ return m("7.2", t);
482
488
  default:
483
489
  return [
484
490
  "iframe_ready",
@@ -531,7 +537,7 @@ function B(e, t, s) {
531
537
  window.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
532
538
  return;
533
539
  }
534
- throw m(
540
+ throw b(
535
541
  ge,
536
542
  "Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment."
537
543
  );
@@ -539,11 +545,11 @@ function B(e, t, s) {
539
545
  function qe(e) {
540
546
  return (t, s) => {
541
547
  if (!C(t, e))
542
- throw m(_e, `Method "${t}" is unsupported in Mini Apps version ${e}`);
548
+ throw b(_e, `Method "${t}" is unsupported in Mini Apps version ${e}`);
543
549
  if (V(s)) {
544
550
  let n;
545
551
  if (t === "web_app_open_link" && "try_instant_view" in s ? n = "try_instant_view" : t === "web_app_set_header_color" && "color" in s && (n = "color"), n && !C(t, n, e))
546
- throw m(
552
+ throw b(
547
553
  we,
548
554
  `Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`
549
555
  );
@@ -555,7 +561,7 @@ function Dt(e) {
555
561
  return ({ req_id: t }) => t === e;
556
562
  }
557
563
  function Bt(e) {
558
- return m(me, `Timeout reached: ${e}ms`);
564
+ return b(me, `Timeout reached: ${e}ms`);
559
565
  }
560
566
  function Mt(e, t) {
561
567
  return Promise.race([
@@ -598,7 +604,7 @@ async function O(e, t, s, n = {}) {
598
604
  capture: Dt(s)
599
605
  });
600
606
  if (i)
601
- throw m(fe, i);
607
+ throw b(fe, i);
602
608
  return r;
603
609
  }
604
610
  function st(...e) {
@@ -746,7 +752,7 @@ const De = w({
746
752
  },
747
753
  username: h().optional()
748
754
  }, "User").optional();
749
- function Ut() {
755
+ function Ht() {
750
756
  return lt({
751
757
  authDate: {
752
758
  type: $t(),
@@ -784,7 +790,7 @@ function Be(e) {
784
790
  function Me(e) {
785
791
  return e.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
786
792
  }
787
- const Ht = A(
793
+ const Ut = A(
788
794
  (e) => {
789
795
  const t = It().optional();
790
796
  return Object.entries(at(e)).reduce((s, [n, r]) => (s[Be(n)] = t.parse(r), s), {});
@@ -798,7 +804,7 @@ function dt(e) {
798
804
  from: "tgWebAppBotInline"
799
805
  },
800
806
  initData: {
801
- type: Ut().optional(),
807
+ type: Ht().optional(),
802
808
  from: "tgWebAppData"
803
809
  },
804
810
  initDataRaw: {
@@ -818,7 +824,7 @@ function dt(e) {
818
824
  from: "tgWebAppStartParam"
819
825
  },
820
826
  themeParams: {
821
- type: Ht(),
827
+ type: Ut(),
822
828
  from: "tgWebAppThemeParams"
823
829
  },
824
830
  version: {
@@ -867,7 +873,7 @@ function Jt(e) {
867
873
  )
868
874
  );
869
875
  }
870
- function Ue(e) {
876
+ function He(e) {
871
877
  const {
872
878
  initDataRaw: t,
873
879
  themeParams: s,
@@ -880,7 +886,7 @@ function Ue(e) {
880
886
  return p.set("tgWebAppPlatform", n), p.set("tgWebAppThemeParams", Jt(s)), p.set("tgWebAppVersion", r), t && p.set("tgWebAppData", t), o && p.set("tgWebAppStartParam", o), typeof i == "boolean" && p.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && p.set("tgWebAppBotInline", a ? "1" : "0"), p.toString();
881
887
  }
882
888
  function Ft(e) {
883
- zt("launchParams", Ue(e));
889
+ zt("launchParams", He(e));
884
890
  }
885
891
  function nt() {
886
892
  for (const e of [
@@ -903,11 +909,11 @@ function Qt() {
903
909
  const e = Gt();
904
910
  return !!(e && e.type === "reload");
905
911
  }
906
- function He() {
912
+ function Ue() {
907
913
  let e = 0;
908
914
  return () => (e += 1).toString();
909
915
  }
910
- const [We] = xt(He);
916
+ const [We] = xt(Ue);
911
917
  function l(e, t) {
912
918
  return () => {
913
919
  const s = nt(), n = {
@@ -1365,7 +1371,7 @@ const rs = l(
1365
1371
  ({ initData: e }) => e ? new ns(e) : void 0
1366
1372
  );
1367
1373
  function fn(e) {
1368
- return Ut().parse(e);
1374
+ return Ht().parse(e);
1369
1375
  }
1370
1376
  class is extends L {
1371
1377
  constructor(t, s, n) {
@@ -1943,7 +1949,7 @@ const bs = l(
1943
1949
  }) => new ms(s.isVisible, e, t)
1944
1950
  );
1945
1951
  function Xt(e) {
1946
- return Ht().parse(e);
1952
+ return Ut().parse(e);
1947
1953
  }
1948
1954
  class vs extends _t {
1949
1955
  /**
@@ -2004,6 +2010,12 @@ class vs extends _t {
2004
2010
  get sectionHeaderTextColor() {
2005
2011
  return this.get("sectionHeaderTextColor");
2006
2012
  }
2013
+ /**
2014
+ * @since v7.6
2015
+ */
2016
+ get sectionSeparatorColor() {
2017
+ return this.get("sectionHeaderTextColor");
2018
+ }
2007
2019
  /**
2008
2020
  * Starts listening to the external theme changes and applies them.
2009
2021
  * @returns Function to stop listening.
@@ -2388,9 +2400,9 @@ function J(e, t) {
2388
2400
  class As {
2389
2401
  constructor(t, s, n = B) {
2390
2402
  if (c(this, "history"), c(this, "ee", new D()), c(this, "attached", !1), c(this, "back", () => this.go(-1)), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this._index = s, this.postEvent = n, t.length === 0)
2391
- throw m(ve, "History should not be empty.");
2403
+ throw b(ve, "History should not be empty.");
2392
2404
  if (s < 0 || s >= t.length)
2393
- throw m(
2405
+ throw b(
2394
2406
  ye,
2395
2407
  "Index should not be zero and higher or equal than history size."
2396
2408
  );
@@ -2515,19 +2527,19 @@ function F({
2515
2527
  function M(e, t) {
2516
2528
  return e.startsWith(t) ? e : `${t}${e}`;
2517
2529
  }
2518
- function U(e) {
2530
+ function H(e) {
2519
2531
  return new URL(
2520
2532
  typeof e == "string" ? e : `${e.pathname || ""}${M(e.search || "", "?")}${M(e.hash || "", "#")}`,
2521
2533
  "http://a"
2522
2534
  );
2523
2535
  }
2524
- function H(e) {
2525
- const t = typeof e == "string" ? e.startsWith("/") : !!(e.pathname && e.pathname.startsWith("/")), s = U(e);
2536
+ function U(e) {
2537
+ const t = typeof e == "string" ? e.startsWith("/") : !!(e.pathname && e.pathname.startsWith("/")), s = H(e);
2526
2538
  return `${t ? s.pathname : s.pathname.slice(1)}${s.search}${s.hash}`;
2527
2539
  }
2528
2540
  function Q(e, t, s) {
2529
2541
  let n, r;
2530
- typeof e == "string" ? n = e : (n = H(e), s = e.state, r = e.id);
2542
+ typeof e == "string" ? n = e : (n = U(e), s = e.state, r = e.id);
2531
2543
  const { pathname: i, search: o, hash: a } = new URL(n, `http://a${M(t, "/")}`);
2532
2544
  return { id: r, pathname: i, params: { hash: a, search: o, state: s } };
2533
2545
  }
@@ -2553,7 +2565,7 @@ async function Is() {
2553
2565
  e = await N(-1);
2554
2566
  }
2555
2567
  function ee(e) {
2556
- return U(e).pathname;
2568
+ return H(e).pathname;
2557
2569
  }
2558
2570
  const Pt = 0, Y = 1, Z = 2;
2559
2571
  class se {
@@ -2677,7 +2689,7 @@ class se {
2677
2689
  * "/pathname?search#hash"
2678
2690
  */
2679
2691
  get path() {
2680
- return H(this);
2692
+ return U(this);
2681
2693
  }
2682
2694
  /**
2683
2695
  * Current pathname. Always starts with the slash.
@@ -2706,8 +2718,8 @@ class se {
2706
2718
  * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2707
2719
  */
2708
2720
  parsePath(t) {
2709
- let s = U(t);
2710
- return this.hashMode && (s = U(s.hash.slice(1))), {
2721
+ let s = H(t);
2722
+ return this.hashMode && (s = H(s.hash.slice(1))), {
2711
2723
  pathname: s.pathname,
2712
2724
  search: s.search,
2713
2725
  hash: s.hash
@@ -2727,7 +2739,7 @@ class se {
2727
2739
  * @param value - path presented as string or URLLike.
2728
2740
  */
2729
2741
  renderPath(t) {
2730
- const s = (this.base.length === 1 ? "" : this.base) + M(H(t), "/");
2742
+ const s = (this.base.length === 1 ? "" : this.base) + M(U(t), "/");
2731
2743
  return this.hashMode ? M(s.slice(1), this.hashMode === "classic" ? "#" : "#/") : s;
2732
2744
  }
2733
2745
  /**
@@ -2757,13 +2769,13 @@ class se {
2757
2769
  function ks(e) {
2758
2770
  e || (e = {});
2759
2771
  const { href: t, hash: s } = window.location;
2760
- let n = H(
2772
+ let n = U(
2761
2773
  e.hashMode === null ? t : s.includes("?") ? s.slice(1) : `?${s.slice(1)}`
2762
2774
  );
2763
2775
  const r = e.base ? ee(e.base) : void 0;
2764
2776
  if (r) {
2765
2777
  if (!n.startsWith(r))
2766
- throw m(
2778
+ throw b(
2767
2779
  Ee,
2768
2780
  `Path "${n}" expected to be starting with "${r}"`
2769
2781
  );
@@ -2852,13 +2864,13 @@ const [Ns, Ds] = _(Ge), [Sn, Tn] = d(
2852
2864
  ), [Vs, Ls] = _(Fe), [kn, qn] = d(
2853
2865
  Vs,
2854
2866
  Ls
2855
- ), [$s, Us] = _(ts), [On, Nn] = d(
2867
+ ), [$s, Hs] = _(ts), [On, Nn] = d(
2856
2868
  $s,
2857
- Us
2858
- ), [Hs, Ws] = _(ss), [Dn, Bn] = d(
2859
- Hs,
2869
+ Hs
2870
+ ), [Us, Ws] = _(ss), [Dn, Bn] = d(
2871
+ Us,
2860
2872
  Ws
2861
- ), [Gs, js] = _(rs), [Mn, Vn] = d(Gs, js), [zs, Ks] = _(os), [Ln, $n] = d(zs, Ks), [Js, Fs] = _(cs), [Un, Hn] = d(Js, Fs), [Qs, Ys] = _(ls), [Wn, Gn] = d(Qs, Ys), [Zs, Xs] = _(ws), [jn, zn] = d(Zs, Xs), [tn, en] = _(fs), [Kn, Jn] = d(tn, en), [sn, nn] = _(bs), [Fn, Qn] = d(
2873
+ ), [Gs, js] = _(rs), [Mn, Vn] = d(Gs, js), [zs, Ks] = _(os), [Ln, $n] = d(zs, Ks), [Js, Fs] = _(cs), [Hn, Un] = d(Js, Fs), [Qs, Ys] = _(ls), [Wn, Gn] = d(Qs, Ys), [Zs, Xs] = _(ws), [jn, zn] = d(Zs, Xs), [tn, en] = _(fs), [Kn, Jn] = d(tn, en), [sn, nn] = _(bs), [Fn, Qn] = d(
2862
2874
  sn,
2863
2875
  nn
2864
2876
  ), [rn, on] = _(ys), [Yn, Zn] = d(rn, on);
@@ -2880,9 +2892,9 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2880
2892
  const gt = r.get(u);
2881
2893
  if (gt)
2882
2894
  return gt;
2883
- let b, K;
2895
+ let v, K;
2884
2896
  try {
2885
- b = u(...S);
2897
+ v = u(...S);
2886
2898
  } catch (f) {
2887
2899
  K = f;
2888
2900
  }
@@ -2892,8 +2904,8 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2892
2904
  if (K)
2893
2905
  return $({ error: K });
2894
2906
  let I;
2895
- if (Array.isArray(b) && (I = b[1], b = b[0]), !b)
2896
- return $({ result: b, cleanup: I });
2907
+ if (Array.isArray(v) && (I = v[1], v = v[0]), !v)
2908
+ return $({ result: v, cleanup: I });
2897
2909
  function ft(f) {
2898
2910
  if ("on" in f) {
2899
2911
  const k = f.on("change", () => a()), mt = I;
@@ -2903,10 +2915,10 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2903
2915
  }
2904
2916
  return { result: f, cleanup: I };
2905
2917
  }
2906
- return b instanceof Promise ? (b.then(
2918
+ return v instanceof Promise ? (v.then(
2907
2919
  (f) => a((k) => k.set(u, ft(f))),
2908
2920
  (f) => a((k) => k.set(u, { error: f }))
2909
- ), $({})) : $(ft(b));
2921
+ ), $({})) : $(ft(v));
2910
2922
  }
2911
2923
  }), [r]);
2912
2924
  return R(() => (n.current = !0, () => {
@@ -2967,7 +2979,7 @@ export {
2967
2979
  Ie as compareVersions,
2968
2980
  ks as createBrowserNavigatorFromLocation,
2969
2981
  qe as createPostEvent,
2970
- U as createSafeURL,
2982
+ H as createSafeURL,
2971
2983
  $t as date,
2972
2984
  xn as getHash,
2973
2985
  ee as getPathname,
@@ -3015,7 +3027,7 @@ export {
3015
3027
  nt as retrieveLaunchParams,
3016
3028
  It as rgb,
3017
3029
  lt as searchParams,
3018
- Ue as serializeLaunchParams,
3030
+ He as serializeLaunchParams,
3019
3031
  Jt as serializeThemeParams,
3020
3032
  P as setCSSVar,
3021
3033
  le as setDebug,
@@ -3026,17 +3038,17 @@ export {
3026
3038
  ke as targetOrigin,
3027
3039
  At as toRGB,
3028
3040
  Ct as unsubscribe,
3029
- H as urlToPath,
3041
+ U as urlToPath,
3030
3042
  Ds as useBackButton,
3031
3043
  Ns as useBackButtonRaw,
3032
3044
  Ms as useBiometryManager,
3033
3045
  Bs as useBiometryManagerRaw,
3034
3046
  Ls as useClosingBehavior,
3035
3047
  Vs as useClosingBehaviorRaw,
3036
- Us as useCloudStorage,
3048
+ Hs as useCloudStorage,
3037
3049
  $s as useCloudStorageRaw,
3038
3050
  Ws as useHapticFeedback,
3039
- Hs as useHapticFeedbackRaw,
3051
+ Us as useHapticFeedbackRaw,
3040
3052
  js as useInitData,
3041
3053
  Gs as useInitDataRaw,
3042
3054
  Ks as useInvoice,
@@ -3073,8 +3085,8 @@ export {
3073
3085
  Mn as withInitDataRaw,
3074
3086
  $n as withInvoice,
3075
3087
  Ln as withInvoiceRaw,
3076
- Hn as withMainButton,
3077
- Un as withMainButtonRaw,
3088
+ Un as withMainButton,
3089
+ Hn as withMainButtonRaw,
3078
3090
  Gn as withMiniApp,
3079
3091
  Wn as withMiniAppRaw,
3080
3092
  zn as withPopup,