@jolibox/sdk 1.1.4-beta.1 → 1.1.4-beta.3

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.
@@ -3,13 +3,13 @@
3
3
  "packages/sdk/.rush/temp/shrinkwrap-deps.json": "2dae37e4e0434d977846f6598de8fbcb9919efc5",
4
4
  "packages/sdk/.eslintrc.js": "c11c589d14fe58bf4d37d259d8323b193bab6092",
5
5
  "packages/sdk/README.md": "5660cd88848b7a5428394cc34d881a35dd402188",
6
- "packages/sdk/package.json": "756b84976306471c206279636d233f7ad64e5871",
6
+ "packages/sdk/package.json": "10bac6bd2a44b325432606b5e4534f5c98fa9c38",
7
7
  "packages/sdk/src/api/__tests__/canIUse.test.ts": "27fbe5050ac2e95d6643ff5fec335ba4d22ceb93",
8
8
  "packages/sdk/src/api/can-i-use.ts": "c6f9e896d05a63eabd754ab01d90711186eb8959",
9
9
  "packages/sdk/src/api/get-system-info.ts": "20eed7f356c629708452bb6f61cc05774f054070",
10
10
  "packages/sdk/src/api/index.ts": "d7390d30c9207b1450e018898a21cc458f6e613e",
11
11
  "packages/sdk/src/errors.ts": "1e74d62516994468d8f402d3ad2de999d3b0bb86",
12
- "packages/sdk/src/index.ts": "aab8ffff507dc63da0257e41460dd33b22dca7fd",
12
+ "packages/sdk/src/index.ts": "2c22b6c790b467bf675fc1f354450de3d4d2c045",
13
13
  "packages/sdk/src/loader/h5.ts": "76be98a2ec6c1fc2ad585772b22042b4f41dbd64",
14
14
  "packages/sdk/src/loader/index.ts": "9410ac6ccfa67ae44e6a6cb02f90a333da8f87c9",
