@tma.js/sdk 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (r,
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
6
|
-
this.prefix =
|
|
1
|
+
var It = Object.defineProperty;
|
|
2
|
+
var Tt = (r, t, e) => t in r ? It(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var o = (r, t, e) => (Tt(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
class ht {
|
|
5
|
+
constructor(t, e) {
|
|
6
|
+
this.prefix = t, this.enabled = e;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Prints message into a console in case, logger is currently enabled.
|
|
10
10
|
* @param level - log level.
|
|
11
11
|
* @param args - arguments.
|
|
12
12
|
*/
|
|
13
|
-
print(
|
|
13
|
+
print(t, ...e) {
|
|
14
14
|
if (!this.enabled)
|
|
15
15
|
return;
|
|
16
16
|
const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
|
|
@@ -20,7 +20,7 @@ class he {
|
|
|
20
20
|
fractionalSecondDigits: 3,
|
|
21
21
|
timeZone: "UTC"
|
|
22
22
|
}).format(s);
|
|
23
|
-
console[
|
|
23
|
+
console[t](`[${n}]`, this.prefix, ...e);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Disables the logger.
|
|
@@ -32,8 +32,8 @@ class he {
|
|
|
32
32
|
* Prints error message into a console.
|
|
33
33
|
* @param args
|
|
34
34
|
*/
|
|
35
|
-
error(...
|
|
36
|
-
this.print("error", ...
|
|
35
|
+
error(...t) {
|
|
36
|
+
this.print("error", ...t);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Enables the logger.
|
|
@@ -45,64 +45,64 @@ class he {
|
|
|
45
45
|
* Prints log message into a console.
|
|
46
46
|
* @param args
|
|
47
47
|
*/
|
|
48
|
-
log(...
|
|
49
|
-
this.print("log", ...
|
|
48
|
+
log(...t) {
|
|
49
|
+
this.print("log", ...t);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Prints warning message into a console.
|
|
53
53
|
* @param args
|
|
54
54
|
*/
|
|
55
|
-
warn(...
|
|
56
|
-
this.print("warn", ...
|
|
55
|
+
warn(...t) {
|
|
56
|
+
this.print("warn", ...t);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
let
|
|
60
|
-
const k = new
|
|
61
|
-
function
|
|
59
|
+
let ut = "https://web.telegram.org";
|
|
60
|
+
const k = new ht("[SDK]", !1);
|
|
61
|
+
function Qe(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 Ze(r) {
|
|
69
|
+
ut = r;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
71
|
+
function $t() {
|
|
72
|
+
return ut;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function pt() {
|
|
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 W(r) {
|
|
82
82
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return "external" in r &&
|
|
84
|
+
function Lt(r) {
|
|
85
|
+
return "external" in r && W(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return "TelegramWebviewProxy" in r &&
|
|
87
|
+
function Bt(r) {
|
|
88
|
+
return "TelegramWebviewProxy" in r && W(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
|
|
89
89
|
}
|
|
90
|
-
function d(r,
|
|
90
|
+
function d(r, t, e) {
|
|
91
91
|
let s = {}, n;
|
|
92
|
-
|
|
93
|
-
const { targetOrigin: i =
|
|
94
|
-
if (k.log(`Calling method "${r}"`, n),
|
|
92
|
+
t === void 0 && e === void 0 ? s = {} : t !== void 0 && e !== void 0 ? (s = e, n = t) : t !== void 0 && ("targetOrigin" in t ? s = t : n = t);
|
|
93
|
+
const { targetOrigin: i = $t() } = s;
|
|
94
|
+
if (k.log(`Calling method "${r}"`, n), pt()) {
|
|
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 (Lt(window)) {
|
|
102
102
|
window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
105
|
+
if (Bt(window)) {
|
|
106
106
|
window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
@@ -110,24 +110,24 @@ function d(r, e, t) {
|
|
|
110
110
|
"Unable to determine current environment and possible way to send event."
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
const
|
|
113
|
+
function Dt(r, t) {
|
|
114
|
+
const e = r.split("."), s = t.split("."), n = Math.max(e.length, s.length);
|
|
115
115
|
for (let i = 0; i < n; i += 1) {
|
|
116
|
-
const a = parseInt(
|
|
116
|
+
const a = parseInt(e[i] || "0", 10), c = parseInt(s[i] || "0", 10);
|
|
117
117
|
if (a !== c)
|
|
118
118
|
return a > c ? 1 : -1;
|
|
119
119
|
}
|
|
120
120
|
return 0;
|
|
121
121
|
}
|
|
122
|
-
function v(r,
|
|
123
|
-
return
|
|
122
|
+
function v(r, t) {
|
|
123
|
+
return Dt(r, t) <= 0;
|
|
124
124
|
}
|
|
125
|
-
function A(r,
|
|
126
|
-
if (typeof
|
|
127
|
-
if (r === "web_app_open_link" &&
|
|
128
|
-
return v("6.4",
|
|
129
|
-
if (r === "web_app_set_header_color" &&
|
|
130
|
-
return v("6.9",
|
|
125
|
+
function A(r, t, e) {
|
|
126
|
+
if (typeof e == "string") {
|
|
127
|
+
if (r === "web_app_open_link" && t === "try_instant_view")
|
|
128
|
+
return v("6.4", e);
|
|
129
|
+
if (r === "web_app_set_header_color" && t === "color")
|
|
130
|
+
return v("6.9", e);
|
|
131
131
|
}
|
|
132
132
|
switch (r) {
|
|
133
133
|
case "web_app_open_tg_link":
|
|
@@ -136,67 +136,67 @@ function A(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 v("6.1",
|
|
139
|
+
return v("6.1", t);
|
|
140
140
|
case "web_app_open_popup":
|
|
141
|
-
return v("6.2",
|
|
141
|
+
return v("6.2", t);
|
|
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 v("6.4",
|
|
145
|
+
return v("6.4", t);
|
|
146
146
|
case "web_app_switch_inline_query":
|
|
147
|
-
return v("6.7",
|
|
147
|
+
return v("6.7", t);
|
|
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 v("6.9",
|
|
151
|
+
return v("6.9", t);
|
|
152
152
|
case "web_app_setup_settings_button":
|
|
153
|
-
return v("6.10",
|
|
153
|
+
return v("6.10", t);
|
|
154
154
|
default:
|
|
155
155
|
return !0;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
class
|
|
159
|
-
constructor(
|
|
160
|
-
super(`Method "${
|
|
158
|
+
class K extends Error {
|
|
159
|
+
constructor(t, e) {
|
|
160
|
+
super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, K.prototype);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
class
|
|
164
|
-
constructor(
|
|
165
|
-
super(`Parameter "${
|
|
163
|
+
class Y extends Error {
|
|
164
|
+
constructor(t, e, s) {
|
|
165
|
+
super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, Y.prototype);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
return (
|
|
170
|
-
if (!A(
|
|
171
|
-
throw new
|
|
172
|
-
if (
|
|
168
|
+
function Ot(r) {
|
|
169
|
+
return (t, e) => {
|
|
170
|
+
if (!A(t, r))
|
|
171
|
+
throw new K(t, r);
|
|
172
|
+
if (W(e)) {
|
|
173
173
|
let s;
|
|
174
|
-
if (
|
|
175
|
-
throw new
|
|
174
|
+
if (t === "web_app_open_link" && "try_instant_view" in e ? s = "try_instant_view" : t === "web_app_set_header_color" && "color" in e && (s = "color"), s && !A(t, s, r))
|
|
175
|
+
throw new Y(t, s, r);
|
|
176
176
|
}
|
|
177
|
-
return d(
|
|
177
|
+
return d(t, e);
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function
|
|
181
|
-
return ({ req_id:
|
|
180
|
+
function lt(r) {
|
|
181
|
+
return ({ req_id: t }) => t === r;
|
|
182
182
|
}
|
|
183
|
-
class
|
|
184
|
-
constructor(
|
|
183
|
+
class j extends Error {
|
|
184
|
+
constructor(e, { cause: s, type: n } = {}) {
|
|
185
185
|
super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
|
|
186
186
|
/**
|
|
187
187
|
* Parser name.
|
|
188
188
|
*/
|
|
189
189
|
o(this, "type");
|
|
190
|
-
this.value =
|
|
190
|
+
this.value = e, Object.setPrototypeOf(this, j.prototype), this.type = n;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
class
|
|
194
|
-
constructor(
|
|
195
|
-
super(`Unable to parse field "${
|
|
193
|
+
class G extends Error {
|
|
194
|
+
constructor(t, { cause: e, type: s } = {}) {
|
|
195
|
+
super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, G.prototype);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
const
|
|
198
|
+
function dt(r, t) {
|
|
199
|
+
const e = {};
|
|
200
200
|
for (const s in r) {
|
|
201
201
|
const n = r[s];
|
|
202
202
|
if (!n)
|
|
@@ -209,72 +209,72 @@ function de(r, e) {
|
|
|
209
209
|
i = n.from || s, a = typeof p == "function" ? p : p.parse.bind(p);
|
|
210
210
|
}
|
|
211
211
|
let c;
|
|
212
|
-
const u =
|
|
212
|
+
const u = t(i);
|
|
213
213
|
try {
|
|
214
214
|
c = a(u);
|
|
215
215
|
} catch (p) {
|
|
216
|
-
throw p instanceof
|
|
216
|
+
throw p instanceof j ? new G(i, {
|
|
217
217
|
type: p.type,
|
|
218
218
|
cause: p
|
|
219
|
-
}) : new
|
|
219
|
+
}) : new G(i, { cause: p });
|
|
220
220
|
}
|
|
221
|
-
c !== void 0 && (
|
|
221
|
+
c !== void 0 && (e[s] = c);
|
|
222
222
|
}
|
|
223
|
-
return
|
|
223
|
+
return e;
|
|
224
224
|
}
|
|
225
225
|
function V() {
|
|
226
226
|
return new TypeError("Value has unexpected type");
|
|
227
227
|
}
|
|
228
|
-
function
|
|
229
|
-
let
|
|
230
|
-
if (typeof
|
|
228
|
+
function X(r) {
|
|
229
|
+
let t = r;
|
|
230
|
+
if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
|
|
231
231
|
throw V();
|
|
232
|
-
return
|
|
232
|
+
return t;
|
|
233
233
|
}
|
|
234
|
-
class
|
|
235
|
-
constructor(
|
|
236
|
-
this.parser =
|
|
234
|
+
class F {
|
|
235
|
+
constructor(t, e, s) {
|
|
236
|
+
this.parser = t, this.isOptional = e, this.type = s;
|
|
237
237
|
}
|
|
238
|
-
parse(
|
|
239
|
-
if (!(this.isOptional &&
|
|
238
|
+
parse(t) {
|
|
239
|
+
if (!(this.isOptional && t === void 0))
|
|
240
240
|
try {
|
|
241
|
-
return this.parser(
|
|
242
|
-
} catch (
|
|
243
|
-
throw new
|
|
241
|
+
return this.parser(t);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
throw new j(t, { type: this.type, cause: e });
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
optional() {
|
|
247
247
|
return this.isOptional = !0, this;
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
function f(r,
|
|
251
|
-
return new
|
|
252
|
-
const s =
|
|
253
|
-
return
|
|
254
|
-
}, !1,
|
|
250
|
+
function f(r, t) {
|
|
251
|
+
return new F((e) => {
|
|
252
|
+
const s = X(e);
|
|
253
|
+
return dt(r, (n) => s[n]);
|
|
254
|
+
}, !1, t);
|
|
255
255
|
}
|
|
256
|
-
function R(r,
|
|
257
|
-
return () => new
|
|
256
|
+
function R(r, t) {
|
|
257
|
+
return () => new F(r, !1, t);
|
|
258
258
|
}
|
|
259
259
|
const h = R((r) => {
|
|
260
260
|
if (typeof r == "string" || typeof r == "number")
|
|
261
261
|
return r.toString();
|
|
262
262
|
throw V();
|
|
263
263
|
}, "string");
|
|
264
|
-
function
|
|
264
|
+
function Wt(r) {
|
|
265
265
|
return f({
|
|
266
266
|
eventType: h(),
|
|
267
|
-
eventData: (
|
|
267
|
+
eventData: (t) => t
|
|
268
268
|
}).parse(r);
|
|
269
269
|
}
|
|
270
|
-
function
|
|
270
|
+
function Ht(r, t) {
|
|
271
271
|
window.dispatchEvent(new MessageEvent("message", {
|
|
272
|
-
data: JSON.stringify({ eventType: r, eventData:
|
|
272
|
+
data: JSON.stringify({ eventType: r, eventData: t }),
|
|
273
273
|
// We specify window.parent to imitate the case, it sent us this event.
|
|
274
274
|
source: window.parent
|
|
275
275
|
}));
|
|
276
276
|
}
|
|
277
|
-
function
|
|
277
|
+
function Nt() {
|
|
278
278
|
const r = window;
|
|
279
279
|
"TelegramGameProxy_receiveEvent" in r || [
|
|
280
280
|
["TelegramGameProxy_receiveEvent"],
|
|
@@ -283,112 +283,112 @@ function He() {
|
|
|
283
283
|
// Desktop.
|
|
284
284
|
["Telegram", "WebView", "receiveEvent"]
|
|
285
285
|
// Android and iOS.
|
|
286
|
-
].forEach((
|
|
287
|
-
let
|
|
288
|
-
|
|
286
|
+
].forEach((t) => {
|
|
287
|
+
let e = r;
|
|
288
|
+
t.forEach((s, n, i) => {
|
|
289
289
|
if (n === i.length - 1) {
|
|
290
|
-
|
|
290
|
+
e[s] = Ht;
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
293
|
-
s in
|
|
293
|
+
s in e || (e[s] = {}), e = e[s];
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
-
function
|
|
298
|
-
|
|
299
|
-
if (
|
|
297
|
+
function Ut(r) {
|
|
298
|
+
Nt(), window.addEventListener("message", (t) => {
|
|
299
|
+
if (t.source === window.parent)
|
|
300
300
|
try {
|
|
301
|
-
const { eventType:
|
|
302
|
-
r(
|
|
301
|
+
const { eventType: e, eventData: s } = Wt(t.data);
|
|
302
|
+
r(e, s);
|
|
303
303
|
} catch {
|
|
304
304
|
}
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function Mt() {
|
|
308
308
|
return f({
|
|
309
309
|
req_id: h(),
|
|
310
310
|
data: (r) => r === null ? r : h().optional().parse(r)
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function Gt() {
|
|
314
314
|
return f({
|
|
315
315
|
req_id: h(),
|
|
316
316
|
result: (r) => r,
|
|
317
317
|
error: h().optional()
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function jt() {
|
|
321
321
|
return f({
|
|
322
322
|
slug: h(),
|
|
323
323
|
status: h()
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function Ft() {
|
|
327
327
|
return f({ status: h() });
|
|
328
328
|
}
|
|
329
|
-
function
|
|
329
|
+
function zt() {
|
|
330
330
|
return f({
|
|
331
331
|
button_id: (r) => r == null ? void 0 : h().parse(r)
|
|
332
332
|
});
|
|
333
333
|
}
|
|
334
|
-
function
|
|
334
|
+
function Jt() {
|
|
335
335
|
return f({
|
|
336
336
|
data: h().optional()
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
|
-
function
|
|
339
|
+
function tt(r) {
|
|
340
340
|
return /^#[\da-f]{6}$/i.test(r);
|
|
341
341
|
}
|
|
342
|
-
function
|
|
342
|
+
function Qt(r) {
|
|
343
343
|
return /^#[\da-f]{3}$/i.test(r);
|
|
344
344
|
}
|
|
345
|
-
function
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
349
|
-
if (
|
|
345
|
+
function ft(r) {
|
|
346
|
+
const t = r.replace(/\s/g, "").toLowerCase();
|
|
347
|
+
if (tt(t))
|
|
348
|
+
return t;
|
|
349
|
+
if (Qt(t)) {
|
|
350
350
|
let s = "#";
|
|
351
351
|
for (let n = 0; n < 3; n += 1)
|
|
352
|
-
s +=
|
|
352
|
+
s += t[1 + n].repeat(2);
|
|
353
353
|
return s;
|
|
354
354
|
}
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
355
|
+
const e = t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
|
|
356
|
+
if (e === null)
|
|
357
357
|
throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
|
|
358
|
-
return
|
|
358
|
+
return e.slice(1).reduce((s, n) => {
|
|
359
359
|
const i = parseInt(n, 10).toString(16);
|
|
360
360
|
return s + (i.length === 1 ? "0" : "") + i;
|
|
361
361
|
}, "#");
|
|
362
362
|
}
|
|
363
|
-
const
|
|
364
|
-
function
|
|
363
|
+
const gt = R((r) => ft(h().parse(r)), "rgb");
|
|
364
|
+
function Zt() {
|
|
365
365
|
return f({
|
|
366
366
|
theme_params: (r) => {
|
|
367
|
-
const
|
|
368
|
-
return Object.entries(
|
|
367
|
+
const t = gt().optional();
|
|
368
|
+
return Object.entries(X(r)).reduce((e, [s, n]) => (e[s] = t.parse(n), e), {});
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
372
|
const P = R((r) => {
|
|
373
373
|
if (typeof r == "boolean")
|
|
374
374
|
return r;
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
375
|
+
const t = String(r);
|
|
376
|
+
if (t === "1" || t === "true")
|
|
377
377
|
return !0;
|
|
378
|
-
if (
|
|
378
|
+
if (t === "0" || t === "false")
|
|
379
379
|
return !1;
|
|
380
380
|
throw V();
|
|
381
381
|
}, "boolean"), x = R((r) => {
|
|
382
382
|
if (typeof r == "number")
|
|
383
383
|
return r;
|
|
384
384
|
if (typeof r == "string") {
|
|
385
|
-
const
|
|
386
|
-
if (!Number.isNaN(
|
|
387
|
-
return
|
|
385
|
+
const t = Number(r);
|
|
386
|
+
if (!Number.isNaN(t))
|
|
387
|
+
return t;
|
|
388
388
|
}
|
|
389
389
|
throw V();
|
|
390
390
|
}, "number");
|
|
391
|
-
function
|
|
391
|
+
function Kt() {
|
|
392
392
|
return f({
|
|
393
393
|
height: x(),
|
|
394
394
|
width: (r) => r == null ? window.innerWidth : x().parse(r),
|
|
@@ -396,7 +396,7 @@ function Ze() {
|
|
|
396
396
|
is_expanded: P()
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
|
-
function
|
|
399
|
+
function Yt() {
|
|
400
400
|
return f({ status: h() });
|
|
401
401
|
}
|
|
402
402
|
class w {
|
|
@@ -410,15 +410,15 @@ class w {
|
|
|
410
410
|
* @param listener - event listener.
|
|
411
411
|
* @param once - should listener called only once.
|
|
412
412
|
*/
|
|
413
|
-
addListener(
|
|
414
|
-
let n = this.listeners.get(
|
|
415
|
-
return n || (n = [], this.listeners.set(
|
|
413
|
+
addListener(t, e, s) {
|
|
414
|
+
let n = this.listeners.get(t);
|
|
415
|
+
return n || (n = [], this.listeners.set(t, n)), n.push([e, s]), () => this.off(t, e);
|
|
416
416
|
}
|
|
417
|
-
emit(
|
|
418
|
-
this.subscribeListeners.forEach((n) => n(
|
|
419
|
-
const s = this.listeners.get(
|
|
417
|
+
emit(t, ...e) {
|
|
418
|
+
this.subscribeListeners.forEach((n) => n(t, ...e));
|
|
419
|
+
const s = this.listeners.get(t);
|
|
420
420
|
s && s.forEach(([n, i], a) => {
|
|
421
|
-
n(...
|
|
421
|
+
n(...e), i && s.splice(a, 1);
|
|
422
422
|
});
|
|
423
423
|
}
|
|
424
424
|
/**
|
|
@@ -427,8 +427,8 @@ class w {
|
|
|
427
427
|
* @param listener - event listener.
|
|
428
428
|
* @returns Function to remove event listener.
|
|
429
429
|
*/
|
|
430
|
-
on(
|
|
431
|
-
return this.addListener(
|
|
430
|
+
on(t, e) {
|
|
431
|
+
return this.addListener(t, e, !1);
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
434
434
|
* Adds event listener following the logic, described in `on` method, but calls specified
|
|
@@ -438,8 +438,8 @@ class w {
|
|
|
438
438
|
* @returns Function to remove event listener.
|
|
439
439
|
* @see on
|
|
440
440
|
*/
|
|
441
|
-
once(
|
|
442
|
-
return this.addListener(
|
|
441
|
+
once(t, e) {
|
|
442
|
+
return this.addListener(t, e, !0);
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
445
445
|
* Removes event listener. In case, specified listener was bound several times, it removes
|
|
@@ -447,11 +447,11 @@ class w {
|
|
|
447
447
|
* @param event - event name.
|
|
448
448
|
* @param listener - event listener.
|
|
449
449
|
*/
|
|
450
|
-
off(
|
|
451
|
-
const s = this.listeners.get(
|
|
450
|
+
off(t, e) {
|
|
451
|
+
const s = this.listeners.get(t);
|
|
452
452
|
if (s) {
|
|
453
453
|
for (let n = 0; n < s.length; n += 1)
|
|
454
|
-
if (
|
|
454
|
+
if (e === s[n][0]) {
|
|
455
455
|
s.splice(n, 1);
|
|
456
456
|
return;
|
|
457
457
|
}
|
|
@@ -464,8 +464,8 @@ class w {
|
|
|
464
464
|
* @see on
|
|
465
465
|
* @see once
|
|
466
466
|
*/
|
|
467
|
-
subscribe(
|
|
468
|
-
return this.subscribeListeners.push(
|
|
467
|
+
subscribe(t) {
|
|
468
|
+
return this.subscribeListeners.push(t), () => this.unsubscribe(t);
|
|
469
469
|
}
|
|
470
470
|
/**
|
|
471
471
|
* Removes global event listener. In case, specified listener was bound several times, it removes
|
|
@@ -473,100 +473,100 @@ class w {
|
|
|
473
473
|
* @param listener - events listener.
|
|
474
474
|
* @returns Function to remove event listener.
|
|
475
475
|
*/
|
|
476
|
-
unsubscribe(
|
|
477
|
-
for (let
|
|
478
|
-
if (this.subscribeListeners[
|
|
479
|
-
this.subscribeListeners.splice(
|
|
476
|
+
unsubscribe(t) {
|
|
477
|
+
for (let e = 0; e < this.subscribeListeners.length; e += 1)
|
|
478
|
+
if (this.subscribeListeners[e] === t) {
|
|
479
|
+
this.subscribeListeners.splice(e, 1);
|
|
480
480
|
return;
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
const r = new w(),
|
|
486
|
-
k.log("Emitting processed event:",
|
|
484
|
+
function Xt() {
|
|
485
|
+
const r = new w(), t = (e, ...s) => {
|
|
486
|
+
k.log("Emitting processed event:", e, ...s), r.emit(e, ...s);
|
|
487
487
|
};
|
|
488
488
|
return window.addEventListener("resize", () => {
|
|
489
|
-
|
|
489
|
+
t("viewport_changed", {
|
|
490
490
|
width: window.innerWidth,
|
|
491
491
|
height: window.innerHeight,
|
|
492
492
|
is_state_stable: !0,
|
|
493
493
|
is_expanded: !0
|
|
494
494
|
});
|
|
495
|
-
}),
|
|
496
|
-
k.log("Received raw event:",
|
|
495
|
+
}), Ut((e, s) => {
|
|
496
|
+
k.log("Received raw event:", e, s);
|
|
497
497
|
try {
|
|
498
|
-
switch (
|
|
498
|
+
switch (e) {
|
|
499
499
|
case "viewport_changed":
|
|
500
|
-
return e
|
|
500
|
+
return t(e, Kt().parse(s));
|
|
501
501
|
case "theme_changed":
|
|
502
|
-
return e
|
|
502
|
+
return t(e, Zt().parse(s));
|
|
503
503
|
case "popup_closed":
|
|
504
504
|
return (
|
|
505
505
|
// Sent on desktop.
|
|
506
|
-
s == null ? e
|
|
506
|
+
s == null ? t(e, {}) : t(e, zt().parse(s))
|
|
507
507
|
);
|
|
508
508
|
case "set_custom_style":
|
|
509
|
-
return e
|
|
509
|
+
return t(e, h().parse(s));
|
|
510
510
|
case "qr_text_received":
|
|
511
|
-
return e
|
|
511
|
+
return t(e, Jt().parse(s));
|
|
512
512
|
case "clipboard_text_received":
|
|
513
|
-
return e
|
|
513
|
+
return t(e, Mt().parse(s));
|
|
514
514
|
case "invoice_closed":
|
|
515
|
-
return e
|
|
515
|
+
return t(e, jt().parse(s));
|
|
516
516
|
case "phone_requested":
|
|
517
|
-
return
|
|
517
|
+
return t("phone_requested", Ft().parse(s));
|
|
518
518
|
case "custom_method_invoked":
|
|
519
|
-
return
|
|
519
|
+
return t("custom_method_invoked", Gt().parse(s));
|
|
520
520
|
case "write_access_requested":
|
|
521
|
-
return
|
|
521
|
+
return t("write_access_requested", Yt().parse(s));
|
|
522
522
|
case "main_button_pressed":
|
|
523
523
|
case "back_button_pressed":
|
|
524
524
|
case "settings_button_pressed":
|
|
525
525
|
case "scan_qr_popup_closed":
|
|
526
526
|
case "reload_iframe":
|
|
527
|
-
return e
|
|
527
|
+
return t(e);
|
|
528
528
|
default:
|
|
529
|
-
return e
|
|
529
|
+
return t(e, s);
|
|
530
530
|
}
|
|
531
531
|
} catch (n) {
|
|
532
532
|
k.error("Error processing event:", n);
|
|
533
533
|
}
|
|
534
534
|
}), r;
|
|
535
535
|
}
|
|
536
|
-
const
|
|
537
|
-
function
|
|
536
|
+
const J = "telegram-mini-apps-cached-emitter";
|
|
537
|
+
function H() {
|
|
538
538
|
const r = window;
|
|
539
|
-
return r[
|
|
539
|
+
return r[J] === void 0 && (r[J] = Xt()), r[J];
|
|
540
540
|
}
|
|
541
|
-
function I(r,
|
|
542
|
-
|
|
541
|
+
function I(r, t) {
|
|
542
|
+
H().off(r, t);
|
|
543
543
|
}
|
|
544
|
-
function E(r,
|
|
545
|
-
return
|
|
544
|
+
function E(r, t) {
|
|
545
|
+
return H().on(r, t), () => I(r, t);
|
|
546
546
|
}
|
|
547
|
-
class
|
|
548
|
-
constructor(
|
|
549
|
-
super(`Async call timeout exceeded. Timeout: ${
|
|
547
|
+
class z extends Error {
|
|
548
|
+
constructor(t) {
|
|
549
|
+
super(`Async call timeout exceeded. Timeout: ${t}`), Object.setPrototypeOf(this, z.prototype);
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
function
|
|
553
|
-
return new Promise((
|
|
554
|
-
setTimeout(
|
|
552
|
+
function te(r) {
|
|
553
|
+
return new Promise((t, e) => {
|
|
554
|
+
setTimeout(e, r, new z(r));
|
|
555
555
|
});
|
|
556
556
|
}
|
|
557
|
-
function
|
|
557
|
+
function wt(r, t) {
|
|
558
558
|
return Promise.race([
|
|
559
559
|
typeof r == "function" ? r() : r,
|
|
560
|
-
|
|
560
|
+
te(t)
|
|
561
561
|
]);
|
|
562
562
|
}
|
|
563
|
-
async function y(r,
|
|
563
|
+
async function y(r, t, e) {
|
|
564
564
|
let s;
|
|
565
565
|
const n = new Promise((b) => {
|
|
566
566
|
s = b;
|
|
567
|
-
}), i =
|
|
568
|
-
...
|
|
569
|
-
event:
|
|
567
|
+
}), i = t ? {
|
|
568
|
+
...e,
|
|
569
|
+
event: t,
|
|
570
570
|
method: r
|
|
571
571
|
} : r, {
|
|
572
572
|
method: a,
|
|
@@ -578,12 +578,12 @@ async function y(r, e, t) {
|
|
|
578
578
|
(b) => E(b, (l) => (!u || u(l)) && s(l))
|
|
579
579
|
);
|
|
580
580
|
try {
|
|
581
|
-
return p(a, i.params), await (g ?
|
|
581
|
+
return p(a, i.params), await (g ? wt(n, g) : n);
|
|
582
582
|
} finally {
|
|
583
583
|
_.forEach((b) => b());
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
-
async function
|
|
586
|
+
async function D(r, t, e, s = {}) {
|
|
587
587
|
const {
|
|
588
588
|
result: n,
|
|
589
589
|
error: i
|
|
@@ -591,54 +591,51 @@ async function O(r, e, t, s = {}) {
|
|
|
591
591
|
...s,
|
|
592
592
|
params: {
|
|
593
593
|
method: r,
|
|
594
|
-
params:
|
|
595
|
-
req_id:
|
|
594
|
+
params: t,
|
|
595
|
+
req_id: e
|
|
596
596
|
},
|
|
597
|
-
capture:
|
|
597
|
+
capture: lt(e)
|
|
598
598
|
});
|
|
599
599
|
if (i)
|
|
600
600
|
throw new Error(i);
|
|
601
601
|
return n;
|
|
602
602
|
}
|
|
603
|
-
function
|
|
604
|
-
return
|
|
603
|
+
function Ke(r, t) {
|
|
604
|
+
return H().once(r, t), () => I(r, t);
|
|
605
605
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
606
|
+
function ee(r) {
|
|
607
|
+
H().unsubscribe(r);
|
|
608
608
|
}
|
|
609
|
-
function
|
|
610
|
-
return
|
|
609
|
+
function Ye(r) {
|
|
610
|
+
return H().subscribe(r), () => ee(r);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
return r + (r.length
|
|
612
|
+
function U(r, t) {
|
|
613
|
+
return r + (r.length && t.length ? ` ${t}` : t);
|
|
614
614
|
}
|
|
615
|
-
function
|
|
616
|
-
return r.reduce((e, t) =>
|
|
617
|
-
let s = "";
|
|
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);
|
|
619
|
-
}, "");
|
|
615
|
+
function _t(...r) {
|
|
616
|
+
return r.reduce((t, e) => typeof e == "string" ? U(t, e) : W(e) ? U(t, Object.entries(e).reduce((s, n) => n[1] ? U(s, n[0]) : s, "")) : Array.isArray(e) ? U(t, _t(...e)) : t, "");
|
|
620
617
|
}
|
|
621
|
-
function
|
|
622
|
-
return r.reduce((
|
|
623
|
-
const i =
|
|
624
|
-
i.length > 0 && (
|
|
625
|
-
}),
|
|
618
|
+
function Xe(...r) {
|
|
619
|
+
return r.reduce((t, e) => (W(e) && Object.entries(e).forEach(([s, n]) => {
|
|
620
|
+
const i = _t(t[s], n);
|
|
621
|
+
i.length > 0 && (t[s] = i);
|
|
622
|
+
}), t), {});
|
|
626
623
|
}
|
|
627
|
-
function
|
|
628
|
-
const
|
|
624
|
+
function bt(r) {
|
|
625
|
+
const t = ft(r);
|
|
629
626
|
return Math.sqrt(
|
|
630
627
|
[0.299, 0.587, 0.114].reduce((s, n, i) => {
|
|
631
|
-
const a = parseInt(
|
|
628
|
+
const a = parseInt(t.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
|
|
632
629
|
return s + a * a * n;
|
|
633
630
|
}, 0)
|
|
634
631
|
) < 120;
|
|
635
632
|
}
|
|
636
633
|
class m {
|
|
637
|
-
constructor(
|
|
638
|
-
this.state =
|
|
634
|
+
constructor(t, e) {
|
|
635
|
+
this.state = t, this.ee = e;
|
|
639
636
|
}
|
|
640
|
-
internalSet(
|
|
641
|
-
return this.state[
|
|
637
|
+
internalSet(t, e) {
|
|
638
|
+
return this.state[t] === e || e === void 0 ? !1 : (this.state[t] = e, this.ee.emit(`change:${t}`, e), !0);
|
|
642
639
|
}
|
|
643
640
|
/**
|
|
644
641
|
* Returns copy of current state.
|
|
@@ -646,28 +643,28 @@ class m {
|
|
|
646
643
|
clone() {
|
|
647
644
|
return { ...this.state };
|
|
648
645
|
}
|
|
649
|
-
set(
|
|
646
|
+
set(t, e) {
|
|
650
647
|
let s = !1;
|
|
651
|
-
if (typeof
|
|
652
|
-
s = this.internalSet(
|
|
648
|
+
if (typeof t == "string")
|
|
649
|
+
s = this.internalSet(t, e);
|
|
653
650
|
else
|
|
654
|
-
for (const n in
|
|
655
|
-
this.internalSet(n,
|
|
651
|
+
for (const n in t)
|
|
652
|
+
this.internalSet(n, t[n]) && (s = !0);
|
|
656
653
|
s && this.ee.emit("change");
|
|
657
654
|
}
|
|
658
655
|
/**
|
|
659
656
|
* Returns value by specified key.
|
|
660
657
|
* @param key - state key.
|
|
661
658
|
*/
|
|
662
|
-
get(
|
|
663
|
-
return this.state[
|
|
659
|
+
get(t) {
|
|
660
|
+
return this.state[t];
|
|
664
661
|
}
|
|
665
662
|
}
|
|
666
|
-
function C(r,
|
|
667
|
-
return (
|
|
663
|
+
function C(r, t) {
|
|
664
|
+
return (e) => A(t[e], r);
|
|
668
665
|
}
|
|
669
|
-
class
|
|
670
|
-
constructor(
|
|
666
|
+
class re {
|
|
667
|
+
constructor(t, e, s = d) {
|
|
671
668
|
o(this, "ee", new w());
|
|
672
669
|
o(this, "state");
|
|
673
670
|
/**
|
|
@@ -675,24 +672,24 @@ class rt {
|
|
|
675
672
|
* @param event - event name.
|
|
676
673
|
* @param listener - event listener.
|
|
677
674
|
*/
|
|
678
|
-
o(this, "on", (
|
|
675
|
+
o(this, "on", (t, e) => t === "click" ? E("back_button_pressed", e) : this.ee.on(t, e));
|
|
679
676
|
/**
|
|
680
677
|
* Removes event listener.
|
|
681
678
|
* @param event - event name.
|
|
682
679
|
* @param listener - event listener.
|
|
683
680
|
*/
|
|
684
|
-
o(this, "off", (
|
|
681
|
+
o(this, "off", (t, e) => t === "click" ? I("back_button_pressed", e) : this.ee.off(t, e));
|
|
685
682
|
/**
|
|
686
683
|
* Checks if specified method is supported by current component.
|
|
687
684
|
*/
|
|
688
685
|
o(this, "supports");
|
|
689
|
-
this.postEvent = s, this.state = new m({ isVisible:
|
|
686
|
+
this.postEvent = s, this.state = new m({ isVisible: t }, this.ee), this.supports = C(e, {
|
|
690
687
|
show: "web_app_setup_back_button",
|
|
691
688
|
hide: "web_app_setup_back_button"
|
|
692
689
|
});
|
|
693
690
|
}
|
|
694
|
-
set isVisible(
|
|
695
|
-
this.state.set("isVisible",
|
|
691
|
+
set isVisible(t) {
|
|
692
|
+
this.state.set("isVisible", t), this.postEvent("web_app_setup_back_button", { is_visible: t });
|
|
696
693
|
}
|
|
697
694
|
/**
|
|
698
695
|
* True if BackButton is currently visible.
|
|
@@ -713,8 +710,8 @@ class rt {
|
|
|
713
710
|
this.isVisible = !0;
|
|
714
711
|
}
|
|
715
712
|
}
|
|
716
|
-
class
|
|
717
|
-
constructor(
|
|
713
|
+
class se {
|
|
714
|
+
constructor(t, e = d) {
|
|
718
715
|
o(this, "ee", new w());
|
|
719
716
|
o(this, "state");
|
|
720
717
|
/**
|
|
@@ -725,10 +722,10 @@ class st {
|
|
|
725
722
|
* Removes event listener.
|
|
726
723
|
*/
|
|
727
724
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
728
|
-
this.postEvent =
|
|
725
|
+
this.postEvent = e, this.state = new m({ isConfirmationNeeded: t }, this.ee);
|
|
729
726
|
}
|
|
730
|
-
set isConfirmationNeeded(
|
|
731
|
-
this.state.set("isConfirmationNeeded",
|
|
727
|
+
set isConfirmationNeeded(t) {
|
|
728
|
+
this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
|
|
732
729
|
}
|
|
733
730
|
/**
|
|
734
731
|
* Returns true, if the confirmation dialog enabled while the user is trying
|
|
@@ -752,45 +749,45 @@ class st {
|
|
|
752
749
|
this.isConfirmationNeeded = !0;
|
|
753
750
|
}
|
|
754
751
|
}
|
|
755
|
-
function
|
|
752
|
+
function ne(r) {
|
|
756
753
|
if (Array.isArray(r))
|
|
757
754
|
return r;
|
|
758
755
|
if (typeof r == "string")
|
|
759
756
|
try {
|
|
760
|
-
const
|
|
761
|
-
if (Array.isArray(
|
|
762
|
-
return
|
|
757
|
+
const t = JSON.parse(r);
|
|
758
|
+
if (Array.isArray(t))
|
|
759
|
+
return t;
|
|
763
760
|
} catch {
|
|
764
761
|
}
|
|
765
762
|
throw V();
|
|
766
763
|
}
|
|
767
|
-
class
|
|
768
|
-
constructor(
|
|
769
|
-
super(
|
|
764
|
+
class ie extends F {
|
|
765
|
+
constructor(e, s, n) {
|
|
766
|
+
super(ne, s, n);
|
|
770
767
|
o(this, "itemParser");
|
|
771
|
-
this.itemParser = typeof
|
|
768
|
+
this.itemParser = typeof e == "function" ? e : e.parse.bind(e);
|
|
772
769
|
}
|
|
773
|
-
parse(
|
|
774
|
-
const s = super.parse(
|
|
770
|
+
parse(e) {
|
|
771
|
+
const s = super.parse(e);
|
|
775
772
|
return s === void 0 ? s : s.map(this.itemParser);
|
|
776
773
|
}
|
|
777
|
-
of(
|
|
778
|
-
return this.itemParser = typeof
|
|
774
|
+
of(e) {
|
|
775
|
+
return this.itemParser = typeof e == "function" ? e : e.parse.bind(e), this;
|
|
779
776
|
}
|
|
780
777
|
}
|
|
781
|
-
function
|
|
782
|
-
return new
|
|
778
|
+
function oe(r) {
|
|
779
|
+
return new ie((t) => t, !1, r);
|
|
783
780
|
}
|
|
784
|
-
function
|
|
785
|
-
return r.reduce((
|
|
781
|
+
function nt(r, t) {
|
|
782
|
+
return r.reduce((e, s) => (e[s] = t, e), {});
|
|
786
783
|
}
|
|
787
|
-
class
|
|
788
|
-
constructor(
|
|
784
|
+
class ae {
|
|
785
|
+
constructor(t, e, s = d) {
|
|
789
786
|
/**
|
|
790
787
|
* Checks if specified method is supported by current component.
|
|
791
788
|
*/
|
|
792
789
|
o(this, "supports");
|
|
793
|
-
this.createRequestId =
|
|
790
|
+
this.createRequestId = e, this.postEvent = s, this.supports = C(t, {
|
|
794
791
|
delete: "web_app_invoke_custom_method",
|
|
795
792
|
get: "web_app_invoke_custom_method",
|
|
796
793
|
getKeys: "web_app_invoke_custom_method",
|
|
@@ -802,41 +799,41 @@ class at {
|
|
|
802
799
|
* @param keyOrKeys - key or keys to delete.
|
|
803
800
|
* @param options - request execution options.
|
|
804
801
|
*/
|
|
805
|
-
async delete(
|
|
806
|
-
const s = Array.isArray(
|
|
807
|
-
s.length !== 0 && await
|
|
802
|
+
async delete(t, e = {}) {
|
|
803
|
+
const s = Array.isArray(t) ? t : [t];
|
|
804
|
+
s.length !== 0 && await D(
|
|
808
805
|
"deleteStorageValues",
|
|
809
806
|
{ keys: s },
|
|
810
807
|
this.createRequestId(),
|
|
811
|
-
{ ...
|
|
808
|
+
{ ...e, postEvent: this.postEvent }
|
|
812
809
|
);
|
|
813
810
|
}
|
|
814
811
|
/**
|
|
815
812
|
* Returns list of all keys presented in the cloud storage.
|
|
816
813
|
* @param options - request execution options.
|
|
817
814
|
*/
|
|
818
|
-
async getKeys(
|
|
819
|
-
const
|
|
815
|
+
async getKeys(t = {}) {
|
|
816
|
+
const e = await D(
|
|
820
817
|
"getStorageKeys",
|
|
821
818
|
{},
|
|
822
819
|
this.createRequestId(),
|
|
823
|
-
{ ...
|
|
820
|
+
{ ...t, postEvent: this.postEvent }
|
|
824
821
|
);
|
|
825
|
-
return
|
|
822
|
+
return oe().of(h()).parse(e);
|
|
826
823
|
}
|
|
827
|
-
async get(
|
|
828
|
-
const s = Array.isArray(
|
|
824
|
+
async get(t, e = {}) {
|
|
825
|
+
const s = Array.isArray(t) ? t : [t];
|
|
829
826
|
if (s.length === 0)
|
|
830
|
-
return
|
|
827
|
+
return nt(s, "");
|
|
831
828
|
const n = f(
|
|
832
|
-
|
|
833
|
-
), i = await
|
|
829
|
+
nt(s, h())
|
|
830
|
+
), i = await D(
|
|
834
831
|
"getStorageValues",
|
|
835
832
|
{ keys: s },
|
|
836
833
|
this.createRequestId(),
|
|
837
|
-
{ ...
|
|
834
|
+
{ ...e, postEvent: this.postEvent }
|
|
838
835
|
).then((a) => n.parse(a));
|
|
839
|
-
return Array.isArray(
|
|
836
|
+
return Array.isArray(t) ? i : i[t];
|
|
840
837
|
}
|
|
841
838
|
/**
|
|
842
839
|
* Saves specified value by key.
|
|
@@ -844,22 +841,22 @@ class at {
|
|
|
844
841
|
* @param value - storage value.
|
|
845
842
|
* @param options - request execution options.
|
|
846
843
|
*/
|
|
847
|
-
async set(
|
|
848
|
-
await
|
|
844
|
+
async set(t, e, s = {}) {
|
|
845
|
+
await D(
|
|
849
846
|
"saveStorageValue",
|
|
850
|
-
{ key:
|
|
847
|
+
{ key: t, value: e },
|
|
851
848
|
this.createRequestId(),
|
|
852
849
|
{ ...s, postEvent: this.postEvent }
|
|
853
850
|
);
|
|
854
851
|
}
|
|
855
852
|
}
|
|
856
|
-
class
|
|
857
|
-
constructor(
|
|
853
|
+
class ce {
|
|
854
|
+
constructor(t, e = d) {
|
|
858
855
|
/**
|
|
859
856
|
* Checks if specified method is supported by current component.
|
|
860
857
|
*/
|
|
861
858
|
o(this, "supports");
|
|
862
|
-
this.postEvent =
|
|
859
|
+
this.postEvent = e, this.supports = C(t, {
|
|
863
860
|
impactOccurred: "web_app_trigger_haptic_feedback",
|
|
864
861
|
notificationOccurred: "web_app_trigger_haptic_feedback",
|
|
865
862
|
selectionChanged: "web_app_trigger_haptic_feedback"
|
|
@@ -870,10 +867,10 @@ class ct {
|
|
|
870
867
|
* appropriate haptics based on style value passed.
|
|
871
868
|
* @param style - impact style.
|
|
872
869
|
*/
|
|
873
|
-
impactOccurred(
|
|
870
|
+
impactOccurred(t) {
|
|
874
871
|
this.postEvent("web_app_trigger_haptic_feedback", {
|
|
875
872
|
type: "impact",
|
|
876
|
-
impact_style:
|
|
873
|
+
impact_style: t
|
|
877
874
|
});
|
|
878
875
|
}
|
|
879
876
|
/**
|
|
@@ -882,10 +879,10 @@ class ct {
|
|
|
882
879
|
* type value passed.
|
|
883
880
|
* @param type - notification type.
|
|
884
881
|
*/
|
|
885
|
-
notificationOccurred(
|
|
882
|
+
notificationOccurred(t) {
|
|
886
883
|
this.postEvent("web_app_trigger_haptic_feedback", {
|
|
887
884
|
type: "notification",
|
|
888
|
-
notification_type:
|
|
885
|
+
notification_type: t
|
|
889
886
|
});
|
|
890
887
|
}
|
|
891
888
|
/**
|
|
@@ -899,7 +896,7 @@ class ct {
|
|
|
899
896
|
this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
|
|
900
897
|
}
|
|
901
898
|
}
|
|
902
|
-
function
|
|
899
|
+
function he() {
|
|
903
900
|
return f({
|
|
904
901
|
id: x(),
|
|
905
902
|
type: h(),
|
|
@@ -911,9 +908,9 @@ function ht() {
|
|
|
911
908
|
username: h().optional()
|
|
912
909
|
}, "Chat");
|
|
913
910
|
}
|
|
914
|
-
class
|
|
915
|
-
constructor(
|
|
916
|
-
this.initData =
|
|
911
|
+
class ue {
|
|
912
|
+
constructor(t) {
|
|
913
|
+
this.initData = t;
|
|
917
914
|
}
|
|
918
915
|
/**
|
|
919
916
|
* @see InitDataParsed.authDate
|
|
@@ -932,8 +929,8 @@ class ut {
|
|
|
932
929
|
* the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
|
|
933
930
|
*/
|
|
934
931
|
get canSendAfterDate() {
|
|
935
|
-
const { canSendAfter:
|
|
936
|
-
return
|
|
932
|
+
const { canSendAfter: t } = this;
|
|
933
|
+
return t === void 0 ? void 0 : new Date(this.authDate.getTime() + t * 1e3);
|
|
937
934
|
}
|
|
938
935
|
/**
|
|
939
936
|
* @see InitDataParsed.chat
|
|
@@ -984,7 +981,7 @@ class ut {
|
|
|
984
981
|
return this.initData.user;
|
|
985
982
|
}
|
|
986
983
|
}
|
|
987
|
-
function
|
|
984
|
+
function it() {
|
|
988
985
|
return f({
|
|
989
986
|
addedToAttachmentMenu: {
|
|
990
987
|
type: P().optional(),
|
|
@@ -1022,29 +1019,29 @@ function ie() {
|
|
|
1022
1019
|
username: h().optional()
|
|
1023
1020
|
}, "User");
|
|
1024
1021
|
}
|
|
1025
|
-
const
|
|
1026
|
-
function
|
|
1027
|
-
return new
|
|
1028
|
-
if (typeof
|
|
1022
|
+
const mt = R((r) => r instanceof Date ? r : new Date(x().parse(r) * 1e3), "Date");
|
|
1023
|
+
function et(r, t) {
|
|
1024
|
+
return new F((e) => {
|
|
1025
|
+
if (typeof e != "string" && !(e instanceof URLSearchParams))
|
|
1029
1026
|
throw V();
|
|
1030
|
-
const s = typeof
|
|
1031
|
-
return
|
|
1027
|
+
const s = typeof e == "string" ? new URLSearchParams(e) : e;
|
|
1028
|
+
return dt(r, (n) => {
|
|
1032
1029
|
const i = s.get(n);
|
|
1033
1030
|
return i === null ? void 0 : i;
|
|
1034
1031
|
});
|
|
1035
|
-
}, !1,
|
|
1032
|
+
}, !1, t);
|
|
1036
1033
|
}
|
|
1037
|
-
function
|
|
1038
|
-
return
|
|
1034
|
+
function yt() {
|
|
1035
|
+
return et({
|
|
1039
1036
|
authDate: {
|
|
1040
|
-
type:
|
|
1037
|
+
type: mt(),
|
|
1041
1038
|
from: "auth_date"
|
|
1042
1039
|
},
|
|
1043
1040
|
canSendAfter: {
|
|
1044
1041
|
type: x().optional(),
|
|
1045
1042
|
from: "can_send_after"
|
|
1046
1043
|
},
|
|
1047
|
-
chat:
|
|
1044
|
+
chat: he().optional(),
|
|
1048
1045
|
chatInstance: {
|
|
1049
1046
|
type: h().optional(),
|
|
1050
1047
|
from: "chat_instance"
|
|
@@ -1058,28 +1055,28 @@ function me() {
|
|
|
1058
1055
|
type: h().optional(),
|
|
1059
1056
|
from: "query_id"
|
|
1060
1057
|
},
|
|
1061
|
-
receiver:
|
|
1058
|
+
receiver: it().optional(),
|
|
1062
1059
|
startParam: {
|
|
1063
1060
|
type: h().optional(),
|
|
1064
1061
|
from: "start_param"
|
|
1065
1062
|
},
|
|
1066
|
-
user:
|
|
1063
|
+
user: it().optional()
|
|
1067
1064
|
}, "InitData");
|
|
1068
1065
|
}
|
|
1069
|
-
function
|
|
1070
|
-
return
|
|
1066
|
+
function tr(r) {
|
|
1067
|
+
return yt().parse(r);
|
|
1071
1068
|
}
|
|
1072
|
-
function
|
|
1073
|
-
const { hostname:
|
|
1074
|
-
if (
|
|
1075
|
-
throw new Error(`Incorrect hostname: ${
|
|
1076
|
-
const s =
|
|
1069
|
+
function pe(r) {
|
|
1070
|
+
const { hostname: t, pathname: e } = new URL(r, window.location.href);
|
|
1071
|
+
if (t !== "t.me")
|
|
1072
|
+
throw new Error(`Incorrect hostname: ${t}`);
|
|
1073
|
+
const s = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
1077
1074
|
if (s === null)
|
|
1078
1075
|
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
|
|
1079
1076
|
return s[2];
|
|
1080
1077
|
}
|
|
1081
|
-
class
|
|
1082
|
-
constructor(
|
|
1078
|
+
class le {
|
|
1079
|
+
constructor(t, e = d) {
|
|
1083
1080
|
o(this, "ee", new w());
|
|
1084
1081
|
o(this, "state");
|
|
1085
1082
|
/**
|
|
@@ -1094,10 +1091,10 @@ class lt {
|
|
|
1094
1091
|
* Checks if specified method is supported by current component.
|
|
1095
1092
|
*/
|
|
1096
1093
|
o(this, "supports");
|
|
1097
|
-
this.postEvent =
|
|
1094
|
+
this.postEvent = e, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(t, { open: "web_app_open_invoice" });
|
|
1098
1095
|
}
|
|
1099
|
-
set isOpened(
|
|
1100
|
-
this.state.set("isOpened",
|
|
1096
|
+
set isOpened(t) {
|
|
1097
|
+
this.state.set("isOpened", t);
|
|
1101
1098
|
}
|
|
1102
1099
|
/**
|
|
1103
1100
|
* True if invoice is currently opened.
|
|
@@ -1105,10 +1102,10 @@ class lt {
|
|
|
1105
1102
|
get isOpened() {
|
|
1106
1103
|
return this.state.get("isOpened");
|
|
1107
1104
|
}
|
|
1108
|
-
async open(
|
|
1105
|
+
async open(t, e) {
|
|
1109
1106
|
if (this.isOpened)
|
|
1110
1107
|
throw new Error("Invoice is already opened");
|
|
1111
|
-
const s =
|
|
1108
|
+
const s = e ? pe(t) : t;
|
|
1112
1109
|
this.isOpened = !0;
|
|
1113
1110
|
try {
|
|
1114
1111
|
return (await y("web_app_open_invoice", "invoice_closed", {
|
|
@@ -1123,8 +1120,8 @@ class lt {
|
|
|
1123
1120
|
}
|
|
1124
1121
|
}
|
|
1125
1122
|
}
|
|
1126
|
-
class
|
|
1127
|
-
constructor(
|
|
1123
|
+
class de {
|
|
1124
|
+
constructor(t) {
|
|
1128
1125
|
o(this, "ee", new w());
|
|
1129
1126
|
o(this, "state");
|
|
1130
1127
|
o(this, "postEvent");
|
|
@@ -1133,28 +1130,28 @@ class dt {
|
|
|
1133
1130
|
* @param event - event name.
|
|
1134
1131
|
* @param listener - event listener.
|
|
1135
1132
|
*/
|
|
1136
|
-
o(this, "on", (
|
|
1133
|
+
o(this, "on", (t, e) => (
|
|
1137
1134
|
// FIXME: Event 'main_button_pressed' is still being received on Android
|
|
1138
1135
|
// even if the main button is disabled.
|
|
1139
1136
|
// Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
|
|
1140
|
-
|
|
1137
|
+
t === "click" ? E("main_button_pressed", e) : this.ee.on(t, e)
|
|
1141
1138
|
));
|
|
1142
1139
|
/**
|
|
1143
1140
|
* Removes event listener.
|
|
1144
1141
|
* @param event - event name.
|
|
1145
1142
|
* @param listener - event listener.
|
|
1146
1143
|
*/
|
|
1147
|
-
o(this, "off", (
|
|
1144
|
+
o(this, "off", (t, e) => t === "click" ? I("main_button_pressed", e) : this.ee.off(t, e));
|
|
1148
1145
|
const {
|
|
1149
|
-
postEvent:
|
|
1146
|
+
postEvent: e = d,
|
|
1150
1147
|
text: s,
|
|
1151
1148
|
textColor: n,
|
|
1152
1149
|
backgroundColor: i,
|
|
1153
1150
|
isEnabled: a,
|
|
1154
1151
|
isVisible: c,
|
|
1155
1152
|
isLoaderVisible: u
|
|
1156
|
-
} =
|
|
1157
|
-
this.postEvent =
|
|
1153
|
+
} = t;
|
|
1154
|
+
this.postEvent = e, this.state = new m({
|
|
1158
1155
|
backgroundColor: i,
|
|
1159
1156
|
isEnabled: a,
|
|
1160
1157
|
isVisible: c,
|
|
@@ -1176,8 +1173,8 @@ class dt {
|
|
|
1176
1173
|
text_color: this.textColor
|
|
1177
1174
|
});
|
|
1178
1175
|
}
|
|
1179
|
-
set isEnabled(
|
|
1180
|
-
this.setParams({ isEnabled:
|
|
1176
|
+
set isEnabled(t) {
|
|
1177
|
+
this.setParams({ isEnabled: t });
|
|
1181
1178
|
}
|
|
1182
1179
|
/**
|
|
1183
1180
|
* True if the Main Button is currently enabled.
|
|
@@ -1185,8 +1182,8 @@ class dt {
|
|
|
1185
1182
|
get isEnabled() {
|
|
1186
1183
|
return this.state.get("isEnabled");
|
|
1187
1184
|
}
|
|
1188
|
-
set isLoaderVisible(
|
|
1189
|
-
this.setParams({ isLoaderVisible:
|
|
1185
|
+
set isLoaderVisible(t) {
|
|
1186
|
+
this.setParams({ isLoaderVisible: t });
|
|
1190
1187
|
}
|
|
1191
1188
|
/**
|
|
1192
1189
|
* True if the Main Button loader is currently visible.
|
|
@@ -1194,8 +1191,8 @@ class dt {
|
|
|
1194
1191
|
get isLoaderVisible() {
|
|
1195
1192
|
return this.state.get("isLoaderVisible");
|
|
1196
1193
|
}
|
|
1197
|
-
set isVisible(
|
|
1198
|
-
this.setParams({ isVisible:
|
|
1194
|
+
set isVisible(t) {
|
|
1195
|
+
this.setParams({ isVisible: t });
|
|
1199
1196
|
}
|
|
1200
1197
|
/**
|
|
1201
1198
|
* True if the Main Button is currently visible.
|
|
@@ -1263,32 +1260,32 @@ class dt {
|
|
|
1263
1260
|
* Sets new Main Button text. Minimal length for text is 1 symbol, and maximum is 64 symbols.
|
|
1264
1261
|
* @param text - new text.
|
|
1265
1262
|
*/
|
|
1266
|
-
setText(
|
|
1267
|
-
return this.setParams({ text:
|
|
1263
|
+
setText(t) {
|
|
1264
|
+
return this.setParams({ text: t });
|
|
1268
1265
|
}
|
|
1269
1266
|
/**
|
|
1270
1267
|
* Sets new Main Button text color.
|
|
1271
1268
|
* @param textColor - new text color.
|
|
1272
1269
|
*/
|
|
1273
|
-
setTextColor(
|
|
1274
|
-
return this.setParams({ textColor:
|
|
1270
|
+
setTextColor(t) {
|
|
1271
|
+
return this.setParams({ textColor: t });
|
|
1275
1272
|
}
|
|
1276
1273
|
/**
|
|
1277
1274
|
* Updates current Main Button color.
|
|
1278
1275
|
* @param backgroundColor - color to set.
|
|
1279
1276
|
*/
|
|
1280
|
-
setBackgroundColor(
|
|
1281
|
-
return this.setParams({ backgroundColor:
|
|
1277
|
+
setBackgroundColor(t) {
|
|
1278
|
+
return this.setParams({ backgroundColor: t });
|
|
1282
1279
|
}
|
|
1283
1280
|
/**
|
|
1284
1281
|
* Allows setting multiple Main Button parameters.
|
|
1285
1282
|
* @param params - Main Button parameters.
|
|
1286
1283
|
*/
|
|
1287
|
-
setParams(
|
|
1288
|
-
return this.state.set(
|
|
1284
|
+
setParams(t) {
|
|
1285
|
+
return this.state.set(t), this.commit(), this;
|
|
1289
1286
|
}
|
|
1290
1287
|
}
|
|
1291
|
-
const
|
|
1288
|
+
const fe = et({
|
|
1292
1289
|
contact: f({
|
|
1293
1290
|
userId: {
|
|
1294
1291
|
type: x(),
|
|
@@ -1308,24 +1305,24 @@ const ft = ee({
|
|
|
1308
1305
|
}
|
|
1309
1306
|
}),
|
|
1310
1307
|
authDate: {
|
|
1311
|
-
type:
|
|
1308
|
+
type: mt(),
|
|
1312
1309
|
from: "auth_date"
|
|
1313
1310
|
},
|
|
1314
1311
|
hash: h()
|
|
1315
1312
|
});
|
|
1316
|
-
function
|
|
1317
|
-
return (
|
|
1318
|
-
const [s, n] = e
|
|
1313
|
+
function Et(r, t) {
|
|
1314
|
+
return (e) => {
|
|
1315
|
+
const [s, n] = t[e];
|
|
1319
1316
|
return A(s, n, r);
|
|
1320
1317
|
};
|
|
1321
1318
|
}
|
|
1322
|
-
function
|
|
1323
|
-
return new Promise((
|
|
1324
|
-
setTimeout(
|
|
1319
|
+
function ge(r) {
|
|
1320
|
+
return new Promise((t) => {
|
|
1321
|
+
setTimeout(t, r);
|
|
1325
1322
|
});
|
|
1326
1323
|
}
|
|
1327
|
-
class
|
|
1328
|
-
constructor(
|
|
1324
|
+
class we {
|
|
1325
|
+
constructor(t) {
|
|
1329
1326
|
o(this, "ee", new w());
|
|
1330
1327
|
o(this, "state");
|
|
1331
1328
|
o(this, "botInline");
|
|
@@ -1350,20 +1347,20 @@ class wt {
|
|
|
1350
1347
|
*/
|
|
1351
1348
|
o(this, "supportsParam");
|
|
1352
1349
|
const {
|
|
1353
|
-
postEvent:
|
|
1350
|
+
postEvent: e = d,
|
|
1354
1351
|
headerColor: s,
|
|
1355
1352
|
backgroundColor: n,
|
|
1356
1353
|
version: i,
|
|
1357
1354
|
botInline: a,
|
|
1358
1355
|
createRequestId: c
|
|
1359
|
-
} =
|
|
1356
|
+
} = t, u = C(i, {
|
|
1360
1357
|
requestPhoneAccess: "web_app_request_phone",
|
|
1361
1358
|
requestWriteAccess: "web_app_request_write_access",
|
|
1362
1359
|
switchInlineQuery: "web_app_switch_inline_query",
|
|
1363
1360
|
setHeaderColor: "web_app_set_header_color",
|
|
1364
1361
|
setBackgroundColor: "web_app_set_background_color"
|
|
1365
1362
|
});
|
|
1366
|
-
this.postEvent =
|
|
1363
|
+
this.postEvent = e, 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 = Et(i, {
|
|
1367
1364
|
"setHeaderColor.color": ["web_app_set_header_color", "color"]
|
|
1368
1365
|
});
|
|
1369
1366
|
}
|
|
@@ -1371,7 +1368,7 @@ class wt {
|
|
|
1371
1368
|
* Attempts to get requested contact.
|
|
1372
1369
|
*/
|
|
1373
1370
|
async getRequestedContact() {
|
|
1374
|
-
return
|
|
1371
|
+
return D(
|
|
1375
1372
|
"getRequestedContact",
|
|
1376
1373
|
{},
|
|
1377
1374
|
this.createRequestId(),
|
|
@@ -1379,7 +1376,7 @@ class wt {
|
|
|
1379
1376
|
postEvent: this.postEvent,
|
|
1380
1377
|
timeout: 1e4
|
|
1381
1378
|
}
|
|
1382
|
-
).then((
|
|
1379
|
+
).then((t) => fe.parse(t));
|
|
1383
1380
|
}
|
|
1384
1381
|
/**
|
|
1385
1382
|
* The Mini App background color.
|
|
@@ -1409,7 +1406,7 @@ class wt {
|
|
|
1409
1406
|
* True if current Mini App background color recognized as dark.
|
|
1410
1407
|
*/
|
|
1411
1408
|
get isDark() {
|
|
1412
|
-
return
|
|
1409
|
+
return bt(this.backgroundColor);
|
|
1413
1410
|
}
|
|
1414
1411
|
/**
|
|
1415
1412
|
* True if phone access is currently being requested.
|
|
@@ -1441,25 +1438,25 @@ class wt {
|
|
|
1441
1438
|
* failed.
|
|
1442
1439
|
* @param options - additional options.
|
|
1443
1440
|
*/
|
|
1444
|
-
async requestContact({ timeout:
|
|
1441
|
+
async requestContact({ timeout: t = 5e3 } = {}) {
|
|
1445
1442
|
try {
|
|
1446
1443
|
return await this.getRequestedContact();
|
|
1447
1444
|
} catch {
|
|
1448
1445
|
}
|
|
1449
1446
|
if (await this.requestPhoneAccess() !== "sent")
|
|
1450
1447
|
throw new Error("Access denied.");
|
|
1451
|
-
const s = Date.now() +
|
|
1448
|
+
const s = Date.now() + t;
|
|
1452
1449
|
let n = 50;
|
|
1453
|
-
return
|
|
1450
|
+
return wt(async () => {
|
|
1454
1451
|
for (; Date.now() < s; ) {
|
|
1455
1452
|
try {
|
|
1456
1453
|
return await this.getRequestedContact();
|
|
1457
1454
|
} catch {
|
|
1458
1455
|
}
|
|
1459
|
-
await
|
|
1456
|
+
await ge(n), n += 50;
|
|
1460
1457
|
}
|
|
1461
1458
|
throw new Error("Unable to retrieve requested contact.");
|
|
1462
|
-
},
|
|
1459
|
+
}, t);
|
|
1463
1460
|
}
|
|
1464
1461
|
/**
|
|
1465
1462
|
* Requests current user phone access. Method returns promise, which resolves
|
|
@@ -1470,13 +1467,13 @@ class wt {
|
|
|
1470
1467
|
* @param options - additional options.
|
|
1471
1468
|
* @see requestContact
|
|
1472
1469
|
*/
|
|
1473
|
-
requestPhoneAccess(
|
|
1470
|
+
requestPhoneAccess(t = {}) {
|
|
1474
1471
|
if (this.requestingPhoneAccess)
|
|
1475
1472
|
throw new Error("Phone access is already being requested.");
|
|
1476
1473
|
return this.requestingPhoneAccess = !0, y("web_app_request_phone", "phone_requested", {
|
|
1477
|
-
...
|
|
1474
|
+
...t,
|
|
1478
1475
|
postEvent: this.postEvent
|
|
1479
|
-
}).then((
|
|
1476
|
+
}).then((e) => e.status).finally(() => {
|
|
1480
1477
|
this.requestingPhoneAccess = !1;
|
|
1481
1478
|
});
|
|
1482
1479
|
}
|
|
@@ -1484,13 +1481,13 @@ class wt {
|
|
|
1484
1481
|
* Requests write message access to current user.
|
|
1485
1482
|
* @param options - additional options.
|
|
1486
1483
|
*/
|
|
1487
|
-
requestWriteAccess(
|
|
1484
|
+
requestWriteAccess(t = {}) {
|
|
1488
1485
|
if (this.requestingWriteAccess)
|
|
1489
1486
|
throw new Error("Write access is already being requested.");
|
|
1490
1487
|
return this.requestingWriteAccess = !0, y("web_app_request_write_access", "write_access_requested", {
|
|
1491
|
-
...
|
|
1488
|
+
...t,
|
|
1492
1489
|
postEvent: this.postEvent
|
|
1493
|
-
}).then((
|
|
1490
|
+
}).then((e) => e.status).finally(() => {
|
|
1494
1491
|
this.requestingWriteAccess = !1;
|
|
1495
1492
|
});
|
|
1496
1493
|
}
|
|
@@ -1503,25 +1500,25 @@ class wt {
|
|
|
1503
1500
|
* @param data - data to send to bot.
|
|
1504
1501
|
* @throws {Error} data has incorrect size.
|
|
1505
1502
|
*/
|
|
1506
|
-
sendData(
|
|
1507
|
-
const { size:
|
|
1508
|
-
if (
|
|
1509
|
-
throw new Error(`Passed data has incorrect size: ${
|
|
1510
|
-
this.postEvent("web_app_data_send", { data:
|
|
1503
|
+
sendData(t) {
|
|
1504
|
+
const { size: e } = new Blob([t]);
|
|
1505
|
+
if (e === 0 || e > 4096)
|
|
1506
|
+
throw new Error(`Passed data has incorrect size: ${e}`);
|
|
1507
|
+
this.postEvent("web_app_data_send", { data: t });
|
|
1511
1508
|
}
|
|
1512
1509
|
/**
|
|
1513
1510
|
* Updates current Mini App header color.
|
|
1514
1511
|
* @param color - color key or RGB color.
|
|
1515
1512
|
*/
|
|
1516
|
-
setHeaderColor(
|
|
1517
|
-
this.postEvent("web_app_set_header_color",
|
|
1513
|
+
setHeaderColor(t) {
|
|
1514
|
+
this.postEvent("web_app_set_header_color", tt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
|
|
1518
1515
|
}
|
|
1519
1516
|
/**
|
|
1520
1517
|
* Updates current Mini App background color.
|
|
1521
1518
|
* @param color - RGB color.
|
|
1522
1519
|
*/
|
|
1523
|
-
setBackgroundColor(
|
|
1524
|
-
this.postEvent("web_app_set_background_color", { color:
|
|
1520
|
+
setBackgroundColor(t) {
|
|
1521
|
+
this.postEvent("web_app_set_background_color", { color: t }), this.state.set("backgroundColor", t);
|
|
1525
1522
|
}
|
|
1526
1523
|
/**
|
|
1527
1524
|
* Inserts the bot's username and the specified inline query in the current chat's input field.
|
|
@@ -1533,22 +1530,22 @@ class wt {
|
|
|
1533
1530
|
* @param chatTypes - List of chat types which could be chosen to send the message. Could be
|
|
1534
1531
|
* empty list.
|
|
1535
1532
|
*/
|
|
1536
|
-
switchInlineQuery(
|
|
1533
|
+
switchInlineQuery(t, e = []) {
|
|
1537
1534
|
if (!this.supports("switchInlineQuery") && !this.isBotInline)
|
|
1538
1535
|
throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
|
|
1539
1536
|
this.postEvent("web_app_switch_inline_query", {
|
|
1540
|
-
query:
|
|
1541
|
-
chat_types:
|
|
1537
|
+
query: t,
|
|
1538
|
+
chat_types: e
|
|
1542
1539
|
});
|
|
1543
1540
|
}
|
|
1544
1541
|
}
|
|
1545
|
-
function
|
|
1546
|
-
const
|
|
1542
|
+
function _e(r) {
|
|
1543
|
+
const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
|
|
1547
1544
|
let n;
|
|
1548
|
-
if (
|
|
1549
|
-
throw new Error(`Title has incorrect size: ${
|
|
1550
|
-
if (
|
|
1551
|
-
throw new Error(`Message has incorrect size: ${
|
|
1545
|
+
if (e.length > 64)
|
|
1546
|
+
throw new Error(`Title has incorrect size: ${e.length}`);
|
|
1547
|
+
if (t.length === 0 || t.length > 256)
|
|
1548
|
+
throw new Error(`Message has incorrect size: ${t.length}`);
|
|
1552
1549
|
if (s.length > 3)
|
|
1553
1550
|
throw new Error(`Buttons have incorrect size: ${s.length}`);
|
|
1554
1551
|
return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
|
|
@@ -1564,10 +1561,10 @@ function _t(r) {
|
|
|
1564
1561
|
return { ...i, text: c, id: a };
|
|
1565
1562
|
}
|
|
1566
1563
|
return { ...i, id: a };
|
|
1567
|
-
}), { title:
|
|
1564
|
+
}), { title: e, message: t, buttons: n };
|
|
1568
1565
|
}
|
|
1569
|
-
class
|
|
1570
|
-
constructor(
|
|
1566
|
+
class be {
|
|
1567
|
+
constructor(t, e = d) {
|
|
1571
1568
|
o(this, "ee", new w());
|
|
1572
1569
|
o(this, "state");
|
|
1573
1570
|
/**
|
|
@@ -1582,10 +1579,10 @@ class bt {
|
|
|
1582
1579
|
* Checks if specified method is supported by current component.
|
|
1583
1580
|
*/
|
|
1584
1581
|
o(this, "supports");
|
|
1585
|
-
this.postEvent =
|
|
1582
|
+
this.postEvent = e, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(t, { open: "web_app_open_popup" });
|
|
1586
1583
|
}
|
|
1587
|
-
set isOpened(
|
|
1588
|
-
this.state.set("isOpened",
|
|
1584
|
+
set isOpened(t) {
|
|
1585
|
+
this.state.set("isOpened", t);
|
|
1589
1586
|
}
|
|
1590
1587
|
/**
|
|
1591
1588
|
* True if popup is currently opened.
|
|
@@ -1606,19 +1603,19 @@ class bt {
|
|
|
1606
1603
|
* @param options - popup parameters.
|
|
1607
1604
|
* @throws {Error} Popup is already opened.
|
|
1608
1605
|
*/
|
|
1609
|
-
open(
|
|
1606
|
+
open(t) {
|
|
1610
1607
|
if (this.isOpened)
|
|
1611
1608
|
throw new Error("Popup is already opened.");
|
|
1612
1609
|
return this.isOpened = !0, y("web_app_open_popup", "popup_closed", {
|
|
1613
1610
|
postEvent: this.postEvent,
|
|
1614
|
-
params:
|
|
1615
|
-
}).then(({ button_id:
|
|
1611
|
+
params: _e(t)
|
|
1612
|
+
}).then(({ button_id: e = null }) => e).finally(() => {
|
|
1616
1613
|
this.isOpened = !1;
|
|
1617
1614
|
});
|
|
1618
1615
|
}
|
|
1619
1616
|
}
|
|
1620
|
-
class
|
|
1621
|
-
constructor(
|
|
1617
|
+
class me {
|
|
1618
|
+
constructor(t, e = d) {
|
|
1622
1619
|
o(this, "ee", new w());
|
|
1623
1620
|
o(this, "state");
|
|
1624
1621
|
/**
|
|
@@ -1633,7 +1630,7 @@ class mt {
|
|
|
1633
1630
|
* Checks if specified method is supported by current component.
|
|
1634
1631
|
*/
|
|
1635
1632
|
o(this, "supports");
|
|
1636
|
-
this.postEvent =
|
|
1633
|
+
this.postEvent = e, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(t, {
|
|
1637
1634
|
close: "web_app_close_scan_qr_popup",
|
|
1638
1635
|
open: "web_app_open_scan_qr_popup"
|
|
1639
1636
|
});
|
|
@@ -1644,8 +1641,8 @@ class mt {
|
|
|
1644
1641
|
close() {
|
|
1645
1642
|
this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
|
|
1646
1643
|
}
|
|
1647
|
-
set isOpened(
|
|
1648
|
-
this.state.set("isOpened",
|
|
1644
|
+
set isOpened(t) {
|
|
1645
|
+
this.state.set("isOpened", t);
|
|
1649
1646
|
}
|
|
1650
1647
|
/**
|
|
1651
1648
|
* Returns true in case, QR scanner is currently opened.
|
|
@@ -1659,27 +1656,27 @@ class mt {
|
|
|
1659
1656
|
* case, scanner was closed.
|
|
1660
1657
|
* @param text - title to display.
|
|
1661
1658
|
*/
|
|
1662
|
-
async open(
|
|
1659
|
+
async open(t) {
|
|
1663
1660
|
if (this.isOpened)
|
|
1664
1661
|
throw new Error("QR scanner is already opened.");
|
|
1665
1662
|
this.isOpened = !0;
|
|
1666
1663
|
try {
|
|
1667
|
-
const
|
|
1664
|
+
const e = await y(
|
|
1668
1665
|
"web_app_open_scan_qr_popup",
|
|
1669
1666
|
["qr_text_received", "scan_qr_popup_closed"],
|
|
1670
1667
|
{
|
|
1671
1668
|
postEvent: this.postEvent,
|
|
1672
|
-
params: { text:
|
|
1669
|
+
params: { text: t }
|
|
1673
1670
|
}
|
|
1674
1671
|
);
|
|
1675
|
-
return typeof
|
|
1672
|
+
return typeof e == "object" && typeof e.data == "string" ? e.data : null;
|
|
1676
1673
|
} finally {
|
|
1677
1674
|
this.isOpened = !1;
|
|
1678
1675
|
}
|
|
1679
1676
|
}
|
|
1680
1677
|
}
|
|
1681
|
-
class
|
|
1682
|
-
constructor(
|
|
1678
|
+
class ye {
|
|
1679
|
+
constructor(t, e, s = d) {
|
|
1683
1680
|
o(this, "ee", new w());
|
|
1684
1681
|
o(this, "state");
|
|
1685
1682
|
/**
|
|
@@ -1687,24 +1684,24 @@ class yt {
|
|
|
1687
1684
|
* @param event - event name.
|
|
1688
1685
|
* @param listener - event listener.
|
|
1689
1686
|
*/
|
|
1690
|
-
o(this, "on", (
|
|
1687
|
+
o(this, "on", (t, e) => t === "click" ? E("settings_button_pressed", e) : this.ee.on(t, e));
|
|
1691
1688
|
/**
|
|
1692
1689
|
* Removes event listener.
|
|
1693
1690
|
* @param event - event name.
|
|
1694
1691
|
* @param listener - event listener.
|
|
1695
1692
|
*/
|
|
1696
|
-
o(this, "off", (
|
|
1693
|
+
o(this, "off", (t, e) => t === "click" ? I("settings_button_pressed", e) : this.ee.off(t, e));
|
|
1697
1694
|
/**
|
|
1698
1695
|
* Checks if specified method is supported by current component.
|
|
1699
1696
|
*/
|
|
1700
1697
|
o(this, "supports");
|
|
1701
|
-
this.postEvent = s, this.state = new m({ isVisible:
|
|
1698
|
+
this.postEvent = s, this.state = new m({ isVisible: t }, this.ee), this.supports = C(e, {
|
|
1702
1699
|
show: "web_app_setup_settings_button",
|
|
1703
1700
|
hide: "web_app_setup_settings_button"
|
|
1704
1701
|
});
|
|
1705
1702
|
}
|
|
1706
|
-
set isVisible(
|
|
1707
|
-
this.state.set("isVisible",
|
|
1703
|
+
set isVisible(t) {
|
|
1704
|
+
this.state.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
|
|
1708
1705
|
}
|
|
1709
1706
|
/**
|
|
1710
1707
|
* True if SettingsButton is currently visible.
|
|
@@ -1725,32 +1722,32 @@ class yt {
|
|
|
1725
1722
|
this.isVisible = !0;
|
|
1726
1723
|
}
|
|
1727
1724
|
}
|
|
1728
|
-
function
|
|
1729
|
-
return r.replace(/(^|_)bg/, (
|
|
1725
|
+
function Ee(r) {
|
|
1726
|
+
return r.replace(/(^|_)bg/, (t, e) => `${e}background`).replace(/_([a-z])/g, (t, e) => e.toUpperCase());
|
|
1730
1727
|
}
|
|
1731
|
-
function
|
|
1732
|
-
return r.replace(/[A-Z]/g, (
|
|
1728
|
+
function Ce(r) {
|
|
1729
|
+
return r.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`).replace(/(^|_)background/, (t, e) => `${e}bg`);
|
|
1733
1730
|
}
|
|
1734
|
-
const
|
|
1731
|
+
const Ct = R(
|
|
1735
1732
|
(r) => {
|
|
1736
|
-
const
|
|
1737
|
-
return Object.entries(
|
|
1733
|
+
const t = gt().optional();
|
|
1734
|
+
return Object.entries(X(r)).reduce((e, [s, n]) => (e[Ee(s)] = t.parse(n), e), {});
|
|
1738
1735
|
},
|
|
1739
1736
|
"ThemeParams"
|
|
1740
1737
|
);
|
|
1741
|
-
function
|
|
1742
|
-
return
|
|
1738
|
+
function vt(r) {
|
|
1739
|
+
return Ct().parse(r);
|
|
1743
1740
|
}
|
|
1744
|
-
function
|
|
1745
|
-
return y("web_app_request_theme", "theme_changed", r).then(
|
|
1741
|
+
function er(r) {
|
|
1742
|
+
return y("web_app_request_theme", "theme_changed", r).then(vt);
|
|
1746
1743
|
}
|
|
1747
|
-
function
|
|
1744
|
+
function ve(r) {
|
|
1748
1745
|
return JSON.stringify(
|
|
1749
|
-
Object.entries(r).reduce((
|
|
1746
|
+
Object.entries(r).reduce((t, [e, s]) => (s && (t[Ce(e)] = s), t), {})
|
|
1750
1747
|
);
|
|
1751
1748
|
}
|
|
1752
|
-
class
|
|
1753
|
-
constructor(
|
|
1749
|
+
class Pe {
|
|
1750
|
+
constructor(t) {
|
|
1754
1751
|
o(this, "ee", new w());
|
|
1755
1752
|
o(this, "state");
|
|
1756
1753
|
/**
|
|
@@ -1761,7 +1758,7 @@ class Pt {
|
|
|
1761
1758
|
* Removes event listener.
|
|
1762
1759
|
*/
|
|
1763
1760
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1764
|
-
this.state = new m(
|
|
1761
|
+
this.state = new m(t, this.ee);
|
|
1765
1762
|
}
|
|
1766
1763
|
/**
|
|
1767
1764
|
* @since v6.10
|
|
@@ -1785,8 +1782,8 @@ class Pt {
|
|
|
1785
1782
|
* Retrieves palette color value by its name.
|
|
1786
1783
|
* @param key - palette key name.
|
|
1787
1784
|
*/
|
|
1788
|
-
get(
|
|
1789
|
-
return this.state.get(
|
|
1785
|
+
get(t) {
|
|
1786
|
+
return this.state.get(t);
|
|
1790
1787
|
}
|
|
1791
1788
|
/**
|
|
1792
1789
|
* Returns the copy of the internal state of the current component instance.
|
|
@@ -1808,7 +1805,7 @@ class Pt {
|
|
|
1808
1805
|
* value is calculated according to theme background color.
|
|
1809
1806
|
*/
|
|
1810
1807
|
get isDark() {
|
|
1811
|
-
return !this.backgroundColor ||
|
|
1808
|
+
return !this.backgroundColor || bt(this.backgroundColor);
|
|
1812
1809
|
}
|
|
1813
1810
|
get linkColor() {
|
|
1814
1811
|
return this.get("linkColor");
|
|
@@ -1833,8 +1830,8 @@ class Pt {
|
|
|
1833
1830
|
* @returns Function to stop listening.
|
|
1834
1831
|
*/
|
|
1835
1832
|
listen() {
|
|
1836
|
-
return E("theme_changed", (
|
|
1837
|
-
this.state.set(
|
|
1833
|
+
return E("theme_changed", (t) => {
|
|
1834
|
+
this.state.set(vt(t.theme_params));
|
|
1838
1835
|
});
|
|
1839
1836
|
}
|
|
1840
1837
|
/**
|
|
@@ -1847,8 +1844,8 @@ class Pt {
|
|
|
1847
1844
|
return this.get("textColor");
|
|
1848
1845
|
}
|
|
1849
1846
|
}
|
|
1850
|
-
class
|
|
1851
|
-
constructor(
|
|
1847
|
+
class Se {
|
|
1848
|
+
constructor(t, e, s = d) {
|
|
1852
1849
|
/**
|
|
1853
1850
|
* Checks if specified method is supported by current component.
|
|
1854
1851
|
*/
|
|
@@ -1857,9 +1854,9 @@ class St {
|
|
|
1857
1854
|
* Checks if specified method parameter is supported by current component.
|
|
1858
1855
|
*/
|
|
1859
1856
|
o(this, "supportsParam");
|
|
1860
|
-
this.version =
|
|
1857
|
+
this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = C(t, {
|
|
1861
1858
|
readTextFromClipboard: "web_app_read_text_from_clipboard"
|
|
1862
|
-
}), this.supportsParam =
|
|
1859
|
+
}), this.supportsParam = Et(t, {
|
|
1863
1860
|
"openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
|
|
1864
1861
|
});
|
|
1865
1862
|
}
|
|
@@ -1872,15 +1869,15 @@ class St {
|
|
|
1872
1869
|
* @param url - URL to be opened.
|
|
1873
1870
|
* @param tryInstantView
|
|
1874
1871
|
*/
|
|
1875
|
-
openLink(
|
|
1876
|
-
const s = new URL(
|
|
1872
|
+
openLink(t, e) {
|
|
1873
|
+
const s = new URL(t, window.location.href).toString();
|
|
1877
1874
|
if (!A("web_app_open_link", this.version)) {
|
|
1878
1875
|
window.open(s, "_blank");
|
|
1879
1876
|
return;
|
|
1880
1877
|
}
|
|
1881
1878
|
this.postEvent("web_app_open_link", {
|
|
1882
1879
|
url: s,
|
|
1883
|
-
...typeof
|
|
1880
|
+
...typeof e == "boolean" ? { try_instant_view: e } : {}
|
|
1884
1881
|
});
|
|
1885
1882
|
}
|
|
1886
1883
|
/**
|
|
@@ -1889,16 +1886,16 @@ class St {
|
|
|
1889
1886
|
* @param url - URL to be opened.
|
|
1890
1887
|
* @throws {Error} URL has not allowed hostname.
|
|
1891
1888
|
*/
|
|
1892
|
-
openTelegramLink(
|
|
1889
|
+
openTelegramLink(t) {
|
|
1893
1890
|
const {
|
|
1894
|
-
hostname:
|
|
1891
|
+
hostname: e,
|
|
1895
1892
|
pathname: s,
|
|
1896
1893
|
search: n
|
|
1897
|
-
} = new URL(
|
|
1898
|
-
if (
|
|
1899
|
-
throw new Error(`URL has not allowed hostname: ${
|
|
1894
|
+
} = new URL(t, window.location.href);
|
|
1895
|
+
if (e !== "t.me")
|
|
1896
|
+
throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
|
|
1900
1897
|
if (!A("web_app_open_tg_link", this.version)) {
|
|
1901
|
-
window.location.href =
|
|
1898
|
+
window.location.href = t;
|
|
1902
1899
|
return;
|
|
1903
1900
|
}
|
|
1904
1901
|
this.postEvent("web_app_open_tg_link", { path_full: s + n });
|
|
@@ -1910,33 +1907,33 @@ class St {
|
|
|
1910
1907
|
* - Access to clipboard is not allowed
|
|
1911
1908
|
*/
|
|
1912
1909
|
async readTextFromClipboard() {
|
|
1913
|
-
const
|
|
1914
|
-
data:
|
|
1910
|
+
const t = this.createRequestId(), {
|
|
1911
|
+
data: e = null
|
|
1915
1912
|
} = await y("web_app_read_text_from_clipboard", "clipboard_text_received", {
|
|
1916
1913
|
postEvent: this.postEvent,
|
|
1917
|
-
params: { req_id:
|
|
1918
|
-
capture:
|
|
1914
|
+
params: { req_id: t },
|
|
1915
|
+
capture: lt(t)
|
|
1919
1916
|
});
|
|
1920
|
-
return
|
|
1917
|
+
return e;
|
|
1921
1918
|
}
|
|
1922
1919
|
}
|
|
1923
|
-
function
|
|
1920
|
+
function ke(r) {
|
|
1924
1921
|
return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
|
|
1925
1922
|
}
|
|
1926
|
-
async function
|
|
1927
|
-
const
|
|
1923
|
+
async function Pt(r) {
|
|
1924
|
+
const t = await y("web_app_request_viewport", "viewport_changed", r);
|
|
1928
1925
|
return {
|
|
1929
|
-
height:
|
|
1930
|
-
width:
|
|
1931
|
-
isExpanded:
|
|
1932
|
-
isStateStable:
|
|
1926
|
+
height: t.height,
|
|
1927
|
+
width: t.width,
|
|
1928
|
+
isExpanded: t.is_expanded,
|
|
1929
|
+
isStateStable: t.is_state_stable
|
|
1933
1930
|
};
|
|
1934
1931
|
}
|
|
1935
1932
|
function L(r) {
|
|
1936
1933
|
return r < 0 ? 0 : r;
|
|
1937
1934
|
}
|
|
1938
|
-
class
|
|
1939
|
-
constructor(
|
|
1935
|
+
class xe {
|
|
1936
|
+
constructor(t) {
|
|
1940
1937
|
o(this, "ee", new w());
|
|
1941
1938
|
o(this, "state");
|
|
1942
1939
|
o(this, "postEvent");
|
|
@@ -1949,14 +1946,14 @@ class xt {
|
|
|
1949
1946
|
*/
|
|
1950
1947
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1951
1948
|
const {
|
|
1952
|
-
height:
|
|
1949
|
+
height: e,
|
|
1953
1950
|
isExpanded: s,
|
|
1954
1951
|
width: n,
|
|
1955
1952
|
stableHeight: i,
|
|
1956
1953
|
postEvent: a = d
|
|
1957
|
-
} =
|
|
1954
|
+
} = t;
|
|
1958
1955
|
this.postEvent = a, this.state = new m({
|
|
1959
|
-
height: L(
|
|
1956
|
+
height: L(e),
|
|
1960
1957
|
isExpanded: s,
|
|
1961
1958
|
stableHeight: L(i),
|
|
1962
1959
|
width: L(n)
|
|
@@ -1967,13 +1964,13 @@ class xt {
|
|
|
1967
1964
|
* instance.
|
|
1968
1965
|
* @param options - options to request fresh data.
|
|
1969
1966
|
*/
|
|
1970
|
-
sync(
|
|
1971
|
-
return
|
|
1967
|
+
sync(t) {
|
|
1968
|
+
return Pt(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
|
|
1972
1969
|
this.state.set({
|
|
1973
|
-
height:
|
|
1970
|
+
height: e,
|
|
1974
1971
|
width: n,
|
|
1975
1972
|
isExpanded: s,
|
|
1976
|
-
stableHeight: i ?
|
|
1973
|
+
stableHeight: i ? e : this.state.get("stableHeight")
|
|
1977
1974
|
});
|
|
1978
1975
|
});
|
|
1979
1976
|
}
|
|
@@ -2018,14 +2015,14 @@ class xt {
|
|
|
2018
2015
|
* @returns Function to stop listening.
|
|
2019
2016
|
*/
|
|
2020
2017
|
listen() {
|
|
2021
|
-
return E("viewport_changed", (
|
|
2018
|
+
return E("viewport_changed", (t) => {
|
|
2022
2019
|
const {
|
|
2023
|
-
height:
|
|
2020
|
+
height: e,
|
|
2024
2021
|
width: s,
|
|
2025
2022
|
is_expanded: n,
|
|
2026
2023
|
is_state_stable: i
|
|
2027
|
-
} =
|
|
2028
|
-
height: L(
|
|
2024
|
+
} = t, a = {
|
|
2025
|
+
height: L(e),
|
|
2029
2026
|
isExpanded: n,
|
|
2030
2027
|
width: L(s)
|
|
2031
2028
|
};
|
|
@@ -2064,18 +2061,18 @@ class xt {
|
|
|
2064
2061
|
return this.stableHeight === this.height;
|
|
2065
2062
|
}
|
|
2066
2063
|
}
|
|
2067
|
-
function S(r,
|
|
2068
|
-
document.documentElement.style.setProperty(r,
|
|
2064
|
+
function S(r, t) {
|
|
2065
|
+
document.documentElement.style.setProperty(r, t);
|
|
2069
2066
|
}
|
|
2070
|
-
function
|
|
2071
|
-
const
|
|
2067
|
+
function qe(r, t) {
|
|
2068
|
+
const e = () => {
|
|
2072
2069
|
S("--tg-background-color", r.backgroundColor);
|
|
2073
2070
|
}, s = () => {
|
|
2074
2071
|
const {
|
|
2075
2072
|
backgroundColor: n,
|
|
2076
2073
|
secondaryBackgroundColor: i
|
|
2077
|
-
} =
|
|
2078
|
-
if (
|
|
2074
|
+
} = t;
|
|
2075
|
+
if (tt(r.headerColor)) {
|
|
2079
2076
|
S("--tg-header-color", r.headerColor);
|
|
2080
2077
|
return;
|
|
2081
2078
|
}
|
|
@@ -2085,61 +2082,61 @@ function qt(r, e) {
|
|
|
2085
2082
|
}
|
|
2086
2083
|
r.headerColor === "secondary_bg_color" && i && S("--tg-header-color", i);
|
|
2087
2084
|
};
|
|
2088
|
-
|
|
2085
|
+
t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
|
|
2089
2086
|
}
|
|
2090
|
-
function
|
|
2091
|
-
const
|
|
2092
|
-
const
|
|
2093
|
-
Object.entries(
|
|
2087
|
+
function Ae(r) {
|
|
2088
|
+
const t = () => {
|
|
2089
|
+
const e = r.getState();
|
|
2090
|
+
Object.entries(e).forEach(([s, n]) => {
|
|
2094
2091
|
if (n) {
|
|
2095
2092
|
const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
|
|
2096
2093
|
S(`--tg-theme-${i}`, n);
|
|
2097
2094
|
}
|
|
2098
2095
|
});
|
|
2099
2096
|
};
|
|
2100
|
-
r.on("change",
|
|
2097
|
+
r.on("change", t), t();
|
|
2101
2098
|
}
|
|
2102
|
-
function
|
|
2103
|
-
const
|
|
2104
|
-
r.on("change:height",
|
|
2099
|
+
function ot(r) {
|
|
2100
|
+
const t = () => S("--tg-viewport-height", `${r.height}px`), e = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-stable-height", `${r.stableHeight}px`);
|
|
2101
|
+
r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
|
|
2105
2102
|
}
|
|
2106
|
-
function
|
|
2103
|
+
function Ve() {
|
|
2107
2104
|
const r = document.createElement("style");
|
|
2108
|
-
r.id = "telegram-custom-styles", document.head.appendChild(r), E("set_custom_style", (
|
|
2109
|
-
r.innerHTML =
|
|
2105
|
+
r.id = "telegram-custom-styles", document.head.appendChild(r), E("set_custom_style", (t) => {
|
|
2106
|
+
r.innerHTML = t;
|
|
2110
2107
|
});
|
|
2111
2108
|
}
|
|
2112
|
-
function
|
|
2109
|
+
function St(r) {
|
|
2113
2110
|
return `telegram-mini-apps-${r}`;
|
|
2114
2111
|
}
|
|
2115
|
-
function T(r,
|
|
2116
|
-
sessionStorage.setItem(
|
|
2112
|
+
function T(r, t) {
|
|
2113
|
+
sessionStorage.setItem(St(r), JSON.stringify(t));
|
|
2117
2114
|
}
|
|
2118
2115
|
function $(r) {
|
|
2119
|
-
const
|
|
2120
|
-
return
|
|
2116
|
+
const t = sessionStorage.getItem(St(r));
|
|
2117
|
+
return t ? JSON.parse(t) : null;
|
|
2121
2118
|
}
|
|
2122
|
-
function
|
|
2123
|
-
const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new
|
|
2119
|
+
function Re(r, t, e) {
|
|
2120
|
+
const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new re(s, t, e);
|
|
2124
2121
|
return n.on("change", () => {
|
|
2125
2122
|
T("back-button", { isVisible: n.isVisible });
|
|
2126
2123
|
}), n;
|
|
2127
2124
|
}
|
|
2128
|
-
function
|
|
2129
|
-
const { isConfirmationNeeded:
|
|
2125
|
+
function Ie(r, t) {
|
|
2126
|
+
const { isConfirmationNeeded: e = !1 } = r ? $("closing-behavior") || {} : {}, s = new se(e, t);
|
|
2130
2127
|
return s.on("change", () => T("closing-behavior", {
|
|
2131
2128
|
isConfirmationNeeded: s.isConfirmationNeeded
|
|
2132
2129
|
})), s;
|
|
2133
2130
|
}
|
|
2134
|
-
function
|
|
2131
|
+
function Te(r, t, e, s) {
|
|
2135
2132
|
const {
|
|
2136
|
-
backgroundColor: n =
|
|
2133
|
+
backgroundColor: n = t,
|
|
2137
2134
|
isEnabled: i = !1,
|
|
2138
2135
|
isVisible: a = !1,
|
|
2139
2136
|
isLoaderVisible: c = !1,
|
|
2140
|
-
textColor: u =
|
|
2137
|
+
textColor: u = e,
|
|
2141
2138
|
text: p = ""
|
|
2142
|
-
} = r ? $("main-button") || {} : {}, g = new
|
|
2139
|
+
} = r ? $("main-button") || {} : {}, g = new de({
|
|
2143
2140
|
backgroundColor: n,
|
|
2144
2141
|
isEnabled: i,
|
|
2145
2142
|
isLoaderVisible: c,
|
|
@@ -2157,14 +2154,14 @@ function Tt(r, e, t, s) {
|
|
|
2157
2154
|
});
|
|
2158
2155
|
return g.on("change", _), g;
|
|
2159
2156
|
}
|
|
2160
|
-
function $
|
|
2157
|
+
function $e(r, t, e, s, n, i) {
|
|
2161
2158
|
const {
|
|
2162
|
-
backgroundColor: a =
|
|
2159
|
+
backgroundColor: a = t,
|
|
2163
2160
|
headerColor: c = "bg_color"
|
|
2164
|
-
} = r ? $("mini-app") || {} : {}, u = new
|
|
2161
|
+
} = r ? $("mini-app") || {} : {}, u = new we({
|
|
2165
2162
|
headerColor: c,
|
|
2166
2163
|
backgroundColor: a,
|
|
2167
|
-
version:
|
|
2164
|
+
version: e,
|
|
2168
2165
|
botInline: s,
|
|
2169
2166
|
createRequestId: n,
|
|
2170
2167
|
postEvent: i
|
|
@@ -2174,80 +2171,80 @@ function $t(r, e, t, s, n, i) {
|
|
|
2174
2171
|
});
|
|
2175
2172
|
return u.on("change", p), u;
|
|
2176
2173
|
}
|
|
2177
|
-
function
|
|
2174
|
+
function Le() {
|
|
2178
2175
|
let r = 0;
|
|
2179
2176
|
return () => (r += 1, r.toString());
|
|
2180
2177
|
}
|
|
2181
|
-
function
|
|
2182
|
-
const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new
|
|
2178
|
+
function Be(r, t, e) {
|
|
2179
|
+
const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new ye(s, t, e);
|
|
2183
2180
|
return n.on("change", () => {
|
|
2184
2181
|
T("settings-button", { isVisible: n.isVisible });
|
|
2185
2182
|
}), n;
|
|
2186
2183
|
}
|
|
2187
|
-
function
|
|
2188
|
-
const
|
|
2189
|
-
return
|
|
2190
|
-
}
|
|
2191
|
-
function
|
|
2192
|
-
const
|
|
2193
|
-
return
|
|
2194
|
-
height:
|
|
2195
|
-
isExpanded:
|
|
2196
|
-
stableHeight:
|
|
2197
|
-
width:
|
|
2198
|
-
})),
|
|
2199
|
-
}
|
|
2200
|
-
function
|
|
2184
|
+
function De(r) {
|
|
2185
|
+
const t = new Pe(r);
|
|
2186
|
+
return t.listen(), t;
|
|
2187
|
+
}
|
|
2188
|
+
function M(r) {
|
|
2189
|
+
const t = new xe(r);
|
|
2190
|
+
return t.on("change", () => T("viewport", {
|
|
2191
|
+
height: t.height,
|
|
2192
|
+
isExpanded: t.isExpanded,
|
|
2193
|
+
stableHeight: t.stableHeight,
|
|
2194
|
+
width: t.width
|
|
2195
|
+
})), t.listen(), t;
|
|
2196
|
+
}
|
|
2197
|
+
function Oe(r, t, e, s) {
|
|
2201
2198
|
const n = r ? $("viewport") : null;
|
|
2202
2199
|
if (n)
|
|
2203
|
-
return
|
|
2204
|
-
if (
|
|
2205
|
-
return
|
|
2200
|
+
return M({ ...n, postEvent: e });
|
|
2201
|
+
if (ke(t))
|
|
2202
|
+
return M({
|
|
2206
2203
|
height: window.innerHeight,
|
|
2207
2204
|
isExpanded: !0,
|
|
2208
|
-
postEvent:
|
|
2205
|
+
postEvent: e,
|
|
2209
2206
|
stableHeight: window.innerHeight,
|
|
2210
2207
|
width: window.innerWidth
|
|
2211
2208
|
});
|
|
2212
2209
|
if (s)
|
|
2213
|
-
return
|
|
2214
|
-
postEvent:
|
|
2210
|
+
return Pt({
|
|
2211
|
+
postEvent: e,
|
|
2215
2212
|
timeout: 5e3
|
|
2216
|
-
}).then(({ height: a, isStateStable: c, ...u }) =>
|
|
2213
|
+
}).then(({ height: a, isStateStable: c, ...u }) => M({
|
|
2217
2214
|
...u,
|
|
2218
2215
|
height: a,
|
|
2219
2216
|
stableHeight: c ? a : 0
|
|
2220
2217
|
}));
|
|
2221
|
-
const i =
|
|
2218
|
+
const i = M({
|
|
2222
2219
|
width: 0,
|
|
2223
2220
|
height: 0,
|
|
2224
2221
|
isExpanded: !1,
|
|
2225
|
-
postEvent:
|
|
2222
|
+
postEvent: e,
|
|
2226
2223
|
stableHeight: 0
|
|
2227
2224
|
});
|
|
2228
|
-
return i.sync({ postEvent:
|
|
2225
|
+
return i.sync({ postEvent: e, timeout: 5e3 }).catch((a) => {
|
|
2229
2226
|
console.error("Unable to actualize viewport state", a);
|
|
2230
2227
|
}), i;
|
|
2231
2228
|
}
|
|
2232
|
-
function
|
|
2229
|
+
function We(r) {
|
|
2233
2230
|
return typeof r == "object" ? r : r ? {
|
|
2234
2231
|
themeParams: !0,
|
|
2235
2232
|
viewport: !0,
|
|
2236
2233
|
miniApp: !0
|
|
2237
2234
|
} : {};
|
|
2238
2235
|
}
|
|
2239
|
-
function
|
|
2240
|
-
const n =
|
|
2241
|
-
n.miniApp &&
|
|
2236
|
+
function at(r, t, e, s) {
|
|
2237
|
+
const n = We(r);
|
|
2238
|
+
n.miniApp && qe(t, e), n.themeParams && Ae(e), n.viewport && (s instanceof Promise ? s.then(ot) : ot(s));
|
|
2242
2239
|
}
|
|
2243
|
-
function
|
|
2244
|
-
return
|
|
2240
|
+
function He() {
|
|
2241
|
+
return et({
|
|
2245
2242
|
botInline: {
|
|
2246
2243
|
type: P().optional(),
|
|
2247
2244
|
from: "tgWebAppBotInline"
|
|
2248
2245
|
},
|
|
2249
2246
|
initData: {
|
|
2250
|
-
type:
|
|
2247
|
+
type: yt().optional(),
|
|
2251
2248
|
from: "tgWebAppData"
|
|
2252
2249
|
},
|
|
2253
2250
|
initDataRaw: {
|
|
@@ -2267,7 +2264,7 @@ function Ht() {
|
|
|
2267
2264
|
from: "tgWebAppStartParam"
|
|
2268
2265
|
},
|
|
2269
2266
|
themeParams: {
|
|
2270
|
-
type:
|
|
2267
|
+
type: Ct(),
|
|
2271
2268
|
from: "tgWebAppThemeParams"
|
|
2272
2269
|
},
|
|
2273
2270
|
version: {
|
|
@@ -2276,71 +2273,72 @@ function Ht() {
|
|
|
2276
2273
|
}
|
|
2277
2274
|
}, "LaunchParams");
|
|
2278
2275
|
}
|
|
2279
|
-
function
|
|
2280
|
-
return
|
|
2276
|
+
function kt(r) {
|
|
2277
|
+
return He().parse(r);
|
|
2281
2278
|
}
|
|
2282
|
-
function
|
|
2283
|
-
|
|
2284
|
-
|
|
2279
|
+
function xt(r) {
|
|
2280
|
+
return kt(
|
|
2281
|
+
r.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&")
|
|
2282
|
+
);
|
|
2285
2283
|
}
|
|
2286
|
-
function
|
|
2287
|
-
return
|
|
2284
|
+
function Ne() {
|
|
2285
|
+
return xt(window.location.href);
|
|
2288
2286
|
}
|
|
2289
|
-
function
|
|
2287
|
+
function qt() {
|
|
2290
2288
|
return performance.getEntriesByType("navigation")[0];
|
|
2291
2289
|
}
|
|
2292
|
-
function
|
|
2293
|
-
const r =
|
|
2290
|
+
function Ue() {
|
|
2291
|
+
const r = qt();
|
|
2294
2292
|
if (!r)
|
|
2295
2293
|
throw new Error("Unable to get first navigation entry.");
|
|
2296
|
-
return
|
|
2294
|
+
return xt(r.name);
|
|
2297
2295
|
}
|
|
2298
|
-
function
|
|
2296
|
+
function Me(r) {
|
|
2299
2297
|
const {
|
|
2300
|
-
initDataRaw:
|
|
2301
|
-
themeParams:
|
|
2298
|
+
initDataRaw: t,
|
|
2299
|
+
themeParams: e,
|
|
2302
2300
|
platform: s,
|
|
2303
2301
|
version: n,
|
|
2304
2302
|
showSettings: i,
|
|
2305
2303
|
startParam: a,
|
|
2306
2304
|
botInline: c
|
|
2307
2305
|
} = r, u = new URLSearchParams();
|
|
2308
|
-
return
|
|
2306
|
+
return t && u.set("tgWebAppData", t), u.set("tgWebAppPlatform", s), u.set("tgWebAppThemeParams", ve(e)), 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();
|
|
2309
2307
|
}
|
|
2310
|
-
const
|
|
2311
|
-
function
|
|
2312
|
-
return
|
|
2308
|
+
const At = "telegram-mini-apps-launch-params";
|
|
2309
|
+
function Ge() {
|
|
2310
|
+
return kt(sessionStorage.getItem(At) || "");
|
|
2313
2311
|
}
|
|
2314
|
-
function
|
|
2315
|
-
sessionStorage.setItem(
|
|
2312
|
+
function je(r) {
|
|
2313
|
+
sessionStorage.setItem(At, Me(r));
|
|
2316
2314
|
}
|
|
2317
|
-
function
|
|
2315
|
+
function rt() {
|
|
2318
2316
|
const r = [];
|
|
2319
|
-
for (const
|
|
2317
|
+
for (const t of [
|
|
2320
2318
|
// Try to retrieve launch parameters from the current location. This method can return
|
|
2321
2319
|
// nothing in case, location was changed and then page was reloaded.
|
|
2322
|
-
|
|
2320
|
+
Ne,
|
|
2323
2321
|
// Then, try using the lower level API - window.performance.
|
|
2324
|
-
|
|
2322
|
+
Ue,
|
|
2325
2323
|
// Finally, try to extract launch parameters from the session storage.
|
|
2326
|
-
|
|
2324
|
+
Ge
|
|
2327
2325
|
])
|
|
2328
2326
|
try {
|
|
2329
|
-
const
|
|
2330
|
-
return
|
|
2331
|
-
} catch (
|
|
2332
|
-
r.push(
|
|
2327
|
+
const e = t();
|
|
2328
|
+
return je(e), e;
|
|
2329
|
+
} catch (e) {
|
|
2330
|
+
r.push(e);
|
|
2333
2331
|
}
|
|
2334
2332
|
throw k.error("Unable to extract launch parameters. Received errors:", r), new Error("Unable to retrieve launch parameters from any known source.");
|
|
2335
2333
|
}
|
|
2336
|
-
function
|
|
2334
|
+
function Vt() {
|
|
2337
2335
|
var r;
|
|
2338
|
-
return ((r =
|
|
2336
|
+
return ((r = qt()) == null ? void 0 : r.type) === "reload";
|
|
2339
2337
|
}
|
|
2340
2338
|
function rr(r = {}) {
|
|
2341
2339
|
const {
|
|
2342
|
-
async:
|
|
2343
|
-
complete:
|
|
2340
|
+
async: t = !1,
|
|
2341
|
+
complete: e = t,
|
|
2344
2342
|
cssVars: s = !1,
|
|
2345
2343
|
acceptCustomStyles: n = !1
|
|
2346
2344
|
} = r;
|
|
@@ -2352,24 +2350,24 @@ function rr(r = {}) {
|
|
|
2352
2350
|
platform: u,
|
|
2353
2351
|
themeParams: p,
|
|
2354
2352
|
botInline: g = !1
|
|
2355
|
-
} =
|
|
2356
|
-
|
|
2353
|
+
} = rt(), _ = Vt(), b = Le(), l = Ot(c);
|
|
2354
|
+
pt() && (n && Ve(), l("iframe_ready", { reload_supported: !0 }), E("reload_iframe", () => {
|
|
2357
2355
|
l("iframe_will_reload"), window.location.reload();
|
|
2358
2356
|
}));
|
|
2359
2357
|
const q = {
|
|
2360
|
-
backButton:
|
|
2361
|
-
closingBehavior:
|
|
2362
|
-
cloudStorage: new
|
|
2358
|
+
backButton: Re(_, c, l),
|
|
2359
|
+
closingBehavior: Ie(_, l),
|
|
2360
|
+
cloudStorage: new ae(c, b, l),
|
|
2363
2361
|
createRequestId: b,
|
|
2364
|
-
hapticFeedback: new
|
|
2365
|
-
invoice: new
|
|
2366
|
-
mainButton:
|
|
2362
|
+
hapticFeedback: new ce(c, l),
|
|
2363
|
+
invoice: new le(c, l),
|
|
2364
|
+
mainButton: Te(
|
|
2367
2365
|
_,
|
|
2368
2366
|
p.buttonColor || "#000000",
|
|
2369
2367
|
p.buttonTextColor || "#ffffff",
|
|
2370
2368
|
l
|
|
2371
2369
|
),
|
|
2372
|
-
miniApp: $
|
|
2370
|
+
miniApp: $e(
|
|
2373
2371
|
_,
|
|
2374
2372
|
p.backgroundColor || "#ffffff",
|
|
2375
2373
|
c,
|
|
@@ -2377,86 +2375,86 @@ function rr(r = {}) {
|
|
|
2377
2375
|
b,
|
|
2378
2376
|
l
|
|
2379
2377
|
),
|
|
2380
|
-
popup: new
|
|
2378
|
+
popup: new be(c, l),
|
|
2381
2379
|
postEvent: l,
|
|
2382
|
-
qrScanner: new
|
|
2383
|
-
settingsButton:
|
|
2384
|
-
themeParams:
|
|
2385
|
-
utils: new
|
|
2380
|
+
qrScanner: new me(c, l),
|
|
2381
|
+
settingsButton: Be(_, c, l),
|
|
2382
|
+
themeParams: De(p),
|
|
2383
|
+
utils: new Se(c, b, l),
|
|
2386
2384
|
...i ? {
|
|
2387
|
-
initData: new
|
|
2385
|
+
initData: new ue(i),
|
|
2388
2386
|
initDataRaw: a
|
|
2389
2387
|
} : {}
|
|
2390
|
-
},
|
|
2391
|
-
return
|
|
2388
|
+
}, N = Oe(_, u, l, e);
|
|
2389
|
+
return N instanceof Promise || e ? Promise.resolve(N).then((st) => (at(
|
|
2392
2390
|
s,
|
|
2393
2391
|
q.miniApp,
|
|
2394
2392
|
q.themeParams,
|
|
2395
|
-
|
|
2396
|
-
), { ...q, viewport:
|
|
2393
|
+
st
|
|
2394
|
+
), { ...q, viewport: st })) : (at(
|
|
2397
2395
|
s,
|
|
2398
2396
|
q.miniApp,
|
|
2399
2397
|
q.themeParams,
|
|
2400
|
-
|
|
2401
|
-
), { ...q, viewport:
|
|
2398
|
+
N
|
|
2399
|
+
), { ...q, viewport: N });
|
|
2402
2400
|
} catch (i) {
|
|
2403
|
-
if (
|
|
2401
|
+
if (e)
|
|
2404
2402
|
return Promise.reject(i);
|
|
2405
2403
|
throw i;
|
|
2406
2404
|
}
|
|
2407
2405
|
}
|
|
2408
2406
|
function sr() {
|
|
2409
2407
|
return {
|
|
2410
|
-
launchParams:
|
|
2411
|
-
isPageReload:
|
|
2408
|
+
launchParams: rt(),
|
|
2409
|
+
isPageReload: Vt()
|
|
2412
2410
|
};
|
|
2413
2411
|
}
|
|
2414
2412
|
function nr() {
|
|
2415
2413
|
try {
|
|
2416
|
-
return
|
|
2414
|
+
return rt(), !0;
|
|
2417
2415
|
} catch {
|
|
2418
2416
|
return !1;
|
|
2419
2417
|
}
|
|
2420
2418
|
}
|
|
2421
2419
|
function ir(r) {
|
|
2422
|
-
const
|
|
2423
|
-
return
|
|
2420
|
+
const t = r.match(/#(.+)/);
|
|
2421
|
+
return t ? t[1] : null;
|
|
2424
2422
|
}
|
|
2425
|
-
async function
|
|
2423
|
+
async function O(r) {
|
|
2426
2424
|
return r === 0 ? !0 : Promise.race([
|
|
2427
|
-
new Promise((
|
|
2428
|
-
window.addEventListener("popstate", function
|
|
2429
|
-
window.removeEventListener("popstate",
|
|
2425
|
+
new Promise((t) => {
|
|
2426
|
+
window.addEventListener("popstate", function e() {
|
|
2427
|
+
window.removeEventListener("popstate", e), t(!0);
|
|
2430
2428
|
}), window.history.go(r);
|
|
2431
2429
|
}),
|
|
2432
2430
|
// Usually, it takes about 1ms to emit this event, but we use some buffer.
|
|
2433
|
-
new Promise((
|
|
2434
|
-
setTimeout(
|
|
2431
|
+
new Promise((t) => {
|
|
2432
|
+
setTimeout(t, 50, !1);
|
|
2435
2433
|
})
|
|
2436
2434
|
]);
|
|
2437
2435
|
}
|
|
2438
|
-
async function
|
|
2439
|
-
if (window.history.length <= 1 || (window.history.pushState(null, ""), await
|
|
2436
|
+
async function Fe() {
|
|
2437
|
+
if (window.history.length <= 1 || (window.history.pushState(null, ""), await O(1 - window.history.length)))
|
|
2440
2438
|
return;
|
|
2441
|
-
let
|
|
2442
|
-
for (;
|
|
2443
|
-
|
|
2439
|
+
let t = await O(-1);
|
|
2440
|
+
for (; t; )
|
|
2441
|
+
t = await O(-1);
|
|
2444
2442
|
}
|
|
2445
|
-
function B(r,
|
|
2446
|
-
return r.startsWith(
|
|
2443
|
+
function B(r, t) {
|
|
2444
|
+
return r.startsWith(t) ? r : `${t}${r}`;
|
|
2447
2445
|
}
|
|
2448
|
-
class
|
|
2449
|
-
constructor(
|
|
2446
|
+
class ze {
|
|
2447
|
+
constructor(t, e, {
|
|
2450
2448
|
debug: s = !1,
|
|
2451
2449
|
loggerPrefix: n = "Navigator"
|
|
2452
2450
|
}) {
|
|
2453
2451
|
o(this, "logger");
|
|
2454
2452
|
o(this, "entries");
|
|
2455
|
-
if (this.entriesCursor =
|
|
2453
|
+
if (this.entriesCursor = e, t.length === 0)
|
|
2456
2454
|
throw new Error("Entries list should not be empty.");
|
|
2457
|
-
if (
|
|
2455
|
+
if (e >= t.length)
|
|
2458
2456
|
throw new Error("Cursor should be less than entries count.");
|
|
2459
|
-
this.entries =
|
|
2457
|
+
this.entries = t.map(({ pathname: i = "", search: a, hash: c }) => {
|
|
2460
2458
|
if (!i.startsWith("/") && i.length > 0)
|
|
2461
2459
|
throw new Error('Pathname should start with "/"');
|
|
2462
2460
|
return {
|
|
@@ -2464,29 +2462,29 @@ class zt {
|
|
|
2464
2462
|
search: a ? B(a, "?") : "",
|
|
2465
2463
|
hash: c ? B(c, "#") : ""
|
|
2466
2464
|
};
|
|
2467
|
-
}), this.logger = new
|
|
2465
|
+
}), this.logger = new ht(`[${n}]`, s);
|
|
2468
2466
|
}
|
|
2469
2467
|
/**
|
|
2470
2468
|
* Converts entry to the navigation entry.
|
|
2471
2469
|
* @param entry - entry data
|
|
2472
2470
|
*/
|
|
2473
|
-
formatEntry(
|
|
2474
|
-
let
|
|
2475
|
-
if (typeof
|
|
2476
|
-
|
|
2471
|
+
formatEntry(t) {
|
|
2472
|
+
let e;
|
|
2473
|
+
if (typeof t == "string")
|
|
2474
|
+
e = t;
|
|
2477
2475
|
else {
|
|
2478
2476
|
const {
|
|
2479
2477
|
pathname: a = "",
|
|
2480
2478
|
search: c,
|
|
2481
2479
|
hash: u
|
|
2482
|
-
} =
|
|
2483
|
-
|
|
2480
|
+
} = t;
|
|
2481
|
+
e = a + (c ? B(c, "?") : "") + (u ? B(u, "#") : "");
|
|
2484
2482
|
}
|
|
2485
2483
|
const {
|
|
2486
2484
|
pathname: s,
|
|
2487
2485
|
search: n,
|
|
2488
2486
|
hash: i
|
|
2489
|
-
} = new URL(
|
|
2487
|
+
} = new URL(e, `https://localhost${this.path}`);
|
|
2490
2488
|
return {
|
|
2491
2489
|
pathname: s,
|
|
2492
2490
|
search: n,
|
|
@@ -2533,23 +2531,23 @@ class zt {
|
|
|
2533
2531
|
* Moves entries cursor by specified delta.
|
|
2534
2532
|
* @param delta - cursor delta.
|
|
2535
2533
|
*/
|
|
2536
|
-
go(
|
|
2537
|
-
this.logger.log(`called go(${
|
|
2538
|
-
const
|
|
2534
|
+
go(t) {
|
|
2535
|
+
this.logger.log(`called go(${t})`);
|
|
2536
|
+
const e = Math.min(
|
|
2539
2537
|
this.entries.length - 1,
|
|
2540
|
-
Math.max(this.entriesCursor +
|
|
2538
|
+
Math.max(this.entriesCursor + t, 0)
|
|
2541
2539
|
);
|
|
2542
|
-
if (this.entriesCursor ===
|
|
2540
|
+
if (this.entriesCursor === e)
|
|
2543
2541
|
return this.performGo({
|
|
2544
2542
|
updated: !1,
|
|
2545
|
-
delta:
|
|
2543
|
+
delta: t
|
|
2546
2544
|
});
|
|
2547
2545
|
const s = this.entry;
|
|
2548
|
-
this.entriesCursor =
|
|
2546
|
+
this.entriesCursor = e;
|
|
2549
2547
|
const n = this.entry;
|
|
2550
2548
|
return this.logger.log("State changed", { before: s, after: n }), this.performGo({
|
|
2551
2549
|
updated: !0,
|
|
2552
|
-
delta:
|
|
2550
|
+
delta: t,
|
|
2553
2551
|
before: s,
|
|
2554
2552
|
after: n
|
|
2555
2553
|
});
|
|
@@ -2558,7 +2556,7 @@ class zt {
|
|
|
2558
2556
|
* Returns copy of navigator entries.
|
|
2559
2557
|
*/
|
|
2560
2558
|
getEntries() {
|
|
2561
|
-
return this.entries.map((
|
|
2559
|
+
return this.entries.map((t) => ({ ...t }));
|
|
2562
2560
|
}
|
|
2563
2561
|
/**
|
|
2564
2562
|
* Current hash.
|
|
@@ -2589,10 +2587,10 @@ class zt {
|
|
|
2589
2587
|
* push("#my-hash"); // "/home" -> "/home#my-hash"
|
|
2590
2588
|
* push("johny#my-hash"); // "/home/root" -> "/home/johny#my-hash"
|
|
2591
2589
|
*/
|
|
2592
|
-
push(
|
|
2590
|
+
push(t) {
|
|
2593
2591
|
this.entriesCursor !== this.entries.length - 1 && this.entries.splice(this.entriesCursor + 1);
|
|
2594
|
-
const
|
|
2595
|
-
this.entriesCursor += 1, this.entries[this.entriesCursor] =
|
|
2592
|
+
const e = this.formatEntry(t), s = this.entry;
|
|
2593
|
+
this.entriesCursor += 1, this.entries[this.entriesCursor] = e;
|
|
2596
2594
|
const n = this.entry;
|
|
2597
2595
|
return this.logger.log("State changed", { before: s, after: n }), this.performPush({
|
|
2598
2596
|
before: s,
|
|
@@ -2619,15 +2617,15 @@ class zt {
|
|
|
2619
2617
|
* @see push
|
|
2620
2618
|
* @returns True if changes were done.
|
|
2621
2619
|
*/
|
|
2622
|
-
replace(
|
|
2623
|
-
const
|
|
2624
|
-
if (this.search ===
|
|
2620
|
+
replace(t) {
|
|
2621
|
+
const e = this.formatEntry(t);
|
|
2622
|
+
if (this.search === e.search && this.pathname === e.pathname && this.hash === e.hash)
|
|
2625
2623
|
return this.performReplace({
|
|
2626
2624
|
updated: !1,
|
|
2627
|
-
entry:
|
|
2625
|
+
entry: e
|
|
2628
2626
|
});
|
|
2629
2627
|
const s = this.entry;
|
|
2630
|
-
this.entries[this.entriesCursor] =
|
|
2628
|
+
this.entries[this.entriesCursor] = e;
|
|
2631
2629
|
const n = this.entry;
|
|
2632
2630
|
return this.logger.log("State changed", { before: s, after: n }), this.performReplace({
|
|
2633
2631
|
updated: !0,
|
|
@@ -2644,10 +2642,10 @@ class zt {
|
|
|
2644
2642
|
return this.entry.search;
|
|
2645
2643
|
}
|
|
2646
2644
|
}
|
|
2647
|
-
const
|
|
2648
|
-
class
|
|
2649
|
-
constructor(
|
|
2650
|
-
super(
|
|
2645
|
+
const ct = 0, Q = 1, Z = 2;
|
|
2646
|
+
class Rt extends ze {
|
|
2647
|
+
constructor(e, s, n = {}) {
|
|
2648
|
+
super(e, s, {
|
|
2651
2649
|
...n,
|
|
2652
2650
|
loggerPrefix: "HashNavigator"
|
|
2653
2651
|
});
|
|
@@ -2657,16 +2655,16 @@ class Ve extends zt {
|
|
|
2657
2655
|
* Handles window "popstate" event.
|
|
2658
2656
|
* @param state - event state.
|
|
2659
2657
|
*/
|
|
2660
|
-
o(this, "onPopState", async ({ state:
|
|
2661
|
-
if (this.logger.log('"popstate" event received. State:',
|
|
2658
|
+
o(this, "onPopState", async ({ state: e }) => {
|
|
2659
|
+
if (this.logger.log('"popstate" event received. State:', e), e === null)
|
|
2662
2660
|
return this.push(window.location.hash.slice(1));
|
|
2663
|
-
if (
|
|
2661
|
+
if (e === ct) {
|
|
2664
2662
|
this.logger.log("Void reached. Moving history forward"), window.history.forward();
|
|
2665
2663
|
return;
|
|
2666
2664
|
}
|
|
2667
|
-
if (
|
|
2665
|
+
if (e === Q)
|
|
2668
2666
|
return this.back();
|
|
2669
|
-
if (
|
|
2667
|
+
if (e === Z)
|
|
2670
2668
|
return this.forward();
|
|
2671
2669
|
});
|
|
2672
2670
|
o(this, "back", () => super.back());
|
|
@@ -2683,7 +2681,7 @@ class Ve extends zt {
|
|
|
2683
2681
|
* Creates navigator from current window location hash.
|
|
2684
2682
|
* @param options - options passed to constructor.
|
|
2685
2683
|
*/
|
|
2686
|
-
static fromLocation(
|
|
2684
|
+
static fromLocation(e) {
|
|
2687
2685
|
const {
|
|
2688
2686
|
search: s,
|
|
2689
2687
|
pathname: n,
|
|
@@ -2692,29 +2690,29 @@ class Ve extends zt {
|
|
|
2692
2690
|
window.location.hash.slice(1),
|
|
2693
2691
|
window.location.href
|
|
2694
2692
|
);
|
|
2695
|
-
return new
|
|
2693
|
+
return new Rt([{ search: s, pathname: n, hash: i }], 0, e);
|
|
2696
2694
|
}
|
|
2697
|
-
async performGo(
|
|
2698
|
-
|
|
2695
|
+
async performGo(e) {
|
|
2696
|
+
e.updated && (this.attached && await this.syncHistory(), this.emitChanged(e.before, e.after));
|
|
2699
2697
|
}
|
|
2700
|
-
async performPush({ before:
|
|
2701
|
-
this.attached && await this.syncHistory(), this.emitChanged(
|
|
2698
|
+
async performPush({ before: e, after: s }) {
|
|
2699
|
+
this.attached && await this.syncHistory(), this.emitChanged(e, s);
|
|
2702
2700
|
}
|
|
2703
|
-
async performReplace(
|
|
2704
|
-
|
|
2701
|
+
async performReplace(e) {
|
|
2702
|
+
e.updated && (this.attached && window.history.replaceState(null, "", `#${this.path}`), this.emitChanged(e.before, e.after));
|
|
2705
2703
|
}
|
|
2706
2704
|
/**
|
|
2707
2705
|
* Synchronizes current navigator state with browser history.
|
|
2708
2706
|
*/
|
|
2709
2707
|
async syncHistory() {
|
|
2710
2708
|
window.removeEventListener("popstate", this.onPopState);
|
|
2711
|
-
const
|
|
2712
|
-
await
|
|
2709
|
+
const e = `#${this.path}`;
|
|
2710
|
+
await Fe(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Q, ""), window.history.pushState(null, "", e), window.history.pushState(Z, ""), await O(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Q, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(Z, ""), await O(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ct, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
|
|
2713
2711
|
}
|
|
2714
|
-
emitChanged(
|
|
2712
|
+
emitChanged(e, s) {
|
|
2715
2713
|
this.ee.emit("change", {
|
|
2716
2714
|
navigator: this,
|
|
2717
|
-
from:
|
|
2715
|
+
from: e,
|
|
2718
2716
|
to: s
|
|
2719
2717
|
});
|
|
2720
2718
|
}
|
|
@@ -2733,83 +2731,83 @@ class Ve extends zt {
|
|
|
2733
2731
|
}
|
|
2734
2732
|
}
|
|
2735
2733
|
function or(r) {
|
|
2736
|
-
return r instanceof
|
|
2734
|
+
return r instanceof z;
|
|
2737
2735
|
}
|
|
2738
2736
|
export {
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2737
|
+
re as BackButton,
|
|
2738
|
+
se as ClosingBehavior,
|
|
2739
|
+
ae as CloudStorage,
|
|
2740
|
+
ce as HapticFeedback,
|
|
2741
|
+
Rt as HashNavigator,
|
|
2742
|
+
ue as InitData,
|
|
2743
|
+
le as Invoice,
|
|
2744
|
+
de as MainButton,
|
|
2745
|
+
K as MethodUnsupportedError,
|
|
2746
|
+
we as MiniApp,
|
|
2747
|
+
ze as Navigator,
|
|
2748
|
+
Y as ParameterUnsupportedError,
|
|
2749
|
+
j as ParseError,
|
|
2750
|
+
G as ParseSchemaFieldError,
|
|
2751
|
+
be as Popup,
|
|
2752
|
+
me as QRScanner,
|
|
2753
|
+
ye as SettingsButton,
|
|
2754
|
+
Pe as ThemeParams,
|
|
2755
|
+
z as TimeoutError,
|
|
2756
|
+
Se as Utils,
|
|
2757
|
+
xe as Viewport,
|
|
2758
|
+
oe as array,
|
|
2759
|
+
qe as bindMiniAppCSSVars,
|
|
2760
|
+
Ae as bindThemeCSSVars,
|
|
2761
|
+
ot as bindViewportCSSVars,
|
|
2764
2762
|
P as boolean,
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2763
|
+
he as chatParser,
|
|
2764
|
+
_t as classNames,
|
|
2765
|
+
Dt as compareVersions,
|
|
2766
|
+
Ot as createPostEvent,
|
|
2767
|
+
mt as date,
|
|
2770
2768
|
ir as getHash,
|
|
2771
2769
|
rr as init,
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2770
|
+
yt as initDataParser,
|
|
2771
|
+
D as invokeCustomMethod,
|
|
2772
|
+
bt as isColorDark,
|
|
2773
|
+
pt as isIframe,
|
|
2774
|
+
Vt as isPageReload,
|
|
2775
|
+
tt as isRGB,
|
|
2776
|
+
Qt as isRGBShort,
|
|
2777
|
+
W as isRecord,
|
|
2778
|
+
ke as isStableViewportPlatform,
|
|
2781
2779
|
nr as isTMA,
|
|
2782
2780
|
or as isTimeoutError,
|
|
2783
2781
|
f as json,
|
|
2784
|
-
|
|
2785
|
-
|
|
2782
|
+
He as launchParamsParser,
|
|
2783
|
+
Xe as mergeClassNames,
|
|
2786
2784
|
x as number,
|
|
2787
2785
|
I as off,
|
|
2788
2786
|
E as on,
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2787
|
+
Ke as once,
|
|
2788
|
+
tr as parseInitData,
|
|
2789
|
+
kt as parseLaunchParams,
|
|
2790
|
+
Wt as parseMessage,
|
|
2791
|
+
vt as parseThemeParams,
|
|
2794
2792
|
d as postEvent,
|
|
2795
2793
|
y as request,
|
|
2796
|
-
|
|
2797
|
-
|
|
2794
|
+
er as requestThemeParams,
|
|
2795
|
+
Pt as requestViewport,
|
|
2798
2796
|
sr as retrieveLaunchData,
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2797
|
+
rt as retrieveLaunchParams,
|
|
2798
|
+
gt as rgb,
|
|
2799
|
+
et as searchParams,
|
|
2800
|
+
Me as serializeLaunchParams,
|
|
2801
|
+
ve as serializeThemeParams,
|
|
2804
2802
|
S as setCSSVar,
|
|
2805
|
-
|
|
2806
|
-
|
|
2803
|
+
Qe as setDebug,
|
|
2804
|
+
Ze as setTargetOrigin,
|
|
2807
2805
|
h as string,
|
|
2808
|
-
|
|
2806
|
+
Ye as subscribe,
|
|
2809
2807
|
A as supports,
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2808
|
+
Ct as themeParamsParser,
|
|
2809
|
+
ft as toRGB,
|
|
2810
|
+
ee as unsubscribe,
|
|
2811
|
+
it as userParser,
|
|
2812
|
+
wt as withTimeout
|
|
2815
2813
|
};
|