@tma.js/bridge 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +261 -261
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { is as L, looseObject as l, function as Y, nullish as h, boolean as I, number as j, string as d, optional as z, unknown as ye, parse as M, any as Ee } from "valibot";
|
|
2
2
|
import { throwifyFpFn as x, getStorageValue as Pe, setStorageValue as X, createLogger as xe, throwifyAnyEither as C, BetterTaskEither as ke, createCbCollector as Se } from "@tma.js/toolkit";
|
|
3
|
-
import { createLogger as
|
|
3
|
+
import { createLogger as or, deepSnakeToCamelObjKeys as ar } from "@tma.js/toolkit";
|
|
4
4
|
import { BetterPromise as Z, TimeoutError as Te } from "better-promises";
|
|
5
|
-
import { CancelledError as
|
|
6
|
-
import { parseLaunchParamsQueryFp as ee, themeParams as Ae, pipeJsonToSchema as
|
|
5
|
+
import { CancelledError as sr, TimeoutError as ur } from "better-promises";
|
|
6
|
+
import { parseLaunchParamsQueryFp as ee, themeParams as Ae, pipeJsonToSchema as te, miniAppsMessage as re, serializeLaunchParamsQuery as $e, parseLaunchParamsQuery as Me } from "@tma.js/transformers";
|
|
7
7
|
import { errorClass as b, errorClassWithData as Le } from "error-kid";
|
|
8
8
|
import { signal as k, computed as ne } from "@tma.js/signals";
|
|
9
9
|
import Ce from "mitt";
|
|
@@ -20,72 +20,72 @@ function ae() {
|
|
|
20
20
|
return !0;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
var We = function(e,
|
|
24
|
-
if (
|
|
25
|
-
(o || !(n in
|
|
26
|
-
return e.concat(o || Array.prototype.slice.call(
|
|
23
|
+
var We = function(e, t, r) {
|
|
24
|
+
if (r || arguments.length === 2) for (var n = 0, a = t.length, o; n < a; n++)
|
|
25
|
+
(o || !(n in t)) && (o || (o = Array.prototype.slice.call(t, 0, n)), o[n] = t[n]);
|
|
26
|
+
return e.concat(o || Array.prototype.slice.call(t));
|
|
27
27
|
};
|
|
28
28
|
function Fe(e) {
|
|
29
29
|
return e;
|
|
30
30
|
}
|
|
31
|
-
function y(e,
|
|
31
|
+
function y(e, t, r, n, a, o, i, s, u) {
|
|
32
32
|
switch (arguments.length) {
|
|
33
33
|
case 1:
|
|
34
34
|
return e;
|
|
35
35
|
case 2:
|
|
36
36
|
return function() {
|
|
37
|
-
return
|
|
37
|
+
return t(e.apply(this, arguments));
|
|
38
38
|
};
|
|
39
39
|
case 3:
|
|
40
40
|
return function() {
|
|
41
|
-
return t(
|
|
41
|
+
return r(t(e.apply(this, arguments)));
|
|
42
42
|
};
|
|
43
43
|
case 4:
|
|
44
44
|
return function() {
|
|
45
|
-
return n(t(
|
|
45
|
+
return n(r(t(e.apply(this, arguments))));
|
|
46
46
|
};
|
|
47
47
|
case 5:
|
|
48
48
|
return function() {
|
|
49
|
-
return a(n(t(
|
|
49
|
+
return a(n(r(t(e.apply(this, arguments)))));
|
|
50
50
|
};
|
|
51
51
|
case 6:
|
|
52
52
|
return function() {
|
|
53
|
-
return o(a(n(t(
|
|
53
|
+
return o(a(n(r(t(e.apply(this, arguments))))));
|
|
54
54
|
};
|
|
55
55
|
case 7:
|
|
56
56
|
return function() {
|
|
57
|
-
return i(o(a(n(t(
|
|
57
|
+
return i(o(a(n(r(t(e.apply(this, arguments)))))));
|
|
58
58
|
};
|
|
59
59
|
case 8:
|
|
60
60
|
return function() {
|
|
61
|
-
return s(i(o(a(n(t(
|
|
61
|
+
return s(i(o(a(n(r(t(e.apply(this, arguments))))))));
|
|
62
62
|
};
|
|
63
63
|
case 9:
|
|
64
64
|
return function() {
|
|
65
|
-
return u(s(i(o(a(n(t(
|
|
65
|
+
return u(s(i(o(a(n(r(t(e.apply(this, arguments)))))))));
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function m(e,
|
|
69
|
+
function m(e, t, r, n, a, o, i, s, u) {
|
|
70
70
|
switch (arguments.length) {
|
|
71
71
|
case 1:
|
|
72
72
|
return e;
|
|
73
73
|
case 2:
|
|
74
|
-
return
|
|
74
|
+
return t(e);
|
|
75
75
|
case 3:
|
|
76
|
-
return t(
|
|
76
|
+
return r(t(e));
|
|
77
77
|
case 4:
|
|
78
|
-
return n(t(
|
|
78
|
+
return n(r(t(e)));
|
|
79
79
|
case 5:
|
|
80
|
-
return a(n(t(
|
|
80
|
+
return a(n(r(t(e))));
|
|
81
81
|
case 6:
|
|
82
|
-
return o(a(n(t(
|
|
82
|
+
return o(a(n(r(t(e)))));
|
|
83
83
|
case 7:
|
|
84
|
-
return i(o(a(n(t(
|
|
84
|
+
return i(o(a(n(r(t(e))))));
|
|
85
85
|
case 8:
|
|
86
|
-
return s(i(o(a(n(t(
|
|
86
|
+
return s(i(o(a(n(r(t(e)))))));
|
|
87
87
|
case 9:
|
|
88
|
-
return u(s(i(o(a(n(t(
|
|
88
|
+
return u(s(i(o(a(n(r(t(e))))))));
|
|
89
89
|
default: {
|
|
90
90
|
for (var c = arguments[0], p = 1; p < arguments.length; p++)
|
|
91
91
|
c = arguments[p](c);
|
|
@@ -93,14 +93,14 @@ function m(e, r, t, n, a, o, i, s, u) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var W = function(e,
|
|
97
|
-
var
|
|
96
|
+
var W = function(e, t) {
|
|
97
|
+
var r = typeof e == "number" ? function(n) {
|
|
98
98
|
return n.length >= e;
|
|
99
99
|
} : e;
|
|
100
100
|
return function() {
|
|
101
101
|
var n = Array.from(arguments);
|
|
102
|
-
return
|
|
103
|
-
return
|
|
102
|
+
return r(arguments) ? t.apply(this, n) : function(a) {
|
|
103
|
+
return t.apply(void 0, We([a], n, !1));
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
}, qe = { _tag: "None" }, Oe = function(e) {
|
|
@@ -111,31 +111,31 @@ var W = function(e, r) {
|
|
|
111
111
|
return { _tag: "Left", left: e };
|
|
112
112
|
}, Ie = function(e) {
|
|
113
113
|
return { _tag: "Right", right: e };
|
|
114
|
-
}, w = Ue, _ = Ie, ie = /* @__PURE__ */ W(2, function(e,
|
|
115
|
-
return E(e) ? e :
|
|
114
|
+
}, w = Ue, _ = Ie, ie = /* @__PURE__ */ W(2, function(e, t) {
|
|
115
|
+
return E(e) ? e : t(e.right);
|
|
116
116
|
}), je = function(e) {
|
|
117
|
-
return function(
|
|
118
|
-
return E(
|
|
117
|
+
return function(t) {
|
|
118
|
+
return E(t) ? t : _(e(t.right));
|
|
119
119
|
};
|
|
120
120
|
}, ze = function(e) {
|
|
121
|
-
return function(r) {
|
|
122
|
-
return E(r) ? w(e(r.left)) : r;
|
|
123
|
-
};
|
|
124
|
-
}, E = Re, se = function(e, r) {
|
|
125
121
|
return function(t) {
|
|
126
|
-
return E(t) ? e(t.left) :
|
|
122
|
+
return E(t) ? w(e(t.left)) : t;
|
|
123
|
+
};
|
|
124
|
+
}, E = Re, se = function(e, t) {
|
|
125
|
+
return function(r) {
|
|
126
|
+
return E(r) ? e(r.left) : t(r.right);
|
|
127
127
|
};
|
|
128
|
-
}, Ge = se, F = se, Ve = F, q = function(e,
|
|
128
|
+
}, Ge = se, F = se, Ve = F, q = function(e, t) {
|
|
129
129
|
try {
|
|
130
130
|
return _(e());
|
|
131
|
-
} catch (
|
|
132
|
-
return w(r
|
|
131
|
+
} catch (r) {
|
|
132
|
+
return w(t(r));
|
|
133
133
|
}
|
|
134
134
|
}, De = ie, Ne = ie, Be = qe, Je = Oe, Qe = function(e) {
|
|
135
135
|
return e._tag === "None";
|
|
136
|
-
}, He = function(e,
|
|
137
|
-
return function(
|
|
138
|
-
return Qe(
|
|
136
|
+
}, He = function(e, t) {
|
|
137
|
+
return function(r) {
|
|
138
|
+
return Qe(r) ? e() : t(r.value);
|
|
139
139
|
};
|
|
140
140
|
}, Ke = He;
|
|
141
141
|
function Ye(e) {
|
|
@@ -145,34 +145,34 @@ function Xe(e) {
|
|
|
145
145
|
return y(w, e.of);
|
|
146
146
|
}
|
|
147
147
|
function Ze(e) {
|
|
148
|
-
return function(
|
|
149
|
-
return e.chain(
|
|
150
|
-
return E(n) ? e.of(n) :
|
|
148
|
+
return function(t, r) {
|
|
149
|
+
return e.chain(t, function(n) {
|
|
150
|
+
return E(n) ? e.of(n) : r(n.right);
|
|
151
151
|
});
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
return function(
|
|
154
|
+
function et(e) {
|
|
155
|
+
return function(t, r) {
|
|
156
156
|
return function(n) {
|
|
157
|
-
return e.map(n, F(
|
|
157
|
+
return e.map(n, F(t, r));
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
var ue = function(e,
|
|
162
|
-
return m(e,
|
|
163
|
-
},
|
|
164
|
-
return m(e,
|
|
165
|
-
},
|
|
166
|
-
return function(
|
|
161
|
+
var ue = function(e, t) {
|
|
162
|
+
return m(e, rt(t));
|
|
163
|
+
}, tt = function(e, t) {
|
|
164
|
+
return m(e, nt(t));
|
|
165
|
+
}, rt = function(e) {
|
|
166
|
+
return function(t) {
|
|
167
167
|
return function() {
|
|
168
|
-
return Promise.resolve().then(
|
|
168
|
+
return Promise.resolve().then(t).then(e);
|
|
169
169
|
};
|
|
170
170
|
};
|
|
171
|
-
},
|
|
172
|
-
return function(
|
|
171
|
+
}, nt = function(e) {
|
|
172
|
+
return function(t) {
|
|
173
173
|
return function() {
|
|
174
|
-
return Promise.all([Promise.resolve().then(
|
|
175
|
-
var n =
|
|
174
|
+
return Promise.all([Promise.resolve().then(t), Promise.resolve().then(e)]).then(function(r) {
|
|
175
|
+
var n = r[0], a = r[1];
|
|
176
176
|
return n(a);
|
|
177
177
|
});
|
|
178
178
|
};
|
|
@@ -181,69 +181,69 @@ var ue = function(e, r) {
|
|
|
181
181
|
return function() {
|
|
182
182
|
return Promise.resolve(e);
|
|
183
183
|
};
|
|
184
|
-
},
|
|
184
|
+
}, ot = /* @__PURE__ */ W(2, function(e, t) {
|
|
185
185
|
return function() {
|
|
186
|
-
return Promise.resolve().then(e).then(function(
|
|
187
|
-
return r
|
|
186
|
+
return Promise.resolve().then(e).then(function(r) {
|
|
187
|
+
return t(r)();
|
|
188
188
|
});
|
|
189
189
|
};
|
|
190
|
-
}), pe = "Task",
|
|
190
|
+
}), pe = "Task", at = {
|
|
191
191
|
URI: pe,
|
|
192
192
|
map: ue
|
|
193
193
|
}, _e = {
|
|
194
194
|
of: ce
|
|
195
|
-
},
|
|
195
|
+
}, it = {
|
|
196
196
|
URI: pe,
|
|
197
197
|
map: ue,
|
|
198
198
|
of: ce,
|
|
199
|
-
ap:
|
|
200
|
-
chain:
|
|
201
|
-
},
|
|
202
|
-
class
|
|
203
|
-
`Method "${
|
|
199
|
+
ap: tt,
|
|
200
|
+
chain: ot
|
|
201
|
+
}, st = /* @__PURE__ */ Xe(_e), fe = /* @__PURE__ */ Ye(_e), le = /* @__PURE__ */ et(at), me = /* @__PURE__ */ W(2, Ze(it)), ut = me, ct = me;
|
|
202
|
+
class pt extends b("MethodUnsupportedError", (t, r) => [
|
|
203
|
+
`Method "${t}" is unsupported in Mini Apps version ${r}`
|
|
204
204
|
]) {
|
|
205
205
|
}
|
|
206
|
-
class
|
|
207
|
-
`Parameter "${
|
|
206
|
+
class _t extends b("MethodParameterUnsupportedError", (t, r, n) => [
|
|
207
|
+
`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
|
|
208
208
|
]) {
|
|
209
209
|
}
|
|
210
|
-
class
|
|
210
|
+
class ft extends Le(
|
|
211
211
|
"LaunchParamsRetrieveError",
|
|
212
|
-
(
|
|
213
|
-
(
|
|
212
|
+
(t) => ({ errors: t }),
|
|
213
|
+
(t) => [
|
|
214
214
|
[
|
|
215
215
|
"Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?",
|
|
216
216
|
"📖 Refer to docs for more information:",
|
|
217
217
|
"https://docs.telegram-mini-apps.com/packages/tma-js-bridge/environment",
|
|
218
218
|
"",
|
|
219
219
|
"Collected errors:",
|
|
220
|
-
...
|
|
220
|
+
...t.map(({ source: r, error: n }) => `Source: ${r} / ${n instanceof Error ? n.message : String(n)}`)
|
|
221
221
|
].join(`
|
|
222
222
|
`)
|
|
223
223
|
]
|
|
224
224
|
) {
|
|
225
225
|
}
|
|
226
|
-
class
|
|
227
|
-
`Invalid value for launch params: ${
|
|
228
|
-
{ cause:
|
|
226
|
+
class lt extends b("InvalidLaunchParamsError", (t, r) => [
|
|
227
|
+
`Invalid value for launch params: ${t}`,
|
|
228
|
+
{ cause: r }
|
|
229
229
|
]) {
|
|
230
230
|
}
|
|
231
|
-
class
|
|
231
|
+
class mt extends b("UnknownEnvError") {
|
|
232
232
|
}
|
|
233
|
-
class
|
|
233
|
+
class wt extends b(
|
|
234
234
|
"InvokeCustomMethodError",
|
|
235
|
-
(
|
|
235
|
+
(t) => [`Server returned error: ${t}`]
|
|
236
236
|
) {
|
|
237
237
|
}
|
|
238
238
|
const G = "launchParams";
|
|
239
239
|
function V(e) {
|
|
240
240
|
return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
241
241
|
}
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
return
|
|
245
|
-
})),
|
|
246
|
-
|
|
242
|
+
const gt = y(S, De(ee)), jt = x(gt), ht = y(S, je((e) => {
|
|
243
|
+
const t = new URLSearchParams(e).get("tgWebAppData");
|
|
244
|
+
return t ? Je(t) : Be;
|
|
245
|
+
})), zt = y(
|
|
246
|
+
ht,
|
|
247
247
|
Ve((e) => {
|
|
248
248
|
throw e;
|
|
249
249
|
}, (e) => e),
|
|
@@ -252,7 +252,7 @@ const gr = y(S, De(ee)), jr = x(gr), hr = y(S, je((e) => {
|
|
|
252
252
|
);
|
|
253
253
|
function S() {
|
|
254
254
|
const e = [];
|
|
255
|
-
for (const [
|
|
255
|
+
for (const [t, r] of [
|
|
256
256
|
// Try to retrieve launch parameters from the current location. This method
|
|
257
257
|
// can return nothing in case, location was changed, and then the page was
|
|
258
258
|
// reloaded.
|
|
@@ -265,9 +265,9 @@ function S() {
|
|
|
265
265
|
// Finally, try using the session storage.
|
|
266
266
|
[() => Pe(G), "local storage"]
|
|
267
267
|
]) {
|
|
268
|
-
const n =
|
|
268
|
+
const n = t();
|
|
269
269
|
if (!n) {
|
|
270
|
-
e.push({ source:
|
|
270
|
+
e.push({ source: r, error: new Error("Source is empty") });
|
|
271
271
|
continue;
|
|
272
272
|
}
|
|
273
273
|
const a = m(
|
|
@@ -275,37 +275,37 @@ function S() {
|
|
|
275
275
|
Ge((o) => o, () => !0)
|
|
276
276
|
);
|
|
277
277
|
if (typeof a != "boolean") {
|
|
278
|
-
e.push({ source:
|
|
278
|
+
e.push({ source: r, error: a });
|
|
279
279
|
continue;
|
|
280
280
|
}
|
|
281
281
|
return X(G, n), _(n);
|
|
282
282
|
}
|
|
283
|
-
return w(new
|
|
283
|
+
return w(new ft(e));
|
|
284
284
|
}
|
|
285
|
-
const
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
const u =
|
|
289
|
-
|
|
285
|
+
const Gt = x(S);
|
|
286
|
+
function dt(e, t) {
|
|
287
|
+
const r = /* @__PURE__ */ new Map(), n = Ce(), a = (o, i, s = !1) => {
|
|
288
|
+
const u = r.get(o) || /* @__PURE__ */ new Map();
|
|
289
|
+
r.set(o, u);
|
|
290
290
|
const c = u.get(i) || [];
|
|
291
291
|
u.set(i, c);
|
|
292
292
|
const p = c.findIndex((f) => f[1] === s);
|
|
293
293
|
if (p >= 0 && (n.off(o, c[p][0]), c.splice(p, 1), !c.length && (u.delete(i), !u.size))) {
|
|
294
|
-
const f =
|
|
295
|
-
|
|
294
|
+
const f = r.size;
|
|
295
|
+
r.delete(o), f && !r.size && t();
|
|
296
296
|
}
|
|
297
297
|
};
|
|
298
298
|
return {
|
|
299
299
|
on(o, i, s) {
|
|
300
|
-
!
|
|
300
|
+
!r.size && e();
|
|
301
301
|
const u = () => {
|
|
302
302
|
a(o, i, s);
|
|
303
303
|
}, c = (...T) => {
|
|
304
304
|
s && u(), o === "*" ? i({ name: T[0], payload: T[1] }) : i(...T);
|
|
305
305
|
};
|
|
306
306
|
n.on(o, c);
|
|
307
|
-
const p =
|
|
308
|
-
|
|
307
|
+
const p = r.get(o) || /* @__PURE__ */ new Map();
|
|
308
|
+
r.set(o, p);
|
|
309
309
|
const f = p.get(i) || [];
|
|
310
310
|
return p.set(i, f), f.push([c, s || !1]), u;
|
|
311
311
|
},
|
|
@@ -313,22 +313,22 @@ function dr(e, r) {
|
|
|
313
313
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
314
314
|
emit: n.emit,
|
|
315
315
|
clear() {
|
|
316
|
-
const o =
|
|
317
|
-
n.all.clear(),
|
|
316
|
+
const o = r.size;
|
|
317
|
+
n.all.clear(), r.clear(), o && t();
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
|
-
function A(e,
|
|
321
|
+
function A(e, t) {
|
|
322
322
|
window.dispatchEvent(new MessageEvent("message", {
|
|
323
|
-
data: JSON.stringify({ eventType: e, eventData:
|
|
323
|
+
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
324
324
|
// We specify this kind of source here in order to allow the package's "on" function to
|
|
325
325
|
// capture it. The reason is this function always checks the event source and relies on
|
|
326
326
|
// it to be the parent window.
|
|
327
327
|
source: window.parent
|
|
328
328
|
}));
|
|
329
329
|
}
|
|
330
|
-
function $(e,
|
|
331
|
-
const n = [
|
|
330
|
+
function $(e, t, r) {
|
|
331
|
+
const n = [r], a = e[t];
|
|
332
332
|
typeof a == "function" && n.push(a);
|
|
333
333
|
const o = (...s) => {
|
|
334
334
|
n.forEach((u) => u(...s));
|
|
@@ -339,48 +339,48 @@ function $(e, r, t) {
|
|
|
339
339
|
unwrap() {
|
|
340
340
|
const { length: s } = n;
|
|
341
341
|
if (s === 1) {
|
|
342
|
-
delete e[
|
|
342
|
+
delete e[t];
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
345
|
if (s === 2) {
|
|
346
|
-
N(e,
|
|
346
|
+
N(e, t, n[1]);
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
349
|
-
n.unshift(1), N(e,
|
|
349
|
+
n.unshift(1), N(e, t, o);
|
|
350
350
|
}
|
|
351
351
|
});
|
|
352
352
|
we(
|
|
353
353
|
e,
|
|
354
|
-
|
|
354
|
+
t,
|
|
355
355
|
() => i,
|
|
356
356
|
(s) => n.push(s)
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
|
-
function D(e,
|
|
360
|
-
const
|
|
361
|
-
we(e,
|
|
359
|
+
function D(e, t) {
|
|
360
|
+
const r = e[t];
|
|
361
|
+
we(e, t, () => r, (n) => {
|
|
362
362
|
Object.entries(n).forEach(([a, o]) => {
|
|
363
|
-
|
|
363
|
+
r[a] = o;
|
|
364
364
|
});
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
|
-
function we(e,
|
|
368
|
-
Object.defineProperty(e,
|
|
367
|
+
function we(e, t, r, n) {
|
|
368
|
+
Object.defineProperty(e, t, {
|
|
369
369
|
enumerable: !0,
|
|
370
370
|
configurable: !0,
|
|
371
|
-
get:
|
|
371
|
+
get: r,
|
|
372
372
|
set: n
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
|
-
function N(e,
|
|
376
|
-
Object.defineProperty(e,
|
|
375
|
+
function N(e, t, r) {
|
|
376
|
+
Object.defineProperty(e, t, {
|
|
377
377
|
enumerable: !0,
|
|
378
378
|
configurable: !0,
|
|
379
379
|
writable: !0,
|
|
380
|
-
value:
|
|
380
|
+
value: r
|
|
381
381
|
});
|
|
382
382
|
}
|
|
383
|
-
const
|
|
383
|
+
const vt = {
|
|
384
384
|
clipboard_text_received: l({
|
|
385
385
|
req_id: d(),
|
|
386
386
|
data: h(d())
|
|
@@ -417,36 +417,36 @@ const vr = {
|
|
|
417
417
|
function B(e) {
|
|
418
418
|
if (e.source !== window.parent)
|
|
419
419
|
return;
|
|
420
|
-
let
|
|
420
|
+
let t;
|
|
421
421
|
try {
|
|
422
|
-
|
|
422
|
+
t = M(te(re()), e.data);
|
|
423
423
|
} catch {
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
426
|
-
const { eventType:
|
|
426
|
+
const { eventType: r, eventData: n } = t, a = vt[r];
|
|
427
427
|
let o;
|
|
428
428
|
try {
|
|
429
429
|
o = a ? M(a, n) : n;
|
|
430
430
|
} catch (i) {
|
|
431
431
|
return g().forceError(
|
|
432
432
|
[
|
|
433
|
-
`An error occurred processing the "${
|
|
433
|
+
`An error occurred processing the "${r}" event from the Telegram application.`,
|
|
434
434
|
"Please, file an issue here:",
|
|
435
|
-
"https://github.com/Telegram-Mini-Apps/
|
|
435
|
+
"https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"
|
|
436
436
|
].join(`
|
|
437
437
|
`),
|
|
438
|
-
|
|
438
|
+
t,
|
|
439
439
|
i
|
|
440
440
|
);
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
yt(r, o);
|
|
443
443
|
}
|
|
444
444
|
const {
|
|
445
445
|
on: ge,
|
|
446
|
-
off:
|
|
447
|
-
emit:
|
|
448
|
-
clear:
|
|
449
|
-
} =
|
|
446
|
+
off: bt,
|
|
447
|
+
emit: yt,
|
|
448
|
+
clear: Et
|
|
449
|
+
} = dt(
|
|
450
450
|
() => {
|
|
451
451
|
const e = window;
|
|
452
452
|
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), $(e.TelegramGameProxy, "receiveEvent", A), D(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), $(e.Telegram.WebView, "receiveEvent", A), D(e.Telegram, "WebView"), $(e, "TelegramGameProxy_receiveEvent", A), window.addEventListener("message", B);
|
|
@@ -457,23 +457,23 @@ const {
|
|
|
457
457
|
["TelegramGameProxy", "receiveEvent"],
|
|
458
458
|
["Telegram", "WebView", "receiveEvent"]
|
|
459
459
|
].forEach((e) => {
|
|
460
|
-
const
|
|
461
|
-
let
|
|
460
|
+
const t = window;
|
|
461
|
+
let r = [void 0, t];
|
|
462
462
|
for (const o of e)
|
|
463
|
-
if (
|
|
463
|
+
if (r = [r[1], r[1][o]], !r[1])
|
|
464
464
|
return;
|
|
465
|
-
const [n, a] =
|
|
466
|
-
"unwrap" in a && (a.unwrap(), n && n !==
|
|
465
|
+
const [n, a] = r;
|
|
466
|
+
"unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
|
|
467
467
|
}), window.removeEventListener("message", B);
|
|
468
468
|
}
|
|
469
|
-
), P = k(!1), O = k("https://web.telegram.org"),
|
|
469
|
+
), P = k(!1), O = k("https://web.telegram.org"), Pt = (e) => {
|
|
470
470
|
g().log("Event received:", e);
|
|
471
471
|
}, he = ne(P);
|
|
472
|
-
function
|
|
473
|
-
e !== P() && (P.set(e), (e ? ge :
|
|
472
|
+
function Vt(e) {
|
|
473
|
+
e !== P() && (P.set(e), (e ? ge : bt)("*", Pt));
|
|
474
474
|
}
|
|
475
475
|
const de = ne(O);
|
|
476
|
-
function
|
|
476
|
+
function Dt(e) {
|
|
477
477
|
O.set(e), g().log("New target origin set", e);
|
|
478
478
|
}
|
|
479
479
|
const v = k((...e) => {
|
|
@@ -483,55 +483,55 @@ const v = k((...e) => {
|
|
|
483
483
|
textColor: "white",
|
|
484
484
|
shouldLog: he
|
|
485
485
|
}));
|
|
486
|
-
function
|
|
487
|
-
|
|
486
|
+
function Nt() {
|
|
487
|
+
Et(), [v, O, de, P, he, g].forEach((e) => {
|
|
488
488
|
e.unsubAll(), "reset" in e && e.reset();
|
|
489
489
|
});
|
|
490
490
|
}
|
|
491
|
-
const
|
|
492
|
-
function
|
|
491
|
+
const xt = (...e) => v()(...e);
|
|
492
|
+
function kt(e, t) {
|
|
493
493
|
m(
|
|
494
494
|
R(
|
|
495
495
|
// @ts-expect-error It's ok, TS can't determine a specific override.
|
|
496
496
|
e,
|
|
497
|
-
|
|
497
|
+
t
|
|
498
498
|
),
|
|
499
|
-
ze((
|
|
500
|
-
throw
|
|
499
|
+
ze((r) => {
|
|
500
|
+
throw r;
|
|
501
501
|
})
|
|
502
502
|
);
|
|
503
503
|
}
|
|
504
|
-
function R(e,
|
|
505
|
-
g().log("Posting event:",
|
|
506
|
-
const
|
|
507
|
-
return ae() ? (
|
|
504
|
+
function R(e, t) {
|
|
505
|
+
g().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
|
|
506
|
+
const r = window, n = JSON.stringify({ eventType: e, eventData: t });
|
|
507
|
+
return ae() ? (xt(n, de()), _(void 0)) : oe(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), _(void 0)) : L(l({ external: l({ notify: Y() }) }), r) ? (r.external.notify(n), _(void 0)) : w(new mt());
|
|
508
508
|
}
|
|
509
|
-
function U(e,
|
|
509
|
+
function U(e, t, r = {}) {
|
|
510
510
|
const {
|
|
511
511
|
// If no capture function was passed, we capture the first compatible event.
|
|
512
512
|
capture: n = () => !0,
|
|
513
513
|
postEvent: a = R
|
|
514
|
-
} =
|
|
514
|
+
} = r;
|
|
515
515
|
return m(
|
|
516
|
-
async () => a(e,
|
|
517
|
-
|
|
516
|
+
async () => a(e, r.params),
|
|
517
|
+
ct(() => ke((o, i, s) => {
|
|
518
518
|
const [u, c] = Se();
|
|
519
|
-
(Array.isArray(
|
|
519
|
+
(Array.isArray(t) ? t : [t]).forEach((p) => {
|
|
520
520
|
u(
|
|
521
521
|
ge(p, (f) => {
|
|
522
|
-
(Array.isArray(
|
|
522
|
+
(Array.isArray(t) ? n({ event: p, payload: f }) : n(f)) && o(f);
|
|
523
523
|
})
|
|
524
524
|
);
|
|
525
525
|
}), s.on("finalized", c);
|
|
526
|
-
},
|
|
526
|
+
}, r))
|
|
527
527
|
);
|
|
528
528
|
}
|
|
529
|
-
function
|
|
530
|
-
const { postEvent: n } =
|
|
529
|
+
function Bt(e, t, r) {
|
|
530
|
+
const { postEvent: n } = r || {};
|
|
531
531
|
return C(
|
|
532
532
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
533
|
-
U(e,
|
|
534
|
-
...
|
|
533
|
+
U(e, t, {
|
|
534
|
+
...r,
|
|
535
535
|
postEvent: n ? (...a) => {
|
|
536
536
|
try {
|
|
537
537
|
return n(...a), _(void 0);
|
|
@@ -542,30 +542,30 @@ function Br(e, r, t) {
|
|
|
542
542
|
})
|
|
543
543
|
);
|
|
544
544
|
}
|
|
545
|
-
function
|
|
546
|
-
const
|
|
545
|
+
function Jt(e, t) {
|
|
546
|
+
const r = St(
|
|
547
547
|
// @ts-expect-error TS doesn't get what override we are going to use.
|
|
548
548
|
e,
|
|
549
|
-
|
|
549
|
+
t
|
|
550
550
|
);
|
|
551
|
-
return typeof
|
|
551
|
+
return typeof r == "function" ? Z.fn(() => C(r)) : r;
|
|
552
552
|
}
|
|
553
|
-
function
|
|
554
|
-
const
|
|
553
|
+
function St(e, t) {
|
|
554
|
+
const r = oe(window);
|
|
555
555
|
if (!e)
|
|
556
|
-
return
|
|
557
|
-
if (
|
|
556
|
+
return r || m(S(), F(() => !1, () => !0));
|
|
557
|
+
if (r)
|
|
558
558
|
return fe(!0);
|
|
559
|
-
const { timeout: n = 100 } =
|
|
559
|
+
const { timeout: n = 100 } = t || {};
|
|
560
560
|
return m(
|
|
561
|
-
U("web_app_request_theme", "theme_changed", { ...
|
|
561
|
+
U("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
|
|
562
562
|
le(
|
|
563
563
|
(a) => Te.is(a) ? _(!1) : w(a),
|
|
564
564
|
() => _(!0)
|
|
565
565
|
)
|
|
566
566
|
);
|
|
567
567
|
}
|
|
568
|
-
function
|
|
568
|
+
function Qt({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
569
569
|
if (e) {
|
|
570
570
|
const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
|
|
571
571
|
// Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
|
|
@@ -576,22 +576,22 @@ function Qr({ launchParams: e, onEvent: r, resetPostMessage: t } = {}) {
|
|
|
576
576
|
try {
|
|
577
577
|
Me(o);
|
|
578
578
|
} catch (i) {
|
|
579
|
-
throw new
|
|
579
|
+
throw new lt(o, i);
|
|
580
580
|
}
|
|
581
581
|
X("launchParams", o);
|
|
582
582
|
}
|
|
583
583
|
if (ae()) {
|
|
584
|
-
if (!
|
|
584
|
+
if (!t)
|
|
585
585
|
return;
|
|
586
|
-
|
|
586
|
+
r && v.reset();
|
|
587
587
|
const o = v();
|
|
588
588
|
v.set((...i) => {
|
|
589
589
|
const [s] = i, u = () => {
|
|
590
590
|
o(...i);
|
|
591
591
|
};
|
|
592
592
|
try {
|
|
593
|
-
const c = M(re(
|
|
594
|
-
|
|
593
|
+
const c = M(te(re()), s);
|
|
594
|
+
t([c.eventType, c.eventData], u);
|
|
595
595
|
} catch {
|
|
596
596
|
u();
|
|
597
597
|
}
|
|
@@ -606,20 +606,20 @@ function Qr({ launchParams: e, onEvent: r, resetPostMessage: t } = {}) {
|
|
|
606
606
|
const s = () => {
|
|
607
607
|
a(o, i);
|
|
608
608
|
};
|
|
609
|
-
|
|
609
|
+
t ? t([o, i ? JSON.parse(i) : void 0], s) : s();
|
|
610
610
|
}
|
|
611
611
|
}, g().log("Environment was mocked by the mockTelegramEnv function");
|
|
612
612
|
}
|
|
613
|
-
function
|
|
614
|
-
return ({ req_id:
|
|
613
|
+
function Tt(e) {
|
|
614
|
+
return ({ req_id: t }) => t === e;
|
|
615
615
|
}
|
|
616
616
|
function J(e) {
|
|
617
617
|
return e.split(".").map(Number);
|
|
618
618
|
}
|
|
619
|
-
function
|
|
620
|
-
const
|
|
619
|
+
function At(e, t) {
|
|
620
|
+
const r = J(e), n = J(t), a = Math.max(r.length, n.length);
|
|
621
621
|
for (let o = 0; o < a; o += 1) {
|
|
622
|
-
const i =
|
|
622
|
+
const i = r[o] || 0, s = n[o] || 0;
|
|
623
623
|
if (i !== s)
|
|
624
624
|
return i > s ? 1 : -1;
|
|
625
625
|
}
|
|
@@ -713,39 +713,39 @@ const Q = {
|
|
|
713
713
|
],
|
|
714
714
|
9.1: ["web_app_hide_keyboard"]
|
|
715
715
|
};
|
|
716
|
-
function H(e,
|
|
717
|
-
return Object.keys(Q).find((n) => Q[n].some((a) =>
|
|
716
|
+
function H(e, t) {
|
|
717
|
+
return Object.keys(Q).find((n) => Q[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
|
|
718
718
|
}
|
|
719
|
-
function K(e,
|
|
720
|
-
const n =
|
|
719
|
+
function K(e, t, r) {
|
|
720
|
+
const n = r ? H(
|
|
721
721
|
e,
|
|
722
|
-
|
|
722
|
+
t
|
|
723
723
|
) : H(e);
|
|
724
|
-
return n ?
|
|
724
|
+
return n ? At(n, r || t) <= 0 : !1;
|
|
725
725
|
}
|
|
726
|
-
function
|
|
727
|
-
const
|
|
728
|
-
const { method: a, version: o } = n, i = "param" in n ? new
|
|
729
|
-
if (
|
|
726
|
+
function Ht(e, t = "strict") {
|
|
727
|
+
const r = typeof t == "function" ? t : (n) => {
|
|
728
|
+
const { method: a, version: o } = n, i = "param" in n ? new _t(a, n.param, o) : new pt(a, o);
|
|
729
|
+
if (t === "strict")
|
|
730
730
|
throw i;
|
|
731
731
|
return g().forceWarn(i.message);
|
|
732
732
|
};
|
|
733
|
-
return (n, a) => K(n, e) ? n === "web_app_set_header_color" && L(l({ color: Ee() }), a) && !K(n, "color", e) ?
|
|
733
|
+
return (n, a) => K(n, e) ? n === "web_app_set_header_color" && L(l({ color: Ee() }), a) && !K(n, "color", e) ? r({ version: e, method: n, param: "color" }) : kt(n, a) : r({ version: e, method: n });
|
|
734
734
|
}
|
|
735
|
-
function $
|
|
735
|
+
function $t(e, t, r, n) {
|
|
736
736
|
return m(
|
|
737
737
|
U("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
738
738
|
...n || {},
|
|
739
|
-
params: { method: e, params:
|
|
740
|
-
capture:
|
|
739
|
+
params: { method: e, params: t, req_id: r },
|
|
740
|
+
capture: Tt(r)
|
|
741
741
|
}),
|
|
742
|
-
|
|
742
|
+
ut(({ result: a, error: o }) => o ? st(new wt(o)) : fe(a))
|
|
743
743
|
);
|
|
744
744
|
}
|
|
745
|
-
function
|
|
745
|
+
function Kt(e, t, r, n) {
|
|
746
746
|
return Z.fn(() => m(
|
|
747
747
|
// @ts-expect-error TypeScript is unable to determine required override.
|
|
748
|
-
$
|
|
748
|
+
$t(e, t, r, n),
|
|
749
749
|
le(
|
|
750
750
|
(a) => {
|
|
751
751
|
throw a;
|
|
@@ -754,102 +754,102 @@ function Kr(e, r, t, n) {
|
|
|
754
754
|
)
|
|
755
755
|
)());
|
|
756
756
|
}
|
|
757
|
-
function
|
|
758
|
-
Object.hasOwn || (Object.hasOwn = function(e,
|
|
759
|
-
return Object.prototype.hasOwnProperty.call(e,
|
|
757
|
+
function Yt() {
|
|
758
|
+
Object.hasOwn || (Object.hasOwn = function(e, t) {
|
|
759
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
760
760
|
});
|
|
761
761
|
}
|
|
762
762
|
function ve(e) {
|
|
763
763
|
return q(() => decodeURIComponent(
|
|
764
|
-
atob(e).replace(/-/g, "+").replace(/_/g, "/").split("").map((
|
|
765
|
-
), (
|
|
764
|
+
atob(e).replace(/-/g, "+").replace(/_/g, "/").split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
765
|
+
), (t) => t);
|
|
766
766
|
}
|
|
767
|
-
const
|
|
767
|
+
const Xt = x(ve);
|
|
768
768
|
function be(e) {
|
|
769
769
|
return btoa(
|
|
770
|
-
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (
|
|
770
|
+
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
|
|
771
771
|
).replace(/\+/g, "-").replace(/\//g, "_");
|
|
772
772
|
}
|
|
773
|
-
var
|
|
773
|
+
var Mt = function(e) {
|
|
774
774
|
return q(function() {
|
|
775
775
|
return JSON.parse(e);
|
|
776
776
|
}, Fe);
|
|
777
777
|
};
|
|
778
|
-
function
|
|
779
|
-
const
|
|
780
|
-
return
|
|
778
|
+
function Lt(e) {
|
|
779
|
+
const t = be(typeof e == "string" ? e : JSON.stringify(e));
|
|
780
|
+
return t.length > 512 ? w(new Error("Value is too long for start parameter")) : _(t);
|
|
781
781
|
}
|
|
782
|
-
const
|
|
783
|
-
function
|
|
782
|
+
const Zt = x(Lt);
|
|
783
|
+
function er(e, t) {
|
|
784
784
|
return C(
|
|
785
|
-
|
|
785
|
+
Ct(
|
|
786
786
|
e,
|
|
787
787
|
// @ts-expect-error TypeScript is unable to detect a correct override.
|
|
788
|
-
typeof
|
|
788
|
+
typeof t == "function" ? (r) => q(() => t(r), (n) => n) : t
|
|
789
789
|
)
|
|
790
790
|
);
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function Ct(e, t) {
|
|
793
793
|
return m(
|
|
794
794
|
ve(e),
|
|
795
|
-
Ne((
|
|
795
|
+
Ne((r) => t ? typeof t == "function" ? t(r) : Mt(r) : _(r))
|
|
796
796
|
);
|
|
797
797
|
}
|
|
798
|
-
function
|
|
798
|
+
function tr(e) {
|
|
799
799
|
return be(e).length <= 512;
|
|
800
800
|
}
|
|
801
801
|
export {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
802
|
+
sr as CancelledError,
|
|
803
|
+
lt as InvalidLaunchParamsError,
|
|
804
|
+
wt as InvokeCustomMethodFailedError,
|
|
805
|
+
ft as LaunchParamsRetrieveError,
|
|
806
|
+
_t as MethodParameterUnsupportedError,
|
|
807
|
+
pt as MethodUnsupportedError,
|
|
808
|
+
ur as TimeoutError,
|
|
809
|
+
mt as UnknownEnvError,
|
|
810
|
+
Yt as applyPolyfills,
|
|
811
|
+
Tt as captureSameReq,
|
|
812
|
+
At as compareVersions,
|
|
813
|
+
or as createLogger,
|
|
814
|
+
Ht as createPostEvent,
|
|
815
|
+
Zt as createStartParam,
|
|
816
|
+
Lt as createStartParamFp,
|
|
817
817
|
he as debug,
|
|
818
|
-
|
|
818
|
+
Xt as decodeBase64Url,
|
|
819
819
|
ve as decodeBase64UrlFp,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
820
|
+
er as decodeStartParam,
|
|
821
|
+
Ct as decodeStartParamFp,
|
|
822
|
+
ar as deepSnakeToCamelObjKeys,
|
|
823
823
|
A as emitEvent,
|
|
824
824
|
be as encodeBase64Url,
|
|
825
825
|
H as getReleaseVersion,
|
|
826
826
|
oe as hasWebviewProxy,
|
|
827
|
-
|
|
828
|
-
$
|
|
827
|
+
Kt as invokeCustomMethod,
|
|
828
|
+
$t as invokeCustomMethodFp,
|
|
829
829
|
ae as isIframe,
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
830
|
+
tr as isSafeToCreateStartParam,
|
|
831
|
+
Jt as isTMA,
|
|
832
|
+
St as isTMAFp,
|
|
833
833
|
g as logger,
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
834
|
+
Qt as mockTelegramEnv,
|
|
835
|
+
bt as off,
|
|
836
|
+
Et as offAll,
|
|
837
837
|
ge as on,
|
|
838
|
-
|
|
838
|
+
kt as postEvent,
|
|
839
839
|
R as postEventFp,
|
|
840
|
-
|
|
840
|
+
xt as postMessage,
|
|
841
841
|
v as postMessageImpl,
|
|
842
|
-
|
|
842
|
+
Bt as request,
|
|
843
843
|
U as requestFp,
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
844
|
+
Nt as resetGlobals,
|
|
845
|
+
jt as retrieveLaunchParams,
|
|
846
|
+
gt as retrieveLaunchParamsFp,
|
|
847
|
+
zt as retrieveRawInitData,
|
|
848
|
+
ht as retrieveRawInitDataFp,
|
|
849
|
+
Gt as retrieveRawLaunchParams,
|
|
850
850
|
S as retrieveRawLaunchParamsFp,
|
|
851
|
-
|
|
852
|
-
|
|
851
|
+
Vt as setDebug,
|
|
852
|
+
Dt as setTargetOrigin,
|
|
853
853
|
K as supports,
|
|
854
854
|
de as targetOrigin
|
|
855
855
|
};
|