@jolibox/native-bridge 1.3.4 → 1.3.5-beta.2

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,t,r)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,v=(e,t)=>{for(var r in t||(t={}))ce.call(t,r)&&ae(e,r,t[r]);if(D)for(var r of D(t))ue.call(t,r)&&ae(e,r,t[r]);return e},le=(e,t)=>$e(e,Ve(t));var de=(e,t)=>{var r={};for(var n in e)ce.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&D)for(var n of D(e))t.indexOf(n)<0&&ue.call(e,n)&&(r[n]=e[n]);return r};var R=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});function He(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let t=atob(e),r=t.length,n=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=t.charCodeAt(s);return n.buffer};function I(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(r){return{}}if(typeof e!="object"||e===null)return{};if(!He(e))return e;let t=e.__nativeBuffers__;if(delete e.__nativeBuffers__,t)for(let r=0;r<t.length;r++){let n=t[r];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 t="",r=new Uint8Array(e),n=r.byteLength;for(let s=0;s<n;s++)t+=String.fromCharCode(r[s]);return btoa(t)};function ge(e={},t=!1){let r=e,n=[];for(let[s,i]of Object.entries(r))if(i!==void 0&&i instanceof ArrayBuffer&&i.byteLength!==void 0){let a=t?{value:i,key:s}:{base64:Ke(i),key:s};n.push(a),delete r[s]}return n.length>0&&(r.__nativeBuffers__=n),r}var he=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=(e,t)=>{for(var r in t)he(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{for(var s=n>1?void 0:n?ze(t,r):t,i=e.length-1,a;i>=0;i--)(a=e[i])&&(s=(n?a(t,r,s):a(s))||s);return n&&s&&he(t,r,s),s},Ye=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new t};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let r=new Event("abort");this.signal.dispatchEvent(r)};let t=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(t.prototype,"aborted",{get:function(){return this._aborted}}),t.prototype.addEventListener=function(r,n){this._eventListeners[r]||(this._eventListeners[r]=[]),this._eventListeners[r].push(n)},t.prototype.removeEventListener=function(r,n){if(!this._eventListeners[r])return;let s=this._eventListeners[r].indexOf(n);s!==-1&&this._eventListeners[r].splice(s,1)},t.prototype.dispatchEvent=function(r){if(this._eventListeners[r.type])for(let n of this._eventListeners[r.type])n.call(this,r)},window.AbortController=e,window.AbortSignal=t}function Qe(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}var ve=class{constructor(){this.state="pending",this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};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 t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var et=(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))(et||{}),tt=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 tt{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,t,r,n){super(e),this.errNo=t,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=r,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 C(e){return(...t)=>{var r,n;((n=(r=globalThis.VConsole)==null?void 0:r[e])!=null?n:globalThis.console[e])(...t)}}var x={log:C("log"),warn:C("warn"),info:C("info"),error:C("error"),debug:C("debug")};Object.assign(globalThis,{logger:x});var me=Symbol.for("Jolibox.canIUseMap"),rt={};globalThis[me]||(globalThis[me]=rt);function Re(e,t,r){let n=e;for(let s of t)if(n&&typeof n=="object")n=n[s];else return r;return n===void 0?r:n}var G=Symbol.for("Jolibox.canIUseMap.native"),nt={};globalThis[G]||(globalThis[G]=nt);var q={get config(){return globalThis[G]}};var st=(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))(st||{}),it=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(it||{}),ot=(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))(ot||{});function at(){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 t=Window.prototype,r=Object.getOwnPropertyDescriptor(t,"localStorage");if(r&&r.get){let n=r.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}}at();var A=typeof window=="undefined",Ae=()=>!A&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),xt={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 z{constructor(t){this.element=t,this.next=z.Undefined,this.prev=z.Undefined}};K.Undefined=new K(void 0);var m=K,ct=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 t=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=t}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,t){let r=new m(e);if(this._first===m.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!==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 t=e.prev;t.next=e.next,e.next.prev=t}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}},ut=0,w=class{constructor(e){this.value=e,this.id=ut++}},O=class{constructor(e){this.options=e,this._size=0}dispose(e){var t,r;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)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var n,s,i,a,o,u;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let c=new w(t);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 f=this._listeners.indexOf(c);f>=0&&(this._listeners.splice(f,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,t){var r;if(!e)return;let n=((r=this.options)==null?void 0:r.onListenerError)||Error.constructor;if(!n){e.value(t);return}try{e.value(t)}catch(s){n(s)}}fire(e){this._listeners&&(this._listeners instanceof w?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,r=!0){var n;let s=(n=this.listeners.get(e))!=null?n:new O,i=u=>t(...u.args),a=s.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,s);let o=this.cachedEventQueue.get(e);if(o&&r)for(let u of o)t(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new ct,this.cachedEventQueue.set(e,n)),n.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...n)=>{t(...n),this.off(e,r)};this.on(e,r,!1)}},W={};We(W,{None:()=>lt,filter:()=>gt,once:()=>xe,toPromise:()=>dt});var lt=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function dt(e){return new Promise(t=>xe(e)(t))}function xe(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function gt(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(i.fire,i)}},i=new O(s);return i.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var H=Symbol.for("Jolibox.hostEmitter"),mt=()=>{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]},Tt=mt();function pt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)ht(e[n],t[n])}function ht(e,t){if(Q(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(be(t)){try{if(e instanceof t)return}catch(r){}if(!Ze(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 Y=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new O,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 pt(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}};Y=fe([_e],Y);var pe=class{constructor(){this._onWillExecuteCommand=new O,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new O,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new Y,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Qe(3e4)),this._starActivation}executeCommand(e,...t){return Ye(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),W.toPromise(W.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}}};pe=fe([_e],pe);var kt=Symbol.for("Jolibox.commands");b("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});b("requestProductDetailsAsync",{version:102e4});b("invokeSubscriptionPanelSync",{version:107e4,properties:{type:{game:107e4,drama:107e4}}});b("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});b("getABTest",{version:1050100,platforms:{android:1050100,ios:!1}});b("userTrackAsync",{version:1e6});b("openMiniapp",{version:1050100});b("requestCoinDetailsSync",{version:1070100});b("requestCoinDetailsAsync",{version:1070100});b("sendServerEventAsync",{version:1070100});function b(e,t){if(q.config[e]){x.warn(`[can i use] ${e} already registered`);return}q.config[e]=v({},t)}var ft=(e,t)=>{function r(s){var d;let[i,...a]=s.split(":");if(!i)return!1;let o=q.config[i];if(!o)return!1;let u=(d=t==null?void 0:t())!=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:r}};function P(e,t){return`[${e}]:${t}`}var Te=()=>Ae();var N="custom_event_";var ke=[],Ie=[],Ce=["env","createRequestTask","login"],J="__batch_event__",we="__native_batch_event__";var vt=e=>e==="pv"?e:"default",E=class{constructor(t){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:r,interval:n=30,eventName:s,tagNameOrder:i,metricName:a,type:o}=t;this.reporter=r,this.interval=n,this.eventName=s,this.tagNameOrder=i,this.metricName=a,this.type=vt(o)}report(t){this.type==="pv"?this.addPVPoint(t):this.addPoint(t),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(t){if(Object.keys(this.cache).length){if(t){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(t){let r=(n,s,i,a)=>{let o=s.shift();if(o){let u=a[o];n[u]||(n[u]={}),r(n[u],s,i,a)}else n[i]||(n[i]=[]),n[i].push(a[i])};r(this.cache,[...this.tagNameOrder],this.metricName,t)}addPVPoint(t){let r=(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;r(s[l],[...i],a,d)})}else s[a]?s[a]++:s[a]=1},n={point:t,metricName:this.metricName,tagNameOrder:this.tagNameOrder};r(this.cache,[...this.tagNameOrder],this.metricName,t)}processPoints(t){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:t}}clearPoints(){this.cache={}}},Oe=!1,Z,ee,te;function Pe(e,t){Oe||(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)}}),te=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),t("onJoliboxEnterBackground",()=>{Z.flush(),ee.flush(),te.flush()}),Oe=!0);function r(s){var T,k;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,f=(k=(T=c.match(/\S:(\S+)\s?/))==null?void 0:T[1])!=null?k:"fail";Z.report({status:f,method:n(i,a),errNo:`${l}`,errMsg:c,isForeground:u,duration:Date.now()-o}),o&&g&&p&&(ee.report({status:f,method:i,isForeground:u,duration:Number((g-o).toFixed(3))}),te.report({status:f,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 r}var re=[],bt=!1,ne=Symbol.for("Jolibox.invokeResolverInstance"),yt=new Map;globalThis[ne]||(globalThis[ne]=yt);var _t={get resolveMap(){return globalThis[ne]}};function De(e,t){let r=0,n=!0,s=_t.resolveMap,i=Pe(e,t);t("onJoliboxEnterBackground",()=>{n=!1}),t("onJoliboxEnterForeground",()=>{n=!0,re.forEach(g=>R(this,[g],function*({method:c,args:l,resolve:d}){let p=yield o(c,l);d(p)})),re.length=0});let a=(c,l)=>{let d=s.get(Number(c));if(!d)return;let g=I(l);d(g),s.delete(Number(c))},o=(c,l)=>{var ie,oe;let d=Date.now(),g=`${n}`;r+=1;let p=new ve;if(s.set(r,p.resolve),!n&&Ie.includes(c))return new Promise(_=>{re.push({method:c,args:l,resolve:_})});let T=le(v({},{method:c,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),k=!bt&&ke.includes(c),$=ge(l,k),V=k?$:JSON.stringify($),h;if(c.endsWith("Sync")||Ce.includes(c)?h=(ie=e.call)==null?void 0:ie.call(e,c,$,r):typeof V=="string"?h=e.invoke(c,V,r):h=(oe=e.call)==null?void 0:oe.call(e,c,V,r),h){try{typeof h=="string"&&(h=JSON.parse(h)),h=I(h)}catch(_){x.error(_)}return s.delete(r),h.errorCode&&(h.errorCode=P(c,h.errorCode)),i(v(v({},T),h)),h}return c.endsWith("Sync")&&s.delete(r),p.promise.then(_=>(_.errorCode&&(_.errorCode=P(c,_.errorCode)),i(v(v({},T),_)),_))};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,t){if(!S(t)){x.warn(`[Jolibox SDK]${e} no response value`);return}let o=t,{errMsg:r,errNo:n,errorType:s,errorCode:i}=o,a=de(o,["errMsg","errNo","errorType","errorCode"]);if(r&&r!==`${e}:ok`)throw new Ne(r,n,s,i);return a}var F=Symbol.for("Jolibox.subscribeInstance");function Ue(e){if(globalThis[F])return globalThis[F];let t=new B,r=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 t.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[F]={onNative:t.on.bind(t),offNative:t.off.bind(t),subscribe:r.on.bind(r),unsubscribe:r.off.bind(r),subscribeHandler(s,i,a){let o=I(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{r.emit(d.slice(N.length),g,a)}catch(p){}});return}if(s.startsWith(N)){r.emit(s.slice(N.length),u,a);return}t.emit(s,u,a)}},globalThis[F]}function Le(e){let t=new Map,r=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(()=>{t.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(J,g,f)}catch(f){}}),n=void 0,t.clear()}));let d=t.get(c);d||(d=[],t.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(()=>{r.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,f)}catch(f){}}),s=void 0,r.clear()}));let d=r.get(c);d||(d=[],r.set(c,d)),d.push([o,u])}}}function se(e){let{subscribeHandler:t,onNative:r,offNative:n,subscribe:s,unsubscribe:i}=Ue(e),{invokeNative:a,invokeHandler:o,applyNative:u}=De(e,r),{publish:c,emitNative:l}=Le(e);return{invokeHandler:o,subscribeHandler:t,applyNative:u,invokeNative:a,onNative:r,offNative:n,emitNative:l,publish:c,subscribe:s,unsubscribe:i}}function j(e,t){return{params:e,__extra:{startTime:Date.now(),type:t}}}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 t=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!t)e.onError(new Se("native env failed"));else{let{data:r}=JSON.parse(t);return r!=null?r:void 0}};if(typeof window!="undefined"&&window.webkit){let e=window.webkit.messageHandlers,t=(s="")=>{y.trigger(),e.onDocumentReady.postMessage({path:s})},r=s=>R(void 0,null,function*(){let i=yield y.exit();e.doExit.postMessage({uuid:s,shouldInterrupt:i})});M={onDocumentReady:t,doExit:r,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:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}if(typeof window!="undefined"&&window.JoliAndroidSDKBridge){let s,e=window.JoliAndroidSDKBridge,t=(i="")=>{y.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},r=i=>R(void 0,null,function*(){let a=yield y.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:a}))});M={onDocumentReady:t,invoke(i,a,o){e.invoke(JSON.stringify({event:i,paramsString:a,callbackId:o}))},doExit:r,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:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}var Je=M;if(!Je&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var St=v({},Je),Fe=se(St),{invokeHandler:Be}=Fe,{applyNative:Vr,invokeNative:Hr,onNative:Nt,offNative:Gr,subscribeHandler:Et,publish:Kr,emitNative:zr,subscribe:Wr,unsubscribe:Yr}=Fe,Qr=(e,t)=>{Nt(e,(...r)=>{var n;(n=r[0])!=null&&n.errorCode&&(r[0].errorCode=P(e,r[0].errorCode)),t(...r)})};globalThis.joliboxJSBridge={callHandler:Be,invokeHandler:Be,subscribeHandler:Et};export{y as RuntimeLoader,Vr as applyNative,zr as emitNative,Hr as invokeNative,Gr as offNative,Nt as onNative,Qr as onNativeWithError,Kr as publish,ft as registerCanIUseContext,Wr as subscribe,Et as subscribeHandler,Yr as unsubscribe};
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};
@@ -12,6 +12,14 @@ declare global {
12
12
  | 'HistoryUserScore'
13
13
  | 'UseGameItem' // TODO: deprecate
14
14
  | 'GameTaskEvent';
15
+ interface INativeProviderConfig {
16
+ provider: 'ADMOB' | 'APPLOVIN';
17
+ params: {
18
+ placementId: string;
19
+ adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL';
20
+ extra?: Record<string, any>;
21
+ };
22
+ }
15
23
  interface NativeMethodMap {
16
24
  prefetchImages: (params: {
17
25
  /** 需要预下载的图片 url */
@@ -537,6 +545,26 @@ declare global {
537
545
  errMsg: string;
538
546
  errNo?: number;
539
547
  }>;
548
+
549
+ /** native ads */
550
+ loadAdsAsync: (params: { params: { providers: INativeProviderConfig[] } }) => Promise<{
551
+ errMsg: string;
552
+ errNo?: number;
553
+ }>;
554
+
555
+ showAdAsync: (params: { params: { providers: INativeProviderConfig[] } }) => Promise<{
556
+ errMsg: string;
557
+ errNo?: number;
558
+ data: {
559
+ UUID: string;
560
+ };
561
+ }>;
562
+
563
+ isAdsReadySync: (params: { params: { providers: INativeProviderConfig[] } }) => {
564
+ errMsg: string;
565
+ errNo?: number;
566
+ data: boolean;
567
+ };
540
568
  }
541
569
 
542
570
  interface NativeEventMap {
@@ -671,6 +699,17 @@ declare global {
671
699
  };
672
700
  }
673
701
  ];
702
+
703
+ onAdsStateChange: [
704
+ {
705
+ UUID: string;
706
+ event: 'onAdShow' | 'onAdError' | 'onAdClosed' | 'onAdClicked' | 'onAdRewarded' | 'onAdDismissed';
707
+ data: {
708
+ placementId: string;
709
+ provider: string;
710
+ };
711
+ }
712
+ ];
674
713
  }
675
714
  }
