@tma.js/bridge 2.3.2 → 4.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +156 -35
  2. package/dist/dts/env.d.ts +69 -0
  3. package/dist/dts/errors.d.ts +55 -9
  4. package/dist/dts/events.d.ts +64 -0
  5. package/dist/dts/index.d.ts +14 -26
  6. package/dist/dts/invokeCustomMethod.d.ts +33 -0
  7. package/dist/dts/launch-params.d.ts +101 -19
  8. package/dist/dts/logger.d.ts +29 -0
  9. package/dist/dts/mockTelegramEnv.d.ts +55 -0
  10. package/dist/dts/post-event.d.ts +40 -0
  11. package/dist/dts/request.d.ts +98 -0
  12. package/dist/dts/result.d.ts +45 -0
  13. package/dist/dts/start-param.d.ts +34 -40
  14. package/dist/dts/theme-params.d.ts +10 -0
  15. package/dist/dts/types/common.d.ts +61 -0
  16. package/dist/dts/{events/types → types}/events.d.ts +75 -56
  17. package/dist/dts/types/index.d.ts +5 -0
  18. package/dist/dts/{methods/types → types}/methods.d.ts +200 -116
  19. package/dist/dts/versions.d.ts +83 -0
  20. package/dist/dts/window-hooks.d.ts +27 -0
  21. package/dist/index.cjs +2 -3
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.iife.js +2 -3
  24. package/dist/index.iife.js.map +1 -1
  25. package/dist/index.js +619 -601
  26. package/dist/index.js.map +1 -1
  27. package/package.json +11 -19
  28. package/dist/dts/applyPolyfills.d.ts +0 -5
  29. package/dist/dts/base64-url.d.ts +0 -24
  30. package/dist/dts/env/hasWebviewProxy.d.ts +0 -10
  31. package/dist/dts/env/isIframe.d.ts +0 -5
  32. package/dist/dts/env/isTMA.d.ts +0 -31
  33. package/dist/dts/env/mockTelegramEnv.d.ts +0 -60
  34. package/dist/dts/events/createEmitter.d.ts +0 -58
  35. package/dist/dts/events/emitEvent.d.ts +0 -33
  36. package/dist/dts/events/emitter.d.ts +0 -2
  37. package/dist/dts/events/types/index.d.ts +0 -3
  38. package/dist/dts/events/types/listening.d.ts +0 -5
  39. package/dist/dts/events/types/misc.d.ts +0 -16
  40. package/dist/dts/globals.d.ts +0 -53
  41. package/dist/dts/methods/captureSameReq.d.ts +0 -10
  42. package/dist/dts/methods/createPostEvent.d.ts +0 -30
  43. package/dist/dts/methods/getReleaseVersion.d.ts +0 -15
  44. package/dist/dts/methods/postEvent.d.ts +0 -35
  45. package/dist/dts/methods/postMessage.d.ts +0 -7
  46. package/dist/dts/methods/supports.d.ts +0 -15
  47. package/dist/dts/methods/types/custom-method.d.ts +0 -59
  48. package/dist/dts/methods/types/index.d.ts +0 -6
  49. package/dist/dts/methods/types/misc.d.ts +0 -27
  50. package/dist/dts/methods/types/utils.d.ts +0 -9
  51. package/dist/dts/obj-prop-helpers.d.ts +0 -39
  52. package/dist/dts/utils/compareVersions.d.ts +0 -10
  53. package/dist/dts/utils/invokeCustomMethod.d.ts +0 -34
  54. package/dist/dts/utils/request.d.ts +0 -102
  55. package/dist/dts/utils/request2.d.ts +0 -62
  56. /package/dist/dts/{methods/types → types}/haptic-feedback.d.ts +0 -0
  57. /package/dist/dts/{methods/types → types}/popup.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,482 +1,600 @@
