@telegram-apps/sdk
Version:
TypeScript Source Development Kit for Telegram Mini Apps client application.
168 lines (167 loc) • 6.82 kB
TypeScript
import { isRGB } from '@telegram-apps/transformers';
import { Computed } from '@telegram-apps/signals';
import { RequestOptionsNoCapture } from '../../../types.js';
import { AnyColor, GetCssVarNameFn } from './types.js';
/**
* True if the Mini App component is supported.
*/
export declare const isSupported: Computed<boolean>;
/**
* Creates CSS variables connected with the mini app.
*
* Default variables:
* - `--tg-bg-color`
* - `--tg-header-color`
* - `--tg-bottom-bar-color`
*
* Variables are being automatically updated if theme parameters were changed.
*
* @param getCSSVarName - function, returning complete CSS variable name for the specified
* mini app key.
* @returns Function to stop updating variables.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {CSSVarsBoundError} CSS variables are already bound
* @throws {FunctionNotAvailableError} The parent component is not mounted
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example Using no arguments
* if (bindCssVars.isAvailable()) {
* bindCssVars();
* }
* @example Using custom CSS vars generator
* if (bindCssVars.isAvailable()) {
* bindCssVars(key => `--my-prefix-${key}`);
* }
*/
export declare const bindCssVars: import('../../wrappers/wrapSafe.js').SafeWrapped<(getCSSVarName?: GetCssVarNameFn) => VoidFunction, true, never>;
/**
* Closes the Mini App.
* @param returnBack - should the client return to the previous activity.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example
* if (close.isAvailable()) {
* close();
* }
*/
export declare const close: import('../../wrappers/wrapSafe.js').SafeWrapped<(returnBack?: boolean) => void, false, never>;
/**
* Mounts the component.
*
* This function restores the component state and is automatically saving it in the local storage
* if it changed.
*
* Internally, the function mounts the Theme Params component to work with correctly extracted
* theme palette values.
* @since Mini Apps v6.1
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @deprecated Use `mountSync`.
* @example
* if (mount.isAvailable()) {
* await mount();
* }
*/
export declare const mount: import('../../wrappers/wrapSafe.js').SafeWrapped<(options?: RequestOptionsNoCapture | undefined) => import('@telegram-apps/bridge').AbortablePromise<void>, true, never>;
/**
* @deprecated The initialization is synchronous. Use `mountSync`.
*/
export declare const isMounting: Computed<boolean>;
/**
* @deprecated The initialization is synchronous. Use `mountSync`.
*/
export declare const mountPromise: Computed<import('@telegram-apps/bridge').AbortablePromise<any> | undefined>;
/**
* @deprecated The initialization is synchronous. Use `mountSync`.
*/
export declare const mountError: Computed<Error | undefined>;
export declare const _isMounted: import('@telegram-apps/signals').Signal<boolean>, isMounted: Computed<boolean>;
/**
* Mounts the component.
*
* This function restores the component state and is automatically saving it in the local storage
* if it changed.
*
* Internally, the function mounts the Theme Params component to work with correctly extracted
* theme palette values.
* @since Mini Apps v6.1
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (mountSync.isAvailable()) {
* mountSync();
* }
*/
export declare const mountSync: import('../../wrappers/wrapSafe.js').SafeWrapped<() => void, true, never>;
/**
* Informs the Telegram app that the Mini App is ready to be displayed.
*
* It is recommended to call this method as early as possible, as soon as all
* essential interface elements loaded.
*
* Once this method is called, the loading placeholder is hidden and the Mini
* App shown.
*
* If the method is not called, the placeholder will be hidden only when the
* page was fully loaded.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example
* if (ready.isAvailable()) {
* ready();
* }
*/
export declare const ready: import('../../wrappers/wrapSafe.js').SafeWrapped<() => void, false, never>;
/**
* Updates the background color.
* @since Mini Apps v6.1
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @throws {FunctionNotAvailableError} The parent component is not mounted
* @throws {UnknownThemeParamsKeyError} Unknown theme params key passed
* @example
* if (setBackgroundColor.isAvailable()) {
* setBackgroundColor('bg_color');
* }
*/
export declare const setBackgroundColor: import('../../wrappers/wrapSafe.js').SafeWrapped<(color: AnyColor) => void, true, never>;
/**
* Updates the bottom bar background color.
* @since Mini Apps v7.10
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @throws {FunctionNotAvailableError} The parent component is not mounted
* @throws {UnknownThemeParamsKeyError} Unknown theme params key passed
* @example
* if (setBottomBarColor.isAvailable()) {
* setBottomBarColor('#ff11a3');
* }
*/
export declare const setBottomBarColor: import('../../wrappers/wrapSafe.js').SafeWrapped<(color: AnyColor) => void, true, never>;
/**
* Updates the header color.
* @since Mini Apps v6.1
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @throws {FunctionNotAvailableError} The parent component is not mounted
* @throws {UnknownThemeParamsKeyError} Unknown theme params key passed
* @example Using known color key
* if (setHeaderColor.isAvailable()) {
* setHeaderColor('bg_color');
* }
* @example Using RGB
* if (setHeaderColor.isAvailable() && setHeaderColor.supports.rgb()) {
* setHeaderColor('#ffaabb');
* }
*/
export declare const setHeaderColor: import('../../wrappers/wrapSafe.js').SafeWrapped<(color: AnyColor) => void, true, {
rgb: ["web_app_set_header_color", "color", typeof isRGB];
}>;
/**
* Unmounts the component, removing the listener, saving the component state in the local storage.
*/
export declare function unmount(): void;