15
15
  "packages/sdk/src/loader/native.ts": "ae1261a36a77a215e9d01b3aaed49e5bab0afb06",
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var r in t)N(e,r,{get:t[r],enumerable:!0})},Ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ae(t))!Le.call(e,s)&&s!==r&&N(e,s,{get:()=>t[s],enumerable:!(n=Ue(t,s))||n.enumerable});return e};var Te=e=>Ce(N({},"__esModule",{value:!0}),e);var tt={};we(tt,{JoliboxSDK:()=>Q});module.exports=Te(tt);var Y=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Oe=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},X=(e,t,r,n)=>{for(var s=n>1?void 0:n?De(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&Y(t,r,s),s};function Ne(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function j(e){return typeof e=="string"}function q(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ke(e){return typeof e>"u"}function Pe(e){return Ke(e)||e===null}function Me(e){return typeof e=="function"}function Z(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var ke=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(ke||{}),je=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},ee=class extends je{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var te=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Je={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Je});var re=Symbol.for("Jolibox.canIUseMap"),Fe={};globalThis[re]=Fe;var ne={get config(){return globalThis[re]}};function J(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Be=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Ve=0,I=class{constructor(e){this.value=e,this.id=Ve++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},F=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Be,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},M={};Oe(M,{None:()=>Ge,filter:()=>He,once:()=>se,toPromise:()=>$e});var Ge=()=>{console.log("[Jolibox SDK] None Event")};function $e(e){return new Promise(t=>se(e)(t))}function se(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function He(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var K=Symbol.for("Jolibox.hostEmitter"),ze=()=>{let e=new F;return globalThis[K]||(globalThis[K]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[K]},oe=ze();function We(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Qe(e[n],t[n])}function Qe(e,t){if(j(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Me(t)){try{if(e instanceof t)return}catch{}if(!Pe(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return We(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=X([Z],A);var k=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ne(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),M.toPromise(M.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};k=X([Z],k);var P=Symbol.for("Jolibox.commands");function h(){if(globalThis[P])return globalThis[P];let e=new A,t=new k,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[P]=r,r}document.addEventListener("DOMContentLoaded",()=>oe.emit("onDocumentReady"));var ie=h(),B=e=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=B;window.addEventListener("unhandledrejection",B.bind(void 0));window.addEventListener("error",B.bind(void 0));window.onerror=(e,t,r,n,s)=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var V=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},S=e=>parseInt(V(e).major,10),b=(e,t)=>{let{major:r,minor:n,patch:s}=V(e),{major:o,minor:i,patch:l}=V(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var ae=h(),L=(e,t)=>{ae.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{ae.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var le="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(le)??"{}"),G=Date.now(),ce=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,me=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ye(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:G};if(n){let{bootstrap_version:o}=x;if(!(o&&b(o,n))){let i=await(await fetch($(n))).text();me(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&b(o,r))){let i=await(await fetch(H(r))).text();me(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(le,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var de=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ce(G,d)&&S(c)==t&&b(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new te(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),Ie=await import(f);return URL.revokeObjectURL(f),Ie}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ce(G,m)&&S(d)==t&&b(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ye()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var ue=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Xe="1.0.0",he=Xe,z=S(he),_e=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,qe=typeof _e<"u",$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,H=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,pe=$(z),fe=H(z);function Ze(){qe?ue(_e,{bootstrapUrl:pe,implementUrl:fe})():de({bootstrapUrl:pe,implementUrl:fe,currentMajorVersion:z,currentVersion:he})()}Ze();var W=h();async function ge(){return await W.executeCommand("API.getSystemInfo")}function Ee(){return W.excuteCommandSync("API.getSystemInfoSync")}function ye(){return W.excuteCommandSync("API.env")}function Re(e,t){return ne.config[e]?.[t]}function ve(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var be="1.0.0";function w(e){let r=ye().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Re(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||J(be,i,"<")?!1:s.length===0?!0:Se(o,s)||Se(o.properties,s)}function Se(e,t){if(!e)return!1;let r=ve(e,t);return r?q(r)?!0:j(r)?J(be,r,">="):!1:!1}var xe=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new F}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var et="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(et,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var Q=class{constructor(){this.runtime=new xe;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=ge.bind(this);this.getSystemInfoSync=Ee.bind(this);this.canIUse=w.bind(this)}};
1
+ "use strict";var K=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var r in t)K(e,r,{get:t[r],enumerable:!0})},Ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ae(t))!Le.call(e,s)&&s!==r&&K(e,s,{get:()=>t[s],enumerable:!(n=Ue(t,s))||n.enumerable});return e};var Te=e=>Ce(K({},"__esModule",{value:!0}),e);var tt={};we(tt,{JoliboxSDK:()=>N});module.exports=Te(tt);var Y=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Oe=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},X=(e,t,r,n)=>{for(var s=n>1?void 0:n?De(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&Y(t,r,s),s};function Ne(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function J(e){return typeof e=="string"}function q(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ke(e){return typeof e>"u"}function Pe(e){return Ke(e)||e===null}function Me(e){return typeof e=="function"}function Z(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var ke=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(ke||{}),je=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},ee=class extends je{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var te=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Je={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Je});var re=Symbol.for("Jolibox.canIUseMap"),Fe={};globalThis[re]=Fe;var ne={get config(){return globalThis[re]}};function F(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Be=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Ve=0,I=class{constructor(e){this.value=e,this.id=Ve++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},B=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Be,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},k={};Oe(k,{None:()=>Ge,filter:()=>He,once:()=>se,toPromise:()=>$e});var Ge=()=>{console.log("[Jolibox SDK] None Event")};function $e(e){return new Promise(t=>se(e)(t))}function se(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function He(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var P=Symbol.for("Jolibox.hostEmitter"),ze=()=>{let e=new B;return globalThis[P]||(globalThis[P]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[P]},oe=ze();function We(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Qe(e[n],t[n])}function Qe(e,t){if(J(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Me(t)){try{if(e instanceof t)return}catch{}if(!Pe(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return We(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=X([Z],A);var j=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ne(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),k.toPromise(k.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};j=X([Z],j);var M=Symbol.for("Jolibox.commands");function h(){if(globalThis[M])return globalThis[M];let e=new A,t=new j,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[M]=r,r}document.addEventListener("DOMContentLoaded",()=>oe.emit("onDocumentReady"));var ie=h(),V=e=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=V;window.addEventListener("unhandledrejection",V.bind(void 0));window.addEventListener("error",V.bind(void 0));window.onerror=(e,t,r,n,s)=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var G=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},b=e=>parseInt(G(e).major,10),S=(e,t)=>{let{major:r,minor:n,patch:s}=G(e),{major:o,minor:i,patch:l}=G(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var ae=h(),L=(e,t)=>{ae.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{ae.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var le="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(le)??"{}"),$=Date.now(),ce=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,me=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ye(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:$};if(n){let{bootstrap_version:o}=x;if(!(o&&S(o,n))){let i=await(await fetch(H(n))).text();me(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&S(o,r))){let i=await(await fetch(z(r))).text();me(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(le,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var de=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ce($,d)&&b(c)==t&&S(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new te(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),Ie=await import(f);return URL.revokeObjectURL(f),Ie}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ce($,m)&&b(d)==t&&S(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ye()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var ue=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Xe="1.0.0",he=Xe,W=b(he),_e=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,qe=typeof _e<"u",H=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,z=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,pe=H(W),fe=z(W);function Ze(){qe?ue(_e,{bootstrapUrl:pe,implementUrl:fe})():de({bootstrapUrl:pe,implementUrl:fe,currentMajorVersion:W,currentVersion:he})()}Ze();var Q=h();async function ge(){return await Q.executeCommand("API.getSystemInfo")}function Ee(){return Q.excuteCommandSync("API.getSystemInfoSync")}function ye(){return Q.excuteCommandSync("API.env")}function Re(e,t){return ne.config[e]?.[t]}function ve(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var Se="1.0.0";function w(e){let r=ye().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Re(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||F(Se,i,"<")?!1:s.length===0?!0:be(o,s)||be(o.properties,s)}function be(e,t){if(!e)return!1;let r=ve(e,t);return r?q(r)?!0:J(r)?F(Se,r,">="):!1:!1}var xe=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new B}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var et="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(et,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var N=class{constructor(){this.runtime=new xe;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=ge.bind(this);this.getSystemInfoSync=Ee.bind(this);this.canIUse=w.bind(this)}};window.JoliboxSDK=N;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,11 @@ import { LifecycleSDK } from './sdks/lifecycle';
12
12
  import { StorageSDK } from './sdks/storage';
13
13
  import { JoliboxAds } from './sdks/ads';
14
14
  import { KeyboardSDK } from './sdks/keyboard';
15
+ declare global {
16
+ interface Window {
17
+ JoliboxSDK: typeof JoliboxSDK;
18
+ }
19
+ }
15
20
  export declare class JoliboxSDK {
16
21
  readonly runtime: any;
17
22
  readonly ads: JoliboxAds;
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- var W=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ue=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},Q=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ie(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&W(t,r,s),s};function Ae(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function k(e){return typeof e=="string"}function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Le(e){return typeof e>"u"}function we(e){return Le(e)||e===null}function Ce(e){return typeof e=="function"}function X(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var Te=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Te||{}),De=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},q=class extends De{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Z=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Oe={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Oe});var ee=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[ee]=Ne;var te={get config(){return globalThis[ee]}};function j(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Ke=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Pe=0,I=class{constructor(e){this.value=e,this.id=Pe++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Ke,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},P={};Ue(P,{None:()=>Me,filter:()=>je,once:()=>re,toPromise:()=>ke});var Me=()=>{console.log("[Jolibox SDK] None Event")};function ke(e){return new Promise(t=>re(e)(t))}function re(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function je(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var N=Symbol.for("Jolibox.hostEmitter"),Je=()=>{let e=new J;return globalThis[N]||(globalThis[N]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[N]},ne=Je();function Fe(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Be(e[n],t[n])}function Be(e,t){if(k(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Ce(t)){try{if(e instanceof t)return}catch{}if(!we(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return Fe(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=Q([X],A);var M=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ae(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),P.toPromise(P.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};M=Q([X],M);var K=Symbol.for("Jolibox.commands");function h(){if(globalThis[K])return globalThis[K];let e=new A,t=new M,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[K]=r,r}document.addEventListener("DOMContentLoaded",()=>ne.emit("onDocumentReady"));var se=h(),F=e=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=F;window.addEventListener("unhandledrejection",F.bind(void 0));window.addEventListener("error",F.bind(void 0));window.onerror=(e,t,r,n,s)=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var B=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},S=e=>parseInt(B(e).major,10),b=(e,t)=>{let{major:r,minor:n,patch:s}=B(e),{major:o,minor:i,patch:l}=B(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var oe=h(),L=(e,t)=>{oe.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{oe.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var ce="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(ce)??"{}"),V=Date.now(),ie=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ae=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ve(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:V};if(n){let{bootstrap_version:o}=x;if(!(o&&b(o,n))){let i=await(await fetch(G(n))).text();ae(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&b(o,r))){let i=await(await fetch($(r))).text();ae(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(ce,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var me=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ie(V,d)&&S(c)==t&&b(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new Z(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),xe=await import(f);return URL.revokeObjectURL(f),xe}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ie(V,m)&&S(d)==t&&b(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ve()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var le=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Ge="1.0.0",pe=Ge,H=S(pe),fe=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,$e=typeof fe<"u",G=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,de=G(H),ue=$(H);function He(){$e?le(fe,{bootstrapUrl:de,implementUrl:ue})():me({bootstrapUrl:de,implementUrl:ue,currentMajorVersion:H,currentVersion:pe})()}He();var z=h();async function he(){return await z.executeCommand("API.getSystemInfo")}function _e(){return z.excuteCommandSync("API.getSystemInfoSync")}function ge(){return z.excuteCommandSync("API.env")}function Ee(e,t){return te.config[e]?.[t]}function ye(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var ve="1.0.0";function w(e){let r=ge().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Ee(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||j(ve,i,"<")?!1:s.length===0?!0:Re(o,s)||Re(o.properties,s)}function Re(e,t){if(!e)return!1;let r=ye(e,t);return r?Y(r)?!0:k(r)?j(ve,r,">="):!1:!1}var Se=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new J}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var ze="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(ze,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var be=class{constructor(){this.runtime=new Se;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=he.bind(this);this.getSystemInfoSync=_e.bind(this);this.canIUse=w.bind(this)}};export{be as JoliboxSDK};
1
+ var Q=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ue=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},Y=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ie(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&Q(t,r,s),s};function Ae(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function k(e){return typeof e=="string"}function X(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Le(e){return typeof e>"u"}function we(e){return Le(e)||e===null}function Ce(e){return typeof e=="function"}function q(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var Te=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Te||{}),De=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},Z=class extends De{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var ee=class extends Z{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends Z{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Oe={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Oe});var te=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[te]=Ne;var re={get config(){return globalThis[te]}};function j(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Ke=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Pe=0,I=class{constructor(e){this.value=e,this.id=Pe++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Ke,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},P={};Ue(P,{None:()=>Me,filter:()=>je,once:()=>ne,toPromise:()=>ke});var Me=()=>{console.log("[Jolibox SDK] None Event")};function ke(e){return new Promise(t=>ne(e)(t))}function ne(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function je(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var N=Symbol.for("Jolibox.hostEmitter"),Je=()=>{let e=new J;return globalThis[N]||(globalThis[N]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[N]},se=Je();function Fe(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Be(e[n],t[n])}function Be(e,t){if(k(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Ce(t)){try{if(e instanceof t)return}catch{}if(!we(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return Fe(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=Y([q],A);var M=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ae(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),P.toPromise(P.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};M=Y([q],M);var K=Symbol.for("Jolibox.commands");function h(){if(globalThis[K])return globalThis[K];let e=new A,t=new M,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[K]=r,r}document.addEventListener("DOMContentLoaded",()=>se.emit("onDocumentReady"));var oe=h(),F=e=>{oe.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=F;window.addEventListener("unhandledrejection",F.bind(void 0));window.addEventListener("error",F.bind(void 0));window.onerror=(e,t,r,n,s)=>{oe.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var B=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},b=e=>parseInt(B(e).major,10),S=(e,t)=>{let{major:r,minor:n,patch:s}=B(e),{major:o,minor:i,patch:l}=B(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var ie=h(),L=(e,t)=>{ie.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{ie.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var me="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(me)??"{}"),V=Date.now(),ae=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ce=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ve(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:V};if(n){let{bootstrap_version:o}=x;if(!(o&&S(o,n))){let i=await(await fetch(G(n))).text();ce(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&S(o,r))){let i=await(await fetch($(r))).text();ce(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(me,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var le=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ae(V,d)&&b(c)==t&&S(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new ee(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),xe=await import(f);return URL.revokeObjectURL(f),xe}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ae(V,m)&&b(d)==t&&S(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ve()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var de=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Ge="1.0.0",fe=Ge,H=b(fe),he=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,$e=typeof he<"u",G=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,ue=G(H),pe=$(H);function He(){$e?de(he,{bootstrapUrl:ue,implementUrl:pe})():le({bootstrapUrl:ue,implementUrl:pe,currentMajorVersion:H,currentVersion:fe})()}He();var z=h();async function _e(){return await z.executeCommand("API.getSystemInfo")}function ge(){return z.excuteCommandSync("API.getSystemInfoSync")}function Ee(){return z.excuteCommandSync("API.env")}function ye(e,t){return re.config[e]?.[t]}function Re(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var be="1.0.0";function w(e){let r=Ee().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=ye(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||j(be,i,"<")?!1:s.length===0?!0:ve(o,s)||ve(o.properties,s)}function ve(e,t){if(!e)return!1;let r=Re(e,t);return r?X(r)?!0:k(r)?j(be,r,">="):!1:!1}var Se=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new J}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var ze="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(ze,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var W=class{constructor(){this.runtime=new Se;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=_e.bind(this);this.getSystemInfoSync=ge.bind(this);this.canIUse=w.bind(this)}};window.JoliboxSDK=W;export{W as JoliboxSDK};
@@ -1 +1 @@
1
- "use strict";(()=>{var W=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ue=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},Q=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ie(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&W(t,r,s),s};function Ae(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function k(e){return typeof e=="string"}function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Le(e){return typeof e>"u"}function we(e){return Le(e)||e===null}function Ce(e){return typeof e=="function"}function X(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var Te=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Te||{}),De=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},q=class extends De{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Z=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Oe={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Oe});var ee=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[ee]=Ne;var te={get config(){return globalThis[ee]}};function j(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Ke=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Pe=0,I=class{constructor(e){this.value=e,this.id=Pe++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Ke,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},P={};Ue(P,{None:()=>Me,filter:()=>je,once:()=>re,toPromise:()=>ke});var Me=()=>{console.log("[Jolibox SDK] None Event")};function ke(e){return new Promise(t=>re(e)(t))}function re(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function je(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var N=Symbol.for("Jolibox.hostEmitter"),Je=()=>{let e=new J;return globalThis[N]||(globalThis[N]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[N]},ne=Je();function Fe(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Be(e[n],t[n])}function Be(e,t){if(k(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Ce(t)){try{if(e instanceof t)return}catch{}if(!we(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return Fe(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=Q([X],A);var M=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ae(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),P.toPromise(P.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};M=Q([X],M);var K=Symbol.for("Jolibox.commands");function h(){if(globalThis[K])return globalThis[K];let e=new A,t=new M,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[K]=r,r}document.addEventListener("DOMContentLoaded",()=>ne.emit("onDocumentReady"));var se=h(),F=e=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=F;window.addEventListener("unhandledrejection",F.bind(void 0));window.addEventListener("error",F.bind(void 0));window.onerror=(e,t,r,n,s)=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var B=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},S=e=>parseInt(B(e).major,10),b=(e,t)=>{let{major:r,minor:n,patch:s}=B(e),{major:o,minor:i,patch:l}=B(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var oe=h(),L=(e,t)=>{oe.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{oe.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var ce="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(ce)??"{}"),V=Date.now(),ie=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ae=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ve(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:V};if(n){let{bootstrap_version:o}=x;if(!(o&&b(o,n))){let i=await(await fetch(G(n))).text();ae(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&b(o,r))){let i=await(await fetch($(r))).text();ae(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(ce,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var me=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ie(V,d)&&S(c)==t&&b(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new Z(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),xe=await import(f);return URL.revokeObjectURL(f),xe}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ie(V,m)&&S(d)==t&&b(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ve()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var le=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Ge="1.0.0",pe=Ge,H=S(pe),fe=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,$e=typeof fe<"u",G=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,de=G(H),ue=$(H);function He(){$e?le(fe,{bootstrapUrl:de,implementUrl:ue})():me({bootstrapUrl:de,implementUrl:ue,currentMajorVersion:H,currentVersion:pe})()}He();var z=h();async function he(){return await z.executeCommand("API.getSystemInfo")}function _e(){return z.excuteCommandSync("API.getSystemInfoSync")}function ge(){return z.excuteCommandSync("API.env")}function Ee(e,t){return te.config[e]?.[t]}function ye(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var ve="1.0.0";function w(e){let r=ge().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Ee(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||j(ve,i,"<")?!1:s.length===0?!0:Re(o,s)||Re(o.properties,s)}function Re(e,t){if(!e)return!1;let r=ye(e,t);return r?Y(r)?!0:k(r)?j(ve,r,">="):!1:!1}var Se=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new J}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var ze="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(ze,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var be=class{constructor(){this.runtime=new Se;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=he.bind(this);this.getSystemInfoSync=_e.bind(this);this.canIUse=w.bind(this)}};})();
1
+ "use strict";(()=>{var Q=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ue=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},Y=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ie(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&Q(t,r,s),s};function Ae(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function k(e){return typeof e=="string"}function X(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Le(e){return typeof e>"u"}function we(e){return Le(e)||e===null}function Ce(e){return typeof e=="function"}function q(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var Te=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Te||{}),De=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},Z=class extends De{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var ee=class extends Z{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends Z{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Oe={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Oe});var te=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[te]=Ne;var re={get config(){return globalThis[te]}};function j(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Ke=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Pe=0,I=class{constructor(e){this.value=e,this.id=Pe++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Ke,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},P={};Ue(P,{None:()=>Me,filter:()=>je,once:()=>ne,toPromise:()=>ke});var Me=()=>{console.log("[Jolibox SDK] None Event")};function ke(e){return new Promise(t=>ne(e)(t))}function ne(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function je(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var N=Symbol.for("Jolibox.hostEmitter"),Je=()=>{let e=new J;return globalThis[N]||(globalThis[N]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[N]},se=Je();function Fe(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Be(e[n],t[n])}function Be(e,t){if(k(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Ce(t)){try{if(e instanceof t)return}catch{}if(!we(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return Fe(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=Y([q],A);var M=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ae(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),P.toPromise(P.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};M=Y([q],M);var K=Symbol.for("Jolibox.commands");function h(){if(globalThis[K])return globalThis[K];let e=new A,t=new M,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[K]=r,r}document.addEventListener("DOMContentLoaded",()=>se.emit("onDocumentReady"));var oe=h(),F=e=>{oe.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=F;window.addEventListener("unhandledrejection",F.bind(void 0));window.addEventListener("error",F.bind(void 0));window.onerror=(e,t,r,n,s)=>{oe.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var B=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},b=e=>parseInt(B(e).major,10),S=(e,t)=>{let{major:r,minor:n,patch:s}=B(e),{major:o,minor:i,patch:l}=B(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var ie=h(),L=(e,t)=>{ie.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{ie.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var me="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(me)??"{}"),V=Date.now(),ae=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ce=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ve(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:V};if(n){let{bootstrap_version:o}=x;if(!(o&&S(o,n))){let i=await(await fetch(G(n))).text();ce(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&S(o,r))){let i=await(await fetch($(r))).text();ce(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(me,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var le=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ae(V,d)&&b(c)==t&&S(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new ee(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),xe=await import(f);return URL.revokeObjectURL(f),xe}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ae(V,m)&&b(d)==t&&S(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ve()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var de=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Ge="1.0.0",fe=Ge,H=b(fe),he=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,$e=typeof he<"u",G=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,ue=G(H),pe=$(H);function He(){$e?de(he,{bootstrapUrl:ue,implementUrl:pe})():le({bootstrapUrl:ue,implementUrl:pe,currentMajorVersion:H,currentVersion:fe})()}He();var z=h();async function _e(){return await z.executeCommand("API.getSystemInfo")}function ge(){return z.excuteCommandSync("API.getSystemInfoSync")}function Ee(){return z.excuteCommandSync("API.env")}function ye(e,t){return re.config[e]?.[t]}function Re(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var be="1.0.0";function w(e){let r=Ee().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=ye(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||j(be,i,"<")?!1:s.length===0?!0:ve(o,s)||ve(o.properties,s)}function ve(e,t){if(!e)return!1;let r=Re(e,t);return r?X(r)?!0:k(r)?j(be,r,">="):!1:!1}var Se=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new J}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var ze="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(ze,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var W=class{constructor(){this.runtime=new Se;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=_e.bind(this);this.getSystemInfoSync=ge.bind(this);this.canIUse=w.bind(this)}};window.JoliboxSDK=W;})();
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jolibox/sdk",
3
3
  "description": "This project is common Jolibox JS-SDk interfere",
4
- "version": "1.1.4-beta.1",
4
+ "version": "1.1.4-beta.3",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "@jolibox/common": "1.1.4-beta.1",
11
- "@jolibox/types": "1.1.4-beta.1"
10
+ "@jolibox/common": "1.1.4-beta.3",
11
+ "@jolibox/types": "1.1.4-beta.3"
12
12
  },
13
13
  "devDependencies": {
14
14
  "typescript": "5.7.3",
package/sdk.build.log CHANGED
@@ -1,17 +0,0 @@
1
- Invoking: npm run clean && npm run build:cjs && npm run build:esm && npm run build:iife && tsc
2
-
3
- > @jolibox/sdk@1.1.4-beta.1 clean
4
- > rimraf ./dist
5
-
6
-
7
- > @jolibox/sdk@1.1.4-beta.1 build:cjs
8
- > esbuild ./src/index.ts --log-level=error --format=cjs --outfile=./dist/index.cjs.js --bundle --minify
9
-
10
-
11
- > @jolibox/sdk@1.1.4-beta.1 build:esm
12
- > esbuild ./src/index.ts --log-level=error --format=esm --outfile=./dist/index.es.js --bundle --minify
13
-
14
-
15
- > @jolibox/sdk@1.1.4-beta.1 build:iife
16
- > esbuild ./src/index.ts --log-level=error --format=iife --outfile=./dist/index.iife.js --bundle --minify
17
-
package/src/index.ts CHANGED
@@ -15,6 +15,12 @@ import { StorageSDK } from './sdks/storage';
15
15
  import { JoliboxAds } from './sdks/ads';
16
16
  import { KeyboardSDK } from './sdks/keyboard';
17
17
 
18
+ declare global {
19
+ interface Window {
20
+ JoliboxSDK: typeof JoliboxSDK; // TODO: code review this @Dengxue
21
+ }
22
+ }
23
+
18
24
  export class JoliboxSDK {
19
25
  readonly runtime = new RuntimeSDK();
20
26
  readonly ads = new JoliboxAds();
@@ -27,3 +33,5 @@ export class JoliboxSDK {
27
33
  getSystemInfoSync = getSystemInfoSync.bind(this);
28
34
  canIUse = canIUse.bind(this);
29
35
  }
36
+
37
+ window.JoliboxSDK = JoliboxSDK; // TODO: code review this @Dengxue