@tma.js/sdk-solid 2.1.10 → 3.0.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/LICENSE +1 -1
- package/README.md +9 -9
- package/dist/dts/index.d.ts +1 -18
- package/dist/dts/useSignal.d.ts +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -3026
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/dts/SDKProvider/SDKContext.d.ts +0 -8
- package/dist/dts/SDKProvider/SDKProvider.d.ts +0 -8
- package/dist/dts/SDKProvider/SDKProvider.types.d.ts +0 -54
- package/dist/dts/createHOC.d.ts +0 -15
- package/dist/dts/createHook.d.ts +0 -13
- package/dist/dts/hooks-hocs/back-button.d.ts +0 -8
- package/dist/dts/hooks-hocs/biometry-manager.d.ts +0 -8
- package/dist/dts/hooks-hocs/closing-behavior.d.ts +0 -8
- package/dist/dts/hooks-hocs/cloud-storage.d.ts +0 -8
- package/dist/dts/hooks-hocs/haptic-feedback.d.ts +0 -8
- package/dist/dts/hooks-hocs/init-data.d.ts +0 -8
- package/dist/dts/hooks-hocs/invoice.d.ts +0 -8
- package/dist/dts/hooks-hocs/main-button.d.ts +0 -8
- package/dist/dts/hooks-hocs/mini-app.d.ts +0 -8
- package/dist/dts/hooks-hocs/popup.d.ts +0 -8
- package/dist/dts/hooks-hocs/qr-scanner.d.ts +0 -8
- package/dist/dts/hooks-hocs/settings-button.d.ts +0 -8
- package/dist/dts/hooks-hocs/theme-params.d.ts +0 -8
- package/dist/dts/hooks-hocs/utils.d.ts +0 -8
- package/dist/dts/hooks-hocs/viewport.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,3030 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
s !== void 0 && t && t(s), s = void 0;
|
|
7
|
-
};
|
|
8
|
-
return [() => s === void 0 ? s = e(n) : s, n];
|
|
1
|
+
import { createSignal as r, onCleanup as n } from "solid-js";
|
|
2
|
+
export * from "@tma.js/sdk";
|
|
3
|
+
function p(e) {
|
|
4
|
+
const [t, o] = r(e());
|
|
5
|
+
return n(e.sub(o)), t;
|
|
9
6
|
}
|
|
10
|
-
function yt(e) {
|
|
11
|
-
const t = U(), { count: s } = t;
|
|
12
|
-
t.unsubscribe(e), s && !t.count && Se();
|
|
13
|
-
}
|
|
14
|
-
function ae(e) {
|
|
15
|
-
return U().subscribe(e), () => yt(e);
|
|
16
|
-
}
|
|
17
|
-
class ce {
|
|
18
|
-
constructor(t, s = {}) {
|
|
19
|
-
this.scope = t, this.options = s;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Prints message into a console in case, logger is currently enabled.
|
|
23
|
-
* @param level - log level.
|
|
24
|
-
* @param args - arguments.
|
|
25
|
-
*/
|
|
26
|
-
print(t, ...s) {
|
|
27
|
-
const n = /* @__PURE__ */ new Date(), r = Intl.DateTimeFormat("en-GB", {
|
|
28
|
-
hour: "2-digit",
|
|
29
|
-
minute: "2-digit",
|
|
30
|
-
second: "2-digit",
|
|
31
|
-
fractionalSecondDigits: 3,
|
|
32
|
-
timeZone: "UTC"
|
|
33
|
-
}).format(n), { textColor: i, bgColor: o } = this.options, a = "font-weight: bold;padding: 0 5px;border-radius:5px";
|
|
34
|
-
console[t](
|
|
35
|
-
`%c${r}%c / %c${this.scope}`,
|
|
36
|
-
`${a};background-color: lightblue;color:black`,
|
|
37
|
-
"",
|
|
38
|
-
`${a};${i ? `color:${i};` : ""}${o ? `background-color:${o}` : ""}`,
|
|
39
|
-
...s
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Prints error message into a console.
|
|
44
|
-
* @param args
|
|
45
|
-
*/
|
|
46
|
-
error(...t) {
|
|
47
|
-
this.print("error", ...t);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Prints log message into a console.
|
|
51
|
-
* @param args
|
|
52
|
-
*/
|
|
53
|
-
log(...t) {
|
|
54
|
-
this.print("log", ...t);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const X = new ce("SDK", {
|
|
58
|
-
bgColor: "forestgreen",
|
|
59
|
-
textColor: "white"
|
|
60
|
-
});
|
|
61
|
-
let F = !1;
|
|
62
|
-
const gt = ({ name: e, payload: t }) => {
|
|
63
|
-
X.log("Event received:", t ? { name: e, payload: t } : { name: e });
|
|
64
|
-
};
|
|
65
|
-
function he(e) {
|
|
66
|
-
F !== e && (F = e, e ? ae(gt) : yt(gt));
|
|
67
|
-
}
|
|
68
|
-
function pe(...e) {
|
|
69
|
-
F && X.log(...e);
|
|
70
|
-
}
|
|
71
|
-
class k {
|
|
72
|
-
constructor() {
|
|
73
|
-
c(this, "listeners", /* @__PURE__ */ new Map()), c(this, "listenersCount", 0), c(this, "subscribeListeners", []);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Removes all event listeners.
|
|
77
|
-
*/
|
|
78
|
-
clear() {
|
|
79
|
-
this.listeners.clear(), this.subscribeListeners = [];
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns count of bound listeners.
|
|
83
|
-
*/
|
|
84
|
-
get count() {
|
|
85
|
-
return this.listenersCount + this.subscribeListeners.length;
|
|
86
|
-
}
|
|
87
|
-
emit(t, ...s) {
|
|
88
|
-
this.subscribeListeners.forEach((n) => n({
|
|
89
|
-
event: t,
|
|
90
|
-
args: s
|
|
91
|
-
})), (this.listeners.get(t) || []).forEach(([n, r]) => {
|
|
92
|
-
n(...s), r && this.off(t, n);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Adds new event listener.
|
|
97
|
-
* @param event - event name.
|
|
98
|
-
* @param listener - event listener.
|
|
99
|
-
* @param once - should listener be called only once.
|
|
100
|
-
* @returns Function to remove bound event listener.
|
|
101
|
-
*/
|
|
102
|
-
on(t, s, n) {
|
|
103
|
-
let r = this.listeners.get(t);
|
|
104
|
-
return r || this.listeners.set(t, r = []), r.push([s, n]), this.listenersCount += 1, () => this.off(t, s);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Removes event listener. In case, specified listener was bound several times, it removes
|
|
108
|
-
* only a single one.
|
|
109
|
-
* @param event - event name.
|
|
110
|
-
* @param listener - event listener.
|
|
111
|
-
*/
|
|
112
|
-
off(t, s) {
|
|
113
|
-
const n = this.listeners.get(t) || [];
|
|
114
|
-
for (let r = 0; r < n.length; r += 1)
|
|
115
|
-
if (s === n[r][0]) {
|
|
116
|
-
n.splice(r, 1), this.listenersCount -= 1;
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Adds a new event listener for all events.
|
|
122
|
-
* @param listener - event listener.
|
|
123
|
-
* @returns Function to remove event listener.
|
|
124
|
-
*/
|
|
125
|
-
subscribe(t) {
|
|
126
|
-
return this.subscribeListeners.push(t), () => this.unsubscribe(t);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Removes global event listener. In case, specified listener was bound several times, it removes
|
|
130
|
-
* only a single one.
|
|
131
|
-
* @param listener - event listener.
|
|
132
|
-
*/
|
|
133
|
-
unsubscribe(t) {
|
|
134
|
-
for (let s = 0; s < this.subscribeListeners.length; s += 1)
|
|
135
|
-
if (this.subscribeListeners[s] === t) {
|
|
136
|
-
this.subscribeListeners.splice(s, 1);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function Q(e, t, s) {
|
|
142
|
-
return window.addEventListener(e, t, s), () => window.removeEventListener(e, t, s);
|
|
143
|
-
}
|
|
144
|
-
function tt(...e) {
|
|
145
|
-
let t = !1;
|
|
146
|
-
const s = [...e];
|
|
147
|
-
return [
|
|
148
|
-
(n) => !t && s.push(n),
|
|
149
|
-
() => {
|
|
150
|
-
t || (t = !0, s.forEach((n) => n()));
|
|
151
|
-
},
|
|
152
|
-
t
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
class $ extends Error {
|
|
156
|
-
constructor(t, s, n) {
|
|
157
|
-
super(s, { cause: n }), this.type = t, Object.setPrototypeOf(this, $.prototype);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function b(e, t, s) {
|
|
161
|
-
return new $(e, t, s);
|
|
162
|
-
}
|
|
163
|
-
const ue = "ERR_METHOD_UNSUPPORTED", le = "ERR_METHOD_PARAMETER_UNSUPPORTED", de = "ERR_UNKNOWN_ENV", _e = "ERR_INVOKE_CUSTOM_METHOD_RESPONSE", ge = "ERR_TIMED_OUT", fe = "ERR_UNEXPECTED_TYPE", Et = "ERR_PARSE", we = "ERR_NAVIGATION_LIST_EMPTY", me = "ERR_NAVIGATION_CURSOR_INVALID", zs = "ERR_NAVIGATION_ITEM_INVALID", Js = "ERR_SSR_INIT", be = "ERR_INVALID_PATH_BASE";
|
|
164
|
-
function S() {
|
|
165
|
-
return b(fe, "Value has unexpected type");
|
|
166
|
-
}
|
|
167
|
-
class L {
|
|
168
|
-
constructor(t, s, n) {
|
|
169
|
-
this.parser = t, this.isOptional = s, this.type = n;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Attempts to parse passed value
|
|
173
|
-
* @param value - value to parse.
|
|
174
|
-
* @throws {SDKError} ERR_PARSE
|
|
175
|
-
* @see ERR_PARSE
|
|
176
|
-
*/
|
|
177
|
-
parse(t) {
|
|
178
|
-
if (!(this.isOptional && t === void 0))
|
|
179
|
-
try {
|
|
180
|
-
return this.parser(t);
|
|
181
|
-
} catch (s) {
|
|
182
|
-
throw b(
|
|
183
|
-
Et,
|
|
184
|
-
`Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
|
|
185
|
-
s
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
optional() {
|
|
190
|
-
return this.isOptional = !0, this;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function T(e, t) {
|
|
194
|
-
return () => new L(e, !1, t);
|
|
195
|
-
}
|
|
196
|
-
const y = T((e) => {
|
|
197
|
-
if (typeof e == "boolean")
|
|
198
|
-
return e;
|
|
199
|
-
const t = String(e);
|
|
200
|
-
if (t === "1" || t === "true")
|
|
201
|
-
return !0;
|
|
202
|
-
if (t === "0" || t === "false")
|
|
203
|
-
return !1;
|
|
204
|
-
throw S();
|
|
205
|
-
}, "boolean");
|
|
206
|
-
function Pt(e, t) {
|
|
207
|
-
const s = {};
|
|
208
|
-
for (const n in e) {
|
|
209
|
-
const r = e[n];
|
|
210
|
-
if (!r)
|
|
211
|
-
continue;
|
|
212
|
-
let i, o;
|
|
213
|
-
if (typeof r == "function" || "parse" in r)
|
|
214
|
-
i = n, o = typeof r == "function" ? r : r.parse.bind(r);
|
|
215
|
-
else {
|
|
216
|
-
const { type: a } = r;
|
|
217
|
-
i = r.from || n, o = typeof a == "function" ? a : a.parse.bind(a);
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
const a = o(t(i));
|
|
221
|
-
a !== void 0 && (s[n] = a);
|
|
222
|
-
} catch (a) {
|
|
223
|
-
throw b(Et, `Unable to parse field "${n}"`, a);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return s;
|
|
227
|
-
}
|
|
228
|
-
function et(e) {
|
|
229
|
-
let t = e;
|
|
230
|
-
if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
|
|
231
|
-
throw S();
|
|
232
|
-
return t;
|
|
233
|
-
}
|
|
234
|
-
function f(e, t) {
|
|
235
|
-
return new L((s) => {
|
|
236
|
-
const n = et(s);
|
|
237
|
-
return Pt(e, (r) => n[r]);
|
|
238
|
-
}, !1, t);
|
|
239
|
-
}
|
|
240
|
-
const P = T((e) => {
|
|
241
|
-
if (typeof e == "number")
|
|
242
|
-
return e;
|
|
243
|
-
if (typeof e == "string") {
|
|
244
|
-
const t = Number(e);
|
|
245
|
-
if (!Number.isNaN(t))
|
|
246
|
-
return t;
|
|
247
|
-
}
|
|
248
|
-
throw S();
|
|
249
|
-
}, "number");
|
|
250
|
-
function st(e) {
|
|
251
|
-
return /^#[\da-f]{6}$/i.test(e);
|
|
252
|
-
}
|
|
253
|
-
function ve(e) {
|
|
254
|
-
return /^#[\da-f]{3}$/i.test(e);
|
|
255
|
-
}
|
|
256
|
-
function xt(e) {
|
|
257
|
-
const t = e.replace(/\s/g, "").toLowerCase();
|
|
258
|
-
if (st(t))
|
|
259
|
-
return t;
|
|
260
|
-
if (ve(t)) {
|
|
261
|
-
let n = "#";
|
|
262
|
-
for (let r = 0; r < 3; r += 1)
|
|
263
|
-
n += t[1 + r].repeat(2);
|
|
264
|
-
return n;
|
|
265
|
-
}
|
|
266
|
-
const s = 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}\)$/);
|
|
267
|
-
if (!s)
|
|
268
|
-
throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);
|
|
269
|
-
return s.slice(1).reduce((n, r) => {
|
|
270
|
-
const i = parseInt(r, 10).toString(16);
|
|
271
|
-
return n + (i.length === 1 ? "0" : "") + i;
|
|
272
|
-
}, "#");
|
|
273
|
-
}
|
|
274
|
-
const p = T((e) => {
|
|
275
|
-
if (typeof e == "string" || typeof e == "number")
|
|
276
|
-
return e.toString();
|
|
277
|
-
throw S();
|
|
278
|
-
}, "string"), Ct = T((e) => xt(p().parse(e)), "rgb");
|
|
279
|
-
function St(e) {
|
|
280
|
-
return f({
|
|
281
|
-
eventType: p(),
|
|
282
|
-
eventData: (t) => t
|
|
283
|
-
}).parse(e);
|
|
284
|
-
}
|
|
285
|
-
function ye() {
|
|
286
|
-
["TelegramGameProxy_receiveEvent", "TelegramGameProxy", "Telegram"].forEach((e) => {
|
|
287
|
-
delete window[e];
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
function Y(e, t) {
|
|
291
|
-
window.dispatchEvent(new MessageEvent("message", {
|
|
292
|
-
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
293
|
-
// We specify window.parent to imitate the case, the parent iframe sent us this event.
|
|
294
|
-
source: window.parent
|
|
295
|
-
}));
|
|
296
|
-
}
|
|
297
|
-
function Ee() {
|
|
298
|
-
[
|
|
299
|
-
["TelegramGameProxy_receiveEvent"],
|
|
300
|
-
// Windows Phone.
|
|
301
|
-
["TelegramGameProxy", "receiveEvent"],
|
|
302
|
-
// Desktop.
|
|
303
|
-
["Telegram", "WebView", "receiveEvent"]
|
|
304
|
-
// Android and iOS.
|
|
305
|
-
].forEach((e) => {
|
|
306
|
-
let t = window;
|
|
307
|
-
e.forEach((s, n, r) => {
|
|
308
|
-
if (n === r.length - 1) {
|
|
309
|
-
t[s] = Y;
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
s in t || (t[s] = {}), t = t[s];
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
const Pe = {
|
|
317
|
-
clipboard_text_received: f({
|
|
318
|
-
req_id: p(),
|
|
319
|
-
data: (e) => e === null ? e : p().optional().parse(e)
|
|
320
|
-
}),
|
|
321
|
-
custom_method_invoked: f({
|
|
322
|
-
req_id: p(),
|
|
323
|
-
result: (e) => e,
|
|
324
|
-
error: p().optional()
|
|
325
|
-
}),
|
|
326
|
-
invoice_closed: f({ slug: p(), status: p() }),
|
|
327
|
-
phone_requested: f({ status: p() }),
|
|
328
|
-
popup_closed: {
|
|
329
|
-
parse(e) {
|
|
330
|
-
return f({
|
|
331
|
-
button_id: (t) => t == null ? void 0 : p().parse(t)
|
|
332
|
-
}).parse(e ?? {});
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
qr_text_received: f({ data: p().optional() }),
|
|
336
|
-
theme_changed: f({
|
|
337
|
-
theme_params: (e) => {
|
|
338
|
-
const t = Ct().optional();
|
|
339
|
-
return Object.entries(et(e)).reduce((s, [n, r]) => (s[n] = t.parse(r), s), {});
|
|
340
|
-
}
|
|
341
|
-
}),
|
|
342
|
-
viewport_changed: f({
|
|
343
|
-
height: P(),
|
|
344
|
-
width: (e) => e == null ? window.innerWidth : P().parse(e),
|
|
345
|
-
is_state_stable: y(),
|
|
346
|
-
is_expanded: y()
|
|
347
|
-
}),
|
|
348
|
-
write_access_requested: f({ status: p() })
|
|
349
|
-
};
|
|
350
|
-
function xe() {
|
|
351
|
-
const e = new k(), t = new k();
|
|
352
|
-
t.subscribe((n) => {
|
|
353
|
-
e.emit("event", { name: n.event, payload: n.args[0] });
|
|
354
|
-
}), Ee();
|
|
355
|
-
const [, s] = tt(
|
|
356
|
-
// Don't forget to remove created handlers.
|
|
357
|
-
ye,
|
|
358
|
-
// Add "resize" event listener to make sure, we always have fresh viewport information.
|
|
359
|
-
// Desktop version of Telegram is sometimes not sending the viewport_changed
|
|
360
|
-
// event. For example, when the MainButton is shown. That's why we should
|
|
361
|
-
// add our own listener to make sure, viewport information is always fresh.
|
|
362
|
-
// Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/10
|
|
363
|
-
Q("resize", () => {
|
|
364
|
-
t.emit("viewport_changed", {
|
|
365
|
-
width: window.innerWidth,
|
|
366
|
-
height: window.innerHeight,
|
|
367
|
-
is_state_stable: !0,
|
|
368
|
-
is_expanded: !0
|
|
369
|
-
});
|
|
370
|
-
}),
|
|
371
|
-
// Add listener, which handles events sent from the Telegram web application and also events
|
|
372
|
-
// generated by the local emitEvent function.
|
|
373
|
-
Q("message", (n) => {
|
|
374
|
-
if (n.source !== window.parent)
|
|
375
|
-
return;
|
|
376
|
-
let r;
|
|
377
|
-
try {
|
|
378
|
-
r = St(n.data);
|
|
379
|
-
} catch {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
const { eventType: i, eventData: o } = r, a = Pe[i];
|
|
383
|
-
try {
|
|
384
|
-
const h = a ? a.parse(o) : o;
|
|
385
|
-
t.emit(...h ? [i, h] : [i]);
|
|
386
|
-
} catch (h) {
|
|
387
|
-
X.error(
|
|
388
|
-
`An error occurred processing the "${i}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,
|
|
389
|
-
r,
|
|
390
|
-
h
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
}),
|
|
394
|
-
// Clear emitters.
|
|
395
|
-
() => e.clear(),
|
|
396
|
-
() => t.clear()
|
|
397
|
-
);
|
|
398
|
-
return [{
|
|
399
|
-
on: t.on.bind(t),
|
|
400
|
-
off: t.off.bind(t),
|
|
401
|
-
subscribe(n) {
|
|
402
|
-
return e.on("event", n);
|
|
403
|
-
},
|
|
404
|
-
unsubscribe(n) {
|
|
405
|
-
e.off("event", n);
|
|
406
|
-
},
|
|
407
|
-
get count() {
|
|
408
|
-
return t.count + e.count;
|
|
409
|
-
}
|
|
410
|
-
}, s];
|
|
411
|
-
}
|
|
412
|
-
const [Ce, Se] = vt(
|
|
413
|
-
(e) => {
|
|
414
|
-
const [t, s] = xe(), n = t.off.bind(t);
|
|
415
|
-
return t.off = (r, i) => {
|
|
416
|
-
const { count: o } = t;
|
|
417
|
-
n(r, i), o && !t.count && e();
|
|
418
|
-
}, [t, s];
|
|
419
|
-
},
|
|
420
|
-
([, e]) => e()
|
|
421
|
-
);
|
|
422
|
-
function U() {
|
|
423
|
-
return Ce()[0];
|
|
424
|
-
}
|
|
425
|
-
function H(e, t) {
|
|
426
|
-
U().off(e, t);
|
|
427
|
-
}
|
|
428
|
-
function v(e, t, s) {
|
|
429
|
-
return U().on(e, t, s);
|
|
430
|
-
}
|
|
431
|
-
function N(e) {
|
|
432
|
-
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
433
|
-
}
|
|
434
|
-
function Te(e, t) {
|
|
435
|
-
const s = e.split("."), n = t.split("."), r = Math.max(s.length, n.length);
|
|
436
|
-
for (let i = 0; i < r; i += 1) {
|
|
437
|
-
const o = parseInt(s[i] || "0", 10), a = parseInt(n[i] || "0", 10);
|
|
438
|
-
if (o !== a)
|
|
439
|
-
return o > a ? 1 : -1;
|
|
440
|
-
}
|
|
441
|
-
return 0;
|
|
442
|
-
}
|
|
443
|
-
function m(e, t) {
|
|
444
|
-
return Te(e, t) <= 0;
|
|
445
|
-
}
|
|
446
|
-
function x(e, t, s) {
|
|
447
|
-
if (typeof s == "string") {
|
|
448
|
-
if (e === "web_app_open_link") {
|
|
449
|
-
if (t === "try_instant_view")
|
|
450
|
-
return m("6.4", s);
|
|
451
|
-
if (t === "try_browser")
|
|
452
|
-
return m("7.6", s);
|
|
453
|
-
}
|
|
454
|
-
if (e === "web_app_set_header_color" && t === "color")
|
|
455
|
-
return m("6.9", s);
|
|
456
|
-
if (e === "web_app_close" && t === "return_back")
|
|
457
|
-
return m("7.6", s);
|
|
458
|
-
}
|
|
459
|
-
switch (e) {
|
|
460
|
-
case "web_app_open_tg_link":
|
|
461
|
-
case "web_app_open_invoice":
|
|
462
|
-
case "web_app_setup_back_button":
|
|
463
|
-
case "web_app_set_background_color":
|
|
464
|
-
case "web_app_set_header_color":
|
|
465
|
-
case "web_app_trigger_haptic_feedback":
|
|
466
|
-
return m("6.1", t);
|
|
467
|
-
case "web_app_open_popup":
|
|
468
|
-
return m("6.2", t);
|
|
469
|
-
case "web_app_close_scan_qr_popup":
|
|
470
|
-
case "web_app_open_scan_qr_popup":
|
|
471
|
-
case "web_app_read_text_from_clipboard":
|
|
472
|
-
return m("6.4", t);
|
|
473
|
-
case "web_app_switch_inline_query":
|
|
474
|
-
return m("6.7", t);
|
|
475
|
-
case "web_app_invoke_custom_method":
|
|
476
|
-
case "web_app_request_write_access":
|
|
477
|
-
case "web_app_request_phone":
|
|
478
|
-
return m("6.9", t);
|
|
479
|
-
case "web_app_setup_settings_button":
|
|
480
|
-
return m("6.10", t);
|
|
481
|
-
case "web_app_biometry_get_info":
|
|
482
|
-
case "web_app_biometry_open_settings":
|
|
483
|
-
case "web_app_biometry_request_access":
|
|
484
|
-
case "web_app_biometry_request_auth":
|
|
485
|
-
case "web_app_biometry_update_token":
|
|
486
|
-
return m("7.2", t);
|
|
487
|
-
default:
|
|
488
|
-
return [
|
|
489
|
-
"iframe_ready",
|
|
490
|
-
"iframe_will_reload",
|
|
491
|
-
"web_app_close",
|
|
492
|
-
"web_app_data_send",
|
|
493
|
-
"web_app_expand",
|
|
494
|
-
"web_app_open_link",
|
|
495
|
-
"web_app_ready",
|
|
496
|
-
"web_app_request_theme",
|
|
497
|
-
"web_app_request_viewport",
|
|
498
|
-
"web_app_setup_main_button",
|
|
499
|
-
"web_app_setup_closing_behavior"
|
|
500
|
-
].includes(e);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
function Tt(e) {
|
|
504
|
-
return "external" in e && N(e.external) && "notify" in e.external && typeof e.external.notify == "function";
|
|
505
|
-
}
|
|
506
|
-
function Rt(e) {
|
|
507
|
-
return "TelegramWebviewProxy" in e && N(e.TelegramWebviewProxy) && "postEvent" in e.TelegramWebviewProxy && typeof e.TelegramWebviewProxy.postEvent == "function";
|
|
508
|
-
}
|
|
509
|
-
function nt() {
|
|
510
|
-
try {
|
|
511
|
-
return window.self !== window.top;
|
|
512
|
-
} catch {
|
|
513
|
-
return !0;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
let At = "https://web.telegram.org";
|
|
517
|
-
function Fs(e) {
|
|
518
|
-
At = e;
|
|
519
|
-
}
|
|
520
|
-
function Re() {
|
|
521
|
-
return At;
|
|
522
|
-
}
|
|
523
|
-
function q(e, t, s) {
|
|
524
|
-
let n = {}, r;
|
|
525
|
-
t === void 0 && s === void 0 ? n = {} : t !== void 0 && s !== void 0 ? (n = s, r = t) : t !== void 0 && ("targetOrigin" in t ? n = t : r = t);
|
|
526
|
-
const { targetOrigin: i = Re() } = n;
|
|
527
|
-
if (pe("Posting event:", r ? { event: e, data: r } : { event: e }), nt()) {
|
|
528
|
-
window.parent.postMessage(JSON.stringify({ eventType: e, eventData: r }), i);
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if (Tt(window)) {
|
|
532
|
-
window.external.notify(JSON.stringify({ eventType: e, eventData: r }));
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
if (Rt(window)) {
|
|
536
|
-
window.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
throw b(
|
|
540
|
-
de,
|
|
541
|
-
"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment."
|
|
542
|
-
);
|
|
543
|
-
}
|
|
544
|
-
function Ae(e) {
|
|
545
|
-
return (t, s) => {
|
|
546
|
-
if (!x(t, e))
|
|
547
|
-
throw b(ue, `Method "${t}" is unsupported in Mini Apps version ${e}`);
|
|
548
|
-
if (N(s)) {
|
|
549
|
-
let n;
|
|
550
|
-
if (t === "web_app_open_link" && "try_instant_view" in s ? n = "try_instant_view" : t === "web_app_set_header_color" && "color" in s && (n = "color"), n && !x(t, n, e))
|
|
551
|
-
throw b(
|
|
552
|
-
le,
|
|
553
|
-
`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
return q(t, s);
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
function It(e) {
|
|
560
|
-
return ({ req_id: t }) => t === e;
|
|
561
|
-
}
|
|
562
|
-
function kt(e) {
|
|
563
|
-
return b(ge, `Timeout reached: ${e}ms`);
|
|
564
|
-
}
|
|
565
|
-
function qt(e, t) {
|
|
566
|
-
return Promise.race([
|
|
567
|
-
typeof e == "function" ? e() : e,
|
|
568
|
-
new Promise((s, n) => {
|
|
569
|
-
setTimeout(() => {
|
|
570
|
-
n(kt(t));
|
|
571
|
-
}, t);
|
|
572
|
-
})
|
|
573
|
-
]);
|
|
574
|
-
}
|
|
575
|
-
async function w(e) {
|
|
576
|
-
let t;
|
|
577
|
-
const s = new Promise((a) => {
|
|
578
|
-
t = a;
|
|
579
|
-
}), { event: n, capture: r, timeout: i } = e, [, o] = tt(
|
|
580
|
-
...(Array.isArray(n) ? n : [n]).map(
|
|
581
|
-
(a) => v(a, (h) => (!r || r(h)) && t(h))
|
|
582
|
-
)
|
|
583
|
-
);
|
|
584
|
-
try {
|
|
585
|
-
return (e.postEvent || q)(e.method, e.params), await (i ? qt(s, i) : s);
|
|
586
|
-
} finally {
|
|
587
|
-
o();
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
async function A(e, t, s, n = {}) {
|
|
591
|
-
const {
|
|
592
|
-
result: r,
|
|
593
|
-
error: i
|
|
594
|
-
} = await w({
|
|
595
|
-
...n,
|
|
596
|
-
method: "web_app_invoke_custom_method",
|
|
597
|
-
event: "custom_method_invoked",
|
|
598
|
-
params: {
|
|
599
|
-
method: e,
|
|
600
|
-
params: t,
|
|
601
|
-
req_id: s
|
|
602
|
-
},
|
|
603
|
-
capture: It(s)
|
|
604
|
-
});
|
|
605
|
-
if (i)
|
|
606
|
-
throw b(_e, i);
|
|
607
|
-
return r;
|
|
608
|
-
}
|
|
609
|
-
function Z(...e) {
|
|
610
|
-
return e.map((t) => {
|
|
611
|
-
if (typeof t == "string")
|
|
612
|
-
return t;
|
|
613
|
-
if (N(t))
|
|
614
|
-
return Z(Object.entries(t).map((s) => s[1] && s[0]));
|
|
615
|
-
if (Array.isArray(t))
|
|
616
|
-
return Z(...t);
|
|
617
|
-
}).filter(Boolean).join(" ");
|
|
618
|
-
}
|
|
619
|
-
function Qs(...e) {
|
|
620
|
-
return e.reduce((t, s) => (N(s) && Object.entries(s).forEach(([n, r]) => {
|
|
621
|
-
const i = Z(t[n], r);
|
|
622
|
-
i.length && (t[n] = i);
|
|
623
|
-
}), t), {});
|
|
624
|
-
}
|
|
625
|
-
function Ot(e) {
|
|
626
|
-
const t = xt(e);
|
|
627
|
-
return Math.sqrt(
|
|
628
|
-
[0.299, 0.587, 0.114].reduce((s, n, r) => {
|
|
629
|
-
const i = parseInt(t.slice(1 + r * 2, 1 + (r + 1) * 2), 16);
|
|
630
|
-
return s + i * i * n;
|
|
631
|
-
}, 0)
|
|
632
|
-
) < 120;
|
|
633
|
-
}
|
|
634
|
-
class Ie {
|
|
635
|
-
constructor(t) {
|
|
636
|
-
c(this, "ee", new k()), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this.state = t;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Clones current state and returns its copy.
|
|
640
|
-
*/
|
|
641
|
-
clone() {
|
|
642
|
-
return { ...this.state };
|
|
643
|
-
}
|
|
644
|
-
set(t, s) {
|
|
645
|
-
Object.entries(typeof t == "string" ? { [t]: s } : t).reduce((n, [r, i]) => this.state[r] === i || i === void 0 ? n : (this.state[r] = i, this.ee.emit(`change:${r}`, i), !0), !1) && this.ee.emit("change", this.state);
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Returns value by specified key.
|
|
649
|
-
* @param key - state key.
|
|
650
|
-
*/
|
|
651
|
-
get(t) {
|
|
652
|
-
return this.state[t];
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
class rt {
|
|
656
|
-
constructor(t) {
|
|
657
|
-
c(this, "state"), c(this, "get"), c(this, "set"), c(this, "clone"), this.state = new Ie(t), this.set = this.state.set.bind(this.state), this.get = this.state.get.bind(this.state), this.clone = this.state.clone.bind(this.state);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
function Nt(e, t) {
|
|
661
|
-
return (s) => x(t[s], e);
|
|
662
|
-
}
|
|
663
|
-
class it extends rt {
|
|
664
|
-
constructor(t, s, n) {
|
|
665
|
-
super(t), c(this, "supports"), this.supports = Nt(s, n);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
class ke extends it {
|
|
669
|
-
constructor(t, s, n) {
|
|
670
|
-
super({ isVisible: t }, s, {
|
|
671
|
-
show: "web_app_setup_back_button",
|
|
672
|
-
hide: "web_app_setup_back_button"
|
|
673
|
-
}), c(this, "on", (r, i) => r === "click" ? v("back_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? H("back_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
|
|
674
|
-
}
|
|
675
|
-
set isVisible(t) {
|
|
676
|
-
this.set("isVisible", t), this.postEvent("web_app_setup_back_button", { is_visible: t });
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* True if BackButton is currently visible.
|
|
680
|
-
*/
|
|
681
|
-
get isVisible() {
|
|
682
|
-
return this.get("isVisible");
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Hides the BackButton.
|
|
686
|
-
*/
|
|
687
|
-
hide() {
|
|
688
|
-
this.isVisible = !1;
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Shows the BackButton.
|
|
692
|
-
*/
|
|
693
|
-
show() {
|
|
694
|
-
this.isVisible = !0;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
const Dt = T((e) => e instanceof Date ? e : new Date(P().parse(e) * 1e3), "Date");
|
|
698
|
-
function ot(e, t) {
|
|
699
|
-
return new L((s) => {
|
|
700
|
-
if (typeof s != "string" && !(s instanceof URLSearchParams))
|
|
701
|
-
throw S();
|
|
702
|
-
const n = typeof s == "string" ? new URLSearchParams(s) : s;
|
|
703
|
-
return Pt(e, (r) => {
|
|
704
|
-
const i = n.get(r);
|
|
705
|
-
return i === null ? void 0 : i;
|
|
706
|
-
});
|
|
707
|
-
}, !1, t);
|
|
708
|
-
}
|
|
709
|
-
const qe = f({
|
|
710
|
-
id: P(),
|
|
711
|
-
type: p(),
|
|
712
|
-
title: p(),
|
|
713
|
-
photoUrl: {
|
|
714
|
-
type: p().optional(),
|
|
715
|
-
from: "photo_url"
|
|
716
|
-
},
|
|
717
|
-
username: p().optional()
|
|
718
|
-
}, "Chat").optional(), ft = f({
|
|
719
|
-
addedToAttachmentMenu: {
|
|
720
|
-
type: y().optional(),
|
|
721
|
-
from: "added_to_attachment_menu"
|
|
722
|
-
},
|
|
723
|
-
allowsWriteToPm: {
|
|
724
|
-
type: y().optional(),
|
|
725
|
-
from: "allows_write_to_pm"
|
|
726
|
-
},
|
|
727
|
-
firstName: {
|
|
728
|
-
type: p(),
|
|
729
|
-
from: "first_name"
|
|
730
|
-
},
|
|
731
|
-
id: P(),
|
|
732
|
-
isBot: {
|
|
733
|
-
type: y().optional(),
|
|
734
|
-
from: "is_bot"
|
|
735
|
-
},
|
|
736
|
-
isPremium: {
|
|
737
|
-
type: y().optional(),
|
|
738
|
-
from: "is_premium"
|
|
739
|
-
},
|
|
740
|
-
languageCode: {
|
|
741
|
-
type: p().optional(),
|
|
742
|
-
from: "language_code"
|
|
743
|
-
},
|
|
744
|
-
lastName: {
|
|
745
|
-
type: p().optional(),
|
|
746
|
-
from: "last_name"
|
|
747
|
-
},
|
|
748
|
-
photoUrl: {
|
|
749
|
-
type: p().optional(),
|
|
750
|
-
from: "photo_url"
|
|
751
|
-
},
|
|
752
|
-
username: p().optional()
|
|
753
|
-
}, "User").optional();
|
|
754
|
-
function Vt() {
|
|
755
|
-
return ot({
|
|
756
|
-
authDate: {
|
|
757
|
-
type: Dt(),
|
|
758
|
-
from: "auth_date"
|
|
759
|
-
},
|
|
760
|
-
canSendAfter: {
|
|
761
|
-
type: P().optional(),
|
|
762
|
-
from: "can_send_after"
|
|
763
|
-
},
|
|
764
|
-
chat: qe,
|
|
765
|
-
chatInstance: {
|
|
766
|
-
type: p().optional(),
|
|
767
|
-
from: "chat_instance"
|
|
768
|
-
},
|
|
769
|
-
chatType: {
|
|
770
|
-
type: p().optional(),
|
|
771
|
-
from: "chat_type"
|
|
772
|
-
},
|
|
773
|
-
hash: p(),
|
|
774
|
-
queryId: {
|
|
775
|
-
type: p().optional(),
|
|
776
|
-
from: "query_id"
|
|
777
|
-
},
|
|
778
|
-
receiver: ft,
|
|
779
|
-
startParam: {
|
|
780
|
-
type: p().optional(),
|
|
781
|
-
from: "start_param"
|
|
782
|
-
},
|
|
783
|
-
user: ft
|
|
784
|
-
}, "InitData");
|
|
785
|
-
}
|
|
786
|
-
function Oe(e) {
|
|
787
|
-
return e.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
|
|
788
|
-
}
|
|
789
|
-
function Ne(e) {
|
|
790
|
-
return e.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
|
|
791
|
-
}
|
|
792
|
-
const Mt = T(
|
|
793
|
-
(e) => {
|
|
794
|
-
const t = Ct().optional();
|
|
795
|
-
return Object.entries(et(e)).reduce((s, [n, r]) => (s[Oe(n)] = t.parse(r), s), {});
|
|
796
|
-
},
|
|
797
|
-
"ThemeParams"
|
|
798
|
-
);
|
|
799
|
-
function at(e) {
|
|
800
|
-
return ot({
|
|
801
|
-
botInline: {
|
|
802
|
-
type: y().optional(),
|
|
803
|
-
from: "tgWebAppBotInline"
|
|
804
|
-
},
|
|
805
|
-
initData: {
|
|
806
|
-
type: Vt().optional(),
|
|
807
|
-
from: "tgWebAppData"
|
|
808
|
-
},
|
|
809
|
-
initDataRaw: {
|
|
810
|
-
type: p().optional(),
|
|
811
|
-
from: "tgWebAppData"
|
|
812
|
-
},
|
|
813
|
-
platform: {
|
|
814
|
-
type: p(),
|
|
815
|
-
from: "tgWebAppPlatform"
|
|
816
|
-
},
|
|
817
|
-
showSettings: {
|
|
818
|
-
type: y().optional(),
|
|
819
|
-
from: "tgWebAppShowSettings"
|
|
820
|
-
},
|
|
821
|
-
startParam: {
|
|
822
|
-
type: p().optional(),
|
|
823
|
-
from: "tgWebAppStartParam"
|
|
824
|
-
},
|
|
825
|
-
themeParams: {
|
|
826
|
-
type: Mt(),
|
|
827
|
-
from: "tgWebAppThemeParams"
|
|
828
|
-
},
|
|
829
|
-
version: {
|
|
830
|
-
type: p(),
|
|
831
|
-
from: "tgWebAppVersion"
|
|
832
|
-
}
|
|
833
|
-
}).parse(e);
|
|
834
|
-
}
|
|
835
|
-
function Bt(e) {
|
|
836
|
-
return at(
|
|
837
|
-
e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&")
|
|
838
|
-
);
|
|
839
|
-
}
|
|
840
|
-
function De() {
|
|
841
|
-
return Bt(window.location.href);
|
|
842
|
-
}
|
|
843
|
-
function $t() {
|
|
844
|
-
return performance.getEntriesByType("navigation")[0];
|
|
845
|
-
}
|
|
846
|
-
function Ve() {
|
|
847
|
-
const e = $t();
|
|
848
|
-
if (!e)
|
|
849
|
-
throw new Error("Unable to get first navigation entry.");
|
|
850
|
-
return Bt(e.name);
|
|
851
|
-
}
|
|
852
|
-
function Lt(e) {
|
|
853
|
-
return `tma.js/${e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`)}`;
|
|
854
|
-
}
|
|
855
|
-
function Ut(e, t) {
|
|
856
|
-
sessionStorage.setItem(Lt(e), JSON.stringify(t));
|
|
857
|
-
}
|
|
858
|
-
function Ht(e) {
|
|
859
|
-
const t = sessionStorage.getItem(Lt(e));
|
|
860
|
-
try {
|
|
861
|
-
return t ? JSON.parse(t) : void 0;
|
|
862
|
-
} catch {
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
function Me() {
|
|
866
|
-
return at(Ht("launchParams") || "");
|
|
867
|
-
}
|
|
868
|
-
function Wt(e) {
|
|
869
|
-
return JSON.stringify(
|
|
870
|
-
Object.fromEntries(
|
|
871
|
-
Object.entries(e).map(([t, s]) => [Ne(t), s])
|
|
872
|
-
)
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
function Be(e) {
|
|
876
|
-
const {
|
|
877
|
-
initDataRaw: t,
|
|
878
|
-
themeParams: s,
|
|
879
|
-
platform: n,
|
|
880
|
-
version: r,
|
|
881
|
-
showSettings: i,
|
|
882
|
-
startParam: o,
|
|
883
|
-
botInline: a
|
|
884
|
-
} = e, h = new URLSearchParams();
|
|
885
|
-
return h.set("tgWebAppPlatform", n), h.set("tgWebAppThemeParams", Wt(s)), h.set("tgWebAppVersion", r), t && h.set("tgWebAppData", t), o && h.set("tgWebAppStartParam", o), typeof i == "boolean" && h.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && h.set("tgWebAppBotInline", a ? "1" : "0"), h.toString();
|
|
886
|
-
}
|
|
887
|
-
function jt(e) {
|
|
888
|
-
Ut("launchParams", Be(e));
|
|
889
|
-
}
|
|
890
|
-
function $e() {
|
|
891
|
-
for (const e of [
|
|
892
|
-
// Try to retrieve launch parameters from the current location. This method can return
|
|
893
|
-
// nothing in case, location was changed and then page was reloaded.
|
|
894
|
-
De,
|
|
895
|
-
// Then, try using the lower level API - window.performance.
|
|
896
|
-
Ve,
|
|
897
|
-
// Finally, try to extract launch parameters from the session storage.
|
|
898
|
-
Me
|
|
899
|
-
])
|
|
900
|
-
try {
|
|
901
|
-
const t = e();
|
|
902
|
-
return jt(t), t;
|
|
903
|
-
} catch {
|
|
904
|
-
}
|
|
905
|
-
throw new Error("Unable to retrieve launch parameters from any known source.");
|
|
906
|
-
}
|
|
907
|
-
function Gt() {
|
|
908
|
-
const e = $t();
|
|
909
|
-
return !!(e && e.type === "reload");
|
|
910
|
-
}
|
|
911
|
-
function Le() {
|
|
912
|
-
let e = 0;
|
|
913
|
-
return () => (e += 1).toString();
|
|
914
|
-
}
|
|
915
|
-
const [Ue] = vt(Le);
|
|
916
|
-
function d(e, t) {
|
|
917
|
-
return () => {
|
|
918
|
-
const s = $e(), n = {
|
|
919
|
-
...s,
|
|
920
|
-
postEvent: Ae(s.version),
|
|
921
|
-
createRequestId: Ue()
|
|
922
|
-
};
|
|
923
|
-
if (typeof e == "function")
|
|
924
|
-
return e(n);
|
|
925
|
-
const [r, i, o] = tt(), a = t({
|
|
926
|
-
...n,
|
|
927
|
-
// State should only be passed only in case, current page was reloaded. If we don't add
|
|
928
|
-
// this check, state restoration will work improperly in the web version of Telegram,
|
|
929
|
-
// when we are always working in the same "session" (tab).
|
|
930
|
-
state: Gt() ? Ht(e) : void 0,
|
|
931
|
-
addCleanup: r
|
|
932
|
-
}), h = (u) => (o || r(
|
|
933
|
-
u.on("change", (l) => {
|
|
934
|
-
Ut(e, l);
|
|
935
|
-
})
|
|
936
|
-
), u);
|
|
937
|
-
return [
|
|
938
|
-
a instanceof Promise ? a.then(h) : h(a),
|
|
939
|
-
i
|
|
940
|
-
];
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
const He = d("backButton", ({
|
|
944
|
-
postEvent: e,
|
|
945
|
-
version: t,
|
|
946
|
-
state: s = { isVisible: !1 }
|
|
947
|
-
}) => new ke(s.isVisible, t, e));
|
|
948
|
-
class D extends it {
|
|
949
|
-
constructor() {
|
|
950
|
-
super(...arguments), c(this, "on", this.state.on.bind(this.state)), c(this, "off", this.state.off.bind(this.state));
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
function Kt(e) {
|
|
954
|
-
const t = e.available ? e : {
|
|
955
|
-
available: !1,
|
|
956
|
-
device_id: "",
|
|
957
|
-
token_saved: !1,
|
|
958
|
-
access_requested: !1,
|
|
959
|
-
access_granted: !1,
|
|
960
|
-
type: ""
|
|
961
|
-
};
|
|
962
|
-
return {
|
|
963
|
-
available: !0,
|
|
964
|
-
type: t.type,
|
|
965
|
-
deviceId: t.device_id,
|
|
966
|
-
tokenSaved: t.token_saved,
|
|
967
|
-
accessRequested: t.access_requested,
|
|
968
|
-
accessGranted: t.access_granted
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
class We extends D {
|
|
972
|
-
constructor({ postEvent: t, version: s, ...n }) {
|
|
973
|
-
super(n, s, {
|
|
974
|
-
auth: "web_app_biometry_request_auth",
|
|
975
|
-
openSettings: "web_app_biometry_open_settings",
|
|
976
|
-
requestAccess: "web_app_biometry_request_access",
|
|
977
|
-
updateToken: "web_app_biometry_update_token"
|
|
978
|
-
}), c(this, "postEvent"), c(this, "authPromise"), c(this, "accessPromise"), this.postEvent = t;
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* Shows whether biometry is available.
|
|
982
|
-
*/
|
|
983
|
-
get available() {
|
|
984
|
-
return this.get("available");
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Shows whether permission to use biometrics has been granted.
|
|
988
|
-
*/
|
|
989
|
-
get accessGranted() {
|
|
990
|
-
return this.get("accessGranted");
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Shows whether if permission to use biometrics has been requested.
|
|
994
|
-
*/
|
|
995
|
-
get accessRequested() {
|
|
996
|
-
return this.get("accessRequested");
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Authenticates the user using biometrics.
|
|
1000
|
-
* @param options - method options.
|
|
1001
|
-
* @since 7.2
|
|
1002
|
-
* @returns Token from the local secure storage, if authentication was successful.
|
|
1003
|
-
*/
|
|
1004
|
-
async authenticate({
|
|
1005
|
-
reason: t,
|
|
1006
|
-
...s
|
|
1007
|
-
}) {
|
|
1008
|
-
return this.authPromise || (this.authPromise = w({
|
|
1009
|
-
...s,
|
|
1010
|
-
method: "web_app_biometry_request_auth",
|
|
1011
|
-
event: "biometry_auth_requested",
|
|
1012
|
-
postEvent: this.postEvent,
|
|
1013
|
-
params: {
|
|
1014
|
-
// TODO: Check if reason is empty works fine.
|
|
1015
|
-
reason: (t || "").trim()
|
|
1016
|
-
}
|
|
1017
|
-
}).then(({ token: n }) => n).finally(() => this.authPromise = void 0)), this.authPromise;
|
|
1018
|
-
}
|
|
1019
|
-
/**
|
|
1020
|
-
* A unique device identifier that can be used to match the token to the device.
|
|
1021
|
-
*/
|
|
1022
|
-
get deviceId() {
|
|
1023
|
-
return this.get("deviceId");
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* Opens the biometric access settings for bots. Useful when you need to request biometrics
|
|
1027
|
-
* access to users who haven't granted it yet.
|
|
1028
|
-
*
|
|
1029
|
-
* _Note that this method can be called only in response to user interaction with the Mini App
|
|
1030
|
-
* interface (e.g. a click inside the Mini App or on the main button)_.
|
|
1031
|
-
* @since 7.2
|
|
1032
|
-
*/
|
|
1033
|
-
openSettings() {
|
|
1034
|
-
this.postEvent("web_app_biometry_open_settings");
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Requests permission to use biometrics.
|
|
1038
|
-
* @since 7.2
|
|
1039
|
-
* @returns Promise with true, if access was granted.
|
|
1040
|
-
*/
|
|
1041
|
-
requestAccess({ reason: t, ...s } = {}) {
|
|
1042
|
-
return this.accessPromise || (this.accessPromise = w({
|
|
1043
|
-
...s,
|
|
1044
|
-
postEvent: this.postEvent,
|
|
1045
|
-
method: "web_app_biometry_request_access",
|
|
1046
|
-
event: "biometry_info_received",
|
|
1047
|
-
params: { reason: t || "" }
|
|
1048
|
-
}).then((n) => {
|
|
1049
|
-
const r = Kt(n);
|
|
1050
|
-
return this.set(r), r.accessGranted;
|
|
1051
|
-
}).finally(() => this.accessPromise = void 0)), this.accessPromise;
|
|
1052
|
-
}
|
|
1053
|
-
/**
|
|
1054
|
-
* The type of biometrics currently available on the device.
|
|
1055
|
-
*/
|
|
1056
|
-
get biometryType() {
|
|
1057
|
-
return this.get("biometryType");
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Shows whether token was saved previously in the local secure storage.
|
|
1061
|
-
*/
|
|
1062
|
-
get tokenSaved() {
|
|
1063
|
-
return this.get("tokenSaved");
|
|
1064
|
-
}
|
|
1065
|
-
/**
|
|
1066
|
-
* Updates the biometric token in a secure storage on the device.
|
|
1067
|
-
* @returns Promise with `true`, if token was updated.
|
|
1068
|
-
*/
|
|
1069
|
-
async updateToken({ token: t, ...s } = {}) {
|
|
1070
|
-
return ["removed", "updated"].includes(
|
|
1071
|
-
(await w({
|
|
1072
|
-
...s,
|
|
1073
|
-
postEvent: this.postEvent,
|
|
1074
|
-
method: "web_app_biometry_update_token",
|
|
1075
|
-
event: "biometry_token_updated",
|
|
1076
|
-
params: { token: t || "" }
|
|
1077
|
-
})).status
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
async function je(e) {
|
|
1082
|
-
return Kt(
|
|
1083
|
-
await w({
|
|
1084
|
-
...e || {},
|
|
1085
|
-
method: "web_app_biometry_get_info",
|
|
1086
|
-
event: "biometry_info_received"
|
|
1087
|
-
})
|
|
1088
|
-
);
|
|
1089
|
-
}
|
|
1090
|
-
const Ge = d(
|
|
1091
|
-
"biometryManager",
|
|
1092
|
-
async ({ postEvent: e, version: t, state: s }) => new We({
|
|
1093
|
-
...s || x("web_app_biometry_get_info", t) ? s || await je({ timeout: 1e3 }) : {
|
|
1094
|
-
available: !1,
|
|
1095
|
-
accessGranted: !1,
|
|
1096
|
-
accessRequested: !1,
|
|
1097
|
-
tokenSaved: !1,
|
|
1098
|
-
deviceId: ""
|
|
1099
|
-
},
|
|
1100
|
-
version: t,
|
|
1101
|
-
postEvent: e
|
|
1102
|
-
})
|
|
1103
|
-
);
|
|
1104
|
-
class ct extends rt {
|
|
1105
|
-
constructor() {
|
|
1106
|
-
super(...arguments), c(this, "on", this.state.on.bind(this.state)), c(this, "off", this.state.off.bind(this.state));
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
class Ke extends ct {
|
|
1110
|
-
constructor(t, s) {
|
|
1111
|
-
super({ isConfirmationNeeded: t }), this.postEvent = s;
|
|
1112
|
-
}
|
|
1113
|
-
set isConfirmationNeeded(t) {
|
|
1114
|
-
this.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* True, if the confirmation dialog should be shown while the user is trying to close
|
|
1118
|
-
* the Mini App.
|
|
1119
|
-
*/
|
|
1120
|
-
get isConfirmationNeeded() {
|
|
1121
|
-
return this.get("isConfirmationNeeded");
|
|
1122
|
-
}
|
|
1123
|
-
/**
|
|
1124
|
-
* Disables the confirmation dialog when closing the Mini App.
|
|
1125
|
-
*/
|
|
1126
|
-
disableConfirmation() {
|
|
1127
|
-
this.isConfirmationNeeded = !1;
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* Enables the confirmation dialog when closing the Mini App.
|
|
1131
|
-
*/
|
|
1132
|
-
enableConfirmation() {
|
|
1133
|
-
this.isConfirmationNeeded = !0;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
const ze = d(
|
|
1137
|
-
"closingBehavior",
|
|
1138
|
-
({
|
|
1139
|
-
postEvent: e,
|
|
1140
|
-
state: t = { isConfirmationNeeded: !1 }
|
|
1141
|
-
}) => new Ke(t.isConfirmationNeeded, e)
|
|
1142
|
-
);
|
|
1143
|
-
class ht {
|
|
1144
|
-
constructor(t, s) {
|
|
1145
|
-
c(this, "supports"), this.supports = Nt(t, s);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
function Je(e) {
|
|
1149
|
-
if (Array.isArray(e))
|
|
1150
|
-
return e;
|
|
1151
|
-
if (typeof e == "string")
|
|
1152
|
-
try {
|
|
1153
|
-
const t = JSON.parse(e);
|
|
1154
|
-
if (Array.isArray(t))
|
|
1155
|
-
return t;
|
|
1156
|
-
} catch {
|
|
1157
|
-
}
|
|
1158
|
-
throw S();
|
|
1159
|
-
}
|
|
1160
|
-
class Fe extends L {
|
|
1161
|
-
constructor(t, s, n) {
|
|
1162
|
-
super(Je, s, n), c(this, "itemParser"), this.itemParser = typeof t == "function" ? t : t.parse.bind(t);
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Attempts to parse passed value
|
|
1166
|
-
* @param value - value to parse.
|
|
1167
|
-
* @throws {SDKError} ERR_PARSE
|
|
1168
|
-
* @see ERR_PARSE
|
|
1169
|
-
*/
|
|
1170
|
-
parse(t) {
|
|
1171
|
-
const s = super.parse(t);
|
|
1172
|
-
return s === void 0 ? s : s.map(this.itemParser);
|
|
1173
|
-
}
|
|
1174
|
-
of(t) {
|
|
1175
|
-
return this.itemParser = typeof t == "function" ? t : t.parse.bind(t), this;
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
function Qe(e) {
|
|
1179
|
-
return new Fe((t) => t, !1, e);
|
|
1180
|
-
}
|
|
1181
|
-
function wt(e, t) {
|
|
1182
|
-
return Object.fromEntries(e.map((s) => [s, t]));
|
|
1183
|
-
}
|
|
1184
|
-
class Ye extends ht {
|
|
1185
|
-
constructor(t, s, n) {
|
|
1186
|
-
super(t, {
|
|
1187
|
-
delete: "web_app_invoke_custom_method",
|
|
1188
|
-
get: "web_app_invoke_custom_method",
|
|
1189
|
-
getKeys: "web_app_invoke_custom_method",
|
|
1190
|
-
set: "web_app_invoke_custom_method"
|
|
1191
|
-
}), this.createRequestId = s, this.postEvent = n;
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Deletes specified key or keys from the cloud storage.
|
|
1195
|
-
* @param keyOrKeys - key or keys to delete.
|
|
1196
|
-
* @param options - request execution options.
|
|
1197
|
-
*/
|
|
1198
|
-
async delete(t, s = {}) {
|
|
1199
|
-
const n = Array.isArray(t) ? t : [t];
|
|
1200
|
-
n.length && await A(
|
|
1201
|
-
"deleteStorageValues",
|
|
1202
|
-
{ keys: n },
|
|
1203
|
-
this.createRequestId(),
|
|
1204
|
-
{ ...s, postEvent: this.postEvent }
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Returns list of all keys presented in the cloud storage.
|
|
1209
|
-
* @param options - request execution options.
|
|
1210
|
-
*/
|
|
1211
|
-
async getKeys(t = {}) {
|
|
1212
|
-
return Qe().of(p()).parse(
|
|
1213
|
-
await A(
|
|
1214
|
-
"getStorageKeys",
|
|
1215
|
-
{},
|
|
1216
|
-
this.createRequestId(),
|
|
1217
|
-
{ ...t, postEvent: this.postEvent }
|
|
1218
|
-
)
|
|
1219
|
-
);
|
|
1220
|
-
}
|
|
1221
|
-
async get(t, s = {}) {
|
|
1222
|
-
const n = Array.isArray(t) ? t : [t];
|
|
1223
|
-
if (!n.length)
|
|
1224
|
-
return wt(n, "");
|
|
1225
|
-
const r = await A(
|
|
1226
|
-
"getStorageValues",
|
|
1227
|
-
{ keys: n },
|
|
1228
|
-
this.createRequestId(),
|
|
1229
|
-
{ ...s, postEvent: this.postEvent }
|
|
1230
|
-
), i = f(wt(n, p()), "CloudStorageData").parse(r);
|
|
1231
|
-
return Array.isArray(t) ? i : i[t];
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Saves specified value by key.
|
|
1235
|
-
* @param key - storage key.
|
|
1236
|
-
* @param value - storage value.
|
|
1237
|
-
* @param options - request execution options.
|
|
1238
|
-
*/
|
|
1239
|
-
async set(t, s, n = {}) {
|
|
1240
|
-
await A(
|
|
1241
|
-
"saveStorageValue",
|
|
1242
|
-
{ key: t, value: s },
|
|
1243
|
-
this.createRequestId(),
|
|
1244
|
-
{ ...n, postEvent: this.postEvent }
|
|
1245
|
-
);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
const Ze = d(
|
|
1249
|
-
({ createRequestId: e, postEvent: t, version: s }) => new Ye(s, e, t)
|
|
1250
|
-
);
|
|
1251
|
-
class Xe extends ht {
|
|
1252
|
-
constructor(t, s) {
|
|
1253
|
-
super(t, {
|
|
1254
|
-
impactOccurred: "web_app_trigger_haptic_feedback",
|
|
1255
|
-
notificationOccurred: "web_app_trigger_haptic_feedback",
|
|
1256
|
-
selectionChanged: "web_app_trigger_haptic_feedback"
|
|
1257
|
-
}), this.postEvent = s;
|
|
1258
|
-
}
|
|
1259
|
-
/**
|
|
1260
|
-
* A method tells that an impact occurred. The Telegram app may play the
|
|
1261
|
-
* appropriate haptics based on style value passed.
|
|
1262
|
-
* @param style - impact style.
|
|
1263
|
-
*/
|
|
1264
|
-
impactOccurred(t) {
|
|
1265
|
-
this.postEvent("web_app_trigger_haptic_feedback", {
|
|
1266
|
-
type: "impact",
|
|
1267
|
-
impact_style: t
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
/**
|
|
1271
|
-
* A method tells that a task or action has succeeded, failed, or produced
|
|
1272
|
-
* a warning. The Telegram app may play the appropriate haptics based on
|
|
1273
|
-
* type value passed.
|
|
1274
|
-
* @param type - notification type.
|
|
1275
|
-
*/
|
|
1276
|
-
notificationOccurred(t) {
|
|
1277
|
-
this.postEvent("web_app_trigger_haptic_feedback", {
|
|
1278
|
-
type: "notification",
|
|
1279
|
-
notification_type: t
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
/**
|
|
1283
|
-
* A method tells that the user has changed a selection. The Telegram app
|
|
1284
|
-
* may play the appropriate haptics.
|
|
1285
|
-
*
|
|
1286
|
-
* Do not use this feedback when the user makes or confirms a selection;
|
|
1287
|
-
* use it only when the selection changes.
|
|
1288
|
-
*/
|
|
1289
|
-
selectionChanged() {
|
|
1290
|
-
this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
const ts = d(
|
|
1294
|
-
({ version: e, postEvent: t }) => new Xe(e, t)
|
|
1295
|
-
);
|
|
1296
|
-
class es {
|
|
1297
|
-
constructor(t) {
|
|
1298
|
-
this.initData = t;
|
|
1299
|
-
}
|
|
1300
|
-
/**
|
|
1301
|
-
* @see InitDataParsed.authDate
|
|
1302
|
-
*/
|
|
1303
|
-
get authDate() {
|
|
1304
|
-
return this.initData.authDate;
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* @see InitDataParsed.canSendAfter
|
|
1308
|
-
*/
|
|
1309
|
-
get canSendAfter() {
|
|
1310
|
-
return this.initData.canSendAfter;
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Date after which it is allowed to call
|
|
1314
|
-
* the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
|
|
1315
|
-
*/
|
|
1316
|
-
get canSendAfterDate() {
|
|
1317
|
-
const { canSendAfter: t } = this;
|
|
1318
|
-
return t ? new Date(this.authDate.getTime() + t * 1e3) : void 0;
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* @see InitDataParsed.chat
|
|
1322
|
-
*/
|
|
1323
|
-
get chat() {
|
|
1324
|
-
return this.initData.chat;
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* @see InitDataParsed.chatType
|
|
1328
|
-
*/
|
|
1329
|
-
get chatType() {
|
|
1330
|
-
return this.initData.chatType;
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* @see InitDataParsed.chatInstance
|
|
1334
|
-
*/
|
|
1335
|
-
get chatInstance() {
|
|
1336
|
-
return this.initData.chatInstance;
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* @see InitDataParsed.hash
|
|
1340
|
-
*/
|
|
1341
|
-
get hash() {
|
|
1342
|
-
return this.initData.hash;
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* @see InitDataParsed.queryId
|
|
1346
|
-
*/
|
|
1347
|
-
get queryId() {
|
|
1348
|
-
return this.initData.queryId;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* @see InitDataParsed.receiver
|
|
1352
|
-
*/
|
|
1353
|
-
get receiver() {
|
|
1354
|
-
return this.initData.receiver;
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* @see InitDataParsed.startParam
|
|
1358
|
-
*/
|
|
1359
|
-
get startParam() {
|
|
1360
|
-
return this.initData.startParam;
|
|
1361
|
-
}
|
|
1362
|
-
/**
|
|
1363
|
-
* @see InitDataParsed.user
|
|
1364
|
-
*/
|
|
1365
|
-
get user() {
|
|
1366
|
-
return this.initData.user;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
const ss = d(
|
|
1370
|
-
({ initData: e }) => e ? new es(e) : void 0
|
|
1371
|
-
);
|
|
1372
|
-
function Ys(e) {
|
|
1373
|
-
return Vt().parse(e);
|
|
1374
|
-
}
|
|
1375
|
-
class ns extends D {
|
|
1376
|
-
constructor(t, s, n) {
|
|
1377
|
-
super({ isOpened: t }, s, { open: "web_app_open_invoice" }), this.postEvent = n;
|
|
1378
|
-
}
|
|
1379
|
-
set isOpened(t) {
|
|
1380
|
-
this.set("isOpened", t);
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* True if invoice is currently opened.
|
|
1384
|
-
*/
|
|
1385
|
-
get isOpened() {
|
|
1386
|
-
return this.get("isOpened");
|
|
1387
|
-
}
|
|
1388
|
-
async open(t, s) {
|
|
1389
|
-
if (this.isOpened)
|
|
1390
|
-
throw new Error("Invoice is already opened");
|
|
1391
|
-
let n;
|
|
1392
|
-
if (!s)
|
|
1393
|
-
n = t;
|
|
1394
|
-
else {
|
|
1395
|
-
const { hostname: r, pathname: i } = new URL(t, window.location.href);
|
|
1396
|
-
if (r !== "t.me")
|
|
1397
|
-
throw new Error(`Incorrect hostname: ${r}`);
|
|
1398
|
-
const o = i.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
1399
|
-
if (!o)
|
|
1400
|
-
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
|
|
1401
|
-
[, , n] = o;
|
|
1402
|
-
}
|
|
1403
|
-
this.isOpened = !0;
|
|
1404
|
-
try {
|
|
1405
|
-
return (await w({
|
|
1406
|
-
method: "web_app_open_invoice",
|
|
1407
|
-
event: "invoice_closed",
|
|
1408
|
-
params: { slug: n },
|
|
1409
|
-
postEvent: this.postEvent,
|
|
1410
|
-
capture(r) {
|
|
1411
|
-
return n === r.slug;
|
|
1412
|
-
}
|
|
1413
|
-
})).status;
|
|
1414
|
-
} finally {
|
|
1415
|
-
this.isOpened = !1;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
const rs = d(
|
|
1420
|
-
({ version: e, postEvent: t }) => new ns(!1, e, t)
|
|
1421
|
-
);
|
|
1422
|
-
class is extends rt {
|
|
1423
|
-
constructor({ postEvent: t, ...s }) {
|
|
1424
|
-
super(s), c(this, "postEvent"), c(this, "on", (n, r) => n === "click" ? v("main_button_pressed", r) : this.state.on(n, r)), c(this, "off", (n, r) => n === "click" ? H("main_button_pressed", r) : this.state.off(n, r)), this.postEvent = t;
|
|
1425
|
-
}
|
|
1426
|
-
/**
|
|
1427
|
-
* The MainButton background color.
|
|
1428
|
-
*/
|
|
1429
|
-
get bgColor() {
|
|
1430
|
-
return this.get("bgColor");
|
|
1431
|
-
}
|
|
1432
|
-
/**
|
|
1433
|
-
* Sends current local state to the Telegram application.
|
|
1434
|
-
*/
|
|
1435
|
-
commit() {
|
|
1436
|
-
this.text !== "" && this.postEvent("web_app_setup_main_button", {
|
|
1437
|
-
is_visible: this.isVisible,
|
|
1438
|
-
is_active: this.isEnabled,
|
|
1439
|
-
is_progress_visible: this.isLoaderVisible,
|
|
1440
|
-
text: this.text,
|
|
1441
|
-
color: this.bgColor,
|
|
1442
|
-
text_color: this.textColor
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* Disables the MainButton.
|
|
1447
|
-
* @see Does not work on Android: https://github.com/Telegram-Mini-Apps/issues/issues/1
|
|
1448
|
-
*/
|
|
1449
|
-
disable() {
|
|
1450
|
-
return this.isEnabled = !1, this;
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Enables the MainButton.
|
|
1454
|
-
*/
|
|
1455
|
-
enable() {
|
|
1456
|
-
return this.isEnabled = !0, this;
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* Hides the MainButton.
|
|
1460
|
-
*/
|
|
1461
|
-
hide() {
|
|
1462
|
-
return this.isVisible = !1, this;
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* Hides the MainButton loading indicator.
|
|
1466
|
-
*/
|
|
1467
|
-
hideLoader() {
|
|
1468
|
-
return this.isLoaderVisible = !1, this;
|
|
1469
|
-
}
|
|
1470
|
-
set isEnabled(t) {
|
|
1471
|
-
this.setParams({ isEnabled: t });
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* True if the MainButton is enabled.
|
|
1475
|
-
*/
|
|
1476
|
-
get isEnabled() {
|
|
1477
|
-
return this.get("isEnabled");
|
|
1478
|
-
}
|
|
1479
|
-
set isLoaderVisible(t) {
|
|
1480
|
-
this.setParams({ isLoaderVisible: t });
|
|
1481
|
-
}
|
|
1482
|
-
/**
|
|
1483
|
-
* True if the MainButton loader is visible.
|
|
1484
|
-
*/
|
|
1485
|
-
get isLoaderVisible() {
|
|
1486
|
-
return this.get("isLoaderVisible");
|
|
1487
|
-
}
|
|
1488
|
-
set isVisible(t) {
|
|
1489
|
-
this.setParams({ isVisible: t });
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* True if the MainButton is visible.
|
|
1493
|
-
*/
|
|
1494
|
-
get isVisible() {
|
|
1495
|
-
return this.get("isVisible");
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Shows the MainButton.
|
|
1499
|
-
*
|
|
1500
|
-
* Note that opening the Mini App from the attachment menu hides the main button until the
|
|
1501
|
-
* user interacts with the Mini App interface.
|
|
1502
|
-
*/
|
|
1503
|
-
show() {
|
|
1504
|
-
return this.isVisible = !0, this;
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Shows a loading indicator on the Main Button.
|
|
1508
|
-
*/
|
|
1509
|
-
showLoader() {
|
|
1510
|
-
return this.isLoaderVisible = !0, this;
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Sets a new MainButton text. Minimal length for the text is 1 symbol, and maximum is 64 symbols.
|
|
1514
|
-
* @param text - a new text.
|
|
1515
|
-
*/
|
|
1516
|
-
setText(t) {
|
|
1517
|
-
return this.setParams({ text: t });
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Sets a new Main Button text color.
|
|
1521
|
-
* @param textColor - new text color.
|
|
1522
|
-
*/
|
|
1523
|
-
setTextColor(t) {
|
|
1524
|
-
return this.setParams({ textColor: t });
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* Updates current Main Button color.
|
|
1528
|
-
* @param bgColor - color to set.
|
|
1529
|
-
*/
|
|
1530
|
-
setBgColor(t) {
|
|
1531
|
-
return this.setParams({ bgColor: t });
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Allows setting multiple Main Button parameters.
|
|
1535
|
-
* @param params - Main Button parameters.
|
|
1536
|
-
*/
|
|
1537
|
-
setParams(t) {
|
|
1538
|
-
return this.set(t), this.commit(), this;
|
|
1539
|
-
}
|
|
1540
|
-
/**
|
|
1541
|
-
* The MainButton text.
|
|
1542
|
-
*/
|
|
1543
|
-
get text() {
|
|
1544
|
-
return this.get("text");
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* The MainButton text color.
|
|
1548
|
-
*/
|
|
1549
|
-
get textColor() {
|
|
1550
|
-
return this.get("textColor");
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
const os = d(
|
|
1554
|
-
"mainButton",
|
|
1555
|
-
({
|
|
1556
|
-
postEvent: e,
|
|
1557
|
-
themeParams: t,
|
|
1558
|
-
state: s = {
|
|
1559
|
-
isVisible: !1,
|
|
1560
|
-
isEnabled: !1,
|
|
1561
|
-
text: "",
|
|
1562
|
-
isLoaderVisible: !1,
|
|
1563
|
-
textColor: t.buttonTextColor || "#ffffff",
|
|
1564
|
-
bgColor: t.buttonColor || "#000000"
|
|
1565
|
-
}
|
|
1566
|
-
}) => new is({ ...s, postEvent: e })
|
|
1567
|
-
);
|
|
1568
|
-
function as() {
|
|
1569
|
-
return ot({
|
|
1570
|
-
contact: f({
|
|
1571
|
-
userId: {
|
|
1572
|
-
type: P(),
|
|
1573
|
-
from: "user_id"
|
|
1574
|
-
},
|
|
1575
|
-
phoneNumber: {
|
|
1576
|
-
type: p(),
|
|
1577
|
-
from: "phone_number"
|
|
1578
|
-
},
|
|
1579
|
-
firstName: {
|
|
1580
|
-
type: p(),
|
|
1581
|
-
from: "first_name"
|
|
1582
|
-
},
|
|
1583
|
-
lastName: {
|
|
1584
|
-
type: p().optional(),
|
|
1585
|
-
from: "last_name"
|
|
1586
|
-
}
|
|
1587
|
-
}),
|
|
1588
|
-
authDate: {
|
|
1589
|
-
type: Dt(),
|
|
1590
|
-
from: "auth_date"
|
|
1591
|
-
},
|
|
1592
|
-
hash: p()
|
|
1593
|
-
}, "RequestedContact");
|
|
1594
|
-
}
|
|
1595
|
-
function zt(e, t) {
|
|
1596
|
-
return (s) => {
|
|
1597
|
-
const [n, r] = t[s];
|
|
1598
|
-
return x(n, r, e);
|
|
1599
|
-
};
|
|
1600
|
-
}
|
|
1601
|
-
function cs(e) {
|
|
1602
|
-
return new Promise((t) => {
|
|
1603
|
-
setTimeout(t, e);
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
class hs extends D {
|
|
1607
|
-
constructor({ postEvent: t, createRequestId: s, version: n, botInline: r, ...i }) {
|
|
1608
|
-
super(i, n, {
|
|
1609
|
-
requestPhoneAccess: "web_app_request_phone",
|
|
1610
|
-
requestWriteAccess: "web_app_request_write_access",
|
|
1611
|
-
switchInlineQuery: "web_app_switch_inline_query",
|
|
1612
|
-
setHeaderColor: "web_app_set_header_color",
|
|
1613
|
-
setBackgroundColor: "web_app_set_background_color"
|
|
1614
|
-
}), c(this, "botInline"), c(this, "postEvent"), c(this, "createRequestId"), c(this, "requestPhoneAccessPromise"), c(this, "requestWriteAccessPromise"), c(this, "supportsParam"), this.createRequestId = s, this.postEvent = t, this.botInline = r;
|
|
1615
|
-
const o = this.supports.bind(this);
|
|
1616
|
-
this.supports = (a) => o(a) ? a !== "switchInlineQuery" || r : !1, this.supportsParam = zt(n, {
|
|
1617
|
-
"setHeaderColor.color": ["web_app_set_header_color", "color"]
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* Attempts to get requested contact.
|
|
1622
|
-
* @param timeout - request timeout.
|
|
1623
|
-
*/
|
|
1624
|
-
async getRequestedContact({
|
|
1625
|
-
timeout: t = 1e4
|
|
1626
|
-
} = {}) {
|
|
1627
|
-
return as().parse(
|
|
1628
|
-
await A(
|
|
1629
|
-
"getRequestedContact",
|
|
1630
|
-
{},
|
|
1631
|
-
this.createRequestId(),
|
|
1632
|
-
{ postEvent: this.postEvent, timeout: t }
|
|
1633
|
-
)
|
|
1634
|
-
);
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* The Mini App background color.
|
|
1638
|
-
* @example "#ffaabb"
|
|
1639
|
-
*/
|
|
1640
|
-
get bgColor() {
|
|
1641
|
-
return this.get("bgColor");
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Closes the Mini App.
|
|
1645
|
-
*/
|
|
1646
|
-
close() {
|
|
1647
|
-
this.postEvent("web_app_close");
|
|
1648
|
-
}
|
|
1649
|
-
/**
|
|
1650
|
-
* The Mini App header color.
|
|
1651
|
-
* @example "#ffaabb"
|
|
1652
|
-
* @example "bg_color"
|
|
1653
|
-
*/
|
|
1654
|
-
get headerColor() {
|
|
1655
|
-
return this.get("headerColor");
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* True if the Mini App is currently launched in bot inline mode.
|
|
1659
|
-
*/
|
|
1660
|
-
get isBotInline() {
|
|
1661
|
-
return this.botInline;
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* True if current Mini App background color is recognized as dark.
|
|
1665
|
-
*/
|
|
1666
|
-
get isDark() {
|
|
1667
|
-
return Ot(this.bgColor);
|
|
1668
|
-
}
|
|
1669
|
-
/**
|
|
1670
|
-
* Informs the Telegram app that the Mini App is ready to be displayed.
|
|
1671
|
-
*
|
|
1672
|
-
* It is recommended to call this method as early as possible, as soon as all essential
|
|
1673
|
-
* interface elements loaded. Once this method called, the loading placeholder is hidden
|
|
1674
|
-
* and the Mini App shown.
|
|
1675
|
-
*
|
|
1676
|
-
* If the method not called, the placeholder will be hidden only when the page fully loaded.
|
|
1677
|
-
*/
|
|
1678
|
-
ready() {
|
|
1679
|
-
this.postEvent("web_app_ready");
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* Requests current user contact information. In contrary to requestPhoneAccess, this method
|
|
1683
|
-
* returns promise with contact information that rejects in case, user denied access, or request
|
|
1684
|
-
* failed.
|
|
1685
|
-
* @param options - additional options.
|
|
1686
|
-
*/
|
|
1687
|
-
async requestContact({ timeout: t = 5e3 } = {}) {
|
|
1688
|
-
try {
|
|
1689
|
-
return await this.getRequestedContact();
|
|
1690
|
-
} catch {
|
|
1691
|
-
}
|
|
1692
|
-
if (await this.requestPhoneAccess() !== "sent")
|
|
1693
|
-
throw new Error("Access denied.");
|
|
1694
|
-
const s = Date.now() + t;
|
|
1695
|
-
let n = 50;
|
|
1696
|
-
return qt(async () => {
|
|
1697
|
-
for (; Date.now() < s; ) {
|
|
1698
|
-
try {
|
|
1699
|
-
return await this.getRequestedContact();
|
|
1700
|
-
} catch {
|
|
1701
|
-
}
|
|
1702
|
-
await cs(n), n += 50;
|
|
1703
|
-
}
|
|
1704
|
-
throw kt(t);
|
|
1705
|
-
}, t);
|
|
1706
|
-
}
|
|
1707
|
-
/**
|
|
1708
|
-
* Requests current user phone access. Method returns promise, which resolves
|
|
1709
|
-
* status of the request. In case, user accepted the request, Mini App bot will receive
|
|
1710
|
-
* the according notification.
|
|
1711
|
-
*
|
|
1712
|
-
* To obtain the retrieved information instead, utilize the `requestContact` method.
|
|
1713
|
-
* @param options - additional options.
|
|
1714
|
-
* @see requestContact
|
|
1715
|
-
*/
|
|
1716
|
-
async requestPhoneAccess(t = {}) {
|
|
1717
|
-
return this.requestPhoneAccessPromise || (this.requestPhoneAccessPromise = w({
|
|
1718
|
-
...t,
|
|
1719
|
-
method: "web_app_request_phone",
|
|
1720
|
-
event: "phone_requested",
|
|
1721
|
-
postEvent: this.postEvent
|
|
1722
|
-
}).then(({ status: s }) => s).finally(() => this.requestPhoneAccessPromise = void 0)), this.requestPhoneAccessPromise;
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Requests write message access to current user.
|
|
1726
|
-
* @param options - additional options.
|
|
1727
|
-
*/
|
|
1728
|
-
async requestWriteAccess(t = {}) {
|
|
1729
|
-
return this.requestWriteAccessPromise || (this.requestWriteAccessPromise = w({
|
|
1730
|
-
...t,
|
|
1731
|
-
method: "web_app_request_write_access",
|
|
1732
|
-
event: "write_access_requested",
|
|
1733
|
-
postEvent: this.postEvent
|
|
1734
|
-
}).then(({ status: s }) => s).finally(() => this.requestWriteAccessPromise = void 0)), this.requestWriteAccessPromise;
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* A method used to send data to the bot. When this method called, a service message sent to
|
|
1738
|
-
* the bot containing the data of the length up to 4096 bytes, and the Mini App closed. See the
|
|
1739
|
-
* field `web_app_data` in the class [Message](https://core.telegram.org/bots/api#message).
|
|
1740
|
-
*
|
|
1741
|
-
* This method is only available for Mini Apps launched via a Keyboard button.
|
|
1742
|
-
* @param data - data to send to bot.
|
|
1743
|
-
* @throws {Error} data has incorrect size.
|
|
1744
|
-
*/
|
|
1745
|
-
sendData(t) {
|
|
1746
|
-
const { size: s } = new Blob([t]);
|
|
1747
|
-
if (!s || s > 4096)
|
|
1748
|
-
throw new Error(`Passed data has incorrect size: ${s}`);
|
|
1749
|
-
this.postEvent("web_app_data_send", { data: t });
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Updates current Mini App header color.
|
|
1753
|
-
*
|
|
1754
|
-
* @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
1755
|
-
* @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
1756
|
-
* @param color - color key or RGB color.
|
|
1757
|
-
*/
|
|
1758
|
-
setHeaderColor(t) {
|
|
1759
|
-
this.postEvent("web_app_set_header_color", st(t) ? { color: t } : { color_key: t }), this.set("headerColor", t);
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* Updates current Mini App background color.
|
|
1763
|
-
*
|
|
1764
|
-
* @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
1765
|
-
* @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
1766
|
-
* @param color - RGB color.
|
|
1767
|
-
*/
|
|
1768
|
-
setBgColor(t) {
|
|
1769
|
-
this.postEvent("web_app_set_background_color", { color: t }), this.set("bgColor", t);
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Inserts the bot's username and the specified inline query in the current chat's input field.
|
|
1773
|
-
* Query may be empty, in which case only the bot's username will be inserted. The client prompts
|
|
1774
|
-
* the user to choose a specific chat, then opens that chat and inserts the bot's username and
|
|
1775
|
-
* the specified inline query in the input field.
|
|
1776
|
-
* @param text - text which should be inserted in the input after the current bot name. Max
|
|
1777
|
-
* length is 256 symbols.
|
|
1778
|
-
* @param chatTypes - List of chat types which could be chosen to send the message. Could be
|
|
1779
|
-
* empty list.
|
|
1780
|
-
*/
|
|
1781
|
-
switchInlineQuery(t, s = []) {
|
|
1782
|
-
if (!this.supports("switchInlineQuery") && !this.isBotInline)
|
|
1783
|
-
throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
|
|
1784
|
-
this.postEvent("web_app_switch_inline_query", { query: t, chat_types: s });
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
const ps = d(
|
|
1788
|
-
"miniApp",
|
|
1789
|
-
({
|
|
1790
|
-
themeParams: e,
|
|
1791
|
-
botInline: t = !1,
|
|
1792
|
-
state: s = {
|
|
1793
|
-
bgColor: e.bgColor || "#ffffff",
|
|
1794
|
-
headerColor: e.headerBgColor || "#000000"
|
|
1795
|
-
},
|
|
1796
|
-
...n
|
|
1797
|
-
}) => new hs({ ...n, ...s, botInline: t })
|
|
1798
|
-
);
|
|
1799
|
-
function us(e) {
|
|
1800
|
-
const t = e.message.trim(), s = (e.title || "").trim(), n = e.buttons || [];
|
|
1801
|
-
let r;
|
|
1802
|
-
if (s.length > 64)
|
|
1803
|
-
throw new Error(`Title has incorrect size: ${s.length}`);
|
|
1804
|
-
if (!t.length || t.length > 256)
|
|
1805
|
-
throw new Error(`Message has incorrect size: ${t.length}`);
|
|
1806
|
-
if (n.length > 3)
|
|
1807
|
-
throw new Error(`Buttons have incorrect size: ${n.length}`);
|
|
1808
|
-
return n.length ? r = n.map((i) => {
|
|
1809
|
-
const { id: o = "" } = i;
|
|
1810
|
-
if (o.length > 64)
|
|
1811
|
-
throw new Error(`Button ID has incorrect size: ${o}`);
|
|
1812
|
-
if (!i.type || i.type === "default" || i.type === "destructive") {
|
|
1813
|
-
const a = i.text.trim();
|
|
1814
|
-
if (!a.length || a.length > 64) {
|
|
1815
|
-
const h = i.type || "default";
|
|
1816
|
-
throw new Error(`Button text with type "${h}" has incorrect size: ${i.text.length}`);
|
|
1817
|
-
}
|
|
1818
|
-
return { ...i, text: a, id: o };
|
|
1819
|
-
}
|
|
1820
|
-
return { ...i, id: o };
|
|
1821
|
-
}) : r = [{ type: "close", id: "" }], { title: s, message: t, buttons: r };
|
|
1822
|
-
}
|
|
1823
|
-
class ls extends D {
|
|
1824
|
-
constructor(t, s, n) {
|
|
1825
|
-
super({ isOpened: t }, s, { open: "web_app_open_popup" }), this.postEvent = n;
|
|
1826
|
-
}
|
|
1827
|
-
set isOpened(t) {
|
|
1828
|
-
this.set("isOpened", t);
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* True if the Popup is opened.
|
|
1832
|
-
*/
|
|
1833
|
-
get isOpened() {
|
|
1834
|
-
return this.get("isOpened");
|
|
1835
|
-
}
|
|
1836
|
-
/**
|
|
1837
|
-
* A method that shows a native popup described by the `params` argument.
|
|
1838
|
-
* Promise will be resolved when popup is closed. Resolved value will have
|
|
1839
|
-
* an identifier of pressed button.
|
|
1840
|
-
*
|
|
1841
|
-
* In case, user clicked outside the popup or clicked top right popup close
|
|
1842
|
-
* button, null will be returned.
|
|
1843
|
-
*
|
|
1844
|
-
* @param options - popup parameters.
|
|
1845
|
-
* @throws {Error} Popup is already opened.
|
|
1846
|
-
*/
|
|
1847
|
-
async open(t) {
|
|
1848
|
-
if (this.isOpened)
|
|
1849
|
-
throw new Error("Popup is already opened.");
|
|
1850
|
-
this.isOpened = !0;
|
|
1851
|
-
try {
|
|
1852
|
-
const { button_id: s = null } = await w({
|
|
1853
|
-
event: "popup_closed",
|
|
1854
|
-
method: "web_app_open_popup",
|
|
1855
|
-
postEvent: this.postEvent,
|
|
1856
|
-
params: us(t)
|
|
1857
|
-
});
|
|
1858
|
-
return s;
|
|
1859
|
-
} finally {
|
|
1860
|
-
this.isOpened = !1;
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
const ds = d(
|
|
1865
|
-
({ postEvent: e, version: t }) => new ls(!1, t, e)
|
|
1866
|
-
);
|
|
1867
|
-
class _s extends D {
|
|
1868
|
-
constructor(t, s, n) {
|
|
1869
|
-
super({ isOpened: t }, s, {
|
|
1870
|
-
close: "web_app_close_scan_qr_popup",
|
|
1871
|
-
open: "web_app_open_scan_qr_popup"
|
|
1872
|
-
}), this.postEvent = n;
|
|
1873
|
-
}
|
|
1874
|
-
/**
|
|
1875
|
-
* Closes the scanner.
|
|
1876
|
-
*/
|
|
1877
|
-
close() {
|
|
1878
|
-
this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
|
|
1879
|
-
}
|
|
1880
|
-
set isOpened(t) {
|
|
1881
|
-
this.set("isOpened", t);
|
|
1882
|
-
}
|
|
1883
|
-
/**
|
|
1884
|
-
* Returns true if the scanner is currently opened.
|
|
1885
|
-
*/
|
|
1886
|
-
get isOpened() {
|
|
1887
|
-
return this.get("isOpened");
|
|
1888
|
-
}
|
|
1889
|
-
async open(t) {
|
|
1890
|
-
if (this.isOpened)
|
|
1891
|
-
throw new Error("The scanner is already opened");
|
|
1892
|
-
const { text: s, capture: n } = (typeof t == "string" ? { text: t } : t) || {};
|
|
1893
|
-
this.isOpened = !0;
|
|
1894
|
-
try {
|
|
1895
|
-
const r = (await w({
|
|
1896
|
-
method: "web_app_open_scan_qr_popup",
|
|
1897
|
-
event: ["qr_text_received", "scan_qr_popup_closed"],
|
|
1898
|
-
postEvent: this.postEvent,
|
|
1899
|
-
params: { text: s },
|
|
1900
|
-
capture(i) {
|
|
1901
|
-
return i.event === "scan_qr_popup_closed" || !n || n(i.payload);
|
|
1902
|
-
}
|
|
1903
|
-
}) || {}).data || null;
|
|
1904
|
-
return r && this.close(), r;
|
|
1905
|
-
} finally {
|
|
1906
|
-
this.isOpened = !1;
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
// TODO: Streaming mode, allowing to scan several QRs until closed.
|
|
1910
|
-
}
|
|
1911
|
-
const gs = d(
|
|
1912
|
-
({ version: e, postEvent: t }) => new _s(!1, e, t)
|
|
1913
|
-
);
|
|
1914
|
-
class fs extends it {
|
|
1915
|
-
constructor(t, s, n) {
|
|
1916
|
-
super({ isVisible: t }, s, {
|
|
1917
|
-
show: "web_app_setup_settings_button",
|
|
1918
|
-
hide: "web_app_setup_settings_button"
|
|
1919
|
-
}), c(this, "on", (r, i) => r === "click" ? v("settings_button_pressed", i) : this.state.on(r, i)), c(this, "off", (r, i) => r === "click" ? H("settings_button_pressed", i) : this.state.off(r, i)), this.postEvent = n;
|
|
1920
|
-
}
|
|
1921
|
-
set isVisible(t) {
|
|
1922
|
-
this.set("isVisible", t), this.postEvent("web_app_setup_settings_button", { is_visible: t });
|
|
1923
|
-
}
|
|
1924
|
-
/**
|
|
1925
|
-
* True if the SettingsButton is visible.
|
|
1926
|
-
*/
|
|
1927
|
-
get isVisible() {
|
|
1928
|
-
return this.get("isVisible");
|
|
1929
|
-
}
|
|
1930
|
-
/**
|
|
1931
|
-
* Hides the SettingsButton.
|
|
1932
|
-
*/
|
|
1933
|
-
hide() {
|
|
1934
|
-
this.isVisible = !1;
|
|
1935
|
-
}
|
|
1936
|
-
/**
|
|
1937
|
-
* Shows the SettingsButton.
|
|
1938
|
-
*/
|
|
1939
|
-
show() {
|
|
1940
|
-
this.isVisible = !0;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
const ws = d(
|
|
1944
|
-
"settingsButton",
|
|
1945
|
-
({
|
|
1946
|
-
version: e,
|
|
1947
|
-
postEvent: t,
|
|
1948
|
-
state: s = { isVisible: !1 }
|
|
1949
|
-
}) => new fs(s.isVisible, e, t)
|
|
1950
|
-
);
|
|
1951
|
-
function Jt(e) {
|
|
1952
|
-
return Mt().parse(e);
|
|
1953
|
-
}
|
|
1954
|
-
class ms extends ct {
|
|
1955
|
-
/**
|
|
1956
|
-
* @since v6.10
|
|
1957
|
-
*/
|
|
1958
|
-
get accentTextColor() {
|
|
1959
|
-
return this.get("accentTextColor");
|
|
1960
|
-
}
|
|
1961
|
-
get bgColor() {
|
|
1962
|
-
return this.get("bgColor");
|
|
1963
|
-
}
|
|
1964
|
-
get buttonColor() {
|
|
1965
|
-
return this.get("buttonColor");
|
|
1966
|
-
}
|
|
1967
|
-
get buttonTextColor() {
|
|
1968
|
-
return this.get("buttonTextColor");
|
|
1969
|
-
}
|
|
1970
|
-
get destructiveTextColor() {
|
|
1971
|
-
return this.get("destructiveTextColor");
|
|
1972
|
-
}
|
|
1973
|
-
/**
|
|
1974
|
-
* Returns the copy of the internal state of the current component instance.
|
|
1975
|
-
*/
|
|
1976
|
-
getState() {
|
|
1977
|
-
return this.clone();
|
|
1978
|
-
}
|
|
1979
|
-
/**
|
|
1980
|
-
* @since v6.10
|
|
1981
|
-
*/
|
|
1982
|
-
get headerBgColor() {
|
|
1983
|
-
return this.get("headerBgColor");
|
|
1984
|
-
}
|
|
1985
|
-
get hintColor() {
|
|
1986
|
-
return this.get("hintColor");
|
|
1987
|
-
}
|
|
1988
|
-
/**
|
|
1989
|
-
* @returns True in case, current color scheme is recognized as dark. This
|
|
1990
|
-
* value is calculated according to theme bg color.
|
|
1991
|
-
*/
|
|
1992
|
-
get isDark() {
|
|
1993
|
-
return !this.bgColor || Ot(this.bgColor);
|
|
1994
|
-
}
|
|
1995
|
-
get linkColor() {
|
|
1996
|
-
return this.get("linkColor");
|
|
1997
|
-
}
|
|
1998
|
-
get secondaryBgColor() {
|
|
1999
|
-
return this.get("secondaryBgColor");
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* @since v6.10
|
|
2003
|
-
*/
|
|
2004
|
-
get sectionBgColor() {
|
|
2005
|
-
return this.get("sectionBgColor");
|
|
2006
|
-
}
|
|
2007
|
-
/**
|
|
2008
|
-
* @since v6.10
|
|
2009
|
-
*/
|
|
2010
|
-
get sectionHeaderTextColor() {
|
|
2011
|
-
return this.get("sectionHeaderTextColor");
|
|
2012
|
-
}
|
|
2013
|
-
/**
|
|
2014
|
-
* @since v7.6
|
|
2015
|
-
*/
|
|
2016
|
-
get sectionSeparatorColor() {
|
|
2017
|
-
return this.get("sectionHeaderTextColor");
|
|
2018
|
-
}
|
|
2019
|
-
/**
|
|
2020
|
-
* Starts listening to the external theme changes and applies them.
|
|
2021
|
-
* @returns Function to stop listening.
|
|
2022
|
-
*/
|
|
2023
|
-
listen() {
|
|
2024
|
-
return v("theme_changed", (t) => {
|
|
2025
|
-
this.set(Jt(t.theme_params));
|
|
2026
|
-
});
|
|
2027
|
-
}
|
|
2028
|
-
/**
|
|
2029
|
-
* @since v6.10
|
|
2030
|
-
*/
|
|
2031
|
-
get subtitleTextColor() {
|
|
2032
|
-
return this.get("subtitleTextColor");
|
|
2033
|
-
}
|
|
2034
|
-
get textColor() {
|
|
2035
|
-
return this.get("textColor");
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
const bs = d(
|
|
2039
|
-
"themeParams",
|
|
2040
|
-
({ themeParams: e, state: t = e, addCleanup: s }) => {
|
|
2041
|
-
const n = new ms(t);
|
|
2042
|
-
return s(n.listen()), n;
|
|
2043
|
-
}
|
|
2044
|
-
);
|
|
2045
|
-
function Zs(e = {}) {
|
|
2046
|
-
return w({
|
|
2047
|
-
...e,
|
|
2048
|
-
method: "web_app_request_theme",
|
|
2049
|
-
event: "theme_changed"
|
|
2050
|
-
}).then(Jt);
|
|
2051
|
-
}
|
|
2052
|
-
class vs extends ht {
|
|
2053
|
-
constructor(t, s, n) {
|
|
2054
|
-
super(t, { readTextFromClipboard: "web_app_read_text_from_clipboard" }), c(this, "supportsParam"), this.version = t, this.createRequestId = s, this.postEvent = n, this.supportsParam = zt(t, {
|
|
2055
|
-
"openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Opens a link in an external browser. The Mini App will not be closed.
|
|
2060
|
-
*
|
|
2061
|
-
* Note that this method can be called only in response to the user
|
|
2062
|
-
* interaction with the Mini App interface (e.g. click inside the Mini App
|
|
2063
|
-
* or on the main button).
|
|
2064
|
-
* @param url - URL to be opened.
|
|
2065
|
-
* @param tryInstantView
|
|
2066
|
-
*/
|
|
2067
|
-
openLink(t, s) {
|
|
2068
|
-
const n = new URL(t, window.location.href).toString();
|
|
2069
|
-
if (!x("web_app_open_link", this.version)) {
|
|
2070
|
-
window.open(n, "_blank");
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2073
|
-
this.postEvent("web_app_open_link", {
|
|
2074
|
-
url: n,
|
|
2075
|
-
...typeof s == "boolean" ? { try_instant_view: s } : {}
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
/**
|
|
2079
|
-
* Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
|
|
2080
|
-
* link in full format, with hostname "t.me".
|
|
2081
|
-
* @param url - URL to be opened.
|
|
2082
|
-
* @throws {Error} URL has not allowed hostname.
|
|
2083
|
-
*/
|
|
2084
|
-
openTelegramLink(t) {
|
|
2085
|
-
const { hostname: s, pathname: n, search: r } = new URL(t, "https://t.me");
|
|
2086
|
-
if (s !== "t.me")
|
|
2087
|
-
throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);
|
|
2088
|
-
if (!x("web_app_open_tg_link", this.version)) {
|
|
2089
|
-
window.location.href = t;
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
this.postEvent("web_app_open_tg_link", { path_full: n + r });
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* Reads text from clipboard and returns string or null. null is returned
|
|
2096
|
-
* in cases:
|
|
2097
|
-
* - Value in clipboard is not text
|
|
2098
|
-
* - Access to clipboard is not allowed
|
|
2099
|
-
*/
|
|
2100
|
-
async readTextFromClipboard() {
|
|
2101
|
-
const t = this.createRequestId(), {
|
|
2102
|
-
data: s = null
|
|
2103
|
-
} = await w({
|
|
2104
|
-
method: "web_app_read_text_from_clipboard",
|
|
2105
|
-
event: "clipboard_text_received",
|
|
2106
|
-
postEvent: this.postEvent,
|
|
2107
|
-
params: { req_id: t },
|
|
2108
|
-
capture: It(t)
|
|
2109
|
-
});
|
|
2110
|
-
return s;
|
|
2111
|
-
}
|
|
2112
|
-
/**
|
|
2113
|
-
* Shares specified URL with the passed to the chats, selected by user. After being called,
|
|
2114
|
-
* it closes the mini application.
|
|
2115
|
-
*
|
|
2116
|
-
* This method uses Telegram's Share Links.
|
|
2117
|
-
* @param url - URL to share.
|
|
2118
|
-
* @param text - text to append after the URL.
|
|
2119
|
-
* @see https://core.telegram.org/api/links#share-links
|
|
2120
|
-
* @see https://core.telegram.org/widgets/share#custom-buttons
|
|
2121
|
-
*/
|
|
2122
|
-
shareURL(t, s) {
|
|
2123
|
-
this.openTelegramLink(
|
|
2124
|
-
"https://t.me/share/url?" + new URLSearchParams({ url: t, text: s || "" }).toString()
|
|
2125
|
-
);
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
const ys = d(
|
|
2129
|
-
({ version: e, postEvent: t, createRequestId: s }) => new vs(e, s, t)
|
|
2130
|
-
);
|
|
2131
|
-
async function Ft(e = {}) {
|
|
2132
|
-
const {
|
|
2133
|
-
is_expanded: t,
|
|
2134
|
-
is_state_stable: s,
|
|
2135
|
-
...n
|
|
2136
|
-
} = await w({
|
|
2137
|
-
...e,
|
|
2138
|
-
method: "web_app_request_viewport",
|
|
2139
|
-
event: "viewport_changed"
|
|
2140
|
-
});
|
|
2141
|
-
return { ...n, isExpanded: t, isStateStable: s };
|
|
2142
|
-
}
|
|
2143
|
-
function R(e) {
|
|
2144
|
-
return e < 0 ? 0 : e;
|
|
2145
|
-
}
|
|
2146
|
-
class Es extends ct {
|
|
2147
|
-
constructor({ postEvent: t, stableHeight: s, height: n, width: r, isExpanded: i }) {
|
|
2148
|
-
super({
|
|
2149
|
-
height: R(n),
|
|
2150
|
-
isExpanded: i,
|
|
2151
|
-
stableHeight: R(s),
|
|
2152
|
-
width: R(r)
|
|
2153
|
-
}), c(this, "postEvent"), this.postEvent = t;
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Requests viewport information from the Telegram application and updates current Viewport
|
|
2157
|
-
* instance.
|
|
2158
|
-
* @param options - options to request fresh data.
|
|
2159
|
-
*/
|
|
2160
|
-
async sync(t) {
|
|
2161
|
-
const { isStateStable: s, ...n } = await Ft(t);
|
|
2162
|
-
this.set({
|
|
2163
|
-
...n,
|
|
2164
|
-
stableHeight: s ? n.height : this.get("stableHeight")
|
|
2165
|
-
});
|
|
2166
|
-
}
|
|
2167
|
-
/**
|
|
2168
|
-
* The current height of the **visible area** of the Mini App.
|
|
2169
|
-
*
|
|
2170
|
-
* The application can display just the top part of the Mini App, with its lower part remaining
|
|
2171
|
-
* outside the screen area. From this position, the user can "pull" the Mini App to its
|
|
2172
|
-
* maximum height, while the bot can do the same by calling `expand` method. As the position of
|
|
2173
|
-
* the Mini App changes, the current height value of the visible area will be updated in real
|
|
2174
|
-
* time.
|
|
2175
|
-
*
|
|
2176
|
-
* Please note that the refresh rate of this value is not sufficient to smoothly follow the
|
|
2177
|
-
* lower border of the window. It should not be used to pin interface elements to the bottom
|
|
2178
|
-
* of the visible area. It's more appropriate to use the value of the `stableHeight`
|
|
2179
|
-
* field for this purpose.
|
|
2180
|
-
*
|
|
2181
|
-
* @see stableHeight
|
|
2182
|
-
*/
|
|
2183
|
-
get height() {
|
|
2184
|
-
return this.get("height");
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* The height of the visible area of the Mini App in its last stable state.
|
|
2188
|
-
*
|
|
2189
|
-
* The application can display just the top part of the Mini App, with its lower part remaining
|
|
2190
|
-
* outside the screen area. From this position, the user can "pull" the Mini App to its
|
|
2191
|
-
* maximum height, while the application can do the same by calling `expand` method.
|
|
2192
|
-
*
|
|
2193
|
-
* Unlike the value of `height`, the value of `stableHeight` does not change as the position
|
|
2194
|
-
* of the Mini App changes with user gestures or during animations. The value of `stableHeight`
|
|
2195
|
-
* will be updated after all gestures and animations are completed and
|
|
2196
|
-
* the Mini App reaches its final size.
|
|
2197
|
-
*
|
|
2198
|
-
* @see height
|
|
2199
|
-
*/
|
|
2200
|
-
get stableHeight() {
|
|
2201
|
-
return this.get("stableHeight");
|
|
2202
|
-
}
|
|
2203
|
-
/**
|
|
2204
|
-
* Starts listening to viewport changes and applies them.
|
|
2205
|
-
* @returns Function to stop listening.
|
|
2206
|
-
*/
|
|
2207
|
-
listen() {
|
|
2208
|
-
return v("viewport_changed", (t) => {
|
|
2209
|
-
const {
|
|
2210
|
-
height: s,
|
|
2211
|
-
width: n,
|
|
2212
|
-
is_expanded: r,
|
|
2213
|
-
is_state_stable: i
|
|
2214
|
-
} = t, o = R(s);
|
|
2215
|
-
this.set({
|
|
2216
|
-
height: o,
|
|
2217
|
-
isExpanded: r,
|
|
2218
|
-
width: R(n),
|
|
2219
|
-
...i ? { stableHeight: o } : {}
|
|
2220
|
-
});
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
/**
|
|
2224
|
-
* True if the Mini App is expanded to the maximum available height. Otherwise, if
|
|
2225
|
-
* the Mini App occupies part of the screen and can be expanded to the full height using
|
|
2226
|
-
* `expand` method.
|
|
2227
|
-
* @see expand
|
|
2228
|
-
*/
|
|
2229
|
-
get isExpanded() {
|
|
2230
|
-
return this.get("isExpanded");
|
|
2231
|
-
}
|
|
2232
|
-
/**
|
|
2233
|
-
* Current visible area width.
|
|
2234
|
-
*/
|
|
2235
|
-
get width() {
|
|
2236
|
-
return this.get("width");
|
|
2237
|
-
}
|
|
2238
|
-
/**
|
|
2239
|
-
* A method that expands the Mini App to the maximum available height. To find out if the Mini
|
|
2240
|
-
* App is expanded to the maximum height, refer to the value of the `isExpanded`.
|
|
2241
|
-
* @see isExpanded
|
|
2242
|
-
*/
|
|
2243
|
-
expand() {
|
|
2244
|
-
this.postEvent("web_app_expand"), this.set("isExpanded", !0);
|
|
2245
|
-
}
|
|
2246
|
-
/**
|
|
2247
|
-
* True if the current viewport height is stable and is not going to change in the next moment.
|
|
2248
|
-
*/
|
|
2249
|
-
get isStable() {
|
|
2250
|
-
return this.stableHeight === this.height;
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
const Ps = d(
|
|
2254
|
-
"viewport",
|
|
2255
|
-
async ({ state: e, platform: t, postEvent: s, addCleanup: n }) => {
|
|
2256
|
-
let r = !1, i = 0, o = 0, a = 0;
|
|
2257
|
-
if (e)
|
|
2258
|
-
r = e.isExpanded, i = e.height, o = e.width, a = e.stableHeight;
|
|
2259
|
-
else if (["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(t))
|
|
2260
|
-
r = !0, i = window.innerHeight, o = window.innerWidth, a = window.innerHeight;
|
|
2261
|
-
else {
|
|
2262
|
-
const u = await Ft({ timeout: 1e3, postEvent: s });
|
|
2263
|
-
r = u.isExpanded, i = u.height, o = u.width, a = u.isStateStable ? i : 0;
|
|
2264
|
-
}
|
|
2265
|
-
const h = new Es({
|
|
2266
|
-
postEvent: s,
|
|
2267
|
-
height: i,
|
|
2268
|
-
width: o,
|
|
2269
|
-
stableHeight: a,
|
|
2270
|
-
isExpanded: r
|
|
2271
|
-
});
|
|
2272
|
-
return n(h.listen()), h;
|
|
2273
|
-
}
|
|
2274
|
-
);
|
|
2275
|
-
function E(e, t) {
|
|
2276
|
-
document.documentElement.style.setProperty(e, t);
|
|
2277
|
-
}
|
|
2278
|
-
function Xs(e, t, s) {
|
|
2279
|
-
s || (s = (a) => `--tg-${a}-color`);
|
|
2280
|
-
const n = s("header"), r = s("bg"), i = () => {
|
|
2281
|
-
const { headerColor: a } = e;
|
|
2282
|
-
if (st(a))
|
|
2283
|
-
E(n, a);
|
|
2284
|
-
else {
|
|
2285
|
-
const { bgColor: h, secondaryBgColor: u } = t;
|
|
2286
|
-
a === "bg_color" && h ? E(n, h) : a === "secondary_bg_color" && u && E(n, u);
|
|
2287
|
-
}
|
|
2288
|
-
E(r, e.bgColor);
|
|
2289
|
-
}, o = [
|
|
2290
|
-
t.on("change", i),
|
|
2291
|
-
e.on("change", i)
|
|
2292
|
-
];
|
|
2293
|
-
return i(), () => o.forEach((a) => a());
|
|
2294
|
-
}
|
|
2295
|
-
function tn(e, t) {
|
|
2296
|
-
t || (t = (n) => `--tg-theme-${n.replace(/[A-Z]/g, (r) => `-${r.toLowerCase()}`)}`);
|
|
2297
|
-
const s = () => {
|
|
2298
|
-
Object.entries(e.getState()).forEach(([n, r]) => {
|
|
2299
|
-
r && E(t(n), r);
|
|
2300
|
-
});
|
|
2301
|
-
};
|
|
2302
|
-
return s(), e.on("change", s);
|
|
2303
|
-
}
|
|
2304
|
-
function en(e, t) {
|
|
2305
|
-
t || (t = (u) => `--tg-viewport-${u}`);
|
|
2306
|
-
const [
|
|
2307
|
-
s,
|
|
2308
|
-
n,
|
|
2309
|
-
r
|
|
2310
|
-
] = ["height", "width", "stable-height"].map((u) => t(u)), i = () => E(s, `${e.height}px`), o = () => E(n, `${e.width}px`), a = () => E(r, `${e.stableHeight}px`), h = [
|
|
2311
|
-
e.on("change:height", i),
|
|
2312
|
-
e.on("change:width", o),
|
|
2313
|
-
e.on("change:stableHeight", a)
|
|
2314
|
-
];
|
|
2315
|
-
return i(), o(), a(), () => h.forEach((u) => u());
|
|
2316
|
-
}
|
|
2317
|
-
function xs(e = !0) {
|
|
2318
|
-
const t = [
|
|
2319
|
-
v("reload_iframe", () => {
|
|
2320
|
-
q("iframe_will_reload"), window.location.reload();
|
|
2321
|
-
})
|
|
2322
|
-
], s = () => t.forEach((n) => n());
|
|
2323
|
-
if (e) {
|
|
2324
|
-
const n = document.createElement("style");
|
|
2325
|
-
n.id = "telegram-custom-styles", document.head.appendChild(n), t.push(
|
|
2326
|
-
v("set_custom_style", (r) => {
|
|
2327
|
-
n.innerHTML = r;
|
|
2328
|
-
}),
|
|
2329
|
-
() => document.head.removeChild(n)
|
|
2330
|
-
);
|
|
2331
|
-
}
|
|
2332
|
-
return q("iframe_ready", { reload_supported: !0 }), s;
|
|
2333
|
-
}
|
|
2334
|
-
function sn() {
|
|
2335
|
-
return typeof window > "u";
|
|
2336
|
-
}
|
|
2337
|
-
async function nn() {
|
|
2338
|
-
if (Rt(window))
|
|
2339
|
-
return !0;
|
|
2340
|
-
try {
|
|
2341
|
-
return await w({ method: "web_app_request_theme", event: "theme_changed", timeout: 100 }), !0;
|
|
2342
|
-
} catch {
|
|
2343
|
-
return !1;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
function rn(e) {
|
|
2347
|
-
const t = typeof e == "string" ? at(e) : e;
|
|
2348
|
-
jt(t);
|
|
2349
|
-
function s(r) {
|
|
2350
|
-
if (typeof r == "string")
|
|
2351
|
-
try {
|
|
2352
|
-
const { eventType: i } = St(r);
|
|
2353
|
-
i === "web_app_request_theme" && Y("theme_changed", {
|
|
2354
|
-
theme_params: JSON.parse(Wt(t.themeParams))
|
|
2355
|
-
}), i === "web_app_request_viewport" && Y("viewport_changed", {
|
|
2356
|
-
width: window.innerWidth,
|
|
2357
|
-
height: window.innerHeight,
|
|
2358
|
-
is_state_stable: !0,
|
|
2359
|
-
is_expanded: !0
|
|
2360
|
-
});
|
|
2361
|
-
} catch {
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
if (nt()) {
|
|
2365
|
-
const r = window.parent.postMessage.bind(window.parent);
|
|
2366
|
-
window.parent.postMessage = (i) => {
|
|
2367
|
-
s(i), r(i);
|
|
2368
|
-
};
|
|
2369
|
-
return;
|
|
2370
|
-
}
|
|
2371
|
-
if (Tt(window)) {
|
|
2372
|
-
const r = window.external.notify.bind(window.external);
|
|
2373
|
-
window.external.notify = (i) => {
|
|
2374
|
-
s(i), r(i);
|
|
2375
|
-
};
|
|
2376
|
-
return;
|
|
2377
|
-
}
|
|
2378
|
-
const n = window.TelegramWebviewProxy;
|
|
2379
|
-
window.TelegramWebviewProxy = {
|
|
2380
|
-
...n || {},
|
|
2381
|
-
postEvent(...r) {
|
|
2382
|
-
s(JSON.stringify({ eventType: r[0], eventData: r[1] })), n && n.postEvent(...r);
|
|
2383
|
-
}
|
|
2384
|
-
};
|
|
2385
|
-
}
|
|
2386
|
-
function Cs(e) {
|
|
2387
|
-
return e instanceof $;
|
|
2388
|
-
}
|
|
2389
|
-
function on(e, t) {
|
|
2390
|
-
return Cs(e) && e.type === t;
|
|
2391
|
-
}
|
|
2392
|
-
function j(e, t) {
|
|
2393
|
-
let s, n, r;
|
|
2394
|
-
return typeof e == "string" ? s = e : (s = e.pathname === void 0 ? t : e.pathname, n = e.params, r = e.id), Object.freeze({
|
|
2395
|
-
id: r || (Math.random() * 2 ** 14 | 0).toString(16),
|
|
2396
|
-
pathname: s,
|
|
2397
|
-
params: n
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
class Ss {
|
|
2401
|
-
constructor(t, s, n = q) {
|
|
2402
|
-
if (c(this, "history"), c(this, "ee", new k()), c(this, "attached", !1), c(this, "back", () => this.go(-1)), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this._index = s, this.postEvent = n, t.length === 0)
|
|
2403
|
-
throw b(we, "History should not be empty.");
|
|
2404
|
-
if (s < 0 || s >= t.length)
|
|
2405
|
-
throw b(
|
|
2406
|
-
me,
|
|
2407
|
-
"Index should not be zero and higher or equal than history size."
|
|
2408
|
-
);
|
|
2409
|
-
this.history = t.map((r) => j(r, ""));
|
|
2410
|
-
}
|
|
2411
|
-
/**
|
|
2412
|
-
* Allows this navigator to control the `BackButton` visibility state. It also tracks the
|
|
2413
|
-
* `BackButton` clicks and calls the `back` method.
|
|
2414
|
-
*/
|
|
2415
|
-
attach() {
|
|
2416
|
-
this.attached || (this.attached = !0, this.sync(), v("back_button_pressed", this.back));
|
|
2417
|
-
}
|
|
2418
|
-
/**
|
|
2419
|
-
* Currently active history item.
|
|
2420
|
-
*/
|
|
2421
|
-
get current() {
|
|
2422
|
-
return this.history[this.index];
|
|
2423
|
-
}
|
|
2424
|
-
/**
|
|
2425
|
-
* Prevents current navigator from controlling the BackButton visibility state.
|
|
2426
|
-
*/
|
|
2427
|
-
detach() {
|
|
2428
|
-
this.attached = !1, H("back_button_pressed", this.back);
|
|
2429
|
-
}
|
|
2430
|
-
/**
|
|
2431
|
-
* Goes to the next history item.
|
|
2432
|
-
*/
|
|
2433
|
-
forward() {
|
|
2434
|
-
this.go(1);
|
|
2435
|
-
}
|
|
2436
|
-
/**
|
|
2437
|
-
* Changes currently active history item index by the specified delta. This method doesn't
|
|
2438
|
-
* change index in case, the updated index points to the non-existing history item. This behavior
|
|
2439
|
-
* is preserved until the `fit` argument is specified.
|
|
2440
|
-
* @param delta - index delta.
|
|
2441
|
-
* @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
|
|
2442
|
-
*/
|
|
2443
|
-
go(t, s) {
|
|
2444
|
-
const n = this.index + t, r = Math.min(
|
|
2445
|
-
Math.max(0, n),
|
|
2446
|
-
this.history.length - 1
|
|
2447
|
-
);
|
|
2448
|
-
(n === r || s) && this.replaceAndMove(r, this.history[r]);
|
|
2449
|
-
}
|
|
2450
|
-
/**
|
|
2451
|
-
* Goes to the specified index. Method does nothing in case, passed index is out of bounds.
|
|
2452
|
-
*
|
|
2453
|
-
* If "fit" option was specified and index is out of bounds, it will be cut to the nearest
|
|
2454
|
-
* bound.
|
|
2455
|
-
* @param index - target index.
|
|
2456
|
-
* @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
|
|
2457
|
-
*/
|
|
2458
|
-
goTo(t, s) {
|
|
2459
|
-
this.go(t - this.index, s);
|
|
2460
|
-
}
|
|
2461
|
-
/**
|
|
2462
|
-
* True if navigator has items before the current item.
|
|
2463
|
-
*/
|
|
2464
|
-
get hasPrev() {
|
|
2465
|
-
return this.index > 0;
|
|
2466
|
-
}
|
|
2467
|
-
/**
|
|
2468
|
-
* True if navigator has items after the current item.
|
|
2469
|
-
*/
|
|
2470
|
-
get hasNext() {
|
|
2471
|
-
return this.index !== this.history.length - 1;
|
|
2472
|
-
}
|
|
2473
|
-
/**
|
|
2474
|
-
* Currently active history item index.
|
|
2475
|
-
*/
|
|
2476
|
-
get index() {
|
|
2477
|
-
return this._index;
|
|
2478
|
-
}
|
|
2479
|
-
/**
|
|
2480
|
-
* Adds a new history item removing all after the current one.
|
|
2481
|
-
* @param item - item to add.
|
|
2482
|
-
*/
|
|
2483
|
-
push(t) {
|
|
2484
|
-
this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, j(t, this.current.pathname));
|
|
2485
|
-
}
|
|
2486
|
-
/**
|
|
2487
|
-
* Replaces the current history item.
|
|
2488
|
-
* @param item - item to replace the current item with.
|
|
2489
|
-
*/
|
|
2490
|
-
replace(t) {
|
|
2491
|
-
this.replaceAndMove(this.index, j(t, this.current.pathname));
|
|
2492
|
-
}
|
|
2493
|
-
/**
|
|
2494
|
-
* Sets history item by the specified index.
|
|
2495
|
-
* @param index - history item index to replace.
|
|
2496
|
-
* @param historyItem - history item to set.
|
|
2497
|
-
*/
|
|
2498
|
-
replaceAndMove(t, s) {
|
|
2499
|
-
const n = t - this.index;
|
|
2500
|
-
if (!n && this.current === s)
|
|
2501
|
-
return;
|
|
2502
|
-
const r = this.current;
|
|
2503
|
-
if (this.index !== t) {
|
|
2504
|
-
const i = this._index;
|
|
2505
|
-
this._index = t, this.attached && i > 0 != t > 0 && this.sync();
|
|
2506
|
-
}
|
|
2507
|
-
this.history[t] = s, this.ee.emit("change", {
|
|
2508
|
-
navigator: this,
|
|
2509
|
-
from: r,
|
|
2510
|
-
to: this.current,
|
|
2511
|
-
delta: n
|
|
2512
|
-
});
|
|
2513
|
-
}
|
|
2514
|
-
/**
|
|
2515
|
-
* Actualizes the `BackButton` visibility state.
|
|
2516
|
-
*/
|
|
2517
|
-
sync() {
|
|
2518
|
-
this.postEvent("web_app_setup_back_button", { is_visible: !!this.index });
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
function G({
|
|
2522
|
-
params: e,
|
|
2523
|
-
...t
|
|
2524
|
-
}) {
|
|
2525
|
-
return { ...e || { hash: "", search: "" }, ...t };
|
|
2526
|
-
}
|
|
2527
|
-
function O(e, t) {
|
|
2528
|
-
return e.startsWith(t) ? e : `${t}${e}`;
|
|
2529
|
-
}
|
|
2530
|
-
function M(e) {
|
|
2531
|
-
return new URL(
|
|
2532
|
-
typeof e == "string" ? e : `${e.pathname || ""}${O(e.search || "", "?")}${O(e.hash || "", "#")}`,
|
|
2533
|
-
"http://a"
|
|
2534
|
-
);
|
|
2535
|
-
}
|
|
2536
|
-
function B(e) {
|
|
2537
|
-
const t = typeof e == "string" ? e.startsWith("/") : !!(e.pathname && e.pathname.startsWith("/")), s = M(e);
|
|
2538
|
-
return `${t ? s.pathname : s.pathname.slice(1)}${s.search}${s.hash}`;
|
|
2539
|
-
}
|
|
2540
|
-
function K(e, t, s) {
|
|
2541
|
-
let n, r;
|
|
2542
|
-
typeof e == "string" ? n = e : (n = B(e), s = e.state, r = e.id);
|
|
2543
|
-
const { pathname: i, search: o, hash: a } = new URL(n, `http://a${O(t, "/")}`);
|
|
2544
|
-
return { id: r, pathname: i, params: { hash: a, search: o, state: s } };
|
|
2545
|
-
}
|
|
2546
|
-
async function I(e) {
|
|
2547
|
-
return e === 0 ? !0 : Promise.race([
|
|
2548
|
-
new Promise((t) => {
|
|
2549
|
-
const s = Q("popstate", () => {
|
|
2550
|
-
s(), t(!0);
|
|
2551
|
-
});
|
|
2552
|
-
window.history.go(e);
|
|
2553
|
-
}),
|
|
2554
|
-
// Usually, it takes about 1ms to emit this event, but we use some buffer.
|
|
2555
|
-
new Promise((t) => {
|
|
2556
|
-
setTimeout(t, 50, !1);
|
|
2557
|
-
})
|
|
2558
|
-
]);
|
|
2559
|
-
}
|
|
2560
|
-
async function Ts() {
|
|
2561
|
-
if (window.history.length <= 1 || (window.history.pushState(null, ""), await I(1 - window.history.length)))
|
|
2562
|
-
return;
|
|
2563
|
-
let e = await I(-1);
|
|
2564
|
-
for (; e; )
|
|
2565
|
-
e = await I(-1);
|
|
2566
|
-
}
|
|
2567
|
-
function Qt(e) {
|
|
2568
|
-
return M(e).pathname;
|
|
2569
|
-
}
|
|
2570
|
-
const mt = 0, z = 1, J = 2;
|
|
2571
|
-
class Yt {
|
|
2572
|
-
constructor(t, s, { postEvent: n, hashMode: r = "classic", base: i } = {}) {
|
|
2573
|
-
c(this, "navigator"), c(this, "ee", new k()), c(this, "hashMode"), c(this, "base"), c(this, "attached", !1), c(this, "onPopState", ({ state: o }) => {
|
|
2574
|
-
if (o === null)
|
|
2575
|
-
return this.push(this.parsePath(window.location.href));
|
|
2576
|
-
o === mt ? window.history.forward() : o === z && this.back(), o === J && this.forward();
|
|
2577
|
-
}), c(this, "onNavigatorChange", async ({
|
|
2578
|
-
to: o,
|
|
2579
|
-
from: a,
|
|
2580
|
-
delta: h
|
|
2581
|
-
}) => {
|
|
2582
|
-
this.attached && await this.syncHistory(), this.ee.emit("change", {
|
|
2583
|
-
delta: h,
|
|
2584
|
-
from: G(a),
|
|
2585
|
-
to: G(o),
|
|
2586
|
-
navigator: this
|
|
2587
|
-
});
|
|
2588
|
-
}), c(this, "on", this.ee.on.bind(this.ee)), c(this, "off", this.ee.off.bind(this.ee)), this.navigator = new Ss(
|
|
2589
|
-
t.map((o) => K(o, "/")),
|
|
2590
|
-
s,
|
|
2591
|
-
n
|
|
2592
|
-
), this.navigator.on("change", (o) => {
|
|
2593
|
-
this.onNavigatorChange(o);
|
|
2594
|
-
}), this.hashMode = r, this.base = Qt(i || "");
|
|
2595
|
-
}
|
|
2596
|
-
/**
|
|
2597
|
-
* Attaches current navigator to the browser history allowing navigator to manipulate it.
|
|
2598
|
-
*/
|
|
2599
|
-
async attach() {
|
|
2600
|
-
this.attached || (this.attached = !0, this.navigator.attach(), window.addEventListener("popstate", this.onPopState), await this.syncHistory());
|
|
2601
|
-
}
|
|
2602
|
-
/**
|
|
2603
|
-
* Goes back in history by 1.
|
|
2604
|
-
*/
|
|
2605
|
-
back() {
|
|
2606
|
-
this.navigator.back();
|
|
2607
|
-
}
|
|
2608
|
-
/**
|
|
2609
|
-
* Detaches current navigator from the browser history.
|
|
2610
|
-
*/
|
|
2611
|
-
detach() {
|
|
2612
|
-
this.attached = !1, this.navigator.detach(), window.removeEventListener("popstate", this.onPopState);
|
|
2613
|
-
}
|
|
2614
|
-
/**
|
|
2615
|
-
* Goes forward in history.
|
|
2616
|
-
*/
|
|
2617
|
-
forward() {
|
|
2618
|
-
return this.navigator.forward();
|
|
2619
|
-
}
|
|
2620
|
-
/**
|
|
2621
|
-
* Current history cursor.
|
|
2622
|
-
*/
|
|
2623
|
-
get index() {
|
|
2624
|
-
return this.navigator.index;
|
|
2625
|
-
}
|
|
2626
|
-
/**
|
|
2627
|
-
* Current history item identifier.
|
|
2628
|
-
*/
|
|
2629
|
-
get id() {
|
|
2630
|
-
return this.navigator.current.id;
|
|
2631
|
-
}
|
|
2632
|
-
/**
|
|
2633
|
-
* Changes currently active history item index by the specified delta. This method doesn't
|
|
2634
|
-
* change index in case, the updated index points to the non-existing history item. This behavior
|
|
2635
|
-
* is preserved until the `fit` argument is specified.
|
|
2636
|
-
* @param delta - index delta.
|
|
2637
|
-
* @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
|
|
2638
|
-
*/
|
|
2639
|
-
go(t, s) {
|
|
2640
|
-
return this.navigator.go(t, s);
|
|
2641
|
-
}
|
|
2642
|
-
/**
|
|
2643
|
-
* Goes to the specified index. Method does nothing in case, passed index is out of bounds.
|
|
2644
|
-
*
|
|
2645
|
-
* If "fit" option was specified and index is out of bounds, it will be cut to the nearest
|
|
2646
|
-
* bound.
|
|
2647
|
-
* @param index - target index.
|
|
2648
|
-
* @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
|
|
2649
|
-
*/
|
|
2650
|
-
goTo(t, s) {
|
|
2651
|
-
this.navigator.goTo(t, s);
|
|
2652
|
-
}
|
|
2653
|
-
/**
|
|
2654
|
-
* Current history item hash.
|
|
2655
|
-
* @see URL.hash
|
|
2656
|
-
* @example
|
|
2657
|
-
* "", "#my-hash"
|
|
2658
|
-
*/
|
|
2659
|
-
get hash() {
|
|
2660
|
-
return (this.navigator.current.params || {}).hash || "";
|
|
2661
|
-
}
|
|
2662
|
-
/**
|
|
2663
|
-
* True if navigator has items before the current item.
|
|
2664
|
-
*/
|
|
2665
|
-
get hasPrev() {
|
|
2666
|
-
return this.navigator.hasPrev;
|
|
2667
|
-
}
|
|
2668
|
-
/**
|
|
2669
|
-
* True if navigator has items after the current item.
|
|
2670
|
-
*/
|
|
2671
|
-
get hasNext() {
|
|
2672
|
-
return this.navigator.hasNext;
|
|
2673
|
-
}
|
|
2674
|
-
/**
|
|
2675
|
-
* Navigation history.
|
|
2676
|
-
*/
|
|
2677
|
-
get history() {
|
|
2678
|
-
return this.navigator.history.map(G);
|
|
2679
|
-
}
|
|
2680
|
-
/**
|
|
2681
|
-
* Path, including pathname, search and hash.
|
|
2682
|
-
* @example Pathname only.
|
|
2683
|
-
* "/pathname"
|
|
2684
|
-
* @example Pathname + search.
|
|
2685
|
-
* "/pathname?search"
|
|
2686
|
-
* @example Pathname + hash.
|
|
2687
|
-
* "/pathname#hash"
|
|
2688
|
-
* @example Pathname + search + hash.
|
|
2689
|
-
* "/pathname?search#hash"
|
|
2690
|
-
*/
|
|
2691
|
-
get path() {
|
|
2692
|
-
return B(this);
|
|
2693
|
-
}
|
|
2694
|
-
/**
|
|
2695
|
-
* Current pathname. Always starts with the slash.
|
|
2696
|
-
* @see URL.pathname
|
|
2697
|
-
* @example
|
|
2698
|
-
* "/", "/abc"
|
|
2699
|
-
*/
|
|
2700
|
-
get pathname() {
|
|
2701
|
-
return this.navigator.current.pathname;
|
|
2702
|
-
}
|
|
2703
|
-
/**
|
|
2704
|
-
* Depending on the current navigation type, parses incoming path and returns it presented as
|
|
2705
|
-
* an object. In other words, this method parses the passed path and returns object, describing
|
|
2706
|
-
* how the navigator "sees" it.
|
|
2707
|
-
*
|
|
2708
|
-
* @example Hash mode is omitted.
|
|
2709
|
-
* parsePath('/abc?a=1#hash');
|
|
2710
|
-
* // { pathname: '/abc', search: '?a=1', hash: '#hash' }
|
|
2711
|
-
* parsePath('http://example.com/abc?a=1#hash');
|
|
2712
|
-
* // { pathname: '/abc', search: '?a=1', hash: '#hash' }
|
|
2713
|
-
*
|
|
2714
|
-
* @example Hash mode is enabled.
|
|
2715
|
-
* parsePath('/abc?a=1#tma?is=cool#yeah');
|
|
2716
|
-
* // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
|
|
2717
|
-
* parsePath('http://example.com/abc?a=1#tma?is=cool#yeah');
|
|
2718
|
-
* // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
|
|
2719
|
-
*/
|
|
2720
|
-
parsePath(t) {
|
|
2721
|
-
let s = M(t);
|
|
2722
|
-
return this.hashMode && (s = M(s.hash.slice(1))), {
|
|
2723
|
-
pathname: s.pathname,
|
|
2724
|
-
search: s.search,
|
|
2725
|
-
hash: s.hash
|
|
2726
|
-
};
|
|
2727
|
-
}
|
|
2728
|
-
push(t, s) {
|
|
2729
|
-
const n = K(t, this.path), { state: r = s } = n.params;
|
|
2730
|
-
this.navigator.push({ ...n, params: { ...n.params, state: r } });
|
|
2731
|
-
}
|
|
2732
|
-
replace(t, s) {
|
|
2733
|
-
const n = K(t, this.path), { state: r = s } = n.params;
|
|
2734
|
-
this.navigator.replace({ ...n, params: { ...n.params, state: r } });
|
|
2735
|
-
}
|
|
2736
|
-
/**
|
|
2737
|
-
* Combines the navigator `base` property with the passed path data applying the navigator
|
|
2738
|
-
* navigation mode.
|
|
2739
|
-
* @param value - path presented as string or URLLike.
|
|
2740
|
-
*/
|
|
2741
|
-
renderPath(t) {
|
|
2742
|
-
const s = (this.base.length === 1 ? "" : this.base) + O(B(t), "/");
|
|
2743
|
-
return this.hashMode ? O(s.slice(1), this.hashMode === "classic" ? "#" : "#/") : s;
|
|
2744
|
-
}
|
|
2745
|
-
/**
|
|
2746
|
-
* Synchronizes current navigator state with browser history.
|
|
2747
|
-
*/
|
|
2748
|
-
async syncHistory() {
|
|
2749
|
-
window.removeEventListener("popstate", this.onPopState);
|
|
2750
|
-
const { state: t } = this, s = this.renderPath(this);
|
|
2751
|
-
await Ts(), this.hasPrev && this.hasNext ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s), window.history.pushState(J, ""), await I(-1)) : this.hasPrev ? (window.history.replaceState(z, ""), window.history.pushState(t, "", s)) : this.hasNext ? (window.history.replaceState(t, s), window.history.pushState(J, ""), await I(-1)) : (window.history.replaceState(mt, ""), window.history.pushState(t, "", s)), window.addEventListener("popstate", this.onPopState);
|
|
2752
|
-
}
|
|
2753
|
-
/**
|
|
2754
|
-
* Current query parameters.
|
|
2755
|
-
* @see URL.search
|
|
2756
|
-
* @example
|
|
2757
|
-
* "", "?", "?a=1"
|
|
2758
|
-
*/
|
|
2759
|
-
get search() {
|
|
2760
|
-
return (this.navigator.current.params || {}).search || "";
|
|
2761
|
-
}
|
|
2762
|
-
/**
|
|
2763
|
-
* Current history item state.
|
|
2764
|
-
*/
|
|
2765
|
-
get state() {
|
|
2766
|
-
return (this.navigator.current.params || {}).state;
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
function Rs(e) {
|
|
2770
|
-
e || (e = {});
|
|
2771
|
-
const { href: t, hash: s } = window.location;
|
|
2772
|
-
let n = B(
|
|
2773
|
-
e.hashMode === null ? t : s.includes("?") ? s.slice(1) : `?${s.slice(1)}`
|
|
2774
|
-
);
|
|
2775
|
-
const r = e.base ? Qt(e.base) : void 0;
|
|
2776
|
-
if (r) {
|
|
2777
|
-
if (!n.startsWith(r))
|
|
2778
|
-
throw b(
|
|
2779
|
-
be,
|
|
2780
|
-
`Path "${n}" expected to be starting with "${r}"`
|
|
2781
|
-
);
|
|
2782
|
-
n = n.slice(r.length);
|
|
2783
|
-
}
|
|
2784
|
-
return new Yt([n], 0, e);
|
|
2785
|
-
}
|
|
2786
|
-
function an(e) {
|
|
2787
|
-
const t = e.match(/#(.+)/);
|
|
2788
|
-
return t ? t[1] : null;
|
|
2789
|
-
}
|
|
2790
|
-
function As(e, t) {
|
|
2791
|
-
if (Gt()) {
|
|
2792
|
-
const s = sessionStorage.getItem(e);
|
|
2793
|
-
if (s)
|
|
2794
|
-
try {
|
|
2795
|
-
const { index: n, history: r } = JSON.parse(s);
|
|
2796
|
-
return new Yt(
|
|
2797
|
-
r,
|
|
2798
|
-
n,
|
|
2799
|
-
t
|
|
2800
|
-
);
|
|
2801
|
-
} catch (n) {
|
|
2802
|
-
console.error("Unable to restore hash navigator state.", n);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
return Rs(t);
|
|
2806
|
-
}
|
|
2807
|
-
function cn(e, t) {
|
|
2808
|
-
const s = As(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
|
|
2809
|
-
index: s.index,
|
|
2810
|
-
history: s.history
|
|
2811
|
-
}));
|
|
2812
|
-
return s.on("change", n), n(), s;
|
|
2813
|
-
}
|
|
2814
|
-
function _(e) {
|
|
2815
|
-
return (t, s, ...n) => (r) => bt(s, ut(() => ut({
|
|
2816
|
-
[t]: e(...n)
|
|
2817
|
-
}, r)));
|
|
2818
|
-
}
|
|
2819
|
-
const Zt = ee();
|
|
2820
|
-
function Is() {
|
|
2821
|
-
const e = se(Zt);
|
|
2822
|
-
if (!e)
|
|
2823
|
-
throw new Error("useSDK was used outside of SDKProvider.");
|
|
2824
|
-
return e;
|
|
2825
|
-
}
|
|
2826
|
-
function g(e) {
|
|
2827
|
-
return (...t) => {
|
|
2828
|
-
const s = Is()(e, ...t), n = () => s.signal();
|
|
2829
|
-
return Object.defineProperty(n, "error", () => s.error), n;
|
|
2830
|
-
};
|
|
2831
|
-
}
|
|
2832
|
-
const ks = g(He), hn = _(ks), qs = g(Ge), pn = _(qs), Os = g(ze), un = _(Os), Ns = g(Ze), ln = _(Ns), Ds = g(ts), dn = _(Ds), Vs = g(ss), _n = _(Vs), Ms = g(rs), gn = _(Ms), Bs = g(os), fn = _(Bs), $s = g(ps), wn = _($s), Ls = g(ds), mn = _(Ls), Us = g(gs), bn = _(Us), Hs = g(ws), vn = _(Hs), Ws = g(bs), yn = _(Ws), js = g(ys), En = _(js), Gs = g(Ps), Pn = _(Gs), xn = (e) => {
|
|
2833
|
-
const t = /* @__PURE__ */ new Map(), s = (n, ...r) => {
|
|
2834
|
-
if (t.has(n))
|
|
2835
|
-
return t.get(n);
|
|
2836
|
-
function i(l) {
|
|
2837
|
-
return t.set(n, l), l;
|
|
2838
|
-
}
|
|
2839
|
-
let o;
|
|
2840
|
-
try {
|
|
2841
|
-
o = n(...r);
|
|
2842
|
-
} catch (l) {
|
|
2843
|
-
return i({
|
|
2844
|
-
error: l,
|
|
2845
|
-
signal: () => {
|
|
2846
|
-
throw l;
|
|
2847
|
-
}
|
|
2848
|
-
});
|
|
2849
|
-
}
|
|
2850
|
-
let a;
|
|
2851
|
-
Array.isArray(o) && ([o, a] = o);
|
|
2852
|
-
const [h] = ne(() => o), u = _t(() => {
|
|
2853
|
-
if (h.state !== "ready")
|
|
2854
|
-
return;
|
|
2855
|
-
const l = h();
|
|
2856
|
-
if (!l || !("on" in l))
|
|
2857
|
-
return l;
|
|
2858
|
-
const Xt = re((V) => (V(l), l.on("change", () => V(l)))), te = Object.getPrototypeOf(l), W = {};
|
|
2859
|
-
return new Proxy(l, {
|
|
2860
|
-
get(V, C) {
|
|
2861
|
-
if (!(C in W)) {
|
|
2862
|
-
const pt = Reflect.getOwnPropertyDescriptor(te, C);
|
|
2863
|
-
W[C] = pt && "get" in pt ? _t(() => Xt()[C]) : () => Reflect.get(V, C);
|
|
2864
|
-
}
|
|
2865
|
-
return W[C]();
|
|
2866
|
-
}
|
|
2867
|
-
});
|
|
2868
|
-
});
|
|
2869
|
-
return i({
|
|
2870
|
-
signal() {
|
|
2871
|
-
if (h.error)
|
|
2872
|
-
throw h.error;
|
|
2873
|
-
return u();
|
|
2874
|
-
},
|
|
2875
|
-
get error() {
|
|
2876
|
-
return h.error;
|
|
2877
|
-
},
|
|
2878
|
-
cleanup: a
|
|
2879
|
-
});
|
|
2880
|
-
};
|
|
2881
|
-
return lt(() => {
|
|
2882
|
-
he(e.debug || !1);
|
|
2883
|
-
}), lt(() => {
|
|
2884
|
-
nt() && dt(xs(e.acceptCustomStyles));
|
|
2885
|
-
}), dt(() => {
|
|
2886
|
-
t.forEach((n) => n.cleanup && n.cleanup());
|
|
2887
|
-
}), bt(Zt.Provider, {
|
|
2888
|
-
value: s,
|
|
2889
|
-
get children() {
|
|
2890
|
-
return e.children;
|
|
2891
|
-
}
|
|
2892
|
-
});
|
|
2893
|
-
};
|
|
2894
7
|
export {
|
|
2895
|
-
|
|
2896
|
-
Ss as BasicNavigator,
|
|
2897
|
-
We as BiometryManager,
|
|
2898
|
-
Yt as BrowserNavigator,
|
|
2899
|
-
Ke as ClosingBehavior,
|
|
2900
|
-
Ye as CloudStorage,
|
|
2901
|
-
be as ERR_INVALID_PATH_BASE,
|
|
2902
|
-
_e as ERR_INVOKE_CUSTOM_METHOD_RESPONSE,
|
|
2903
|
-
le as ERR_METHOD_PARAMETER_UNSUPPORTED,
|
|
2904
|
-
ue as ERR_METHOD_UNSUPPORTED,
|
|
2905
|
-
we as ERR_NAVIGATION_HISTORY_EMPTY,
|
|
2906
|
-
me as ERR_NAVIGATION_INDEX_INVALID,
|
|
2907
|
-
zs as ERR_NAVIGATION_ITEM_INVALID,
|
|
2908
|
-
Et as ERR_PARSE,
|
|
2909
|
-
Js as ERR_SSR_INIT,
|
|
2910
|
-
ge as ERR_TIMED_OUT,
|
|
2911
|
-
fe as ERR_UNEXPECTED_TYPE,
|
|
2912
|
-
de as ERR_UNKNOWN_ENV,
|
|
2913
|
-
k as EventEmitter,
|
|
2914
|
-
Xe as HapticFeedback,
|
|
2915
|
-
es as InitData,
|
|
2916
|
-
ns as Invoice,
|
|
2917
|
-
is as MainButton,
|
|
2918
|
-
hs as MiniApp,
|
|
2919
|
-
ls as Popup,
|
|
2920
|
-
_s as QRScanner,
|
|
2921
|
-
$ as SDKError,
|
|
2922
|
-
xn as SDKProvider,
|
|
2923
|
-
fs as SettingsButton,
|
|
2924
|
-
ms as ThemeParams,
|
|
2925
|
-
vs as Utils,
|
|
2926
|
-
Es as Viewport,
|
|
2927
|
-
Qe as array,
|
|
2928
|
-
Xs as bindMiniAppCSSVars,
|
|
2929
|
-
tn as bindThemeParamsCSSVars,
|
|
2930
|
-
en as bindViewportCSSVars,
|
|
2931
|
-
y as boolean,
|
|
2932
|
-
It as captureSameReq,
|
|
2933
|
-
Z as classNames,
|
|
2934
|
-
Te as compareVersions,
|
|
2935
|
-
Rs as createBrowserNavigatorFromLocation,
|
|
2936
|
-
Ae as createPostEvent,
|
|
2937
|
-
M as createSafeURL,
|
|
2938
|
-
Dt as date,
|
|
2939
|
-
an as getHash,
|
|
2940
|
-
Qt as getPathname,
|
|
2941
|
-
He as initBackButton,
|
|
2942
|
-
Ge as initBiometryManager,
|
|
2943
|
-
ze as initClosingBehavior,
|
|
2944
|
-
Ze as initCloudStorage,
|
|
2945
|
-
ts as initHapticFeedback,
|
|
2946
|
-
ss as initInitData,
|
|
2947
|
-
rs as initInvoice,
|
|
2948
|
-
os as initMainButton,
|
|
2949
|
-
ps as initMiniApp,
|
|
2950
|
-
cn as initNavigator,
|
|
2951
|
-
ds as initPopup,
|
|
2952
|
-
gs as initQRScanner,
|
|
2953
|
-
ws as initSettingsButton,
|
|
2954
|
-
bs as initThemeParams,
|
|
2955
|
-
ys as initUtils,
|
|
2956
|
-
Ps as initViewport,
|
|
2957
|
-
xs as initWeb,
|
|
2958
|
-
A as invokeCustomMethod,
|
|
2959
|
-
Ot as isColorDark,
|
|
2960
|
-
nt as isIframe,
|
|
2961
|
-
Gt as isPageReload,
|
|
2962
|
-
st as isRGB,
|
|
2963
|
-
ve as isRGBShort,
|
|
2964
|
-
Cs as isSDKError,
|
|
2965
|
-
on as isSDKErrorOfType,
|
|
2966
|
-
sn as isSSR,
|
|
2967
|
-
nn as isTMA,
|
|
2968
|
-
f as json,
|
|
2969
|
-
Qs as mergeClassNames,
|
|
2970
|
-
rn as mockTelegramEnv,
|
|
2971
|
-
P as number,
|
|
2972
|
-
H as off,
|
|
2973
|
-
v as on,
|
|
2974
|
-
Ys as parseInitData,
|
|
2975
|
-
at as parseLaunchParams,
|
|
2976
|
-
Jt as parseThemeParams,
|
|
2977
|
-
q as postEvent,
|
|
2978
|
-
w as request,
|
|
2979
|
-
je as requestBiometryInfo,
|
|
2980
|
-
Zs as requestThemeParams,
|
|
2981
|
-
Ft as requestViewport,
|
|
2982
|
-
$e as retrieveLaunchParams,
|
|
2983
|
-
Ct as rgb,
|
|
2984
|
-
ot as searchParams,
|
|
2985
|
-
Be as serializeLaunchParams,
|
|
2986
|
-
Wt as serializeThemeParams,
|
|
2987
|
-
E as setCSSVar,
|
|
2988
|
-
he as setDebug,
|
|
2989
|
-
Fs as setTargetOrigin,
|
|
2990
|
-
p as string,
|
|
2991
|
-
ae as subscribe,
|
|
2992
|
-
x as supports,
|
|
2993
|
-
Re as targetOrigin,
|
|
2994
|
-
xt as toRGB,
|
|
2995
|
-
yt as unsubscribe,
|
|
2996
|
-
B as urlToPath,
|
|
2997
|
-
ks as useBackButton,
|
|
2998
|
-
qs as useBiometryManager,
|
|
2999
|
-
Os as useClosingBehavior,
|
|
3000
|
-
Ns as useCloudStorage,
|
|
3001
|
-
Ds as useHapticFeedback,
|
|
3002
|
-
Vs as useInitData,
|
|
3003
|
-
Ms as useInvoice,
|
|
3004
|
-
Bs as useMainButton,
|
|
3005
|
-
$s as useMiniApp,
|
|
3006
|
-
Ls as usePopup,
|
|
3007
|
-
Us as useQRScanner,
|
|
3008
|
-
Is as useSDK,
|
|
3009
|
-
Hs as useSettingsButton,
|
|
3010
|
-
Ws as useThemeParams,
|
|
3011
|
-
js as useUtils,
|
|
3012
|
-
Gs as useViewport,
|
|
3013
|
-
hn as withBackButton,
|
|
3014
|
-
pn as withBiometryManager,
|
|
3015
|
-
un as withClosingBehavior,
|
|
3016
|
-
ln as withCloudStorage,
|
|
3017
|
-
dn as withHapticFeedback,
|
|
3018
|
-
_n as withInitData,
|
|
3019
|
-
gn as withInvoice,
|
|
3020
|
-
fn as withMainButton,
|
|
3021
|
-
wn as withMiniApp,
|
|
3022
|
-
mn as withPopup,
|
|
3023
|
-
bn as withQRScanner,
|
|
3024
|
-
vn as withSettingsButton,
|
|
3025
|
-
yn as withThemeParams,
|
|
3026
|
-
qt as withTimeout,
|
|
3027
|
-
En as withUtils,
|
|
3028
|
-
Pn as withViewport
|
|
8
|
+
p as useSignal
|
|
3029
9
|
};
|
|
3030
10
|
//# sourceMappingURL=index.js.map
|