@jolibox/native-bridge 1.1.44 → 1.1.46

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,He=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var oe=(e,r,t)=>r in e?je(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,v=(e,r)=>{for(var t in r||(r={}))ae.call(r,t)&&oe(e,t,r[t]);if(C)for(var t of C(r))ce.call(r,t)&&oe(e,t,r[t]);return e},ue=(e,r)=>He(e,Ve(r));var le=(e,r)=>{var t={};for(var n in e)ae.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&C)for(var n of C(e))r.indexOf(n)<0&&ce.call(e,n)&&(t[n]=e[n]);return t};var S=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(u){i(u)}},a=c=>{try{o(t.throw(c))}catch(u){i(u)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,a);o((t=t.apply(e,r)).next())});function Ge(e){return!!(e!=null&&e.__nativeBuffers__)}var Ke=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function O(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Ge(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 i;n.value?i=n.value:n.base64&&(i=Ke(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var $e=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function de(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let a=r?{value:s,key:i}:{base64:$e(s),key:i};n.push(a),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var pe=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=(e,r)=>{for(var t in r)pe(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{for(var i=n>1?void 0:n?ze(r,t):r,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=(n?a(r,t,i):a(i))||i);return n&&i&&pe(r,t,i),i},qe=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(u){i(u)}},a=c=>{try{o(t.throw(c))}catch(u){i(u)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,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 i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,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 Ye(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var he=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 Y(e){return typeof e=="string"}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Q(e){return typeof e=="number"&&!isNaN(e)}function Qe(e){return typeof e=="undefined"}function Xe(e){return Qe(e)||e===null}function ve(e){return typeof e=="function"}function be(e){return _(e)&&ve(e.then)}function ye(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.prototype,n}var Ze=(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))(Ze||{}),er=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}},D=class extends er{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var _e=class extends D{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends D{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 D{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var U=class extends D{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 R={log:k("log"),warn:k("warn"),info:k("info"),error:k("error"),debug:k("debug")};Object.assign(globalThis,{logger:R});var ge=Symbol.for("Jolibox.canIUseMap"),rr={};globalThis[ge]||(globalThis[ge]=rr);function Se(e,r,t){let n=e;for(let i of r)if(n&&typeof n=="object")n=n[i];else return t;return n===void 0?t:n}var K=Symbol.for("Jolibox.canIUseMap.native"),tr={};globalThis[K]||(globalThis[K]=tr);var L={get config(){return globalThis[K]}};var nr=(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))(nr||{}),ir=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(ir||{}),sr=(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))(sr||{});function or(){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}}or();var Re=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),xr={isiOS: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:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var $=class z{constructor(r){this.element=r,this.next=z.Undefined,this.prev=z.Undefined}};$.Undefined=new $(void 0);var m=$,ar=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 i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.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}},cr=0,I=class{constructor(e){this.value=e,this.id=cr++}},w=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 I&&(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,i,s,a,o,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let u=new I(r);return this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,u]:this._listeners.push(u):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=u,(a=(s=this.options)==null?void 0:s.onDidFirstListener)==null||a.call(s,this)),(c=(o=this.options)==null?void 0:o.onDidAddListener)==null||c.call(o,this),this._size++,()=>{var l,d,g,p;if(!this._disposed){if(this._listeners instanceof I)this._listeners.id===u.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 h=this._listeners.indexOf(u);h>=0&&(this._listeners.splice(h,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(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let i=(n=this.listeners.get(e))!=null?n:new w,s=c=>r(...c.args),a=i.event(s);this.listerHandlerMap.set(r,{handler:s,dispose:a}),this.listeners.set(e,i);let o=this.cachedEventQueue.get(e);if(o&&t)for(let c of o)r(...c.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 ar,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)}},W={};We(W,{None:()=>ur,filter:()=>dr,once:()=>xe,toPromise:()=>lr});var ur=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function lr(e){return new Promise(r=>xe(e)(r))}function xe(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function dr(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new w(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var G=Symbol.for("Jolibox.hostEmitter"),gr=()=>{let e=new J;return globalThis[G]||(globalThis[G]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[G]},Tr=gr();function mr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)pr(e[n],r[n])}function pr(e,r){if(Y(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(ve(r)){try{if(e instanceof r)return}catch(t){}if(!Xe(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 q=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new w,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 i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return mr(i,t),n(...i)}}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}};q=fe([ye],q);var me=class{constructor(){this._onWillExecuteCommand=new w,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new w,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new q,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ye(3e4)),this._starActivation}executeCommand(e,...r){return qe(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),W.toPromise(W.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}}};me=fe([ye],me);var Or=Symbol.for("Jolibox.commands");A("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});A("requestProductDetailsAsync",{version:102e4});A("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});function A(e,r){if(L.config[e]){R.warn(`[can i use] ${e} already registered`);return}L.config[e]=v({},r)}var fr=e=>{function r(n){let[i,...s]=n.split(":");if(!i)return!1;let a=L.config[i];if(!a)return!1;let o=a.version;if(typeof o!="number")return!1;let c=e();return typeof c!="number"||c<o?!1:s.length===0?!0:t(a,s,c)||t(a.properties,s,c)}function t(n,i,s){if(!n)return!1;let a=Se(n,i);if(!a)return!1;if(_(a)){let o=a.version;return Q(o)?typeof s=="number"&&s>=o:!0}return Q(a)?typeof s=="number"&&s>=a:a===!0}return{canIUseNative:r}};function P(e,r){return`[${e}]:${r}`}var Te=()=>Re();var N="custom_event_";var Oe=[],ke=[],Ie=["env","createRequestTask","login"],B="__batch_event__",we="__native_batch_event__";var hr=e=>e==="pv"?e:"default",E=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=a,this.type=hr(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,i,s,a)=>{let o=i.shift();if(o){let c=a[o];n[c]||(n[c]={}),t(n[c],i,s,a)}else n[s]||(n[s]=[]),n[s].push(a[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,a,o)=>{let c=s.shift();if(!c&&_(o))throw new U(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(c){let u=[];if(_(o))u.push(...Object.keys(o));else if(Y(o)){if(s.length>0)throw new U(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);u.push(o)}else throw new U(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);u.forEach(l=>{i[l]||(i[l]={});let d=_(o)?o[l]:o;t(i[l],[...s],a,d)})}else i[a]?i[a]++:i[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={}}},Ae=!1,X,Z,ee;function Pe(e,r){Ae||(X=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Z=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),ee=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{X.flush(),Z.flush(),ee.flush()}),Ae=!0);function t(i){var x,T;let{method:s,args:a,startTime:o,isForeground:c,errMsg:u=`${s}:fail no errMsg`,errNo:l=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:g,invokeCallback:p}=d,h=(T=(x=u.match(/\S:(\S+)\s?/))==null?void 0:x[1])!=null?T:"fail";X.report({status:h,method:n(s,a),errNo:`${l}`,errMsg:u,isForeground:c,duration:Date.now()-o}),o&&g&&p&&(Z.report({status:h,method:s,isForeground:c,duration:Number((g-o).toFixed(3))}),ee.report({status:h,method:s,isForeground:c,duration:Number((Date.now()-p).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var re=[],vr=!1,te=Symbol.for("Jolibox.invokeResolverInstance"),br=new Map;globalThis[te]||(globalThis[te]=br);var yr={get resolveMap(){return globalThis[te]}};function Ce(e,r){let t=0,n=!0,i=yr.resolveMap,s=Pe(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,re.forEach(g=>S(this,[g],function*({method:u,args:l,resolve:d}){let p=yield o(u,l);d(p)})),re.length=0});let a=(u,l)=>{let d=i.get(Number(u));if(!d)return;let g=O(l);d(g),i.delete(Number(u))},o=(u,l)=>{var ie,se;let d=Date.now(),g=`${n}`;t+=1;let p=new he;if(i.set(t,p.resolve),!n&&ke.includes(u))return new Promise(y=>{re.push({method:u,args:l,resolve:y})});let x=ue(v({},{method:u,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),T=!vr&&Oe.includes(u),H=de(l,T),V=T?H:JSON.stringify(H),f;if(u.endsWith("Sync")||Ie.includes(u)?f=(ie=e.call)==null?void 0:ie.call(e,u,H,t):typeof V=="string"?f=e.invoke(u,V,t):f=(se=e.call)==null?void 0:se.call(e,u,V,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=O(f)}catch(y){R.error(y)}return i.delete(t),f.errorCode&&(f.errorCode=P(u,f.errorCode)),s(v(v({},x),f)),f}return u.endsWith("Sync")&&i.delete(t),p.promise.then(y=>(y.errorCode&&(y.errorCode=P(u,y.errorCode)),s(v(v({},x),y)),y))};return{invokeNative:o,applyNative:(u,l)=>{let d=o(u,l);return be(d)?d.then(g=>Me(u,g)):Me(u,d)},invokeHandler:a}}function Me(e,r){if(!_(r)){R.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=o,a=le(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new Ne(t,n,i,s);return a}var F=Symbol.for("Jolibox.subscribeInstance");function De(e){if(globalThis[F])return globalThis[F];let r=new J,t=new J,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-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(i,s,a){let o=O(s),c;if(o.__extra){c=o.params;let{type:u,startTime:l}=o.__extra;n.report({type:u,event:i,duration:Date.now()-l})}else c=o;if(i===B){c.forEach(l=>{let[d,g]=l;try{t.emit(d.slice(N.length),g,a)}catch(p){}});return}if(i.startsWith(N)){t.emit(i.slice(N.length),c,a);return}r.emit(i,c,a)}},globalThis[F]}function Ue(e){let r=new Map,t=new Map,n,i;return{publish:(o,c,u,l)=>{if(l){let g=u!==void 0?u==="*"?"*":[u]:void 0;e.publish(`${N}${o}`,c,g);return}n||(n=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let h=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(B,g,h)}catch(h){}}),n=void 0,r.clear()}));let d=r.get(u);d||(d=[],r.set(u,d)),d.push([`${N}${o}`,c])},emitNative:(o,c,u,l)=>{if(l){let g=u!==void 0?u==="*"?"*":[u]:void 0;e.publish(o,c,g),console.log("emitNative",o,c,g);return}i||(i=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let h=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,h)}catch(h){}}),i=void 0,t.clear()}));let d=t.get(u);d||(d=[],t.set(u,d)),d.push([o,c])}}}function ne(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=De(e),{invokeNative:a,invokeHandler:o,applyNative:c}=Ce(e,t),{publish:u,emitNative:l}=Ue(e);return{invokeHandler:o,subscribeHandler:r,applyNative:c,invokeNative:a,onNative:t,offNative:n,emitNative:l,publish:u,subscribe:i,unsubscribe:s}}function j(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,b={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){b.trigger=e},onDoExit(e){b.exit=e},onDoBackPress(e){b.backPress=e}},Le=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new _e("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{b.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>S(void 0,null,function*(){let s=yield b.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});M={onDocumentReady:r,doExit:t,invoke(i,s,a){e.invoke.postMessage({event:i,paramsString:s,callbackId:a})},publish(i,s,a){let o=j(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(o),webviewIds:a}))},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:Le,doExit:t};globalThis.joliboxJSCore=v({},n)}if(window.JoliAndroidSDKBridge){let i,e=window.JoliAndroidSDKBridge,r=(s="")=>{b.trigger(),e.onDocumentReady(JSON.stringify({path:s}))},t=s=>S(void 0,null,function*(){let a=yield b.exit();e.doExit(JSON.stringify({uuid:s,shouldInterrupt:a}))});M={onDocumentReady:r,invoke(s,a,o){e.invoke(JSON.stringify({event:s,paramsString:a,callbackId:o}))},doExit:t,publish(s,a,o){let c=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:s,paramsString:JSON.stringify(c),webviewIds:o}))},call(s,a,o){let c=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(a),callbackId:o}));if(c)return JSON.parse(c)},doBackPress(s){return S(this,null,function*(){let a=yield b.backPress();e.doBackPress(JSON.stringify({uuid:s,shouldInterrupt:a}))})}};let n={onDocumentReady:r,env:Le,doExit:t};globalThis.joliboxJSCore=v({},n)}var Be=M;if(!Be&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var _r=v({},Be),Fe=ne(_r),{invokeHandler:Je}=Fe,{applyNative:jt,invokeNative:Ht,onNative:Nr,offNative:Vt,subscribeHandler:Er,publish:Gt,emitNative:Kt,subscribe:$t,unsubscribe:zt}=Fe,Wt=(e,r)=>{Nr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=P(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Je,invokeHandler:Je,subscribeHandler:Er};export{b as RuntimeLoader,jt as applyNative,Kt as emitNative,Ht as invokeNative,Vt as offNative,Nr as onNative,Wt as onNativeWithError,Gt as publish,fr as registerCanIUseContext,$t as subscribe,Er as subscribeHandler,zt as unsubscribe};
1
+ var je=Object.defineProperty,He=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var oe=(e,r,t)=>r in e?je(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,v=(e,r)=>{for(var t in r||(r={}))ae.call(r,t)&&oe(e,t,r[t]);if(C)for(var t of C(r))ce.call(r,t)&&oe(e,t,r[t]);return e},le=(e,r)=>He(e,Ve(r));var ue=(e,r)=>{var t={};for(var n in e)ae.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&C)for(var n of C(e))r.indexOf(n)<0&&ce.call(e,n)&&(t[n]=e[n]);return t};var S=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(l){i(l)}},a=c=>{try{o(t.throw(c))}catch(l){i(l)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,a);o((t=t.apply(e,r)).next())});function Ge(e){return!!(e!=null&&e.__nativeBuffers__)}var Ke=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function O(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Ge(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 i;n.value?i=n.value:n.base64&&(i=Ke(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var $e=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function de(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let a=r?{value:s,key:i}:{base64:$e(s),key:i};n.push(a),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var pe=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=(e,r)=>{for(var t in r)pe(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{for(var i=n>1?void 0:n?ze(r,t):r,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=(n?a(r,t,i):a(i))||i);return n&&i&&pe(r,t,i),i},qe=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(l){i(l)}},a=c=>{try{o(t.throw(c))}catch(l){i(l)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,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 i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,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 Ye(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var he=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 Y(e){return typeof e=="string"}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Q(e){return typeof e=="number"&&!isNaN(e)}function Qe(e){return typeof e=="undefined"}function Xe(e){return Qe(e)||e===null}function ve(e){return typeof e=="function"}function be(e){return _(e)&&ve(e.then)}function ye(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.prototype,n}var Ze=(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))(Ze||{}),er=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}},D=class extends er{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var _e=class extends D{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends D{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 D{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var U=class extends D{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 R={log:k("log"),warn:k("warn"),info:k("info"),error:k("error"),debug:k("debug")};Object.assign(globalThis,{logger:R});var ge=Symbol.for("Jolibox.canIUseMap"),rr={};globalThis[ge]||(globalThis[ge]=rr);function Se(e,r,t){let n=e;for(let i of r)if(n&&typeof n=="object")n=n[i];else return t;return n===void 0?t:n}var K=Symbol.for("Jolibox.canIUseMap.native"),tr={};globalThis[K]||(globalThis[K]=tr);var L={get config(){return globalThis[K]}};var nr=(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))(nr||{}),ir=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(ir||{}),sr=(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))(sr||{});function or(){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}}or();var Re=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),xr={isiOS: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:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var $=class z{constructor(r){this.element=r,this.next=z.Undefined,this.prev=z.Undefined}};$.Undefined=new $(void 0);var m=$,ar=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 i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.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}},cr=0,I=class{constructor(e){this.value=e,this.id=cr++}},w=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 I&&(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,i,s,a,o,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let l=new I(r);return this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,l]:this._listeners.push(l):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=l,(a=(s=this.options)==null?void 0:s.onDidFirstListener)==null||a.call(s,this)),(c=(o=this.options)==null?void 0:o.onDidAddListener)==null||c.call(o,this),this._size++,()=>{var u,d,g,p;if(!this._disposed){if(this._listeners instanceof I)this._listeners.id===l.id&&(this._listeners=void 0,this._size=0,(d=(u=this.options)==null?void 0:u.onDidRemoveLastListener)==null||d.call(u));else if(this._listeners){let h=this._listeners.indexOf(l);h>=0&&(this._listeners.splice(h,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(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let i=(n=this.listeners.get(e))!=null?n:new w,s=c=>r(...c.args),a=i.event(s);this.listerHandlerMap.set(r,{handler:s,dispose:a}),this.listeners.set(e,i);let o=this.cachedEventQueue.get(e);if(o&&t)for(let c of o)r(...c.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 ar,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)}},W={};We(W,{None:()=>lr,filter:()=>dr,once:()=>xe,toPromise:()=>ur});var lr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function ur(e){return new Promise(r=>xe(e)(r))}function xe(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function dr(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new w(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var G=Symbol.for("Jolibox.hostEmitter"),gr=()=>{let e=new J;return globalThis[G]||(globalThis[G]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[G]},Tr=gr();function mr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)pr(e[n],r[n])}function pr(e,r){if(Y(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(ve(r)){try{if(e instanceof r)return}catch(t){}if(!Xe(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 q=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new w,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 i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return mr(i,t),n(...i)}}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}};q=fe([ye],q);var me=class{constructor(){this._onWillExecuteCommand=new w,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new w,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new q,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ye(3e4)),this._starActivation}executeCommand(e,...r){return qe(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),W.toPromise(W.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}}};me=fe([ye],me);var Or=Symbol.for("Jolibox.commands");A("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});A("requestProductDetailsAsync",{version:102e4});A("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});function A(e,r){if(L.config[e]){R.warn(`[can i use] ${e} already registered`);return}L.config[e]=v({},r)}var fr=e=>{function r(n){let[i,...s]=n.split(":");if(!i)return!1;let a=L.config[i];if(!a)return!1;let o=a.version;if(typeof o!="number")return!1;let c=e();return typeof c!="number"||c<o?!1:s.length===0?!0:t(a,s,c)||t(a.properties,s,c)}function t(n,i,s){if(!n)return!1;let a=Se(n,i);if(!a)return!1;if(_(a)){let o=a.version;return Q(o)?typeof s=="number"&&s>=o:!0}return Q(a)?typeof s=="number"&&s>=a:a===!0}return{canIUseNative:r}};function P(e,r){return`[${e}]:${r}`}var Te=()=>Re();var N="custom_event_";var Oe=[],ke=[],Ie=["env","createRequestTask","login"],B="__batch_event__",we="__native_batch_event__";var hr=e=>e==="pv"?e:"default",E=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=a,this.type=hr(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,i,s,a)=>{let o=i.shift();if(o){let c=a[o];n[c]||(n[c]={}),t(n[c],i,s,a)}else n[s]||(n[s]=[]),n[s].push(a[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,a,o)=>{let c=s.shift();if(!c&&_(o))throw new U(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(c){let l=[];if(_(o))l.push(...Object.keys(o));else if(Y(o)){if(s.length>0)throw new U(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);l.push(o)}else throw new U(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);l.forEach(u=>{i[u]||(i[u]={});let d=_(o)?o[u]:o;t(i[u],[...s],a,d)})}else i[a]?i[a]++:i[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={}}},Ae=!1,X,Z,ee;function Pe(e,r){Ae||(X=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Z=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),ee=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{X.flush(),Z.flush(),ee.flush()}),Ae=!0);function t(i){var x,T;let{method:s,args:a,startTime:o,isForeground:c,errMsg:l=`${s}:fail no errMsg`,errNo:u=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:g,invokeCallback:p}=d,h=(T=(x=l.match(/\S:(\S+)\s?/))==null?void 0:x[1])!=null?T:"fail";X.report({status:h,method:n(s,a),errNo:`${u}`,errMsg:l,isForeground:c,duration:Date.now()-o}),o&&g&&p&&(Z.report({status:h,method:s,isForeground:c,duration:Number((g-o).toFixed(3))}),ee.report({status:h,method:s,isForeground:c,duration:Number((Date.now()-p).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var re=[],vr=!1,te=Symbol.for("Jolibox.invokeResolverInstance"),br=new Map;globalThis[te]||(globalThis[te]=br);var yr={get resolveMap(){return globalThis[te]}};function Ce(e,r){let t=0,n=!0,i=yr.resolveMap,s=Pe(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,re.forEach(g=>S(this,[g],function*({method:l,args:u,resolve:d}){let p=yield o(l,u);d(p)})),re.length=0});let a=(l,u)=>{let d=i.get(Number(l));if(!d)return;let g=O(u);d(g),i.delete(Number(l))},o=(l,u)=>{var ie,se;let d=Date.now(),g=`${n}`;t+=1;let p=new he;if(i.set(t,p.resolve),!n&&ke.includes(l))return new Promise(y=>{re.push({method:l,args:u,resolve:y})});let x=le(v({},{method:l,startTime:d,args:u,isForeground:g}),{invokeType:"js-bridge"}),T=!vr&&Oe.includes(l),H=de(u,T),V=T?H:JSON.stringify(H),f;if(l.endsWith("Sync")||Ie.includes(l)?f=(ie=e.call)==null?void 0:ie.call(e,l,H,t):typeof V=="string"?f=e.invoke(l,V,t):f=(se=e.call)==null?void 0:se.call(e,l,V,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=O(f)}catch(y){R.error(y)}return i.delete(t),f.errorCode&&(f.errorCode=P(l,f.errorCode)),s(v(v({},x),f)),f}return l.endsWith("Sync")&&i.delete(t),p.promise.then(y=>(y.errorCode&&(y.errorCode=P(l,y.errorCode)),s(v(v({},x),y)),y))};return{invokeNative:o,applyNative:(l,u)=>{let d=o(l,u);return be(d)?d.then(g=>Me(l,g)):Me(l,d)},invokeHandler:a}}function Me(e,r){if(!_(r)){R.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=o,a=ue(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new Ne(t,n,i,s);return a}var F=Symbol.for("Jolibox.subscribeInstance");function De(e){if(globalThis[F])return globalThis[F];let r=new J,t=new J,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-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(i,s,a){let o=O(s),c;if(o.__extra){c=o.params;let{type:l,startTime:u}=o.__extra;n.report({type:l,event:i,duration:Date.now()-u})}else c=o;if(i===B){c.forEach(u=>{let[d,g]=u;try{t.emit(d.slice(N.length),g,a)}catch(p){}});return}if(i.startsWith(N)){t.emit(i.slice(N.length),c,a);return}r.emit(i,c,a)}},globalThis[F]}function Ue(e){let r=new Map,t=new Map,n,i;return{publish:(o,c,l,u)=>{if(u){let g=l!==void 0?l==="*"?"*":[l]:void 0;e.publish(`${N}${o}`,c,g);return}n||(n=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let h=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(B,g,h)}catch(h){}}),n=void 0,r.clear()}));let d=r.get(l);d||(d=[],r.set(l,d)),d.push([`${N}${o}`,c])},emitNative:(o,c,l,u)=>{if(u){let g=l!==void 0?l==="*"?"*":[l]:void 0;e.publish(o,c,g),console.log("emitNative",o,c,g);return}i||(i=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let h=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,h)}catch(h){}}),i=void 0,t.clear()}));let d=t.get(l);d||(d=[],t.set(l,d)),d.push([o,c])}}}function ne(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=De(e),{invokeNative:a,invokeHandler:o,applyNative:c}=Ce(e,t),{publish:l,emitNative:u}=Ue(e);return{invokeHandler:o,subscribeHandler:r,applyNative:c,invokeNative:a,onNative:t,offNative:n,emitNative:u,publish:l,subscribe:i,unsubscribe:s}}function j(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,b={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){b.trigger=e},onDoExit(e){b.exit=e},onDoBackPress(e){b.backPress=e}},Le=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new _e("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{b.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>S(void 0,null,function*(){let s=yield b.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});M={onDocumentReady:r,doExit:t,invoke(i,s,a){e.invoke.postMessage({event:i,paramsString:s,callbackId:a})},publish(i,s,a){let o=j(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(o),webviewIds:a}))},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:Le,doExit:t};globalThis.joliboxJSCore=v({},n)}if(window.JoliAndroidSDKBridge){let i,e=window.JoliAndroidSDKBridge,r=(s="")=>{b.trigger(),e.onDocumentReady(JSON.stringify({path:s}))},t=s=>S(void 0,null,function*(){let a=yield b.exit();e.doExit(JSON.stringify({uuid:s,shouldInterrupt:a}))});M={onDocumentReady:r,invoke(s,a,o){e.invoke(JSON.stringify({event:s,paramsString:a,callbackId:o}))},doExit:t,publish(s,a,o){let c=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:s,paramsString:JSON.stringify(c),webviewIds:o}))},call(s,a,o){let c=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(a),callbackId:o}));if(c)return JSON.parse(c)},doBackPress(s){return S(this,null,function*(){let a=yield b.backPress();e.doBackPress(JSON.stringify({uuid:s,shouldInterrupt:a}))})}};let n={onDocumentReady:r,env:Le,doExit:t};globalThis.joliboxJSCore=v({},n)}var Be=M;if(!Be&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var _r=v({},Be),Fe=ne(_r),{invokeHandler:Je}=Fe,{applyNative:jt,invokeNative:Ht,onNative:Nr,offNative:Vt,subscribeHandler:Er,publish:Gt,emitNative:Kt,subscribe:$t,unsubscribe:zt}=Fe,Wt=(e,r)=>{Nr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=P(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Je,invokeHandler:Je,subscribeHandler:Er};export{b as RuntimeLoader,jt as applyNative,Kt as emitNative,Ht as invokeNative,Vt as offNative,Nr as onNative,Wt as onNativeWithError,Gt as publish,fr as registerCanIUseContext,$t as subscribe,Er as subscribeHandler,zt as unsubscribe};
@@ -398,6 +398,7 @@ declare global {
398
398
  onBeforeExit: [
399
399
  {
400
400
  uuid: string;
401
+ disableExitRecommendDialog?: boolean;
401
402
  }
402
403
  ];
403
404
  onJoliboxServiceReady: [
@@ -463,6 +464,7 @@ declare global {
463
464
  onBeforeBackPress: [
464
465
  {
465
466
  uuid: string;
467
+ disableExitRecommendDialog?: boolean;
466
468
  }
467
469
  ];
468
470
 
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.1.44",
4
+ "version": "1.1.46",
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.1.44",
15
- "@jolibox/types": "1.1.44"
14
+ "@jolibox/common": "1.1.46",
15
+ "@jolibox/types": "1.1.46"
16
16
  },
17
17
  "devDependencies": {
18
18
  "typescript": "5.7.3",
@@ -398,6 +398,7 @@ declare global {
398
398
  onBeforeExit: [
399
399
  {
400
400
  uuid: string;
401
+ disableExitRecommendDialog?: boolean;
401
402
  }
402
403
  ];
403
404
  onJoliboxServiceReady: [
@@ -463,6 +464,7 @@ declare global {
463
464
  onBeforeBackPress: [
464
465
  {
465
466
  uuid: string;
467
+ disableExitRecommendDialog?: boolean;
466
468
  }
467
469
  ];
468
470