@tma.js/sdk-react 2.2.8 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +9 -9
- package/dist/dts/hooks.d.ts +42 -0
- package/dist/dts/index.d.ts +1 -19
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -3081
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/dts/SDKProvider/SDKContext.d.ts +0 -8
- package/dist/dts/SDKProvider/SDKProvider.d.ts +0 -7
- package/dist/dts/SDKProvider/SDKProvider.types.d.ts +0 -41
- package/dist/dts/createHOCs.d.ts +0 -24
- package/dist/dts/createHooks.d.ts +0 -21
- package/dist/dts/hooks-hocs/back-button.d.ts +0 -2
- package/dist/dts/hooks-hocs/biometry-manager.d.ts +0 -2
- package/dist/dts/hooks-hocs/closing-behavior.d.ts +0 -2
- package/dist/dts/hooks-hocs/cloud-storage.d.ts +0 -2
- package/dist/dts/hooks-hocs/haptic-feedback.d.ts +0 -2
- package/dist/dts/hooks-hocs/init-data.d.ts +0 -2
- package/dist/dts/hooks-hocs/invoice.d.ts +0 -2
- package/dist/dts/hooks-hocs/launch-params.d.ts +0 -10
- package/dist/dts/hooks-hocs/main-button.d.ts +0 -2
- package/dist/dts/hooks-hocs/mini-app.d.ts +0 -2
- package/dist/dts/hooks-hocs/popup.d.ts +0 -2
- package/dist/dts/hooks-hocs/qr-scanner.d.ts +0 -2
- package/dist/dts/hooks-hocs/settings-button.d.ts +0 -2
- package/dist/dts/hooks-hocs/theme-params.d.ts +0 -2
- package/dist/dts/hooks-hocs/utils.d.ts +0 -2
- package/dist/dts/hooks-hocs/viewport.d.ts +0 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
[docs-badge]: https://img.shields.io/badge/documentation-blue?logo=gitbook&logoColor=white
|
|
6
6
|
|
|
7
|
-
[
|
|
7
|
+
[code-link]: https://github.com/Telegram-Mini-Apps/tma.js/tree/master/tma.js/sdk-react
|
|
8
8
|
|
|
9
|
-
[
|
|
9
|
+
[docs-link]: https://docs.telegram-mini-apps.com/packages/tma-js-sdk-react
|
|
10
10
|
|
|
11
|
-
[
|
|
11
|
+
[npm-link]: https://npmjs.com/package/@tma.js/sdk-react
|
|
12
12
|
|
|
13
|
-
[
|
|
13
|
+
[npm-badge]: https://img.shields.io/npm/v/@tma.js/sdk-react?logo=npm
|
|
14
14
|
|
|
15
|
-
[
|
|
15
|
+
[size-badge]: https://img.shields.io/bundlephobia/minzip/@tma.js/sdk-react
|
|
16
16
|
|
|
17
|
-
[![NPM][
|
|
18
|
-
![Size][
|
|
19
|
-
[![docs-badge]][
|
|
20
|
-
[![code-badge]][
|
|
17
|
+
[![NPM][npm-badge]][npm-link]
|
|
18
|
+
![Size][size-badge]
|
|
19
|
+
[![docs-badge]][docs-link]
|
|
20
|
+
[![code-badge]][code-link]
|
|
21
21
|
|
|
22
22
|
React JS bindings
|
|
23
23
|
for [client SDK](https://docs.telegram-mini-apps.com/packages/tma-js-sdk). Includes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AndroidDeviceData, RetrieveLaunchParamsResult, DeepConvertSnakeKeysToCamelCase } from '@tma.js/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the underlying signal value updating it each time the signal value changes.
|
|
4
|
+
* @param signal - a signal.
|
|
5
|
+
* @param getServerSnapshot - an optional function returning the signal value snapshot. It is used
|
|
6
|
+
* only during SSR to provide an initial value of the signal. When not set, defaults to the
|
|
7
|
+
* signal itself.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useSignal<T>(signal: {
|
|
10
|
+
(): T;
|
|
11
|
+
sub(fn: VoidFunction): VoidFunction;
|
|
12
|
+
}, getServerSnapshot?: () => T): T;
|
|
13
|
+
/**
|
|
14
|
+
* @returns Launch parameters from any known source.
|
|
15
|
+
* @param camelCase - should the output be camel-cased.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useLaunchParams(camelCase?: false): RetrieveLaunchParamsResult;
|
|
18
|
+
/**
|
|
19
|
+
* @returns Launch parameters from any known source.
|
|
20
|
+
* @param camelCase - should the output be camel-cased.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useLaunchParams(camelCase: true): DeepConvertSnakeKeysToCamelCase<RetrieveLaunchParamsResult>;
|
|
23
|
+
/**
|
|
24
|
+
* @returns Launch parameters in a raw format from any known source.
|
|
25
|
+
* @see retrieveRawLaunchParams
|
|
26
|
+
*/
|
|
27
|
+
export declare function useRawLaunchParams(): string;
|
|
28
|
+
/**
|
|
29
|
+
* @returns Raw init data from any known source.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useRawInitData(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves Android device data from the navigator.userAgent.
|
|
34
|
+
* @see https://core.telegram.org/bots/webapps#additional-data-in-user-agent
|
|
35
|
+
*/
|
|
36
|
+
export declare function useAndroidDeviceData(): AndroidDeviceData;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves Android device data from the specified User Agent.
|
|
39
|
+
* @see https://core.telegram.org/bots/webapps#additional-data-in-user-agent
|
|
40
|
+
* @param userAgent - user agent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useAndroidDeviceDataFrom(userAgent: string): AndroidDeviceData;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
+
export * from './hooks.js';
|
|
1
2
|
export * from '@tma.js/sdk';
|
|
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
|
-
export { useLaunchParams } from './hooks-hocs/launch-params.js';
|
|
16
|
-
export * from './hooks-hocs/utils.js';
|
|
17
|
-
export * from './hooks-hocs/viewport.js';
|
|
18
|
-
export { useSDK } from './SDKProvider/SDKContext.js';
|
|
19
|
-
export { SDKProvider } from './SDKProvider/SDKProvider.js';
|
|
20
|
-
export type { SDKContextType, SDKContextItem, SDKProviderProps, } from './SDKProvider/SDKProvider.types.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
Please, file an issue here:
|
|
3
|
-
https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,i,h)}}),()=>e.clear(),()=>t.clear());return[{on:t.on.bind(t),off:t.off.bind(t),subscribe(n){return e.on("event",n)},unsubscribe(n){e.off("event",n)},get count(){return t.count+e.count}},s]}const[Us,Ws]=Dt(e=>{const[t,s]=Hs(),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 Us()[0]}function H(e,t){F().off(e,t)}function E(e,t,s){return F().on(e,t,s)}function U(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 m(e,t){return Jt(e,t)<=0}function x(e,t,s){if(typeof s=="string"){if(e==="web_app_open_link"){if(t==="try_instant_view")return m("6.4",s);if(t==="try_browser")return m("7.6",s)}if(e==="web_app_set_header_color"&&t==="color")return m("6.9",s);if(e==="web_app_close"&&t==="return_back")return m("7.6",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 m("6.1",t);case"web_app_open_popup":return m("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 m("6.4",t);case"web_app_switch_inline_query":return m("6.7",t);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return m("6.9",t);case"web_app_setup_settings_button":return m("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 m("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 Yt(e){return"external"in e&&U(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Zt(e){return"TelegramWebviewProxy"in e&&U(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function Q(){try{return window.self!==window.top}catch{return!0}}const js="https://web.telegram.org";let Xt=js;function Gs(e){Xt=e}function te(){return Xt}function A(e,t,s){let n={},i;if(!t&&!s?n={}:t&&s?(n=s,i=t):t&&("targetOrigin"in t?n=t:i=t),Ds("Posting event:",i?{event:e,data:i}:{event:e}),Q())return window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),n.targetOrigin||te());if(Yt(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Zt(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw b($t,"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside the Telegram application environment.")}function ee(e){return(t,s)=>{if(!x(t,e))throw b(Vt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(U(s)&&t==="web_app_set_header_color"&&"color"in s&&!x(t,"color",e))throw b(Lt,`Parameter "color" of "${t}" method is unsupported in Mini Apps version ${e}`);return A(t,s)}}function lt(e){return({req_id:t})=>t===e}function se(e){return b(Ut,`Timeout reached: ${e}ms`)}function dt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n(se(t))},t)})])}async function d(e){let t;const s=new Promise(a=>t=a),{event:n,capture:i,timeout:r}=e,[,o]=ut((Array.isArray(n)?n:[n]).map(a=>E(a,h=>{(!i||(Array.isArray(n)?i({event:a,payload:h}):i(h)))&&t(h)})));try{return(e.postEvent||A)(e.method,e.params),await(r?dt(s,r):s)}finally{o()}}async function T(e,t,s,n={}){const{result:i,error:r}=await d({...n,method:"web_app_invoke_custom_method",event:"custom_method_invoked",params:{method:e,params:t,req_id:s},capture:lt(s)});if(r)throw b(Ht,r);return i}function G(...e){return e.map(t=>{if(typeof t=="string")return t;if(U(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)=>(U(s)&&Object.entries(s).forEach(([n,i])=>{const r=G(t[n],i);r.length&&(t[n]=r)}),t),{})}function J(e){return/^#[\da-f]{6}$/i.test(e)}function ne(e){return/^#[\da-f]{3}$/i.test(e)}function wt(e){const t=e.replace(/\s/g,"").toLowerCase();if(J(t))return t;if(ne(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},"#")}function _t(e){const t=wt(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 I),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 gt{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 ie(e,t){return s=>x(t[s],e)}class ft extends gt{constructor(t,s,n){super(t),c(this,"supports"),this.supports=ie(s,n)}}class re extends ft{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"?H("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 mt=q(e=>e instanceof Date?e:new Date(S().parse(e)*1e3),"Date");function Y(e,t){return new z(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw B();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 Fs=y({id:S(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat").optional(),kt=y({addedToAttachmentMenu:{type:R().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:R().optional(),from:"allows_write_to_pm"},firstName:{type:u(),from:"first_name"},id:S(),isBot:{type:R().optional(),from:"is_bot"},isPremium:{type:R().optional(),from:"is_premium"},languageCode:{type:u().optional(),from:"language_code"},lastName:{type:u().optional(),from:"last_name"},photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"User").optional();function oe(){return Y({authDate:{type:mt(),from:"auth_date"},canSendAfter:{type:S().optional(),from:"can_send_after"},chat:Fs,chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:kt,startParam:{type:u().optional(),from:"start_param"},user:kt},"InitData")}const ae=q(e=>wt(u().parse(e)),"rgb");function Qs(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Js(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const ce=q(e=>{const t=ae().optional();return Object.entries(Ft(e)).reduce((s,[n,i])=>(s[Qs(n)]=t.parse(i),s),{})},"ThemeParams");function Z(e){return Y({botInline:{type:R().optional(),from:"tgWebAppBotInline"},initData:{type:oe().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:R().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:ce(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}}).parse(e)}function he(e){return Z(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function Ys(){return he(window.location.href)}function ue(){return performance.getEntriesByType("navigation")[0]}function Zs(){const e=ue();if(!e)throw new Error("Unable to get first navigation entry.");return he(e.name)}function pe(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function le(e,t){sessionStorage.setItem(pe(e),JSON.stringify(t))}function de(e){const t=sessionStorage.getItem(pe(e));try{return t?JSON.parse(t):void 0}catch{}}function Xs(){return Z(de("launchParams")||"")}function bt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[Js(t),s])))}function we(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:r,startParam:o,botInline:a}=e,h=new URLSearchParams;return h.set("tgWebAppPlatform",n),h.set("tgWebAppThemeParams",bt(s)),h.set("tgWebAppVersion",i),t&&h.set("tgWebAppData",t),o&&h.set("tgWebAppStartParam",o),typeof r=="boolean"&&h.set("tgWebAppShowSettings",r?"1":"0"),typeof a=="boolean"&&h.set("tgWebAppBotInline",a?"1":"0"),h.toString()}function _e(e){le("launchParams",we(e))}function K(){for(const e of[Ys,Zs,Xs])try{const t=e();return _e(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function vt(){const e=ue();return!!(e&&e.type==="reload")}function tn(){let e=0;return()=>(e+=1).toString()}const[en]=Dt(tn);function w(e,t){return()=>{const s=K(),n={...s,postEvent:ee(s.version),createRequestId:en()};if(typeof e=="function")return e(n);const[i,r,o]=ut(),a=t({...n,state:vt()?de(e):void 0,addCleanup:i}),h=p=>(o||i(p.on("change",C=>{le(e,C)})),p);return[a instanceof Promise?a.then(h):h(a),r]}}const ge=w("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new re(s.isVisible,t,e));class W extends ft{constructor(){super(...arguments),c(this,"on",this.state.on.bind(this.state)),c(this,"off",this.state.off.bind(this.state))}}function fe(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 me 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=d({...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=d({...s,postEvent:this.postEvent,method:"web_app_biometry_request_access",event:"biometry_info_received",params:{reason:t||""}}).then(n=>{const i=fe(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 d({...s,postEvent:this.postEvent,method:"web_app_biometry_update_token",event:"biometry_token_updated",params:{token:t||""}})).status)}}async function be(e){return fe(await d({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const ve=w("biometryManager",async({postEvent:e,version:t,state:s})=>new me({...s||x("web_app_biometry_get_info",t)?s||await be({timeout:1e3}):{available:!1,accessGranted:!1,accessRequested:!1,tokenSaved:!1,deviceId:""},version:t,postEvent:e}));class yt extends gt{constructor(){super(...arguments),c(this,"on",this.state.on.bind(this.state)),c(this,"off",this.state.off.bind(this.state))}}class ye 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 Ee=w("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new ye(t.isConfirmationNeeded,e));class Et{constructor(t,s){c(this,"supports"),this.supports=ie(t,s)}}function sn(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 B()}class nn extends z{constructor(t,s,n){super(sn,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 Re(e){return new nn(t=>t,!1,e)}function Bt(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class Pe 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 T("deleteStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent})}async getKeys(t={}){return Re().of(u()).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=y(Bt(n,u()),"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 Se=w(({createRequestId:e,postEvent:t,version:s})=>new Pe(s,e,t));class xe 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 Ce=w(({version:e,postEvent:t})=>new xe(e,t));class Te{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 Ie=w(({initData:e})=>e?new Te(e):void 0);function rn(e){return oe().parse(e)}class Ae 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 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 d({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 ke=w(({version:e,postEvent:t})=>new Ae(!1,e,t));class Be extends gt{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"?H("main_button_pressed",i):this.state.off(n,i)),this.postEvent=t}get bgColor(){return this.get("bgColor")}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.bgColor,text_color:this.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}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")}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})}setBgColor(t){return this.setParams({bgColor:t})}setParams(t){return this.set(t),this.commit(),this}get text(){return this.get("text")}get textColor(){return this.get("textColor")}}const qe=w("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",bgColor:t.buttonColor||"#000000"}})=>new Be({...s,postEvent:e}));function on(){return Y({contact:y({userId:{type:S(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:mt(),from:"auth_date"},hash:u()},"RequestedContact")}function Oe(e,t){return s=>{const[n,i]=t[s];return x(n,i,e)}}function an(e){return new Promise(t=>{setTimeout(t,e)})}class De 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 o=this.supports.bind(this);this.supports=a=>o(a)?a!=="switchInlineQuery"||i:!1,this.supportsParam=Oe(n,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:t=1e4}={}){return on().parse(await T("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:t}))}get bgColor(){return this.get("bgColor")}close(t){this.postEvent("web_app_close",{return_back:t})}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 dt(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await an(n),n+=50}throw se(t)},t)}async requestPhoneAccess(t={}){return this.requestPhoneAccessPromise||(this.requestPhoneAccessPromise=d({...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=d({...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",J(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 Me=w("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new De({...n,...s,botInline:t}));function cn(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 h=r.type||"default";throw new Error(`Button text with type "${h}" 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 Ne 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 d({event:"popup_closed",method:"web_app_open_popup",postEvent:this.postEvent,params:cn(t)});return s}finally{this.isOpened=!1}}}const Ve=w(({postEvent:e,version:t})=>new Ne(!1,t,e));class Le 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("The scanner is already opened");const{text:s,capture:n}=(typeof t=="string"?{text:t}:t)||{};this.isOpened=!0;try{const i=(await d({method:"web_app_open_scan_qr_popup",event:["qr_text_received","scan_qr_popup_closed"],postEvent:this.postEvent,params:{text:s},capture(r){return r.event==="scan_qr_popup_closed"||!n||n(r.payload)}})||{}).data||null;return i&&this.close(),i}finally{this.isOpened=!1}}}const $e=w(({version:e,postEvent:t})=>new Le(!1,e,t));class He extends ft{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"?H("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 Ue=w("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new He(s.isVisible,e,t));function Rt(e){return ce().parse(e)}class We 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")}get sectionSeparatorColor(){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 je=w("themeParams",({themeParams:e,state:t=e,addCleanup:s})=>{const n=new We(t);return s(n.listen()),n});function hn(e={}){return d({...e,method:"web_app_request_theme",event:"theme_changed"}).then(Rt)}function V(e,t){return e.startsWith(t)?e:`${t}${e}`}function k(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${V(e.search||"","?")}${V(e.hash||"","#")}`,"http://a")}class Ge extends Et{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=Oe(t,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(t,s){const n=k(t).toString();if(!x("web_app_open_link",this.version)){window.open(n,"_blank");return}const i=typeof s=="boolean"?{tryInstantView:s}:s||{};this.postEvent("web_app_open_link",{url:n,try_browser:i.tryBrowser,try_instant_view:i.tryInstantView})}openTelegramLink(t){const{hostname:s,pathname:n,search:i}=new URL(t,"https://t.me");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 d({method:"web_app_read_text_from_clipboard",event:"clipboard_text_received",postEvent:this.postEvent,params:{req_id:t},capture:lt(t)});return s}shareURL(t,s){this.openTelegramLink("https://t.me/share/url?"+new URLSearchParams({url:t,text:s||""}).toString().replace(/\+/g,"%20"))}}const Ke=w(({version:e,postEvent:t,createRequestId:s})=>new Ge(e,s,t));async function Pt(e={}){const{is_expanded:t,is_state_stable:s,...n}=await d({...e,method:"web_app_request_viewport",event:"viewport_changed"});return{...n,isExpanded:t,isStateStable:s}}function M(e){return e<0?0:e}class ze extends yt{constructor({postEvent:t,stableHeight:s,height:n,width:i,isExpanded:r}){super({height:M(n),isExpanded:r,stableHeight:M(s),width:M(i)}),c(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=M(s);this.set({height:o,isExpanded:i,width:M(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}}const Fe=w("viewport",async({state:e,platform:t,postEvent:s,addCleanup:n})=>{let i=!1,r=0,o=0,a=0;if(e)i=e.isExpanded,r=e.height,o=e.width,a=e.stableHeight;else if(["macos","tdesktop","unigram","webk","weba","web"].includes(t))i=!0,r=window.innerHeight,o=window.innerWidth,a=window.innerHeight;else{const p=await Pt({timeout:1e3,postEvent:s});i=p.isExpanded,r=p.height,o=p.width,a=p.isStateStable?r:0}const h=new ze({postEvent:s,height:r,width:o,stableHeight:a,isExpanded:i});return n(h.listen()),h});function P(e,t){document.documentElement.style.setProperty(e,t)}function un(e,t,s){s||(s=a=>`--tg-${a}-color`);const n=s("header"),i=s("bg"),r=()=>{const{headerColor:a}=e;if(J(a))P(n,a);else{const{bgColor:h,secondaryBgColor:p}=t;a==="bg_color"&&h?P(n,h):a==="secondary_bg_color"&&p&&P(n,p)}P(i,e.bgColor)},o=[t.on("change",r),e.on("change",r)];return r(),()=>o.forEach(a=>a())}function pn(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&&P(t(n),i)})};return s(),e.on("change",s)}function ln(e,t){t||(t=p=>`--tg-viewport-${p}`);const[s,n,i]=["height","width","stable-height"].map(p=>t(p)),r=()=>P(s,`${e.height}px`),o=()=>P(n,`${e.width}px`),a=()=>P(i,`${e.stableHeight}px`),h=[e.on("change:height",r),e.on("change:width",o),e.on("change:stableHeight",a)];return r(),o(),a(),()=>h.forEach(p=>p())}function Qe(e=!0){const t=[E("reload_iframe",()=>{A("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 A("iframe_ready",{reload_supported:!0}),s}function Je(){return typeof window>"u"}async function dn(){if(Zt(window))return!0;try{return await d({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function wn(e){const t=typeof e=="string"?Z(e):e;_e(t);function s(i){if(typeof i=="string")try{const{eventType:r}=Qt(i);r==="web_app_request_theme"&&at("theme_changed",{theme_params:JSON.parse(bt(t.themeParams))}),r==="web_app_request_viewport"&&at("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}catch{}}if(Q()){const i=window.parent.postMessage.bind(window.parent);window.parent.postMessage=r=>{s(r),i(r)};return}if(Yt(window)){const i=window.external.notify.bind(window.external);window.external.notify=r=>{s(r),i(r)};return}const n=window.TelegramWebviewProxy;window.TelegramWebviewProxy={...n||{},postEvent(...i){s(JSON.stringify({eventType:i[0],eventData:i[1]})),n&&n.postEvent(...i)}}}function Ye(e){return e instanceof $}function _n(e,t){return Ye(e)&&e.type===t}function tt(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 Ze{constructor(t,s,n=A){if(c(this,"history"),c(this,"ee",new I),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 b(jt,"History should not be empty.");if(s<0||s>=t.length)throw b(Gt,"Index should not be zero and higher or equal than history size.");this.history=t.map(i=>tt(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,H("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,tt(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,tt(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 et({params:e,...t}){return{...e||{hash:"",search:""},...t}}function L(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=k(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function st(e,t,s){let n,i;typeof e=="string"?n=e:(n=L(e),s=e.state,i=e.id);const{pathname:r,search:o,hash:a}=new URL(n,`http://a${V(t,"/")}`);return{id:i,pathname:r,params:{hash:a,search:o,state:s}}}async function N(e){return e===0?!0:Promise.race([new Promise(t=>{const s=ot("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function gn(){if(window.history.length<=1||(window.history.pushState(null,""),await N(1-window.history.length)))return;let e=await N(-1);for(;e;)e=await N(-1)}function St(e){return k(e).pathname}const qt=0,nt=1,it=2;class xt{constructor(t,s,{postEvent:n,hashMode:i="classic",base:r}={}){c(this,"navigator"),c(this,"ee",new I),c(this,"hashMode"),c(this,"base"),c(this,"attached",!1),c(this,"onPopState",({state:o})=>{if(o===null)return this.push(this.parsePath(window.location.href));o===qt?window.history.forward():o===nt&&this.back(),o===it&&this.forward()}),c(this,"onNavigatorChange",async({to:o,from:a,delta:h})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:h,from:et(a),to:et(o),navigator:this})}),c(this,"on",this.ee.on.bind(this.ee)),c(this,"off",this.ee.off.bind(this.ee)),this.navigator=new Ze(t.map(o=>st(o,"/")),s,n),this.navigator.on("change",o=>{this.onNavigatorChange(o)}),this.hashMode=i,this.base=St(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(et)}get path(){return L(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=k(t);return this.hashMode&&(s=k(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=st(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=st(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)+V(L(t),"/");return this.hashMode?V(s.slice(1),this.hashMode==="classic"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await gn(),this.hasPrev&&this.hasNext?(window.history.replaceState(nt,""),window.history.pushState(t,"",s),window.history.pushState(it,""),await N(-1)):this.hasPrev?(window.history.replaceState(nt,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(it,""),await N(-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 Xe(e){e||(e={});const{href:t,hash:s}=window.location;let n=L(e.hashMode===null?t:s.includes("?")?s.slice(1):`?${s.slice(1)}`);const i=e.base?St(e.base):void 0;if(i){if(!n.startsWith(i))throw b(Kt,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new xt([n],0,e)}function fn(e){const t=e.match(/#(.+)/);return t?t[1]:null}function mn(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 Xe(t)}function bn(e,t){const s=mn(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}function _(e,t){function s(n){return function(r,o,a){return h=>{const p={...h,[r]:n(o)};return Ot.jsx(a,{...p})}}}return[s(e),s(t)]}const ts=l.createContext(void 0);function es(){const e=l.useContext(ts);if(!e)throw new Error("useSDK was used outside the SDKProvider.");return e}function g(e){function t(n){const i=es(),[r,o]=l.useState(n?void 0:()=>{if(Je())throw new Error("Using hooks on the server side, you must explicitly specify ssr = true option");return i.use(e)});return l.useEffect(()=>{o(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[ss,ns]=g(ge),[vn,yn]=_(ss,ns),[is,rs]=g(ve),[En,Rn]=_(is,rs),[os,as]=g(Ee),[Pn,Sn]=_(os,as),[cs,hs]=g(Se),[xn,Cn]=_(cs,hs),[us,ps]=g(Ce),[Tn,In]=_(us,ps),[ls,ds]=g(Ie),[An,kn]=_(ls,ds),[ws,_s]=g(ke),[Bn,qn]=_(ws,_s),[gs,fs]=g(qe),[On,Dn]=_(gs,fs),[ms,bs]=g(Me),[Mn,Nn]=_(ms,bs),[vs,ys]=g(Ve),[Vn,Ln]=_(vs,ys),[Es,Rs]=g($e),[$n,Hn]=_(Es,Rs),[Ps,Ss]=g(Ue),[Un,Wn]=_(Ps,Ss),[xs,Cs]=g(je),[jn,Gn]=_(xs,Cs);function Kn(e){const[t,s]=l.useState(()=>e?void 0:K());return l.useEffect(()=>{e&&s(K())},[]),t}const[Ts,Is]=g(Ke),[zn,Fn]=_(Ts,Is),[As,ks]=g(Fe),[Qn,Jn]=_(As,ks);function Yn({children:e,acceptCustomStyles:t,debug:s}){const n=l.useRef(!0),[i,r]=l.useState(new Map),o=l.useRef(i),a=l.useCallback(p=>{n.current&&r(C=>(p&&p(C),new Map(C)))},[]),h=l.useMemo(()=>({use(p,...C){const Ct=i.get(p);if(Ct)return Ct;let v,X;try{v=p(...C)}catch(f){X=f}function j(f){return i.set(p,f),f}if(X)return j({error:X});let O;if(Array.isArray(v)&&(O=v[1],v=v[0]),!v)return j({result:v,cleanup:O});function Tt(f){if("on"in f){const D=f.on("change",()=>a()),It=O;O=()=>{It&&It(),D()}}return{result:f,cleanup:O}}return v instanceof Promise?(v.then(f=>a(D=>D.set(p,Tt(f))),f=>a(D=>D.set(p,{error:f}))),j({})):j(Tt(v))}}),[i]);return l.useEffect(()=>(n.current=!0,()=>{n.current=!1}),[]),l.useEffect(()=>{if(Q())return Qe(t)},[t]),l.useEffect(()=>{Nt(s||!1)},[s]),l.useEffect(()=>{o.current=i},[i]),l.useEffect(()=>()=>{o.current.forEach(p=>{"cleanup"in p&&p.cleanup&&p.cleanup()})},[]),Ot.jsx(ts.Provider,{value:h,children:e})}exports.BackButton=re;exports.BasicNavigator=Ze;exports.BiometryManager=me;exports.BrowserNavigator=xt;exports.ClosingBehavior=ye;exports.CloudStorage=Pe;exports.ERR_INVALID_PATH_BASE=Kt;exports.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Ht;exports.ERR_METHOD_PARAMETER_UNSUPPORTED=Lt;exports.ERR_METHOD_UNSUPPORTED=Vt;exports.ERR_NAVIGATION_HISTORY_EMPTY=jt;exports.ERR_NAVIGATION_INDEX_INVALID=Gt;exports.ERR_NAVIGATION_ITEM_INVALID=Ms;exports.ERR_PARSE=pt;exports.ERR_SSR_INIT=Ns;exports.ERR_TIMED_OUT=Ut;exports.ERR_UNEXPECTED_TYPE=Wt;exports.ERR_UNKNOWN_ENV=$t;exports.EventEmitter=I;exports.HapticFeedback=xe;exports.InitData=Te;exports.Invoice=Ae;exports.MainButton=Be;exports.MiniApp=De;exports.Popup=Ne;exports.QRScanner=Le;exports.SDKError=$;exports.SDKProvider=Yn;exports.SettingsButton=He;exports.ThemeParams=We;exports.Utils=Ge;exports.Viewport=ze;exports.array=Re;exports.bindMiniAppCSSVars=un;exports.bindThemeParamsCSSVars=pn;exports.bindViewportCSSVars=ln;exports.boolean=R;exports.captureSameReq=lt;exports.classNames=G;exports.compareVersions=Jt;exports.createBrowserNavigatorFromLocation=Xe;exports.createPostEvent=ee;exports.createSafeURL=k;exports.date=mt;exports.getHash=fn;exports.getPathname=St;exports.initBackButton=ge;exports.initBiometryManager=ve;exports.initClosingBehavior=Ee;exports.initCloudStorage=Se;exports.initHapticFeedback=Ce;exports.initInitData=Ie;exports.initInvoice=ke;exports.initMainButton=qe;exports.initMiniApp=Me;exports.initNavigator=bn;exports.initPopup=Ve;exports.initQRScanner=$e;exports.initSettingsButton=Ue;exports.initThemeParams=je;exports.initUtils=Ke;exports.initViewport=Fe;exports.initWeb=Qe;exports.invokeCustomMethod=T;exports.isColorDark=_t;exports.isIframe=Q;exports.isPageReload=vt;exports.isRGB=J;exports.isRGBShort=ne;exports.isSDKError=Ye;exports.isSDKErrorOfType=_n;exports.isSSR=Je;exports.isTMA=dn;exports.json=y;exports.mergeClassNames=Ks;exports.mockTelegramEnv=wn;exports.number=S;exports.off=H;exports.on=E;exports.parseInitData=rn;exports.parseLaunchParams=Z;exports.parseThemeParams=Rt;exports.postEvent=A;exports.request=d;exports.requestBiometryInfo=be;exports.requestThemeParams=hn;exports.requestViewport=Pt;exports.retrieveLaunchParams=K;exports.rgb=ae;exports.searchParams=Y;exports.serializeLaunchParams=we;exports.serializeThemeParams=bt;exports.setCSSVar=P;exports.setDebug=Nt;exports.setTargetOrigin=Gs;exports.string=u;exports.subscribe=Mt;exports.supports=x;exports.targetOrigin=te;exports.toRGB=wt;exports.unsubscribe=ct;exports.urlToPath=L;exports.useBackButton=ns;exports.useBackButtonRaw=ss;exports.useBiometryManager=rs;exports.useBiometryManagerRaw=is;exports.useClosingBehavior=as;exports.useClosingBehaviorRaw=os;exports.useCloudStorage=hs;exports.useCloudStorageRaw=cs;exports.useHapticFeedback=ps;exports.useHapticFeedbackRaw=us;exports.useInitData=ds;exports.useInitDataRaw=ls;exports.useInvoice=_s;exports.useInvoiceRaw=ws;exports.useLaunchParams=Kn;exports.useMainButton=fs;exports.useMainButtonRaw=gs;exports.useMiniApp=bs;exports.useMiniAppRaw=ms;exports.usePopup=ys;exports.usePopupRaw=vs;exports.useQRScanner=Rs;exports.useQRScannerRaw=Es;exports.useSDK=es;exports.useSettingsButton=Ss;exports.useSettingsButtonRaw=Ps;exports.useThemeParams=Cs;exports.useThemeParamsRaw=xs;exports.useUtils=Is;exports.useUtilsRaw=Ts;exports.useViewport=ks;exports.useViewportRaw=As;exports.withBackButton=yn;exports.withBackButtonRaw=vn;exports.withBiometryManager=Rn;exports.withBiometryManagerRaw=En;exports.withClosingBehavior=Sn;exports.withClosingBehaviorRaw=Pn;exports.withCloudStorage=Cn;exports.withCloudStorageRaw=xn;exports.withHapticFeedback=In;exports.withHapticFeedbackRaw=Tn;exports.withInitData=kn;exports.withInitDataRaw=An;exports.withInvoice=qn;exports.withInvoiceRaw=Bn;exports.withMainButton=Dn;exports.withMainButtonRaw=On;exports.withMiniApp=Nn;exports.withMiniAppRaw=Mn;exports.withPopup=Ln;exports.withPopupRaw=Vn;exports.withQRScanner=Hn;exports.withQRScannerRaw=$n;exports.withSettingsButton=Wn;exports.withSettingsButtonRaw=Un;exports.withThemeParams=Gn;exports.withThemeParamsRaw=jn;exports.withTimeout=dt;exports.withUtils=Fn;exports.withUtilsRaw=zn;exports.withViewport=Jn;exports.withViewportRaw=Qn;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),r=require("@tma.js/sdk");function n(e,t){return a.useSyncExternalStore(u=>e.sub(u),e,t||e)}function o(e){return a.useMemo(()=>{const t=r.retrieveLaunchParams();return e?r.deepSnakeToCamelObjKeys(t):t},[e])}function i(){return a.useMemo(r.retrieveRawLaunchParams,[])}function s(){return a.useMemo(r.retrieveRawInitData,[])}function c(){return a.useMemo(r.retrieveAndroidDeviceData,[])}function d(e){return a.useMemo(()=>r.retrieveAndroidDeviceDataFrom(e),[e])}exports.useAndroidDeviceData=c;exports.useAndroidDeviceDataFrom=d;exports.useLaunchParams=o;exports.useRawInitData=s;exports.useRawLaunchParams=i;exports.useSignal=n;Object.keys(r).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
|
|
4
2
|
//# sourceMappingURL=index.cjs.map
|