@idosgames/core 0.26.6 → 0.26.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- 'use strict';var zod=require('zod');function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function Z(){return crypto.randomUUID()}var he="idos-host-files",E="files";function D(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function Pe(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},g=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(he,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(E)||e.result.createObjectStore(E,{keyPath:"key"});},await D(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(E,e).objectStore(E)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await D(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:Pe(t),size:t.byteLength,updatedAt:Date.now()};return await D(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await D(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let R=c.result;if(!R)return n();let f=R.value;f.key.startsWith(e)&&s.push({key:f.key,size:f.size,updatedAt:f.updatedAt}),R.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function k(){return typeof document<"u"&&typeof document.createElement=="function"}function U(r={}){return k()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var ee="idos_device_id",B="idos:platformSignIn:declined:",l="UNAVAILABLE",H=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}buyProduct(e){return Promise.resolve({ok:false,error:l})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:l})}getDeviceID(){let e=this.storage.getString(ee);return e||(e=this.newDeviceID(),this.storage.setString(ee,e)),e}newDeviceID(){return Z()}setSignInDeclined(e,t){t?this.storage.setString(B+e,"1"):this.storage.remove(B+e);}isSignInDeclined(e){return this.storage.getString(B+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function M(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var y=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},T=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function F(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function L(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}zod.z.enum(["Virtual","Crypto"]).catch("Virtual");zod.z.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item");var a={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"};zod.z.enum(["Unknown","Web","Android","Ios"]).catch("Unknown");zod.z.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay");zod.z.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season"]).catch("TimedEvent");zod.z.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic");function re(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return te(e);let t=r.cordova?.platformId;return t?te(t):r.navigator?.userAgent??""?a.Web:a.Unknown}function te(r){let e=r.toLowerCase();return e==="android"?a.Android:e==="ios"?a.Ios:e==="web"?a.Web:a.Unknown}var S=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",oe=/^[a-z0-9]{8}-preview\.idos\.games$/;function G(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function V(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return oe.test(r)?true:G(r)&&globalThis.__IDOS_PREVIEW__!=null}function h(r){if(typeof window<"u"&&oe.test(window.location.hostname.toLowerCase()))return r===N;if(S.includes(r))return true;if(typeof window>"u"||!G(window.location.hostname))return false;try{return G(new URL(r).hostname)}catch{return false}}var se="IDOS_PLATFORM_WALLET_ACK",ne="PLATFORM_WALLET_UNAVAILABLE",be=5e3,ve=18e4;function He(){if(h(N))return [N];let r=[...S],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&h(e)&&r.push(e),r}function we(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:ne,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=we(),c=o.answerTimeoutMs??ve;return new Promise(R=>{let f=false,x,W=b=>{f||(f=true,window.removeEventListener("message",X),clearTimeout(x),R(b));},X=b=>{if(!h(b.origin))return;let p=b.data;if(!(!p||p.requestId!==i)){if(p.type===se){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),be),window.addEventListener("message",X);for(let b of He())try{n.postMessage({type:r,requestId:i,...t},b);}catch{}})}var K={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Se=30*6e4;function ie(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!S.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function z(){if(typeof window>"u"||!V())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ae(r){let e=await u(K.request,K.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Se}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var j={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},Ae=15*6e4,Re=/^[a-z0-9]{8}-preview\.idos\.games$/;function A(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Re.test(window.location.hostname.toLowerCase())}async function le(r){let e=await u(j.request,j.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:Ae});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},Ie=5*6e4;function ue(){return A()}async function ce(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:Ie});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var $={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},ke=10*6e4,Te=["DECLINED","NOT_ENOUGH_CREDITS"];function pe(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function de(){return A()}async function me(r){let e=await u($.request,$.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var ge="IDOS_APP_FRAME_HIDDEN";function P(){return globalThis.navigator??null}function q(){return typeof window<"u"}function fe(){if(!q())return false;try{return window.self!==window.top}catch{return true}}var C=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new y){if(super(e,new g),!q()){this.id="web",this.supports=H;return}let t=P(),o=ie();this.supports=Object.freeze({autoSignIn:o,signIn:o||z(),rewardedAds:ue(),titleAds:false,storePurchases:false,creditsPayments:pe(),creditsConfirm:de(),cryptoTopUp:A(),sceneCaptureRequests:fe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:F(),filePicker:k(),pushNotifications:false}),this.id=m()?"telegram":z()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),fe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==ge||h(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return re()}getFullURL(){return q()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return P()?.userAgent||"Web"}getLanguage(){return P()?.language||""}async signIn(e){return this.supports.signIn?ae(e):{error:l}}async showRewardedAd(e){return this.supports.rewardedAds?ce(e):{ok:false,error:l}}async confirmCredits(e){return this.supports.creditsConfirm?me(e):{ok:false,error:l}}async topUp(e){return this.supports.cryptoTopUp?le(e):{ok:false,error:l}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}q()&&window.open(e,"_blank","noopener");}async share(e){let t=P();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=P();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=P();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return Ce(e)}vibrate(e){try{P()?.vibrate?.(M(e));}catch{}}createWorker(e,t){return L(e,t)}};function Ce(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var J=1,ye="__IDOS_HOST__";function Y(){let r=globalThis[ye];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var Oe={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function _e(r){switch((r??"").toLowerCase()){case "android":return a.Android;case "ios":return a.Ios;case "web":return a.Web;default:return a.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new y){super(t,new g),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??H[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:F(),filePicker:k(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},Oe[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===a.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return _e(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:xe(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:M(e)});}createWorker(e,t){return L(e,t)}};function xe(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var _=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new T),this.supports=Object.freeze({...H,...t.supports}),this.clientPlatform=t.clientPlatform??a.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:l}}async showRewardedAd(){return {ok:false,error:l}}async confirmCredits(){return {ok:false,error:l}}async topUp(){return {ok:false,error:l}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Ee(){let r=Y();return r?new O(r):typeof window>"u"?new _:new C}
1
+ 'use strict';var zod=require('zod');function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function Z(){return crypto.randomUUID()}var he="idos-host-files",E="files";function D(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function Pe(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},g=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(he,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(E)||e.result.createObjectStore(E,{keyPath:"key"});},await D(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(E,e).objectStore(E)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await D(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:Pe(t),size:t.byteLength,updatedAt:Date.now()};return await D(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await D(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let R=c.result;if(!R)return n();let f=R.value;f.key.startsWith(e)&&s.push({key:f.key,size:f.size,updatedAt:f.updatedAt}),R.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function k(){return typeof document<"u"&&typeof document.createElement=="function"}function U(r={}){return k()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var ee="idos_device_id",B="idos:platformSignIn:declined:",l="UNAVAILABLE",H=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}buyProduct(e){return Promise.resolve({ok:false,error:l})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:l})}getDeviceID(){let e=this.storage.getString(ee);return e||(e=this.newDeviceID(),this.storage.setString(ee,e)),e}newDeviceID(){return Z()}setSignInDeclined(e,t){t?this.storage.setString(B+e,"1"):this.storage.remove(B+e);}isSignInDeclined(e){return this.storage.getString(B+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function M(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var y=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},T=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function F(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function L(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}zod.z.enum(["Virtual","Crypto"]).catch("Virtual");zod.z.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item");var a={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"};zod.z.enum(["Unknown","Web","Android","Ios"]).catch("Unknown");zod.z.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay");zod.z.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season","Challenge","ChallengePoints"]).catch("TimedEvent");zod.z.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic");function re(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return te(e);let t=r.cordova?.platformId;return t?te(t):r.navigator?.userAgent??""?a.Web:a.Unknown}function te(r){let e=r.toLowerCase();return e==="android"?a.Android:e==="ios"?a.Ios:e==="web"?a.Web:a.Unknown}var S=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",oe=/^[a-z0-9]{8}-preview\.idos\.games$/;function G(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function V(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return oe.test(r)?true:G(r)&&globalThis.__IDOS_PREVIEW__!=null}function h(r){if(typeof window<"u"&&oe.test(window.location.hostname.toLowerCase()))return r===N;if(S.includes(r))return true;if(typeof window>"u"||!G(window.location.hostname))return false;try{return G(new URL(r).hostname)}catch{return false}}var se="IDOS_PLATFORM_WALLET_ACK",ne="PLATFORM_WALLET_UNAVAILABLE",be=5e3,ve=18e4;function He(){if(h(N))return [N];let r=[...S],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&h(e)&&r.push(e),r}function we(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:ne,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=we(),c=o.answerTimeoutMs??ve;return new Promise(R=>{let f=false,x,W=b=>{f||(f=true,window.removeEventListener("message",X),clearTimeout(x),R(b));},X=b=>{if(!h(b.origin))return;let p=b.data;if(!(!p||p.requestId!==i)){if(p.type===se){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),be),window.addEventListener("message",X);for(let b of He())try{n.postMessage({type:r,requestId:i,...t},b);}catch{}})}var K={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Se=30*6e4;function ie(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!S.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function z(){if(typeof window>"u"||!V())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ae(r){let e=await u(K.request,K.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Se}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var j={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},Ae=15*6e4,Re=/^[a-z0-9]{8}-preview\.idos\.games$/;function A(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Re.test(window.location.hostname.toLowerCase())}async function le(r){let e=await u(j.request,j.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:Ae});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},Ie=5*6e4;function ue(){return A()}async function ce(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:Ie});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var $={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},ke=10*6e4,Te=["DECLINED","NOT_ENOUGH_CREDITS"];function pe(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function de(){return A()}async function me(r){let e=await u($.request,$.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var ge="IDOS_APP_FRAME_HIDDEN";function P(){return globalThis.navigator??null}function q(){return typeof window<"u"}function fe(){if(!q())return false;try{return window.self!==window.top}catch{return true}}var C=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new y){if(super(e,new g),!q()){this.id="web",this.supports=H;return}let t=P(),o=ie();this.supports=Object.freeze({autoSignIn:o,signIn:o||z(),rewardedAds:ue(),titleAds:false,storePurchases:false,creditsPayments:pe(),creditsConfirm:de(),cryptoTopUp:A(),sceneCaptureRequests:fe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:F(),filePicker:k(),pushNotifications:false}),this.id=m()?"telegram":z()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),fe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==ge||h(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return re()}getFullURL(){return q()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return P()?.userAgent||"Web"}getLanguage(){return P()?.language||""}async signIn(e){return this.supports.signIn?ae(e):{error:l}}async showRewardedAd(e){return this.supports.rewardedAds?ce(e):{ok:false,error:l}}async confirmCredits(e){return this.supports.creditsConfirm?me(e):{ok:false,error:l}}async topUp(e){return this.supports.cryptoTopUp?le(e):{ok:false,error:l}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}q()&&window.open(e,"_blank","noopener");}async share(e){let t=P();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=P();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=P();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return Ce(e)}vibrate(e){try{P()?.vibrate?.(M(e));}catch{}}createWorker(e,t){return L(e,t)}};function Ce(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var J=1,ye="__IDOS_HOST__";function Y(){let r=globalThis[ye];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var Oe={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function _e(r){switch((r??"").toLowerCase()){case "android":return a.Android;case "ios":return a.Ios;case "web":return a.Web;default:return a.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new y){super(t,new g),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??H[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:F(),filePicker:k(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},Oe[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===a.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return _e(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:xe(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:M(e)});}createWorker(e,t){return L(e,t)}};function xe(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var _=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new T),this.supports=Object.freeze({...H,...t.supports}),this.clientPlatform=t.clientPlatform??a.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:l}}async showRewardedAd(){return {ok:false,error:l}}async confirmCredits(){return {ok:false,error:l}}async topUp(){return {ok:false,error:l}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Ee(){let r=Y();return r?new O(r):typeof window>"u"?new _:new C}
2
2
  exports.BrowserFileStore=g;exports.BrowserStorage=y;exports.MemoryFileStore=v;exports.MemoryHost=_;exports.MemoryStorage=T;exports.NATIVE_HOST_GLOBAL=ye;exports.NATIVE_HOST_PROTOCOL=J;exports.NativeHost=O;exports.PLATFORM_AD_MESSAGES=Q;exports.PLATFORM_BRIDGE_ACK=se;exports.PLATFORM_CREDITS_CONFIRM_FINAL=Te;exports.PLATFORM_CREDITS_CONFIRM_MESSAGES=$;exports.PLATFORM_ORIGINS=S;exports.PLATFORM_PAGE_UNAVAILABLE=ne;exports.PLATFORM_SIGN_IN_MESSAGES=K;exports.PLATFORM_TOPUP_MESSAGES=j;exports.SITE_FRAME_HIDDEN_MESSAGE=ge;exports.WebHost=C;exports.askPlatformPage=u;exports.createDefaultHost=Ee;exports.getTelegramWebApp=m;exports.isPlatformParentOrigin=h;exports.readNativeHostGlobal=Y;exports.shareFallbackText=I;
@@ -1,5 +1,5 @@
1
- import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-xACJW0x5.cjs';
2
- export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-xACJW0x5.cjs';
1
+ import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-gNo-pSSn.cjs';
2
+ export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-gNo-pSSn.cjs';
3
3
  import 'zod';
4
4
 
5
5
  declare abstract class BaseHost implements GameHost {
@@ -1,5 +1,5 @@
1
- import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-xACJW0x5.js';
2
- export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-xACJW0x5.js';
1
+ import { G as GameHost, d as HostCapabilities, K as KeyValueStorage, h as HostFileStore, C as ClientPlatform, o as HostSignInAnswer, b as HostAdRequest, c as HostAdResult, e as HostCreditsConfirmRequest, l as HostResult, u as HostTopUpRequest, q as HostStorePurchaseRequest, r as HostStorePurchaseResult, s as HostStoreReceipt, i as HostPickFilesRequest, f as HostFile, k as HostPushTokenRequest, j as HostPushToken, n as HostShareRequest, m as HostShareOutcome, g as HostFileOutcome, w as HostWorkerOptions, v as HostUnsubscribe, t as HostStoredFileInfo } from '../GameHost-gNo-pSSn.js';
2
+ export { H as HostAdProvider, p as HostStore, x as shareFallbackText } from '../GameHost-gNo-pSSn.js';
3
3
  import 'zod';
4
4
 
5
5
  declare abstract class BaseHost implements GameHost {
@@ -1 +1 @@
1
- export{c as BrowserFileStore,d as BrowserStorage,b as MemoryFileStore,s as MemoryHost,e as MemoryStorage,v as NATIVE_HOST_GLOBAL,u as NATIVE_HOST_PROTOCOL,x as NativeHost,G as PLATFORM_AD_MESSAGES,B as PLATFORM_BRIDGE_ACK,I as PLATFORM_CREDITS_CONFIRM_FINAL,H as PLATFORM_CREDITS_CONFIRM_MESSAGES,z as PLATFORM_ORIGINS,C as PLATFORM_PAGE_UNAVAILABLE,E as PLATFORM_SIGN_IN_MESSAGES,F as PLATFORM_TOPUP_MESSAGES,J as SITE_FRAME_HIDDEN_MESSAGE,K as WebHost,D as askPlatformPage,L as createDefaultHost,y as getTelegramWebApp,A as isPlatformParentOrigin,w as readNativeHostGlobal,t as shareFallbackText}from'../chunk-YZ32MQXQ.js';
1
+ export{c as BrowserFileStore,d as BrowserStorage,b as MemoryFileStore,s as MemoryHost,e as MemoryStorage,v as NATIVE_HOST_GLOBAL,u as NATIVE_HOST_PROTOCOL,x as NativeHost,G as PLATFORM_AD_MESSAGES,B as PLATFORM_BRIDGE_ACK,I as PLATFORM_CREDITS_CONFIRM_FINAL,H as PLATFORM_CREDITS_CONFIRM_MESSAGES,z as PLATFORM_ORIGINS,C as PLATFORM_PAGE_UNAVAILABLE,E as PLATFORM_SIGN_IN_MESSAGES,F as PLATFORM_TOPUP_MESSAGES,J as SITE_FRAME_HIDDEN_MESSAGE,K as WebHost,D as askPlatformPage,L as createDefaultHost,y as getTelegramWebApp,A as isPlatformParentOrigin,w as readNativeHostGlobal,t as shareFallbackText}from'../chunk-S24V5BGG.js';
@@ -1,7 +1,7 @@
1
- import { I as IceServer } from '../VoiceController-BWb8NTp2.cjs';
2
- export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-BWb8NTp2.cjs';
1
+ import { I as IceServer } from '../VoiceController-FdN8yiN8.cjs';
2
+ export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-FdN8yiN8.cjs';
3
3
  import 'zod';
4
- import '../GameHost-xACJW0x5.cjs';
4
+ import '../GameHost-gNo-pSSn.cjs';
5
5
  import 'decimal.js';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
- import { I as IceServer } from '../VoiceController-BMXi4MNo.js';
2
- export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-BMXi4MNo.js';
1
+ import { I as IceServer } from '../VoiceController-BHAlGvEd.js';
2
+ export { C as ChannelName, M as MemberLeftKind, a as MicMode, R as RealtimeClient, b as RealtimeSession, c as RealtimeSessionEvents, d as RealtimeSessionOptions, V as VoiceController, e as VoiceControllerEvents, f as VoiceControllerOptions } from '../VoiceController-BHAlGvEd.js';
3
3
  import 'zod';
4
- import '../GameHost-xACJW0x5.js';
4
+ import '../GameHost-gNo-pSSn.js';
5
5
  import 'decimal.js';
6
6
 
7
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/core",
3
- "version": "0.26.6",
3
+ "version": "0.26.8",
4
4
  "description": "Engine-agnostic core of the IDosGames SDK (transport, auth, cache, services, events).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- import {z as z$1}from'zod';function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function Z(){return crypto.randomUUID()}var he="idos-host-files",E="files";function D(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function Pe(r){return r.slice().buffer}var v=class{map=new Map;async read(e){let t=this.map.get(e);return t?t.bytes.slice():null}async write(e,t){return this.map.set(e,{bytes:t.slice(),updatedAt:Date.now()}),true}async remove(e){this.map.delete(e);}async list(e=""){let t=[];for(let[o,s]of this.map)o.startsWith(e)&&t.push({key:o,size:s.bytes.byteLength,updatedAt:s.updatedAt});return t.sort((o,s)=>s.updatedAt-o.updatedAt)}},g=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(he,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(E)||e.result.createObjectStore(E,{keyPath:"key"});},await D(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(E,e).objectStore(E)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await D(t.get(e));return o?new Uint8Array(o.bytes):null}catch{return null}}async write(e,t){let o=await this.store("readwrite");if(!o)return this.fallback.write(e,t);try{let s={key:e,bytes:Pe(t),size:t.byteLength,updatedAt:Date.now()};return await D(o.put(s)),!0}catch{return false}}async remove(e){let t=await this.store("readwrite");if(!t)return this.fallback.remove(e);try{await D(t.delete(e));}catch{}}async list(e=""){let t=await this.store("readonly");if(!t)return this.fallback.list(e);try{let o=e&&typeof IDBKeyRange<"u"?IDBKeyRange.bound(e,e+"\uFFFF"):void 0,s=[];return await new Promise((n,i)=>{let c=t.openCursor(o);c.onerror=()=>i(c.error),c.onsuccess=()=>{let R=c.result;if(!R)return n();let f=R.value;f.key.startsWith(e)&&s.push({key:f.key,size:f.size,updatedAt:f.updatedAt}),R.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function k(){return typeof document<"u"&&typeof document.createElement=="function"}function U(r={}){return k()?new Promise(e=>{let t=false,o=document.createElement("input");o.type="file",r.accept?.length&&(o.accept=r.accept.join(",")),o.multiple=r.multiple===true,o.style.display="none";let s=n=>{t||(t=true,o.remove(),e(n));};o.addEventListener("cancel",()=>s([])),o.addEventListener("change",()=>{let n=[...o.files??[]];Promise.all(n.map(async i=>{try{return {bytes:new Uint8Array(await i.arrayBuffer()),name:i.name,mime:i.type||"application/octet-stream"}}catch{return null}})).then(i=>s(i.filter(c=>c!==null)));}),document.body?.appendChild(o),o.click();}):Promise.resolve([])}var ee="idos_device_id",B="idos:platformSignIn:declined:",l="UNAVAILABLE",H=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,sceneCaptureRequests:false,share:false,vibration:false,sharedMemory:false,filePicker:false,pushNotifications:false}),d=class{storage;files;visible=true;visibilityListeners=new Set;linkListeners=new Set;constructor(e,t=new v){this.storage=e,this.files=t;}buyProduct(e){return Promise.resolve({ok:false,error:l})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:l})}getDeviceID(){let e=this.storage.getString(ee);return e||(e=this.newDeviceID(),this.storage.setString(ee,e)),e}newDeviceID(){return Z()}setSignInDeclined(e,t){t?this.storage.setString(B+e,"1"):this.storage.remove(B+e);}isSignInDeclined(e){return this.storage.getString(B+e)==="1"}isVisible(){return this.visible}onVisibilityChange(e){return this.visibilityListeners.add(e),()=>{this.visibilityListeners.delete(e);}}onLinkOpened(e){return this.linkListeners.add(e),()=>{this.linkListeners.delete(e);}}emitLink(e){for(let t of [...this.linkListeners])try{t(e);}catch{}}setVisible(e){if(e!==this.visible){this.visible=e;for(let t of [...this.visibilityListeners])try{t(e);}catch{}}}};function M(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var y=class{getString(e){if(typeof localStorage>"u")return null;try{return localStorage.getItem(e)}catch{return null}}setString(e,t){if(!(typeof localStorage>"u"))try{localStorage.setItem(e,t);}catch{}}remove(e){if(!(typeof localStorage>"u"))try{localStorage.removeItem(e);}catch{}}},T=class{map=new Map;getString(e){return this.map.get(e)??null}setString(e,t){this.map.set(e,t);}remove(e){this.map.delete(e);}};function F(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function L(r,e={}){if(typeof Worker>"u")return null;try{let t=typeof location<"u"?location.href:void 0,o=t?new URL(r,t):new URL(r),s={type:"module",name:e.name};if(o.protocol==="blob:"||o.protocol==="data:"||!t||o.origin===new URL(t).origin)return new Worker(o.href,s);let n=URL.createObjectURL(new Blob([`import ${JSON.stringify(o.href)};`],{type:"text/javascript"}));return new Worker(n,s)}catch{return null}}function m(){return globalThis.Telegram?.WebApp??null}var Ve={Virtual:"Virtual",Crypto:"Crypto"},Ke=z$1.enum(["Virtual","Crypto"]).catch("Virtual"),ze={Item:"Item",VirtualCurrency:"VirtualCurrency",CryptoCurrency:"CryptoCurrency",RewardedVideoCredit:"RewardedVideoCredit",Purchase:"Purchase",PlatformCredits:"PlatformCredits"},je=z$1.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item"),a={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"},Qe=z$1.enum(["Unknown","Web","Android","Ios"]).catch("Unknown"),$e={GooglePlay:"GooglePlay",AppleAppStore:"AppleAppStore"},Je=z$1.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay"),Ye={TimedEvent:"TimedEvent",Quest:"Quest",Leaderboard:"Leaderboard",CoopEvent:"CoopEvent",Season:"Season"},Xe=z$1.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season"]).catch("TimedEvent"),Ze={AlwaysOn:"AlwaysOn",Scheduled:"Scheduled",Chained:"Chained",Triggered:"Triggered",Cyclic:"Cyclic",Relative:"Relative"},et=z$1.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic"),tt={None:"None",Device:"Device",Email:"Email",iDosGames:"iDosGames",Facebook:"Facebook",Google:"Google",Apple:"Apple",GooglePlay:"GooglePlay",Telegram:"Telegram",Wallet:"Wallet"};function re(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return te(e);let t=r.cordova?.platformId;return t?te(t):r.navigator?.userAgent??""?a.Web:a.Unknown}function te(r){let e=r.toLowerCase();return e==="android"?a.Android:e==="ios"?a.Ios:e==="web"?a.Web:a.Unknown}var S=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",oe=/^[a-z0-9]{8}-preview\.idos\.games$/;function G(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function V(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return oe.test(r)?true:G(r)&&globalThis.__IDOS_PREVIEW__!=null}function h(r){if(typeof window<"u"&&oe.test(window.location.hostname.toLowerCase()))return r===N;if(S.includes(r))return true;if(typeof window>"u"||!G(window.location.hostname))return false;try{return G(new URL(r).hostname)}catch{return false}}var se="IDOS_PLATFORM_WALLET_ACK",ne="PLATFORM_WALLET_UNAVAILABLE",be=5e3,ve=18e4;function He(){if(h(N))return [N];let r=[...S],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&h(e)&&r.push(e),r}function we(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:ne,data:{}};if(typeof window>"u"||window.self===window.top)return Promise.resolve(s);let n=window.parent;if(!n)return Promise.resolve(s);let i=we(),c=o.answerTimeoutMs??ve;return new Promise(R=>{let f=false,x,W=b=>{f||(f=true,window.removeEventListener("message",X),clearTimeout(x),R(b));},X=b=>{if(!h(b.origin))return;let p=b.data;if(!(!p||p.requestId!==i)){if(p.type===se){clearTimeout(x),x=setTimeout(()=>W({ok:false,error:"TIMEOUT",data:{}}),c);return}p.type===e&&W({ok:p.ok===true,error:typeof p.error=="string"?p.error:void 0,data:p});}};x=setTimeout(()=>W(s),be),window.addEventListener("message",X);for(let b of He())try{n.postMessage({type:r,requestId:i,...t},b);}catch{}})}var K={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Se=30*6e4;function ie(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(V())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!S.includes(r))try{let e=new URL(r).hostname;if(e!=="localhost"&&e!=="127.0.0.1")return !1}catch{return false}return true}function z(){if(typeof window>"u"||!V())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ae(r){let e=await u(K.request,K.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Se}),t=e.data.ticket;if(e.ok&&typeof t=="string"&&t.length>0)return {ticket:t};let o=e.data.code;return e.ok&&typeof o=="string"&&o.length>0?{code:o}:{error:e.error??"no_code"}}var j={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},Ae=15*6e4,Re=/^[a-z0-9]{8}-preview\.idos\.games$/;function A(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Re.test(window.location.hostname.toLowerCase())}async function le(r){let e=await u(j.request,j.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:Ae});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},Ie=5*6e4;function ue(){return A()}async function ce(r){let e=await u(Q.request,Q.response,{titleID:r.titleID,userID:r.userID,requestID:r.requestID,placementID:r.placementID,adUnitID:r.adUnitID??null},{answerTimeoutMs:Ie});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var $={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},ke=10*6e4,Te=["DECLINED","NOT_ENOUGH_CREDITS"];function pe(){let r=globalThis.navigator?.userAgent??"";if(!/\biDosGamesApp\/(?:player|studio)\//.test(r))return true;let e=/\biDosGamesPlatform\/(ios|android)\b/.exec(r);return (e?e[1]:/\bAndroid\b/.test(r)?"android":"ios")!=="ios"}function de(){return A()}async function me(r){let e=await u($.request,$.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var ge="IDOS_APP_FRAME_HIDDEN";function P(){return globalThis.navigator??null}function q(){return typeof window<"u"}function fe(){if(!q())return false;try{return window.self!==window.top}catch{return true}}var C=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new y){if(super(e,new g),!q()){this.id="web",this.supports=H;return}let t=P(),o=ie();this.supports=Object.freeze({autoSignIn:o,signIn:o||z(),rewardedAds:ue(),titleAds:false,storePurchases:false,creditsPayments:pe(),creditsConfirm:de(),cryptoTopUp:A(),sceneCaptureRequests:fe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:F(),filePicker:k(),pushNotifications:false}),this.id=m()?"telegram":z()?"preview":this.supports.cryptoTopUp?"site":"web",this.watchVisibility(),window.addEventListener("hashchange",()=>this.emitLink(window.location.href));}watchVisibility(){typeof document<"u"&&(this.documentHidden=document.visibilityState==="hidden",document.addEventListener("visibilitychange",()=>{this.documentHidden=document.visibilityState==="hidden",this.update();})),fe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==ge||h(e.origin)&&(this.hiddenBySite=t.hidden===true,this.update());}),this.update();}update(){this.setVisible(!this.documentHidden&&!this.hiddenBySite);}getPlatform(){return m()?.platform??"Web"}getClientPlatform(){return re()}getFullURL(){return q()?window.location.href:""}getStartParameter(){let e=m()?.initDataUnsafe?.start_param;return typeof e=="string"?e:null}getReferrer(){return typeof document>"u"?null:document.referrer||null}getTelegramInitDataRaw(){let e=m()?.initData;return e&&e.length>0?e:null}getDeviceModel(){return P()?.userAgent||"Web"}getLanguage(){return P()?.language||""}async signIn(e){return this.supports.signIn?ae(e):{error:l}}async showRewardedAd(e){return this.supports.rewardedAds?ce(e):{ok:false,error:l}}async confirmCredits(e){return this.supports.creditsConfirm?me(e):{ok:false,error:l}}async topUp(e){return this.supports.cryptoTopUp?le(e):{ok:false,error:l}}openInvoice(e){let t=m();if(t?.openInvoice){t.openInvoice(e);return}this.openUrl(e);}openUrl(e){let t=m();if(t?.openTelegramLink&&/^https:\/\/t\.me\//i.test(e)){t.openTelegramLink(e);return}q()&&window.open(e,"_blank","noopener");}async share(e){let t=P();if(t?.share)try{return await t.share({url:e.url||void 0,title:e.title,text:e.text}),"shared"}catch(o){if(o?.name==="AbortError")return "cancelled"}return await this.copyText(I(e))?"copied":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=P();if(typeof File<"u"&&o?.share&&o.canShare){let n=new File([t],e.name,{type:e.mime});if(o.canShare({files:[n]}))try{return await o.share({files:[n],title:e.name}),"shared"}catch(i){if(i?.name==="AbortError")return "cancelled"}}let s=document.createElement("a");return s.href=URL.createObjectURL(t),s.download=e.name,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(s.href),3e4),"saved"}async copyText(e){let t=P();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return Ce(e)}vibrate(e){try{P()?.vibrate?.(M(e));}catch{}}createWorker(e,t){return L(e,t)}};function Ce(r){if(typeof document>"u"||!document.body)return false;let e=document.createElement("textarea");e.value=r,e.setAttribute("readonly",""),e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let t=false;try{t=document.execCommand("copy");}catch{t=false;}return e.remove(),t}var J=1,ye="__IDOS_HOST__";function Y(){let r=globalThis[ye];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var Oe={signIn:30*6e4,showRewardedAd:5*6e4,confirmCredits:10*6e4,topUp:15*6e4,openInvoice:3e4,openUrl:3e4,share:10*6e4,shareFile:10*6e4,copyText:3e4,vibrate:3e4,buyProduct:30*6e4,finishPurchase:6e4,pendingPurchases:6e4,requestPushToken:10*6e4};function _e(r){switch((r??"").toLowerCase()){case "android":return a.Android;case "ios":return a.Ios;case "web":return a.Web;default:return a.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new y){super(t,new g),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??H[n];this.supports=Object.freeze({autoSignIn:s("autoSignIn"),signIn:s("signIn")||s("autoSignIn"),rewardedAds:s("rewardedAds")||s("titleAds"),titleAds:s("titleAds"),storePurchases:s("storePurchases"),creditsPayments:s("creditsPayments"),creditsConfirm:s("creditsConfirm"),cryptoTopUp:s("cryptoTopUp"),sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:F(),filePicker:k(),pushNotifications:s("pushNotifications")}),e.receive=n=>this.receive(n),e.info?.visible===false&&this.setVisible(false);}receive(e){let t;try{t=JSON.parse(e);}catch{return}if(!(!t||t.v!==1)){if(t.kind==="response"&&typeof t.id=="string"){let o=this.pending.get(t.id);if(!o)return;this.pending.delete(t.id),clearTimeout(o.timer),o.resolve(t.ok===true?{ok:true,result:t.result??{}}:{ok:false,error:typeof t.error=="string"?t.error:"FAILED"});return}if(t.kind==="event"&&t.name==="visibility"){let o=t.data;typeof o?.visible=="boolean"&&this.setVisible(o.visible);return}if(t.kind==="event"&&t.name==="link"){let o=t.data;typeof o?.url=="string"&&o.url&&this.emitLink(o.url);}}}request(e,t){let o=`r${this.nextId++}`,s={v:1,kind:"request",id:o,method:e,params:t};return new Promise(n=>{let i=setTimeout(()=>{this.pending.delete(o),n({ok:false,error:"TIMEOUT"});},Oe[e]);this.pending.set(o,{resolve:n,timer:i});try{this.shell.post(JSON.stringify(s));}catch{clearTimeout(i),this.pending.delete(o),n({ok:false,error:"UNAVAILABLE"});}})}notify(e,t){this.request(e,t);}newDeviceID(){return this.shell.info?.deviceId||super.newDeviceID()}getPlatform(){return this.getClientPlatform()===a.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return _e(this.shell.clientPlatform)}getFullURL(){return this.shell.info?.launchUrl??""}getStartParameter(){return this.shell.info?.startParameter??null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return this.shell.info?.deviceModel||this.id}getLanguage(){return this.shell.info?.language||""}async signIn(e){if(!this.supports.signIn)return {error:"UNAVAILABLE"};let t=await this.request("signIn",{titleID:e});if(!t.ok)return {error:t.error};let{code:o,ticket:s}=t.result;return typeof s=="string"&&s.length>0?{ticket:s}:typeof o=="string"&&o.length>0?{code:o}:{error:"no_code"}}async showRewardedAd(e){if(!this.supports.rewardedAds)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("showRewardedAd",e);return t.ok?{ok:true,via:t.result.via==="unit"?"unit":"ad"}:{ok:false,error:t.error}}async confirmCredits(e){if(!this.supports.creditsConfirm)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("confirmCredits",e);return t.ok?{ok:true}:{ok:false,error:t.error}}async topUp(e){if(!this.supports.cryptoTopUp)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("topUp",e);return t.ok?{ok:true}:{ok:false,error:t.error}}openInvoice(e){this.notify("openInvoice",{url:e});}async buyProduct(e){if(!this.supports.storePurchases)return {ok:false,error:"UNAVAILABLE"};let t=await this.request("buyProduct",e);if(!t.ok)return {ok:false,error:t.error};let o=t.result.receipt;return o&&typeof o.receipt=="string"&&o.receipt?{ok:true,receipt:o}:{ok:false,error:"FAILED"}}async finishPurchase(e,t){return this.supports.storePurchases?(await this.request("finishPurchase",{receipt:e,consumable:t})).ok:false}async pendingPurchases(){if(!this.supports.storePurchases)return [];let e=await this.request("pendingPurchases",{});return !e.ok||!Array.isArray(e.result.receipts)?[]:e.result.receipts.filter(t=>t&&typeof t.receipt=="string"&&t.receipt)}async requestPushToken(e){if(!this.supports.pushNotifications)return {error:"UNAVAILABLE"};let t=await this.request("requestPushToken",{prompt:e.prompt===true});if(!t.ok)return {error:t.error};let{token:o,transport:s}=t.result;return typeof o!="string"||!o?{error:"UNAVAILABLE"}:{token:o,transport:s==="Apns"?"Apns":"Fcm"}}openUrl(e){this.notify("openUrl",{url:e});}async share(e){if(!this.supports.share)return await this.copyText(I(e))?"copied":"unavailable";let t=await this.request("share",e);return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}pickFiles(e){return U(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:xe(e.bytes)});return t.ok?t.result.outcome??"shared":t.error==="CANCELLED"?"cancelled":"unavailable"}async copyText(e){return (await this.request("copyText",{text:e})).ok}vibrate(e){this.supports.vibration&&this.notify("vibrate",{pattern:M(e)});}createWorker(e,t){return L(e,t)}};function xe(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var _=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new T),this.supports=Object.freeze({...H,...t.supports}),this.clientPlatform=t.clientPlatform??a.Web,this.deviceId=t.deviceId??"memory-device";}setVisibleForTest(e){this.setVisible(e);}newDeviceID(){return this.deviceId}getPlatform(){return "Web"}getClientPlatform(){return this.clientPlatform}getFullURL(){return ""}getStartParameter(){return null}getReferrer(){return null}getTelegramInitDataRaw(){return null}getDeviceModel(){return "Memory"}getLanguage(){return ""}async signIn(){return {error:l}}async showRewardedAd(){return {ok:false,error:l}}async confirmCredits(){return {ok:false,error:l}}async topUp(){return {ok:false,error:l}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Ee(){let r=Y();return r?new O(r):typeof window>"u"?new _:new C}
2
- export{h as A,se as B,ne as C,u as D,K as E,j as F,Q as G,$ as H,Te as I,ge as J,C as K,Ee as L,Z as a,v as b,g as c,y as d,T as e,Ve as f,Ke as g,ze as h,je as i,a as j,Qe as k,$e as l,Je as m,Ye as n,Xe as o,Ze as p,et as q,tt as r,_ as s,I as t,J as u,ye as v,Y as w,O as x,m as y,S as z};