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