@tma.js/sdk 0.12.0 → 0.12.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/dist/index.js +80 -76
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +6 -6
- package/src/components/InitData/InitData.ts +14 -6
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var at = (s, t, e) => t in s ? it(s, t, { enumerable: !0, configurable: !0, writ
|
|
|
3
3
|
var i = (s, t, e) => (at(s, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
4
|
import { parse as U, retrieveFromStorage as F, saveToStorage as ct } from "@tma.js/launch-params";
|
|
5
5
|
import { EventEmitter as w } from "@tma.js/event-emitter";
|
|
6
|
-
import { supports as C, postEvent as
|
|
6
|
+
import { supports as C, postEvent as g, on as x, off as K, request as _, detectSupportParams as ht, setDebug as ut, setTargetOrigin as pt, isIframe as lt } from "@tma.js/bridge";
|
|
7
7
|
import { array as dt, string as j, json as gt } from "@tma.js/parsing";
|
|
8
8
|
import { parse as N } from "@tma.js/theme-params";
|
|
9
9
|
import { isColorDark as J, isRGB as bt } from "@tma.js/colors";
|
|
@@ -41,7 +41,7 @@ class f {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
class Ct {
|
|
44
|
-
constructor(t, e, o =
|
|
44
|
+
constructor(t, e, o = g) {
|
|
45
45
|
i(this, "ee", new w());
|
|
46
46
|
i(this, "state");
|
|
47
47
|
/**
|
|
@@ -96,7 +96,7 @@ class Ct {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
class vt {
|
|
99
|
-
constructor(t, e =
|
|
99
|
+
constructor(t, e = g) {
|
|
100
100
|
i(this, "ee", new w());
|
|
101
101
|
i(this, "state");
|
|
102
102
|
/**
|
|
@@ -139,7 +139,7 @@ function z(s, t) {
|
|
|
139
139
|
return s.reduce((e, o) => (e[o] = t, e), {});
|
|
140
140
|
}
|
|
141
141
|
class Et {
|
|
142
|
-
constructor(t, e, o =
|
|
142
|
+
constructor(t, e, o = g) {
|
|
143
143
|
/**
|
|
144
144
|
* Checks if specified method is supported by current component.
|
|
145
145
|
*/
|
|
@@ -210,7 +210,7 @@ class Et {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
class kt {
|
|
213
|
-
constructor(t, e =
|
|
213
|
+
constructor(t, e = g) {
|
|
214
214
|
/**
|
|
215
215
|
* Checks if specified method is supported by current component.
|
|
216
216
|
*/
|
|
@@ -258,19 +258,23 @@ class xt {
|
|
|
258
258
|
const {
|
|
259
259
|
chat: r = null,
|
|
260
260
|
canSendAfter: n = null,
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
chatType: a = null,
|
|
262
|
+
chatInstance: c = null,
|
|
263
|
+
user: u = null,
|
|
264
|
+
queryId: p = null,
|
|
263
265
|
receiver: h = null,
|
|
264
|
-
startParam:
|
|
266
|
+
startParam: l = null
|
|
265
267
|
} = o;
|
|
266
268
|
this.state = new f({
|
|
267
269
|
authDate: t,
|
|
268
|
-
canSendAfter: n,
|
|
270
|
+
canSendAfter: n === null ? null : new Date(t.getTime() + n * 1e3),
|
|
269
271
|
chat: r,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
+
chatType: a,
|
|
273
|
+
chatInstance: c,
|
|
274
|
+
user: u,
|
|
275
|
+
queryId: p,
|
|
272
276
|
receiver: h,
|
|
273
|
-
startParam:
|
|
277
|
+
startParam: l,
|
|
274
278
|
hash: e
|
|
275
279
|
});
|
|
276
280
|
}
|
|
@@ -336,7 +340,7 @@ class xt {
|
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
342
|
class Vt {
|
|
339
|
-
constructor(t, e, o, r, n, a, c =
|
|
343
|
+
constructor(t, e, o, r, n, a, c = g) {
|
|
340
344
|
i(this, "ee", new w());
|
|
341
345
|
i(this, "state");
|
|
342
346
|
/**
|
|
@@ -520,8 +524,8 @@ function St(s) {
|
|
|
520
524
|
if (n.type === void 0 || n.type === "default" || n.type === "destructive") {
|
|
521
525
|
const c = n.text.trim();
|
|
522
526
|
if (c.length === 0 || c.length > 64) {
|
|
523
|
-
const
|
|
524
|
-
throw new Error(`Button text with type "${
|
|
527
|
+
const u = n.type || "default";
|
|
528
|
+
throw new Error(`Button text with type "${u}" has incorrect size: ${n.text.length}`);
|
|
525
529
|
}
|
|
526
530
|
return { ...n, text: c, id: a };
|
|
527
531
|
}
|
|
@@ -529,7 +533,7 @@ function St(s) {
|
|
|
529
533
|
}), { title: e, message: t, buttons: r };
|
|
530
534
|
}
|
|
531
535
|
class Pt {
|
|
532
|
-
constructor(t, e =
|
|
536
|
+
constructor(t, e = g) {
|
|
533
537
|
i(this, "ee", new w());
|
|
534
538
|
i(this, "state");
|
|
535
539
|
/**
|
|
@@ -583,7 +587,7 @@ class Pt {
|
|
|
583
587
|
}
|
|
584
588
|
}
|
|
585
589
|
class qt {
|
|
586
|
-
constructor(t, e =
|
|
590
|
+
constructor(t, e = g) {
|
|
587
591
|
i(this, "ee", new w());
|
|
588
592
|
i(this, "state");
|
|
589
593
|
/**
|
|
@@ -761,7 +765,7 @@ function E(s) {
|
|
|
761
765
|
return s < 0 ? 0 : s;
|
|
762
766
|
}
|
|
763
767
|
class k {
|
|
764
|
-
constructor(t, e, o, r, n =
|
|
768
|
+
constructor(t, e, o, r, n = g) {
|
|
765
769
|
i(this, "ee", new w());
|
|
766
770
|
i(this, "state");
|
|
767
771
|
/**
|
|
@@ -912,7 +916,7 @@ function T(s) {
|
|
|
912
916
|
return t.href;
|
|
913
917
|
}
|
|
914
918
|
class Ot {
|
|
915
|
-
constructor(t, e, o, r, n, a =
|
|
919
|
+
constructor(t, e, o, r, n, a = g) {
|
|
916
920
|
i(this, "ee", new w());
|
|
917
921
|
i(this, "state");
|
|
918
922
|
/**
|
|
@@ -1136,9 +1140,9 @@ class $ extends Error {
|
|
|
1136
1140
|
super(`Method "${t}" is not supported in the Web Apps version ${e}.`), Object.setPrototypeOf(this, $.prototype);
|
|
1137
1141
|
}
|
|
1138
1142
|
}
|
|
1139
|
-
class
|
|
1143
|
+
class I extends Error {
|
|
1140
1144
|
constructor(t, e, o) {
|
|
1141
|
-
super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`), Object.setPrototypeOf(this,
|
|
1145
|
+
super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`), Object.setPrototypeOf(this, I.prototype);
|
|
1142
1146
|
}
|
|
1143
1147
|
}
|
|
1144
1148
|
function G(s, t) {
|
|
@@ -1170,11 +1174,11 @@ function $t(s) {
|
|
|
1170
1174
|
const t = () => Bt(s);
|
|
1171
1175
|
s.on("changed", t), t();
|
|
1172
1176
|
}
|
|
1173
|
-
function
|
|
1177
|
+
function It(s, t) {
|
|
1174
1178
|
const e = () => Tt(s, t);
|
|
1175
1179
|
t.on("changed", e), s.on("backgroundColorChanged", e), s.on("headerColorChanged", e), e();
|
|
1176
1180
|
}
|
|
1177
|
-
function
|
|
1181
|
+
function At(s) {
|
|
1178
1182
|
const t = () => {
|
|
1179
1183
|
W("--tg-viewport-height", s.height);
|
|
1180
1184
|
}, e = () => {
|
|
@@ -1182,7 +1186,7 @@ function It(s) {
|
|
|
1182
1186
|
};
|
|
1183
1187
|
s.on("heightChanged", t), s.on("stableHeightChanged", e), t(), e();
|
|
1184
1188
|
}
|
|
1185
|
-
function
|
|
1189
|
+
function Ht(s) {
|
|
1186
1190
|
return typeof s == "boolean" ? s ? { themeParams: !0, viewport: !0, webApp: !0 } : {} : s;
|
|
1187
1191
|
}
|
|
1188
1192
|
function Q(s) {
|
|
@@ -1195,7 +1199,7 @@ function S(s) {
|
|
|
1195
1199
|
const t = sessionStorage.getItem(Q(s));
|
|
1196
1200
|
return t ? JSON.parse(t) : null;
|
|
1197
1201
|
}
|
|
1198
|
-
function
|
|
1202
|
+
function Rt(s, t, e) {
|
|
1199
1203
|
const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, r = new Ct(o, t, e);
|
|
1200
1204
|
return r.on("isVisibleChanged", () => {
|
|
1201
1205
|
V("back-button", { isVisible: r.isVisible });
|
|
@@ -1213,25 +1217,25 @@ function Lt(s, t, e, o) {
|
|
|
1213
1217
|
isEnabled: n = !1,
|
|
1214
1218
|
isVisible: a = !1,
|
|
1215
1219
|
isProgressVisible: c = !1,
|
|
1216
|
-
textColor:
|
|
1220
|
+
textColor: u = e,
|
|
1217
1221
|
text: p = ""
|
|
1218
|
-
} = s ? S("main-button") || {} : {},
|
|
1222
|
+
} = s ? S("main-button") || {} : {}, h = new Vt(
|
|
1219
1223
|
r,
|
|
1220
1224
|
n,
|
|
1221
1225
|
a,
|
|
1222
1226
|
c,
|
|
1223
1227
|
p,
|
|
1224
|
-
|
|
1228
|
+
u,
|
|
1225
1229
|
o
|
|
1226
|
-
),
|
|
1227
|
-
backgroundColor:
|
|
1228
|
-
isEnabled:
|
|
1229
|
-
isVisible:
|
|
1230
|
-
isProgressVisible:
|
|
1231
|
-
text:
|
|
1232
|
-
textColor:
|
|
1230
|
+
), l = () => V("main-button", {
|
|
1231
|
+
backgroundColor: h.backgroundColor,
|
|
1232
|
+
isEnabled: h.isEnabled,
|
|
1233
|
+
isVisible: h.isVisible,
|
|
1234
|
+
isProgressVisible: h.isProgressVisible,
|
|
1235
|
+
text: h.text,
|
|
1236
|
+
textColor: h.textColor
|
|
1233
1237
|
});
|
|
1234
|
-
return
|
|
1238
|
+
return h.on("backgroundColorChanged", l), h.on("isEnabledChanged", l), h.on("isVisibleChanged", l), h.on("isProgressVisibleChanged", l), h.on("textColorChanged", l), h.on("textChanged", l), h;
|
|
1235
1239
|
}
|
|
1236
1240
|
function Nt(s, t) {
|
|
1237
1241
|
return s ? (e, o) => {
|
|
@@ -1239,9 +1243,9 @@ function Nt(s, t) {
|
|
|
1239
1243
|
throw new $(e, t);
|
|
1240
1244
|
return ft(o) && ht(e, o).forEach((r) => {
|
|
1241
1245
|
if (!C(e, r, t))
|
|
1242
|
-
throw new
|
|
1243
|
-
}),
|
|
1244
|
-
} :
|
|
1246
|
+
throw new I(e, r, t);
|
|
1247
|
+
}), g(e, o);
|
|
1248
|
+
} : g;
|
|
1245
1249
|
}
|
|
1246
1250
|
function zt() {
|
|
1247
1251
|
let s = 0;
|
|
@@ -1257,22 +1261,22 @@ async function Wt(s, t, e) {
|
|
|
1257
1261
|
stableHeight: r = window.innerHeight,
|
|
1258
1262
|
width: n = window.innerWidth,
|
|
1259
1263
|
isExpanded: a = !1
|
|
1260
|
-
} = s ? S("viewport") || {} : {},
|
|
1261
|
-
const
|
|
1262
|
-
return k.sync(
|
|
1264
|
+
} = s ? S("viewport") || {} : {}, u = t === "macos" || t === "web" ? (() => {
|
|
1265
|
+
const h = new k(o, n, r, a, e);
|
|
1266
|
+
return k.sync(h), h;
|
|
1263
1267
|
})() : await k.synced({ postEvent: e }), p = () => V("viewport", {
|
|
1264
|
-
height:
|
|
1265
|
-
isExpanded:
|
|
1266
|
-
stableHeight:
|
|
1267
|
-
width:
|
|
1268
|
+
height: u.height,
|
|
1269
|
+
isExpanded: u.isExpanded,
|
|
1270
|
+
stableHeight: u.stableHeight,
|
|
1271
|
+
width: u.width
|
|
1268
1272
|
});
|
|
1269
|
-
return
|
|
1273
|
+
return u.on("heightChanged", p), u.on("isExpandedChanged", p), u.on("stableHeightChanged", p), u.on("widthChanged", p), u;
|
|
1270
1274
|
}
|
|
1271
1275
|
function Ut(s, t, e, o, r, n) {
|
|
1272
1276
|
const {
|
|
1273
1277
|
backgroundColor: a = t,
|
|
1274
1278
|
headerColor: c = "bg_color"
|
|
1275
|
-
} = s ? S("web-app") || {} : {},
|
|
1279
|
+
} = s ? S("web-app") || {} : {}, u = new Ot(
|
|
1276
1280
|
c,
|
|
1277
1281
|
a,
|
|
1278
1282
|
e,
|
|
@@ -1280,10 +1284,10 @@ function Ut(s, t, e, o, r, n) {
|
|
|
1280
1284
|
r,
|
|
1281
1285
|
n
|
|
1282
1286
|
), p = () => V("web-app", {
|
|
1283
|
-
backgroundColor:
|
|
1284
|
-
headerColor:
|
|
1287
|
+
backgroundColor: u.backgroundColor,
|
|
1288
|
+
headerColor: u.headerColor
|
|
1285
1289
|
});
|
|
1286
|
-
return
|
|
1290
|
+
return u.on("backgroundColorChanged", p), u.on("headerColorChanged", p), u;
|
|
1287
1291
|
}
|
|
1288
1292
|
function Z() {
|
|
1289
1293
|
let s;
|
|
@@ -1315,53 +1319,53 @@ async function jt(s = {}) {
|
|
|
1315
1319
|
launchParams: c = Z()
|
|
1316
1320
|
} = s;
|
|
1317
1321
|
a && ut(a), typeof n == "string" && pt(n);
|
|
1318
|
-
const
|
|
1322
|
+
const u = F(), p = c instanceof URLSearchParams || typeof c == "string" ? U(c) : c;
|
|
1319
1323
|
ct(p);
|
|
1320
|
-
const
|
|
1321
|
-
initData:
|
|
1324
|
+
const h = Ft() || Kt(u, p), {
|
|
1325
|
+
initData: l,
|
|
1322
1326
|
initDataRaw: X,
|
|
1323
1327
|
version: m,
|
|
1324
|
-
platform:
|
|
1325
|
-
themeParams:
|
|
1328
|
+
platform: A,
|
|
1329
|
+
themeParams: H
|
|
1326
1330
|
} = p, {
|
|
1327
1331
|
backgroundColor: Y = "#ffffff",
|
|
1328
1332
|
buttonColor: tt = "#000000",
|
|
1329
1333
|
buttonTextColor: et = "#ffffff"
|
|
1330
|
-
} =
|
|
1331
|
-
|
|
1334
|
+
} = H, R = zt(), d = Nt(t, m), q = Mt(H), D = Ut(
|
|
1335
|
+
h,
|
|
1332
1336
|
Y,
|
|
1333
1337
|
m,
|
|
1334
|
-
I,
|
|
1335
1338
|
A,
|
|
1336
|
-
|
|
1339
|
+
R,
|
|
1340
|
+
d
|
|
1337
1341
|
), {
|
|
1338
1342
|
themeParams: st,
|
|
1339
1343
|
viewport: ot,
|
|
1340
1344
|
webApp: rt
|
|
1341
|
-
} =
|
|
1342
|
-
rt &&
|
|
1343
|
-
const L = await Wt(
|
|
1344
|
-
if (ot &&
|
|
1345
|
+
} = Ht(e);
|
|
1346
|
+
rt && It(D, q), st && $t(q);
|
|
1347
|
+
const L = await Wt(h, A, d);
|
|
1348
|
+
if (ot && At(L), r && lt()) {
|
|
1345
1349
|
const y = document.createElement("style");
|
|
1346
1350
|
y.id = "telegram-custom-styles", document.head.appendChild(y), x("set_custom_style", (B) => {
|
|
1347
1351
|
y.innerHTML = B;
|
|
1348
|
-
}),
|
|
1352
|
+
}), d("iframe_ready");
|
|
1349
1353
|
}
|
|
1350
1354
|
const O = {
|
|
1351
|
-
backButton:
|
|
1352
|
-
closingBehavior: Dt(
|
|
1353
|
-
cloudStorage: new Et(m,
|
|
1354
|
-
haptic: new kt(m,
|
|
1355
|
-
mainButton: Lt(
|
|
1356
|
-
popup: new Pt(m,
|
|
1357
|
-
postEvent:
|
|
1358
|
-
qrScanner: new qt(m,
|
|
1355
|
+
backButton: Rt(h, m, d),
|
|
1356
|
+
closingBehavior: Dt(h, d),
|
|
1357
|
+
cloudStorage: new Et(m, R, d),
|
|
1358
|
+
haptic: new kt(m, d),
|
|
1359
|
+
mainButton: Lt(h, tt, et, d),
|
|
1360
|
+
popup: new Pt(m, d),
|
|
1361
|
+
postEvent: d,
|
|
1362
|
+
qrScanner: new qt(m, d),
|
|
1359
1363
|
themeParams: q,
|
|
1360
1364
|
viewport: L,
|
|
1361
1365
|
webApp: D
|
|
1362
1366
|
};
|
|
1363
|
-
if (
|
|
1364
|
-
const { authDate: y, hash: B, ...nt } =
|
|
1367
|
+
if (l !== void 0) {
|
|
1368
|
+
const { authDate: y, hash: B, ...nt } = l;
|
|
1365
1369
|
O.initData = new xt(y, B, nt), O.initDataRaw = X;
|
|
1366
1370
|
}
|
|
1367
1371
|
return O;
|
|
@@ -1384,7 +1388,7 @@ export {
|
|
|
1384
1388
|
xt as InitData,
|
|
1385
1389
|
Vt as MainButton,
|
|
1386
1390
|
$ as MethodNotSupportedError,
|
|
1387
|
-
|
|
1391
|
+
I as ParameterUnsupportedError,
|
|
1388
1392
|
Pt as Popup,
|
|
1389
1393
|
qt as QRScanner,
|
|
1390
1394
|
P as ThemeParams,
|