@vbotma/bridge 2.2.6 → 2.2.7
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/env/host/bridge.d.ts +48 -0
- package/dist/dts/events/createEmitter.d.ts +2 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +3 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +276 -237
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
this.tapps=this.tapps||{};this.tapps.bridge=(function(f){"use strict";let A;function Ve(e){return{lang:(e==null?void 0:e.lang)??(A==null?void 0:A.lang),message:e==null?void 0:e.message,abortEarly:(e==null?void 0:e.abortEarly)??(A==null?void 0:A.abortEarly),abortPipeEarly:(e==null?void 0:e.abortPipeEarly)??(A==null?void 0:A.abortPipeEarly)}}let ae;function zt(e){return ae==null?void 0:ae.get(e)}let oe;function Jt(e){return oe==null?void 0:oe.get(e)}let ce;function Gt(e,t){var n;return(n=ce==null?void 0:ce.get(e))==null?void 0:n.get(t)}function Kt(e){var n,r;const t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&((r=(n=Object.getPrototypeOf(e))==null?void 0:n.constructor)==null?void 0:r.name))??"null":t}function w(e,t,n,r,s){const i=s&&"input"in s?s.input:n.value,u=(s==null?void 0:s.expected)??e.expects??null,o=(s==null?void 0:s.received)??Kt(i),c={kind:e.kind,type:e.type,input:i,expected:u,received:o,message:`Invalid ${t}: ${u?`Expected ${u} but r`:"R"}eceived ${o}`,requirement:e.requirement,path:s==null?void 0:s.path,issues:s==null?void 0:s.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},a=e.kind==="schema",l=(s==null?void 0:s.message)??e.message??Gt(e.reference,c.lang)??(a?Jt(c.lang):null)??r.message??zt(c.lang);l!==void 0&&(c.message=typeof l=="function"?l(c):l),a&&(n.typed=!1),n.issues?n.issues.push(c):n.issues=[c]}function E(e){return{version:1,vendor:"valibot",validate(t){return e["~run"]({value:t},Ve())}}}function De(e,t){return Object.hasOwn(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function Ht(e,t){const n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}var Qt=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function Q(e,t){return{kind:"validation",type:"check",reference:Q,async:!1,expects:null,requirement:e,message:t,"~run"(n,r){return n.typed&&!this.requirement(n.value)&&w(this,"input",n,r),n}}}function Te(e){return{kind:"validation",type:"integer",reference:Te,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(t,n){return t.typed&&!this.requirement(t.value)&&w(this,"integer",t,n),t}}}function C(e){return{kind:"transformation",type:"transform",reference:C,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}function Yt(e,t,n){return typeof e.fallback=="function"?e.fallback(t,n):e.fallback}function le(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function fe(e,t){return!e["~run"]({value:t},{abortEarly:!0}).issues}function Be(){return{kind:"schema",type:"any",reference:Be,expects:"any",async:!1,get"~standard"(){return E(this)},"~run"(e){return e.typed=!0,e}}}function F(e){return{kind:"schema",type:"boolean",reference:F,expects:"boolean",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,n),t}}}function Ue(e){return{kind:"schema",type:"date",reference:Ue,expects:"Date",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return t.value instanceof Date?isNaN(t.value)?w(this,"type",t,n,{received:'"Invalid Date"'}):t.typed=!0:w(this,"type",t,n),t}}}function pe(e){return{kind:"schema",type:"function",reference:pe,expects:"Function",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="function"?t.typed=!0:w(this,"type",t,n),t}}}function _e(e,t){return{kind:"schema",type:"instance",reference:_e,expects:e.name,async:!1,class:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){return n.value instanceof this.class?n.typed=!0:w(this,"type",n,r),n}}}function b(e,t){return{kind:"schema",type:"loose_object",reference:b,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){var i;const s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};for(const u in this.entries){const o=this.entries[u];if(u in s||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){const c=u in s?s[u]:le(o),a=o["~run"]({value:c},r);if(a.issues){const l={type:"object",origin:"value",input:s,key:u,value:c};for(const p of a.issues)p.path?p.path.unshift(l):p.path=[l],(i=n.issues)==null||i.push(p);if(n.issues||(n.issues=a.issues),r.abortEarly){n.typed=!1;break}}a.typed||(n.typed=!1),n.value[u]=a.value}else if(o.fallback!==void 0)n.value[u]=Yt(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"&&(w(this,"key",n,r,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:s,key:u,value:s[u]}]}),r.abortEarly))break}if(!n.issues||!r.abortEarly)for(const u in s)De(s,u)&&!(u in this.entries)&&(n.value[u]=s[u])}else w(this,"type",n,r);return n}}}function W(e,t){return{kind:"schema",type:"nullish",reference:W,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return E(this)},"~run"(n,r){return(n.value===null||n.value===void 0)&&(this.default!==void 0&&(n.value=le(this,n,r)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,r)}}}function V(e){return{kind:"schema",type:"number",reference:V,expects:"number",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,n),t}}}function h(e,t){return{kind:"schema",type:"optional",reference:h,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return E(this)},"~run"(n,r){return n.value===void 0&&(this.default!==void 0&&(n.value=le(this,n,r)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,r)}}}function Ne(e,t,n){return{kind:"schema",type:"record",reference:Ne,expects:"Object",async:!1,key:e,value:t,message:n,get"~standard"(){return E(this)},"~run"(r,s){var u,o;const i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(const c in i)if(De(i,c)){const a=i[c],l=this.key["~run"]({value:c},s);if(l.issues){const d={type:"object",origin:"key",input:i,key:c,value:a};for(const v of l.issues)v.path=[d],(u=r.issues)==null||u.push(v);if(r.issues||(r.issues=l.issues),s.abortEarly){r.typed=!1;break}}const p=this.value["~run"]({value:a},s);if(p.issues){const d={type:"object",origin:"value",input:i,key:c,value:a};for(const v of p.issues)v.path?v.path.unshift(d):v.path=[d],(o=r.issues)==null||o.push(v);if(r.issues||(r.issues=p.issues),s.abortEarly){r.typed=!1;break}}(!l.typed||!p.typed)&&(r.typed=!1),l.typed&&(r.value[l.value]=p.value)}}else w(this,"type",r,s);return r}}}function _(e){return{kind:"schema",type:"string",reference:_,expects:"string",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,n),t}}}function xe(e){let t;if(e)for(const n of e)t?t.push(...n.issues):t=n.issues;return t}function Y(e,t){return{kind:"schema",type:"union",reference:Y,expects:Ht(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){let s,i,u;for(const o of this.options){const c=o["~run"]({value:n.value},r);if(c.typed)if(c.issues)i?i.push(c):i=[c];else{s=c;break}else u?u.push(c):u=[c]}if(s)return s;if(i){if(i.length===1)return i[0];w(this,"type",n,r,{issues:xe(i)}),n.typed=!0}else{if((u==null?void 0:u.length)===1)return u[0];w(this,"type",n,r,{issues:xe(u)})}return n}}}function he(){return{kind:"schema",type:"unknown",reference:he,expects:"unknown",async:!1,get"~standard"(){return E(this)},"~run"(e){return e.typed=!0,e}}}function x(e,t,n){const r=e["~run"]({value:t},Ve(n));if(r.issues)throw new Qt(r.issues);return r.value}function O(...e){return{...e[0],pipe:e,get"~standard"(){return E(this)},"~run"(t,n){for(const r of e)if(r.kind!=="metadata"){if(t.issues&&(r.kind==="schema"||r.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r["~run"](t,n))}return t}}}function de(e){return fe(b({VBotWebviewProxy:b({postEvent:pe()})}),e)}function ve(){try{return window.self!==window.top}catch{return!0}}var Zt=Object.defineProperty,Xt=(e,t,n)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ze=(e,t,n)=>Xt(e,typeof t!="symbol"?t+"":t,n),en=Object.defineProperty,tn=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t,n)=>tn(e,typeof t!="symbol"?t+"":t,n);function Je(e){return t=>t instanceof e}function Ge(e,t){const n=class extends Error{constructor(...s){const i=typeof t=="function"?t(...s):typeof t=="string"?[t]:t||[];super(...i),this.name=e}};me(n,"is",Je(n));let r=n;return Object.defineProperty(r,"name",{value:e}),r}function nn(e,t,n){const r=class extends Ge(e,n){constructor(...i){super(...i),me(this,"data"),this.data=t(...i)}};me(r,"is",Je(r));let s=r;return Object.defineProperty(s,"name",{value:e}),s}let Ke=class extends Ge("CancelledError","Promise was canceled"){},ye=class extends nn("TimeoutError",t=>({timeout:t}),(t,n)=>[`Timeout reached: ${t}ms`,{cause:n}]){};const rn=Symbol("resolved");function sn(e){return{tag:rn,value:e}}function He(e,t){return e.reject=t.reject,e.resolve=t.resolve,e}class q extends Promise{constructor(t,n){let r,s,i,u;typeof t=="function"?(i=t,u=n||{}):u=t||{};let o,c;const a=()=>!!c,l=()=>!!o;let p={};const d=[],v=()=>{d.forEach(Le=>Le()),d.splice(0,d.length),p={}},S=new AbortController,I=()=>l()||a();super((Le,$r)=>{const{abortOnResolve:Cr=!0,abortOnReject:Fr=!0}=u;s=m=>{var $,k;I()||(Le(m),o=[m],($=p.resolved)==null||$.forEach(P=>P(m)),(k=p.finalized)==null||k.forEach(P=>P({kind:"resolved",result:m})),v(),Cr&&S.abort(sn(m)))},r=m=>{var $,k;I()||($r(m),c=[m],($=p.rejected)==null||$.forEach(P=>P(m)),(k=p.finalized)==null||k.forEach(P=>P({kind:"rejected",reason:m})),v(),Fr&&S.abort(m))};const{abortSignal:N}=u;if(N){if(N.aborted)return r(N.reason);const m=()=>{r(N.reason)};N.addEventListener("abort",m,!0),d.push(()=>{N.removeEventListener("abort",m,!0)})}const{timeout:We}=u;if(We){const m=setTimeout(()=>{r(new ye(We))},We);d.push(()=>{clearTimeout(m)})}try{const m=()=>{},$=i&&i(s,r,{abortSignal:S.signal,get isRejected(){return a()},get isResolved(){return l()},on(k,P){if(o||c){if(k==="finalized"){const ue=o?{kind:"resolved",result:o[0]}:{kind:"rejected",reason:c[0]};P(ue)}else k==="resolved"&&o?P(o[0]):k==="rejected"&&c&&P(c[0]);return m}return p[k]||(p[k]=[]),p[k].push(P),()=>{const ue=p[k]||[],xt=ue.indexOf(P);xt>=0&&ue.splice(xt,1)}},get result(){return o==null?void 0:o[0]},get rejectReason(){return c==null?void 0:c[0]},throwIfRejected(){if(c)throw c[0]}});$ instanceof Promise&&$.catch(r)}catch(m){r(m)}}),ze(this,"reject"),ze(this,"resolve"),this.reject=r,this.resolve=s}static fn(t,n){return new q(async(r,s,i)=>{try{r(await t(i))}catch(u){s(u)}},n)}static resolve(t){return this.fn(()=>t)}static reject(t){return new q((n,r)=>{r(t)})}cancel(){this.reject(new Ke)}catch(t){return this.then(void 0,t)}finally(t){return He(super.finally(t),this)}then(t,n){return He(super.then(t,n),this)}}var un=function(e,t,n){if(n||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};function an(e){return e}function Qe(e,t,n,r,s,i,u,o,c){switch(arguments.length){case 1:return e;case 2:return function(){return t(e.apply(this,arguments))};case 3:return function(){return n(t(e.apply(this,arguments)))};case 4:return function(){return r(n(t(e.apply(this,arguments))))};case 5:return function(){return s(r(n(t(e.apply(this,arguments)))))};case 6:return function(){return i(s(r(n(t(e.apply(this,arguments))))))};case 7:return function(){return u(i(s(r(n(t(e.apply(this,arguments)))))))};case 8:return function(){return o(u(i(s(r(n(t(e.apply(this,arguments))))))))};case 9:return function(){return c(o(u(i(s(r(n(t(e.apply(this,arguments)))))))))}}}function y(e,t,n,r,s,i,u,o,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return n(t(e));case 4:return r(n(t(e)));case 5:return s(r(n(t(e))));case 6:return i(s(r(n(t(e)))));case 7:return u(i(s(r(n(t(e))))));case 8:return o(u(i(s(r(n(t(e)))))));case 9:return c(o(u(i(s(r(n(t(e))))))));default:{for(var a=arguments[0],l=1;l<arguments.length;l++)a=arguments[l](a);return a}}}var Z=function(e,t){var n=typeof e=="number"?function(r){return r.length>=e}:e;return function(){var r=Array.from(arguments);return n(arguments)?t.apply(this,r):function(s){return t.apply(void 0,un([s],r,!1))}}},on={_tag:"None"},cn=function(e){return{_tag:"Some",value:e}},ln=function(e){return e._tag==="Left"},Ye=function(e){return{_tag:"Left",left:e}},Ze=function(e){return{_tag:"Right",right:e}},fn=on,pn=cn,_n=function(e){return e._tag==="None"},hn=function(e,t){return function(n){return _n(n)?e():t(n.value)}},dn=hn,j=Ye,g=Ze,Xe=Z(2,function(e,t){return D(e)?e:t(e.right)}),vn=function(e){return function(t){return D(t)?t:g(e(t.right))}},mn=function(e,t){return function(n){return D(n)?j(e(n.left)):g(t(n.right))}},yn=function(e){return function(t){return D(t)?j(e(t.left)):t}},D=ln,et=function(e,t){return function(n){return D(n)?e(n.left):t(n.right)}},bn=et,z=et,gn=z,X=function(e,t){try{return g(e())}catch(n){return j(t(n))}},wn=Xe,En=Xe;function kn(e){return Qe(g,e.of)}function Pn(e){return Qe(j,e.of)}function Sn(e){return function(t,n){return e.chain(t,function(r){return D(r)?e.of(r):n(r.right)})}}function jn(e){return function(t,n,r){return e.map(t,mn(n,r))}}function An(e){return function(t,n){return function(r){return e.map(r,z(t,n))}}}var On=function(e){return X(function(){return JSON.parse(e)},an)},tt=function(e,t){return y(e,Rn(t))},Mn=function(e,t){return y(e,In(t))},Rn=function(e){return function(t){return function(){return Promise.resolve().then(t).then(e)}}},In=function(e){return function(t){return function(){return Promise.all([Promise.resolve().then(t),Promise.resolve().then(e)]).then(function(n){var r=n[0],s=n[1];return r(s)})}}},be=function(e){return function(){return Promise.resolve(e)}},$n=Z(2,function(e,t){return function(){return Promise.resolve().then(e).then(function(n){return t(n)()})}}),nt="Task",rt={URI:nt,map:tt},st={of:be},Cn={URI:nt,map:tt,of:be,ap:Mn,chain:$n},Fn=function(e,t,n,r){function s(i){return i instanceof n?i:new n(function(u){u(i)})}return new(n||(n=Promise))(function(i,u){function o(l){try{a(r.next(l))}catch(p){u(p)}}function c(l){try{a(r.throw(l))}catch(p){u(p)}}function a(l){l.done?i(l.value):s(l.value).then(o,c)}a((r=r.apply(e,t||[])).next())})},qn=function(e,t){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,s,i,u;return u={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function o(a){return function(l){return c([a,l])}}function c(a){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(n=0)),n;)try{if(r=1,s&&(i=a[0]&2?s.return:a[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,a[1])).done)return i;switch(s=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){n.label=a[1];break}if(a[0]===6&&n.label<i[1]){n.label=i[1],i=a;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(a);break}i[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(l){a=[6,l],s=0}finally{r=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},it=Pn(st),ge=kn(st),Ln=be,ee=An(rt),Wn=ee,Vn=function(e,t){return function(){return Fn(void 0,void 0,void 0,function(){var n;return qn(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,e().then(Ze)];case 1:return[2,r.sent()];case 2:return n=r.sent(),[2,Ye(t(n))];case 3:return[2]}})})}},ut=Z(3,jn(rt)),at=Z(2,Sn(Cn)),Dn=at,we=at;function Tn(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Bn(e){return Object.entries(e).reduce((t,[n,r])=>(t[Tn(n)]=r,t),{})}function Ee(e){const t=Bn(e);for(const n in t){const r=t[n];r&&typeof r=="object"&&!(r instanceof Date)&&(t[n]=Array.isArray(r)?r.map(Ee):Ee(r))}return t}function ot(e){return`tapps/${e}`}function ct(e,t){sessionStorage.setItem(ot(e),JSON.stringify(t))}function Un(e){const t=sessionStorage.getItem(ot(e));try{return t?JSON.parse(t):void 0}catch{}}function lt(...e){const t=e.flat(1);return[t.push.bind(t),()=>{t.forEach(n=>{n()})}]}function ft(e,t){t||(t={});const{textColor:n,bgColor:r,shouldLog:s}=t,i=s===void 0?!0:s,u=typeof i=="boolean"?()=>i:i,o=(c,a,...l)=>{if(a||u()){const p="font-weight:bold;padding:0 5px;border-radius:100px",[d,v,S]={log:["#0089c3","white","INFO"],error:["#ff0000F0","white","ERR"],warn:["#D38E15","white","WARN"]}[c];console[c](`%c${S} ${Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(new Date)}%c %c${e}`,`${p};background-color:${d};color:${v}`,"",`${p};${n?`color:${n};`:""}${r?`background-color:${r}`:""}`,...l)}};return[["log","forceLog"],["warn","forceWarn"],["error","forceError"]].reduce((c,[a,l])=>(c[a]=o.bind(void 0,a,!1),c[l]=o.bind(void 0,a,!0),c),{})}function J(e){const t=n=>{throw n};return typeof e=="function"?q.resolve(y(e,ee(t,n=>n))()):y(e,z(t,n=>n))}function G(e){return Object.assign((...t)=>J(e(...t)),e)}const ke=Object.assign((e,t)=>y(Vn(()=>new q((n,r,s)=>e(i=>n(g(i)),i=>n(j(i)),s),t),n=>n),we(z(it,ge))),{fn:(e,t)=>ke((n,r,s)=>{const i=e(s);y(typeof i=="function"?i:Ln(i),Wn(r,n))()},t)});var Nn=Object.defineProperty,xn=(e,t,n)=>t in e?Nn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pe=(e,t,n)=>xn(e,typeof t!="symbol"?t+"":t,n);function pt(e){return t=>t instanceof e}function T(e,t){const n=class extends Error{constructor(...i){const u=typeof t=="function"?t(...i):typeof t=="string"?[t]:t||[];super(...u),this.name=e}};Pe(n,"is",pt(n));let r=n;return Object.defineProperty(r,"name",{value:e}),r}function zn(e,t,n){const r=class extends T(e,n){constructor(...u){super(...u),Pe(this,"data"),this.data=t(...u)}};Pe(r,"is",pt(r));let s=r;return Object.defineProperty(s,"name",{value:e}),s}class _t extends T("MethodUnsupportedError",(t,n)=>[`Method "${t}" is unsupported in Mini Apps version ${n}`]){}class ht extends T("MethodParameterUnsupportedError",(t,n,r)=>[`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${r}`]){}class dt extends zn("LaunchParamsRetrieveError",t=>({errors:t}),t=>[["Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?","📖 Refer to docs for more information:","https://docs.vbot-mini-apps.com/packages/tma-js-bridge/environment","","Collected errors:",...t.map(({source:n,error:r})=>`Source: ${n} / ${r instanceof Error?r.message:String(r)}`)].join(`
|
|
2
|
-
`)]){}class
|
|
3
|
-
`),t,
|
|
1
|
+
this.tapps=this.tapps||{};this.tapps.bridge=(function(f){"use strict";let A;function Ve(e){return{lang:(e==null?void 0:e.lang)??(A==null?void 0:A.lang),message:e==null?void 0:e.message,abortEarly:(e==null?void 0:e.abortEarly)??(A==null?void 0:A.abortEarly),abortPipeEarly:(e==null?void 0:e.abortPipeEarly)??(A==null?void 0:A.abortPipeEarly)}}let ue;function Gt(e){return ue==null?void 0:ue.get(e)}let ce;function Ht(e){return ce==null?void 0:ce.get(e)}let le;function Kt(e,t){var n;return(n=le==null?void 0:le.get(e))==null?void 0:n.get(t)}function Qt(e){var n,r;const t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&((r=(n=Object.getPrototypeOf(e))==null?void 0:n.constructor)==null?void 0:r.name))??"null":t}function w(e,t,n,r,s){const i=s&&"input"in s?s.input:n.value,o=(s==null?void 0:s.expected)??e.expects??null,u=(s==null?void 0:s.received)??Qt(i),c={kind:e.kind,type:e.type,input:i,expected:o,received:u,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${u}`,requirement:e.requirement,path:s==null?void 0:s.path,issues:s==null?void 0:s.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},a=e.kind==="schema",l=(s==null?void 0:s.message)??e.message??Kt(e.reference,c.lang)??(a?Ht(c.lang):null)??r.message??Gt(c.lang);l!==void 0&&(c.message=typeof l=="function"?l(c):l),a&&(n.typed=!1),n.issues?n.issues.push(c):n.issues=[c]}function E(e){return{version:1,vendor:"valibot",validate(t){return e["~run"]({value:t},Ve())}}}function De(e,t){return Object.hasOwn(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function Yt(e,t){const n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}var Zt=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function Y(e,t){return{kind:"validation",type:"check",reference:Y,async:!1,expects:null,requirement:e,message:t,"~run"(n,r){return n.typed&&!this.requirement(n.value)&&w(this,"input",n,r),n}}}function Te(e){return{kind:"validation",type:"integer",reference:Te,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(t,n){return t.typed&&!this.requirement(t.value)&&w(this,"integer",t,n),t}}}function $(e){return{kind:"transformation",type:"transform",reference:$,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}function Xt(e,t,n){return typeof e.fallback=="function"?e.fallback(t,n):e.fallback}function fe(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function pe(e,t){return!e["~run"]({value:t},{abortEarly:!0}).issues}function Ue(){return{kind:"schema",type:"any",reference:Ue,expects:"any",async:!1,get"~standard"(){return E(this)},"~run"(e){return e.typed=!0,e}}}function F(e){return{kind:"schema",type:"boolean",reference:F,expects:"boolean",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,n),t}}}function Ne(e){return{kind:"schema",type:"date",reference:Ne,expects:"Date",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return t.value instanceof Date?isNaN(t.value)?w(this,"type",t,n,{received:'"Invalid Date"'}):t.typed=!0:w(this,"type",t,n),t}}}function de(e){return{kind:"schema",type:"function",reference:de,expects:"Function",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="function"?t.typed=!0:w(this,"type",t,n),t}}}function _e(e,t){return{kind:"schema",type:"instance",reference:_e,expects:e.name,async:!1,class:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){return n.value instanceof this.class?n.typed=!0:w(this,"type",n,r),n}}}function b(e,t){return{kind:"schema",type:"loose_object",reference:b,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){var i;const s=n.value;if(s&&typeof s=="object"){n.typed=!0,n.value={};for(const o in this.entries){const u=this.entries[o];if(o in s||(u.type==="exact_optional"||u.type==="optional"||u.type==="nullish")&&u.default!==void 0){const c=o in s?s[o]:fe(u),a=u["~run"]({value:c},r);if(a.issues){const l={type:"object",origin:"value",input:s,key:o,value:c};for(const p of a.issues)p.path?p.path.unshift(l):p.path=[l],(i=n.issues)==null||i.push(p);if(n.issues||(n.issues=a.issues),r.abortEarly){n.typed=!1;break}}a.typed||(n.typed=!1),n.value[o]=a.value}else if(u.fallback!==void 0)n.value[o]=Xt(u);else if(u.type!=="exact_optional"&&u.type!=="optional"&&u.type!=="nullish"&&(w(this,"key",n,r,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:s,key:o,value:s[o]}]}),r.abortEarly))break}if(!n.issues||!r.abortEarly)for(const o in s)De(s,o)&&!(o in this.entries)&&(n.value[o]=s[o])}else w(this,"type",n,r);return n}}}function q(e,t){return{kind:"schema",type:"nullish",reference:q,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return E(this)},"~run"(n,r){return(n.value===null||n.value===void 0)&&(this.default!==void 0&&(n.value=fe(this,n,r)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,r)}}}function B(e){return{kind:"schema",type:"number",reference:B,expects:"number",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,n),t}}}function _(e,t){return{kind:"schema",type:"optional",reference:_,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return E(this)},"~run"(n,r){return n.value===void 0&&(this.default!==void 0&&(n.value=fe(this,n,r)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,r)}}}function xe(e,t,n){return{kind:"schema",type:"record",reference:xe,expects:"Object",async:!1,key:e,value:t,message:n,get"~standard"(){return E(this)},"~run"(r,s){var o,u;const i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(const c in i)if(De(i,c)){const a=i[c],l=this.key["~run"]({value:c},s);if(l.issues){const h={type:"object",origin:"key",input:i,key:c,value:a};for(const v of l.issues)v.path=[h],(o=r.issues)==null||o.push(v);if(r.issues||(r.issues=l.issues),s.abortEarly){r.typed=!1;break}}const p=this.value["~run"]({value:a},s);if(p.issues){const h={type:"object",origin:"value",input:i,key:c,value:a};for(const v of p.issues)v.path?v.path.unshift(h):v.path=[h],(u=r.issues)==null||u.push(v);if(r.issues||(r.issues=p.issues),s.abortEarly){r.typed=!1;break}}(!l.typed||!p.typed)&&(r.typed=!1),l.typed&&(r.value[l.value]=p.value)}}else w(this,"type",r,s);return r}}}function d(e){return{kind:"schema",type:"string",reference:d,expects:"string",async:!1,message:e,get"~standard"(){return E(this)},"~run"(t,n){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,n),t}}}function Je(e){let t;if(e)for(const n of e)t?t.push(...n.issues):t=n.issues;return t}function Z(e,t){return{kind:"schema",type:"union",reference:Z,expects:Yt(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return E(this)},"~run"(n,r){let s,i,o;for(const u of this.options){const c=u["~run"]({value:n.value},r);if(c.typed)if(c.issues)i?i.push(c):i=[c];else{s=c;break}else o?o.push(c):o=[c]}if(s)return s;if(i){if(i.length===1)return i[0];w(this,"type",n,r,{issues:Je(i)}),n.typed=!0}else{if((o==null?void 0:o.length)===1)return o[0];w(this,"type",n,r,{issues:Je(o)})}return n}}}function he(){return{kind:"schema",type:"unknown",reference:he,expects:"unknown",async:!1,get"~standard"(){return E(this)},"~run"(e){return e.typed=!0,e}}}function x(e,t,n){const r=e["~run"]({value:t},Ve(n));if(r.issues)throw new Zt(r.issues);return r.value}function O(...e){return{...e[0],pipe:e,get"~standard"(){return E(this)},"~run"(t,n){for(const r of e)if(r.kind!=="metadata"){if(t.issues&&(r.kind==="schema"||r.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r["~run"](t,n))}return t}}}function ve(e){return pe(b({VBotWebviewProxy:b({postEvent:de()})}),e)}function me(){try{return window.self!==window.top}catch{return!0}}var en=Object.defineProperty,tn=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ze=(e,t,n)=>tn(e,typeof t!="symbol"?t+"":t,n),nn=Object.defineProperty,rn=(e,t,n)=>t in e?nn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ye=(e,t,n)=>rn(e,typeof t!="symbol"?t+"":t,n);function Ge(e){return t=>t instanceof e}function He(e,t){const n=class extends Error{constructor(...s){const i=typeof t=="function"?t(...s):typeof t=="string"?[t]:t||[];super(...i),this.name=e}};ye(n,"is",Ge(n));let r=n;return Object.defineProperty(r,"name",{value:e}),r}function sn(e,t,n){const r=class extends He(e,n){constructor(...i){super(...i),ye(this,"data"),this.data=t(...i)}};ye(r,"is",Ge(r));let s=r;return Object.defineProperty(s,"name",{value:e}),s}let Ke=class extends He("CancelledError","Promise was canceled"){},be=class extends sn("TimeoutError",t=>({timeout:t}),(t,n)=>[`Timeout reached: ${t}ms`,{cause:n}]){};const on=Symbol("resolved");function an(e){return{tag:on,value:e}}function Qe(e,t){return e.reject=t.reject,e.resolve=t.resolve,e}class L extends Promise{constructor(t,n){let r,s,i,o;typeof t=="function"?(i=t,o=n||{}):o=t||{};let u,c;const a=()=>!!c,l=()=>!!u;let p={};const h=[],v=()=>{h.forEach(qe=>qe()),h.splice(0,h.length),p={}},S=new AbortController,I=()=>l()||a();super((qe,Lr)=>{const{abortOnResolve:Wr=!0,abortOnReject:qr=!0}=o;s=m=>{var C,k;I()||(qe(m),u=[m],(C=p.resolved)==null||C.forEach(P=>P(m)),(k=p.finalized)==null||k.forEach(P=>P({kind:"resolved",result:m})),v(),Wr&&S.abort(an(m)))},r=m=>{var C,k;I()||(Lr(m),c=[m],(C=p.rejected)==null||C.forEach(P=>P(m)),(k=p.finalized)==null||k.forEach(P=>P({kind:"rejected",reason:m})),v(),qr&&S.abort(m))};const{abortSignal:N}=o;if(N){if(N.aborted)return r(N.reason);const m=()=>{r(N.reason)};N.addEventListener("abort",m,!0),h.push(()=>{N.removeEventListener("abort",m,!0)})}const{timeout:Be}=o;if(Be){const m=setTimeout(()=>{r(new be(Be))},Be);h.push(()=>{clearTimeout(m)})}try{const m=()=>{},C=i&&i(s,r,{abortSignal:S.signal,get isRejected(){return a()},get isResolved(){return l()},on(k,P){if(u||c){if(k==="finalized"){const ae=u?{kind:"resolved",result:u[0]}:{kind:"rejected",reason:c[0]};P(ae)}else k==="resolved"&&u?P(u[0]):k==="rejected"&&c&&P(c[0]);return m}return p[k]||(p[k]=[]),p[k].push(P),()=>{const ae=p[k]||[],zt=ae.indexOf(P);zt>=0&&ae.splice(zt,1)}},get result(){return u==null?void 0:u[0]},get rejectReason(){return c==null?void 0:c[0]},throwIfRejected(){if(c)throw c[0]}});C instanceof Promise&&C.catch(r)}catch(m){r(m)}}),ze(this,"reject"),ze(this,"resolve"),this.reject=r,this.resolve=s}static fn(t,n){return new L(async(r,s,i)=>{try{r(await t(i))}catch(o){s(o)}},n)}static resolve(t){return this.fn(()=>t)}static reject(t){return new L((n,r)=>{r(t)})}cancel(){this.reject(new Ke)}catch(t){return this.then(void 0,t)}finally(t){return Qe(super.finally(t),this)}then(t,n){return Qe(super.then(t,n),this)}}var un=function(e,t,n){if(n||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};function cn(e){return e}function Ye(e,t,n,r,s,i,o,u,c){switch(arguments.length){case 1:return e;case 2:return function(){return t(e.apply(this,arguments))};case 3:return function(){return n(t(e.apply(this,arguments)))};case 4:return function(){return r(n(t(e.apply(this,arguments))))};case 5:return function(){return s(r(n(t(e.apply(this,arguments)))))};case 6:return function(){return i(s(r(n(t(e.apply(this,arguments))))))};case 7:return function(){return o(i(s(r(n(t(e.apply(this,arguments)))))))};case 8:return function(){return u(o(i(s(r(n(t(e.apply(this,arguments))))))))};case 9:return function(){return c(u(o(i(s(r(n(t(e.apply(this,arguments)))))))))}}}function y(e,t,n,r,s,i,o,u,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return n(t(e));case 4:return r(n(t(e)));case 5:return s(r(n(t(e))));case 6:return i(s(r(n(t(e)))));case 7:return o(i(s(r(n(t(e))))));case 8:return u(o(i(s(r(n(t(e)))))));case 9:return c(u(o(i(s(r(n(t(e))))))));default:{for(var a=arguments[0],l=1;l<arguments.length;l++)a=arguments[l](a);return a}}}var X=function(e,t){var n=typeof e=="number"?function(r){return r.length>=e}:e;return function(){var r=Array.from(arguments);return n(arguments)?t.apply(this,r):function(s){return t.apply(void 0,un([s],r,!1))}}},ln={_tag:"None"},fn=function(e){return{_tag:"Some",value:e}},pn=function(e){return e._tag==="Left"},Ze=function(e){return{_tag:"Left",left:e}},Xe=function(e){return{_tag:"Right",right:e}},dn=ln,_n=fn,hn=function(e){return e._tag==="None"},vn=function(e,t){return function(n){return hn(n)?e():t(n.value)}},mn=vn,j=Ze,g=Xe,et=X(2,function(e,t){return V(e)?e:t(e.right)}),yn=function(e){return function(t){return V(t)?t:g(e(t.right))}},bn=function(e,t){return function(n){return V(n)?j(e(n.left)):g(t(n.right))}},gn=function(e){return function(t){return V(t)?j(e(t.left)):t}},V=pn,tt=function(e,t){return function(n){return V(n)?e(n.left):t(n.right)}},wn=tt,J=tt,En=J,ee=function(e,t){try{return g(e())}catch(n){return j(t(n))}},kn=et,Pn=et;function Sn(e){return Ye(g,e.of)}function jn(e){return Ye(j,e.of)}function An(e){return function(t,n){return e.chain(t,function(r){return V(r)?e.of(r):n(r.right)})}}function On(e){return function(t,n,r){return e.map(t,bn(n,r))}}function Mn(e){return function(t,n){return function(r){return e.map(r,J(t,n))}}}var Rn=function(e){return ee(function(){return JSON.parse(e)},cn)},nt=function(e,t){return y(e,Cn(t))},In=function(e,t){return y(e,$n(t))},Cn=function(e){return function(t){return function(){return Promise.resolve().then(t).then(e)}}},$n=function(e){return function(t){return function(){return Promise.all([Promise.resolve().then(t),Promise.resolve().then(e)]).then(function(n){var r=n[0],s=n[1];return r(s)})}}},ge=function(e){return function(){return Promise.resolve(e)}},Fn=X(2,function(e,t){return function(){return Promise.resolve().then(e).then(function(n){return t(n)()})}}),rt="Task",st={URI:rt,map:nt},it={of:ge},Ln={URI:rt,map:nt,of:ge,ap:In,chain:Fn},Wn=function(e,t,n,r){function s(i){return i instanceof n?i:new n(function(o){o(i)})}return new(n||(n=Promise))(function(i,o){function u(l){try{a(r.next(l))}catch(p){o(p)}}function c(l){try{a(r.throw(l))}catch(p){o(p)}}function a(l){l.done?i(l.value):s(l.value).then(u,c)}a((r=r.apply(e,t||[])).next())})},qn=function(e,t){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,s,i,o;return o={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function u(a){return function(l){return c([a,l])}}function c(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(n=0)),n;)try{if(r=1,s&&(i=a[0]&2?s.return:a[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,a[1])).done)return i;switch(s=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){n.label=a[1];break}if(a[0]===6&&n.label<i[1]){n.label=i[1],i=a;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(a);break}i[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(l){a=[6,l],s=0}finally{r=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},ot=jn(it),we=Sn(it),Bn=ge,te=Mn(st),Vn=te,Dn=function(e,t){return function(){return Wn(void 0,void 0,void 0,function(){var n;return qn(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,e().then(Xe)];case 1:return[2,r.sent()];case 2:return n=r.sent(),[2,Ze(t(n))];case 3:return[2]}})})}},at=X(3,On(st)),ut=X(2,An(Ln)),Tn=ut,Ee=ut;function Un(e){return e.replace(/_[a-z]/g,t=>t[1].toUpperCase())}function Nn(e){return Object.entries(e).reduce((t,[n,r])=>(t[Un(n)]=r,t),{})}function ke(e){const t=Nn(e);for(const n in t){const r=t[n];r&&typeof r=="object"&&!(r instanceof Date)&&(t[n]=Array.isArray(r)?r.map(ke):ke(r))}return t}function ct(e){return`tapps/${e}`}function lt(e,t){sessionStorage.setItem(ct(e),JSON.stringify(t))}function xn(e){const t=sessionStorage.getItem(ct(e));try{return t?JSON.parse(t):void 0}catch{}}function ft(...e){const t=e.flat(1);return[t.push.bind(t),()=>{t.forEach(n=>{n()})}]}function pt(e,t){t||(t={});const{textColor:n,bgColor:r,shouldLog:s}=t,i=s===void 0?!0:s,o=typeof i=="boolean"?()=>i:i,u=(c,a,...l)=>{if(a||o()){const p="font-weight:bold;padding:0 5px;border-radius:100px",[h,v,S]={log:["#0089c3","white","INFO"],error:["#ff0000F0","white","ERR"],warn:["#D38E15","white","WARN"]}[c];console[c](`%c${S} ${Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(new Date)}%c %c${e}`,`${p};background-color:${h};color:${v}`,"",`${p};${n?`color:${n};`:""}${r?`background-color:${r}`:""}`,...l)}};return[["log","forceLog"],["warn","forceWarn"],["error","forceError"]].reduce((c,[a,l])=>(c[a]=u.bind(void 0,a,!1),c[l]=u.bind(void 0,a,!0),c),{})}function z(e){const t=n=>{throw n};return typeof e=="function"?L.resolve(y(e,te(t,n=>n))()):y(e,J(t,n=>n))}function G(e){return Object.assign((...t)=>z(e(...t)),e)}const Pe=Object.assign((e,t)=>y(Dn(()=>new L((n,r,s)=>e(i=>n(g(i)),i=>n(j(i)),s),t),n=>n),Ee(J(ot,we))),{fn:(e,t)=>Pe((n,r,s)=>{const i=e(s);y(typeof i=="function"?i:Bn(i),Vn(r,n))()},t)});var Jn=Object.defineProperty,zn=(e,t,n)=>t in e?Jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t,n)=>zn(e,typeof t!="symbol"?t+"":t,n);function dt(e){return t=>t instanceof e}function D(e,t){const n=class extends Error{constructor(...i){const o=typeof t=="function"?t(...i):typeof t=="string"?[t]:t||[];super(...o),this.name=e}};Se(n,"is",dt(n));let r=n;return Object.defineProperty(r,"name",{value:e}),r}function Gn(e,t,n){const r=class extends D(e,n){constructor(...o){super(...o),Se(this,"data"),this.data=t(...o)}};Se(r,"is",dt(r));let s=r;return Object.defineProperty(s,"name",{value:e}),s}class _t extends D("MethodUnsupportedError",(t,n)=>[`Method "${t}" is unsupported in Mini Apps version ${n}`]){}class ht extends D("MethodParameterUnsupportedError",(t,n,r)=>[`Parameter "${n}" of "${t}" method is unsupported in Mini Apps version ${r}`]){}class vt extends Gn("LaunchParamsRetrieveError",t=>({errors:t}),t=>[["Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?","📖 Refer to docs for more information:","https://docs.vbot-mini-apps.com/packages/tma-js-bridge/environment","","Collected errors:",...t.map(({source:n,error:r})=>`Source: ${n} / ${r instanceof Error?r.message:String(r)}`)].join(`
|
|
2
|
+
`)]){}class mt extends D("InvalidLaunchParamsError",(t,n)=>[`Invalid value for launch params: ${t}`,{cause:n}]){}class je extends D("UnknownEnvError"){}class yt extends D("InvokeCustomMethodError",t=>[`Server returned error: ${t}`]){}function Hn(e){const t=n=>{const r={};return new URLSearchParams(n).forEach((s,i)=>{const o=r[i];Array.isArray(o)?o.push(s):o===void 0?r[i]=s:r[i]=[o,s]}),x(e,r)};return O(Z([d(),_e(URLSearchParams)]),Y(n=>{try{return t(n),!0}catch{return!1}},"The value doesn't match required schema"),$(t))}function Kn(e){return O(d(),Y(t=>{try{return JSON.parse(t),!0}catch{return!1}},"Input is not a valid JSON value"),$(JSON.parse),e)}function M(e){return O(d(),Kn(e))}function bt(e){return O(Z([d(),_e(URLSearchParams)]),Hn(e))}function ne(e){return t=>e.test(t)}const Qn=ne(/^#[\da-f]{3}$/i),Yn=ne(/^#[\da-f]{4}$/i),Zn=ne(/^#[\da-f]{6}$/i),Xn=ne(/^#[\da-f]{8}$/i);function er(e){return[Zn,Xn,Qn,Yn].some(t=>t(e))}function tr(){return b({id:B(),photo_url:_(d()),type:d(),title:d(),username:_(d())})}function gt(){return b({added_to_attachment_menu:_(F()),allows_write_to_pm:_(F()),first_name:d(),id:B(),is_bot:_(F()),is_premium:_(F()),last_name:_(d()),language_code:_(d()),photo_url:_(d()),username:_(d())})}function nr(){return b({projectCode:d(),uid:d(),sessionId:d(),rootToken:d()})}function rr(){return b({auth_date:O(d(),$(e=>new Date(Number(e)*1e3)),Ne()),can_send_after:_(O(d(),$(Number),Te())),chat:_(M(tr())),chat_type:_(d()),chat_instance:_(d()),hash:_(d()),query_id:_(d()),receiver:_(M(gt())),start_param:_(d()),signature:_(d()),user:_(M(gt())),auth:_(M(nr()))})}function sr(){return bt(rr())}function Ae(){return xe(d(),O(Z([d(),B()]),$(e=>typeof e=="number"?`#${(e&16777215).toString(16).padStart(6,"0")}`:e),Y(er)))}function ir(){const e=_(O(d(),$(t=>t==="1")));return b({vbWebAppBotInline:e,vbWebAppData:_(sr()),vbWebAppDefaultColors:_(M(Ae())),vbWebAppFullscreen:e,vbWebAppPlatform:d(),vbWebAppShowSettings:e,vbWebAppStartParam:_(d()),vbWebAppThemeParams:M(Ae()),vbWebAppVersion:d()})}function or(){return bt(ir())}function wt(){return b({eventType:d(),eventData:_(he())})}function Oe(e){return ee(()=>x(or(),e),t=>t)}const ar=G(Oe);function Et(e,t){return t||(t=(n,r)=>JSON.stringify(r)),new URLSearchParams(Object.entries(e).reduce((n,[r,s])=>(Array.isArray(s)?n.push(...s.map(i=>[r,String(i)])):s!=null&&n.push([r,s instanceof Date?(s.getTime()/1e3|0).toString():typeof s=="string"||typeof s=="number"?String(s):typeof s=="boolean"?s?"1":"0":t(r,s)]),n),[])).toString()}function ur(e){return Et(e)}function cr(e){return Et(e,(t,n)=>t==="vbWebAppData"?ur(n):JSON.stringify(n))}const kt="launchParams";function Pt(e){return e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&")}function St(){return y(H(),kn(Oe))}const lr=G(St);function jt(){return y(H(),yn(e=>{const t=new URLSearchParams(e).get("vbWebAppData");return t?_n(t):dn}))}function fr(){return y(jt(),En(e=>{throw e},e=>e),mn(()=>{},e=>e))}function H(){const e=[];for(const[t,n]of[[()=>Pt(window.location.href),"window.location.href"],[()=>{const r=performance.getEntriesByType("navigation")[0];return r&&Pt(r.name)},"performance navigation entries"],[()=>xn(kt),"local storage"]]){const r=t();if(!r){e.push({source:n,error:new Error("Source is empty")});continue}const s=y(Oe(r),wn(i=>i,()=>!0));if(typeof s!="boolean"){e.push({source:n,error:s});continue}return lt(kt,r),g(r)}return j(new vt(e))}const pr=G(H);function dr(e,t){t()}function W(e,t){t||(t={});const n=t.equals||Object.is;let r=[],s=e;const i=a=>{if(!n(s,a)){const l=s;s=a,dr(c,()=>{[...r].forEach(([p,h])=>{p(a,l),h&&u(p,!0)})})}};function o(a){const l=typeof a!="object"?{once:a}:a;return{once:l.once||!1,signal:l.signal||!1}}const u=(a,l)=>{const p=o(l),h=r.findIndex(([v,S])=>v===a&&S.once===p.once&&S.signal===p.signal);h>=0&&r.splice(h,1)},c=Object.assign(function(){return _r(c),s},{destroy(){r=[]},set:i,reset(){i(e)},sub(a,l){return r.push([a,o(l)]),()=>u(a,l)},unsub:u,unsubAll(){r=r.filter(a=>a[1].signal)}});return c}const K=[];function _r(e){K.length&&K[K.length-1].add(e)}function At(e,t){let n=new Set,r;function s(){return r||(r=W(o(),t))}function i(){s().set(o())}function o(){n.forEach(a=>{a.unsub(i,{signal:!0})});const u=new Set;let c;K.push(u);try{c=e()}finally{K.pop()}return u.forEach(a=>{a.sub(i,{signal:!0})}),n=u,c}return Object.assign(function(){return s()()},{destroy(){s().destroy()},sub(...u){return s().sub(...u)},unsub(...u){s().unsub(...u)},unsubAll(...u){s().unsubAll(...u)}})}function hr(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map(function(s){s(n)}),(r=e.get("*"))&&r.slice().map(function(s){s(t,n)})}}}function Ot(e,t){const n=new Map,r=hr(),s=(i,o,u=!1)=>{const c=n.get(i)||new Map;n.set(i,c);const a=c.get(o)||[];c.set(o,a);const l=a.findIndex(p=>p[1]===u);if(l>=0&&(r.off(i,a[l][0]),a.splice(l,1),!a.length&&(c.delete(o),!c.size))){const p=n.size;n.delete(i),p&&!n.size&&t()}};return{on(i,o,u){!n.size&&e();const c=()=>{s(i,o,u)},a=(...h)=>{u&&c(),i==="*"?o({name:h[0],payload:h[1]}):o(...h)};r.on(i,a);const l=n.get(i)||new Map;n.set(i,l);const p=l.get(o)||[];return l.set(o,p),p.push([a,u||!1]),c},off:s,emit:r.emit,clear(){const i=n.size;r.all.clear(),n.clear(),i&&t()}}}function re(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}const se=W(!1),Me=W("https://web.telegram.org"),vr=e=>{R().log("Event received:",e)},Re=At(se);function mr(e){e!==se()&&(se.set(e),(e?ie:$t)("*",vr))}const Ie=At(Me);function yr(e){Me.set(e),R().log("New target origin set",e)}const T=W((...e)=>{window.parent.postMessage(...e)}),R=W(pt("Bridge",{bgColor:"#9147ff",textColor:"white",shouldLog:Re}));function br(){Ft(),[T,Me,Ie,se,Re,R].forEach(e=>{e.unsubAll(),"reset"in e&&e.reset()})}function Ce(e,t,n){const r=[n],s=e[t];typeof s=="function"&&r.push(s);const i=(...u)=>{r.forEach(c=>c(...u))},o=Object.assign((...u)=>{i(...u)},{unwrap(){const{length:u}=r;if(u===1){delete e[t];return}if(u===2){It(e,t,r[1]);return}r.unshift(1),It(e,t,i)}});Rt(e,t,()=>o,u=>r.push(u))}function Mt(e,t){const n=e[t];Rt(e,t,()=>n,r=>{Object.entries(r).forEach(([s,i])=>{n[s]=i})})}function Rt(e,t,n,r){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:n,set:r})}function It(e,t,n){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n})}const gr={clipboard_text_received:b({req_id:d(),data:q(d())}),custom_method_invoked:b({req_id:d(),result:_(he()),error:_(d())}),popup_closed:q(b({button_id:q(d(),()=>{})}),{}),viewport_changed:q(b({height:B(),width:q(B(),()=>window.innerWidth),is_state_stable:F(),is_expanded:F()}),()=>({height:window.innerHeight,is_state_stable:!0,is_expanded:!0})),theme_changed:b({theme_params:Ae()})};function Ct(e){if(e.source!==window.parent)return;let t;try{t=x(M(wt()),e.data)}catch{return}const{eventType:n,eventData:r}=t,s=gr[n];let i;try{i=s?x(s,r):r}catch(o){return R().forceError([`An error occurred processing the "${n}" event from the VBot application.`,"Please, file an issue here:","https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"].join(`
|
|
3
|
+
`),t,o)}wr(n,i)}const{on:ie,off:$t,emit:wr,clear:Ft}=Ot(()=>{const e=window;!e.TelegramGameProxy&&(e.TelegramGameProxy={}),Ce(e.TelegramGameProxy,"receiveEvent",re),Mt(e,"TelegramGameProxy"),!e.VBot&&(e.VBot={}),!e.VBot.WebView&&(e.VBot.WebView={}),Ce(e.VBot.WebView,"receiveEvent",re),Mt(e.VBot,"WebView"),Ce(e,"TelegramGameProxy_receiveEvent",re),window.addEventListener("message",Ct)},()=>{[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["VBot","WebView","receiveEvent"]].forEach(e=>{const t=window;let n=[void 0,t];for(const i of e)if(n=[n[1],n[1][i]],!n[1])return;const[r,s]=n;"unwrap"in s&&(s.unwrap(),r&&r!==t&&!Object.keys(r).length&&delete t[e[0]])}),window.removeEventListener("message",Ct)}),Lt=(...e)=>T()(...e);function Wt(e,t){y(U(e,t),gn(n=>{throw n}))}function U(e,t){R().log("Posting event:",t?{eventType:e,eventData:t}:{eventType:e});const n=window,r=JSON.stringify({eventType:e,eventData:t});return me()?(Lt(r,Ie()),g(void 0)):ve(n)?(n.VBotWebviewProxy.postEvent(e,JSON.stringify(t)),g(void 0)):pe(b({external:b({notify:de()})}),n)?(n.external.notify(r),g(void 0)):j(new je)}function oe(e,t,n={}){const{capture:r=()=>!0,postEvent:s=U}=n,i=W(),[o,u]=ft();(Array.isArray(t)?t:[t]).forEach(a=>{o(ie(a,l=>{const p=Array.isArray(t);r(p?{event:a,payload:l}:l)&&i.set([p?{event:a,payload:l}:l])}))});const c=a=>(u(),a);return y(async()=>s(e,n.params),Ee(()=>Pe((a,l,p)=>{const h=i();if(h)return a(h[0]);const v=I=>{I&&a(I[0])},S=()=>{i.unsub(v)};i.sub(v),p.on("finalized",S)},n)),at(c,c))}function Er(e,t,n){const{postEvent:r}=n||{};return z(oe(e,t,{...n,postEvent:r?(...s)=>{try{return r(...s),g(void 0)}catch(i){return j(i)}}:U}))}function kr(e,t){const n=qt(e,t);return typeof n=="function"?L.fn(()=>z(n)):n}function qt(e,t){const n=ve(window);if(!e)return n||y(H(),J(()=>!1,()=>!0));if(n)return we(!0);const{timeout:r=100}=t||{};return y(oe("web_app_request_theme","theme_changed",{...t,timeout:r}),te(s=>be.is(s)||je.is(s)?g(!1):j(s),()=>g(!0)))}function Pr({launchParams:e,onEvent:t,resetPostMessage:n}={}){if(e){const i=typeof e=="string"||e instanceof URLSearchParams?e.toString():cr({...e,vbWebAppData:void 0})+(e.vbWebAppData?`&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}`:"");try{ar(i)}catch(o){throw new mt(i,o)}lt("launchParams",i)}if(me()){if(!t)return;n&&T.reset();const i=T();T.set((...o)=>{const[u]=o,c=()=>{i(...o)};try{const a=x(M(wt()),u);t({name:a.eventType,params:a.eventData},c)}catch{c()}});return}const r=window.VBotWebviewProxy||{},s=r.postEvent||(()=>{});window.VBotWebviewProxy={...r,postEvent(i,o){const u=()=>{s(i,o)};t?t({name:i,params:o?JSON.parse(o):void 0},u):u()}},R().log("Environment was mocked by the mockVBotEnv function")}function Sr(e,t="*"){const n=i=>{if(i.source===e.contentWindow)try{const o=JSON.parse(i.data),{eventType:u,eventData:c}=o;r.emit(u,c)}catch{}},r=Ot(()=>{window.addEventListener("message",n)},()=>{window.removeEventListener("message",n)}),s={...r,send:(i,o)=>{if(e.contentWindow){const u=JSON.stringify({eventType:i,eventData:o});e.contentWindow.postMessage(u,t)}},clear:()=>{r.clear(),Q===s&&(Q=void 0)}};return Q=s,s}let Q;function jr(){if(!Q)throw new Error("HostBridge not initialized. Call defineHostBridge() first.");return Q}function Bt(e){return({req_id:t})=>t===e}const Vt={"6.0":["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"],6.1:["web_app_open_tg_link","web_app_open_invoice","web_app_setup_back_button","web_app_set_background_color","web_app_set_header_color","web_app_trigger_haptic_feedback"],6.2:["web_app_open_popup"],6.4:["web_app_close_scan_qr_popup","web_app_open_scan_qr_popup","web_app_read_text_from_clipboard",{method:"web_app_open_link",param:"try_instant_view"}],6.7:["web_app_switch_inline_query"],6.9:["web_app_invoke_custom_method","web_app_request_write_access","web_app_request_phone",{method:"web_app_set_header_color",param:"color"}],"6.10":["web_app_setup_settings_button"],7.2:["web_app_biometry_get_info","web_app_biometry_open_settings","web_app_biometry_request_access","web_app_biometry_request_auth","web_app_biometry_update_token"],7.6:[{method:"web_app_open_link",param:"try_browser"},{method:"web_app_close",param:"return_back"}],7.7:["web_app_setup_swipe_behavior"],7.8:["web_app_share_to_story"],"7.10":["web_app_setup_secondary_button","web_app_set_bottom_bar_color",{method:"web_app_setup_main_button",param:"has_shine_effect"}],"8.0":["web_app_request_safe_area","web_app_request_content_safe_area","web_app_request_fullscreen","web_app_exit_fullscreen","web_app_set_emoji_status","web_app_add_to_home_screen","web_app_check_home_screen","web_app_request_emoji_status_access","web_app_check_location","web_app_open_location_settings","web_app_request_file_download","web_app_request_location","web_app_send_prepared_message","web_app_start_accelerometer","web_app_start_device_orientation","web_app_start_gyroscope","web_app_stop_accelerometer","web_app_stop_device_orientation","web_app_stop_gyroscope","web_app_toggle_orientation_lock"],"9.0":["web_app_device_storage_clear","web_app_device_storage_get_key","web_app_device_storage_save_key","web_app_secure_storage_clear","web_app_secure_storage_get_key","web_app_secure_storage_restore_key","web_app_secure_storage_save_key"],9.1:["web_app_hide_keyboard"],9.2:["web_app_send_notification","web_app_finish_refresh"]};function $e(e,t){return Object.keys(Vt).find(r=>Vt[r].some(s=>t?typeof s=="object"&&s.method===e&&s.param===t:s===e))||null}function Dt(e){return e.split(".").map(Number)}function Tt(e,t){const n=Dt(e),r=Dt(t),s=Math.max(n.length,r.length);for(let i=0;i<s;i+=1){const o=n[i]||0,u=r[i]||0;if(o!==u)return o>u?1:-1}return 0}function Fe(e,t,n){const r=n?$e(e,t):$e(e);return r?Tt(r,n||t)<=0:!1}function Ar(e,t="strict"){const n=typeof t=="function"?t:r=>{const{method:s,version:i}=r,o="param"in r?new ht(s,r.param,i):new _t(s,i);if(t==="strict")throw o;return R().forceWarn(o.message)};return((r,s)=>Fe(r,e)?r==="web_app_set_header_color"&&pe(b({color:Ue()}),s)&&!Fe(r,"color",e)?n({version:e,method:r,param:"color"}):Wt(r,s):n({version:e,method:r}))}function Ut(e,t,n,r){return y(oe("web_app_invoke_custom_method","custom_method_invoked",{...r||{},params:{method:e,params:t,req_id:n},capture:Bt(n)}),Tn(({result:s,error:i})=>i?ot(new yt(i)):we(s)))}function Or(e,t,n,r){return L.fn(()=>y(Ut(e,t,n,r),te(s=>{throw s},s=>s))())}function Nt(e,t,n={}){const{capture:r=()=>!0,postEvent:s=U}=n,i=W(),[o,u]=ft();(Array.isArray(t)?t:[t]).forEach(a=>{o(ie(a,l=>{(Array.isArray(t)?r({event:a,payload:l}):r(l))&&i.set([l])}))});const c=a=>(u(),a);return y(async()=>s(e,n.params),Ee(()=>Pe((a,l,p)=>{const h=i();if(h)return a(h[0]);const v=I=>{I&&a(I[0])},S=()=>{i.unsub(v)};i.sub(v),p.on("finalized",S)},n)),at(c,c))}function Mr(e,t,n){const{postEvent:r}=n||{};return z(Nt(e,t,{...n,postEvent:r?(...s)=>{try{return r(...s),g(void 0)}catch(i){return j(i)}}:U}))}function Rr(){Object.hasOwn||(Object.hasOwn=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)})}function Le(e){return ee(()=>decodeURIComponent(atob(e.replace(/-/g,"+").replace(/_/g,"/")).split("").map(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)).join("")),t=>t)}const Ir=G(Le);function We(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,n)=>String.fromCharCode(parseInt(`0x${n}`)))).replace(/\+/g,"-").replace(/\//g,"_")}function xt(e){const t=We(typeof e=="string"?e:JSON.stringify(e));return t.length>512?j(new Error("Value is too long for start parameter")):g(t)}const Cr=G(xt);function $r(e,t){return z(Jt(e,typeof t=="function"?n=>ee(()=>t(n),r=>r):t))}function Jt(e,t){return y(Le(e),Pn(n=>t?typeof t=="function"?t(n):Rn(n):g(n)))}function Fr(e){return We(e).length<=512}return f.CancelledError=Ke,f.InvalidLaunchParamsError=mt,f.InvokeCustomMethodFailedError=yt,f.LaunchParamsRetrieveError=vt,f.MethodParameterUnsupportedError=ht,f.MethodUnsupportedError=_t,f.TimeoutError=be,f.UnknownEnvError=je,f.applyPolyfills=Rr,f.captureSameReq=Bt,f.compareVersions=Tt,f.createLogger=pt,f.createPostEvent=Ar,f.createStartParam=Cr,f.createStartParamFp=xt,f.debug=Re,f.decodeBase64Url=Ir,f.decodeBase64UrlFp=Le,f.decodeStartParam=$r,f.decodeStartParamFp=Jt,f.deepSnakeToCamelObjKeys=ke,f.defineHostBridge=Sr,f.emitEvent=re,f.encodeBase64Url=We,f.getHostBridge=jr,f.getReleaseVersion=$e,f.hasWebviewProxy=ve,f.invokeCustomMethod=Or,f.invokeCustomMethodFp=Ut,f.isIframe=me,f.isSafeToCreateStartParam=Fr,f.isVBMA=kr,f.isVBMAFp=qt,f.logger=R,f.mockVBotEnv=Pr,f.off=$t,f.offAll=Ft,f.on=ie,f.postEvent=Wt,f.postEventFp=U,f.postMessage=Lt,f.postMessageImpl=T,f.request=Mr,f.request2=Er,f.request2Fp=oe,f.requestFp=Nt,f.resetGlobals=br,f.retrieveLaunchParams=lr,f.retrieveLaunchParamsFp=St,f.retrieveRawInitData=fr,f.retrieveRawInitDataFp=jt,f.retrieveRawLaunchParams=pr,f.retrieveRawLaunchParamsFp=H,f.setDebug=mr,f.setTargetOrigin=yr,f.supports=Fe,f.targetOrigin=Ie,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"}),f})({});
|
|
4
4
|
//# sourceMappingURL=index.iife.js.map
|