@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,47 @@
1
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
2
+ import { LaunchParamName, PickLaunchParams } from '../../launch-params/types.js';
3
+ import { CreateRequestIdFn } from '../../request-id/types.js';
4
+ import { StorageKey, StorageValue } from '../../storage/storage.js';
5
+ import { If, IsNever } from '../../types/index.js';
6
+
7
+ /**
8
+ * Object, which supports tracking its state changes.
9
+ */
10
+ export interface WithOnChange<State> {
11
+ on(event: 'change', listener: (state: State) => void): void;
12
+ }
13
+ type LaunchParamsWithState<LP extends LaunchParamName, State> = PickLaunchParams<LP> & If<IsNever<State>, {}, {
14
+ state?: State;
15
+ }>;
16
+ export type SSROptions<LP extends LaunchParamName, State> = LaunchParamsWithState<LP, State>;
17
+ /**
18
+ * Options passed to a component factory.
19
+ */
20
+ export type FactoryOptions<LP extends LaunchParamName, State> = LaunchParamsWithState<LP, State> & {
21
+ postEvent: PostEvent;
22
+ createRequestId: CreateRequestIdFn;
23
+ };
24
+ export interface Factory<LP extends LaunchParamName, R, State> {
25
+ /**
26
+ * Creates new component instance.
27
+ * @param options - factory options.
28
+ */
29
+ (options: FactoryOptions<LP, State>): R;
30
+ }
31
+ export interface FactoryStatic<LP extends LaunchParamName, R> extends Factory<LP, R, never> {
32
+ }
33
+ export interface FactoryDynamic<LP extends LaunchParamName, R, SK extends StorageKey> extends Factory<LP, R, StorageValue<SK>> {
34
+ }
35
+ export interface InitComponentFn<LP extends LaunchParamName, Result, State> {
36
+ /**
37
+ * Initializes new component instance.
38
+ * @param options - initialization options.
39
+ */
40
+ (options?: {
41
+ /**
42
+ * Options, applicable only to SSR mode.
43
+ */
44
+ ssr?: SSROptions<LP, State>;
45
+ }): Result;
46
+ }
47
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Creates resettable singleton. We mostly need it for test purposes.
3
+ * @param create - function which creates singleton entity.
4
+ * @param onReset - function which will be called in case, singleton was reset.
5
+ */
6
+ export declare function createSingleton<T>(create: (reset: () => void) => T, onReset?: (entity: T) => void): [
7
+ /**
8
+ * Returns singleton entity.
9
+ */
10
+ get: () => T,
11
+ /**
12
+ * Resets last stored entity.
13
+ */
14
+ reset: () => void
15
+ ];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates object with specified keys and value.
3
+ * @param keys - object keys.
4
+ * @param value - keys value.
5
+ */
6
+ export declare function objectFromKeys<K extends string, V>(keys: K[], value: V): Record<K, V>;
@@ -0,0 +1,118 @@
1
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
2
+ import { EventEmitter } from '../../events/event-emitter/EventEmitter.js';
3
+ import { BasicNavigatorAnyHistoryItem, BasicNavigatorEvents, BasicNavigatorHistoryItem } from './types.js';
4
+
5
+ type Emitter<Params> = EventEmitter<BasicNavigatorEvents<Params>>;
6
+ export declare class BasicNavigator<Params = {}> {
7
+ /**
8
+ * Currently active history item.
9
+ */
10
+ private _index;
11
+ /**
12
+ * Function to call Mini Apps methods.
13
+ * @default Global `postEvent` function.
14
+ */
15
+ private readonly postEvent;
16
+ /**
17
+ * Navigation history.
18
+ */
19
+ readonly history: Readonly<BasicNavigatorHistoryItem<Params>>[];
20
+ private readonly ee;
21
+ constructor(
22
+ /**
23
+ * Navigation history.
24
+ */
25
+ history: readonly BasicNavigatorAnyHistoryItem<Params>[],
26
+ /**
27
+ * Currently active history item.
28
+ */
29
+ _index: number,
30
+ /**
31
+ * Function to call Mini Apps methods.
32
+ * @default Global `postEvent` function.
33
+ */
34
+ postEvent?: PostEvent);
35
+ /**
36
+ * True, if current navigator is currently attached.
37
+ */
38
+ private attached;
39
+ /**
40
+ * Allows this navigator to control the `BackButton` visibility state. It also tracks the
41
+ * `BackButton` clicks and calls the `back` method.
42
+ */
43
+ attach(): void;
44
+ /**
45
+ * Goes to the previous history item.
46
+ */
47
+ back: () => void;
48
+ /**
49
+ * Currently active history item.
50
+ */
51
+ get current(): Readonly<BasicNavigatorHistoryItem<Params>>;
52
+ /**
53
+ * Prevents current navigator from controlling the BackButton visibility state.
54
+ */
55
+ detach(): void;
56
+ /**
57
+ * Goes to the next history item.
58
+ */
59
+ forward(): void;
60
+ /**
61
+ * Changes currently active history item index by the specified delta. This method doesn't
62
+ * change index in case, the updated index points to the non-existing history item. This behavior
63
+ * is preserved until the `fit` argument is specified.
64
+ * @param delta - index delta.
65
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
66
+ */
67
+ go(delta: number, fit?: boolean): void;
68
+ /**
69
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
70
+ *
71
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
72
+ * bound.
73
+ * @param index - target index.
74
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
75
+ */
76
+ goTo(index: number, fit?: boolean): void;
77
+ /**
78
+ * True if navigator has items before the current item.
79
+ */
80
+ get hasPrev(): boolean;
81
+ /**
82
+ * True if navigator has items after the current item.
83
+ */
84
+ get hasNext(): boolean;
85
+ /**
86
+ * Currently active history item index.
87
+ */
88
+ get index(): number;
89
+ /**
90
+ * Adds new event listener.
91
+ */
92
+ on: Emitter<Params>['on'];
93
+ /**
94
+ * Removes event listener.
95
+ */
96
+ off: Emitter<Params>['off'];
97
+ /**
98
+ * Adds a new history item removing all after the current one.
99
+ * @param item - item to add.
100
+ */
101
+ push(item: BasicNavigatorAnyHistoryItem<Params>): void;
102
+ /**
103
+ * Replaces the current history item.
104
+ * @param item - item to replace the current item with.
105
+ */
106
+ replace(item: BasicNavigatorAnyHistoryItem<Params>): void;
107
+ /**
108
+ * Sets history item by the specified index.
109
+ * @param index - history item index to replace.
110
+ * @param historyItem - history item to set.
111
+ */
112
+ private replaceAndMove;
113
+ /**
114
+ * Actualizes the `BackButton` visibility state.
115
+ */
116
+ private sync;
117
+ }
118
+ export {};
@@ -0,0 +1,8 @@
1
+ import { BasicNavigatorAnyHistoryItem, BasicNavigatorHistoryItem } from './types.js';
2
+
3
+ /**
4
+ * Converts any known history item type to the local one.
5
+ * @param item - history item presented as a string or an object.
6
+ * @param relativePathname - relative pathname.
7
+ */
8
+ export declare function prepareItem<Params>(item: BasicNavigatorAnyHistoryItem<Params>, relativePathname: string): Readonly<BasicNavigatorHistoryItem<Params>>;
@@ -0,0 +1,37 @@
1
+ import { BasicNavigator } from './BasicNavigator.js';
2
+
3
+ /**
4
+ * History item used by the `BasicNavigator`.
5
+ */
6
+ export interface BasicNavigatorHistoryItem<Params> {
7
+ id: string;
8
+ pathname: string;
9
+ params?: Params;
10
+ }
11
+ /**
12
+ * History item used by the `BasicNavigator` methods.
13
+ */
14
+ export type BasicNavigatorAnyHistoryItem<Params> = string | Partial<BasicNavigatorHistoryItem<Params>>;
15
+ /**
16
+ * Events supported by `BasicNavigator`.
17
+ */
18
+ export interface BasicNavigatorEvents<Params> {
19
+ change: {
20
+ /**
21
+ * Navigator instance.
22
+ */
23
+ navigator: BasicNavigator<Params>;
24
+ /**
25
+ * Navigator cursor delta.
26
+ */
27
+ delta: number;
28
+ /**
29
+ * Previous active history item.
30
+ */
31
+ from: BasicNavigatorHistoryItem<Params>;
32
+ /**
33
+ * Currently active history item.
34
+ */
35
+ to: BasicNavigatorHistoryItem<Params>;
36
+ };
37
+ }
@@ -0,0 +1,198 @@
1
+ import { EventEmitter } from '../../events/event-emitter/EventEmitter.js';
2
+ import { BrowserNavigatorAnyHistoryItem, BrowserNavigatorConOptions, BrowserNavigatorEvents, BrowserNavigatorHashMode, BrowserNavigatorHistoryItem, URLLike } from './types.js';
3
+
4
+ type Emitter<State> = EventEmitter<BrowserNavigatorEvents<State>>;
5
+ export declare class BrowserNavigator<State = {}> {
6
+ private readonly navigator;
7
+ private readonly ee;
8
+ readonly hashMode?: BrowserNavigatorHashMode;
9
+ readonly base: string;
10
+ constructor(
11
+ /**
12
+ * Navigation history.
13
+ */
14
+ history: readonly BrowserNavigatorAnyHistoryItem<State>[],
15
+ /**
16
+ * Currently active history item index.
17
+ */
18
+ index: number, { postEvent, hashMode, base }?: BrowserNavigatorConOptions);
19
+ /**
20
+ * Shows whether the navigator is currently attached to the browser history.
21
+ */
22
+ private attached;
23
+ /**
24
+ * Attaches current navigator to the browser history allowing navigator to manipulate it.
25
+ */
26
+ attach(): Promise<void>;
27
+ /**
28
+ * Goes back in history by 1.
29
+ */
30
+ back(): void;
31
+ /**
32
+ * Detaches current navigator from the browser history.
33
+ */
34
+ detach(): void;
35
+ /**
36
+ * Goes forward in history.
37
+ */
38
+ forward(): void;
39
+ /**
40
+ * Current history cursor.
41
+ */
42
+ get index(): number;
43
+ /**
44
+ * Current history item identifier.
45
+ */
46
+ get id(): string;
47
+ /**
48
+ * Changes currently active history item index by the specified delta. This method doesn't
49
+ * change index in case, the updated index points to the non-existing history item. This behavior
50
+ * is preserved until the `fit` argument is specified.
51
+ * @param delta - index delta.
52
+ * @param fit - cuts the delta argument to fit the bounds `[0, history.length - 1]`.
53
+ */
54
+ go(delta: number, fit?: boolean): void;
55
+ /**
56
+ * Goes to the specified index. Method does nothing in case, passed index is out of bounds.
57
+ *
58
+ * If "fit" option was specified and index is out of bounds, it will be cut to the nearest
59
+ * bound.
60
+ * @param index - target index.
61
+ * @param fit - cuts the index argument to fit the bounds `[0, history.length - 1]`.
62
+ */
63
+ goTo(index: number, fit?: boolean): void;
64
+ /**
65
+ * Current history item hash.
66
+ * @see URL.hash
67
+ * @example
68
+ * "", "#my-hash"
69
+ */
70
+ get hash(): string;
71
+ /**
72
+ * True if navigator has items before the current item.
73
+ */
74
+ get hasPrev(): boolean;
75
+ /**
76
+ * True if navigator has items after the current item.
77
+ */
78
+ get hasNext(): boolean;
79
+ /**
80
+ * Navigation history.
81
+ */
82
+ get history(): BrowserNavigatorHistoryItem<State>[];
83
+ /**
84
+ * Handles the window "popstate" event.
85
+ * @param state - event state.
86
+ */
87
+ private onPopState;
88
+ /**
89
+ * Underlying navigator change event listener.
90
+ */
91
+ private onNavigatorChange;
92
+ /**
93
+ * Adds new event listener.
94
+ */
95
+ on: Emitter<State>['on'];
96
+ /**
97
+ * Removes event listener.
98
+ */
99
+ off: Emitter<State>['off'];
100
+ /**
101
+ * Path, including pathname, search and hash.
102
+ * @example Pathname only.
103
+ * "/pathname"
104
+ * @example Pathname + search.
105
+ * "/pathname?search"
106
+ * @example Pathname + hash.
107
+ * "/pathname#hash"
108
+ * @example Pathname + search + hash.
109
+ * "/pathname?search#hash"
110
+ */
111
+ get path(): string;
112
+ /**
113
+ * Current pathname. Always starts with the slash.
114
+ * @see URL.pathname
115
+ * @example
116
+ * "/", "/abc"
117
+ */
118
+ get pathname(): string;
119
+ /**
120
+ * Depending on the current navigation type, parses incoming path and returns it presented as
121
+ * an object. In other words, this method parses the passed path and returns object, describing
122
+ * how the navigator "sees" it.
123
+ *
124
+ * @example Hash mode is omitted.
125
+ * parsePath('/abc?a=1#hash');
126
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
127
+ * parsePath('http://example.com/abc?a=1#hash');
128
+ * // { pathname: '/abc', search: '?a=1', hash: '#hash' }
129
+ *
130
+ * @example Hash mode is enabled.
131
+ * parsePath('/abc?a=1#tma?is=cool#yeah');
132
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
133
+ * parsePath('http://example.com/abc?a=1#tma?is=cool#yeah');
134
+ * // { pathname: '/tma', search: '?is=cool', hash: '#yeah' }
135
+ */
136
+ parsePath(path: string | URL): URLLike;
137
+ /**
138
+ * Pushes new history item. Method replaces all entries after the current one with the one
139
+ * being pushed. Take a note, that passed item is always relative. In case, you want to use
140
+ * it as an absolute one, use the "/" prefix. Example: "/absolute", { pathname: "/absolute" }.
141
+ *
142
+ * To create a final path, navigator uses a method, used in the URL class constructor, resolving
143
+ * a path based on the current one.
144
+ * @param path - entry path.
145
+ * @param state - entry state.
146
+ *
147
+ * @example Pushing an absolute path.
148
+ * push("/absolute"); // "/absolute"
149
+ *
150
+ * @example Pushing a relative path.
151
+ * push("relative"); // "/home/root" -> "/home/relative"
152
+ *
153
+ * @example Pushing query parameters.
154
+ * push("/absolute?my-param=1"); // "/home/root" -> "/absolute?my-param=1"
155
+ * push("relative?my-param=1"); // "/home/root" -> "/home/relative?my-param=1"
156
+ * push("?my-param=1"); // "/home" -> "/home?my-param=1"
157
+ *
158
+ * @example Pushing hash.
159
+ * push("#my-hash"); // "/home" -> "/home#my-hash"
160
+ * push("relative#my-hash"); // "/home/root" -> "/home/relative#my-hash"
161
+ *
162
+ * @example Pushing state.
163
+ * push("", { state: 'my-state' }); "/home/root" -> "/home/root"
164
+ * push({ state: 'my-state' }); "/home/root" -> "/home/root"
165
+ */
166
+ push(path: string, state?: State): void;
167
+ push(item: BrowserNavigatorAnyHistoryItem<State>): void;
168
+ /**
169
+ * Replaces the current history item. Has the same logic as the `push` method.
170
+ * @param path - entry path.
171
+ * @param state - entry state.
172
+ * @see push
173
+ */
174
+ replace(path: string, state?: State): void;
175
+ replace(item: BrowserNavigatorAnyHistoryItem<State>): void;
176
+ /**
177
+ * Combines the navigator `base` property with the passed path data applying the navigator
178
+ * navigation mode.
179
+ * @param value - path presented as string or URLLike.
180
+ */
181
+ renderPath(value: string | URLLike): string;
182
+ /**
183
+ * Synchronizes current navigator state with browser history.
184
+ */
185
+ private syncHistory;
186
+ /**
187
+ * Current query parameters.
188
+ * @see URL.search
189
+ * @example
190
+ * "", "?", "?a=1"
191
+ */
192
+ get search(): string;
193
+ /**
194
+ * Current history item state.
195
+ */
196
+ get state(): State | undefined;
197
+ }
198
+ export {};
@@ -0,0 +1,7 @@
1
+ import { BasicNavigatorHistoryItem } from '../BasicNavigator/types.js';
2
+ import { BrowserNavigatorHistoryItem, BrowserNavigatorHistoryItemParams } from './types.js';
3
+
4
+ /**
5
+ * Converts basic navigator entry to browser navigator entry.
6
+ */
7
+ export declare function basicItemToBrowser<State>({ params, ...rest }: BasicNavigatorHistoryItem<BrowserNavigatorHistoryItemParams<State>>): BrowserNavigatorHistoryItem<State>;
@@ -0,0 +1,4 @@
1
+ import { BrowserNavigator } from './BrowserNavigator.js';
2
+ import { BrowserNavigatorConOptions } from './types.js';
3
+
4
+ export declare function createBrowserNavigatorFromLocation<State>(options?: BrowserNavigatorConOptions): BrowserNavigator<State>;
@@ -0,0 +1,25 @@
1
+ import { BrowserNavigatorAnyHistoryItem } from './types.js';
2
+
3
+ interface PrepareItemResult<State> {
4
+ id?: string;
5
+ pathname: string;
6
+ params: {
7
+ hash: string;
8
+ search: string;
9
+ state?: State;
10
+ };
11
+ }
12
+ /**
13
+ * Converts a path, presented as a string to a basic navigator appropriate form.
14
+ * @param path - full path.
15
+ * @param relativePath - relative path.
16
+ * @param state - history item state.
17
+ */
18
+ export declare function prepareItem<State>(path: string, relativePath: string, state?: State): PrepareItemResult<State>;
19
+ /**
20
+ * Converts a path, presented as an object to a basic navigator appropriate form.
21
+ * @param item - history item data.
22
+ * @param relativePath - relative path.
23
+ */
24
+ export declare function prepareItem<State>(item: BrowserNavigatorAnyHistoryItem<State>, relativePath: string): PrepareItemResult<State>;
25
+ export {};
@@ -0,0 +1,63 @@
1
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
2
+ import { BrowserNavigator } from './BrowserNavigator.js';
3
+
4
+ /**
5
+ * Minimal set of properties we are working with in this library.
6
+ */
7
+ export interface URLLike extends Pick<URL, 'pathname' | 'search' | 'hash'> {
8
+ }
9
+ export interface BrowserNavigatorConOptions {
10
+ /**
11
+ * Base navigator URL.
12
+ * @default ""
13
+ */
14
+ base?: string;
15
+ /**
16
+ * Hash navigation mode. Omit, if non-hash mode is required.
17
+ */
18
+ hashMode?: BrowserNavigatorHashMode;
19
+ /**
20
+ * Function to call Mini Apps methods.
21
+ * @default Global postEvent function.
22
+ */
23
+ postEvent?: PostEvent;
24
+ }
25
+ export interface BrowserNavigatorHistoryItemParams<State> extends Pick<URLLike, 'search' | 'hash'> {
26
+ state?: State;
27
+ }
28
+ export interface BrowserNavigatorHistoryItem<State> extends URLLike {
29
+ id: string;
30
+ state?: State;
31
+ }
32
+ export type BrowserNavigatorAnyHistoryItem<State> = string | Partial<BrowserNavigatorHistoryItem<State>>;
33
+ /**
34
+ * Hash navigation mode.
35
+ * @example 'default'
36
+ * '#pathname?search'
37
+ * @example 'slash'
38
+ * '#/pathname?search'
39
+ */
40
+ export type BrowserNavigatorHashMode = 'default' | 'slash';
41
+ /**
42
+ * Events supported by `BrowserNavigator`.
43
+ */
44
+ export interface BrowserNavigatorEvents<State> {
45
+ change: {
46
+ /**
47
+ * Navigator instance.
48
+ */
49
+ navigator: BrowserNavigator<State>;
50
+ /**
51
+ * Navigator cursor delta.
52
+ */
53
+ delta: number;
54
+ /**
55
+ * Previous active history item.
56
+ */
57
+ from: BrowserNavigatorHistoryItem<State>;
58
+ /**
59
+ * Currently active history item.
60
+ */
61
+ to: BrowserNavigatorHistoryItem<State>;
62
+ };
63
+ }
@@ -0,0 +1,7 @@
1
+ import { URLLike } from './BrowserNavigator/types.js';
2
+
3
+ /**
4
+ * Safely creates new instance of URL with some predefined protocol and hostname.
5
+ * @param urlOrPath - URL instance or path.
6
+ */
7
+ export declare function createSafeURL(urlOrPath: string | Partial<URLLike>): URL;
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Returns string after first met "#" symbol.
3
2
  * @param value - string to take hash part from.
