@tma.js/sdk 1.5.3 → 2.0.1

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 +114 -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 +3001 -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
@@ -0,0 +1,53 @@
1
+ import { WithTrackableState } from '../../classes/WithTrackableState.js';
2
+ import { RGB } from '../../colors/types.js';
3
+ import { RemoveEventListenerFn } from '../../events/types.js';
4
+ import { ThemeParamsParsed, ThemeParamsState } from './types.js';
5
+
6
+ /**
7
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/theming
8
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/theme-params
9
+ */
10
+ export declare class ThemeParams extends WithTrackableState<ThemeParamsState> {
11
+ /**
12
+ * @since v6.10
13
+ */
14
+ get accentTextColor(): RGB | undefined;
15
+ get bgColor(): RGB | undefined;
16
+ get buttonColor(): RGB | undefined;
17
+ get buttonTextColor(): RGB | undefined;
18
+ get destructiveTextColor(): RGB | undefined;
19
+ /**
20
+ * Returns the copy of the internal state of the current component instance.
21
+ */
22
+ getState(): ThemeParamsParsed;
23
+ /**
24
+ * @since v6.10
25
+ */
26
+ get headerBgColor(): RGB | undefined;
27
+ get hintColor(): RGB | undefined;
28
+ /**
29
+ * @returns True in case, current color scheme is recognized as dark. This
30
+ * value is calculated according to theme bg color.
31
+ */
32
+ get isDark(): boolean;
33
+ get linkColor(): RGB | undefined;
34
+ get secondaryBgColor(): RGB | undefined;
35
+ /**
36
+ * @since v6.10
37
+ */
38
+ get sectionBgColor(): RGB | undefined;
39
+ /**
40
+ * @since v6.10
41
+ */
42
+ get sectionHeaderTextColor(): RGB | undefined;
43
+ /**
44
+ * Starts listening to the external theme changes and applies them.
45
+ * @returns Function to stop listening.
46
+ */
47
+ listen(): RemoveEventListenerFn;
48
+ /**
49
+ * @since v6.10
50
+ */
51
+ get subtitleTextColor(): RGB | undefined;
52
+ get textColor(): RGB | undefined;
53
+ }
@@ -0,0 +1,7 @@
1
+ import { ThemeParams } from './ThemeParams.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `ThemeParams` class.
5
+ * @see ThemeParams
6
+ */
7
+ export declare const initThemeParams: import('../../index.js').InitComponentFn<"themeParams", ThemeParams, import('./types.js').ThemeParamsParsed>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Converts a palette key from the Telegram application to the representation used by the package.
3
+ * @param key - palette key.
4
+ */
5
+ export declare function keyToLocal(key: string): string;
6
+ /**
7
+ * Converts palette key from the local representation to the representation sent from the
8
+ * Telegram application.
9
+ * @param key - palette key.
10
+ */
11
+ export declare function keyToExternal(key: string): string;
@@ -1,4 +1,5 @@
1
- import type { ThemeParamsParsed } from './types.js';
1
+ import { ThemeParamsParsed } from '../types.js';
2
+
2
3
  /**
3
4
  * Parses incoming value as theme parameters.
4
5
  * @param value - value to parse.
@@ -1,4 +1,5 @@
1
- import type { ThemeParamsParsed } from './types.js';
1
+ import { ThemeParamsParsed } from '../types.js';
2
+
2
3
  /**
3
4
  * Serializes theme parameters to representation sent from the Telegram application.
4
5
  */
