@vbotma/bridge 2.2.9 → 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,16 +1,16 @@
1
- import { is as O, looseObject as w, function as re, nullish as E, boolean as D, number as G, string as P, optional as J, unknown as ge, parse as A, any as ye } from "valibot";
2
- import { throwifyFpFn as W, getStorageValue as ve, setStorageValue as R, createLogger as Ee, throwifyAnyEither as C, createCbCollector as ne, BetterTaskEither as oe } from "@vbotma/toolkit";
3
- import { createLogger as xt, deepSnakeToCamelObjKeys as St } from "@vbotma/toolkit";
4
- import { BetterPromise as ae, TimeoutError as Pe } from "better-promises";
5
- import { CancelledError as At, TimeoutError as Bt } from "better-promises";
1
+ import { is as O, looseObject as w, function as ne, nullish as P, boolean as J, number as G, string as x, optional as H, unknown as he, parse as B, any as ye } from "valibot";
2
+ import { throwifyFpFn as A, getStorageValue as ve, setStorageValue as R, createLogger as Ee, throwifyAnyEither as V, createCbCollector as oe, BetterTaskEither as ae } from "@vbotma/toolkit";
3
+ import { createLogger as St, deepSnakeToCamelObjKeys as kt } from "@vbotma/toolkit";
4
+ import { BetterPromise as se, TimeoutError as Pe } from "better-promises";
5
+ import { CancelledError as Bt, TimeoutError as Ct } from "better-promises";
6
6
  import { function as l, either as c, option as F, taskEither as d, json as xe } from "fp-ts";
7
7
  import { errorClassWithData as Se, errorClass as S } from "error-kid";
8
- import { parseLaunchParamsQueryFp as se, themeParams as ke, pipeJsonToSchema as T, miniAppsMessage as U, serializeLaunchParamsQuery as ie, parseLaunchParamsQuery as pe } from "@vbotma/transformers";
9
- import { signal as g, computed as ce } from "@vbotma/signals";
10
- import Ae from "mitt";
11
- function _e(e) {
8
+ import { parseLaunchParamsQueryFp as ie, themeParams as ke, pipeJsonToSchema as T, miniAppsMessage as U, serializeLaunchParamsQuery as pe, parseLaunchParamsQuery as ce } from "@vbotma/transformers";
9
+ import { signal as y, computed as _e } from "@vbotma/signals";
10
+ import We from "mitt";
11
+ function ue(e) {
12
12
  return O(
13
- w({ VBotWebviewProxy: w({ postEvent: re() }) }),
13
+ w({ VBotWebviewProxy: w({ postEvent: ne() }) }),
14
14
  e
15
15
  );
16
16
  }
@@ -28,11 +28,11 @@ class Be extends (/* @__PURE__ */ S(
28
28
  ]
29
29
  )) {
30
30
  }
