@tma.js/sdk 0.12.7 → 0.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/dts/components/BackButton/BackButton.d.ts +1 -1
- package/dist/dts/components/ClosingBehaviour/ClosingBehaviour.d.ts +3 -3
- package/dist/dts/components/InitData/InitData.d.ts +12 -13
- package/dist/dts/components/MainButton/MainButton.d.ts +3 -3
- package/dist/dts/components/Viewport/Viewport.d.ts +14 -14
- package/dist/dts/components/WebApp/WebApp.d.ts +12 -12
- package/dist/dts/env.d.ts +1 -1
- package/dist/dts/init/creators/createViewport.d.ts +1 -1
- package/dist/dts/init/creators/createWebApp.d.ts +1 -1
- package/dist/dts/init/types.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +142 -143
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -10
- package/src/components/BackButton/BackButton.ts +1 -1
- package/src/components/ClosingBehaviour/ClosingBehaviour.ts +3 -3
- package/src/components/InitData/InitData.ts +12 -13
- package/src/components/MainButton/MainButton.ts +3 -3
- package/src/components/Viewport/Viewport.ts +14 -14
- package/src/components/WebApp/WebApp.ts +12 -12
- package/src/env.ts +1 -1
- package/src/errors/MethodNotSupportedError.ts +1 -1
- package/src/errors/ParameterNotSupportedError.ts +1 -1
- package/src/init/creators/createViewport.ts +1 -1
- package/src/init/creators/createWebApp.ts +1 -1
- package/src/init/css.ts +1 -1
- package/src/init/init.ts +1 -1
- package/src/init/types.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var it = Object.defineProperty;
|
|
2
2
|
var at = (s, t, e) => t in s ? it(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
3
|
var i = (s, t, e) => (at(s, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
-
import { parse as
|
|
4
|
+
import { parse as W, retrieveFromStorage as F, saveToStorage as ct } from "@tma.js/launch-params";
|
|
5
5
|
import { EventEmitter as w } from "@tma.js/event-emitter";
|
|
6
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";
|
|
@@ -13,8 +13,8 @@ function v(s, t) {
|
|
|
13
13
|
}
|
|
14
14
|
function mt(s, t) {
|
|
15
15
|
return (e) => {
|
|
16
|
-
const [o,
|
|
17
|
-
return C(o,
|
|
16
|
+
const [o, n] = t[e];
|
|
17
|
+
return C(o, n, s);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
class f {
|
|
@@ -32,8 +32,8 @@ class f {
|
|
|
32
32
|
if (typeof t == "string")
|
|
33
33
|
o = this.internalSet(t, e);
|
|
34
34
|
else
|
|
35
|
-
for (const
|
|
36
|
-
this.internalSet(
|
|
35
|
+
for (const n in t)
|
|
36
|
+
this.internalSet(n, t[n]) && (o = !0);
|
|
37
37
|
o && this.emit("changed");
|
|
38
38
|
}
|
|
39
39
|
get(t) {
|
|
@@ -110,28 +110,28 @@ class vt {
|
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Returns true, if the confirmation dialog enabled while the user is trying
|
|
113
|
-
* to close the
|
|
113
|
+
* to close the Mini App.
|
|
114
114
|
*/
|
|
115
115
|
get isConfirmationNeeded() {
|
|
116
116
|
return this.state.get("isConfirmationNeeded");
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Disables the confirmation dialog while the user is trying to close the
|
|
120
|
-
*
|
|
120
|
+
* Mini App.
|
|
121
121
|
*/
|
|
122
122
|
disableConfirmation() {
|
|
123
123
|
this.isConfirmationNeeded = !1;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Enables the confirmation dialog while the user is trying to close the
|
|
127
|
-
*
|
|
127
|
+
* Mini App.
|
|
128
128
|
*/
|
|
129
129
|
enableConfirmation() {
|
|
130
130
|
this.isConfirmationNeeded = !0;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
const yt = dt().of(j());
|
|
134
|
-
function
|
|
134
|
+
function M(s, t) {
|
|
135
135
|
return s.reduce((e, o) => (e[o] = t, e), {});
|
|
136
136
|
}
|
|
137
137
|
class Et {
|
|
@@ -154,15 +154,15 @@ class Et {
|
|
|
154
154
|
* @param options - execution options.
|
|
155
155
|
*/
|
|
156
156
|
async invokeCustomMethod(t, e, o = {}) {
|
|
157
|
-
const { result:
|
|
157
|
+
const { result: n, error: r } = await _(
|
|
158
158
|
"web_app_invoke_custom_method",
|
|
159
159
|
{ method: t, params: e, req_id: this.createRequestId() },
|
|
160
160
|
"custom_method_invoked",
|
|
161
161
|
{ ...o, postEvent: this.postEvent }
|
|
162
162
|
);
|
|
163
|
-
if (
|
|
164
|
-
throw new Error(typeof
|
|
165
|
-
return
|
|
163
|
+
if (r)
|
|
164
|
+
throw new Error(typeof r == "string" ? r : `Unknown error: ${JSON.stringify(r)}`);
|
|
165
|
+
return n;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Deletes specified keys from the CloudStorage.
|
|
@@ -188,12 +188,12 @@ class Et {
|
|
|
188
188
|
*/
|
|
189
189
|
async getValues(t, e) {
|
|
190
190
|
if (t.length === 0)
|
|
191
|
-
return
|
|
191
|
+
return M(t, "");
|
|
192
192
|
const o = gt(
|
|
193
|
-
|
|
193
|
+
M(t, j())
|
|
194
194
|
// fixme
|
|
195
|
-
),
|
|
196
|
-
return o.parse(
|
|
195
|
+
), n = await this.invokeCustomMethod("getStorageValues", { keys: t }, e);
|
|
196
|
+
return o.parse(n);
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
199
|
* Saves specified value by key.
|
|
@@ -252,8 +252,8 @@ class xt {
|
|
|
252
252
|
constructor(t, e, o = {}) {
|
|
253
253
|
i(this, "state");
|
|
254
254
|
const {
|
|
255
|
-
chat:
|
|
256
|
-
canSendAfter:
|
|
255
|
+
chat: n = null,
|
|
256
|
+
canSendAfter: r = null,
|
|
257
257
|
chatType: a = null,
|
|
258
258
|
chatInstance: c = null,
|
|
259
259
|
user: u = null,
|
|
@@ -263,8 +263,8 @@ class xt {
|
|
|
263
263
|
} = o;
|
|
264
264
|
this.state = new f({
|
|
265
265
|
authDate: t,
|
|
266
|
-
canSendAfter:
|
|
267
|
-
chat:
|
|
266
|
+
canSendAfter: r === null ? null : new Date(t.getTime() + r * 1e3),
|
|
267
|
+
chat: n,
|
|
268
268
|
chatType: a,
|
|
269
269
|
chatInstance: c,
|
|
270
270
|
user: u,
|
|
@@ -281,17 +281,16 @@ class xt {
|
|
|
281
281
|
return this.state.get("authDate");
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
|
-
* Date after which a message can be sent via the
|
|
285
|
-
* method.
|
|
286
|
-
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
284
|
+
* Date after which a message can be sent via the
|
|
285
|
+
* [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
|
|
287
286
|
*/
|
|
288
287
|
get canSendAfter() {
|
|
289
288
|
return this.state.get("canSendAfter");
|
|
290
289
|
}
|
|
291
290
|
/**
|
|
292
|
-
* An object containing data about the chat where the bot was
|
|
293
|
-
*
|
|
294
|
-
*
|
|
291
|
+
* An object containing data about the chat where the bot was launched via the attachment
|
|
292
|
+
* menu. Returned for supergroups, channels and group chats – only for Mini Apps launched via
|
|
293
|
+
* the attachment menu.
|
|
295
294
|
*/
|
|
296
295
|
get chat() {
|
|
297
296
|
return this.state.get("chat");
|
|
@@ -303,8 +302,8 @@ class xt {
|
|
|
303
302
|
return this.state.get("chatType");
|
|
304
303
|
}
|
|
305
304
|
/**
|
|
306
|
-
* A global identifier indicating the chat from which Mini App was
|
|
307
|
-
*
|
|
305
|
+
* A global identifier indicating the chat from which Mini App was opened. Returned only for
|
|
306
|
+
* applications opened by direct link.
|
|
308
307
|
*/
|
|
309
308
|
get chatInstance() {
|
|
310
309
|
return this.state.get("chatInstance");
|
|
@@ -318,7 +317,7 @@ class xt {
|
|
|
318
317
|
return this.state.get("hash");
|
|
319
318
|
}
|
|
320
319
|
/**
|
|
321
|
-
* A unique identifier for the
|
|
320
|
+
* A unique identifier for the Mini App session, required for sending
|
|
322
321
|
* messages via the `answerWebAppQuery` method.
|
|
323
322
|
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
324
323
|
*/
|
|
@@ -328,7 +327,7 @@ class xt {
|
|
|
328
327
|
/**
|
|
329
328
|
* An object containing data about the chat partner of the current
|
|
330
329
|
* user in the chat where the bot was launched via the attachment menu.
|
|
331
|
-
* Returned only for private chats and only for
|
|
330
|
+
* Returned only for private chats and only for Mini Apps launched
|
|
332
331
|
* via the attachment menu.
|
|
333
332
|
*/
|
|
334
333
|
get receiver() {
|
|
@@ -336,7 +335,7 @@ class xt {
|
|
|
336
335
|
}
|
|
337
336
|
/**
|
|
338
337
|
* The value of the `startattach` parameter, passed via link. Only
|
|
339
|
-
* returned for
|
|
338
|
+
* returned for Mini Apps when launched from the attachment menu via link.
|
|
340
339
|
*/
|
|
341
340
|
get startParam() {
|
|
342
341
|
return this.state.get("startParam");
|
|
@@ -349,7 +348,7 @@ class xt {
|
|
|
349
348
|
}
|
|
350
349
|
}
|
|
351
350
|
class Vt {
|
|
352
|
-
constructor(t, e, o,
|
|
351
|
+
constructor(t, e, o, n, r, a, c = g) {
|
|
353
352
|
i(this, "ee", new w());
|
|
354
353
|
i(this, "state");
|
|
355
354
|
/**
|
|
@@ -375,8 +374,8 @@ class Vt {
|
|
|
375
374
|
backgroundColor: t,
|
|
376
375
|
isEnabled: e,
|
|
377
376
|
isVisible: o,
|
|
378
|
-
isProgressVisible:
|
|
379
|
-
text:
|
|
377
|
+
isProgressVisible: n,
|
|
378
|
+
text: r,
|
|
380
379
|
textColor: a
|
|
381
380
|
}, this.ee);
|
|
382
381
|
}
|
|
@@ -463,8 +462,8 @@ class Vt {
|
|
|
463
462
|
return this.isProgressVisible = !1, this;
|
|
464
463
|
}
|
|
465
464
|
/**
|
|
466
|
-
* Shows the button. Note that opening the
|
|
467
|
-
* menu hides the main button until the user interacts with the
|
|
465
|
+
* Shows the button. Note that opening the Mini App from the attachment
|
|
466
|
+
* menu hides the main button until the user interacts with the Mini App
|
|
468
467
|
* interface.
|
|
469
468
|
*
|
|
470
469
|
* Returns current button instance for chaining.
|
|
@@ -515,27 +514,27 @@ class Vt {
|
|
|
515
514
|
}
|
|
516
515
|
function St(s) {
|
|
517
516
|
const t = s.message.trim(), e = (s.title || "").trim(), o = s.buttons || [];
|
|
518
|
-
let
|
|
517
|
+
let n;
|
|
519
518
|
if (e.length > 64)
|
|
520
519
|
throw new Error(`Title has incorrect size: ${e.length}`);
|
|
521
520
|
if (t.length === 0 || t.length > 256)
|
|
522
521
|
throw new Error(`Message has incorrect size: ${t.length}`);
|
|
523
522
|
if (o.length > 3)
|
|
524
523
|
throw new Error(`Buttons have incorrect size: ${o.length}`);
|
|
525
|
-
return o.length === 0 ?
|
|
526
|
-
const { id: a = "" } =
|
|
524
|
+
return o.length === 0 ? n = [{ type: "close", id: "" }] : n = o.map((r) => {
|
|
525
|
+
const { id: a = "" } = r;
|
|
527
526
|
if (a.length > 64)
|
|
528
527
|
throw new Error(`Button ID has incorrect size: ${a}`);
|
|
529
|
-
if (
|
|
530
|
-
const c =
|
|
528
|
+
if (r.type === void 0 || r.type === "default" || r.type === "destructive") {
|
|
529
|
+
const c = r.text.trim();
|
|
531
530
|
if (c.length === 0 || c.length > 64) {
|
|
532
|
-
const u =
|
|
533
|
-
throw new Error(`Button text with type "${u}" has incorrect size: ${
|
|
531
|
+
const u = r.type || "default";
|
|
532
|
+
throw new Error(`Button text with type "${u}" has incorrect size: ${r.text.length}`);
|
|
534
533
|
}
|
|
535
|
-
return { ...
|
|
534
|
+
return { ...r, text: c, id: a };
|
|
536
535
|
}
|
|
537
|
-
return { ...
|
|
538
|
-
}), { title: e, message: t, buttons:
|
|
536
|
+
return { ...r, id: a };
|
|
537
|
+
}), { title: e, message: t, buttons: n };
|
|
539
538
|
}
|
|
540
539
|
class Pt {
|
|
541
540
|
constructor(t, e = g) {
|
|
@@ -650,13 +649,13 @@ class qt {
|
|
|
650
649
|
}
|
|
651
650
|
}
|
|
652
651
|
}
|
|
653
|
-
function
|
|
652
|
+
function z(s) {
|
|
654
653
|
const {
|
|
655
654
|
backgroundColor: t = null,
|
|
656
655
|
buttonTextColor: e = null,
|
|
657
656
|
buttonColor: o = null,
|
|
658
|
-
hintColor:
|
|
659
|
-
linkColor:
|
|
657
|
+
hintColor: n = null,
|
|
658
|
+
linkColor: r = null,
|
|
660
659
|
textColor: a = null,
|
|
661
660
|
secondaryBackgroundColor: c = null
|
|
662
661
|
} = s;
|
|
@@ -664,8 +663,8 @@ function M(s) {
|
|
|
664
663
|
backgroundColor: t,
|
|
665
664
|
buttonTextColor: e,
|
|
666
665
|
buttonColor: o,
|
|
667
|
-
hintColor:
|
|
668
|
-
linkColor:
|
|
666
|
+
hintColor: n,
|
|
667
|
+
linkColor: r,
|
|
669
668
|
textColor: a,
|
|
670
669
|
secondaryBackgroundColor: c
|
|
671
670
|
};
|
|
@@ -682,7 +681,7 @@ class P {
|
|
|
682
681
|
* Removes event listener.
|
|
683
682
|
*/
|
|
684
683
|
i(this, "off", this.ee.off.bind(this.ee));
|
|
685
|
-
this.state = new f(
|
|
684
|
+
this.state = new f(z(t), this.ee);
|
|
686
685
|
}
|
|
687
686
|
/**
|
|
688
687
|
* Requests fresh information about current theme.
|
|
@@ -691,11 +690,11 @@ class P {
|
|
|
691
690
|
* @param options - method options.
|
|
692
691
|
*/
|
|
693
692
|
static async request(t = {}) {
|
|
694
|
-
const { timeout: e = 1e3, ...o } = t,
|
|
693
|
+
const { timeout: e = 1e3, ...o } = t, n = await _("web_app_request_theme", "theme_changed", {
|
|
695
694
|
...o,
|
|
696
695
|
timeout: e
|
|
697
696
|
});
|
|
698
|
-
return N(
|
|
697
|
+
return N(n.theme_params);
|
|
699
698
|
}
|
|
700
699
|
/**
|
|
701
700
|
* Synchronizes specified instance of ThemeParams with the actual value in the native
|
|
@@ -704,7 +703,7 @@ class P {
|
|
|
704
703
|
*/
|
|
705
704
|
static sync(t) {
|
|
706
705
|
x("theme_changed", (e) => {
|
|
707
|
-
t.state.set(
|
|
706
|
+
t.state.set(z(N(e.theme_params)));
|
|
708
707
|
});
|
|
709
708
|
}
|
|
710
709
|
/**
|
|
@@ -770,7 +769,7 @@ function E(s) {
|
|
|
770
769
|
return s < 0 ? 0 : s;
|
|
771
770
|
}
|
|
772
771
|
class k {
|
|
773
|
-
constructor(t, e, o,
|
|
772
|
+
constructor(t, e, o, n, r = g) {
|
|
774
773
|
i(this, "ee", new w());
|
|
775
774
|
i(this, "state");
|
|
776
775
|
/**
|
|
@@ -781,9 +780,9 @@ class k {
|
|
|
781
780
|
* Removes event listener.
|
|
782
781
|
*/
|
|
783
782
|
i(this, "off", this.ee.off.bind(this.ee));
|
|
784
|
-
this.postEvent =
|
|
783
|
+
this.postEvent = r, this.state = new f({
|
|
785
784
|
height: E(t),
|
|
786
|
-
isExpanded:
|
|
785
|
+
isExpanded: n,
|
|
787
786
|
stableHeight: E(o),
|
|
788
787
|
width: E(e)
|
|
789
788
|
}, this.ee);
|
|
@@ -797,14 +796,14 @@ class k {
|
|
|
797
796
|
*/
|
|
798
797
|
static async request(t = {}) {
|
|
799
798
|
const { timeout: e = 1e3, ...o } = t, {
|
|
800
|
-
is_expanded:
|
|
801
|
-
is_state_stable:
|
|
799
|
+
is_expanded: n,
|
|
800
|
+
is_state_stable: r,
|
|
802
801
|
...a
|
|
803
802
|
} = await _("web_app_request_viewport", "viewport_changed", {
|
|
804
803
|
...o,
|
|
805
804
|
timeout: e
|
|
806
805
|
});
|
|
807
|
-
return { ...a, isExpanded:
|
|
806
|
+
return { ...a, isExpanded: n, isStateStable: r };
|
|
808
807
|
}
|
|
809
808
|
/**
|
|
810
809
|
* Synchronizes specified instance of Viewport with the actual value in the native
|
|
@@ -815,34 +814,34 @@ class k {
|
|
|
815
814
|
x("viewport_changed", (e) => {
|
|
816
815
|
const {
|
|
817
816
|
height: o,
|
|
818
|
-
width:
|
|
819
|
-
is_expanded:
|
|
817
|
+
width: n,
|
|
818
|
+
is_expanded: r,
|
|
820
819
|
is_state_stable: a
|
|
821
820
|
} = e, c = E(o);
|
|
822
821
|
t.state.set({
|
|
823
822
|
height: c,
|
|
824
|
-
isExpanded:
|
|
825
|
-
width: E(
|
|
823
|
+
isExpanded: r,
|
|
824
|
+
width: E(n),
|
|
826
825
|
stableHeight: a ? c : void 0
|
|
827
826
|
});
|
|
828
827
|
});
|
|
829
828
|
}
|
|
830
829
|
/**
|
|
831
830
|
* Returns initialized instance of Viewport which is synchronized with
|
|
832
|
-
* its actual state in
|
|
831
|
+
* its actual state in Mini Apps.
|
|
833
832
|
* @param options - method options.
|
|
834
833
|
*/
|
|
835
834
|
static async synced(t = {}) {
|
|
836
|
-
const { height: e, isExpanded: o, width:
|
|
837
|
-
return this.sync(
|
|
835
|
+
const { height: e, isExpanded: o, width: n } = await this.request(t), r = new k(e, n, e, o, t.postEvent);
|
|
836
|
+
return this.sync(r), r;
|
|
838
837
|
}
|
|
839
838
|
/**
|
|
840
|
-
* The current height of the visible area of the
|
|
839
|
+
* The current height of the visible area of the Mini App.
|
|
841
840
|
*
|
|
842
|
-
* The application can display just the top part of the
|
|
841
|
+
* The application can display just the top part of the Mini App, with its
|
|
843
842
|
* lower part remaining outside the screen area. From this position, the
|
|
844
|
-
* user can "pull" the
|
|
845
|
-
* the same by calling `expand` method. As the position of the
|
|
843
|
+
* user can "pull" the Mini App to its maximum height, while the bot can do
|
|
844
|
+
* the same by calling `expand` method. As the position of the Mini App
|
|
846
845
|
* changes, the current height value of the visible area will be updated
|
|
847
846
|
* in real time.
|
|
848
847
|
*
|
|
@@ -860,18 +859,18 @@ class k {
|
|
|
860
859
|
return this.state.get("height");
|
|
861
860
|
}
|
|
862
861
|
/**
|
|
863
|
-
* The height of the visible area of the
|
|
862
|
+
* The height of the visible area of the Mini App in its last stable state.
|
|
864
863
|
*
|
|
865
|
-
* The application can display just the top part of the
|
|
864
|
+
* The application can display just the top part of the Mini App, with its
|
|
866
865
|
* lower part remaining outside the screen area. From this position,
|
|
867
|
-
* the user can "pull" the
|
|
866
|
+
* the user can "pull" the Mini App to its maximum height, while the bot can
|
|
868
867
|
* do the same by calling `expand` method.
|
|
869
868
|
*
|
|
870
869
|
* Unlike the value of `height`, the value of `stableHeight`
|
|
871
|
-
* does not change as the position of the
|
|
870
|
+
* does not change as the position of the Mini App changes with user
|
|
872
871
|
* gestures or during animations. The value of `stableHeight`
|
|
873
872
|
* will be updated after all gestures and animations are completed and
|
|
874
|
-
* the
|
|
873
|
+
* the Mini App reaches its final size.
|
|
875
874
|
*
|
|
876
875
|
* @see init
|
|
877
876
|
* @see expand
|
|
@@ -881,8 +880,8 @@ class k {
|
|
|
881
880
|
return this.state.get("stableHeight");
|
|
882
881
|
}
|
|
883
882
|
/**
|
|
884
|
-
* Returns true if the
|
|
885
|
-
* Otherwise, if the
|
|
883
|
+
* Returns true if the Mini App is expanded to the maximum available height.
|
|
884
|
+
* Otherwise, if the Mini App occupies part of the screen and can be expanded
|
|
886
885
|
* to the full height using `expand` method.
|
|
887
886
|
* @see expand
|
|
888
887
|
*/
|
|
@@ -896,8 +895,8 @@ class k {
|
|
|
896
895
|
return this.state.get("width");
|
|
897
896
|
}
|
|
898
897
|
/**
|
|
899
|
-
* A method that expands the
|
|
900
|
-
* find out if the
|
|
898
|
+
* A method that expands the Mini App to the maximum available height. To
|
|
899
|
+
* find out if the Mini App is expanded to the maximum height, refer to the
|
|
901
900
|
* value of the `isExpanded`.
|
|
902
901
|
* @see isExpanded
|
|
903
902
|
*/
|
|
@@ -921,7 +920,7 @@ function T(s) {
|
|
|
921
920
|
return t.href;
|
|
922
921
|
}
|
|
923
922
|
class Ot {
|
|
924
|
-
constructor(t, e, o,
|
|
923
|
+
constructor(t, e, o, n, r, a = g) {
|
|
925
924
|
i(this, "ee", new w());
|
|
926
925
|
i(this, "state");
|
|
927
926
|
/**
|
|
@@ -940,7 +939,7 @@ class Ot {
|
|
|
940
939
|
* Checks if specified method parameter is supported by current component.
|
|
941
940
|
*/
|
|
942
941
|
i(this, "supportsParam");
|
|
943
|
-
this.currentVersion = o, this.currentPlatform =
|
|
942
|
+
this.currentVersion = o, this.currentPlatform = n, this.createRequestId = r, this.postEvent = a, this.state = new f({
|
|
944
943
|
backgroundColor: e,
|
|
945
944
|
headerColor: t
|
|
946
945
|
}, this.ee), this.supports = v(o, {
|
|
@@ -969,7 +968,7 @@ class Ot {
|
|
|
969
968
|
return J(this.backgroundColor) ? "dark" : "light";
|
|
970
969
|
}
|
|
971
970
|
/**
|
|
972
|
-
* Closes the
|
|
971
|
+
* Closes the Mini App.
|
|
973
972
|
*/
|
|
974
973
|
close() {
|
|
975
974
|
this.postEvent("web_app_close");
|
|
@@ -982,17 +981,17 @@ class Ot {
|
|
|
982
981
|
}
|
|
983
982
|
/**
|
|
984
983
|
* Returns true if passed version is more than or equal to current
|
|
985
|
-
*
|
|
984
|
+
* Mini App version.
|
|
986
985
|
* @param version - compared version.
|
|
987
986
|
*/
|
|
988
987
|
isVersionAtLeast(t) {
|
|
989
988
|
return _t(t, this.version) >= 0;
|
|
990
989
|
}
|
|
991
990
|
/**
|
|
992
|
-
* Opens a link in an external browser. The
|
|
991
|
+
* Opens a link in an external browser. The Mini App will not be closed.
|
|
993
992
|
*
|
|
994
993
|
* Note that this method can be called only in response to the user
|
|
995
|
-
* interaction with the
|
|
994
|
+
* interaction with the Mini App interface (e.g. click inside the Mini App
|
|
996
995
|
* or on the main button).
|
|
997
996
|
* @param url - URL to be opened.
|
|
998
997
|
* @param tryInstantView
|
|
@@ -1009,20 +1008,20 @@ class Ot {
|
|
|
1009
1008
|
});
|
|
1010
1009
|
}
|
|
1011
1010
|
/**
|
|
1012
|
-
* Opens a Telegram link inside Telegram app. The
|
|
1011
|
+
* Opens a Telegram link inside Telegram app. The Mini App will be closed.
|
|
1013
1012
|
* It expects passing link in full format, with hostname "t.me".
|
|
1014
1013
|
* @param url - URL to be opened.
|
|
1015
1014
|
* @throws {Error} URL has not allowed hostname.
|
|
1016
1015
|
*/
|
|
1017
1016
|
openTelegramLink(t) {
|
|
1018
|
-
const { hostname: e, pathname: o, search:
|
|
1017
|
+
const { hostname: e, pathname: o, search: n } = new URL(T(t));
|
|
1019
1018
|
if (e !== "t.me")
|
|
1020
1019
|
throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);
|
|
1021
1020
|
if (!C("web_app_open_tg_link", this.version)) {
|
|
1022
1021
|
window.location.href = t;
|
|
1023
1022
|
return;
|
|
1024
1023
|
}
|
|
1025
|
-
return this.postEvent("web_app_open_tg_link", { path_full: o +
|
|
1024
|
+
return this.postEvent("web_app_open_tg_link", { path_full: o + n });
|
|
1026
1025
|
}
|
|
1027
1026
|
/**
|
|
1028
1027
|
* Opens an invoice using its url. It expects passing link in full format,
|
|
@@ -1033,27 +1032,27 @@ class Ot {
|
|
|
1033
1032
|
const { hostname: e, pathname: o } = new URL(T(t));
|
|
1034
1033
|
if (e !== "t.me")
|
|
1035
1034
|
throw new Error(`Incorrect hostname: ${e}`);
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1035
|
+
const n = o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
1036
|
+
if (n === null)
|
|
1038
1037
|
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');
|
|
1039
|
-
const [, ,
|
|
1040
|
-
return (await _("web_app_open_invoice", { slug:
|
|
1038
|
+
const [, , r] = n;
|
|
1039
|
+
return (await _("web_app_open_invoice", { slug: r }, "invoice_closed", {
|
|
1041
1040
|
postEvent: this.postEvent,
|
|
1042
|
-
capture: ({ slug: c }) =>
|
|
1041
|
+
capture: ({ slug: c }) => r === c
|
|
1043
1042
|
})).status;
|
|
1044
1043
|
}
|
|
1045
1044
|
/**
|
|
1046
|
-
* Returns current
|
|
1045
|
+
* Returns current Mini App platform.
|
|
1047
1046
|
*/
|
|
1048
1047
|
get platform() {
|
|
1049
1048
|
return this.currentPlatform;
|
|
1050
1049
|
}
|
|
1051
1050
|
/**
|
|
1052
|
-
* Informs the Telegram app that the
|
|
1051
|
+
* Informs the Telegram app that the Mini App is ready to be displayed.
|
|
1053
1052
|
*
|
|
1054
1053
|
* It is recommended to call this method as early as possible, as soon as
|
|
1055
1054
|
* all essential interface elements loaded. Once this method called,
|
|
1056
|
-
* the loading placeholder is hidden and the
|
|
1055
|
+
* the loading placeholder is hidden and the Mini App shown.
|
|
1057
1056
|
*
|
|
1058
1057
|
* If the method not called, the placeholder will be hidden only when
|
|
1059
1058
|
* the page fully loaded.
|
|
@@ -1097,10 +1096,10 @@ class Ot {
|
|
|
1097
1096
|
/**
|
|
1098
1097
|
* A method used to send data to the bot. When this method called, a
|
|
1099
1098
|
* service message sent to the bot containing the data of the
|
|
1100
|
-
* length up to 4096 bytes, and the
|
|
1099
|
+
* length up to 4096 bytes, and the Mini App closed. See the field
|
|
1101
1100
|
* `web_app_data` in the class Message.
|
|
1102
1101
|
*
|
|
1103
|
-
* This method is only available for
|
|
1102
|
+
* This method is only available for Mini Apps launched via a Keyboard button.
|
|
1104
1103
|
* @param data - data to send to bot.
|
|
1105
1104
|
* @throws {Error} data has incorrect size.
|
|
1106
1105
|
*/
|
|
@@ -1133,7 +1132,7 @@ class Ot {
|
|
|
1133
1132
|
this.postEvent("web_app_set_background_color", { color: t }), this.state.set("backgroundColor", t);
|
|
1134
1133
|
}
|
|
1135
1134
|
/**
|
|
1136
|
-
* Current
|
|
1135
|
+
* Current Mini App version. This property is used by other components to check if
|
|
1137
1136
|
* some functionality is available on current device.
|
|
1138
1137
|
*/
|
|
1139
1138
|
get version() {
|
|
@@ -1142,12 +1141,12 @@ class Ot {
|
|
|
1142
1141
|
}
|
|
1143
1142
|
class I extends Error {
|
|
1144
1143
|
constructor(t, e) {
|
|
1145
|
-
super(`Method "${t}" is not supported in the
|
|
1144
|
+
super(`Method "${t}" is not supported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, I.prototype);
|
|
1146
1145
|
}
|
|
1147
1146
|
}
|
|
1148
1147
|
class $ extends Error {
|
|
1149
1148
|
constructor(t, e, o) {
|
|
1150
|
-
super(`Parameter "${e}" in method "${t}" is not supported in the
|
|
1149
|
+
super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`), Object.setPrototypeOf(this, $.prototype);
|
|
1151
1150
|
}
|
|
1152
1151
|
}
|
|
1153
1152
|
function G(s, t) {
|
|
@@ -1156,7 +1155,7 @@ function G(s, t) {
|
|
|
1156
1155
|
function b(s, t) {
|
|
1157
1156
|
t !== null && G(s, t);
|
|
1158
1157
|
}
|
|
1159
|
-
function
|
|
1158
|
+
function U(s, t) {
|
|
1160
1159
|
G(s, `${t}px`);
|
|
1161
1160
|
}
|
|
1162
1161
|
function Bt(s) {
|
|
@@ -1164,16 +1163,16 @@ function Bt(s) {
|
|
|
1164
1163
|
backgroundColor: t,
|
|
1165
1164
|
buttonTextColor: e,
|
|
1166
1165
|
secondaryBackgroundColor: o,
|
|
1167
|
-
hintColor:
|
|
1168
|
-
buttonColor:
|
|
1166
|
+
hintColor: n,
|
|
1167
|
+
buttonColor: r,
|
|
1169
1168
|
linkColor: a,
|
|
1170
1169
|
textColor: c
|
|
1171
1170
|
} = s;
|
|
1172
|
-
b("--tg-theme-bg-color", t), b("--tg-theme-button-color",
|
|
1171
|
+
b("--tg-theme-bg-color", t), b("--tg-theme-button-color", r), b("--tg-theme-button-text-color", e), b("--tg-theme-hint-color", n), b("--tg-theme-link-color", a), b("--tg-theme-secondary-bg-color", o), b("--tg-theme-text-color", c);
|
|
1173
1172
|
}
|
|
1174
1173
|
function Tt(s, t) {
|
|
1175
|
-
const { backgroundColor: e, secondaryBackgroundColor: o } = t, { backgroundColor:
|
|
1176
|
-
b("--tg-bg-color",
|
|
1174
|
+
const { backgroundColor: e, secondaryBackgroundColor: o } = t, { backgroundColor: n, headerColor: r } = s;
|
|
1175
|
+
b("--tg-bg-color", n), b("--tg-header-color", r === "bg_color" ? e : o);
|
|
1177
1176
|
}
|
|
1178
1177
|
function It(s) {
|
|
1179
1178
|
const t = () => Bt(s);
|
|
@@ -1185,9 +1184,9 @@ function $t(s, t) {
|
|
|
1185
1184
|
}
|
|
1186
1185
|
function At(s) {
|
|
1187
1186
|
const t = () => {
|
|
1188
|
-
|
|
1187
|
+
U("--tg-viewport-height", s.height);
|
|
1189
1188
|
}, e = () => {
|
|
1190
|
-
|
|
1189
|
+
U("--tg-viewport-stable-height", s.stableHeight);
|
|
1191
1190
|
};
|
|
1192
1191
|
s.on("heightChanged", t), s.on("stableHeightChanged", e), t(), e();
|
|
1193
1192
|
}
|
|
@@ -1205,10 +1204,10 @@ function S(s) {
|
|
|
1205
1204
|
return t ? JSON.parse(t) : null;
|
|
1206
1205
|
}
|
|
1207
1206
|
function Rt(s, t, e) {
|
|
1208
|
-
const { isVisible: o = !1 } = s ? S("back-button") || {} : {},
|
|
1209
|
-
return
|
|
1210
|
-
V("back-button", { isVisible:
|
|
1211
|
-
}),
|
|
1207
|
+
const { isVisible: o = !1 } = s ? S("back-button") || {} : {}, n = new Ct(o, t, e);
|
|
1208
|
+
return n.on("isVisibleChanged", () => {
|
|
1209
|
+
V("back-button", { isVisible: n.isVisible });
|
|
1210
|
+
}), n;
|
|
1212
1211
|
}
|
|
1213
1212
|
function Dt(s, t) {
|
|
1214
1213
|
const { isConfirmationNeeded: e = !1 } = s ? S("closing-behavior") || {} : {}, o = new vt(e, t);
|
|
@@ -1218,15 +1217,15 @@ function Dt(s, t) {
|
|
|
1218
1217
|
}
|
|
1219
1218
|
function Lt(s, t, e, o) {
|
|
1220
1219
|
const {
|
|
1221
|
-
backgroundColor:
|
|
1222
|
-
isEnabled:
|
|
1220
|
+
backgroundColor: n = t,
|
|
1221
|
+
isEnabled: r = !1,
|
|
1223
1222
|
isVisible: a = !1,
|
|
1224
1223
|
isProgressVisible: c = !1,
|
|
1225
1224
|
textColor: u = e,
|
|
1226
1225
|
text: p = ""
|
|
1227
1226
|
} = s ? S("main-button") || {} : {}, h = new Vt(
|
|
1228
|
-
r,
|
|
1229
1227
|
n,
|
|
1228
|
+
r,
|
|
1230
1229
|
a,
|
|
1231
1230
|
c,
|
|
1232
1231
|
p,
|
|
@@ -1246,28 +1245,28 @@ function Nt(s, t) {
|
|
|
1246
1245
|
return s ? (e, o) => {
|
|
1247
1246
|
if (!C(e, t))
|
|
1248
1247
|
throw new I(e, t);
|
|
1249
|
-
return ft(o) && ht(e, o).forEach((
|
|
1250
|
-
if (!C(e,
|
|
1251
|
-
throw new $(e,
|
|
1248
|
+
return ft(o) && ht(e, o).forEach((n) => {
|
|
1249
|
+
if (!C(e, n, t))
|
|
1250
|
+
throw new $(e, n, t);
|
|
1252
1251
|
}), g(e, o);
|
|
1253
1252
|
} : g;
|
|
1254
1253
|
}
|
|
1255
|
-
function
|
|
1254
|
+
function Mt() {
|
|
1256
1255
|
let s = 0;
|
|
1257
1256
|
return () => (s += 1, s.toString());
|
|
1258
1257
|
}
|
|
1259
|
-
function
|
|
1258
|
+
function zt(s) {
|
|
1260
1259
|
const t = new P(s);
|
|
1261
1260
|
return P.sync(t), t;
|
|
1262
1261
|
}
|
|
1263
|
-
async function
|
|
1262
|
+
async function Ut(s, t, e) {
|
|
1264
1263
|
const {
|
|
1265
1264
|
height: o = window.innerHeight,
|
|
1266
|
-
stableHeight:
|
|
1267
|
-
width:
|
|
1265
|
+
stableHeight: n = window.innerHeight,
|
|
1266
|
+
width: r = window.innerWidth,
|
|
1268
1267
|
isExpanded: a = !1
|
|
1269
1268
|
} = s ? S("viewport") || {} : {}, u = t === "macos" || t === "web" ? (() => {
|
|
1270
|
-
const h = new k(o,
|
|
1269
|
+
const h = new k(o, r, n, a, e);
|
|
1271
1270
|
return k.sync(h), h;
|
|
1272
1271
|
})() : await k.synced({ postEvent: e }), p = () => V("viewport", {
|
|
1273
1272
|
height: u.height,
|
|
@@ -1277,7 +1276,7 @@ async function Wt(s, t, e) {
|
|
|
1277
1276
|
});
|
|
1278
1277
|
return u.on("heightChanged", p), u.on("isExpandedChanged", p), u.on("stableHeightChanged", p), u.on("widthChanged", p), u;
|
|
1279
1278
|
}
|
|
1280
|
-
function
|
|
1279
|
+
function Wt(s, t, e, o, n, r) {
|
|
1281
1280
|
const {
|
|
1282
1281
|
backgroundColor: a = t,
|
|
1283
1282
|
headerColor: c = "bg_color"
|
|
@@ -1286,8 +1285,8 @@ function Ut(s, t, e, o, r, n) {
|
|
|
1286
1285
|
a,
|
|
1287
1286
|
e,
|
|
1288
1287
|
o,
|
|
1289
|
-
|
|
1290
|
-
|
|
1288
|
+
n,
|
|
1289
|
+
r
|
|
1291
1290
|
), p = () => V("web-app", {
|
|
1292
1291
|
backgroundColor: u.backgroundColor,
|
|
1293
1292
|
headerColor: u.headerColor
|
|
@@ -1297,7 +1296,7 @@ function Ut(s, t, e, o, r, n) {
|
|
|
1297
1296
|
function Z() {
|
|
1298
1297
|
let s;
|
|
1299
1298
|
try {
|
|
1300
|
-
return
|
|
1299
|
+
return W(window.location.hash.slice(1));
|
|
1301
1300
|
} catch (e) {
|
|
1302
1301
|
s = e;
|
|
1303
1302
|
}
|
|
@@ -1318,13 +1317,13 @@ async function jt(s = {}) {
|
|
|
1318
1317
|
checkCompat: t = !0,
|
|
1319
1318
|
cssVars: e = !1,
|
|
1320
1319
|
acceptScrollbarStyle: o = !0,
|
|
1321
|
-
acceptCustomStyles:
|
|
1322
|
-
targetOrigin:
|
|
1320
|
+
acceptCustomStyles: n = o,
|
|
1321
|
+
targetOrigin: r,
|
|
1323
1322
|
debug: a = !1,
|
|
1324
1323
|
launchParams: c
|
|
1325
1324
|
} = s;
|
|
1326
|
-
a && ut(a), typeof
|
|
1327
|
-
const u = F(), p = c instanceof URLSearchParams || typeof c == "string" ?
|
|
1325
|
+
a && ut(a), typeof r == "string" && pt(r);
|
|
1326
|
+
const u = F(), p = c instanceof URLSearchParams || typeof c == "string" ? W(c) : Z();
|
|
1328
1327
|
ct(p);
|
|
1329
1328
|
const h = Ft() || Kt(u, p), {
|
|
1330
1329
|
initData: l,
|
|
@@ -1336,7 +1335,7 @@ async function jt(s = {}) {
|
|
|
1336
1335
|
backgroundColor: Y = "#ffffff",
|
|
1337
1336
|
buttonColor: tt = "#000000",
|
|
1338
1337
|
buttonTextColor: et = "#ffffff"
|
|
1339
|
-
} = H, R =
|
|
1338
|
+
} = H, R = Mt(), d = Nt(t, m), q = zt(H), D = Wt(
|
|
1340
1339
|
h,
|
|
1341
1340
|
Y,
|
|
1342
1341
|
m,
|
|
@@ -1346,11 +1345,11 @@ async function jt(s = {}) {
|
|
|
1346
1345
|
), {
|
|
1347
1346
|
themeParams: st,
|
|
1348
1347
|
viewport: ot,
|
|
1349
|
-
webApp:
|
|
1348
|
+
webApp: nt
|
|
1350
1349
|
} = Ht(e);
|
|
1351
|
-
|
|
1352
|
-
const L = await
|
|
1353
|
-
if (ot && At(L),
|
|
1350
|
+
nt && $t(D, q), st && It(q);
|
|
1351
|
+
const L = await Ut(h, A, d);
|
|
1352
|
+
if (ot && At(L), n && lt()) {
|
|
1354
1353
|
const y = document.createElement("style");
|
|
1355
1354
|
y.id = "telegram-custom-styles", document.head.appendChild(y), x("set_custom_style", (B) => {
|
|
1356
1355
|
y.innerHTML = B;
|
|
@@ -1370,8 +1369,8 @@ async function jt(s = {}) {
|
|
|
1370
1369
|
webApp: D
|
|
1371
1370
|
};
|
|
1372
1371
|
if (l !== void 0) {
|
|
1373
|
-
const { authDate: y, hash: B, ...
|
|
1374
|
-
O.initData = new xt(y, B,
|
|
1372
|
+
const { authDate: y, hash: B, ...rt } = l;
|
|
1373
|
+
O.initData = new xt(y, B, rt), O.initDataRaw = X;
|
|
1375
1374
|
}
|
|
1376
1375
|
return O;
|
|
1377
1376
|
}
|