676
715
  }
@@ -5,6 +5,7 @@ import { NativeCanIUseInfo } from '@jolibox/common';
5
5
  import './registered/payment';
6
6
  import './registered/login';
7
7
  import './registered/call-host-method';
8
+ import './registered/ads';
8
9
  type DynamicMethodName = 'getABTest' | 'userTrackAsync' | 'openMiniapp';
9
10
  export declare function registerCanIUseNative(name: keyof jsb.service.NativeMethodMap | DynamicMethodName, config: NativeCanIUseInfo): void;
10
11
  export declare const registerCanIUseContext: (nativeSDKVersionCodeGetter: () => number | undefined, platformGetter: () => "h5" | "android" | "ios") => {
@@ -0,0 +1 @@
1
+ export {};
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.4",
4
+ "version": "1.3.5-beta.2",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -11,8 +11,8 @@
11
11
  ],
12
12
  "types": "./dist/index.d.ts",
13
13
  "dependencies": {
14
- "@jolibox/common": "1.3.4",
15
- "@jolibox/types": "1.3.4"
14
+ "@jolibox/common": "1.3.5-beta.2",
15
+ "@jolibox/types": "1.3.5-beta.2"
16
16
  },
17
17
  "devDependencies": {
18
18
  "typescript": "5.7.3",
@@ -12,6 +12,14 @@ declare global {
12
12
  | 'HistoryUserScore'
13
13
  | 'UseGameItem' // TODO: deprecate
14
14
  | 'GameTaskEvent';
15
+ interface INativeProviderConfig {
16
+ provider: 'ADMOB' | 'APPLOVIN';
17
+ params: {
18
+ placementId: string;
19
+ adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL';
20
+ extra?: Record<string, any>;
21
+ };
22
+ }
15
23
  interface NativeMethodMap {
16
24
  prefetchImages: (params: {
17
25
  /** 需要预下载的图片 url */
@@ -537,6 +545,26 @@ declare global {
537
545
  errMsg: string;
538
546
  errNo?: number;
539
547
  }>;
548
+
549
+ /** native ads */
550
+ loadAdsAsync: (params: { params: { providers: INativeProviderConfig[] } }) => Promise<{
551
+ errMsg: string;
552
+ errNo?: number;
553
+ }>;
554
+
555
+ showAdAsync: (params: { params: { providers: INativeProviderConfig[] } }) => Promise<{
556
+ errMsg: string;
557
+ errNo?: number;
558
+ data: {
559
+ UUID: string;
560
+ };
561
+ }>;
562
+
563
+ isAdsReadySync: (params: { params: { providers: INativeProviderConfig[] } }) => {
564
+ errMsg: string;
565
+ errNo?: number;
566
+ data: boolean;
567
+ };
540
568
  }
541
569
 
542
570
  interface NativeEventMap {
@@ -671,6 +699,17 @@ declare global {
671
699
  };
672
700
  }
673
701
  ];
702
+
703
+ onAdsStateChange: [
704
+ {
705
+ UUID: string;
706
+ event: 'onAdShow' | 'onAdError' | 'onAdClosed' | 'onAdClicked' | 'onAdRewarded' | 'onAdDismissed';
707
+ data: {
708
+ placementId: string;
709
+ provider: string;
710
+ };
711
+ }
712
+ ];
674
713
  }
675
714
  }
676
715
  }