31
- class We extends (/* @__PURE__ */ S("MethodParameterUnsupportedError", (t, r, n) => [
31
+ class Ce extends (/* @__PURE__ */ S("MethodParameterUnsupportedError", (t, r, n) => [
32
32
  `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
33
33
  ])) {
34
34
  }
35
- class Ce extends (/* @__PURE__ */ Se(
35
+ class Ae extends (/* @__PURE__ */ Se(
36
36
  "LaunchParamsRetrieveError",
37
37
  (t) => ({ errors: t }),
38
38
  (t) => [
@@ -46,7 +46,7 @@ class Ce extends (/* @__PURE__ */ Se(
46
46
  ]
47
47
  )) {
48
48
  }
49
- class ue extends (/* @__PURE__ */ S(
49
+ class fe extends (/* @__PURE__ */ S(
50
50
  "InvalidLaunchParamsError",
51
51
  (t, r) => [
52
52
  `Invalid value for launch params: ${t}`,
@@ -54,27 +54,27 @@ class ue extends (/* @__PURE__ */ S(
54
54
  ]
55
55
  )) {
56
56
  }
57
- class fe extends (/* @__PURE__ */ S("UnknownEnvError")) {
57
+ class le extends (/* @__PURE__ */ S("UnknownEnvError")) {
58
58
  }
59
59
  class Ve extends (/* @__PURE__ */ S(
60
60
  "InvokeCustomMethodError",
61
61
  (t) => [`Server returned error: ${t}`]
62
62
  )) {
63
63
  }
64
- const H = "launchParams";
65
- function N(e) {
64
+ const N = "launchParams";
65
+ function Q(e) {
66
66
  return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
67
67
  }
68
68
  function Le() {
69
69
  return l.pipe(
70
- V(),
71
- c.chainW(se)
70
+ L(),
71
+ c.chainW(ie)
72
72
  );
73
73
  }
74
- const rt = W(Le);
74
+ const rt = A(Le);
75
75
  function Me() {
76
76
  return l.pipe(
77
- V(),
77
+ L(),
78
78
  c.map((e) => {
79
79
  const t = new URLSearchParams(e).get("vbWebAppData");
80
80
  return t ? F.some(t) : F.none;
@@ -91,20 +91,20 @@ function nt() {
91
91
  }, (e) => e)
92
92
  );
93
93
  }
94
- function V() {
94
+ function L() {
95
95
  const e = [];
96
96
  for (const [t, r] of [
97
97
  // Try to retrieve launch parameters from the current location. This method
98
98
  // can return nothing in case, location was changed, and then the page was
99
99
  // reloaded.
100
- [() => N(window.location.href), "window.location.href"],
100
+ [() => Q(window.location.href), "window.location.href"],
101
101
  // Then, try using the lower level API - window.performance.
102
102
  [() => {
103
103
  const n = performance.getEntriesByType("navigation")[0];
104
- return n && N(n.name);
104
+ return n && Q(n.name);
105
105
  }, "performance navigation entries"],
106
106
  // Finally, try using the session storage.
107
- [() => ve(H), "local storage"]
107
+ [() => ve(N), "local storage"]
108
108
  ]) {
109
109
  const n = t();
110
110
  if (!n) {
@@ -112,20 +112,20 @@ function V() {
112
112
  continue;
113
113
  }
114
114
  const a = l.pipe(
115
- se(n),
115
+ ie(n),
116
116
  c.foldW((o) => o, () => !0)
117
117
  );
118
118
  if (typeof a != "boolean") {
119
119
  e.push({ source: r, error: a });
120
120
  continue;
121
121
  }
122
- return R(H, n), c.right(n);
122
+ return R(N, n), c.right(n);
123
123
  }
124
- return c.left(new Ce(e));
124
+ return c.left(new Ae(e));
125
125
  }
126
- const ot = W(V);
127
- function le(e, t) {
128
- const r = /* @__PURE__ */ new Map(), n = Ae(), a = (o, s, i = !1) => {
126
+ const ot = A(L);
127
+ function I(e, t) {
128
+ const r = /* @__PURE__ */ new Map(), n = We(), a = (o, s, i = !1) => {
129
129
  const _ = r.get(o) || /* @__PURE__ */ new Map();
130
130
  r.set(o, _);
131
131
  const p = _.get(s) || [];
@@ -159,7 +159,7 @@ function le(e, t) {
159
159
  }
160
160
  };
161
161
  }
162
- function M(e, t) {
162
+ function W(e, t) {
163
163
  window.dispatchEvent(new MessageEvent("message", {
164
164
  data: JSON.stringify({ eventType: e, eventData: t }),
165
165
  // We specify this kind of source here in order to allow the package's "on" function to
@@ -168,25 +168,25 @@ function M(e, t) {
168
168
  source: window.parent
169
169
  }));
170
170
  }
171
- const B = g(!1), I = g("https://web.telegram.org"), qe = (e) => {
171
+ const C = y(!1), $ = y("https://web.telegram.org"), qe = (e) => {
172
172
  h().log("Event received:", e);
173
- }, we = ce(B);
173
+ }, we = _e(C);
174
174
  function at(e) {
175
- e !== B() && (B.set(e), (e ? $ : Oe)("*", qe));
175
+ e !== C() && (C.set(e), (e ? z : Oe)("*", qe));
176
176
  }
177
- const de = ce(I);
177
+ const de = _e($);
178
178
  function st(e) {
179
- I.set(e), h().log("New target origin set", e);
179
+ $.set(e), h().log("New target origin set", e);
180
180
  }
181
- const b = g((...e) => {
181
+ const b = y((...e) => {
182
182
  window.parent.postMessage(...e);
183
- }), h = g(Ee("Bridge", {
183
+ }), h = y(Ee("Bridge", {
184
184
  bgColor: "#9147ff",
185
185
  textColor: "white",
186
186
  shouldLog: we
187
187
  }));
188
188
  function it() {
189
- Te(), [b, I, de, B, we, h].forEach((e) => {
189
+ Te(), [b, $, de, C, we, h].forEach((e) => {
190
190
  e.unsubAll(), "reset" in e && e.reset();
191
191
  });
192
192
  }
@@ -206,10 +206,10 @@ function q(e, t, r) {
206
206
  return;
207
207
  }
208
208
  if (i === 2) {
209
- K(e, t, n[1]);
209
+ Y(e, t, n[1]);
210
210
  return;
211
211
  }
212
- n.unshift(1), K(e, t, o);
212
+ n.unshift(1), Y(e, t, o);
213
213
  }
214
214
  });
215
215
  me(
@@ -219,7 +219,7 @@ function q(e, t, r) {
219
219
  (i) => n.push(i)
220
220
  );
221
221
  }
222
- function Q(e, t) {
222
+ function K(e, t) {
223
223
  const r = e[t];
224
224
  me(e, t, () => r, (n) => {
225
225
  Object.entries(n).forEach(([a, o]) => {
@@ -235,7 +235,7 @@ function me(e, t, r, n) {
235
235
  set: n
236
236
  });
237
237
  }
238
- function K(e, t, r) {
238
+ function Y(e, t, r) {
239
239
  Object.defineProperty(e, t, {
240
240
  enumerable: !0,
241
241
  configurable: !0,
@@ -245,25 +245,25 @@ function K(e, t, r) {
245
245
  }
246
246
  const Fe = {
247
247
  clipboard_text_received: w({
248
- req_id: P(),
249
- data: E(P())
248
+ req_id: x(),
249
+ data: P(x())
250
250
  }),
251
251
  custom_method_invoked: w({
252
- req_id: P(),
253
- result: J(ge()),
254
- error: J(P())
252
+ req_id: x(),
253
+ result: H(he()),
254
+ error: H(x())
255
255
  }),
256
- popup_closed: E(
257
- w({ button_id: E(P(), () => {
256
+ popup_closed: P(
257
+ w({ button_id: P(x(), () => {
258
258
  }) }),
259
259
  {}
260
260
  ),
261
- viewport_changed: E(
261
+ viewport_changed: P(
262
262
  w({
263
263
  height: G(),
264
- width: E(G(), () => window.innerWidth),
265
- is_state_stable: D(),
266
- is_expanded: D()
264
+ width: P(G(), () => window.innerWidth),
265
+ is_state_stable: J(),
266
+ is_expanded: J()
267
267
  }),
268
268
  // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
269
269
  // null. Leaving this default value until the bug is fixed.
@@ -277,19 +277,19 @@ const Fe = {
277
277
  theme_params: ke()
278
278
  })
279
279
  };
280
- function Y(e) {
280
+ function X(e) {
281
281
  if (e.source !== window.parent)
282
282
  return;
283
283
  let t;
284
284
  try {
285
- t = A(T(U()), e.data);
285
+ t = B(T(U()), e.data);
286
286
  } catch {
287
287
  return;
288
288
  }
289
289
  const { eventType: r, eventData: n } = t, a = Fe[r];
290
290
  let o;
291
291
  try {
292
- o = a ? A(a, n) : n;
292
+ o = a ? B(a, n) : n;
293
293
  } catch (s) {
294
294
  return h().forceError(
295
295
  [
@@ -305,14 +305,14 @@ function Y(e) {
305
305
  Re(r, o);
306
306
  }
307
307
  const {
308
- on: $,
308
+ on: z,
309
309
  off: Oe,
310
310
  emit: Re,
311
311
  clear: Te
312
- } = le(
312
+ } = I(
313
313
  () => {
314
314
  const e = window;
315
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", M), Q(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", M), Q(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", M), window.addEventListener("message", Y);
315
+ !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", W), K(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", W), K(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", W), window.addEventListener("message", X);
316
316
  },
317
317
  () => {
318
318
  [
@@ -327,7 +327,7 @@ const {
327
327
  return;
328
328
  const [n, a] = r;
329
329
  "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
330
- }), window.removeEventListener("message", Y);
330
+ }), window.removeEventListener("message", X);
331
331
  }
332
332
  ), Ue = (...e) => b()(...e);
333
333
  function je(e, t) {
@@ -345,17 +345,17 @@ function je(e, t) {
345
345
  function k(e, t) {
346
346
  h().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
347
347
  const r = window, n = JSON.stringify({ eventType: e, eventData: t });
348
- return j() ? (Ue(n, de()), c.right(void 0)) : _e(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: re() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new fe());
348
+ return j() ? (Ue(n, de()), c.right(void 0)) : ue(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: ne() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new le());
349
349
  }
350
- function z(e, t, r = {}) {
350
+ function D(e, t, r = {}) {
351
351
  const {
352
352
  // If no capture function was passed, we capture the first compatible event.
353
353
  capture: n = () => !0,
354
354
  postEvent: a = k
355
- } = r, o = g(), [s, i] = ne();
355
+ } = r, o = y(), [s, i] = oe();
356
356
  (Array.isArray(t) ? t : [t]).forEach((p) => {
357
357
  s(
358
- $(p, (u) => {
358
+ z(p, (u) => {
359
359
  const f = Array.isArray(t);
360
360
  n(f ? { event: p, payload: u } : u) && o.set([
361
361
  f ? { event: p, payload: u } : u
@@ -366,25 +366,25 @@ function z(e, t, r = {}) {
366
366
  const _ = (p) => (i(), p);
367
367
  return l.pipe(
368
368
  async () => a(e, r.params),
369
- d.chainW(() => oe((p, u, f) => {
369
+ d.chainW(() => ae((p, u, f) => {
370
370
  const m = o();
371
371
  if (m)
372
372
  return p(m[0]);
373
- const y = (v) => {
374
- v && p(v[0]);
375
- }, L = () => {
376
- o.unsub(y);
373
+ const v = (E) => {
374
+ E && p(E[0]);
375
+ }, M = () => {
376
+ o.unsub(v);
377
377
  };
378
- o.sub(y), f.on("finalized", L);
378
+ o.sub(v), f.on("finalized", M);
379
379
  }, r)),
380
380
  d.mapBoth(_, _)
381
381
  );
382
382
  }
383
383
  function pt(e, t, r) {
384
384
  const { postEvent: n } = r || {};
385
- return C(
385
+ return V(
386
386
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
387
- z(e, t, {
387
+ D(e, t, {
388
388
  ...r,
389
389
  postEvent: n ? (...a) => {
390
390
  try {
@@ -402,19 +402,19 @@ function ct(e, t) {
402
402
  e,
403
403
  t
404
404
  );
405
- return typeof r == "function" ? ae.fn(() => C(r)) : r;
405
+ return typeof r == "function" ? se.fn(() => V(r)) : r;
406
406
  }
407
407
  function Ie(e, t) {
408
- const r = _e(window);
408
+ const r = ue(window);
409
409
  if (!e)
410
- return r || l.pipe(V(), c.match(() => !1, () => !0));
410
+ return r || l.pipe(L(), c.match(() => !1, () => !0));
411
411
  if (r)
412
412
  return d.right(!0);
413
413
  const { timeout: n = 100 } = t || {};
414
414
  return l.pipe(
415
- z("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
415
+ D("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
416
416
  d.match(
417
- (a) => Pe.is(a) || fe.is(a) ? c.right(!1) : c.left(a),
417
+ (a) => Pe.is(a) || le.is(a) ? c.right(!1) : c.left(a),
418
418
  () => c.right(!0)
419
419
  )
420
420
  );
@@ -425,12 +425,12 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
425
425
  // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
426
426
  // value. We are doing it because we are working with vbWebAppData presented as a
427
427
  // string, not an object as serializeLaunchParamsQuery requires.
428
- ie({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
428
+ pe({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
429
429
  );
430
430
  try {
431
- pe(o);
431
+ ce(o);
432
432
  } catch (s) {
433
- throw new ue(o, s);
433
+ throw new fe(o, s);
434
434
  }
435
435
  R("launchParams", o);
436
436
  }
@@ -444,7 +444,7 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
444
444
  o(...s);
445
445
  };
446
446
  try {
447
- const p = A(T(U()), i);
447
+ const p = B(T(U()), i);
448
448
  t({ name: p.eventType, params: p.eventData }, _);
449
449
  } catch {
450
450
  _();
@@ -473,12 +473,12 @@ function ut({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
473
473
  // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
474
474
  // value. We are doing it because we are working with vbWebAppData presented as a
475
475
  // string, not an object as serializeLaunchParamsQuery requires.
476
- ie({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
476
+ pe({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
477
477
  );
478
478
  try {
479
- pe(o);
479
+ ce(o);
480
480
  } catch (s) {
481
- throw new ue(o, s);
481
+ throw new fe(o, s);
482
482
  }
483
483
  R("launchParams", o);
484
484
  }
@@ -492,7 +492,7 @@ function ut({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
492
492
  o(...s);
493
493
  };
494
494
  try {
495
- const p = A(T(U()), i);
495
+ const p = B(T(U()), i);
496
496
  t({ name: p.eventType, params: p.eventData }, _);
497
497
  } catch {
498
498
  _();
@@ -523,7 +523,7 @@ function ft(e, t = "*") {
523
523
  n.emit(i, _);
524
524
  } catch {
525
525
  }
526
- }, n = le(
526
+ }, n = I(
527
527
  () => {
528
528
  window.addEventListener("message", r);
529
529
  },
@@ -541,21 +541,50 @@ function ft(e, t = "*") {
541
541
  },
542
542
  // We need to override clear to also remove the window listener
543
543
  clear: () => {
544
- n.clear(), x === a && (x = void 0);
544
+ n.clear(), g === a && (g = void 0);
545
545
  }
546
546
  };
547
- return x = a, a;
547
+ return g = a, a;
548
548
  }
549
- let x;
550
549
  function lt() {
551
- if (!x)
552
- throw new Error("HostBridge not initialized. Call defineHostBridge() first.");
553
- return x;
550
+ const e = I(
551
+ () => {
552
+ },
553
+ () => {
554
+ }
555
+ ), t = {
556
+ ...e,
557
+ send: (r, n) => {
558
+ W(r, n);
559
+ },
560
+ clear: () => {
561
+ var r;
562
+ e.clear(), g === t && (g = void 0), (r = window.VBotWebviewProxy) != null && r.__isWebComponentProxy && delete window.VBotWebviewProxy;
563
+ }
564
+ };
565
+ return window.VBotWebviewProxy = {
566
+ __isWebComponentProxy: !0,
567
+ postEvent(r, n) {
568
+ let a;
569
+ try {
570
+ a = n ? JSON.parse(n) : void 0;
571
+ } catch {
572
+ a = n;
573
+ }
574
+ e.emit(r, a);
575
+ }
576
+ }, g = t, t;
577
+ }
578
+ let g;
579
+ function wt() {
580
+ if (!g)
581
+ throw new Error("HostBridge not initialized. Call defineHostBridge() or defineWebComponentBridge() first.");
582
+ return g;
554
583
  }
555
584
  function $e(e) {
556
585
  return ({ req_id: t }) => t === e;
557
586
  }
558
- const X = {
587
+ const Z = {
559
588
  "6.0": [
560
589
  "iframe_ready",
561
590
  "iframe_will_reload",
@@ -647,14 +676,14 @@ const X = {
647
676
  "web_app_finish_refresh"
648
677
  ]
649
678
  };
650
- function Z(e, t) {
651
- return Object.keys(X).find((n) => X[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
679
+ function ee(e, t) {
680
+ return Object.keys(Z).find((n) => Z[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
652
681
  }
653
- function ee(e) {
682
+ function te(e) {
654
683
  return e.split(".").map(Number);
655
684
  }
656
685
  function ze(e, t) {
657
- const r = ee(e), n = ee(t), a = Math.max(r.length, n.length);
686
+ const r = te(e), n = te(t), a = Math.max(r.length, n.length);
658
687
  for (let o = 0; o < a; o += 1) {
659
688
  const s = r[o] || 0, i = n[o] || 0;
660
689
  if (s !== i)
@@ -662,25 +691,25 @@ function ze(e, t) {
662
691
  }
663
692
  return 0;
664
693
  }
665
- function te(e, t, r) {
666
- const n = r ? Z(
694
+ function re(e, t, r) {
695
+ const n = r ? ee(
667
696
  e,
668
697
  t
669
- ) : Z(e);
698
+ ) : ee(e);
670
699
  return n ? ze(n, r || t) <= 0 : !1;
671
700
  }
672
- function wt(e, t = "strict") {
701
+ function dt(e, t = "strict") {
673
702
  const r = typeof t == "function" ? t : (n) => {
674
- const { method: a, version: o } = n, s = "param" in n ? new We(a, n.param, o) : new Be(a, o);
703
+ const { method: a, version: o } = n, s = "param" in n ? new Ce(a, n.param, o) : new Be(a, o);
675
704
  if (t === "strict")
676
705
  throw s;
677
706
  return h().forceWarn(s.message);
678
707
  };
679
- return ((n, a) => te(n, e) ? n === "web_app_set_header_color" && O(w({ color: ye() }), a) && !te(n, "color", e) ? r({ version: e, method: n, param: "color" }) : je(n, a) : r({ version: e, method: n }));
708
+ return ((n, a) => re(n, e) ? n === "web_app_set_header_color" && O(w({ color: ye() }), a) && !re(n, "color", e) ? r({ version: e, method: n, param: "color" }) : je(n, a) : r({ version: e, method: n }));
680
709
  }
681
710
  function De(e, t, r, n) {
682
711
  return l.pipe(
683
- z("web_app_invoke_custom_method", "custom_method_invoked", {
712
+ D("web_app_invoke_custom_method", "custom_method_invoked", {
684
713
  ...n || {},
685
714
  params: { method: e, params: t, req_id: r },
686
715
  capture: $e(r)
@@ -688,8 +717,8 @@ function De(e, t, r, n) {
688
717
  d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
689
718
  );
690
719
  }
691
- function dt(e, t, r, n) {
692
- return ae.fn(() => l.pipe(
720
+ function mt(e, t, r, n) {
721
+ return se.fn(() => l.pipe(
693
722
  // @ts-expect-error TypeScript is unable to determine required override.
694
723
  De(e, t, r, n),
695
724
  d.match(
@@ -700,15 +729,15 @@ function dt(e, t, r, n) {
700
729
  )
701
730
  )());
702
731
  }
703
- function Ge(e, t, r = {}) {
732
+ function Je(e, t, r = {}) {
704
733
  const {
705
734
  // If no capture function was passed, we capture the first compatible event.
706
735
  capture: n = () => !0,
707
736
  postEvent: a = k
708
- } = r, o = g(), [s, i] = ne();
737
+ } = r, o = y(), [s, i] = oe();
709
738
  (Array.isArray(t) ? t : [t]).forEach((p) => {
710
739
  s(
711
- $(p, (u) => {
740
+ z(p, (u) => {
712
741
  (Array.isArray(t) ? n({ event: p, payload: u }) : n(u)) && o.set([u]);
713
742
  })
714
743
  );
@@ -716,25 +745,25 @@ function Ge(e, t, r = {}) {
716
745
  const _ = (p) => (i(), p);
717
746
  return l.pipe(
718
747
  async () => a(e, r.params),
719
- d.chainW(() => oe((p, u, f) => {
748
+ d.chainW(() => ae((p, u, f) => {
720
749
  const m = o();
721
750
  if (m)
722
751
  return p(m[0]);
723
- const y = (v) => {
724
- v && p(v[0]);
725
- }, L = () => {
726
- o.unsub(y);
752
+ const v = (E) => {
753
+ E && p(E[0]);
754
+ }, M = () => {
755
+ o.unsub(v);
727
756
  };
728
- o.sub(y), f.on("finalized", L);
757
+ o.sub(v), f.on("finalized", M);
729
758
  }, r)),
730
759
  d.mapBoth(_, _)
731
760
  );
732
761
  }
733
- function mt(e, t, r) {
762
+ function bt(e, t, r) {
734
763
  const { postEvent: n } = r || {};
735
- return C(
764
+ return V(
736
765
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
737
- Ge(e, t, {
766
+ Je(e, t, {
738
767
  ...r,
739
768
  postEvent: n ? (...a) => {
740
769
  try {
@@ -746,7 +775,7 @@ function mt(e, t, r) {
746
775
  })
747
776
  );
748
777
  }
749
- function bt() {
778
+ function gt() {
750
779
  Object.hasOwn || (Object.hasOwn = function(e, t) {
751
780
  return Object.prototype.hasOwnProperty.call(e, t);
752
781
  });
@@ -758,19 +787,19 @@ function be(e) {
758
787
  ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
759
788
  ), (t) => t);
760
789
  }
761
- const ht = W(be);
762
- function he(e) {
790
+ const ht = A(be);
791
+ function ge(e) {
763
792
  return btoa(
764
793
  encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
765
794
  ).replace(/\+/g, "-").replace(/\//g, "_");
766
795
  }
767
- function Je(e) {
768
- const t = he(typeof e == "string" ? e : JSON.stringify(e));
796
+ function Ge(e) {
797
+ const t = ge(typeof e == "string" ? e : JSON.stringify(e));
769
798
  return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
770
799
  }
771
- const gt = W(Je);
772
- function yt(e, t) {
773
- return C(
800
+ const yt = A(Ge);
801
+ function vt(e, t) {
802
+ return V(
774
803
  He(
775
804
  e,
776
805
  // @ts-expect-error TypeScript is unable to detect a correct override.
@@ -784,67 +813,68 @@ function He(e, t) {
784
813
  c.chain((r) => t ? typeof t == "function" ? t(r) : xe.parse(r) : c.right(r))
785
814
  );
786
815
  }
787
- function vt(e) {
788
- return he(e).length <= 512;
816
+ function Et(e) {
817
+ return ge(e).length <= 512;
789
818
  }
790
819
  export {
791
- At as CancelledError,
792
- ue as InvalidLaunchParamsError,
820
+ Bt as CancelledError,
821
+ fe as InvalidLaunchParamsError,
793
822
  Ve as InvokeCustomMethodFailedError,
794
- Ce as LaunchParamsRetrieveError,
795
- We as MethodParameterUnsupportedError,
823
+ Ae as LaunchParamsRetrieveError,
824
+ Ce as MethodParameterUnsupportedError,
796
825
  Be as MethodUnsupportedError,
797
- Bt as TimeoutError,
798
- fe as UnknownEnvError,
799
- bt as applyPolyfills,
826
+ Ct as TimeoutError,
827
+ le as UnknownEnvError,
828
+ gt as applyPolyfills,
800
829
  $e as captureSameReq,
801
830
  ze as compareVersions,
802
- xt as createLogger,
803
- wt as createPostEvent,
804
- gt as createStartParam,
805
- Je as createStartParamFp,
831
+ St as createLogger,
832
+ dt as createPostEvent,
833
+ yt as createStartParam,
834
+ Ge as createStartParamFp,
806
835
  we as debug,
807
836
  ht as decodeBase64Url,
808
837
  be as decodeBase64UrlFp,
809
- yt as decodeStartParam,
838
+ vt as decodeStartParam,
810
839
  He as decodeStartParamFp,
811
- St as deepSnakeToCamelObjKeys,
840
+ kt as deepSnakeToCamelObjKeys,
812
841
  ft as defineHostBridge,
813
- M as emitEvent,
814
- he as encodeBase64Url,
815
- lt as getHostBridge,
816
- Z as getReleaseVersion,
817
- _e as hasWebviewProxy,
818
- dt as invokeCustomMethod,
842
+ lt as defineWebComponentBridge,
843
+ W as emitEvent,
844
+ ge as encodeBase64Url,
845
+ wt as getHostBridge,
846
+ ee as getReleaseVersion,
847
+ ue as hasWebviewProxy,
848
+ mt as invokeCustomMethod,
819
849
  De as invokeCustomMethodFp,
820
850
  j as isIframe,
821
- vt as isSafeToCreateStartParam,
851
+ Et as isSafeToCreateStartParam,
822
852
  ct as isVBma,
823
853
  Ie as isVBmaFp,
824
854
  h as logger,
825
855
  _t as mockVBotEnv,
826
856
  Oe as off,
827
857
  Te as offAll,
828
- $ as on,
858
+ z as on,
829
859
  je as postEvent,
830
860
  k as postEventFp,
831
861
  Ue as postMessage,
832
862
  b as postMessageImpl,
833
- mt as request,
863
+ bt as request,
834
864
  pt as request2,
835
- z as request2Fp,
836
- Ge as requestFp,
865
+ D as request2Fp,
866
+ Je as requestFp,
837
867
  it as resetGlobals,
838
868
  rt as retrieveLaunchParams,
839
869
  Le as retrieveLaunchParamsFp,
840
870
  nt as retrieveRawInitData,
841
871
  Me as retrieveRawInitDataFp,
842
872
  ot as retrieveRawLaunchParams,
843
- V as retrieveRawLaunchParamsFp,
873
+ L as retrieveRawLaunchParamsFp,
844
874
  at as setDebug,
845
875
  ut as setLaunchParams,
846
876
  st as setTargetOrigin,
847
- te as supports,
877
+ re as supports,
848
878
  de as targetOrigin
849
879
  };
850
880
  //# sourceMappingURL=index.js.map