@tma.js/sdk 1.5.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/dist/dts/bridge/events/event-emitter/createMiniAppsEventEmitter.d.ts +15 -0
  2. package/dist/dts/bridge/events/event-emitter/singleton.d.ts +8 -0
  3. package/dist/dts/bridge/events/event-handlers/cleanupEventHandlers.d.ts +4 -0
  4. package/dist/dts/bridge/events/event-handlers/defineEventHandlers.d.ts +6 -0
  5. package/dist/dts/bridge/events/event-handlers/emitMiniAppsEvent.d.ts +9 -0
  6. package/dist/dts/bridge/events/{off.d.ts → listening/off.d.ts} +3 -2
  7. package/dist/dts/bridge/events/listening/on.d.ts +12 -0
  8. package/dist/dts/bridge/events/listening/subscribe.d.ts +9 -0
  9. package/dist/dts/bridge/events/listening/unsubscribe.d.ts +7 -0
  10. package/dist/dts/bridge/events/types.d.ts +294 -2
  11. package/dist/dts/bridge/methods/createPostEvent.d.ts +7 -4
  12. package/dist/dts/bridge/methods/postEvent.d.ts +24 -15
  13. package/dist/dts/bridge/methods/{custom-methods.d.ts → types/custom-methods.d.ts} +2 -1
  14. package/dist/dts/bridge/methods/types/index.d.ts +4 -0
  15. package/dist/dts/bridge/methods/{methods.d.ts → types/methods.d.ts} +70 -17
  16. package/dist/dts/{globals.d.ts → bridge/target-origin.d.ts} +0 -9
  17. package/dist/dts/bridge/{invokeCustomMethod.d.ts → utils/invokeCustomMethod.d.ts} +7 -2
  18. package/dist/dts/bridge/utils/request.d.ts +35 -0
  19. package/dist/dts/classes/State/State.d.ts +46 -0
  20. package/dist/dts/classes/State/types.d.ts +29 -0
  21. package/dist/dts/classes/WithStateUtils.d.ts +18 -0
  22. package/dist/dts/classes/WithSupports.d.ts +19 -0
  23. package/dist/dts/classes/WithSupportsAndStateUtils.d.ts +24 -0
  24. package/dist/dts/classes/WithSupportsAndTrackableState.d.ts +16 -0
  25. package/dist/dts/classes/WithTrackableState.d.ts +16 -0
  26. package/dist/dts/classnames/mergeClassNames.d.ts +2 -1
  27. package/dist/dts/colors/isRGB.d.ts +2 -1
  28. package/dist/dts/colors/isRGBShort.d.ts +2 -1
  29. package/dist/dts/colors/toRGB.d.ts +2 -1
  30. package/dist/dts/components/BackButton/BackButton.d.ts +41 -0
  31. package/dist/dts/components/BackButton/initBackButton.d.ts +7 -0
  32. package/dist/dts/components/BackButton/types.d.ts +25 -0
  33. package/dist/dts/components/BiometryManager/BiometryManager.d.ts +61 -0
  34. package/dist/dts/components/BiometryManager/formatEvent.d.ts +34 -0
  35. package/dist/dts/components/BiometryManager/initBiometryManager.d.ts +7 -0
  36. package/dist/dts/components/BiometryManager/requestBiometryInfo.d.ts +8 -0
  37. package/dist/dts/components/BiometryManager/types.d.ts +40 -0
  38. package/dist/dts/components/ClosingBehavior/ClosingBehavior.d.ts +26 -0
  39. package/dist/dts/components/ClosingBehavior/initClosingBehavior.d.ts +7 -0
  40. package/dist/dts/components/{closing-behavior → ClosingBehavior}/types.d.ts +14 -1
  41. package/dist/dts/components/{cloud-storage → CloudStorage}/CloudStorage.d.ts +11 -11
  42. package/dist/dts/components/CloudStorage/initCloudStorage.d.ts +7 -0
  43. package/dist/dts/components/{haptic-feedback → HapticFeedback}/HapticFeedback.d.ts +9 -13
  44. package/dist/dts/components/HapticFeedback/initHapticFeedback.d.ts +7 -0
  45. package/dist/dts/components/{init-data → InitData}/InitData.d.ts +4 -2
  46. package/dist/dts/components/InitData/initInitData.d.ts +7 -0
  47. package/dist/dts/components/{init-data → InitData}/parseInitData.d.ts +2 -1
  48. package/dist/dts/components/InitData/parsers/chat.d.ts +3 -0
  49. package/dist/dts/components/InitData/parsers/initData.d.ts +7 -0
  50. package/dist/dts/components/InitData/parsers/user.d.ts +3 -0
  51. package/dist/dts/components/{init-data → InitData}/types.d.ts +2 -3
  52. package/dist/dts/components/Invoice/Invoice.d.ts +31 -0
  53. package/dist/dts/components/Invoice/initInvoice.d.ts +7 -0
  54. package/dist/dts/components/{invoice → Invoice}/types.d.ts +14 -1
  55. package/dist/dts/components/MainButton/MainButton.d.ts +106 -0
  56. package/dist/dts/components/MainButton/initMainButton.d.ts +7 -0
  57. package/dist/dts/components/MainButton/types.d.ts +40 -0
  58. package/dist/dts/components/{mini-app → MiniApp}/MiniApp.d.ts +29 -43
  59. package/dist/dts/components/MiniApp/initMiniApp.d.ts +7 -0
  60. package/dist/dts/components/MiniApp/parsing/contact.d.ts +7 -0
  61. package/dist/dts/components/MiniApp/types.d.ts +53 -0
  62. package/dist/dts/components/Popup/Popup.d.ts +30 -0
  63. package/dist/dts/components/Popup/initPopup.d.ts +7 -0
  64. package/dist/dts/components/{popup → Popup}/preparePopupParams.d.ts +3 -2
  65. package/dist/dts/components/{popup → Popup}/types.d.ts +2 -1
  66. package/dist/dts/components/QRScanner/QRScanner.d.ts +28 -0
  67. package/dist/dts/components/QRScanner/initQRScanner.d.ts +7 -0
  68. package/dist/dts/components/{qr-scanner → QRScanner}/types.d.ts +14 -1
  69. package/dist/dts/components/SettingsButton/SettingsButton.d.ts +37 -0
  70. package/dist/dts/components/SettingsButton/initSettingsButton.d.ts +7 -0
  71. package/dist/dts/components/{settings-button → SettingsButton}/types.d.ts +18 -3
  72. package/dist/dts/components/ThemeParams/ThemeParams.d.ts +53 -0
  73. package/dist/dts/components/ThemeParams/initThemeParams.d.ts +7 -0
  74. package/dist/dts/components/ThemeParams/keys.d.ts +11 -0
  75. package/dist/dts/components/{theme-params → ThemeParams/parsing}/parseThemeParams.d.ts +2 -1
  76. package/dist/dts/components/{theme-params → ThemeParams/parsing}/serializeThemeParams.d.ts +2 -1
  77. package/dist/dts/components/ThemeParams/parsing/themeParams.d.ts +4 -0
  78. package/dist/dts/components/ThemeParams/requestThemeParams.d.ts +8 -0
  79. package/dist/dts/components/ThemeParams/types.d.ts +29 -0
  80. package/dist/dts/components/{utils → Utils}/Utils.d.ts +10 -12
  81. package/dist/dts/components/Utils/initUtils.d.ts +7 -0
  82. package/dist/dts/components/Viewport/Viewport.d.ts +77 -0
  83. package/dist/dts/components/Viewport/initViewport.d.ts +8 -0
  84. package/dist/dts/components/Viewport/initViewportFromRequest.d.ts +10 -0
  85. package/dist/dts/components/{viewport → Viewport}/requestViewport.d.ts +3 -2
  86. package/dist/dts/components/Viewport/types.d.ts +35 -0
  87. package/dist/dts/css-vars/bindMiniAppCSSVars.d.ts +29 -0
  88. package/dist/dts/css-vars/bindThemeParamsCSSVars.d.ts +29 -0
  89. package/dist/dts/css-vars/bindViewportCSSVars.d.ts +32 -0
  90. package/dist/dts/{css → css-vars}/setCSSVar.d.ts +1 -1
  91. package/dist/dts/debug/debug.d.ts +14 -0
  92. package/dist/dts/{bridge/env → env}/hasExternalNotify.d.ts +5 -7
  93. package/dist/dts/{bridge/env → env}/hasWebviewProxy.d.ts +5 -7
  94. package/dist/dts/env/initWeb.d.ts +11 -0
  95. package/dist/dts/env/isSSR.d.ts +4 -0
  96. package/dist/dts/{misc → env}/isTMA.d.ts +1 -1
  97. package/dist/dts/errors/SDKError.d.ts +9 -0
  98. package/dist/dts/errors/createError.d.ts +10 -0
  99. package/dist/dts/errors/errors.d.ts +53 -0
  100. package/dist/dts/errors/isSDKError.d.ts +7 -0
  101. package/dist/dts/errors/isSDKErrorOfType.d.ts +8 -0
  102. package/dist/dts/{event-emitter → events/event-emitter}/EventEmitter.d.ts +20 -30
  103. package/dist/dts/{event-emitter → events/event-emitter}/types.d.ts +10 -9
  104. package/dist/dts/events/onWindow.d.ts +10 -0
  105. package/dist/dts/events/types.d.ts +6 -0
  106. package/dist/dts/index.d.ts +113 -92
  107. package/dist/dts/index.low-level.d.ts +41 -0
  108. package/dist/dts/launch-params/parseLaunchParams.d.ts +2 -1
  109. package/dist/dts/launch-params/retrieveFromLocation.d.ts +2 -1
  110. package/dist/dts/launch-params/retrieveFromPerformance.d.ts +3 -3
  111. package/dist/dts/launch-params/{storage.d.ts → retrieveFromStorage.d.ts} +2 -6
  112. package/dist/dts/launch-params/retrieveFromUrl.d.ts +2 -1
  113. package/dist/dts/launch-params/retrieveLaunchParams.d.ts +2 -1
  114. package/dist/dts/launch-params/saveToStorage.d.ts +7 -0
  115. package/dist/dts/launch-params/serializeLaunchParams.d.ts +2 -1
  116. package/dist/dts/launch-params/types.d.ts +12 -13
  117. package/dist/dts/logger/Logger.d.ts +9 -18
  118. package/dist/dts/misc/createComponentInitFn/createComponentInitFn.d.ts +15 -0
  119. package/dist/dts/misc/createComponentInitFn/types.d.ts +47 -0
  120. package/dist/dts/misc/createSingleton.d.ts +15 -0
  121. package/dist/dts/misc/objectFromKeys.d.ts +6 -0
  122. package/dist/dts/navigation/BasicNavigator/BasicNavigator.d.ts +118 -0
  123. package/dist/dts/navigation/BasicNavigator/prepareItem.d.ts +8 -0
  124. package/dist/dts/navigation/BasicNavigator/types.d.ts +37 -0
  125. package/dist/dts/navigation/BrowserNavigator/BrowserNavigator.d.ts +198 -0
  126. package/dist/dts/navigation/BrowserNavigator/basicItemToBrowser.d.ts +7 -0
  127. package/dist/dts/navigation/BrowserNavigator/createBrowserNavigatorFromLocation.d.ts +4 -0
  128. package/dist/dts/navigation/BrowserNavigator/prepareItem.d.ts +25 -0
  129. package/dist/dts/navigation/BrowserNavigator/types.d.ts +63 -0
  130. package/dist/dts/navigation/createSafeURL.d.ts +7 -0
  131. package/dist/dts/navigation/getHash.d.ts +2 -1
  132. package/dist/dts/navigation/getPathname.d.ts +7 -0
  133. package/dist/dts/navigation/initNavigator.d.ts +9 -0
  134. package/dist/dts/navigation/urlToPath.d.ts +7 -0
  135. package/dist/dts/parsing/ArrayParser/ArrayParser.d.ts +17 -0
  136. package/dist/dts/parsing/ArrayParser/types.d.ts +12 -0
  137. package/dist/dts/parsing/ValueParser/ValueParser.d.ts +17 -0
  138. package/dist/dts/parsing/{ValueParser.d.ts → ValueParser/types.d.ts} +6 -14
  139. package/dist/dts/parsing/createTypeError.d.ts +6 -0
  140. package/dist/dts/parsing/createValueParserGenerator.d.ts +3 -2
  141. package/dist/dts/parsing/parseBySchema.d.ts +2 -1
  142. package/dist/dts/parsing/parsers/array.d.ts +3 -2
  143. package/dist/dts/parsing/parsers/boolean.d.ts +2 -1
  144. package/dist/dts/parsing/parsers/date.d.ts +2 -1
  145. package/dist/dts/parsing/parsers/json.d.ts +3 -2
  146. package/dist/dts/parsing/parsers/number.d.ts +2 -1
  147. package/dist/dts/parsing/parsers/rgb.d.ts +3 -2
  148. package/dist/dts/parsing/parsers/searchParams.d.ts +3 -2
  149. package/dist/dts/parsing/parsers/string.d.ts +2 -1
  150. package/dist/dts/{init/creators → request-id}/createRequestIdGenerator.d.ts +3 -2
  151. package/dist/dts/{types/request-id.d.ts → request-id/types.d.ts} +1 -1
  152. package/dist/dts/storage/storage.d.ts +42 -0
  153. package/dist/dts/supports/createSupportsFn.d.ts +12 -0
  154. package/dist/dts/supports/{createSupportsParamFunc.d.ts → createSupportsParamFn.d.ts} +5 -4
  155. package/dist/dts/supports/supports.d.ts +3 -2
  156. package/dist/dts/supports/types.d.ts +1 -1
  157. package/dist/dts/timeout/createTimeoutError.d.ts +7 -0
  158. package/dist/dts/timeout/sleep.d.ts +1 -1
  159. package/dist/dts/timeout/withTimeout.d.ts +1 -2
  160. package/dist/dts/types/index.d.ts +6 -0
  161. package/dist/dts/types/methods.d.ts +2 -1
  162. package/dist/dts/types/misc.d.ts +12 -0
  163. package/dist/dts/types/utils.d.ts +16 -0
  164. package/dist/dts/version/compareVersions.d.ts +2 -1
  165. package/dist/index.cjs +2 -1
  166. package/dist/index.cjs.map +1 -0
  167. package/dist/index.iife.js +2 -1
  168. package/dist/index.iife.js.map +1 -0
  169. package/dist/index.js +2998 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/index.low-level.iife.js +2 -0
  172. package/dist/index.low-level.iife.js.map +1 -0
  173. package/package.json +7 -9
  174. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +0 -8
  175. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +0 -8
  176. package/dist/dts/bridge/events/createEmitter.d.ts +0 -6
  177. package/dist/dts/bridge/events/events.d.ts +0 -140
  178. package/dist/dts/bridge/events/on.d.ts +0 -9
  179. package/dist/dts/bridge/events/onTelegramEvent.d.ts +0 -7
  180. package/dist/dts/bridge/events/once.d.ts +0 -8
  181. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +0 -13
  182. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +0 -16
  183. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +0 -12
  184. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +0 -8
  185. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +0 -8
  186. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +0 -7
  187. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +0 -42
  188. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +0 -19
  189. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +0 -8
  190. package/dist/dts/bridge/events/singletonEmitter.d.ts +0 -6
  191. package/dist/dts/bridge/events/subscribe.d.ts +0 -8
  192. package/dist/dts/bridge/events/unsubscribe.d.ts +0 -6
  193. package/dist/dts/bridge/request.d.ts +0 -54
  194. package/dist/dts/components/back-button/BackButton.d.ts +0 -47
  195. package/dist/dts/components/back-button/types.d.ts +0 -10
  196. package/dist/dts/components/closing-behavior/ClosingBehavior.d.ts +0 -39
  197. package/dist/dts/components/init-data/chatParser.d.ts +0 -6
  198. package/dist/dts/components/init-data/initDataParser.d.ts +0 -6
  199. package/dist/dts/components/init-data/userParser.d.ts +0 -6
  200. package/dist/dts/components/invoice/Invoice.d.ts +0 -47
  201. package/dist/dts/components/main-button/MainButton.d.ts +0 -104
  202. package/dist/dts/components/main-button/types.d.ts +0 -20
  203. package/dist/dts/components/mini-app/contactParser.d.ts +0 -2
  204. package/dist/dts/components/mini-app/types.d.ts +0 -32
  205. package/dist/dts/components/popup/Popup.d.ts +0 -48
  206. package/dist/dts/components/qr-scanner/QRScanner.d.ts +0 -44
  207. package/dist/dts/components/settings-button/SettingsButton.d.ts +0 -42
  208. package/dist/dts/components/theme-params/ThemeParams.d.ts +0 -66
  209. package/dist/dts/components/theme-params/keys.d.ts +0 -11
  210. package/dist/dts/components/theme-params/requestThemeParams.d.ts +0 -7
  211. package/dist/dts/components/theme-params/themeParamsParser.d.ts +0 -3
  212. package/dist/dts/components/theme-params/types.d.ts +0 -14
  213. package/dist/dts/components/viewport/Viewport.d.ts +0 -90
  214. package/dist/dts/components/viewport/isStableViewportPlatform.d.ts +0 -7
  215. package/dist/dts/components/viewport/types.d.ts +0 -18
  216. package/dist/dts/components/viewport/utils.d.ts +0 -5
  217. package/dist/dts/css/bindMiniAppCSSVars.d.ts +0 -16
  218. package/dist/dts/css/bindThemeCSSVars.d.ts +0 -12
  219. package/dist/dts/css/bindViewportCSSVars.d.ts +0 -20
  220. package/dist/dts/init/catchCustomStyles.d.ts +0 -4
  221. package/dist/dts/init/creators/createBackButton.d.ts +0 -10
  222. package/dist/dts/init/creators/createClosingBehavior.d.ts +0 -9
  223. package/dist/dts/init/creators/createMainButton.d.ts +0 -12
  224. package/dist/dts/init/creators/createMiniApp.d.ts +0 -16
  225. package/dist/dts/init/creators/createSettingsButton.d.ts +0 -10
  226. package/dist/dts/init/creators/createThemeParams.d.ts +0 -7
  227. package/dist/dts/init/creators/createViewport.d.ts +0 -11
  228. package/dist/dts/init/css/processCSSVarsOption.d.ts +0 -12
  229. package/dist/dts/init/init.d.ts +0 -9
  230. package/dist/dts/init/types.d.ts +0 -85
  231. package/dist/dts/launch-params/launchParamsParser.d.ts +0 -6
  232. package/dist/dts/launch-params/retrieveLaunchData.d.ts +0 -7
  233. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +0 -46
  234. package/dist/dts/navigation/HashNavigator/types.d.ts +0 -33
  235. package/dist/dts/navigation/Navigator/Navigator.d.ts +0 -104
  236. package/dist/dts/navigation/Navigator/types.d.ts +0 -44
  237. package/dist/dts/parsing/ArrayValueParser.d.ts +0 -18
  238. package/dist/dts/parsing/ParseError.d.ts +0 -22
  239. package/dist/dts/parsing/ParseSchemaFieldError.d.ts +0 -17
  240. package/dist/dts/parsing/unexpectedTypeError.d.ts +0 -4
  241. package/dist/dts/state/State.d.ts +0 -28
  242. package/dist/dts/state/types.d.ts +0 -27
  243. package/dist/dts/storage.d.ts +0 -50
  244. package/dist/dts/supports/createSupportsFunc.d.ts +0 -10
  245. package/dist/dts/timeout/TimeoutError.d.ts +0 -3
  246. package/dist/dts/timeout/isTimeoutError.d.ts +0 -6
  247. package/dist/index.mjs +0 -2813
  248. /package/dist/dts/bridge/methods/{haptic.d.ts → types/haptic.d.ts} +0 -0
  249. /package/dist/dts/bridge/methods/{popup.d.ts → types/popup.d.ts} +0 -0
  250. /package/dist/dts/bridge/{captureSameReq.d.ts → utils/captureSameReq.d.ts} +0 -0
  251. /package/dist/dts/{misc → env}/isIframe.d.ts +0 -0
  252. /package/dist/dts/navigation/{HashNavigator/drop.d.ts → drop.d.ts} +0 -0
  253. /package/dist/dts/{misc → navigation}/getFirstNavigationEntry.d.ts +0 -0
  254. /package/dist/dts/navigation/{HashNavigator/go.d.ts → go.d.ts} +0 -0
  255. /package/dist/dts/{misc → navigation}/isPageReload.d.ts +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,2998 @@
