@tma.js/sdk 1.4.8 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +2 -2
  2. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +2 -2
  3. package/dist/dts/bridge/events/events.d.ts +13 -3
  4. package/dist/dts/bridge/events/on.d.ts +5 -3
  5. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +2 -2
  6. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +2 -2
  7. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +1 -1
  8. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +1 -1
  9. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +1 -1
  10. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +1 -1
  11. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +2 -2
  12. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +1 -1
  13. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +1 -1
  14. package/dist/dts/bridge/events/singletonEmitter.d.ts +1 -1
  15. package/dist/dts/bridge/invokeCustomMethod.d.ts +2 -2
  16. package/dist/dts/bridge/methods/createPostEvent.d.ts +1 -1
  17. package/dist/dts/bridge/methods/custom-methods.d.ts +1 -1
  18. package/dist/dts/bridge/methods/methods.d.ts +5 -2
  19. package/dist/dts/bridge/request.d.ts +5 -3
  20. package/dist/dts/classnames/mergeClassNames.d.ts +2 -18
  21. package/dist/dts/{back-button → components/back-button}/BackButton.d.ts +4 -4
  22. package/dist/dts/{back-button → components/back-button}/types.d.ts +2 -2
  23. package/dist/dts/{closing-behavior → components/closing-behavior}/ClosingBehavior.d.ts +6 -3
  24. package/dist/dts/{closing-behavior → components/closing-behavior}/types.d.ts +1 -1
  25. package/dist/dts/{cloud-storage → components/cloud-storage}/CloudStorage.d.ts +5 -4
  26. package/dist/dts/{haptic-feedback → components/haptic-feedback}/HapticFeedback.d.ts +4 -3
  27. package/dist/dts/components/init-data/chatParser.d.ts +6 -0
  28. package/dist/dts/components/init-data/initDataParser.d.ts +6 -0
  29. package/dist/dts/components/init-data/userParser.d.ts +6 -0
  30. package/dist/dts/{invoice → components/invoice}/Invoice.d.ts +9 -5
  31. package/dist/dts/{invoice → components/invoice}/types.d.ts +1 -1
  32. package/dist/dts/{main-button → components/main-button}/MainButton.d.ts +2 -2
  33. package/dist/dts/{main-button → components/main-button}/types.d.ts +3 -3
  34. package/dist/dts/{mini-app → components/mini-app}/MiniApp.d.ts +11 -6
  35. package/dist/dts/components/mini-app/contactParser.d.ts +2 -0
  36. package/dist/dts/{mini-app → components/mini-app}/types.d.ts +6 -5
  37. package/dist/dts/{popup → components/popup}/Popup.d.ts +8 -5
  38. package/dist/dts/{popup → components/popup}/preparePopupParams.d.ts +1 -1
  39. package/dist/dts/{popup → components/popup}/types.d.ts +1 -1
  40. package/dist/dts/{qr-scanner → components/qr-scanner}/QRScanner.d.ts +8 -5
  41. package/dist/dts/{qr-scanner → components/qr-scanner}/types.d.ts +1 -1
  42. package/dist/dts/{settings-button → components/settings-button}/SettingsButton.d.ts +4 -4
  43. package/dist/dts/{settings-button → components/settings-button}/types.d.ts +2 -2
  44. package/dist/dts/{theme-params → components/theme-params}/ThemeParams.d.ts +8 -4
  45. package/dist/dts/{theme-params → components/theme-params}/requestThemeParams.d.ts +1 -1
  46. package/dist/dts/components/theme-params/themeParamsParser.d.ts +3 -0
  47. package/dist/dts/{theme-params → components/theme-params}/types.d.ts +2 -2
  48. package/dist/dts/{utils → components/utils}/Utils.d.ts +4 -4
  49. package/dist/dts/{viewport → components/viewport}/Viewport.d.ts +8 -4
  50. package/dist/dts/{viewport → components/viewport}/isStableViewportPlatform.d.ts +1 -1
  51. package/dist/dts/{viewport → components/viewport}/requestViewport.d.ts +1 -1
  52. package/dist/dts/{viewport → components/viewport}/types.d.ts +2 -2
  53. package/dist/dts/css/bindMiniAppCSSVars.d.ts +2 -2
  54. package/dist/dts/css/bindThemeCSSVars.d.ts +1 -1
  55. package/dist/dts/css/bindViewportCSSVars.d.ts +1 -1
  56. package/dist/dts/event-emitter/types.d.ts +1 -1
  57. package/dist/dts/globals.d.ts +1 -1
  58. package/dist/dts/index.d.ts +142 -27
  59. package/dist/dts/init/creators/createBackButton.d.ts +2 -2
  60. package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -2
  61. package/dist/dts/init/creators/createMainButton.d.ts +3 -3
  62. package/dist/dts/init/creators/createMiniApp.d.ts +5 -5
  63. package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
  64. package/dist/dts/init/creators/createSettingsButton.d.ts +2 -2
  65. package/dist/dts/init/creators/createThemeParams.d.ts +2 -1
  66. package/dist/dts/init/creators/createViewport.d.ts +3 -3
  67. package/dist/dts/init/css/processCSSVarsOption.d.ts +3 -3
  68. package/dist/dts/init/types.d.ts +16 -16
  69. package/dist/dts/launch-params/launchParamsParser.d.ts +2 -1
  70. package/dist/dts/launch-params/types.d.ts +3 -3
  71. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +6 -3
  72. package/dist/dts/navigation/HashNavigator/types.d.ts +1 -2
  73. package/dist/dts/navigation/Navigator/Navigator.d.ts +1 -1
  74. package/dist/dts/parsing/ValueParser.d.ts +1 -1
  75. package/dist/dts/parsing/parsers/array.d.ts +2 -2
  76. package/dist/dts/parsing/parsers/boolean.d.ts +2 -1
  77. package/dist/dts/parsing/parsers/date.d.ts +2 -1
  78. package/dist/dts/parsing/parsers/number.d.ts +2 -1
  79. package/dist/dts/parsing/parsers/rgb.d.ts +3 -1
  80. package/dist/dts/parsing/parsers/string.d.ts +2 -1
  81. package/dist/dts/state/State.d.ts +2 -2
  82. package/dist/dts/state/types.d.ts +1 -1
  83. package/dist/dts/storage.d.ts +2 -2
  84. package/dist/dts/supports/createSupportsFunc.d.ts +2 -2
  85. package/dist/dts/supports/createSupportsParamFunc.d.ts +2 -2
  86. package/dist/dts/supports/supports.d.ts +2 -2
  87. package/dist/dts/supports/types.d.ts +3 -0
  88. package/dist/dts/types/logical.d.ts +16 -0
  89. package/dist/dts/types/methods.d.ts +1 -1
  90. package/dist/dts/types/unions.d.ts +20 -0
  91. package/dist/dts/types/utils.d.ts +0 -28
  92. package/dist/dts/version/compareVersions.d.ts +2 -1
  93. package/dist/dts/version/types.d.ts +1 -0
  94. package/dist/index.cjs +1 -1
  95. package/dist/index.iife.js +1 -1
  96. package/dist/index.mjs +1527 -1527
  97. package/package.json +1 -1
  98. package/dist/dts/back-button/index.d.ts +0 -2
  99. package/dist/dts/bridge/env/index.d.ts +0 -2
  100. package/dist/dts/bridge/errors/index.d.ts +0 -2
  101. package/dist/dts/bridge/events/index.d.ts +0 -9
  102. package/dist/dts/bridge/events/parsers/index.d.ts +0 -9
  103. package/dist/dts/bridge/index.d.ts +0 -7
  104. package/dist/dts/bridge/methods/index.d.ts +0 -6
  105. package/dist/dts/classnames/index.d.ts +0 -2
  106. package/dist/dts/closing-behavior/index.d.ts +0 -2
  107. package/dist/dts/cloud-storage/index.d.ts +0 -1
  108. package/dist/dts/colors/index.d.ts +0 -5
  109. package/dist/dts/css/index.d.ts +0 -4
  110. package/dist/dts/event-emitter/index.d.ts +0 -2
  111. package/dist/dts/haptic-feedback/index.d.ts +0 -1
  112. package/dist/dts/init/creators/index.d.ts +0 -8
  113. package/dist/dts/init/css/index.d.ts +0 -1
  114. package/dist/dts/init/index.d.ts +0 -2
  115. package/dist/dts/init-data/chatParser.d.ts +0 -5
  116. package/dist/dts/init-data/index.d.ts +0 -6
  117. package/dist/dts/init-data/initDataParser.d.ts +0 -5
  118. package/dist/dts/init-data/userParser.d.ts +0 -5
  119. package/dist/dts/invoice/index.d.ts +0 -2
  120. package/dist/dts/launch-params/index.d.ts +0 -10
  121. package/dist/dts/logger/index.d.ts +0 -1
  122. package/dist/dts/main-button/index.d.ts +0 -2
  123. package/dist/dts/mini-app/contactParser.d.ts +0 -2
  124. package/dist/dts/mini-app/index.d.ts +0 -2
  125. package/dist/dts/misc/index.d.ts +0 -5
  126. package/dist/dts/navigation/HashNavigator/index.d.ts +0 -2
  127. package/dist/dts/navigation/Navigator/index.d.ts +0 -2
  128. package/dist/dts/navigation/index.d.ts +0 -4
  129. package/dist/dts/parsing/index.d.ts +0 -10
  130. package/dist/dts/parsing/parsers/index.d.ts +0 -8
  131. package/dist/dts/popup/index.d.ts +0 -2
  132. package/dist/dts/qr-scanner/index.d.ts +0 -2
  133. package/dist/dts/settings-button/index.d.ts +0 -2
  134. package/dist/dts/state/index.d.ts +0 -2
  135. package/dist/dts/supports/index.d.ts +0 -4
  136. package/dist/dts/theme-params/index.d.ts +0 -6
  137. package/dist/dts/theme-params/themeParamsParser.d.ts +0 -2
  138. package/dist/dts/timeout/index.d.ts +0 -4
  139. package/dist/dts/types/index.d.ts +0 -4
  140. package/dist/dts/utils/index.d.ts +0 -1
  141. package/dist/dts/version/index.d.ts +0 -2
  142. package/dist/dts/viewport/index.d.ts +0 -4
  143. /package/dist/dts/{init-data → components/init-data}/InitData.d.ts +0 -0
  144. /package/dist/dts/{init-data → components/init-data}/parseInitData.d.ts +0 -0
  145. /package/dist/dts/{init-data → components/init-data}/types.d.ts +0 -0
  146. /package/dist/dts/{theme-params → components/theme-params}/keys.d.ts +0 -0
  147. /package/dist/dts/{theme-params → components/theme-params}/parseThemeParams.d.ts +0 -0
  148. /package/dist/dts/{theme-params → components/theme-params}/serializeThemeParams.d.ts +0 -0
  149. /package/dist/dts/{viewport → components/viewport}/utils.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -1,80 +1,191 @@
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 ue {
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 pe = "https://web.telegram.org";
60
+ const q = new ue("[SDK]", !1);
61
+ function Zt(r) {
62
+ if (r) {
63
+ q.enable();
64
+ return;
65
+ }
66
+ q.disable();
67
+ }
68
+ function Kt(r) {
69
+ pe = r;
6
70
  }
7
- function pe() {
71
+ function Le() {
72
+ return pe;
73
+ }
74
+ function le() {
8
75
  try {
9
76
  return window.self !== window.top;
10
77
  } catch {
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
81
  function R(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 Te(r) {
85
+ return "external" in r && R(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 $e(r) {
88
+ return "TelegramWebviewProxy" in r && R(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 = Le() } = s;
94
+ if (q.log(`Calling method "${r}"`, n), le()) {
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 (Te(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 ($e(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 P(r, e) {
123
+ return Be(r, e) <= 0;
124
+ }
125
+ function I(r, e, t) {
126
+ if (typeof t == "string") {
127
+ if (r === "web_app_open_link" && e === "try_instant_view")
128
+ return P("6.4", t);
129
+ if (r === "web_app_set_header_color" && e === "color")
130
+ return P("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 P("6.1", e);
140
+ case "web_app_open_popup":
141
+ return P("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 P("6.4", e);
146
+ case "web_app_switch_inline_query":
147
+ return P("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 P("6.9", e);
152
+ case "web_app_setup_settings_button":
153
+ return P("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 Y extends Error {
159
+ constructor(e, t) {
160
+ super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`), Object.setPrototypeOf(this, Y.prototype);
74
161
  }
75
162
  }
76
- function T(r, e) {
77
- return () => new z(r, !1, e);
163
+ class X 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, X.prototype);
166
+ }
167
+ }
168
+ function De(r) {
169
+ return (e, t) => {
170
+ if (!I(e, r))
171
+ throw new Y(e, r);
172
+ if (R(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 && !I(e, s, r))
175
+ throw new X(e, s, r);
176
+ }
177
+ return d(e, t);
178
+ };
179
+ }
180
+ class F extends Error {
181
+ constructor(t, { cause: s, type: n } = {}) {
182
+ super(`Unable to parse value${n ? ` as ${n}` : ""}`, { cause: s });
183
+ /**
184
+ * Parser name.
185
+ */
186
+ o(this, "type");
187
+ this.value = t, Object.setPrototypeOf(this, F.prototype), this.type = n;
188
+ }
78
189
  }
79
190
  class j extends Error {
80
191
  constructor(e, { cause: t, type: s } = {}) {
@@ -108,685 +219,59 @@ function de(r, e) {
108
219
  }
109
220
  return t;
110
221
  }
111
- function $e(r) {
112
- return new Te((e) => e, !1, r);
222
+ function L() {
223
+ return new TypeError("Value has unexpected type");
113
224
  }
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
- function Y(r) {
225
+ function ee(r) {
134
226
  let e = r;
135
227
  if (typeof e == "string" && (e = JSON.parse(e)), typeof e != "object" || e === null || Array.isArray(e))
136
228
  throw L();
137
229
  return e;
138
230
  }
231
+ class z {
232
+ constructor(e, t, s) {
233
+ this.parser = e, this.isOptional = t, this.type = s;
234
+ }
235
+ parse(e) {
236
+ if (!(this.isOptional && e === void 0))
237
+ try {
238
+ return this.parser(e);
239
+ } catch (t) {
240
+ throw new F(e, { type: this.type, cause: t });
241
+ }
242
+ }
243
+ optional() {
244
+ return this.isOptional = !0, this;
245
+ }
246
+ }
139
247
  function f(r, e) {
140
248
  return new z((t) => {
141
- const s = Y(t);
249
+ const s = ee(t);
142
250
  return de(r, (n) => s[n]);
143
251
  }, !1, e);
144
252
  }
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;
253
+ function T(r, e) {
254
+ return () => new z(r, !1, e);
177
255
  }
178
256
  const h = T((r) => {
179
257
  if (typeof r == "string" || typeof r == "number")
180
258
  return r.toString();
181
259
  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() {
195
- 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");
205
- }
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
- }
278
- }
279
- function ne() {
280
- 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");
316
- }
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");
348
- }
349
- function Zt(r) {
350
- return be().parse(r);
351
- }
352
- function Oe(r) {
353
- return r.replace(/(^|_)bg/, (e, t) => `${t}background`).replace(/_([a-z])/g, (e, t) => t.toUpperCase());
354
- }
355
- function He(r) {
356
- return r.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`).replace(/(^|_)background/, (e, t) => `${t}bg`);
357
- }
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);
367
- }
368
- function Kt(r = {}) {
369
- return m("web_app_request_theme", "theme_changed", r).then(ye);
370
- }
371
- function Ne(r) {
372
- return JSON.stringify(
373
- Object.entries(r).reduce((e, [t, s]) => (s && (e[He(t)] = s), e), {})
374
- );
375
- }
376
- class w {
377
- constructor() {
378
- o(this, "listeners", /* @__PURE__ */ new Map());
379
- o(this, "subscribeListeners", []);
380
- }
381
- /**
382
- * Adds specified event listener.
383
- * @param event - event name.
384
- * @param listener - event listener.
385
- * @param once - should listener called only once.
386
- */
387
- addListener(e, t, s) {
388
- let n = this.listeners.get(e);
389
- return n || (n = [], this.listeners.set(e, n)), n.push([t, s]), () => this.off(e, t);
390
- }
391
- emit(e, ...t) {
392
- this.subscribeListeners.forEach((n) => n(e, ...t));
393
- const s = this.listeners.get(e);
394
- s && s.forEach(([n, i], a) => {
395
- n(...t), i && s.splice(a, 1);
396
- });
397
- }
398
- /**
399
- * Adds event listener.
400
- * @param event - event name.
401
- * @param listener - event listener.
402
- * @returns Function to remove event listener.
403
- */
404
- on(e, t) {
405
- return this.addListener(e, t, !1);
406
- }
407
- /**
408
- * Adds event listener following the logic, described in `on` method, but calls specified
409
- * listener only once, removing it after.
410
- * @param event - event name.
411
- * @param listener - event listener.
412
- * @returns Function to remove event listener.
413
- * @see on
414
- */
415
- once(e, t) {
416
- return this.addListener(e, t, !0);
417
- }
418
- /**
419
- * Removes event listener. In case, specified listener was bound several times, it removes
420
- * only a single one.
421
- * @param event - event name.
422
- * @param listener - event listener.
423
- */
424
- off(e, t) {
425
- const s = this.listeners.get(e);
426
- if (s) {
427
- for (let n = 0; n < s.length; n += 1)
428
- if (t === s[n][0]) {
429
- s.splice(n, 1);
430
- return;
431
- }
432
- }
433
- }
434
- /**
435
- * Adds event listener to all events.
436
- * @param listener - events listener.
437
- * @returns Function to remove event listener.
438
- * @see on
439
- * @see once
440
- */
441
- subscribe(e) {
442
- return this.subscribeListeners.push(e), () => this.unsubscribe(e);
443
- }
444
- /**
445
- * Removes global event listener. In case, specified listener was bound several times, it removes
446
- * only a single one.
447
- * @param listener - events listener.
448
- * @returns Function to remove event listener.
449
- */
450
- unsubscribe(e) {
451
- for (let t = 0; t < this.subscribeListeners.length; t += 1)
452
- if (this.subscribeListeners[t] === e) {
453
- this.subscribeListeners.splice(t, 1);
454
- return;
455
- }
456
- }
457
- }
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({
260
+ }, "string"), We = f({
776
261
  eventType: h(),
777
262
  eventData: (r) => r
778
263
  });
779
- function Xe(r) {
780
- return Ye.parse(r);
264
+ function Oe(r) {
265
+ return We.parse(r);
781
266
  }
782
- function et(r, e) {
267
+ function He(r, e) {
783
268
  window.dispatchEvent(new MessageEvent("message", {
784
269
  data: JSON.stringify({ eventType: r, eventData: e }),
785
270
  // We specify window.parent to imitate the case, it sent us this event.
786
271
  source: window.parent
787
272
  }));
788
273
  }
789
- function tt() {
274
+ function Ne() {
790
275
  const r = window;
791
276
  "TelegramGameProxy_receiveEvent" in r || [
792
277
  ["TelegramGameProxy_receiveEvent"],
@@ -799,64 +284,108 @@ function tt() {
799
284
  let t = r;
800
285
  e.forEach((s, n, i) => {
801
286
  if (n === i.length - 1) {
802
- t[s] = et;
287
+ t[s] = He;
803
288
  return;
804
289
  }
805
290
  s in t || (t[s] = {}), t = t[s];
806
291
  });
807
292
  });
808
293
  }
809
- function rt(r) {
810
- tt(), window.addEventListener("message", (e) => {
294
+ function Ue(r) {
295
+ Ne(), window.addEventListener("message", (e) => {
811
296
  if (e.source === window.parent)
812
297
  try {
813
- const { eventType: t, eventData: s } = Xe(e.data);
298
+ const { eventType: t, eventData: s } = Oe(e.data);
814
299
  r(t, s);
815
300
  } catch {
816
301
  }
817
302
  });
818
303
  }
819
- function st() {
304
+ function Me() {
820
305
  return f({
821
306
  req_id: h(),
822
307
  data: (r) => r === null ? r : h().optional().parse(r)
823
308
  });
824
309
  }
825
- function nt() {
310
+ function Ge() {
826
311
  return f({
827
312
  req_id: h(),
828
313
  result: (r) => r,
829
314
  error: h().optional()
830
315
  });
831
316
  }
832
- function it() {
317
+ function je() {
833
318
  return f({
834
319
  slug: h(),
835
320
  status: h()
836
321
  });
837
322
  }
838
- function ot() {
323
+ function Fe() {
839
324
  return f({ status: h() });
840
325
  }
841
- function at() {
326
+ function ze() {
842
327
  return f({
843
328
  button_id: (r) => r == null ? void 0 : h().parse(r)
844
329
  });
845
330
  }
846
- function ct() {
331
+ function Je() {
847
332
  return f({
848
333
  data: h().optional()
849
334
  });
850
335
  }
851
- function ht() {
336
+ function te(r) {
337
+ return /^#[\da-f]{6}$/i.test(r);
338
+ }
339
+ function Qe(r) {
340
+ return /^#[\da-f]{3}$/i.test(r);
341
+ }
342
+ function fe(r) {
343
+ const e = r.replace(/\s/g, "").toLowerCase();
344
+ if (te(e))
345
+ return e;
346
+ if (Qe(e)) {
347
+ let s = "#";
348
+ for (let n = 0; n < 3; n += 1)
349
+ s += e[1 + n].repeat(2);
350
+ return s;
351
+ }
352
+ 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}\)$/);
353
+ if (t === null)
354
+ throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);
355
+ return t.slice(1).reduce((s, n) => {
356
+ const i = parseInt(n, 10).toString(16);
357
+ return s + (i.length === 1 ? "0" : "") + i;
358
+ }, "#");
359
+ }
360
+ const ge = T((r) => fe(h().parse(r)), "rgb");
361
+ function Ze() {
852
362
  return f({
853
363
  theme_params: (r) => {
854
- const e = _e().optional();
855
- return Object.entries(Y(r)).reduce((t, [s, n]) => (t[s] = e.parse(n), t), {});
364
+ const e = ge().optional();
365
+ return Object.entries(ee(r)).reduce((t, [s, n]) => (t[s] = e.parse(n), t), {});
856
366
  }
857
367
  });
858
368
  }
859
- function ut() {
369
+ const k = T((r) => {
370
+ if (typeof r == "boolean")
371
+ return r;
372
+ const e = String(r);
373
+ if (e === "1" || e === "true")
374
+ return !0;
375
+ if (e === "0" || e === "false")
376
+ return !1;
377
+ throw L();
378
+ }, "boolean"), A = T((r) => {
379
+ if (typeof r == "number")
380
+ return r;
381
+ if (typeof r == "string") {
382
+ const e = Number(r);
383
+ if (!Number.isNaN(e))
384
+ return e;
385
+ }
386
+ throw L();
387
+ }, "number");
388
+ function Ke() {
860
389
  return f({
861
390
  height: A(),
862
391
  width: (r) => r == null ? window.innerWidth : A().parse(r),
@@ -864,10 +393,92 @@ function ut() {
864
393
  is_expanded: k()
865
394
  });
866
395
  }
867
- function pt() {
396
+ function Ye() {
868
397
  return f({ status: h() });
869
398
  }
870
- function lt() {
399
+ class w {
400
+ constructor() {
401
+ o(this, "listeners", /* @__PURE__ */ new Map());
402
+ o(this, "subscribeListeners", []);
403
+ }
404
+ /**
405
+ * Adds specified event listener.
406
+ * @param event - event name.
407
+ * @param listener - event listener.
408
+ * @param once - should listener called only once.
409
+ */
410
+ addListener(e, t, s) {
411
+ let n = this.listeners.get(e);
412
+ return n || (n = [], this.listeners.set(e, n)), n.push([t, s]), () => this.off(e, t);
413
+ }
414
+ emit(e, ...t) {
415
+ this.subscribeListeners.forEach((n) => n(e, ...t));
416
+ const s = this.listeners.get(e);
417
+ s && s.forEach(([n, i], a) => {
418
+ n(...t), i && s.splice(a, 1);
419
+ });
420
+ }
421
+ /**
422
+ * Adds event listener.
423
+ * @param event - event name.
424
+ * @param listener - event listener.
425
+ * @returns Function to remove event listener.
426
+ */
427
+ on(e, t) {
428
+ return this.addListener(e, t, !1);
429
+ }
430
+ /**
431
+ * Adds event listener following the logic, described in `on` method, but calls specified
432
+ * listener only once, removing it after.
433
+ * @param event - event name.
434
+ * @param listener - event listener.
435
+ * @returns Function to remove event listener.
436
+ * @see on
437
+ */
438
+ once(e, t) {
439
+ return this.addListener(e, t, !0);
440
+ }
441
+ /**
442
+ * Removes event listener. In case, specified listener was bound several times, it removes
443
+ * only a single one.
444
+ * @param event - event name.
445
+ * @param listener - event listener.
446
+ */
447
+ off(e, t) {
448
+ const s = this.listeners.get(e);
449
+ if (s) {
450
+ for (let n = 0; n < s.length; n += 1)
451
+ if (t === s[n][0]) {
452
+ s.splice(n, 1);
453
+ return;
454
+ }
455
+ }
456
+ }
457
+ /**
458
+ * Adds event listener to all events.
459
+ * @param listener - events listener.
460
+ * @returns Function to remove event listener.
461
+ * @see on
462
+ * @see once
463
+ */
464
+ subscribe(e) {
465
+ return this.subscribeListeners.push(e), () => this.unsubscribe(e);
466
+ }
467
+ /**
468
+ * Removes global event listener. In case, specified listener was bound several times, it removes
469
+ * only a single one.
470
+ * @param listener - events listener.
471
+ * @returns Function to remove event listener.
472
+ */
473
+ unsubscribe(e) {
474
+ for (let t = 0; t < this.subscribeListeners.length; t += 1)
475
+ if (this.subscribeListeners[t] === e) {
476
+ this.subscribeListeners.splice(t, 1);
477
+ return;
478
+ }
479
+ }
480
+ }
481
+ function Xe() {
871
482
  const r = new w(), e = (t, ...s) => {
872
483
  q.log("Emitting processed event:", t, ...s), r.emit(t, ...s);
873
484
  };
@@ -878,33 +489,33 @@ function lt() {
878
489
  is_state_stable: !0,
879
490
  is_expanded: !0
880
491
  });
881
- }), rt((t, s) => {
492
+ }), Ue((t, s) => {
882
493
  q.log("Received raw event:", t, s);
883
494
  try {
884
495
  switch (t) {
885
496
  case "viewport_changed":
886
- return e(t, ut().parse(s));
497
+ return e(t, Ke().parse(s));
887
498
  case "theme_changed":
888
- return e(t, ht().parse(s));
499
+ return e(t, Ze().parse(s));
889
500
  case "popup_closed":
890
501
  return (
891
502
  // Sent on desktop.
892
- s == null ? e(t, {}) : e(t, at().parse(s))
503
+ s == null ? e(t, {}) : e(t, ze().parse(s))
893
504
  );
894
505
  case "set_custom_style":
895
506
  return e(t, h().parse(s));
896
507
  case "qr_text_received":
897
- return e(t, ct().parse(s));
508
+ return e(t, Je().parse(s));
898
509
  case "clipboard_text_received":
899
- return e(t, st().parse(s));
510
+ return e(t, Me().parse(s));
900
511
  case "invoice_closed":
901
- return e(t, it().parse(s));
512
+ return e(t, je().parse(s));
902
513
  case "phone_requested":
903
- return e("phone_requested", ot().parse(s));
514
+ return e("phone_requested", Fe().parse(s));
904
515
  case "custom_method_invoked":
905
- return e("custom_method_invoked", nt().parse(s));
516
+ return e("custom_method_invoked", Ge().parse(s));
906
517
  case "write_access_requested":
907
- return e("write_access_requested", pt().parse(s));
518
+ return e("write_access_requested", Ye().parse(s));
908
519
  case "main_button_pressed":
909
520
  case "back_button_pressed":
910
521
  case "settings_button_pressed":
@@ -921,135 +532,29 @@ function lt() {
921
532
  }
922
533
  const Q = "telegram-mini-apps-cached-emitter";
923
534
  function U() {
924
- 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);
941
- }
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
- }
986
- }
987
- 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
- };
995
- }
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
- };
535
+ const r = window;
536
+ return r[Q] === void 0 && (r[Q] = Xe()), r[Q];
537
+ }
538
+ function $(r, e) {
539
+ U().off(r, e);
540
+ }
541
+ function y(r, e) {
542
+ return U().on(r, e), () => $(r, e);
1030
543
  }
1031
544
  class J extends Error {
1032
545
  constructor(e) {
1033
546
  super(`Async call timeout exceeded. Timeout: ${e}`), Object.setPrototypeOf(this, J.prototype);
1034
547
  }
1035
548
  }
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) {
549
+ function et(r) {
1045
550
  return new Promise((e, t) => {
1046
551
  setTimeout(t, r, new J(r));
1047
552
  });
1048
553
  }
1049
- function xe(r, e) {
554
+ function we(r, e) {
1050
555
  return Promise.race([
1051
556
  r(),
1052
- _t(e)
557
+ et(e)
1053
558
  ]);
1054
559
  }
1055
560
  function m(r, e, t, s) {
@@ -1065,7 +570,7 @@ function m(r, e, t, s) {
1065
570
  x(), l(v);
1066
571
  }
1067
572
  });
1068
- return typeof p == "number" ? xe(_, p) : _();
573
+ return typeof p == "number" ? we(_, p) : _();
1069
574
  }
1070
575
  async function H(r, e, t, s = {}) {
1071
576
  const { result: n, error: i } = await m(
@@ -1082,69 +587,70 @@ async function H(r, e, t, s = {}) {
1082
587
  throw new Error(i);
1083
588
  return n;
1084
589
  }
1085
- class bt {
1086
- constructor(e, t, s = d) {
1087
- o(this, "ee", new w());
1088
- o(this, "state");
1089
- /**
1090
- * Adds event listener.
1091
- * @param event - event name.
1092
- * @param listener - event listener.
1093
- */
1094
- o(this, "on", (e, t) => e === "click" ? y("back_button_pressed", t) : this.ee.on(e, t));
1095
- /**
1096
- * Removes event listener.
1097
- * @param event - event name.
1098
- * @param listener - event listener.
1099
- */
1100
- o(this, "off", (e, t) => e === "click" ? $("back_button_pressed", t) : this.ee.off(e, t));
1101
- /**
1102
- * Checks if specified method is supported by current component.
1103
- */
1104
- o(this, "supports");
1105
- this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
1106
- show: "web_app_setup_back_button",
1107
- hide: "web_app_setup_back_button"
1108
- });
1109
- }
1110
- set isVisible(e) {
1111
- this.state.set("isVisible", e), this.postEvent("web_app_setup_back_button", { is_visible: e });
1112
- }
1113
- /**
1114
- * True if BackButton is currently visible.
1115
- */
1116
- get isVisible() {
1117
- return this.state.get("isVisible");
1118
- }
1119
- /**
1120
- * Hides the BackButton.
1121
- */
1122
- hide() {
1123
- this.isVisible = !1;
1124
- }
1125
- /**
1126
- * Shows the BackButton.
1127
- */
1128
- show() {
1129
- this.isVisible = !0;
1130
- }
590
+ function Yt(r, e) {
591
+ return U().once(r, e), () => $(r, e);
1131
592
  }
1132
- function ie(r, e) {
593
+ function tt(r) {
594
+ U().unsubscribe(r);
595
+ }
596
+ function Xt(r) {
597
+ return U().subscribe(r), () => tt(r);
598
+ }
599
+ function ne(r, e) {
1133
600
  return r + (r.length > 0 && e.length > 0 ? ` ${e}` : e);
1134
601
  }
1135
- function mt(...r) {
602
+ function rt(...r) {
1136
603
  return r.reduce((e, t) => {
1137
604
  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);
605
+ return typeof t == "string" ? s = t : typeof t == "object" && t !== null && (s = Object.entries(t).reduce((n, [i, a]) => a ? ne(n, i) : n, "")), ne(e, s);
1139
606
  }, "");
1140
607
  }
1141
- function ir(...r) {
608
+ function er(...r) {
1142
609
  return r.reduce((e, t) => (R(t) && Object.entries(t).forEach(([s, n]) => {
1143
- const i = mt(e[s], n);
610
+ const i = rt(e[s], n);
1144
611
  i.length > 0 && (e[s] = i);
1145
612
  }), e), {});
1146
613
  }
1147
- class yt {
614
+ function _e(r) {
615
+ const e = fe(r);
616
+ return Math.sqrt(
617
+ [0.299, 0.587, 0.114].reduce((s, n, i) => {
618
+ const a = parseInt(e.slice(1 + i * 2, 1 + (i + 1) * 2), 16);
619
+ return s + a * a * n;
620
+ }, 0)
621
+ ) < 120;
622
+ }
623
+ class b {
624
+ constructor(e, t) {
625
+ this.state = e, this.ee = t;
626
+ }
627
+ internalSet(e, t) {
628
+ return this.state[e] === t || t === void 0 ? !1 : (this.state[e] = t, this.ee.emit(`change:${e}`, t), !0);
629
+ }
630
+ /**
631
+ * Returns copy of current state.
632
+ */
633
+ clone() {
634
+ return { ...this.state };
635
+ }
636
+ set(e, t) {
637
+ let s = !1;
638
+ if (typeof e == "string")
639
+ s = this.internalSet(e, t);
640
+ else
641
+ for (const n in e)
642
+ this.internalSet(n, e[n]) && (s = !0);
643
+ s && this.ee.emit("change");
644
+ }
645
+ /**
646
+ * Returns value by specified key.
647
+ * @param key - state key.
648
+ */
649
+ get(e) {
650
+ return this.state[e];
651
+ }
652
+ }
653
+ class st {
1148
654
  constructor(e, t = d) {
1149
655
  o(this, "ee", new w());
1150
656
  o(this, "state");
@@ -1183,10 +689,42 @@ class yt {
1183
689
  this.isConfirmationNeeded = !0;
1184
690
  }
1185
691
  }
1186
- function oe(r, e) {
692
+ function nt(r) {
693
+ if (Array.isArray(r))
694
+ return r;
695
+ if (typeof r == "string")
696
+ try {
697
+ const e = JSON.parse(r);
698
+ if (Array.isArray(e))
699
+ return e;
700
+ } catch {
701
+ }
702
+ throw L();
703
+ }
704
+ class it extends z {
705
+ constructor(t, s, n) {
706
+ super(nt, s, n);
707
+ o(this, "itemParser");
708
+ this.itemParser = typeof t == "function" ? t : t.parse.bind(t);
709
+ }
710
+ parse(t) {
711
+ const s = super.parse(t);
712
+ return s === void 0 ? s : s.map(this.itemParser);
713
+ }
714
+ of(t) {
715
+ return this.itemParser = typeof t == "function" ? t : t.parse.bind(t), this;
716
+ }
717
+ }
718
+ function ot(r) {
719
+ return new it((e) => e, !1, r);
720
+ }
721
+ function E(r, e) {
722
+ return (t) => I(e[t], r);
723
+ }
724
+ function ie(r, e) {
1187
725
  return r.reduce((t, s) => (t[s] = e, t), {});
1188
726
  }
1189
- class Et {
727
+ class at {
1190
728
  constructor(e, t, s = d) {
1191
729
  /**
1192
730
  * Checks if specified method is supported by current component.
@@ -1224,14 +762,14 @@ class Et {
1224
762
  this.createRequestId(),
1225
763
  { ...e, postEvent: this.postEvent }
1226
764
  );
1227
- return $e().of(h()).parse(t);
765
+ return ot().of(h()).parse(t);
1228
766
  }
1229
767
  async get(e, t = {}) {
1230
768
  const s = Array.isArray(e) ? e : [e];
1231
769
  if (s.length === 0)
1232
- return oe(s, "");
770
+ return ie(s, "");
1233
771
  const n = f(
1234
- oe(s, h())
772
+ ie(s, h())
1235
773
  ), i = await H(
1236
774
  "getStorageValues",
1237
775
  { keys: s },
@@ -1255,120 +793,281 @@ class Et {
1255
793
  );
1256
794
  }
1257
795
  }
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();
796
+ class ct {
797
+ constructor(e, t = d) {
798
+ /**
799
+ * Checks if specified method is supported by current component.
800
+ */
801
+ o(this, "supports");
802
+ this.postEvent = t, this.supports = E(e, {
803
+ impactOccurred: "web_app_trigger_haptic_feedback",
804
+ notificationOccurred: "web_app_trigger_haptic_feedback",
805
+ selectionChanged: "web_app_trigger_haptic_feedback"
806
+ });
807
+ }
808
+ /**
809
+ * A method tells that an impact occurred. The Telegram app may play the
810
+ * appropriate haptics based on style value passed.
811
+ * @param style - impact style.
812
+ */
813
+ impactOccurred(e) {
814
+ this.postEvent("web_app_trigger_haptic_feedback", {
815
+ type: "impact",
816
+ impact_style: e
817
+ });
818
+ }
819
+ /**
820
+ * A method tells that a task or action has succeeded, failed, or produced
821
+ * a warning. The Telegram app may play the appropriate haptics based on
822
+ * type value passed.
823
+ * @param type - notification type.
824
+ */
825
+ notificationOccurred(e) {
826
+ this.postEvent("web_app_trigger_haptic_feedback", {
827
+ type: "notification",
828
+ notification_type: e
829
+ });
830
+ }
831
+ /**
832
+ * A method tells that the user has changed a selection. The Telegram app
833
+ * may play the appropriate haptics.
834
+ *
835
+ * Do not use this feedback when the user makes or confirms a selection;
836
+ * use it only when the selection changes.
837
+ */
838
+ selectionChanged() {
839
+ this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
840
+ }
841
+ }
842
+ function ht() {
843
+ return f({
844
+ id: A(),
845
+ type: h(),
846
+ title: h(),
847
+ photoUrl: {
848
+ type: h().optional(),
849
+ from: "photo_url"
850
+ },
851
+ username: h().optional()
852
+ }, "Chat");
853
+ }
854
+ class ut {
855
+ constructor(e) {
856
+ this.initData = e;
857
+ }
858
+ /**
859
+ * @see InitDataParsed.authDate
860
+ */
861
+ get authDate() {
862
+ return this.initData.authDate;
863
+ }
864
+ /**
865
+ * @see InitDataParsed.canSendAfter
866
+ */
867
+ get canSendAfter() {
868
+ return this.initData.canSendAfter;
869
+ }
870
+ /**
871
+ * Date after which it is allowed to call
872
+ * the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
873
+ */
874
+ get canSendAfterDate() {
875
+ const { canSendAfter: e } = this;
876
+ return e === void 0 ? void 0 : new Date(this.authDate.getTime() + e * 1e3);
877
+ }
878
+ /**
879
+ * @see InitDataParsed.chat
880
+ */
881
+ get chat() {
882
+ return this.initData.chat;
883
+ }
884
+ /**
885
+ * @see InitDataParsed.chatType
886
+ */
887
+ get chatType() {
888
+ return this.initData.chatType;
889
+ }
890
+ /**
891
+ * @see InitDataParsed.chatInstance
892
+ */
893
+ get chatInstance() {
894
+ return this.initData.chatInstance;
895
+ }
896
+ /**
897
+ * @see InitDataParsed.hash
898
+ */
899
+ get hash() {
900
+ return this.initData.hash;
901
+ }
902
+ /**
903
+ * @see InitDataParsed.queryId
904
+ */
905
+ get queryId() {
906
+ return this.initData.queryId;
907
+ }
908
+ /**
909
+ * @see InitDataParsed.receiver
910
+ */
911
+ get receiver() {
912
+ return this.initData.receiver;
913
+ }
914
+ /**
915
+ * @see InitDataParsed.startParam
916
+ */
917
+ get startParam() {
918
+ return this.initData.startParam;
919
+ }
920
+ /**
921
+ * @see InitDataParsed.user
922
+ */
923
+ get user() {
924
+ return this.initData.user;
925
+ }
926
+ }
927
+ function oe() {
928
+ return f({
929
+ addedToAttachmentMenu: {
930
+ type: k().optional(),
931
+ from: "added_to_attachment_menu"
932
+ },
933
+ allowsWriteToPm: {
934
+ type: k().optional(),
935
+ from: "allows_write_to_pm"
936
+ },
937
+ firstName: {
938
+ type: h(),
939
+ from: "first_name"
940
+ },
941
+ id: A(),
942
+ isBot: {
943
+ type: k().optional(),
944
+ from: "is_bot"
945
+ },
946
+ isPremium: {
947
+ type: k().optional(),
948
+ from: "is_premium"
949
+ },
950
+ languageCode: {
951
+ type: h().optional(),
952
+ from: "language_code"
953
+ },
954
+ lastName: {
955
+ type: h().optional(),
956
+ from: "last_name"
957
+ },
958
+ photoUrl: {
959
+ type: h().optional(),
960
+ from: "photo_url"
961
+ },
962
+ username: h().optional()
963
+ }, "User");
1280
964
  }
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
- }
965
+ const be = T((r) => r instanceof Date ? r : new Date(A().parse(r) * 1e3), "Date");
966
+ function re(r, e) {
967
+ return new z((t) => {
968
+ if (typeof t != "string" && !(t instanceof URLSearchParams))
969
+ throw L();
970
+ const s = typeof t == "string" ? new URLSearchParams(t) : t;
971
+ return de(r, (n) => {
972
+ const i = s.get(n);
973
+ return i === null ? void 0 : i;
1289
974
  });
1290
- };
1291
- r.on("change", e), e();
975
+ }, !1, e);
1292
976
  }
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();
977
+ function me() {
978
+ return re({
979
+ authDate: {
980
+ type: be(),
981
+ from: "auth_date"
982
+ },
983
+ canSendAfter: {
984
+ type: A().optional(),
985
+ from: "can_send_after"
986
+ },
987
+ chat: ht().optional(),
988
+ chatInstance: {
989
+ type: h().optional(),
990
+ from: "chat_instance"
991
+ },
992
+ chatType: {
993
+ type: h().optional(),
994
+ from: "chat_type"
995
+ },
996
+ hash: h(),
997
+ queryId: {
998
+ type: h().optional(),
999
+ from: "query_id"
1000
+ },
1001
+ receiver: oe().optional(),
1002
+ startParam: {
1003
+ type: h().optional(),
1004
+ from: "start_param"
1005
+ },
1006
+ user: oe().optional()
1007
+ }, "InitData");
1296
1008
  }
1297
- class Pt {
1009
+ function tr(r) {
1010
+ return me().parse(r);
1011
+ }
1012
+ function pt(r) {
1013
+ const { hostname: e, pathname: t } = new URL(r, window.location.href);
1014
+ if (e !== "t.me")
1015
+ throw new Error(`Incorrect hostname: ${e}`);
1016
+ const s = t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1017
+ if (s === null)
1018
+ throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1019
+ return s[2];
1020
+ }
1021
+ class lt {
1298
1022
  constructor(e, t = d) {
1023
+ o(this, "ee", new w());
1024
+ o(this, "state");
1025
+ /**
1026
+ * Adds new event listener.
1027
+ */
1028
+ o(this, "on", this.ee.on.bind(this.ee));
1029
+ /**
1030
+ * Removes event listener.
1031
+ */
1032
+ o(this, "off", this.ee.off.bind(this.ee));
1299
1033
  /**
1300
1034
  * Checks if specified method is supported by current component.
1301
1035
  */
1302
1036
  o(this, "supports");
1303
- this.postEvent = t, this.supports = E(e, {
1304
- impactOccurred: "web_app_trigger_haptic_feedback",
1305
- notificationOccurred: "web_app_trigger_haptic_feedback",
1306
- selectionChanged: "web_app_trigger_haptic_feedback"
1307
- });
1037
+ this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, { open: "web_app_open_invoice" });
1308
1038
  }
1309
- /**
1310
- * A method tells that an impact occurred. The Telegram app may play the
1311
- * appropriate haptics based on style value passed.
1312
- * @param style - impact style.
1313
- */
1314
- impactOccurred(e) {
1315
- this.postEvent("web_app_trigger_haptic_feedback", {
1316
- type: "impact",
1317
- impact_style: e
1318
- });
1039
+ set isOpened(e) {
1040
+ this.state.set("isOpened", e);
1319
1041
  }
1320
1042
  /**
1321
- * A method tells that a task or action has succeeded, failed, or produced
1322
- * a warning. The Telegram app may play the appropriate haptics based on
1323
- * type value passed.
1324
- * @param type - notification type.
1043
+ * True if invoice is currently opened.
1325
1044
  */
1326
- notificationOccurred(e) {
1327
- this.postEvent("web_app_trigger_haptic_feedback", {
1328
- type: "notification",
1329
- notification_type: e
1330
- });
1045
+ get isOpened() {
1046
+ return this.state.get("isOpened");
1331
1047
  }
1332
- /**
1333
- * A method tells that the user has changed a selection. The Telegram app
1334
- * may play the appropriate haptics.
1335
- *
1336
- * Do not use this feedback when the user makes or confirms a selection;
1337
- * use it only when the selection changes.
1338
- */
1339
- selectionChanged() {
1340
- this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1048
+ async open(e, t) {
1049
+ if (this.isOpened)
1050
+ throw new Error("Invoice is already opened");
1051
+ const s = t ? pt(e) : e;
1052
+ this.isOpened = !0;
1053
+ try {
1054
+ return (await m(
1055
+ "web_app_open_invoice",
1056
+ { slug: s },
1057
+ "invoice_closed",
1058
+ {
1059
+ postEvent: this.postEvent,
1060
+ capture(i) {
1061
+ return s === i.slug;
1062
+ }
1063
+ }
1064
+ )).status;
1065
+ } finally {
1066
+ this.isOpened = !1;
1067
+ }
1341
1068
  }
1342
1069
  }
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
- });
1348
- }
1349
- function qe(r) {
1350
- return `telegram-mini-apps-${r}`;
1351
- }
1352
- function B(r, e) {
1353
- sessionStorage.setItem(qe(r), JSON.stringify(e));
1354
- }
1355
- function D(r) {
1356
- const e = sessionStorage.getItem(qe(r));
1357
- return e ? JSON.parse(e) : null;
1358
- }
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;
1364
- }
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;
1370
- }
1371
- class qt {
1070
+ class dt {
1372
1071
  constructor(e) {
1373
1072
  o(this, "ee", new w());
1374
1073
  o(this, "state");
@@ -1533,33 +1232,7 @@ class qt {
1533
1232
  return this.state.set(e), this.commit(), this;
1534
1233
  }
1535
1234
  }
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({
1235
+ const ft = re({
1563
1236
  contact: f({
1564
1237
  userId: {
1565
1238
  type: A(),
@@ -1579,12 +1252,23 @@ const Vt = ee({
1579
1252
  }
1580
1253
  }),
1581
1254
  authDate: {
1582
- type: fe(),
1255
+ type: be(),
1583
1256
  from: "auth_date"
1584
1257
  },
1585
1258
  hash: h()
1586
1259
  });
1587
- class Rt {
1260
+ function ye(r, e) {
1261
+ return (t) => {
1262
+ const [s, n] = e[t];
1263
+ return I(s, n, r);
1264
+ };
1265
+ }
1266
+ function gt(r) {
1267
+ return new Promise((e) => {
1268
+ setTimeout(e, r);
1269
+ });
1270
+ }
1271
+ class wt {
1588
1272
  constructor(e) {
1589
1273
  o(this, "ee", new w());
1590
1274
  o(this, "state");
@@ -1623,7 +1307,7 @@ class Rt {
1623
1307
  setHeaderColor: "web_app_set_header_color",
1624
1308
  setBackgroundColor: "web_app_set_background_color"
1625
1309
  });
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, {
1310
+ 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 = ye(i, {
1627
1311
  "setHeaderColor.color": ["web_app_set_header_color", "color"]
1628
1312
  });
1629
1313
  }
@@ -1639,7 +1323,7 @@ class Rt {
1639
1323
  postEvent: this.postEvent,
1640
1324
  timeout: 1e4
1641
1325
  }
1642
- ).then((e) => Vt.parse(e));
1326
+ ).then((e) => ft.parse(e));
1643
1327
  }
1644
1328
  /**
1645
1329
  * The Mini App background color.
@@ -1669,7 +1353,7 @@ class Rt {
1669
1353
  * True if current Mini App background color recognized as dark.
1670
1354
  */
1671
1355
  get isDark() {
1672
- return we(this.backgroundColor);
1356
+ return _e(this.backgroundColor);
1673
1357
  }
1674
1358
  /**
1675
1359
  * True if phone access is currently being requested.
@@ -1710,13 +1394,13 @@ class Rt {
1710
1394
  throw new Error("Access denied.");
1711
1395
  const s = Date.now() + e;
1712
1396
  let n = 50;
1713
- return xe(async () => {
1397
+ return we(async () => {
1714
1398
  for (; Date.now() < s; ) {
1715
1399
  try {
1716
1400
  return await this.getRequestedContact();
1717
1401
  } catch {
1718
1402
  }
1719
- await wt(n), n += 50;
1403
+ await gt(n), n += 50;
1720
1404
  }
1721
1405
  throw new Error("Unable to retrieve requested contact.");
1722
1406
  }, e);
@@ -1774,7 +1458,7 @@ class Rt {
1774
1458
  * @param color - color key or RGB color.
1775
1459
  */
1776
1460
  setHeaderColor(e) {
1777
- this.postEvent("web_app_set_header_color", X(e) ? { color: e } : { color_key: e }), this.state.set("headerColor", e);
1461
+ this.postEvent("web_app_set_header_color", te(e) ? { color: e } : { color_key: e }), this.state.set("headerColor", e);
1778
1462
  }
1779
1463
  /**
1780
1464
  * Updates current Mini App background color.
@@ -1802,104 +1486,87 @@ class Rt {
1802
1486
  });
1803
1487
  }
1804
1488
  }
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());
1489
+ function _t(r) {
1490
+ const e = r.message.trim(), t = (r.title || "").trim(), s = r.buttons || [];
1491
+ let n;
1492
+ if (t.length > 64)
1493
+ throw new Error(`Title has incorrect size: ${t.length}`);
1494
+ if (e.length === 0 || e.length > 256)
1495
+ throw new Error(`Message has incorrect size: ${e.length}`);
1496
+ if (s.length > 3)
1497
+ throw new Error(`Buttons have incorrect size: ${s.length}`);
1498
+ return s.length === 0 ? n = [{ type: "close", id: "" }] : n = s.map((i) => {
1499
+ const { id: a = "" } = i;
1500
+ if (a.length > 64)
1501
+ throw new Error(`Button ID has incorrect size: ${a}`);
1502
+ if (i.type === void 0 || i.type === "default" || i.type === "destructive") {
1503
+ const c = i.text.trim();
1504
+ if (c.length === 0 || c.length > 64) {
1505
+ const u = i.type || "default";
1506
+ throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`);
1507
+ }
1508
+ return { ...i, text: c, id: a };
1509
+ }
1510
+ return { ...i, id: a };
1511
+ }), { title: t, message: e, buttons: n };
1825
1512
  }
1826
- class Tt {
1827
- constructor(e, t, s = d) {
1513
+ class bt {
1514
+ constructor(e, t = d) {
1828
1515
  o(this, "ee", new w());
1829
1516
  o(this, "state");
1830
1517
  /**
1831
- * Adds event listener.
1832
- * @param event - event name.
1833
- * @param listener - event listener.
1518
+ * Adds new event listener.
1834
1519
  */
1835
- o(this, "on", (e, t) => e === "click" ? y("settings_button_pressed", t) : this.ee.on(e, t));
1520
+ o(this, "on", this.ee.on.bind(this.ee));
1836
1521
  /**
1837
1522
  * Removes event listener.
1838
- * @param event - event name.
1839
- * @param listener - event listener.
1840
1523
  */
1841
- o(this, "off", (e, t) => e === "click" ? $("settings_button_pressed", t) : this.ee.off(e, t));
1524
+ o(this, "off", this.ee.off.bind(this.ee));
1842
1525
  /**
1843
1526
  * Checks if specified method is supported by current component.
1844
1527
  */
1845
1528
  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"
1849
- });
1850
- }
1851
- set isVisible(e) {
1852
- this.state.set("isVisible", e), this.postEvent("web_app_setup_settings_button", { is_visible: e });
1529
+ this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, { open: "web_app_open_popup" });
1853
1530
  }
1854
- /**
1855
- * True if SettingsButton is currently visible.
1856
- */
1857
- get isVisible() {
1858
- return this.state.get("isVisible");
1531
+ set isOpened(e) {
1532
+ this.state.set("isOpened", e);
1859
1533
  }
1860
1534
  /**
1861
- * Hides the SettingsButton.
1535
+ * True if popup is currently opened.
1862
1536
  */
1863
- hide() {
1864
- this.isVisible = !1;
1537
+ get isOpened() {
1538
+ return this.state.get("isOpened");
1865
1539
  }
1866
1540
  /**
1867
- * Shows the SettingsButton.
1541
+ * A method that shows a native popup described by the `params` argument.
1542
+ * Promise will be resolved when popup is closed. Resolved value will have
1543
+ * an identifier of pressed button.
1544
+ *
1545
+ * In case, user clicked outside the popup or clicked top right popup close
1546
+ * button, null will be returned.
1547
+ *
1548
+ * FIXME: In desktop, this function may work incorrectly.
1549
+ * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7
1550
+ * @param options - popup parameters.
1551
+ * @throws {Error} Popup is already opened.
1868
1552
  */
1869
- show() {
1870
- this.isVisible = !0;
1553
+ open(e) {
1554
+ if (this.isOpened)
1555
+ throw new Error("Popup is already opened.");
1556
+ return this.isOpened = !0, m(
1557
+ "web_app_open_popup",
1558
+ _t(e),
1559
+ "popup_closed",
1560
+ { postEvent: this.postEvent }
1561
+ ).then(({ button_id: t = null }) => t).finally(() => {
1562
+ this.isOpened = !1;
1563
+ });
1871
1564
  }
1872
1565
  }
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) {
1884
- return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
1885
- }
1886
- async function Ae(r) {
1887
- const e = await m("web_app_request_viewport", "viewport_changed", r);
1888
- return {
1889
- height: e.height,
1890
- width: e.width,
1891
- isExpanded: e.is_expanded,
1892
- isStateStable: e.is_state_stable
1893
- };
1894
- }
1895
- function W(r) {
1896
- return r < 0 ? 0 : r;
1897
- }
1898
- class Wt {
1899
- constructor(e) {
1566
+ class mt {
1567
+ constructor(e, t = d) {
1900
1568
  o(this, "ee", new w());
1901
1569
  o(this, "state");
1902
- o(this, "postEvent");
1903
1570
  /**
1904
1571
  * Adds new event listener.
1905
1572
  */
@@ -1908,185 +1575,126 @@ class Wt {
1908
1575
  * Removes event listener.
1909
1576
  */
1910
1577
  o(this, "off", this.ee.off.bind(this.ee));
1911
- const {
1912
- height: t,
1913
- isExpanded: s,
1914
- width: n,
1915
- stableHeight: i,
1916
- postEvent: a = d
1917
- } = e;
1918
- this.postEvent = a, this.state = new b({
1919
- height: W(t),
1920
- isExpanded: s,
1921
- stableHeight: W(i),
1922
- width: W(n)
1923
- }, this.ee);
1924
- }
1925
- /**
1926
- * Request viewport information from the Telegram application and updates current Viewport
1927
- * instance.
1928
- * @param options - options to request fresh data.
1929
- */
1930
- sync(e) {
1931
- return Ae(e).then(({ height: t, isExpanded: s, width: n, isStateStable: i }) => {
1932
- this.state.set({
1933
- height: t,
1934
- width: n,
1935
- isExpanded: s,
1936
- stableHeight: i ? t : this.state.get("stableHeight")
1937
- });
1578
+ /**
1579
+ * Checks if specified method is supported by current component.
1580
+ */
1581
+ o(this, "supports");
1582
+ this.postEvent = t, this.state = new b({ isOpened: !1 }, this.ee), this.supports = E(e, {
1583
+ close: "web_app_close_scan_qr_popup",
1584
+ open: "web_app_open_scan_qr_popup"
1938
1585
  });
1939
1586
  }
1940
1587
  /**
1941
- * The current height of the visible area of the Mini App.
1942
- *
1943
- * The application can display just the top part of the Mini App, with its
1944
- * lower part remaining outside the screen area. From this position, the
1945
- * user can "pull" the Mini App to its maximum height, while the bot can do
1946
- * the same by calling `expand` method. As the position of the Mini App
1947
- * changes, the current height value of the visible area will be updated
1948
- * in real time.
1949
- *
1950
- * Please note that the refresh rate of this value is not sufficient
1951
- * to smoothly follow the lower border of the window. It should not be
1952
- * used to pin interface elements to the bottom of the visible area. It's
1953
- * more appropriate to use the value of the `stableHeight`
1954
- * field for this purpose.
1588
+ * Closes scanner.
1955
1589
  */
1956
- get height() {
1957
- return this.state.get("height");
1590
+ close() {
1591
+ this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
1592
+ }
1593
+ set isOpened(e) {
1594
+ this.state.set("isOpened", e);
1958
1595
  }
1959
1596
  /**
1960
- * The height of the visible area of the Mini App in its last stable state.
1961
- *
1962
- * The application can display just the top part of the Mini App, with its
1963
- * lower part remaining outside the screen area. From this position,
1964
- * the user can "pull" the Mini App to its maximum height, while the bot can
1965
- * do the same by calling `expand` method.
1966
- *
1967
- * Unlike the value of `height`, the value of `stableHeight`
1968
- * does not change as the position of the Mini App changes with user
1969
- * gestures or during animations. The value of `stableHeight`
1970
- * will be updated after all gestures and animations are completed and
1971
- * the Mini App reaches its final size.
1597
+ * Returns true in case, QR scanner is currently opened.
1972
1598
  */
1973
- get stableHeight() {
1974
- return this.state.get("stableHeight");
1599
+ get isOpened() {
1600
+ return this.state.get("isOpened");
1975
1601
  }
1976
1602
  /**
1977
- * Starts listening to viewport changes and applies them.
1978
- * @returns Function to stop listening.
1603
+ * Opens scanner with specified title shown to user. Method returns promise
1604
+ * with scanned QR content in case, it was scanned. It will contain null in
1605
+ * case, scanner was closed.
1606
+ * @param text - title to display.
1979
1607
  */
1980
- listen() {
1981
- return y("viewport_changed", (e) => {
1982
- const {
1983
- height: t,
1984
- width: s,
1985
- is_expanded: n,
1986
- is_state_stable: i
1987
- } = e, a = {
1988
- height: W(t),
1989
- isExpanded: n,
1990
- width: W(s)
1991
- };
1992
- i && (a.stableHeight = a.height), this.state.set(a);
1608
+ async open(e) {
1609
+ if (this.isOpened)
1610
+ throw new Error("QR scanner is already opened.");
1611
+ this.isOpened = !0;
1612
+ try {
1613
+ const t = await m(
1614
+ "web_app_open_scan_qr_popup",
1615
+ { text: e },
1616
+ ["qr_text_received", "scan_qr_popup_closed"],
1617
+ { postEvent: this.postEvent }
1618
+ );
1619
+ return typeof t == "object" && typeof t.data == "string" ? t.data : null;
1620
+ } finally {
1621
+ this.isOpened = !1;
1622
+ }
1623
+ }
1624
+ }
1625
+ class yt {
1626
+ constructor(e, t, s = d) {
1627
+ o(this, "ee", new w());
1628
+ o(this, "state");
1629
+ /**
1630
+ * Adds event listener.
1631
+ * @param event - event name.
1632
+ * @param listener - event listener.
1633
+ */
1634
+ o(this, "on", (e, t) => e === "click" ? y("settings_button_pressed", t) : this.ee.on(e, t));
1635
+ /**
1636
+ * Removes event listener.
1637
+ * @param event - event name.
1638
+ * @param listener - event listener.
1639
+ */
1640
+ o(this, "off", (e, t) => e === "click" ? $("settings_button_pressed", t) : this.ee.off(e, t));
1641
+ /**
1642
+ * Checks if specified method is supported by current component.
1643
+ */
1644
+ o(this, "supports");
1645
+ this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
1646
+ show: "web_app_setup_settings_button",
1647
+ hide: "web_app_setup_settings_button"
1993
1648
  });
1994
1649
  }
1995
- /**
1996
- * Returns true if the Mini App is expanded to the maximum available height.
1997
- * Otherwise, if the Mini App occupies part of the screen and can be expanded
1998
- * to the full height using `expand` method.
1999
- * @see expand
2000
- */
2001
- get isExpanded() {
2002
- return this.state.get("isExpanded");
1650
+ set isVisible(e) {
1651
+ this.state.set("isVisible", e), this.postEvent("web_app_setup_settings_button", { is_visible: e });
2003
1652
  }
2004
1653
  /**
2005
- * Current viewport width.
1654
+ * True if SettingsButton is currently visible.
2006
1655
  */
2007
- get width() {
2008
- return this.state.get("width");
1656
+ get isVisible() {
1657
+ return this.state.get("isVisible");
2009
1658
  }
2010
1659
  /**
2011
- * A method that expands the Mini App to the maximum available height. To
2012
- * find out if the Mini App is expanded to the maximum height, refer to the
2013
- * value of the `isExpanded`.
2014
- * @see isExpanded
1660
+ * Hides the SettingsButton.
2015
1661
  */
2016
- expand() {
2017
- this.postEvent("web_app_expand"), this.state.set("isExpanded", !0);
1662
+ hide() {
1663
+ this.isVisible = !1;
2018
1664
  }
2019
1665
  /**
2020
- * Returns true in case current viewport height is stable and is not going to
2021
- * change in the next moment.
1666
+ * Shows the SettingsButton.
2022
1667
  */
2023
- get isStable() {
2024
- return this.stableHeight === this.height;
1668
+ show() {
1669
+ this.isVisible = !0;
2025
1670
  }
2026
1671
  }
2027
- function G(r) {
2028
- const e = new Wt(r);
2029
- return e.on("change", () => B("viewport", {
2030
- height: e.height,
2031
- isExpanded: e.isExpanded,
2032
- stableHeight: e.stableHeight,
2033
- width: e.width
2034
- })), e.listen(), e;
1672
+ function Et(r) {
1673
+ return r.replace(/(^|_)bg/, (e, t) => `${t}background`).replace(/_([a-z])/g, (e, t) => t.toUpperCase());
2035
1674
  }
2036
- function Ot(r, e, t, s) {
2037
- const n = r ? D("viewport") : null;
2038
- if (n)
2039
- return G({ ...n, postEvent: t });
2040
- if (Dt(e))
2041
- return G({
2042
- height: window.innerHeight,
2043
- isExpanded: !0,
2044
- postEvent: t,
2045
- stableHeight: window.innerHeight,
2046
- width: window.innerWidth
2047
- });
2048
- if (s)
2049
- return Ae({
2050
- postEvent: t,
2051
- timeout: 5e3
2052
- }).then(({ height: a, isStateStable: c, ...u }) => G({
2053
- ...u,
2054
- height: a,
2055
- stableHeight: c ? a : 0
2056
- }));
2057
- const i = G({
2058
- width: 0,
2059
- height: 0,
2060
- isExpanded: !1,
2061
- postEvent: t,
2062
- stableHeight: 0
2063
- });
2064
- return i.sync({ postEvent: t, timeout: 5e3 }).catch((a) => {
2065
- console.error("Unable to actualize viewport state", a);
2066
- }), i;
1675
+ function Ct(r) {
1676
+ return r.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`).replace(/(^|_)background/, (e, t) => `${t}bg`);
2067
1677
  }
2068
- function Ht(r) {
2069
- return typeof r == "object" ? r : r ? {
2070
- themeParams: !0,
2071
- viewport: !0,
2072
- miniApp: !0
2073
- } : {};
1678
+ const Ee = T(
1679
+ (r) => {
1680
+ const e = ge().optional();
1681
+ return Object.entries(ee(r)).reduce((t, [s, n]) => (t[Et(s)] = e.parse(n), t), {});
1682
+ },
1683
+ "ThemeParams"
1684
+ );
1685
+ function Ce(r) {
1686
+ return Ee().parse(r);
2074
1687
  }
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));
1688
+ function rr(r = {}) {
1689
+ return m("web_app_request_theme", "theme_changed", r).then(Ce);
2078
1690
  }
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];
1691
+ function vt(r) {
1692
+ return JSON.stringify(
1693
+ Object.entries(r).reduce((e, [t, s]) => (s && (e[Ct(t)] = s), e), {})
1694
+ );
2087
1695
  }
2088
- class Ut {
2089
- constructor(e, t = d) {
1696
+ class Pt {
1697
+ constructor(e) {
2090
1698
  o(this, "ee", new w());
2091
1699
  o(this, "state");
2092
1700
  /**
@@ -2097,71 +1705,183 @@ class Ut {
2097
1705
  * Removes event listener.
2098
1706
  */
2099
1707
  o(this, "off", this.ee.off.bind(this.ee));
1708
+ this.state = new b(e, this.ee);
1709
+ }
1710
+ /**
1711
+ * @since v6.10
1712
+ */
1713
+ get accentTextColor() {
1714
+ return this.get("accentTextColor");
1715
+ }
1716
+ get backgroundColor() {
1717
+ return this.get("backgroundColor");
1718
+ }
1719
+ get buttonColor() {
1720
+ return this.get("buttonColor");
1721
+ }
1722
+ get buttonTextColor() {
1723
+ return this.get("buttonTextColor");
1724
+ }
1725
+ get destructiveTextColor() {
1726
+ return this.get("destructiveTextColor");
1727
+ }
1728
+ /**
1729
+ * Retrieves palette color value by its name.
1730
+ * @param key - palette key name.
1731
+ */
1732
+ get(e) {
1733
+ return this.state.get(e);
1734
+ }
1735
+ /**
1736
+ * Returns the copy of the internal state of the current component instance.
1737
+ */
1738
+ getState() {
1739
+ return this.state.clone();
1740
+ }
1741
+ /**
1742
+ * @since v6.10
1743
+ */
1744
+ get headerBackgroundColor() {
1745
+ return this.get("headerBackgroundColor");
1746
+ }
1747
+ get hintColor() {
1748
+ return this.get("hintColor");
1749
+ }
1750
+ /**
1751
+ * Returns true in case, current color scheme is recognized as dark. This
1752
+ * value is calculated according to theme background color.
1753
+ */
1754
+ get isDark() {
1755
+ return !this.backgroundColor || _e(this.backgroundColor);
1756
+ }
1757
+ get linkColor() {
1758
+ return this.get("linkColor");
1759
+ }
1760
+ get secondaryBackgroundColor() {
1761
+ return this.get("secondaryBackgroundColor");
1762
+ }
1763
+ /**
1764
+ * @since v6.10
1765
+ */
1766
+ get sectionBackgroundColor() {
1767
+ return this.get("sectionBackgroundColor");
1768
+ }
1769
+ /**
1770
+ * @since v6.10
1771
+ */
1772
+ get sectionHeaderTextColor() {
1773
+ return this.get("sectionHeaderTextColor");
1774
+ }
1775
+ /**
1776
+ * Starts listening to theme changes and applies them.
1777
+ * @returns Function to stop listening.
1778
+ */
1779
+ listen() {
1780
+ return y("theme_changed", (e) => {
1781
+ this.state.set(Ce(e.theme_params));
1782
+ });
1783
+ }
1784
+ /**
1785
+ * @since v6.10
1786
+ */
1787
+ get subtitleTextColor() {
1788
+ return this.get("subtitleTextColor");
1789
+ }
1790
+ get textColor() {
1791
+ return this.get("textColor");
1792
+ }
1793
+ }
1794
+ class kt {
1795
+ constructor(e, t, s = d) {
2100
1796
  /**
2101
1797
  * Checks if specified method is supported by current component.
2102
1798
  */
2103
1799
  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);
1800
+ /**
1801
+ * Checks if specified method parameter is supported by current component.
1802
+ */
1803
+ o(this, "supportsParam");
1804
+ this.version = e, this.createRequestId = t, this.postEvent = s, this.supports = E(e, {
1805
+ readTextFromClipboard: "web_app_read_text_from_clipboard"
1806
+ }), this.supportsParam = ye(e, {
1807
+ "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
1808
+ });
2108
1809
  }
2109
1810
  /**
2110
- * True if invoice is currently opened.
1811
+ * Opens a link in an external browser. The Mini App will not be closed.
1812
+ *
1813
+ * Note that this method can be called only in response to the user
1814
+ * interaction with the Mini App interface (e.g. click inside the Mini App
1815
+ * or on the main button).
1816
+ * @param url - URL to be opened.
1817
+ * @param tryInstantView
2111
1818
  */
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;
1819
+ openLink(e, t) {
1820
+ const s = new URL(e, window.location.href).toString();
1821
+ if (!I("web_app_open_link", this.version)) {
1822
+ window.open(s, "_blank");
1823
+ return;
2134
1824
  }
1825
+ this.postEvent("web_app_open_link", {
1826
+ url: s,
1827
+ ...typeof t == "boolean" ? { try_instant_view: t } : {}
1828
+ });
2135
1829
  }
2136
- }
2137
- 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 };
1830
+ /**
1831
+ * Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
1832
+ * link in full format, with hostname "t.me".
1833
+ * @param url - URL to be opened.
1834
+ * @throws {Error} URL has not allowed hostname.
1835
+ */
1836
+ openTelegramLink(e) {
1837
+ const {
1838
+ hostname: t,
1839
+ pathname: s,
1840
+ search: n
1841
+ } = new URL(e, window.location.href);
1842
+ if (t !== "t.me")
1843
+ throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);
1844
+ if (!I("web_app_open_tg_link", this.version)) {
1845
+ window.location.href = e;
1846
+ return;
2157
1847
  }
2158
- return { ...i, id: a };
2159
- }), { title: t, message: e, buttons: n };
1848
+ this.postEvent("web_app_open_tg_link", { path_full: s + n });
1849
+ }
1850
+ /**
1851
+ * Reads text from clipboard and returns string or null. null is returned
1852
+ * in cases:
1853
+ * - Value in clipboard is not text
1854
+ * - Access to clipboard is not allowed
1855
+ */
1856
+ readTextFromClipboard() {
1857
+ return m(
1858
+ "web_app_read_text_from_clipboard",
1859
+ { req_id: this.createRequestId() },
1860
+ "clipboard_text_received",
1861
+ { postEvent: this.postEvent }
1862
+ ).then(({ data: e = null }) => e);
1863
+ }
2160
1864
  }
2161
- class Gt {
2162
- constructor(e, t = d) {
1865
+ function St(r) {
1866
+ return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
1867
+ }
1868
+ async function ve(r) {
1869
+ const e = await m("web_app_request_viewport", "viewport_changed", r);
1870
+ return {
1871
+ height: e.height,
1872
+ width: e.width,
1873
+ isExpanded: e.is_expanded,
1874
+ isStateStable: e.is_state_stable
1875
+ };
1876
+ }
1877
+ function W(r) {
1878
+ return r < 0 ? 0 : r;
1879
+ }
1880
+ class xt {
1881
+ constructor(e) {
2163
1882
  o(this, "ee", new w());
2164
1883
  o(this, "state");
1884
+ o(this, "postEvent");
2165
1885
  /**
2166
1886
  * Adds new event listener.
2167
1887
  */
@@ -2170,178 +1890,443 @@ class Gt {
2170
1890
  * Removes event listener.
2171
1891
  */
2172
1892
  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" });
1893
+ const {
1894
+ height: t,
1895
+ isExpanded: s,
1896
+ width: n,
1897
+ stableHeight: i,
1898
+ postEvent: a = d
1899
+ } = e;
1900
+ this.postEvent = a, this.state = new b({
1901
+ height: W(t),
1902
+ isExpanded: s,
1903
+ stableHeight: W(i),
1904
+ width: W(n)
1905
+ }, this.ee);
2178
1906
  }
2179
- set isOpened(e) {
2180
- this.state.set("isOpened", e);
1907
+ /**
1908
+ * Request viewport information from the Telegram application and updates current Viewport
1909
+ * instance.
1910
+ * @param options - options to request fresh data.
1911
+ */
1912
+ sync(e) {
1913
+ return ve(e).then(({ height: t, isExpanded: s, width: n, isStateStable: i }) => {
1914
+ this.state.set({
1915
+ height: t,
1916
+ width: n,
1917
+ isExpanded: s,
1918
+ stableHeight: i ? t : this.state.get("stableHeight")
1919
+ });
1920
+ });
2181
1921
  }
2182
1922
  /**
2183
- * True if popup is currently opened.
1923
+ * The current height of the visible area of the Mini App.
1924
+ *
1925
+ * The application can display just the top part of the Mini App, with its
1926
+ * lower part remaining outside the screen area. From this position, the
1927
+ * user can "pull" the Mini App to its maximum height, while the bot can do
1928
+ * the same by calling `expand` method. As the position of the Mini App
1929
+ * changes, the current height value of the visible area will be updated
1930
+ * in real time.
1931
+ *
1932
+ * Please note that the refresh rate of this value is not sufficient
1933
+ * to smoothly follow the lower border of the window. It should not be
1934
+ * used to pin interface elements to the bottom of the visible area. It's
1935
+ * more appropriate to use the value of the `stableHeight`
1936
+ * field for this purpose.
2184
1937
  */
2185
- get isOpened() {
2186
- return this.state.get("isOpened");
1938
+ get height() {
1939
+ return this.state.get("height");
2187
1940
  }
2188
1941
  /**
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.
1942
+ * The height of the visible area of the Mini App in its last stable state.
2192
1943
  *
2193
- * In case, user clicked outside the popup or clicked top right popup close
2194
- * button, null will be returned.
1944
+ * The application can display just the top part of the Mini App, with its
1945
+ * lower part remaining outside the screen area. From this position,
1946
+ * the user can "pull" the Mini App to its maximum height, while the bot can
1947
+ * do the same by calling `expand` method.
2195
1948
  *
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.
1949
+ * Unlike the value of `height`, the value of `stableHeight`
1950
+ * does not change as the position of the Mini App changes with user
1951
+ * gestures or during animations. The value of `stableHeight`
1952
+ * will be updated after all gestures and animations are completed and
1953
+ * the Mini App reaches its final size.
2200
1954
  */
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
- });
1955
+ get stableHeight() {
1956
+ return this.state.get("stableHeight");
2212
1957
  }
2213
- }
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"
1958
+ /**
1959
+ * Starts listening to viewport changes and applies them.
1960
+ * @returns Function to stop listening.
1961
+ */
1962
+ listen() {
1963
+ return y("viewport_changed", (e) => {
1964
+ const {
1965
+ height: t,
1966
+ width: s,
1967
+ is_expanded: n,
1968
+ is_state_stable: i
1969
+ } = e, a = {
1970
+ height: W(t),
1971
+ isExpanded: n,
1972
+ width: W(s)
1973
+ };
1974
+ i && (a.stableHeight = a.height), this.state.set(a);
2233
1975
  });
2234
1976
  }
2235
1977
  /**
2236
- * Closes scanner.
1978
+ * Returns true if the Mini App is expanded to the maximum available height.
1979
+ * Otherwise, if the Mini App occupies part of the screen and can be expanded
1980
+ * to the full height using `expand` method.
1981
+ * @see expand
2237
1982
  */
2238
- close() {
2239
- this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
1983
+ get isExpanded() {
1984
+ return this.state.get("isExpanded");
2240
1985
  }
2241
- set isOpened(e) {
2242
- this.state.set("isOpened", e);
1986
+ /**
1987
+ * Current viewport width.
1988
+ */
1989
+ get width() {
1990
+ return this.state.get("width");
2243
1991
  }
2244
1992
  /**
2245
- * Returns true in case, QR scanner is currently opened.
1993
+ * A method that expands the Mini App to the maximum available height. To
1994
+ * find out if the Mini App is expanded to the maximum height, refer to the
1995
+ * value of the `isExpanded`.
1996
+ * @see isExpanded
2246
1997
  */
2247
- get isOpened() {
2248
- return this.state.get("isOpened");
1998
+ expand() {
1999
+ this.postEvent("web_app_expand"), this.state.set("isExpanded", !0);
2249
2000
  }
2250
2001
  /**
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.
2002
+ * Returns true in case current viewport height is stable and is not going to
2003
+ * change in the next moment.
2255
2004
  */
2256
- async open(e) {
2257
- if (this.isOpened)
2258
- throw new Error("QR scanner is already opened.");
2259
- this.isOpened = !0;
2260
- 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;
2270
- }
2005
+ get isStable() {
2006
+ return this.stableHeight === this.height;
2271
2007
  }
2272
2008
  }
2273
- class Ft {
2009
+ function S(r, e) {
2010
+ document.documentElement.style.setProperty(r, e);
2011
+ }
2012
+ function qt(r, e) {
2013
+ const t = () => {
2014
+ S("--tg-background-color", r.backgroundColor);
2015
+ }, s = () => {
2016
+ const {
2017
+ backgroundColor: n,
2018
+ secondaryBackgroundColor: i
2019
+ } = e;
2020
+ if (te(r.headerColor)) {
2021
+ S("--tg-header-color", r.headerColor);
2022
+ return;
2023
+ }
2024
+ if (r.headerColor === "bg_color" && n) {
2025
+ S("--tg-header-color", n);
2026
+ return;
2027
+ }
2028
+ r.headerColor === "secondary_bg_color" && i && S("--tg-header-color", i);
2029
+ };
2030
+ e.on("change", s), r.on("change:backgroundColor", t), r.on("change:headerColor", s), t(), s();
2031
+ }
2032
+ function At(r) {
2033
+ const e = () => {
2034
+ const t = r.getState();
2035
+ Object.entries(t).forEach(([s, n]) => {
2036
+ if (n) {
2037
+ const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
2038
+ S(`--tg-theme-${i}`, n);
2039
+ }
2040
+ });
2041
+ };
2042
+ r.on("change", e), e();
2043
+ }
2044
+ function ae(r) {
2045
+ 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`);
2046
+ r.on("change:height", e), r.on("change:width", t), r.on("change:stableHeight", s), e(), t(), s();
2047
+ }
2048
+ function Vt() {
2049
+ const r = document.createElement("style");
2050
+ r.id = "telegram-custom-styles", document.head.appendChild(r), y("set_custom_style", (e) => {
2051
+ r.innerHTML = e;
2052
+ });
2053
+ }
2054
+ class Rt {
2274
2055
  constructor(e, t, s = d) {
2056
+ o(this, "ee", new w());
2057
+ o(this, "state");
2275
2058
  /**
2276
- * Checks if specified method is supported by current component.
2059
+ * Adds event listener.
2060
+ * @param event - event name.
2061
+ * @param listener - event listener.
2277
2062
  */
2278
- o(this, "supports");
2063
+ o(this, "on", (e, t) => e === "click" ? y("back_button_pressed", t) : this.ee.on(e, t));
2279
2064
  /**
2280
- * Checks if specified method parameter is supported by current component.
2065
+ * Removes event listener.
2066
+ * @param event - event name.
2067
+ * @param listener - event listener.
2281
2068
  */
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"]
2069
+ o(this, "off", (e, t) => e === "click" ? $("back_button_pressed", t) : this.ee.off(e, t));
2070
+ /**
2071
+ * Checks if specified method is supported by current component.
2072
+ */
2073
+ o(this, "supports");
2074
+ this.postEvent = s, this.state = new b({ isVisible: e }, this.ee), this.supports = E(t, {
2075
+ show: "web_app_setup_back_button",
2076
+ hide: "web_app_setup_back_button"
2287
2077
  });
2288
2078
  }
2079
+ set isVisible(e) {
2080
+ this.state.set("isVisible", e), this.postEvent("web_app_setup_back_button", { is_visible: e });
2081
+ }
2289
2082
  /**
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
2083
+ * True if BackButton is currently visible.
2297
2084
  */
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
- });
2085
+ get isVisible() {
2086
+ return this.state.get("isVisible");
2308
2087
  }
2309
2088
  /**
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.
2089
+ * Hides the BackButton.
2314
2090
  */
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 });
2091
+ hide() {
2092
+ this.isVisible = !1;
2328
2093
  }
2329
2094
  /**
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
2095
+ * Shows the BackButton.
2334
2096
  */
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);
2097
+ show() {
2098
+ this.isVisible = !0;
2342
2099
  }
2343
2100
  }
2344
- function or(r = {}) {
2101
+ function Pe(r) {
2102
+ return `telegram-mini-apps-${r}`;
2103
+ }
2104
+ function B(r, e) {
2105
+ sessionStorage.setItem(Pe(r), JSON.stringify(e));
2106
+ }
2107
+ function D(r) {
2108
+ const e = sessionStorage.getItem(Pe(r));
2109
+ return e ? JSON.parse(e) : null;
2110
+ }
2111
+ function It(r, e, t) {
2112
+ const { isVisible: s = !1 } = r ? D("back-button") || {} : {}, n = new Rt(s, e, t);
2113
+ return n.on("change", () => {
2114
+ B("back-button", { isVisible: n.isVisible });
2115
+ }), n;
2116
+ }
2117
+ function Lt(r, e) {
2118
+ const { isConfirmationNeeded: t = !1 } = r ? D("closing-behavior") || {} : {}, s = new st(t, e);
2119
+ return s.on("change", () => B("closing-behavior", {
2120
+ isConfirmationNeeded: s.isConfirmationNeeded
2121
+ })), s;
2122
+ }
2123
+ function Tt(r, e, t, s) {
2124
+ const {
2125
+ backgroundColor: n = e,
2126
+ isEnabled: i = !1,
2127
+ isVisible: a = !1,
2128
+ isLoaderVisible: c = !1,
2129
+ textColor: u = t,
2130
+ text: p = ""
2131
+ } = r ? D("main-button") || {} : {}, g = new dt({
2132
+ backgroundColor: n,
2133
+ isEnabled: i,
2134
+ isLoaderVisible: c,
2135
+ isVisible: a,
2136
+ postEvent: s,
2137
+ text: p,
2138
+ textColor: u
2139
+ }), _ = () => B("main-button", {
2140
+ backgroundColor: g.backgroundColor,
2141
+ isEnabled: g.isEnabled,
2142
+ isLoaderVisible: g.isLoaderVisible,
2143
+ isVisible: g.isVisible,
2144
+ text: g.text,
2145
+ textColor: g.textColor
2146
+ });
2147
+ return g.on("change", _), g;
2148
+ }
2149
+ function $t(r, e, t, s, n, i) {
2150
+ const {
2151
+ backgroundColor: a = e,
2152
+ headerColor: c = "bg_color"
2153
+ } = r ? D("mini-app") || {} : {}, u = new wt({
2154
+ headerColor: c,
2155
+ backgroundColor: a,
2156
+ version: t,
2157
+ botInline: s,
2158
+ createRequestId: n,
2159
+ postEvent: i
2160
+ }), p = () => B("mini-app", {
2161
+ backgroundColor: u.backgroundColor,
2162
+ headerColor: u.headerColor
2163
+ });
2164
+ return u.on("change", p), u;
2165
+ }
2166
+ function Bt() {
2167
+ let r = 0;
2168
+ return () => (r += 1, r.toString());
2169
+ }
2170
+ function Dt(r, e, t) {
2171
+ const { isVisible: s = !1 } = r ? D("settings-button") || {} : {}, n = new yt(s, e, t);
2172
+ return n.on("change", () => {
2173
+ B("settings-button", { isVisible: n.isVisible });
2174
+ }), n;
2175
+ }
2176
+ function Wt(r) {
2177
+ const e = new Pt(r);
2178
+ return e.listen(), e;
2179
+ }
2180
+ function G(r) {
2181
+ const e = new xt(r);
2182
+ return e.on("change", () => B("viewport", {
2183
+ height: e.height,
2184
+ isExpanded: e.isExpanded,
2185
+ stableHeight: e.stableHeight,
2186
+ width: e.width
2187
+ })), e.listen(), e;
2188
+ }
2189
+ function Ot(r, e, t, s) {
2190
+ const n = r ? D("viewport") : null;
2191
+ if (n)
2192
+ return G({ ...n, postEvent: t });
2193
+ if (St(e))
2194
+ return G({
2195
+ height: window.innerHeight,
2196
+ isExpanded: !0,
2197
+ postEvent: t,
2198
+ stableHeight: window.innerHeight,
2199
+ width: window.innerWidth
2200
+ });
2201
+ if (s)
2202
+ return ve({
2203
+ postEvent: t,
2204
+ timeout: 5e3
2205
+ }).then(({ height: a, isStateStable: c, ...u }) => G({
2206
+ ...u,
2207
+ height: a,
2208
+ stableHeight: c ? a : 0
2209
+ }));
2210
+ const i = G({
2211
+ width: 0,
2212
+ height: 0,
2213
+ isExpanded: !1,
2214
+ postEvent: t,
2215
+ stableHeight: 0
2216
+ });
2217
+ return i.sync({ postEvent: t, timeout: 5e3 }).catch((a) => {
2218
+ console.error("Unable to actualize viewport state", a);
2219
+ }), i;
2220
+ }
2221
+ function Ht(r) {
2222
+ return typeof r == "object" ? r : r ? {
2223
+ themeParams: !0,
2224
+ viewport: !0,
2225
+ miniApp: !0
2226
+ } : {};
2227
+ }
2228
+ function ce(r, e, t, s) {
2229
+ const n = Ht(r);
2230
+ n.miniApp && qt(e, t), n.themeParams && At(t), n.viewport && (s instanceof Promise ? s.then(ae) : ae(s));
2231
+ }
2232
+ function Nt() {
2233
+ return re({
2234
+ botInline: {
2235
+ type: k().optional(),
2236
+ from: "tgWebAppBotInline"
2237
+ },
2238
+ initData: {
2239
+ type: me().optional(),
2240
+ from: "tgWebAppData"
2241
+ },
2242
+ initDataRaw: {
2243
+ type: h().optional(),
2244
+ from: "tgWebAppData"
2245
+ },
2246
+ platform: {
2247
+ type: h(),
2248
+ from: "tgWebAppPlatform"
2249
+ },
2250
+ showSettings: {
2251
+ type: k().optional(),
2252
+ from: "tgWebAppShowSettings"
2253
+ },
2254
+ startParam: {
2255
+ type: h().optional(),
2256
+ from: "tgWebAppStartParam"
2257
+ },
2258
+ themeParams: {
2259
+ type: Ee(),
2260
+ from: "tgWebAppThemeParams"
2261
+ },
2262
+ version: {
2263
+ type: h(),
2264
+ from: "tgWebAppVersion"
2265
+ }
2266
+ }, "LaunchParams");
2267
+ }
2268
+ function ke(r) {
2269
+ return Nt().parse(r);
2270
+ }
2271
+ function Se(r) {
2272
+ const e = r.includes("?") ? r.replace("#", "&").slice(r.indexOf("?") + 1) : r.slice(r.indexOf("#") + 1);
2273
+ return ke(e);
2274
+ }
2275
+ function Ut() {
2276
+ return Se(window.location.href);
2277
+ }
2278
+ function xe() {
2279
+ return performance.getEntriesByType("navigation")[0];
2280
+ }
2281
+ function Mt() {
2282
+ const r = xe();
2283
+ if (!r)
2284
+ throw new Error("Unable to get first navigation entry.");
2285
+ return Se(r.name);
2286
+ }
2287
+ function Gt(r) {
2288
+ const {
2289
+ initDataRaw: e,
2290
+ themeParams: t,
2291
+ platform: s,
2292
+ version: n,
2293
+ showSettings: i,
2294
+ startParam: a,
2295
+ botInline: c
2296
+ } = r, u = new URLSearchParams();
2297
+ 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();
2298
+ }
2299
+ const qe = "telegram-mini-apps-launch-params";
2300
+ function jt() {
2301
+ return ke(sessionStorage.getItem(qe) || "");
2302
+ }
2303
+ function Ft(r) {
2304
+ sessionStorage.setItem(qe, Gt(r));
2305
+ }
2306
+ function se() {
2307
+ const r = [];
2308
+ for (const e of [
2309
+ // Try to retrieve launch parameters from the current location. This method can return
2310
+ // nothing in case, location was changed and then page was reloaded.
2311
+ Ut,
2312
+ // Then, try using the lower level API - window.performance.
2313
+ Mt,
2314
+ // Finally, try to extract launch parameters from the session storage.
2315
+ jt
2316
+ ])
2317
+ try {
2318
+ const t = e();
2319
+ return Ft(t), t;
2320
+ } catch (t) {
2321
+ r.push(t);
2322
+ }
2323
+ throw q.error("Unable to extract launch parameters. Received errors:", r), new Error("Unable to retrieve launch parameters from any known source.");
2324
+ }
2325
+ function Ae() {
2326
+ var r;
2327
+ return ((r = xe()) == null ? void 0 : r.type) === "reload";
2328
+ }
2329
+ function sr(r = {}) {
2345
2330
  const {
2346
2331
  async: e = !1,
2347
2332
  complete: t = e,
@@ -2356,24 +2341,24 @@ function or(r = {}) {
2356
2341
  platform: u,
2357
2342
  themeParams: p,
2358
2343
  botInline: g = !1
2359
- } = te(), _ = le(), V = Lt(), l = gt(c);
2360
- pe() && (n && kt(), l("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => {
2344
+ } = se(), _ = Ae(), V = Bt(), l = De(c);
2345
+ le() && (n && Vt(), l("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => {
2361
2346
  l("iframe_will_reload"), window.location.reload();
2362
2347
  }));
2363
2348
  const C = {
2364
- backButton: St(_, c, l),
2365
- closingBehavior: xt(_, l),
2366
- cloudStorage: new Et(c, V, l),
2349
+ backButton: It(_, c, l),
2350
+ closingBehavior: Lt(_, l),
2351
+ cloudStorage: new at(c, V, l),
2367
2352
  createRequestId: V,
2368
- hapticFeedback: new Pt(c, l),
2369
- invoice: new Ut(c, l),
2370
- mainButton: At(
2353
+ hapticFeedback: new ct(c, l),
2354
+ invoice: new lt(c, l),
2355
+ mainButton: Tt(
2371
2356
  _,
2372
2357
  p.buttonColor || "#000000",
2373
2358
  p.buttonTextColor || "#ffffff",
2374
2359
  l
2375
2360
  ),
2376
- miniApp: It(
2361
+ miniApp: $t(
2377
2362
  _,
2378
2363
  p.backgroundColor || "#ffffff",
2379
2364
  c,
@@ -2381,14 +2366,14 @@ function or(r = {}) {
2381
2366
  V,
2382
2367
  l
2383
2368
  ),
2384
- popup: new Gt(c, l),
2369
+ popup: new bt(c, l),
2385
2370
  postEvent: l,
2386
- qrScanner: new jt(c, l),
2387
- settingsButton: $t(_, c, l),
2388
- themeParams: Bt(p),
2389
- utils: new Ft(c, V, l),
2371
+ qrScanner: new mt(c, l),
2372
+ settingsButton: Dt(_, c, l),
2373
+ themeParams: Wt(p),
2374
+ utils: new kt(c, V, l),
2390
2375
  ...i ? {
2391
- initData: new We(i),
2376
+ initData: new ut(i),
2392
2377
  initDataRaw: a
2393
2378
  } : {}
2394
2379
  }, x = Ot(_, u, l, t);
@@ -2409,10 +2394,20 @@ function or(r = {}) {
2409
2394
  throw i;
2410
2395
  }
2411
2396
  }
2412
- function O(r, e) {
2413
- return r.startsWith(e) ? r : `${e}${r}`;
2397
+ function nr() {
2398
+ return {
2399
+ launchParams: se(),
2400
+ isPageReload: Ae()
2401
+ };
2414
2402
  }
2415
- function ar(r) {
2403
+ function ir() {
2404
+ try {
2405
+ return se(), !0;
2406
+ } catch {
2407
+ return !1;
2408
+ }
2409
+ }
2410
+ function or(r) {
2416
2411
  const e = r.match(/#(.+)/);
2417
2412
  return e ? e[1] : null;
2418
2413
  }
@@ -2436,6 +2431,9 @@ async function zt() {
2436
2431
  for (; e; )
2437
2432
  e = await N(-1);
2438
2433
  }
2434
+ function O(r, e) {
2435
+ return r.startsWith(e) ? r : `${e}${r}`;
2436
+ }
2439
2437
  class Jt {
2440
2438
  constructor(e, t, {
2441
2439
  debug: s = !1,
@@ -2455,7 +2453,7 @@ class Jt {
2455
2453
  search: a ? O(a, "?") : "",
2456
2454
  hash: c ? O(c, "#") : ""
2457
2455
  };
2458
- }), this.logger = new ve(`[${n}]`, s);
2456
+ }), this.logger = new ue(`[${n}]`, s);
2459
2457
  }
2460
2458
  /**
2461
2459
  * Converts entry to the navigation entry.
@@ -2723,81 +2721,83 @@ class Ve extends Jt {
2723
2721
  this.attached && (this.logger.log("Detaching", this), this.attached = !1, window.removeEventListener("popstate", this.onPopState), $("back_button_pressed", this.back));
2724
2722
  }
2725
2723
  }
2724
+ function ar(r) {
2725
+ return r instanceof J;
2726
+ }
2726
2727
  export {
2727
- bt as BackButton,
2728
- yt as ClosingBehavior,
2729
- Et as CloudStorage,
2730
- Pt as HapticFeedback,
2728
+ st as ClosingBehavior,
2729
+ at as CloudStorage,
2730
+ ct as HapticFeedback,
2731
2731
  Ve as HashNavigator,
2732
- We as InitData,
2733
- Ut as Invoice,
2734
- qt as MainButton,
2735
- re as MethodUnsupportedError,
2736
- Rt as MiniApp,
2732
+ ut as InitData,
2733
+ lt as Invoice,
2734
+ dt as MainButton,
2735
+ Y as MethodUnsupportedError,
2736
+ wt as MiniApp,
2737
2737
  Jt as Navigator,
2738
- se as ParameterUnsupportedError,
2738
+ X as ParameterUnsupportedError,
2739
2739
  F as ParseError,
2740
2740
  j as ParseSchemaFieldError,
2741
- Gt as Popup,
2742
- jt as QRScanner,
2743
- Tt as SettingsButton,
2744
- Ue as ThemeParams,
2741
+ bt as Popup,
2742
+ mt as QRScanner,
2743
+ yt as SettingsButton,
2744
+ Pt as ThemeParams,
2745
2745
  J as TimeoutError,
2746
- Ft as Utils,
2747
- Wt as Viewport,
2748
- $e as array,
2749
- Ct as bindMiniAppCSSVars,
2750
- vt as bindThemeCSSVars,
2746
+ kt as Utils,
2747
+ xt as Viewport,
2748
+ ot as array,
2749
+ qt as bindMiniAppCSSVars,
2750
+ At as bindThemeCSSVars,
2751
2751
  ae as bindViewportCSSVars,
2752
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,
2753
+ ht as chatParser,
2754
+ rt as classNames,
2755
+ Be as compareVersions,
2756
+ De as createPostEvent,
2757
+ be as date,
2758
+ or as getHash,
2759
+ sr as init,
2760
+ me as initDataParser,
2761
2761
  H as invokeCustomMethod,
2762
- we as isColorDark,
2763
- pe as isIframe,
2764
- le as isPageReload,
2765
- X as isRGB,
2766
- Be as isRGBShort,
2762
+ _e as isColorDark,
2763
+ le as isIframe,
2764
+ Ae as isPageReload,
2765
+ te as isRGB,
2766
+ Qe as isRGBShort,
2767
2767
  R as isRecord,
2768
- Dt as isStableViewportPlatform,
2769
- tr as isTMA,
2770
- nr as isTimeoutError,
2768
+ St as isStableViewportPlatform,
2769
+ ir as isTMA,
2770
+ ar as isTimeoutError,
2771
2771
  f as json,
2772
- Me as launchParamsParser,
2773
- ir as mergeClassNames,
2772
+ Nt as launchParamsParser,
2773
+ er as mergeClassNames,
2774
2774
  A as number,
2775
2775
  $ as off,
2776
2776
  y as on,
2777
- rr as once,
2778
- Zt as parseInitData,
2779
- Ee as parseLaunchParams,
2780
- Xe as parseMessage,
2781
- ye as parseThemeParams,
2777
+ Yt as once,
2778
+ tr as parseInitData,
2779
+ ke as parseLaunchParams,
2780
+ Oe as parseMessage,
2781
+ Ce as parseThemeParams,
2782
2782
  d as postEvent,
2783
2783
  m as request,
2784
- Kt as requestThemeParams,
2785
- Ae as requestViewport,
2786
- er as retrieveLaunchData,
2787
- te as retrieveLaunchParams,
2788
- _e as rgb,
2789
- ee as searchParams,
2790
- ze as serializeLaunchParams,
2791
- Ne as serializeThemeParams,
2784
+ rr as requestThemeParams,
2785
+ ve as requestViewport,
2786
+ nr as retrieveLaunchData,
2787
+ se as retrieveLaunchParams,
2788
+ ge as rgb,
2789
+ re as searchParams,
2790
+ Gt as serializeLaunchParams,
2791
+ vt as serializeThemeParams,
2792
2792
  S as setCSSVar,
2793
- Yt as setDebug,
2794
- Xt as setTargetOrigin,
2793
+ Zt as setDebug,
2794
+ Kt as setTargetOrigin,
2795
2795
  h as string,
2796
- sr as subscribe,
2796
+ Xt as subscribe,
2797
2797
  I as supports,
2798
- me as themeParamsParser,
2799
- ge as toRGB,
2800
- dt as unsubscribe,
2801
- ne as userParser,
2802
- xe as withTimeout
2798
+ Ee as themeParamsParser,
2799
+ fe as toRGB,
2800
+ tt as unsubscribe,
2801
+ oe as userParser,
2802
+ we as withTimeout
2803
2803
  };