@core-ease/telegram-kit 3.0.1
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 +21 -0
- package/README.md +299 -0
- package/dist/animation/index.d.mts +4 -0
- package/dist/animation/index.d.ts +4 -0
- package/dist/animation/index.js +2413 -0
- package/dist/animation/index.mjs +5 -0
- package/dist/animation/lottie/index.d.mts +10 -0
- package/dist/animation/lottie/index.d.ts +10 -0
- package/dist/animation/lottie/index.js +2313 -0
- package/dist/animation/lottie/index.mjs +4 -0
- package/dist/animation/tgs/index.d.mts +18 -0
- package/dist/animation/tgs/index.d.ts +18 -0
- package/dist/animation/tgs/index.js +2402 -0
- package/dist/animation/tgs/index.mjs +4 -0
- package/dist/bot/index.d.mts +477 -0
- package/dist/bot/index.d.ts +477 -0
- package/dist/bot/index.js +870 -0
- package/dist/bot/index.mjs +847 -0
- package/dist/bot-D8BnLWIi.d.mts +2041 -0
- package/dist/bot-D8BnLWIi.d.ts +2041 -0
- package/dist/browser.global.js +23 -0
- package/dist/chunk-7AARTHNW.mjs +40 -0
- package/dist/chunk-7CVYPKAL.mjs +15 -0
- package/dist/chunk-B3PWALX5.mjs +4418 -0
- package/dist/chunk-BQEUEAVK.mjs +2262 -0
- package/dist/chunk-FPWYSKK2.mjs +3089 -0
- package/dist/chunk-JXK5HCDV.mjs +254 -0
- package/dist/chunk-OMH2JGOH.mjs +88 -0
- package/dist/chunk-PXO36YTU.mjs +38 -0
- package/dist/core/index.d.mts +151 -0
- package/dist/core/index.d.ts +151 -0
- package/dist/core/index.js +3837 -0
- package/dist/core/index.mjs +495 -0
- package/dist/dev/index.d.mts +77 -0
- package/dist/dev/index.d.ts +77 -0
- package/dist/dev/index.js +3214 -0
- package/dist/dev/index.mjs +151 -0
- package/dist/engine-BDm1_hzn.d.mts +382 -0
- package/dist/engine-BDm1_hzn.d.ts +382 -0
- package/dist/format/index.d.mts +61 -0
- package/dist/format/index.d.ts +61 -0
- package/dist/format/index.js +121 -0
- package/dist/format/index.mjs +112 -0
- package/dist/hooks/index.d.mts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +4234 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/hooks-C5Per70R.d.mts +1066 -0
- package/dist/hooks-C5Per70R.d.ts +1066 -0
- package/dist/index.d.mts +849 -0
- package/dist/index.d.ts +849 -0
- package/dist/index.js +5026 -0
- package/dist/index.mjs +478 -0
- package/dist/keyboards/index.d.mts +50 -0
- package/dist/keyboards/index.d.ts +50 -0
- package/dist/keyboards/index.js +127 -0
- package/dist/keyboards/index.mjs +124 -0
- package/dist/links/index.d.mts +53 -0
- package/dist/links/index.d.ts +53 -0
- package/dist/links/index.js +139 -0
- package/dist/links/index.mjs +133 -0
- package/dist/lottie/index.d.mts +3 -0
- package/dist/lottie/index.d.ts +3 -0
- package/dist/lottie/index.js +2313 -0
- package/dist/lottie/index.mjs +4 -0
- package/dist/qr/index.d.mts +75 -0
- package/dist/qr/index.d.ts +75 -0
- package/dist/qr/index.js +983 -0
- package/dist/qr/index.mjs +946 -0
- package/dist/sdk/index.d.mts +322 -0
- package/dist/sdk/index.d.ts +322 -0
- package/dist/sdk/index.js +3138 -0
- package/dist/sdk/index.mjs +2 -0
- package/dist/server/index.d.mts +28 -0
- package/dist/server/index.d.ts +28 -0
- package/dist/server/index.js +254 -0
- package/dist/server/index.mjs +246 -0
- package/dist/tgs/index.d.mts +3 -0
- package/dist/tgs/index.d.ts +3 -0
- package/dist/tgs/index.js +2402 -0
- package/dist/tgs/index.mjs +4 -0
- package/dist/webapp-B-3_74nK.d.mts +842 -0
- package/dist/webapp-B-3_74nK.d.ts +842 -0
- package/dist/webapp-BDi9q3-a.d.mts +42 -0
- package/dist/webapp-YvmwFYUQ.d.ts +42 -0
- package/package.json +165 -0
|
@@ -0,0 +1,3089 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __spreadValues } from './chunk-7AARTHNW.mjs';
|
|
3
|
+
|
|
4
|
+
// src/sdk/_internal/core/utils.ts
|
|
5
|
+
function urlSafeDecode(urlencoded) {
|
|
6
|
+
try {
|
|
7
|
+
urlencoded = urlencoded.replace(/\+/g, "%20");
|
|
8
|
+
return decodeURIComponent(urlencoded);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return urlencoded;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function urlParseQueryString(queryString) {
|
|
14
|
+
const params = {};
|
|
15
|
+
if (!queryString.length) {
|
|
16
|
+
return params;
|
|
17
|
+
}
|
|
18
|
+
const queryStringParams = queryString.split("&");
|
|
19
|
+
for (let i = 0; i < queryStringParams.length; i++) {
|
|
20
|
+
const param = queryStringParams[i].split("=");
|
|
21
|
+
const paramName = urlSafeDecode(param[0]);
|
|
22
|
+
const paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
|
|
23
|
+
params[paramName] = paramValue;
|
|
24
|
+
}
|
|
25
|
+
return params;
|
|
26
|
+
}
|
|
27
|
+
function urlParseHashParams(locationHash) {
|
|
28
|
+
locationHash = locationHash.replace(/^#/, "");
|
|
29
|
+
const params = {};
|
|
30
|
+
if (!locationHash.length) {
|
|
31
|
+
return params;
|
|
32
|
+
}
|
|
33
|
+
if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
|
|
34
|
+
params._path = urlSafeDecode(locationHash);
|
|
35
|
+
return params;
|
|
36
|
+
}
|
|
37
|
+
const qIndex = locationHash.indexOf("?");
|
|
38
|
+
if (qIndex >= 0) {
|
|
39
|
+
const pathParam = locationHash.substr(0, qIndex);
|
|
40
|
+
params._path = urlSafeDecode(pathParam);
|
|
41
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
42
|
+
}
|
|
43
|
+
const queryParams = urlParseQueryString(locationHash);
|
|
44
|
+
for (const k in queryParams) {
|
|
45
|
+
params[k] = queryParams[k];
|
|
46
|
+
}
|
|
47
|
+
return params;
|
|
48
|
+
}
|
|
49
|
+
function urlAppendHashParams(url, addHash) {
|
|
50
|
+
const ind = url.indexOf("#");
|
|
51
|
+
if (ind < 0) {
|
|
52
|
+
return url + "#" + addHash;
|
|
53
|
+
}
|
|
54
|
+
const curHash = url.substr(ind + 1);
|
|
55
|
+
if (curHash.indexOf("=") >= 0 || curHash.indexOf("?") >= 0) {
|
|
56
|
+
return url + "&" + addHash;
|
|
57
|
+
}
|
|
58
|
+
if (curHash.length > 0) {
|
|
59
|
+
return url + "?" + addHash;
|
|
60
|
+
}
|
|
61
|
+
return url + addHash;
|
|
62
|
+
}
|
|
63
|
+
var SESSION_STORAGE_PREFIX = "__telegram__";
|
|
64
|
+
function sessionStorageSet(key, value) {
|
|
65
|
+
try {
|
|
66
|
+
window.sessionStorage.setItem(SESSION_STORAGE_PREFIX + key, JSON.stringify(value));
|
|
67
|
+
return true;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function sessionStorageGet(key) {
|
|
73
|
+
try {
|
|
74
|
+
const raw = window.sessionStorage.getItem(SESSION_STORAGE_PREFIX + key);
|
|
75
|
+
return JSON.parse(raw);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function strTrim(str) {
|
|
81
|
+
return String(str).replace(/^\s+|\s+$/g, "");
|
|
82
|
+
}
|
|
83
|
+
function byteLength(str) {
|
|
84
|
+
if (typeof window !== "undefined" && window.Blob) {
|
|
85
|
+
try {
|
|
86
|
+
return new Blob([str]).size;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let s = str.length;
|
|
91
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
92
|
+
const code = str.charCodeAt(i);
|
|
93
|
+
if (code > 127 && code <= 2047) s++;
|
|
94
|
+
else if (code > 2047 && code <= 65535) s += 2;
|
|
95
|
+
if (code >= 56320 && code <= 57343) i--;
|
|
96
|
+
}
|
|
97
|
+
return s;
|
|
98
|
+
}
|
|
99
|
+
function versionCompare(v1, v2) {
|
|
100
|
+
const a1 = (typeof v1 === "string" ? v1 : "").replace(/^\s+|\s+$/g, "").split(".");
|
|
101
|
+
const a2 = (typeof v2 === "string" ? v2 : "").replace(/^\s+|\s+$/g, "").split(".");
|
|
102
|
+
const len = Math.max(a1.length, a2.length);
|
|
103
|
+
for (let i = 0; i < len; i++) {
|
|
104
|
+
const p1 = parseInt(a1[i]) || 0;
|
|
105
|
+
const p2 = parseInt(a2[i]) || 0;
|
|
106
|
+
if (p1 == p2) continue;
|
|
107
|
+
if (p1 > p2) return 1;
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
function parseColorToHex(color) {
|
|
113
|
+
const str = String(color);
|
|
114
|
+
let match;
|
|
115
|
+
if (match = /^\s*#([0-9a-f]{6})\s*$/i.exec(str)) {
|
|
116
|
+
return "#" + match[1].toLowerCase();
|
|
117
|
+
} else if (match = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(str)) {
|
|
118
|
+
return ("#" + match[1] + match[1] + match[2] + match[2] + match[3] + match[3]).toLowerCase();
|
|
119
|
+
} else if (match = /^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(str)) {
|
|
120
|
+
let r = parseInt(match[1]);
|
|
121
|
+
let g = parseInt(match[2]);
|
|
122
|
+
let b = parseInt(match[3]);
|
|
123
|
+
const rHex = (r < 16 ? "0" : "") + r.toString(16);
|
|
124
|
+
const gHex = (g < 16 ? "0" : "") + g.toString(16);
|
|
125
|
+
const bHex = (b < 16 ? "0" : "") + b.toString(16);
|
|
126
|
+
return "#" + rHex + gHex + bHex;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function isColorDark(rgb) {
|
|
131
|
+
let hex = rgb.replace(/[\s#]/g, "");
|
|
132
|
+
if (hex.length == 3) {
|
|
133
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
134
|
+
}
|
|
135
|
+
const r = parseInt(hex.substr(0, 2), 16);
|
|
136
|
+
const g = parseInt(hex.substr(2, 2), 16);
|
|
137
|
+
const b = parseInt(hex.substr(4, 2), 16);
|
|
138
|
+
const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b));
|
|
139
|
+
return hsp < 120;
|
|
140
|
+
}
|
|
141
|
+
function generateRandomId(len, taken) {
|
|
142
|
+
let tries = 100;
|
|
143
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
144
|
+
const charsLen = chars.length;
|
|
145
|
+
while (--tries) {
|
|
146
|
+
let id = "";
|
|
147
|
+
for (let i = 0; i < len; i++) {
|
|
148
|
+
id += chars[Math.floor(Math.random() * charsLen)];
|
|
149
|
+
}
|
|
150
|
+
if (!taken(id)) {
|
|
151
|
+
return id;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
throw new Error("WebAppCallbackIdGenerateFailed");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/sdk/_internal/core/webview.ts
|
|
158
|
+
var TelegramWebView = class {
|
|
159
|
+
constructor() {
|
|
160
|
+
this.eventHandlers = {};
|
|
161
|
+
this.handleParentMessage = (event) => {
|
|
162
|
+
if (event.source !== window.parent) return;
|
|
163
|
+
let dataParsed;
|
|
164
|
+
try {
|
|
165
|
+
dataParsed = JSON.parse(event.data);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (!dataParsed || !dataParsed.eventType) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (dataParsed.eventType == "set_custom_style") {
|
|
173
|
+
if (event.origin === "https://web.telegram.org" && this.iFrameStyleEl) {
|
|
174
|
+
this.iFrameStyleEl.innerHTML = dataParsed.eventData;
|
|
175
|
+
}
|
|
176
|
+
} else if (dataParsed.eventType == "reload_iframe") {
|
|
177
|
+
try {
|
|
178
|
+
window.parent.postMessage(JSON.stringify({ eventType: "iframe_will_reload" }), "*");
|
|
179
|
+
} catch (e) {
|
|
180
|
+
}
|
|
181
|
+
location.reload();
|
|
182
|
+
} else {
|
|
183
|
+
this.receiveEvent(dataParsed.eventType, dataParsed.eventData);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
/** Dispatches an incoming event to every subscriber of `eventType`. */
|
|
187
|
+
this.receiveEvent = (eventType, eventData) => {
|
|
188
|
+
console.log("[@core-ease/telegram-kit:webview] < receiveEvent", eventType, eventData);
|
|
189
|
+
this.callEventCallbacks(eventType, (callback) => callback(eventType, eventData));
|
|
190
|
+
};
|
|
191
|
+
let locationHash = "";
|
|
192
|
+
try {
|
|
193
|
+
locationHash = location.hash.toString();
|
|
194
|
+
} catch (e) {
|
|
195
|
+
}
|
|
196
|
+
const parsedParams = urlParseHashParams(locationHash);
|
|
197
|
+
const storedParams = sessionStorageGet("initParams");
|
|
198
|
+
if (storedParams) {
|
|
199
|
+
for (const key in storedParams) {
|
|
200
|
+
if (typeof parsedParams[key] === "undefined") {
|
|
201
|
+
parsedParams[key] = storedParams[key];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
sessionStorageSet("initParams", parsedParams);
|
|
206
|
+
this.initParams = parsedParams;
|
|
207
|
+
let isIframe = false;
|
|
208
|
+
try {
|
|
209
|
+
isIframe = window.parent != null && window !== window.parent;
|
|
210
|
+
if (isIframe) {
|
|
211
|
+
window.addEventListener("message", this.handleParentMessage);
|
|
212
|
+
this.iFrameStyleEl = document.createElement("style");
|
|
213
|
+
document.head.appendChild(this.iFrameStyleEl);
|
|
214
|
+
try {
|
|
215
|
+
window.parent.postMessage(
|
|
216
|
+
JSON.stringify({ eventType: "iframe_ready", eventData: { reload_supported: true } }),
|
|
217
|
+
"*"
|
|
218
|
+
);
|
|
219
|
+
} catch (e) {
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
}
|
|
224
|
+
this.isIframe = isIframe;
|
|
225
|
+
window.TelegramGameProxy_receiveEvent = this.receiveEvent;
|
|
226
|
+
window.TelegramGameProxy = { receiveEvent: this.receiveEvent };
|
|
227
|
+
}
|
|
228
|
+
/** Sends a named event + payload to the native Telegram client. */
|
|
229
|
+
postEvent(eventType, callback, eventData = "") {
|
|
230
|
+
const cb = callback || (() => {
|
|
231
|
+
});
|
|
232
|
+
console.log("[@core-ease/telegram-kit:webview] > postEvent", eventType, eventData);
|
|
233
|
+
if (window.TelegramWebviewProxy !== void 0) {
|
|
234
|
+
window.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
|
|
235
|
+
cb();
|
|
236
|
+
} else if (window.external && "notify" in window.external) {
|
|
237
|
+
window.external.notify(JSON.stringify({ eventType, eventData }));
|
|
238
|
+
cb();
|
|
239
|
+
} else if (this.isIframe) {
|
|
240
|
+
try {
|
|
241
|
+
const trustedTarget = "*";
|
|
242
|
+
window.parent.postMessage(JSON.stringify({ eventType, eventData }), trustedTarget);
|
|
243
|
+
cb();
|
|
244
|
+
} catch (e) {
|
|
245
|
+
cb(e);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
cb({ notAvailable: true });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
callEventCallbacks(eventType, func) {
|
|
252
|
+
const handlers = this.eventHandlers[eventType];
|
|
253
|
+
if (!handlers || !handlers.length) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
257
|
+
try {
|
|
258
|
+
func(handlers[i]);
|
|
259
|
+
} catch (e) {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
onEvent(eventType, callback) {
|
|
264
|
+
if (this.eventHandlers[eventType] === void 0) {
|
|
265
|
+
this.eventHandlers[eventType] = [];
|
|
266
|
+
}
|
|
267
|
+
if (this.eventHandlers[eventType].indexOf(callback) === -1) {
|
|
268
|
+
this.eventHandlers[eventType].push(callback);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
offEvent(eventType, callback) {
|
|
272
|
+
const handlers = this.eventHandlers[eventType];
|
|
273
|
+
if (handlers === void 0) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const index = handlers.indexOf(callback);
|
|
277
|
+
if (index === -1) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
handlers.splice(index, 1);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
var Utils = {
|
|
284
|
+
urlSafeDecode,
|
|
285
|
+
urlParseQueryString,
|
|
286
|
+
urlParseHashParams,
|
|
287
|
+
urlAppendHashParams,
|
|
288
|
+
sessionStorageSet,
|
|
289
|
+
sessionStorageGet
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// src/sdk/_internal/core/errors.ts
|
|
293
|
+
var WebAppErrorName = /* @__PURE__ */ ((WebAppErrorName2) => {
|
|
294
|
+
WebAppErrorName2["MethodUnsupported"] = "WebAppMethodUnsupported";
|
|
295
|
+
WebAppErrorName2["DataInvalid"] = "WebAppDataInvalid";
|
|
296
|
+
WebAppErrorName2["InlineModeDisabled"] = "WebAppInlineModeDisabled";
|
|
297
|
+
WebAppErrorName2["InlineQueryInvalid"] = "WebAppInlineQueryInvalid";
|
|
298
|
+
WebAppErrorName2["InlineChooseChatTypesInvalid"] = "WebAppInlineChooseChatTypesInvalid";
|
|
299
|
+
WebAppErrorName2["InlineChooseChatTypeInvalid"] = "WebAppInlineChooseChatTypeInvalid";
|
|
300
|
+
WebAppErrorName2["TgUrlInvalid"] = "WebAppTgUrlInvalid";
|
|
301
|
+
WebAppErrorName2["InvoiceUrlInvalid"] = "WebAppInvoiceUrlInvalid";
|
|
302
|
+
WebAppErrorName2["InvoiceOpened"] = "WebAppInvoiceOpened";
|
|
303
|
+
WebAppErrorName2["PopupOpened"] = "WebAppPopupOpened";
|
|
304
|
+
WebAppErrorName2["PopupParamInvalid"] = "WebAppPopupParamInvalid";
|
|
305
|
+
WebAppErrorName2["ScanQrPopupOpened"] = "WebAppScanQrPopupOpened";
|
|
306
|
+
WebAppErrorName2["ScanQrPopupParamInvalid"] = "WebAppScanQrPopupParamInvalid";
|
|
307
|
+
WebAppErrorName2["WriteAccessRequested"] = "WebAppWriteAccessRequested";
|
|
308
|
+
WebAppErrorName2["ContactRequested"] = "WebAppContactRequested";
|
|
309
|
+
WebAppErrorName2["DownloadFilePopupOpened"] = "WebAppDownloadFilePopupOpened";
|
|
310
|
+
WebAppErrorName2["DownloadFileParamInvalid"] = "WebAppDownloadFileParamInvalid";
|
|
311
|
+
WebAppErrorName2["MediaUrlInvalid"] = "WebAppMediaUrlInvalid";
|
|
312
|
+
WebAppErrorName2["ShareToStoryParamInvalid"] = "WebAppShareToStoryParamInvalid";
|
|
313
|
+
WebAppErrorName2["ShareMessageOpened"] = "WebAppShareMessageOpened";
|
|
314
|
+
WebAppErrorName2["RequestChatOpened"] = "WebAppRequestChatOpened";
|
|
315
|
+
WebAppErrorName2["EmojiStatusRequested"] = "WebAppEmojiStatusRequested";
|
|
316
|
+
WebAppErrorName2["EmojiStatusAccessRequested"] = "WebAppEmojiStatusAccessRequested";
|
|
317
|
+
WebAppErrorName2["HeaderColorInvalid"] = "WebAppHeaderColorInvalid";
|
|
318
|
+
WebAppErrorName2["HeaderColorKeyInvalid"] = "WebAppHeaderColorKeyInvalid";
|
|
319
|
+
WebAppErrorName2["BackgroundColorInvalid"] = "WebAppBackgroundColorInvalid";
|
|
320
|
+
WebAppErrorName2["BottomBarColorInvalid"] = "WebAppBottomBarColorInvalid";
|
|
321
|
+
WebAppErrorName2["BottomButtonParamInvalid"] = "WebAppBottomButtonParamInvalid";
|
|
322
|
+
WebAppErrorName2["HapticImpactStyleInvalid"] = "WebAppHapticImpactStyleInvalid";
|
|
323
|
+
WebAppErrorName2["HapticNotificationTypeInvalid"] = "WebAppHapticNotificationTypeInvalid";
|
|
324
|
+
WebAppErrorName2["HapticFeedbackTypeInvalid"] = "WebAppHapticFeedbackTypeInvalid";
|
|
325
|
+
WebAppErrorName2["BiometricManagerNotInited"] = "WebAppBiometricManagerNotInited";
|
|
326
|
+
WebAppErrorName2["BiometricManagerBiometricsNotAvailable"] = "WebAppBiometricManagerBiometricsNotAvailable";
|
|
327
|
+
WebAppErrorName2["BiometricManagerAccessRequested"] = "WebAppBiometricManagerAccessRequested";
|
|
328
|
+
WebAppErrorName2["BiometricManagerBiometricAccessNotGranted"] = "WebAppBiometricManagerBiometricAccessNotGranted";
|
|
329
|
+
WebAppErrorName2["BiometricManagerAuthenticationRequested"] = "WebAppBiometricManagerAuthenticationRequested";
|
|
330
|
+
WebAppErrorName2["BiometricManagerTokenInvalid"] = "WebAppBiometricManagerTokenInvalid";
|
|
331
|
+
WebAppErrorName2["BiometricManagerTokenUpdateRequested"] = "WebAppBiometricManagerTokenUpdateRequested";
|
|
332
|
+
WebAppErrorName2["BiometricManagerBiometricsAccessNotRequested"] = "WebAppBiometricManagerBiometricsAccessNotRequested";
|
|
333
|
+
WebAppErrorName2["BiometricRequestAccessParamInvalid"] = "WebAppBiometricRequestAccessParamInvalid";
|
|
334
|
+
WebAppErrorName2["LocationManagerNotInited"] = "WebAppLocationManagerNotInited";
|
|
335
|
+
WebAppErrorName2["LocationManagerLocationNotAvailable"] = "WebAppLocationManagerLocationNotAvailable";
|
|
336
|
+
WebAppErrorName2["LocationManagerLocationAccessNotRequested"] = "WebAppLocationManagerLocationAccessNotRequested";
|
|
337
|
+
WebAppErrorName2["CallbackIdGenerateFailed"] = "WebAppCallbackIdGenerateFailed";
|
|
338
|
+
return WebAppErrorName2;
|
|
339
|
+
})(WebAppErrorName || {});
|
|
340
|
+
var WebAppError = class _WebAppError extends Error {
|
|
341
|
+
constructor(name) {
|
|
342
|
+
super(name);
|
|
343
|
+
this.name = name;
|
|
344
|
+
this.message = name;
|
|
345
|
+
Object.setPrototypeOf(this, _WebAppError.prototype);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
function throwWebAppError(name) {
|
|
349
|
+
throw new WebAppError(name);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/sdk/_internal/core/kernel.ts
|
|
353
|
+
var WebAppKernel = class {
|
|
354
|
+
constructor(webView) {
|
|
355
|
+
/** Mutable current protocol version reported by the client, e.g. '8.0'. */
|
|
356
|
+
this._version = "6.0";
|
|
357
|
+
this.callbacks = {};
|
|
358
|
+
/** Height (px) reserved by the in-browser debug bottom bar, if active. */
|
|
359
|
+
this.bottomBarHeightPx = 0;
|
|
360
|
+
this.onCustomMethodInvoked = (_eventType, eventData) => {
|
|
361
|
+
var _a;
|
|
362
|
+
if (eventData.req_id && this.hasCallback(eventData.req_id)) {
|
|
363
|
+
const entry = this.takeCallback(eventData.req_id);
|
|
364
|
+
let res = null;
|
|
365
|
+
let err = null;
|
|
366
|
+
if (typeof eventData.result !== "undefined") {
|
|
367
|
+
res = eventData.result;
|
|
368
|
+
}
|
|
369
|
+
if (typeof eventData.error !== "undefined") {
|
|
370
|
+
err = eventData.error;
|
|
371
|
+
}
|
|
372
|
+
(_a = entry == null ? void 0 : entry.callback) == null ? void 0 : _a.call(entry, err, res);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
this.webView = webView;
|
|
376
|
+
this.initParams = webView.initParams;
|
|
377
|
+
if (this.initParams.tgWebAppVersion) {
|
|
378
|
+
this._version = this.initParams.tgWebAppVersion;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
get version() {
|
|
382
|
+
return this._version;
|
|
383
|
+
}
|
|
384
|
+
set version(v) {
|
|
385
|
+
this._version = v;
|
|
386
|
+
}
|
|
387
|
+
versionAtLeast(ver) {
|
|
388
|
+
return versionCompare(this._version, ver) >= 0;
|
|
389
|
+
}
|
|
390
|
+
/** Logs + throws `WebAppMethodUnsupported` for a method gated by version. */
|
|
391
|
+
requireVersion(ver, methodName) {
|
|
392
|
+
if (!this.versionAtLeast(ver)) {
|
|
393
|
+
console.error(`[@core-ease/telegram-kit] Method ${methodName} is not supported in version ${this._version}`);
|
|
394
|
+
throwWebAppError("WebAppMethodUnsupported" /* MethodUnsupported */);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/** Same as {@link requireVersion} but warns instead of throwing (soft-gated features). */
|
|
398
|
+
warnIfUnsupported(ver, featureName) {
|
|
399
|
+
if (!this.versionAtLeast(ver)) {
|
|
400
|
+
console.warn(`[@core-ease/telegram-kit] ${featureName} is not supported in version ${this._version}`);
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
setCssProperty(name, value) {
|
|
406
|
+
const root = document.documentElement;
|
|
407
|
+
if (root && root.style && root.style.setProperty) {
|
|
408
|
+
root.style.setProperty("--tg-" + name, value);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
strTrim(str) {
|
|
412
|
+
return strTrim(str);
|
|
413
|
+
}
|
|
414
|
+
byteLength(str) {
|
|
415
|
+
return byteLength(str);
|
|
416
|
+
}
|
|
417
|
+
/** Dispatches an internal `webview:<eventType>` event to WebApp-level subscribers. */
|
|
418
|
+
receiveWebViewEvent(eventType, ...args) {
|
|
419
|
+
this.webView.callEventCallbacks("webview:" + eventType, (callback) => {
|
|
420
|
+
callback.apply(null, args);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
onWebViewEvent(eventType, callback) {
|
|
424
|
+
this.webView.onEvent("webview:" + eventType, callback);
|
|
425
|
+
}
|
|
426
|
+
offWebViewEvent(eventType, callback) {
|
|
427
|
+
this.webView.offEvent("webview:" + eventType, callback);
|
|
428
|
+
}
|
|
429
|
+
/** Allocates a fresh request id and registers its pending callback. */
|
|
430
|
+
registerCallback(callback, len = 16) {
|
|
431
|
+
const id = generateRandomId(len, (candidate) => !!this.callbacks[candidate]);
|
|
432
|
+
this.callbacks[id] = { callback };
|
|
433
|
+
return id;
|
|
434
|
+
}
|
|
435
|
+
takeCallback(reqId) {
|
|
436
|
+
const entry = this.callbacks[reqId];
|
|
437
|
+
if (entry) {
|
|
438
|
+
delete this.callbacks[reqId];
|
|
439
|
+
}
|
|
440
|
+
return entry;
|
|
441
|
+
}
|
|
442
|
+
hasCallback(reqId) {
|
|
443
|
+
return !!this.callbacks[reqId];
|
|
444
|
+
}
|
|
445
|
+
/** Generic `web_app_invoke_custom_method` used by CloudStorage, contact lookup, etc. */
|
|
446
|
+
invokeCustomMethod(method, params, callback) {
|
|
447
|
+
this.requireVersion("6.9", "invokeCustomMethod");
|
|
448
|
+
const reqId = this.registerCallback(callback);
|
|
449
|
+
this.webView.postEvent("web_app_invoke_custom_method", void 0, {
|
|
450
|
+
req_id: reqId,
|
|
451
|
+
method,
|
|
452
|
+
params: params || {}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/sdk/_internal/theme/theme-manager.ts
|
|
458
|
+
var ThemeManager = class {
|
|
459
|
+
constructor(kernel) {
|
|
460
|
+
this.kernel = kernel;
|
|
461
|
+
this.themeParams = {};
|
|
462
|
+
this._colorScheme = "light";
|
|
463
|
+
this.backgroundColorValue = "bg_color";
|
|
464
|
+
this.appBackgroundColor = null;
|
|
465
|
+
this.headerColorKey = "bg_color";
|
|
466
|
+
this.headerColorValue = null;
|
|
467
|
+
this.appHeaderColorKey = null;
|
|
468
|
+
this.appHeaderColorValue = null;
|
|
469
|
+
this.bottomBarColorValue = "bottom_bar_bg_color";
|
|
470
|
+
this.appBottomBarColor = null;
|
|
471
|
+
/** Called after every bottom-bar color update, e.g. to refresh the debug bar. */
|
|
472
|
+
this.onBottomBarColorApplied = null;
|
|
473
|
+
const storedTheme = sessionStorageGet("themeParams");
|
|
474
|
+
const rawTheme = kernel.initParams.tgWebAppThemeParams;
|
|
475
|
+
if (rawTheme && rawTheme.length) {
|
|
476
|
+
try {
|
|
477
|
+
const parsed = JSON.parse(rawTheme);
|
|
478
|
+
if (parsed) this.setThemeParams(parsed);
|
|
479
|
+
} catch (e) {
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (storedTheme) {
|
|
483
|
+
this.setThemeParams(storedTheme);
|
|
484
|
+
}
|
|
485
|
+
const storedColors = sessionStorageGet("defaultColors");
|
|
486
|
+
const rawColors = kernel.initParams.tgWebAppDefaultColors;
|
|
487
|
+
if (rawColors && rawColors.length) {
|
|
488
|
+
try {
|
|
489
|
+
const parsed = JSON.parse(rawColors);
|
|
490
|
+
if (parsed) this.setDefaultColors(parsed);
|
|
491
|
+
} catch (e) {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (storedColors) {
|
|
495
|
+
this.setDefaultColors(storedColors);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
get colorScheme() {
|
|
499
|
+
return this._colorScheme;
|
|
500
|
+
}
|
|
501
|
+
getThemeParams() {
|
|
502
|
+
return this.themeParams;
|
|
503
|
+
}
|
|
504
|
+
setThemeParams(theme) {
|
|
505
|
+
if (theme.bg_color == "#1c1c1d" && theme.bg_color == theme.secondary_bg_color) {
|
|
506
|
+
theme.secondary_bg_color = "#2c2c2e";
|
|
507
|
+
}
|
|
508
|
+
for (const key in theme) {
|
|
509
|
+
const color = parseColorToHex(theme[key]);
|
|
510
|
+
if (color) {
|
|
511
|
+
this.themeParams[key] = color;
|
|
512
|
+
if (key == "bg_color") {
|
|
513
|
+
this._colorScheme = isColorDark(color) ? "dark" : "light";
|
|
514
|
+
this.kernel.setCssProperty("color-scheme", this._colorScheme);
|
|
515
|
+
}
|
|
516
|
+
const cssKey = "theme-" + key.split("_").join("-");
|
|
517
|
+
this.kernel.setCssProperty(cssKey, color);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
sessionStorageSet("themeParams", this.themeParams);
|
|
521
|
+
}
|
|
522
|
+
setDefaultColors(defColors) {
|
|
523
|
+
if (this._colorScheme == "dark") {
|
|
524
|
+
if (defColors.bg_dark_color) {
|
|
525
|
+
this.backgroundColorValue = defColors.bg_dark_color;
|
|
526
|
+
}
|
|
527
|
+
if (defColors.header_dark_color) {
|
|
528
|
+
this.headerColorKey = null;
|
|
529
|
+
this.headerColorValue = defColors.header_dark_color;
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
if (defColors.bg_color) {
|
|
533
|
+
this.backgroundColorValue = defColors.bg_color;
|
|
534
|
+
}
|
|
535
|
+
if (defColors.header_color) {
|
|
536
|
+
this.headerColorKey = null;
|
|
537
|
+
this.headerColorValue = defColors.header_color;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
sessionStorageSet("defaultColors", defColors);
|
|
541
|
+
}
|
|
542
|
+
// ---------------------------------------------------------------------
|
|
543
|
+
// Header color
|
|
544
|
+
// ---------------------------------------------------------------------
|
|
545
|
+
getHeaderColor() {
|
|
546
|
+
if (this.headerColorKey == "secondary_bg_color") {
|
|
547
|
+
return this.themeParams.secondary_bg_color;
|
|
548
|
+
} else if (this.headerColorKey == "bg_color") {
|
|
549
|
+
return this.themeParams.bg_color;
|
|
550
|
+
}
|
|
551
|
+
return this.headerColorValue;
|
|
552
|
+
}
|
|
553
|
+
setHeaderColor(color) {
|
|
554
|
+
if (!this.kernel.warnIfUnsupported("6.1", "Header color")) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (!this.kernel.versionAtLeast("6.9")) {
|
|
558
|
+
if (this.themeParams.bg_color && this.themeParams.bg_color == color) {
|
|
559
|
+
color = "bg_color";
|
|
560
|
+
} else if (this.themeParams.secondary_bg_color && this.themeParams.secondary_bg_color == color) {
|
|
561
|
+
color = "secondary_bg_color";
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
let headColor = null;
|
|
565
|
+
let colorKey = null;
|
|
566
|
+
if (color == "bg_color" || color == "secondary_bg_color") {
|
|
567
|
+
colorKey = color;
|
|
568
|
+
} else if (this.kernel.versionAtLeast("6.9")) {
|
|
569
|
+
headColor = parseColorToHex(color);
|
|
570
|
+
if (!headColor) {
|
|
571
|
+
console.error("[@core-ease/telegram-kit] Header color format is invalid", color);
|
|
572
|
+
throwWebAppError("WebAppHeaderColorInvalid" /* HeaderColorInvalid */);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!this.kernel.versionAtLeast("6.9") && colorKey != "bg_color" && colorKey != "secondary_bg_color") {
|
|
576
|
+
console.error(
|
|
577
|
+
"[@core-ease/telegram-kit] Header color key should be one of Telegram.WebApp.themeParams.bg_color, Telegram.WebApp.themeParams.secondary_bg_color, 'bg_color', 'secondary_bg_color'",
|
|
578
|
+
color
|
|
579
|
+
);
|
|
580
|
+
throwWebAppError("WebAppHeaderColorKeyInvalid" /* HeaderColorKeyInvalid */);
|
|
581
|
+
}
|
|
582
|
+
this.headerColorKey = colorKey;
|
|
583
|
+
this.headerColorValue = headColor || null;
|
|
584
|
+
this.updateHeaderColor();
|
|
585
|
+
}
|
|
586
|
+
updateHeaderColor() {
|
|
587
|
+
if (this.appHeaderColorKey != this.headerColorKey || this.appHeaderColorValue != this.headerColorValue) {
|
|
588
|
+
this.appHeaderColorKey = this.headerColorKey;
|
|
589
|
+
this.appHeaderColorValue = this.headerColorValue;
|
|
590
|
+
if (this.appHeaderColorValue) {
|
|
591
|
+
this.kernel.webView.postEvent("web_app_set_header_color", void 0, { color: this.appHeaderColorValue });
|
|
592
|
+
} else {
|
|
593
|
+
this.kernel.webView.postEvent("web_app_set_header_color", void 0, { color_key: this.appHeaderColorKey });
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
// ---------------------------------------------------------------------
|
|
598
|
+
// Background color
|
|
599
|
+
// ---------------------------------------------------------------------
|
|
600
|
+
getBackgroundColor() {
|
|
601
|
+
if (this.backgroundColorValue == "secondary_bg_color") {
|
|
602
|
+
return this.themeParams.secondary_bg_color;
|
|
603
|
+
} else if (this.backgroundColorValue == "bg_color") {
|
|
604
|
+
return this.themeParams.bg_color;
|
|
605
|
+
}
|
|
606
|
+
return this.backgroundColorValue;
|
|
607
|
+
}
|
|
608
|
+
setBackgroundColor(color) {
|
|
609
|
+
if (!this.kernel.warnIfUnsupported("6.1", "Background color")) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
let bgColor;
|
|
613
|
+
if (color == "bg_color" || color == "secondary_bg_color") {
|
|
614
|
+
bgColor = color;
|
|
615
|
+
} else {
|
|
616
|
+
const parsed = parseColorToHex(color);
|
|
617
|
+
if (!parsed) {
|
|
618
|
+
console.error("[@core-ease/telegram-kit] Background color format is invalid", color);
|
|
619
|
+
throwWebAppError("WebAppBackgroundColorInvalid" /* BackgroundColorInvalid */);
|
|
620
|
+
}
|
|
621
|
+
bgColor = parsed;
|
|
622
|
+
}
|
|
623
|
+
this.backgroundColorValue = bgColor;
|
|
624
|
+
this.updateBackgroundColor();
|
|
625
|
+
}
|
|
626
|
+
updateBackgroundColor() {
|
|
627
|
+
const color = this.getBackgroundColor();
|
|
628
|
+
if (this.appBackgroundColor != color) {
|
|
629
|
+
this.appBackgroundColor = color != null ? color : null;
|
|
630
|
+
this.kernel.webView.postEvent("web_app_set_background_color", void 0, { color });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
// ---------------------------------------------------------------------
|
|
634
|
+
// Bottom bar color
|
|
635
|
+
// ---------------------------------------------------------------------
|
|
636
|
+
getBottomBarColor() {
|
|
637
|
+
if (this.bottomBarColorValue == "bottom_bar_bg_color") {
|
|
638
|
+
return this.themeParams.bottom_bar_bg_color || this.themeParams.secondary_bg_color || "#ffffff";
|
|
639
|
+
} else if (this.bottomBarColorValue == "secondary_bg_color") {
|
|
640
|
+
return this.themeParams.secondary_bg_color;
|
|
641
|
+
} else if (this.bottomBarColorValue == "bg_color") {
|
|
642
|
+
return this.themeParams.bg_color;
|
|
643
|
+
}
|
|
644
|
+
return this.bottomBarColorValue;
|
|
645
|
+
}
|
|
646
|
+
setBottomBarColor(color) {
|
|
647
|
+
if (!this.kernel.warnIfUnsupported("7.10", "Bottom bar color")) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
let bgColor;
|
|
651
|
+
if (color == "bg_color" || color == "secondary_bg_color" || color == "bottom_bar_bg_color") {
|
|
652
|
+
bgColor = color;
|
|
653
|
+
} else {
|
|
654
|
+
const parsed = parseColorToHex(color);
|
|
655
|
+
if (!parsed) {
|
|
656
|
+
console.error("[@core-ease/telegram-kit] Bottom bar color format is invalid", color);
|
|
657
|
+
throwWebAppError("WebAppBottomBarColorInvalid" /* BottomBarColorInvalid */);
|
|
658
|
+
}
|
|
659
|
+
bgColor = parsed;
|
|
660
|
+
}
|
|
661
|
+
this.bottomBarColorValue = bgColor;
|
|
662
|
+
this.updateBottomBarColor();
|
|
663
|
+
}
|
|
664
|
+
updateBottomBarColor() {
|
|
665
|
+
var _a;
|
|
666
|
+
const color = this.getBottomBarColor();
|
|
667
|
+
if (this.appBottomBarColor != color) {
|
|
668
|
+
this.appBottomBarColor = color;
|
|
669
|
+
this.kernel.webView.postEvent("web_app_set_bottom_bar_color", void 0, { color });
|
|
670
|
+
}
|
|
671
|
+
(_a = this.onBottomBarColorApplied) == null ? void 0 : _a.call(this);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// src/sdk/_internal/theme/viewport-manager.ts
|
|
676
|
+
var ViewportManager = class {
|
|
677
|
+
constructor(kernel) {
|
|
678
|
+
this.kernel = kernel;
|
|
679
|
+
this.viewportHeightPx = false;
|
|
680
|
+
this.viewportStableHeightPx = false;
|
|
681
|
+
this._isExpanded = true;
|
|
682
|
+
this._safeAreaInset = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
683
|
+
this._contentSafeAreaInset = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
684
|
+
this._isFullscreen = false;
|
|
685
|
+
this._isOrientationLocked = false;
|
|
686
|
+
this._isClosingConfirmationEnabled = false;
|
|
687
|
+
this._isVerticalSwipesEnabled = true;
|
|
688
|
+
this.lastWindowHeight = typeof window !== "undefined" ? window.innerHeight : 0;
|
|
689
|
+
this.handleViewportChanged = (_eventType, eventData) => {
|
|
690
|
+
if (eventData.height) {
|
|
691
|
+
window.removeEventListener("resize", this.onWindowResize);
|
|
692
|
+
this.setViewportHeight(eventData);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
this.handleSafeAreaChanged = (_eventType, eventData) => {
|
|
696
|
+
if (eventData) this.setSafeAreaInset(eventData);
|
|
697
|
+
};
|
|
698
|
+
this.handleContentSafeAreaChanged = (_eventType, eventData) => {
|
|
699
|
+
if (eventData) this.setContentSafeAreaInset(eventData);
|
|
700
|
+
};
|
|
701
|
+
this.handleFullscreenChanged = (_eventType, eventData) => {
|
|
702
|
+
this.setFullscreen(eventData.is_fullscreen);
|
|
703
|
+
this.kernel.receiveWebViewEvent("fullscreenChanged");
|
|
704
|
+
};
|
|
705
|
+
this.handleFullscreenFailed = (_eventType, eventData) => {
|
|
706
|
+
if (eventData.error == "ALREADY_FULLSCREEN" && !this._isFullscreen) {
|
|
707
|
+
this.setFullscreen(true);
|
|
708
|
+
}
|
|
709
|
+
this.kernel.receiveWebViewEvent("fullscreenFailed", { error: eventData.error });
|
|
710
|
+
};
|
|
711
|
+
if (kernel.initParams.tgWebAppFullscreen) {
|
|
712
|
+
this.setFullscreen(true);
|
|
713
|
+
}
|
|
714
|
+
const storedFullscreen = sessionStorageGet("isFullscreen");
|
|
715
|
+
if (storedFullscreen) {
|
|
716
|
+
this.setFullscreen(storedFullscreen == "yes");
|
|
717
|
+
}
|
|
718
|
+
const storedOrientationLock = sessionStorageGet("isOrientationLocked");
|
|
719
|
+
if (storedOrientationLock) {
|
|
720
|
+
this.setOrientationLock(storedOrientationLock == "yes");
|
|
721
|
+
}
|
|
722
|
+
this.onWindowResize = this.onWindowResize.bind(this);
|
|
723
|
+
}
|
|
724
|
+
// ---------------------------------------------------------------------
|
|
725
|
+
// Getters mirroring the public WebApp properties
|
|
726
|
+
// ---------------------------------------------------------------------
|
|
727
|
+
get isExpanded() {
|
|
728
|
+
return this._isExpanded;
|
|
729
|
+
}
|
|
730
|
+
get viewportHeight() {
|
|
731
|
+
const raw = this.viewportHeightPx === false ? window.innerHeight : this.viewportHeightPx;
|
|
732
|
+
return raw - this.kernel.bottomBarHeightPx;
|
|
733
|
+
}
|
|
734
|
+
get viewportStableHeight() {
|
|
735
|
+
const raw = this.viewportStableHeightPx === false ? window.innerHeight : this.viewportStableHeightPx;
|
|
736
|
+
return raw - this.kernel.bottomBarHeightPx;
|
|
737
|
+
}
|
|
738
|
+
get safeAreaInset() {
|
|
739
|
+
return this._safeAreaInset;
|
|
740
|
+
}
|
|
741
|
+
get contentSafeAreaInset() {
|
|
742
|
+
return this._contentSafeAreaInset;
|
|
743
|
+
}
|
|
744
|
+
get isFullscreen() {
|
|
745
|
+
return this._isFullscreen;
|
|
746
|
+
}
|
|
747
|
+
get isOrientationLocked() {
|
|
748
|
+
return this._isOrientationLocked;
|
|
749
|
+
}
|
|
750
|
+
get isClosingConfirmationEnabled() {
|
|
751
|
+
return this._isClosingConfirmationEnabled;
|
|
752
|
+
}
|
|
753
|
+
get isVerticalSwipesEnabled() {
|
|
754
|
+
return this._isVerticalSwipesEnabled;
|
|
755
|
+
}
|
|
756
|
+
// ---------------------------------------------------------------------
|
|
757
|
+
// Viewport height
|
|
758
|
+
// ---------------------------------------------------------------------
|
|
759
|
+
/** Re-applies the current viewport CSS vars; call after bottom-bar height changes too. */
|
|
760
|
+
setViewportHeight(data) {
|
|
761
|
+
let emitEvent = false;
|
|
762
|
+
if (typeof data !== "undefined") {
|
|
763
|
+
this._isExpanded = !!data.is_expanded;
|
|
764
|
+
this.viewportHeightPx = data.height;
|
|
765
|
+
if (data.is_state_stable) {
|
|
766
|
+
this.viewportStableHeightPx = data.height;
|
|
767
|
+
}
|
|
768
|
+
emitEvent = true;
|
|
769
|
+
}
|
|
770
|
+
const bottomBarHeight = this.kernel.bottomBarHeightPx;
|
|
771
|
+
const height = this.viewportHeightPx !== false ? this.viewportHeightPx - bottomBarHeight + "px" : bottomBarHeight ? `calc(100vh - ${bottomBarHeight}px)` : "100vh";
|
|
772
|
+
const stableHeight = this.viewportStableHeightPx !== false ? this.viewportStableHeightPx - bottomBarHeight + "px" : bottomBarHeight ? `calc(100vh - ${bottomBarHeight}px)` : "100vh";
|
|
773
|
+
this.kernel.setCssProperty("viewport-height", height);
|
|
774
|
+
this.kernel.setCssProperty("viewport-stable-height", stableHeight);
|
|
775
|
+
if (emitEvent) {
|
|
776
|
+
this.kernel.receiveWebViewEvent("viewportChanged", { isStateStable: !!data.is_state_stable });
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
onWindowResize() {
|
|
780
|
+
if (this.lastWindowHeight != window.innerHeight) {
|
|
781
|
+
this.lastWindowHeight = window.innerHeight;
|
|
782
|
+
this.kernel.receiveWebViewEvent("viewportChanged", { isStateStable: true });
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
// ---------------------------------------------------------------------
|
|
786
|
+
// Safe area insets
|
|
787
|
+
// ---------------------------------------------------------------------
|
|
788
|
+
setSafeAreaInset(data) {
|
|
789
|
+
if (typeof data !== "undefined") {
|
|
790
|
+
if (typeof data.top !== "undefined") this._safeAreaInset.top = data.top;
|
|
791
|
+
if (typeof data.bottom !== "undefined") this._safeAreaInset.bottom = data.bottom;
|
|
792
|
+
if (typeof data.left !== "undefined") this._safeAreaInset.left = data.left;
|
|
793
|
+
if (typeof data.right !== "undefined") this._safeAreaInset.right = data.right;
|
|
794
|
+
this.kernel.receiveWebViewEvent("safeAreaChanged");
|
|
795
|
+
}
|
|
796
|
+
this.kernel.setCssProperty("safe-area-inset-top", this._safeAreaInset.top + "px");
|
|
797
|
+
this.kernel.setCssProperty("safe-area-inset-bottom", this._safeAreaInset.bottom + "px");
|
|
798
|
+
this.kernel.setCssProperty("safe-area-inset-left", this._safeAreaInset.left + "px");
|
|
799
|
+
this.kernel.setCssProperty("safe-area-inset-right", this._safeAreaInset.right + "px");
|
|
800
|
+
}
|
|
801
|
+
setContentSafeAreaInset(data) {
|
|
802
|
+
if (typeof data !== "undefined") {
|
|
803
|
+
if (typeof data.top !== "undefined") this._contentSafeAreaInset.top = data.top;
|
|
804
|
+
if (typeof data.bottom !== "undefined") this._contentSafeAreaInset.bottom = data.bottom;
|
|
805
|
+
if (typeof data.left !== "undefined") this._contentSafeAreaInset.left = data.left;
|
|
806
|
+
if (typeof data.right !== "undefined") this._contentSafeAreaInset.right = data.right;
|
|
807
|
+
this.kernel.receiveWebViewEvent("contentSafeAreaChanged");
|
|
808
|
+
}
|
|
809
|
+
this.kernel.setCssProperty("content-safe-area-inset-top", this._contentSafeAreaInset.top + "px");
|
|
810
|
+
this.kernel.setCssProperty("content-safe-area-inset-bottom", this._contentSafeAreaInset.bottom + "px");
|
|
811
|
+
this.kernel.setCssProperty("content-safe-area-inset-left", this._contentSafeAreaInset.left + "px");
|
|
812
|
+
this.kernel.setCssProperty("content-safe-area-inset-right", this._contentSafeAreaInset.right + "px");
|
|
813
|
+
}
|
|
814
|
+
// ---------------------------------------------------------------------
|
|
815
|
+
// Closing confirmation / vertical swipes
|
|
816
|
+
// ---------------------------------------------------------------------
|
|
817
|
+
setClosingConfirmation(needConfirmation) {
|
|
818
|
+
if (!this.kernel.warnIfUnsupported("6.2", "Closing confirmation")) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
this._isClosingConfirmationEnabled = !!needConfirmation;
|
|
822
|
+
this.kernel.webView.postEvent("web_app_setup_closing_behavior", void 0, {
|
|
823
|
+
need_confirmation: this._isClosingConfirmationEnabled
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
toggleVerticalSwipes(enableSwipes) {
|
|
827
|
+
if (!this.kernel.warnIfUnsupported("7.7", "Changing swipes behavior")) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
this._isVerticalSwipesEnabled = !!enableSwipes;
|
|
831
|
+
this.kernel.webView.postEvent("web_app_setup_swipe_behavior", void 0, {
|
|
832
|
+
allow_vertical_swipe: this._isVerticalSwipesEnabled
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
// ---------------------------------------------------------------------
|
|
836
|
+
// Fullscreen
|
|
837
|
+
// ---------------------------------------------------------------------
|
|
838
|
+
setFullscreen(isFullscreen) {
|
|
839
|
+
this._isFullscreen = !!isFullscreen;
|
|
840
|
+
sessionStorageSet("isFullscreen", this._isFullscreen ? "yes" : "no");
|
|
841
|
+
}
|
|
842
|
+
requestFullscreen() {
|
|
843
|
+
this.kernel.requireVersion("8.0", "requestFullscreen");
|
|
844
|
+
this.kernel.webView.postEvent("web_app_request_fullscreen");
|
|
845
|
+
}
|
|
846
|
+
exitFullscreen() {
|
|
847
|
+
this.kernel.requireVersion("8.0", "exitFullscreen");
|
|
848
|
+
this.kernel.webView.postEvent("web_app_exit_fullscreen");
|
|
849
|
+
}
|
|
850
|
+
// ---------------------------------------------------------------------
|
|
851
|
+
// Orientation lock
|
|
852
|
+
// ---------------------------------------------------------------------
|
|
853
|
+
setOrientationLock(isLocked) {
|
|
854
|
+
this._isOrientationLocked = !!isLocked;
|
|
855
|
+
sessionStorageSet("isOrientationLocked", this._isOrientationLocked ? "yes" : "no");
|
|
856
|
+
}
|
|
857
|
+
toggleOrientationLock(locked) {
|
|
858
|
+
if (!this.kernel.warnIfUnsupported("8.0", "Orientation locking")) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.setOrientationLock(locked);
|
|
862
|
+
this.kernel.webView.postEvent("web_app_toggle_orientation_lock", void 0, {
|
|
863
|
+
locked: this._isOrientationLocked
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// src/sdk/_internal/ui/back-button.ts
|
|
869
|
+
var BackButton = class {
|
|
870
|
+
constructor(kernel) {
|
|
871
|
+
this.kernel = kernel;
|
|
872
|
+
this._isVisible = false;
|
|
873
|
+
this.curButtonState = null;
|
|
874
|
+
this.handleBackButtonPressed = () => {
|
|
875
|
+
this.kernel.receiveWebViewEvent("backButtonClicked");
|
|
876
|
+
};
|
|
877
|
+
kernel.webView.onEvent("back_button_pressed", this.handleBackButtonPressed);
|
|
878
|
+
}
|
|
879
|
+
get isVisible() {
|
|
880
|
+
return this._isVisible;
|
|
881
|
+
}
|
|
882
|
+
set isVisible(val) {
|
|
883
|
+
this.setParams({ is_visible: val });
|
|
884
|
+
}
|
|
885
|
+
checkVersion() {
|
|
886
|
+
return this.kernel.warnIfUnsupported("6.1", "BackButton");
|
|
887
|
+
}
|
|
888
|
+
buttonParams() {
|
|
889
|
+
return { is_visible: this._isVisible };
|
|
890
|
+
}
|
|
891
|
+
updateButton() {
|
|
892
|
+
const params = this.buttonParams();
|
|
893
|
+
const state = JSON.stringify(params);
|
|
894
|
+
if (this.curButtonState === state) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
this.curButtonState = state;
|
|
898
|
+
this.kernel.webView.postEvent("web_app_setup_back_button", void 0, params);
|
|
899
|
+
}
|
|
900
|
+
setParams(params) {
|
|
901
|
+
if (!this.checkVersion()) {
|
|
902
|
+
return this;
|
|
903
|
+
}
|
|
904
|
+
if (typeof params.is_visible !== "undefined") {
|
|
905
|
+
this._isVisible = !!params.is_visible;
|
|
906
|
+
}
|
|
907
|
+
this.updateButton();
|
|
908
|
+
return this;
|
|
909
|
+
}
|
|
910
|
+
onClick(callback) {
|
|
911
|
+
if (this.checkVersion()) {
|
|
912
|
+
this.kernel.onWebViewEvent("backButtonClicked", callback);
|
|
913
|
+
}
|
|
914
|
+
return this;
|
|
915
|
+
}
|
|
916
|
+
offClick(callback) {
|
|
917
|
+
if (this.checkVersion()) {
|
|
918
|
+
this.kernel.offWebViewEvent("backButtonClicked", callback);
|
|
919
|
+
}
|
|
920
|
+
return this;
|
|
921
|
+
}
|
|
922
|
+
show() {
|
|
923
|
+
return this.setParams({ is_visible: true });
|
|
924
|
+
}
|
|
925
|
+
hide() {
|
|
926
|
+
return this.setParams({ is_visible: false });
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
// src/sdk/_internal/ui/bottom-button.ts
|
|
931
|
+
var BottomButton = class {
|
|
932
|
+
constructor(type, kernel, theme, debugBar) {
|
|
933
|
+
this.kernel = kernel;
|
|
934
|
+
this.theme = theme;
|
|
935
|
+
this.debugBar = debugBar;
|
|
936
|
+
this.isVisibleValue = false;
|
|
937
|
+
this.isActiveValue = true;
|
|
938
|
+
this.hasShineEffectValue = false;
|
|
939
|
+
this.isProgressVisibleValue = false;
|
|
940
|
+
this.iconCustomEmojiIdValue = false;
|
|
941
|
+
this.colorValue = false;
|
|
942
|
+
this.textColorValue = false;
|
|
943
|
+
this.positionValue = "left";
|
|
944
|
+
this.curButtonState = null;
|
|
945
|
+
this.handlePressed = () => {
|
|
946
|
+
if (this.isActiveValue) {
|
|
947
|
+
this.kernel.receiveWebViewEvent(this.webViewEventName);
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
this.type = type;
|
|
951
|
+
this.isMain = type === "main";
|
|
952
|
+
if (this.isMain) {
|
|
953
|
+
this.setupEventName = "web_app_setup_main_button";
|
|
954
|
+
this.nativePressEventName = "main_button_pressed";
|
|
955
|
+
this.webViewEventName = "mainButtonClicked";
|
|
956
|
+
this.defaultText = "Continue";
|
|
957
|
+
this.defaultColor = () => theme.getThemeParams().button_color || "#2481cc";
|
|
958
|
+
this.defaultTextColor = () => theme.getThemeParams().button_text_color || "#ffffff";
|
|
959
|
+
} else {
|
|
960
|
+
this.setupEventName = "web_app_setup_secondary_button";
|
|
961
|
+
this.nativePressEventName = "secondary_button_pressed";
|
|
962
|
+
this.webViewEventName = "secondaryButtonClicked";
|
|
963
|
+
this.defaultText = "Cancel";
|
|
964
|
+
this.defaultColor = () => theme.getBottomBarColor();
|
|
965
|
+
this.defaultTextColor = () => theme.getThemeParams().button_color || "#2481cc";
|
|
966
|
+
}
|
|
967
|
+
this.textValue = this.defaultText;
|
|
968
|
+
kernel.webView.onEvent(this.nativePressEventName, this.handlePressed);
|
|
969
|
+
debugBar.registerButton(type, this.handlePressed);
|
|
970
|
+
}
|
|
971
|
+
// ---------------------------------------------------------------------
|
|
972
|
+
// Public property accessors (mirrors Object.defineProperty in original)
|
|
973
|
+
// ---------------------------------------------------------------------
|
|
974
|
+
get iconCustomEmojiId() {
|
|
975
|
+
return this.iconCustomEmojiIdValue;
|
|
976
|
+
}
|
|
977
|
+
set iconCustomEmojiId(val) {
|
|
978
|
+
this.setParams({ icon_custom_emoji_id: val });
|
|
979
|
+
}
|
|
980
|
+
get text() {
|
|
981
|
+
return this.textValue;
|
|
982
|
+
}
|
|
983
|
+
set text(val) {
|
|
984
|
+
this.setParams({ text: val });
|
|
985
|
+
}
|
|
986
|
+
get color() {
|
|
987
|
+
return this.colorValue || this.defaultColor();
|
|
988
|
+
}
|
|
989
|
+
set color(val) {
|
|
990
|
+
this.setParams({ color: val });
|
|
991
|
+
}
|
|
992
|
+
get textColor() {
|
|
993
|
+
return this.textColorValue || this.defaultTextColor();
|
|
994
|
+
}
|
|
995
|
+
set textColor(val) {
|
|
996
|
+
this.setParams({ text_color: val });
|
|
997
|
+
}
|
|
998
|
+
get isVisible() {
|
|
999
|
+
return this.isVisibleValue;
|
|
1000
|
+
}
|
|
1001
|
+
set isVisible(val) {
|
|
1002
|
+
this.setParams({ is_visible: val });
|
|
1003
|
+
}
|
|
1004
|
+
get isProgressVisible() {
|
|
1005
|
+
return this.isProgressVisibleValue;
|
|
1006
|
+
}
|
|
1007
|
+
get isActive() {
|
|
1008
|
+
return this.isActiveValue;
|
|
1009
|
+
}
|
|
1010
|
+
set isActive(val) {
|
|
1011
|
+
this.setParams({ is_active: val });
|
|
1012
|
+
}
|
|
1013
|
+
get hasShineEffect() {
|
|
1014
|
+
return this.hasShineEffectValue;
|
|
1015
|
+
}
|
|
1016
|
+
set hasShineEffect(val) {
|
|
1017
|
+
this.setParams({ has_shine_effect: val });
|
|
1018
|
+
}
|
|
1019
|
+
get position() {
|
|
1020
|
+
return this.positionValue;
|
|
1021
|
+
}
|
|
1022
|
+
set position(val) {
|
|
1023
|
+
if (!this.isMain) this.setParams({ position: val });
|
|
1024
|
+
}
|
|
1025
|
+
// ---------------------------------------------------------------------
|
|
1026
|
+
// Wire protocol
|
|
1027
|
+
// ---------------------------------------------------------------------
|
|
1028
|
+
buttonParams() {
|
|
1029
|
+
if (!this.isVisibleValue) {
|
|
1030
|
+
return { is_visible: false };
|
|
1031
|
+
}
|
|
1032
|
+
const params = {
|
|
1033
|
+
is_visible: true,
|
|
1034
|
+
is_active: this.isActiveValue,
|
|
1035
|
+
is_progress_visible: this.isProgressVisibleValue,
|
|
1036
|
+
icon_custom_emoji_id: this.iconCustomEmojiIdValue || void 0,
|
|
1037
|
+
text: this.textValue,
|
|
1038
|
+
color: this.color,
|
|
1039
|
+
text_color: this.textColor,
|
|
1040
|
+
has_shine_effect: this.hasShineEffectValue && this.isActiveValue && !this.isProgressVisibleValue
|
|
1041
|
+
};
|
|
1042
|
+
if (!this.isMain) {
|
|
1043
|
+
params.position = this.positionValue;
|
|
1044
|
+
}
|
|
1045
|
+
return params;
|
|
1046
|
+
}
|
|
1047
|
+
updateButton() {
|
|
1048
|
+
const params = this.buttonParams();
|
|
1049
|
+
const state = JSON.stringify(params);
|
|
1050
|
+
if (this.curButtonState === state) {
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
this.curButtonState = state;
|
|
1054
|
+
this.kernel.webView.postEvent(this.setupEventName, void 0, params);
|
|
1055
|
+
if (this.debugBar.enabled) {
|
|
1056
|
+
this.debugBar.updateButtonVisual(this.type, params);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
setParams(params) {
|
|
1060
|
+
if (typeof params.icon_custom_emoji_id !== "undefined") {
|
|
1061
|
+
let emojiId = params.icon_custom_emoji_id;
|
|
1062
|
+
if (emojiId === false || emojiId === null) {
|
|
1063
|
+
emojiId = "";
|
|
1064
|
+
}
|
|
1065
|
+
if (emojiId !== "" && !/^[0-9]{10,20}$/.test(emojiId)) {
|
|
1066
|
+
console.error("[@core-ease/telegram-kit] Bottom button icon custom emoji is invalid", params.icon_custom_emoji_id);
|
|
1067
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1068
|
+
}
|
|
1069
|
+
this.iconCustomEmojiIdValue = emojiId || false;
|
|
1070
|
+
}
|
|
1071
|
+
if (typeof params.text !== "undefined") {
|
|
1072
|
+
const text = strTrim(params.text);
|
|
1073
|
+
if (!text.length && !this.iconCustomEmojiIdValue) {
|
|
1074
|
+
console.error("[@core-ease/telegram-kit] Bottom button text is required", params.text);
|
|
1075
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1076
|
+
}
|
|
1077
|
+
if (text.length > 64) {
|
|
1078
|
+
console.error("[@core-ease/telegram-kit] Bottom button text is too long", text);
|
|
1079
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1080
|
+
}
|
|
1081
|
+
this.textValue = text;
|
|
1082
|
+
}
|
|
1083
|
+
if (typeof params.color !== "undefined") {
|
|
1084
|
+
if (params.color === false || params.color === null) {
|
|
1085
|
+
this.colorValue = false;
|
|
1086
|
+
} else {
|
|
1087
|
+
const color = parseColorToHex(params.color);
|
|
1088
|
+
if (!color) {
|
|
1089
|
+
console.error("[@core-ease/telegram-kit] Bottom button color format is invalid", params.color);
|
|
1090
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1091
|
+
}
|
|
1092
|
+
this.colorValue = color;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (typeof params.text_color !== "undefined") {
|
|
1096
|
+
if (params.text_color === false || params.text_color === null) {
|
|
1097
|
+
this.textColorValue = false;
|
|
1098
|
+
} else {
|
|
1099
|
+
const textColor = parseColorToHex(params.text_color);
|
|
1100
|
+
if (!textColor) {
|
|
1101
|
+
console.error("[@core-ease/telegram-kit] Bottom button text color format is invalid", params.text_color);
|
|
1102
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1103
|
+
}
|
|
1104
|
+
this.textColorValue = textColor;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
if (typeof params.is_visible !== "undefined") {
|
|
1108
|
+
if (params.is_visible && !this.textValue.length) {
|
|
1109
|
+
console.error("[@core-ease/telegram-kit] Bottom button text is required");
|
|
1110
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1111
|
+
}
|
|
1112
|
+
this.isVisibleValue = !!params.is_visible;
|
|
1113
|
+
}
|
|
1114
|
+
if (typeof params.has_shine_effect !== "undefined") {
|
|
1115
|
+
this.hasShineEffectValue = !!params.has_shine_effect;
|
|
1116
|
+
}
|
|
1117
|
+
if (!this.isMain && typeof params.position !== "undefined") {
|
|
1118
|
+
if (params.position != "left" && params.position != "right" && params.position != "top" && params.position != "bottom") {
|
|
1119
|
+
console.error("[@core-ease/telegram-kit] Bottom button posiition is invalid", params.position);
|
|
1120
|
+
throwWebAppError("WebAppBottomButtonParamInvalid" /* BottomButtonParamInvalid */);
|
|
1121
|
+
}
|
|
1122
|
+
this.positionValue = params.position;
|
|
1123
|
+
}
|
|
1124
|
+
if (typeof params.is_active !== "undefined") {
|
|
1125
|
+
this.isActiveValue = !!params.is_active;
|
|
1126
|
+
}
|
|
1127
|
+
this.updateButton();
|
|
1128
|
+
return this;
|
|
1129
|
+
}
|
|
1130
|
+
setText(text) {
|
|
1131
|
+
return this.setParams({ text });
|
|
1132
|
+
}
|
|
1133
|
+
onClick(callback) {
|
|
1134
|
+
this.kernel.onWebViewEvent(this.webViewEventName, callback);
|
|
1135
|
+
return this;
|
|
1136
|
+
}
|
|
1137
|
+
offClick(callback) {
|
|
1138
|
+
this.kernel.offWebViewEvent(this.webViewEventName, callback);
|
|
1139
|
+
return this;
|
|
1140
|
+
}
|
|
1141
|
+
show() {
|
|
1142
|
+
return this.setParams({ is_visible: true });
|
|
1143
|
+
}
|
|
1144
|
+
hide() {
|
|
1145
|
+
return this.setParams({ is_visible: false });
|
|
1146
|
+
}
|
|
1147
|
+
enable() {
|
|
1148
|
+
return this.setParams({ is_active: true });
|
|
1149
|
+
}
|
|
1150
|
+
disable() {
|
|
1151
|
+
return this.setParams({ is_active: false });
|
|
1152
|
+
}
|
|
1153
|
+
showProgress(leaveActive) {
|
|
1154
|
+
this.isActiveValue = !!leaveActive;
|
|
1155
|
+
this.isProgressVisibleValue = true;
|
|
1156
|
+
this.updateButton();
|
|
1157
|
+
return this;
|
|
1158
|
+
}
|
|
1159
|
+
hideProgress() {
|
|
1160
|
+
if (!this.isActiveValue) {
|
|
1161
|
+
this.isActiveValue = true;
|
|
1162
|
+
}
|
|
1163
|
+
this.isProgressVisibleValue = false;
|
|
1164
|
+
this.updateButton();
|
|
1165
|
+
return this;
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
// src/sdk/_internal/ui/settings-button.ts
|
|
1170
|
+
var SettingsButton = class {
|
|
1171
|
+
constructor(kernel) {
|
|
1172
|
+
this.kernel = kernel;
|
|
1173
|
+
this._isVisible = false;
|
|
1174
|
+
this.curButtonState = null;
|
|
1175
|
+
this.handleSettingsButtonPressed = () => {
|
|
1176
|
+
this.kernel.receiveWebViewEvent("settingsButtonClicked");
|
|
1177
|
+
};
|
|
1178
|
+
kernel.webView.onEvent("settings_button_pressed", this.handleSettingsButtonPressed);
|
|
1179
|
+
}
|
|
1180
|
+
get isVisible() {
|
|
1181
|
+
return this._isVisible;
|
|
1182
|
+
}
|
|
1183
|
+
set isVisible(val) {
|
|
1184
|
+
this.setParams({ is_visible: val });
|
|
1185
|
+
}
|
|
1186
|
+
checkVersion() {
|
|
1187
|
+
return this.kernel.warnIfUnsupported("6.10", "SettingsButton");
|
|
1188
|
+
}
|
|
1189
|
+
buttonParams() {
|
|
1190
|
+
return { is_visible: this._isVisible };
|
|
1191
|
+
}
|
|
1192
|
+
updateButton() {
|
|
1193
|
+
const params = this.buttonParams();
|
|
1194
|
+
const state = JSON.stringify(params);
|
|
1195
|
+
if (this.curButtonState === state) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
this.curButtonState = state;
|
|
1199
|
+
this.kernel.webView.postEvent("web_app_setup_settings_button", void 0, params);
|
|
1200
|
+
}
|
|
1201
|
+
setParams(params) {
|
|
1202
|
+
if (!this.checkVersion()) {
|
|
1203
|
+
return this;
|
|
1204
|
+
}
|
|
1205
|
+
if (typeof params.is_visible !== "undefined") {
|
|
1206
|
+
this._isVisible = !!params.is_visible;
|
|
1207
|
+
}
|
|
1208
|
+
this.updateButton();
|
|
1209
|
+
return this;
|
|
1210
|
+
}
|
|
1211
|
+
onClick(callback) {
|
|
1212
|
+
if (this.checkVersion()) {
|
|
1213
|
+
this.kernel.onWebViewEvent("settingsButtonClicked", callback);
|
|
1214
|
+
}
|
|
1215
|
+
return this;
|
|
1216
|
+
}
|
|
1217
|
+
offClick(callback) {
|
|
1218
|
+
if (this.checkVersion()) {
|
|
1219
|
+
this.kernel.offWebViewEvent("settingsButtonClicked", callback);
|
|
1220
|
+
}
|
|
1221
|
+
return this;
|
|
1222
|
+
}
|
|
1223
|
+
show() {
|
|
1224
|
+
return this.setParams({ is_visible: true });
|
|
1225
|
+
}
|
|
1226
|
+
hide() {
|
|
1227
|
+
return this.setParams({ is_visible: false });
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
// src/sdk/_internal/ui/debug-bottom-bar.ts
|
|
1232
|
+
var SPINNER_SVG = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewport="0 0 48 48" width="48px" height="48px"><circle cx="50%" cy="50%" stroke="{COLOR}" stroke-width="2.25" stroke-linecap="round" fill="none" stroke-dashoffset="106" r="9" stroke-dasharray="56.52" rotate="-90"><animate attributeName="stroke-dashoffset" attributeType="XML" dur="360s" from="0" to="12500" repeatCount="indefinite"></animate><animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="1s" from="-90 24 24" to="630 24 24" repeatCount="indefinite"></animateTransform></circle></svg>';
|
|
1233
|
+
var DebugBottomBar = class {
|
|
1234
|
+
constructor(kernel, getBottomBarColor) {
|
|
1235
|
+
this.kernel = kernel;
|
|
1236
|
+
this.getBottomBarColor = getBottomBarColor;
|
|
1237
|
+
this.container = null;
|
|
1238
|
+
this.buttons = {};
|
|
1239
|
+
/** Invoked whenever the reserved bottom-bar height changes. */
|
|
1240
|
+
this.onHeightChanged = null;
|
|
1241
|
+
this.enabled = !!kernel.initParams.tgWebAppDebug;
|
|
1242
|
+
if (!this.enabled) return;
|
|
1243
|
+
this.container = document.createElement("tg-bottom-bar");
|
|
1244
|
+
const style = {
|
|
1245
|
+
display: "flex",
|
|
1246
|
+
gap: "7px",
|
|
1247
|
+
font: "600 14px/18px sans-serif",
|
|
1248
|
+
width: "100%",
|
|
1249
|
+
background: getBottomBarColor(),
|
|
1250
|
+
position: "fixed",
|
|
1251
|
+
left: "0",
|
|
1252
|
+
right: "0",
|
|
1253
|
+
bottom: "0",
|
|
1254
|
+
margin: "0",
|
|
1255
|
+
padding: "7px",
|
|
1256
|
+
textAlign: "center",
|
|
1257
|
+
boxSizing: "border-box",
|
|
1258
|
+
zIndex: "10000"
|
|
1259
|
+
};
|
|
1260
|
+
Object.assign(this.container.style, style);
|
|
1261
|
+
document.addEventListener("DOMContentLoaded", function onDomLoaded() {
|
|
1262
|
+
document.removeEventListener("DOMContentLoaded", onDomLoaded);
|
|
1263
|
+
document.body.appendChild(this_container());
|
|
1264
|
+
});
|
|
1265
|
+
const this_container = () => this.container;
|
|
1266
|
+
const animStyle = document.createElement("style");
|
|
1267
|
+
animStyle.innerHTML = 'tg-bottom-button.shine { position: relative; overflow: hidden; } tg-bottom-button.shine:before { content:""; position: absolute; top: 0; width: 100%; height: 100%; background: linear-gradient(120deg, transparent, rgba(255, 255, 255, .2), transparent); animation: tg-bottom-button-shine 5s ease-in-out infinite; } @-webkit-keyframes tg-bottom-button-shine { 0% {left: -100%;} 12%,100% {left: 100%}} @keyframes tg-bottom-button-shine { 0% {left: -100%;} 12%,100% {left: 100%}}';
|
|
1268
|
+
this.container.appendChild(animStyle);
|
|
1269
|
+
}
|
|
1270
|
+
/** Creates & registers a debug clone of a Main/Secondary button; returns its element. */
|
|
1271
|
+
registerButton(type, onPressed) {
|
|
1272
|
+
if (!this.enabled || !this.container) return null;
|
|
1273
|
+
const el = document.createElement("tg-bottom-button");
|
|
1274
|
+
const style = {
|
|
1275
|
+
display: "none",
|
|
1276
|
+
width: "100%",
|
|
1277
|
+
height: "44px",
|
|
1278
|
+
borderRadius: "0",
|
|
1279
|
+
background: "no-repeat right center",
|
|
1280
|
+
padding: "13px 15px",
|
|
1281
|
+
textAlign: "center",
|
|
1282
|
+
boxSizing: "border-box"
|
|
1283
|
+
};
|
|
1284
|
+
Object.assign(el.style, style);
|
|
1285
|
+
this.container.appendChild(el);
|
|
1286
|
+
el.addEventListener("click", onPressed, false);
|
|
1287
|
+
this.buttons[type] = { el, isVisible: false, position: "left" };
|
|
1288
|
+
return el;
|
|
1289
|
+
}
|
|
1290
|
+
/** Applies visual state coming from `BottomButton.buttonParams()`. */
|
|
1291
|
+
updateButtonVisual(type, params) {
|
|
1292
|
+
const entry = this.buttons[type];
|
|
1293
|
+
if (!entry) return;
|
|
1294
|
+
const el = entry.el;
|
|
1295
|
+
entry.isVisible = !!params.is_visible;
|
|
1296
|
+
entry.position = params.position || "left";
|
|
1297
|
+
if (params.is_visible) {
|
|
1298
|
+
el.style.display = "block";
|
|
1299
|
+
el.style.opacity = params.is_active ? "1" : "0.8";
|
|
1300
|
+
el.style.cursor = params.is_active ? "pointer" : "auto";
|
|
1301
|
+
el.disabled = !params.is_active;
|
|
1302
|
+
el.innerText = params.text || "";
|
|
1303
|
+
el.className = params.has_shine_effect ? "shine" : "";
|
|
1304
|
+
el.style.backgroundImage = params.is_progress_visible ? `url('data:image/svg+xml,${encodeURIComponent(
|
|
1305
|
+
SPINNER_SVG.replace("{COLOR}", params.text_color || "#ffffff")
|
|
1306
|
+
)}')` : "none";
|
|
1307
|
+
el.style.backgroundColor = params.color || "";
|
|
1308
|
+
el.style.color = params.text_color || "";
|
|
1309
|
+
} else {
|
|
1310
|
+
el.style.display = "none";
|
|
1311
|
+
}
|
|
1312
|
+
this.updateBar();
|
|
1313
|
+
}
|
|
1314
|
+
updateBar() {
|
|
1315
|
+
var _a;
|
|
1316
|
+
if (!this.enabled || !this.container) return;
|
|
1317
|
+
const main = this.buttons.main;
|
|
1318
|
+
const secondary = this.buttons.secondary;
|
|
1319
|
+
let height = 0;
|
|
1320
|
+
if (main && main.isVisible || secondary && secondary.isVisible) {
|
|
1321
|
+
this.container.style.display = "flex";
|
|
1322
|
+
height = 58;
|
|
1323
|
+
if ((main == null ? void 0 : main.isVisible) && (secondary == null ? void 0 : secondary.isVisible)) {
|
|
1324
|
+
if (secondary.position == "top") {
|
|
1325
|
+
this.container.style.flexDirection = "column-reverse";
|
|
1326
|
+
height += 51;
|
|
1327
|
+
} else if (secondary.position == "bottom") {
|
|
1328
|
+
this.container.style.flexDirection = "column";
|
|
1329
|
+
height += 51;
|
|
1330
|
+
} else if (secondary.position == "left") {
|
|
1331
|
+
this.container.style.flexDirection = "row-reverse";
|
|
1332
|
+
} else if (secondary.position == "right") {
|
|
1333
|
+
this.container.style.flexDirection = "row";
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
this.container.style.display = "none";
|
|
1338
|
+
height = 0;
|
|
1339
|
+
}
|
|
1340
|
+
this.kernel.bottomBarHeightPx = height;
|
|
1341
|
+
this.container.style.background = this.getBottomBarColor();
|
|
1342
|
+
if (document.documentElement) {
|
|
1343
|
+
document.documentElement.style.boxSizing = "border-box";
|
|
1344
|
+
document.documentElement.style.paddingBottom = height + "px";
|
|
1345
|
+
}
|
|
1346
|
+
(_a = this.onHeightChanged) == null ? void 0 : _a.call(this);
|
|
1347
|
+
}
|
|
1348
|
+
/** Called after the bottom-bar color changes so the debug bar repaints too. */
|
|
1349
|
+
refreshColor() {
|
|
1350
|
+
if (!this.enabled || !this.container) return;
|
|
1351
|
+
this.updateBar();
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
// src/sdk/_internal/ui/popup.ts
|
|
1356
|
+
var PopupManager = class {
|
|
1357
|
+
constructor(kernel) {
|
|
1358
|
+
this.kernel = kernel;
|
|
1359
|
+
this.pending = false;
|
|
1360
|
+
this.handlePopupClosed = (_eventType, eventData) => {
|
|
1361
|
+
var _a;
|
|
1362
|
+
if (this.pending) {
|
|
1363
|
+
const popupData = this.pending;
|
|
1364
|
+
this.pending = false;
|
|
1365
|
+
const buttonId = typeof eventData.button_id !== "undefined" ? eventData.button_id : null;
|
|
1366
|
+
(_a = popupData.callback) == null ? void 0 : _a.call(popupData, buttonId);
|
|
1367
|
+
this.kernel.receiveWebViewEvent("popupClosed", { button_id: buttonId });
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
kernel.webView.onEvent("popup_closed", this.handlePopupClosed);
|
|
1371
|
+
}
|
|
1372
|
+
showPopup(params, callback) {
|
|
1373
|
+
this.kernel.requireVersion("6.2", "showPopup");
|
|
1374
|
+
if (this.pending) {
|
|
1375
|
+
console.error("[@core-ease/telegram-kit] Popup is already opened");
|
|
1376
|
+
throwWebAppError("WebAppPopupOpened" /* PopupOpened */);
|
|
1377
|
+
}
|
|
1378
|
+
const popupParams = { message: "" };
|
|
1379
|
+
if (typeof params.title !== "undefined") {
|
|
1380
|
+
const title = strTrim(params.title);
|
|
1381
|
+
if (title.length > 64) {
|
|
1382
|
+
console.error("[@core-ease/telegram-kit] Popup title is too long", title);
|
|
1383
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1384
|
+
}
|
|
1385
|
+
if (title.length > 0) {
|
|
1386
|
+
popupParams.title = title;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
let message = "";
|
|
1390
|
+
if (typeof params.message !== "undefined") {
|
|
1391
|
+
message = strTrim(params.message);
|
|
1392
|
+
}
|
|
1393
|
+
if (!message.length) {
|
|
1394
|
+
console.error("[@core-ease/telegram-kit] Popup message is required", params.message);
|
|
1395
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1396
|
+
}
|
|
1397
|
+
if (message.length > 256) {
|
|
1398
|
+
console.error("[@core-ease/telegram-kit] Popup message is too long", message);
|
|
1399
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1400
|
+
}
|
|
1401
|
+
popupParams.message = message;
|
|
1402
|
+
const buttons = [];
|
|
1403
|
+
if (typeof params.buttons !== "undefined") {
|
|
1404
|
+
if (!Array.isArray(params.buttons)) {
|
|
1405
|
+
console.error("[@core-ease/telegram-kit] Popup buttons should be an array", params.buttons);
|
|
1406
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1407
|
+
}
|
|
1408
|
+
for (const button of params.buttons) {
|
|
1409
|
+
const btn = {};
|
|
1410
|
+
let id = "";
|
|
1411
|
+
if (typeof button.id !== "undefined") {
|
|
1412
|
+
id = String(button.id);
|
|
1413
|
+
if (id.length > 64) {
|
|
1414
|
+
console.error("[@core-ease/telegram-kit] Popup button id is too long", id);
|
|
1415
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
btn.id = id;
|
|
1419
|
+
const buttonType = button.type || "default";
|
|
1420
|
+
btn.type = buttonType;
|
|
1421
|
+
if (buttonType == "ok" || buttonType == "close" || buttonType == "cancel") ; else if (buttonType == "default" || buttonType == "destructive") {
|
|
1422
|
+
let text = "";
|
|
1423
|
+
if (typeof button.text !== "undefined") {
|
|
1424
|
+
text = strTrim(button.text);
|
|
1425
|
+
}
|
|
1426
|
+
if (!text.length) {
|
|
1427
|
+
console.error(`[@core-ease/telegram-kit] Popup button text is required for type ${buttonType}`, button.text);
|
|
1428
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1429
|
+
}
|
|
1430
|
+
if (text.length > 64) {
|
|
1431
|
+
console.error("[@core-ease/telegram-kit] Popup button text is too long", text);
|
|
1432
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1433
|
+
}
|
|
1434
|
+
btn.text = text;
|
|
1435
|
+
} else {
|
|
1436
|
+
console.error("[@core-ease/telegram-kit] Popup button type is invalid", buttonType);
|
|
1437
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1438
|
+
}
|
|
1439
|
+
buttons.push(btn);
|
|
1440
|
+
}
|
|
1441
|
+
} else {
|
|
1442
|
+
buttons.push({ id: "", type: "close" });
|
|
1443
|
+
}
|
|
1444
|
+
if (buttons.length < 1) {
|
|
1445
|
+
console.error("[@core-ease/telegram-kit] Popup should have at least one button");
|
|
1446
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1447
|
+
}
|
|
1448
|
+
if (buttons.length > 3) {
|
|
1449
|
+
console.error("[@core-ease/telegram-kit] Popup should not have more than 3 buttons");
|
|
1450
|
+
throwWebAppError("WebAppPopupParamInvalid" /* PopupParamInvalid */);
|
|
1451
|
+
}
|
|
1452
|
+
popupParams.buttons = buttons;
|
|
1453
|
+
this.pending = { callback };
|
|
1454
|
+
this.kernel.webView.postEvent("web_app_open_popup", void 0, popupParams);
|
|
1455
|
+
}
|
|
1456
|
+
showAlert(message, callback) {
|
|
1457
|
+
this.showPopup({ message }, callback ? () => callback() : void 0);
|
|
1458
|
+
}
|
|
1459
|
+
showConfirm(message, callback) {
|
|
1460
|
+
this.showPopup(
|
|
1461
|
+
{
|
|
1462
|
+
message,
|
|
1463
|
+
buttons: [
|
|
1464
|
+
{ type: "ok", id: "ok" },
|
|
1465
|
+
{ type: "cancel" }
|
|
1466
|
+
]
|
|
1467
|
+
},
|
|
1468
|
+
callback ? (buttonId) => callback(buttonId == "ok") : void 0
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
// src/sdk/_internal/ui/scan-qr.ts
|
|
1474
|
+
var ScanQrManager = class {
|
|
1475
|
+
constructor(kernel) {
|
|
1476
|
+
this.kernel = kernel;
|
|
1477
|
+
this.pending = false;
|
|
1478
|
+
this.handleQrTextReceived = (_eventType, eventData) => {
|
|
1479
|
+
if (this.pending) {
|
|
1480
|
+
const popupData = this.pending;
|
|
1481
|
+
const data = typeof eventData.data !== "undefined" ? eventData.data : null;
|
|
1482
|
+
if (popupData.callback) {
|
|
1483
|
+
if (popupData.callback(data)) {
|
|
1484
|
+
this.pending = false;
|
|
1485
|
+
this.kernel.webView.postEvent("web_app_close_scan_qr_popup", void 0);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
this.kernel.receiveWebViewEvent("qrTextReceived", { data });
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
this.handleScanQrPopupClosed = () => {
|
|
1492
|
+
this.pending = false;
|
|
1493
|
+
this.kernel.receiveWebViewEvent("scanQrPopupClosed");
|
|
1494
|
+
};
|
|
1495
|
+
kernel.webView.onEvent("qr_text_received", this.handleQrTextReceived);
|
|
1496
|
+
kernel.webView.onEvent("scan_qr_popup_closed", this.handleScanQrPopupClosed);
|
|
1497
|
+
}
|
|
1498
|
+
showScanQrPopup(params, callback) {
|
|
1499
|
+
this.kernel.requireVersion("6.4", "showScanQrPopup");
|
|
1500
|
+
if (this.pending) {
|
|
1501
|
+
console.error("[@core-ease/telegram-kit] Popup is already opened");
|
|
1502
|
+
throwWebAppError("WebAppScanQrPopupOpened" /* ScanQrPopupOpened */);
|
|
1503
|
+
}
|
|
1504
|
+
const popupParams = {};
|
|
1505
|
+
if (typeof params.text !== "undefined") {
|
|
1506
|
+
const text = strTrim(params.text);
|
|
1507
|
+
if (text.length > 64) {
|
|
1508
|
+
console.error("[@core-ease/telegram-kit] Scan QR popup text is too long", text);
|
|
1509
|
+
throwWebAppError("WebAppScanQrPopupParamInvalid" /* ScanQrPopupParamInvalid */);
|
|
1510
|
+
}
|
|
1511
|
+
if (text.length > 0) {
|
|
1512
|
+
popupParams.text = text;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
this.pending = { callback };
|
|
1516
|
+
this.kernel.webView.postEvent("web_app_open_scan_qr_popup", void 0, popupParams);
|
|
1517
|
+
}
|
|
1518
|
+
closeScanQrPopup() {
|
|
1519
|
+
this.kernel.requireVersion("6.4", "closeScanQrPopup");
|
|
1520
|
+
this.pending = false;
|
|
1521
|
+
this.kernel.webView.postEvent("web_app_close_scan_qr_popup", void 0);
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
// src/sdk/_internal/features/haptic-feedback.ts
|
|
1526
|
+
var HapticFeedback = class {
|
|
1527
|
+
constructor(kernel) {
|
|
1528
|
+
this.kernel = kernel;
|
|
1529
|
+
}
|
|
1530
|
+
trigger(params) {
|
|
1531
|
+
if (!this.kernel.warnIfUnsupported("6.1", "HapticFeedback")) {
|
|
1532
|
+
return this;
|
|
1533
|
+
}
|
|
1534
|
+
if (params.type == "impact") {
|
|
1535
|
+
if (params.impact_style != "light" && params.impact_style != "medium" && params.impact_style != "heavy" && params.impact_style != "rigid" && params.impact_style != "soft") {
|
|
1536
|
+
console.error("[@core-ease/telegram-kit] Haptic impact style is invalid", params.impact_style);
|
|
1537
|
+
throwWebAppError("WebAppHapticImpactStyleInvalid" /* HapticImpactStyleInvalid */);
|
|
1538
|
+
}
|
|
1539
|
+
} else if (params.type == "notification") {
|
|
1540
|
+
if (params.notification_type != "error" && params.notification_type != "success" && params.notification_type != "warning") {
|
|
1541
|
+
console.error("[@core-ease/telegram-kit] Haptic notification type is invalid", params.notification_type);
|
|
1542
|
+
throwWebAppError("WebAppHapticNotificationTypeInvalid" /* HapticNotificationTypeInvalid */);
|
|
1543
|
+
}
|
|
1544
|
+
} else if (params.type == "selection_change") ; else {
|
|
1545
|
+
console.error("[@core-ease/telegram-kit] Haptic feedback type is invalid", params.type);
|
|
1546
|
+
throwWebAppError("WebAppHapticFeedbackTypeInvalid" /* HapticFeedbackTypeInvalid */);
|
|
1547
|
+
}
|
|
1548
|
+
this.kernel.webView.postEvent("web_app_trigger_haptic_feedback", void 0, params);
|
|
1549
|
+
return this;
|
|
1550
|
+
}
|
|
1551
|
+
impactOccurred(style) {
|
|
1552
|
+
return this.trigger({ type: "impact", impact_style: style });
|
|
1553
|
+
}
|
|
1554
|
+
notificationOccurred(type) {
|
|
1555
|
+
return this.trigger({ type: "notification", notification_type: type });
|
|
1556
|
+
}
|
|
1557
|
+
selectionChanged() {
|
|
1558
|
+
return this.trigger({ type: "selection_change" });
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
// src/sdk/_internal/features/cloud-storage.ts
|
|
1563
|
+
var CloudStorage = class {
|
|
1564
|
+
constructor(kernel) {
|
|
1565
|
+
this.kernel = kernel;
|
|
1566
|
+
}
|
|
1567
|
+
invoke(method, params, callback) {
|
|
1568
|
+
this.kernel.requireVersion("6.9", "CloudStorage");
|
|
1569
|
+
this.kernel.invokeCustomMethod(method, params, callback);
|
|
1570
|
+
return this;
|
|
1571
|
+
}
|
|
1572
|
+
setItem(key, value, callback) {
|
|
1573
|
+
return this.invoke("saveStorageValue", { key, value }, callback);
|
|
1574
|
+
}
|
|
1575
|
+
getItem(key, callback) {
|
|
1576
|
+
return this.getItems(
|
|
1577
|
+
[key],
|
|
1578
|
+
callback ? (err, res) => err ? callback(err) : callback(null, res == null ? void 0 : res[key]) : void 0
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
getItems(keys, callback) {
|
|
1582
|
+
return this.invoke("getStorageValues", { keys }, callback);
|
|
1583
|
+
}
|
|
1584
|
+
removeItem(key, callback) {
|
|
1585
|
+
return this.removeItems([key], callback);
|
|
1586
|
+
}
|
|
1587
|
+
removeItems(keys, callback) {
|
|
1588
|
+
return this.invoke("deleteStorageValues", { keys }, callback);
|
|
1589
|
+
}
|
|
1590
|
+
getKeys(callback) {
|
|
1591
|
+
return this.invoke("getStorageKeys", {}, callback);
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
|
|
1595
|
+
// src/sdk/_internal/features/device-storage.ts
|
|
1596
|
+
var DeviceStorage = class {
|
|
1597
|
+
constructor(kernel) {
|
|
1598
|
+
this.kernel = kernel;
|
|
1599
|
+
this.handleEvent = (eventType, eventData) => {
|
|
1600
|
+
var _a;
|
|
1601
|
+
if (!eventData.req_id || !this.kernel.hasCallback(eventData.req_id)) return;
|
|
1602
|
+
const entry = this.kernel.takeCallback(eventData.req_id);
|
|
1603
|
+
let res = null;
|
|
1604
|
+
let err = null;
|
|
1605
|
+
if (eventType == "device_storage_failed") {
|
|
1606
|
+
err = eventData.error || "UNKNOWN_ERROR";
|
|
1607
|
+
} else if (eventType == "device_storage_key_received") {
|
|
1608
|
+
res = eventData.value;
|
|
1609
|
+
} else {
|
|
1610
|
+
res = true;
|
|
1611
|
+
}
|
|
1612
|
+
(_a = entry == null ? void 0 : entry.callback) == null ? void 0 : _a.call(entry, err, res);
|
|
1613
|
+
};
|
|
1614
|
+
kernel.webView.onEvent("device_storage_key_saved", this.handleEvent);
|
|
1615
|
+
kernel.webView.onEvent("device_storage_key_received", this.handleEvent);
|
|
1616
|
+
kernel.webView.onEvent("device_storage_cleared", this.handleEvent);
|
|
1617
|
+
kernel.webView.onEvent("device_storage_failed", this.handleEvent);
|
|
1618
|
+
}
|
|
1619
|
+
invoke(method, params, callback) {
|
|
1620
|
+
this.kernel.requireVersion("9.0", "DeviceStorage");
|
|
1621
|
+
const reqId = this.kernel.registerCallback(callback);
|
|
1622
|
+
this.kernel.webView.postEvent(method, void 0, __spreadValues({ req_id: reqId }, params));
|
|
1623
|
+
return this;
|
|
1624
|
+
}
|
|
1625
|
+
setItem(key, value, callback) {
|
|
1626
|
+
return this.invoke("web_app_device_storage_save_key", { key, value }, callback);
|
|
1627
|
+
}
|
|
1628
|
+
getItem(key, callback) {
|
|
1629
|
+
return this.invoke("web_app_device_storage_get_key", { key }, callback);
|
|
1630
|
+
}
|
|
1631
|
+
removeItem(key, callback) {
|
|
1632
|
+
return this.invoke("web_app_device_storage_save_key", { key, value: null }, callback);
|
|
1633
|
+
}
|
|
1634
|
+
clear(callback) {
|
|
1635
|
+
return this.invoke("web_app_device_storage_clear", {}, callback);
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
// src/sdk/_internal/features/secure-storage.ts
|
|
1640
|
+
var SecureStorage = class {
|
|
1641
|
+
constructor(kernel) {
|
|
1642
|
+
this.kernel = kernel;
|
|
1643
|
+
this.handleEvent = (eventType, eventData) => {
|
|
1644
|
+
var _a;
|
|
1645
|
+
if (!eventData.req_id || !this.kernel.hasCallback(eventData.req_id)) return;
|
|
1646
|
+
const entry = this.kernel.takeCallback(eventData.req_id);
|
|
1647
|
+
let res = null;
|
|
1648
|
+
let err = null;
|
|
1649
|
+
let canRestore = null;
|
|
1650
|
+
if (eventType == "secure_storage_failed") {
|
|
1651
|
+
err = eventData.error || "UNKNOWN_ERROR";
|
|
1652
|
+
} else if (eventType == "secure_storage_key_received") {
|
|
1653
|
+
res = eventData.value;
|
|
1654
|
+
if (eventData.can_restore) {
|
|
1655
|
+
canRestore = true;
|
|
1656
|
+
}
|
|
1657
|
+
} else if (eventType == "secure_storage_key_restored") {
|
|
1658
|
+
res = eventData.value;
|
|
1659
|
+
} else {
|
|
1660
|
+
res = true;
|
|
1661
|
+
}
|
|
1662
|
+
(_a = entry == null ? void 0 : entry.callback) == null ? void 0 : _a.call(entry, err, res, canRestore);
|
|
1663
|
+
};
|
|
1664
|
+
kernel.webView.onEvent("secure_storage_key_saved", this.handleEvent);
|
|
1665
|
+
kernel.webView.onEvent("secure_storage_key_received", this.handleEvent);
|
|
1666
|
+
kernel.webView.onEvent("secure_storage_key_restored", this.handleEvent);
|
|
1667
|
+
kernel.webView.onEvent("secure_storage_cleared", this.handleEvent);
|
|
1668
|
+
kernel.webView.onEvent("secure_storage_failed", this.handleEvent);
|
|
1669
|
+
}
|
|
1670
|
+
invoke(method, params, callback) {
|
|
1671
|
+
this.kernel.requireVersion("9.0", "SecureStorage");
|
|
1672
|
+
const reqId = this.kernel.registerCallback(callback);
|
|
1673
|
+
this.kernel.webView.postEvent(method, void 0, __spreadValues({ req_id: reqId }, params));
|
|
1674
|
+
return this;
|
|
1675
|
+
}
|
|
1676
|
+
setItem(key, value, callback) {
|
|
1677
|
+
return this.invoke("web_app_secure_storage_save_key", { key, value }, callback);
|
|
1678
|
+
}
|
|
1679
|
+
getItem(key, callback) {
|
|
1680
|
+
return this.invoke("web_app_secure_storage_get_key", { key }, callback);
|
|
1681
|
+
}
|
|
1682
|
+
restoreItem(key, callback) {
|
|
1683
|
+
return this.invoke("web_app_secure_storage_restore_key", { key }, callback);
|
|
1684
|
+
}
|
|
1685
|
+
removeItem(key, callback) {
|
|
1686
|
+
return this.invoke("web_app_secure_storage_save_key", { key, value: null }, callback);
|
|
1687
|
+
}
|
|
1688
|
+
clear(callback) {
|
|
1689
|
+
return this.invoke("web_app_secure_storage_clear", {}, callback);
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
// src/sdk/_internal/features/biometric-manager.ts
|
|
1694
|
+
var BiometricManager = class {
|
|
1695
|
+
constructor(kernel) {
|
|
1696
|
+
this.kernel = kernel;
|
|
1697
|
+
this._isInited = false;
|
|
1698
|
+
this._isBiometricAvailable = false;
|
|
1699
|
+
this._biometricType = "unknown";
|
|
1700
|
+
this._isAccessRequested = false;
|
|
1701
|
+
this._isAccessGranted = false;
|
|
1702
|
+
this._isBiometricTokenSaved = false;
|
|
1703
|
+
this._deviceId = "";
|
|
1704
|
+
this.initCallbacks = [];
|
|
1705
|
+
this.accessRequestState = false;
|
|
1706
|
+
this.authRequestState = false;
|
|
1707
|
+
this.tokenRequestState = false;
|
|
1708
|
+
this.handleInfoReceived = (_eventType, eventData) => {
|
|
1709
|
+
var _a;
|
|
1710
|
+
this._isInited = true;
|
|
1711
|
+
if (eventData.available) {
|
|
1712
|
+
this._isBiometricAvailable = true;
|
|
1713
|
+
this._biometricType = eventData.type || "unknown";
|
|
1714
|
+
if (eventData.access_requested) {
|
|
1715
|
+
this._isAccessRequested = true;
|
|
1716
|
+
this._isAccessGranted = !!eventData.access_granted;
|
|
1717
|
+
this._isBiometricTokenSaved = !!eventData.token_saved;
|
|
1718
|
+
} else {
|
|
1719
|
+
this._isAccessRequested = false;
|
|
1720
|
+
this._isAccessGranted = false;
|
|
1721
|
+
this._isBiometricTokenSaved = false;
|
|
1722
|
+
}
|
|
1723
|
+
} else {
|
|
1724
|
+
this._isBiometricAvailable = false;
|
|
1725
|
+
this._biometricType = "unknown";
|
|
1726
|
+
this._isAccessRequested = false;
|
|
1727
|
+
this._isAccessGranted = false;
|
|
1728
|
+
this._isBiometricTokenSaved = false;
|
|
1729
|
+
}
|
|
1730
|
+
this._deviceId = eventData.device_id || "";
|
|
1731
|
+
if (this.initCallbacks.length > 0) {
|
|
1732
|
+
this.initCallbacks.forEach((cb) => cb());
|
|
1733
|
+
this.initCallbacks = [];
|
|
1734
|
+
}
|
|
1735
|
+
if (this.accessRequestState) {
|
|
1736
|
+
const state = this.accessRequestState;
|
|
1737
|
+
this.accessRequestState = false;
|
|
1738
|
+
(_a = state.callback) == null ? void 0 : _a.call(state, this._isAccessGranted);
|
|
1739
|
+
}
|
|
1740
|
+
this.kernel.receiveWebViewEvent("biometricManagerUpdated");
|
|
1741
|
+
};
|
|
1742
|
+
this.handleAuthRequested = (_eventType, eventData) => {
|
|
1743
|
+
var _a;
|
|
1744
|
+
const isAuthenticated = eventData.status == "authorized";
|
|
1745
|
+
const biometricToken = eventData.token || "";
|
|
1746
|
+
if (this.authRequestState) {
|
|
1747
|
+
const state = this.authRequestState;
|
|
1748
|
+
this.authRequestState = false;
|
|
1749
|
+
(_a = state.callback) == null ? void 0 : _a.call(state, isAuthenticated, isAuthenticated ? biometricToken : null);
|
|
1750
|
+
}
|
|
1751
|
+
this.kernel.receiveWebViewEvent(
|
|
1752
|
+
"biometricAuthRequested",
|
|
1753
|
+
isAuthenticated ? { isAuthenticated: true, biometricToken } : { isAuthenticated: false }
|
|
1754
|
+
);
|
|
1755
|
+
};
|
|
1756
|
+
this.handleTokenUpdated = (_eventType, eventData) => {
|
|
1757
|
+
var _a;
|
|
1758
|
+
let applied = false;
|
|
1759
|
+
if (this._isBiometricAvailable && this._isAccessRequested) {
|
|
1760
|
+
if (eventData.status == "updated") {
|
|
1761
|
+
this._isBiometricTokenSaved = true;
|
|
1762
|
+
applied = true;
|
|
1763
|
+
} else if (eventData.status == "removed") {
|
|
1764
|
+
this._isBiometricTokenSaved = false;
|
|
1765
|
+
applied = true;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
if (this.tokenRequestState) {
|
|
1769
|
+
const state = this.tokenRequestState;
|
|
1770
|
+
this.tokenRequestState = false;
|
|
1771
|
+
(_a = state.callback) == null ? void 0 : _a.call(state, applied);
|
|
1772
|
+
}
|
|
1773
|
+
this.kernel.receiveWebViewEvent("biometricTokenUpdated", { isUpdated: applied });
|
|
1774
|
+
};
|
|
1775
|
+
kernel.webView.onEvent("biometry_info_received", this.handleInfoReceived);
|
|
1776
|
+
kernel.webView.onEvent("biometry_auth_requested", this.handleAuthRequested);
|
|
1777
|
+
kernel.webView.onEvent("biometry_token_updated", this.handleTokenUpdated);
|
|
1778
|
+
}
|
|
1779
|
+
get isInited() {
|
|
1780
|
+
return this._isInited;
|
|
1781
|
+
}
|
|
1782
|
+
get isBiometricAvailable() {
|
|
1783
|
+
return this._isInited && this._isBiometricAvailable;
|
|
1784
|
+
}
|
|
1785
|
+
get biometricType() {
|
|
1786
|
+
return this._biometricType || "unknown";
|
|
1787
|
+
}
|
|
1788
|
+
get isAccessRequested() {
|
|
1789
|
+
return this._isAccessRequested;
|
|
1790
|
+
}
|
|
1791
|
+
get isAccessGranted() {
|
|
1792
|
+
return this._isAccessRequested && this._isAccessGranted;
|
|
1793
|
+
}
|
|
1794
|
+
get isBiometricTokenSaved() {
|
|
1795
|
+
return this._isBiometricTokenSaved;
|
|
1796
|
+
}
|
|
1797
|
+
get deviceId() {
|
|
1798
|
+
return this._deviceId || "";
|
|
1799
|
+
}
|
|
1800
|
+
checkVersion() {
|
|
1801
|
+
return this.kernel.warnIfUnsupported("7.2", "BiometricManager");
|
|
1802
|
+
}
|
|
1803
|
+
checkInit() {
|
|
1804
|
+
if (!this._isInited) {
|
|
1805
|
+
console.error("[@core-ease/telegram-kit] BiometricManager should be inited before using.");
|
|
1806
|
+
throwWebAppError("WebAppBiometricManagerNotInited" /* BiometricManagerNotInited */);
|
|
1807
|
+
}
|
|
1808
|
+
return true;
|
|
1809
|
+
}
|
|
1810
|
+
init(callback) {
|
|
1811
|
+
if (!this.checkVersion()) return this;
|
|
1812
|
+
if (this._isInited) return this;
|
|
1813
|
+
if (callback) this.initCallbacks.push(callback);
|
|
1814
|
+
this.kernel.webView.postEvent("web_app_biometry_get_info");
|
|
1815
|
+
return this;
|
|
1816
|
+
}
|
|
1817
|
+
requestAccess(params, callback) {
|
|
1818
|
+
if (!this.checkVersion()) return this;
|
|
1819
|
+
this.checkInit();
|
|
1820
|
+
if (!this._isBiometricAvailable) {
|
|
1821
|
+
console.error("[@core-ease/telegram-kit] Biometrics is not available on this device.");
|
|
1822
|
+
throwWebAppError("WebAppBiometricManagerBiometricsNotAvailable" /* BiometricManagerBiometricsNotAvailable */);
|
|
1823
|
+
}
|
|
1824
|
+
if (this.accessRequestState) {
|
|
1825
|
+
console.error("[@core-ease/telegram-kit] Access is already requested");
|
|
1826
|
+
throwWebAppError("WebAppBiometricManagerAccessRequested" /* BiometricManagerAccessRequested */);
|
|
1827
|
+
}
|
|
1828
|
+
const popupParams = {};
|
|
1829
|
+
if (typeof params.reason !== "undefined") {
|
|
1830
|
+
const reason = strTrim(params.reason);
|
|
1831
|
+
if (reason.length > 128) {
|
|
1832
|
+
console.error("[@core-ease/telegram-kit] Biometric reason is too long", reason);
|
|
1833
|
+
throwWebAppError("WebAppBiometricRequestAccessParamInvalid" /* BiometricRequestAccessParamInvalid */);
|
|
1834
|
+
}
|
|
1835
|
+
if (reason.length > 0) popupParams.reason = reason;
|
|
1836
|
+
}
|
|
1837
|
+
this.accessRequestState = { callback };
|
|
1838
|
+
this.kernel.webView.postEvent("web_app_biometry_request_access", void 0, popupParams);
|
|
1839
|
+
return this;
|
|
1840
|
+
}
|
|
1841
|
+
authenticate(params, callback) {
|
|
1842
|
+
if (!this.checkVersion()) return this;
|
|
1843
|
+
this.checkInit();
|
|
1844
|
+
if (!this._isBiometricAvailable) {
|
|
1845
|
+
console.error("[@core-ease/telegram-kit] Biometrics is not available on this device.");
|
|
1846
|
+
throwWebAppError("WebAppBiometricManagerBiometricsNotAvailable" /* BiometricManagerBiometricsNotAvailable */);
|
|
1847
|
+
}
|
|
1848
|
+
if (!this.isAccessGranted) {
|
|
1849
|
+
console.error("[@core-ease/telegram-kit] Biometric access was not granted by the user.");
|
|
1850
|
+
throwWebAppError("WebAppBiometricManagerBiometricAccessNotGranted" /* BiometricManagerBiometricAccessNotGranted */);
|
|
1851
|
+
}
|
|
1852
|
+
if (this.authRequestState) {
|
|
1853
|
+
console.error("[@core-ease/telegram-kit] Authentication request is already in progress.");
|
|
1854
|
+
throwWebAppError("WebAppBiometricManagerAuthenticationRequested" /* BiometricManagerAuthenticationRequested */);
|
|
1855
|
+
}
|
|
1856
|
+
const popupParams = {};
|
|
1857
|
+
if (typeof params.reason !== "undefined") {
|
|
1858
|
+
const reason = strTrim(params.reason);
|
|
1859
|
+
if (reason.length > 128) {
|
|
1860
|
+
console.error("[@core-ease/telegram-kit] Biometric reason is too long", reason);
|
|
1861
|
+
throwWebAppError("WebAppBiometricRequestAccessParamInvalid" /* BiometricRequestAccessParamInvalid */);
|
|
1862
|
+
}
|
|
1863
|
+
if (reason.length > 0) popupParams.reason = reason;
|
|
1864
|
+
}
|
|
1865
|
+
this.authRequestState = { callback };
|
|
1866
|
+
this.kernel.webView.postEvent("web_app_biometry_request_auth", void 0, popupParams);
|
|
1867
|
+
return this;
|
|
1868
|
+
}
|
|
1869
|
+
updateBiometricToken(token, callback) {
|
|
1870
|
+
if (!this.checkVersion()) return this;
|
|
1871
|
+
token = token || "";
|
|
1872
|
+
if (token.length > 1024) {
|
|
1873
|
+
console.error("[@core-ease/telegram-kit] Token is too long", token);
|
|
1874
|
+
throwWebAppError("WebAppBiometricManagerTokenInvalid" /* BiometricManagerTokenInvalid */);
|
|
1875
|
+
}
|
|
1876
|
+
this.checkInit();
|
|
1877
|
+
if (!this._isBiometricAvailable) {
|
|
1878
|
+
console.error("[@core-ease/telegram-kit] Biometrics is not available on this device.");
|
|
1879
|
+
throwWebAppError("WebAppBiometricManagerBiometricsNotAvailable" /* BiometricManagerBiometricsNotAvailable */);
|
|
1880
|
+
}
|
|
1881
|
+
if (!this.isAccessGranted) {
|
|
1882
|
+
console.error("[@core-ease/telegram-kit] Biometric access was not granted by the user.");
|
|
1883
|
+
throwWebAppError("WebAppBiometricManagerBiometricAccessNotGranted" /* BiometricManagerBiometricAccessNotGranted */);
|
|
1884
|
+
}
|
|
1885
|
+
if (this.tokenRequestState) {
|
|
1886
|
+
console.error("[@core-ease/telegram-kit] Token request is already in progress.");
|
|
1887
|
+
throwWebAppError("WebAppBiometricManagerTokenUpdateRequested" /* BiometricManagerTokenUpdateRequested */);
|
|
1888
|
+
}
|
|
1889
|
+
this.tokenRequestState = { callback };
|
|
1890
|
+
this.kernel.webView.postEvent("web_app_biometry_update_token", void 0, { token });
|
|
1891
|
+
return this;
|
|
1892
|
+
}
|
|
1893
|
+
openSettings() {
|
|
1894
|
+
if (!this.checkVersion()) return this;
|
|
1895
|
+
this.checkInit();
|
|
1896
|
+
if (!this._isBiometricAvailable) {
|
|
1897
|
+
console.error("[@core-ease/telegram-kit] Biometrics is not available on this device.");
|
|
1898
|
+
throwWebAppError("WebAppBiometricManagerBiometricsNotAvailable" /* BiometricManagerBiometricsNotAvailable */);
|
|
1899
|
+
}
|
|
1900
|
+
if (!this._isAccessRequested) {
|
|
1901
|
+
console.error("[@core-ease/telegram-kit] Biometric access was not requested yet.");
|
|
1902
|
+
throwWebAppError("WebAppBiometricManagerBiometricsAccessNotRequested" /* BiometricManagerBiometricsAccessNotRequested */);
|
|
1903
|
+
}
|
|
1904
|
+
if (this._isAccessGranted) {
|
|
1905
|
+
console.warn("[@core-ease/telegram-kit] Biometric access was granted by the user, no need to go to settings.");
|
|
1906
|
+
return this;
|
|
1907
|
+
}
|
|
1908
|
+
this.kernel.webView.postEvent("web_app_biometry_open_settings");
|
|
1909
|
+
return this;
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
// src/sdk/_internal/features/location-manager.ts
|
|
1914
|
+
var LocationManager = class {
|
|
1915
|
+
constructor(kernel) {
|
|
1916
|
+
this.kernel = kernel;
|
|
1917
|
+
this._isInited = false;
|
|
1918
|
+
this._isLocationAvailable = false;
|
|
1919
|
+
this._isAccessRequested = false;
|
|
1920
|
+
this._isAccessGranted = false;
|
|
1921
|
+
this.initCallbacks = [];
|
|
1922
|
+
this.getRequestCallbacks = [];
|
|
1923
|
+
this.handleLocationChecked = (_eventType, eventData) => {
|
|
1924
|
+
this._isInited = true;
|
|
1925
|
+
if (eventData.available) {
|
|
1926
|
+
this._isLocationAvailable = true;
|
|
1927
|
+
if (eventData.access_requested) {
|
|
1928
|
+
this._isAccessRequested = true;
|
|
1929
|
+
this._isAccessGranted = !!eventData.access_granted;
|
|
1930
|
+
} else {
|
|
1931
|
+
this._isAccessRequested = false;
|
|
1932
|
+
this._isAccessGranted = false;
|
|
1933
|
+
}
|
|
1934
|
+
} else {
|
|
1935
|
+
this._isLocationAvailable = false;
|
|
1936
|
+
this._isAccessRequested = false;
|
|
1937
|
+
this._isAccessGranted = false;
|
|
1938
|
+
}
|
|
1939
|
+
if (this.initCallbacks.length > 0) {
|
|
1940
|
+
this.initCallbacks.forEach((cb) => cb());
|
|
1941
|
+
this.initCallbacks = [];
|
|
1942
|
+
}
|
|
1943
|
+
this.kernel.receiveWebViewEvent("locationManagerUpdated");
|
|
1944
|
+
};
|
|
1945
|
+
this.handleLocationRequested = (_eventType, eventData) => {
|
|
1946
|
+
let locationData = null;
|
|
1947
|
+
if (eventData.available) {
|
|
1948
|
+
locationData = {
|
|
1949
|
+
latitude: eventData.latitude,
|
|
1950
|
+
longitude: eventData.longitude,
|
|
1951
|
+
altitude: null,
|
|
1952
|
+
course: null,
|
|
1953
|
+
speed: null,
|
|
1954
|
+
horizontal_accuracy: null,
|
|
1955
|
+
vertical_accuracy: null,
|
|
1956
|
+
course_accuracy: null,
|
|
1957
|
+
speed_accuracy: null
|
|
1958
|
+
};
|
|
1959
|
+
if (typeof eventData.altitude !== "undefined" && eventData.altitude !== null) {
|
|
1960
|
+
locationData.altitude = eventData.altitude;
|
|
1961
|
+
}
|
|
1962
|
+
if (typeof eventData.course !== "undefined" && eventData.course !== null) {
|
|
1963
|
+
locationData.course = eventData.course % 360;
|
|
1964
|
+
}
|
|
1965
|
+
if (typeof eventData.speed !== "undefined" && eventData.speed !== null) {
|
|
1966
|
+
locationData.speed = eventData.speed;
|
|
1967
|
+
}
|
|
1968
|
+
if (typeof eventData.horizontal_accuracy !== "undefined" && eventData.horizontal_accuracy !== null) {
|
|
1969
|
+
locationData.horizontal_accuracy = eventData.horizontal_accuracy;
|
|
1970
|
+
}
|
|
1971
|
+
if (typeof eventData.vertical_accuracy !== "undefined" && eventData.vertical_accuracy !== null) {
|
|
1972
|
+
locationData.vertical_accuracy = eventData.vertical_accuracy;
|
|
1973
|
+
}
|
|
1974
|
+
if (typeof eventData.course_accuracy !== "undefined" && eventData.course_accuracy !== null) {
|
|
1975
|
+
locationData.course_accuracy = eventData.course_accuracy;
|
|
1976
|
+
}
|
|
1977
|
+
if (typeof eventData.speed_accuracy !== "undefined" && eventData.speed_accuracy !== null) {
|
|
1978
|
+
locationData.speed_accuracy = eventData.speed_accuracy;
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
if (!eventData.available || !this._isLocationAvailable || !this._isAccessRequested || !this._isAccessGranted) {
|
|
1982
|
+
this.initCallbacks.push(() => this.locationResponse(locationData));
|
|
1983
|
+
this.kernel.webView.postEvent("web_app_check_location");
|
|
1984
|
+
} else {
|
|
1985
|
+
this.locationResponse(locationData);
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
kernel.webView.onEvent("location_checked", this.handleLocationChecked);
|
|
1989
|
+
kernel.webView.onEvent("location_requested", this.handleLocationRequested);
|
|
1990
|
+
}
|
|
1991
|
+
get isInited() {
|
|
1992
|
+
return this._isInited;
|
|
1993
|
+
}
|
|
1994
|
+
get isLocationAvailable() {
|
|
1995
|
+
return this._isInited && this._isLocationAvailable;
|
|
1996
|
+
}
|
|
1997
|
+
get isAccessRequested() {
|
|
1998
|
+
return this._isAccessRequested;
|
|
1999
|
+
}
|
|
2000
|
+
get isAccessGranted() {
|
|
2001
|
+
return this._isAccessRequested && this._isAccessGranted;
|
|
2002
|
+
}
|
|
2003
|
+
locationResponse(response) {
|
|
2004
|
+
if (this.getRequestCallbacks.length > 0) {
|
|
2005
|
+
this.getRequestCallbacks.forEach((cb) => cb(response));
|
|
2006
|
+
this.getRequestCallbacks = [];
|
|
2007
|
+
}
|
|
2008
|
+
if (response !== null) {
|
|
2009
|
+
this.kernel.receiveWebViewEvent("locationRequested", { locationData: response });
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
checkVersion() {
|
|
2013
|
+
return this.kernel.warnIfUnsupported("8.0", "LocationManager");
|
|
2014
|
+
}
|
|
2015
|
+
checkInit() {
|
|
2016
|
+
if (!this._isInited) {
|
|
2017
|
+
console.error("[@core-ease/telegram-kit] LocationManager should be inited before using.");
|
|
2018
|
+
throwWebAppError("WebAppLocationManagerNotInited" /* LocationManagerNotInited */);
|
|
2019
|
+
}
|
|
2020
|
+
return true;
|
|
2021
|
+
}
|
|
2022
|
+
init(callback) {
|
|
2023
|
+
if (!this.checkVersion()) return this;
|
|
2024
|
+
if (this._isInited) return this;
|
|
2025
|
+
if (callback) this.initCallbacks.push(callback);
|
|
2026
|
+
this.kernel.webView.postEvent("web_app_check_location");
|
|
2027
|
+
return this;
|
|
2028
|
+
}
|
|
2029
|
+
getLocation(callback) {
|
|
2030
|
+
if (!this.checkVersion()) return this;
|
|
2031
|
+
this.checkInit();
|
|
2032
|
+
if (!this._isLocationAvailable) {
|
|
2033
|
+
console.error("[@core-ease/telegram-kit] Location is not available on this device.");
|
|
2034
|
+
throwWebAppError("WebAppLocationManagerLocationNotAvailable" /* LocationManagerLocationNotAvailable */);
|
|
2035
|
+
}
|
|
2036
|
+
this.getRequestCallbacks.push(callback);
|
|
2037
|
+
this.kernel.webView.postEvent("web_app_request_location");
|
|
2038
|
+
return this;
|
|
2039
|
+
}
|
|
2040
|
+
openSettings() {
|
|
2041
|
+
if (!this.checkVersion()) return this;
|
|
2042
|
+
this.checkInit();
|
|
2043
|
+
if (!this._isLocationAvailable) {
|
|
2044
|
+
console.error("[@core-ease/telegram-kit] Location is not available on this device.");
|
|
2045
|
+
throwWebAppError("WebAppLocationManagerLocationNotAvailable" /* LocationManagerLocationNotAvailable */);
|
|
2046
|
+
}
|
|
2047
|
+
if (!this._isAccessRequested) {
|
|
2048
|
+
console.error("[@core-ease/telegram-kit] Location access was not requested yet.");
|
|
2049
|
+
throwWebAppError("WebAppLocationManagerLocationAccessNotRequested" /* LocationManagerLocationAccessNotRequested */);
|
|
2050
|
+
}
|
|
2051
|
+
if (this._isAccessGranted) {
|
|
2052
|
+
console.warn("[@core-ease/telegram-kit] Location access was granted by the user, no need to go to settings.");
|
|
2053
|
+
return this;
|
|
2054
|
+
}
|
|
2055
|
+
this.kernel.webView.postEvent("web_app_open_location_settings");
|
|
2056
|
+
return this;
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
|
|
2060
|
+
// src/sdk/_internal/features/invoice.ts
|
|
2061
|
+
var InvoiceManager = class {
|
|
2062
|
+
constructor(kernel) {
|
|
2063
|
+
this.kernel = kernel;
|
|
2064
|
+
this.openInvoices = {};
|
|
2065
|
+
this.handleInvoiceClosed = (_eventType, eventData) => {
|
|
2066
|
+
var _a;
|
|
2067
|
+
if (eventData.slug && this.openInvoices[eventData.slug]) {
|
|
2068
|
+
const invoiceData = this.openInvoices[eventData.slug];
|
|
2069
|
+
delete this.openInvoices[eventData.slug];
|
|
2070
|
+
(_a = invoiceData.callback) == null ? void 0 : _a.call(invoiceData, eventData.status);
|
|
2071
|
+
this.kernel.receiveWebViewEvent("invoiceClosed", { url: invoiceData.url, status: eventData.status });
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
kernel.webView.onEvent("invoice_closed", this.handleInvoiceClosed);
|
|
2075
|
+
}
|
|
2076
|
+
openInvoice(url, callback) {
|
|
2077
|
+
const a = document.createElement("A");
|
|
2078
|
+
a.href = url;
|
|
2079
|
+
const match = a.pathname.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
2080
|
+
const slug = match == null ? void 0 : match[2];
|
|
2081
|
+
if (a.protocol != "http:" && a.protocol != "https:" || a.hostname != "t.me" || !match || !slug) {
|
|
2082
|
+
console.error("[@core-ease/telegram-kit] Invoice url is invalid", url);
|
|
2083
|
+
throwWebAppError("WebAppInvoiceUrlInvalid" /* InvoiceUrlInvalid */);
|
|
2084
|
+
}
|
|
2085
|
+
this.kernel.requireVersion("6.1", "openInvoice");
|
|
2086
|
+
if (this.openInvoices[slug]) {
|
|
2087
|
+
console.error("[@core-ease/telegram-kit] Invoice is already opened");
|
|
2088
|
+
throwWebAppError("WebAppInvoiceOpened" /* InvoiceOpened */);
|
|
2089
|
+
}
|
|
2090
|
+
this.openInvoices[slug] = { url, callback };
|
|
2091
|
+
this.kernel.webView.postEvent("web_app_open_invoice", void 0, { slug });
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
|
|
2095
|
+
// src/sdk/_internal/features/clipboard.ts
|
|
2096
|
+
var ClipboardManager = class {
|
|
2097
|
+
constructor(kernel) {
|
|
2098
|
+
this.kernel = kernel;
|
|
2099
|
+
this.handleClipboardTextReceived = (_eventType, eventData) => {
|
|
2100
|
+
var _a;
|
|
2101
|
+
if (!eventData.req_id || !this.kernel.hasCallback(eventData.req_id)) return;
|
|
2102
|
+
const entry = this.kernel.takeCallback(eventData.req_id);
|
|
2103
|
+
const data = typeof eventData.data !== "undefined" ? eventData.data : null;
|
|
2104
|
+
(_a = entry == null ? void 0 : entry.callback) == null ? void 0 : _a.call(entry, data);
|
|
2105
|
+
this.kernel.receiveWebViewEvent("clipboardTextReceived", { data });
|
|
2106
|
+
};
|
|
2107
|
+
kernel.webView.onEvent("clipboard_text_received", this.handleClipboardTextReceived);
|
|
2108
|
+
}
|
|
2109
|
+
readTextFromClipboard(callback) {
|
|
2110
|
+
this.kernel.requireVersion("6.4", "readTextFromClipboard");
|
|
2111
|
+
const reqId = this.kernel.registerCallback(callback);
|
|
2112
|
+
this.kernel.webView.postEvent("web_app_read_text_from_clipboard", void 0, { req_id: reqId });
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
|
|
2116
|
+
// src/sdk/_internal/features/custom-method-helpers.ts
|
|
2117
|
+
function invokeGetRequestedContact(kernel, callback, timeout) {
|
|
2118
|
+
let reqTo;
|
|
2119
|
+
let fallbackTo;
|
|
2120
|
+
let reqDelay = 0;
|
|
2121
|
+
const reqInvoke = () => {
|
|
2122
|
+
kernel.invokeCustomMethod("getRequestedContact", {}, (_err, res) => {
|
|
2123
|
+
if (typeof res === "string" && res.substr(0, 1) == '"' && res.substr(-1) == '"') {
|
|
2124
|
+
res = JSON.parse(res);
|
|
2125
|
+
}
|
|
2126
|
+
if (res && res.length) {
|
|
2127
|
+
clearTimeout(fallbackTo);
|
|
2128
|
+
callback(res);
|
|
2129
|
+
} else {
|
|
2130
|
+
reqDelay += 50;
|
|
2131
|
+
reqTo = setTimeout(reqInvoke, reqDelay);
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
};
|
|
2135
|
+
const fallbackInvoke = () => {
|
|
2136
|
+
clearTimeout(reqTo);
|
|
2137
|
+
callback("");
|
|
2138
|
+
};
|
|
2139
|
+
fallbackTo = setTimeout(fallbackInvoke, timeout);
|
|
2140
|
+
reqInvoke();
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// src/sdk/_internal/features/contact.ts
|
|
2144
|
+
var ContactManager = class {
|
|
2145
|
+
constructor(kernel) {
|
|
2146
|
+
this.kernel = kernel;
|
|
2147
|
+
this.writeAccessRequested = false;
|
|
2148
|
+
this.contactRequested = false;
|
|
2149
|
+
this.handleWriteAccessRequested = (_eventType, eventData) => {
|
|
2150
|
+
var _a;
|
|
2151
|
+
if (this.writeAccessRequested) {
|
|
2152
|
+
const requestData = this.writeAccessRequested;
|
|
2153
|
+
this.writeAccessRequested = false;
|
|
2154
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, eventData.status == "allowed");
|
|
2155
|
+
this.kernel.receiveWebViewEvent("writeAccessRequested", { status: eventData.status });
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
this.handlePhoneRequested = (_eventType, eventData) => {
|
|
2159
|
+
var _a;
|
|
2160
|
+
if (!this.contactRequested) return;
|
|
2161
|
+
const requestData = this.contactRequested;
|
|
2162
|
+
this.contactRequested = false;
|
|
2163
|
+
const requestSent = eventData.status == "sent";
|
|
2164
|
+
const webViewEvent = { status: eventData.status };
|
|
2165
|
+
if (requestSent) {
|
|
2166
|
+
invokeGetRequestedContact(this.kernel, (res) => {
|
|
2167
|
+
var _a2;
|
|
2168
|
+
if (res && res.length) {
|
|
2169
|
+
webViewEvent.response = res;
|
|
2170
|
+
webViewEvent.responseUnsafe = urlParseQueryString(res);
|
|
2171
|
+
for (const key in webViewEvent.responseUnsafe) {
|
|
2172
|
+
const val = webViewEvent.responseUnsafe[key];
|
|
2173
|
+
try {
|
|
2174
|
+
if ((val == null ? void 0 : val.substr(0, 1)) == "{" && (val == null ? void 0 : val.substr(-1)) == "}" || (val == null ? void 0 : val.substr(0, 1)) == "[" && (val == null ? void 0 : val.substr(-1)) == "]") {
|
|
2175
|
+
webViewEvent.responseUnsafe[key] = JSON.parse(val);
|
|
2176
|
+
}
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
(_a2 = requestData.callback) == null ? void 0 : _a2.call(requestData, requestSent, webViewEvent);
|
|
2182
|
+
this.kernel.receiveWebViewEvent("contactRequested", webViewEvent);
|
|
2183
|
+
}, 3e3);
|
|
2184
|
+
} else {
|
|
2185
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, requestSent, webViewEvent);
|
|
2186
|
+
this.kernel.receiveWebViewEvent("contactRequested", webViewEvent);
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
kernel.webView.onEvent("write_access_requested", this.handleWriteAccessRequested);
|
|
2190
|
+
kernel.webView.onEvent("phone_requested", this.handlePhoneRequested);
|
|
2191
|
+
}
|
|
2192
|
+
requestWriteAccess(callback) {
|
|
2193
|
+
this.kernel.requireVersion("6.9", "requestWriteAccess");
|
|
2194
|
+
if (this.writeAccessRequested) {
|
|
2195
|
+
console.error("[@core-ease/telegram-kit] Write access is already requested");
|
|
2196
|
+
throwWebAppError("WebAppWriteAccessRequested" /* WriteAccessRequested */);
|
|
2197
|
+
}
|
|
2198
|
+
this.writeAccessRequested = { callback };
|
|
2199
|
+
this.kernel.webView.postEvent("web_app_request_write_access");
|
|
2200
|
+
}
|
|
2201
|
+
requestContact(callback) {
|
|
2202
|
+
this.kernel.requireVersion("6.9", "requestContact");
|
|
2203
|
+
if (this.contactRequested) {
|
|
2204
|
+
console.error("[@core-ease/telegram-kit] Contact is already requested");
|
|
2205
|
+
throwWebAppError("WebAppContactRequested" /* ContactRequested */);
|
|
2206
|
+
}
|
|
2207
|
+
this.contactRequested = { callback };
|
|
2208
|
+
this.kernel.webView.postEvent("web_app_request_phone");
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
// src/sdk/_internal/features/home-screen.ts
|
|
2213
|
+
var HomeScreenManager = class {
|
|
2214
|
+
constructor(kernel) {
|
|
2215
|
+
this.kernel = kernel;
|
|
2216
|
+
this.statusCallbacks = [];
|
|
2217
|
+
this.handleAdded = () => {
|
|
2218
|
+
this.kernel.receiveWebViewEvent("homeScreenAdded");
|
|
2219
|
+
};
|
|
2220
|
+
this.handleChecked = (_eventType, eventData) => {
|
|
2221
|
+
const status = eventData.status || "unknown";
|
|
2222
|
+
if (this.statusCallbacks.length > 0) {
|
|
2223
|
+
this.statusCallbacks.forEach((cb) => cb(status));
|
|
2224
|
+
this.statusCallbacks = [];
|
|
2225
|
+
}
|
|
2226
|
+
this.kernel.receiveWebViewEvent("homeScreenChecked", { status });
|
|
2227
|
+
};
|
|
2228
|
+
kernel.webView.onEvent("home_screen_added", this.handleAdded);
|
|
2229
|
+
kernel.webView.onEvent("home_screen_checked", this.handleChecked);
|
|
2230
|
+
}
|
|
2231
|
+
addToHomeScreen() {
|
|
2232
|
+
this.kernel.requireVersion("8.0", "addToHomeScreen");
|
|
2233
|
+
this.kernel.webView.postEvent("web_app_add_to_home_screen");
|
|
2234
|
+
}
|
|
2235
|
+
checkHomeScreenStatus(callback) {
|
|
2236
|
+
this.kernel.requireVersion("8.0", "checkHomeScreenStatus");
|
|
2237
|
+
if (callback) this.statusCallbacks.push(callback);
|
|
2238
|
+
this.kernel.webView.postEvent("web_app_check_home_screen");
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
|
|
2242
|
+
// src/sdk/_internal/features/download-file.ts
|
|
2243
|
+
var DownloadFileManager = class {
|
|
2244
|
+
constructor(kernel) {
|
|
2245
|
+
this.kernel = kernel;
|
|
2246
|
+
this.requested = false;
|
|
2247
|
+
this.handleFileDownloadRequested = (_eventType, eventData) => {
|
|
2248
|
+
var _a;
|
|
2249
|
+
if (!this.requested) return;
|
|
2250
|
+
const requestData = this.requested;
|
|
2251
|
+
this.requested = false;
|
|
2252
|
+
const isDownloading = eventData.status == "downloading";
|
|
2253
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, isDownloading);
|
|
2254
|
+
this.kernel.receiveWebViewEvent("fileDownloadRequested", { status: isDownloading ? "downloading" : "cancelled" });
|
|
2255
|
+
};
|
|
2256
|
+
kernel.webView.onEvent("file_download_requested", this.handleFileDownloadRequested);
|
|
2257
|
+
}
|
|
2258
|
+
downloadFile(params, callback) {
|
|
2259
|
+
this.kernel.requireVersion("8.0", "downloadFile");
|
|
2260
|
+
if (this.requested) {
|
|
2261
|
+
console.error("[@core-ease/telegram-kit] Popup is already opened");
|
|
2262
|
+
throwWebAppError("WebAppDownloadFilePopupOpened" /* DownloadFilePopupOpened */);
|
|
2263
|
+
}
|
|
2264
|
+
const a = document.createElement("A");
|
|
2265
|
+
const dlParams = {};
|
|
2266
|
+
if (!params || !params.url || !params.url.length) {
|
|
2267
|
+
console.error("[@core-ease/telegram-kit] Url is required");
|
|
2268
|
+
throwWebAppError("WebAppDownloadFileParamInvalid" /* DownloadFileParamInvalid */);
|
|
2269
|
+
}
|
|
2270
|
+
a.href = params.url;
|
|
2271
|
+
if (a.protocol != "https:") {
|
|
2272
|
+
console.error("[@core-ease/telegram-kit] Url protocol is not supported", params.url);
|
|
2273
|
+
throwWebAppError("WebAppDownloadFileParamInvalid" /* DownloadFileParamInvalid */);
|
|
2274
|
+
}
|
|
2275
|
+
dlParams.url = a.href;
|
|
2276
|
+
if (!params || !params.file_name || !params.file_name.length) {
|
|
2277
|
+
console.error("[@core-ease/telegram-kit] File name is required");
|
|
2278
|
+
throwWebAppError("WebAppDownloadFileParamInvalid" /* DownloadFileParamInvalid */);
|
|
2279
|
+
}
|
|
2280
|
+
dlParams.file_name = params.file_name;
|
|
2281
|
+
this.requested = { callback };
|
|
2282
|
+
this.kernel.webView.postEvent("web_app_request_file_download", void 0, dlParams);
|
|
2283
|
+
}
|
|
2284
|
+
};
|
|
2285
|
+
|
|
2286
|
+
// src/sdk/_internal/features/sharing.ts
|
|
2287
|
+
var SharingManager = class {
|
|
2288
|
+
constructor(kernel) {
|
|
2289
|
+
this.kernel = kernel;
|
|
2290
|
+
this.shareMessageOpened = false;
|
|
2291
|
+
this.requestChatOpened = false;
|
|
2292
|
+
this.handlePreparedMessageSent = () => {
|
|
2293
|
+
var _a;
|
|
2294
|
+
if (!this.shareMessageOpened) return;
|
|
2295
|
+
const requestData = this.shareMessageOpened;
|
|
2296
|
+
this.shareMessageOpened = false;
|
|
2297
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, true);
|
|
2298
|
+
this.kernel.receiveWebViewEvent("shareMessageSent");
|
|
2299
|
+
};
|
|
2300
|
+
this.handlePreparedMessageFailed = (_eventType, eventData) => {
|
|
2301
|
+
var _a;
|
|
2302
|
+
if (!this.shareMessageOpened) return;
|
|
2303
|
+
const requestData = this.shareMessageOpened;
|
|
2304
|
+
this.shareMessageOpened = false;
|
|
2305
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, false);
|
|
2306
|
+
this.kernel.receiveWebViewEvent("shareMessageFailed", { error: eventData.error });
|
|
2307
|
+
};
|
|
2308
|
+
this.handleRequestedChatSent = () => {
|
|
2309
|
+
var _a;
|
|
2310
|
+
if (!this.requestChatOpened) return;
|
|
2311
|
+
const requestData = this.requestChatOpened;
|
|
2312
|
+
this.requestChatOpened = false;
|
|
2313
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, true);
|
|
2314
|
+
this.kernel.receiveWebViewEvent("requestedChatSent");
|
|
2315
|
+
};
|
|
2316
|
+
this.handleRequestedChatFailed = (_eventType, eventData) => {
|
|
2317
|
+
var _a;
|
|
2318
|
+
if (!this.requestChatOpened) return;
|
|
2319
|
+
const requestData = this.requestChatOpened;
|
|
2320
|
+
this.requestChatOpened = false;
|
|
2321
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, false);
|
|
2322
|
+
this.kernel.receiveWebViewEvent("requestedChatFailed", { error: eventData.error });
|
|
2323
|
+
};
|
|
2324
|
+
kernel.webView.onEvent("prepared_message_sent", this.handlePreparedMessageSent);
|
|
2325
|
+
kernel.webView.onEvent("prepared_message_failed", this.handlePreparedMessageFailed);
|
|
2326
|
+
kernel.webView.onEvent("requested_chat_sent", this.handleRequestedChatSent);
|
|
2327
|
+
kernel.webView.onEvent("requested_chat_failed", this.handleRequestedChatFailed);
|
|
2328
|
+
}
|
|
2329
|
+
shareToStory(mediaUrl, params = {}) {
|
|
2330
|
+
this.kernel.requireVersion("7.8", "shareToStory");
|
|
2331
|
+
const a = document.createElement("A");
|
|
2332
|
+
a.href = mediaUrl;
|
|
2333
|
+
if (a.protocol != "http:" && a.protocol != "https:") {
|
|
2334
|
+
console.error("[@core-ease/telegram-kit] Media url protocol is not supported", mediaUrl);
|
|
2335
|
+
throwWebAppError("WebAppMediaUrlInvalid" /* MediaUrlInvalid */);
|
|
2336
|
+
}
|
|
2337
|
+
const shareParams = { media_url: a.href };
|
|
2338
|
+
if (typeof params.text !== "undefined") {
|
|
2339
|
+
const text = strTrim(params.text);
|
|
2340
|
+
if (text.length > 2048) {
|
|
2341
|
+
console.error("[@core-ease/telegram-kit] Text is too long", text);
|
|
2342
|
+
throwWebAppError("WebAppShareToStoryParamInvalid" /* ShareToStoryParamInvalid */);
|
|
2343
|
+
}
|
|
2344
|
+
if (text.length > 0) shareParams.text = text;
|
|
2345
|
+
}
|
|
2346
|
+
if (typeof params.widget_link !== "undefined") {
|
|
2347
|
+
const widgetLinkParam = params.widget_link || {};
|
|
2348
|
+
a.href = widgetLinkParam.url;
|
|
2349
|
+
if (a.protocol != "http:" && a.protocol != "https:") {
|
|
2350
|
+
console.error("[@core-ease/telegram-kit] Link protocol is not supported", widgetLinkParam.url);
|
|
2351
|
+
throwWebAppError("WebAppShareToStoryParamInvalid" /* ShareToStoryParamInvalid */);
|
|
2352
|
+
}
|
|
2353
|
+
const widgetLink = { url: a.href };
|
|
2354
|
+
if (typeof widgetLinkParam.name !== "undefined") {
|
|
2355
|
+
const linkName = strTrim(widgetLinkParam.name);
|
|
2356
|
+
if (linkName.length > 48) {
|
|
2357
|
+
console.error("[@core-ease/telegram-kit] Link name is too long", linkName);
|
|
2358
|
+
throwWebAppError("WebAppShareToStoryParamInvalid" /* ShareToStoryParamInvalid */);
|
|
2359
|
+
}
|
|
2360
|
+
if (linkName.length > 0) widgetLink.name = linkName;
|
|
2361
|
+
}
|
|
2362
|
+
shareParams.widget_link = widgetLink;
|
|
2363
|
+
}
|
|
2364
|
+
this.kernel.webView.postEvent("web_app_share_to_story", void 0, shareParams);
|
|
2365
|
+
}
|
|
2366
|
+
shareMessage(msgId, callback) {
|
|
2367
|
+
this.kernel.requireVersion("8.0", "shareMessage");
|
|
2368
|
+
if (this.shareMessageOpened) {
|
|
2369
|
+
console.error("[@core-ease/telegram-kit] Share message is already opened");
|
|
2370
|
+
throwWebAppError("WebAppShareMessageOpened" /* ShareMessageOpened */);
|
|
2371
|
+
}
|
|
2372
|
+
this.shareMessageOpened = { callback };
|
|
2373
|
+
this.kernel.webView.postEvent("web_app_send_prepared_message", void 0, { id: msgId });
|
|
2374
|
+
}
|
|
2375
|
+
requestChat(reqId, callback) {
|
|
2376
|
+
this.kernel.requireVersion("9.6", "requestChat");
|
|
2377
|
+
if (this.requestChatOpened) {
|
|
2378
|
+
console.error("[@core-ease/telegram-kit] Request chat is already opened");
|
|
2379
|
+
throwWebAppError("WebAppRequestChatOpened" /* RequestChatOpened */);
|
|
2380
|
+
}
|
|
2381
|
+
this.requestChatOpened = { callback };
|
|
2382
|
+
this.kernel.webView.postEvent("web_app_request_chat", void 0, { req_id: reqId });
|
|
2383
|
+
}
|
|
2384
|
+
switchInlineQuery(query, chooseChatTypes, initParams) {
|
|
2385
|
+
this.kernel.requireVersion("6.6", "switchInlineQuery");
|
|
2386
|
+
if (!initParams.tgWebAppBotInline) {
|
|
2387
|
+
console.error(
|
|
2388
|
+
"[@core-ease/telegram-kit] Inline mode is disabled for this bot. Read more about inline mode: https://core.telegram.org/bots/inline"
|
|
2389
|
+
);
|
|
2390
|
+
throwWebAppError("WebAppInlineModeDisabled" /* InlineModeDisabled */);
|
|
2391
|
+
}
|
|
2392
|
+
const q = query || "";
|
|
2393
|
+
if (q.length > 256) {
|
|
2394
|
+
console.error("[@core-ease/telegram-kit] Inline query is too long", q);
|
|
2395
|
+
throwWebAppError("WebAppInlineQueryInvalid" /* InlineQueryInvalid */);
|
|
2396
|
+
}
|
|
2397
|
+
const chatTypes = [];
|
|
2398
|
+
if (chooseChatTypes) {
|
|
2399
|
+
if (!Array.isArray(chooseChatTypes)) {
|
|
2400
|
+
console.error("[@core-ease/telegram-kit] Choose chat types should be an array", chooseChatTypes);
|
|
2401
|
+
throwWebAppError("WebAppInlineChooseChatTypesInvalid" /* InlineChooseChatTypesInvalid */);
|
|
2402
|
+
}
|
|
2403
|
+
const goodTypes = { users: 1, bots: 1, groups: 1, channels: 1 };
|
|
2404
|
+
for (const chatType of chooseChatTypes) {
|
|
2405
|
+
if (!goodTypes[chatType]) {
|
|
2406
|
+
console.error("[@core-ease/telegram-kit] Choose chat type is invalid", chatType);
|
|
2407
|
+
throwWebAppError("WebAppInlineChooseChatTypeInvalid" /* InlineChooseChatTypeInvalid */);
|
|
2408
|
+
}
|
|
2409
|
+
if (goodTypes[chatType] != 2) {
|
|
2410
|
+
goodTypes[chatType] = 2;
|
|
2411
|
+
chatTypes.push(chatType);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
this.kernel.webView.postEvent("web_app_switch_inline_query", void 0, { query: q, chat_types: chatTypes });
|
|
2416
|
+
}
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
// src/sdk/_internal/features/emoji-status.ts
|
|
2420
|
+
var EmojiStatusManager = class {
|
|
2421
|
+
constructor(kernel) {
|
|
2422
|
+
this.kernel = kernel;
|
|
2423
|
+
this.setRequested = false;
|
|
2424
|
+
this.accessRequested = false;
|
|
2425
|
+
this.handleSet = () => {
|
|
2426
|
+
var _a;
|
|
2427
|
+
if (!this.setRequested) return;
|
|
2428
|
+
const requestData = this.setRequested;
|
|
2429
|
+
this.setRequested = false;
|
|
2430
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, true);
|
|
2431
|
+
this.kernel.receiveWebViewEvent("emojiStatusSet");
|
|
2432
|
+
};
|
|
2433
|
+
this.handleFailed = (_eventType, eventData) => {
|
|
2434
|
+
var _a;
|
|
2435
|
+
if (!this.setRequested) return;
|
|
2436
|
+
const requestData = this.setRequested;
|
|
2437
|
+
this.setRequested = false;
|
|
2438
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, false);
|
|
2439
|
+
this.kernel.receiveWebViewEvent("emojiStatusFailed", { error: eventData.error });
|
|
2440
|
+
};
|
|
2441
|
+
this.handleAccessRequested = (_eventType, eventData) => {
|
|
2442
|
+
var _a;
|
|
2443
|
+
if (!this.accessRequested) return;
|
|
2444
|
+
const requestData = this.accessRequested;
|
|
2445
|
+
this.accessRequested = false;
|
|
2446
|
+
(_a = requestData.callback) == null ? void 0 : _a.call(requestData, eventData.status == "allowed");
|
|
2447
|
+
this.kernel.receiveWebViewEvent("emojiStatusAccessRequested", { status: eventData.status });
|
|
2448
|
+
};
|
|
2449
|
+
kernel.webView.onEvent("emoji_status_set", this.handleSet);
|
|
2450
|
+
kernel.webView.onEvent("emoji_status_failed", this.handleFailed);
|
|
2451
|
+
kernel.webView.onEvent("emoji_status_access_requested", this.handleAccessRequested);
|
|
2452
|
+
}
|
|
2453
|
+
setEmojiStatus(customEmojiId, params = {}, callback) {
|
|
2454
|
+
this.kernel.requireVersion("8.0", "setEmojiStatus");
|
|
2455
|
+
const statusParams = { custom_emoji_id: customEmojiId };
|
|
2456
|
+
if (typeof params.duration !== "undefined") {
|
|
2457
|
+
statusParams.duration = params.duration;
|
|
2458
|
+
}
|
|
2459
|
+
if (this.setRequested) {
|
|
2460
|
+
console.error("[@core-ease/telegram-kit] Emoji status is already requested");
|
|
2461
|
+
throwWebAppError("WebAppEmojiStatusRequested" /* EmojiStatusRequested */);
|
|
2462
|
+
}
|
|
2463
|
+
this.setRequested = { callback };
|
|
2464
|
+
this.kernel.webView.postEvent("web_app_set_emoji_status", void 0, statusParams);
|
|
2465
|
+
}
|
|
2466
|
+
requestEmojiStatusAccess(callback) {
|
|
2467
|
+
this.kernel.requireVersion("8.0", "requestEmojiStatusAccess");
|
|
2468
|
+
if (this.accessRequested) {
|
|
2469
|
+
console.error("[@core-ease/telegram-kit] Emoji status permission is already requested");
|
|
2470
|
+
throwWebAppError("WebAppEmojiStatusAccessRequested" /* EmojiStatusAccessRequested */);
|
|
2471
|
+
}
|
|
2472
|
+
this.accessRequested = { callback };
|
|
2473
|
+
this.kernel.webView.postEvent("web_app_request_emoji_status_access");
|
|
2474
|
+
}
|
|
2475
|
+
};
|
|
2476
|
+
|
|
2477
|
+
// src/sdk/_internal/features/links.ts
|
|
2478
|
+
var LinkManager = class {
|
|
2479
|
+
constructor(kernel) {
|
|
2480
|
+
this.kernel = kernel;
|
|
2481
|
+
/**
|
|
2482
|
+
* Intercepts clicks on in-page `t.me` links while running inside an
|
|
2483
|
+
* iframe (web.telegram.org) and routes them through `openTelegramLink`
|
|
2484
|
+
* instead of letting the browser navigate directly.
|
|
2485
|
+
*/
|
|
2486
|
+
this.handleDocumentClick = (e) => {
|
|
2487
|
+
if (e.metaKey || e.ctrlKey) return;
|
|
2488
|
+
let el = e.target;
|
|
2489
|
+
while (el && el.tagName != "A" && el.parentNode) {
|
|
2490
|
+
el = el.parentNode;
|
|
2491
|
+
}
|
|
2492
|
+
if (el && el.tagName == "A" && el.target != "_blank" && (el.protocol == "http:" || el.protocol == "https:") && el.hostname == "t.me") {
|
|
2493
|
+
this.openTelegramLink(el.href);
|
|
2494
|
+
e.preventDefault();
|
|
2495
|
+
}
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2498
|
+
openLink(url, options = {}) {
|
|
2499
|
+
const a = document.createElement("A");
|
|
2500
|
+
a.href = url;
|
|
2501
|
+
if (a.protocol != "http:" && a.protocol != "https:") {
|
|
2502
|
+
console.error("[@core-ease/telegram-kit] Url protocol is not supported", url);
|
|
2503
|
+
throwWebAppError("WebAppTgUrlInvalid" /* TgUrlInvalid */);
|
|
2504
|
+
}
|
|
2505
|
+
const resolvedUrl = a.href;
|
|
2506
|
+
if (this.kernel.versionAtLeast("6.1")) {
|
|
2507
|
+
const reqParams = { url: resolvedUrl };
|
|
2508
|
+
if (this.kernel.versionAtLeast("6.4") && options.try_instant_view) {
|
|
2509
|
+
reqParams.try_instant_view = true;
|
|
2510
|
+
}
|
|
2511
|
+
if (this.kernel.versionAtLeast("7.6") && options.try_browser) {
|
|
2512
|
+
reqParams.try_browser = options.try_browser;
|
|
2513
|
+
}
|
|
2514
|
+
this.kernel.webView.postEvent("web_app_open_link", void 0, reqParams);
|
|
2515
|
+
} else {
|
|
2516
|
+
window.open(resolvedUrl, "_blank");
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
openTelegramLink(url, options = {}) {
|
|
2520
|
+
const a = document.createElement("A");
|
|
2521
|
+
a.href = url;
|
|
2522
|
+
if (a.protocol != "http:" && a.protocol != "https:") {
|
|
2523
|
+
console.error("[@core-ease/telegram-kit] Url protocol is not supported", url);
|
|
2524
|
+
throwWebAppError("WebAppTgUrlInvalid" /* TgUrlInvalid */);
|
|
2525
|
+
}
|
|
2526
|
+
if (a.hostname != "t.me") {
|
|
2527
|
+
console.error("[@core-ease/telegram-kit] Url host is not supported", url);
|
|
2528
|
+
throwWebAppError("WebAppTgUrlInvalid" /* TgUrlInvalid */);
|
|
2529
|
+
}
|
|
2530
|
+
const pathFull = a.pathname + a.search;
|
|
2531
|
+
if (this.kernel.webView.isIframe || this.kernel.versionAtLeast("6.1")) {
|
|
2532
|
+
const reqParams = { path_full: pathFull };
|
|
2533
|
+
if (options.force_request) {
|
|
2534
|
+
reqParams.force_request = true;
|
|
2535
|
+
}
|
|
2536
|
+
this.kernel.webView.postEvent("web_app_open_tg_link", void 0, reqParams);
|
|
2537
|
+
} else {
|
|
2538
|
+
location.href = "https://t.me" + pathFull;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2542
|
+
|
|
2543
|
+
// src/sdk/_internal/sensors/motion-sensor-base.ts
|
|
2544
|
+
var MotionSensorBase = class {
|
|
2545
|
+
constructor(kernel, names, initialValues) {
|
|
2546
|
+
this.kernel = kernel;
|
|
2547
|
+
this.names = names;
|
|
2548
|
+
this._isStarted = false;
|
|
2549
|
+
this.startCallbacks = [];
|
|
2550
|
+
this.stopCallbacks = [];
|
|
2551
|
+
this.handleStarted = () => {
|
|
2552
|
+
this._isStarted = true;
|
|
2553
|
+
if (this.startCallbacks.length > 0) {
|
|
2554
|
+
this.startCallbacks.forEach((cb) => cb(true));
|
|
2555
|
+
this.startCallbacks = [];
|
|
2556
|
+
}
|
|
2557
|
+
this.kernel.receiveWebViewEvent(this.names.webViewStarted);
|
|
2558
|
+
};
|
|
2559
|
+
this.handleStopped = () => {
|
|
2560
|
+
this._isStarted = false;
|
|
2561
|
+
if (this.stopCallbacks.length > 0) {
|
|
2562
|
+
this.stopCallbacks.forEach((cb) => cb(true));
|
|
2563
|
+
this.stopCallbacks = [];
|
|
2564
|
+
}
|
|
2565
|
+
this.kernel.receiveWebViewEvent(this.names.webViewStopped);
|
|
2566
|
+
};
|
|
2567
|
+
this.handleChanged = (_eventType, eventData) => {
|
|
2568
|
+
this.values = this.mapChangedPayload(eventData);
|
|
2569
|
+
this.kernel.receiveWebViewEvent(this.names.webViewChanged);
|
|
2570
|
+
};
|
|
2571
|
+
this.handleFailed = (_eventType, eventData) => {
|
|
2572
|
+
if (this.startCallbacks.length > 0) {
|
|
2573
|
+
this.startCallbacks.forEach((cb) => cb(false));
|
|
2574
|
+
this.startCallbacks = [];
|
|
2575
|
+
}
|
|
2576
|
+
this.kernel.receiveWebViewEvent(this.names.webViewFailed, { error: eventData.error });
|
|
2577
|
+
};
|
|
2578
|
+
this.values = initialValues;
|
|
2579
|
+
kernel.webView.onEvent(names.started, this.handleStarted);
|
|
2580
|
+
kernel.webView.onEvent(names.stopped, this.handleStopped);
|
|
2581
|
+
kernel.webView.onEvent(names.changed, this.handleChanged);
|
|
2582
|
+
kernel.webView.onEvent(names.failed, this.handleFailed);
|
|
2583
|
+
}
|
|
2584
|
+
get isStarted() {
|
|
2585
|
+
return this._isStarted;
|
|
2586
|
+
}
|
|
2587
|
+
checkVersion() {
|
|
2588
|
+
return this.kernel.warnIfUnsupported(this.names.minVersion, this.names.displayName);
|
|
2589
|
+
}
|
|
2590
|
+
buildStartParams(refreshRate) {
|
|
2591
|
+
const params = {};
|
|
2592
|
+
const rate = parseInt(String(refreshRate != null ? refreshRate : 1e3));
|
|
2593
|
+
if (isNaN(rate) || rate < 20 || rate > 1e3) {
|
|
2594
|
+
console.warn(`[@core-ease/telegram-kit] ${this.names.displayName} refresh_rate is invalid`, rate);
|
|
2595
|
+
} else {
|
|
2596
|
+
params.refresh_rate = rate;
|
|
2597
|
+
}
|
|
2598
|
+
return params;
|
|
2599
|
+
}
|
|
2600
|
+
doStart(reqParams, callback) {
|
|
2601
|
+
if (callback) this.startCallbacks.push(callback);
|
|
2602
|
+
this.kernel.webView.postEvent(this.names.startCommand, void 0, reqParams);
|
|
2603
|
+
}
|
|
2604
|
+
stop(callback) {
|
|
2605
|
+
if (!this.checkVersion()) return this;
|
|
2606
|
+
if (callback) this.stopCallbacks.push(callback);
|
|
2607
|
+
this.kernel.webView.postEvent(this.names.stopCommand);
|
|
2608
|
+
return this;
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
// src/sdk/_internal/sensors/accelerometer.ts
|
|
2613
|
+
var Accelerometer = class extends MotionSensorBase {
|
|
2614
|
+
constructor(kernel) {
|
|
2615
|
+
super(
|
|
2616
|
+
kernel,
|
|
2617
|
+
{
|
|
2618
|
+
started: "accelerometer_started",
|
|
2619
|
+
stopped: "accelerometer_stopped",
|
|
2620
|
+
changed: "accelerometer_changed",
|
|
2621
|
+
failed: "accelerometer_failed",
|
|
2622
|
+
webViewStarted: "accelerometerStarted",
|
|
2623
|
+
webViewStopped: "accelerometerStopped",
|
|
2624
|
+
webViewChanged: "accelerometerChanged",
|
|
2625
|
+
webViewFailed: "accelerometerFailed",
|
|
2626
|
+
startCommand: "web_app_start_accelerometer",
|
|
2627
|
+
stopCommand: "web_app_stop_accelerometer",
|
|
2628
|
+
minVersion: "8.0",
|
|
2629
|
+
displayName: "Accelerometer"
|
|
2630
|
+
},
|
|
2631
|
+
{ x: null, y: null, z: null }
|
|
2632
|
+
);
|
|
2633
|
+
}
|
|
2634
|
+
mapChangedPayload(eventData) {
|
|
2635
|
+
return { x: eventData.x, y: eventData.y, z: eventData.z };
|
|
2636
|
+
}
|
|
2637
|
+
get x() {
|
|
2638
|
+
return this.values.x;
|
|
2639
|
+
}
|
|
2640
|
+
get y() {
|
|
2641
|
+
return this.values.y;
|
|
2642
|
+
}
|
|
2643
|
+
get z() {
|
|
2644
|
+
return this.values.z;
|
|
2645
|
+
}
|
|
2646
|
+
start(params = {}, callback) {
|
|
2647
|
+
if (!this.checkVersion()) return this;
|
|
2648
|
+
const reqParams = this.buildStartParams(params.refresh_rate);
|
|
2649
|
+
this.doStart(reqParams, callback);
|
|
2650
|
+
return this;
|
|
2651
|
+
}
|
|
2652
|
+
};
|
|
2653
|
+
|
|
2654
|
+
// src/sdk/_internal/sensors/gyroscope.ts
|
|
2655
|
+
var Gyroscope = class extends MotionSensorBase {
|
|
2656
|
+
constructor(kernel) {
|
|
2657
|
+
super(
|
|
2658
|
+
kernel,
|
|
2659
|
+
{
|
|
2660
|
+
started: "gyroscope_started",
|
|
2661
|
+
stopped: "gyroscope_stopped",
|
|
2662
|
+
changed: "gyroscope_changed",
|
|
2663
|
+
failed: "gyroscope_failed",
|
|
2664
|
+
webViewStarted: "gyroscopeStarted",
|
|
2665
|
+
webViewStopped: "gyroscopeStopped",
|
|
2666
|
+
webViewChanged: "gyroscopeChanged",
|
|
2667
|
+
webViewFailed: "gyroscopeFailed",
|
|
2668
|
+
startCommand: "web_app_start_gyroscope",
|
|
2669
|
+
stopCommand: "web_app_stop_gyroscope",
|
|
2670
|
+
minVersion: "8.0",
|
|
2671
|
+
displayName: "Gyroscope"
|
|
2672
|
+
},
|
|
2673
|
+
{ x: null, y: null, z: null }
|
|
2674
|
+
);
|
|
2675
|
+
}
|
|
2676
|
+
mapChangedPayload(eventData) {
|
|
2677
|
+
return { x: eventData.x, y: eventData.y, z: eventData.z };
|
|
2678
|
+
}
|
|
2679
|
+
get x() {
|
|
2680
|
+
return this.values.x;
|
|
2681
|
+
}
|
|
2682
|
+
get y() {
|
|
2683
|
+
return this.values.y;
|
|
2684
|
+
}
|
|
2685
|
+
get z() {
|
|
2686
|
+
return this.values.z;
|
|
2687
|
+
}
|
|
2688
|
+
start(params = {}, callback) {
|
|
2689
|
+
if (!this.checkVersion()) return this;
|
|
2690
|
+
const reqParams = this.buildStartParams(params.refresh_rate);
|
|
2691
|
+
this.doStart(reqParams, callback);
|
|
2692
|
+
return this;
|
|
2693
|
+
}
|
|
2694
|
+
};
|
|
2695
|
+
|
|
2696
|
+
// src/sdk/_internal/sensors/device-orientation.ts
|
|
2697
|
+
var DeviceOrientation = class extends MotionSensorBase {
|
|
2698
|
+
constructor(kernel) {
|
|
2699
|
+
super(
|
|
2700
|
+
kernel,
|
|
2701
|
+
{
|
|
2702
|
+
started: "device_orientation_started",
|
|
2703
|
+
stopped: "device_orientation_stopped",
|
|
2704
|
+
changed: "device_orientation_changed",
|
|
2705
|
+
failed: "device_orientation_failed",
|
|
2706
|
+
webViewStarted: "deviceOrientationStarted",
|
|
2707
|
+
webViewStopped: "deviceOrientationStopped",
|
|
2708
|
+
webViewChanged: "deviceOrientationChanged",
|
|
2709
|
+
webViewFailed: "deviceOrientationFailed",
|
|
2710
|
+
startCommand: "web_app_start_device_orientation",
|
|
2711
|
+
stopCommand: "web_app_stop_device_orientation",
|
|
2712
|
+
minVersion: "8.0",
|
|
2713
|
+
displayName: "DeviceOrientation"
|
|
2714
|
+
},
|
|
2715
|
+
{ absolute: false, alpha: null, beta: null, gamma: null }
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
mapChangedPayload(eventData) {
|
|
2719
|
+
return {
|
|
2720
|
+
absolute: !!eventData.absolute,
|
|
2721
|
+
alpha: eventData.alpha,
|
|
2722
|
+
beta: eventData.beta,
|
|
2723
|
+
gamma: eventData.gamma
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
get absolute() {
|
|
2727
|
+
return this.values.absolute;
|
|
2728
|
+
}
|
|
2729
|
+
get alpha() {
|
|
2730
|
+
return this.values.alpha;
|
|
2731
|
+
}
|
|
2732
|
+
get beta() {
|
|
2733
|
+
return this.values.beta;
|
|
2734
|
+
}
|
|
2735
|
+
get gamma() {
|
|
2736
|
+
return this.values.gamma;
|
|
2737
|
+
}
|
|
2738
|
+
start(params = {}, callback) {
|
|
2739
|
+
if (!this.checkVersion()) return this;
|
|
2740
|
+
const reqParams = this.buildStartParams(params.refresh_rate);
|
|
2741
|
+
reqParams.need_absolute = !!params.need_absolute;
|
|
2742
|
+
this.doStart(reqParams, callback);
|
|
2743
|
+
return this;
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
|
|
2747
|
+
// src/sdk/_internal/webapp.ts
|
|
2748
|
+
var WebApp = class {
|
|
2749
|
+
constructor(webView) {
|
|
2750
|
+
this.webView = webView;
|
|
2751
|
+
this.webAppInitData = "";
|
|
2752
|
+
this.webAppInitDataUnsafe = {};
|
|
2753
|
+
this.webAppPlatform = "unknown";
|
|
2754
|
+
this.webAppIsActive = true;
|
|
2755
|
+
this.handleThemeChanged = (_eventType, eventData) => {
|
|
2756
|
+
if (eventData.theme_params) {
|
|
2757
|
+
this.theme.setThemeParams(eventData.theme_params);
|
|
2758
|
+
this.MainButton.setParams({});
|
|
2759
|
+
this.SecondaryButton.setParams({});
|
|
2760
|
+
this.theme.updateHeaderColor();
|
|
2761
|
+
this.theme.updateBackgroundColor();
|
|
2762
|
+
this.theme.updateBottomBarColor();
|
|
2763
|
+
this.kernel.receiveWebViewEvent("themeChanged");
|
|
2764
|
+
}
|
|
2765
|
+
};
|
|
2766
|
+
this.handleVisibilityChanged = (_eventType, eventData) => {
|
|
2767
|
+
if (eventData.is_visible) {
|
|
2768
|
+
this.webAppIsActive = true;
|
|
2769
|
+
this.kernel.receiveWebViewEvent("activated");
|
|
2770
|
+
} else {
|
|
2771
|
+
this.webAppIsActive = false;
|
|
2772
|
+
this.kernel.receiveWebViewEvent("deactivated");
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
const kernel = new WebAppKernel(webView);
|
|
2776
|
+
this.kernel = kernel;
|
|
2777
|
+
const initParams = webView.initParams;
|
|
2778
|
+
if (initParams.tgWebAppData && initParams.tgWebAppData.length) {
|
|
2779
|
+
this.webAppInitData = initParams.tgWebAppData;
|
|
2780
|
+
const parsed = urlParseQueryString(this.webAppInitData);
|
|
2781
|
+
for (const key in parsed) {
|
|
2782
|
+
const val = parsed[key];
|
|
2783
|
+
try {
|
|
2784
|
+
if ((val == null ? void 0 : val.substr(0, 1)) == "{" && (val == null ? void 0 : val.substr(-1)) == "}" || (val == null ? void 0 : val.substr(0, 1)) == "[" && (val == null ? void 0 : val.substr(-1)) == "]") {
|
|
2785
|
+
parsed[key] = JSON.parse(val);
|
|
2786
|
+
}
|
|
2787
|
+
} catch (e) {
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
this.webAppInitDataUnsafe = parsed;
|
|
2791
|
+
}
|
|
2792
|
+
if (initParams.tgWebAppPlatform) {
|
|
2793
|
+
this.webAppPlatform = initParams.tgWebAppPlatform;
|
|
2794
|
+
}
|
|
2795
|
+
this.theme = new ThemeManager(kernel);
|
|
2796
|
+
this.viewport = new ViewportManager(kernel);
|
|
2797
|
+
this.debugBar = new DebugBottomBar(kernel, () => this.theme.getBottomBarColor());
|
|
2798
|
+
this.BackButton = new BackButton(kernel);
|
|
2799
|
+
this.MainButton = new BottomButton("main", kernel, this.theme, this.debugBar);
|
|
2800
|
+
this.SecondaryButton = new BottomButton("secondary", kernel, this.theme, this.debugBar);
|
|
2801
|
+
this.SettingsButton = new SettingsButton(kernel);
|
|
2802
|
+
this.popups = new PopupManager(kernel);
|
|
2803
|
+
this.scanQr = new ScanQrManager(kernel);
|
|
2804
|
+
this.HapticFeedback = new HapticFeedback(kernel);
|
|
2805
|
+
this.CloudStorage = new CloudStorage(kernel);
|
|
2806
|
+
this.DeviceStorage = new DeviceStorage(kernel);
|
|
2807
|
+
this.SecureStorage = new SecureStorage(kernel);
|
|
2808
|
+
this.BiometricManager = new BiometricManager(kernel);
|
|
2809
|
+
this.LocationManager = new LocationManager(kernel);
|
|
2810
|
+
this.invoices = new InvoiceManager(kernel);
|
|
2811
|
+
this.clipboard = new ClipboardManager(kernel);
|
|
2812
|
+
this.contact = new ContactManager(kernel);
|
|
2813
|
+
this.homeScreen = new HomeScreenManager(kernel);
|
|
2814
|
+
this.downloadFileManager = new DownloadFileManager(kernel);
|
|
2815
|
+
this.sharing = new SharingManager(kernel);
|
|
2816
|
+
this.emojiStatus = new EmojiStatusManager(kernel);
|
|
2817
|
+
this.links = new LinkManager(kernel);
|
|
2818
|
+
this.Accelerometer = new Accelerometer(kernel);
|
|
2819
|
+
this.DeviceOrientation = new DeviceOrientation(kernel);
|
|
2820
|
+
this.Gyroscope = new Gyroscope(kernel);
|
|
2821
|
+
this.debugBar.onHeightChanged = () => this.viewport.setViewportHeight();
|
|
2822
|
+
this.theme.onBottomBarColorApplied = () => {
|
|
2823
|
+
this.debugBar.refreshColor();
|
|
2824
|
+
this.SecondaryButton.setParams({});
|
|
2825
|
+
};
|
|
2826
|
+
kernel.webView.onEvent("theme_changed", this.handleThemeChanged);
|
|
2827
|
+
kernel.webView.onEvent("viewport_changed", this.viewport.handleViewportChanged);
|
|
2828
|
+
kernel.webView.onEvent("safe_area_changed", this.viewport.handleSafeAreaChanged);
|
|
2829
|
+
kernel.webView.onEvent("content_safe_area_changed", this.viewport.handleContentSafeAreaChanged);
|
|
2830
|
+
kernel.webView.onEvent("visibility_changed", this.handleVisibilityChanged);
|
|
2831
|
+
kernel.webView.onEvent("fullscreen_changed", this.viewport.handleFullscreenChanged);
|
|
2832
|
+
kernel.webView.onEvent("fullscreen_failed", this.viewport.handleFullscreenFailed);
|
|
2833
|
+
kernel.webView.onEvent("custom_method_invoked", kernel.onCustomMethodInvoked);
|
|
2834
|
+
window.addEventListener("resize", this.viewport.onWindowResize);
|
|
2835
|
+
if (webView.isIframe) {
|
|
2836
|
+
document.addEventListener("click", this.links.handleDocumentClick);
|
|
2837
|
+
}
|
|
2838
|
+
this.theme.updateHeaderColor();
|
|
2839
|
+
this.theme.updateBackgroundColor();
|
|
2840
|
+
this.theme.updateBottomBarColor();
|
|
2841
|
+
this.viewport.setViewportHeight();
|
|
2842
|
+
if (initParams.tgWebAppShowSettings) {
|
|
2843
|
+
this.SettingsButton.show();
|
|
2844
|
+
}
|
|
2845
|
+
kernel.webView.postEvent("web_app_request_theme");
|
|
2846
|
+
kernel.webView.postEvent("web_app_request_viewport");
|
|
2847
|
+
kernel.webView.postEvent("web_app_request_safe_area");
|
|
2848
|
+
kernel.webView.postEvent("web_app_request_content_safe_area");
|
|
2849
|
+
}
|
|
2850
|
+
// -----------------------------------------------------------------------
|
|
2851
|
+
// Public read-only properties
|
|
2852
|
+
// -----------------------------------------------------------------------
|
|
2853
|
+
get initData() {
|
|
2854
|
+
return this.webAppInitData;
|
|
2855
|
+
}
|
|
2856
|
+
get initDataUnsafe() {
|
|
2857
|
+
return this.webAppInitDataUnsafe;
|
|
2858
|
+
}
|
|
2859
|
+
get version() {
|
|
2860
|
+
return this.kernel.version;
|
|
2861
|
+
}
|
|
2862
|
+
get platform() {
|
|
2863
|
+
return this.webAppPlatform;
|
|
2864
|
+
}
|
|
2865
|
+
get colorScheme() {
|
|
2866
|
+
return this.theme.colorScheme;
|
|
2867
|
+
}
|
|
2868
|
+
get themeParams() {
|
|
2869
|
+
return this.theme.getThemeParams();
|
|
2870
|
+
}
|
|
2871
|
+
get isExpanded() {
|
|
2872
|
+
return this.viewport.isExpanded;
|
|
2873
|
+
}
|
|
2874
|
+
get viewportHeight() {
|
|
2875
|
+
return this.viewport.viewportHeight;
|
|
2876
|
+
}
|
|
2877
|
+
get viewportStableHeight() {
|
|
2878
|
+
return this.viewport.viewportStableHeight;
|
|
2879
|
+
}
|
|
2880
|
+
get safeAreaInset() {
|
|
2881
|
+
return this.viewport.safeAreaInset;
|
|
2882
|
+
}
|
|
2883
|
+
get contentSafeAreaInset() {
|
|
2884
|
+
return this.viewport.contentSafeAreaInset;
|
|
2885
|
+
}
|
|
2886
|
+
get isFullscreen() {
|
|
2887
|
+
return this.viewport.isFullscreen;
|
|
2888
|
+
}
|
|
2889
|
+
get isActive() {
|
|
2890
|
+
return this.webAppIsActive;
|
|
2891
|
+
}
|
|
2892
|
+
get isClosingConfirmationEnabled() {
|
|
2893
|
+
return this.viewport.isClosingConfirmationEnabled;
|
|
2894
|
+
}
|
|
2895
|
+
set isClosingConfirmationEnabled(val) {
|
|
2896
|
+
this.viewport.setClosingConfirmation(val);
|
|
2897
|
+
}
|
|
2898
|
+
get isVerticalSwipesEnabled() {
|
|
2899
|
+
return this.viewport.isVerticalSwipesEnabled;
|
|
2900
|
+
}
|
|
2901
|
+
set isVerticalSwipesEnabled(val) {
|
|
2902
|
+
this.viewport.toggleVerticalSwipes(val);
|
|
2903
|
+
}
|
|
2904
|
+
get isOrientationLocked() {
|
|
2905
|
+
return this.viewport.isOrientationLocked;
|
|
2906
|
+
}
|
|
2907
|
+
set isOrientationLocked(val) {
|
|
2908
|
+
this.viewport.toggleOrientationLock(val);
|
|
2909
|
+
}
|
|
2910
|
+
get headerColor() {
|
|
2911
|
+
return this.theme.getHeaderColor();
|
|
2912
|
+
}
|
|
2913
|
+
set headerColor(val) {
|
|
2914
|
+
this.theme.setHeaderColor(val);
|
|
2915
|
+
}
|
|
2916
|
+
get backgroundColor() {
|
|
2917
|
+
return this.theme.getBackgroundColor();
|
|
2918
|
+
}
|
|
2919
|
+
set backgroundColor(val) {
|
|
2920
|
+
this.theme.setBackgroundColor(val);
|
|
2921
|
+
}
|
|
2922
|
+
get bottomBarColor() {
|
|
2923
|
+
return this.theme.getBottomBarColor();
|
|
2924
|
+
}
|
|
2925
|
+
set bottomBarColor(val) {
|
|
2926
|
+
this.theme.setBottomBarColor(val);
|
|
2927
|
+
}
|
|
2928
|
+
// -----------------------------------------------------------------------
|
|
2929
|
+
// Methods
|
|
2930
|
+
// -----------------------------------------------------------------------
|
|
2931
|
+
isVersionAtLeast(ver) {
|
|
2932
|
+
return this.kernel.versionAtLeast(ver);
|
|
2933
|
+
}
|
|
2934
|
+
setHeaderColor(colorKey) {
|
|
2935
|
+
this.headerColor = colorKey;
|
|
2936
|
+
}
|
|
2937
|
+
setBackgroundColor(color) {
|
|
2938
|
+
this.backgroundColor = color;
|
|
2939
|
+
}
|
|
2940
|
+
setBottomBarColor(color) {
|
|
2941
|
+
this.bottomBarColor = color;
|
|
2942
|
+
}
|
|
2943
|
+
enableClosingConfirmation() {
|
|
2944
|
+
this.isClosingConfirmationEnabled = true;
|
|
2945
|
+
}
|
|
2946
|
+
disableClosingConfirmation() {
|
|
2947
|
+
this.isClosingConfirmationEnabled = false;
|
|
2948
|
+
}
|
|
2949
|
+
enableVerticalSwipes() {
|
|
2950
|
+
this.isVerticalSwipesEnabled = true;
|
|
2951
|
+
}
|
|
2952
|
+
disableVerticalSwipes() {
|
|
2953
|
+
this.isVerticalSwipesEnabled = false;
|
|
2954
|
+
}
|
|
2955
|
+
lockOrientation() {
|
|
2956
|
+
this.isOrientationLocked = true;
|
|
2957
|
+
}
|
|
2958
|
+
unlockOrientation() {
|
|
2959
|
+
this.isOrientationLocked = false;
|
|
2960
|
+
}
|
|
2961
|
+
requestFullscreen() {
|
|
2962
|
+
this.viewport.requestFullscreen();
|
|
2963
|
+
}
|
|
2964
|
+
exitFullscreen() {
|
|
2965
|
+
this.viewport.exitFullscreen();
|
|
2966
|
+
}
|
|
2967
|
+
addToHomeScreen() {
|
|
2968
|
+
this.homeScreen.addToHomeScreen();
|
|
2969
|
+
}
|
|
2970
|
+
checkHomeScreenStatus(callback) {
|
|
2971
|
+
this.homeScreen.checkHomeScreenStatus(callback);
|
|
2972
|
+
}
|
|
2973
|
+
onEvent(eventType, callback) {
|
|
2974
|
+
this.kernel.onWebViewEvent(eventType, callback);
|
|
2975
|
+
}
|
|
2976
|
+
offEvent(eventType, callback) {
|
|
2977
|
+
this.kernel.offWebViewEvent(eventType, callback);
|
|
2978
|
+
}
|
|
2979
|
+
sendData(data) {
|
|
2980
|
+
if (!data || !data.length) {
|
|
2981
|
+
console.error("[@core-ease/telegram-kit] Data is required", data);
|
|
2982
|
+
throwWebAppError("WebAppDataInvalid" /* DataInvalid */);
|
|
2983
|
+
}
|
|
2984
|
+
if (byteLength(data) > 4096) {
|
|
2985
|
+
console.error("[@core-ease/telegram-kit] Data is too long", data);
|
|
2986
|
+
throwWebAppError("WebAppDataInvalid" /* DataInvalid */);
|
|
2987
|
+
}
|
|
2988
|
+
this.kernel.webView.postEvent("web_app_data_send", void 0, { data });
|
|
2989
|
+
}
|
|
2990
|
+
switchInlineQuery(query, chooseChatTypes) {
|
|
2991
|
+
this.sharing.switchInlineQuery(query, chooseChatTypes, this.kernel.initParams);
|
|
2992
|
+
}
|
|
2993
|
+
openLink(url, options) {
|
|
2994
|
+
this.links.openLink(url, options);
|
|
2995
|
+
}
|
|
2996
|
+
openTelegramLink(url, options) {
|
|
2997
|
+
this.links.openTelegramLink(url, options);
|
|
2998
|
+
}
|
|
2999
|
+
openInvoice(url, callback) {
|
|
3000
|
+
this.invoices.openInvoice(url, callback);
|
|
3001
|
+
}
|
|
3002
|
+
showPopup(params, callback) {
|
|
3003
|
+
this.popups.showPopup(params, callback);
|
|
3004
|
+
}
|
|
3005
|
+
showAlert(message, callback) {
|
|
3006
|
+
this.popups.showAlert(message, callback);
|
|
3007
|
+
}
|
|
3008
|
+
showConfirm(message, callback) {
|
|
3009
|
+
this.popups.showConfirm(message, callback);
|
|
3010
|
+
}
|
|
3011
|
+
showScanQrPopup(params, callback) {
|
|
3012
|
+
this.scanQr.showScanQrPopup(params, callback);
|
|
3013
|
+
}
|
|
3014
|
+
closeScanQrPopup() {
|
|
3015
|
+
this.scanQr.closeScanQrPopup();
|
|
3016
|
+
}
|
|
3017
|
+
readTextFromClipboard(callback) {
|
|
3018
|
+
this.clipboard.readTextFromClipboard(callback);
|
|
3019
|
+
}
|
|
3020
|
+
requestWriteAccess(callback) {
|
|
3021
|
+
this.contact.requestWriteAccess(callback);
|
|
3022
|
+
}
|
|
3023
|
+
requestContact(callback) {
|
|
3024
|
+
this.contact.requestContact(callback);
|
|
3025
|
+
}
|
|
3026
|
+
downloadFile(params, callback) {
|
|
3027
|
+
this.downloadFileManager.downloadFile(params, callback);
|
|
3028
|
+
}
|
|
3029
|
+
shareToStory(mediaUrl, params) {
|
|
3030
|
+
this.sharing.shareToStory(mediaUrl, params);
|
|
3031
|
+
}
|
|
3032
|
+
shareMessage(msgId, callback) {
|
|
3033
|
+
this.sharing.shareMessage(msgId, callback);
|
|
3034
|
+
}
|
|
3035
|
+
requestChat(reqId, callback) {
|
|
3036
|
+
this.sharing.requestChat(reqId, callback);
|
|
3037
|
+
}
|
|
3038
|
+
setEmojiStatus(customEmojiId, params, callback) {
|
|
3039
|
+
this.emojiStatus.setEmojiStatus(customEmojiId, params, callback);
|
|
3040
|
+
}
|
|
3041
|
+
requestEmojiStatusAccess(callback) {
|
|
3042
|
+
this.emojiStatus.requestEmojiStatusAccess(callback);
|
|
3043
|
+
}
|
|
3044
|
+
invokeCustomMethod(method, params, callback) {
|
|
3045
|
+
this.kernel.invokeCustomMethod(method, params, callback);
|
|
3046
|
+
}
|
|
3047
|
+
hideKeyboard() {
|
|
3048
|
+
this.kernel.webView.postEvent("web_app_hide_keyboard");
|
|
3049
|
+
}
|
|
3050
|
+
ready() {
|
|
3051
|
+
this.kernel.webView.postEvent("web_app_ready");
|
|
3052
|
+
}
|
|
3053
|
+
expand() {
|
|
3054
|
+
this.kernel.webView.postEvent("web_app_expand");
|
|
3055
|
+
}
|
|
3056
|
+
close(options = {}) {
|
|
3057
|
+
const reqParams = {};
|
|
3058
|
+
if (this.kernel.versionAtLeast("7.6") && options.return_back) {
|
|
3059
|
+
reqParams.return_back = true;
|
|
3060
|
+
}
|
|
3061
|
+
this.kernel.webView.postEvent("web_app_close", void 0, reqParams);
|
|
3062
|
+
}
|
|
3063
|
+
};
|
|
3064
|
+
|
|
3065
|
+
// src/sdk/index.ts
|
|
3066
|
+
var SDK_NAME = "@core-ease/telegram-kit";
|
|
3067
|
+
var bootstrapped = null;
|
|
3068
|
+
function bootstrapTelegramWebApp() {
|
|
3069
|
+
var _a;
|
|
3070
|
+
if (bootstrapped) {
|
|
3071
|
+
return bootstrapped;
|
|
3072
|
+
}
|
|
3073
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
3074
|
+
throw new Error(`[${SDK_NAME}] bootstrapTelegramWebApp() requires a browser environment (window/document).`);
|
|
3075
|
+
}
|
|
3076
|
+
const webView = new TelegramWebView();
|
|
3077
|
+
const telegram = (_a = window.Telegram) != null ? _a : window.Telegram = {};
|
|
3078
|
+
telegram.WebView = webView;
|
|
3079
|
+
telegram.Utils = Utils;
|
|
3080
|
+
const webApp = new WebApp(webView);
|
|
3081
|
+
telegram.WebApp = webApp;
|
|
3082
|
+
bootstrapped = { webView, webApp };
|
|
3083
|
+
return bootstrapped;
|
|
3084
|
+
}
|
|
3085
|
+
function isBootstrapped() {
|
|
3086
|
+
return bootstrapped !== null;
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3089
|
+
export { Accelerometer, BackButton, BiometricManager, BottomButton, ClipboardManager, CloudStorage, ContactManager, DebugBottomBar, DeviceOrientation, DeviceStorage, DownloadFileManager, EmojiStatusManager, Gyroscope, HapticFeedback, HomeScreenManager, InvoiceManager, LinkManager, LocationManager, PopupManager, SDK_NAME, ScanQrManager, SecureStorage, SettingsButton, SharingManager, TelegramWebView, ThemeManager, Utils, ViewportManager, WebApp, WebAppError, WebAppErrorName, WebAppKernel, bootstrapTelegramWebApp, isBootstrapped };
|