@tma.js/bridge 2.2.4 → 2.3.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,41 +1,42 @@
1
- import { is as O, looseObject as m, function as Y, nullish as v, boolean as I, number as $, string as E, optional as z, unknown as me, parse as F, any as we } from "valibot";
2
- import { throwifyFpFn as T, getStorageValue as de, setStorageValue as X, createLogger as ge, throwifyAnyEither as A, createCbCollector as Z, BetterTaskEither as ee } from "@tma.js/toolkit";
3
- import { createLogger as yt, deepSnakeToCamelObjKeys as vt } from "@tma.js/toolkit";
4
- import { BetterPromise as te, TimeoutError as be } from "better-promises";
5
- import { CancelledError as Pt, TimeoutError as kt } from "better-promises";
6
- import { function as f, either as c, option as L, taskEither as w, json as he } from "fp-ts";
7
- import { errorClassWithData as ye, errorClass as k } from "error-kid";
8
- import { parseLaunchParamsQueryFp as re, themeParams as ve, pipeJsonToSchema as ne, miniAppsMessage as oe, serializeLaunchParamsQuery as Ee, parseLaunchParamsQuery as Pe } from "@tma.js/transformers";
9
- import { signal as b, computed as ae } from "@tma.js/signals";
1
+ import * as T from "valibot";
2
+ import { looseObject as d, nullish as v, boolean as z, number as V, string as E, optional as B, unknown as we, parse as L, is as O, function as de, any as G } from "valibot";
3
+ import { throwifyFpFn as A, getStorageValue as be, setStorageValue as Z, createLogger as ge, throwifyAnyEither as C, createCbCollector as ee, BetterTaskEither as te } from "@tma.js/toolkit";
4
+ import { createLogger as vt, deepSnakeToCamelObjKeys as Et } from "@tma.js/toolkit";
5
+ import { BetterPromise as re, TimeoutError as he } from "better-promises";
6
+ import { CancelledError as xt, TimeoutError as kt } from "better-promises";
7
+ import { function as l, either as c, option as R, taskEither as f, json as ye } from "fp-ts";
8
+ import { errorClassWithData as ve, errorClass as x } from "error-kid";
9
+ import { parseLaunchParamsQueryFp as ne, themeParams as Ee, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as Pe, parseLaunchParamsQuery as xe } from "@tma.js/transformers";
10
+ import { signal as g, computed as se } from "@tma.js/signals";
10
11
  import ke from "mitt";
