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