@tma.js/sdk 2.4.0 → 2.5.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var Ot = Object.defineProperty;
2
2
  var Ut = (e, t, s) => t in e ? Ot(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var c = (e, t, s) => (Ut(e, typeof t != "symbol" ? t + "" : t, s), s);
3
+ var c = (e, t, s) => Ut(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  function at(e, t) {
5
5
  let s;
6
6
  const n = () => {
@@ -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,26 @@ 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
+ * @see https://core.telegram.org/widgets/share#custom-buttons
2219
+ */
2220
+ shareURL(s, n) {
2221
+ this.openTelegramLink(
2222
+ "https://t.me/share/url?" + new URLSearchParams({ url: s, text: n || "" }).toString()
2223
+ );
2224
+ }
2210
2225
  }
2211
2226
  const gs = l(
2212
2227
  ({ version: e, postEvent: t, createRequestId: s }) => new Ue(e, s, t)
2213
2228
  );
2214
- async function $t(e = {}) {
2229
+ async function Lt(e = {}) {
2215
2230
  const {
2216
2231
  is_expanded: t,
2217
2232
  is_state_stable: s,
@@ -2243,7 +2258,7 @@ class He extends et {
2243
2258
  * @param options - options to request fresh data.
2244
2259
  */
2245
2260
  async sync(s) {
2246
- const { isStateStable: n, ...r } = await $t(s);
2261
+ const { isStateStable: n, ...r } = await Lt(s);
2247
2262
  this.set({
2248
2263
  ...r,
2249
2264
  stableHeight: n ? r.height : this.get("stableHeight")
@@ -2344,7 +2359,7 @@ const ws = l(
2344
2359
  else if (["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(t))
2345
2360
  r = !0, i = window.innerHeight, o = window.innerWidth, a = window.innerHeight;
2346
2361
  else {
2347
- const u = await $t({ timeout: 1e3, postEvent: s });
2362
+ const u = await Lt({ timeout: 1e3, postEvent: s });
2348
2363
  r = u.isExpanded, i = u.height, o = u.width, a = u.isStateStable ? i : 0;
2349
2364
  }
2350
2365
  const p = new He({
@@ -2402,7 +2417,7 @@ function ys(e, t) {
2402
2417
  function vs(e = !0) {
2403
2418
  const t = [
2404
2419
  w("reload_iframe", () => {
2405
- R("iframe_will_reload"), window.location.reload();
2420
+ T("iframe_will_reload"), window.location.reload();
2406
2421
  })
2407
2422
  ], s = () => t.forEach((n) => n());
2408
2423
  if (e) {
@@ -2414,7 +2429,7 @@ function vs(e = !0) {
2414
2429
  () => document.head.removeChild(n)
2415
2430
  );
2416
2431
  }
2417
- return R("iframe_ready", { reload_supported: !0 }), s;
2432
+ return T("iframe_ready", { reload_supported: !0 }), s;
2418
2433
  }
2419
2434
  function Es() {
2420
2435
  return typeof window > "u";
@@ -2474,7 +2489,7 @@ function Ge(e) {
2474
2489
  function Ss(e, t) {
2475
2490
  return Ge(e) && e.type === t;
2476
2491
  }
2477
- function L(e, t) {
2492
+ function $(e, t) {
2478
2493
  let s, n, r;
2479
2494
  return typeof e == "string" ? s = e : (s = e.pathname === void 0 ? t : e.pathname, n = e.params, r = e.id), Object.freeze({
2480
2495
  id: r || (Math.random() * 2 ** 14 | 0).toString(16),
@@ -2483,12 +2498,12 @@ function L(e, t) {
2483
2498
  });
2484
2499
  }
2485
2500
  class je {
2486
- constructor(t, s, n = R) {
2501
+ constructor(t, s, n = T) {
2487
2502
  /**
2488
2503
  * Navigation history.
2489
2504
  */
2490
2505
  c(this, "history");
2491
- c(this, "ee", new T());
2506
+ c(this, "ee", new R());
2492
2507
  /**
2493
2508
  * True, if current navigator is currently attached.
2494
2509
  */
@@ -2512,7 +2527,7 @@ class je {
2512
2527
  Xt,
2513
2528
  "Index should not be zero and higher or equal than history size."
2514
2529
  );
2515
- this.history = t.map((r) => L(r, ""));
2530
+ this.history = t.map((r) => $(r, ""));
2516
2531
  }
2517
2532
  /**
2518
2533
  * Allows this navigator to control the `BackButton` visibility state. It also tracks the
@@ -2531,7 +2546,7 @@ class je {
2531
2546
  * Prevents current navigator from controlling the BackButton visibility state.
2532
2547
  */
2533
2548
  detach() {
2534
- this.attached = !1, $("back_button_pressed", this.back);
2549
+ this.attached = !1, L("back_button_pressed", this.back);
2535
2550
  }
2536
2551
  /**
2537
2552
  * Goes to the next history item.
@@ -2587,14 +2602,14 @@ class je {
2587
2602
  * @param item - item to add.
2588
2603
  */
2589
2604
  push(t) {
2590
- this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, L(t, this.current.pathname));
2605
+ this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, $(t, this.current.pathname));
2591
2606
  }
2592
2607
  /**
2593
2608
  * Replaces the current history item.
2594
2609
  * @param item - item to replace the current item with.
2595
2610
  */
2596
2611
  replace(t) {
2597
- this.replaceAndMove(this.index, L(t, this.current.pathname));
2612
+ this.replaceAndMove(this.index, $(t, this.current.pathname));
2598
2613
  }
2599
2614
  /**
2600
2615
  * Sets history item by the specified index.
@@ -2670,14 +2685,14 @@ async function ze() {
2670
2685
  for (; t; )
2671
2686
  t = await C(-1);
2672
2687
  }
2673
- function Lt(e) {
2688
+ function $t(e) {
2674
2689
  return k(e).pathname;
2675
2690
  }
2676
2691
  const ot = 0, O = 1, U = 2;
2677
2692
  class Bt {
2678
2693
  constructor(t, s, { postEvent: n, hashMode: r = "classic", base: i } = {}) {
2679
2694
  c(this, "navigator");
2680
- c(this, "ee", new T());
2695
+ c(this, "ee", new R());
2681
2696
  c(this, "hashMode");
2682
2697
  c(this, "base");
2683
2698
  /**
@@ -2720,7 +2735,9 @@ class Bt {
2720
2735
  t.map((o) => W(o, "/")),
2721
2736
  s,
2722
2737
  n
2723
- ), this.navigator.on("change", this.onNavigatorChange), this.hashMode = r, this.base = Lt(i || "");
2738
+ ), this.navigator.on("change", (o) => {
2739
+ this.onNavigatorChange(o);
2740
+ }), this.hashMode = r, this.base = $t(i || "");
2724
2741
  }
2725
2742
  /**
2726
2743
  * Attaches current navigator to the browser history allowing navigator to manipulate it.
@@ -2901,7 +2918,7 @@ function Fe(e) {
2901
2918
  let n = N(
2902
2919
  e.hashMode === null ? t : s.includes("?") ? s.slice(1) : `?${s.slice(1)}`
2903
2920
  );
2904
- const r = e.base ? Lt(e.base) : void 0;
2921
+ const r = e.base ? $t(e.base) : void 0;
2905
2922
  if (r) {
2906
2923
  if (!n.startsWith(r))
2907
2924
  throw f(
@@ -2922,14 +2939,18 @@ function Je(e, t) {
2922
2939
  if (s)
2923
2940
  try {
2924
2941
  const { index: n, history: r } = JSON.parse(s);
2925
- return new Bt(r, n, t);
2942
+ return new Bt(
2943
+ r,
2944
+ n,
2945
+ t
2946
+ );
2926
2947
  } catch (n) {
2927
2948
  console.error("Unable to restore hash navigator state.", n);
2928
2949
  }
2929
2950
  }
2930
2951
  return Fe(t);
2931
2952
  }
2932
- function Ts(e, t) {
2953
+ function Rs(e, t) {
2933
2954
  const s = Je(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
2934
2955
  index: s.index,
2935
2956
  history: s.history
@@ -2955,20 +2976,20 @@ export {
2955
2976
  Yt as ERR_TIMED_OUT,
2956
2977
  Zt as ERR_UNEXPECTED_TYPE,
2957
2978
  Jt as ERR_UNKNOWN_ENV,
2958
- T as EventEmitter,
2979
+ R as EventEmitter,
2959
2980
  Ie as HapticFeedback,
2960
2981
  qe as InitData,
2961
2982
  ke as Invoice,
2962
2983
  Ne as MainButton,
2963
2984
  Me as MiniApp,
2964
- Le as Popup,
2985
+ $e as Popup,
2965
2986
  Be as QRScanner,
2966
2987
  D as SDKError,
2967
2988
  We as SettingsButton,
2968
2989
  Oe as ThemeParams,
2969
2990
  Ue as Utils,
2970
2991
  He as Viewport,
2971
- Re as array,
2992
+ Te as array,
2972
2993
  bs as bindMiniAppCSSVars,
2973
2994
  ms as bindThemeParamsCSSVars,
2974
2995
  ys as bindViewportCSSVars,
@@ -2981,7 +3002,7 @@ export {
2981
3002
  k as createSafeURL,
2982
3003
  Pt as date,
2983
3004
  Cs as getHash,
2984
- Lt as getPathname,
3005
+ $t as getPathname,
2985
3006
  es as initBackButton,
2986
3007
  ss as initBiometryManager,
2987
3008
  ns as initClosingBehavior,
@@ -2991,7 +3012,7 @@ export {
2991
3012
  cs as initInvoice,
2992
3013
  hs as initMainButton,
2993
3014
  ps as initMiniApp,
2994
- Ts as initNavigator,
3015
+ Rs as initNavigator,
2995
3016
  us as initPopup,
2996
3017
  ls as initQRScanner,
2997
3018
  ds as initSettingsButton,
@@ -3013,16 +3034,16 @@ export {
3013
3034
  ts as mergeClassNames,
3014
3035
  xs as mockTelegramEnv,
3015
3036
  y as number,
3016
- $ as off,
3037
+ L as off,
3017
3038
  w as on,
3018
3039
  as as parseInitData,
3019
3040
  tt as parseLaunchParams,
3020
3041
  Mt as parseThemeParams,
3021
- R as postEvent,
3042
+ T as postEvent,
3022
3043
  _ as request,
3023
3044
  xe as requestBiometryInfo,
3024
3045
  fs as requestThemeParams,
3025
- $t as requestViewport,
3046
+ Lt as requestViewport,
3026
3047
  ye as retrieveLaunchParams,
3027
3048
  lt as rgb,
3028
3049
  X as searchParams,