@tma.js/sdk 0.11.5 → 0.12.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/CloudStorage/CloudStorage.d.ts +2 -2
- package/dist/dts/components/ThemeParams/ThemeParams.d.ts +4 -3
- package/dist/dts/components/ThemeParams/types.d.ts +2 -2
- package/dist/dts/components/WebApp/WebApp.d.ts +5 -4
- package/dist/dts/index.d.ts +2 -3
- package/dist/dts/init/creators/createBackButton.d.ts +2 -1
- package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -1
- package/dist/dts/init/creators/createMainButton.d.ts +2 -1
- package/dist/dts/init/creators/createThemeParams.d.ts +7 -0
- package/dist/dts/init/creators/createViewport.d.ts +3 -2
- package/dist/dts/init/creators/createWebApp.d.ts +4 -2
- package/dist/dts/init/creators/index.d.ts +1 -1
- package/dist/dts/init/types.d.ts +5 -5
- package/dist/dts/launch-params.d.ts +3 -17
- package/dist/dts/state/State.d.ts +1 -1
- package/dist/dts/storage.d.ts +0 -1
- package/dist/dts/types.d.ts +0 -4
- package/dist/index.js +290 -304
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +9 -6
- package/src/components/MainButton/MainButton.ts +1 -1
- package/src/components/ThemeParams/ThemeParams.ts +3 -3
- package/src/components/ThemeParams/types.ts +5 -5
- package/src/components/WebApp/WebApp.ts +2 -1
- package/src/index.ts +2 -3
- package/src/init/creators/createBackButton.ts +7 -2
- package/src/init/creators/createClosingBehavior.ts +6 -2
- package/src/init/creators/createMainButton.ts +3 -1
- package/src/init/creators/{createSyncedThemeParams.ts → createThemeParams.ts} +3 -3
- package/src/init/creators/createViewport.ts +8 -4
- package/src/init/creators/createWebApp.ts +5 -2
- package/src/init/creators/index.ts +1 -1
- package/src/init/init.ts +67 -20
- package/src/init/types.ts +5 -5
- package/src/launch-params.ts +14 -55
- package/src/storage.ts +1 -2
- package/src/types.ts +0 -15
- package/src/url.ts +1 -2
- package/dist/dts/init/creators/createSyncedThemeParams.d.ts +0 -7
- package/dist/dts/theme-params.d.ts +0 -18
- package/src/theme-params.ts +0 -34
package/dist/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(c,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tma.js/parsing"),require("@tma.js/init-data"),require("@tma.js/bridge"),require("@tma.js/utils"),require("@tma.js/event-emitter"),require("@tma.js/colors")):typeof define=="function"&&define.amd?define(["exports","@tma.js/parsing","@tma.js/init-data","@tma.js/bridge","@tma.js/utils","@tma.js/event-emitter","@tma.js/colors"],u):(c=typeof globalThis<"u"?globalThis:c||self,u((c["@tma"]=c["@tma"]||{},c["@tma"]["js/sdk"]={}),c["@tma"]["js/parsing"],c["@tma"]["js/init-data"],c["@tma"]["js/bridge"],c["@tma"]["js/utils"],c["@tma"]["js/event-emitter"],c["@tma"]["js/colors"]))})(this,function(c,u,w,h,T,m,j){"use strict";var jt=Object.defineProperty;var At=(c,u,w)=>u in c?jt(c,u,{enumerable:!0,configurable:!0,writable:!0,value:w}):c[u]=w;var i=(c,u,w)=>(At(c,typeof u!="symbol"?u+"":u,w),w);function v(s,t){return e=>h.supports(t[e],s)}function nt(s,t){return e=>{const[o,n]=t[e];return h.supports(o,n,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 n in t)this.internalSet(n,t[n])&&(o=!0);o&&this.emit("changed")}get(t){return this.state[t]}}class D{constructor(t,e,o=h.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return h.on("back_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return h.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=v(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 L{constructor(t,e=h.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 _({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 rt=u.array().of(u.string());function W(s,t){return s.reduce((e,o)=>(e[o]=t,e),{})}class M{constructor(t,e,o=h.postEvent){i(this,"supports");this.createRequestId=e,this.postEvent=o,this.supports=v(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 h.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 rt.parse(e)}async getValues(t,e){if(t.length===0)return W(t,"");const o=u.json(W(t,u.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 N{constructor(t,e=h.postEvent){i(this,"supports");this.postEvent=e,this.supports=v(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 z{constructor(t,e,o={}){i(this,"state");const{chat:n=null,canSendAfter:r=null,user:p=null,queryId:a=null,receiver:d=null,startParam:l=null}=o;this.state=new _({authDate:t,canSendAfter:r,chat:n,user:p,queryId:a,receiver:d,startParam:l,hash:e})}get authDate(){return this.state.get("authDate")}get canSendAfter(){return this.state.get("canSendAfter")}get chat(){return this.state.get("chat")}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 U{constructor(t,e,o,n,r,p,a=h.postEvent){i(this,"ee",new m.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return h.on("main_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return h.off("main_button_pressed",e);this.ee.off(t,e)});this.postEvent=a,this.state=new _({backgroundColor:t,isEnabled:e,isVisible:o,isProgressVisible:n,text:r,textColor:p},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 it(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:p=""}=r;if(p.length>64)throw new Error(`Button ID has incorrect size: ${p}`);if(r.type===void 0||r.type==="default"||r.type==="destructive"){const a=r.text.trim();if(a.length===0||a.length>64){const d=r.type||"default";throw new Error(`Button text with type "${d}" has incorrect size: ${r.text.length}`)}return{...r,text:a,id:p}}return{...r,id:p}}),{title:e,message:t,buttons:n}}class F{constructor(t,e=h.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 _({isOpened:!1},this.ee),this.supports=v(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 h.request("web_app_open_popup",it(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class K{constructor(t,e=h.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 _({isOpened:!1},this.ee),this.supports=v(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 h.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}}}const at=u.json({backgroundColor:{type:u.rgb().optional(),from:"bg_color"},buttonColor:{type:u.rgb().optional(),from:"button_color"},buttonTextColor:{type:u.rgb().optional(),from:"button_text_color"},hintColor:{type:u.rgb().optional(),from:"hint_color"},linkColor:{type:u.rgb().optional(),from:"link_color"},textColor:{type:u.rgb().optional(),from:"text_color"},secondaryBackgroundColor:{type:u.rgb().optional(),from:"secondary_bg_color"}});function x(s){return at.parse(s)}function J(s){const{backgroundColor:t=null,buttonTextColor:e=null,buttonColor:o=null,hintColor:n=null,linkColor:r=null,textColor:p=null,secondaryBackgroundColor:a=null}=s;return{backgroundColor:t,buttonTextColor:e,buttonColor:o,hintColor:n,linkColor:r,textColor:p,secondaryBackgroundColor:a}}class P{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 _(J(t),this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,n=await h.request("web_app_request_theme","theme_changed",{...o,timeout:e});return x(n.theme_params)}static sync(t){h.on("theme_changed",e=>{t.state.set(J(x(e.theme_params)))})}static async synced(t){const e=await this.request(t),o=new P(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||j.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 V(s){return s<0?0:s}class y{constructor(t,e,o,n,r=h.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 _({height:V(t),isExpanded:n,stableHeight:V(o),width:V(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,{is_expanded:n,is_state_stable:r,...p}=await h.request("web_app_request_viewport","viewport_changed",{...o,timeout:e});return{...p,isExpanded:n,isStateStable:r}}static sync(t){h.on("viewport_changed",e=>{const{height:o,width:n,is_expanded:r,is_state_stable:p}=e,a=V(o);t.state.set({height:a,isExpanded:r,width:V(n),stableHeight:p?a:void 0})})}static async synced(t={}){const{height:e,isExpanded:o,width:n}=await this.request(t),r=new y(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 q(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 Q{constructor(t,e,o,n,r,p=h.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=p,this.state=new _({backgroundColor:e,headerColor:t},this.ee),this.supports=v(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=nt(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 j.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return T.compareVersions(t,this.version)>=0}openLink(t,e){const o=q(t);if(!h.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(q(t));if(e!=="t.me")throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);if(!h.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(q(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 h.request("web_app_open_invoice",{slug:r},"invoice_closed",{postEvent:this.postEvent,capture:({slug:a})=>r===a})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:t=null}=await h.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 h.request("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return t}async requestWriteAccess(){const{status:t}=await h.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",j.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}}function G(s){return`telegram-web-apps-${s}`}function E(s,t){sessionStorage.setItem(G(s),JSON.stringify(t))}function k(s){const t=sessionStorage.getItem(G(s));return t?JSON.parse(t):null}const ct=u.searchParams({version:{type:u.string(),from:"tgWebAppVersion"},initData:{type:w.initData.optional(),from:"tgWebAppData"},initDataRaw:{type:u.string().optional(),from:"tgWebAppData"},platform:{type:u.string(),from:"tgWebAppPlatform"},themeParams:{type:x,from:"tgWebAppThemeParams"}});function B(s){return ct.parse(s)}function A(){const s=[];try{const t=window.location.hash.slice(1),e=B(t);return E("launch-params",t),e}catch(t){s.push(t instanceof Error?t.message:"unknown error")}try{const t=k("launch-params");if(t)return B(t);s.push("Launch params are missing in local storage")}catch(t){s.push(t instanceof Error?t.message:"unknown error")}throw new Error(`Unable to extract launch params. Errors: "${s.join('", "')}"`)}function Z(s,t){document.documentElement.style.setProperty(s,t)}function f(s,t){t!==null&&Z(s,t)}function X(s,t){Z(s,`${t}px`)}function ht(s){const{backgroundColor:t,buttonTextColor:e,secondaryBackgroundColor:o,hintColor:n,buttonColor:r,linkColor:p,textColor:a}=s;f("--tg-theme-bg-color",t),f("--tg-theme-button-color",r),f("--tg-theme-button-text-color",e),f("--tg-theme-hint-color",n),f("--tg-theme-link-color",p),f("--tg-theme-secondary-bg-color",o),f("--tg-theme-text-color",a)}function ut(s,t){const{backgroundColor:e,secondaryBackgroundColor:o}=t,{backgroundColor:n,headerColor:r}=s;f("--tg-bg-color",n),f("--tg-header-color",r==="bg_color"?e:o)}function pt(s){const t=()=>ht(s);s.on("changed",t),t()}function lt(s,t){const e=()=>ut(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function dt(s){const t=()=>{X("--tg-viewport-height",s.height)},e=()=>{X("--tg-viewport-stable-height",s.stableHeight)};s.on("heightChanged",t),s.on("stableHeightChanged",e),t(),e()}function gt(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function _t(s,t){const{isVisible:e=!1}=k("back-button")||{},o=new D(e,s,t);return o.on("isVisibleChanged",()=>{E("back-button",{isVisible:o.isVisible})}),o}function ft(s){const{isConfirmationNeeded:t=!1}=k("closing-behavior")||{},e=new L(t,s);return e.on("isConfirmationNeededChanged",()=>E("closing-behavior",{isConfirmationNeeded:e.isConfirmationNeeded})),e}function mt(s,t,e){const{backgroundColor:o=s,isEnabled:n=!1,isVisible:r=!1,isProgressVisible:p=!1,textColor:a=t,text:d=""}=k("main-button")||{},l=new U(o,n,r,p,d,a,e),b=()=>E("main-button",{backgroundColor:l.backgroundColor,isEnabled:l.isEnabled,isVisible:l.isVisible,isProgressVisible:l.isProgressVisible,text:l.text,textColor:l.textColor});return l.on("backgroundColorChanged",b),l.on("isEnabledChanged",b),l.on("isVisibleChanged",b),l.on("isProgressVisibleChanged",b),l.on("textColorChanged",b),l.on("textChanged",b),l}class O extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Web Apps version ${e}.`),Object.setPrototypeOf(this,O.prototype)}}class R extends Error{constructor(t,e,o){super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`),Object.setPrototypeOf(this,R.prototype)}}function bt(s,t){return s?(e,o)=>{if(!h.supports(e,t))throw new O(e,t);return T.isRecord(o)&&h.detectSupportParams(e,o).forEach(n=>{if(!h.supports(e,n,t))throw new R(e,n,t)}),h.postEvent(e,o)}:h.postEvent}function wt(){let s=0;return()=>(s+=1,s.toString())}function Ct(s){const t=new P(s);return P.sync(t),t}async function vt(s,t){const{height:e=window.innerHeight,stableHeight:o=window.innerHeight,width:n=window.innerWidth,isExpanded:r=!1}=k("viewport")||{},a=s==="macos"||s==="web"?(()=>{const l=new y(e,n,o,r,t);return y.sync(l),l})():await y.synced({postEvent:t}),d=()=>E("viewport",{height:a.height,isExpanded:a.isExpanded,stableHeight:a.stableHeight,width:a.width});return a.on("heightChanged",d),a.on("isExpandedChanged",d),a.on("stableHeightChanged",d),a.on("widthChanged",d),a}function yt(s,t,e,o,n){const{backgroundColor:r=s,headerColor:p="bg_color"}=k("web-app")||{},a=new Q(p,r,t,e,o,n),d=()=>E("web-app",{backgroundColor:a.backgroundColor,headerColor:a.headerColor});return a.on("backgroundColorChanged",d),a.on("headerColorChanged",d),a}async function Et(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:o=!0,acceptCustomStyles:n=o,targetOrigin:r,debug:p=!1,launchParams:a}=s;p&&h.setDebug(p),typeof r=="string"&&h.setTargetOrigin(r);let d;a?d=a instanceof URLSearchParams||typeof a=="string"?B(a):a:d=A();const{initData:l,initDataRaw:b,version:C,platform:Y,themeParams:tt}=d,{backgroundColor:Vt="#ffffff",buttonColor:St="#000000",buttonTextColor:xt="#ffffff"}=tt,et=wt(),g=bt(t,C),$=Ct(tt),st=yt(Vt,C,Y,et,g),{themeParams:qt,viewport:Bt,webApp:Ot}=gt(e);Ot&<(st,$),qt&&pt($);const ot=await vt(Y,g);if(Bt&&dt(ot),n&&h.isIframe()){const S=document.createElement("style");S.id="telegram-custom-styles",document.head.appendChild(S),h.on("set_custom_style",I=>{S.innerHTML=I}),g("iframe_ready")}const H={backButton:_t(C,g),closingBehavior:ft(g),cloudStorage:new M(C,et,g),haptic:new N(C,g),mainButton:mt(St,xt,g),popup:new F(C,g),postEvent:g,qrScanner:new K(C,g),themeParams:$,viewport:ot,webApp:st};if(l!==void 0){const{authDate:S,hash:I,...Tt}=l;H.initData=new z(S,I,Tt),H.initDataRaw=b}return H}function kt(s={}){return T.withTimeout(Et(s),s.timeout||1e3)}function Pt(){try{return A(),!0}catch{return!1}}c.BackButton=D,c.ClosingBehaviour=L,c.CloudStorage=M,c.HapticFeedback=N,c.InitData=z,c.MainButton=U,c.MethodNotSupportedError=O,c.Popup=F,c.QRScanner=K,c.ThemeParams=P,c.Viewport=y,c.WebApp=Q,c.formatURL=q,c.init=kt,c.isTWA=Pt,c.parseLaunchParams=B,c.parseThemeParams=x,c.retrieveLaunchParams=A,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@tma.js/launch-params"),require("@tma.js/event-emitter"),require("@tma.js/bridge"),require("@tma.js/parsing"),require("@tma.js/theme-params"),require("@tma.js/colors"),require("@tma.js/utils")):typeof define=="function"&&define.amd?define(["exports","@tma.js/launch-params","@tma.js/event-emitter","@tma.js/bridge","@tma.js/parsing","@tma.js/theme-params","@tma.js/colors","@tma.js/utils"],d):(a=typeof globalThis<"u"?globalThis:a||self,d((a["@tma"]=a["@tma"]||{},a["@tma"]["js/sdk"]={}),a["@tma"]["js/launch-params"],a["@tma"]["js/event-emitter"],a["@tma"]["js/bridge"],a["@tma"]["js/parsing"],a["@tma"]["js/theme-params"],a["@tma"]["js/colors"],a["@tma"]["js/utils"]))})(this,function(a,d,_,c,P,I,j,T){"use strict";var Rt=Object.defineProperty;var $t=(a,d,_)=>d in a?Rt(a,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):a[d]=_;var i=(a,d,_)=>($t(a,typeof d!="symbol"?d+"":d,_),_);function v(s,t){return e=>c.supports(t[e],s)}function nt(s,t){return e=>{const[o,n]=t[e];return c.supports(o,n,s)}}class m{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 D{constructor(t,e,o=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return c.on("back_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return c.off("back_button_pressed",e);this.ee.off(t,e)});i(this,"supports");this.postEvent=o,this.state=new m({isVisible:t},this.ee),this.supports=v(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 L{constructor(t,e=c.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 m({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 rt=P.array().of(P.string());function N(s,t){return s.reduce((e,o)=>(e[o]=t,e),{})}class M{constructor(t,e,o=c.postEvent){i(this,"supports");this.createRequestId=e,this.postEvent=o,this.supports=v(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 c.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 rt.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 W{constructor(t,e=c.postEvent){i(this,"supports");this.postEvent=e,this.supports=v(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 z{constructor(t,e,o={}){i(this,"state");const{chat:n=null,canSendAfter:r=null,user:h=null,queryId:u=null,receiver:p=null,startParam:g=null}=o;this.state=new m({authDate:t,canSendAfter:r,chat:n,user:h,queryId:u,receiver:p,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 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 U{constructor(t,e,o,n,r,h,u=c.postEvent){i(this,"ee",new _.EventEmitter);i(this,"state");i(this,"on",(t,e)=>{if(t==="click")return c.on("main_button_pressed",e);this.ee.on(t,e)});i(this,"off",(t,e)=>{if(t==="click")return c.off("main_button_pressed",e);this.ee.off(t,e)});this.postEvent=u,this.state=new m({backgroundColor:t,isEnabled:e,isVisible:o,isProgressVisible:n,text:r,textColor:h},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 it(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:h=""}=r;if(h.length>64)throw new Error(`Button ID has incorrect size: ${h}`);if(r.type===void 0||r.type==="default"||r.type==="destructive"){const u=r.text.trim();if(u.length===0||u.length>64){const p=r.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${r.text.length}`)}return{...r,text:u,id:h}}return{...r,id:h}}),{title:e,message:t,buttons:n}}class F{constructor(t,e=c.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 m({isOpened:!1},this.ee),this.supports=v(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 c.request("web_app_open_popup",it(t),"popup_closed",{postEvent:this.postEvent});return e}finally{this.state.set("isOpened",!1)}}}class K{constructor(t,e=c.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 m({isOpened:!1},this.ee),this.supports=v(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 c.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 J(s){const{backgroundColor:t=null,buttonTextColor:e=null,buttonColor:o=null,hintColor:n=null,linkColor:r=null,textColor:h=null,secondaryBackgroundColor:u=null}=s;return{backgroundColor:t,buttonTextColor:e,buttonColor:o,hintColor:n,linkColor:r,textColor:h,secondaryBackgroundColor:u}}class y{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 m(J(t),this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,n=await c.request("web_app_request_theme","theme_changed",{...o,timeout:e});return I.parse(n.theme_params)}static sync(t){c.on("theme_changed",e=>{t.state.set(J(I.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||j.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 k(s){return s<0?0:s}class E{constructor(t,e,o,n,r=c.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=r,this.state=new m({height:k(t),isExpanded:n,stableHeight:k(o),width:k(e)},this.ee)}static async request(t={}){const{timeout:e=1e3,...o}=t,{is_expanded:n,is_state_stable:r,...h}=await c.request("web_app_request_viewport","viewport_changed",{...o,timeout:e});return{...h,isExpanded:n,isStateStable:r}}static sync(t){c.on("viewport_changed",e=>{const{height:o,width:n,is_expanded:r,is_state_stable:h}=e,u=k(o);t.state.set({height:u,isExpanded:r,width:k(n),stableHeight:h?u:void 0})})}static async synced(t={}){const{height:e,isExpanded:o,width:n}=await this.request(t),r=new E(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 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 Q{constructor(t,e,o,n,r,h=c.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=o,this.currentPlatform=n,this.createRequestId=r,this.postEvent=h,this.state=new m({backgroundColor:e,headerColor:t},this.ee),this.supports=v(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=nt(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 j.isColorDark(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(t){return T.compareVersions(t,this.version)>=0}openLink(t,e){const o=x(t);if(!c.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(x(t));if(e!=="t.me")throw new Error(`URL has not allowed hostname: ${e}. Only "t.me" is allowed`);if(!c.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(x(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 c.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 c.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 c.request("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return t}async requestWriteAccess(){const{status:t}=await c.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",j.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 B extends Error{constructor(t,e){super(`Method "${t}" is not supported in the Web Apps version ${e}.`),Object.setPrototypeOf(this,B.prototype)}}class O extends Error{constructor(t,e,o){super(`Parameter "${e}" in method "${t}" is not supported in the Web Apps version ${o}.`),Object.setPrototypeOf(this,O.prototype)}}function G(s,t){document.documentElement.style.setProperty(s,t)}function b(s,t){t!==null&&G(s,t)}function Z(s,t){G(s,`${t}px`)}function at(s){const{backgroundColor:t,buttonTextColor:e,secondaryBackgroundColor:o,hintColor:n,buttonColor:r,linkColor:h,textColor:u}=s;b("--tg-theme-bg-color",t),b("--tg-theme-button-color",r),b("--tg-theme-button-text-color",e),b("--tg-theme-hint-color",n),b("--tg-theme-link-color",h),b("--tg-theme-secondary-bg-color",o),b("--tg-theme-text-color",u)}function ct(s,t){const{backgroundColor:e,secondaryBackgroundColor:o}=t,{backgroundColor:n,headerColor:r}=s;b("--tg-bg-color",n),b("--tg-header-color",r==="bg_color"?e:o)}function ht(s){const t=()=>at(s);s.on("changed",t),t()}function ut(s,t){const e=()=>ct(s,t);t.on("changed",e),s.on("backgroundColorChanged",e),s.on("headerColorChanged",e),e()}function pt(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 lt(s){return typeof s=="boolean"?s?{themeParams:!0,viewport:!0,webApp:!0}:{}:s}function X(s){return`telegram-mini-apps-${s}`}function S(s,t){sessionStorage.setItem(X(s),JSON.stringify(t))}function V(s){const t=sessionStorage.getItem(X(s));return t?JSON.parse(t):null}function dt(s,t,e){const{isVisible:o=!1}=s?V("back-button")||{}:{},n=new D(o,t,e);return n.on("isVisibleChanged",()=>{S("back-button",{isVisible:n.isVisible})}),n}function gt(s,t){const{isConfirmationNeeded:e=!1}=s?V("closing-behavior")||{}:{},o=new L(e,t);return o.on("isConfirmationNeededChanged",()=>S("closing-behavior",{isConfirmationNeeded:o.isConfirmationNeeded})),o}function _t(s,t,e,o){const{backgroundColor:n=t,isEnabled:r=!1,isVisible:h=!1,isProgressVisible:u=!1,textColor:p=e,text:g=""}=s?V("main-button")||{}:{},l=new U(n,r,h,u,g,p,o),w=()=>S("main-button",{backgroundColor:l.backgroundColor,isEnabled:l.isEnabled,isVisible:l.isVisible,isProgressVisible:l.isProgressVisible,text:l.text,textColor:l.textColor});return l.on("backgroundColorChanged",w),l.on("isEnabledChanged",w),l.on("isVisibleChanged",w),l.on("isProgressVisibleChanged",w),l.on("textColorChanged",w),l.on("textChanged",w),l}function ft(s,t){return s?(e,o)=>{if(!c.supports(e,t))throw new B(e,t);return T.isRecord(o)&&c.detectSupportParams(e,o).forEach(n=>{if(!c.supports(e,n,t))throw new O(e,n,t)}),c.postEvent(e,o)}:c.postEvent}function mt(){let s=0;return()=>(s+=1,s.toString())}function bt(s){const t=new y(s);return y.sync(t),t}async function wt(s,t,e){const{height:o=window.innerHeight,stableHeight:n=window.innerHeight,width:r=window.innerWidth,isExpanded:h=!1}=s?V("viewport")||{}:{},p=t==="macos"||t==="web"?(()=>{const l=new E(o,r,n,h,e);return E.sync(l),l})():await E.synced({postEvent:e}),g=()=>S("viewport",{height:p.height,isExpanded:p.isExpanded,stableHeight:p.stableHeight,width:p.width});return p.on("heightChanged",g),p.on("isExpandedChanged",g),p.on("stableHeightChanged",g),p.on("widthChanged",g),p}function Ct(s,t,e,o,n,r){const{backgroundColor:h=t,headerColor:u="bg_color"}=s?V("web-app")||{}:{},p=new Q(u,h,e,o,n,r),g=()=>S("web-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("backgroundColorChanged",g),p.on("headerColorChanged",g),p}function R(){let s;try{return d.parse(window.location.hash.slice(1))}catch(e){s=e}const t=d.retrieveFromStorage();if(t)return t;throw new Error("Unable to extract launch params",{cause:s})}function vt(){return window.performance.getEntriesByType("navigation").some(s=>s.type==="reload")}function Et(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 yt(s={}){const{checkCompat:t=!0,cssVars:e=!1,acceptScrollbarStyle:o=!0,acceptCustomStyles:n=o,targetOrigin:r,debug:h=!1,launchParams:u=R()}=s;h&&c.setDebug(h),typeof r=="string"&&c.setTargetOrigin(r);const p=d.retrieveFromStorage(),g=u instanceof URLSearchParams||typeof u=="string"?d.parse(u):u;d.saveToStorage(g);const l=vt()||Et(p,g),{initData:w,initDataRaw:Vt,version:C,platform:Y,themeParams:tt}=g,{backgroundColor:qt="#ffffff",buttonColor:Pt="#000000",buttonTextColor:xt="#ffffff"}=tt,et=mt(),f=ft(t,C),$=bt(tt),st=Ct(l,qt,C,Y,et,f),{themeParams:Bt,viewport:Ot,webApp:jt}=lt(e);jt&&ut(st,$),Bt&&ht($);const ot=await wt(l,Y,f);if(Ot&&pt(ot),n&&c.isIframe()){const q=document.createElement("style");q.id="telegram-custom-styles",document.head.appendChild(q),c.on("set_custom_style",H=>{q.innerHTML=H}),f("iframe_ready")}const A={backButton:dt(l,C,f),closingBehavior:gt(l,f),cloudStorage:new M(C,et,f),haptic:new W(C,f),mainButton:_t(l,Pt,xt,f),popup:new F(C,f),postEvent:f,qrScanner:new K(C,f),themeParams:$,viewport:ot,webApp:st};if(w!==void 0){const{authDate:q,hash:H,...Tt}=w;A.initData=new z(q,H,Tt),A.initDataRaw=Vt}return A}function kt(s={}){return T.withTimeout(yt(s),s.timeout||1e3)}function St(){try{return R(),!0}catch{return!1}}a.BackButton=D,a.ClosingBehaviour=L,a.CloudStorage=M,a.HapticFeedback=W,a.InitData=z,a.MainButton=U,a.MethodNotSupportedError=B,a.ParameterUnsupportedError=O,a.Popup=F,a.QRScanner=K,a.ThemeParams=y,a.Viewport=E,a.WebApp=Q,a.formatURL=x,a.init=kt,a.isTWA=St,a.retrieveLaunchParams=R,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=index.umd.cjs.map
|