@tma.js/sdk 0.13.1 → 0.13.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/components/ThemeParams/ThemeParams.d.ts +14 -2
- package/dist/dts/components/ThemeParams/types.d.ts +1 -4
- package/dist/dts/init/css.d.ts +3 -10
- package/dist/dts/state/State.d.ts +4 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +339 -346
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/components/ThemeParams/ThemeParams.ts +45 -43
- package/src/components/ThemeParams/types.ts +1 -8
- package/src/init/css.ts +11 -35
- package/src/state/State.ts +9 -5
|
@@ -29,6 +29,7 @@ export declare class ThemeParams {
|
|
|
29
29
|
private readonly ee;
|
|
30
30
|
private readonly state;
|
|
31
31
|
constructor(params: ThemeParamsType);
|
|
32
|
+
get accentTextColor(): RGB | null;
|
|
32
33
|
/**
|
|
33
34
|
* Returns background color.
|
|
34
35
|
*/
|
|
@@ -41,6 +42,14 @@ export declare class ThemeParams {
|
|
|
41
42
|
* Returns button text color.
|
|
42
43
|
*/
|
|
43
44
|
get buttonTextColor(): RGB | null;
|
|
45
|
+
get destructiveTextColor(): RGB | null;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves palette color value by its name.
|
|
48
|
+
* @param key - palette key name.
|
|
49
|
+
*/
|
|
50
|
+
get(key: keyof ThemeParamsType): RGB | null;
|
|
51
|
+
getState(): ThemeParamsType;
|
|
52
|
+
get headerBackgroundColor(): RGB | null;
|
|
44
53
|
/**
|
|
45
54
|
* Returns hint color.
|
|
46
55
|
*/
|
|
@@ -57,15 +66,18 @@ export declare class ThemeParams {
|
|
|
57
66
|
/**
|
|
58
67
|
* Adds new event listener.
|
|
59
68
|
*/
|
|
60
|
-
on: <E extends
|
|
69
|
+
on: <E extends `${string}Changed` | "changed">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => import("@tma.js/event-emitter").RemoveEventListener;
|
|
61
70
|
/**
|
|
62
71
|
* Removes event listener.
|
|
63
72
|
*/
|
|
64
|
-
off: <E extends
|
|
73
|
+
off: <E extends `${string}Changed` | "changed">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
|
|
65
74
|
/**
|
|
66
75
|
* Returns secondary background color.
|
|
67
76
|
*/
|
|
68
77
|
get secondaryBackgroundColor(): RGB | null;
|
|
78
|
+
get sectionBackgroundColor(): RGB | null;
|
|
79
|
+
get sectionHeaderTextColor(): RGB | null;
|
|
80
|
+
get subtitleTextColor(): RGB | null;
|
|
69
81
|
/**
|
|
70
82
|
* Returns text color.
|
|
71
83
|
*/
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { HasUndefined, If } from '@tma.js/util-types';
|
|
2
1
|
import type { ThemeParams } from '@tma.js/theme-params';
|
|
3
2
|
import type { StateEvents } from '../../state/index.js';
|
|
4
|
-
export type ThemeParamsState =
|
|
5
|
-
[K in keyof ThemeParams]-?: If<HasUndefined<ThemeParams[K]>, Exclude<ThemeParams[K], undefined> | null, ThemeParams[K]>;
|
|
6
|
-
};
|
|
3
|
+
export type ThemeParamsState = ThemeParams;
|
|
7
4
|
export type ThemeParamsEvents = StateEvents<ThemeParamsState>;
|
|
8
5
|
export type ThemeParamsEventName = keyof ThemeParamsEvents;
|
|
9
6
|
export type ThemeParamsEventListener<E extends ThemeParamsEventName> = ThemeParamsEvents[E];
|
package/dist/dts/init/css.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import type { ThemeParams, WebApp, Viewport } from '../components/index.js';
|
|
2
2
|
import type { InitCSSVarsOption, InitCSSVarsSpecificOption } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Creates CSS variables connected with theme parameters.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - `--tg-theme-bg-color`
|
|
8
|
-
* - `--tg-theme-button-color`
|
|
9
|
-
* - `--tg-theme-button-text-color`
|
|
10
|
-
* - `--tg-theme-hint-color`
|
|
11
|
-
* - `--tg-theme-link-color`
|
|
12
|
-
* - `--tg-theme-secondary-bg-color`
|
|
13
|
-
* - `--tg-theme-text-color`
|
|
4
|
+
* Creates CSS variables connected with theme parameters. Created CSS variables names are
|
|
5
|
+
* following the pattern "--tg-theme-{name}". {name} is a theme parameters key name converted
|
|
6
|
+
* from snake to kebab case.
|
|
14
7
|
*
|
|
15
8
|
* Variables are being automatically updated in case, corresponding properties
|
|
16
9
|
* updated in passed ThemeParams instance.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventEmitter } from '@tma.js/event-emitter';
|
|
2
|
-
import type { StateEvents
|
|
2
|
+
import type { StateEvents } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents state which is observable via passed EventEmitter.
|
|
5
5
|
*/
|
|
@@ -9,7 +9,8 @@ export declare class State<S extends object> {
|
|
|
9
9
|
constructor(state: S, ee?: EventEmitter<StateEvents<S>> | undefined);
|
|
10
10
|
private emit;
|
|
11
11
|
private internalSet;
|
|
12
|
-
set<K extends
|
|
12
|
+
set<K extends keyof S>(key: K, value: S[K]): void;
|
|
13
13
|
set(state: Partial<S>): void;
|
|
14
|
-
get<K extends
|
|
14
|
+
get<K extends keyof S>(key: K): Readonly<S[K]>;
|
|
15
|
+
getState(): S;
|
|
15
16
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ut=Object.defineProperty;var lt=(s,t,e)=>t in s?ut(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(lt(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@tma.js/launch-params"),m=require("@tma.js/event-emitter"),a=require("@tma.js/bridge"),P=require("@tma.js/parsing"),L=require("@tma.js/theme-params"),A=require("@tma.js/colors"),U=require("@tma.js/utils");function C(s,t){return e=>a.supports(t[e],s)}function pt(s,t){return e=>{const[o,n]=t[e];return a.supports(o,n,s)}}class f{constructor(t,e){this.state=t,this.ee=e}emit(t,e){this.ee&&this.ee.emit(t,e)}internalSet(t,e){return this.state[t]===e?!1:(this.state[t]=e,this.emit(`${t}Changed`,e),!0)}set(t,e){let o=!1;if(typeof t=="string")o=this.internalSet(t,e);else for(const n in t)this.internalSet(n,t[n])&&(o=!0);o&&this.emit("changed")}get(t){return this.state[t]}}class F{constructor(t,e,o=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",(t,e)=>t==="click"?a.on("back_button_pressed",e):this.ee.on(t,e));i(this,"off",(t,e)=>{if(t==="click")return a.off("back_button_pressed",e);this.ee.off(t,e)});i(this,"supports");this.postEvent=o,this.state=new f({isVisible:t},this.ee),this.supports=C(e,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(t){this.state.set("isVisible",t),this.postEvent("web_app_setup_back_button",{is_visible:t})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}class K{constructor(t,e=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=e,this.state=new f({isConfirmationNeeded:t},this.ee)}set isConfirmationNeeded(t){this.state.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const dt=P.array().of(P.string());function N(s,t){return s.reduce((e,o)=>(e[o]=t,e),{})}class j{constructor(t,e,o=a.postEvent){i(this,"supports");this.createRequestId=e,this.postEvent=o,this.supports=C(t,{deleteKeys:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",getValues:"web_app_invoke_custom_method",saveValue:"web_app_invoke_custom_method"})}async invokeCustomMethod(t,e,o={}){const{result:n,error:r}=await a.request("web_app_invoke_custom_method",{method:t,params:e,req_id:this.createRequestId()},"custom_method_invoked",{...o,postEvent:this.postEvent});if(r)throw new Error(typeof r=="string"?r:`Unknown error: ${JSON.stringify(r)}`);return n}async deleteKeys(t,e){t.length!==0&&await this.invokeCustomMethod("deleteStorageValues",{keys:t},e)}async getKeys(t){const e=await this.invokeCustomMethod("getStorageKeys",{},t);return dt.parse(e)}async getValues(t,e){if(t.length===0)return N(t,"");const o=P.json(N(t,P.string())),n=await this.invokeCustomMethod("getStorageValues",{keys:t},e);return o.parse(n)}async saveValue(t,e,o){await this.invokeCustomMethod("saveStorageValue",{key:t,value:e},o)}}class J{constructor(t,e=a.postEvent){i(this,"supports");this.postEvent=e,this.supports=C(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:t})}notificationOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:t})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}class Q{constructor(t,e,o={}){i(this,"state");const{chat:n=null,canSendAfter:r=null,chatType:c=null,chatInstance:u=null,user:h=null,queryId:p=null,receiver:l=null,startParam:d=null}=o;this.state=new f({authDate:t,canSendAfter:r===null?null:new Date(t.getTime()+r*1e3),chat:n,chatType:c,chatInstance:u,user:h,queryId:p,receiver:l,startParam:d,hash:e})}get authDate(){return this.state.get("authDate")}get canSendAfter(){return this.state.get("canSendAfter")}get chat(){return this.state.get("chat")}get chatType(){return this.state.get("chatType")}get chatInstance(){return this.state.get("chatInstance")}get hash(){return this.state.get("hash")}get queryId(){return this.state.get("queryId")}get receiver(){return this.state.get("receiver")}get startParam(){return this.state.get("startParam")}get user(){return this.state.get("user")}}class G{constructor(t,e,o,n,r,c,u=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",(t,e)=>t==="click"?a.on("main_button_pressed",e):this.ee.on(t,e));i(this,"off",(t,e)=>{if(t==="click")return a.off("main_button_pressed",e);this.ee.off(t,e)});this.postEvent=u,this.state=new f({backgroundColor:t,isEnabled:e,isVisible:o,isProgressVisible:n,text:r,textColor:c},this.ee)}set isEnabled(t){this.state.set("isEnabled",t),this.commit()}get isEnabled(){return this.state.get("isEnabled")}set isProgressVisible(t){this.state.set("isProgressVisible",t),this.commit()}get isProgressVisible(){return this.state.get("isProgressVisible")}set isVisible(t){this.state.set("isVisible",t),this.commit()}get isVisible(){return this.state.get("isVisible")}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isProgressVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideProgress(){return this.isProgressVisible=!1,this}show(){return this.isVisible=!0,this}showProgress(){return this.isProgressVisible=!0,this}setText(t){return this.state.set("text",t),this.commit(),this}setTextColor(t){return this.state.set("textColor",t),this.commit(),this}setBackgroundColor(t){return this.state.set("backgroundColor",t),this.commit(),this}}function gt(s){const t=s.message.trim(),e=(s.title||"").trim(),o=s.buttons||[];let n;if(e.length>64)throw new Error(`Title has incorrect size: ${e.length}`);if(t.length===0||t.length>256)throw new Error(`Message has incorrect size: ${t.length}`);if(o.length>3)throw new Error(`Buttons have incorrect size: ${o.length}`);return o.length===0?n=[{type:"close",id:""}]:n=o.map(r=>{const{id:c=""}=r;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(r.type===void 0||r.type==="default"||r.type==="destructive"){const u=r.text.trim();if(u.length===0||u.length>64){const h=r.type||"default";throw new Error(`Button text with type "${h}" has incorrect size: ${r.text.length}`)}return{...r,text:u,id:c}}return{...r,id:c}}),{title:e,message:t,buttons:n}}class Z{constructor(t,e=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new f({isOpened:!1},this.ee),this.supports=C(t,{open:"web_app_open_popup"})}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.state.set("isOpened",!0);try{const{button_id:e=null}=await a.request("web_app_open_popup",gt(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class X{constructor(t,e=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new f({isOpened:!1},this.ee),this.supports=C(t,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.state.set("isOpened",t)}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const e=await a.request("web_app_open_scan_qr_popup",{text:t},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof e=="object"&&typeof e.data=="string"?e.data:null}finally{this.isOpened=!1}}}function z(s){const{accentTextColor:t=null,backgroundColor:e=null,buttonColor:o=null,buttonTextColor:n=null,destructiveTextColor:r=null,headerBackgroundColor:c=null,hintColor:u=null,linkColor:h=null,secondaryBackgroundColor:p=null,sectionBackgroundColor:l=null,sectionHeaderTextColor:d=null,subtitleTextColor:b=null,textColor:V=null}=s;return{accentTextColor:t,backgroundColor:e,buttonColor:o,buttonTextColor:n,destructiveTextColor:r,headerBackgroundColor:c,hintColor:u,linkColor:h,secondaryBackgroundColor:p,sectionBackgroundColor:l,sectionHeaderTextColor:d,subtitleTextColor:b,textColor:V}}class y{constructor(t){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.state=new f(z(t),this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,n=await a.request("web_app_request_theme","theme_changed",{...o,timeout:e});return L.parse(n.theme_params)}static sync(t){a.on("theme_changed",e=>{t.state.set(z(L.parse(e.theme_params)))})}static async synced(t){const e=await this.request(t),o=new y(e);return this.sync(o),o}get backgroundColor(){return this.state.get("backgroundColor")}get buttonColor(){return this.state.get("buttonColor")}get buttonTextColor(){return this.state.get("buttonTextColor")}get hintColor(){return this.state.get("hintColor")}get isDark(){return this.backgroundColor===null||A.isColorDark(this.backgroundColor)}get linkColor(){return this.state.get("linkColor")}get secondaryBackgroundColor(){return this.state.get("secondaryBackgroundColor")}get textColor(){return this.state.get("textColor")}}function E(s){return s<0?0:s}class w{constructor(t,e,o,n,r=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=r,this.state=new f({height:E(t),isExpanded:n,stableHeight:E(o),width:E(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,{is_expanded:n,is_state_stable:r,...c}=await a.request("web_app_request_viewport","viewport_changed",{...o,timeout:e});return{...c,isExpanded:n,isStateStable:r}}static sync(t){a.on("viewport_changed",e=>{const{height:o,width:n,is_expanded:r,is_state_stable:c}=e,u=E(o);t.state.set({height:u,isExpanded:r,width:E(n),stableHeight:c?u:void 0})})}static async synced(t={}){const{height:e,isExpanded:o,width:n}=await this.request(t),r=new w(e,n,e,o,t.postEvent);return this.sync(r),r}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.state.set("isExpanded",!0),this.postEvent("web_app_expand")}get isStable(){return this.stableHeight===this.height}}function S(s){const t=document.createElement("a");if(t.href=s,t.protocol!=="http:"&&t.protocol!=="https:")throw Error(`URL protocol is not supported by OS, or link has not allowed protocol: ${t.protocol}`);return t.href}class Y{constructor(t,e,o,n,r,c=a.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");i(this,"supportsParam");this.currentVersion=o,this.currentPlatform=n,this.createRequestId=r,this.postEvent=c,this.state=new f({backgroundColor:e,headerColor:t},this.ee),this.supports=C(o,{openInvoice:"web_app_open_invoice",readTextFromClipboard:"web_app_read_text_from_clipboard",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color",requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access"}),this.supportsParam=pt(o,{"setHeaderColor.color":["web_app_set_header_color","color"],"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}get backgroundColor(){return this.state.get("backgroundColor")}get colorScheme(){return A.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return U.compareVersions(t,this.version)>=0}openLink(t,e){const o=S(t);if(!a.supports("web_app_open_link",this.version)){window.open(o,"_blank");return}return this.postEvent("web_app_open_link",{url:o,...typeof e=="boolean"?{try_instant_view:e}:{}})}openTelegramLink(t){const{hostname:e,pathname:o,search:n}=new URL(S(t));if(e!=="t.me")throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);if(!a.supports("web_app_open_tg_link",this.version)){window.location.href=t;return}return this.postEvent("web_app_open_tg_link",{path_full:o+n})}async openInvoice(t){const{hostname:e,pathname:o}=new URL(S(t));if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const n=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(n===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,r]=n;return(await a.request("web_app_open_invoice",{slug:r},"invoice_closed",{postEvent:this.postEvent,capture:({slug:u})=>r===u})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:t=null}=await a.request("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent});return t}async requestPhoneAccess(){const{status:t}=await a.request("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return t}async requestWriteAccess(){const{status:t}=await a.request("web_app_request_write_access","write_access_requested",{postEvent:this.postEvent});return t}sendData(t){const{size:e}=new Blob([t]);if(e===0||e>4096)throw new Error(`Passed data has incorrect size: ${e}`);this.postEvent("web_app_data_send",{data:t})}setHeaderColor(t){this.postEvent("web_app_set_header_color",A.isRGB(t)?{color:t}:{color_key:t}),this.state.set("headerColor",t)}setBackgroundColor(t){this.postEvent("web_app_set_background_color",{color:t}),this.state.set("backgroundColor",t)}get version(){return this.currentVersion}}class I extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Mini Apps version ${e}.`),Object.setPrototypeOf(this,I.prototype)}}class H extends Error{constructor(t,e,o){super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`),Object.setPrototypeOf(this,H.prototype)}}function tt(s,t){document.documentElement.style.setProperty(s,t)}function _(s,t){t!==null&&tt(s,t)}function W(s,t){tt(s,`${t}px`)}function bt(s){const{backgroundColor:t,buttonTextColor:e,secondaryBackgroundColor:o,hintColor:n,buttonColor:r,linkColor:c,textColor:u}=s;_("--tg-theme-bg-color",t),_("--tg-theme-button-color",r),_("--tg-theme-button-text-color",e),_("--tg-theme-hint-color",n),_("--tg-theme-link-color",c),_("--tg-theme-secondary-bg-color",o),_("--tg-theme-text-color",u)}function _t(s,t){const{backgroundColor:e,secondaryBackgroundColor:o}=t,{backgroundColor:n,headerColor:r}=s;_("--tg-bg-color",n),_("--tg-header-color",r==="bg_color"?e:o)}function ft(s){const t=()=>bt(s);s.on("changed",t),t()}function mt(s,t){const e=()=>_t(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function wt(s){const t=()=>{W("--tg-viewport-height",s.height)},e=()=>{W("--tg-viewport-stable-height",s.stableHeight)};s.on("heightChanged",t),s.on("stableHeightChanged",e),t(),e()}function Ct(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function et(s){return`telegram-mini-apps-${s}`}function k(s,t){sessionStorage.setItem(et(s),JSON.stringify(t))}function x(s){const t=sessionStorage.getItem(et(s));return t?JSON.parse(t):null}function vt(s,t,e){const{isVisible:o=!1}=s?x("back-button")||{}:{},n=new F(o,t,e);return n.on("isVisibleChanged",()=>{k("back-button",{isVisible:n.isVisible})}),n}function Et(s,t){const{isConfirmationNeeded:e=!1}=s?x("closing-behavior")||{}:{},o=new K(e,t);return o.on("isConfirmationNeededChanged",()=>k("closing-behavior",{isConfirmationNeeded:o.isConfirmationNeeded})),o}function yt(s,t,e,o){const{backgroundColor:n=t,isEnabled:r=!1,isVisible:c=!1,isProgressVisible:u=!1,textColor:h=e,text:p=""}=s?x("main-button")||{}:{},l=new G(n,r,c,u,p,h,o),d=()=>k("main-button",{backgroundColor:l.backgroundColor,isEnabled:l.isEnabled,isVisible:l.isVisible,isProgressVisible:l.isProgressVisible,text:l.text,textColor:l.textColor});return l.on("backgroundColorChanged",d),l.on("isEnabledChanged",d),l.on("isVisibleChanged",d),l.on("isProgressVisibleChanged",d),l.on("textColorChanged",d),l.on("textChanged",d),l}function kt(){let s=0;return()=>(s+=1,s.toString())}function xt(s){const t=new y(s);return y.sync(t),t}async function Vt(s,t,e){const{height:o=window.innerHeight,stableHeight:n=window.innerHeight,width:r=window.innerWidth,isExpanded:c=!1}=s?x("viewport")||{}:{},h=t==="macos"||t==="web"?(()=>{const l=new w(o,r,n,c,e);return w.sync(l),l})():await w.synced({postEvent:e}),p=()=>k("viewport",{height:h.height,isExpanded:h.isExpanded,stableHeight:h.stableHeight,width:h.width});return h.on("heightChanged",p),h.on("isExpandedChanged",p),h.on("stableHeightChanged",p),h.on("widthChanged",p),h}function St(s,t,e,o,n,r){const{backgroundColor:c=t,headerColor:u="bg_color"}=s?x("web-app")||{}:{},h=new Y(u,c,e,o,n,r),p=()=>k("web-app",{backgroundColor:h.backgroundColor,headerColor:h.headerColor});return h.on("backgroundColorChanged",p),h.on("headerColorChanged",p),h}async function Pt(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:o=!0,acceptCustomStyles:n=o,targetOrigin:r,launchParams:c,debug:u=!1}=s;u&&a.setDebug(u),typeof r=="string"&&a.setTargetOrigin(r);const{launchParams:h,isPageReload:p}=O.retrieveLaunchData({currentLaunchParams:typeof c=="string"||c instanceof URLSearchParams?O.parse(c):c}),{initData:l,initDataRaw:d,version:b,platform:V,themeParams:$}=h,{backgroundColor:ot="#ffffff",buttonColor:nt="#000000",buttonTextColor:rt="#ffffff"}=$,R=kt(),g=t?a.createPostEvent(b):a.postEvent,q=xt($),D=St(p,ot,b,V,R,g),{themeParams:it,viewport:at,webApp:ct}=Ct(e);ct&&mt(D,q),it&&ft(q);const M=await Vt(p,V,g);if(at&&wt(M),n&&a.isIframe()){const v=document.createElement("style");v.id="telegram-custom-styles",document.head.appendChild(v),a.on("set_custom_style",B=>{v.innerHTML=B}),g("iframe_ready")}const T={backButton:vt(p,b,g),closingBehavior:Et(p,g),cloudStorage:new j(b,R,g),haptic:new J(b,g),mainButton:yt(p,nt,rt,g),popup:new Z(b,g),postEvent:g,qrScanner:new X(b,g),themeParams:q,viewport:M,webApp:D};if(l!==void 0){const{authDate:v,hash:B,...ht}=l;T.initData=new Q(v,B,ht),T.initDataRaw=d}return T}function qt(s={}){return U.withTimeout(Pt(s),s.timeout||1e3)}function st(){try{return O.retrieveLaunchData(),!0}catch{return!1}}function Tt(){return st()}exports.BackButton=F;exports.ClosingBehaviour=K;exports.CloudStorage=j;exports.HapticFeedback=J;exports.InitData=Q;exports.MainButton=G;exports.MethodNotSupportedError=I;exports.ParameterUnsupportedError=H;exports.Popup=Z;exports.QRScanner=X;exports.ThemeParams=y;exports.Viewport=w;exports.WebApp=Y;exports.formatURL=S;exports.init=qt;exports.isTMA=st;exports.isTWA=Tt;
|
|
1
|
+
"use strict";var ht=Object.defineProperty;var ut=(s,t,e)=>t in s?ht(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(ut(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@tma.js/launch-params"),_=require("@tma.js/event-emitter"),a=require("@tma.js/bridge"),S=require("@tma.js/parsing"),L=require("@tma.js/theme-params"),B=require("@tma.js/colors"),W=require("@tma.js/utils");function w(s,t){return e=>a.supports(t[e],s)}function pt(s,t){return e=>{const[r,n]=t[e];return a.supports(r,n,s)}}class b{constructor(t,e){this.state=t,this.ee=e}emit(t,e){this.ee&&this.ee.emit(t,e)}internalSet(t,e){return this.state[t]===e?!1:(this.state[t]=e,this.emit(`${String(t)}Changed`,e),!0)}set(t,e){let r=!1;if(typeof t=="string")r=this.internalSet(t,e);else for(const n in t)this.internalSet(n,t[n])&&(r=!0);r&&this.emit("changed")}get(t){return this.state[t]}getState(){return{...this.state}}}class U{constructor(t,e,r=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>t==="click"?a.on("back_button_pressed",e):this.ee.on(t,e));i(this,"off",(t,e)=>{if(t==="click")return a.off("back_button_pressed",e);this.ee.off(t,e)});i(this,"supports");this.postEvent=r,this.state=new b({isVisible:t},this.ee),this.supports=w(e,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(t){this.state.set("isVisible",t),this.postEvent("web_app_setup_back_button",{is_visible:t})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}class j{constructor(t,e=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=e,this.state=new b({isConfirmationNeeded:t},this.ee)}set isConfirmationNeeded(t){this.state.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const lt=S.array().of(S.string());function N(s,t){return s.reduce((e,r)=>(e[r]=t,e),{})}class F{constructor(t,e,r=a.postEvent){i(this,"supports");this.createRequestId=e,this.postEvent=r,this.supports=w(t,{deleteKeys:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",getValues:"web_app_invoke_custom_method",saveValue:"web_app_invoke_custom_method"})}async invokeCustomMethod(t,e,r={}){const{result:n,error:o}=await a.request("web_app_invoke_custom_method",{method:t,params:e,req_id:this.createRequestId()},"custom_method_invoked",{...r,postEvent:this.postEvent});if(o)throw new Error(typeof o=="string"?o:`Unknown error: ${JSON.stringify(o)}`);return n}async deleteKeys(t,e){t.length!==0&&await this.invokeCustomMethod("deleteStorageValues",{keys:t},e)}async getKeys(t){const e=await this.invokeCustomMethod("getStorageKeys",{},t);return lt.parse(e)}async getValues(t,e){if(t.length===0)return N(t,"");const r=S.json(N(t,S.string())),n=await this.invokeCustomMethod("getStorageValues",{keys:t},e);return r.parse(n)}async saveValue(t,e,r){await this.invokeCustomMethod("saveStorageValue",{key:t,value:e},r)}}class K{constructor(t,e=a.postEvent){i(this,"supports");this.postEvent=e,this.supports=w(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:t})}notificationOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:t})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}class J{constructor(t,e,r={}){i(this,"state");const{chat:n=null,canSendAfter:o=null,chatType:c=null,chatInstance:p=null,user:h=null,queryId:l=null,receiver:u=null,startParam:g=null}=r;this.state=new b({authDate:t,canSendAfter:o===null?null:new Date(t.getTime()+o*1e3),chat:n,chatType:c,chatInstance:p,user:h,queryId:l,receiver:u,startParam:g,hash:e})}get authDate(){return this.state.get("authDate")}get canSendAfter(){return this.state.get("canSendAfter")}get chat(){return this.state.get("chat")}get chatType(){return this.state.get("chatType")}get chatInstance(){return this.state.get("chatInstance")}get hash(){return this.state.get("hash")}get queryId(){return this.state.get("queryId")}get receiver(){return this.state.get("receiver")}get startParam(){return this.state.get("startParam")}get user(){return this.state.get("user")}}class Q{constructor(t,e,r,n,o,c,p=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>t==="click"?a.on("main_button_pressed",e):this.ee.on(t,e));i(this,"off",(t,e)=>{if(t==="click")return a.off("main_button_pressed",e);this.ee.off(t,e)});this.postEvent=p,this.state=new b({backgroundColor:t,isEnabled:e,isVisible:r,isProgressVisible:n,text:o,textColor:c},this.ee)}set isEnabled(t){this.state.set("isEnabled",t),this.commit()}get isEnabled(){return this.state.get("isEnabled")}set isProgressVisible(t){this.state.set("isProgressVisible",t),this.commit()}get isProgressVisible(){return this.state.get("isProgressVisible")}set isVisible(t){this.state.set("isVisible",t),this.commit()}get isVisible(){return this.state.get("isVisible")}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isProgressVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideProgress(){return this.isProgressVisible=!1,this}show(){return this.isVisible=!0,this}showProgress(){return this.isProgressVisible=!0,this}setText(t){return this.state.set("text",t),this.commit(),this}setTextColor(t){return this.state.set("textColor",t),this.commit(),this}setBackgroundColor(t){return this.state.set("backgroundColor",t),this.commit(),this}}function dt(s){const t=s.message.trim(),e=(s.title||"").trim(),r=s.buttons||[];let n;if(e.length>64)throw new Error(`Title has incorrect size: ${e.length}`);if(t.length===0||t.length>256)throw new Error(`Message has incorrect size: ${t.length}`);if(r.length>3)throw new Error(`Buttons have incorrect size: ${r.length}`);return r.length===0?n=[{type:"close",id:""}]:n=r.map(o=>{const{id:c=""}=o;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(o.type===void 0||o.type==="default"||o.type==="destructive"){const p=o.text.trim();if(p.length===0||p.length>64){const h=o.type||"default";throw new Error(`Button text with type "${h}" has incorrect size: ${o.text.length}`)}return{...o,text:p,id:c}}return{...o,id:c}}),{title:e,message:t,buttons:n}}class G{constructor(t,e=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new b({isOpened:!1},this.ee),this.supports=w(t,{open:"web_app_open_popup"})}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.state.set("isOpened",!0);try{const{button_id:e=null}=await a.request("web_app_open_popup",dt(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class Z{constructor(t,e=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");this.postEvent=e,this.state=new b({isOpened:!1},this.ee),this.supports=w(t,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.state.set("isOpened",t)}get isOpened(){return this.state.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const e=await a.request("web_app_open_scan_qr_popup",{text:t},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof e=="object"&&typeof e.data=="string"?e.data:null}finally{this.isOpened=!1}}}class E{constructor(t){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.state=new b(t,this.ee)}static async request(t={}){const{timeout:e=1e3,...r}=t,n=await a.request("web_app_request_theme","theme_changed",{...r,timeout:e});return L.parse(n.theme_params)}static sync(t){a.on("theme_changed",e=>{t.state.set(L.parse(e.theme_params))})}static async synced(t){const e=await this.request(t),r=new E(e);return this.sync(r),r}get accentTextColor(){return this.get("accentTextColor")}get backgroundColor(){return this.get("backgroundColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}get(t){return this.state.get(t)||null}getState(){return this.state.getState()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return this.backgroundColor===null||B.isColorDark(this.backgroundColor)}get linkColor(){return this.get("linkColor")}get secondaryBackgroundColor(){return this.get("secondaryBackgroundColor")}get sectionBackgroundColor(){return this.get("sectionBackgroundColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}function v(s){return s<0?0:s}class m{constructor(t,e,r,n,o=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=o,this.state=new b({height:v(t),isExpanded:n,stableHeight:v(r),width:v(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...r}=t,{is_expanded:n,is_state_stable:o,...c}=await a.request("web_app_request_viewport","viewport_changed",{...r,timeout:e});return{...c,isExpanded:n,isStateStable:o}}static sync(t){a.on("viewport_changed",e=>{const{height:r,width:n,is_expanded:o,is_state_stable:c}=e,p=v(r);t.state.set({height:p,isExpanded:o,width:v(n),stableHeight:c?p:void 0})})}static async synced(t={}){const{height:e,isExpanded:r,width:n}=await this.request(t),o=new m(e,n,e,r,t.postEvent);return this.sync(o),o}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.state.set("isExpanded",!0),this.postEvent("web_app_expand")}get isStable(){return this.stableHeight===this.height}}function x(s){const t=document.createElement("a");if(t.href=s,t.protocol!=="http:"&&t.protocol!=="https:")throw Error(`URL protocol is not supported by OS, or link has not allowed protocol: ${t.protocol}`);return t.href}class X{constructor(t,e,r,n,o,c=a.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));i(this,"supports");i(this,"supportsParam");this.currentVersion=r,this.currentPlatform=n,this.createRequestId=o,this.postEvent=c,this.state=new b({backgroundColor:e,headerColor:t},this.ee),this.supports=w(r,{openInvoice:"web_app_open_invoice",readTextFromClipboard:"web_app_read_text_from_clipboard",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color",requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access"}),this.supportsParam=pt(r,{"setHeaderColor.color":["web_app_set_header_color","color"],"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}get backgroundColor(){return this.state.get("backgroundColor")}get colorScheme(){return B.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return W.compareVersions(t,this.version)>=0}openLink(t,e){const r=x(t);if(!a.supports("web_app_open_link",this.version)){window.open(r,"_blank");return}return this.postEvent("web_app_open_link",{url:r,...typeof e=="boolean"?{try_instant_view:e}:{}})}openTelegramLink(t){const{hostname:e,pathname:r,search:n}=new URL(x(t));if(e!=="t.me")throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);if(!a.supports("web_app_open_tg_link",this.version)){window.location.href=t;return}return this.postEvent("web_app_open_tg_link",{path_full:r+n})}async openInvoice(t){const{hostname:e,pathname:r}=new URL(x(t));if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const n=r.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(n===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,o]=n;return(await a.request("web_app_open_invoice",{slug:o},"invoice_closed",{postEvent:this.postEvent,capture:({slug:p})=>o===p})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:t=null}=await a.request("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent});return t}async requestPhoneAccess(){const{status:t}=await a.request("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return t}async requestWriteAccess(){const{status:t}=await a.request("web_app_request_write_access","write_access_requested",{postEvent:this.postEvent});return t}sendData(t){const{size:e}=new Blob([t]);if(e===0||e>4096)throw new Error(`Passed data has incorrect size: ${e}`);this.postEvent("web_app_data_send",{data:t})}setHeaderColor(t){this.postEvent("web_app_set_header_color",B.isRGB(t)?{color:t}:{color_key:t}),this.state.set("headerColor",t)}setBackgroundColor(t){this.postEvent("web_app_set_background_color",{color:t}),this.state.set("backgroundColor",t)}get version(){return this.currentVersion}}class A extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Mini Apps version ${e}.`),Object.setPrototypeOf(this,A.prototype)}}class I extends Error{constructor(t,e,r){super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${r}.`),Object.setPrototypeOf(this,I.prototype)}}function Y(s,t){document.documentElement.style.setProperty(s,t)}function O(s,t){t!==null&&Y(s,t)}function z(s,t){Y(s,`${t}px`)}function gt(s,t){const{backgroundColor:e,secondaryBackgroundColor:r}=t,{backgroundColor:n,headerColor:o}=s;O("--tg-bg-color",n),O("--tg-header-color",o==="bg_color"?e:r)}function bt(s){const t=()=>{const e=s.getState();Object.entries(e).forEach(([r,n])=>{const o=r.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);O(`--tg-theme-${o}`,n||null)})};s.on("changed",t),t()}function _t(s,t){const e=()=>gt(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function ft(s){const t=()=>{z("--tg-viewport-height",s.height)},e=()=>{z("--tg-viewport-stable-height",s.stableHeight)};s.on("heightChanged",t),s.on("stableHeightChanged",e),t(),e()}function mt(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function tt(s){return`telegram-mini-apps-${s}`}function y(s,t){sessionStorage.setItem(tt(s),JSON.stringify(t))}function k(s){const t=sessionStorage.getItem(tt(s));return t?JSON.parse(t):null}function wt(s,t,e){const{isVisible:r=!1}=s?k("back-button")||{}:{},n=new U(r,t,e);return n.on("isVisibleChanged",()=>{y("back-button",{isVisible:n.isVisible})}),n}function Ct(s,t){const{isConfirmationNeeded:e=!1}=s?k("closing-behavior")||{}:{},r=new j(e,t);return r.on("isConfirmationNeededChanged",()=>y("closing-behavior",{isConfirmationNeeded:r.isConfirmationNeeded})),r}function vt(s,t,e,r){const{backgroundColor:n=t,isEnabled:o=!1,isVisible:c=!1,isProgressVisible:p=!1,textColor:h=e,text:l=""}=s?k("main-button")||{}:{},u=new Q(n,o,c,p,l,h,r),g=()=>y("main-button",{backgroundColor:u.backgroundColor,isEnabled:u.isEnabled,isVisible:u.isVisible,isProgressVisible:u.isProgressVisible,text:u.text,textColor:u.textColor});return u.on("backgroundColorChanged",g),u.on("isEnabledChanged",g),u.on("isVisibleChanged",g),u.on("isProgressVisibleChanged",g),u.on("textColorChanged",g),u.on("textChanged",g),u}function Et(){let s=0;return()=>(s+=1,s.toString())}function yt(s){const t=new E(s);return E.sync(t),t}async function kt(s,t,e){const{height:r=window.innerHeight,stableHeight:n=window.innerHeight,width:o=window.innerWidth,isExpanded:c=!1}=s?k("viewport")||{}:{},h=t==="macos"||t==="web"?(()=>{const u=new m(r,o,n,c,e);return m.sync(u),u})():await m.synced({postEvent:e}),l=()=>y("viewport",{height:h.height,isExpanded:h.isExpanded,stableHeight:h.stableHeight,width:h.width});return h.on("heightChanged",l),h.on("isExpandedChanged",l),h.on("stableHeightChanged",l),h.on("widthChanged",l),h}function xt(s,t,e,r,n,o){const{backgroundColor:c=t,headerColor:p="bg_color"}=s?k("web-app")||{}:{},h=new X(p,c,e,r,n,o),l=()=>y("web-app",{backgroundColor:h.backgroundColor,headerColor:h.headerColor});return h.on("backgroundColorChanged",l),h.on("headerColorChanged",l),h}async function St(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:r=!0,acceptCustomStyles:n=r,targetOrigin:o,launchParams:c,debug:p=!1}=s;p&&a.setDebug(p),typeof o=="string"&&a.setTargetOrigin(o);const{launchParams:h,isPageReload:l}=T.retrieveLaunchData({currentLaunchParams:typeof c=="string"||c instanceof URLSearchParams?T.parse(c):c}),{initData:u,initDataRaw:g,version:f,platform:$,themeParams:H}=h,{backgroundColor:st="#ffffff",buttonColor:rt="#000000",buttonTextColor:nt="#ffffff"}=H,R=Et(),d=t?a.createPostEvent(f):a.postEvent,V=yt(H),D=xt(l,st,f,$,R,d),{themeParams:ot,viewport:it,webApp:at}=mt(e);at&&_t(D,V),ot&&bt(V);const M=await kt(l,$,d);if(it&&ft(M),n&&a.isIframe()){const C=document.createElement("style");C.id="telegram-custom-styles",document.head.appendChild(C),a.on("set_custom_style",q=>{C.innerHTML=q}),d("iframe_ready")}const P={backButton:wt(l,f,d),closingBehavior:Ct(l,d),cloudStorage:new F(f,R,d),haptic:new K(f,d),mainButton:vt(l,rt,nt,d),popup:new G(f,d),postEvent:d,qrScanner:new Z(f,d),themeParams:V,viewport:M,webApp:D};if(u!==void 0){const{authDate:C,hash:q,...ct}=u;P.initData=new J(C,q,ct),P.initDataRaw=g}return P}function Vt(s={}){return W.withTimeout(St(s),s.timeout||1e3)}function et(){try{return T.retrieveLaunchData(),!0}catch{return!1}}function Pt(){return et()}exports.BackButton=U;exports.ClosingBehaviour=j;exports.CloudStorage=F;exports.HapticFeedback=K;exports.InitData=J;exports.MainButton=Q;exports.MethodNotSupportedError=A;exports.ParameterUnsupportedError=I;exports.Popup=G;exports.QRScanner=Z;exports.ThemeParams=E;exports.Viewport=m;exports.WebApp=X;exports.formatURL=x;exports.init=Vt;exports.isTMA=et;exports.isTWA=Pt;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|