@tma.js/sdk 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var Ts=Object.defineProperty;var Cs=(r,b,w)=>b in r?Ts(r,b,{enumerable:!0,configurable:!0,writable:!0,value:w}):r[b]=w;var h=(r,b,w)=>(Cs(r,typeof b!="symbol"?b+"":b,w),w);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(r){"use strict";function b(e,t){let s;const n=()=>{s!==void 0&&t&&t(s),s=void 0};return[()=>s===void 0?s=e(n):s,n]}function w(e){const t=H(),{count:s}=t;t.unsubscribe(e),s&&!t.count&&ke()}function bt(e){return H().subscribe(e),()=>w(e)}class we{constructor(t,s={}){this.scope=t,this.options=s}print(t,...s){const n=new Date,i=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(n),{textColor:o,bgColor:c}=this.options,a="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${a};background-color: lightblue;color:black`,"",`${a};${o?`color:${o};`:""}${c?`background-color:${c}`:""}`,...s)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const x=new we("SDK",{bgColor:"forestgreen",textColor:"white"});let F=!1;const mt=({event:e,args:[t]})=>{x.log("Event received:",t===void 0?{name:e}:{name:e,data:t})};function ye(e){F!==e&&(F=e,e?bt(mt):w(mt))}function Ee(...e){F&&x.log(...e)}class I{constructor(){h(this,"listeners",new Map);h(this,"listenersCount",0);h(this,"subscribeListeners",[])}clear(){this.listeners.clear(),this.subscribeListeners=[]}get count(){return this.listenersCount+this.subscribeListeners.length}emit(t,...s){this.subscribeListeners.forEach(i=>i({event:t,args:s})),(this.listeners.get(t)||[]).forEach(([i,o])=>{i(...s),o&&this.off(t,i)})}on(t,s,n){let i=this.listeners.get(t);return i||this.listeners.set(t,i=[]),i.push([s,n]),this.listenersCount+=1,()=>this.off(t,s)}off(t,s){const n=this.listeners.get(t)||[];for(let i=0;i<n.length;i+=1)if(s===n[i][0]){n.splice(i,1),this.listenersCount-=1;return}}subscribe(t){return this.subscribeListeners.push(t),()=>this.unsubscribe(t)}unsubscribe(t){for(let s=0;s<this.subscribeListeners.length;s+=1)if(this.subscribeListeners[s]===t){this.subscribeListeners.splice(s,1);return}}}function z(e,t,s){return window.addEventListener(e,t,s),()=>window.removeEventListener(e,t,s)}class N extends Error{constructor(t,s,n){super(s,{cause:n}),this.type=t,Object.setPrototypeOf(this,N.prototype)}}function g(e,t,s){return new N(e,t,s)}const wt="ERR_METHOD_UNSUPPORTED",yt="ERR_METHOD_PARAMETER_UNSUPPORTED",Et="ERR_UNKNOWN_ENV",vt="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Pt="ERR_TIMED_OUT",St="ERR_UNEXPECTED_TYPE",J="ERR_PARSE",Rt="ERR_NAVIGATION_LIST_EMPTY",Tt="ERR_NAVIGATION_CURSOR_INVALID",ve="ERR_NAVIGATION_ITEM_INVALID",Pe="ERR_SSR_INIT",Ct="ERR_INVALID_PATH_BASE";function R(){return g(St,"Value has unexpected type")}class ${constructor(t,s,n){this.parser=t,this.isOptional=s,this.type=n}parse(t){if(!(this.isOptional&&t===void 0))try{return this.parser(t)}catch(s){throw g(J,`Unable to parse value${this.type?` as ${this.type}`:""}`,s)}}optional(){return this.isOptional=!0,this}}function T(e,t){return()=>new $(e,!1,t)}const y=T(e=>{if(typeof e=="boolean")return e;const t=String(e);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;throw R()},"boolean");function At(e,t){const s={};for(const n in e){const i=e[n];if(!i)continue;let o,c;if(typeof i=="function"||"parse"in i)o=n,c=typeof i=="function"?i:i.parse.bind(i);else{const{type:a}=i;o=i.from||n,c=typeof a=="function"?a:a.parse.bind(a)}try{const a=c(t(o));a!==void 0&&(s[n]=a)}catch(a){throw g(J,`Unable to parse field "${n}"`,a)}}return s}function Q(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw R();return t}function d(e,t){return new $(s=>{const n=Q(s);return At(e,i=>n[i])},!1,t)}const P=T(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw R()},"number");function U(e){return/^#[\da-f]{6}$/i.test(e)}function It(e){return/^#[\da-f]{3}$/i.test(e)}function Y(e){const t=e.replace(/\s/g,"").toLowerCase();if(U(t))return t;if(It(t)){let n="#";for(let i=0;i<3;i+=1)n+=t[1+i].repeat(2);return n}const s=t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(!s)throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);return s.slice(1).reduce((n,i)=>{const o=parseInt(i,10).toString(16);return n+(o.length===1?"0":"")+o},"#")}const u=T(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw R()},"string"),K=T(e=>Y(u().parse(e)),"rgb");function Se(e){return d({eventType:u(),eventData:t=>t}).parse(e)}function Re(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function Te(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Ce(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=Te;return}s in t||(t[s]={}),t=t[s]})})}const Ae=d({button_id:e=>e==null?void 0:u().parse(e)}),Ie={clipboard_text_received:d({req_id:u(),data:e=>e===null?e:u().optional().parse(e)}),custom_method_invoked:d({req_id:u(),result:e=>e,error:u().optional()}),invoice_closed:d({slug:u(),status:u()}),phone_requested:d({status:u()}),popup_closed:{parse:e=>Ae.parse(e??{})},qr_text_received:d({data:u().optional()}),theme_changed:d({theme_params:e=>{const t=K().optional();return Object.entries(Q(e)).reduce((s,[n,i])=>(s[n]=t.parse(i),s),{})}}),viewport_changed:d({height:P(),width:e=>e==null?window.innerWidth:P().parse(e),is_state_stable:y(),is_expanded:y()}),write_access_requested:d({status:u()})};function Ne(){const e=new I;Ce();let t=[Re,z("resize",()=>{e.emit("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),z("message",s=>{if(s.source!==window.parent)return;let n;try{n=Se(s.data)}catch{return}const{eventType:i,eventData:o}=n,c=Ie[i];try{const a=c?c.parse(o):o;e.emit(...a?[i,a]:[i])}catch(a){x.error(`An error occurred processing the "${i}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,n,a)}}),()=>e.clear()];return[e,()=>{t.forEach(s=>s()),t=[]}]}const[qe,ke]=b(e=>{const[t,s]=Ne(),n=t.off.bind(t);return t.off=(i,o)=>{const{count:c}=t;n(i,o),c&&!t.count&&e()},[t,s]},([,e])=>e());function H(){return qe()[0]}function q(e,t){H().off(e,t)}function m(e,t,s){return H().on(e,t,s)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Nt(e,t){const s=e.split("."),n=t.split("."),i=Math.max(s.length,n.length);for(let o=0;o<i;o+=1){const c=parseInt(s[o]||"0",10),a=parseInt(n[o]||"0",10);if(c!==a)return c>a?1:-1}return 0}function E(e,t){return Nt(e,t)<=0}function S(e,t,s){if(typeof s=="string"){if(e==="web_app_open_link"&&t==="try_instant_view")return E("6.4",s);if(e==="web_app_set_header_color"&&t==="color")return E("6.9",s)}switch(e){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 E("6.1",t);case"web_app_open_popup":return E("6.2",t);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return E("6.4",t);case"web_app_switch_inline_query":return E("6.7",t);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return E("6.9",t);case"web_app_setup_settings_button":return E("6.10",t);case"web_app_biometry_get_info":case"web_app_biometry_open_settings":case"web_app_biometry_request_access":case"web_app_biometry_request_auth":case"web_app_biometry_update_token":return E("7.2",t);default:return["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"].includes(e)}}function De(e){return"external"in e&&k(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function qt(e){return"TelegramWebviewProxy"in e&&k(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function kt(){try{return window.self!==window.top}catch{return!0}}let Dt="https://web.telegram.org";function Ve(e){Dt=e}function Vt(){return Dt}function C(e,t,s){let n={},i;t===void 0&&s===void 0?n={}:t!==void 0&&s!==void 0?(n=s,i=t):t!==void 0&&("targetOrigin"in t?n=t:i=t);const{targetOrigin:o=Vt()}=n;if(Ee("Posting event:",i?{event:e,data:i}:{event:e}),kt()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),o);return}if(De(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(qt(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw g(Et,"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment.")}function Mt(e){return(t,s)=>{if(!S(t,e))throw g(wt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(k(s)){let n;if(t==="web_app_open_link"&&"try_instant_view"in s?n="try_instant_view":t==="web_app_set_header_color"&&"color"in s&&(n="color"),n&&!S(t,n,e))throw g(yt,`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return C(t,s)}}function X(e){return({req_id:t})=>t===e}function Bt(e){return g(Pt,`Timeout reached: ${e}ms`)}function Z(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n(Bt(t))},t)})])}async function _(e){let t;const s=new Promise(l=>{t=l}),{method:n,event:i,capture:o,postEvent:c=C,timeout:a}=e,p=(Array.isArray(i)?i:[i]).map(l=>m(l,j=>(!o||o(j))&&t(j)));try{return c(n,e.params),await(a?Z(s,a):s)}finally{p.forEach(l=>l())}}async function A(e,t,s,n={}){const{result:i,error:o}=await _({...n,method:"web_app_invoke_custom_method",event:"custom_method_invoked",params:{method:e,params:t,req_id:s},capture:X(s)});if(o)throw g(vt,o);return i}function W(...e){return e.map(t=>{if(typeof t=="string")return t;if(k(t))return W(Object.entries(t).map(s=>s[1]&&s[0]));if(Array.isArray(t))return W(...t)}).filter(Boolean).join(" ")}function Me(...e){return e.reduce((t,s)=>(k(s)&&Object.entries(s).forEach(([n,i])=>{const o=W(t[n],i);o.length&&(t[n]=o)}),t),{})}function tt(e){const t=Y(e);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const o=parseInt(t.slice(1+i*2,1+(i+1)*2),16);return s+o*o*n},0))<120}class Be{constructor(t){h(this,"ee",new I);h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));this.state=t}clone(){return{...this.state}}set(t,s){Object.entries(typeof t=="string"?{[t]:s}:t).reduce((i,[o,c])=>this.state[o]===c||c===void 0?i:(this.state[o]=c,this.ee.emit(`change:${o}`,c),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class et{constructor(t){h(this,"state");h(this,"get");h(this,"set");h(this,"clone");this.state=new Be(t),this.set=this.state.set.bind(this.state),this.get=this.state.get.bind(this.state),this.clone=this.state.clone.bind(this.state)}}function Ot(e,t){return s=>S(t[s],e)}class st extends et{constructor(s,n,i){super(s);h(this,"supports");this.supports=Ot(n,i)}}class Lt extends st{constructor(s,n,i){super({isVisible:s},n,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"});h(this,"on",(s,n)=>s==="click"?m("back_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?q("back_button_pressed",n):this.state.off(s,n));this.postEvent=i}set isVisible(s){this.set("isVisible",s),this.postEvent("web_app_setup_back_button",{is_visible:s})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const nt=T(e=>e instanceof Date?e:new Date(P().parse(e)*1e3),"Date");function G(e,t){return new $(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw R();const n=typeof s=="string"?new URLSearchParams(s):s;return At(e,i=>{const o=n.get(i);return o===null?void 0:o})},!1,t)}const Oe=d({id:P(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat").optional(),$t=d({addedToAttachmentMenu:{type:y().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:y().optional(),from:"allows_write_to_pm"},firstName:{type:u(),from:"first_name"},id:P(),isBot:{type:y().optional(),from:"is_bot"},isPremium:{type:y().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").optional();function Ut(){return G({authDate:{type:nt(),from:"auth_date"},canSendAfter:{type:P().optional(),from:"can_send_after"},chat:Oe,chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:$t,startParam:{type:u().optional(),from:"start_param"},user:$t},"InitData")}function Le(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function $e(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const Ht=T(e=>{const t=K().optional();return Object.entries(Q(e)).reduce((s,[n,i])=>(s[Le(n)]=t.parse(i),s),{})},"ThemeParams");function it(e){return G({botInline:{type:y().optional(),from:"tgWebAppBotInline"},initData:{type:Ut().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:y().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:Ht(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}}).parse(e)}function Wt(e){return it(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function Ue(){return Wt(window.location.href)}function Gt(){return performance.getEntriesByType("navigation")[0]}function He(){const e=Gt();if(!e)throw new Error("Unable to get first navigation entry.");return Wt(e.name)}function jt(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function xt(e,t){sessionStorage.setItem(jt(e),JSON.stringify(t))}function Ft(e){const t=sessionStorage.getItem(jt(e));try{return t?JSON.parse(t):void 0}catch{}}function We(){return it(Ft("launchParams")||"")}function zt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[$e(t),s])))}function Jt(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:o,startParam:c,botInline:a}=e,p=new URLSearchParams;return p.set("tgWebAppPlatform",n),p.set("tgWebAppThemeParams",zt(s)),p.set("tgWebAppVersion",i),t&&p.set("tgWebAppData",t),c&&p.set("tgWebAppStartParam",c),typeof o=="boolean"&&p.set("tgWebAppShowSettings",o?"1":"0"),typeof a=="boolean"&&p.set("tgWebAppBotInline",a?"1":"0"),p.toString()}function Ge(e){xt("launchParams",Jt(e))}function Qt(){for(const e of[Ue,He,We])try{const t=e();return Ge(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function rt(){const e=Gt();return!!(e&&e.type==="reload")}function je(){let e=0;return()=>(e+=1).toString()}function xe(){let e=!1;const t=[];return[s=>!e&&t.push(s),()=>{e||(e=!0,t.forEach(s=>s()))},e]}const[Fe]=b(je);function f(e,t){return()=>{const s=Qt(),n={...s,postEvent:Mt(s.version),createRequestId:Fe()};if(typeof e=="function")return e(n);const[i,o,c]=xe(),a=t({...n,state:rt()?Ft(e):void 0,addCleanup:i}),p=l=>(c||i(l.on("change",j=>{xt(e,j)})),l);return[a instanceof Promise?a.then(p):p(a),o]}}const ze=f("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new Lt(s.isVisible,t,e));class D extends st{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}function Yt(e){const t=e.available?e:{available:!1,device_id:"",token_saved:!1,access_requested:!1,access_granted:!1,type:""};return{available:!0,type:t.type,deviceId:t.device_id,tokenSaved:t.token_saved,accessRequested:t.access_requested,accessGranted:t.access_granted}}class Kt extends D{constructor({postEvent:s,version:n,...i}){super(i,n,{auth:"web_app_biometry_request_auth",openSettings:"web_app_biometry_open_settings",requestAccess:"web_app_biometry_request_access",updateToken:"web_app_biometry_update_token"});h(this,"postEvent");h(this,"authPromise");h(this,"accessPromise");this.postEvent=s}get available(){return this.get("available")}get accessGranted(){return this.get("accessGranted")}get accessRequested(){return this.get("accessRequested")}async authenticate({reason:s,...n}){return this.authPromise||(this.authPromise=_({...n,method:"web_app_biometry_request_auth",event:"biometry_auth_requested",postEvent:this.postEvent,params:{reason:(s||"").trim()}}).then(({token:i})=>i).finally(()=>this.authPromise=void 0)),this.authPromise}get deviceId(){return this.get("deviceId")}openSettings(){this.postEvent("web_app_biometry_open_settings")}requestAccess({reason:s,...n}={}){return this.accessPromise||(this.accessPromise=_({...n,postEvent:this.postEvent,method:"web_app_biometry_request_access",event:"biometry_info_received",params:{reason:s||""}}).then(i=>{const o=Yt(i);return this.set(o),o.accessGranted}).finally(()=>this.accessPromise=void 0)),this.accessPromise}get biometryType(){return this.get("biometryType")}get tokenSaved(){return this.get("tokenSaved")}async updateToken({token:s,...n}={}){return["removed","updated"].includes((await _({...n,postEvent:this.postEvent,method:"web_app_biometry_update_token",event:"biometry_token_updated",params:{token:s||""}})).status)}}async function Xt(e){return Yt(await _({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const Je=f("biometryManager",async({postEvent:e,version:t,state:s})=>new Kt({...s||await Xt({timeout:1e3}),version:t,postEvent:e}));class ot extends et{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}class Zt extends ot{constructor(t,s){super({isConfirmationNeeded:t}),this.postEvent=s}set isConfirmationNeeded(t){this.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const Qe=f("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new Zt(t.isConfirmationNeeded,e));class at{constructor(t,s){h(this,"supports");this.supports=Ot(t,s)}}function Ye(e){if(Array.isArray(e))return e;if(typeof e=="string")try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch{}throw R()}class Ke extends ${constructor(s,n,i){super(Ye,n,i);h(this,"itemParser");this.itemParser=typeof s=="function"?s:s.parse.bind(s)}parse(s){const n=super.parse(s);return n===void 0?n:n.map(this.itemParser)}of(s){return this.itemParser=typeof s=="function"?s:s.parse.bind(s),this}}function te(e){return new Ke(t=>t,!1,e)}function ee(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class se extends at{constructor(t,s,n){super(t,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"}),this.createRequestId=s,this.postEvent=n}async delete(t,s={}){const n=Array.isArray(t)?t:[t];n.length&&await A("deleteStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent})}async getKeys(t={}){return te().of(u()).parse(await A("getStorageKeys",{},this.createRequestId(),{...t,postEvent:this.postEvent}))}async get(t,s={}){const n=Array.isArray(t)?t:[t];if(!n.length)return ee(n,"");const i=await A("getStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent}),o=d(ee(n,u()),"CloudStorageData").parse(i);return Array.isArray(t)?o:o[t]}async set(t,s,n={}){await A("saveStorageValue",{key:t,value:s},this.createRequestId(),{...n,postEvent:this.postEvent})}}const Xe=f(({createRequestId:e,postEvent:t,version:s})=>new se(s,e,t));class ne extends at{constructor(t,s){super(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"}),this.postEvent=s}impactOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:t})}notificationOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:t})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}const Ze=f(({version:e,postEvent:t})=>new ne(e,t));class ie{constructor(t){this.initData=t}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:t}=this;return t?new Date(this.authDate.getTime()+t*1e3):void 0}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}}const ts=f(({initData:e})=>e?new ie(e):void 0);function es(e){return Ut().parse(e)}class re extends D{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_invoice"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t,s){if(this.isOpened)throw new Error("Invoice is already opened");let n;if(!s)n=t;else{const{hostname:i,pathname:o}=new URL(t,window.location.href);if(i!=="t.me")throw new Error(`Incorrect hostname: ${i}`);const c=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!c)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,n]=c}this.isOpened=!0;try{return(await _({method:"web_app_open_invoice",event:"invoice_closed",params:{slug:n},postEvent:this.postEvent,capture(o){return n===o.slug}})).status}finally{this.isOpened=!1}}}const ss=f(({version:e,postEvent:t})=>new re(!1,e,t));class oe extends et{constructor({postEvent:s,...n}){super(n);h(this,"postEvent");h(this,"on",(s,n)=>s==="click"?m("main_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?q("main_button_pressed",n):this.state.off(s,n));this.postEvent=s}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(s){this.setParams({isEnabled:s})}get isEnabled(){return this.get("isEnabled")}set isLoaderVisible(s){this.setParams({isLoaderVisible:s})}get isLoaderVisible(){return this.get("isLoaderVisible")}set isVisible(s){this.setParams({isVisible:s})}get isVisible(){return this.get("isVisible")}get backgroundColor(){return this.get("backgroundColor")}get text(){return this.get("text")}get textColor(){return this.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(s){return this.setParams({text:s})}setTextColor(s){return this.setParams({textColor:s})}setBackgroundColor(s){return this.setParams({backgroundColor:s})}setParams(s){return this.set(s),this.commit(),this}}const ns=f("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",backgroundColor:t.buttonColor||"#000000"}})=>new oe({...s,postEvent:e}));function is(){return G({contact:d({userId:{type:P(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:nt(),from:"auth_date"},hash:u()},"RequestedContact")}function ae(e,t){return s=>{const[n,i]=t[s];return S(n,i,e)}}function rs(e){return new Promise(t=>{setTimeout(t,e)})}class ce extends D{constructor({postEvent:s,createRequestId:n,version:i,botInline:o,...c}){super(c,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"});h(this,"botInline");h(this,"postEvent");h(this,"createRequestId");h(this,"requestPhoneAccessPromise");h(this,"requestWriteAccessPromise");h(this,"supportsParam");this.createRequestId=n,this.postEvent=s,this.botInline=o;const a=this.supports.bind(this);this.supports=p=>a(p)?p!=="switchInlineQuery"||o:!1,this.supportsParam=ae(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:s=1e4}={}){return is().parse(await A("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:s}))}get bgColor(){return this.get("bgColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return tt(this.bgColor)}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:s=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const i=Date.now()+s;let o=50;return Z(async()=>{for(;Date.now()<i;){try{return await this.getRequestedContact()}catch{}await rs(o),o+=50}throw Bt(s)},s)}async requestPhoneAccess(s={}){return this.requestPhoneAccessPromise||(this.requestPhoneAccessPromise=_({...s,method:"web_app_request_phone",event:"phone_requested",postEvent:this.postEvent}).then(({status:n})=>n).finally(()=>this.requestPhoneAccessPromise=void 0)),this.requestPhoneAccessPromise}async requestWriteAccess(s={}){return this.requestWriteAccessPromise||(this.requestWriteAccessPromise=_({...s,method:"web_app_request_write_access",event:"write_access_requested",postEvent:this.postEvent}).then(({status:n})=>n).finally(()=>this.requestWriteAccessPromise=void 0)),this.requestWriteAccessPromise}sendData(s){const{size:n}=new Blob([s]);if(!n||n>4096)throw new Error(`Passed data has incorrect size: ${n}`);this.postEvent("web_app_data_send",{data:s})}setHeaderColor(s){this.postEvent("web_app_set_header_color",U(s)?{color:s}:{color_key:s}),this.set("headerColor",s)}setBgColor(s){this.postEvent("web_app_set_background_color",{color:s}),this.set("bgColor",s)}switchInlineQuery(s,n=[]){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:s,chat_types:n})}}const os=f("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new ce({...n,...s,botInline:t}));function as(e){const t=e.message.trim(),s=(e.title||"").trim(),n=e.buttons||[];let i;if(s.length>64)throw new Error(`Title has incorrect size: ${s.length}`);if(!t.length||t.length>256)throw new Error(`Message has incorrect size: ${t.length}`);if(n.length>3)throw new Error(`Buttons have incorrect size: ${n.length}`);return n.length?i=n.map(o=>{const{id:c=""}=o;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(!o.type||o.type==="default"||o.type==="destructive"){const a=o.text.trim();if(!a.length||a.length>64){const p=o.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${o.text.length}`)}return{...o,text:a,id:c}}return{...o,id:c}}):i=[{type:"close",id:""}],{title:s,message:t,buttons:i}}class he extends D{constructor(t,s,n){super({isOpened:t},s,{open:"web_app_open_popup"}),this.postEvent=n}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.isOpened=!0;try{const{button_id:s=null}=await _({event:"popup_closed",method:"web_app_open_popup",postEvent:this.postEvent,params:as(t)});return s}finally{this.isOpened=!1}}}const cs=f(({postEvent:e,version:t})=>new he(!1,t,e));class ue extends D{constructor(t,s,n){super({isOpened:t},s,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"}),this.postEvent=n}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{return(await _({method:"web_app_open_scan_qr_popup",event:["qr_text_received","scan_qr_popup_closed"],postEvent:this.postEvent,params:{text:t}})||{}).data||null}finally{this.isOpened=!1}}}const hs=f(({version:e,postEvent:t})=>new ue(!1,e,t));class pe extends st{constructor(s,n,i){super({isVisible:s},n,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"});h(this,"on",(s,n)=>s==="click"?m("settings_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?q("settings_button_pressed",n):this.state.off(s,n));this.postEvent=i}set isVisible(s){this.set("isVisible",s),this.postEvent("web_app_setup_settings_button",{is_visible:s})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const us=f("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new pe(s.isVisible,e,t));function ct(e){return Ht().parse(e)}class le extends ot{get accentTextColor(){return this.get("accentTextColor")}get bgColor(){return this.get("bgColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}getState(){return this.clone()}get headerBgColor(){return this.get("headerBgColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.bgColor||tt(this.bgColor)}get linkColor(){return this.get("linkColor")}get secondaryBgColor(){return this.get("secondaryBgColor")}get sectionBgColor(){return this.get("sectionBgColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return m("theme_changed",t=>{this.set(ct(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const ps=f("themeParams",({themeParams:e,state:t=e,addCleanup:s})=>{const n=new le(t);return s(n.listen()),n});function ls(e={}){return _({...e,method:"web_app_request_theme",event:"theme_changed"}).then(ct)}class de extends at{constructor(s,n,i){super(s,{readTextFromClipboard:"web_app_read_text_from_clipboard"});h(this,"supportsParam");this.version=s,this.createRequestId=n,this.postEvent=i,this.supportsParam=ae(s,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(s,n){const i=new URL(s,window.location.href).toString();if(!S("web_app_open_link",this.version)){window.open(i,"_blank");return}this.postEvent("web_app_open_link",{url:i,...typeof n=="boolean"?{try_instant_view:n}:{}})}openTelegramLink(s){const{hostname:n,pathname:i,search:o}=new URL(s,window.location.href);if(n!=="t.me")throw new Error(`URL has not allowed hostname: ${n}. Only "t.me" is allowed`);if(!S("web_app_open_tg_link",this.version)){window.location.href=s;return}this.postEvent("web_app_open_tg_link",{path_full:i+o})}async readTextFromClipboard(){const s=this.createRequestId(),{data:n=null}=await _({method:"web_app_read_text_from_clipboard",event:"clipboard_text_received",postEvent:this.postEvent,params:{req_id:s},capture:X(s)});return n}}const ds=f(({version:e,postEvent:t,createRequestId:s})=>new de(e,s,t));async function ht(e={}){const{is_expanded:t,is_state_stable:s,...n}=await _({...e,method:"web_app_request_viewport",event:"viewport_changed"});return{...n,isExpanded:t,isStateStable:s}}function V(e){return e<0?0:e}class _e extends ot{constructor({postEvent:s,stableHeight:n,height:i,width:o,isExpanded:c}){super({height:V(i),isExpanded:c,stableHeight:V(n),width:V(o)});h(this,"postEvent");this.postEvent=s}async sync(s){const{isStateStable:n,...i}=await ht(s);this.set({...i,stableHeight:n?i.height:this.get("stableHeight")})}get height(){return this.get("height")}get stableHeight(){return this.get("stableHeight")}listen(){return m("viewport_changed",s=>{const{height:n,width:i,is_expanded:o,is_state_stable:c}=s,a=V(n);this.set({height:a,isExpanded:o,width:V(i),...c?{stableHeight:a}:{}})})}get isExpanded(){return this.get("isExpanded")}get width(){return this.get("width")}expand(){this.postEvent("web_app_expand"),this.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}const _s=f("viewport",async({state:e,platform:t,postEvent:s,addCleanup:n})=>{let i=!1,o=0,c=0,a=0;if(e)i=e.isExpanded,o=e.height,c=e.width,a=e.stableHeight;else if(["macos","tdesktop","unigram","webk","weba","web"].includes(t))i=!0,o=window.innerHeight,c=window.innerWidth,a=window.innerHeight;else{const l=await ht({timeout:1e3,postEvent:s});i=l.isExpanded,o=l.height,c=l.width,a=l.isStateStable?o:0}const p=new _e({postEvent:s,height:o,width:c,stableHeight:a,isExpanded:i});return n(p.listen()),p});function v(e,t){document.documentElement.style.setProperty(e,t)}function fs(e,t,s){s||(s=a=>`--tg-${a}-color`);const n=s("header"),i=s("bg"),o=()=>{const{headerColor:a}=e;if(U(a))v(n,a);else{const{bgColor:p,secondaryBgColor:l}=t;a==="bg_color"&&p?v(n,p):a==="secondary_bg_color"&&l&&v(n,l)}v(i,e.bgColor)},c=[t.on("change",o),e.on("change",o)];return o(),()=>c.forEach(a=>a())}function gs(e,t){t||(t=n=>`--tg-theme-${n.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`);const s=()=>{Object.entries(e.getState()).forEach(([n,i])=>{i&&v(t(n),i)})};return s(),e.on("change",s)}function bs(e,t){t||(t=l=>`--tg-viewport-${l}`);const[s,n,i]=["height","width","stable-height"].map(l=>t(l)),o=()=>v(s,`${e.height}px`),c=()=>v(n,`${e.width}px`),a=()=>v(i,`${e.stableHeight}px`),p=[e.on("change:height",o),e.on("change:width",c),e.on("change:stableHeight",a)];return o(),c(),a(),()=>p.forEach(l=>l())}function ms(e=!0){const t=[m("reload_iframe",()=>{C("iframe_will_reload"),window.location.reload()})],s=()=>t.forEach(n=>n());if(e){const n=document.createElement("style");n.id="telegram-custom-styles",document.head.appendChild(n),t.push(m("set_custom_style",i=>{n.innerHTML=i}),()=>document.head.removeChild(n))}return C("iframe_ready",{reload_supported:!0}),s}function ws(){return typeof window>"u"}async function ys(){if(qt(window))return!0;try{return await _({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function fe(e){return e instanceof N}function Es(e,t){return fe(e)&&e.type===t}function ut(e,t){let s,n,i;return typeof e=="string"?s=e:(s=e.pathname===void 0?t:e.pathname,n=e.params,i=e.id),Object.freeze({id:i||(Math.random()*2**14|0).toString(16),pathname:s,params:n})}class ge{constructor(t,s,n=C){h(this,"history");h(this,"ee",new I);h(this,"attached",!1);h(this,"back",()=>this.go(-1));h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));if(this._index=s,this.postEvent=n,t.length===0)throw g(Rt,"History should not be empty.");if(s<0||s>=t.length)throw g(Tt,"Index should not be zero and higher or equal than history size.");this.history=t.map(i=>ut(i,""))}attach(){this.attached||(this.attached=!0,this.sync(),m("back_button_pressed",this.back))}get current(){return this.history[this.index]}detach(){this.attached=!1,q("back_button_pressed",this.back)}forward(){this.go(1)}go(t,s){const n=this.index+t,i=Math.min(Math.max(0,n),this.history.length-1);(n===i||s)&&this.replaceAndMove(i,this.history[i])}goTo(t,s){this.go(t-this.index,s)}get hasPrev(){return this.index>0}get hasNext(){return this.index!==this.history.length-1}get index(){return this._index}push(t){this.hasNext&&this.history.splice(this.index+1),this.replaceAndMove(this.index+1,ut(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,ut(t,this.current.pathname))}replaceAndMove(t,s){const n=t-this.index;if(!n&&this.current===s)return;const i=this.current;if(this.index!==t){const o=this._index;this._index=t,this.attached&&o>0!=t>0&&this.sync()}this.history[t]=s,this.ee.emit("change",{navigator:this,from:i,to:this.current,delta:n})}sync(){this.postEvent("web_app_setup_back_button",{is_visible:!!this.index})}}function pt({params:e,...t}){return{...e||{hash:"",search:""},...t}}function M(e,t){return e.startsWith(t)?e:`${t}${e}`}function B(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${M(e.search||"","?")}${M(e.hash||"","#")}`,"http://a")}function O(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=B(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function lt(e,t,s){let n,i;typeof e=="string"?n=e:(n=O(e),s=e.state,i=e.id);const{pathname:o,search:c,hash:a}=new URL(n,`http://a${M(t,"/")}`);return{id:i,pathname:o,params:{hash:a,search:c,state:s}}}async function L(e){return e===0?!0:Promise.race([new Promise(t=>{const s=z("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function vs(){if(window.history.length<=1||(window.history.pushState(null,""),await L(1-window.history.length)))return;let t=await L(-1);for(;t;)t=await L(-1)}function dt(e){return B(e).pathname}const be=0,_t=1,ft=2;class gt{constructor(t,s,{postEvent:n,hashMode:i="classic",base:o}={}){h(this,"navigator");h(this,"ee",new I);h(this,"hashMode");h(this,"base");h(this,"attached",!1);h(this,"onPopState",({state:t})=>{if(t===null)return this.push(this.parsePath(window.location.href));t===be?window.history.forward():t===_t&&this.back(),t===ft&&this.forward()});h(this,"onNavigatorChange",async({to:t,from:s,delta:n})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:n,from:pt(s),to:pt(t),navigator:this})});h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));this.navigator=new ge(t.map(c=>lt(c,"/")),s,n),this.navigator.on("change",this.onNavigatorChange),this.hashMode=i,this.base=dt(o||"")}async attach(){this.attached||(this.attached=!0,this.navigator.attach(),window.addEventListener("popstate",this.onPopState),await this.syncHistory())}back(){this.navigator.back()}detach(){this.attached=!1,this.navigator.detach(),window.removeEventListener("popstate",this.onPopState)}forward(){return this.navigator.forward()}get index(){return this.navigator.index}get id(){return this.navigator.current.id}go(t,s){return this.navigator.go(t,s)}goTo(t,s){this.navigator.goTo(t,s)}get hash(){return(this.navigator.current.params||{}).hash||""}get hasPrev(){return this.navigator.hasPrev}get hasNext(){return this.navigator.hasNext}get history(){return this.navigator.history.map(pt)}get path(){return O(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=B(t);return this.hashMode&&(s=B(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=lt(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=lt(t,this.path),{state:i=s}=n.params;this.navigator.replace({...n,params:{...n.params,state:i}})}renderPath(t){const s=(this.base.length===1?"":this.base)+M(O(t),"/");return this.hashMode?M(s.slice(1),this.hashMode==="classic"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await vs(),this.hasPrev&&this.hasNext?(window.history.replaceState(_t,""),window.history.pushState(t,"",s),window.history.pushState(ft,""),await L(-1)):this.hasPrev?(window.history.replaceState(_t,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(ft,""),await L(-1)):(window.history.replaceState(be,""),window.history.pushState(t,"",s)),window.addEventListener("popstate",this.onPopState)}get search(){return(this.navigator.current.params||{}).search||""}get state(){return(this.navigator.current.params||{}).state}}function me(e){e||(e={});const{href:t,hash:s}=window.location;let n=O(e.hashMode===null?t:s.includes("?")?s.slice(1):`?${s.slice(1)}`);const i=e.base?dt(e.base):void 0;if(i){if(!n.startsWith(i))throw g(Ct,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new gt([n],0,e)}function Ps(e){const t=e.match(/#(.+)/);return t?t[1]:null}function Ss(e,t){if(rt()){const s=sessionStorage.getItem(e);if(s)try{const{index:n,history:i}=JSON.parse(s);return new gt(i,n,t)}catch(n){console.error("Unable to restore hash navigator state.",n)}}return me(t)}function Rs(e,t){const s=Ss(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}return r.BackButton=Lt,r.BasicNavigator=ge,r.BiometryManager=Kt,r.BrowserNavigator=gt,r.ClosingBehavior=Zt,r.CloudStorage=se,r.ERR_INVALID_PATH_BASE=Ct,r.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=vt,r.ERR_METHOD_PARAMETER_UNSUPPORTED=yt,r.ERR_METHOD_UNSUPPORTED=wt,r.ERR_NAVIGATION_HISTORY_EMPTY=Rt,r.ERR_NAVIGATION_INDEX_INVALID=Tt,r.ERR_NAVIGATION_ITEM_INVALID=ve,r.ERR_PARSE=J,r.ERR_SSR_INIT=Pe,r.ERR_TIMED_OUT=Pt,r.ERR_UNEXPECTED_TYPE=St,r.ERR_UNKNOWN_ENV=Et,r.EventEmitter=I,r.HapticFeedback=ne,r.InitData=ie,r.Invoice=re,r.MainButton=oe,r.MiniApp=ce,r.Popup=he,r.QRScanner=ue,r.SDKError=N,r.SettingsButton=pe,r.ThemeParams=le,r.Utils=de,r.Viewport=_e,r.array=te,r.bindMiniAppCSSVars=fs,r.bindThemeParamsCSSVars=gs,r.bindViewportCSSVars=bs,r.boolean=y,r.captureSameReq=X,r.classNames=W,r.compareVersions=Nt,r.createBrowserNavigatorFromLocation=me,r.createPostEvent=Mt,r.createSafeURL=B,r.date=nt,r.getHash=Ps,r.getPathname=dt,r.initBackButton=ze,r.initBiometryManager=Je,r.initClosingBehavior=Qe,r.initCloudStorage=Xe,r.initHapticFeedback=Ze,r.initInitData=ts,r.initInvoice=ss,r.initMainButton=ns,r.initMiniApp=os,r.initNavigator=Rs,r.initPopup=cs,r.initQRScanner=hs,r.initSettingsButton=us,r.initThemeParams=ps,r.initUtils=ds,r.initViewport=_s,r.initWeb=ms,r.invokeCustomMethod=A,r.isColorDark=tt,r.isIframe=kt,r.isPageReload=rt,r.isRGB=U,r.isRGBShort=It,r.isSDKError=fe,r.isSDKErrorOfType=Es,r.isSSR=ws,r.isTMA=ys,r.json=d,r.mergeClassNames=Me,r.number=P,r.off=q,r.on=m,r.parseInitData=es,r.parseLaunchParams=it,r.parseThemeParams=ct,r.postEvent=C,r.request=_,r.requestBiometryInfo=Xt,r.requestThemeParams=ls,r.requestViewport=ht,r.retrieveLaunchParams=Qt,r.rgb=K,r.searchParams=G,r.serializeLaunchParams=Jt,r.serializeThemeParams=zt,r.setCSSVar=v,r.setDebug=ye,r.setTargetOrigin=Ve,r.string=u,r.subscribe=bt,r.supports=S,r.targetOrigin=Vt,r.toRGB=Y,r.unsubscribe=w,r.urlToPath=O,r.withTimeout=Z,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),r}({});
1
+ var Cn=Object.defineProperty;var An=(r,b,m)=>b in r?Cn(r,b,{enumerable:!0,configurable:!0,writable:!0,value:m}):r[b]=m;var h=(r,b,m)=>(An(r,typeof b!="symbol"?b+"":b,m),m);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(r){"use strict";function b(e,t){let n;const s=()=>{n!==void 0&&t&&t(n),n=void 0};return[()=>n===void 0?n=e(s):n,s]}function m(e){const t=W(),{count:n}=t;t.unsubscribe(e),n&&!t.count&&Me()}function yt(e){return W().subscribe(e),()=>m(e)}class Se{constructor(t,n={}){this.scope=t,this.options=n}print(t,...n){const s=new Date,i=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s),{textColor:o,bgColor:c}=this.options,a="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${a};background-color: lightblue;color:black`,"",`${a};${o?`color:${o};`:""}${c?`background-color:${c}`:""}`,...n)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const z=new Se("SDK",{bgColor:"forestgreen",textColor:"white"});let F=!1;const Et=({name:e,payload:t})=>{z.log("Event received:",t?{name:e,payload:t}:{name:e})};function Re(e){F!==e&&(F=e,e?yt(Et):m(Et))}function Te(...e){F&&z.log(...e)}class R{constructor(){h(this,"listeners",new Map);h(this,"listenersCount",0);h(this,"subscribeListeners",[])}clear(){this.listeners.clear(),this.subscribeListeners=[]}get count(){return this.listenersCount+this.subscribeListeners.length}emit(t,...n){this.subscribeListeners.forEach(i=>i({event:t,args:n})),(this.listeners.get(t)||[]).forEach(([i,o])=>{i(...n),o&&this.off(t,i)})}on(t,n,s){let i=this.listeners.get(t);return i||this.listeners.set(t,i=[]),i.push([n,s]),this.listenersCount+=1,()=>this.off(t,n)}off(t,n){const s=this.listeners.get(t)||[];for(let i=0;i<s.length;i+=1)if(n===s[i][0]){s.splice(i,1),this.listenersCount-=1;return}}subscribe(t){return this.subscribeListeners.push(t),()=>this.unsubscribe(t)}unsubscribe(t){for(let n=0;n<this.subscribeListeners.length;n+=1)if(this.subscribeListeners[n]===t){this.subscribeListeners.splice(n,1);return}}}function J(e,t,n){return window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)}function vt(...e){let t=!1;const n=[...e];return[s=>!t&&n.push(s),()=>{t||(t=!0,n.forEach(s=>s()))},t]}class N extends Error{constructor(t,n,s){super(n,{cause:s}),this.type=t,Object.setPrototypeOf(this,N.prototype)}}function g(e,t,n){return new N(e,t,n)}const Pt="ERR_METHOD_UNSUPPORTED",St="ERR_METHOD_PARAMETER_UNSUPPORTED",Rt="ERR_UNKNOWN_ENV",Tt="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Ct="ERR_TIMED_OUT",At="ERR_UNEXPECTED_TYPE",Q="ERR_PARSE",It="ERR_NAVIGATION_LIST_EMPTY",Nt="ERR_NAVIGATION_CURSOR_INVALID",Ce="ERR_NAVIGATION_ITEM_INVALID",Ae="ERR_SSR_INIT",qt="ERR_INVALID_PATH_BASE";function T(){return g(At,"Value has unexpected type")}class ${constructor(t,n,s){this.parser=t,this.isOptional=n,this.type=s}parse(t){if(!(this.isOptional&&t===void 0))try{return this.parser(t)}catch(n){throw g(Q,`Unable to parse value${this.type?` as ${this.type}`:""}`,n)}}optional(){return this.isOptional=!0,this}}function C(e,t){return()=>new $(e,!1,t)}const y=C(e=>{if(typeof e=="boolean")return e;const t=String(e);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;throw T()},"boolean");function Dt(e,t){const n={};for(const s in e){const i=e[s];if(!i)continue;let o,c;if(typeof i=="function"||"parse"in i)o=s,c=typeof i=="function"?i:i.parse.bind(i);else{const{type:a}=i;o=i.from||s,c=typeof a=="function"?a:a.parse.bind(a)}try{const a=c(t(o));a!==void 0&&(n[s]=a)}catch(a){throw g(Q,`Unable to parse field "${s}"`,a)}}return n}function Y(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw T();return t}function d(e,t){return new $(n=>{const s=Y(n);return Dt(e,i=>s[i])},!1,t)}const P=C(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw T()},"number");function U(e){return/^#[\da-f]{6}$/i.test(e)}function kt(e){return/^#[\da-f]{3}$/i.test(e)}function K(e){const t=e.replace(/\s/g,"").toLowerCase();if(U(t))return t;if(kt(t)){let s="#";for(let i=0;i<3;i+=1)s+=t[1+i].repeat(2);return s}const n=t.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||t.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(!n)throw new Error(`Value "${e}" does not satisfy any of known RGB formats.`);return n.slice(1).reduce((s,i)=>{const o=parseInt(i,10).toString(16);return s+(o.length===1?"0":"")+o},"#")}const u=C(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw T()},"string"),X=C(e=>K(u().parse(e)),"rgb");function Mt(e){return d({eventType:u(),eventData:t=>t}).parse(e)}function Ie(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function Z(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Ne(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((n,s,i)=>{if(s===i.length-1){t[n]=Z;return}n in t||(t[n]={}),t=t[n]})})}const qe={clipboard_text_received:d({req_id:u(),data:e=>e===null?e:u().optional().parse(e)}),custom_method_invoked:d({req_id:u(),result:e=>e,error:u().optional()}),invoice_closed:d({slug:u(),status:u()}),phone_requested:d({status:u()}),popup_closed:{parse(e){return d({button_id:t=>t==null?void 0:u().parse(t)}).parse(e??{})}},qr_text_received:d({data:u().optional()}),theme_changed:d({theme_params:e=>{const t=X().optional();return Object.entries(Y(e)).reduce((n,[s,i])=>(n[s]=t.parse(i),n),{})}}),viewport_changed:d({height:P(),width:e=>e==null?window.innerWidth:P().parse(e),is_state_stable:y(),is_expanded:y()}),write_access_requested:d({status:u()})};function De(){const e=new R,t=new R;t.subscribe(s=>{e.emit("event",{name:s.event,payload:s.args[0]})}),Ne();const[,n]=vt(Ie,J("resize",()=>{t.emit("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),J("message",s=>{if(s.source!==window.parent)return;let i;try{i=Mt(s.data)}catch{return}const{eventType:o,eventData:c}=i,a=qe[o];try{const p=a?a.parse(c):c;t.emit(...p?[o,p]:[o])}catch(p){z.error(`An error occurred processing the "${o}" event from the Telegram application. Please, file an issue here: https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose`,i,p)}}),()=>e.clear(),()=>t.clear());return[{on:t.on.bind(t),off:t.off.bind(t),subscribe(s){return e.on("event",s)},unsubscribe(s){e.off("event",s)},get count(){return t.count+e.count}},n]}const[ke,Me]=b(e=>{const[t,n]=De(),s=t.off.bind(t);return t.off=(i,o)=>{const{count:c}=t;s(i,o),c&&!t.count&&e()},[t,n]},([,e])=>e());function W(){return ke()[0]}function q(e,t){W().off(e,t)}function w(e,t,n){return W().on(e,t,n)}function D(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Vt(e,t){const n=e.split("."),s=t.split("."),i=Math.max(n.length,s.length);for(let o=0;o<i;o+=1){const c=parseInt(n[o]||"0",10),a=parseInt(s[o]||"0",10);if(c!==a)return c>a?1:-1}return 0}function E(e,t){return Vt(e,t)<=0}function S(e,t,n){if(typeof n=="string"){if(e==="web_app_open_link"&&t==="try_instant_view")return E("6.4",n);if(e==="web_app_set_header_color"&&t==="color")return E("6.9",n)}switch(e){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 E("6.1",t);case"web_app_open_popup":return E("6.2",t);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return E("6.4",t);case"web_app_switch_inline_query":return E("6.7",t);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return E("6.9",t);case"web_app_setup_settings_button":return E("6.10",t);case"web_app_biometry_get_info":case"web_app_biometry_open_settings":case"web_app_biometry_request_access":case"web_app_biometry_request_auth":case"web_app_biometry_update_token":return E("7.2",t);default:return["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"].includes(e)}}function Bt(e){return"external"in e&&D(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Ot(e){return"TelegramWebviewProxy"in e&&D(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function tt(){try{return window.self!==window.top}catch{return!0}}let Lt="https://web.telegram.org";function Ve(e){Lt=e}function $t(){return Lt}function A(e,t,n){let s={},i;t===void 0&&n===void 0?s={}:t!==void 0&&n!==void 0?(s=n,i=t):t!==void 0&&("targetOrigin"in t?s=t:i=t);const{targetOrigin:o=$t()}=s;if(Te("Posting event:",i?{event:e,data:i}:{event:e}),tt()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),o);return}if(Bt(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Ot(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw g(Rt,"Unable to determine current environment and possible way to send event. You are probably trying to use Mini Apps method outside of Telegram application environment.")}function Ut(e){return(t,n)=>{if(!S(t,e))throw g(Pt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(D(n)){let s;if(t==="web_app_open_link"&&"try_instant_view"in n?s="try_instant_view":t==="web_app_set_header_color"&&"color"in n&&(s="color"),s&&!S(t,s,e))throw g(St,`Parameter "${s}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return A(t,n)}}function et(e){return({req_id:t})=>t===e}function Wt(e){return g(Ct,`Timeout reached: ${e}ms`)}function nt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((n,s)=>{setTimeout(()=>{s(Wt(t))},t)})])}async function _(e){let t;const n=new Promise(l=>{t=l}),{method:s,event:i,capture:o,postEvent:c=A,timeout:a}=e,p=(Array.isArray(i)?i:[i]).map(l=>w(l,j=>(!o||o(j))&&t(j)));try{return c(s,e.params),await(a?nt(n,a):n)}finally{p.forEach(l=>l())}}async function I(e,t,n,s={}){const{result:i,error:o}=await _({...s,method:"web_app_invoke_custom_method",event:"custom_method_invoked",params:{method:e,params:t,req_id:n},capture:et(n)});if(o)throw g(Tt,o);return i}function H(...e){return e.map(t=>{if(typeof t=="string")return t;if(D(t))return H(Object.entries(t).map(n=>n[1]&&n[0]));if(Array.isArray(t))return H(...t)}).filter(Boolean).join(" ")}function Be(...e){return e.reduce((t,n)=>(D(n)&&Object.entries(n).forEach(([s,i])=>{const o=H(t[s],i);o.length&&(t[s]=o)}),t),{})}function st(e){const t=K(e);return Math.sqrt([.299,.587,.114].reduce((n,s,i)=>{const o=parseInt(t.slice(1+i*2,1+(i+1)*2),16);return n+o*o*s},0))<120}class Oe{constructor(t){h(this,"ee",new R);h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));this.state=t}clone(){return{...this.state}}set(t,n){Object.entries(typeof t=="string"?{[t]:n}:t).reduce((i,[o,c])=>this.state[o]===c||c===void 0?i:(this.state[o]=c,this.ee.emit(`change:${o}`,c),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class it{constructor(t){h(this,"state");h(this,"get");h(this,"set");h(this,"clone");this.state=new Oe(t),this.set=this.state.set.bind(this.state),this.get=this.state.get.bind(this.state),this.clone=this.state.clone.bind(this.state)}}function Ht(e,t){return n=>S(t[n],e)}class rt extends it{constructor(n,s,i){super(n);h(this,"supports");this.supports=Ht(s,i)}}class xt extends rt{constructor(n,s,i){super({isVisible:n},s,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"});h(this,"on",(n,s)=>n==="click"?w("back_button_pressed",s):this.state.on(n,s));h(this,"off",(n,s)=>n==="click"?q("back_button_pressed",s):this.state.off(n,s));this.postEvent=i}set isVisible(n){this.set("isVisible",n),this.postEvent("web_app_setup_back_button",{is_visible:n})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const ot=C(e=>e instanceof Date?e:new Date(P().parse(e)*1e3),"Date");function x(e,t){return new $(n=>{if(typeof n!="string"&&!(n instanceof URLSearchParams))throw T();const s=typeof n=="string"?new URLSearchParams(n):n;return Dt(e,i=>{const o=s.get(i);return o===null?void 0:o})},!1,t)}const Le=d({id:P(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat").optional(),Gt=d({addedToAttachmentMenu:{type:y().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:y().optional(),from:"allows_write_to_pm"},firstName:{type:u(),from:"first_name"},id:P(),isBot:{type:y().optional(),from:"is_bot"},isPremium:{type:y().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").optional();function jt(){return x({authDate:{type:ot(),from:"auth_date"},canSendAfter:{type:P().optional(),from:"can_send_after"},chat:Le,chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:Gt,startParam:{type:u().optional(),from:"start_param"},user:Gt},"InitData")}function $e(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Ue(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const zt=C(e=>{const t=X().optional();return Object.entries(Y(e)).reduce((n,[s,i])=>(n[$e(s)]=t.parse(i),n),{})},"ThemeParams");function G(e){return x({botInline:{type:y().optional(),from:"tgWebAppBotInline"},initData:{type:jt().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:y().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:zt(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}}).parse(e)}function Ft(e){return G(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function We(){return Ft(window.location.href)}function Jt(){return performance.getEntriesByType("navigation")[0]}function He(){const e=Jt();if(!e)throw new Error("Unable to get first navigation entry.");return Ft(e.name)}function Qt(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function Yt(e,t){sessionStorage.setItem(Qt(e),JSON.stringify(t))}function Kt(e){const t=sessionStorage.getItem(Qt(e));try{return t?JSON.parse(t):void 0}catch{}}function xe(){return G(Kt("launchParams")||"")}function at(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,n])=>[Ue(t),n])))}function Xt(e){const{initDataRaw:t,themeParams:n,platform:s,version:i,showSettings:o,startParam:c,botInline:a}=e,p=new URLSearchParams;return p.set("tgWebAppPlatform",s),p.set("tgWebAppThemeParams",at(n)),p.set("tgWebAppVersion",i),t&&p.set("tgWebAppData",t),c&&p.set("tgWebAppStartParam",c),typeof o=="boolean"&&p.set("tgWebAppShowSettings",o?"1":"0"),typeof a=="boolean"&&p.set("tgWebAppBotInline",a?"1":"0"),p.toString()}function Zt(e){Yt("launchParams",Xt(e))}function te(){for(const e of[We,He,xe])try{const t=e();return Zt(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function ct(){const e=Jt();return!!(e&&e.type==="reload")}function Ge(){let e=0;return()=>(e+=1).toString()}const[je]=b(Ge);function f(e,t){return()=>{const n=te(),s={...n,postEvent:Ut(n.version),createRequestId:je()};if(typeof e=="function")return e(s);const[i,o,c]=vt(),a=t({...s,state:ct()?Kt(e):void 0,addCleanup:i}),p=l=>(c||i(l.on("change",j=>{Yt(e,j)})),l);return[a instanceof Promise?a.then(p):p(a),o]}}const ze=f("backButton",({postEvent:e,version:t,state:n={isVisible:!1}})=>new xt(n.isVisible,t,e));class k extends rt{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}function ee(e){const t=e.available?e:{available:!1,device_id:"",token_saved:!1,access_requested:!1,access_granted:!1,type:""};return{available:!0,type:t.type,deviceId:t.device_id,tokenSaved:t.token_saved,accessRequested:t.access_requested,accessGranted:t.access_granted}}class ne extends k{constructor({postEvent:n,version:s,...i}){super(i,s,{auth:"web_app_biometry_request_auth",openSettings:"web_app_biometry_open_settings",requestAccess:"web_app_biometry_request_access",updateToken:"web_app_biometry_update_token"});h(this,"postEvent");h(this,"authPromise");h(this,"accessPromise");this.postEvent=n}get available(){return this.get("available")}get accessGranted(){return this.get("accessGranted")}get accessRequested(){return this.get("accessRequested")}async authenticate({reason:n,...s}){return this.authPromise||(this.authPromise=_({...s,method:"web_app_biometry_request_auth",event:"biometry_auth_requested",postEvent:this.postEvent,params:{reason:(n||"").trim()}}).then(({token:i})=>i).finally(()=>this.authPromise=void 0)),this.authPromise}get deviceId(){return this.get("deviceId")}openSettings(){this.postEvent("web_app_biometry_open_settings")}requestAccess({reason:n,...s}={}){return this.accessPromise||(this.accessPromise=_({...s,postEvent:this.postEvent,method:"web_app_biometry_request_access",event:"biometry_info_received",params:{reason:n||""}}).then(i=>{const o=ee(i);return this.set(o),o.accessGranted}).finally(()=>this.accessPromise=void 0)),this.accessPromise}get biometryType(){return this.get("biometryType")}get tokenSaved(){return this.get("tokenSaved")}async updateToken({token:n,...s}={}){return["removed","updated"].includes((await _({...s,postEvent:this.postEvent,method:"web_app_biometry_update_token",event:"biometry_token_updated",params:{token:n||""}})).status)}}async function se(e){return ee(await _({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const Fe=f("biometryManager",async({postEvent:e,version:t,state:n})=>new ne({...n||S("web_app_biometry_get_info",t)?n||await se({timeout:1e3}):{available:!1,accessGranted:!1,accessRequested:!1,tokenSaved:!1,deviceId:""},version:t,postEvent:e}));class ht extends it{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}class ie extends ht{constructor(t,n){super({isConfirmationNeeded:t}),this.postEvent=n}set isConfirmationNeeded(t){this.set("isConfirmationNeeded",t),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:t})}get isConfirmationNeeded(){return this.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}const Je=f("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new ie(t.isConfirmationNeeded,e));class ut{constructor(t,n){h(this,"supports");this.supports=Ht(t,n)}}function Qe(e){if(Array.isArray(e))return e;if(typeof e=="string")try{const t=JSON.parse(e);if(Array.isArray(t))return t}catch{}throw T()}class Ye extends ${constructor(n,s,i){super(Qe,s,i);h(this,"itemParser");this.itemParser=typeof n=="function"?n:n.parse.bind(n)}parse(n){const s=super.parse(n);return s===void 0?s:s.map(this.itemParser)}of(n){return this.itemParser=typeof n=="function"?n:n.parse.bind(n),this}}function re(e){return new Ye(t=>t,!1,e)}function oe(e,t){return Object.fromEntries(e.map(n=>[n,t]))}class ae extends ut{constructor(t,n,s){super(t,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"}),this.createRequestId=n,this.postEvent=s}async delete(t,n={}){const s=Array.isArray(t)?t:[t];s.length&&await I("deleteStorageValues",{keys:s},this.createRequestId(),{...n,postEvent:this.postEvent})}async getKeys(t={}){return re().of(u()).parse(await I("getStorageKeys",{},this.createRequestId(),{...t,postEvent:this.postEvent}))}async get(t,n={}){const s=Array.isArray(t)?t:[t];if(!s.length)return oe(s,"");const i=await I("getStorageValues",{keys:s},this.createRequestId(),{...n,postEvent:this.postEvent}),o=d(oe(s,u()),"CloudStorageData").parse(i);return Array.isArray(t)?o:o[t]}async set(t,n,s={}){await I("saveStorageValue",{key:t,value:n},this.createRequestId(),{...s,postEvent:this.postEvent})}}const Ke=f(({createRequestId:e,postEvent:t,version:n})=>new ae(n,e,t));class ce extends ut{constructor(t,n){super(t,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"}),this.postEvent=n}impactOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:t})}notificationOccurred(t){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:t})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}const Xe=f(({version:e,postEvent:t})=>new ce(e,t));class he{constructor(t){this.initData=t}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:t}=this;return t?new Date(this.authDate.getTime()+t*1e3):void 0}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}}const Ze=f(({initData:e})=>e?new he(e):void 0);function tn(e){return jt().parse(e)}class ue extends k{constructor(t,n,s){super({isOpened:t},n,{open:"web_app_open_invoice"}),this.postEvent=s}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t,n){if(this.isOpened)throw new Error("Invoice is already opened");let s;if(!n)s=t;else{const{hostname:i,pathname:o}=new URL(t,window.location.href);if(i!=="t.me")throw new Error(`Incorrect hostname: ${i}`);const c=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!c)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,s]=c}this.isOpened=!0;try{return(await _({method:"web_app_open_invoice",event:"invoice_closed",params:{slug:s},postEvent:this.postEvent,capture(o){return s===o.slug}})).status}finally{this.isOpened=!1}}}const en=f(({version:e,postEvent:t})=>new ue(!1,e,t));class pe extends it{constructor({postEvent:n,...s}){super(s);h(this,"postEvent");h(this,"on",(n,s)=>n==="click"?w("main_button_pressed",s):this.state.on(n,s));h(this,"off",(n,s)=>n==="click"?q("main_button_pressed",s):this.state.off(n,s));this.postEvent=n}get bgColor(){return this.get("bgColor")}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.bgColor,text_color:this.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}set isEnabled(n){this.setParams({isEnabled:n})}get isEnabled(){return this.get("isEnabled")}set isLoaderVisible(n){this.setParams({isLoaderVisible:n})}get isLoaderVisible(){return this.get("isLoaderVisible")}set isVisible(n){this.setParams({isVisible:n})}get isVisible(){return this.get("isVisible")}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(n){return this.setParams({text:n})}setTextColor(n){return this.setParams({textColor:n})}setBgColor(n){return this.setParams({bgColor:n})}setParams(n){return this.set(n),this.commit(),this}get text(){return this.get("text")}get textColor(){return this.get("textColor")}}const nn=f("mainButton",({postEvent:e,themeParams:t,state:n={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",bgColor:t.buttonColor||"#000000"}})=>new pe({...n,postEvent:e}));function sn(){return x({contact:d({userId:{type:P(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:ot(),from:"auth_date"},hash:u()},"RequestedContact")}function le(e,t){return n=>{const[s,i]=t[n];return S(s,i,e)}}function rn(e){return new Promise(t=>{setTimeout(t,e)})}class de extends k{constructor({postEvent:n,createRequestId:s,version:i,botInline:o,...c}){super(c,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"});h(this,"botInline");h(this,"postEvent");h(this,"createRequestId");h(this,"requestPhoneAccessPromise");h(this,"requestWriteAccessPromise");h(this,"supportsParam");this.createRequestId=s,this.postEvent=n,this.botInline=o;const a=this.supports.bind(this);this.supports=p=>a(p)?p!=="switchInlineQuery"||o:!1,this.supportsParam=le(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:n=1e4}={}){return sn().parse(await I("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:n}))}get bgColor(){return this.get("bgColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return st(this.bgColor)}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:n=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const i=Date.now()+n;let o=50;return nt(async()=>{for(;Date.now()<i;){try{return await this.getRequestedContact()}catch{}await rn(o),o+=50}throw Wt(n)},n)}async requestPhoneAccess(n={}){return this.requestPhoneAccessPromise||(this.requestPhoneAccessPromise=_({...n,method:"web_app_request_phone",event:"phone_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestPhoneAccessPromise=void 0)),this.requestPhoneAccessPromise}async requestWriteAccess(n={}){return this.requestWriteAccessPromise||(this.requestWriteAccessPromise=_({...n,method:"web_app_request_write_access",event:"write_access_requested",postEvent:this.postEvent}).then(({status:s})=>s).finally(()=>this.requestWriteAccessPromise=void 0)),this.requestWriteAccessPromise}sendData(n){const{size:s}=new Blob([n]);if(!s||s>4096)throw new Error(`Passed data has incorrect size: ${s}`);this.postEvent("web_app_data_send",{data:n})}setHeaderColor(n){this.postEvent("web_app_set_header_color",U(n)?{color:n}:{color_key:n}),this.set("headerColor",n)}setBgColor(n){this.postEvent("web_app_set_background_color",{color:n}),this.set("bgColor",n)}switchInlineQuery(n,s=[]){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:n,chat_types:s})}}const on=f("miniApp",({themeParams:e,botInline:t=!1,state:n={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...s})=>new de({...s,...n,botInline:t}));function an(e){const t=e.message.trim(),n=(e.title||"").trim(),s=e.buttons||[];let i;if(n.length>64)throw new Error(`Title has incorrect size: ${n.length}`);if(!t.length||t.length>256)throw new Error(`Message has incorrect size: ${t.length}`);if(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length?i=s.map(o=>{const{id:c=""}=o;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(!o.type||o.type==="default"||o.type==="destructive"){const a=o.text.trim();if(!a.length||a.length>64){const p=o.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${o.text.length}`)}return{...o,text:a,id:c}}return{...o,id:c}}):i=[{type:"close",id:""}],{title:n,message:t,buttons:i}}class _e extends k{constructor(t,n,s){super({isOpened:t},n,{open:"web_app_open_popup"}),this.postEvent=s}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("Popup is already opened.");this.isOpened=!0;try{const{button_id:n=null}=await _({event:"popup_closed",method:"web_app_open_popup",postEvent:this.postEvent,params:an(t)});return n}finally{this.isOpened=!1}}}const cn=f(({postEvent:e,version:t})=>new _e(!1,t,e));class fe extends k{constructor(t,n,s){super({isOpened:t},n,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"}),this.postEvent=s}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(t){this.set("isOpened",t)}get isOpened(){return this.get("isOpened")}async open(t){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{return(await _({method:"web_app_open_scan_qr_popup",event:["qr_text_received","scan_qr_popup_closed"],postEvent:this.postEvent,params:{text:t}})||{}).data||null}finally{this.isOpened=!1}}}const hn=f(({version:e,postEvent:t})=>new fe(!1,e,t));class ge extends rt{constructor(n,s,i){super({isVisible:n},s,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"});h(this,"on",(n,s)=>n==="click"?w("settings_button_pressed",s):this.state.on(n,s));h(this,"off",(n,s)=>n==="click"?q("settings_button_pressed",s):this.state.off(n,s));this.postEvent=i}set isVisible(n){this.set("isVisible",n),this.postEvent("web_app_setup_settings_button",{is_visible:n})}get isVisible(){return this.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}const un=f("settingsButton",({version:e,postEvent:t,state:n={isVisible:!1}})=>new ge(n.isVisible,e,t));function pt(e){return zt().parse(e)}class be extends ht{get accentTextColor(){return this.get("accentTextColor")}get bgColor(){return this.get("bgColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}getState(){return this.clone()}get headerBgColor(){return this.get("headerBgColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.bgColor||st(this.bgColor)}get linkColor(){return this.get("linkColor")}get secondaryBgColor(){return this.get("secondaryBgColor")}get sectionBgColor(){return this.get("sectionBgColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return w("theme_changed",t=>{this.set(pt(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const pn=f("themeParams",({themeParams:e,state:t=e,addCleanup:n})=>{const s=new be(t);return n(s.listen()),s});function ln(e={}){return _({...e,method:"web_app_request_theme",event:"theme_changed"}).then(pt)}class we extends ut{constructor(n,s,i){super(n,{readTextFromClipboard:"web_app_read_text_from_clipboard"});h(this,"supportsParam");this.version=n,this.createRequestId=s,this.postEvent=i,this.supportsParam=le(n,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(n,s){const i=new URL(n,window.location.href).toString();if(!S("web_app_open_link",this.version)){window.open(i,"_blank");return}this.postEvent("web_app_open_link",{url:i,...typeof s=="boolean"?{try_instant_view:s}:{}})}openTelegramLink(n){const{hostname:s,pathname:i,search:o}=new URL(n,window.location.href);if(s!=="t.me")throw new Error(`URL has not allowed hostname: ${s}. Only "t.me" is allowed`);if(!S("web_app_open_tg_link",this.version)){window.location.href=n;return}this.postEvent("web_app_open_tg_link",{path_full:i+o})}async readTextFromClipboard(){const n=this.createRequestId(),{data:s=null}=await _({method:"web_app_read_text_from_clipboard",event:"clipboard_text_received",postEvent:this.postEvent,params:{req_id:n},capture:et(n)});return s}}const dn=f(({version:e,postEvent:t,createRequestId:n})=>new we(e,n,t));async function lt(e={}){const{is_expanded:t,is_state_stable:n,...s}=await _({...e,method:"web_app_request_viewport",event:"viewport_changed"});return{...s,isExpanded:t,isStateStable:n}}function M(e){return e<0?0:e}class me extends ht{constructor({postEvent:n,stableHeight:s,height:i,width:o,isExpanded:c}){super({height:M(i),isExpanded:c,stableHeight:M(s),width:M(o)});h(this,"postEvent");this.postEvent=n}async sync(n){const{isStateStable:s,...i}=await lt(n);this.set({...i,stableHeight:s?i.height:this.get("stableHeight")})}get height(){return this.get("height")}get stableHeight(){return this.get("stableHeight")}listen(){return w("viewport_changed",n=>{const{height:s,width:i,is_expanded:o,is_state_stable:c}=n,a=M(s);this.set({height:a,isExpanded:o,width:M(i),...c?{stableHeight:a}:{}})})}get isExpanded(){return this.get("isExpanded")}get width(){return this.get("width")}expand(){this.postEvent("web_app_expand"),this.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}const _n=f("viewport",async({state:e,platform:t,postEvent:n,addCleanup:s})=>{let i=!1,o=0,c=0,a=0;if(e)i=e.isExpanded,o=e.height,c=e.width,a=e.stableHeight;else if(["macos","tdesktop","unigram","webk","weba","web"].includes(t))i=!0,o=window.innerHeight,c=window.innerWidth,a=window.innerHeight;else{const l=await lt({timeout:1e3,postEvent:n});i=l.isExpanded,o=l.height,c=l.width,a=l.isStateStable?o:0}const p=new me({postEvent:n,height:o,width:c,stableHeight:a,isExpanded:i});return s(p.listen()),p});function v(e,t){document.documentElement.style.setProperty(e,t)}function fn(e,t,n){n||(n=a=>`--tg-${a}-color`);const s=n("header"),i=n("bg"),o=()=>{const{headerColor:a}=e;if(U(a))v(s,a);else{const{bgColor:p,secondaryBgColor:l}=t;a==="bg_color"&&p?v(s,p):a==="secondary_bg_color"&&l&&v(s,l)}v(i,e.bgColor)},c=[t.on("change",o),e.on("change",o)];return o(),()=>c.forEach(a=>a())}function gn(e,t){t||(t=s=>`--tg-theme-${s.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`);const n=()=>{Object.entries(e.getState()).forEach(([s,i])=>{i&&v(t(s),i)})};return n(),e.on("change",n)}function bn(e,t){t||(t=l=>`--tg-viewport-${l}`);const[n,s,i]=["height","width","stable-height"].map(l=>t(l)),o=()=>v(n,`${e.height}px`),c=()=>v(s,`${e.width}px`),a=()=>v(i,`${e.stableHeight}px`),p=[e.on("change:height",o),e.on("change:width",c),e.on("change:stableHeight",a)];return o(),c(),a(),()=>p.forEach(l=>l())}function wn(e=!0){const t=[w("reload_iframe",()=>{A("iframe_will_reload"),window.location.reload()})],n=()=>t.forEach(s=>s());if(e){const s=document.createElement("style");s.id="telegram-custom-styles",document.head.appendChild(s),t.push(w("set_custom_style",i=>{s.innerHTML=i}),()=>document.head.removeChild(s))}return A("iframe_ready",{reload_supported:!0}),n}function mn(){return typeof window>"u"}async function yn(){if(Ot(window))return!0;try{return await _({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function En(e){const t=typeof e=="string"?G(e):e;Zt(t);function n(i){if(typeof i=="string")try{const{eventType:o}=Mt(i);o==="web_app_request_theme"&&Z("theme_changed",{theme_params:JSON.parse(at(t.themeParams))}),o==="web_app_request_viewport"&&Z("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}catch{}}if(tt()){const i=window.parent.postMessage.bind(window.parent);window.parent.postMessage=o=>{n(o),i(o)};return}if(Bt(window)){const i=window.external.notify.bind(window.external);window.external.notify=o=>{n(o),i(o)};return}const s=window.TelegramWebviewProxy;window.TelegramWebviewProxy={...s||{},postEvent(...i){n(JSON.stringify({eventType:i[0],eventData:i[1]})),s&&s.postEvent(...i)}}}function ye(e){return e instanceof N}function vn(e,t){return ye(e)&&e.type===t}function dt(e,t){let n,s,i;return typeof e=="string"?n=e:(n=e.pathname===void 0?t:e.pathname,s=e.params,i=e.id),Object.freeze({id:i||(Math.random()*2**14|0).toString(16),pathname:n,params:s})}class Ee{constructor(t,n,s=A){h(this,"history");h(this,"ee",new R);h(this,"attached",!1);h(this,"back",()=>this.go(-1));h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));if(this._index=n,this.postEvent=s,t.length===0)throw g(It,"History should not be empty.");if(n<0||n>=t.length)throw g(Nt,"Index should not be zero and higher or equal than history size.");this.history=t.map(i=>dt(i,""))}attach(){this.attached||(this.attached=!0,this.sync(),w("back_button_pressed",this.back))}get current(){return this.history[this.index]}detach(){this.attached=!1,q("back_button_pressed",this.back)}forward(){this.go(1)}go(t,n){const s=this.index+t,i=Math.min(Math.max(0,s),this.history.length-1);(s===i||n)&&this.replaceAndMove(i,this.history[i])}goTo(t,n){this.go(t-this.index,n)}get hasPrev(){return this.index>0}get hasNext(){return this.index!==this.history.length-1}get index(){return this._index}push(t){this.hasNext&&this.history.splice(this.index+1),this.replaceAndMove(this.index+1,dt(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,dt(t,this.current.pathname))}replaceAndMove(t,n){const s=t-this.index;if(!s&&this.current===n)return;const i=this.current;if(this.index!==t){const o=this._index;this._index=t,this.attached&&o>0!=t>0&&this.sync()}this.history[t]=n,this.ee.emit("change",{navigator:this,from:i,to:this.current,delta:s})}sync(){this.postEvent("web_app_setup_back_button",{is_visible:!!this.index})}}function _t({params:e,...t}){return{...e||{hash:"",search:""},...t}}function V(e,t){return e.startsWith(t)?e:`${t}${e}`}function B(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${V(e.search||"","?")}${V(e.hash||"","#")}`,"http://a")}function O(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),n=B(e);return`${t?n.pathname:n.pathname.slice(1)}${n.search}${n.hash}`}function ft(e,t,n){let s,i;typeof e=="string"?s=e:(s=O(e),n=e.state,i=e.id);const{pathname:o,search:c,hash:a}=new URL(s,`http://a${V(t,"/")}`);return{id:i,pathname:o,params:{hash:a,search:c,state:n}}}async function L(e){return e===0?!0:Promise.race([new Promise(t=>{const n=J("popstate",()=>{n(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function Pn(){if(window.history.length<=1||(window.history.pushState(null,""),await L(1-window.history.length)))return;let t=await L(-1);for(;t;)t=await L(-1)}function gt(e){return B(e).pathname}const ve=0,bt=1,wt=2;class mt{constructor(t,n,{postEvent:s,hashMode:i="classic",base:o}={}){h(this,"navigator");h(this,"ee",new R);h(this,"hashMode");h(this,"base");h(this,"attached",!1);h(this,"onPopState",({state:t})=>{if(t===null)return this.push(this.parsePath(window.location.href));t===ve?window.history.forward():t===bt&&this.back(),t===wt&&this.forward()});h(this,"onNavigatorChange",async({to:t,from:n,delta:s})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:s,from:_t(n),to:_t(t),navigator:this})});h(this,"on",this.ee.on.bind(this.ee));h(this,"off",this.ee.off.bind(this.ee));this.navigator=new Ee(t.map(c=>ft(c,"/")),n,s),this.navigator.on("change",this.onNavigatorChange),this.hashMode=i,this.base=gt(o||"")}async attach(){this.attached||(this.attached=!0,this.navigator.attach(),window.addEventListener("popstate",this.onPopState),await this.syncHistory())}back(){this.navigator.back()}detach(){this.attached=!1,this.navigator.detach(),window.removeEventListener("popstate",this.onPopState)}forward(){return this.navigator.forward()}get index(){return this.navigator.index}get id(){return this.navigator.current.id}go(t,n){return this.navigator.go(t,n)}goTo(t,n){this.navigator.goTo(t,n)}get hash(){return(this.navigator.current.params||{}).hash||""}get hasPrev(){return this.navigator.hasPrev}get hasNext(){return this.navigator.hasNext}get history(){return this.navigator.history.map(_t)}get path(){return O(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let n=B(t);return this.hashMode&&(n=B(n.hash.slice(1))),{pathname:n.pathname,search:n.search,hash:n.hash}}push(t,n){const s=ft(t,this.path),{state:i=n}=s.params;this.navigator.push({...s,params:{...s.params,state:i}})}replace(t,n){const s=ft(t,this.path),{state:i=n}=s.params;this.navigator.replace({...s,params:{...s.params,state:i}})}renderPath(t){const n=(this.base.length===1?"":this.base)+V(O(t),"/");return this.hashMode?V(n.slice(1),this.hashMode==="classic"?"#":"#/"):n}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,n=this.renderPath(this);await Pn(),this.hasPrev&&this.hasNext?(window.history.replaceState(bt,""),window.history.pushState(t,"",n),window.history.pushState(wt,""),await L(-1)):this.hasPrev?(window.history.replaceState(bt,""),window.history.pushState(t,"",n)):this.hasNext?(window.history.replaceState(t,n),window.history.pushState(wt,""),await L(-1)):(window.history.replaceState(ve,""),window.history.pushState(t,"",n)),window.addEventListener("popstate",this.onPopState)}get search(){return(this.navigator.current.params||{}).search||""}get state(){return(this.navigator.current.params||{}).state}}function Pe(e){e||(e={});const{href:t,hash:n}=window.location;let s=O(e.hashMode===null?t:n.includes("?")?n.slice(1):`?${n.slice(1)}`);const i=e.base?gt(e.base):void 0;if(i){if(!s.startsWith(i))throw g(qt,`Path "${s}" expected to be starting with "${i}"`);s=s.slice(i.length)}return new mt([s],0,e)}function Sn(e){const t=e.match(/#(.+)/);return t?t[1]:null}function Rn(e,t){if(ct()){const n=sessionStorage.getItem(e);if(n)try{const{index:s,history:i}=JSON.parse(n);return new mt(i,s,t)}catch(s){console.error("Unable to restore hash navigator state.",s)}}return Pe(t)}function Tn(e,t){const n=Rn(e,t),s=()=>sessionStorage.setItem(e,JSON.stringify({index:n.index,history:n.history}));return n.on("change",s),s(),n}return r.BackButton=xt,r.BasicNavigator=Ee,r.BiometryManager=ne,r.BrowserNavigator=mt,r.ClosingBehavior=ie,r.CloudStorage=ae,r.ERR_INVALID_PATH_BASE=qt,r.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Tt,r.ERR_METHOD_PARAMETER_UNSUPPORTED=St,r.ERR_METHOD_UNSUPPORTED=Pt,r.ERR_NAVIGATION_HISTORY_EMPTY=It,r.ERR_NAVIGATION_INDEX_INVALID=Nt,r.ERR_NAVIGATION_ITEM_INVALID=Ce,r.ERR_PARSE=Q,r.ERR_SSR_INIT=Ae,r.ERR_TIMED_OUT=Ct,r.ERR_UNEXPECTED_TYPE=At,r.ERR_UNKNOWN_ENV=Rt,r.EventEmitter=R,r.HapticFeedback=ce,r.InitData=he,r.Invoice=ue,r.MainButton=pe,r.MiniApp=de,r.Popup=_e,r.QRScanner=fe,r.SDKError=N,r.SettingsButton=ge,r.ThemeParams=be,r.Utils=we,r.Viewport=me,r.array=re,r.bindMiniAppCSSVars=fn,r.bindThemeParamsCSSVars=gn,r.bindViewportCSSVars=bn,r.boolean=y,r.captureSameReq=et,r.classNames=H,r.compareVersions=Vt,r.createBrowserNavigatorFromLocation=Pe,r.createPostEvent=Ut,r.createSafeURL=B,r.date=ot,r.getHash=Sn,r.getPathname=gt,r.initBackButton=ze,r.initBiometryManager=Fe,r.initClosingBehavior=Je,r.initCloudStorage=Ke,r.initHapticFeedback=Xe,r.initInitData=Ze,r.initInvoice=en,r.initMainButton=nn,r.initMiniApp=on,r.initNavigator=Tn,r.initPopup=cn,r.initQRScanner=hn,r.initSettingsButton=un,r.initThemeParams=pn,r.initUtils=dn,r.initViewport=_n,r.initWeb=wn,r.invokeCustomMethod=I,r.isColorDark=st,r.isIframe=tt,r.isPageReload=ct,r.isRGB=U,r.isRGBShort=kt,r.isSDKError=ye,r.isSDKErrorOfType=vn,r.isSSR=mn,r.isTMA=yn,r.json=d,r.mergeClassNames=Be,r.mockTelegramEnv=En,r.number=P,r.off=q,r.on=w,r.parseInitData=tn,r.parseLaunchParams=G,r.parseThemeParams=pt,r.postEvent=A,r.request=_,r.requestBiometryInfo=se,r.requestThemeParams=ln,r.requestViewport=lt,r.retrieveLaunchParams=te,r.rgb=X,r.searchParams=x,r.serializeLaunchParams=Xt,r.serializeThemeParams=at,r.setCSSVar=v,r.setDebug=Re,r.setTargetOrigin=Ve,r.string=u,r.subscribe=yt,r.supports=S,r.targetOrigin=$t,r.toRGB=K,r.unsubscribe=m,r.urlToPath=O,r.withTimeout=nt,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),r}({});
2
2
  //# sourceMappingURL=index.iife.js.map