@tma.js/sdk 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +1 -1
- package/dist/dts/bridge/index.d.ts +1 -0
- package/dist/dts/bridge/invoke-custom-method.d.ts +18 -0
- package/dist/dts/bridge/methods/custom-methods.d.ts +56 -0
- package/dist/dts/bridge/methods/index.d.ts +1 -1
- package/dist/dts/bridge/methods/methods.d.ts +1 -1
- package/dist/dts/bridge/request.d.ts +3 -12
- package/dist/dts/cloud-storage/CloudStorage.d.ts +7 -16
- package/dist/dts/index.d.ts +7 -6
- package/dist/dts/init/creators/createMiniApp.d.ts +3 -1
- package/dist/dts/mini-app/MiniApp.d.ts +34 -4
- package/dist/dts/mini-app/contactParser.d.ts +2 -0
- package/dist/dts/mini-app/types.d.ts +12 -0
- package/dist/dts/timeout/index.d.ts +1 -0
- package/dist/dts/timeout/sleep.d.ts +5 -0
- package/dist/dts/timeout/withTimeout.d.ts +5 -12
- package/dist/dts/types/index.d.ts +1 -0
- package/dist/dts/types/methods.d.ts +15 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +610 -484
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/bridge/events/parsers/phoneRequested.ts +1 -1
- package/src/bridge/index.ts +1 -0
- package/src/bridge/invoke-custom-method.ts +56 -0
- package/src/bridge/methods/custom-methods.ts +68 -0
- package/src/bridge/methods/index.ts +1 -1
- package/src/bridge/methods/methods.ts +3 -5
- package/src/bridge/request.ts +35 -44
- package/src/cloud-storage/CloudStorage.ts +36 -53
- package/src/index.ts +8 -20
- package/src/init/creators/createMiniApp.ts +4 -0
- package/src/init/init.ts +1 -0
- package/src/mini-app/MiniApp.ts +131 -20
- package/src/mini-app/contactParser.ts +29 -0
- package/src/mini-app/types.ts +13 -0
- package/src/timeout/index.ts +1 -0
- package/src/timeout/sleep.ts +10 -0
- package/src/timeout/withTimeout.ts +10 -22
- package/src/types/index.ts +1 -0
- package/src/types/methods.ts +18 -0
- package/dist/dts/bridge/methods/invoke-custom-method.d.ts +0 -24
- package/src/bridge/methods/invoke-custom-method.ts +0 -25
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
var $t = Object.defineProperty;
|
|
2
2
|
var Tt = (r, t, e) => t in r ? $t(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
3
|
var o = (r, t, e) => (Tt(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
-
function
|
|
4
|
+
function H(r) {
|
|
5
5
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function ht() {
|
|
8
8
|
return performance.getEntriesByType("navigation")[0] || null;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const r =
|
|
10
|
+
function Bt() {
|
|
11
|
+
const r = ht();
|
|
12
12
|
return r ? r.type === "reload" : null;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function R() {
|
|
15
15
|
return new TypeError("Value has unexpected type");
|
|
16
16
|
}
|
|
17
|
-
class
|
|
17
|
+
class F extends Error {
|
|
18
18
|
constructor(e, { cause: s, type: n } = {}) {
|
|
19
19
|
super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
|
|
20
20
|
/**
|
|
21
21
|
* Parser name.
|
|
22
22
|
*/
|
|
23
23
|
o(this, "type");
|
|
24
|
-
this.value = e, Object.setPrototypeOf(this,
|
|
24
|
+
this.value = e, Object.setPrototypeOf(this, F.prototype), this.type = n;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
class
|
|
27
|
+
class z {
|
|
28
28
|
constructor(t, e, s) {
|
|
29
29
|
this.parser = t, this.isOptional = e, this.type = s;
|
|
30
30
|
}
|
|
@@ -33,14 +33,14 @@ class F {
|
|
|
33
33
|
try {
|
|
34
34
|
return this.parser(t);
|
|
35
35
|
} catch (e) {
|
|
36
|
-
throw new
|
|
36
|
+
throw new F(t, { type: this.type, cause: e });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
optional() {
|
|
40
40
|
return this.isOptional = !0, this;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function Dt(r) {
|
|
44
44
|
if (Array.isArray(r))
|
|
45
45
|
return r;
|
|
46
46
|
if (typeof r == "string")
|
|
@@ -50,11 +50,11 @@ function Rt(r) {
|
|
|
50
50
|
return t;
|
|
51
51
|
} catch {
|
|
52
52
|
}
|
|
53
|
-
throw
|
|
53
|
+
throw R();
|
|
54
54
|
}
|
|
55
|
-
class
|
|
55
|
+
class Wt extends z {
|
|
56
56
|
constructor(e, s, n) {
|
|
57
|
-
super(
|
|
57
|
+
super(Dt, s, n);
|
|
58
58
|
o(this, "itemParser");
|
|
59
59
|
this.itemParser = typeof e == "function" ? e : e.parse.bind(e);
|
|
60
60
|
}
|
|
@@ -66,15 +66,15 @@ class Bt extends F {
|
|
|
66
66
|
return this.itemParser = typeof e == "function" ? e : e.parse.bind(e), this;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
return () => new
|
|
69
|
+
function V(r, t) {
|
|
70
|
+
return () => new z(r, !1, t);
|
|
71
71
|
}
|
|
72
|
-
class
|
|
72
|
+
class j extends Error {
|
|
73
73
|
constructor(t, { cause: e, type: s } = {}) {
|
|
74
|
-
super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this,
|
|
74
|
+
super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, j.prototype);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function ut(r, t) {
|
|
78
78
|
const e = {};
|
|
79
79
|
for (const s in r) {
|
|
80
80
|
const n = r[s];
|
|
@@ -84,27 +84,27 @@ function ht(r, t) {
|
|
|
84
84
|
if (typeof n == "function" || "parse" in n)
|
|
85
85
|
i = s, a = typeof n == "function" ? n : n.parse.bind(n);
|
|
86
86
|
else {
|
|
87
|
-
const { type:
|
|
88
|
-
i = n.from || s, a = typeof
|
|
87
|
+
const { type: p } = n;
|
|
88
|
+
i = n.from || s, a = typeof p == "function" ? p : p.parse.bind(p);
|
|
89
89
|
}
|
|
90
90
|
let c;
|
|
91
91
|
const u = t(i);
|
|
92
92
|
try {
|
|
93
93
|
c = a(u);
|
|
94
|
-
} catch (
|
|
95
|
-
throw
|
|
96
|
-
type:
|
|
97
|
-
cause:
|
|
98
|
-
}) : new
|
|
94
|
+
} catch (p) {
|
|
95
|
+
throw p instanceof F ? new j(i, {
|
|
96
|
+
type: p.type,
|
|
97
|
+
cause: p
|
|
98
|
+
}) : new j(i, { cause: p });
|
|
99
99
|
}
|
|
100
100
|
c !== void 0 && (e[s] = c);
|
|
101
101
|
}
|
|
102
102
|
return e;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return new
|
|
104
|
+
function Nt(r) {
|
|
105
|
+
return new Wt((t) => t, !1, r);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const P = V((r) => {
|
|
108
108
|
if (typeof r == "boolean")
|
|
109
109
|
return r;
|
|
110
110
|
const t = String(r);
|
|
@@ -112,8 +112,8 @@ const k = L((r) => {
|
|
|
112
112
|
return !0;
|
|
113
113
|
if (t === "0" || t === "false")
|
|
114
114
|
return !1;
|
|
115
|
-
throw
|
|
116
|
-
}, "boolean"),
|
|
115
|
+
throw R();
|
|
116
|
+
}, "boolean"), k = V((r) => {
|
|
117
117
|
if (typeof r == "number")
|
|
118
118
|
return r;
|
|
119
119
|
if (typeof r == "string") {
|
|
@@ -121,31 +121,31 @@ const k = L((r) => {
|
|
|
121
121
|
if (!Number.isNaN(t))
|
|
122
122
|
return t;
|
|
123
123
|
}
|
|
124
|
-
throw
|
|
125
|
-
}, "number"),
|
|
126
|
-
function
|
|
124
|
+
throw R();
|
|
125
|
+
}, "number"), pt = V((r) => r instanceof Date ? r : new Date(k().parse(r) * 1e3), "Date");
|
|
126
|
+
function Y(r) {
|
|
127
127
|
let t = r;
|
|
128
128
|
if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
|
|
129
|
-
throw
|
|
129
|
+
throw R();
|
|
130
130
|
return t;
|
|
131
131
|
}
|
|
132
132
|
function g(r, t) {
|
|
133
|
-
return new
|
|
134
|
-
const s =
|
|
135
|
-
return
|
|
133
|
+
return new z((e) => {
|
|
134
|
+
const s = Y(e);
|
|
135
|
+
return ut(r, (n) => s[n]);
|
|
136
136
|
}, !1, t);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function lt(r) {
|
|
139
139
|
return /^#[\da-f]{6}$/i.test(r);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function Ot(r) {
|
|
142
142
|
return /^#[\da-f]{3}$/i.test(r);
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function dt(r) {
|
|
145
145
|
const t = r.replace(/\s/g, "").toLowerCase();
|
|
146
|
-
if (
|
|
146
|
+
if (lt(t))
|
|
147
147
|
return t;
|
|
148
|
-
if (
|
|
148
|
+
if (Ot(t)) {
|
|
149
149
|
let s = "#";
|
|
150
150
|
for (let n = 0; n < 3; n += 1)
|
|
151
151
|
s += t[1 + n].repeat(2);
|
|
@@ -159,8 +159,8 @@ function pt(r) {
|
|
|
159
159
|
return s + (i.length === 1 ? "0" : "") + i;
|
|
160
160
|
}, "#");
|
|
161
161
|
}
|
|
162
|
-
function
|
|
163
|
-
const t =
|
|
162
|
+
function ft(r) {
|
|
163
|
+
const t = dt(r);
|
|
164
164
|
return Math.sqrt(
|
|
165
165
|
[0.299, 0.587, 0.114].reduce((s, n, i) => {
|
|
166
166
|
const a = parseInt(t.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
|
|
@@ -168,25 +168,25 @@ function lt(r) {
|
|
|
168
168
|
}, 0)
|
|
169
169
|
) < 120;
|
|
170
170
|
}
|
|
171
|
-
const h =
|
|
171
|
+
const h = V((r) => {
|
|
172
172
|
if (typeof r == "string" || typeof r == "number")
|
|
173
173
|
return r.toString();
|
|
174
|
-
throw
|
|
175
|
-
}, "string"),
|
|
176
|
-
function
|
|
177
|
-
return new
|
|
174
|
+
throw R();
|
|
175
|
+
}, "string"), gt = V((r) => dt(h().parse(r)), "rgb");
|
|
176
|
+
function X(r, t) {
|
|
177
|
+
return new z((e) => {
|
|
178
178
|
if (typeof e != "string" && !(e instanceof URLSearchParams))
|
|
179
|
-
throw
|
|
179
|
+
throw R();
|
|
180
180
|
const s = typeof e == "string" ? new URLSearchParams(e) : e;
|
|
181
|
-
return
|
|
181
|
+
return ut(r, (n) => {
|
|
182
182
|
const i = s.get(n);
|
|
183
183
|
return i === null ? void 0 : i;
|
|
184
184
|
});
|
|
185
185
|
}, !1, t);
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function Ht() {
|
|
188
188
|
return g({
|
|
189
|
-
id:
|
|
189
|
+
id: k(),
|
|
190
190
|
type: h(),
|
|
191
191
|
title: h(),
|
|
192
192
|
photoUrl: {
|
|
@@ -196,7 +196,7 @@ function Ot() {
|
|
|
196
196
|
username: h().optional()
|
|
197
197
|
}, "Chat");
|
|
198
198
|
}
|
|
199
|
-
class
|
|
199
|
+
class Ut {
|
|
200
200
|
constructor(t) {
|
|
201
201
|
this.initData = t;
|
|
202
202
|
}
|
|
@@ -269,27 +269,27 @@ class Wt {
|
|
|
269
269
|
return this.initData.user;
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function rt() {
|
|
273
273
|
return g({
|
|
274
274
|
addedToAttachmentMenu: {
|
|
275
|
-
type:
|
|
275
|
+
type: P().optional(),
|
|
276
276
|
from: "added_to_attachment_menu"
|
|
277
277
|
},
|
|
278
278
|
allowsWriteToPm: {
|
|
279
|
-
type:
|
|
279
|
+
type: P().optional(),
|
|
280
280
|
from: "allows_write_to_pm"
|
|
281
281
|
},
|
|
282
282
|
firstName: {
|
|
283
283
|
type: h(),
|
|
284
284
|
from: "first_name"
|
|
285
285
|
},
|
|
286
|
-
id:
|
|
286
|
+
id: k(),
|
|
287
287
|
isBot: {
|
|
288
|
-
type:
|
|
288
|
+
type: P().optional(),
|
|
289
289
|
from: "is_bot"
|
|
290
290
|
},
|
|
291
291
|
isPremium: {
|
|
292
|
-
type:
|
|
292
|
+
type: P().optional(),
|
|
293
293
|
from: "is_premium"
|
|
294
294
|
},
|
|
295
295
|
languageCode: {
|
|
@@ -307,17 +307,17 @@ function tt() {
|
|
|
307
307
|
username: h().optional()
|
|
308
308
|
}, "User");
|
|
309
309
|
}
|
|
310
|
-
function
|
|
311
|
-
return
|
|
310
|
+
function wt() {
|
|
311
|
+
return X({
|
|
312
312
|
authDate: {
|
|
313
|
-
type:
|
|
313
|
+
type: pt(),
|
|
314
314
|
from: "auth_date"
|
|
315
315
|
},
|
|
316
316
|
canSendAfter: {
|
|
317
|
-
type:
|
|
317
|
+
type: k().optional(),
|
|
318
318
|
from: "can_send_after"
|
|
319
319
|
},
|
|
320
|
-
chat:
|
|
320
|
+
chat: Ht().optional(),
|
|
321
321
|
chatInstance: {
|
|
322
322
|
type: h().optional(),
|
|
323
323
|
from: "chat_instance"
|
|
@@ -331,42 +331,42 @@ function gt() {
|
|
|
331
331
|
type: h().optional(),
|
|
332
332
|
from: "query_id"
|
|
333
333
|
},
|
|
334
|
-
receiver:
|
|
334
|
+
receiver: rt().optional(),
|
|
335
335
|
startParam: {
|
|
336
336
|
type: h().optional(),
|
|
337
337
|
from: "start_param"
|
|
338
338
|
},
|
|
339
|
-
user:
|
|
339
|
+
user: rt().optional()
|
|
340
340
|
}, "InitData");
|
|
341
341
|
}
|
|
342
|
-
function
|
|
343
|
-
return
|
|
342
|
+
function er(r) {
|
|
343
|
+
return wt().parse(r);
|
|
344
344
|
}
|
|
345
345
|
function Mt(r) {
|
|
346
346
|
return r.replace(/(^|_)bg/, (t, e) => `${e}background`).replace(/_([a-z])/g, (t, e) => e.toUpperCase());
|
|
347
347
|
}
|
|
348
|
-
function
|
|
348
|
+
function jt(r) {
|
|
349
349
|
return r.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`).replace(/(^|_)background/, (t, e) => `${e}bg`);
|
|
350
350
|
}
|
|
351
|
-
const _t =
|
|
351
|
+
const _t = V(
|
|
352
352
|
(r) => {
|
|
353
|
-
const t =
|
|
354
|
-
return Object.entries(
|
|
353
|
+
const t = gt().optional();
|
|
354
|
+
return Object.entries(Y(r)).reduce((e, [s, n]) => (e[Mt(s)] = t.parse(n), e), {});
|
|
355
355
|
},
|
|
356
356
|
"ThemeParams"
|
|
357
357
|
);
|
|
358
|
-
function
|
|
358
|
+
function bt(r) {
|
|
359
359
|
return _t().parse(r);
|
|
360
360
|
}
|
|
361
|
-
function
|
|
362
|
-
return
|
|
361
|
+
function rr(r = {}) {
|
|
362
|
+
return m("web_app_request_theme", "theme_changed", r).then(bt);
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function Gt(r) {
|
|
365
365
|
return JSON.stringify(
|
|
366
|
-
Object.entries(r).reduce((t, [e, s]) => (s && (t[
|
|
366
|
+
Object.entries(r).reduce((t, [e, s]) => (s && (t[jt(e)] = s), t), {})
|
|
367
367
|
);
|
|
368
368
|
}
|
|
369
|
-
class
|
|
369
|
+
class w {
|
|
370
370
|
constructor() {
|
|
371
371
|
o(this, "listeners", /* @__PURE__ */ new Map());
|
|
372
372
|
o(this, "subscribeListeners", []);
|
|
@@ -448,7 +448,7 @@ class _ {
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
class
|
|
451
|
+
class _ {
|
|
452
452
|
constructor(t, e) {
|
|
453
453
|
this.state = t, this.ee = e;
|
|
454
454
|
}
|
|
@@ -478,9 +478,9 @@ class w {
|
|
|
478
478
|
return this.state[t];
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
class
|
|
481
|
+
class Ft {
|
|
482
482
|
constructor(t) {
|
|
483
|
-
o(this, "ee", new
|
|
483
|
+
o(this, "ee", new w());
|
|
484
484
|
o(this, "state");
|
|
485
485
|
/**
|
|
486
486
|
* Adds new event listener.
|
|
@@ -490,7 +490,7 @@ class Gt {
|
|
|
490
490
|
* Removes event listener.
|
|
491
491
|
*/
|
|
492
492
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
493
|
-
this.state = new
|
|
493
|
+
this.state = new _(t, this.ee);
|
|
494
494
|
}
|
|
495
495
|
/**
|
|
496
496
|
* @since v6.10
|
|
@@ -537,7 +537,7 @@ class Gt {
|
|
|
537
537
|
* value is calculated according to theme background color.
|
|
538
538
|
*/
|
|
539
539
|
get isDark() {
|
|
540
|
-
return !this.backgroundColor ||
|
|
540
|
+
return !this.backgroundColor || ft(this.backgroundColor);
|
|
541
541
|
}
|
|
542
542
|
get linkColor() {
|
|
543
543
|
return this.get("linkColor");
|
|
@@ -562,8 +562,8 @@ class Gt {
|
|
|
562
562
|
* @returns Function to stop listening.
|
|
563
563
|
*/
|
|
564
564
|
listen() {
|
|
565
|
-
return
|
|
566
|
-
this.state.set(
|
|
565
|
+
return y("theme_changed", (t) => {
|
|
566
|
+
this.state.set(bt(t.theme_params));
|
|
567
567
|
});
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
@@ -576,14 +576,14 @@ class Gt {
|
|
|
576
576
|
return this.get("textColor");
|
|
577
577
|
}
|
|
578
578
|
}
|
|
579
|
-
function
|
|
580
|
-
return
|
|
579
|
+
function mt() {
|
|
580
|
+
return X({
|
|
581
581
|
botInline: {
|
|
582
|
-
type:
|
|
582
|
+
type: P().optional(),
|
|
583
583
|
from: "tgWebAppBotInline"
|
|
584
584
|
},
|
|
585
585
|
initData: {
|
|
586
|
-
type:
|
|
586
|
+
type: wt().optional(),
|
|
587
587
|
from: "tgWebAppData"
|
|
588
588
|
},
|
|
589
589
|
initDataRaw: {
|
|
@@ -595,7 +595,7 @@ function bt() {
|
|
|
595
595
|
from: "tgWebAppPlatform"
|
|
596
596
|
},
|
|
597
597
|
showSettings: {
|
|
598
|
-
type:
|
|
598
|
+
type: P().optional(),
|
|
599
599
|
from: "tgWebAppShowSettings"
|
|
600
600
|
},
|
|
601
601
|
themeParams: {
|
|
@@ -608,33 +608,33 @@ function bt() {
|
|
|
608
608
|
}
|
|
609
609
|
}, "LaunchParams");
|
|
610
610
|
}
|
|
611
|
-
function
|
|
612
|
-
return
|
|
613
|
-
}
|
|
614
|
-
function Ft() {
|
|
615
|
-
return mt(window.location.hash.slice(1));
|
|
611
|
+
function yt(r) {
|
|
612
|
+
return mt().parse(r);
|
|
616
613
|
}
|
|
617
614
|
function zt() {
|
|
618
|
-
|
|
615
|
+
return yt(window.location.hash.slice(1));
|
|
616
|
+
}
|
|
617
|
+
function Jt() {
|
|
618
|
+
const r = ht();
|
|
619
619
|
if (!r)
|
|
620
620
|
throw new Error("Unable to get first navigation entry.");
|
|
621
621
|
const t = r.name.match(/#(.*)/);
|
|
622
622
|
if (!t)
|
|
623
623
|
throw new Error("First navigation entry does not contain hash part.");
|
|
624
|
-
return
|
|
624
|
+
return yt(t[1]);
|
|
625
625
|
}
|
|
626
|
-
function
|
|
626
|
+
function Qt() {
|
|
627
627
|
try {
|
|
628
|
-
return
|
|
628
|
+
return Jt();
|
|
629
629
|
} catch {
|
|
630
630
|
}
|
|
631
631
|
try {
|
|
632
|
-
return
|
|
632
|
+
return zt();
|
|
633
633
|
} catch {
|
|
634
634
|
}
|
|
635
635
|
return null;
|
|
636
636
|
}
|
|
637
|
-
function
|
|
637
|
+
function Zt(r) {
|
|
638
638
|
const {
|
|
639
639
|
initDataRaw: t,
|
|
640
640
|
themeParams: e,
|
|
@@ -643,30 +643,30 @@ function Qt(r) {
|
|
|
643
643
|
showSettings: i,
|
|
644
644
|
botInline: a
|
|
645
645
|
} = r, c = new URLSearchParams();
|
|
646
|
-
return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", s), c.set("tgWebAppThemeParams",
|
|
646
|
+
return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", s), c.set("tgWebAppThemeParams", Gt(e)), c.set("tgWebAppVersion", n), typeof i == "boolean" && c.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && c.set("tgWebAppBotInline", a ? "1" : "0"), c.toString();
|
|
647
647
|
}
|
|
648
|
-
const
|
|
649
|
-
function
|
|
650
|
-
const r = sessionStorage.getItem(
|
|
651
|
-
return r ?
|
|
648
|
+
const Et = "telegram-mini-apps-launch-params";
|
|
649
|
+
function Kt() {
|
|
650
|
+
const r = sessionStorage.getItem(Et);
|
|
651
|
+
return r ? mt().parse(r) : null;
|
|
652
652
|
}
|
|
653
|
-
function
|
|
654
|
-
sessionStorage.setItem(
|
|
653
|
+
function Yt(r) {
|
|
654
|
+
sessionStorage.setItem(Et, Zt(r));
|
|
655
655
|
}
|
|
656
|
-
function
|
|
656
|
+
function Xt() {
|
|
657
657
|
try {
|
|
658
658
|
return window.self !== window.top;
|
|
659
659
|
} catch {
|
|
660
660
|
return !0;
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
|
-
function
|
|
664
|
-
const r =
|
|
663
|
+
function te() {
|
|
664
|
+
const r = Kt(), t = Qt(), e = Bt();
|
|
665
665
|
if (r) {
|
|
666
666
|
if (t)
|
|
667
667
|
return {
|
|
668
668
|
launchParams: t,
|
|
669
|
-
isPageReload:
|
|
669
|
+
isPageReload: Xt() ? e || r.initDataRaw === t.initDataRaw : !0
|
|
670
670
|
};
|
|
671
671
|
if (e)
|
|
672
672
|
return {
|
|
@@ -682,45 +682,45 @@ function Xt() {
|
|
|
682
682
|
};
|
|
683
683
|
throw new Error("Unable to retrieve any launch parameters.");
|
|
684
684
|
}
|
|
685
|
-
const
|
|
686
|
-
function
|
|
687
|
-
const r = window[
|
|
685
|
+
const st = "tmajsLaunchData";
|
|
686
|
+
function Ct() {
|
|
687
|
+
const r = window[st];
|
|
688
688
|
if (r)
|
|
689
689
|
return r;
|
|
690
|
-
const t =
|
|
691
|
-
return window[
|
|
690
|
+
const t = te();
|
|
691
|
+
return window[st] = t, Yt(t.launchParams), t;
|
|
692
692
|
}
|
|
693
|
-
function
|
|
693
|
+
function sr() {
|
|
694
694
|
try {
|
|
695
|
-
return
|
|
695
|
+
return Ct(), !0;
|
|
696
696
|
} catch {
|
|
697
697
|
return !1;
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
|
-
function te(r) {
|
|
701
|
-
return "external" in r && O(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
702
|
-
}
|
|
703
700
|
function ee(r) {
|
|
704
|
-
return "
|
|
701
|
+
return "external" in r && H(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
705
702
|
}
|
|
706
|
-
function
|
|
703
|
+
function re(r) {
|
|
704
|
+
return "TelegramWebviewProxy" in r && H(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
|
|
705
|
+
}
|
|
706
|
+
function vt() {
|
|
707
707
|
try {
|
|
708
708
|
return window.self !== window.top;
|
|
709
709
|
} catch {
|
|
710
710
|
return !0;
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
|
-
class
|
|
713
|
+
class tt extends Error {
|
|
714
714
|
constructor(t, e) {
|
|
715
|
-
super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this,
|
|
715
|
+
super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, tt.prototype);
|
|
716
716
|
}
|
|
717
717
|
}
|
|
718
|
-
class
|
|
718
|
+
class et extends Error {
|
|
719
719
|
constructor(t, e, s) {
|
|
720
|
-
super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this,
|
|
720
|
+
super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, et.prototype);
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
class
|
|
723
|
+
class Pt {
|
|
724
724
|
constructor(t, e) {
|
|
725
725
|
this.prefix = t, this.enabled = e;
|
|
726
726
|
}
|
|
@@ -775,31 +775,31 @@ class vt {
|
|
|
775
775
|
this.print("warn", ...t);
|
|
776
776
|
}
|
|
777
777
|
}
|
|
778
|
-
let
|
|
779
|
-
const
|
|
780
|
-
function
|
|
778
|
+
let St = "https://web.telegram.org";
|
|
779
|
+
const q = new Pt("[SDK]", !1);
|
|
780
|
+
function nr(r) {
|
|
781
781
|
if (r) {
|
|
782
|
-
|
|
782
|
+
q.enable();
|
|
783
783
|
return;
|
|
784
784
|
}
|
|
785
|
-
|
|
785
|
+
q.disable();
|
|
786
786
|
}
|
|
787
|
-
function
|
|
788
|
-
|
|
787
|
+
function ir(r) {
|
|
788
|
+
St = r;
|
|
789
789
|
}
|
|
790
|
-
function
|
|
791
|
-
return
|
|
790
|
+
function se() {
|
|
791
|
+
return St;
|
|
792
792
|
}
|
|
793
|
-
const
|
|
793
|
+
const ne = g({
|
|
794
794
|
eventType: h(),
|
|
795
795
|
eventData: (r) => r
|
|
796
796
|
});
|
|
797
|
-
function
|
|
797
|
+
function ie(r, t) {
|
|
798
798
|
window.dispatchEvent(new MessageEvent("message", {
|
|
799
799
|
data: JSON.stringify({ eventType: r, eventData: t })
|
|
800
800
|
}));
|
|
801
801
|
}
|
|
802
|
-
function
|
|
802
|
+
function oe() {
|
|
803
803
|
const r = window;
|
|
804
804
|
"TelegramGameProxy_receiveEvent" in r || [
|
|
805
805
|
["TelegramGameProxy_receiveEvent"],
|
|
@@ -812,76 +812,76 @@ function ie() {
|
|
|
812
812
|
let e = r;
|
|
813
813
|
t.forEach((s, n, i) => {
|
|
814
814
|
if (n === i.length - 1) {
|
|
815
|
-
e[s] =
|
|
815
|
+
e[s] = ie;
|
|
816
816
|
return;
|
|
817
817
|
}
|
|
818
818
|
s in e || (e[s] = {}), e = e[s];
|
|
819
819
|
});
|
|
820
820
|
});
|
|
821
821
|
}
|
|
822
|
-
function
|
|
823
|
-
|
|
822
|
+
function ae(r) {
|
|
823
|
+
oe(), window.addEventListener("message", (t) => {
|
|
824
824
|
try {
|
|
825
|
-
const { eventType: e, eventData: s } =
|
|
825
|
+
const { eventType: e, eventData: s } = ne.parse(t.data);
|
|
826
826
|
r(e, s);
|
|
827
827
|
} catch {
|
|
828
828
|
}
|
|
829
829
|
});
|
|
830
830
|
}
|
|
831
|
-
function
|
|
831
|
+
function ce() {
|
|
832
832
|
return g({
|
|
833
833
|
req_id: h(),
|
|
834
834
|
data: (r) => r === null ? r : h().optional().parse(r)
|
|
835
835
|
});
|
|
836
836
|
}
|
|
837
|
-
function
|
|
837
|
+
function he() {
|
|
838
838
|
return g({
|
|
839
839
|
req_id: h(),
|
|
840
840
|
result: (r) => r,
|
|
841
841
|
error: h().optional()
|
|
842
842
|
});
|
|
843
843
|
}
|
|
844
|
-
function
|
|
844
|
+
function ue() {
|
|
845
845
|
return g({
|
|
846
846
|
slug: h(),
|
|
847
847
|
status: h()
|
|
848
848
|
});
|
|
849
849
|
}
|
|
850
|
-
function
|
|
850
|
+
function pe() {
|
|
851
851
|
return g({ status: h() });
|
|
852
852
|
}
|
|
853
|
-
function
|
|
853
|
+
function le() {
|
|
854
854
|
return g({
|
|
855
855
|
button_id: (r) => r == null ? void 0 : h().parse(r)
|
|
856
856
|
});
|
|
857
857
|
}
|
|
858
|
-
function
|
|
858
|
+
function de() {
|
|
859
859
|
return g({
|
|
860
860
|
data: h().optional()
|
|
861
861
|
});
|
|
862
862
|
}
|
|
863
|
-
function
|
|
863
|
+
function fe() {
|
|
864
864
|
return g({
|
|
865
865
|
theme_params: (r) => {
|
|
866
|
-
const t =
|
|
867
|
-
return Object.entries(
|
|
866
|
+
const t = gt().optional();
|
|
867
|
+
return Object.entries(Y(r)).reduce((e, [s, n]) => (e[s] = t.parse(n), e), {});
|
|
868
868
|
}
|
|
869
869
|
});
|
|
870
870
|
}
|
|
871
|
-
function
|
|
871
|
+
function ge() {
|
|
872
872
|
return g({
|
|
873
|
-
height:
|
|
874
|
-
width: (r) => r == null ? window.innerWidth :
|
|
875
|
-
is_state_stable:
|
|
876
|
-
is_expanded:
|
|
873
|
+
height: k(),
|
|
874
|
+
width: (r) => r == null ? window.innerWidth : k().parse(r),
|
|
875
|
+
is_state_stable: P(),
|
|
876
|
+
is_expanded: P()
|
|
877
877
|
});
|
|
878
878
|
}
|
|
879
|
-
function
|
|
879
|
+
function we() {
|
|
880
880
|
return g({ status: h() });
|
|
881
881
|
}
|
|
882
882
|
function _e() {
|
|
883
|
-
const r = new
|
|
884
|
-
|
|
883
|
+
const r = new w(), t = (e, ...s) => {
|
|
884
|
+
q.log("Emitting processed event:", e, ...s), r.emit(e, ...s);
|
|
885
885
|
};
|
|
886
886
|
return window.addEventListener("resize", () => {
|
|
887
887
|
t("viewport_changed", {
|
|
@@ -890,33 +890,33 @@ function _e() {
|
|
|
890
890
|
is_state_stable: !0,
|
|
891
891
|
is_expanded: !0
|
|
892
892
|
});
|
|
893
|
-
}),
|
|
894
|
-
|
|
893
|
+
}), ae((e, s) => {
|
|
894
|
+
q.log("Received raw event:", e, s);
|
|
895
895
|
try {
|
|
896
896
|
switch (e) {
|
|
897
897
|
case "viewport_changed":
|
|
898
|
-
return t(e,
|
|
898
|
+
return t(e, ge().parse(s));
|
|
899
899
|
case "theme_changed":
|
|
900
|
-
return t(e,
|
|
900
|
+
return t(e, fe().parse(s));
|
|
901
901
|
case "popup_closed":
|
|
902
902
|
return (
|
|
903
903
|
// Sent on desktop.
|
|
904
|
-
s == null ? t(e, {}) : t(e,
|
|
904
|
+
s == null ? t(e, {}) : t(e, le().parse(s))
|
|
905
905
|
);
|
|
906
906
|
case "set_custom_style":
|
|
907
907
|
return t(e, h().parse(s));
|
|
908
908
|
case "qr_text_received":
|
|
909
|
-
return t(e,
|
|
909
|
+
return t(e, de().parse(s));
|
|
910
910
|
case "clipboard_text_received":
|
|
911
|
-
return t(e,
|
|
911
|
+
return t(e, ce().parse(s));
|
|
912
912
|
case "invoice_closed":
|
|
913
|
-
return t(e,
|
|
913
|
+
return t(e, ue().parse(s));
|
|
914
914
|
case "phone_requested":
|
|
915
|
-
return t("phone_requested",
|
|
915
|
+
return t("phone_requested", pe().parse(s));
|
|
916
916
|
case "custom_method_invoked":
|
|
917
|
-
return t("custom_method_invoked",
|
|
917
|
+
return t("custom_method_invoked", he().parse(s));
|
|
918
918
|
case "write_access_requested":
|
|
919
|
-
return t("write_access_requested",
|
|
919
|
+
return t("write_access_requested", we().parse(s));
|
|
920
920
|
case "main_button_pressed":
|
|
921
921
|
case "back_button_pressed":
|
|
922
922
|
case "settings_button_pressed":
|
|
@@ -927,31 +927,31 @@ function _e() {
|
|
|
927
927
|
return t(e, s);
|
|
928
928
|
}
|
|
929
929
|
} catch (n) {
|
|
930
|
-
|
|
930
|
+
q.error("Error processing event:", n);
|
|
931
931
|
}
|
|
932
932
|
}), r;
|
|
933
933
|
}
|
|
934
|
-
const
|
|
935
|
-
function
|
|
934
|
+
const Q = "telegram-mini-apps-cached-emitter";
|
|
935
|
+
function U() {
|
|
936
936
|
const r = window;
|
|
937
|
-
return r[
|
|
937
|
+
return r[Q] === void 0 && (r[Q] = _e()), r[Q];
|
|
938
938
|
}
|
|
939
|
-
function
|
|
940
|
-
|
|
939
|
+
function I(r, t) {
|
|
940
|
+
U().off(r, t);
|
|
941
941
|
}
|
|
942
|
-
function
|
|
943
|
-
return
|
|
942
|
+
function y(r, t) {
|
|
943
|
+
return U().on(r, t), () => I(r, t);
|
|
944
944
|
}
|
|
945
|
-
function
|
|
946
|
-
return
|
|
945
|
+
function or(r, t) {
|
|
946
|
+
return U().once(r, t), () => I(r, t);
|
|
947
947
|
}
|
|
948
|
-
function
|
|
949
|
-
|
|
948
|
+
function be(r) {
|
|
949
|
+
U().unsubscribe(r);
|
|
950
950
|
}
|
|
951
|
-
function
|
|
952
|
-
return
|
|
951
|
+
function ar(r) {
|
|
952
|
+
return U().subscribe(r), () => be(r);
|
|
953
953
|
}
|
|
954
|
-
function
|
|
954
|
+
function me(r, t) {
|
|
955
955
|
const e = r.split("."), s = t.split("."), n = Math.max(e.length, s.length);
|
|
956
956
|
for (let i = 0; i < n; i += 1) {
|
|
957
957
|
const a = parseInt(e[i] || "0", 10), c = parseInt(s[i] || "0", 10);
|
|
@@ -961,7 +961,7 @@ function be(r, t) {
|
|
|
961
961
|
return 0;
|
|
962
962
|
}
|
|
963
963
|
function v(r, t) {
|
|
964
|
-
return
|
|
964
|
+
return me(r, t) <= 0;
|
|
965
965
|
}
|
|
966
966
|
function A(r, t, e) {
|
|
967
967
|
if (typeof e == "string") {
|
|
@@ -996,10 +996,10 @@ function A(r, t, e) {
|
|
|
996
996
|
return !0;
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
|
-
function
|
|
999
|
+
function E(r, t) {
|
|
1000
1000
|
return (e) => A(t[e], r);
|
|
1001
1001
|
}
|
|
1002
|
-
function
|
|
1002
|
+
function kt(r, t) {
|
|
1003
1003
|
return (e) => {
|
|
1004
1004
|
const [s, n] = t[e];
|
|
1005
1005
|
return A(s, n, r);
|
|
@@ -1008,19 +1008,19 @@ function St(r, t) {
|
|
|
1008
1008
|
function f(r, t, e) {
|
|
1009
1009
|
let s = {}, n;
|
|
1010
1010
|
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);
|
|
1011
|
-
const { targetOrigin: i =
|
|
1012
|
-
if (
|
|
1011
|
+
const { targetOrigin: i = se() } = s;
|
|
1012
|
+
if (q.log(`Calling method "${r}"`, n), vt()) {
|
|
1013
1013
|
window.parent.postMessage(JSON.stringify({
|
|
1014
1014
|
eventType: r,
|
|
1015
1015
|
eventData: n
|
|
1016
1016
|
}), i);
|
|
1017
1017
|
return;
|
|
1018
1018
|
}
|
|
1019
|
-
if (
|
|
1019
|
+
if (ee(window)) {
|
|
1020
1020
|
window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
|
|
1021
1021
|
return;
|
|
1022
1022
|
}
|
|
1023
|
-
if (
|
|
1023
|
+
if (re(window)) {
|
|
1024
1024
|
window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
|
|
1025
1025
|
return;
|
|
1026
1026
|
}
|
|
@@ -1028,70 +1028,93 @@ function f(r, t, e) {
|
|
|
1028
1028
|
"Unable to determine current environment and possible way to send event."
|
|
1029
1029
|
);
|
|
1030
1030
|
}
|
|
1031
|
-
function
|
|
1031
|
+
function ye(r) {
|
|
1032
1032
|
return (t, e) => {
|
|
1033
1033
|
if (!A(t, r))
|
|
1034
|
-
throw new
|
|
1035
|
-
if (
|
|
1034
|
+
throw new tt(t, r);
|
|
1035
|
+
if (H(e)) {
|
|
1036
1036
|
let s;
|
|
1037
1037
|
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))
|
|
1038
|
-
throw new
|
|
1038
|
+
throw new et(t, s, r);
|
|
1039
1039
|
}
|
|
1040
1040
|
return f(t, e);
|
|
1041
1041
|
};
|
|
1042
1042
|
}
|
|
1043
|
-
class
|
|
1043
|
+
class J extends Error {
|
|
1044
1044
|
constructor(t) {
|
|
1045
|
-
super(`Async call timeout exceeded. Timeout: ${t}`), Object.setPrototypeOf(this,
|
|
1045
|
+
super(`Async call timeout exceeded. Timeout: ${t}`), Object.setPrototypeOf(this, J.prototype);
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
|
-
function
|
|
1048
|
+
function cr(r) {
|
|
1049
|
+
return r instanceof J;
|
|
1050
|
+
}
|
|
1051
|
+
function Ee(r) {
|
|
1052
|
+
return new Promise((t) => {
|
|
1053
|
+
setTimeout(t, r);
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
function Ce(r) {
|
|
1049
1057
|
return new Promise((t, e) => {
|
|
1050
|
-
setTimeout(e, r, new
|
|
1058
|
+
setTimeout(e, r, new J(r));
|
|
1051
1059
|
});
|
|
1052
1060
|
}
|
|
1053
|
-
function
|
|
1054
|
-
return
|
|
1055
|
-
r(
|
|
1056
|
-
|
|
1057
|
-
])
|
|
1061
|
+
function xt(r, t) {
|
|
1062
|
+
return Promise.race([
|
|
1063
|
+
r(),
|
|
1064
|
+
Ce(t)
|
|
1065
|
+
]);
|
|
1058
1066
|
}
|
|
1059
|
-
function
|
|
1067
|
+
function m(r, t, e, s) {
|
|
1060
1068
|
let n, i, a, c;
|
|
1061
|
-
typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t], n = e) : (i = t, a = Array.isArray(e) ? e : [e], n = s),
|
|
1062
|
-
const { postEvent: u = f, timeout:
|
|
1063
|
-
const x = a.map((B) =>
|
|
1064
|
-
|
|
1065
|
-
})),
|
|
1069
|
+
typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t], n = e) : (i = t, a = Array.isArray(e) ? e : [e], n = s), H(i) && typeof i.req_id == "string" && (c = i.req_id);
|
|
1070
|
+
const { postEvent: u = f, timeout: p } = n || {}, l = n && "capture" in n ? n.capture : null, b = () => new Promise((d, C) => {
|
|
1071
|
+
const x = a.map((B) => y(B, (M) => {
|
|
1072
|
+
c && (!H(M) || M.req_id !== c) || typeof l == "function" && !l(M) || (T(), d(M));
|
|
1073
|
+
})), T = () => x.forEach((B) => B());
|
|
1066
1074
|
try {
|
|
1067
1075
|
u(r, i);
|
|
1068
1076
|
} catch (B) {
|
|
1069
|
-
|
|
1077
|
+
T(), C(B);
|
|
1070
1078
|
}
|
|
1071
1079
|
});
|
|
1072
|
-
return typeof
|
|
1080
|
+
return typeof p == "number" ? xt(b, p) : b();
|
|
1081
|
+
}
|
|
1082
|
+
async function N(r, t, e, s = {}) {
|
|
1083
|
+
const { result: n, error: i } = await m(
|
|
1084
|
+
"web_app_invoke_custom_method",
|
|
1085
|
+
{
|
|
1086
|
+
method: r,
|
|
1087
|
+
params: t,
|
|
1088
|
+
req_id: e
|
|
1089
|
+
},
|
|
1090
|
+
"custom_method_invoked",
|
|
1091
|
+
s
|
|
1092
|
+
);
|
|
1093
|
+
if (i)
|
|
1094
|
+
throw new Error(i);
|
|
1095
|
+
return n;
|
|
1073
1096
|
}
|
|
1074
|
-
class
|
|
1097
|
+
class ve {
|
|
1075
1098
|
constructor(t, e, s = f) {
|
|
1076
|
-
o(this, "ee", new
|
|
1099
|
+
o(this, "ee", new w());
|
|
1077
1100
|
o(this, "state");
|
|
1078
1101
|
/**
|
|
1079
1102
|
* Adds event listener.
|
|
1080
1103
|
* @param event - event name.
|
|
1081
1104
|
* @param listener - event listener.
|
|
1082
1105
|
*/
|
|
1083
|
-
o(this, "on", (t, e) => t === "click" ?
|
|
1106
|
+
o(this, "on", (t, e) => t === "click" ? y("back_button_pressed", e) : this.ee.on(t, e));
|
|
1084
1107
|
/**
|
|
1085
1108
|
* Removes event listener.
|
|
1086
1109
|
* @param event - event name.
|
|
1087
1110
|
* @param listener - event listener.
|
|
1088
1111
|
*/
|
|
1089
|
-
o(this, "off", (t, e) => t === "click" ?
|
|
1112
|
+
o(this, "off", (t, e) => t === "click" ? I("back_button_pressed", e) : this.ee.off(t, e));
|
|
1090
1113
|
/**
|
|
1091
1114
|
* Checks if specified method is supported by current component.
|
|
1092
1115
|
*/
|
|
1093
1116
|
o(this, "supports");
|
|
1094
|
-
this.postEvent = s, this.state = new
|
|
1117
|
+
this.postEvent = s, this.state = new _({ isVisible: t }, this.ee), this.supports = E(e, {
|
|
1095
1118
|
show: "web_app_setup_back_button",
|
|
1096
1119
|
hide: "web_app_setup_back_button"
|
|
1097
1120
|
});
|
|
@@ -1118,27 +1141,27 @@ class Ee {
|
|
|
1118
1141
|
this.isVisible = !0;
|
|
1119
1142
|
}
|
|
1120
1143
|
}
|
|
1121
|
-
function
|
|
1144
|
+
function nt(r, t) {
|
|
1122
1145
|
return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
|
|
1123
1146
|
}
|
|
1124
|
-
function
|
|
1147
|
+
function Pe(...r) {
|
|
1125
1148
|
return r.reduce((t, e) => {
|
|
1126
1149
|
let s = "";
|
|
1127
|
-
return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ?
|
|
1150
|
+
return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? nt(n, i) : n, "")), nt(t, s);
|
|
1128
1151
|
}, "");
|
|
1129
1152
|
}
|
|
1130
|
-
function
|
|
1153
|
+
function Se(r) {
|
|
1131
1154
|
return typeof r == "object" && r !== null && !Array.isArray(null);
|
|
1132
1155
|
}
|
|
1133
|
-
function
|
|
1134
|
-
return r.reduce((t, e) => (
|
|
1135
|
-
const i =
|
|
1156
|
+
function hr(...r) {
|
|
1157
|
+
return r.reduce((t, e) => (Se(e) && Object.entries(e).forEach(([s, n]) => {
|
|
1158
|
+
const i = Pe(t[s], n);
|
|
1136
1159
|
i.length > 0 && (t[s] = i);
|
|
1137
1160
|
}), t), {});
|
|
1138
1161
|
}
|
|
1139
1162
|
class ke {
|
|
1140
1163
|
constructor(t, e = f) {
|
|
1141
|
-
o(this, "ee", new
|
|
1164
|
+
o(this, "ee", new w());
|
|
1142
1165
|
o(this, "state");
|
|
1143
1166
|
/**
|
|
1144
1167
|
* Adds new event listener.
|
|
@@ -1148,7 +1171,7 @@ class ke {
|
|
|
1148
1171
|
* Removes event listener.
|
|
1149
1172
|
*/
|
|
1150
1173
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1151
|
-
this.postEvent = e, this.state = new
|
|
1174
|
+
this.postEvent = e, this.state = new _({ isConfirmationNeeded: t }, this.ee);
|
|
1152
1175
|
}
|
|
1153
1176
|
set isConfirmationNeeded(t) {
|
|
1154
1177
|
this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
|
|
@@ -1175,63 +1198,61 @@ class ke {
|
|
|
1175
1198
|
this.isConfirmationNeeded = !0;
|
|
1176
1199
|
}
|
|
1177
1200
|
}
|
|
1178
|
-
function
|
|
1201
|
+
function it(r, t) {
|
|
1179
1202
|
return r.reduce((e, s) => (e[s] = t, e), {});
|
|
1180
1203
|
}
|
|
1181
|
-
class
|
|
1204
|
+
class xe {
|
|
1182
1205
|
constructor(t, e, s = f) {
|
|
1183
1206
|
/**
|
|
1184
1207
|
* Checks if specified method is supported by current component.
|
|
1185
1208
|
*/
|
|
1186
1209
|
o(this, "supports");
|
|
1187
|
-
this.createRequestId = e, this.postEvent = s, this.supports =
|
|
1210
|
+
this.createRequestId = e, this.postEvent = s, this.supports = E(t, {
|
|
1188
1211
|
delete: "web_app_invoke_custom_method",
|
|
1189
1212
|
get: "web_app_invoke_custom_method",
|
|
1190
1213
|
getKeys: "web_app_invoke_custom_method",
|
|
1191
1214
|
set: "web_app_invoke_custom_method"
|
|
1192
1215
|
});
|
|
1193
1216
|
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Invokes custom method related to CloudStorage.
|
|
1196
|
-
* @param method - method name.
|
|
1197
|
-
* @param params - method parameters.
|
|
1198
|
-
* @param options - execution options.
|
|
1199
|
-
*/
|
|
1200
|
-
async invokeCustomMethod(t, e, s = {}) {
|
|
1201
|
-
const { result: n, error: i } = await b(
|
|
1202
|
-
"web_app_invoke_custom_method",
|
|
1203
|
-
{ method: t, params: e, req_id: this.createRequestId() },
|
|
1204
|
-
"custom_method_invoked",
|
|
1205
|
-
{ ...s, postEvent: this.postEvent }
|
|
1206
|
-
);
|
|
1207
|
-
if (i)
|
|
1208
|
-
throw new Error(i);
|
|
1209
|
-
return n;
|
|
1210
|
-
}
|
|
1211
1217
|
/**
|
|
1212
1218
|
* Deletes specified key or keys from the cloud storage.
|
|
1213
1219
|
* @param keyOrKeys - key or keys to delete.
|
|
1214
1220
|
* @param options - request execution options.
|
|
1215
1221
|
*/
|
|
1216
|
-
async delete(t, e) {
|
|
1222
|
+
async delete(t, e = {}) {
|
|
1217
1223
|
const s = Array.isArray(t) ? t : [t];
|
|
1218
|
-
s.length !== 0 && await
|
|
1224
|
+
s.length !== 0 && await N(
|
|
1225
|
+
"deleteStorageValues",
|
|
1226
|
+
{ keys: s },
|
|
1227
|
+
this.createRequestId(),
|
|
1228
|
+
{ ...e, postEvent: this.postEvent }
|
|
1229
|
+
);
|
|
1219
1230
|
}
|
|
1220
1231
|
/**
|
|
1221
1232
|
* Returns list of all keys presented in the cloud storage.
|
|
1222
1233
|
* @param options - request execution options.
|
|
1223
1234
|
*/
|
|
1224
|
-
async getKeys(t) {
|
|
1225
|
-
const e = await
|
|
1226
|
-
|
|
1235
|
+
async getKeys(t = {}) {
|
|
1236
|
+
const e = await N(
|
|
1237
|
+
"getStorageKeys",
|
|
1238
|
+
{},
|
|
1239
|
+
this.createRequestId(),
|
|
1240
|
+
{ ...t, postEvent: this.postEvent }
|
|
1241
|
+
);
|
|
1242
|
+
return Nt().of(h()).parse(e);
|
|
1227
1243
|
}
|
|
1228
|
-
async get(t, e) {
|
|
1244
|
+
async get(t, e = {}) {
|
|
1229
1245
|
const s = Array.isArray(t) ? t : [t];
|
|
1230
1246
|
if (s.length === 0)
|
|
1231
|
-
return
|
|
1247
|
+
return it(s, "");
|
|
1232
1248
|
const n = g(
|
|
1233
|
-
|
|
1234
|
-
), i = await
|
|
1249
|
+
it(s, h())
|
|
1250
|
+
), i = await N(
|
|
1251
|
+
"getStorageValues",
|
|
1252
|
+
{ keys: s },
|
|
1253
|
+
this.createRequestId(),
|
|
1254
|
+
{ ...e, postEvent: this.postEvent }
|
|
1255
|
+
).then((a) => n.parse(a));
|
|
1235
1256
|
return Array.isArray(t) ? i : i[t];
|
|
1236
1257
|
}
|
|
1237
1258
|
/**
|
|
@@ -1240,17 +1261,22 @@ class Se {
|
|
|
1240
1261
|
* @param value - storage value.
|
|
1241
1262
|
* @param options - request execution options.
|
|
1242
1263
|
*/
|
|
1243
|
-
async set(t, e, s) {
|
|
1244
|
-
await
|
|
1264
|
+
async set(t, e, s = {}) {
|
|
1265
|
+
await N(
|
|
1266
|
+
"saveStorageValue",
|
|
1267
|
+
{ key: t, value: e },
|
|
1268
|
+
this.createRequestId(),
|
|
1269
|
+
{ ...s, postEvent: this.postEvent }
|
|
1270
|
+
);
|
|
1245
1271
|
}
|
|
1246
1272
|
}
|
|
1247
|
-
class
|
|
1273
|
+
class qe {
|
|
1248
1274
|
constructor(t, e = f) {
|
|
1249
1275
|
/**
|
|
1250
1276
|
* Checks if specified method is supported by current component.
|
|
1251
1277
|
*/
|
|
1252
1278
|
o(this, "supports");
|
|
1253
|
-
this.postEvent = e, this.supports =
|
|
1279
|
+
this.postEvent = e, this.supports = E(t, {
|
|
1254
1280
|
impactOccurred: "web_app_trigger_haptic_feedback",
|
|
1255
1281
|
notificationOccurred: "web_app_trigger_haptic_feedback",
|
|
1256
1282
|
selectionChanged: "web_app_trigger_haptic_feedback"
|
|
@@ -1290,37 +1316,37 @@ class xe {
|
|
|
1290
1316
|
this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
|
|
1291
1317
|
}
|
|
1292
1318
|
}
|
|
1293
|
-
function
|
|
1319
|
+
function Ae() {
|
|
1294
1320
|
const r = document.createElement("style");
|
|
1295
|
-
r.id = "telegram-custom-styles", document.head.appendChild(r),
|
|
1321
|
+
r.id = "telegram-custom-styles", document.head.appendChild(r), y("set_custom_style", (t) => {
|
|
1296
1322
|
r.innerHTML = t;
|
|
1297
1323
|
});
|
|
1298
1324
|
}
|
|
1299
|
-
function
|
|
1325
|
+
function qt(r) {
|
|
1300
1326
|
return `telegram-mini-apps-${r}`;
|
|
1301
1327
|
}
|
|
1302
|
-
function
|
|
1303
|
-
sessionStorage.setItem(
|
|
1328
|
+
function L(r, t) {
|
|
1329
|
+
sessionStorage.setItem(qt(r), JSON.stringify(t));
|
|
1304
1330
|
}
|
|
1305
|
-
function
|
|
1306
|
-
const t = sessionStorage.getItem(
|
|
1331
|
+
function $(r) {
|
|
1332
|
+
const t = sessionStorage.getItem(qt(r));
|
|
1307
1333
|
return t ? JSON.parse(t) : null;
|
|
1308
1334
|
}
|
|
1309
|
-
function
|
|
1310
|
-
const { isVisible: s = !1 } = r ?
|
|
1335
|
+
function Re(r, t, e) {
|
|
1336
|
+
const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new ve(s, t, e);
|
|
1311
1337
|
return n.on("change", () => {
|
|
1312
|
-
|
|
1338
|
+
L("back-button", { isVisible: n.isVisible });
|
|
1313
1339
|
}), n;
|
|
1314
1340
|
}
|
|
1315
|
-
function
|
|
1316
|
-
const { isConfirmationNeeded: e = !1 } = r ?
|
|
1317
|
-
return s.on("change", () =>
|
|
1341
|
+
function Ve(r, t) {
|
|
1342
|
+
const { isConfirmationNeeded: e = !1 } = r ? $("closing-behavior") || {} : {}, s = new ke(e, t);
|
|
1343
|
+
return s.on("change", () => L("closing-behavior", {
|
|
1318
1344
|
isConfirmationNeeded: s.isConfirmationNeeded
|
|
1319
1345
|
})), s;
|
|
1320
1346
|
}
|
|
1321
|
-
class
|
|
1347
|
+
class Ie {
|
|
1322
1348
|
constructor(t) {
|
|
1323
|
-
o(this, "ee", new
|
|
1349
|
+
o(this, "ee", new w());
|
|
1324
1350
|
o(this, "state");
|
|
1325
1351
|
o(this, "postEvent");
|
|
1326
1352
|
/**
|
|
@@ -1332,14 +1358,14 @@ class qe {
|
|
|
1332
1358
|
// FIXME: Event 'main_button_pressed' is still being received on Android
|
|
1333
1359
|
// even if the main button is disabled.
|
|
1334
1360
|
// Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
|
|
1335
|
-
t === "click" ?
|
|
1361
|
+
t === "click" ? y("main_button_pressed", e) : this.ee.on(t, e)
|
|
1336
1362
|
));
|
|
1337
1363
|
/**
|
|
1338
1364
|
* Removes event listener.
|
|
1339
1365
|
* @param event - event name.
|
|
1340
1366
|
* @param listener - event listener.
|
|
1341
1367
|
*/
|
|
1342
|
-
o(this, "off", (t, e) => t === "click" ?
|
|
1368
|
+
o(this, "off", (t, e) => t === "click" ? I("main_button_pressed", e) : this.ee.off(t, e));
|
|
1343
1369
|
const {
|
|
1344
1370
|
postEvent: e = f,
|
|
1345
1371
|
text: s,
|
|
@@ -1349,7 +1375,7 @@ class qe {
|
|
|
1349
1375
|
isVisible: c,
|
|
1350
1376
|
isLoaderVisible: u
|
|
1351
1377
|
} = t;
|
|
1352
|
-
this.postEvent = e, this.state = new
|
|
1378
|
+
this.postEvent = e, this.state = new _({
|
|
1353
1379
|
backgroundColor: i,
|
|
1354
1380
|
isEnabled: a,
|
|
1355
1381
|
isVisible: c,
|
|
@@ -1490,31 +1516,59 @@ function Le(r, t, e, s) {
|
|
|
1490
1516
|
isVisible: a = !1,
|
|
1491
1517
|
isLoaderVisible: c = !1,
|
|
1492
1518
|
textColor: u = e,
|
|
1493
|
-
text:
|
|
1494
|
-
} = r ?
|
|
1519
|
+
text: p = ""
|
|
1520
|
+
} = r ? $("main-button") || {} : {}, l = new Ie({
|
|
1495
1521
|
backgroundColor: n,
|
|
1496
1522
|
isEnabled: i,
|
|
1497
1523
|
isLoaderVisible: c,
|
|
1498
1524
|
isVisible: a,
|
|
1499
1525
|
postEvent: s,
|
|
1500
|
-
text:
|
|
1526
|
+
text: p,
|
|
1501
1527
|
textColor: u
|
|
1502
|
-
}),
|
|
1503
|
-
backgroundColor:
|
|
1504
|
-
isEnabled:
|
|
1505
|
-
isLoaderVisible:
|
|
1506
|
-
isVisible:
|
|
1507
|
-
text:
|
|
1508
|
-
textColor:
|
|
1528
|
+
}), b = () => L("main-button", {
|
|
1529
|
+
backgroundColor: l.backgroundColor,
|
|
1530
|
+
isEnabled: l.isEnabled,
|
|
1531
|
+
isLoaderVisible: l.isLoaderVisible,
|
|
1532
|
+
isVisible: l.isVisible,
|
|
1533
|
+
text: l.text,
|
|
1534
|
+
textColor: l.textColor
|
|
1509
1535
|
});
|
|
1510
|
-
return
|
|
1536
|
+
return l.on("change", b), l;
|
|
1511
1537
|
}
|
|
1512
|
-
|
|
1538
|
+
const $e = X({
|
|
1539
|
+
contact: g({
|
|
1540
|
+
userId: {
|
|
1541
|
+
type: k(),
|
|
1542
|
+
from: "user_id"
|
|
1543
|
+
},
|
|
1544
|
+
phoneNumber: {
|
|
1545
|
+
type: h(),
|
|
1546
|
+
from: "phone_number"
|
|
1547
|
+
},
|
|
1548
|
+
firstName: {
|
|
1549
|
+
type: h(),
|
|
1550
|
+
from: "first_name"
|
|
1551
|
+
},
|
|
1552
|
+
lastName: {
|
|
1553
|
+
type: h(),
|
|
1554
|
+
from: "last_name"
|
|
1555
|
+
}
|
|
1556
|
+
}),
|
|
1557
|
+
authDate: {
|
|
1558
|
+
type: pt(),
|
|
1559
|
+
from: "auth_date"
|
|
1560
|
+
},
|
|
1561
|
+
hash: h()
|
|
1562
|
+
});
|
|
1563
|
+
class Te {
|
|
1513
1564
|
constructor(t) {
|
|
1514
|
-
o(this, "ee", new
|
|
1565
|
+
o(this, "ee", new w());
|
|
1515
1566
|
o(this, "state");
|
|
1516
1567
|
o(this, "botInline");
|
|
1517
1568
|
o(this, "postEvent");
|
|
1569
|
+
o(this, "createRequestId");
|
|
1570
|
+
o(this, "requestingPhoneAccess", !1);
|
|
1571
|
+
o(this, "requestingWriteAccess", !1);
|
|
1518
1572
|
/**
|
|
1519
1573
|
* Adds new event listener.
|
|
1520
1574
|
*/
|
|
@@ -1536,18 +1590,33 @@ class $e {
|
|
|
1536
1590
|
headerColor: s,
|
|
1537
1591
|
backgroundColor: n,
|
|
1538
1592
|
version: i,
|
|
1539
|
-
botInline: a
|
|
1540
|
-
|
|
1593
|
+
botInline: a,
|
|
1594
|
+
createRequestId: c
|
|
1595
|
+
} = t, u = E(i, {
|
|
1541
1596
|
requestPhoneAccess: "web_app_request_phone",
|
|
1542
1597
|
requestWriteAccess: "web_app_request_write_access",
|
|
1543
1598
|
switchInlineQuery: "web_app_switch_inline_query",
|
|
1544
1599
|
setHeaderColor: "web_app_set_header_color",
|
|
1545
1600
|
setBackgroundColor: "web_app_set_background_color"
|
|
1546
1601
|
});
|
|
1547
|
-
this.postEvent = e, this.botInline = a, this.supports = (
|
|
1602
|
+
this.postEvent = e, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new _({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = kt(i, {
|
|
1548
1603
|
"setHeaderColor.color": ["web_app_set_header_color", "color"]
|
|
1549
1604
|
});
|
|
1550
1605
|
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Attempts to get requested contact.
|
|
1608
|
+
*/
|
|
1609
|
+
async getRequestedContact() {
|
|
1610
|
+
return N(
|
|
1611
|
+
"getRequestedContact",
|
|
1612
|
+
{},
|
|
1613
|
+
this.createRequestId(),
|
|
1614
|
+
{
|
|
1615
|
+
postEvent: this.postEvent,
|
|
1616
|
+
timeout: 1e4
|
|
1617
|
+
}
|
|
1618
|
+
).then((t) => $e.parse(t));
|
|
1619
|
+
}
|
|
1551
1620
|
/**
|
|
1552
1621
|
* The Mini App background color.
|
|
1553
1622
|
*/
|
|
@@ -1576,7 +1645,19 @@ class $e {
|
|
|
1576
1645
|
* True if current Mini App background color recognized as dark.
|
|
1577
1646
|
*/
|
|
1578
1647
|
get isDark() {
|
|
1579
|
-
return
|
|
1648
|
+
return ft(this.backgroundColor);
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* True if phone access is currently being requested.
|
|
1652
|
+
*/
|
|
1653
|
+
get isRequestingPhoneAccess() {
|
|
1654
|
+
return this.requestingPhoneAccess;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* True if write access is currently being requested.
|
|
1658
|
+
*/
|
|
1659
|
+
get isRequestingWriteAccess() {
|
|
1660
|
+
return this.requestingWriteAccess;
|
|
1580
1661
|
}
|
|
1581
1662
|
/**
|
|
1582
1663
|
* Informs the Telegram app that the Mini App is ready to be displayed.
|
|
@@ -1591,24 +1672,63 @@ class $e {
|
|
|
1591
1672
|
this.postEvent("web_app_ready");
|
|
1592
1673
|
}
|
|
1593
1674
|
/**
|
|
1594
|
-
* Requests current user
|
|
1675
|
+
* Requests current user contact information. In contrary to requestPhoneAccess, this method
|
|
1676
|
+
* returns promise with contact information that rejects in case, user denied access, or request
|
|
1677
|
+
* failed.
|
|
1678
|
+
* @param options - additional options.
|
|
1595
1679
|
*/
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1680
|
+
async requestContact({ timeout: t = 5e3 } = {}) {
|
|
1681
|
+
try {
|
|
1682
|
+
return await this.getRequestedContact();
|
|
1683
|
+
} catch {
|
|
1684
|
+
}
|
|
1685
|
+
if (await this.requestPhoneAccess() !== "sent")
|
|
1686
|
+
throw new Error("Access denied.");
|
|
1687
|
+
const s = Date.now() + t;
|
|
1688
|
+
let n = 50;
|
|
1689
|
+
return xt(async () => {
|
|
1690
|
+
for (; Date.now() < s; ) {
|
|
1691
|
+
try {
|
|
1692
|
+
return await this.getRequestedContact();
|
|
1693
|
+
} catch {
|
|
1694
|
+
}
|
|
1695
|
+
await Ee(n), n += 50;
|
|
1696
|
+
}
|
|
1697
|
+
throw new Error("Unable to retrieve requested contact.");
|
|
1698
|
+
}, t);
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Requests current user phone access. Method returns promise, which resolves
|
|
1702
|
+
* status of the request. In case, user accepted the request, Mini App bot will receive
|
|
1703
|
+
* the according notification.
|
|
1704
|
+
*
|
|
1705
|
+
* To obtain the retrieved information instead, utilize the requestContact method.
|
|
1706
|
+
* @param options - additional options.
|
|
1707
|
+
* @see requestContact
|
|
1708
|
+
*/
|
|
1709
|
+
requestPhoneAccess(t = {}) {
|
|
1710
|
+
if (this.requestingPhoneAccess)
|
|
1711
|
+
throw new Error("Phone access is already being requested.");
|
|
1712
|
+
return this.requestingPhoneAccess = !0, m("web_app_request_phone", "phone_requested", {
|
|
1713
|
+
...t,
|
|
1714
|
+
postEvent: this.postEvent
|
|
1715
|
+
}).then((e) => e.status).finally(() => {
|
|
1716
|
+
this.requestingPhoneAccess = !1;
|
|
1717
|
+
});
|
|
1602
1718
|
}
|
|
1603
1719
|
/**
|
|
1604
1720
|
* Requests write message access to current user.
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
"
|
|
1610
|
-
|
|
1611
|
-
|
|
1721
|
+
* @param options - additional options.
|
|
1722
|
+
*/
|
|
1723
|
+
requestWriteAccess(t = {}) {
|
|
1724
|
+
if (this.requestingWriteAccess)
|
|
1725
|
+
throw new Error("Write access is already being requested.");
|
|
1726
|
+
return this.requestingWriteAccess = !0, m("web_app_request_write_access", "write_access_requested", {
|
|
1727
|
+
...t,
|
|
1728
|
+
postEvent: this.postEvent
|
|
1729
|
+
}).then((e) => e.status).finally(() => {
|
|
1730
|
+
this.requestingWriteAccess = !1;
|
|
1731
|
+
});
|
|
1612
1732
|
}
|
|
1613
1733
|
/**
|
|
1614
1734
|
* A method used to send data to the bot. When this method called, a service message sent to
|
|
@@ -1630,7 +1750,7 @@ class $e {
|
|
|
1630
1750
|
* @param color - color key or RGB color.
|
|
1631
1751
|
*/
|
|
1632
1752
|
setHeaderColor(t) {
|
|
1633
|
-
this.postEvent("web_app_set_header_color",
|
|
1753
|
+
this.postEvent("web_app_set_header_color", lt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
|
|
1634
1754
|
}
|
|
1635
1755
|
/**
|
|
1636
1756
|
* Updates current Mini App background color.
|
|
@@ -1658,47 +1778,48 @@ class $e {
|
|
|
1658
1778
|
});
|
|
1659
1779
|
}
|
|
1660
1780
|
}
|
|
1661
|
-
function
|
|
1781
|
+
function Be(r, t, e, s, n, i) {
|
|
1662
1782
|
const {
|
|
1663
|
-
backgroundColor:
|
|
1664
|
-
headerColor:
|
|
1665
|
-
} = r ?
|
|
1666
|
-
headerColor:
|
|
1667
|
-
backgroundColor:
|
|
1783
|
+
backgroundColor: a = t,
|
|
1784
|
+
headerColor: c = "bg_color"
|
|
1785
|
+
} = r ? $("mini-app") || {} : {}, u = new Te({
|
|
1786
|
+
headerColor: c,
|
|
1787
|
+
backgroundColor: a,
|
|
1668
1788
|
version: e,
|
|
1669
1789
|
botInline: s,
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1790
|
+
createRequestId: n,
|
|
1791
|
+
postEvent: i
|
|
1792
|
+
}), p = () => L("mini-app", {
|
|
1793
|
+
backgroundColor: u.backgroundColor,
|
|
1794
|
+
headerColor: u.headerColor
|
|
1674
1795
|
});
|
|
1675
|
-
return
|
|
1796
|
+
return u.on("change", p), u;
|
|
1676
1797
|
}
|
|
1677
|
-
function
|
|
1798
|
+
function De() {
|
|
1678
1799
|
let r = 0;
|
|
1679
1800
|
return () => (r += 1, r.toString());
|
|
1680
1801
|
}
|
|
1681
|
-
class
|
|
1802
|
+
class We {
|
|
1682
1803
|
constructor(t, e, s = f) {
|
|
1683
|
-
o(this, "ee", new
|
|
1804
|
+
o(this, "ee", new w());
|
|
1684
1805
|
o(this, "state");
|
|
1685
1806
|
/**
|
|
1686
1807
|
* Adds event listener.
|
|
1687
1808
|
* @param event - event name.
|
|
1688
1809
|
* @param listener - event listener.
|
|
1689
1810
|
*/
|
|
1690
|
-
o(this, "on", (t, e) => t === "click" ?
|
|
1811
|
+
o(this, "on", (t, e) => t === "click" ? y("settings_button_pressed", e) : this.ee.on(t, e));
|
|
1691
1812
|
/**
|
|
1692
1813
|
* Removes event listener.
|
|
1693
1814
|
* @param event - event name.
|
|
1694
1815
|
* @param listener - event listener.
|
|
1695
1816
|
*/
|
|
1696
|
-
o(this, "off", (t, e) => t === "click" ?
|
|
1817
|
+
o(this, "off", (t, e) => t === "click" ? I("settings_button_pressed", e) : this.ee.off(t, e));
|
|
1697
1818
|
/**
|
|
1698
1819
|
* Checks if specified method is supported by current component.
|
|
1699
1820
|
*/
|
|
1700
1821
|
o(this, "supports");
|
|
1701
|
-
this.postEvent = s, this.state = new
|
|
1822
|
+
this.postEvent = s, this.state = new _({ isVisible: t }, this.ee), this.supports = E(e, {
|
|
1702
1823
|
show: "web_app_setup_settings_button",
|
|
1703
1824
|
hide: "web_app_setup_settings_button"
|
|
1704
1825
|
});
|
|
@@ -1725,18 +1846,18 @@ class Re {
|
|
|
1725
1846
|
this.isVisible = !0;
|
|
1726
1847
|
}
|
|
1727
1848
|
}
|
|
1728
|
-
function
|
|
1729
|
-
const { isVisible: s = !1 } = r ?
|
|
1849
|
+
function Ne(r, t, e) {
|
|
1850
|
+
const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new We(s, t, e);
|
|
1730
1851
|
return n.on("change", () => {
|
|
1731
|
-
|
|
1852
|
+
L("settings-button", { isVisible: n.isVisible });
|
|
1732
1853
|
}), n;
|
|
1733
1854
|
}
|
|
1734
|
-
function
|
|
1735
|
-
const t = new
|
|
1855
|
+
function Oe(r) {
|
|
1856
|
+
const t = new Ft(r);
|
|
1736
1857
|
return t.listen(), t;
|
|
1737
1858
|
}
|
|
1738
|
-
async function
|
|
1739
|
-
const t = await
|
|
1859
|
+
async function At(r) {
|
|
1860
|
+
const t = await m("web_app_request_viewport", "viewport_changed", r);
|
|
1740
1861
|
return {
|
|
1741
1862
|
height: t.height,
|
|
1742
1863
|
width: t.width,
|
|
@@ -1747,9 +1868,9 @@ async function Pt(r) {
|
|
|
1747
1868
|
function D(r) {
|
|
1748
1869
|
return r < 0 ? 0 : r;
|
|
1749
1870
|
}
|
|
1750
|
-
class
|
|
1871
|
+
class G {
|
|
1751
1872
|
constructor(t) {
|
|
1752
|
-
o(this, "ee", new
|
|
1873
|
+
o(this, "ee", new w());
|
|
1753
1874
|
o(this, "state");
|
|
1754
1875
|
o(this, "postEvent");
|
|
1755
1876
|
/**
|
|
@@ -1767,7 +1888,7 @@ class j {
|
|
|
1767
1888
|
stableHeight: i,
|
|
1768
1889
|
postEvent: a = f
|
|
1769
1890
|
} = t;
|
|
1770
|
-
this.postEvent = a, this.state = new
|
|
1891
|
+
this.postEvent = a, this.state = new _({
|
|
1771
1892
|
height: D(e),
|
|
1772
1893
|
isExpanded: s,
|
|
1773
1894
|
stableHeight: D(i),
|
|
@@ -1780,7 +1901,7 @@ class j {
|
|
|
1780
1901
|
* @param options - options to request fresh data.
|
|
1781
1902
|
*/
|
|
1782
1903
|
sync(t) {
|
|
1783
|
-
return
|
|
1904
|
+
return At(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
|
|
1784
1905
|
this.state.set({
|
|
1785
1906
|
height: e,
|
|
1786
1907
|
width: n,
|
|
@@ -1830,7 +1951,7 @@ class j {
|
|
|
1830
1951
|
* @returns Function to stop listening.
|
|
1831
1952
|
*/
|
|
1832
1953
|
listen() {
|
|
1833
|
-
return
|
|
1954
|
+
return y("viewport_changed", (t) => {
|
|
1834
1955
|
const {
|
|
1835
1956
|
height: e,
|
|
1836
1957
|
width: s,
|
|
@@ -1876,23 +1997,23 @@ class j {
|
|
|
1876
1997
|
return this.stableHeight === this.height;
|
|
1877
1998
|
}
|
|
1878
1999
|
}
|
|
1879
|
-
function
|
|
2000
|
+
function Rt(r) {
|
|
1880
2001
|
return !["macos", "web", "weba"].includes(r);
|
|
1881
2002
|
}
|
|
1882
|
-
function
|
|
1883
|
-
if (r || !
|
|
1884
|
-
return new
|
|
2003
|
+
function Vt(r, t, e) {
|
|
2004
|
+
if (r || !Rt(t))
|
|
2005
|
+
return new G({
|
|
1885
2006
|
height: window.innerHeight,
|
|
1886
2007
|
isExpanded: !0,
|
|
1887
2008
|
postEvent: e,
|
|
1888
2009
|
stableHeight: window.innerHeight,
|
|
1889
2010
|
width: window.innerWidth
|
|
1890
2011
|
});
|
|
1891
|
-
const s =
|
|
1892
|
-
return s ? new
|
|
2012
|
+
const s = $("viewport");
|
|
2013
|
+
return s ? new G({ ...s, postEvent: e }) : null;
|
|
1893
2014
|
}
|
|
1894
|
-
function
|
|
1895
|
-
return r.listen(), r.on("change", () =>
|
|
2015
|
+
function It(r) {
|
|
2016
|
+
return r.listen(), r.on("change", () => L("viewport", {
|
|
1896
2017
|
height: r.height,
|
|
1897
2018
|
isExpanded: r.isExpanded,
|
|
1898
2019
|
stableHeight: r.stableHeight,
|
|
@@ -1900,8 +2021,8 @@ function qt(r) {
|
|
|
1900
2021
|
})), r;
|
|
1901
2022
|
}
|
|
1902
2023
|
function He(r, t, e) {
|
|
1903
|
-
const s =
|
|
1904
|
-
|
|
2024
|
+
const s = It(
|
|
2025
|
+
Vt(r, t, e) || new G({
|
|
1905
2026
|
width: 0,
|
|
1906
2027
|
height: 0,
|
|
1907
2028
|
isExpanded: !1,
|
|
@@ -1909,13 +2030,13 @@ function He(r, t, e) {
|
|
|
1909
2030
|
stableHeight: 0
|
|
1910
2031
|
})
|
|
1911
2032
|
);
|
|
1912
|
-
return
|
|
2033
|
+
return Rt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
|
|
1913
2034
|
console.error("Unable to actualize viewport state", n);
|
|
1914
2035
|
}), s;
|
|
1915
2036
|
}
|
|
1916
|
-
async function
|
|
1917
|
-
return
|
|
1918
|
-
|
|
2037
|
+
async function Ue(r, t, e) {
|
|
2038
|
+
return It(
|
|
2039
|
+
Vt(r, t, e) || await At({ postEvent: e, timeout: 100 }).then(({ height: s, isStateStable: n, ...i }) => new G({
|
|
1919
2040
|
...i,
|
|
1920
2041
|
height: s,
|
|
1921
2042
|
stableHeight: n ? s : 0
|
|
@@ -1925,7 +2046,7 @@ async function Ne(r, t, e) {
|
|
|
1925
2046
|
function S(r, t) {
|
|
1926
2047
|
document.documentElement.style.setProperty(r, t);
|
|
1927
2048
|
}
|
|
1928
|
-
function
|
|
2049
|
+
function Me(r, t) {
|
|
1929
2050
|
const e = () => {
|
|
1930
2051
|
S("--tg-background-color", r.backgroundColor);
|
|
1931
2052
|
}, s = () => {
|
|
@@ -1937,7 +2058,7 @@ function Oe(r, t) {
|
|
|
1937
2058
|
};
|
|
1938
2059
|
t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
|
|
1939
2060
|
}
|
|
1940
|
-
function
|
|
2061
|
+
function je(r) {
|
|
1941
2062
|
const t = () => {
|
|
1942
2063
|
const e = r.getState();
|
|
1943
2064
|
Object.entries(e).forEach(([s, n]) => {
|
|
@@ -1949,22 +2070,22 @@ function We(r) {
|
|
|
1949
2070
|
};
|
|
1950
2071
|
r.on("change", t), t();
|
|
1951
2072
|
}
|
|
1952
|
-
function
|
|
2073
|
+
function ot(r) {
|
|
1953
2074
|
const t = () => S("--tg-viewport-height", `${r.height}px`), e = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-height", `${r.stableHeight}px`);
|
|
1954
2075
|
r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
|
|
1955
2076
|
}
|
|
1956
|
-
function
|
|
2077
|
+
function Ge(r) {
|
|
1957
2078
|
return typeof r == "object" ? r : r ? {
|
|
1958
2079
|
themeParams: !0,
|
|
1959
2080
|
viewport: !0,
|
|
1960
2081
|
miniApp: !0
|
|
1961
2082
|
} : {};
|
|
1962
2083
|
}
|
|
1963
|
-
function
|
|
1964
|
-
const n =
|
|
1965
|
-
n.miniApp &&
|
|
2084
|
+
function at(r, t, e, s) {
|
|
2085
|
+
const n = Ge(r);
|
|
2086
|
+
n.miniApp && Me(t, e), n.themeParams && je(e), n.viewport && (s instanceof Promise ? s.then(ot) : ot(s));
|
|
1966
2087
|
}
|
|
1967
|
-
function
|
|
2088
|
+
function Fe(r) {
|
|
1968
2089
|
const { hostname: t, pathname: e } = new URL(r, window.location.href);
|
|
1969
2090
|
if (t !== "t.me")
|
|
1970
2091
|
throw new Error(`Incorrect hostname: ${t}`);
|
|
@@ -1973,9 +2094,9 @@ function Ue(r) {
|
|
|
1973
2094
|
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
|
|
1974
2095
|
return s[2];
|
|
1975
2096
|
}
|
|
1976
|
-
class
|
|
2097
|
+
class ze {
|
|
1977
2098
|
constructor(t, e = f) {
|
|
1978
|
-
o(this, "ee", new
|
|
2099
|
+
o(this, "ee", new w());
|
|
1979
2100
|
o(this, "state");
|
|
1980
2101
|
/**
|
|
1981
2102
|
* Adds new event listener.
|
|
@@ -1989,7 +2110,7 @@ class je {
|
|
|
1989
2110
|
* Checks if specified method is supported by current component.
|
|
1990
2111
|
*/
|
|
1991
2112
|
o(this, "supports");
|
|
1992
|
-
this.postEvent = e, this.state = new
|
|
2113
|
+
this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, { open: "web_app_open_invoice" });
|
|
1993
2114
|
}
|
|
1994
2115
|
set isOpened(t) {
|
|
1995
2116
|
this.state.set("isOpened", t);
|
|
@@ -2003,10 +2124,10 @@ class je {
|
|
|
2003
2124
|
async open(t, e) {
|
|
2004
2125
|
if (this.isOpened)
|
|
2005
2126
|
throw new Error("Invoice is already opened");
|
|
2006
|
-
const s = e ?
|
|
2127
|
+
const s = e ? Fe(t) : t;
|
|
2007
2128
|
this.isOpened = !0;
|
|
2008
2129
|
try {
|
|
2009
|
-
return (await
|
|
2130
|
+
return (await m(
|
|
2010
2131
|
"web_app_open_invoice",
|
|
2011
2132
|
{ slug: s },
|
|
2012
2133
|
"invoice_closed",
|
|
@@ -2022,7 +2143,7 @@ class je {
|
|
|
2022
2143
|
}
|
|
2023
2144
|
}
|
|
2024
2145
|
}
|
|
2025
|
-
function
|
|
2146
|
+
function Je(r) {
|
|
2026
2147
|
const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
|
|
2027
2148
|
let n;
|
|
2028
2149
|
if (e.length > 64)
|
|
@@ -2046,9 +2167,9 @@ function Ge(r) {
|
|
|
2046
2167
|
return { ...i, id: a };
|
|
2047
2168
|
}), { title: e, message: t, buttons: n };
|
|
2048
2169
|
}
|
|
2049
|
-
class
|
|
2170
|
+
class Qe {
|
|
2050
2171
|
constructor(t, e = f) {
|
|
2051
|
-
o(this, "ee", new
|
|
2172
|
+
o(this, "ee", new w());
|
|
2052
2173
|
o(this, "state");
|
|
2053
2174
|
/**
|
|
2054
2175
|
* Adds new event listener.
|
|
@@ -2062,7 +2183,7 @@ class Fe {
|
|
|
2062
2183
|
* Checks if specified method is supported by current component.
|
|
2063
2184
|
*/
|
|
2064
2185
|
o(this, "supports");
|
|
2065
|
-
this.postEvent = e, this.state = new
|
|
2186
|
+
this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, { open: "web_app_open_popup" });
|
|
2066
2187
|
}
|
|
2067
2188
|
set isOpened(t) {
|
|
2068
2189
|
this.state.set("isOpened", t);
|
|
@@ -2089,9 +2210,9 @@ class Fe {
|
|
|
2089
2210
|
open(t) {
|
|
2090
2211
|
if (this.isOpened)
|
|
2091
2212
|
throw new Error("Popup is already opened.");
|
|
2092
|
-
return this.isOpened = !0,
|
|
2213
|
+
return this.isOpened = !0, m(
|
|
2093
2214
|
"web_app_open_popup",
|
|
2094
|
-
|
|
2215
|
+
Je(t),
|
|
2095
2216
|
"popup_closed",
|
|
2096
2217
|
{ postEvent: this.postEvent }
|
|
2097
2218
|
).then(({ button_id: e = null }) => e).finally(() => {
|
|
@@ -2099,9 +2220,9 @@ class Fe {
|
|
|
2099
2220
|
});
|
|
2100
2221
|
}
|
|
2101
2222
|
}
|
|
2102
|
-
class
|
|
2223
|
+
class Ze {
|
|
2103
2224
|
constructor(t, e = f) {
|
|
2104
|
-
o(this, "ee", new
|
|
2225
|
+
o(this, "ee", new w());
|
|
2105
2226
|
o(this, "state");
|
|
2106
2227
|
/**
|
|
2107
2228
|
* Adds new event listener.
|
|
@@ -2115,7 +2236,7 @@ class ze {
|
|
|
2115
2236
|
* Checks if specified method is supported by current component.
|
|
2116
2237
|
*/
|
|
2117
2238
|
o(this, "supports");
|
|
2118
|
-
this.postEvent = e, this.state = new
|
|
2239
|
+
this.postEvent = e, this.state = new _({ isOpened: !1 }, this.ee), this.supports = E(t, {
|
|
2119
2240
|
close: "web_app_close_scan_qr_popup",
|
|
2120
2241
|
open: "web_app_open_scan_qr_popup"
|
|
2121
2242
|
});
|
|
@@ -2146,7 +2267,7 @@ class ze {
|
|
|
2146
2267
|
throw new Error("QR scanner is already opened.");
|
|
2147
2268
|
this.isOpened = !0;
|
|
2148
2269
|
try {
|
|
2149
|
-
const e = await
|
|
2270
|
+
const e = await m(
|
|
2150
2271
|
"web_app_open_scan_qr_popup",
|
|
2151
2272
|
{ text: t },
|
|
2152
2273
|
["qr_text_received", "scan_qr_popup_closed"],
|
|
@@ -2158,7 +2279,7 @@ class ze {
|
|
|
2158
2279
|
}
|
|
2159
2280
|
}
|
|
2160
2281
|
}
|
|
2161
|
-
class
|
|
2282
|
+
class Ke {
|
|
2162
2283
|
constructor(t, e, s = f) {
|
|
2163
2284
|
/**
|
|
2164
2285
|
* Checks if specified method is supported by current component.
|
|
@@ -2168,9 +2289,9 @@ class Je {
|
|
|
2168
2289
|
* Checks if specified method parameter is supported by current component.
|
|
2169
2290
|
*/
|
|
2170
2291
|
o(this, "supportsParam");
|
|
2171
|
-
this.version = t, this.createRequestId = e, this.postEvent = s, this.supports =
|
|
2292
|
+
this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = E(t, {
|
|
2172
2293
|
readTextFromClipboard: "web_app_read_text_from_clipboard"
|
|
2173
|
-
}), this.supportsParam =
|
|
2294
|
+
}), this.supportsParam = kt(t, {
|
|
2174
2295
|
"openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
|
|
2175
2296
|
});
|
|
2176
2297
|
}
|
|
@@ -2221,7 +2342,7 @@ class Je {
|
|
|
2221
2342
|
* - Access to clipboard is not allowed
|
|
2222
2343
|
*/
|
|
2223
2344
|
readTextFromClipboard() {
|
|
2224
|
-
return
|
|
2345
|
+
return m(
|
|
2225
2346
|
"web_app_read_text_from_clipboard",
|
|
2226
2347
|
{ req_id: this.createRequestId() },
|
|
2227
2348
|
"clipboard_text_received",
|
|
@@ -2229,7 +2350,7 @@ class Je {
|
|
|
2229
2350
|
).then(({ data: t = null }) => t);
|
|
2230
2351
|
}
|
|
2231
2352
|
}
|
|
2232
|
-
function
|
|
2353
|
+
function ur(r = {}) {
|
|
2233
2354
|
const {
|
|
2234
2355
|
async: t = !1,
|
|
2235
2356
|
cssVars: e = !1,
|
|
@@ -2243,51 +2364,52 @@ function or(r = {}) {
|
|
|
2243
2364
|
version: a,
|
|
2244
2365
|
platform: c,
|
|
2245
2366
|
themeParams: u,
|
|
2246
|
-
botInline:
|
|
2367
|
+
botInline: p = !1
|
|
2247
2368
|
},
|
|
2248
|
-
isPageReload:
|
|
2249
|
-
} =
|
|
2250
|
-
|
|
2369
|
+
isPageReload: l
|
|
2370
|
+
} = Ct(), b = De(), d = ye(a);
|
|
2371
|
+
vt() && (s && Ae(), d("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => window.location.reload()));
|
|
2251
2372
|
const C = {
|
|
2252
|
-
backButton:
|
|
2253
|
-
closingBehavior:
|
|
2254
|
-
cloudStorage: new
|
|
2255
|
-
createRequestId:
|
|
2256
|
-
hapticFeedback: new
|
|
2257
|
-
invoice: new
|
|
2373
|
+
backButton: Re(l, a, d),
|
|
2374
|
+
closingBehavior: Ve(l, d),
|
|
2375
|
+
cloudStorage: new xe(a, b, d),
|
|
2376
|
+
createRequestId: b,
|
|
2377
|
+
hapticFeedback: new qe(a, d),
|
|
2378
|
+
invoice: new ze(a, d),
|
|
2258
2379
|
mainButton: Le(
|
|
2259
|
-
|
|
2380
|
+
l,
|
|
2260
2381
|
u.buttonColor || "#000000",
|
|
2261
2382
|
u.buttonTextColor || "#ffffff",
|
|
2262
|
-
|
|
2383
|
+
d
|
|
2263
2384
|
),
|
|
2264
|
-
miniApp:
|
|
2265
|
-
|
|
2385
|
+
miniApp: Be(
|
|
2386
|
+
l,
|
|
2266
2387
|
u.backgroundColor || "#ffffff",
|
|
2267
2388
|
a,
|
|
2268
|
-
|
|
2269
|
-
|
|
2389
|
+
p,
|
|
2390
|
+
b,
|
|
2391
|
+
d
|
|
2270
2392
|
),
|
|
2271
|
-
popup: new
|
|
2272
|
-
postEvent:
|
|
2273
|
-
qrScanner: new
|
|
2274
|
-
settingsButton:
|
|
2275
|
-
themeParams:
|
|
2276
|
-
utils: new
|
|
2393
|
+
popup: new Qe(a, d),
|
|
2394
|
+
postEvent: d,
|
|
2395
|
+
qrScanner: new Ze(a, d),
|
|
2396
|
+
settingsButton: Ne(l, a, d),
|
|
2397
|
+
themeParams: Oe(u),
|
|
2398
|
+
utils: new Ke(a, b, d),
|
|
2277
2399
|
...n ? {
|
|
2278
|
-
initData: new
|
|
2400
|
+
initData: new Ut(n),
|
|
2279
2401
|
initDataRaw: i
|
|
2280
2402
|
} : {}
|
|
2281
|
-
}, x = t ?
|
|
2282
|
-
return x instanceof Promise ? x.then((
|
|
2403
|
+
}, x = t ? Ue(l, c, d) : He(l, c, d);
|
|
2404
|
+
return x instanceof Promise ? x.then((T) => (at(
|
|
2283
2405
|
e,
|
|
2284
2406
|
C.miniApp,
|
|
2285
2407
|
C.themeParams,
|
|
2286
|
-
|
|
2408
|
+
T
|
|
2287
2409
|
), {
|
|
2288
2410
|
...C,
|
|
2289
|
-
viewport:
|
|
2290
|
-
})) : (
|
|
2411
|
+
viewport: T
|
|
2412
|
+
})) : (at(
|
|
2291
2413
|
e,
|
|
2292
2414
|
C.miniApp,
|
|
2293
2415
|
C.themeParams,
|
|
@@ -2299,14 +2421,14 @@ function or(r = {}) {
|
|
|
2299
2421
|
throw n;
|
|
2300
2422
|
}
|
|
2301
2423
|
}
|
|
2302
|
-
function
|
|
2424
|
+
function W(r, t) {
|
|
2303
2425
|
return r.startsWith(t) ? r : `${t}${r}`;
|
|
2304
2426
|
}
|
|
2305
|
-
function
|
|
2427
|
+
function pr(r) {
|
|
2306
2428
|
const t = r.match(/#(.+)/);
|
|
2307
2429
|
return t ? t[1] : null;
|
|
2308
2430
|
}
|
|
2309
|
-
async function
|
|
2431
|
+
async function O(r) {
|
|
2310
2432
|
return r === 0 ? !0 : Promise.race([
|
|
2311
2433
|
new Promise((t) => {
|
|
2312
2434
|
window.addEventListener("popstate", function e() {
|
|
@@ -2319,14 +2441,14 @@ async function N(r) {
|
|
|
2319
2441
|
})
|
|
2320
2442
|
]);
|
|
2321
2443
|
}
|
|
2322
|
-
async function
|
|
2323
|
-
if (window.history.length <= 1 || (window.history.pushState(null, ""), await
|
|
2444
|
+
async function Ye() {
|
|
2445
|
+
if (window.history.length <= 1 || (window.history.pushState(null, ""), await O(1 - window.history.length)))
|
|
2324
2446
|
return;
|
|
2325
|
-
let t = await
|
|
2447
|
+
let t = await O(-1);
|
|
2326
2448
|
for (; t; )
|
|
2327
|
-
t = await
|
|
2449
|
+
t = await O(-1);
|
|
2328
2450
|
}
|
|
2329
|
-
class
|
|
2451
|
+
class Xe {
|
|
2330
2452
|
constructor(t, e, {
|
|
2331
2453
|
debug: s = !1,
|
|
2332
2454
|
loggerPrefix: n = "Navigator"
|
|
@@ -2341,11 +2463,11 @@ class Ze {
|
|
|
2341
2463
|
if (!i.startsWith("/") && i.length > 0)
|
|
2342
2464
|
throw new Error('Pathname should start with "/"');
|
|
2343
2465
|
return {
|
|
2344
|
-
pathname:
|
|
2345
|
-
search: a ?
|
|
2346
|
-
hash: c ?
|
|
2466
|
+
pathname: W(i, "/"),
|
|
2467
|
+
search: a ? W(a, "?") : "",
|
|
2468
|
+
hash: c ? W(c, "#") : ""
|
|
2347
2469
|
};
|
|
2348
|
-
}), this.logger = new
|
|
2470
|
+
}), this.logger = new Pt(`[${n}]`, s);
|
|
2349
2471
|
}
|
|
2350
2472
|
/**
|
|
2351
2473
|
* Converts entry to the navigation entry.
|
|
@@ -2361,7 +2483,7 @@ class Ze {
|
|
|
2361
2483
|
search: c,
|
|
2362
2484
|
hash: u
|
|
2363
2485
|
} = t;
|
|
2364
|
-
e = a + (c ?
|
|
2486
|
+
e = a + (c ? W(c, "?") : "") + (u ? W(u, "#") : "");
|
|
2365
2487
|
}
|
|
2366
2488
|
const {
|
|
2367
2489
|
pathname: s,
|
|
@@ -2525,14 +2647,14 @@ class Ze {
|
|
|
2525
2647
|
return this.entry.search;
|
|
2526
2648
|
}
|
|
2527
2649
|
}
|
|
2528
|
-
const
|
|
2529
|
-
class Lt extends
|
|
2650
|
+
const ct = 0, Z = 1, K = 2;
|
|
2651
|
+
class Lt extends Xe {
|
|
2530
2652
|
constructor(e, s, n = {}) {
|
|
2531
2653
|
super(e, s, {
|
|
2532
2654
|
...n,
|
|
2533
2655
|
loggerPrefix: "HashNavigator"
|
|
2534
2656
|
});
|
|
2535
|
-
o(this, "ee", new
|
|
2657
|
+
o(this, "ee", new w());
|
|
2536
2658
|
o(this, "attached", !1);
|
|
2537
2659
|
/**
|
|
2538
2660
|
* Handles window "popstate" event.
|
|
@@ -2541,13 +2663,13 @@ class Lt extends Ze {
|
|
|
2541
2663
|
o(this, "onPopState", async ({ state: e }) => {
|
|
2542
2664
|
if (this.logger.log('"popstate" event received. State:', e), e === null)
|
|
2543
2665
|
return this.push(window.location.hash.slice(1));
|
|
2544
|
-
if (e ===
|
|
2666
|
+
if (e === ct) {
|
|
2545
2667
|
this.logger.log("Void reached. Moving history forward"), window.history.forward();
|
|
2546
2668
|
return;
|
|
2547
2669
|
}
|
|
2548
|
-
if (e ===
|
|
2670
|
+
if (e === Z)
|
|
2549
2671
|
return this.back();
|
|
2550
|
-
if (e ===
|
|
2672
|
+
if (e === K)
|
|
2551
2673
|
return this.forward();
|
|
2552
2674
|
});
|
|
2553
2675
|
o(this, "back", () => super.back());
|
|
@@ -2590,7 +2712,7 @@ class Lt extends Ze {
|
|
|
2590
2712
|
async syncHistory() {
|
|
2591
2713
|
window.removeEventListener("popstate", this.onPopState);
|
|
2592
2714
|
const e = `#${this.path}`;
|
|
2593
|
-
await
|
|
2715
|
+
await Ye(), f("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e), window.history.pushState(K, ""), await O(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(K, ""), await O(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ct, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
|
|
2594
2716
|
}
|
|
2595
2717
|
emitChanged(e, s) {
|
|
2596
2718
|
this.ee.emit("change", {
|
|
@@ -2604,69 +2726,73 @@ class Lt extends Ze {
|
|
|
2604
2726
|
*/
|
|
2605
2727
|
async attach() {
|
|
2606
2728
|
if (!this.attached)
|
|
2607
|
-
return this.logger.log("Attaching", this), this.attached = !0,
|
|
2729
|
+
return this.logger.log("Attaching", this), this.attached = !0, y("back_button_pressed", this.back), this.syncHistory();
|
|
2608
2730
|
}
|
|
2609
2731
|
/**
|
|
2610
2732
|
* Detaches current navigator from the browser history.
|
|
2611
2733
|
*/
|
|
2612
2734
|
detach() {
|
|
2613
|
-
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState),
|
|
2735
|
+
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), I("back_button_pressed", this.back));
|
|
2614
2736
|
}
|
|
2615
2737
|
}
|
|
2616
2738
|
export {
|
|
2617
|
-
|
|
2739
|
+
ve as BackButton,
|
|
2618
2740
|
ke as ClosingBehavior,
|
|
2619
|
-
|
|
2620
|
-
|
|
2741
|
+
xe as CloudStorage,
|
|
2742
|
+
qe as HapticFeedback,
|
|
2621
2743
|
Lt as HashNavigator,
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
me as
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2744
|
+
Ut as InitData,
|
|
2745
|
+
ze as Invoice,
|
|
2746
|
+
Ie as MainButton,
|
|
2747
|
+
tt as MethodUnsupportedError,
|
|
2748
|
+
Te as MiniApp,
|
|
2749
|
+
Xe as Navigator,
|
|
2750
|
+
et as ParameterUnsupportedError,
|
|
2751
|
+
Qe as Popup,
|
|
2752
|
+
Ze as QRScanner,
|
|
2753
|
+
We as SettingsButton,
|
|
2754
|
+
Ft as ThemeParams,
|
|
2755
|
+
J as TimeoutError,
|
|
2756
|
+
Ke as Utils,
|
|
2757
|
+
G as Viewport,
|
|
2758
|
+
Ht as chatParser,
|
|
2759
|
+
Pe as classNames,
|
|
2760
|
+
me as compareVersions,
|
|
2761
|
+
ye as createPostEvent,
|
|
2762
|
+
pr as getHash,
|
|
2763
|
+
ur as init,
|
|
2764
|
+
wt as initDataParser,
|
|
2765
|
+
N as invokeCustomMethod,
|
|
2766
|
+
ft as isColorDark,
|
|
2767
|
+
vt as isIframe,
|
|
2768
|
+
lt as isRGB,
|
|
2769
|
+
Ot as isRGBShort,
|
|
2770
|
+
H as isRecord,
|
|
2771
|
+
sr as isTMA,
|
|
2772
|
+
cr as isTimeoutError,
|
|
2773
|
+
mt as launchParamsParser,
|
|
2774
|
+
hr as mergeClassNames,
|
|
2775
|
+
I as off,
|
|
2776
|
+
y as on,
|
|
2777
|
+
or as once,
|
|
2778
|
+
er as parseInitData,
|
|
2779
|
+
yt as parseLaunchParams,
|
|
2780
|
+
bt as parseThemeParams,
|
|
2656
2781
|
f as postEvent,
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2782
|
+
m as request,
|
|
2783
|
+
rr as requestThemeParams,
|
|
2784
|
+
At as requestViewport,
|
|
2785
|
+
Ct as retrieveLaunchData,
|
|
2786
|
+
Zt as serializeLaunchParams,
|
|
2787
|
+
Gt as serializeThemeParams,
|
|
2788
|
+
nr as setDebug,
|
|
2789
|
+
ir as setTargetOrigin,
|
|
2790
|
+
ar as subscribe,
|
|
2666
2791
|
A as supports,
|
|
2667
2792
|
_t as themeParamsParser,
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2793
|
+
dt as toRGB,
|
|
2794
|
+
be as unsubscribe,
|
|
2795
|
+
rt as userParser,
|
|
2796
|
+
xt as withTimeout
|
|
2671
2797
|
};
|
|
2672
2798
|
//# sourceMappingURL=index.mjs.map
|