3
+ * @returns String after the first met "#" symbol. In case, value doesn't contain hashtag, the
4
+ * function will return null.
4
5
  *
5
6
  * @example No hash.
6
7
  * getHash('/path'); // null
@@ -0,0 +1,7 @@
1
+ import { URLLike } from './BrowserNavigator/types.js';
2
+
3
+ /**
4
+ * Extracts pathname from the value.
5
+ * @param value - source value.
6
+ */
7
+ export declare function getPathname(value: string | Partial<URLLike>): string;
@@ -0,0 +1,9 @@
1
+ import { BrowserNavigatorConOptions } from './BrowserNavigator/types.js';
2
+ import { BrowserNavigator } from './BrowserNavigator/BrowserNavigator.js';
3
+
4
+ /**
5
+ * Initializes a standard Mini Apps navigator.
6
+ * @param sessionStorageKey - session storage key, containing the navigator state.
7
+ * @param options - additional BrowserNavigator options.
8
+ */
9
+ export declare function initNavigator<State>(sessionStorageKey: string, options?: BrowserNavigatorConOptions): BrowserNavigator<State>;
@@ -0,0 +1,7 @@
1
+ import { URLLike } from './BrowserNavigator/types.js';
2
+
3
+ /**
4
+ * Extracts path part from a URL.
5
+ * @param urlOrPath - URL instance or path.
6
+ */
7
+ export declare function urlToPath(urlOrPath: string | Partial<URLLike>): string;
@@ -0,0 +1,17 @@
1
+ import { ValueParser } from '../ValueParser/ValueParser.js';
2
+ import { ArrayParserOfResult } from '../ArrayParser/types.js';
3
+ import { AnyParser } from '../types.js';
4
+ import { ValueParserParseResult } from '../ValueParser/types.js';
5
+
6
+ export declare class ArrayParser<ItemType, IsOptional extends boolean> extends ValueParser<unknown[], IsOptional> {
7
+ private itemParser;
8
+ constructor(itemParser: AnyParser<ItemType>, isOptional: IsOptional, type?: string);
9
+ /**
10
+ * Attempts to parse passed value
11
+ * @param value - value to parse.
12
+ * @throws {SDKError} ERR_PARSE
13
+ * @see ERR_PARSE
14
+ */
15
+ parse(value: unknown): ValueParserParseResult<ItemType[], IsOptional>;
16
+ of<Item>(itemParser: AnyParser<Item>): ArrayParserOfResult<this, Item, IsOptional>;
17
+ }
@@ -0,0 +1,12 @@
1
+ import { AnyParser } from '../types.js';
2
+ import { ValueParserOverrides } from '../ValueParser/types.js';
3
+
4
+ export type ArrayParserOfResult<BaseClass, ItemType, IsOptional extends boolean> = ArrayParserType<BaseClass, ItemType, IsOptional>;
5
+ export interface ArrayParserOverrides<BaseClass, ItemType, IsOptional extends boolean> extends ValueParserOverrides<BaseClass, ItemType[], IsOptional> {
6
+ /**
7
+ * Specifies parser for each array item.
8
+ * @param parser - item parser.
9
+ */
10
+ of<Item>(parser: AnyParser<Item>): ArrayParserOfResult<BaseClass, Item, IsOptional>;
11
+ }
12
+ export type ArrayParserType<BaseClass, ItemType, IsOptional extends boolean> = Omit<BaseClass, keyof ArrayParserOverrides<any, any, any>> & ArrayParserOverrides<BaseClass, ItemType, IsOptional>;
@@ -0,0 +1,17 @@
1
+ import { Parser } from '../types.js';
2
+ import { ValueParserOptionalResult, ValueParserParseResult } from './types.js';
3
+
4
+ export declare class ValueParser<ResultType, IsOptional extends boolean> {
5
+ protected parser: Parser<ResultType>;
6
+ protected isOptional: IsOptional;
7
+ protected type?: string | undefined;
8
+ constructor(parser: Parser<ResultType>, isOptional: IsOptional, type?: string | undefined);
9
+ /**
10
+ * Attempts to parse passed value
11
+ * @param value - value to parse.
12
+ * @throws {SDKError} ERR_PARSE
13
+ * @see ERR_PARSE
14
+ */
15
+ parse(value: unknown): ValueParserParseResult<ResultType, IsOptional>;
16
+ optional(): ValueParserOptionalResult<this, ResultType>;
17
+ }