@jolibox/native-bridge 1.3.5-beta.9 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var je=Object.defineProperty,$e=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ae=(e,r,t)=>r in e?je(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,b=(e,r)=>{for(var t in r||(r={}))ce.call(r,t)&&ae(e,t,r[t]);if(D)for(var t of D(r))ue.call(r,t)&&ae(e,t,r[t]);return e},le=(e,r)=>$e(e,Ve(r));var de=(e,r)=>{var t={};for(var n in e)ce.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&D)for(var n of D(e))r.indexOf(n)<0&&ue.call(e,n)&&(t[n]=e[n]);return t};var R=(e,r,t)=>new Promise((n,s)=>{var i=u=>{try{o(t.next(u))}catch(c){s(c)}},a=u=>{try{o(t.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((t=t.apply(e,r)).next())});function He(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=r.charCodeAt(s);return n.buffer};function C(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!He(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let s;n.value?s=n.value:n.base64&&(s=Ge(n.base64)),typeof s!="undefined"&&s instanceof ArrayBuffer&&(e[n.key]=s)}}return e}var Ke=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let s=0;s<n;s++)r+=String.fromCharCode(t[s]);return btoa(r)};function ge(e={},r=!1){let t=e,n=[];for(let[s,i]of Object.entries(t))if(i!==void 0&&i instanceof ArrayBuffer&&i.byteLength!==void 0){let a=r?{value:i,key:s}:{base64:Ke(i),key:s};n.push(a),delete t[s]}return n.length>0&&(t.__nativeBuffers__=n),t}var he=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var ze=(e,r)=>{for(var t in r)he(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{for(var s=n>1?void 0:n?We(r,t):r,i=e.length-1,a;i>=0;i--)(a=e[i])&&(s=(n?a(r,t,s):a(s))||s);return n&&s&&he(r,t,s),s},Ye=(e,r,t)=>new Promise((n,s)=>{var i=u=>{try{o(t.next(u))}catch(c){s(c)}},a=u=>{try{o(t.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let s=this._eventListeners[t].indexOf(n);s!==-1&&this._eventListeners[t].splice(s,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function Qe(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var ve=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function Q(e){return typeof e=="string"}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function X(e){return typeof e=="number"&&!isNaN(e)}function Xe(e){return typeof e=="undefined"}function Ze(e){return Xe(e)||e===null}function be(e){return typeof e=="function"}function ye(e){return S(e)&&be(e.then)}function _e(e){let r=e,t=null,n=function(...s){return t||(t=new r(...s)),t};return n.prototype=r.prototype,n}var er=(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))(er||{}),rr=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}},U=class extends rr{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Se=class extends U{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends U{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var Ee=class extends U{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var L=class extends U{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function k(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var I={log:k("log"),warn:k("warn"),info:k("info"),error:k("error"),debug:k("debug")};Object.assign(globalThis,{logger:I});var me=Symbol.for("Jolibox.canIUseMap"),tr={};globalThis[me]||(globalThis[me]=tr);function Re(e,r,t){let n=e;for(let s of r)if(n&&typeof n=="object")n=n[s];else return t;return n===void 0?t:n}var G=Symbol.for("Jolibox.canIUseMap.native"),nr={};globalThis[G]||(globalThis[G]=nr);var q={get config(){return globalThis[G]}};var sr=(e=>(e[e.Other=0]="Other",e[e.Route=1]="Route",e[e.Click=2]="Click",e[e.View=3]="View",e[e.Expose=4]="Expose",e[e.Swipe=5]="Swipe",e[e.Input=6]="Input",e[e.Select=7]="Select",e[e.SwitchOn=8]="SwitchOn",e[e.SwitchOff=9]="SwitchOff",e[e.Submit=10]="Submit",e[e.Scroll=11]="Scroll",e[e.Hide=12]="Hide",e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(sr||{}),ir=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(ir||{}),or=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(or||{});function ar(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}ar();var A=typeof window=="undefined",Ae=()=>!A&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),Ir={isiOS:!A&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3]||"0",10)]},isAndroid:!A&&navigator.userAgent.includes("Android"),isMac:!A&&navigator.userAgent.includes("Mac"),isFacebook:!A&&navigator.userAgent.includes("FB_IAB"),isPC:!A&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var K=class W{constructor(r){this.element=r,this.next=W.Undefined,this.prev=W.Undefined}};K.Undefined=new K(void 0);var m=K,cr=class{constructor(){this._first=m.Undefined,this._last=m.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let r=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=r}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new m(e);if(this._first===m.Undefined)this._first=t,this._last=t;else if(r){let s=this._last;this._last=t,t.prev=s,s.next=t}else{let s=this._first;this._first=t,t.next=s,s.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}},ur=0,w=class{constructor(e){this.value=e,this.id=ur++}},P=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof w&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,s,i,a,o,u;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let c=new w(r);return this._listeners?this._listeners instanceof w?this._listeners=[this._listeners,c]:this._listeners.push(c):((s=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||s.call(n,this),this._listeners=c,(a=(i=this.options)==null?void 0:i.onDidFirstListener)==null||a.call(i,this)),(u=(o=this.options)==null?void 0:o.onDidAddListener)==null||u.call(o,this),this._size++,()=>{var l,d,g,p;if(!this._disposed){if(this._listeners instanceof w)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(d=(l=this.options)==null?void 0:l.onDidRemoveLastListener)==null||d.call(l));else if(this._listeners){let v=this._listeners.indexOf(c);v>=0&&(this._listeners.splice(v,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(s){n(s)}}fire(e){this._listeners&&(this._listeners instanceof w?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},B=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let s=(n=this.listeners.get(e))!=null?n:new P,i=u=>r(...u.args),a=s.event(i);this.listerHandlerMap.set(r,{handler:i,dispose:a}),this.listeners.set(e,s);let o=this.cachedEventQueue.get(e);if(o&&t)for(let u of o)r(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new cr,this.cachedEventQueue.set(e,n)),n.push({args:r}),t&&t.fire({event:e,args:r})}once(e,r){let t=(...n)=>{r(...n),this.off(e,t)};this.on(e,t,!1)}},z={};ze(z,{None:()=>lr,filter:()=>gr,once:()=>Ie,toPromise:()=>dr});var lr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function dr(e){return new Promise(r=>Ie(e)(r))}function Ie(e){return(r,t=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,r.call(t,s)},null)}}function gr(e,r){return(t=>{let n,s={onWillAddFirstListener(){n=t(i.fire,i)}},i=new P(s);return i.event})((t,n=null)=>e(s=>r(s)&&t.call(n,s),null))}var H=Symbol.for("Jolibox.hostEmitter"),mr=()=>{let e=new B;return globalThis[H]||(globalThis[H]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[H]},xr=mr();function pr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)hr(e[n],r[n])}function hr(e,r){if(Q(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(be(r)){try{if(e instanceof r)return}catch(t){}if(!Ze(e)&&e.constructor===r||r.length===1&&r.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 Y=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new P,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 t=[];for(let s of e.metadata.args)t.push(s.constraint);let n=e.handler;e.handler=function(...s){return pr(s,t),n(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};Y=fe([_e],Y);var pe=class{constructor(){this._onWillExecuteCommand=new P,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new P,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new Y,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Qe(3e4)),this._starActivation}executeCommand(e,...r){return Ye(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),z.toPromise(z.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};pe=fe([_e],pe);var Tr=Symbol.for("Jolibox.commands");h("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});h("requestProductDetailsAsync",{version:102e4});h("invokeSubscriptionPanelSync",{version:107e4,properties:{type:{game:107e4,drama:107e4}}});h("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});h("getABTest",{version:1050100,platforms:{android:1050100,ios:!1}});h("userTrackAsync",{version:1e6});h("openMiniapp",{version:1050100});h("requestCoinDetailsSync",{version:1070100});h("requestCoinDetailsAsync",{version:1070100});h("sendServerEventAsync",{version:1070100});h("loadAdsAsync",{version:1070200});h("showAdAsync",{version:1070200});function h(e,r){if(q.config[e]){I.warn(`[can i use] ${e} already registered`);return}q.config[e]=b({},r)}var fr=(e,r)=>{function t(s){var d;let[i,...a]=s.split(":");if(!i)return!1;let o=q.config[i];if(!o)return!1;let u=(d=r==null?void 0:r())!=null?d:"",c=o.version;if(o.platforms&&u in o.platforms){let g=o.platforms[u];if(g===!1)return!1;typeof g=="number"&&(c=g)}if(typeof c!="number")return!1;let l=e();return typeof l!="number"||l<c?!1:a.length===0?!0:n(o,a,l)||n(o.properties,a,l)}function n(s,i,a){if(!s)return!1;let o=Re(s,i);if(!o)return!1;if(S(o)){let u=o.version;return X(u)?typeof a=="number"&&a>=u:!0}return X(o)?typeof a=="number"&&a>=o:o===!0}return{canIUseNative:t}};function O(e,r){return`[${e}]:${r}`}var xe=()=>Ae();var N="custom_event_";var Te=[],Ce=[],ke=["env","createRequestTask","login"],J="__batch_event__",we="__native_batch_event__";var vr=e=>e==="pv"?e:"default",E=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:s,tagNameOrder:i,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=s,this.tagNameOrder=i,this.metricName=a,this.type=vr(o)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,s,i,a)=>{let o=s.shift();if(o){let u=a[o];n[u]||(n[u]={}),t(n[u],s,i,a)}else n[i]||(n[i]=[]),n[i].push(a[i])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(s,i,a,o)=>{let u=i.shift();if(!u&&S(o))throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(u){let c=[];if(S(o))c.push(...Object.keys(o));else if(Q(o)){if(i.length>0)throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new L(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(l=>{s[l]||(s[l]={});let d=S(o)?o[l]:o;t(s[l],[...i],a,d)})}else s[a]?s[a]++:s[a]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},Pe=!1,Z,ee,re;function Oe(e,r){Pe||(Z=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),ee=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),re=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),r("onJoliboxEnterBackground",()=>{Z.flush(),ee.flush(),re.flush()}),Pe=!0);function t(s){var x,T;let{method:i,args:a,startTime:o,isForeground:u,errMsg:c=`${i}:fail no errMsg`,errNo:l=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=s,{receiveJSInvoke:g,invokeCallback:p}=d,v=(T=(x=c.match(/\S:(\S+)\s?/))==null?void 0:x[1])!=null?T:"fail";Z.report({status:v,method:n(i,a),errNo:`${l}`,errMsg:c,isForeground:u,duration:Date.now()-o}),o&&g&&p&&(ee.report({status:v,method:i,isForeground:u,duration:Number((g-o).toFixed(3))}),re.report({status:v,method:i,isForeground:u,duration:Number((Date.now()-p).toFixed(3))}))}function n(s,i){return(s==="callHostMethod"||s==="callHostMethodSync")&&i!=null&&i.method?`${s}-${i.method}`:s}return t}var te=[],br=!1,ne=Symbol.for("Jolibox.invokeResolverInstance"),yr=new Map;globalThis[ne]||(globalThis[ne]=yr);var _r={get resolveMap(){return globalThis[ne]}};function De(e,r){let t=0,n=!0,s=_r.resolveMap,i=Oe(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,te.forEach(g=>R(this,[g],function*({method:c,args:l,resolve:d}){let p=yield o(c,l);d(p)})),te.length=0});let a=(c,l)=>{let d=s.get(Number(c));if(!d)return;let g=C(l);d(g),s.delete(Number(c))},o=(c,l)=>{var ie,oe;let d=Date.now(),g=`${n}`;t+=1;let p=new ve;if(s.set(t,p.resolve),!n&&Ce.includes(c))return new Promise(_=>{te.push({method:c,args:l,resolve:_})});let x=le(b({},{method:c,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),T=!br&&Te.includes(c),$=ge(l,T),V=T?$:JSON.stringify($),f;if(c.endsWith("Sync")||ke.includes(c)?f=(ie=e.call)==null?void 0:ie.call(e,c,$,t):typeof V=="string"?f=e.invoke(c,V,t):f=(oe=e.call)==null?void 0:oe.call(e,c,V,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=C(f)}catch(_){I.error(_)}return s.delete(t),f.errorCode&&(f.errorCode=O(c,f.errorCode)),i(b(b({},x),f)),f}return c.endsWith("Sync")&&s.delete(t),p.promise.then(_=>(_.errorCode&&(_.errorCode=O(c,_.errorCode)),i(b(b({},x),_)),_))};return{invokeNative:o,applyNative:(c,l)=>{let d=o(c,l);return ye(d)?d.then(g=>Me(c,g)):Me(c,d)},invokeHandler:a}}function Me(e,r){if(!S(r)){I.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:s,errorCode:i}=o,a=de(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new Ne(t,n,s,i);return a}var F=Symbol.for("Jolibox.subscribeInstance");function Ue(e){if(globalThis[F])return globalThis[F];let r=new B,t=new B,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[F]={onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(s,i,a){let o=C(i),u;if(o.__extra){u=o.params;let{type:c,startTime:l}=o.__extra;n.report({type:c,event:s,duration:Date.now()-l})}else u=o;if(s===J){u.forEach(l=>{let[d,g]=l;try{t.emit(d.slice(N.length),g,a)}catch(p){}});return}if(s.startsWith(N)){t.emit(s.slice(N.length),u,a);return}r.emit(s,u,a)}},globalThis[F]}function Le(e){let r=new Map,t=new Map,n,s;return{publish:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(`${N}${o}`,u,g);return}n||(n=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let v=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(J,g,v)}catch(v){}}),n=void 0,r.clear()}));let d=r.get(c);d||(d=[],r.set(c,d)),d.push([`${N}${o}`,u])},emitNative:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(o,u,g),console.log("emitNative",o,u,g);return}s||(s=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let v=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,v)}catch(v){}}),s=void 0,t.clear()}));let d=t.get(c);d||(d=[],t.set(c,d)),d.push([o,u])}}}function se(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:s,unsubscribe:i}=Ue(e),{invokeNative:a,invokeHandler:o,applyNative:u}=De(e,t),{publish:c,emitNative:l}=Le(e);return{invokeHandler:o,subscribeHandler:r,applyNative:u,invokeNative:a,onNative:t,offNative:n,emitNative:l,publish:c,subscribe:s,unsubscribe:i}}function j(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,y={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){y.trigger=e},onDoExit(e){y.exit=e},onDoBackPress(e){y.backPress=e}},qe=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new Se("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(typeof window!="undefined"&&window.webkit){let e=window.webkit.messageHandlers,r=(s="")=>{y.trigger(),e.onDocumentReady.postMessage({path:s})},t=s=>R(void 0,null,function*(){let i=yield y.exit();e.doExit.postMessage({uuid:s,shouldInterrupt:i})});M={onDocumentReady:r,doExit:t,invoke(s,i,a){e.invoke.postMessage({event:s,paramsString:i,callbackId:a})},publish(s,i,a){let o=j(i,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:s,paramsString:JSON.stringify(o),webviewIds:a}))},call(s,i,a){let o=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(i),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:qe,doExit:t};globalThis.joliboxJSCore=b({},n)}if(typeof window!="undefined"&&window.JoliAndroidSDKBridge){let s,e=window.JoliAndroidSDKBridge,r=(i="")=>{y.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},t=i=>R(void 0,null,function*(){let a=yield y.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:a}))});M={onDocumentReady:r,invoke(i,a,o){e.invoke(JSON.stringify({event:i,paramsString:a,callbackId:o}))},doExit:t,publish(i,a,o){let u=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:i,paramsString:JSON.stringify(u),webviewIds:o}))},call(i,a,o){let u=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(a),callbackId:o}));if(u)return JSON.parse(u)},doBackPress(i){return R(this,null,function*(){let a=yield y.backPress();e.doBackPress(JSON.stringify({uuid:i,shouldInterrupt:a}))})}};let n={onDocumentReady:r,env:qe,doExit:t};globalThis.joliboxJSCore=b({},n)}var Je=M;if(!Je&&xe())throw new Ee("No joliboxJScore is found, native bridge not found.");var Sr=b({},Je),Fe=se(Sr),{invokeHandler:Be}=Fe,{applyNative:Gt,invokeNative:Kt,onNative:Nr,offNative:Wt,subscribeHandler:Er,publish:zt,emitNative:Yt,subscribe:Qt,unsubscribe:Xt}=Fe,Zt=(e,r)=>{Nr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=O(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Be,invokeHandler:Be,subscribeHandler:Er};export{y as RuntimeLoader,Gt as applyNative,Yt as emitNative,Kt as invokeNative,Wt as offNative,Nr as onNative,Zt as onNativeWithError,zt as publish,fr as registerCanIUseContext,Qt as subscribe,Er as subscribeHandler,Xt as unsubscribe};
1
+ var je=Object.defineProperty,Ve=Object.defineProperties;var $e=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ae=(e,r,t)=>r in e?je(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,b=(e,r)=>{for(var t in r||(r={}))ce.call(r,t)&&ae(e,t,r[t]);if(D)for(var t of D(r))ue.call(r,t)&&ae(e,t,r[t]);return e},le=(e,r)=>Ve(e,$e(r));var de=(e,r)=>{var t={};for(var n in e)ce.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&D)for(var n of D(e))r.indexOf(n)<0&&ue.call(e,n)&&(t[n]=e[n]);return t};var R=(e,r,t)=>new Promise((n,s)=>{var i=u=>{try{o(t.next(u))}catch(c){s(c)}},a=u=>{try{o(t.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((t=t.apply(e,r)).next())});function He(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=r.charCodeAt(s);return n.buffer};function C(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!He(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let s;n.value?s=n.value:n.base64&&(s=Ge(n.base64)),typeof s!="undefined"&&s instanceof ArrayBuffer&&(e[n.key]=s)}}return e}var Ke=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let s=0;s<n;s++)r+=String.fromCharCode(t[s]);return btoa(r)};function ge(e={},r=!1){let t=e,n=[];for(let[s,i]of Object.entries(t))if(i!==void 0&&i instanceof ArrayBuffer&&i.byteLength!==void 0){let a=r?{value:i,key:s}:{base64:Ke(i),key:s};n.push(a),delete t[s]}return n.length>0&&(t.__nativeBuffers__=n),t}var he=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var ze=(e,r)=>{for(var t in r)he(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{for(var s=n>1?void 0:n?We(r,t):r,i=e.length-1,a;i>=0;i--)(a=e[i])&&(s=(n?a(r,t,s):a(s))||s);return n&&s&&he(r,t,s),s},Ye=(e,r,t)=>new Promise((n,s)=>{var i=u=>{try{o(t.next(u))}catch(c){s(c)}},a=u=>{try{o(t.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let s=this._eventListeners[t].indexOf(n);s!==-1&&this._eventListeners[t].splice(s,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function Qe(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var ve=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function Q(e){return typeof e=="string"}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function X(e){return typeof e=="number"&&!isNaN(e)}function Xe(e){return typeof e=="undefined"}function Ze(e){return Xe(e)||e===null}function be(e){return typeof e=="function"}function ye(e){return S(e)&&be(e.then)}function _e(e){let r=e,t=null,n=function(...s){return t||(t=new r(...s)),t};return n.prototype=r.prototype,n}var er=(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))(er||{}),rr=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}},U=class extends rr{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Se=class extends U{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends U{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var Ee=class extends U{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var L=class extends U{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function k(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var I={log:k("log"),warn:k("warn"),info:k("info"),error:k("error"),debug:k("debug")};Object.assign(globalThis,{logger:I});var me=Symbol.for("Jolibox.canIUseMap"),tr={};globalThis[me]||(globalThis[me]=tr);function Re(e,r,t){let n=e;for(let s of r)if(n&&typeof n=="object")n=n[s];else return t;return n===void 0?t:n}var G=Symbol.for("Jolibox.canIUseMap.native"),nr={};globalThis[G]||(globalThis[G]=nr);var q={get config(){return globalThis[G]}};var sr=(e=>(e[e.Other=0]="Other",e[e.Route=1]="Route",e[e.Click=2]="Click",e[e.View=3]="View",e[e.Expose=4]="Expose",e[e.Swipe=5]="Swipe",e[e.Input=6]="Input",e[e.Select=7]="Select",e[e.SwitchOn=8]="SwitchOn",e[e.SwitchOff=9]="SwitchOff",e[e.Submit=10]="Submit",e[e.Scroll=11]="Scroll",e[e.Hide=12]="Hide",e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(sr||{}),ir=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(ir||{}),or=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(or||{});function ar(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}ar();var A=typeof window=="undefined",Ae=()=>!A&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),Ir={isiOS:!A&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3]||"0",10)]},isAndroid:!A&&navigator.userAgent.includes("Android"),isMac:!A&&navigator.userAgent.includes("Mac"),isFacebook:!A&&navigator.userAgent.includes("FB_IAB"),isPC:!A&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var K=class W{constructor(r){this.element=r,this.next=W.Undefined,this.prev=W.Undefined}};K.Undefined=new K(void 0);var m=K,cr=class{constructor(){this._first=m.Undefined,this._last=m.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let r=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=r}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new m(e);if(this._first===m.Undefined)this._first=t,this._last=t;else if(r){let s=this._last;this._last=t,t.prev=s,s.next=t}else{let s=this._first;this._first=t,t.next=s,s.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}},ur=0,w=class{constructor(e){this.value=e,this.id=ur++}},P=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof w&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,s,i,a,o,u;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let c=new w(r);return this._listeners?this._listeners instanceof w?this._listeners=[this._listeners,c]:this._listeners.push(c):((s=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||s.call(n,this),this._listeners=c,(a=(i=this.options)==null?void 0:i.onDidFirstListener)==null||a.call(i,this)),(u=(o=this.options)==null?void 0:o.onDidAddListener)==null||u.call(o,this),this._size++,()=>{var l,d,g,p;if(!this._disposed){if(this._listeners instanceof w)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(d=(l=this.options)==null?void 0:l.onDidRemoveLastListener)==null||d.call(l));else if(this._listeners){let v=this._listeners.indexOf(c);v>=0&&(this._listeners.splice(v,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(s){n(s)}}fire(e){this._listeners&&(this._listeners instanceof w?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},B=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let s=(n=this.listeners.get(e))!=null?n:new P,i=u=>r(...u.args),a=s.event(i);this.listerHandlerMap.set(r,{handler:i,dispose:a}),this.listeners.set(e,s);let o=this.cachedEventQueue.get(e);if(o&&t)for(let u of o)r(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new cr,this.cachedEventQueue.set(e,n)),n.push({args:r}),t&&t.fire({event:e,args:r})}once(e,r){let t=(...n)=>{r(...n),this.off(e,t)};this.on(e,t,!1)}},z={};ze(z,{None:()=>lr,filter:()=>gr,once:()=>Ie,toPromise:()=>dr});var lr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function dr(e){return new Promise(r=>Ie(e)(r))}function Ie(e){return(r,t=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,r.call(t,s)},null)}}function gr(e,r){return(t=>{let n,s={onWillAddFirstListener(){n=t(i.fire,i)}},i=new P(s);return i.event})((t,n=null)=>e(s=>r(s)&&t.call(n,s),null))}var H=Symbol.for("Jolibox.hostEmitter"),mr=()=>{let e=new B;return globalThis[H]||(globalThis[H]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[H]},xr=mr();function pr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)hr(e[n],r[n])}function hr(e,r){if(Q(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(be(r)){try{if(e instanceof r)return}catch(t){}if(!Ze(e)&&e.constructor===r||r.length===1&&r.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 Y=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new P,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 t=[];for(let s of e.metadata.args)t.push(s.constraint);let n=e.handler;e.handler=function(...s){return pr(s,t),n(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};Y=fe([_e],Y);var pe=class{constructor(){this._onWillExecuteCommand=new P,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new P,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new Y,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Qe(3e4)),this._starActivation}executeCommand(e,...r){return Ye(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),z.toPromise(z.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};pe=fe([_e],pe);var Tr=Symbol.for("Jolibox.commands");h("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});h("requestProductDetailsAsync",{version:102e4});h("invokeSubscriptionPanelSync",{version:107e4,properties:{type:{game:107e4,drama:107e4}}});h("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});h("getABTest",{version:1050100,platforms:{android:1050100,ios:!1}});h("userTrackAsync",{version:1e6});h("openMiniapp",{version:1050100});h("requestCoinDetailsSync",{version:1070100});h("requestCoinDetailsAsync",{version:1070100});h("sendServerEventAsync",{version:1070100});h("loadAdsAsync",{version:1070200});h("showAdAsync",{version:1070200});function h(e,r){if(q.config[e]){I.warn(`[can i use] ${e} already registered`);return}q.config[e]=b({},r)}var fr=(e,r)=>{function t(s){var d;let[i,...a]=s.split(":");if(!i)return!1;let o=q.config[i];if(!o)return!1;let u=(d=r==null?void 0:r())!=null?d:"",c=o.version;if(o.platforms&&u in o.platforms){let g=o.platforms[u];if(g===!1)return!1;typeof g=="number"&&(c=g)}if(typeof c!="number")return!1;let l=e();return typeof l!="number"||l<c?!1:a.length===0?!0:n(o,a,l)||n(o.properties,a,l)}function n(s,i,a){if(!s)return!1;let o=Re(s,i);if(!o)return!1;if(S(o)){let u=o.version;return X(u)?typeof a=="number"&&a>=u:!0}return X(o)?typeof a=="number"&&a>=o:o===!0}return{canIUseNative:t}};function O(e,r){return`[${e}]:${r}`}var xe=()=>Ae();var N="custom_event_";var Te=[],Ce=[],ke=["env","createRequestTask","login"],J="__batch_event__",we="__native_batch_event__";var vr=e=>e==="pv"?e:"default",E=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:s,tagNameOrder:i,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=s,this.tagNameOrder=i,this.metricName=a,this.type=vr(o)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,s,i,a)=>{let o=s.shift();if(o){let u=a[o];n[u]||(n[u]={}),t(n[u],s,i,a)}else n[i]||(n[i]=[]),n[i].push(a[i])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(s,i,a,o)=>{let u=i.shift();if(!u&&S(o))throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(u){let c=[];if(S(o))c.push(...Object.keys(o));else if(Q(o)){if(i.length>0)throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new L(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(l=>{s[l]||(s[l]={});let d=S(o)?o[l]:o;t(s[l],[...i],a,d)})}else s[a]?s[a]++:s[a]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},Pe=!1,Z,ee,re;function Oe(e,r){Pe||(Z=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),ee=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),re=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),r("onJoliboxEnterBackground",()=>{Z.flush(),ee.flush(),re.flush()}),Pe=!0);function t(s){var x,T;let{method:i,args:a,startTime:o,isForeground:u,errMsg:c=`${i}:fail no errMsg`,errNo:l=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=s,{receiveJSInvoke:g,invokeCallback:p}=d,v=(T=(x=c.match(/\S:(\S+)\s?/))==null?void 0:x[1])!=null?T:"fail";Z.report({status:v,method:n(i,a),errNo:`${l}`,errMsg:c,isForeground:u,duration:Date.now()-o}),o&&g&&p&&(ee.report({status:v,method:i,isForeground:u,duration:Number((g-o).toFixed(3))}),re.report({status:v,method:i,isForeground:u,duration:Number((Date.now()-p).toFixed(3))}))}function n(s,i){return(s==="callHostMethod"||s==="callHostMethodSync")&&i!=null&&i.method?`${s}-${i.method}`:s}return t}var te=[],br=!1,ne=Symbol.for("Jolibox.invokeResolverInstance"),yr=new Map;globalThis[ne]||(globalThis[ne]=yr);var _r={get resolveMap(){return globalThis[ne]}};function De(e,r){let t=0,n=!0,s=_r.resolveMap,i=Oe(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,te.forEach(g=>R(this,[g],function*({method:c,args:l,resolve:d}){let p=yield o(c,l);d(p)})),te.length=0});let a=(c,l)=>{let d=s.get(Number(c));if(!d)return;let g=C(l);d(g),s.delete(Number(c))},o=(c,l)=>{var ie,oe;let d=Date.now(),g=`${n}`;t+=1;let p=new ve;if(s.set(t,p.resolve),!n&&Ce.includes(c))return new Promise(_=>{te.push({method:c,args:l,resolve:_})});let x=le(b({},{method:c,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),T=!br&&Te.includes(c),V=ge(l,T),$=T?V:JSON.stringify(V),f;if(c.endsWith("Sync")||ke.includes(c)?f=(ie=e.call)==null?void 0:ie.call(e,c,V,t):typeof $=="string"?f=e.invoke(c,$,t):f=(oe=e.call)==null?void 0:oe.call(e,c,$,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=C(f)}catch(_){I.error(_)}return s.delete(t),f.errorCode&&(f.errorCode=O(c,f.errorCode)),i(b(b({},x),f)),f}return c.endsWith("Sync")&&s.delete(t),p.promise.then(_=>(_.errorCode&&(_.errorCode=O(c,_.errorCode)),i(b(b({},x),_)),_))};return{invokeNative:o,applyNative:(c,l)=>{let d=o(c,l);return ye(d)?d.then(g=>Me(c,g)):Me(c,d)},invokeHandler:a}}function Me(e,r){if(!S(r)){I.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:s,errorCode:i}=o,a=de(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new Ne(t,n,s,i);return a}var F=Symbol.for("Jolibox.subscribeInstance");function Ue(e){if(globalThis[F])return globalThis[F];let r=new B,t=new B,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[F]={onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(s,i,a){let o=C(i),u;if(o.__extra){u=o.params;let{type:c,startTime:l}=o.__extra;n.report({type:c,event:s,duration:Date.now()-l})}else u=o;if(s===J){u.forEach(l=>{let[d,g]=l;try{t.emit(d.slice(N.length),g,a)}catch(p){}});return}if(s.startsWith(N)){t.emit(s.slice(N.length),u,a);return}r.emit(s,u,a)}},globalThis[F]}function Le(e){let r=new Map,t=new Map,n,s;return{publish:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(`${N}${o}`,u,g);return}n||(n=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let v=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(J,g,v)}catch(v){}}),n=void 0,r.clear()}));let d=r.get(c);d||(d=[],r.set(c,d)),d.push([`${N}${o}`,u])},emitNative:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(o,u,g),console.log("emitNative",o,u,g);return}s||(s=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let v=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,v)}catch(v){}}),s=void 0,t.clear()}));let d=t.get(c);d||(d=[],t.set(c,d)),d.push([o,u])}}}function se(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:s,unsubscribe:i}=Ue(e),{invokeNative:a,invokeHandler:o,applyNative:u}=De(e,t),{publish:c,emitNative:l}=Le(e);return{invokeHandler:o,subscribeHandler:r,applyNative:u,invokeNative:a,onNative:t,offNative:n,emitNative:l,publish:c,subscribe:s,unsubscribe:i}}function j(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,y={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){y.trigger=e},onDoExit(e){y.exit=e},onDoBackPress(e){y.backPress=e}},qe=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new Se("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(typeof window!="undefined"&&window.webkit){let e=window.webkit.messageHandlers,r=(s="")=>{y.trigger(),e.onDocumentReady.postMessage({path:s})},t=s=>R(void 0,null,function*(){let i=yield y.exit();e.doExit.postMessage({uuid:s,shouldInterrupt:i})});M={onDocumentReady:r,doExit:t,invoke(s,i,a){e.invoke.postMessage({event:s,paramsString:i,callbackId:a})},publish(s,i,a){let o=j(i,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:s,paramsString:JSON.stringify(o),webviewIds:a}))},call(s,i,a){let o=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(i),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:qe,doExit:t};globalThis.joliboxJSCore=b({},n)}if(typeof window!="undefined"&&window.JoliAndroidSDKBridge){let s,e=window.JoliAndroidSDKBridge,r=(i="")=>{y.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},t=i=>R(void 0,null,function*(){let a=yield y.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:a}))});M={onDocumentReady:r,invoke(i,a,o){e.invoke(JSON.stringify({event:i,paramsString:a,callbackId:o}))},doExit:t,publish(i,a,o){let u=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:i,paramsString:JSON.stringify(u),webviewIds:o}))},call(i,a,o){let u=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(a),callbackId:o}));if(u)return JSON.parse(u)},doBackPress(i){return R(this,null,function*(){let a=yield y.backPress();e.doBackPress(JSON.stringify({uuid:i,shouldInterrupt:a}))})}};let n={onDocumentReady:r,env:qe,doExit:t};globalThis.joliboxJSCore=b({},n)}var Je=M;if(!Je&&xe())throw new Ee("No joliboxJScore is found, native bridge not found.");var Sr=b({},Je),Fe=se(Sr),{invokeHandler:Be}=Fe,{applyNative:Gt,invokeNative:Kt,onNative:Nr,offNative:Wt,subscribeHandler:Er,publish:zt,emitNative:Yt,subscribe:Qt,unsubscribe:Xt}=Fe,Zt=(e,r)=>{Nr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=O(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Be,invokeHandler:Be,subscribeHandler:Er};export{y as RuntimeLoader,Gt as applyNative,Yt as emitNative,Kt as invokeNative,Wt as offNative,Nr as onNative,Zt as onNativeWithError,zt as publish,fr as registerCanIUseContext,Qt as subscribe,Er as subscribeHandler,Xt as unsubscribe};
@@ -16,7 +16,7 @@ declare global {
16
16
  provider: 'ADMOB' | 'APPLOVIN';
17
17
  params: {
18
18
  placementId: string;
19
- adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL';
19
+ adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL' | 'NATIVE';
20
20
  extra?: Record<string, any>;
21
21
  };
22
22
  }
@@ -669,7 +669,7 @@ declare global {
669
669
  errNo?: number;
670
670
  errMsg?: string;
671
671
  subPlanId: string; // 订阅Id
672
- tickedId?: string;
672
+ ticketId?: string;
673
673
  };
674
674
  }
675
675
  ];
@@ -682,7 +682,7 @@ declare global {
682
682
  errNo?: number;
683
683
  errMsg?: string;
684
684
  subPlanId: string; // 订阅Id
685
- tickedId?: string;
685
+ ticketId?: string;
686
686
  };
687
687
  }
688
688
  ];
@@ -695,7 +695,7 @@ declare global {
695
695
  errNo?: number;
696
696
  errMsg?: string;
697
697
  subPlanId: string; // 订阅Id
698
- tickedId?: string; // for iOS
698
+ ticketId?: string; // for iOS
699
699
  };
700
700
  }
701
701
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jolibox/native-bridge",
3
3
  "description": "This project is Jolibox JS-SDk bridge for Native",
4
- "version": "1.3.5-beta.9",
4
+ "version": "1.3.6",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -11,15 +11,15 @@
11
11
  ],