11
- function se(e) {
12
- return O(
13
- m({ TelegramWebviewProxy: m({ postEvent: Y() }) }),
14
- e
12
+ function ie(e) {
13
+ return typeof e == "object" && !!e && !Array.isArray(e) && T.is(
14
+ T.looseObject({ TelegramWebviewProxy: T.looseObject({ postEvent: T.function() }) }),
15
+ { TelegramWebviewProxy: e.TelegramWebviewProxy }
15
16
  );
16
17
  }
17
- function ie() {
18
+ function pe() {
18
19
  try {
19
20
  return window.self !== window.top;
20
21
  } catch {
21
22
  return !0;
22
23
  }
23
24
  }
24
- class xe extends (/* @__PURE__ */ k({
25
+ class Te extends (/* @__PURE__ */ x({
25
26
  name: "MethodUnsupportedError",
26
27
  super: (t, r) => [
27
28
  `Method "${t}" is unsupported in Mini Apps version ${r}`
28
29
  ]
29
30
  })) {
30
31
  }
31
- class Se extends (/* @__PURE__ */ k({
32
+ class Se extends (/* @__PURE__ */ x({
32
33
  name: "MethodParameterUnsupportedError",
33
34
  super: (t, r, n) => [
34
35
  `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
35
36
  ]
36
37
  })) {
37
38
  }
38
- class Te extends (/* @__PURE__ */ ye({
39
+ class Ae extends (/* @__PURE__ */ ve({
39
40
  name: "LaunchParamsRetrieveError",
40
41
  data: (t) => ({ errors: t }),
41
42
  super: (t) => [
@@ -51,7 +52,7 @@ class Te extends (/* @__PURE__ */ ye({
51
52
  ]
52
53
  })) {
53
54
  }
54
- class Ae extends (/* @__PURE__ */ k({
55
+ class Ce extends (/* @__PURE__ */ x({
55
56
  name: "InvalidLaunchParamsError",
56
57
  super: (t, r) => [
57
58
  `Invalid value for launch params: ${t}`,
@@ -59,86 +60,86 @@ class Ae extends (/* @__PURE__ */ k({
59
60
  ]
60
61
  })) {
61
62
  }
62
- class pe extends (/* @__PURE__ */ k({ name: "UnknownEnvError" })) {
63
+ class ce extends (/* @__PURE__ */ x({ name: "UnknownEnvError" })) {
63
64
  }
64
- class Ce extends (/* @__PURE__ */ k({
65
+ class Me extends (/* @__PURE__ */ x({
65
66
  name: "InvokeCustomMethodError",
66
67
  super: (t) => [`Server returned error: ${t}`]
67
68
  })) {
68
69
  }
69
- const V = "launchParams";
70
- function B(e) {
70
+ const D = "launchParams";
71
+ function J(e) {
71
72
  return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
72
73
  }
73
- function Me() {
74
- return f.pipe(
75
- C(),
76
- c.chainW(re)
74
+ function We() {
75
+ return l.pipe(
76
+ M(),
77
+ c.chainW(ne)
77
78
  );
78
79
  }
79
- const tt = T(Me);
80
- function qe() {
81
- return f.pipe(
82
- C(),
80
+ const rt = A(We);
81
+ function je() {
82
+ return l.pipe(
83
+ M(),
83
84
  c.map((e) => {
84
85
  const t = new URLSearchParams(e).get("tgWebAppData");
85
- return t ? L.some(t) : L.none;
86
+ return t ? R.some(t) : R.none;
86
87
  })
87
88
  );
88
89
  }
89
- function rt() {
90
- return f.pipe(
91
- qe(),
90
+ function nt() {
91
+ return l.pipe(
92
+ je(),
92
93
  c.fold((e) => {
93
94
  throw e;
94
95
  }, (e) => e),
95
- L.match(() => {
96
+ R.match(() => {
96
97
  }, (e) => e)
97
98
  );
98
99
  }
99
- function C() {
100
+ function M() {
100
101
  const e = [];
101
102
  for (const [t, r] of [
102
103
  // Try to retrieve launch parameters from the current location. This method
103
104
  // can return nothing in case, location was changed, and then the page was
104
105
  // reloaded.
105
- [() => B(window.location.href), "window.location.href"],
106
+ [() => J(window.location.href), "window.location.href"],
106
107
  // Then, try using the lower level API - window.performance.
107
108
  [() => {
108
109
  const n = performance.getEntriesByType("navigation")[0];
109
- return n && B(n.name);
110
+ return n && J(n.name);
110
111
  }, "performance navigation entries"],
111
112
  // Finally, try using the session storage.
112
- [() => de(V), "local storage"]
113
+ [() => be(D), "local storage"]
113
114
  ]) {
114
115
  const n = t();
115
116
  if (!n) {
116
117
  e.push({ source: r, error: new Error("Source is empty") });
117
118
  continue;
118
119
  }
119
- const a = f.pipe(
120
- re(n),
120
+ const a = l.pipe(
121
+ ne(n),
121
122
  c.foldW((o) => o, () => !0)
122
123
  );
123
124
  if (typeof a != "boolean") {
124
125
  e.push({ source: r, error: a });
125
126
  continue;
126
127
  }
127
- return X(V, n), c.right(n);
128
+ return Z(D, n), c.right(n);
128
129
  }
129
- return c.left(new Te(e));
130
+ return c.left(new Ae(e));
130
131
  }
131
- const nt = T(C);
132
- function We(e, t) {
132
+ const ot = A(M);
133
+ function qe(e, t) {
133
134
  const r = /* @__PURE__ */ new Map(), n = ke(), a = (o, s, p = !1) => {
134
135
  const _ = r.get(o) || /* @__PURE__ */ new Map();
135
136
  r.set(o, _);
136
137
  const i = _.get(s) || [];
137
138
  _.set(s, i);
138
- const u = i.findIndex((l) => l[1] === p);
139
+ const u = i.findIndex((m) => m[1] === p);
139
140
  if (u >= 0 && (n.off(o, i[u][0]), i.splice(u, 1), !i.length && (_.delete(s), !_.size))) {
140
- const l = r.size;
141
- r.delete(o), l && !r.size && t();
141
+ const m = r.size;
142
+ r.delete(o), m && !r.size && t();
142
143
  }
143
144
  };
144
145
  return {
@@ -146,14 +147,14 @@ function We(e, t) {
146
147
  !r.size && e();
147
148
  const _ = () => {
148
149
  a(o, s, p);
149
- }, i = (...d) => {
150
- p && _(), o === "*" ? s({ name: d[0], payload: d[1] }) : s(...d);
150
+ }, i = (...w) => {
151
+ p && _(), o === "*" ? s({ name: w[0], payload: w[1] }) : s(...w);
151
152
  };
152
153
  n.on(o, i);
153
154
  const u = r.get(o) || /* @__PURE__ */ new Map();
154
155
  r.set(o, u);
155
- const l = u.get(s) || [];
156
- return u.set(s, l), l.push([i, p || !1]), _;
156
+ const m = u.get(s) || [];
157
+ return u.set(s, m), m.push([i, p || !1]), _;
157
158
  },
158
159
  off: a,
159
160
  // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -164,7 +165,7 @@ function We(e, t) {
164
165
  }
165
166
  };
166
167
  }
167
- function q(e, t) {
168
+ function j(e, t) {
168
169
  window.dispatchEvent(new MessageEvent("message", {
169
170
  data: JSON.stringify({ eventType: e, eventData: t }),
170
171
  // We specify this kind of source here in order to allow the package's "on" function to
@@ -173,29 +174,29 @@ function q(e, t) {
173
174
  source: window.parent
174
175
  }));
175
176
  }
176
- const S = b(!1), R = b("https://web.telegram.org"), Fe = (e) => {
177
- g().log("Event received:", e);
178
- }, ce = ae(S);
179
- function ot(e) {
180
- e !== S() && (S.set(e), (e ? j : Oe)("*", Fe));
181
- }
182
- const _e = ae(R);
177
+ const S = g(!1), U = g("https://web.telegram.org"), Fe = (e) => {
178
+ b().log("Event received:", e);
179
+ }, _e = se(S);
183
180
  function at(e) {
184
- R.set(e), g().log("New target origin set", e);
181
+ e !== S() && (S.set(e), (e ? I : Oe)("*", Fe));
182
+ }
183
+ const ue = se(U);
184
+ function st(e) {
185
+ U.set(e), b().log("New target origin set", e);
185
186
  }
186
- const P = b((...e) => {
187
+ const P = g((...e) => {
187
188
  window.parent.postMessage(...e);
188
- }), g = b(ge("Bridge", {
189
+ }), b = g(ge("Bridge", {
189
190
  bgColor: "#9147ff",
190
191
  textColor: "white",
191
- shouldLog: ce
192
+ shouldLog: _e
192
193
  }));
193
- function st() {
194
- je(), [P, R, _e, S, ce, g].forEach((e) => {
194
+ function it() {
195
+ Ue(), [P, U, ue, S, _e, b].forEach((e) => {
195
196
  e.unsubAll(), "reset" in e && e.reset();
196
197
  });
197
198
  }
198
- function W(e, t, r) {
199
+ function q(e, t, r) {
199
200
  const n = [r], a = e[t];
200
201
  typeof a == "function" && n.push(a);
201
202
  const o = (...p) => {
@@ -211,28 +212,28 @@ function W(e, t, r) {
211
212
  return;
212
213
  }
213
214
  if (p === 2) {
214
- D(e, t, n[1]);
215
+ Q(e, t, n[1]);
215
216
  return;
216
217
  }
217
- n.unshift(1), D(e, t, o);
218
+ n.unshift(1), Q(e, t, o);
218
219
  }
219
220
  });
220
- ue(
221
+ me(
221
222
  e,
222
223
  t,
223
224
  () => s,
224
225
  (p) => n.push(p)
225
226
  );
226
227
  }
227
- function G(e, t) {
228
+ function N(e, t) {
228
229
  const r = e[t];
229
- ue(e, t, () => r, (n) => {
230
+ me(e, t, () => r, (n) => {
230
231
  Object.entries(n).forEach(([a, o]) => {
231
232
  r[a] = o;
232
233
  });
233
234
  });
234
235
  }
235
- function ue(e, t, r, n) {
236
+ function me(e, t, r, n) {
236
237
  Object.defineProperty(e, t, {
237
238
  enumerable: !0,
238
239
  configurable: !0,
@@ -240,7 +241,7 @@ function ue(e, t, r, n) {
240
241
  set: n
241
242
  });
242
243
  }
243
- function D(e, t, r) {
244
+ function Q(e, t, r) {
244
245
  Object.defineProperty(e, t, {
245
246
  enumerable: !0,
246
247
  configurable: !0,
@@ -249,26 +250,26 @@ function D(e, t, r) {
249
250
  });
250
251
  }
251
252
  const Le = {
252
- clipboard_text_received: m({
253
+ clipboard_text_received: d({
253
254
  req_id: E(),
254
255
  data: v(E())
255
256
  }),
256
- custom_method_invoked: m({
257
+ custom_method_invoked: d({
257
258
  req_id: E(),
258
- result: z(me()),
259
- error: z(E())
259
+ result: B(we()),
260
+ error: B(E())
260
261
  }),
261
262
  popup_closed: v(
262
- m({ button_id: v(E(), () => {
263
+ d({ button_id: v(E(), () => {
263
264
  }) }),
264
265
  {}
265
266
  ),
266
267
  viewport_changed: v(
267
- m({
268
- height: $(),
269
- width: v($(), () => window.innerWidth),
270
- is_state_stable: I(),
271
- is_expanded: I()
268
+ d({
269
+ height: V(),
270
+ width: v(V(), () => window.innerWidth),
271
+ is_state_stable: z(),
272
+ is_expanded: z()
272
273
  }),
273
274
  // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
274
275
  // null. Leaving this default value until the bug is fixed.
@@ -278,25 +279,25 @@ const Le = {
278
279
  is_expanded: !0
279
280
  })
280
281
  ),
281
- theme_changed: m({
282
- theme_params: ve()
282
+ theme_changed: d({
283
+ theme_params: Ee()
283
284
  })
284
285
  };
285
- function J(e) {
286
+ function H(e) {
286
287
  if (e.source !== window.parent)
287
288
  return;
288
289
  let t;
289
290
  try {
290
- t = F(ne(oe()), e.data);
291
+ t = L(oe(ae()), e.data);
291
292
  } catch {
292
293
  return;
293
294
  }
294
295
  const { eventType: r, eventData: n } = t, a = Le[r];
295
296
  let o;
296
297
  try {
297
- o = a ? F(a, n) : n;
298
+ o = a ? L(a, n) : n;
298
299
  } catch (s) {
299
- return g().forceError(
300
+ return b().forceError(
300
301
  [
301
302
  `An error occurred processing the "${r}" event from the Telegram application.`,
302
303
  "Please, file an issue here:",
@@ -310,14 +311,14 @@ function J(e) {
310
311
  Re(r, o);
311
312
  }
312
313
  const {
313
- on: j,
314
+ on: I,
314
315
  off: Oe,
315
316
  emit: Re,
316
- clear: je
317
- } = We(
317
+ clear: Ue
318
+ } = qe(
318
319
  () => {
319
320
  const e = window;
320
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), W(e.TelegramGameProxy, "receiveEvent", q), G(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), W(e.Telegram.WebView, "receiveEvent", q), G(e.Telegram, "WebView"), W(e, "TelegramGameProxy_receiveEvent", q), window.addEventListener("message", J);
321
+ !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", j), N(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), q(e.Telegram.WebView, "receiveEvent", j), N(e.Telegram, "WebView"), q(e, "TelegramGameProxy_receiveEvent", j), window.addEventListener("message", H);
321
322
  },
322
323
  () => {
323
324
  [
@@ -332,12 +333,12 @@ const {
332
333
  return;
333
334
  const [n, a] = r;
334
335
  "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
335
- }), window.removeEventListener("message", J);
336
+ }), window.removeEventListener("message", H);
336
337
  }
337
- ), Ue = (...e) => P()(...e);
338
- function Ie(e, t) {
339
- f.pipe(
340
- x(
338
+ ), Ie = (...e) => P()(...e);
339
+ function $e(e, t) {
340
+ l.pipe(
341
+ k(
341
342
  // @ts-expect-error It's ok, TS can't determine a specific override.
342
343
  e,
343
344
  t
@@ -347,49 +348,49 @@ function Ie(e, t) {
347
348
  })
348
349
  );
349
350
  }
350
- function x(e, t) {
351
- g().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
351
+ function k(e, t) {
352
+ b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
352
353
  const r = window, n = JSON.stringify({ eventType: e, eventData: t });
353
- return ie() ? (Ue(n, _e()), c.right(void 0)) : se(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(m({ external: m({ notify: Y() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new pe());
354
+ return pe() ? (Ie(n, ue()), c.right(void 0)) : ie(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(d({ external: d({ notify: de() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new ce());
354
355
  }
355
- function U(e, t, r = {}) {
356
+ function $(e, t, r = {}) {
356
357
  const {
357
358
  // If no capture function was passed, we capture the first compatible event.
358
359
  capture: n = () => !0,
359
- postEvent: a = x
360
- } = r, o = b(), [s, p] = Z();
360
+ postEvent: a = k
361
+ } = r, o = g(), [s, p] = ee();
361
362
  (Array.isArray(t) ? t : [t]).forEach((i) => {
362
363
  s(
363
- j(i, (u) => {
364
- const l = Array.isArray(t);
365
- n(l ? { event: i, payload: u } : u) && o.set([
366
- l ? { event: i, payload: u } : u
364
+ I(i, (u) => {
365
+ const m = Array.isArray(t);
366
+ n(m ? { event: i, payload: u } : u) && o.set([
367
+ m ? { event: i, payload: u } : u
367
368
  ]);
368
369
  })
369
370
  );
370
371
  });
371
372
  const _ = (i) => (p(), i);
372
- return f.pipe(
373
+ return l.pipe(
373
374
  async () => a(e, r.params),
374
- w.chainW(() => ee((i, u, l) => {
375
- const d = o();
376
- if (d)
377
- return i(d[0]);
375
+ f.chainW(() => te((i, u, m) => {
376
+ const w = o();
377
+ if (w)
378
+ return i(w[0]);
378
379
  const h = (y) => {
379
380
  y && i(y[0]);
380
- }, M = () => {
381
+ }, W = () => {
381
382
  o.unsub(h);
382
383
  };
383
- o.sub(h), l.on("finalized", M);
384
+ o.sub(h), m.on("finalized", W);
384
385
  }, r)),
385
- w.mapBoth(_, _)
386
+ f.mapBoth(_, _)
386
387
  );
387
388
  }
388
- function it(e, t, r) {
389
+ function pt(e, t, r) {
389
390
  const { postEvent: n } = r || {};
390
- return A(
391
+ return C(
391
392
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
392
- U(e, t, {
393
+ $(e, t, {
393
394
  ...r,
394
395
  postEvent: n ? (...a) => {
395
396
  try {
@@ -397,49 +398,49 @@ function it(e, t, r) {
397
398
  } catch (o) {
398
399
  return c.left(o);
399
400
  }
400
- } : x
401
+ } : k
401
402
  })
402
403
  );
403
404
  }
404
- function pt(e, t) {
405
- const r = $e(
405
+ function ct(e, t) {
406
+ const r = ze(
406
407
  // @ts-expect-error TS doesn't get what override we are going to use.
407
408
  e,
408
409
  t
409
410
  );
410
- return typeof r == "function" ? te.fn(() => A(r)) : r;
411
+ return typeof r == "function" ? re.fn(() => C(r)) : r;
411
412
  }
412
- function $e(e, t) {
413
- const r = se(window);
413
+ function ze(e, t) {
414
+ const r = ie(window);
414
415
  if (!e)
415
- return r || f.pipe(C(), c.match(() => !1, () => !0));
416
+ return r || l.pipe(M(), c.match(() => !1, () => !0));
416
417
  if (r)
417
- return w.right(!0);
418
+ return f.right(!0);
418
419
  const { timeout: n = 100 } = t || {};
419
- return f.pipe(
420
- U("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
421
- w.match(
422
- (a) => be.is(a) || pe.is(a) ? c.right(!1) : c.left(a),
420
+ return l.pipe(
421
+ $("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
422
+ f.match(
423
+ (a) => he.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
423
424
  () => c.right(!0)
424
425
  )
425
426
  );
426
427
  }
427
- function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
428
+ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
428
429
  if (e) {
429
430
  const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
430
431
  // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
431
432
  // value. We are doing it because we are working with tgWebAppData presented as a
432
433
  // string, not an object as serializeLaunchParamsQuery requires.
433
- Ee({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
434
+ Pe({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
434
435
  );
435
436
  try {
436
- Pe(o);
437
+ xe(o);
437
438
  } catch (s) {
438
- throw new Ae(o, s);
439
+ throw new Ce(o, s);
439
440
  }
440
- X("launchParams", o);
441
+ Z("launchParams", o);
441
442
  }
442
- if (ie()) {
443
+ if (pe()) {
443
444
  if (!t)
444
445
  return;
445
446
  r && P.reset();
@@ -449,7 +450,7 @@ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
449
450
  o(...s);
450
451
  };
451
452
  try {
452
- const i = F(ne(oe()), p);
453
+ const i = L(oe(ae()), p);
453
454
  t({ name: i.eventType, params: i.eventData }, _);
454
455
  } catch {
455
456
  _();
@@ -470,12 +471,12 @@ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
470
471
  params: s ? JSON.parse(s) : void 0
471
472
  }, p) : p();
472
473
  }
473
- }, g().log("Environment was mocked by the mockTelegramEnv function");
474
+ }, b().log("Environment was mocked by the mockTelegramEnv function");
474
475
  }
475
- function ze(e) {
476
+ function Ve(e) {
476
477
  return ({ req_id: t }) => t === e;
477
478
  }
478
- const N = {
479
+ const K = {
479
480
  "6.0": [
480
481
  "iframe_ready",
481
482
  "iframe_will_reload",
@@ -561,16 +562,20 @@ const N = {
561
562
  "web_app_secure_storage_restore_key",
562
563
  "web_app_secure_storage_save_key"
563
564
  ],
564
- 9.1: ["web_app_hide_keyboard"]
565
+ 9.1: ["web_app_hide_keyboard"],
566
+ 9.5: [
567
+ { method: "web_app_setup_main_button", param: "icon_custom_emoji_id" },
568
+ { method: "web_app_setup_secondary_button", param: "icon_custom_emoji_id" }
569
+ ]
565
570
  };
566
- function Q(e, t) {
567
- return Object.keys(N).find((n) => N[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
571
+ function Y(e, t) {
572
+ return Object.keys(K).find((n) => K[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
568
573
  }
569
- function H(e) {
574
+ function X(e) {
570
575
  return e.split(".").map(Number);
571
576
  }
572
- function Ve(e, t) {
573
- const r = H(e), n = H(t), a = Math.max(r.length, n.length);
577
+ function Be(e, t) {
578
+ const r = X(e), n = X(t), a = Math.max(r.length, n.length);
574
579
  for (let o = 0; o < a; o += 1) {
575
580
  const s = r[o] || 0, p = n[o] || 0;
576
581
  if (s !== p)
@@ -578,37 +583,37 @@ function Ve(e, t) {
578
583
  }
579
584
  return 0;
580
585
  }
581
- function K(e, t, r) {
582
- const n = r ? Q(
586
+ function F(e, t, r) {
587
+ const n = r ? Y(
583
588
  e,
584
589
  t
585
- ) : Q(e);
586
- return n ? Ve(n, r || t) <= 0 : !1;
590
+ ) : Y(e);
591
+ return n ? Be(n, r || t) <= 0 : !1;
587
592
  }
588
- function _t(e, t = "strict") {
593
+ function ut(e, t = "strict") {
589
594
  const r = typeof t == "function" ? t : (n) => {
590
- const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new xe(a, o);
595
+ const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new Te(a, o);
591
596
  if (t === "strict")
592
597
  throw s;
593
- return g().forceWarn(s.message);
598
+ return b().forceWarn(s.message);
594
599
  };
595
- return (n, a) => K(n, e) ? n === "web_app_set_header_color" && O(m({ color: we() }), a) && !K(n, "color", e) ? r({ version: e, method: n, param: "color" }) : Ie(n, a) : r({ version: e, method: n });
600
+ return (n, a) => F(n, e) ? n === "web_app_set_header_color" && O(d({ color: G() }), a) && !F(n, "color", e) ? r({ version: e, method: n, param: "color" }) : (n === "web_app_setup_main_button" || n === "web_app_setup_secondary_button") && O(d({ icon_custom_emoji_id: G() }), a) && !F(n, "icon_custom_emoji_id", e) ? r({ version: e, method: n, param: "icon_custom_emoji_id" }) : $e(n, a) : r({ version: e, method: n });
596
601
  }
597
- function Be(e, t, r, n) {
598
- return f.pipe(
599
- U("web_app_invoke_custom_method", "custom_method_invoked", {
602
+ function Ge(e, t, r, n) {
603
+ return l.pipe(
604
+ $("web_app_invoke_custom_method", "custom_method_invoked", {
600
605
  ...n || {},
601
606
  params: { method: e, params: t, req_id: r },
602
- capture: ze(r)
607
+ capture: Ve(r)
603
608
  }),
604
- w.chain(({ result: a, error: o }) => o ? w.left(new Ce(o)) : w.right(a))
609
+ f.chain(({ result: a, error: o }) => o ? f.left(new Me(o)) : f.right(a))
605
610
  );
606
611
  }
607
- function ut(e, t, r, n) {
608
- return te.fn(() => f.pipe(
612
+ function mt(e, t, r, n) {
613
+ return re.fn(() => l.pipe(
609
614
  // @ts-expect-error TypeScript is unable to determine required override.
610
- Be(e, t, r, n),
611
- w.match(
615
+ Ge(e, t, r, n),
616
+ f.match(
612
617
  (a) => {
613
618
  throw a;
614
619
  },
@@ -616,41 +621,41 @@ function ut(e, t, r, n) {
616
621
  )
617
622
  )());
618
623
  }
619
- function Ge(e, t, r = {}) {
624
+ function De(e, t, r = {}) {
620
625
  const {
621
626
  // If no capture function was passed, we capture the first compatible event.
622
627
  capture: n = () => !0,
623
- postEvent: a = x
624
- } = r, o = b(), [s, p] = Z();
628
+ postEvent: a = k
629
+ } = r, o = g(), [s, p] = ee();
625
630
  (Array.isArray(t) ? t : [t]).forEach((i) => {
626
631
  s(
627
- j(i, (u) => {
632
+ I(i, (u) => {
628
633
  (Array.isArray(t) ? n({ event: i, payload: u }) : n(u)) && o.set([u]);
629
634
  })
630
635
  );
631
636
  });
632
637
  const _ = (i) => (p(), i);
633
- return f.pipe(
638
+ return l.pipe(
634
639
  async () => a(e, r.params),
635
- w.chainW(() => ee((i, u, l) => {
636
- const d = o();
637
- if (d)
638
- return i(d[0]);
640
+ f.chainW(() => te((i, u, m) => {
641
+ const w = o();
642
+ if (w)
643
+ return i(w[0]);
639
644
  const h = (y) => {
640
645
  y && i(y[0]);
641
- }, M = () => {
646
+ }, W = () => {
642
647
  o.unsub(h);
643
648
  };
644
- o.sub(h), l.on("finalized", M);
649
+ o.sub(h), m.on("finalized", W);
645
650
  }, r)),
646
- w.mapBoth(_, _)
651
+ f.mapBoth(_, _)
647
652
  );
648
653
  }
649
654
  function lt(e, t, r) {
650
655
  const { postEvent: n } = r || {};
651
- return A(
656
+ return C(
652
657
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
653
- Ge(e, t, {
658
+ De(e, t, {
654
659
  ...r,
655
660
  postEvent: n ? (...a) => {
656
661
  try {
@@ -658,7 +663,7 @@ function lt(e, t, r) {
658
663
  } catch (o) {
659
664
  return c.left(o);
660
665
  }
661
- } : x
666
+ } : k
662
667
  })
663
668
  );
664
669
  }
@@ -674,90 +679,90 @@ function le(e) {
674
679
  ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
675
680
  ), (t) => t);
676
681
  }
677
- const mt = T(le);
682
+ const wt = A(le);
678
683
  function fe(e) {
679
684
  return btoa(
680
685
  encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
681
686
  ).replace(/\+/g, "-").replace(/\//g, "_");
682
687
  }
683
- function De(e) {
688
+ function Je(e) {
684
689
  const t = fe(typeof e == "string" ? e : JSON.stringify(e));
685
690
  return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
686
691
  }
687
- const wt = T(De);
688
- function dt(e, t) {
689
- return A(
690
- Je(
692
+ const dt = A(Je);
693
+ function bt(e, t) {
694
+ return C(
695
+ Ne(
691
696
  e,
692
697
  // @ts-expect-error TypeScript is unable to detect a correct override.
693
698
  typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
694
699
  )
695
700
  );
696
701
  }
697
- function Je(e, t) {
698
- return f.pipe(
702
+ function Ne(e, t) {
703
+ return l.pipe(
699
704
  le(e),
700
- c.chain((r) => t ? typeof t == "function" ? t(r) : he.parse(r) : c.right(r))
705
+ c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(r))
701
706
  );
702
707
  }
703
708
  function gt(e) {
704
709
  return fe(e).length <= 512;
705
710
  }
706
711
  export {
707
- Pt as CancelledError,
708
- Ae as InvalidLaunchParamsError,
709
- Ce as InvokeCustomMethodFailedError,
710
- Te as LaunchParamsRetrieveError,
712
+ xt as CancelledError,
713
+ Ce as InvalidLaunchParamsError,
714
+ Me as InvokeCustomMethodFailedError,
715
+ Ae as LaunchParamsRetrieveError,
711
716
  Se as MethodParameterUnsupportedError,
712
- xe as MethodUnsupportedError,
717
+ Te as MethodUnsupportedError,
713
718
  kt as TimeoutError,
714
- pe as UnknownEnvError,
719
+ ce as UnknownEnvError,
715
720
  ft as applyPolyfills,
716
- ze as captureSameReq,
717
- Ve as compareVersions,
718
- yt as createLogger,
719
- _t as createPostEvent,
720
- wt as createStartParam,
721
- De as createStartParamFp,
722
- ce as debug,
723
- mt as decodeBase64Url,
721
+ Ve as captureSameReq,
722
+ Be as compareVersions,
723
+ vt as createLogger,
724
+ ut as createPostEvent,
725
+ dt as createStartParam,
726
+ Je as createStartParamFp,
727
+ _e as debug,
728
+ wt as decodeBase64Url,
724
729
  le as decodeBase64UrlFp,
725
- dt as decodeStartParam,
726
- Je as decodeStartParamFp,
727
- vt as deepSnakeToCamelObjKeys,
728
- q as emitEvent,
730
+ bt as decodeStartParam,
731
+ Ne as decodeStartParamFp,
732
+ Et as deepSnakeToCamelObjKeys,
733
+ j as emitEvent,
729
734
  fe as encodeBase64Url,
730
- Q as getReleaseVersion,
731
- se as hasWebviewProxy,
732
- ut as invokeCustomMethod,
733
- Be as invokeCustomMethodFp,
734
- ie as isIframe,
735
+ Y as getReleaseVersion,
736
+ ie as hasWebviewProxy,
737
+ mt as invokeCustomMethod,
738
+ Ge as invokeCustomMethodFp,
739
+ pe as isIframe,
735
740
  gt as isSafeToCreateStartParam,
736
- pt as isTMA,
737
- $e as isTMAFp,
738
- g as logger,
739
- ct as mockTelegramEnv,
741
+ ct as isTMA,
742
+ ze as isTMAFp,
743
+ b as logger,
744
+ _t as mockTelegramEnv,
740
745
  Oe as off,
741
- je as offAll,
742
- j as on,
743
- Ie as postEvent,
744
- x as postEventFp,
745
- Ue as postMessage,
746
+ Ue as offAll,
747
+ I as on,
748
+ $e as postEvent,
749
+ k as postEventFp,
750
+ Ie as postMessage,
746
751
  P as postMessageImpl,
747
752
  lt as request,
748
- it as request2,
749
- U as request2Fp,
750
- Ge as requestFp,
751
- st as resetGlobals,
752
- tt as retrieveLaunchParams,
753
- Me as retrieveLaunchParamsFp,
754
- rt as retrieveRawInitData,
755
- qe as retrieveRawInitDataFp,
756
- nt as retrieveRawLaunchParams,
757
- C as retrieveRawLaunchParamsFp,
758
- ot as setDebug,
759
- at as setTargetOrigin,
760
- K as supports,
761
- _e as targetOrigin
753
+ pt as request2,
754
+ $ as request2Fp,
755
+ De as requestFp,
756
+ it as resetGlobals,
757
+ rt as retrieveLaunchParams,
758
+ We as retrieveLaunchParamsFp,
759
+ nt as retrieveRawInitData,
760
+ je as retrieveRawInitDataFp,
761
+ ot as retrieveRawLaunchParams,
762
+ M as retrieveRawLaunchParamsFp,
763
+ at as setDebug,
764
+ st as setTargetOrigin,
765
+ F as supports,
766
+ ue as targetOrigin
762
767
  };
763
768
  //# sourceMappingURL=index.js.map