@tma.js/sdk 2.4.0 → 2.5.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.
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ function Ye(e) {
69
69
  function jt(...e) {
70
70
  H && F.log(...e);
71
71
  }
72
- class T {
72
+ class R {
73
73
  constructor() {
74
74
  c(this, "listeners", /* @__PURE__ */ new Map());
75
75
  c(this, "listenersCount", 0);
@@ -351,7 +351,7 @@ const re = {
351
351
  write_access_requested: d({ status: h() })
352
352
  };
353
353
  function ie() {
354
- const e = new T(), t = new T();
354
+ const e = new R(), t = new R();
355
355
  t.subscribe((n) => {
356
356
  e.emit("event", { name: n.event, payload: n.args[0] });
357
357
  }), ne();
@@ -425,7 +425,7 @@ const [oe, ae] = at(
425
425
  function M() {
426
426
  return oe()[0];
427
427
  }
428
- function $(e, t) {
428
+ function L(e, t) {
429
429
  M().off(e, t);
430
430
  }
431
431
  function w(e, t, s) {
@@ -517,7 +517,7 @@ function Xe(e) {
517
517
  function he() {
518
518
  return wt;
519
519
  }
520
- function R(e, t, s) {
520
+ function T(e, t, s) {
521
521
  let n = {}, r;
522
522
  t === void 0 && s === void 0 ? n = {} : t !== void 0 && s !== void 0 ? (n = s, r = t) : t !== void 0 && ("targetOrigin" in t ? n = t : r = t);
523
523
  const { targetOrigin: i = he() } = n;
@@ -550,7 +550,7 @@ function pe(e) {
550
550
  `Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`
551
551
  );
552
552
  }
553
- return R(t, s);
553
+ return T(t, s);
554
554
  };
555
555
  }
556
556
  function bt(e) {
@@ -579,7 +579,7 @@ async function _(e) {
579
579
  )
580
580
  );
581
581
  try {
582
- return (e.postEvent || R)(e.method, e.params), await (i ? yt(s, i) : s);
582
+ return (e.postEvent || T)(e.method, e.params), await (i ? yt(s, i) : s);
583
583
  } finally {
584
584
  o();
585
585
  }
@@ -630,7 +630,7 @@ function vt(e) {
630
630
  }
631
631
  class ue {
632
632
  constructor(t) {
633
- c(this, "ee", new T());
633
+ c(this, "ee", new R());
634
634
  /**
635
635
  * Adds new event listener.
636
636
  */
@@ -706,7 +706,7 @@ class le extends K {
706
706
  * @param event - event to listen.
707
707
  * @param listener - listener to remove.
708
708
  */
709
- c(this, "off", (s, n) => s === "click" ? $("back_button_pressed", n) : this.state.off(s, n));
709
+ c(this, "off", (s, n) => s === "click" ? L("back_button_pressed", n) : this.state.off(s, n));
710
710
  this.postEvent = r;
711
711
  }
712
712
  set isVisible(s) {
@@ -877,23 +877,23 @@ function Ct(e) {
877
877
  function ge() {
878
878
  return Ct(window.location.href);
879
879
  }
880
- function Tt() {
880
+ function Rt() {
881
881
  return performance.getEntriesByType("navigation")[0];
882
882
  }
883
883
  function we() {
884
- const e = Tt();
884
+ const e = Rt();
885
885
  if (!e)
886
886
  throw new Error("Unable to get first navigation entry.");
887
887
  return Ct(e.name);
888
888
  }
889
- function Rt(e) {
889
+ function Tt(e) {
890
890
  return `tma.js/${e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`)}`;
891
891
  }
892
892
  function At(e, t) {
893
- sessionStorage.setItem(Rt(e), JSON.stringify(t));
893
+ sessionStorage.setItem(Tt(e), JSON.stringify(t));
894
894
  }
895
895
  function It(e) {
896
- const t = sessionStorage.getItem(Rt(e));
896
+ const t = sessionStorage.getItem(Tt(e));
897
897
  try {
898
898
  return t ? JSON.parse(t) : void 0;
899
899
  } catch {
@@ -942,7 +942,7 @@ function ye() {
942
942
  throw new Error("Unable to retrieve launch parameters from any known source.");
943
943
  }
944
944
  function Nt() {
945
- const e = Tt();
945
+ const e = Rt();
946
946
  return !!(e && e.type === "reload");
947
947
  }
948
948
  function ve() {
@@ -1218,7 +1218,7 @@ function Ce(e) {
1218
1218
  }
1219
1219
  throw E();
1220
1220
  }
1221
- class Te extends V {
1221
+ class Re extends V {
1222
1222
  constructor(s, n, r) {
1223
1223
  super(Ce, n, r);
1224
1224
  c(this, "itemParser");
@@ -1238,8 +1238,8 @@ class Te extends V {
1238
1238
  return this.itemParser = typeof s == "function" ? s : s.parse.bind(s), this;
1239
1239
  }
1240
1240
  }
1241
- function Re(e) {
1242
- return new Te((t) => t, !1, e);
1241
+ function Te(e) {
1242
+ return new Re((t) => t, !1, e);
1243
1243
  }
1244
1244
  function it(e, t) {
1245
1245
  return Object.fromEntries(e.map((s) => [s, t]));
@@ -1272,7 +1272,7 @@ class Ae extends st {
1272
1272
  * @param options - request execution options.
1273
1273
  */
1274
1274
  async getKeys(t = {}) {
1275
- return Re().of(h()).parse(
1275
+ return Te().of(h()).parse(
1276
1276
  await S(
1277
1277
  "getStorageKeys",
1278
1278
  {},
@@ -1497,7 +1497,7 @@ class Ne extends Z {
1497
1497
  * @param event - event to listen.
1498
1498
  * @param listener - listener to remove.
1499
1499
  */
1500
- c(this, "off", (s, n) => s === "click" ? $("main_button_pressed", n) : this.state.off(s, n));
1500
+ c(this, "off", (s, n) => s === "click" ? L("main_button_pressed", n) : this.state.off(s, n));
1501
1501
  this.postEvent = s;
1502
1502
  }
1503
1503
  /**
@@ -1883,7 +1883,7 @@ const ps = l(
1883
1883
  ...n
1884
1884
  }) => new Me({ ...n, ...s, botInline: t })
1885
1885
  );
1886
- function $e(e) {
1886
+ function Le(e) {
1887
1887
  const t = e.message.trim(), s = (e.title || "").trim(), n = e.buttons || [];
1888
1888
  let r;
1889
1889
  if (s.length > 64)
@@ -1907,7 +1907,7 @@ function $e(e) {
1907
1907
  return { ...i, id: o };
1908
1908
  }) : r = [{ type: "close", id: "" }], { title: s, message: t, buttons: r };
1909
1909
  }
1910
- class Le extends q {
1910
+ class $e extends q {
1911
1911
  constructor(t, s, n) {
1912
1912
  super({ isOpened: t }, s, { open: "web_app_open_popup" }), this.postEvent = n;
1913
1913
  }
@@ -1940,7 +1940,7 @@ class Le extends q {
1940
1940
  event: "popup_closed",
1941
1941
  method: "web_app_open_popup",
1942
1942
  postEvent: this.postEvent,
1943
- params: $e(t)
1943
+ params: Le(t)
1944
1944
  });
1945
1945
  return s;
1946
1946
  } finally {
@@ -1949,7 +1949,7 @@ class Le extends q {
1949
1949
  }
1950
1950
  }
1951
1951
  const us = l(
1952
- ({ postEvent: e, version: t }) => new Le(!1, t, e)
1952
+ ({ postEvent: e, version: t }) => new $e(!1, t, e)
1953
1953
  );
1954
1954
  class Be extends q {
1955
1955
  constructor(t, s, n) {
@@ -2014,7 +2014,7 @@ class We extends K {
2014
2014
  * @param event - event to listen.
2015
2015
  * @param listener - listener to remove.
2016
2016
  */
2017
- c(this, "off", (s, n) => s === "click" ? $("settings_button_pressed", n) : this.state.off(s, n));
2017
+ c(this, "off", (s, n) => s === "click" ? L("settings_button_pressed", n) : this.state.off(s, n));
2018
2018
  this.postEvent = r;
2019
2019
  }
2020
2020
  set isVisible(s) {
@@ -2180,7 +2180,7 @@ class Ue extends st {
2180
2180
  * @throws {Error} URL has not allowed hostname.
2181
2181
  */
2182
2182
  openTelegramLink(s) {
2183
- const { hostname: n, pathname: r, search: i } = new URL(s, window.location.href);
2183
+ const { hostname: n, pathname: r, search: i } = new URL(s, "https://t.me");
2184
2184
  if (n !== "t.me")
2185
2185
  throw new Error(`URL has not allowed hostname: ${n}. Only "t.me" is allowed`);
2186
2186
  if (!v("web_app_open_tg_link", this.version)) {
@@ -2207,11 +2207,25 @@ class Ue extends st {
2207
2207
  });
2208
2208
  return n;
2209
2209
  }
2210
+ /**
2211
+ * Shares specified URL with the passed to the chats, selected by user. After being called,
2212
+ * it closes the mini application.
2213
+ *
2214
+ * This method uses Telegram's Share Links.
2215
+ * @param url - URL to share.
2216
+ * @param text - text to append after the URL.
2217
+ * @see https://core.telegram.org/api/links#share-links
2218
+ */
2219
+ shareURL(s, n) {
2220
+ this.openTelegramLink(
2221
+ "https://t.me/share?" + new URLSearchParams({ url: s, text: n || "" }).toString()
2222
+ );
2223
+ }
2210
2224
  }
2211
2225
  const gs = l(
2212
2226
  ({ version: e, postEvent: t, createRequestId: s }) => new Ue(e, s, t)
2213
2227
  );
2214
- async function $t(e = {}) {
2228
+ async function Lt(e = {}) {
2215
2229
  const {
2216
2230
  is_expanded: t,
2217
2231
  is_state_stable: s,
@@ -2243,7 +2257,7 @@ class He extends et {
2243
2257
  * @param options - options to request fresh data.
2244
2258
  */
2245
2259
  async sync(s) {
2246
- const { isStateStable: n, ...r } = await $t(s);
2260
+ const { isStateStable: n, ...r } = await Lt(s);
2247
2261
  this.set({
2248
2262
  ...r,
2249
2263
  stableHeight: n ? r.height : this.get("stableHeight")
@@ -2344,7 +2358,7 @@ const ws = l(
2344
2358
  else if (["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(t))
2345
2359
  r = !0, i = window.innerHeight, o = window.innerWidth, a = window.innerHeight;
2346
2360
  else {
2347
- const u = await $t({ timeout: 1e3, postEvent: s });
2361
+ const u = await Lt({ timeout: 1e3, postEvent: s });
2348
2362
  r = u.isExpanded, i = u.height, o = u.width, a = u.isStateStable ? i : 0;
2349
2363
  }
2350
2364
  const p = new He({
@@ -2402,7 +2416,7 @@ function ys(e, t) {
2402
2416
  function vs(e = !0) {
2403
2417
  const t = [
2404
2418
  w("reload_iframe", () => {
2405
- R("iframe_will_reload"), window.location.reload();
2419
+ T("iframe_will_reload"), window.location.reload();
2406
2420
  })
2407
2421
  ], s = () => t.forEach((n) => n());
2408
2422
  if (e) {
@@ -2414,7 +2428,7 @@ function vs(e = !0) {
2414
2428
  () => document.head.removeChild(n)
2415
2429
  );
2416
2430
  }
2417
- return R("iframe_ready", { reload_supported: !0 }), s;
2431
+ return T("iframe_ready", { reload_supported: !0 }), s;
2418
2432
  }
2419
2433
  function Es() {
2420
2434
  return typeof window > "u";
@@ -2474,7 +2488,7 @@ function Ge(e) {
2474
2488
  function Ss(e, t) {
2475
2489
  return Ge(e) && e.type === t;
2476
2490
  }
2477
- function L(e, t) {
2491
+ function $(e, t) {
2478
2492
  let s, n, r;
2479
2493
  return typeof e == "string" ? s = e : (s = e.pathname === void 0 ? t : e.pathname, n = e.params, r = e.id), Object.freeze({
2480
2494
  id: r || (Math.random() * 2 ** 14 | 0).toString(16),
@@ -2483,12 +2497,12 @@ function L(e, t) {
2483
2497
  });
2484
2498
  }
2485
2499
  class je {
2486
- constructor(t, s, n = R) {
2500
+ constructor(t, s, n = T) {
2487
2501
  /**
2488
2502
  * Navigation history.
2489
2503
  */
2490
2504
  c(this, "history");
2491
- c(this, "ee", new T());
2505
+ c(this, "ee", new R());
2492
2506
  /**
2493
2507
  * True, if current navigator is currently attached.
2494
2508
  */
@@ -2512,7 +2526,7 @@ class je {
2512
2526
  Xt,
2513
2527
  "Index should not be zero and higher or equal than history size."
2514
2528
  );
2515
- this.history = t.map((r) => L(r, ""));
2529
+ this.history = t.map((r) => $(r, ""));
2516
2530
  }
2517
2531
  /**
2518
2532
  * Allows this navigator to control the `BackButton` visibility state. It also tracks the
@@ -2531,7 +2545,7 @@ class je {
2531
2545
  * Prevents current navigator from controlling the BackButton visibility state.
2532
2546
  */
2533
2547
  detach() {
2534
- this.attached = !1, $("back_button_pressed", this.back);
2548
+ this.attached = !1, L("back_button_pressed", this.back);
2535
2549
  }
2536
2550
  /**
2537
2551
  * Goes to the next history item.
@@ -2587,14 +2601,14 @@ class je {
2587
2601
  * @param item - item to add.
2588
2602
  */
2589
2603
  push(t) {
2590
- this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, L(t, this.current.pathname));
2604
+ this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, $(t, this.current.pathname));
2591
2605
  }
2592
2606
  /**
2593
2607
  * Replaces the current history item.
2594
2608
  * @param item - item to replace the current item with.
2595
2609
  */
2596
2610
  replace(t) {
2597
- this.replaceAndMove(this.index, L(t, this.current.pathname));
2611
+ this.replaceAndMove(this.index, $(t, this.current.pathname));
2598
2612
  }
2599
2613
  /**
2600
2614
  * Sets history item by the specified index.
@@ -2670,14 +2684,14 @@ async function ze() {
2670
2684
  for (; t; )
2671
2685
  t = await C(-1);
2672
2686
  }
2673
- function Lt(e) {
2687
+ function $t(e) {
2674
2688
  return k(e).pathname;
2675
2689
  }
2676
2690
  const ot = 0, O = 1, U = 2;
2677
2691
  class Bt {
2678
2692
  constructor(t, s, { postEvent: n, hashMode: r = "classic", base: i } = {}) {
2679
2693
  c(this, "navigator");
2680
- c(this, "ee", new T());
2694
+ c(this, "ee", new R());
2681
2695
  c(this, "hashMode");
2682
2696
  c(this, "base");
2683
2697
  /**
@@ -2720,7 +2734,9 @@ class Bt {
2720
2734
  t.map((o) => W(o, "/")),
2721
2735
  s,
2722
2736
  n
2723
- ), this.navigator.on("change", this.onNavigatorChange), this.hashMode = r, this.base = Lt(i || "");
2737
+ ), this.navigator.on("change", (o) => {
2738
+ this.onNavigatorChange(o);
2739
+ }), this.hashMode = r, this.base = $t(i || "");
2724
2740
  }
2725
2741
  /**
2726
2742
  * Attaches current navigator to the browser history allowing navigator to manipulate it.
@@ -2901,7 +2917,7 @@ function Fe(e) {
2901
2917
  let n = N(
2902
2918
  e.hashMode === null ? t : s.includes("?") ? s.slice(1) : `?${s.slice(1)}`
2903
2919
  );
2904
- const r = e.base ? Lt(e.base) : void 0;
2920
+ const r = e.base ? $t(e.base) : void 0;
2905
2921
  if (r) {
2906
2922
  if (!n.startsWith(r))
2907
2923
  throw f(
@@ -2922,14 +2938,18 @@ function Je(e, t) {
2922
2938
  if (s)
2923
2939
  try {
2924
2940
  const { index: n, history: r } = JSON.parse(s);
2925
- return new Bt(r, n, t);
2941
+ return new Bt(
2942
+ r,
2943
+ n,
2944
+ t
2945
+ );
2926
2946
  } catch (n) {
2927
2947
  console.error("Unable to restore hash navigator state.", n);
2928
2948
  }
2929
2949
  }
2930
2950
  return Fe(t);
2931
2951
  }
2932
- function Ts(e, t) {
2952
+ function Rs(e, t) {
2933
2953
  const s = Je(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
2934
2954
  index: s.index,
2935
2955
  history: s.history
@@ -2955,20 +2975,20 @@ export {
2955
2975
  Yt as ERR_TIMED_OUT,
2956
2976
  Zt as ERR_UNEXPECTED_TYPE,
2957
2977
  Jt as ERR_UNKNOWN_ENV,
2958
- T as EventEmitter,
2978
+ R as EventEmitter,
2959
2979
  Ie as HapticFeedback,
2960
2980
  qe as InitData,
2961
2981
  ke as Invoice,
2962
2982
  Ne as MainButton,
2963
2983
  Me as MiniApp,
2964
- Le as Popup,
2984
+ $e as Popup,
2965
2985
  Be as QRScanner,
2966
2986
  D as SDKError,
2967
2987
  We as SettingsButton,
2968
2988
  Oe as ThemeParams,
2969
2989
  Ue as Utils,
2970
2990
  He as Viewport,
2971
- Re as array,
2991
+ Te as array,
2972
2992
  bs as bindMiniAppCSSVars,
2973
2993
  ms as bindThemeParamsCSSVars,
2974
2994
  ys as bindViewportCSSVars,
@@ -2981,7 +3001,7 @@ export {
2981
3001
  k as createSafeURL,
2982
3002
  Pt as date,
2983
3003
  Cs as getHash,
2984
- Lt as getPathname,
3004
+ $t as getPathname,
2985
3005
  es as initBackButton,
2986
3006
  ss as initBiometryManager,
2987
3007
  ns as initClosingBehavior,
@@ -2991,7 +3011,7 @@ export {
2991
3011
  cs as initInvoice,
2992
3012
  hs as initMainButton,
2993
3013
  ps as initMiniApp,
2994
- Ts as initNavigator,
3014
+ Rs as initNavigator,
2995
3015
  us as initPopup,
2996
3016
  ls as initQRScanner,
2997
3017
  ds as initSettingsButton,
@@ -3013,16 +3033,16 @@ export {
3013
3033
  ts as mergeClassNames,
3014
3034
  xs as mockTelegramEnv,
3015
3035
  y as number,
3016
- $ as off,
3036
+ L as off,
3017
3037
  w as on,
3018
3038
  as as parseInitData,
3019
3039
  tt as parseLaunchParams,
3020
3040
  Mt as parseThemeParams,
3021
- R as postEvent,
3041
+ T as postEvent,
3022
3042
  _ as request,
3023
3043
  xe as requestBiometryInfo,
3024
3044
  fs as requestThemeParams,
3025
- $t as requestViewport,
3045
+ Lt as requestViewport,
3026
3046
  ye as retrieveLaunchParams,
3027
3047
  lt as rgb,
3028
3048
  X as searchParams,