@tma.js/sdk 0.13.3 → 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 -7
- 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 +2245 -1025
- 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 +31 -21
- 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 -85
- package/dist/dts/components/ThemeParams/index.d.ts +0 -2
- package/dist/dts/components/ThemeParams/types.d.ts +0 -6
- 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 -50
- 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 -168
- package/src/components/ThemeParams/index.ts +0 -2
- package/src/components/ThemeParams/types.ts +0 -11
- 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 -142
- 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
|
@@ -1,54 +1,104 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { getStorageValue, saveStorageValue } from '~/storage.js';
|
|
2
|
+
import { requestViewport, Viewport } from '~/viewport/index.js';
|
|
3
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
4
|
+
import type { Platform } from '~/types/index.js';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Attempts to create Viewport instance using known parameters and local storage.
|
|
8
|
+
* @param isPageReload - was page reloaded.
|
|
9
|
+
* @param platform - platform identifier.
|
|
10
|
+
* @param postEvent - Bridge postEvent function.
|
|
11
|
+
*/
|
|
12
|
+
function tryCreate(
|
|
13
|
+
isPageReload: boolean,
|
|
14
|
+
platform: Platform,
|
|
15
|
+
postEvent: PostEvent,
|
|
16
|
+
): Viewport | null {
|
|
17
|
+
if (isPageReload || platform === 'macos' || platform === 'web' || platform === 'weba') {
|
|
18
|
+
return new Viewport({
|
|
19
|
+
height: window.innerHeight,
|
|
20
|
+
isExpanded: true,
|
|
21
|
+
postEvent,
|
|
22
|
+
stableHeight: window.innerHeight,
|
|
23
|
+
width: window.innerWidth,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const state = getStorageValue('viewport');
|
|
28
|
+
if (state) {
|
|
29
|
+
return new Viewport({ ...state, postEvent });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Synchronizes specified Viewport instance with Telegram application and always saves its state
|
|
37
|
+
* in local storage.
|
|
38
|
+
* @param viewport - Viewport instance.
|
|
39
|
+
*/
|
|
40
|
+
function bind(viewport: Viewport): Viewport {
|
|
41
|
+
viewport.listen();
|
|
42
|
+
|
|
43
|
+
// TODO: Should probably use throttle for height.
|
|
44
|
+
viewport.on('change', () => saveStorageValue('viewport', {
|
|
45
|
+
height: viewport.height,
|
|
46
|
+
isExpanded: viewport.isExpanded,
|
|
47
|
+
stableHeight: viewport.stableHeight,
|
|
48
|
+
width: viewport.width,
|
|
49
|
+
}));
|
|
5
50
|
|
|
6
|
-
|
|
51
|
+
return viewport;
|
|
52
|
+
}
|
|
7
53
|
|
|
8
54
|
/**
|
|
9
|
-
* Creates Viewport instance using
|
|
10
|
-
*
|
|
11
|
-
* @param isPageReload - was
|
|
12
|
-
* @param platform -
|
|
13
|
-
* @param postEvent - Bridge postEvent function
|
|
55
|
+
* Creates Viewport instance using its actual state from the storage. Otherwise, creates it
|
|
56
|
+
* with default parameters.
|
|
57
|
+
* @param isPageReload - was page reloaded.
|
|
58
|
+
* @param platform - platform identifier.
|
|
59
|
+
* @param postEvent - Bridge postEvent function.
|
|
14
60
|
*/
|
|
15
|
-
export
|
|
61
|
+
export function createViewportSync(
|
|
16
62
|
isPageReload: boolean,
|
|
17
63
|
platform: Platform,
|
|
18
64
|
postEvent: PostEvent,
|
|
19
|
-
):
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// MacOS and Web K versions do not support requesting current viewport information. That's why we
|
|
35
|
-
// should construct Viewport instance by ourselves.
|
|
36
|
-
const component = platform === 'macos' || platform === 'web'
|
|
37
|
-
? createSynced()
|
|
38
|
-
: await Viewport.synced({ postEvent });
|
|
39
|
-
|
|
40
|
-
const saveState = () => saveStorageValue('viewport', {
|
|
41
|
-
height: component.height,
|
|
42
|
-
isExpanded: component.isExpanded,
|
|
43
|
-
stableHeight: component.stableHeight,
|
|
44
|
-
width: component.width,
|
|
65
|
+
): Viewport {
|
|
66
|
+
const viewport = bind(
|
|
67
|
+
tryCreate(isPageReload, platform, postEvent) || new Viewport({
|
|
68
|
+
width: 0,
|
|
69
|
+
height: 0,
|
|
70
|
+
isExpanded: false,
|
|
71
|
+
postEvent,
|
|
72
|
+
stableHeight: 0,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
viewport.sync({ postEvent, timeout: 100 }).catch((e) => {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.error('Unable to actualize viewport state', e);
|
|
45
79
|
});
|
|
46
80
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
component.on('isExpandedChanged', saveState);
|
|
50
|
-
component.on('stableHeightChanged', saveState);
|
|
51
|
-
component.on('widthChanged', saveState);
|
|
81
|
+
return viewport;
|
|
82
|
+
}
|
|
52
83
|
|
|
53
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Creates Viewport instance using its actual state from the Telegram application.
|
|
86
|
+
* @param isPageReload - was page reloaded.
|
|
87
|
+
* @param platform - platform identifier.
|
|
88
|
+
* @param postEvent - Bridge postEvent function.
|
|
89
|
+
*/
|
|
90
|
+
export async function createViewportAsync(
|
|
91
|
+
isPageReload: boolean,
|
|
92
|
+
platform: Platform,
|
|
93
|
+
postEvent: PostEvent,
|
|
94
|
+
): Promise<Viewport> {
|
|
95
|
+
return bind(
|
|
96
|
+
tryCreate(isPageReload, platform, postEvent)
|
|
97
|
+
|| await requestViewport({ postEvent, timeout: 100 })
|
|
98
|
+
.then(({ height, isStateStable, ...rest }) => new Viewport({
|
|
99
|
+
...rest,
|
|
100
|
+
height,
|
|
101
|
+
stableHeight: isStateStable ? height : 0,
|
|
102
|
+
})),
|
|
103
|
+
);
|
|
54
104
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './createBackButton.js';
|
|
2
2
|
export * from './createClosingBehavior.js';
|
|
3
3
|
export * from './createMainButton.js';
|
|
4
|
+
export * from './createMiniApp.js';
|
|
4
5
|
export * from './createRequestIdGenerator.js';
|
|
5
6
|
export * from './createThemeParams.js';
|
|
6
7
|
export * from './createViewport.js';
|
|
7
|
-
export * from './createWebApp.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { setCSSVar } from '~/init/css/setCSSVar.js';
|
|
2
|
+
import type { MiniApp } from '~/mini-app/index.js';
|
|
3
|
+
import type { ThemeParams } from '~/theme-params/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates CSS variables connected with WebApp background and header colors based on
|
|
7
|
+
* passed WebApp and ThemeParams instances.
|
|
8
|
+
*
|
|
9
|
+
* Created variables:
|
|
10
|
+
* - `--tg-background-color`
|
|
11
|
+
* - `--tg-header-color`
|
|
12
|
+
*
|
|
13
|
+
* Variables are being automatically updated in case, corresponding properties are updating.
|
|
14
|
+
*
|
|
15
|
+
* @param miniApp - MiniApp instance.
|
|
16
|
+
* @param themeParams - ThemeParams instance.
|
|
17
|
+
*/
|
|
18
|
+
export function bindMiniAppCSSVars(miniApp: MiniApp, themeParams: ThemeParams): void {
|
|
19
|
+
const actualizeBackground = () => {
|
|
20
|
+
setCSSVar('--tg-background-color', miniApp.backgroundColor);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const actualizeHeader = () => {
|
|
24
|
+
const {
|
|
25
|
+
backgroundColor,
|
|
26
|
+
secondaryBackgroundColor,
|
|
27
|
+
} = themeParams;
|
|
28
|
+
|
|
29
|
+
if (miniApp.headerColor === 'bg_color') {
|
|
30
|
+
if (backgroundColor) {
|
|
31
|
+
setCSSVar('--tg-header-color', backgroundColor);
|
|
32
|
+
}
|
|
33
|
+
} else if (miniApp.headerColor === 'secondary_bg_color') {
|
|
34
|
+
if (secondaryBackgroundColor) {
|
|
35
|
+
setCSSVar('--tg-header-color', secondaryBackgroundColor);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
setCSSVar('--tg-header-color', miniApp.headerColor);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
themeParams.on('change', actualizeHeader);
|
|
43
|
+
miniApp.on('change:backgroundColor', actualizeBackground);
|
|
44
|
+
miniApp.on('change:headerColor', actualizeHeader);
|
|
45
|
+
|
|
46
|
+
actualizeBackground();
|
|
47
|
+
actualizeHeader();
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ThemeParams } from '~/theme-params/index.js';
|
|
2
|
+
|
|
3
|
+
import { setCSSVar } from './setCSSVar.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates CSS variables connected with theme parameters. Created CSS variables names are
|
|
7
|
+
* following the pattern "--tg-theme-{name}". {name} is a theme parameters key name converted
|
|
8
|
+
* from snake to kebab case.
|
|
9
|
+
*
|
|
10
|
+
* Variables are being automatically updated in case, corresponding properties
|
|
11
|
+
* updated in passed ThemeParams instance.
|
|
12
|
+
*
|
|
13
|
+
* @param themeParams - ThemeParams instance.
|
|
14
|
+
*/
|
|
15
|
+
export function bindThemeCSSVars(themeParams: ThemeParams): void {
|
|
16
|
+
const actualize = () => {
|
|
17
|
+
const state = themeParams.getState();
|
|
18
|
+
|
|
19
|
+
Object.entries(state).forEach(([k, v]) => {
|
|
20
|
+
if (v) {
|
|
21
|
+
const key = k
|
|
22
|
+
.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
23
|
+
setCSSVar(`--tg-theme-${key}`, v);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
themeParams.on('change', actualize);
|
|
29
|
+
|
|
30
|
+
actualize();
|
|
31
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Viewport } from '~/viewport/index.js';
|
|
2
|
+
|
|
3
|
+
import { setCSSVar } from './setCSSVar.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Accepts Viewport instance and sets CSS variables connected with viewport
|
|
7
|
+
* sizes.
|
|
8
|
+
*
|
|
9
|
+
* Be careful using this function as long as it can impact application
|
|
10
|
+
* performance. Viewport size is changing rather often, this makes CSS
|
|
11
|
+
* variables update, which leads to possible layout redraw.
|
|
12
|
+
*
|
|
13
|
+
* Variables:
|
|
14
|
+
* - `--tg-viewport-height`
|
|
15
|
+
* - `--tg-viewport-width`
|
|
16
|
+
* - `--tg-viewport-stable-height`
|
|
17
|
+
*
|
|
18
|
+
* Variables are being automatically updated in case, corresponding properties
|
|
19
|
+
* updated in passed Viewport instance.
|
|
20
|
+
*
|
|
21
|
+
* @param viewport - Viewport instance.
|
|
22
|
+
*/
|
|
23
|
+
export function bindViewportCSSVars(viewport: Viewport): void {
|
|
24
|
+
const setHeight = () => setCSSVar('--tg-viewport-height', `${viewport.height}px`);
|
|
25
|
+
const setWidth = () => setCSSVar('--tg-viewport-width', `${viewport.width}px`);
|
|
26
|
+
const setStableHeight = () => setCSSVar('--tg-viewport-height', `${viewport.stableHeight}px`);
|
|
27
|
+
|
|
28
|
+
// TODO: Should probably add debounce or throttle.
|
|
29
|
+
viewport.on('change:height', setHeight);
|
|
30
|
+
viewport.on('change:width', setWidth);
|
|
31
|
+
viewport.on('change:stableHeight', setStableHeight);
|
|
32
|
+
|
|
33
|
+
setHeight();
|
|
34
|
+
setWidth();
|
|
35
|
+
setStableHeight();
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './processCSSVarsOption.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MiniApp } from '~/mini-app/index.js';
|
|
2
|
+
import type { ThemeParams } from '~/theme-params/index.js';
|
|
3
|
+
import type { Viewport } from '~/viewport/index.js';
|
|
4
|
+
|
|
5
|
+
import { bindMiniAppCSSVars } from './bindMiniAppCSSVars.js';
|
|
6
|
+
import { bindThemeCSSVars } from './bindThemeCSSVars.js';
|
|
7
|
+
import { bindViewportCSSVars } from './bindViewportCSSVars.js';
|
|
8
|
+
import type { InitCSSVarsOption, InitCSSVarsSpecificOption } from '../types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts init cssVars option to more narrow type.
|
|
12
|
+
* @param option - option value.
|
|
13
|
+
*/
|
|
14
|
+
function parseCSSVarsOptions(option: InitCSSVarsOption): InitCSSVarsSpecificOption {
|
|
15
|
+
if (typeof option === 'object') {
|
|
16
|
+
return option;
|
|
17
|
+
}
|
|
18
|
+
return option
|
|
19
|
+
? {
|
|
20
|
+
themeParams: true,
|
|
21
|
+
viewport: true,
|
|
22
|
+
miniApp: true,
|
|
23
|
+
}
|
|
24
|
+
: {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Process initialization CSS vars option.
|
|
29
|
+
* @param option - option value.
|
|
30
|
+
* @param miniApp - MiniApp instance.
|
|
31
|
+
* @param themeParams - ThemeParams instance.
|
|
32
|
+
* @param viewportOrPromise - Viewport instance or promise resolving it.
|
|
33
|
+
*/
|
|
34
|
+
export function processCSSVars(
|
|
35
|
+
option: InitCSSVarsOption,
|
|
36
|
+
miniApp: MiniApp,
|
|
37
|
+
themeParams: ThemeParams,
|
|
38
|
+
viewportOrPromise: Viewport | Promise<Viewport>,
|
|
39
|
+
): void {
|
|
40
|
+
const cssVarsOptions = parseCSSVarsOptions(option);
|
|
41
|
+
|
|
42
|
+
if (cssVarsOptions.miniApp) {
|
|
43
|
+
bindMiniAppCSSVars(miniApp, themeParams);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (cssVarsOptions.themeParams) {
|
|
47
|
+
bindThemeCSSVars(themeParams);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (cssVarsOptions.viewport) {
|
|
51
|
+
if (viewportOrPromise instanceof Promise) {
|
|
52
|
+
viewportOrPromise.then(bindViewportCSSVars);
|
|
53
|
+
} else {
|
|
54
|
+
bindViewportCSSVars(viewportOrPromise);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/init/init.ts
CHANGED
|
@@ -1,167 +1,125 @@
|
|
|
1
|
+
import { createPostEvent, isIframe, on } from '~/bridge/index.js';
|
|
2
|
+
import { CloudStorage } from '~/cloud-storage/index.js';
|
|
3
|
+
import { HapticFeedback } from '~/haptic-feedback/index.js';
|
|
4
|
+
import { catchCustomStyles } from '~/init/catchCustomStyles.js';
|
|
1
5
|
import {
|
|
2
|
-
isIframe,
|
|
3
|
-
setDebug,
|
|
4
|
-
setTargetOrigin,
|
|
5
|
-
on,
|
|
6
|
-
createPostEvent,
|
|
7
|
-
postEvent as bridgePostEvent,
|
|
8
|
-
} from '@tma.js/bridge';
|
|
9
|
-
import { withTimeout } from '@tma.js/utils';
|
|
10
|
-
import { parse, retrieveLaunchData } from '@tma.js/launch-params';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
CloudStorage,
|
|
14
|
-
HapticFeedback,
|
|
15
|
-
InitData,
|
|
16
|
-
Popup,
|
|
17
|
-
QRScanner,
|
|
18
|
-
} from '../components/index.js';
|
|
19
|
-
import {
|
|
20
|
-
bindThemeCSSVariables,
|
|
21
|
-
bindViewportCSSVariables,
|
|
22
|
-
bindWebAppVariables,
|
|
23
|
-
parseCSSVarsOptions,
|
|
24
|
-
} from './css.js';
|
|
25
|
-
import {
|
|
26
|
-
createThemeParams,
|
|
27
6
|
createBackButton,
|
|
7
|
+
createClosingBehavior,
|
|
28
8
|
createMainButton,
|
|
29
|
-
|
|
30
|
-
createWebApp,
|
|
9
|
+
createMiniApp,
|
|
31
10
|
createRequestIdGenerator,
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
createThemeParams, createViewportAsync,
|
|
12
|
+
createViewportSync,
|
|
13
|
+
} from '~/init/creators/index.js';
|
|
14
|
+
import { processCSSVars } from '~/init/css/index.js';
|
|
15
|
+
import { InitData } from '~/init-data/index.js';
|
|
16
|
+
import { Invoice } from '~/invoice/index.js';
|
|
17
|
+
import { retrieveLaunchData } from '~/launch-params/index.js';
|
|
18
|
+
import { Popup } from '~/popup/index.js';
|
|
19
|
+
import { QRScanner } from '~/qr-scanner/index.js';
|
|
20
|
+
import { Utils } from '~/utils/index.js';
|
|
34
21
|
|
|
35
22
|
import type { InitOptions, InitResult } from './types.js';
|
|
36
23
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*/
|
|
41
|
-
async function actualInit(options: InitOptions = {}): Promise<InitResult> {
|
|
24
|
+
type ComputedInitResult<O> = O extends { async: true } ? Promise<InitResult> : InitResult;
|
|
25
|
+
|
|
26
|
+
export function init<O extends InitOptions>(options: O): ComputedInitResult<O> {
|
|
42
27
|
const {
|
|
43
|
-
|
|
28
|
+
async = false,
|
|
44
29
|
cssVars = false,
|
|
45
|
-
|
|
46
|
-
acceptCustomStyles = acceptScrollbarStyle,
|
|
47
|
-
targetOrigin,
|
|
48
|
-
launchParams: launchParamsOption,
|
|
49
|
-
debug = false,
|
|
30
|
+
acceptCustomStyles = false,
|
|
50
31
|
} = options;
|
|
51
32
|
|
|
52
|
-
// Set global settings.
|
|
53
|
-
if (debug) {
|
|
54
|
-
setDebug(debug);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (typeof targetOrigin === 'string') {
|
|
58
|
-
setTargetOrigin(targetOrigin);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
33
|
// Retrieve launch data.
|
|
62
|
-
const { launchParams, isPageReload } = retrieveLaunchData({
|
|
63
|
-
currentLaunchParams: typeof launchParamsOption === 'string' || launchParamsOption instanceof URLSearchParams
|
|
64
|
-
? parse(launchParamsOption)
|
|
65
|
-
: launchParamsOption,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
34
|
const {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
buttonColor = '#000000',
|
|
78
|
-
buttonTextColor = '#ffffff',
|
|
79
|
-
} = lpThemeParams;
|
|
80
|
-
|
|
81
|
-
const createRequestId = createRequestIdGenerator();
|
|
82
|
-
const postEvent = checkCompat
|
|
83
|
-
? createPostEvent(version)
|
|
84
|
-
: bridgePostEvent;
|
|
85
|
-
const themeParams = createThemeParams(lpThemeParams);
|
|
86
|
-
const webApp = createWebApp(
|
|
35
|
+
launchParams: {
|
|
36
|
+
initData,
|
|
37
|
+
initDataRaw,
|
|
38
|
+
version,
|
|
39
|
+
platform,
|
|
40
|
+
themeParams,
|
|
41
|
+
botInline = false,
|
|
42
|
+
},
|
|
87
43
|
isPageReload,
|
|
88
|
-
|
|
89
|
-
version,
|
|
90
|
-
platform,
|
|
91
|
-
createRequestId,
|
|
92
|
-
postEvent,
|
|
93
|
-
);
|
|
44
|
+
} = retrieveLaunchData();
|
|
94
45
|
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// Apply viewport CSS variables.
|
|
112
|
-
if (createViewportCSSVars) {
|
|
113
|
-
bindViewportCSSVariables(viewport);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// In case, we are currently in iframe, it is required to listen to
|
|
117
|
-
// messages, coming from parent source to apply requested changes.
|
|
118
|
-
// The only one case, when current application was placed into iframe is
|
|
119
|
-
// web version of Telegram.
|
|
120
|
-
if (acceptCustomStyles && isIframe()) {
|
|
121
|
-
// Create special style element which is responsible for application
|
|
122
|
-
// style controlled by external app.
|
|
123
|
-
const styleElement = document.createElement('style');
|
|
124
|
-
styleElement.id = 'telegram-custom-styles';
|
|
125
|
-
document.head.appendChild(styleElement);
|
|
126
|
-
|
|
127
|
-
// Listen to custom style changes.
|
|
128
|
-
on('set_custom_style', (html) => {
|
|
129
|
-
styleElement.innerHTML = html;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Notify Telegram, iframe is ready. This will result in sending style
|
|
133
|
-
// tag html from native application.
|
|
134
|
-
postEvent('iframe_ready');
|
|
46
|
+
const createRequestId = createRequestIdGenerator();
|
|
47
|
+
const postEvent = createPostEvent(version);
|
|
48
|
+
|
|
49
|
+
// In Telegram web version we should listen to special event sent from the Telegram application
|
|
50
|
+
// to know, when we should reload the Mini App.
|
|
51
|
+
if (isIframe()) {
|
|
52
|
+
if (acceptCustomStyles) {
|
|
53
|
+
catchCustomStyles();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Notify Telegram, iframe is ready. This will result in sending style tag html from native
|
|
57
|
+
// application which is used in catchCustomStyles function. We should call this method also
|
|
58
|
+
// to start receiving "reload_iframe" events from the Telegram application.
|
|
59
|
+
postEvent('iframe_ready', { reload_supported: true });
|
|
60
|
+
on('reload_iframe', () => window.location.reload());
|
|
135
61
|
}
|
|
136
62
|
|
|
137
|
-
const result: InitResult = {
|
|
63
|
+
const result: Omit<InitResult, 'viewport'> = {
|
|
138
64
|
backButton: createBackButton(isPageReload, version, postEvent),
|
|
139
65
|
closingBehavior: createClosingBehavior(isPageReload, postEvent),
|
|
140
66
|
cloudStorage: new CloudStorage(version, createRequestId, postEvent),
|
|
141
|
-
|
|
142
|
-
|
|
67
|
+
createRequestId,
|
|
68
|
+
hapticFeedback: new HapticFeedback(version, postEvent),
|
|
69
|
+
invoice: new Invoice(version, postEvent),
|
|
70
|
+
mainButton: createMainButton(
|
|
71
|
+
isPageReload,
|
|
72
|
+
themeParams.buttonColor || '#000000',
|
|
73
|
+
themeParams.buttonTextColor || '#ffffff',
|
|
74
|
+
postEvent,
|
|
75
|
+
),
|
|
76
|
+
miniApp: createMiniApp(
|
|
77
|
+
isPageReload,
|
|
78
|
+
themeParams.backgroundColor || '#ffffff',
|
|
79
|
+
version,
|
|
80
|
+
botInline,
|
|
81
|
+
postEvent,
|
|
82
|
+
),
|
|
143
83
|
popup: new Popup(version, postEvent),
|
|
144
84
|
postEvent,
|
|
145
85
|
qrScanner: new QRScanner(version, postEvent),
|
|
146
|
-
themeParams,
|
|
147
|
-
|
|
148
|
-
|
|
86
|
+
themeParams: createThemeParams(themeParams),
|
|
87
|
+
utils: new Utils(version, createRequestId, postEvent),
|
|
88
|
+
...(initData
|
|
89
|
+
// Init data could be missing in case, application was launched via InlineKeyboardButton.
|
|
90
|
+
? {
|
|
91
|
+
initData: new InitData(initData),
|
|
92
|
+
initDataRaw,
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
149
95
|
};
|
|
150
96
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
97
|
+
const viewport = async
|
|
98
|
+
? createViewportAsync(isPageReload, platform, postEvent)
|
|
99
|
+
: createViewportSync(isPageReload, platform, postEvent);
|
|
100
|
+
|
|
101
|
+
if (viewport instanceof Promise) {
|
|
102
|
+
return viewport.then((vp) => {
|
|
103
|
+
processCSSVars(
|
|
104
|
+
cssVars,
|
|
105
|
+
result.miniApp,
|
|
106
|
+
result.themeParams,
|
|
107
|
+
vp,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
...result,
|
|
112
|
+
viewport: vp,
|
|
113
|
+
};
|
|
114
|
+
}) as ComputedInitResult<O>;
|
|
156
115
|
}
|
|
157
116
|
|
|
158
|
-
|
|
159
|
-
|
|
117
|
+
processCSSVars(
|
|
118
|
+
cssVars,
|
|
119
|
+
result.miniApp,
|
|
120
|
+
result.themeParams,
|
|
121
|
+
viewport,
|
|
122
|
+
);
|
|
160
123
|
|
|
161
|
-
|
|
162
|
-
* Initializes all SDK components.
|
|
163
|
-
* @param options - initialization options.
|
|
164
|
-
*/
|
|
165
|
-
export function init(options: InitOptions = {}): Promise<InitResult> {
|
|
166
|
-
return withTimeout(actualInit(options), options.timeout || 1000);
|
|
124
|
+
return { ...result, viewport } as ComputedInitResult<O>;
|
|
167
125
|
}
|