@tma.js/sdk 0.12.9 → 0.13.0
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 +2 -2
- package/dist/dts/env.d.ts +6 -4
- package/dist/dts/index.d.ts +0 -1
- 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 +253 -257
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/components/ThemeParams/ThemeParams.ts +16 -4
- package/src/env.ts +12 -7
- package/src/index.ts +0 -1
- package/src/init/init.ts +8 -53
- package/dist/dts/launch-params.d.ts +0 -6
- package/src/launch-params.ts +0 -28
|
@@ -57,11 +57,11 @@ export declare class ThemeParams {
|
|
|
57
57
|
/**
|
|
58
58
|
* Adds new event listener.
|
|
59
59
|
*/
|
|
60
|
-
on: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => import("@tma.js/event-emitter").RemoveEventListener;
|
|
60
|
+
on: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "accentTextColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "destructiveTextColorChanged" | "headerBackgroundColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged" | "sectionBackgroundColorChanged" | "sectionHeaderTextColorChanged" | "subtitleTextColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => import("@tma.js/event-emitter").RemoveEventListener;
|
|
61
61
|
/**
|
|
62
62
|
* Removes event listener.
|
|
63
63
|
*/
|
|
64
|
-
off: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
|
|
64
|
+
off: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "accentTextColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "destructiveTextColorChanged" | "headerBackgroundColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged" | "sectionBackgroundColorChanged" | "sectionHeaderTextColorChanged" | "subtitleTextColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
|
|
65
65
|
/**
|
|
66
66
|
* Returns secondary background color.
|
|
67
67
|
*/
|
package/dist/dts/env.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true in case, current environment is Telegram Mini Apps.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
3
|
+
*/
|
|
4
|
+
export declare function isTMA(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true in case, current environment is Telegram Mini Apps.
|
|
7
|
+
* @see computeLaunchData
|
|
8
|
+
* @deprecated Use `isTMA`
|
|
7
9
|
*/
|
|
8
10
|
export declare function isTWA(): boolean;
|
package/dist/dts/index.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var pt=Object.defineProperty;var lt=(s,t,e)=>t in s?pt(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 y=require("@tma.js/launch-params"),f=require("@tma.js/event-emitter"),a=require("@tma.js/bridge"),P=require("@tma.js/parsing"),z=require("@tma.js/theme-params"),A=require("@tma.js/colors"),R=require("@tma.js/utils");function C(s,t){return e=>a.supports(t[e],s)}function dt(s,t){return e=>{const[o,r]=t[e];return a.supports(o,r,s)}}class _{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 r in t)this.internalSet(r,t[r])&&(o=!0);o&&this.emit("changed")}get(t){return this.state[t]}}class K{constructor(t,e,o=a.postEvent){i(this,"ee",new f.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 _({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 j{constructor(t,e=a.postEvent){i(this,"ee",new f.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 _({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 gt=P.array().of(P.string());function U(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:r,error:n}=await a.request("web_app_invoke_custom_method",{method:t,params:e,req_id:this.createRequestId()},"custom_method_invoked",{...o,postEvent:this.postEvent});if(n)throw new Error(typeof n=="string"?n:`Unknown error: ${JSON.stringify(n)}`);return r}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 gt.parse(e)}async getValues(t,e){if(t.length===0)return U(t,"");const o=P.json(U(t,P.string())),r=await this.invokeCustomMethod("getStorageValues",{keys:t},e);return o.parse(r)}async saveValue(t,e,o){await this.invokeCustomMethod("saveStorageValue",{key:t,value:e},o)}}class Q{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 G{constructor(t,e,o={}){i(this,"state");const{chat:r=null,canSendAfter:n=null,chatType:c=null,chatInstance:h=null,user:p=null,queryId:l=null,receiver:u=null,startParam:d=null}=o;this.state=new _({authDate:t,canSendAfter:n===null?null:new Date(t.getTime()+n*1e3),chat:r,chatType:c,chatInstance:h,user:p,queryId:l,receiver:u,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 Z{constructor(t,e,o,r,n,c,h=a.postEvent){i(this,"ee",new f.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=h,this.state=new _({backgroundColor:t,isEnabled:e,isVisible:o,isProgressVisible:r,text:n,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 bt(s){const t=s.message.trim(),e=(s.title||"").trim(),o=s.buttons||[];let r;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?r=[{type:"close",id:""}]:r=o.map(n=>{const{id:c=""}=n;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(n.type===void 0||n.type==="default"||n.type==="destructive"){const h=n.text.trim();if(h.length===0||h.length>64){const p=n.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${n.text.length}`)}return{...n,text:h,id:c}}return{...n,id:c}}),{title:e,message:t,buttons:r}}class X{constructor(t,e=a.postEvent){i(this,"ee",new f.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 _({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",bt(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class Y{constructor(t,e=a.postEvent){i(this,"ee",new f.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 _({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 W(s){const{backgroundColor:t=null,buttonTextColor:e=null,buttonColor:o=null,hintColor:r=null,linkColor:n=null,textColor:c=null,secondaryBackgroundColor:h=null}=s;return{backgroundColor:t,buttonTextColor:e,buttonColor:o,hintColor:r,linkColor:n,textColor:c,secondaryBackgroundColor:h}}class k{constructor(t){i(this,"ee",new f.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 _(W(t),this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,r=await a.request("web_app_request_theme","theme_changed",{...o,timeout:e});return z.parse(r.theme_params)}static sync(t){a.on("theme_changed",e=>{t.state.set(W(z.parse(e.theme_params)))})}static async synced(t){const e=await this.request(t),o=new k(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,r,n=a.postEvent){i(this,"ee",new f.EventEmitter);i(this,"state");i(this,"on",this.ee.on.bind(this.ee));i(this,"off",this.ee.off.bind(this.ee));this.postEvent=n,this.state=new _({height:E(t),isExpanded:r,stableHeight:E(o),width:E(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,{is_expanded:r,is_state_stable:n,...c}=await a.request("web_app_request_viewport","viewport_changed",{...o,timeout:e});return{...c,isExpanded:r,isStateStable:n}}static sync(t){a.on("viewport_changed",e=>{const{height:o,width:r,is_expanded:n,is_state_stable:c}=e,h=E(o);t.state.set({height:h,isExpanded:n,width:E(r),stableHeight:c?h:void 0})})}static async synced(t={}){const{height:e,isExpanded:o,width:r}=await this.request(t),n=new w(e,r,e,o,t.postEvent);return this.sync(n),n}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 V(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 tt{constructor(t,e,o,r,n,c=a.postEvent){i(this,"ee",new f.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=r,this.createRequestId=n,this.postEvent=c,this.state=new _({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=dt(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 R.compareVersions(t,this.version)>=0}openLink(t,e){const o=V(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:r}=new URL(V(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+r})}async openInvoice(t){const{hostname:e,pathname:o}=new URL(V(t));if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const r=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(r===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,n]=r;return(await a.request("web_app_open_invoice",{slug:n},"invoice_closed",{postEvent:this.postEvent,capture:({slug:h})=>n===h})).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 q extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Mini Apps version ${e}.`),Object.setPrototypeOf(this,q.prototype)}}class B extends Error{constructor(t,e,o){super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`),Object.setPrototypeOf(this,B.prototype)}}function et(s,t){document.documentElement.style.setProperty(s,t)}function b(s,t){t!==null&&et(s,t)}function F(s,t){et(s,`${t}px`)}function _t(s){const{backgroundColor:t,buttonTextColor:e,secondaryBackgroundColor:o,hintColor:r,buttonColor:n,linkColor:c,textColor:h}=s;b("--tg-theme-bg-color",t),b("--tg-theme-button-color",n),b("--tg-theme-button-text-color",e),b("--tg-theme-hint-color",r),b("--tg-theme-link-color",c),b("--tg-theme-secondary-bg-color",o),b("--tg-theme-text-color",h)}function ft(s,t){const{backgroundColor:e,secondaryBackgroundColor:o}=t,{backgroundColor:r,headerColor:n}=s;b("--tg-bg-color",r),b("--tg-header-color",n==="bg_color"?e:o)}function mt(s){const t=()=>_t(s);s.on("changed",t),t()}function wt(s,t){const e=()=>ft(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function Ct(s){const t=()=>{F("--tg-viewport-height",s.height)},e=()=>{F("--tg-viewport-stable-height",s.stableHeight)};s.on("heightChanged",t),s.on("stableHeightChanged",e),t(),e()}function vt(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function st(s){return`telegram-mini-apps-${s}`}function S(s,t){sessionStorage.setItem(st(s),JSON.stringify(t))}function x(s){const t=sessionStorage.getItem(st(s));return t?JSON.parse(t):null}function Et(s,t,e){const{isVisible:o=!1}=s?x("back-button")||{}:{},r=new K(o,t,e);return r.on("isVisibleChanged",()=>{S("back-button",{isVisible:r.isVisible})}),r}function yt(s,t){const{isConfirmationNeeded:e=!1}=s?x("closing-behavior")||{}:{},o=new j(e,t);return o.on("isConfirmationNeededChanged",()=>S("closing-behavior",{isConfirmationNeeded:o.isConfirmationNeeded})),o}function kt(s,t,e,o){const{backgroundColor:r=t,isEnabled:n=!1,isVisible:c=!1,isProgressVisible:h=!1,textColor:p=e,text:l=""}=s?x("main-button")||{}:{},u=new Z(r,n,c,h,l,p,o),d=()=>S("main-button",{backgroundColor:u.backgroundColor,isEnabled:u.isEnabled,isVisible:u.isVisible,isProgressVisible:u.isProgressVisible,text:u.text,textColor:u.textColor});return u.on("backgroundColorChanged",d),u.on("isEnabledChanged",d),u.on("isVisibleChanged",d),u.on("isProgressVisibleChanged",d),u.on("textColorChanged",d),u.on("textChanged",d),u}function St(s,t){return s?(e,o)=>{if(!a.supports(e,t))throw new q(e,t);return R.isRecord(o)&&a.detectSupportParams(e,o).forEach(r=>{if(!a.supports(e,r,t))throw new B(e,r,t)}),a.postEvent(e,o)}:a.postEvent}function xt(){let s=0;return()=>(s+=1,s.toString())}function Vt(s){const t=new k(s);return k.sync(t),t}async function Pt(s,t,e){const{height:o=window.innerHeight,stableHeight:r=window.innerHeight,width:n=window.innerWidth,isExpanded:c=!1}=s?x("viewport")||{}:{},p=t==="macos"||t==="web"?(()=>{const u=new w(o,n,r,c,e);return w.sync(u),u})():await w.synced({postEvent:e}),l=()=>S("viewport",{height:p.height,isExpanded:p.isExpanded,stableHeight:p.stableHeight,width:p.width});return p.on("heightChanged",l),p.on("isExpandedChanged",l),p.on("stableHeightChanged",l),p.on("widthChanged",l),p}function qt(s,t,e,o,r,n){const{backgroundColor:c=t,headerColor:h="bg_color"}=s?x("web-app")||{}:{},p=new tt(h,c,e,o,r,n),l=()=>S("web-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("backgroundColorChanged",l),p.on("headerColorChanged",l),p}function $(){let s;try{return y.parse(window.location.hash.slice(1))}catch(e){s=e}const t=y.retrieveFromStorage();if(t)return t;throw new Error("Unable to extract launch params",{cause:s})}function Bt(){return window.performance.getEntriesByType("navigation").some(s=>s.type==="reload")}function Ot(s,t){var e,o;return s?((e=s.initData)==null?void 0:e.hash)===((o=t.initData)==null?void 0:o.hash):!1}async function Tt(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:o=!0,acceptCustomStyles:r=o,targetOrigin:n,debug:c=!1,launchParams:h}=s;c&&a.setDebug(c),typeof n=="string"&&a.setTargetOrigin(n);const p=y.retrieveFromStorage(),l=h instanceof URLSearchParams||typeof h=="string"?y.parse(h):$();y.saveToStorage(l);const u=Bt()||Ot(p,l),{initData:d,initDataRaw:ot,version:m,platform:H,themeParams:D}=l,{backgroundColor:rt="#ffffff",buttonColor:nt="#000000",buttonTextColor:it="#ffffff"}=D,L=xt(),g=St(t,m),O=Vt(D),M=qt(u,rt,m,H,L,g),{themeParams:at,viewport:ct,webApp:ht}=vt(e);ht&&wt(M,O),at&&mt(O);const N=await Pt(u,H,g);if(ct&&Ct(N),r&&a.isIframe()){const v=document.createElement("style");v.id="telegram-custom-styles",document.head.appendChild(v),a.on("set_custom_style",I=>{v.innerHTML=I}),g("iframe_ready")}const T={backButton:Et(u,m,g),closingBehavior:yt(u,g),cloudStorage:new J(m,L,g),haptic:new Q(m,g),mainButton:kt(u,nt,it,g),popup:new X(m,g),postEvent:g,qrScanner:new Y(m,g),themeParams:O,viewport:N,webApp:M};if(d!==void 0){const{authDate:v,hash:I,...ut}=d;T.initData=new G(v,I,ut),T.initDataRaw=ot}return T}function It(s={}){return R.withTimeout(Tt(s),s.timeout||1e3)}function At(){try{return $(),!0}catch{return!1}}exports.BackButton=K;exports.ClosingBehaviour=j;exports.CloudStorage=J;exports.HapticFeedback=Q;exports.InitData=G;exports.MainButton=Z;exports.MethodNotSupportedError=q;exports.ParameterUnsupportedError=B;exports.Popup=X;exports.QRScanner=Y;exports.ThemeParams=k;exports.Viewport=w;exports.WebApp=tt;exports.formatURL=V;exports.init=It;exports.isTWA=At;exports.retrieveLaunchParams=$;
|
|
1
|
+
"use strict";var ut=Object.defineProperty;var pt=(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)=>(pt(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@tma.js/launch-params"),w=require("@tma.js/event-emitter"),a=require("@tma.js/bridge"),P=require("@tma.js/parsing"),N=require("@tma.js/theme-params"),H=require("@tma.js/colors"),$=require("@tma.js/utils");function C(s,t){return e=>a.supports(t[e],s)}function lt(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 w.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 w.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 z(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 z(t,"");const o=P.json(z(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:l=null,receiver:p=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:l,receiver:p,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 w.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 w.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 w.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 W(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:l=null,sectionBackgroundColor:p=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:l,sectionBackgroundColor:p,sectionHeaderTextColor:d,subtitleTextColor:b,textColor:V}}class y{constructor(t){i(this,"ee",new w.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(W(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 N.parse(n.theme_params)}static sync(t){a.on("theme_changed",e=>{t.state.set(W(N.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||H.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 m{constructor(t,e,o,n,r=a.postEvent){i(this,"ee",new w.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 m(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 w.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=lt(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 H.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return $.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",H.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 q extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Mini Apps version ${e}.`),Object.setPrototypeOf(this,q.prototype)}}class T extends Error{constructor(t,e,o){super(`Parameter "${e}" in method "${t}" is not supported in the Mini Apps version ${o}.`),Object.setPrototypeOf(this,T.prototype)}}function tt(s,t){document.documentElement.style.setProperty(s,t)}function _(s,t){t!==null&&tt(s,t)}function U(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 wt(s,t){const e=()=>_t(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function mt(s){const t=()=>{U("--tg-viewport-height",s.height)},e=()=>{U("--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:l=""}=s?x("main-button")||{}:{},p=new G(n,r,c,u,l,h,o),d=()=>k("main-button",{backgroundColor:p.backgroundColor,isEnabled:p.isEnabled,isVisible:p.isVisible,isProgressVisible:p.isProgressVisible,text:p.text,textColor:p.textColor});return p.on("backgroundColorChanged",d),p.on("isEnabledChanged",d),p.on("isVisibleChanged",d),p.on("isProgressVisibleChanged",d),p.on("textColorChanged",d),p.on("textChanged",d),p}function kt(s,t){return s?(e,o)=>{if(!a.supports(e,t))throw new q(e,t);return $.isRecord(o)&&a.detectSupportParams(e,o).forEach(n=>{if(!a.supports(e,n,t))throw new T(e,n,t)}),a.postEvent(e,o)}:a.postEvent}function xt(){let s=0;return()=>(s+=1,s.toString())}function Vt(s){const t=new y(s);return y.sync(t),t}async function St(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 p=new m(o,r,n,c,e);return m.sync(p),p})():await m.synced({postEvent:e}),l=()=>k("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 Pt(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),l=()=>k("web-app",{backgroundColor:h.backgroundColor,headerColor:h.headerColor});return h.on("backgroundColorChanged",l),h.on("headerColorChanged",l),h}async function qt(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:l}=I.retrieveLaunchData({currentLaunchParams:typeof c=="string"||c instanceof URLSearchParams?I.parse(c):c}),{initData:p,initDataRaw:d,version:b,platform:V,themeParams:R}=h,{backgroundColor:ot="#ffffff",buttonColor:nt="#000000",buttonTextColor:rt="#ffffff"}=R,D=xt(),g=kt(t,b),B=Vt(R),M=Pt(l,ot,b,V,D,g),{themeParams:it,viewport:at,webApp:ct}=Ct(e);ct&&wt(M,B),it&&ft(B);const L=await St(l,V,g);if(at&&mt(L),n&&a.isIframe()){const v=document.createElement("style");v.id="telegram-custom-styles",document.head.appendChild(v),a.on("set_custom_style",A=>{v.innerHTML=A}),g("iframe_ready")}const O={backButton:vt(l,b,g),closingBehavior:Et(l,g),cloudStorage:new j(b,D,g),haptic:new J(b,g),mainButton:yt(l,nt,rt,g),popup:new Z(b,g),postEvent:g,qrScanner:new X(b,g),themeParams:B,viewport:L,webApp:M};if(p!==void 0){const{authDate:v,hash:A,...ht}=p;O.initData=new Q(v,A,ht),O.initDataRaw=d}return O}function Tt(s={}){return $.withTimeout(qt(s),s.timeout||1e3)}function st(){try{return I.retrieveLaunchData(),!0}catch{return!1}}function Bt(){return st()}exports.BackButton=F;exports.ClosingBehaviour=K;exports.CloudStorage=j;exports.HapticFeedback=J;exports.InitData=Q;exports.MainButton=G;exports.MethodNotSupportedError=q;exports.ParameterUnsupportedError=T;exports.Popup=Z;exports.QRScanner=X;exports.ThemeParams=y;exports.Viewport=m;exports.WebApp=Y;exports.formatURL=S;exports.init=Tt;exports.isTMA=st;exports.isTWA=Bt;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|