@tma.js/bridge 2.1.3 → 2.2.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
@@ -1,34 +1,34 @@
1
- import { is as L, looseObject as f, function as Z, nullish as v, boolean as z, number as G, string as b, optional as V, unknown as Se, parse as C, any as Te } from "valibot";
2
- import { throwifyFpFn as S, getStorageValue as $e, setStorageValue as ee, createLogger as Ae, throwifyAnyEither as W, createCbCollector as Me, BetterTaskEither as Ce } from "@tma.js/toolkit";
3
- import { createLogger as pr, deepSnakeToCamelObjKeys as _r } from "@tma.js/toolkit";
4
- import { BetterPromise as te, TimeoutError as Le } from "better-promises";
5
- import { CancelledError as lr, TimeoutError as mr } from "better-promises";
6
- import { parseLaunchParamsQueryFp as re, themeParams as We, pipeJsonToSchema as ne, miniAppsMessage as oe, serializeLaunchParamsQuery as Fe, parseLaunchParamsQuery as qe } from "@tma.js/transformers";
7
- import { errorClass as E, errorClassWithData as Oe } from "error-kid";
8
- import { signal as P, computed as ae } from "@tma.js/signals";
9
- import Re from "mitt";
10
- function se(e) {
11
- return L(
12
- f({ TelegramWebviewProxy: f({ postEvent: Z() }) }),
1
+ import { is as U, looseObject as m, function as te, nullish as E, boolean as V, number as B, string as P, optional as D, unknown as Me, parse as R, any as Ce } from "valibot";
2
+ import { throwifyFpFn as $, getStorageValue as Le, setStorageValue as re, createLogger as qe, throwifyAnyEither as M, createCbCollector as ne, BetterTaskEither as oe } from "@tma.js/toolkit";
3
+ import { createLogger as fr, deepSnakeToCamelObjKeys as lr } from "@tma.js/toolkit";
4
+ import { BetterPromise as ae, TimeoutError as Fe } from "better-promises";
5
+ import { CancelledError as wr, TimeoutError as hr } from "better-promises";
6
+ import { errorClass as k, errorClassWithData as We } from "error-kid";
7
+ import { parseLaunchParamsQueryFp as se, themeParams as Re, pipeJsonToSchema as ie, miniAppsMessage as ue, serializeLaunchParamsQuery as Ue, parseLaunchParamsQuery as Ie } from "@tma.js/transformers";
8
+ import { signal as d, computed as ce } from "@tma.js/signals";
9
+ import Oe from "mitt";
10
+ function pe(e) {
11
+ return U(
12
+ m({ TelegramWebviewProxy: m({ postEvent: te() }) }),
13
13
  e
14
14
  );
15
15
  }
16
- function ie() {
16
+ function _e() {
17
17
  try {
18
18
  return window.self !== window.top;
19
19
  } catch {
20
20
  return !0;
21
21
  }
22
22
  }
23
- var Ue = function(e, t, r) {
23
+ var je = function(e, t, r) {
24
24
  if (r || arguments.length === 2) for (var n = 0, a = t.length, o; n < a; n++)
25
25
  (o || !(n in t)) && (o || (o = Array.prototype.slice.call(t, 0, n)), o[n] = t[n]);
26
26
  return e.concat(o || Array.prototype.slice.call(t));
27
27
  };
28
- function Ie(e) {
28
+ function ze(e) {
29
29
  return e;
30
30
  }
31
- function x(e, t, r, n, a, o, s, i, c) {
31
+ function S(e, t, r, n, a, o, s, i, c) {
32
32
  switch (arguments.length) {
33
33
  case 1:
34
34
  return e;
@@ -93,91 +93,91 @@ function l(e, t, r, n, a, o, s, i, c) {
93
93
  }
94
94
  }
95
95
  }
96
- var T = function(e, t) {
96
+ var C = function(e, t) {
97
97
  var r = typeof e == "number" ? function(n) {
98
98
  return n.length >= e;
99
99
  } : e;
100
100
  return function() {
101
101
  var n = Array.from(arguments);
102
102
  return r(arguments) ? t.apply(this, n) : function(a) {
103
- return t.apply(void 0, Ue([a], n, !1));
103
+ return t.apply(void 0, je([a], n, !1));
104
104
  };
105
105
  };
106
- }, je = { _tag: "None" }, ze = function(e) {
106
+ }, Ge = { _tag: "None" }, Ve = function(e) {
107
107
  return { _tag: "Some", value: e };
108
- }, Ge = function(e) {
108
+ }, Be = function(e) {
109
109
  return e._tag === "Left";
110
- }, Ve = function(e) {
110
+ }, De = function(e) {
111
111
  return { _tag: "Left", left: e };
112
- }, Be = function(e) {
112
+ }, Ne = function(e) {
113
113
  return { _tag: "Right", right: e };
114
- }, m = Ve, _ = Be, ue = /* @__PURE__ */ T(2, function(e, t) {
115
- return d(e) ? e : t(e.right);
116
- }), De = function(e) {
114
+ }, w = De, _ = Ne, fe = /* @__PURE__ */ C(2, function(e, t) {
115
+ return v(e) ? e : t(e.right);
116
+ }), Je = function(e) {
117
117
  return function(t) {
118
- return d(t) ? t : _(e(t.right));
118
+ return v(t) ? t : _(e(t.right));
119
119
  };
120
- }, Ne = function(e, t) {
120
+ }, Qe = function(e, t) {
121
121
  return function(r) {
122
- return d(r) ? m(e(r.left)) : _(t(r.right));
122
+ return v(r) ? w(e(r.left)) : _(t(r.right));
123
123
  };
124
- }, Je = function(e) {
124
+ }, He = function(e) {
125
125
  return function(t) {
126
- return d(t) ? m(e(t.left)) : t;
126
+ return v(t) ? w(e(t.left)) : t;
127
127
  };
128
- }, d = Ge, ce = function(e, t) {
128
+ }, v = Be, le = function(e, t) {
129
129
  return function(r) {
130
- return d(r) ? e(r.left) : t(r.right);
130
+ return v(r) ? e(r.left) : t(r.right);
131
131
  };
132
- }, Qe = ce, F = ce, He = F, q = function(e, t) {
132
+ }, Ke = le, I = le, Ye = I, O = function(e, t) {
133
133
  try {
134
134
  return _(e());
135
135
  } catch (r) {
136
- return m(t(r));
136
+ return w(t(r));
137
137
  }
138
- }, Ke = ue, Ye = ue, Xe = je, Ze = ze, et = function(e) {
138
+ }, Xe = fe, Ze = fe, et = Ge, tt = Ve, rt = function(e) {
139
139
  return e._tag === "None";
140
- }, tt = function(e, t) {
140
+ }, nt = function(e, t) {
141
141
  return function(r) {
142
- return et(r) ? e() : t(r.value);
142
+ return rt(r) ? e() : t(r.value);
143
143
  };
144
- }, rt = tt;
145
- function nt(e) {
146
- return x(_, e.of);
144
+ }, ot = nt;
145
+ function at(e) {
146
+ return S(_, e.of);
147
147
  }
148
- function ot(e) {
149
- return x(m, e.of);
148
+ function st(e) {
149
+ return S(w, e.of);
150
150
  }
151
- function at(e) {
151
+ function it(e) {
152
152
  return function(t, r) {
153
153
  return e.chain(t, function(n) {
154
- return d(n) ? e.of(n) : r(n.right);
154
+ return v(n) ? e.of(n) : r(n.right);
155
155
  });
156
156
  };
157
157
  }
158
- function st(e) {
158
+ function ut(e) {
159
159
  return function(t, r, n) {
160
- return e.map(t, Ne(r, n));
160
+ return e.map(t, Qe(r, n));
161
161
  };
162
162
  }
163
- function it(e) {
163
+ function ct(e) {
164
164
  return function(t, r) {
165
165
  return function(n) {
166
- return e.map(n, F(t, r));
166
+ return e.map(n, I(t, r));
167
167
  };
168
168
  };
169
169
  }
170
- var pe = function(e, t) {
171
- return l(e, ct(t));
172
- }, ut = function(e, t) {
173
- return l(e, pt(t));
174
- }, ct = function(e) {
170
+ var me = function(e, t) {
171
+ return l(e, _t(t));
172
+ }, pt = function(e, t) {
173
+ return l(e, ft(t));
174
+ }, _t = function(e) {
175
175
  return function(t) {
176
176
  return function() {
177
177
  return Promise.resolve().then(t).then(e);
178
178
  };
179
179
  };
180
- }, pt = function(e) {
180
+ }, ft = function(e) {
181
181
  return function(t) {
182
182
  return function() {
183
183
  return Promise.all([Promise.resolve().then(t), Promise.resolve().then(e)]).then(function(r) {
@@ -186,37 +186,37 @@ var pe = function(e, t) {
186
186
  });
187
187
  };
188
188
  };
189
- }, _e = function(e) {
189
+ }, we = function(e) {
190
190
  return function() {
191
191
  return Promise.resolve(e);
192
192
  };
193
- }, _t = /* @__PURE__ */ T(2, function(e, t) {
193
+ }, lt = /* @__PURE__ */ C(2, function(e, t) {
194
194
  return function() {
195
195
  return Promise.resolve().then(e).then(function(r) {
196
196
  return t(r)();
197
197
  });
198
198
  };
199
- }), fe = "Task", le = {
200
- URI: fe,
201
- map: pe
202
- }, me = {
203
- of: _e
204
- }, ft = {
205
- URI: fe,
206
- map: pe,
207
- of: _e,
208
- ap: ut,
209
- chain: _t
210
- }, lt = /* @__PURE__ */ ot(me), we = /* @__PURE__ */ nt(me), he = /* @__PURE__ */ it(le), mt = /* @__PURE__ */ T(3, st(le)), ge = /* @__PURE__ */ T(2, at(ft)), wt = ge, ht = ge;
211
- class gt extends E("MethodUnsupportedError", (t, r) => [
199
+ }), he = "Task", ge = {
200
+ URI: he,
201
+ map: me
202
+ }, de = {
203
+ of: we
204
+ }, mt = {
205
+ URI: he,
206
+ map: me,
207
+ of: we,
208
+ ap: pt,
209
+ chain: lt
210
+ }, wt = /* @__PURE__ */ st(de), ve = /* @__PURE__ */ at(de), be = /* @__PURE__ */ ct(ge), ye = /* @__PURE__ */ C(3, ut(ge)), Ee = /* @__PURE__ */ C(2, it(mt)), ht = Ee, Pe = Ee;
211
+ class gt extends k("MethodUnsupportedError", (t, r) => [
212
212
  `Method "${t}" is unsupported in Mini Apps version ${r}`
213
213
  ]) {
214
214
  }
215
- class dt extends E("MethodParameterUnsupportedError", (t, r, n) => [
215
+ class dt extends k("MethodParameterUnsupportedError", (t, r, n) => [
216
216
  `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
217
217
  ]) {
218
218
  }
219
- class vt extends Oe(
219
+ class vt extends We(
220
220
  "LaunchParamsRetrieveError",
221
221
  (t) => ({ errors: t }),
222
222
  (t) => [
@@ -232,47 +232,47 @@ class vt extends Oe(
232
232
  ]
233
233
  ) {
234
234
  }
235
- class bt extends E("InvalidLaunchParamsError", (t, r) => [
235
+ class bt extends k("InvalidLaunchParamsError", (t, r) => [
236
236
  `Invalid value for launch params: ${t}`,
237
237
  { cause: r }
238
238
  ]) {
239
239
  }
240
- class de extends E("UnknownEnvError") {
240
+ class xe extends k("UnknownEnvError") {
241
241
  }
242
- class yt extends E(
242
+ class yt extends k(
243
243
  "InvokeCustomMethodError",
244
244
  (t) => [`Server returned error: ${t}`]
245
245
  ) {
246
246
  }
247
- const B = "launchParams";
248
- function D(e) {
247
+ const N = "launchParams";
248
+ function J(e) {
249
249
  return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
250
250
  }
251
- const Et = x($, Ke(re)), Nt = S(Et), Pt = x($, De((e) => {
251
+ const Et = S(L, Xe(se)), Jt = $(Et), Pt = S(L, Je((e) => {
252
252
  const t = new URLSearchParams(e).get("tgWebAppData");
253
- return t ? Ze(t) : Xe;
254
- })), Jt = x(
253
+ return t ? tt(t) : et;
254
+ })), Qt = S(
255
255
  Pt,
256
- He((e) => {
256
+ Ye((e) => {
257
257
  throw e;
258
258
  }, (e) => e),
259
- rt(() => {
259
+ ot(() => {
260
260
  }, (e) => e)
261
261
  );
262
- function $() {
262
+ function L() {
263
263
  const e = [];
264
264
  for (const [t, r] of [
265
265
  // Try to retrieve launch parameters from the current location. This method
266
266
  // can return nothing in case, location was changed, and then the page was
267
267
  // reloaded.
268
- [() => D(window.location.href), "window.location.href"],
268
+ [() => J(window.location.href), "window.location.href"],
269
269
  // Then, try using the lower level API - window.performance.
270
270
  [() => {
271
271
  const n = performance.getEntriesByType("navigation")[0];
272
- return n && D(n.name);
272
+ return n && J(n.name);
273
273
  }, "performance navigation entries"],
274
274
  // Finally, try using the session storage.
275
- [() => $e(B), "local storage"]
275
+ [() => Le(N), "local storage"]
276
276
  ]) {
277
277
  const n = t();
278
278
  if (!n) {
@@ -280,28 +280,28 @@ function $() {
280
280
  continue;
281
281
  }
282
282
  const a = l(
283
- re(n),
284
- Qe((o) => o, () => !0)
283
+ se(n),
284
+ Ke((o) => o, () => !0)
285
285
  );
286
286
  if (typeof a != "boolean") {
287
287
  e.push({ source: r, error: a });
288
288
  continue;
289
289
  }
290
- return ee(B, n), _(n);
290
+ return re(N, n), _(n);
291
291
  }
292
- return m(new vt(e));
292
+ return w(new vt(e));
293
293
  }
294
- const Qt = S($);
294
+ const Ht = $(L);
295
295
  function xt(e, t) {
296
- const r = /* @__PURE__ */ new Map(), n = Re(), a = (o, s, i = !1) => {
296
+ const r = /* @__PURE__ */ new Map(), n = Oe(), a = (o, s, i = !1) => {
297
297
  const c = r.get(o) || /* @__PURE__ */ new Map();
298
298
  r.set(o, c);
299
299
  const u = c.get(s) || [];
300
300
  c.set(s, u);
301
- const p = u.findIndex((w) => w[1] === i);
301
+ const p = u.findIndex((f) => f[1] === i);
302
302
  if (p >= 0 && (n.off(o, u[p][0]), u.splice(p, 1), !u.length && (c.delete(s), !c.size))) {
303
- const w = r.size;
304
- r.delete(o), w && !r.size && t();
303
+ const f = r.size;
304
+ r.delete(o), f && !r.size && t();
305
305
  }
306
306
  };
307
307
  return {
@@ -309,14 +309,14 @@ function xt(e, t) {
309
309
  !r.size && e();
310
310
  const c = () => {
311
311
  a(o, s, i);
312
- }, u = (...g) => {
313
- i && c(), o === "*" ? s({ name: g[0], payload: g[1] }) : s(...g);
312
+ }, u = (...h) => {
313
+ i && c(), o === "*" ? s({ name: h[0], payload: h[1] }) : s(...h);
314
314
  };
315
315
  n.on(o, u);
316
316
  const p = r.get(o) || /* @__PURE__ */ new Map();
317
317
  r.set(o, p);
318
- const w = p.get(s) || [];
319
- return p.set(s, w), w.push([u, i || !1]), c;
318
+ const f = p.get(s) || [];
319
+ return p.set(s, f), f.push([u, i || !1]), c;
320
320
  },
321
321
  off: a,
322
322
  // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -327,7 +327,7 @@ function xt(e, t) {
327
327
  }
328
328
  };
329
329
  }
330
- function A(e, t) {
330
+ function F(e, t) {
331
331
  window.dispatchEvent(new MessageEvent("message", {
332
332
  data: JSON.stringify({ eventType: e, eventData: t }),
333
333
  // We specify this kind of source here in order to allow the package's "on" function to
@@ -336,7 +336,29 @@ function A(e, t) {
336
336
  source: window.parent
337
337
  }));
338
338
  }
339
- function M(e, t, r) {
339
+ const T = d(!1), j = d("https://web.telegram.org"), kt = (e) => {
340
+ g().log("Event received:", e);
341
+ }, ke = ce(T);
342
+ function Kt(e) {
343
+ e !== T() && (T.set(e), (e ? z : At)("*", kt));
344
+ }
345
+ const Se = ce(j);
346
+ function Yt(e) {
347
+ j.set(e), g().log("New target origin set", e);
348
+ }
349
+ const x = d((...e) => {
350
+ window.parent.postMessage(...e);
351
+ }), g = d(qe("Bridge", {
352
+ bgColor: "#9147ff",
353
+ textColor: "white",
354
+ shouldLog: ke
355
+ }));
356
+ function Xt() {
357
+ $t(), [x, j, Se, T, ke, g].forEach((e) => {
358
+ e.unsubAll(), "reset" in e && e.reset();
359
+ });
360
+ }
361
+ function W(e, t, r) {
340
362
  const n = [r], a = e[t];
341
363
  typeof a == "function" && n.push(a);
342
364
  const o = (...i) => {
@@ -352,28 +374,28 @@ function M(e, t, r) {
352
374
  return;
353
375
  }
354
376
  if (i === 2) {
355
- J(e, t, n[1]);
377
+ H(e, t, n[1]);
356
378
  return;
357
379
  }
358
- n.unshift(1), J(e, t, o);
380
+ n.unshift(1), H(e, t, o);
359
381
  }
360
382
  });
361
- ve(
383
+ Ae(
362
384
  e,
363
385
  t,
364
386
  () => s,
365
387
  (i) => n.push(i)
366
388
  );
367
389
  }
368
- function N(e, t) {
390
+ function Q(e, t) {
369
391
  const r = e[t];
370
- ve(e, t, () => r, (n) => {
392
+ Ae(e, t, () => r, (n) => {
371
393
  Object.entries(n).forEach(([a, o]) => {
372
394
  r[a] = o;
373
395
  });
374
396
  });
375
397
  }
376
- function ve(e, t, r, n) {
398
+ function Ae(e, t, r, n) {
377
399
  Object.defineProperty(e, t, {
378
400
  enumerable: !0,
379
401
  configurable: !0,
@@ -381,7 +403,7 @@ function ve(e, t, r, n) {
381
403
  set: n
382
404
  });
383
405
  }
384
- function J(e, t, r) {
406
+ function H(e, t, r) {
385
407
  Object.defineProperty(e, t, {
386
408
  enumerable: !0,
387
409
  configurable: !0,
@@ -389,27 +411,27 @@ function J(e, t, r) {
389
411
  value: r
390
412
  });
391
413
  }
392
- const kt = {
393
- clipboard_text_received: f({
394
- req_id: b(),
395
- data: v(b())
414
+ const St = {
415
+ clipboard_text_received: m({
416
+ req_id: P(),
417
+ data: E(P())
396
418
  }),
397
- custom_method_invoked: f({
398
- req_id: b(),
399
- result: V(Se()),
400
- error: V(b())
419
+ custom_method_invoked: m({
420
+ req_id: P(),
421
+ result: D(Me()),
422
+ error: D(P())
401
423
  }),
402
- popup_closed: v(
403
- f({ button_id: v(b(), () => {
424
+ popup_closed: E(
425
+ m({ button_id: E(P(), () => {
404
426
  }) }),
405
427
  {}
406
428
  ),
407
- viewport_changed: v(
408
- f({
409
- height: G(),
410
- width: v(G(), () => window.innerWidth),
411
- is_state_stable: z(),
412
- is_expanded: z()
429
+ viewport_changed: E(
430
+ m({
431
+ height: B(),
432
+ width: E(B(), () => window.innerWidth),
433
+ is_state_stable: V(),
434
+ is_expanded: V()
413
435
  }),
414
436
  // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
415
437
  // null. Leaving this default value until the bug is fixed.
@@ -419,25 +441,25 @@ const kt = {
419
441
  is_expanded: !0
420
442
  })
421
443
  ),
422
- theme_changed: f({
423
- theme_params: We()
444
+ theme_changed: m({
445
+ theme_params: Re()
424
446
  })
425
447
  };
426
- function Q(e) {
448
+ function K(e) {
427
449
  if (e.source !== window.parent)
428
450
  return;
429
451
  let t;
430
452
  try {
431
- t = C(ne(oe()), e.data);
453
+ t = R(ie(ue()), e.data);
432
454
  } catch {
433
455
  return;
434
456
  }
435
- const { eventType: r, eventData: n } = t, a = kt[r];
457
+ const { eventType: r, eventData: n } = t, a = St[r];
436
458
  let o;
437
459
  try {
438
- o = a ? C(a, n) : n;
460
+ o = a ? R(a, n) : n;
439
461
  } catch (s) {
440
- return h().forceError(
462
+ return g().forceError(
441
463
  [
442
464
  `An error occurred processing the "${r}" event from the Telegram application.`,
443
465
  "Please, file an issue here:",
@@ -451,14 +473,14 @@ function Q(e) {
451
473
  Tt(r, o);
452
474
  }
453
475
  const {
454
- on: be,
455
- off: St,
476
+ on: z,
477
+ off: At,
456
478
  emit: Tt,
457
479
  clear: $t
458
480
  } = xt(
459
481
  () => {
460
482
  const e = window;
461
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), M(e.TelegramGameProxy, "receiveEvent", A), N(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), M(e.Telegram.WebView, "receiveEvent", A), N(e.Telegram, "WebView"), M(e, "TelegramGameProxy_receiveEvent", A), window.addEventListener("message", Q);
483
+ !e.TelegramGameProxy && (e.TelegramGameProxy = {}), W(e.TelegramGameProxy, "receiveEvent", F), Q(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), W(e.Telegram.WebView, "receiveEvent", F), Q(e.Telegram, "WebView"), W(e, "TelegramGameProxy_receiveEvent", F), window.addEventListener("message", K);
462
484
  },
463
485
  () => {
464
486
  [
@@ -473,143 +495,124 @@ const {
473
495
  return;
474
496
  const [n, a] = r;
475
497
  "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
476
- }), window.removeEventListener("message", Q);
498
+ }), window.removeEventListener("message", K);
477
499
  }
478
- ), k = P(!1), O = P("https://web.telegram.org"), At = (e) => {
479
- h().log("Event received:", e);
480
- }, ye = ae(k);
481
- function Ht(e) {
482
- e !== k() && (k.set(e), (e ? be : St)("*", At));
483
- }
484
- const Ee = ae(O);
485
- function Kt(e) {
486
- O.set(e), h().log("New target origin set", e);
487
- }
488
- const y = P((...e) => {
489
- window.parent.postMessage(...e);
490
- }), h = P(Ae("Bridge", {
491
- bgColor: "#9147ff",
492
- textColor: "white",
493
- shouldLog: ye
494
- }));
495
- function Yt() {
496
- $t(), [y, O, Ee, k, ye, h].forEach((e) => {
497
- e.unsubAll(), "reset" in e && e.reset();
498
- });
499
- }
500
- const Mt = (...e) => y()(...e);
500
+ ), Mt = (...e) => x()(...e);
501
501
  function Ct(e, t) {
502
502
  l(
503
- R(
503
+ A(
504
504
  // @ts-expect-error It's ok, TS can't determine a specific override.
505
505
  e,
506
506
  t
507
507
  ),
508
- Je((r) => {
508
+ He((r) => {
509
509
  throw r;
510
510
  })
511
511
  );
512
512
  }
513
- function R(e, t) {
514
- h().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
513
+ function A(e, t) {
514
+ g().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
515
515
  const r = window, n = JSON.stringify({ eventType: e, eventData: t });
516
- return ie() ? (Mt(n, Ee()), _(void 0)) : se(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), _(void 0)) : L(f({ external: f({ notify: Z() }) }), r) ? (r.external.notify(n), _(void 0)) : m(new de());
516
+ return _e() ? (Mt(n, Se()), _(void 0)) : pe(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), _(void 0)) : U(m({ external: m({ notify: te() }) }), r) ? (r.external.notify(n), _(void 0)) : w(new xe());
517
517
  }
518
- function U(e, t, r = {}) {
518
+ function G(e, t, r = {}) {
519
519
  const {
520
520
  // If no capture function was passed, we capture the first compatible event.
521
521
  capture: n = () => !0,
522
- postEvent: a = R
523
- } = r, o = P(), [s, i] = Me();
522
+ postEvent: a = A
523
+ } = r, o = d(), [s, i] = ne();
524
524
  (Array.isArray(t) ? t : [t]).forEach((u) => {
525
525
  s(
526
- be(u, (p) => {
527
- (Array.isArray(t) ? n({ event: u, payload: p }) : n(p)) && o.set([p]);
526
+ z(u, (p) => {
527
+ const f = Array.isArray(t);
528
+ n(f ? { event: u, payload: p } : p) && o.set([
529
+ f ? { event: u, payload: p } : p
530
+ ]);
528
531
  })
529
532
  );
530
533
  });
531
534
  const c = (u) => (i(), u);
532
535
  return l(
533
536
  async () => a(e, r.params),
534
- ht(() => Ce((u, p, w) => {
535
- const g = o();
536
- if (g)
537
- return u(g[0]);
538
- const I = (j) => {
539
- j && u(j[0]);
540
- }, ke = () => {
541
- o.unsub(I);
537
+ Pe(() => oe((u, p, f) => {
538
+ const h = o();
539
+ if (h)
540
+ return u(h[0]);
541
+ const b = (y) => {
542
+ y && u(y[0]);
543
+ }, q = () => {
544
+ o.unsub(b);
542
545
  };
543
- o.sub(I), w.on("finalized", ke);
546
+ o.sub(b), f.on("finalized", q);
544
547
  }, r)),
545
- mt(c, c)
548
+ ye(c, c)
546
549
  );
547
550
  }
548
- function Xt(e, t, r) {
551
+ function Zt(e, t, r) {
549
552
  const { postEvent: n } = r || {};
550
- return W(
553
+ return M(
551
554
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
552
- U(e, t, {
555
+ G(e, t, {
553
556
  ...r,
554
557
  postEvent: n ? (...a) => {
555
558
  try {
556
559
  return n(...a), _(void 0);
557
560
  } catch (o) {
558
- return m(o);
561
+ return w(o);
559
562
  }
560
- } : R
563
+ } : A
561
564
  })
562
565
  );
563
566
  }
564
- function Zt(e, t) {
567
+ function er(e, t) {
565
568
  const r = Lt(
566
569
  // @ts-expect-error TS doesn't get what override we are going to use.
567
570
  e,
568
571
  t
569
572
  );
570
- return typeof r == "function" ? te.fn(() => W(r)) : r;
573
+ return typeof r == "function" ? ae.fn(() => M(r)) : r;
571
574
  }
572
575
  function Lt(e, t) {
573
- const r = se(window);
576
+ const r = pe(window);
574
577
  if (!e)
575
- return r || l($(), F(() => !1, () => !0));
578
+ return r || l(L(), I(() => !1, () => !0));
576
579
  if (r)
577
- return we(!0);
580
+ return ve(!0);
578
581
  const { timeout: n = 100 } = t || {};
579
582
  return l(
580
- U("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
581
- he(
582
- (a) => Le.is(a) || de.is(a) ? _(!1) : m(a),
583
+ G("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
584
+ be(
585
+ (a) => Fe.is(a) || xe.is(a) ? _(!1) : w(a),
583
586
  () => _(!0)
584
587
  )
585
588
  );
586
589
  }
587
- function er({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
590
+ function tr({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
588
591
  if (e) {
589
592
  const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
590
593
  // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
591
594
  // value. We are doing it because we are working with tgWebAppData presented as a
592
595
  // string, not an object as serializeLaunchParamsQuery requires.
593
- Fe({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
596
+ Ue({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
594
597
  );
595
598
  try {
596
- qe(o);
599
+ Ie(o);
597
600
  } catch (s) {
598
601
  throw new bt(o, s);
599
602
  }
600
- ee("launchParams", o);
603
+ re("launchParams", o);
601
604
  }
602
- if (ie()) {
605
+ if (_e()) {
603
606
  if (!t)
604
607
  return;
605
- r && y.reset();
606
- const o = y();
607
- y.set((...s) => {
608
+ r && x.reset();
609
+ const o = x();
610
+ x.set((...s) => {
608
611
  const [i] = s, c = () => {
609
612
  o(...s);
610
613
  };
611
614
  try {
612
- const u = C(ne(oe()), i);
615
+ const u = R(ie(ue()), i);
613
616
  t({ name: u.eventType, params: u.eventData }, c);
614
617
  } catch {
615
618
  c();
@@ -630,24 +633,12 @@ function er({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
630
633
  params: s ? JSON.parse(s) : void 0
631
634
  }, i) : i();
632
635
  }
633
- }, h().log("Environment was mocked by the mockTelegramEnv function");
636
+ }, g().log("Environment was mocked by the mockTelegramEnv function");
634
637
  }
635
- function Wt(e) {
638
+ function qt(e) {
636
639
  return ({ req_id: t }) => t === e;
637
640
  }
638
- function H(e) {
639
- return e.split(".").map(Number);
640
- }
641
- function Ft(e, t) {
642
- const r = H(e), n = H(t), a = Math.max(r.length, n.length);
643
- for (let o = 0; o < a; o += 1) {
644
- const s = r[o] || 0, i = n[o] || 0;
645
- if (s !== i)
646
- return s > i ? 1 : -1;
647
- }
648
- return 0;
649
- }
650
- const K = {
641
+ const Y = {
651
642
  "6.0": [
652
643
  "iframe_ready",
653
644
  "iframe_will_reload",
@@ -735,40 +726,52 @@ const K = {
735
726
  ],
736
727
  9.1: ["web_app_hide_keyboard"]
737
728
  };
738
- function Y(e, t) {
739
- return Object.keys(K).find((n) => K[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
729
+ function X(e, t) {
730
+ return Object.keys(Y).find((n) => Y[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
731
+ }
732
+ function Z(e) {
733
+ return e.split(".").map(Number);
734
+ }
735
+ function Ft(e, t) {
736
+ const r = Z(e), n = Z(t), a = Math.max(r.length, n.length);
737
+ for (let o = 0; o < a; o += 1) {
738
+ const s = r[o] || 0, i = n[o] || 0;
739
+ if (s !== i)
740
+ return s > i ? 1 : -1;
741
+ }
742
+ return 0;
740
743
  }
741
- function X(e, t, r) {
742
- const n = r ? Y(
744
+ function ee(e, t, r) {
745
+ const n = r ? X(
743
746
  e,
744
747
  t
745
- ) : Y(e);
748
+ ) : X(e);
746
749
  return n ? Ft(n, r || t) <= 0 : !1;
747
750
  }
748
- function tr(e, t = "strict") {
751
+ function rr(e, t = "strict") {
749
752
  const r = typeof t == "function" ? t : (n) => {
750
753
  const { method: a, version: o } = n, s = "param" in n ? new dt(a, n.param, o) : new gt(a, o);
751
754
  if (t === "strict")
752
755
  throw s;
753
- return h().forceWarn(s.message);
756
+ return g().forceWarn(s.message);
754
757
  };
755
- return (n, a) => X(n, e) ? n === "web_app_set_header_color" && L(f({ color: Te() }), a) && !X(n, "color", e) ? r({ version: e, method: n, param: "color" }) : Ct(n, a) : r({ version: e, method: n });
758
+ return (n, a) => ee(n, e) ? n === "web_app_set_header_color" && U(m({ color: Ce() }), a) && !ee(n, "color", e) ? r({ version: e, method: n, param: "color" }) : Ct(n, a) : r({ version: e, method: n });
756
759
  }
757
- function qt(e, t, r, n) {
760
+ function Wt(e, t, r, n) {
758
761
  return l(
759
- U("web_app_invoke_custom_method", "custom_method_invoked", {
762
+ G("web_app_invoke_custom_method", "custom_method_invoked", {
760
763
  ...n || {},
761
764
  params: { method: e, params: t, req_id: r },
762
- capture: Wt(r)
765
+ capture: qt(r)
763
766
  }),
764
- wt(({ result: a, error: o }) => o ? lt(new yt(o)) : we(a))
767
+ ht(({ result: a, error: o }) => o ? wt(new yt(o)) : ve(a))
765
768
  );
766
769
  }
767
- function rr(e, t, r, n) {
768
- return te.fn(() => l(
770
+ function nr(e, t, r, n) {
771
+ return ae.fn(() => l(
769
772
  // @ts-expect-error TypeScript is unable to determine required override.
770
- qt(e, t, r, n),
771
- he(
773
+ Wt(e, t, r, n),
774
+ be(
772
775
  (a) => {
773
776
  throw a;
774
777
  },
@@ -776,103 +779,153 @@ function rr(e, t, r, n) {
776
779
  )
777
780
  )());
778
781
  }
779
- function nr() {
782
+ function Rt(e, t, r = {}) {
783
+ const {
784
+ // If no capture function was passed, we capture the first compatible event.
785
+ capture: n = () => !0,
786
+ postEvent: a = A
787
+ } = r, o = d(), [s, i] = ne();
788
+ (Array.isArray(t) ? t : [t]).forEach((u) => {
789
+ s(
790
+ z(u, (p) => {
791
+ (Array.isArray(t) ? n({ event: u, payload: p }) : n(p)) && o.set([p]);
792
+ })
793
+ );
794
+ });
795
+ const c = (u) => (i(), u);
796
+ return l(
797
+ async () => a(e, r.params),
798
+ Pe(() => oe((u, p, f) => {
799
+ const h = o();
800
+ if (h)
801
+ return u(h[0]);
802
+ const b = (y) => {
803
+ y && u(y[0]);
804
+ }, q = () => {
805
+ o.unsub(b);
806
+ };
807
+ o.sub(b), f.on("finalized", q);
808
+ }, r)),
809
+ ye(c, c)
810
+ );
811
+ }
812
+ function or(e, t, r) {
813
+ const { postEvent: n } = r || {};
814
+ return M(
815
+ // @ts-expect-error TypeScript will not be able to handle our overrides here.
816
+ Rt(e, t, {
817
+ ...r,
818
+ postEvent: n ? (...a) => {
819
+ try {
820
+ return n(...a), _(void 0);
821
+ } catch (o) {
822
+ return w(o);
823
+ }
824
+ } : A
825
+ })
826
+ );
827
+ }
828
+ function ar() {
780
829
  Object.hasOwn || (Object.hasOwn = function(e, t) {
781
830
  return Object.prototype.hasOwnProperty.call(e, t);
782
831
  });
783
832
  }
784
- function Pe(e) {
785
- return q(() => decodeURIComponent(
786
- atob(e).replace(/-/g, "+").replace(/_/g, "/").split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
833
+ function Te(e) {
834
+ return O(() => decodeURIComponent(
835
+ atob(
836
+ e.replace(/-/g, "+").replace(/_/g, "/")
837
+ ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
787
838
  ), (t) => t);
788
839
  }
789
- const or = S(Pe);
790
- function xe(e) {
840
+ const sr = $(Te);
841
+ function $e(e) {
791
842
  return btoa(
792
843
  encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
793
844
  ).replace(/\+/g, "-").replace(/\//g, "_");
794
845
  }
795
- var Ot = function(e) {
796
- return q(function() {
846
+ var Ut = function(e) {
847
+ return O(function() {
797
848
  return JSON.parse(e);
798
- }, Ie);
849
+ }, ze);
799
850
  };
800
- function Rt(e) {
801
- const t = xe(typeof e == "string" ? e : JSON.stringify(e));
802
- return t.length > 512 ? m(new Error("Value is too long for start parameter")) : _(t);
803
- }
804
- const ar = S(Rt);
805
- function sr(e, t) {
806
- return W(
807
- Ut(
851
+ function It(e) {
852
+ const t = $e(typeof e == "string" ? e : JSON.stringify(e));
853
+ return t.length > 512 ? w(new Error("Value is too long for start parameter")) : _(t);
854
+ }
855
+ const ir = $(It);
856
+ function ur(e, t) {
857
+ return M(
858
+ Ot(
808
859
  e,
809
860
  // @ts-expect-error TypeScript is unable to detect a correct override.
810
- typeof t == "function" ? (r) => q(() => t(r), (n) => n) : t
861
+ typeof t == "function" ? (r) => O(() => t(r), (n) => n) : t
811
862
  )
812
863
  );
813
864
  }
814
- function Ut(e, t) {
865
+ function Ot(e, t) {
815
866
  return l(
816
- Pe(e),
817
- Ye((r) => t ? typeof t == "function" ? t(r) : Ot(r) : _(r))
867
+ Te(e),
868
+ Ze((r) => t ? typeof t == "function" ? t(r) : Ut(r) : _(r))
818
869
  );
819
870
  }
820
- function ir(e) {
821
- return xe(e).length <= 512;
871
+ function cr(e) {
872
+ return $e(e).length <= 512;
822
873
  }
823
874
  export {
824
- lr as CancelledError,
875
+ wr as CancelledError,
825
876
  bt as InvalidLaunchParamsError,
826
877
  yt as InvokeCustomMethodFailedError,
827
878
  vt as LaunchParamsRetrieveError,
828
879
  dt as MethodParameterUnsupportedError,
829
880
  gt as MethodUnsupportedError,
830
- mr as TimeoutError,
831
- de as UnknownEnvError,
832
- nr as applyPolyfills,
833
- Wt as captureSameReq,
881
+ hr as TimeoutError,
882
+ xe as UnknownEnvError,
883
+ ar as applyPolyfills,
884
+ qt as captureSameReq,
834
885
  Ft as compareVersions,
835
- pr as createLogger,
836
- tr as createPostEvent,
837
- ar as createStartParam,
838
- Rt as createStartParamFp,
839
- ye as debug,
840
- or as decodeBase64Url,
841
- Pe as decodeBase64UrlFp,
842
- sr as decodeStartParam,
843
- Ut as decodeStartParamFp,
844
- _r as deepSnakeToCamelObjKeys,
845
- A as emitEvent,
846
- xe as encodeBase64Url,
847
- Y as getReleaseVersion,
848
- se as hasWebviewProxy,
849
- rr as invokeCustomMethod,
850
- qt as invokeCustomMethodFp,
851
- ie as isIframe,
852
- ir as isSafeToCreateStartParam,
853
- Zt as isTMA,
886
+ fr as createLogger,
887
+ rr as createPostEvent,
888
+ ir as createStartParam,
889
+ It as createStartParamFp,
890
+ ke as debug,
891
+ sr as decodeBase64Url,
892
+ Te as decodeBase64UrlFp,
893
+ ur as decodeStartParam,
894
+ Ot as decodeStartParamFp,
895
+ lr as deepSnakeToCamelObjKeys,
896
+ F as emitEvent,
897
+ $e as encodeBase64Url,
898
+ X as getReleaseVersion,
899
+ pe as hasWebviewProxy,
900
+ nr as invokeCustomMethod,
901
+ Wt as invokeCustomMethodFp,
902
+ _e as isIframe,
903
+ cr as isSafeToCreateStartParam,
904
+ er as isTMA,
854
905
  Lt as isTMAFp,
855
- h as logger,
856
- er as mockTelegramEnv,
857
- St as off,
906
+ g as logger,
907
+ tr as mockTelegramEnv,
908
+ At as off,
858
909
  $t as offAll,
859
- be as on,
910
+ z as on,
860
911
  Ct as postEvent,
861
- R as postEventFp,
912
+ A as postEventFp,
862
913
  Mt as postMessage,
863
- y as postMessageImpl,
864
- Xt as request,
865
- U as requestFp,
866
- Yt as resetGlobals,
867
- Nt as retrieveLaunchParams,
914
+ x as postMessageImpl,
915
+ or as request,
916
+ Zt as request2,
917
+ G as request2Fp,
918
+ Rt as requestFp,
919
+ Xt as resetGlobals,
920
+ Jt as retrieveLaunchParams,
868
921
  Et as retrieveLaunchParamsFp,
869
- Jt as retrieveRawInitData,
922
+ Qt as retrieveRawInitData,
870
923
  Pt as retrieveRawInitDataFp,
871
- Qt as retrieveRawLaunchParams,
872
- $ as retrieveRawLaunchParamsFp,
873
- Ht as setDebug,
874
- Kt as setTargetOrigin,
875
- X as supports,
876
- Ee as targetOrigin
924
+ Ht as retrieveRawLaunchParams,
925
+ L as retrieveRawLaunchParamsFp,
926
+ Kt as setDebug,
927
+ Yt as setTargetOrigin,
928
+ ee as supports,
929
+ Se as targetOrigin
877
930
  };
878
931
  //# sourceMappingURL=index.js.map