@vbotma/bridge 2.2.8 → 2.2.10

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,42 +1,43 @@
1
- import { is as O, looseObject as w, function as X, nullish as y, boolean as U, number as I, string as E, optional as $, unknown as de, parse as L, any as be } from "valibot";
2
- import { throwifyFpFn as C, getStorageValue as he, setStorageValue as Z, createLogger as ge, throwifyAnyEither as A, createCbCollector as ee, BetterTaskEither as te } from "@vbotma/toolkit";
3
- import { createLogger as Pt, deepSnakeToCamelObjKeys as kt } from "@vbotma/toolkit";
4
- import { BetterPromise as re, TimeoutError as ve } from "better-promises";
5
- import { CancelledError as St, TimeoutError as Bt } from "better-promises";
6
- import { function as l, either as c, option as F, taskEither as m, json as ye } from "fp-ts";
7
- import { errorClassWithData as Ee, errorClass as x } from "error-kid";
8
- import { parseLaunchParamsQueryFp as ne, themeParams as Pe, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as ke, parseLaunchParamsQuery as xe } from "@vbotma/transformers";
9
- import { signal as h, computed as se } from "@vbotma/signals";
10
- import Se from "mitt";
11
- function ie(e) {
1
+ import { is as O, looseObject as w, function as ne, nullish as P, boolean as D, number as G, string as x, optional as N, unknown as he, parse as W, any as ye } from "valibot";
2
+ import { throwifyFpFn as C, getStorageValue as ve, setStorageValue as R, createLogger as Ee, throwifyAnyEither as A, 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
+ import { function as l, either as c, option as F, taskEither as d, json as xe } from "fp-ts";
7
+ import { errorClassWithData as Se, errorClass as S } from "error-kid";
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: X() }) }),
13
+ w({ VBotWebviewProxy: w({ postEvent: ne() }) }),
14
14
  e
15
15
  );
16
16
  }
