@tma.js/sdk 0.12.1 → 0.12.2
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/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.js → index.mjs} +1 -1
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +16 -16
- package/dist/index.js.map +0 -1
- package/dist/index.umd.cjs +0 -2
- package/dist/index.umd.cjs.map +0 -1
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/supports.ts","../src/state/State.ts","../src/components/BackButton/BackButton.ts","../src/components/ClosingBehaviour/ClosingBehaviour.ts","../src/components/CloudStorage/CloudStorage.ts","../src/components/HapticFeedback/HapticFeedback.ts","../src/components/InitData/InitData.ts","../src/components/MainButton/MainButton.ts","../src/components/Popup/utils.ts","../src/components/Popup/Popup.ts","../src/components/QRScanner/QRScanner.ts","../src/components/ThemeParams/ThemeParams.ts","../src/components/Viewport/Viewport.ts","../src/url.ts","../src/components/WebApp/WebApp.ts","../src/errors/MethodNotSupportedError.ts","../src/errors/ParameterNotSupportedError.ts","../src/init/css.ts","../src/storage.ts","../src/init/creators/createBackButton.ts","../src/init/creators/createClosingBehavior.ts","../src/init/creators/createMainButton.ts","../src/init/creators/createPostEvent.ts","../src/init/creators/createRequestIdGenerator.ts","../src/init/creators/createThemeParams.ts","../src/init/creators/createViewport.ts","../src/init/creators/createWebApp.ts","../src/launch-params.ts","../src/init/init.ts","../src/env.ts"],"sourcesContent":["import type { Version } from '@tma.js/utils';\nimport {\n supports,\n type MethodName,\n type HasCheckSupportMethodName,\n type HasCheckSupportMethodParam,\n} from '@tma.js/bridge';\n\nexport type SupportsFunc<M extends string> = (method: M) => boolean;\n\ntype HasCheckSupportMethodTuple = {\n [M in HasCheckSupportMethodName]: [M, HasCheckSupportMethodParam<M>]\n}[HasCheckSupportMethodName];\n\n/**\n * Returns function, which accepts predefined method name and checks if it is supported\n * via passed schema and version.\n * @param schema - object which contains methods names and TWA method as a dependency.\n * @param version - platform version.\n */\nexport function createSupportsFunc<M extends string>(\n version: Version,\n schema: Record<M, MethodName>,\n): SupportsFunc<M> {\n return (method) => supports(schema[method], version);\n}\n\n/**\n * Returns function, which accepts predefined method name and checks if it is supported\n * via passed schema and version.\n * @param schema - object which contains methods names and TWA methods with specified parameter\n * as a dependency.\n * @param version - platform version.\n */\nexport function createSupportsParamFunc<P extends string>(\n version: Version,\n schema: Record<P, HasCheckSupportMethodTuple>,\n): SupportsFunc<P> {\n return (method) => {\n const [tmaMethod, param] = schema[method];\n\n return supports(tmaMethod, param, version);\n };\n}\n","import type { EventEmitter } from '@tma.js/event-emitter';\n\nimport type { StateEvents, StringKeys } from './types.js';\n\n/**\n * Represents state which is observable via passed EventEmitter.\n */\nexport class State<S extends object> {\n constructor(private readonly state: S, private readonly ee?: EventEmitter<StateEvents<S>>) {\n }\n\n private emit(key: string, value?: unknown) {\n if (this.ee) {\n (this.ee as any).emit(key, value);\n }\n }\n\n private internalSet<K extends StringKeys<S>>(key: K, value: S[K]): boolean {\n if (this.state[key] === value) {\n return false;\n }\n\n this.state[key] = value;\n this.emit(`${key}Changed`, value);\n\n return true;\n }\n\n set<K extends StringKeys<S>>(key: K, value: S[K]): void;\n set(state: Partial<S>): void;\n set(keyOrState: any, value?: any): void {\n let didChange = false;\n\n if (typeof keyOrState === 'string') {\n didChange = this.internalSet(keyOrState as any, value);\n } else {\n // eslint-disable-next-line\n for (const key in keyOrState) {\n if (this.internalSet(key as any, keyOrState[key])) {\n didChange = true;\n }\n }\n }\n\n if (didChange) {\n this.emit('changed');\n }\n }\n\n get<K extends StringKeys<S>>(key: K): Readonly<S[K]> {\n return this.state[key];\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, off, postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { BackButtonEvents, BackButtonState, BackButtonEventListener } from './types.js';\n\n/**\n * Class which controls the back button displayed in the header\n * of the Web App in the Telegram interface. It is mostly used in case, when\n * you want to provide a way to go bach in routing history or \"rollback\" some\n * action.\n */\nexport class BackButton {\n private readonly ee = new EventEmitter<BackButtonEvents>();\n\n private readonly state: State<BackButtonState>;\n\n constructor(\n isVisible: boolean,\n version: Version,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({ isVisible }, this.ee);\n this.supports = createSupportsFunc(version, {\n show: 'web_app_setup_back_button',\n hide: 'web_app_setup_back_button',\n });\n }\n\n private set isVisible(visible: boolean) {\n this.state.set('isVisible', visible);\n this.postEvent('web_app_setup_back_button', { is_visible: visible });\n }\n\n /**\n * True if BackButton is currently visible.\n */\n get isVisible(): boolean {\n return this.state.get('isVisible');\n }\n\n /**\n * Hides the BackButton.\n */\n hide(): void {\n this.isVisible = false;\n }\n\n /**\n * Adds event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n on: typeof this.ee.on = (event, listener) => {\n if (event === 'click') {\n return on('back_button_pressed', listener as BackButtonEventListener<'click'>);\n }\n\n this.ee.on(event, listener);\n };\n\n /**\n * Removes event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n off: typeof this.ee.off = (event, listener) => {\n if (event === 'click') {\n return off('back_button_pressed', listener as BackButtonEventListener<'click'>);\n }\n\n this.ee.off(event, listener);\n };\n\n /**\n * Shows the BackButton.\n */\n show(): void {\n this.isVisible = true;\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'show' | 'hide'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport { State } from '../../state/index.js';\n\nimport type { ClosingBehaviourEvents, ClosingBehaviourState } from './types.js';\n\n/**\n * Component responsible for controlling current closing confirmation\n * status.\n */\nexport class ClosingBehaviour {\n private readonly ee = new EventEmitter<ClosingBehaviourEvents>();\n\n private readonly state: State<ClosingBehaviourState>;\n\n constructor(\n isConfirmationNeeded: boolean,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({ isConfirmationNeeded }, this.ee);\n }\n\n private set isConfirmationNeeded(value: boolean) {\n this.state.set('isConfirmationNeeded', value);\n this.postEvent('web_app_setup_closing_behavior', { need_confirmation: value });\n }\n\n /**\n * Returns true, if the confirmation dialog enabled while the user is trying\n * to close the Web App.\n */\n get isConfirmationNeeded(): boolean {\n return this.state.get('isConfirmationNeeded');\n }\n\n /**\n * Disables the confirmation dialog while the user is trying to close the\n * Web App.\n */\n disableConfirmation(): void {\n this.isConfirmationNeeded = false;\n }\n\n /**\n * Enables the confirmation dialog while the user is trying to close the\n * Web App.\n */\n enableConfirmation(): void {\n this.isConfirmationNeeded = true;\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n}\n","import {\n postEvent as defaultPostEvent,\n request,\n type RequestOptions,\n} from '@tma.js/bridge';\nimport { array, json, string } from '@tma.js/parsing';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\n\nimport type { CreateRequestIdFunc } from '../../types.js';\n\ntype WiredRequestOptions = Omit<RequestOptions, 'postEvent'>;\n\ninterface Methods {\n deleteStorageValues: { keys: string | string[] };\n getStorageValues: { keys: string | string[] };\n getStorageKeys: {};\n saveStorageValue: { key: string; value: string };\n}\n\nconst stringArray = array().of(string());\n\nfunction objectFromKeys<K extends string, V>(keys: K[], value: V): Record<K, V> {\n return keys.reduce<Record<K, V>>((acc, key) => {\n acc[key] = value;\n return acc;\n }, {} as Record<K, V>);\n}\n\nexport class CloudStorage {\n constructor(\n version: Version,\n private readonly createRequestId: CreateRequestIdFunc,\n private readonly postEvent = defaultPostEvent,\n ) {\n this.supports = createSupportsFunc(version, {\n deleteKeys: 'web_app_invoke_custom_method',\n getKeys: 'web_app_invoke_custom_method',\n getValues: 'web_app_invoke_custom_method',\n saveValue: 'web_app_invoke_custom_method',\n });\n }\n\n /**\n * Invokes custom method related to CloudStorage.\n * @param method - method name.\n * @param params - method parameters.\n * @param options - execution options.\n */\n private async invokeCustomMethod<M extends keyof Methods>(\n method: M,\n params: Methods[M],\n options: WiredRequestOptions = {},\n ): Promise<unknown> {\n const { result, error } = await request(\n 'web_app_invoke_custom_method',\n { method, params, req_id: this.createRequestId() },\n 'custom_method_invoked',\n { ...options, postEvent: this.postEvent },\n );\n\n if (error) {\n throw new Error(typeof error === 'string' ? error : `Unknown error: ${JSON.stringify(error)}`);\n }\n\n return result;\n }\n\n /**\n * Deletes specified keys from the CloudStorage.\n * @param keys - keys list.\n * @param options - request execution options.\n */\n async deleteKeys(keys: string[], options?: WiredRequestOptions): Promise<void> {\n if (keys.length === 0) {\n return;\n }\n\n await this.invokeCustomMethod('deleteStorageValues', { keys }, options);\n }\n\n /**\n * Returns list of all keys presented in CloudStorage.\n * @param options - request execution options.\n */\n async getKeys(options?: WiredRequestOptions): Promise<string[]> {\n const result = await this.invokeCustomMethod('getStorageKeys', {}, options);\n\n return stringArray.parse(result);\n }\n\n /**\n * Returns map, where key is one of the specified in keys argument, and value is according\n * storage value.\n * @param keys - keys list.\n * @param options - request execution options.\n */\n async getValues<K extends string>(\n keys: K[],\n options?: WiredRequestOptions,\n ): Promise<Record<K, string>> {\n if (keys.length === 0) {\n return objectFromKeys(keys, '');\n }\n\n const schema = json<Record<K, string>>(\n objectFromKeys(keys, string()) as any, // fixme\n );\n const result = await this.invokeCustomMethod('getStorageValues', { keys }, options);\n\n return schema.parse(result);\n }\n\n /**\n * Saves specified value by key.\n * @param key - storage key.\n * @param value - storage value.\n * @param options - request execution options.\n */\n async saveValue(key: string, value: string, options?: WiredRequestOptions): Promise<void> {\n await this.invokeCustomMethod('saveStorageValue', { key, value }, options);\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<\n | 'deleteKeys'\n | 'getKeys'\n | 'getValues'\n | 'saveValue'\n >;\n}\n","import type { Version } from '@tma.js/utils';\nimport {\n postEvent as defaultPostEvent,\n type PostEvent,\n type ImpactHapticFeedbackStyle,\n type NotificationHapticFeedbackType,\n} from '@tma.js/bridge';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\n\n/**\n * Class which controls haptic feedback. It allows calling different types of\n * haptic notifications which usually occur after user interaction with\n * application.\n */\nexport class HapticFeedback {\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.supports = createSupportsFunc(version, {\n impactOccurred: 'web_app_trigger_haptic_feedback',\n notificationOccurred: 'web_app_trigger_haptic_feedback',\n selectionChanged: 'web_app_trigger_haptic_feedback',\n });\n }\n\n /**\n * A method tells that an impact occurred. The Telegram app may play the\n * appropriate haptics based on style value passed.\n * @param style - impact style.\n */\n impactOccurred(style: ImpactHapticFeedbackStyle): void {\n this.postEvent('web_app_trigger_haptic_feedback', { type: 'impact', impact_style: style });\n }\n\n /**\n * A method tells that a task or action has succeeded, failed, or produced\n * a warning. The Telegram app may play the appropriate haptics based on\n * type value passed.\n * @param type - notification type.\n */\n notificationOccurred(type: NotificationHapticFeedbackType): void {\n this.postEvent('web_app_trigger_haptic_feedback', {\n type: 'notification',\n notification_type: type,\n });\n }\n\n /**\n * A method tells that the user has changed a selection. The Telegram app\n * may play the appropriate haptics.\n *\n * Do not use this feedback when the user makes or confirms a selection;\n * use it only when the selection changes.\n */\n selectionChanged(): void {\n this.postEvent('web_app_trigger_haptic_feedback', { type: 'selection_change' });\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'impactOccurred' | 'notificationOccurred' | 'selectionChanged'>;\n}\n","import type { HasUndefined, If } from '@tma.js/util-types';\nimport type {\n Chat,\n InitData as InitDataType,\n User,\n} from '@tma.js/init-data';\n\nimport { State } from '../../state/index.js';\n\ntype InitDataState = {\n [K in keyof InitDataType]-?: 'canSendAfter' extends K\n ? Date | null\n : If<\n HasUndefined<InitDataType[K]>,\n Exclude<InitDataType[K], undefined> | null,\n InitDataType[K]\n >;\n};\n\n/**\n * Class which is responsible for displaying Web Apps init data.\n */\nexport class InitData {\n private readonly state: State<InitDataState>;\n\n constructor(\n authDate: Date,\n hash: string,\n options: Omit<InitDataType, 'authDate' | 'hash'> = {},\n ) {\n const {\n chat = null,\n canSendAfter = null,\n chatType = null,\n chatInstance = null,\n user = null,\n queryId = null,\n receiver = null,\n startParam = null,\n } = options;\n this.state = new State({\n authDate,\n canSendAfter: canSendAfter === null\n ? null\n : new Date(authDate.getTime() + canSendAfter * 1000),\n chat,\n chatType,\n chatInstance,\n user,\n queryId,\n receiver,\n startParam,\n hash,\n });\n }\n\n /**\n * Init data generation date.\n */\n get authDate(): Date {\n return this.state.get('authDate');\n }\n\n /**\n * Date after which a message can be sent via the answerWebAppQuery\n * method.\n * @see https://core.telegram.org/bots/api#answerwebappquery\n */\n get canSendAfter(): Date | null {\n return this.state.get('canSendAfter');\n }\n\n /**\n * An object containing data about the chat where the bot was\n * launched via the attachment menu. Returned for supergroups, channels and\n * group chats – only for Web Apps launched via the attachment menu.\n */\n get chat(): Chat | null {\n return this.state.get('chat');\n }\n\n /**\n * A hash of all passed parameters, which the bot server can use to\n * check their validity.\n * @see https://core.telegram.org/bots/webapps#validating-data-received-via-the-web-app\n */\n get hash(): string {\n return this.state.get('hash');\n }\n\n /**\n * A unique identifier for the Web App session, required for sending\n * messages via the `answerWebAppQuery` method.\n * @see https://core.telegram.org/bots/api#answerwebappquery\n */\n get queryId(): string | null {\n return this.state.get('queryId');\n }\n\n /**\n * An object containing data about the chat partner of the current\n * user in the chat where the bot was launched via the attachment menu.\n * Returned only for private chats and only for Web Apps launched\n * via the attachment menu.\n */\n get receiver(): User | null {\n return this.state.get('receiver');\n }\n\n /**\n * The value of the `startattach` parameter, passed via link. Only\n * returned for Web Apps when launched from the attachment menu via link.\n */\n get startParam(): string | null {\n return this.state.get('startParam');\n }\n\n /**\n * An object containing data about the current user.\n */\n get user(): User | null {\n return this.state.get('user');\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, off, postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport type { RGB } from '@tma.js/colors';\n\nimport { State } from '../../state/index.js';\n\nimport type { MainButtonEventListener, MainButtonEvents, MainButtonState } from './types.js';\n\n/**\n * Controls the main button, which is displayed at the bottom\n * of the Web App in the Telegram interface.\n */\nexport class MainButton {\n private readonly ee = new EventEmitter<MainButtonEvents>();\n\n private readonly state: State<MainButtonState>;\n\n constructor(\n backgroundColor: RGB,\n isEnabled: boolean,\n isVisible: boolean,\n isProgressVisible: boolean,\n text: string,\n textColor: RGB,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n backgroundColor,\n isEnabled,\n isVisible,\n isProgressVisible,\n text,\n textColor,\n }, this.ee);\n }\n\n private set isEnabled(value: boolean) {\n this.state.set('isEnabled', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton is currently enabled.\n */\n get isEnabled(): boolean {\n return this.state.get('isEnabled');\n }\n\n private set isProgressVisible(value: boolean) {\n this.state.set('isProgressVisible', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton loading progress is currently visible.\n */\n get isProgressVisible(): boolean {\n return this.state.get('isProgressVisible');\n }\n\n private set isVisible(value: boolean) {\n this.state.set('isVisible', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton is currently visible.\n */\n get isVisible(): boolean {\n return this.state.get('isVisible');\n }\n\n /**\n * Sends current local button state to Telegram application.\n */\n private commit(): void {\n // We should not commit changes until payload is correct. We could\n // have some invalid values in case, button instance was created\n // with empty values. Otherwise, an unexpected behaviour could be received.\n if (this.text === '') {\n return;\n }\n\n this.postEvent('web_app_setup_main_button', {\n is_visible: this.isVisible,\n is_active: this.isEnabled,\n is_progress_visible: this.isProgressVisible,\n text: this.text,\n color: this.backgroundColor,\n text_color: this.textColor,\n });\n }\n\n /**\n * Returns current main button background color.\n */\n get backgroundColor(): RGB {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns current main button text.\n */\n get text(): string {\n return this.state.get('text');\n }\n\n /**\n * Returns current main button text color.\n */\n get textColor(): RGB {\n return this.state.get('textColor');\n }\n\n /**\n * Disables button. Returns current button instance for chaining.\n */\n disable(): this {\n // FIXME: This method does not work on Android. Event \"main_button_pressed\"\n // keeps getting received even in case, button is disabled.\n // Issue: https://github.com/Telegram-Mini-Apps/documentation/issues/1\n this.isEnabled = false;\n return this;\n }\n\n /**\n * Enables button. Returns current button instance for chaining.\n */\n enable(): this {\n this.isEnabled = true;\n return this;\n }\n\n /**\n * Hides button. Returns current button instance for chaining.\n */\n hide(): this {\n this.isVisible = false;\n return this;\n }\n\n /**\n * Hides button progress. Returns current button instance for chaining.\n */\n hideProgress(): this {\n this.isProgressVisible = false;\n return this;\n }\n\n /**\n * Adds new event listener.\n * FIXME: Event 'main_button_pressed' is still being received on Android\n * even if the main button is disabled.\n * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3\n * @param event - event name.\n * @param listener - event listener.\n */\n on: typeof this.ee.on = (event, listener) => {\n if (event === 'click') {\n return on('main_button_pressed', listener as MainButtonEventListener<'click'>);\n }\n this.ee.on(event, listener);\n };\n\n /**\n * Removes event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n off: typeof this.ee.off = (event, listener) => {\n if (event === 'click') {\n return off('main_button_pressed', listener as MainButtonEventListener<'click'>);\n }\n this.ee.off(event, listener);\n };\n\n /**\n * Shows the button. Note that opening the Web App from the attachment\n * menu hides the main button until the user interacts with the Web App\n * interface.\n *\n * Returns current button instance for chaining.\n */\n show(): this {\n this.isVisible = true;\n return this;\n }\n\n /**\n * A method to show a loading indicator on the button.\n * It is recommended to display loading progress if the action tied to the\n * button may take a long time.\n *\n * Returns current button instance for chaining.\n */\n showProgress(): this {\n this.isProgressVisible = true;\n return this;\n }\n\n /**\n * Sets new main button text. Returns current button instance for chaining.\n * Minimal length for text is 1 symbol, and maximum is 64 symbols.\n *\n * Returns current button instance for chaining.\n * @param value - new text.\n */\n setText(value: string): this {\n this.state.set('text', value);\n this.commit();\n\n return this;\n }\n\n /**\n * Sets new main button text color. Returns current button instance for\n * chaining.\n *\n * Returns current button instance for chaining.\n * @param value - new text color.\n */\n setTextColor(value: RGB): this {\n this.state.set('textColor', value);\n this.commit();\n\n return this;\n }\n\n /**\n * Updates current button color. Returns current button instance for\n * chaining.\n *\n * Returns current button instance for chaining.\n * @param value - color to set.\n */\n setBackgroundColor(value: RGB): this {\n this.state.set('backgroundColor', value);\n this.commit();\n\n return this;\n }\n}\n","import type { PopupButton, PopupParams as BridgePopupParams } from '@tma.js/bridge';\n\nimport type { PopupParams } from './types.js';\n\n/**\n * Prepares popup parameters before sending them to native app.\n * @param params - popup parameters.\n */\nexport function preparePopupParams(params: PopupParams): BridgePopupParams {\n const message = params.message.trim();\n const title = (params.title || '').trim();\n const buttons = params.buttons || [];\n let preparedButtons: PopupButton[];\n\n // Check title.\n if (title.length > 64) {\n throw new Error(`Title has incorrect size: ${title.length}`);\n }\n\n // Check message.\n if (message.length === 0 || message.length > 256) {\n throw new Error(`Message has incorrect size: ${message.length}`);\n }\n\n // Check buttons.\n if (buttons.length > 3) {\n throw new Error(`Buttons have incorrect size: ${buttons.length}`);\n }\n\n // Append button in case, there are no buttons passed.\n if (buttons.length === 0) {\n preparedButtons = [{ type: 'close', id: '' }];\n } else {\n // Otherwise, check all the buttons.\n preparedButtons = buttons.map((b) => {\n const { id = '' } = b;\n\n // Check button ID.\n if (id.length > 64) {\n throw new Error(`Button ID has incorrect size: ${id}`);\n }\n\n if (b.type === undefined || b.type === 'default' || b.type === 'destructive') {\n const text = b.text.trim();\n\n if (text.length === 0 || text.length > 64) {\n const type = b.type || 'default';\n\n throw new Error(`Button text with type \"${type}\" has incorrect size: ${b.text.length}`);\n }\n\n return { ...b, text, id };\n }\n\n return { ...b, id };\n });\n }\n return { title, message, buttons: preparedButtons };\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, request, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { preparePopupParams } from './utils.js';\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { PopupParams, PopupEvents, PopupState } from './types.js';\n\n/**\n * Controls currently displayed application popup. It allows developers to\n * open new custom popups and detect popup-connected events.\n */\nexport class Popup {\n private readonly ee = new EventEmitter<PopupEvents>();\n\n private readonly state: State<PopupState>;\n\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.state = new State({ isOpened: false }, this.ee);\n this.supports = createSupportsFunc(version, { open: 'web_app_open_popup' });\n }\n\n /**\n * Shows whether popup is currently opened.\n */\n get isOpened(): boolean {\n return this.state.get('isOpened');\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n\n /**\n * A method that shows a native popup described by the `params` argument.\n * Promise will be resolved when popup is closed. Resolved value will have\n * an identifier of pressed button.\n *\n * In case, user clicked outside the popup or clicked top right popup close\n * button, null will be returned.\n *\n * FIXME: In desktop, this function may work incorrectly.\n * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7\n * @param params - popup parameters.\n * @throws {Error} Popup is already opened.\n */\n async open(params: PopupParams): Promise<string | null> {\n if (this.isOpened) {\n throw new Error('Popup is already opened.');\n }\n\n this.state.set('isOpened', true);\n\n try {\n const { button_id: buttonId = null } = await request(\n 'web_app_open_popup',\n preparePopupParams(params),\n 'popup_closed',\n { postEvent: this.postEvent },\n );\n\n return buttonId;\n } finally {\n this.state.set('isOpened', false);\n }\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'open'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, request, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { QRScannerEvents, QRScannerState } from './types.js';\n\n/**\n * Provides QR scanner functionality.\n */\nexport class QRScanner {\n private readonly ee = new EventEmitter<QRScannerEvents>();\n\n private readonly state: State<QRScannerState>;\n\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.state = new State({ isOpened: false }, this.ee);\n this.supports = createSupportsFunc(version, {\n close: 'web_app_close_scan_qr_popup',\n open: 'web_app_open_scan_qr_popup',\n });\n }\n\n /**\n * Closes scanner.\n */\n close(): void {\n this.postEvent('web_app_close_scan_qr_popup');\n this.isOpened = false;\n }\n\n private set isOpened(value) {\n this.state.set('isOpened', value);\n }\n\n /**\n * Returns true in case, QR scanner is currently opened.\n */\n get isOpened(): boolean {\n return this.state.get('isOpened');\n }\n\n /**\n * Opens scanner with specified title shown to user. Method returns promise\n * with scanned QR content in case, it was scanned. It will contain null in\n * case, scanner was closed.\n * @param text - title to display.\n */\n async open(text?: string): Promise<string | null> {\n if (this.isOpened) {\n throw new Error('QR scanner is already opened.');\n }\n\n this.isOpened = true;\n\n try {\n const result = await request(\n 'web_app_open_scan_qr_popup',\n { text },\n ['qr_text_received', 'scan_qr_popup_closed'],\n { postEvent: this.postEvent },\n );\n\n return typeof result === 'object' && typeof result.data === 'string' ? result.data : null;\n } finally {\n this.isOpened = false;\n }\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'open' | 'close'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { parse, type ThemeParams as ThemeParamsType } from '@tma.js/theme-params';\nimport { on, request, type RequestOptions } from '@tma.js/bridge';\nimport { isColorDark } from '@tma.js/colors';\n\nimport type { RGB } from '@tma.js/colors';\n\nimport { State } from '../../state/index.js';\n\nimport type { ThemeParamsEvents, ThemeParamsState } from './types.js';\n\nfunction prepareThemeParams(value: ThemeParamsType): ThemeParamsState {\n const {\n backgroundColor = null,\n buttonTextColor = null,\n buttonColor = null,\n hintColor = null,\n linkColor = null,\n textColor = null,\n secondaryBackgroundColor = null,\n } = value;\n\n return {\n backgroundColor,\n buttonTextColor,\n buttonColor,\n hintColor,\n linkColor,\n textColor,\n secondaryBackgroundColor,\n };\n}\n\n/**\n * Contains information about currently used theme by application.\n * @see https://core.telegram.org/bots/webapps#themeparams\n */\nexport class ThemeParams {\n /**\n * Requests fresh information about current theme.\n * FIXME: Be careful using this function in desktop version of Telegram as\n * long as method web_app_request_theme does not work on `macos` platform.\n * @param options - method options.\n */\n static async request(options: RequestOptions = {}): Promise<ThemeParamsType> {\n const { timeout = 1000, ...restOptions } = options;\n const result = await request('web_app_request_theme', 'theme_changed', {\n ...restOptions,\n timeout,\n });\n\n return parse(result.theme_params);\n }\n\n /**\n * Synchronizes specified instance of ThemeParams with the actual value in the native\n * application.\n * @param themeParams - ThemeParams instance.\n */\n static sync(themeParams: ThemeParams): void {\n on('theme_changed', (event) => {\n themeParams.state.set(prepareThemeParams(parse(event.theme_params)));\n });\n }\n\n /**\n * Returns instance of ThemeParams which is synchronized with external\n * environment.\n * @param options - method options.\n */\n static async synced(options?: RequestOptions): Promise<ThemeParams> {\n const params = await this.request(options);\n const tp = new ThemeParams(params);\n\n this.sync(tp);\n\n return tp;\n }\n\n private readonly ee = new EventEmitter<ThemeParamsEvents>();\n\n private readonly state: State<ThemeParamsState>;\n\n constructor(params: ThemeParamsType) {\n this.state = new State(prepareThemeParams(params), this.ee);\n }\n\n /**\n * Returns background color.\n */\n get backgroundColor(): RGB | null {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns button color.\n */\n get buttonColor(): RGB | null {\n return this.state.get('buttonColor');\n }\n\n /**\n * Returns button text color.\n */\n get buttonTextColor(): RGB | null {\n return this.state.get('buttonTextColor');\n }\n\n /**\n * Returns hint color.\n */\n get hintColor(): RGB | null {\n return this.state.get('hintColor');\n }\n\n /**\n * Returns true in case, current color scheme is recognized as dark. This\n * value is calculated according to theme background color.\n */\n get isDark(): boolean {\n return this.backgroundColor === null || isColorDark(this.backgroundColor);\n }\n\n /**\n * Returns current link color.\n */\n get linkColor(): RGB | null {\n return this.state.get('linkColor');\n }\n\n /**\n * Adds new event listener.\n */\n on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off = this.ee.off.bind(this.ee);\n\n /**\n * Returns secondary background color.\n */\n get secondaryBackgroundColor(): RGB | null {\n return this.state.get('secondaryBackgroundColor');\n }\n\n /**\n * Returns text color.\n */\n get textColor(): RGB | null {\n return this.state.get('textColor');\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, postEvent as defaultPostEvent, request, type RequestOptions, type PostEvent } from '@tma.js/bridge';\n\nimport { State } from '../../state/index.js';\n\nimport type { ViewportEvents, ViewportState } from './types.js';\n\nexport interface RequestViewportResult {\n height: number;\n isStateStable: boolean;\n isExpanded: boolean;\n width: number;\n}\n\n/**\n * Formats value to make it stay in bounds [0, +Inf).\n * @param value - value to format.\n */\nfunction truncate(value: number): number {\n return value < 0 ? 0 : value;\n}\n\n/**\n * Contains information about current WebApp device viewport, its dimensions\n * and state.\n */\nexport class Viewport {\n /**\n * Requests fresh information about current viewport.\n * FIXME: Be careful using this function in desktop version of Telegram as\n * long as method web_app_request_viewport does not work on `macos` platform.\n * @see Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/5\n * @param options - method options.\n */\n static async request(options: RequestOptions = {}): Promise<RequestViewportResult> {\n const { timeout = 1000, ...restOptions } = options;\n const {\n is_expanded: isExpanded,\n is_state_stable: isStateStable,\n ...rest\n } = await request('web_app_request_viewport', 'viewport_changed', {\n ...restOptions,\n timeout,\n });\n\n return { ...rest, isExpanded, isStateStable };\n }\n\n /**\n * Synchronizes specified instance of Viewport with the actual value in the native\n * application.\n * @param viewport - Viewport instance.\n */\n static sync(viewport: Viewport): void {\n on('viewport_changed', (event) => {\n const {\n height,\n width,\n is_expanded: isExpanded,\n is_state_stable: isStateStable,\n } = event;\n const formattedHeight = truncate(height);\n\n viewport.state.set({\n height: formattedHeight,\n isExpanded,\n width: truncate(width),\n stableHeight: isStateStable ? formattedHeight : undefined,\n });\n });\n }\n\n /**\n * Returns initialized instance of Viewport which is synchronized with\n * its actual state in Web Apps.\n * @param options - method options.\n */\n static async synced(options: RequestOptions = {}): Promise<Viewport> {\n const { height, isExpanded, width } = await this.request(options);\n const viewport = new Viewport(height, width, height, isExpanded, options.postEvent);\n\n this.sync(viewport);\n\n return viewport;\n }\n\n private readonly ee = new EventEmitter<ViewportEvents>();\n\n private readonly state: State<ViewportState>;\n\n constructor(\n height: number,\n width: number,\n stableHeight: number,\n isExpanded: boolean,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n height: truncate(height),\n isExpanded,\n stableHeight: truncate(stableHeight),\n width: truncate(width),\n }, this.ee);\n }\n\n /**\n * The current height of the visible area of the Web App.\n *\n * The application can display just the top part of the Web App, with its\n * lower part remaining outside the screen area. From this position, the\n * user can \"pull\" the Web App to its maximum height, while the bot can do\n * the same by calling `expand` method. As the position of the Web App\n * changes, the current height value of the visible area will be updated\n * in real time.\n *\n * Please note that the refresh rate of this value is not sufficient\n * to smoothly follow the lower border of the window. It should not be\n * used to pin interface elements to the bottom of the visible area. It's\n * more appropriate to use the value of the `stableHeight`\n * field for this purpose.\n *\n * @see init\n * @see expand\n * @see stableHeight\n */\n get height(): number {\n return this.state.get('height');\n }\n\n /**\n * The height of the visible area of the Web App in its last stable state.\n *\n * The application can display just the top part of the Web App, with its\n * lower part remaining outside the screen area. From this position,\n * the user can \"pull\" the Web App to its maximum height, while the bot can\n * do the same by calling `expand` method.\n *\n * Unlike the value of `height`, the value of `stableHeight`\n * does not change as the position of the Web App changes with user\n * gestures or during animations. The value of `stableHeight`\n * will be updated after all gestures and animations are completed and\n * the Web App reaches its final size.\n *\n * @see init\n * @see expand\n * @see height\n */\n get stableHeight(): number {\n return this.state.get('stableHeight');\n }\n\n /**\n * Returns true if the Web App is expanded to the maximum available height.\n * Otherwise, if the Web App occupies part of the screen and can be expanded\n * to the full height using `expand` method.\n * @see expand\n */\n get isExpanded(): boolean {\n return this.state.get('isExpanded');\n }\n\n /**\n * Current viewport width.\n */\n get width(): number {\n return this.state.get('width');\n }\n\n /**\n * A method that expands the Web App to the maximum available height. To\n * find out if the Web App is expanded to the maximum height, refer to the\n * value of the `isExpanded`.\n * @see isExpanded\n */\n expand(): void {\n this.state.set('isExpanded', true);\n this.postEvent('web_app_expand');\n }\n\n /**\n * Returns true in case current viewport height is stable and is not going to\n * change in the next moment.\n */\n get isStable(): boolean {\n return this.stableHeight === this.height;\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n}\n","/**\n * Converts passed URL to its full form.\n * @param url - URL to format.\n * @throws {Error} URL protocol is not supported by OS, or link has not allowed\n * protocol.\n */\nexport function formatURL(url: string): string {\n // TODO: Maybe, there is a bit easier way? window.open will accept\n // unformatted URL too, probably.\n\n // We do create new anchor element and assign its href to passed URL. This\n // will format link, so it could be used in `window.open`.\n const anchor = document.createElement('a');\n anchor.href = url;\n\n // Check if protocol is correct.\n if (anchor.protocol !== 'http:' && anchor.protocol !== 'https:') {\n throw Error(\n `URL protocol is not supported by OS, or link has not allowed protocol: ${anchor.protocol}`,\n );\n }\n return anchor.href;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { compareVersions, type Version } from '@tma.js/utils';\nimport { isRGB, isColorDark, type RGB } from '@tma.js/colors';\nimport {\n postEvent as defaultPostEvent,\n supports,\n request,\n type PhoneRequestedStatus,\n type WriteAccessRequestedStatus,\n type InvoiceStatus,\n type PostEvent,\n} from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { formatURL } from '../../url.js';\nimport { State } from '../../state/index.js';\nimport { createSupportsFunc, createSupportsParamFunc, type SupportsFunc } from '../../supports.js';\n\nimport type { ColorScheme } from '../../types.js';\nimport type { WebAppEvents, WebAppHeaderColor, WebAppState } from './types.js';\n\n/**\n * Provides common Web Apps functionality not covered by other system\n * components.\n */\nexport class WebApp {\n private readonly ee = new EventEmitter<WebAppEvents>();\n\n private readonly state: State<WebAppState>;\n\n constructor(\n headerColor: WebAppHeaderColor,\n backgroundColor: RGB,\n private readonly currentVersion: Version,\n private readonly currentPlatform: Platform,\n private readonly createRequestId: () => string,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n backgroundColor,\n headerColor,\n }, this.ee);\n this.supports = createSupportsFunc(currentVersion, {\n openInvoice: 'web_app_open_invoice',\n readTextFromClipboard: 'web_app_read_text_from_clipboard',\n setHeaderColor: 'web_app_set_header_color',\n setBackgroundColor: 'web_app_set_background_color',\n requestPhoneAccess: 'web_app_request_phone',\n requestWriteAccess: 'web_app_request_write_access',\n });\n this.supportsParam = createSupportsParamFunc(currentVersion, {\n 'setHeaderColor.color': ['web_app_set_header_color', 'color'],\n 'openLink.tryInstantView': ['web_app_open_link', 'try_instant_view'],\n });\n }\n\n /**\n * Returns current application background color.\n */\n get backgroundColor(): RGB {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns current application color scheme. This value is\n * computed based on the current background color.\n */\n get colorScheme(): ColorScheme {\n return isColorDark(this.backgroundColor) ? 'dark' : 'light';\n }\n\n /**\n * Closes the Web App.\n */\n close(): void {\n this.postEvent('web_app_close');\n }\n\n /**\n * Returns current application header color.\n */\n get headerColor(): WebAppHeaderColor {\n return this.state.get('headerColor');\n }\n\n /**\n * Returns true if passed version is more than or equal to current\n * Web App version.\n * @param version - compared version.\n */\n isVersionAtLeast(version: Version): boolean {\n return compareVersions(version, this.version) >= 0;\n }\n\n /**\n * Opens a link in an external browser. The Web App will not be closed.\n *\n * Note that this method can be called only in response to the user\n * interaction with the Web App interface (e.g. click inside the Web App\n * or on the main button).\n * @param url - URL to be opened.\n * @param tryInstantView\n */\n openLink(url: string, tryInstantView?: boolean): void {\n const formattedUrl = formatURL(url);\n\n // If method is not supported, we are doing it in legacy way.\n if (!supports('web_app_open_link', this.version)) {\n window.open(formattedUrl, '_blank');\n return;\n }\n\n // Otherwise, do it normally.\n return this.postEvent('web_app_open_link', {\n url: formattedUrl,\n ...(typeof tryInstantView === 'boolean' ? { try_instant_view: tryInstantView } : {}),\n });\n }\n\n /**\n * Opens a Telegram link inside Telegram app. The Web App will be closed.\n * It expects passing link in full format, with hostname \"t.me\".\n * @param url - URL to be opened.\n * @throws {Error} URL has not allowed hostname.\n */\n openTelegramLink(url: string): void {\n const { hostname, pathname, search } = new URL(formatURL(url));\n\n if (hostname !== 't.me') {\n throw new Error(`URL has not allowed hostname: ${hostname}. Only \"t.me\" is allowed`);\n }\n\n if (!supports('web_app_open_tg_link', this.version)) {\n window.location.href = url;\n return;\n }\n\n return this.postEvent('web_app_open_tg_link', { path_full: pathname + search });\n }\n\n /**\n * Opens an invoice using its url. It expects passing link in full format,\n * with hostname \"t.me\".\n * @param url - invoice URL.\n */\n async openInvoice(url: string): Promise<InvoiceStatus> {\n // TODO: Allow opening with slug.\n const { hostname, pathname } = new URL(formatURL(url));\n\n if (hostname !== 't.me') {\n throw new Error(`Incorrect hostname: ${hostname}`);\n }\n // Valid examples:\n // \"/invoice/my-slug\"\n // \"/$my-slug\"\n const match = pathname.match(/^\\/(\\$|invoice\\/)([A-Za-z0-9\\-_=]+)$/);\n\n if (match === null) {\n throw new Error('Link pathname has incorrect format. Expected to receive \"/invoice/slug\" or \"/$slug\"');\n }\n const [, , slug] = match;\n\n const result = await request('web_app_open_invoice', { slug }, 'invoice_closed', {\n postEvent: this.postEvent,\n capture: ({ slug: eventSlug }) => slug === eventSlug,\n });\n\n return result.status;\n }\n\n /**\n * Adds new event listener.\n */\n on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off = this.ee.off.bind(this.ee);\n\n /**\n * Returns current Web App platform.\n */\n get platform(): Platform {\n return this.currentPlatform;\n }\n\n /**\n * Informs the Telegram app that the Web App is ready to be displayed.\n *\n * It is recommended to call this method as early as possible, as soon as\n * all essential interface elements loaded. Once this method called,\n * the loading placeholder is hidden and the Web App shown.\n *\n * If the method not called, the placeholder will be hidden only when\n * the page fully loaded.\n */\n ready(): void {\n this.postEvent('web_app_ready');\n }\n\n /**\n * Reads text from clipboard and returns string or null. null is returned\n * in cases:\n * - Value in clipboard is not text\n * - Access to clipboard is not allowed\n */\n async readTextFromClipboard(): Promise<string | null> {\n // TODO: Generate request id.\n const { data = null } = await request(\n 'web_app_read_text_from_clipboard',\n { req_id: this.createRequestId() },\n 'clipboard_text_received',\n { postEvent: this.postEvent },\n );\n\n return data;\n }\n\n /**\n * Requests current user phone access.\n */\n async requestPhoneAccess(): Promise<PhoneRequestedStatus> {\n const { status } = await request('web_app_request_phone', 'phone_requested', {\n postEvent: this.postEvent,\n });\n\n return status;\n }\n\n /**\n * Requests write message access to current user.\n */\n async requestWriteAccess(): Promise<WriteAccessRequestedStatus> {\n const { status } = await request('web_app_request_write_access', 'write_access_requested', {\n postEvent: this.postEvent,\n });\n\n return status;\n }\n\n /**\n * A method used to send data to the bot. When this method called, a\n * service message sent to the bot containing the data of the\n * length up to 4096 bytes, and the Web App closed. See the field\n * `web_app_data` in the class Message.\n *\n * This method is only available for Web Apps launched via a Keyboard button.\n * @param data - data to send to bot.\n * @throws {Error} data has incorrect size.\n */\n sendData(data: string): void {\n // Firstly, compute passed text size in bytes.\n const { size } = new Blob([data]);\n if (size === 0 || size > 4096) {\n throw new Error(`Passed data has incorrect size: ${size}`);\n }\n this.postEvent('web_app_data_send', { data });\n }\n\n /**\n * Updates current application header color.\n * FIXME: Has no effect on desktop, works incorrectly on Android.\n * Issues:\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/9\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/8\n * @param color - color key or RGB color.\n */\n setHeaderColor(color: WebAppHeaderColor) {\n this.postEvent('web_app_set_header_color', isRGB(color) ? { color } : { color_key: color });\n this.state.set('headerColor', color);\n }\n\n /**\n * Updates current application background color.\n * FIXME: Has no effect on desktop, works incorrectly in Android.\n * Issues:\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/9\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/8\n * @param color - RGB color.\n */\n setBackgroundColor(color: RGB) {\n this.postEvent('web_app_set_background_color', { color });\n this.state.set('backgroundColor', color);\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<\n | 'openInvoice'\n | 'readTextFromClipboard'\n | 'setHeaderColor'\n | 'setBackgroundColor'\n | 'requestWriteAccess'\n | 'requestPhoneAccess'\n >;\n\n /**\n * Checks if specified method parameter is supported by current component.\n */\n supportsParam: SupportsFunc<'setHeaderColor.color' | 'openLink.tryInstantView'>;\n\n /**\n * Current Web App version. This property is used by other components to check if\n * some functionality is available on current device.\n */\n get version(): Version {\n return this.currentVersion;\n }\n}\n","/**\n * Error thrown in case, unsupported method was called.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string, version: string) {\n super(`Method \"${method}\" is not supported in the Web Apps version ${version}.`);\n Object.setPrototypeOf(this, MethodNotSupportedError.prototype);\n }\n}\n","/**\n * Error thrown in case, unsupported parameter was used.\n */\nexport class ParameterUnsupportedError extends Error {\n constructor(method: string, param: string, version: string) {\n super(`Parameter \"${param}\" in method \"${method}\" is not supported in the Web Apps version ${version}.`);\n Object.setPrototypeOf(this, ParameterUnsupportedError.prototype);\n }\n}\n","import type { RGB } from '@tma.js/colors';\n\nimport type { ThemeParams, WebApp, Viewport } from '../components/index.js';\nimport type { InitCSSVarsOption, InitCSSVarsSpecificOption } from './types.js';\n\n/**\n * Sets CSS variable.\n * @param name - variable name.\n * @param value - variable value.\n */\nfunction setVariable(name: string, value: string): void {\n document.documentElement.style.setProperty(name, value);\n}\n\n/**\n * Sets new CSS color variable in case, its value is not null.\n * @param name - variable name.\n * @param color - variable value.\n */\nfunction setColorVariable(name: string, color: RGB | null): void {\n if (color === null) {\n return;\n }\n setVariable(name, color);\n}\n\n/**\n * Sets new CSS variable which value is amount of pixels.\n * @param name - variable name.\n * @param size - variable value.\n */\nfunction setSizeVariable(name: string, size: number) {\n setVariable(name, `${size}px`);\n}\n\n/**\n * Creates CSS variables based on theme parameters.\n * @param themeParams - ThemeParams instance.\n */\nfunction createThemeVariables(themeParams: ThemeParams): void {\n const {\n backgroundColor,\n buttonTextColor,\n secondaryBackgroundColor,\n hintColor,\n buttonColor,\n linkColor,\n textColor,\n } = themeParams;\n\n setColorVariable('--tg-theme-bg-color', backgroundColor);\n setColorVariable('--tg-theme-button-color', buttonColor);\n setColorVariable('--tg-theme-button-text-color', buttonTextColor);\n setColorVariable('--tg-theme-hint-color', hintColor);\n setColorVariable('--tg-theme-link-color', linkColor);\n setColorVariable('--tg-theme-secondary-bg-color', secondaryBackgroundColor);\n setColorVariable('--tg-theme-text-color', textColor);\n}\n\n/**\n * Creates CSS variables based on Web App background and header colors with\n * theme parameters.\n * @param webApp - WebApp instance.\n * @param themeParams - theme parameters.\n */\nfunction createWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {\n const { backgroundColor, secondaryBackgroundColor } = themeParams;\n const { backgroundColor: webAppBackgroundColor, headerColor } = webApp;\n\n setColorVariable('--tg-bg-color', webAppBackgroundColor);\n setColorVariable('--tg-header-color', headerColor === 'bg_color' ? backgroundColor : secondaryBackgroundColor);\n}\n\n/**\n * Creates CSS variables connected with theme parameters.\n *\n * Created variables:\n * - `--tg-theme-bg-color`\n * - `--tg-theme-button-color`\n * - `--tg-theme-button-text-color`\n * - `--tg-theme-hint-color`\n * - `--tg-theme-link-color`\n * - `--tg-theme-secondary-bg-color`\n * - `--tg-theme-text-color`\n *\n * Variables are being automatically updated in case, corresponding properties\n * updated in passed ThemeParams instance.\n *\n * @param themeParams - ThemeParams instance.\n */\nexport function bindThemeCSSVariables(themeParams: ThemeParams): void {\n const actualize = () => createThemeVariables(themeParams);\n\n themeParams.on('changed', actualize);\n\n actualize();\n}\n\n/**\n * Creates CSS variables connected with WebApp background and header colors based on\n * passed WebApp and ThemeParams instances.\n *\n * Created variables:\n * - `--tg-bg-color`\n * - `--tg-header-color`\n *\n * Variables are being automatically updated in case, corresponding properties are updating.\n *\n * @param webApp - WebApp instance.\n * @param themeParams - ThemeParams instance.\n */\nexport function bindWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {\n const actualize = () => createWebAppVariables(webApp, themeParams);\n\n themeParams.on('changed', actualize);\n webApp.on('backgroundColorChanged', actualize);\n webApp.on('headerColorChanged', actualize);\n\n actualize();\n}\n\n/**\n * Accepts Viewport instance and sets CSS variables connected with viewport\n * sizes.\n *\n * Be careful using this function as long as it can impact application\n * performance. Viewport size is changing rather often, this makes CSS\n * variables update, which leads to possible layout redraw.\n *\n * Variables:\n * - `--tg-viewport-height`\n * - `--tg-viewport-stable-height`\n *\n * Variables are being automatically updated in case, corresponding properties\n * updated in passed Viewport instance.\n *\n * @param viewport - Viewport instance.\n */\nexport function bindViewportCSSVariables(viewport: Viewport): void {\n const setHeight = () => {\n setSizeVariable('--tg-viewport-height', viewport.height);\n };\n\n const setStableHeight = () => {\n setSizeVariable('--tg-viewport-stable-height', viewport.stableHeight);\n };\n\n viewport.on('heightChanged', setHeight);\n viewport.on('stableHeightChanged', setStableHeight);\n\n setHeight();\n setStableHeight();\n}\n\n/**\n * Converts init cssVars option to more narrow type.\n * @param option - option value.\n */\nexport function parseCSSVarsOptions(option: InitCSSVarsOption): InitCSSVarsSpecificOption {\n if (typeof option === 'boolean') {\n return option\n ? { themeParams: true, viewport: true, webApp: true }\n : {};\n }\n return option;\n}\n","import type { HeaderColorKey } from '@tma.js/bridge';\nimport type { RGB } from '@tma.js/colors';\n\n/**\n * Describes storage keys and according values.\n */\ninterface StorageParams {\n 'back-button': {\n isVisible: boolean\n };\n 'closing-behavior': {\n isConfirmationNeeded: boolean;\n };\n 'main-button': {\n backgroundColor: RGB;\n isEnabled: boolean;\n isVisible: boolean;\n isProgressVisible: boolean;\n text: string;\n textColor: RGB;\n };\n viewport: {\n height: number;\n isExpanded: boolean;\n stableHeight: number;\n width: number;\n };\n 'web-app': {\n backgroundColor: RGB;\n headerColor: HeaderColorKey | RGB;\n };\n}\n\n/**\n * Key which could be used to store data in storage.\n */\ntype StorageKey = keyof StorageParams;\n\n/**\n * Formats key which could be used during the communication with the storage.\n * @param key - session storage key.\n */\nfunction formatKey(key: StorageKey): string {\n return `telegram-mini-apps-${key}`;\n}\n\n/**\n * Saves value in sessionStorage.\n * @param key - storage key.\n * @param value - storage value.\n */\nexport function saveStorageValue<K extends StorageKey>(key: K, value: StorageParams[K]): void {\n sessionStorage.setItem(formatKey(key), JSON.stringify(value));\n}\n\n/**\n * Extracts value from the sessionStorage.\n * @param key - storage key.\n */\nexport function getStorageValue<K extends StorageKey>(key: K): StorageParams[K] | null {\n const value = sessionStorage.getItem(formatKey(key));\n\n return value ? JSON.parse(value) : null;\n}\n","import type { PostEvent } from '@tma.js/bridge';\n\nimport { BackButton } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates BackButton instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param version - platform version.\n * @param postEvent - Bridge postEvent function\n */\nexport function createBackButton(\n isPageReload: boolean,\n version: string,\n postEvent: PostEvent,\n): BackButton {\n const { isVisible = false } = isPageReload ? getStorageValue('back-button') || {} : {};\n const component = new BackButton(isVisible, version, postEvent);\n\n component.on('isVisibleChanged', () => {\n saveStorageValue('back-button', { isVisible: component.isVisible });\n });\n\n return component;\n}\n","import type { PostEvent } from '@tma.js/bridge';\n\nimport { ClosingBehaviour } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates ClosingBehaviour instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param postEvent - Bridge postEvent function\n */\nexport function createClosingBehavior(\n isPageReload: boolean,\n postEvent: PostEvent,\n): ClosingBehaviour {\n const { isConfirmationNeeded = false } = isPageReload ? getStorageValue('closing-behavior') || {} : {};\n\n const component = new ClosingBehaviour(isConfirmationNeeded, postEvent);\n\n component.on('isConfirmationNeededChanged', () => saveStorageValue('closing-behavior', {\n isConfirmationNeeded: component.isConfirmationNeeded,\n }));\n\n return component;\n}\n","import type { RGB } from '@tma.js/colors';\nimport type { PostEvent } from '@tma.js/bridge';\n\nimport { MainButton } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates MainButton instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param backgroundColor - background color.\n * @param textColor - text color.\n * @param postEvent - Bridge postEvent function\n */\nexport function createMainButton(\n isPageReload: boolean,\n backgroundColor: RGB,\n textColor: RGB,\n postEvent: PostEvent,\n): MainButton {\n const {\n backgroundColor: stateBackgroundColor = backgroundColor,\n isEnabled = false,\n isVisible = false,\n isProgressVisible = false,\n textColor: stateTextColor = textColor,\n text = '',\n } = isPageReload ? getStorageValue('main-button') || {} : {};\n\n const component = new MainButton(\n stateBackgroundColor,\n isEnabled,\n isVisible,\n isProgressVisible,\n text,\n stateTextColor,\n postEvent,\n );\n\n const saveState = () => saveStorageValue('main-button', {\n backgroundColor: component.backgroundColor,\n isEnabled: component.isEnabled,\n isVisible: component.isVisible,\n isProgressVisible: component.isProgressVisible,\n text: component.text,\n textColor: component.textColor,\n });\n\n component.on('backgroundColorChanged', saveState);\n component.on('isEnabledChanged', saveState);\n component.on('isVisibleChanged', saveState);\n component.on('isProgressVisibleChanged', saveState);\n component.on('textColorChanged', saveState);\n component.on('textChanged', saveState);\n\n return component;\n}\n","import {\n supports,\n postEvent as defaultPostEvent,\n detectSupportParams,\n type PostEvent,\n} from '@tma.js/bridge';\nimport { isRecord } from '@tma.js/utils';\n\nimport { MethodNotSupportedError, ParameterUnsupportedError } from '../../errors/index.js';\n\n/**\n * Creates postEvent function.\n * @param checkCompat - should compatibility check be enabled.\n * @param version - platform version.\n */\nexport function createPostEvent(checkCompat: boolean, version: string): PostEvent {\n return checkCompat\n ? (method: any, params: any) => {\n // Firstly, check if method itself is supported.\n if (!supports(method, version)) {\n throw new MethodNotSupportedError(method, version);\n }\n\n // Method could use parameters, which are supported only in specific versions of TWA.\n if (isRecord(params)) {\n detectSupportParams(method, params).forEach((param) => {\n if (!supports(method as any, param, version)) {\n throw new ParameterUnsupportedError(method, param, version);\n }\n });\n }\n\n return defaultPostEvent(method, params);\n }\n : defaultPostEvent;\n}\n","import type { CreateRequestIdFunc } from '../../types.js';\n\n/**\n * Creates function which generated request identifiers.\n */\nexport function createRequestIdGenerator(): CreateRequestIdFunc {\n let requestId = 0;\n\n return () => {\n requestId += 1;\n return requestId.toString();\n };\n}\n","import type { ThemeParams as ThemeParamsType } from '@tma.js/theme-params';\n\nimport { ThemeParams } from '../../components/index.js';\n\n/**\n * Creates synced instance of ThemeParams.\n * @param params - theme parameters.\n */\nexport function createThemeParams(params: ThemeParamsType): ThemeParams {\n const themeParams = new ThemeParams(params);\n ThemeParams.sync(themeParams);\n\n return themeParams;\n}\n","import type { PostEvent } from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { Viewport } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates Viewport instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param platform - Telegram Web Apps platform name.\n * @param postEvent - Bridge postEvent function\n */\nexport async function createViewport(\n isPageReload: boolean,\n platform: Platform,\n postEvent: PostEvent,\n): Promise<Viewport> {\n const {\n height = window.innerHeight,\n stableHeight = window.innerHeight,\n width = window.innerWidth,\n isExpanded = false,\n } = isPageReload ? getStorageValue('viewport') || {} : {};\n\n const createSynced = () => {\n const viewport = new Viewport(height, width, stableHeight, isExpanded, postEvent);\n Viewport.sync(viewport);\n\n return viewport;\n };\n\n // MacOS and Web K versions do not support requesting current viewport information. That's why we\n // should construct Viewport instance by ourselves.\n const component = platform === 'macos' || platform === 'web'\n ? createSynced()\n : await Viewport.synced({ postEvent });\n\n const saveState = () => saveStorageValue('viewport', {\n height: component.height,\n isExpanded: component.isExpanded,\n stableHeight: component.stableHeight,\n width: component.width,\n });\n\n // TODO: Should probably use throttle for height.\n component.on('heightChanged', saveState);\n component.on('isExpandedChanged', saveState);\n component.on('stableHeightChanged', saveState);\n component.on('widthChanged', saveState);\n\n return component;\n}\n","import type { RGB } from '@tma.js/colors';\nimport type { PostEvent } from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { WebApp } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\nimport type { CreateRequestIdFunc } from '../../types.js';\n\n/**\n * Creates WebApp instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param backgroundColor - web app background color.\n * @param version - platform version.\n * @param platform - Telegram Web Apps platform name.\n * @param createRequestId - function which generates request identifiers.\n * @param postEvent - Bridge postEvent function\n */\nexport function createWebApp(\n isPageReload: boolean,\n backgroundColor: RGB,\n version: string,\n platform: Platform,\n createRequestId: CreateRequestIdFunc,\n postEvent: PostEvent,\n): WebApp {\n const {\n backgroundColor: stateBackgroundColor = backgroundColor,\n headerColor = 'bg_color',\n } = isPageReload ? getStorageValue('web-app') || {} : {};\n\n const component = new WebApp(\n headerColor,\n stateBackgroundColor,\n version,\n platform,\n createRequestId,\n postEvent,\n );\n\n const saveState = () => saveStorageValue('web-app', {\n backgroundColor: component.backgroundColor,\n headerColor: component.headerColor,\n });\n\n component.on('backgroundColorChanged', saveState);\n component.on('headerColorChanged', saveState);\n\n return component;\n}\n","import { parse, retrieveFromStorage } from '@tma.js/launch-params';\nimport type { LaunchParams } from '@tma.js/launch-params';\n\n/**\n * Attempts to extract launch params from window.location.hash. In case, window.location.hash\n * lacks of valid data, function attempts to extract launch params from the sessionStorage.\n */\nexport function retrieveLaunchParams(): LaunchParams {\n let error: unknown | undefined;\n\n // Try to extract Mini App data from hash. This block of code covers usual flow, when\n // application was firstly opened by the user and its hash always contains required parameters.\n try {\n return parse(window.location.hash.slice(1));\n } catch (e) {\n error = e;\n }\n\n // Mini Apps allows reloading current page. In this case, window.location.reload() will be\n // called which means, that init will be called again. As the result, current window\n // location will lose Mini App data. To solve this problem, we are extracting launch\n // params saved previously.\n const fromStorage = retrieveFromStorage();\n if (fromStorage) {\n return fromStorage;\n }\n\n throw new Error('Unable to extract launch params', { cause: error });\n}\n","import {\n isIframe,\n setDebug,\n setTargetOrigin,\n on,\n} from '@tma.js/bridge';\nimport { withTimeout } from '@tma.js/utils';\nimport type { LaunchParams } from '@tma.js/launch-params';\nimport {\n parse as parseLaunchParams,\n saveToStorage as saveLaunchParamsToStorage,\n retrieveFromStorage,\n} from '@tma.js/launch-params';\n\nimport {\n CloudStorage,\n HapticFeedback,\n InitData,\n Popup,\n QRScanner,\n} from '../components/index.js';\nimport {\n bindThemeCSSVariables,\n bindViewportCSSVariables,\n bindWebAppVariables,\n parseCSSVarsOptions,\n} from './css.js';\nimport {\n createPostEvent,\n createThemeParams,\n createBackButton,\n createMainButton,\n createViewport,\n createWebApp, createRequestIdGenerator, createClosingBehavior,\n} from './creators/index.js';\nimport { retrieveLaunchParams } from '../launch-params.js';\n\nimport type { InitOptions, InitResult } from './types.js';\n\n/**\n * Returns true in case, current session was created due to native location reload.\n */\nfunction isNativePageReload(): boolean {\n return (\n window\n .performance\n .getEntriesByType('navigation') as PerformanceNavigationTiming[]\n ).some((entry) => entry.type === 'reload');\n}\n\n/**\n * Returns true if current page was reloaded.\n * @param launchParamsFromStorage - launch parameters from sessionStorage.\n * @param currentLaunchParams - actual launch parameters.\n */\nfunction computePageReload(\n launchParamsFromStorage: LaunchParams | null,\n currentLaunchParams: LaunchParams,\n): boolean {\n // To check if page was reloaded, we should check if previous init data hash equals to the\n // current one. Nevertheless, there are some cases, when init data is missing. For example,\n // when app was launched via KeyboardButton. In this case we try to use the native way of\n // checking if current page was reloaded (which could still return incorrect result).\n // Issue: https://github.com/Telegram-Mini-Apps/issues/issues/12\n if (!launchParamsFromStorage) {\n return false;\n }\n\n return launchParamsFromStorage.initData?.hash === currentLaunchParams.initData?.hash;\n}\n\n/**\n * Represents actual init function.\n * @param options - init options.\n */\nasync function actualInit(options: InitOptions = {}): Promise<InitResult> {\n const {\n checkCompat = true,\n cssVars = false,\n acceptScrollbarStyle = true,\n acceptCustomStyles = acceptScrollbarStyle,\n targetOrigin,\n debug = false,\n launchParams: optionsLaunchParams = retrieveLaunchParams(),\n } = options;\n\n // Set global settings.\n if (debug) {\n setDebug(debug);\n }\n\n if (typeof targetOrigin === 'string') {\n setTargetOrigin(targetOrigin);\n }\n\n // Get Web App launch params and save them to session storage, so they will be accessible from\n // anywhere.\n const launchParamsFromStorage = retrieveFromStorage();\n const launchParams = optionsLaunchParams instanceof URLSearchParams || typeof optionsLaunchParams === 'string'\n ? parseLaunchParams(optionsLaunchParams)\n : optionsLaunchParams;\n\n saveLaunchParamsToStorage(launchParams);\n\n // Compute if page was reloaded. We will need it to decide if SDK components should be restored\n // or created from scratch.\n const isPageReload = isNativePageReload()\n || computePageReload(launchParamsFromStorage, launchParams);\n\n const {\n initData,\n initDataRaw,\n version,\n platform,\n themeParams: lpThemeParams,\n } = launchParams;\n const {\n backgroundColor = '#ffffff',\n buttonColor = '#000000',\n buttonTextColor = '#ffffff',\n } = lpThemeParams;\n\n const createRequestId = createRequestIdGenerator();\n const postEvent = createPostEvent(checkCompat, version);\n const themeParams = createThemeParams(lpThemeParams);\n const webApp = createWebApp(\n isPageReload,\n backgroundColor,\n version,\n platform,\n createRequestId,\n postEvent,\n );\n\n const {\n themeParams: createThemeParamsCSSVars,\n viewport: createViewportCSSVars,\n webApp: createWebAppCSSVars,\n } = parseCSSVarsOptions(cssVars);\n\n if (createWebAppCSSVars) {\n bindWebAppVariables(webApp, themeParams);\n }\n\n if (createThemeParamsCSSVars) {\n bindThemeCSSVariables(themeParams);\n }\n\n const viewport = await createViewport(isPageReload, platform, postEvent);\n\n // Apply viewport CSS variables.\n if (createViewportCSSVars) {\n bindViewportCSSVariables(viewport);\n }\n\n // In case, we are currently in iframe, it is required to listen to\n // messages, coming from parent source to apply requested changes.\n // The only one case, when current application was placed into iframe is\n // web version of Telegram.\n if (acceptCustomStyles && isIframe()) {\n // Create special style element which is responsible for application\n // style controlled by external app.\n const styleElement = document.createElement('style');\n styleElement.id = 'telegram-custom-styles';\n document.head.appendChild(styleElement);\n\n // Listen to custom style changes.\n on('set_custom_style', (html) => {\n styleElement.innerHTML = html;\n });\n\n // Notify Telegram, iframe is ready. This will result in sending style\n // tag html from native application.\n postEvent('iframe_ready');\n }\n\n const result: InitResult = {\n backButton: createBackButton(isPageReload, version, postEvent),\n closingBehavior: createClosingBehavior(isPageReload, postEvent),\n cloudStorage: new CloudStorage(version, createRequestId, postEvent),\n haptic: new HapticFeedback(version, postEvent),\n mainButton: createMainButton(isPageReload, buttonColor, buttonTextColor, postEvent),\n popup: new Popup(version, postEvent),\n postEvent,\n qrScanner: new QRScanner(version, postEvent),\n themeParams,\n viewport,\n webApp,\n };\n\n // Init data could be missing in case, application was launched via InlineKeyboardButton.\n if (initData !== undefined) {\n const { authDate, hash, ...restInitData } = initData;\n result.initData = new InitData(authDate, hash, restInitData);\n result.initDataRaw = initDataRaw;\n }\n\n return result;\n}\n\n/**\n * Initializes all SDK components.\n * @param options - initialization options.\n */\nexport function init(options: InitOptions = {}): Promise<InitResult> {\n return withTimeout(actualInit(options), options.timeout || 1000);\n}\n","import { retrieveLaunchParams } from './launch-params.js';\n\n/**\n * Returns true in case, current environment is Telegram Web Apps.\n *\n * `isTWA` utilizes such function as `retrieveLaunchParams`, which attempts to retrieve\n * launch parameters from the current environment.\n * @see retrieveLaunchParams\n */\nexport function isTWA(): boolean {\n try {\n retrieveLaunchParams();\n return true;\n } catch (e) {\n return false;\n }\n}\n"],"names":["createSupportsFunc","version","schema","method","supports","createSupportsParamFunc","tmaMethod","param","State","state","ee","key","value","keyOrState","didChange","BackButton","isVisible","postEvent","defaultPostEvent","__publicField","EventEmitter","event","listener","on","off","visible","ClosingBehaviour","isConfirmationNeeded","stringArray","array","string","objectFromKeys","keys","acc","CloudStorage","createRequestId","params","options","result","error","request","json","HapticFeedback","style","type","InitData","authDate","hash","chat","canSendAfter","chatType","chatInstance","user","queryId","receiver","startParam","MainButton","backgroundColor","isEnabled","isProgressVisible","text","textColor","preparePopupParams","message","title","buttons","preparedButtons","b","id","Popup","buttonId","QRScanner","prepareThemeParams","buttonTextColor","buttonColor","hintColor","linkColor","secondaryBackgroundColor","ThemeParams","timeout","restOptions","parse","themeParams","tp","isColorDark","truncate","Viewport","height","width","stableHeight","isExpanded","isStateStable","rest","viewport","formattedHeight","formatURL","url","anchor","WebApp","headerColor","currentVersion","currentPlatform","compareVersions","tryInstantView","formattedUrl","hostname","pathname","search","match","slug","eventSlug","data","status","size","color","isRGB","MethodNotSupportedError","ParameterUnsupportedError","setVariable","name","setColorVariable","setSizeVariable","createThemeVariables","createWebAppVariables","webApp","webAppBackgroundColor","bindThemeCSSVariables","actualize","bindWebAppVariables","bindViewportCSSVariables","setHeight","setStableHeight","parseCSSVarsOptions","option","formatKey","saveStorageValue","getStorageValue","createBackButton","isPageReload","component","createClosingBehavior","createMainButton","stateBackgroundColor","stateTextColor","saveState","createPostEvent","checkCompat","isRecord","detectSupportParams","createRequestIdGenerator","requestId","createThemeParams","createViewport","platform","createWebApp","retrieveLaunchParams","fromStorage","retrieveFromStorage","isNativePageReload","entry","computePageReload","launchParamsFromStorage","currentLaunchParams","_a","_b","actualInit","cssVars","acceptScrollbarStyle","acceptCustomStyles","targetOrigin","debug","optionsLaunchParams","setDebug","setTargetOrigin","launchParams","parseLaunchParams","saveLaunchParamsToStorage","initData","initDataRaw","lpThemeParams","createThemeParamsCSSVars","createViewportCSSVars","createWebAppCSSVars","isIframe","styleElement","html","restInitData","init","withTimeout","isTWA"],"mappings":";;;;;;;;;;AAoBgB,SAAAA,EACdC,GACAC,GACiB;AACjB,SAAO,CAACC,MAAWC,EAASF,EAAOC,CAAM,GAAGF,CAAO;AACrD;AASgB,SAAAI,GACdJ,GACAC,GACiB;AACjB,SAAO,CAACC,MAAW;AACjB,UAAM,CAACG,GAAWC,CAAK,IAAIL,EAAOC,CAAM;AAEjC,WAAAC,EAASE,GAAWC,GAAON,CAAO;AAAA,EAAA;AAE7C;ACpCO,MAAMO,EAAwB;AAAA,EACnC,YAA6BC,GAA2BC,GAAmC;AAA9D,SAAA,QAAAD,GAA2B,KAAA,KAAAC;AAAA,EACxD;AAAA,EAEQ,KAAKC,GAAaC,GAAiB;AACzC,IAAI,KAAK,MACN,KAAK,GAAW,KAAKD,GAAKC,CAAK;AAAA,EAEpC;AAAA,EAEQ,YAAqCD,GAAQC,GAAsB;AACzE,WAAI,KAAK,MAAMD,CAAG,MAAMC,IACf,MAGJ,KAAA,MAAMD,CAAG,IAAIC,GAClB,KAAK,KAAK,GAAGD,CAAG,WAAWC,CAAK,GAEzB;AAAA,EACT;AAAA,EAIA,IAAIC,GAAiBD,GAAmB;AACtC,QAAIE,IAAY;AAEZ,QAAA,OAAOD,KAAe;AACZ,MAAAC,IAAA,KAAK,YAAYD,GAAmBD,CAAK;AAAA;AAGrD,iBAAWD,KAAOE;AAChB,QAAI,KAAK,YAAYF,GAAYE,EAAWF,CAAG,CAAC,MAClCG,IAAA;AAKlB,IAAIA,KACF,KAAK,KAAK,SAAS;AAAA,EAEvB;AAAA,EAEA,IAA6B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,IAAyB;AACnE,SAAOuJ,GAAYvB,GAAWhI,CAAO,GAAGA,EAAQ,WAAW,GAAI;AACjE;ACrMO,SAASwJ,KAAiB;AAC3B,MAAA;AACmB,WAAAlC,KACd;AAAA,UACG;AACH,WAAA;AAAA,EACT;AACF;"}
|
package/dist/index.umd.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@tma.js/launch-params"),require("@tma.js/event-emitter"),require("@tma.js/bridge"),require("@tma.js/parsing"),require("@tma.js/theme-params"),require("@tma.js/colors"),require("@tma.js/utils")):typeof define=="function"&&define.amd?define(["exports","@tma.js/launch-params","@tma.js/event-emitter","@tma.js/bridge","@tma.js/parsing","@tma.js/theme-params","@tma.js/colors","@tma.js/utils"],d):(a=typeof globalThis<"u"?globalThis:a||self,d((a["@tma"]=a["@tma"]||{},a["@tma"]["js/sdk"]={}),a["@tma"]["js/launch-params"],a["@tma"]["js/event-emitter"],a["@tma"]["js/bridge"],a["@tma"]["js/parsing"],a["@tma"]["js/theme-params"],a["@tma"]["js/colors"],a["@tma"]["js/utils"]))})(this,function(a,d,_,c,P,H,T,j){"use strict";var At=Object.defineProperty;var It=(a,d,_)=>d in a?At(a,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):a[d]=_;var i=(a,d,_)=>(It(a,typeof d!="symbol"?d+"":d,_),_);function v(s,t){return e=>c.supports(t[e],s)}function ot(s,t){return e=>{const[n,o]=t[e];return c.supports(n,o,s)}}class b{constructor(t,e){this.state=t,this.ee=e}emit(t,e){this.ee&&this.ee.emit(t,e)}internalSet(t,e){return this.state[t]===e?!1:(this.state[t]=e,this.emit(`${t}Changed`,e),!0)}set(t,e){let n=!1;if(typeof t=="string")n=this.internalSet(t,e);else for(const o in t)this.internalSet(o,t[o])&&(n=!0);n&&this.emit("changed")}get(t){return this.state[t]}}class D{constructor(t,e,n=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return c.on("back_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return c.off("back_button_pressed",e);this.ee.off(t,e)});i(this,"supports");this.postEvent=n,this.state=new b({isVisible:t},this.ee),this.supports=v(e,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(t){this.state.set("isVisible",t),this.postEvent("web_app_setup_back_button",{is_visible:t})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}class L{constructor(t,e=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=e,this.state=new b({isConfirmationNeeded:t},this.ee)}set isConfirmationNeeded(t){this.state.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const rt=P.array().of(P.string());function N(s,t){return s.reduce((e,n)=>(e[n]=t,e),{})}class M{constructor(t,e,n=c.postEvent){i(this,"supports");this.createRequestId=e,this.postEvent=n,this.supports=v(t,{deleteKeys:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",getValues:"web_app_invoke_custom_method",saveValue:"web_app_invoke_custom_method"})}async invokeCustomMethod(t,e,n={}){const{result:o,error:r}=await c.request("web_app_invoke_custom_method",{method:t,params:e,req_id:this.createRequestId()},"custom_method_invoked",{...n,postEvent:this.postEvent});if(r)throw new Error(typeof r=="string"?r:`Unknown error: ${JSON.stringify(r)}`);return o}async deleteKeys(t,e){t.length!==0&&await this.invokeCustomMethod("deleteStorageValues",{keys:t},e)}async getKeys(t){const e=await this.invokeCustomMethod("getStorageKeys",{},t);return rt.parse(e)}async getValues(t,e){if(t.length===0)return N(t,"");const n=P.json(N(t,P.string())),o=await this.invokeCustomMethod("getStorageValues",{keys:t},e);return n.parse(o)}async saveValue(t,e,n){await this.invokeCustomMethod("saveStorageValue",{key:t,value:e},n)}}class W{constructor(t,e=c.postEvent){i(this,"supports");this.postEvent=e,this.supports=v(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:t})}notificationOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:t})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}class z{constructor(t,e,n={}){i(this,"state");const{chat:o=null,canSendAfter:r=null,chatType:h=null,chatInstance:u=null,user:l=null,queryId:g=null,receiver:p=null,startParam:f=null}=n;this.state=new b({authDate:t,canSendAfter:r===null?null:new Date(t.getTime()+r*1e3),chat:o,chatType:h,chatInstance:u,user:l,queryId:g,receiver:p,startParam:f,hash:e})}get authDate(){return this.state.get("authDate")}get canSendAfter(){return this.state.get("canSendAfter")}get chat(){return this.state.get("chat")}get hash(){return this.state.get("hash")}get queryId(){return this.state.get("queryId")}get receiver(){return this.state.get("receiver")}get startParam(){return this.state.get("startParam")}get user(){return this.state.get("user")}}class U{constructor(t,e,n,o,r,h,u=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return c.on("main_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return c.off("main_button_pressed",e);this.ee.off(t,e)});this.postEvent=u,this.state=new b({backgroundColor:t,isEnabled:e,isVisible:n,isProgressVisible:o,text:r,textColor:h},this.ee)}set isEnabled(t){this.state.set("isEnabled",t),this.commit()}get isEnabled(){return this.state.get("isEnabled")}set isProgressVisible(t){this.state.set("isProgressVisible",t),this.commit()}get isProgressVisible(){return this.state.get("isProgressVisible")}set isVisible(t){this.state.set("isVisible",t),this.commit()}get isVisible(){return this.state.get("isVisible")}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isProgressVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideProgress(){return this.isProgressVisible=!1,this}show(){return this.isVisible=!0,this}showProgress(){return this.isProgressVisible=!0,this}setText(t){return this.state.set("text",t),this.commit(),this}setTextColor(t){return this.state.set("textColor",t),this.commit(),this}setBackgroundColor(t){return this.state.set("backgroundColor",t),this.commit(),this}}function it(s){const t=s.message.trim(),e=(s.title||"").trim(),n=s.buttons||[];let o;if(e.length>64)throw new Error(`Title has incorrect size: ${e.length}`);if(t.length===0||t.length>256)throw new Error(`Message has incorrect size: ${t.length}`);if(n.length>3)throw new Error(`Buttons have incorrect size: ${n.length}`);return n.length===0?o=[{type:"close",id:""}]:o=n.map(r=>{const{id:h=""}=r;if(h.length>64)throw new Error(`Button ID has incorrect size: ${h}`);if(r.type===void 0||r.type==="default"||r.type==="destructive"){const u=r.text.trim();if(u.length===0||u.length>64){const l=r.type||"default";throw new Error(`Button text with type "${l}" has incorrect size: ${r.text.length}`)}return{...r,text:u,id:h}}return{...r,id:h}}),{title:e,message:t,buttons:o}}class F{constructor(t,e=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new b({isOpened:!1},this.ee),this.supports=v(t,{open:"web_app_open_popup"})}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.state.set("isOpened",!0);try{const{button_id:e=null}=await c.request("web_app_open_popup",it(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class K{constructor(t,e=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new b({isOpened:!1},this.ee),this.supports=v(t,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.state.set("isOpened",t)}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const e=await c.request("web_app_open_scan_qr_popup",{text:t},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof e=="object"&&typeof e.data=="string"?e.data:null}finally{this.isOpened=!1}}}function J(s){const{backgroundColor:t=null,buttonTextColor:e=null,buttonColor:n=null,hintColor:o=null,linkColor:r=null,textColor:h=null,secondaryBackgroundColor:u=null}=s;return{backgroundColor:t,buttonTextColor:e,buttonColor:n,hintColor:o,linkColor:r,textColor:h,secondaryBackgroundColor:u}}class y{constructor(t){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.state=new b(J(t),this.ee)}static async request(t={}){const{timeout:e=1e3,...n}=t,o=await c.request("web_app_request_theme","theme_changed",{...n,timeout:e});return H.parse(o.theme_params)}static sync(t){c.on("theme_changed",e=>{t.state.set(J(H.parse(e.theme_params)))})}static async synced(t){const e=await this.request(t),n=new y(e);return this.sync(n),n}get backgroundColor(){return this.state.get("backgroundColor")}get buttonColor(){return this.state.get("buttonColor")}get buttonTextColor(){return this.state.get("buttonTextColor")}get hintColor(){return this.state.get("hintColor")}get isDark(){return this.backgroundColor===null||T.isColorDark(this.backgroundColor)}get linkColor(){return this.state.get("linkColor")}get secondaryBackgroundColor(){return this.state.get("secondaryBackgroundColor")}get textColor(){return this.state.get("textColor")}}function k(s){return s<0?0:s}class E{constructor(t,e,n,o,r=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=r,this.state=new b({height:k(t),isExpanded:o,stableHeight:k(n),width:k(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...n}=t,{is_expanded:o,is_state_stable:r,...h}=await c.request("web_app_request_viewport","viewport_changed",{...n,timeout:e});return{...h,isExpanded:o,isStateStable:r}}static sync(t){c.on("viewport_changed",e=>{const{height:n,width:o,is_expanded:r,is_state_stable:h}=e,u=k(n);t.state.set({height:u,isExpanded:r,width:k(o),stableHeight:h?u:void 0})})}static async synced(t={}){const{height:e,isExpanded:n,width:o}=await this.request(t),r=new E(e,o,e,n,t.postEvent);return this.sync(r),r}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.state.set("isExpanded",!0),this.postEvent("web_app_expand")}get isStable(){return this.stableHeight===this.height}}function x(s){const t=document.createElement("a");if(t.href=s,t.protocol!=="http:"&&t.protocol!=="https:")throw Error(`URL protocol is not supported by OS, or link has not allowed protocol: ${t.protocol}`);return t.href}class Q{constructor(t,e,n,o,r,h=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");i(this,"supportsParam");this.currentVersion=n,this.currentPlatform=o,this.createRequestId=r,this.postEvent=h,this.state=new b({backgroundColor:e,headerColor:t},this.ee),this.supports=v(n,{openInvoice:"web_app_open_invoice",readTextFromClipboard:"web_app_read_text_from_clipboard",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color",requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access"}),this.supportsParam=ot(n,{"setHeaderColor.color":["web_app_set_header_color","color"],"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}get backgroundColor(){return this.state.get("backgroundColor")}get colorScheme(){return T.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return j.compareVersions(t,this.version)>=0}openLink(t,e){const n=x(t);if(!c.supports("web_app_open_link",this.version)){window.open(n,"_blank");return}return this.postEvent("web_app_open_link",{url:n,...typeof e=="boolean"?{try_instant_view:e}:{}})}openTelegramLink(t){const{hostname:e,pathname:n,search:o}=new URL(x(t));if(e!=="t.me")throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);if(!c.supports("web_app_open_tg_link",this.version)){window.location.href=t;return}return this.postEvent("web_app_open_tg_link",{path_full:n+o})}async openInvoice(t){const{hostname:e,pathname:n}=new URL(x(t));if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const o=n.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(o===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,r]=o;return(await c.request("web_app_open_invoice",{slug:r},"invoice_closed",{postEvent:this.postEvent,capture:({slug:u})=>r===u})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:t=null}=await c.request("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent});return t}async requestPhoneAccess(){const{status:t}=await c.request("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return t}async requestWriteAccess(){const{status:t}=await c.request("web_app_request_write_access","write_access_requested",{postEvent:this.postEvent});return t}sendData(t){const{size:e}=new Blob([t]);if(e===0||e>4096)throw new Error(`Passed data has incorrect size: ${e}`);this.postEvent("web_app_data_send",{data:t})}setHeaderColor(t){this.postEvent("web_app_set_header_color",T.isRGB(t)?{color:t}:{color_key:t}),this.state.set("headerColor",t)}setBackgroundColor(t){this.postEvent("web_app_set_background_color",{color:t}),this.state.set("backgroundColor",t)}get version(){return this.currentVersion}}class B extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Web Apps version ${e}.`),Object.setPrototypeOf(this,B.prototype)}}class O extends Error{constructor(t,e,n){super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${n}.`),Object.setPrototypeOf(this,O.prototype)}}function G(s,t){document.documentElement.style.setProperty(s,t)}function w(s,t){t!==null&&G(s,t)}function Z(s,t){G(s,`${t}px`)}function at(s){const{backgroundColor:t,buttonTextColor:e,secondaryBackgroundColor:n,hintColor:o,buttonColor:r,linkColor:h,textColor:u}=s;w("--tg-theme-bg-color",t),w("--tg-theme-button-color",r),w("--tg-theme-button-text-color",e),w("--tg-theme-hint-color",o),w("--tg-theme-link-color",h),w("--tg-theme-secondary-bg-color",n),w("--tg-theme-text-color",u)}function ct(s,t){const{backgroundColor:e,secondaryBackgroundColor:n}=t,{backgroundColor:o,headerColor:r}=s;w("--tg-bg-color",o),w("--tg-header-color",r==="bg_color"?e:n)}function ht(s){const t=()=>at(s);s.on("changed",t),t()}function ut(s,t){const e=()=>ct(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function pt(s){const t=()=>{Z("--tg-viewport-height",s.height)},e=()=>{Z("--tg-viewport-stable-height",s.stableHeight)};s.on("heightChanged",t),s.on("stableHeightChanged",e),t(),e()}function lt(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function X(s){return`telegram-mini-apps-${s}`}function S(s,t){sessionStorage.setItem(X(s),JSON.stringify(t))}function V(s){const t=sessionStorage.getItem(X(s));return t?JSON.parse(t):null}function dt(s,t,e){const{isVisible:n=!1}=s?V("back-button")||{}:{},o=new D(n,t,e);return o.on("isVisibleChanged",()=>{S("back-button",{isVisible:o.isVisible})}),o}function gt(s,t){const{isConfirmationNeeded:e=!1}=s?V("closing-behavior")||{}:{},n=new L(e,t);return n.on("isConfirmationNeededChanged",()=>S("closing-behavior",{isConfirmationNeeded:n.isConfirmationNeeded})),n}function _t(s,t,e,n){const{backgroundColor:o=t,isEnabled:r=!1,isVisible:h=!1,isProgressVisible:u=!1,textColor:l=e,text:g=""}=s?V("main-button")||{}:{},p=new U(o,r,h,u,g,l,n),f=()=>S("main-button",{backgroundColor:p.backgroundColor,isEnabled:p.isEnabled,isVisible:p.isVisible,isProgressVisible:p.isProgressVisible,text:p.text,textColor:p.textColor});return p.on("backgroundColorChanged",f),p.on("isEnabledChanged",f),p.on("isVisibleChanged",f),p.on("isProgressVisibleChanged",f),p.on("textColorChanged",f),p.on("textChanged",f),p}function ft(s,t){return s?(e,n)=>{if(!c.supports(e,t))throw new B(e,t);return j.isRecord(n)&&c.detectSupportParams(e,n).forEach(o=>{if(!c.supports(e,o,t))throw new O(e,o,t)}),c.postEvent(e,n)}:c.postEvent}function mt(){let s=0;return()=>(s+=1,s.toString())}function bt(s){const t=new y(s);return y.sync(t),t}async function wt(s,t,e){const{height:n=window.innerHeight,stableHeight:o=window.innerHeight,width:r=window.innerWidth,isExpanded:h=!1}=s?V("viewport")||{}:{},l=t==="macos"||t==="web"?(()=>{const p=new E(n,r,o,h,e);return E.sync(p),p})():await E.synced({postEvent:e}),g=()=>S("viewport",{height:l.height,isExpanded:l.isExpanded,stableHeight:l.stableHeight,width:l.width});return l.on("heightChanged",g),l.on("isExpandedChanged",g),l.on("stableHeightChanged",g),l.on("widthChanged",g),l}function Ct(s,t,e,n,o,r){const{backgroundColor:h=t,headerColor:u="bg_color"}=s?V("web-app")||{}:{},l=new Q(u,h,e,n,o,r),g=()=>S("web-app",{backgroundColor:l.backgroundColor,headerColor:l.headerColor});return l.on("backgroundColorChanged",g),l.on("headerColorChanged",g),l}function A(){let s;try{return d.parse(window.location.hash.slice(1))}catch(e){s=e}const t=d.retrieveFromStorage();if(t)return t;throw new Error("Unable to extract launch params",{cause:s})}function vt(){return window.performance.getEntriesByType("navigation").some(s=>s.type==="reload")}function Et(s,t){var e,n;return s?((e=s.initData)==null?void 0:e.hash)===((n=t.initData)==null?void 0:n.hash):!1}async function yt(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:n=!0,acceptCustomStyles:o=n,targetOrigin:r,debug:h=!1,launchParams:u=A()}=s;h&&c.setDebug(h),typeof r=="string"&&c.setTargetOrigin(r);const l=d.retrieveFromStorage(),g=u instanceof URLSearchParams||typeof u=="string"?d.parse(u):u;d.saveToStorage(g);const p=vt()||Et(l,g),{initData:f,initDataRaw:Vt,version:C,platform:Y,themeParams:tt}=g,{backgroundColor:qt="#ffffff",buttonColor:Pt="#000000",buttonTextColor:xt="#ffffff"}=tt,et=mt(),m=ft(t,C),I=bt(tt),st=Ct(p,qt,C,Y,et,m),{themeParams:Bt,viewport:Ot,webApp:Tt}=lt(e);Tt&&ut(st,I),Bt&&ht(I);const nt=await wt(p,Y,m);if(Ot&&pt(nt),o&&c.isIframe()){const q=document.createElement("style");q.id="telegram-custom-styles",document.head.appendChild(q),c.on("set_custom_style",$=>{q.innerHTML=$}),m("iframe_ready")}const R={backButton:dt(p,C,m),closingBehavior:gt(p,m),cloudStorage:new M(C,et,m),haptic:new W(C,m),mainButton:_t(p,Pt,xt,m),popup:new F(C,m),postEvent:m,qrScanner:new K(C,m),themeParams:I,viewport:nt,webApp:st};if(f!==void 0){const{authDate:q,hash:$,...jt}=f;R.initData=new z(q,$,jt),R.initDataRaw=Vt}return R}function kt(s={}){return j.withTimeout(yt(s),s.timeout||1e3)}function St(){try{return A(),!0}catch{return!1}}a.BackButton=D,a.ClosingBehaviour=L,a.CloudStorage=M,a.HapticFeedback=W,a.InitData=z,a.MainButton=U,a.MethodNotSupportedError=B,a.ParameterUnsupportedError=O,a.Popup=F,a.QRScanner=K,a.ThemeParams=y,a.Viewport=E,a.WebApp=Q,a.formatURL=x,a.init=kt,a.isTWA=St,a.retrieveLaunchParams=A,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
-
//# sourceMappingURL=index.umd.cjs.map
|
package/dist/index.umd.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.cjs","sources":["../src/supports.ts","../src/state/State.ts","../src/components/BackButton/BackButton.ts","../src/components/ClosingBehaviour/ClosingBehaviour.ts","../src/components/CloudStorage/CloudStorage.ts","../src/components/HapticFeedback/HapticFeedback.ts","../src/components/InitData/InitData.ts","../src/components/MainButton/MainButton.ts","../src/components/Popup/utils.ts","../src/components/Popup/Popup.ts","../src/components/QRScanner/QRScanner.ts","../src/components/ThemeParams/ThemeParams.ts","../src/components/Viewport/Viewport.ts","../src/url.ts","../src/components/WebApp/WebApp.ts","../src/errors/MethodNotSupportedError.ts","../src/errors/ParameterNotSupportedError.ts","../src/init/css.ts","../src/storage.ts","../src/init/creators/createBackButton.ts","../src/init/creators/createClosingBehavior.ts","../src/init/creators/createMainButton.ts","../src/init/creators/createPostEvent.ts","../src/init/creators/createRequestIdGenerator.ts","../src/init/creators/createThemeParams.ts","../src/init/creators/createViewport.ts","../src/init/creators/createWebApp.ts","../src/launch-params.ts","../src/init/init.ts","../src/env.ts"],"sourcesContent":["import type { Version } from '@tma.js/utils';\nimport {\n supports,\n type MethodName,\n type HasCheckSupportMethodName,\n type HasCheckSupportMethodParam,\n} from '@tma.js/bridge';\n\nexport type SupportsFunc<M extends string> = (method: M) => boolean;\n\ntype HasCheckSupportMethodTuple = {\n [M in HasCheckSupportMethodName]: [M, HasCheckSupportMethodParam<M>]\n}[HasCheckSupportMethodName];\n\n/**\n * Returns function, which accepts predefined method name and checks if it is supported\n * via passed schema and version.\n * @param schema - object which contains methods names and TWA method as a dependency.\n * @param version - platform version.\n */\nexport function createSupportsFunc<M extends string>(\n version: Version,\n schema: Record<M, MethodName>,\n): SupportsFunc<M> {\n return (method) => supports(schema[method], version);\n}\n\n/**\n * Returns function, which accepts predefined method name and checks if it is supported\n * via passed schema and version.\n * @param schema - object which contains methods names and TWA methods with specified parameter\n * as a dependency.\n * @param version - platform version.\n */\nexport function createSupportsParamFunc<P extends string>(\n version: Version,\n schema: Record<P, HasCheckSupportMethodTuple>,\n): SupportsFunc<P> {\n return (method) => {\n const [tmaMethod, param] = schema[method];\n\n return supports(tmaMethod, param, version);\n };\n}\n","import type { EventEmitter } from '@tma.js/event-emitter';\n\nimport type { StateEvents, StringKeys } from './types.js';\n\n/**\n * Represents state which is observable via passed EventEmitter.\n */\nexport class State<S extends object> {\n constructor(private readonly state: S, private readonly ee?: EventEmitter<StateEvents<S>>) {\n }\n\n private emit(key: string, value?: unknown) {\n if (this.ee) {\n (this.ee as any).emit(key, value);\n }\n }\n\n private internalSet<K extends StringKeys<S>>(key: K, value: S[K]): boolean {\n if (this.state[key] === value) {\n return false;\n }\n\n this.state[key] = value;\n this.emit(`${key}Changed`, value);\n\n return true;\n }\n\n set<K extends StringKeys<S>>(key: K, value: S[K]): void;\n set(state: Partial<S>): void;\n set(keyOrState: any, value?: any): void {\n let didChange = false;\n\n if (typeof keyOrState === 'string') {\n didChange = this.internalSet(keyOrState as any, value);\n } else {\n // eslint-disable-next-line\n for (const key in keyOrState) {\n if (this.internalSet(key as any, keyOrState[key])) {\n didChange = true;\n }\n }\n }\n\n if (didChange) {\n this.emit('changed');\n }\n }\n\n get<K extends StringKeys<S>>(key: K): Readonly<S[K]> {\n return this.state[key];\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, off, postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { BackButtonEvents, BackButtonState, BackButtonEventListener } from './types.js';\n\n/**\n * Class which controls the back button displayed in the header\n * of the Web App in the Telegram interface. It is mostly used in case, when\n * you want to provide a way to go bach in routing history or \"rollback\" some\n * action.\n */\nexport class BackButton {\n private readonly ee = new EventEmitter<BackButtonEvents>();\n\n private readonly state: State<BackButtonState>;\n\n constructor(\n isVisible: boolean,\n version: Version,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({ isVisible }, this.ee);\n this.supports = createSupportsFunc(version, {\n show: 'web_app_setup_back_button',\n hide: 'web_app_setup_back_button',\n });\n }\n\n private set isVisible(visible: boolean) {\n this.state.set('isVisible', visible);\n this.postEvent('web_app_setup_back_button', { is_visible: visible });\n }\n\n /**\n * True if BackButton is currently visible.\n */\n get isVisible(): boolean {\n return this.state.get('isVisible');\n }\n\n /**\n * Hides the BackButton.\n */\n hide(): void {\n this.isVisible = false;\n }\n\n /**\n * Adds event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n on: typeof this.ee.on = (event, listener) => {\n if (event === 'click') {\n return on('back_button_pressed', listener as BackButtonEventListener<'click'>);\n }\n\n this.ee.on(event, listener);\n };\n\n /**\n * Removes event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n off: typeof this.ee.off = (event, listener) => {\n if (event === 'click') {\n return off('back_button_pressed', listener as BackButtonEventListener<'click'>);\n }\n\n this.ee.off(event, listener);\n };\n\n /**\n * Shows the BackButton.\n */\n show(): void {\n this.isVisible = true;\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'show' | 'hide'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport { State } from '../../state/index.js';\n\nimport type { ClosingBehaviourEvents, ClosingBehaviourState } from './types.js';\n\n/**\n * Component responsible for controlling current closing confirmation\n * status.\n */\nexport class ClosingBehaviour {\n private readonly ee = new EventEmitter<ClosingBehaviourEvents>();\n\n private readonly state: State<ClosingBehaviourState>;\n\n constructor(\n isConfirmationNeeded: boolean,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({ isConfirmationNeeded }, this.ee);\n }\n\n private set isConfirmationNeeded(value: boolean) {\n this.state.set('isConfirmationNeeded', value);\n this.postEvent('web_app_setup_closing_behavior', { need_confirmation: value });\n }\n\n /**\n * Returns true, if the confirmation dialog enabled while the user is trying\n * to close the Web App.\n */\n get isConfirmationNeeded(): boolean {\n return this.state.get('isConfirmationNeeded');\n }\n\n /**\n * Disables the confirmation dialog while the user is trying to close the\n * Web App.\n */\n disableConfirmation(): void {\n this.isConfirmationNeeded = false;\n }\n\n /**\n * Enables the confirmation dialog while the user is trying to close the\n * Web App.\n */\n enableConfirmation(): void {\n this.isConfirmationNeeded = true;\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n}\n","import {\n postEvent as defaultPostEvent,\n request,\n type RequestOptions,\n} from '@tma.js/bridge';\nimport { array, json, string } from '@tma.js/parsing';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\n\nimport type { CreateRequestIdFunc } from '../../types.js';\n\ntype WiredRequestOptions = Omit<RequestOptions, 'postEvent'>;\n\ninterface Methods {\n deleteStorageValues: { keys: string | string[] };\n getStorageValues: { keys: string | string[] };\n getStorageKeys: {};\n saveStorageValue: { key: string; value: string };\n}\n\nconst stringArray = array().of(string());\n\nfunction objectFromKeys<K extends string, V>(keys: K[], value: V): Record<K, V> {\n return keys.reduce<Record<K, V>>((acc, key) => {\n acc[key] = value;\n return acc;\n }, {} as Record<K, V>);\n}\n\nexport class CloudStorage {\n constructor(\n version: Version,\n private readonly createRequestId: CreateRequestIdFunc,\n private readonly postEvent = defaultPostEvent,\n ) {\n this.supports = createSupportsFunc(version, {\n deleteKeys: 'web_app_invoke_custom_method',\n getKeys: 'web_app_invoke_custom_method',\n getValues: 'web_app_invoke_custom_method',\n saveValue: 'web_app_invoke_custom_method',\n });\n }\n\n /**\n * Invokes custom method related to CloudStorage.\n * @param method - method name.\n * @param params - method parameters.\n * @param options - execution options.\n */\n private async invokeCustomMethod<M extends keyof Methods>(\n method: M,\n params: Methods[M],\n options: WiredRequestOptions = {},\n ): Promise<unknown> {\n const { result, error } = await request(\n 'web_app_invoke_custom_method',\n { method, params, req_id: this.createRequestId() },\n 'custom_method_invoked',\n { ...options, postEvent: this.postEvent },\n );\n\n if (error) {\n throw new Error(typeof error === 'string' ? error : `Unknown error: ${JSON.stringify(error)}`);\n }\n\n return result;\n }\n\n /**\n * Deletes specified keys from the CloudStorage.\n * @param keys - keys list.\n * @param options - request execution options.\n */\n async deleteKeys(keys: string[], options?: WiredRequestOptions): Promise<void> {\n if (keys.length === 0) {\n return;\n }\n\n await this.invokeCustomMethod('deleteStorageValues', { keys }, options);\n }\n\n /**\n * Returns list of all keys presented in CloudStorage.\n * @param options - request execution options.\n */\n async getKeys(options?: WiredRequestOptions): Promise<string[]> {\n const result = await this.invokeCustomMethod('getStorageKeys', {}, options);\n\n return stringArray.parse(result);\n }\n\n /**\n * Returns map, where key is one of the specified in keys argument, and value is according\n * storage value.\n * @param keys - keys list.\n * @param options - request execution options.\n */\n async getValues<K extends string>(\n keys: K[],\n options?: WiredRequestOptions,\n ): Promise<Record<K, string>> {\n if (keys.length === 0) {\n return objectFromKeys(keys, '');\n }\n\n const schema = json<Record<K, string>>(\n objectFromKeys(keys, string()) as any, // fixme\n );\n const result = await this.invokeCustomMethod('getStorageValues', { keys }, options);\n\n return schema.parse(result);\n }\n\n /**\n * Saves specified value by key.\n * @param key - storage key.\n * @param value - storage value.\n * @param options - request execution options.\n */\n async saveValue(key: string, value: string, options?: WiredRequestOptions): Promise<void> {\n await this.invokeCustomMethod('saveStorageValue', { key, value }, options);\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<\n | 'deleteKeys'\n | 'getKeys'\n | 'getValues'\n | 'saveValue'\n >;\n}\n","import type { Version } from '@tma.js/utils';\nimport {\n postEvent as defaultPostEvent,\n type PostEvent,\n type ImpactHapticFeedbackStyle,\n type NotificationHapticFeedbackType,\n} from '@tma.js/bridge';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\n\n/**\n * Class which controls haptic feedback. It allows calling different types of\n * haptic notifications which usually occur after user interaction with\n * application.\n */\nexport class HapticFeedback {\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.supports = createSupportsFunc(version, {\n impactOccurred: 'web_app_trigger_haptic_feedback',\n notificationOccurred: 'web_app_trigger_haptic_feedback',\n selectionChanged: 'web_app_trigger_haptic_feedback',\n });\n }\n\n /**\n * A method tells that an impact occurred. The Telegram app may play the\n * appropriate haptics based on style value passed.\n * @param style - impact style.\n */\n impactOccurred(style: ImpactHapticFeedbackStyle): void {\n this.postEvent('web_app_trigger_haptic_feedback', { type: 'impact', impact_style: style });\n }\n\n /**\n * A method tells that a task or action has succeeded, failed, or produced\n * a warning. The Telegram app may play the appropriate haptics based on\n * type value passed.\n * @param type - notification type.\n */\n notificationOccurred(type: NotificationHapticFeedbackType): void {\n this.postEvent('web_app_trigger_haptic_feedback', {\n type: 'notification',\n notification_type: type,\n });\n }\n\n /**\n * A method tells that the user has changed a selection. The Telegram app\n * may play the appropriate haptics.\n *\n * Do not use this feedback when the user makes or confirms a selection;\n * use it only when the selection changes.\n */\n selectionChanged(): void {\n this.postEvent('web_app_trigger_haptic_feedback', { type: 'selection_change' });\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'impactOccurred' | 'notificationOccurred' | 'selectionChanged'>;\n}\n","import type { HasUndefined, If } from '@tma.js/util-types';\nimport type {\n Chat,\n InitData as InitDataType,\n User,\n} from '@tma.js/init-data';\n\nimport { State } from '../../state/index.js';\n\ntype InitDataState = {\n [K in keyof InitDataType]-?: 'canSendAfter' extends K\n ? Date | null\n : If<\n HasUndefined<InitDataType[K]>,\n Exclude<InitDataType[K], undefined> | null,\n InitDataType[K]\n >;\n};\n\n/**\n * Class which is responsible for displaying Web Apps init data.\n */\nexport class InitData {\n private readonly state: State<InitDataState>;\n\n constructor(\n authDate: Date,\n hash: string,\n options: Omit<InitDataType, 'authDate' | 'hash'> = {},\n ) {\n const {\n chat = null,\n canSendAfter = null,\n chatType = null,\n chatInstance = null,\n user = null,\n queryId = null,\n receiver = null,\n startParam = null,\n } = options;\n this.state = new State({\n authDate,\n canSendAfter: canSendAfter === null\n ? null\n : new Date(authDate.getTime() + canSendAfter * 1000),\n chat,\n chatType,\n chatInstance,\n user,\n queryId,\n receiver,\n startParam,\n hash,\n });\n }\n\n /**\n * Init data generation date.\n */\n get authDate(): Date {\n return this.state.get('authDate');\n }\n\n /**\n * Date after which a message can be sent via the answerWebAppQuery\n * method.\n * @see https://core.telegram.org/bots/api#answerwebappquery\n */\n get canSendAfter(): Date | null {\n return this.state.get('canSendAfter');\n }\n\n /**\n * An object containing data about the chat where the bot was\n * launched via the attachment menu. Returned for supergroups, channels and\n * group chats – only for Web Apps launched via the attachment menu.\n */\n get chat(): Chat | null {\n return this.state.get('chat');\n }\n\n /**\n * A hash of all passed parameters, which the bot server can use to\n * check their validity.\n * @see https://core.telegram.org/bots/webapps#validating-data-received-via-the-web-app\n */\n get hash(): string {\n return this.state.get('hash');\n }\n\n /**\n * A unique identifier for the Web App session, required for sending\n * messages via the `answerWebAppQuery` method.\n * @see https://core.telegram.org/bots/api#answerwebappquery\n */\n get queryId(): string | null {\n return this.state.get('queryId');\n }\n\n /**\n * An object containing data about the chat partner of the current\n * user in the chat where the bot was launched via the attachment menu.\n * Returned only for private chats and only for Web Apps launched\n * via the attachment menu.\n */\n get receiver(): User | null {\n return this.state.get('receiver');\n }\n\n /**\n * The value of the `startattach` parameter, passed via link. Only\n * returned for Web Apps when launched from the attachment menu via link.\n */\n get startParam(): string | null {\n return this.state.get('startParam');\n }\n\n /**\n * An object containing data about the current user.\n */\n get user(): User | null {\n return this.state.get('user');\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, off, postEvent as defaultPostEvent, type PostEvent } from '@tma.js/bridge';\n\nimport type { RGB } from '@tma.js/colors';\n\nimport { State } from '../../state/index.js';\n\nimport type { MainButtonEventListener, MainButtonEvents, MainButtonState } from './types.js';\n\n/**\n * Controls the main button, which is displayed at the bottom\n * of the Web App in the Telegram interface.\n */\nexport class MainButton {\n private readonly ee = new EventEmitter<MainButtonEvents>();\n\n private readonly state: State<MainButtonState>;\n\n constructor(\n backgroundColor: RGB,\n isEnabled: boolean,\n isVisible: boolean,\n isProgressVisible: boolean,\n text: string,\n textColor: RGB,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n backgroundColor,\n isEnabled,\n isVisible,\n isProgressVisible,\n text,\n textColor,\n }, this.ee);\n }\n\n private set isEnabled(value: boolean) {\n this.state.set('isEnabled', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton is currently enabled.\n */\n get isEnabled(): boolean {\n return this.state.get('isEnabled');\n }\n\n private set isProgressVisible(value: boolean) {\n this.state.set('isProgressVisible', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton loading progress is currently visible.\n */\n get isProgressVisible(): boolean {\n return this.state.get('isProgressVisible');\n }\n\n private set isVisible(value: boolean) {\n this.state.set('isVisible', value);\n this.commit();\n }\n\n /**\n * Returns true in case, MainButton is currently visible.\n */\n get isVisible(): boolean {\n return this.state.get('isVisible');\n }\n\n /**\n * Sends current local button state to Telegram application.\n */\n private commit(): void {\n // We should not commit changes until payload is correct. We could\n // have some invalid values in case, button instance was created\n // with empty values. Otherwise, an unexpected behaviour could be received.\n if (this.text === '') {\n return;\n }\n\n this.postEvent('web_app_setup_main_button', {\n is_visible: this.isVisible,\n is_active: this.isEnabled,\n is_progress_visible: this.isProgressVisible,\n text: this.text,\n color: this.backgroundColor,\n text_color: this.textColor,\n });\n }\n\n /**\n * Returns current main button background color.\n */\n get backgroundColor(): RGB {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns current main button text.\n */\n get text(): string {\n return this.state.get('text');\n }\n\n /**\n * Returns current main button text color.\n */\n get textColor(): RGB {\n return this.state.get('textColor');\n }\n\n /**\n * Disables button. Returns current button instance for chaining.\n */\n disable(): this {\n // FIXME: This method does not work on Android. Event \"main_button_pressed\"\n // keeps getting received even in case, button is disabled.\n // Issue: https://github.com/Telegram-Mini-Apps/documentation/issues/1\n this.isEnabled = false;\n return this;\n }\n\n /**\n * Enables button. Returns current button instance for chaining.\n */\n enable(): this {\n this.isEnabled = true;\n return this;\n }\n\n /**\n * Hides button. Returns current button instance for chaining.\n */\n hide(): this {\n this.isVisible = false;\n return this;\n }\n\n /**\n * Hides button progress. Returns current button instance for chaining.\n */\n hideProgress(): this {\n this.isProgressVisible = false;\n return this;\n }\n\n /**\n * Adds new event listener.\n * FIXME: Event 'main_button_pressed' is still being received on Android\n * even if the main button is disabled.\n * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3\n * @param event - event name.\n * @param listener - event listener.\n */\n on: typeof this.ee.on = (event, listener) => {\n if (event === 'click') {\n return on('main_button_pressed', listener as MainButtonEventListener<'click'>);\n }\n this.ee.on(event, listener);\n };\n\n /**\n * Removes event listener.\n * @param event - event name.\n * @param listener - event listener.\n */\n off: typeof this.ee.off = (event, listener) => {\n if (event === 'click') {\n return off('main_button_pressed', listener as MainButtonEventListener<'click'>);\n }\n this.ee.off(event, listener);\n };\n\n /**\n * Shows the button. Note that opening the Web App from the attachment\n * menu hides the main button until the user interacts with the Web App\n * interface.\n *\n * Returns current button instance for chaining.\n */\n show(): this {\n this.isVisible = true;\n return this;\n }\n\n /**\n * A method to show a loading indicator on the button.\n * It is recommended to display loading progress if the action tied to the\n * button may take a long time.\n *\n * Returns current button instance for chaining.\n */\n showProgress(): this {\n this.isProgressVisible = true;\n return this;\n }\n\n /**\n * Sets new main button text. Returns current button instance for chaining.\n * Minimal length for text is 1 symbol, and maximum is 64 symbols.\n *\n * Returns current button instance for chaining.\n * @param value - new text.\n */\n setText(value: string): this {\n this.state.set('text', value);\n this.commit();\n\n return this;\n }\n\n /**\n * Sets new main button text color. Returns current button instance for\n * chaining.\n *\n * Returns current button instance for chaining.\n * @param value - new text color.\n */\n setTextColor(value: RGB): this {\n this.state.set('textColor', value);\n this.commit();\n\n return this;\n }\n\n /**\n * Updates current button color. Returns current button instance for\n * chaining.\n *\n * Returns current button instance for chaining.\n * @param value - color to set.\n */\n setBackgroundColor(value: RGB): this {\n this.state.set('backgroundColor', value);\n this.commit();\n\n return this;\n }\n}\n","import type { PopupButton, PopupParams as BridgePopupParams } from '@tma.js/bridge';\n\nimport type { PopupParams } from './types.js';\n\n/**\n * Prepares popup parameters before sending them to native app.\n * @param params - popup parameters.\n */\nexport function preparePopupParams(params: PopupParams): BridgePopupParams {\n const message = params.message.trim();\n const title = (params.title || '').trim();\n const buttons = params.buttons || [];\n let preparedButtons: PopupButton[];\n\n // Check title.\n if (title.length > 64) {\n throw new Error(`Title has incorrect size: ${title.length}`);\n }\n\n // Check message.\n if (message.length === 0 || message.length > 256) {\n throw new Error(`Message has incorrect size: ${message.length}`);\n }\n\n // Check buttons.\n if (buttons.length > 3) {\n throw new Error(`Buttons have incorrect size: ${buttons.length}`);\n }\n\n // Append button in case, there are no buttons passed.\n if (buttons.length === 0) {\n preparedButtons = [{ type: 'close', id: '' }];\n } else {\n // Otherwise, check all the buttons.\n preparedButtons = buttons.map((b) => {\n const { id = '' } = b;\n\n // Check button ID.\n if (id.length > 64) {\n throw new Error(`Button ID has incorrect size: ${id}`);\n }\n\n if (b.type === undefined || b.type === 'default' || b.type === 'destructive') {\n const text = b.text.trim();\n\n if (text.length === 0 || text.length > 64) {\n const type = b.type || 'default';\n\n throw new Error(`Button text with type \"${type}\" has incorrect size: ${b.text.length}`);\n }\n\n return { ...b, text, id };\n }\n\n return { ...b, id };\n });\n }\n return { title, message, buttons: preparedButtons };\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, request, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { preparePopupParams } from './utils.js';\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { PopupParams, PopupEvents, PopupState } from './types.js';\n\n/**\n * Controls currently displayed application popup. It allows developers to\n * open new custom popups and detect popup-connected events.\n */\nexport class Popup {\n private readonly ee = new EventEmitter<PopupEvents>();\n\n private readonly state: State<PopupState>;\n\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.state = new State({ isOpened: false }, this.ee);\n this.supports = createSupportsFunc(version, { open: 'web_app_open_popup' });\n }\n\n /**\n * Shows whether popup is currently opened.\n */\n get isOpened(): boolean {\n return this.state.get('isOpened');\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n\n /**\n * A method that shows a native popup described by the `params` argument.\n * Promise will be resolved when popup is closed. Resolved value will have\n * an identifier of pressed button.\n *\n * In case, user clicked outside the popup or clicked top right popup close\n * button, null will be returned.\n *\n * FIXME: In desktop, this function may work incorrectly.\n * Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7\n * @param params - popup parameters.\n * @throws {Error} Popup is already opened.\n */\n async open(params: PopupParams): Promise<string | null> {\n if (this.isOpened) {\n throw new Error('Popup is already opened.');\n }\n\n this.state.set('isOpened', true);\n\n try {\n const { button_id: buttonId = null } = await request(\n 'web_app_open_popup',\n preparePopupParams(params),\n 'popup_closed',\n { postEvent: this.postEvent },\n );\n\n return buttonId;\n } finally {\n this.state.set('isOpened', false);\n }\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'open'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { postEvent as defaultPostEvent, request, type PostEvent } from '@tma.js/bridge';\n\nimport type { Version } from '@tma.js/utils';\n\nimport { createSupportsFunc, type SupportsFunc } from '../../supports.js';\nimport { State } from '../../state/index.js';\n\nimport type { QRScannerEvents, QRScannerState } from './types.js';\n\n/**\n * Provides QR scanner functionality.\n */\nexport class QRScanner {\n private readonly ee = new EventEmitter<QRScannerEvents>();\n\n private readonly state: State<QRScannerState>;\n\n constructor(version: Version, private readonly postEvent: PostEvent = defaultPostEvent) {\n this.state = new State({ isOpened: false }, this.ee);\n this.supports = createSupportsFunc(version, {\n close: 'web_app_close_scan_qr_popup',\n open: 'web_app_open_scan_qr_popup',\n });\n }\n\n /**\n * Closes scanner.\n */\n close(): void {\n this.postEvent('web_app_close_scan_qr_popup');\n this.isOpened = false;\n }\n\n private set isOpened(value) {\n this.state.set('isOpened', value);\n }\n\n /**\n * Returns true in case, QR scanner is currently opened.\n */\n get isOpened(): boolean {\n return this.state.get('isOpened');\n }\n\n /**\n * Opens scanner with specified title shown to user. Method returns promise\n * with scanned QR content in case, it was scanned. It will contain null in\n * case, scanner was closed.\n * @param text - title to display.\n */\n async open(text?: string): Promise<string | null> {\n if (this.isOpened) {\n throw new Error('QR scanner is already opened.');\n }\n\n this.isOpened = true;\n\n try {\n const result = await request(\n 'web_app_open_scan_qr_popup',\n { text },\n ['qr_text_received', 'scan_qr_popup_closed'],\n { postEvent: this.postEvent },\n );\n\n return typeof result === 'object' && typeof result.data === 'string' ? result.data : null;\n } finally {\n this.isOpened = false;\n }\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<'open' | 'close'>;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { parse, type ThemeParams as ThemeParamsType } from '@tma.js/theme-params';\nimport { on, request, type RequestOptions } from '@tma.js/bridge';\nimport { isColorDark } from '@tma.js/colors';\n\nimport type { RGB } from '@tma.js/colors';\n\nimport { State } from '../../state/index.js';\n\nimport type { ThemeParamsEvents, ThemeParamsState } from './types.js';\n\nfunction prepareThemeParams(value: ThemeParamsType): ThemeParamsState {\n const {\n backgroundColor = null,\n buttonTextColor = null,\n buttonColor = null,\n hintColor = null,\n linkColor = null,\n textColor = null,\n secondaryBackgroundColor = null,\n } = value;\n\n return {\n backgroundColor,\n buttonTextColor,\n buttonColor,\n hintColor,\n linkColor,\n textColor,\n secondaryBackgroundColor,\n };\n}\n\n/**\n * Contains information about currently used theme by application.\n * @see https://core.telegram.org/bots/webapps#themeparams\n */\nexport class ThemeParams {\n /**\n * Requests fresh information about current theme.\n * FIXME: Be careful using this function in desktop version of Telegram as\n * long as method web_app_request_theme does not work on `macos` platform.\n * @param options - method options.\n */\n static async request(options: RequestOptions = {}): Promise<ThemeParamsType> {\n const { timeout = 1000, ...restOptions } = options;\n const result = await request('web_app_request_theme', 'theme_changed', {\n ...restOptions,\n timeout,\n });\n\n return parse(result.theme_params);\n }\n\n /**\n * Synchronizes specified instance of ThemeParams with the actual value in the native\n * application.\n * @param themeParams - ThemeParams instance.\n */\n static sync(themeParams: ThemeParams): void {\n on('theme_changed', (event) => {\n themeParams.state.set(prepareThemeParams(parse(event.theme_params)));\n });\n }\n\n /**\n * Returns instance of ThemeParams which is synchronized with external\n * environment.\n * @param options - method options.\n */\n static async synced(options?: RequestOptions): Promise<ThemeParams> {\n const params = await this.request(options);\n const tp = new ThemeParams(params);\n\n this.sync(tp);\n\n return tp;\n }\n\n private readonly ee = new EventEmitter<ThemeParamsEvents>();\n\n private readonly state: State<ThemeParamsState>;\n\n constructor(params: ThemeParamsType) {\n this.state = new State(prepareThemeParams(params), this.ee);\n }\n\n /**\n * Returns background color.\n */\n get backgroundColor(): RGB | null {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns button color.\n */\n get buttonColor(): RGB | null {\n return this.state.get('buttonColor');\n }\n\n /**\n * Returns button text color.\n */\n get buttonTextColor(): RGB | null {\n return this.state.get('buttonTextColor');\n }\n\n /**\n * Returns hint color.\n */\n get hintColor(): RGB | null {\n return this.state.get('hintColor');\n }\n\n /**\n * Returns true in case, current color scheme is recognized as dark. This\n * value is calculated according to theme background color.\n */\n get isDark(): boolean {\n return this.backgroundColor === null || isColorDark(this.backgroundColor);\n }\n\n /**\n * Returns current link color.\n */\n get linkColor(): RGB | null {\n return this.state.get('linkColor');\n }\n\n /**\n * Adds new event listener.\n */\n on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off = this.ee.off.bind(this.ee);\n\n /**\n * Returns secondary background color.\n */\n get secondaryBackgroundColor(): RGB | null {\n return this.state.get('secondaryBackgroundColor');\n }\n\n /**\n * Returns text color.\n */\n get textColor(): RGB | null {\n return this.state.get('textColor');\n }\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { on, postEvent as defaultPostEvent, request, type RequestOptions, type PostEvent } from '@tma.js/bridge';\n\nimport { State } from '../../state/index.js';\n\nimport type { ViewportEvents, ViewportState } from './types.js';\n\nexport interface RequestViewportResult {\n height: number;\n isStateStable: boolean;\n isExpanded: boolean;\n width: number;\n}\n\n/**\n * Formats value to make it stay in bounds [0, +Inf).\n * @param value - value to format.\n */\nfunction truncate(value: number): number {\n return value < 0 ? 0 : value;\n}\n\n/**\n * Contains information about current WebApp device viewport, its dimensions\n * and state.\n */\nexport class Viewport {\n /**\n * Requests fresh information about current viewport.\n * FIXME: Be careful using this function in desktop version of Telegram as\n * long as method web_app_request_viewport does not work on `macos` platform.\n * @see Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/5\n * @param options - method options.\n */\n static async request(options: RequestOptions = {}): Promise<RequestViewportResult> {\n const { timeout = 1000, ...restOptions } = options;\n const {\n is_expanded: isExpanded,\n is_state_stable: isStateStable,\n ...rest\n } = await request('web_app_request_viewport', 'viewport_changed', {\n ...restOptions,\n timeout,\n });\n\n return { ...rest, isExpanded, isStateStable };\n }\n\n /**\n * Synchronizes specified instance of Viewport with the actual value in the native\n * application.\n * @param viewport - Viewport instance.\n */\n static sync(viewport: Viewport): void {\n on('viewport_changed', (event) => {\n const {\n height,\n width,\n is_expanded: isExpanded,\n is_state_stable: isStateStable,\n } = event;\n const formattedHeight = truncate(height);\n\n viewport.state.set({\n height: formattedHeight,\n isExpanded,\n width: truncate(width),\n stableHeight: isStateStable ? formattedHeight : undefined,\n });\n });\n }\n\n /**\n * Returns initialized instance of Viewport which is synchronized with\n * its actual state in Web Apps.\n * @param options - method options.\n */\n static async synced(options: RequestOptions = {}): Promise<Viewport> {\n const { height, isExpanded, width } = await this.request(options);\n const viewport = new Viewport(height, width, height, isExpanded, options.postEvent);\n\n this.sync(viewport);\n\n return viewport;\n }\n\n private readonly ee = new EventEmitter<ViewportEvents>();\n\n private readonly state: State<ViewportState>;\n\n constructor(\n height: number,\n width: number,\n stableHeight: number,\n isExpanded: boolean,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n height: truncate(height),\n isExpanded,\n stableHeight: truncate(stableHeight),\n width: truncate(width),\n }, this.ee);\n }\n\n /**\n * The current height of the visible area of the Web App.\n *\n * The application can display just the top part of the Web App, with its\n * lower part remaining outside the screen area. From this position, the\n * user can \"pull\" the Web App to its maximum height, while the bot can do\n * the same by calling `expand` method. As the position of the Web App\n * changes, the current height value of the visible area will be updated\n * in real time.\n *\n * Please note that the refresh rate of this value is not sufficient\n * to smoothly follow the lower border of the window. It should not be\n * used to pin interface elements to the bottom of the visible area. It's\n * more appropriate to use the value of the `stableHeight`\n * field for this purpose.\n *\n * @see init\n * @see expand\n * @see stableHeight\n */\n get height(): number {\n return this.state.get('height');\n }\n\n /**\n * The height of the visible area of the Web App in its last stable state.\n *\n * The application can display just the top part of the Web App, with its\n * lower part remaining outside the screen area. From this position,\n * the user can \"pull\" the Web App to its maximum height, while the bot can\n * do the same by calling `expand` method.\n *\n * Unlike the value of `height`, the value of `stableHeight`\n * does not change as the position of the Web App changes with user\n * gestures or during animations. The value of `stableHeight`\n * will be updated after all gestures and animations are completed and\n * the Web App reaches its final size.\n *\n * @see init\n * @see expand\n * @see height\n */\n get stableHeight(): number {\n return this.state.get('stableHeight');\n }\n\n /**\n * Returns true if the Web App is expanded to the maximum available height.\n * Otherwise, if the Web App occupies part of the screen and can be expanded\n * to the full height using `expand` method.\n * @see expand\n */\n get isExpanded(): boolean {\n return this.state.get('isExpanded');\n }\n\n /**\n * Current viewport width.\n */\n get width(): number {\n return this.state.get('width');\n }\n\n /**\n * A method that expands the Web App to the maximum available height. To\n * find out if the Web App is expanded to the maximum height, refer to the\n * value of the `isExpanded`.\n * @see isExpanded\n */\n expand(): void {\n this.state.set('isExpanded', true);\n this.postEvent('web_app_expand');\n }\n\n /**\n * Returns true in case current viewport height is stable and is not going to\n * change in the next moment.\n */\n get isStable(): boolean {\n return this.stableHeight === this.height;\n }\n\n /**\n * Adds new event listener.\n */\n on: typeof this.ee.on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off: typeof this.ee.off = this.ee.off.bind(this.ee);\n}\n","/**\n * Converts passed URL to its full form.\n * @param url - URL to format.\n * @throws {Error} URL protocol is not supported by OS, or link has not allowed\n * protocol.\n */\nexport function formatURL(url: string): string {\n // TODO: Maybe, there is a bit easier way? window.open will accept\n // unformatted URL too, probably.\n\n // We do create new anchor element and assign its href to passed URL. This\n // will format link, so it could be used in `window.open`.\n const anchor = document.createElement('a');\n anchor.href = url;\n\n // Check if protocol is correct.\n if (anchor.protocol !== 'http:' && anchor.protocol !== 'https:') {\n throw Error(\n `URL protocol is not supported by OS, or link has not allowed protocol: ${anchor.protocol}`,\n );\n }\n return anchor.href;\n}\n","import { EventEmitter } from '@tma.js/event-emitter';\nimport { compareVersions, type Version } from '@tma.js/utils';\nimport { isRGB, isColorDark, type RGB } from '@tma.js/colors';\nimport {\n postEvent as defaultPostEvent,\n supports,\n request,\n type PhoneRequestedStatus,\n type WriteAccessRequestedStatus,\n type InvoiceStatus,\n type PostEvent,\n} from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { formatURL } from '../../url.js';\nimport { State } from '../../state/index.js';\nimport { createSupportsFunc, createSupportsParamFunc, type SupportsFunc } from '../../supports.js';\n\nimport type { ColorScheme } from '../../types.js';\nimport type { WebAppEvents, WebAppHeaderColor, WebAppState } from './types.js';\n\n/**\n * Provides common Web Apps functionality not covered by other system\n * components.\n */\nexport class WebApp {\n private readonly ee = new EventEmitter<WebAppEvents>();\n\n private readonly state: State<WebAppState>;\n\n constructor(\n headerColor: WebAppHeaderColor,\n backgroundColor: RGB,\n private readonly currentVersion: Version,\n private readonly currentPlatform: Platform,\n private readonly createRequestId: () => string,\n private readonly postEvent: PostEvent = defaultPostEvent,\n ) {\n this.state = new State({\n backgroundColor,\n headerColor,\n }, this.ee);\n this.supports = createSupportsFunc(currentVersion, {\n openInvoice: 'web_app_open_invoice',\n readTextFromClipboard: 'web_app_read_text_from_clipboard',\n setHeaderColor: 'web_app_set_header_color',\n setBackgroundColor: 'web_app_set_background_color',\n requestPhoneAccess: 'web_app_request_phone',\n requestWriteAccess: 'web_app_request_write_access',\n });\n this.supportsParam = createSupportsParamFunc(currentVersion, {\n 'setHeaderColor.color': ['web_app_set_header_color', 'color'],\n 'openLink.tryInstantView': ['web_app_open_link', 'try_instant_view'],\n });\n }\n\n /**\n * Returns current application background color.\n */\n get backgroundColor(): RGB {\n return this.state.get('backgroundColor');\n }\n\n /**\n * Returns current application color scheme. This value is\n * computed based on the current background color.\n */\n get colorScheme(): ColorScheme {\n return isColorDark(this.backgroundColor) ? 'dark' : 'light';\n }\n\n /**\n * Closes the Web App.\n */\n close(): void {\n this.postEvent('web_app_close');\n }\n\n /**\n * Returns current application header color.\n */\n get headerColor(): WebAppHeaderColor {\n return this.state.get('headerColor');\n }\n\n /**\n * Returns true if passed version is more than or equal to current\n * Web App version.\n * @param version - compared version.\n */\n isVersionAtLeast(version: Version): boolean {\n return compareVersions(version, this.version) >= 0;\n }\n\n /**\n * Opens a link in an external browser. The Web App will not be closed.\n *\n * Note that this method can be called only in response to the user\n * interaction with the Web App interface (e.g. click inside the Web App\n * or on the main button).\n * @param url - URL to be opened.\n * @param tryInstantView\n */\n openLink(url: string, tryInstantView?: boolean): void {\n const formattedUrl = formatURL(url);\n\n // If method is not supported, we are doing it in legacy way.\n if (!supports('web_app_open_link', this.version)) {\n window.open(formattedUrl, '_blank');\n return;\n }\n\n // Otherwise, do it normally.\n return this.postEvent('web_app_open_link', {\n url: formattedUrl,\n ...(typeof tryInstantView === 'boolean' ? { try_instant_view: tryInstantView } : {}),\n });\n }\n\n /**\n * Opens a Telegram link inside Telegram app. The Web App will be closed.\n * It expects passing link in full format, with hostname \"t.me\".\n * @param url - URL to be opened.\n * @throws {Error} URL has not allowed hostname.\n */\n openTelegramLink(url: string): void {\n const { hostname, pathname, search } = new URL(formatURL(url));\n\n if (hostname !== 't.me') {\n throw new Error(`URL has not allowed hostname: ${hostname}. Only \"t.me\" is allowed`);\n }\n\n if (!supports('web_app_open_tg_link', this.version)) {\n window.location.href = url;\n return;\n }\n\n return this.postEvent('web_app_open_tg_link', { path_full: pathname + search });\n }\n\n /**\n * Opens an invoice using its url. It expects passing link in full format,\n * with hostname \"t.me\".\n * @param url - invoice URL.\n */\n async openInvoice(url: string): Promise<InvoiceStatus> {\n // TODO: Allow opening with slug.\n const { hostname, pathname } = new URL(formatURL(url));\n\n if (hostname !== 't.me') {\n throw new Error(`Incorrect hostname: ${hostname}`);\n }\n // Valid examples:\n // \"/invoice/my-slug\"\n // \"/$my-slug\"\n const match = pathname.match(/^\\/(\\$|invoice\\/)([A-Za-z0-9\\-_=]+)$/);\n\n if (match === null) {\n throw new Error('Link pathname has incorrect format. Expected to receive \"/invoice/slug\" or \"/$slug\"');\n }\n const [, , slug] = match;\n\n const result = await request('web_app_open_invoice', { slug }, 'invoice_closed', {\n postEvent: this.postEvent,\n capture: ({ slug: eventSlug }) => slug === eventSlug,\n });\n\n return result.status;\n }\n\n /**\n * Adds new event listener.\n */\n on = this.ee.on.bind(this.ee);\n\n /**\n * Removes event listener.\n */\n off = this.ee.off.bind(this.ee);\n\n /**\n * Returns current Web App platform.\n */\n get platform(): Platform {\n return this.currentPlatform;\n }\n\n /**\n * Informs the Telegram app that the Web App is ready to be displayed.\n *\n * It is recommended to call this method as early as possible, as soon as\n * all essential interface elements loaded. Once this method called,\n * the loading placeholder is hidden and the Web App shown.\n *\n * If the method not called, the placeholder will be hidden only when\n * the page fully loaded.\n */\n ready(): void {\n this.postEvent('web_app_ready');\n }\n\n /**\n * Reads text from clipboard and returns string or null. null is returned\n * in cases:\n * - Value in clipboard is not text\n * - Access to clipboard is not allowed\n */\n async readTextFromClipboard(): Promise<string | null> {\n // TODO: Generate request id.\n const { data = null } = await request(\n 'web_app_read_text_from_clipboard',\n { req_id: this.createRequestId() },\n 'clipboard_text_received',\n { postEvent: this.postEvent },\n );\n\n return data;\n }\n\n /**\n * Requests current user phone access.\n */\n async requestPhoneAccess(): Promise<PhoneRequestedStatus> {\n const { status } = await request('web_app_request_phone', 'phone_requested', {\n postEvent: this.postEvent,\n });\n\n return status;\n }\n\n /**\n * Requests write message access to current user.\n */\n async requestWriteAccess(): Promise<WriteAccessRequestedStatus> {\n const { status } = await request('web_app_request_write_access', 'write_access_requested', {\n postEvent: this.postEvent,\n });\n\n return status;\n }\n\n /**\n * A method used to send data to the bot. When this method called, a\n * service message sent to the bot containing the data of the\n * length up to 4096 bytes, and the Web App closed. See the field\n * `web_app_data` in the class Message.\n *\n * This method is only available for Web Apps launched via a Keyboard button.\n * @param data - data to send to bot.\n * @throws {Error} data has incorrect size.\n */\n sendData(data: string): void {\n // Firstly, compute passed text size in bytes.\n const { size } = new Blob([data]);\n if (size === 0 || size > 4096) {\n throw new Error(`Passed data has incorrect size: ${size}`);\n }\n this.postEvent('web_app_data_send', { data });\n }\n\n /**\n * Updates current application header color.\n * FIXME: Has no effect on desktop, works incorrectly on Android.\n * Issues:\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/9\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/8\n * @param color - color key or RGB color.\n */\n setHeaderColor(color: WebAppHeaderColor) {\n this.postEvent('web_app_set_header_color', isRGB(color) ? { color } : { color_key: color });\n this.state.set('headerColor', color);\n }\n\n /**\n * Updates current application background color.\n * FIXME: Has no effect on desktop, works incorrectly in Android.\n * Issues:\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/9\n * https://github.com/Telegram-Mini-Apps/tma.js/issues/8\n * @param color - RGB color.\n */\n setBackgroundColor(color: RGB) {\n this.postEvent('web_app_set_background_color', { color });\n this.state.set('backgroundColor', color);\n }\n\n /**\n * Checks if specified method is supported by current component.\n */\n supports: SupportsFunc<\n | 'openInvoice'\n | 'readTextFromClipboard'\n | 'setHeaderColor'\n | 'setBackgroundColor'\n | 'requestWriteAccess'\n | 'requestPhoneAccess'\n >;\n\n /**\n * Checks if specified method parameter is supported by current component.\n */\n supportsParam: SupportsFunc<'setHeaderColor.color' | 'openLink.tryInstantView'>;\n\n /**\n * Current Web App version. This property is used by other components to check if\n * some functionality is available on current device.\n */\n get version(): Version {\n return this.currentVersion;\n }\n}\n","/**\n * Error thrown in case, unsupported method was called.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string, version: string) {\n super(`Method \"${method}\" is not supported in the Web Apps version ${version}.`);\n Object.setPrototypeOf(this, MethodNotSupportedError.prototype);\n }\n}\n","/**\n * Error thrown in case, unsupported parameter was used.\n */\nexport class ParameterUnsupportedError extends Error {\n constructor(method: string, param: string, version: string) {\n super(`Parameter \"${param}\" in method \"${method}\" is not supported in the Web Apps version ${version}.`);\n Object.setPrototypeOf(this, ParameterUnsupportedError.prototype);\n }\n}\n","import type { RGB } from '@tma.js/colors';\n\nimport type { ThemeParams, WebApp, Viewport } from '../components/index.js';\nimport type { InitCSSVarsOption, InitCSSVarsSpecificOption } from './types.js';\n\n/**\n * Sets CSS variable.\n * @param name - variable name.\n * @param value - variable value.\n */\nfunction setVariable(name: string, value: string): void {\n document.documentElement.style.setProperty(name, value);\n}\n\n/**\n * Sets new CSS color variable in case, its value is not null.\n * @param name - variable name.\n * @param color - variable value.\n */\nfunction setColorVariable(name: string, color: RGB | null): void {\n if (color === null) {\n return;\n }\n setVariable(name, color);\n}\n\n/**\n * Sets new CSS variable which value is amount of pixels.\n * @param name - variable name.\n * @param size - variable value.\n */\nfunction setSizeVariable(name: string, size: number) {\n setVariable(name, `${size}px`);\n}\n\n/**\n * Creates CSS variables based on theme parameters.\n * @param themeParams - ThemeParams instance.\n */\nfunction createThemeVariables(themeParams: ThemeParams): void {\n const {\n backgroundColor,\n buttonTextColor,\n secondaryBackgroundColor,\n hintColor,\n buttonColor,\n linkColor,\n textColor,\n } = themeParams;\n\n setColorVariable('--tg-theme-bg-color', backgroundColor);\n setColorVariable('--tg-theme-button-color', buttonColor);\n setColorVariable('--tg-theme-button-text-color', buttonTextColor);\n setColorVariable('--tg-theme-hint-color', hintColor);\n setColorVariable('--tg-theme-link-color', linkColor);\n setColorVariable('--tg-theme-secondary-bg-color', secondaryBackgroundColor);\n setColorVariable('--tg-theme-text-color', textColor);\n}\n\n/**\n * Creates CSS variables based on Web App background and header colors with\n * theme parameters.\n * @param webApp - WebApp instance.\n * @param themeParams - theme parameters.\n */\nfunction createWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {\n const { backgroundColor, secondaryBackgroundColor } = themeParams;\n const { backgroundColor: webAppBackgroundColor, headerColor } = webApp;\n\n setColorVariable('--tg-bg-color', webAppBackgroundColor);\n setColorVariable('--tg-header-color', headerColor === 'bg_color' ? backgroundColor : secondaryBackgroundColor);\n}\n\n/**\n * Creates CSS variables connected with theme parameters.\n *\n * Created variables:\n * - `--tg-theme-bg-color`\n * - `--tg-theme-button-color`\n * - `--tg-theme-button-text-color`\n * - `--tg-theme-hint-color`\n * - `--tg-theme-link-color`\n * - `--tg-theme-secondary-bg-color`\n * - `--tg-theme-text-color`\n *\n * Variables are being automatically updated in case, corresponding properties\n * updated in passed ThemeParams instance.\n *\n * @param themeParams - ThemeParams instance.\n */\nexport function bindThemeCSSVariables(themeParams: ThemeParams): void {\n const actualize = () => createThemeVariables(themeParams);\n\n themeParams.on('changed', actualize);\n\n actualize();\n}\n\n/**\n * Creates CSS variables connected with WebApp background and header colors based on\n * passed WebApp and ThemeParams instances.\n *\n * Created variables:\n * - `--tg-bg-color`\n * - `--tg-header-color`\n *\n * Variables are being automatically updated in case, corresponding properties are updating.\n *\n * @param webApp - WebApp instance.\n * @param themeParams - ThemeParams instance.\n */\nexport function bindWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void {\n const actualize = () => createWebAppVariables(webApp, themeParams);\n\n themeParams.on('changed', actualize);\n webApp.on('backgroundColorChanged', actualize);\n webApp.on('headerColorChanged', actualize);\n\n actualize();\n}\n\n/**\n * Accepts Viewport instance and sets CSS variables connected with viewport\n * sizes.\n *\n * Be careful using this function as long as it can impact application\n * performance. Viewport size is changing rather often, this makes CSS\n * variables update, which leads to possible layout redraw.\n *\n * Variables:\n * - `--tg-viewport-height`\n * - `--tg-viewport-stable-height`\n *\n * Variables are being automatically updated in case, corresponding properties\n * updated in passed Viewport instance.\n *\n * @param viewport - Viewport instance.\n */\nexport function bindViewportCSSVariables(viewport: Viewport): void {\n const setHeight = () => {\n setSizeVariable('--tg-viewport-height', viewport.height);\n };\n\n const setStableHeight = () => {\n setSizeVariable('--tg-viewport-stable-height', viewport.stableHeight);\n };\n\n viewport.on('heightChanged', setHeight);\n viewport.on('stableHeightChanged', setStableHeight);\n\n setHeight();\n setStableHeight();\n}\n\n/**\n * Converts init cssVars option to more narrow type.\n * @param option - option value.\n */\nexport function parseCSSVarsOptions(option: InitCSSVarsOption): InitCSSVarsSpecificOption {\n if (typeof option === 'boolean') {\n return option\n ? { themeParams: true, viewport: true, webApp: true }\n : {};\n }\n return option;\n}\n","import type { HeaderColorKey } from '@tma.js/bridge';\nimport type { RGB } from '@tma.js/colors';\n\n/**\n * Describes storage keys and according values.\n */\ninterface StorageParams {\n 'back-button': {\n isVisible: boolean\n };\n 'closing-behavior': {\n isConfirmationNeeded: boolean;\n };\n 'main-button': {\n backgroundColor: RGB;\n isEnabled: boolean;\n isVisible: boolean;\n isProgressVisible: boolean;\n text: string;\n textColor: RGB;\n };\n viewport: {\n height: number;\n isExpanded: boolean;\n stableHeight: number;\n width: number;\n };\n 'web-app': {\n backgroundColor: RGB;\n headerColor: HeaderColorKey | RGB;\n };\n}\n\n/**\n * Key which could be used to store data in storage.\n */\ntype StorageKey = keyof StorageParams;\n\n/**\n * Formats key which could be used during the communication with the storage.\n * @param key - session storage key.\n */\nfunction formatKey(key: StorageKey): string {\n return `telegram-mini-apps-${key}`;\n}\n\n/**\n * Saves value in sessionStorage.\n * @param key - storage key.\n * @param value - storage value.\n */\nexport function saveStorageValue<K extends StorageKey>(key: K, value: StorageParams[K]): void {\n sessionStorage.setItem(formatKey(key), JSON.stringify(value));\n}\n\n/**\n * Extracts value from the sessionStorage.\n * @param key - storage key.\n */\nexport function getStorageValue<K extends StorageKey>(key: K): StorageParams[K] | null {\n const value = sessionStorage.getItem(formatKey(key));\n\n return value ? JSON.parse(value) : null;\n}\n","import type { PostEvent } from '@tma.js/bridge';\n\nimport { BackButton } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates BackButton instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param version - platform version.\n * @param postEvent - Bridge postEvent function\n */\nexport function createBackButton(\n isPageReload: boolean,\n version: string,\n postEvent: PostEvent,\n): BackButton {\n const { isVisible = false } = isPageReload ? getStorageValue('back-button') || {} : {};\n const component = new BackButton(isVisible, version, postEvent);\n\n component.on('isVisibleChanged', () => {\n saveStorageValue('back-button', { isVisible: component.isVisible });\n });\n\n return component;\n}\n","import type { PostEvent } from '@tma.js/bridge';\n\nimport { ClosingBehaviour } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates ClosingBehaviour instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param postEvent - Bridge postEvent function\n */\nexport function createClosingBehavior(\n isPageReload: boolean,\n postEvent: PostEvent,\n): ClosingBehaviour {\n const { isConfirmationNeeded = false } = isPageReload ? getStorageValue('closing-behavior') || {} : {};\n\n const component = new ClosingBehaviour(isConfirmationNeeded, postEvent);\n\n component.on('isConfirmationNeededChanged', () => saveStorageValue('closing-behavior', {\n isConfirmationNeeded: component.isConfirmationNeeded,\n }));\n\n return component;\n}\n","import type { RGB } from '@tma.js/colors';\nimport type { PostEvent } from '@tma.js/bridge';\n\nimport { MainButton } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates MainButton instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param backgroundColor - background color.\n * @param textColor - text color.\n * @param postEvent - Bridge postEvent function\n */\nexport function createMainButton(\n isPageReload: boolean,\n backgroundColor: RGB,\n textColor: RGB,\n postEvent: PostEvent,\n): MainButton {\n const {\n backgroundColor: stateBackgroundColor = backgroundColor,\n isEnabled = false,\n isVisible = false,\n isProgressVisible = false,\n textColor: stateTextColor = textColor,\n text = '',\n } = isPageReload ? getStorageValue('main-button') || {} : {};\n\n const component = new MainButton(\n stateBackgroundColor,\n isEnabled,\n isVisible,\n isProgressVisible,\n text,\n stateTextColor,\n postEvent,\n );\n\n const saveState = () => saveStorageValue('main-button', {\n backgroundColor: component.backgroundColor,\n isEnabled: component.isEnabled,\n isVisible: component.isVisible,\n isProgressVisible: component.isProgressVisible,\n text: component.text,\n textColor: component.textColor,\n });\n\n component.on('backgroundColorChanged', saveState);\n component.on('isEnabledChanged', saveState);\n component.on('isVisibleChanged', saveState);\n component.on('isProgressVisibleChanged', saveState);\n component.on('textColorChanged', saveState);\n component.on('textChanged', saveState);\n\n return component;\n}\n","import {\n supports,\n postEvent as defaultPostEvent,\n detectSupportParams,\n type PostEvent,\n} from '@tma.js/bridge';\nimport { isRecord } from '@tma.js/utils';\n\nimport { MethodNotSupportedError, ParameterUnsupportedError } from '../../errors/index.js';\n\n/**\n * Creates postEvent function.\n * @param checkCompat - should compatibility check be enabled.\n * @param version - platform version.\n */\nexport function createPostEvent(checkCompat: boolean, version: string): PostEvent {\n return checkCompat\n ? (method: any, params: any) => {\n // Firstly, check if method itself is supported.\n if (!supports(method, version)) {\n throw new MethodNotSupportedError(method, version);\n }\n\n // Method could use parameters, which are supported only in specific versions of TWA.\n if (isRecord(params)) {\n detectSupportParams(method, params).forEach((param) => {\n if (!supports(method as any, param, version)) {\n throw new ParameterUnsupportedError(method, param, version);\n }\n });\n }\n\n return defaultPostEvent(method, params);\n }\n : defaultPostEvent;\n}\n","import type { CreateRequestIdFunc } from '../../types.js';\n\n/**\n * Creates function which generated request identifiers.\n */\nexport function createRequestIdGenerator(): CreateRequestIdFunc {\n let requestId = 0;\n\n return () => {\n requestId += 1;\n return requestId.toString();\n };\n}\n","import type { ThemeParams as ThemeParamsType } from '@tma.js/theme-params';\n\nimport { ThemeParams } from '../../components/index.js';\n\n/**\n * Creates synced instance of ThemeParams.\n * @param params - theme parameters.\n */\nexport function createThemeParams(params: ThemeParamsType): ThemeParams {\n const themeParams = new ThemeParams(params);\n ThemeParams.sync(themeParams);\n\n return themeParams;\n}\n","import type { PostEvent } from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { Viewport } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\n/**\n * Creates Viewport instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param platform - Telegram Web Apps platform name.\n * @param postEvent - Bridge postEvent function\n */\nexport async function createViewport(\n isPageReload: boolean,\n platform: Platform,\n postEvent: PostEvent,\n): Promise<Viewport> {\n const {\n height = window.innerHeight,\n stableHeight = window.innerHeight,\n width = window.innerWidth,\n isExpanded = false,\n } = isPageReload ? getStorageValue('viewport') || {} : {};\n\n const createSynced = () => {\n const viewport = new Viewport(height, width, stableHeight, isExpanded, postEvent);\n Viewport.sync(viewport);\n\n return viewport;\n };\n\n // MacOS and Web K versions do not support requesting current viewport information. That's why we\n // should construct Viewport instance by ourselves.\n const component = platform === 'macos' || platform === 'web'\n ? createSynced()\n : await Viewport.synced({ postEvent });\n\n const saveState = () => saveStorageValue('viewport', {\n height: component.height,\n isExpanded: component.isExpanded,\n stableHeight: component.stableHeight,\n width: component.width,\n });\n\n // TODO: Should probably use throttle for height.\n component.on('heightChanged', saveState);\n component.on('isExpandedChanged', saveState);\n component.on('stableHeightChanged', saveState);\n component.on('widthChanged', saveState);\n\n return component;\n}\n","import type { RGB } from '@tma.js/colors';\nimport type { PostEvent } from '@tma.js/bridge';\nimport type { Platform } from '@tma.js/launch-params';\n\nimport { WebApp } from '../../components/index.js';\n\nimport { getStorageValue, saveStorageValue } from '../../storage.js';\n\nimport type { CreateRequestIdFunc } from '../../types.js';\n\n/**\n * Creates WebApp instance using last locally saved data also saving each state in\n * the storage.\n * @param isPageReload - was current page reloaded.\n * @param backgroundColor - web app background color.\n * @param version - platform version.\n * @param platform - Telegram Web Apps platform name.\n * @param createRequestId - function which generates request identifiers.\n * @param postEvent - Bridge postEvent function\n */\nexport function createWebApp(\n isPageReload: boolean,\n backgroundColor: RGB,\n version: string,\n platform: Platform,\n createRequestId: CreateRequestIdFunc,\n postEvent: PostEvent,\n): WebApp {\n const {\n backgroundColor: stateBackgroundColor = backgroundColor,\n headerColor = 'bg_color',\n } = isPageReload ? getStorageValue('web-app') || {} : {};\n\n const component = new WebApp(\n headerColor,\n stateBackgroundColor,\n version,\n platform,\n createRequestId,\n postEvent,\n );\n\n const saveState = () => saveStorageValue('web-app', {\n backgroundColor: component.backgroundColor,\n headerColor: component.headerColor,\n });\n\n component.on('backgroundColorChanged', saveState);\n component.on('headerColorChanged', saveState);\n\n return component;\n}\n","import { parse, retrieveFromStorage } from '@tma.js/launch-params';\nimport type { LaunchParams } from '@tma.js/launch-params';\n\n/**\n * Attempts to extract launch params from window.location.hash. In case, window.location.hash\n * lacks of valid data, function attempts to extract launch params from the sessionStorage.\n */\nexport function retrieveLaunchParams(): LaunchParams {\n let error: unknown | undefined;\n\n // Try to extract Mini App data from hash. This block of code covers usual flow, when\n // application was firstly opened by the user and its hash always contains required parameters.\n try {\n return parse(window.location.hash.slice(1));\n } catch (e) {\n error = e;\n }\n\n // Mini Apps allows reloading current page. In this case, window.location.reload() will be\n // called which means, that init will be called again. As the result, current window\n // location will lose Mini App data. To solve this problem, we are extracting launch\n // params saved previously.\n const fromStorage = retrieveFromStorage();\n if (fromStorage) {\n return fromStorage;\n }\n\n throw new Error('Unable to extract launch params', { cause: error });\n}\n","import {\n isIframe,\n setDebug,\n setTargetOrigin,\n on,\n} from '@tma.js/bridge';\nimport { withTimeout } from '@tma.js/utils';\nimport type { LaunchParams } from '@tma.js/launch-params';\nimport {\n parse as parseLaunchParams,\n saveToStorage as saveLaunchParamsToStorage,\n retrieveFromStorage,\n} from '@tma.js/launch-params';\n\nimport {\n CloudStorage,\n HapticFeedback,\n InitData,\n Popup,\n QRScanner,\n} from '../components/index.js';\nimport {\n bindThemeCSSVariables,\n bindViewportCSSVariables,\n bindWebAppVariables,\n parseCSSVarsOptions,\n} from './css.js';\nimport {\n createPostEvent,\n createThemeParams,\n createBackButton,\n createMainButton,\n createViewport,\n createWebApp, createRequestIdGenerator, createClosingBehavior,\n} from './creators/index.js';\nimport { retrieveLaunchParams } from '../launch-params.js';\n\nimport type { InitOptions, InitResult } from './types.js';\n\n/**\n * Returns true in case, current session was created due to native location reload.\n */\nfunction isNativePageReload(): boolean {\n return (\n window\n .performance\n .getEntriesByType('navigation') as PerformanceNavigationTiming[]\n ).some((entry) => entry.type === 'reload');\n}\n\n/**\n * Returns true if current page was reloaded.\n * @param launchParamsFromStorage - launch parameters from sessionStorage.\n * @param currentLaunchParams - actual launch parameters.\n */\nfunction computePageReload(\n launchParamsFromStorage: LaunchParams | null,\n currentLaunchParams: LaunchParams,\n): boolean {\n // To check if page was reloaded, we should check if previous init data hash equals to the\n // current one. Nevertheless, there are some cases, when init data is missing. For example,\n // when app was launched via KeyboardButton. In this case we try to use the native way of\n // checking if current page was reloaded (which could still return incorrect result).\n // Issue: https://github.com/Telegram-Mini-Apps/issues/issues/12\n if (!launchParamsFromStorage) {\n return false;\n }\n\n return launchParamsFromStorage.initData?.hash === currentLaunchParams.initData?.hash;\n}\n\n/**\n * Represents actual init function.\n * @param options - init options.\n */\nasync function actualInit(options: InitOptions = {}): Promise<InitResult> {\n const {\n checkCompat = true,\n cssVars = false,\n acceptScrollbarStyle = true,\n acceptCustomStyles = acceptScrollbarStyle,\n targetOrigin,\n debug = false,\n launchParams: optionsLaunchParams = retrieveLaunchParams(),\n } = options;\n\n // Set global settings.\n if (debug) {\n setDebug(debug);\n }\n\n if (typeof targetOrigin === 'string') {\n setTargetOrigin(targetOrigin);\n }\n\n // Get Web App launch params and save them to session storage, so they will be accessible from\n // anywhere.\n const launchParamsFromStorage = retrieveFromStorage();\n const launchParams = optionsLaunchParams instanceof URLSearchParams || typeof optionsLaunchParams === 'string'\n ? parseLaunchParams(optionsLaunchParams)\n : optionsLaunchParams;\n\n saveLaunchParamsToStorage(launchParams);\n\n // Compute if page was reloaded. We will need it to decide if SDK components should be restored\n // or created from scratch.\n const isPageReload = isNativePageReload()\n || computePageReload(launchParamsFromStorage, launchParams);\n\n const {\n initData,\n initDataRaw,\n version,\n platform,\n themeParams: lpThemeParams,\n } = launchParams;\n const {\n backgroundColor = '#ffffff',\n buttonColor = '#000000',\n buttonTextColor = '#ffffff',\n } = lpThemeParams;\n\n const createRequestId = createRequestIdGenerator();\n const postEvent = createPostEvent(checkCompat, version);\n const themeParams = createThemeParams(lpThemeParams);\n const webApp = createWebApp(\n isPageReload,\n backgroundColor,\n version,\n platform,\n createRequestId,\n postEvent,\n );\n\n const {\n themeParams: createThemeParamsCSSVars,\n viewport: createViewportCSSVars,\n webApp: createWebAppCSSVars,\n } = parseCSSVarsOptions(cssVars);\n\n if (createWebAppCSSVars) {\n bindWebAppVariables(webApp, themeParams);\n }\n\n if (createThemeParamsCSSVars) {\n bindThemeCSSVariables(themeParams);\n }\n\n const viewport = await createViewport(isPageReload, platform, postEvent);\n\n // Apply viewport CSS variables.\n if (createViewportCSSVars) {\n bindViewportCSSVariables(viewport);\n }\n\n // In case, we are currently in iframe, it is required to listen to\n // messages, coming from parent source to apply requested changes.\n // The only one case, when current application was placed into iframe is\n // web version of Telegram.\n if (acceptCustomStyles && isIframe()) {\n // Create special style element which is responsible for application\n // style controlled by external app.\n const styleElement = document.createElement('style');\n styleElement.id = 'telegram-custom-styles';\n document.head.appendChild(styleElement);\n\n // Listen to custom style changes.\n on('set_custom_style', (html) => {\n styleElement.innerHTML = html;\n });\n\n // Notify Telegram, iframe is ready. This will result in sending style\n // tag html from native application.\n postEvent('iframe_ready');\n }\n\n const result: InitResult = {\n backButton: createBackButton(isPageReload, version, postEvent),\n closingBehavior: createClosingBehavior(isPageReload, postEvent),\n cloudStorage: new CloudStorage(version, createRequestId, postEvent),\n haptic: new HapticFeedback(version, postEvent),\n mainButton: createMainButton(isPageReload, buttonColor, buttonTextColor, postEvent),\n popup: new Popup(version, postEvent),\n postEvent,\n qrScanner: new QRScanner(version, postEvent),\n themeParams,\n viewport,\n webApp,\n };\n\n // Init data could be missing in case, application was launched via InlineKeyboardButton.\n if (initData !== undefined) {\n const { authDate, hash, ...restInitData } = initData;\n result.initData = new InitData(authDate, hash, restInitData);\n result.initDataRaw = initDataRaw;\n }\n\n return result;\n}\n\n/**\n * Initializes all SDK components.\n * @param options - initialization options.\n */\nexport function init(options: InitOptions = {}): Promise<InitResult> {\n return withTimeout(actualInit(options), options.timeout || 1000);\n}\n","import { retrieveLaunchParams } from './launch-params.js';\n\n/**\n * Returns true in case, current environment is Telegram Web Apps.\n *\n * `isTWA` utilizes such function as `retrieveLaunchParams`, which attempts to retrieve\n * launch parameters from the current environment.\n * @see retrieveLaunchParams\n */\nexport function isTWA(): boolean {\n try {\n retrieveLaunchParams();\n return true;\n } catch (e) {\n return false;\n }\n}\n"],"names":["createSupportsFunc","version","schema","method","supports","createSupportsParamFunc","tmaMethod","param","State","state","ee","key","value","keyOrState","didChange","BackButton","isVisible","postEvent","defaultPostEvent","__publicField","EventEmitter","event","listener","on","off","visible","ClosingBehaviour","isConfirmationNeeded","stringArray","array","string","objectFromKeys","keys","acc","CloudStorage","createRequestId","params","options","result","error","request","json","HapticFeedback","style","type","InitData","authDate","hash","chat","canSendAfter","chatType","chatInstance","user","queryId","receiver","startParam","MainButton","backgroundColor","isEnabled","isProgressVisible","text","textColor","preparePopupParams","message","title","buttons","preparedButtons","b","id","Popup","buttonId","QRScanner","prepareThemeParams","buttonTextColor","buttonColor","hintColor","linkColor","secondaryBackgroundColor","ThemeParams","timeout","restOptions","parse","themeParams","tp","isColorDark","truncate","Viewport","height","width","stableHeight","isExpanded","isStateStable","rest","viewport","formattedHeight","formatURL","url","anchor","WebApp","headerColor","currentVersion","currentPlatform","compareVersions","tryInstantView","formattedUrl","hostname","pathname","search","match","slug","eventSlug","data","status","size","color","isRGB","MethodNotSupportedError","ParameterUnsupportedError","setVariable","name","setColorVariable","setSizeVariable","createThemeVariables","createWebAppVariables","webApp","webAppBackgroundColor","bindThemeCSSVariables","actualize","bindWebAppVariables","bindViewportCSSVariables","setHeight","setStableHeight","parseCSSVarsOptions","option","formatKey","saveStorageValue","getStorageValue","createBackButton","isPageReload","component","createClosingBehavior","createMainButton","stateBackgroundColor","stateTextColor","saveState","createPostEvent","checkCompat","isRecord","detectSupportParams","createRequestIdGenerator","requestId","createThemeParams","createViewport","platform","createWebApp","retrieveLaunchParams","fromStorage","retrieveFromStorage","isNativePageReload","entry","computePageReload","launchParamsFromStorage","currentLaunchParams","_a","_b","actualInit","cssVars","acceptScrollbarStyle","acceptCustomStyles","targetOrigin","debug","optionsLaunchParams","setDebug","setTargetOrigin","launchParams","parseLaunchParams","saveLaunchParamsToStorage","initData","initDataRaw","lpThemeParams","createThemeParamsCSSVars","createViewportCSSVars","createWebAppCSSVars","isIframe","styleElement","html","restInitData","init","withTimeout","isTWA"],"mappings":"u8BAoBgB,SAAAA,EACdC,EACAC,EACiB,CACjB,OAAQC,GAAWC,EAAA,SAASF,EAAOC,CAAM,EAAGF,CAAO,CACrD,CASgB,SAAAI,GACdJ,EACAC,EACiB,CACjB,OAAQC,GAAW,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