1
+ var Mt = Object.defineProperty;
2
+ var Lt = (e, t, s) => t in e ? Mt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var c = (e, t, s) => (Lt(e, typeof t != "symbol" ? t + "" : t, s), s);
4
+ function ct(e, t) {
5
+ let s;
6
+ const n = () => {
7
+ s !== void 0 && t && t(s), s = void 0;
8
+ };
9
+ return [() => s === void 0 ? s = e(n) : s, n];
10
+ }
11
+ function ht(e) {
12
+ const t = L(), { count: s } = t;
13
+ t.unsubscribe(e), s && !t.count && ae();
14
+ }
15
+ function Bt(e) {
16
+ return L().subscribe(e), () => ht(e);
17
+ }
18
+ class Ot {
19
+ constructor(t, s = {}) {
20
+ this.scope = t, this.options = s;
21
+ }
22
+ /**
23
+ * Prints message into a console in case, logger is currently enabled.
24
+ * @param level - log level.
25
+ * @param args - arguments.
26
+ */
27
+ print(t, ...s) {
28
+ const n = /* @__PURE__ */ new Date(), r = Intl.DateTimeFormat("en-GB", {
29
+ hour: "2-digit",
30
+ minute: "2-digit",
31
+ second: "2-digit",
32
+ fractionalSecondDigits: 3,
33
+ timeZone: "UTC"
34
+ }).format(n), { textColor: i, bgColor: o } = this.options, a = "font-weight: bold;padding: 0 5px;border-radius:5px";
35
+ console[t](
36
+ `%c${r}%c / %c${this.scope}`,
37
+ `${a};background-color: lightblue;color:black`,
38
+ "",
39
+ `${a};${i ? `color:${i};` : ""}${o ? `background-color:${o}` : ""}`,
40
+ ...s
41
+ );
42
+ }
43
+ /**
44
+ * Prints error message into a console.
45
+ * @param args
46
+ */
47
+ error(...t) {
48
+ this.print("error", ...t);
49
+ }
50
+ /**
51
+ * Prints log message into a console.
52
+ * @param args
53
+ */
54
+ log(...t) {
55
+ this.print("log", ...t);
56
+ }
57
+ }
58
+ const D = new Ot("SDK", {
59
+ bgColor: "forestgreen",
60
+ textColor: "white"
61
+ });
62
+ let j = !1;
63
+ const nt = ({ event: e, args: [t] }) => {
64
+ D.log("Event received:", t === void 0 ? { name: e } : { name: e, data: t });
65
+ };
66
+ function es(e) {
67
+ j !== e && (j = e, e ? Bt(nt) : ht(nt));
68
+ }
69
+ function Ut(...e) {
70
+ j && D.log(...e);
71
+ }
72
+ class V {
73
+ constructor() {
74
+ c(this, "listeners", /* @__PURE__ */ new Map());
75
+ c(this, "listenersCount", 0);
76
+ c(this, "subscribeListeners", []);
77
+ }
78
+ /**
79
+ * Removes all event listeners.
80
+ */
81
+ clear() {
82
+ this.listeners.clear(), this.subscribeListeners = [];
83
+ }
84
+ /**
85
+ * Returns count of bound listeners.
86
+ */
87
+ get count() {
88
+ return this.listenersCount + this.subscribeListeners.length;
89
+ }
90
+ emit(t, ...s) {
91
+ this.subscribeListeners.forEach((r) => r({
92
+ event: t,
93
+ args: s
94
+ })), (this.listeners.get(t) || []).forEach(([r, i]) => {
95
+ r(...s), i && this.off(t, r);
96
+ });
97
+ }
98
+ /**
99
+ * Adds new event listener.
100
+ * @param event - event name.
101
+ * @param listener - event listener.
102
+ * @param once - should listener be called only once.
103
+ * @returns Function to remove bound event listener.
104
+ */
105
+ on(t, s, n) {
106
+ let r = this.listeners.get(t);
107
+ return r || this.listeners.set(t, r = []), r.push([s, n]), this.listenersCount += 1, () => this.off(t, s);
108
+ }
109
+ /**
110
+ * Removes event listener. In case, specified listener was bound several times, it removes
111
+ * only a single one.
112
+ * @param event - event name.
113
+ * @param listener - event listener.
114
+ */
115
+ off(t, s) {
116
+ const n = this.listeners.get(t) || [];
117
+ for (let r = 0; r < n.length; r += 1)
118
+ if (s === n[r][0]) {
119
+ n.splice(r, 1), this.listenersCount -= 1;
120
+ return;
121
+ }
122
+ }
123
+ /**
124
+ * Adds a new event listener for all events.
125
+ * @param listener - event listener.
126
+ * @returns Function to remove event listener.
127
+ */
128
+ subscribe(t) {
129
+ return this.subscribeListeners.push(t), () => this.unsubscribe(t);
130
+ }
131
+ /**
132
+ * Removes global event listener. In case, specified listener was bound several times, it removes
133
+ * only a single one.
134
+ * @param listener - event listener.
135
+ */
136
+ unsubscribe(t) {
137
+ for (let s = 0; s < this.subscribeListeners.length; s += 1)
138
+ if (this.subscribeListeners[s] === t) {
139
+ this.subscribeListeners.splice(s, 1);
140
+ return;
141
+ }
142
+ }
143
+ }
144
+ function z(e, t, s) {
145
+ return window.addEventListener(e, t, s), () => window.removeEventListener(e, t, s);
146
+ }
147
+ class $ extends Error {
148
+ constructor(t, s, n) {
149
+ super(s, { cause: n }), this.type = t, Object.setPrototypeOf(this, $.prototype);
150
+ }
151
+ }
152
+ function u(e, t, s) {
153
+ return new $(e, t, s);
154
+ }
155
+ const Wt = "ERR_METHOD_UNSUPPORTED", Ht = "ERR_METHOD_PARAMETER_UNSUPPORTED", Gt = "ERR_UNKNOWN_ENV", jt = "ERR_INVOKE_CUSTOM_METHOD_RESPONSE", zt = "ERR_TIMED_OUT", Ft = "ERR_UNEXPECTED_TYPE", pt = "ERR_PARSE", Jt = "ERR_NAVIGATION_LIST_EMPTY", Qt = "ERR_NAVIGATION_CURSOR_INVALID", ss = "ERR_NAVIGATION_ITEM_INVALID", J = "ERR_SSR_INIT", Yt = "ERR_SSR_POST_EVENT", Zt = "ERR_INVALID_PATH_BASE";
156
+ function P() {
157
+ return u(Ft, "Value has unexpected type");
158
+ }
159
+ class M {
160
+ constructor(t, s, n) {
161
+ this.parser = t, this.isOptional = s, this.type = n;
162
+ }
163
+ /**
164
+ * Attempts to parse passed value
165
+ * @param value - value to parse.
166
+ * @throws {SDKError} ERR_PARSE
167
+ * @see ERR_PARSE
168
+ */
169
+ parse(t) {
170
+ if (!(this.isOptional && t === void 0))
171
+ try {
172
+ return this.parser(t);
173
+ } catch (s) {
174
+ throw u(
175
+ pt,
176
+ `Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
177
+ s
178
+ );
179
+ }
180
+ }
181
+ optional() {
182
+ return this.isOptional = !0, this;
183
+ }
184
+ }
185
+ function S(e, t) {
186
+ return () => new M(e, !1, t);
187
+ }
188
+ const w = S((e) => {
189
+ if (typeof e == "boolean")
190
+ return e;
191
+ const t = String(e);
192
+ if (t === "1" || t === "true")
193
+ return !0;
194
+ if (t === "0" || t === "false")
195
+ return !1;
196
+ throw P();
197
+ }, "boolean");
198
+ function ut(e, t) {
199
+ const s = {};
200
+ for (const n in e) {
201
+ const r = e[n];
202
+ if (!r)
203
+ continue;
204
+ let i, o;
205
+ if (typeof r == "function" || "parse" in r)
206
+ i = n, o = typeof r == "function" ? r : r.parse.bind(r);
207
+ else {
208
+ const { type: a } = r;
209
+ i = r.from || n, o = typeof a == "function" ? a : a.parse.bind(a);
210
+ }
211
+ try {
212
+ const a = o(t(i));
213
+ a !== void 0 && (s[n] = a);
214
+ } catch (a) {
215
+ throw u(pt, `Unable to parse field "${n}"`, a);
216
+ }
217
+ }
218
+ return s;
219
+ }
220
+ function Q(e) {
221
+ let t = e;
222
+ if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
223
+ throw P();
224
+ return t;
225
+ }
226
+ function _(e, t) {
227
+ return new M((s) => {
228
+ const n = Q(s);
229
+ return ut(e, (r) => n[r]);
230
+ }, !1, t);
231
+ }
232
+ const y = S((e) => {
233
+ if (typeof e == "number")
234
+ return e;
235
+ if (typeof e == "string") {
236
+ const t = Number(e);
237
+ if (!Number.isNaN(t))
238
+ return t;
239
+ }
240
+ throw P();
241
+ }, "number");
242
+ function Y(e) {
243
+ return /^#[\da-f]{6}$/i.test(e);
244
+ }
245
+ function Xt(e) {
246
+ return /^#[\da-f]{3}$/i.test(e);
247
+ }
248
+ function lt(e) {
249
+ const t = e.replace(/\s/g, "").toLowerCase();
250
+ if (Y(t))
251
+ return t;
252
+ if (Xt(t)) {
253
+ let n = "#";
254
+ for (let r = 0; r < 3; r += 1)
255
+ n += t[1 + r].repeat(2);
256
+ return n;
257
+ }
258
+ const s = t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
259
+ if (!s)
260
+ throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);
261
+ return s.slice(1).reduce((n, r) => {
262
+ const i = parseInt(r, 10).toString(16);
263
+ return n + (i.length === 1 ? "0" : "") + i;
264
+ }, "#");
265
+ }
266
+ const h = S((e) => {
267
+ if (typeof e == "string" || typeof e == "number")
268
+ return e.toString();
269
+ throw P();
270
+ }, "string"), dt = S((e) => lt(h().parse(e)), "rgb");
271
+ function Kt(e) {
272
+ return _({
273
+ eventType: h(),
274
+ eventData: (t) => t
275
+ }).parse(e);
276
+ }
277
+ function te() {
278
+ ["TelegramGameProxy_receiveEvent", "TelegramGameProxy", "Telegram"].forEach((e) => {
279
+ delete window[e];
280
+ });
281
+ }
282
+ function ee(e, t) {
283
+ window.dispatchEvent(new MessageEvent("message", {
284
+ data: JSON.stringify({ eventType: e, eventData: t }),
285
+ // We specify window.parent to imitate the case, the parent iframe sent us this event.
286
+ source: window.parent
287
+ }));
288
+ }
289
+ function se() {
290
+ [
291
+ ["TelegramGameProxy_receiveEvent"],
292
+ // Windows Phone.
293
+ ["TelegramGameProxy", "receiveEvent"],
294
+ // Desktop.
295
+ ["Telegram", "WebView", "receiveEvent"]
296
+ // Android and iOS.
297
+ ].forEach((e) => {
298
+ let t = window;
299
+ e.forEach((s, n, r) => {
300
+ if (n === r.length - 1) {
301
+ t[s] = ee;
302
+ return;
303
+ }
304
+ s in t || (t[s] = {}), t = t[s];
305
+ });
306
+ });
307
+ }
308
+ const ne = _({
309
+ button_id: (e) => e == null ? void 0 : h().parse(e)
310
+ }), re = {
311
+ clipboard_text_received: _({
312
+ req_id: h(),
313
+ data: (e) => e === null ? e : h().optional().parse(e)
314
+ }),
315
+ custom_method_invoked: _({
316
+ req_id: h(),
317
+ result: (e) => e,
318
+ error: h().optional()
319
+ }),
320
+ invoice_closed: _({
321
+ slug: h(),
322
+ status: h()
323
+ }),
324
+ phone_requested: _({
325
+ status: h()
326
+ }),
327
+ popup_closed: {
328
+ parse: (e) => ne.parse(e ?? {})
329
+ },
330
+ qr_text_received: _({
331
+ data: h().optional()
332
+ }),
333
+ theme_changed: _({
334
+ theme_params: (e) => {
335
+ const t = dt().optional();
336
+ return Object.entries(Q(e)).reduce((s, [n, r]) => (s[n] = t.parse(r), s), {});
337
+ }
338
+ }),
339
+ viewport_changed: _({
340
+ height: y(),
341
+ width: (e) => e == null ? window.innerWidth : y().parse(e),
342
+ is_state_stable: w(),
343
+ is_expanded: w()
344
+ }),
345
+ write_access_requested: _({
346
+ status: h()
347
+ })
348
+ };
349
+ function ie() {
350
+ const e = new V();
351
+ se();
352
+ let t = [
353
+ // Don't forget to remove created handlers.
354
+ te,
355
+ // Add "resize" event listener to make sure, we always have fresh viewport information.
356
+ // Desktop version of Telegram is sometimes not sending the viewport_changed
357
+ // event. For example, when the MainButton is shown. That's why we should
358
+ // add our own listener to make sure, viewport information is always fresh.
359
+ // Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/10
360
+ z("resize", () => {
361
+ e.emit("viewport_changed", {
362
+ width: window.innerWidth,
363
+ height: window.innerHeight,
364
+ is_state_stable: !0,
365
+ is_expanded: !0
366
+ });
367
+ }),
368
+ // Add listener, which handles events sent from the Telegram web application and also events
369
+ // generated by the local emitEvent function.
370
+ z("message", (s) => {
371
+ if (s.source !== window.parent)
372
+ return;
373
+ let n;
374
+ try {
375
+ n = Kt(s.data);
376
+ } catch {
377
+ return;
378
+ }
379
+ const { eventType: r, eventData: i } = n, o = re[r];
380
+ try {
381
+ const a = o ? o.parse(i) : i;
382
+ e.emit(...a ? [r, a] : [r]);
383
+ } catch (a) {
384
+ D.error(
385
+ `An error occurred processing the "${r}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,
386
+ n,
387
+ a
388
+ );
389
+ }
390
+ }),
391
+ // Clear emitter bound events.
392
+ () => e.clear()
393
+ ];
394
+ return [e, () => {
395
+ t.forEach((s) => s()), t = [];
396
+ }];
397
+ }
398
+ const [oe, ae] = ct(
399
+ (e) => {
400
+ const [t, s] = ie(), n = t.off.bind(t);
401
+ return t.off = (r, i) => {
402
+ const { count: o } = t;
403
+ n(r, i), o && !t.count && e();
404
+ }, [t, s];
405
+ },
406
+ ([, e]) => e()
407
+ );
408
+ function L() {
409
+ return oe()[0];
410
+ }
411
+ function B(e, t) {
412
+ L().off(e, t);
413
+ }
414
+ function b(e, t, s) {
415
+ return L().on(e, t, s);
416
+ }
417
+ function I(e) {
418
+ return typeof e == "object" && e !== null && !Array.isArray(e);
419
+ }
420
+ function ce(e, t) {
421
+ const s = e.split("."), n = t.split("."), r = Math.max(s.length, n.length);
422
+ for (let i = 0; i < r; i += 1) {
423
+ const o = parseInt(s[i] || "0", 10), a = parseInt(n[i] || "0", 10);
424
+ if (o !== a)
425
+ return o > a ? 1 : -1;
426
+ }
427
+ return 0;
428
+ }
429
+ function g(e, t) {
430
+ return ce(e, t) <= 0;
431
+ }
432
+ function v(e, t, s) {
433
+ if (typeof s == "string") {
434
+ if (e === "web_app_open_link" && t === "try_instant_view")
435
+ return g("6.4", s);
436
+ if (e === "web_app_set_header_color" && t === "color")
437
+ return g("6.9", s);
438
+ }
439
+ switch (e) {
440
+ case "web_app_open_tg_link":
441
+ case "web_app_open_invoice":
442
+ case "web_app_setup_back_button":
443
+ case "web_app_set_background_color":
444
+ case "web_app_set_header_color":
445
+ case "web_app_trigger_haptic_feedback":
446
+ return g("6.1", t);
447
+ case "web_app_open_popup":
448
+ return g("6.2", t);
449
+ case "web_app_close_scan_qr_popup":
450
+ case "web_app_open_scan_qr_popup":
451
+ case "web_app_read_text_from_clipboard":
452
+ return g("6.4", t);
453
+ case "web_app_switch_inline_query":
454
+ return g("6.7", t);
455
+ case "web_app_invoke_custom_method":
456
+ case "web_app_request_write_access":
457
+ case "web_app_request_phone":
458
+ return g("6.9", t);
459
+ case "web_app_setup_settings_button":
460
+ return g("6.10", t);
461
+ case "web_app_biometry_get_info":
462
+ case "web_app_biometry_open_settings":
463
+ case "web_app_biometry_request_access":
464
+ case "web_app_biometry_request_auth":
465
+ case "web_app_biometry_update_token":
466
+ return g("7.2", t);
467
+ default:
468
+ return [
469
+ "iframe_ready",
470
+ "iframe_will_reload",
471
+ "web_app_close",
472
+ "web_app_data_send",
473
+ "web_app_expand",
474
+ "web_app_open_link",
475
+ "web_app_ready",
476
+ "web_app_request_theme",
477
+ "web_app_request_viewport",
478
+ "web_app_setup_main_button",
479
+ "web_app_setup_closing_behavior"
480
+ ].includes(e);
481
+ }
482
+ }
483
+ function he(e) {
484
+ return "external" in e && I(e.external) && "notify" in e.external && typeof e.external.notify == "function";
485
+ }
486
+ function pe(e) {
487
+ return "TelegramWebviewProxy" in e && I(e.TelegramWebviewProxy) && "postEvent" in e.TelegramWebviewProxy && typeof e.TelegramWebviewProxy.postEvent == "function";
488
+ }
489
+ function ue() {
490
+ try {
491
+ return window.self !== window.top;
492
+ } catch {
493
+ return !0;
494
+ }
495
+ }
496
+ let _t = "https://web.telegram.org";
497
+ function ns(e) {
498
+ _t = e;
499
+ }
500
+ function le() {
501
+ return _t;
502
+ }
503
+ function T(e, t, s) {
504
+ let n = {}, r;
505
+ t === void 0 && s === void 0 ? n = {} : t !== void 0 && s !== void 0 ? (n = s, r = t) : t !== void 0 && ("targetOrigin" in t ? n = t : r = t);
506
+ const { targetOrigin: i = le() } = n;
507
+ if (Ut("Posting event:", r ? { event: e, data: r } : { event: e }), ue()) {
508
+ window.parent.postMessage(JSON.stringify({ eventType: e, eventData: r }), i);
509
+ return;
510
+ }
511
+ if (he(window)) {
512
+ window.external.notify(JSON.stringify({ eventType: e, eventData: r }));
513
+ return;
514
+ }
515
+ if (pe(window)) {
516
+ window.TelegramWebviewProxy.postEvent(e, JSON.stringify(r));
517
+ return;
518
+ }
519
+ throw u(
520
+ Gt,
521
+ "Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment."
522
+ );
523
+ }
524
+ function de(e) {
525
+ return (t, s) => {
526
+ if (!v(t, e))
527
+ throw u(Wt, `Method "${t}" is unsupported in Mini Apps version ${e}`);
528
+ if (I(s)) {
529
+ let n;
530
+ if (t === "web_app_open_link" && "try_instant_view" in s ? n = "try_instant_view" : t === "web_app_set_header_color" && "color" in s && (n = "color"), n && !v(t, n, e))
531
+ throw u(
532
+ Ht,
533
+ `Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`
534
+ );
535
+ }
536
+ return T(t, s);
537
+ };
538
+ }
539
+ function ft(e) {
540
+ return ({ req_id: t }) => t === e;
541
+ }
542
+ function gt(e) {
543
+ return u(zt, `Timeout reached: ${e}ms`);
544
+ }
545
+ function bt(e, t) {
546
+ return Promise.race([
547
+ typeof e == "function" ? e() : e,
548
+ new Promise((s, n) => {
549
+ setTimeout(() => {
550
+ n(gt(t));
551
+ }, t);
552
+ })
553
+ ]);
554
+ }
555
+ async function f(e) {
556
+ let t;
557
+ const s = new Promise((d) => {
558
+ t = d;
559
+ }), {
560
+ method: n,
561
+ event: r,
562
+ capture: i,
563
+ postEvent: o = T,
564
+ timeout: a
565
+ } = e, p = (Array.isArray(r) ? r : [r]).map(
566
+ (d) => b(d, (st) => (!i || i(st)) && t(st))
567
+ );
568
+ try {
569
+ return o(n, e.params), await (a ? bt(s, a) : s);
570
+ } finally {
571
+ p.forEach((d) => d());
572
+ }
573
+ }
574
+ async function R(e, t, s, n = {}) {
575
+ const {
576
+ result: r,
577
+ error: i
578
+ } = await f({
579
+ ...n,
580
+ method: "web_app_invoke_custom_method",
581
+ event: "custom_method_invoked",
582
+ params: {
583
+ method: e,
584
+ params: t,
585
+ req_id: s
586
+ },
587
+ capture: ft(s)
588
+ });
589
+ if (i)
590
+ throw u(jt, i);
591
+ return r;
592
+ }
593
+ function F(...e) {
594
+ return e.map((t) => {
595
+ if (typeof t == "string")
596
+ return t;
597
+ if (I(t))
598
+ return F(Object.entries(t).map((s) => s[1] && s[0]));
599
+ if (Array.isArray(t))
600
+ return F(...t);
601
+ }).filter(Boolean).join(" ");
602
+ }
603
+ function rs(...e) {
604
+ return e.reduce((t, s) => (I(s) && Object.entries(s).forEach(([n, r]) => {
605
+ const i = F(t[n], r);
606
+ i.length && (t[n] = i);
607
+ }), t), {});
608
+ }
609
+ function wt(e) {
610
+ const t = lt(e);
611
+ return Math.sqrt(
612
+ [0.299, 0.587, 0.114].reduce((s, n, r) => {
613
+ const i = parseInt(t.slice(1 + r * 2, 1 + (r + 1) * 2), 16);
614
+ return s + i * i * n;
615
+ }, 0)
616
+ ) < 120;
617
+ }
618
+ class _e {
619
+ constructor(t) {
620
+ c(this, "ee", new V());
621
+ /**
622
+ * Adds new event listener.
623
+ */
624
+ c(this, "on", this.ee.on.bind(this.ee));
625
+ /**
626
+ * Removes event listener.
627
+ */
628
+ c(this, "off", this.ee.off.bind(this.ee));
629
+ this.state = t;
630
+ }
631
+ /**
632
+ * Clones current state and returns its copy.
633
+ */
634
+ clone() {
635
+ return { ...this.state };
636
+ }
637
+ set(t, s) {
638
+ Object.entries(typeof t == "string" ? { [t]: s } : t).reduce((r, [i, o]) => this.state[i] === o || o === void 0 ? r : (this.state[i] = o, this.ee.emit(`change:${i}`, o), !0), !1) && this.ee.emit("change", this.state);
639
+ }
640
+ /**
641
+ * Returns value by specified key.
642
+ * @param key - state key.
643
+ */
644
+ get(t) {
645
+ return this.state[t];
646
+ }
647
+ }
648
+ class Z {
649
+ constructor(t) {
650
+ c(this, "state");
651
+ /**
652
+ * Gets the state value.
653
+ */
654
+ c(this, "get");
655
+ /**
656
+ * Sets the state value.
657
+ */
658
+ c(this, "set");
659
+ /**
660
+ * Clones the current state.
661
+ */
662
+ c(this, "clone");
663
+ this.state = new _e(t), this.set = this.state.set.bind(this.state), this.get = this.state.get.bind(this.state), this.clone = this.state.clone.bind(this.state);
664
+ }
665
+ }
666
+ function mt(e, t) {
667
+ return (s) => v(t[s], e);
668
+ }
669
+ class X extends Z {
670
+ constructor(s, n, r) {
671
+ super(s);
672
+ /**
673
+ * @returns True, if specified method is supported by the current component.
674
+ */
675
+ c(this, "supports");
676
+ this.supports = mt(n, r);
677
+ }
678
+ }
679
+ class fe extends X {
680
+ constructor(s, n, r) {
681
+ super({ isVisible: s }, n, {
682
+ show: "web_app_setup_back_button",
683
+ hide: "web_app_setup_back_button"
684
+ });
685
+ /**
686
+ * Adds a new event listener.
687
+ * @param event - event to listen.
688
+ * @param listener - listener to add.
689
+ */
690
+ c(this, "on", (s, n) => s === "click" ? b("back_button_pressed", n) : this.state.on(s, n));
691
+ /**
692
+ * Removes the event listener.
693
+ * @param event - event to listen.
694
+ * @param listener - listener to remove.
695
+ */
696
+ c(this, "off", (s, n) => s === "click" ? B("back_button_pressed", n) : this.state.off(s, n));
697
+ this.postEvent = r;
698
+ }
699
+ set isVisible(s) {
700
+ this.set("isVisible", s), this.postEvent("web_app_setup_back_button", { is_visible: s });
701
+ }
702
+ /**
703
+ * True if BackButton is currently visible.
704
+ */
705
+ get isVisible() {
706
+ return this.get("isVisible");
707
+ }
708
+ /**
709
+ * Hides the BackButton.
710
+ */
711
+ hide() {
712
+ this.isVisible = !1;
713
+ }
714
+ /**
715
+ * Shows the BackButton.
716
+ */
717
+ show() {
718
+ this.isVisible = !0;
719
+ }
720
+ }
721
+ function E() {
722
+ return typeof window > "u";
723
+ }
724
+ const yt = S((e) => e instanceof Date ? e : new Date(y().parse(e) * 1e3), "Date");
725
+ function K(e, t) {
726
+ return new M((s) => {
727
+ if (typeof s != "string" && !(s instanceof URLSearchParams))
728
+ throw P();
729
+ const n = typeof s == "string" ? new URLSearchParams(s) : s;
730
+ return ut(e, (r) => {
731
+ const i = n.get(r);
732
+ return i === null ? void 0 : i;
733
+ });
734
+ }, !1, t);
735
+ }
736
+ const ge = _({
737
+ id: y(),
738
+ type: h(),
739
+ title: h(),
740
+ photoUrl: {
741
+ type: h().optional(),
742
+ from: "photo_url"
743
+ },
744
+ username: h().optional()
745
+ }, "Chat").optional(), rt = _({
746
+ addedToAttachmentMenu: {
747
+ type: w().optional(),
748
+ from: "added_to_attachment_menu"
749
+ },
750
+ allowsWriteToPm: {
751
+ type: w().optional(),
752
+ from: "allows_write_to_pm"
753
+ },
754
+ firstName: {
755
+ type: h(),
756
+ from: "first_name"
757
+ },
758
+ id: y(),
759
+ isBot: {
760
+ type: w().optional(),
761
+ from: "is_bot"
762
+ },
763
+ isPremium: {
764
+ type: w().optional(),
765
+ from: "is_premium"
766
+ },
767
+ languageCode: {
768
+ type: h().optional(),
769
+ from: "language_code"
770
+ },
771
+ lastName: {
772
+ type: h().optional(),
773
+ from: "last_name"
774
+ },
775
+ photoUrl: {
776
+ type: h().optional(),
777
+ from: "photo_url"
778
+ },
779
+ username: h().optional()
780
+ }, "User").optional();
781
+ function vt() {
782
+ return K({
783
+ authDate: {
784
+ type: yt(),
785
+ from: "auth_date"
786
+ },
787
+ canSendAfter: {
788
+ type: y().optional(),
789
+ from: "can_send_after"
790
+ },
791
+ chat: ge,
792
+ chatInstance: {
793
+ type: h().optional(),
794
+ from: "chat_instance"
795
+ },
796
+ chatType: {
797
+ type: h().optional(),
798
+ from: "chat_type"
799
+ },
800
+ hash: h(),
801
+ queryId: {
802
+ type: h().optional(),
803
+ from: "query_id"
804
+ },
805
+ receiver: rt,
806
+ startParam: {
807
+ type: h().optional(),
808
+ from: "start_param"
809
+ },
810
+ user: rt
811
+ }, "InitData");
812
+ }
813
+ function be(e) {
814
+ return e.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
815
+ }
816
+ function we(e) {
817
+ return e.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
818
+ }
819
+ const Et = S(
820
+ (e) => {
821
+ const t = dt().optional();
822
+ return Object.entries(Q(e)).reduce((s, [n, r]) => (s[be(n)] = t.parse(r), s), {});
823
+ },
824
+ "ThemeParams"
825
+ );
826
+ function Pt(e) {
827
+ return K({
828
+ botInline: {
829
+ type: w().optional(),
830
+ from: "tgWebAppBotInline"
831
+ },
832
+ initData: {
833
+ type: vt().optional(),
834
+ from: "tgWebAppData"
835
+ },
836
+ initDataRaw: {
837
+ type: h().optional(),
838
+ from: "tgWebAppData"
839
+ },
840
+ platform: {
841
+ type: h(),
842
+ from: "tgWebAppPlatform"
843
+ },
844
+ showSettings: {
845
+ type: w().optional(),
846
+ from: "tgWebAppShowSettings"
847
+ },
848
+ startParam: {
849
+ type: h().optional(),
850
+ from: "tgWebAppStartParam"
851
+ },
852
+ themeParams: {
853
+ type: Et(),
854
+ from: "tgWebAppThemeParams"
855
+ },
856
+ version: {
857
+ type: h(),
858
+ from: "tgWebAppVersion"
859
+ }
860
+ }).parse(e);
861
+ }
862
+ function St(e) {
863
+ return Pt(
864
+ e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&")
865
+ );
866
+ }
867
+ function me() {
868
+ return St(window.location.href);
869
+ }
870
+ function xt() {
871
+ return performance.getEntriesByType("navigation")[0];
872
+ }
873
+ function ye() {
874
+ const e = xt();
875
+ if (!e)
876
+ throw new Error("Unable to get first navigation entry.");
877
+ return St(e.name);
878
+ }
879
+ function Rt(e) {
880
+ return `tma.js/${e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`)}`;
881
+ }
882
+ function Ct(e, t) {
883
+ sessionStorage.setItem(Rt(e), JSON.stringify(t));
884
+ }
885
+ function Tt(e) {
886
+ const t = sessionStorage.getItem(Rt(e));
887
+ try {
888
+ return t ? JSON.parse(t) : void 0;
889
+ } catch {
890
+ }
891
+ }
892
+ function ve() {
893
+ return Pt(Tt("launchParams") || "");
894
+ }
895
+ function Ee(e) {
896
+ return JSON.stringify(
897
+ Object.fromEntries(
898
+ Object.entries(e).map(([t, s]) => [we(t), s])
899
+ )
900
+ );
901
+ }
902
+ function Pe(e) {
903
+ const {
904
+ initDataRaw: t,
905
+ themeParams: s,
906
+ platform: n,
907
+ version: r,
908
+ showSettings: i,
909
+ startParam: o,
910
+ botInline: a
911
+ } = e, p = new URLSearchParams();
912
+ return p.set("tgWebAppPlatform", n), p.set("tgWebAppThemeParams", Ee(s)), p.set("tgWebAppVersion", r), t && p.set("tgWebAppData", t), o && p.set("tgWebAppStartParam", o), typeof i == "boolean" && p.set("tgWebAppShowSettings", i ? "1" : "0"), typeof a == "boolean" && p.set("tgWebAppBotInline", a ? "1" : "0"), p.toString();
913
+ }
914
+ function Se(e) {
915
+ Ct("launchParams", Pe(e));
916
+ }
917
+ function xe() {
918
+ for (const e of [
919
+ // Try to retrieve launch parameters from the current location. This method can return
920
+ // nothing in case, location was changed and then page was reloaded.
921
+ me,
922
+ // Then, try using the lower level API - window.performance.
923
+ ye,
924
+ // Finally, try to extract launch parameters from the session storage.
925
+ ve
926
+ ])
927
+ try {
928
+ const t = e();
929
+ return Se(t), t;
930
+ } catch {
931
+ }
932
+ throw new Error("Unable to retrieve launch parameters from any known source.");
933
+ }
934
+ function At() {
935
+ const e = xt();
936
+ return !!(e && e.type === "reload");
937
+ }
938
+ function Re() {
939
+ let e = 0;
940
+ return () => (e += 1).toString();
941
+ }
942
+ const [Ce] = ct(Re);
943
+ function l(e, t) {
944
+ return ({ ssr: s } = {}) => {
945
+ let n;
946
+ if (E()) {
947
+ if (!s)
948
+ throw u(
949
+ J,
950
+ "ssr.options must be specified to initialize component on the server side"
951
+ );
952
+ n = s;
953
+ } else
954
+ n = xe();
955
+ const r = {
956
+ ...n,
957
+ postEvent: "version" in n ? de(n.version) : () => {
958
+ throw u(
959
+ Yt,
960
+ "postEvent function is forbidden to be called on the server side."
961
+ );
962
+ },
963
+ createRequestId: Ce()
964
+ };
965
+ if (E() || typeof e == "function")
966
+ return typeof e == "function" ? e(r) : t(r);
967
+ const i = t({
968
+ ...r,
969
+ state: At() ? Tt(e) : void 0
970
+ }), o = (a) => (a.on("change", (p) => {
971
+ Ct(e, p);
972
+ }), a);
973
+ return i instanceof Promise ? i.then(o) : o(i);
974
+ };
975
+ }
976
+ const is = l("backButton", ({
977
+ postEvent: e,
978
+ version: t,
979
+ state: s = { isVisible: !1 }
980
+ }) => new fe(s.isVisible, t, e));
981
+ class q extends X {
982
+ constructor() {
983
+ super(...arguments);
984
+ /**
985
+ * Adds a new event listener.
986
+ */
987
+ c(this, "on", this.state.on.bind(this.state));
988
+ /**
989
+ * Removes the event listener.
990
+ */
991
+ c(this, "off", this.state.off.bind(this.state));
992
+ }
993
+ }
994
+ function It(e) {
995
+ const t = e.available ? e : {
996
+ available: !1,
997
+ device_id: "",
998
+ token_saved: !1,
999
+ access_requested: !1,
1000
+ access_granted: !1,
1001
+ type: ""
1002
+ };
1003
+ return {
1004
+ available: !0,
1005
+ type: t.type,
1006
+ deviceId: t.device_id,
1007
+ tokenSaved: t.token_saved,
1008
+ accessRequested: t.access_requested,
1009
+ accessGranted: t.access_granted
1010
+ };
1011
+ }
1012
+ class it extends q {
1013
+ constructor({ postEvent: s, version: n, ...r }) {
1014
+ super(r, n, {
1015
+ auth: "web_app_biometry_request_auth",
1016
+ openSettings: "web_app_biometry_open_settings",
1017
+ requestAccess: "web_app_biometry_request_access",
1018
+ updateToken: "web_app_biometry_update_token"
1019
+ });
1020
+ c(this, "postEvent");
1021
+ c(this, "authPromise");
1022
+ c(this, "accessPromise");
1023
+ this.postEvent = s;
1024
+ }
1025
+ /**
1026
+ * Shows whether biometry is available.
1027
+ */
1028
+ get available() {
1029
+ return this.get("available");
1030
+ }
1031
+ /**
1032
+ * Shows whether permission to use biometrics has been granted.
1033
+ */
1034
+ get accessGranted() {
1035
+ return this.get("accessGranted");
1036
+ }
1037
+ /**
1038
+ * Shows whether if permission to use biometrics has been requested.
1039
+ */
1040
+ get accessRequested() {
1041
+ return this.get("accessRequested");
1042
+ }
1043
+ /**
1044
+ * Authenticates the user using biometrics.
1045
+ * @param options - method options.
1046
+ * @since 7.2
1047
+ * @returns Token from the local secure storage, if authentication was successful.
1048
+ */
1049
+ async authenticate({
1050
+ reason: s,
1051
+ ...n
1052
+ }) {
1053
+ return this.authPromise || (this.authPromise = f({
1054
+ ...n,
1055
+ method: "web_app_biometry_request_auth",
1056
+ event: "biometry_auth_requested",
1057
+ postEvent: this.postEvent,
1058
+ params: {
1059
+ // TODO: Check if reason is empty works fine.
1060
+ reason: (s || "").trim()
1061
+ }
1062
+ }).then(({ token: r }) => r).finally(() => this.authPromise = void 0)), this.authPromise;
1063
+ }
1064
+ /**
1065
+ * A unique device identifier that can be used to match the token to the device.
1066
+ */
1067
+ get deviceId() {
1068
+ return this.get("deviceId");
1069
+ }
1070
+ /**
1071
+ * Opens the biometric access settings for bots. Useful when you need to request biometrics
1072
+ * access to users who haven't granted it yet.
1073
+ *
1074
+ * _Note that this method can be called only in response to user interaction with the Mini App
1075
+ * interface (e.g. a click inside the Mini App or on the main button)_.
1076
+ * @since 7.2
1077
+ */
1078
+ openSettings() {
1079
+ this.postEvent("web_app_biometry_open_settings");
1080
+ }
1081
+ /**
1082
+ * Requests permission to use biometrics.
1083
+ * @since 7.2
1084
+ * @returns Promise with true, if access was granted.
1085
+ */
1086
+ requestAccess({ reason: s, ...n } = {}) {
1087
+ return this.accessPromise || (this.accessPromise = f({
1088
+ ...n,
1089
+ postEvent: this.postEvent,
1090
+ method: "web_app_biometry_request_access",
1091
+ event: "biometry_info_received",
1092
+ params: { reason: s || "" }
1093
+ }).then((r) => {
1094
+ const i = It(r);
1095
+ return this.set(i), i.accessGranted;
1096
+ }).finally(() => this.accessPromise = void 0)), this.accessPromise;
1097
+ }
1098
+ /**
1099
+ * The type of biometrics currently available on the device.
1100
+ */
1101
+ get biometryType() {
1102
+ return this.get("biometryType");
1103
+ }
1104
+ /**
1105
+ * Shows whether token was saved previously in the local secure storage.
1106
+ */
1107
+ get tokenSaved() {
1108
+ return this.get("tokenSaved");
1109
+ }
1110
+ /**
1111
+ * Updates the biometric token in a secure storage on the device.
1112
+ * @returns Promise with `true`, if token was updated.
1113
+ */
1114
+ async updateToken({ token: s, ...n } = {}) {
1115
+ return ["removed", "updated"].includes(
1116
+ (await f({
1117
+ ...n,
1118
+ postEvent: this.postEvent,
1119
+ method: "web_app_biometry_update_token",
1120
+ event: "biometry_token_updated",
1121
+ params: { token: s || "" }
1122
+ })).status
1123
+ );
1124
+ }
1125
+ }
1126
+ async function Te(e) {
1127
+ return It(
1128
+ await f({
1129
+ ...e || {},
1130
+ method: "web_app_biometry_get_info",
1131
+ event: "biometry_info_received"
1132
+ })
1133
+ );
1134
+ }
1135
+ const os = l("biometryManager", async ({ postEvent: e, version: t, state: s }) => {
1136
+ if (s)
1137
+ return new it({ ...s, version: t, postEvent: e });
1138
+ if (E())
1139
+ throw u(
1140
+ J,
1141
+ "BiometryManager cannot be instantiated on the server side without passing the ssr.state object."
1142
+ );
1143
+ return new it({
1144
+ ...await Te({ timeout: 1e3 }),
1145
+ version: t,
1146
+ postEvent: e
1147
+ });
1148
+ });
1149
+ class tt extends Z {
1150
+ constructor() {
1151
+ super(...arguments);
1152
+ /**
1153
+ * Adds a new event listener.
1154
+ */
1155
+ c(this, "on", this.state.on.bind(this.state));
1156
+ /**
1157
+ * Removes the event listener.
1158
+ */
1159
+ c(this, "off", this.state.off.bind(this.state));
1160
+ }
1161
+ }
1162
+ class Ae extends tt {
1163
+ constructor(t, s) {
1164
+ super({ isConfirmationNeeded: t }), this.postEvent = s;
1165
+ }
1166
+ set isConfirmationNeeded(t) {
1167
+ this.set("isConfirmationNeeded", t), this.postEvent("web_app_setup_closing_behavior", { need_confirmation: t });
1168
+ }
1169
+ /**
1170
+ * True, if the confirmation dialog should be shown while the user is trying to close
1171
+ * the Mini App.
1172
+ */
1173
+ get isConfirmationNeeded() {
1174
+ return this.get("isConfirmationNeeded");
1175
+ }
1176
+ /**
1177
+ * Disables the confirmation dialog when closing the Mini App.
1178
+ */
1179
+ disableConfirmation() {
1180
+ this.isConfirmationNeeded = !1;
1181
+ }
1182
+ /**
1183
+ * Enables the confirmation dialog when closing the Mini App.
1184
+ */
1185
+ enableConfirmation() {
1186
+ this.isConfirmationNeeded = !0;
1187
+ }
1188
+ }
1189
+ const as = l("closingBehavior", ({
1190
+ postEvent: e,
1191
+ state: t = { isConfirmationNeeded: !1 }
1192
+ }) => new Ae(t.isConfirmationNeeded, e));
1193
+ class et {
1194
+ constructor(t, s) {
1195
+ /**
1196
+ * @returns True, if specified method is supported by the current component.
1197
+ */
1198
+ c(this, "supports");
1199
+ this.supports = mt(t, s);
1200
+ }
1201
+ }
1202
+ function Ie(e) {
1203
+ if (Array.isArray(e))
1204
+ return e;
1205
+ if (typeof e == "string")
1206
+ try {
1207
+ const t = JSON.parse(e);
1208
+ if (Array.isArray(t))
1209
+ return t;
1210
+ } catch {
1211
+ }
1212
+ throw P();
1213
+ }
1214
+ class qe extends M {
1215
+ constructor(s, n, r) {
1216
+ super(Ie, n, r);
1217
+ c(this, "itemParser");
1218
+ this.itemParser = typeof s == "function" ? s : s.parse.bind(s);
1219
+ }
1220
+ /**
1221
+ * Attempts to parse passed value
1222
+ * @param value - value to parse.
1223
+ * @throws {SDKError} ERR_PARSE
1224
+ * @see ERR_PARSE
1225
+ */
1226
+ parse(s) {
1227
+ const n = super.parse(s);
1228
+ return n === void 0 ? n : n.map(this.itemParser);
1229
+ }
1230
+ of(s) {
1231
+ return this.itemParser = typeof s == "function" ? s : s.parse.bind(s), this;
1232
+ }
1233
+ }
1234
+ function ke(e) {
1235
+ return new qe((t) => t, !1, e);
1236
+ }
1237
+ function ot(e, t) {
1238
+ return Object.fromEntries(e.map((s) => [s, t]));
1239
+ }
1240
+ class Ne extends et {
1241
+ constructor(t, s, n) {
1242
+ super(t, {
1243
+ delete: "web_app_invoke_custom_method",
1244
+ get: "web_app_invoke_custom_method",
1245
+ getKeys: "web_app_invoke_custom_method",
1246
+ set: "web_app_invoke_custom_method"
1247
+ }), this.createRequestId = s, this.postEvent = n;
1248
+ }
1249
+ /**
1250
+ * Deletes specified key or keys from the cloud storage.
1251
+ * @param keyOrKeys - key or keys to delete.
1252
+ * @param options - request execution options.
1253
+ */
1254
+ async delete(t, s = {}) {
1255
+ const n = Array.isArray(t) ? t : [t];
1256
+ n.length && await R(
1257
+ "deleteStorageValues",
1258
+ { keys: n },
1259
+ this.createRequestId(),
1260
+ { ...s, postEvent: this.postEvent }
1261
+ );
1262
+ }
1263
+ /**
1264
+ * Returns list of all keys presented in the cloud storage.
1265
+ * @param options - request execution options.
1266
+ */
1267
+ async getKeys(t = {}) {
1268
+ return ke().of(h()).parse(
1269
+ await R(
1270
+ "getStorageKeys",
1271
+ {},
1272
+ this.createRequestId(),
1273
+ { ...t, postEvent: this.postEvent }
1274
+ )
1275
+ );
1276
+ }
1277
+ async get(t, s = {}) {
1278
+ const n = Array.isArray(t) ? t : [t];
1279
+ if (!n.length)
1280
+ return ot(n, "");
1281
+ const r = await R(
1282
+ "getStorageValues",
1283
+ { keys: n },
1284
+ this.createRequestId(),
1285
+ { ...s, postEvent: this.postEvent }
1286
+ ), i = _(ot(n, h()), "CloudStorageData").parse(r);
1287
+ return Array.isArray(t) ? i : i[t];
1288
+ }
1289
+ /**
1290
+ * Saves specified value by key.
1291
+ * @param key - storage key.
1292
+ * @param value - storage value.
1293
+ * @param options - request execution options.
1294
+ */
1295
+ async set(t, s, n = {}) {
1296
+ await R(
1297
+ "saveStorageValue",
1298
+ { key: t, value: s },
1299
+ this.createRequestId(),
1300
+ { ...n, postEvent: this.postEvent }
1301
+ );
1302
+ }
1303
+ }
1304
+ const cs = l(
1305
+ ({ createRequestId: e, postEvent: t, version: s }) => new Ne(s, e, t)
1306
+ );
1307
+ class De extends et {
1308
+ constructor(t, s) {
1309
+ super(t, {
1310
+ impactOccurred: "web_app_trigger_haptic_feedback",
1311
+ notificationOccurred: "web_app_trigger_haptic_feedback",
1312
+ selectionChanged: "web_app_trigger_haptic_feedback"
1313
+ }), this.postEvent = s;
1314
+ }
1315
+ /**
1316
+ * A method tells that an impact occurred. The Telegram app may play the
1317
+ * appropriate haptics based on style value passed.
1318
+ * @param style - impact style.
1319
+ */
1320
+ impactOccurred(t) {
1321
+ this.postEvent("web_app_trigger_haptic_feedback", {
1322
+ type: "impact",
1323
+ impact_style: t
1324
+ });
1325
+ }
1326
+ /**
1327
+ * A method tells that a task or action has succeeded, failed, or produced
1328
+ * a warning. The Telegram app may play the appropriate haptics based on
1329
+ * type value passed.
1330
+ * @param type - notification type.
1331
+ */
1332
+ notificationOccurred(t) {
1333
+ this.postEvent("web_app_trigger_haptic_feedback", {
1334
+ type: "notification",
1335
+ notification_type: t
1336
+ });
1337
+ }
1338
+ /**
1339
+ * A method tells that the user has changed a selection. The Telegram app
1340
+ * may play the appropriate haptics.
1341
+ *
1342
+ * Do not use this feedback when the user makes or confirms a selection;
1343
+ * use it only when the selection changes.
1344
+ */
1345
+ selectionChanged() {
1346
+ this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1347
+ }
1348
+ }
1349
+ const hs = l(
1350
+ ({ version: e, postEvent: t }) => new De(e, t)
1351
+ );
1352
+ class Ve {
1353
+ constructor(t) {
1354
+ this.initData = t;
1355
+ }
1356
+ /**
1357
+ * @see InitDataParsed.authDate
1358
+ */
1359
+ get authDate() {
1360
+ return this.initData.authDate;
1361
+ }
1362
+ /**
1363
+ * @see InitDataParsed.canSendAfter
1364
+ */
1365
+ get canSendAfter() {
1366
+ return this.initData.canSendAfter;
1367
+ }
1368
+ /**
1369
+ * Date after which it is allowed to call
1370
+ * the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
1371
+ */
1372
+ get canSendAfterDate() {
1373
+ const { canSendAfter: t } = this;
1374
+ return t ? new Date(this.authDate.getTime() + t * 1e3) : void 0;
1375
+ }
1376
+ /**
1377
+ * @see InitDataParsed.chat
1378
+ */
1379
+ get chat() {
1380
+ return this.initData.chat;
1381
+ }
1382
+ /**
1383
+ * @see InitDataParsed.chatType
1384
+ */
1385
+ get chatType() {
1386
+ return this.initData.chatType;
1387
+ }
1388
+ /**
1389
+ * @see InitDataParsed.chatInstance
1390
+ */
1391
+ get chatInstance() {
1392
+ return this.initData.chatInstance;
1393
+ }
1394
+ /**
1395
+ * @see InitDataParsed.hash
1396
+ */
1397
+ get hash() {
1398
+ return this.initData.hash;
1399
+ }
1400
+ /**
1401
+ * @see InitDataParsed.queryId
1402
+ */
1403
+ get queryId() {
1404
+ return this.initData.queryId;
1405
+ }
1406
+ /**
1407
+ * @see InitDataParsed.receiver
1408
+ */
1409
+ get receiver() {
1410
+ return this.initData.receiver;
1411
+ }
1412
+ /**
1413
+ * @see InitDataParsed.startParam
1414
+ */
1415
+ get startParam() {
1416
+ return this.initData.startParam;
1417
+ }
1418
+ /**
1419
+ * @see InitDataParsed.user
1420
+ */
1421
+ get user() {
1422
+ return this.initData.user;
1423
+ }
1424
+ }
1425
+ const ps = l(
1426
+ ({ initData: e }) => e ? new Ve(e) : void 0
1427
+ );
1428
+ function us(e) {
1429
+ return vt().parse(e);
1430
+ }
1431
+ class $e extends q {
1432
+ constructor(t, s, n) {
1433
+ super({ isOpened: t }, s, { open: "web_app_open_invoice" }), this.postEvent = n;
1434
+ }
1435
+ set isOpened(t) {
1436
+ this.set("isOpened", t);
1437
+ }
1438
+ /**
1439
+ * True if invoice is currently opened.
1440
+ */
1441
+ get isOpened() {
1442
+ return this.get("isOpened");
1443
+ }
1444
+ async open(t, s) {
1445
+ if (this.isOpened)
1446
+ throw new Error("Invoice is already opened");
1447
+ let n;
1448
+ if (!s)
1449
+ n = t;
1450
+ else {
1451
+ const { hostname: r, pathname: i } = new URL(t, window.location.href);
1452
+ if (r !== "t.me")
1453
+ throw new Error(`Incorrect hostname: ${r}`);
1454
+ const o = i.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
1455
+ if (!o)
1456
+ throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
1457
+ [, , n] = o;
1458
+ }
1459
+ this.isOpened = !0;
1460
+ try {
1461
+ return (await f({
1462
+ method: "web_app_open_invoice",
1463
+ event: "invoice_closed",
1464
+ params: { slug: n },
1465
+ postEvent: this.postEvent,
1466
+ capture(i) {
1467
+ return n === i.slug;
1468
+ }
1469
+ })).status;
1470
+ } finally {
1471
+ this.isOpened = !1;
1472
+ }
1473
+ }
1474
+ }
1475
+ const ls = l(
1476
+ ({ version: e, postEvent: t }) => new $e(!1, e, t)
1477
+ );
1478
+ class Me extends Z {
1479
+ constructor({ postEvent: s, ...n }) {
1480
+ super(n);
1481
+ c(this, "postEvent");
1482
+ /**
1483
+ * Adds a new event listener.
1484
+ * @param event - event to listen.
1485
+ * @param listener - listener to add.
1486
+ */
1487
+ c(this, "on", (s, n) => s === "click" ? b("main_button_pressed", n) : this.state.on(s, n));
1488
+ /**
1489
+ * Removes the event listener.
1490
+ * @param event - event to listen.
1491
+ * @param listener - listener to remove.
1492
+ */
1493
+ c(this, "off", (s, n) => s === "click" ? B("main_button_pressed", n) : this.state.off(s, n));
1494
+ this.postEvent = s;
1495
+ }
1496
+ /**
1497
+ * Sends current local state to the Telegram application.
1498
+ */
1499
+ commit() {
1500
+ this.text !== "" && this.postEvent("web_app_setup_main_button", {
1501
+ is_visible: this.isVisible,
1502
+ is_active: this.isEnabled,
1503
+ is_progress_visible: this.isLoaderVisible,
1504
+ text: this.text,
1505
+ color: this.backgroundColor,
1506
+ text_color: this.textColor
1507
+ });
1508
+ }
1509
+ set isEnabled(s) {
1510
+ this.setParams({ isEnabled: s });
1511
+ }
1512
+ /**
1513
+ * True if the MainButton is enabled.
1514
+ */
1515
+ get isEnabled() {
1516
+ return this.get("isEnabled");
1517
+ }
1518
+ set isLoaderVisible(s) {
1519
+ this.setParams({ isLoaderVisible: s });
1520
+ }
1521
+ /**
1522
+ * True if the MainButton loader is visible.
1523
+ */
1524
+ get isLoaderVisible() {
1525
+ return this.get("isLoaderVisible");
1526
+ }
1527
+ set isVisible(s) {
1528
+ this.setParams({ isVisible: s });
1529
+ }
1530
+ /**
1531
+ * True if the MainButton is visible.
1532
+ */
1533
+ get isVisible() {
1534
+ return this.get("isVisible");
1535
+ }
1536
+ /**
1537
+ * The MainButton background color.
1538
+ */
1539
+ get backgroundColor() {
1540
+ return this.get("backgroundColor");
1541
+ }
1542
+ /**
1543
+ * The MainButton text.
1544
+ */
1545
+ get text() {
1546
+ return this.get("text");
1547
+ }
1548
+ /**
1549
+ * The MainButton text color.
1550
+ */
1551
+ get textColor() {
1552
+ return this.get("textColor");
1553
+ }
1554
+ /**
1555
+ * Disables the MainButton.
1556
+ * @see Does not work on Android: https://github.com/Telegram-Mini-Apps/issues/issues/1
1557
+ */
1558
+ disable() {
1559
+ return this.isEnabled = !1, this;
1560
+ }
1561
+ /**
1562
+ * Enables the MainButton.
1563
+ */
1564
+ enable() {
1565
+ return this.isEnabled = !0, this;
1566
+ }
1567
+ /**
1568
+ * Hides the MainButton.
1569
+ */
1570
+ hide() {
1571
+ return this.isVisible = !1, this;
1572
+ }
1573
+ /**
1574
+ * Hides the MainButton loading indicator.
1575
+ */
1576
+ hideLoader() {
1577
+ return this.isLoaderVisible = !1, this;
1578
+ }
1579
+ /**
1580
+ * Shows the MainButton.
1581
+ *
1582
+ * Note that opening the Mini App from the attachment menu hides the main button until the
1583
+ * user interacts with the Mini App interface.
1584
+ */
1585
+ show() {
1586
+ return this.isVisible = !0, this;
1587
+ }
1588
+ /**
1589
+ * Shows a loading indicator on the Main Button.
1590
+ */
1591
+ showLoader() {
1592
+ return this.isLoaderVisible = !0, this;
1593
+ }
1594
+ /**
1595
+ * Sets a new MainButton text. Minimal length for the text is 1 symbol, and maximum is 64 symbols.
1596
+ * @param text - a new text.
1597
+ */
1598
+ setText(s) {
1599
+ return this.setParams({ text: s });
1600
+ }
1601
+ /**
1602
+ * Sets a new Main Button text color.
1603
+ * @param textColor - new text color.
1604
+ */
1605
+ setTextColor(s) {
1606
+ return this.setParams({ textColor: s });
1607
+ }
1608
+ /**
1609
+ * Updates current Main Button color.
1610
+ * @param backgroundColor - color to set.
1611
+ */
1612
+ setBackgroundColor(s) {
1613
+ return this.setParams({ backgroundColor: s });
1614
+ }
1615
+ /**
1616
+ * Allows setting multiple Main Button parameters.
1617
+ * @param params - Main Button parameters.
1618
+ */
1619
+ setParams(s) {
1620
+ return this.set(s), this.commit(), this;
1621
+ }
1622
+ }
1623
+ const ds = l("mainButton", ({
1624
+ postEvent: e,
1625
+ themeParams: t,
1626
+ state: s = {
1627
+ isVisible: !1,
1628
+ isEnabled: !1,
1629
+ text: "",
1630
+ isLoaderVisible: !1,
1631
+ textColor: t.buttonTextColor || "#ffffff",
1632
+ backgroundColor: t.buttonColor || "#000000"
1633
+ }
1634
+ }) => new Me({ ...s, postEvent: e }));
1635
+ function Le() {
1636
+ return K({
1637
+ contact: _({
1638
+ userId: {
1639
+ type: y(),
1640
+ from: "user_id"
1641
+ },
1642
+ phoneNumber: {
1643
+ type: h(),
1644
+ from: "phone_number"
1645
+ },
1646
+ firstName: {
1647
+ type: h(),
1648
+ from: "first_name"
1649
+ },
1650
+ lastName: {
1651
+ type: h().optional(),
1652
+ from: "last_name"
1653
+ }
1654
+ }),
1655
+ authDate: {
1656
+ type: yt(),
1657
+ from: "auth_date"
1658
+ },
1659
+ hash: h()
1660
+ }, "RequestedContact");
1661
+ }
1662
+ function qt(e, t) {
1663
+ return (s) => {
1664
+ const [n, r] = t[s];
1665
+ return v(n, r, e);
1666
+ };
1667
+ }
1668
+ function Be(e) {
1669
+ return new Promise((t) => {
1670
+ setTimeout(t, e);
1671
+ });
1672
+ }
1673
+ class Oe extends q {
1674
+ constructor({ postEvent: s, createRequestId: n, version: r, botInline: i, ...o }) {
1675
+ super(o, r, {
1676
+ requestPhoneAccess: "web_app_request_phone",
1677
+ requestWriteAccess: "web_app_request_write_access",
1678
+ switchInlineQuery: "web_app_switch_inline_query",
1679
+ setHeaderColor: "web_app_set_header_color",
1680
+ setBackgroundColor: "web_app_set_background_color"
1681
+ });
1682
+ c(this, "botInline");
1683
+ c(this, "postEvent");
1684
+ c(this, "createRequestId");
1685
+ c(this, "requestPhoneAccessPromise");
1686
+ c(this, "requestWriteAccessPromise");
1687
+ /**
1688
+ * Checks if specified method parameter is supported by current component.
1689
+ */
1690
+ c(this, "supportsParam");
1691
+ this.createRequestId = n, this.postEvent = s, this.botInline = i;
1692
+ const a = this.supports.bind(this);
1693
+ this.supports = (p) => a(p) ? p !== "switchInlineQuery" || i : !1, this.supportsParam = qt(r, {
1694
+ "setHeaderColor.color": ["web_app_set_header_color", "color"]
1695
+ });
1696
+ }
1697
+ /**
1698
+ * Attempts to get requested contact.
1699
+ * @param timeout - request timeout.
1700
+ */
1701
+ async getRequestedContact({
1702
+ timeout: s = 1e4
1703
+ } = {}) {
1704
+ return Le().parse(
1705
+ await R(
1706
+ "getRequestedContact",
1707
+ {},
1708
+ this.createRequestId(),
1709
+ { postEvent: this.postEvent, timeout: s }
1710
+ )
1711
+ );
1712
+ }
1713
+ /**
1714
+ * The Mini App background color.
1715
+ * @example "#ffaabb"
1716
+ */
1717
+ get bgColor() {
1718
+ return this.get("bgColor");
1719
+ }
1720
+ /**
1721
+ * Closes the Mini App.
1722
+ */
1723
+ close() {
1724
+ this.postEvent("web_app_close");
1725
+ }
1726
+ /**
1727
+ * The Mini App header color.
1728
+ * @example "#ffaabb"
1729
+ * @example "bg_color"
1730
+ */
1731
+ get headerColor() {
1732
+ return this.get("headerColor");
1733
+ }
1734
+ /**
1735
+ * True if the Mini App is currently launched in bot inline mode.
1736
+ */
1737
+ get isBotInline() {
1738
+ return this.botInline;
1739
+ }
1740
+ /**
1741
+ * True if current Mini App background color is recognized as dark.
1742
+ */
1743
+ get isDark() {
1744
+ return wt(this.bgColor);
1745
+ }
1746
+ /**
1747
+ * Informs the Telegram app that the Mini App is ready to be displayed.
1748
+ *
1749
+ * It is recommended to call this method as early as possible, as soon as all essential
1750
+ * interface elements loaded. Once this method called, the loading placeholder is hidden
1751
+ * and the Mini App shown.
1752
+ *
1753
+ * If the method not called, the placeholder will be hidden only when the page fully loaded.
1754
+ */
1755
+ ready() {
1756
+ this.postEvent("web_app_ready");
1757
+ }
1758
+ /**
1759
+ * Requests current user contact information. In contrary to requestPhoneAccess, this method
1760
+ * returns promise with contact information that rejects in case, user denied access, or request
1761
+ * failed.
1762
+ * @param options - additional options.
1763
+ */
1764
+ async requestContact({ timeout: s = 5e3 } = {}) {
1765
+ try {
1766
+ return await this.getRequestedContact();
1767
+ } catch {
1768
+ }
1769
+ if (await this.requestPhoneAccess() !== "sent")
1770
+ throw new Error("Access denied.");
1771
+ const r = Date.now() + s;
1772
+ let i = 50;
1773
+ return bt(async () => {
1774
+ for (; Date.now() < r; ) {
1775
+ try {
1776
+ return await this.getRequestedContact();
1777
+ } catch {
1778
+ }
1779
+ await Be(i), i += 50;
1780
+ }
1781
+ throw gt(s);
1782
+ }, s);
1783
+ }
1784
+ /**
1785
+ * Requests current user phone access. Method returns promise, which resolves
1786
+ * status of the request. In case, user accepted the request, Mini App bot will receive
1787
+ * the according notification.
1788
+ *
1789
+ * To obtain the retrieved information instead, utilize the `requestContact` method.
1790
+ * @param options - additional options.
1791
+ * @see requestContact
1792
+ */
1793
+ async requestPhoneAccess(s = {}) {
1794
+ return this.requestPhoneAccessPromise || (this.requestPhoneAccessPromise = f({
1795
+ ...s,
1796
+ method: "web_app_request_phone",
1797
+ event: "phone_requested",
1798
+ postEvent: this.postEvent
1799
+ }).then(({ status: n }) => n).finally(() => this.requestPhoneAccessPromise = void 0)), this.requestPhoneAccessPromise;
1800
+ }
1801
+ /**
1802
+ * Requests write message access to current user.
1803
+ * @param options - additional options.
1804
+ */
1805
+ async requestWriteAccess(s = {}) {
1806
+ return this.requestWriteAccessPromise || (this.requestWriteAccessPromise = f({
1807
+ ...s,
1808
+ method: "web_app_request_write_access",
1809
+ event: "write_access_requested",
1810
+ postEvent: this.postEvent
1811
+ }).then(({ status: n }) => n).finally(() => this.requestWriteAccessPromise = void 0)), this.requestWriteAccessPromise;
1812
+ }
1813
+ /**
1814
+ * A method used to send data to the bot. When this method called, a service message sent to
1815
+ * the bot containing the data of the length up to 4096 bytes, and the Mini App closed. See the
1816
+ * field `web_app_data` in the class [Message](https://core.telegram.org/bots/api#message).
1817
+ *
1818
+ * This method is only available for Mini Apps launched via a Keyboard button.
1819
+ * @param data - data to send to bot.
1820
+ * @throws {Error} data has incorrect size.
1821
+ */
1822
+ sendData(s) {
1823
+ const { size: n } = new Blob([s]);
1824
+ if (!n || n > 4096)
1825
+ throw new Error(`Passed data has incorrect size: ${n}`);
1826
+ this.postEvent("web_app_data_send", { data: s });
1827
+ }
1828
+ /**
1829
+ * Updates current Mini App header color.
1830
+ *
1831
+ * @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
1832
+ * @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
1833
+ * @param color - color key or RGB color.
1834
+ */
1835
+ setHeaderColor(s) {
1836
+ this.postEvent("web_app_set_header_color", Y(s) ? { color: s } : { color_key: s }), this.set("headerColor", s);
1837
+ }
1838
+ /**
1839
+ * Updates current Mini App background color.
1840
+ *
1841
+ * @see No effect on desktop: https://github.com/Telegram-Mini-Apps/tma.js/issues/9
1842
+ * @see Works incorrectly in Android: https://github.com/Telegram-Mini-Apps/tma.js/issues/8
1843
+ * @param color - RGB color.
1844
+ */
1845
+ setBgColor(s) {
1846
+ this.postEvent("web_app_set_background_color", { color: s }), this.set("bgColor", s);
1847
+ }
1848
+ /**
1849
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
1850
+ * Query may be empty, in which case only the bot's username will be inserted. The client prompts
1851
+ * the user to choose a specific chat, then opens that chat and inserts the bot's username and
1852
+ * the specified inline query in the input field.
1853
+ * @param text - text which should be inserted in the input after the current bot name. Max
1854
+ * length is 256 symbols.
1855
+ * @param chatTypes - List of chat types which could be chosen to send the message. Could be
1856
+ * empty list.
1857
+ */
1858
+ switchInlineQuery(s, n = []) {
1859
+ if (!this.supports("switchInlineQuery") && !this.isBotInline)
1860
+ throw new Error("Method is unsupported because Mini App should be launched in inline mode.");
1861
+ this.postEvent("web_app_switch_inline_query", { query: s, chat_types: n });
1862
+ }
1863
+ }
1864
+ const _s = l("miniApp", ({
1865
+ themeParams: e,
1866
+ botInline: t = !1,
1867
+ state: s = {
1868
+ bgColor: e.bgColor || "#ffffff",
1869
+ headerColor: e.headerBgColor || "#000000"
1870
+ },
1871
+ ...n
1872
+ }) => new Oe({ ...n, ...s, botInline: t }));
1873
+ function Ue(e) {
1874
+ const t = e.message.trim(), s = (e.title || "").trim(), n = e.buttons || [];
1875
+ let r;
1876
+ if (s.length > 64)
1877
+ throw new Error(`Title has incorrect size: ${s.length}`);
1878
+ if (!t.length || t.length > 256)
1879
+ throw new Error(`Message has incorrect size: ${t.length}`);
1880
+ if (n.length > 3)
1881
+ throw new Error(`Buttons have incorrect size: ${n.length}`);
1882
+ return n.length ? r = n.map((i) => {
1883
+ const { id: o = "" } = i;
1884
+ if (o.length > 64)
1885
+ throw new Error(`Button ID has incorrect size: ${o}`);
1886
+ if (!i.type || i.type === "default" || i.type === "destructive") {
1887
+ const a = i.text.trim();
1888
+ if (!a.length || a.length > 64) {
1889
+ const p = i.type || "default";
1890
+ throw new Error(`Button text with type "${p}" has incorrect size: ${i.text.length}`);
1891
+ }
1892
+ return { ...i, text: a, id: o };
1893
+ }
1894
+ return { ...i, id: o };
1895
+ }) : r = [{ type: "close", id: "" }], { title: s, message: t, buttons: r };
1896
+ }
1897
+ class We extends q {
1898
+ constructor(t, s, n) {
1899
+ super({ isOpened: t }, s, { open: "web_app_open_popup" }), this.postEvent = n;
1900
+ }
1901
+ set isOpened(t) {
1902
+ this.set("isOpened", t);
1903
+ }
1904
+ /**
1905
+ * True if the Popup is opened.
1906
+ */
1907
+ get isOpened() {
1908
+ return this.get("isOpened");
1909
+ }
1910
+ /**
1911
+ * A method that shows a native popup described by the `params` argument.
1912
+ * Promise will be resolved when popup is closed. Resolved value will have
1913
+ * an identifier of pressed button.
1914
+ *
1915
+ * In case, user clicked outside the popup or clicked top right popup close
1916
+ * button, null will be returned.
1917
+ *
1918
+ * @param options - popup parameters.
1919
+ * @throws {Error} Popup is already opened.
1920
+ */
1921
+ async open(t) {
1922
+ if (this.isOpened)
1923
+ throw new Error("Popup is already opened.");
1924
+ this.isOpened = !0;
1925
+ try {
1926
+ const { button_id: s = null } = await f({
1927
+ event: "popup_closed",
1928
+ method: "web_app_open_popup",
1929
+ postEvent: this.postEvent,
1930
+ params: Ue(t)
1931
+ });
1932
+ return s;
1933
+ } finally {
1934
+ this.isOpened = !1;
1935
+ }
1936
+ }
1937
+ }
1938
+ const fs = l(
1939
+ ({ postEvent: e, version: t }) => new We(!1, t, e)
1940
+ );
1941
+ class He extends q {
1942
+ constructor(t, s, n) {
1943
+ super({ isOpened: t }, s, {
1944
+ close: "web_app_close_scan_qr_popup",
1945
+ open: "web_app_open_scan_qr_popup"
1946
+ }), this.postEvent = n;
1947
+ }
1948
+ /**
1949
+ * Closes scanner.
1950
+ */
1951
+ close() {
1952
+ this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
1953
+ }
1954
+ set isOpened(t) {
1955
+ this.set("isOpened", t);
1956
+ }
1957
+ /**
1958
+ * Returns true in case, QR scanner is currently opened.
1959
+ */
1960
+ get isOpened() {
1961
+ return this.get("isOpened");
1962
+ }
1963
+ /**
1964
+ * Opens scanner with specified title shown to user. Method returns promise
1965
+ * with scanned QR content in case, it was scanned. It will contain null in
1966
+ * case, scanner was closed.
1967
+ * @param text - title to display.
1968
+ */
1969
+ async open(t) {
1970
+ if (this.isOpened)
1971
+ throw new Error("QR scanner is already opened.");
1972
+ this.isOpened = !0;
1973
+ try {
1974
+ return (await f({
1975
+ method: "web_app_open_scan_qr_popup",
1976
+ event: ["qr_text_received", "scan_qr_popup_closed"],
1977
+ postEvent: this.postEvent,
1978
+ params: { text: t }
1979
+ }) || {}).data || null;
1980
+ } finally {
1981
+ this.isOpened = !1;
1982
+ }
1983
+ }
1984
+ }
1985
+ const gs = l(
1986
+ ({ version: e, postEvent: t }) => new He(!1, e, t)
1987
+ );
1988
+ class Ge extends X {
1989
+ constructor(s, n, r) {
1990
+ super({ isVisible: s }, n, {
1991
+ show: "web_app_setup_settings_button",
1992
+ hide: "web_app_setup_settings_button"
1993
+ });
1994
+ /**
1995
+ * Adds a new event listener.
1996
+ * @param event - event to listen.
1997
+ * @param listener - listener to add.
1998
+ */
1999
+ c(this, "on", (s, n) => s === "click" ? b("settings_button_pressed", n) : this.state.on(s, n));
2000
+ /**
2001
+ * Removes the event listener.
2002
+ * @param event - event to listen.
2003
+ * @param listener - listener to remove.
2004
+ */
2005
+ c(this, "off", (s, n) => s === "click" ? B("settings_button_pressed", n) : this.state.off(s, n));
2006
+ this.postEvent = r;
2007
+ }
2008
+ set isVisible(s) {
2009
+ this.set("isVisible", s), this.postEvent("web_app_setup_settings_button", { is_visible: s });
2010
+ }
2011
+ /**
2012
+ * True if the SettingsButton is visible.
2013
+ */
2014
+ get isVisible() {
2015
+ return this.get("isVisible");
2016
+ }
2017
+ /**
2018
+ * Hides the SettingsButton.
2019
+ */
2020
+ hide() {
2021
+ this.isVisible = !1;
2022
+ }
2023
+ /**
2024
+ * Shows the SettingsButton.
2025
+ */
2026
+ show() {
2027
+ this.isVisible = !0;
2028
+ }
2029
+ }
2030
+ const bs = l("settingsButton", ({
2031
+ version: e,
2032
+ postEvent: t,
2033
+ state: s = { isVisible: !1 }
2034
+ }) => new Ge(s.isVisible, e, t));
2035
+ function kt(e) {
2036
+ return Et().parse(e);
2037
+ }
2038
+ class je extends tt {
2039
+ /**
2040
+ * @since v6.10
2041
+ */
2042
+ get accentTextColor() {
2043
+ return this.get("accentTextColor");
2044
+ }
2045
+ get bgColor() {
2046
+ return this.get("bgColor");
2047
+ }
2048
+ get buttonColor() {
2049
+ return this.get("buttonColor");
2050
+ }
2051
+ get buttonTextColor() {
2052
+ return this.get("buttonTextColor");
2053
+ }
2054
+ get destructiveTextColor() {
2055
+ return this.get("destructiveTextColor");
2056
+ }
2057
+ /**
2058
+ * Returns the copy of the internal state of the current component instance.
2059
+ */
2060
+ getState() {
2061
+ return this.clone();
2062
+ }
2063
+ /**
2064
+ * @since v6.10
2065
+ */
2066
+ get headerBgColor() {
2067
+ return this.get("headerBgColor");
2068
+ }
2069
+ get hintColor() {
2070
+ return this.get("hintColor");
2071
+ }
2072
+ /**
2073
+ * @returns True in case, current color scheme is recognized as dark. This
2074
+ * value is calculated according to theme bg color.
2075
+ */
2076
+ get isDark() {
2077
+ return !this.bgColor || wt(this.bgColor);
2078
+ }
2079
+ get linkColor() {
2080
+ return this.get("linkColor");
2081
+ }
2082
+ get secondaryBgColor() {
2083
+ return this.get("secondaryBgColor");
2084
+ }
2085
+ /**
2086
+ * @since v6.10
2087
+ */
2088
+ get sectionBgColor() {
2089
+ return this.get("sectionBgColor");
2090
+ }
2091
+ /**
2092
+ * @since v6.10
2093
+ */
2094
+ get sectionHeaderTextColor() {
2095
+ return this.get("sectionHeaderTextColor");
2096
+ }
2097
+ /**
2098
+ * Starts listening to the external theme changes and applies them.
2099
+ * @returns Function to stop listening.
2100
+ */
2101
+ listen() {
2102
+ return b("theme_changed", (t) => {
2103
+ this.set(kt(t.theme_params));
2104
+ });
2105
+ }
2106
+ /**
2107
+ * @since v6.10
2108
+ */
2109
+ get subtitleTextColor() {
2110
+ return this.get("subtitleTextColor");
2111
+ }
2112
+ get textColor() {
2113
+ return this.get("textColor");
2114
+ }
2115
+ }
2116
+ const ws = l("themeParams", ({ themeParams: e, state: t = e }) => {
2117
+ const s = new je(t);
2118
+ return E() || s.listen(), s;
2119
+ });
2120
+ function ms(e = {}) {
2121
+ return f({
2122
+ ...e,
2123
+ method: "web_app_request_theme",
2124
+ event: "theme_changed"
2125
+ }).then(kt);
2126
+ }
2127
+ class ze extends et {
2128
+ constructor(s, n, r) {
2129
+ super(s, { readTextFromClipboard: "web_app_read_text_from_clipboard" });
2130
+ /**
2131
+ * Checks if specified method parameter is supported by current component.
2132
+ */
2133
+ c(this, "supportsParam");
2134
+ this.version = s, this.createRequestId = n, this.postEvent = r, this.supportsParam = qt(s, {
2135
+ "openLink.tryInstantView": ["web_app_open_link", "try_instant_view"]
2136
+ });
2137
+ }
2138
+ /**
2139
+ * Opens a link in an external browser. The Mini App will not be closed.
2140
+ *
2141
+ * Note that this method can be called only in response to the user
2142
+ * interaction with the Mini App interface (e.g. click inside the Mini App
2143
+ * or on the main button).
2144
+ * @param url - URL to be opened.
2145
+ * @param tryInstantView
2146
+ */
2147
+ openLink(s, n) {
2148
+ const r = new URL(s, window.location.href).toString();
2149
+ if (!v("web_app_open_link", this.version)) {
2150
+ window.open(r, "_blank");
2151
+ return;
2152
+ }
2153
+ this.postEvent("web_app_open_link", {
2154
+ url: r,
2155
+ ...typeof n == "boolean" ? { try_instant_view: n } : {}
2156
+ });
2157
+ }
2158
+ /**
2159
+ * Opens a Telegram link inside Telegram app. The Mini App will be closed. It expects passing
2160
+ * link in full format, with hostname "t.me".
2161
+ * @param url - URL to be opened.
2162
+ * @throws {Error} URL has not allowed hostname.
2163
+ */
2164
+ openTelegramLink(s) {
2165
+ const { hostname: n, pathname: r, search: i } = new URL(s, window.location.href);
2166
+ if (n !== "t.me")
2167
+ throw new Error(`URL has not allowed hostname: ${n}. Only "t.me" is allowed`);
2168
+ if (!v("web_app_open_tg_link", this.version)) {
2169
+ window.location.href = s;
2170
+ return;
2171
+ }
2172
+ this.postEvent("web_app_open_tg_link", { path_full: r + i });
2173
+ }
2174
+ /**
2175
+ * Reads text from clipboard and returns string or null. null is returned
2176
+ * in cases:
2177
+ * - Value in clipboard is not text
2178
+ * - Access to clipboard is not allowed
2179
+ */
2180
+ async readTextFromClipboard() {
2181
+ const s = this.createRequestId(), {
2182
+ data: n = null
2183
+ } = await f({
2184
+ method: "web_app_read_text_from_clipboard",
2185
+ event: "clipboard_text_received",
2186
+ postEvent: this.postEvent,
2187
+ params: { req_id: s },
2188
+ capture: ft(s)
2189
+ });
2190
+ return n;
2191
+ }
2192
+ }
2193
+ const ys = l(
2194
+ ({ version: e, postEvent: t, createRequestId: s }) => new ze(e, s, t)
2195
+ );
2196
+ async function Nt(e = {}) {
2197
+ const {
2198
+ is_expanded: t,
2199
+ is_state_stable: s,
2200
+ ...n
2201
+ } = await f({
2202
+ ...e,
2203
+ method: "web_app_request_viewport",
2204
+ event: "viewport_changed"
2205
+ });
2206
+ return { ...n, isExpanded: t, isStateStable: s };
2207
+ }
2208
+ function x(e) {
2209
+ return e < 0 ? 0 : e;
2210
+ }
2211
+ class Dt extends tt {
2212
+ constructor({ postEvent: s, stableHeight: n, height: r, width: i, isExpanded: o }) {
2213
+ super({
2214
+ height: x(r),
2215
+ isExpanded: o,
2216
+ stableHeight: x(n),
2217
+ width: x(i)
2218
+ });
2219
+ c(this, "postEvent");
2220
+ this.postEvent = s;
2221
+ }
2222
+ /**
2223
+ * Requests viewport information from the Telegram application and updates current Viewport
2224
+ * instance.
2225
+ * @param options - options to request fresh data.
2226
+ */
2227
+ async sync(s) {
2228
+ const { isStateStable: n, ...r } = await Nt(s);
2229
+ this.set({
2230
+ ...r,
2231
+ stableHeight: n ? r.height : this.get("stableHeight")
2232
+ });
2233
+ }
2234
+ /**
2235
+ * The current height of the **visible area** of the Mini App.
2236
+ *
2237
+ * The application can display just the top part of the Mini App, with its lower part remaining
2238
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
2239
+ * maximum height, while the bot can do the same by calling `expand` method. As the position of
2240
+ * the Mini App changes, the current height value of the visible area will be updated in real
2241
+ * time.
2242
+ *
2243
+ * Please note that the refresh rate of this value is not sufficient to smoothly follow the
2244
+ * lower border of the window. It should not be used to pin interface elements to the bottom
2245
+ * of the visible area. It's more appropriate to use the value of the `stableHeight`
2246
+ * field for this purpose.
2247
+ *
2248
+ * @see stableHeight
2249
+ */
2250
+ get height() {
2251
+ return this.get("height");
2252
+ }
2253
+ /**
2254
+ * The height of the visible area of the Mini App in its last stable state.
2255
+ *
2256
+ * The application can display just the top part of the Mini App, with its lower part remaining
2257
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
2258
+ * maximum height, while the application can do the same by calling `expand` method.
2259
+ *
2260
+ * Unlike the value of `height`, the value of `stableHeight` does not change as the position
2261
+ * of the Mini App changes with user gestures or during animations. The value of `stableHeight`
2262
+ * will be updated after all gestures and animations are completed and
2263
+ * the Mini App reaches its final size.
2264
+ *
2265
+ * @see height
2266
+ */
2267
+ get stableHeight() {
2268
+ return this.get("stableHeight");
2269
+ }
2270
+ /**
2271
+ * Starts listening to viewport changes and applies them.
2272
+ * @returns Function to stop listening.
2273
+ */
2274
+ listen() {
2275
+ return b("viewport_changed", (s) => {
2276
+ const {
2277
+ height: n,
2278
+ width: r,
2279
+ is_expanded: i,
2280
+ is_state_stable: o
2281
+ } = s, a = x(n);
2282
+ this.set({
2283
+ height: a,
2284
+ isExpanded: i,
2285
+ width: x(r),
2286
+ ...o ? { stableHeight: a } : {}
2287
+ });
2288
+ });
2289
+ }
2290
+ /**
2291
+ * True if the Mini App is expanded to the maximum available height. Otherwise, if
2292
+ * the Mini App occupies part of the screen and can be expanded to the full height using
2293
+ * `expand` method.
2294
+ * @see expand
2295
+ */
2296
+ get isExpanded() {
2297
+ return this.get("isExpanded");
2298
+ }
2299
+ /**
2300
+ * Current visible area width.
2301
+ */
2302
+ get width() {
2303
+ return this.get("width");
2304
+ }
2305
+ /**
2306
+ * A method that expands the Mini App to the maximum available height. To find out if the Mini
2307
+ * App is expanded to the maximum height, refer to the value of the `isExpanded`.
2308
+ * @see isExpanded
2309
+ */
2310
+ expand() {
2311
+ this.postEvent("web_app_expand"), this.set("isExpanded", !0);
2312
+ }
2313
+ /**
2314
+ * True if the current viewport height is stable and is not going to change in the next moment.
2315
+ */
2316
+ get isStable() {
2317
+ return this.stableHeight === this.height;
2318
+ }
2319
+ }
2320
+ async function Fe(e, t = {}) {
2321
+ const {
2322
+ height: s,
2323
+ width: n,
2324
+ isExpanded: r,
2325
+ isStateStable: i
2326
+ } = await Nt({ ...t, postEvent: e });
2327
+ return new Dt({
2328
+ postEvent: e,
2329
+ height: s,
2330
+ width: n,
2331
+ isExpanded: r,
2332
+ stableHeight: i ? s : 0
2333
+ });
2334
+ }
2335
+ function Je({
2336
+ state: e,
2337
+ platform: t,
2338
+ postEvent: s
2339
+ }) {
2340
+ let n = !1, r = 0, i = 0, o = 0;
2341
+ return e ? (n = e.isExpanded, r = e.height, i = e.width, o = e.stableHeight) : ["macos", "tdesktop", "unigram", "webk", "weba", "web"].includes(t) && (n = !0, r = window.innerHeight, i = window.innerWidth, o = window.innerHeight), new Dt({
2342
+ postEvent: s,
2343
+ height: r,
2344
+ width: i,
2345
+ stableHeight: o,
2346
+ isExpanded: n
2347
+ });
2348
+ }
2349
+ const vs = l(
2350
+ "viewport",
2351
+ async (e) => {
2352
+ if (E() && !e.state)
2353
+ throw u(
2354
+ J,
2355
+ "Viewport cannot be instantiated on the server side without passing the ssr.state object."
2356
+ );
2357
+ let t = Je(e);
2358
+ return E() || (t.width === 0 && await Fe(e.postEvent, { timeout: 1e3 }).then((s) => t = s).catch((s) => D.error("Unable to sync viewport state", s)), t.listen()), t;
2359
+ }
2360
+ );
2361
+ function m(e, t) {
2362
+ document.documentElement.style.setProperty(e, t);
2363
+ }
2364
+ function Es(e, t, s) {
2365
+ s || (s = (a) => `--tg-${a}-color`);
2366
+ const n = s("header"), r = s("bg"), i = () => {
2367
+ const { headerColor: a } = e;
2368
+ if (Y(a))
2369
+ m(n, a);
2370
+ else {
2371
+ const { bgColor: p, secondaryBgColor: d } = t;
2372
+ a === "bg_color" && p ? m(n, p) : a === "secondary_bg_color" && d && m(n, d);
2373
+ }
2374
+ m(r, e.bgColor);
2375
+ }, o = [
2376
+ t.on("change", i),
2377
+ e.on("change", i)
2378
+ ];
2379
+ return i(), () => o.forEach((a) => a());
2380
+ }
2381
+ function Ps(e, t) {
2382
+ t || (t = (n) => `--tg-theme-${n.replace(/[A-Z]/g, (r) => `-${r.toLowerCase()}`)}`);
2383
+ const s = () => {
2384
+ Object.entries(e.getState()).forEach(([n, r]) => {
2385
+ r && m(t(n), r);
2386
+ });
2387
+ };
2388
+ return s(), e.on("change", s);
2389
+ }
2390
+ function Ss(e, t) {
2391
+ t || (t = (d) => `--tg-viewport-${d}`);
2392
+ const [
2393
+ s,
2394
+ n,
2395
+ r
2396
+ ] = ["height", "width", "stable-height"].map((d) => t(d)), i = () => m(s, `${e.height}px`), o = () => m(n, `${e.width}px`), a = () => m(r, `${e.stableHeight}px`), p = [
2397
+ e.on("change:height", i),
2398
+ e.on("change:width", o),
2399
+ e.on("change:stableHeight", a)
2400
+ ];
2401
+ return i(), o(), a(), () => p.forEach((d) => d());
2402
+ }
2403
+ function xs(e = !0) {
2404
+ const t = [
2405
+ b("reload_iframe", () => {
2406
+ T("iframe_will_reload"), window.location.reload();
2407
+ })
2408
+ ], s = () => t.forEach((n) => n());
2409
+ if (e) {
2410
+ const n = document.createElement("style");
2411
+ n.id = "telegram-custom-styles", document.head.appendChild(n), t.push(
2412
+ b("set_custom_style", (r) => {
2413
+ n.innerHTML = r;
2414
+ }),
2415
+ () => document.head.removeChild(n)
2416
+ );
2417
+ }
2418
+ return T("iframe_ready", { reload_supported: !0 }), s;
2419
+ }
2420
+ async function Rs() {
2421
+ try {
2422
+ return await f({ method: "web_app_request_theme", event: "theme_changed", timeout: 100 }), !0;
2423
+ } catch {
2424
+ return !1;
2425
+ }
2426
+ }
2427
+ function Qe(e) {
2428
+ return e instanceof $;
2429
+ }
2430
+ function Cs(e, t) {
2431
+ return Qe(e) && e.type === t;
2432
+ }
2433
+ function O(e, t) {
2434
+ let s, n, r;
2435
+ return typeof e == "string" ? s = e : (s = e.pathname === void 0 ? t : e.pathname, n = e.params, r = e.id), Object.freeze({
2436
+ id: r || (Math.random() * 2 ** 14 | 0).toString(16),
2437
+ pathname: s,
2438
+ params: n
2439
+ });
2440
+ }
2441
+ class Ye {
2442
+ constructor(t, s, n = T) {
2443
+ /**
2444
+ * Navigation history.
2445
+ */
2446
+ c(this, "history");
2447
+ c(this, "ee", new V());
2448
+ /**
2449
+ * True, if current navigator is currently attached.
2450
+ */
2451
+ c(this, "attached", !1);
2452
+ /**
2453
+ * Goes to the previous history item.
2454
+ */
2455
+ c(this, "back", () => this.go(-1));
2456
+ /**
2457
+ * Adds new event listener.
2458
+ */
2459
+ c(this, "on", this.ee.on.bind(this.ee));
2460
+ /**
2461
+ * Removes event listener.
2462
+ */
2463
+ c(this, "off", this.ee.off.bind(this.ee));
2464
+ if (this._index = s, this.postEvent = n, t.length === 0)
2465
+ throw u(Jt, "History should not be empty.");
2466
+ if (s < 0 || s >= t.length)
2467
+ throw u(
2468
+ Qt,
2469
+ "Index should not be zero and higher or equal than history size."
2470
+ );
2471
+ this.history = t.map((r) => O(r, ""));
2472
+ }
2473
+ /**
2474
+ * Allows this navigator to control the `BackButton` visibility state. It also tracks the
2475
+ * `BackButton` clicks and calls the `back` method.
2476
+ */
2477
+ attach() {
2478
+ this.attached || (this.attached = !0, this.sync(), b("back_button_pressed", this.back));
2479
+ }
2480
+ /**
2481
+ * Currently active history item.
2482
+ */
2483
+ get current() {
2484
+ return this.history[this.index];
2485
+ }
2486
+ /**
2487
+ * Prevents current navigator from controlling the BackButton visibility state.
2488
+ */
2489
+ detach() {
2490
+ this.attached = !1, B("back_button_pressed", this.back);
2491
+ }
2492
+ /**
2493
+ * Goes to the next history item.
2494
+ */
2495
+ forward() {
2496
+ this.go(1);
2497
+ }
2498
+ /**
2499
+ * Changes currently active history item index by the specified delta. This method doesn't
2500
+ * change index in case, the updated index points to the non-existing history item. This behavior
2501
+ * is preserved until the `fit` argument is specified.
2502
+ * @param delta - index delta.
2503
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
2504
+ */
2505
+ go(t, s) {
2506
+ const n = this.index + t, r = Math.min(
2507
+ Math.max(0, n),
2508
+ this.history.length - 1
2509
+ );
2510
+ (n === r || s) && this.replaceAndMove(r, this.history[r]);
2511
+ }
2512
+ /**
2513
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
2514
+ *
2515
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
2516
+ * bound.
2517
+ * @param index - target index.
2518
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
2519
+ */
2520
+ goTo(t, s) {
2521
+ this.go(t - this.index, s);
2522
+ }
2523
+ /**
2524
+ * True if navigator has items before the current item.
2525
+ */
2526
+ get hasPrev() {
2527
+ return this.index > 0;
2528
+ }
2529
+ /**
2530
+ * True if navigator has items after the current item.
2531
+ */
2532
+ get hasNext() {
2533
+ return this.index !== this.history.length - 1;
2534
+ }
2535
+ /**
2536
+ * Currently active history item index.
2537
+ */
2538
+ get index() {
2539
+ return this._index;
2540
+ }
2541
+ /**
2542
+ * Adds a new history item removing all after the current one.
2543
+ * @param item - item to add.
2544
+ */
2545
+ push(t) {
2546
+ this.hasNext && this.history.splice(this.index + 1), this.replaceAndMove(this.index + 1, O(t, this.current.pathname));
2547
+ }
2548
+ /**
2549
+ * Replaces the current history item.
2550
+ * @param item - item to replace the current item with.
2551
+ */
2552
+ replace(t) {
2553
+ this.replaceAndMove(this.index, O(t, this.current.pathname));
2554
+ }
2555
+ /**
2556
+ * Sets history item by the specified index.
2557
+ * @param index - history item index to replace.
2558
+ * @param historyItem - history item to set.
2559
+ */
2560
+ replaceAndMove(t, s) {
2561
+ const n = t - this.index;
2562
+ if (!n && this.current === s)
2563
+ return;
2564
+ const r = this.current;
2565
+ if (this.index !== t) {
2566
+ const i = this._index;
2567
+ this._index = t, this.attached && i > 0 != t > 0 && this.sync();
2568
+ }
2569
+ this.history[t] = s, this.ee.emit("change", {
2570
+ navigator: this,
2571
+ from: r,
2572
+ to: this.current,
2573
+ delta: n
2574
+ });
2575
+ }
2576
+ /**
2577
+ * Actualizes the `BackButton` visibility state.
2578
+ */
2579
+ sync() {
2580
+ this.postEvent("web_app_setup_back_button", { is_visible: !!this.index });
2581
+ }
2582
+ }
2583
+ function U({
2584
+ params: e,
2585
+ ...t
2586
+ }) {
2587
+ return { ...e || { hash: "", search: "" }, ...t };
2588
+ }
2589
+ function A(e, t) {
2590
+ return e.startsWith(t) ? e : `${t}${e}`;
2591
+ }
2592
+ function k(e) {
2593
+ return new URL(
2594
+ typeof e == "string" ? e : `${e.pathname || ""}${A(e.search || "", "?")}${A(e.hash || "", "#")}`,
2595
+ "http://a"
2596
+ );
2597
+ }
2598
+ function N(e) {
2599
+ const t = typeof e == "string" ? e.startsWith("/") : !!(e.pathname && e.pathname.startsWith("/")), s = k(e);
2600
+ return `${t ? s.pathname : s.pathname.slice(1)}${s.search}${s.hash}`;
2601
+ }
2602
+ function W(e, t, s) {
2603
+ let n, r;
2604
+ typeof e == "string" ? n = e : (n = N(e), s = e.state, r = e.id);
2605
+ const { pathname: i, search: o, hash: a } = new URL(n, `http://a${A(t, "/")}`);
2606
+ return { id: r, pathname: i, params: { hash: a, search: o, state: s } };
2607
+ }
2608
+ async function C(e) {
2609
+ return e === 0 ? !0 : Promise.race([
2610
+ new Promise((t) => {
2611
+ const s = z("popstate", () => {
2612
+ s(), t(!0);
2613
+ });
2614
+ window.history.go(e);
2615
+ }),
2616
+ // Usually, it takes about 1ms to emit this event, but we use some buffer.
2617
+ new Promise((t) => {
2618
+ setTimeout(t, 50, !1);
2619
+ })
2620
+ ]);
2621
+ }
2622
+ async function Ze() {
2623
+ if (window.history.length <= 1 || (window.history.pushState(null, ""), await C(1 - window.history.length)))
2624
+ return;
2625
+ let t = await C(-1);
2626
+ for (; t; )
2627
+ t = await C(-1);
2628
+ }
2629
+ function Vt(e) {
2630
+ return k(e).pathname;
2631
+ }
2632
+ const at = 0, H = 1, G = 2;
2633
+ class $t {
2634
+ constructor(t, s, { postEvent: n, hashMode: r, base: i } = {}) {
2635
+ c(this, "navigator");
2636
+ c(this, "ee", new V());
2637
+ c(this, "hashMode");
2638
+ c(this, "base");
2639
+ /**
2640
+ * Shows whether the navigator is currently attached to the browser history.
2641
+ */
2642
+ c(this, "attached", !1);
2643
+ /**
2644
+ * Handles the window "popstate" event.
2645
+ * @param state - event state.
2646
+ */
2647
+ c(this, "onPopState", ({ state: t }) => {
2648
+ if (t === null)
2649
+ return this.push(this.parsePath(window.location.href));
2650
+ t === at ? window.history.forward() : t === H && this.back(), t === G && this.forward();
2651
+ });
2652
+ /**
2653
+ * Underlying navigator change event listener.
2654
+ */
2655
+ c(this, "onNavigatorChange", async ({
2656
+ to: t,
2657
+ from: s,
2658
+ delta: n
2659
+ }) => {
2660
+ this.attached && await this.syncHistory(), this.ee.emit("change", {
2661
+ delta: n,
2662
+ from: U(s),
2663
+ to: U(t),
2664
+ navigator: this
2665
+ });
2666
+ });
2667
+ /**
2668
+ * Adds new event listener.
2669
+ */
2670
+ c(this, "on", this.ee.on.bind(this.ee));
2671
+ /**
2672
+ * Removes event listener.
2673
+ */
2674
+ c(this, "off", this.ee.off.bind(this.ee));
2675
+ this.navigator = new Ye(
2676
+ t.map((o) => W(o, "/")),
2677
+ s,
2678
+ n
2679
+ ), this.navigator.on("change", this.onNavigatorChange), this.hashMode = r, this.base = Vt(i || "");
2680
+ }
2681
+ /**
2682
+ * Attaches current navigator to the browser history allowing navigator to manipulate it.
2683
+ */
2684
+ async attach() {
2685
+ this.attached || (this.attached = !0, this.navigator.attach(), window.addEventListener("popstate", this.onPopState), await this.syncHistory());
2686
+ }
2687
+ /**
2688
+ * Goes back in history by 1.
2689
+ */
2690
+ back() {
2691
+ this.navigator.back();
2692
+ }
2693
+ /**
2694
+ * Detaches current navigator from the browser history.
2695
+ */
2696
+ detach() {
2697
+ this.attached = !1, this.navigator.detach(), window.removeEventListener("popstate", this.onPopState);
2698
+ }
2699
+ /**
2700
+ * Goes forward in history.
2701
+ */
2702
+ forward() {
2703
+ return this.navigator.forward();
2704
+ }
2705
+ /**
2706
+ * Current history cursor.
2707
+ */
2708
+ get index() {
2709
+ return this.navigator.index;
2710
+ }
2711
+ /**
2712
+ * Current history item identifier.
2713
+ */
2714
+ get id() {
2715
+ return this.navigator.current.id;
2716
+ }
2717
+ /**
2718
+ * Changes currently active history item index by the specified delta. This method doesn't
2719
+ * change index in case, the updated index points to the non-existing history item. This behavior
2720
+ * is preserved until the `fit` argument is specified.
2721
+ * @param delta - index delta.
2722
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
2723
+ */
2724
+ go(t, s) {
2725
+ return this.navigator.go(t, s);
2726
+ }
2727
+ /**
2728
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
2729
+ *
2730
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
2731
+ * bound.
2732
+ * @param index - target index.
2733
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
2734
+ */
2735
+ goTo(t, s) {
2736
+ this.navigator.goTo(t, s);
2737
+ }
2738
+ /**
2739
+ * Current history item hash.
2740
+ * @see URL.hash
2741
+ * @example
2742
+ * "", "#my-hash"
2743
+ */
2744
+ get hash() {
2745
+ return (this.navigator.current.params || {}).hash || "";
2746
+ }
2747
+ /**
2748
+ * True if navigator has items before the current item.
2749
+ */
2750
+ get hasPrev() {
2751
+ return this.navigator.hasPrev;
2752
+ }
2753
+ /**
2754
+ * True if navigator has items after the current item.
2755
+ */
2756
+ get hasNext() {
2757
+ return this.navigator.hasNext;
2758
+ }
2759
+ /**
2760
+ * Navigation history.
2761
+ */
2762
+ get history() {
2763
+ return this.navigator.history.map(U);
2764
+ }
2765
+ /**
2766
+ * Path, including pathname, search and hash.
2767
+ * @example Pathname only.
2768
+ * "/pathname"
2769
+ * @example Pathname + search.
2770
+ * "/pathname?search"
2771
+ * @example Pathname + hash.
2772
+ * "/pathname#hash"
2773
+ * @example Pathname + search + hash.
2774
+ * "/pathname?search#hash"
2775
+ */
2776
+ get path() {
2777
+ return N(this);
2778
+ }
2779
+ /**
2780
+ * Current pathname. Always starts with the slash.
2781
+ * @see URL.pathname
2782
+ * @example
2783
+ * "/", "/abc"
2784
+ */
2785
+ get pathname() {
2786
+ return this.navigator.current.pathname;
2787
+ }
2788
+ /**
2789
+ * Depending on the current navigation type, parses incoming path and returns it presented as
2790
+ * an object. In other words, this method parses the passed path and returns object, describing
2791
+ * how the navigator "sees" it.
2792
+ *
2793
+ * @example Hash mode is omitted.
2794
+ * parsePath('/abc?a=1#hash');
2795
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
2796
+ * parsePath('http://example.com/abc?a=1#hash');
2797
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
2798
+ *
2799
+ * @example Hash mode is enabled.
2800
+ * parsePath('/abc?a=1#tma?is=cool#yeah');
2801
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2802
+ * parsePath('http://example.com/abc?a=1#tma?is=cool#yeah');
2803
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
2804
+ */
2805
+ parsePath(t) {
2806
+ let s = k(t);
2807
+ return this.hashMode && (s = k(s.hash.slice(1))), {
2808
+ pathname: s.pathname,
2809
+ search: s.search,
2810
+ hash: s.hash
2811
+ };
2812
+ }
2813
+ push(t, s) {
2814
+ const n = W(t, this.path), { state: r = s } = n.params;
2815
+ this.navigator.push({ ...n, params: { ...n.params, state: r } });
2816
+ }
2817
+ replace(t, s) {
2818
+ const n = W(t, this.path), { state: r = s } = n.params;
2819
+ this.navigator.replace({ ...n, params: { ...n.params, state: r } });
2820
+ }
2821
+ /**
2822
+ * Combines the navigator `base` property with the passed path data applying the navigator
2823
+ * navigation mode.
2824
+ * @param value - path presented as string or URLLike.
2825
+ */
2826
+ renderPath(t) {
2827
+ const s = (this.base.length === 1 ? "" : this.base) + A(N(t), "/");
2828
+ return this.hashMode ? A(s.slice(1), this.hashMode === "default" ? "#" : "#/") : s;
2829
+ }
2830
+ /**
2831
+ * Synchronizes current navigator state with browser history.
2832
+ */
2833
+ async syncHistory() {
2834
+ window.removeEventListener("popstate", this.onPopState);
2835
+ const { state: t } = this, s = this.renderPath(this);
2836
+ await Ze(), this.hasPrev && this.hasNext ? (window.history.replaceState(H, ""), window.history.pushState(t, "", s), window.history.pushState(G, ""), await C(-1)) : this.hasPrev ? (window.history.replaceState(H, ""), window.history.pushState(t, "", s)) : this.hasNext ? (window.history.replaceState(t, s), window.history.pushState(G, ""), await C(-1)) : (window.history.replaceState(at, ""), window.history.pushState(t, "", s)), window.addEventListener("popstate", this.onPopState);
2837
+ }
2838
+ /**
2839
+ * Current query parameters.
2840
+ * @see URL.search
2841
+ * @example
2842
+ * "", "?", "?a=1"
2843
+ */
2844
+ get search() {
2845
+ return (this.navigator.current.params || {}).search || "";
2846
+ }
2847
+ /**
2848
+ * Current history item state.
2849
+ */
2850
+ get state() {
2851
+ return (this.navigator.current.params || {}).state;
2852
+ }
2853
+ }
2854
+ function Xe(e) {
2855
+ e || (e = {});
2856
+ const { href: t, hash: s } = window.location;
2857
+ let n = N(
2858
+ e.hashMode ? s.includes("?") ? s.slice(1) : `?${s.slice(1)}` : t
2859
+ );
2860
+ const r = e.base ? Vt(e.base) : void 0;
2861
+ if (r) {
2862
+ if (!n.startsWith(r))
2863
+ throw u(
2864
+ Zt,
2865
+ `Path "${n}" expected to be starting with "${r}"`
2866
+ );
2867
+ n = n.slice(r.length);
2868
+ }
2869
+ return new $t([n], 0, e);
2870
+ }
2871
+ function Ts(e) {
2872
+ const t = e.match(/#(.+)/);
2873
+ return t ? t[1] : null;
2874
+ }
2875
+ function Ke(e, t) {
2876
+ if (At()) {
2877
+ const s = sessionStorage.getItem(e);
2878
+ if (s)
2879
+ try {
2880
+ const { index: n, history: r } = JSON.parse(s);
2881
+ return new $t(r, n, t);
2882
+ } catch (n) {
2883
+ console.error("Unable to restore hash navigator state.", n);
2884
+ }
2885
+ }
2886
+ return Xe(t);
2887
+ }
2888
+ function As(e, t) {
2889
+ const s = Ke(e, t), n = () => sessionStorage.setItem(e, JSON.stringify({
2890
+ index: s.index,
2891
+ history: s.history
2892
+ }));
2893
+ return s.on("change", n), n(), s;
2894
+ }
2895
+ export {
2896
+ fe as BackButton,
2897
+ Ye as BasicNavigator,
2898
+ it as BiometryManager,
2899
+ $t as BrowserNavigator,
2900
+ Ae as ClosingBehavior,
2901
+ Ne as CloudStorage,
2902
+ Zt as ERR_INVALID_PATH_BASE,
2903
+ jt as ERR_INVOKE_CUSTOM_METHOD_RESPONSE,
2904
+ Ht as ERR_METHOD_PARAMETER_UNSUPPORTED,
2905
+ Wt as ERR_METHOD_UNSUPPORTED,
2906
+ Jt as ERR_NAVIGATION_HISTORY_EMPTY,
2907
+ Qt as ERR_NAVIGATION_INDEX_INVALID,
2908
+ ss as ERR_NAVIGATION_ITEM_INVALID,
2909
+ pt as ERR_PARSE,
2910
+ J as ERR_SSR_INIT,
2911
+ Yt as ERR_SSR_POST_EVENT,
2912
+ zt as ERR_TIMED_OUT,
2913
+ Ft as ERR_UNEXPECTED_TYPE,
2914
+ Gt as ERR_UNKNOWN_ENV,
2915
+ V as EventEmitter,
2916
+ De as HapticFeedback,
2917
+ Ve as InitData,
2918
+ $e as Invoice,
2919
+ Me as MainButton,
2920
+ Oe as MiniApp,
2921
+ We as Popup,
2922
+ He as QRScanner,
2923
+ $ as SDKError,
2924
+ Ge as SettingsButton,
2925
+ je as ThemeParams,
2926
+ ze as Utils,
2927
+ Dt as Viewport,
2928
+ ke as array,
2929
+ Es as bindMiniAppCSSVars,
2930
+ Ps as bindThemeParamsCSSVars,
2931
+ Ss as bindViewportCSSVars,
2932
+ w as boolean,
2933
+ ft as captureSameReq,
2934
+ F as classNames,
2935
+ ce as compareVersions,
2936
+ Xe as createBrowserNavigatorFromLocation,
2937
+ de as createPostEvent,
2938
+ k as createSafeURL,
2939
+ yt as date,
2940
+ Ts as getHash,
2941
+ Vt as getPathname,
2942
+ is as initBackButton,
2943
+ os as initBiometryManager,
2944
+ as as initClosingBehavior,
2945
+ cs as initCloudStorage,
2946
+ hs as initHapticFeedback,
2947
+ ps as initInitData,
2948
+ ls as initInvoice,
2949
+ ds as initMainButton,
2950
+ _s as initMiniApp,
2951
+ As as initNavigator,
2952
+ fs as initPopup,
2953
+ gs as initQRScanner,
2954
+ bs as initSettingsButton,
2955
+ ws as initThemeParams,
2956
+ ys as initUtils,
2957
+ vs as initViewport,
2958
+ xs as initWeb,
2959
+ R as invokeCustomMethod,
2960
+ wt as isColorDark,
2961
+ ue as isIframe,
2962
+ At as isPageReload,
2963
+ Y as isRGB,
2964
+ Xt as isRGBShort,
2965
+ Qe as isSDKError,
2966
+ Cs as isSDKErrorOfType,
2967
+ Rs as isTMA,
2968
+ _ as json,
2969
+ rs as mergeClassNames,
2970
+ y as number,
2971
+ B as off,
2972
+ b as on,
2973
+ us as parseInitData,
2974
+ Pt as parseLaunchParams,
2975
+ kt as parseThemeParams,
2976
+ T as postEvent,
2977
+ f as request,
2978
+ Te as requestBiometryInfo,
2979
+ ms as requestThemeParams,
2980
+ Nt as requestViewport,
2981
+ xe as retrieveLaunchParams,
2982
+ dt as rgb,
2983
+ K as searchParams,
2984
+ Pe as serializeLaunchParams,
2985
+ Ee as serializeThemeParams,
2986
+ m as setCSSVar,
2987
+ es as setDebug,
2988
+ ns as setTargetOrigin,
2989
+ h as string,
2990
+ Bt as subscribe,
2991
+ v as supports,
2992
+ le as targetOrigin,
2993
+ lt as toRGB,
2994
+ ht as unsubscribe,
2995
+ N as urlToPath,
2996
+ bt as withTimeout
2997
+ };
2998
+ //# sourceMappingURL=index.js.map