@tma.js/sdk 1.5.1 → 1.5.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,7 +1,7 @@
1
1
  import type { LaunchParams } from './types.js';
2
2
  /**
3
- * @param url - URL to extract launch parameters from.
3
+ * @param urlString - URL to extract launch parameters from.
4
4
  * @returns Launch parameters from the specified URL.
5
5
  * @throws Error if function was unable to extract launch parameters from the passed URL.
6
6
  */
7
- export declare function retrieveFromUrl(url: string): LaunchParams;
7
+ export declare function retrieveFromUrl(urlString: string): LaunchParams;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ot=Object.defineProperty;var at=(r,e,t)=>e in r?ot(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(at(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class ve{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,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)}}let Pe="https://web.telegram.org";const x=new ve("[SDK]",!1);function ct(r){if(r){x.enable();return}x.disable()}function ht(r){Pe=r}function ut(){return Pe}function ne(){try{return window.self!==window.top}catch{return!0}}function T(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function pt(r){return"external"in r&&T(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function lt(r){return"TelegramWebviewProxy"in r&&T(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=ut()}=s;if(x.log(`Calling method "${r}"`,n),ne()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(pt(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(lt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function Se(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const a=parseInt(t[i]||"0",10),c=parseInt(s[i]||"0",10);if(a!==c)return a>c?1:-1}return 0}function S(r,e){return Se(r,e)<=0}function q(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return S("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return S("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 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_switch_inline_query":return S("6.7",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}}class z extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,z.prototype)}}class J extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,J.prototype)}}function ke(r){return(e,t)=>{if(!q(e,r))throw new z(e,r);if(T(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!q(e,s,r))throw new J(e,s,r)}return d(e,t)}}function xe(r){return({req_id:e})=>e===r}class W extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});o(this,"type");this.value=t,Object.setPrototypeOf(this,W.prototype),this.type=n}}class H extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,H.prototype)}}function qe(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,a;if(typeof n=="function"||"parse"in n)i=s,a=typeof n=="function"?n:n.parse.bind(n);else{const{type:p}=n;i=n.from||s,a=typeof p=="function"?p:p.parse.bind(p)}let c;const u=e(i);try{c=a(u)}catch(p){throw p instanceof W?new H(i,{type:p.type,cause:p}):new H(i,{cause:p})}c!==void 0&&(t[s]=c)}return t}function I(){return new TypeError("Value has unexpected type")}function ie(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw I();return e}class Q{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new W(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function f(r,e){return new Q(t=>{const s=ie(t);return qe(r,n=>s[n])},!1,e)}function L(r,e){return()=>new Q(r,!1,e)}const h=L(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw I()},"string");function Ae(r){return f({eventType:h(),eventData:e=>e}).parse(r)}function dt(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function ft(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=dt;return}s in t||(t[s]={}),t=t[s]})})}function gt(r){ft(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=Ae(e.data);r(t,s)}catch{}})}function wt(){return f({req_id:h(),data:r=>r===null?r:h().optional().parse(r)})}function _t(){return f({req_id:h(),result:r=>r,error:h().optional()})}function bt(){return f({slug:h(),status:h()})}function mt(){return f({status:h()})}function yt(){return f({button_id:r=>r==null?void 0:h().parse(r)})}function Et(){return f({data:h().optional()})}function Z(r){return/^#[\da-f]{6}$/i.test(r)}function Ve(r){return/^#[\da-f]{3}$/i.test(r)}function oe(r){const e=r.replace(/\s/g,"").toLowerCase();if(Z(e))return e;if(Ve(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}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((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}const ae=L(r=>oe(h().parse(r)),"rgb");function Ct(){return f({theme_params:r=>{const e=ae().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}const C=L(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 I()},"boolean"),k=L(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw I()},"number");function vt(){return f({height:k(),width:r=>r==null?window.innerWidth:k().parse(r),is_state_stable:C(),is_expanded:C()})}function Pt(){return f({status:h()})}class w{constructor(){o(this,"listeners",new Map);o(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],a)=>{n(...t),i&&s.splice(a,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,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 St(){const r=new w,e=(t,...s)=>{x.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),gt((t,s)=>{x.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,vt().parse(s));case"theme_changed":return e(t,Ct().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,yt().parse(s));case"set_custom_style":return e(t,h().parse(s));case"qr_text_received":return e(t,Et().parse(s));case"clipboard_text_received":return e(t,wt().parse(s));case"invoice_closed":return e(t,bt().parse(s));case"phone_requested":return e("phone_requested",mt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",_t().parse(s));case"write_access_requested":return e("write_access_requested",Pt().parse(s));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,s)}}catch(n){x.error("Error processing event:",n)}}),r}const X="telegram-mini-apps-cached-emitter";function M(){const r=window;return r[X]===void 0&&(r[X]=St()),r[X]}function A(r,e){M().off(r,e)}function y(r,e){return M().on(r,e),()=>A(r,e)}class U extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,U.prototype)}}function kt(r){return new Promise((e,t)=>{setTimeout(t,r,new U(r))})}function ce(r,e){return Promise.race([typeof r=="function"?r():r,kt(e)])}async function m(r,e,t){let s;const n=new Promise(b=>{s=b}),i=e?{...t,event:e,method:r}:r,{method:a,event:c,capture:u,postEvent:p=d,timeout:g}=i,_=(Array.isArray(c)?c:[c]).map(b=>y(b,l=>(!u||u(l))&&s(l)));try{return p(a,i.params),await(g?ce(n,g):n)}finally{_.forEach(b=>b())}}async function R(r,e,t,s={}){const{result:n,error:i}=await m("web_app_invoke_custom_method","custom_method_invoked",{...s,params:{method:r,params:e,req_id:t},capture:xe(t)});if(i)throw new Error(i);return n}function xt(r,e){return M().once(r,e),()=>A(r,e)}function Re(r){M().unsubscribe(r)}function qt(r){return M().subscribe(r),()=>Re(r)}function j(r,e){return r+(r.length&&e.length?` ${e}`:e)}function he(...r){return r.reduce((e,t)=>typeof t=="string"?j(e,t):T(t)?j(e,Object.entries(t).reduce((s,n)=>n[1]?j(s,n[0]):s,"")):Array.isArray(t)?j(e,he(...t)):e,"")}function At(...r){return r.reduce((e,t)=>(T(t)&&Object.entries(t).forEach(([s,n])=>{const i=he(e[s],n);i.length>0&&(e[s]=i)}),e),{})}function ue(r){const e=oe(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const a=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+a*a*n},0))<120}class E{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}function P(r,e){return t=>q(e[t],r)}class Te{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("back_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("back_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=P(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 Ie{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new E({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}}function Vt(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 I()}class Rt extends Q{constructor(t,s,n){super(Vt,s,n);o(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function Le(r){return new Rt(e=>e,!1,r)}function ye(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class Be{constructor(e,t,s=d){o(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=P(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await R("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await R("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Le().of(h()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return ye(s,"");const n=f(ye(s,h())),i=await R("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(a=>n.parse(a));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await R("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}class $e{constructor(e,t=d){o(this,"supports");this.postEvent=t,this.supports=P(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"})}}function De(){return f({id:k(),type:h(),title:h(),photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"Chat")}class Oe{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function re(){return f({addedToAttachmentMenu:{type:C().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:C().optional(),from:"allows_write_to_pm"},firstName:{type:h(),from:"first_name"},id:k(),isBot:{type:C().optional(),from:"is_bot"},isPremium:{type:C().optional(),from:"is_premium"},languageCode:{type:h().optional(),from:"language_code"},lastName:{type:h().optional(),from:"last_name"},photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"User")}const pe=L(r=>r instanceof Date?r:new Date(k().parse(r)*1e3),"Date");function K(r,e){return new Q(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw I();const s=typeof t=="string"?new URLSearchParams(t):t;return qe(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function le(){return K({authDate:{type:pe(),from:"auth_date"},canSendAfter:{type:k().optional(),from:"can_send_after"},chat:De().optional(),chatInstance:{type:h().optional(),from:"chat_instance"},chatType:{type:h().optional(),from:"chat_type"},hash:h(),queryId:{type:h().optional(),from:"query_id"},receiver:re().optional(),startParam:{type:h().optional(),from:"start_param"},user:re().optional()},"InitData")}function Tt(r){return le().parse(r)}function It(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class Ne{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?It(e):e;this.isOpened=!0;try{return(await m("web_app_open_invoice","invoice_closed",{params:{slug:s},postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}class He{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",(e,t)=>e==="click"?y("main_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u}=e;this.postEvent=t,this.state=new E({backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}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}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}const Lt=K({contact:f({userId:{type:k(),from:"user_id"},phoneNumber:{type:h(),from:"phone_number"},firstName:{type:h(),from:"first_name"},lastName:{type:h().optional(),from:"last_name"}}),authDate:{type:pe(),from:"auth_date"},hash:h()});function We(r,e){return t=>{const[s,n]=e[t];return q(s,n,r)}}function Bt(r){return new Promise(e=>{setTimeout(e,r)})}class Me{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"botInline");o(this,"postEvent");o(this,"createRequestId");o(this,"requestingPhoneAccess",!1);o(this,"requestingWriteAccess",!1);o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");o(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:a,createRequestId:c}=e,u=P(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=a,this.createRequestId=c,this.supports=p=>!(!u(p)||p==="switchInlineQuery"&&!a),this.state=new E({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=We(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return R("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Lt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ue(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ce(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Bt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,m("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,m("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}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",Z(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)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function $t(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;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(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:a=""}=i;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const c=i.text.trim();if(c.length===0||c.length>64){const u=i.type||"default";throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`)}return{...i,text:c,id:a}}return{...i,id:a}}),{title:t,message:e,buttons:n}}class Ue{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,m("web_app_open_popup","popup_closed",{postEvent:this.postEvent,params:$t(e)}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class Ge{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(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 m("web_app_open_scan_qr_popup",["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent,params:{text:e}});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class je{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("settings_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("settings_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=P(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Dt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function Ot(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const de=L(r=>{const e=ae().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[Dt(s)]=e.parse(n),t),{})},"ThemeParams");function fe(r){return de().parse(r)}function Nt(r){return m("web_app_request_theme","theme_changed",r).then(fe)}function Fe(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[Ot(t)]=s),e),{}))}class ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.state=new E(e,this.ee)}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)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ue(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")}listen(){return y("theme_changed",e=>{this.state.set(fe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}class Je{constructor(e,t,s=d){o(this,"supports");o(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=P(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=We(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!q("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!q("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}async readTextFromClipboard(){const e=this.createRequestId(),{data:t=null}=await m("web_app_read_text_from_clipboard","clipboard_text_received",{postEvent:this.postEvent,params:{req_id:e},capture:xe(e)});return t}}function Qe(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function ge(r){const e=await m("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function D(r){return r<0?0:r}class Ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:a=d}=e;this.postEvent=a,this.state=new E({height:D(t),isExpanded:s,stableHeight:D(i),width:D(n)},this.ee)}sync(e){return ge(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return y("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,a={height:D(t),isExpanded:n,width:D(s)};i&&(a.stableHeight=a.height),this.state.set(a)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function v(r,e){document.documentElement.style.setProperty(r,e)}function Ke(r,e){const t=()=>{v("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Z(r.headerColor)){v("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){v("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&v("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Ye(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,a=>`-${a.toLowerCase()}`);v(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function se(r){const e=()=>v("--tg-viewport-height",`${r.height}px`),t=()=>v("--tg-viewport-width",`${r.width}px`),s=()=>v("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}function Ht(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),y("set_custom_style",e=>{r.innerHTML=e})}function Xe(r){return`telegram-mini-apps-${r}`}function B(r,e){sessionStorage.setItem(Xe(r),JSON.stringify(e))}function $(r){const e=sessionStorage.getItem(Xe(r));return e?JSON.parse(e):null}function Wt(r,e,t){const{isVisible:s=!1}=r?$("back-button")||{}:{},n=new Te(s,e,t);return n.on("change",()=>{B("back-button",{isVisible:n.isVisible})}),n}function Mt(r,e){const{isConfirmationNeeded:t=!1}=r?$("closing-behavior")||{}:{},s=new Ie(t,e);return s.on("change",()=>B("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}function Ut(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:a=!1,isLoaderVisible:c=!1,textColor:u=t,text:p=""}=r?$("main-button")||{}:{},g=new He({backgroundColor:n,isEnabled:i,isLoaderVisible:c,isVisible:a,postEvent:s,text:p,textColor:u}),_=()=>B("main-button",{backgroundColor:g.backgroundColor,isEnabled:g.isEnabled,isLoaderVisible:g.isLoaderVisible,isVisible:g.isVisible,text:g.text,textColor:g.textColor});return g.on("change",_),g}function Gt(r,e,t,s,n,i){const{backgroundColor:a=e,headerColor:c="bg_color"}=r?$("mini-app")||{}:{},u=new Me({headerColor:c,backgroundColor:a,version:t,botInline:s,createRequestId:n,postEvent:i}),p=()=>B("mini-app",{backgroundColor:u.backgroundColor,headerColor:u.headerColor});return u.on("change",p),u}function jt(){let r=0;return()=>(r+=1,r.toString())}function Ft(r,e,t){const{isVisible:s=!1}=r?$("settings-button")||{}:{},n=new je(s,e,t);return n.on("change",()=>{B("settings-button",{isVisible:n.isVisible})}),n}function zt(r){const e=new ze(r);return e.listen(),e}function F(r){const e=new Ze(r);return e.on("change",()=>B("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function Jt(r,e,t,s){const n=r?$("viewport"):null;if(n)return F({...n,postEvent:t});if(Qe(e))return F({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return ge({postEvent:t,timeout:5e3}).then(({height:a,isStateStable:c,...u})=>F({...u,height:a,stableHeight:c?a:0}));const i=F({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(a=>{console.error("Unable to actualize viewport state",a)}),i}function Qt(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ee(r,e,t,s){const n=Qt(r);n.miniApp&&Ke(e,t),n.themeParams&&Ye(t),n.viewport&&(s instanceof Promise?s.then(se):se(s))}function et(){return K({botInline:{type:C().optional(),from:"tgWebAppBotInline"},initData:{type:le().optional(),from:"tgWebAppData"},initDataRaw:{type:h().optional(),from:"tgWebAppData"},platform:{type:h(),from:"tgWebAppPlatform"},showSettings:{type:C().optional(),from:"tgWebAppShowSettings"},startParam:{type:h().optional(),from:"tgWebAppStartParam"},themeParams:{type:de(),from:"tgWebAppThemeParams"},version:{type:h(),from:"tgWebAppVersion"}},"LaunchParams")}function we(r){return et().parse(r)}function tt(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return we(e)}function Zt(){return tt(window.location.href)}function rt(){return performance.getEntriesByType("navigation")[0]}function Kt(){const r=rt();if(!r)throw new Error("Unable to get first navigation entry.");return tt(r.name)}function st(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:a,botInline:c}=r,u=new URLSearchParams;return e&&u.set("tgWebAppData",e),u.set("tgWebAppPlatform",s),u.set("tgWebAppThemeParams",Fe(t)),u.set("tgWebAppVersion",n),a&&u.set("tgWebAppStartParam",n),typeof i=="boolean"&&u.set("tgWebAppShowSettings",i?"1":"0"),typeof c=="boolean"&&u.set("tgWebAppBotInline",c?"1":"0"),u.toString()}const nt="telegram-mini-apps-launch-params";function Yt(){return we(sessionStorage.getItem(nt)||"")}function Xt(r){sessionStorage.setItem(nt,st(r))}function Y(){const r=[];for(const e of[Zt,Kt,Yt])try{const t=e();return Xt(t),t}catch(t){r.push(t)}throw x.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function _e(){var r;return((r=rt())==null?void 0:r.type)==="reload"}function er(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:a,version:c,platform:u,themeParams:p,botInline:g=!1}=Y(),_=_e(),b=jt(),l=ke(c);ne()&&(n&&Ht(),l("iframe_ready",{reload_supported:!0}),y("reload_iframe",()=>{l("iframe_will_reload"),window.location.reload()}));const V={backButton:Wt(_,c,l),closingBehavior:Mt(_,l),cloudStorage:new Be(c,b,l),createRequestId:b,hapticFeedback:new $e(c,l),invoice:new Ne(c,l),mainButton:Ut(_,p.buttonColor||"#000000",p.buttonTextColor||"#ffffff",l),miniApp:Gt(_,p.backgroundColor||"#ffffff",c,g,b,l),popup:new Ue(c,l),postEvent:l,qrScanner:new Ge(c,l),settingsButton:Ft(_,c,l),themeParams:zt(p),utils:new Je(c,b,l),...i?{initData:new Oe(i),initDataRaw:a}:{}},G=Jt(_,u,l,t);return G instanceof Promise||t?Promise.resolve(G).then(me=>(Ee(s,V.miniApp,V.themeParams,me),{...V,viewport:me})):(Ee(s,V.miniApp,V.themeParams,G),{...V,viewport:G})}catch(i){if(t)return Promise.reject(i);throw i}}function tr(){return{launchParams:Y(),isPageReload:_e()}}function rr(){try{return Y(),!0}catch{return!1}}function sr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function N(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function nr(){if(window.history.length<=1||(window.history.pushState(null,""),await N(1-window.history.length)))return;let e=await N(-1);for(;e;)e=await N(-1)}function O(r,e){return r.startsWith(e)?r:`${e}${r}`}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){o(this,"logger");o(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:a,hash:c})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:O(i,"/"),search:a?O(a,"?"):"",hash:c?O(c,"#"):""}}),this.logger=new ve(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:a="",search:c,hash:u}=e;t=a+(c?O(c,"?"):"")+(u?O(u,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const Ce=0,ee=1,te=2;class be extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});o(this,"ee",new w);o(this,"attached",!1);o(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===Ce){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===ee)return this.back();if(t===te)return this.forward()});o(this,"back",()=>super.back());o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new be([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await nr(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t),window.history.pushState(te,""),await N(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(te,""),await N(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(Ce,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,y("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),A("back_button_pressed",this.back))}}function ir(r){return r instanceof U}exports.BackButton=Te;exports.ClosingBehavior=Ie;exports.CloudStorage=Be;exports.HapticFeedback=$e;exports.HashNavigator=be;exports.InitData=Oe;exports.Invoice=Ne;exports.MainButton=He;exports.MethodUnsupportedError=z;exports.MiniApp=Me;exports.Navigator=it;exports.ParameterUnsupportedError=J;exports.ParseError=W;exports.ParseSchemaFieldError=H;exports.Popup=Ue;exports.QRScanner=Ge;exports.SettingsButton=je;exports.ThemeParams=ze;exports.TimeoutError=U;exports.Utils=Je;exports.Viewport=Ze;exports.array=Le;exports.bindMiniAppCSSVars=Ke;exports.bindThemeCSSVars=Ye;exports.bindViewportCSSVars=se;exports.boolean=C;exports.chatParser=De;exports.classNames=he;exports.compareVersions=Se;exports.createPostEvent=ke;exports.date=pe;exports.getHash=sr;exports.init=er;exports.initDataParser=le;exports.invokeCustomMethod=R;exports.isColorDark=ue;exports.isIframe=ne;exports.isPageReload=_e;exports.isRGB=Z;exports.isRGBShort=Ve;exports.isRecord=T;exports.isStableViewportPlatform=Qe;exports.isTMA=rr;exports.isTimeoutError=ir;exports.json=f;exports.launchParamsParser=et;exports.mergeClassNames=At;exports.number=k;exports.off=A;exports.on=y;exports.once=xt;exports.parseInitData=Tt;exports.parseLaunchParams=we;exports.parseMessage=Ae;exports.parseThemeParams=fe;exports.postEvent=d;exports.request=m;exports.requestThemeParams=Nt;exports.requestViewport=ge;exports.retrieveLaunchData=tr;exports.retrieveLaunchParams=Y;exports.rgb=ae;exports.searchParams=K;exports.serializeLaunchParams=st;exports.serializeThemeParams=Fe;exports.setCSSVar=v;exports.setDebug=ct;exports.setTargetOrigin=ht;exports.string=h;exports.subscribe=qt;exports.supports=q;exports.themeParamsParser=de;exports.toRGB=oe;exports.unsubscribe=Re;exports.userParser=re;exports.withTimeout=ce;
1
+ "use strict";var ot=Object.defineProperty;var at=(r,e,t)=>e in r?ot(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(at(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class ve{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,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)}}let Pe="https://web.telegram.org";const x=new ve("[SDK]",!1);function ct(r){if(r){x.enable();return}x.disable()}function ht(r){Pe=r}function ut(){return Pe}function ne(){try{return window.self!==window.top}catch{return!0}}function T(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function pt(r){return"external"in r&&T(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function lt(r){return"TelegramWebviewProxy"in r&&T(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=ut()}=s;if(x.log(`Calling method "${r}"`,n),ne()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(pt(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(lt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function Se(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const a=parseInt(t[i]||"0",10),c=parseInt(s[i]||"0",10);if(a!==c)return a>c?1:-1}return 0}function S(r,e){return Se(r,e)<=0}function q(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return S("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return S("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 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_switch_inline_query":return S("6.7",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}}class z extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,z.prototype)}}class J extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,J.prototype)}}function ke(r){return(e,t)=>{if(!q(e,r))throw new z(e,r);if(T(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!q(e,s,r))throw new J(e,s,r)}return d(e,t)}}function xe(r){return({req_id:e})=>e===r}class W extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});o(this,"type");this.value=t,Object.setPrototypeOf(this,W.prototype),this.type=n}}class H extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,H.prototype)}}function qe(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,a;if(typeof n=="function"||"parse"in n)i=s,a=typeof n=="function"?n:n.parse.bind(n);else{const{type:p}=n;i=n.from||s,a=typeof p=="function"?p:p.parse.bind(p)}let c;const u=e(i);try{c=a(u)}catch(p){throw p instanceof W?new H(i,{type:p.type,cause:p}):new H(i,{cause:p})}c!==void 0&&(t[s]=c)}return t}function I(){return new TypeError("Value has unexpected type")}function ie(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw I();return e}class Q{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new W(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function f(r,e){return new Q(t=>{const s=ie(t);return qe(r,n=>s[n])},!1,e)}function L(r,e){return()=>new Q(r,!1,e)}const h=L(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw I()},"string");function Ae(r){return f({eventType:h(),eventData:e=>e}).parse(r)}function dt(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function ft(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=dt;return}s in t||(t[s]={}),t=t[s]})})}function gt(r){ft(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=Ae(e.data);r(t,s)}catch{}})}function wt(){return f({req_id:h(),data:r=>r===null?r:h().optional().parse(r)})}function _t(){return f({req_id:h(),result:r=>r,error:h().optional()})}function bt(){return f({slug:h(),status:h()})}function mt(){return f({status:h()})}function yt(){return f({button_id:r=>r==null?void 0:h().parse(r)})}function Et(){return f({data:h().optional()})}function Z(r){return/^#[\da-f]{6}$/i.test(r)}function Ve(r){return/^#[\da-f]{3}$/i.test(r)}function oe(r){const e=r.replace(/\s/g,"").toLowerCase();if(Z(e))return e;if(Ve(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}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((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}const ae=L(r=>oe(h().parse(r)),"rgb");function Ct(){return f({theme_params:r=>{const e=ae().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}const C=L(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 I()},"boolean"),k=L(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw I()},"number");function vt(){return f({height:k(),width:r=>r==null?window.innerWidth:k().parse(r),is_state_stable:C(),is_expanded:C()})}function Pt(){return f({status:h()})}class w{constructor(){o(this,"listeners",new Map);o(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],a)=>{n(...t),i&&s.splice(a,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,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 St(){const r=new w,e=(t,...s)=>{x.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),gt((t,s)=>{x.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,vt().parse(s));case"theme_changed":return e(t,Ct().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,yt().parse(s));case"set_custom_style":return e(t,h().parse(s));case"qr_text_received":return e(t,Et().parse(s));case"clipboard_text_received":return e(t,wt().parse(s));case"invoice_closed":return e(t,bt().parse(s));case"phone_requested":return e("phone_requested",mt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",_t().parse(s));case"write_access_requested":return e("write_access_requested",Pt().parse(s));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,s)}}catch(n){x.error("Error processing event:",n)}}),r}const X="telegram-mini-apps-cached-emitter";function M(){const r=window;return r[X]===void 0&&(r[X]=St()),r[X]}function A(r,e){M().off(r,e)}function y(r,e){return M().on(r,e),()=>A(r,e)}class U extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,U.prototype)}}function kt(r){return new Promise((e,t)=>{setTimeout(t,r,new U(r))})}function ce(r,e){return Promise.race([typeof r=="function"?r():r,kt(e)])}async function m(r,e,t){let s;const n=new Promise(b=>{s=b}),i=e?{...t,event:e,method:r}:r,{method:a,event:c,capture:u,postEvent:p=d,timeout:g}=i,_=(Array.isArray(c)?c:[c]).map(b=>y(b,l=>(!u||u(l))&&s(l)));try{return p(a,i.params),await(g?ce(n,g):n)}finally{_.forEach(b=>b())}}async function R(r,e,t,s={}){const{result:n,error:i}=await m("web_app_invoke_custom_method","custom_method_invoked",{...s,params:{method:r,params:e,req_id:t},capture:xe(t)});if(i)throw new Error(i);return n}function xt(r,e){return M().once(r,e),()=>A(r,e)}function Re(r){M().unsubscribe(r)}function qt(r){return M().subscribe(r),()=>Re(r)}function j(r,e){return r+(r.length&&e.length?` ${e}`:e)}function he(...r){return r.reduce((e,t)=>typeof t=="string"?j(e,t):T(t)?j(e,Object.entries(t).reduce((s,n)=>n[1]?j(s,n[0]):s,"")):Array.isArray(t)?j(e,he(...t)):e,"")}function At(...r){return r.reduce((e,t)=>(T(t)&&Object.entries(t).forEach(([s,n])=>{const i=he(e[s],n);i.length>0&&(e[s]=i)}),e),{})}function ue(r){const e=oe(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const a=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+a*a*n},0))<120}class E{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}function P(r,e){return t=>q(e[t],r)}class Te{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("back_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("back_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=P(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 Ie{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new E({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}}function Vt(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 I()}class Rt extends Q{constructor(t,s,n){super(Vt,s,n);o(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function Le(r){return new Rt(e=>e,!1,r)}function ye(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class Be{constructor(e,t,s=d){o(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=P(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await R("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await R("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Le().of(h()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return ye(s,"");const n=f(ye(s,h())),i=await R("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(a=>n.parse(a));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await R("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}class $e{constructor(e,t=d){o(this,"supports");this.postEvent=t,this.supports=P(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"})}}function De(){return f({id:k(),type:h(),title:h(),photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"Chat")}class Oe{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function re(){return f({addedToAttachmentMenu:{type:C().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:C().optional(),from:"allows_write_to_pm"},firstName:{type:h(),from:"first_name"},id:k(),isBot:{type:C().optional(),from:"is_bot"},isPremium:{type:C().optional(),from:"is_premium"},languageCode:{type:h().optional(),from:"language_code"},lastName:{type:h().optional(),from:"last_name"},photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"User")}const pe=L(r=>r instanceof Date?r:new Date(k().parse(r)*1e3),"Date");function K(r,e){return new Q(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw I();const s=typeof t=="string"?new URLSearchParams(t):t;return qe(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function le(){return K({authDate:{type:pe(),from:"auth_date"},canSendAfter:{type:k().optional(),from:"can_send_after"},chat:De().optional(),chatInstance:{type:h().optional(),from:"chat_instance"},chatType:{type:h().optional(),from:"chat_type"},hash:h(),queryId:{type:h().optional(),from:"query_id"},receiver:re().optional(),startParam:{type:h().optional(),from:"start_param"},user:re().optional()},"InitData")}function Tt(r){return le().parse(r)}function It(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class Ne{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?It(e):e;this.isOpened=!0;try{return(await m("web_app_open_invoice","invoice_closed",{params:{slug:s},postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}class He{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",(e,t)=>e==="click"?y("main_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u}=e;this.postEvent=t,this.state=new E({backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}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}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}const Lt=K({contact:f({userId:{type:k(),from:"user_id"},phoneNumber:{type:h(),from:"phone_number"},firstName:{type:h(),from:"first_name"},lastName:{type:h().optional(),from:"last_name"}}),authDate:{type:pe(),from:"auth_date"},hash:h()});function We(r,e){return t=>{const[s,n]=e[t];return q(s,n,r)}}function Bt(r){return new Promise(e=>{setTimeout(e,r)})}class Me{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"botInline");o(this,"postEvent");o(this,"createRequestId");o(this,"requestingPhoneAccess",!1);o(this,"requestingWriteAccess",!1);o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");o(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:a,createRequestId:c}=e,u=P(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=a,this.createRequestId=c,this.supports=p=>!(!u(p)||p==="switchInlineQuery"&&!a),this.state=new E({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=We(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return R("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Lt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ue(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ce(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Bt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,m("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,m("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}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",Z(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)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function $t(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;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(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:a=""}=i;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const c=i.text.trim();if(c.length===0||c.length>64){const u=i.type||"default";throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`)}return{...i,text:c,id:a}}return{...i,id:a}}),{title:t,message:e,buttons:n}}class Ue{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,m("web_app_open_popup","popup_closed",{postEvent:this.postEvent,params:$t(e)}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class Ge{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new E({isOpened:!1},this.ee),this.supports=P(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 m("web_app_open_scan_qr_popup",["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent,params:{text:e}});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class je{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("settings_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?A("settings_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=P(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Dt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function Ot(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const de=L(r=>{const e=ae().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[Dt(s)]=e.parse(n),t),{})},"ThemeParams");function fe(r){return de().parse(r)}function Nt(r){return m("web_app_request_theme","theme_changed",r).then(fe)}function Fe(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[Ot(t)]=s),e),{}))}class ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.state=new E(e,this.ee)}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)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ue(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")}listen(){return y("theme_changed",e=>{this.state.set(fe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}class Je{constructor(e,t,s=d){o(this,"supports");o(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=P(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=We(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!q("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!q("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}async readTextFromClipboard(){const e=this.createRequestId(),{data:t=null}=await m("web_app_read_text_from_clipboard","clipboard_text_received",{postEvent:this.postEvent,params:{req_id:e},capture:xe(e)});return t}}function Qe(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function ge(r){const e=await m("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function D(r){return r<0?0:r}class Ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:a=d}=e;this.postEvent=a,this.state=new E({height:D(t),isExpanded:s,stableHeight:D(i),width:D(n)},this.ee)}sync(e){return ge(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return y("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,a={height:D(t),isExpanded:n,width:D(s)};i&&(a.stableHeight=a.height),this.state.set(a)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function v(r,e){document.documentElement.style.setProperty(r,e)}function Ke(r,e){const t=()=>{v("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Z(r.headerColor)){v("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){v("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&v("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Ye(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,a=>`-${a.toLowerCase()}`);v(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function se(r){const e=()=>v("--tg-viewport-height",`${r.height}px`),t=()=>v("--tg-viewport-width",`${r.width}px`),s=()=>v("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}function Ht(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),y("set_custom_style",e=>{r.innerHTML=e})}function Xe(r){return`telegram-mini-apps-${r}`}function B(r,e){sessionStorage.setItem(Xe(r),JSON.stringify(e))}function $(r){const e=sessionStorage.getItem(Xe(r));return e?JSON.parse(e):null}function Wt(r,e,t){const{isVisible:s=!1}=r?$("back-button")||{}:{},n=new Te(s,e,t);return n.on("change",()=>{B("back-button",{isVisible:n.isVisible})}),n}function Mt(r,e){const{isConfirmationNeeded:t=!1}=r?$("closing-behavior")||{}:{},s=new Ie(t,e);return s.on("change",()=>B("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}function Ut(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:a=!1,isLoaderVisible:c=!1,textColor:u=t,text:p=""}=r?$("main-button")||{}:{},g=new He({backgroundColor:n,isEnabled:i,isLoaderVisible:c,isVisible:a,postEvent:s,text:p,textColor:u}),_=()=>B("main-button",{backgroundColor:g.backgroundColor,isEnabled:g.isEnabled,isLoaderVisible:g.isLoaderVisible,isVisible:g.isVisible,text:g.text,textColor:g.textColor});return g.on("change",_),g}function Gt(r,e,t,s,n,i){const{backgroundColor:a=e,headerColor:c="bg_color"}=r?$("mini-app")||{}:{},u=new Me({headerColor:c,backgroundColor:a,version:t,botInline:s,createRequestId:n,postEvent:i}),p=()=>B("mini-app",{backgroundColor:u.backgroundColor,headerColor:u.headerColor});return u.on("change",p),u}function jt(){let r=0;return()=>(r+=1,r.toString())}function Ft(r,e,t){const{isVisible:s=!1}=r?$("settings-button")||{}:{},n=new je(s,e,t);return n.on("change",()=>{B("settings-button",{isVisible:n.isVisible})}),n}function zt(r){const e=new ze(r);return e.listen(),e}function F(r){const e=new Ze(r);return e.on("change",()=>B("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function Jt(r,e,t,s){const n=r?$("viewport"):null;if(n)return F({...n,postEvent:t});if(Qe(e))return F({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return ge({postEvent:t,timeout:5e3}).then(({height:a,isStateStable:c,...u})=>F({...u,height:a,stableHeight:c?a:0}));const i=F({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(a=>{console.error("Unable to actualize viewport state",a)}),i}function Qt(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ee(r,e,t,s){const n=Qt(r);n.miniApp&&Ke(e,t),n.themeParams&&Ye(t),n.viewport&&(s instanceof Promise?s.then(se):se(s))}function et(){return K({botInline:{type:C().optional(),from:"tgWebAppBotInline"},initData:{type:le().optional(),from:"tgWebAppData"},initDataRaw:{type:h().optional(),from:"tgWebAppData"},platform:{type:h(),from:"tgWebAppPlatform"},showSettings:{type:C().optional(),from:"tgWebAppShowSettings"},startParam:{type:h().optional(),from:"tgWebAppStartParam"},themeParams:{type:de(),from:"tgWebAppThemeParams"},version:{type:h(),from:"tgWebAppVersion"}},"LaunchParams")}function we(r){return et().parse(r)}function tt(r){return we(r.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function Zt(){return tt(window.location.href)}function rt(){return performance.getEntriesByType("navigation")[0]}function Kt(){const r=rt();if(!r)throw new Error("Unable to get first navigation entry.");return tt(r.name)}function st(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:a,botInline:c}=r,u=new URLSearchParams;return e&&u.set("tgWebAppData",e),u.set("tgWebAppPlatform",s),u.set("tgWebAppThemeParams",Fe(t)),u.set("tgWebAppVersion",n),a&&u.set("tgWebAppStartParam",a),typeof i=="boolean"&&u.set("tgWebAppShowSettings",i?"1":"0"),typeof c=="boolean"&&u.set("tgWebAppBotInline",c?"1":"0"),u.toString()}const nt="telegram-mini-apps-launch-params";function Yt(){return we(sessionStorage.getItem(nt)||"")}function Xt(r){sessionStorage.setItem(nt,st(r))}function Y(){const r=[];for(const e of[Zt,Kt,Yt])try{const t=e();return Xt(t),t}catch(t){r.push(t)}throw x.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function _e(){var r;return((r=rt())==null?void 0:r.type)==="reload"}function er(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:a,version:c,platform:u,themeParams:p,botInline:g=!1}=Y(),_=_e(),b=jt(),l=ke(c);ne()&&(n&&Ht(),l("iframe_ready",{reload_supported:!0}),y("reload_iframe",()=>{l("iframe_will_reload"),window.location.reload()}));const V={backButton:Wt(_,c,l),closingBehavior:Mt(_,l),cloudStorage:new Be(c,b,l),createRequestId:b,hapticFeedback:new $e(c,l),invoice:new Ne(c,l),mainButton:Ut(_,p.buttonColor||"#000000",p.buttonTextColor||"#ffffff",l),miniApp:Gt(_,p.backgroundColor||"#ffffff",c,g,b,l),popup:new Ue(c,l),postEvent:l,qrScanner:new Ge(c,l),settingsButton:Ft(_,c,l),themeParams:zt(p),utils:new Je(c,b,l),...i?{initData:new Oe(i),initDataRaw:a}:{}},G=Jt(_,u,l,t);return G instanceof Promise||t?Promise.resolve(G).then(me=>(Ee(s,V.miniApp,V.themeParams,me),{...V,viewport:me})):(Ee(s,V.miniApp,V.themeParams,G),{...V,viewport:G})}catch(i){if(t)return Promise.reject(i);throw i}}function tr(){return{launchParams:Y(),isPageReload:_e()}}function rr(){try{return Y(),!0}catch{return!1}}function sr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function N(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function nr(){if(window.history.length<=1||(window.history.pushState(null,""),await N(1-window.history.length)))return;let e=await N(-1);for(;e;)e=await N(-1)}function O(r,e){return r.startsWith(e)?r:`${e}${r}`}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){o(this,"logger");o(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:a,hash:c})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:O(i,"/"),search:a?O(a,"?"):"",hash:c?O(c,"#"):""}}),this.logger=new ve(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:a="",search:c,hash:u}=e;t=a+(c?O(c,"?"):"")+(u?O(u,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const Ce=0,ee=1,te=2;class be extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});o(this,"ee",new w);o(this,"attached",!1);o(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===Ce){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===ee)return this.back();if(t===te)return this.forward()});o(this,"back",()=>super.back());o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new be([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await nr(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t),window.history.pushState(te,""),await N(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(te,""),await N(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(Ce,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,y("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),A("back_button_pressed",this.back))}}function ir(r){return r instanceof U}exports.BackButton=Te;exports.ClosingBehavior=Ie;exports.CloudStorage=Be;exports.HapticFeedback=$e;exports.HashNavigator=be;exports.InitData=Oe;exports.Invoice=Ne;exports.MainButton=He;exports.MethodUnsupportedError=z;exports.MiniApp=Me;exports.Navigator=it;exports.ParameterUnsupportedError=J;exports.ParseError=W;exports.ParseSchemaFieldError=H;exports.Popup=Ue;exports.QRScanner=Ge;exports.SettingsButton=je;exports.ThemeParams=ze;exports.TimeoutError=U;exports.Utils=Je;exports.Viewport=Ze;exports.array=Le;exports.bindMiniAppCSSVars=Ke;exports.bindThemeCSSVars=Ye;exports.bindViewportCSSVars=se;exports.boolean=C;exports.chatParser=De;exports.classNames=he;exports.compareVersions=Se;exports.createPostEvent=ke;exports.date=pe;exports.getHash=sr;exports.init=er;exports.initDataParser=le;exports.invokeCustomMethod=R;exports.isColorDark=ue;exports.isIframe=ne;exports.isPageReload=_e;exports.isRGB=Z;exports.isRGBShort=Ve;exports.isRecord=T;exports.isStableViewportPlatform=Qe;exports.isTMA=rr;exports.isTimeoutError=ir;exports.json=f;exports.launchParamsParser=et;exports.mergeClassNames=At;exports.number=k;exports.off=A;exports.on=y;exports.once=xt;exports.parseInitData=Tt;exports.parseLaunchParams=we;exports.parseMessage=Ae;exports.parseThemeParams=fe;exports.postEvent=d;exports.request=m;exports.requestThemeParams=Nt;exports.requestViewport=ge;exports.retrieveLaunchData=tr;exports.retrieveLaunchParams=Y;exports.rgb=ae;exports.searchParams=K;exports.serializeLaunchParams=st;exports.serializeThemeParams=Fe;exports.setCSSVar=v;exports.setDebug=ct;exports.setTargetOrigin=ht;exports.string=h;exports.subscribe=qt;exports.supports=q;exports.themeParamsParser=de;exports.toRGB=oe;exports.unsubscribe=Re;exports.userParser=re;exports.withTimeout=ce;
@@ -1 +1 @@
1
- var ir=Object.defineProperty;var or=(o,b,q)=>b in o?ir(o,b,{enumerable:!0,configurable:!0,writable:!0,value:q}):o[b]=q;var a=(o,b,q)=>(or(o,typeof b!="symbol"?b+"":b,q),q);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(o){"use strict";class b{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,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)}}let q="https://web.telegram.org";const R=new b("[SDK]",!1);function at(r){if(r){R.enable();return}R.disable()}function ct(r){q=r}function ht(){return q}function re(){try{return window.self!==window.top}catch{return!0}}function L(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function ut(r){return"external"in r&&L(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function pt(r){return"TelegramWebviewProxy"in r&&L(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function f(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=ht()}=s;if(R.log(`Calling method "${r}"`,n),re()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(ut(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(pt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function Ce(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const c=parseInt(t[i]||"0",10),h=parseInt(s[i]||"0",10);if(c!==h)return c>h?1:-1}return 0}function A(r,e){return Ce(r,e)<=0}function T(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return A("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return A("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 A("6.1",e);case"web_app_open_popup":return A("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 A("6.4",e);case"web_app_switch_inline_query":return A("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return A("6.9",e);case"web_app_setup_settings_button":return A("6.10",e);default:return!0}}class z extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,z.prototype)}}class J extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,J.prototype)}}function ve(r){return(e,t)=>{if(!T(e,r))throw new z(e,r);if(L(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!T(e,s,r))throw new J(e,s,r)}return f(e,t)}}function Pe(r){return({req_id:e})=>e===r}class W extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});a(this,"type");this.value=t,Object.setPrototypeOf(this,W.prototype),this.type=n}}class M extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,M.prototype)}}function Se(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,c;if(typeof n=="function"||"parse"in n)i=s,c=typeof n=="function"?n:n.parse.bind(n);else{const{type:l}=n;i=n.from||s,c=typeof l=="function"?l:l.parse.bind(l)}let h;const p=e(i);try{h=c(p)}catch(l){throw l instanceof W?new M(i,{type:l.type,cause:l}):new M(i,{cause:l})}h!==void 0&&(t[s]=h)}return t}function B(){return new TypeError("Value has unexpected type")}function se(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw B();return e}class Q{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new W(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function g(r,e){return new Q(t=>{const s=se(t);return Se(r,n=>s[n])},!1,e)}function $(r,e){return()=>new Q(r,!1,e)}const u=$(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw B()},"string");function ke(r){return g({eventType:u(),eventData:e=>e}).parse(r)}function lt(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function dt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=lt;return}s in t||(t[s]={}),t=t[s]})})}function ft(r){dt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=ke(e.data);r(t,s)}catch{}})}function gt(){return g({req_id:u(),data:r=>r===null?r:u().optional().parse(r)})}function wt(){return g({req_id:u(),result:r=>r,error:u().optional()})}function _t(){return g({slug:u(),status:u()})}function bt(){return g({status:u()})}function mt(){return g({button_id:r=>r==null?void 0:u().parse(r)})}function yt(){return g({data:u().optional()})}function Z(r){return/^#[\da-f]{6}$/i.test(r)}function qe(r){return/^#[\da-f]{3}$/i.test(r)}function ne(r){const e=r.replace(/\s/g,"").toLowerCase();if(Z(e))return e;if(qe(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}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((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}const ie=$(r=>ne(u().parse(r)),"rgb");function Et(){return g({theme_params:r=>{const e=ie().optional();return Object.entries(se(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}const P=$(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 B()},"boolean"),V=$(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw B()},"number");function Ct(){return g({height:V(),width:r=>r==null?window.innerWidth:V().parse(r),is_state_stable:P(),is_expanded:P()})}function vt(){return g({status:u()})}class _{constructor(){a(this,"listeners",new Map);a(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],c)=>{n(...t),i&&s.splice(c,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,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 Pt(){const r=new _,e=(t,...s)=>{R.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),ft((t,s)=>{R.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,Ct().parse(s));case"theme_changed":return e(t,Et().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,mt().parse(s));case"set_custom_style":return e(t,u().parse(s));case"qr_text_received":return e(t,yt().parse(s));case"clipboard_text_received":return e(t,gt().parse(s));case"invoice_closed":return e(t,_t().parse(s));case"phone_requested":return e("phone_requested",bt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",wt().parse(s));case"write_access_requested":return e("write_access_requested",vt().parse(s));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,s)}}catch(n){R.error("Error processing event:",n)}}),r}const oe="telegram-mini-apps-cached-emitter";function U(){const r=window;return r[oe]===void 0&&(r[oe]=Pt()),r[oe]}function I(r,e){U().off(r,e)}function m(r,e){return U().on(r,e),()=>I(r,e)}class x extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,x.prototype)}}function St(r){return new Promise((e,t)=>{setTimeout(t,r,new x(r))})}function ae(r,e){return Promise.race([typeof r=="function"?r():r,St(e)])}async function y(r,e,t){let s;const n=new Promise(v=>{s=v}),i=e?{...t,event:e,method:r}:r,{method:c,event:h,capture:p,postEvent:l=f,timeout:w}=i,C=(Array.isArray(h)?h:[h]).map(v=>m(v,d=>(!p||p(d))&&s(d)));try{return l(c,i.params),await(w?ae(n,w):n)}finally{C.forEach(v=>v())}}async function D(r,e,t,s={}){const{result:n,error:i}=await y("web_app_invoke_custom_method","custom_method_invoked",{...s,params:{method:r,params:e,req_id:t},capture:Pe(t)});if(i)throw new Error(i);return n}function kt(r,e){return U().once(r,e),()=>I(r,e)}function Ae(r){U().unsubscribe(r)}function qt(r){return U().subscribe(r),()=>Ae(r)}function K(r,e){return r+(r.length&&e.length?` ${e}`:e)}function ce(...r){return r.reduce((e,t)=>typeof t=="string"?K(e,t):L(t)?K(e,Object.entries(t).reduce((s,n)=>n[1]?K(s,n[0]):s,"")):Array.isArray(t)?K(e,ce(...t)):e,"")}function At(...r){return r.reduce((e,t)=>(L(t)&&Object.entries(t).forEach(([s,n])=>{const i=ce(e[s],n);i.length>0&&(e[s]=i)}),e),{})}function he(r){const e=ne(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const c=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+c*c*n},0))<120}class E{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}function S(r,e){return t=>T(e[t],r)}class Ve{constructor(e,t,s=f){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?m("back_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("back_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=S(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 Re{constructor(e,t=f){a(this,"ee",new _);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 E({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}}function Vt(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 B()}class Rt extends Q{constructor(t,s,n){super(Vt,s,n);a(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function Te(r){return new Rt(e=>e,!1,r)}function Ie(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class Le{constructor(e,t,s=f){a(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=S(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await D("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await D("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Te().of(u()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return Ie(s,"");const n=g(Ie(s,u())),i=await D("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(c=>n.parse(c));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await D("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}class Be{constructor(e,t=f){a(this,"supports");this.postEvent=t,this.supports=S(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"})}}function $e(){return g({id:V(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat")}class De{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function ue(){return g({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:V(),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()},"User")}const pe=$(r=>r instanceof Date?r:new Date(V().parse(r)*1e3),"Date");function Y(r,e){return new Q(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw B();const s=typeof t=="string"?new URLSearchParams(t):t;return Se(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function le(){return Y({authDate:{type:pe(),from:"auth_date"},canSendAfter:{type:V().optional(),from:"can_send_after"},chat:$e().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:ue().optional(),startParam:{type:u().optional(),from:"start_param"},user:ue().optional()},"InitData")}function Tt(r){return le().parse(r)}function It(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class Oe{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?It(e):e;this.isOpened=!0;try{return(await y("web_app_open_invoice","invoice_closed",{params:{slug:s},postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}class Ne{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",(e,t)=>e==="click"?m("main_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=f,text:s,textColor:n,backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p}=e;this.postEvent=t,this.state=new E({backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}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}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}const Lt=Y({contact:g({userId:{type:V(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:pe(),from:"auth_date"},hash:u()});function He(r,e){return t=>{const[s,n]=e[t];return T(s,n,r)}}function Bt(r){return new Promise(e=>{setTimeout(e,r)})}class We{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"botInline");a(this,"postEvent");a(this,"createRequestId");a(this,"requestingPhoneAccess",!1);a(this,"requestingWriteAccess",!1);a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");a(this,"supportsParam");const{postEvent:t=f,headerColor:s,backgroundColor:n,version:i,botInline:c,createRequestId:h}=e,p=S(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=c,this.createRequestId=h,this.supports=l=>!(!p(l)||l==="switchInlineQuery"&&!c),this.state=new E({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=He(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return D("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Lt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return he(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ae(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Bt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,y("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,y("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}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",Z(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)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function $t(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;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(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:c=""}=i;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const h=i.text.trim();if(h.length===0||h.length>64){const p=i.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${i.text.length}`)}return{...i,text:h,id:c}}return{...i,id:c}}),{title:t,message:e,buttons:n}}class Me{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,y("web_app_open_popup","popup_closed",{postEvent:this.postEvent,params:$t(e)}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class Ue{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(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",["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent,params:{text:e}});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class xe{constructor(e,t,s=f){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?m("settings_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("settings_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=S(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Dt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function Ot(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const de=$(r=>{const e=ie().optional();return Object.entries(se(r)).reduce((t,[s,n])=>(t[Dt(s)]=e.parse(n),t),{})},"ThemeParams");function fe(r){return de().parse(r)}function Nt(r){return y("web_app_request_theme","theme_changed",r).then(fe)}function Ge(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[Ot(t)]=s),e),{}))}class je{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.state=new E(e,this.ee)}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)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||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")}listen(){return m("theme_changed",e=>{this.state.set(fe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}class Fe{constructor(e,t,s=f){a(this,"supports");a(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=S(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=He(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!T("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);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}this.postEvent("web_app_open_tg_link",{path_full:s+n})}async readTextFromClipboard(){const e=this.createRequestId(),{data:t=null}=await y("web_app_read_text_from_clipboard","clipboard_text_received",{postEvent:this.postEvent,params:{req_id:e},capture:Pe(e)});return t}}function ze(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function ge(r){const e=await y("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function G(r){return r<0?0:r}class Je{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:c=f}=e;this.postEvent=c,this.state=new E({height:G(t),isExpanded:s,stableHeight:G(i),width:G(n)},this.ee)}sync(e){return ge(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return m("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,c={height:G(t),isExpanded:n,width:G(s)};i&&(c.stableHeight=c.height),this.state.set(c)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function k(r,e){document.documentElement.style.setProperty(r,e)}function Qe(r,e){const t=()=>{k("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Z(r.headerColor)){k("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){k("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&k("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Ze(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);k(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function we(r){const e=()=>k("--tg-viewport-height",`${r.height}px`),t=()=>k("--tg-viewport-width",`${r.width}px`),s=()=>k("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}function Ht(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),m("set_custom_style",e=>{r.innerHTML=e})}function Ke(r){return`telegram-mini-apps-${r}`}function O(r,e){sessionStorage.setItem(Ke(r),JSON.stringify(e))}function N(r){const e=sessionStorage.getItem(Ke(r));return e?JSON.parse(e):null}function Wt(r,e,t){const{isVisible:s=!1}=r?N("back-button")||{}:{},n=new Ve(s,e,t);return n.on("change",()=>{O("back-button",{isVisible:n.isVisible})}),n}function Mt(r,e){const{isConfirmationNeeded:t=!1}=r?N("closing-behavior")||{}:{},s=new Re(t,e);return s.on("change",()=>O("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}function Ut(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:c=!1,isLoaderVisible:h=!1,textColor:p=t,text:l=""}=r?N("main-button")||{}:{},w=new Ne({backgroundColor:n,isEnabled:i,isLoaderVisible:h,isVisible:c,postEvent:s,text:l,textColor:p}),C=()=>O("main-button",{backgroundColor:w.backgroundColor,isEnabled:w.isEnabled,isLoaderVisible:w.isLoaderVisible,isVisible:w.isVisible,text:w.text,textColor:w.textColor});return w.on("change",C),w}function xt(r,e,t,s,n,i){const{backgroundColor:c=e,headerColor:h="bg_color"}=r?N("mini-app")||{}:{},p=new We({headerColor:h,backgroundColor:c,version:t,botInline:s,createRequestId:n,postEvent:i}),l=()=>O("mini-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("change",l),p}function Gt(){let r=0;return()=>(r+=1,r.toString())}function jt(r,e,t){const{isVisible:s=!1}=r?N("settings-button")||{}:{},n=new xe(s,e,t);return n.on("change",()=>{O("settings-button",{isVisible:n.isVisible})}),n}function Ft(r){const e=new je(r);return e.listen(),e}function X(r){const e=new Je(r);return e.on("change",()=>O("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function zt(r,e,t,s){const n=r?N("viewport"):null;if(n)return X({...n,postEvent:t});if(ze(e))return X({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return ge({postEvent:t,timeout:5e3}).then(({height:c,isStateStable:h,...p})=>X({...p,height:c,stableHeight:h?c:0}));const i=X({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(c=>{console.error("Unable to actualize viewport state",c)}),i}function Jt(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ye(r,e,t,s){const n=Jt(r);n.miniApp&&Qe(e,t),n.themeParams&&Ze(t),n.viewport&&(s instanceof Promise?s.then(we):we(s))}function Xe(){return Y({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:le().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:de(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}},"LaunchParams")}function _e(r){return Xe().parse(r)}function et(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return _e(e)}function Qt(){return et(window.location.href)}function tt(){return performance.getEntriesByType("navigation")[0]}function Zt(){const r=tt();if(!r)throw new Error("Unable to get first navigation entry.");return et(r.name)}function rt(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:c,botInline:h}=r,p=new URLSearchParams;return e&&p.set("tgWebAppData",e),p.set("tgWebAppPlatform",s),p.set("tgWebAppThemeParams",Ge(t)),p.set("tgWebAppVersion",n),c&&p.set("tgWebAppStartParam",n),typeof i=="boolean"&&p.set("tgWebAppShowSettings",i?"1":"0"),typeof h=="boolean"&&p.set("tgWebAppBotInline",h?"1":"0"),p.toString()}const st="telegram-mini-apps-launch-params";function Kt(){return _e(sessionStorage.getItem(st)||"")}function Yt(r){sessionStorage.setItem(st,rt(r))}function ee(){const r=[];for(const e of[Qt,Zt,Kt])try{const t=e();return Yt(t),t}catch(t){r.push(t)}throw R.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function be(){var r;return((r=tt())==null?void 0:r.type)==="reload"}function Xt(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:c,version:h,platform:p,themeParams:l,botInline:w=!1}=ee(),C=be(),v=Gt(),d=ve(h);re()&&(n&&Ht(),d("iframe_ready",{reload_supported:!0}),m("reload_iframe",()=>{d("iframe_will_reload"),window.location.reload()}));const H={backButton:Wt(C,h,d),closingBehavior:Mt(C,d),cloudStorage:new Le(h,v,d),createRequestId:v,hapticFeedback:new Be(h,d),invoice:new Oe(h,d),mainButton:Ut(C,l.buttonColor||"#000000",l.buttonTextColor||"#ffffff",d),miniApp:xt(C,l.backgroundColor||"#ffffff",h,w,v,d),popup:new Me(h,d),postEvent:d,qrScanner:new Ue(h,d),settingsButton:jt(C,h,d),themeParams:Ft(l),utils:new Fe(h,v,d),...i?{initData:new De(i),initDataRaw:c}:{}},te=zt(C,p,d,t);return te instanceof Promise||t?Promise.resolve(te).then(ot=>(Ye(s,H.miniApp,H.themeParams,ot),{...H,viewport:ot})):(Ye(s,H.miniApp,H.themeParams,te),{...H,viewport:te})}catch(i){if(t)return Promise.reject(i);throw i}}function er(){return{launchParams:ee(),isPageReload:be()}}function tr(){try{return ee(),!0}catch{return!1}}function rr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function j(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function sr(){if(window.history.length<=1||(window.history.pushState(null,""),await j(1-window.history.length)))return;let e=await j(-1);for(;e;)e=await j(-1)}function F(r,e){return r.startsWith(e)?r:`${e}${r}`}class nt{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){a(this,"logger");a(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:c,hash:h})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:F(i,"/"),search:c?F(c,"?"):"",hash:h?F(h,"#"):""}}),this.logger=new b(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:c="",search:h,hash:p}=e;t=c+(h?F(h,"?"):"")+(p?F(p,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const it=0,me=1,ye=2;class Ee extends nt{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});a(this,"ee",new _);a(this,"attached",!1);a(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===it){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===me)return this.back();if(t===ye)return this.forward()});a(this,"back",()=>super.back());a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new Ee([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await sr(),f("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(me,""),window.history.pushState(null,"",t),window.history.pushState(ye,""),await j(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(me,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(ye,""),await j(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(it,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,m("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),I("back_button_pressed",this.back))}}function nr(r){return r instanceof x}return o.BackButton=Ve,o.ClosingBehavior=Re,o.CloudStorage=Le,o.HapticFeedback=Be,o.HashNavigator=Ee,o.InitData=De,o.Invoice=Oe,o.MainButton=Ne,o.MethodUnsupportedError=z,o.MiniApp=We,o.Navigator=nt,o.ParameterUnsupportedError=J,o.ParseError=W,o.ParseSchemaFieldError=M,o.Popup=Me,o.QRScanner=Ue,o.SettingsButton=xe,o.ThemeParams=je,o.TimeoutError=x,o.Utils=Fe,o.Viewport=Je,o.array=Te,o.bindMiniAppCSSVars=Qe,o.bindThemeCSSVars=Ze,o.bindViewportCSSVars=we,o.boolean=P,o.chatParser=$e,o.classNames=ce,o.compareVersions=Ce,o.createPostEvent=ve,o.date=pe,o.getHash=rr,o.init=Xt,o.initDataParser=le,o.invokeCustomMethod=D,o.isColorDark=he,o.isIframe=re,o.isPageReload=be,o.isRGB=Z,o.isRGBShort=qe,o.isRecord=L,o.isStableViewportPlatform=ze,o.isTMA=tr,o.isTimeoutError=nr,o.json=g,o.launchParamsParser=Xe,o.mergeClassNames=At,o.number=V,o.off=I,o.on=m,o.once=kt,o.parseInitData=Tt,o.parseLaunchParams=_e,o.parseMessage=ke,o.parseThemeParams=fe,o.postEvent=f,o.request=y,o.requestThemeParams=Nt,o.requestViewport=ge,o.retrieveLaunchData=er,o.retrieveLaunchParams=ee,o.rgb=ie,o.searchParams=Y,o.serializeLaunchParams=rt,o.serializeThemeParams=Ge,o.setCSSVar=k,o.setDebug=at,o.setTargetOrigin=ct,o.string=u,o.subscribe=qt,o.supports=T,o.themeParamsParser=de,o.toRGB=ne,o.unsubscribe=Ae,o.userParser=ue,o.withTimeout=ae,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
1
+ var ir=Object.defineProperty;var or=(o,b,q)=>b in o?ir(o,b,{enumerable:!0,configurable:!0,writable:!0,value:q}):o[b]=q;var a=(o,b,q)=>(or(o,typeof b!="symbol"?b+"":b,q),q);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(o){"use strict";class b{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,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)}}let q="https://web.telegram.org";const R=new b("[SDK]",!1);function at(r){if(r){R.enable();return}R.disable()}function ct(r){q=r}function ht(){return q}function re(){try{return window.self!==window.top}catch{return!0}}function L(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function ut(r){return"external"in r&&L(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function pt(r){return"TelegramWebviewProxy"in r&&L(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function f(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=ht()}=s;if(R.log(`Calling method "${r}"`,n),re()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(ut(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(pt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function Ce(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const c=parseInt(t[i]||"0",10),h=parseInt(s[i]||"0",10);if(c!==h)return c>h?1:-1}return 0}function A(r,e){return Ce(r,e)<=0}function T(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return A("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return A("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 A("6.1",e);case"web_app_open_popup":return A("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 A("6.4",e);case"web_app_switch_inline_query":return A("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return A("6.9",e);case"web_app_setup_settings_button":return A("6.10",e);default:return!0}}class z extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,z.prototype)}}class J extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,J.prototype)}}function ve(r){return(e,t)=>{if(!T(e,r))throw new z(e,r);if(L(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!T(e,s,r))throw new J(e,s,r)}return f(e,t)}}function Pe(r){return({req_id:e})=>e===r}class W extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});a(this,"type");this.value=t,Object.setPrototypeOf(this,W.prototype),this.type=n}}class M extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,M.prototype)}}function Se(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,c;if(typeof n=="function"||"parse"in n)i=s,c=typeof n=="function"?n:n.parse.bind(n);else{const{type:l}=n;i=n.from||s,c=typeof l=="function"?l:l.parse.bind(l)}let h;const p=e(i);try{h=c(p)}catch(l){throw l instanceof W?new M(i,{type:l.type,cause:l}):new M(i,{cause:l})}h!==void 0&&(t[s]=h)}return t}function B(){return new TypeError("Value has unexpected type")}function se(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw B();return e}class Q{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new W(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function g(r,e){return new Q(t=>{const s=se(t);return Se(r,n=>s[n])},!1,e)}function $(r,e){return()=>new Q(r,!1,e)}const u=$(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw B()},"string");function ke(r){return g({eventType:u(),eventData:e=>e}).parse(r)}function lt(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function dt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=lt;return}s in t||(t[s]={}),t=t[s]})})}function ft(r){dt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=ke(e.data);r(t,s)}catch{}})}function gt(){return g({req_id:u(),data:r=>r===null?r:u().optional().parse(r)})}function wt(){return g({req_id:u(),result:r=>r,error:u().optional()})}function _t(){return g({slug:u(),status:u()})}function bt(){return g({status:u()})}function mt(){return g({button_id:r=>r==null?void 0:u().parse(r)})}function yt(){return g({data:u().optional()})}function Z(r){return/^#[\da-f]{6}$/i.test(r)}function qe(r){return/^#[\da-f]{3}$/i.test(r)}function ne(r){const e=r.replace(/\s/g,"").toLowerCase();if(Z(e))return e;if(qe(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}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((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}const ie=$(r=>ne(u().parse(r)),"rgb");function Et(){return g({theme_params:r=>{const e=ie().optional();return Object.entries(se(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}const P=$(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 B()},"boolean"),V=$(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw B()},"number");function Ct(){return g({height:V(),width:r=>r==null?window.innerWidth:V().parse(r),is_state_stable:P(),is_expanded:P()})}function vt(){return g({status:u()})}class _{constructor(){a(this,"listeners",new Map);a(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],c)=>{n(...t),i&&s.splice(c,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,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 Pt(){const r=new _,e=(t,...s)=>{R.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),ft((t,s)=>{R.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,Ct().parse(s));case"theme_changed":return e(t,Et().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,mt().parse(s));case"set_custom_style":return e(t,u().parse(s));case"qr_text_received":return e(t,yt().parse(s));case"clipboard_text_received":return e(t,gt().parse(s));case"invoice_closed":return e(t,_t().parse(s));case"phone_requested":return e("phone_requested",bt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",wt().parse(s));case"write_access_requested":return e("write_access_requested",vt().parse(s));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,s)}}catch(n){R.error("Error processing event:",n)}}),r}const oe="telegram-mini-apps-cached-emitter";function U(){const r=window;return r[oe]===void 0&&(r[oe]=Pt()),r[oe]}function I(r,e){U().off(r,e)}function m(r,e){return U().on(r,e),()=>I(r,e)}class G extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,G.prototype)}}function St(r){return new Promise((e,t)=>{setTimeout(t,r,new G(r))})}function ae(r,e){return Promise.race([typeof r=="function"?r():r,St(e)])}async function y(r,e,t){let s;const n=new Promise(v=>{s=v}),i=e?{...t,event:e,method:r}:r,{method:c,event:h,capture:p,postEvent:l=f,timeout:w}=i,C=(Array.isArray(h)?h:[h]).map(v=>m(v,d=>(!p||p(d))&&s(d)));try{return l(c,i.params),await(w?ae(n,w):n)}finally{C.forEach(v=>v())}}async function D(r,e,t,s={}){const{result:n,error:i}=await y("web_app_invoke_custom_method","custom_method_invoked",{...s,params:{method:r,params:e,req_id:t},capture:Pe(t)});if(i)throw new Error(i);return n}function kt(r,e){return U().once(r,e),()=>I(r,e)}function Ae(r){U().unsubscribe(r)}function qt(r){return U().subscribe(r),()=>Ae(r)}function K(r,e){return r+(r.length&&e.length?` ${e}`:e)}function ce(...r){return r.reduce((e,t)=>typeof t=="string"?K(e,t):L(t)?K(e,Object.entries(t).reduce((s,n)=>n[1]?K(s,n[0]):s,"")):Array.isArray(t)?K(e,ce(...t)):e,"")}function At(...r){return r.reduce((e,t)=>(L(t)&&Object.entries(t).forEach(([s,n])=>{const i=ce(e[s],n);i.length>0&&(e[s]=i)}),e),{})}function he(r){const e=ne(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const c=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+c*c*n},0))<120}class E{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}function S(r,e){return t=>T(e[t],r)}class Ve{constructor(e,t,s=f){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?m("back_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("back_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=S(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 Re{constructor(e,t=f){a(this,"ee",new _);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 E({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}}function Vt(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 B()}class Rt extends Q{constructor(t,s,n){super(Vt,s,n);a(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function Te(r){return new Rt(e=>e,!1,r)}function Ie(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class Le{constructor(e,t,s=f){a(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=S(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await D("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await D("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Te().of(u()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return Ie(s,"");const n=g(Ie(s,u())),i=await D("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(c=>n.parse(c));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await D("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}class Be{constructor(e,t=f){a(this,"supports");this.postEvent=t,this.supports=S(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"})}}function $e(){return g({id:V(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat")}class De{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function ue(){return g({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:V(),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()},"User")}const pe=$(r=>r instanceof Date?r:new Date(V().parse(r)*1e3),"Date");function Y(r,e){return new Q(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw B();const s=typeof t=="string"?new URLSearchParams(t):t;return Se(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function le(){return Y({authDate:{type:pe(),from:"auth_date"},canSendAfter:{type:V().optional(),from:"can_send_after"},chat:$e().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:ue().optional(),startParam:{type:u().optional(),from:"start_param"},user:ue().optional()},"InitData")}function Tt(r){return le().parse(r)}function It(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class Oe{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?It(e):e;this.isOpened=!0;try{return(await y("web_app_open_invoice","invoice_closed",{params:{slug:s},postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}class Ne{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",(e,t)=>e==="click"?m("main_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=f,text:s,textColor:n,backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p}=e;this.postEvent=t,this.state=new E({backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}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}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}const Lt=Y({contact:g({userId:{type:V(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:pe(),from:"auth_date"},hash:u()});function He(r,e){return t=>{const[s,n]=e[t];return T(s,n,r)}}function Bt(r){return new Promise(e=>{setTimeout(e,r)})}class We{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"botInline");a(this,"postEvent");a(this,"createRequestId");a(this,"requestingPhoneAccess",!1);a(this,"requestingWriteAccess",!1);a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");a(this,"supportsParam");const{postEvent:t=f,headerColor:s,backgroundColor:n,version:i,botInline:c,createRequestId:h}=e,p=S(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=c,this.createRequestId=h,this.supports=l=>!(!p(l)||l==="switchInlineQuery"&&!c),this.state=new E({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=He(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return D("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Lt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return he(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ae(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Bt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,y("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,y("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}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",Z(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)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function $t(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;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(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:c=""}=i;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const h=i.text.trim();if(h.length===0||h.length>64){const p=i.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${i.text.length}`)}return{...i,text:h,id:c}}return{...i,id:c}}),{title:t,message:e,buttons:n}}class Me{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,y("web_app_open_popup","popup_closed",{postEvent:this.postEvent,params:$t(e)}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class Ue{constructor(e,t=f){a(this,"ee",new _);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 E({isOpened:!1},this.ee),this.supports=S(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",["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent,params:{text:e}});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class Ge{constructor(e,t,s=f){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?m("settings_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?I("settings_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new E({isVisible:e},this.ee),this.supports=S(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Dt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function Ot(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const de=$(r=>{const e=ie().optional();return Object.entries(se(r)).reduce((t,[s,n])=>(t[Dt(s)]=e.parse(n),t),{})},"ThemeParams");function fe(r){return de().parse(r)}function Nt(r){return y("web_app_request_theme","theme_changed",r).then(fe)}function je(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[Ot(t)]=s),e),{}))}class xe{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.state=new E(e,this.ee)}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)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||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")}listen(){return m("theme_changed",e=>{this.state.set(fe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}class Fe{constructor(e,t,s=f){a(this,"supports");a(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=S(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=He(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!T("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);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}this.postEvent("web_app_open_tg_link",{path_full:s+n})}async readTextFromClipboard(){const e=this.createRequestId(),{data:t=null}=await y("web_app_read_text_from_clipboard","clipboard_text_received",{postEvent:this.postEvent,params:{req_id:e},capture:Pe(e)});return t}}function ze(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function ge(r){const e=await y("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function j(r){return r<0?0:r}class Je{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:c=f}=e;this.postEvent=c,this.state=new E({height:j(t),isExpanded:s,stableHeight:j(i),width:j(n)},this.ee)}sync(e){return ge(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return m("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,c={height:j(t),isExpanded:n,width:j(s)};i&&(c.stableHeight=c.height),this.state.set(c)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function k(r,e){document.documentElement.style.setProperty(r,e)}function Qe(r,e){const t=()=>{k("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Z(r.headerColor)){k("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){k("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&k("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Ze(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);k(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function we(r){const e=()=>k("--tg-viewport-height",`${r.height}px`),t=()=>k("--tg-viewport-width",`${r.width}px`),s=()=>k("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}function Ht(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),m("set_custom_style",e=>{r.innerHTML=e})}function Ke(r){return`telegram-mini-apps-${r}`}function O(r,e){sessionStorage.setItem(Ke(r),JSON.stringify(e))}function N(r){const e=sessionStorage.getItem(Ke(r));return e?JSON.parse(e):null}function Wt(r,e,t){const{isVisible:s=!1}=r?N("back-button")||{}:{},n=new Ve(s,e,t);return n.on("change",()=>{O("back-button",{isVisible:n.isVisible})}),n}function Mt(r,e){const{isConfirmationNeeded:t=!1}=r?N("closing-behavior")||{}:{},s=new Re(t,e);return s.on("change",()=>O("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}function Ut(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:c=!1,isLoaderVisible:h=!1,textColor:p=t,text:l=""}=r?N("main-button")||{}:{},w=new Ne({backgroundColor:n,isEnabled:i,isLoaderVisible:h,isVisible:c,postEvent:s,text:l,textColor:p}),C=()=>O("main-button",{backgroundColor:w.backgroundColor,isEnabled:w.isEnabled,isLoaderVisible:w.isLoaderVisible,isVisible:w.isVisible,text:w.text,textColor:w.textColor});return w.on("change",C),w}function Gt(r,e,t,s,n,i){const{backgroundColor:c=e,headerColor:h="bg_color"}=r?N("mini-app")||{}:{},p=new We({headerColor:h,backgroundColor:c,version:t,botInline:s,createRequestId:n,postEvent:i}),l=()=>O("mini-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("change",l),p}function jt(){let r=0;return()=>(r+=1,r.toString())}function xt(r,e,t){const{isVisible:s=!1}=r?N("settings-button")||{}:{},n=new Ge(s,e,t);return n.on("change",()=>{O("settings-button",{isVisible:n.isVisible})}),n}function Ft(r){const e=new xe(r);return e.listen(),e}function X(r){const e=new Je(r);return e.on("change",()=>O("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function zt(r,e,t,s){const n=r?N("viewport"):null;if(n)return X({...n,postEvent:t});if(ze(e))return X({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return ge({postEvent:t,timeout:5e3}).then(({height:c,isStateStable:h,...p})=>X({...p,height:c,stableHeight:h?c:0}));const i=X({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(c=>{console.error("Unable to actualize viewport state",c)}),i}function Jt(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ye(r,e,t,s){const n=Jt(r);n.miniApp&&Qe(e,t),n.themeParams&&Ze(t),n.viewport&&(s instanceof Promise?s.then(we):we(s))}function Xe(){return Y({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:le().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:de(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}},"LaunchParams")}function _e(r){return Xe().parse(r)}function et(r){return _e(r.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function Qt(){return et(window.location.href)}function tt(){return performance.getEntriesByType("navigation")[0]}function Zt(){const r=tt();if(!r)throw new Error("Unable to get first navigation entry.");return et(r.name)}function rt(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:c,botInline:h}=r,p=new URLSearchParams;return e&&p.set("tgWebAppData",e),p.set("tgWebAppPlatform",s),p.set("tgWebAppThemeParams",je(t)),p.set("tgWebAppVersion",n),c&&p.set("tgWebAppStartParam",c),typeof i=="boolean"&&p.set("tgWebAppShowSettings",i?"1":"0"),typeof h=="boolean"&&p.set("tgWebAppBotInline",h?"1":"0"),p.toString()}const st="telegram-mini-apps-launch-params";function Kt(){return _e(sessionStorage.getItem(st)||"")}function Yt(r){sessionStorage.setItem(st,rt(r))}function ee(){const r=[];for(const e of[Qt,Zt,Kt])try{const t=e();return Yt(t),t}catch(t){r.push(t)}throw R.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function be(){var r;return((r=tt())==null?void 0:r.type)==="reload"}function Xt(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:c,version:h,platform:p,themeParams:l,botInline:w=!1}=ee(),C=be(),v=jt(),d=ve(h);re()&&(n&&Ht(),d("iframe_ready",{reload_supported:!0}),m("reload_iframe",()=>{d("iframe_will_reload"),window.location.reload()}));const H={backButton:Wt(C,h,d),closingBehavior:Mt(C,d),cloudStorage:new Le(h,v,d),createRequestId:v,hapticFeedback:new Be(h,d),invoice:new Oe(h,d),mainButton:Ut(C,l.buttonColor||"#000000",l.buttonTextColor||"#ffffff",d),miniApp:Gt(C,l.backgroundColor||"#ffffff",h,w,v,d),popup:new Me(h,d),postEvent:d,qrScanner:new Ue(h,d),settingsButton:xt(C,h,d),themeParams:Ft(l),utils:new Fe(h,v,d),...i?{initData:new De(i),initDataRaw:c}:{}},te=zt(C,p,d,t);return te instanceof Promise||t?Promise.resolve(te).then(ot=>(Ye(s,H.miniApp,H.themeParams,ot),{...H,viewport:ot})):(Ye(s,H.miniApp,H.themeParams,te),{...H,viewport:te})}catch(i){if(t)return Promise.reject(i);throw i}}function er(){return{launchParams:ee(),isPageReload:be()}}function tr(){try{return ee(),!0}catch{return!1}}function rr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function x(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function sr(){if(window.history.length<=1||(window.history.pushState(null,""),await x(1-window.history.length)))return;let e=await x(-1);for(;e;)e=await x(-1)}function F(r,e){return r.startsWith(e)?r:`${e}${r}`}class nt{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){a(this,"logger");a(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:c,hash:h})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:F(i,"/"),search:c?F(c,"?"):"",hash:h?F(h,"#"):""}}),this.logger=new b(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:c="",search:h,hash:p}=e;t=c+(h?F(h,"?"):"")+(p?F(p,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const it=0,me=1,ye=2;class Ee extends nt{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});a(this,"ee",new _);a(this,"attached",!1);a(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===it){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===me)return this.back();if(t===ye)return this.forward()});a(this,"back",()=>super.back());a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new Ee([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await sr(),f("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(me,""),window.history.pushState(null,"",t),window.history.pushState(ye,""),await x(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(me,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(ye,""),await x(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(it,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,m("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),I("back_button_pressed",this.back))}}function nr(r){return r instanceof G}return o.BackButton=Ve,o.ClosingBehavior=Re,o.CloudStorage=Le,o.HapticFeedback=Be,o.HashNavigator=Ee,o.InitData=De,o.Invoice=Oe,o.MainButton=Ne,o.MethodUnsupportedError=z,o.MiniApp=We,o.Navigator=nt,o.ParameterUnsupportedError=J,o.ParseError=W,o.ParseSchemaFieldError=M,o.Popup=Me,o.QRScanner=Ue,o.SettingsButton=Ge,o.ThemeParams=xe,o.TimeoutError=G,o.Utils=Fe,o.Viewport=Je,o.array=Te,o.bindMiniAppCSSVars=Qe,o.bindThemeCSSVars=Ze,o.bindViewportCSSVars=we,o.boolean=P,o.chatParser=$e,o.classNames=ce,o.compareVersions=Ce,o.createPostEvent=ve,o.date=pe,o.getHash=rr,o.init=Xt,o.initDataParser=le,o.invokeCustomMethod=D,o.isColorDark=he,o.isIframe=re,o.isPageReload=be,o.isRGB=Z,o.isRGBShort=qe,o.isRecord=L,o.isStableViewportPlatform=ze,o.isTMA=tr,o.isTimeoutError=nr,o.json=g,o.launchParamsParser=Xe,o.mergeClassNames=At,o.number=V,o.off=I,o.on=m,o.once=kt,o.parseInitData=Tt,o.parseLaunchParams=_e,o.parseMessage=ke,o.parseThemeParams=fe,o.postEvent=f,o.request=y,o.requestThemeParams=Nt,o.requestViewport=ge,o.retrieveLaunchData=er,o.retrieveLaunchParams=ee,o.rgb=ie,o.searchParams=Y,o.serializeLaunchParams=rt,o.serializeThemeParams=je,o.setCSSVar=k,o.setDebug=at,o.setTargetOrigin=ct,o.string=u,o.subscribe=qt,o.supports=T,o.themeParamsParser=de,o.toRGB=ne,o.unsubscribe=Ae,o.userParser=ue,o.withTimeout=ae,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});