@lingxia/bridge 0.7.0 → 0.9.0

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.
@@ -1 +1 @@
1
- var __extends=this&&this.__extends||function(){var e=function(n,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},e(n,t)};return function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=n}e(n,t),n.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e},__assign.apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))(function(r,i){function a(e){try{s(o.next(e))}catch(e){i(e)}}function l(e){try{s(o.throw(e))}catch(e){i(e)}}function s(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(a,l)}s((o=o.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(e,n){var t,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=l(0),a.throw=l(1),a.return=l(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(s){return function(l){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(t=1,o&&(r=2&l[0]?o.return:l[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;switch(o=0,r&&(l=[2&l[0],r.value]),l[0]){case 0:case 1:r=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,o=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!r||l[1]>r[0]&&l[1]<r[3])){i.label=l[1];break}if(6===l[0]&&i.label<r[1]){i.label=r[1],r=l;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(l);break}r[2]&&i.ops.pop(),i.trys.pop();continue}l=n.call(e,i)}catch(e){l=[6,e],o=0}finally{t=r=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,s])}}},__spreadArray=this&&this.__spreadArray||function(e,n,t){if(t||2===arguments.length)for(var o,r=0,i=n.length;r<i;r++)!o&&r in n||(o||(o=Array.prototype.slice.call(n,0,r)),o[r]=n[r]);return e.concat(o||Array.prototype.slice.call(n))},__LX_RUNTIME_PLATFORM__="mobile",__LingXiaBridgeBundle=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var n="BRIDGE_TIMEOUT",t="BRIDGE_CANCELED",o="BRIDGE_HANDSHAKE_FAILED",r="BRIDGE_MALFORMED_MESSAGE",i="BRIDGE_METHOD_NOT_FOUND",a="BRIDGE_CAPABILITY_DENIED",l="BRIDGE_INTERNAL_ERROR",s="BRIDGE_OUTBOX_FULL",c="BRIDGE_STREAM_CLOSED",d=function(e){function n(n,t,o){var r=e.call(this,t)||this;return r.name="BridgeInvocationError",r.code=n,r.data=o,r}return __extends(n,e),n}(Error);function u(e){if(e instanceof d)return e;if(e&&"object"==typeof e){var n=e,t=l;("string"==typeof n.code&&""!==n.code.trim()||"number"==typeof n.code&&Number.isFinite(n.code))&&(t=n.code);var o="string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error";return new d(t,o,"data"in n?n.data:void 0)}var r=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new d(l,r)}function f(e){var n=u(e);return __assign({code:String(n.code||l),message:"string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error"},void 0===n.data?{}:{data:n.data})}function m(e){var n,t=e.os,o=e.send;if("undefined"!=typeof window&&"undefined"!=typeof document){var r="iOS"===t;if(r||"Android"===t){var i=Symbol.for("LingXia.NativeComponentCoverageMonitor");if(!(null===(n=window[i])||void 0===n?void 0:n.installed)){var a={installed:!0,coveredById:new Map,coveredCount:0,anyCovered:!1,scheduled:!1,hasAnyVideo:!1,scrollLocked:!1,scrollY:0,htmlOverflow:"",bodyOverflow:"",bodyPosition:"",bodyTop:"",bodyWidth:""};window[i]=a,new MutationObserver(u).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0});var l={handleEvent:function(){(a.hasAnyVideo||0!==a.coveredById.size)&&u()}},s={handleEvent:function(){return u()}};window.addEventListener("scroll",l,{capture:!0,passive:!0}),window.addEventListener("resize",s),u()}}}function c(e){var n,t,o=null===(n=e.getBoundingClientRect)||void 0===n?void 0:n.call(e);if(!o)return!1;if(o.width<2||o.height<2)return!1;var r=o.left+o.width/2,i=o.top+o.height/2;if(r<0||i<0||r>=window.innerWidth||i>=window.innerHeight)return!1;var a=null===(t=document.elementFromPoint)||void 0===t?void 0:t.call(document,r,i);return!!a&&(a!==document.documentElement&&a!==document.body&&!(a===e||e.contains(a)))}function d(){a.scheduled=!1;var e=document.querySelectorAll("lx-video[id]");if(a.hasAnyVideo=e.length>0,a.hasAnyVideo||0!==a.coveredById.size||a.anyCovered){for(var n=new Set,t=0,i=Array.from(e);t<i.length;t++){var l=i[t];if(p=l.id){n.add(p);var s=c(l),d=a.coveredById.get(p);d!==s&&(!0===d&&(a.coveredCount-=1),!0===s&&(a.coveredCount+=1),a.coveredById.set(p,s),o({id:p,action:"component.coverage",covered:s}))}}for(var u=[],f=0,m=a.coveredById.entries();f<m.length;f++){var v=m[f],p=v[0];s=v[1];n.has(p)||(u.push(p),!0===s&&(a.coveredCount-=1))}for(var h=0,g=u;h<g.length;h++){p=g[h];a.coveredById.delete(p),o({id:p,action:"component.coverage",covered:!1})}var y=a.coveredCount>0;y!==a.anyCovered&&(a.anyCovered=y,r&&(y?function(){if(r&&!a.scrollLocked){var e=document.documentElement,n=document.body;e&&n&&(a.scrollLocked=!0,a.scrollY=window.scrollY||e.scrollTop||0,a.htmlOverflow=e.style.overflow||"",a.bodyOverflow=n.style.overflow||"",a.bodyPosition=n.style.position||"",a.bodyTop=n.style.top||"",a.bodyWidth=n.style.width||"",e.style.overflow="hidden",n.style.overflow="hidden",n.style.position="fixed",n.style.top="".concat(-a.scrollY,"px"),n.style.width="100%")}}():function(){if(r&&a.scrollLocked){var e=document.documentElement,n=document.body;e&&n&&(a.scrollLocked=!1,e.style.overflow=a.htmlOverflow,n.style.overflow=a.bodyOverflow,n.style.position=a.bodyPosition,n.style.top=a.bodyTop,n.style.width=a.bodyWidth,window.scrollTo(0,a.scrollY))}}()))}}function u(){a.scheduled||(a.scheduled=!0,requestAnimationFrame(d))}}var v="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{};function p(){return v.os||"unknown"}function h(){return"iOS"===v.os}function g(){return"macOS"===v.os}var y="__LingXiaRecvMessage",w=5e3,x="[LX.Bridge]",b="messageport",_="jsinterface",k=v.appleDownstreamURL,E={data:!1,proto:!1,all:!1},I=[];function C(e){return E.all||E[e]}function T(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.log.apply(console,__spreadArray([x],e,!1))}function L(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.warn.apply(console,__spreadArray([x],e,!1))}function S(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.error.apply(console,__spreadArray([x],e,!1))}function M(e){try{return JSON.stringify(e)}catch(n){return function(e,n){var t=new WeakSet;return JSON.stringify(e,function(e,n){if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},n)}(e)}}function N(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch(e){return{}}}var O,A,j="iOS"===v.os||"macOS"===v.os?"webkit":"Harmony"===v.os?"messageport":"Android"===v.os?(null===(A=null===(O=window.LingXiaProxy)||void 0===O?void 0:O.supportsMessagePort)||void 0===A?void 0:A.call(O))?"messageport":"jsinterface":"unknown";"undefined"!=typeof window&&"function"!=typeof window[y]&&(window[y]=function(e){I.push(e)});var P=null,B=!1,R=null,F=null,D=null,X=200,H={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},q={handleEvent:function(e){var n,t,o=e;if("LingXia-port-init"===o.data){var r=null===(n=o.ports)||void 0===n?void 0:n[0];r&&(Je._connectWebMessagePort(r),null===(t=H.resolve)||void 0===t||t.call(H,r))}}};function z(){H.listenerInstalled||(H.listenerInstalled=!0,window.addEventListener("message",q))}function G(){null!==H.timer&&(window.clearTimeout(H.timer),H.timer=null),H.resolve=null,H.reject=null,H.promise=null}function U(){return"webkit"===j&&(h()||g())}function W(){null!==D&&(clearTimeout(D),D=null)}function J(e){for(var n=0,t=Array.from(ae.keys());n<t.length;n++){xe(t[n],{code:c,message:e})}for(var o=0,r=Array.from(le.keys());o<r.length;o++){be(r[o],{code:c,message:e})}!function(e){for(var n=0,t=Array.from(se.entries());n<t.length;n++){var o=t[n],r=o[0],i=o[1];se.delete(r),i._emitClose(c,e)}}(e)}function Y(){return __awaiter(this,void 0,void 0,function(){var e,n,t,o,r,i,a,l,s;return __generator(this,function(c){switch(c.label){case 0:if(!k)throw new Error("Apple downstream URL is not configured");return e=new AbortController,F=e,[4,fetch(k,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal})];case 1:if(!(n=c.sent()).ok)throw new Error("Apple downstream HTTP ".concat(n.status));if(!n.body)throw new Error("Apple downstream response body unavailable");B=!0,X=200,C("proto")&&T("Apple downstream connected"),Le(),t=n.body.getReader(),o=new TextDecoder,r="",c.label=2;case 2:c.trys.push([2,6,7,8]),c.label=3;case 3:return[4,t.read()];case 4:return i=c.sent(),a=i.value,i.done?[3,5]:(r=function(e){for(var n=e;;){var t=n.indexOf("\n");if(t<0)break;var o=n.slice(0,t).trim();if(n=n.slice(t+1),o)try{je(JSON.parse(o))}catch(e){L("Apple downstream parse error:",e,o)}}return n}(r+=o.decode(a,{stream:!0})),[3,3]);case 5:if(r+=o.decode(),l=r.trim())try{je(JSON.parse(l))}catch(e){L("Apple downstream trailing parse error:",e,l)}return[3,8];case 6:if(s=c.sent(),e.signal.aborted)return[2];throw s;case 7:try{t.releaseLock()}catch(e){}return[7];case 8:return[2]}})})}function V(){U()&&(R||(W(),R=Y().catch(function(e){(null==F?void 0:F.signal.aborted)||L("Apple downstream failed:",e)}).finally(function(){var e,n=null!==(e=null==F?void 0:F.signal.aborted)&&void 0!==e&&e;R=null,F=null;var t,o,r=B;B=!1,t="Apple downstream closed",o=r,Te(),K=null,Q=!1,Z=!1,ee=0,o&&J(t),n||function(e){if(U()){W();var n=X;X=Math.min(2*X,2e3);var t="Apple downstream disconnected, retrying in ".concat(n,"ms: ").concat(e);n<=200?T(t):L(t),D=setTimeout(function(){D=null,V()},n)}}("stream closed")})))}function $(e){var n,t,o,r=e.kind;"req"!==r&&"notify"!==r||T("postToNative: ".concat(r," ").concat(e.method)),C("proto")&&console.log("→",JSON.stringify(e,null,2));try{if("webkit"===j)return void(null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers.LingXia)||void 0===t||t.postMessage(e));var i=M(e);if(j===b&&P)return void P.postMessage(i);if(j===_&&(null===(o=window.LingXiaProxy)||void 0===o?void 0:o.postMessage))return void window.LingXiaProxy.postMessage(i);L("Transport not ready")}catch(e){S("Send error:",e)}}var K=null,Q=!1,Z=!1,ee=0,ne=null,te={},oe=0;function re(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function ie(e,n){var t,o=re(),r=!1,i=function(){},a=function(){},l=[],s=[],c=new Promise(function(e,n){i=e,a=n});return(t={id:e,result:c,on:function(e,n){return"data"===e&&o.data.add(n),"end"===e&&o.end.add(n),"error"===e&&o.error.add(n),this}})[Symbol.asyncIterator]=function(){return{next:function(){return l.length>0?Promise.resolve({done:!1,value:l.shift()}):r?c.then(function(e){return{done:!0,value:e}},function(e){return Promise.reject(e)}):new Promise(function(e,n){s.push({resolve:e,reject:n})})}}},t.cancel=function(){r||n()},t._emitData=function(e){if(!r){s.length>0?s.shift().resolve({done:!1,value:e}):l.push(e);for(var n=0,t=o.data;n<t.length;n++){var i=t[n];try{i(e)}catch(e){L("Stream data listener failed:",e)}}}},t._resolve=function(e){if(!r){for(r=!0,i(e);s.length>0;)s.shift().resolve({done:!0,value:e});for(var n=0,t=o.end;n<t.length;n++){var a=t[n];try{a(e)}catch(e){L("Stream end listener failed:",e)}}}},t._reject=function(e){if(!r){for(r=!0,a(e);s.length>0;)s.shift().reject(e);for(var n=0,t=o.error;n<t.length;n++){var i=t[n];try{i(e)}catch(e){L("Stream error listener failed:",e)}}}},t}var ae=new Map,le=new Map,se=new Map,ce=[],de=-1,ue={},fe=new Set,me=new WeakMap,ve=new Map;function pe(e,n){ve.set(e,n)}function he(e){if(e.startsWith("host."))return"host";var n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function ge(e){if(null!=e)return e}function ye(){return j===b?!!P:U()?B:"webkit"===j||j===_}function we(){return ye()&&Q}function xe(e,n){var t,o=ae.get(e);if(o){ae.delete(e),null!==o.timerId&&clearTimeout(o.timerId);var r=u(n);if("stream"===o.mode&&o.stream)return void o.stream._reject(r);null===(t=o.reject)||void 0===t||t.call(o,r)}}function be(e,n){var t=le.get(e);if(t){le.delete(e),null!==t.timerId&&clearTimeout(t.timerId);var o=u(n);t.channel._reject(o),t.reject(o)}}function _e(e,n){ae.has(e)?xe(e,n):le.has(e)&&be(e,n)}function ke(e){var t=ae.get(e);t&&(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0?null!==t.timerId&&(clearTimeout(t.timerId),t.timerId=null):(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(function(){ae.has(e)&&xe(e,{code:n,message:"'".concat(t.method,"' timed out")})},t.timeoutMs)))}function Ee(e){ae.has(e)?ke(e):le.has(e)&&function(e){var t=le.get(e);t&&(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(function(){be(e,{code:n,message:"Channel '".concat(t.topic,"' timed out")})},w))}(e)}function Ie(e){for(var n,t=ce.length-1;t>=0;t--)if((null===(n=ce[t])||void 0===n?void 0:n.reqId)===e)return ce.splice(t,1),!0;return!1}function Ce(e,n){var t=e.kind,o="hello"===t||"helloAck"===t||"ready"===t;if(!we()&&!o)return ce.length>=256?(S("Outbox full"),void(n&&_e(n,{code:s,message:"Bridge outbox is full"}))):void ce.push({msg:e,reqId:n});n&&Ee(n),$(e)}function Te(){null!==ne&&(clearTimeout(ne),ne=null)}function Le(){if(!Q&&ye()){Te();var e={v:2,kind:"hello",nonce:v.nonce||"",role:"view",protocolsSupported:[2]};Z=!0,$(e),ne=setTimeout(function(){if(!Q)if(++ee<3)L("Handshake timeout (".concat(ee,"/").concat(3,"), retrying...")),Z=!1,Le();else{for(S("Handshake failed"),Te(),Z=!1,ee=0;ce.length;){var e=ce.shift();(null==e?void 0:e.reqId)&&_e(e.reqId,{code:o,message:"Bridge handshake failed"})}for(var n=0,t=Array.from(le.keys());n<t.length;n++){be(t[n],{code:o,message:"Bridge handshake failed"})}}},1e4)}}function Se(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Me(e,n,t){void 0===t&&(t=!1);var o=function(e){if(""===e)return[];if(!e.startsWith("/"))throw new Error("Invalid JSON pointer: ".concat(e));return e.split("/").slice(1).map(Se)}(n);if(0===o.length)return{container:{$root:e},key:"$root"};for(var r=e,i=0;i<o.length-1;i++){var a=o[i];if(Array.isArray(r))r=r[Number(a)];else{if(!r||"object"!=typeof r)throw new Error("Invalid container at ".concat(a));var l=r;if(t&&void 0===l[a]){var s=o[i+1];l[a]=s&&/^\d+$/.test(s)?[]:{}}r=l[a]}}return{container:r,key:o[o.length-1]}}function Ne(e){fe.forEach(function(n){try{if(!me.has(n))return me.set(n,!0),void n(N(ue),{rev:de,initial:!0});n(N(ue),{rev:de,initial:e})}catch(e){L("Subscriber error:",e)}})}function Oe(e){if("function"!=typeof e)return function(){};if(fe.add(e),de>=0){me.set(e,!0);try{e(N(ue),{rev:de,initial:!0})}catch(e){S("Callback error:",e)}}return function(){fe.delete(e),me.delete(e)}}function Ae(e){We.call("state.getSnapshot",{scope:e}).catch(function(){})}function je(e){var n,t;if(e&&"object"==typeof e){var o=e;if("event"===o.type&&"nativecomponent"===o.name&&o.payload){var r=o.payload,l=r.id||r.componentId;if("string"==typeof l){var s=Pe.get(l);if(s)try{s(r)}catch(e){S("NC handler error:",e)}}return}}var c=function(e){if(!e||"object"!=typeof e)return null;var n=e.v,t=e.kind;return 2!==n||"string"!=typeof t?null:e}(e);if(c)switch(c.kind){case"helloAck":return void(K=c.sessionId);case"ready":if(K&&c.sessionId!==K)return void L("sessionId mismatch");if(Te(),Q=!0,ee=0,c.hostMethods)for(var d=0,f=Object.entries(c.hostMethods);d<f.length;d++){var m=f[d],v=m[0],p=m[1];te[v]=p}return C("proto")&&T("Handshake complete, hostMethods:",Object.keys(te).length),void function(){if(we())for(;ce.length;){var e=ce.shift();e&&(e.reqId&&Ee(e.reqId),$(e.msg))}}();case"res":var h=ae.get(c.id);if(!h)return;if(ae.delete(c.id),null!==h.timerId&&clearTimeout(h.timerId),c.ok){if("state.getSnapshot"===h.method&&(function(e){if(!e||"object"!=typeof e)return!1;var n=e;return!("number"!=typeof n.rev||!Number.isFinite(n.rev)||!n.state||"object"!=typeof n.state||(ue=n.state,de=n.rev,C("data")&&(console.group("[LX] snapshot(res)"),console.log("rev:",de,"state:",N(ue)),console.groupEnd()),Ne(!0),0))}(c.result)||L("Invalid state.getSnapshot result")),"stream"===h.mode&&h.stream)return void h.stream._resolve(c.result);null===(n=h.resolve)||void 0===n||n.call(h,c.result)}else{var g=u(c.error);if("stream"===h.mode&&h.stream)return void h.stream._reject(g);null===(t=h.reject)||void 0===t||t.call(h,g)}return;case"event":if(ae.has(c.id)){var y=ae.get(c.id);return void("stream"===(null==y?void 0:y.mode)&&y.stream?(ke(c.id),y.stream._emitData(c.payload)):L("Received event for non-stream request '".concat(c.id,"'")))}return;case"state.snapshot":return ue=c.state||{},de=c.rev,C("data")&&(console.group("[LX] snapshot"),console.log("rev:",de,"state:",N(ue)),console.groupEnd()),void Ne(!0);case"state.patch":if(c.baseRev!==de)return L("baseRev mismatch",{have:de,want:c.baseRev}),void Ae(c.scope);try{!function(e,n){for(var t=0,o=n;t<o.length;t++){var r=o[t],i="add"===r.op||"replace"===r.op,a=Me(e,r.path,i),l=a.container,s=a.key;if("$root"!==s)if(Array.isArray(l)){var c="-"===s?l.length:Number(s);if(!Number.isFinite(c)||c<0)throw new Error("Invalid index");"remove"===r.op?l.splice(c,1):"add"===r.op?l.splice(c,0,r.value):"replace"===r.op&&(l[c]=r.value)}else{if(!l||"object"!=typeof l)throw new Error("Invalid container");var d=l;"remove"===r.op?delete d[s]:d[s]=r.value}else{for(var u=0,f=Object.keys(e);u<f.length;u++)delete e[f[u]];if("remove"!==r.op){var m=r.value;m&&"object"==typeof m&&Object.assign(e,m)}}}}(ue,c.ops||[]),de=c.rev}catch(e){return S("Patch failed:",e),void Ae(c.scope)}return C("data")&&(console.group("[LX] patch"),console.log("rev:",de,"ops:",c.ops),console.groupEnd()),Ne(!1),void(c.ack&&Ce({v:2,kind:"state.ack",scope:c.scope,rev:c.rev}));case"ch.ack":if(!(x=le.get(c.id)))return;if(le.delete(c.id),null!==x.timerId&&clearTimeout(x.timerId),c.ok)x.channel._markOpen(),se.set(c.id,x.channel),x.resolve(x.channel);else{g=u(c.error);x.channel._reject(g),x.reject(g)}return;case"ch.data":var w=se.get(c.id);if(!w)return;return void w._emitData(c.payload);case"ch.close":var x;if(x=le.get(c.id))return le.delete(c.id),void x.channel._emitClose(c.code,c.reason);var b=se.get(c.id);if(!b)return;return se.delete(c.id),void b._emitClose(c.code,c.reason);case"req":var _=c,k=he(_.method);if(!_.cap||_.cap!==k)return void Ce({v:2,kind:"res",id:_.id,ok:!1,error:{code:a,message:"Invalid cap for ".concat(_.method)}});var E=ve.get(_.method);return E?void Promise.resolve().then(function(){return E(_.params)}).then(function(e){Ce({v:2,kind:"res",id:_.id,ok:!0,result:e})}).catch(function(e){Ce({v:2,kind:"res",id:_.id,ok:!1,error:u(e)})}):void Ce({v:2,kind:"res",id:_.id,ok:!1,error:{code:i,message:"View handler not found: ".concat(_.method)}})}else L("Invalid V2 message:",e)}var Pe=new Map,Be=[],Re=!1;function Fe(){var e,n,t;return"undefined"!=typeof window&&!(!(null===(n=null===(e=window.webkit)||void 0===e?void 0:e.messageHandlers)||void 0===n?void 0:n.NativeComponent)&&!(null===(t=window.NativeComponentBridge)||void 0===t?void 0:t.postMessage))}function De(e){var n,t,o;try{if(null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===t?void 0:t.NativeComponent)return void window.webkit.messageHandlers.NativeComponent.postMessage(e);if(null===(o=window.NativeComponentBridge)||void 0===o?void 0:o.postMessage)return void window.NativeComponentBridge.postMessage(M(e))}catch(e){S("NativeComponent send error:",e)}}function Xe(){if(Fe()&&0!==Be.length)for(Re=!0;Be.length;){var e=Be.shift();try{De(e)}catch(e){break}}}function He(e){try{if(!Fe())return void Be.push(e);Re||Xe(),De(e)}catch(e){S("NC send failed:",e)}}function qe(e){return"".concat(e,"_").concat(Date.now(),"_").concat(oe++)}function ze(e,n,t){if(n)if(n.aborted)t();else{var o={handleEvent:function(){n.removeEventListener("abort",o),t()}};n.addEventListener("abort",o)}}var Ge,Ue,We={call:function(e,n,o){return new Promise(function(i,a){var l;if(e&&"string"==typeof e){Z||Le();var s=qe("c"),c=(null==o?void 0:o.cap)||he(e),d=null!==(l=null==o?void 0:o.timeoutMs)&&void 0!==l?l:w;ae.set(s,{method:e,mode:"call",resolve:i,reject:function(e){return a(e)},timeoutMs:d,timerId:null}),Ce({v:2,kind:"req",id:s,method:e,params:ge(n),cap:c},s),ze(0,null==o?void 0:o.signal,function(){var e=Ie(s);xe(s,{code:t,message:"Bridge request aborted"}),!e&&Q&&Ce({v:2,kind:"cancel",id:s})})}else a({code:r,message:"Method name must be a non-empty string"})})},stream:function(e,n,o){var i;if(!e||"string"!=typeof e){var a=ie("invalid",function(){});return a._reject({code:r,message:"Method name must be a non-empty string"}),a}Z||Le();var l=qe("c"),s=ie(l,function(){Ie(l)?xe(l,{code:t,message:"Bridge request aborted"}):Q&&Ce({v:2,kind:"cancel",id:l})}),c=(null==o?void 0:o.cap)||he(e),d=null!==(i=null==o?void 0:o.timeoutMs)&&void 0!==i?i:w;return ae.set(l,{method:e,mode:"stream",stream:s,timeoutMs:d,timerId:null}),Ce({v:2,kind:"req",id:l,method:e,params:ge(n),cap:c},l),ze(0,null==o?void 0:o.signal,function(){return s.cancel()}),s},notify:function(e,n,t){e&&"string"==typeof e&&(Z||Le(),Ce({v:2,kind:"notify",method:e,params:ge(n),cap:(null==t?void 0:t.cap)||he(e)}))},state:{subscribe:Oe},channel:{open:function(e,n,t){return e&&"string"==typeof e?(Z||Le(),new Promise(function(o,r){var i=qe("ch"),a=function(e,n,t){var o,r=re(),i=!1,a=0,l=!1,s=[],d=[],u=((o={id:e,send:function(t){i?n(t,a++):u._reject({code:c,message:"Channel '".concat(e,"' is closed")})},on:function(e,n){return"data"===e&&r.data.add(n),"close"===e&&r.close.add(n),"error"===e&&r.error.add(n),this}})[Symbol.asyncIterator]=function(){return{next:function(){return s.length>0?Promise.resolve({done:!1,value:s.shift()}):l?Promise.resolve({done:!0,value:void 0}):new Promise(function(e,n){d.push({resolve:e,reject:n})})}}},o.close=function(e,n){i&&(i=!1,l=!0,t(e,n),u._emitClose(e,n))},o._emitData=function(e){if(i){d.length>0?d.shift().resolve({done:!1,value:e}):s.push(e);for(var n=0,t=r.data;n<t.length;n++){var o=t[n];try{o(e)}catch(e){L("Channel listener failed:",e)}}}},o._emitClose=function(e,n){for(l=!0;d.length>0;)d.shift().resolve({done:!0,value:void 0});for(var t=0,o=r.close;t<o.length;t++){var i=o[t];try{i(e,n)}catch(e){L("Channel close listener failed:",e)}}},o._reject=function(e){for(l=!0;d.length>0;)d.shift().reject(e);for(var n=0,t=r.error;n<t.length;n++){var o=t[n];try{o(e)}catch(e){L("Channel error listener failed:",e)}}},o._markOpen=function(){i=!0,l=!1},o._isOpen=function(){return i},o._nextSeq=function(){return a++},o);return u}(i,function(e,n){Ce({v:2,kind:"ch.data",id:i,seq:n,payload:e})},function(e,n){var t=le.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),le.delete(i),se.delete(i),Ce({v:2,kind:"ch.close",id:i,code:e,reason:n})});le.set(i,{topic:e,channel:a,resolve:o,reject:r,timerId:null}),Ce({v:2,kind:"ch.open",id:i,topic:e,params:ge(n),cap:(null==t?void 0:t.cap)||he(e)},i)})):Promise.reject({code:r,message:"Topic name must be a non-empty string"})}}},Je={invoke:function(e,n,t){return We.call(Ye(e),n,Ve(t)).then(function(e){return e}).catch(function(e){return Promise.reject(f(e))})},notify:function(e,n,t){We.notify(Ye(e),n,Ve(t))},stream:function(e,n,t){return $e(We.stream(Ye(e),n,Ve(t)))},channel:function(e,n,t){return We.channel.open(Ye(e),n,Ve(t)).then(function(e){return function(e){var n=new Set,t=new Set;return e.on("data",function(e){for(var t=0,o=n;t<o.length;t++){(0,o[t])(e)}}),e.on("close",function(e,n){for(var o={code:e,reason:n},r=0,i=t;r<i.length;r++){(0,i[r])(o)}}),{send:function(n){e.send(n)},onMessage:function(e){return n.add(e),function(){n.delete(e)}},onClose:function(e){return t.add(e),function(){t.delete(e)}},close:function(n,t){e.close(n,t)}}}(e)}).catch(function(e){return Promise.reject(f(e))})},raw:We,state:{subscribe:Oe},_connectWebMessagePort:function(e){if(j===b){if(P&&P!==e)try{P.onmessage=null,P.close()}catch(e){}P=e,e.onmessage=function(e){var n=e.data;if("string"==typeof n)try{n=JSON.parse(n)}catch(e){return}je(n)};try{e.start()}catch(e){}T("Port connected"),Le()}},_receiveEvaluateMessage:function(e){try{e&&je(JSON.parse(e))}catch(e){S("Parse error:",e)}},debug:(Ge=E,Ue={},Object.keys(Ge).forEach(function(e){Object.defineProperty(Ue,e,{enumerable:!0,configurable:!1,get:function(){return Ge[e]},set:function(n){Ge[e]=!!n,console.log("[LX] ".concat(e,": ").concat(n))}})}),Ue),platform:{isHarmony:function(){return"Harmony"===v.os},isIOS:h,isAndroid:function(){return"Android"===v.os},isMacOS:g,isDesktop:function(){return g()},getOS:p},dom:{measureById:function(e){try{if(!e)return null;var n=document.getElementById(e);if(!n)return null;var t=n.getBoundingClientRect(),o=0;try{o=parseFloat(getComputedStyle(n).borderRadius)||0}catch(e){}return[t.left+window.scrollX,t.top+window.scrollY,t.width,t.height,o]}catch(e){return null}}},nativeComponents:{send:He,hasHandler:Fe,flush:Xe,register:function(e,n){return e&&"function"==typeof n?(Pe.set(e,n),function(){return Pe.delete(e)}):function(){}},unregister:function(e){Pe.delete(e)}},isReady:function(){return Q}};function Ye(e){return e.startsWith("host.")?e:"host.".concat(e)}function Ve(e){return __assign(__assign({},e||{}),{cap:(null==e?void 0:e.cap)||"host"})}function $e(e){var n=new Set,t=new Set;return e.on("data",function(e){for(var t=0,o=n;t<o.length;t++){(0,o[t])(e)}}),e.on("error",function(e){for(var n=f(e),o=0,r=t;o<r.length;o++){(0,r[o])(n)}}),{onEvent:function(e){return n.add(e),function(){n.delete(e)}},onError:function(e){return t.add(e),function(){t.delete(e)}},result:e.result.catch(function(e){return Promise.reject(f(e))}),cancel:function(){e.cancel()}}}function Ke(){if(window.__LX_BRIDGE_INIT_STATE)T("Bridge already ".concat(window.__LX_BRIDGE_INIT_STATE,", skipping duplicate init"));else{window.__LX_BRIDGE_INIT_STATE="initializing";try{T("Method: ".concat(j)),function(e){if("undefined"!=typeof window&&(window[y]=e,0!==I.length))for(var n=0,t=I.splice(0,I.length);n<t.length;n++){var o=t[n];try{e(o)}catch(e){L("Failed to replay queued native message:",e)}}}(Je._receiveEvaluateMessage),U()?V():j===b?(z(),function(){var e,n;if(P)return Promise.resolve(P);if(H.promise)return H.promise;z(),H.promise=new Promise(function(e,n){H.resolve=function(n){G(),e(n)},H.reject=function(e){G(),n(e)},H.timer=window.setTimeout(function(){var e;null===(e=H.reject)||void 0===e||e.call(H,new Error("MessagePort init timed out after ".concat(5e3,"ms")))},5e3)});try{null===(e=window.LingXiaProxy)||void 0===e||e.getPort("LingXiaPort")}catch(e){null===(n=H.reject)||void 0===n||n.call(H,e)}return H.promise}().catch(function(e){return L("Port init failed:",e)})):"webkit"===j||j===_?Le():L("Unknown method"),window.LingXiaBridge=Je,m({os:p(),send:He}),window.__LX_BRIDGE_INIT_STATE="initialized",T("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}}}function Qe(e){var n=document.createElement("div");return n.textContent=e,n.innerHTML}function Ze(e){var n=e.failedPath,t=e.reason,o=document.createElement("style");o.textContent="\n* { margin: 0; padding: 0; box-sizing: border-box; }\nbody {\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n background: #f5f5f7;\n color: #1d1d1f;\n padding: 20px;\n -webkit-font-smoothing: antialiased;\n}\n.lx-error {\n text-align: center;\n max-width: 400px;\n}\n.lx-error-code {\n font-size: 120px;\n font-weight: 700;\n color: #d1d1d6;\n line-height: 1;\n letter-spacing: -4px;\n}\n.lx-error-title {\n font-size: 21px;\n font-weight: 600;\n margin: 16px 0 8px;\n color: #1d1d1f;\n}\n.lx-error-desc {\n font-size: 15px;\n color: #86868b;\n line-height: 1.5;\n}\n.lx-error-path {\n display: inline-block;\n margin-top: 20px;\n padding: 10px 16px;\n background: rgba(0,0,0,0.04);\n border-radius: 8px;\n font-family: 'SF Mono', ui-monospace, Menlo, Monaco, monospace;\n font-size: 13px;\n color: #1d1d1f;\n word-break: break-all;\n max-width: 100%;\n}\n@media (prefers-color-scheme: dark) {\n body { background: #000; color: #f5f5f7; }\n .lx-error-code { color: #3a3a3c; }\n .lx-error-title { color: #f5f5f7; }\n .lx-error-desc { color: #86868b; }\n .lx-error-path { background: rgba(255,255,255,0.08); color: #f5f5f7; }\n}\n",document.head.appendChild(o),document.body.innerHTML="",document.body.style.cssText="";var r=document.createElement("div");r.className="lx-error";var i='<div class="lx-error-code">404</div>';i+='<h1 class="lx-error-title">Page Not Found</h1>',i+="<p class=\"lx-error-desc\">The page you're looking for doesn't exist.</p>",n&&(i+='<div class="lx-error-path">'.concat(Qe(n),"</div>")),t&&(i+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Qe(t),"</p>")),r.innerHTML=i,document.body.appendChild(r)}function en(){var e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function nn(){var e;return(null===(e=window.__LX_RUNTIME_CONFIG)||void 0===e?void 0:e.error)||null}var tn={handleEvent:function(){return on()}};function on(){if(en()){var e=nn();e&&Ze(e)}}function rn(){Ke(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",tn):on()}var an="lx-action-sheet-style",ln=null;function sn(e){var n,t,o,r=e,i=null!==(n=null==r?void 0:r.itemList)&&void 0!==n?n:[],a=null!==(t=null==r?void 0:r.cancelText)&&void 0!==t?t:"Cancel",l=null!==(o=null==r?void 0:r.itemColor)&&void 0!==o?o:"#007AFF",s=(null!=ln?ln:Promise.resolve()).then(function(){return cn(i,a,l)},function(){return cn(i,a,l)});return ln=s,s}function cn(e,n,t){return new Promise(function(o){var r=!1,i="macOS"===p();!function(){if(!document.getElementById(an)){var e=document.createElement("style");e.id=an,e.textContent="\n.lx-as-backdrop {\n position: fixed; inset: 0; z-index: 99999;\n background: rgba(0,0,0,0.4);\n opacity: 0; transition: opacity ".concat(300,"ms ease;\n}\n.lx-as-backdrop.lx-as-visible { opacity: 1; }\n\n.lx-as-sheet {\n position: fixed; left: 0; right: 0; bottom: 0; z-index: 100000;\n transform: translateY(100%);\n transition: transform ").concat(300,"ms ease;\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n -webkit-font-smoothing: antialiased;\n}\n.lx-as-sheet.lx-as-visible { transform: translateY(0); }\n.lx-as-sheet.lx-as-desktop {\n left: 50%;\n right: auto;\n bottom: auto;\n top: 50%;\n width: min(92vw, 460px);\n transform: translate(-50%, calc(-50% + 16px));\n}\n.lx-as-sheet.lx-as-desktop.lx-as-visible { transform: translate(-50%, -50%); }\n\n.lx-as-container {\n background: #fff;\n border-radius: 16px 16px 0 0;\n overflow: hidden;\n}\n.lx-as-container.lx-as-desktop {\n border-radius: 16px;\n}\n\n.lx-as-item {\n display: block; width: 100%;\n height: 56px;\n line-height: 56px;\n padding: 0;\n border: none; background: none;\n font-size: 18px; font-weight: 400;\n text-align: center;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n position: relative;\n}\n.lx-as-item:active { background: rgba(0,0,0,0.08); }\n.lx-as-item + .lx-as-item::before {\n content: ''; position: absolute; top: 0; left: 0; right: 0;\n height: 1px; background: #E0E0E0;\n}\n.lx-as-separator {\n height: 8px;\n background: #F2F2F2;\n}\n.lx-as-cancel-btn { font-weight: 500; color: #000; }\n"),document.head.appendChild(e)}}();var a=document.createElement("div");a.className="lx-as-backdrop";var l=document.createElement("div");l.className="lx-as-sheet",i&&l.classList.add("lx-as-desktop");var s=document.createElement("div");s.className="lx-as-container",i&&s.classList.add("lx-as-desktop"),e.forEach(function(e,n){var o=document.createElement("button");o.className="lx-as-item",o.textContent=e,o.style.color=t,o.addEventListener("click",function(){return u(n)}),s.appendChild(o)});var c=document.createElement("div");c.className="lx-as-separator",s.appendChild(c);var d=document.createElement("button");function u(e){r||(r=!0,a.classList.remove("lx-as-visible"),l.classList.remove("lx-as-visible"),setTimeout(function(){a.remove(),l.remove(),o({tapIndex:e})},300))}d.className="lx-as-item lx-as-cancel-btn",d.textContent=n,d.addEventListener("click",function(){return u(-1)}),s.appendChild(d),l.appendChild(s),document.body.appendChild(a),document.body.appendChild(l),requestAnimationFrame(function(){a.classList.add("lx-as-visible"),l.classList.add("lx-as-visible")}),a.addEventListener("click",function(){return u(-1)})})}var dn=200,un="lx-modal-style",fn=null;function mn(e){var n,t,o,r,i,a,l=e,s=null!==(n=null==l?void 0:l.title)&&void 0!==n?n:"",c=null!==(t=null==l?void 0:l.content)&&void 0!==t?t:"",d=null===(o=null==l?void 0:l.showCancel)||void 0===o||o,u=null!==(r=null==l?void 0:l.cancelText)&&void 0!==r?r:"Cancel",f=null==l?void 0:l.cancelColor,m=null!==(i=null==l?void 0:l.confirmText)&&void 0!==i?i:"OK",v=null!==(a=null==l?void 0:l.confirmColor)&&void 0!==a?a:"#007AFF",p=(null!=fn?fn:Promise.resolve()).then(function(){return vn(s,c,d,u,f,m,v)},function(){return vn(s,c,d,u,f,m,v)});return fn=p,p}function vn(e,n,t,o,r,i,a){return new Promise(function(l){var s=!1;!function(){if(!document.getElementById(un)){var e=document.createElement("style");e.id=un,e.textContent="\n.lx-modal-backdrop {\n position: fixed; inset: 0; z-index: 99999;\n background: rgba(0,0,0,0.4);\n opacity: 0; transition: opacity ".concat(dn,"ms ease;\n display: flex; align-items: center; justify-content: center;\n}\n.lx-modal-backdrop.lx-modal-visible { opacity: 1; }\n\n.lx-modal-dialog {\n width: min(92vw, 320px);\n background: #fff;\n border-radius: 14px;\n overflow: hidden;\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n -webkit-font-smoothing: antialiased;\n transform: scale(0.95); opacity: 0;\n transition: transform ").concat(dn,"ms ease, opacity ").concat(dn,"ms ease;\n}\n.lx-modal-backdrop.lx-modal-visible .lx-modal-dialog {\n transform: scale(1); opacity: 1;\n}\n\n.lx-modal-body {\n padding: 24px 20px 16px;\n text-align: center;\n}\n.lx-modal-title {\n margin: 0 0 8px;\n font-size: 17px;\n font-weight: 600;\n color: #000;\n line-height: 1.35;\n}\n.lx-modal-content {\n margin: 0;\n font-size: 14px;\n color: #666;\n line-height: 1.5;\n word-break: break-word;\n}\n.lx-modal-body:has(.lx-modal-title:empty) .lx-modal-content {\n font-size: 17px;\n font-weight: 600;\n color: #000;\n}\n\n.lx-modal-footer {\n display: flex;\n border-top: 1px solid #E0E0E0;\n}\n.lx-modal-btn {\n flex: 1;\n height: 44px;\n line-height: 44px;\n padding: 0;\n border: none;\n background: none;\n font-size: 17px;\n text-align: center;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n}\n.lx-modal-btn:active { background: rgba(0,0,0,0.06); }\n.lx-modal-btn + .lx-modal-btn {\n border-left: 1px solid #E0E0E0;\n}\n.lx-modal-btn-cancel {\n color: #666;\n font-weight: 400;\n}\n.lx-modal-btn-confirm {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n .lx-modal-dialog { background: #2c2c2e; }\n .lx-modal-title { color: #f5f5f7; }\n .lx-modal-content { color: #ababab; }\n .lx-modal-body:has(.lx-modal-title:empty) .lx-modal-content {\n color: #f5f5f7;\n }\n .lx-modal-footer { border-top-color: #3a3a3c; }\n .lx-modal-btn:active { background: rgba(255,255,255,0.08); }\n .lx-modal-btn + .lx-modal-btn { border-left-color: #3a3a3c; }\n .lx-modal-btn-cancel { color: #ababab; }\n}\n"),document.head.appendChild(e)}}();var c=document.createElement("div");c.className="lx-modal-backdrop";var d=document.createElement("div");d.className="lx-modal-dialog";var u=document.createElement("div");u.className="lx-modal-body";var f=document.createElement("div");if(f.className="lx-modal-title",f.textContent=e,u.appendChild(f),n){var m=document.createElement("p");m.className="lx-modal-content",m.textContent=n,u.appendChild(m)}d.appendChild(u);var v=document.createElement("div");if(v.className="lx-modal-footer",t){var p=document.createElement("button");p.className="lx-modal-btn lx-modal-btn-cancel",p.textContent=o,r&&(p.style.color=r),p.addEventListener("click",function(){return g(!1)}),v.appendChild(p)}var h=document.createElement("button");function g(e){s||(s=!0,c.classList.remove("lx-modal-visible"),setTimeout(function(){c.remove(),l({confirm:e,cancel:!e})},dn))}h.className="lx-modal-btn lx-modal-btn-confirm",h.textContent=i,h.style.color=a,h.addEventListener("click",function(){return g(!0)}),v.appendChild(h),d.appendChild(v),c.appendChild(d),document.body.appendChild(c),requestAnimationFrame(function(){c.classList.add("lx-modal-visible")})})}var pn="lx-toast-style",hn=null;function gn(e){var n,t,o,r,i,a=e,l=null!==(n=null==a?void 0:a.title)&&void 0!==n?n:"",s=null!==(t=null==a?void 0:a.icon)&&void 0!==t?t:"none",c=null!==(o=null==a?void 0:a.duration)&&void 0!==o?o:1500,d=null!==(r=null==a?void 0:a.mask)&&void 0!==r&&r,u=null!==(i=null==a?void 0:a.position)&&void 0!==i?i:"center";hn&&(hn.dismiss(),hn=null),function(){if(!document.getElementById(pn)){var e=document.createElement("style");e.id=pn,e.textContent="\n.lx-toast-mask {\n position: fixed; inset: 0; z-index: 99998;\n}\n.lx-toast-container {\n position: fixed; left: 0; right: 0; z-index: 99999;\n display: flex; justify-content: center;\n pointer-events: none;\n}\n.lx-toast-container.lx-toast-top { top: 0; padding-top: 80px; }\n.lx-toast-container.lx-toast-center { top: 0; bottom: 0; align-items: center; }\n.lx-toast-container.lx-toast-bottom { bottom: 0; padding-bottom: 80px; }\n\n.lx-toast-box {\n display: flex; flex-direction: column; align-items: center; gap: 10px;\n min-width: 120px; max-width: 280px;\n padding: 20px;\n background: rgba(0,0,0,0.8);\n border-radius: 12px;\n color: #fff;\n pointer-events: auto;\n transform: scale(0.8); opacity: 0;\n transition: transform ".concat(200,"ms ease, opacity ").concat(200,"ms ease;\n}\n.lx-toast-box.lx-toast-no-icon {\n min-width: auto; min-height: auto;\n padding: 12px 20px;\n}\n.lx-toast-box.lx-toast-visible {\n transform: scale(1); opacity: 1;\n}\n.lx-toast-icon {\n width: 36px; height: 36px;\n color: #fff;\n line-height: 0;\n}\n.lx-toast-title {\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n font-size: 16px; font-weight: 500;\n text-align: center;\n line-height: 1.4;\n word-break: break-word;\n -webkit-font-smoothing: antialiased;\n}\n"),document.head.appendChild(e)}}();var f=null;d&&((f=document.createElement("div")).className="lx-toast-mask",document.body.appendChild(f));var m=document.createElement("div");m.className="lx-toast-container","top"===u?m.classList.add("lx-toast-top"):"bottom"===u?m.classList.add("lx-toast-bottom"):m.classList.add("lx-toast-center");var v=document.createElement("div");v.className="lx-toast-box";var p="none"!==s;if(p||v.classList.add("lx-toast-no-icon"),p){var h=document.createElement("div");h.className="lx-toast-icon","success"===s?h.innerHTML='<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="18" cy="18" r="17" stroke="currentColor" stroke-width="2"/><path d="M11 18l5 5 9-9" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>':"error"===s?h.innerHTML='<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="18" cy="18" r="17" stroke="currentColor" stroke-width="2"/><path d="M13 13l10 10M23 13l-10 10" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>':"loading"===s&&(h.innerHTML='<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 4a14 14 0 0 1 14 14" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="0.8s" repeatCount="indefinite"/></path></svg>'),v.appendChild(h)}var g=document.createElement("div");g.className="lx-toast-title",g.textContent=l,v.appendChild(g),m.appendChild(v),document.body.appendChild(m),requestAnimationFrame(function(){v.classList.add("lx-toast-visible")});var y=!1;function w(){y||(y=!0,(null==hn?void 0:hn.dismiss)===w&&(hn=null),v.classList.remove("lx-toast-visible"),x&&clearTimeout(x),setTimeout(function(){m.remove(),null==f||f.remove()},200))}var x=null;return c>0&&(x=setTimeout(w,c)),hn={dismiss:w,timer:x},Promise.resolve()}function yn(){return hn&&(hn.dismiss(),hn=null),Promise.resolve()}return"all"!==__LX_RUNTIME_PLATFORM__&&"desktop"!==__LX_RUNTIME_PLATFORM__||(pe("ui.showActionSheet",sn),pe("ui.showModal",mn),pe("ui.showToast",gn),pe("ui.hideToast",yn)),rn(),e.LingXiaBridge=Je,e.boot=function(){Ke(),on()},e.bootWhenReady=rn,e.channel=function(e,n,t){return Je.channel(e,n,t)},e.getErrorInfo=nn,e.hasError=en,e.initBridge=Ke,e.invoke=function(e,n,t){return Je.invoke(e,n,t)},e.isNativeError=function(e,n){if(!e||"object"!=typeof e)return!1;var t=e;return"string"==typeof t.code&&""!==t.code.trim()&&("string"==typeof t.message&&(void 0===n||t.code===n))},e.notify=function(e,n,t){We.notify(Ye(e),n,Ve(t))},e.renderErrorUI=Ze,e.stream=function(e,n,t){return $e(We.stream(Ye(e),n,Ve(t)))},e}({});
1
+ var __extends=this&&this.__extends||function(){var e=function(n,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},e(n,t)};return function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=n}e(n,t),n.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},__assign.apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))(function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function c(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(a,c)}l((r=r.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(e,n){var t,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=n.call(e,i)}catch(e){c=[6,e],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}},__spreadArray=this&&this.__spreadArray||function(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))},__LX_RUNTIME_PLATFORM__="mobile",__LingXiaBridgeBundle=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var n="BRIDGE_TIMEOUT",t="BRIDGE_CANCELED",r="BRIDGE_HANDSHAKE_FAILED",o="BRIDGE_MALFORMED_MESSAGE",i="BRIDGE_METHOD_NOT_FOUND",a="BRIDGE_CAPABILITY_DENIED",c="BRIDGE_INTERNAL_ERROR",l="BRIDGE_OUTBOX_FULL",s="BRIDGE_STREAM_CLOSED",d=function(e){function n(n,t,r){var o=e.call(this,t)||this;return o.name="BridgeInvocationError",o.code=n,o.data=r,o}return __extends(n,e),n}(Error);function u(e){if(e instanceof d)return e;if(e&&"object"==typeof e){var n=e,t=c;("string"==typeof n.code&&""!==n.code.trim()||"number"==typeof n.code&&Number.isFinite(n.code))&&(t=n.code);var r="string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error";return new d(t,r,"data"in n?n.data:void 0)}var o=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new d(c,o)}function f(e){var n=u(e);return __assign({code:String(n.code||c),message:"string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error"},void 0===n.data?{}:{data:n.data})}function v(e){var n,t=e.os,r=e.send;if("undefined"!=typeof window&&"undefined"!=typeof document){var o="iOS"===t;if(o||"Android"===t){var i=Symbol.for("LingXia.NativeComponentCoverageMonitor");if(!(null===(n=window[i])||void 0===n?void 0:n.installed)){var a={installed:!0,coveredById:new Map,coveredCount:0,anyCovered:!1,scheduled:!1,hasAnyVideo:!1,scrollLocked:!1,scrollY:0,htmlOverflow:"",bodyOverflow:"",bodyPosition:"",bodyTop:"",bodyWidth:""};window[i]=a,new MutationObserver(u).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0});var c={handleEvent:function(){(a.hasAnyVideo||0!==a.coveredById.size)&&u()}},l={handleEvent:function(){return u()}};window.addEventListener("scroll",c,{capture:!0,passive:!0}),window.addEventListener("resize",l),u()}}}function s(e){var n,t,r=null===(n=e.getBoundingClientRect)||void 0===n?void 0:n.call(e);if(!r)return!1;if(r.width<2||r.height<2)return!1;var o=r.left+r.width/2,i=r.top+r.height/2;if(o<0||i<0||o>=window.innerWidth||i>=window.innerHeight)return!1;var a=null===(t=document.elementFromPoint)||void 0===t?void 0:t.call(document,o,i);return!!a&&(a!==document.documentElement&&a!==document.body&&!(a===e||e.contains(a)))}function d(){a.scheduled=!1;var e=document.querySelectorAll("lx-video[id]");if(a.hasAnyVideo=e.length>0,a.hasAnyVideo||0!==a.coveredById.size||a.anyCovered){for(var n=new Set,t=0,i=Array.from(e);t<i.length;t++){var c=i[t];if(m=c.id){n.add(m);var l=s(c),d=a.coveredById.get(m);d!==l&&(!0===d&&(a.coveredCount-=1),!0===l&&(a.coveredCount+=1),a.coveredById.set(m,l),r({id:m,action:"component.coverage",covered:l}))}}for(var u=[],f=0,v=a.coveredById.entries();f<v.length;f++){var p=v[f],m=p[0];l=p[1];n.has(m)||(u.push(m),!0===l&&(a.coveredCount-=1))}for(var h=0,g=u;h<g.length;h++){m=g[h];a.coveredById.delete(m),r({id:m,action:"component.coverage",covered:!1})}var y=a.coveredCount>0;y!==a.anyCovered&&(a.anyCovered=y,o&&(y?function(){if(o&&!a.scrollLocked){var e=document.documentElement,n=document.body;e&&n&&(a.scrollLocked=!0,a.scrollY=window.scrollY||e.scrollTop||0,a.htmlOverflow=e.style.overflow||"",a.bodyOverflow=n.style.overflow||"",a.bodyPosition=n.style.position||"",a.bodyTop=n.style.top||"",a.bodyWidth=n.style.width||"",e.style.overflow="hidden",n.style.overflow="hidden",n.style.position="fixed",n.style.top="".concat(-a.scrollY,"px"),n.style.width="100%")}}():function(){if(o&&a.scrollLocked){var e=document.documentElement,n=document.body;e&&n&&(a.scrollLocked=!1,e.style.overflow=a.htmlOverflow,n.style.overflow=a.bodyOverflow,n.style.position=a.bodyPosition,n.style.top=a.bodyTop,n.style.width=a.bodyWidth,window.scrollTo(0,a.scrollY))}}()))}}function u(){a.scheduled||(a.scheduled=!0,requestAnimationFrame(d))}}var p="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{};function m(){return p.os||"unknown"}function h(){return"iOS"===p.os}function g(){return"macOS"===p.os}var y="__LingXiaRecvMessage",w=5e3,_="[LX.Bridge]",b="messageport",I="jsinterface",k=p.appleDownstreamURL,E={data:!1,proto:!1,all:!1},x=[];function S(e){return E.all||E[e]}function T(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.log.apply(console,__spreadArray([_],e,!1))}function O(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.warn.apply(console,__spreadArray([_],e,!1))}function M(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.error.apply(console,__spreadArray([_],e,!1))}function j(e){try{return JSON.stringify(e)}catch(n){return function(e,n){var t=new WeakSet;return JSON.stringify(e,function(e,n){if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},n)}(e)}}function A(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch(e){return{}}}var L,C,N="iOS"===p.os||"macOS"===p.os?"webkit":"Harmony"===p.os?"messageport":"Android"===p.os?(null===(C=null===(L=window.LingXiaProxy)||void 0===L?void 0:L.supportsMessagePort)||void 0===C?void 0:C.call(L))?"messageport":"jsinterface":"unknown";"undefined"!=typeof window&&"function"!=typeof window[y]&&(window[y]=function(e){x.push(e)});var P=null,B=!1,R=null,D=null,X=null,G=200,F={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},H={handleEvent:function(e){var n,t,r=e;if("LingXia-port-init"===r.data){var o=null===(n=r.ports)||void 0===n?void 0:n[0];o&&(ze._connectWebMessagePort(o),null===(t=F.resolve)||void 0===t||t.call(F,o))}}};function q(){F.listenerInstalled||(F.listenerInstalled=!0,window.addEventListener("message",H))}function U(){null!==F.timer&&(window.clearTimeout(F.timer),F.timer=null),F.resolve=null,F.reject=null,F.promise=null}function W(){return"webkit"===N&&(h()||g())}function z(){null!==X&&(clearTimeout(X),X=null)}function J(e){for(var n=0,t=Array.from(ae.keys());n<t.length;n++){we(t[n],{code:s,message:e})}for(var r=0,o=Array.from(ce.keys());r<o.length;r++){_e(o[r],{code:s,message:e})}!function(e){for(var n=0,t=Array.from(le.entries());n<t.length;n++){var r=t[n],o=r[0],i=r[1];le.delete(o),i._emitClose(s,e)}}(e)}function Y(){return __awaiter(this,void 0,void 0,function(){var e,n,t,r,o,i,a,c,l;return __generator(this,function(s){switch(s.label){case 0:if(!k)throw new Error("Apple downstream URL is not configured");return e=new AbortController,D=e,[4,fetch(k,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal})];case 1:if(!(n=s.sent()).ok)throw new Error("Apple downstream HTTP ".concat(n.status));if(!n.body)throw new Error("Apple downstream response body unavailable");B=!0,G=200,S("proto")&&T("Apple downstream connected"),Te(),t=n.body.getReader(),r=new TextDecoder,o="",s.label=2;case 2:s.trys.push([2,6,7,8]),s.label=3;case 3:return[4,t.read()];case 4:return i=s.sent(),a=i.value,i.done?[3,5]:(o=function(e){for(var n=e;;){var t=n.indexOf("\n");if(t<0)break;var r=n.slice(0,t).trim();if(n=n.slice(t+1),r)try{Ce(JSON.parse(r))}catch(e){O("Apple downstream parse error:",e,r)}}return n}(o+=r.decode(a,{stream:!0})),[3,3]);case 5:if(o+=r.decode(),c=o.trim())try{Ce(JSON.parse(c))}catch(e){O("Apple downstream trailing parse error:",e,c)}return[3,8];case 6:if(l=s.sent(),e.signal.aborted)return[2];throw l;case 7:try{t.releaseLock()}catch(e){}return[7];case 8:return[2]}})})}function V(){W()&&(R||(z(),R=Y().catch(function(e){(null==D?void 0:D.signal.aborted)||O("Apple downstream failed:",e)}).finally(function(){var e,n=null!==(e=null==D?void 0:D.signal.aborted)&&void 0!==e&&e;R=null,D=null;var t,r,o=B;B=!1,t="Apple downstream closed",r=o,Se(),K=null,Q=!1,Z=!1,ee=0,r&&J(t),n||function(e){if(W()){z();var n=G;G=Math.min(2*G,2e3);var t="Apple downstream disconnected, retrying in ".concat(n,"ms: ").concat(e);n<=200?T(t):O(t),X=setTimeout(function(){X=null,V()},n)}}("stream closed")})))}function $(e){var n,t,r,o=e.kind;"req"!==o&&"notify"!==o||T("postToNative: ".concat(o," ").concat(e.method)),S("proto")&&console.log("→",JSON.stringify(e,null,2));try{if("webkit"===N)return void(null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers.LingXia)||void 0===t||t.postMessage(e));var i=j(e);if(N===b&&P)return void P.postMessage(i);if(N===I&&(null===(r=window.LingXiaProxy)||void 0===r?void 0:r.postMessage))return void window.LingXiaProxy.postMessage(i);O("Transport not ready")}catch(e){M("Send error:",e)}}var K=null,Q=!1,Z=!1,ee=0,ne=null,te={},re=0;function oe(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function ie(e,n){var t,r=oe(),o=!1,i=function(){},a=function(){},c=[],l=[],s=new Promise(function(e,n){i=e,a=n});return(t={id:e,result:s,on:function(e,n){return"data"===e&&r.data.add(n),"end"===e&&r.end.add(n),"error"===e&&r.error.add(n),this}})[Symbol.asyncIterator]=function(){return{next:function(){return c.length>0?Promise.resolve({done:!1,value:c.shift()}):o?s.then(function(e){return{done:!0,value:e}},function(e){return Promise.reject(e)}):new Promise(function(e,n){l.push({resolve:e,reject:n})})}}},t.cancel=function(){o||n()},t._emitData=function(e){if(!o){l.length>0?l.shift().resolve({done:!1,value:e}):c.push(e);for(var n=0,t=r.data;n<t.length;n++){var i=t[n];try{i(e)}catch(e){O("Stream data listener failed:",e)}}}},t._resolve=function(e){if(!o){for(o=!0,i(e);l.length>0;)l.shift().resolve({done:!0,value:e});for(var n=0,t=r.end;n<t.length;n++){var a=t[n];try{a(e)}catch(e){O("Stream end listener failed:",e)}}}},t._reject=function(e){if(!o){for(o=!0,a(e);l.length>0;)l.shift().reject(e);for(var n=0,t=r.error;n<t.length;n++){var i=t[n];try{i(e)}catch(e){O("Stream error listener failed:",e)}}}},t}var ae=new Map,ce=new Map,le=new Map,se=[],de=-1,ue={},fe=new Set,ve=new WeakMap,pe=new Map;function me(e){if(e.startsWith("host."))return"host";var n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function he(e){if(null!=e)return e}function ge(){return N===b?!!P:W()?B:"webkit"===N||N===I}function ye(){return ge()&&Q}function we(e,n){var t,r=ae.get(e);if(r){ae.delete(e),null!==r.timerId&&clearTimeout(r.timerId);var o=u(n);if("stream"===r.mode&&r.stream)return void r.stream._reject(o);null===(t=r.reject)||void 0===t||t.call(r,o)}}function _e(e,n){var t=ce.get(e);if(t){ce.delete(e),null!==t.timerId&&clearTimeout(t.timerId);var r=u(n);t.channel._reject(r),t.reject(r)}}function be(e,n){ae.has(e)?we(e,n):ce.has(e)&&_e(e,n)}function Ie(e){var t=ae.get(e);t&&(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0?null!==t.timerId&&(clearTimeout(t.timerId),t.timerId=null):(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(function(){ae.has(e)&&we(e,{code:n,message:"'".concat(t.method,"' timed out")})},t.timeoutMs)))}function ke(e){ae.has(e)?Ie(e):ce.has(e)&&function(e){var t=ce.get(e);t&&(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(function(){_e(e,{code:n,message:"Channel '".concat(t.topic,"' timed out")})},w))}(e)}function Ee(e){for(var n,t=se.length-1;t>=0;t--)if((null===(n=se[t])||void 0===n?void 0:n.reqId)===e)return se.splice(t,1),!0;return!1}function xe(e,n){var t=e.kind,r="hello"===t||"helloAck"===t||"ready"===t;if(!ye()&&!r)return se.length>=256?(M("Outbox full"),void(n&&be(n,{code:l,message:"Bridge outbox is full"}))):void se.push({msg:e,reqId:n});n&&ke(n),$(e)}function Se(){null!==ne&&(clearTimeout(ne),ne=null)}function Te(){if(!Q&&ge()){Se();var e={v:2,kind:"hello",nonce:p.nonce||"",role:"view",protocolsSupported:[2]};Z=!0,$(e),ne=setTimeout(function(){if(!Q)if(++ee<3)O("Handshake timeout (".concat(ee,"/").concat(3,"), retrying...")),Z=!1,Te();else{for(M("Handshake failed"),Se(),Z=!1,ee=0;se.length;){var e=se.shift();(null==e?void 0:e.reqId)&&be(e.reqId,{code:r,message:"Bridge handshake failed"})}for(var n=0,t=Array.from(ce.keys());n<t.length;n++){_e(t[n],{code:r,message:"Bridge handshake failed"})}}},1e4)}}function Oe(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Me(e,n,t){void 0===t&&(t=!1);var r=function(e){if(""===e)return[];if(!e.startsWith("/"))throw new Error("Invalid JSON pointer: ".concat(e));return e.split("/").slice(1).map(Oe)}(n);if(0===r.length)return{container:{$root:e},key:"$root"};for(var o=e,i=0;i<r.length-1;i++){var a=r[i];if(Array.isArray(o))o=o[Number(a)];else{if(!o||"object"!=typeof o)throw new Error("Invalid container at ".concat(a));var c=o;if(t&&void 0===c[a]){var l=r[i+1];c[a]=l&&/^\d+$/.test(l)?[]:{}}o=c[a]}}return{container:o,key:r[r.length-1]}}function je(e){fe.forEach(function(n){try{if(!ve.has(n))return ve.set(n,!0),void n(A(ue),{rev:de,initial:!0});n(A(ue),{rev:de,initial:e})}catch(e){O("Subscriber error:",e)}})}function Ae(e){if("function"!=typeof e)return function(){};if(fe.add(e),de>=0){ve.set(e,!0);try{e(A(ue),{rev:de,initial:!0})}catch(e){M("Callback error:",e)}}return function(){fe.delete(e),ve.delete(e)}}function Le(e){We.call("state.getSnapshot",{scope:e}).catch(function(){})}function Ce(e){var n,t;if(e&&"object"==typeof e){var r=e;if("event"===r.type&&"nativecomponent"===r.name&&r.payload){var o=r.payload,c=o.id||o.componentId;if("string"==typeof c){var l=Ne.get(c);if(l)try{l(o)}catch(e){M("NC handler error:",e)}}return}}var s=function(e){if(!e||"object"!=typeof e)return null;var n=e.v,t=e.kind;return 2!==n||"string"!=typeof t?null:e}(e);if(s)switch(s.kind){case"helloAck":return void(K=s.sessionId);case"ready":if(K&&s.sessionId!==K)return void O("sessionId mismatch");if(Se(),Q=!0,ee=0,s.hostMethods)for(var d=0,f=Object.entries(s.hostMethods);d<f.length;d++){var v=f[d],p=v[0],m=v[1];te[p]=m}return S("proto")&&T("Handshake complete, hostMethods:",Object.keys(te).length),void function(){if(ye())for(;se.length;){var e=se.shift();e&&(e.reqId&&ke(e.reqId),$(e.msg))}}();case"res":var h=ae.get(s.id);if(!h)return;if(ae.delete(s.id),null!==h.timerId&&clearTimeout(h.timerId),s.ok){if("state.getSnapshot"===h.method&&(function(e){if(!e||"object"!=typeof e)return!1;var n=e;return!("number"!=typeof n.rev||!Number.isFinite(n.rev)||!n.state||"object"!=typeof n.state||(ue=n.state,de=n.rev,S("data")&&(console.group("[LX] snapshot(res)"),console.log("rev:",de,"state:",A(ue)),console.groupEnd()),je(!0),0))}(s.result)||O("Invalid state.getSnapshot result")),"stream"===h.mode&&h.stream)return void h.stream._resolve(s.result);null===(n=h.resolve)||void 0===n||n.call(h,s.result)}else{var g=u(s.error);if("stream"===h.mode&&h.stream)return void h.stream._reject(g);null===(t=h.reject)||void 0===t||t.call(h,g)}return;case"event":if(ae.has(s.id)){var y=ae.get(s.id);return void("stream"===(null==y?void 0:y.mode)&&y.stream?(Ie(s.id),y.stream._emitData(s.payload)):O("Received event for non-stream request '".concat(s.id,"'")))}return;case"state.snapshot":return ue=s.state||{},de=s.rev,S("data")&&(console.group("[LX] snapshot"),console.log("rev:",de,"state:",A(ue)),console.groupEnd()),void je(!0);case"state.patch":if(s.baseRev!==de)return O("baseRev mismatch",{have:de,want:s.baseRev}),void Le(s.scope);try{!function(e,n){for(var t=0,r=n;t<r.length;t++){var o=r[t],i="add"===o.op||"replace"===o.op,a=Me(e,o.path,i),c=a.container,l=a.key;if("$root"!==l)if(Array.isArray(c)){var s="-"===l?c.length:Number(l);if(!Number.isFinite(s)||s<0)throw new Error("Invalid index");"remove"===o.op?c.splice(s,1):"add"===o.op?c.splice(s,0,o.value):"replace"===o.op&&(c[s]=o.value)}else{if(!c||"object"!=typeof c)throw new Error("Invalid container");var d=c;"remove"===o.op?delete d[l]:d[l]=o.value}else{for(var u=0,f=Object.keys(e);u<f.length;u++)delete e[f[u]];if("remove"!==o.op){var v=o.value;v&&"object"==typeof v&&Object.assign(e,v)}}}}(ue,s.ops||[]),de=s.rev}catch(e){return M("Patch failed:",e),void Le(s.scope)}return S("data")&&(console.group("[LX] patch"),console.log("rev:",de,"ops:",s.ops),console.groupEnd()),je(!1),void(s.ack&&xe({v:2,kind:"state.ack",scope:s.scope,rev:s.rev}));case"ch.ack":if(!(_=ce.get(s.id)))return;if(ce.delete(s.id),null!==_.timerId&&clearTimeout(_.timerId),s.ok)_.channel._markOpen(),le.set(s.id,_.channel),_.resolve(_.channel);else{g=u(s.error);_.channel._reject(g),_.reject(g)}return;case"ch.data":var w=le.get(s.id);if(!w)return;return void w._emitData(s.payload);case"ch.close":var _;if(_=ce.get(s.id))return ce.delete(s.id),void _.channel._emitClose(s.code,s.reason);var b=le.get(s.id);if(!b)return;return le.delete(s.id),void b._emitClose(s.code,s.reason);case"req":var I=s,k=me(I.method);if(!I.cap||I.cap!==k)return void xe({v:2,kind:"res",id:I.id,ok:!1,error:{code:a,message:"Invalid cap for ".concat(I.method)}});var E=pe.get(I.method);return E?void Promise.resolve().then(function(){return E(I.params)}).then(function(e){xe({v:2,kind:"res",id:I.id,ok:!0,result:e})}).catch(function(e){xe({v:2,kind:"res",id:I.id,ok:!1,error:u(e)})}):void xe({v:2,kind:"res",id:I.id,ok:!1,error:{code:i,message:"View handler not found: ".concat(I.method)}})}else O("Invalid V2 message:",e)}var Ne=new Map,Pe=[],Be=!1;function Re(){var e,n,t;return"undefined"!=typeof window&&!(!(null===(n=null===(e=window.webkit)||void 0===e?void 0:e.messageHandlers)||void 0===n?void 0:n.NativeComponent)&&!(null===(t=window.NativeComponentBridge)||void 0===t?void 0:t.postMessage))}function De(e){var n,t,r;try{if(null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===t?void 0:t.NativeComponent)return void window.webkit.messageHandlers.NativeComponent.postMessage(e);if(null===(r=window.NativeComponentBridge)||void 0===r?void 0:r.postMessage)return void window.NativeComponentBridge.postMessage(j(e))}catch(e){M("NativeComponent send error:",e)}}function Xe(){if(Re()&&0!==Pe.length)for(Be=!0;Pe.length;){var e=Pe.shift();try{De(e)}catch(e){break}}}function Ge(e){try{if(!Re())return void Pe.push(e);Be||Xe(),De(e)}catch(e){M("NC send failed:",e)}}function Fe(e){return"".concat(e,"_").concat(Date.now(),"_").concat(re++)}function He(e,n,t){if(n)if(n.aborted)t();else{var r={handleEvent:function(){n.removeEventListener("abort",r),t()}};n.addEventListener("abort",r)}}var qe,Ue,We={call:function(e,n,r){return new Promise(function(i,a){var c;if(e&&"string"==typeof e){Z||Te();var l=Fe("c"),s=(null==r?void 0:r.cap)||me(e),d=null!==(c=null==r?void 0:r.timeoutMs)&&void 0!==c?c:w;ae.set(l,{method:e,mode:"call",resolve:i,reject:function(e){return a(e)},timeoutMs:d,timerId:null}),xe({v:2,kind:"req",id:l,method:e,params:he(n),cap:s},l),He(0,null==r?void 0:r.signal,function(){var e=Ee(l);we(l,{code:t,message:"Bridge request aborted"}),!e&&Q&&xe({v:2,kind:"cancel",id:l})})}else a({code:o,message:"Method name must be a non-empty string"})})},stream:function(e,n,r){var i;if(!e||"string"!=typeof e){var a=ie("invalid",function(){});return a._reject({code:o,message:"Method name must be a non-empty string"}),a}Z||Te();var c=Fe("c"),l=ie(c,function(){Ee(c)?we(c,{code:t,message:"Bridge request aborted"}):Q&&xe({v:2,kind:"cancel",id:c})}),s=(null==r?void 0:r.cap)||me(e),d=null!==(i=null==r?void 0:r.timeoutMs)&&void 0!==i?i:w;return ae.set(c,{method:e,mode:"stream",stream:l,timeoutMs:d,timerId:null}),xe({v:2,kind:"req",id:c,method:e,params:he(n),cap:s},c),He(0,null==r?void 0:r.signal,function(){return l.cancel()}),l},notify:function(e,n,t){e&&"string"==typeof e&&(Z||Te(),xe({v:2,kind:"notify",method:e,params:he(n),cap:(null==t?void 0:t.cap)||me(e)}))},state:{subscribe:Ae},channel:{open:function(e,n,t){return e&&"string"==typeof e?(Z||Te(),new Promise(function(r,o){var i=Fe("ch"),a=function(e,n,t){var r,o=oe(),i=!1,a=0,c=!1,l=[],d=[],u=((r={id:e,send:function(t){i?n(t,a++):u._reject({code:s,message:"Channel '".concat(e,"' is closed")})},on:function(e,n){return"data"===e&&o.data.add(n),"close"===e&&o.close.add(n),"error"===e&&o.error.add(n),this}})[Symbol.asyncIterator]=function(){return{next:function(){return l.length>0?Promise.resolve({done:!1,value:l.shift()}):c?Promise.resolve({done:!0,value:void 0}):new Promise(function(e,n){d.push({resolve:e,reject:n})})}}},r.close=function(e,n){i&&(i=!1,c=!0,t(e,n),u._emitClose(e,n))},r._emitData=function(e){if(i){d.length>0?d.shift().resolve({done:!1,value:e}):l.push(e);for(var n=0,t=o.data;n<t.length;n++){var r=t[n];try{r(e)}catch(e){O("Channel listener failed:",e)}}}},r._emitClose=function(e,n){for(c=!0;d.length>0;)d.shift().resolve({done:!0,value:void 0});for(var t=0,r=o.close;t<r.length;t++){var i=r[t];try{i(e,n)}catch(e){O("Channel close listener failed:",e)}}},r._reject=function(e){for(c=!0;d.length>0;)d.shift().reject(e);for(var n=0,t=o.error;n<t.length;n++){var r=t[n];try{r(e)}catch(e){O("Channel error listener failed:",e)}}},r._markOpen=function(){i=!0,c=!1},r._isOpen=function(){return i},r._nextSeq=function(){return a++},r);return u}(i,function(e,n){xe({v:2,kind:"ch.data",id:i,seq:n,payload:e})},function(e,n){var t=ce.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),ce.delete(i),le.delete(i),xe({v:2,kind:"ch.close",id:i,code:e,reason:n})});ce.set(i,{topic:e,channel:a,resolve:r,reject:o,timerId:null}),xe({v:2,kind:"ch.open",id:i,topic:e,params:he(n),cap:(null==t?void 0:t.cap)||me(e)},i)})):Promise.reject({code:o,message:"Topic name must be a non-empty string"})}}},ze={invoke:function(e,n,t){return We.call(Je(e),n,Ye(t)).then(function(e){return e}).catch(function(e){return Promise.reject(f(e))})},notify:function(e,n,t){We.notify(Je(e),n,Ye(t))},stream:function(e,n,t){return Ve(We.stream(Je(e),n,Ye(t)))},channel:function(e,n,t){return We.channel.open(Je(e),n,Ye(t)).then(function(e){return function(e){var n=new Set,t=new Set;return e.on("data",function(e){for(var t=0,r=n;t<r.length;t++){(0,r[t])(e)}}),e.on("close",function(e,n){for(var r={code:e,reason:n},o=0,i=t;o<i.length;o++){(0,i[o])(r)}}),{send:function(n){e.send(n)},onMessage:function(e){return n.add(e),function(){n.delete(e)}},onClose:function(e){return t.add(e),function(){t.delete(e)}},close:function(n,t){e.close(n,t)}}}(e)}).catch(function(e){return Promise.reject(f(e))})},raw:We,state:{subscribe:Ae},_connectWebMessagePort:function(e){if(N===b){if(P&&P!==e)try{P.onmessage=null,P.close()}catch(e){}P=e,e.onmessage=function(e){var n=e.data;if("string"==typeof n)try{n=JSON.parse(n)}catch(e){return}Ce(n)};try{e.start()}catch(e){}T("Port connected"),Te()}},_receiveEvaluateMessage:function(e){try{e&&Ce(JSON.parse(e))}catch(e){M("Parse error:",e)}},debug:(qe=E,Ue={},Object.keys(qe).forEach(function(e){Object.defineProperty(Ue,e,{enumerable:!0,configurable:!1,get:function(){return qe[e]},set:function(n){qe[e]=!!n,console.log("[LX] ".concat(e,": ").concat(n))}})}),Ue),platform:{isHarmony:function(){return"Harmony"===p.os},isIOS:h,isAndroid:function(){return"Android"===p.os},isMacOS:g,isDesktop:function(){return g()},getOS:m},dom:{measureById:function(e){try{if(!e)return null;var n=document.getElementById(e);if(!n)return null;var t=n.getBoundingClientRect(),r=0;try{r=parseFloat(getComputedStyle(n).borderRadius)||0}catch(e){}return[t.left+window.scrollX,t.top+window.scrollY,t.width,t.height,r]}catch(e){return null}}},nativeComponents:{send:Ge,hasHandler:Re,flush:Xe,register:function(e,n){return e&&"function"==typeof n?(Ne.set(e,n),function(){return Ne.delete(e)}):function(){}},unregister:function(e){Ne.delete(e)}},isReady:function(){return Q}};function Je(e){return e.startsWith("host.")?e:"host.".concat(e)}function Ye(e){return __assign(__assign({},e||{}),{cap:(null==e?void 0:e.cap)||"host"})}function Ve(e){var n=new Set,t=new Set;return e.on("data",function(e){for(var t=0,r=n;t<r.length;t++){(0,r[t])(e)}}),e.on("error",function(e){for(var n=f(e),r=0,o=t;r<o.length;r++){(0,o[r])(n)}}),{onEvent:function(e){return n.add(e),function(){n.delete(e)}},onError:function(e){return t.add(e),function(){t.delete(e)}},result:e.result.catch(function(e){return Promise.reject(f(e))}),cancel:function(){e.cancel()}}}function $e(){if(window.__LX_BRIDGE_INIT_STATE)T("Bridge already ".concat(window.__LX_BRIDGE_INIT_STATE,", skipping duplicate init"));else{window.__LX_BRIDGE_INIT_STATE="initializing";try{T("Method: ".concat(N)),function(e){if("undefined"!=typeof window&&(window[y]=e,0!==x.length))for(var n=0,t=x.splice(0,x.length);n<t.length;n++){var r=t[n];try{e(r)}catch(e){O("Failed to replay queued native message:",e)}}}(ze._receiveEvaluateMessage),W()?V():N===b?(q(),function(){var e,n;if(P)return Promise.resolve(P);if(F.promise)return F.promise;q(),F.promise=new Promise(function(e,n){F.resolve=function(n){U(),e(n)},F.reject=function(e){U(),n(e)},F.timer=window.setTimeout(function(){var e;null===(e=F.reject)||void 0===e||e.call(F,new Error("MessagePort init timed out after ".concat(5e3,"ms")))},5e3)});try{null===(e=window.LingXiaProxy)||void 0===e||e.getPort("LingXiaPort")}catch(e){null===(n=F.reject)||void 0===n||n.call(F,e)}return F.promise}().catch(function(e){return O("Port init failed:",e)})):"webkit"===N||N===I?Te():O("Unknown method"),window.LingXiaBridge=ze,v({os:m(),send:Ge}),window.__LX_BRIDGE_INIT_STATE="initialized",T("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}}}function Ke(e){var n=document.createElement("div");return n.textContent=e,n.innerHTML}function Qe(e){var n=e.failedPath,t=e.reason,r=document.createElement("style");r.textContent="\n* { margin: 0; padding: 0; box-sizing: border-box; }\nbody {\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n background: #f5f5f7;\n color: #1d1d1f;\n padding: 20px;\n -webkit-font-smoothing: antialiased;\n}\n.lx-error {\n text-align: center;\n max-width: 400px;\n}\n.lx-error-code {\n font-size: 120px;\n font-weight: 700;\n color: #d1d1d6;\n line-height: 1;\n letter-spacing: -4px;\n}\n.lx-error-title {\n font-size: 21px;\n font-weight: 600;\n margin: 16px 0 8px;\n color: #1d1d1f;\n}\n.lx-error-desc {\n font-size: 15px;\n color: #86868b;\n line-height: 1.5;\n}\n.lx-error-path {\n display: inline-block;\n margin-top: 20px;\n padding: 10px 16px;\n background: rgba(0,0,0,0.04);\n border-radius: 8px;\n font-family: 'SF Mono', ui-monospace, Menlo, Monaco, monospace;\n font-size: 13px;\n color: #1d1d1f;\n word-break: break-all;\n max-width: 100%;\n}\n@media (prefers-color-scheme: dark) {\n body { background: #000; color: #f5f5f7; }\n .lx-error-code { color: #3a3a3c; }\n .lx-error-title { color: #f5f5f7; }\n .lx-error-desc { color: #86868b; }\n .lx-error-path { background: rgba(255,255,255,0.08); color: #f5f5f7; }\n}\n",document.head.appendChild(r),document.body.innerHTML="",document.body.style.cssText="";var o=document.createElement("div");o.className="lx-error";var i='<div class="lx-error-code">404</div>';i+='<h1 class="lx-error-title">Page Not Found</h1>',i+="<p class=\"lx-error-desc\">The page you're looking for doesn't exist.</p>",n&&(i+='<div class="lx-error-path">'.concat(Ke(n),"</div>")),t&&(i+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Ke(t),"</p>")),o.innerHTML=i,document.body.appendChild(o)}function Ze(){var e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function en(){var e;return(null===(e=window.__LX_RUNTIME_CONFIG)||void 0===e?void 0:e.error)||null}var nn={handleEvent:function(){return tn()}};function tn(){if(Ze()){var e=en();e&&Qe(e)}}function rn(){$e(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",nn):tn()}return rn(),e.LingXiaBridge=ze,e.boot=function(){$e(),tn()},e.bootWhenReady=rn,e.channel=function(e,n,t){return ze.channel(e,n,t)},e.getErrorInfo=en,e.hasError=Ze,e.initBridge=$e,e.invoke=function(e,n,t){return ze.invoke(e,n,t)},e.isNativeError=function(e,n){if(!e||"object"!=typeof e)return!1;var t=e;return"string"==typeof t.code&&""!==t.code.trim()&&("string"==typeof t.message&&(void 0===n||t.code===n))},e.notify=function(e,n,t){We.notify(Je(e),n,Ye(t))},e.renderErrorUI=Qe,e.stream=function(e,n,t){return Ve(We.stream(Je(e),n,Ye(t)))},e}({});
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@lingxia/bridge",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "description": "LingXia Web Runtime - Bridge, boot, and error handling for WebView",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/LingXia-Dev/LingXia.git",
9
+ "directory": "packages/lingxia-bridge"
10
+ },
6
11
  "type": "module",
7
12
  "main": "dist/es2020/index.js",
8
13
  "types": "dist/index.d.ts",