@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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { isRecord } from '~/misc/index.js';
|
|
2
|
+
import { withTimeout } from '~/timeout/index.js';
|
|
3
|
+
import type { And, If, IsNever } from '~/types/index.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type MiniAppsEventHasParams,
|
|
7
|
+
type MiniAppsEventName,
|
|
8
|
+
type MiniAppsEventParams,
|
|
9
|
+
on,
|
|
10
|
+
} from './events/index.js';
|
|
11
|
+
import {
|
|
12
|
+
type MiniAppsEmptyMethodName,
|
|
13
|
+
type MiniAppsMethodAcceptParams,
|
|
14
|
+
type MiniAppsMethodName,
|
|
15
|
+
type MiniAppsMethodParams,
|
|
16
|
+
type MiniAppsNonEmptyMethodName,
|
|
17
|
+
type PostEvent,
|
|
18
|
+
postEvent as defaultPostEvent,
|
|
19
|
+
} from './methods/index.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Names of methods, which require passing "req_id" parameter.
|
|
23
|
+
*/
|
|
24
|
+
type MethodWithRequestId = {
|
|
25
|
+
[M in MiniAppsMethodName]: If<
|
|
26
|
+
And<
|
|
27
|
+
MiniAppsMethodAcceptParams<M>,
|
|
28
|
+
MiniAppsMethodParams<M> extends { req_id: string } ? true : false
|
|
29
|
+
>,
|
|
30
|
+
M,
|
|
31
|
+
never
|
|
32
|
+
>;
|
|
33
|
+
}[MiniAppsMethodName];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Names of events, which contain "req_id" parameter.
|
|
37
|
+
*/
|
|
38
|
+
type EventWithRequestId = {
|
|
39
|
+
[E in MiniAppsEventName]: If<
|
|
40
|
+
And<MiniAppsEventHasParams<E>, MiniAppsEventParams<E> extends {
|
|
41
|
+
req_id: string
|
|
42
|
+
} ? true : false>,
|
|
43
|
+
E,
|
|
44
|
+
never
|
|
45
|
+
>;
|
|
46
|
+
}[MiniAppsEventName];
|
|
47
|
+
|
|
48
|
+
export interface RequestOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Bridge postEvent method.
|
|
51
|
+
* @default Global postEvent method.
|
|
52
|
+
*/
|
|
53
|
+
postEvent?: PostEvent;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Execution timeout.
|
|
57
|
+
*/
|
|
58
|
+
timeout?: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RequestOptionsAdvanced<EventPayload> extends RequestOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Should return true in case, this event should be captured. If not specified,
|
|
64
|
+
* request is not skipping captured events.
|
|
65
|
+
*/
|
|
66
|
+
capture?: If<IsNever<EventPayload>, () => boolean, (payload: EventPayload) => boolean>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Calls specified TWA method and captures one of the specified events. Returns promise
|
|
71
|
+
* which will be resolved in case, event with specified in method request identifier
|
|
72
|
+
* was captured.
|
|
73
|
+
* @param method - method to execute.
|
|
74
|
+
* @param params - method parameters.
|
|
75
|
+
* @param event - event or events to listen.
|
|
76
|
+
* @param options - additional execution options.
|
|
77
|
+
*/
|
|
78
|
+
export function request<M extends MethodWithRequestId, E extends EventWithRequestId>(
|
|
79
|
+
method: M,
|
|
80
|
+
params: MiniAppsMethodParams<M>,
|
|
81
|
+
event: E | E[],
|
|
82
|
+
options?: RequestOptions,
|
|
83
|
+
): Promise<MiniAppsEventParams<E>>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Calls specified TWA method and captures one of the specified events. Returns promise
|
|
87
|
+
* which will be resolved in case, specified event was captured.
|
|
88
|
+
* @param method - method to execute.
|
|
89
|
+
* @param event - event or events to listen.
|
|
90
|
+
* @param options - additional execution options.
|
|
91
|
+
*/
|
|
92
|
+
export function request<M extends MiniAppsEmptyMethodName, E extends MiniAppsEventName>(
|
|
93
|
+
method: M,
|
|
94
|
+
event: E | E[],
|
|
95
|
+
options?: RequestOptionsAdvanced<MiniAppsEventParams<E>>,
|
|
96
|
+
): Promise<MiniAppsEventParams<E>>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Calls specified TWA method and captures one of the specified events. Returns promise
|
|
100
|
+
* which will be resolved in case, specified event was captured.
|
|
101
|
+
* @param method - method to execute
|
|
102
|
+
* @param params - method parameters.
|
|
103
|
+
* @param event - event or events to listen
|
|
104
|
+
* @param options - additional execution options.
|
|
105
|
+
*/
|
|
106
|
+
export function request<M extends MiniAppsNonEmptyMethodName, E extends MiniAppsEventName>(
|
|
107
|
+
method: M,
|
|
108
|
+
params: MiniAppsMethodParams<M>,
|
|
109
|
+
event: E | E[],
|
|
110
|
+
options?: RequestOptionsAdvanced<MiniAppsEventParams<E>>,
|
|
111
|
+
): Promise<MiniAppsEventParams<E>>;
|
|
112
|
+
|
|
113
|
+
export function request(
|
|
114
|
+
method: MiniAppsMethodName,
|
|
115
|
+
eventOrParams: MiniAppsEventName | MiniAppsEventName[] | MiniAppsEventParams<any>,
|
|
116
|
+
eventOrOptions?:
|
|
117
|
+
| MiniAppsEventName
|
|
118
|
+
| MiniAppsEventName[]
|
|
119
|
+
| RequestOptions
|
|
120
|
+
| RequestOptionsAdvanced<any>,
|
|
121
|
+
options?: RequestOptions | RequestOptionsAdvanced<any>,
|
|
122
|
+
): Promise<any> {
|
|
123
|
+
let executionOptions: RequestOptions | RequestOptionsAdvanced<any> | undefined;
|
|
124
|
+
let methodParams: MiniAppsEventParams<any> | undefined;
|
|
125
|
+
let events: MiniAppsEventName[];
|
|
126
|
+
let requestId: string | undefined;
|
|
127
|
+
|
|
128
|
+
if (typeof eventOrParams === 'string' || Array.isArray(eventOrParams)) {
|
|
129
|
+
// Override: [method, event, options?]
|
|
130
|
+
events = Array.isArray(eventOrParams) ? eventOrParams : [eventOrParams] as MiniAppsEventName[];
|
|
131
|
+
executionOptions = eventOrOptions as (RequestOptionsAdvanced<any> | undefined);
|
|
132
|
+
} else {
|
|
133
|
+
// Override: [method, params, event, options?]
|
|
134
|
+
methodParams = eventOrParams as MiniAppsEventParams<any>;
|
|
135
|
+
events = Array.isArray(eventOrOptions)
|
|
136
|
+
? eventOrOptions
|
|
137
|
+
: [eventOrOptions] as MiniAppsEventName[];
|
|
138
|
+
executionOptions = options;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// In case, method parameters were passed, and they contained request identifier, we should store
|
|
142
|
+
// it and wait for the event with this identifier to occur.
|
|
143
|
+
if (isRecord(methodParams) && typeof methodParams.req_id === 'string') {
|
|
144
|
+
requestId = methodParams.req_id;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const { postEvent = defaultPostEvent, timeout } = executionOptions || {};
|
|
148
|
+
const capture = executionOptions && 'capture' in executionOptions
|
|
149
|
+
? executionOptions.capture
|
|
150
|
+
: null;
|
|
151
|
+
|
|
152
|
+
const promise = new Promise((res, rej) => {
|
|
153
|
+
// Iterate over each event and create event listener.
|
|
154
|
+
const stoppers = events.map((ev) => on(ev, (data?) => {
|
|
155
|
+
// If request identifier was specified, we are waiting for event with the same value
|
|
156
|
+
// to occur.
|
|
157
|
+
if (typeof requestId === 'string' && (!isRecord(data) || data.req_id !== requestId)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (typeof capture === 'function' && !capture(data)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
166
|
+
stopListening();
|
|
167
|
+
res(data);
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
// Function which removes all event listeners.
|
|
171
|
+
const stopListening = () => stoppers.forEach((stop) => stop());
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
// We are wrapping this call in try catch, because it can throw errors in case,
|
|
175
|
+
// compatibility check was enabled. We want an error to be captured by promise, not by
|
|
176
|
+
// another one external try catch.
|
|
177
|
+
postEvent(method as any, methodParams);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
stopListening();
|
|
180
|
+
rej(e);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return typeof timeout === 'number' ? withTimeout(promise, timeout) : promise;
|
|
185
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inserts a space between a and b in case both of them are
|
|
3
|
+
* non-empty strings.
|
|
4
|
+
* @param a
|
|
5
|
+
* @param b
|
|
6
|
+
*/
|
|
7
|
+
function space(a: string, b: string): string {
|
|
8
|
+
return a + (a.length > 0 && b.length > 0 ? ` ${b}` : b);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Function which joins passed values with space following these rules:
|
|
13
|
+
* 1. If value is non-empty string, it will be added to output.
|
|
14
|
+
* 2. If value is object, only those keys will be added, which values are truthy.
|
|
15
|
+
* 3. All other values are ignored.
|
|
16
|
+
*
|
|
17
|
+
* You can find this function to similar one from package {@link https://www.npmjs.com/package/classnames|classnames}.
|
|
18
|
+
* @param values - values array.
|
|
19
|
+
*/
|
|
20
|
+
export function classNames(...values: any[]): string {
|
|
21
|
+
return values.reduce<string>((acc, value) => {
|
|
22
|
+
let formattedValue = '';
|
|
23
|
+
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
formattedValue = value;
|
|
26
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
27
|
+
formattedValue = Object
|
|
28
|
+
.entries(value)
|
|
29
|
+
.reduce<string>((valueAcc, [className, enable]) => (enable ? space(valueAcc, className) : valueAcc), '');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return space(acc, formattedValue);
|
|
33
|
+
}, '');
|
|
34
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { classNames } from './classNames.js';
|
|
2
|
+
|
|
3
|
+
type FilterUnion<U> = Exclude<U, number | string | null | undefined | any[] | boolean>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns union keys removing those, which values are not strings.
|
|
7
|
+
*/
|
|
8
|
+
type UnionFilteredKeys<U> = U extends U
|
|
9
|
+
? {
|
|
10
|
+
[K in keyof U]: U[K] extends string ? K : never
|
|
11
|
+
}[keyof U]
|
|
12
|
+
: never;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns union required keys.
|
|
16
|
+
*/
|
|
17
|
+
type UnionRequiredKeys<U> = U extends U
|
|
18
|
+
? {
|
|
19
|
+
[K in UnionFilteredKeys<U>]-?: ({} extends { [P in K]: U[K] } ? never : K)
|
|
20
|
+
}[UnionFilteredKeys<U>]
|
|
21
|
+
: never;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns union optional keys.
|
|
25
|
+
*/
|
|
26
|
+
type UnionOptionalKeys<U> = Exclude<UnionFilteredKeys<U>, UnionRequiredKeys<U>>;
|
|
27
|
+
|
|
28
|
+
type MergeClassNames<Tuple extends any[]> = Tuple[number] extends infer Union
|
|
29
|
+
? FilterUnion<Union> extends infer UnionFiltered
|
|
30
|
+
? {
|
|
31
|
+
[K in UnionRequiredKeys<UnionFiltered>]: string;
|
|
32
|
+
} & {
|
|
33
|
+
[K in UnionOptionalKeys<UnionFiltered>]?: string;
|
|
34
|
+
}
|
|
35
|
+
: never
|
|
36
|
+
: never;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns true in case, passed value is Record.
|
|
40
|
+
* @param value
|
|
41
|
+
*/
|
|
42
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
43
|
+
return typeof value === 'object' && value !== null && !Array.isArray(null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Merges 2 sets of parameters. Function expects passing an array of objects with values, which
|
|
48
|
+
* could be passed to `classNames` function. As the result, it returns an object with keys
|
|
49
|
+
* from all objects with merged values.
|
|
50
|
+
* @see classNames
|
|
51
|
+
*/
|
|
52
|
+
export function mergeClassNames<T extends any[]>(...partials: T): MergeClassNames<T> {
|
|
53
|
+
return partials.reduce<MergeClassNames<T>>((acc, partial) => {
|
|
54
|
+
if (!isObject(partial)) {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Object.entries(partial).forEach(([key, value]) => {
|
|
59
|
+
const className = classNames((acc as any)[key], value);
|
|
60
|
+
|
|
61
|
+
if (className.length > 0) {
|
|
62
|
+
(acc as any)[key] = className;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return acc;
|
|
67
|
+
}, {} as MergeClassNames<T>);
|
|
68
|
+
}
|
package/src/{components/ClosingBehaviour/ClosingBehaviour.ts → closing-behavior/ClosingBehavior.ts}
RENAMED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type PostEvent, postEvent as defaultPostEvent } from '~/bridge/index.js';
|
|
2
|
+
import { EventEmitter } from '~/event-emitter/index.js';
|
|
3
|
+
import { State } from '~/state/index.js';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
ClosingBehaviorEvents,
|
|
7
|
+
ClosingBehaviorState,
|
|
8
|
+
} from './types.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Component responsible for controlling current closing confirmation
|
|
10
12
|
* status.
|
|
11
13
|
*/
|
|
12
|
-
export class
|
|
13
|
-
private readonly ee = new EventEmitter<
|
|
14
|
+
export class ClosingBehavior {
|
|
15
|
+
private readonly ee = new EventEmitter<ClosingBehaviorEvents>();
|
|
14
16
|
|
|
15
|
-
private readonly state: State<
|
|
17
|
+
private readonly state: State<ClosingBehaviorState>;
|
|
16
18
|
|
|
17
19
|
constructor(
|
|
18
20
|
isConfirmationNeeded: boolean,
|
|
@@ -53,10 +55,10 @@ export class ClosingBehaviour {
|
|
|
53
55
|
/**
|
|
54
56
|
* Adds new event listener.
|
|
55
57
|
*/
|
|
56
|
-
on
|
|
58
|
+
on = this.ee.on.bind(this.ee);
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
61
|
* Removes event listener.
|
|
60
62
|
*/
|
|
61
|
-
off
|
|
63
|
+
off = this.ee.off.bind(this.ee);
|
|
62
64
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StateEvents } from '~/state/index.js';
|
|
2
|
+
|
|
3
|
+
export interface ClosingBehaviorState {
|
|
4
|
+
isConfirmationNeeded: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type ClosingBehaviorEvents = StateEvents<ClosingBehaviorState>;
|
|
8
|
+
|
|
9
|
+
export type ClosingBehaviorEventName = keyof ClosingBehaviorEvents;
|
|
10
|
+
|
|
11
|
+
export type ClosingBehaviorEventListener<E extends ClosingBehaviorEventName> =
|
|
12
|
+
ClosingBehaviorEvents[E];
|
|
@@ -2,14 +2,18 @@ import {
|
|
|
2
2
|
postEvent as defaultPostEvent,
|
|
3
3
|
request,
|
|
4
4
|
type RequestOptions,
|
|
5
|
-
} from '
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
} from '~/bridge/index.js';
|
|
6
|
+
import {
|
|
7
|
+
array,
|
|
8
|
+
json,
|
|
9
|
+
string,
|
|
10
|
+
} from '~/parsing/index.js';
|
|
11
|
+
import {
|
|
12
|
+
createSupportsFunc,
|
|
13
|
+
type SupportsFunc,
|
|
14
|
+
} from '~/supports/index.js';
|
|
15
|
+
import type { CreateRequestIdFunc } from '~/types/index.js';
|
|
16
|
+
import type { Version } from '~/version/index.js';
|
|
13
17
|
|
|
14
18
|
type WiredRequestOptions = Omit<RequestOptions, 'postEvent'>;
|
|
15
19
|
|
|
@@ -36,10 +40,10 @@ export class CloudStorage {
|
|
|
36
40
|
private readonly postEvent = defaultPostEvent,
|
|
37
41
|
) {
|
|
38
42
|
this.supports = createSupportsFunc(version, {
|
|
39
|
-
|
|
43
|
+
delete: 'web_app_invoke_custom_method',
|
|
44
|
+
get: 'web_app_invoke_custom_method',
|
|
40
45
|
getKeys: 'web_app_invoke_custom_method',
|
|
41
|
-
|
|
42
|
-
saveValue: 'web_app_invoke_custom_method',
|
|
46
|
+
set: 'web_app_invoke_custom_method',
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -62,18 +66,19 @@ export class CloudStorage {
|
|
|
62
66
|
);
|
|
63
67
|
|
|
64
68
|
if (error) {
|
|
65
|
-
throw new Error(
|
|
69
|
+
throw new Error(error);
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
return result;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
|
-
* Deletes specified keys from the
|
|
73
|
-
* @param
|
|
76
|
+
* Deletes specified key or keys from the cloud storage.
|
|
77
|
+
* @param keyOrKeys - key or keys to delete.
|
|
74
78
|
* @param options - request execution options.
|
|
75
79
|
*/
|
|
76
|
-
async
|
|
80
|
+
async delete(keyOrKeys: string | string[], options?: WiredRequestOptions): Promise<void> {
|
|
81
|
+
const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
77
82
|
if (keys.length === 0) {
|
|
78
83
|
return;
|
|
79
84
|
}
|
|
@@ -82,7 +87,7 @@ export class CloudStorage {
|
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
|
-
* Returns list of all keys presented in
|
|
90
|
+
* Returns list of all keys presented in the cloud storage.
|
|
86
91
|
* @param options - request execution options.
|
|
87
92
|
*/
|
|
88
93
|
async getKeys(options?: WiredRequestOptions): Promise<string[]> {
|
|
@@ -97,20 +102,37 @@ export class CloudStorage {
|
|
|
97
102
|
* @param keys - keys list.
|
|
98
103
|
* @param options - request execution options.
|
|
99
104
|
*/
|
|
100
|
-
|
|
105
|
+
get<K extends string>(
|
|
101
106
|
keys: K[],
|
|
102
107
|
options?: WiredRequestOptions,
|
|
103
|
-
): Promise<Record<K, string
|
|
108
|
+
): Promise<Record<K, string>>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns value of the specified key.
|
|
112
|
+
* @param key - cloud storage key.
|
|
113
|
+
* @param options - request execution options.
|
|
114
|
+
* @return Value of the specified key. In case, key was not created previously, function
|
|
115
|
+
* will return empty string.
|
|
116
|
+
*/
|
|
117
|
+
get(key: string, options?: WiredRequestOptions): Promise<string>;
|
|
118
|
+
|
|
119
|
+
async get(
|
|
120
|
+
keyOrKeys: string | string[],
|
|
121
|
+
options?: WiredRequestOptions,
|
|
122
|
+
): Promise<string | Record<string, string>> {
|
|
123
|
+
const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
104
124
|
if (keys.length === 0) {
|
|
105
|
-
return objectFromKeys(keys, '');
|
|
125
|
+
return objectFromKeys<string, string>(keys, '');
|
|
106
126
|
}
|
|
107
127
|
|
|
108
|
-
const schema = json
|
|
109
|
-
objectFromKeys(keys, string())
|
|
128
|
+
const schema = json(
|
|
129
|
+
objectFromKeys(keys, string()),
|
|
110
130
|
);
|
|
111
|
-
const result = await this
|
|
131
|
+
const result = await this
|
|
132
|
+
.invokeCustomMethod('getStorageValues', { keys }, options)
|
|
133
|
+
.then((data) => schema.parse(data));
|
|
112
134
|
|
|
113
|
-
return
|
|
135
|
+
return Array.isArray(keyOrKeys) ? result : result[keyOrKeys];
|
|
114
136
|
}
|
|
115
137
|
|
|
116
138
|
/**
|
|
@@ -119,7 +141,7 @@ export class CloudStorage {
|
|
|
119
141
|
* @param value - storage value.
|
|
120
142
|
* @param options - request execution options.
|
|
121
143
|
*/
|
|
122
|
-
async
|
|
144
|
+
async set(key: string, value: string, options?: WiredRequestOptions): Promise<void> {
|
|
123
145
|
await this.invokeCustomMethod('saveStorageValue', { key, value }, options);
|
|
124
146
|
}
|
|
125
147
|
|
|
@@ -127,9 +149,9 @@ export class CloudStorage {
|
|
|
127
149
|
* Checks if specified method is supported by current component.
|
|
128
150
|
*/
|
|
129
151
|
supports: SupportsFunc<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
152
|
+
| 'delete'
|
|
153
|
+
| 'get'
|
|
154
|
+
| 'getKeys'
|
|
155
|
+
| 'set'
|
|
134
156
|
>;
|
|
135
157
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toRGB } from './toRGB.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true in case, the color is recognized as dark.
|
|
5
|
+
* @param color - color in any format acceptable by toRGB function.
|
|
6
|
+
* @see toRGB
|
|
7
|
+
*/
|
|
8
|
+
export function isColorDark(color: string): boolean {
|
|
9
|
+
// Convert color to RGB.
|
|
10
|
+
const rgb = toRGB(color);
|
|
11
|
+
|
|
12
|
+
// Real formula: hsp = Math.sqrt(0.299 * r * r + 0.587 * g * g + 0.114 * b * b)
|
|
13
|
+
// See: https://stackoverflow.com/a/596243
|
|
14
|
+
const hsp = Math.sqrt(
|
|
15
|
+
[0.299, 0.587, 0.114].reduce<number>((acc, modifier, idx) => {
|
|
16
|
+
// Extract part of #RRGGBB pattern and convert it to DEC.
|
|
17
|
+
const dec = parseInt(rgb.slice(1 + idx * 2, 1 + (idx + 1) * 2), 16);
|
|
18
|
+
return acc + dec * dec * modifier;
|
|
19
|
+
}, 0),
|
|
20
|
+
);
|
|
21
|
+
return hsp < 120;
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isRGB } from './isRGB.js';
|
|
2
|
+
import { isRGBShort } from './isRGBShort.js';
|
|
3
|
+
import type { RGB } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts passed value to #RRGGBB format. Accepts following color formats:
|
|
7
|
+
* - `#RGB`
|
|
8
|
+
* - `#RRGGBB`
|
|
9
|
+
* - `rgb(1,2,3)`
|
|
10
|
+
* - `rgba(1,2,3,4)`
|
|
11
|
+
* @param value - value to convert.
|
|
12
|
+
* @throws {Error} Passed value does not satisfy any of known RGB formats.
|
|
13
|
+
*/
|
|
14
|
+
export function toRGB(value: string): RGB {
|
|
15
|
+
// Remove all spaces.
|
|
16
|
+
const clean = value.replace(/\s/g, '').toLowerCase();
|
|
17
|
+
|
|
18
|
+
// Value already has required format.
|
|
19
|
+
if (isRGB(clean)) {
|
|
20
|
+
return clean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Convert from #RGB.
|
|
24
|
+
if (isRGBShort(clean)) {
|
|
25
|
+
let color = '#';
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < 3; i += 1) {
|
|
28
|
+
color += clean[1 + i].repeat(2);
|
|
29
|
+
}
|
|
30
|
+
return color as RGB;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Example valid values: rgb(0,3,10) rgba(32,114,8,0)
|
|
34
|
+
const match = clean.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)
|
|
35
|
+
|| clean.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);
|
|
36
|
+
|
|
37
|
+
// In case, this didn't work as well, we can't extract RGB color from passed
|
|
38
|
+
// text.
|
|
39
|
+
if (match === null) {
|
|
40
|
+
throw new Error(`Value "${value}" does not satisfy any of known RGB formats.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Otherwise, take R, G and B components, convert to hex and create #RRGGBB
|
|
44
|
+
// string.
|
|
45
|
+
return match.slice(1).reduce((acc, component) => {
|
|
46
|
+
const formatted = parseInt(component, 10).toString(16);
|
|
47
|
+
return acc + (formatted.length === 1 ? '0' : '') + formatted;
|
|
48
|
+
}, '#') as RGB;
|
|
49
|
+
}
|