@idosgames/core 0.26.8 → 0.26.9

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.
@@ -130,6 +130,11 @@ interface HostCapabilities {
130
130
  readonly creditsConfirm: boolean;
131
131
  /** The host opens its crypto top-up window when a crypto price is short (`topUp`). */
132
132
  readonly cryptoTopUp: boolean;
133
+ /**
134
+ * The host opens the platform's trade panel for the game's token (`openTrade`): the site's page around the game,
135
+ * or a link to it from a browser. `false` in the iDos Games app (no crypto there) and in the AI Coder's preview.
136
+ */
137
+ readonly tokenTrade: boolean;
133
138
  /**
134
139
  * The host asks the game for still frames and recordings of its scene (the site's "share a shot" and
135
140
  * "best moments"); the app shell answers those requests. A native host captures by itself: `false`.
@@ -285,6 +290,13 @@ interface HostTopUpRequest {
285
290
  /** Tokens to deposit, as an exact decimal string ("12.5"). */
286
291
  amount: string;
287
292
  }
293
+ /** `openTrade` request: buy or sell the game's token in the platform's trade panel. */
294
+ interface HostTradeRequest {
295
+ titleID: string;
296
+ side: "buy" | "sell";
297
+ /** Pre-filled amount as an exact decimal string: buy = pair currency to spend, sell = tokens to sell. */
298
+ amount?: string;
299
+ }
288
300
  /** What to share: a link, a text, or both (at least one). */