@@ -0,0 +1,4 @@
1
+ import { ValueParserGenerator } from '../../../parsing/createValueParserGenerator.js';
2
+ import { ThemeParamsParsed } from '../types.js';
3
+
4
+ export declare const themeParams: ValueParserGenerator<ThemeParamsParsed>;
@@ -0,0 +1,8 @@
1
+ import { ExecuteWithOptions } from '../../types/index.js';
2
+ import { ThemeParamsParsed } from './types.js';
3
+
4
+ /**
5
+ * Requests current theme parameters from the Telegram application.
6
+ * @param options - request options.
7
+ */
8
+ export declare function requestThemeParams(options?: ExecuteWithOptions): Promise<ThemeParamsParsed>;
@@ -0,0 +1,29 @@
1
+ import { StateEvents } from '../../classes/State/types.js';
2
+ import { RGB } from '../../colors/types.js';
3
+
4
+ export type ThemeParamsKey = 'accentTextColor' | 'bgColor' | 'buttonColor' | 'buttonTextColor' | 'destructiveTextColor' | 'headerBgColor' | 'hintColor' | 'linkColor' | 'secondaryBgColor' | 'sectionBgColor' | 'sectionHeaderTextColor' | 'subtitleTextColor' | 'textColor';
5
+ /**
6
+ * Application [theme parameters](https://docs.telegram-mini-apps.com/platform/theming).
7
+ * Defines palette used by the Telegram application.
8
+ */
9
+ export interface ThemeParamsParsed {
10
+ [key: ThemeParamsKey | string]: RGB | undefined;
11
+ }
12
+ /**
13
+ * ThemeParams internal state.
14
+ */
15
+ export interface ThemeParamsState extends ThemeParamsParsed {
16
+ }
17
+ /**
18
+ * ThemeParams trackable events.
19
+ */
20
+ export interface ThemeParamsEvents extends StateEvents<ThemeParamsState> {
21
+ }
22
+ /**
23
+ * ThemeParams event name.
24
+ */
25
+ export type ThemeParamsEventName = keyof ThemeParamsEvents;
26
+ /**
27
+ * ThemeParams event listener.
28
+ */
29
+ export type ThemeParamsEventListener<E extends ThemeParamsEventName> = ThemeParamsEvents[E];
@@ -1,15 +1,17 @@
1
- import type { PostEvent } from '../../bridge/methods/postEvent.js';
2
- import type { SupportsFunc } from '../../supports/types.js';
3
- import type { CreateRequestIdFunc } from '../../types/request-id.js';
4
- import type { Version } from '../../version/types.js';
1
+ import { WithSupports } from '../../classes/WithSupports.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { CreateRequestIdFn } from '../../request-id/types.js';
4
+ import { SupportsFn } from '../../supports/types.js';
5
+ import { Version } from '../../version/types.js';
6
+
5
7
  /**
6
- * Provides common Mini Apps functionality not covered by other system components.
8
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/utils
7
9
  */