1
- import * as T from "valibot";
2
- import { looseObject as d, nullish as v, boolean as z, number as V, string as E, optional as B, unknown as we, parse as L, is as O, function as de, any as G } from "valibot";
3
- import { throwifyFpFn as A, getStorageValue as be, setStorageValue as Z, createLogger as ge, throwifyAnyEither as C, createCbCollector as ee, BetterTaskEither as te } from "@tma.js/toolkit";
4
- import { createLogger as vt, deepSnakeToCamelObjKeys as Et } from "@tma.js/toolkit";
5
- import { BetterPromise as re, TimeoutError as he } from "better-promises";
6
- import { CancelledError as xt, TimeoutError as kt } from "better-promises";
7
- import { function as l, either as c, option as R, taskEither as f, json as ye } from "fp-ts";
8
- import { errorClassWithData as ve, errorClass as x } from "error-kid";
9
- import { parseLaunchParamsQueryFp as ne, themeParams as Ee, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as Pe, parseLaunchParamsQuery as xe } from "@tma.js/transformers";
10
- import { signal as g, computed as se } from "@tma.js/signals";
11
- import ke from "mitt";
12
- function ie(e) {
13
- return typeof e == "object" && !!e && !Array.isArray(e) && T.is(
14
- T.looseObject({ TelegramWebviewProxy: T.looseObject({ postEvent: T.function() }) }),
15
- { TelegramWebviewProxy: e.TelegramWebviewProxy }
16
- );
17
- }
18
- function pe() {
19
- try {
20
- return window.self !== window.top;
21
- } catch {
22
- return !0;
23
- }
1
+ import { errorClass as Se, errorClassWithData as d } from "error-kid";
2
+ import { matchError as qt } from "error-kid";
3
+ import { pipe as l, string as i, parseJson as ie, record as Te, union as xe, number as $, transform as U, check as ke, safeParse as j, object as Le, ValiError as We, optional as u, nonEmpty as K, looseObject as w, unknown as ce, parse as Ae, nullish as b, boolean as X } from "valibot";
4
+ class pe extends (/* @__PURE__ */ Se({
5
+ name: "UnknownEnvError",
6
+ message: "Unable to determine the way to communicate with the Telegram client"
7
+ })) {
24
8
  }
25
- class Te extends (/* @__PURE__ */ x({
9
+ class qe extends (/* @__PURE__ */ d({
26
10
  name: "MethodUnsupportedError",
27
- super: (t, r) => [
28
- `Method "${t}" is unsupported in Mini Apps version ${r}`
29
- ]
11
+ data: (t, r) => ({ method: t, version: r }),
12
+ message: (t, r) => `Method "${t}" is unsupported in Mini Apps version ${r}`
30
13
  })) {
31
14
  }
32
- class Se extends (/* @__PURE__ */ x({
15
+ class Me extends (/* @__PURE__ */ d({
33
16
  name: "MethodParameterUnsupportedError",
34
- super: (t, r, n) => [
35
- `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
36
- ]
17
+ data: (t, r, n) => ({ method: t, param: r, version: n }),
18
+ message: (t, r, n) => `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
37
19
  })) {
38
20
  }
39
- class Ae extends (/* @__PURE__ */ ve({
21
+ class Oe extends (/* @__PURE__ */ d({
40
22
  name: "LaunchParamsRetrieveError",
41
23
  data: (t) => ({ errors: t }),
42
- super: (t) => [
43
- [
44
- "Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?",
45
- "📖 Refer to docs for more information:",
46
- "https://docs.telegram-mini-apps.com/packages/tma-js-bridge/environment",
47
- "",
48
- "Collected errors:",
49
- ...t.map(({ source: r, error: n }) => `Source: ${r} / ${n instanceof Error ? n.message : String(n)}`)
50
- ].join(`
24
+ message: (t) => [
25
+ "Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?",
26
+ "",
27
+ "Collected errors:",
28
+ ...t.map(({ source: r, error: n }) => `- ${r}: ${n instanceof Error ? n.message : String(n)}`)
29
+ ].join(`
51
30
  `)
52
- ]
53
31
  })) {
54
32
  }
55
- class Ce extends (/* @__PURE__ */ x({
33
+ class Re extends (/* @__PURE__ */ d({
56
34
  name: "InvalidLaunchParamsError",
57
- super: (t, r) => [
58
- `Invalid value for launch params: ${t}`,
59
- { cause: r }
60
- ]
35
+ message: (t) => `Invalid launch parameters: ${t}`,
36
+ cause: (t, r) => r,
37
+ data: (t) => ({ value: t })
61
38
  })) {
62
39
  }
63
- class ce extends (/* @__PURE__ */ x({ name: "UnknownEnvError" })) {
40
+ class Ie extends (/* @__PURE__ */ d({
41
+ name: "InvokeCustomMethodFailedError",
42
+ data: (t) => ({ error: t }),
43
+ message: (t) => `Custom method invocation failed: ${t}`
44
+ })) {
64
45
  }
65
- class Me extends (/* @__PURE__ */ x({
66
- name: "InvokeCustomMethodError",
67
- super: (t) => [`Server returned error: ${t}`]
46
+ class ue extends (/* @__PURE__ */ d({
47
+ name: "TimeoutError",
48
+ data: (t) => ({ timeout: t }),
49
+ message: (t) => `Timeout reached: ${t}ms`
68
50
  })) {
69
51
  }
70
- const D = "launchParams";
71
- function J(e) {
72
- return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
52
+ class $e extends (/* @__PURE__ */ d({
53
+ name: "StartParamTooLongError",
54
+ data: (t) => ({ length: t }),
55
+ message: (t) => `Encoded start parameter length is ${t}, but the maximum allowed is 512`
56
+ })) {
73
57
  }
74
- function We() {
75
- return l.pipe(
76
- M(),
77
- c.chainW(ne)
78
- );
58
+ function f(e) {
59
+ return { ok: !0, data: e };
79
60
  }
80
- const rt = A(We);
81
- function je() {
82
- return l.pipe(
83
- M(),
84
- c.map((e) => {
85
- const t = new URLSearchParams(e).get("tgWebAppData");
86
- return t ? R.some(t) : R.none;
87
- })
88
- );
61
+ function h(e) {
62
+ return { ok: !1, error: e };
89
63
  }
90
- function nt() {
91
- return l.pipe(
92
- je(),
93
- c.fold((e) => {
94
- throw e;
95
- }, (e) => e),
96
- R.match(() => {
97
- }, (e) => e)
98
- );
64
+ function A(e) {
65
+ if (!e.ok)
66
+ throw e.error;
67
+ return e.data;
68
+ }
69
+ function v(e) {
70
+ return (...t) => {
71
+ const r = e(...t);
72
+ return r instanceof Promise ? r.then(A) : A(r);
73
+ };
74
+ }
75
+ const Ue = l(
76
+ xe([i(), $()]),
77
+ U((e) => typeof e == "number" ? `#${(e & 16777215).toString(16).padStart(6, "0")}` : e),
78
+ ke(
79
+ (e) => /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.test(e),
80
+ (e) => `Invalid color: ${String(e.input)}`
81
+ )
82
+ ), _e = Te(i(), Ue), Q = l(
83
+ i(),
84
+ ie(),
85
+ _e
86
+ ), fe = "tma.js/launch-params", M = u(l(i(), U((e) => e === "1"))), je = Le({
87
+ tgWebAppBotInline: M,
88
+ tgWebAppData: u(i()),
89
+ tgWebAppDefaultColors: u(Q),
90
+ tgWebAppFullscreen: M,
91
+ tgWebAppPlatform: l(i(), K()),
92
+ tgWebAppShowSettings: M,
93
+ tgWebAppStartParam: u(i()),
94
+ tgWebAppThemeParams: u(Q, "{}"),
95
+ tgWebAppVersion: l(i(), K())
96
+ });
97
+ function le(e) {
98
+ const t = new URLSearchParams(e), r = {};
99
+ t.forEach((o, a) => {
100
+ a in r || (r[a] = o);
101
+ });
102
+ const n = j(je, r);
103
+ return n.success ? f(n.output) : h(new Re(t.toString(), new We(n.issues)));
104
+ }
105
+ const De = /* @__PURE__ */ v(le);
106
+ function Ce(e) {
107
+ const t = new URLSearchParams();
108
+ return Object.entries(e).forEach(([r, n]) => {
109
+ n !== void 0 && t.set(
110
+ r,
111
+ typeof n == "boolean" ? n ? "1" : "0" : typeof n == "object" ? JSON.stringify(n) : String(n)
112
+ );
113
+ }), t.toString();
114
+ }
115
+ function Y(e) {
116
+ return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
99
117
  }
100
- function M() {
118
+ function Z(e) {
119
+ try {
120
+ return sessionStorage.getItem(e);
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+ const Ne = [
126
+ // Launch parameters are passed in the URL hash. They can be missing in case the app changed
127
+ // the location and then the page was reloaded.
128
+ ["window.location.href", () => Y(window.location.href)],
129
+ // The initial page URL.
130
+ ["performance navigation entries", () => {
131
+ const [e] = performance.getEntriesByType("navigation");
132
+ return e && Y(e.name);
133
+ }],
134
+ // Value saved by this package previously.
135
+ ["session storage", () => Z(fe)],
136
+ // Value saved by the official SDK.
137
+ ["official SDK session storage", () => {
138
+ const e = Z("__telegram__initParams");
139
+ if (!e)
140
+ return;
141
+ const t = JSON.parse(e);
142
+ return t ? new URLSearchParams(
143
+ Object.entries(t).filter((r) => typeof r[1] == "string")
144
+ ).toString() : void 0;
145
+ }]
146
+ ];
147
+ function de(e) {
148
+ try {
149
+ sessionStorage.setItem(fe, e);
150
+ } catch {
151
+ }
152
+ }
153
+ function D() {
101
154
  const e = [];
102
- for (const [t, r] of [
103
- // Try to retrieve launch parameters from the current location. This method
104
- // can return nothing in case, location was changed, and then the page was
105
- // reloaded.
106
- [() => J(window.location.href), "window.location.href"],
107
- // Then, try using the lower level API - window.performance.
108
- [() => {
109
- const n = performance.getEntriesByType("navigation")[0];
110
- return n && J(n.name);
111
- }, "performance navigation entries"],
112
- // Finally, try using the session storage.
113
- [() => be(D), "local storage"]
114
- ]) {
115
- const n = t();
155
+ for (const [t, r] of Ne) {
156
+ let n;
157
+ try {
158
+ n = r();
159
+ } catch (a) {
160
+ e.push({ source: t, error: a });
161
+ continue;
162
+ }
116
163
  if (!n) {
117
- e.push({ source: r, error: new Error("Source is empty") });
164
+ e.push({ source: t, error: new Error("Source is empty") });
118
165
  continue;
119
166
  }
120
- const a = l.pipe(
121
- ne(n),
122
- c.foldW((o) => o, () => !0)
123
- );
124
- if (typeof a != "boolean") {
125
- e.push({ source: r, error: a });
167
+ const o = le(n);
168
+ if (!o.ok) {
169
+ e.push({ source: t, error: o.error });
126
170
  continue;
127
171
  }
128
- return Z(D, n), c.right(n);
172
+ return de(n), f({ raw: n, parsed: o.data });
129
173
  }
130
- return c.left(new Ae(e));
131
- }
132
- const ot = A(M);
133
- function qe(e, t) {
134
- const r = /* @__PURE__ */ new Map(), n = ke(), a = (o, s, p = !1) => {
135
- const _ = r.get(o) || /* @__PURE__ */ new Map();
136
- r.set(o, _);
137
- const i = _.get(s) || [];
138
- _.set(s, i);
139
- const u = i.findIndex((m) => m[1] === p);
140
- if (u >= 0 && (n.off(o, i[u][0]), i.splice(u, 1), !i.length && (_.delete(s), !_.size))) {
141
- const m = r.size;
142
- r.delete(o), m && !r.size && t();
143
- }
144
- };
145
- return {
146
- on(o, s, p) {
147
- !r.size && e();
148
- const _ = () => {
149
- a(o, s, p);
150
- }, i = (...w) => {
151
- p && _(), o === "*" ? s({ name: w[0], payload: w[1] }) : s(...w);
152
- };
153
- n.on(o, i);
154
- const u = r.get(o) || /* @__PURE__ */ new Map();
155
- r.set(o, u);
156
- const m = u.get(s) || [];
157
- return u.set(s, m), m.push([i, p || !1]), _;
158
- },
159
- off: a,
160
- // eslint-disable-next-line @typescript-eslint/unbound-method
161
- emit: n.emit,
162
- clear() {
163
- const o = r.size;
164
- n.all.clear(), r.clear(), o && t();
165
- }
166
- };
174
+ return h(new Oe(e));
175
+ }
176
+ function Je() {
177
+ const e = D();
178
+ return e.ok ? f(e.data.raw) : e;
179
+ }
180
+ const Ve = /* @__PURE__ */ v(Je);
181
+ function ze() {
182
+ const e = D();
183
+ return e.ok ? f(e.data.parsed) : e;
184
+ }
185
+ const _t = /* @__PURE__ */ v(ze);
186
+ function Be() {
187
+ const e = D();
188
+ return e.ok ? f(e.data.parsed.tgWebAppData) : e;
189
+ }
190
+ const ft = /* @__PURE__ */ v(Be), O = [
191
+ "%cBridge",
192
+ "background:#9147ff;color:white;font-weight:bold;padding:0 5px;border-radius:5px"
193
+ ], me = {
194
+ log: (...e) => console.log(...O, ...e),
195
+ warn: (...e) => console.warn(...O, ...e),
196
+ error: (...e) => console.error(...O, ...e)
197
+ };
198
+ let C = !1, N = me;
199
+ function lt(e) {
200
+ C = e;
167
201
  }
168
- function j(e, t) {
169
- window.dispatchEvent(new MessageEvent("message", {
170
- data: JSON.stringify({ eventType: e, eventData: t }),
171
- // We specify this kind of source here in order to allow the package's "on" function to
172
- // capture it. The reason is this function always checks the event source and relies on
173
- // it to be the parent window.
174
- source: window.parent
175
- }));
202
+ function dt() {
203
+ return C;
176
204
  }
177
- const S = g(!1), U = g("https://web.telegram.org"), Fe = (e) => {
178
- b().log("Event received:", e);
179
- }, _e = se(S);
180
- function at(e) {
181
- e !== S() && (S.set(e), (e ? I : Oe)("*", Fe));
205
+ function mt(e = me) {
206
+ N = e;
182
207
  }
183
- const ue = se(U);
184
- function st(e) {
185
- U.set(e), b().log("New target origin set", e);
186
- }
187
- const P = g((...e) => {
188
- window.parent.postMessage(...e);
189
- }), b = g(ge("Bridge", {
190
- bgColor: "#9147ff",
191
- textColor: "white",
192
- shouldLog: _e
193
- }));
194
- function it() {
195
- Ue(), [P, U, ue, S, _e, b].forEach((e) => {
196
- e.unsubAll(), "reset" in e && e.reset();
197
- });
208
+ function J() {
209
+ return N;
198
210
  }
199
- function q(e, t, r) {
200
- const n = [r], a = e[t];
201
- typeof a == "function" && n.push(a);
202
- const o = (...p) => {
203
- n.forEach((_) => _(...p));
204
- }, s = Object.assign((...p) => {
205
- o(...p);
206
- }, {
207
- // Unwraps the composer.
208
- unwrap() {
209
- const { length: p } = n;
210
- if (p === 1) {
211
- delete e[t];
212
- return;
213
- }
214
- if (p === 2) {
215
- Q(e, t, n[1]);
216
- return;
217
- }
218
- n.unshift(1), Q(e, t, o);
211
+ function V(...e) {
212
+ C && N.log(...e);
213
+ }
214
+ function R(e, t, r) {
215
+ let n = typeof e[t] == "function" ? e[t] : void 0;
216
+ const o = (...a) => {
217
+ r(...a), n && n(...a);
218
+ };
219
+ return Object.defineProperty(e, t, {
220
+ configurable: !0,
221
+ enumerable: !0,
222
+ get: () => o,
223
+ set(a) {
224
+ n = typeof a == "function" ? a : void 0;
219
225
  }
220
- });
221
- me(
222
- e,
223
- t,
224
- () => s,
225
- (p) => n.push(p)
226
- );
226
+ }), () => {
227
+ n ? Object.defineProperty(e, t, {
228
+ configurable: !0,
229
+ enumerable: !0,
230
+ writable: !0,
231
+ value: n
232
+ }) : delete e[t];
233
+ };
227
234
  }
228
- function N(e, t) {
235
+ function ee(e, t) {
229
236
  const r = e[t];
230
- me(e, t, () => r, (n) => {
231
- Object.entries(n).forEach(([a, o]) => {
232
- r[a] = o;
233
- });
234
- });
235
- }
236
- function me(e, t, r, n) {
237
- Object.defineProperty(e, t, {
238
- enumerable: !0,
237
+ return Object.defineProperty(e, t, {
239
238
  configurable: !0,
240
- get: r,
241
- set: n
242
- });
243
- }
244
- function Q(e, t, r) {
245
- Object.defineProperty(e, t, {
246
239
  enumerable: !0,
247
- configurable: !0,
248
- writable: !0,
249
- value: r
240
+ get: () => r,
241
+ set(n) {
242
+ n && typeof n == "object" && Object.assign(r, n);
243
+ }
244
+ }), () => {
245
+ Object.defineProperty(e, t, {
246
+ configurable: !0,
247
+ enumerable: !0,
248
+ writable: !0,
249
+ value: r
250
+ });
251
+ };
252
+ }
253
+ function I(e, t) {
254
+ return e[t] ? () => {
255
+ } : (e[t] = {}, () => {
256
+ const r = e[t];
257
+ r && typeof r == "object" && !Object.keys(r).length && delete e[t];
250
258
  });
251
259
  }
252
- const Le = {
253
- clipboard_text_received: d({
254
- req_id: E(),
255
- data: v(E())
260
+ const _ = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
261
+ let L;
262
+ const we = l(
263
+ i(),
264
+ ie(),
265
+ w({ eventType: i(), eventData: u(ce()) })
266
+ ), Ge = {
267
+ clipboard_text_received: w({
268
+ req_id: i(),
269
+ data: b(i())
256
270
  }),
257
- custom_method_invoked: d({
258
- req_id: E(),
259
- result: B(we()),
260
- error: B(E())
271
+ custom_method_invoked: w({
272
+ req_id: i(),
273
+ result: u(ce()),
274
+ error: u(i())
261
275
  }),
262
- popup_closed: v(
263
- d({ button_id: v(E(), () => {
264
- }) }),
265
- {}
276
+ popup_closed: l(
277
+ b(w({ button_id: b(i()) })),
278
+ U((e) => e && typeof e.button_id == "string" ? { button_id: e.button_id } : {})
266
279
  ),
267
- viewport_changed: v(
268
- d({
269
- height: V(),
270
- width: v(V(), () => window.innerWidth),
271
- is_state_stable: z(),
272
- is_expanded: z()
280
+ theme_changed: w({ theme_params: _e }),
281
+ viewport_changed: b(
282
+ w({
283
+ height: $(),
284
+ width: b($(), () => window.innerWidth),
285
+ is_expanded: X(),
286
+ is_state_stable: X()
273
287
  }),
274
- // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
275
- // null. Leaving this default value until the bug is fixed.
288
+ // macOS client sends null instead of the payload.
276
289
  () => ({
277
290
  height: window.innerHeight,
278
- is_state_stable: !0,
279
- is_expanded: !0
291
+ width: window.innerWidth,
292
+ is_expanded: !0,
293
+ is_state_stable: !0
280
294
  })
281
- ),
282
- theme_changed: d({
283
- theme_params: Ee()
284
- })
295
+ )
285
296
  };
286
- function H(e) {
287
- if (e.source !== window.parent)
288
- return;
289
- let t;
297
+ function Fe(e, t) {
290
298
  try {
291
- t = L(oe(ae()), e.data);
292
- } catch {
293
- return;
299
+ e(t);
300
+ } catch (r) {
301
+ J().error("An event listener threw an error:", r);
294
302
  }
295
- const { eventType: r, eventData: n } = t, a = Le[r];
296
- let o;
303
+ }
304
+ function te(e, t) {
305
+ [...e].forEach(([r, n]) => {
306
+ e.get(r) !== void 0 && (n && e.delete(r), Fe(r, t));
307
+ });
308
+ }
309
+ function W(e, t) {
310
+ const r = Ge[e];
311
+ let n;
297
312
  try {
298
- o = a ? L(a, n) : n;
299
- } catch (s) {
300
- return b().forceError(
301
- [
302
- `An error occurred processing the "${r}" event from the Telegram application.`,
303
- "Please, file an issue here:",
304
- "https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"
305
- ].join(`
306
- `),
307
- t,
308
- s
309
- );
310
- }
311
- Re(r, o);
312
- }
313
- const {
314
- on: I,
315
- off: Oe,
316
- emit: Re,
317
- clear: Ue
318
- } = qe(
319
- () => {
320
- const e = window;
321
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", j), N(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), q(e.Telegram.WebView, "receiveEvent", j), N(e.Telegram, "WebView"), q(e, "TelegramGameProxy_receiveEvent", j), window.addEventListener("message", H);
322
- },
323
- () => {
324
- [
325
- ["TelegramGameProxy_receiveEvent"],
326
- ["TelegramGameProxy", "receiveEvent"],
327
- ["Telegram", "WebView", "receiveEvent"]
328
- ].forEach((e) => {
329
- const t = window;
330
- let r = [void 0, t];
331
- for (const o of e)
332
- if (r = [r[1], r[1][o]], !r[1])
333
- return;
334
- const [n, a] = r;
335
- "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
336
- }), window.removeEventListener("message", H);
313
+ n = r ? Ae(r, t) : t;
314
+ } catch (a) {
315
+ J().error(`Unable to process the "${e}" event payload:`, t, a);
316
+ return;
337
317
  }
338
- ), Ie = (...e) => P()(...e);
339
- function $e(e, t) {
340
- l.pipe(
341
- k(
342
- // @ts-expect-error It's ok, TS can't determine a specific override.
343
- e,
344
- t
345
- ),
346
- c.mapLeft((r) => {
347
- throw r;
348
- })
318
+ V("Event received:", e, n);
319
+ const o = _.get(e);
320
+ o && (te(o, n), !o.size && _.delete(e)), te(y, { name: e, payload: n }), E();
321
+ }
322
+ function re(e) {
323
+ if (e.source !== window.parent)
324
+ return;
325
+ const t = j(we, e.data);
326
+ t.success && W(t.output.eventType, t.output.eventData);
327
+ }
328
+ function He() {
329
+ const e = P(), t = [
330
+ I(e, "Telegram"),
331
+ I(e.Telegram, "WebView"),
332
+ ee(e.Telegram, "WebView"),
333
+ R(e.Telegram.WebView, "receiveEvent", W),
334
+ I(e, "TelegramGameProxy"),
335
+ ee(e, "TelegramGameProxy"),
336
+ R(e.TelegramGameProxy, "receiveEvent", W),
337
+ R(e, "TelegramGameProxy_receiveEvent", W)
338
+ ];
339
+ return window.addEventListener("message", re), () => {
340
+ window.removeEventListener("message", re), t.reverse().forEach((r) => r());
341
+ };
342
+ }
343
+ function Ke() {
344
+ L || (L = He());
345
+ }
346
+ function E() {
347
+ L && !_.size && !y.size && (L(), L = void 0);
348
+ }
349
+ function be(e, t, r) {
350
+ const { signal: n } = r;
351
+ if (n && n.aborted)
352
+ return () => {
353
+ };
354
+ Ke(), e();
355
+ const o = () => {
356
+ t(), E(), n && n.removeEventListener("abort", o);
357
+ };
358
+ return n && n.addEventListener("abort", o), o;
359
+ }
360
+ function Xe(e, t, r = {}) {
361
+ return be(
362
+ () => {
363
+ const n = _.get(e) || /* @__PURE__ */ new Map();
364
+ _.set(e, n), n.set(t, !!r.once);
365
+ },
366
+ () => Qe(e, t),
367
+ r
349
368
  );
350
369
  }
351
- function k(e, t) {
352
- b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
353
- const r = window, n = JSON.stringify({ eventType: e, eventData: t });
354
- return pe() ? (Ie(n, ue()), c.right(void 0)) : ie(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(d({ external: d({ notify: de() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new ce());
370
+ function Qe(e, t) {
371
+ const r = _.get(e);
372
+ r && (r.delete(t), !r.size && _.delete(e)), E();
355
373
  }
356
- function $(e, t, r = {}) {
357
- const {
358
- // If no capture function was passed, we capture the first compatible event.
359
- capture: n = () => !0,
360
- postEvent: a = k
361
- } = r, o = g(), [s, p] = ee();
362
- (Array.isArray(t) ? t : [t]).forEach((i) => {
363
- s(
364
- I(i, (u) => {
365
- const m = Array.isArray(t);
366
- n(m ? { event: i, payload: u } : u) && o.set([
367
- m ? { event: i, payload: u } : u
368
- ]);
369
- })
370
- );
371
- });
372
- const _ = (i) => (p(), i);
373
- return l.pipe(
374
- async () => a(e, r.params),
375
- f.chainW(() => te((i, u, m) => {
376
- const w = o();
377
- if (w)
378
- return i(w[0]);
379
- const h = (y) => {
380
- y && i(y[0]);
381
- }, W = () => {
382
- o.unsub(h);
383
- };
384
- o.sub(h), m.on("finalized", W);
385
- }, r)),
386
- f.mapBoth(_, _)
374
+ function wt(e, t = {}) {
375
+ return be(
376
+ () => y.set(e, !!t.once),
377
+ () => Ye(e),
378
+ t
387
379
  );
388
380
  }
389
- function pt(e, t, r) {
390
- const { postEvent: n } = r || {};
391
- return C(
392
- // @ts-expect-error TypeScript will not be able to handle our overrides here.
393
- $(e, t, {
394
- ...r,
395
- postEvent: n ? (...a) => {
381
+ function Ye(e) {
382
+ y.delete(e), E();
383
+ }
384
+ function bt() {
385
+ _.clear(), y.clear(), E();
386
+ }
387
+ function gt(e, ...t) {
388
+ var o, a;
389
+ const [r] = t, n = (a = (o = P().Telegram) == null ? void 0 : o.WebView) == null ? void 0 : a.receiveEvent;
390
+ if (!B() && typeof n == "function") {
391
+ n(e, r);
392
+ return;
393
+ }
394
+ window.dispatchEvent(new MessageEvent("message", {
395
+ data: JSON.stringify({ eventType: e, eventData: r }),
396
+ source: window.parent
397
+ }));
398
+ }
399
+ let z = "https://web.telegram.org";
400
+ function ht(e) {
401
+ z = e;
402
+ }
403
+ function vt() {
404
+ return z;
405
+ }
406
+ let g = (e, t) => {
407
+ window.parent.postMessage(e, t);
408
+ };
409
+ function Ze(e) {
410
+ const t = g;
411
+ return g = e, () => {
412
+ g = t;
413
+ };
414
+ }
415
+ function et() {
416
+ return g;
417
+ }
418
+ const ge = (e, ...t) => {
419
+ const [r = ""] = t;
420
+ V("Posting method:", e, r);
421
+ const n = JSON.stringify({ eventType: e, eventData: r });
422
+ if (B()) {
423
+ g(n, z);
424
+ return;
425
+ }
426
+ const o = P();
427
+ if (o.TelegramWebviewProxy && typeof o.TelegramWebviewProxy.postEvent == "function") {
428
+ o.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
429
+ return;
430
+ }
431
+ if (o.external && typeof o.external.notify == "function") {
432
+ o.external.notify(n);
433
+ return;
434
+ }
435
+ throw new pe();
436
+ };
437
+ function he(e, t, ...r) {
438
+ const {
439
+ capture: n = () => !0,
440
+ timeout: o,
441
+ signal: a,
442
+ params: s,
443
+ postEvent: p = ge
444
+ } = r[0] || {};
445
+ return new Promise((S, m) => {
446
+ if (a && a.aborted)
447
+ return m(a.reason);
448
+ const T = [], G = (c) => (x) => {
449
+ T.forEach((k) => k()), c(x);
450
+ }, F = G(S), q = G(m), H = Array.isArray(t);
451
+ if ((H ? t : [t]).forEach((c) => {
452
+ T.push(Xe(c, (x) => {
453
+ const k = H ? { event: c, payload: x } : x;
396
454
  try {
397
- return n(...a), c.right(void 0);
398
- } catch (o) {
399
- return c.left(o);
455
+ n(k) && F(f(k));
456
+ } catch (Pe) {
457
+ q(Pe);
400
458
  }
401
- } : k
402
- })
403
- );
459
+ }));
460
+ }), o) {
461
+ const c = setTimeout(() => F(h(new ue(o))), o);
462
+ T.push(() => clearTimeout(c));
463
+ }
464
+ if (a) {
465
+ const c = () => q(a.reason);
466
+ a.addEventListener("abort", c), T.push(() => a.removeEventListener("abort", c));
467
+ }
468
+ try {
469
+ p(e, s);
470
+ } catch (c) {
471
+ q(c);
472
+ }
473
+ });
404
474
  }
405
- function ct(e, t) {
406
- const r = ze(
407
- // @ts-expect-error TS doesn't get what override we are going to use.
408
- e,
409
- t
410
- );
411
- return typeof r == "function" ? re.fn(() => C(r)) : r;
412
- }
413
- function ze(e, t) {
414
- const r = ie(window);
415
- if (!e)
416
- return r || l.pipe(M(), c.match(() => !1, () => !0));
417
- if (r)
418
- return f.right(!0);
419
- const { timeout: n = 100 } = t || {};
420
- return l.pipe(
421
- $("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
422
- f.match(
423
- (a) => he.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
424
- () => c.right(!0)
425
- )
475
+ async function tt(e, t, ...r) {
476
+ return A(await he(e, t, ...r));
477
+ }
478
+ function rt() {
479
+ return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
480
+ }
481
+ function nt(e) {
482
+ return (t) => t.req_id === e;
483
+ }
484
+ function P() {
485
+ return window;
486
+ }
487
+ function B() {
488
+ try {
489
+ return window.self !== window.top;
490
+ } catch {
491
+ return !0;
492
+ }
493
+ }
494
+ function ve() {
495
+ var e;
496
+ return typeof ((e = P().TelegramWebviewProxy) == null ? void 0 : e.postEvent) == "function";
497
+ }
498
+ function yt() {
499
+ if (ve())
500
+ return !0;
501
+ try {
502
+ return Ve(), !0;
503
+ } catch {
504
+ return !1;
505
+ }
506
+ }
507
+ async function Et(e = {}) {
508
+ if (ve())
509
+ return !0;
510
+ try {
511
+ return await tt("web_app_request_theme", "theme_changed", { timeout: 100, ...e }), !0;
512
+ } catch (t) {
513
+ if (ue.is(t) || pe.is(t))
514
+ return !1;
515
+ throw t;
516
+ }
517
+ }
518
+ async function ot(e, t, { requestId: r = rt(), ...n } = {}) {
519
+ const o = await he(
520
+ "web_app_invoke_custom_method",
521
+ "custom_method_invoked",
522
+ {
523
+ ...n,
524
+ params: { method: e, params: t, req_id: r },
525
+ capture: nt(r)
526
+ }
426
527
  );
528
+ if (!o.ok)
529
+ return o;
530
+ const { result: a, error: s } = o.data;
531
+ return s ? h(new Ie(s)) : f(a);
532
+ }
533
+ async function Pt(e, t, r) {
534
+ return A(await ot(e, t, r));
427
535
  }
428
- function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
536
+ function St({ launchParams: e, onMethod: t } = {}) {
429
537
  if (e) {
430
- const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
431
- // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
432
- // value. We are doing it because we are working with tgWebAppData presented as a
433
- // string, not an object as serializeLaunchParamsQuery requires.
434
- Pe({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
435
- );
436
- try {
437
- xe(o);
438
- } catch (s) {
439
- throw new Ce(o, s);
440
- }
441
- Z("launchParams", o);
538
+ const a = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : Ce(e);
539
+ De(a), de(a);
442
540
  }
443
- if (pe()) {
541
+ if (B()) {
444
542
  if (!t)
445
- return;
446
- r && P.reset();
447
- const o = P();
448
- P.set((...s) => {
449
- const [p] = s, _ = () => {
450
- o(...s);
543
+ return () => {
451
544
  };
452
- try {
453
- const i = L(oe(ae()), p);
454
- t({ name: i.eventType, params: i.eventData }, _);
455
- } catch {
456
- _();
457
- }
545
+ const a = et();
546
+ return Ze((s, p) => {
547
+ const S = () => a(s, p), m = j(we, s);
548
+ if (!m.success)
549
+ return S();
550
+ t({
551
+ name: m.output.eventType,
552
+ params: ne(m.output.eventData)
553
+ }, S);
458
554
  });
459
- return;
460
555
  }
461
- const n = window.TelegramWebviewProxy || {}, a = n.postEvent || (() => {
462
- });
463
- window.TelegramWebviewProxy = {
464
- ...n,
465
- postEvent(o, s) {
466
- const p = () => {
467
- a(o, s);
468
- };
556
+ const r = P(), n = r.TelegramWebviewProxy, o = {
557
+ postEvent(a, s) {
558
+ const p = () => n && n.postEvent(a, s);
469
559
  t ? t({
470
- name: o,
471
- params: s ? JSON.parse(s) : void 0
560
+ name: a,
561
+ params: ne(s ? JSON.parse(s) : void 0)
472
562
  }, p) : p();
473
563
  }
474
- }, b().log("Environment was mocked by the mockTelegramEnv function");
564
+ };
565
+ return r.TelegramWebviewProxy = o, V("Environment was mocked"), () => {
566
+ r.TelegramWebviewProxy === o && (n ? r.TelegramWebviewProxy = n : delete r.TelegramWebviewProxy);
567
+ };
475
568
  }
476
- function Ve(e) {
477
- return ({ req_id: t }) => t === e;
569
+ function ne(e) {
570
+ return e === "" ? void 0 : e;
478
571
  }
479
- const K = {
572
+ const ye = 512;
573
+ function Ee(e) {
574
+ let t = "";
575
+ return new TextEncoder().encode(e).forEach((r) => {
576
+ t += String.fromCharCode(r);
577
+ }), btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
578
+ }
579
+ function at(e) {
580
+ const t = atob(e.replace(/-/g, "+").replace(/_/g, "/"));
581
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(
582
+ Uint8Array.from(t, (r) => r.charCodeAt(0))
583
+ );
584
+ }
585
+ function Tt(e) {
586
+ return Ee(e).length <= ye;
587
+ }
588
+ function st(e) {
589
+ const t = Ee(typeof e == "string" ? e : JSON.stringify(e));
590
+ return t.length > ye ? h(new $e(t.length)) : f(t);
591
+ }
592
+ const xt = /* @__PURE__ */ v(st);
593
+ function kt(e, t) {
594
+ const r = at(e);
595
+ return t ? t === "json" ? JSON.parse(r) : t(r) : r;
596
+ }
597
+ const oe = {
480
598
  "6.0": [
481
599
  "iframe_ready",
482
600
  "iframe_will_reload",
@@ -503,14 +621,14 @@ const K = {
503
621
  "web_app_close_scan_qr_popup",
504
622
  "web_app_open_scan_qr_popup",
505
623
  "web_app_read_text_from_clipboard",
506
- { method: "web_app_open_link", param: "try_instant_view" }
624
+ ["web_app_open_link", "try_instant_view"]
507
625
  ],
508
626
  6.7: ["web_app_switch_inline_query"],
509
627
  6.9: [
510
628
  "web_app_invoke_custom_method",
511
629
  "web_app_request_write_access",
512
630
  "web_app_request_phone",
513
- { method: "web_app_set_header_color", param: "color" }
631
+ ["web_app_set_header_color", "color"]
514
632
  ],
515
633
  "6.10": ["web_app_setup_settings_button"],
516
634
  7.2: [
@@ -521,15 +639,15 @@ const K = {
521
639
  "web_app_biometry_update_token"
522
640
  ],
523
641
  7.6: [
524
- { method: "web_app_open_link", param: "try_browser" },
525
- { method: "web_app_close", param: "return_back" }
642
+ ["web_app_open_link", "try_browser"],
643
+ ["web_app_close", "return_back"]
526
644
  ],
527
645
  7.7: ["web_app_setup_swipe_behavior"],
528
646
  7.8: ["web_app_share_to_story"],
529
647
  "7.10": [
530
648
  "web_app_setup_secondary_button",
531
649
  "web_app_set_bottom_bar_color",
532
- { method: "web_app_setup_main_button", param: "has_shine_effect" }
650
+ ["web_app_setup_main_button", "has_shine_effect"]
533
651
  ],
534
652
  "8.0": [
535
653
  "web_app_request_safe_area",
@@ -564,205 +682,105 @@ const K = {
564
682
  ],
565
683
  9.1: ["web_app_hide_keyboard"],
566
684
  9.5: [
567
- { method: "web_app_setup_main_button", param: "icon_custom_emoji_id" },
568
- { method: "web_app_setup_secondary_button", param: "icon_custom_emoji_id" }
569
- ]
685
+ ["web_app_setup_main_button", "icon_custom_emoji_id"],
686
+ ["web_app_setup_secondary_button", "icon_custom_emoji_id"]
687
+ ],
688
+ 9.6: ["web_app_request_chat"]
570
689
  };
571
- function Y(e, t) {
572
- return Object.keys(K).find((n) => K[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
573
- }
574
- function X(e) {
575
- return e.split(".").map(Number);
576
- }
577
- function Be(e, t) {
578
- const r = X(e), n = X(t), a = Math.max(r.length, n.length);
579
- for (let o = 0; o < a; o += 1) {
580
- const s = r[o] || 0, p = n[o] || 0;
581
- if (s !== p)
582
- return s > p ? 1 : -1;
690
+ function it(e, t) {
691
+ const r = e.split(".").map(Number), n = t.split(".").map(Number);
692
+ for (let o = 0; o < Math.max(r.length, n.length); o++) {
693
+ const a = r[o] || 0, s = n[o] || 0;
694
+ if (a !== s)
695
+ return a > s ? 1 : -1;
583
696
  }
584
697
  return 0;
585
698
  }
586
- function F(e, t, r) {
587
- const n = r ? Y(
588
- e,
589
- t
590
- ) : Y(e);
591
- return n ? Be(n, r || t) <= 0 : !1;
699
+ function ae(e, t) {
700
+ return Object.keys(oe).find((r) => oe[r].some((n) => t ? typeof n == "object" && n[0] === e && n[1] === t : n === e));
701
+ }
702
+ function se(e, t, r) {
703
+ const n = r ? ae(e, t) : ae(e);
704
+ return !!n && it(n, r || t) <= 0;
592
705
  }
593
- function ut(e, t = "strict") {
706
+ const ct = [
707
+ ["web_app_set_header_color", "color"],
708
+ ["web_app_setup_main_button", "icon_custom_emoji_id"],
709
+ ["web_app_setup_secondary_button", "icon_custom_emoji_id"]
710
+ ];
711
+ function Lt(e, t = "strict") {
594
712
  const r = typeof t == "function" ? t : (n) => {
595
- const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new Te(a, o);
713
+ const o = "param" in n ? new Me(n.method, n.param, n.version) : new qe(n.method, n.version);
596
714
  if (t === "strict")
597
- throw s;
598
- return b().forceWarn(s.message);
715
+ throw o;
716
+ J().warn(o.message);
717
+ };
718
+ return (n, ...o) => {
719
+ if (!se(n, e))
720
+ return r({ version: e, method: n });
721
+ const [a] = o;
722
+ for (const [s, p] of ct)
723
+ if (n === s && a && typeof a == "object" && p in a && !se(s, p, e))
724
+ return r({ version: e, method: n, param: p });
725
+ ge(n, ...o);
599
726
  };
600
- return (n, a) => F(n, e) ? n === "web_app_set_header_color" && O(d({ color: G() }), a) && !F(n, "color", e) ? r({ version: e, method: n, param: "color" }) : (n === "web_app_setup_main_button" || n === "web_app_setup_secondary_button") && O(d({ icon_custom_emoji_id: G() }), a) && !F(n, "icon_custom_emoji_id", e) ? r({ version: e, method: n, param: "icon_custom_emoji_id" }) : $e(n, a) : r({ version: e, method: n });
601
- }
602
- function Ge(e, t, r, n) {
603
- return l.pipe(
604
- $("web_app_invoke_custom_method", "custom_method_invoked", {
605
- ...n || {},
606
- params: { method: e, params: t, req_id: r },
607
- capture: Ve(r)
608
- }),
609
- f.chain(({ result: a, error: o }) => o ? f.left(new Me(o)) : f.right(a))
610
- );
611
- }
612
- function mt(e, t, r, n) {
613
- return re.fn(() => l.pipe(
614
- // @ts-expect-error TypeScript is unable to determine required override.
615
- Ge(e, t, r, n),
616
- f.match(
617
- (a) => {
618
- throw a;
619
- },
620
- (a) => a
621
- )
622
- )());
623
- }
624
- function De(e, t, r = {}) {
625
- const {
626
- // If no capture function was passed, we capture the first compatible event.
627
- capture: n = () => !0,
628
- postEvent: a = k
629
- } = r, o = g(), [s, p] = ee();
630
- (Array.isArray(t) ? t : [t]).forEach((i) => {
631
- s(
632
- I(i, (u) => {
633
- (Array.isArray(t) ? n({ event: i, payload: u }) : n(u)) && o.set([u]);
634
- })
635
- );
636
- });
637
- const _ = (i) => (p(), i);
638
- return l.pipe(
639
- async () => a(e, r.params),
640
- f.chainW(() => te((i, u, m) => {
641
- const w = o();
642
- if (w)
643
- return i(w[0]);
644
- const h = (y) => {
645
- y && i(y[0]);
646
- }, W = () => {
647
- o.unsub(h);
648
- };
649
- o.sub(h), m.on("finalized", W);
650
- }, r)),
651
- f.mapBoth(_, _)
652
- );
653
- }
654
- function lt(e, t, r) {
655
- const { postEvent: n } = r || {};
656
- return C(
657
- // @ts-expect-error TypeScript will not be able to handle our overrides here.
658
- De(e, t, {
659
- ...r,
660
- postEvent: n ? (...a) => {
661
- try {
662
- return n(...a), c.right(void 0);
663
- } catch (o) {
664
- return c.left(o);
665
- }
666
- } : k
667
- })
668
- );
669
- }
670
- function ft() {
671
- Object.hasOwn || (Object.hasOwn = function(e, t) {
672
- return Object.prototype.hasOwnProperty.call(e, t);
673
- });
674
- }
675
- function le(e) {
676
- return c.tryCatch(() => decodeURIComponent(
677
- atob(
678
- e.replace(/-/g, "+").replace(/_/g, "/")
679
- ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
680
- ), (t) => t);
681
- }
682
- const wt = A(le);
683
- function fe(e) {
684
- return btoa(
685
- encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
686
- ).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
687
- }
688
- function Je(e) {
689
- const t = fe(typeof e == "string" ? e : JSON.stringify(e));
690
- return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
691
- }
692
- const dt = A(Je);
693
- function bt(e, t) {
694
- return C(
695
- Ne(
696
- e,
697
- // @ts-expect-error TypeScript is unable to detect a correct override.
698
- typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
699
- )
700
- );
701
- }
702
- function Ne(e, t) {
703
- return l.pipe(
704
- le(e),
705
- c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(r))
706
- );
707
- }
708
- function gt(e) {
709
- return fe(e).length <= 512;
710
727
  }
711
728
  export {
712
- xt as CancelledError,
713
- Ce as InvalidLaunchParamsError,
714
- Me as InvokeCustomMethodFailedError,
715
- Ae as LaunchParamsRetrieveError,
716
- Se as MethodParameterUnsupportedError,
717
- Te as MethodUnsupportedError,
718
- kt as TimeoutError,
719
- ce as UnknownEnvError,
720
- ft as applyPolyfills,
721
- Ve as captureSameReq,
722
- Be as compareVersions,
723
- vt as createLogger,
724
- ut as createPostEvent,
725
- dt as createStartParam,
726
- Je as createStartParamFp,
727
- _e as debug,
728
- wt as decodeBase64Url,
729
- le as decodeBase64UrlFp,
730
- bt as decodeStartParam,
731
- Ne as decodeStartParamFp,
732
- Et as deepSnakeToCamelObjKeys,
733
- j as emitEvent,
734
- fe as encodeBase64Url,
735
- Y as getReleaseVersion,
736
- ie as hasWebviewProxy,
737
- mt as invokeCustomMethod,
738
- Ge as invokeCustomMethodFp,
739
- pe as isIframe,
740
- gt as isSafeToCreateStartParam,
741
- ct as isTMA,
742
- ze as isTMAFp,
743
- b as logger,
744
- _t as mockTelegramEnv,
745
- Oe as off,
746
- Ue as offAll,
747
- I as on,
748
- $e as postEvent,
749
- k as postEventFp,
750
- Ie as postMessage,
751
- P as postMessageImpl,
752
- lt as request,
753
- pt as request2,
754
- $ as request2Fp,
755
- De as requestFp,
756
- it as resetGlobals,
757
- rt as retrieveLaunchParams,
758
- We as retrieveLaunchParamsFp,
759
- nt as retrieveRawInitData,
760
- je as retrieveRawInitDataFp,
761
- ot as retrieveRawLaunchParams,
762
- M as retrieveRawLaunchParamsFp,
763
- at as setDebug,
764
- st as setTargetOrigin,
765
- F as supports,
766
- ue as targetOrigin
729
+ Re as InvalidLaunchParamsError,
730
+ Ie as InvokeCustomMethodFailedError,
731
+ Oe as LaunchParamsRetrieveError,
732
+ Me as MethodParameterUnsupportedError,
733
+ qe as MethodUnsupportedError,
734
+ $e as StartParamTooLongError,
735
+ ue as TimeoutError,
736
+ pe as UnknownEnvError,
737
+ nt as captureSameReq,
738
+ it as compareVersions,
739
+ Lt as createPostEvent,
740
+ rt as createRequestId,
741
+ xt as createStartParam,
742
+ at as decodeBase64Url,
743
+ kt as decodeStartParam,
744
+ gt as emitEvent,
745
+ Ee as encodeBase64Url,
746
+ h as err,
747
+ J as getLogger,
748
+ ae as getReleaseVersion,
749
+ vt as getTargetOrigin,
750
+ ve as hasWebviewProxy,
751
+ Pt as invokeCustomMethod,
752
+ dt as isDebug,
753
+ B as isIframe,
754
+ Tt as isSafeToCreateStartParam,
755
+ yt as isTMA,
756
+ Et as isTMAAsync,
757
+ qt as matchError,
758
+ St as mockTelegramEnv,
759
+ bt as offAll,
760
+ Ye as offAnyEvent,
761
+ Qe as offEvent,
762
+ f as ok,
763
+ wt as onAnyEvent,
764
+ Xe as onEvent,
765
+ De as parseLaunchParams,
766
+ ge as postEvent,
767
+ tt as request,
768
+ _t as retrieveLaunchParams,
769
+ ft as retrieveRawInitData,
770
+ Ve as retrieveRawLaunchParams,
771
+ st as safeCreateStartParam,
772
+ ot as safeInvokeCustomMethod,
773
+ le as safeParseLaunchParams,
774
+ he as safeRequest,
775
+ ze as safeRetrieveLaunchParams,
776
+ Be as safeRetrieveRawInitData,
777
+ Je as safeRetrieveRawLaunchParams,
778
+ Ce as serializeLaunchParams,
779
+ lt as setDebug,
780
+ mt as setLogger,
781
+ ht as setTargetOrigin,
782
+ se as supports,
783
+ v as throwing,
784
+ A as unwrap
767
785
  };
768
786
  //# sourceMappingURL=index.js.map