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