17
- function pe() {
17
+ function j() {
18
18
  try {
19
19
  return window.self !== window.top;
20
20
  } catch {
21
21
  return !0;
22
22
  }
23
23
  }
24
- class Be extends (/* @__PURE__ */ x("MethodUnsupportedError", (t, r) => [
25
- `Method "${t}" is unsupported in Mini Apps version ${r}`
26
- ])) {
24
+ class Be extends (/* @__PURE__ */ S(
25
+ "MethodUnsupportedError",
26
+ (t, r) => [
27
+ `Method "${t}" is unsupported in Mini Apps version ${r}`
28
+ ]
29
+ )) {
27
30
  }
28
- class Ce extends (/* @__PURE__ */ x("MethodParameterUnsupportedError", (t, r, n) => [
31
+ class Ce extends (/* @__PURE__ */ S("MethodParameterUnsupportedError", (t, r, n) => [
29
32
  `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
30
33
  ])) {
31
34
  }
32
- class Ae extends (/* @__PURE__ */ Ee(
35
+ class Ae extends (/* @__PURE__ */ Se(
33
36
  "LaunchParamsRetrieveError",
34
37
  (t) => ({ errors: t }),
35
38
  (t) => [
36
39
  [
37
- "Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?",
38
- "📖 Refer to docs for more information:",
39
- "https://docs.vbot-mini-apps.com/packages/tma-js-bridge/environment",
40
+ "Unable to retrieve launch parameters from any known source. You should pass correct parameters to Mini App",
40
41
  "",
41
42
  "Collected errors:",
42
43
  ...t.map(({ source: r, error: n }) => `Source: ${r} / ${n instanceof Error ? n.message : String(n)}`)
@@ -45,30 +46,33 @@ class Ae extends (/* @__PURE__ */ Ee(
45
46
  ]
46
47
  )) {
47
48
  }
48
- class Ve extends (/* @__PURE__ */ x("InvalidLaunchParamsError", (t, r) => [
49
- `Invalid value for launch params: ${t}`,
50
- { cause: r }
51
- ])) {
49
+ class fe extends (/* @__PURE__ */ S(
50
+ "InvalidLaunchParamsError",
51
+ (t, r) => [
52
+ `Invalid value for launch params: ${t}`,
53
+ { cause: r }
54
+ ]
55
+ )) {
52
56
  }
53
- class ce extends (/* @__PURE__ */ x("UnknownEnvError")) {
57
+ class le extends (/* @__PURE__ */ S("UnknownEnvError")) {
54
58
  }
55
- class Me extends (/* @__PURE__ */ x(
59
+ class Ve extends (/* @__PURE__ */ S(
56
60
  "InvokeCustomMethodError",
57
61
  (t) => [`Server returned error: ${t}`]
58
62
  )) {
59
63
  }
60
- const z = "launchParams";
61
- function G(e) {
64
+ const H = "launchParams";
65
+ function Q(e) {
62
66
  return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
63
67
  }
64
- function We() {
68
+ function Le() {
65
69
  return l.pipe(
66
70
  V(),
67
- c.chainW(ne)
71
+ c.chainW(ie)
68
72
  );
69
73
  }
70
- const rt = C(We);
71
- function qe() {
74
+ const rt = C(Le);
75
+ function Me() {
72
76
  return l.pipe(
73
77
  V(),
74
78
  c.map((e) => {
@@ -79,7 +83,7 @@ function qe() {
79
83
  }
80
84
  function nt() {
81
85
  return l.pipe(
82
- qe(),
86
+ Me(),
83
87
  c.fold((e) => {
84
88
  throw e;
85
89
  }, (e) => e),
@@ -93,14 +97,14 @@ function V() {
93
97
  // Try to retrieve launch parameters from the current location. This method
94
98
  // can return nothing in case, location was changed, and then the page was
95
99
  // reloaded.
96
- [() => G(window.location.href), "window.location.href"],
100
+ [() => Q(window.location.href), "window.location.href"],
97
101
  // Then, try using the lower level API - window.performance.
98
102
  [() => {
99
103
  const n = performance.getEntriesByType("navigation")[0];
100
- return n && G(n.name);
104
+ return n && Q(n.name);
101
105
  }, "performance navigation entries"],
102
106
  // Finally, try using the session storage.
103
- [() => he(z), "local storage"]
107
+ [() => ve(H), "local storage"]
104
108
  ]) {
105
109
  const n = t();
106
110
  if (!n) {
@@ -108,20 +112,20 @@ function V() {
108
112
  continue;
109
113
  }
110
114
  const a = l.pipe(
111
- ne(n),
115
+ ie(n),
112
116
  c.foldW((o) => o, () => !0)
113
117
  );
114
118
  if (typeof a != "boolean") {
115
119
  e.push({ source: r, error: a });
116
120
  continue;
117
121
  }
118
- return Z(z, n), c.right(n);
122
+ return R(H, n), c.right(n);
119
123
  }
120
124
  return c.left(new Ae(e));
121
125
  }
122
126
  const ot = C(V);
123
- function _e(e, t) {
124
- const r = /* @__PURE__ */ new Map(), n = Se(), a = (o, s, i = !1) => {
127
+ function I(e, t) {
128
+ const r = /* @__PURE__ */ new Map(), n = We(), a = (o, s, i = !1) => {
125
129
  const _ = r.get(o) || /* @__PURE__ */ new Map();
126
130
  r.set(o, _);
127
131
  const p = _.get(s) || [];
@@ -137,8 +141,8 @@ function _e(e, t) {
137
141
  !r.size && e();
138
142
  const _ = () => {
139
143
  a(o, s, i);
140
- }, p = (...d) => {
141
- i && _(), o === "*" ? s({ name: d[0], payload: d[1] }) : s(...d);
144
+ }, p = (...m) => {
145
+ i && _(), o === "*" ? s({ name: m[0], payload: m[1] }) : s(...m);
142
146
  };
143
147
  n.on(o, p);
144
148
  const u = r.get(o) || /* @__PURE__ */ new Map();
@@ -155,7 +159,7 @@ function _e(e, t) {
155
159
  }
156
160
  };
157
161
  }
158
- function W(e, t) {
162
+ function M(e, t) {
159
163
  window.dispatchEvent(new MessageEvent("message", {
160
164
  data: JSON.stringify({ eventType: e, eventData: t }),
161
165
  // We specify this kind of source here in order to allow the package's "on" function to
@@ -164,25 +168,25 @@ function W(e, t) {
164
168
  source: window.parent
165
169
  }));
166
170
  }
167
- const B = h(!1), T = h("https://web.telegram.org"), Le = (e) => {
168
- b().log("Event received:", e);
169
- }, ue = se(B);
171
+ const B = y(!1), $ = y("https://web.telegram.org"), qe = (e) => {
172
+ h().log("Event received:", e);
173
+ }, we = _e(B);
170
174
  function at(e) {
171
- e !== B() && (B.set(e), (e ? R : Oe)("*", Le));
175
+ e !== B() && (B.set(e), (e ? z : Oe)("*", qe));
172
176
  }
173
- const fe = se(T);
177
+ const de = _e($);
174
178
  function st(e) {
175
- T.set(e), b().log("New target origin set", e);
179
+ $.set(e), h().log("New target origin set", e);
176
180
  }
177
- const P = h((...e) => {
181
+ const b = y((...e) => {
178
182
  window.parent.postMessage(...e);
179
- }), b = h(ge("Bridge", {
183
+ }), h = y(Ee("Bridge", {
180
184
  bgColor: "#9147ff",
181
185
  textColor: "white",
182
- shouldLog: ue
186
+ shouldLog: we
183
187
  }));
184
188
  function it() {
185
- Re(), [P, T, fe, B, ue, b].forEach((e) => {
189
+ Te(), [b, $, de, B, we, h].forEach((e) => {
186
190
  e.unsubAll(), "reset" in e && e.reset();
187
191
  });
188
192
  }
@@ -202,28 +206,28 @@ function q(e, t, r) {
202
206
  return;
203
207
  }
204
208
  if (i === 2) {
205
- H(e, t, n[1]);
209
+ Y(e, t, n[1]);
206
210
  return;
207
211
  }
208
- n.unshift(1), H(e, t, o);
212
+ n.unshift(1), Y(e, t, o);
209
213
  }
210
214
  });
211
- le(
215
+ me(
212
216
  e,
213
217
  t,
214
218
  () => s,
215
219
  (i) => n.push(i)
216
220
  );
217
221
  }
218
- function D(e, t) {
222
+ function K(e, t) {
219
223
  const r = e[t];
220
- le(e, t, () => r, (n) => {
224
+ me(e, t, () => r, (n) => {
221
225
  Object.entries(n).forEach(([a, o]) => {
222
226
  r[a] = o;
223
227
  });
224
228
  });
225
229
  }
226
- function le(e, t, r, n) {
230
+ function me(e, t, r, n) {
227
231
  Object.defineProperty(e, t, {
228
232
  enumerable: !0,
229
233
  configurable: !0,
@@ -231,7 +235,7 @@ function le(e, t, r, n) {
231
235
  set: n
232
236
  });
233
237
  }
234
- function H(e, t, r) {
238
+ function Y(e, t, r) {
235
239
  Object.defineProperty(e, t, {
236
240
  enumerable: !0,
237
241
  configurable: !0,
@@ -241,25 +245,25 @@ function H(e, t, r) {
241
245
  }
242
246
  const Fe = {
243
247
  clipboard_text_received: w({
244
- req_id: E(),
245
- data: y(E())
248
+ req_id: x(),
249
+ data: P(x())
246
250
  }),
247
251
  custom_method_invoked: w({
248
- req_id: E(),
249
- result: $(de()),
250
- error: $(E())
252
+ req_id: x(),
253
+ result: N(he()),
254
+ error: N(x())
251
255
  }),
252
- popup_closed: y(
253
- w({ button_id: y(E(), () => {
256
+ popup_closed: P(
257
+ w({ button_id: P(x(), () => {
254
258
  }) }),
255
259
  {}
256
260
  ),
257
- viewport_changed: y(
261
+ viewport_changed: P(
258
262
  w({
259
- height: I(),
260
- width: y(I(), () => window.innerWidth),
261
- is_state_stable: U(),
262
- is_expanded: U()
263
+ height: G(),
264
+ width: P(G(), () => window.innerWidth),
265
+ is_state_stable: D(),
266
+ is_expanded: D()
263
267
  }),
264
268
  // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
265
269
  // null. Leaving this default value until the bug is fixed.
@@ -270,24 +274,24 @@ const Fe = {
270
274
  })
271
275
  ),
272
276
  theme_changed: w({
273
- theme_params: Pe()
277
+ theme_params: ke()
274
278
  })
275
279
  };
276
- function J(e) {
280
+ function X(e) {
277
281
  if (e.source !== window.parent)
278
282
  return;
279
283
  let t;
280
284
  try {
281
- t = L(oe(ae()), e.data);
285
+ t = W(T(U()), e.data);
282
286
  } catch {
283
287
  return;
284
288
  }
285
289
  const { eventType: r, eventData: n } = t, a = Fe[r];
286
290
  let o;
287
291
  try {
288
- o = a ? L(a, n) : n;
292
+ o = a ? W(a, n) : n;
289
293
  } catch (s) {
290
- return b().forceError(
294
+ return h().forceError(
291
295
  [
292
296
  `An error occurred processing the "${r}" event from the VBot application.`,
293
297
  "Please, file an issue here:",
@@ -298,17 +302,17 @@ function J(e) {
298
302
  s
299
303
  );
300
304
  }
301
- Te(r, o);
305
+ Re(r, o);
302
306
  }
303
307
  const {
304
- on: R,
308
+ on: z,
305
309
  off: Oe,
306
- emit: Te,
307
- clear: Re
308
- } = _e(
310
+ emit: Re,
311
+ clear: Te
312
+ } = I(
309
313
  () => {
310
314
  const e = window;
311
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", W), D(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", W), D(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", W), window.addEventListener("message", J);
315
+ !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", M), K(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", M), K(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", M), window.addEventListener("message", X);
312
316
  },
313
317
  () => {
314
318
  [
@@ -323,12 +327,12 @@ const {
323
327
  return;
324
328
  const [n, a] = r;
325
329
  "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
326
- }), window.removeEventListener("message", J);
330
+ }), window.removeEventListener("message", X);
327
331
  }
328
- ), je = (...e) => P()(...e);
329
- function Ue(e, t) {
332
+ ), Ue = (...e) => b()(...e);
333
+ function je(e, t) {
330
334
  l.pipe(
331
- S(
335
+ k(
332
336
  // @ts-expect-error It's ok, TS can't determine a specific override.
333
337
  e,
334
338
  t
@@ -338,20 +342,20 @@ function Ue(e, t) {
338
342
  })
339
343
  );
340
344
  }
341
- function S(e, t) {
342
- b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
345
+ function k(e, t) {
346
+ h().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
343
347
  const r = window, n = JSON.stringify({ eventType: e, eventData: t });
344
- return pe() ? (je(n, fe()), c.right(void 0)) : ie(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: X() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new ce());
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());
345
349
  }
346
- function j(e, t, r = {}) {
350
+ function J(e, t, r = {}) {
347
351
  const {
348
352
  // If no capture function was passed, we capture the first compatible event.
349
353
  capture: n = () => !0,
350
- postEvent: a = S
351
- } = r, o = h(), [s, i] = ee();
354
+ postEvent: a = k
355
+ } = r, o = y(), [s, i] = oe();
352
356
  (Array.isArray(t) ? t : [t]).forEach((p) => {
353
357
  s(
354
- R(p, (u) => {
358
+ z(p, (u) => {
355
359
  const f = Array.isArray(t);
356
360
  n(f ? { event: p, payload: u } : u) && o.set([
357
361
  f ? { event: p, payload: u } : u
@@ -362,25 +366,25 @@ function j(e, t, r = {}) {
362
366
  const _ = (p) => (i(), p);
363
367
  return l.pipe(
364
368
  async () => a(e, r.params),
365
- m.chainW(() => te((p, u, f) => {
366
- const d = o();
367
- if (d)
368
- return p(d[0]);
369
- const g = (v) => {
370
- v && p(v[0]);
371
- }, M = () => {
372
- o.unsub(g);
369
+ d.chainW(() => ae((p, u, f) => {
370
+ const m = o();
371
+ if (m)
372
+ return p(m[0]);
373
+ const v = (E) => {
374
+ E && p(E[0]);
375
+ }, L = () => {
376
+ o.unsub(v);
373
377
  };
374
- o.sub(g), f.on("finalized", M);
378
+ o.sub(v), f.on("finalized", L);
375
379
  }, r)),
376
- m.mapBoth(_, _)
380
+ d.mapBoth(_, _)
377
381
  );
378
382
  }
379
383
  function pt(e, t, r) {
380
384
  const { postEvent: n } = r || {};
381
385
  return A(
382
386
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
383
- j(e, t, {
387
+ J(e, t, {
384
388
  ...r,
385
389
  postEvent: n ? (...a) => {
386
390
  try {
@@ -388,7 +392,7 @@ function pt(e, t, r) {
388
392
  } catch (o) {
389
393
  return c.left(o);
390
394
  }
391
- } : S
395
+ } : k
392
396
  })
393
397
  );
394
398
  }
@@ -398,19 +402,19 @@ function ct(e, t) {
398
402
  e,
399
403
  t
400
404
  );
401
- return typeof r == "function" ? re.fn(() => A(r)) : r;
405
+ return typeof r == "function" ? se.fn(() => A(r)) : r;
402
406
  }
403
407
  function Ie(e, t) {
404
- const r = ie(window);
408
+ const r = ue(window);
405
409
  if (!e)
406
410
  return r || l.pipe(V(), c.match(() => !1, () => !0));
407
411
  if (r)
408
- return m.right(!0);
412
+ return d.right(!0);
409
413
  const { timeout: n = 100 } = t || {};
410
414
  return l.pipe(
411
- j("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
412
- m.match(
413
- (a) => ve.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
415
+ J("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
416
+ d.match(
417
+ (a) => Pe.is(a) || le.is(a) ? c.right(!1) : c.left(a),
414
418
  () => c.right(!0)
415
419
  )
416
420
  );
@@ -421,26 +425,74 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
421
425
  // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
422
426
  // value. We are doing it because we are working with vbWebAppData presented as a
423
427
  // string, not an object as serializeLaunchParamsQuery requires.
424
- ke({ ...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
+ );
430
+ try {
431
+ ce(o);
432
+ } catch (s) {
433
+ throw new fe(o, s);
434
+ }
435
+ R("launchParams", o);
436
+ }
437
+ if (j()) {
438
+ if (!t)
439
+ return;
440
+ r && b.reset();
441
+ const o = b();
442
+ b.set((...s) => {
443
+ const [i] = s, _ = () => {
444
+ o(...s);
445
+ };
446
+ try {
447
+ const p = W(T(U()), i);
448
+ t({ name: p.eventType, params: p.eventData }, _);
449
+ } catch {
450
+ _();
451
+ }
452
+ });
453
+ return;
454
+ }
455
+ const n = window.VBotWebviewProxy || {}, a = n.postEvent || (() => {
456
+ });
457
+ window.VBotWebviewProxy = {
458
+ ...n,
459
+ postEvent(o, s) {
460
+ const i = () => {
461
+ a(o, s);
462
+ };
463
+ t ? t({
464
+ name: o,
465
+ params: s ? JSON.parse(s) : void 0
466
+ }, i) : i();
467
+ }
468
+ }, h().log("Environment was mocked by the mockVBotEnv function");
469
+ }
470
+ function ut({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
471
+ if (e) {
472
+ const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
473
+ // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
474
+ // value. We are doing it because we are working with vbWebAppData presented as a
475
+ // string, not an object as serializeLaunchParamsQuery requires.
476
+ pe({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
425
477
  );
426
478
  try {
427
- xe(o);
479
+ ce(o);
428
480
  } catch (s) {
429
- throw new Ve(o, s);
481
+ throw new fe(o, s);
430
482
  }
431
- Z("launchParams", o);
483
+ R("launchParams", o);
432
484
  }
433
- if (pe()) {
485
+ if (j()) {
434
486
  if (!t)
435
487
  return;
436
- r && P.reset();
437
- const o = P();
438
- P.set((...s) => {
488
+ r && b.reset();
489
+ const o = b();
490
+ b.set((...s) => {
439
491
  const [i] = s, _ = () => {
440
492
  o(...s);
441
493
  };
442
494
  try {
443
- const p = L(oe(ae()), i);
495
+ const p = W(T(U()), i);
444
496
  t({ name: p.eventType, params: p.eventData }, _);
445
497
  } catch {
446
498
  _();
@@ -461,9 +513,9 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
461
513
  params: s ? JSON.parse(s) : void 0
462
514
  }, i) : i();
463
515
  }
464
- }, b().log("Environment was mocked by the mockVBotEnv function");
516
+ }, h().log("Launch params are injected by the setLaunchParams function");
465
517
  }
466
- function ut(e, t = "*") {
518
+ function ft(e, t = "*") {
467
519
  const r = (o) => {
468
520
  if (o.source === e.contentWindow)
469
521
  try {
@@ -471,7 +523,7 @@ function ut(e, t = "*") {
471
523
  n.emit(i, _);
472
524
  } catch {
473
525
  }
474
- }, n = _e(
526
+ }, n = I(
475
527
  () => {
476
528
  window.addEventListener("message", r);
477
529
  },
@@ -489,21 +541,51 @@ function ut(e, t = "*") {
489
541
  },
490
542
  // We need to override clear to also remove the window listener
491
543
  clear: () => {
492
- n.clear(), k === a && (k = void 0);
544
+ n.clear(), g === a && (g = void 0);
493
545
  }
494
546
  };
495
- return k = a, a;
547
+ return g = a, a;
496
548
  }
497
- let k;
498
- function ft() {
499
- if (!k)
500
- throw new Error("HostBridge not initialized. Call defineHostBridge() first.");
501
- return k;
549
+ function lt() {
550
+ const e = I(
551
+ () => {
552
+ },
553
+ () => {
554
+ }
555
+ ), t = {
556
+ ...e,
557
+ send: (r, n) => {
558
+ const a = JSON.stringify({ eventType: r, eventData: n });
559
+ window.postMessage(a, window.location.origin || "*");
560
+ },
561
+ clear: () => {
562
+ var r;
563
+ e.clear(), g === t && (g = void 0), (r = window.VBotWebviewProxy) != null && r.__isWebComponentProxy && delete window.VBotWebviewProxy;
564
+ }
565
+ };
566
+ return window.VBotWebviewProxy = {
567
+ __isWebComponentProxy: !0,
568
+ postEvent(r, n) {
569
+ let a;
570
+ try {
571
+ a = n ? JSON.parse(n) : void 0;
572
+ } catch {
573
+ a = n;
574
+ }
575
+ e.emit(r, a);
576
+ }
577
+ }, g = t, t;
578
+ }
579
+ let g;
580
+ function wt() {
581
+ if (!g)
582
+ throw new Error("HostBridge not initialized. Call defineHostBridge() or defineWebComponentBridge() first.");
583
+ return g;
502
584
  }
503
585
  function $e(e) {
504
586
  return ({ req_id: t }) => t === e;
505
587
  }
506
- const N = {
588
+ const Z = {
507
589
  "6.0": [
508
590
  "iframe_ready",
509
591
  "iframe_will_reload",
@@ -595,14 +677,14 @@ const N = {
595
677
  "web_app_finish_refresh"
596
678
  ]
597
679
  };
598
- function Q(e, t) {
599
- return Object.keys(N).find((n) => N[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
680
+ function ee(e, t) {
681
+ return Object.keys(Z).find((n) => Z[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
600
682
  }
601
- function K(e) {
683
+ function te(e) {
602
684
  return e.split(".").map(Number);
603
685
  }
604
686
  function ze(e, t) {
605
- const r = K(e), n = K(t), a = Math.max(r.length, n.length);
687
+ const r = te(e), n = te(t), a = Math.max(r.length, n.length);
606
688
  for (let o = 0; o < a; o += 1) {
607
689
  const s = r[o] || 0, i = n[o] || 0;
608
690
  if (s !== i)
@@ -610,37 +692,37 @@ function ze(e, t) {
610
692
  }
611
693
  return 0;
612
694
  }
613
- function Y(e, t, r) {
614
- const n = r ? Q(
695
+ function re(e, t, r) {
696
+ const n = r ? ee(
615
697
  e,
616
698
  t
617
- ) : Q(e);
699
+ ) : ee(e);
618
700
  return n ? ze(n, r || t) <= 0 : !1;
619
701
  }
620
- function lt(e, t = "strict") {
702
+ function dt(e, t = "strict") {
621
703
  const r = typeof t == "function" ? t : (n) => {
622
704
  const { method: a, version: o } = n, s = "param" in n ? new Ce(a, n.param, o) : new Be(a, o);
623
705
  if (t === "strict")
624
706
  throw s;
625
- return b().forceWarn(s.message);
707
+ return h().forceWarn(s.message);
626
708
  };
627
- return ((n, a) => Y(n, e) ? n === "web_app_set_header_color" && O(w({ color: be() }), a) && !Y(n, "color", e) ? r({ version: e, method: n, param: "color" }) : Ue(n, a) : r({ version: e, method: n }));
709
+ 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 }));
628
710
  }
629
- function Ge(e, t, r, n) {
711
+ function Je(e, t, r, n) {
630
712
  return l.pipe(
631
- j("web_app_invoke_custom_method", "custom_method_invoked", {
713
+ J("web_app_invoke_custom_method", "custom_method_invoked", {
632
714
  ...n || {},
633
715
  params: { method: e, params: t, req_id: r },
634
716
  capture: $e(r)
635
717
  }),
636
- m.chain(({ result: a, error: o }) => o ? m.left(new Me(o)) : m.right(a))
718
+ d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
637
719
  );
638
720
  }
639
- function wt(e, t, r, n) {
640
- return re.fn(() => l.pipe(
721
+ function mt(e, t, r, n) {
722
+ return se.fn(() => l.pipe(
641
723
  // @ts-expect-error TypeScript is unable to determine required override.
642
- Ge(e, t, r, n),
643
- m.match(
724
+ Je(e, t, r, n),
725
+ d.match(
644
726
  (a) => {
645
727
  throw a;
646
728
  },
@@ -652,11 +734,11 @@ function De(e, t, r = {}) {
652
734
  const {
653
735
  // If no capture function was passed, we capture the first compatible event.
654
736
  capture: n = () => !0,
655
- postEvent: a = S
656
- } = r, o = h(), [s, i] = ee();
737
+ postEvent: a = k
738
+ } = r, o = y(), [s, i] = oe();
657
739
  (Array.isArray(t) ? t : [t]).forEach((p) => {
658
740
  s(
659
- R(p, (u) => {
741
+ z(p, (u) => {
660
742
  (Array.isArray(t) ? n({ event: p, payload: u }) : n(u)) && o.set([u]);
661
743
  })
662
744
  );
@@ -664,21 +746,21 @@ function De(e, t, r = {}) {
664
746
  const _ = (p) => (i(), p);
665
747
  return l.pipe(
666
748
  async () => a(e, r.params),
667
- m.chainW(() => te((p, u, f) => {
668
- const d = o();
669
- if (d)
670
- return p(d[0]);
671
- const g = (v) => {
672
- v && p(v[0]);
673
- }, M = () => {
674
- o.unsub(g);
749
+ d.chainW(() => ae((p, u, f) => {
750
+ const m = o();
751
+ if (m)
752
+ return p(m[0]);
753
+ const v = (E) => {
754
+ E && p(E[0]);
755
+ }, L = () => {
756
+ o.unsub(v);
675
757
  };
676
- o.sub(g), f.on("finalized", M);
758
+ o.sub(v), f.on("finalized", L);
677
759
  }, r)),
678
- m.mapBoth(_, _)
760
+ d.mapBoth(_, _)
679
761
  );
680
762
  }
681
- function mt(e, t, r) {
763
+ function bt(e, t, r) {
682
764
  const { postEvent: n } = r || {};
683
765
  return A(
684
766
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
@@ -690,108 +772,110 @@ function mt(e, t, r) {
690
772
  } catch (o) {
691
773
  return c.left(o);
692
774
  }
693
- } : S
775
+ } : k
694
776
  })
695
777
  );
696
778
  }
697
- function dt() {
779
+ function gt() {
698
780
  Object.hasOwn || (Object.hasOwn = function(e, t) {
699
781
  return Object.prototype.hasOwnProperty.call(e, t);
700
782
  });
701
783
  }
702
- function we(e) {
784
+ function be(e) {
703
785
  return c.tryCatch(() => decodeURIComponent(
704
786
  atob(
705
787
  e.replace(/-/g, "+").replace(/_/g, "/")
706
788
  ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
707
789
  ), (t) => t);
708
790
  }
709
- const bt = C(we);
710
- function me(e) {
791
+ const ht = C(be);
792
+ function ge(e) {
711
793
  return btoa(
712
794
  encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
713
795
  ).replace(/\+/g, "-").replace(/\//g, "_");
714
796
  }
715
- function He(e) {
716
- const t = me(typeof e == "string" ? e : JSON.stringify(e));
797
+ function Ge(e) {
798
+ const t = ge(typeof e == "string" ? e : JSON.stringify(e));
717
799
  return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
718
800
  }
719
- const ht = C(He);
720
- function gt(e, t) {
801
+ const yt = C(Ge);
802
+ function vt(e, t) {
721
803
  return A(
722
- Je(
804
+ Ne(
723
805
  e,
724
806
  // @ts-expect-error TypeScript is unable to detect a correct override.
725
807
  typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
726
808
  )
727
809
  );
728
810
  }
729
- function Je(e, t) {
811
+ function Ne(e, t) {
730
812
  return l.pipe(
731
- we(e),
732
- c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(r))
813
+ be(e),
814
+ c.chain((r) => t ? typeof t == "function" ? t(r) : xe.parse(r) : c.right(r))
733
815
  );
734
816
  }
735
- function vt(e) {
736
- return me(e).length <= 512;
817
+ function Et(e) {
818
+ return ge(e).length <= 512;
737
819
  }
738
820
  export {
739
- St as CancelledError,
740
- Ve as InvalidLaunchParamsError,
741
- Me as InvokeCustomMethodFailedError,
821
+ Bt as CancelledError,
822
+ fe as InvalidLaunchParamsError,
823
+ Ve as InvokeCustomMethodFailedError,
742
824
  Ae as LaunchParamsRetrieveError,
743
825
  Ce as MethodParameterUnsupportedError,
744
826
  Be as MethodUnsupportedError,
745
- Bt as TimeoutError,
746
- ce as UnknownEnvError,
747
- dt as applyPolyfills,
827
+ Ct as TimeoutError,
828
+ le as UnknownEnvError,
829
+ gt as applyPolyfills,
748
830
  $e as captureSameReq,
749
831
  ze as compareVersions,
750
- Pt as createLogger,
751
- lt as createPostEvent,
752
- ht as createStartParam,
753
- He as createStartParamFp,
754
- ue as debug,
755
- bt as decodeBase64Url,
756
- we as decodeBase64UrlFp,
757
- gt as decodeStartParam,
758
- Je as decodeStartParamFp,
832
+ St as createLogger,
833
+ dt as createPostEvent,
834
+ yt as createStartParam,
835
+ Ge as createStartParamFp,
836
+ we as debug,
837
+ ht as decodeBase64Url,
838
+ be as decodeBase64UrlFp,
839
+ vt as decodeStartParam,
840
+ Ne as decodeStartParamFp,
759
841
  kt as deepSnakeToCamelObjKeys,
760
- ut as defineHostBridge,
761
- W as emitEvent,
762
- me as encodeBase64Url,
763
- ft as getHostBridge,
764
- Q as getReleaseVersion,
765
- ie as hasWebviewProxy,
766
- wt as invokeCustomMethod,
767
- Ge as invokeCustomMethodFp,
768
- pe as isIframe,
769
- vt as isSafeToCreateStartParam,
842
+ ft as defineHostBridge,
843
+ lt as defineWebComponentBridge,
844
+ M as emitEvent,
845
+ ge as encodeBase64Url,
846
+ wt as getHostBridge,
847
+ ee as getReleaseVersion,
848
+ ue as hasWebviewProxy,
849
+ mt as invokeCustomMethod,
850
+ Je as invokeCustomMethodFp,
851
+ j as isIframe,
852
+ Et as isSafeToCreateStartParam,
770
853
  ct as isVBma,
771
854
  Ie as isVBmaFp,
772
- b as logger,
855
+ h as logger,
773
856
  _t as mockVBotEnv,
774
857
  Oe as off,
775
- Re as offAll,
776
- R as on,
777
- Ue as postEvent,
778
- S as postEventFp,
779
- je as postMessage,
780
- P as postMessageImpl,
781
- mt as request,
858
+ Te as offAll,
859
+ z as on,
860
+ je as postEvent,
861
+ k as postEventFp,
862
+ Ue as postMessage,
863
+ b as postMessageImpl,
864
+ bt as request,
782
865
  pt as request2,
783
- j as request2Fp,
866
+ J as request2Fp,
784
867
  De as requestFp,
785
868
  it as resetGlobals,
786
869
  rt as retrieveLaunchParams,
787
- We as retrieveLaunchParamsFp,
870
+ Le as retrieveLaunchParamsFp,
788
871
  nt as retrieveRawInitData,
789
- qe as retrieveRawInitDataFp,
872
+ Me as retrieveRawInitDataFp,
790
873
  ot as retrieveRawLaunchParams,
791
874
  V as retrieveRawLaunchParamsFp,
792
875
  at as setDebug,
876
+ ut as setLaunchParams,
793
877
  st as setTargetOrigin,
794
- Y as supports,
795
- fe as targetOrigin
878
+ re as supports,
879
+ de as targetOrigin
796
880
  };
797
881
  //# sourceMappingURL=index.js.map