@tma.js/sdk 3.0.5 → 3.0.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
@@ -134,10 +134,10 @@ function Pt(s) {
134
134
  var V = me, I = be, as = /* @__PURE__ */ lt(2, function(s, e) {
135
135
  return rt(s) ? s : e(s.right);
136
136
  }), Ot = function(s, e) {
137
- return c(s, D(e));
137
+ return c(s, P(e));
138
138
  }, ge = function(s, e) {
139
139
  return c(s, ps(e));
140
- }, Dt = "Either", D = function(s) {
140
+ }, Dt = "Either", P = function(s) {
141
141
  return function(e) {
142
142
  return rt(e) ? e : I(s(e.right));
143
143
  };
@@ -172,11 +172,11 @@ var V = me, I = be, as = /* @__PURE__ */ lt(2, function(s, e) {
172
172
  return V(e(r));
173
173
  }
174
174
  }, ms = /* @__PURE__ */ cs(Rt), bs = /* @__PURE__ */ Pt(ds), ie = bs;
175
- function P(s) {
175
+ function O(s) {
176
176
  return typeof s == "function" ? s() : s;
177
177
  }
178
178
  function z(s, e) {
179
- return w(() => ot(s, P(e)));
179
+ return w(() => ot(s, O(e)));
180
180
  }
181
181
  var it = ss, ht = rs, gs = function(s, e) {
182
182
  return c(s, Cs(e));
@@ -460,7 +460,7 @@ class rr extends K(
460
460
  ) {
461
461
  }
462
462
  function A(s, e) {
463
- const r = w(() => P(e.version) || "100"), n = w(() => P(e.isTma)), { requires: i, returns: o } = e, u = i ? typeof i == "object" ? i : { every: [i] } : void 0, a = (f) => {
463
+ const r = w(() => O(e.version) || "100"), n = w(() => O(e.isTma)), { requires: i, returns: o } = e, u = i ? typeof i == "object" ? i : { every: [i] } : void 0, a = (f) => {
464
464
  if (!e.supports)
465
465
  return !0;
466
466
  const b = e.supports[f];
@@ -602,8 +602,8 @@ class dt {
602
602
  this.mount = () => {
603
603
  if (this.isMounted())
604
604
  return I(void 0);
605
- const u = P(o) ? r() : void 0, a = u ? I(u) : typeof n == "function" ? n() : I(n);
606
- return c(a, D((p) => {
605
+ const u = O(o) ? r() : void 0, a = u ? I(u) : typeof n == "function" ? n() : I(n);
606
+ return c(a, P((p) => {
607
607
  Ct(() => {
608
608
  this._isMounted.set(!0), e == null || e(p);
609
609
  });
@@ -729,7 +729,7 @@ class kt {
729
729
  const b = { ...this.state(), ...Mt(f) };
730
730
  return _.hasDiff(b) ? c(
731
731
  a(l, p(b)),
732
- D(() => {
732
+ P(() => {
733
733
  _.setState(b);
734
734
  })
735
735
  ) : I(void 0);
@@ -867,7 +867,7 @@ function ar() {
867
867
  return !!s && s.type === "reload";
868
868
  }
869
869
  function ft(s) {
870
- return (e) => ({ ...e, ...P(s) });
870
+ return (e) => ({ ...e, ...O(s) });
871
871
  }
872
872
  function et(s) {
873
873
  return ft({
@@ -924,7 +924,7 @@ class Jt {
924
924
  this.mount = (u) => {
925
925
  if (this._isMounted())
926
926
  return q(void 0);
927
- const a = P(o) ? n() : void 0;
927
+ const a = O(o) ? n() : void 0;
928
928
  return c(
929
929
  a ? q(a) : e(u),
930
930
  B((p) => {
@@ -1111,14 +1111,14 @@ class cr {
1111
1111
  const Ee = (s, e, r) => Oe(s, e, {
1112
1112
  postEvent: mt,
1113
1113
  ...r
1114
- }), kn = (...s) => Ke.fn(() => Ee(...s)()), U = ft({
1114
+ }), kn = (...s) => Ke.fn(() => Ee(...s)()), G = ft({
1115
1115
  request: Ee
1116
1116
  }), En = new cr({
1117
1117
  ...c(
1118
1118
  F(),
1119
1119
  L,
1120
1120
  v,
1121
- U,
1121
+ G,
1122
1122
  et("biometry")
1123
1123
  ),
1124
1124
  offInfoReceived(s) {
@@ -1328,7 +1328,7 @@ function dr({ request: s, ...e }) {
1328
1328
  const fr = dr(c(
1329
1329
  F(),
1330
1330
  v,
1331
- U
1331
+ G
1332
1332
  )), xn = h(fr);
1333
1333
  function _r({ request: s, ...e }) {
1334
1334
  return A((r, n) => c(
@@ -1348,7 +1348,7 @@ function _r({ request: s, ...e }) {
1348
1348
  }
1349
1349
  const mr = _r(c(
1350
1350
  F(),
1351
- U,
1351
+ G,
1352
1352
  v
1353
1353
  )), Bn = h(mr);
1354
1354
  class br {
@@ -1424,7 +1424,7 @@ function Fr({ request: s, ...e }) {
1424
1424
  const Cr = Fr(c(
1425
1425
  F(),
1426
1426
  v,
1427
- U
1427
+ G
1428
1428
  )), Vn = h(Cr);
1429
1429
  class Sr {
1430
1430
  constructor({ retrieveInitData: e }) {
@@ -1500,7 +1500,7 @@ class Sr {
1500
1500
  t(this, "restore");
1501
1501
  this.restoreFp = () => c(
1502
1502
  e(),
1503
- D(Fe(() => {
1503
+ P(Fe(() => {
1504
1504
  }, ({ raw: r, obj: n }) => {
1505
1505
  this._state.set(n), this._raw.set(r);
1506
1506
  }))
@@ -1519,10 +1519,10 @@ const Tn = new Sr({
1519
1519
  ms,
1520
1520
  ie("obj", () => c(
1521
1521
  St(),
1522
- D(({ tgWebAppData: s }) => s ? ht(s) : it)
1522
+ P(({ tgWebAppData: s }) => s ? ht(s) : it)
1523
1523
  )),
1524
1524
  ie("raw", Ue),
1525
- D(({ obj: s, raw: e }) => c(
1525
+ P(({ obj: s, raw: e }) => c(
1526
1526
  As,
1527
1527
  ae("obj", () => s),
1528
1528
  ae("raw", () => e)
@@ -1593,7 +1593,7 @@ class vr {
1593
1593
  }), this.openUrl = h(this.openUrlFp), this.openSlug = h(this.openSlugFp);
1594
1594
  }
1595
1595
  }
1596
- const $n = new vr(c(F(), U, v));
1596
+ const $n = new vr(c(F(), G, v));
1597
1597
  function yr({ postEvent: s, ...e }) {
1598
1598
  return A((r, n = {}) => {
1599
1599
  if (typeof r == "string")
@@ -1616,7 +1616,7 @@ const kr = yr(c(
1616
1616
  function Er({ postEvent: s, version: e, ...r }) {
1617
1617
  return A((n) => {
1618
1618
  const i = n.toString();
1619
- return i.match(/^https:\/\/t.me\/.+/) ? ot("web_app_open_tg_link", P(e)) ? (n = new URL(n), s("web_app_open_tg_link", { path_full: n.pathname + n.search })) : (window.location.href = i, I(void 0)) : V(new Q(`"${i}" is invalid URL`));
1619
+ return i.match(/^https:\/\/t.me\/.+/) ? ot("web_app_open_tg_link", O(e)) ? (n = new URL(n), s("web_app_open_tg_link", { path_full: n.pathname + n.search })) : (window.location.href = i, I(void 0)) : V(new Q(`"${i}" is invalid URL`));
1620
1620
  }, { ...r, returns: "either" });
1621
1621
  }
1622
1622
  const Ie = Er(c(
@@ -1753,7 +1753,7 @@ const On = new Br(c(
1753
1753
  F(),
1754
1754
  L,
1755
1755
  v,
1756
- U,
1756
+ G,
1757
1757
  et("locationManager")
1758
1758
  ));
1759
1759
  class qr {
@@ -1967,7 +1967,7 @@ class qr {
1967
1967
  })
1968
1968
  }), i = (o, u) => {
1969
1969
  const a = n.stateGetter(o);
1970
- return w(() => a() || P(u));
1970
+ return w(() => a() || O(u));
1971
1971
  };
1972
1972
  this.bgColor = i("bgColor", e.bgColor), this.textColor = i("textColor", e.textColor), this.hasShineEffect = n.stateGetter("hasShineEffect"), this.isEnabled = n.stateGetter("isEnabled"), this.isLoaderVisible = n.stateGetter("isLoaderVisible"), this.text = n.stateGetter("text"), this.isVisible = n.stateGetter("isVisible"), this.isMounted = n.isMounted, this.state = n.state, [this.setBgColor, this.setBgColorFp] = n.stateSetters("bgColor"), [this.setTextColor, this.setTextColorFp] = n.stateSetters("textColor"), [
1973
1973
  [this.disableShineEffect, this.disableShineEffectFp],
@@ -1998,7 +1998,7 @@ function Xt(s) {
1998
1998
  function Mr(s) {
1999
1999
  return c(
2000
2000
  Qe(s),
2001
- D((e) => Math.sqrt(
2001
+ P((e) => Math.sqrt(
2002
2002
  [0.299, 0.587, 0.114].reduce((r, n, i) => {
2003
2003
  const o = parseInt(e.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
2004
2004
  return r + o * o * n;
@@ -2122,7 +2122,7 @@ class Vr {
2122
2122
  }), p = (C) => {
2123
2123
  a.setState(C.theme_params);
2124
2124
  }, l = new dt({
2125
- initialState: () => I(P(e)),
2125
+ initialState: () => I(O(e)),
2126
2126
  isPageReload: u,
2127
2127
  onMounted(C) {
2128
2128
  a.setState(C), r(p);
@@ -2361,9 +2361,9 @@ class Tr {
2361
2361
  [this.bottomBarColor, "web_app_set_bottom_bar_color"]
2362
2362
  ].forEach(([x, R]) => {
2363
2363
  const T = x();
2364
- if (!Et(T) && (R === "web_app_set_header_color" || !["bg_color", "secondary_bg_color"].includes(T))) {
2365
- const O = d[T];
2366
- O && i(R, { color: O });
2364
+ if (!Et(T) && (R !== "web_app_set_header_color" || !["bg_color", "secondary_bg_color"].includes(T))) {
2365
+ const D = d[T];
2366
+ D && i(R, { color: D });
2367
2367
  }
2368
2368
  });
2369
2369
  }, _ = new dt({
@@ -2399,41 +2399,46 @@ class Tr {
2399
2399
  onChange: e.set
2400
2400
  });
2401
2401
  this.state = g.state;
2402
- const C = (d) => Et(d) ? d : P(u)[d], y = (d) => w(() => C(d()));
2402
+ const C = (d) => Et(d) ? d : O(u)[d], y = (d) => w(() => C(d()));
2403
2403
  this.isActive = g.getter("isActive"), this.isSupported = w(() => [
2404
2404
  "web_app_set_header_color",
2405
2405
  "web_app_set_background_color",
2406
2406
  "web_app_set_bottom_bar_color"
2407
- ].some((d) => ot(d, P(n))));
2407
+ ].some((d) => ot(d, O(n))));
2408
2408
  const S = j(!1);
2409
2409
  this.isCssVarsBound = w(S), this.bindCssVarsFp = A((d) => {
2410
2410
  if (S())
2411
2411
  return V(new Qt());
2412
2412
  const [x, R] = Lt(() => {
2413
2413
  S.set(!1);
2414
- }), T = (O, G) => {
2414
+ }), T = (D, U) => {
2415
2415
  const H = () => {
2416
- Zt(O, G() || null);
2416
+ Zt(D, U() || null);
2417
2417
  };
2418
- H(), x(G.sub(H), Xt.bind(null, O));
2418
+ H(), x(U.sub(H), Xt.bind(null, D));
2419
2419
  };
2420
- return d || (d = (O) => `--tg-${le(O)}`), T(d("bgColor"), this.bgColorRgb), T(d("bottomBarColor"), this.bottomBarColorRgb), T(d("headerColor"), this.headerColorRgb), S.set(!0), I(R);
2420
+ return d || (d = (D) => `--tg-${le(D)}`), T(d("bgColor"), this.bgColorRgb), T(d("bottomBarColor"), this.bottomBarColorRgb), T(d("headerColor"), this.headerColorRgb), S.set(!0), I(R);
2421
2421
  }, { isTma: o, returns: "either", isMounted: this.isMounted }), this.bindCssVars = h(this.bindCssVarsFp);
2422
2422
  const f = (d) => {
2423
2423
  const x = g.getter(d), R = y(x), T = {
2424
2424
  headerColor: "web_app_set_header_color",
2425
2425
  bgColor: "web_app_set_background_color",
2426
2426
  bottomBarColor: "web_app_set_bottom_bar_color"
2427
- }[d], O = A(
2428
- (G) => {
2429
- if (G === x())
2427
+ }[d], D = A(
2428
+ (U) => {
2429
+ if (U === x())
2430
2430
  return I(void 0);
2431
- if (T === "web_app_set_header_color" && (G === "bg_color" || G === "secondary_bg_color"))
2432
- return i("web_app_set_header_color", { color_key: G });
2433
- const H = C(G);
2431
+ if (T === "web_app_set_header_color" && (U === "bg_color" || U === "secondary_bg_color"))
2432
+ return c(
2433
+ i("web_app_set_header_color", { color_key: U }),
2434
+ P(() => {
2435
+ g.setState({ [d]: U });
2436
+ })
2437
+ );
2438
+ const H = C(U);
2434
2439
  return c(
2435
- H ? i(T, { color: H }) : V(new rr(G)),
2436
- D(() => {
2440
+ H ? i(T, { color: H }) : V(new rr(U)),
2441
+ P(() => {
2437
2442
  g.setState({ [d]: H });
2438
2443
  })
2439
2444
  );
@@ -2453,7 +2458,7 @@ class Tr {
2453
2458
  } : void 0
2454
2459
  }
2455
2460
  );
2456
- return [x, R, h(O), O];
2461
+ return [x, R, h(D), D];
2457
2462
  };
2458
2463
  [
2459
2464
  this.bgColor,
@@ -2579,7 +2584,7 @@ class Rr {
2579
2584
  )), this.show = h(this.showFp);
2580
2585
  }
2581
2586
  }
2582
- const Un = new Rr(c(F(), U, v));
2587
+ const Un = new Rr(c(F(), G, v));
2583
2588
  function Pr({ request: s, ...e }) {
2584
2589
  return A((r) => c(
2585
2590
  s("web_app_request_phone", "phone_requested", r),
@@ -2589,7 +2594,7 @@ function Pr({ request: s, ...e }) {
2589
2594
  const qe = Pr(c(
2590
2595
  F(),
2591
2596
  v,
2592
- U
2597
+ G
2593
2598
  )), Gn = h(qe);
2594
2599
  function Or({
2595
2600
  invokeCustomMethod: s,
@@ -2687,7 +2692,7 @@ function Gr({ request: s, ...e }) {
2687
2692
  const jr = Gr(c(
2688
2693
  F(),
2689
2694
  v,
2690
- U
2695
+ G
2691
2696
  )), Wn = h(jr);
2692
2697
  class Hr {
2693
2698
  constructor({
@@ -2790,7 +2795,7 @@ class Hr {
2790
2795
  }),
2791
2796
  B(() => g)
2792
2797
  );
2793
- }), this.closeFp = a(() => c(o("web_app_close_scan_qr_popup"), D(m))), this.openFp = p((_) => c(
2798
+ }), this.closeFp = a(() => c(o("web_app_close_scan_qr_popup"), P(m))), this.openFp = p((_) => c(
2794
2799
  this.isOpened() ? $(new zt("The QR Scanner is already opened")) : async () => o("web_app_open_scan_qr_popup", { text: _.text }),
2795
2800
  at(() => {
2796
2801
  const [g, C] = Lt(), y = (S) => (C(), S);
@@ -3062,7 +3067,7 @@ class Wr {
3062
3067
  })
3063
3068
  }), i = (o, u) => {
3064
3069
  const a = n.stateGetter(o);
3065
- return w(() => a() || P(u));
3070
+ return w(() => a() || O(u));
3066
3071
  };
3067
3072
  this.isSupported = z("web_app_setup_secondary_button", r.version), this.bgColor = i("bgColor", e.bgColor), this.textColor = i("textColor", e.textColor), this.position = n.stateGetter("position"), this.hasShineEffect = n.stateGetter("hasShineEffect"), this.isEnabled = n.stateGetter("isEnabled"), this.isLoaderVisible = n.stateGetter("isLoaderVisible"), this.text = n.stateGetter("text"), this.isVisible = n.stateGetter("isVisible"), this.isMounted = n.isMounted, this.state = n.state, [this.setPosition, this.setPositionFp] = n.stateSetters("position"), [this.setBgColor, this.setBgColorFp] = n.stateSetters("bgColor"), [this.setTextColor, this.setTextColorFp] = n.stateSetters("textColor"), [
3068
3073
  [this.disableShineEffect, this.disableShineEffectFp],
@@ -3244,7 +3249,7 @@ class Qr {
3244
3249
  const C = { isVerticalEnabled: g };
3245
3250
  return u.hasDiff(C) ? c(
3246
3251
  e("web_app_setup_swipe_behavior", { allow_vertical_swipe: g }),
3247
- D(() => {
3252
+ P(() => {
3248
3253
  u.setState(C);
3249
3254
  })
3250
3255
  ) : I(void 0);
@@ -3289,7 +3294,7 @@ function zr({ request: s, ...e }) {
3289
3294
  }
3290
3295
  const Nr = zr(c(
3291
3296
  F(),
3292
- U,
3297
+ G,
3293
3298
  v
3294
3299
  )), Yn = h(Nr);
3295
3300
  function Jr({ invokeCustomMethod: s, ...e }) {
@@ -3334,7 +3339,7 @@ const en = tn({
3334
3339
  ...c(
3335
3340
  F(),
3336
3341
  v,
3337
- U
3342
+ G
3338
3343
  ),
3339
3344
  createRequestId: Ae
3340
3345
  }), to = h(en);
@@ -3381,7 +3386,7 @@ function on({ request: s, ...e }) {
3381
3386
  }
3382
3387
  const an = on(c(
3383
3388
  F(),
3384
- U,
3389
+ G,
3385
3390
  v
3386
3391
  )), ro = h(an);
3387
3392
  function un({ postEvent: s, ...e }) {
@@ -3403,7 +3408,7 @@ function ln({ isInlineMode: s, postEvent: e, ...r }) {
3403
3408
  }), {
3404
3409
  ...r,
3405
3410
  requires: {
3406
- every: ["web_app_switch_inline_query", () => P(s) ? void 0 : "The application must be launched in the inline mode"]
3411
+ every: ["web_app_switch_inline_query", () => O(s) ? void 0 : "The application must be launched in the inline mode"]
3407
3412
  },
3408
3413
  returns: "either"
3409
3414
  });
@@ -3644,13 +3649,13 @@ class hn {
3644
3649
  d.setState({ isFullscreen: k.is_fullscreen });
3645
3650
  }, T = (k) => {
3646
3651
  d.setState({ safeAreaInsets: k });
3647
- }, O = (k) => {
3652
+ }, D = (k) => {
3648
3653
  d.setState({ contentSafeAreaInsets: k });
3649
- }, G = new Jt({
3654
+ }, U = new Jt({
3650
3655
  initialState(k) {
3651
3656
  const st = (N) => () => {
3652
3657
  const [X, W] = N === "safe-area" ? ["web_app_request_safe_area", "safe_area_changed"] : ["web_app_request_content_safe_area", "content_safe_area_changed"];
3653
- return ot(X, P(S)) ? _(X, W, k) : q({ top: 0, left: 0, right: 0, bottom: 0 });
3658
+ return ot(X, O(S)) ? _(X, W, k) : q({ top: 0, left: 0, right: 0, bottom: 0 });
3654
3659
  }, M = (N) => () => typeof N == "boolean" ? q(N) : ve(N());
3655
3660
  return c(
3656
3661
  Js,
@@ -3678,10 +3683,10 @@ class hn {
3678
3683
  },
3679
3684
  isPageReload: r,
3680
3685
  onMounted(k) {
3681
- o(x), u(R), i(T), n(O), d.setState(k);
3686
+ o(x), u(R), i(T), n(D), d.setState(k);
3682
3687
  },
3683
3688
  onUnmounted() {
3684
- m(x), p(R), l(T), a(O);
3689
+ m(x), p(R), l(T), a(D);
3685
3690
  },
3686
3691
  restoreState: e.get
3687
3692
  }), H = (k) => w(() => this.safeAreaInsets()[k]), bt = (k) => w(() => this.contentSafeAreaInsets()[k]);
@@ -3702,7 +3707,7 @@ class hn {
3702
3707
  ),
3703
3708
  Z((M) => "error" in M && M.error !== "ALREADY_FULLSCREEN" ? $(new er(M.error)) : (d.setState({ isFullscreen: "is_fullscreen" in M ? M.is_fullscreen : !0 }), q(void 0)))
3704
3709
  ));
3705
- this.isMounted = G.isMounted, this.mountFp = Ve(G.mount), this.mount = h(this.mountFp), this.isFullscreen = d.getter("isFullscreen"), this.requestFullscreenFp = ee(!0), this.requestFullscreen = h(this.requestFullscreenFp), this.exitFullscreenFp = ee(!1), this.exitFullscreen = h(this.exitFullscreenFp);
3710
+ this.isMounted = U.isMounted, this.mountFp = Ve(U.mount), this.mount = h(this.mountFp), this.isFullscreen = d.getter("isFullscreen"), this.requestFullscreenFp = ee(!0), this.requestFullscreen = h(this.requestFullscreenFp), this.exitFullscreenFp = ee(!1), this.exitFullscreen = h(this.exitFullscreenFp);
3706
3711
  const gt = j(!1);
3707
3712
  this.isCssVarsBound = w(gt), this.bindCssVarsFp = te(
3708
3713
  (k) => {
@@ -3758,13 +3763,13 @@ function dn() {
3758
3763
  et("viewport"),
3759
3764
  v,
3760
3765
  L,
3761
- U
3766
+ G
3762
3767
  ),
3763
3768
  isFullscreen() {
3764
- return c(St(), D((o) => !!o.tgWebAppFullscreen));
3769
+ return c(St(), P((o) => !!o.tgWebAppFullscreen));
3765
3770
  },
3766
3771
  isViewportStable() {
3767
- return c(St(), D((o) => ["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(o.tgWebAppPlatform)));
3772
+ return c(St(), P((o) => ["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(o.tgWebAppPlatform)));
3768
3773
  },
3769
3774
  offContentSafeAreaInsetsChanged: i.off,
3770
3775
  offFullscreenChanged: r.off,
@@ -3814,7 +3819,7 @@ function fn(s = {}) {
3814
3819
  }
3815
3820
  return c(
3816
3821
  mt("iframe_ready", { reload_supported: !0 }),
3817
- D(() => (re().log("The package was initialized"), o))
3822
+ P(() => (re().log("The package was initialized"), o))
3818
3823
  );
3819
3824
  }
3820
3825
  const ao = yt(fn);