@tma.js/sdk 1.4.8 → 1.5.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 (155) hide show
  1. package/dist/dts/bridge/captureSameReq.d.ts +10 -0
  2. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +2 -2
  3. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +2 -2
  4. package/dist/dts/bridge/events/events.d.ts +13 -3
  5. package/dist/dts/bridge/events/on.d.ts +2 -3
  6. package/dist/dts/bridge/events/once.d.ts +2 -3
  7. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +2 -2
  8. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +2 -2
  9. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +1 -1
  10. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +1 -1
  11. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +1 -1
  12. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +1 -1
  13. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +2 -2
  14. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +1 -1
  15. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +1 -1
  16. package/dist/dts/bridge/events/singletonEmitter.d.ts +1 -1
  17. package/dist/dts/bridge/events/subscribe.d.ts +2 -3
  18. package/dist/dts/bridge/events/types.d.ts +4 -0
  19. package/dist/dts/bridge/invokeCustomMethod.d.ts +2 -2
  20. package/dist/dts/bridge/methods/createPostEvent.d.ts +1 -1
  21. package/dist/dts/bridge/methods/custom-methods.d.ts +1 -1
  22. package/dist/dts/bridge/methods/methods.d.ts +9 -8
  23. package/dist/dts/bridge/request.d.ts +38 -40
  24. package/dist/dts/classnames/mergeClassNames.d.ts +2 -18
  25. package/dist/dts/{back-button → components/back-button}/BackButton.d.ts +4 -4
  26. package/dist/dts/{back-button → components/back-button}/types.d.ts +2 -2
  27. package/dist/dts/{closing-behavior → components/closing-behavior}/ClosingBehavior.d.ts +6 -3
  28. package/dist/dts/{closing-behavior → components/closing-behavior}/types.d.ts +1 -1
  29. package/dist/dts/{cloud-storage → components/cloud-storage}/CloudStorage.d.ts +5 -4
  30. package/dist/dts/{haptic-feedback → components/haptic-feedback}/HapticFeedback.d.ts +4 -3
  31. package/dist/dts/components/init-data/chatParser.d.ts +6 -0
  32. package/dist/dts/components/init-data/initDataParser.d.ts +6 -0
  33. package/dist/dts/components/init-data/userParser.d.ts +6 -0
  34. package/dist/dts/{invoice → components/invoice}/Invoice.d.ts +9 -5
  35. package/dist/dts/{invoice → components/invoice}/types.d.ts +1 -1
  36. package/dist/dts/{main-button → components/main-button}/MainButton.d.ts +2 -2
  37. package/dist/dts/{main-button → components/main-button}/types.d.ts +3 -3
  38. package/dist/dts/{mini-app → components/mini-app}/MiniApp.d.ts +11 -6
  39. package/dist/dts/components/mini-app/contactParser.d.ts +2 -0
  40. package/dist/dts/{mini-app → components/mini-app}/types.d.ts +6 -5
  41. package/dist/dts/{popup → components/popup}/Popup.d.ts +8 -5
  42. package/dist/dts/{popup → components/popup}/preparePopupParams.d.ts +1 -1
  43. package/dist/dts/{popup → components/popup}/types.d.ts +1 -1
  44. package/dist/dts/{qr-scanner → components/qr-scanner}/QRScanner.d.ts +8 -5
  45. package/dist/dts/{qr-scanner → components/qr-scanner}/types.d.ts +1 -1
  46. package/dist/dts/{settings-button → components/settings-button}/SettingsButton.d.ts +4 -4
  47. package/dist/dts/{settings-button → components/settings-button}/types.d.ts +2 -2
  48. package/dist/dts/{theme-params → components/theme-params}/ThemeParams.d.ts +8 -4
  49. package/dist/dts/components/theme-params/requestThemeParams.d.ts +7 -0
  50. package/dist/dts/components/theme-params/themeParamsParser.d.ts +3 -0
  51. package/dist/dts/{theme-params → components/theme-params}/types.d.ts +2 -2
  52. package/dist/dts/{utils → components/utils}/Utils.d.ts +4 -4
  53. package/dist/dts/{viewport → components/viewport}/Viewport.d.ts +9 -5
  54. package/dist/dts/{viewport → components/viewport}/isStableViewportPlatform.d.ts +1 -1
  55. package/dist/dts/{viewport → components/viewport}/requestViewport.d.ts +2 -2
  56. package/dist/dts/{viewport → components/viewport}/types.d.ts +2 -2
  57. package/dist/dts/css/bindMiniAppCSSVars.d.ts +2 -2
  58. package/dist/dts/css/bindThemeCSSVars.d.ts +1 -1
  59. package/dist/dts/css/bindViewportCSSVars.d.ts +1 -1
  60. package/dist/dts/event-emitter/types.d.ts +1 -1
  61. package/dist/dts/globals.d.ts +1 -1
  62. package/dist/dts/index.d.ts +144 -27
  63. package/dist/dts/init/creators/createBackButton.d.ts +2 -2
  64. package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -2
  65. package/dist/dts/init/creators/createMainButton.d.ts +3 -3
  66. package/dist/dts/init/creators/createMiniApp.d.ts +5 -5
  67. package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
  68. package/dist/dts/init/creators/createSettingsButton.d.ts +2 -2
  69. package/dist/dts/init/creators/createThemeParams.d.ts +2 -1
  70. package/dist/dts/init/creators/createViewport.d.ts +3 -3
  71. package/dist/dts/init/css/processCSSVarsOption.d.ts +3 -3
  72. package/dist/dts/init/types.d.ts +16 -16
  73. package/dist/dts/launch-params/launchParamsParser.d.ts +2 -1
  74. package/dist/dts/launch-params/types.d.ts +3 -3
  75. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +6 -3
  76. package/dist/dts/navigation/HashNavigator/types.d.ts +1 -2
  77. package/dist/dts/navigation/Navigator/Navigator.d.ts +1 -1
  78. package/dist/dts/parsing/ValueParser.d.ts +1 -1
  79. package/dist/dts/parsing/parsers/array.d.ts +2 -2
  80. package/dist/dts/parsing/parsers/boolean.d.ts +2 -1
  81. package/dist/dts/parsing/parsers/date.d.ts +2 -1
  82. package/dist/dts/parsing/parsers/number.d.ts +2 -1
  83. package/dist/dts/parsing/parsers/rgb.d.ts +3 -1
  84. package/dist/dts/parsing/parsers/string.d.ts +2 -1
  85. package/dist/dts/state/State.d.ts +2 -2
  86. package/dist/dts/state/types.d.ts +1 -1
  87. package/dist/dts/storage.d.ts +2 -2
  88. package/dist/dts/supports/createSupportsFunc.d.ts +2 -2
  89. package/dist/dts/supports/createSupportsParamFunc.d.ts +2 -2
  90. package/dist/dts/supports/supports.d.ts +2 -2
  91. package/dist/dts/supports/types.d.ts +3 -0
  92. package/dist/dts/timeout/withTimeout.d.ts +2 -2
  93. package/dist/dts/types/logical.d.ts +16 -0
  94. package/dist/dts/types/methods.d.ts +1 -1
  95. package/dist/dts/types/unions.d.ts +20 -0
  96. package/dist/dts/types/utils.d.ts +0 -28
  97. package/dist/dts/version/compareVersions.d.ts +2 -1
  98. package/dist/dts/version/types.d.ts +1 -0
  99. package/dist/index.cjs +1 -1
  100. package/dist/index.iife.js +1 -1
  101. package/dist/index.mjs +1714 -1702
  102. package/package.json +1 -1
  103. package/dist/dts/back-button/index.d.ts +0 -2
  104. package/dist/dts/bridge/env/index.d.ts +0 -2
  105. package/dist/dts/bridge/errors/index.d.ts +0 -2
  106. package/dist/dts/bridge/events/index.d.ts +0 -9
  107. package/dist/dts/bridge/events/parsers/index.d.ts +0 -9
  108. package/dist/dts/bridge/index.d.ts +0 -7
  109. package/dist/dts/bridge/methods/index.d.ts +0 -6
  110. package/dist/dts/classnames/index.d.ts +0 -2
  111. package/dist/dts/closing-behavior/index.d.ts +0 -2
  112. package/dist/dts/cloud-storage/index.d.ts +0 -1
  113. package/dist/dts/colors/index.d.ts +0 -5
  114. package/dist/dts/css/index.d.ts +0 -4
  115. package/dist/dts/event-emitter/index.d.ts +0 -2
  116. package/dist/dts/haptic-feedback/index.d.ts +0 -1
  117. package/dist/dts/init/creators/index.d.ts +0 -8
  118. package/dist/dts/init/css/index.d.ts +0 -1
  119. package/dist/dts/init/index.d.ts +0 -2
  120. package/dist/dts/init-data/chatParser.d.ts +0 -5
  121. package/dist/dts/init-data/index.d.ts +0 -6
  122. package/dist/dts/init-data/initDataParser.d.ts +0 -5
  123. package/dist/dts/init-data/userParser.d.ts +0 -5
  124. package/dist/dts/invoice/index.d.ts +0 -2
  125. package/dist/dts/launch-params/index.d.ts +0 -10
  126. package/dist/dts/logger/index.d.ts +0 -1
  127. package/dist/dts/main-button/index.d.ts +0 -2
  128. package/dist/dts/mini-app/contactParser.d.ts +0 -2
  129. package/dist/dts/mini-app/index.d.ts +0 -2
  130. package/dist/dts/misc/index.d.ts +0 -5
  131. package/dist/dts/navigation/HashNavigator/index.d.ts +0 -2
  132. package/dist/dts/navigation/Navigator/index.d.ts +0 -2
  133. package/dist/dts/navigation/index.d.ts +0 -4
  134. package/dist/dts/parsing/index.d.ts +0 -10
  135. package/dist/dts/parsing/parsers/index.d.ts +0 -8
  136. package/dist/dts/popup/index.d.ts +0 -2
  137. package/dist/dts/qr-scanner/index.d.ts +0 -2
  138. package/dist/dts/settings-button/index.d.ts +0 -2
  139. package/dist/dts/state/index.d.ts +0 -2
  140. package/dist/dts/supports/index.d.ts +0 -4
  141. package/dist/dts/theme-params/index.d.ts +0 -6
  142. package/dist/dts/theme-params/requestThemeParams.d.ts +0 -7
  143. package/dist/dts/theme-params/themeParamsParser.d.ts +0 -2
  144. package/dist/dts/timeout/index.d.ts +0 -4
  145. package/dist/dts/types/index.d.ts +0 -4
  146. package/dist/dts/utils/index.d.ts +0 -1
  147. package/dist/dts/version/index.d.ts +0 -2
  148. package/dist/dts/viewport/index.d.ts +0 -4
  149. /package/dist/dts/{init-data → components/init-data}/InitData.d.ts +0 -0
  150. /package/dist/dts/{init-data → components/init-data}/parseInitData.d.ts +0 -0
  151. /package/dist/dts/{init-data → components/init-data}/types.d.ts +0 -0
  152. /package/dist/dts/{theme-params → components/theme-params}/keys.d.ts +0 -0
  153. /package/dist/dts/{theme-params → components/theme-params}/parseThemeParams.d.ts +0 -0
  154. /package/dist/dts/{theme-params → components/theme-params}/serializeThemeParams.d.ts +0 -0
  155. /package/dist/dts/{viewport → components/viewport}/utils.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -1,8 +1,75 @@
1
1
  var Re = Object.defineProperty;
