@vbotma/bridge 2.2.6 → 2.2.7
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/dts/env/host/bridge.d.ts +48 -0
- package/dist/dts/events/createEmitter.d.ts +2 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +3 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +276 -237
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { is as
|
|
2
|
-
import { throwifyFpFn as A, getStorageValue as
|
|
3
|
-
import { createLogger as
|
|
4
|
-
import { BetterPromise as
|
|
5
|
-
import { CancelledError as
|
|
6
|
-
import { function as l, either as c, option as F, taskEither as
|
|
7
|
-
import { errorClassWithData as
|
|
8
|
-
import { parseLaunchParamsQueryFp as
|
|
9
|
-
import { signal as h, computed as
|
|
10
|
-
import
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
|
|
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 me, parse as L, any as be } from "valibot";
|
|
2
|
+
import { throwifyFpFn as A, getStorageValue as he, setStorageValue as Z, createLogger as ge, throwifyAnyEither as C, 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 d, 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) {
|
|
12
|
+
return O(
|
|
13
|
+
w({ VBotWebviewProxy: w({ postEvent: X() }) }),
|
|
14
14
|
e
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function pe() {
|
|
18
18
|
try {
|
|
19
19
|
return window.self !== window.top;
|
|
20
20
|
} catch {
|
|
21
21
|
return !0;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class Be extends (/* @__PURE__ */ x("MethodUnsupportedError", (t, r) => [
|
|
25
25
|
`Method "${t}" is unsupported in Mini Apps version ${r}`
|
|
26
26
|
])) {
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class Ae extends (/* @__PURE__ */ x("MethodParameterUnsupportedError", (t, r, n) => [
|
|
29
29
|
`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
|
|
30
30
|
])) {
|
|
31
31
|
}
|
|
32
|
-
class
|
|
32
|
+
class Ce extends (/* @__PURE__ */ Ee(
|
|
33
33
|
"LaunchParamsRetrieveError",
|
|
34
34
|
(t) => ({ errors: t }),
|
|
35
35
|
(t) => [
|
|
@@ -45,30 +45,30 @@ class Ae extends (/* @__PURE__ */ ye(
|
|
|
45
45
|
]
|
|
46
46
|
)) {
|
|
47
47
|
}
|
|
48
|
-
class
|
|
48
|
+
class Me extends (/* @__PURE__ */ x("InvalidLaunchParamsError", (t, r) => [
|
|
49
49
|
`Invalid value for launch params: ${t}`,
|
|
50
50
|
{ cause: r }
|
|
51
51
|
])) {
|
|
52
52
|
}
|
|
53
|
-
class
|
|
53
|
+
class ce extends (/* @__PURE__ */ x("UnknownEnvError")) {
|
|
54
54
|
}
|
|
55
|
-
class
|
|
55
|
+
class Ve extends (/* @__PURE__ */ x(
|
|
56
56
|
"InvokeCustomMethodError",
|
|
57
57
|
(t) => [`Server returned error: ${t}`]
|
|
58
58
|
)) {
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
function
|
|
60
|
+
const z = "launchParams";
|
|
61
|
+
function G(e) {
|
|
62
62
|
return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function We() {
|
|
65
65
|
return l.pipe(
|
|
66
66
|
M(),
|
|
67
|
-
c.chainW(
|
|
67
|
+
c.chainW(ne)
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
function
|
|
70
|
+
const rt = A(We);
|
|
71
|
+
function qe() {
|
|
72
72
|
return l.pipe(
|
|
73
73
|
M(),
|
|
74
74
|
c.map((e) => {
|
|
@@ -77,9 +77,9 @@ function Be() {
|
|
|
77
77
|
})
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function nt() {
|
|
81
81
|
return l.pipe(
|
|
82
|
-
|
|
82
|
+
qe(),
|
|
83
83
|
c.fold((e) => {
|
|
84
84
|
throw e;
|
|
85
85
|
}, (e) => e),
|
|
@@ -93,14 +93,14 @@ function M() {
|
|
|
93
93
|
// Try to retrieve launch parameters from the current location. This method
|
|
94
94
|
// can return nothing in case, location was changed, and then the page was
|
|
95
95
|
// reloaded.
|
|
96
|
-
[() =>
|
|
96
|
+
[() => G(window.location.href), "window.location.href"],
|
|
97
97
|
// Then, try using the lower level API - window.performance.
|
|
98
98
|
[() => {
|
|
99
99
|
const n = performance.getEntriesByType("navigation")[0];
|
|
100
|
-
return n &&
|
|
100
|
+
return n && G(n.name);
|
|
101
101
|
}, "performance navigation entries"],
|
|
102
102
|
// Finally, try using the session storage.
|
|
103
|
-
[() =>
|
|
103
|
+
[() => he(z), "local storage"]
|
|
104
104
|
]) {
|
|
105
105
|
const n = t();
|
|
106
106
|
if (!n) {
|
|
@@ -108,43 +108,43 @@ function M() {
|
|
|
108
108
|
continue;
|
|
109
109
|
}
|
|
110
110
|
const a = l.pipe(
|
|
111
|
-
|
|
111
|
+
ne(n),
|
|
112
112
|
c.foldW((o) => o, () => !0)
|
|
113
113
|
);
|
|
114
114
|
if (typeof a != "boolean") {
|
|
115
115
|
e.push({ source: r, error: a });
|
|
116
116
|
continue;
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return Z(z, n), c.right(n);
|
|
119
119
|
}
|
|
120
|
-
return c.left(new
|
|
120
|
+
return c.left(new Ce(e));
|
|
121
121
|
}
|
|
122
|
-
const
|
|
123
|
-
function
|
|
124
|
-
const r = /* @__PURE__ */ new Map(), n =
|
|
122
|
+
const ot = A(M);
|
|
123
|
+
function _e(e, t) {
|
|
124
|
+
const r = /* @__PURE__ */ new Map(), n = Se(), a = (o, s, i = !1) => {
|
|
125
125
|
const _ = r.get(o) || /* @__PURE__ */ new Map();
|
|
126
126
|
r.set(o, _);
|
|
127
|
-
const
|
|
128
|
-
_.set(s,
|
|
129
|
-
const u =
|
|
130
|
-
if (u >= 0 && (n.off(o,
|
|
127
|
+
const p = _.get(s) || [];
|
|
128
|
+
_.set(s, p);
|
|
129
|
+
const u = p.findIndex((f) => f[1] === i);
|
|
130
|
+
if (u >= 0 && (n.off(o, p[u][0]), p.splice(u, 1), !p.length && (_.delete(s), !_.size))) {
|
|
131
131
|
const f = r.size;
|
|
132
132
|
r.delete(o), f && !r.size && t();
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
return {
|
|
136
|
-
on(o, s,
|
|
136
|
+
on(o, s, i) {
|
|
137
137
|
!r.size && e();
|
|
138
138
|
const _ = () => {
|
|
139
|
-
a(o, s,
|
|
140
|
-
},
|
|
141
|
-
|
|
139
|
+
a(o, s, i);
|
|
140
|
+
}, p = (...m) => {
|
|
141
|
+
i && _(), o === "*" ? s({ name: m[0], payload: m[1] }) : s(...m);
|
|
142
142
|
};
|
|
143
|
-
n.on(o,
|
|
143
|
+
n.on(o, p);
|
|
144
144
|
const u = r.get(o) || /* @__PURE__ */ new Map();
|
|
145
145
|
r.set(o, u);
|
|
146
146
|
const f = u.get(s) || [];
|
|
147
|
-
return u.set(s, f), f.push([
|
|
147
|
+
return u.set(s, f), f.push([p, i || !1]), _;
|
|
148
148
|
},
|
|
149
149
|
off: a,
|
|
150
150
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -155,7 +155,7 @@ function qe(e, t) {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function W(e, t) {
|
|
159
159
|
window.dispatchEvent(new MessageEvent("message", {
|
|
160
160
|
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
161
161
|
// We specify this kind of source here in order to allow the package's "on" function to
|
|
@@ -164,66 +164,66 @@ function B(e, t) {
|
|
|
164
164
|
source: window.parent
|
|
165
165
|
}));
|
|
166
166
|
}
|
|
167
|
-
const
|
|
167
|
+
const B = h(!1), T = h("https://web.telegram.org"), Le = (e) => {
|
|
168
168
|
b().log("Event received:", e);
|
|
169
|
-
},
|
|
170
|
-
function ot(e) {
|
|
171
|
-
e !== S() && (S.set(e), (e ? O : Le)("*", We));
|
|
172
|
-
}
|
|
173
|
-
const _e = ae(T);
|
|
169
|
+
}, ue = se(B);
|
|
174
170
|
function at(e) {
|
|
171
|
+
e !== B() && (B.set(e), (e ? R : Oe)("*", Le));
|
|
172
|
+
}
|
|
173
|
+
const fe = se(T);
|
|
174
|
+
function st(e) {
|
|
175
175
|
T.set(e), b().log("New target origin set", e);
|
|
176
176
|
}
|
|
177
177
|
const P = h((...e) => {
|
|
178
178
|
window.parent.postMessage(...e);
|
|
179
|
-
}), b = h(
|
|
179
|
+
}), b = h(ge("Bridge", {
|
|
180
180
|
bgColor: "#9147ff",
|
|
181
181
|
textColor: "white",
|
|
182
|
-
shouldLog:
|
|
182
|
+
shouldLog: ue
|
|
183
183
|
}));
|
|
184
|
-
function
|
|
185
|
-
|
|
184
|
+
function it() {
|
|
185
|
+
Re(), [P, T, fe, B, ue, b].forEach((e) => {
|
|
186
186
|
e.unsubAll(), "reset" in e && e.reset();
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
function q(e, t, r) {
|
|
190
190
|
const n = [r], a = e[t];
|
|
191
191
|
typeof a == "function" && n.push(a);
|
|
192
|
-
const o = (...
|
|
193
|
-
n.forEach((_) => _(...
|
|
194
|
-
}, s = Object.assign((...
|
|
195
|
-
o(...
|
|
192
|
+
const o = (...i) => {
|
|
193
|
+
n.forEach((_) => _(...i));
|
|
194
|
+
}, s = Object.assign((...i) => {
|
|
195
|
+
o(...i);
|
|
196
196
|
}, {
|
|
197
197
|
// Unwraps the composer.
|
|
198
198
|
unwrap() {
|
|
199
|
-
const { length:
|
|
200
|
-
if (
|
|
199
|
+
const { length: i } = n;
|
|
200
|
+
if (i === 1) {
|
|
201
201
|
delete e[t];
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
|
-
if (
|
|
205
|
-
|
|
204
|
+
if (i === 2) {
|
|
205
|
+
H(e, t, n[1]);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
n.unshift(1),
|
|
208
|
+
n.unshift(1), H(e, t, o);
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
|
-
|
|
211
|
+
le(
|
|
212
212
|
e,
|
|
213
213
|
t,
|
|
214
214
|
() => s,
|
|
215
|
-
(
|
|
215
|
+
(i) => n.push(i)
|
|
216
216
|
);
|
|
217
217
|
}
|
|
218
|
-
function
|
|
218
|
+
function D(e, t) {
|
|
219
219
|
const r = e[t];
|
|
220
|
-
|
|
220
|
+
le(e, t, () => r, (n) => {
|
|
221
221
|
Object.entries(n).forEach(([a, o]) => {
|
|
222
222
|
r[a] = o;
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
function
|
|
226
|
+
function le(e, t, r, n) {
|
|
227
227
|
Object.defineProperty(e, t, {
|
|
228
228
|
enumerable: !0,
|
|
229
229
|
configurable: !0,
|
|
@@ -231,7 +231,7 @@ function ue(e, t, r, n) {
|
|
|
231
231
|
set: n
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
|
-
function
|
|
234
|
+
function H(e, t, r) {
|
|
235
235
|
Object.defineProperty(e, t, {
|
|
236
236
|
enumerable: !0,
|
|
237
237
|
configurable: !0,
|
|
@@ -240,26 +240,26 @@ function D(e, t, r) {
|
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
const Fe = {
|
|
243
|
-
clipboard_text_received:
|
|
243
|
+
clipboard_text_received: w({
|
|
244
244
|
req_id: E(),
|
|
245
|
-
data:
|
|
245
|
+
data: y(E())
|
|
246
246
|
}),
|
|
247
|
-
custom_method_invoked:
|
|
247
|
+
custom_method_invoked: w({
|
|
248
248
|
req_id: E(),
|
|
249
|
-
result:
|
|
250
|
-
error:
|
|
249
|
+
result: $(me()),
|
|
250
|
+
error: $(E())
|
|
251
251
|
}),
|
|
252
|
-
popup_closed:
|
|
253
|
-
|
|
252
|
+
popup_closed: y(
|
|
253
|
+
w({ button_id: y(E(), () => {
|
|
254
254
|
}) }),
|
|
255
255
|
{}
|
|
256
256
|
),
|
|
257
|
-
viewport_changed:
|
|
258
|
-
|
|
259
|
-
height:
|
|
260
|
-
width:
|
|
261
|
-
is_state_stable:
|
|
262
|
-
is_expanded:
|
|
257
|
+
viewport_changed: y(
|
|
258
|
+
w({
|
|
259
|
+
height: I(),
|
|
260
|
+
width: y(I(), () => window.innerWidth),
|
|
261
|
+
is_state_stable: U(),
|
|
262
|
+
is_expanded: U()
|
|
263
263
|
}),
|
|
264
264
|
// TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
|
|
265
265
|
// null. Leaving this default value until the bug is fixed.
|
|
@@ -269,8 +269,8 @@ const Fe = {
|
|
|
269
269
|
is_expanded: !0
|
|
270
270
|
})
|
|
271
271
|
),
|
|
272
|
-
theme_changed:
|
|
273
|
-
theme_params:
|
|
272
|
+
theme_changed: w({
|
|
273
|
+
theme_params: Pe()
|
|
274
274
|
})
|
|
275
275
|
};
|
|
276
276
|
function J(e) {
|
|
@@ -278,14 +278,14 @@ function J(e) {
|
|
|
278
278
|
return;
|
|
279
279
|
let t;
|
|
280
280
|
try {
|
|
281
|
-
t =
|
|
281
|
+
t = L(oe(ae()), e.data);
|
|
282
282
|
} catch {
|
|
283
283
|
return;
|
|
284
284
|
}
|
|
285
285
|
const { eventType: r, eventData: n } = t, a = Fe[r];
|
|
286
286
|
let o;
|
|
287
287
|
try {
|
|
288
|
-
o = a ?
|
|
288
|
+
o = a ? L(a, n) : n;
|
|
289
289
|
} catch (s) {
|
|
290
290
|
return b().forceError(
|
|
291
291
|
[
|
|
@@ -301,14 +301,14 @@ function J(e) {
|
|
|
301
301
|
Te(r, o);
|
|
302
302
|
}
|
|
303
303
|
const {
|
|
304
|
-
on:
|
|
305
|
-
off:
|
|
304
|
+
on: R,
|
|
305
|
+
off: Oe,
|
|
306
306
|
emit: Te,
|
|
307
|
-
clear:
|
|
308
|
-
} =
|
|
307
|
+
clear: Re
|
|
308
|
+
} = _e(
|
|
309
309
|
() => {
|
|
310
310
|
const e = window;
|
|
311
|
-
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent",
|
|
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);
|
|
312
312
|
},
|
|
313
313
|
() => {
|
|
314
314
|
[
|
|
@@ -325,10 +325,10 @@ const {
|
|
|
325
325
|
"unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
|
|
326
326
|
}), window.removeEventListener("message", J);
|
|
327
327
|
}
|
|
328
|
-
),
|
|
329
|
-
function
|
|
328
|
+
), je = (...e) => P()(...e);
|
|
329
|
+
function Ue(e, t) {
|
|
330
330
|
l.pipe(
|
|
331
|
-
|
|
331
|
+
S(
|
|
332
332
|
// @ts-expect-error It's ok, TS can't determine a specific override.
|
|
333
333
|
e,
|
|
334
334
|
t
|
|
@@ -338,49 +338,49 @@ function je(e, t) {
|
|
|
338
338
|
})
|
|
339
339
|
);
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function S(e, t) {
|
|
342
342
|
b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
|
|
343
343
|
const r = window, n = JSON.stringify({ eventType: e, eventData: t });
|
|
344
|
-
return
|
|
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());
|
|
345
345
|
}
|
|
346
|
-
function
|
|
346
|
+
function j(e, t, r = {}) {
|
|
347
347
|
const {
|
|
348
348
|
// If no capture function was passed, we capture the first compatible event.
|
|
349
349
|
capture: n = () => !0,
|
|
350
|
-
postEvent: a =
|
|
351
|
-
} = r, o = h(), [s,
|
|
352
|
-
(Array.isArray(t) ? t : [t]).forEach((
|
|
350
|
+
postEvent: a = S
|
|
351
|
+
} = r, o = h(), [s, i] = ee();
|
|
352
|
+
(Array.isArray(t) ? t : [t]).forEach((p) => {
|
|
353
353
|
s(
|
|
354
|
-
|
|
354
|
+
R(p, (u) => {
|
|
355
355
|
const f = Array.isArray(t);
|
|
356
|
-
n(f ? { event:
|
|
357
|
-
f ? { event:
|
|
356
|
+
n(f ? { event: p, payload: u } : u) && o.set([
|
|
357
|
+
f ? { event: p, payload: u } : u
|
|
358
358
|
]);
|
|
359
359
|
})
|
|
360
360
|
);
|
|
361
361
|
});
|
|
362
|
-
const _ = (
|
|
362
|
+
const _ = (p) => (i(), p);
|
|
363
363
|
return l.pipe(
|
|
364
364
|
async () => a(e, r.params),
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
return
|
|
369
|
-
const g = (
|
|
370
|
-
|
|
365
|
+
d.chainW(() => te((p, u, f) => {
|
|
366
|
+
const m = o();
|
|
367
|
+
if (m)
|
|
368
|
+
return p(m[0]);
|
|
369
|
+
const g = (v) => {
|
|
370
|
+
v && p(v[0]);
|
|
371
371
|
}, V = () => {
|
|
372
372
|
o.unsub(g);
|
|
373
373
|
};
|
|
374
374
|
o.sub(g), f.on("finalized", V);
|
|
375
375
|
}, r)),
|
|
376
|
-
|
|
376
|
+
d.mapBoth(_, _)
|
|
377
377
|
);
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function pt(e, t, r) {
|
|
380
380
|
const { postEvent: n } = r || {};
|
|
381
381
|
return C(
|
|
382
382
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
383
|
-
|
|
383
|
+
j(e, t, {
|
|
384
384
|
...r,
|
|
385
385
|
postEvent: n ? (...a) => {
|
|
386
386
|
try {
|
|
@@ -388,60 +388,60 @@ function it(e, t, r) {
|
|
|
388
388
|
} catch (o) {
|
|
389
389
|
return c.left(o);
|
|
390
390
|
}
|
|
391
|
-
} :
|
|
391
|
+
} : S
|
|
392
392
|
})
|
|
393
393
|
);
|
|
394
394
|
}
|
|
395
|
-
function
|
|
396
|
-
const r =
|
|
395
|
+
function ct(e, t) {
|
|
396
|
+
const r = Ie(
|
|
397
397
|
// @ts-expect-error TS doesn't get what override we are going to use.
|
|
398
398
|
e,
|
|
399
399
|
t
|
|
400
400
|
);
|
|
401
|
-
return typeof r == "function" ?
|
|
401
|
+
return typeof r == "function" ? re.fn(() => C(r)) : r;
|
|
402
402
|
}
|
|
403
|
-
function
|
|
404
|
-
const r =
|
|
403
|
+
function Ie(e, t) {
|
|
404
|
+
const r = ie(window);
|
|
405
405
|
if (!e)
|
|
406
406
|
return r || l.pipe(M(), c.match(() => !1, () => !0));
|
|
407
407
|
if (r)
|
|
408
|
-
return
|
|
408
|
+
return d.right(!0);
|
|
409
409
|
const { timeout: n = 100 } = t || {};
|
|
410
410
|
return l.pipe(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
(a) =>
|
|
411
|
+
j("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
|
|
412
|
+
d.match(
|
|
413
|
+
(a) => ve.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
|
|
414
414
|
() => c.right(!0)
|
|
415
415
|
)
|
|
416
416
|
);
|
|
417
417
|
}
|
|
418
|
-
function
|
|
418
|
+
function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
419
419
|
if (e) {
|
|
420
420
|
const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
|
|
421
421
|
// Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
|
|
422
422
|
// value. We are doing it because we are working with vbWebAppData presented as a
|
|
423
423
|
// string, not an object as serializeLaunchParamsQuery requires.
|
|
424
|
-
|
|
424
|
+
ke({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
|
|
425
425
|
);
|
|
426
426
|
try {
|
|
427
|
-
|
|
427
|
+
xe(o);
|
|
428
428
|
} catch (s) {
|
|
429
|
-
throw new
|
|
429
|
+
throw new Me(o, s);
|
|
430
430
|
}
|
|
431
|
-
|
|
431
|
+
Z("launchParams", o);
|
|
432
432
|
}
|
|
433
|
-
if (
|
|
433
|
+
if (pe()) {
|
|
434
434
|
if (!t)
|
|
435
435
|
return;
|
|
436
436
|
r && P.reset();
|
|
437
437
|
const o = P();
|
|
438
438
|
P.set((...s) => {
|
|
439
|
-
const [
|
|
439
|
+
const [i] = s, _ = () => {
|
|
440
440
|
o(...s);
|
|
441
441
|
};
|
|
442
442
|
try {
|
|
443
|
-
const
|
|
444
|
-
t({ name:
|
|
443
|
+
const p = L(oe(ae()), i);
|
|
444
|
+
t({ name: p.eventType, params: p.eventData }, _);
|
|
445
445
|
} catch {
|
|
446
446
|
_();
|
|
447
447
|
}
|
|
@@ -453,17 +453,54 @@ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
453
453
|
window.VBotWebviewProxy = {
|
|
454
454
|
...n,
|
|
455
455
|
postEvent(o, s) {
|
|
456
|
-
const
|
|
456
|
+
const i = () => {
|
|
457
457
|
a(o, s);
|
|
458
458
|
};
|
|
459
459
|
t ? t({
|
|
460
460
|
name: o,
|
|
461
461
|
params: s ? JSON.parse(s) : void 0
|
|
462
|
-
},
|
|
462
|
+
}, i) : i();
|
|
463
463
|
}
|
|
464
464
|
}, b().log("Environment was mocked by the mockVBotEnv function");
|
|
465
465
|
}
|
|
466
|
-
function
|
|
466
|
+
function ut(e, t = "*") {
|
|
467
|
+
const r = (o) => {
|
|
468
|
+
if (o.source === e.contentWindow)
|
|
469
|
+
try {
|
|
470
|
+
const s = JSON.parse(o.data), { eventType: i, eventData: _ } = s;
|
|
471
|
+
n.emit(i, _);
|
|
472
|
+
} catch {
|
|
473
|
+
}
|
|
474
|
+
}, n = _e(
|
|
475
|
+
() => {
|
|
476
|
+
window.addEventListener("message", r);
|
|
477
|
+
},
|
|
478
|
+
() => {
|
|
479
|
+
window.removeEventListener("message", r);
|
|
480
|
+
}
|
|
481
|
+
), a = {
|
|
482
|
+
// Spread the emitter methods: on, off, emit, clear
|
|
483
|
+
...n,
|
|
484
|
+
send: (o, s) => {
|
|
485
|
+
if (e.contentWindow) {
|
|
486
|
+
const i = JSON.stringify({ eventType: o, eventData: s });
|
|
487
|
+
e.contentWindow.postMessage(i, t);
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
// We need to override clear to also remove the window listener
|
|
491
|
+
clear: () => {
|
|
492
|
+
n.clear(), k === a && (k = void 0);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
return k = a, a;
|
|
496
|
+
}
|
|
497
|
+
let k;
|
|
498
|
+
function ft() {
|
|
499
|
+
if (!k)
|
|
500
|
+
throw new Error("HostBridge not initialized. Call defineHostBridge() first.");
|
|
501
|
+
return k;
|
|
502
|
+
}
|
|
503
|
+
function $e(e) {
|
|
467
504
|
return ({ req_id: t }) => t === e;
|
|
468
505
|
}
|
|
469
506
|
const N = {
|
|
@@ -561,49 +598,49 @@ const N = {
|
|
|
561
598
|
function Q(e, t) {
|
|
562
599
|
return Object.keys(N).find((n) => N[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
|
|
563
600
|
}
|
|
564
|
-
function
|
|
601
|
+
function K(e) {
|
|
565
602
|
return e.split(".").map(Number);
|
|
566
603
|
}
|
|
567
|
-
function
|
|
568
|
-
const r =
|
|
604
|
+
function ze(e, t) {
|
|
605
|
+
const r = K(e), n = K(t), a = Math.max(r.length, n.length);
|
|
569
606
|
for (let o = 0; o < a; o += 1) {
|
|
570
|
-
const s = r[o] || 0,
|
|
571
|
-
if (s !==
|
|
572
|
-
return s >
|
|
607
|
+
const s = r[o] || 0, i = n[o] || 0;
|
|
608
|
+
if (s !== i)
|
|
609
|
+
return s > i ? 1 : -1;
|
|
573
610
|
}
|
|
574
611
|
return 0;
|
|
575
612
|
}
|
|
576
|
-
function
|
|
613
|
+
function Y(e, t, r) {
|
|
577
614
|
const n = r ? Q(
|
|
578
615
|
e,
|
|
579
616
|
t
|
|
580
617
|
) : Q(e);
|
|
581
|
-
return n ?
|
|
618
|
+
return n ? ze(n, r || t) <= 0 : !1;
|
|
582
619
|
}
|
|
583
|
-
function
|
|
620
|
+
function lt(e, t = "strict") {
|
|
584
621
|
const r = typeof t == "function" ? t : (n) => {
|
|
585
|
-
const { method: a, version: o } = n, s = "param" in n ? new
|
|
622
|
+
const { method: a, version: o } = n, s = "param" in n ? new Ae(a, n.param, o) : new Be(a, o);
|
|
586
623
|
if (t === "strict")
|
|
587
624
|
throw s;
|
|
588
625
|
return b().forceWarn(s.message);
|
|
589
626
|
};
|
|
590
|
-
return ((n, a) =>
|
|
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 }));
|
|
591
628
|
}
|
|
592
|
-
function
|
|
629
|
+
function Ge(e, t, r, n) {
|
|
593
630
|
return l.pipe(
|
|
594
|
-
|
|
631
|
+
j("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
595
632
|
...n || {},
|
|
596
633
|
params: { method: e, params: t, req_id: r },
|
|
597
|
-
capture:
|
|
634
|
+
capture: $e(r)
|
|
598
635
|
}),
|
|
599
|
-
|
|
636
|
+
d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
|
|
600
637
|
);
|
|
601
638
|
}
|
|
602
|
-
function
|
|
603
|
-
return
|
|
639
|
+
function wt(e, t, r, n) {
|
|
640
|
+
return re.fn(() => l.pipe(
|
|
604
641
|
// @ts-expect-error TypeScript is unable to determine required override.
|
|
605
|
-
|
|
606
|
-
|
|
642
|
+
Ge(e, t, r, n),
|
|
643
|
+
d.match(
|
|
607
644
|
(a) => {
|
|
608
645
|
throw a;
|
|
609
646
|
},
|
|
@@ -611,41 +648,41 @@ function ut(e, t, r, n) {
|
|
|
611
648
|
)
|
|
612
649
|
)());
|
|
613
650
|
}
|
|
614
|
-
function
|
|
651
|
+
function De(e, t, r = {}) {
|
|
615
652
|
const {
|
|
616
653
|
// If no capture function was passed, we capture the first compatible event.
|
|
617
654
|
capture: n = () => !0,
|
|
618
|
-
postEvent: a =
|
|
619
|
-
} = r, o = h(), [s,
|
|
620
|
-
(Array.isArray(t) ? t : [t]).forEach((
|
|
655
|
+
postEvent: a = S
|
|
656
|
+
} = r, o = h(), [s, i] = ee();
|
|
657
|
+
(Array.isArray(t) ? t : [t]).forEach((p) => {
|
|
621
658
|
s(
|
|
622
|
-
|
|
623
|
-
(Array.isArray(t) ? n({ event:
|
|
659
|
+
R(p, (u) => {
|
|
660
|
+
(Array.isArray(t) ? n({ event: p, payload: u }) : n(u)) && o.set([u]);
|
|
624
661
|
})
|
|
625
662
|
);
|
|
626
663
|
});
|
|
627
|
-
const _ = (
|
|
664
|
+
const _ = (p) => (i(), p);
|
|
628
665
|
return l.pipe(
|
|
629
666
|
async () => a(e, r.params),
|
|
630
|
-
|
|
631
|
-
const
|
|
632
|
-
if (
|
|
633
|
-
return
|
|
634
|
-
const g = (
|
|
635
|
-
|
|
667
|
+
d.chainW(() => te((p, u, f) => {
|
|
668
|
+
const m = o();
|
|
669
|
+
if (m)
|
|
670
|
+
return p(m[0]);
|
|
671
|
+
const g = (v) => {
|
|
672
|
+
v && p(v[0]);
|
|
636
673
|
}, V = () => {
|
|
637
674
|
o.unsub(g);
|
|
638
675
|
};
|
|
639
676
|
o.sub(g), f.on("finalized", V);
|
|
640
677
|
}, r)),
|
|
641
|
-
|
|
678
|
+
d.mapBoth(_, _)
|
|
642
679
|
);
|
|
643
680
|
}
|
|
644
|
-
function
|
|
681
|
+
function dt(e, t, r) {
|
|
645
682
|
const { postEvent: n } = r || {};
|
|
646
683
|
return C(
|
|
647
684
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
648
|
-
|
|
685
|
+
De(e, t, {
|
|
649
686
|
...r,
|
|
650
687
|
postEvent: n ? (...a) => {
|
|
651
688
|
try {
|
|
@@ -653,34 +690,34 @@ function ft(e, t, r) {
|
|
|
653
690
|
} catch (o) {
|
|
654
691
|
return c.left(o);
|
|
655
692
|
}
|
|
656
|
-
} :
|
|
693
|
+
} : S
|
|
657
694
|
})
|
|
658
695
|
);
|
|
659
696
|
}
|
|
660
|
-
function
|
|
697
|
+
function mt() {
|
|
661
698
|
Object.hasOwn || (Object.hasOwn = function(e, t) {
|
|
662
699
|
return Object.prototype.hasOwnProperty.call(e, t);
|
|
663
700
|
});
|
|
664
701
|
}
|
|
665
|
-
function
|
|
702
|
+
function we(e) {
|
|
666
703
|
return c.tryCatch(() => decodeURIComponent(
|
|
667
704
|
atob(
|
|
668
705
|
e.replace(/-/g, "+").replace(/_/g, "/")
|
|
669
706
|
).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
670
707
|
), (t) => t);
|
|
671
708
|
}
|
|
672
|
-
const
|
|
673
|
-
function
|
|
709
|
+
const bt = A(we);
|
|
710
|
+
function de(e) {
|
|
674
711
|
return btoa(
|
|
675
712
|
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
|
|
676
713
|
).replace(/\+/g, "-").replace(/\//g, "_");
|
|
677
714
|
}
|
|
678
|
-
function
|
|
679
|
-
const t =
|
|
715
|
+
function He(e) {
|
|
716
|
+
const t = de(typeof e == "string" ? e : JSON.stringify(e));
|
|
680
717
|
return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
|
|
681
718
|
}
|
|
682
|
-
const
|
|
683
|
-
function
|
|
719
|
+
const ht = A(He);
|
|
720
|
+
function gt(e, t) {
|
|
684
721
|
return C(
|
|
685
722
|
Je(
|
|
686
723
|
e,
|
|
@@ -691,68 +728,70 @@ function dt(e, t) {
|
|
|
691
728
|
}
|
|
692
729
|
function Je(e, t) {
|
|
693
730
|
return l.pipe(
|
|
694
|
-
|
|
695
|
-
c.chain((r) => t ? typeof t == "function" ? t(r) :
|
|
731
|
+
we(e),
|
|
732
|
+
c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(r))
|
|
696
733
|
);
|
|
697
734
|
}
|
|
698
|
-
function
|
|
699
|
-
return
|
|
735
|
+
function vt(e) {
|
|
736
|
+
return de(e).length <= 512;
|
|
700
737
|
}
|
|
701
738
|
export {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
739
|
+
St as CancelledError,
|
|
740
|
+
Me as InvalidLaunchParamsError,
|
|
741
|
+
Ve as InvokeCustomMethodFailedError,
|
|
742
|
+
Ce as LaunchParamsRetrieveError,
|
|
743
|
+
Ae as MethodParameterUnsupportedError,
|
|
744
|
+
Be as MethodUnsupportedError,
|
|
745
|
+
Bt as TimeoutError,
|
|
746
|
+
ce as UnknownEnvError,
|
|
747
|
+
mt as applyPolyfills,
|
|
748
|
+
$e as captureSameReq,
|
|
749
|
+
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,
|
|
721
758
|
Je as decodeStartParamFp,
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
759
|
+
kt as deepSnakeToCamelObjKeys,
|
|
760
|
+
ut as defineHostBridge,
|
|
761
|
+
W as emitEvent,
|
|
762
|
+
de as encodeBase64Url,
|
|
763
|
+
ft as getHostBridge,
|
|
725
764
|
Q as getReleaseVersion,
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
765
|
+
ie as hasWebviewProxy,
|
|
766
|
+
wt as invokeCustomMethod,
|
|
767
|
+
Ge as invokeCustomMethodFp,
|
|
768
|
+
pe as isIframe,
|
|
769
|
+
vt as isSafeToCreateStartParam,
|
|
770
|
+
ct as isVBMA,
|
|
771
|
+
Ie as isVBMAFp,
|
|
733
772
|
b as logger,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
773
|
+
_t as mockVBotEnv,
|
|
774
|
+
Oe as off,
|
|
775
|
+
Re as offAll,
|
|
776
|
+
R as on,
|
|
777
|
+
Ue as postEvent,
|
|
778
|
+
S as postEventFp,
|
|
779
|
+
je as postMessage,
|
|
741
780
|
P as postMessageImpl,
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
781
|
+
dt as request,
|
|
782
|
+
pt as request2,
|
|
783
|
+
j as request2Fp,
|
|
784
|
+
De as requestFp,
|
|
785
|
+
it as resetGlobals,
|
|
786
|
+
rt as retrieveLaunchParams,
|
|
787
|
+
We as retrieveLaunchParamsFp,
|
|
788
|
+
nt as retrieveRawInitData,
|
|
789
|
+
qe as retrieveRawInitDataFp,
|
|
790
|
+
ot as retrieveRawLaunchParams,
|
|
752
791
|
M as retrieveRawLaunchParamsFp,
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
792
|
+
at as setDebug,
|
|
793
|
+
st as setTargetOrigin,
|
|
794
|
+
Y as supports,
|
|
795
|
+
fe as targetOrigin
|
|
757
796
|
};
|
|
758
797
|
//# sourceMappingURL=index.js.map
|