@tma.js/sdk-solid 2.1.6 → 2.1.7

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
@@ -8,11 +8,11 @@ function vt(e, t) {
8
8
  return [() => s === void 0 ? s = e(n) : s, n];
9
9
  }
10
10
  function yt(e) {
11
- const t = H(), { count: s } = t;
11
+ const t = U(), { count: s } = t;
12
12
  t.unsubscribe(e), s && !t.count && Se();
13
13
  }
14
14
  function ae(e) {
15
- return H().subscribe(e), () => yt(e);
15
+ return U().subscribe(e), () => yt(e);
16
16
  }
17
17
  class ce {
18
18
  constructor(t, s = {}) {
@@ -190,10 +190,10 @@ class L {
190
190
  return this.isOptional = !0, this;
191
191
  }
192
192
  }
193
- function T(e, t) {
193
+ function R(e, t) {
194
194
  return () => new L(e, !1, t);
195
195
  }
196
- const y = T((e) => {
196
+ const y = R((e) => {
197
197
  if (typeof e == "boolean")
198
198
  return e;
199
199
  const t = String(e);
@@ -237,7 +237,7 @@ function f(e, t) {
237
237
  return Pt(e, (r) => n[r]);
238
238
  }, !1, t);
239
239
  }
240
- const P = T((e) => {
240
+ const P = R((e) => {
241
241
  if (typeof e == "number")
242
242
  return e;
243
243
  if (typeof e == "string") {
@@ -271,11 +271,11 @@ function xt(e) {
271
271
  return n + (i.length === 1 ? "0" : "") + i;
272
272
  }, "#");
273
273
  }
274
- const p = T((e) => {
274
+ const p = R((e) => {
275
275
  if (typeof e == "string" || typeof e == "number")
276
276
  return e.toString();
277
277
  throw S();
278
- }, "string"), Ct = T((e) => xt(p().parse(e)), "rgb");
278
+ }, "string"), Ct = R((e) => xt(p().parse(e)), "rgb");
279
279
  function St(e) {
280
280
  return f({
281
281
  eventType: p(),
@@ -419,19 +419,19 @@ const [Ce, Se] = vt(
419
419
  },
420
420
  ([, e]) => e()
421
421
  );
422
- function H() {
422
+ function U() {
423
423
  return Ce()[0];
424
424
  }
425
- function U(e, t) {
426
- H().off(e, t);
425
+ function H(e, t) {
426
+ U().off(e, t);
427
427
  }
428
428
  function v(e, t, s) {
429
- return H().on(e, t, s);
429
+ return U().on(e, t, s);
430
430
  }
431
431
  function N(e) {
432
432
  return typeof e == "object" && e !== null && !Array.isArray(e);
433
433
  }
434
- function Te(e, t) {
434
+ function Re(e, t) {
435
435
  const s = e.split("."), n = t.split("."), r = Math.max(s.length, n.length);
436
436
  for (let i = 0; i < r; i += 1) {
437
437
  const o = parseInt(s[i] || "0", 10), a = parseInt(n[i] || "0", 10);
@@ -441,7 +441,7 @@ function Te(e, t) {
441
441
  return 0;
442
442
  }
443
443
  function b(e, t) {
444
- return Te(e, t) <= 0;
444
+ return Re(e, t) <= 0;
445
445
  }
446
446
  function x(e, t, s) {
447
447
  if (typeof s == "string") {
@@ -494,10 +494,10 @@ function x(e, t, s) {
494
494
  ].includes(e);
495
495
  }
496
496
  }
497
- function Tt(e) {
497
+ function Rt(e) {
498
498
  return "external" in e && N(e.external) && "notify" in e.external && typeof e.external.notify == "function";
499
499
  }
500
- function Rt(e) {
500
+ function Tt(e) {
501
501
  return "TelegramWebviewProxy" in e && N(e.TelegramWebviewProxy) && "postEvent" in e.TelegramWebviewProxy && typeof e.TelegramWebviewProxy.postEvent == "function";
502
502
  }
503
503
  function nt() {
@@ -511,22 +511,22 @@ let At = "https://web.telegram.org";
511
511
  function Fs(e) {
512
512
  At = e;
513
513
  }
514
- function Re() {
514
+ function Te() {
515
515
  return At;
516
516
  }
517
517
  function q(e, t, s) {
518
518
  let n = {}, r;
519
519
  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);
520
- const { targetOrigin: i = Re() } = n;
520
+ const { targetOrigin: i = Te() } = n;
521
521
  if (pe("Posting event:", r ? { event: e, data: r } : { event: e }), nt()) {
522
522
  window.parent.postMessage(JSON.stringify({ eventType: e, eventData: r }), i);
523
523
  return;
524
524
  }
525
- if (Tt(window)) {
525
+ if (Rt(window)) {
526
526
  window.external.notify(JSON.stringify({ eventType: e, eventData: r }));
527
527
  return;
528
528
  }
529
- if (Rt(window)) {
529
+ if (Tt(window)) {
530
530
  window.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
531
531
  return;
532
532
  }
@@ -664,7 +664,7 @@ class ke extends it {
664
664
  super({ isVisible: t }, s, {
665
665
  show: "web_app_setup_back_button",
666
666
  hide: "web_app_setup_back_button"
667
- }), c(this, "on", (r, i) => r === "click" ? v("back_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? U("back_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
667
+ }), c(this, "on", (r, i) => r === "click" ? v("back_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? H("back_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
668
668
  }
669
669
  set isVisible(t) {
670
670
  this.set("isVisible", t), this.postEvent("web_app_setup_back_button", { is_visible: t });
@@ -688,7 +688,7 @@ class ke extends it {
688
688
  this.isVisible = !0;
689
689
  }
690
690
  }
691
- const Dt = T((e) => e instanceof Date ? e : new Date(P().parse(e) * 1e3), "Date");
691
+ const Dt = R((e) => e instanceof Date ? e : new Date(P().parse(e) * 1e3), "Date");
692
692
  function ot(e, t) {
693
693
  return new L((s) => {
694
694
  if (typeof s != "string" && !(s instanceof URLSearchParams))
@@ -783,7 +783,7 @@ function Oe(e) {
783
783
  function Ne(e) {
784
784
  return e.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
785
785
  }
786
- const Mt = T(
786
+ const Mt = R(
787
787
  (e) => {
788
788
  const t = Ct().optional();
789
789
  return Object.entries(et(e)).reduce((s, [n, r]) => (s[Oe(n)] = t.parse(r), s), {});
@@ -846,10 +846,10 @@ function Ve() {
846
846
  function Lt(e) {
847
847
  return `tma.js/${e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`)}`;
848
848
  }
849
- function Ht(e, t) {
849
+ function Ut(e, t) {
850
850
  sessionStorage.setItem(Lt(e), JSON.stringify(t));
851
851
  }
852
- function Ut(e) {
852
+ function Ht(e) {
853
853
  const t = sessionStorage.getItem(Lt(e));
854
854
  try {
855
855
  return t ? JSON.parse(t) : void 0;
@@ -857,7 +857,7 @@ function Ut(e) {
857
857
  }
858
858
  }
859
859
  function Me() {
860
- return at(Ut("launchParams") || "");
860
+ return at(Ht("launchParams") || "");
861
861
  }
862
862
  function Wt(e) {
863
863
  return JSON.stringify(
@@ -879,7 +879,7 @@ function Be(e) {
879
879
  return h.set("tgWebAppPlatform", n), h.set("tgWebAppThemeParams", Wt(s)), h.set("tgWebAppVersion", r), t && h.set("tgWebAppData", t), o && h.set("tgWebAppStartParam", o), typeof i == "boolean" && h.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && h.set("tgWebAppBotInline", a ? "1" : "0"), h.toString();
880
880
  }
881
881
  function jt(e) {
882
- Ht("launchParams", Be(e));
882
+ Ut("launchParams", Be(e));
883
883
  }
884
884
  function $e() {
885
885
  for (const e of [
@@ -906,13 +906,13 @@ function Le() {
906
906
  let e = 0;
907
907
  return () => (e += 1).toString();
908
908
  }
909
- const [He] = vt(Le);
909
+ const [Ue] = vt(Le);
910
910
  function l(e, t) {
911
911
  return () => {
912
912
  const s = $e(), n = {
913
913
  ...s,
914
914
  postEvent: Ae(s.version),
915
- createRequestId: He()
915
+ createRequestId: Ue()
916
916
  };
917
917
  if (typeof e == "function")
918
918
  return e(n);
@@ -921,11 +921,11 @@ function l(e, t) {
921
921
  // State should only be passed only in case, current page was reloaded. If we don't add
922
922
  // this check, state restoration will work improperly in the web version of Telegram,
923
923
  // when we are always working in the same "session" (tab).
924
- state: Gt() ? Ut(e) : void 0,
924
+ state: Gt() ? Ht(e) : void 0,
925
925
  addCleanup: r
926
926
  }), h = (u) => (o || r(
927
927
  u.on("change", (d) => {
928
- Ht(e, d);
928
+ Ut(e, d);
929
929
  })
930
930
  ), u);
931
931
  return [
@@ -934,7 +934,7 @@ function l(e, t) {
934
934
  ];
935
935
  };
936
936
  }
937
- const Ue = l("backButton", ({
937
+ const He = l("backButton", ({
938
938
  postEvent: e,
939
939
  version: t,
940
940
  state: s = { isVisible: !1 }
@@ -1415,7 +1415,7 @@ const rs = l(
1415
1415
  );
1416
1416
  class is extends rt {
1417
1417
  constructor({ postEvent: t, ...s }) {
1418
- super(s), c(this, "postEvent"), c(this, "on", (n, r) => n === "click" ? v("main_button_pressed", r) : this.state.on(n, r)), c(this, "off", (n, r) => n === "click" ? U("main_button_pressed", r) : this.state.off(n, r)), this.postEvent = t;
1418
+ super(s), c(this, "postEvent"), c(this, "on", (n, r) => n === "click" ? v("main_button_pressed", r) : this.state.on(n, r)), c(this, "off", (n, r) => n === "click" ? H("main_button_pressed", r) : this.state.off(n, r)), this.postEvent = t;
1419
1419
  }
1420
1420
  /**
1421
1421
  * The MainButton background color.
@@ -1909,7 +1909,7 @@ class fs extends it {
1909
1909
  super({ isVisible: t }, s, {
1910
1910
  show: "web_app_setup_settings_button",
1911
1911
  hide: "web_app_setup_settings_button"
1912
- }), c(this, "on", (r, i) => r === "click" ? v("settings_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? U("settings_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
1912
+ }), c(this, "on", (r, i) => r === "click" ? v("settings_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? H("settings_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
1913
1913
  }
1914
1914
  set isVisible(t) {
1915
1915
  this.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
@@ -2069,7 +2069,7 @@ class vs extends ht {
2069
2069
  * @throws {Error} URL has not allowed hostname.
2070
2070
  */
2071
2071
  openTelegramLink(t) {
2072
- const { hostname: s, pathname: n, search: r } = new URL(t, window.location.href);
2072
+ const { hostname: s, pathname: n, search: r } = new URL(t, "https://t.me");
2073
2073
  if (s !== "t.me")
2074
2074
  throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);
2075
2075
  if (!x("web_app_open_tg_link", this.version)) {
@@ -2096,6 +2096,20 @@ class vs extends ht {
2096
2096
  });
2097
2097
  return s;
2098
2098
  }
2099
+ /**
2100
+ * Shares specified URL with the passed to the chats, selected by user. After being called,
2101
+ * it closes the mini application.
2102
+ *
2103
+ * This method uses Telegram's Share Links.
2104
+ * @param url - URL to share.
2105
+ * @param text - text to append after the URL.
2106
+ * @see https://core.telegram.org/api/links#share-links
2107
+ */
2108
+ shareURL(t, s) {
2109
+ this.openTelegramLink(
2110
+ "https://t.me/share?" + new URLSearchParams({ url: t, text: s || "" }).toString()
2111
+ );
2112
+ }
2099
2113
  }
2100
2114
  const ys = l(
2101
2115
  ({ version: e, postEvent: t, createRequestId: s }) => new vs(e, s, t)
@@ -2112,16 +2126,16 @@ async function Ft(e = {}) {
2112
2126
  });
2113
2127
  return { ...n, isExpanded: t, isStateStable: s };
2114
2128
  }
2115
- function R(e) {
2129
+ function T(e) {
2116
2130
  return e < 0 ? 0 : e;
2117
2131
  }
2118
2132
  class Es extends ct {
2119
2133
  constructor({ postEvent: t, stableHeight: s, height: n, width: r, isExpanded: i }) {
2120
2134
  super({
2121
- height: R(n),
2135
+ height: T(n),
2122
2136
  isExpanded: i,
2123
- stableHeight: R(s),
2124
- width: R(r)
2137
+ stableHeight: T(s),
2138
+ width: T(r)
2125
2139
  }), c(this, "postEvent"), this.postEvent = t;
2126
2140
  }
2127
2141
  /**
@@ -2183,11 +2197,11 @@ class Es extends ct {
2183
2197
  width: n,
2184
2198
  is_expanded: r,
2185
2199
  is_state_stable: i
2186
- } = t, o = R(s);
2200
+ } = t, o = T(s);
2187
2201
  this.set({
2188
2202
  height: o,
2189
2203
  isExpanded: r,
2190
- width: R(n),
2204
+ width: T(n),
2191
2205
  ...i ? { stableHeight: o } : {}
2192
2206
  });
2193
2207
  });
@@ -2307,7 +2321,7 @@ function sn() {
2307
2321
  return typeof window > "u";
2308
2322
  }
2309
2323
  async function nn() {
2310
- if (Rt(window))
2324
+ if (Tt(window))
2311
2325
  return !0;
2312
2326
  try {
2313
2327
  return await w({ method: "web_app_request_theme", event: "theme_changed", timeout: 100 }), !0;
@@ -2340,7 +2354,7 @@ function rn(e) {
2340
2354
  };
2341
2355
  return;
2342
2356
  }
2343
- if (Tt(window)) {
2357
+ if (Rt(window)) {
2344
2358
  const r = window.external.notify.bind(window.external);
2345
2359
  window.external.notify = (i) => {
2346
2360
  s(i), r(i);
@@ -2397,7 +2411,7 @@ class Ss {
2397
2411
  * Prevents current navigator from controlling the BackButton visibility state.
2398
2412
  */
2399
2413
  detach() {
2400
- this.attached = !1, U("back_button_pressed", this.back);
2414
+ this.attached = !1, H("back_button_pressed", this.back);
2401
2415
  }
2402
2416
  /**
2403
2417
  * Goes to the next history item.
@@ -2529,7 +2543,7 @@ async function I(e) {
2529
2543
  })
2530
2544
  ]);
2531
2545
  }
2532
- async function Ts() {
2546
+ async function Rs() {
2533
2547
  if (window.history.length <= 1 || (window.history.pushState(null, ""), await I(1 - window.history.length)))
2534
2548
  return;
2535
2549
  let e = await I(-1);
@@ -2561,7 +2575,9 @@ class Yt {
2561
2575
  t.map((o) => K(o, "/")),
2562
2576
  s,
2563
2577
  n
2564
- ), this.navigator.on("change", this.onNavigatorChange), this.hashMode = r, this.base = Qt(i || "");
2578
+ ), this.navigator.on("change", (o) => {
2579
+ this.onNavigatorChange(o);
2580
+ }), this.hashMode = r, this.base = Qt(i || "");
2565
2581
  }
2566
2582
  /**
2567
2583
  * Attaches current navigator to the browser history allowing navigator to manipulate it.
@@ -2718,7 +2734,7 @@ class Yt {
2718
2734
  async syncHistory() {
2719
2735
  window.removeEventListener("popstate", this.onPopState);
2720
2736
  const { state: t } = this, s = this.renderPath(this);
2721
- await Ts(), this.hasPrev && this.hasNext ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s), window.history.pushState(J, ""), await I(-1)) : this.hasPrev ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s)) : this.hasNext ? (window.history.replaceState(t, s), window.history.pushState(J, ""), await I(-1)) : (window.history.replaceState(mt, ""), window.history.pushState(t, "", s)), window.addEventListener("popstate", this.onPopState);
2737
+ await Rs(), this.hasPrev && this.hasNext ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s), window.history.pushState(J, ""), await I(-1)) : this.hasPrev ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s)) : this.hasNext ? (window.history.replaceState(t, s), window.history.pushState(J, ""), await I(-1)) : (window.history.replaceState(mt, ""), window.history.pushState(t, "", s)), window.addEventListener("popstate", this.onPopState);
2722
2738
  }
2723
2739
  /**
2724
2740
  * Current query parameters.
@@ -2736,7 +2752,7 @@ class Yt {
2736
2752
  return (this.navigator.current.params || {}).state;
2737
2753
  }
2738
2754
  }
2739
- function Rs(e) {
2755
+ function Ts(e) {
2740
2756
  e || (e = {});
2741
2757
  const { href: t, hash: s } = window.location;
2742
2758
  let n = B(
@@ -2763,12 +2779,16 @@ function As(e, t) {
2763
2779
  if (s)
2764
2780
  try {
2765
2781
  const { index: n, history: r } = JSON.parse(s);
2766
- return new Yt(r, n, t);
2782
+ return new Yt(
2783
+ r,
2784
+ n,
2785
+ t
2786
+ );
2767
2787
  } catch (n) {
2768
2788
  console.error("Unable to restore hash navigator state.", n);
2769
2789
  }
2770
2790
  }
2771
- return Rs(t);
2791
+ return Ts(t);
2772
2792
  }
2773
2793
  function cn(e, t) {
2774
2794
  const s = As(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
@@ -2795,7 +2815,7 @@ function g(e) {
2795
2815
  return Object.defineProperty(n, "error", () => s.error), n;
2796
2816
  };
2797
2817
  }
2798
- const ks = g(Ue), hn = _(ks), qs = g(Ge), pn = _(qs), Os = g(ze), un = _(Os), Ns = g(Ze), dn = _(Ns), Ds = g(ts), ln = _(Ds), Vs = g(ss), _n = _(Vs), Ms = g(rs), gn = _(Ms), Bs = g(os), fn = _(Bs), $s = g(ps), wn = _($s), Ls = g(ls), mn = _(Ls), Hs = g(gs), bn = _(Hs), Us = g(ws), vn = _(Us), Ws = g(bs), yn = _(Ws), js = g(ys), En = _(js), Gs = g(Ps), Pn = _(Gs), xn = (e) => {
2818
+ const ks = g(He), hn = _(ks), qs = g(Ge), pn = _(qs), Os = g(ze), un = _(Os), Ns = g(Ze), dn = _(Ns), Ds = g(ts), ln = _(Ds), Vs = g(ss), _n = _(Vs), Ms = g(rs), gn = _(Ms), Bs = g(os), fn = _(Bs), $s = g(ps), wn = _($s), Ls = g(ls), mn = _(Ls), Us = g(gs), bn = _(Us), Hs = g(ws), vn = _(Hs), Ws = g(bs), yn = _(Ws), js = g(ys), En = _(js), Gs = g(Ps), Pn = _(Gs), xn = (e) => {
2799
2819
  const t = /* @__PURE__ */ new Map(), s = (n, ...r) => {
2800
2820
  if (t.has(n))
2801
2821
  return t.get(n);
@@ -2897,14 +2917,14 @@ export {
2897
2917
  y as boolean,
2898
2918
  It as captureSameReq,
2899
2919
  Z as classNames,
2900
- Te as compareVersions,
2901
- Rs as createBrowserNavigatorFromLocation,
2920
+ Re as compareVersions,
2921
+ Ts as createBrowserNavigatorFromLocation,
2902
2922
  Ae as createPostEvent,
2903
2923
  M as createSafeURL,
2904
2924
  Dt as date,
2905
2925
  an as getHash,
2906
2926
  Qt as getPathname,
2907
- Ue as initBackButton,
2927
+ He as initBackButton,
2908
2928
  Ge as initBiometryManager,
2909
2929
  ze as initClosingBehavior,
2910
2930
  Ze as initCloudStorage,
@@ -2935,7 +2955,7 @@ export {
2935
2955
  Qs as mergeClassNames,
2936
2956
  rn as mockTelegramEnv,
2937
2957
  P as number,
2938
- U as off,
2958
+ H as off,
2939
2959
  v as on,
2940
2960
  Ys as parseInitData,
2941
2961
  at as parseLaunchParams,
@@ -2956,7 +2976,7 @@ export {
2956
2976
  p as string,
2957
2977
  ae as subscribe,
2958
2978
  x as supports,
2959
- Re as targetOrigin,
2979
+ Te as targetOrigin,
2960
2980
  xt as toRGB,
2961
2981
  yt as unsubscribe,
2962
2982
  B as urlToPath,
@@ -2970,9 +2990,9 @@ export {
2970
2990
  Bs as useMainButton,
2971
2991
  $s as useMiniApp,
2972
2992
  Ls as usePopup,
2973
- Hs as useQRScanner,
2993
+ Us as useQRScanner,
2974
2994
  Is as useSDK,
2975
- Us as useSettingsButton,
2995
+ Hs as useSettingsButton,
2976
2996
  Ws as useThemeParams,
2977
2997
  js as useUtils,
2978
2998
  Gs as useViewport,