2
2
  var Ie = (r, e, t) => e in r ? Re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var o = (r, e, t) => (Ie(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- function ue() {
5
- return performance.getEntriesByType("navigation")[0];
4
+ class he {
5
+ constructor(e, t) {
6
+ this.prefix = e, this.enabled = t;
7
+ }
8
+ /**
9
+ * Prints message into a console in case, logger is currently enabled.
10
+ * @param level - log level.
11
+ * @param args - arguments.
12
+ */
13
+ print(e, ...t) {
14
+ if (!this.enabled)
15
+ return;
16
+ const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
17
+ hour: "2-digit",
18
+ minute: "2-digit",
19
+ second: "2-digit",
20
+ fractionalSecondDigits: 3,
21
+ timeZone: "UTC"
22
+ }).format(s);
23
+ console[e](`[${n}]`, this.prefix, ...t);
24
+ }
25
+ /**
26
+ * Disables the logger.
27
+ */
28
+ disable() {
29
+ this.enabled = !1;
30
+ }
31
+ /**
32
+ * Prints error message into a console.
33
+ * @param args
34
+ */
35
+ error(...e) {
36
+ this.print("error", ...e);
37
+ }
38
+ /**
39
+ * Enables the logger.
40
+ */
41
+ enable() {
42
+ this.enabled = !0;
43
+ }
44
+ /**
45
+ * Prints log message into a console.
46
+ * @param args
47
+ */
48
+ log(...e) {
49
+ this.print("log", ...e);
50
+ }
51
+ /**
52
+ * Prints warning message into a console.
53
+ * @param args
54
+ */
55
+ warn(...e) {
56
+ this.print("warn", ...e);
57
+ }
58
+ }
59
+ let ue = "https://web.telegram.org";
60
+ const k = new he("[SDK]", !1);
61
+ function Qt(r) {
62
+ if (r) {
63
+ k.enable();
64
+ return;
65
+ }
66
+ k.disable();
67
+ }
68
+ function Zt(r) {
69
+ ue = r;
70
+ }
71
+ function Te() {
72
+ return ue;
6
73
  }
7
74
  function pe() {
8
75
  try {
@@ -11,74 +78,121 @@ function pe() {
11
78
  return !0;
12
79
  }
13
80
  }
14
- function le() {
15
- var r;
16
- return ((r = ue()) == null ? void 0 : r.type) === "reload";
17
- }
18
- function R(r) {
81
+ function M(r) {
19
82
  return typeof r == "object" && r !== null && !Array.isArray(r);
20
83
  }
21
- function L() {
22
- return new TypeError("Value has unexpected type");
84
+ function $e(r) {
85
+ return "external" in r && M(r.external) && "notify" in r.external && typeof r.external.notify == "function";
23
86
  }
24
- class F extends Error {
25
- constructor(t, { cause: s, type: n } = {}) {
26
- super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
27
- /**
28
- * Parser name.
29
- */
30
- o(this, "type");
31
- this.value = t, Object.setPrototypeOf(this, F.prototype), this.type = n;
32
- }
87
+ function Le(r) {
88
+ return "TelegramWebviewProxy" in r && M(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
33
89
  }
34
- class z {
35
- constructor(e, t, s) {
36
- this.parser = e, this.isOptional = t, this.type = s;
90
+ function d(r, e, t) {
91
+ let s = {}, n;
92
+ e === void 0 && t === void 0 ? s = {} : e !== void 0 && t !== void 0 ? (s = t, n = e) : e !== void 0 && ("targetOrigin" in e ? s = e : n = e);
93
+ const { targetOrigin: i = Te() } = s;
94
+ if (k.log(`Calling method "${r}"`, n), pe()) {
95
+ window.parent.postMessage(JSON.stringify({
96
+ eventType: r,
97
+ eventData: n
98
+ }), i);
99
+ return;
37
100
  }
38
- parse(e) {
39
- if (!(this.isOptional && e === void 0))
40
- try {
41
- return this.parser(e);
42
- } catch (t) {
43
- throw new F(e, { type: this.type, cause: t });
44
- }
101
+ if ($e(window)) {
102
+ window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
103
+ return;
45
104
  }
46
- optional() {
47
- return this.isOptional = !0, this;
105
+ if (Le(window)) {
106
+ window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
107
+ return;
48
108
  }
109
+ throw new Error(
110
+ "Unable to determine current environment and possible way to send event."
111
+ );
49
112
  }
50
- function Le(r) {
51
- if (Array.isArray(r))
52
- return r;
53
- if (typeof r == "string")
54
- try {
55
- const e = JSON.parse(r);
56
- if (Array.isArray(e))
57
- return e;
58
- } catch {
59
- }
60
- throw L();
113
+ function Be(r, e) {
114
+ const t = r.split("."), s = e.split("."), n = Math.max(t.length, s.length);
115
+ for (let i = 0; i < n; i += 1) {
116
+ const a = parseInt(t[i] || "0", 10), c = parseInt(s[i] || "0", 10);
117
+ if (a !== c)
118
+ return a > c ? 1 : -1;
119
+ }
120
+ return 0;
61
121
  }
62
- class Te extends z {
63
- constructor(t, s, n) {
64
- super(Le, s, n);
65
- o(this, "itemParser");
66
- this.itemParser = typeof t == "function" ? t : t.parse.bind(t);
122
+ function v(r, e) {
123
+ return Be(r, e) <= 0;
124
+ }
125
+ function A(r, e, t) {
126
+ if (typeof t == "string") {
127
+ if (r === "web_app_open_link" && e === "try_instant_view")
128
+ return v("6.4", t);
129
+ if (r === "web_app_set_header_color" && e === "color")
130
+ return v("6.9", t);
67
131
  }
68
- parse(t) {
69
- const s = super.parse(t);
70
- return s === void 0 ? s : s.map(this.itemParser);
132
+ switch (r) {
133
+ case "web_app_open_tg_link":
134
+ case "web_app_open_invoice":
135
+ case "web_app_setup_back_button":
136
+ case "web_app_set_background_color":
137
+ case "web_app_set_header_color":
138
+ case "web_app_trigger_haptic_feedback":
139
+ return v("6.1", e);
140
+ case "web_app_open_popup":
141
+ return v("6.2", e);
142
+ case "web_app_close_scan_qr_popup":
143
+ case "web_app_open_scan_qr_popup":
144
+ case "web_app_read_text_from_clipboard":
145
+ return v("6.4", e);
146
+ case "web_app_switch_inline_query":
147
+ return v("6.7", e);
148
+ case "web_app_invoke_custom_method":
149
+ case "web_app_request_write_access":
150
+ case "web_app_request_phone":
151
+ return v("6.9", e);
152
+ case "web_app_setup_settings_button":
153
+ return v("6.10", e);
154
+ default:
155
+ return !0;
71
156
  }
72
- of(t) {
73
- return this.itemParser = typeof t == "function" ? t : t.parse.bind(t), this;
157
+ }
158
+ class Z extends Error {
159
+ constructor(e, t) {
160
+ super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`), Object.setPrototypeOf(this, Z.prototype);
74
161
  }
75
162
  }
76
- function T(r, e) {
77
- return () => new z(r, !1, e);
163
+ class K extends Error {
164
+ constructor(e, t, s) {
165
+ super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, K.prototype);
166
+ }
167
+ }
168
+ function Oe(r) {
169
+ return (e, t) => {
170
+ if (!A(e, r))
171
+ throw new Z(e, r);
172
+ if (M(t)) {
173
+ let s;
174
+ if (e === "web_app_open_link" && "try_instant_view" in t ? s = "try_instant_view" : e === "web_app_set_header_color" && "color" in t && (s = "color"), s && !A(e, s, r))
175
+ throw new K(e, s, r);
176
+ }
177
+ return d(e, t);
178
+ };
179
+ }
180
+ function le(r) {
181
+ return ({ req_id: e }) => e === r;
182
+ }
183
+ class G extends Error {
184
+ constructor(t, { cause: s, type: n } = {}) {
185
+ super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
186
+ /**
187
+ * Parser name.
188
+ */
189
+ o(this, "type");
190
+ this.value = t, Object.setPrototypeOf(this, G.prototype), this.type = n;
191
+ }
78
192
  }
79
- class j extends Error {
193
+ class U extends Error {
80
194
  constructor(e, { cause: t, type: s } = {}) {
81
- super(`Unable to parse field "${e}"${s ? ` as ${s}` : ""}`, { cause: t }), Object.setPrototypeOf(this, j.prototype);
195
+ super(`Unable to parse field "${e}"${s ? ` as ${s}` : ""}`, { cause: t }), Object.setPrototypeOf(this, U.prototype);
82
196
  }
83
197
  }
84
198
  function de(r, e) {
@@ -99,279 +213,191 @@ function de(r, e) {
99
213
  try {
100
214
  c = a(u);
101
215
  } catch (p) {
102
- throw p instanceof F ? new j(i, {
216
+ throw p instanceof G ? new U(i, {
103
217
  type: p.type,
104
218
  cause: p
105
- }) : new j(i, { cause: p });
219
+ }) : new U(i, { cause: p });
106
220
  }
107
221
  c !== void 0 && (t[s] = c);
108
222
  }
109
223
  return t;
110
224
  }
111
- function $e(r) {
112
- return new Te((e) => e, !1, r);
225
+ function V() {
226
+ return new TypeError("Value has unexpected type");
113
227
  }
114
- const k = T((r) => {
115
- if (typeof r == "boolean")
116
- return r;
117
- const e = String(r);
118
- if (e === "1" || e === "true")
119
- return !0;
120
- if (e === "0" || e === "false")
121
- return !1;
122
- throw L();
123
- }, "boolean"), A = T((r) => {
124
- if (typeof r == "number")
125
- return r;
126
- if (typeof r == "string") {
127
- const e = Number(r);
128
- if (!Number.isNaN(e))
129
- return e;
130
- }
131
- throw L();
132
- }, "number"), fe = T((r) => r instanceof Date ? r : new Date(A().parse(r) * 1e3), "Date");
133
228
  function Y(r) {
134
229
  let e = r;
135
230
  if (typeof e == "string" && (e = JSON.parse(e)), typeof e != "object" || e === null || Array.isArray(e))
136
- throw L();
231
+ throw V();
137
232
  return e;
138
233
  }
234
+ class j {
235
+ constructor(e, t, s) {
236
+ this.parser = e, this.isOptional = t, this.type = s;
237
+ }
238
+ parse(e) {
239
+ if (!(this.isOptional && e === void 0))
240
+ try {
241
+ return this.parser(e);
242
+ } catch (t) {
243
+ throw new G(e, { type: this.type, cause: t });
244
+ }
245
+ }
246
+ optional() {
247
+ return this.isOptional = !0, this;
248
+ }
249
+ }
139
250
  function f(r, e) {
140
- return new z((t) => {
251
+ return new j((t) => {
141
252
  const s = Y(t);
142
253
  return de(r, (n) => s[n]);
143
254
  }, !1, e);
144
255
  }
145
- function X(r) {
146
- return /^#[\da-f]{6}$/i.test(r);
147
- }
148
- function Be(r) {
149
- return /^#[\da-f]{3}$/i.test(r);
150
- }
151
- function ge(r) {
152
- const e = r.replace(/\s/g, "").toLowerCase();
153
- if (X(e))
154
- return e;
155
- if (Be(e)) {
156
- let s = "#";
157
- for (let n = 0; n < 3; n += 1)
158
- s += e[1 + n].repeat(2);
159
- return s;
160
- }
161
- const t = e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
162
- if (t === null)
163
- throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
164
- return t.slice(1).reduce((s, n) => {
165
- const i = parseInt(n, 10).toString(16);
166
- return s + (i.length === 1 ? "0" : "") + i;
167
- }, "#");
168
- }
169
- function we(r) {
170
- const e = ge(r);
171
- return Math.sqrt(
172
- [0.299, 0.587, 0.114].reduce((s, n, i) => {
173
- const a = parseInt(e.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
174
- return s + a * a * n;
175
- }, 0)
176
- ) < 120;
256
+ function R(r, e) {
257
+ return () => new j(r, !1, e);
177
258
  }
178
- const h = T((r) => {
259
+ const h = R((r) => {
179
260
  if (typeof r == "string" || typeof r == "number")
180
261
  return r.toString();
181
- throw L();
182
- }, "string"), _e = T((r) => ge(h().parse(r)), "rgb");
183
- function ee(r, e) {
184
- return new z((t) => {
185
- if (typeof t != "string" && !(t instanceof URLSearchParams))
186
- throw L();
187
- const s = typeof t == "string" ? new URLSearchParams(t) : t;
188
- return de(r, (n) => {
189
- const i = s.get(n);
190
- return i === null ? void 0 : i;
191
- });
192
- }, !1, e);
193
- }
194
- function De() {
262
+ throw V();
263
+ }, "string");
264
+ function De(r) {
195
265
  return f({
196
- id: A(),
197
- type: h(),
198
- title: h(),
199
- photoUrl: {
200
- type: h().optional(),
201
- from: "photo_url"
202
- },
203
- username: h().optional()
204
- }, "Chat");
266
+ eventType: h(),
267
+ eventData: (e) => e
268
+ }).parse(r);
205
269
  }
206
- class We {
207
- constructor(e) {
208
- this.initData = e;
209
- }
210
- /**
211
- * @see InitDataParsed.authDate
212
- */
213
- get authDate() {
214
- return this.initData.authDate;
215
- }
216
- /**
217
- * @see InitDataParsed.canSendAfter
218
- */
219
- get canSendAfter() {
220
- return this.initData.canSendAfter;
221
- }
222
- /**
223
- * Date after which it is allowed to call
224
- * the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
225
- */
226
- get canSendAfterDate() {
227
- const { canSendAfter: e } = this;
228
- return e === void 0 ? void 0 : new Date(this.authDate.getTime() + e * 1e3);
229
- }
230
- /**
231
- * @see InitDataParsed.chat
232
- */
233
- get chat() {
234
- return this.initData.chat;
235
- }
236
- /**
237
- * @see InitDataParsed.chatType
238
- */
239
- get chatType() {
240
- return this.initData.chatType;
241
- }
242
- /**
243
- * @see InitDataParsed.chatInstance
244
- */
245
- get chatInstance() {
246
- return this.initData.chatInstance;
247
- }
248
- /**
249
- * @see InitDataParsed.hash
250
- */
251
- get hash() {
252
- return this.initData.hash;
253
- }
254
- /**
255
- * @see InitDataParsed.queryId
256
- */
257
- get queryId() {
258
- return this.initData.queryId;
259
- }
260
- /**
261
- * @see InitDataParsed.receiver
262
- */
263
- get receiver() {
264
- return this.initData.receiver;
265
- }
266
- /**
267
- * @see InitDataParsed.startParam
268
- */
269
- get startParam() {
270
- return this.initData.startParam;
271
- }
272
- /**
273
- * @see InitDataParsed.user
274
- */
275
- get user() {
276
- return this.initData.user;
277
- }
270
+ function We(r, e) {
271
+ window.dispatchEvent(new MessageEvent("message", {
272
+ data: JSON.stringify({ eventType: r, eventData: e }),
273
+ // We specify window.parent to imitate the case, it sent us this event.
274
+ source: window.parent
275
+ }));
276
+ }
277
+ function He() {
278
+ const r = window;
279
+ "TelegramGameProxy_receiveEvent" in r || [
280
+ ["TelegramGameProxy_receiveEvent"],
281
+ // Windows Phone.
282
+ ["TelegramGameProxy", "receiveEvent"],
283
+ // Desktop.
284
+ ["Telegram", "WebView", "receiveEvent"]
285
+ // Android and iOS.
286
+ ].forEach((e) => {
287
+ let t = r;
288
+ e.forEach((s, n, i) => {
289
+ if (n === i.length - 1) {
290
+ t[s] = We;
291
+ return;
292
+ }
293
+ s in t || (t[s] = {}), t = t[s];
294
+ });
295
+ });
296
+ }
297
+ function Ne(r) {
298
+ He(), window.addEventListener("message", (e) => {
299
+ if (e.source === window.parent)
300
+ try {
301
+ const { eventType: t, eventData: s } = De(e.data);
302
+ r(t, s);
303
+ } catch {
304
+ }
305
+ });
278
306
  }
279
- function ne() {
307
+ function Ue() {
280
308
  return f({
281
- addedToAttachmentMenu: {
282
- type: k().optional(),
283
- from: "added_to_attachment_menu"
284
- },
285
- allowsWriteToPm: {
286
- type: k().optional(),
287
- from: "allows_write_to_pm"
288
- },
289
- firstName: {
290
- type: h(),
291
- from: "first_name"
292
- },
293
- id: A(),
294
- isBot: {
295
- type: k().optional(),
296
- from: "is_bot"
297
- },
298
- isPremium: {
299
- type: k().optional(),
300
- from: "is_premium"
301
- },
302
- languageCode: {
303
- type: h().optional(),
304
- from: "language_code"
305
- },
306
- lastName: {
307
- type: h().optional(),
308
- from: "last_name"
309
- },
310
- photoUrl: {
311
- type: h().optional(),
312
- from: "photo_url"
313
- },
314
- username: h().optional()
315
- }, "User");
309
+ req_id: h(),
310
+ data: (r) => r === null ? r : h().optional().parse(r)
311
+ });
316
312
  }
317
- function be() {
318
- return ee({
319
- authDate: {
320
- type: fe(),
321
- from: "auth_date"
322
- },
323
- canSendAfter: {
324
- type: A().optional(),
325
- from: "can_send_after"
326
- },
327
- chat: De().optional(),
328
- chatInstance: {
329
- type: h().optional(),
330
- from: "chat_instance"
331
- },
332
- chatType: {
333
- type: h().optional(),
334
- from: "chat_type"
335
- },
336
- hash: h(),
337
- queryId: {
338
- type: h().optional(),
339
- from: "query_id"
340
- },
341
- receiver: ne().optional(),
342
- startParam: {
343
- type: h().optional(),
344
- from: "start_param"
345
- },
346
- user: ne().optional()
347
- }, "InitData");
313
+ function Me() {
314
+ return f({
315
+ req_id: h(),
316
+ result: (r) => r,
317
+ error: h().optional()
318
+ });
348
319
  }
349
- function Zt(r) {
350
- return be().parse(r);
320
+ function Ge() {
321
+ return f({
322
+ slug: h(),
323
+ status: h()
324
+ });
351
325
  }
352
- function Oe(r) {
353
- return r.replace(/(^|_)bg/, (e, t) => `${t}background`).replace(/_([a-z])/g, (e, t) => t.toUpperCase());
326
+ function je() {
327
+ return f({ status: h() });
354
328
  }
355
- function He(r) {
356
- return r.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`).replace(/(^|_)background/, (e, t) => `${t}bg`);
329
+ function Fe() {
330
+ return f({
331
+ button_id: (r) => r == null ? void 0 : h().parse(r)
332
+ });
357
333
  }
358
- const me = T(
359
- (r) => {
360
- const e = _e().optional();
361
- return Object.entries(Y(r)).reduce((t, [s, n]) => (t[Oe(s)] = e.parse(n), t), {});
362
- },
363
- "ThemeParams"
364
- );
365
- function ye(r) {
366
- return me().parse(r);
334
+ function ze() {
335
+ return f({
336
+ data: h().optional()
337
+ });
338
+ }
339
+ function X(r) {
340
+ return /^#[\da-f]{6}$/i.test(r);
367
341
  }
368
- function Kt(r = {}) {
369
- return m("web_app_request_theme", "theme_changed", r).then(ye);
342
+ function Je(r) {
343
+ return /^#[\da-f]{3}$/i.test(r);
370
344
  }
371
- function Ne(r) {
372
- return JSON.stringify(
373
- Object.entries(r).reduce((e, [t, s]) => (s && (e[He(t)] = s), e), {})
374
- );
345
+ function fe(r) {
346
+ const e = r.replace(/\s/g, "").toLowerCase();
347
+ if (X(e))
348
+ return e;
349
+ if (Je(e)) {
350
+ let s = "#";
351
+ for (let n = 0; n < 3; n += 1)
352
+ s += e[1 + n].repeat(2);
353
+ return s;
354
+ }
355
+ const t = e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
356
+ if (t === null)
357
+ throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
358
+ return t.slice(1).reduce((s, n) => {
359
+ const i = parseInt(n, 10).toString(16);
360
+ return s + (i.length === 1 ? "0" : "") + i;
361
+ }, "#");
362
+ }
363
+ const ge = R((r) => fe(h().parse(r)), "rgb");
364
+ function Qe() {
365
+ return f({
366
+ theme_params: (r) => {
367
+ const e = ge().optional();
368
+ return Object.entries(Y(r)).reduce((t, [s, n]) => (t[s] = e.parse(n), t), {});
369
+ }
370
+ });
371
+ }
372
+ const P = R((r) => {
373
+ if (typeof r == "boolean")
374
+ return r;
375
+ const e = String(r);
376
+ if (e === "1" || e === "true")
377
+ return !0;
378
+ if (e === "0" || e === "false")
379
+ return !1;
380
+ throw V();
381
+ }, "boolean"), x = R((r) => {
382
+ if (typeof r == "number")
383
+ return r;
384
+ if (typeof r == "string") {
385
+ const e = Number(r);
386
+ if (!Number.isNaN(e))
387
+ return e;
388
+ }
389
+ throw V();
390
+ }, "number");
391
+ function Ze() {
392
+ return f({
393
+ height: x(),
394
+ width: (r) => r == null ? window.innerWidth : x().parse(r),
395
+ is_state_stable: P(),
396
+ is_expanded: P()
397
+ });
398
+ }
399
+ function Ke() {
400
+ return f({ status: h() });
375
401
  }
376
402
  class w {
377
403
  constructor() {
@@ -455,421 +481,9 @@ class w {
455
481
  }
456
482
  }
457
483
  }
458
- class b {
459
- constructor(e, t) {
460
- this.state = e, this.ee = t;
461
- }
462
- internalSet(e, t) {
463
- return this.state[e] === t || t === void 0 ? !1 : (this.state[e] = t, this.ee.emit(`change:${e}`, t), !0);
464
- }
465
- /**
466
- * Returns copy of current state.
467
- */
468
- clone() {
469
- return { ...this.state };
470
- }
471
- set(e, t) {
472
- let s = !1;
473
- if (typeof e == "string")
474
- s = this.internalSet(e, t);
475
- else
476
- for (const n in e)
477
- this.internalSet(n, e[n]) && (s = !0);
478
- s && this.ee.emit("change");
479
- }
480
- /**
481
- * Returns value by specified key.
482
- * @param key - state key.
483
- */
484
- get(e) {
485
- return this.state[e];
486
- }
487
- }
488
- class Ue {
489
- constructor(e) {
490
- o(this, "ee", new w());
491
- o(this, "state");
492
- /**
493
- * Adds new event listener.
494
- */
495
- o(this, "on", this.ee.on.bind(this.ee));
496
- /**
497
- * Removes event listener.
498
- */
499
- o(this, "off", this.ee.off.bind(this.ee));
500
- this.state = new b(e, this.ee);
501
- }
502
- /**
503
- * @since v6.10
504
- */
505
- get accentTextColor() {
506
- return this.get("accentTextColor");
507
- }
508
- get backgroundColor() {
509
- return this.get("backgroundColor");
510
- }
511
- get buttonColor() {
512
- return this.get("buttonColor");
513
- }
514
- get buttonTextColor() {
515
- return this.get("buttonTextColor");
516
- }
517
- get destructiveTextColor() {
518
- return this.get("destructiveTextColor");
519
- }
520
- /**
521
- * Retrieves palette color value by its name.
522
- * @param key - palette key name.
523
- */
524
- get(e) {
525
- return this.state.get(e);
526
- }
527
- /**
528
- * Returns the copy of the internal state of the current component instance.
529
- */
530
- getState() {
531
- return this.state.clone();
532
- }
533
- /**
534
- * @since v6.10
535
- */
536
- get headerBackgroundColor() {
537
- return this.get("headerBackgroundColor");
538
- }
539
- get hintColor() {
540
- return this.get("hintColor");
541
- }
542
- /**
543
- * Returns true in case, current color scheme is recognized as dark. This
544
- * value is calculated according to theme background color.
545
- */
546
- get isDark() {
547
- return !this.backgroundColor || we(this.backgroundColor);
548
- }
549
- get linkColor() {
550
- return this.get("linkColor");
551
- }
552
- get secondaryBackgroundColor() {
553
- return this.get("secondaryBackgroundColor");
554
- }
555
- /**
556
- * @since v6.10
557
- */
558
- get sectionBackgroundColor() {
559
- return this.get("sectionBackgroundColor");
560
- }
561
- /**
562
- * @since v6.10
563
- */
564
- get sectionHeaderTextColor() {
565
- return this.get("sectionHeaderTextColor");
566
- }
567
- /**
568
- * Starts listening to theme changes and applies them.
569
- * @returns Function to stop listening.
570
- */
571
- listen() {
572
- return y("theme_changed", (e) => {
573
- this.state.set(ye(e.theme_params));
574
- });
575
- }
576
- /**
577
- * @since v6.10
578
- */
579
- get subtitleTextColor() {
580
- return this.get("subtitleTextColor");
581
- }
582
- get textColor() {
583
- return this.get("textColor");
584
- }
585
- }
586
- function Me() {
587
- return ee({
588
- botInline: {
589
- type: k().optional(),
590
- from: "tgWebAppBotInline"
591
- },
592
- initData: {
593
- type: be().optional(),
594
- from: "tgWebAppData"
595
- },
596
- initDataRaw: {
597
- type: h().optional(),
598
- from: "tgWebAppData"
599
- },
600
- platform: {
601
- type: h(),
602
- from: "tgWebAppPlatform"
603
- },
604
- showSettings: {
605
- type: k().optional(),
606
- from: "tgWebAppShowSettings"
607
- },
608
- startParam: {
609
- type: h().optional(),
610
- from: "tgWebAppStartParam"
611
- },
612
- themeParams: {
613
- type: me(),
614
- from: "tgWebAppThemeParams"
615
- },
616
- version: {
617
- type: h(),
618
- from: "tgWebAppVersion"
619
- }
620
- }, "LaunchParams");
621
- }
622
- function Ee(r) {
623
- return Me().parse(r);
624
- }
625
- function Ce(r) {
626
- const e = r.includes("?") ? r.replace("#", "&").slice(r.indexOf("?") + 1) : r.slice(r.indexOf("#") + 1);
627
- return Ee(e);
628
- }
629
- function Ge() {
630
- return Ce(window.location.href);
631
- }
632
- function je() {
633
- const r = ue();
634
- if (!r)
635
- throw new Error("Unable to get first navigation entry.");
636
- return Ce(r.name);
637
- }
638
- class ve {
639
- constructor(e, t) {
640
- this.prefix = e, this.enabled = t;
641
- }
642
- /**
643
- * Prints message into a console in case, logger is currently enabled.
644
- * @param level - log level.
645
- * @param args - arguments.
646
- */
647
- print(e, ...t) {
648
- if (!this.enabled)
649
- return;
650
- const s = /* @__PURE__ */ new Date(), n = Intl.DateTimeFormat("en-GB", {
651
- hour: "2-digit",
652
- minute: "2-digit",
653
- second: "2-digit",
654
- fractionalSecondDigits: 3,
655
- timeZone: "UTC"
656
- }).format(s);
657
- console[e](`[${n}]`, this.prefix, ...t);
658
- }
659
- /**
660
- * Disables the logger.
661
- */
662
- disable() {
663
- this.enabled = !1;
664
- }
665
- /**
666
- * Prints error message into a console.
667
- * @param args
668
- */
669
- error(...e) {
670
- this.print("error", ...e);
671
- }
672
- /**
673
- * Enables the logger.
674
- */
675
- enable() {
676
- this.enabled = !0;
677
- }
678
- /**
679
- * Prints log message into a console.
680
- * @param args
681
- */
682
- log(...e) {
683
- this.print("log", ...e);
684
- }
685
- /**
686
- * Prints warning message into a console.
687
- * @param args
688
- */
689
- warn(...e) {
690
- this.print("warn", ...e);
691
- }
692
- }
693
- let Pe = "https://web.telegram.org";
694
- const q = new ve("[SDK]", !1);
695
- function Yt(r) {
696
- if (r) {
697
- q.enable();
698
- return;
699
- }
700
- q.disable();
701
- }
702
- function Xt(r) {
703
- Pe = r;
704
- }
705
- function Fe() {
706
- return Pe;
707
- }
708
- function ze(r) {
709
- const {
710
- initDataRaw: e,
711
- themeParams: t,
712
- platform: s,
713
- version: n,
714
- showSettings: i,
715
- startParam: a,
716
- botInline: c
717
- } = r, u = new URLSearchParams();
718
- return e && u.set("tgWebAppData", e), u.set("tgWebAppPlatform", s), u.set("tgWebAppThemeParams", Ne(t)), u.set("tgWebAppVersion", n), a && u.set("tgWebAppStartParam", n), typeof i == "boolean" && u.set("tgWebAppShowSettings", i ? "1" : "0"), typeof c == "boolean" && u.set("tgWebAppBotInline", c ? "1" : "0"), u.toString();
719
- }
720
- const ke = "telegram-mini-apps-launch-params";
721
- function Je() {
722
- return Ee(sessionStorage.getItem(ke) || "");
723
- }
724
- function Qe(r) {
725
- sessionStorage.setItem(ke, ze(r));
726
- }
727
- function te() {
728
- const r = [];
729
- for (const e of [
730
- // Try to retrieve launch parameters from the current location. This method can return
731
- // nothing in case, location was changed and then page was reloaded.
732
- Ge,
733
- // Then, try using the lower level API - window.performance.
734
- je,
735
- // Finally, try to extract launch parameters from the session storage.
736
- Je
737
- ])
738
- try {
739
- const t = e();
740
- return Qe(t), t;
741
- } catch (t) {
742
- r.push(t);
743
- }
744
- throw q.error("Unable to extract launch parameters. Received errors:", r), new Error("Unable to retrieve launch parameters from any known source.");
745
- }
746
- function er() {
747
- return {
748
- launchParams: te(),
749
- isPageReload: le()
750
- };
751
- }
752
- function tr() {
753
- try {
754
- return te(), !0;
755
- } catch {
756
- return !1;
757
- }
758
- }
759
- function Ze(r) {
760
- return "external" in r && R(r.external) && "notify" in r.external && typeof r.external.notify == "function";
761
- }
762
- function Ke(r) {
763
- return "TelegramWebviewProxy" in r && R(r.TelegramWebviewProxy) && "postEvent" in r.TelegramWebviewProxy && typeof r.TelegramWebviewProxy.postEvent == "function";
764
- }
765
- class re extends Error {
766
- constructor(e, t) {
767
- super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`), Object.setPrototypeOf(this, re.prototype);
768
- }
769
- }
770
- class se extends Error {
771
- constructor(e, t, s) {
772
- super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, se.prototype);
773
- }
774
- }
775
- const Ye = f({
776
- eventType: h(),
777
- eventData: (r) => r
778
- });
779
- function Xe(r) {
780
- return Ye.parse(r);
781
- }
782
- function et(r, e) {
783
- window.dispatchEvent(new MessageEvent("message", {
784
- data: JSON.stringify({ eventType: r, eventData: e }),
785
- // We specify window.parent to imitate the case, it sent us this event.
786
- source: window.parent
787
- }));
788
- }
789
- function tt() {
790
- const r = window;
791
- "TelegramGameProxy_receiveEvent" in r || [
792
- ["TelegramGameProxy_receiveEvent"],
793
- // Windows Phone.
794
- ["TelegramGameProxy", "receiveEvent"],
795
- // Desktop.
796
- ["Telegram", "WebView", "receiveEvent"]
797
- // Android and iOS.
798
- ].forEach((e) => {
799
- let t = r;
800
- e.forEach((s, n, i) => {
801
- if (n === i.length - 1) {
802
- t[s] = et;
803
- return;
804
- }
805
- s in t || (t[s] = {}), t = t[s];
806
- });
807
- });
808
- }
809
- function rt(r) {
810
- tt(), window.addEventListener("message", (e) => {
811
- if (e.source === window.parent)
812
- try {
813
- const { eventType: t, eventData: s } = Xe(e.data);
814
- r(t, s);
815
- } catch {
816
- }
817
- });
818
- }
819
- function st() {
820
- return f({
821
- req_id: h(),
822
- data: (r) => r === null ? r : h().optional().parse(r)
823
- });
824
- }
825
- function nt() {
826
- return f({
827
- req_id: h(),
828
- result: (r) => r,
829
- error: h().optional()
830
- });
831
- }
832
- function it() {
833
- return f({
834
- slug: h(),
835
- status: h()
836
- });
837
- }
838
- function ot() {
839
- return f({ status: h() });
840
- }
841
- function at() {
842
- return f({
843
- button_id: (r) => r == null ? void 0 : h().parse(r)
844
- });
845
- }
846
- function ct() {
847
- return f({
848
- data: h().optional()
849
- });
850
- }
851
- function ht() {
852
- return f({
853
- theme_params: (r) => {
854
- const e = _e().optional();
855
- return Object.entries(Y(r)).reduce((t, [s, n]) => (t[s] = e.parse(n), t), {});
856
- }
857
- });
858
- }
859
- function ut() {
860
- return f({
861
- height: A(),
862
- width: (r) => r == null ? window.innerWidth : A().parse(r),
863
- is_state_stable: k(),
864
- is_expanded: k()
865
- });
866
- }
867
- function pt() {
868
- return f({ status: h() });
869
- }
870
- function lt() {
484
+ function Ye() {
871
485
  const r = new w(), e = (t, ...s) => {
872
- q.log("Emitting processed event:", t, ...s), r.emit(t, ...s);
486
+ k.log("Emitting processed event:", t, ...s), r.emit(t, ...s);
873
487
  };
874
488
  return window.addEventListener("resize", () => {
875
489
  e("viewport_changed", {
@@ -878,33 +492,33 @@ function lt() {
878
492
  is_state_stable: !0,
879
493
  is_expanded: !0
880
494
  });
881
- }), rt((t, s) => {
882
- q.log("Received raw event:", t, s);
495
+ }), Ne((t, s) => {
496
+ k.log("Received raw event:", t, s);
883
497
  try {
884
498
  switch (t) {
885
499
  case "viewport_changed":
886
- return e(t, ut().parse(s));
500
+ return e(t, Ze().parse(s));
887
501
  case "theme_changed":
888
- return e(t, ht().parse(s));
502
+ return e(t, Qe().parse(s));
889
503
  case "popup_closed":
890
504
  return (
891
505
  // Sent on desktop.
892
- s == null ? e(t, {}) : e(t, at().parse(s))
506
+ s == null ? e(t, {}) : e(t, Fe().parse(s))
893
507
  );
894
508
  case "set_custom_style":
895
509
  return e(t, h().parse(s));
896
510
  case "qr_text_received":
897
- return e(t, ct().parse(s));
511
+ return e(t, ze().parse(s));
898
512
  case "clipboard_text_received":
899
- return e(t, st().parse(s));
513
+ return e(t, Ue().parse(s));
900
514
  case "invoice_closed":
901
- return e(t, it().parse(s));
515
+ return e(t, Ge().parse(s));
902
516
  case "phone_requested":
903
- return e("phone_requested", ot().parse(s));
517
+ return e("phone_requested", je().parse(s));
904
518
  case "custom_method_invoked":
905
- return e("custom_method_invoked", nt().parse(s));
519
+ return e("custom_method_invoked", Me().parse(s));
906
520
  case "write_access_requested":
907
- return e("write_access_requested", pt().parse(s));
521
+ return e("write_access_requested", Ke().parse(s));
908
522
  case "main_button_pressed":
909
523
  case "back_button_pressed":
910
524
  case "settings_button_pressed":
@@ -915,174 +529,144 @@ function lt() {
915
529
  return e(t, s);
916
530
  }
917
531
  } catch (n) {
918
- q.error("Error processing event:", n);
532
+ k.error("Error processing event:", n);
919
533
  }
920
534
  }), r;
921
535
  }
922
- const Q = "telegram-mini-apps-cached-emitter";
923
- function U() {
536
+ const z = "telegram-mini-apps-cached-emitter";
537
+ function W() {
924
538
  const r = window;
925
- return r[Q] === void 0 && (r[Q] = lt()), r[Q];
926
- }
927
- function $(r, e) {
928
- U().off(r, e);
929
- }
930
- function y(r, e) {
931
- return U().on(r, e), () => $(r, e);
932
- }
933
- function rr(r, e) {
934
- return U().once(r, e), () => $(r, e);
935
- }
936
- function dt(r) {
937
- U().unsubscribe(r);
938
- }
939
- function sr(r) {
940
- return U().subscribe(r), () => dt(r);
539
+ return r[z] === void 0 && (r[z] = Ye()), r[z];
941
540
  }
942
- function ft(r, e) {
943
- const t = r.split("."), s = e.split("."), n = Math.max(t.length, s.length);
944
- for (let i = 0; i < n; i += 1) {
945
- const a = parseInt(t[i] || "0", 10), c = parseInt(s[i] || "0", 10);
946
- if (a !== c)
947
- return a > c ? 1 : -1;
948
- }
949
- return 0;
950
- }
951
- function P(r, e) {
952
- return ft(r, e) <= 0;
953
- }
954
- function I(r, e, t) {
955
- if (typeof t == "string") {
956
- if (r === "web_app_open_link" && e === "try_instant_view")
957
- return P("6.4", t);
958
- if (r === "web_app_set_header_color" && e === "color")
959
- return P("6.9", t);
960
- }
961
- switch (r) {
962
- case "web_app_open_tg_link":
963
- case "web_app_open_invoice":
964
- case "web_app_setup_back_button":
965
- case "web_app_set_background_color":
966
- case "web_app_set_header_color":
967
- case "web_app_trigger_haptic_feedback":
968
- return P("6.1", e);
969
- case "web_app_open_popup":
970
- return P("6.2", e);
971
- case "web_app_close_scan_qr_popup":
972
- case "web_app_open_scan_qr_popup":
973
- case "web_app_read_text_from_clipboard":
974
- return P("6.4", e);
975
- case "web_app_switch_inline_query":
976
- return P("6.7", e);
977
- case "web_app_invoke_custom_method":
978
- case "web_app_request_write_access":
979
- case "web_app_request_phone":
980
- return P("6.9", e);
981
- case "web_app_setup_settings_button":
982
- return P("6.10", e);
983
- default:
984
- return !0;
985
- }
541
+ function I(r, e) {
542
+ W().off(r, e);
986
543
  }
987
544
  function E(r, e) {
988
- return (t) => I(e[t], r);
989
- }
990
- function Se(r, e) {
991
- return (t) => {
992
- const [s, n] = e[t];
993
- return I(s, n, r);
994
- };
545
+ return W().on(r, e), () => I(r, e);
995
546
  }
996
- function d(r, e, t) {
997
- let s = {}, n;
998
- e === void 0 && t === void 0 ? s = {} : e !== void 0 && t !== void 0 ? (s = t, n = e) : e !== void 0 && ("targetOrigin" in e ? s = e : n = e);
999
- const { targetOrigin: i = Fe() } = s;
1000
- if (q.log(`Calling method "${r}"`, n), pe()) {
1001
- window.parent.postMessage(JSON.stringify({
1002
- eventType: r,
1003
- eventData: n
1004
- }), i);
1005
- return;
1006
- }
1007
- if (Ze(window)) {
1008
- window.external.notify(JSON.stringify({ eventType: r, eventData: n }));
1009
- return;
1010
- }
1011
- if (Ke(window)) {
1012
- window.TelegramWebviewProxy.postEvent(r, JSON.stringify(n));
1013
- return;
1014
- }
1015
- throw new Error(
1016
- "Unable to determine current environment and possible way to send event."
1017
- );
1018
- }
1019
- function gt(r) {
1020
- return (e, t) => {
1021
- if (!I(e, r))
1022
- throw new re(e, r);
1023
- if (R(t)) {
1024
- let s;
1025
- if (e === "web_app_open_link" && "try_instant_view" in t ? s = "try_instant_view" : e === "web_app_set_header_color" && "color" in t && (s = "color"), s && !I(e, s, r))
1026
- throw new se(e, s, r);
1027
- }
1028
- return d(e, t);
1029
- };
1030
- }
1031
- class J extends Error {
547
+ class F extends Error {
1032
548
  constructor(e) {
1033
- super(`Async call timeout exceeded. Timeout: ${e}`), Object.setPrototypeOf(this, J.prototype);
549
+ super(`Async call timeout exceeded. Timeout: ${e}`), Object.setPrototypeOf(this, F.prototype);
1034
550
  }
1035
551
  }
1036
- function nr(r) {
1037
- return r instanceof J;
1038
- }
1039
- function wt(r) {
1040
- return new Promise((e) => {
1041
- setTimeout(e, r);
1042
- });
1043
- }
1044
- function _t(r) {
552
+ function Xe(r) {
1045
553
  return new Promise((e, t) => {
1046
- setTimeout(t, r, new J(r));
554
+ setTimeout(t, r, new F(r));
1047
555
  });
1048
556
  }
1049
- function xe(r, e) {
557
+ function we(r, e) {
1050
558
  return Promise.race([
1051
- r(),
1052
- _t(e)
559
+ typeof r == "function" ? r() : r,
560
+ Xe(e)
1053
561
  ]);
1054
562
  }
1055
- function m(r, e, t, s) {
1056
- let n, i, a, c;
1057
- typeof e == "string" || Array.isArray(e) ? (a = Array.isArray(e) ? e : [e], n = t) : (i = e, a = Array.isArray(t) ? t : [t], n = s), R(i) && typeof i.req_id == "string" && (c = i.req_id);
1058
- const { postEvent: u = d, timeout: p } = n || {}, g = n && "capture" in n ? n.capture : null, _ = () => new Promise((V, l) => {
1059
- const C = a.map((v) => y(v, (M) => {
1060
- c && (!R(M) || M.req_id !== c) || typeof g == "function" && !g(M) || (x(), V(M));
1061
- })), x = () => C.forEach((v) => v());
1062
- try {
1063
- u(r, i);
1064
- } catch (v) {
1065
- x(), l(v);
1066
- }
1067
- });
1068
- return typeof p == "number" ? xe(_, p) : _();
563
+ async function y(r, e, t) {
564
+ let s;
565
+ const n = new Promise((b) => {
566
+ s = b;
567
+ }), i = e ? {
568
+ ...t,
569
+ event: e,
570
+ method: r
571
+ } : r, {
572
+ method: a,
573
+ event: c,
574
+ capture: u,
575
+ postEvent: p = d,
576
+ timeout: g
577
+ } = i, _ = (Array.isArray(c) ? c : [c]).map(
578
+ (b) => E(b, (l) => (!u || u(l)) && s(l))
579
+ );
580
+ try {
581
+ return p(a, i.params), await (g ? we(n, g) : n);
582
+ } finally {
583
+ _.forEach((b) => b());
584
+ }
1069
585
  }
1070
- async function H(r, e, t, s = {}) {
1071
- const { result: n, error: i } = await m(
1072
- "web_app_invoke_custom_method",
1073
- {
586
+ async function O(r, e, t, s = {}) {
587
+ const {
588
+ result: n,
589
+ error: i
590
+ } = await y("web_app_invoke_custom_method", "custom_method_invoked", {
591
+ ...s,
592
+ params: {
1074
593
  method: r,
1075
594
  params: e,
1076
595
  req_id: t
1077
596
  },
1078
- "custom_method_invoked",
1079
- s
1080
- );
597
+ capture: le(t)
598
+ });
1081
599
  if (i)
1082
600
  throw new Error(i);
1083
601
  return n;
1084
602
  }
1085
- class bt {
603
+ function Kt(r, e) {
604
+ return W().once(r, e), () => I(r, e);
605
+ }
606
+ function et(r) {
607
+ W().unsubscribe(r);
608
+ }
609
+ function Yt(r) {
610
+ return W().subscribe(r), () => et(r);
611
+ }
612
+ function se(r, e) {
613
+ return r + (r.length > 0 && e.length > 0 ? ` ${e}` : e);
614
+ }
615
+ function tt(...r) {
616
+ return r.reduce((e, t) => {
617
+ let s = "";
618
+ return typeof t == "string" ? s = t : typeof t == "object" && t !== null && (s = Object.entries(t).reduce((n, [i, a]) => a ? se(n, i) : n, "")), se(e, s);
619
+ }, "");
620
+ }
621
+ function Xt(...r) {
622
+ return r.reduce((e, t) => (M(t) && Object.entries(t).forEach(([s, n]) => {
623
+ const i = tt(e[s], n);
624
+ i.length > 0 && (e[s] = i);
625
+ }), e), {});
626
+ }
627
+ function _e(r) {
628
+ const e = fe(r);
629
+ return Math.sqrt(
630
+ [0.299, 0.587, 0.114].reduce((s, n, i) => {
631
+ const a = parseInt(e.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
632
+ return s + a * a * n;
633
+ }, 0)
634
+ ) < 120;
635
+ }
636
+ class m {
637
+ constructor(e, t) {
638
+ this.state = e, this.ee = t;
639
+ }
640
+ internalSet(e, t) {
641
+ return this.state[e] === t || t === void 0 ? !1 : (this.state[e] = t, this.ee.emit(`change:${e}`, t), !0);
642
+ }
643
+ /**
644
+ * Returns copy of current state.
645
+ */
646
+ clone() {
647
+ return { ...this.state };
648
+ }
649
+ set(e, t) {
650
+ let s = !1;
651
+ if (typeof e == "string")
652
+ s = this.internalSet(e, t);
653
+ else
654
+ for (const n in e)
655
+ this.internalSet(n, e[n]) && (s = !0);
656
+ s && this.ee.emit("change");
657
+ }
658
+ /**
659
+ * Returns value by specified key.
660
+ * @param key - state key.
661
+ */
662
+ get(e) {
663
+ return this.state[e];
664
+ }
665
+ }
666
+ function C(r, e) {
667
+ return (t) => A(e[t], r);
668
+ }
669
+ class rt {
1086
670
  constructor(e, t, s = d) {
1087
671
  o(this, "ee", new w());
1088
672
  o(this, "state");
@@ -1091,18 +675,18 @@ class bt {
1091
675
  * @param event - event name.
1092
676
  * @param listener - event listener.
1093
677
  */
1094
- o(this, "on", (e, t) => e === "click" ? y("back_button_pressed", t) : this.ee.on(e, t));
678
+ o(this, "on", (e, t) => e === "click" ? E("back_button_pressed", t) : this.ee.on(e, t));
1095
679
  /**
1096
680
  * Removes event listener.
1097
681
  * @param event - event name.
1098
682
  * @param listener - event listener.
1099
683
  */
1100
- o(this, "off", (e, t) => e === "click" ? $("back_button_pressed", t) : this.ee.off(e, t));
684
+ o(this, "off", (e, t) => e === "click" ? I("back_button_pressed", t) : this.ee.off(e, t));
1101
685
  /**
1102
686
  * Checks if specified method is supported by current component.
1103
687
  */
1104
688
  o(this, "supports");
1105
- this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
689
+ this.postEvent = s, this.state = new m({ isVisible: e }, this.ee), this.supports = C(t, {
1106
690
  show: "web_app_setup_back_button",
1107
691
  hide: "web_app_setup_back_button"
1108
692
  });
@@ -1126,25 +710,10 @@ class bt {
1126
710
  * Shows the BackButton.
1127
711
  */
1128
712
  show() {
1129
- this.isVisible = !0;
1130
- }
1131
- }
1132
- function ie(r, e) {
1133
- return r + (r.length > 0 && e.length > 0 ? ` ${e}` : e);
1134
- }
1135
- function mt(...r) {
1136
- return r.reduce((e, t) => {
1137
- let s = "";
1138
- return typeof t == "string" ? s = t : typeof t == "object" && t !== null && (s = Object.entries(t).reduce((n, [i, a]) => a ? ie(n, i) : n, "")), ie(e, s);
1139
- }, "");
1140
- }
1141
- function ir(...r) {
1142
- return r.reduce((e, t) => (R(t) && Object.entries(t).forEach(([s, n]) => {
1143
- const i = mt(e[s], n);
1144
- i.length > 0 && (e[s] = i);
1145
- }), e), {});
713
+ this.isVisible = !0;
714
+ }
1146
715
  }
1147
- class yt {
716
+ class st {
1148
717
  constructor(e, t = d) {
1149
718
  o(this, "ee", new w());
1150
719
  o(this, "state");
@@ -1156,7 +725,7 @@ class yt {
1156
725
  * Removes event listener.
1157
726
  */
1158
727
  o(this, "off", this.ee.off.bind(this.ee));
1159
- this.postEvent = t, this.state = new b({ isConfirmationNeeded: e }, this.ee);
728
+ this.postEvent = t, this.state = new m({ isConfirmationNeeded: e }, this.ee);
1160
729
  }
1161
730
  set isConfirmationNeeded(e) {
1162
731
  this.state.set("isConfirmationNeeded", e), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: e });
@@ -1183,16 +752,45 @@ class yt {
1183
752
  this.isConfirmationNeeded = !0;
1184
753
  }
1185
754
  }
1186
- function oe(r, e) {
755
+ function nt(r) {
756
+ if (Array.isArray(r))
757
+ return r;
758
+ if (typeof r == "string")
759
+ try {
760
+ const e = JSON.parse(r);
761
+ if (Array.isArray(e))
762
+ return e;
763
+ } catch {
764
+ }
765
+ throw V();
766
+ }
767
+ class it extends j {
768
+ constructor(t, s, n) {
769
+ super(nt, s, n);
770
+ o(this, "itemParser");
771
+ this.itemParser = typeof t == "function" ? t : t.parse.bind(t);
772
+ }
773
+ parse(t) {
774
+ const s = super.parse(t);
775
+ return s === void 0 ? s : s.map(this.itemParser);
776
+ }
777
+ of(t) {
778
+ return this.itemParser = typeof t == "function" ? t : t.parse.bind(t), this;
779
+ }
780
+ }
781
+ function ot(r) {
782
+ return new it((e) => e, !1, r);
783
+ }
784
+ function ne(r, e) {
1187
785
  return r.reduce((t, s) => (t[s] = e, t), {});
1188
786
  }
1189
- class Et {
787
+ class at {
1190
788
  constructor(e, t, s = d) {
1191
789
  /**
1192
790
  * Checks if specified method is supported by current component.
1193
791
  */
1194
792
  o(this, "supports");
1195
- this.createRequestId = t, this.postEvent = s, this.supports = E(e, {
793
+ this.createRequestId = t, this.postEvent = s, this.supports = C(e, {
1196
794
  delete: "web_app_invoke_custom_method",
1197
795
  get: "web_app_invoke_custom_method",
1198
796
  getKeys: "web_app_invoke_custom_method",
@@ -1206,7 +804,7 @@ class Et {
1206
804
  */
1207
805
  async delete(e, t = {}) {
1208
806
  const s = Array.isArray(e) ? e : [e];
1209
- s.length !== 0 && await H(
807
+ s.length !== 0 && await O(
1210
808
  "deleteStorageValues",
1211
809
  { keys: s },
1212
810
  this.createRequestId(),
@@ -1218,21 +816,21 @@ class Et {
1218
816
  * @param options - request execution options.
1219
817
  */
1220
818
  async getKeys(e = {}) {
1221
- const t = await H(
819
+ const t = await O(
1222
820
  "getStorageKeys",
1223
821
  {},
1224
822
  this.createRequestId(),
1225
823
  { ...e, postEvent: this.postEvent }
1226
824
  );
1227
- return $e().of(h()).parse(t);
825
+ return ot().of(h()).parse(t);
1228
826
  }
1229
827
  async get(e, t = {}) {
1230
828
  const s = Array.isArray(e) ? e : [e];
1231
829
  if (s.length === 0)
1232
- return oe(s, "");
830
+ return ne(s, "");
1233
831
  const n = f(
1234
- oe(s, h())
1235
- ), i = await H(
832
+ ne(s, h())
833
+ ), i = await O(
1236
834
  "getStorageValues",
1237
835
  { keys: s },
1238
836
  this.createRequestId(),
@@ -1247,7 +845,7 @@ class Et {
1247
845
  * @param options - request execution options.
1248
846
  */
1249
847
  async set(e, t, s = {}) {
1250
- await H(
848
+ await O(
1251
849
  "saveStorageValue",
1252
850
  { key: e, value: t },
1253
851
  this.createRequestId(),
@@ -1255,52 +853,13 @@ class Et {
1255
853
  );
1256
854
  }
1257
855
  }
1258
- function S(r, e) {
1259
- document.documentElement.style.setProperty(r, e);
1260
- }
1261
- function Ct(r, e) {
1262
- const t = () => {
1263
- S("--tg-background-color", r.backgroundColor);
1264
- }, s = () => {
1265
- const {
1266
- backgroundColor: n,
1267
- secondaryBackgroundColor: i
1268
- } = e;
1269
- if (X(r.headerColor)) {
1270
- S("--tg-header-color", r.headerColor);
1271
- return;
1272
- }
1273
- if (r.headerColor === "bg_color" && n) {
1274
- S("--tg-header-color", n);
1275
- return;
1276
- }
1277
- r.headerColor === "secondary_bg_color" && i && S("--tg-header-color", i);
1278
- };
1279
- e.on("change", s), r.on("change:backgroundColor", t), r.on("change:headerColor", s), t(), s();
1280
- }
1281
- function vt(r) {
1282
- const e = () => {
1283
- const t = r.getState();
1284
- Object.entries(t).forEach(([s, n]) => {
1285
- if (n) {
1286
- const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
1287
- S(`--tg-theme-${i}`, n);
1288
- }
1289
- });
1290
- };
1291
- r.on("change", e), e();
1292
- }
1293
- function ae(r) {
1294
- const e = () => S("--tg-viewport-height", `${r.height}px`), t = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-stable-height", `${r.stableHeight}px`);
1295
- r.on("change:height", e), r.on("change:width", t), r.on("change:stableHeight", s), e(), t(), s();
1296
- }
1297
- class Pt {
856
+ class ct {
1298
857
  constructor(e, t = d) {
1299
858
  /**
1300
859
  * Checks if specified method is supported by current component.
1301
860
  */
1302
861
  o(this, "supports");
1303
- this.postEvent = t, this.supports = E(e, {
862
+ this.postEvent = t, this.supports = C(e, {
1304
863
  impactOccurred: "web_app_trigger_haptic_feedback",
1305
864
  notificationOccurred: "web_app_trigger_haptic_feedback",
1306
865
  selectionChanged: "web_app_trigger_haptic_feedback"
@@ -1340,35 +899,231 @@ class Pt {
1340
899
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1341
900
  }
1342
901
  }
1343
- function kt() {
1344
- const r = document.createElement("style");
1345
- r.id = "telegram-custom-styles", document.head.appendChild(r), y("set_custom_style", (e) => {
1346
- r.innerHTML = e;
1347
- });
902
+ function ht() {
903
+ return f({
904
+ id: x(),
905
+ type: h(),
906
+ title: h(),
907
+ photoUrl: {
908
+ type: h().optional(),
909
+ from: "photo_url"
910
+ },
911
+ username: h().optional()
912
+ }, "Chat");
1348
913
  }
1349
- function qe(r) {
1350
- return `telegram-mini-apps-${r}`;
914
+ class ut {
915
+ constructor(e) {
916
+ this.initData = e;
917
+ }
918
+ /**
919
+ * @see InitDataParsed.authDate
920
+ */
921
+ get authDate() {
922
+ return this.initData.authDate;
923
+ }
924
+ /**
925
+ * @see InitDataParsed.canSendAfter
926
+ */
927
+ get canSendAfter() {
928
+ return this.initData.canSendAfter;
929
+ }
930
+ /**
931
+ * Date after which it is allowed to call
932
+ * the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
933
+ */
934
+ get canSendAfterDate() {
935
+ const { canSendAfter: e } = this;
936
+ return e === void 0 ? void 0 : new Date(this.authDate.getTime() + e * 1e3);
937
+ }
938
+ /**
939
+ * @see InitDataParsed.chat
940
+ */
941
+ get chat() {
942
+ return this.initData.chat;
943
+ }
944
+ /**
945
+ * @see InitDataParsed.chatType
946
+ */
947
+ get chatType() {
948
+ return this.initData.chatType;
949
+ }
950
+ /**
951
+ * @see InitDataParsed.chatInstance
952
+ */
953
+ get chatInstance() {
954
+ return this.initData.chatInstance;
955
+ }
956
+ /**
957
+ * @see InitDataParsed.hash
958
+ */
959
+ get hash() {
960
+ return this.initData.hash;
961
+ }
962
+ /**
963
+ * @see InitDataParsed.queryId
964
+ */
965
+ get queryId() {
966
+ return this.initData.queryId;
967
+ }
968
+ /**
969
+ * @see InitDataParsed.receiver
970
+ */
971
+ get receiver() {
972
+ return this.initData.receiver;
973
+ }
974
+ /**
975
+ * @see InitDataParsed.startParam
976
+ */
977
+ get startParam() {
978
+ return this.initData.startParam;
979
+ }
980
+ /**
981
+ * @see InitDataParsed.user
982
+ */
983
+ get user() {
984
+ return this.initData.user;
985
+ }
1351
986
  }
1352
- function B(r, e) {
1353
- sessionStorage.setItem(qe(r), JSON.stringify(e));
987
+ function ie() {
988
+ return f({
989
+ addedToAttachmentMenu: {
990
+ type: P().optional(),
991
+ from: "added_to_attachment_menu"
992
+ },
993
+ allowsWriteToPm: {
994
+ type: P().optional(),
995
+ from: "allows_write_to_pm"
996
+ },
997
+ firstName: {
998
+ type: h(),
999
+ from: "first_name"
1000
+ },
1001
+ id: x(),
1002
+ isBot: {
1003
+ type: P().optional(),
1004
+ from: "is_bot"
1005
+ },
1006
+ isPremium: {
1007
+ type: P().optional(),
1008
+ from: "is_premium"
1009
+ },
1010
+ languageCode: {
1011
+ type: h().optional(),
1012
+ from: "language_code"
1013
+ },
1014
+ lastName: {
1015
+ type: h().optional(),
1016
+ from: "last_name"
1017
+ },
1018
+ photoUrl: {
1019
+ type: h().optional(),
1020
+ from: "photo_url"
1021
+ },
1022
+ username: h().optional()
1023
+ }, "User");
1354
1024
  }
1355
- function D(r) {
1356
- const e = sessionStorage.getItem(qe(r));
1357
- return e ? JSON.parse(e) : null;
1025
+ const be = R((r) => r instanceof Date ? r : new Date(x().parse(r) * 1e3), "Date");
1026
+ function ee(r, e) {
1027
+ return new j((t) => {
1028
+ if (typeof t != "string" && !(t instanceof URLSearchParams))
1029
+ throw V();
1030
+ const s = typeof t == "string" ? new URLSearchParams(t) : t;
1031
+ return de(r, (n) => {
1032
+ const i = s.get(n);
1033
+ return i === null ? void 0 : i;
1034
+ });
1035
+ }, !1, e);
1358
1036
  }
1359
- function St(r, e, t) {
1360
- const { isVisible: s = !1 } = r ? D("back-button") || {} : {}, n = new bt(s, e, t);
1361
- return n.on("change", () => {
1362
- B("back-button", { isVisible: n.isVisible });
1363
- }), n;
1037
+ function me() {
1038
+ return ee({
1039
+ authDate: {
1040
+ type: be(),
1041
+ from: "auth_date"
1042
+ },
1043
+ canSendAfter: {
1044
+ type: x().optional(),
1045
+ from: "can_send_after"
1046
+ },
1047
+ chat: ht().optional(),
1048
+ chatInstance: {
1049
+ type: h().optional(),
1050
+ from: "chat_instance"
1051
+ },
1052
+ chatType: {
1053
+ type: h().optional(),
1054
+ from: "chat_type"
1055
+ },
1056
+ hash: h(),
1057
+ queryId: {
1058
+ type: h().optional(),
1059
+ from: "query_id"
1060
+ },
1061
+ receiver: ie().optional(),
1062
+ startParam: {
1063
+ type: h().optional(),
1064
+ from: "start_param"
1065
+ },
1066
+ user: ie().optional()
1067
+ }, "InitData");
1364
1068
  }
1365
- function xt(r, e) {
1366
- const { isConfirmationNeeded: t = !1 } = r ? D("closing-behavior") || {} : {}, s = new yt(t, e);
1367
- return s.on("change", () => B("closing-behavior", {
1368
- isConfirmationNeeded: s.isConfirmationNeeded
1369
- })), s;
1069
+ function er(r) {
1070
+ return me().parse(r);
1071
+ }
1072
+ function pt(r) {
1073
+ const { hostname: e, pathname: t } = new URL(r, window.location.href);
1074
+ if (e !== "t.me")
1075
+ throw new Error(`Incorrect hostname: ${e}`);
1076
+ const s = t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1077
+ if (s === null)
1078
+ throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1079
+ return s[2];
1080
+ }
1081
+ class lt {
1082
+ constructor(e, t = d) {
1083
+ o(this, "ee", new w());
1084
+ o(this, "state");
1085
+ /**
1086
+ * Adds new event listener.
1087
+ */
1088
+ o(this, "on", this.ee.on.bind(this.ee));
1089
+ /**
1090
+ * Removes event listener.
1091
+ */
1092
+ o(this, "off", this.ee.off.bind(this.ee));
1093
+ /**
1094
+ * Checks if specified method is supported by current component.
1095
+ */
1096
+ o(this, "supports");
1097
+ this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, { open: "web_app_open_invoice" });
1098
+ }
1099
+ set isOpened(e) {
1100
+ this.state.set("isOpened", e);
1101
+ }
1102
+ /**
1103
+ * True if invoice is currently opened.
1104
+ */
1105
+ get isOpened() {
1106
+ return this.state.get("isOpened");
1107
+ }
1108
+ async open(e, t) {
1109
+ if (this.isOpened)
1110
+ throw new Error("Invoice is already opened");
1111
+ const s = t ? pt(e) : e;
1112
+ this.isOpened = !0;
1113
+ try {
1114
+ return (await y("web_app_open_invoice", "invoice_closed", {
1115
+ params: { slug: s },
1116
+ postEvent: this.postEvent,
1117
+ capture(i) {
1118
+ return s === i.slug;
1119
+ }
1120
+ })).status;
1121
+ } finally {
1122
+ this.isOpened = !1;
1123
+ }
1124
+ }
1370
1125
  }
1371
- class qt {
1126
+ class dt {
1372
1127
  constructor(e) {
1373
1128
  o(this, "ee", new w());
1374
1129
  o(this, "state");
@@ -1382,14 +1137,14 @@ class qt {
1382
1137
  // FIXME: Event 'main_button_pressed' is still being received on Android
1383
1138
  // even if the main button is disabled.
1384
1139
  // Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
1385
- e === "click" ? y("main_button_pressed", t) : this.ee.on(e, t)
1140
+ e === "click" ? E("main_button_pressed", t) : this.ee.on(e, t)
1386
1141
  ));
1387
1142
  /**
1388
1143
  * Removes event listener.
1389
1144
  * @param event - event name.
1390
1145
  * @param listener - event listener.
1391
1146
  */
1392
- o(this, "off", (e, t) => e === "click" ? $("main_button_pressed", t) : this.ee.off(e, t));
1147
+ o(this, "off", (e, t) => e === "click" ? I("main_button_pressed", t) : this.ee.off(e, t));
1393
1148
  const {
1394
1149
  postEvent: t = d,
1395
1150
  text: s,
@@ -1399,7 +1154,7 @@ class qt {
1399
1154
  isVisible: c,
1400
1155
  isLoaderVisible: u
1401
1156
  } = e;
1402
- this.postEvent = t, this.state = new b({
1157
+ this.postEvent = t, this.state = new m({
1403
1158
  backgroundColor: i,
1404
1159
  isEnabled: a,
1405
1160
  isVisible: c,
@@ -1443,448 +1198,733 @@ class qt {
1443
1198
  this.setParams({ isVisible: e });
1444
1199
  }
1445
1200
  /**
1446
- * True if the Main Button is currently visible.
1201
+ * True if the Main Button is currently visible.
1202
+ */
1203
+ get isVisible() {
1204
+ return this.state.get("isVisible");
1205
+ }
1206
+ /**
1207
+ * The Main Button background color.
1208
+ */
1209
+ get backgroundColor() {
1210
+ return this.state.get("backgroundColor");
1211
+ }
1212
+ /**
1213
+ * The Main Button text.
1214
+ */
1215
+ get text() {
1216
+ return this.state.get("text");
1217
+ }
1218
+ /**
1219
+ * The Main Button text color.
1220
+ */
1221
+ get textColor() {
1222
+ return this.state.get("textColor");
1223
+ }
1224
+ /**
1225
+ * Disables the Main Button.
1226
+ */
1227
+ disable() {
1228
+ return this.isEnabled = !1, this;
1229
+ }
1230
+ /**
1231
+ * Enables the Main Button.
1232
+ */
1233
+ enable() {
1234
+ return this.isEnabled = !0, this;
1235
+ }
1236
+ /**
1237
+ * Hides the Main Button.
1238
+ */
1239
+ hide() {
1240
+ return this.isVisible = !1, this;
1241
+ }
1242
+ /**
1243
+ * Hides the Main Button loader.
1244
+ */
1245
+ hideLoader() {
1246
+ return this.isLoaderVisible = !1, this;
1247
+ }
1248
+ /**
1249
+ * Shows the Main Button. Note that opening the Mini App from the attachment menu hides the
1250
+ * main button until the user interacts with the Mini App interface.
1251
+ */
1252
+ show() {
1253
+ return this.isVisible = !0, this;
1254
+ }
1255
+ /**
1256
+ * A method to show a loading indicator on the Main Button. It is recommended to display
1257
+ * loader if the action tied to the button may take a long time.
1258
+ */
1259
+ showLoader() {
1260
+ return this.isLoaderVisible = !0, this;
1261
+ }
1262
+ /**
1263
+ * Sets new Main Button text. Minimal length for text is 1 symbol, and maximum is 64 symbols.
1264
+ * @param text - new text.
1265
+ */
1266
+ setText(e) {
1267
+ return this.setParams({ text: e });
1268
+ }
1269
+ /**
1270
+ * Sets new Main Button text color.
1271
+ * @param textColor - new text color.
1272
+ */
1273
+ setTextColor(e) {
1274
+ return this.setParams({ textColor: e });
1275
+ }
1276
+ /**
1277
+ * Updates current Main Button color.
1278
+ * @param backgroundColor - color to set.
1279
+ */
1280
+ setBackgroundColor(e) {
1281
+ return this.setParams({ backgroundColor: e });
1282
+ }
1283
+ /**
1284
+ * Allows setting multiple Main Button parameters.
1285
+ * @param params - Main Button parameters.
1286
+ */
1287
+ setParams(e) {
1288
+ return this.state.set(e), this.commit(), this;
1289
+ }
1290
+ }
1291
+ const ft = ee({
1292
+ contact: f({
1293
+ userId: {
1294
+ type: x(),
1295
+ from: "user_id"
1296
+ },
1297
+ phoneNumber: {
1298
+ type: h(),
1299
+ from: "phone_number"
1300
+ },
1301
+ firstName: {
1302
+ type: h(),
1303
+ from: "first_name"
1304
+ },
1305
+ lastName: {
1306
+ type: h().optional(),
1307
+ from: "last_name"
1308
+ }
1309
+ }),
1310
+ authDate: {
1311
+ type: be(),
1312
+ from: "auth_date"
1313
+ },
1314
+ hash: h()
1315
+ });
1316
+ function ye(r, e) {
1317
+ return (t) => {
1318
+ const [s, n] = e[t];
1319
+ return A(s, n, r);
1320
+ };
1321
+ }
1322
+ function gt(r) {
1323
+ return new Promise((e) => {
1324
+ setTimeout(e, r);
1325
+ });
1326
+ }
1327
+ class wt {
1328
+ constructor(e) {
1329
+ o(this, "ee", new w());
1330
+ o(this, "state");
1331
+ o(this, "botInline");
1332
+ o(this, "postEvent");
1333
+ o(this, "createRequestId");
1334
+ o(this, "requestingPhoneAccess", !1);
1335
+ o(this, "requestingWriteAccess", !1);
1336
+ /**
1337
+ * Adds new event listener.
1338
+ */
1339
+ o(this, "on", this.ee.on.bind(this.ee));
1340
+ /**
1341
+ * Removes event listener.
1342
+ */
1343
+ o(this, "off", this.ee.off.bind(this.ee));
1344
+ /**
1345
+ * Checks if specified method is supported by current component.
1346
+ */
1347
+ o(this, "supports");
1348
+ /**
1349
+ * Checks if specified method parameter is supported by current component.
1350
+ */
1351
+ o(this, "supportsParam");
1352
+ const {
1353
+ postEvent: t = d,
1354
+ headerColor: s,
1355
+ backgroundColor: n,
1356
+ version: i,
1357
+ botInline: a,
1358
+ createRequestId: c
1359
+ } = e, u = C(i, {
1360
+ requestPhoneAccess: "web_app_request_phone",
1361
+ requestWriteAccess: "web_app_request_write_access",
1362
+ switchInlineQuery: "web_app_switch_inline_query",
1363
+ setHeaderColor: "web_app_set_header_color",
1364
+ setBackgroundColor: "web_app_set_background_color"
1365
+ });
1366
+ this.postEvent = t, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new m({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = ye(i, {
1367
+ "setHeaderColor.color": ["web_app_set_header_color", "color"]
1368
+ });
1369
+ }
1370
+ /**
1371
+ * Attempts to get requested contact.
1372
+ */
1373
+ async getRequestedContact() {
1374
+ return O(
1375
+ "getRequestedContact",
1376
+ {},
1377
+ this.createRequestId(),
1378
+ {
1379
+ postEvent: this.postEvent,
1380
+ timeout: 1e4
1381
+ }
1382
+ ).then((e) => ft.parse(e));
1383
+ }
1384
+ /**
1385
+ * The Mini App background color.
1386
+ */
1387
+ get backgroundColor() {
1388
+ return this.state.get("backgroundColor");
1389
+ }
1390
+ /**
1391
+ * Closes the Mini App.
1392
+ */
1393
+ close() {
1394
+ this.postEvent("web_app_close");
1395
+ }
1396
+ /**
1397
+ * The Mini App header color. Could either be a header color key or RGB color.
1398
+ */
1399
+ get headerColor() {
1400
+ return this.state.get("headerColor");
1401
+ }
1402
+ /**
1403
+ * True if Mini App is currently launched in bot inline mode.
1404
+ */
1405
+ get isBotInline() {
1406
+ return this.botInline;
1407
+ }
1408
+ /**
1409
+ * True if current Mini App background color recognized as dark.
1410
+ */
1411
+ get isDark() {
1412
+ return _e(this.backgroundColor);
1413
+ }
1414
+ /**
1415
+ * True if phone access is currently being requested.
1416
+ */
1417
+ get isRequestingPhoneAccess() {
1418
+ return this.requestingPhoneAccess;
1419
+ }
1420
+ /**
1421
+ * True if write access is currently being requested.
1422
+ */
1423
+ get isRequestingWriteAccess() {
1424
+ return this.requestingWriteAccess;
1425
+ }
1426
+ /**
1427
+ * Informs the Telegram app that the Mini App is ready to be displayed.
1428
+ *
1429
+ * It is recommended to call this method as early as possible, as soon as all essential
1430
+ * interface elements loaded. Once this method called, the loading placeholder is hidden
1431
+ * and the Mini App shown.
1432
+ *
1433
+ * If the method not called, the placeholder will be hidden only when the page fully loaded.
1434
+ */
1435
+ ready() {
1436
+ this.postEvent("web_app_ready");
1437
+ }
1438
+ /**
1439
+ * Requests current user contact information. In contrary to requestPhoneAccess, this method
1440
+ * returns promise with contact information that rejects in case, user denied access, or request
1441
+ * failed.
1442
+ * @param options - additional options.
1443
+ */
1444
+ async requestContact({ timeout: e = 5e3 } = {}) {
1445
+ try {
1446
+ return await this.getRequestedContact();
1447
+ } catch {
1448
+ }
1449
+ if (await this.requestPhoneAccess() !== "sent")
1450
+ throw new Error("Access denied.");
1451
+ const s = Date.now() + e;
1452
+ let n = 50;
1453
+ return we(async () => {
1454
+ for (; Date.now() < s; ) {
1455
+ try {
1456
+ return await this.getRequestedContact();
1457
+ } catch {
1458
+ }
1459
+ await gt(n), n += 50;
1460
+ }
1461
+ throw new Error("Unable to retrieve requested contact.");
1462
+ }, e);
1463
+ }
1464
+ /**
1465
+ * Requests current user phone access. Method returns promise, which resolves
1466
+ * status of the request. In case, user accepted the request, Mini App bot will receive
1467
+ * the according notification.
1468
+ *
1469
+ * To obtain the retrieved information instead, utilize the requestContact method.
1470
+ * @param options - additional options.
1471
+ * @see requestContact
1447
1472
  */
1448
- get isVisible() {
1449
- return this.state.get("isVisible");
1473
+ requestPhoneAccess(e = {}) {
1474
+ if (this.requestingPhoneAccess)
1475
+ throw new Error("Phone access is already being requested.");
1476
+ return this.requestingPhoneAccess = !0, y("web_app_request_phone", "phone_requested", {
1477
+ ...e,
1478
+ postEvent: this.postEvent
1479
+ }).then((t) => t.status).finally(() => {
1480
+ this.requestingPhoneAccess = !1;
1481
+ });
1450
1482
  }
1451
1483
  /**
1452
- * The Main Button background color.
1484
+ * Requests write message access to current user.
1485
+ * @param options - additional options.
1453
1486
  */
1454
- get backgroundColor() {
1455
- return this.state.get("backgroundColor");
1487
+ requestWriteAccess(e = {}) {
1488
+ if (this.requestingWriteAccess)
1489
+ throw new Error("Write access is already being requested.");
1490
+ return this.requestingWriteAccess = !0, y("web_app_request_write_access", "write_access_requested", {
1491
+ ...e,
1492
+ postEvent: this.postEvent
1493
+ }).then((t) => t.status).finally(() => {
1494
+ this.requestingWriteAccess = !1;
1495
+ });
1456
1496
  }
1457
1497
  /**
1458
- * The Main Button text.
1498
+ * A method used to send data to the bot. When this method called, a service message sent to
1499
+ * the bot containing the data of the length up to 4096 bytes, and the Mini App closed. See the
1500
+ * field `web_app_data` in the class [Message](https://core.telegram.org/bots/api#message).
1501
+ *
1502
+ * This method is only available for Mini Apps launched via a Keyboard button.
1503
+ * @param data - data to send to bot.
1504
+ * @throws {Error} data has incorrect size.
1459
1505
  */
1460
- get text() {
1461
- return this.state.get("text");
1506
+ sendData(e) {
1507
+ const { size: t } = new Blob([e]);
1508
+ if (t === 0 || t > 4096)
1509
+ throw new Error(`Passed data has incorrect size: ${t}`);
1510
+ this.postEvent("web_app_data_send", { data: e });
1462
1511
  }
1463
1512
  /**
1464
- * The Main Button text color.
1513
+ * Updates current Mini App header color.
1514
+ * @param color - color key or RGB color.
1465
1515
  */
1466
- get textColor() {
1467
- return this.state.get("textColor");
1516
+ setHeaderColor(e) {
1517
+ this.postEvent("web_app_set_header_color", X(e) ? { color: e } : { color_key: e }), this.state.set("headerColor", e);
1468
1518
  }
1469
1519
  /**
1470
- * Disables the Main Button.
1520
+ * Updates current Mini App background color.
1521
+ * @param color - RGB color.
1471
1522
  */
1472
- disable() {
1473
- return this.isEnabled = !1, this;
1523
+ setBackgroundColor(e) {
1524
+ this.postEvent("web_app_set_background_color", { color: e }), this.state.set("backgroundColor", e);
1474
1525
  }
1475
1526
  /**
1476
- * Enables the Main Button.
1527
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
1528
+ * Query may be empty, in which case only the bot's username will be inserted. The client prompts
1529
+ * the user to choose a specific chat, then opens that chat and inserts the bot's username and
1530
+ * the specified inline query in the input field.
1531
+ * @param text - text which should be inserted in the input after the current bot name. Max
1532
+ * length is 256 symbols.
1533
+ * @param chatTypes - List of chat types which could be chosen to send the message. Could be
1534
+ * empty list.
1477
1535
  */
1478
- enable() {
1479
- return this.isEnabled = !0, this;
1536
+ switchInlineQuery(e, t = []) {
1537
+ if (!this.supports("switchInlineQuery") && !this.isBotInline)
1538
+ throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
1539
+ this.postEvent("web_app_switch_inline_query", {
1540
+ query: e,
1541
+ chat_types: t
1542
+ });
1480
1543
  }
1481
- /**
1482
- * Hides the Main Button.
1483
- */
1484
- hide() {
1485
- return this.isVisible = !1, this;
1544
+ }
1545
+ function _t(r) {
1546
+ const e = r.message.trim(), t = (r.title || "").trim(), s = r.buttons || [];
1547
+ let n;
1548
+ if (t.length > 64)
1549
+ throw new Error(`Title has incorrect size: ${t.length}`);
1550
+ if (e.length === 0 || e.length > 256)
1551
+ throw new Error(`Message has incorrect size: ${e.length}`);
1552
+ if (s.length > 3)
1553
+ throw new Error(`Buttons have incorrect size: ${s.length}`);
1554
+ return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
1555
+ const { id: a = "" } = i;
1556
+ if (a.length > 64)
1557
+ throw new Error(`Button ID has incorrect size: ${a}`);
1558
+ if (i.type === void 0 || i.type === "default" || i.type === "destructive") {
1559
+ const c = i.text.trim();
1560
+ if (c.length === 0 || c.length > 64) {
1561
+ const u = i.type || "default";
1562
+ throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`);
1563
+ }
1564
+ return { ...i, text: c, id: a };
1565
+ }
1566
+ return { ...i, id: a };
1567
+ }), { title: t, message: e, buttons: n };
1568
+ }
1569
+ class bt {
1570
+ constructor(e, t = d) {
1571
+ o(this, "ee", new w());
1572
+ o(this, "state");
1573
+ /**
1574
+ * Adds new event listener.
1575
+ */
1576
+ o(this, "on", this.ee.on.bind(this.ee));
1577
+ /**
1578
+ * Removes event listener.
1579
+ */
1580
+ o(this, "off", this.ee.off.bind(this.ee));
1581
+ /**
1582
+ * Checks if specified method is supported by current component.
1583
+ */
1584
+ o(this, "supports");
1585
+ this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, { open: "web_app_open_popup" });
1486
1586
  }
1487
- /**
1488
- * Hides the Main Button loader.
1489
- */
1490
- hideLoader() {
1491
- return this.isLoaderVisible = !1, this;
1587
+ set isOpened(e) {
1588
+ this.state.set("isOpened", e);
1492
1589
  }
1493
1590
  /**
1494
- * Shows the Main Button. Note that opening the Mini App from the attachment menu hides the
1495
- * main button until the user interacts with the Mini App interface.
1591
+ * True if popup is currently opened.
1496
1592
  */
1497
- show() {
1498
- return this.isVisible = !0, this;
1593
+ get isOpened() {
1594
+ return this.state.get("isOpened");
1499
1595
  }
1500
1596
  /**
1501
- * A method to show a loading indicator on the Main Button. It is recommended to display
1502
- * loader if the action tied to the button may take a long time.
1597
+ * A method that shows a native popup described by the `params` argument.
1598
+ * Promise will be resolved when popup is closed. Resolved value will have
1599
+ * an identifier of pressed button.
1600
+ *
1601
+ * In case, user clicked outside the popup or clicked top right popup close
1602
+ * button, null will be returned.
1603
+ *
1604
+ * FIXME: In desktop, this function may work incorrectly.
1605
+ * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7
1606
+ * @param options - popup parameters.
1607
+ * @throws {Error} Popup is already opened.
1503
1608
  */
1504
- showLoader() {
1505
- return this.isLoaderVisible = !0, this;
1609
+ open(e) {
1610
+ if (this.isOpened)
1611
+ throw new Error("Popup is already opened.");
1612
+ return this.isOpened = !0, y("web_app_open_popup", "popup_closed", {
1613
+ postEvent: this.postEvent,
1614
+ params: _t(e)
1615
+ }).then(({ button_id: t = null }) => t).finally(() => {
1616
+ this.isOpened = !1;
1617
+ });
1506
1618
  }
1507
- /**
1508
- * Sets new Main Button text. Minimal length for text is 1 symbol, and maximum is 64 symbols.
1509
- * @param text - new text.
1510
- */
1511
- setText(e) {
1512
- return this.setParams({ text: e });
1619
+ }
1620
+ class mt {
1621
+ constructor(e, t = d) {
1622
+ o(this, "ee", new w());
1623
+ o(this, "state");
1624
+ /**
1625
+ * Adds new event listener.
1626
+ */
1627
+ o(this, "on", this.ee.on.bind(this.ee));
1628
+ /**
1629
+ * Removes event listener.
1630
+ */
1631
+ o(this, "off", this.ee.off.bind(this.ee));
1632
+ /**
1633
+ * Checks if specified method is supported by current component.
1634
+ */
1635
+ o(this, "supports");
1636
+ this.postEvent = t, this.state = new m({ isOpened: !1 }, this.ee), this.supports = C(e, {
1637
+ close: "web_app_close_scan_qr_popup",
1638
+ open: "web_app_open_scan_qr_popup"
1639
+ });
1513
1640
  }
1514
1641
  /**
1515
- * Sets new Main Button text color.
1516
- * @param textColor - new text color.
1642
+ * Closes scanner.
1517
1643
  */
1518
- setTextColor(e) {
1519
- return this.setParams({ textColor: e });
1644
+ close() {
1645
+ this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
1646
+ }
1647
+ set isOpened(e) {
1648
+ this.state.set("isOpened", e);
1520
1649
  }
1521
1650
  /**
1522
- * Updates current Main Button color.
1523
- * @param backgroundColor - color to set.
1651
+ * Returns true in case, QR scanner is currently opened.
1524
1652
  */
1525
- setBackgroundColor(e) {
1526
- return this.setParams({ backgroundColor: e });
1653
+ get isOpened() {
1654
+ return this.state.get("isOpened");
1527
1655
  }
1528
1656
  /**
1529
- * Allows setting multiple Main Button parameters.
1530
- * @param params - Main Button parameters.
1657
+ * Opens scanner with specified title shown to user. Method returns promise
1658
+ * with scanned QR content in case, it was scanned. It will contain null in
1659
+ * case, scanner was closed.
1660
+ * @param text - title to display.
1531
1661
  */
1532
- setParams(e) {
1533
- return this.state.set(e), this.commit(), this;
1534
- }
1535
- }
1536
- function At(r, e, t, s) {
1537
- const {
1538
- backgroundColor: n = e,
1539
- isEnabled: i = !1,
1540
- isVisible: a = !1,
1541
- isLoaderVisible: c = !1,
1542
- textColor: u = t,
1543
- text: p = ""
1544
- } = r ? D("main-button") || {} : {}, g = new qt({
1545
- backgroundColor: n,
1546
- isEnabled: i,
1547
- isLoaderVisible: c,
1548
- isVisible: a,
1549
- postEvent: s,
1550
- text: p,
1551
- textColor: u
1552
- }), _ = () => B("main-button", {
1553
- backgroundColor: g.backgroundColor,
1554
- isEnabled: g.isEnabled,
1555
- isLoaderVisible: g.isLoaderVisible,
1556
- isVisible: g.isVisible,
1557
- text: g.text,
1558
- textColor: g.textColor
1559
- });
1560
- return g.on("change", _), g;
1561
- }
1562
- const Vt = ee({
1563
- contact: f({
1564
- userId: {
1565
- type: A(),
1566
- from: "user_id"
1567
- },
1568
- phoneNumber: {
1569
- type: h(),
1570
- from: "phone_number"
1571
- },
1572
- firstName: {
1573
- type: h(),
1574
- from: "first_name"
1575
- },
1576
- lastName: {
1577
- type: h().optional(),
1578
- from: "last_name"
1662
+ async open(e) {
1663
+ if (this.isOpened)
1664
+ throw new Error("QR scanner is already opened.");
1665
+ this.isOpened = !0;
1666
+ try {
1667
+ const t = await y(
1668
+ "web_app_open_scan_qr_popup",
1669
+ ["qr_text_received", "scan_qr_popup_closed"],
1670
+ {
1671
+ postEvent: this.postEvent,
1672
+ params: { text: e }
1673
+ }
1674
+ );
1675
+ return typeof t == "object" && typeof t.data == "string" ? t.data : null;
1676
+ } finally {
1677
+ this.isOpened = !1;
1579
1678
  }
1580
- }),
1581
- authDate: {
1582
- type: fe(),
1583
- from: "auth_date"
1584
- },
1585
- hash: h()
1586
- });
1587
- class Rt {
1588
- constructor(e) {
1679
+ }
1680
+ }
1681
+ class yt {
1682
+ constructor(e, t, s = d) {
1589
1683
  o(this, "ee", new w());
1590
1684
  o(this, "state");
1591
- o(this, "botInline");
1592
- o(this, "postEvent");
1593
- o(this, "createRequestId");
1594
- o(this, "requestingPhoneAccess", !1);
1595
- o(this, "requestingWriteAccess", !1);
1596
1685
  /**
1597
- * Adds new event listener.
1686
+ * Adds event listener.
1687
+ * @param event - event name.
1688
+ * @param listener - event listener.
1598
1689
  */
1599
- o(this, "on", this.ee.on.bind(this.ee));
1690
+ o(this, "on", (e, t) => e === "click" ? E("settings_button_pressed", t) : this.ee.on(e, t));
1600
1691
  /**
1601
1692
  * Removes event listener.
1693
+ * @param event - event name.
1694
+ * @param listener - event listener.
1602
1695
  */
1603
- o(this, "off", this.ee.off.bind(this.ee));
1696
+ o(this, "off", (e, t) => e === "click" ? I("settings_button_pressed", t) : this.ee.off(e, t));
1604
1697
  /**
1605
1698
  * Checks if specified method is supported by current component.
1606
1699
  */
1607
1700
  o(this, "supports");
1608
- /**
1609
- * Checks if specified method parameter is supported by current component.
1610
- */
1611
- o(this, "supportsParam");
1612
- const {
1613
- postEvent: t = d,
1614
- headerColor: s,
1615
- backgroundColor: n,
1616
- version: i,
1617
- botInline: a,
1618
- createRequestId: c
1619
- } = e, u = E(i, {
1620
- requestPhoneAccess: "web_app_request_phone",
1621
- requestWriteAccess: "web_app_request_write_access",
1622
- switchInlineQuery: "web_app_switch_inline_query",
1623
- setHeaderColor: "web_app_set_header_color",
1624
- setBackgroundColor: "web_app_set_background_color"
1625
- });
1626
- this.postEvent = t, this.botInline = a, this.createRequestId = c, this.supports = (p) => !(!u(p) || p === "switchInlineQuery" && !a), this.state = new b({ backgroundColor: n, headerColor: s }, this.ee), this.supportsParam = Se(i, {
1627
- "setHeaderColor.color": ["web_app_set_header_color", "color"]
1701
+ this.postEvent = s, this.state = new m({ isVisible: e }, this.ee), this.supports = C(t, {
1702
+ show: "web_app_setup_settings_button",
1703
+ hide: "web_app_setup_settings_button"
1628
1704
  });
1629
1705
  }
1630
- /**
1631
- * Attempts to get requested contact.
1632
- */
1633
- async getRequestedContact() {
1634
- return H(
1635
- "getRequestedContact",
1636
- {},
1637
- this.createRequestId(),
1638
- {
1639
- postEvent: this.postEvent,
1640
- timeout: 1e4
1641
- }
1642
- ).then((e) => Vt.parse(e));
1706
+ set isVisible(e) {
1707
+ this.state.set("isVisible", e), this.postEvent("web_app_setup_settings_button", { is_visible: e });
1643
1708
  }
1644
1709
  /**
1645
- * The Mini App background color.
1710
+ * True if SettingsButton is currently visible.
1646
1711
  */
1647
- get backgroundColor() {
1648
- return this.state.get("backgroundColor");
1712
+ get isVisible() {
1713
+ return this.state.get("isVisible");
1649
1714
  }
1650
1715
  /**
1651
- * Closes the Mini App.
1716
+ * Hides the SettingsButton.
1652
1717
  */
1653
- close() {
1654
- this.postEvent("web_app_close");
1718
+ hide() {
1719
+ this.isVisible = !1;
1655
1720
  }
1656
1721
  /**
1657
- * The Mini App header color. Could either be a header color key or RGB color.
1722
+ * Shows the SettingsButton.
1658
1723
  */
1659
- get headerColor() {
1660
- return this.state.get("headerColor");
1724
+ show() {
1725
+ this.isVisible = !0;
1661
1726
  }
1662
- /**
1663
- * True if Mini App is currently launched in bot inline mode.
1664
- */
1665
- get isBotInline() {
1666
- return this.botInline;
1727
+ }
1728
+ function Et(r) {
1729
+ return r.replace(/(^|_)bg/, (e, t) => `${t}background`).replace(/_([a-z])/g, (e, t) => t.toUpperCase());
1730
+ }
1731
+ function Ct(r) {
1732
+ return r.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`).replace(/(^|_)background/, (e, t) => `${t}bg`);
1733
+ }
1734
+ const Ee = R(
1735
+ (r) => {
1736
+ const e = ge().optional();
1737
+ return Object.entries(Y(r)).reduce((t, [s, n]) => (t[Et(s)] = e.parse(n), t), {});
1738
+ },
1739
+ "ThemeParams"
1740
+ );
1741
+ function Ce(r) {
1742
+ return Ee().parse(r);
1743
+ }
1744
+ function tr(r) {
1745
+ return y("web_app_request_theme", "theme_changed", r).then(Ce);
1746
+ }
1747
+ function vt(r) {
1748
+ return JSON.stringify(
1749
+ Object.entries(r).reduce((e, [t, s]) => (s && (e[Ct(t)] = s), e), {})
1750
+ );
1751
+ }
1752
+ class Pt {
1753
+ constructor(e) {
1754
+ o(this, "ee", new w());
1755
+ o(this, "state");
1756
+ /**
1757
+ * Adds new event listener.
1758
+ */
1759
+ o(this, "on", this.ee.on.bind(this.ee));
1760
+ /**
1761
+ * Removes event listener.
1762
+ */
1763
+ o(this, "off", this.ee.off.bind(this.ee));
1764
+ this.state = new m(e, this.ee);
1667
1765
  }
1668
1766
  /**
1669
- * True if current Mini App background color recognized as dark.
1767
+ * @since v6.10
1670
1768
  */
1671
- get isDark() {
1672
- return we(this.backgroundColor);
1769
+ get accentTextColor() {
1770
+ return this.get("accentTextColor");
1673
1771
  }
1674
- /**
1675
- * True if phone access is currently being requested.
1676
- */
1677
- get isRequestingPhoneAccess() {
1678
- return this.requestingPhoneAccess;
1772
+ get backgroundColor() {
1773
+ return this.get("backgroundColor");
1679
1774
  }
1680
- /**
1681
- * True if write access is currently being requested.
1682
- */
1683
- get isRequestingWriteAccess() {
1684
- return this.requestingWriteAccess;
1775
+ get buttonColor() {
1776
+ return this.get("buttonColor");
1685
1777
  }
1686
- /**
1687
- * Informs the Telegram app that the Mini App is ready to be displayed.
1688
- *
1689
- * It is recommended to call this method as early as possible, as soon as all essential
1690
- * interface elements loaded. Once this method called, the loading placeholder is hidden
1691
- * and the Mini App shown.
1692
- *
1693
- * If the method not called, the placeholder will be hidden only when the page fully loaded.
1694
- */
1695
- ready() {
1696
- this.postEvent("web_app_ready");
1778
+ get buttonTextColor() {
1779
+ return this.get("buttonTextColor");
1780
+ }
1781
+ get destructiveTextColor() {
1782
+ return this.get("destructiveTextColor");
1697
1783
  }
1698
1784
  /**
1699
- * Requests current user contact information. In contrary to requestPhoneAccess, this method
1700
- * returns promise with contact information that rejects in case, user denied access, or request
1701
- * failed.
1702
- * @param options - additional options.
1785
+ * Retrieves palette color value by its name.
1786
+ * @param key - palette key name.
1703
1787
  */
1704
- async requestContact({ timeout: e = 5e3 } = {}) {
1705
- try {
1706
- return await this.getRequestedContact();
1707
- } catch {
1708
- }
1709
- if (await this.requestPhoneAccess() !== "sent")
1710
- throw new Error("Access denied.");
1711
- const s = Date.now() + e;
1712
- let n = 50;
1713
- return xe(async () => {
1714
- for (; Date.now() < s; ) {
1715
- try {
1716
- return await this.getRequestedContact();
1717
- } catch {
1718
- }
1719
- await wt(n), n += 50;
1720
- }
1721
- throw new Error("Unable to retrieve requested contact.");
1722
- }, e);
1788
+ get(e) {
1789
+ return this.state.get(e);
1723
1790
  }
1724
1791
  /**
1725
- * Requests current user phone access. Method returns promise, which resolves
1726
- * status of the request. In case, user accepted the request, Mini App bot will receive
1727
- * the according notification.
1728
- *
1729
- * To obtain the retrieved information instead, utilize the requestContact method.
1730
- * @param options - additional options.
1731
- * @see requestContact
1792
+ * Returns the copy of the internal state of the current component instance.
1732
1793
  */
1733
- requestPhoneAccess(e = {}) {
1734
- if (this.requestingPhoneAccess)
1735
- throw new Error("Phone access is already being requested.");
1736
- return this.requestingPhoneAccess = !0, m("web_app_request_phone", "phone_requested", {
1737
- ...e,
1738
- postEvent: this.postEvent
1739
- }).then((t) => t.status).finally(() => {
1740
- this.requestingPhoneAccess = !1;
1741
- });
1794
+ getState() {
1795
+ return this.state.clone();
1742
1796
  }
1743
1797
  /**
1744
- * Requests write message access to current user.
1745
- * @param options - additional options.
1798
+ * @since v6.10
1746
1799
  */
1747
- requestWriteAccess(e = {}) {
1748
- if (this.requestingWriteAccess)
1749
- throw new Error("Write access is already being requested.");
1750
- return this.requestingWriteAccess = !0, m("web_app_request_write_access", "write_access_requested", {
1751
- ...e,
1752
- postEvent: this.postEvent
1753
- }).then((t) => t.status).finally(() => {
1754
- this.requestingWriteAccess = !1;
1755
- });
1800
+ get headerBackgroundColor() {
1801
+ return this.get("headerBackgroundColor");
1802
+ }
1803
+ get hintColor() {
1804
+ return this.get("hintColor");
1756
1805
  }
1757
1806
  /**
1758
- * A method used to send data to the bot. When this method called, a service message sent to
1759
- * the bot containing the data of the length up to 4096 bytes, and the Mini App closed. See the
1760
- * field `web_app_data` in the class [Message](https://core.telegram.org/bots/api#message).
1761
- *
1762
- * This method is only available for Mini Apps launched via a Keyboard button.
1763
- * @param data - data to send to bot.
1764
- * @throws {Error} data has incorrect size.
1807
+ * Returns true in case, current color scheme is recognized as dark. This
1808
+ * value is calculated according to theme background color.
1765
1809
  */
1766
- sendData(e) {
1767
- const { size: t } = new Blob([e]);
1768
- if (t === 0 || t > 4096)
1769
- throw new Error(`Passed data has incorrect size: ${t}`);
1770
- this.postEvent("web_app_data_send", { data: e });
1810
+ get isDark() {
1811
+ return !this.backgroundColor || _e(this.backgroundColor);
1812
+ }
1813
+ get linkColor() {
1814
+ return this.get("linkColor");
1815
+ }
1816
+ get secondaryBackgroundColor() {
1817
+ return this.get("secondaryBackgroundColor");
1771
1818
  }
1772
1819
  /**
1773
- * Updates current Mini App header color.
1774
- * @param color - color key or RGB color.
1820
+ * @since v6.10
1775
1821
  */
1776
- setHeaderColor(e) {
1777
- this.postEvent("web_app_set_header_color", X(e) ? { color: e } : { color_key: e }), this.state.set("headerColor", e);
1822
+ get sectionBackgroundColor() {
1823
+ return this.get("sectionBackgroundColor");
1778
1824
  }
1779
1825
  /**
1780
- * Updates current Mini App background color.
1781
- * @param color - RGB color.
1826
+ * @since v6.10
1782
1827
  */
1783
- setBackgroundColor(e) {
1784
- this.postEvent("web_app_set_background_color", { color: e }), this.state.set("backgroundColor", e);
1828
+ get sectionHeaderTextColor() {
1829
+ return this.get("sectionHeaderTextColor");
1785
1830
  }
1786
1831
  /**
1787
- * Inserts the bot's username and the specified inline query in the current chat's input field.
1788
- * Query may be empty, in which case only the bot's username will be inserted. The client prompts
1789
- * the user to choose a specific chat, then opens that chat and inserts the bot's username and
1790
- * the specified inline query in the input field.
1791
- * @param text - text which should be inserted in the input after the current bot name. Max
1792
- * length is 256 symbols.
1793
- * @param chatTypes - List of chat types which could be chosen to send the message. Could be
1794
- * empty list.
1832
+ * Starts listening to theme changes and applies them.
1833
+ * @returns Function to stop listening.
1795
1834
  */
1796
- switchInlineQuery(e, t = []) {
1797
- if (!this.supports("switchInlineQuery") && !this.isBotInline)
1798
- throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
1799
- this.postEvent("web_app_switch_inline_query", {
1800
- query: e,
1801
- chat_types: t
1835
+ listen() {
1836
+ return E("theme_changed", (e) => {
1837
+ this.state.set(Ce(e.theme_params));
1802
1838
  });
1803
1839
  }
1840
+ /**
1841
+ * @since v6.10
1842
+ */
1843
+ get subtitleTextColor() {
1844
+ return this.get("subtitleTextColor");
1845
+ }
1846
+ get textColor() {
1847
+ return this.get("textColor");
1848
+ }
1804
1849
  }
1805
- function It(r, e, t, s, n, i) {
1806
- const {
1807
- backgroundColor: a = e,
1808
- headerColor: c = "bg_color"
1809
- } = r ? D("mini-app") || {} : {}, u = new Rt({
1810
- headerColor: c,
1811
- backgroundColor: a,
1812
- version: t,
1813
- botInline: s,
1814
- createRequestId: n,
1815
- postEvent: i
1816
- }), p = () => B("mini-app", {
1817
- backgroundColor: u.backgroundColor,
1818
- headerColor: u.headerColor
1819
- });
1820
- return u.on("change", p), u;
1821
- }
1822
- function Lt() {
1823
- let r = 0;
1824
- return () => (r += 1, r.toString());
1825
- }
1826
- class Tt {
1850
+ class St {
1827
1851
  constructor(e, t, s = d) {
1828
- o(this, "ee", new w());
1829
- o(this, "state");
1830
- /**
1831
- * Adds event listener.
1832
- * @param event - event name.
1833
- * @param listener - event listener.
1834
- */
1835
- o(this, "on", (e, t) => e === "click" ? y("settings_button_pressed", t) : this.ee.on(e, t));
1836
- /**
1837
- * Removes event listener.
1838
- * @param event - event name.
1839
- * @param listener - event listener.
1840
- */
1841
- o(this, "off", (e, t) => e === "click" ? $("settings_button_pressed", t) : this.ee.off(e, t));
1842
1852
  /**
1843
1853
  * Checks if specified method is supported by current component.
1844
1854
  */
1845
1855
  o(this, "supports");
1846
- this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
1847
- show: "web_app_setup_settings_button",
1848
- hide: "web_app_setup_settings_button"
1856
+ /**
1857
+ * Checks if specified method parameter is supported by current component.
1858
+ */
1859
+ o(this, "supportsParam");
1860
+ this.version = e, this.createRequestId = t, this.postEvent = s, this.supports = C(e, {
1861
+ readTextFromClipboard: "web_app_read_text_from_clipboard"
1862
+ }), this.supportsParam = ye(e, {
1863
+ "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
1849
1864
  });
1850
1865
  }
1851
- set isVisible(e) {
1852
- this.state.set("isVisible", e), this.postEvent("web_app_setup_settings_button", { is_visible: e });
1853
- }
1854
1866
  /**
1855
- * True if SettingsButton is currently visible.
1867
+ * Opens a link in an external browser. The Mini App will not be closed.
1868
+ *
1869
+ * Note that this method can be called only in response to the user
1870
+ * interaction with the Mini App interface (e.g. click inside the Mini App
1871
+ * or on the main button).
1872
+ * @param url - URL to be opened.
1873
+ * @param tryInstantView
1856
1874
  */
1857
- get isVisible() {
1858
- return this.state.get("isVisible");
1875
+ openLink(e, t) {
1876
+ const s = new URL(e, window.location.href).toString();
1877
+ if (!A("web_app_open_link", this.version)) {
1878
+ window.open(s, "_blank");
1879
+ return;
1880
+ }
1881
+ this.postEvent("web_app_open_link", {
1882
+ url: s,
1883
+ ...typeof t == "boolean" ? { try_instant_view: t } : {}
1884
+ });
1859
1885
  }
1860
1886
  /**
1861
- * Hides the SettingsButton.
1887
+ * Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
1888
+ * link in full format, with hostname "t.me".
1889
+ * @param url - URL to be opened.
1890
+ * @throws {Error} URL has not allowed hostname.
1862
1891
  */
1863
- hide() {
1864
- this.isVisible = !1;
1892
+ openTelegramLink(e) {
1893
+ const {
1894
+ hostname: t,
1895
+ pathname: s,
1896
+ search: n
1897
+ } = new URL(e, window.location.href);
1898
+ if (t !== "t.me")
1899
+ throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);
1900
+ if (!A("web_app_open_tg_link", this.version)) {
1901
+ window.location.href = e;
1902
+ return;
1903
+ }
1904
+ this.postEvent("web_app_open_tg_link", { path_full: s + n });
1865
1905
  }
1866
1906
  /**
1867
- * Shows the SettingsButton.
1907
+ * Reads text from clipboard and returns string or null. null is returned
1908
+ * in cases:
1909
+ * - Value in clipboard is not text
1910
+ * - Access to clipboard is not allowed
1868
1911
  */
1869
- show() {
1870
- this.isVisible = !0;
1912
+ async readTextFromClipboard() {
1913
+ const e = this.createRequestId(), {
1914
+ data: t = null
1915
+ } = await y("web_app_read_text_from_clipboard", "clipboard_text_received", {
1916
+ postEvent: this.postEvent,
1917
+ params: { req_id: e },
1918
+ capture: le(e)
1919
+ });
1920
+ return t;
1871
1921
  }
1872
1922
  }
1873
- function $t(r, e, t) {
1874
- const { isVisible: s = !1 } = r ? D("settings-button") || {} : {}, n = new Tt(s, e, t);
1875
- return n.on("change", () => {
1876
- B("settings-button", { isVisible: n.isVisible });
1877
- }), n;
1878
- }
1879
- function Bt(r) {
1880
- const e = new Ue(r);
1881
- return e.listen(), e;
1882
- }
1883
- function Dt(r) {
1923
+ function kt(r) {
1884
1924
  return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
1885
1925
  }
1886
- async function Ae(r) {
1887
- const e = await m("web_app_request_viewport", "viewport_changed", r);
1926
+ async function ve(r) {
1927
+ const e = await y("web_app_request_viewport", "viewport_changed", r);
1888
1928
  return {
1889
1929
  height: e.height,
1890
1930
  width: e.width,
@@ -1892,10 +1932,10 @@ async function Ae(r) {
1892
1932
  isStateStable: e.is_state_stable
1893
1933
  };
1894
1934
  }
1895
- function W(r) {
1935
+ function L(r) {
1896
1936
  return r < 0 ? 0 : r;
1897
1937
  }
1898
- class Wt {
1938
+ class xt {
1899
1939
  constructor(e) {
1900
1940
  o(this, "ee", new w());
1901
1941
  o(this, "state");
@@ -1915,11 +1955,11 @@ class Wt {
1915
1955
  stableHeight: i,
1916
1956
  postEvent: a = d
1917
1957
  } = e;
1918
- this.postEvent = a, this.state = new b({
1919
- height: W(t),
1958
+ this.postEvent = a, this.state = new m({
1959
+ height: L(t),
1920
1960
  isExpanded: s,
1921
- stableHeight: W(i),
1922
- width: W(n)
1961
+ stableHeight: L(i),
1962
+ width: L(n)
1923
1963
  }, this.ee);
1924
1964
  }
1925
1965
  /**
@@ -1928,7 +1968,7 @@ class Wt {
1928
1968
  * @param options - options to request fresh data.
1929
1969
  */
1930
1970
  sync(e) {
1931
- return Ae(e).then(({ height: t, isExpanded: s, width: n, isStateStable: i }) => {
1971
+ return ve(e).then(({ height: t, isExpanded: s, width: n, isStateStable: i }) => {
1932
1972
  this.state.set({
1933
1973
  height: t,
1934
1974
  width: n,
@@ -1978,16 +2018,16 @@ class Wt {
1978
2018
  * @returns Function to stop listening.
1979
2019
  */
1980
2020
  listen() {
1981
- return y("viewport_changed", (e) => {
2021
+ return E("viewport_changed", (e) => {
1982
2022
  const {
1983
2023
  height: t,
1984
2024
  width: s,
1985
2025
  is_expanded: n,
1986
2026
  is_state_stable: i
1987
2027
  } = e, a = {
1988
- height: W(t),
2028
+ height: L(t),
1989
2029
  isExpanded: n,
1990
- width: W(s)
2030
+ width: L(s)
1991
2031
  };
1992
2032
  i && (a.stableHeight = a.height), this.state.set(a);
1993
2033
  });
@@ -2024,21 +2064,145 @@ class Wt {
2024
2064
  return this.stableHeight === this.height;
2025
2065
  }
2026
2066
  }
2027
- function G(r) {
2028
- const e = new Wt(r);
2029
- return e.on("change", () => B("viewport", {
2067
+ function S(r, e) {
2068
+ document.documentElement.style.setProperty(r, e);
2069
+ }
2070
+ function qt(r, e) {
2071
+ const t = () => {
2072
+ S("--tg-background-color", r.backgroundColor);
2073
+ }, s = () => {
2074
+ const {
2075
+ backgroundColor: n,
2076
+ secondaryBackgroundColor: i
2077
+ } = e;
2078
+ if (X(r.headerColor)) {
2079
+ S("--tg-header-color", r.headerColor);
2080
+ return;
2081
+ }
2082
+ if (r.headerColor === "bg_color" && n) {
2083
+ S("--tg-header-color", n);
2084
+ return;
2085
+ }
2086
+ r.headerColor === "secondary_bg_color" && i && S("--tg-header-color", i);
2087
+ };
2088
+ e.on("change", s), r.on("change:backgroundColor", t), r.on("change:headerColor", s), t(), s();
2089
+ }
2090
+ function At(r) {
2091
+ const e = () => {
2092
+ const t = r.getState();
2093
+ Object.entries(t).forEach(([s, n]) => {
2094
+ if (n) {
2095
+ const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
2096
+ S(`--tg-theme-${i}`, n);
2097
+ }
2098
+ });
2099
+ };
2100
+ r.on("change", e), e();
2101
+ }
2102
+ function oe(r) {
2103
+ const e = () => S("--tg-viewport-height", `${r.height}px`), t = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-stable-height", `${r.stableHeight}px`);
2104
+ r.on("change:height", e), r.on("change:width", t), r.on("change:stableHeight", s), e(), t(), s();
2105
+ }
2106
+ function Vt() {
2107
+ const r = document.createElement("style");
2108
+ r.id = "telegram-custom-styles", document.head.appendChild(r), E("set_custom_style", (e) => {
2109
+ r.innerHTML = e;
2110
+ });
2111
+ }
2112
+ function Pe(r) {
2113
+ return `telegram-mini-apps-${r}`;
2114
+ }
2115
+ function T(r, e) {
2116
+ sessionStorage.setItem(Pe(r), JSON.stringify(e));
2117
+ }
2118
+ function $(r) {
2119
+ const e = sessionStorage.getItem(Pe(r));
2120
+ return e ? JSON.parse(e) : null;
2121
+ }
2122
+ function Rt(r, e, t) {
2123
+ const { isVisible: s = !1 } = r ? $("back-button") || {} : {}, n = new rt(s, e, t);
2124
+ return n.on("change", () => {
2125
+ T("back-button", { isVisible: n.isVisible });
2126
+ }), n;
2127
+ }
2128
+ function It(r, e) {
2129
+ const { isConfirmationNeeded: t = !1 } = r ? $("closing-behavior") || {} : {}, s = new st(t, e);
2130
+ return s.on("change", () => T("closing-behavior", {
2131
+ isConfirmationNeeded: s.isConfirmationNeeded
2132
+ })), s;
2133
+ }
2134
+ function Tt(r, e, t, s) {
2135
+ const {
2136
+ backgroundColor: n = e,
2137
+ isEnabled: i = !1,
2138
+ isVisible: a = !1,
2139
+ isLoaderVisible: c = !1,
2140
+ textColor: u = t,
2141
+ text: p = ""
2142
+ } = r ? $("main-button") || {} : {}, g = new dt({
2143
+ backgroundColor: n,
2144
+ isEnabled: i,
2145
+ isLoaderVisible: c,
2146
+ isVisible: a,
2147
+ postEvent: s,
2148
+ text: p,
2149
+ textColor: u
2150
+ }), _ = () => T("main-button", {
2151
+ backgroundColor: g.backgroundColor,
2152
+ isEnabled: g.isEnabled,
2153
+ isLoaderVisible: g.isLoaderVisible,
2154
+ isVisible: g.isVisible,
2155
+ text: g.text,
2156
+ textColor: g.textColor
2157
+ });
2158
+ return g.on("change", _), g;
2159
+ }
2160
+ function $t(r, e, t, s, n, i) {
2161
+ const {
2162
+ backgroundColor: a = e,
2163
+ headerColor: c = "bg_color"
2164
+ } = r ? $("mini-app") || {} : {}, u = new wt({
2165
+ headerColor: c,
2166
+ backgroundColor: a,
2167
+ version: t,
2168
+ botInline: s,
2169
+ createRequestId: n,
2170
+ postEvent: i
2171
+ }), p = () => T("mini-app", {
2172
+ backgroundColor: u.backgroundColor,
2173
+ headerColor: u.headerColor
2174
+ });
2175
+ return u.on("change", p), u;
2176
+ }
2177
+ function Lt() {
2178
+ let r = 0;
2179
+ return () => (r += 1, r.toString());
2180
+ }
2181
+ function Bt(r, e, t) {
2182
+ const { isVisible: s = !1 } = r ? $("settings-button") || {} : {}, n = new yt(s, e, t);
2183
+ return n.on("change", () => {
2184
+ T("settings-button", { isVisible: n.isVisible });
2185
+ }), n;
2186
+ }
2187
+ function Ot(r) {
2188
+ const e = new Pt(r);
2189
+ return e.listen(), e;
2190
+ }
2191
+ function N(r) {
2192
+ const e = new xt(r);
2193
+ return e.on("change", () => T("viewport", {
2030
2194
  height: e.height,
2031
2195
  isExpanded: e.isExpanded,
2032
2196
  stableHeight: e.stableHeight,
2033
2197
  width: e.width
2034
2198
  })), e.listen(), e;
2035
2199
  }
2036
- function Ot(r, e, t, s) {
2037
- const n = r ? D("viewport") : null;
2200
+ function Dt(r, e, t, s) {
2201
+ const n = r ? $("viewport") : null;
2038
2202
  if (n)
2039
- return G({ ...n, postEvent: t });
2040
- if (Dt(e))
2041
- return G({
2203
+ return N({ ...n, postEvent: t });
2204
+ if (kt(e))
2205
+ return N({
2042
2206
  height: window.innerHeight,
2043
2207
  isExpanded: !0,
2044
2208
  postEvent: t,
@@ -2046,15 +2210,15 @@ function Ot(r, e, t, s) {
2046
2210
  width: window.innerWidth
2047
2211
  });
2048
2212
  if (s)
2049
- return Ae({
2213
+ return ve({
2050
2214
  postEvent: t,
2051
2215
  timeout: 5e3
2052
- }).then(({ height: a, isStateStable: c, ...u }) => G({
2216
+ }).then(({ height: a, isStateStable: c, ...u }) => N({
2053
2217
  ...u,
2054
2218
  height: a,
2055
2219
  stableHeight: c ? a : 0
2056
2220
  }));
2057
- const i = G({
2221
+ const i = N({
2058
2222
  width: 0,
2059
2223
  height: 0,
2060
2224
  isExpanded: !1,
@@ -2065,283 +2229,115 @@ function Ot(r, e, t, s) {
2065
2229
  console.error("Unable to actualize viewport state", a);
2066
2230
  }), i;
2067
2231
  }
2068
- function Ht(r) {
2232
+ function Wt(r) {
2069
2233
  return typeof r == "object" ? r : r ? {
2070
- themeParams: !0,
2071
- viewport: !0,
2072
- miniApp: !0
2073
- } : {};
2074
- }
2075
- function ce(r, e, t, s) {
2076
- const n = Ht(r);
2077
- n.miniApp && Ct(e, t), n.themeParams && vt(t), n.viewport && (s instanceof Promise ? s.then(ae) : ae(s));
2078
- }
2079
- function Nt(r) {
2080
- const { hostname: e, pathname: t } = new URL(r, window.location.href);
2081
- if (e !== "t.me")
2082
- throw new Error(`Incorrect hostname: ${e}`);
2083
- const s = t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
2084
- if (s === null)
2085
- throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
2086
- return s[2];
2087
- }
2088
- class Ut {
2089
- constructor(e, t = d) {
2090
- o(this, "ee", new w());
2091
- o(this, "state");
2092
- /**
2093
- * Adds new event listener.
2094
- */
2095
- o(this, "on", this.ee.on.bind(this.ee));
2096
- /**
2097
- * Removes event listener.
2098
- */
2099
- o(this, "off", this.ee.off.bind(this.ee));
2100
- /**
2101
- * Checks if specified method is supported by current component.
2102
- */
2103
- o(this, "supports");
2104
- this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, { open: "web_app_open_invoice" });
2105
- }
2106
- set isOpened(e) {
2107
- this.state.set("isOpened", e);
2108
- }
2109
- /**
2110
- * True if invoice is currently opened.
2111
- */
2112
- get isOpened() {
2113
- return this.state.get("isOpened");
2114
- }
2115
- async open(e, t) {
2116
- if (this.isOpened)
2117
- throw new Error("Invoice is already opened");
2118
- const s = t ? Nt(e) : e;
2119
- this.isOpened = !0;
2120
- try {
2121
- return (await m(
2122
- "web_app_open_invoice",
2123
- { slug: s },
2124
- "invoice_closed",
2125
- {
2126
- postEvent: this.postEvent,
2127
- capture(i) {
2128
- return s === i.slug;
2129
- }
2130
- }
2131
- )).status;
2132
- } finally {
2133
- this.isOpened = !1;
2234
+ themeParams: !0,
2235
+ viewport: !0,
2236
+ miniApp: !0
2237
+ } : {};
2238
+ }
2239
+ function ae(r, e, t, s) {
2240
+ const n = Wt(r);
2241
+ n.miniApp && qt(e, t), n.themeParams && At(t), n.viewport && (s instanceof Promise ? s.then(oe) : oe(s));
2242
+ }
2243
+ function Ht() {
2244
+ return ee({
2245
+ botInline: {
2246
+ type: P().optional(),
2247
+ from: "tgWebAppBotInline"
2248
+ },
2249
+ initData: {
2250
+ type: me().optional(),
2251
+ from: "tgWebAppData"
2252
+ },
2253
+ initDataRaw: {
2254
+ type: h().optional(),
2255
+ from: "tgWebAppData"
2256
+ },
2257
+ platform: {
2258
+ type: h(),
2259
+ from: "tgWebAppPlatform"
2260
+ },
2261
+ showSettings: {
2262
+ type: P().optional(),
2263
+ from: "tgWebAppShowSettings"
2264
+ },
2265
+ startParam: {
2266
+ type: h().optional(),
2267
+ from: "tgWebAppStartParam"
2268
+ },
2269
+ themeParams: {
2270
+ type: Ee(),
2271
+ from: "tgWebAppThemeParams"
2272
+ },
2273
+ version: {
2274
+ type: h(),
2275
+ from: "tgWebAppVersion"
2134
2276
  }
2135
- }
2277
+ }, "LaunchParams");
2278
+ }
2279
+ function Se(r) {
2280
+ return Ht().parse(r);
2281
+ }
2282
+ function ke(r) {
2283
+ const e = r.includes("?") ? r.replace("#", "&").slice(r.indexOf("?") + 1) : r.slice(r.indexOf("#") + 1);
2284
+ return Se(e);
2285
+ }
2286
+ function Nt() {
2287
+ return ke(window.location.href);
2288
+ }
2289
+ function xe() {
2290
+ return performance.getEntriesByType("navigation")[0];
2291
+ }
2292
+ function Ut() {
2293
+ const r = xe();
2294
+ if (!r)
2295
+ throw new Error("Unable to get first navigation entry.");
2296
+ return ke(r.name);
2136
2297
  }
2137
2298
  function Mt(r) {
2138
- const e = r.message.trim(), t = (r.title || "").trim(), s = r.buttons || [];
2139
- let n;
2140
- if (t.length > 64)
2141
- throw new Error(`Title has incorrect size: ${t.length}`);
2142
- if (e.length === 0 || e.length > 256)
2143
- throw new Error(`Message has incorrect size: ${e.length}`);
2144
- if (s.length > 3)
2145
- throw new Error(`Buttons have incorrect size: ${s.length}`);
2146
- return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
2147
- const { id: a = "" } = i;
2148
- if (a.length > 64)
2149
- throw new Error(`Button ID has incorrect size: ${a}`);
2150
- if (i.type === void 0 || i.type === "default" || i.type === "destructive") {
2151
- const c = i.text.trim();
2152
- if (c.length === 0 || c.length > 64) {
2153
- const u = i.type || "default";
2154
- throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`);
2155
- }
2156
- return { ...i, text: c, id: a };
2157
- }
2158
- return { ...i, id: a };
2159
- }), { title: t, message: e, buttons: n };
2299
+ const {
2300
+ initDataRaw: e,
2301
+ themeParams: t,
2302
+ platform: s,
2303
+ version: n,
2304
+ showSettings: i,
2305
+ startParam: a,
2306
+ botInline: c
2307
+ } = r, u = new URLSearchParams();
2308
+ return e && u.set("tgWebAppData", e), u.set("tgWebAppPlatform", s), u.set("tgWebAppThemeParams", vt(t)), u.set("tgWebAppVersion", n), a && u.set("tgWebAppStartParam", n), typeof i == "boolean" && u.set("tgWebAppShowSettings", i ? "1" : "0"), typeof c == "boolean" && u.set("tgWebAppBotInline", c ? "1" : "0"), u.toString();
2160
2309
  }
2161
- class Gt {
2162
- constructor(e, t = d) {
2163
- o(this, "ee", new w());
2164
- o(this, "state");
2165
- /**
2166
- * Adds new event listener.
2167
- */
2168
- o(this, "on", this.ee.on.bind(this.ee));
2169
- /**
2170
- * Removes event listener.
2171
- */
2172
- o(this, "off", this.ee.off.bind(this.ee));
2173
- /**
2174
- * Checks if specified method is supported by current component.
2175
- */
2176
- o(this, "supports");
2177
- this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, { open: "web_app_open_popup" });
2178
- }
2179
- set isOpened(e) {
2180
- this.state.set("isOpened", e);
2181
- }
2182
- /**
2183
- * True if popup is currently opened.
2184
- */
2185
- get isOpened() {
2186
- return this.state.get("isOpened");
2187
- }
2188
- /**
2189
- * A method that shows a native popup described by the `params` argument.
2190
- * Promise will be resolved when popup is closed. Resolved value will have
2191
- * an identifier of pressed button.
2192
- *
2193
- * In case, user clicked outside the popup or clicked top right popup close
2194
- * button, null will be returned.
2195
- *
2196
- * FIXME: In desktop, this function may work incorrectly.
2197
- * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7
2198
- * @param options - popup parameters.
2199
- * @throws {Error} Popup is already opened.
2200
- */
2201
- open(e) {
2202
- if (this.isOpened)
2203
- throw new Error("Popup is already opened.");
2204
- return this.isOpened = !0, m(
2205
- "web_app_open_popup",
2206
- Mt(e),
2207
- "popup_closed",
2208
- { postEvent: this.postEvent }
2209
- ).then(({ button_id: t = null }) => t).finally(() => {
2210
- this.isOpened = !1;
2211
- });
2212
- }
2310
+ const qe = "telegram-mini-apps-launch-params";
2311
+ function Gt() {
2312
+ return Se(sessionStorage.getItem(qe) || "");
2213
2313
  }
2214
- class jt {
2215
- constructor(e, t = d) {
2216
- o(this, "ee", new w());
2217
- o(this, "state");
2218
- /**
2219
- * Adds new event listener.
2220
- */
2221
- o(this, "on", this.ee.on.bind(this.ee));
2222
- /**
2223
- * Removes event listener.
2224
- */
2225
- o(this, "off", this.ee.off.bind(this.ee));
2226
- /**
2227
- * Checks if specified method is supported by current component.
2228
- */
2229
- o(this, "supports");
2230
- this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, {
2231
- close: "web_app_close_scan_qr_popup",
2232
- open: "web_app_open_scan_qr_popup"
2233
- });
2234
- }
2235
- /**
2236
- * Closes scanner.
2237
- */
2238
- close() {
2239
- this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
2240
- }
2241
- set isOpened(e) {
2242
- this.state.set("isOpened", e);
2243
- }
2244
- /**
2245
- * Returns true in case, QR scanner is currently opened.
2246
- */
2247
- get isOpened() {
2248
- return this.state.get("isOpened");
2249
- }
2250
- /**
2251
- * Opens scanner with specified title shown to user. Method returns promise
2252
- * with scanned QR content in case, it was scanned. It will contain null in
2253
- * case, scanner was closed.
2254
- * @param text - title to display.
2255
- */
2256
- async open(e) {
2257
- if (this.isOpened)
2258
- throw new Error("QR scanner is already opened.");
2259
- this.isOpened = !0;
2314
+ function jt(r) {
2315
+ sessionStorage.setItem(qe, Mt(r));
2316
+ }
2317
+ function te() {
2318
+ const r = [];
2319
+ for (const e of [
2320
+ // Try to retrieve launch parameters from the current location. This method can return
2321
+ // nothing in case, location was changed and then page was reloaded.
2322
+ Nt,
2323
+ // Then, try using the lower level API - window.performance.
2324
+ Ut,
2325
+ // Finally, try to extract launch parameters from the session storage.
2326
+ Gt
2327
+ ])
2260
2328
  try {
2261
- const t = await m(
2262
- "web_app_open_scan_qr_popup",
2263
- { text: e },
2264
- ["qr_text_received", "scan_qr_popup_closed"],
2265
- { postEvent: this.postEvent }
2266
- );
2267
- return typeof t == "object" && typeof t.data == "string" ? t.data : null;
2268
- } finally {
2269
- this.isOpened = !1;
2329
+ const t = e();
2330
+ return jt(t), t;
2331
+ } catch (t) {
2332
+ r.push(t);
2270
2333
  }
2271
- }
2334
+ throw k.error("Unable to extract launch parameters. Received errors:", r), new Error("Unable to retrieve launch parameters from any known source.");
2272
2335
  }
2273
- class Ft {
2274
- constructor(e, t, s = d) {
2275
- /**
2276
- * Checks if specified method is supported by current component.
2277
- */
2278
- o(this, "supports");
2279
- /**
2280
- * Checks if specified method parameter is supported by current component.
2281
- */
2282
- o(this, "supportsParam");
2283
- this.version = e, this.createRequestId = t, this.postEvent = s, this.supports = E(e, {
2284
- readTextFromClipboard: "web_app_read_text_from_clipboard"
2285
- }), this.supportsParam = Se(e, {
2286
- "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
2287
- });
2288
- }
2289
- /**
2290
- * Opens a link in an external browser. The Mini App will not be closed.
2291
- *
2292
- * Note that this method can be called only in response to the user
2293
- * interaction with the Mini App interface (e.g. click inside the Mini App
2294
- * or on the main button).
2295
- * @param url - URL to be opened.
2296
- * @param tryInstantView
2297
- */
2298
- openLink(e, t) {
2299
- const s = new URL(e, window.location.href).toString();
2300
- if (!I("web_app_open_link", this.version)) {
2301
- window.open(s, "_blank");
2302
- return;
2303
- }
2304
- this.postEvent("web_app_open_link", {
2305
- url: s,
2306
- ...typeof t == "boolean" ? { try_instant_view: t } : {}
2307
- });
2308
- }
2309
- /**
2310
- * Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
2311
- * link in full format, with hostname "t.me".
2312
- * @param url - URL to be opened.
2313
- * @throws {Error} URL has not allowed hostname.
2314
- */
2315
- openTelegramLink(e) {
2316
- const {
2317
- hostname: t,
2318
- pathname: s,
2319
- search: n
2320
- } = new URL(e, window.location.href);
2321
- if (t !== "t.me")
2322
- throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);
2323
- if (!I("web_app_open_tg_link", this.version)) {
2324
- window.location.href = e;
2325
- return;
2326
- }
2327
- this.postEvent("web_app_open_tg_link", { path_full: s + n });
2328
- }
2329
- /**
2330
- * Reads text from clipboard and returns string or null. null is returned
2331
- * in cases:
2332
- * - Value in clipboard is not text
2333
- * - Access to clipboard is not allowed
2334
- */
2335
- readTextFromClipboard() {
2336
- return m(
2337
- "web_app_read_text_from_clipboard",
2338
- { req_id: this.createRequestId() },
2339
- "clipboard_text_received",
2340
- { postEvent: this.postEvent }
2341
- ).then(({ data: e = null }) => e);
2342
- }
2336
+ function Ae() {
2337
+ var r;
2338
+ return ((r = xe()) == null ? void 0 : r.type) === "reload";
2343
2339
  }
2344
- function or(r = {}) {
2340
+ function rr(r = {}) {
2345
2341
  const {
2346
2342
  async: e = !1,
2347
2343
  complete: t = e,
@@ -2356,67 +2352,77 @@ function or(r = {}) {
2356
2352
  platform: u,
2357
2353
  themeParams: p,
2358
2354
  botInline: g = !1
2359
- } = te(), _ = le(), V = Lt(), l = gt(c);
2360
- pe() && (n && kt(), l("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => {
2355
+ } = te(), _ = Ae(), b = Lt(), l = Oe(c);
2356
+ pe() && (n && Vt(), l("iframe_ready", { reload_supported: !0 }), E("reload_iframe", () => {
2361
2357
  l("iframe_will_reload"), window.location.reload();
2362
2358
  }));
2363
- const C = {
2364
- backButton: St(_, c, l),
2365
- closingBehavior: xt(_, l),
2366
- cloudStorage: new Et(c, V, l),
2367
- createRequestId: V,
2368
- hapticFeedback: new Pt(c, l),
2369
- invoice: new Ut(c, l),
2370
- mainButton: At(
2359
+ const q = {
2360
+ backButton: Rt(_, c, l),
2361
+ closingBehavior: It(_, l),
2362
+ cloudStorage: new at(c, b, l),
2363
+ createRequestId: b,
2364
+ hapticFeedback: new ct(c, l),
2365
+ invoice: new lt(c, l),
2366
+ mainButton: Tt(
2371
2367
  _,
2372
2368
  p.buttonColor || "#000000",
2373
2369
  p.buttonTextColor || "#ffffff",
2374
2370
  l
2375
2371
  ),
2376
- miniApp: It(
2372
+ miniApp: $t(
2377
2373
  _,
2378
2374
  p.backgroundColor || "#ffffff",
2379
2375
  c,
2380
2376
  g,
2381
- V,
2377
+ b,
2382
2378
  l
2383
2379
  ),
2384
- popup: new Gt(c, l),
2380
+ popup: new bt(c, l),
2385
2381
  postEvent: l,
2386
- qrScanner: new jt(c, l),
2387
- settingsButton: $t(_, c, l),
2388
- themeParams: Bt(p),
2389
- utils: new Ft(c, V, l),
2382
+ qrScanner: new mt(c, l),
2383
+ settingsButton: Bt(_, c, l),
2384
+ themeParams: Ot(p),
2385
+ utils: new St(c, b, l),
2390
2386
  ...i ? {
2391
- initData: new We(i),
2387
+ initData: new ut(i),
2392
2388
  initDataRaw: a
2393
2389
  } : {}
2394
- }, x = Ot(_, u, l, t);
2395
- return x instanceof Promise || t ? Promise.resolve(x).then((v) => (ce(
2390
+ }, H = Dt(_, u, l, t);
2391
+ return H instanceof Promise || t ? Promise.resolve(H).then((re) => (ae(
2396
2392
  s,
2397
- C.miniApp,
2398
- C.themeParams,
2399
- v
2400
- ), { ...C, viewport: v })) : (ce(
2393
+ q.miniApp,
2394
+ q.themeParams,
2395
+ re
2396
+ ), { ...q, viewport: re })) : (ae(
2401
2397
  s,
2402
- C.miniApp,
2403
- C.themeParams,
2404
- x
2405
- ), { ...C, viewport: x });
2398
+ q.miniApp,
2399
+ q.themeParams,
2400
+ H
2401
+ ), { ...q, viewport: H });
2406
2402
  } catch (i) {
2407
2403
  if (t)
2408
2404
  return Promise.reject(i);
2409
2405
  throw i;
2410
2406
  }
2411
2407
  }
2412
- function O(r, e) {
2413
- return r.startsWith(e) ? r : `${e}${r}`;
2408
+ function sr() {
2409
+ return {
2410
+ launchParams: te(),
2411
+ isPageReload: Ae()
2412
+ };
2413
+ }
2414
+ function nr() {
2415
+ try {
2416
+ return te(), !0;
2417
+ } catch {
2418
+ return !1;
2419
+ }
2414
2420
  }
2415
- function ar(r) {
2421
+ function ir(r) {
2416
2422
  const e = r.match(/#(.+)/);
2417
2423
  return e ? e[1] : null;
2418
2424
  }
2419
- async function N(r) {
2425
+ async function D(r) {
2420
2426
  return r === 0 ? !0 : Promise.race([
2421
2427
  new Promise((e) => {
2422
2428
  window.addEventListener("popstate", function t() {
@@ -2429,14 +2435,17 @@ async function N(r) {
2429
2435
  })
2430
2436
  ]);
2431
2437
  }
2432
- async function zt() {
2433
- if (window.history.length <= 1 || (window.history.pushState(null, ""), await N(1 - window.history.length)))
2438
+ async function Ft() {
2439
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await D(1 - window.history.length)))
2434
2440
  return;
2435
- let e = await N(-1);
2441
+ let e = await D(-1);
2436
2442
  for (; e; )
2437
- e = await N(-1);
2443
+ e = await D(-1);
2438
2444
  }
2439
- class Jt {
2445
+ function B(r, e) {
2446
+ return r.startsWith(e) ? r : `${e}${r}`;
2447
+ }
2448
+ class zt {
2440
2449
  constructor(e, t, {
2441
2450
  debug: s = !1,
2442
2451
  loggerPrefix: n = "Navigator"
@@ -2451,11 +2460,11 @@ class Jt {
2451
2460
  if (!i.startsWith("/") && i.length > 0)
2452
2461
  throw new Error('Pathname should start with "/"');
2453
2462
  return {
2454
- pathname: O(i, "/"),
2455
- search: a ? O(a, "?") : "",
2456
- hash: c ? O(c, "#") : ""
2463
+ pathname: B(i, "/"),
2464
+ search: a ? B(a, "?") : "",
2465
+ hash: c ? B(c, "#") : ""
2457
2466
  };
2458
- }), this.logger = new ve(`[${n}]`, s);
2467
+ }), this.logger = new he(`[${n}]`, s);
2459
2468
  }
2460
2469
  /**
2461
2470
  * Converts entry to the navigation entry.
@@ -2471,7 +2480,7 @@ class Jt {
2471
2480
  search: c,
2472
2481
  hash: u
2473
2482
  } = e;
2474
- t = a + (c ? O(c, "?") : "") + (u ? O(u, "#") : "");
2483
+ t = a + (c ? B(c, "?") : "") + (u ? B(u, "#") : "");
2475
2484
  }
2476
2485
  const {
2477
2486
  pathname: s,
@@ -2635,8 +2644,8 @@ class Jt {
2635
2644
  return this.entry.search;
2636
2645
  }
2637
2646
  }
2638
- const he = 0, Z = 1, K = 2;
2639
- class Ve extends Jt {
2647
+ const ce = 0, J = 1, Q = 2;
2648
+ class Ve extends zt {
2640
2649
  constructor(t, s, n = {}) {
2641
2650
  super(t, s, {
2642
2651
  ...n,
@@ -2651,13 +2660,13 @@ class Ve extends Jt {
2651
2660
  o(this, "onPopState", async ({ state: t }) => {
2652
2661
  if (this.logger.log('"popstate" event received. State:', t), t === null)
2653
2662
  return this.push(window.location.hash.slice(1));
2654
- if (t === he) {
2663
+ if (t === ce) {
2655
2664
  this.logger.log("Void reached. Moving history forward"), window.history.forward();
2656
2665
  return;
2657
2666
  }
2658
- if (t === Z)
2667
+ if (t === J)
2659
2668
  return this.back();
2660
- if (t === K)
2669
+ if (t === Q)
2661
2670
  return this.forward();
2662
2671
  });
2663
2672
  o(this, "back", () => super.back());
@@ -2700,7 +2709,7 @@ class Ve extends Jt {
2700
2709
  async syncHistory() {
2701
2710
  window.removeEventListener("popstate", this.onPopState);
2702
2711
  const t = `#${this.path}`;
2703
- await zt(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", t), window.history.pushState(K, ""), await N(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", t)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, t), window.history.pushState(K, ""), await N(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(he, ""), window.history.pushState(null, "", t)), window.addEventListener("popstate", this.onPopState);
2712
+ await Ft(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(J, ""), window.history.pushState(null, "", t), window.history.pushState(Q, ""), await D(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(J, ""), window.history.pushState(null, "", t)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, t), window.history.pushState(Q, ""), await D(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ce, ""), window.history.pushState(null, "", t)), window.addEventListener("popstate", this.onPopState);
2704
2713
  }
2705
2714
  emitChanged(t, s) {
2706
2715
  this.ee.emit("change", {
@@ -2714,90 +2723,93 @@ class Ve extends Jt {
2714
2723
  */
2715
2724
  async attach() {
2716
2725
  if (!this.attached)
2717
- return this.logger.log("Attaching", this), this.attached = !0, y("back_button_pressed", this.back), this.syncHistory();
2726
+ return this.logger.log("Attaching", this), this.attached = !0, E("back_button_pressed", this.back), this.syncHistory();
2718
2727
  }
2719
2728
  /**
2720
2729
  * Detaches current navigator from the browser history.
2721
2730
  */
2722
2731
  detach() {
2723
- this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), $("back_button_pressed", this.back));
2732
+ this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), I("back_button_pressed", this.back));
2724
2733
  }
2725
2734
  }
2735
+ function or(r) {
2736
+ return r instanceof F;
2737
+ }
2726
2738
  export {
2727
- bt as BackButton,
2728
- yt as ClosingBehavior,
2729
- Et as CloudStorage,
2730
- Pt as HapticFeedback,
2739
+ rt as BackButton,
2740
+ st as ClosingBehavior,
2741
+ at as CloudStorage,
2742
+ ct as HapticFeedback,
2731
2743
  Ve as HashNavigator,
2732
- We as InitData,
2733
- Ut as Invoice,
2734
- qt as MainButton,
2735
- re as MethodUnsupportedError,
2736
- Rt as MiniApp,
2737
- Jt as Navigator,
2738
- se as ParameterUnsupportedError,
2739
- F as ParseError,
2740
- j as ParseSchemaFieldError,
2741
- Gt as Popup,
2742
- jt as QRScanner,
2743
- Tt as SettingsButton,
2744
- Ue as ThemeParams,
2745
- J as TimeoutError,
2746
- Ft as Utils,
2747
- Wt as Viewport,
2748
- $e as array,
2749
- Ct as bindMiniAppCSSVars,
2750
- vt as bindThemeCSSVars,
2751
- ae as bindViewportCSSVars,
2752
- k as boolean,
2753
- De as chatParser,
2754
- mt as classNames,
2755
- ft as compareVersions,
2756
- gt as createPostEvent,
2757
- fe as date,
2758
- ar as getHash,
2759
- or as init,
2760
- be as initDataParser,
2761
- H as invokeCustomMethod,
2762
- we as isColorDark,
2744
+ ut as InitData,
2745
+ lt as Invoice,
2746
+ dt as MainButton,
2747
+ Z as MethodUnsupportedError,
2748
+ wt as MiniApp,
2749
+ zt as Navigator,
2750
+ K as ParameterUnsupportedError,
2751
+ G as ParseError,
2752
+ U as ParseSchemaFieldError,
2753
+ bt as Popup,
2754
+ mt as QRScanner,
2755
+ yt as SettingsButton,
2756
+ Pt as ThemeParams,
2757
+ F as TimeoutError,
2758
+ St as Utils,
2759
+ xt as Viewport,
2760
+ ot as array,
2761
+ qt as bindMiniAppCSSVars,
2762
+ At as bindThemeCSSVars,
2763
+ oe as bindViewportCSSVars,
2764
+ P as boolean,
2765
+ ht as chatParser,
2766
+ tt as classNames,
2767
+ Be as compareVersions,
2768
+ Oe as createPostEvent,
2769
+ be as date,
2770
+ ir as getHash,
2771
+ rr as init,
2772
+ me as initDataParser,
2773
+ O as invokeCustomMethod,
2774
+ _e as isColorDark,
2763
2775
  pe as isIframe,
2764
- le as isPageReload,
2776
+ Ae as isPageReload,
2765
2777
  X as isRGB,
2766
- Be as isRGBShort,
2767
- R as isRecord,
2768
- Dt as isStableViewportPlatform,
2769
- tr as isTMA,
2770
- nr as isTimeoutError,
2778
+ Je as isRGBShort,
2779
+ M as isRecord,
2780
+ kt as isStableViewportPlatform,
2781
+ nr as isTMA,
2782
+ or as isTimeoutError,
2771
2783
  f as json,
2772
- Me as launchParamsParser,
2773
- ir as mergeClassNames,
2774
- A as number,
2775
- $ as off,
2776
- y as on,
2777
- rr as once,
2778
- Zt as parseInitData,
2779
- Ee as parseLaunchParams,
2780
- Xe as parseMessage,
2781
- ye as parseThemeParams,
2784
+ Ht as launchParamsParser,
2785
+ Xt as mergeClassNames,
2786
+ x as number,
2787
+ I as off,
2788
+ E as on,
2789
+ Kt as once,
2790
+ er as parseInitData,
2791
+ Se as parseLaunchParams,
2792
+ De as parseMessage,
2793
+ Ce as parseThemeParams,
2782
2794
  d as postEvent,
2783
- m as request,
2784
- Kt as requestThemeParams,
2785
- Ae as requestViewport,
2786
- er as retrieveLaunchData,
2795
+ y as request,
2796
+ tr as requestThemeParams,
2797
+ ve as requestViewport,
2798
+ sr as retrieveLaunchData,
2787
2799
  te as retrieveLaunchParams,
2788
- _e as rgb,
2800
+ ge as rgb,
2789
2801
  ee as searchParams,
2790
- ze as serializeLaunchParams,
2791
- Ne as serializeThemeParams,
2802
+ Mt as serializeLaunchParams,
2803
+ vt as serializeThemeParams,
2792
2804
  S as setCSSVar,
2793
- Yt as setDebug,
2794
- Xt as setTargetOrigin,
2805
+ Qt as setDebug,
2806
+ Zt as setTargetOrigin,
2795
2807
  h as string,
2796
- sr as subscribe,
2797
- I as supports,
2798
- me as themeParamsParser,
2799
- ge as toRGB,
2800
- dt as unsubscribe,
2801
- ne as userParser,
2802
- xe as withTimeout
2808
+ Yt as subscribe,
2809
+ A as supports,
2810
+ Ee as themeParamsParser,
2811
+ fe as toRGB,
2812
+ et as unsubscribe,
2813
+ ie as userParser,
2814
+ we as withTimeout
2803
2815
  };