@tma.js/sdk 1.4.9 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/bridge/captureSameReq.d.ts +10 -0
- package/dist/dts/bridge/events/on.d.ts +1 -4
- package/dist/dts/bridge/events/once.d.ts +2 -3
- package/dist/dts/bridge/events/subscribe.d.ts +2 -3
- package/dist/dts/bridge/events/types.d.ts +4 -0
- package/dist/dts/bridge/methods/methods.d.ts +5 -7
- package/dist/dts/bridge/request.d.ts +36 -40
- package/dist/dts/components/theme-params/ThemeParams.d.ts +1 -1
- package/dist/dts/components/theme-params/requestThemeParams.d.ts +2 -2
- package/dist/dts/components/viewport/Viewport.d.ts +3 -3
- package/dist/dts/components/viewport/requestViewport.d.ts +2 -2
- package/dist/dts/index.d.ts +3 -1
- package/dist/dts/timeout/withTimeout.d.ts +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.mjs +454 -442
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Re = Object.defineProperty;
|
|
2
2
|
var Ie = (r, e, t) => e in r ? Re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
3
|
var o = (r, e, t) => (Ie(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
class
|
|
4
|
+
class he {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
this.prefix = e, this.enabled = t;
|
|
7
7
|
}
|
|
@@ -56,53 +56,53 @@ class ue {
|
|
|
56
56
|
this.print("warn", ...e);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
let
|
|
60
|
-
const
|
|
61
|
-
function
|
|
59
|
+
let ue = "https://web.telegram.org";
|
|
60
|
+
const k = new he("[SDK]", !1);
|
|
61
|
+
function Qt(r) {
|
|
62
62
|
if (r) {
|
|
63
|
-
|
|
63
|
+
k.enable();
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
k.disable();
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
68
|
+
function Zt(r) {
|
|
69
|
+
ue = r;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
71
|
+
function Te() {
|
|
72
|
+
return ue;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function pe() {
|
|
75
75
|
try {
|
|
76
76
|
return window.self !== window.top;
|
|
77
77
|
} catch {
|
|
78
78
|
return !0;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function M(r) {
|
|
82
82
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
83
83
|
}
|
|
84
|
-
function Te(r) {
|
|
85
|
-
return "external" in r && R(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
86
|
-
}
|
|
87
84
|
function $e(r) {
|
|
88
|
-
return "
|
|
85
|
+
return "external" in r && M(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
86
|
+
}
|
|
87
|
+
function Le(r) {
|
|
88
|
+
return "TelegramWebviewProxy" in r && M(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
|
|
89
89
|
}
|
|
90
90
|
function d(r, e, t) {
|
|
91
91
|
let s = {}, n;
|
|
92
92
|
e === void 0 && t === void 0 ? s = {} : e !== void 0 && t !== void 0 ? (s = t, n = e) : e !== void 0 && ("targetOrigin" in e ? s = e : n = e);
|
|
93
|
-
const { targetOrigin: i =
|
|
94
|
-
if (
|
|
93
|
+
const { targetOrigin: i = Te() } = s;
|
|
94
|
+
if (k.log(`Calling method "${r}"`, n), pe()) {
|
|
95
95
|
window.parent.postMessage(JSON.stringify({
|
|
96
96
|
eventType: r,
|
|
97
97
|
eventData: n
|
|
98
98
|
}), i);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
101
|
+
if ($e(window)) {
|
|
102
102
|
window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
105
|
+
if (Le(window)) {
|
|
106
106
|
window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
@@ -119,15 +119,15 @@ function Be(r, e) {
|
|
|
119
119
|
}
|
|
120
120
|
return 0;
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function v(r, e) {
|
|
123
123
|
return Be(r, e) <= 0;
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function A(r, e, t) {
|
|
126
126
|
if (typeof t == "string") {
|
|
127
127
|
if (r === "web_app_open_link" && e === "try_instant_view")
|
|
128
|
-
return
|
|
128
|
+
return v("6.4", t);
|
|
129
129
|
if (r === "web_app_set_header_color" && e === "color")
|
|
130
|
-
return
|
|
130
|
+
return v("6.9", t);
|
|
131
131
|
}
|
|
132
132
|
switch (r) {
|
|
133
133
|
case "web_app_open_tg_link":
|
|
@@ -136,60 +136,63 @@ function I(r, e, t) {
|
|
|
136
136
|
case "web_app_set_background_color":
|
|
137
137
|
case "web_app_set_header_color":
|
|
138
138
|
case "web_app_trigger_haptic_feedback":
|
|
139
|
-
return
|
|
139
|
+
return v("6.1", e);
|
|
140
140
|
case "web_app_open_popup":
|
|
141
|
-
return
|
|
141
|
+
return v("6.2", e);
|
|
142
142
|
case "web_app_close_scan_qr_popup":
|
|
143
143
|
case "web_app_open_scan_qr_popup":
|
|
144
144
|
case "web_app_read_text_from_clipboard":
|
|
145
|
-
return
|
|
145
|
+
return v("6.4", e);
|
|
146
146
|
case "web_app_switch_inline_query":
|
|
147
|
-
return
|
|
147
|
+
return v("6.7", e);
|
|
148
148
|
case "web_app_invoke_custom_method":
|
|
149
149
|
case "web_app_request_write_access":
|
|
150
150
|
case "web_app_request_phone":
|
|
151
|
-
return
|
|
151
|
+
return v("6.9", e);
|
|
152
152
|
case "web_app_setup_settings_button":
|
|
153
|
-
return
|
|
153
|
+
return v("6.10", e);
|
|
154
154
|
default:
|
|
155
155
|
return !0;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
class
|
|
158
|
+
class Z extends Error {
|
|
159
159
|
constructor(e, t) {
|
|
160
|
-
super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`), Object.setPrototypeOf(this,
|
|
160
|
+
super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`), Object.setPrototypeOf(this, Z.prototype);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
class
|
|
163
|
+
class K extends Error {
|
|
164
164
|
constructor(e, t, s) {
|
|
165
|
-
super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this,
|
|
165
|
+
super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, K.prototype);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function Oe(r) {
|
|
169
169
|
return (e, t) => {
|
|
170
|
-
if (!
|
|
171
|
-
throw new
|
|
172
|
-
if (
|
|
170
|
+
if (!A(e, r))
|
|
171
|
+
throw new Z(e, r);
|
|
172
|
+
if (M(t)) {
|
|
173
173
|
let s;
|
|
174
|
-
if (e === "web_app_open_link" && "try_instant_view" in t ? s = "try_instant_view" : e === "web_app_set_header_color" && "color" in t && (s = "color"), s && !
|
|
175
|
-
throw new
|
|
174
|
+
if (e === "web_app_open_link" && "try_instant_view" in t ? s = "try_instant_view" : e === "web_app_set_header_color" && "color" in t && (s = "color"), s && !A(e, s, r))
|
|
175
|
+
throw new K(e, s, r);
|
|
176
176
|
}
|
|
177
177
|
return d(e, t);
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
function le(r) {
|
|
181
|
+
return ({ req_id: e }) => e === r;
|
|
182
|
+
}
|
|
183
|
+
class G extends Error {
|
|
181
184
|
constructor(t, { cause: s, type: n } = {}) {
|
|
182
185
|
super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
|
|
183
186
|
/**
|
|
184
187
|
* Parser name.
|
|
185
188
|
*/
|
|
186
189
|
o(this, "type");
|
|
187
|
-
this.value = t, Object.setPrototypeOf(this,
|
|
190
|
+
this.value = t, Object.setPrototypeOf(this, G.prototype), this.type = n;
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
|
-
class
|
|
193
|
+
class U extends Error {
|
|
191
194
|
constructor(e, { cause: t, type: s } = {}) {
|
|
192
|
-
super(`Unable to parse field "${e}"${s ? ` as ${s}` : ""}`, { cause: t }), Object.setPrototypeOf(this,
|
|
195
|
+
super(`Unable to parse field "${e}"${s ? ` as ${s}` : ""}`, { cause: t }), Object.setPrototypeOf(this, U.prototype);
|
|
193
196
|
}
|
|
194
197
|
}
|
|
195
198
|
function de(r, e) {
|
|
@@ -210,25 +213,25 @@ function de(r, e) {
|
|
|
210
213
|
try {
|
|
211
214
|
c = a(u);
|
|
212
215
|
} catch (p) {
|
|
213
|
-
throw p instanceof
|
|
216
|
+
throw p instanceof G ? new U(i, {
|
|
214
217
|
type: p.type,
|
|
215
218
|
cause: p
|
|
216
|
-
}) : new
|
|
219
|
+
}) : new U(i, { cause: p });
|
|
217
220
|
}
|
|
218
221
|
c !== void 0 && (t[s] = c);
|
|
219
222
|
}
|
|
220
223
|
return t;
|
|
221
224
|
}
|
|
222
|
-
function
|
|
225
|
+
function V() {
|
|
223
226
|
return new TypeError("Value has unexpected type");
|
|
224
227
|
}
|
|
225
|
-
function
|
|
228
|
+
function Y(r) {
|
|
226
229
|
let e = r;
|
|
227
230
|
if (typeof e == "string" && (e = JSON.parse(e)), typeof e != "object" || e === null || Array.isArray(e))
|
|
228
|
-
throw
|
|
231
|
+
throw V();
|
|
229
232
|
return e;
|
|
230
233
|
}
|
|
231
|
-
class
|
|
234
|
+
class j {
|
|
232
235
|
constructor(e, t, s) {
|
|
233
236
|
this.parser = e, this.isOptional = t, this.type = s;
|
|
234
237
|
}
|
|
@@ -237,7 +240,7 @@ class z {
|
|
|
237
240
|
try {
|
|
238
241
|
return this.parser(e);
|
|
239
242
|
} catch (t) {
|
|
240
|
-
throw new
|
|
243
|
+
throw new G(e, { type: this.type, cause: t });
|
|
241
244
|
}
|
|
242
245
|
}
|
|
243
246
|
optional() {
|
|
@@ -245,33 +248,33 @@ class z {
|
|
|
245
248
|
}
|
|
246
249
|
}
|
|
247
250
|
function f(r, e) {
|
|
248
|
-
return new
|
|
249
|
-
const s =
|
|
251
|
+
return new j((t) => {
|
|
252
|
+
const s = Y(t);
|
|
250
253
|
return de(r, (n) => s[n]);
|
|
251
254
|
}, !1, e);
|
|
252
255
|
}
|
|
253
|
-
function
|
|
254
|
-
return () => new
|
|
256
|
+
function R(r, e) {
|
|
257
|
+
return () => new j(r, !1, e);
|
|
255
258
|
}
|
|
256
|
-
const h =
|
|
259
|
+
const h = R((r) => {
|
|
257
260
|
if (typeof r == "string" || typeof r == "number")
|
|
258
261
|
return r.toString();
|
|
259
|
-
throw
|
|
260
|
-
}, "string")
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
throw V();
|
|
263
|
+
}, "string");
|
|
264
|
+
function De(r) {
|
|
265
|
+
return f({
|
|
266
|
+
eventType: h(),
|
|
267
|
+
eventData: (e) => e
|
|
268
|
+
}).parse(r);
|
|
266
269
|
}
|
|
267
|
-
function
|
|
270
|
+
function We(r, e) {
|
|
268
271
|
window.dispatchEvent(new MessageEvent("message", {
|
|
269
272
|
data: JSON.stringify({ eventType: r, eventData: e }),
|
|
270
273
|
// We specify window.parent to imitate the case, it sent us this event.
|
|
271
274
|
source: window.parent
|
|
272
275
|
}));
|
|
273
276
|
}
|
|
274
|
-
function
|
|
277
|
+
function He() {
|
|
275
278
|
const r = window;
|
|
276
279
|
"TelegramGameProxy_receiveEvent" in r || [
|
|
277
280
|
["TelegramGameProxy_receiveEvent"],
|
|
@@ -284,66 +287,66 @@ function Ne() {
|
|
|
284
287
|
let t = r;
|
|
285
288
|
e.forEach((s, n, i) => {
|
|
286
289
|
if (n === i.length - 1) {
|
|
287
|
-
t[s] =
|
|
290
|
+
t[s] = We;
|
|
288
291
|
return;
|
|
289
292
|
}
|
|
290
293
|
s in t || (t[s] = {}), t = t[s];
|
|
291
294
|
});
|
|
292
295
|
});
|
|
293
296
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
297
|
+
function Ne(r) {
|
|
298
|
+
He(), window.addEventListener("message", (e) => {
|
|
296
299
|
if (e.source === window.parent)
|
|
297
300
|
try {
|
|
298
|
-
const { eventType: t, eventData: s } =
|
|
301
|
+
const { eventType: t, eventData: s } = De(e.data);
|
|
299
302
|
r(t, s);
|
|
300
303
|
} catch {
|
|
301
304
|
}
|
|
302
305
|
});
|
|
303
306
|
}
|
|
304
|
-
function
|
|
307
|
+
function Ue() {
|
|
305
308
|
return f({
|
|
306
309
|
req_id: h(),
|
|
307
310
|
data: (r) => r === null ? r : h().optional().parse(r)
|
|
308
311
|
});
|
|
309
312
|
}
|
|
310
|
-
function
|
|
313
|
+
function Me() {
|
|
311
314
|
return f({
|
|
312
315
|
req_id: h(),
|
|
313
316
|
result: (r) => r,
|
|
314
317
|
error: h().optional()
|
|
315
318
|
});
|
|
316
319
|
}
|
|
317
|
-
function
|
|
320
|
+
function Ge() {
|
|
318
321
|
return f({
|
|
319
322
|
slug: h(),
|
|
320
323
|
status: h()
|
|
321
324
|
});
|
|
322
325
|
}
|
|
323
|
-
function
|
|
326
|
+
function je() {
|
|
324
327
|
return f({ status: h() });
|
|
325
328
|
}
|
|
326
|
-
function
|
|
329
|
+
function Fe() {
|
|
327
330
|
return f({
|
|
328
331
|
button_id: (r) => r == null ? void 0 : h().parse(r)
|
|
329
332
|
});
|
|
330
333
|
}
|
|
331
|
-
function
|
|
334
|
+
function ze() {
|
|
332
335
|
return f({
|
|
333
336
|
data: h().optional()
|
|
334
337
|
});
|
|
335
338
|
}
|
|
336
|
-
function
|
|
339
|
+
function X(r) {
|
|
337
340
|
return /^#[\da-f]{6}$/i.test(r);
|
|
338
341
|
}
|
|
339
|
-
function
|
|
342
|
+
function Je(r) {
|
|
340
343
|
return /^#[\da-f]{3}$/i.test(r);
|
|
341
344
|
}
|
|
342
345
|
function fe(r) {
|
|
343
346
|
const e = r.replace(/\s/g, "").toLowerCase();
|
|
344
|
-
if (
|
|
347
|
+
if (X(e))
|
|
345
348
|
return e;
|
|
346
|
-
if (
|
|
349
|
+
if (Je(e)) {
|
|
347
350
|
let s = "#";
|
|
348
351
|
for (let n = 0; n < 3; n += 1)
|
|
349
352
|
s += e[1 + n].repeat(2);
|
|
@@ -357,16 +360,16 @@ function fe(r) {
|
|
|
357
360
|
return s + (i.length === 1 ? "0" : "") + i;
|
|
358
361
|
}, "#");
|
|
359
362
|
}
|
|
360
|
-
const ge =
|
|
361
|
-
function
|
|
363
|
+
const ge = R((r) => fe(h().parse(r)), "rgb");
|
|
364
|
+
function Qe() {
|
|
362
365
|
return f({
|
|
363
366
|
theme_params: (r) => {
|
|
364
367
|
const e = ge().optional();
|
|
365
|
-
return Object.entries(
|
|
368
|
+
return Object.entries(Y(r)).reduce((t, [s, n]) => (t[s] = e.parse(n), t), {});
|
|
366
369
|
}
|
|
367
370
|
});
|
|
368
371
|
}
|
|
369
|
-
const
|
|
372
|
+
const P = R((r) => {
|
|
370
373
|
if (typeof r == "boolean")
|
|
371
374
|
return r;
|
|
372
375
|
const e = String(r);
|
|
@@ -374,8 +377,8 @@ const k = T((r) => {
|
|
|
374
377
|
return !0;
|
|
375
378
|
if (e === "0" || e === "false")
|
|
376
379
|
return !1;
|
|
377
|
-
throw
|
|
378
|
-
}, "boolean"),
|
|
380
|
+
throw V();
|
|
381
|
+
}, "boolean"), x = R((r) => {
|
|
379
382
|
if (typeof r == "number")
|
|
380
383
|
return r;
|
|
381
384
|
if (typeof r == "string") {
|
|
@@ -383,17 +386,17 @@ const k = T((r) => {
|
|
|
383
386
|
if (!Number.isNaN(e))
|
|
384
387
|
return e;
|
|
385
388
|
}
|
|
386
|
-
throw
|
|
389
|
+
throw V();
|
|
387
390
|
}, "number");
|
|
388
|
-
function
|
|
391
|
+
function Ze() {
|
|
389
392
|
return f({
|
|
390
|
-
height:
|
|
391
|
-
width: (r) => r == null ? window.innerWidth :
|
|
392
|
-
is_state_stable:
|
|
393
|
-
is_expanded:
|
|
393
|
+
height: x(),
|
|
394
|
+
width: (r) => r == null ? window.innerWidth : x().parse(r),
|
|
395
|
+
is_state_stable: P(),
|
|
396
|
+
is_expanded: P()
|
|
394
397
|
});
|
|
395
398
|
}
|
|
396
|
-
function
|
|
399
|
+
function Ke() {
|
|
397
400
|
return f({ status: h() });
|
|
398
401
|
}
|
|
399
402
|
class w {
|
|
@@ -478,9 +481,9 @@ class w {
|
|
|
478
481
|
}
|
|
479
482
|
}
|
|
480
483
|
}
|
|
481
|
-
function
|
|
484
|
+
function Ye() {
|
|
482
485
|
const r = new w(), e = (t, ...s) => {
|
|
483
|
-
|
|
486
|
+
k.log("Emitting processed event:", t, ...s), r.emit(t, ...s);
|
|
484
487
|
};
|
|
485
488
|
return window.addEventListener("resize", () => {
|
|
486
489
|
e("viewport_changed", {
|
|
@@ -489,33 +492,33 @@ function Xe() {
|
|
|
489
492
|
is_state_stable: !0,
|
|
490
493
|
is_expanded: !0
|
|
491
494
|
});
|
|
492
|
-
}),
|
|
493
|
-
|
|
495
|
+
}), Ne((t, s) => {
|
|
496
|
+
k.log("Received raw event:", t, s);
|
|
494
497
|
try {
|
|
495
498
|
switch (t) {
|
|
496
499
|
case "viewport_changed":
|
|
497
|
-
return e(t, Ke().parse(s));
|
|
498
|
-
case "theme_changed":
|
|
499
500
|
return e(t, Ze().parse(s));
|
|
501
|
+
case "theme_changed":
|
|
502
|
+
return e(t, Qe().parse(s));
|
|
500
503
|
case "popup_closed":
|
|
501
504
|
return (
|
|
502
505
|
// Sent on desktop.
|
|
503
|
-
s == null ? e(t, {}) : e(t,
|
|
506
|
+
s == null ? e(t, {}) : e(t, Fe().parse(s))
|
|
504
507
|
);
|
|
505
508
|
case "set_custom_style":
|
|
506
509
|
return e(t, h().parse(s));
|
|
507
510
|
case "qr_text_received":
|
|
508
|
-
return e(t,
|
|
511
|
+
return e(t, ze().parse(s));
|
|
509
512
|
case "clipboard_text_received":
|
|
510
|
-
return e(t,
|
|
513
|
+
return e(t, Ue().parse(s));
|
|
511
514
|
case "invoice_closed":
|
|
512
|
-
return e(t,
|
|
515
|
+
return e(t, Ge().parse(s));
|
|
513
516
|
case "phone_requested":
|
|
514
|
-
return e("phone_requested",
|
|
517
|
+
return e("phone_requested", je().parse(s));
|
|
515
518
|
case "custom_method_invoked":
|
|
516
|
-
return e("custom_method_invoked",
|
|
519
|
+
return e("custom_method_invoked", Me().parse(s));
|
|
517
520
|
case "write_access_requested":
|
|
518
|
-
return e("write_access_requested",
|
|
521
|
+
return e("write_access_requested", Ke().parse(s));
|
|
519
522
|
case "main_button_pressed":
|
|
520
523
|
case "back_button_pressed":
|
|
521
524
|
case "settings_button_pressed":
|
|
@@ -526,88 +529,98 @@ function Xe() {
|
|
|
526
529
|
return e(t, s);
|
|
527
530
|
}
|
|
528
531
|
} catch (n) {
|
|
529
|
-
|
|
532
|
+
k.error("Error processing event:", n);
|
|
530
533
|
}
|
|
531
534
|
}), r;
|
|
532
535
|
}
|
|
533
|
-
const
|
|
534
|
-
function
|
|
536
|
+
const z = "telegram-mini-apps-cached-emitter";
|
|
537
|
+
function W() {
|
|
535
538
|
const r = window;
|
|
536
|
-
return r[
|
|
539
|
+
return r[z] === void 0 && (r[z] = Ye()), r[z];
|
|
537
540
|
}
|
|
538
|
-
function
|
|
539
|
-
|
|
541
|
+
function I(r, e) {
|
|
542
|
+
W().off(r, e);
|
|
540
543
|
}
|
|
541
|
-
function
|
|
542
|
-
return
|
|
544
|
+
function E(r, e) {
|
|
545
|
+
return W().on(r, e), () => I(r, e);
|
|
543
546
|
}
|
|
544
|
-
class
|
|
547
|
+
class F extends Error {
|
|
545
548
|
constructor(e) {
|
|
546
|
-
super(`Async call timeout exceeded. Timeout: ${e}`), Object.setPrototypeOf(this,
|
|
549
|
+
super(`Async call timeout exceeded. Timeout: ${e}`), Object.setPrototypeOf(this, F.prototype);
|
|
547
550
|
}
|
|
548
551
|
}
|
|
549
|
-
function
|
|
552
|
+
function Xe(r) {
|
|
550
553
|
return new Promise((e, t) => {
|
|
551
|
-
setTimeout(t, r, new
|
|
554
|
+
setTimeout(t, r, new F(r));
|
|
552
555
|
});
|
|
553
556
|
}
|
|
554
557
|
function we(r, e) {
|
|
555
558
|
return Promise.race([
|
|
556
|
-
r(),
|
|
557
|
-
|
|
559
|
+
typeof r == "function" ? r() : r,
|
|
560
|
+
Xe(e)
|
|
558
561
|
]);
|
|
559
562
|
}
|
|
560
|
-
function
|
|
561
|
-
let
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
563
|
+
async function y(r, e, t) {
|
|
564
|
+
let s;
|
|
565
|
+
const n = new Promise((b) => {
|
|
566
|
+
s = b;
|
|
567
|
+
}), i = e ? {
|
|
568
|
+
...t,
|
|
569
|
+
event: e,
|
|
570
|
+
method: r
|
|
571
|
+
} : r, {
|
|
572
|
+
method: a,
|
|
573
|
+
event: c,
|
|
574
|
+
capture: u,
|
|
575
|
+
postEvent: p = d,
|
|
576
|
+
timeout: g
|
|
577
|
+
} = i, _ = (Array.isArray(c) ? c : [c]).map(
|
|
578
|
+
(b) => E(b, (l) => (!u || u(l)) && s(l))
|
|
579
|
+
);
|
|
580
|
+
try {
|
|
581
|
+
return p(a, i.params), await (g ? we(n, g) : n);
|
|
582
|
+
} finally {
|
|
583
|
+
_.forEach((b) => b());
|
|
584
|
+
}
|
|
574
585
|
}
|
|
575
|
-
async function
|
|
576
|
-
const {
|
|
577
|
-
|
|
578
|
-
|
|
586
|
+
async function O(r, e, t, s = {}) {
|
|
587
|
+
const {
|
|
588
|
+
result: n,
|
|
589
|
+
error: i
|
|
590
|
+
} = await y("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
591
|
+
...s,
|
|
592
|
+
params: {
|
|
579
593
|
method: r,
|
|
580
594
|
params: e,
|
|
581
595
|
req_id: t
|
|
582
596
|
},
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
);
|
|
597
|
+
capture: le(t)
|
|
598
|
+
});
|
|
586
599
|
if (i)
|
|
587
600
|
throw new Error(i);
|
|
588
601
|
return n;
|
|
589
602
|
}
|
|
590
|
-
function
|
|
591
|
-
return
|
|
603
|
+
function Kt(r, e) {
|
|
604
|
+
return W().once(r, e), () => I(r, e);
|
|
592
605
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
606
|
+
function et(r) {
|
|
607
|
+
W().unsubscribe(r);
|
|
595
608
|
}
|
|
596
|
-
function
|
|
597
|
-
return
|
|
609
|
+
function Yt(r) {
|
|
610
|
+
return W().subscribe(r), () => et(r);
|
|
598
611
|
}
|
|
599
|
-
function
|
|
612
|
+
function se(r, e) {
|
|
600
613
|
return r + (r.length > 0 && e.length > 0 ? ` ${e}` : e);
|
|
601
614
|
}
|
|
602
|
-
function
|
|
615
|
+
function tt(...r) {
|
|
603
616
|
return r.reduce((e, t) => {
|
|
604
617
|
let s = "";
|
|
605
|
-
return typeof t == "string" ? s = t : typeof t == "object" && t !== null && (s = Object.entries(t).reduce((n, [i, a]) => a ?
|
|
618
|
+
return typeof t == "string" ? s = t : typeof t == "object" && t !== null && (s = Object.entries(t).reduce((n, [i, a]) => a ? se(n, i) : n, "")), se(e, s);
|
|
606
619
|
}, "");
|
|
607
620
|
}
|
|
608
|
-
function
|
|
609
|
-
return r.reduce((e, t) => (
|
|
610
|
-
const i =
|
|
621
|
+
function Xt(...r) {
|
|
622
|
+
return r.reduce((e, t) => (M(t) && Object.entries(t).forEach(([s, n]) => {
|
|
623
|
+
const i = tt(e[s], n);
|
|
611
624
|
i.length > 0 && (e[s] = i);
|
|
612
625
|
}), e), {});
|
|
613
626
|
}
|
|
@@ -620,7 +633,7 @@ function _e(r) {
|
|
|
620
633
|
}, 0)
|
|
621
634
|
) < 120;
|
|
622
635
|
}
|
|
623
|
-
class
|
|
636
|
+
class m {
|
|
624
637
|
constructor(e, t) {
|
|
625
638
|
this.state = e, this.ee = t;
|
|
626
639
|
}
|
|
@@ -650,6 +663,56 @@ class b {
|
|
|
650
663
|
return this.state[e];
|
|
651
664
|
}
|
|
652
665
|
}
|
|
666
|
+
function C(r, e) {
|
|
667
|
+
return (t) => A(e[t], r);
|
|
668
|
+
}
|
|
669
|
+
class rt {
|
|
670
|
+
constructor(e, t, s = d) {
|
|
671
|
+
o(this, "ee", new w());
|
|
672
|
+
o(this, "state");
|
|
673
|
+
/**
|
|
674
|
+
* Adds event listener.
|
|
675
|
+
* @param event - event name.
|
|
676
|
+
* @param listener - event listener.
|
|
677
|
+
*/
|
|
678
|
+
o(this, "on", (e, t) => e === "click" ? E("back_button_pressed", t) : this.ee.on(e, t));
|
|
679
|
+
/**
|
|
680
|
+
* Removes event listener.
|
|
681
|
+
* @param event - event name.
|
|
682
|
+
* @param listener - event listener.
|
|
683
|
+
*/
|
|
684
|
+
o(this, "off", (e, t) => e === "click" ? I("back_button_pressed", t) : this.ee.off(e, t));
|
|
685
|
+
/**
|
|
686
|
+
* Checks if specified method is supported by current component.
|
|
687
|
+
*/
|
|
688
|
+
o(this, "supports");
|
|
689
|
+
this.postEvent = s, this.state = new m({ isVisible: e }, this.ee), this.supports = C(t, {
|
|
690
|
+
show: "web_app_setup_back_button",
|
|
691
|
+
hide: "web_app_setup_back_button"
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
set isVisible(e) {
|
|
695
|
+
this.state.set("isVisible", e), this.postEvent("web_app_setup_back_button", { is_visible: e });
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* True if BackButton is currently visible.
|
|
699
|
+
*/
|
|
700
|
+
get isVisible() {
|
|
701
|
+
return this.state.get("isVisible");
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Hides the BackButton.
|
|
705
|
+
*/
|
|
706
|
+
hide() {
|
|
707
|
+
this.isVisible = !1;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Shows the BackButton.
|
|
711
|
+
*/
|
|
712
|
+
show() {
|
|
713
|
+
this.isVisible = !0;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
653
716
|
class st {
|
|
654
717
|
constructor(e, t = d) {
|
|
655
718
|
o(this, "ee", new w());
|
|
@@ -662,7 +725,7 @@ class st {
|
|
|
662
725
|
* Removes event listener.
|
|
663
726
|
*/
|
|
664
727
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
665
|
-
this.postEvent = t, this.state = new
|
|
728
|
+
this.postEvent = t, this.state = new m({ isConfirmationNeeded: e }, this.ee);
|
|
666
729
|
}
|
|
667
730
|
set isConfirmationNeeded(e) {
|
|
668
731
|
this.state.set("isConfirmationNeeded", e), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: e });
|
|
@@ -699,9 +762,9 @@ function nt(r) {
|
|
|
699
762
|
return e;
|
|
700
763
|
} catch {
|
|
701
764
|
}
|
|
702
|
-
throw
|
|
765
|
+
throw V();
|
|
703
766
|
}
|
|
704
|
-
class it extends
|
|
767
|
+
class it extends j {
|
|
705
768
|
constructor(t, s, n) {
|
|
706
769
|
super(nt, s, n);
|
|
707
770
|
o(this, "itemParser");
|
|
@@ -718,10 +781,7 @@ class it extends z {
|
|
|
718
781
|
function ot(r) {
|
|
719
782
|
return new it((e) => e, !1, r);
|
|
720
783
|
}
|
|
721
|
-
function
|
|
722
|
-
return (t) => I(e[t], r);
|
|
723
|
-
}
|
|
724
|
-
function ie(r, e) {
|
|
784
|
+
function ne(r, e) {
|
|
725
785
|
return r.reduce((t, s) => (t[s] = e, t), {});
|
|
726
786
|
}
|
|
727
787
|
class at {
|
|
@@ -730,7 +790,7 @@ class at {
|
|
|
730
790
|
* Checks if specified method is supported by current component.
|
|
731
791
|
*/
|
|
732
792
|
o(this, "supports");
|
|
733
|
-
this.createRequestId = t, this.postEvent = s, this.supports =
|
|
793
|
+
this.createRequestId = t, this.postEvent = s, this.supports = C(e, {
|
|
734
794
|
delete: "web_app_invoke_custom_method",
|
|
735
795
|
get: "web_app_invoke_custom_method",
|
|
736
796
|
getKeys: "web_app_invoke_custom_method",
|
|
@@ -744,7 +804,7 @@ class at {
|
|
|
744
804
|
*/
|
|
745
805
|
async delete(e, t = {}) {
|
|
746
806
|
const s = Array.isArray(e) ? e : [e];
|
|
747
|
-
s.length !== 0 && await
|
|
807
|
+
s.length !== 0 && await O(
|
|
748
808
|
"deleteStorageValues",
|
|
749
809
|
{ keys: s },
|
|
750
810
|
this.createRequestId(),
|
|
@@ -756,7 +816,7 @@ class at {
|
|
|
756
816
|
* @param options - request execution options.
|
|
757
817
|
*/
|
|
758
818
|
async getKeys(e = {}) {
|
|
759
|
-
const t = await
|
|
819
|
+
const t = await O(
|
|
760
820
|
"getStorageKeys",
|
|
761
821
|
{},
|
|
762
822
|
this.createRequestId(),
|
|
@@ -767,10 +827,10 @@ class at {
|
|
|
767
827
|
async get(e, t = {}) {
|
|
768
828
|
const s = Array.isArray(e) ? e : [e];
|
|
769
829
|
if (s.length === 0)
|
|
770
|
-
return
|
|
830
|
+
return ne(s, "");
|
|
771
831
|
const n = f(
|
|
772
|
-
|
|
773
|
-
), i = await
|
|
832
|
+
ne(s, h())
|
|
833
|
+
), i = await O(
|
|
774
834
|
"getStorageValues",
|
|
775
835
|
{ keys: s },
|
|
776
836
|
this.createRequestId(),
|
|
@@ -785,7 +845,7 @@ class at {
|
|
|
785
845
|
* @param options - request execution options.
|
|
786
846
|
*/
|
|
787
847
|
async set(e, t, s = {}) {
|
|
788
|
-
await
|
|
848
|
+
await O(
|
|
789
849
|
"saveStorageValue",
|
|
790
850
|
{ key: e, value: t },
|
|
791
851
|
this.createRequestId(),
|
|
@@ -799,7 +859,7 @@ class ct {
|
|
|
799
859
|
* Checks if specified method is supported by current component.
|
|
800
860
|
*/
|
|
801
861
|
o(this, "supports");
|
|
802
|
-
this.postEvent = t, this.supports =
|
|
862
|
+
this.postEvent = t, this.supports = C(e, {
|
|
803
863
|
impactOccurred: "web_app_trigger_haptic_feedback",
|
|
804
864
|
notificationOccurred: "web_app_trigger_haptic_feedback",
|
|
805
865
|
selectionChanged: "web_app_trigger_haptic_feedback"
|
|
@@ -841,7 +901,7 @@ class ct {
|
|
|
841
901
|
}
|
|
842
902
|
function ht() {
|
|
843
903
|
return f({
|
|
844
|
-
id:
|
|
904
|
+
id: x(),
|
|
845
905
|
type: h(),
|
|
846
906
|
title: h(),
|
|
847
907
|
photoUrl: {
|
|
@@ -924,27 +984,27 @@ class ut {
|
|
|
924
984
|
return this.initData.user;
|
|
925
985
|
}
|
|
926
986
|
}
|
|
927
|
-
function
|
|
987
|
+
function ie() {
|
|
928
988
|
return f({
|
|
929
989
|
addedToAttachmentMenu: {
|
|
930
|
-
type:
|
|
990
|
+
type: P().optional(),
|
|
931
991
|
from: "added_to_attachment_menu"
|
|
932
992
|
},
|
|
933
993
|
allowsWriteToPm: {
|
|
934
|
-
type:
|
|
994
|
+
type: P().optional(),
|
|
935
995
|
from: "allows_write_to_pm"
|
|
936
996
|
},
|
|
937
997
|
firstName: {
|
|
938
998
|
type: h(),
|
|
939
999
|
from: "first_name"
|
|
940
1000
|
},
|
|
941
|
-
id:
|
|
1001
|
+
id: x(),
|
|
942
1002
|
isBot: {
|
|
943
|
-
type:
|
|
1003
|
+
type: P().optional(),
|
|
944
1004
|
from: "is_bot"
|
|
945
1005
|
},
|
|
946
1006
|
isPremium: {
|
|
947
|
-
type:
|
|
1007
|
+
type: P().optional(),
|
|
948
1008
|
from: "is_premium"
|
|
949
1009
|
},
|
|
950
1010
|
languageCode: {
|
|
@@ -962,11 +1022,11 @@ function oe() {
|
|
|
962
1022
|
username: h().optional()
|
|
963
1023
|
}, "User");
|
|
964
1024
|
}
|
|
965
|
-
const be =
|
|
966
|
-
function
|
|
967
|
-
return new
|
|
1025
|
+
const be = R((r) => r instanceof Date ? r : new Date(x().parse(r) * 1e3), "Date");
|
|
1026
|
+
function ee(r, e) {
|
|
1027
|
+
return new j((t) => {
|
|
968
1028
|
if (typeof t != "string" && !(t instanceof URLSearchParams))
|
|
969
|
-
throw
|
|
1029
|
+
throw V();
|
|
970
1030
|
const s = typeof t == "string" ? new URLSearchParams(t) : t;
|
|
971
1031
|
return de(r, (n) => {
|
|
972
1032
|
const i = s.get(n);
|
|
@@ -975,13 +1035,13 @@ function re(r, e) {
|
|
|
975
1035
|
}, !1, e);
|
|
976
1036
|
}
|
|
977
1037
|
function me() {
|
|
978
|
-
return
|
|
1038
|
+
return ee({
|
|
979
1039
|
authDate: {
|
|
980
1040
|
type: be(),
|
|
981
1041
|
from: "auth_date"
|
|
982
1042
|
},
|
|
983
1043
|
canSendAfter: {
|
|
984
|
-
type:
|
|
1044
|
+
type: x().optional(),
|
|
985
1045
|
from: "can_send_after"
|
|
986
1046
|
},
|
|
987
1047
|
chat: ht().optional(),
|
|
@@ -998,15 +1058,15 @@ function me() {
|
|
|
998
1058
|
type: h().optional(),
|
|
999
1059
|
from: "query_id"
|
|
1000
1060
|
},
|
|
1001
|
-
receiver:
|
|
1061
|
+
receiver: ie().optional(),
|
|
1002
1062
|
startParam: {
|
|
1003
1063
|
type: h().optional(),
|
|
1004
1064
|
from: "start_param"
|
|
1005
1065
|
},
|
|
1006
|
-
user:
|
|
1066
|
+
user: ie().optional()
|
|
1007
1067
|
}, "InitData");
|
|
1008
1068
|
}
|
|
1009
|
-
function
|
|
1069
|
+
function er(r) {
|
|
1010
1070
|
return me().parse(r);
|
|
1011
1071
|
}
|
|
1012
1072
|
function pt(r) {
|
|
@@ -1034,7 +1094,7 @@ class lt {
|
|
|
1034
1094
|
* Checks if specified method is supported by current component.
|
|
1035
1095
|
*/
|
|
1036
1096
|
o(this, "supports");
|
|
1037
|
-
this.postEvent = t, this.state = new
|
|
1097
|
+
this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, { open: "web_app_open_invoice" });
|
|
1038
1098
|
}
|
|
1039
1099
|
set isOpened(e) {
|
|
1040
1100
|
this.state.set("isOpened", e);
|
|
@@ -1051,17 +1111,13 @@ class lt {
|
|
|
1051
1111
|
const s = t ? pt(e) : e;
|
|
1052
1112
|
this.isOpened = !0;
|
|
1053
1113
|
try {
|
|
1054
|
-
return (await
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
postEvent: this.postEvent,
|
|
1060
|
-
capture(i) {
|
|
1061
|
-
return s === i.slug;
|
|
1062
|
-
}
|
|
1114
|
+
return (await y("web_app_open_invoice", "invoice_closed", {
|
|
1115
|
+
params: { slug: s },
|
|
1116
|
+
postEvent: this.postEvent,
|
|
1117
|
+
capture(i) {
|
|
1118
|
+
return s === i.slug;
|
|
1063
1119
|
}
|
|
1064
|
-
)).status;
|
|
1120
|
+
})).status;
|
|
1065
1121
|
} finally {
|
|
1066
1122
|
this.isOpened = !1;
|
|
1067
1123
|
}
|
|
@@ -1081,14 +1137,14 @@ class dt {
|
|
|
1081
1137
|
// FIXME: Event 'main_button_pressed' is still being received on Android
|
|
1082
1138
|
// even if the main button is disabled.
|
|
1083
1139
|
// Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
|
|
1084
|
-
e === "click" ?
|
|
1140
|
+
e === "click" ? E("main_button_pressed", t) : this.ee.on(e, t)
|
|
1085
1141
|
));
|
|
1086
1142
|
/**
|
|
1087
1143
|
* Removes event listener.
|
|
1088
1144
|
* @param event - event name.
|
|
1089
1145
|
* @param listener - event listener.
|
|
1090
1146
|
*/
|
|
1091
|
-
o(this, "off", (e, t) => e === "click" ?
|
|
1147
|
+
o(this, "off", (e, t) => e === "click" ? I("main_button_pressed", t) : this.ee.off(e, t));
|
|
1092
1148
|
const {
|
|
1093
1149
|
postEvent: t = d,
|
|
1094
1150
|
text: s,
|
|
@@ -1098,7 +1154,7 @@ class dt {
|
|
|
1098
1154
|
isVisible: c,
|
|
1099
1155
|
isLoaderVisible: u
|
|
1100
1156
|
} = e;
|
|
1101
|
-
this.postEvent = t, this.state = new
|
|
1157
|
+
this.postEvent = t, this.state = new m({
|
|
1102
1158
|
backgroundColor: i,
|
|
1103
1159
|
isEnabled: a,
|
|
1104
1160
|
isVisible: c,
|
|
@@ -1232,10 +1288,10 @@ class dt {
|
|
|
1232
1288
|
return this.state.set(e), this.commit(), this;
|
|
1233
1289
|
}
|
|
1234
1290
|
}
|
|
1235
|
-
const ft =
|
|
1291
|
+
const ft = ee({
|
|
1236
1292
|
contact: f({
|
|
1237
1293
|
userId: {
|
|
1238
|
-
type:
|
|
1294
|
+
type: x(),
|
|
1239
1295
|
from: "user_id"
|
|
1240
1296
|
},
|
|
1241
1297
|
phoneNumber: {
|
|
@@ -1260,7 +1316,7 @@ const ft = re({
|
|
|
1260
1316
|
function ye(r, e) {
|
|
1261
1317
|
return (t) => {
|
|
1262
1318
|
const [s, n] = e[t];
|
|
1263
|
-
return
|
|
1319
|
+
return A(s, n, r);
|
|
1264
1320
|
};
|
|
1265
1321
|
}
|
|
1266
1322
|
function gt(r) {
|
|
@@ -1300,14 +1356,14 @@ class wt {
|
|
|
1300
1356
|
version: i,
|
|
1301
1357
|
botInline: a,
|
|
1302
1358
|
createRequestId: c
|
|
1303
|
-
} = e, u =
|
|
1359
|
+
} = e, u = C(i, {
|
|
1304
1360
|
requestPhoneAccess: "web_app_request_phone",
|
|
1305
1361
|
requestWriteAccess: "web_app_request_write_access",
|
|
1306
1362
|
switchInlineQuery: "web_app_switch_inline_query",
|
|
1307
1363
|
setHeaderColor: "web_app_set_header_color",
|
|
1308
1364
|
setBackgroundColor: "web_app_set_background_color"
|
|
1309
1365
|
});
|
|
1310
|
-
this.postEvent = t, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new
|
|
1366
|
+
this.postEvent = t, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new m({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = ye(i, {
|
|
1311
1367
|
"setHeaderColor.color": ["web_app_set_header_color", "color"]
|
|
1312
1368
|
});
|
|
1313
1369
|
}
|
|
@@ -1315,7 +1371,7 @@ class wt {
|
|
|
1315
1371
|
* Attempts to get requested contact.
|
|
1316
1372
|
*/
|
|
1317
1373
|
async getRequestedContact() {
|
|
1318
|
-
return
|
|
1374
|
+
return O(
|
|
1319
1375
|
"getRequestedContact",
|
|
1320
1376
|
{},
|
|
1321
1377
|
this.createRequestId(),
|
|
@@ -1417,7 +1473,7 @@ class wt {
|
|
|
1417
1473
|
requestPhoneAccess(e = {}) {
|
|
1418
1474
|
if (this.requestingPhoneAccess)
|
|
1419
1475
|
throw new Error("Phone access is already being requested.");
|
|
1420
|
-
return this.requestingPhoneAccess = !0,
|
|
1476
|
+
return this.requestingPhoneAccess = !0, y("web_app_request_phone", "phone_requested", {
|
|
1421
1477
|
...e,
|
|
1422
1478
|
postEvent: this.postEvent
|
|
1423
1479
|
}).then((t) => t.status).finally(() => {
|
|
@@ -1431,7 +1487,7 @@ class wt {
|
|
|
1431
1487
|
requestWriteAccess(e = {}) {
|
|
1432
1488
|
if (this.requestingWriteAccess)
|
|
1433
1489
|
throw new Error("Write access is already being requested.");
|
|
1434
|
-
return this.requestingWriteAccess = !0,
|
|
1490
|
+
return this.requestingWriteAccess = !0, y("web_app_request_write_access", "write_access_requested", {
|
|
1435
1491
|
...e,
|
|
1436
1492
|
postEvent: this.postEvent
|
|
1437
1493
|
}).then((t) => t.status).finally(() => {
|
|
@@ -1458,7 +1514,7 @@ class wt {
|
|
|
1458
1514
|
* @param color - color key or RGB color.
|
|
1459
1515
|
*/
|
|
1460
1516
|
setHeaderColor(e) {
|
|
1461
|
-
this.postEvent("web_app_set_header_color",
|
|
1517
|
+
this.postEvent("web_app_set_header_color", X(e) ? { color: e } : { color_key: e }), this.state.set("headerColor", e);
|
|
1462
1518
|
}
|
|
1463
1519
|
/**
|
|
1464
1520
|
* Updates current Mini App background color.
|
|
@@ -1526,7 +1582,7 @@ class bt {
|
|
|
1526
1582
|
* Checks if specified method is supported by current component.
|
|
1527
1583
|
*/
|
|
1528
1584
|
o(this, "supports");
|
|
1529
|
-
this.postEvent = t, this.state = new
|
|
1585
|
+
this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, { open: "web_app_open_popup" });
|
|
1530
1586
|
}
|
|
1531
1587
|
set isOpened(e) {
|
|
1532
1588
|
this.state.set("isOpened", e);
|
|
@@ -1553,12 +1609,10 @@ class bt {
|
|
|
1553
1609
|
open(e) {
|
|
1554
1610
|
if (this.isOpened)
|
|
1555
1611
|
throw new Error("Popup is already opened.");
|
|
1556
|
-
return this.isOpened = !0,
|
|
1557
|
-
|
|
1558
|
-
_t(e)
|
|
1559
|
-
|
|
1560
|
-
{ postEvent: this.postEvent }
|
|
1561
|
-
).then(({ button_id: t = null }) => t).finally(() => {
|
|
1612
|
+
return this.isOpened = !0, y("web_app_open_popup", "popup_closed", {
|
|
1613
|
+
postEvent: this.postEvent,
|
|
1614
|
+
params: _t(e)
|
|
1615
|
+
}).then(({ button_id: t = null }) => t).finally(() => {
|
|
1562
1616
|
this.isOpened = !1;
|
|
1563
1617
|
});
|
|
1564
1618
|
}
|
|
@@ -1579,7 +1633,7 @@ class mt {
|
|
|
1579
1633
|
* Checks if specified method is supported by current component.
|
|
1580
1634
|
*/
|
|
1581
1635
|
o(this, "supports");
|
|
1582
|
-
this.postEvent = t, this.state = new
|
|
1636
|
+
this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, {
|
|
1583
1637
|
close: "web_app_close_scan_qr_popup",
|
|
1584
1638
|
open: "web_app_open_scan_qr_popup"
|
|
1585
1639
|
});
|
|
@@ -1610,11 +1664,13 @@ class mt {
|
|
|
1610
1664
|
throw new Error("QR scanner is already opened.");
|
|
1611
1665
|
this.isOpened = !0;
|
|
1612
1666
|
try {
|
|
1613
|
-
const t = await
|
|
1667
|
+
const t = await y(
|
|
1614
1668
|
"web_app_open_scan_qr_popup",
|
|
1615
|
-
{ text: e },
|
|
1616
1669
|
["qr_text_received", "scan_qr_popup_closed"],
|
|
1617
|
-
{
|
|
1670
|
+
{
|
|
1671
|
+
postEvent: this.postEvent,
|
|
1672
|
+
params: { text: e }
|
|
1673
|
+
}
|
|
1618
1674
|
);
|
|
1619
1675
|
return typeof t == "object" && typeof t.data == "string" ? t.data : null;
|
|
1620
1676
|
} finally {
|
|
@@ -1631,18 +1687,18 @@ class yt {
|
|
|
1631
1687
|
* @param event - event name.
|
|
1632
1688
|
* @param listener - event listener.
|
|
1633
1689
|
*/
|
|
1634
|
-
o(this, "on", (e, t) => e === "click" ?
|
|
1690
|
+
o(this, "on", (e, t) => e === "click" ? E("settings_button_pressed", t) : this.ee.on(e, t));
|
|
1635
1691
|
/**
|
|
1636
1692
|
* Removes event listener.
|
|
1637
1693
|
* @param event - event name.
|
|
1638
1694
|
* @param listener - event listener.
|
|
1639
1695
|
*/
|
|
1640
|
-
o(this, "off", (e, t) => e === "click" ?
|
|
1696
|
+
o(this, "off", (e, t) => e === "click" ? I("settings_button_pressed", t) : this.ee.off(e, t));
|
|
1641
1697
|
/**
|
|
1642
1698
|
* Checks if specified method is supported by current component.
|
|
1643
1699
|
*/
|
|
1644
1700
|
o(this, "supports");
|
|
1645
|
-
this.postEvent = s, this.state = new
|
|
1701
|
+
this.postEvent = s, this.state = new m({ isVisible: e }, this.ee), this.supports = C(t, {
|
|
1646
1702
|
show: "web_app_setup_settings_button",
|
|
1647
1703
|
hide: "web_app_setup_settings_button"
|
|
1648
1704
|
});
|
|
@@ -1675,18 +1731,18 @@ function Et(r) {
|
|
|
1675
1731
|
function Ct(r) {
|
|
1676
1732
|
return r.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`).replace(/(^|_)background/, (e, t) => `${t}bg`);
|
|
1677
1733
|
}
|
|
1678
|
-
const Ee =
|
|
1734
|
+
const Ee = R(
|
|
1679
1735
|
(r) => {
|
|
1680
1736
|
const e = ge().optional();
|
|
1681
|
-
return Object.entries(
|
|
1737
|
+
return Object.entries(Y(r)).reduce((t, [s, n]) => (t[Et(s)] = e.parse(n), t), {});
|
|
1682
1738
|
},
|
|
1683
1739
|
"ThemeParams"
|
|
1684
1740
|
);
|
|
1685
1741
|
function Ce(r) {
|
|
1686
1742
|
return Ee().parse(r);
|
|
1687
1743
|
}
|
|
1688
|
-
function
|
|
1689
|
-
return
|
|
1744
|
+
function tr(r) {
|
|
1745
|
+
return y("web_app_request_theme", "theme_changed", r).then(Ce);
|
|
1690
1746
|
}
|
|
1691
1747
|
function vt(r) {
|
|
1692
1748
|
return JSON.stringify(
|
|
@@ -1705,7 +1761,7 @@ class Pt {
|
|
|
1705
1761
|
* Removes event listener.
|
|
1706
1762
|
*/
|
|
1707
1763
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1708
|
-
this.state = new
|
|
1764
|
+
this.state = new m(e, this.ee);
|
|
1709
1765
|
}
|
|
1710
1766
|
/**
|
|
1711
1767
|
* @since v6.10
|
|
@@ -1777,7 +1833,7 @@ class Pt {
|
|
|
1777
1833
|
* @returns Function to stop listening.
|
|
1778
1834
|
*/
|
|
1779
1835
|
listen() {
|
|
1780
|
-
return
|
|
1836
|
+
return E("theme_changed", (e) => {
|
|
1781
1837
|
this.state.set(Ce(e.theme_params));
|
|
1782
1838
|
});
|
|
1783
1839
|
}
|
|
@@ -1791,7 +1847,7 @@ class Pt {
|
|
|
1791
1847
|
return this.get("textColor");
|
|
1792
1848
|
}
|
|
1793
1849
|
}
|
|
1794
|
-
class
|
|
1850
|
+
class St {
|
|
1795
1851
|
constructor(e, t, s = d) {
|
|
1796
1852
|
/**
|
|
1797
1853
|
* Checks if specified method is supported by current component.
|
|
@@ -1801,7 +1857,7 @@ class kt {
|
|
|
1801
1857
|
* Checks if specified method parameter is supported by current component.
|
|
1802
1858
|
*/
|
|
1803
1859
|
o(this, "supportsParam");
|
|
1804
|
-
this.version = e, this.createRequestId = t, this.postEvent = s, this.supports =
|
|
1860
|
+
this.version = e, this.createRequestId = t, this.postEvent = s, this.supports = C(e, {
|
|
1805
1861
|
readTextFromClipboard: "web_app_read_text_from_clipboard"
|
|
1806
1862
|
}), this.supportsParam = ye(e, {
|
|
1807
1863
|
"openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
|
|
@@ -1818,7 +1874,7 @@ class kt {
|
|
|
1818
1874
|
*/
|
|
1819
1875
|
openLink(e, t) {
|
|
1820
1876
|
const s = new URL(e, window.location.href).toString();
|
|
1821
|
-
if (!
|
|
1877
|
+
if (!A("web_app_open_link", this.version)) {
|
|
1822
1878
|
window.open(s, "_blank");
|
|
1823
1879
|
return;
|
|
1824
1880
|
}
|
|
@@ -1841,7 +1897,7 @@ class kt {
|
|
|
1841
1897
|
} = new URL(e, window.location.href);
|
|
1842
1898
|
if (t !== "t.me")
|
|
1843
1899
|
throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);
|
|
1844
|
-
if (!
|
|
1900
|
+
if (!A("web_app_open_tg_link", this.version)) {
|
|
1845
1901
|
window.location.href = e;
|
|
1846
1902
|
return;
|
|
1847
1903
|
}
|
|
@@ -1853,20 +1909,22 @@ class kt {
|
|
|
1853
1909
|
* - Value in clipboard is not text
|
|
1854
1910
|
* - Access to clipboard is not allowed
|
|
1855
1911
|
*/
|
|
1856
|
-
readTextFromClipboard() {
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
{
|
|
1862
|
-
|
|
1912
|
+
async readTextFromClipboard() {
|
|
1913
|
+
const e = this.createRequestId(), {
|
|
1914
|
+
data: t = null
|
|
1915
|
+
} = await y("web_app_read_text_from_clipboard", "clipboard_text_received", {
|
|
1916
|
+
postEvent: this.postEvent,
|
|
1917
|
+
params: { req_id: e },
|
|
1918
|
+
capture: le(e)
|
|
1919
|
+
});
|
|
1920
|
+
return t;
|
|
1863
1921
|
}
|
|
1864
1922
|
}
|
|
1865
|
-
function
|
|
1923
|
+
function kt(r) {
|
|
1866
1924
|
return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
|
|
1867
1925
|
}
|
|
1868
1926
|
async function ve(r) {
|
|
1869
|
-
const e = await
|
|
1927
|
+
const e = await y("web_app_request_viewport", "viewport_changed", r);
|
|
1870
1928
|
return {
|
|
1871
1929
|
height: e.height,
|
|
1872
1930
|
width: e.width,
|
|
@@ -1874,7 +1932,7 @@ async function ve(r) {
|
|
|
1874
1932
|
isStateStable: e.is_state_stable
|
|
1875
1933
|
};
|
|
1876
1934
|
}
|
|
1877
|
-
function
|
|
1935
|
+
function L(r) {
|
|
1878
1936
|
return r < 0 ? 0 : r;
|
|
1879
1937
|
}
|
|
1880
1938
|
class xt {
|
|
@@ -1897,11 +1955,11 @@ class xt {
|
|
|
1897
1955
|
stableHeight: i,
|
|
1898
1956
|
postEvent: a = d
|
|
1899
1957
|
} = e;
|
|
1900
|
-
this.postEvent = a, this.state = new
|
|
1901
|
-
height:
|
|
1958
|
+
this.postEvent = a, this.state = new m({
|
|
1959
|
+
height: L(t),
|
|
1902
1960
|
isExpanded: s,
|
|
1903
|
-
stableHeight:
|
|
1904
|
-
width:
|
|
1961
|
+
stableHeight: L(i),
|
|
1962
|
+
width: L(n)
|
|
1905
1963
|
}, this.ee);
|
|
1906
1964
|
}
|
|
1907
1965
|
/**
|
|
@@ -1960,16 +2018,16 @@ class xt {
|
|
|
1960
2018
|
* @returns Function to stop listening.
|
|
1961
2019
|
*/
|
|
1962
2020
|
listen() {
|
|
1963
|
-
return
|
|
2021
|
+
return E("viewport_changed", (e) => {
|
|
1964
2022
|
const {
|
|
1965
2023
|
height: t,
|
|
1966
2024
|
width: s,
|
|
1967
2025
|
is_expanded: n,
|
|
1968
2026
|
is_state_stable: i
|
|
1969
2027
|
} = e, a = {
|
|
1970
|
-
height:
|
|
2028
|
+
height: L(t),
|
|
1971
2029
|
isExpanded: n,
|
|
1972
|
-
width:
|
|
2030
|
+
width: L(s)
|
|
1973
2031
|
};
|
|
1974
2032
|
i && (a.stableHeight = a.height), this.state.set(a);
|
|
1975
2033
|
});
|
|
@@ -2017,7 +2075,7 @@ function qt(r, e) {
|
|
|
2017
2075
|
backgroundColor: n,
|
|
2018
2076
|
secondaryBackgroundColor: i
|
|
2019
2077
|
} = e;
|
|
2020
|
-
if (
|
|
2078
|
+
if (X(r.headerColor)) {
|
|
2021
2079
|
S("--tg-header-color", r.headerColor);
|
|
2022
2080
|
return;
|
|
2023
2081
|
}
|
|
@@ -2041,82 +2099,35 @@ function At(r) {
|
|
|
2041
2099
|
};
|
|
2042
2100
|
r.on("change", e), e();
|
|
2043
2101
|
}
|
|
2044
|
-
function
|
|
2102
|
+
function oe(r) {
|
|
2045
2103
|
const e = () => S("--tg-viewport-height", `${r.height}px`), t = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-stable-height", `${r.stableHeight}px`);
|
|
2046
2104
|
r.on("change:height", e), r.on("change:width", t), r.on("change:stableHeight", s), e(), t(), s();
|
|
2047
2105
|
}
|
|
2048
2106
|
function Vt() {
|
|
2049
2107
|
const r = document.createElement("style");
|
|
2050
|
-
r.id = "telegram-custom-styles", document.head.appendChild(r),
|
|
2108
|
+
r.id = "telegram-custom-styles", document.head.appendChild(r), E("set_custom_style", (e) => {
|
|
2051
2109
|
r.innerHTML = e;
|
|
2052
2110
|
});
|
|
2053
2111
|
}
|
|
2054
|
-
class Rt {
|
|
2055
|
-
constructor(e, t, s = d) {
|
|
2056
|
-
o(this, "ee", new w());
|
|
2057
|
-
o(this, "state");
|
|
2058
|
-
/**
|
|
2059
|
-
* Adds event listener.
|
|
2060
|
-
* @param event - event name.
|
|
2061
|
-
* @param listener - event listener.
|
|
2062
|
-
*/
|
|
2063
|
-
o(this, "on", (e, t) => e === "click" ? y("back_button_pressed", t) : this.ee.on(e, t));
|
|
2064
|
-
/**
|
|
2065
|
-
* Removes event listener.
|
|
2066
|
-
* @param event - event name.
|
|
2067
|
-
* @param listener - event listener.
|
|
2068
|
-
*/
|
|
2069
|
-
o(this, "off", (e, t) => e === "click" ? $("back_button_pressed", t) : this.ee.off(e, t));
|
|
2070
|
-
/**
|
|
2071
|
-
* Checks if specified method is supported by current component.
|
|
2072
|
-
*/
|
|
2073
|
-
o(this, "supports");
|
|
2074
|
-
this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
|
|
2075
|
-
show: "web_app_setup_back_button",
|
|
2076
|
-
hide: "web_app_setup_back_button"
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
set isVisible(e) {
|
|
2080
|
-
this.state.set("isVisible", e), this.postEvent("web_app_setup_back_button", { is_visible: e });
|
|
2081
|
-
}
|
|
2082
|
-
/**
|
|
2083
|
-
* True if BackButton is currently visible.
|
|
2084
|
-
*/
|
|
2085
|
-
get isVisible() {
|
|
2086
|
-
return this.state.get("isVisible");
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* Hides the BackButton.
|
|
2090
|
-
*/
|
|
2091
|
-
hide() {
|
|
2092
|
-
this.isVisible = !1;
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* Shows the BackButton.
|
|
2096
|
-
*/
|
|
2097
|
-
show() {
|
|
2098
|
-
this.isVisible = !0;
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
2112
|
function Pe(r) {
|
|
2102
2113
|
return `telegram-mini-apps-${r}`;
|
|
2103
2114
|
}
|
|
2104
|
-
function
|
|
2115
|
+
function T(r, e) {
|
|
2105
2116
|
sessionStorage.setItem(Pe(r), JSON.stringify(e));
|
|
2106
2117
|
}
|
|
2107
|
-
function
|
|
2118
|
+
function $(r) {
|
|
2108
2119
|
const e = sessionStorage.getItem(Pe(r));
|
|
2109
2120
|
return e ? JSON.parse(e) : null;
|
|
2110
2121
|
}
|
|
2111
|
-
function
|
|
2112
|
-
const { isVisible: s = !1 } = r ?
|
|
2122
|
+
function Rt(r, e, t) {
|
|
2123
|
+
const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new rt(s, e, t);
|
|
2113
2124
|
return n.on("change", () => {
|
|
2114
|
-
|
|
2125
|
+
T("back-button", { isVisible: n.isVisible });
|
|
2115
2126
|
}), n;
|
|
2116
2127
|
}
|
|
2117
|
-
function
|
|
2118
|
-
const { isConfirmationNeeded: t = !1 } = r ?
|
|
2119
|
-
return s.on("change", () =>
|
|
2128
|
+
function It(r, e) {
|
|
2129
|
+
const { isConfirmationNeeded: t = !1 } = r ? $("closing-behavior") || {} : {}, s = new st(t, e);
|
|
2130
|
+
return s.on("change", () => T("closing-behavior", {
|
|
2120
2131
|
isConfirmationNeeded: s.isConfirmationNeeded
|
|
2121
2132
|
})), s;
|
|
2122
2133
|
}
|
|
@@ -2128,7 +2139,7 @@ function Tt(r, e, t, s) {
|
|
|
2128
2139
|
isLoaderVisible: c = !1,
|
|
2129
2140
|
textColor: u = t,
|
|
2130
2141
|
text: p = ""
|
|
2131
|
-
} = r ?
|
|
2142
|
+
} = r ? $("main-button") || {} : {}, g = new dt({
|
|
2132
2143
|
backgroundColor: n,
|
|
2133
2144
|
isEnabled: i,
|
|
2134
2145
|
isLoaderVisible: c,
|
|
@@ -2136,7 +2147,7 @@ function Tt(r, e, t, s) {
|
|
|
2136
2147
|
postEvent: s,
|
|
2137
2148
|
text: p,
|
|
2138
2149
|
textColor: u
|
|
2139
|
-
}), _ = () =>
|
|
2150
|
+
}), _ = () => T("main-button", {
|
|
2140
2151
|
backgroundColor: g.backgroundColor,
|
|
2141
2152
|
isEnabled: g.isEnabled,
|
|
2142
2153
|
isLoaderVisible: g.isLoaderVisible,
|
|
@@ -2150,48 +2161,48 @@ function $t(r, e, t, s, n, i) {
|
|
|
2150
2161
|
const {
|
|
2151
2162
|
backgroundColor: a = e,
|
|
2152
2163
|
headerColor: c = "bg_color"
|
|
2153
|
-
} = r ?
|
|
2164
|
+
} = r ? $("mini-app") || {} : {}, u = new wt({
|
|
2154
2165
|
headerColor: c,
|
|
2155
2166
|
backgroundColor: a,
|
|
2156
2167
|
version: t,
|
|
2157
2168
|
botInline: s,
|
|
2158
2169
|
createRequestId: n,
|
|
2159
2170
|
postEvent: i
|
|
2160
|
-
}), p = () =>
|
|
2171
|
+
}), p = () => T("mini-app", {
|
|
2161
2172
|
backgroundColor: u.backgroundColor,
|
|
2162
2173
|
headerColor: u.headerColor
|
|
2163
2174
|
});
|
|
2164
2175
|
return u.on("change", p), u;
|
|
2165
2176
|
}
|
|
2166
|
-
function
|
|
2177
|
+
function Lt() {
|
|
2167
2178
|
let r = 0;
|
|
2168
2179
|
return () => (r += 1, r.toString());
|
|
2169
2180
|
}
|
|
2170
|
-
function
|
|
2171
|
-
const { isVisible: s = !1 } = r ?
|
|
2181
|
+
function Bt(r, e, t) {
|
|
2182
|
+
const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new yt(s, e, t);
|
|
2172
2183
|
return n.on("change", () => {
|
|
2173
|
-
|
|
2184
|
+
T("settings-button", { isVisible: n.isVisible });
|
|
2174
2185
|
}), n;
|
|
2175
2186
|
}
|
|
2176
|
-
function
|
|
2187
|
+
function Ot(r) {
|
|
2177
2188
|
const e = new Pt(r);
|
|
2178
2189
|
return e.listen(), e;
|
|
2179
2190
|
}
|
|
2180
|
-
function
|
|
2191
|
+
function N(r) {
|
|
2181
2192
|
const e = new xt(r);
|
|
2182
|
-
return e.on("change", () =>
|
|
2193
|
+
return e.on("change", () => T("viewport", {
|
|
2183
2194
|
height: e.height,
|
|
2184
2195
|
isExpanded: e.isExpanded,
|
|
2185
2196
|
stableHeight: e.stableHeight,
|
|
2186
2197
|
width: e.width
|
|
2187
2198
|
})), e.listen(), e;
|
|
2188
2199
|
}
|
|
2189
|
-
function
|
|
2190
|
-
const n = r ?
|
|
2200
|
+
function Dt(r, e, t, s) {
|
|
2201
|
+
const n = r ? $("viewport") : null;
|
|
2191
2202
|
if (n)
|
|
2192
|
-
return
|
|
2193
|
-
if (
|
|
2194
|
-
return
|
|
2203
|
+
return N({ ...n, postEvent: t });
|
|
2204
|
+
if (kt(e))
|
|
2205
|
+
return N({
|
|
2195
2206
|
height: window.innerHeight,
|
|
2196
2207
|
isExpanded: !0,
|
|
2197
2208
|
postEvent: t,
|
|
@@ -2202,12 +2213,12 @@ function Ot(r, e, t, s) {
|
|
|
2202
2213
|
return ve({
|
|
2203
2214
|
postEvent: t,
|
|
2204
2215
|
timeout: 5e3
|
|
2205
|
-
}).then(({ height: a, isStateStable: c, ...u }) =>
|
|
2216
|
+
}).then(({ height: a, isStateStable: c, ...u }) => N({
|
|
2206
2217
|
...u,
|
|
2207
2218
|
height: a,
|
|
2208
2219
|
stableHeight: c ? a : 0
|
|
2209
2220
|
}));
|
|
2210
|
-
const i =
|
|
2221
|
+
const i = N({
|
|
2211
2222
|
width: 0,
|
|
2212
2223
|
height: 0,
|
|
2213
2224
|
isExpanded: !1,
|
|
@@ -2218,21 +2229,21 @@ function Ot(r, e, t, s) {
|
|
|
2218
2229
|
console.error("Unable to actualize viewport state", a);
|
|
2219
2230
|
}), i;
|
|
2220
2231
|
}
|
|
2221
|
-
function
|
|
2232
|
+
function Wt(r) {
|
|
2222
2233
|
return typeof r == "object" ? r : r ? {
|
|
2223
2234
|
themeParams: !0,
|
|
2224
2235
|
viewport: !0,
|
|
2225
2236
|
miniApp: !0
|
|
2226
2237
|
} : {};
|
|
2227
2238
|
}
|
|
2228
|
-
function
|
|
2229
|
-
const n =
|
|
2230
|
-
n.miniApp && qt(e, t), n.themeParams && At(t), n.viewport && (s instanceof Promise ? s.then(
|
|
2239
|
+
function ae(r, e, t, s) {
|
|
2240
|
+
const n = Wt(r);
|
|
2241
|
+
n.miniApp && qt(e, t), n.themeParams && At(t), n.viewport && (s instanceof Promise ? s.then(oe) : oe(s));
|
|
2231
2242
|
}
|
|
2232
|
-
function
|
|
2233
|
-
return
|
|
2243
|
+
function Ht() {
|
|
2244
|
+
return ee({
|
|
2234
2245
|
botInline: {
|
|
2235
|
-
type:
|
|
2246
|
+
type: P().optional(),
|
|
2236
2247
|
from: "tgWebAppBotInline"
|
|
2237
2248
|
},
|
|
2238
2249
|
initData: {
|
|
@@ -2248,7 +2259,7 @@ function Nt() {
|
|
|
2248
2259
|
from: "tgWebAppPlatform"
|
|
2249
2260
|
},
|
|
2250
2261
|
showSettings: {
|
|
2251
|
-
type:
|
|
2262
|
+
type: P().optional(),
|
|
2252
2263
|
from: "tgWebAppShowSettings"
|
|
2253
2264
|
},
|
|
2254
2265
|
startParam: {
|
|
@@ -2265,26 +2276,26 @@ function Nt() {
|
|
|
2265
2276
|
}
|
|
2266
2277
|
}, "LaunchParams");
|
|
2267
2278
|
}
|
|
2268
|
-
function ke(r) {
|
|
2269
|
-
return Nt().parse(r);
|
|
2270
|
-
}
|
|
2271
2279
|
function Se(r) {
|
|
2280
|
+
return Ht().parse(r);
|
|
2281
|
+
}
|
|
2282
|
+
function ke(r) {
|
|
2272
2283
|
const e = r.includes("?") ? r.replace("#", "&").slice(r.indexOf("?") + 1) : r.slice(r.indexOf("#") + 1);
|
|
2273
|
-
return
|
|
2284
|
+
return Se(e);
|
|
2274
2285
|
}
|
|
2275
|
-
function
|
|
2276
|
-
return
|
|
2286
|
+
function Nt() {
|
|
2287
|
+
return ke(window.location.href);
|
|
2277
2288
|
}
|
|
2278
2289
|
function xe() {
|
|
2279
2290
|
return performance.getEntriesByType("navigation")[0];
|
|
2280
2291
|
}
|
|
2281
|
-
function
|
|
2292
|
+
function Ut() {
|
|
2282
2293
|
const r = xe();
|
|
2283
2294
|
if (!r)
|
|
2284
2295
|
throw new Error("Unable to get first navigation entry.");
|
|
2285
|
-
return
|
|
2296
|
+
return ke(r.name);
|
|
2286
2297
|
}
|
|
2287
|
-
function
|
|
2298
|
+
function Mt(r) {
|
|
2288
2299
|
const {
|
|
2289
2300
|
initDataRaw: e,
|
|
2290
2301
|
themeParams: t,
|
|
@@ -2297,36 +2308,36 @@ function Gt(r) {
|
|
|
2297
2308
|
return e && u.set("tgWebAppData", e), u.set("tgWebAppPlatform", s), u.set("tgWebAppThemeParams", vt(t)), u.set("tgWebAppVersion", n), a && u.set("tgWebAppStartParam", n), typeof i == "boolean" && u.set("tgWebAppShowSettings", i ? "1" : "0"), typeof c == "boolean" && u.set("tgWebAppBotInline", c ? "1" : "0"), u.toString();
|
|
2298
2309
|
}
|
|
2299
2310
|
const qe = "telegram-mini-apps-launch-params";
|
|
2300
|
-
function
|
|
2301
|
-
return
|
|
2311
|
+
function Gt() {
|
|
2312
|
+
return Se(sessionStorage.getItem(qe) || "");
|
|
2302
2313
|
}
|
|
2303
|
-
function
|
|
2304
|
-
sessionStorage.setItem(qe,
|
|
2314
|
+
function jt(r) {
|
|
2315
|
+
sessionStorage.setItem(qe, Mt(r));
|
|
2305
2316
|
}
|
|
2306
|
-
function
|
|
2317
|
+
function te() {
|
|
2307
2318
|
const r = [];
|
|
2308
2319
|
for (const e of [
|
|
2309
2320
|
// Try to retrieve launch parameters from the current location. This method can return
|
|
2310
2321
|
// nothing in case, location was changed and then page was reloaded.
|
|
2311
|
-
|
|
2322
|
+
Nt,
|
|
2312
2323
|
// Then, try using the lower level API - window.performance.
|
|
2313
|
-
|
|
2324
|
+
Ut,
|
|
2314
2325
|
// Finally, try to extract launch parameters from the session storage.
|
|
2315
|
-
|
|
2326
|
+
Gt
|
|
2316
2327
|
])
|
|
2317
2328
|
try {
|
|
2318
2329
|
const t = e();
|
|
2319
|
-
return
|
|
2330
|
+
return jt(t), t;
|
|
2320
2331
|
} catch (t) {
|
|
2321
2332
|
r.push(t);
|
|
2322
2333
|
}
|
|
2323
|
-
throw
|
|
2334
|
+
throw k.error("Unable to extract launch parameters. Received errors:", r), new Error("Unable to retrieve launch parameters from any known source.");
|
|
2324
2335
|
}
|
|
2325
2336
|
function Ae() {
|
|
2326
2337
|
var r;
|
|
2327
2338
|
return ((r = xe()) == null ? void 0 : r.type) === "reload";
|
|
2328
2339
|
}
|
|
2329
|
-
function
|
|
2340
|
+
function rr(r = {}) {
|
|
2330
2341
|
const {
|
|
2331
2342
|
async: e = !1,
|
|
2332
2343
|
complete: t = e,
|
|
@@ -2341,15 +2352,15 @@ function sr(r = {}) {
|
|
|
2341
2352
|
platform: u,
|
|
2342
2353
|
themeParams: p,
|
|
2343
2354
|
botInline: g = !1
|
|
2344
|
-
} =
|
|
2345
|
-
|
|
2355
|
+
} = te(), _ = Ae(), b = Lt(), l = Oe(c);
|
|
2356
|
+
pe() && (n && Vt(), l("iframe_ready", { reload_supported: !0 }), E("reload_iframe", () => {
|
|
2346
2357
|
l("iframe_will_reload"), window.location.reload();
|
|
2347
2358
|
}));
|
|
2348
|
-
const
|
|
2349
|
-
backButton:
|
|
2350
|
-
closingBehavior:
|
|
2351
|
-
cloudStorage: new at(c,
|
|
2352
|
-
createRequestId:
|
|
2359
|
+
const q = {
|
|
2360
|
+
backButton: Rt(_, c, l),
|
|
2361
|
+
closingBehavior: It(_, l),
|
|
2362
|
+
cloudStorage: new at(c, b, l),
|
|
2363
|
+
createRequestId: b,
|
|
2353
2364
|
hapticFeedback: new ct(c, l),
|
|
2354
2365
|
invoice: new lt(c, l),
|
|
2355
2366
|
mainButton: Tt(
|
|
@@ -2363,55 +2374,55 @@ function sr(r = {}) {
|
|
|
2363
2374
|
p.backgroundColor || "#ffffff",
|
|
2364
2375
|
c,
|
|
2365
2376
|
g,
|
|
2366
|
-
|
|
2377
|
+
b,
|
|
2367
2378
|
l
|
|
2368
2379
|
),
|
|
2369
2380
|
popup: new bt(c, l),
|
|
2370
2381
|
postEvent: l,
|
|
2371
2382
|
qrScanner: new mt(c, l),
|
|
2372
|
-
settingsButton:
|
|
2373
|
-
themeParams:
|
|
2374
|
-
utils: new
|
|
2383
|
+
settingsButton: Bt(_, c, l),
|
|
2384
|
+
themeParams: Ot(p),
|
|
2385
|
+
utils: new St(c, b, l),
|
|
2375
2386
|
...i ? {
|
|
2376
2387
|
initData: new ut(i),
|
|
2377
2388
|
initDataRaw: a
|
|
2378
2389
|
} : {}
|
|
2379
|
-
},
|
|
2380
|
-
return
|
|
2390
|
+
}, H = Dt(_, u, l, t);
|
|
2391
|
+
return H instanceof Promise || t ? Promise.resolve(H).then((re) => (ae(
|
|
2381
2392
|
s,
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
), { ...
|
|
2393
|
+
q.miniApp,
|
|
2394
|
+
q.themeParams,
|
|
2395
|
+
re
|
|
2396
|
+
), { ...q, viewport: re })) : (ae(
|
|
2386
2397
|
s,
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
), { ...
|
|
2398
|
+
q.miniApp,
|
|
2399
|
+
q.themeParams,
|
|
2400
|
+
H
|
|
2401
|
+
), { ...q, viewport: H });
|
|
2391
2402
|
} catch (i) {
|
|
2392
2403
|
if (t)
|
|
2393
2404
|
return Promise.reject(i);
|
|
2394
2405
|
throw i;
|
|
2395
2406
|
}
|
|
2396
2407
|
}
|
|
2397
|
-
function
|
|
2408
|
+
function sr() {
|
|
2398
2409
|
return {
|
|
2399
|
-
launchParams:
|
|
2410
|
+
launchParams: te(),
|
|
2400
2411
|
isPageReload: Ae()
|
|
2401
2412
|
};
|
|
2402
2413
|
}
|
|
2403
|
-
function
|
|
2414
|
+
function nr() {
|
|
2404
2415
|
try {
|
|
2405
|
-
return
|
|
2416
|
+
return te(), !0;
|
|
2406
2417
|
} catch {
|
|
2407
2418
|
return !1;
|
|
2408
2419
|
}
|
|
2409
2420
|
}
|
|
2410
|
-
function
|
|
2421
|
+
function ir(r) {
|
|
2411
2422
|
const e = r.match(/#(.+)/);
|
|
2412
2423
|
return e ? e[1] : null;
|
|
2413
2424
|
}
|
|
2414
|
-
async function
|
|
2425
|
+
async function D(r) {
|
|
2415
2426
|
return r === 0 ? !0 : Promise.race([
|
|
2416
2427
|
new Promise((e) => {
|
|
2417
2428
|
window.addEventListener("popstate", function t() {
|
|
@@ -2424,17 +2435,17 @@ async function N(r) {
|
|
|
2424
2435
|
})
|
|
2425
2436
|
]);
|
|
2426
2437
|
}
|
|
2427
|
-
async function
|
|
2428
|
-
if (window.history.length <= 1 || (window.history.pushState(null, ""), await
|
|
2438
|
+
async function Ft() {
|
|
2439
|
+
if (window.history.length <= 1 || (window.history.pushState(null, ""), await D(1 - window.history.length)))
|
|
2429
2440
|
return;
|
|
2430
|
-
let e = await
|
|
2441
|
+
let e = await D(-1);
|
|
2431
2442
|
for (; e; )
|
|
2432
|
-
e = await
|
|
2443
|
+
e = await D(-1);
|
|
2433
2444
|
}
|
|
2434
|
-
function
|
|
2445
|
+
function B(r, e) {
|
|
2435
2446
|
return r.startsWith(e) ? r : `${e}${r}`;
|
|
2436
2447
|
}
|
|
2437
|
-
class
|
|
2448
|
+
class zt {
|
|
2438
2449
|
constructor(e, t, {
|
|
2439
2450
|
debug: s = !1,
|
|
2440
2451
|
loggerPrefix: n = "Navigator"
|
|
@@ -2449,11 +2460,11 @@ class Jt {
|
|
|
2449
2460
|
if (!i.startsWith("/") && i.length > 0)
|
|
2450
2461
|
throw new Error('Pathname should start with "/"');
|
|
2451
2462
|
return {
|
|
2452
|
-
pathname:
|
|
2453
|
-
search: a ?
|
|
2454
|
-
hash: c ?
|
|
2463
|
+
pathname: B(i, "/"),
|
|
2464
|
+
search: a ? B(a, "?") : "",
|
|
2465
|
+
hash: c ? B(c, "#") : ""
|
|
2455
2466
|
};
|
|
2456
|
-
}), this.logger = new
|
|
2467
|
+
}), this.logger = new he(`[${n}]`, s);
|
|
2457
2468
|
}
|
|
2458
2469
|
/**
|
|
2459
2470
|
* Converts entry to the navigation entry.
|
|
@@ -2469,7 +2480,7 @@ class Jt {
|
|
|
2469
2480
|
search: c,
|
|
2470
2481
|
hash: u
|
|
2471
2482
|
} = e;
|
|
2472
|
-
t = a + (c ?
|
|
2483
|
+
t = a + (c ? B(c, "?") : "") + (u ? B(u, "#") : "");
|
|
2473
2484
|
}
|
|
2474
2485
|
const {
|
|
2475
2486
|
pathname: s,
|
|
@@ -2633,8 +2644,8 @@ class Jt {
|
|
|
2633
2644
|
return this.entry.search;
|
|
2634
2645
|
}
|
|
2635
2646
|
}
|
|
2636
|
-
const
|
|
2637
|
-
class Ve extends
|
|
2647
|
+
const ce = 0, J = 1, Q = 2;
|
|
2648
|
+
class Ve extends zt {
|
|
2638
2649
|
constructor(t, s, n = {}) {
|
|
2639
2650
|
super(t, s, {
|
|
2640
2651
|
...n,
|
|
@@ -2649,13 +2660,13 @@ class Ve extends Jt {
|
|
|
2649
2660
|
o(this, "onPopState", async ({ state: t }) => {
|
|
2650
2661
|
if (this.logger.log('"popstate" event received. State:', t), t === null)
|
|
2651
2662
|
return this.push(window.location.hash.slice(1));
|
|
2652
|
-
if (t ===
|
|
2663
|
+
if (t === ce) {
|
|
2653
2664
|
this.logger.log("Void reached. Moving history forward"), window.history.forward();
|
|
2654
2665
|
return;
|
|
2655
2666
|
}
|
|
2656
|
-
if (t ===
|
|
2667
|
+
if (t === J)
|
|
2657
2668
|
return this.back();
|
|
2658
|
-
if (t ===
|
|
2669
|
+
if (t === Q)
|
|
2659
2670
|
return this.forward();
|
|
2660
2671
|
});
|
|
2661
2672
|
o(this, "back", () => super.back());
|
|
@@ -2698,7 +2709,7 @@ class Ve extends Jt {
|
|
|
2698
2709
|
async syncHistory() {
|
|
2699
2710
|
window.removeEventListener("popstate", this.onPopState);
|
|
2700
2711
|
const t = `#${this.path}`;
|
|
2701
|
-
await
|
|
2712
|
+
await Ft(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(J, ""), window.history.pushState(null, "", t), window.history.pushState(Q, ""), await D(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(J, ""), window.history.pushState(null, "", t)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, t), window.history.pushState(Q, ""), await D(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ce, ""), window.history.pushState(null, "", t)), window.addEventListener("popstate", this.onPopState);
|
|
2702
2713
|
}
|
|
2703
2714
|
emitChanged(t, s) {
|
|
2704
2715
|
this.ee.emit("change", {
|
|
@@ -2712,19 +2723,20 @@ class Ve extends Jt {
|
|
|
2712
2723
|
*/
|
|
2713
2724
|
async attach() {
|
|
2714
2725
|
if (!this.attached)
|
|
2715
|
-
return this.logger.log("Attaching", this), this.attached = !0,
|
|
2726
|
+
return this.logger.log("Attaching", this), this.attached = !0, E("back_button_pressed", this.back), this.syncHistory();
|
|
2716
2727
|
}
|
|
2717
2728
|
/**
|
|
2718
2729
|
* Detaches current navigator from the browser history.
|
|
2719
2730
|
*/
|
|
2720
2731
|
detach() {
|
|
2721
|
-
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState),
|
|
2732
|
+
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), I("back_button_pressed", this.back));
|
|
2722
2733
|
}
|
|
2723
2734
|
}
|
|
2724
|
-
function
|
|
2725
|
-
return r instanceof
|
|
2735
|
+
function or(r) {
|
|
2736
|
+
return r instanceof F;
|
|
2726
2737
|
}
|
|
2727
2738
|
export {
|
|
2739
|
+
rt as BackButton,
|
|
2728
2740
|
st as ClosingBehavior,
|
|
2729
2741
|
at as CloudStorage,
|
|
2730
2742
|
ct as HapticFeedback,
|
|
@@ -2732,72 +2744,72 @@ export {
|
|
|
2732
2744
|
ut as InitData,
|
|
2733
2745
|
lt as Invoice,
|
|
2734
2746
|
dt as MainButton,
|
|
2735
|
-
|
|
2747
|
+
Z as MethodUnsupportedError,
|
|
2736
2748
|
wt as MiniApp,
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2749
|
+
zt as Navigator,
|
|
2750
|
+
K as ParameterUnsupportedError,
|
|
2751
|
+
G as ParseError,
|
|
2752
|
+
U as ParseSchemaFieldError,
|
|
2741
2753
|
bt as Popup,
|
|
2742
2754
|
mt as QRScanner,
|
|
2743
2755
|
yt as SettingsButton,
|
|
2744
2756
|
Pt as ThemeParams,
|
|
2745
|
-
|
|
2746
|
-
|
|
2757
|
+
F as TimeoutError,
|
|
2758
|
+
St as Utils,
|
|
2747
2759
|
xt as Viewport,
|
|
2748
2760
|
ot as array,
|
|
2749
2761
|
qt as bindMiniAppCSSVars,
|
|
2750
2762
|
At as bindThemeCSSVars,
|
|
2751
|
-
|
|
2752
|
-
|
|
2763
|
+
oe as bindViewportCSSVars,
|
|
2764
|
+
P as boolean,
|
|
2753
2765
|
ht as chatParser,
|
|
2754
|
-
|
|
2766
|
+
tt as classNames,
|
|
2755
2767
|
Be as compareVersions,
|
|
2756
|
-
|
|
2768
|
+
Oe as createPostEvent,
|
|
2757
2769
|
be as date,
|
|
2758
|
-
|
|
2759
|
-
|
|
2770
|
+
ir as getHash,
|
|
2771
|
+
rr as init,
|
|
2760
2772
|
me as initDataParser,
|
|
2761
|
-
|
|
2773
|
+
O as invokeCustomMethod,
|
|
2762
2774
|
_e as isColorDark,
|
|
2763
|
-
|
|
2775
|
+
pe as isIframe,
|
|
2764
2776
|
Ae as isPageReload,
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2777
|
+
X as isRGB,
|
|
2778
|
+
Je as isRGBShort,
|
|
2779
|
+
M as isRecord,
|
|
2780
|
+
kt as isStableViewportPlatform,
|
|
2781
|
+
nr as isTMA,
|
|
2782
|
+
or as isTimeoutError,
|
|
2771
2783
|
f as json,
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2784
|
+
Ht as launchParamsParser,
|
|
2785
|
+
Xt as mergeClassNames,
|
|
2786
|
+
x as number,
|
|
2787
|
+
I as off,
|
|
2788
|
+
E as on,
|
|
2789
|
+
Kt as once,
|
|
2790
|
+
er as parseInitData,
|
|
2791
|
+
Se as parseLaunchParams,
|
|
2792
|
+
De as parseMessage,
|
|
2781
2793
|
Ce as parseThemeParams,
|
|
2782
2794
|
d as postEvent,
|
|
2783
|
-
|
|
2784
|
-
|
|
2795
|
+
y as request,
|
|
2796
|
+
tr as requestThemeParams,
|
|
2785
2797
|
ve as requestViewport,
|
|
2786
|
-
|
|
2787
|
-
|
|
2798
|
+
sr as retrieveLaunchData,
|
|
2799
|
+
te as retrieveLaunchParams,
|
|
2788
2800
|
ge as rgb,
|
|
2789
|
-
|
|
2790
|
-
|
|
2801
|
+
ee as searchParams,
|
|
2802
|
+
Mt as serializeLaunchParams,
|
|
2791
2803
|
vt as serializeThemeParams,
|
|
2792
2804
|
S as setCSSVar,
|
|
2793
|
-
|
|
2794
|
-
|
|
2805
|
+
Qt as setDebug,
|
|
2806
|
+
Zt as setTargetOrigin,
|
|
2795
2807
|
h as string,
|
|
2796
|
-
|
|
2797
|
-
|
|
2808
|
+
Yt as subscribe,
|
|
2809
|
+
A as supports,
|
|
2798
2810
|
Ee as themeParamsParser,
|
|
2799
2811
|
fe as toRGB,
|
|
2800
|
-
|
|
2801
|
-
|
|
2812
|
+
et as unsubscribe,
|
|
2813
|
+
ie as userParser,
|
|
2802
2814
|
we as withTimeout
|
|
2803
2815
|
};
|