@tma.js/sdk 0.12.5 → 0.12.6

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.
@@ -1,2 +1,2 @@
1
- var ar=Object.defineProperty;var cr=(l,v,S)=>v in l?ar(l,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):l[v]=S;var a=(l,v,S)=>(cr(l,typeof v!="symbol"?v+"":v,S),S);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(l){"use strict";var v=Object.defineProperty,S=(t,e,r)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,le=(t,e,r)=>(S(t,typeof e!="symbol"?e+"":e,r),r);let C=class{constructor(){le(this,"listeners",{}),le(this,"subscribeListeners",[])}emit(e,...r){this.subscribeListeners.forEach(o=>o(e,...r));const n=this.listeners[e];if(n===void 0)return;const s=[];n.forEach(o=>{if(typeof o=="function"){o(...r);return}o.once&&s.push(o.listener),o.listener(...r)}),s.forEach(o=>this.off(e,o))}on(e,r){const n=this.listeners[e];n===void 0?this.listeners[e]=[r]:n.push(r)}once(e,r){const n=this.listeners[e],s={listener:r,once:!0};n===void 0?this.listeners[e]=[s]:n.push(s)}off(e,r){const n=this.listeners[e];if(n!==void 0)for(let s=0;s<n.length;s+=1){const o=n[s],i=typeof o=="function"?o:o.listener;r===i&&(n.splice(s,1),s-=1)}}subscribe(e){this.subscribeListeners.push(e)}unsubscribe(e){const r=this.subscribeListeners.indexOf(e);r>=0&&this.subscribeListeners.splice(r,1)}};function W(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function he(t,e){const r=t.split("."),n=e.split("."),s=Math.max(r.length,n.length);for(let o=0;o<s;o+=1){const i=parseInt(r[o]||"0",10),c=parseInt(n[o]||"0",10);if(i!==c)return i>c?1:-1}return 0}let Fe=class Je extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,Je.prototype)}};function de(t){return new Promise((e,r)=>{setTimeout(r,t,new Fe(t))})}function fe(t,e){return typeof t=="function"?(...r)=>Promise.race([t(...r),de(e)]):Promise.race([t,de(e)])}let Ge=class{constructor(e,r){this.prefix=e,this.enabled=r}print(e,...r){if(!this.enabled)return;const n=new Date,s=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(n);console[e](`[${s}]`,this.prefix,...r)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}};function Ke(t){return/^#[\da-f]{3}$/i.test(t)}function ge(t){return/^#[\da-f]{6}$/i.test(t)}function _e(t){const e=t.replace(/\s/g,"").toLowerCase();if(ge(e))return e;if(Ke(e)){let n="#";for(let s=0;s<3;s+=1)n+=e[1+s].repeat(2);return n}const r=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(r===null)throw new Error(`Value "${t}" does not satisfy any of known RGB formats.`);return r.slice(1).reduce((n,s)=>{const o=parseInt(s,10).toString(16);return n+(o.length===1?"0":"")+o},"#")}function be(t){const e=_e(t);return Math.sqrt([.299,.587,.114].reduce((r,n,s)=>{const o=parseInt(e.slice(1+s*2,1+(s+1)*2),16);return r+o*o*n},0))<120}var Qe=Object.defineProperty,Ze=(t,e,r)=>e in t?Qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xe=(t,e,r)=>(Ze(t,typeof e!="symbol"?e+"":e,r),r);class b extends Error{constructor(e,{type:r,error:n,field:s}={}){super(`Unable to parse ${s?`field "${s}"`:"value"} as ${r}`,{cause:{value:e,error:n}}),Object.setPrototypeOf(this,b.prototype)}}class G{constructor(e,r,n){this.parser=e,this.isOptional=r,this.isEmpty=n}parse(e){return this.isOptional&&this.isEmpty(e)?void 0:this.parser(e)}optional(){return this.isOptional=!0,this}}function Ye(t){if(Array.isArray(t))return t;if(typeof t=="string")try{const e=JSON.parse(t);if(Array.isArray(e))return e}catch{}throw new b(t,{type:"array"})}let et=class extends G{constructor(e,r,n){super(Ye,r,n),Xe(this,"itemParser"),this.itemParser=typeof e=="function"?e:e.parse.bind(e)}parse(e){const r=super.parse(e);return r===void 0?r:r.map(this.itemParser)}of(e){return this.itemParser=typeof e=="function"?e:e.parse.bind(e),this}};function K(t){return t===void 0}function tt(){return new et(t=>t,!1,K)}function N(){return new TypeError("Does not have any of expected types")}function T(t,{isEmpty:e=K}={}){return function({isEmpty:r=e}={}){return new G(t,!1,r)}}function we(t,e,r){const n={};for(const s in t){const o=t[s];if(!o)continue;let i,c;if("type"in o){const{type:u}=o;i=o.from||s,c=typeof u=="function"?u:u.parse.bind(u)}else i=s,c=typeof o=="function"?o:o.parse.bind(o);let p;const h=e(i);try{p=c(h)}catch(u){throw new b(h,{field:i,type:r,error:u})}p!==void 0&&(n[s]=p)}return n}const te=T(t=>{if(typeof t=="boolean")return t;throw new b(t,{type:"boolean",error:N()})}),L=T(t=>{if(typeof t=="number")return t;if(typeof t=="string"){const e=Number(t);if(!Number.isNaN(e))return e}throw new b(t,{type:"number",error:N()})}),rt=L(),nt=T(t=>{if(t instanceof Date)return t;try{return new Date(rt.parse(t)*1e3)}catch(e){throw new b(t,{type:"Date",error:e})}});function f(t,e={}){const{type:r,isEmpty:n=K}=e;return new G(s=>{let o=s;if(typeof o=="string")try{o=JSON.parse(o)}catch(i){throw new b(s,{type:r,error:i})}if(typeof o!="object"||o===null||Array.isArray(o))throw new b(s,{type:r,error:N()});return we(t,i=>o[i])},!1,n)}const d=T(t=>{if(typeof t=="string"||typeof t=="number")return t.toString();throw new b(t,{type:"string",error:N()})}),st=d(),me=T(t=>{try{return _e(st.parse(t))}catch(e){throw new b(t,{type:"RGB",error:e})}});function ye(t,e={}){const{type:r,isEmpty:n=K}=e;return new G(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw new b(s,{type:r,error:N()});const o=typeof s=="string"?new URLSearchParams(s):s;return we(t,i=>{const c=o.get(i);return c===null?void 0:c})},!1,n)}let ve="https://web.telegram.org";const H=new Ge("[Bridge]",!1);function ot(t){if(t){H.enable();return}H.disable()}function it(t){ve=t}function at(){return ve}function ct(t){return t==null}const $=me().optional(),ut=L(),pt=T(t=>t==null?window.innerWidth:ut.parse(t)),lt=f({theme_params:f({bg_color:$,text_color:$,hint_color:$,link_color:$,button_color:$,button_text_color:$,secondary_bg_color:$})}),ht=f({height:L(),width:pt(),is_state_stable:te(),is_expanded:te()}),dt=f({button_id:d({isEmpty:ct}).optional()}),ft=f({data:d().optional()}),gt=f({slug:d(),status:d()}),_t=f({req_id:d(),data:t=>t===null?t:d().optional().parse(t)}),bt=f({status:d()}),wt=f({status:d()}),mt=f({req_id:d(),result:t=>t,error:d().optional()}),yt=f({eventType:d(),eventData:t=>t});function vt(t,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:t,eventData:e})}))}function Ct(){const t=window;"TelegramGameProxy_receiveEvent"in t||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let r=t;e.forEach((n,s,o)=>{if(s===o.length-1){r[n]=vt;return}n in r||(r[n]={}),r=r[n]})})}function Et(t){Ct(),window.addEventListener("message",e=>{try{const{eventType:r,eventData:n}=yt.parse(e.data);t(r,n)}catch{}})}const re="__telegram-cached-emitter__";function kt(){const t=new C,e=(r,...n)=>{H.log("Emitting processed event:",r,...n),t.emit(r,...n)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),Et((r,n)=>{H.log("Received raw event:",r,n);try{switch(r){case"viewport_changed":return e(r,ht.parse(n));case"theme_changed":return e(r,lt.parse(n));case"popup_closed":return n==null?e(r,{}):e(r,dt.parse(n));case"set_custom_style":return e(r,d().parse(n));case"qr_text_received":return e(r,ft.parse(n));case"clipboard_text_received":return e(r,_t.parse(n));case"invoice_closed":return e(r,gt.parse(n));case"phone_requested":return e("phone_requested",wt.parse(n));case"custom_method_invoked":return e("custom_method_invoked",mt.parse(n));case"write_access_requested":return e("write_access_requested",bt.parse(n));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":return e(r);default:return e(r,n)}}catch(s){H.error("Error processing event:",s)}}),t}function Ce(){const t=window;return t[re]===void 0&&(t[re]=kt()),t[re]}function ne(t,e){Ce().off(t,e)}function A(t,e){return Ce().on(t,e),()=>ne(t,e)}function Pt(t){return"external"in t&&W(t.external)&&"notify"in t.external&&typeof t.external.notify=="function"}function xt(t){return"TelegramWebviewProxy"in t&&W(t.TelegramWebviewProxy)&&"postEvent"in t.TelegramWebviewProxy&&typeof t.TelegramWebviewProxy.postEvent=="function"}function Ee(){try{return window.self!==window.top}catch{return!0}}function w(t,e,r){let n={},s;e===void 0&&r===void 0?n={}:e!==void 0&&r!==void 0?(n=r,s=e):e!==void 0&&("targetOrigin"in e?n=e:s=e);const{targetOrigin:o=at()}=n;if(Ee()){window.parent.postMessage(JSON.stringify({eventType:t,eventData:s}),o);return}if(Pt(window)){window.external.notify(JSON.stringify({eventType:t,eventData:s}));return}if(xt(window)){window.TelegramWebviewProxy.postEvent(t,JSON.stringify(s));return}throw new Error("Unable to determine current environment and possible way to send event.")}function E(t,e,r,n){let s,o,i,c;typeof e=="string"||Array.isArray(e)?(i=Array.isArray(e)?e:[e],s=r):(o=e,i=Array.isArray(r)?r:[r],s=n),W(o)&&typeof o.req_id=="string"&&(c=o.req_id);const{postEvent:p=w,timeout:h}=s||{},u=s&&"capture"in s?s.capture:null,g=new Promise((ae,x)=>{const ee=i.map(O=>A(O,R=>{typeof c=="string"&&(!W(R)||R.req_id!==c)||typeof u=="function"&&!u(R)||(J(),ae(R))})),J=()=>ee.forEach(O=>O());try{p(t,o)}catch(O){J(),x(O)}});return typeof h=="number"?fe(g,h):g}function V(t,e){return he(t,e)<=0}function St(t,e){return t==="web_app_open_link"&&"try_instant_view"in e?["try_instant_view"]:t==="web_app_set_header_color"&&"color"in e?["color"]:[]}function B(t,e,r){if(typeof r=="string"){if(t==="web_app_open_link"&&e==="try_instant_view")return V("6.4",r);if(t==="web_app_set_header_color"&&e==="color")return V("6.9",r)}switch(t){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return V("6.1",e);case"web_app_open_popup":return V("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return V("6.4",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return V("6.9",e);case"web_app_setup_settings_button":return V("6.10",e);default:return!0}}function D(t,e){return r=>B(e[r],t)}function $t(t,e){return r=>{const[n,s]=e[r];return B(n,s,t)}}class k{constructor(e,r){this.state=e,this.ee=r}emit(e,r){this.ee&&this.ee.emit(e,r)}internalSet(e,r){return this.state[e]===r?!1:(this.state[e]=r,this.emit(`${e}Changed`,r),!0)}set(e,r){let n=!1;if(typeof e=="string")n=this.internalSet(e,r);else for(const s in e)this.internalSet(s,e[s])&&(n=!0);n&&this.emit("changed")}get(e){return this.state[e]}}class ke{constructor(e,r,n=w){a(this,"ee",new C);a(this,"state");a(this,"on",(e,r)=>{if(e==="click")return A("back_button_pressed",r);this.ee.on(e,r)});a(this,"off",(e,r)=>{if(e==="click")return ne("back_button_pressed",r);this.ee.off(e,r)});a(this,"supports");this.postEvent=n,this.state=new k({isVisible:e},this.ee),this.supports=D(r,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}class Pe{constructor(e,r=w){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.postEvent=r,this.state=new k({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const Vt=tt().of(d());function xe(t,e){return t.reduce((r,n)=>(r[n]=e,r),{})}class Se{constructor(e,r,n=w){a(this,"supports");this.createRequestId=r,this.postEvent=n,this.supports=D(e,{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(e,r,n={}){const{result:s,error:o}=await E("web_app_invoke_custom_method",{method:e,params:r,req_id:this.createRequestId()},"custom_method_invoked",{...n,postEvent:this.postEvent});if(o)throw new Error(typeof o=="string"?o:`Unknown error: ${JSON.stringify(o)}`);return s}async deleteKeys(e,r){e.length!==0&&await this.invokeCustomMethod("deleteStorageValues",{keys:e},r)}async getKeys(e){const r=await this.invokeCustomMethod("getStorageKeys",{},e);return Vt.parse(r)}async getValues(e,r){if(e.length===0)return xe(e,"");const n=f(xe(e,d())),s=await this.invokeCustomMethod("getStorageValues",{keys:e},r);return n.parse(s)}async saveValue(e,r,n){await this.invokeCustomMethod("saveStorageValue",{key:e,value:r},n)}}class $e{constructor(e,r=w){a(this,"supports");this.postEvent=r,this.supports=D(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}class Ve{constructor(e,r,n={}){a(this,"state");const{chat:s=null,canSendAfter:o=null,chatType:i=null,chatInstance:c=null,user:p=null,queryId:h=null,receiver:u=null,startParam:g=null}=n;this.state=new k({authDate:e,canSendAfter:o===null?null:new Date(e.getTime()+o*1e3),chat:s,chatType:i,chatInstance:c,user:p,queryId:h,receiver:u,startParam:g,hash:r})}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 qe{constructor(e,r,n,s,o,i,c=w){a(this,"ee",new C);a(this,"state");a(this,"on",(e,r)=>{if(e==="click")return A("main_button_pressed",r);this.ee.on(e,r)});a(this,"off",(e,r)=>{if(e==="click")return ne("main_button_pressed",r);this.ee.off(e,r)});this.postEvent=c,this.state=new k({backgroundColor:e,isEnabled:r,isVisible:n,isProgressVisible:s,text:o,textColor:i},this.ee)}set isEnabled(e){this.state.set("isEnabled",e),this.commit()}get isEnabled(){return this.state.get("isEnabled")}set isProgressVisible(e){this.state.set("isProgressVisible",e),this.commit()}get isProgressVisible(){return this.state.get("isProgressVisible")}set isVisible(e){this.state.set("isVisible",e),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(e){return this.state.set("text",e),this.commit(),this}setTextColor(e){return this.state.set("textColor",e),this.commit(),this}setBackgroundColor(e){return this.state.set("backgroundColor",e),this.commit(),this}}function qt(t){const e=t.message.trim(),r=(t.title||"").trim(),n=t.buttons||[];let s;if(r.length>64)throw new Error(`Title has incorrect size: ${r.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(n.length>3)throw new Error(`Buttons have incorrect size: ${n.length}`);return n.length===0?s=[{type:"close",id:""}]:s=n.map(o=>{const{id:i=""}=o;if(i.length>64)throw new Error(`Button ID has incorrect size: ${i}`);if(o.type===void 0||o.type==="default"||o.type==="destructive"){const c=o.text.trim();if(c.length===0||c.length>64){const p=o.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${o.text.length}`)}return{...o,text:c,id:i}}return{...o,id:i}}),{title:r,message:e,buttons:s}}class Oe{constructor(e,r=w){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=r,this.state=new k({isOpened:!1},this.ee),this.supports=D(e,{open:"web_app_open_popup"})}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("Popup is already opened.");this.state.set("isOpened",!0);try{const{button_id:r=null}=await E("web_app_open_popup",qt(e),"popup_closed",{postEvent:this.postEvent});return r}finally{this.state.set("isOpened",!1)}}}class Te{constructor(e,r=w){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=r,this.state=new k({isOpened:!1},this.ee),this.supports=D(e,{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(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const r=await E("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof r=="object"&&typeof r.data=="string"?r.data:null}finally{this.isOpened=!1}}}const q=me().optional(),Ot=f({backgroundColor:{type:q,from:"bg_color"},buttonColor:{type:q,from:"button_color"},buttonTextColor:{type:q,from:"button_text_color"},hintColor:{type:q,from:"hint_color"},linkColor:{type:q,from:"link_color"},textColor:{type:q,from:"text_color"},secondaryBackgroundColor:{type:q,from:"secondary_bg_color"}});function se(t){return Ot.parse(t)}function Ae(t){const{backgroundColor:e=null,buttonTextColor:r=null,buttonColor:n=null,hintColor:s=null,linkColor:o=null,textColor:i=null,secondaryBackgroundColor:c=null}=t;return{backgroundColor:e,buttonTextColor:r,buttonColor:n,hintColor:s,linkColor:o,textColor:i,secondaryBackgroundColor:c}}class U{constructor(e){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.state=new k(Ae(e),this.ee)}static async request(e={}){const{timeout:r=1e3,...n}=e,s=await E("web_app_request_theme","theme_changed",{...n,timeout:r});return se(s.theme_params)}static sync(e){A("theme_changed",r=>{e.state.set(Ae(se(r.theme_params)))})}static async synced(e){const r=await this.request(e),n=new U(r);return this.sync(n),n}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||be(this.backgroundColor)}get linkColor(){return this.state.get("linkColor")}get secondaryBackgroundColor(){return this.state.get("secondaryBackgroundColor")}get textColor(){return this.state.get("textColor")}}function M(t){return t<0?0:t}class I{constructor(e,r,n,s,o=w){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.postEvent=o,this.state=new k({height:M(e),isExpanded:s,stableHeight:M(n),width:M(r)},this.ee)}static async request(e={}){const{timeout:r=1e3,...n}=e,{is_expanded:s,is_state_stable:o,...i}=await E("web_app_request_viewport","viewport_changed",{...n,timeout:r});return{...i,isExpanded:s,isStateStable:o}}static sync(e){A("viewport_changed",r=>{const{height:n,width:s,is_expanded:o,is_state_stable:i}=r,c=M(n);e.state.set({height:c,isExpanded:o,width:M(s),stableHeight:i?c:void 0})})}static async synced(e={}){const{height:r,isExpanded:n,width:s}=await this.request(e),o=new I(r,s,r,n,e.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 Q(t){const e=document.createElement("a");if(e.href=t,e.protocol!=="http:"&&e.protocol!=="https:")throw Error(`URL protocol is not supported by OS, or link has not allowed protocol: ${e.protocol}`);return e.href}class Be{constructor(e,r,n,s,o,i=w){a(this,"ee",new C);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");a(this,"supportsParam");this.currentVersion=n,this.currentPlatform=s,this.createRequestId=o,this.postEvent=i,this.state=new k({backgroundColor:r,headerColor:e},this.ee),this.supports=D(n,{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=$t(n,{"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 be(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(e){return he(e,this.version)>=0}openLink(e,r){const n=Q(e);if(!B("web_app_open_link",this.version)){window.open(n,"_blank");return}return this.postEvent("web_app_open_link",{url:n,...typeof r=="boolean"?{try_instant_view:r}:{}})}openTelegramLink(e){const{hostname:r,pathname:n,search:s}=new URL(Q(e));if(r!=="t.me")throw new Error(`URL has not allowed hostname: ${r}. Only "t.me" is allowed`);if(!B("web_app_open_tg_link",this.version)){window.location.href=e;return}return this.postEvent("web_app_open_tg_link",{path_full:n+s})}async openInvoice(e){const{hostname:r,pathname:n}=new URL(Q(e));if(r!=="t.me")throw new Error(`Incorrect hostname: ${r}`);const s=n.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,o]=s;return(await E("web_app_open_invoice",{slug:o},"invoice_closed",{postEvent:this.postEvent,capture:({slug:c})=>o===c})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:e=null}=await E("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent});return e}async requestPhoneAccess(){const{status:e}=await E("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return e}async requestWriteAccess(){const{status:e}=await E("web_app_request_write_access","write_access_requested",{postEvent:this.postEvent});return e}sendData(e){const{size:r}=new Blob([e]);if(r===0||r>4096)throw new Error(`Passed data has incorrect size: ${r}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",ge(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}get version(){return this.currentVersion}}class Z extends Error{constructor(e,r){super(`Method "${e}" is not supported in the Web Apps version ${r}.`),Object.setPrototypeOf(this,Z.prototype)}}class X extends Error{constructor(e,r,n){super(`Parameter "${r}" in method "${e}" is not supported in the Web Apps version ${n}.`),Object.setPrototypeOf(this,X.prototype)}}function _(t,e){return{from:e,type:t}}const Y=d(),y=d().optional(),De=L(),Tt=L().optional(),Ie=te().optional();function Re(){return f({firstName:_(Y,"first_name"),id:De,isBot:_(Ie,"is_bot"),isPremium:_(Ie,"is_premium"),lastName:_(y,"last_name"),languageCode:_(y,"language_code"),photoUrl:_(y,"photo_url"),username:y})}function At(){return f({id:De,type:Y,title:Y,photoUrl:_(y,"photo_url"),username:y})}const Bt=ye({authDate:_(nt(),"auth_date"),hash:Y,user:Re().optional(),receiver:Re().optional(),chat:At().optional(),chatType:_(y,"chat_type"),chatInstance:_(y,"chat_instance"),canSendAfter:_(Tt,"can_send_after"),queryId:_(y,"query_id"),startParam:_(y,"start_param")}),Dt=ye({version:{type:d(),from:"tgWebAppVersion"},initData:{type:Bt.optional(),from:"tgWebAppData"},initDataRaw:{type:d().optional(),from:"tgWebAppData"},platform:{type:d(),from:"tgWebAppPlatform"},themeParams:{type:se,from:"tgWebAppThemeParams"}});function oe(t){return Dt.parse(t)}const We="telegram-mini-apps-launch-params";function Ne(){const t=sessionStorage.getItem(We);if(t)try{return oe(t)}catch{}return null}function It(t){const{initDataRaw:e,version:r,platform:n,themeParams:s}=t,o=new URLSearchParams;o.set("tgWebAppVersion",r),o.set("tgWebAppPlatform",n),o.set("tgWebAppThemeParams",JSON.stringify(s)),e&&o.set("tgWebAppData",e),sessionStorage.setItem(We,o.toString())}function Le(t,e){document.documentElement.style.setProperty(t,e)}function P(t,e){e!==null&&Le(t,e)}function He(t,e){Le(t,`${e}px`)}function Rt(t){const{backgroundColor:e,buttonTextColor:r,secondaryBackgroundColor:n,hintColor:s,buttonColor:o,linkColor:i,textColor:c}=t;P("--tg-theme-bg-color",e),P("--tg-theme-button-color",o),P("--tg-theme-button-text-color",r),P("--tg-theme-hint-color",s),P("--tg-theme-link-color",i),P("--tg-theme-secondary-bg-color",n),P("--tg-theme-text-color",c)}function Wt(t,e){const{backgroundColor:r,secondaryBackgroundColor:n}=e,{backgroundColor:s,headerColor:o}=t;P("--tg-bg-color",s),P("--tg-header-color",o==="bg_color"?r:n)}function Nt(t){const e=()=>Rt(t);t.on("changed",e),e()}function Lt(t,e){const r=()=>Wt(t,e);e.on("changed",r),t.on("backgroundColorChanged",r),t.on("headerColorChanged",r),r()}function Ht(t){const e=()=>{He("--tg-viewport-height",t.height)},r=()=>{He("--tg-viewport-stable-height",t.stableHeight)};t.on("heightChanged",e),t.on("stableHeightChanged",r),e(),r()}function Ut(t){return typeof t=="boolean"?t?{themeParams:!0,viewport:!0,webApp:!0}:{}:t}function Ue(t){return`telegram-mini-apps-${t}`}function j(t,e){sessionStorage.setItem(Ue(t),JSON.stringify(e))}function z(t){const e=sessionStorage.getItem(Ue(t));return e?JSON.parse(e):null}function Mt(t,e,r){const{isVisible:n=!1}=t?z("back-button")||{}:{},s=new ke(n,e,r);return s.on("isVisibleChanged",()=>{j("back-button",{isVisible:s.isVisible})}),s}function jt(t,e){const{isConfirmationNeeded:r=!1}=t?z("closing-behavior")||{}:{},n=new Pe(r,e);return n.on("isConfirmationNeededChanged",()=>j("closing-behavior",{isConfirmationNeeded:n.isConfirmationNeeded})),n}function zt(t,e,r,n){const{backgroundColor:s=e,isEnabled:o=!1,isVisible:i=!1,isProgressVisible:c=!1,textColor:p=r,text:h=""}=t?z("main-button")||{}:{},u=new qe(s,o,i,c,h,p,n),g=()=>j("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 Jt(t,e){return t?(r,n)=>{if(!B(r,e))throw new Z(r,e);return W(n)&&St(r,n).forEach(s=>{if(!B(r,s,e))throw new X(r,s,e)}),w(r,n)}:w}function Ft(){let t=0;return()=>(t+=1,t.toString())}function Gt(t){const e=new U(t);return U.sync(e),e}async function Kt(t,e,r){const{height:n=window.innerHeight,stableHeight:s=window.innerHeight,width:o=window.innerWidth,isExpanded:i=!1}=t?z("viewport")||{}:{},p=e==="macos"||e==="web"?(()=>{const u=new I(n,o,s,i,r);return I.sync(u),u})():await I.synced({postEvent:r}),h=()=>j("viewport",{height:p.height,isExpanded:p.isExpanded,stableHeight:p.stableHeight,width:p.width});return p.on("heightChanged",h),p.on("isExpandedChanged",h),p.on("stableHeightChanged",h),p.on("widthChanged",h),p}function Qt(t,e,r,n,s,o){const{backgroundColor:i=e,headerColor:c="bg_color"}=t?z("web-app")||{}:{},p=new Be(c,i,r,n,s,o),h=()=>j("web-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("backgroundColorChanged",h),p.on("headerColorChanged",h),p}function ie(){let t;try{return oe(window.location.hash.slice(1))}catch(r){t=r}const e=Ne();if(e)return e;throw new Error("Unable to extract launch params",{cause:t})}function Zt(){return window.performance.getEntriesByType("navigation").some(t=>t.type==="reload")}function Xt(t,e){var r,n;return t?((r=t.initData)==null?void 0:r.hash)===((n=e.initData)==null?void 0:n.hash):!1}async function Yt(t={}){const{checkCompat:e=!0,cssVars:r=!1,acceptScrollbarStyle:n=!0,acceptCustomStyles:s=n,targetOrigin:o,debug:i=!1,launchParams:c=ie()}=t;i&&ot(i),typeof o=="string"&&it(o);const p=Ne(),h=c instanceof URLSearchParams||typeof c=="string"?oe(c):c;It(h);const u=Zt()||Xt(p,h),{initData:g,initDataRaw:ae,version:x,platform:ee,themeParams:J}=h,{backgroundColor:O="#ffffff",buttonColor:R="#000000",buttonTextColor:rr="#ffffff"}=J,Me=Ft(),m=Jt(e,x),ce=Gt(J),je=Qt(u,O,x,ee,Me,m),{themeParams:nr,viewport:sr,webApp:or}=Ut(r);or&&Lt(je,ce),nr&&Nt(ce);const ze=await Kt(u,ee,m);if(sr&&Ht(ze),s&&Ee()){const F=document.createElement("style");F.id="telegram-custom-styles",document.head.appendChild(F),A("set_custom_style",pe=>{F.innerHTML=pe}),m("iframe_ready")}const ue={backButton:Mt(u,x,m),closingBehavior:jt(u,m),cloudStorage:new Se(x,Me,m),haptic:new $e(x,m),mainButton:zt(u,R,rr,m),popup:new Oe(x,m),postEvent:m,qrScanner:new Te(x,m),themeParams:ce,viewport:ze,webApp:je};if(g!==void 0){const{authDate:F,hash:pe,...ir}=g;ue.initData=new Ve(F,pe,ir),ue.initDataRaw=ae}return ue}function er(t={}){return fe(Yt(t),t.timeout||1e3)}function tr(){try{return ie(),!0}catch{return!1}}return l.BackButton=ke,l.ClosingBehaviour=Pe,l.CloudStorage=Se,l.HapticFeedback=$e,l.InitData=Ve,l.MainButton=qe,l.MethodNotSupportedError=Z,l.ParameterUnsupportedError=X,l.Popup=Oe,l.QRScanner=Te,l.ThemeParams=U,l.Viewport=I,l.WebApp=Be,l.formatURL=Q,l.init=er,l.isTWA=tr,l.retrieveLaunchParams=ie,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"}),l}({});
1
+ var nr=Object.defineProperty;var or=(h,w,P)=>w in h?nr(h,w,{enumerable:!0,configurable:!0,writable:!0,value:P}):h[w]=P;var c=(h,w,P)=>(or(h,typeof w!="symbol"?w+"":w,P),P);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(h){"use strict";var w=Object.defineProperty,P=(t,e,r)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ae=(t,e,r)=>(P(t,typeof e!="symbol"?e+"":e,r),r);let y=class{constructor(){ae(this,"listeners",{}),ae(this,"subscribeListeners",[])}emit(e,...r){this.subscribeListeners.forEach(s=>s(e,...r));const n=this.listeners[e];if(n===void 0)return;const o=[];n.forEach(s=>{if(typeof s=="function"){s(...r);return}s.once&&o.push(s.listener),s.listener(...r)}),o.forEach(s=>this.off(e,s))}on(e,r){const n=this.listeners[e];n===void 0?this.listeners[e]=[r]:n.push(r)}once(e,r){const n=this.listeners[e],o={listener:r,once:!0};n===void 0?this.listeners[e]=[o]:n.push(o)}off(e,r){const n=this.listeners[e];if(n!==void 0)for(let o=0;o<n.length;o+=1){const s=n[o],i=typeof s=="function"?s:s.listener;r===i&&(n.splice(o,1),o-=1)}}subscribe(e){this.subscribeListeners.push(e)}unsubscribe(e){const r=this.subscribeListeners.indexOf(e);r>=0&&this.subscribeListeners.splice(r,1)}};function R(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ce(t,e){const r=t.split("."),n=e.split("."),o=Math.max(r.length,n.length);for(let s=0;s<o;s+=1){const i=parseInt(r[s]||"0",10),a=parseInt(n[s]||"0",10);if(i!==a)return i>a?1:-1}return 0}let Me=class Ue extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,Ue.prototype)}};function ue(t){return new Promise((e,r)=>{setTimeout(r,t,new Me(t))})}function pe(t,e){return typeof t=="function"?(...r)=>Promise.race([t(...r),ue(e)]):Promise.race([t,ue(e)])}let je=class{constructor(e,r){this.prefix=e,this.enabled=r}print(e,...r){if(!this.enabled)return;const n=new Date,o=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(n);console[e](`[${o}]`,this.prefix,...r)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}};function ze(t){return/^#[\da-f]{3}$/i.test(t)}function le(t){return/^#[\da-f]{6}$/i.test(t)}function he(t){const e=t.replace(/\s/g,"").toLowerCase();if(le(e))return e;if(ze(e)){let n="#";for(let o=0;o<3;o+=1)n+=e[1+o].repeat(2);return n}const r=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(r===null)throw new Error(`Value "${t}" does not satisfy any of known RGB formats.`);return r.slice(1).reduce((n,o)=>{const s=parseInt(o,10).toString(16);return n+(s.length===1?"0":"")+s},"#")}function de(t){const e=he(t);return Math.sqrt([.299,.587,.114].reduce((r,n,o)=>{const s=parseInt(e.slice(1+o*2,1+(o+1)*2),16);return r+s*s*n},0))<120}var Je=Object.defineProperty,Fe=(t,e,r)=>e in t?Je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ge=(t,e,r)=>(Fe(t,typeof e!="symbol"?e+"":e,r),r);class g extends Error{constructor(e,{type:r,error:n,field:o}={}){super(`Unable to parse ${o?`field "${o}"`:"value"} as ${r}`,{cause:{value:e,error:n}}),Object.setPrototypeOf(this,g.prototype)}}let J=class{constructor(e,r,n){this.parser=e,this.isOptional=r,this.isEmpty=n}parse(e){return this.isOptional&&this.isEmpty(e)?void 0:this.parser(e)}optional(){return this.isOptional=!0,this}};function Ke(t){if(Array.isArray(t))return t;if(typeof t=="string")try{const e=JSON.parse(t);if(Array.isArray(e))return e}catch{}throw new g(t,{type:"array"})}let Qe=class extends J{constructor(e,r,n){super(Ke,r,n),Ge(this,"itemParser"),this.itemParser=typeof e=="function"?e:e.parse.bind(e)}parse(e){const r=super.parse(e);return r===void 0?r:r.map(this.itemParser)}of(e){return this.itemParser=typeof e=="function"?e:e.parse.bind(e),this}};function F(t){return t===void 0}function Ze(){return new Qe(t=>t,!1,F)}function W(){return new TypeError("Does not have any of expected types")}function q(t,{isEmpty:e=F}={}){return function({isEmpty:r=e}={}){return new J(t,!1,r)}}function fe(t,e,r){const n={};for(const o in t){const s=t[o];if(!s)continue;let i,a;if("type"in s){const{type:u}=s;i=s.from||o,a=typeof u=="function"?u:u.parse.bind(u)}else i=o,a=typeof s=="function"?s:s.parse.bind(s);let l;const d=e(i);try{l=a(d)}catch(u){throw new g(d,{field:i,type:r,error:u})}l!==void 0&&(n[o]=l)}return n}const G=q(t=>{if(typeof t=="boolean")return t;throw new g(t,{type:"boolean",error:W()})}),O=q(t=>{if(typeof t=="number")return t;if(typeof t=="string"){const e=Number(t);if(!Number.isNaN(e))return e}throw new g(t,{type:"number",error:W()})}),Xe=O(),Ye=q(t=>{if(t instanceof Date)return t;try{return new Date(Xe.parse(t)*1e3)}catch(e){throw new g(t,{type:"Date",error:e})}});function f(t,e={}){const{type:r,isEmpty:n=F}=e;return new J(o=>{let s=o;if(typeof s=="string")try{s=JSON.parse(s)}catch(i){throw new g(o,{type:r,error:i})}if(typeof s!="object"||s===null||Array.isArray(s))throw new g(o,{type:r,error:W()});return fe(t,i=>s[i])},!1,n)}const p=q(t=>{if(typeof t=="string"||typeof t=="number")return t.toString();throw new g(t,{type:"string",error:W()})}),et=p(),_e=q(t=>{try{return he(et.parse(t))}catch(e){throw new g(t,{type:"RGB",error:e})}});function ge(t,e={}){const{type:r,isEmpty:n=F}=e;return new J(o=>{if(typeof o!="string"&&!(o instanceof URLSearchParams))throw new g(o,{type:r,error:W()});const s=typeof o=="string"?new URLSearchParams(o):o;return fe(t,i=>{const a=s.get(i);return a===null?void 0:a})},!1,n)}let be="https://web.telegram.org";const N=new je("[Bridge]",!1);function tt(t){if(t){N.enable();return}N.disable()}function rt(t){be=t}function nt(){return be}function ot(t){return t==null}const x=_e().optional(),st=O(),it=q(t=>t==null?window.innerWidth:st.parse(t)),at=f({theme_params:f({bg_color:x,text_color:x,hint_color:x,link_color:x,button_color:x,button_text_color:x,secondary_bg_color:x})}),ct=f({height:O(),width:it(),is_state_stable:G(),is_expanded:G()}),ut=f({button_id:p({isEmpty:ot}).optional()}),pt=f({data:p().optional()}),lt=f({slug:p(),status:p()}),ht=f({req_id:p(),data:t=>t===null?t:p().optional().parse(t)}),dt=f({status:p()}),ft=f({status:p()}),_t=f({req_id:p(),result:t=>t,error:p().optional()}),gt=f({eventType:p(),eventData:t=>t});function bt(t,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:t,eventData:e})}))}function mt(){const t=window;"TelegramGameProxy_receiveEvent"in t||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let r=t;e.forEach((n,o,s)=>{if(o===s.length-1){r[n]=bt;return}n in r||(r[n]={}),r=r[n]})})}function wt(t){mt(),window.addEventListener("message",e=>{try{const{eventType:r,eventData:n}=gt.parse(e.data);t(r,n)}catch{}})}const Y="__telegram-cached-emitter__";function yt(){const t=new y,e=(r,...n)=>{N.log("Emitting processed event:",r,...n),t.emit(r,...n)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),wt((r,n)=>{N.log("Received raw event:",r,n);try{switch(r){case"viewport_changed":return e(r,ct.parse(n));case"theme_changed":return e(r,at.parse(n));case"popup_closed":return n==null?e(r,{}):e(r,ut.parse(n));case"set_custom_style":return e(r,p().parse(n));case"qr_text_received":return e(r,pt.parse(n));case"clipboard_text_received":return e(r,ht.parse(n));case"invoice_closed":return e(r,lt.parse(n));case"phone_requested":return e("phone_requested",ft.parse(n));case"custom_method_invoked":return e("custom_method_invoked",_t.parse(n));case"write_access_requested":return e("write_access_requested",dt.parse(n));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":return e(r);default:return e(r,n)}}catch(o){N.error("Error processing event:",o)}}),t}function me(){const t=window;return t[Y]===void 0&&(t[Y]=yt()),t[Y]}function ee(t,e){me().off(t,e)}function T(t,e){return me().on(t,e),()=>ee(t,e)}function vt(t){return"external"in t&&R(t.external)&&"notify"in t.external&&typeof t.external.notify=="function"}function Ct(t){return"TelegramWebviewProxy"in t&&R(t.TelegramWebviewProxy)&&"postEvent"in t.TelegramWebviewProxy&&typeof t.TelegramWebviewProxy.postEvent=="function"}function we(){try{return window.self!==window.top}catch{return!0}}function b(t,e,r){let n={},o;e===void 0&&r===void 0?n={}:e!==void 0&&r!==void 0?(n=r,o=e):e!==void 0&&("targetOrigin"in e?n=e:o=e);const{targetOrigin:s=nt()}=n;if(we()){window.parent.postMessage(JSON.stringify({eventType:t,eventData:o}),s);return}if(vt(window)){window.external.notify(JSON.stringify({eventType:t,eventData:o}));return}if(Ct(window)){window.TelegramWebviewProxy.postEvent(t,JSON.stringify(o));return}throw new Error("Unable to determine current environment and possible way to send event.")}function v(t,e,r,n){let o,s,i,a;typeof e=="string"||Array.isArray(e)?(i=Array.isArray(e)?e:[e],o=r):(s=e,i=Array.isArray(r)?r:[r],o=n),R(s)&&typeof s.req_id=="string"&&(a=s.req_id);const{postEvent:l=b,timeout:d}=o||{},u=o&&"capture"in o?o.capture:null,_=new Promise((ne,k)=>{const X=i.map(V=>T(V,I=>{typeof a=="string"&&(!R(I)||I.req_id!==a)||typeof u=="function"&&!u(I)||(j(),ne(I))})),j=()=>X.forEach(V=>V());try{l(t,s)}catch(V){j(),k(V)}});return typeof d=="number"?pe(_,d):_}function S(t,e){return ce(t,e)<=0}function Et(t,e){return t==="web_app_open_link"&&"try_instant_view"in e?["try_instant_view"]:t==="web_app_set_header_color"&&"color"in e?["color"]:[]}function A(t,e,r){if(typeof r=="string"){if(t==="web_app_open_link"&&e==="try_instant_view")return S("6.4",r);if(t==="web_app_set_header_color"&&e==="color")return S("6.9",r)}switch(t){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return S("6.1",e);case"web_app_open_popup":return S("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return S("6.4",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return S("6.9",e);case"web_app_setup_settings_button":return S("6.10",e);default:return!0}}function B(t,e){return r=>A(e[r],t)}function kt(t,e){return r=>{const[n,o]=e[r];return A(n,o,t)}}class C{constructor(e,r){this.state=e,this.ee=r}emit(e,r){this.ee&&this.ee.emit(e,r)}internalSet(e,r){return this.state[e]===r?!1:(this.state[e]=r,this.emit(`${e}Changed`,r),!0)}set(e,r){let n=!1;if(typeof e=="string")n=this.internalSet(e,r);else for(const o in e)this.internalSet(o,e[o])&&(n=!0);n&&this.emit("changed")}get(e){return this.state[e]}}class ye{constructor(e,r,n=b){c(this,"ee",new y);c(this,"state");c(this,"on",(e,r)=>{if(e==="click")return T("back_button_pressed",r);this.ee.on(e,r)});c(this,"off",(e,r)=>{if(e==="click")return ee("back_button_pressed",r);this.ee.off(e,r)});c(this,"supports");this.postEvent=n,this.state=new C({isVisible:e},this.ee),this.supports=B(r,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}class ve{constructor(e,r=b){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));this.postEvent=r,this.state=new C({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const Pt=Ze().of(p());function Ce(t,e){return t.reduce((r,n)=>(r[n]=e,r),{})}class Ee{constructor(e,r,n=b){c(this,"supports");this.createRequestId=r,this.postEvent=n,this.supports=B(e,{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(e,r,n={}){const{result:o,error:s}=await v("web_app_invoke_custom_method",{method:e,params:r,req_id:this.createRequestId()},"custom_method_invoked",{...n,postEvent:this.postEvent});if(s)throw new Error(typeof s=="string"?s:`Unknown error: ${JSON.stringify(s)}`);return o}async deleteKeys(e,r){e.length!==0&&await this.invokeCustomMethod("deleteStorageValues",{keys:e},r)}async getKeys(e){const r=await this.invokeCustomMethod("getStorageKeys",{},e);return Pt.parse(r)}async getValues(e,r){if(e.length===0)return Ce(e,"");const n=f(Ce(e,p())),o=await this.invokeCustomMethod("getStorageValues",{keys:e},r);return n.parse(o)}async saveValue(e,r,n){await this.invokeCustomMethod("saveStorageValue",{key:e,value:r},n)}}class ke{constructor(e,r=b){c(this,"supports");this.postEvent=r,this.supports=B(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}class Pe{constructor(e,r,n={}){c(this,"state");const{chat:o=null,canSendAfter:s=null,chatType:i=null,chatInstance:a=null,user:l=null,queryId:d=null,receiver:u=null,startParam:_=null}=n;this.state=new C({authDate:e,canSendAfter:s===null?null:new Date(e.getTime()+s*1e3),chat:o,chatType:i,chatInstance:a,user:l,queryId:d,receiver:u,startParam:_,hash:r})}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 xe{constructor(e,r,n,o,s,i,a=b){c(this,"ee",new y);c(this,"state");c(this,"on",(e,r)=>{if(e==="click")return T("main_button_pressed",r);this.ee.on(e,r)});c(this,"off",(e,r)=>{if(e==="click")return ee("main_button_pressed",r);this.ee.off(e,r)});this.postEvent=a,this.state=new C({backgroundColor:e,isEnabled:r,isVisible:n,isProgressVisible:o,text:s,textColor:i},this.ee)}set isEnabled(e){this.state.set("isEnabled",e),this.commit()}get isEnabled(){return this.state.get("isEnabled")}set isProgressVisible(e){this.state.set("isProgressVisible",e),this.commit()}get isProgressVisible(){return this.state.get("isProgressVisible")}set isVisible(e){this.state.set("isVisible",e),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(e){return this.state.set("text",e),this.commit(),this}setTextColor(e){return this.state.set("textColor",e),this.commit(),this}setBackgroundColor(e){return this.state.set("backgroundColor",e),this.commit(),this}}function xt(t){const e=t.message.trim(),r=(t.title||"").trim(),n=t.buttons||[];let o;if(r.length>64)throw new Error(`Title has incorrect size: ${r.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(n.length>3)throw new Error(`Buttons have incorrect size: ${n.length}`);return n.length===0?o=[{type:"close",id:""}]:o=n.map(s=>{const{id:i=""}=s;if(i.length>64)throw new Error(`Button ID has incorrect size: ${i}`);if(s.type===void 0||s.type==="default"||s.type==="destructive"){const a=s.text.trim();if(a.length===0||a.length>64){const l=s.type||"default";throw new Error(`Button text with type "${l}" has incorrect size: ${s.text.length}`)}return{...s,text:a,id:i}}return{...s,id:i}}),{title:r,message:e,buttons:o}}class Se{constructor(e,r=b){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));c(this,"supports");this.postEvent=r,this.state=new C({isOpened:!1},this.ee),this.supports=B(e,{open:"web_app_open_popup"})}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("Popup is already opened.");this.state.set("isOpened",!0);try{const{button_id:r=null}=await v("web_app_open_popup",xt(e),"popup_closed",{postEvent:this.postEvent});return r}finally{this.state.set("isOpened",!1)}}}class $e{constructor(e,r=b){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));c(this,"supports");this.postEvent=r,this.state=new C({isOpened:!1},this.ee),this.supports=B(e,{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(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const r=await v("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof r=="object"&&typeof r.data=="string"?r.data:null}finally{this.isOpened=!1}}}const $=_e().optional();function Ve(){return f({backgroundColor:{type:$,from:"bg_color"},buttonColor:{type:$,from:"button_color"},buttonTextColor:{type:$,from:"button_text_color"},hintColor:{type:$,from:"hint_color"},linkColor:{type:$,from:"link_color"},secondaryBackgroundColor:{type:$,from:"secondary_bg_color"},textColor:{type:$,from:"text_color"}})}function qe(t){return Ve().parse(t)}function St(t){const{linkColor:e,secondaryBackgroundColor:r,hintColor:n,textColor:o,buttonTextColor:s,buttonColor:i,backgroundColor:a}=t;return JSON.stringify({bg_color:a,button_color:i,button_text_color:s,hint_color:n,link_color:e,secondary_bg_color:r,text_color:o})}function Oe(t){const{backgroundColor:e=null,buttonTextColor:r=null,buttonColor:n=null,hintColor:o=null,linkColor:s=null,textColor:i=null,secondaryBackgroundColor:a=null}=t;return{backgroundColor:e,buttonTextColor:r,buttonColor:n,hintColor:o,linkColor:s,textColor:i,secondaryBackgroundColor:a}}class L{constructor(e){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));this.state=new C(Oe(e),this.ee)}static async request(e={}){const{timeout:r=1e3,...n}=e,o=await v("web_app_request_theme","theme_changed",{...n,timeout:r});return qe(o.theme_params)}static sync(e){T("theme_changed",r=>{e.state.set(Oe(qe(r.theme_params)))})}static async synced(e){const r=await this.request(e),n=new L(r);return this.sync(n),n}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||de(this.backgroundColor)}get linkColor(){return this.state.get("linkColor")}get secondaryBackgroundColor(){return this.state.get("secondaryBackgroundColor")}get textColor(){return this.state.get("textColor")}}function H(t){return t<0?0:t}class D{constructor(e,r,n,o,s=b){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));this.postEvent=s,this.state=new C({height:H(e),isExpanded:o,stableHeight:H(n),width:H(r)},this.ee)}static async request(e={}){const{timeout:r=1e3,...n}=e,{is_expanded:o,is_state_stable:s,...i}=await v("web_app_request_viewport","viewport_changed",{...n,timeout:r});return{...i,isExpanded:o,isStateStable:s}}static sync(e){T("viewport_changed",r=>{const{height:n,width:o,is_expanded:s,is_state_stable:i}=r,a=H(n);e.state.set({height:a,isExpanded:s,width:H(o),stableHeight:i?a:void 0})})}static async synced(e={}){const{height:r,isExpanded:n,width:o}=await this.request(e),s=new D(r,o,r,n,e.postEvent);return this.sync(s),s}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 K(t){const e=document.createElement("a");if(e.href=t,e.protocol!=="http:"&&e.protocol!=="https:")throw Error(`URL protocol is not supported by OS, or link has not allowed protocol: ${e.protocol}`);return e.href}class Te{constructor(e,r,n,o,s,i=b){c(this,"ee",new y);c(this,"state");c(this,"on",this.ee.on.bind(this.ee));c(this,"off",this.ee.off.bind(this.ee));c(this,"supports");c(this,"supportsParam");this.currentVersion=n,this.currentPlatform=o,this.createRequestId=s,this.postEvent=i,this.state=new C({backgroundColor:r,headerColor:e},this.ee),this.supports=B(n,{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=kt(n,{"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 de(this.backgroundColor)?"dark":"light"}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}isVersionAtLeast(e){return ce(e,this.version)>=0}openLink(e,r){const n=K(e);if(!A("web_app_open_link",this.version)){window.open(n,"_blank");return}return this.postEvent("web_app_open_link",{url:n,...typeof r=="boolean"?{try_instant_view:r}:{}})}openTelegramLink(e){const{hostname:r,pathname:n,search:o}=new URL(K(e));if(r!=="t.me")throw new Error(`URL has not allowed hostname: ${r}. Only "t.me" is allowed`);if(!A("web_app_open_tg_link",this.version)){window.location.href=e;return}return this.postEvent("web_app_open_tg_link",{path_full:n+o})}async openInvoice(e){const{hostname:r,pathname:n}=new URL(K(e));if(r!=="t.me")throw new Error(`Incorrect hostname: ${r}`);const o=n.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(o===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/slug" or "/$slug"');const[,,s]=o;return(await v("web_app_open_invoice",{slug:s},"invoice_closed",{postEvent:this.postEvent,capture:({slug:a})=>s===a})).status}get platform(){return this.currentPlatform}ready(){this.postEvent("web_app_ready")}async readTextFromClipboard(){const{data:e=null}=await v("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent});return e}async requestPhoneAccess(){const{status:e}=await v("web_app_request_phone","phone_requested",{postEvent:this.postEvent});return e}async requestWriteAccess(){const{status:e}=await v("web_app_request_write_access","write_access_requested",{postEvent:this.postEvent});return e}sendData(e){const{size:r}=new Blob([e]);if(r===0||r>4096)throw new Error(`Passed data has incorrect size: ${r}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",le(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}get version(){return this.currentVersion}}class Q extends Error{constructor(e,r){super(`Method "${e}" is not supported in the Web Apps version ${r}.`),Object.setPrototypeOf(this,Q.prototype)}}class Z extends Error{constructor(e,r,n){super(`Parameter "${r}" in method "${e}" is not supported in the Web Apps version ${n}.`),Object.setPrototypeOf(this,Z.prototype)}}function $t(){return f({id:O(),type:p(),title:p(),photoUrl:{type:p().optional(),from:"photo_url"},username:p().optional()})}function Ae(){return f({firstName:{type:p(),from:"first_name"},id:O(),isBot:{type:G().optional(),from:"is_bot"},isPremium:{type:G().optional(),from:"is_premium"},lastName:{type:p().optional(),from:"last_name"},languageCode:{type:p().optional(),from:"language_code"},photoUrl:{type:p().optional(),from:"photo_url"},username:p().optional()})}function Vt(){return ge({authDate:{type:Ye(),from:"auth_date"},canSendAfter:{type:O().optional(),from:"can_send_after"},chat:$t().optional(),chatInstance:{type:p().optional(),from:"chat_instance"},chatType:{type:p().optional(),from:"chat_type"},hash:p(),queryId:{type:p().optional(),from:"query_id"},receiver:Ae().optional(),startParam:{type:p().optional(),from:"start_param"},user:Ae().optional()})}function qt(){return ge({initData:{type:Vt().optional(),from:"tgWebAppData"},initDataRaw:{type:p().optional(),from:"tgWebAppData"},platform:{type:p(),from:"tgWebAppPlatform"},themeParams:{type:Ve(),from:"tgWebAppThemeParams"},version:{type:p(),from:"tgWebAppVersion"}})}function te(t){return qt().parse(t)}function Ot(t){const{initDataRaw:e,themeParams:r,platform:n,version:o}=t,s=new URLSearchParams;return e&&s.set("tgWebAppData",e),s.set("tgWebAppPlatform",n),s.set("tgWebAppThemeParams",St(r)),s.set("tgWebAppVersion",o),s.toString()}const Be="telegram-mini-apps-launch-params";function De(){const t=sessionStorage.getItem(Be);if(t)try{return te(t)}catch{}return null}function Tt(t){sessionStorage.setItem(Be,Ot(t))}function Ie(t,e){document.documentElement.style.setProperty(t,e)}function E(t,e){e!==null&&Ie(t,e)}function Re(t,e){Ie(t,`${e}px`)}function At(t){const{backgroundColor:e,buttonTextColor:r,secondaryBackgroundColor:n,hintColor:o,buttonColor:s,linkColor:i,textColor:a}=t;E("--tg-theme-bg-color",e),E("--tg-theme-button-color",s),E("--tg-theme-button-text-color",r),E("--tg-theme-hint-color",o),E("--tg-theme-link-color",i),E("--tg-theme-secondary-bg-color",n),E("--tg-theme-text-color",a)}function Bt(t,e){const{backgroundColor:r,secondaryBackgroundColor:n}=e,{backgroundColor:o,headerColor:s}=t;E("--tg-bg-color",o),E("--tg-header-color",s==="bg_color"?r:n)}function Dt(t){const e=()=>At(t);t.on("changed",e),e()}function It(t,e){const r=()=>Bt(t,e);e.on("changed",r),t.on("backgroundColorChanged",r),t.on("headerColorChanged",r),r()}function Rt(t){const e=()=>{Re("--tg-viewport-height",t.height)},r=()=>{Re("--tg-viewport-stable-height",t.stableHeight)};t.on("heightChanged",e),t.on("stableHeightChanged",r),e(),r()}function Wt(t){return typeof t=="boolean"?t?{themeParams:!0,viewport:!0,webApp:!0}:{}:t}function We(t){return`telegram-mini-apps-${t}`}function U(t,e){sessionStorage.setItem(We(t),JSON.stringify(e))}function M(t){const e=sessionStorage.getItem(We(t));return e?JSON.parse(e):null}function Nt(t,e,r){const{isVisible:n=!1}=t?M("back-button")||{}:{},o=new ye(n,e,r);return o.on("isVisibleChanged",()=>{U("back-button",{isVisible:o.isVisible})}),o}function Lt(t,e){const{isConfirmationNeeded:r=!1}=t?M("closing-behavior")||{}:{},n=new ve(r,e);return n.on("isConfirmationNeededChanged",()=>U("closing-behavior",{isConfirmationNeeded:n.isConfirmationNeeded})),n}function Ht(t,e,r,n){const{backgroundColor:o=e,isEnabled:s=!1,isVisible:i=!1,isProgressVisible:a=!1,textColor:l=r,text:d=""}=t?M("main-button")||{}:{},u=new xe(o,s,i,a,d,l,n),_=()=>U("main-button",{backgroundColor:u.backgroundColor,isEnabled:u.isEnabled,isVisible:u.isVisible,isProgressVisible:u.isProgressVisible,text:u.text,textColor:u.textColor});return u.on("backgroundColorChanged",_),u.on("isEnabledChanged",_),u.on("isVisibleChanged",_),u.on("isProgressVisibleChanged",_),u.on("textColorChanged",_),u.on("textChanged",_),u}function Ut(t,e){return t?(r,n)=>{if(!A(r,e))throw new Q(r,e);return R(n)&&Et(r,n).forEach(o=>{if(!A(r,o,e))throw new Z(r,o,e)}),b(r,n)}:b}function Mt(){let t=0;return()=>(t+=1,t.toString())}function jt(t){const e=new L(t);return L.sync(e),e}async function zt(t,e,r){const{height:n=window.innerHeight,stableHeight:o=window.innerHeight,width:s=window.innerWidth,isExpanded:i=!1}=t?M("viewport")||{}:{},l=e==="macos"||e==="web"?(()=>{const u=new D(n,s,o,i,r);return D.sync(u),u})():await D.synced({postEvent:r}),d=()=>U("viewport",{height:l.height,isExpanded:l.isExpanded,stableHeight:l.stableHeight,width:l.width});return l.on("heightChanged",d),l.on("isExpandedChanged",d),l.on("stableHeightChanged",d),l.on("widthChanged",d),l}function Jt(t,e,r,n,o,s){const{backgroundColor:i=e,headerColor:a="bg_color"}=t?M("web-app")||{}:{},l=new Te(a,i,r,n,o,s),d=()=>U("web-app",{backgroundColor:l.backgroundColor,headerColor:l.headerColor});return l.on("backgroundColorChanged",d),l.on("headerColorChanged",d),l}function re(){let t;try{return te(window.location.hash.slice(1))}catch(r){t=r}const e=De();if(e)return e;throw new Error("Unable to extract launch params",{cause:t})}function Ft(){return window.performance.getEntriesByType("navigation").some(t=>t.type==="reload")}function Gt(t,e){var r,n;return t?((r=t.initData)==null?void 0:r.hash)===((n=e.initData)==null?void 0:n.hash):!1}async function Kt(t={}){const{checkCompat:e=!0,cssVars:r=!1,acceptScrollbarStyle:n=!0,acceptCustomStyles:o=n,targetOrigin:s,debug:i=!1,launchParams:a}=t;i&&tt(i),typeof s=="string"&&rt(s);const l=De(),d=a instanceof URLSearchParams||typeof a=="string"?te(a):re();Tt(d);const u=Ft()||Gt(l,d),{initData:_,initDataRaw:ne,version:k,platform:X,themeParams:j}=d,{backgroundColor:V="#ffffff",buttonColor:I="#000000",buttonTextColor:Xt="#ffffff"}=j,Ne=Mt(),m=Ut(e,k),oe=jt(j),Le=Jt(u,V,k,X,Ne,m),{themeParams:Yt,viewport:er,webApp:tr}=Wt(r);tr&&It(Le,oe),Yt&&Dt(oe);const He=await zt(u,X,m);if(er&&Rt(He),o&&we()){const z=document.createElement("style");z.id="telegram-custom-styles",document.head.appendChild(z),T("set_custom_style",ie=>{z.innerHTML=ie}),m("iframe_ready")}const se={backButton:Nt(u,k,m),closingBehavior:Lt(u,m),cloudStorage:new Ee(k,Ne,m),haptic:new ke(k,m),mainButton:Ht(u,I,Xt,m),popup:new Se(k,m),postEvent:m,qrScanner:new $e(k,m),themeParams:oe,viewport:He,webApp:Le};if(_!==void 0){const{authDate:z,hash:ie,...rr}=_;se.initData=new Pe(z,ie,rr),se.initDataRaw=ne}return se}function Qt(t={}){return pe(Kt(t),t.timeout||1e3)}function Zt(){try{return re(),!0}catch{return!1}}return h.BackButton=ye,h.ClosingBehaviour=ve,h.CloudStorage=Ee,h.HapticFeedback=ke,h.InitData=Pe,h.MainButton=xe,h.MethodNotSupportedError=Q,h.ParameterUnsupportedError=Z,h.Popup=Se,h.QRScanner=$e,h.ThemeParams=L,h.Viewport=D,h.WebApp=Te,h.formatURL=K,h.init=Qt,h.isTWA=Zt,h.retrieveLaunchParams=re,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),h}({});
2
2
  //# sourceMappingURL=index.iife.js.map