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