@tma.js/sdk-react 2.1.1 → 2.1.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/dist/dts/SDKProvider/SDKProvider.types.d.ts +6 -3
- package/dist/dts/createHooks.d.ts +14 -16
- package/dist/dts/hooks-hocs/back-button.d.ts +2 -2
- package/dist/dts/hooks-hocs/biometry-manager.d.ts +2 -2
- package/dist/dts/hooks-hocs/closing-behavior.d.ts +2 -2
- package/dist/dts/hooks-hocs/cloud-storage.d.ts +2 -2
- package/dist/dts/hooks-hocs/haptic-feedback.d.ts +2 -2
- package/dist/dts/hooks-hocs/init-data.d.ts +2 -2
- package/dist/dts/hooks-hocs/invoice.d.ts +2 -8
- package/dist/dts/hooks-hocs/main-button.d.ts +2 -2
- package/dist/dts/hooks-hocs/mini-app.d.ts +2 -2
- package/dist/dts/hooks-hocs/popup.d.ts +2 -2
- package/dist/dts/hooks-hocs/qr-scanner.d.ts +2 -2
- package/dist/dts/hooks-hocs/settings-button.d.ts +2 -2
- package/dist/dts/hooks-hocs/theme-params.d.ts +2 -2
- package/dist/dts/hooks-hocs/utils.d.ts +2 -2
- package/dist/dts/hooks-hocs/viewport.d.ts +2 -2
- package/dist/dts/index.d.ts +15 -15
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +711 -687
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFn } from '@tma.js/sdk';
|
|
1
|
+
import { AnyFn, CleanupFn } from '@tma.js/sdk';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
4
|
export interface SDKProviderProps extends PropsWithChildren {
|
|
@@ -22,6 +22,10 @@ export type SDKContextItem<T> = ({
|
|
|
22
22
|
* This item execution result. The property may be missing in case, execution is async.
|
|
23
23
|
*/
|
|
24
24
|
result?: T;
|
|
25
|
+
/**
|
|
26
|
+
* Function to cleanup item side effects.
|
|
27
|
+
*/
|
|
28
|
+
cleanup?: CleanupFn;
|
|
25
29
|
} | {
|
|
26
30
|
/**
|
|
27
31
|
* An error occurred during execution.
|
|
@@ -33,7 +37,6 @@ export interface SDKContextType {
|
|
|
33
37
|
* Uses specified factory with the passed arguments. In case, this factory was called
|
|
34
38
|
* previously, a cached result will be returned.
|
|
35
39
|
* @param factory - factory function.
|
|
36
|
-
* @param args - factory arguments.
|
|
37
40
|
*/
|
|
38
|
-
use<Fn extends AnyFn>(factory: Fn
|
|
41
|
+
use<Fn extends AnyFn>(factory: Fn): SDKContextItem<Awaited<ReturnType<Fn>>>;
|
|
39
42
|
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { AnyFn } from '@tma.js/sdk';
|
|
1
|
+
import { CleanupFn, AnyFn } from '@tma.js/sdk';
|
|
2
2
|
import { SDKContextItem } from './SDKProvider/SDKProvider.types.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
(...args: Parameters<Fn>): SDKContextItem<HookFnResult<Fn>>;
|
|
4
|
+
type ExtractResult<T> = T extends [result: infer R, cleanup: CleanupFn] ? ExtractResult<R> : T extends Promise<infer U> ? U | undefined : T;
|
|
5
|
+
type HookFnResult<Fn extends AnyFn> = ExtractResult<ReturnType<Fn>>;
|
|
6
|
+
interface Hook<Result> {
|
|
7
|
+
(ssr?: false): Result;
|
|
8
|
+
(ssr: true): Result | undefined;
|
|
11
9
|
}
|
|
12
|
-
export interface
|
|
13
|
-
/**
|
|
14
|
-
* Hook, which retrieves a result of the factory.
|
|
15
|
-
* @throws An error, if factory execution was unsuccessful.
|
|
16
|
-
*/
|
|
17
|
-
(...args: Parameters<Fn>): HookFnResult<Fn>;
|
|
10
|
+
export interface HookRaw<Factory extends AnyFn> extends Hook<SDKContextItem<HookFnResult<Factory>>> {
|
|
18
11
|
}
|
|
19
|
-
export
|
|
12
|
+
export interface HookResult<Factory extends AnyFn> extends Hook<HookFnResult<Factory>> {
|
|
13
|
+
}
|
|
14
|
+
export type Hooks<Factory extends AnyFn> = [
|
|
15
|
+
useRaw: HookRaw<Factory>,
|
|
16
|
+
useResult: HookResult<Factory>
|
|
17
|
+
];
|
|
20
18
|
/**
|
|
21
19
|
* @returns Hooks, simplifying work process with the SDK components.
|
|
22
20
|
*/
|
|
23
|
-
export declare function createHooks<
|
|
21
|
+
export declare function createHooks<Factory extends AnyFn>(factory: Factory): Hooks<Factory>;
|
|
24
22
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useBackButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withBackButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useBackButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').BackButton>>, useBackButton: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').BackButton>>;
|
|
2
|
+
export declare const withBackButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').BackButton>>>, withBackButton: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').BackButton>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useBiometryManagerRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withBiometryManagerRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useBiometryManagerRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').BiometryManager>>>, useBiometryManager: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').BiometryManager>>>;
|
|
2
|
+
export declare const withBiometryManagerRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').BiometryManager>>>>, withBiometryManager: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').BiometryManager>>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useClosingBehaviorRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withClosingBehaviorRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useClosingBehaviorRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ClosingBehavior>>, useClosingBehavior: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ClosingBehavior>>;
|
|
2
|
+
export declare const withClosingBehaviorRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ClosingBehavior>>>, withClosingBehavior: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ClosingBehavior>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useCloudStorageRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withCloudStorageRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useCloudStorageRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').CloudStorage>>, useCloudStorage: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').CloudStorage>>;
|
|
2
|
+
export declare const withCloudStorageRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').CloudStorage>>>, withCloudStorage: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').CloudStorage>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useHapticFeedbackRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withHapticFeedbackRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useHapticFeedbackRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').HapticFeedback>>, useHapticFeedback: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').HapticFeedback>>;
|
|
2
|
+
export declare const withHapticFeedbackRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').HapticFeedback>>>, withHapticFeedback: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').HapticFeedback>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useInitDataRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withInitDataRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useInitDataRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').InitData | undefined>>, useInitData: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').InitData | undefined>>;
|
|
2
|
+
export declare const withInitDataRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').InitData | undefined>>>, withInitData: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').InitData | undefined>>>;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
export declare const useInvoiceRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitComponentFn<"version", import('@tma.js/sdk').Invoice, never>>, useInvoice: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitComponentFn<"version", import('@tma.js/sdk').Invoice, never>>;
|
|
5
|
-
/**
|
|
6
|
-
* HOC to pass the Invoice component instance to the wrapped component.
|
|
7
|
-
*/
|
|
8
|
-
export declare const withInvoiceRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitComponentFn<"version", import('@tma.js/sdk').Invoice, never>>>, withInvoice: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitComponentFn<"version", import('@tma.js/sdk').Invoice, never>>>;
|
|
1
|
+
export declare const useInvoiceRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Invoice>>, useInvoice: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Invoice>>;
|
|
2
|
+
export declare const withInvoiceRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Invoice>>>, withInvoice: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Invoice>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useMainButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withMainButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useMainButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MainButton>>, useMainButton: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MainButton>>;
|
|
2
|
+
export declare const withMainButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MainButton>>>, withMainButton: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MainButton>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useMiniAppRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withMiniAppRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useMiniAppRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MiniApp>>, useMiniApp: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MiniApp>>;
|
|
2
|
+
export declare const withMiniAppRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MiniApp>>>, withMiniApp: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').MiniApp>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const usePopupRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withPopupRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const usePopupRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Popup>>, usePopup: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Popup>>;
|
|
2
|
+
export declare const withPopupRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Popup>>>, withPopup: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Popup>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useQRScannerRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withQRScannerRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useQRScannerRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').QRScanner>>, useQRScanner: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').QRScanner>>;
|
|
2
|
+
export declare const withQRScannerRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').QRScanner>>>, withQRScanner: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').QRScanner>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useSettingsButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withSettingsButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useSettingsButtonRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').SettingsButton>>, useSettingsButton: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').SettingsButton>>;
|
|
2
|
+
export declare const withSettingsButtonRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').SettingsButton>>>, withSettingsButton: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').SettingsButton>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useThemeParamsRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withThemeParamsRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useThemeParamsRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ThemeParams>>, useThemeParams: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ThemeParams>>;
|
|
2
|
+
export declare const withThemeParamsRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ThemeParams>>>, withThemeParams: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<import('@tma.js/sdk').ThemeParams>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useUtilsRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withUtilsRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useUtilsRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Utils>>, useUtils: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Utils>>;
|
|
2
|
+
export declare const withUtilsRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Utils>>>, withUtils: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitStaticComponentFn<import('@tma.js/sdk').Utils>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useViewportRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
2
|
-
export declare const withViewportRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').
|
|
1
|
+
export declare const useViewportRaw: import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').Viewport>>>, useViewport: import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').Viewport>>>;
|
|
2
|
+
export declare const withViewportRaw: import('../createHOCs.js').HOC<import('../createHooks.js').HookRaw<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').Viewport>>>>, withViewport: import('../createHOCs.js').HOC<import('../createHooks.js').HookResult<import('@tma.js/sdk').InitDynamicComponentFn<Promise<import('@tma.js/sdk').Viewport>>>>;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export * from '@tma.js/sdk';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
2
|
+
export * from './hooks-hocs/back-button.js';
|
|
3
|
+
export * from './hooks-hocs/biometry-manager.js';
|
|
4
|
+
export * from './hooks-hocs/closing-behavior.js';
|
|
5
|
+
export * from './hooks-hocs/cloud-storage.js';
|
|
6
|
+
export * from './hooks-hocs/haptic-feedback.js';
|
|
7
|
+
export * from './hooks-hocs/init-data.js';
|
|
8
|
+
export * from './hooks-hocs/invoice.js';
|
|
9
|
+
export * from './hooks-hocs/main-button.js';
|
|
10
|
+
export * from './hooks-hocs/mini-app.js';
|
|
11
|
+
export * from './hooks-hocs/popup.js';
|
|
12
|
+
export * from './hooks-hocs/qr-scanner.js';
|
|
13
|
+
export * from './hooks-hocs/settings-button.js';
|
|
14
|
+
export * from './hooks-hocs/theme-params.js';
|
|
15
15
|
export { useLaunchParams } from './hooks-hocs/launch-params.js';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
16
|
+
export * from './hooks-hocs/utils.js';
|
|
17
|
+
export * from './hooks-hocs/viewport.js';
|
|
18
18
|
export { useSDK } from './SDKProvider/SDKContext.js';
|
|
19
19
|
export { SDKProvider } from './SDKProvider/SDKProvider.js';
|
|
20
20
|
export type { SDKContextType, SDKContextItem, SDKProviderProps, } from './SDKProvider/SDKProvider.types.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ot=require("react/jsx-runtime"),b=require("react");var Cs=Object.defineProperty,xs=(e,t,s)=>t in e?Cs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,h=(e,t,s)=>(xs(e,typeof t!="symbol"?t+"":t,s),s);function Dt(e,t){let s;const n=()=>{s!==void 0&&t&&t(s),s=void 0};return[()=>s===void 0?s=e(n):s,n]}function ot(e){const t=F(),{count:s}=t;t.unsubscribe(e),s&&!t.count&&$s()}function Mt(e){return F().subscribe(e),()=>ot(e)}class Ts{constructor(t,s={}){this.scope=t,this.options=s}print(t,...s){const n=new Date,i=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(n),{textColor:r,bgColor:o}=this.options,a="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${a};background-color: lightblue;color:black`,"",`${a};${r?`color:${r};`:""}${o?`background-color:${o}`:""}`,...s)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const G=new Ts("SDK",{bgColor:"forestgreen",textColor:"white"});let nt=!1;const It=({event:e,args:[t]})=>{G.log("Event received:",t===void 0?{name:e}:{name:e,data:t})};function Nt(e){nt!==e&&(nt=e,e?Mt(It):ot(It))}function ks(...e){nt&&G.log(...e)}class V{constructor(){h(this,"listeners",new Map),h(this,"listenersCount",0),h(this,"subscribeListeners",[])}clear(){this.listeners.clear(),this.subscribeListeners=[]}get count(){return this.listenersCount+this.subscribeListeners.length}emit(t,...s){this.subscribeListeners.forEach(n=>n({event:t,args:s})),(this.listeners.get(t)||[]).forEach(([n,i])=>{n(...s),i&&this.off(t,n)})}on(t,s,n){let i=this.listeners.get(t);return i||this.listeners.set(t,i=[]),i.push([s,n]),this.listenersCount+=1,()=>this.off(t,s)}off(t,s){const n=this.listeners.get(t)||[];for(let i=0;i<n.length;i+=1)if(s===n[i][0]){n.splice(i,1),this.listenersCount-=1;return}}subscribe(t){return this.subscribeListeners.push(t),()=>this.unsubscribe(t)}unsubscribe(t){for(let s=0;s<this.subscribeListeners.length;s+=1)if(this.subscribeListeners[s]===t){this.subscribeListeners.splice(s,1);return}}}function it(e,t,s){return window.addEventListener(e,t,s),()=>window.removeEventListener(e,t,s)}class $ extends Error{constructor(t,s,n){super(s,{cause:n}),this.type=t,Object.setPrototypeOf(this,$.prototype)}}function w(e,t,s){return new $(e,t,s)}const Vt="ERR_METHOD_UNSUPPORTED",$t="ERR_METHOD_PARAMETER_UNSUPPORTED",Lt="ERR_UNKNOWN_ENV",Ht="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Ut="ERR_TIMED_OUT",Wt="ERR_UNEXPECTED_TYPE",at="ERR_PARSE",jt="ERR_NAVIGATION_LIST_EMPTY",Gt="ERR_NAVIGATION_CURSOR_INVALID",Is="ERR_NAVIGATION_ITEM_INVALID",K="ERR_SSR_INIT",Kt="ERR_SSR_POST_EVENT",zt="ERR_INVALID_PATH_BASE";function A(){return w(Wt,"Value has unexpected type")}class z{constructor(t,s,n){this.parser=t,this.isOptional=s,this.type=n}parse(t){if(!(this.isOptional&&t===void 0))try{return this.parser(t)}catch(s){throw w(at,`Unable to parse value${this.type?` as ${this.type}`:""}`,s)}}optional(){return this.isOptional=!0,this}}function B(e,t){return()=>new z(e,!1,t)}const P=B(e=>{if(typeof e=="boolean")return e;const t=String(e);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;throw A()},"boolean");function Qt(e,t){const s={};for(const n in e){const i=e[n];if(!i)continue;let r,o;if(typeof i=="function"||"parse"in i)r=n,o=typeof i=="function"?i:i.parse.bind(i);else{const{type:a}=i;r=i.from||n,o=typeof a=="function"?a:a.parse.bind(a)}try{const a=o(t(r));a!==void 0&&(s[n]=a)}catch(a){throw w(at,`Unable to parse field "${n}"`,a)}}return s}function ht(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw A();return t}function l(e,t){return new z(s=>{const n=ht(s);return Qt(e,i=>n[i])},!1,t)}const C=B(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw A()},"number");function Q(e){return/^#[\da-f]{6}$/i.test(e)}function Ft(e){return/^#[\da-f]{3}$/i.test(e)}function ct(e){const t=e.replace(/\s/g,"").toLowerCase();if(Q(t))return t;if(Ft(t)){let n="#";for(let i=0;i<3;i+=1)n+=t[1+i].repeat(2);return n}const s=t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(!s)throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);return s.slice(1).reduce((n,i)=>{const r=parseInt(i,10).toString(16);return n+(r.length===1?"0":"")+r},"#")}const c=B(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw A()},"string"),ut=B(e=>ct(c().parse(e)),"rgb");function As(e){return l({eventType:c(),eventData:t=>t}).parse(e)}function Bs(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function qs(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Os(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=qs;return}s in t||(t[s]={}),t=t[s]})})}const Ds=l({button_id:e=>e==null?void 0:c().parse(e)}),Ms={clipboard_text_received:l({req_id:c(),data:e=>e===null?e:c().optional().parse(e)}),custom_method_invoked:l({req_id:c(),result:e=>e,error:c().optional()}),invoice_closed:l({slug:c(),status:c()}),phone_requested:l({status:c()}),popup_closed:{parse:e=>Ds.parse(e??{})},qr_text_received:l({data:c().optional()}),theme_changed:l({theme_params:e=>{const t=ut().optional();return Object.entries(ht(e)).reduce((s,[n,i])=>(s[n]=t.parse(i),s),{})}}),viewport_changed:l({height:C(),width:e=>e==null?window.innerWidth:C().parse(e),is_state_stable:P(),is_expanded:P()}),write_access_requested:l({status:c()})};function Ns(){const e=new V;Os();let t=[Bs,it("resize",()=>{e.emit("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),it("message",s=>{if(s.source!==window.parent)return;let n;try{n=As(s.data)}catch{return}const{eventType:i,eventData:r}=n,o=Ms[i];try{const a=o?o.parse(r):r;e.emit(...a?[i,a]:[i])}catch(a){G.error(`An error occurred processing the "${i}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,n,a)}}),()=>e.clear()];return[e,()=>{t.forEach(s=>s()),t=[]}]}const[Vs,$s]=Dt(e=>{const[t,s]=Ns(),n=t.off.bind(t);return t.off=(i,r)=>{const{count:o}=t;n(i,r),o&&!t.count&&e()},[t,s]},([,e])=>e());function F(){return Vs()[0]}function L(e,t){F().off(e,t)}function E(e,t,s){return F().on(e,t,s)}function H(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Jt(e,t){const s=e.split("."),n=t.split("."),i=Math.max(s.length,n.length);for(let r=0;r<i;r+=1){const o=parseInt(s[r]||"0",10),a=parseInt(n[r]||"0",10);if(o!==a)return o>a?1:-1}return 0}function R(e,t){return Jt(e,t)<=0}function x(e,t,s){if(typeof s=="string"){if(e==="web_app_open_link"&&t==="try_instant_view")return R("6.4",s);if(e==="web_app_set_header_color"&&t==="color")return R("6.9",s)}switch(e){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return R("6.1",t);case"web_app_open_popup":return R("6.2",t);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return R("6.4",t);case"web_app_switch_inline_query":return R("6.7",t);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return R("6.9",t);case"web_app_setup_settings_button":return R("6.10",t);case"web_app_biometry_get_info":case"web_app_biometry_open_settings":case"web_app_biometry_request_access":case"web_app_biometry_request_auth":case"web_app_biometry_update_token":return R("7.2",t);default:return["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"].includes(e)}}function Ls(e){return"external"in e&&H(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Yt(e){return"TelegramWebviewProxy"in e&&H(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function pt(){try{return window.self!==window.top}catch{return!0}}let Zt="https://web.telegram.org";function Hs(e){Zt=e}function Xt(){return Zt}function I(e,t,s){let n={},i;t===void 0&&s===void 0?n={}:t!==void 0&&s!==void 0?(n=s,i=t):t!==void 0&&("targetOrigin"in t?n=t:i=t);const{targetOrigin:r=Xt()}=n;if(ks("Posting event:",i?{event:e,data:i}:{event:e}),pt()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),r);return}if(Ls(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Yt(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw w(Lt,"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment.")}function te(e){return(t,s)=>{if(!x(t,e))throw w(Vt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(H(s)){let n;if(t==="web_app_open_link"&&"try_instant_view"in s?n="try_instant_view":t==="web_app_set_header_color"&&"color"in s&&(n="color"),n&&!x(t,n,e))throw w($t,`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return I(t,s)}}function dt(e){return({req_id:t})=>t===e}function ee(e){return w(Ut,`Timeout reached: ${e}ms`)}function lt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n(ee(t))},t)})])}async function _(e){let t;const s=new Promise(p=>{t=p}),{method:n,event:i,capture:r,postEvent:o=I,timeout:a}=e,u=(Array.isArray(i)?i:[i]).map(p=>E(p,d=>(!r||r(d))&&t(d)));try{return o(n,e.params),await(a?lt(s,a):s)}finally{u.forEach(p=>p())}}async function k(e,t,s,n={}){const{result:i,error:r}=await _({...n,method:"web_app_invoke_custom_method",event:"custom_method_invoked",params:{method:e,params:t,req_id:s},capture:dt(s)});if(r)throw w(Ht,r);return i}function j(...e){return e.map(t=>{if(typeof t=="string")return t;if(H(t))return j(Object.entries(t).map(s=>s[1]&&s[0]));if(Array.isArray(t))return j(...t)}).filter(Boolean).join(" ")}function Us(...e){return e.reduce((t,s)=>(H(s)&&Object.entries(s).forEach(([n,i])=>{const r=j(t[n],i);r.length&&(t[n]=r)}),t),{})}function _t(e){const t=ct(e);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const r=parseInt(t.slice(1+i*2,1+(i+1)*2),16);return s+r*r*n},0))<120}class Ws{constructor(t){h(this,"ee",new V),h(this,"on",this.ee.on.bind(this.ee)),h(this,"off",this.ee.off.bind(this.ee)),this.state=t}clone(){return{...this.state}}set(t,s){Object.entries(typeof t=="string"?{[t]:s}:t).reduce((n,[i,r])=>this.state[i]===r||r===void 0?n:(this.state[i]=r,this.ee.emit(`change:${i}`,r),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class wt{constructor(t){h(this,"state"),h(this,"get"),h(this,"set"),h(this,"clone"),this.state=new Ws(t),this.set=this.state.set.bind(this.state),this.get=this.state.get.bind(this.state),this.clone=this.state.clone.bind(this.state)}}function se(e,t){return s=>x(t[s],e)}class gt extends wt{constructor(t,s,n){super(t),h(this,"supports"),this.supports=se(s,n)}}class ne extends gt{constructor(t,s,n){super({isVisible:t},s,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"}),h(this,"on",(i,r)=>i==="click"?E("back_button_pressed",r):this.state.on(i,r)),h(this,"off",(i,r)=>i==="click"?L("back_button_pressed",r):this.state.off(i,r)),this.postEvent=n}set isVisible(t){this.set("isVisible",t),this.postEvent("web_app_setup_back_button",{is_visible:t})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function T(){return typeof window>"u"}const ft=B(e=>e instanceof Date?e:new Date(C().parse(e)*1e3),"Date");function J(e,t){return new z(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw A();const n=typeof s=="string"?new URLSearchParams(s):s;return Qt(e,i=>{const r=n.get(i);return r===null?void 0:r})},!1,t)}const js=l({id:C(),type:c(),title:c(),photoUrl:{type:c().optional(),from:"photo_url"},username:c().optional()},"Chat").optional(),At=l({addedToAttachmentMenu:{type:P().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:P().optional(),from:"allows_write_to_pm"},firstName:{type:c(),from:"first_name"},id:C(),isBot:{type:P().optional(),from:"is_bot"},isPremium:{type:P().optional(),from:"is_premium"},languageCode:{type:c().optional(),from:"language_code"},lastName:{type:c().optional(),from:"last_name"},photoUrl:{type:c().optional(),from:"photo_url"},username:c().optional()},"User").optional();function ie(){return J({authDate:{type:ft(),from:"auth_date"},canSendAfter:{type:C().optional(),from:"can_send_after"},chat:js,chatInstance:{type:c().optional(),from:"chat_instance"},chatType:{type:c().optional(),from:"chat_type"},hash:c(),queryId:{type:c().optional(),from:"query_id"},receiver:At,startParam:{type:c().optional(),from:"start_param"},user:At},"InitData")}function Gs(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Ks(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const re=B(e=>{const t=ut().optional();return Object.entries(ht(e)).reduce((s,[n,i])=>(s[Gs(n)]=t.parse(i),s),{})},"ThemeParams");function mt(e){return J({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:ie().optional(),from:"tgWebAppData"},initDataRaw:{type:c().optional(),from:"tgWebAppData"},platform:{type:c(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:c().optional(),from:"tgWebAppStartParam"},themeParams:{type:re(),from:"tgWebAppThemeParams"},version:{type:c(),from:"tgWebAppVersion"}}).parse(e)}function oe(e){return mt(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function zs(){return oe(window.location.href)}function ae(){return performance.getEntriesByType("navigation")[0]}function Qs(){const e=ae();if(!e)throw new Error("Unable to get first navigation entry.");return oe(e.name)}function he(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function ce(e,t){sessionStorage.setItem(he(e),JSON.stringify(t))}function ue(e){const t=sessionStorage.getItem(he(e));try{return t?JSON.parse(t):void 0}catch{}}function Fs(){return mt(ue("launchParams")||"")}function pe(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[Ks(t),s])))}function de(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:r,startParam:o,botInline:a}=e,u=new URLSearchParams;return u.set("tgWebAppPlatform",n),u.set("tgWebAppThemeParams",pe(s)),u.set("tgWebAppVersion",i),t&&u.set("tgWebAppData",t),o&&u.set("tgWebAppStartParam",o),typeof r=="boolean"&&u.set("tgWebAppShowSettings",r?"1":"0"),typeof a=="boolean"&&u.set("tgWebAppBotInline",a?"1":"0"),u.toString()}function Js(e){ce("launchParams",de(e))}function bt(){for(const e of[zs,Qs,Fs])try{const t=e();return Js(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function vt(){const e=ae();return!!(e&&e.type==="reload")}function Ys(){let e=0;return()=>(e+=1).toString()}const[Zs]=Dt(Ys);function g(e,t){return({ssr:s}={})=>{let n;if(T()){if(!s)throw w(K,"ssr.options must be specified to initialize component on the server side");n=s}else n=bt();const i={...n,postEvent:"version"in n?te(n.version):()=>{throw w(Kt,"postEvent function is forbidden to be called on the server side.")},createRequestId:Zs()};if(T()||typeof e=="function")return typeof e=="function"?e(i):t(i);const r=t({...i,state:vt()?ue(e):void 0}),o=a=>(a.on("change",u=>{ce(e,u)}),a);return r instanceof Promise?r.then(o):o(r)}}const le=g("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new ne(s.isVisible,t,e));class U extends gt{constructor(){super(...arguments),h(this,"on",this.state.on.bind(this.state)),h(this,"off",this.state.off.bind(this.state))}}function _e(e){const t=e.available?e:{available:!1,device_id:"",token_saved:!1,access_requested:!1,access_granted:!1,type:""};return{available:!0,type:t.type,deviceId:t.device_id,tokenSaved:t.token_saved,accessRequested:t.access_requested,accessGranted:t.access_granted}}class rt extends U{constructor({postEvent:t,version:s,...n}){super(n,s,{auth:"web_app_biometry_request_auth",openSettings:"web_app_biometry_open_settings",requestAccess:"web_app_biometry_request_access",updateToken:"web_app_biometry_update_token"}),h(this,"postEvent"),h(this,"authPromise"),h(this,"accessPromise"),this.postEvent=t}get available(){return this.get("available")}get accessGranted(){return this.get("accessGranted")}get accessRequested(){return this.get("accessRequested")}async authenticate({reason:t,...s}){return this.authPromise||(this.authPromise=_({...s,method:"web_app_biometry_request_auth",event:"biometry_auth_requested",postEvent:this.postEvent,params:{reason:(t||"").trim()}}).then(({token:n})=>n).finally(()=>this.authPromise=void 0)),this.authPromise}get deviceId(){return this.get("deviceId")}openSettings(){this.postEvent("web_app_biometry_open_settings")}requestAccess({reason:t,...s}={}){return this.accessPromise||(this.accessPromise=_({...s,postEvent:this.postEvent,method:"web_app_biometry_request_access",event:"biometry_info_received",params:{reason:t||""}}).then(n=>{const i=_e(n);return this.set(i),i.accessGranted}).finally(()=>this.accessPromise=void 0)),this.accessPromise}get biometryType(){return this.get("biometryType")}get tokenSaved(){return this.get("tokenSaved")}async updateToken({token:t,...s}={}){return["removed","updated"].includes((await _({...s,postEvent:this.postEvent,method:"web_app_biometry_update_token",event:"biometry_token_updated",params:{token:t||""}})).status)}}async function we(e){return _e(await _({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const ge=g("biometryManager",async({postEvent:e,version:t,state:s})=>{if(s)return new rt({...s,version:t,postEvent:e});if(T())throw w(K,"BiometryManager cannot be instantiated on the server side without passing the ssr.state object.");return new rt({...await we({timeout:1e3}),version:t,postEvent:e})});class yt extends wt{constructor(){super(...arguments),h(this,"on",this.state.on.bind(this.state)),h(this,"off",this.state.off.bind(this.state))}}class fe extends yt{constructor(t,s){super({isConfirmationNeeded:t}),this.postEvent=s}set isConfirmationNeeded(t){this.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const me=g("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new fe(t.isConfirmationNeeded,e));class Et{constructor(t,s){h(this,"supports"),this.supports=se(t,s)}}function Xs(e){if(Array.isArray(e))return e;if(typeof e=="string")try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch{}throw A()}class tn extends z{constructor(t,s,n){super(Xs,s,n),h(this,"itemParser"),this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function be(e){return new tn(t=>t,!1,e)}function Bt(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class ve extends Et{constructor(t,s,n){super(t,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"}),this.createRequestId=s,this.postEvent=n}async delete(t,s={}){const n=Array.isArray(t)?t:[t];n.length&&await k("deleteStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent})}async getKeys(t={}){return be().of(c()).parse(await k("getStorageKeys",{},this.createRequestId(),{...t,postEvent:this.postEvent}))}async get(t,s={}){const n=Array.isArray(t)?t:[t];if(!n.length)return Bt(n,"");const i=await k("getStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent}),r=l(Bt(n,c()),"CloudStorageData").parse(i);return Array.isArray(t)?r:r[t]}async set(t,s,n={}){await k("saveStorageValue",{key:t,value:s},this.createRequestId(),{...n,postEvent:this.postEvent})}}const ye=g(({createRequestId:e,postEvent:t,version:s})=>new ve(s,e,t));class Ee extends Et{constructor(t,s){super(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"}),this.postEvent=s}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"})}}const Re=g(({version:e,postEvent:t})=>new Ee(e,t));class Pe{constructor(t){this.initData=t}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:t}=this;return t?new Date(this.authDate.getTime()+t*1e3):void 0}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}const Se=g(({initData:e})=>e?new Pe(e):void 0);function en(e){return ie().parse(e)}class Ce extends U{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_invoice"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t,s){if(this.isOpened)throw new Error("Invoice is already opened");let n;if(!s)n=t;else{const{hostname:i,pathname:r}=new URL(t,window.location.href);if(i!=="t.me")throw new Error(`Incorrect hostname: ${i}`);const o=r.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!o)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,n]=o}this.isOpened=!0;try{return(await _({method:"web_app_open_invoice",event:"invoice_closed",params:{slug:n},postEvent:this.postEvent,capture(i){return n===i.slug}})).status}finally{this.isOpened=!1}}}const xe=g(({version:e,postEvent:t})=>new Ce(!1,e,t));class Te extends wt{constructor({postEvent:t,...s}){super(s),h(this,"postEvent"),h(this,"on",(n,i)=>n==="click"?E("main_button_pressed",i):this.state.on(n,i)),h(this,"off",(n,i)=>n==="click"?L("main_button_pressed",i):this.state.off(n,i)),this.postEvent=t}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(t){this.setParams({isEnabled:t})}get isEnabled(){return this.get("isEnabled")}set isLoaderVisible(t){this.setParams({isLoaderVisible:t})}get isLoaderVisible(){return this.get("isLoaderVisible")}set isVisible(t){this.setParams({isVisible:t})}get isVisible(){return this.get("isVisible")}get backgroundColor(){return this.get("backgroundColor")}get text(){return this.get("text")}get textColor(){return this.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(t){return this.setParams({text:t})}setTextColor(t){return this.setParams({textColor:t})}setBackgroundColor(t){return this.setParams({backgroundColor:t})}setParams(t){return this.set(t),this.commit(),this}}const ke=g("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",backgroundColor:t.buttonColor||"#000000"}})=>new Te({...s,postEvent:e}));function sn(){return J({contact:l({userId:{type:C(),from:"user_id"},phoneNumber:{type:c(),from:"phone_number"},firstName:{type:c(),from:"first_name"},lastName:{type:c().optional(),from:"last_name"}}),authDate:{type:ft(),from:"auth_date"},hash:c()},"RequestedContact")}function Ie(e,t){return s=>{const[n,i]=t[s];return x(n,i,e)}}function nn(e){return new Promise(t=>{setTimeout(t,e)})}class Ae extends U{constructor({postEvent:t,createRequestId:s,version:n,botInline:i,...r}){super(r,n,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"}),h(this,"botInline"),h(this,"postEvent"),h(this,"createRequestId"),h(this,"requestPhoneAccessPromise"),h(this,"requestWriteAccessPromise"),h(this,"supportsParam"),this.createRequestId=s,this.postEvent=t,this.botInline=i;const o=this.supports.bind(this);this.supports=a=>o(a)?a!=="switchInlineQuery"||i:!1,this.supportsParam=Ie(n,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:t=1e4}={}){return sn().parse(await k("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:t}))}get bgColor(){return this.get("bgColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return _t(this.bgColor)}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:t=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+t;let n=50;return lt(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await nn(n),n+=50}throw ee(t)},t)}async requestPhoneAccess(t={}){return this.requestPhoneAccessPromise||(this.requestPhoneAccessPromise=_({...t,method:"web_app_request_phone",event:"phone_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestPhoneAccessPromise=void 0)),this.requestPhoneAccessPromise}async requestWriteAccess(t={}){return this.requestWriteAccessPromise||(this.requestWriteAccessPromise=_({...t,method:"web_app_request_write_access",event:"write_access_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestWriteAccessPromise=void 0)),this.requestWriteAccessPromise}sendData(t){const{size:s}=new Blob([t]);if(!s||s>4096)throw new Error(`Passed data has incorrect size: ${s}`);this.postEvent("web_app_data_send",{data:t})}setHeaderColor(t){this.postEvent("web_app_set_header_color",Q(t)?{color:t}:{color_key:t}),this.set("headerColor",t)}setBgColor(t){this.postEvent("web_app_set_background_color",{color:t}),this.set("bgColor",t)}switchInlineQuery(t,s=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:t,chat_types:s})}}const Be=g("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new Ae({...n,...s,botInline:t}));function rn(e){const t=e.message.trim(),s=(e.title||"").trim(),n=e.buttons||[];let i;if(s.length>64)throw new Error(`Title has incorrect size: ${s.length}`);if(!t.length||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?i=n.map(r=>{const{id:o=""}=r;if(o.length>64)throw new Error(`Button ID has incorrect size: ${o}`);if(!r.type||r.type==="default"||r.type==="destructive"){const a=r.text.trim();if(!a.length||a.length>64){const u=r.type||"default";throw new Error(`Button text with type "${u}" has incorrect size: ${r.text.length}`)}return{...r,text:a,id:o}}return{...r,id:o}}):i=[{type:"close",id:""}],{title:s,message:t,buttons:i}}class qe extends U{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_popup"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.isOpened=!0;try{const{button_id:s=null}=await _({event:"popup_closed",method:"web_app_open_popup",postEvent:this.postEvent,params:rn(t)});return s}finally{this.isOpened=!1}}}const Oe=g(({postEvent:e,version:t})=>new qe(!1,t,e));class De extends U{constructor(t,s,n){super({isOpened:t},s,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"}),this.postEvent=n}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{return(await _({method:"web_app_open_scan_qr_popup",event:["qr_text_received","scan_qr_popup_closed"],postEvent:this.postEvent,params:{text:t}})||{}).data||null}finally{this.isOpened=!1}}}const Me=g(({version:e,postEvent:t})=>new De(!1,e,t));class Ne extends gt{constructor(t,s,n){super({isVisible:t},s,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"}),h(this,"on",(i,r)=>i==="click"?E("settings_button_pressed",r):this.state.on(i,r)),h(this,"off",(i,r)=>i==="click"?L("settings_button_pressed",r):this.state.off(i,r)),this.postEvent=n}set isVisible(t){this.set("isVisible",t),this.postEvent("web_app_setup_settings_button",{is_visible:t})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const Ve=g("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new Ne(s.isVisible,e,t));function Rt(e){return re().parse(e)}class $e extends yt{get accentTextColor(){return this.get("accentTextColor")}get bgColor(){return this.get("bgColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}getState(){return this.clone()}get headerBgColor(){return this.get("headerBgColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.bgColor||_t(this.bgColor)}get linkColor(){return this.get("linkColor")}get secondaryBgColor(){return this.get("secondaryBgColor")}get sectionBgColor(){return this.get("sectionBgColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return E("theme_changed",t=>{this.set(Rt(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const Le=g("themeParams",({themeParams:e,state:t=e})=>{const s=new $e(t);return T()||s.listen(),s});function on(e={}){return _({...e,method:"web_app_request_theme",event:"theme_changed"}).then(Rt)}class He extends Et{constructor(t,s,n){super(t,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),h(this,"supportsParam"),this.version=t,this.createRequestId=s,this.postEvent=n,this.supportsParam=Ie(t,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(t,s){const n=new URL(t,window.location.href).toString();if(!x("web_app_open_link",this.version)){window.open(n,"_blank");return}this.postEvent("web_app_open_link",{url:n,...typeof s=="boolean"?{try_instant_view:s}:{}})}openTelegramLink(t){const{hostname:s,pathname:n,search:i}=new URL(t,window.location.href);if(s!=="t.me")throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);if(!x("web_app_open_tg_link",this.version)){window.location.href=t;return}this.postEvent("web_app_open_tg_link",{path_full:n+i})}async readTextFromClipboard(){const t=this.createRequestId(),{data:s=null}=await _({method:"web_app_read_text_from_clipboard",event:"clipboard_text_received",postEvent:this.postEvent,params:{req_id:t},capture:dt(t)});return s}}const Ue=g(({version:e,postEvent:t,createRequestId:s})=>new He(e,s,t));async function Pt(e={}){const{is_expanded:t,is_state_stable:s,...n}=await _({...e,method:"web_app_request_viewport",event:"viewport_changed"});return{...n,isExpanded:t,isStateStable:s}}function q(e){return e<0?0:e}class St extends yt{constructor({postEvent:t,stableHeight:s,height:n,width:i,isExpanded:r}){super({height:q(n),isExpanded:r,stableHeight:q(s),width:q(i)}),h(this,"postEvent"),this.postEvent=t}async sync(t){const{isStateStable:s,...n}=await Pt(t);this.set({...n,stableHeight:s?n.height:this.get("stableHeight")})}get height(){return this.get("height")}get stableHeight(){return this.get("stableHeight")}listen(){return E("viewport_changed",t=>{const{height:s,width:n,is_expanded:i,is_state_stable:r}=t,o=q(s);this.set({height:o,isExpanded:i,width:q(n),...r?{stableHeight:o}:{}})})}get isExpanded(){return this.get("isExpanded")}get width(){return this.get("width")}expand(){this.postEvent("web_app_expand"),this.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}async function an(e,t={}){const{height:s,width:n,isExpanded:i,isStateStable:r}=await Pt({...t,postEvent:e});return new St({postEvent:e,height:s,width:n,isExpanded:i,stableHeight:r?s:0})}function hn({state:e,platform:t,postEvent:s}){let n=!1,i=0,r=0,o=0;return e?(n=e.isExpanded,i=e.height,r=e.width,o=e.stableHeight):["macos","tdesktop","unigram","webk","weba","web"].includes(t)&&(n=!0,i=window.innerHeight,r=window.innerWidth,o=window.innerHeight),new St({postEvent:s,height:i,width:r,stableHeight:o,isExpanded:n})}const We=g("viewport",async e=>{if(T()&&!e.state)throw w(K,"Viewport cannot be instantiated on the server side without passing the ssr.state object.");let t=hn(e);return T()||(t.width===0&&await an(e.postEvent,{timeout:1e3}).then(s=>t=s).catch(s=>G.error("Unable to sync viewport state",s)),t.listen()),t});function S(e,t){document.documentElement.style.setProperty(e,t)}function cn(e,t,s){s||(s=a=>`--tg-${a}-color`);const n=s("header"),i=s("bg"),r=()=>{const{headerColor:a}=e;if(Q(a))S(n,a);else{const{bgColor:u,secondaryBgColor:p}=t;a==="bg_color"&&u?S(n,u):a==="secondary_bg_color"&&p&&S(n,p)}S(i,e.bgColor)},o=[t.on("change",r),e.on("change",r)];return r(),()=>o.forEach(a=>a())}function un(e,t){t||(t=n=>`--tg-theme-${n.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`);const s=()=>{Object.entries(e.getState()).forEach(([n,i])=>{i&&S(t(n),i)})};return s(),e.on("change",s)}function pn(e,t){t||(t=p=>`--tg-viewport-${p}`);const[s,n,i]=["height","width","stable-height"].map(p=>t(p)),r=()=>S(s,`${e.height}px`),o=()=>S(n,`${e.width}px`),a=()=>S(i,`${e.stableHeight}px`),u=[e.on("change:height",r),e.on("change:width",o),e.on("change:stableHeight",a)];return r(),o(),a(),()=>u.forEach(p=>p())}function je(e=!0){const t=[E("reload_iframe",()=>{I("iframe_will_reload"),window.location.reload()})],s=()=>t.forEach(n=>n());if(e){const n=document.createElement("style");n.id="telegram-custom-styles",document.head.appendChild(n),t.push(E("set_custom_style",i=>{n.innerHTML=i}),()=>document.head.removeChild(n))}return I("iframe_ready",{reload_supported:!0}),s}async function dn(){if(Yt(window))return!0;try{return await _({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function Ge(e){return e instanceof $}function ln(e,t){return Ge(e)&&e.type===t}function Z(e,t){let s,n,i;return typeof e=="string"?s=e:(s=e.pathname===void 0?t:e.pathname,n=e.params,i=e.id),Object.freeze({id:i||(Math.random()*2**14|0).toString(16),pathname:s,params:n})}class Ke{constructor(t,s,n=I){if(h(this,"history"),h(this,"ee",new V),h(this,"attached",!1),h(this,"back",()=>this.go(-1)),h(this,"on",this.ee.on.bind(this.ee)),h(this,"off",this.ee.off.bind(this.ee)),this._index=s,this.postEvent=n,t.length===0)throw w(jt,"History should not be empty.");if(s<0||s>=t.length)throw w(Gt,"Index should not be zero and higher or equal than history size.");this.history=t.map(i=>Z(i,""))}attach(){this.attached||(this.attached=!0,this.sync(),E("back_button_pressed",this.back))}get current(){return this.history[this.index]}detach(){this.attached=!1,L("back_button_pressed",this.back)}forward(){this.go(1)}go(t,s){const n=this.index+t,i=Math.min(Math.max(0,n),this.history.length-1);(n===i||s)&&this.replaceAndMove(i,this.history[i])}goTo(t,s){this.go(t-this.index,s)}get hasPrev(){return this.index>0}get hasNext(){return this.index!==this.history.length-1}get index(){return this._index}push(t){this.hasNext&&this.history.splice(this.index+1),this.replaceAndMove(this.index+1,Z(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,Z(t,this.current.pathname))}replaceAndMove(t,s){const n=t-this.index;if(!n&&this.current===s)return;const i=this.current;if(this.index!==t){const r=this._index;this._index=t,this.attached&&r>0!=t>0&&this.sync()}this.history[t]=s,this.ee.emit("change",{navigator:this,from:i,to:this.current,delta:n})}sync(){this.postEvent("web_app_setup_back_button",{is_visible:!!this.index})}}function X({params:e,...t}){return{...e||{hash:"",search:""},...t}}function D(e,t){return e.startsWith(t)?e:`${t}${e}`}function M(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${D(e.search||"","?")}${D(e.hash||"","#")}`,"http://a")}function N(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=M(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function tt(e,t,s){let n,i;typeof e=="string"?n=e:(n=N(e),s=e.state,i=e.id);const{pathname:r,search:o,hash:a}=new URL(n,`http://a${D(t,"/")}`);return{id:i,pathname:r,params:{hash:a,search:o,state:s}}}async function O(e){return e===0?!0:Promise.race([new Promise(t=>{const s=it("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function _n(){if(window.history.length<=1||(window.history.pushState(null,""),await O(1-window.history.length)))return;let e=await O(-1);for(;e;)e=await O(-1)}function Ct(e){return M(e).pathname}const qt=0,et=1,st=2;class xt{constructor(t,s,{postEvent:n,hashMode:i,base:r}={}){h(this,"navigator"),h(this,"ee",new V),h(this,"hashMode"),h(this,"base"),h(this,"attached",!1),h(this,"onPopState",({state:o})=>{if(o===null)return this.push(this.parsePath(window.location.href));o===qt?window.history.forward():o===et&&this.back(),o===st&&this.forward()}),h(this,"onNavigatorChange",async({to:o,from:a,delta:u})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:u,from:X(a),to:X(o),navigator:this})}),h(this,"on",this.ee.on.bind(this.ee)),h(this,"off",this.ee.off.bind(this.ee)),this.navigator=new Ke(t.map(o=>tt(o,"/")),s,n),this.navigator.on("change",this.onNavigatorChange),this.hashMode=i,this.base=Ct(r||"")}async attach(){this.attached||(this.attached=!0,this.navigator.attach(),window.addEventListener("popstate",this.onPopState),await this.syncHistory())}back(){this.navigator.back()}detach(){this.attached=!1,this.navigator.detach(),window.removeEventListener("popstate",this.onPopState)}forward(){return this.navigator.forward()}get index(){return this.navigator.index}get id(){return this.navigator.current.id}go(t,s){return this.navigator.go(t,s)}goTo(t,s){this.navigator.goTo(t,s)}get hash(){return(this.navigator.current.params||{}).hash||""}get hasPrev(){return this.navigator.hasPrev}get hasNext(){return this.navigator.hasNext}get history(){return this.navigator.history.map(X)}get path(){return N(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=M(t);return this.hashMode&&(s=M(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=tt(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=tt(t,this.path),{state:i=s}=n.params;this.navigator.replace({...n,params:{...n.params,state:i}})}renderPath(t){const s=(this.base.length===1?"":this.base)+D(N(t),"/");return this.hashMode?D(s.slice(1),this.hashMode==="default"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await _n(),this.hasPrev&&this.hasNext?(window.history.replaceState(et,""),window.history.pushState(t,"",s),window.history.pushState(st,""),await O(-1)):this.hasPrev?(window.history.replaceState(et,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(st,""),await O(-1)):(window.history.replaceState(qt,""),window.history.pushState(t,"",s)),window.addEventListener("popstate",this.onPopState)}get search(){return(this.navigator.current.params||{}).search||""}get state(){return(this.navigator.current.params||{}).state}}function ze(e){e||(e={});const{href:t,hash:s}=window.location;let n=N(e.hashMode?s.includes("?")?s.slice(1):`?${s.slice(1)}`:t);const i=e.base?Ct(e.base):void 0;if(i){if(!n.startsWith(i))throw w(zt,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new xt([n],0,e)}function wn(e){const t=e.match(/#(.+)/);return t?t[1]:null}function gn(e,t){if(vt()){const s=sessionStorage.getItem(e);if(s)try{const{index:n,history:i}=JSON.parse(s);return new xt(i,n,t)}catch(n){console.error("Unable to restore hash navigator state.",n)}}return ze(t)}function fn(e,t){const s=gn(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}function f(e,t){function s(n){return(i,r,o)=>a=>{const u=a[r]||[],p={...a,[i]:n(...u)};return Ot.jsx(o,{...p})}}return[s(e),s(t)]}const Qe=b.createContext(void 0);function Fe(){const e=b.useContext(Qe);if(!e)throw new Error("useSDK was used outside the SDKProvider.");return e}function m(e){const t=(...n)=>{const i=Fe();return b.useMemo(()=>i.use(e,...n),[i])};return[t,(...n)=>{const i=t(...n);if("error"in i)throw i.error;return i.result}]}const[Je,Ye]=m(le),[mn,bn]=f(Je,Ye),[Ze,Xe]=m(ge),[vn,yn]=f(Ze,Xe),[ts,es]=m(me),[En,Rn]=f(ts,es),[ss,ns]=m(ye),[Pn,Sn]=f(ss,ns),[is,rs]=m(Re),[Cn,xn]=f(is,rs),[os,as]=m(Se),[Tn,kn]=f(os,as),[hs,cs]=m(xe),[In,An]=f(hs,cs),[us,ps]=m(ke),[Bn,qn]=f(us,ps),[ds,ls]=m(Be),[On,Dn]=f(ds,ls),[_s,ws]=m(Oe),[Mn,Nn]=f(_s,ws),[gs,fs]=m(Me),[Vn,$n]=f(gs,fs),[ms,bs]=m(Ve),[Ln,Hn]=f(ms,bs),[vs,ys]=m(Le),[Un,Wn]=f(vs,ys);function jn(){return b.useMemo(bt,[])}const[Es,Rs]=m(Ue),[Gn,Kn]=f(Es,Rs),[Ps,Ss]=m(We),[zn,Qn]=f(Ps,Ss);function Fn({children:e,acceptCustomStyles:t,debug:s}){const n=b.useRef(!0),[i,r]=b.useState(()=>new Map),o=b.useCallback(d=>{n.current&&r(W=>(d&&d(W),new Map(W)))},[]),a=b.useCallback(()=>o(),[o]),u=b.useRef([]),p=b.useMemo(()=>({use(d,...W){const Tt=i.get(d);if(Tt)return Tt;let v;try{v={result:d(...W)}}catch(y){v={error:y}}if("error"in v||!v.result)return i.set(d,v),v;const kt=y=>("on"in y&&(y.on("change",a),u.current.push(y)),{result:y});return v.result instanceof Promise?(v.result.then(y=>o(Y=>Y.set(d,kt(y))),y=>o(Y=>Y.set(d,{error:y}))),i.set(d,{}),{}):(i.set(d,v=kt(v.result)),v)}}),[i]);return b.useEffect(()=>{Nt(s||!1)},[s]),b.useEffect(()=>()=>{n.current=!1},[]),b.useEffect(()=>{if(pt())return je(t)},[t]),b.useEffect(()=>()=>u.current.forEach(d=>d.off("change",a)),[a]),Ot.jsx(Qe.Provider,{value:p,children:e})}exports.BackButton=ne;exports.BasicNavigator=Ke;exports.BiometryManager=rt;exports.BrowserNavigator=xt;exports.ClosingBehavior=fe;exports.CloudStorage=ve;exports.ERR_INVALID_PATH_BASE=zt;exports.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Ht;exports.ERR_METHOD_PARAMETER_UNSUPPORTED=$t;exports.ERR_METHOD_UNSUPPORTED=Vt;exports.ERR_NAVIGATION_HISTORY_EMPTY=jt;exports.ERR_NAVIGATION_INDEX_INVALID=Gt;exports.ERR_NAVIGATION_ITEM_INVALID=Is;exports.ERR_PARSE=at;exports.ERR_SSR_INIT=K;exports.ERR_SSR_POST_EVENT=Kt;exports.ERR_TIMED_OUT=Ut;exports.ERR_UNEXPECTED_TYPE=Wt;exports.ERR_UNKNOWN_ENV=Lt;exports.EventEmitter=V;exports.HapticFeedback=Ee;exports.InitData=Pe;exports.Invoice=Ce;exports.MainButton=Te;exports.MiniApp=Ae;exports.Popup=qe;exports.QRScanner=De;exports.SDKError=$;exports.SDKProvider=Fn;exports.SettingsButton=Ne;exports.ThemeParams=$e;exports.Utils=He;exports.Viewport=St;exports.array=be;exports.bindMiniAppCSSVars=cn;exports.bindThemeParamsCSSVars=un;exports.bindViewportCSSVars=pn;exports.boolean=P;exports.captureSameReq=dt;exports.classNames=j;exports.compareVersions=Jt;exports.createBrowserNavigatorFromLocation=ze;exports.createPostEvent=te;exports.createSafeURL=M;exports.date=ft;exports.getHash=wn;exports.getPathname=Ct;exports.initBackButton=le;exports.initBiometryManager=ge;exports.initClosingBehavior=me;exports.initCloudStorage=ye;exports.initHapticFeedback=Re;exports.initInitData=Se;exports.initInvoice=xe;exports.initMainButton=ke;exports.initMiniApp=Be;exports.initNavigator=fn;exports.initPopup=Oe;exports.initQRScanner=Me;exports.initSettingsButton=Ve;exports.initThemeParams=Le;exports.initUtils=Ue;exports.initViewport=We;exports.initWeb=je;exports.invokeCustomMethod=k;exports.isColorDark=_t;exports.isIframe=pt;exports.isPageReload=vt;exports.isRGB=Q;exports.isRGBShort=Ft;exports.isSDKError=Ge;exports.isSDKErrorOfType=ln;exports.isSSR=T;exports.isTMA=dn;exports.json=l;exports.mergeClassNames=Us;exports.number=C;exports.off=L;exports.on=E;exports.parseInitData=en;exports.parseLaunchParams=mt;exports.parseThemeParams=Rt;exports.postEvent=I;exports.request=_;exports.requestBiometryInfo=we;exports.requestThemeParams=on;exports.requestViewport=Pt;exports.retrieveLaunchParams=bt;exports.rgb=ut;exports.searchParams=J;exports.serializeLaunchParams=de;exports.serializeThemeParams=pe;exports.setCSSVar=S;exports.setDebug=Nt;exports.setTargetOrigin=Hs;exports.string=c;exports.subscribe=Mt;exports.supports=x;exports.targetOrigin=Xt;exports.toRGB=ct;exports.unsubscribe=ot;exports.urlToPath=N;exports.useBackButton=Ye;exports.useBackButtonRaw=Je;exports.useBiometryManager=Xe;exports.useBiometryManagerRaw=Ze;exports.useClosingBehavior=es;exports.useClosingBehaviorRaw=ts;exports.useCloudStorage=ns;exports.useCloudStorageRaw=ss;exports.useHapticFeedback=rs;exports.useHapticFeedbackRaw=is;exports.useInitData=as;exports.useInitDataRaw=os;exports.useInvoice=cs;exports.useInvoiceRaw=hs;exports.useLaunchParams=jn;exports.useMainButton=ps;exports.useMainButtonRaw=us;exports.useMiniApp=ls;exports.useMiniAppRaw=ds;exports.usePopup=ws;exports.usePopupRaw=_s;exports.useQRScanner=fs;exports.useQRScannerRaw=gs;exports.useSDK=Fe;exports.useSettingsButton=bs;exports.useSettingsButtonRaw=ms;exports.useThemeParams=ys;exports.useThemeParamsRaw=vs;exports.useUtils=Rs;exports.useUtilsRaw=Es;exports.useViewport=Ss;exports.useViewportRaw=Ps;exports.withBackButton=bn;exports.withBackButtonRaw=mn;exports.withBiometryManager=yn;exports.withBiometryManagerRaw=vn;exports.withClosingBehavior=Rn;exports.withClosingBehaviorRaw=En;exports.withCloudStorage=Sn;exports.withCloudStorageRaw=Pn;exports.withHapticFeedback=xn;exports.withHapticFeedbackRaw=Cn;exports.withInitData=kn;exports.withInitDataRaw=Tn;exports.withInvoice=An;exports.withInvoiceRaw=In;exports.withMainButton=qn;exports.withMainButtonRaw=Bn;exports.withMiniApp=Dn;exports.withMiniAppRaw=On;exports.withPopup=Nn;exports.withPopupRaw=Mn;exports.withQRScanner=$n;exports.withQRScannerRaw=Vn;exports.withSettingsButton=Hn;exports.withSettingsButtonRaw=Ln;exports.withThemeParams=Wn;exports.withThemeParamsRaw=Un;exports.withTimeout=lt;exports.withUtils=Kn;exports.withUtilsRaw=Gn;exports.withViewport=Qn;exports.withViewportRaw=zn;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ot=require("react/jsx-runtime"),d=require("react");var ks=Object.defineProperty,Is=(e,t,s)=>t in e?ks(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t,s)=>(Is(e,typeof t!="symbol"?t+"":t,s),s);function Dt(e,t){let s;const n=()=>{s!==void 0&&t&&t(s),s=void 0};return[()=>s===void 0?s=e(n):s,n]}function it(e){const t=Q(),{count:s}=t;t.unsubscribe(e),s&&!t.count&&Ws()}function Mt(e){return Q().subscribe(e),()=>it(e)}class As{constructor(t,s={}){this.scope=t,this.options=s}print(t,...s){const n=new Date,i=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(n),{textColor:r,bgColor:a}=this.options,o="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${o};background-color: lightblue;color:black`,"",`${o};${r?`color:${r};`:""}${a?`background-color:${a}`:""}`,...s)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const rt=new As("SDK",{bgColor:"forestgreen",textColor:"white"});let st=!1;const It=({event:e,args:[t]})=>{rt.log("Event received:",t===void 0?{name:e}:{name:e,data:t})};function Nt(e){st!==e&&(st=e,e?Mt(It):it(It))}function Bs(...e){st&&rt.log(...e)}class ${constructor(){c(this,"listeners",new Map),c(this,"listenersCount",0),c(this,"subscribeListeners",[])}clear(){this.listeners.clear(),this.subscribeListeners=[]}get count(){return this.listenersCount+this.subscribeListeners.length}emit(t,...s){this.subscribeListeners.forEach(n=>n({event:t,args:s})),(this.listeners.get(t)||[]).forEach(([n,i])=>{n(...s),i&&this.off(t,n)})}on(t,s,n){let i=this.listeners.get(t);return i||this.listeners.set(t,i=[]),i.push([s,n]),this.listenersCount+=1,()=>this.off(t,s)}off(t,s){const n=this.listeners.get(t)||[];for(let i=0;i<n.length;i+=1)if(s===n[i][0]){n.splice(i,1),this.listenersCount-=1;return}}subscribe(t){return this.subscribeListeners.push(t),()=>this.unsubscribe(t)}unsubscribe(t){for(let s=0;s<this.subscribeListeners.length;s+=1)if(this.subscribeListeners[s]===t){this.subscribeListeners.splice(s,1);return}}}function nt(e,t,s){return window.addEventListener(e,t,s),()=>window.removeEventListener(e,t,s)}class L extends Error{constructor(t,s,n){super(s,{cause:n}),this.type=t,Object.setPrototypeOf(this,L.prototype)}}function v(e,t,s){return new L(e,t,s)}const Vt="ERR_METHOD_UNSUPPORTED",$t="ERR_METHOD_PARAMETER_UNSUPPORTED",Lt="ERR_UNKNOWN_ENV",Ut="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Ht="ERR_TIMED_OUT",Wt="ERR_UNEXPECTED_TYPE",ot="ERR_PARSE",jt="ERR_NAVIGATION_LIST_EMPTY",Gt="ERR_NAVIGATION_CURSOR_INVALID",qs="ERR_NAVIGATION_ITEM_INVALID",Os="ERR_SSR_INIT",Kt="ERR_INVALID_PATH_BASE";function I(){return v(Wt,"Value has unexpected type")}class K{constructor(t,s,n){this.parser=t,this.isOptional=s,this.type=n}parse(t){if(!(this.isOptional&&t===void 0))try{return this.parser(t)}catch(s){throw v(ot,`Unable to parse value${this.type?` as ${this.type}`:""}`,s)}}optional(){return this.isOptional=!0,this}}function A(e,t){return()=>new K(e,!1,t)}const P=A(e=>{if(typeof e=="boolean")return e;const t=String(e);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;throw I()},"boolean");function zt(e,t){const s={};for(const n in e){const i=e[n];if(!i)continue;let r,a;if(typeof i=="function"||"parse"in i)r=n,a=typeof i=="function"?i:i.parse.bind(i);else{const{type:o}=i;r=i.from||n,a=typeof o=="function"?o:o.parse.bind(o)}try{const o=a(t(r));o!==void 0&&(s[n]=o)}catch(o){throw v(ot,`Unable to parse field "${n}"`,o)}}return s}function at(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw I();return t}function _(e,t){return new K(s=>{const n=at(s);return zt(e,i=>n[i])},!1,t)}const C=A(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw I()},"number");function z(e){return/^#[\da-f]{6}$/i.test(e)}function Qt(e){return/^#[\da-f]{3}$/i.test(e)}function ct(e){const t=e.replace(/\s/g,"").toLowerCase();if(z(t))return t;if(Qt(t)){let n="#";for(let i=0;i<3;i+=1)n+=t[1+i].repeat(2);return n}const s=t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(!s)throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);return s.slice(1).reduce((n,i)=>{const r=parseInt(i,10).toString(16);return n+(r.length===1?"0":"")+r},"#")}const h=A(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw I()},"string"),ht=A(e=>ct(h().parse(e)),"rgb");function Ds(e){return _({eventType:h(),eventData:t=>t}).parse(e)}function Ms(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function Ns(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Vs(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=Ns;return}s in t||(t[s]={}),t=t[s]})})}const $s=_({button_id:e=>e==null?void 0:h().parse(e)}),Ls={clipboard_text_received:_({req_id:h(),data:e=>e===null?e:h().optional().parse(e)}),custom_method_invoked:_({req_id:h(),result:e=>e,error:h().optional()}),invoice_closed:_({slug:h(),status:h()}),phone_requested:_({status:h()}),popup_closed:{parse:e=>$s.parse(e??{})},qr_text_received:_({data:h().optional()}),theme_changed:_({theme_params:e=>{const t=ht().optional();return Object.entries(at(e)).reduce((s,[n,i])=>(s[n]=t.parse(i),s),{})}}),viewport_changed:_({height:C(),width:e=>e==null?window.innerWidth:C().parse(e),is_state_stable:P(),is_expanded:P()}),write_access_requested:_({status:h()})};function Us(){const e=new $;Vs();let t=[Ms,nt("resize",()=>{e.emit("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),nt("message",s=>{if(s.source!==window.parent)return;let n;try{n=Ds(s.data)}catch{return}const{eventType:i,eventData:r}=n,a=Ls[i];try{const o=a?a.parse(r):r;e.emit(...o?[i,o]:[i])}catch(o){rt.error(`An error occurred processing the "${i}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,n,o)}}),()=>e.clear()];return[e,()=>{t.forEach(s=>s()),t=[]}]}const[Hs,Ws]=Dt(e=>{const[t,s]=Us(),n=t.off.bind(t);return t.off=(i,r)=>{const{count:a}=t;n(i,r),a&&!t.count&&e()},[t,s]},([,e])=>e());function Q(){return Hs()[0]}function U(e,t){Q().off(e,t)}function E(e,t,s){return Q().on(e,t,s)}function H(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ft(e,t){const s=e.split("."),n=t.split("."),i=Math.max(s.length,n.length);for(let r=0;r<i;r+=1){const a=parseInt(s[r]||"0",10),o=parseInt(n[r]||"0",10);if(a!==o)return a>o?1:-1}return 0}function R(e,t){return Ft(e,t)<=0}function x(e,t,s){if(typeof s=="string"){if(e==="web_app_open_link"&&t==="try_instant_view")return R("6.4",s);if(e==="web_app_set_header_color"&&t==="color")return R("6.9",s)}switch(e){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return R("6.1",t);case"web_app_open_popup":return R("6.2",t);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return R("6.4",t);case"web_app_switch_inline_query":return R("6.7",t);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return R("6.9",t);case"web_app_setup_settings_button":return R("6.10",t);case"web_app_biometry_get_info":case"web_app_biometry_open_settings":case"web_app_biometry_request_access":case"web_app_biometry_request_auth":case"web_app_biometry_update_token":return R("7.2",t);default:return["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"].includes(e)}}function js(e){return"external"in e&&H(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Jt(e){return"TelegramWebviewProxy"in e&&H(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function ut(){try{return window.self!==window.top}catch{return!0}}let Yt="https://web.telegram.org";function Gs(e){Yt=e}function Zt(){return Yt}function k(e,t,s){let n={},i;t===void 0&&s===void 0?n={}:t!==void 0&&s!==void 0?(n=s,i=t):t!==void 0&&("targetOrigin"in t?n=t:i=t);const{targetOrigin:r=Zt()}=n;if(Bs("Posting event:",i?{event:e,data:i}:{event:e}),ut()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),r);return}if(js(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Jt(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw v(Lt,"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment.")}function Xt(e){return(t,s)=>{if(!x(t,e))throw v(Vt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(H(s)){let n;if(t==="web_app_open_link"&&"try_instant_view"in s?n="try_instant_view":t==="web_app_set_header_color"&&"color"in s&&(n="color"),n&&!x(t,n,e))throw v($t,`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return k(t,s)}}function pt(e){return({req_id:t})=>t===e}function te(e){return v(Ht,`Timeout reached: ${e}ms`)}function lt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n(te(t))},t)})])}async function w(e){let t;const s=new Promise(p=>{t=p}),{method:n,event:i,capture:r,postEvent:a=k,timeout:o}=e,u=(Array.isArray(i)?i:[i]).map(p=>E(p,l=>(!r||r(l))&&t(l)));try{return a(n,e.params),await(o?lt(s,o):s)}finally{u.forEach(p=>p())}}async function T(e,t,s,n={}){const{result:i,error:r}=await w({...n,method:"web_app_invoke_custom_method",event:"custom_method_invoked",params:{method:e,params:t,req_id:s},capture:pt(s)});if(r)throw v(Ut,r);return i}function G(...e){return e.map(t=>{if(typeof t=="string")return t;if(H(t))return G(Object.entries(t).map(s=>s[1]&&s[0]));if(Array.isArray(t))return G(...t)}).filter(Boolean).join(" ")}function Ks(...e){return e.reduce((t,s)=>(H(s)&&Object.entries(s).forEach(([n,i])=>{const r=G(t[n],i);r.length&&(t[n]=r)}),t),{})}function dt(e){const t=ct(e);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const r=parseInt(t.slice(1+i*2,1+(i+1)*2),16);return s+r*r*n},0))<120}class zs{constructor(t){c(this,"ee",new $),c(this,"on",this.ee.on.bind(this.ee)),c(this,"off",this.ee.off.bind(this.ee)),this.state=t}clone(){return{...this.state}}set(t,s){Object.entries(typeof t=="string"?{[t]:s}:t).reduce((n,[i,r])=>this.state[i]===r||r===void 0?n:(this.state[i]=r,this.ee.emit(`change:${i}`,r),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class _t{constructor(t){c(this,"state"),c(this,"get"),c(this,"set"),c(this,"clone"),this.state=new zs(t),this.set=this.state.set.bind(this.state),this.get=this.state.get.bind(this.state),this.clone=this.state.clone.bind(this.state)}}function ee(e,t){return s=>x(t[s],e)}class wt extends _t{constructor(t,s,n){super(t),c(this,"supports"),this.supports=ee(s,n)}}class se extends wt{constructor(t,s,n){super({isVisible:t},s,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"}),c(this,"on",(i,r)=>i==="click"?E("back_button_pressed",r):this.state.on(i,r)),c(this,"off",(i,r)=>i==="click"?U("back_button_pressed",r):this.state.off(i,r)),this.postEvent=n}set isVisible(t){this.set("isVisible",t),this.postEvent("web_app_setup_back_button",{is_visible:t})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const gt=A(e=>e instanceof Date?e:new Date(C().parse(e)*1e3),"Date");function F(e,t){return new K(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw I();const n=typeof s=="string"?new URLSearchParams(s):s;return zt(e,i=>{const r=n.get(i);return r===null?void 0:r})},!1,t)}const Qs=_({id:C(),type:h(),title:h(),photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"Chat").optional(),At=_({addedToAttachmentMenu:{type:P().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:P().optional(),from:"allows_write_to_pm"},firstName:{type:h(),from:"first_name"},id:C(),isBot:{type:P().optional(),from:"is_bot"},isPremium:{type:P().optional(),from:"is_premium"},languageCode:{type:h().optional(),from:"language_code"},lastName:{type:h().optional(),from:"last_name"},photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"User").optional();function ne(){return F({authDate:{type:gt(),from:"auth_date"},canSendAfter:{type:C().optional(),from:"can_send_after"},chat:Qs,chatInstance:{type:h().optional(),from:"chat_instance"},chatType:{type:h().optional(),from:"chat_type"},hash:h(),queryId:{type:h().optional(),from:"query_id"},receiver:At,startParam:{type:h().optional(),from:"start_param"},user:At},"InitData")}function Fs(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Js(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const ie=A(e=>{const t=ht().optional();return Object.entries(at(e)).reduce((s,[n,i])=>(s[Fs(n)]=t.parse(i),s),{})},"ThemeParams");function ft(e){return F({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:ne().optional(),from:"tgWebAppData"},initDataRaw:{type:h().optional(),from:"tgWebAppData"},platform:{type:h(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:h().optional(),from:"tgWebAppStartParam"},themeParams:{type:ie(),from:"tgWebAppThemeParams"},version:{type:h(),from:"tgWebAppVersion"}}).parse(e)}function re(e){return ft(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function Ys(){return re(window.location.href)}function oe(){return performance.getEntriesByType("navigation")[0]}function Zs(){const e=oe();if(!e)throw new Error("Unable to get first navigation entry.");return re(e.name)}function ae(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function ce(e,t){sessionStorage.setItem(ae(e),JSON.stringify(t))}function he(e){const t=sessionStorage.getItem(ae(e));try{return t?JSON.parse(t):void 0}catch{}}function Xs(){return ft(he("launchParams")||"")}function ue(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[Js(t),s])))}function pe(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:r,startParam:a,botInline:o}=e,u=new URLSearchParams;return u.set("tgWebAppPlatform",n),u.set("tgWebAppThemeParams",ue(s)),u.set("tgWebAppVersion",i),t&&u.set("tgWebAppData",t),a&&u.set("tgWebAppStartParam",a),typeof r=="boolean"&&u.set("tgWebAppShowSettings",r?"1":"0"),typeof o=="boolean"&&u.set("tgWebAppBotInline",o?"1":"0"),u.toString()}function tn(e){ce("launchParams",pe(e))}function mt(){for(const e of[Ys,Zs,Xs])try{const t=e();return tn(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function bt(){const e=oe();return!!(e&&e.type==="reload")}function en(){let e=0;return()=>(e+=1).toString()}function sn(){let e=!1;const t=[];return[s=>!e&&t.push(s),()=>{e||(e=!0,t.forEach(s=>s()))},e]}const[nn]=Dt(en);function g(e,t){return()=>{const s=mt(),n={...s,postEvent:Xt(s.version),createRequestId:nn()};if(typeof e=="function")return e(n);const[i,r,a]=sn(),o=t({...n,state:bt()?he(e):void 0,addCleanup:i}),u=p=>(a||i(p.on("change",l=>{ce(e,l)})),p);return[o instanceof Promise?o.then(u):u(o),r]}}const le=g("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new se(s.isVisible,t,e));class W extends wt{constructor(){super(...arguments),c(this,"on",this.state.on.bind(this.state)),c(this,"off",this.state.off.bind(this.state))}}function de(e){const t=e.available?e:{available:!1,device_id:"",token_saved:!1,access_requested:!1,access_granted:!1,type:""};return{available:!0,type:t.type,deviceId:t.device_id,tokenSaved:t.token_saved,accessRequested:t.access_requested,accessGranted:t.access_granted}}class _e extends W{constructor({postEvent:t,version:s,...n}){super(n,s,{auth:"web_app_biometry_request_auth",openSettings:"web_app_biometry_open_settings",requestAccess:"web_app_biometry_request_access",updateToken:"web_app_biometry_update_token"}),c(this,"postEvent"),c(this,"authPromise"),c(this,"accessPromise"),this.postEvent=t}get available(){return this.get("available")}get accessGranted(){return this.get("accessGranted")}get accessRequested(){return this.get("accessRequested")}async authenticate({reason:t,...s}){return this.authPromise||(this.authPromise=w({...s,method:"web_app_biometry_request_auth",event:"biometry_auth_requested",postEvent:this.postEvent,params:{reason:(t||"").trim()}}).then(({token:n})=>n).finally(()=>this.authPromise=void 0)),this.authPromise}get deviceId(){return this.get("deviceId")}openSettings(){this.postEvent("web_app_biometry_open_settings")}requestAccess({reason:t,...s}={}){return this.accessPromise||(this.accessPromise=w({...s,postEvent:this.postEvent,method:"web_app_biometry_request_access",event:"biometry_info_received",params:{reason:t||""}}).then(n=>{const i=de(n);return this.set(i),i.accessGranted}).finally(()=>this.accessPromise=void 0)),this.accessPromise}get biometryType(){return this.get("biometryType")}get tokenSaved(){return this.get("tokenSaved")}async updateToken({token:t,...s}={}){return["removed","updated"].includes((await w({...s,postEvent:this.postEvent,method:"web_app_biometry_update_token",event:"biometry_token_updated",params:{token:t||""}})).status)}}async function we(e){return de(await w({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const ge=g("biometryManager",async({postEvent:e,version:t,state:s})=>new _e({...s||await we({timeout:1e3}),version:t,postEvent:e}));class vt extends _t{constructor(){super(...arguments),c(this,"on",this.state.on.bind(this.state)),c(this,"off",this.state.off.bind(this.state))}}class fe extends vt{constructor(t,s){super({isConfirmationNeeded:t}),this.postEvent=s}set isConfirmationNeeded(t){this.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const me=g("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new fe(t.isConfirmationNeeded,e));class yt{constructor(t,s){c(this,"supports"),this.supports=ee(t,s)}}function rn(e){if(Array.isArray(e))return e;if(typeof e=="string")try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch{}throw I()}class on extends K{constructor(t,s,n){super(rn,s,n),c(this,"itemParser"),this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function be(e){return new on(t=>t,!1,e)}function Bt(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class ve extends yt{constructor(t,s,n){super(t,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"}),this.createRequestId=s,this.postEvent=n}async delete(t,s={}){const n=Array.isArray(t)?t:[t];n.length&&await T("deleteStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent})}async getKeys(t={}){return be().of(h()).parse(await T("getStorageKeys",{},this.createRequestId(),{...t,postEvent:this.postEvent}))}async get(t,s={}){const n=Array.isArray(t)?t:[t];if(!n.length)return Bt(n,"");const i=await T("getStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent}),r=_(Bt(n,h()),"CloudStorageData").parse(i);return Array.isArray(t)?r:r[t]}async set(t,s,n={}){await T("saveStorageValue",{key:t,value:s},this.createRequestId(),{...n,postEvent:this.postEvent})}}const ye=g(({createRequestId:e,postEvent:t,version:s})=>new ve(s,e,t));class Ee extends yt{constructor(t,s){super(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"}),this.postEvent=s}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"})}}const Re=g(({version:e,postEvent:t})=>new Ee(e,t));class Pe{constructor(t){this.initData=t}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:t}=this;return t?new Date(this.authDate.getTime()+t*1e3):void 0}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}const Se=g(({initData:e})=>e?new Pe(e):void 0);function an(e){return ne().parse(e)}class Ce extends W{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_invoice"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t,s){if(this.isOpened)throw new Error("Invoice is already opened");let n;if(!s)n=t;else{const{hostname:i,pathname:r}=new URL(t,window.location.href);if(i!=="t.me")throw new Error(`Incorrect hostname: ${i}`);const a=r.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!a)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,n]=a}this.isOpened=!0;try{return(await w({method:"web_app_open_invoice",event:"invoice_closed",params:{slug:n},postEvent:this.postEvent,capture(i){return n===i.slug}})).status}finally{this.isOpened=!1}}}const xe=g(({version:e,postEvent:t})=>new Ce(!1,e,t));class Te extends _t{constructor({postEvent:t,...s}){super(s),c(this,"postEvent"),c(this,"on",(n,i)=>n==="click"?E("main_button_pressed",i):this.state.on(n,i)),c(this,"off",(n,i)=>n==="click"?U("main_button_pressed",i):this.state.off(n,i)),this.postEvent=t}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(t){this.setParams({isEnabled:t})}get isEnabled(){return this.get("isEnabled")}set isLoaderVisible(t){this.setParams({isLoaderVisible:t})}get isLoaderVisible(){return this.get("isLoaderVisible")}set isVisible(t){this.setParams({isVisible:t})}get isVisible(){return this.get("isVisible")}get backgroundColor(){return this.get("backgroundColor")}get text(){return this.get("text")}get textColor(){return this.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(t){return this.setParams({text:t})}setTextColor(t){return this.setParams({textColor:t})}setBackgroundColor(t){return this.setParams({backgroundColor:t})}setParams(t){return this.set(t),this.commit(),this}}const ke=g("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",backgroundColor:t.buttonColor||"#000000"}})=>new Te({...s,postEvent:e}));function cn(){return F({contact:_({userId:{type:C(),from:"user_id"},phoneNumber:{type:h(),from:"phone_number"},firstName:{type:h(),from:"first_name"},lastName:{type:h().optional(),from:"last_name"}}),authDate:{type:gt(),from:"auth_date"},hash:h()},"RequestedContact")}function Ie(e,t){return s=>{const[n,i]=t[s];return x(n,i,e)}}function hn(e){return new Promise(t=>{setTimeout(t,e)})}class Ae extends W{constructor({postEvent:t,createRequestId:s,version:n,botInline:i,...r}){super(r,n,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"}),c(this,"botInline"),c(this,"postEvent"),c(this,"createRequestId"),c(this,"requestPhoneAccessPromise"),c(this,"requestWriteAccessPromise"),c(this,"supportsParam"),this.createRequestId=s,this.postEvent=t,this.botInline=i;const a=this.supports.bind(this);this.supports=o=>a(o)?o!=="switchInlineQuery"||i:!1,this.supportsParam=Ie(n,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:t=1e4}={}){return cn().parse(await T("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:t}))}get bgColor(){return this.get("bgColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return dt(this.bgColor)}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:t=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+t;let n=50;return lt(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await hn(n),n+=50}throw te(t)},t)}async requestPhoneAccess(t={}){return this.requestPhoneAccessPromise||(this.requestPhoneAccessPromise=w({...t,method:"web_app_request_phone",event:"phone_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestPhoneAccessPromise=void 0)),this.requestPhoneAccessPromise}async requestWriteAccess(t={}){return this.requestWriteAccessPromise||(this.requestWriteAccessPromise=w({...t,method:"web_app_request_write_access",event:"write_access_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestWriteAccessPromise=void 0)),this.requestWriteAccessPromise}sendData(t){const{size:s}=new Blob([t]);if(!s||s>4096)throw new Error(`Passed data has incorrect size: ${s}`);this.postEvent("web_app_data_send",{data:t})}setHeaderColor(t){this.postEvent("web_app_set_header_color",z(t)?{color:t}:{color_key:t}),this.set("headerColor",t)}setBgColor(t){this.postEvent("web_app_set_background_color",{color:t}),this.set("bgColor",t)}switchInlineQuery(t,s=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:t,chat_types:s})}}const Be=g("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new Ae({...n,...s,botInline:t}));function un(e){const t=e.message.trim(),s=(e.title||"").trim(),n=e.buttons||[];let i;if(s.length>64)throw new Error(`Title has incorrect size: ${s.length}`);if(!t.length||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?i=n.map(r=>{const{id:a=""}=r;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(!r.type||r.type==="default"||r.type==="destructive"){const o=r.text.trim();if(!o.length||o.length>64){const u=r.type||"default";throw new Error(`Button text with type "${u}" has incorrect size: ${r.text.length}`)}return{...r,text:o,id:a}}return{...r,id:a}}):i=[{type:"close",id:""}],{title:s,message:t,buttons:i}}class qe extends W{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_popup"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.isOpened=!0;try{const{button_id:s=null}=await w({event:"popup_closed",method:"web_app_open_popup",postEvent:this.postEvent,params:un(t)});return s}finally{this.isOpened=!1}}}const Oe=g(({postEvent:e,version:t})=>new qe(!1,t,e));class De extends W{constructor(t,s,n){super({isOpened:t},s,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"}),this.postEvent=n}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{return(await w({method:"web_app_open_scan_qr_popup",event:["qr_text_received","scan_qr_popup_closed"],postEvent:this.postEvent,params:{text:t}})||{}).data||null}finally{this.isOpened=!1}}}const Me=g(({version:e,postEvent:t})=>new De(!1,e,t));class Ne extends wt{constructor(t,s,n){super({isVisible:t},s,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"}),c(this,"on",(i,r)=>i==="click"?E("settings_button_pressed",r):this.state.on(i,r)),c(this,"off",(i,r)=>i==="click"?U("settings_button_pressed",r):this.state.off(i,r)),this.postEvent=n}set isVisible(t){this.set("isVisible",t),this.postEvent("web_app_setup_settings_button",{is_visible:t})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const Ve=g("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new Ne(s.isVisible,e,t));function Et(e){return ie().parse(e)}class $e extends vt{get accentTextColor(){return this.get("accentTextColor")}get bgColor(){return this.get("bgColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}getState(){return this.clone()}get headerBgColor(){return this.get("headerBgColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.bgColor||dt(this.bgColor)}get linkColor(){return this.get("linkColor")}get secondaryBgColor(){return this.get("secondaryBgColor")}get sectionBgColor(){return this.get("sectionBgColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return E("theme_changed",t=>{this.set(Et(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const Le=g("themeParams",({themeParams:e,state:t=e,addCleanup:s})=>{const n=new $e(t);return s(n.listen()),n});function pn(e={}){return w({...e,method:"web_app_request_theme",event:"theme_changed"}).then(Et)}class Ue extends yt{constructor(t,s,n){super(t,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),c(this,"supportsParam"),this.version=t,this.createRequestId=s,this.postEvent=n,this.supportsParam=Ie(t,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(t,s){const n=new URL(t,window.location.href).toString();if(!x("web_app_open_link",this.version)){window.open(n,"_blank");return}this.postEvent("web_app_open_link",{url:n,...typeof s=="boolean"?{try_instant_view:s}:{}})}openTelegramLink(t){const{hostname:s,pathname:n,search:i}=new URL(t,window.location.href);if(s!=="t.me")throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);if(!x("web_app_open_tg_link",this.version)){window.location.href=t;return}this.postEvent("web_app_open_tg_link",{path_full:n+i})}async readTextFromClipboard(){const t=this.createRequestId(),{data:s=null}=await w({method:"web_app_read_text_from_clipboard",event:"clipboard_text_received",postEvent:this.postEvent,params:{req_id:t},capture:pt(t)});return s}}const He=g(({version:e,postEvent:t,createRequestId:s})=>new Ue(e,s,t));async function Rt(e={}){const{is_expanded:t,is_state_stable:s,...n}=await w({...e,method:"web_app_request_viewport",event:"viewport_changed"});return{...n,isExpanded:t,isStateStable:s}}function O(e){return e<0?0:e}class We extends vt{constructor({postEvent:t,stableHeight:s,height:n,width:i,isExpanded:r}){super({height:O(n),isExpanded:r,stableHeight:O(s),width:O(i)}),c(this,"postEvent"),this.postEvent=t}async sync(t){const{isStateStable:s,...n}=await Rt(t);this.set({...n,stableHeight:s?n.height:this.get("stableHeight")})}get height(){return this.get("height")}get stableHeight(){return this.get("stableHeight")}listen(){return E("viewport_changed",t=>{const{height:s,width:n,is_expanded:i,is_state_stable:r}=t,a=O(s);this.set({height:a,isExpanded:i,width:O(n),...r?{stableHeight:a}:{}})})}get isExpanded(){return this.get("isExpanded")}get width(){return this.get("width")}expand(){this.postEvent("web_app_expand"),this.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}const je=g("viewport",async({state:e,platform:t,postEvent:s,addCleanup:n})=>{let i=!1,r=0,a=0,o=0;if(e)i=e.isExpanded,r=e.height,a=e.width,o=e.stableHeight;else if(["macos","tdesktop","unigram","webk","weba","web"].includes(t))i=!0,r=window.innerHeight,a=window.innerWidth,o=window.innerHeight;else{const p=await Rt({timeout:1e3,postEvent:s});i=p.isExpanded,r=p.height,a=p.width,o=p.isStateStable?r:0}const u=new We({postEvent:s,height:r,width:a,stableHeight:o,isExpanded:i});return n(u.listen()),u});function S(e,t){document.documentElement.style.setProperty(e,t)}function ln(e,t,s){s||(s=o=>`--tg-${o}-color`);const n=s("header"),i=s("bg"),r=()=>{const{headerColor:o}=e;if(z(o))S(n,o);else{const{bgColor:u,secondaryBgColor:p}=t;o==="bg_color"&&u?S(n,u):o==="secondary_bg_color"&&p&&S(n,p)}S(i,e.bgColor)},a=[t.on("change",r),e.on("change",r)];return r(),()=>a.forEach(o=>o())}function dn(e,t){t||(t=n=>`--tg-theme-${n.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`);const s=()=>{Object.entries(e.getState()).forEach(([n,i])=>{i&&S(t(n),i)})};return s(),e.on("change",s)}function _n(e,t){t||(t=p=>`--tg-viewport-${p}`);const[s,n,i]=["height","width","stable-height"].map(p=>t(p)),r=()=>S(s,`${e.height}px`),a=()=>S(n,`${e.width}px`),o=()=>S(i,`${e.stableHeight}px`),u=[e.on("change:height",r),e.on("change:width",a),e.on("change:stableHeight",o)];return r(),a(),o(),()=>u.forEach(p=>p())}function Ge(e=!0){const t=[E("reload_iframe",()=>{k("iframe_will_reload"),window.location.reload()})],s=()=>t.forEach(n=>n());if(e){const n=document.createElement("style");n.id="telegram-custom-styles",document.head.appendChild(n),t.push(E("set_custom_style",i=>{n.innerHTML=i}),()=>document.head.removeChild(n))}return k("iframe_ready",{reload_supported:!0}),s}function Ke(){return typeof window>"u"}async function wn(){if(Jt(window))return!0;try{return await w({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function ze(e){return e instanceof L}function gn(e,t){return ze(e)&&e.type===t}function Y(e,t){let s,n,i;return typeof e=="string"?s=e:(s=e.pathname===void 0?t:e.pathname,n=e.params,i=e.id),Object.freeze({id:i||(Math.random()*2**14|0).toString(16),pathname:s,params:n})}class Qe{constructor(t,s,n=k){if(c(this,"history"),c(this,"ee",new $),c(this,"attached",!1),c(this,"back",()=>this.go(-1)),c(this,"on",this.ee.on.bind(this.ee)),c(this,"off",this.ee.off.bind(this.ee)),this._index=s,this.postEvent=n,t.length===0)throw v(jt,"History should not be empty.");if(s<0||s>=t.length)throw v(Gt,"Index should not be zero and higher or equal than history size.");this.history=t.map(i=>Y(i,""))}attach(){this.attached||(this.attached=!0,this.sync(),E("back_button_pressed",this.back))}get current(){return this.history[this.index]}detach(){this.attached=!1,U("back_button_pressed",this.back)}forward(){this.go(1)}go(t,s){const n=this.index+t,i=Math.min(Math.max(0,n),this.history.length-1);(n===i||s)&&this.replaceAndMove(i,this.history[i])}goTo(t,s){this.go(t-this.index,s)}get hasPrev(){return this.index>0}get hasNext(){return this.index!==this.history.length-1}get index(){return this._index}push(t){this.hasNext&&this.history.splice(this.index+1),this.replaceAndMove(this.index+1,Y(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,Y(t,this.current.pathname))}replaceAndMove(t,s){const n=t-this.index;if(!n&&this.current===s)return;const i=this.current;if(this.index!==t){const r=this._index;this._index=t,this.attached&&r>0!=t>0&&this.sync()}this.history[t]=s,this.ee.emit("change",{navigator:this,from:i,to:this.current,delta:n})}sync(){this.postEvent("web_app_setup_back_button",{is_visible:!!this.index})}}function Z({params:e,...t}){return{...e||{hash:"",search:""},...t}}function M(e,t){return e.startsWith(t)?e:`${t}${e}`}function N(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${M(e.search||"","?")}${M(e.hash||"","#")}`,"http://a")}function V(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=N(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function X(e,t,s){let n,i;typeof e=="string"?n=e:(n=V(e),s=e.state,i=e.id);const{pathname:r,search:a,hash:o}=new URL(n,`http://a${M(t,"/")}`);return{id:i,pathname:r,params:{hash:o,search:a,state:s}}}async function D(e){return e===0?!0:Promise.race([new Promise(t=>{const s=nt("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function fn(){if(window.history.length<=1||(window.history.pushState(null,""),await D(1-window.history.length)))return;let e=await D(-1);for(;e;)e=await D(-1)}function Pt(e){return N(e).pathname}const qt=0,tt=1,et=2;class St{constructor(t,s,{postEvent:n,hashMode:i="classic",base:r}={}){c(this,"navigator"),c(this,"ee",new $),c(this,"hashMode"),c(this,"base"),c(this,"attached",!1),c(this,"onPopState",({state:a})=>{if(a===null)return this.push(this.parsePath(window.location.href));a===qt?window.history.forward():a===tt&&this.back(),a===et&&this.forward()}),c(this,"onNavigatorChange",async({to:a,from:o,delta:u})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:u,from:Z(o),to:Z(a),navigator:this})}),c(this,"on",this.ee.on.bind(this.ee)),c(this,"off",this.ee.off.bind(this.ee)),this.navigator=new Qe(t.map(a=>X(a,"/")),s,n),this.navigator.on("change",this.onNavigatorChange),this.hashMode=i,this.base=Pt(r||"")}async attach(){this.attached||(this.attached=!0,this.navigator.attach(),window.addEventListener("popstate",this.onPopState),await this.syncHistory())}back(){this.navigator.back()}detach(){this.attached=!1,this.navigator.detach(),window.removeEventListener("popstate",this.onPopState)}forward(){return this.navigator.forward()}get index(){return this.navigator.index}get id(){return this.navigator.current.id}go(t,s){return this.navigator.go(t,s)}goTo(t,s){this.navigator.goTo(t,s)}get hash(){return(this.navigator.current.params||{}).hash||""}get hasPrev(){return this.navigator.hasPrev}get hasNext(){return this.navigator.hasNext}get history(){return this.navigator.history.map(Z)}get path(){return V(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=N(t);return this.hashMode&&(s=N(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=X(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=X(t,this.path),{state:i=s}=n.params;this.navigator.replace({...n,params:{...n.params,state:i}})}renderPath(t){const s=(this.base.length===1?"":this.base)+M(V(t),"/");return this.hashMode?M(s.slice(1),this.hashMode==="classic"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await fn(),this.hasPrev&&this.hasNext?(window.history.replaceState(tt,""),window.history.pushState(t,"",s),window.history.pushState(et,""),await D(-1)):this.hasPrev?(window.history.replaceState(tt,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(et,""),await D(-1)):(window.history.replaceState(qt,""),window.history.pushState(t,"",s)),window.addEventListener("popstate",this.onPopState)}get search(){return(this.navigator.current.params||{}).search||""}get state(){return(this.navigator.current.params||{}).state}}function Fe(e){e||(e={});const{href:t,hash:s}=window.location;let n=V(e.hashMode===null?t:s.includes("?")?s.slice(1):`?${s.slice(1)}`);const i=e.base?Pt(e.base):void 0;if(i){if(!n.startsWith(i))throw v(Kt,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new St([n],0,e)}function mn(e){const t=e.match(/#(.+)/);return t?t[1]:null}function bn(e,t){if(bt()){const s=sessionStorage.getItem(e);if(s)try{const{index:n,history:i}=JSON.parse(s);return new St(i,n,t)}catch(n){console.error("Unable to restore hash navigator state.",n)}}return Fe(t)}function vn(e,t){const s=bn(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}function f(e,t){function s(n){return(i,r,a)=>o=>{const u=o[r]||[],p={...o,[i]:n(...u)};return Ot.jsx(a,{...p})}}return[s(e),s(t)]}const Je=d.createContext(void 0);function Ye(){const e=d.useContext(Je);if(!e)throw new Error("useSDK was used outside the SDKProvider.");return e}function m(e){function t(n){const i=Ye(),[r,a]=d.useState(n?void 0:()=>{if(Ke())throw new Error("Using hooks on the server side, you must explicitly specify ssr = true option");return i.use(e)});return d.useEffect(()=>{a(i.use(e))},[i]),r}function s(n){const i=t(n);if(i){if("error"in i)throw i.error;return i.result}}return[t,s]}const[Ze,Xe]=m(le),[yn,En]=f(Ze,Xe),[ts,es]=m(ge),[Rn,Pn]=f(ts,es),[ss,ns]=m(me),[Sn,Cn]=f(ss,ns),[is,rs]=m(ye),[xn,Tn]=f(is,rs),[os,as]=m(Re),[kn,In]=f(os,as),[cs,hs]=m(Se),[An,Bn]=f(cs,hs),[us,ps]=m(xe),[qn,On]=f(us,ps),[ls,ds]=m(ke),[Dn,Mn]=f(ls,ds),[_s,ws]=m(Be),[Nn,Vn]=f(_s,ws),[gs,fs]=m(Oe),[$n,Ln]=f(gs,fs),[ms,bs]=m(Me),[Un,Hn]=f(ms,bs),[vs,ys]=m(Ve),[Wn,jn]=f(vs,ys),[Es,Rs]=m(Le),[Gn,Kn]=f(Es,Rs);function zn(){return d.useMemo(mt,[])}const[Ps,Ss]=m(He),[Qn,Fn]=f(Ps,Ss),[Cs,xs]=m(je),[Jn,Yn]=f(Cs,xs);function Zn({children:e,acceptCustomStyles:t,debug:s}){const n=d.useRef(!0),i=d.useRef(new Map),[r,a]=d.useState([]),o=d.useCallback(()=>a([]),[]),u=d.useCallback(l=>{n.current&&(l&&l(i.current),o())},[o]),p=d.useMemo(()=>({use(l,...Ts){const{current:Ct}=i,xt=Ct.get(l);if(xt)return xt;let y,J;try{y=l(...Ts)}catch(b){J=b}function j(b){return Ct.set(l,b),b}if(J)return j({error:J});let B;if(Array.isArray(y)&&(B=y[1],y=y[0]),!y)return j({result:y,cleanup:B});function Tt(b){if("on"in b){const q=b.on("change",o),kt=B;B=()=>{kt&&kt(),q()}}return{result:b,cleanup:B}}return y instanceof Promise?(y.then(b=>u(q=>q.set(l,Tt(b))),b=>u(q=>q.set(l,{error:b}))),j({})):j(Tt(y))}}),[r]);return d.useEffect(()=>{if(ut())return Ge(t)},[t]),d.useEffect(()=>{Nt(s||!1)},[s]),d.useEffect(()=>()=>{n.current=!1},[]),d.useEffect(()=>()=>{i.current.forEach(l=>{"cleanup"in l&&l.cleanup&&l.cleanup()})},[o]),Ot.jsx(Je.Provider,{value:p,children:e})}exports.BackButton=se;exports.BasicNavigator=Qe;exports.BiometryManager=_e;exports.BrowserNavigator=St;exports.ClosingBehavior=fe;exports.CloudStorage=ve;exports.ERR_INVALID_PATH_BASE=Kt;exports.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Ut;exports.ERR_METHOD_PARAMETER_UNSUPPORTED=$t;exports.ERR_METHOD_UNSUPPORTED=Vt;exports.ERR_NAVIGATION_HISTORY_EMPTY=jt;exports.ERR_NAVIGATION_INDEX_INVALID=Gt;exports.ERR_NAVIGATION_ITEM_INVALID=qs;exports.ERR_PARSE=ot;exports.ERR_SSR_INIT=Os;exports.ERR_TIMED_OUT=Ht;exports.ERR_UNEXPECTED_TYPE=Wt;exports.ERR_UNKNOWN_ENV=Lt;exports.EventEmitter=$;exports.HapticFeedback=Ee;exports.InitData=Pe;exports.Invoice=Ce;exports.MainButton=Te;exports.MiniApp=Ae;exports.Popup=qe;exports.QRScanner=De;exports.SDKError=L;exports.SDKProvider=Zn;exports.SettingsButton=Ne;exports.ThemeParams=$e;exports.Utils=Ue;exports.Viewport=We;exports.array=be;exports.bindMiniAppCSSVars=ln;exports.bindThemeParamsCSSVars=dn;exports.bindViewportCSSVars=_n;exports.boolean=P;exports.captureSameReq=pt;exports.classNames=G;exports.compareVersions=Ft;exports.createBrowserNavigatorFromLocation=Fe;exports.createPostEvent=Xt;exports.createSafeURL=N;exports.date=gt;exports.getHash=mn;exports.getPathname=Pt;exports.initBackButton=le;exports.initBiometryManager=ge;exports.initClosingBehavior=me;exports.initCloudStorage=ye;exports.initHapticFeedback=Re;exports.initInitData=Se;exports.initInvoice=xe;exports.initMainButton=ke;exports.initMiniApp=Be;exports.initNavigator=vn;exports.initPopup=Oe;exports.initQRScanner=Me;exports.initSettingsButton=Ve;exports.initThemeParams=Le;exports.initUtils=He;exports.initViewport=je;exports.initWeb=Ge;exports.invokeCustomMethod=T;exports.isColorDark=dt;exports.isIframe=ut;exports.isPageReload=bt;exports.isRGB=z;exports.isRGBShort=Qt;exports.isSDKError=ze;exports.isSDKErrorOfType=gn;exports.isSSR=Ke;exports.isTMA=wn;exports.json=_;exports.mergeClassNames=Ks;exports.number=C;exports.off=U;exports.on=E;exports.parseInitData=an;exports.parseLaunchParams=ft;exports.parseThemeParams=Et;exports.postEvent=k;exports.request=w;exports.requestBiometryInfo=we;exports.requestThemeParams=pn;exports.requestViewport=Rt;exports.retrieveLaunchParams=mt;exports.rgb=ht;exports.searchParams=F;exports.serializeLaunchParams=pe;exports.serializeThemeParams=ue;exports.setCSSVar=S;exports.setDebug=Nt;exports.setTargetOrigin=Gs;exports.string=h;exports.subscribe=Mt;exports.supports=x;exports.targetOrigin=Zt;exports.toRGB=ct;exports.unsubscribe=it;exports.urlToPath=V;exports.useBackButton=Xe;exports.useBackButtonRaw=Ze;exports.useBiometryManager=es;exports.useBiometryManagerRaw=ts;exports.useClosingBehavior=ns;exports.useClosingBehaviorRaw=ss;exports.useCloudStorage=rs;exports.useCloudStorageRaw=is;exports.useHapticFeedback=as;exports.useHapticFeedbackRaw=os;exports.useInitData=hs;exports.useInitDataRaw=cs;exports.useInvoice=ps;exports.useInvoiceRaw=us;exports.useLaunchParams=zn;exports.useMainButton=ds;exports.useMainButtonRaw=ls;exports.useMiniApp=ws;exports.useMiniAppRaw=_s;exports.usePopup=fs;exports.usePopupRaw=gs;exports.useQRScanner=bs;exports.useQRScannerRaw=ms;exports.useSDK=Ye;exports.useSettingsButton=ys;exports.useSettingsButtonRaw=vs;exports.useThemeParams=Rs;exports.useThemeParamsRaw=Es;exports.useUtils=Ss;exports.useUtilsRaw=Ps;exports.useViewport=xs;exports.useViewportRaw=Cs;exports.withBackButton=En;exports.withBackButtonRaw=yn;exports.withBiometryManager=Pn;exports.withBiometryManagerRaw=Rn;exports.withClosingBehavior=Cn;exports.withClosingBehaviorRaw=Sn;exports.withCloudStorage=Tn;exports.withCloudStorageRaw=xn;exports.withHapticFeedback=In;exports.withHapticFeedbackRaw=kn;exports.withInitData=Bn;exports.withInitDataRaw=An;exports.withInvoice=On;exports.withInvoiceRaw=qn;exports.withMainButton=Mn;exports.withMainButtonRaw=Dn;exports.withMiniApp=Vn;exports.withMiniAppRaw=Nn;exports.withPopup=Ln;exports.withPopupRaw=$n;exports.withQRScanner=Hn;exports.withQRScannerRaw=Un;exports.withSettingsButton=jn;exports.withSettingsButtonRaw=Wn;exports.withThemeParams=Kn;exports.withThemeParamsRaw=Gn;exports.withTimeout=lt;exports.withUtils=Fn;exports.withUtilsRaw=Qn;exports.withViewport=Yn;exports.withViewportRaw=Jn;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|