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