@tma.js/sdk 0.13.3 → 1.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 (426) hide show
  1. package/dist/dts/{components/BackButton → back-button}/BackButton.d.ts +12 -9
  2. package/dist/dts/back-button/index.d.ts +2 -0
  3. package/dist/dts/{components/BackButton → back-button}/types.d.ts +3 -2
  4. package/dist/dts/bridge/env/hasExternalNotify.d.ts +12 -0
  5. package/dist/dts/bridge/env/hasWebviewProxy.d.ts +12 -0
  6. package/dist/dts/bridge/env/index.d.ts +3 -0
  7. package/dist/dts/bridge/env/isIframe.d.ts +5 -0
  8. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +8 -0
  9. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +8 -0
  10. package/dist/dts/bridge/errors/index.d.ts +2 -0
  11. package/dist/dts/bridge/events/createEmitter.d.ts +6 -0
  12. package/dist/dts/bridge/events/events.d.ts +130 -0
  13. package/dist/dts/bridge/events/index.d.ts +9 -0
  14. package/dist/dts/bridge/events/off.d.ts +7 -0
  15. package/dist/dts/bridge/events/on.d.ts +10 -0
  16. package/dist/dts/bridge/events/onTelegramEvent.d.ts +7 -0
  17. package/dist/dts/bridge/events/once.d.ts +9 -0
  18. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +13 -0
  19. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +16 -0
  20. package/dist/dts/bridge/events/parsers/index.d.ts +9 -0
  21. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +12 -0
  22. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +8 -0
  23. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +8 -0
  24. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +7 -0
  25. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +42 -0
  26. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +19 -0
  27. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +8 -0
  28. package/dist/dts/bridge/events/singletonEmitter.d.ts +6 -0
  29. package/dist/dts/bridge/events/subscribe.d.ts +9 -0
  30. package/dist/dts/bridge/events/unsubscribe.d.ts +6 -0
  31. package/dist/dts/bridge/index.d.ts +5 -0
  32. package/dist/dts/bridge/methods/createPostEvent.d.ts +10 -0
  33. package/dist/dts/bridge/methods/haptic.d.ts +40 -0
  34. package/dist/dts/bridge/methods/index.d.ts +6 -0
  35. package/dist/dts/bridge/methods/invoke-custom-method.d.ts +24 -0
  36. package/dist/dts/bridge/methods/methods.d.ts +329 -0
  37. package/dist/dts/bridge/methods/popup.d.ts +49 -0
  38. package/dist/dts/bridge/methods/postEvent.d.ts +29 -0
  39. package/dist/dts/bridge/request.d.ts +65 -0
  40. package/dist/dts/classnames/classNames.d.ts +10 -0
  41. package/dist/dts/classnames/index.d.ts +2 -0
  42. package/dist/dts/classnames/mergeClassNames.d.ts +32 -0
  43. package/dist/dts/{components/ClosingBehaviour/ClosingBehaviour.d.ts → closing-behavior/ClosingBehavior.d.ts} +5 -4
  44. package/dist/dts/closing-behavior/index.d.ts +2 -0
  45. package/dist/dts/closing-behavior/types.d.ts +7 -0
  46. package/dist/dts/{components/CloudStorage → cloud-storage}/CloudStorage.d.ts +19 -11
  47. package/dist/dts/colors/index.d.ts +5 -0
  48. package/dist/dts/colors/isColorDark.d.ts +6 -0
  49. package/dist/dts/colors/isRGB.d.ts +6 -0
  50. package/dist/dts/colors/isRGBShort.d.ts +6 -0
  51. package/dist/dts/colors/toRGB.d.ts +11 -0
  52. package/dist/dts/colors/types.d.ts +8 -0
  53. package/dist/dts/event-emitter/EventEmitter.d.ts +64 -0
  54. package/dist/dts/event-emitter/index.d.ts +2 -0
  55. package/dist/dts/event-emitter/types.d.ts +44 -0
  56. package/dist/dts/globals.d.ts +22 -0
  57. package/dist/dts/{components/HapticFeedback → haptic-feedback}/HapticFeedback.d.ts +3 -3
  58. package/dist/dts/index.d.ts +24 -6
  59. package/dist/dts/init/catchCustomStyles.d.ts +4 -0
  60. package/dist/dts/init/creators/createBackButton.d.ts +2 -2
  61. package/dist/dts/init/creators/createClosingBehavior.d.ts +3 -3
  62. package/dist/dts/init/creators/createMainButton.d.ts +3 -3
  63. package/dist/dts/init/creators/createMiniApp.d.ts +14 -0
  64. package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
  65. package/dist/dts/init/creators/createThemeParams.d.ts +2 -3
  66. package/dist/dts/init/creators/createViewport.d.ts +16 -9
  67. package/dist/dts/init/creators/index.d.ts +1 -1
  68. package/dist/dts/init/css/bindMiniAppCSSVars.d.ts +16 -0
  69. package/dist/dts/init/css/bindThemeCSSVars.d.ts +12 -0
  70. package/dist/dts/init/css/bindViewportCSSVars.d.ts +20 -0
  71. package/dist/dts/init/css/index.d.ts +1 -0
  72. package/dist/dts/init/css/processCSSVarsOption.d.ts +12 -0
  73. package/dist/dts/init/css/setCSSVar.d.ts +6 -0
  74. package/dist/dts/init/init.d.ts +5 -5
  75. package/dist/dts/init/types.d.ts +42 -69
  76. package/dist/dts/init-data/InitData.d.ts +53 -0
  77. package/dist/dts/init-data/chatParser.d.ts +5 -0
  78. package/dist/dts/init-data/index.d.ts +6 -0
  79. package/dist/dts/init-data/initDataParser.d.ts +5 -0
  80. package/dist/dts/init-data/parseInitData.d.ts +6 -0
  81. package/dist/dts/init-data/types.d.ts +133 -0
  82. package/dist/dts/init-data/userParser.d.ts +5 -0
  83. package/dist/dts/invoice/Invoice.d.ts +43 -0
  84. package/dist/dts/invoice/index.d.ts +2 -0
  85. package/dist/dts/invoice/types.d.ts +7 -0
  86. package/dist/dts/launch-params/computeLaunchData.d.ts +6 -0
  87. package/dist/dts/launch-params/computePageReload.d.ts +6 -0
  88. package/dist/dts/launch-params/getFirstNavigationEntry.d.ts +6 -0
  89. package/dist/dts/launch-params/index.d.ts +12 -0
  90. package/dist/dts/launch-params/launchParamsParser.d.ts +5 -0
  91. package/dist/dts/launch-params/parseLaunchParams.d.ts +6 -0
  92. package/dist/dts/launch-params/retrieveCurrent.d.ts +5 -0
  93. package/dist/dts/launch-params/retrieveFromLocation.d.ts +6 -0
  94. package/dist/dts/launch-params/retrieveFromPerformance.d.ts +8 -0
  95. package/dist/dts/launch-params/retrieveLaunchData.d.ts +6 -0
  96. package/dist/dts/launch-params/serializeLaunchParams.d.ts +6 -0
  97. package/dist/dts/launch-params/storage.d.ts +13 -0
  98. package/dist/dts/launch-params/types.d.ts +48 -0
  99. package/dist/dts/logger/Logger.d.ts +38 -0
  100. package/dist/dts/logger/index.d.ts +1 -0
  101. package/dist/dts/main-button/MainButton.d.ts +104 -0
  102. package/dist/dts/main-button/index.d.ts +2 -0
  103. package/dist/dts/main-button/types.d.ts +20 -0
  104. package/dist/dts/mini-app/MiniApp.d.ts +99 -0
  105. package/dist/dts/mini-app/index.d.ts +2 -0
  106. package/dist/dts/mini-app/types.d.ts +19 -0
  107. package/dist/dts/misc/index.d.ts +2 -0
  108. package/dist/dts/misc/isRecord.d.ts +5 -0
  109. package/dist/dts/misc/isTMA.d.ts +4 -0
  110. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +43 -0
  111. package/dist/dts/navigation/HashNavigator/drop.d.ts +4 -0
  112. package/dist/dts/navigation/HashNavigator/go.d.ts +5 -0
  113. package/dist/dts/navigation/HashNavigator/index.d.ts +2 -0
  114. package/dist/dts/navigation/HashNavigator/types.d.ts +34 -0
  115. package/dist/dts/navigation/Navigator/Navigator.d.ts +104 -0
  116. package/dist/dts/navigation/Navigator/index.d.ts +2 -0
  117. package/dist/dts/navigation/Navigator/types.d.ts +44 -0
  118. package/dist/dts/navigation/ensurePrefix.d.ts +7 -0
  119. package/dist/dts/navigation/getHash.d.ts +14 -0
  120. package/dist/dts/navigation/index.d.ts +4 -0
  121. package/dist/dts/parsing/ArrayValueParser.d.ts +18 -0
  122. package/dist/dts/parsing/ParseError.d.ts +22 -0
  123. package/dist/dts/parsing/ParseSchemaFieldError.d.ts +17 -0
  124. package/dist/dts/parsing/ValueParser.d.ts +36 -0
  125. package/dist/dts/parsing/createValueParserGenerator.d.ts +9 -0
  126. package/dist/dts/parsing/index.d.ts +10 -0
  127. package/dist/dts/parsing/parseBySchema.d.ts +8 -0
  128. package/dist/dts/parsing/parsers/array.d.ts +6 -0
  129. package/dist/dts/parsing/parsers/boolean.d.ts +4 -0
  130. package/dist/dts/parsing/parsers/date.d.ts +4 -0
  131. package/dist/dts/parsing/parsers/index.d.ts +8 -0
  132. package/dist/dts/parsing/parsers/json.d.ts +8 -0
  133. package/dist/dts/parsing/parsers/number.d.ts +4 -0
  134. package/dist/dts/parsing/parsers/rgb.d.ts +4 -0
  135. package/dist/dts/parsing/parsers/searchParams.d.ts +8 -0
  136. package/dist/dts/parsing/parsers/string.d.ts +4 -0
  137. package/dist/dts/parsing/toRecord.d.ts +7 -0
  138. package/dist/dts/parsing/types.d.ts +30 -0
  139. package/dist/dts/parsing/unexpectedTypeError.d.ts +4 -0
  140. package/dist/dts/{components/Popup → popup}/Popup.d.ts +10 -9
  141. package/dist/dts/popup/index.d.ts +2 -0
  142. package/dist/dts/popup/preparePopupParams.d.ts +7 -0
  143. package/dist/dts/{components/Popup → popup}/types.d.ts +4 -4
  144. package/dist/dts/{components/QRScanner → qr-scanner}/QRScanner.d.ts +6 -5
  145. package/dist/dts/qr-scanner/index.d.ts +2 -0
  146. package/dist/dts/{components/QRScanner → qr-scanner}/types.d.ts +1 -1
  147. package/dist/dts/state/State.d.ts +19 -7
  148. package/dist/dts/state/types.d.ts +4 -7
  149. package/dist/dts/storage.d.ts +4 -4
  150. package/dist/dts/supports/createSupportsFunc.d.ts +10 -0
  151. package/dist/dts/supports/createSupportsParamFunc.d.ts +15 -0
  152. package/dist/dts/supports/index.d.ts +4 -0
  153. package/dist/dts/supports/supports.d.ts +15 -0
  154. package/dist/dts/supports/types.d.ts +1 -0
  155. package/dist/dts/theme-params/ThemeParams.d.ts +62 -0
  156. package/dist/dts/theme-params/index.d.ts +6 -0
  157. package/dist/dts/theme-params/keys.d.ts +11 -0
  158. package/dist/dts/theme-params/parseThemeParams.d.ts +6 -0
  159. package/dist/dts/theme-params/requestThemeParams.d.ts +7 -0
  160. package/dist/dts/theme-params/serializeThemeParams.d.ts +5 -0
  161. package/dist/dts/theme-params/themeParamsParser.d.ts +2 -0
  162. package/dist/dts/theme-params/types.d.ts +14 -0
  163. package/dist/dts/timeout/TimeoutError.d.ts +3 -0
  164. package/dist/dts/timeout/index.d.ts +3 -0
  165. package/dist/dts/timeout/isTimeoutError.d.ts +6 -0
  166. package/dist/dts/timeout/withTimeout.d.ts +14 -0
  167. package/dist/dts/types/index.d.ts +3 -0
  168. package/dist/dts/types/platform.d.ts +4 -0
  169. package/dist/dts/types/request-id.d.ts +9 -0
  170. package/dist/dts/types/utils.d.ts +36 -0
  171. package/dist/dts/utils/Utils.d.ts +45 -0
  172. package/dist/dts/utils/index.d.ts +1 -0
  173. package/dist/dts/version/compareVersions.d.ts +8 -0
  174. package/dist/dts/version/index.d.ts +2 -0
  175. package/dist/dts/version/types.d.ts +4 -0
  176. package/dist/dts/{components/Viewport → viewport}/Viewport.d.ts +16 -38
  177. package/dist/dts/viewport/index.d.ts +3 -0
  178. package/dist/dts/viewport/requestViewport.d.ts +12 -0
  179. package/dist/dts/{components/Viewport → viewport}/types.d.ts +9 -1
  180. package/dist/dts/viewport/utils.d.ts +5 -0
  181. package/dist/index.cjs +1 -1
  182. package/dist/index.cjs.map +1 -1
  183. package/dist/index.iife.js +1 -1
  184. package/dist/index.iife.js.map +1 -1
  185. package/dist/index.mjs +2254 -1027
  186. package/dist/index.mjs.map +1 -1
  187. package/package.json +7 -16
  188. package/src/{components/BackButton → back-button}/BackButton.ts +23 -21
  189. package/src/back-button/index.ts +2 -0
  190. package/src/{components/BackButton → back-button}/types.ts +3 -2
  191. package/src/bridge/env/hasExternalNotify.ts +19 -0
  192. package/src/bridge/env/hasWebviewProxy.ts +19 -0
  193. package/src/bridge/env/index.ts +3 -0
  194. package/src/bridge/env/isIframe.ts +11 -0
  195. package/src/bridge/errors/MethodUnsupportedError.ts +13 -0
  196. package/src/bridge/errors/ParameterUnsupportedError.ts +13 -0
  197. package/src/bridge/errors/index.ts +2 -0
  198. package/src/bridge/events/createEmitter.ts +108 -0
  199. package/src/bridge/events/events.ts +170 -0
  200. package/src/bridge/events/index.ts +9 -0
  201. package/src/bridge/events/off.ts +14 -0
  202. package/src/bridge/events/on.ts +19 -0
  203. package/src/bridge/events/onTelegramEvent.ts +83 -0
  204. package/src/bridge/events/once.ts +18 -0
  205. package/src/bridge/events/parsers/clipboardTextReceived.ts +26 -0
  206. package/src/bridge/events/parsers/customMethodInvoked.ts +25 -0
  207. package/src/bridge/events/parsers/index.ts +9 -0
  208. package/src/bridge/events/parsers/invoiceClosed.ts +26 -0
  209. package/src/bridge/events/parsers/phoneRequested.ts +14 -0
  210. package/src/bridge/events/parsers/popupClosed.ts +19 -0
  211. package/src/bridge/events/parsers/qrTextReceived.ts +14 -0
  212. package/src/bridge/events/parsers/theme-changed.ts +58 -0
  213. package/src/bridge/events/parsers/viewportChanged.ts +33 -0
  214. package/src/bridge/events/parsers/writeAccessRequested.ts +14 -0
  215. package/src/bridge/events/singletonEmitter.ts +19 -0
  216. package/src/bridge/events/subscribe.ts +15 -0
  217. package/src/bridge/events/unsubscribe.ts +10 -0
  218. package/src/bridge/index.ts +5 -0
  219. package/src/bridge/methods/createPostEvent.ts +40 -0
  220. package/src/bridge/methods/haptic.ts +52 -0
  221. package/src/bridge/methods/index.ts +6 -0
  222. package/src/bridge/methods/invoke-custom-method.ts +25 -0
  223. package/src/bridge/methods/methods.ts +372 -0
  224. package/src/bridge/methods/popup.ts +53 -0
  225. package/src/bridge/methods/postEvent.ts +101 -0
  226. package/src/bridge/request.ts +185 -0
  227. package/src/classnames/classNames.ts +34 -0
  228. package/src/classnames/index.ts +2 -0
  229. package/src/classnames/mergeClassNames.ts +68 -0
  230. package/src/{components/ClosingBehaviour/ClosingBehaviour.ts → closing-behavior/ClosingBehavior.ts} +12 -10
  231. package/src/closing-behavior/index.ts +2 -0
  232. package/src/closing-behavior/types.ts +12 -0
  233. package/src/{components/CloudStorage → cloud-storage}/CloudStorage.ts +50 -28
  234. package/src/colors/index.ts +5 -0
  235. package/src/colors/isColorDark.ts +22 -0
  236. package/src/colors/isRGB.ts +9 -0
  237. package/src/colors/isRGBShort.ts +9 -0
  238. package/src/colors/toRGB.ts +49 -0
  239. package/src/colors/types.ts +9 -0
  240. package/src/event-emitter/EventEmitter.ts +146 -0
  241. package/src/event-emitter/index.ts +2 -0
  242. package/src/event-emitter/types.ts +60 -0
  243. package/src/globals.ts +38 -0
  244. package/src/{components/HapticFeedback → haptic-feedback}/HapticFeedback.ts +16 -8
  245. package/src/index.ts +171 -6
  246. package/src/init/catchCustomStyles.ts +17 -0
  247. package/src/init/creators/createBackButton.ts +4 -6
  248. package/src/init/creators/createClosingBehavior.ts +6 -8
  249. package/src/init/creators/createMainButton.ts +13 -20
  250. package/src/init/creators/createMiniApp.ts +44 -0
  251. package/src/init/creators/createRequestIdGenerator.ts +1 -1
  252. package/src/init/creators/createThemeParams.ts +3 -6
  253. package/src/init/creators/createViewport.ts +92 -42
  254. package/src/init/creators/index.ts +1 -1
  255. package/src/init/css/bindMiniAppCSSVars.ts +48 -0
  256. package/src/init/css/bindThemeCSSVars.ts +31 -0
  257. package/src/init/css/bindViewportCSSVars.ts +36 -0
  258. package/src/init/css/index.ts +1 -0
  259. package/src/init/css/processCSSVarsOption.ts +57 -0
  260. package/src/init/css/setCSSVar.ts +8 -0
  261. package/src/init/init.ts +119 -154
  262. package/src/init/types.ts +42 -87
  263. package/src/init-data/InitData.ts +96 -0
  264. package/src/init-data/chatParser.ts +19 -0
  265. package/src/init-data/index.ts +6 -0
  266. package/src/init-data/initDataParser.ts +41 -0
  267. package/src/init-data/parseInitData.ts +10 -0
  268. package/src/init-data/types.ts +164 -0
  269. package/src/init-data/userParser.ts +45 -0
  270. package/src/invoice/Invoice.ts +123 -0
  271. package/src/invoice/index.ts +2 -0
  272. package/src/invoice/types.ts +11 -0
  273. package/src/launch-params/computeLaunchData.ts +81 -0
  274. package/src/launch-params/computePageReload.ts +13 -0
  275. package/src/launch-params/getFirstNavigationEntry.ts +10 -0
  276. package/src/launch-params/index.ts +12 -0
  277. package/src/launch-params/launchParamsParser.ts +41 -0
  278. package/src/launch-params/parseLaunchParams.ts +10 -0
  279. package/src/launch-params/retrieveCurrent.ts +27 -0
  280. package/src/launch-params/retrieveFromLocation.ts +10 -0
  281. package/src/launch-params/retrieveFromPerformance.ts +23 -0
  282. package/src/launch-params/retrieveLaunchData.ts +30 -0
  283. package/src/launch-params/serializeLaunchParams.ts +37 -0
  284. package/src/launch-params/storage.ts +33 -0
  285. package/src/launch-params/types.ts +57 -0
  286. package/src/logger/Logger.ts +72 -0
  287. package/src/logger/index.ts +1 -0
  288. package/src/main-button/MainButton.ts +239 -0
  289. package/src/main-button/index.ts +2 -0
  290. package/src/main-button/types.ts +26 -0
  291. package/src/mini-app/MiniApp.ts +237 -0
  292. package/src/mini-app/index.ts +2 -0
  293. package/src/mini-app/types.ts +25 -0
  294. package/src/misc/index.ts +2 -0
  295. package/src/misc/isRecord.ts +7 -0
  296. package/src/misc/isTMA.ts +13 -0
  297. package/src/navigation/HashNavigator/HashNavigator.ts +220 -0
  298. package/src/navigation/HashNavigator/drop.ts +36 -0
  299. package/src/navigation/HashNavigator/go.ts +28 -0
  300. package/src/navigation/HashNavigator/index.ts +2 -0
  301. package/src/navigation/HashNavigator/types.ts +41 -0
  302. package/src/navigation/Navigator/Navigator.ts +282 -0
  303. package/src/navigation/Navigator/index.ts +2 -0
  304. package/src/navigation/Navigator/types.ts +55 -0
  305. package/src/navigation/ensurePrefix.ts +9 -0
  306. package/src/navigation/getHash.ts +17 -0
  307. package/src/navigation/index.ts +4 -0
  308. package/src/parsing/ArrayValueParser.ts +79 -0
  309. package/src/parsing/ParseError.ts +27 -0
  310. package/src/parsing/ParseSchemaFieldError.ts +21 -0
  311. package/src/parsing/ValueParser.ts +71 -0
  312. package/src/parsing/createValueParserGenerator.ts +16 -0
  313. package/src/parsing/index.ts +10 -0
  314. package/src/parsing/parseBySchema.ts +65 -0
  315. package/src/parsing/parsers/array.ts +9 -0
  316. package/src/parsing/parsers/boolean.ts +22 -0
  317. package/src/parsing/parsers/date.ts +13 -0
  318. package/src/parsing/parsers/index.ts +8 -0
  319. package/src/parsing/parsers/json.ts +17 -0
  320. package/src/parsing/parsers/number.ts +21 -0
  321. package/src/parsing/parsers/rgb.ts +12 -0
  322. package/src/parsing/parsers/searchParams.ts +24 -0
  323. package/src/parsing/parsers/string.ts +12 -0
  324. package/src/parsing/toRecord.ts +27 -0
  325. package/src/parsing/types.ts +32 -0
  326. package/src/parsing/unexpectedTypeError.ts +6 -0
  327. package/src/{components/Popup → popup}/Popup.ts +38 -28
  328. package/src/popup/index.ts +2 -0
  329. package/src/{components/Popup/utils.ts → popup/preparePopupParams.ts} +3 -3
  330. package/src/{components/Popup → popup}/types.ts +4 -4
  331. package/src/{components/QRScanner → qr-scanner}/QRScanner.ts +18 -10
  332. package/src/qr-scanner/index.ts +2 -0
  333. package/src/{components/QRScanner → qr-scanner}/types.ts +1 -1
  334. package/src/state/State.ts +31 -21
  335. package/src/state/types.ts +5 -8
  336. package/src/storage.ts +6 -4
  337. package/src/supports/createSupportsFunc.ts +18 -0
  338. package/src/supports/createSupportsParamFunc.ts +27 -0
  339. package/src/supports/index.ts +4 -0
  340. package/src/supports/supports.ts +84 -0
  341. package/src/supports/types.ts +1 -0
  342. package/src/theme-params/ThemeParams.ts +131 -0
  343. package/src/theme-params/index.ts +6 -0
  344. package/src/theme-params/keys.ts +24 -0
  345. package/src/theme-params/parseThemeParams.ts +10 -0
  346. package/src/theme-params/requestThemeParams.ts +13 -0
  347. package/src/theme-params/serializeThemeParams.ts +20 -0
  348. package/src/theme-params/themeParamsParser.ts +20 -0
  349. package/src/theme-params/types.ts +33 -0
  350. package/src/timeout/TimeoutError.ts +6 -0
  351. package/src/timeout/index.ts +3 -0
  352. package/src/timeout/isTimeoutError.ts +9 -0
  353. package/src/timeout/withTimeout.ts +36 -0
  354. package/src/types/index.ts +3 -0
  355. package/src/types/platform.ts +14 -0
  356. package/src/types/request-id.ts +10 -0
  357. package/src/types/utils.ts +50 -0
  358. package/src/utils/Utils.ts +107 -0
  359. package/src/utils/index.ts +1 -0
  360. package/src/version/compareVersions.ts +28 -0
  361. package/src/version/index.ts +2 -0
  362. package/src/version/types.ts +4 -0
  363. package/src/{components/Viewport → viewport}/Viewport.ts +72 -98
  364. package/src/viewport/index.ts +3 -0
  365. package/src/viewport/requestViewport.ts +23 -0
  366. package/src/{components/Viewport → viewport}/types.ts +10 -1
  367. package/src/viewport/utils.ts +7 -0
  368. package/dist/dts/components/BackButton/index.d.ts +0 -2
  369. package/dist/dts/components/ClosingBehaviour/index.d.ts +0 -2
  370. package/dist/dts/components/ClosingBehaviour/types.d.ts +0 -7
  371. package/dist/dts/components/InitData/InitData.d.ts +0 -60
  372. package/dist/dts/components/InitData/index.d.ts +0 -1
  373. package/dist/dts/components/MainButton/MainButton.d.ts +0 -114
  374. package/dist/dts/components/MainButton/index.d.ts +0 -2
  375. package/dist/dts/components/MainButton/types.d.ts +0 -15
  376. package/dist/dts/components/Popup/index.d.ts +0 -2
  377. package/dist/dts/components/Popup/utils.d.ts +0 -7
  378. package/dist/dts/components/QRScanner/index.d.ts +0 -2
  379. package/dist/dts/components/ThemeParams/ThemeParams.d.ts +0 -85
  380. package/dist/dts/components/ThemeParams/index.d.ts +0 -2
  381. package/dist/dts/components/ThemeParams/types.d.ts +0 -6
  382. package/dist/dts/components/Viewport/index.d.ts +0 -2
  383. package/dist/dts/components/WebApp/WebApp.d.ts +0 -146
  384. package/dist/dts/components/WebApp/index.d.ts +0 -2
  385. package/dist/dts/components/WebApp/types.d.ts +0 -11
  386. package/dist/dts/components/index.d.ts +0 -11
  387. package/dist/dts/env.d.ts +0 -10
  388. package/dist/dts/errors/MethodNotSupportedError.d.ts +0 -6
  389. package/dist/dts/errors/ParameterNotSupportedError.d.ts +0 -6
  390. package/dist/dts/errors/index.d.ts +0 -2
  391. package/dist/dts/init/creators/createWebApp.d.ts +0 -16
  392. package/dist/dts/init/css.d.ts +0 -50
  393. package/dist/dts/supports.d.ts +0 -22
  394. package/dist/dts/types.d.ts +0 -10
  395. package/dist/dts/url.d.ts +0 -7
  396. package/src/components/BackButton/index.ts +0 -2
  397. package/src/components/ClosingBehaviour/index.ts +0 -6
  398. package/src/components/ClosingBehaviour/types.ts +0 -12
  399. package/src/components/InitData/InitData.ts +0 -139
  400. package/src/components/InitData/index.ts +0 -1
  401. package/src/components/MainButton/MainButton.ts +0 -242
  402. package/src/components/MainButton/index.ts +0 -2
  403. package/src/components/MainButton/types.ts +0 -20
  404. package/src/components/Popup/index.ts +0 -8
  405. package/src/components/QRScanner/index.ts +0 -2
  406. package/src/components/ThemeParams/ThemeParams.ts +0 -168
  407. package/src/components/ThemeParams/index.ts +0 -2
  408. package/src/components/ThemeParams/types.ts +0 -11
  409. package/src/components/Viewport/index.ts +0 -2
  410. package/src/components/WebApp/WebApp.ts +0 -311
  411. package/src/components/WebApp/index.ts +0 -2
  412. package/src/components/WebApp/types.ts +0 -17
  413. package/src/components/index.ts +0 -11
  414. package/src/env.ts +0 -22
  415. package/src/errors/MethodNotSupportedError.ts +0 -9
  416. package/src/errors/ParameterNotSupportedError.ts +0 -9
  417. package/src/errors/index.ts +0 -2
  418. package/src/init/creators/createWebApp.ts +0 -52
  419. package/src/init/css.ts +0 -142
  420. package/src/supports.ts +0 -44
  421. package/src/types.ts +0 -13
  422. package/src/url.ts +0 -23
  423. /package/dist/dts/{components/CloudStorage → cloud-storage}/index.d.ts +0 -0
  424. /package/dist/dts/{components/HapticFeedback → haptic-feedback}/index.d.ts +0 -0
  425. /package/src/{components/CloudStorage → cloud-storage}/index.ts +0 -0
  426. /package/src/{components/HapticFeedback → haptic-feedback}/index.ts +0 -0
