@tma.js/sdk 0.13.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/{components/BackButton → back-button}/BackButton.d.ts +12 -9
- package/dist/dts/back-button/index.d.ts +2 -0
- package/dist/dts/{components/BackButton → back-button}/types.d.ts +3 -2
- package/dist/dts/bridge/env/hasExternalNotify.d.ts +12 -0
- package/dist/dts/bridge/env/hasWebviewProxy.d.ts +12 -0
- package/dist/dts/bridge/env/index.d.ts +3 -0
- package/dist/dts/bridge/env/isIframe.d.ts +5 -0
- package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +8 -0
- package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +8 -0
- package/dist/dts/bridge/errors/index.d.ts +2 -0
- package/dist/dts/bridge/events/createEmitter.d.ts +6 -0
- package/dist/dts/bridge/events/events.d.ts +130 -0
- package/dist/dts/bridge/events/index.d.ts +9 -0
- package/dist/dts/bridge/events/off.d.ts +7 -0
- package/dist/dts/bridge/events/on.d.ts +10 -0
- package/dist/dts/bridge/events/onTelegramEvent.d.ts +7 -0
- package/dist/dts/bridge/events/once.d.ts +9 -0
- package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +13 -0
- package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +16 -0
- package/dist/dts/bridge/events/parsers/index.d.ts +9 -0
- package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +12 -0
- package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +8 -0
- package/dist/dts/bridge/events/parsers/popupClosed.d.ts +8 -0
- package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +7 -0
- package/dist/dts/bridge/events/parsers/theme-changed.d.ts +42 -0
- package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +19 -0
- package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +8 -0
- package/dist/dts/bridge/events/singletonEmitter.d.ts +6 -0
- package/dist/dts/bridge/events/subscribe.d.ts +9 -0
- package/dist/dts/bridge/events/unsubscribe.d.ts +6 -0
- package/dist/dts/bridge/index.d.ts +5 -0
- package/dist/dts/bridge/methods/createPostEvent.d.ts +10 -0
- package/dist/dts/bridge/methods/haptic.d.ts +40 -0
- package/dist/dts/bridge/methods/index.d.ts +6 -0
- package/dist/dts/bridge/methods/invoke-custom-method.d.ts +24 -0
- package/dist/dts/bridge/methods/methods.d.ts +329 -0
- package/dist/dts/bridge/methods/popup.d.ts +49 -0
- package/dist/dts/bridge/methods/postEvent.d.ts +29 -0
- package/dist/dts/bridge/request.d.ts +65 -0
- package/dist/dts/classnames/classNames.d.ts +10 -0
- package/dist/dts/classnames/index.d.ts +2 -0
- package/dist/dts/classnames/mergeClassNames.d.ts +32 -0
- package/dist/dts/{components/ClosingBehaviour/ClosingBehaviour.d.ts → closing-behavior/ClosingBehavior.d.ts} +5 -4
- package/dist/dts/closing-behavior/index.d.ts +2 -0
- package/dist/dts/closing-behavior/types.d.ts +7 -0
- package/dist/dts/{components/CloudStorage → cloud-storage}/CloudStorage.d.ts +19 -11
- package/dist/dts/colors/index.d.ts +5 -0
- package/dist/dts/colors/isColorDark.d.ts +6 -0
- package/dist/dts/colors/isRGB.d.ts +6 -0
- package/dist/dts/colors/isRGBShort.d.ts +6 -0
- package/dist/dts/colors/toRGB.d.ts +11 -0
- package/dist/dts/colors/types.d.ts +8 -0
- package/dist/dts/event-emitter/EventEmitter.d.ts +64 -0
- package/dist/dts/event-emitter/index.d.ts +2 -0
- package/dist/dts/event-emitter/types.d.ts +44 -0
- package/dist/dts/globals.d.ts +22 -0
- package/dist/dts/{components/HapticFeedback → haptic-feedback}/HapticFeedback.d.ts +3 -3
- package/dist/dts/index.d.ts +24 -6
- package/dist/dts/init/catchCustomStyles.d.ts +4 -0
- package/dist/dts/init/creators/createBackButton.d.ts +2 -2
- package/dist/dts/init/creators/createClosingBehavior.d.ts +3 -3
- package/dist/dts/init/creators/createMainButton.d.ts +3 -3
- package/dist/dts/init/creators/createMiniApp.d.ts +14 -0
- package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
- package/dist/dts/init/creators/createThemeParams.d.ts +2 -3
- package/dist/dts/init/creators/createViewport.d.ts +16 -9
- package/dist/dts/init/creators/index.d.ts +1 -1
- package/dist/dts/init/css/bindMiniAppCSSVars.d.ts +16 -0
- package/dist/dts/init/css/bindThemeCSSVars.d.ts +12 -0
- package/dist/dts/init/css/bindViewportCSSVars.d.ts +20 -0
- package/dist/dts/init/css/index.d.ts +1 -0
- package/dist/dts/init/css/processCSSVarsOption.d.ts +12 -0
- package/dist/dts/init/css/setCSSVar.d.ts +6 -0
- package/dist/dts/init/init.d.ts +5 -5
- package/dist/dts/init/types.d.ts +42 -69
- package/dist/dts/init-data/InitData.d.ts +53 -0
- package/dist/dts/init-data/chatParser.d.ts +5 -0
- package/dist/dts/init-data/index.d.ts +6 -0
- package/dist/dts/init-data/initDataParser.d.ts +5 -0
- package/dist/dts/init-data/parseInitData.d.ts +6 -0
- package/dist/dts/init-data/types.d.ts +133 -0
- package/dist/dts/init-data/userParser.d.ts +5 -0
- package/dist/dts/invoice/Invoice.d.ts +43 -0
- package/dist/dts/invoice/index.d.ts +2 -0
- package/dist/dts/invoice/types.d.ts +7 -0
- package/dist/dts/launch-params/computeLaunchData.d.ts +6 -0
- package/dist/dts/launch-params/computePageReload.d.ts +6 -0
- package/dist/dts/launch-params/getFirstNavigationEntry.d.ts +6 -0
- package/dist/dts/launch-params/index.d.ts +12 -0
- package/dist/dts/launch-params/launchParamsParser.d.ts +5 -0
- package/dist/dts/launch-params/parseLaunchParams.d.ts +6 -0
- package/dist/dts/launch-params/retrieveCurrent.d.ts +5 -0
- package/dist/dts/launch-params/retrieveFromLocation.d.ts +6 -0
- package/dist/dts/launch-params/retrieveFromPerformance.d.ts +8 -0
- package/dist/dts/launch-params/retrieveLaunchData.d.ts +6 -0
- package/dist/dts/launch-params/serializeLaunchParams.d.ts +6 -0
- package/dist/dts/launch-params/storage.d.ts +13 -0
- package/dist/dts/launch-params/types.d.ts +48 -0
- package/dist/dts/logger/Logger.d.ts +38 -0
- package/dist/dts/logger/index.d.ts +1 -0
- package/dist/dts/main-button/MainButton.d.ts +104 -0
- package/dist/dts/main-button/index.d.ts +2 -0
- package/dist/dts/main-button/types.d.ts +20 -0
- package/dist/dts/mini-app/MiniApp.d.ts +99 -0
- package/dist/dts/mini-app/index.d.ts +2 -0
- package/dist/dts/mini-app/types.d.ts +19 -0
- package/dist/dts/misc/index.d.ts +2 -0
- package/dist/dts/misc/isRecord.d.ts +5 -0
- package/dist/dts/misc/isTMA.d.ts +4 -0
- package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +43 -0
- package/dist/dts/navigation/HashNavigator/drop.d.ts +4 -0
- package/dist/dts/navigation/HashNavigator/go.d.ts +5 -0
- package/dist/dts/navigation/HashNavigator/index.d.ts +2 -0
- package/dist/dts/navigation/HashNavigator/types.d.ts +34 -0
- package/dist/dts/navigation/Navigator/Navigator.d.ts +104 -0
- package/dist/dts/navigation/Navigator/index.d.ts +2 -0
- package/dist/dts/navigation/Navigator/types.d.ts +44 -0
- package/dist/dts/navigation/ensurePrefix.d.ts +7 -0
- package/dist/dts/navigation/getHash.d.ts +14 -0
- package/dist/dts/navigation/index.d.ts +4 -0
- package/dist/dts/parsing/ArrayValueParser.d.ts +18 -0
- package/dist/dts/parsing/ParseError.d.ts +22 -0
- package/dist/dts/parsing/ParseSchemaFieldError.d.ts +17 -0
- package/dist/dts/parsing/ValueParser.d.ts +36 -0
- package/dist/dts/parsing/createValueParserGenerator.d.ts +9 -0
- package/dist/dts/parsing/index.d.ts +10 -0
- package/dist/dts/parsing/parseBySchema.d.ts +8 -0
- package/dist/dts/parsing/parsers/array.d.ts +6 -0
- package/dist/dts/parsing/parsers/boolean.d.ts +4 -0
- package/dist/dts/parsing/parsers/date.d.ts +4 -0
- package/dist/dts/parsing/parsers/index.d.ts +8 -0
- package/dist/dts/parsing/parsers/json.d.ts +8 -0
- package/dist/dts/parsing/parsers/number.d.ts +4 -0
- package/dist/dts/parsing/parsers/rgb.d.ts +4 -0
- package/dist/dts/parsing/parsers/searchParams.d.ts +8 -0
- package/dist/dts/parsing/parsers/string.d.ts +4 -0
- package/dist/dts/parsing/toRecord.d.ts +7 -0
- package/dist/dts/parsing/types.d.ts +30 -0
- package/dist/dts/parsing/unexpectedTypeError.d.ts +4 -0
- package/dist/dts/{components/Popup → popup}/Popup.d.ts +10 -9
- package/dist/dts/popup/index.d.ts +2 -0
- package/dist/dts/popup/preparePopupParams.d.ts +7 -0
- package/dist/dts/{components/Popup → popup}/types.d.ts +4 -4
- package/dist/dts/{components/QRScanner → qr-scanner}/QRScanner.d.ts +6 -5
- package/dist/dts/qr-scanner/index.d.ts +2 -0
- package/dist/dts/{components/QRScanner → qr-scanner}/types.d.ts +1 -1
- package/dist/dts/state/State.d.ts +19 -6
- package/dist/dts/state/types.d.ts +4 -7
- package/dist/dts/storage.d.ts +4 -4
- package/dist/dts/supports/createSupportsFunc.d.ts +10 -0
- package/dist/dts/supports/createSupportsParamFunc.d.ts +15 -0
- package/dist/dts/supports/index.d.ts +4 -0
- package/dist/dts/supports/supports.d.ts +15 -0
- package/dist/dts/supports/types.d.ts +1 -0
- package/dist/dts/theme-params/ThemeParams.d.ts +62 -0
- package/dist/dts/theme-params/index.d.ts +6 -0
- package/dist/dts/theme-params/keys.d.ts +11 -0
- package/dist/dts/theme-params/parseThemeParams.d.ts +6 -0
- package/dist/dts/theme-params/requestThemeParams.d.ts +7 -0
- package/dist/dts/theme-params/serializeThemeParams.d.ts +5 -0
- package/dist/dts/theme-params/themeParamsParser.d.ts +2 -0
- package/dist/dts/theme-params/types.d.ts +14 -0
- package/dist/dts/timeout/TimeoutError.d.ts +3 -0
- package/dist/dts/timeout/index.d.ts +3 -0
- package/dist/dts/timeout/isTimeoutError.d.ts +6 -0
- package/dist/dts/timeout/withTimeout.d.ts +14 -0
- package/dist/dts/types/index.d.ts +3 -0
- package/dist/dts/types/platform.d.ts +4 -0
- package/dist/dts/types/request-id.d.ts +9 -0
- package/dist/dts/types/utils.d.ts +36 -0
- package/dist/dts/utils/Utils.d.ts +45 -0
- package/dist/dts/utils/index.d.ts +1 -0
- package/dist/dts/version/compareVersions.d.ts +8 -0
- package/dist/dts/version/index.d.ts +2 -0
- package/dist/dts/version/types.d.ts +4 -0
- package/dist/dts/{components/Viewport → viewport}/Viewport.d.ts +16 -38
- package/dist/dts/viewport/index.d.ts +3 -0
- package/dist/dts/viewport/requestViewport.d.ts +12 -0
- package/dist/dts/{components/Viewport → viewport}/types.d.ts +9 -1
- package/dist/dts/viewport/utils.d.ts +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +2249 -1036
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -16
- package/src/{components/BackButton → back-button}/BackButton.ts +23 -21
- package/src/back-button/index.ts +2 -0
- package/src/{components/BackButton → back-button}/types.ts +3 -2
- package/src/bridge/env/hasExternalNotify.ts +19 -0
- package/src/bridge/env/hasWebviewProxy.ts +19 -0
- package/src/bridge/env/index.ts +3 -0
- package/src/bridge/env/isIframe.ts +11 -0
- package/src/bridge/errors/MethodUnsupportedError.ts +13 -0
- package/src/bridge/errors/ParameterUnsupportedError.ts +13 -0
- package/src/bridge/errors/index.ts +2 -0
- package/src/bridge/events/createEmitter.ts +108 -0
- package/src/bridge/events/events.ts +170 -0
- package/src/bridge/events/index.ts +9 -0
- package/src/bridge/events/off.ts +14 -0
- package/src/bridge/events/on.ts +19 -0
- package/src/bridge/events/onTelegramEvent.ts +83 -0
- package/src/bridge/events/once.ts +18 -0
- package/src/bridge/events/parsers/clipboardTextReceived.ts +26 -0
- package/src/bridge/events/parsers/customMethodInvoked.ts +25 -0
- package/src/bridge/events/parsers/index.ts +9 -0
- package/src/bridge/events/parsers/invoiceClosed.ts +26 -0
- package/src/bridge/events/parsers/phoneRequested.ts +14 -0
- package/src/bridge/events/parsers/popupClosed.ts +19 -0
- package/src/bridge/events/parsers/qrTextReceived.ts +14 -0
- package/src/bridge/events/parsers/theme-changed.ts +58 -0
- package/src/bridge/events/parsers/viewportChanged.ts +33 -0
- package/src/bridge/events/parsers/writeAccessRequested.ts +14 -0
- package/src/bridge/events/singletonEmitter.ts +19 -0
- package/src/bridge/events/subscribe.ts +15 -0
- package/src/bridge/events/unsubscribe.ts +10 -0
- package/src/bridge/index.ts +5 -0
- package/src/bridge/methods/createPostEvent.ts +40 -0
- package/src/bridge/methods/haptic.ts +52 -0
- package/src/bridge/methods/index.ts +6 -0
- package/src/bridge/methods/invoke-custom-method.ts +25 -0
- package/src/bridge/methods/methods.ts +372 -0
- package/src/bridge/methods/popup.ts +53 -0
- package/src/bridge/methods/postEvent.ts +101 -0
- package/src/bridge/request.ts +185 -0
- package/src/classnames/classNames.ts +34 -0
- package/src/classnames/index.ts +2 -0
- package/src/classnames/mergeClassNames.ts +68 -0
- package/src/{components/ClosingBehaviour/ClosingBehaviour.ts → closing-behavior/ClosingBehavior.ts} +12 -10
- package/src/closing-behavior/index.ts +2 -0
- package/src/closing-behavior/types.ts +12 -0
- package/src/{components/CloudStorage → cloud-storage}/CloudStorage.ts +50 -28
- package/src/colors/index.ts +5 -0
- package/src/colors/isColorDark.ts +22 -0
- package/src/colors/isRGB.ts +9 -0
- package/src/colors/isRGBShort.ts +9 -0
- package/src/colors/toRGB.ts +49 -0
- package/src/colors/types.ts +9 -0
- package/src/event-emitter/EventEmitter.ts +146 -0
- package/src/event-emitter/index.ts +2 -0
- package/src/event-emitter/types.ts +60 -0
- package/src/globals.ts +38 -0
- package/src/{components/HapticFeedback → haptic-feedback}/HapticFeedback.ts +16 -8
- package/src/index.ts +171 -6
- package/src/init/catchCustomStyles.ts +17 -0
- package/src/init/creators/createBackButton.ts +4 -6
- package/src/init/creators/createClosingBehavior.ts +6 -8
- package/src/init/creators/createMainButton.ts +13 -20
- package/src/init/creators/createMiniApp.ts +44 -0
- package/src/init/creators/createRequestIdGenerator.ts +1 -1
- package/src/init/creators/createThemeParams.ts +3 -6
- package/src/init/creators/createViewport.ts +92 -42
- package/src/init/creators/index.ts +1 -1
- package/src/init/css/bindMiniAppCSSVars.ts +48 -0
- package/src/init/css/bindThemeCSSVars.ts +31 -0
- package/src/init/css/bindViewportCSSVars.ts +36 -0
- package/src/init/css/index.ts +1 -0
- package/src/init/css/processCSSVarsOption.ts +57 -0
- package/src/init/css/setCSSVar.ts +8 -0
- package/src/init/init.ts +96 -138
- package/src/init/types.ts +42 -87
- package/src/init-data/InitData.ts +96 -0
- package/src/init-data/chatParser.ts +19 -0
- package/src/init-data/index.ts +6 -0
- package/src/init-data/initDataParser.ts +41 -0
- package/src/init-data/parseInitData.ts +10 -0
- package/src/init-data/types.ts +164 -0
- package/src/init-data/userParser.ts +45 -0
- package/src/invoice/Invoice.ts +123 -0
- package/src/invoice/index.ts +2 -0
- package/src/invoice/types.ts +11 -0
- package/src/launch-params/computeLaunchData.ts +81 -0
- package/src/launch-params/computePageReload.ts +13 -0
- package/src/launch-params/getFirstNavigationEntry.ts +10 -0
- package/src/launch-params/index.ts +12 -0
- package/src/launch-params/launchParamsParser.ts +41 -0
- package/src/launch-params/parseLaunchParams.ts +10 -0
- package/src/launch-params/retrieveCurrent.ts +27 -0
- package/src/launch-params/retrieveFromLocation.ts +10 -0
- package/src/launch-params/retrieveFromPerformance.ts +23 -0
- package/src/launch-params/retrieveLaunchData.ts +30 -0
- package/src/launch-params/serializeLaunchParams.ts +37 -0
- package/src/launch-params/storage.ts +33 -0
- package/src/launch-params/types.ts +57 -0
- package/src/logger/Logger.ts +72 -0
- package/src/logger/index.ts +1 -0
- package/src/main-button/MainButton.ts +239 -0
- package/src/main-button/index.ts +2 -0
- package/src/main-button/types.ts +26 -0
- package/src/mini-app/MiniApp.ts +237 -0
- package/src/mini-app/index.ts +2 -0
- package/src/mini-app/types.ts +25 -0
- package/src/misc/index.ts +2 -0
- package/src/misc/isRecord.ts +7 -0
- package/src/misc/isTMA.ts +13 -0
- package/src/navigation/HashNavigator/HashNavigator.ts +220 -0
- package/src/navigation/HashNavigator/drop.ts +36 -0
- package/src/navigation/HashNavigator/go.ts +28 -0
- package/src/navigation/HashNavigator/index.ts +2 -0
- package/src/navigation/HashNavigator/types.ts +41 -0
- package/src/navigation/Navigator/Navigator.ts +282 -0
- package/src/navigation/Navigator/index.ts +2 -0
- package/src/navigation/Navigator/types.ts +55 -0
- package/src/navigation/ensurePrefix.ts +9 -0
- package/src/navigation/getHash.ts +17 -0
- package/src/navigation/index.ts +4 -0
- package/src/parsing/ArrayValueParser.ts +79 -0
- package/src/parsing/ParseError.ts +27 -0
- package/src/parsing/ParseSchemaFieldError.ts +21 -0
- package/src/parsing/ValueParser.ts +71 -0
- package/src/parsing/createValueParserGenerator.ts +16 -0
- package/src/parsing/index.ts +10 -0
- package/src/parsing/parseBySchema.ts +65 -0
- package/src/parsing/parsers/array.ts +9 -0
- package/src/parsing/parsers/boolean.ts +22 -0
- package/src/parsing/parsers/date.ts +13 -0
- package/src/parsing/parsers/index.ts +8 -0
- package/src/parsing/parsers/json.ts +17 -0
- package/src/parsing/parsers/number.ts +21 -0
- package/src/parsing/parsers/rgb.ts +12 -0
- package/src/parsing/parsers/searchParams.ts +24 -0
- package/src/parsing/parsers/string.ts +12 -0
- package/src/parsing/toRecord.ts +27 -0
- package/src/parsing/types.ts +32 -0
- package/src/parsing/unexpectedTypeError.ts +6 -0
- package/src/{components/Popup → popup}/Popup.ts +38 -28
- package/src/popup/index.ts +2 -0
- package/src/{components/Popup/utils.ts → popup/preparePopupParams.ts} +3 -3
- package/src/{components/Popup → popup}/types.ts +4 -4
- package/src/{components/QRScanner → qr-scanner}/QRScanner.ts +18 -10
- package/src/qr-scanner/index.ts +2 -0
- package/src/{components/QRScanner → qr-scanner}/types.ts +1 -1
- package/src/state/State.ts +30 -16
- package/src/state/types.ts +5 -8
- package/src/storage.ts +6 -4
- package/src/supports/createSupportsFunc.ts +18 -0
- package/src/supports/createSupportsParamFunc.ts +27 -0
- package/src/supports/index.ts +4 -0
- package/src/supports/supports.ts +84 -0
- package/src/supports/types.ts +1 -0
- package/src/theme-params/ThemeParams.ts +131 -0
- package/src/theme-params/index.ts +6 -0
- package/src/theme-params/keys.ts +24 -0
- package/src/theme-params/parseThemeParams.ts +10 -0
- package/src/theme-params/requestThemeParams.ts +13 -0
- package/src/theme-params/serializeThemeParams.ts +20 -0
- package/src/theme-params/themeParamsParser.ts +20 -0
- package/src/theme-params/types.ts +33 -0
- package/src/timeout/TimeoutError.ts +6 -0
- package/src/timeout/index.ts +3 -0
- package/src/timeout/isTimeoutError.ts +9 -0
- package/src/timeout/withTimeout.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types/platform.ts +14 -0
- package/src/types/request-id.ts +10 -0
- package/src/types/utils.ts +50 -0
- package/src/utils/Utils.ts +107 -0
- package/src/utils/index.ts +1 -0
- package/src/version/compareVersions.ts +28 -0
- package/src/version/index.ts +2 -0
- package/src/version/types.ts +4 -0
- package/src/{components/Viewport → viewport}/Viewport.ts +72 -98
- package/src/viewport/index.ts +3 -0
- package/src/viewport/requestViewport.ts +23 -0
- package/src/{components/Viewport → viewport}/types.ts +10 -1
- package/src/viewport/utils.ts +7 -0
- package/dist/dts/components/BackButton/index.d.ts +0 -2
- package/dist/dts/components/ClosingBehaviour/index.d.ts +0 -2
- package/dist/dts/components/ClosingBehaviour/types.d.ts +0 -7
- package/dist/dts/components/InitData/InitData.d.ts +0 -60
- package/dist/dts/components/InitData/index.d.ts +0 -1
- package/dist/dts/components/MainButton/MainButton.d.ts +0 -114
- package/dist/dts/components/MainButton/index.d.ts +0 -2
- package/dist/dts/components/MainButton/types.d.ts +0 -15
- package/dist/dts/components/Popup/index.d.ts +0 -2
- package/dist/dts/components/Popup/utils.d.ts +0 -7
- package/dist/dts/components/QRScanner/index.d.ts +0 -2
- package/dist/dts/components/ThemeParams/ThemeParams.d.ts +0 -73
- package/dist/dts/components/ThemeParams/index.d.ts +0 -2
- package/dist/dts/components/ThemeParams/types.d.ts +0 -9
- package/dist/dts/components/Viewport/index.d.ts +0 -2
- package/dist/dts/components/WebApp/WebApp.d.ts +0 -146
- package/dist/dts/components/WebApp/index.d.ts +0 -2
- package/dist/dts/components/WebApp/types.d.ts +0 -11
- package/dist/dts/components/index.d.ts +0 -11
- package/dist/dts/env.d.ts +0 -10
- package/dist/dts/errors/MethodNotSupportedError.d.ts +0 -6
- package/dist/dts/errors/ParameterNotSupportedError.d.ts +0 -6
- package/dist/dts/errors/index.d.ts +0 -2
- package/dist/dts/init/creators/createWebApp.d.ts +0 -16
- package/dist/dts/init/css.d.ts +0 -57
- package/dist/dts/supports.d.ts +0 -22
- package/dist/dts/types.d.ts +0 -10
- package/dist/dts/url.d.ts +0 -7
- package/src/components/BackButton/index.ts +0 -2
- package/src/components/ClosingBehaviour/index.ts +0 -6
- package/src/components/ClosingBehaviour/types.ts +0 -12
- package/src/components/InitData/InitData.ts +0 -139
- package/src/components/InitData/index.ts +0 -1
- package/src/components/MainButton/MainButton.ts +0 -242
- package/src/components/MainButton/index.ts +0 -2
- package/src/components/MainButton/types.ts +0 -20
- package/src/components/Popup/index.ts +0 -8
- package/src/components/QRScanner/index.ts +0 -2
- package/src/components/ThemeParams/ThemeParams.ts +0 -166
- package/src/components/ThemeParams/index.ts +0 -2
- package/src/components/ThemeParams/types.ts +0 -18
- package/src/components/Viewport/index.ts +0 -2
- package/src/components/WebApp/WebApp.ts +0 -311
- package/src/components/WebApp/index.ts +0 -2
- package/src/components/WebApp/types.ts +0 -17
- package/src/components/index.ts +0 -11
- package/src/env.ts +0 -22
- package/src/errors/MethodNotSupportedError.ts +0 -9
- package/src/errors/ParameterNotSupportedError.ts +0 -9
- package/src/errors/index.ts +0 -2
- package/src/init/creators/createWebApp.ts +0 -52
- package/src/init/css.ts +0 -166
- package/src/supports.ts +0 -44
- package/src/types.ts +0 -13
- package/src/url.ts +0 -23
- /package/dist/dts/{components/CloudStorage → cloud-storage}/index.d.ts +0 -0
- /package/dist/dts/{components/HapticFeedback → haptic-feedback}/index.d.ts +0 -0
- /package/src/{components/CloudStorage → cloud-storage}/index.ts +0 -0
- /package/src/{components/HapticFeedback → haptic-feedback}/index.ts +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnySubscribeListener,
|
|
3
|
+
EmptyEventName,
|
|
4
|
+
EventListener, EventName,
|
|
5
|
+
EventParams, NonEmptyEventName, RemoveEventListener,
|
|
6
|
+
} from './types.js';
|
|
7
|
+
|
|
8
|
+
type AddedEventListener = [listener: EventListener<any>, once: boolean];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Opinionated event emitter implementation.
|
|
12
|
+
*/
|
|
13
|
+
export class EventEmitter<Schema> {
|
|
14
|
+
private readonly listeners: Map<string, AddedEventListener[]> = new Map();
|
|
15
|
+
|
|
16
|
+
private readonly subscribeListeners: AnySubscribeListener<Schema>[] = [];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Adds specified event listener.
|
|
20
|
+
* @param event - event name.
|
|
21
|
+
* @param listener - event listener.
|
|
22
|
+
* @param once - should listener called only once.
|
|
23
|
+
*/
|
|
24
|
+
private addListener<E extends EventName<Schema>>(
|
|
25
|
+
event: E,
|
|
26
|
+
listener: EventListener<Schema[E]>,
|
|
27
|
+
once: boolean,
|
|
28
|
+
): RemoveEventListener {
|
|
29
|
+
let listeners = this.listeners.get(event);
|
|
30
|
+
if (!listeners) {
|
|
31
|
+
listeners = [];
|
|
32
|
+
this.listeners.set(event, listeners);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
listeners.push([listener, once]);
|
|
36
|
+
|
|
37
|
+
return () => this.off(event, listener);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Emits known event which has no parameters.
|
|
42
|
+
* @param event - event name.
|
|
43
|
+
*/
|
|
44
|
+
emit<E extends EmptyEventName<Schema>>(event: E): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Emits known event which has parameters.
|
|
48
|
+
* @param event - event name.
|
|
49
|
+
* @param args - list of event listener arguments.
|
|
50
|
+
*/
|
|
51
|
+
emit<E extends NonEmptyEventName<Schema>>(
|
|
52
|
+
event: E,
|
|
53
|
+
...args: EventParams<Schema[E]>
|
|
54
|
+
): void;
|
|
55
|
+
|
|
56
|
+
emit(event: EventName<Schema>, ...args: any[]): void {
|
|
57
|
+
this.subscribeListeners.forEach((l) => (l as any)(event, ...args));
|
|
58
|
+
|
|
59
|
+
const listeners = this.listeners.get(event);
|
|
60
|
+
if (!listeners) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
listeners.forEach(([listener, once], idx) => {
|
|
65
|
+
listener(...args);
|
|
66
|
+
if (once) {
|
|
67
|
+
listeners.splice(idx, 1);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Adds event listener.
|
|
74
|
+
* @param event - event name.
|
|
75
|
+
* @param listener - event listener.
|
|
76
|
+
* @returns Function to remove event listener.
|
|
77
|
+
*/
|
|
78
|
+
on<E extends EventName<Schema>>(
|
|
79
|
+
event: E,
|
|
80
|
+
listener: EventListener<Schema[E]>,
|
|
81
|
+
): RemoveEventListener {
|
|
82
|
+
return this.addListener(event, listener, false);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Adds event listener following the logic, described in `on` method, but calls specified
|
|
87
|
+
* listener only once, removing it after.
|
|
88
|
+
* @param event - event name.
|
|
89
|
+
* @param listener - event listener.
|
|
90
|
+
* @returns Function to remove event listener.
|
|
91
|
+
* @see on
|
|
92
|
+
*/
|
|
93
|
+
once<E extends EventName<Schema>>(
|
|
94
|
+
event: E,
|
|
95
|
+
listener: EventListener<Schema[E]>,
|
|
96
|
+
): RemoveEventListener {
|
|
97
|
+
return this.addListener(event, listener, true);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Removes event listener. In case, specified listener was bound several times, it removes
|
|
102
|
+
* only a single one.
|
|
103
|
+
* @param event - event name.
|
|
104
|
+
* @param listener - event listener.
|
|
105
|
+
*/
|
|
106
|
+
off<E extends EventName<Schema>>(event: E, listener: EventListener<Schema[E]>): void {
|
|
107
|
+
const listeners = this.listeners.get(event);
|
|
108
|
+
if (!listeners) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (let i = 0; i < listeners.length; i += 1) {
|
|
113
|
+
if (listener === listeners[i][0]) {
|
|
114
|
+
listeners.splice(i, 1);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Adds event listener to all events.
|
|
122
|
+
* @param listener - events listener.
|
|
123
|
+
* @returns Function to remove event listener.
|
|
124
|
+
* @see on
|
|
125
|
+
* @see once
|
|
126
|
+
*/
|
|
127
|
+
subscribe(listener: AnySubscribeListener<Schema>): RemoveEventListener {
|
|
128
|
+
this.subscribeListeners.push(listener);
|
|
129
|
+
return () => this.unsubscribe(listener);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Removes global event listener. In case, specified listener was bound several times, it removes
|
|
134
|
+
* only a single one.
|
|
135
|
+
* @param listener - events listener.
|
|
136
|
+
* @returns Function to remove event listener.
|
|
137
|
+
*/
|
|
138
|
+
unsubscribe(listener: AnySubscribeListener<Schema>): void {
|
|
139
|
+
for (let i = 0; i < this.subscribeListeners.length; i += 1) {
|
|
140
|
+
if (this.subscribeListeners[i] === listener) {
|
|
141
|
+
this.subscribeListeners.splice(i, 1);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IsNever } from '~/types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function accepting the list of passed arguments and returning nothing.
|
|
5
|
+
*/
|
|
6
|
+
type VoidFunc<Args extends any[] = []> = (...args: Args) => void;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Accepts type assuming, it is responsible for describing event listener
|
|
10
|
+
* parameters. Covers following cases:
|
|
11
|
+
* 1. If function is passed, return its arguments.
|
|
12
|
+
* 2. If never or void is passed, return empty tuple.
|
|
13
|
+
* 3. If array is passed return this type.
|
|
14
|
+
* 4. Otherwise, return tuple with passed type.
|
|
15
|
+
*/
|
|
16
|
+
export type EventParams<Params> = Params extends any[]
|
|
17
|
+
? Params
|
|
18
|
+
: Params extends (...args: any[]) => any
|
|
19
|
+
? Parameters<Params>
|
|
20
|
+
: IsNever<Params> extends true
|
|
21
|
+
? []
|
|
22
|
+
: Params extends void
|
|
23
|
+
? []
|
|
24
|
+
: [Params];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns function that represents event listener with specified
|
|
28
|
+
* list of parameters.
|
|
29
|
+
*/
|
|
30
|
+
export type EventListener<Params> = VoidFunc<EventParams<Params>>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns event names.
|
|
34
|
+
*/
|
|
35
|
+
export type EventName<Schema> = Extract<keyof Schema, string>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns event names which do not require any arguments.
|
|
39
|
+
*/
|
|
40
|
+
export type EmptyEventName<Schema> = {
|
|
41
|
+
[E in EventName<Schema>]: EventParams<Schema[E]> extends [] ? E : never;
|
|
42
|
+
}[EventName<Schema>];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns event names which require arguments.
|
|
46
|
+
*/
|
|
47
|
+
export type NonEmptyEventName<Schema> =
|
|
48
|
+
Exclude<EventName<Schema>, EmptyEventName<Schema>>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Represents any listener, which could be used in EventEmitter.subscribe.
|
|
52
|
+
*/
|
|
53
|
+
export type AnySubscribeListener<Schema> = {
|
|
54
|
+
[E in keyof Schema]: (event: E, ...args: EventParams<Schema[E]>) => void;
|
|
55
|
+
}[keyof Schema];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Function which removes event listener.
|
|
59
|
+
*/
|
|
60
|
+
export type RemoveEventListener = () => void;
|
package/src/globals.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Logger } from '~/logger/index.js';
|
|
2
|
+
|
|
3
|
+
let currentTargetOrigin = 'https://web.telegram.org';
|
|
4
|
+
|
|
5
|
+
export const logger = new Logger('[SDK]', false);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sets new debug mode. Enabling debug mode leads to printing
|
|
9
|
+
* additional messages in console, related to the processes
|
|
10
|
+
* inside the package.
|
|
11
|
+
* @param value - should debug mode be enabled.
|
|
12
|
+
*/
|
|
13
|
+
export function setDebug(value: boolean): void {
|
|
14
|
+
if (value) {
|
|
15
|
+
logger.enable();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
logger.disable();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Sets new global targetOrigin, used by `postEvent` method.
|
|
23
|
+
* Default value is "https://web.telegram.org". You don't need to
|
|
24
|
+
* use this method until you know what you are doing.
|
|
25
|
+
*
|
|
26
|
+
* This method could be used for test purposes.
|
|
27
|
+
* @param value - new target origin.
|
|
28
|
+
*/
|
|
29
|
+
export function setTargetOrigin(value: string): void {
|
|
30
|
+
currentTargetOrigin = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns current global target origin.
|
|
35
|
+
*/
|
|
36
|
+
export function targetOrigin(): string {
|
|
37
|
+
return currentTargetOrigin;
|
|
38
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { Version } from '@tma.js/utils';
|
|
2
1
|
import {
|
|
3
|
-
postEvent as defaultPostEvent,
|
|
4
|
-
type PostEvent,
|
|
5
2
|
type ImpactHapticFeedbackStyle,
|
|
6
3
|
type NotificationHapticFeedbackType,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
type PostEvent,
|
|
5
|
+
postEvent as defaultPostEvent,
|
|
6
|
+
} from '~/bridge/index.js';
|
|
7
|
+
import {
|
|
8
|
+
createSupportsFunc,
|
|
9
|
+
type SupportsFunc,
|
|
10
|
+
} from '~/supports/index.js';
|
|
11
|
+
import type { Version } from '~/version/index.js';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Class which controls haptic feedback. It allows calling different types of
|
|
@@ -14,7 +16,10 @@ import { createSupportsFunc, type SupportsFunc } from '../../supports.js';
|
|
|
14
16
|
* application.
|
|
15
17
|
*/
|
|
16
18
|
export class HapticFeedback {
|
|
17
|
-
constructor(
|
|
19
|
+
constructor(
|
|
20
|
+
version: Version,
|
|
21
|
+
private readonly postEvent: PostEvent = defaultPostEvent,
|
|
22
|
+
) {
|
|
18
23
|
this.supports = createSupportsFunc(version, {
|
|
19
24
|
impactOccurred: 'web_app_trigger_haptic_feedback',
|
|
20
25
|
notificationOccurred: 'web_app_trigger_haptic_feedback',
|
|
@@ -28,7 +33,10 @@ export class HapticFeedback {
|
|
|
28
33
|
* @param style - impact style.
|
|
29
34
|
*/
|
|
30
35
|
impactOccurred(style: ImpactHapticFeedbackStyle): void {
|
|
31
|
-
this.postEvent('web_app_trigger_haptic_feedback', {
|
|
36
|
+
this.postEvent('web_app_trigger_haptic_feedback', {
|
|
37
|
+
type: 'impact',
|
|
38
|
+
impact_style: style,
|
|
39
|
+
});
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,171 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
export {
|
|
2
|
+
BackButton,
|
|
3
|
+
type BackButtonEventName,
|
|
4
|
+
type BackButtonEventListener,
|
|
5
|
+
} from './back-button/index.js';
|
|
6
|
+
export {
|
|
7
|
+
createPostEvent,
|
|
8
|
+
isIframe,
|
|
9
|
+
on,
|
|
10
|
+
off,
|
|
11
|
+
once,
|
|
12
|
+
postEvent,
|
|
13
|
+
request,
|
|
14
|
+
subscribe,
|
|
15
|
+
unsubscribe,
|
|
16
|
+
MethodUnsupportedError,
|
|
17
|
+
ParameterUnsupportedError,
|
|
18
|
+
type HeaderColorKey,
|
|
19
|
+
type InvoiceStatus,
|
|
20
|
+
type ImpactHapticFeedbackStyle,
|
|
21
|
+
type MiniAppsMethodName,
|
|
22
|
+
type MiniAppsEventName,
|
|
23
|
+
type MiniAppsEventParams,
|
|
24
|
+
type MiniAppsEventListener,
|
|
25
|
+
type MiniAppsGlobalEventListener,
|
|
26
|
+
type MiniAppsEmptyMethodName,
|
|
27
|
+
type MiniAppsMethodAcceptParams,
|
|
28
|
+
type MiniAppsMethodParams,
|
|
29
|
+
type MiniAppsNonEmptyMethodName,
|
|
30
|
+
type MiniAppsMethods,
|
|
31
|
+
type MiniAppsEventEmitter,
|
|
32
|
+
type MiniAppsEventHasParams,
|
|
33
|
+
type MiniAppsEvents,
|
|
34
|
+
type NotificationHapticFeedbackType,
|
|
35
|
+
type PhoneRequestedStatus,
|
|
36
|
+
type PostEvent,
|
|
37
|
+
type RequestOptions,
|
|
38
|
+
type SwitchInlineQueryChatType,
|
|
39
|
+
type WriteAccessRequestedStatus,
|
|
40
|
+
} from './bridge/index.js';
|
|
41
|
+
export {
|
|
42
|
+
classNames,
|
|
43
|
+
mergeClassNames,
|
|
44
|
+
} from './classnames/index.js';
|
|
45
|
+
export {
|
|
46
|
+
ClosingBehavior,
|
|
47
|
+
type ClosingBehaviorEventListener,
|
|
48
|
+
type ClosingBehaviorEventName,
|
|
49
|
+
type ClosingBehaviorEvents,
|
|
50
|
+
} from './closing-behavior/index.js';
|
|
51
|
+
export { CloudStorage } from './cloud-storage/index.js';
|
|
52
|
+
export {
|
|
53
|
+
isRGB,
|
|
54
|
+
isRGBShort,
|
|
55
|
+
isColorDark,
|
|
56
|
+
toRGB,
|
|
57
|
+
type RGB,
|
|
58
|
+
type RGBShort,
|
|
59
|
+
} from './colors/index.js';
|
|
60
|
+
export { HapticFeedback } from './haptic-feedback/index.js';
|
|
61
|
+
export {
|
|
62
|
+
init,
|
|
63
|
+
type InitOptions,
|
|
64
|
+
type InitResult,
|
|
65
|
+
} from './init/index.js';
|
|
66
|
+
export {
|
|
67
|
+
chatParser,
|
|
68
|
+
InitData,
|
|
69
|
+
initDataParser,
|
|
70
|
+
parseInitData,
|
|
71
|
+
userParser,
|
|
72
|
+
type Chat,
|
|
73
|
+
type ChatType,
|
|
74
|
+
type InitDataParsed,
|
|
75
|
+
type User,
|
|
76
|
+
} from './init-data/index.js';
|
|
77
|
+
export {
|
|
78
|
+
Invoice,
|
|
79
|
+
type InvoiceEvents,
|
|
80
|
+
type InvoiceEventListener,
|
|
81
|
+
type InvoiceEventName,
|
|
82
|
+
} from './invoice/index.js';
|
|
83
|
+
export {
|
|
84
|
+
launchParamsParser,
|
|
85
|
+
parseLaunchParams,
|
|
86
|
+
retrieveLaunchData,
|
|
87
|
+
serializeLaunchParams,
|
|
88
|
+
type LaunchParams,
|
|
89
|
+
type LaunchData,
|
|
90
|
+
} from './launch-params/index.js';
|
|
91
|
+
export {
|
|
92
|
+
MainButton,
|
|
93
|
+
type MainButtonParams,
|
|
94
|
+
type MainButtonProps,
|
|
95
|
+
type MainButtonEvents,
|
|
96
|
+
type MainButtonEventName,
|
|
97
|
+
type MainButtonEventListener,
|
|
98
|
+
} from './main-button/index.js';
|
|
99
|
+
export {
|
|
100
|
+
MiniApp,
|
|
101
|
+
type MiniAppHeaderColor,
|
|
102
|
+
type MiniAppEventName,
|
|
103
|
+
type MiniAppEventListener,
|
|
104
|
+
type MiniAppEvents,
|
|
105
|
+
type MiniAppProps,
|
|
106
|
+
} from './mini-app/index.js';
|
|
107
|
+
export {
|
|
108
|
+
isTMA,
|
|
109
|
+
isRecord,
|
|
110
|
+
} from './misc/index.js';
|
|
111
|
+
export {
|
|
112
|
+
getHash,
|
|
113
|
+
HashNavigator,
|
|
114
|
+
Navigator,
|
|
115
|
+
type NavigationEntry,
|
|
116
|
+
type NavigatorConEntry,
|
|
117
|
+
type NavigatorOptions,
|
|
118
|
+
type HashNavigatorOptions,
|
|
119
|
+
type HashNavigatorEventsMap,
|
|
120
|
+
type HashNavigatorEventListener,
|
|
121
|
+
type HashNavigatorEventName,
|
|
122
|
+
} from './navigation/index.js';
|
|
123
|
+
export {
|
|
124
|
+
Popup,
|
|
125
|
+
type PopupEventName,
|
|
126
|
+
type PopupEventListener,
|
|
127
|
+
type PopupEvents,
|
|
128
|
+
type OpenPopupOptions,
|
|
129
|
+
type OpenPopupOptionsButton,
|
|
130
|
+
} from './popup/index.js';
|
|
131
|
+
export {
|
|
132
|
+
QRScanner,
|
|
133
|
+
type QRScannerEventListener,
|
|
134
|
+
type QRScannerEventName,
|
|
135
|
+
type QRScannerEvents,
|
|
136
|
+
} from './qr-scanner/index.js';
|
|
137
|
+
export { supports } from './supports/index.js';
|
|
138
|
+
export {
|
|
139
|
+
parseThemeParams,
|
|
140
|
+
requestThemeParams,
|
|
141
|
+
serializeThemeParams,
|
|
142
|
+
themeParamsParser,
|
|
143
|
+
ThemeParams,
|
|
144
|
+
type ThemeParamsEventListener,
|
|
145
|
+
type ThemeParamsEventName,
|
|
146
|
+
type ThemeParamsEvents,
|
|
147
|
+
type ThemeParamsKey,
|
|
148
|
+
type ThemeParamsParsed,
|
|
149
|
+
} from './theme-params/index.js';
|
|
150
|
+
export type {
|
|
151
|
+
RequestId,
|
|
152
|
+
CreateRequestIdFunc,
|
|
153
|
+
} from './types/index.js';
|
|
154
|
+
export { Utils } from './utils/index.js';
|
|
155
|
+
export {
|
|
156
|
+
compareVersions,
|
|
157
|
+
type Version,
|
|
158
|
+
} from './version/index.js';
|
|
159
|
+
export {
|
|
160
|
+
requestViewport,
|
|
161
|
+
Viewport,
|
|
162
|
+
type RequestViewportResult,
|
|
163
|
+
type ViewportProps,
|
|
164
|
+
type ViewportEventName,
|
|
165
|
+
type ViewportEventListener,
|
|
166
|
+
type ViewportEvents,
|
|
167
|
+
} from './viewport/index.js';
|
|
168
|
+
export {
|
|
169
|
+
setTargetOrigin,
|
|
170
|
+
setDebug,
|
|
171
|
+
} from './globals.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { on } from '~/bridge/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates style html element which contains styles sent from the Telegram application.
|
|
5
|
+
*/
|
|
6
|
+
export function catchCustomStyles(): void {
|
|
7
|
+
const element = document.createElement('style');
|
|
8
|
+
element.id = 'telegram-custom-styles';
|
|
9
|
+
document.head.appendChild(element);
|
|
10
|
+
|
|
11
|
+
on('set_custom_style', (html) => {
|
|
12
|
+
// It is safe to use innerHTML here as long as style tag has a special behavior related
|
|
13
|
+
// to the specified content. In case, any script will be passed here, it will not be
|
|
14
|
+
// executed.
|
|
15
|
+
element.innerHTML = html;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { getStorageValue, saveStorageValue } from '../../storage.js';
|
|
1
|
+
import { BackButton } from '~/back-button/index.js';
|
|
2
|
+
import { getStorageValue, saveStorageValue } from '~/storage.js';
|
|
3
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Creates BackButton instance using last locally saved data also saving each state in
|
|
@@ -19,7 +17,7 @@ export function createBackButton(
|
|
|
19
17
|
const { isVisible = false } = isPageReload ? getStorageValue('back-button') || {} : {};
|
|
20
18
|
const component = new BackButton(isVisible, version, postEvent);
|
|
21
19
|
|
|
22
|
-
component.on('
|
|
20
|
+
component.on('change', () => {
|
|
23
21
|
saveStorageValue('back-button', { isVisible: component.isVisible });
|
|
24
22
|
});
|
|
25
23
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { getStorageValue, saveStorageValue } from '../../storage.js';
|
|
1
|
+
import { ClosingBehavior } from '~/closing-behavior/index.js';
|
|
2
|
+
import { getStorageValue, saveStorageValue } from '~/storage.js';
|
|
3
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Creates ClosingBehaviour instance using last locally saved data also saving each state in
|
|
@@ -13,12 +11,12 @@ import { getStorageValue, saveStorageValue } from '../../storage.js';
|
|
|
13
11
|
export function createClosingBehavior(
|
|
14
12
|
isPageReload: boolean,
|
|
15
13
|
postEvent: PostEvent,
|
|
16
|
-
):
|
|
14
|
+
): ClosingBehavior {
|
|
17
15
|
const { isConfirmationNeeded = false } = isPageReload ? getStorageValue('closing-behavior') || {} : {};
|
|
18
16
|
|
|
19
|
-
const component = new
|
|
17
|
+
const component = new ClosingBehavior(isConfirmationNeeded, postEvent);
|
|
20
18
|
|
|
21
|
-
component.on('
|
|
19
|
+
component.on('change', () => saveStorageValue('closing-behavior', {
|
|
22
20
|
isConfirmationNeeded: component.isConfirmationNeeded,
|
|
23
21
|
}));
|
|
24
22
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { getStorageValue, saveStorageValue } from '../../storage.js';
|
|
1
|
+
import { MainButton } from '~/main-button/index.js';
|
|
2
|
+
import { getStorageValue, saveStorageValue } from '~/storage.js';
|
|
3
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
4
|
+
import type { RGB } from '~/colors/index.js';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Creates MainButton instance using last locally saved data also saving each state in
|
|
@@ -23,36 +21,31 @@ export function createMainButton(
|
|
|
23
21
|
backgroundColor: stateBackgroundColor = backgroundColor,
|
|
24
22
|
isEnabled = false,
|
|
25
23
|
isVisible = false,
|
|
26
|
-
|
|
24
|
+
isLoaderVisible = false,
|
|
27
25
|
textColor: stateTextColor = textColor,
|
|
28
26
|
text = '',
|
|
29
27
|
} = isPageReload ? getStorageValue('main-button') || {} : {};
|
|
30
28
|
|
|
31
|
-
const component = new MainButton(
|
|
32
|
-
stateBackgroundColor,
|
|
29
|
+
const component = new MainButton({
|
|
30
|
+
backgroundColor: stateBackgroundColor,
|
|
33
31
|
isEnabled,
|
|
32
|
+
isLoaderVisible,
|
|
34
33
|
isVisible,
|
|
35
|
-
isProgressVisible,
|
|
36
|
-
text,
|
|
37
|
-
stateTextColor,
|
|
38
34
|
postEvent,
|
|
39
|
-
|
|
35
|
+
text,
|
|
36
|
+
textColor: stateTextColor,
|
|
37
|
+
});
|
|
40
38
|
|
|
41
39
|
const saveState = () => saveStorageValue('main-button', {
|
|
42
40
|
backgroundColor: component.backgroundColor,
|
|
43
41
|
isEnabled: component.isEnabled,
|
|
42
|
+
isLoaderVisible: component.isLoaderVisible,
|
|
44
43
|
isVisible: component.isVisible,
|
|
45
|
-
isProgressVisible: component.isProgressVisible,
|
|
46
44
|
text: component.text,
|
|
47
45
|
textColor: component.textColor,
|
|
48
46
|
});
|
|
49
47
|
|
|
50
|
-
component.on('
|
|
51
|
-
component.on('isEnabledChanged', saveState);
|
|
52
|
-
component.on('isVisibleChanged', saveState);
|
|
53
|
-
component.on('isProgressVisibleChanged', saveState);
|
|
54
|
-
component.on('textColorChanged', saveState);
|
|
55
|
-
component.on('textChanged', saveState);
|
|
48
|
+
component.on('change', saveState);
|
|
56
49
|
|
|
57
50
|
return component;
|
|
58
51
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MiniApp } from '~/mini-app/index.js';
|
|
2
|
+
import { getStorageValue, saveStorageValue } from '~/storage.js';
|
|
3
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
4
|
+
import type { RGB } from '~/colors/index.js';
|
|
5
|
+
import type { Version } from '~/version/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates MiniApp instance using last locally saved data also saving each state in
|
|
9
|
+
* the storage.
|
|
10
|
+
* @param isPageReload - was current page reloaded.
|
|
11
|
+
* @param backgroundColor - web app background color.
|
|
12
|
+
* @param version - platform version.
|
|
13
|
+
* @param botInline - is Mini App launched in inline mode.
|
|
14
|
+
* @param postEvent - Bridge postEvent function
|
|
15
|
+
*/
|
|
16
|
+
export function createMiniApp(
|
|
17
|
+
isPageReload: boolean,
|
|
18
|
+
backgroundColor: RGB,
|
|
19
|
+
version: Version,
|
|
20
|
+
botInline: boolean,
|
|
21
|
+
postEvent: PostEvent,
|
|
22
|
+
): MiniApp {
|
|
23
|
+
const {
|
|
24
|
+
backgroundColor: stateBackgroundColor = backgroundColor,
|
|
25
|
+
headerColor = 'bg_color',
|
|
26
|
+
} = isPageReload ? getStorageValue('mini-app') || {} : {};
|
|
27
|
+
|
|
28
|
+
const component = new MiniApp({
|
|
29
|
+
headerColor,
|
|
30
|
+
backgroundColor: stateBackgroundColor,
|
|
31
|
+
version,
|
|
32
|
+
botInline,
|
|
33
|
+
postEvent,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const saveState = () => saveStorageValue('mini-app', {
|
|
37
|
+
backgroundColor: component.backgroundColor,
|
|
38
|
+
headerColor: component.headerColor,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
component.on('change', saveState);
|
|
42
|
+
|
|
43
|
+
return component;
|
|
44
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { ThemeParams } from '../../components/index.js';
|
|
1
|
+
import { ThemeParams, type ThemeParamsParsed } from '~/theme-params/index.js';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Creates synced instance of ThemeParams.
|
|
7
5
|
* @param params - theme parameters.
|
|
8
6
|
*/
|
|
9
|
-
export function createThemeParams(params:
|
|
7
|
+
export function createThemeParams(params: ThemeParamsParsed): ThemeParams {
|
|
10
8
|
const themeParams = new ThemeParams(params);
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
themeParams.listen();
|
|
13
10
|
return themeParams;
|
|
14
11
|
}
|