@tma.js/sdk 1.0.2 → 1.1.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/index.d.ts +1 -0
- package/dist/dts/init/creators/createSettingsButton.d.ts +10 -0
- package/dist/dts/init/creators/index.d.ts +1 -0
- package/dist/dts/init/init.d.ts +1 -0
- package/dist/dts/init/types.d.ts +2 -0
- package/dist/dts/settings-button/SettingsButton.d.ts +42 -0
- package/dist/dts/settings-button/index.d.ts +2 -0
- package/dist/dts/settings-button/types.d.ts +10 -0
- package/dist/dts/storage.d.ts +3 -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 +592 -534
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/init/creators/createSettingsButton.ts +25 -0
- package/src/init/creators/createViewport.ts +16 -5
- package/src/init/creators/index.ts +1 -0
- package/src/init/init.ts +8 -5
- package/src/init/types.ts +2 -0
- package/src/settings-button/SettingsButton.ts +85 -0
- package/src/settings-button/index.ts +2 -0
- package/src/settings-button/types.ts +15 -0
- package/src/storage.ts +3 -0
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
var $t = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var o = (r, t, e) => (
|
|
4
|
-
function
|
|
2
|
+
var Tt = (r, t, e) => t in r ? $t(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
|
+
function O(r) {
|
|
5
5
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
6
6
|
}
|
|
7
7
|
function ct() {
|
|
8
8
|
return performance.getEntriesByType("navigation")[0] || null;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function It() {
|
|
11
11
|
const r = ct();
|
|
12
12
|
return r ? r.type === "reload" : null;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function q() {
|
|
15
15
|
return new TypeError("Value has unexpected type");
|
|
16
16
|
}
|
|
17
17
|
class G extends Error {
|
|
18
|
-
constructor(e, { cause:
|
|
19
|
-
super(`Unable to parse value${
|
|
18
|
+
constructor(e, { cause: s, type: n } = {}) {
|
|
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, G.prototype), this.type =
|
|
24
|
+
this.value = e, Object.setPrototypeOf(this, G.prototype), this.type = n;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
class F {
|
|
28
|
-
constructor(t, e,
|
|
29
|
-
this.parser = t, this.isOptional = e, this.type =
|
|
28
|
+
constructor(t, e, s) {
|
|
29
|
+
this.parser = t, this.isOptional = e, this.type = s;
|
|
30
30
|
}
|
|
31
31
|
parse(t) {
|
|
32
32
|
if (!(this.isOptional && t === void 0))
|
|
@@ -40,7 +40,7 @@ class F {
|
|
|
40
40
|
return this.isOptional = !0, this;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function Rt(r) {
|
|
44
44
|
if (Array.isArray(r))
|
|
45
45
|
return r;
|
|
46
46
|
if (typeof r == "string")
|
|
@@ -50,61 +50,61 @@ function It(r) {
|
|
|
50
50
|
return t;
|
|
51
51
|
} catch {
|
|
52
52
|
}
|
|
53
|
-
throw
|
|
53
|
+
throw q();
|
|
54
54
|
}
|
|
55
|
-
class
|
|
56
|
-
constructor(e,
|
|
57
|
-
super(
|
|
55
|
+
class Bt extends F {
|
|
56
|
+
constructor(e, s, n) {
|
|
57
|
+
super(Rt, s, n);
|
|
58
58
|
o(this, "itemParser");
|
|
59
59
|
this.itemParser = typeof e == "function" ? e : e.parse.bind(e);
|
|
60
60
|
}
|
|
61
61
|
parse(e) {
|
|
62
|
-
const
|
|
63
|
-
return
|
|
62
|
+
const s = super.parse(e);
|
|
63
|
+
return s === void 0 ? s : s.map(this.itemParser);
|
|
64
64
|
}
|
|
65
65
|
of(e) {
|
|
66
66
|
return this.itemParser = typeof e == "function" ? e : e.parse.bind(e), this;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function L(r, t) {
|
|
70
70
|
return () => new F(r, !1, t);
|
|
71
71
|
}
|
|
72
72
|
class U extends Error {
|
|
73
|
-
constructor(t, { cause: e, type:
|
|
74
|
-
super(`Unable to parse field "${t}"${
|
|
73
|
+
constructor(t, { cause: e, type: s } = {}) {
|
|
74
|
+
super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, U.prototype);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
function ht(r, t) {
|
|
78
78
|
const e = {};
|
|
79
|
-
for (const
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
79
|
+
for (const s in r) {
|
|
80
|
+
const n = r[s];
|
|
81
|
+
if (!n)
|
|
82
82
|
continue;
|
|
83
83
|
let i, a;
|
|
84
|
-
if (typeof
|
|
85
|
-
i =
|
|
84
|
+
if (typeof n == "function" || "parse" in n)
|
|
85
|
+
i = s, a = typeof n == "function" ? n : n.parse.bind(n);
|
|
86
86
|
else {
|
|
87
|
-
const { type:
|
|
88
|
-
i =
|
|
87
|
+
const { type: d } = n;
|
|
88
|
+
i = n.from || s, a = typeof d == "function" ? d : d.parse.bind(d);
|
|
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 U(i, { cause:
|
|
94
|
+
} catch (d) {
|
|
95
|
+
throw d instanceof G ? new U(i, {
|
|
96
|
+
type: d.type,
|
|
97
|
+
cause: d
|
|
98
|
+
}) : new U(i, { cause: d });
|
|
99
99
|
}
|
|
100
|
-
c !== void 0 && (e[
|
|
100
|
+
c !== void 0 && (e[s] = c);
|
|
101
101
|
}
|
|
102
102
|
return e;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return new
|
|
104
|
+
function Dt(r) {
|
|
105
|
+
return new Bt((t) => t, !1, r);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const k = L((r) => {
|
|
108
108
|
if (typeof r == "boolean")
|
|
109
109
|
return r;
|
|
110
110
|
const t = String(r);
|
|
@@ -112,8 +112,8 @@ const C = $((r) => {
|
|
|
112
112
|
return !0;
|
|
113
113
|
if (t === "0" || t === "false")
|
|
114
114
|
return !1;
|
|
115
|
-
throw
|
|
116
|
-
}, "boolean"),
|
|
115
|
+
throw q();
|
|
116
|
+
}, "boolean"), V = L((r) => {
|
|
117
117
|
if (typeof r == "number")
|
|
118
118
|
return r;
|
|
119
119
|
if (typeof r == "string") {
|
|
@@ -121,72 +121,72 @@ const C = $((r) => {
|
|
|
121
121
|
if (!Number.isNaN(t))
|
|
122
122
|
return t;
|
|
123
123
|
}
|
|
124
|
-
throw
|
|
125
|
-
}, "number"),
|
|
124
|
+
throw q();
|
|
125
|
+
}, "number"), Ht = L((r) => r instanceof Date ? r : new Date(V().parse(r) * 1e3), "Date");
|
|
126
126
|
function Z(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 q();
|
|
130
130
|
return t;
|
|
131
131
|
}
|
|
132
132
|
function g(r, t) {
|
|
133
133
|
return new F((e) => {
|
|
134
|
-
const
|
|
135
|
-
return ht(r, (
|
|
134
|
+
const s = Z(e);
|
|
135
|
+
return ht(r, (n) => s[n]);
|
|
136
136
|
}, !1, t);
|
|
137
137
|
}
|
|
138
138
|
function ut(r) {
|
|
139
139
|
return /^#[\da-f]{6}$/i.test(r);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function Nt(r) {
|
|
142
142
|
return /^#[\da-f]{3}$/i.test(r);
|
|
143
143
|
}
|
|
144
144
|
function pt(r) {
|
|
145
145
|
const t = r.replace(/\s/g, "").toLowerCase();
|
|
146
146
|
if (ut(t))
|
|
147
147
|
return t;
|
|
148
|
-
if (
|
|
149
|
-
let
|
|
150
|
-
for (let
|
|
151
|
-
|
|
152
|
-
return
|
|
148
|
+
if (Nt(t)) {
|
|
149
|
+
let s = "#";
|
|
150
|
+
for (let n = 0; n < 3; n += 1)
|
|
151
|
+
s += t[1 + n].repeat(2);
|
|
152
|
+
return s;
|
|
153
153
|
}
|
|
154
154
|
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}\)$/);
|
|
155
155
|
if (e === null)
|
|
156
156
|
throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
|
|
157
|
-
return e.slice(1).reduce((
|
|
158
|
-
const i = parseInt(
|
|
159
|
-
return
|
|
157
|
+
return e.slice(1).reduce((s, n) => {
|
|
158
|
+
const i = parseInt(n, 10).toString(16);
|
|
159
|
+
return s + (i.length === 1 ? "0" : "") + i;
|
|
160
160
|
}, "#");
|
|
161
161
|
}
|
|
162
162
|
function lt(r) {
|
|
163
163
|
const t = pt(r);
|
|
164
164
|
return Math.sqrt(
|
|
165
|
-
[0.299, 0.587, 0.114].reduce((
|
|
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);
|
|
167
|
-
return
|
|
167
|
+
return s + a * a * n;
|
|
168
168
|
}, 0)
|
|
169
169
|
) < 120;
|
|
170
170
|
}
|
|
171
|
-
const h =
|
|
171
|
+
const h = L((r) => {
|
|
172
172
|
if (typeof r == "string" || typeof r == "number")
|
|
173
173
|
return r.toString();
|
|
174
|
-
throw
|
|
175
|
-
}, "string"), dt =
|
|
174
|
+
throw q();
|
|
175
|
+
}, "string"), dt = L((r) => pt(h().parse(r)), "rgb");
|
|
176
176
|
function ft(r, t) {
|
|
177
177
|
return new F((e) => {
|
|
178
178
|
if (typeof e != "string" && !(e instanceof URLSearchParams))
|
|
179
|
-
throw
|
|
180
|
-
const
|
|
181
|
-
return ht(r, (
|
|
182
|
-
const i =
|
|
179
|
+
throw q();
|
|
180
|
+
const s = typeof e == "string" ? new URLSearchParams(e) : e;
|
|
181
|
+
return ht(r, (n) => {
|
|
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 Ot() {
|
|
188
188
|
return g({
|
|
189
|
-
id:
|
|
189
|
+
id: V(),
|
|
190
190
|
type: h(),
|
|
191
191
|
title: h(),
|
|
192
192
|
photoUrl: {
|
|
@@ -196,7 +196,7 @@ function Nt() {
|
|
|
196
196
|
username: h().optional()
|
|
197
197
|
}, "Chat");
|
|
198
198
|
}
|
|
199
|
-
class
|
|
199
|
+
class Wt {
|
|
200
200
|
constructor(t) {
|
|
201
201
|
this.initData = t;
|
|
202
202
|
}
|
|
@@ -272,24 +272,24 @@ class Ot {
|
|
|
272
272
|
function tt() {
|
|
273
273
|
return g({
|
|
274
274
|
addedToAttachmentMenu: {
|
|
275
|
-
type:
|
|
275
|
+
type: k().optional(),
|
|
276
276
|
from: "added_to_attachment_menu"
|
|
277
277
|
},
|
|
278
278
|
allowsWriteToPm: {
|
|
279
|
-
type:
|
|
279
|
+
type: k().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: V(),
|
|
287
287
|
isBot: {
|
|
288
|
-
type:
|
|
288
|
+
type: k().optional(),
|
|
289
289
|
from: "is_bot"
|
|
290
290
|
},
|
|
291
291
|
isPremium: {
|
|
292
|
-
type:
|
|
292
|
+
type: k().optional(),
|
|
293
293
|
from: "is_premium"
|
|
294
294
|
},
|
|
295
295
|
languageCode: {
|
|
@@ -310,14 +310,14 @@ function tt() {
|
|
|
310
310
|
function gt() {
|
|
311
311
|
return ft({
|
|
312
312
|
authDate: {
|
|
313
|
-
type:
|
|
313
|
+
type: Ht(),
|
|
314
314
|
from: "auth_date"
|
|
315
315
|
},
|
|
316
316
|
canSendAfter: {
|
|
317
|
-
type:
|
|
317
|
+
type: V().optional(),
|
|
318
318
|
from: "can_send_after"
|
|
319
319
|
},
|
|
320
|
-
chat:
|
|
320
|
+
chat: Ot().optional(),
|
|
321
321
|
chatInstance: {
|
|
322
322
|
type: h().optional(),
|
|
323
323
|
from: "chat_instance"
|
|
@@ -339,34 +339,34 @@ function gt() {
|
|
|
339
339
|
user: tt().optional()
|
|
340
340
|
}, "InitData");
|
|
341
341
|
}
|
|
342
|
-
function
|
|
342
|
+
function Ye(r) {
|
|
343
343
|
return gt().parse(r);
|
|
344
344
|
}
|
|
345
|
-
function
|
|
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 Ut(r) {
|
|
349
349
|
return r.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`).replace(/(^|_)background/, (t, e) => `${e}bg`);
|
|
350
350
|
}
|
|
351
|
-
const
|
|
351
|
+
const _t = L(
|
|
352
352
|
(r) => {
|
|
353
353
|
const t = dt().optional();
|
|
354
|
-
return Object.entries(Z(r)).reduce((e, [
|
|
354
|
+
return Object.entries(Z(r)).reduce((e, [s, n]) => (e[Mt(s)] = t.parse(n), e), {});
|
|
355
355
|
},
|
|
356
356
|
"ThemeParams"
|
|
357
357
|
);
|
|
358
|
-
function
|
|
359
|
-
return
|
|
358
|
+
function wt(r) {
|
|
359
|
+
return _t().parse(r);
|
|
360
360
|
}
|
|
361
|
-
function
|
|
362
|
-
return
|
|
361
|
+
function Xe(r = {}) {
|
|
362
|
+
return b("web_app_request_theme", "theme_changed", r).then(wt);
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function jt(r) {
|
|
365
365
|
return JSON.stringify(
|
|
366
|
-
Object.entries(r).reduce((t, [e,
|
|
366
|
+
Object.entries(r).reduce((t, [e, s]) => (s && (t[Ut(e)] = s), t), {})
|
|
367
367
|
);
|
|
368
368
|
}
|
|
369
|
-
class
|
|
369
|
+
class _ {
|
|
370
370
|
constructor() {
|
|
371
371
|
o(this, "listeners", /* @__PURE__ */ new Map());
|
|
372
372
|
o(this, "subscribeListeners", []);
|
|
@@ -377,15 +377,15 @@ class w {
|
|
|
377
377
|
* @param listener - event listener.
|
|
378
378
|
* @param once - should listener called only once.
|
|
379
379
|
*/
|
|
380
|
-
addListener(t, e,
|
|
381
|
-
let
|
|
382
|
-
return
|
|
380
|
+
addListener(t, e, s) {
|
|
381
|
+
let n = this.listeners.get(t);
|
|
382
|
+
return n || (n = [], this.listeners.set(t, n)), n.push([e, s]), () => this.off(t, e);
|
|
383
383
|
}
|
|
384
384
|
emit(t, ...e) {
|
|
385
|
-
this.subscribeListeners.forEach((
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
this.subscribeListeners.forEach((n) => n(t, ...e));
|
|
386
|
+
const s = this.listeners.get(t);
|
|
387
|
+
s && s.forEach(([n, i], a) => {
|
|
388
|
+
n(...e), i && s.splice(a, 1);
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
391
|
/**
|
|
@@ -415,11 +415,11 @@ class w {
|
|
|
415
415
|
* @param listener - event listener.
|
|
416
416
|
*/
|
|
417
417
|
off(t, e) {
|
|
418
|
-
const
|
|
419
|
-
if (
|
|
420
|
-
for (let
|
|
421
|
-
if (e === n
|
|
422
|
-
|
|
418
|
+
const s = this.listeners.get(t);
|
|
419
|
+
if (s) {
|
|
420
|
+
for (let n = 0; n < s.length; n += 1)
|
|
421
|
+
if (e === s[n][0]) {
|
|
422
|
+
s.splice(n, 1);
|
|
423
423
|
return;
|
|
424
424
|
}
|
|
425
425
|
}
|
|
@@ -448,7 +448,7 @@ class w {
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
class
|
|
451
|
+
class w {
|
|
452
452
|
constructor(t, e) {
|
|
453
453
|
this.state = t, this.ee = e;
|
|
454
454
|
}
|
|
@@ -462,13 +462,13 @@ class b {
|
|
|
462
462
|
return { ...this.state };
|
|
463
463
|
}
|
|
464
464
|
set(t, e) {
|
|
465
|
-
let
|
|
465
|
+
let s = !1;
|
|
466
466
|
if (typeof t == "string")
|
|
467
|
-
|
|
467
|
+
s = this.internalSet(t, e);
|
|
468
468
|
else
|
|
469
|
-
for (const
|
|
470
|
-
this.internalSet(
|
|
471
|
-
|
|
469
|
+
for (const n in t)
|
|
470
|
+
this.internalSet(n, t[n]) && (s = !0);
|
|
471
|
+
s && this.ee.emit("change");
|
|
472
472
|
}
|
|
473
473
|
/**
|
|
474
474
|
* Returns value by specified key.
|
|
@@ -478,9 +478,9 @@ class b {
|
|
|
478
478
|
return this.state[t];
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
class
|
|
481
|
+
class Gt {
|
|
482
482
|
constructor(t) {
|
|
483
|
-
o(this, "ee", new
|
|
483
|
+
o(this, "ee", new _());
|
|
484
484
|
o(this, "state");
|
|
485
485
|
/**
|
|
486
486
|
* Adds new event listener.
|
|
@@ -490,7 +490,7 @@ class jt {
|
|
|
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 w(t, this.ee);
|
|
494
494
|
}
|
|
495
495
|
/**
|
|
496
496
|
* @since v6.10
|
|
@@ -562,8 +562,8 @@ class jt {
|
|
|
562
562
|
* @returns Function to stop listening.
|
|
563
563
|
*/
|
|
564
564
|
listen() {
|
|
565
|
-
return
|
|
566
|
-
this.state.set(
|
|
565
|
+
return m("theme_changed", (t) => {
|
|
566
|
+
this.state.set(wt(t.theme_params));
|
|
567
567
|
});
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
@@ -579,7 +579,7 @@ class jt {
|
|
|
579
579
|
function bt() {
|
|
580
580
|
return ft({
|
|
581
581
|
botInline: {
|
|
582
|
-
type:
|
|
582
|
+
type: k().optional(),
|
|
583
583
|
from: "tgWebAppBotInline"
|
|
584
584
|
},
|
|
585
585
|
initData: {
|
|
@@ -595,11 +595,11 @@ function bt() {
|
|
|
595
595
|
from: "tgWebAppPlatform"
|
|
596
596
|
},
|
|
597
597
|
showSettings: {
|
|
598
|
-
type:
|
|
598
|
+
type: k().optional(),
|
|
599
599
|
from: "tgWebAppShowSettings"
|
|
600
600
|
},
|
|
601
601
|
themeParams: {
|
|
602
|
-
type:
|
|
602
|
+
type: _t(),
|
|
603
603
|
from: "tgWebAppThemeParams"
|
|
604
604
|
},
|
|
605
605
|
version: {
|
|
@@ -611,10 +611,10 @@ function bt() {
|
|
|
611
611
|
function mt(r) {
|
|
612
612
|
return bt().parse(r);
|
|
613
613
|
}
|
|
614
|
-
function
|
|
614
|
+
function Ft() {
|
|
615
615
|
return mt(window.location.hash.slice(1));
|
|
616
616
|
}
|
|
617
|
-
function
|
|
617
|
+
function zt() {
|
|
618
618
|
const r = ct();
|
|
619
619
|
if (!r)
|
|
620
620
|
throw new Error("Unable to get first navigation entry.");
|
|
@@ -623,50 +623,50 @@ function Ft() {
|
|
|
623
623
|
throw new Error("First navigation entry does not contain hash part.");
|
|
624
624
|
return mt(t[1]);
|
|
625
625
|
}
|
|
626
|
-
function
|
|
626
|
+
function Jt() {
|
|
627
627
|
try {
|
|
628
|
-
return
|
|
628
|
+
return zt();
|
|
629
629
|
} catch {
|
|
630
630
|
}
|
|
631
631
|
try {
|
|
632
|
-
return
|
|
632
|
+
return Ft();
|
|
633
633
|
} catch {
|
|
634
634
|
}
|
|
635
635
|
return null;
|
|
636
636
|
}
|
|
637
|
-
function
|
|
637
|
+
function Qt(r) {
|
|
638
638
|
const {
|
|
639
639
|
initDataRaw: t,
|
|
640
640
|
themeParams: e,
|
|
641
|
-
platform:
|
|
642
|
-
version:
|
|
641
|
+
platform: s,
|
|
642
|
+
version: n,
|
|
643
643
|
showSettings: i,
|
|
644
644
|
botInline: a
|
|
645
645
|
} = r, c = new URLSearchParams();
|
|
646
|
-
return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform",
|
|
646
|
+
return t && c.set("tgWebAppData", t), c.set("tgWebAppPlatform", s), c.set("tgWebAppThemeParams", jt(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
648
|
const yt = "telegram-mini-apps-launch-params";
|
|
649
|
-
function
|
|
649
|
+
function Zt() {
|
|
650
650
|
const r = sessionStorage.getItem(yt);
|
|
651
651
|
return r ? bt().parse(r) : null;
|
|
652
652
|
}
|
|
653
|
-
function
|
|
654
|
-
sessionStorage.setItem(yt,
|
|
653
|
+
function Kt(r) {
|
|
654
|
+
sessionStorage.setItem(yt, Qt(r));
|
|
655
655
|
}
|
|
656
|
-
function
|
|
656
|
+
function Yt() {
|
|
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 Xt() {
|
|
664
|
+
const r = Zt(), t = Jt(), e = It();
|
|
665
665
|
if (r) {
|
|
666
666
|
if (t)
|
|
667
667
|
return {
|
|
668
668
|
launchParams: t,
|
|
669
|
-
isPageReload:
|
|
669
|
+
isPageReload: Yt() ? e || r.initDataRaw === t.initDataRaw : !0
|
|
670
670
|
};
|
|
671
671
|
if (e)
|
|
672
672
|
return {
|
|
@@ -687,21 +687,21 @@ function Et() {
|
|
|
687
687
|
const r = window[et];
|
|
688
688
|
if (r)
|
|
689
689
|
return r;
|
|
690
|
-
const t =
|
|
691
|
-
return window[et] = t,
|
|
690
|
+
const t = Xt();
|
|
691
|
+
return window[et] = t, Kt(t.launchParams), t;
|
|
692
692
|
}
|
|
693
|
-
function
|
|
693
|
+
function tr() {
|
|
694
694
|
try {
|
|
695
695
|
return Et(), !0;
|
|
696
696
|
} catch {
|
|
697
697
|
return !1;
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
|
-
function Xt(r) {
|
|
701
|
-
return "external" in r && D(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
702
|
-
}
|
|
703
700
|
function te(r) {
|
|
704
|
-
return "
|
|
701
|
+
return "external" in r && O(r.external) && "notify" in r.external && typeof r.external.notify == "function";
|
|
702
|
+
}
|
|
703
|
+
function ee(r) {
|
|
704
|
+
return "TelegramWebviewProxy" in r && O(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
|
|
705
705
|
}
|
|
706
706
|
function Ct() {
|
|
707
707
|
try {
|
|
@@ -716,8 +716,8 @@ class K extends Error {
|
|
|
716
716
|
}
|
|
717
717
|
}
|
|
718
718
|
class Y extends Error {
|
|
719
|
-
constructor(t, e,
|
|
720
|
-
super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${
|
|
719
|
+
constructor(t, e, s) {
|
|
720
|
+
super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, Y.prototype);
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
723
|
class vt {
|
|
@@ -732,14 +732,14 @@ class vt {
|
|
|
732
732
|
print(t, ...e) {
|
|
733
733
|
if (!this.enabled)
|
|
734
734
|
return;
|
|
735
|
-
const
|
|
735
|
+
const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
|
|
736
736
|
hour: "2-digit",
|
|
737
737
|
minute: "2-digit",
|
|
738
738
|
second: "2-digit",
|
|
739
739
|
fractionalSecondDigits: 3,
|
|
740
740
|
timeZone: "UTC"
|
|
741
|
-
}).format(
|
|
742
|
-
console[t](`[${
|
|
741
|
+
}).format(s);
|
|
742
|
+
console[t](`[${n}]`, this.prefix, ...e);
|
|
743
743
|
}
|
|
744
744
|
/**
|
|
745
745
|
* Disables the logger.
|
|
@@ -777,20 +777,20 @@ class vt {
|
|
|
777
777
|
}
|
|
778
778
|
let kt = "https://web.telegram.org";
|
|
779
779
|
const P = new vt("[SDK]", !1);
|
|
780
|
-
function
|
|
780
|
+
function er(r) {
|
|
781
781
|
if (r) {
|
|
782
782
|
P.enable();
|
|
783
783
|
return;
|
|
784
784
|
}
|
|
785
785
|
P.disable();
|
|
786
786
|
}
|
|
787
|
-
function
|
|
787
|
+
function rr(r) {
|
|
788
788
|
kt = r;
|
|
789
789
|
}
|
|
790
|
-
function
|
|
790
|
+
function re() {
|
|
791
791
|
return kt;
|
|
792
792
|
}
|
|
793
|
-
const
|
|
793
|
+
const se = g({
|
|
794
794
|
eventType: h(),
|
|
795
795
|
eventData: (r) => r
|
|
796
796
|
});
|
|
@@ -799,7 +799,7 @@ function ne(r, t) {
|
|
|
799
799
|
data: JSON.stringify({ eventType: r, eventData: t })
|
|
800
800
|
}));
|
|
801
801
|
}
|
|
802
|
-
function
|
|
802
|
+
function ie() {
|
|
803
803
|
const r = window;
|
|
804
804
|
"TelegramGameProxy_receiveEvent" in r || [
|
|
805
805
|
["TelegramGameProxy_receiveEvent"],
|
|
@@ -810,78 +810,78 @@ function se() {
|
|
|
810
810
|
// Android and iOS.
|
|
811
811
|
].forEach((t) => {
|
|
812
812
|
let e = r;
|
|
813
|
-
t.forEach((
|
|
814
|
-
if (
|
|
815
|
-
e[
|
|
813
|
+
t.forEach((s, n, i) => {
|
|
814
|
+
if (n === i.length - 1) {
|
|
815
|
+
e[s] = ne;
|
|
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 oe(r) {
|
|
823
|
+
ie(), window.addEventListener("message", (t) => {
|
|
824
824
|
try {
|
|
825
|
-
const { eventType: e, eventData:
|
|
826
|
-
r(e,
|
|
825
|
+
const { eventType: e, eventData: s } = se.parse(t.data);
|
|
826
|
+
r(e, s);
|
|
827
827
|
} catch {
|
|
828
828
|
}
|
|
829
829
|
});
|
|
830
830
|
}
|
|
831
|
-
function
|
|
831
|
+
function ae() {
|
|
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 ce() {
|
|
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 he() {
|
|
845
845
|
return g({
|
|
846
846
|
slug: h(),
|
|
847
847
|
status: h()
|
|
848
848
|
});
|
|
849
849
|
}
|
|
850
|
-
function
|
|
850
|
+
function ue() {
|
|
851
851
|
return g({ status: h() });
|
|
852
852
|
}
|
|
853
|
-
function
|
|
853
|
+
function pe() {
|
|
854
854
|
return g({
|
|
855
855
|
button_id: (r) => r == null ? void 0 : h().parse(r)
|
|
856
856
|
});
|
|
857
857
|
}
|
|
858
|
-
function
|
|
858
|
+
function le() {
|
|
859
859
|
return g({
|
|
860
860
|
data: h().optional()
|
|
861
861
|
});
|
|
862
862
|
}
|
|
863
|
-
function
|
|
863
|
+
function de() {
|
|
864
864
|
return g({
|
|
865
865
|
theme_params: (r) => {
|
|
866
866
|
const t = dt().optional();
|
|
867
|
-
return Object.entries(Z(r)).reduce((e, [
|
|
867
|
+
return Object.entries(Z(r)).reduce((e, [s, n]) => (e[s] = t.parse(n), e), {});
|
|
868
868
|
}
|
|
869
869
|
});
|
|
870
870
|
}
|
|
871
|
-
function
|
|
871
|
+
function fe() {
|
|
872
872
|
return g({
|
|
873
|
-
height:
|
|
874
|
-
width: (r) => r == null ? window.innerWidth :
|
|
875
|
-
is_state_stable:
|
|
876
|
-
is_expanded:
|
|
873
|
+
height: V(),
|
|
874
|
+
width: (r) => r == null ? window.innerWidth : V().parse(r),
|
|
875
|
+
is_state_stable: k(),
|
|
876
|
+
is_expanded: k()
|
|
877
877
|
});
|
|
878
878
|
}
|
|
879
|
-
function
|
|
879
|
+
function ge() {
|
|
880
880
|
return g({ status: h() });
|
|
881
881
|
}
|
|
882
|
-
function
|
|
883
|
-
const r = new
|
|
884
|
-
P.log("Emitting processed event:", e, ...
|
|
882
|
+
function _e() {
|
|
883
|
+
const r = new _(), t = (e, ...s) => {
|
|
884
|
+
P.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 ge() {
|
|
|
890
890
|
is_state_stable: !0,
|
|
891
891
|
is_expanded: !0
|
|
892
892
|
});
|
|
893
|
-
}),
|
|
894
|
-
P.log("Received raw event:", e,
|
|
893
|
+
}), oe((e, s) => {
|
|
894
|
+
P.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, fe().parse(s));
|
|
899
899
|
case "theme_changed":
|
|
900
|
-
return t(e,
|
|
900
|
+
return t(e, de().parse(s));
|
|
901
901
|
case "popup_closed":
|
|
902
902
|
return (
|
|
903
903
|
// Sent on desktop.
|
|
904
|
-
|
|
904
|
+
s == null ? t(e, {}) : t(e, pe().parse(s))
|
|
905
905
|
);
|
|
906
906
|
case "set_custom_style":
|
|
907
|
-
return t(e, h().parse(
|
|
907
|
+
return t(e, h().parse(s));
|
|
908
908
|
case "qr_text_received":
|
|
909
|
-
return t(e,
|
|
909
|
+
return t(e, le().parse(s));
|
|
910
910
|
case "clipboard_text_received":
|
|
911
|
-
return t(e,
|
|
911
|
+
return t(e, ae().parse(s));
|
|
912
912
|
case "invoice_closed":
|
|
913
|
-
return t(e,
|
|
913
|
+
return t(e, he().parse(s));
|
|
914
914
|
case "phone_requested":
|
|
915
|
-
return t("phone_requested",
|
|
915
|
+
return t("phone_requested", ue().parse(s));
|
|
916
916
|
case "custom_method_invoked":
|
|
917
|
-
return t("custom_method_invoked",
|
|
917
|
+
return t("custom_method_invoked", ce().parse(s));
|
|
918
918
|
case "write_access_requested":
|
|
919
|
-
return t("write_access_requested",
|
|
919
|
+
return t("write_access_requested", ge().parse(s));
|
|
920
920
|
case "main_button_pressed":
|
|
921
921
|
case "back_button_pressed":
|
|
922
922
|
case "settings_button_pressed":
|
|
@@ -924,51 +924,51 @@ function ge() {
|
|
|
924
924
|
case "reload_iframe":
|
|
925
925
|
return t(e);
|
|
926
926
|
default:
|
|
927
|
-
return t(e,
|
|
927
|
+
return t(e, s);
|
|
928
928
|
}
|
|
929
|
-
} catch (
|
|
930
|
-
P.error("Error processing event:",
|
|
929
|
+
} catch (n) {
|
|
930
|
+
P.error("Error processing event:", n);
|
|
931
931
|
}
|
|
932
932
|
}), r;
|
|
933
933
|
}
|
|
934
934
|
const z = "telegram-mini-apps-cached-emitter";
|
|
935
|
-
function
|
|
935
|
+
function W() {
|
|
936
936
|
const r = window;
|
|
937
|
-
return r[z] === void 0 && (r[z] =
|
|
937
|
+
return r[z] === void 0 && (r[z] = _e()), r[z];
|
|
938
938
|
}
|
|
939
|
-
function
|
|
940
|
-
|
|
939
|
+
function $(r, t) {
|
|
940
|
+
W().off(r, t);
|
|
941
941
|
}
|
|
942
|
-
function
|
|
943
|
-
return
|
|
942
|
+
function m(r, t) {
|
|
943
|
+
return W().on(r, t), () => $(r, t);
|
|
944
944
|
}
|
|
945
|
-
function
|
|
946
|
-
return
|
|
945
|
+
function sr(r, t) {
|
|
946
|
+
return W().once(r, t), () => $(r, t);
|
|
947
947
|
}
|
|
948
948
|
function we(r) {
|
|
949
|
-
|
|
949
|
+
W().unsubscribe(r);
|
|
950
950
|
}
|
|
951
|
-
function
|
|
952
|
-
return
|
|
951
|
+
function nr(r) {
|
|
952
|
+
return W().subscribe(r), () => we(r);
|
|
953
953
|
}
|
|
954
|
-
function
|
|
955
|
-
const e = r.split("."),
|
|
956
|
-
for (let i = 0; i <
|
|
957
|
-
const a = parseInt(e[i] || "0", 10), c = parseInt(
|
|
954
|
+
function be(r, t) {
|
|
955
|
+
const e = r.split("."), s = t.split("."), n = Math.max(e.length, s.length);
|
|
956
|
+
for (let i = 0; i < n; i += 1) {
|
|
957
|
+
const a = parseInt(e[i] || "0", 10), c = parseInt(s[i] || "0", 10);
|
|
958
958
|
if (a !== c)
|
|
959
959
|
return a > c ? 1 : -1;
|
|
960
960
|
}
|
|
961
961
|
return 0;
|
|
962
962
|
}
|
|
963
|
-
function
|
|
964
|
-
return
|
|
963
|
+
function v(r, t) {
|
|
964
|
+
return be(r, t) <= 0;
|
|
965
965
|
}
|
|
966
|
-
function
|
|
966
|
+
function A(r, t, e) {
|
|
967
967
|
if (typeof e == "string") {
|
|
968
968
|
if (r === "web_app_open_link" && t === "try_instant_view")
|
|
969
|
-
return
|
|
969
|
+
return v("6.4", e);
|
|
970
970
|
if (r === "web_app_set_header_color" && t === "color")
|
|
971
|
-
return
|
|
971
|
+
return v("6.9", e);
|
|
972
972
|
}
|
|
973
973
|
switch (r) {
|
|
974
974
|
case "web_app_open_tg_link":
|
|
@@ -977,65 +977,65 @@ function q(r, t, e) {
|
|
|
977
977
|
case "web_app_set_background_color":
|
|
978
978
|
case "web_app_set_header_color":
|
|
979
979
|
case "web_app_trigger_haptic_feedback":
|
|
980
|
-
return
|
|
980
|
+
return v("6.1", t);
|
|
981
981
|
case "web_app_open_popup":
|
|
982
|
-
return
|
|
982
|
+
return v("6.2", t);
|
|
983
983
|
case "web_app_close_scan_qr_popup":
|
|
984
984
|
case "web_app_open_scan_qr_popup":
|
|
985
985
|
case "web_app_read_text_from_clipboard":
|
|
986
|
-
return
|
|
986
|
+
return v("6.4", t);
|
|
987
987
|
case "web_app_switch_inline_query":
|
|
988
|
-
return
|
|
988
|
+
return v("6.7", t);
|
|
989
989
|
case "web_app_invoke_custom_method":
|
|
990
990
|
case "web_app_request_write_access":
|
|
991
991
|
case "web_app_request_phone":
|
|
992
|
-
return
|
|
992
|
+
return v("6.9", t);
|
|
993
993
|
case "web_app_setup_settings_button":
|
|
994
|
-
return
|
|
994
|
+
return v("6.10", t);
|
|
995
995
|
default:
|
|
996
996
|
return !0;
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
|
-
function
|
|
1000
|
-
return (e) =>
|
|
999
|
+
function y(r, t) {
|
|
1000
|
+
return (e) => A(t[e], r);
|
|
1001
1001
|
}
|
|
1002
1002
|
function St(r, t) {
|
|
1003
1003
|
return (e) => {
|
|
1004
|
-
const [
|
|
1005
|
-
return
|
|
1004
|
+
const [s, n] = t[e];
|
|
1005
|
+
return A(s, n, r);
|
|
1006
1006
|
};
|
|
1007
1007
|
}
|
|
1008
1008
|
function f(r, t, e) {
|
|
1009
|
-
let
|
|
1010
|
-
t === void 0 && e === void 0 ?
|
|
1011
|
-
const { targetOrigin: i =
|
|
1012
|
-
if (P.log(`Calling method "${r}"`,
|
|
1009
|
+
let s = {}, n;
|
|
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 = re() } = s;
|
|
1012
|
+
if (P.log(`Calling method "${r}"`, n), Ct()) {
|
|
1013
1013
|
window.parent.postMessage(JSON.stringify({
|
|
1014
1014
|
eventType: r,
|
|
1015
|
-
eventData:
|
|
1015
|
+
eventData: n
|
|
1016
1016
|
}), i);
|
|
1017
1017
|
return;
|
|
1018
1018
|
}
|
|
1019
|
-
if (
|
|
1020
|
-
window.external.notify(JSON.stringify({ eventType: r, eventData:
|
|
1019
|
+
if (te(window)) {
|
|
1020
|
+
window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
|
|
1021
1021
|
return;
|
|
1022
1022
|
}
|
|
1023
|
-
if (
|
|
1024
|
-
window.TelegramWebviewProxy.postEvent(r, JSON.stringify(
|
|
1023
|
+
if (ee(window)) {
|
|
1024
|
+
window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
|
|
1025
1025
|
return;
|
|
1026
1026
|
}
|
|
1027
1027
|
throw new Error(
|
|
1028
1028
|
"Unable to determine current environment and possible way to send event."
|
|
1029
1029
|
);
|
|
1030
1030
|
}
|
|
1031
|
-
function
|
|
1031
|
+
function me(r) {
|
|
1032
1032
|
return (t, e) => {
|
|
1033
|
-
if (!
|
|
1033
|
+
if (!A(t, r))
|
|
1034
1034
|
throw new K(t, r);
|
|
1035
|
-
if (
|
|
1036
|
-
let
|
|
1037
|
-
if (t === "web_app_open_link" && "try_instant_view" in e ?
|
|
1038
|
-
throw new Y(t,
|
|
1035
|
+
if (O(e)) {
|
|
1036
|
+
let s;
|
|
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 Y(t, s, r);
|
|
1039
1039
|
}
|
|
1040
1040
|
return f(t, e);
|
|
1041
1041
|
};
|
|
@@ -1050,48 +1050,48 @@ function rt(r) {
|
|
|
1050
1050
|
setTimeout(e, r, new X(r));
|
|
1051
1051
|
});
|
|
1052
1052
|
}
|
|
1053
|
-
function
|
|
1053
|
+
function ye(r, t) {
|
|
1054
1054
|
return typeof r == "function" ? (...e) => Promise.race([
|
|
1055
1055
|
r(...e),
|
|
1056
1056
|
rt(t)
|
|
1057
1057
|
]) : Promise.race([r, rt(t)]);
|
|
1058
1058
|
}
|
|
1059
|
-
function
|
|
1060
|
-
let
|
|
1061
|
-
typeof t == "string" || Array.isArray(t) ? (a = Array.isArray(t) ? t : [t],
|
|
1062
|
-
const { postEvent: u = f, timeout:
|
|
1063
|
-
const x = a.map((
|
|
1064
|
-
typeof c == "string" && (!
|
|
1065
|
-
})),
|
|
1059
|
+
function b(r, t, e, s) {
|
|
1060
|
+
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), O(i) && typeof i.req_id == "string" && (c = i.req_id);
|
|
1062
|
+
const { postEvent: u = f, timeout: d } = n || {}, p = n && "capture" in n ? n.capture : null, E = new Promise((l, C) => {
|
|
1063
|
+
const x = a.map((B) => m(B, (M) => {
|
|
1064
|
+
typeof c == "string" && (!O(M) || M.req_id !== c) || typeof p == "function" && !p(M) || (R(), l(M));
|
|
1065
|
+
})), R = () => x.forEach((B) => B());
|
|
1066
1066
|
try {
|
|
1067
1067
|
u(r, i);
|
|
1068
|
-
} catch (
|
|
1069
|
-
|
|
1068
|
+
} catch (B) {
|
|
1069
|
+
R(), C(B);
|
|
1070
1070
|
}
|
|
1071
1071
|
});
|
|
1072
|
-
return typeof
|
|
1072
|
+
return typeof d == "number" ? ye(E, d) : E;
|
|
1073
1073
|
}
|
|
1074
|
-
class
|
|
1075
|
-
constructor(t, e,
|
|
1076
|
-
o(this, "ee", new
|
|
1074
|
+
class Ee {
|
|
1075
|
+
constructor(t, e, s = f) {
|
|
1076
|
+
o(this, "ee", new _());
|
|
1077
1077
|
o(this, "state");
|
|
1078
1078
|
/**
|
|
1079
1079
|
* Adds event listener.
|
|
1080
1080
|
* @param event - event name.
|
|
1081
1081
|
* @param listener - event listener.
|
|
1082
1082
|
*/
|
|
1083
|
-
o(this, "on", (t, e) => t === "click" ?
|
|
1083
|
+
o(this, "on", (t, e) => t === "click" ? m("back_button_pressed", e) : this.ee.on(t, e));
|
|
1084
1084
|
/**
|
|
1085
1085
|
* Removes event listener.
|
|
1086
1086
|
* @param event - event name.
|
|
1087
1087
|
* @param listener - event listener.
|
|
1088
1088
|
*/
|
|
1089
|
-
o(this, "off", (t, e) => t === "click" ?
|
|
1089
|
+
o(this, "off", (t, e) => t === "click" ? $("back_button_pressed", e) : this.ee.off(t, e));
|
|
1090
1090
|
/**
|
|
1091
1091
|
* Checks if specified method is supported by current component.
|
|
1092
1092
|
*/
|
|
1093
1093
|
o(this, "supports");
|
|
1094
|
-
this.postEvent =
|
|
1094
|
+
this.postEvent = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(e, {
|
|
1095
1095
|
show: "web_app_setup_back_button",
|
|
1096
1096
|
hide: "web_app_setup_back_button"
|
|
1097
1097
|
});
|
|
@@ -1118,27 +1118,27 @@ class ye {
|
|
|
1118
1118
|
this.isVisible = !0;
|
|
1119
1119
|
}
|
|
1120
1120
|
}
|
|
1121
|
-
function
|
|
1121
|
+
function st(r, t) {
|
|
1122
1122
|
return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
|
|
1123
1123
|
}
|
|
1124
|
-
function
|
|
1124
|
+
function Ce(...r) {
|
|
1125
1125
|
return r.reduce((t, e) => {
|
|
1126
|
-
let
|
|
1127
|
-
return typeof e == "string" ?
|
|
1126
|
+
let s = "";
|
|
1127
|
+
return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? st(n, i) : n, "")), st(t, s);
|
|
1128
1128
|
}, "");
|
|
1129
1129
|
}
|
|
1130
|
-
function
|
|
1130
|
+
function ve(r) {
|
|
1131
1131
|
return typeof r == "object" && r !== null && !Array.isArray(null);
|
|
1132
1132
|
}
|
|
1133
|
-
function
|
|
1134
|
-
return r.reduce((t, e) => (
|
|
1135
|
-
const i =
|
|
1136
|
-
i.length > 0 && (t[
|
|
1133
|
+
function ir(...r) {
|
|
1134
|
+
return r.reduce((t, e) => (ve(e) && Object.entries(e).forEach(([s, n]) => {
|
|
1135
|
+
const i = Ce(t[s], n);
|
|
1136
|
+
i.length > 0 && (t[s] = i);
|
|
1137
1137
|
}), t), {});
|
|
1138
1138
|
}
|
|
1139
|
-
class
|
|
1139
|
+
class ke {
|
|
1140
1140
|
constructor(t, e = f) {
|
|
1141
|
-
o(this, "ee", new
|
|
1141
|
+
o(this, "ee", new _());
|
|
1142
1142
|
o(this, "state");
|
|
1143
1143
|
/**
|
|
1144
1144
|
* Adds new event listener.
|
|
@@ -1148,7 +1148,7 @@ class ve {
|
|
|
1148
1148
|
* Removes event listener.
|
|
1149
1149
|
*/
|
|
1150
1150
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1151
|
-
this.postEvent = e, this.state = new
|
|
1151
|
+
this.postEvent = e, this.state = new w({ isConfirmationNeeded: t }, this.ee);
|
|
1152
1152
|
}
|
|
1153
1153
|
set isConfirmationNeeded(t) {
|
|
1154
1154
|
this.state.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
|
|
@@ -1175,16 +1175,16 @@ class ve {
|
|
|
1175
1175
|
this.isConfirmationNeeded = !0;
|
|
1176
1176
|
}
|
|
1177
1177
|
}
|
|
1178
|
-
function
|
|
1179
|
-
return r.reduce((e,
|
|
1178
|
+
function nt(r, t) {
|
|
1179
|
+
return r.reduce((e, s) => (e[s] = t, e), {});
|
|
1180
1180
|
}
|
|
1181
|
-
class
|
|
1182
|
-
constructor(t, e,
|
|
1181
|
+
class Se {
|
|
1182
|
+
constructor(t, e, s = f) {
|
|
1183
1183
|
/**
|
|
1184
1184
|
* Checks if specified method is supported by current component.
|
|
1185
1185
|
*/
|
|
1186
1186
|
o(this, "supports");
|
|
1187
|
-
this.createRequestId = e, this.postEvent =
|
|
1187
|
+
this.createRequestId = e, this.postEvent = s, this.supports = y(t, {
|
|
1188
1188
|
delete: "web_app_invoke_custom_method",
|
|
1189
1189
|
get: "web_app_invoke_custom_method",
|
|
1190
1190
|
getKeys: "web_app_invoke_custom_method",
|
|
@@ -1197,16 +1197,16 @@ class ke {
|
|
|
1197
1197
|
* @param params - method parameters.
|
|
1198
1198
|
* @param options - execution options.
|
|
1199
1199
|
*/
|
|
1200
|
-
async invokeCustomMethod(t, e,
|
|
1201
|
-
const { result:
|
|
1200
|
+
async invokeCustomMethod(t, e, s = {}) {
|
|
1201
|
+
const { result: n, error: i } = await b(
|
|
1202
1202
|
"web_app_invoke_custom_method",
|
|
1203
1203
|
{ method: t, params: e, req_id: this.createRequestId() },
|
|
1204
1204
|
"custom_method_invoked",
|
|
1205
|
-
{ ...
|
|
1205
|
+
{ ...s, postEvent: this.postEvent }
|
|
1206
1206
|
);
|
|
1207
1207
|
if (i)
|
|
1208
1208
|
throw new Error(i);
|
|
1209
|
-
return
|
|
1209
|
+
return n;
|
|
1210
1210
|
}
|
|
1211
1211
|
/**
|
|
1212
1212
|
* Deletes specified key or keys from the cloud storage.
|
|
@@ -1214,8 +1214,8 @@ class ke {
|
|
|
1214
1214
|
* @param options - request execution options.
|
|
1215
1215
|
*/
|
|
1216
1216
|
async delete(t, e) {
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1217
|
+
const s = Array.isArray(t) ? t : [t];
|
|
1218
|
+
s.length !== 0 && await this.invokeCustomMethod("deleteStorageValues", { keys: s }, e);
|
|
1219
1219
|
}
|
|
1220
1220
|
/**
|
|
1221
1221
|
* Returns list of all keys presented in the cloud storage.
|
|
@@ -1223,15 +1223,15 @@ class ke {
|
|
|
1223
1223
|
*/
|
|
1224
1224
|
async getKeys(t) {
|
|
1225
1225
|
const e = await this.invokeCustomMethod("getStorageKeys", {}, t);
|
|
1226
|
-
return
|
|
1226
|
+
return Dt().of(h()).parse(e);
|
|
1227
1227
|
}
|
|
1228
1228
|
async get(t, e) {
|
|
1229
|
-
const
|
|
1230
|
-
if (
|
|
1231
|
-
return
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
), i = await this.invokeCustomMethod("getStorageValues", { keys:
|
|
1229
|
+
const s = Array.isArray(t) ? t : [t];
|
|
1230
|
+
if (s.length === 0)
|
|
1231
|
+
return nt(s, "");
|
|
1232
|
+
const n = g(
|
|
1233
|
+
nt(s, h())
|
|
1234
|
+
), i = await this.invokeCustomMethod("getStorageValues", { keys: s }, e).then((a) => n.parse(a));
|
|
1235
1235
|
return Array.isArray(t) ? i : i[t];
|
|
1236
1236
|
}
|
|
1237
1237
|
/**
|
|
@@ -1240,17 +1240,17 @@ class ke {
|
|
|
1240
1240
|
* @param value - storage value.
|
|
1241
1241
|
* @param options - request execution options.
|
|
1242
1242
|
*/
|
|
1243
|
-
async set(t, e,
|
|
1244
|
-
await this.invokeCustomMethod("saveStorageValue", { key: t, value: e },
|
|
1243
|
+
async set(t, e, s) {
|
|
1244
|
+
await this.invokeCustomMethod("saveStorageValue", { key: t, value: e }, s);
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
|
-
class
|
|
1247
|
+
class xe {
|
|
1248
1248
|
constructor(t, e = f) {
|
|
1249
1249
|
/**
|
|
1250
1250
|
* Checks if specified method is supported by current component.
|
|
1251
1251
|
*/
|
|
1252
1252
|
o(this, "supports");
|
|
1253
|
-
this.postEvent = e, this.supports =
|
|
1253
|
+
this.postEvent = e, this.supports = y(t, {
|
|
1254
1254
|
impactOccurred: "web_app_trigger_haptic_feedback",
|
|
1255
1255
|
notificationOccurred: "web_app_trigger_haptic_feedback",
|
|
1256
1256
|
selectionChanged: "web_app_trigger_haptic_feedback"
|
|
@@ -1290,37 +1290,37 @@ class Se {
|
|
|
1290
1290
|
this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
1293
|
-
function
|
|
1293
|
+
function Pe() {
|
|
1294
1294
|
const r = document.createElement("style");
|
|
1295
|
-
r.id = "telegram-custom-styles", document.head.appendChild(r),
|
|
1295
|
+
r.id = "telegram-custom-styles", document.head.appendChild(r), m("set_custom_style", (t) => {
|
|
1296
1296
|
r.innerHTML = t;
|
|
1297
1297
|
});
|
|
1298
1298
|
}
|
|
1299
1299
|
function xt(r) {
|
|
1300
1300
|
return `telegram-mini-apps-${r}`;
|
|
1301
1301
|
}
|
|
1302
|
-
function
|
|
1302
|
+
function T(r, t) {
|
|
1303
1303
|
sessionStorage.setItem(xt(r), JSON.stringify(t));
|
|
1304
1304
|
}
|
|
1305
|
-
function
|
|
1305
|
+
function I(r) {
|
|
1306
1306
|
const t = sessionStorage.getItem(xt(r));
|
|
1307
1307
|
return t ? JSON.parse(t) : null;
|
|
1308
1308
|
}
|
|
1309
|
-
function
|
|
1310
|
-
const { isVisible:
|
|
1311
|
-
return
|
|
1312
|
-
|
|
1313
|
-
}),
|
|
1309
|
+
function Ve(r, t, e) {
|
|
1310
|
+
const { isVisible: s = !1 } = r ? I("back-button") || {} : {}, n = new Ee(s, t, e);
|
|
1311
|
+
return n.on("change", () => {
|
|
1312
|
+
T("back-button", { isVisible: n.isVisible });
|
|
1313
|
+
}), n;
|
|
1314
1314
|
}
|
|
1315
1315
|
function Ae(r, t) {
|
|
1316
|
-
const { isConfirmationNeeded: e = !1 } = r ?
|
|
1317
|
-
return
|
|
1318
|
-
isConfirmationNeeded:
|
|
1319
|
-
})),
|
|
1316
|
+
const { isConfirmationNeeded: e = !1 } = r ? I("closing-behavior") || {} : {}, s = new ke(e, t);
|
|
1317
|
+
return s.on("change", () => T("closing-behavior", {
|
|
1318
|
+
isConfirmationNeeded: s.isConfirmationNeeded
|
|
1319
|
+
})), s;
|
|
1320
1320
|
}
|
|
1321
1321
|
class qe {
|
|
1322
1322
|
constructor(t) {
|
|
1323
|
-
o(this, "ee", new
|
|
1323
|
+
o(this, "ee", new _());
|
|
1324
1324
|
o(this, "state");
|
|
1325
1325
|
o(this, "postEvent");
|
|
1326
1326
|
/**
|
|
@@ -1332,30 +1332,30 @@ class qe {
|
|
|
1332
1332
|
// FIXME: Event 'main_button_pressed' is still being received on Android
|
|
1333
1333
|
// even if the main button is disabled.
|
|
1334
1334
|
// Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
|
|
1335
|
-
t === "click" ?
|
|
1335
|
+
t === "click" ? m("main_button_pressed", e) : this.ee.on(t, e)
|
|
1336
1336
|
));
|
|
1337
1337
|
/**
|
|
1338
1338
|
* Removes event listener.
|
|
1339
1339
|
* @param event - event name.
|
|
1340
1340
|
* @param listener - event listener.
|
|
1341
1341
|
*/
|
|
1342
|
-
o(this, "off", (t, e) => t === "click" ?
|
|
1342
|
+
o(this, "off", (t, e) => t === "click" ? $("main_button_pressed", e) : this.ee.off(t, e));
|
|
1343
1343
|
const {
|
|
1344
1344
|
postEvent: e = f,
|
|
1345
|
-
text:
|
|
1346
|
-
textColor:
|
|
1345
|
+
text: s,
|
|
1346
|
+
textColor: n,
|
|
1347
1347
|
backgroundColor: i,
|
|
1348
1348
|
isEnabled: a,
|
|
1349
1349
|
isVisible: c,
|
|
1350
1350
|
isLoaderVisible: u
|
|
1351
1351
|
} = t;
|
|
1352
|
-
this.postEvent = e, this.state = new
|
|
1352
|
+
this.postEvent = e, this.state = new w({
|
|
1353
1353
|
backgroundColor: i,
|
|
1354
1354
|
isEnabled: a,
|
|
1355
1355
|
isVisible: c,
|
|
1356
1356
|
isLoaderVisible: u,
|
|
1357
|
-
text:
|
|
1358
|
-
textColor:
|
|
1357
|
+
text: s,
|
|
1358
|
+
textColor: n
|
|
1359
1359
|
}, this.ee);
|
|
1360
1360
|
}
|
|
1361
1361
|
/**
|
|
@@ -1483,23 +1483,23 @@ class qe {
|
|
|
1483
1483
|
return this.state.set(t), this.commit(), this;
|
|
1484
1484
|
}
|
|
1485
1485
|
}
|
|
1486
|
-
function Le(r, t, e,
|
|
1486
|
+
function Le(r, t, e, s) {
|
|
1487
1487
|
const {
|
|
1488
|
-
backgroundColor:
|
|
1488
|
+
backgroundColor: n = t,
|
|
1489
1489
|
isEnabled: i = !1,
|
|
1490
1490
|
isVisible: a = !1,
|
|
1491
1491
|
isLoaderVisible: c = !1,
|
|
1492
1492
|
textColor: u = e,
|
|
1493
|
-
text:
|
|
1494
|
-
} = r ?
|
|
1495
|
-
backgroundColor:
|
|
1493
|
+
text: d = ""
|
|
1494
|
+
} = r ? I("main-button") || {} : {}, p = new qe({
|
|
1495
|
+
backgroundColor: n,
|
|
1496
1496
|
isEnabled: i,
|
|
1497
1497
|
isLoaderVisible: c,
|
|
1498
1498
|
isVisible: a,
|
|
1499
|
-
postEvent:
|
|
1500
|
-
text:
|
|
1499
|
+
postEvent: s,
|
|
1500
|
+
text: d,
|
|
1501
1501
|
textColor: u
|
|
1502
|
-
}),
|
|
1502
|
+
}), E = () => T("main-button", {
|
|
1503
1503
|
backgroundColor: p.backgroundColor,
|
|
1504
1504
|
isEnabled: p.isEnabled,
|
|
1505
1505
|
isLoaderVisible: p.isLoaderVisible,
|
|
@@ -1507,11 +1507,11 @@ function Le(r, t, e, n) {
|
|
|
1507
1507
|
text: p.text,
|
|
1508
1508
|
textColor: p.textColor
|
|
1509
1509
|
});
|
|
1510
|
-
return p.on("change",
|
|
1510
|
+
return p.on("change", E), p;
|
|
1511
1511
|
}
|
|
1512
1512
|
class $e {
|
|
1513
1513
|
constructor(t) {
|
|
1514
|
-
o(this, "ee", new
|
|
1514
|
+
o(this, "ee", new _());
|
|
1515
1515
|
o(this, "state");
|
|
1516
1516
|
o(this, "botInline");
|
|
1517
1517
|
o(this, "postEvent");
|
|
@@ -1533,18 +1533,18 @@ class $e {
|
|
|
1533
1533
|
o(this, "supportsParam");
|
|
1534
1534
|
const {
|
|
1535
1535
|
postEvent: e = f,
|
|
1536
|
-
headerColor:
|
|
1537
|
-
backgroundColor:
|
|
1536
|
+
headerColor: s,
|
|
1537
|
+
backgroundColor: n,
|
|
1538
1538
|
version: i,
|
|
1539
1539
|
botInline: a
|
|
1540
|
-
} = t, c =
|
|
1540
|
+
} = t, c = y(i, {
|
|
1541
1541
|
requestPhoneAccess: "web_app_request_phone",
|
|
1542
1542
|
requestWriteAccess: "web_app_request_write_access",
|
|
1543
1543
|
switchInlineQuery: "web_app_switch_inline_query",
|
|
1544
1544
|
setHeaderColor: "web_app_set_header_color",
|
|
1545
1545
|
setBackgroundColor: "web_app_set_background_color"
|
|
1546
1546
|
});
|
|
1547
|
-
this.postEvent = e, this.botInline = a, this.supports = (u) => !(!c(u) || u === "switchInlineQuery" && !a), this.state = new
|
|
1547
|
+
this.postEvent = e, this.botInline = a, this.supports = (u) => !(!c(u) || u === "switchInlineQuery" && !a), this.state = new w({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = St(i, {
|
|
1548
1548
|
"setHeaderColor.color": ["web_app_set_header_color", "color"]
|
|
1549
1549
|
});
|
|
1550
1550
|
}
|
|
@@ -1594,7 +1594,7 @@ class $e {
|
|
|
1594
1594
|
* Requests current user phone access.
|
|
1595
1595
|
*/
|
|
1596
1596
|
requestPhoneAccess() {
|
|
1597
|
-
return
|
|
1597
|
+
return b(
|
|
1598
1598
|
"web_app_request_phone",
|
|
1599
1599
|
"phone_requested",
|
|
1600
1600
|
{ postEvent: this.postEvent }
|
|
@@ -1604,7 +1604,7 @@ class $e {
|
|
|
1604
1604
|
* Requests write message access to current user.
|
|
1605
1605
|
*/
|
|
1606
1606
|
requestWriteAccess() {
|
|
1607
|
-
return
|
|
1607
|
+
return b(
|
|
1608
1608
|
"web_app_request_write_access",
|
|
1609
1609
|
"write_access_requested",
|
|
1610
1610
|
{ postEvent: this.postEvent }
|
|
@@ -1658,32 +1658,85 @@ class $e {
|
|
|
1658
1658
|
});
|
|
1659
1659
|
}
|
|
1660
1660
|
}
|
|
1661
|
-
function
|
|
1661
|
+
function Te(r, t, e, s, n) {
|
|
1662
1662
|
const {
|
|
1663
1663
|
backgroundColor: i = t,
|
|
1664
1664
|
headerColor: a = "bg_color"
|
|
1665
|
-
} = r ?
|
|
1665
|
+
} = r ? I("mini-app") || {} : {}, c = new $e({
|
|
1666
1666
|
headerColor: a,
|
|
1667
1667
|
backgroundColor: i,
|
|
1668
1668
|
version: e,
|
|
1669
|
-
botInline:
|
|
1670
|
-
postEvent:
|
|
1671
|
-
}), u = () =>
|
|
1669
|
+
botInline: s,
|
|
1670
|
+
postEvent: n
|
|
1671
|
+
}), u = () => T("mini-app", {
|
|
1672
1672
|
backgroundColor: c.backgroundColor,
|
|
1673
1673
|
headerColor: c.headerColor
|
|
1674
1674
|
});
|
|
1675
1675
|
return c.on("change", u), c;
|
|
1676
1676
|
}
|
|
1677
|
-
function
|
|
1677
|
+
function Ie() {
|
|
1678
1678
|
let r = 0;
|
|
1679
1679
|
return () => (r += 1, r.toString());
|
|
1680
1680
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1681
|
+
class Re {
|
|
1682
|
+
constructor(t, e, s = f) {
|
|
1683
|
+
o(this, "ee", new _());
|
|
1684
|
+
o(this, "state");
|
|
1685
|
+
/**
|
|
1686
|
+
* Adds event listener.
|
|
1687
|
+
* @param event - event name.
|
|
1688
|
+
* @param listener - event listener.
|
|
1689
|
+
*/
|
|
1690
|
+
o(this, "on", (t, e) => t === "click" ? m("settings_button_pressed", e) : this.ee.on(t, e));
|
|
1691
|
+
/**
|
|
1692
|
+
* Removes event listener.
|
|
1693
|
+
* @param event - event name.
|
|
1694
|
+
* @param listener - event listener.
|
|
1695
|
+
*/
|
|
1696
|
+
o(this, "off", (t, e) => t === "click" ? $("settings_button_pressed", e) : this.ee.off(t, e));
|
|
1697
|
+
/**
|
|
1698
|
+
* Checks if specified method is supported by current component.
|
|
1699
|
+
*/
|
|
1700
|
+
o(this, "supports");
|
|
1701
|
+
this.postEvent = s, this.state = new w({ isVisible: t }, this.ee), this.supports = y(e, {
|
|
1702
|
+
show: "web_app_setup_settings_button",
|
|
1703
|
+
hide: "web_app_setup_settings_button"
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
set isVisible(t) {
|
|
1707
|
+
this.state.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* True if SettingsButton is currently visible.
|
|
1711
|
+
*/
|
|
1712
|
+
get isVisible() {
|
|
1713
|
+
return this.state.get("isVisible");
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Hides the SettingsButton.
|
|
1717
|
+
*/
|
|
1718
|
+
hide() {
|
|
1719
|
+
this.isVisible = !1;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Shows the SettingsButton.
|
|
1723
|
+
*/
|
|
1724
|
+
show() {
|
|
1725
|
+
this.isVisible = !0;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function Be(r, t, e) {
|
|
1729
|
+
const { isVisible: s = !1 } = r ? I("settings-button") || {} : {}, n = new Re(s, t, e);
|
|
1730
|
+
return n.on("change", () => {
|
|
1731
|
+
T("settings-button", { isVisible: n.isVisible });
|
|
1732
|
+
}), n;
|
|
1733
|
+
}
|
|
1734
|
+
function De(r) {
|
|
1735
|
+
const t = new Gt(r);
|
|
1683
1736
|
return t.listen(), t;
|
|
1684
1737
|
}
|
|
1685
1738
|
async function Pt(r) {
|
|
1686
|
-
const t = await
|
|
1739
|
+
const t = await b("web_app_request_viewport", "viewport_changed", r);
|
|
1687
1740
|
return {
|
|
1688
1741
|
height: t.height,
|
|
1689
1742
|
width: t.width,
|
|
@@ -1691,12 +1744,12 @@ async function Pt(r) {
|
|
|
1691
1744
|
isStateStable: t.is_state_stable
|
|
1692
1745
|
};
|
|
1693
1746
|
}
|
|
1694
|
-
function
|
|
1747
|
+
function D(r) {
|
|
1695
1748
|
return r < 0 ? 0 : r;
|
|
1696
1749
|
}
|
|
1697
1750
|
class j {
|
|
1698
1751
|
constructor(t) {
|
|
1699
|
-
o(this, "ee", new
|
|
1752
|
+
o(this, "ee", new _());
|
|
1700
1753
|
o(this, "state");
|
|
1701
1754
|
o(this, "postEvent");
|
|
1702
1755
|
/**
|
|
@@ -1709,16 +1762,16 @@ class j {
|
|
|
1709
1762
|
o(this, "off", this.ee.off.bind(this.ee));
|
|
1710
1763
|
const {
|
|
1711
1764
|
height: e,
|
|
1712
|
-
isExpanded:
|
|
1713
|
-
width:
|
|
1765
|
+
isExpanded: s,
|
|
1766
|
+
width: n,
|
|
1714
1767
|
stableHeight: i,
|
|
1715
1768
|
postEvent: a = f
|
|
1716
1769
|
} = t;
|
|
1717
|
-
this.postEvent = a, this.state = new
|
|
1718
|
-
height:
|
|
1719
|
-
isExpanded:
|
|
1720
|
-
stableHeight:
|
|
1721
|
-
width:
|
|
1770
|
+
this.postEvent = a, this.state = new w({
|
|
1771
|
+
height: D(e),
|
|
1772
|
+
isExpanded: s,
|
|
1773
|
+
stableHeight: D(i),
|
|
1774
|
+
width: D(n)
|
|
1722
1775
|
}, this.ee);
|
|
1723
1776
|
}
|
|
1724
1777
|
/**
|
|
@@ -1727,11 +1780,11 @@ class j {
|
|
|
1727
1780
|
* @param options - options to request fresh data.
|
|
1728
1781
|
*/
|
|
1729
1782
|
sync(t) {
|
|
1730
|
-
return Pt(t).then(({ height: e, isExpanded:
|
|
1783
|
+
return Pt(t).then(({ height: e, isExpanded: s, width: n, isStateStable: i }) => {
|
|
1731
1784
|
this.state.set({
|
|
1732
1785
|
height: e,
|
|
1733
|
-
width:
|
|
1734
|
-
isExpanded:
|
|
1786
|
+
width: n,
|
|
1787
|
+
isExpanded: s,
|
|
1735
1788
|
stableHeight: i ? e : this.state.get("stableHeight")
|
|
1736
1789
|
});
|
|
1737
1790
|
});
|
|
@@ -1777,16 +1830,16 @@ class j {
|
|
|
1777
1830
|
* @returns Function to stop listening.
|
|
1778
1831
|
*/
|
|
1779
1832
|
listen() {
|
|
1780
|
-
return
|
|
1833
|
+
return m("viewport_changed", (t) => {
|
|
1781
1834
|
const {
|
|
1782
1835
|
height: e,
|
|
1783
|
-
width:
|
|
1784
|
-
is_expanded:
|
|
1836
|
+
width: s,
|
|
1837
|
+
is_expanded: n,
|
|
1785
1838
|
is_state_stable: i
|
|
1786
1839
|
} = t, a = {
|
|
1787
|
-
height:
|
|
1788
|
-
isExpanded:
|
|
1789
|
-
width:
|
|
1840
|
+
height: D(e),
|
|
1841
|
+
isExpanded: n,
|
|
1842
|
+
width: D(s)
|
|
1790
1843
|
};
|
|
1791
1844
|
i && (a.stableHeight = a.height), this.state.set(a);
|
|
1792
1845
|
});
|
|
@@ -1823,8 +1876,11 @@ class j {
|
|
|
1823
1876
|
return this.stableHeight === this.height;
|
|
1824
1877
|
}
|
|
1825
1878
|
}
|
|
1879
|
+
function Vt(r) {
|
|
1880
|
+
return !["macos", "web", "weba"].includes(r);
|
|
1881
|
+
}
|
|
1826
1882
|
function At(r, t, e) {
|
|
1827
|
-
if (r || t
|
|
1883
|
+
if (r || !Vt(t))
|
|
1828
1884
|
return new j({
|
|
1829
1885
|
height: window.innerHeight,
|
|
1830
1886
|
isExpanded: !0,
|
|
@@ -1832,19 +1888,19 @@ function At(r, t, e) {
|
|
|
1832
1888
|
stableHeight: window.innerHeight,
|
|
1833
1889
|
width: window.innerWidth
|
|
1834
1890
|
});
|
|
1835
|
-
const
|
|
1836
|
-
return
|
|
1891
|
+
const s = I("viewport");
|
|
1892
|
+
return s ? new j({ ...s, postEvent: e }) : null;
|
|
1837
1893
|
}
|
|
1838
1894
|
function qt(r) {
|
|
1839
|
-
return r.listen(), r.on("change", () =>
|
|
1895
|
+
return r.listen(), r.on("change", () => T("viewport", {
|
|
1840
1896
|
height: r.height,
|
|
1841
1897
|
isExpanded: r.isExpanded,
|
|
1842
1898
|
stableHeight: r.stableHeight,
|
|
1843
1899
|
width: r.width
|
|
1844
1900
|
})), r;
|
|
1845
1901
|
}
|
|
1846
|
-
function
|
|
1847
|
-
const
|
|
1902
|
+
function He(r, t, e) {
|
|
1903
|
+
const s = qt(
|
|
1848
1904
|
At(r, t, e) || new j({
|
|
1849
1905
|
width: 0,
|
|
1850
1906
|
height: 0,
|
|
@@ -1853,73 +1909,73 @@ function Re(r, t, e) {
|
|
|
1853
1909
|
stableHeight: 0
|
|
1854
1910
|
})
|
|
1855
1911
|
);
|
|
1856
|
-
return
|
|
1857
|
-
console.error("Unable to actualize viewport state",
|
|
1858
|
-
}),
|
|
1912
|
+
return Vt(t) && s.sync({ postEvent: e, timeout: 100 }).catch((n) => {
|
|
1913
|
+
console.error("Unable to actualize viewport state", n);
|
|
1914
|
+
}), s;
|
|
1859
1915
|
}
|
|
1860
|
-
async function
|
|
1916
|
+
async function Ne(r, t, e) {
|
|
1861
1917
|
return qt(
|
|
1862
|
-
At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height:
|
|
1918
|
+
At(r, t, e) || await Pt({ postEvent: e, timeout: 100 }).then(({ height: s, isStateStable: n, ...i }) => new j({
|
|
1863
1919
|
...i,
|
|
1864
|
-
height:
|
|
1865
|
-
stableHeight:
|
|
1920
|
+
height: s,
|
|
1921
|
+
stableHeight: n ? s : 0
|
|
1866
1922
|
}))
|
|
1867
1923
|
);
|
|
1868
1924
|
}
|
|
1869
|
-
function
|
|
1925
|
+
function S(r, t) {
|
|
1870
1926
|
document.documentElement.style.setProperty(r, t);
|
|
1871
1927
|
}
|
|
1872
|
-
function
|
|
1928
|
+
function Oe(r, t) {
|
|
1873
1929
|
const e = () => {
|
|
1874
|
-
|
|
1875
|
-
},
|
|
1930
|
+
S("--tg-background-color", r.backgroundColor);
|
|
1931
|
+
}, s = () => {
|
|
1876
1932
|
const {
|
|
1877
|
-
backgroundColor:
|
|
1933
|
+
backgroundColor: n,
|
|
1878
1934
|
secondaryBackgroundColor: i
|
|
1879
1935
|
} = t;
|
|
1880
|
-
r.headerColor === "bg_color" ?
|
|
1936
|
+
r.headerColor === "bg_color" ? n && S("--tg-header-color", n) : r.headerColor === "secondary_bg_color" ? i && S("--tg-header-color", i) : S("--tg-header-color", r.headerColor);
|
|
1881
1937
|
};
|
|
1882
|
-
t.on("change",
|
|
1938
|
+
t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
|
|
1883
1939
|
}
|
|
1884
|
-
function
|
|
1940
|
+
function We(r) {
|
|
1885
1941
|
const t = () => {
|
|
1886
1942
|
const e = r.getState();
|
|
1887
|
-
Object.entries(e).forEach(([
|
|
1888
|
-
if (
|
|
1889
|
-
const i =
|
|
1890
|
-
|
|
1943
|
+
Object.entries(e).forEach(([s, n]) => {
|
|
1944
|
+
if (n) {
|
|
1945
|
+
const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
|
|
1946
|
+
S(`--tg-theme-${i}`, n);
|
|
1891
1947
|
}
|
|
1892
1948
|
});
|
|
1893
1949
|
};
|
|
1894
1950
|
r.on("change", t), t();
|
|
1895
1951
|
}
|
|
1896
1952
|
function it(r) {
|
|
1897
|
-
const t = () =>
|
|
1898
|
-
r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight",
|
|
1953
|
+
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
|
+
r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
|
|
1899
1955
|
}
|
|
1900
|
-
function
|
|
1956
|
+
function Me(r) {
|
|
1901
1957
|
return typeof r == "object" ? r : r ? {
|
|
1902
1958
|
themeParams: !0,
|
|
1903
1959
|
viewport: !0,
|
|
1904
1960
|
miniApp: !0
|
|
1905
1961
|
} : {};
|
|
1906
1962
|
}
|
|
1907
|
-
function ot(r, t, e,
|
|
1908
|
-
const
|
|
1909
|
-
|
|
1963
|
+
function ot(r, t, e, s) {
|
|
1964
|
+
const n = Me(r);
|
|
1965
|
+
n.miniApp && Oe(t, e), n.themeParams && We(e), n.viewport && (s instanceof Promise ? s.then(it) : it(s));
|
|
1910
1966
|
}
|
|
1911
|
-
function
|
|
1967
|
+
function Ue(r) {
|
|
1912
1968
|
const { hostname: t, pathname: e } = new URL(r, window.location.href);
|
|
1913
1969
|
if (t !== "t.me")
|
|
1914
1970
|
throw new Error(`Incorrect hostname: ${t}`);
|
|
1915
|
-
const
|
|
1916
|
-
if (
|
|
1971
|
+
const s = e.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
1972
|
+
if (s === null)
|
|
1917
1973
|
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
|
|
1918
|
-
return
|
|
1974
|
+
return s[2];
|
|
1919
1975
|
}
|
|
1920
|
-
class
|
|
1976
|
+
class je {
|
|
1921
1977
|
constructor(t, e = f) {
|
|
1922
|
-
o(this, "ee", new
|
|
1978
|
+
o(this, "ee", new _());
|
|
1923
1979
|
o(this, "state");
|
|
1924
1980
|
/**
|
|
1925
1981
|
* Adds new event listener.
|
|
@@ -1933,7 +1989,7 @@ class We {
|
|
|
1933
1989
|
* Checks if specified method is supported by current component.
|
|
1934
1990
|
*/
|
|
1935
1991
|
o(this, "supports");
|
|
1936
|
-
this.postEvent = e, this.state = new
|
|
1992
|
+
this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_invoice" });
|
|
1937
1993
|
}
|
|
1938
1994
|
set isOpened(t) {
|
|
1939
1995
|
this.state.set("isOpened", t);
|
|
@@ -1947,17 +2003,17 @@ class We {
|
|
|
1947
2003
|
async open(t, e) {
|
|
1948
2004
|
if (this.isOpened)
|
|
1949
2005
|
throw new Error("Invoice is already opened");
|
|
1950
|
-
const
|
|
2006
|
+
const s = e ? Ue(t) : t;
|
|
1951
2007
|
this.isOpened = !0;
|
|
1952
2008
|
try {
|
|
1953
|
-
return (await
|
|
2009
|
+
return (await b(
|
|
1954
2010
|
"web_app_open_invoice",
|
|
1955
|
-
{ slug:
|
|
2011
|
+
{ slug: s },
|
|
1956
2012
|
"invoice_closed",
|
|
1957
2013
|
{
|
|
1958
2014
|
postEvent: this.postEvent,
|
|
1959
2015
|
capture(i) {
|
|
1960
|
-
return
|
|
2016
|
+
return s === i.slug;
|
|
1961
2017
|
}
|
|
1962
2018
|
}
|
|
1963
2019
|
)).status;
|
|
@@ -1966,16 +2022,16 @@ class We {
|
|
|
1966
2022
|
}
|
|
1967
2023
|
}
|
|
1968
2024
|
}
|
|
1969
|
-
function
|
|
1970
|
-
const t = r.message.trim(), e = (r.title || "").trim(),
|
|
1971
|
-
let
|
|
2025
|
+
function Ge(r) {
|
|
2026
|
+
const t = r.message.trim(), e = (r.title || "").trim(), s = r.buttons || [];
|
|
2027
|
+
let n;
|
|
1972
2028
|
if (e.length > 64)
|
|
1973
2029
|
throw new Error(`Title has incorrect size: ${e.length}`);
|
|
1974
2030
|
if (t.length === 0 || t.length > 256)
|
|
1975
2031
|
throw new Error(`Message has incorrect size: ${t.length}`);
|
|
1976
|
-
if (
|
|
1977
|
-
throw new Error(`Buttons have incorrect size: ${
|
|
1978
|
-
return
|
|
2032
|
+
if (s.length > 3)
|
|
2033
|
+
throw new Error(`Buttons have incorrect size: ${s.length}`);
|
|
2034
|
+
return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
|
|
1979
2035
|
const { id: a = "" } = i;
|
|
1980
2036
|
if (a.length > 64)
|
|
1981
2037
|
throw new Error(`Button ID has incorrect size: ${a}`);
|
|
@@ -1988,11 +2044,11 @@ function Me(r) {
|
|
|
1988
2044
|
return { ...i, text: c, id: a };
|
|
1989
2045
|
}
|
|
1990
2046
|
return { ...i, id: a };
|
|
1991
|
-
}), { title: e, message: t, buttons:
|
|
2047
|
+
}), { title: e, message: t, buttons: n };
|
|
1992
2048
|
}
|
|
1993
|
-
class
|
|
2049
|
+
class Fe {
|
|
1994
2050
|
constructor(t, e = f) {
|
|
1995
|
-
o(this, "ee", new
|
|
2051
|
+
o(this, "ee", new _());
|
|
1996
2052
|
o(this, "state");
|
|
1997
2053
|
/**
|
|
1998
2054
|
* Adds new event listener.
|
|
@@ -2006,7 +2062,7 @@ class Ue {
|
|
|
2006
2062
|
* Checks if specified method is supported by current component.
|
|
2007
2063
|
*/
|
|
2008
2064
|
o(this, "supports");
|
|
2009
|
-
this.postEvent = e, this.state = new
|
|
2065
|
+
this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, { open: "web_app_open_popup" });
|
|
2010
2066
|
}
|
|
2011
2067
|
set isOpened(t) {
|
|
2012
2068
|
this.state.set("isOpened", t);
|
|
@@ -2033,9 +2089,9 @@ class Ue {
|
|
|
2033
2089
|
open(t) {
|
|
2034
2090
|
if (this.isOpened)
|
|
2035
2091
|
throw new Error("Popup is already opened.");
|
|
2036
|
-
return this.isOpened = !0,
|
|
2092
|
+
return this.isOpened = !0, b(
|
|
2037
2093
|
"web_app_open_popup",
|
|
2038
|
-
|
|
2094
|
+
Ge(t),
|
|
2039
2095
|
"popup_closed",
|
|
2040
2096
|
{ postEvent: this.postEvent }
|
|
2041
2097
|
).then(({ button_id: e = null }) => e).finally(() => {
|
|
@@ -2043,9 +2099,9 @@ class Ue {
|
|
|
2043
2099
|
});
|
|
2044
2100
|
}
|
|
2045
2101
|
}
|
|
2046
|
-
class
|
|
2102
|
+
class ze {
|
|
2047
2103
|
constructor(t, e = f) {
|
|
2048
|
-
o(this, "ee", new
|
|
2104
|
+
o(this, "ee", new _());
|
|
2049
2105
|
o(this, "state");
|
|
2050
2106
|
/**
|
|
2051
2107
|
* Adds new event listener.
|
|
@@ -2059,7 +2115,7 @@ class je {
|
|
|
2059
2115
|
* Checks if specified method is supported by current component.
|
|
2060
2116
|
*/
|
|
2061
2117
|
o(this, "supports");
|
|
2062
|
-
this.postEvent = e, this.state = new
|
|
2118
|
+
this.postEvent = e, this.state = new w({ isOpened: !1 }, this.ee), this.supports = y(t, {
|
|
2063
2119
|
close: "web_app_close_scan_qr_popup",
|
|
2064
2120
|
open: "web_app_open_scan_qr_popup"
|
|
2065
2121
|
});
|
|
@@ -2090,7 +2146,7 @@ class je {
|
|
|
2090
2146
|
throw new Error("QR scanner is already opened.");
|
|
2091
2147
|
this.isOpened = !0;
|
|
2092
2148
|
try {
|
|
2093
|
-
const e = await
|
|
2149
|
+
const e = await b(
|
|
2094
2150
|
"web_app_open_scan_qr_popup",
|
|
2095
2151
|
{ text: t },
|
|
2096
2152
|
["qr_text_received", "scan_qr_popup_closed"],
|
|
@@ -2102,8 +2158,8 @@ class je {
|
|
|
2102
2158
|
}
|
|
2103
2159
|
}
|
|
2104
2160
|
}
|
|
2105
|
-
class
|
|
2106
|
-
constructor(t, e,
|
|
2161
|
+
class Je {
|
|
2162
|
+
constructor(t, e, s = f) {
|
|
2107
2163
|
/**
|
|
2108
2164
|
* Checks if specified method is supported by current component.
|
|
2109
2165
|
*/
|
|
@@ -2112,7 +2168,7 @@ class Ge {
|
|
|
2112
2168
|
* Checks if specified method parameter is supported by current component.
|
|
2113
2169
|
*/
|
|
2114
2170
|
o(this, "supportsParam");
|
|
2115
|
-
this.version = t, this.createRequestId = e, this.postEvent =
|
|
2171
|
+
this.version = t, this.createRequestId = e, this.postEvent = s, this.supports = y(t, {
|
|
2116
2172
|
readTextFromClipboard: "web_app_read_text_from_clipboard"
|
|
2117
2173
|
}), this.supportsParam = St(t, {
|
|
2118
2174
|
"openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
|
|
@@ -2128,13 +2184,13 @@ class Ge {
|
|
|
2128
2184
|
* @param tryInstantView
|
|
2129
2185
|
*/
|
|
2130
2186
|
openLink(t, e) {
|
|
2131
|
-
const
|
|
2132
|
-
if (!
|
|
2133
|
-
window.open(
|
|
2187
|
+
const s = new URL(t, window.location.href).toString();
|
|
2188
|
+
if (!A("web_app_open_link", this.version)) {
|
|
2189
|
+
window.open(s, "_blank");
|
|
2134
2190
|
return;
|
|
2135
2191
|
}
|
|
2136
2192
|
this.postEvent("web_app_open_link", {
|
|
2137
|
-
url:
|
|
2193
|
+
url: s,
|
|
2138
2194
|
...typeof e == "boolean" ? { try_instant_view: e } : {}
|
|
2139
2195
|
});
|
|
2140
2196
|
}
|
|
@@ -2147,16 +2203,16 @@ class Ge {
|
|
|
2147
2203
|
openTelegramLink(t) {
|
|
2148
2204
|
const {
|
|
2149
2205
|
hostname: e,
|
|
2150
|
-
pathname:
|
|
2151
|
-
search:
|
|
2206
|
+
pathname: s,
|
|
2207
|
+
search: n
|
|
2152
2208
|
} = new URL(t, window.location.href);
|
|
2153
2209
|
if (e !== "t.me")
|
|
2154
2210
|
throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
|
|
2155
|
-
if (!
|
|
2211
|
+
if (!A("web_app_open_tg_link", this.version)) {
|
|
2156
2212
|
window.location.href = t;
|
|
2157
2213
|
return;
|
|
2158
2214
|
}
|
|
2159
|
-
this.postEvent("web_app_open_tg_link", { path_full:
|
|
2215
|
+
this.postEvent("web_app_open_tg_link", { path_full: s + n });
|
|
2160
2216
|
}
|
|
2161
2217
|
/**
|
|
2162
2218
|
* Reads text from clipboard and returns string or null. null is returned
|
|
@@ -2165,7 +2221,7 @@ class Ge {
|
|
|
2165
2221
|
* - Access to clipboard is not allowed
|
|
2166
2222
|
*/
|
|
2167
2223
|
readTextFromClipboard() {
|
|
2168
|
-
return
|
|
2224
|
+
return b(
|
|
2169
2225
|
"web_app_read_text_from_clipboard",
|
|
2170
2226
|
{ req_id: this.createRequestId() },
|
|
2171
2227
|
"clipboard_text_received",
|
|
@@ -2173,83 +2229,84 @@ class Ge {
|
|
|
2173
2229
|
).then(({ data: t = null }) => t);
|
|
2174
2230
|
}
|
|
2175
2231
|
}
|
|
2176
|
-
function
|
|
2232
|
+
function or(r = {}) {
|
|
2177
2233
|
const {
|
|
2178
2234
|
async: t = !1,
|
|
2179
2235
|
cssVars: e = !1,
|
|
2180
|
-
acceptCustomStyles:
|
|
2236
|
+
acceptCustomStyles: s = !1
|
|
2181
2237
|
} = r;
|
|
2182
2238
|
try {
|
|
2183
2239
|
const {
|
|
2184
2240
|
launchParams: {
|
|
2185
|
-
initData:
|
|
2241
|
+
initData: n,
|
|
2186
2242
|
initDataRaw: i,
|
|
2187
2243
|
version: a,
|
|
2188
2244
|
platform: c,
|
|
2189
2245
|
themeParams: u,
|
|
2190
|
-
botInline:
|
|
2246
|
+
botInline: d = !1
|
|
2191
2247
|
},
|
|
2192
2248
|
isPageReload: p
|
|
2193
|
-
} = Et(),
|
|
2194
|
-
Ct() && (
|
|
2195
|
-
const
|
|
2196
|
-
backButton:
|
|
2197
|
-
closingBehavior: Ae(p,
|
|
2198
|
-
cloudStorage: new
|
|
2199
|
-
createRequestId:
|
|
2200
|
-
hapticFeedback: new
|
|
2201
|
-
invoice: new
|
|
2249
|
+
} = Et(), E = Ie(), l = me(a);
|
|
2250
|
+
Ct() && (s && Pe(), l("iframe_ready", { reload_supported: !0 }), m("reload_iframe", () => window.location.reload()));
|
|
2251
|
+
const C = {
|
|
2252
|
+
backButton: Ve(p, a, l),
|
|
2253
|
+
closingBehavior: Ae(p, l),
|
|
2254
|
+
cloudStorage: new Se(a, E, l),
|
|
2255
|
+
createRequestId: E,
|
|
2256
|
+
hapticFeedback: new xe(a, l),
|
|
2257
|
+
invoice: new je(a, l),
|
|
2202
2258
|
mainButton: Le(
|
|
2203
2259
|
p,
|
|
2204
2260
|
u.buttonColor || "#000000",
|
|
2205
2261
|
u.buttonTextColor || "#ffffff",
|
|
2206
|
-
|
|
2262
|
+
l
|
|
2207
2263
|
),
|
|
2208
|
-
miniApp:
|
|
2264
|
+
miniApp: Te(
|
|
2209
2265
|
p,
|
|
2210
2266
|
u.backgroundColor || "#ffffff",
|
|
2211
2267
|
a,
|
|
2212
|
-
|
|
2213
|
-
|
|
2268
|
+
d,
|
|
2269
|
+
l
|
|
2214
2270
|
),
|
|
2215
|
-
popup: new
|
|
2216
|
-
postEvent:
|
|
2217
|
-
qrScanner: new
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2271
|
+
popup: new Fe(a, l),
|
|
2272
|
+
postEvent: l,
|
|
2273
|
+
qrScanner: new ze(a, l),
|
|
2274
|
+
settingsButton: Be(p, a, l),
|
|
2275
|
+
themeParams: De(u),
|
|
2276
|
+
utils: new Je(a, E, l),
|
|
2277
|
+
...n ? {
|
|
2278
|
+
initData: new Wt(n),
|
|
2222
2279
|
initDataRaw: i
|
|
2223
2280
|
} : {}
|
|
2224
|
-
}, x = t ?
|
|
2225
|
-
return x instanceof Promise ? x.then((
|
|
2281
|
+
}, x = t ? Ne(p, c, l) : He(p, c, l);
|
|
2282
|
+
return x instanceof Promise ? x.then((R) => (ot(
|
|
2226
2283
|
e,
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2284
|
+
C.miniApp,
|
|
2285
|
+
C.themeParams,
|
|
2286
|
+
R
|
|
2230
2287
|
), {
|
|
2231
|
-
...
|
|
2232
|
-
viewport:
|
|
2288
|
+
...C,
|
|
2289
|
+
viewport: R
|
|
2233
2290
|
})) : (ot(
|
|
2234
2291
|
e,
|
|
2235
|
-
|
|
2236
|
-
|
|
2292
|
+
C.miniApp,
|
|
2293
|
+
C.themeParams,
|
|
2237
2294
|
x
|
|
2238
|
-
), { ...
|
|
2239
|
-
} catch (
|
|
2295
|
+
), { ...C, viewport: x });
|
|
2296
|
+
} catch (n) {
|
|
2240
2297
|
if (t)
|
|
2241
|
-
return Promise.reject(
|
|
2242
|
-
throw
|
|
2298
|
+
return Promise.reject(n);
|
|
2299
|
+
throw n;
|
|
2243
2300
|
}
|
|
2244
2301
|
}
|
|
2245
|
-
function
|
|
2302
|
+
function H(r, t) {
|
|
2246
2303
|
return r.startsWith(t) ? r : `${t}${r}`;
|
|
2247
2304
|
}
|
|
2248
|
-
function
|
|
2305
|
+
function ar(r) {
|
|
2249
2306
|
const t = r.match(/#(.+)/);
|
|
2250
2307
|
return t ? t[1] : null;
|
|
2251
2308
|
}
|
|
2252
|
-
async function
|
|
2309
|
+
async function N(r) {
|
|
2253
2310
|
return r === 0 ? !0 : Promise.race([
|
|
2254
2311
|
new Promise((t) => {
|
|
2255
2312
|
window.addEventListener("popstate", function e() {
|
|
@@ -2262,17 +2319,17 @@ async function B(r) {
|
|
|
2262
2319
|
})
|
|
2263
2320
|
]);
|
|
2264
2321
|
}
|
|
2265
|
-
async function
|
|
2266
|
-
if (window.history.length <= 1 || (window.history.pushState(null, ""), await
|
|
2322
|
+
async function Qe() {
|
|
2323
|
+
if (window.history.length <= 1 || (window.history.pushState(null, ""), await N(1 - window.history.length)))
|
|
2267
2324
|
return;
|
|
2268
|
-
let t = await
|
|
2325
|
+
let t = await N(-1);
|
|
2269
2326
|
for (; t; )
|
|
2270
|
-
t = await
|
|
2327
|
+
t = await N(-1);
|
|
2271
2328
|
}
|
|
2272
|
-
class
|
|
2329
|
+
class Ze {
|
|
2273
2330
|
constructor(t, e, {
|
|
2274
|
-
debug:
|
|
2275
|
-
loggerPrefix:
|
|
2331
|
+
debug: s = !1,
|
|
2332
|
+
loggerPrefix: n = "Navigator"
|
|
2276
2333
|
}) {
|
|
2277
2334
|
o(this, "logger");
|
|
2278
2335
|
o(this, "entries");
|
|
@@ -2284,11 +2341,11 @@ class ze {
|
|
|
2284
2341
|
if (!i.startsWith("/") && i.length > 0)
|
|
2285
2342
|
throw new Error('Pathname should start with "/"');
|
|
2286
2343
|
return {
|
|
2287
|
-
pathname:
|
|
2288
|
-
search: a ?
|
|
2289
|
-
hash: c ?
|
|
2344
|
+
pathname: H(i, "/"),
|
|
2345
|
+
search: a ? H(a, "?") : "",
|
|
2346
|
+
hash: c ? H(c, "#") : ""
|
|
2290
2347
|
};
|
|
2291
|
-
}), this.logger = new vt(`[${
|
|
2348
|
+
}), this.logger = new vt(`[${n}]`, s);
|
|
2292
2349
|
}
|
|
2293
2350
|
/**
|
|
2294
2351
|
* Converts entry to the navigation entry.
|
|
@@ -2304,16 +2361,16 @@ class ze {
|
|
|
2304
2361
|
search: c,
|
|
2305
2362
|
hash: u
|
|
2306
2363
|
} = t;
|
|
2307
|
-
e = a + (c ?
|
|
2364
|
+
e = a + (c ? H(c, "?") : "") + (u ? H(u, "#") : "");
|
|
2308
2365
|
}
|
|
2309
2366
|
const {
|
|
2310
|
-
pathname:
|
|
2311
|
-
search:
|
|
2367
|
+
pathname: s,
|
|
2368
|
+
search: n,
|
|
2312
2369
|
hash: i
|
|
2313
2370
|
} = new URL(e, `https://localhost${this.path}`);
|
|
2314
2371
|
return {
|
|
2315
|
-
pathname:
|
|
2316
|
-
search:
|
|
2372
|
+
pathname: s,
|
|
2373
|
+
search: n,
|
|
2317
2374
|
hash: i
|
|
2318
2375
|
};
|
|
2319
2376
|
}
|
|
@@ -2368,14 +2425,14 @@ class ze {
|
|
|
2368
2425
|
updated: !1,
|
|
2369
2426
|
delta: t
|
|
2370
2427
|
});
|
|
2371
|
-
const n = this.entry;
|
|
2372
|
-
this.entriesCursor = e;
|
|
2373
2428
|
const s = this.entry;
|
|
2374
|
-
|
|
2429
|
+
this.entriesCursor = e;
|
|
2430
|
+
const n = this.entry;
|
|
2431
|
+
return this.logger.log("State changed", { before: s, after: n }), this.performGo({
|
|
2375
2432
|
updated: !0,
|
|
2376
2433
|
delta: t,
|
|
2377
|
-
before:
|
|
2378
|
-
after:
|
|
2434
|
+
before: s,
|
|
2435
|
+
after: n
|
|
2379
2436
|
});
|
|
2380
2437
|
}
|
|
2381
2438
|
/**
|
|
@@ -2415,12 +2472,12 @@ class ze {
|
|
|
2415
2472
|
*/
|
|
2416
2473
|
push(t) {
|
|
2417
2474
|
this.entriesCursor !== this.entries.length - 1 && this.entries.splice(this.entriesCursor + 1);
|
|
2418
|
-
const e = this.formatEntry(t),
|
|
2475
|
+
const e = this.formatEntry(t), s = this.entry;
|
|
2419
2476
|
this.entriesCursor += 1, this.entries[this.entriesCursor] = e;
|
|
2420
|
-
const
|
|
2421
|
-
return this.logger.log("State changed", { before:
|
|
2422
|
-
before:
|
|
2423
|
-
after:
|
|
2477
|
+
const n = this.entry;
|
|
2478
|
+
return this.logger.log("State changed", { before: s, after: n }), this.performPush({
|
|
2479
|
+
before: s,
|
|
2480
|
+
after: n
|
|
2424
2481
|
});
|
|
2425
2482
|
}
|
|
2426
2483
|
/**
|
|
@@ -2450,13 +2507,13 @@ class ze {
|
|
|
2450
2507
|
updated: !1,
|
|
2451
2508
|
entry: e
|
|
2452
2509
|
});
|
|
2453
|
-
const n = this.entry;
|
|
2454
|
-
this.entries[this.entriesCursor] = e;
|
|
2455
2510
|
const s = this.entry;
|
|
2456
|
-
|
|
2511
|
+
this.entries[this.entriesCursor] = e;
|
|
2512
|
+
const n = this.entry;
|
|
2513
|
+
return this.logger.log("State changed", { before: s, after: n }), this.performReplace({
|
|
2457
2514
|
updated: !0,
|
|
2458
|
-
before:
|
|
2459
|
-
after:
|
|
2515
|
+
before: s,
|
|
2516
|
+
after: n
|
|
2460
2517
|
});
|
|
2461
2518
|
}
|
|
2462
2519
|
/**
|
|
@@ -2469,13 +2526,13 @@ class ze {
|
|
|
2469
2526
|
}
|
|
2470
2527
|
}
|
|
2471
2528
|
const at = 0, J = 1, Q = 2;
|
|
2472
|
-
class Lt extends
|
|
2473
|
-
constructor(e,
|
|
2474
|
-
super(e,
|
|
2475
|
-
...
|
|
2529
|
+
class Lt extends Ze {
|
|
2530
|
+
constructor(e, s, n = {}) {
|
|
2531
|
+
super(e, s, {
|
|
2532
|
+
...n,
|
|
2476
2533
|
loggerPrefix: "HashNavigator"
|
|
2477
2534
|
});
|
|
2478
|
-
o(this, "ee", new
|
|
2535
|
+
o(this, "ee", new _());
|
|
2479
2536
|
o(this, "attached", !1);
|
|
2480
2537
|
/**
|
|
2481
2538
|
* Handles window "popstate" event.
|
|
@@ -2509,20 +2566,20 @@ class Lt extends ze {
|
|
|
2509
2566
|
*/
|
|
2510
2567
|
static fromLocation(e) {
|
|
2511
2568
|
const {
|
|
2512
|
-
search:
|
|
2513
|
-
pathname:
|
|
2569
|
+
search: s,
|
|
2570
|
+
pathname: n,
|
|
2514
2571
|
hash: i
|
|
2515
2572
|
} = new URL(
|
|
2516
2573
|
window.location.hash.slice(1),
|
|
2517
2574
|
window.location.href
|
|
2518
2575
|
);
|
|
2519
|
-
return new Lt([{ search:
|
|
2576
|
+
return new Lt([{ search: s, pathname: n, hash: i }], 0, e);
|
|
2520
2577
|
}
|
|
2521
2578
|
async performGo(e) {
|
|
2522
2579
|
e.updated && (this.attached && await this.syncHistory(), this.emitChanged(e.before, e.after));
|
|
2523
2580
|
}
|
|
2524
|
-
async performPush({ before: e, after:
|
|
2525
|
-
this.attached && await this.syncHistory(), this.emitChanged(e,
|
|
2581
|
+
async performPush({ before: e, after: s }) {
|
|
2582
|
+
this.attached && await this.syncHistory(), this.emitChanged(e, s);
|
|
2526
2583
|
}
|
|
2527
2584
|
async performReplace(e) {
|
|
2528
2585
|
e.updated && (this.attached && window.history.replaceState(null, "", `#${this.path}`), this.emitChanged(e.before, e.after));
|
|
@@ -2533,13 +2590,13 @@ class Lt extends ze {
|
|
|
2533
2590
|
async syncHistory() {
|
|
2534
2591
|
window.removeEventListener("popstate", this.onPopState);
|
|
2535
2592
|
const e = `#${this.path}`;
|
|
2536
|
-
await
|
|
2593
|
+
await Qe(), f("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e), window.history.pushState(Q, ""), await N(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(J, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(Q, ""), await N(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(at, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
|
|
2537
2594
|
}
|
|
2538
|
-
emitChanged(e,
|
|
2595
|
+
emitChanged(e, s) {
|
|
2539
2596
|
this.ee.emit("change", {
|
|
2540
2597
|
navigator: this,
|
|
2541
2598
|
from: e,
|
|
2542
|
-
to:
|
|
2599
|
+
to: s
|
|
2543
2600
|
});
|
|
2544
2601
|
}
|
|
2545
2602
|
/**
|
|
@@ -2547,66 +2604,67 @@ class Lt extends ze {
|
|
|
2547
2604
|
*/
|
|
2548
2605
|
async attach() {
|
|
2549
2606
|
if (!this.attached)
|
|
2550
|
-
return this.logger.log("Attaching", this), this.attached = !0,
|
|
2607
|
+
return this.logger.log("Attaching", this), this.attached = !0, m("back_button_pressed", this.back), this.syncHistory();
|
|
2551
2608
|
}
|
|
2552
2609
|
/**
|
|
2553
2610
|
* Detaches current navigator from the browser history.
|
|
2554
2611
|
*/
|
|
2555
2612
|
detach() {
|
|
2556
|
-
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState),
|
|
2613
|
+
this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), $("back_button_pressed", this.back));
|
|
2557
2614
|
}
|
|
2558
2615
|
}
|
|
2559
2616
|
export {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2617
|
+
Ee as BackButton,
|
|
2618
|
+
ke as ClosingBehavior,
|
|
2619
|
+
Se as CloudStorage,
|
|
2620
|
+
xe as HapticFeedback,
|
|
2564
2621
|
Lt as HashNavigator,
|
|
2565
|
-
|
|
2566
|
-
|
|
2622
|
+
Wt as InitData,
|
|
2623
|
+
je as Invoice,
|
|
2567
2624
|
qe as MainButton,
|
|
2568
2625
|
K as MethodUnsupportedError,
|
|
2569
2626
|
$e as MiniApp,
|
|
2570
|
-
|
|
2627
|
+
Ze as Navigator,
|
|
2571
2628
|
Y as ParameterUnsupportedError,
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2629
|
+
Fe as Popup,
|
|
2630
|
+
ze as QRScanner,
|
|
2631
|
+
Re as SettingsButton,
|
|
2632
|
+
Gt as ThemeParams,
|
|
2633
|
+
Je as Utils,
|
|
2576
2634
|
j as Viewport,
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2635
|
+
Ot as chatParser,
|
|
2636
|
+
Ce as classNames,
|
|
2637
|
+
be as compareVersions,
|
|
2638
|
+
me as createPostEvent,
|
|
2639
|
+
ar as getHash,
|
|
2640
|
+
or as init,
|
|
2583
2641
|
gt as initDataParser,
|
|
2584
2642
|
lt as isColorDark,
|
|
2585
2643
|
Ct as isIframe,
|
|
2586
2644
|
ut as isRGB,
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2645
|
+
Nt as isRGBShort,
|
|
2646
|
+
O as isRecord,
|
|
2647
|
+
tr as isTMA,
|
|
2590
2648
|
bt as launchParamsParser,
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2649
|
+
ir as mergeClassNames,
|
|
2650
|
+
$ as off,
|
|
2651
|
+
m as on,
|
|
2652
|
+
sr as once,
|
|
2653
|
+
Ye as parseInitData,
|
|
2596
2654
|
mt as parseLaunchParams,
|
|
2597
|
-
|
|
2655
|
+
wt as parseThemeParams,
|
|
2598
2656
|
f as postEvent,
|
|
2599
|
-
|
|
2600
|
-
|
|
2657
|
+
b as request,
|
|
2658
|
+
Xe as requestThemeParams,
|
|
2601
2659
|
Pt as requestViewport,
|
|
2602
2660
|
Et as retrieveLaunchData,
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2661
|
+
Qt as serializeLaunchParams,
|
|
2662
|
+
jt as serializeThemeParams,
|
|
2663
|
+
er as setDebug,
|
|
2664
|
+
rr as setTargetOrigin,
|
|
2665
|
+
nr as subscribe,
|
|
2666
|
+
A as supports,
|
|
2667
|
+
_t as themeParamsParser,
|
|
2610
2668
|
pt as toRGB,
|
|
2611
2669
|
we as unsubscribe,
|
|
2612
2670
|
tt as userParser
|