@tma.js/sdk 0.11.3
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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/lib/browser.js +2 -0
- package/dist/lib/browser.js.map +1 -0
- package/dist/lib/index.cjs +2 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.mjs +2 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/components/BackButton/BackButton.d.ts +44 -0
- package/dist/types/components/BackButton/index.d.ts +2 -0
- package/dist/types/components/BackButton/types.d.ts +9 -0
- package/dist/types/components/ClosingBehaviour/ClosingBehaviour.d.ts +35 -0
- package/dist/types/components/ClosingBehaviour/index.d.ts +2 -0
- package/dist/types/components/ClosingBehaviour/types.d.ts +7 -0
- package/dist/types/components/CloudStorage/CloudStorage.d.ts +47 -0
- package/dist/types/components/CloudStorage/index.d.ts +1 -0
- package/dist/types/components/HapticFeedback/HapticFeedback.d.ts +37 -0
- package/dist/types/components/HapticFeedback/index.d.ts +1 -0
- package/dist/types/components/InitData/InitData.d.ts +52 -0
- package/dist/types/components/InitData/index.d.ts +1 -0
- package/dist/types/components/MainButton/MainButton.d.ts +114 -0
- package/dist/types/components/MainButton/index.d.ts +2 -0
- package/dist/types/components/MainButton/types.d.ts +15 -0
- package/dist/types/components/Popup/Popup.d.ts +44 -0
- package/dist/types/components/Popup/index.d.ts +2 -0
- package/dist/types/components/Popup/types.d.ts +60 -0
- package/dist/types/components/Popup/utils.d.ts +7 -0
- package/dist/types/components/QRScanner/QRScanner.d.ts +40 -0
- package/dist/types/components/QRScanner/index.d.ts +2 -0
- package/dist/types/components/QRScanner/types.d.ts +7 -0
- package/dist/types/components/ThemeParams/ThemeParams.d.ts +73 -0
- package/dist/types/components/ThemeParams/index.d.ts +2 -0
- package/dist/types/components/ThemeParams/types.d.ts +9 -0
- package/dist/types/components/Viewport/Viewport.d.ts +108 -0
- package/dist/types/components/Viewport/index.d.ts +2 -0
- package/dist/types/components/Viewport/types.d.ts +10 -0
- package/dist/types/components/WebApp/WebApp.d.ts +145 -0
- package/dist/types/components/WebApp/index.d.ts +2 -0
- package/dist/types/components/WebApp/types.d.ts +11 -0
- package/dist/types/components/index.d.ts +11 -0
- package/dist/types/env.d.ts +8 -0
- package/dist/types/errors/MethodNotSupportedError.d.ts +6 -0
- package/dist/types/errors/ParameterNotSupportedError.d.ts +6 -0
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/init/creators/createBackButton.d.ts +9 -0
- package/dist/types/init/creators/createClosingBehavior.d.ts +8 -0
- package/dist/types/init/creators/createMainButton.d.ts +11 -0
- package/dist/types/init/creators/createPostEvent.d.ts +7 -0
- package/dist/types/init/creators/createRequestIdGenerator.d.ts +5 -0
- package/dist/types/init/creators/createSyncedThemeParams.d.ts +7 -0
- package/dist/types/init/creators/createViewport.d.ts +10 -0
- package/dist/types/init/creators/createWebApp.d.ts +14 -0
- package/dist/types/init/creators/index.d.ts +8 -0
- package/dist/types/init/css.d.ts +57 -0
- package/dist/types/init/index.d.ts +2 -0
- package/dist/types/init/init.d.ts +6 -0
- package/dist/types/init/types.d.ts +107 -0
- package/dist/types/launch-params.d.ts +20 -0
- package/dist/types/state/State.d.ts +15 -0
- package/dist/types/state/index.d.ts +2 -0
- package/dist/types/state/types.d.ts +30 -0
- package/dist/types/storage.d.ts +48 -0
- package/dist/types/supports.d.ts +22 -0
- package/dist/types/theme-params.d.ts +18 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/url.d.ts +7 -0
- package/package.json +67 -0
- package/src/components/BackButton/BackButton.ts +90 -0
- package/src/components/BackButton/index.ts +2 -0
- package/src/components/BackButton/types.ts +13 -0
- package/src/components/ClosingBehaviour/ClosingBehaviour.ts +62 -0
- package/src/components/ClosingBehaviour/index.ts +6 -0
- package/src/components/ClosingBehaviour/types.ts +12 -0
- package/src/components/CloudStorage/CloudStorage.ts +135 -0
- package/src/components/CloudStorage/index.ts +1 -0
- package/src/components/HapticFeedback/HapticFeedback.ts +62 -0
- package/src/components/HapticFeedback/index.ts +1 -0
- package/src/components/InitData/InitData.ts +116 -0
- package/src/components/InitData/index.ts +1 -0
- package/src/components/MainButton/MainButton.ts +243 -0
- package/src/components/MainButton/index.ts +2 -0
- package/src/components/MainButton/types.ts +20 -0
- package/src/components/Popup/Popup.ts +81 -0
- package/src/components/Popup/index.ts +8 -0
- package/src/components/Popup/types.ts +69 -0
- package/src/components/Popup/utils.ts +59 -0
- package/src/components/QRScanner/QRScanner.ts +87 -0
- package/src/components/QRScanner/index.ts +2 -0
- package/src/components/QRScanner/types.ts +11 -0
- package/src/components/ThemeParams/ThemeParams.ts +154 -0
- package/src/components/ThemeParams/index.ts +2 -0
- package/src/components/ThemeParams/types.ts +18 -0
- package/src/components/Viewport/Viewport.ts +197 -0
- package/src/components/Viewport/index.ts +2 -0
- package/src/components/Viewport/types.ts +14 -0
- package/src/components/WebApp/WebApp.ts +310 -0
- package/src/components/WebApp/index.ts +2 -0
- package/src/components/WebApp/types.ts +17 -0
- package/src/components/index.ts +11 -0
- package/src/env.ts +17 -0
- package/src/errors/MethodNotSupportedError.ts +9 -0
- package/src/errors/ParameterNotSupportedError.ts +9 -0
- package/src/errors/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/init/creators/createBackButton.ts +22 -0
- package/src/init/creators/createClosingBehavior.ts +22 -0
- package/src/init/creators/createMainButton.ts +56 -0
- package/src/init/creators/createPostEvent.ts +36 -0
- package/src/init/creators/createRequestIdGenerator.ts +13 -0
- package/src/init/creators/createSyncedThemeParams.ts +14 -0
- package/src/init/creators/createViewport.ts +50 -0
- package/src/init/creators/createWebApp.ts +49 -0
- package/src/init/creators/index.ts +8 -0
- package/src/init/css.ts +166 -0
- package/src/init/index.ts +2 -0
- package/src/init/init.ts +160 -0
- package/src/init/types.ts +133 -0
- package/src/launch-params.ts +70 -0
- package/src/state/State.ts +53 -0
- package/src/state/index.ts +2 -0
- package/src/state/types.ts +34 -0
- package/src/storage.ts +65 -0
- package/src/supports.ts +44 -0
- package/src/theme-params.ts +34 -0
- package/src/types.ts +28 -0
- package/src/url.ts +24 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type RequestOptions, type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
export interface RequestViewportResult {
|
|
3
|
+
height: number;
|
|
4
|
+
isStateStable: boolean;
|
|
5
|
+
isExpanded: boolean;
|
|
6
|
+
width: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Contains information about current WebApp device viewport, its dimensions
|
|
10
|
+
* and state.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Viewport {
|
|
13
|
+
private readonly postEvent;
|
|
14
|
+
/**
|
|
15
|
+
* Requests fresh information about current viewport.
|
|
16
|
+
* FIXME: Be careful using this function in desktop version of Telegram as
|
|
17
|
+
* long as method web_app_request_viewport does not work on `macos` platform.
|
|
18
|
+
* @see Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/5
|
|
19
|
+
* @param options - method options.
|
|
20
|
+
*/
|
|
21
|
+
static request(options?: RequestOptions): Promise<RequestViewportResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronizes specified instance of Viewport with the actual value in the native
|
|
24
|
+
* application.
|
|
25
|
+
* @param viewport - Viewport instance.
|
|
26
|
+
*/
|
|
27
|
+
static sync(viewport: Viewport): void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns initialized instance of Viewport which is synchronized with
|
|
30
|
+
* its actual state in Web Apps.
|
|
31
|
+
* @param options - method options.
|
|
32
|
+
*/
|
|
33
|
+
static synced(options?: RequestOptions): Promise<Viewport>;
|
|
34
|
+
private readonly ee;
|
|
35
|
+
private readonly state;
|
|
36
|
+
constructor(height: number, width: number, stableHeight: number, isExpanded: boolean, postEvent?: PostEvent);
|
|
37
|
+
/**
|
|
38
|
+
* The current height of the visible area of the Web App.
|
|
39
|
+
*
|
|
40
|
+
* The application can display just the top part of the Web App, with its
|
|
41
|
+
* lower part remaining outside the screen area. From this position, the
|
|
42
|
+
* user can "pull" the Web App to its maximum height, while the bot can do
|
|
43
|
+
* the same by calling `expand` method. As the position of the Web App
|
|
44
|
+
* changes, the current height value of the visible area will be updated
|
|
45
|
+
* in real time.
|
|
46
|
+
*
|
|
47
|
+
* Please note that the refresh rate of this value is not sufficient
|
|
48
|
+
* to smoothly follow the lower border of the window. It should not be
|
|
49
|
+
* used to pin interface elements to the bottom of the visible area. It's
|
|
50
|
+
* more appropriate to use the value of the `stableHeight`
|
|
51
|
+
* field for this purpose.
|
|
52
|
+
*
|
|
53
|
+
* @see init
|
|
54
|
+
* @see expand
|
|
55
|
+
* @see stableHeight
|
|
56
|
+
*/
|
|
57
|
+
get height(): number;
|
|
58
|
+
/**
|
|
59
|
+
* The height of the visible area of the Web App in its last stable state.
|
|
60
|
+
*
|
|
61
|
+
* The application can display just the top part of the Web App, with its
|
|
62
|
+
* lower part remaining outside the screen area. From this position,
|
|
63
|
+
* the user can "pull" the Web App to its maximum height, while the bot can
|
|
64
|
+
* do the same by calling `expand` method.
|
|
65
|
+
*
|
|
66
|
+
* Unlike the value of `height`, the value of `stableHeight`
|
|
67
|
+
* does not change as the position of the Web App changes with user
|
|
68
|
+
* gestures or during animations. The value of `stableHeight`
|
|
69
|
+
* will be updated after all gestures and animations are completed and
|
|
70
|
+
* the Web App reaches its final size.
|
|
71
|
+
*
|
|
72
|
+
* @see init
|
|
73
|
+
* @see expand
|
|
74
|
+
* @see height
|
|
75
|
+
*/
|
|
76
|
+
get stableHeight(): number;
|
|
77
|
+
/**
|
|
78
|
+
* Returns true if the Web App is expanded to the maximum available height.
|
|
79
|
+
* Otherwise, if the Web App occupies part of the screen and can be expanded
|
|
80
|
+
* to the full height using `expand` method.
|
|
81
|
+
* @see expand
|
|
82
|
+
*/
|
|
83
|
+
get isExpanded(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Current viewport width.
|
|
86
|
+
*/
|
|
87
|
+
get width(): number;
|
|
88
|
+
/**
|
|
89
|
+
* A method that expands the Web App to the maximum available height. To
|
|
90
|
+
* find out if the Web App is expanded to the maximum height, refer to the
|
|
91
|
+
* value of the `isExpanded`.
|
|
92
|
+
* @see isExpanded
|
|
93
|
+
*/
|
|
94
|
+
expand(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Returns true in case current viewport height is stable and is not going to
|
|
97
|
+
* change in the next moment.
|
|
98
|
+
*/
|
|
99
|
+
get isStable(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Adds new event listener.
|
|
102
|
+
*/
|
|
103
|
+
on: typeof this.ee.on;
|
|
104
|
+
/**
|
|
105
|
+
* Removes event listener.
|
|
106
|
+
*/
|
|
107
|
+
off: typeof this.ee.off;
|
|
108
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StateEvents } from '../../state/index.js';
|
|
2
|
+
export interface ViewportState {
|
|
3
|
+
height: number;
|
|
4
|
+
isExpanded: boolean;
|
|
5
|
+
stableHeight: number;
|
|
6
|
+
width: number;
|
|
7
|
+
}
|
|
8
|
+
export type ViewportEvents = StateEvents<ViewportState>;
|
|
9
|
+
export type ViewportEventName = keyof ViewportEvents;
|
|
10
|
+
export type ViewportEventListener<E extends ViewportEventName> = ViewportEvents[E];
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type Version } from '@tma.js/utils';
|
|
2
|
+
import { type RGB } from '@tma.js/colors';
|
|
3
|
+
import { type PhoneRequestedStatus, type WriteAccessRequestedStatus, type InvoiceStatus, type PostEvent } from '@tma.js/bridge';
|
|
4
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
5
|
+
import type { ColorScheme, Platform } from '../../types.js';
|
|
6
|
+
import type { WebAppEvents, WebAppHeaderColor } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Provides common Web Apps functionality not covered by other system
|
|
9
|
+
* components.
|
|
10
|
+
*/
|
|
11
|
+
export declare class WebApp {
|
|
12
|
+
private readonly currentVersion;
|
|
13
|
+
private readonly currentPlatform;
|
|
14
|
+
private readonly createRequestId;
|
|
15
|
+
private readonly postEvent;
|
|
16
|
+
private readonly ee;
|
|
17
|
+
private readonly state;
|
|
18
|
+
constructor(headerColor: WebAppHeaderColor, backgroundColor: RGB, currentVersion: Version, currentPlatform: Platform, createRequestId: () => string, postEvent?: PostEvent);
|
|
19
|
+
/**
|
|
20
|
+
* Returns current application background color.
|
|
21
|
+
*/
|
|
22
|
+
get backgroundColor(): RGB;
|
|
23
|
+
/**
|
|
24
|
+
* Returns current application color scheme. This value is
|
|
25
|
+
* computed based on the current background color.
|
|
26
|
+
*/
|
|
27
|
+
get colorScheme(): ColorScheme;
|
|
28
|
+
/**
|
|
29
|
+
* Closes the Web App.
|
|
30
|
+
*/
|
|
31
|
+
close(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Returns current application header color.
|
|
34
|
+
*/
|
|
35
|
+
get headerColor(): WebAppHeaderColor;
|
|
36
|
+
/**
|
|
37
|
+
* Returns true if passed version is more than or equal to current
|
|
38
|
+
* Web App version.
|
|
39
|
+
* @param version - compared version.
|
|
40
|
+
*/
|
|
41
|
+
isVersionAtLeast(version: Version): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Opens a link in an external browser. The Web App will not be closed.
|
|
44
|
+
*
|
|
45
|
+
* Note that this method can be called only in response to the user
|
|
46
|
+
* interaction with the Web App interface (e.g. click inside the Web App
|
|
47
|
+
* or on the main button).
|
|
48
|
+
* @param url - URL to be opened.
|
|
49
|
+
* @param tryInstantView
|
|
50
|
+
*/
|
|
51
|
+
openLink(url: string, tryInstantView?: boolean): void;
|
|
52
|
+
/**
|
|
53
|
+
* Opens a Telegram link inside Telegram app. The Web App will be closed.
|
|
54
|
+
* It expects passing link in full format, with hostname "t.me".
|
|
55
|
+
* @param url - URL to be opened.
|
|
56
|
+
* @throws {Error} URL has not allowed hostname.
|
|
57
|
+
*/
|
|
58
|
+
openTelegramLink(url: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Opens an invoice using its url. It expects passing link in full format,
|
|
61
|
+
* with hostname "t.me".
|
|
62
|
+
* @param url - invoice URL.
|
|
63
|
+
*/
|
|
64
|
+
openInvoice(url: string): Promise<InvoiceStatus>;
|
|
65
|
+
/**
|
|
66
|
+
* Adds new event listener.
|
|
67
|
+
*/
|
|
68
|
+
on: <E extends "changed" | "backgroundColorChanged" | "headerColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<WebAppEvents[E]>) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Removes event listener.
|
|
71
|
+
*/
|
|
72
|
+
off: <E extends "changed" | "backgroundColorChanged" | "headerColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<WebAppEvents[E]>) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns current Web App platform.
|
|
75
|
+
*/
|
|
76
|
+
get platform(): Platform;
|
|
77
|
+
/**
|
|
78
|
+
* Informs the Telegram app that the Web App is ready to be displayed.
|
|
79
|
+
*
|
|
80
|
+
* It is recommended to call this method as early as possible, as soon as
|
|
81
|
+
* all essential interface elements loaded. Once this method called,
|
|
82
|
+
* the loading placeholder is hidden and the Web App shown.
|
|
83
|
+
*
|
|
84
|
+
* If the method not called, the placeholder will be hidden only when
|
|
85
|
+
* the page fully loaded.
|
|
86
|
+
*/
|
|
87
|
+
ready(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Reads text from clipboard and returns string or null. null is returned
|
|
90
|
+
* in cases:
|
|
91
|
+
* - Value in clipboard is not text
|
|
92
|
+
* - Access to clipboard is not allowed
|
|
93
|
+
*/
|
|
94
|
+
readTextFromClipboard(): Promise<string | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Requests current user phone access.
|
|
97
|
+
*/
|
|
98
|
+
requestPhoneAccess(): Promise<PhoneRequestedStatus>;
|
|
99
|
+
/**
|
|
100
|
+
* Requests write message access to current user.
|
|
101
|
+
*/
|
|
102
|
+
requestWriteAccess(): Promise<WriteAccessRequestedStatus>;
|
|
103
|
+
/**
|
|
104
|
+
* A method used to send data to the bot. When this method called, a
|
|
105
|
+
* service message sent to the bot containing the data of the
|
|
106
|
+
* length up to 4096 bytes, and the Web App closed. See the field
|
|
107
|
+
* `web_app_data` in the class Message.
|
|
108
|
+
*
|
|
109
|
+
* This method is only available for Web Apps launched via a Keyboard button.
|
|
110
|
+
* @param data - data to send to bot.
|
|
111
|
+
* @throws {Error} data has incorrect size.
|
|
112
|
+
*/
|
|
113
|
+
sendData(data: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Updates current application header color.
|
|
116
|
+
* FIXME: Has no effect on desktop, works incorrectly on Android.
|
|
117
|
+
* Issues:
|
|
118
|
+
* https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
119
|
+
* https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
120
|
+
* @param color - color key or RGB color.
|
|
121
|
+
*/
|
|
122
|
+
setHeaderColor(color: WebAppHeaderColor): void;
|
|
123
|
+
/**
|
|
124
|
+
* Updates current application background color.
|
|
125
|
+
* FIXME: Has no effect on desktop, works incorrectly in Android.
|
|
126
|
+
* Issues:
|
|
127
|
+
* https://github.com/Telegram-Mini-Apps/tma.js/issues/9
|
|
128
|
+
* https://github.com/Telegram-Mini-Apps/tma.js/issues/8
|
|
129
|
+
* @param color - RGB color.
|
|
130
|
+
*/
|
|
131
|
+
setBackgroundColor(color: RGB): void;
|
|
132
|
+
/**
|
|
133
|
+
* Checks if specified method is supported by current component.
|
|
134
|
+
*/
|
|
135
|
+
supports: SupportsFunc<'openInvoice' | 'readTextFromClipboard' | 'setHeaderColor' | 'setBackgroundColor' | 'requestWriteAccess' | 'requestPhoneAccess'>;
|
|
136
|
+
/**
|
|
137
|
+
* Checks if specified method parameter is supported by current component.
|
|
138
|
+
*/
|
|
139
|
+
supportsParam: SupportsFunc<'setHeaderColor.color' | 'openLink.tryInstantView'>;
|
|
140
|
+
/**
|
|
141
|
+
* Current Web App version. This property is used by other components to check if
|
|
142
|
+
* some functionality is available on current device.
|
|
143
|
+
*/
|
|
144
|
+
get version(): Version;
|
|
145
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RGB } from '@tma.js/colors';
|
|
2
|
+
import type { HeaderColorKey } from '@tma.js/bridge';
|
|
3
|
+
import type { StateEvents } from '../../state/index.js';
|
|
4
|
+
export type WebAppHeaderColor = HeaderColorKey | RGB;
|
|
5
|
+
export interface WebAppState {
|
|
6
|
+
backgroundColor: RGB;
|
|
7
|
+
headerColor: WebAppHeaderColor;
|
|
8
|
+
}
|
|
9
|
+
export type WebAppEvents = StateEvents<WebAppState>;
|
|
10
|
+
export type WebAppEventName = keyof WebAppEvents;
|
|
11
|
+
export type WebAppEventListener<E extends WebAppEventName> = WebAppEvents[E];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './BackButton/index.js';
|
|
2
|
+
export * from './ClosingBehaviour/index.js';
|
|
3
|
+
export * from './CloudStorage/index.js';
|
|
4
|
+
export * from './HapticFeedback/index.js';
|
|
5
|
+
export * from './InitData/index.js';
|
|
6
|
+
export * from './MainButton/index.js';
|
|
7
|
+
export * from './Popup/index.js';
|
|
8
|
+
export * from './QRScanner/index.js';
|
|
9
|
+
export * from './ThemeParams/index.js';
|
|
10
|
+
export * from './Viewport/index.js';
|
|
11
|
+
export * from './WebApp/index.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true in case, current environment is Telegram Web Apps.
|
|
3
|
+
*
|
|
4
|
+
* `isTWA` utilizes such function as `retrieveLaunchParams`, which attempts to retrieve
|
|
5
|
+
* launch parameters from the current environment.
|
|
6
|
+
* @see retrieveLaunchParams
|
|
7
|
+
*/
|
|
8
|
+
export declare function isTWA(): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './components/index.js';
|
|
2
|
+
export { init, type InitResult, type InitOptions } from './init/index.js';
|
|
3
|
+
export { MethodNotSupportedError } from './errors/index.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './launch-params.js';
|
|
6
|
+
export * from './theme-params.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './url.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import { BackButton } from '../../components/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates BackButton instance using last locally saved data also saving each state in
|
|
5
|
+
* the storage.
|
|
6
|
+
* @param version - platform version.
|
|
7
|
+
* @param postEvent - Bridge postEvent function
|
|
8
|
+
*/
|
|
9
|
+
export declare function createBackButton(version: string, postEvent: PostEvent): BackButton;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import { ClosingBehaviour } from '../../components/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates ClosingBehaviour instance using last locally saved data also saving each state in
|
|
5
|
+
* the storage.
|
|
6
|
+
* @param postEvent - Bridge postEvent function
|
|
7
|
+
*/
|
|
8
|
+
export declare function createClosingBehavior(postEvent: PostEvent): ClosingBehaviour;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RGB } from '@tma.js/colors';
|
|
2
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
3
|
+
import { MainButton } from '../../components/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates MainButton instance using last locally saved data also saving each state in
|
|
6
|
+
* the storage.
|
|
7
|
+
* @param backgroundColor - background color.
|
|
8
|
+
* @param textColor - text color.
|
|
9
|
+
* @param postEvent - Bridge postEvent function
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMainButton(backgroundColor: RGB, textColor: RGB, postEvent: PostEvent): MainButton;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
/**
|
|
3
|
+
* Creates postEvent function.
|
|
4
|
+
* @param checkCompat - should compatibility check be enabled.
|
|
5
|
+
* @param version - platform version.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createPostEvent(checkCompat: boolean, version: string): PostEvent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ThemeParams } from '../../components/index.js';
|
|
2
|
+
import type { ThemeParamsType } from '../../theme-params.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates synced instance of ThemeParams.
|
|
5
|
+
* @param params - theme parameters.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSyncedThemeParams(params: ThemeParamsType): ThemeParams;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import { Viewport } from '../../components/index.js';
|
|
3
|
+
import type { Platform } from '../../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates Viewport instance using last locally saved data also saving each state in
|
|
6
|
+
* the storage.
|
|
7
|
+
* @param platform - Telegram Web Apps platform name.
|
|
8
|
+
* @param postEvent - Bridge postEvent function
|
|
9
|
+
*/
|
|
10
|
+
export declare function createViewport(platform: Platform, postEvent: PostEvent): Promise<Viewport>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RGB } from '@tma.js/colors';
|
|
2
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
3
|
+
import { WebApp } from '../../components/index.js';
|
|
4
|
+
import type { CreateRequestIdFunc, Platform } from '../../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates WebApp instance using last locally saved data also saving each state in
|
|
7
|
+
* the storage.
|
|
8
|
+
* @param backgroundColor - web app background color.
|
|
9
|
+
* @param version - platform version.
|
|
10
|
+
* @param platform - Telegram Web Apps platform name.
|
|
11
|
+
* @param createRequestId - function which generates request identifiers.
|
|
12
|
+
* @param postEvent - Bridge postEvent function
|
|
13
|
+
*/
|
|
14
|
+
export declare function createWebApp(backgroundColor: RGB, version: string, platform: Platform, createRequestId: CreateRequestIdFunc, postEvent: PostEvent): WebApp;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './createBackButton.js';
|
|
2
|
+
export * from './createClosingBehavior.js';
|
|
3
|
+
export * from './createMainButton.js';
|
|
4
|
+
export * from './createPostEvent.js';
|
|
5
|
+
export * from './createRequestIdGenerator.js';
|
|
6
|
+
export * from './createSyncedThemeParams.js';
|
|
7
|
+
export * from './createViewport.js';
|
|
8
|
+
export * from './createWebApp.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ThemeParams, WebApp, Viewport } from '../components/index.js';
|
|
2
|
+
import type { InitCSSVarsOption, InitCSSVarsSpecificOption } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates CSS variables connected with theme parameters.
|
|
5
|
+
*
|
|
6
|
+
* Created variables:
|
|
7
|
+
* - `--tg-theme-bg-color`
|
|
8
|
+
* - `--tg-theme-button-color`
|
|
9
|
+
* - `--tg-theme-button-text-color`
|
|
10
|
+
* - `--tg-theme-hint-color`
|
|
11
|
+
* - `--tg-theme-link-color`
|
|
12
|
+
* - `--tg-theme-secondary-bg-color`
|
|
13
|
+
* - `--tg-theme-text-color`
|
|
14
|
+
*
|
|
15
|
+
* Variables are being automatically updated in case, corresponding properties
|
|
16
|
+
* updated in passed ThemeParams instance.
|
|
17
|
+
*
|
|
18
|
+
* @param themeParams - ThemeParams instance.
|
|
19
|
+
*/
|
|
20
|
+
export declare function bindThemeCSSVariables(themeParams: ThemeParams): void;
|
|
21
|
+
/**
|
|
22
|
+
* Creates CSS variables connected with WebApp background and header colors based on
|
|
23
|
+
* passed WebApp and ThemeParams instances.
|
|
24
|
+
*
|
|
25
|
+
* Created variables:
|
|
26
|
+
* - `--tg-bg-color`
|
|
27
|
+
* - `--tg-header-color`
|
|
28
|
+
*
|
|
29
|
+
* Variables are being automatically updated in case, corresponding properties are updating.
|
|
30
|
+
*
|
|
31
|
+
* @param webApp - WebApp instance.
|
|
32
|
+
* @param themeParams - ThemeParams instance.
|
|
33
|
+
*/
|
|
34
|
+
export declare function bindWebAppVariables(webApp: WebApp, themeParams: ThemeParams): void;
|
|
35
|
+
/**
|
|
36
|
+
* Accepts Viewport instance and sets CSS variables connected with viewport
|
|
37
|
+
* sizes.
|
|
38
|
+
*
|
|
39
|
+
* Be careful using this function as long as it can impact application
|
|
40
|
+
* performance. Viewport size is changing rather often, this makes CSS
|
|
41
|
+
* variables update, which leads to possible layout redraw.
|
|
42
|
+
*
|
|
43
|
+
* Variables:
|
|
44
|
+
* - `--tg-viewport-height`
|
|
45
|
+
* - `--tg-viewport-stable-height`
|
|
46
|
+
*
|
|
47
|
+
* Variables are being automatically updated in case, corresponding properties
|
|
48
|
+
* updated in passed Viewport instance.
|
|
49
|
+
*
|
|
50
|
+
* @param viewport - Viewport instance.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bindViewportCSSVariables(viewport: Viewport): void;
|
|
53
|
+
/**
|
|
54
|
+
* Converts init cssVars option to more narrow type.
|
|
55
|
+
* @param option - option value.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseCSSVarsOptions(option: InitCSSVarsOption): InitCSSVarsSpecificOption;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import type { BackButton, ClosingBehaviour, CloudStorage, HapticFeedback, InitData, MainButton, Popup, QRScanner, ThemeParams, Viewport, WebApp } from '../components/index.js';
|
|
3
|
+
import type { LaunchParams } from '../launch-params.js';
|
|
4
|
+
export type InitResult = {
|
|
5
|
+
backButton: BackButton;
|
|
6
|
+
closingBehavior: ClosingBehaviour;
|
|
7
|
+
cloudStorage: CloudStorage;
|
|
8
|
+
haptic: HapticFeedback;
|
|
9
|
+
initData?: InitData;
|
|
10
|
+
initDataRaw?: string;
|
|
11
|
+
mainButton: MainButton;
|
|
12
|
+
popup: Popup;
|
|
13
|
+
postEvent: PostEvent;
|
|
14
|
+
qrScanner: QRScanner;
|
|
15
|
+
themeParams: ThemeParams;
|
|
16
|
+
viewport: Viewport;
|
|
17
|
+
webApp: WebApp;
|
|
18
|
+
};
|
|
19
|
+
export type InitCSSVarsSpecificOption = {
|
|
20
|
+
/**
|
|
21
|
+
* Enables theme parameters CSS variables:
|
|
22
|
+
* - `--tg-theme-bg-color`
|
|
23
|
+
* - `--tg-theme-button-color`
|
|
24
|
+
* - `--tg-theme-button-text-color`
|
|
25
|
+
* - `--tg-theme-hint-color`
|
|
26
|
+
* - `--tg-theme-link-color`
|
|
27
|
+
* - `--tg-theme-secondary-bg-color`
|
|
28
|
+
* - `--tg-theme-text-color`
|
|
29
|
+
*
|
|
30
|
+
* @see bindThemeCSSVariables
|
|
31
|
+
*/
|
|
32
|
+
themeParams?: true;
|
|
33
|
+
/**
|
|
34
|
+
* Enables viewport CSS variables:
|
|
35
|
+
* - `--tg-viewport-height`
|
|
36
|
+
* - `--tg-viewport-stable-height`
|
|
37
|
+
*
|
|
38
|
+
* @see bindViewportCSSVariables
|
|
39
|
+
*/
|
|
40
|
+
viewport?: true;
|
|
41
|
+
/**
|
|
42
|
+
* Enables web app CSS variables:
|
|
43
|
+
* - `--tg-bg-color`
|
|
44
|
+
* - `--tg-header-color`
|
|
45
|
+
*
|
|
46
|
+
* @see bindWebAppVariables
|
|
47
|
+
*/
|
|
48
|
+
webApp?: true;
|
|
49
|
+
};
|
|
50
|
+
export type InitCSSVarsOption = boolean | InitCSSVarsSpecificOption;
|
|
51
|
+
export interface InitOptions {
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use acceptCustomStyles
|
|
54
|
+
*/
|
|
55
|
+
acceptScrollbarStyle?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Should SDK accept styles sent from the Telegram web application.
|
|
58
|
+
* This option is only used in Web versions of Telegram.
|
|
59
|
+
*
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
acceptCustomStyles?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Should SDK throw an error in case, unsupported by current version of
|
|
65
|
+
* Web App method was called. It is highly recommended not to disable this
|
|
66
|
+
* feature as long as it helps developer to find issues related to usage
|
|
67
|
+
* of unsupported methods.
|
|
68
|
+
*
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
checkCompat?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Should SDK create global CSS variables related to current Telegram
|
|
74
|
+
* application colors.
|
|
75
|
+
*
|
|
76
|
+
* Possible values:
|
|
77
|
+
* - `false` - no CSS variables will be created.
|
|
78
|
+
* - `true` - all CSS variables will be created.
|
|
79
|
+
* - object - applies specific CSS variables.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
cssVars?: InitCSSVarsOption;
|
|
84
|
+
/**
|
|
85
|
+
* Enable debug mode.
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Launch parameters presented as query parameters or already parsed
|
|
92
|
+
* object. In case, this value is not specified, init
|
|
93
|
+
* function will try to retrieve launch parameters from window.location.hash
|
|
94
|
+
* via retrieveLaunchParams function.
|
|
95
|
+
*/
|
|
96
|
+
launchParams?: string | URLSearchParams | LaunchParams;
|
|
97
|
+
/**
|
|
98
|
+
* Sets new targetOrigin, used by bridge's `postEvent` function.
|
|
99
|
+
* @see setTargetOrigin
|
|
100
|
+
*/
|
|
101
|
+
targetOrigin?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Initialization process timeout.
|
|
104
|
+
* @default 1000
|
|
105
|
+
*/
|
|
106
|
+
timeout?: number;
|
|
107
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type InitData } from '@tma.js/init-data';
|
|
2
|
+
import { type ThemeParamsType } from './theme-params.js';
|
|
3
|
+
import type { Platform } from './types.js';
|
|
4
|
+
export interface LaunchParams {
|
|
5
|
+
version: string;
|
|
6
|
+
initData?: InitData;
|
|
7
|
+
initDataRaw?: string;
|
|
8
|
+
platform: Platform;
|
|
9
|
+
themeParams: ThemeParamsType;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses query parameters as launch parameters.
|
|
13
|
+
* @param query - query parameters presented as string or URLSearchParams
|
|
14
|
+
* instance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseLaunchParams(query: string | URLSearchParams): LaunchParams;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts launch params from the current environment.
|
|
19
|
+
*/
|
|
20
|
+
export declare function retrieveLaunchParams(): LaunchParams;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EventEmitter } from '@tma.js/event-emitter';
|
|
2
|
+
import type { StateEvents, StringKeys } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents state which is observable via passed EventEmitter.
|
|
5
|
+
*/
|
|
6
|
+
export declare class State<S extends object> {
|
|
7
|
+
private readonly state;
|
|
8
|
+
private readonly ee?;
|
|
9
|
+
constructor(state: S, ee?: EventEmitter<StateEvents<S>> | undefined);
|
|
10
|
+
private emit;
|
|
11
|
+
private internalSet;
|
|
12
|
+
set<K extends StringKeys<S>>(key: K, value: S[K]): void;
|
|
13
|
+
set(state: Partial<S>): void;
|
|
14
|
+
get<K extends StringKeys<S>>(key: K): Readonly<S[K]>;
|
|
15
|
+
}
|