@tma.js/sdk-react 2.2.4 → 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
@@ -1,6 +1,6 @@
1
1
  import { jsx as Rt } from "react/jsx-runtime";
2
2
  import { createContext as re, useContext as ie, useState as rt, useEffect as R, useRef as bt, useCallback as oe, useMemo as ae } from "react";
3
- var ce = Object.defineProperty, he = (e, t, s) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, c = (e, t, s) => (he(e, typeof t != "symbol" ? t + "" : t, s), s);
3
+ var ce = Object.defineProperty, he = (e, t, s) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, c = (e, t, s) => he(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  function xt(e, t) {
5
5
  let s;
6
6
  const n = () => {
@@ -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.
@@ -2105,10 +2117,11 @@ class Es extends wt {
2105
2117
  * @param url - URL to share.
2106
2118
  * @param text - text to append after the URL.
2107
2119
  * @see https://core.telegram.org/api/links#share-links
2120
+ * @see https://core.telegram.org/widgets/share#custom-buttons
2108
2121
  */
2109
2122
  shareURL(t, s) {
2110
2123
  this.openTelegramLink(
2111
- "https://t.me/share?" + new URLSearchParams({ url: t, text: s || "" }).toString()
2124
+ "https://t.me/share/url?" + new URLSearchParams({ url: t, text: s || "" }).toString()
2112
2125
  );
2113
2126
  }
2114
2127
  }
@@ -2387,9 +2400,9 @@ function J(e, t) {
2387
2400
  class As {
2388
2401
  constructor(t, s, n = B) {
2389
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)
2390
- throw m(ve, "History should not be empty.");
2403
+ throw b(ve, "History should not be empty.");
2391
2404
  if (s < 0 || s >= t.length)
2392
- throw m(
2405
+ throw b(
2393
2406
  ye,
2394
2407
  "Index should not be zero and higher or equal than history size."
2395
2408
  );
@@ -2514,19 +2527,19 @@ function F({
2514
2527
  function M(e, t) {
2515
2528
  return e.startsWith(t) ? e : `${t}${e}`;
2516
2529
  }
2517
- function U(e) {
2530
+ function H(e) {
2518
2531
  return new URL(
2519
2532
  typeof e == "string" ? e : `${e.pathname || ""}${M(e.search || "", "?")}${M(e.hash || "", "#")}`,
2520
2533
  "http://a"
2521
2534
  );
2522
2535
  }
2523
- function H(e) {
2524
- 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);
2525
2538
  return `${t ? s.pathname : s.pathname.slice(1)}${s.search}${s.hash}`;
2526
2539
  }
2527
2540
  function Q(e, t, s) {
2528
2541
  let n, r;
2529
- 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);
2530
2543
  const { pathname: i, search: o, hash: a } = new URL(n, `http://a${M(t, "/")}`);
2531
2544
  return { id: r, pathname: i, params: { hash: a, search: o, state: s } };
2532
2545
  }
@@ -2552,7 +2565,7 @@ async function Is() {
2552
2565
  e = await N(-1);
2553
2566
  }
2554
2567
  function ee(e) {
2555
- return U(e).pathname;
2568
+ return H(e).pathname;
2556
2569
  }
2557
2570
  const Pt = 0, Y = 1, Z = 2;
2558
2571
  class se {
@@ -2676,7 +2689,7 @@ class se {
2676
2689
  * "/pathname?search#hash"
2677
2690
  */
2678
2691
  get path() {
2679
- return H(this);
2692
+ return U(this);
2680
2693
  }
2681
2694
  /**
2682
2695
  * Current pathname. Always starts with the slash.
@@ -2705,8 +2718,8 @@ class se {
2705
2718
  * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2706
2719
  */
2707
2720
  parsePath(t) {
2708
- let s = U(t);
2709
- return this.hashMode && (s = U(s.hash.slice(1))), {
2721
+ let s = H(t);
2722
+ return this.hashMode && (s = H(s.hash.slice(1))), {
2710
2723
  pathname: s.pathname,
2711
2724
  search: s.search,
2712
2725
  hash: s.hash
@@ -2726,7 +2739,7 @@ class se {
2726
2739
  * @param value - path presented as string or URLLike.
2727
2740
  */
2728
2741
  renderPath(t) {
2729
- const s = (this.base.length === 1 ? "" : this.base) + M(H(t), "/");
2742
+ const s = (this.base.length === 1 ? "" : this.base) + M(U(t), "/");
2730
2743
  return this.hashMode ? M(s.slice(1), this.hashMode === "classic" ? "#" : "#/") : s;
2731
2744
  }
2732
2745
  /**
@@ -2756,13 +2769,13 @@ class se {
2756
2769
  function ks(e) {
2757
2770
  e || (e = {});
2758
2771
  const { href: t, hash: s } = window.location;
2759
- let n = H(
2772
+ let n = U(
2760
2773
  e.hashMode === null ? t : s.includes("?") ? s.slice(1) : `?${s.slice(1)}`
2761
2774
  );
2762
2775
  const r = e.base ? ee(e.base) : void 0;
2763
2776
  if (r) {
2764
2777
  if (!n.startsWith(r))
2765
- throw m(
2778
+ throw b(
2766
2779
  Ee,
2767
2780
  `Path "${n}" expected to be starting with "${r}"`
2768
2781
  );
@@ -2851,13 +2864,13 @@ const [Ns, Ds] = _(Ge), [Sn, Tn] = d(
2851
2864
  ), [Vs, Ls] = _(Fe), [kn, qn] = d(
2852
2865
  Vs,
2853
2866
  Ls
2854
- ), [$s, Us] = _(ts), [On, Nn] = d(
2867
+ ), [$s, Hs] = _(ts), [On, Nn] = d(
2855
2868
  $s,
2856
- Us
2857
- ), [Hs, Ws] = _(ss), [Dn, Bn] = d(
2858
- Hs,
2869
+ Hs
2870
+ ), [Us, Ws] = _(ss), [Dn, Bn] = d(
2871
+ Us,
2859
2872
  Ws
2860
- ), [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(
2861
2874
  sn,
2862
2875
  nn
2863
2876
  ), [rn, on] = _(ys), [Yn, Zn] = d(rn, on);
@@ -2879,9 +2892,9 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2879
2892
  const gt = r.get(u);
2880
2893
  if (gt)
2881
2894
  return gt;
2882
- let b, K;
2895
+ let v, K;
2883
2896
  try {
2884
- b = u(...S);
2897
+ v = u(...S);
2885
2898
  } catch (f) {
2886
2899
  K = f;
2887
2900
  }
@@ -2891,8 +2904,8 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2891
2904
  if (K)
2892
2905
  return $({ error: K });
2893
2906
  let I;
2894
- if (Array.isArray(b) && (I = b[1], b = b[0]), !b)
2895
- return $({ result: b, cleanup: I });
2907
+ if (Array.isArray(v) && (I = v[1], v = v[0]), !v)
2908
+ return $({ result: v, cleanup: I });
2896
2909
  function ft(f) {
2897
2910
  if ("on" in f) {
2898
2911
  const k = f.on("change", () => a()), mt = I;
@@ -2902,10 +2915,10 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
2902
2915
  }
2903
2916
  return { result: f, cleanup: I };
2904
2917
  }
2905
- return b instanceof Promise ? (b.then(
2918
+ return v instanceof Promise ? (v.then(
2906
2919
  (f) => a((k) => k.set(u, ft(f))),
2907
2920
  (f) => a((k) => k.set(u, { error: f }))
2908
- ), $({})) : $(ft(b));
2921
+ ), $({})) : $(ft(v));
2909
2922
  }
2910
2923
  }), [r]);
2911
2924
  return R(() => (n.current = !0, () => {
@@ -2966,7 +2979,7 @@ export {
2966
2979
  Ie as compareVersions,
2967
2980
  ks as createBrowserNavigatorFromLocation,
2968
2981
  qe as createPostEvent,
2969
- U as createSafeURL,
2982
+ H as createSafeURL,
2970
2983
  $t as date,
2971
2984
  xn as getHash,
2972
2985
  ee as getPathname,
@@ -3014,7 +3027,7 @@ export {
3014
3027
  nt as retrieveLaunchParams,
3015
3028
  It as rgb,
3016
3029
  lt as searchParams,
3017
- Ue as serializeLaunchParams,
3030
+ He as serializeLaunchParams,
3018
3031
  Jt as serializeThemeParams,
3019
3032
  P as setCSSVar,
3020
3033
  le as setDebug,
@@ -3025,17 +3038,17 @@ export {
3025
3038
  ke as targetOrigin,
3026
3039
  At as toRGB,
3027
3040
  Ct as unsubscribe,
3028
- H as urlToPath,
3041
+ U as urlToPath,
3029
3042
  Ds as useBackButton,
3030
3043
  Ns as useBackButtonRaw,
3031
3044
  Ms as useBiometryManager,
3032
3045
  Bs as useBiometryManagerRaw,
3033
3046
  Ls as useClosingBehavior,
3034
3047
  Vs as useClosingBehaviorRaw,
3035
- Us as useCloudStorage,
3048
+ Hs as useCloudStorage,
3036
3049
  $s as useCloudStorageRaw,
3037
3050
  Ws as useHapticFeedback,
3038
- Hs as useHapticFeedbackRaw,
3051
+ Us as useHapticFeedbackRaw,
3039
3052
  js as useInitData,
3040
3053
  Gs as useInitDataRaw,
3041
3054
  Ks as useInvoice,
@@ -3072,8 +3085,8 @@ export {
3072
3085
  Mn as withInitDataRaw,
3073
3086
  $n as withInvoice,
3074
3087
  Ln as withInvoiceRaw,
3075
- Hn as withMainButton,
3076
- Un as withMainButtonRaw,
3088
+ Un as withMainButton,
3089
+ Hn as withMainButtonRaw,
3077
3090
  Gn as withMiniApp,
3078
3091
  Wn as withMiniAppRaw,
3079
3092
  zn as withPopup,