289
301
  interface HostShareRequest {
290
302
  url?: string;
@@ -349,6 +361,12 @@ interface GameHost {
349
361
  confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
350
362
  /** The host's crypto top-up window (`supports.cryptoTopUp`); `ok` once the deposit is CREDITED. */
351
363
  topUp(request: HostTopUpRequest): Promise<HostResult>;
364
+ /**
365
+ * Opens the platform's trade panel for the game's token (`supports.tokenTrade`) on `side` and `amount`: the player
366
+ * signs with their own wallet there, the game never trades itself. `ok`: the panel opened (the site's own panel
367
+ * around the game, or the site's page in a new tab). Errors: `NO_TOKEN`, `BAD_REQUEST`, `UNAVAILABLE`. Never rejects.
368
+ */
369
+ openTrade(request: HostTradeRequest): Promise<HostResult>;
352
370
  /** Opens a payment invoice link (Telegram Stars; a browser tab elsewhere). */
353
371
  openInvoice(url: string): void;
354
372
  /**
@@ -407,4 +425,4 @@ interface GameHost {
407
425
  onLinkOpened(listener: (url: string) => void): HostUnsubscribe;
408
426
  }
409
427
 
410
- export { AuthType as A, ClientPlatform as C, EventTokenType as E, type GameHost as G, type HostAdProvider as H, IapStore as I, type KeyValueStorage as K, ResourceEntryType as R, ScheduleMode as S, CurrencyType as a, type HostAdRequest as b, type HostAdResult as c, type HostCapabilities as d, type HostCreditsConfirmRequest as e, type HostFile as f, type HostFileOutcome as g, type HostFileStore as h, type HostPickFilesRequest as i, type HostPushToken as j, type HostPushTokenRequest as k, type HostResult as l, type HostShareOutcome as m, type HostShareRequest as n, type HostSignInAnswer as o, type HostStore as p, type HostStorePurchaseRequest as q, type HostStorePurchaseResult as r, type HostStoreReceipt as s, type HostStoredFileInfo as t, type HostTopUpRequest as u, type HostUnsubscribe as v, type HostWorkerOptions as w, shareFallbackText as x, zIapStore as z };
428
+ export { AuthType as A, ClientPlatform as C, EventTokenType as E, type GameHost as G, type HostAdProvider as H, IapStore as I, type KeyValueStorage as K, ResourceEntryType as R, ScheduleMode as S, CurrencyType as a, type HostAdRequest as b, type HostAdResult as c, type HostCapabilities as d, type HostCreditsConfirmRequest as e, type HostFile as f, type HostFileOutcome as g, type HostFileStore as h, type HostPickFilesRequest as i, type HostPushToken as j, type HostPushTokenRequest as k, type HostResult as l, type HostShareOutcome as m, type HostShareRequest as n, type HostSignInAnswer as o, type HostStore as p, type HostStorePurchaseRequest as q, type HostStorePurchaseResult as r, type HostStoreReceipt as s, type HostStoredFileInfo as t, type HostTopUpRequest as u, type HostTradeRequest as v, type HostUnsubscribe as w, type HostWorkerOptions as x, shareFallbackText as y, zIapStore as z };
@@ -130,6 +130,11 @@ interface HostCapabilities {
130
130
  readonly creditsConfirm: boolean;
131
131
  /** The host opens its crypto top-up window when a crypto price is short (`topUp`). */
132
132
  readonly cryptoTopUp: boolean;
133
+ /**
134
+ * The host opens the platform's trade panel for the game's token (`openTrade`): the site's page around the game,
135
+ * or a link to it from a browser. `false` in the iDos Games app (no crypto there) and in the AI Coder's preview.
136
+ */
137
+ readonly tokenTrade: boolean;
133
138
  /**
134
139
  * The host asks the game for still frames and recordings of its scene (the site's "share a shot" and
135
140
  * "best moments"); the app shell answers those requests. A native host captures by itself: `false`.
@@ -285,6 +290,13 @@ interface HostTopUpRequest {
285
290
  /** Tokens to deposit, as an exact decimal string ("12.5"). */
286
291
  amount: string;
287
292
  }
293
+ /** `openTrade` request: buy or sell the game's token in the platform's trade panel. */
294
+ interface HostTradeRequest {
295
+ titleID: string;
296
+ side: "buy" | "sell";
297
+ /** Pre-filled amount as an exact decimal string: buy = pair currency to spend, sell = tokens to sell. */
298
+ amount?: string;
299
+ }
288
300
  /** What to share: a link, a text, or both (at least one). */
289
301
  interface HostShareRequest {
290
302
  url?: string;
@@ -349,6 +361,12 @@ interface GameHost {
349
361
  confirmCredits(request: HostCreditsConfirmRequest): Promise<HostResult>;
350
362
  /** The host's crypto top-up window (`supports.cryptoTopUp`); `ok` once the deposit is CREDITED. */
351
363
  topUp(request: HostTopUpRequest): Promise<HostResult>;
364
+ /**
365
+ * Opens the platform's trade panel for the game's token (`supports.tokenTrade`) on `side` and `amount`: the player
366
+ * signs with their own wallet there, the game never trades itself. `ok`: the panel opened (the site's own panel
367
+ * around the game, or the site's page in a new tab). Errors: `NO_TOKEN`, `BAD_REQUEST`, `UNAVAILABLE`. Never rejects.
368
+ */
369
+ openTrade(request: HostTradeRequest): Promise<HostResult>;
352
370
  /** Opens a payment invoice link (Telegram Stars; a browser tab elsewhere). */
353
371
  openInvoice(url: string): void;
354
372
  /**
@@ -407,4 +425,4 @@ interface GameHost {
407
425
  onLinkOpened(listener: (url: string) => void): HostUnsubscribe;
408
426
  }
409
427
 
410
- export { AuthType as A, ClientPlatform as C, EventTokenType as E, type GameHost as G, type HostAdProvider as H, IapStore as I, type KeyValueStorage as K, ResourceEntryType as R, ScheduleMode as S, CurrencyType as a, type HostAdRequest as b, type HostAdResult as c, type HostCapabilities as d, type HostCreditsConfirmRequest as e, type HostFile as f, type HostFileOutcome as g, type HostFileStore as h, type HostPickFilesRequest as i, type HostPushToken as j, type HostPushTokenRequest as k, type HostResult as l, type HostShareOutcome as m, type HostShareRequest as n, type HostSignInAnswer as o, type HostStore as p, type HostStorePurchaseRequest as q, type HostStorePurchaseResult as r, type HostStoreReceipt as s, type HostStoredFileInfo as t, type HostTopUpRequest as u, type HostUnsubscribe as v, type HostWorkerOptions as w, shareFallbackText as x, zIapStore as z };
428
+ export { AuthType as A, ClientPlatform as C, EventTokenType as E, type GameHost as G, type HostAdProvider as H, IapStore as I, type KeyValueStorage as K, ResourceEntryType as R, ScheduleMode as S, CurrencyType as a, type HostAdRequest as b, type HostAdResult as c, type HostCapabilities as d, type HostCreditsConfirmRequest as e, type HostFile as f, type HostFileOutcome as g, type HostFileStore as h, type HostPickFilesRequest as i, type HostPushToken as j, type HostPushTokenRequest as k, type HostResult as l, type HostShareOutcome as m, type HostShareRequest as n, type HostSignInAnswer as o, type HostStore as p, type HostStorePurchaseRequest as q, type HostStorePurchaseResult as r, type HostStoreReceipt as s, type HostStoredFileInfo as t, type HostTopUpRequest as u, type HostTradeRequest as v, type HostUnsubscribe as w, type HostWorkerOptions as x, shareFallbackText as y, zIapStore as z };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { a as CurrencyType, R as ResourceEntryType, S as ScheduleMode, G as GameHost, K as KeyValueStorage, A as AuthType, z as zIapStore, C as ClientPlatform } from './GameHost-gNo-pSSn.js';
2
+ import { a as CurrencyType, R as ResourceEntryType, S as ScheduleMode, G as GameHost, K as KeyValueStorage, A as AuthType, z as zIapStore, C as ClientPlatform } from './GameHost-CkI6loS9.js';
3
3
  import Decimal from 'decimal.js';
4
4
 
5
5
  type EventMap = Record<string, unknown>;
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { a as CurrencyType, R as ResourceEntryType, S as ScheduleMode, G as GameHost, K as KeyValueStorage, A as AuthType, z as zIapStore, C as ClientPlatform } from './GameHost-gNo-pSSn.cjs';
2
+ import { a as CurrencyType, R as ResourceEntryType, S as ScheduleMode, G as GameHost, K as KeyValueStorage, A as AuthType, z as zIapStore, C as ClientPlatform } from './GameHost-CkI6loS9.cjs';
3
3
  import Decimal from 'decimal.js';
4
4
 
5
5
  type EventMap = Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import {z as z$1}from'zod';function I(r){return [r.text,r.url].filter(e=>!!e).join(" ")}function re(){return crypto.randomUUID()}var ve="idos-host-files",D="files";function U(r){return new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error);})}function we(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)}},y=class{db=null;fallback=new v;open(){return this.db||(this.db=(async()=>{try{if(typeof indexedDB>"u")return null;let e=indexedDB.open(ve,1);return e.onupgradeneeded=()=>{e.result.objectStoreNames.contains(D)||e.result.createObjectStore(D,{keyPath:"key"});},await U(e)}catch{return null}})()),this.db}async store(e){let t=await this.open();if(!t)return null;try{return t.transaction(D,e).objectStore(D)}catch{return null}}async read(e){let t=await this.store("readonly");if(!t)return this.fallback.read(e);try{let o=await U(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:we(t),size:t.byteLength,updatedAt:Date.now()};return await U(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 U(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 A=c.result;if(!A)return n();let g=A.value;g.key.startsWith(e)&&s.push({key:g.key,size:g.size,updatedAt:g.updatedAt}),A.continue();};}),s.sort((n,i)=>i.updatedAt-n.updatedAt)}catch{return []}}};function T(){return typeof document<"u"&&typeof document.createElement=="function"}function M(r={}){return T()?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 oe="idos_device_id",V="idos:platformSignIn:declined:",a="UNAVAILABLE",w=Object.freeze({autoSignIn:false,signIn:false,rewardedAds:false,titleAds:false,storePurchases:false,creditsPayments:true,creditsConfirm:false,cryptoTopUp:false,tokenTrade: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;}openTrade(e){return Promise.resolve({ok:false,error:a})}buyProduct(e){return Promise.resolve({ok:false,error:a})}finishPurchase(e,t){return Promise.resolve(false)}pendingPurchases(){return Promise.resolve([])}pickFiles(e){return Promise.resolve([])}requestPushToken(e){return Promise.resolve({error:a})}getDeviceID(){let e=this.storage.getString(oe);return e||(e=this.newDeviceID(),this.storage.setString(oe,e)),e}newDeviceID(){return re()}setSignInDeclined(e,t){t?this.storage.setString(V+e,"1"):this.storage.remove(V+e);}isSignInDeclined(e){return this.storage.getString(V+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 F(r){return (typeof r=="number"?[r]:[...r]).map(t=>Math.max(0,Math.round(t)))}var h=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{}}},k=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 L(){return globalThis.crossOriginIsolated===true&&typeof SharedArrayBuffer<"u"}function q(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 $e={Virtual:"Virtual",Crypto:"Crypto"},Qe=z$1.enum(["Virtual","Crypto"]).catch("Virtual"),Je={Item:"Item",VirtualCurrency:"VirtualCurrency",CryptoCurrency:"CryptoCurrency",RewardedVideoCredit:"RewardedVideoCredit",Purchase:"Purchase",PlatformCredits:"PlatformCredits"},Ye=z$1.enum(["Item","VirtualCurrency","CryptoCurrency","RewardedVideoCredit","Purchase","PlatformCredits"]).catch("Item"),l={Unknown:"Unknown",Web:"Web",Android:"Android",Ios:"Ios"},Xe=z$1.enum(["Unknown","Web","Android","Ios"]).catch("Unknown"),Ze={GooglePlay:"GooglePlay",AppleAppStore:"AppleAppStore"},et=z$1.enum(["GooglePlay","AppleAppStore","TelegramStars"]).catch("GooglePlay"),tt={TimedEvent:"TimedEvent",Quest:"Quest",Leaderboard:"Leaderboard",CoopEvent:"CoopEvent",Season:"Season",Challenge:"Challenge",ChallengePoints:"ChallengePoints"},rt=z$1.enum(["TimedEvent","Quest","Leaderboard","CoopEvent","Season","Challenge","ChallengePoints"]).catch("TimedEvent"),ot={AlwaysOn:"AlwaysOn",Scheduled:"Scheduled",Chained:"Chained",Triggered:"Triggered",Cyclic:"Cyclic",Relative:"Relative"},st=z$1.enum(["AlwaysOn","Scheduled","Chained","Triggered","Cyclic","Relative"]).catch("Cyclic"),nt={None:"None",Device:"Device",Email:"Email",iDosGames:"iDosGames",Facebook:"Facebook",Google:"Google",Apple:"Apple",GooglePlay:"GooglePlay",Telegram:"Telegram",Wallet:"Wallet"};function ne(){let r=globalThis,e=r.Capacitor?.getPlatform?.();if(e)return se(e);let t=r.cordova?.platformId;return t?se(t):r.navigator?.userAgent??""?l.Web:l.Unknown}function se(r){let e=r.toLowerCase();return e==="android"?l.Android:e==="ios"?l.Ios:e==="web"?l.Web:l.Unknown}var f=["https://idosgames.com","https://www.idosgames.com"],N="https://platform.idosgames.com",ie=/^[a-z0-9]{8}-preview\.idos\.games$/;function K(r){return r==="localhost"||r==="127.0.0.1"||r==="[::1]"||r.endsWith(".localhost")}function C(){if(typeof window>"u")return false;let r=window.location.hostname.toLowerCase();return ie.test(r)?true:K(r)&&globalThis.__IDOS_PREVIEW__!=null}function P(r){if(typeof window<"u"&&ie.test(window.location.hostname.toLowerCase()))return r===N;if(f.includes(r))return true;if(typeof window>"u"||!K(window.location.hostname))return false;try{return K(new URL(r).hostname)}catch{return false}}var ae="IDOS_PLATFORM_WALLET_ACK",B="PLATFORM_WALLET_UNAVAILABLE",Se=5e3,Re=18e4;function Ae(){if(P(N))return [N];let r=[...f],e=window.location.ancestorOrigins?.[0];return e&&!r.includes(e)&&P(e)&&r.push(e),r}function Ie(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function u(r,e,t,o={}){let s={ok:false,error:B,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=Ie(),c=o.answerTimeoutMs??Re;return new Promise(A=>{let g=false,x,W=H=>{g||(g=true,window.removeEventListener("message",te),clearTimeout(x),A(H));},te=H=>{if(!P(H.origin))return;let p=H.data;if(!(!p||p.requestId!==i)){if(p.type===ae){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),Se),window.addEventListener("message",te);for(let H of Ae())try{n.postMessage({type:r,requestId:i,...t},H);}catch{}})}var z={request:"IDOS_PLATFORM_AUTH_REQUEST",response:"IDOS_PLATFORM_AUTH_RESPONSE"},Te=30*6e4;function le(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}if(C())return false;let r=window.location.ancestorOrigins?.[0];if(r&&!f.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 j(){if(typeof window>"u"||!C())return false;try{return window.self!==window.top&&window.parent===window.top}catch{return false}}async function ue(r){let e=await u(z.request,z.response,{titleID:r,supports:["pgs"]},{answerTimeoutMs:Te}),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 $={request:"IDOS_PLATFORM_TOPUP_REQUEST",response:"IDOS_PLATFORM_TOPUP_RESPONSE"},ke=15*6e4,Ce=/^[a-z0-9]{8}-preview\.idos\.games$/;function R(){if(typeof window>"u")return false;try{if(window.self===window.top||window.parent!==window.top)return !1}catch{return false}return !Ce.test(window.location.hostname.toLowerCase())}async function ce(r){let e=await u($.request,$.response,{titleID:r.titleID,userID:r.userID,currencyID:r.currencyID,amount:r.amount},{answerTimeoutMs:ke});return e.ok?{ok:true}:{ok:false,error:e.error}}var Q={request:"IDOS_PLATFORM_AD_REQUEST",response:"IDOS_PLATFORM_AD_RESPONSE"},_e=5*6e4;function pe(){return R()}async function de(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:_e});return e.ok?{ok:true,via:e.data.via==="unit"?"unit":"ad"}:{ok:false,error:e.error}}var J={request:"IDOS_PLATFORM_CREDITS_CONFIRM_REQUEST",response:"IDOS_PLATFORM_CREDITS_CONFIRM_RESPONSE"},Oe=10*6e4,Ee=["DECLINED","NOT_ENOUGH_CREDITS"];function me(){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 fe(){return R()}async function ge(r){let e=await u(J.request,J.response,{titleID:r.titleID,confirmationID:r.confirmationID},{answerTimeoutMs:Oe});return e.ok?{ok:true}:{ok:false,error:e.error}}var Y={request:"IDOS_PLATFORM_TRADE_REQUEST",response:"IDOS_PLATFORM_TRADE_RESPONSE"};function ye(r){return typeof r=="string"&&/^\d{1,15}(\.\d{1,18})?$/.test(r)&&Number(r)>0}function X(r,e,t){let o=`trade=${e}${t?`&amount=${encodeURIComponent(t)}`:""}`;return `${f[0]}/app/${encodeURIComponent(r)}?${o}`}async function he(r){let e=await u(Y.request,Y.response,{titleID:r.titleID,side:r.side,amount:r.amount??null});return e.ok?{ok:true}:{ok:false,error:e.error}}var be="IDOS_APP_FRAME_HIDDEN";function b(){return globalThis.navigator??null}function G(){return typeof window<"u"}function Pe(){if(!G())return false;try{return window.self!==window.top}catch{return true}}var _=class extends d{id;supports;hiddenBySite=false;documentHidden=false;constructor(e=new h){if(super(e,new y),!G()){this.id="web",this.supports=w;return}let t=b(),o=le();this.supports=Object.freeze({autoSignIn:o,signIn:o||j(),rewardedAds:pe(),titleAds:false,storePurchases:false,creditsPayments:me(),creditsConfirm:fe(),cryptoTopUp:R(),tokenTrade:!C(),sceneCaptureRequests:Pe(),share:typeof t?.share=="function",vibration:typeof t?.vibrate=="function",sharedMemory:L(),filePicker:T(),pushNotifications:false}),this.id=m()?"telegram":j()?"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();})),Pe()&&window.addEventListener("message",e=>{let t=e.data;!t||t.type!==be||P(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 ne()}getFullURL(){return G()?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 b()?.userAgent||"Web"}getLanguage(){return b()?.language||""}async signIn(e){return this.supports.signIn?ue(e):{error:a}}async showRewardedAd(e){return this.supports.rewardedAds?de(e):{ok:false,error:a}}async confirmCredits(e){return this.supports.creditsConfirm?ge(e):{ok:false,error:a}}async topUp(e){return this.supports.cryptoTopUp?ce(e):{ok:false,error:a}}async openTrade(e){if(!this.supports.tokenTrade)return {ok:false,error:a};let t=e?.side,o=e?.amount;if(!e?.titleID||t!=="buy"&&t!=="sell"||o!=null&&o!==""&&!ye(o))return {ok:false,error:"BAD_REQUEST"};if(this.supports.cryptoTopUp){let s=await he({titleID:e.titleID,side:t,amount:o||null});return s.ok?{ok:true}:{ok:false,error:s.error===B?a:s.error}}return this.openUrl(X(e.titleID,t,o||null)),{ok:true}}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}G()&&window.open(e,"_blank","noopener");}async share(e){let t=b();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 M(e)}async shareFile(e){if(typeof document>"u"||typeof Blob>"u")return "unavailable";let t=new Blob([e.bytes],{type:e.mime}),o=b();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=b();if(t?.clipboard)try{return await t.clipboard.writeText(e),!0}catch{}return xe(e)}vibrate(e){try{b()?.vibrate?.(F(e));}catch{}}createWorker(e,t){return q(e,t)}};function xe(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 Z=1,He="__IDOS_HOST__";function ee(){let r=globalThis[He];return !r||typeof r!="object"||r.protocol!==1||typeof r.post!="function"?null:r}var De={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 Ue(r){switch((r??"").toLowerCase()){case "android":return l.Android;case "ios":return l.Ios;case "web":return l.Web;default:return l.Unknown}}var O=class extends d{id;supports;shell;pending=new Map;nextId=1;constructor(e,t=new h){super(t,new y),this.shell=e,this.id=`native:${e.id??"unknown"}`;let o=e.capabilities??{},s=n=>o[n]??w[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"),tokenTrade:false,sceneCaptureRequests:false,share:s("share"),vibration:s("vibration"),sharedMemory:L(),filePicker:T(),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"});},De[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()===l.Ios?"iOS":this.getClientPlatform()}getClientPlatform(){return Ue(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 M(e)}async shareFile(e){let t=await this.request("shareFile",{name:e.name,mime:e.mime,data:Me(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:F(e)});}createWorker(e,t){return q(e,t)}};function Me(r){let e="";for(let o=0;o<r.length;o+=32768)e+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(e)}var E=class extends d{id="memory";supports;clientPlatform;deviceId;constructor(e={}){let t="getString"in e?{storage:e}:e;super(t.storage??new k),this.supports=Object.freeze({...w,...t.supports}),this.clientPlatform=t.clientPlatform??l.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:a}}async showRewardedAd(){return {ok:false,error:a}}async confirmCredits(){return {ok:false,error:a}}async topUp(){return {ok:false,error:a}}openInvoice(){}openUrl(){}async share(){return "unavailable"}async shareFile(){return "unavailable"}async copyText(){return false}vibrate(){}createWorker(){return null}};function Fe(){let r=ee();return r?new O(r):typeof window>"u"?new E:new _}
2
+ export{P as A,ae as B,B as C,u as D,z as E,$ as F,Q as G,J as H,Ee as I,Y as J,X as K,be as L,_ as M,Fe as N,re as a,v as b,y as c,h as d,k as e,$e as f,Qe as g,Je as h,Ye as i,l as j,Xe as k,Ze as l,et as m,tt as n,rt as o,ot as p,st as q,nt as r,E as s,I as t,Z as u,He as v,ee as w,O as x,m as y,f as z};