@tma.js/sdk 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/index.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +139 -136
- package/dist/index.js.map +1 -1
- package/dist/index.low-level.iife.js +1 -1
- package/dist/index.low-level.iife.js.map +1 -1
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var As=Object.defineProperty;var Is=(r,b,w)=>b in r?As(r,b,{enumerable:!0,configurable:!0,writable:!0,value:w}):r[b]=w;var h=(r,b,w)=>(Is(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=j(),{count:s}=t;t.unsubscribe(e),s&&!t.count&&De()}function yt(e){return j().subscribe(e),()=>w(e)}class Ee{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:a}=this.options,c="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${c};background-color: lightblue;color:black`,"",`${c};${o?`color:${o};`:""}${a?`background-color:${a}`:""}`,...s)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const U=new Ee("SDK",{bgColor:"forestgreen",textColor:"white"});let z=!1;const Et=({event:e,args:[t]})=>{U.log("Event received:",t===void 0?{name:e}:{name:e,data:t})};function ve(e){z!==e&&(z=e,e?yt(Et):w(Et))}function Re(...e){z&&U.log(...e)}class N{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 J(e,t,s){return window.addEventListener(e,t,s),()=>window.removeEventListener(e,t,s)}class q extends Error{constructor(t,s,n){super(s,{cause:n}),this.type=t,Object.setPrototypeOf(this,q.prototype)}}function l(e,t,s){return new q(e,t,s)}const vt="ERR_METHOD_UNSUPPORTED",Rt="ERR_METHOD_PARAMETER_UNSUPPORTED",St="ERR_UNKNOWN_ENV",Pt="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Tt="ERR_TIMED_OUT",Ct="ERR_UNEXPECTED_TYPE",Q="ERR_PARSE",At="ERR_NAVIGATION_LIST_EMPTY",It="ERR_NAVIGATION_CURSOR_INVALID",Se="ERR_NAVIGATION_ITEM_INVALID",H="ERR_SSR_INIT",Nt="ERR_SSR_POST_EVENT",qt="ERR_INVALID_PATH_BASE";function P(){return l(Ct,"Value has unexpected type")}class W{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 l(Q,`Unable to parse value${this.type?` as ${this.type}`:""}`,s)}}optional(){return this.isOptional=!0,this}}function T(e,t){return()=>new W(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 P()},"boolean");function kt(e,t){const s={};for(const n in e){const i=e[n];if(!i)continue;let o,a;if(typeof i=="function"||"parse"in i)o=n,a=typeof i=="function"?i:i.parse.bind(i);else{const{type:c}=i;o=i.from||n,a=typeof c=="function"?c:c.parse.bind(c)}try{const c=a(t(o));c!==void 0&&(s[n]=c)}catch(c){throw l(Q,`Unable to parse field "${n}"`,c)}}return s}function Y(e){let t=e;if(typeof t=="string"&&(t=JSON.parse(t)),typeof t!="object"||t===null||Array.isArray(t))throw P();return t}function d(e,t){return new W(s=>{const n=Y(s);return kt(e,i=>n[i])},!1,t)}const R=T(e=>{if(typeof e=="number")return e;if(typeof e=="string"){const t=Number(e);if(!Number.isNaN(t))return t}throw P()},"number");function G(e){return/^#[\da-f]{6}$/i.test(e)}function Dt(e){return/^#[\da-f]{3}$/i.test(e)}function K(e){const t=e.replace(/\s/g,"").toLowerCase();if(G(t))return t;if(Dt(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 P()},"string"),X=T(e=>K(u().parse(e)),"rgb");function Pe(e){return d({eventType:u(),eventData:t=>t}).parse(e)}function Te(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function Ce(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Ae(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=Ce;return}s in t||(t[s]={}),t=t[s]})})}const Ie=d({button_id:e=>e==null?void 0:u().parse(e)}),Ne={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=>Ie.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((s,[n,i])=>(s[n]=t.parse(i),s),{})}}),viewport_changed:d({height:R(),width:e=>e==null?window.innerWidth:R().parse(e),is_state_stable:y(),is_expanded:y()}),write_access_requested:d({status:u()})};function qe(){const e=new N;Ae();let t=[Te,J("resize",()=>{e.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 n;try{n=Pe(s.data)}catch{return}const{eventType:i,eventData:o}=n,a=Ne[i];try{const c=a?a.parse(o):o;e.emit(...c?[i,c]:[i])}catch(c){U.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,c)}}),()=>e.clear()];return[e,()=>{t.forEach(s=>s()),t=[]}]}const[ke,De]=b(e=>{const[t,s]=qe(),n=t.off.bind(t);return t.off=(i,o)=>{const{count:a}=t;n(i,o),a&&!t.count&&e()},[t,s]},([,e])=>e());function j(){return ke()[0]}function k(e,t){j().off(e,t)}function m(e,t,s){return j().on(e,t,s)}function D(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Vt(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 a=parseInt(s[o]||"0",10),c=parseInt(n[o]||"0",10);if(a!==c)return a>c?1:-1}return 0}function E(e,t){return Vt(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 Ve(e){return"external"in e&&D(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Me(e){return"TelegramWebviewProxy"in e&&D(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function Mt(){try{return window.self!==window.top}catch{return!0}}let Bt="https://web.telegram.org";function Be(e){Bt=e}function Ot(){return Bt}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=Ot()}=n;if(Re("Posting event:",i?{event:e,data:i}:{event:e}),Mt()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),o);return}if(Ve(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Me(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw l(St,"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 Lt(e){return(t,s)=>{if(!S(t,e))throw l(vt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(D(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 l(Rt,`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return C(t,s)}}function Z(e){return({req_id:t})=>t===e}function $t(e){return l(Tt,`Timeout reached: ${e}ms`)}function tt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n($t(t))},t)})])}async function _(e){let t;const s=new Promise(g=>{t=g}),{method:n,event:i,capture:o,postEvent:a=C,timeout:c}=e,p=(Array.isArray(i)?i:[i]).map(g=>m(g,ye=>(!o||o(ye))&&t(ye)));try{return a(n,e.params),await(c?tt(s,c):s)}finally{p.forEach(g=>g())}}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:Z(s)});if(o)throw l(Pt,o);return i}function x(...e){return e.map(t=>{if(typeof t=="string")return t;if(D(t))return x(Object.entries(t).map(s=>s[1]&&s[0]));if(Array.isArray(t))return x(...t)}).filter(Boolean).join(" ")}function Oe(...e){return e.reduce((t,s)=>(D(s)&&Object.entries(s).forEach(([n,i])=>{const o=x(t[n],i);o.length&&(t[n]=o)}),t),{})}function et(e){const t=K(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 Le{constructor(t){h(this,"ee",new N);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,a])=>this.state[o]===a||a===void 0?i:(this.state[o]=a,this.ee.emit(`change:${o}`,a),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class st{constructor(t){h(this,"state");h(this,"get");h(this,"set");h(this,"clone");this.state=new Le(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 Ut(e,t){return s=>S(t[s],e)}class nt extends st{constructor(s,n,i){super(s);h(this,"supports");this.supports=Ut(n,i)}}class Ht extends nt{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"?k("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}}function I(){return typeof window>"u"}const it=T(e=>e instanceof Date?e:new Date(R().parse(e)*1e3),"Date");function F(e,t){return new W(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw P();const n=typeof s=="string"?new URLSearchParams(s):s;return kt(e,i=>{const o=n.get(i);return o===null?void 0:o})},!1,t)}const $e=d({id:R(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat").optional(),Wt=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:R(),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 Gt(){return F({authDate:{type:it(),from:"auth_date"},canSendAfter:{type:R().optional(),from:"can_send_after"},chat:$e,chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:Wt,startParam:{type:u().optional(),from:"start_param"},user:Wt},"InitData")}function Ue(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function He(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const jt=T(e=>{const t=X().optional();return Object.entries(Y(e)).reduce((s,[n,i])=>(s[Ue(n)]=t.parse(i),s),{})},"ThemeParams");function rt(e){return F({botInline:{type:y().optional(),from:"tgWebAppBotInline"},initData:{type:Gt().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:jt(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}}).parse(e)}function xt(e){return rt(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function We(){return xt(window.location.href)}function Ft(){return performance.getEntriesByType("navigation")[0]}function Ge(){const e=Ft();if(!e)throw new Error("Unable to get first navigation entry.");return xt(e.name)}function zt(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function Jt(e,t){sessionStorage.setItem(zt(e),JSON.stringify(t))}function Qt(e){const t=sessionStorage.getItem(zt(e));try{return t?JSON.parse(t):void 0}catch{}}function je(){return rt(Qt("launchParams")||"")}function Yt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[He(t),s])))}function Kt(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:o,startParam:a,botInline:c}=e,p=new URLSearchParams;return p.set("tgWebAppPlatform",n),p.set("tgWebAppThemeParams",Yt(s)),p.set("tgWebAppVersion",i),t&&p.set("tgWebAppData",t),a&&p.set("tgWebAppStartParam",a),typeof o=="boolean"&&p.set("tgWebAppShowSettings",o?"1":"0"),typeof c=="boolean"&&p.set("tgWebAppBotInline",c?"1":"0"),p.toString()}function xe(e){Jt("launchParams",Kt(e))}function Xt(){for(const e of[We,Ge,je])try{const t=e();return xe(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function ot(){const e=Ft();return!!(e&&e.type==="reload")}function Fe(){let e=0;return()=>(e+=1).toString()}const[ze]=b(Fe);function f(e,t){return({ssr:s}={})=>{let n;if(I()){if(!s)throw l(H,"ssr.options must be specified to initialize component on the server side");n=s}else n=Xt();const i={...n,postEvent:"version"in n?Lt(n.version):()=>{throw l(Nt,"postEvent function is forbidden to be called on the server side.")},createRequestId:ze()};if(I()||typeof e=="function")return typeof e=="function"?e(i):t(i);const o=t({...i,state:ot()?Qt(e):void 0}),a=c=>(c.on("change",p=>{Jt(e,p)}),c);return o instanceof Promise?o.then(a):a(o)}}const Je=f("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new Ht(s.isVisible,t,e));class V extends nt{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}function Zt(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 at extends V{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=Zt(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 te(e){return Zt(await _({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const Qe=f("biometryManager",async({postEvent:e,version:t,state:s})=>{if(s)return new at({...s,version:t,postEvent:e});if(I())throw l(H,"BiometryManager cannot be instantiated on the server side without passing the ssr.state object.");return new at({...await te({timeout:1e3}),version:t,postEvent:e})});class ct extends st{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}class ee extends ct{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 Ye=f("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new ee(t.isConfirmationNeeded,e));class ht{constructor(t,s){h(this,"supports");this.supports=Ut(t,s)}}function Ke(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 P()}class Xe extends W{constructor(s,n,i){super(Ke,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 se(e){return new Xe(t=>t,!1,e)}function ne(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class ie extends ht{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 se().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 ne(n,"");const i=await A("getStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent}),o=d(ne(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 Ze=f(({createRequestId:e,postEvent:t,version:s})=>new ie(s,e,t));class re extends ht{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 ts=f(({version:e,postEvent:t})=>new re(e,t));class oe{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 es=f(({initData:e})=>e?new oe(e):void 0);function ss(e){return Gt().parse(e)}class ae extends V{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 a=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!a)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,n]=a}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 ns=f(({version:e,postEvent:t})=>new ae(!1,e,t));class ce extends st{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"?k("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 is=f("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",backgroundColor:t.buttonColor||"#000000"}})=>new ce({...s,postEvent:e}));function rs(){return F({contact:d({userId:{type:R(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:it(),from:"auth_date"},hash:u()},"RequestedContact")}function he(e,t){return s=>{const[n,i]=t[s];return S(n,i,e)}}function os(e){return new Promise(t=>{setTimeout(t,e)})}class ue extends V{constructor({postEvent:s,createRequestId:n,version:i,botInline:o,...a}){super(a,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 c=this.supports.bind(this);this.supports=p=>c(p)?p!=="switchInlineQuery"||o:!1,this.supportsParam=he(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:s=1e4}={}){return rs().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 et(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 tt(async()=>{for(;Date.now()<i;){try{return await this.getRequestedContact()}catch{}await os(o),o+=50}throw $t(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",G(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 as=f("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new ue({...n,...s,botInline:t}));function cs(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:a=""}=o;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(!o.type||o.type==="default"||o.type==="destructive"){const c=o.text.trim();if(!c.length||c.length>64){const p=o.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${o.text.length}`)}return{...o,text:c,id:a}}return{...o,id:a}}):i=[{type:"close",id:""}],{title:s,message:t,buttons:i}}class pe extends V{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:cs(t)});return s}finally{this.isOpened=!1}}}const hs=f(({postEvent:e,version:t})=>new pe(!1,t,e));class le extends V{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 us=f(({version:e,postEvent:t})=>new le(!1,e,t));class de extends nt{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"?k("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 ps=f("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new de(s.isVisible,e,t));function ut(e){return jt().parse(e)}class _e extends ct{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||et(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(ut(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const ls=f("themeParams",({themeParams:e,state:t=e})=>{const s=new _e(t);return I()||s.listen(),s});function ds(e={}){return _({...e,method:"web_app_request_theme",event:"theme_changed"}).then(ut)}class fe extends ht{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=he(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:Z(s)});return n}}const _s=f(({version:e,postEvent:t,createRequestId:s})=>new fe(e,s,t));async function pt(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 M(e){return e<0?0:e}class lt extends ct{constructor({postEvent:s,stableHeight:n,height:i,width:o,isExpanded:a}){super({height:M(i),isExpanded:a,stableHeight:M(n),width:M(o)});h(this,"postEvent");this.postEvent=s}async sync(s){const{isStateStable:n,...i}=await pt(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:a}=s,c=M(n);this.set({height:c,isExpanded:o,width:M(i),...a?{stableHeight:c}:{}})})}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}}async function fs(e,t={}){const{height:s,width:n,isExpanded:i,isStateStable:o}=await pt({...t,postEvent:e});return new lt({postEvent:e,height:s,width:n,isExpanded:i,stableHeight:o?s:0})}function gs({state:e,platform:t,postEvent:s}){let n=!1,i=0,o=0,a=0;return e?(n=e.isExpanded,i=e.height,o=e.width,a=e.stableHeight):["macos","tdesktop","unigram","webk","weba","web"].includes(t)&&(n=!0,i=window.innerHeight,o=window.innerWidth,a=window.innerHeight),new lt({postEvent:s,height:i,width:o,stableHeight:a,isExpanded:n})}const bs=f("viewport",async e=>{if(I()&&!e.state)throw l(H,"Viewport cannot be instantiated on the server side without passing the ssr.state object.");let t=gs(e);return I()||(t.width===0&&await fs(e.postEvent,{timeout:1e3}).then(s=>t=s).catch(s=>U.error("Unable to sync viewport state",s)),t.listen()),t});function v(e,t){document.documentElement.style.setProperty(e,t)}function ms(e,t,s){s||(s=c=>`--tg-${c}-color`);const n=s("header"),i=s("bg"),o=()=>{const{headerColor:c}=e;if(G(c))v(n,c);else{const{bgColor:p,secondaryBgColor:g}=t;c==="bg_color"&&p?v(n,p):c==="secondary_bg_color"&&g&&v(n,g)}v(i,e.bgColor)},a=[t.on("change",o),e.on("change",o)];return o(),()=>a.forEach(c=>c())}function ws(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 ys(e,t){t||(t=g=>`--tg-viewport-${g}`);const[s,n,i]=["height","width","stable-height"].map(g=>t(g)),o=()=>v(s,`${e.height}px`),a=()=>v(n,`${e.width}px`),c=()=>v(i,`${e.stableHeight}px`),p=[e.on("change:height",o),e.on("change:width",a),e.on("change:stableHeight",c)];return o(),a(),c(),()=>p.forEach(g=>g())}function Es(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}async function vs(){try{return await _({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function ge(e){return e instanceof q}function Rs(e,t){return ge(e)&&e.type===t}function dt(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 be{constructor(t,s,n=C){h(this,"history");h(this,"ee",new N);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 l(At,"History should not be empty.");if(s<0||s>=t.length)throw l(It,"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(),m("back_button_pressed",this.back))}get current(){return this.history[this.index]}detach(){this.attached=!1,k("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,dt(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,dt(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 _t({params:e,...t}){return{...e||{hash:"",search:""},...t}}function B(e,t){return e.startsWith(t)?e:`${t}${e}`}function O(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${B(e.search||"","?")}${B(e.hash||"","#")}`,"http://a")}function L(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=O(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function ft(e,t,s){let n,i;typeof e=="string"?n=e:(n=L(e),s=e.state,i=e.id);const{pathname:o,search:a,hash:c}=new URL(n,`http://a${B(t,"/")}`);return{id:i,pathname:o,params:{hash:c,search:a,state:s}}}async function $(e){return e===0?!0:Promise.race([new Promise(t=>{const s=J("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function Ss(){if(window.history.length<=1||(window.history.pushState(null,""),await $(1-window.history.length)))return;let t=await $(-1);for(;t;)t=await $(-1)}function gt(e){return O(e).pathname}const me=0,bt=1,mt=2;class wt{constructor(t,s,{postEvent:n,hashMode:i,base:o}={}){h(this,"navigator");h(this,"ee",new N);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===me?window.history.forward():t===bt&&this.back(),t===mt&&this.forward()});h(this,"onNavigatorChange",async({to:t,from:s,delta:n})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:n,from:_t(s),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 be(t.map(a=>ft(a,"/")),s,n),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,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(_t)}get path(){return L(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=O(t);return this.hashMode&&(s=O(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=ft(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=ft(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)+B(L(t),"/");return this.hashMode?B(s.slice(1),this.hashMode==="default"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await Ss(),this.hasPrev&&this.hasNext?(window.history.replaceState(bt,""),window.history.pushState(t,"",s),window.history.pushState(mt,""),await $(-1)):this.hasPrev?(window.history.replaceState(bt,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(mt,""),await $(-1)):(window.history.replaceState(me,""),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 we(e){e||(e={});const{href:t,hash:s}=window.location;let n=L(e.hashMode?s.includes("?")?s.slice(1):`?${s.slice(1)}`:t);const i=e.base?gt(e.base):void 0;if(i){if(!n.startsWith(i))throw l(qt,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new wt([n],0,e)}function Ps(e){const t=e.match(/#(.+)/);return t?t[1]:null}function Ts(e,t){if(ot()){const s=sessionStorage.getItem(e);if(s)try{const{index:n,history:i}=JSON.parse(s);return new wt(i,n,t)}catch(n){console.error("Unable to restore hash navigator state.",n)}}return we(t)}function Cs(e,t){const s=Ts(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}return r.BackButton=Ht,r.BasicNavigator=be,r.BiometryManager=at,r.BrowserNavigator=wt,r.ClosingBehavior=ee,r.CloudStorage=ie,r.ERR_INVALID_PATH_BASE=qt,r.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Pt,r.ERR_METHOD_PARAMETER_UNSUPPORTED=Rt,r.ERR_METHOD_UNSUPPORTED=vt,r.ERR_NAVIGATION_HISTORY_EMPTY=At,r.ERR_NAVIGATION_INDEX_INVALID=It,r.ERR_NAVIGATION_ITEM_INVALID=Se,r.ERR_PARSE=Q,r.ERR_SSR_INIT=H,r.ERR_SSR_POST_EVENT=Nt,r.ERR_TIMED_OUT=Tt,r.ERR_UNEXPECTED_TYPE=Ct,r.ERR_UNKNOWN_ENV=St,r.EventEmitter=N,r.HapticFeedback=re,r.InitData=oe,r.Invoice=ae,r.MainButton=ce,r.MiniApp=ue,r.Popup=pe,r.QRScanner=le,r.SDKError=q,r.SettingsButton=de,r.ThemeParams=_e,r.Utils=fe,r.Viewport=lt,r.array=se,r.bindMiniAppCSSVars=ms,r.bindThemeParamsCSSVars=ws,r.bindViewportCSSVars=ys,r.boolean=y,r.captureSameReq=Z,r.classNames=x,r.compareVersions=Vt,r.createBrowserNavigatorFromLocation=we,r.createPostEvent=Lt,r.createSafeURL=O,r.date=it,r.getHash=Ps,r.getPathname=gt,r.initBackButton=Je,r.initBiometryManager=Qe,r.initClosingBehavior=Ye,r.initCloudStorage=Ze,r.initHapticFeedback=ts,r.initInitData=es,r.initInvoice=ns,r.initMainButton=is,r.initMiniApp=as,r.initNavigator=Cs,r.initPopup=hs,r.initQRScanner=us,r.initSettingsButton=ps,r.initThemeParams=ls,r.initUtils=_s,r.initViewport=bs,r.initWeb=Es,r.invokeCustomMethod=A,r.isColorDark=et,r.isIframe=Mt,r.isPageReload=ot,r.isRGB=G,r.isRGBShort=Dt,r.isSDKError=ge,r.isSDKErrorOfType=Rs,r.isTMA=vs,r.json=d,r.mergeClassNames=Oe,r.number=R,r.off=k,r.on=m,r.parseInitData=ss,r.parseLaunchParams=rt,r.parseThemeParams=ut,r.postEvent=C,r.request=_,r.requestBiometryInfo=te,r.requestThemeParams=ds,r.requestViewport=pt,r.retrieveLaunchParams=Xt,r.rgb=X,r.searchParams=F,r.serializeLaunchParams=Kt,r.serializeThemeParams=Yt,r.setCSSVar=v,r.setDebug=ve,r.setTargetOrigin=Be,r.string=u,r.subscribe=yt,r.supports=S,r.targetOrigin=Ot,r.toRGB=K,r.unsubscribe=w,r.urlToPath=L,r.withTimeout=tt,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),r}({});
|
|
1
|
+
var As=Object.defineProperty;var Is=(r,b,m)=>b in r?As(r,b,{enumerable:!0,configurable:!0,writable:!0,value:m}):r[b]=m;var h=(r,b,m)=>(Is(r,typeof b!="symbol"?b+"":b,m),m);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 m(e){const t=j(),{count:s}=t;t.unsubscribe(e),s&&!t.count&&Ve()}function yt(e){return j().subscribe(e),()=>m(e)}class ve{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:a}=this.options,c="font-weight: bold;padding: 0 5px;border-radius:5px";console[t](`%c${i}%c / %c${this.scope}`,`${c};background-color: lightblue;color:black`,"",`${c};${o?`color:${o};`:""}${a?`background-color:${a}`:""}`,...s)}error(...t){this.print("error",...t)}log(...t){this.print("log",...t)}}const U=new ve("SDK",{bgColor:"forestgreen",textColor:"white"});let z=!1;const Et=({event:e,args:[t]})=>{U.log("Event received:",t===void 0?{name:e}:{name:e,data:t})};function Se(e){z!==e&&(z=e,e?yt(Et):m(Et))}function Re(...e){z&&U.log(...e)}class N{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 J(e,t,s){return window.addEventListener(e,t,s),()=>window.removeEventListener(e,t,s)}class q extends Error{constructor(t,s,n){super(s,{cause:n}),this.type=t,Object.setPrototypeOf(this,q.prototype)}}function l(e,t,s){return new q(e,t,s)}const vt="ERR_METHOD_UNSUPPORTED",St="ERR_METHOD_PARAMETER_UNSUPPORTED",Rt="ERR_UNKNOWN_ENV",Pt="ERR_INVOKE_CUSTOM_METHOD_RESPONSE",Tt="ERR_TIMED_OUT",Ct="ERR_UNEXPECTED_TYPE",Q="ERR_PARSE",At="ERR_NAVIGATION_LIST_EMPTY",It="ERR_NAVIGATION_CURSOR_INVALID",Pe="ERR_NAVIGATION_ITEM_INVALID",H="ERR_SSR_INIT",Nt="ERR_SSR_POST_EVENT",qt="ERR_INVALID_PATH_BASE";function T(){return l(Ct,"Value has unexpected type")}class W{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 l(Q,`Unable to parse value${this.type?` as ${this.type}`:""}`,s)}}optional(){return this.isOptional=!0,this}}function C(e,t){return()=>new W(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 kt(e,t){const s={};for(const n in e){const i=e[n];if(!i)continue;let o,a;if(typeof i=="function"||"parse"in i)o=n,a=typeof i=="function"?i:i.parse.bind(i);else{const{type:c}=i;o=i.from||n,a=typeof c=="function"?c:c.parse.bind(c)}try{const c=a(t(o));c!==void 0&&(s[n]=c)}catch(c){throw l(Q,`Unable to parse field "${n}"`,c)}}return s}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 W(s=>{const n=Y(s);return kt(e,i=>n[i])},!1,t)}const S=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 G(e){return/^#[\da-f]{6}$/i.test(e)}function Dt(e){return/^#[\da-f]{3}$/i.test(e)}function K(e){const t=e.replace(/\s/g,"").toLowerCase();if(G(t))return t;if(Dt(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=C(e=>{if(typeof e=="string"||typeof e=="number")return e.toString();throw T()},"string"),X=C(e=>K(u().parse(e)),"rgb");function Te(e){return d({eventType:u(),eventData:t=>t}).parse(e)}function Ce(){["TelegramGameProxy_receiveEvent","TelegramGameProxy","Telegram"].forEach(e=>{delete window[e]})}function Ae(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}function Ie(){[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=window;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=Ae;return}s in t||(t[s]={}),t=t[s]})})}const Ne=d({button_id:e=>e==null?void 0:u().parse(e)}),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=>Ne.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((s,[n,i])=>(s[n]=t.parse(i),s),{})}}),viewport_changed:d({height:S(),width:e=>e==null?window.innerWidth:S().parse(e),is_state_stable:y(),is_expanded:y()}),write_access_requested:d({status:u()})};function ke(){const e=new N;Ie();let t=[Ce,J("resize",()=>{e.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 n;try{n=Te(s.data)}catch{return}const{eventType:i,eventData:o}=n,a=qe[i];try{const c=a?a.parse(o):o;e.emit(...c?[i,c]:[i])}catch(c){U.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,c)}}),()=>e.clear()];return[e,()=>{t.forEach(s=>s()),t=[]}]}const[De,Ve]=b(e=>{const[t,s]=ke(),n=t.off.bind(t);return t.off=(i,o)=>{const{count:a}=t;n(i,o),a&&!t.count&&e()},[t,s]},([,e])=>e());function j(){return De()[0]}function k(e,t){j().off(e,t)}function w(e,t,s){return j().on(e,t,s)}function D(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Vt(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 a=parseInt(s[o]||"0",10),c=parseInt(n[o]||"0",10);if(a!==c)return a>c?1:-1}return 0}function E(e,t){return Vt(e,t)<=0}function R(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 Me(e){return"external"in e&&D(e.external)&&"notify"in e.external&&typeof e.external.notify=="function"}function Mt(e){return"TelegramWebviewProxy"in e&&D(e.TelegramWebviewProxy)&&"postEvent"in e.TelegramWebviewProxy&&typeof e.TelegramWebviewProxy.postEvent=="function"}function Bt(){try{return window.self!==window.top}catch{return!0}}let Ot="https://web.telegram.org";function Be(e){Ot=e}function Lt(){return Ot}function A(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=Lt()}=n;if(Re("Posting event:",i?{event:e,data:i}:{event:e}),Bt()){window.parent.postMessage(JSON.stringify({eventType:e,eventData:i}),o);return}if(Me(window)){window.external.notify(JSON.stringify({eventType:e,eventData:i}));return}if(Mt(window)){window.TelegramWebviewProxy.postEvent(e,JSON.stringify(i));return}throw l(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 $t(e){return(t,s)=>{if(!R(t,e))throw l(vt,`Method "${t}" is unsupported in Mini Apps version ${e}`);if(D(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&&!R(t,n,e))throw l(St,`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${e}`)}return A(t,s)}}function Z(e){return({req_id:t})=>t===e}function Ut(e){return l(Tt,`Timeout reached: ${e}ms`)}function tt(e,t){return Promise.race([typeof e=="function"?e():e,new Promise((s,n)=>{setTimeout(()=>{n(Ut(t))},t)})])}async function _(e){let t;const s=new Promise(g=>{t=g}),{method:n,event:i,capture:o,postEvent:a=A,timeout:c}=e,p=(Array.isArray(i)?i:[i]).map(g=>w(g,Ee=>(!o||o(Ee))&&t(Ee)));try{return a(n,e.params),await(c?tt(s,c):s)}finally{p.forEach(g=>g())}}async function I(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:Z(s)});if(o)throw l(Pt,o);return i}function x(...e){return e.map(t=>{if(typeof t=="string")return t;if(D(t))return x(Object.entries(t).map(s=>s[1]&&s[0]));if(Array.isArray(t))return x(...t)}).filter(Boolean).join(" ")}function Oe(...e){return e.reduce((t,s)=>(D(s)&&Object.entries(s).forEach(([n,i])=>{const o=x(t[n],i);o.length&&(t[n]=o)}),t),{})}function et(e){const t=K(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 Le{constructor(t){h(this,"ee",new N);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,a])=>this.state[o]===a||a===void 0?i:(this.state[o]=a,this.ee.emit(`change:${o}`,a),!0),!1)&&this.ee.emit("change",this.state)}get(t){return this.state[t]}}class st{constructor(t){h(this,"state");h(this,"get");h(this,"set");h(this,"clone");this.state=new Le(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 s=>R(t[s],e)}class nt extends st{constructor(s,n,i){super(s);h(this,"supports");this.supports=Ht(n,i)}}class Wt extends nt{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"?w("back_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?k("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}}function P(){return typeof window>"u"}const it=C(e=>e instanceof Date?e:new Date(S().parse(e)*1e3),"Date");function F(e,t){return new W(s=>{if(typeof s!="string"&&!(s instanceof URLSearchParams))throw T();const n=typeof s=="string"?new URLSearchParams(s):s;return kt(e,i=>{const o=n.get(i);return o===null?void 0:o})},!1,t)}const $e=d({id:S(),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:S(),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 F({authDate:{type:it(),from:"auth_date"},canSendAfter:{type:S().optional(),from:"can_send_after"},chat:$e,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 Ue(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function He(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const xt=C(e=>{const t=X().optional();return Object.entries(Y(e)).reduce((s,[n,i])=>(s[Ue(n)]=t.parse(i),s),{})},"ThemeParams");function rt(e){return F({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:xt(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}}).parse(e)}function Ft(e){return rt(e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&"))}function We(){return Ft(window.location.href)}function zt(){return performance.getEntriesByType("navigation")[0]}function Ge(){const e=zt();if(!e)throw new Error("Unable to get first navigation entry.");return Ft(e.name)}function Jt(e){return`tma.js/${e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}`}function Qt(e,t){sessionStorage.setItem(Jt(e),JSON.stringify(t))}function Yt(e){const t=sessionStorage.getItem(Jt(e));try{return t?JSON.parse(t):void 0}catch{}}function je(){return rt(Yt("launchParams")||"")}function Kt(e){return JSON.stringify(Object.fromEntries(Object.entries(e).map(([t,s])=>[He(t),s])))}function Xt(e){const{initDataRaw:t,themeParams:s,platform:n,version:i,showSettings:o,startParam:a,botInline:c}=e,p=new URLSearchParams;return p.set("tgWebAppPlatform",n),p.set("tgWebAppThemeParams",Kt(s)),p.set("tgWebAppVersion",i),t&&p.set("tgWebAppData",t),a&&p.set("tgWebAppStartParam",a),typeof o=="boolean"&&p.set("tgWebAppShowSettings",o?"1":"0"),typeof c=="boolean"&&p.set("tgWebAppBotInline",c?"1":"0"),p.toString()}function xe(e){Qt("launchParams",Xt(e))}function Zt(){for(const e of[We,Ge,je])try{const t=e();return xe(t),t}catch{}throw new Error("Unable to retrieve launch parameters from any known source.")}function ot(){const e=zt();return!!(e&&e.type==="reload")}function Fe(){let e=0;return()=>(e+=1).toString()}const[ze]=b(Fe);function f(e,t){return({ssr:s}={})=>{let n;if(P()){if(!s)throw l(H,"ssr.options must be specified to initialize component on the server side");n=s}else n=Zt();const i={...n,postEvent:"version"in n?$t(n.version):()=>{throw l(Nt,"postEvent function is forbidden to be called on the server side.")},createRequestId:ze()};if(P()||typeof e=="function")return typeof e=="function"?e(i):t(i);const o=t({...i,state:ot()?Yt(e):void 0}),a=c=>(c.on("change",p=>{Qt(e,p)}),c);return o instanceof Promise?o.then(a):a(o)}}const Je=f("backButton",({postEvent:e,version:t,state:s={isVisible:!1}})=>new Wt(s.isVisible,t,e));class V extends nt{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}function te(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 at extends V{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=te(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 ee(e){return te(await _({...e||{},method:"web_app_biometry_get_info",event:"biometry_info_received"}))}const Qe=f("biometryManager",async({postEvent:e,version:t,state:s})=>{if(s)return new at({...s,version:t,postEvent:e});if(P())throw l(H,"BiometryManager cannot be instantiated on the server side without passing the ssr.state object.");return new at({...await ee({timeout:1e3}),version:t,postEvent:e})});class ct extends st{constructor(){super(...arguments);h(this,"on",this.state.on.bind(this.state));h(this,"off",this.state.off.bind(this.state))}}class se extends ct{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 Ye=f("closingBehavior",({postEvent:e,state:t={isConfirmationNeeded:!1}})=>new se(t.isConfirmationNeeded,e));class ht{constructor(t,s){h(this,"supports");this.supports=Ht(t,s)}}function Ke(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 Xe extends W{constructor(s,n,i){super(Ke,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 ne(e){return new Xe(t=>t,!1,e)}function ie(e,t){return Object.fromEntries(e.map(s=>[s,t]))}class re extends ht{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 I("deleteStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent})}async getKeys(t={}){return ne().of(u()).parse(await I("getStorageKeys",{},this.createRequestId(),{...t,postEvent:this.postEvent}))}async get(t,s={}){const n=Array.isArray(t)?t:[t];if(!n.length)return ie(n,"");const i=await I("getStorageValues",{keys:n},this.createRequestId(),{...s,postEvent:this.postEvent}),o=d(ie(n,u()),"CloudStorageData").parse(i);return Array.isArray(t)?o:o[t]}async set(t,s,n={}){await I("saveStorageValue",{key:t,value:s},this.createRequestId(),{...n,postEvent:this.postEvent})}}const Ze=f(({createRequestId:e,postEvent:t,version:s})=>new re(s,e,t));class oe extends ht{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 ts=f(({version:e,postEvent:t})=>new oe(e,t));class ae{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 es=f(({initData:e})=>e?new ae(e):void 0);function ss(e){return jt().parse(e)}class ce extends V{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 a=o.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(!a)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');[,,n]=a}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 ns=f(({version:e,postEvent:t})=>new ce(!1,e,t));class he extends st{constructor({postEvent:s,...n}){super(n);h(this,"postEvent");h(this,"on",(s,n)=>s==="click"?w("main_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?k("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 is=f("mainButton",({postEvent:e,themeParams:t,state:s={isVisible:!1,isEnabled:!1,text:"",isLoaderVisible:!1,textColor:t.buttonTextColor||"#ffffff",backgroundColor:t.buttonColor||"#000000"}})=>new he({...s,postEvent:e}));function rs(){return F({contact:d({userId:{type:S(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:it(),from:"auth_date"},hash:u()},"RequestedContact")}function ue(e,t){return s=>{const[n,i]=t[s];return R(n,i,e)}}function os(e){return new Promise(t=>{setTimeout(t,e)})}class pe extends V{constructor({postEvent:s,createRequestId:n,version:i,botInline:o,...a}){super(a,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 c=this.supports.bind(this);this.supports=p=>c(p)?p!=="switchInlineQuery"||o:!1,this.supportsParam=ue(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact({timeout:s=1e4}={}){return rs().parse(await I("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 et(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 tt(async()=>{for(;Date.now()<i;){try{return await this.getRequestedContact()}catch{}await os(o),o+=50}throw Ut(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",G(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 as=f("miniApp",({themeParams:e,botInline:t=!1,state:s={bgColor:e.bgColor||"#ffffff",headerColor:e.headerBgColor||"#000000"},...n})=>new pe({...n,...s,botInline:t}));function cs(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:a=""}=o;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(!o.type||o.type==="default"||o.type==="destructive"){const c=o.text.trim();if(!c.length||c.length>64){const p=o.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${o.text.length}`)}return{...o,text:c,id:a}}return{...o,id:a}}):i=[{type:"close",id:""}],{title:s,message:t,buttons:i}}class le extends V{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:cs(t)});return s}finally{this.isOpened=!1}}}const hs=f(({postEvent:e,version:t})=>new le(!1,t,e));class de extends V{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 us=f(({version:e,postEvent:t})=>new de(!1,e,t));class _e extends nt{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"?w("settings_button_pressed",n):this.state.on(s,n));h(this,"off",(s,n)=>s==="click"?k("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 ps=f("settingsButton",({version:e,postEvent:t,state:s={isVisible:!1}})=>new _e(s.isVisible,e,t));function ut(e){return xt().parse(e)}class fe extends ct{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||et(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(ut(t.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}const ls=f("themeParams",({themeParams:e,state:t=e})=>{const s=new fe(t);return P()||s.listen(),s});function ds(e={}){return _({...e,method:"web_app_request_theme",event:"theme_changed"}).then(ut)}class ge extends ht{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=ue(s,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(s,n){const i=new URL(s,window.location.href).toString();if(!R("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(!R("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:Z(s)});return n}}const _s=f(({version:e,postEvent:t,createRequestId:s})=>new ge(e,s,t));async function pt(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 M(e){return e<0?0:e}class lt extends ct{constructor({postEvent:s,stableHeight:n,height:i,width:o,isExpanded:a}){super({height:M(i),isExpanded:a,stableHeight:M(n),width:M(o)});h(this,"postEvent");this.postEvent=s}async sync(s){const{isStateStable:n,...i}=await pt(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 w("viewport_changed",s=>{const{height:n,width:i,is_expanded:o,is_state_stable:a}=s,c=M(n);this.set({height:c,isExpanded:o,width:M(i),...a?{stableHeight:c}:{}})})}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}}async function fs(e,t={}){const{height:s,width:n,isExpanded:i,isStateStable:o}=await pt({...t,postEvent:e});return new lt({postEvent:e,height:s,width:n,isExpanded:i,stableHeight:o?s:0})}function gs({state:e,platform:t,postEvent:s}){let n=!1,i=0,o=0,a=0;return e?(n=e.isExpanded,i=e.height,o=e.width,a=e.stableHeight):["macos","tdesktop","unigram","webk","weba","web"].includes(t)&&(n=!0,i=window.innerHeight,o=window.innerWidth,a=window.innerHeight),new lt({postEvent:s,height:i,width:o,stableHeight:a,isExpanded:n})}const bs=f("viewport",async e=>{if(P()&&!e.state)throw l(H,"Viewport cannot be instantiated on the server side without passing the ssr.state object.");let t=gs(e);return P()||(t.width===0&&await fs(e.postEvent,{timeout:1e3}).then(s=>t=s).catch(s=>U.error("Unable to sync viewport state",s)),t.listen()),t});function v(e,t){document.documentElement.style.setProperty(e,t)}function ws(e,t,s){s||(s=c=>`--tg-${c}-color`);const n=s("header"),i=s("bg"),o=()=>{const{headerColor:c}=e;if(G(c))v(n,c);else{const{bgColor:p,secondaryBgColor:g}=t;c==="bg_color"&&p?v(n,p):c==="secondary_bg_color"&&g&&v(n,g)}v(i,e.bgColor)},a=[t.on("change",o),e.on("change",o)];return o(),()=>a.forEach(c=>c())}function ms(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 ys(e,t){t||(t=g=>`--tg-viewport-${g}`);const[s,n,i]=["height","width","stable-height"].map(g=>t(g)),o=()=>v(s,`${e.height}px`),a=()=>v(n,`${e.width}px`),c=()=>v(i,`${e.stableHeight}px`),p=[e.on("change:height",o),e.on("change:width",a),e.on("change:stableHeight",c)];return o(),a(),c(),()=>p.forEach(g=>g())}function Es(e=!0){const t=[w("reload_iframe",()=>{A("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(w("set_custom_style",i=>{n.innerHTML=i}),()=>document.head.removeChild(n))}return A("iframe_ready",{reload_supported:!0}),s}async function vs(){if(Mt(window))return!0;try{return await _({method:"web_app_request_theme",event:"theme_changed",timeout:100}),!0}catch{return!1}}function be(e){return e instanceof q}function Ss(e,t){return be(e)&&e.type===t}function dt(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 we{constructor(t,s,n=A){h(this,"history");h(this,"ee",new N);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 l(At,"History should not be empty.");if(s<0||s>=t.length)throw l(It,"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,k("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,dt(t,this.current.pathname))}replace(t){this.replaceAndMove(this.index,dt(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 _t({params:e,...t}){return{...e||{hash:"",search:""},...t}}function B(e,t){return e.startsWith(t)?e:`${t}${e}`}function O(e){return new URL(typeof e=="string"?e:`${e.pathname||""}${B(e.search||"","?")}${B(e.hash||"","#")}`,"http://a")}function L(e){const t=typeof e=="string"?e.startsWith("/"):!!(e.pathname&&e.pathname.startsWith("/")),s=O(e);return`${t?s.pathname:s.pathname.slice(1)}${s.search}${s.hash}`}function ft(e,t,s){let n,i;typeof e=="string"?n=e:(n=L(e),s=e.state,i=e.id);const{pathname:o,search:a,hash:c}=new URL(n,`http://a${B(t,"/")}`);return{id:i,pathname:o,params:{hash:c,search:a,state:s}}}async function $(e){return e===0?!0:Promise.race([new Promise(t=>{const s=J("popstate",()=>{s(),t(!0)});window.history.go(e)}),new Promise(t=>{setTimeout(t,50,!1)})])}async function Rs(){if(window.history.length<=1||(window.history.pushState(null,""),await $(1-window.history.length)))return;let t=await $(-1);for(;t;)t=await $(-1)}function gt(e){return O(e).pathname}const me=0,bt=1,wt=2;class mt{constructor(t,s,{postEvent:n,hashMode:i,base:o}={}){h(this,"navigator");h(this,"ee",new N);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===me?window.history.forward():t===bt&&this.back(),t===wt&&this.forward()});h(this,"onNavigatorChange",async({to:t,from:s,delta:n})=>{this.attached&&await this.syncHistory(),this.ee.emit("change",{delta:n,from:_t(s),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 we(t.map(a=>ft(a,"/")),s,n),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,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(_t)}get path(){return L(this)}get pathname(){return this.navigator.current.pathname}parsePath(t){let s=O(t);return this.hashMode&&(s=O(s.hash.slice(1))),{pathname:s.pathname,search:s.search,hash:s.hash}}push(t,s){const n=ft(t,this.path),{state:i=s}=n.params;this.navigator.push({...n,params:{...n.params,state:i}})}replace(t,s){const n=ft(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)+B(L(t),"/");return this.hashMode?B(s.slice(1),this.hashMode==="default"?"#":"#/"):s}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const{state:t}=this,s=this.renderPath(this);await Rs(),this.hasPrev&&this.hasNext?(window.history.replaceState(bt,""),window.history.pushState(t,"",s),window.history.pushState(wt,""),await $(-1)):this.hasPrev?(window.history.replaceState(bt,""),window.history.pushState(t,"",s)):this.hasNext?(window.history.replaceState(t,s),window.history.pushState(wt,""),await $(-1)):(window.history.replaceState(me,""),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 ye(e){e||(e={});const{href:t,hash:s}=window.location;let n=L(e.hashMode?s.includes("?")?s.slice(1):`?${s.slice(1)}`:t);const i=e.base?gt(e.base):void 0;if(i){if(!n.startsWith(i))throw l(qt,`Path "${n}" expected to be starting with "${i}"`);n=n.slice(i.length)}return new mt([n],0,e)}function Ps(e){const t=e.match(/#(.+)/);return t?t[1]:null}function Ts(e,t){if(ot()){const s=sessionStorage.getItem(e);if(s)try{const{index:n,history:i}=JSON.parse(s);return new mt(i,n,t)}catch(n){console.error("Unable to restore hash navigator state.",n)}}return ye(t)}function Cs(e,t){const s=Ts(e,t),n=()=>sessionStorage.setItem(e,JSON.stringify({index:s.index,history:s.history}));return s.on("change",n),n(),s}return r.BackButton=Wt,r.BasicNavigator=we,r.BiometryManager=at,r.BrowserNavigator=mt,r.ClosingBehavior=se,r.CloudStorage=re,r.ERR_INVALID_PATH_BASE=qt,r.ERR_INVOKE_CUSTOM_METHOD_RESPONSE=Pt,r.ERR_METHOD_PARAMETER_UNSUPPORTED=St,r.ERR_METHOD_UNSUPPORTED=vt,r.ERR_NAVIGATION_HISTORY_EMPTY=At,r.ERR_NAVIGATION_INDEX_INVALID=It,r.ERR_NAVIGATION_ITEM_INVALID=Pe,r.ERR_PARSE=Q,r.ERR_SSR_INIT=H,r.ERR_SSR_POST_EVENT=Nt,r.ERR_TIMED_OUT=Tt,r.ERR_UNEXPECTED_TYPE=Ct,r.ERR_UNKNOWN_ENV=Rt,r.EventEmitter=N,r.HapticFeedback=oe,r.InitData=ae,r.Invoice=ce,r.MainButton=he,r.MiniApp=pe,r.Popup=le,r.QRScanner=de,r.SDKError=q,r.SettingsButton=_e,r.ThemeParams=fe,r.Utils=ge,r.Viewport=lt,r.array=ne,r.bindMiniAppCSSVars=ws,r.bindThemeParamsCSSVars=ms,r.bindViewportCSSVars=ys,r.boolean=y,r.captureSameReq=Z,r.classNames=x,r.compareVersions=Vt,r.createBrowserNavigatorFromLocation=ye,r.createPostEvent=$t,r.createSafeURL=O,r.date=it,r.getHash=Ps,r.getPathname=gt,r.initBackButton=Je,r.initBiometryManager=Qe,r.initClosingBehavior=Ye,r.initCloudStorage=Ze,r.initHapticFeedback=ts,r.initInitData=es,r.initInvoice=ns,r.initMainButton=is,r.initMiniApp=as,r.initNavigator=Cs,r.initPopup=hs,r.initQRScanner=us,r.initSettingsButton=ps,r.initThemeParams=ls,r.initUtils=_s,r.initViewport=bs,r.initWeb=Es,r.invokeCustomMethod=I,r.isColorDark=et,r.isIframe=Bt,r.isPageReload=ot,r.isRGB=G,r.isRGBShort=Dt,r.isSDKError=be,r.isSDKErrorOfType=Ss,r.isSSR=P,r.isTMA=vs,r.json=d,r.mergeClassNames=Oe,r.number=S,r.off=k,r.on=w,r.parseInitData=ss,r.parseLaunchParams=rt,r.parseThemeParams=ut,r.postEvent=A,r.request=_,r.requestBiometryInfo=ee,r.requestThemeParams=ds,r.requestViewport=pt,r.retrieveLaunchParams=Zt,r.rgb=X,r.searchParams=F,r.serializeLaunchParams=Xt,r.serializeThemeParams=Kt,r.setCSSVar=v,r.setDebug=Se,r.setTargetOrigin=Be,r.string=u,r.subscribe=yt,r.supports=R,r.targetOrigin=Lt,r.toRGB=K,r.unsubscribe=m,r.urlToPath=L,r.withTimeout=tt,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),r}({});
|
|
2
2
|
//# sourceMappingURL=index.iife.js.map
|