@tma.js/sdk 0.13.2 → 0.13.3

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