@@ -0,0 +1,220 @@
1
+ import { off, on, postEvent } from '~/bridge/index.js';
2
+ import { EventEmitter } from '~/event-emitter/index.js';
3
+
4
+ import { drop } from './drop.js';
5
+ import { go } from './go.js';
6
+ import type {
7
+ HashNavigatorEventsMap,
8
+ HashNavigatorOptions,
9
+ } from './types.js';
10
+ import { Navigator } from '../Navigator/index.js';
11
+ import type {
12
+ NavigationEntry,
13
+ NavigatorConEntry,
14
+ PerformGoOptions,
15
+ PerformPushOptions,
16
+ PerformReplaceOptions,
17
+ } from '../Navigator/types.js';
18
+
19
+ const CURSOR_VOID = 0;
20
+ const CURSOR_BACK = 1;
21
+ const CURSOR_FORWARD = 2;
22
+
23
+ export class HashNavigator extends Navigator<Promise<void>> {
24
+ /**
25
+ * Creates navigator from current window location hash.
26
+ * @param options - options passed to constructor.
27
+ */
28
+ static fromLocation(options?: HashNavigatorOptions): HashNavigator {
29
+ const {
30
+ search,
31
+ pathname,
32
+ hash,
33
+ } = new URL(
34
+ window.location.hash.slice(1),
35
+ window.location.href,
36
+ );
37
+
38
+ return new HashNavigator([{ search, pathname, hash }], 0, options);
39
+ }
40
+
41
+ private readonly ee = new EventEmitter<HashNavigatorEventsMap>();
42
+
43
+ private attached = false;
44
+
45
+ constructor(
46
+ entries: NavigatorConEntry[],
47
+ entriesCursor: number,
48
+ options: HashNavigatorOptions = {},
49
+ ) {
50
+ super(entries, entriesCursor, {
51
+ ...options,
52
+ loggerPrefix: 'HashNavigator',
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Handles window "popstate" event.
58
+ * @param state - event state.
59
+ */
60
+ private onPopState = async ({ state }: PopStateEvent) => {
61
+ this.logger.log('"popstate" event received. State:', state);
62
+
63
+ // In case state is null, we recognize current event as occurring whenever user clicks
64
+ // any anchor.
65
+ // TODO: Should we do it?
66
+ if (state === null) {
67
+ return this.push(window.location.hash.slice(1));
68
+ }
69
+
70
+ // There is only one case when state can be CURSOR_VOID - when history contains
71
+ // only one element. In this case, we should return user to the current history element.
72
+ if (state === CURSOR_VOID) {
73
+ this.logger.log('Void reached. Moving history forward');
74
+ window.history.forward();
75
+ return;
76
+ }
77
+
78
+ // User pressed Back button.
79
+ if (state === CURSOR_BACK) {
80
+ return this.back();
81
+ }
82
+
83
+ // User pressed Forward button.
84
+ if (state === CURSOR_FORWARD) {
85
+ return this.forward();
86
+ }
87
+ };
88
+
89
+ protected async performGo(options: PerformGoOptions): Promise<void> {
90
+ if (!options.updated) {
91
+ return;
92
+ }
93
+
94
+ if (this.attached) {
95
+ await this.syncHistory();
96
+ }
97
+
98
+ this.emitChanged(options.before, options.after);
99
+ }
100
+
101
+ protected async performPush({ before, after }: PerformPushOptions): Promise<void> {
102
+ if (this.attached) {
103
+ await this.syncHistory();
104
+ }
105
+
106
+ this.emitChanged(before, after);
107
+ }
108
+
109
+ protected async performReplace(options: PerformReplaceOptions): Promise<void> {
110
+ if (!options.updated) {
111
+ return;
112
+ }
113
+
114
+ if (this.attached) {
115
+ window.history.replaceState(null, '', `#${this.path}`);
116
+ }
117
+
118
+ this.emitChanged(options.before, options.after);
119
+ }
120
+
121
+ /**
122
+ * Synchronizes current navigator state with browser history.
123
+ */
124
+ private async syncHistory(): Promise<void> {
125
+ // Remove history change event listener to get rid of side effects related to possible
126
+ // future calls of history.go.
127
+ window.removeEventListener('popstate', this.onPopState);
128
+
129
+ const hash = `#${this.path}`;
130
+
131
+ // Drop the browser history and work with the clean one.
132
+ await drop();
133
+
134
+ // Actualize Telegram Mini Apps BackButton state.
135
+ postEvent('web_app_setup_back_button', { is_visible: this.canGoBack });
136
+
137
+ if (this.canGoBack && this.canGoForward) {
138
+ // We have both previous and next elements. History should be:
139
+ // [back, *current*, forward]
140
+ this.logger.log('Setting up history: [<-, *, ->]');
141
+
142
+ window.history.replaceState(CURSOR_BACK, '');
143
+ window.history.pushState(null, '', hash);
144
+ window.history.pushState(CURSOR_FORWARD, '');
145
+
146
+ await go(-1);
147
+ } else if (this.canGoBack) {
148
+ // We have only previous element. History should be:
149
+ // [back, *current*]
150
+ this.logger.log('Setting up history: [<-, *]');
151
+
152
+ window.history.replaceState(CURSOR_BACK, '');
153
+ window.history.pushState(null, '', hash);
154
+ } else if (this.canGoForward) {
155
+ // We have only next element. History should be:
156
+ // [*current*, forward]
157
+ this.logger.log('Setting up history: [*, ->]');
158
+
159
+ window.history.replaceState(null, hash);
160
+ window.history.pushState(CURSOR_FORWARD, '');
161
+
162
+ await go(-1);
163
+ } else {
164
+ // We have no back and next elements. History should be:
165
+ // [void, *current*]
166
+ this.logger.log('Setting up history: [~, *]');
167
+
168
+ window.history.replaceState(CURSOR_VOID, '');
169
+ window.history.pushState(null, '', hash);
170
+ }
171
+
172
+ window.addEventListener('popstate', this.onPopState);
173
+ }
174
+
175
+ private emitChanged(from: NavigationEntry, to: NavigationEntry) {
176
+ this.ee.emit('change', {
177
+ navigator: this,
178
+ from,
179
+ to,
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Attaches current navigator to the browser history allowing navigator to manipulate it.
185
+ */
186
+ async attach(): Promise<void> {
187
+ if (this.attached) {
188
+ return;
189
+ }
190
+ this.logger.log('Attaching', this);
191
+ this.attached = true;
192
+ on('back_button_pressed', this.back);
193
+ return this.syncHistory();
194
+ }
195
+
196
+ back = () => super.back();
197
+
198
+ /**
199
+ * Detaches current navigator from the browser history.
200
+ */
201
+ detach() {
202
+ if (!this.attached) {
203
+ return;
204
+ }
205
+ this.logger.log('Detaching', this);
206
+ this.attached = false;
207
+ window.removeEventListener('popstate', this.onPopState);
208
+ off('back_button_pressed', this.back);
209
+ }
210
+
211
+ /**
212
+ * Adds new event listener.
213
+ */
214
+ on = this.ee.on.bind(this.ee);
215
+
216
+ /**
217
+ * Removes event listener.
218
+ */
219
+ off = this.ee.off.bind(this.ee);
220
+ }
@@ -0,0 +1,36 @@
1
+ import { go } from './go.js';
2
+
3
+ /**
4
+ * Drops current browser history switching browser history cursor to the first one entry.
5
+ */
6
+ export async function drop(): Promise<void> {
7
+ if (window.history.length <= 1) {
8
+ return;
9
+ }
10
+
11
+ // Push empty state to cut states we have no access to.
12
+ window.history.pushState(null, '');
13
+
14
+ // By this line of code we cover the most recent case, when application is opened in WebView,
15
+ // but not in iframe. Applications opened in WebView have simple browser history containing
16
+ // only entries belonging to the current web application.
17
+ const goPerformed = await go(1 - window.history.length);
18
+ if (goPerformed) {
19
+ return;
20
+ }
21
+
22
+ // Nevertheless, iframe works a bit different in context of browser history. Calling
23
+ // window.history.length in iframe will return browser history information related to the
24
+ // external web environment too (e.g. browser tab). So, iframe shares the browser history with
25
+ // the external application, but has no access to its history entries. Calling window.history.go
26
+ // pointing out to the entry belonging to the external application will have no impact, so the
27
+ // previous idea with go(1 - ...) will not work.
28
+ //
29
+ // This is the reason why we iteratively call go(-1) to meet the entry which is recognized as
30
+ // the initial one for the current iframe.
31
+ let shouldGoBack = await go(-1);
32
+ while (shouldGoBack) {
33
+ // eslint-disable-next-line no-await-in-loop
34
+ shouldGoBack = await go(-1);
35
+ }
36
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Performs window.history.go operation waiting for it to be completed.
3
+ * @param delta - history change delta.
4
+ */
5
+ export async function go(delta: number): Promise<boolean> {
6
+ if (delta === 0) {
7
+ return true;
8
+ }
9
+
10
+ // We expect popstate event to occur during some time. Yeah, this seems tricky and not stable,
11
+ // but it seems like we have no other way out. Waiting for Navigation API to be implemented in
12
+ // browsers.
13
+ return Promise.race<boolean>([
14
+ new Promise((res) => {
15
+ window.addEventListener('popstate', function listener() {
16
+ window.removeEventListener('popstate', listener);
17
+ res(true);
18
+ });
19
+
20
+ window.history.go(delta);
21
+ }),
22
+
23
+ // Usually, it takes about 1ms to emit this event, but we use some buffer.
24
+ new Promise((res) => {
25
+ setTimeout(res, 50, false);
26
+ }),
27
+ ]);
28
+ }
@@ -0,0 +1,2 @@
1
+ export * from './HashNavigator.js';
2
+ export * from './types.js';
@@ -0,0 +1,41 @@
1
+ import type { HashNavigator } from './HashNavigator.js';
2
+ import type { NavigatorOptions } from '../Navigator/index.js';
3
+ import type { NavigationEntry } from '../Navigator/types.js';
4
+
5
+ export type HashNavigatorOptions = Omit<NavigatorOptions, 'loggerPrefix'>;
6
+
7
+ interface ChangeEventPayload {
8
+ /**
9
+ * Navigator instance.
10
+ */
11
+ navigator: HashNavigator;
12
+
13
+ /**
14
+ * Previous navigation state.
15
+ */
16
+ from: NavigationEntry;
17
+
18
+ /**
19
+ * Current navigation state.
20
+ */
21
+ to: NavigationEntry;
22
+ }
23
+
24
+ export interface HashNavigatorEventsMap {
25
+ /**
26
+ * Being called whenever current history changes.
27
+ * @param event - generated event.
28
+ */
29
+ change: (event: ChangeEventPayload) => void;
30
+ }
31
+
32
+ /**
33
+ * Navigator event name.
34
+ */
35
+ export type HashNavigatorEventName = keyof HashNavigatorEventsMap;
36
+
37
+ /**
38
+ * Navigator event listener.
39
+ */
40
+ export type HashNavigatorEventListener<E extends HashNavigatorEventName> =
41
+ HashNavigatorEventsMap[E];
@@ -0,0 +1,282 @@
1
+ import { Logger } from '~/logger/index.js';
2
+
3
+ import type {
4
+ AnyEntry,
5
+ NavigationEntry,
6
+ NavigatorConEntry,
7
+ NavigatorOptions,
8
+ PerformGoOptions,
9
+ PerformPushOptions,
10
+ PerformReplaceOptions,
11
+ } from './types.js';
12
+ import { ensurePrefix } from '../ensurePrefix.js';
13
+
14
+ /**
15
+ * Represents basic navigator implementation which uses only memory to store and control
16
+ * navigation state.
17
+ */
18
+ export abstract class Navigator<T> {
19
+ protected logger: Logger;
20
+
21
+ protected readonly entries: NavigationEntry[];
22
+
23
+ constructor(
24
+ entries: NavigatorConEntry[],
25
+ protected entriesCursor: number,
26
+ {
27
+ debug = false,
28
+ loggerPrefix = 'Navigator',
29
+ }: NavigatorOptions,
30
+ ) {
31
+ if (entries.length === 0) {
32
+ throw new Error('Entries list should not be empty.');
33
+ }
34
+
35
+ if (entriesCursor >= entries.length) {
36
+ throw new Error('Cursor should be less than entries count.');
37
+ }
38
+
39
+ this.entries = entries.map(({ pathname = '', search, hash }) => {
40
+ if (!pathname.startsWith('/') && pathname.length > 0) {
41
+ throw new Error('Pathname should start with "/"');
42
+ }
43
+
44
+ return {
45
+ pathname: ensurePrefix(pathname, '/'),
46
+ search: search ? ensurePrefix(search, '?') : '',
47
+ hash: hash ? ensurePrefix(hash, '#') : '',
48
+ };
49
+ });
50
+ this.logger = new Logger(`[${loggerPrefix}]`, debug);
51
+ }
52
+
53
+ protected abstract performGo(options: PerformGoOptions): T;
54
+
55
+ protected abstract performPush(options: PerformPushOptions): T;
56
+
57
+ protected abstract performReplace(options: PerformReplaceOptions): T;
58
+
59
+ /**
60
+ * Converts entry to the navigation entry.
61
+ * @param entry - entry data
62
+ */
63
+ private formatEntry(entry: AnyEntry): NavigationEntry {
64
+ let path: string;
65
+
66
+ if (typeof entry === 'string') {
67
+ path = entry;
68
+ } else {
69
+ const {
70
+ pathname = '',
71
+ search,
72
+ hash,
73
+ } = entry;
74
+
75
+ path = pathname
76
+ + (search ? ensurePrefix(search, '?') : '')
77
+ + (hash ? ensurePrefix(hash, '#') : '');
78
+ }
79
+
80
+ const {
81
+ pathname,
82
+ search,
83
+ hash,
84
+ } = new URL(path, `https://localhost${this.path}`);
85
+ return {
86
+ pathname,
87
+ search,
88
+ hash,
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Current entry.
94
+ */
95
+ protected get entry(): NavigationEntry {
96
+ return this.entries[this.entriesCursor];
97
+ }
98
+
99
+ /**
100
+ * Goes back in history.
101
+ */
102
+ back(): T {
103
+ return this.go(-1);
104
+ }
105
+
106
+ /**
107
+ * Current entries cursor.
108
+ */
109
+ get cursor(): number {
110
+ return this.entriesCursor;
111
+ }
112
+
113
+ /**
114
+ * True if navigator can go back.
115
+ */
116
+ get canGoBack(): boolean {
117
+ return this.entriesCursor > 0;
118
+ }
119
+
120
+ /**
121
+ * True if navigator can go forward.
122
+ */
123
+ get canGoForward(): boolean {
124
+ return this.entriesCursor !== this.entries.length - 1;
125
+ }
126
+
127
+ /**
128
+ * Goes forward in history.
129
+ */
130
+ forward(): T {
131
+ return this.go(1);
132
+ }
133
+
134
+ /**
135
+ * Moves entries cursor by specified delta.
136
+ * @param delta - cursor delta.
137
+ */
138
+ go(delta: number): T {
139
+ this.logger.log(`called go(${delta})`);
140
+
141
+ // Cursor should be in bounds: [0, this.entries).
142
+ const cursor = Math.min(
143
+ this.entries.length - 1,
144
+ Math.max(this.entriesCursor + delta, 0),
145
+ );
146
+
147
+ if (this.entriesCursor === cursor) {
148
+ return this.performGo({
149
+ updated: false,
150
+ delta,
151
+ });
152
+ }
153
+
154
+ const before = this.entry;
155
+ this.entriesCursor = cursor;
156
+ const after = this.entry;
157
+
158
+ this.logger.log('State changed', { before, after });
159
+
160
+ return this.performGo({
161
+ updated: true,
162
+ delta,
163
+ before,
164
+ after,
165
+ });
166
+ }
167
+
168
+ /**
169
+ * Returns copy of navigator entries.
170
+ */
171
+ getEntries(): NavigationEntry[] {
172
+ return this.entries.map((entry) => ({ ...entry }));
173
+ }
174
+
175
+ /**
176
+ * Current hash.
177
+ * @example
178
+ * "", "#", "#hash"
179
+ */
180
+ get hash(): string {
181
+ return this.entry.hash;
182
+ }
183
+
184
+ /**
185
+ * Pushes new entry. Method replaces all entries after the current one with the inserted.
186
+ * @param entry - entry data.
187
+ *
188
+ * @example Pushing absolute pathname.
189
+ * push("/absolute-path"); // "/absolute-path"
190
+ *
191
+ * @example Pushing relative pathname.
192
+ * // Pushing relative path replaces N last path parts, where N is pushed pathname parts count.
193
+ * // Pushing empty path is recognized as relative, but not replacing the last pathname part.
194
+ * push("relative"); // "/home/root" -> "/home/relative"
195
+ *
196
+ * @example Pushing query parameters.
197
+ * push("/absolute?my-param=1"); // "/home" -> "/absolute?my-param=1"
198
+ * push("relative?my-param=1"); // "/home/root" -> "/home/relative?my-param=1"
199
+ * push("?my-param=1"); // "/home" -> "/home?my-param=1"
200
+ *
201
+ * @example Pushing hash.
202
+ * push("#my-hash"); // "/home" -> "/home#my-hash"
203
+ * push("johny#my-hash"); // "/home/root" -> "/home/johny#my-hash"
204
+ */
205
+ push(entry: AnyEntry): T {
206
+ // In case, current cursor refers not to the last one element in the history, we should
207
+ // remove everything after the cursor.
208
+ if (this.entriesCursor !== this.entries.length - 1) {
209
+ this.entries.splice(this.entriesCursor + 1);
210
+ }
211
+
212
+ const formatted = this.formatEntry(entry);
213
+ const before = this.entry;
214
+ this.entriesCursor += 1;
215
+ this.entries[this.entriesCursor] = formatted;
216
+ const after = this.entry;
217
+
218
+ this.logger.log('State changed', { before, after });
219
+
220
+ return this.performPush({
221
+ before,
222
+ after,
223
+ });
224
+ }
225
+
226
+ /**
227
+ * Current full path including pathname, query parameters and hash.
228
+ */
229
+ get path(): string {
230
+ return `${this.pathname}${this.search}${this.hash}`;
231
+ }
232
+
233
+ /**
234
+ * Current pathname.
235
+ * @example
236
+ * "/", "/abc"
237
+ */
238
+ get pathname(): string {
239
+ return this.entry.pathname;
240
+ }
241
+
242
+ /**
243
+ * Replaces current entry. Has the same logic as `push` method.
244
+ * @param entry - entry data.
245
+ * @see push
246
+ * @returns True if changes were done.
247
+ */
248
+ replace(entry: AnyEntry): T {
249
+ const formattedEntry = this.formatEntry(entry);
250
+ if (
251
+ this.search === formattedEntry.search
252
+ && this.pathname === formattedEntry.pathname
253
+ && this.hash === formattedEntry.hash
254
+ ) {
255
+ return this.performReplace({
256
+ updated: false,
257
+ entry: formattedEntry,
258
+ });
259
+ }
260
+
261
+ const before = this.entry;
262
+ this.entries[this.entriesCursor] = formattedEntry;
263
+ const after = this.entry;
264
+
265
+ this.logger.log('State changed', { before, after });
266
+
267
+ return this.performReplace({
268
+ updated: true,
269
+ before,
270
+ after,
271
+ });
272
+ }
273
+
274
+ /**
275
+ * Current query parameters.
276
+ * @example
277
+ * "", "?", "?a=1"
278
+ */
279
+ get search(): string {
280
+ return this.entry.search;
281
+ }
282
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Navigator.js';
2
+ export * from './types.js';
@@ -0,0 +1,55 @@
1
+ export interface NavigationEntry {
2
+ pathname: string;
3
+ search: string;
4
+ hash: string;
5
+ }
6
+
7
+ export type NavigatorConEntry = Partial<NavigationEntry>;
8
+
9
+ /**
10
+ * Entry information is allowed to be used in `push` and `replace` Navigator methods.
11
+ * Should be either path or object partially describing it.
12
+ */
13
+ export type AnyEntry = string | Partial<NavigationEntry>;
14
+
15
+ export type PerformGoOptions =
16
+ | {
17
+ updated: false;
18
+ delta: number;
19
+ }
20
+ | {
21
+ updated: true;
22
+ delta: number;
23
+ before: NavigationEntry;
24
+ after: NavigationEntry;
25
+ };
26
+
27
+ export interface PerformPushOptions {
28
+ before: NavigationEntry;
29
+ after: NavigationEntry;
30
+ }
31
+
32
+ export type PerformReplaceOptions =
33
+ | {
34
+ updated: false;
35
+ entry: NavigationEntry;
36
+ }
37
+ | {
38
+ updated: true;
39
+ before: NavigationEntry;
40
+ after: NavigationEntry;
41
+ };
42
+
43
+ export interface NavigatorOptions {
44
+ /**
45
+ * Should navigator display debug messages.
46
+ * @default false
47
+ */
48
+ debug?: boolean;
49
+
50
+ /**
51
+ * Prefix used for logger.
52
+ * @default 'Navigator'
53
+ */
54
+ loggerPrefix?: string;
55
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ensures, that specified value starts with the specified prefix. If it doesn't, function appends
3
+ * prefix.
4
+ * @param value - value to check.
5
+ * @param prefix - prefix to add.
6
+ */
7
+ export function ensurePrefix(value: string, prefix: string): string {
8
+ return value.startsWith(prefix) ? value : `${prefix}${value}`;
9
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Returns string after first met "#" symbol.
3
+ * @param value - string to take hash part from.
4
+ *
5
+ * @example No hash.
6
+ * getHash('/path'); // null
7
+ *
8
+ * @example Has hash.
9
+ * getHash('/path#abc'); // 'abc'
10
+ *
11
+ * @example Has double hash.
12
+ * getHash('/path#abc#another'); // 'abc#another'
13
+ */
14
+ export function getHash(value: string): string | null {
15
+ const match = value.match(/#(.+)/);
16
+ return match ? match[1] : null;
17
+ }
@@ -0,0 +1,4 @@
1
+ export * from './ensurePrefix.js';
2
+ export * from './getHash.js';
3
+ export * from './HashNavigator/index.js';
4
+ export * from './Navigator/index.js';