12
12
  "types": "./dist/index.d.ts",
13
13
  "dependencies": {
14
- "@jolibox/common": "1.3.5-beta.9",
15
- "@jolibox/types": "1.3.5-beta.9"
14
+ "@jolibox/common": "1.3.6",
15
+ "@jolibox/types": "1.3.6"
16
16
  },
17
17
  "devDependencies": {
18
18
  "typescript": "5.7.3",
19
19
  "@types/jest": "28.1.1",
20
20
  "rimraf": "6.0.1",
21
21
  "esbuild": "0.24.2",
22
- "@jolibox/eslint-config": "1.0.1-beta.16"
22
+ "@jolibox/eslint-config": "1.0.1-beta.19"
23
23
  },
24
24
  "scripts": {
25
25
  "clean": "rimraf ./dist",
@@ -16,7 +16,7 @@ declare global {
16
16
  provider: 'ADMOB' | 'APPLOVIN';
17
17
  params: {
18
18
  placementId: string;
19
- adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL';
19
+ adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL' | 'NATIVE';
20
20
  extra?: Record<string, any>;
21
21
  };
22
22
  }
@@ -669,7 +669,7 @@ declare global {
669
669
  errNo?: number;
670
670
  errMsg?: string;
671
671
  subPlanId: string; // 订阅Id
672
- tickedId?: string;
672
+ ticketId?: string;
673
673
  };
674
674
  }
675
675
  ];
@@ -682,7 +682,7 @@ declare global {
682
682
  errNo?: number;
683
683
  errMsg?: string;
684
684
  subPlanId: string; // 订阅Id
685
- tickedId?: string;
685
+ ticketId?: string;
686
686
  };
687
687
  }
688
688
  ];
@@ -695,7 +695,7 @@ declare global {
695
695
  errNo?: number;
696
696
  errMsg?: string;
697
697
  subPlanId: string; // 订阅Id
698
- tickedId?: string; // for iOS
698
+ ticketId?: string; // for iOS
699
699
  };
700
700
  }
701
701
  ];