@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.
- 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 +2254 -1027
- 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 +119 -154
- 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,311 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from '@tma.js/event-emitter';
|
|
2
|
-
import { compareVersions, type Version } from '@tma.js/utils';
|
|
3
|
-
import { isRGB, isColorDark, type RGB } from '@tma.js/colors';
|
|
4
|
-
import {
|
|
5
|
-
postEvent as defaultPostEvent,
|
|
6
|
-
supports,
|
|
7
|
-
request,
|
|
8
|
-
type PhoneRequestedStatus,
|
|
9
|
-
type WriteAccessRequestedStatus,
|
|
10
|
-
type InvoiceStatus,
|
|
11
|
-
type PostEvent,
|
|
12
|
-
} from '@tma.js/bridge';
|
|
13
|
-
import type { Platform } from '@tma.js/launch-params';
|
|
14
|
-
|
|
15
|
-
import { formatURL } from '../../url.js';
|
|
16
|
-
import { State } from '../../state/index.js';
|
|
17
|
-
import { createSupportsFunc, createSupportsParamFunc, type SupportsFunc } from '../../supports.js';
|
|
18
|
-
|
|
19
|
-
import type { ColorScheme } from '../../types.js';
|
|
20
|
-
import type { WebAppEvents, WebAppHeaderColor, WebAppState } from './types.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Provides common Mini Apps functionality not covered by other system
|
|
24
|
-
* components.
|
|
25
|
-
*/
|
|
26
|
-
export class WebApp {
|
|
27
|
-
private readonly ee = new EventEmitter<WebAppEvents>();
|
|
28
|
-
|
|
29
|
-
private readonly state: State<WebAppState>;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
headerColor: WebAppHeaderColor,
|
|
33
|
-
backgroundColor: RGB,
|
|
34
|
-
private readonly currentVersion: Version,
|
|
35
|
-
private readonly currentPlatform: Platform,
|
|
36
|
-
private readonly createRequestId: () => string,
|
|
37
|
-
private readonly postEvent: PostEvent = defaultPostEvent,
|
|
38
|
-
) {
|
|
39
|
-
this.state = new State({
|
|
40
|
-
backgroundColor,
|
|
41
|
-
headerColor,
|
|
42
|
-
}, this.ee);
|
|
43
|
-
this.supports = createSupportsFunc(currentVersion, {
|
|
44
|
-
openInvoice: 'web_app_open_invoice',
|
|
45
|
-
readTextFromClipboard: 'web_app_read_text_from_clipboard',
|
|
46
|
-
setHeaderColor: 'web_app_set_header_color',
|
|
47
|
-
setBackgroundColor: 'web_app_set_background_color',
|
|
48
|
-
requestPhoneAccess: 'web_app_request_phone',
|
|
49
|
-
requestWriteAccess: 'web_app_request_write_access',
|
|
50
|
-
});
|
|
51
|
-
this.supportsParam = createSupportsParamFunc(currentVersion, {
|
|
52
|
-
'setHeaderColor.color': ['web_app_set_header_color', 'color'],
|
|
53
|
-
'openLink.tryInstantView': ['web_app_open_link', 'try_instant_view'],
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns current application background color.
|
|
59
|
-
*/
|
|
60
|
-
get backgroundColor(): RGB {
|
|
61
|
-
return this.state.get('backgroundColor');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Returns current application color scheme. This value is
|
|
66
|
-
* computed based on the current background color.
|
|
67
|
-
*/
|
|
68
|
-
get colorScheme(): ColorScheme {
|
|
69
|
-
return isColorDark(this.backgroundColor) ? 'dark' : 'light';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Closes the Mini App.
|
|
74
|
-
*/
|
|
75
|
-
close(): void {
|
|
76
|
-
this.postEvent('web_app_close');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Returns current application header color.
|
|
81
|
-
*/
|
|
82
|
-
get headerColor(): WebAppHeaderColor {
|
|
83
|
-
return this.state.get('headerColor');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Returns true if passed version is more than or equal to current
|
|
88
|
-
* Mini App version.
|
|
89
|
-
* @param version - compared version.
|
|
90
|
-
*/
|
|
91
|
-
isVersionAtLeast(version: Version): boolean {
|
|
92
|
-
return compareVersions(version, this.version) >= 0;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Opens a link in an external browser. The Mini App will not be closed.
|
|
97
|
-
*
|
|
98
|
-
* Note that this method can be called only in response to the user
|
|
99
|
-
* interaction with the Mini App interface (e.g. click inside the Mini App
|
|
100
|
-
* or on the main button).
|
|
101
|
-
* @param url - URL to be opened.
|
|
102
|
-
* @param tryInstantView
|
|
103
|
-
*/
|
|
104
|
-
openLink(url: string, tryInstantView?: boolean): void {
|
|
105
|
-
const formattedUrl = formatURL(url);
|
|
106
|
-
|
|
107
|
-
// If method is not supported, we are doing it in legacy way.
|
|
108
|
-
if (!supports('web_app_open_link', this.version)) {
|
|
109
|
-
window.open(formattedUrl, '_blank');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Otherwise, do it normally.
|
|
114
|
-
return this.postEvent('web_app_open_link', {
|
|
115
|
-
url: formattedUrl,
|
|
116
|
-
...(typeof tryInstantView === 'boolean' ? { try_instant_view: tryInstantView } : {}),
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Opens a Telegram link inside Telegram app. The Mini App will be closed.
|
|
122
|
-
* It expects passing link in full format, with hostname "t.me".
|
|
123
|
-
* @param url - URL to be opened.
|
|
124
|
-
* @throws {Error} URL has not allowed hostname.
|
|
125
|
-
*/
|
|
126
|
-
openTelegramLink(url: string): void {
|
|
127
|
-
const { hostname, pathname, search } = new URL(formatURL(url));
|
|
128
|
-
|
|
129
|
-
if (hostname !== 't.me') {
|
|
130
|
-
throw new Error(`URL has not allowed hostname: ${hostname}. Only "t.me" is allowed`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!supports('web_app_open_tg_link', this.version)) {
|
|
134
|
-
window.location.href = url;
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return this.postEvent('web_app_open_tg_link', { path_full: pathname + search });
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Opens an invoice using its url. It expects passing link in full format,
|
|
143
|
-
* with hostname "t.me".
|
|
144
|
-
* @param url - invoice URL.
|
|
145
|
-
*/
|
|
146
|
-
async openInvoice(url: string): Promise<InvoiceStatus> {
|
|
147
|
-
// TODO: Allow opening with slug.
|
|
148
|
-
const { hostname, pathname } = new URL(formatURL(url));
|
|
149
|
-
|
|
150
|
-
if (hostname !== 't.me') {
|
|
151
|
-
throw new Error(`Incorrect hostname: ${hostname}`);
|
|
152
|
-
}
|
|
153
|
-
// Valid examples:
|
|
154
|
-
// "/invoice/my-slug"
|
|
155
|
-
// "/$my-slug"
|
|
156
|
-
const match = pathname.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
157
|
-
|
|
158
|
-
if (match === null) {
|
|
159
|
-
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');
|
|
160
|
-
}
|
|
161
|
-
const [, , slug] = match;
|
|
162
|
-
|
|
163
|
-
const result = await request('web_app_open_invoice', { slug }, 'invoice_closed', {
|
|
164
|
-
postEvent: this.postEvent,
|
|
165
|
-
capture: ({ slug: eventSlug }) => slug === eventSlug,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
return result.status;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Adds new event listener.
|
|
173
|
-
*/
|
|
174
|
-
on = this.ee.on.bind(this.ee);
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Removes event listener.
|
|
178
|
-
*/
|
|
179
|
-
off = this.ee.off.bind(this.ee);
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Returns current Mini App platform.
|
|
183
|
-
*/
|
|
184
|
-
get platform(): Platform {
|
|
185
|
-
return this.currentPlatform;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Informs the Telegram app that the Mini App is ready to be displayed.
|
|
190
|
-
*
|
|
191
|
-
* It is recommended to call this method as early as possible, as soon as
|
|
192
|
-
* all essential interface elements loaded. Once this method called,
|
|
193
|
-
* the loading placeholder is hidden and the Mini App shown.
|
|
194
|
-
*
|
|
195
|
-
* If the method not called, the placeholder will be hidden only when
|
|
196
|
-
* the page fully loaded.
|
|
197
|
-
*/
|
|
198
|
-
ready(): void {
|
|
199
|
-
this.postEvent('web_app_ready');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Reads text from clipboard and returns string or null. null is returned
|
|
204
|
-
* in cases:
|
|
205
|
-
* - Value in clipboard is not text
|
|
206
|
-
* - Access to clipboard is not allowed
|
|
207
|
-
*/
|
|
208
|
-
async readTextFromClipboard(): Promise<string | null> {
|
|
209
|
-
// TODO: Generate request id.
|
|
210
|
-
const { data = null } = await request(
|
|
211
|
-
'web_app_read_text_from_clipboard',
|
|
212
|
-
{ req_id: this.createRequestId() },
|
|
213
|
-
'clipboard_text_received',
|
|
214
|
-
{ postEvent: this.postEvent },
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
return data;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Requests current user phone access.
|
|
222
|
-
*/
|
|
223
|
-
async requestPhoneAccess(): Promise<PhoneRequestedStatus> {
|
|
224
|
-
const { status } = await request('web_app_request_phone', 'phone_requested', {
|
|
225
|
-
postEvent: this.postEvent,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
return status;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Requests write message access to current user.
|
|
233
|
-
*/
|
|
234
|
-
async requestWriteAccess(): Promise<WriteAccessRequestedStatus> {
|
|
235
|
-
const { status } = await request('web_app_request_write_access', 'write_access_requested', {
|
|
236
|
-
postEvent: this.postEvent,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
return status;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* A method used to send data to the bot. When this method called, a
|
|
244
|
-
* service message sent to the bot containing the data of the
|
|
245
|
-
* length up to 4096 bytes, and the Mini App closed. See the field
|
|
246
|
-
* `web_app_data` in the class Message.
|
|
247
|
-
*
|
|
248
|
-
* This method is only available for Mini Apps launched via a Keyboard button.
|
|
249
|
-
* @param data - data to send to bot.
|
|
250
|
-
* @throws {Error} data has incorrect size.
|
|
251
|
-
*/
|
|
252
|
-
sendData(data: string): void {
|
|
253
|
-
// Firstly, compute passed text size in bytes.
|
|
254
|
-
const { size } = new Blob([data]);
|
|
255
|
-
if (size === 0 || size > 4096) {
|
|
256
|
-
throw new Error(`Passed data has incorrect size: ${size}`);
|
|
257
|
-
}
|
|
258
|
-
this.postEvent('web_app_data_send', { data });
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Updates current application header color.
|
|
263
|
-
* FIXME: Has no effect on desktop, works incorrectly on Android.
|
|
264
|
-
* Issues:
|
|
265
|
-
* https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
266
|
-
* https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
267
|
-
* @param color - color key or RGB color.
|
|
268
|
-
*/
|
|
269
|
-
setHeaderColor(color: WebAppHeaderColor) {
|
|
270
|
-
this.postEvent('web_app_set_header_color', isRGB(color) ? { color } : { color_key: color });
|
|
271
|
-
this.state.set('headerColor', color);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Updates current application background color.
|
|
276
|
-
* FIXME: Has no effect on desktop, works incorrectly in Android.
|
|
277
|
-
* Issues:
|
|
278
|
-
* https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
279
|
-
* https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
280
|
-
* @param color - RGB color.
|
|
281
|
-
*/
|
|
282
|
-
setBackgroundColor(color: RGB) {
|
|
283
|
-
this.postEvent('web_app_set_background_color', { color });
|
|
284
|
-
this.state.set('backgroundColor', color);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Checks if specified method is supported by current component.
|
|
289
|
-
*/
|
|
290
|
-
supports: SupportsFunc<
|
|
291
|
-
| 'openInvoice'
|
|
292
|
-
| 'readTextFromClipboard'
|
|
293
|
-
| 'setHeaderColor'
|
|
294
|
-
| 'setBackgroundColor'
|
|
295
|
-
| 'requestWriteAccess'
|
|
296
|
-
| 'requestPhoneAccess'
|
|
297
|
-
>;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Checks if specified method parameter is supported by current component.
|
|
301
|
-
*/
|
|
302
|
-
supportsParam: SupportsFunc<'setHeaderColor.color' | 'openLink.tryInstantView'>;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Current Mini App version. This property is used by other components to check if
|
|
306
|
-
* some functionality is available on current device.
|
|
307
|
-
*/
|
|
308
|
-
get version(): Version {
|
|
309
|
-
return this.currentVersion;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RGB } from '@tma.js/colors';
|
|
2
|
-
import type { HeaderColorKey } from '@tma.js/bridge';
|
|
3
|
-
|
|
4
|
-
import type { StateEvents } from '../../state/index.js';
|
|
5
|
-
|
|
6
|
-
export type WebAppHeaderColor = HeaderColorKey | RGB;
|
|
7
|
-
|
|
8
|
-
export interface WebAppState {
|
|
9
|
-
backgroundColor: RGB;
|
|
10
|
-
headerColor: WebAppHeaderColor;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type WebAppEvents = StateEvents<WebAppState>;
|
|
14
|
-
|
|
15
|
-
export type WebAppEventName = keyof WebAppEvents;
|
|
16
|
-
|
|
17
|
-
export type WebAppEventListener<E extends WebAppEventName> = WebAppEvents[E];
|
package/src/components/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './BackButton/index.js';
|
|
2
|
-
export * from './ClosingBehaviour/index.js';
|
|
3
|
-
export * from './CloudStorage/index.js';
|
|
4
|
-
export * from './HapticFeedback/index.js';
|
|
5
|
-
export * from './InitData/index.js';
|
|
6
|
-
export * from './MainButton/index.js';
|
|
7
|
-
export * from './Popup/index.js';
|
|
8
|
-
export * from './QRScanner/index.js';
|
|
9
|
-
export * from './ThemeParams/index.js';
|
|
10
|
-
export * from './Viewport/index.js';
|
|
11
|
-
export * from './WebApp/index.js';
|
package/src/env.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { retrieveLaunchData } from '@tma.js/launch-params';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns true in case, current environment is Telegram Mini Apps.
|
|
5
|
-
*/
|
|
6
|
-
export function isTMA(): boolean {
|
|
7
|
-
try {
|
|
8
|
-
retrieveLaunchData();
|
|
9
|
-
return true;
|
|
10
|
-
} catch (e) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns true in case, current environment is Telegram Mini Apps.
|
|
17
|
-
* @see computeLaunchData
|
|
18
|
-
* @deprecated Use `isTMA`
|
|
19
|
-
*/
|
|
20
|
-
export function isTWA(): boolean {
|
|
21
|
-
return isTMA();
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown in case, unsupported method was called.
|
|
3
|
-
*/
|
|
4
|
-
export class MethodNotSupportedError extends Error {
|
|
5
|
-
constructor(method: string, version: string) {
|
|
6
|
-
super(`Method "${method}" is not supported in the Mini Apps version ${version}.`);
|
|
7
|
-
Object.setPrototypeOf(this, MethodNotSupportedError.prototype);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown in case, unsupported parameter was used.
|
|
3
|
-
*/
|
|
4
|
-
export class ParameterUnsupportedError extends Error {
|
|
5
|
-
constructor(method: string, param: string, version: string) {
|
|
6
|
-
super(`Parameter "${param}" in method "${method}" is not supported in the Mini Apps version ${version}.`);
|
|
7
|
-
Object.setPrototypeOf(this, ParameterUnsupportedError.prototype);
|
|
8
|
-
}
|
|
9
|
-
}
|
package/src/errors/index.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { RGB } from '@tma.js/colors';
|
|
2
|
-
import type { PostEvent } from '@tma.js/bridge';
|
|
3
|
-
import type { Platform } from '@tma.js/launch-params';
|
|
4
|
-
|
|
5
|
-
import { WebApp } from '../../components/index.js';
|
|
6
|
-
|
|
7
|
-
import { getStorageValue, saveStorageValue } from '../../storage.js';
|
|
8
|
-
|
|
9
|
-
import type { CreateRequestIdFunc } from '../../types.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates WebApp instance using last locally saved data also saving each state in
|
|
13
|
-
* the storage.
|
|
14
|
-
* @param isPageReload - was current page reloaded.
|
|
15
|
-
* @param backgroundColor - web app background color.
|
|
16
|
-
* @param version - platform version.
|
|
17
|
-
* @param platform - Telegram Mini Apps platform name.
|
|
18
|
-
* @param createRequestId - function which generates request identifiers.
|
|
19
|
-
* @param postEvent - Bridge postEvent function
|
|
20
|
-
*/
|
|
21
|
-
export function createWebApp(
|
|
22
|
-
isPageReload: boolean,
|
|
23
|
-
backgroundColor: RGB,
|
|
24
|
-
version: string,
|
|
25
|
-
platform: Platform,
|
|
26
|
-
createRequestId: CreateRequestIdFunc,
|
|
27
|
-
postEvent: PostEvent,
|
|
28
|
-
): WebApp {
|
|
29
|
-
const {
|
|
30
|
-
backgroundColor: stateBackgroundColor = backgroundColor,
|
|
31
|
-
headerColor = 'bg_color',
|
|
32
|
-
} = isPageReload ? getStorageValue('web-app') || {} : {};
|
|
33
|
-
|
|
34
|
-
const component = new WebApp(
|
|
35
|
-
headerColor,
|
|
36
|
-
stateBackgroundColor,
|
|
37
|
-
version,
|
|
38
|
-
platform,
|
|
39
|
-
createRequestId,
|
|
40
|
-
postEvent,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const saveState = () => saveStorageValue('web-app', {
|
|
44
|
-
backgroundColor: component.backgroundColor,
|
|
45
|
-
headerColor: component.headerColor,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
component.on('backgroundColorChanged', saveState);
|
|
49
|
-
component.on('headerColorChanged', saveState);
|
|
50
|
-
|
|
51
|
-
return component;
|
|
52
|
-
}
|
package/src/init/css.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { RGB } from '@tma.js/colors';
|
|
2
|
-
|
|
3
|
-
import type { ThemeParams, WebApp, Viewport } from '../components/index.js';
|
|
4
|
-
import type { InitCSSVarsOption, InitCSSVarsSpecificOption } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Sets CSS variable.
|
|
8
|
-
* @param name - variable name.
|
|
9
|
-
* @param value - variable value.
|
|
10
|
-
*/
|
|
11
|
-
function setVariable(name: string, value: string): void {
|
|
12
|
-
document.documentElement.style.setProperty(name, value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Sets new CSS color variable in case, its value is not null.
|
|
17
|
-
* @param name - variable name.
|
|
18
|
-
* @param color - variable value.
|
|
19
|
-
*/
|
|
20
|
-
function setColorVariable(name: string, color: RGB | null): void {
|
|
21
|
-
if (color === null) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
setVariable(name, color);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Sets new CSS variable which value is amount of pixels.
|
|
29
|
-
* @param name - variable name.
|
|
30
|
-
* @param size - variable value.
|
|
31
|
-
*/
|
|
32
|
-
function setSizeVariable(name: string, size: number) {
|
|
33
|
-
setVariable(name, `${size}px`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Creates CSS variables based on Mini App background and header colors with
|
|
38
|
-
* theme parameters.
|
|
39
|
-
* @param webApp - WebApp instance.
|
|
40
|
-
* @param themeParams - theme parameters.
|
|
41
|
-
*/
|
|
42
|
-
function createWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {
|
|
43
|
-
const { backgroundColor, secondaryBackgroundColor } = themeParams;
|
|
44
|
-
const { backgroundColor: webAppBackgroundColor, headerColor } = webApp;
|
|
45
|
-
|
|
46
|
-
setColorVariable('--tg-bg-color', webAppBackgroundColor);
|
|
47
|
-
setColorVariable('--tg-header-color', headerColor === 'bg_color' ? backgroundColor : secondaryBackgroundColor);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates CSS variables connected with theme parameters. Created CSS variables names are
|
|
52
|
-
* following the pattern "--tg-theme-{name}". {name} is a theme parameters key name converted
|
|
53
|
-
* from snake to kebab case.
|
|
54
|
-
*
|
|
55
|
-
* Variables are being automatically updated in case, corresponding properties
|
|
56
|
-
* updated in passed ThemeParams instance.
|
|
57
|
-
*
|
|
58
|
-
* @param themeParams - ThemeParams instance.
|
|
59
|
-
*/
|
|
60
|
-
export function bindThemeCSSVariables(themeParams: ThemeParams): void {
|
|
61
|
-
const actualize = () => {
|
|
62
|
-
const state = themeParams.getState();
|
|
63
|
-
|
|
64
|
-
Object.entries(state).forEach(([k, v]) => {
|
|
65
|
-
const key = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
66
|
-
setColorVariable(`--tg-theme-${key}`, v || null);
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
themeParams.on('changed', actualize);
|
|
71
|
-
|
|
72
|
-
actualize();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Creates CSS variables connected with WebApp background and header colors based on
|
|
77
|
-
* passed WebApp and ThemeParams instances.
|
|
78
|
-
*
|
|
79
|
-
* Created variables:
|
|
80
|
-
* - `--tg-bg-color`
|
|
81
|
-
* - `--tg-header-color`
|
|
82
|
-
*
|
|
83
|
-
* Variables are being automatically updated in case, corresponding properties are updating.
|
|
84
|
-
*
|
|
85
|
-
* @param webApp - WebApp instance.
|
|
86
|
-
* @param themeParams - ThemeParams instance.
|
|
87
|
-
*/
|
|
88
|
-
export function bindWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {
|
|
89
|
-
const actualize = () => createWebAppVariables(webApp, themeParams);
|
|
90
|
-
|
|
91
|
-
themeParams.on('changed', actualize);
|
|
92
|
-
webApp.on('backgroundColorChanged', actualize);
|
|
93
|
-
webApp.on('headerColorChanged', actualize);
|
|
94
|
-
|
|
95
|
-
actualize();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Accepts Viewport instance and sets CSS variables connected with viewport
|
|
100
|
-
* sizes.
|
|
101
|
-
*
|
|
102
|
-
* Be careful using this function as long as it can impact application
|
|
103
|
-
* performance. Viewport size is changing rather often, this makes CSS
|
|
104
|
-
* variables update, which leads to possible layout redraw.
|
|
105
|
-
*
|
|
106
|
-
* Variables:
|
|
107
|
-
* - `--tg-viewport-height`
|
|
108
|
-
* - `--tg-viewport-stable-height`
|
|
109
|
-
*
|
|
110
|
-
* Variables are being automatically updated in case, corresponding properties
|
|
111
|
-
* updated in passed Viewport instance.
|
|
112
|
-
*
|
|
113
|
-
* @param viewport - Viewport instance.
|
|
114
|
-
*/
|
|
115
|
-
export function bindViewportCSSVariables(viewport: Viewport): void {
|
|
116
|
-
const setHeight = () => {
|
|
117
|
-
setSizeVariable('--tg-viewport-height', viewport.height);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const setStableHeight = () => {
|
|
121
|
-
setSizeVariable('--tg-viewport-stable-height', viewport.stableHeight);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
viewport.on('heightChanged', setHeight);
|
|
125
|
-
viewport.on('stableHeightChanged', setStableHeight);
|
|
126
|
-
|
|
127
|
-
setHeight();
|
|
128
|
-
setStableHeight();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Converts init cssVars option to more narrow type.
|
|
133
|
-
* @param option - option value.
|
|
134
|
-
*/
|
|
135
|
-
export function parseCSSVarsOptions(option: InitCSSVarsOption): InitCSSVarsSpecificOption {
|
|
136
|
-
if (typeof option === 'boolean') {
|
|
137
|
-
return option
|
|
138
|
-
? { themeParams: true, viewport: true, webApp: true }
|
|
139
|
-
: {};
|
|
140
|
-
}
|
|
141
|
-
return option;
|
|
142
|
-
}
|
package/src/supports.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Version } from '@tma.js/utils';
|
|
2
|
-
import {
|
|
3
|
-
supports,
|
|
4
|
-
type MethodName,
|
|
5
|
-
type MethodVersionedParams,
|
|
6
|
-
type MethodWithVersionedParams,
|
|
7
|
-
} from '@tma.js/bridge';
|
|
8
|
-
|
|
9
|
-
export type SupportsFunc<M extends string> = (method: M) => boolean;
|
|
10
|
-
|
|
11
|
-
type HasCheckSupportMethodTuple = {
|
|
12
|
-
[M in MethodWithVersionedParams]: [M, MethodVersionedParams<M>]
|
|
13
|
-
}[MethodWithVersionedParams];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns function, which accepts predefined method name and checks if it is supported
|
|
17
|
-
* via passed schema and version.
|
|
18
|
-
* @param schema - object which contains methods names and TWA method as a dependency.
|
|
19
|
-
* @param version - platform version.
|
|
20
|
-
*/
|
|
21
|
-
export function createSupportsFunc<M extends string>(
|
|
22
|
-
version: Version,
|
|
23
|
-
schema: Record<M, MethodName>,
|
|
24
|
-
): SupportsFunc<M> {
|
|
25
|
-
return (method) => supports(schema[method], version);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns function, which accepts predefined method name and checks if it is supported
|
|
30
|
-
* via passed schema and version.
|
|
31
|
-
* @param schema - object which contains methods names and TWA methods with specified parameter
|
|
32
|
-
* as a dependency.
|
|
33
|
-
* @param version - platform version.
|
|
34
|
-
*/
|
|
35
|
-
export function createSupportsParamFunc<P extends string>(
|
|
36
|
-
version: Version,
|
|
37
|
-
schema: Record<P, HasCheckSupportMethodTuple>,
|
|
38
|
-
): SupportsFunc<P> {
|
|
39
|
-
return (method) => {
|
|
40
|
-
const [tmaMethod, param] = schema[method];
|
|
41
|
-
|
|
42
|
-
return supports(tmaMethod, param, version);
|
|
43
|
-
};
|
|
44
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { PostEvent as BridgePostEvent } from '@tma.js/bridge';
|
|
2
|
-
|
|
3
|
-
export type PostEvent = BridgePostEvent;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Color scheme.
|
|
7
|
-
*/
|
|
8
|
-
export type ColorScheme = 'dark' | 'light';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Function which generates unique request identifiers.
|
|
12
|
-
*/
|
|
13
|
-
export type CreateRequestIdFunc = () => string;
|
package/src/url.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts passed URL to its full form.
|
|
3
|
-
* @param url - URL to format.
|
|
4
|
-
* @throws {Error} URL protocol is not supported by OS, or link has not allowed
|
|
5
|
-
* protocol.
|
|
6
|
-
*/
|
|
7
|
-
export function formatURL(url: string): string {
|
|
8
|
-
// TODO: Maybe, there is a bit easier way? window.open will accept
|
|
9
|
-
// unformatted URL too, probably.
|
|
10
|
-
|
|
11
|
-
// We do create new anchor element and assign its href to passed URL. This
|
|
12
|
-
// will format link, so it could be used in `window.open`.
|
|
13
|
-
const anchor = document.createElement('a');
|
|
14
|
-
anchor.href = url;
|
|
15
|
-
|
|
16
|
-
// Check if protocol is correct.
|
|
17
|
-
if (anchor.protocol !== 'http:' && anchor.protocol !== 'https:') {
|
|
18
|
-
throw Error(
|
|
19
|
-
`URL protocol is not supported by OS, or link has not allowed protocol: ${anchor.protocol}`,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return anchor.href;
|
|
23
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|