8
- export declare class Utils {
10
+ export declare class Utils extends WithSupports<'readTextFromClipboard'> {
9
11
  private readonly version;
10
12
  private readonly createRequestId;
11
13
  private readonly postEvent;
12
- constructor(version: Version, createRequestId: CreateRequestIdFunc, postEvent?: PostEvent);
14
+ constructor(version: Version, createRequestId: CreateRequestIdFn, postEvent: PostEvent);
13
15
  /**
14
16
  * Opens a link in an external browser. The Mini App will not be closed.
15
17
  *
@@ -34,12 +36,8 @@ export declare class Utils {
34
36
  * - Access to clipboard is not allowed
35
37
  */
36
38
  readTextFromClipboard(): Promise<string | null>;
37
- /**
38
- * Checks if specified method is supported by current component.
39
- */
40
- supports: SupportsFunc<'readTextFromClipboard'>;
41
39
  /**
42
40
  * Checks if specified method parameter is supported by current component.
43
41
  */
44
- supportsParam: SupportsFunc<'openLink.tryInstantView'>;
42
+ supportsParam: SupportsFn<'openLink.tryInstantView'>;
45
43
  }
@@ -0,0 +1,7 @@
1
+ import { Utils } from './Utils.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `Utils` class.
5
+ * @see Utils
6
+ */
7
+ export declare const initUtils: import('../../index.js').InitComponentFn<"version", Utils, never>;
@@ -0,0 +1,77 @@
1
+ import { WithTrackableState } from '../../classes/WithTrackableState.js';
2
+ import { RemoveEventListenerFn } from '../../events/types.js';
3
+ import { ExecuteWithOptions } from '../../types/index.js';
4
+ import { ViewportProps, ViewportState } from './types.js';
5
+
6
+ /**
7
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/viewport
8
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/viewport
9
+ */
10
+ export declare class Viewport extends WithTrackableState<ViewportState> {
11
+ private readonly postEvent;
12
+ constructor({ postEvent, stableHeight, height, width, isExpanded }: ViewportProps);
13
+ /**
14
+ * Requests viewport information from the Telegram application and updates current Viewport
15
+ * instance.
16
+ * @param options - options to request fresh data.
17
+ */
18
+ sync(options?: ExecuteWithOptions): Promise<void>;
19
+ /**
20
+ * The current height of the **visible area** of the Mini App.
21
+ *
22
+ * The application can display just the top part of the Mini App, with its lower part remaining
23
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
24
+ * maximum height, while the bot can do the same by calling `expand` method. As the position of
25
+ * the Mini App changes, the current height value of the visible area will be updated in real
26
+ * time.
27
+ *
28
+ * Please note that the refresh rate of this value is not sufficient to smoothly follow the
29
+ * lower border of the window. It should not be used to pin interface elements to the bottom
30
+ * of the visible area. It's more appropriate to use the value of the `stableHeight`
31
+ * field for this purpose.
32
+ *
33
+ * @see stableHeight
34
+ */
35
+ get height(): number;
36
+ /**
37
+ * The height of the visible area of the Mini App in its last stable state.
38
+ *
39
+ * The application can display just the top part of the Mini App, with its lower part remaining
40
+ * outside the screen area. From this position, the user can "pull" the Mini App to its
41
+ * maximum height, while the application can do the same by calling `expand` method.
42
+ *
43
+ * Unlike the value of `height`, the value of `stableHeight` does not change as the position
44
+ * of the Mini App changes with user gestures or during animations. The value of `stableHeight`
45
+ * will be updated after all gestures and animations are completed and
46
+ * the Mini App reaches its final size.
47
+ *
48
+ * @see height
49
+ */
50
+ get stableHeight(): number;
51
+ /**
52
+ * Starts listening to viewport changes and applies them.
53
+ * @returns Function to stop listening.
54
+ */
55
+ listen(): RemoveEventListenerFn;
56
+ /**
57
+ * True if the Mini App is expanded to the maximum available height. Otherwise, if
58
+ * the Mini App occupies part of the screen and can be expanded to the full height using
59
+ * `expand` method.
60
+ * @see expand
61
+ */
62
+ get isExpanded(): boolean;
63
+ /**
64
+ * Current visible area width.
65
+ */
66
+ get width(): number;
67
+ /**
68
+ * A method that expands the Mini App to the maximum available height. To find out if the Mini
69
+ * App is expanded to the maximum height, refer to the value of the `isExpanded`.
70
+ * @see isExpanded
71
+ */
72
+ expand(): void;
73
+ /**
74
+ * True if the current viewport height is stable and is not going to change in the next moment.
75
+ */
76
+ get isStable(): boolean;
77
+ }
@@ -0,0 +1,8 @@
1
+ import { Viewport } from './Viewport.js';
2
+ import { ViewportState } from './types.js';
3
+
4
+ /**
5
+ * @returns A promise with a new initialized instance of the `Viewport` class.
6
+ * @see Viewport
7
+ */
8
+ export declare const initViewport: import('../../misc/createComponentInitFn/types.js').InitComponentFn<"platform", Promise<Viewport>, ViewportState>;
@@ -0,0 +1,10 @@
1
+ import { Viewport } from './Viewport.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { ExecuteWithTimeout } from '../../types/index.js';
4
+
5
+ /**
6
+ * Creates new Viewport instance using Mini Apps method.
7
+ * @param postEvent - function to call Mini Apps method.
8
+ * @param options - additional execution options.
9
+ */
10
+ export declare function initViewportFromRequest(postEvent: PostEvent, options?: ExecuteWithTimeout): Promise<Viewport>;
@@ -1,4 +1,5 @@
1
- import type { RequestSimpleOptions } from '../../bridge/request.js';
1
+ import { ExecuteWithOptions } from '../../types/index.js';
2
+
2
3
  export interface RequestViewportResult {
3
4
  height: number;
4
5
  isStateStable: boolean;
@@ -9,4 +10,4 @@ export interface RequestViewportResult {
9
10
  * Requests viewport actual information from the Telegram application.
10
11
  * @param options - request options.
11
12
  */
12
- export declare function requestViewport(options?: RequestSimpleOptions<'web_app_request_viewport'>): Promise<RequestViewportResult>;
13
+ export declare function requestViewport(options?: ExecuteWithOptions): Promise<RequestViewportResult>;
@@ -0,0 +1,35 @@
1
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
2
+ import { StateEvents } from '../../classes/State/types.js';
3
+
4
+ /**
5
+ * Viewport constructor properties.
6
+ */
7
+ export interface ViewportProps {
8
+ height: number;
9
+ width: number;
10
+ stableHeight: number;
11
+ isExpanded: boolean;
12
+ postEvent: PostEvent;
13
+ }
14
+ /**
15
+ * Viewport internal state.
16
+ */
17
+ export interface ViewportState {
18
+ height: number;
19
+ isExpanded: boolean;
20
+ stableHeight: number;
21
+ width: number;
22
+ }
23
+ /**
24
+ * Viewport trackable events.
25
+ */
26
+ export interface ViewportEvents extends StateEvents<ViewportState> {
27
+ }
28
+ /**
29
+ * Viewport event name.
30
+ */
31
+ export type ViewportEventName = keyof ViewportEvents;
32
+ /**
33
+ * Viewport event listener.
34
+ */
35
+ export type ViewportEventListener<E extends ViewportEventName> = ViewportEvents[E];
@@ -0,0 +1,29 @@
1
+ import { ThemeParams } from '../components/ThemeParams/ThemeParams.js';
2
+ import { MiniApp } from '../components/MiniApp/MiniApp.js';
3
+ import { CleanupFn } from '../types/index.js';
4
+
5
+ export interface GetMiniAppCSSVarNameFn {
6
+ /**
7
+ * @param property - MiniApp property.
8
+ * @returns Computed complete CSS variable name.
9
+ */
10
+ (property: 'bg' | 'header'): string;
11
+ }
12
+ /**
13
+ * Creates CSS variables connected with the MiniApps class instance background and header colors
14
+ * based on the passed MiniApp and ThemeParams instances.
15
+ *
16
+ * Created variables by default:
17
+ * - `--tg-bg-color`
18
+ * - `--tg-header-color`
19
+ *
20
+ * Variables are being automatically updated in case, corresponding MiniApp and ThemeParams
21
+ * properties were updated.
22
+ *
23
+ * @param miniApp - MiniApp instance.
24
+ * @param themeParams - ThemeParams instance.
25
+ * @param getVarName - function, returning complete CSS variable name for the specified
26
+ * MiniApp property.
27
+ * @returns Function to stop updating variables.
28
+ */
29
+ export declare function bindMiniAppCSSVars(miniApp: MiniApp, themeParams: ThemeParams, getVarName?: GetMiniAppCSSVarNameFn): CleanupFn;
@@ -0,0 +1,29 @@
1
+ import { ThemeParams } from '../components/ThemeParams/ThemeParams.js';
2
+ import { CleanupFn } from '../types/index.js';
3
+
4
+ export interface GetThemeParamsCSSVarNameFn {
5
+ /**
6
+ * @param property - ThemeParams property.
7
+ * @returns Computed complete CSS variable name.
8
+ */
9
+ (property: string): string;
10
+ }
11
+ /**
12
+ * Creates CSS variables connected with the passed instance of the ThemeParams class.
13
+ *
14
+ * By default, created CSS variables names are following the pattern "--tg-theme-{name}", where
15
+ * {name} is a theme parameters key name converted from camel case to kebab case.
16
+ *
17
+ * Example:
18
+ * --tg-theme-bg-color
19
+ * --tg-theme-secondary-text-color
20
+ *
21
+ * Variables are being automatically updated in case, corresponding properties updated in
22
+ * the passed ThemeParams instance.
23
+ *
24
+ * @param themeParams - ThemeParams instance.
25
+ * @param getCSSVarName - function, returning complete CSS variable name for the specified
26
+ * ThemeParams property.
27
+ * @returns Function to stop updating variables.
28
+ */
29
+ export declare function bindThemeParamsCSSVars(themeParams: ThemeParams, getCSSVarName?: GetThemeParamsCSSVarNameFn): CleanupFn;
@@ -0,0 +1,32 @@
1
+ import { Viewport } from '../components/Viewport/Viewport.js';
2
+ import { CleanupFn } from '../types/index.js';
3
+
4
+ export interface GetViewportCSSVarNameFn {
5
+ /**
6
+ * @param property - Viewport property.
7
+ * @returns Computed complete CSS variable name.
8
+ */
9
+ (property: 'width' | 'height' | 'stable-height'): string;
10
+ }
11
+ /**
12
+ * Accepts Viewport instance and sets CSS variables connected with viewport
13
+ * sizes.
14
+ *
15
+ * Be careful using this function as long as it can impact application
16
+ * performance. Viewport size is changing rather often, this makes CSS
17
+ * variables update, which leads to possible layout redraw.
18
+ *
19
+ * Variables:
20
+ * - `--tg-viewport-height`
21
+ * - `--tg-viewport-width`
22
+ * - `--tg-viewport-stable-height`
23
+ *
24
+ * Variables are being automatically updated in case, corresponding properties
25
+ * updated in passed Viewport instance.
26
+ *
27
+ * @param viewport - Viewport instance.
28
+ * @param getCSSVarName - function, returning complete CSS variable name for the specified
29
+ * Viewport property.
30
+ * @returns Function to stop updating variables.
31
+ */
32
+ export declare function bindViewportCSSVars(viewport: Viewport, getCSSVarName?: GetViewportCSSVarNameFn): CleanupFn;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sets CSS variable.
2
+ * Sets CSS variable globally.
3
3
  * @param name - variable name.
4
4
  * @param value - variable value.
5
5
  */
@@ -0,0 +1,14 @@
1
+ import { Logger } from '../logger/Logger.js';
2
+
3
+ export declare const logger: Logger;
4
+ /**
5
+ * Sets new debug mode. Enabling debug mode leads to printing additional messages in the console,
6
+ * related to the processes inside the package.
7
+ * @param enable - should debug be enabled.
8
+ */
9
+ export declare function setDebug(enable: boolean): void;
10
+ /**
11
+ * Logs info message into the console.
12
+ * @param args - additional arguments.
13
+ */
14
+ export declare function log(...args: any[]): void;
@@ -1,12 +1,10 @@
1
- type WithExternalNotify<T> = T & {
2
- external: {
3
- notify: (...args: any) => any;
4
- };
5
- };
6
1
  /**
7
2
  * Returns true in case, passed value contains path `external.notify` property and `notify` is a
8
3
  * function.
9
4
  * @param value - value to check.
10
5
  */
11
- export declare function hasExternalNotify<T extends {}>(value: T): value is WithExternalNotify<T>;
12
- export {};
6
+ export declare function hasExternalNotify<T extends object>(value: T): value is (T & {
7
+ external: {
8
+ notify: (...args: any) => any;
9
+ };
10
+ });
@@ -1,12 +1,10 @@
1
- type WithWebviewProxy<T> = T & {
2
- TelegramWebviewProxy: {
3
- postEvent: (...args: any) => any;
4
- };
5
- };
6
1
  /**
7
2
  * Returns true in case, passed value contains path `TelegramWebviewProxy.postEvent` property and
8
3
  * `postEvent` is a function.
9
4
  * @param value - value to check.
10
5
  */
11
- export declare function hasWebviewProxy<T extends {}>(value: T): value is WithWebviewProxy<T>;
12
- export {};
6
+ export declare function hasWebviewProxy<T extends {}>(value: T): value is (T & {
7
+ TelegramWebviewProxy: {
8
+ postEvent: (...args: any) => any;
9
+ };
10
+ });
@@ -0,0 +1,11 @@
1
+ interface CleanupFn {
2
+ (): void;
3
+ }
4
+ /**
5
+ * Performs initialization process in the web version of Telegram.
6
+ * @returns Function, which performs cleanup removing all created elements and listeners.
7
+ * @param acceptCustomStyles - true if SDK should accept styles sent from the Telegram web
8
+ * application. This option is only used in web versions of Telegram. Default: false.
9
+ */
10
+ export declare function initWeb(acceptCustomStyles?: boolean): CleanupFn;
11
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @returns True, if current environment is server.
3
+ */
4
+ export declare function isSSR(): boolean;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Returns true in case, current environment is Telegram Mini Apps.
3
3
  */
4
- export declare function isTMA(): boolean;
4
+ export declare function isTMA(): Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ import { ErrorType } from './errors.js';
2
+
3
+ /**
4
+ * Error used across the SDK.
5
+ */
6
+ export declare class SDKError extends Error {
7
+ readonly type: ErrorType;
8
+ constructor(type: ErrorType, message?: string, cause?: unknown);
9
+ }
@@ -0,0 +1,10 @@
1
+ import { SDKError } from './SDKError.js';
2
+ import { ErrorType } from './errors.js';
3
+
4
+ /**
5
+ * Creates new error using specified type and message.
6
+ * @param type - error code.
7
+ * @param message - error message.
8
+ * @param cause - original error.
9
+ */
10
+ export declare function createError(type: ErrorType, message: string, cause?: unknown): SDKError;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Specified Mini Apps method is unsupported.
3
+ */
4
+ export declare const ERR_METHOD_UNSUPPORTED = "ERR_METHOD_UNSUPPORTED";
5
+ /**
6
+ * Specified Mini Apps method parameter is unsupported.
7
+ */
8
+ export declare const ERR_METHOD_PARAMETER_UNSUPPORTED = "ERR_METHOD_PARAMETER_UNSUPPORTED";
9
+ /**
10
+ * Current environment is not Telegram application.
11
+ */
12
+ export declare const ERR_UNKNOWN_ENV = "ERR_UNKNOWN_ENV";
13
+ /**
14
+ * Telegram application returned and error while invoking custom method.
15
+ */
16
+ export declare const ERR_INVOKE_CUSTOM_METHOD_RESPONSE = "ERR_INVOKE_CUSTOM_METHOD_RESPONSE";
17
+ /**
18
+ * Timeout reached.
19
+ */
20
+ export declare const ERR_TIMED_OUT = "ERR_TIMED_OUT";
21
+ /**
22
+ * Value has unexpected type.
23
+ */
24
+ export declare const ERR_UNEXPECTED_TYPE = "ERR_UNEXPECTED_TYPE";
25
+ /**
26
+ * Something went wrong during value parsing.
27
+ */
28
+ export declare const ERR_PARSE = "ERR_PARSE";
29
+ /**
30
+ * Navigation entries list is empty.
31
+ */
32
+ export declare const ERR_NAVIGATION_HISTORY_EMPTY = "ERR_NAVIGATION_LIST_EMPTY";
33
+ /**
34
+ * Navigation entries cursor is invalid.
35
+ */
36
+ export declare const ERR_NAVIGATION_INDEX_INVALID = "ERR_NAVIGATION_CURSOR_INVALID";
37
+ /**
38
+ * Navigation entries item is invalid.
39
+ */
40
+ export declare const ERR_NAVIGATION_ITEM_INVALID = "ERR_NAVIGATION_ITEM_INVALID";
41
+ /**
42
+ * SSR component initialization failed.
43
+ */
44
+ export declare const ERR_SSR_INIT = "ERR_SSR_INIT";
45
+ /**
46
+ * Server side called postEvent.
47
+ */
48
+ export declare const ERR_SSR_POST_EVENT = "ERR_SSR_POST_EVENT";
49
+ /**
50
+ * Path starts from the invalid base.
51
+ */
52
+ export declare const ERR_INVALID_PATH_BASE = "ERR_INVALID_PATH_BASE";
53
+ export type ErrorType = typeof ERR_METHOD_UNSUPPORTED | typeof ERR_METHOD_PARAMETER_UNSUPPORTED | typeof ERR_UNKNOWN_ENV | typeof ERR_INVOKE_CUSTOM_METHOD_RESPONSE | typeof ERR_TIMED_OUT | typeof ERR_PARSE | typeof ERR_UNEXPECTED_TYPE | typeof ERR_NAVIGATION_HISTORY_EMPTY | typeof ERR_NAVIGATION_INDEX_INVALID | typeof ERR_NAVIGATION_ITEM_INVALID | typeof ERR_SSR_INIT | typeof ERR_SSR_POST_EVENT | typeof ERR_INVALID_PATH_BASE;
@@ -0,0 +1,7 @@
1
+ import { SDKError } from './SDKError.js';
2
+
3
+ /**
4
+ * @returns True, if passed value is an instance of SDKError.
5
+ * @param value - value to check.
6
+ */
7
+ export declare function isSDKError(value: unknown): value is SDKError;
@@ -0,0 +1,8 @@
1
+ import { ErrorType } from './errors.js';
2
+
3
+ /**
4
+ * Returns true if passed value is an SDK error of specified type.
5
+ * @param value - value to check.
6
+ * @param type - error type.
7
+ */
8
+ export declare function isSDKErrorOfType(value: unknown, type: ErrorType): boolean;