@lingxia/bridge 0.20.1 → 0.21.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.
- package/dist/bridge-runtime.es2020.js +1 -1
- package/dist/bridge-runtime.es5.js +1 -1
- package/dist/es2020/bridge.js +5 -0
- package/dist/es2020/index.js +1 -0
- package/dist/es2020/leave-guard.js +117 -0
- package/dist/es5/bridge.js +5 -0
- package/dist/es5/index.js +1 -0
- package/dist/es5/leave-guard.js +117 -0
- package/dist/index.d.ts +2 -0
- package/dist/leave-guard.d.ts +36 -0
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const __LX_RUNTIME_PLATFORM__="all";var __LingXiaBridgeBundle=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const n="BRIDGE_TIMEOUT",t="BRIDGE_CANCELED",o="BRIDGE_HANDSHAKE_FAILED",r="BRIDGE_MALFORMED_MESSAGE",i="BRIDGE_METHOD_NOT_FOUND",s="BRIDGE_CAPABILITY_DENIED",a="BRIDGE_INTERNAL_ERROR",l="BRIDGE_OUTBOX_FULL",c="BRIDGE_STREAM_CLOSED",d="BRIDGE_MESSAGE_TOO_LARGE";var u=class extends Error{constructor(e,n,t){super(n),this.name="BridgeInvocationError",this.code=e,this.data=t}};function f(e){if(e instanceof u)return e;if(e&&"object"==typeof e){const n=e;let t=a;("string"==typeof n.code&&""!==n.code.trim()||"number"==typeof n.code&&Number.isFinite(n.code))&&(t=n.code);const o="string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error";return new u(t,o,"data"in n?n.data:void 0)}const n=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new u(a,n)}function m(e){const n=f(e);return{code:String(n.code||a),message:"string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error",...void 0===n.data?{}:{data:n.data}}}function p({os:e,send:n}){if("undefined"==typeof window)return;if("undefined"==typeof document)return;const t="iOS"===e;if(!t&&"Android"!==e)return;const o=Symbol.for("LingXia.NativeComponentCoverageMonitor");if(window[o]?.installed)return;const r={installed:!0,coveredById:new Map,coveredCount:0,anyCovered:!1,scheduled:!1,hasAnyVideo:!1,scrollLocked:!1,scrollY:0,htmlOverflow:"",bodyOverflow:"",bodyPosition:"",bodyTop:"",bodyWidth:""};function i(e){const n=e.getBoundingClientRect?.();if(!n)return!1;if(n.width<2||n.height<2)return!1;const t=n.left+n.width/2,o=n.top+n.height/2;if(t<0||o<0||t>=window.innerWidth||o>=window.innerHeight)return!1;const r=document.elementFromPoint?.(t,o);return!!r&&(r!==document.documentElement&&r!==document.body&&!(r===e||e.contains(r)))}function s(){r.scheduled=!1;const e=document.querySelectorAll("lx-video[id]");if(r.hasAnyVideo=e.length>0,!r.hasAnyVideo&&0===r.coveredById.size&&!r.anyCovered)return;const o=new Set;for(const t of Array.from(e)){const e=t.id;if(!e)continue;o.add(e);const s=i(t),a=r.coveredById.get(e);a!==s&&(!0===a&&(r.coveredCount-=1),!0===s&&(r.coveredCount+=1),r.coveredById.set(e,s),n({id:e,action:"component.coverage",covered:s}))}const s=[];for(const[e,n]of r.coveredById.entries())o.has(e)||(s.push(e),!0===n&&(r.coveredCount-=1));for(const e of s)r.coveredById.delete(e),n({id:e,action:"component.coverage",covered:!1});const a=r.coveredCount>0;a!==r.anyCovered&&(r.anyCovered=a,t&&(a?function(){if(!t)return;if(r.scrollLocked)return;const e=document.documentElement,n=document.body;e&&n&&(r.scrollLocked=!0,r.scrollY=window.scrollY||e.scrollTop||0,r.htmlOverflow=e.style.overflow||"",r.bodyOverflow=n.style.overflow||"",r.bodyPosition=n.style.position||"",r.bodyTop=n.style.top||"",r.bodyWidth=n.style.width||"",e.style.overflow="hidden",n.style.overflow="hidden",n.style.position="fixed",n.style.top=-r.scrollY+"px",n.style.width="100%")}():function(){if(!t)return;if(!r.scrollLocked)return;const e=document.documentElement,n=document.body;e&&n&&(r.scrollLocked=!1,e.style.overflow=r.htmlOverflow,n.style.overflow=r.bodyOverflow,n.style.position=r.bodyPosition,n.style.top=r.bodyTop,n.style.width=r.bodyWidth,window.scrollTo(0,r.scrollY))}()))}function a(){r.scheduled||(r.scheduled=!0,requestAnimationFrame(s))}window[o]=r,new MutationObserver(a).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0});const l={handleEvent:()=>{(r.hasAnyVideo||0!==r.coveredById.size)&&a()}},c={handleEvent:()=>a()};window.addEventListener("scroll",l,{capture:!0,passive:!0}),window.addEventListener("resize",c),a()}const h=new Set(["hello","req","res","notify","cancel","ch.open","ch.data","ch.close","state.ack","console"]),g=new Set(["helloAck","ready","req","res","event","state.snapshot","state.patch","ch.ack","ch.data","ch.close"]);function v(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function y(e){if(!v(e)||"string"!=typeof e.sessionId||0===e.sessionId.length||"string"!=typeof e.secret||0===e.secret.length)return{ok:!1,error:"INVALID_DOCUMENT_BINDING"};const{sessionId:n,secret:t}=e;return{ok:!0,value:{encode:(e,o)=>h.has(e)&&v(o)?["v","kind","sessionId","secret"].some(e=>e in o)?{ok:!1,error:"SECURITY_FIELD_IN_PAYLOAD"}:{ok:!0,value:{...o,v:3,kind:e,sessionId:n,secret:t}}:{ok:!1,error:"INVALID_DOCUMENT_PAYLOAD"},parse(e,t=65536){if((new TextEncoder).encode(e).byteLength>t)return{ok:!1,error:"FRAME_TOO_LARGE"};if(function(e){const n=new Set(["v","kind","sessionId","secret"]),t=new Set;let o=0;for(let r=0;r<e.length;r++){const i=e[r];if("{"===i||"["===i){o++;continue}if("}"===i||"]"===i){o--;continue}if('"'!==i)continue;const s=r;for(r++;r<e.length;)if("\\"!==e[r]){if('"'===e[r])break;r++}else r+=2;if(r>=e.length)return!1;if(1!==o)continue;let a,l=r+1;for(;/\s/.test(e[l]??"");)l++;if(":"===e[l]){try{a=JSON.parse(e.slice(s,r+1))}catch{return!1}if("string"==typeof a&&n.has(a)){if(t.has(a))return!0;t.add(a)}}}return!1}(e))return{ok:!1,error:"MALFORMED_ENVELOPE"};let o;try{o=JSON.parse(e)}catch{return{ok:!1,error:"MALFORMED_ENVELOPE"}}if(!v(o))return{ok:!1,error:"MALFORMED_ENVELOPE"};if(3!==o.v)return{ok:!1,error:"UNSUPPORTED_VERSION"};if("string"!=typeof o.kind||!g.has(o.kind))return{ok:!1,error:"UNSUPPORTED_NATIVE_KIND"};if("string"!=typeof o.sessionId||0===o.sessionId.length)return{ok:!1,error:"MALFORMED_ENVELOPE"};if(o.sessionId!==n)return{ok:!1,error:"SESSION_MISMATCH"};if(Object.prototype.hasOwnProperty.call(o,"secret"))return{ok:!1,error:"UNEXPECTED_SECRET"};const{v:r,kind:i,sessionId:s,...a}=o;return{ok:!0,value:{kind:o.kind,payload:a}}}}}}const w="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{},b={value:w.displayLanguage?.trim()||"en-US",listeners:new Set};function x(){return"undefined"==typeof window?b:(window.__lxDisplayLanguage||(window.__lxDisplayLanguage={value:w.displayLanguage?.trim()||"en-US",listeners:new Set}),window.__lxDisplayLanguage)}const k=new Set(["ar","ckb","dv","fa","he","ps","sd","ug","ur","yi"]);function E(){if("undefined"!=typeof document&&document.documentElement){const e=x().value;document.documentElement.lang=e,document.documentElement.dir=function(e){try{const n=new Intl.Locale(e),t="function"==typeof n.getTextInfo?n.getTextInfo():n.textInfo;if("rtl"===t?.direction||"ltr"===t?.direction)return t.direction}catch{}return k.has(e.split(/[-_]/)[0].toLowerCase())?"rtl":"ltr"}(e)}}function _(){return w.os||"unknown"}function I(){return"mobile"===w.hostClass||"desktop"===w.hostClass?w.hostClass:"macOS"===w.os||"Windows"===w.os?"desktop":"mobile"}function C(){return"iOS"===w.os}function L(){return"macOS"===w.os}function S(){return"desktop"===I()}E(),"undefined"==typeof window||window.__lingxiaApplyDisplayLanguage||Object.defineProperty(window,"__lingxiaApplyDisplayLanguage",{configurable:!1,enumerable:!1,value:function(e,n){const t="string"==typeof e?e.trim():"",o=x();if("number"==typeof n&&Number.isFinite(n)){if(n<=(o.revision??0))return;o.revision=n}if(t&&t!==o.value){o.value=t,E();for(const e of[...o.listeners])e(t)}}});const T={sizeClass:"compact",width:0,height:0,aside:!1};function N(){if("undefined"==typeof window)return A;if(!window.__lxSurfaceContext){const e=window.__LX_BRIDGE_CFG;window.__lxSurfaceContext={value:M(e?.surfaceContext)??T,revision:"number"==typeof e?.surfaceContextRevision?e.surfaceContextRevision:0,listeners:new Set}}return window.__lxSurfaceContext}const A={value:T,revision:0,listeners:new Set};function M(e){if("object"!=typeof e||null===e)return null;const{sizeClass:n,width:t,height:o,aside:r}=e;return"compact"!==n&&"regular"!==n||"number"!=typeof t||"number"!=typeof o?null:{sizeClass:n,width:t,height:o,aside:!0===r}}"undefined"==typeof window||window.__lingxiaApplySurfaceContext||Object.defineProperty(window,"__lingxiaApplySurfaceContext",{configurable:!1,enumerable:!1,value:function(e,n){const t=M(e),o=N();if(t){if("number"==typeof n){if(n<=o.revision)return;o.revision=n}if(r=o.value,i=t,r.sizeClass!==i.sizeClass||r.width!==i.width||r.height!==i.height||r.aside!==i.aside){var r,i;o.value=t;for(const e of[...o.listeners])e()}}}});let O=null;function P(){const e=N().value;return{sizeClass:e.sizeClass,aside:e.aside,displayLanguage:x().value,formFactor:S()?"desktop":"mobile",os:_(),runner:!0===w.runner}}function D(){const e=P();var n,t;return null!==O&&(t=e,(n=O).sizeClass===t.sizeClass&&n.aside===t.aside&&n.displayLanguage===t.displayLanguage&&n.formFactor===t.formFactor&&n.os===t.os&&n.runner===t.runner)||(O=e),O}function B(e){let n=D();const t=()=>{const t=D();t!==n&&(n=t,e())},o=function(e){const n=x().listeners;return n.add(e),()=>{n.delete(e)}}(t),r=function(e){const n=N().listeners;return n.add(e),()=>{n.delete(e)}}(t);return()=>{o(),r()}}const R="__LingXiaRecvMessage",j=5e3,F="[LX.Bridge]",$="messageport",X="jsinterface",q="webmessage",z=w.appleDownstreamURL,U={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:(console.info||console.log).bind(console),debug:(console.debug||console.log).bind(console),group:(console.group||console.log).bind(console),groupEnd:(console.groupEnd||(()=>{})).bind(console)},G={data:!1,proto:!1,all:!1},H=[];let W={kind:"v2"},V=!1;function J(){if("undefined"==typeof window)return;const e=window.__LingXiaEarlyNativeMessages;if(Array.isArray(e)&&0!==e.length){window.__LingXiaEarlyNativeMessages=[];for(const n of e)"string"==typeof n&&H.push(n)}}function Y(e){if(J(),0===H.length)return;const n=H.splice(0,H.length);for(const t of n)try{e(t)}catch(e){Z("Failed to replay queued native message:",e)}}function K(e){return G.all||G[e]}function Q(...e){(!0===w.dev||G.all||G.proto||G.data)&&U.log(F,...e)}function Z(...e){U.warn(F,...e)}function ee(...e){U.error(F,...e)}function ne(e){try{return JSON.stringify(e)}catch{return function(e,n){const t=new WeakSet;return JSON.stringify(e,(e,n)=>{if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},n)}(e)}}function te(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch{return{}}}const oe="iOS"===w.os||"macOS"===w.os?"webkit":"Harmony"===w.os?"messageport":"Windows"===w.os?"webmessage":"Android"===w.os?window.LingXiaProxy?.supportsMessagePort?.()?"messageport":"jsinterface":"unknown";!function(){if("undefined"==typeof window)return;J();const e=window[R];if("function"==typeof e){if(0===H.length)return;const n=H.splice(0,H.length);for(const t of n)try{e(t)}catch(e){Z("Failed to replay queued native message:",e)}return}window[R]=e=>{H.push(e)}}();let re=null,ie=!1,se=null,ae=null,le=null,ce=200,de=!1,ue=0;let fe=0,me=0;const pe=`${Date.now().toString(36)}${Math.random().toString(36).slice(2,10)}`;let he=null;const ge={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},ve={handleEvent:e=>{const n=e;if("LingXia-port-init"!==n.data)return;const t=n.ports?.[0];t&&(Sn._connectWebMessagePort(t),ge.resolve?.(t))}};function ye(){ge.listenerInstalled||(ge.listenerInstalled=!0,window.addEventListener("message",ve))}function we(){null!==ge.timer&&(window.clearTimeout(ge.timer),ge.timer=null),ge.resolve=null,ge.reject=null,ge.promise=null}function be(){return"webkit"===oe&&(C()||L())}function xe(){null!==le&&(clearTimeout(le),le=null)}function ke(e){be()&&!de&&(de=!0,xe(),null!==he&&(clearInterval(he),he=null),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",Ne),Se=!1,ae?.abort(),ie=!1,_e(e,!0))}function Ee(e){for(const n of Array.from(qe.keys()))tn(n,{code:c,message:e});for(const n of Array.from(ze.keys()))on(n,{code:c,message:e});!function(e){for(const[n,t]of Array.from(Ue.entries()))Ue.delete(n),t._emitClose(c,e)}(e)}function _e(e,n){dn(),"required-v3"!==W.kind&&(Oe=null),Pe=!1,De=!1,Be=!1,Re=0,n&&Ee(e)}function Ie(e){let n=e;for(;;){const e=n.indexOf("\n");if(e<0)break;const t=n.slice(0,e).trim();if(n=n.slice(e+1),t)try{Ce(JSON.parse(t))}catch(e){Z("Apple downstream parse error:",e,t)}}return n}function Ce(e){if(!e||"object"!=typeof e)return;fe=Date.now();const n=e;if(!0!==n.lxshutdown){if(void 0===n.lxhb){if(!0===n.lxreset)return ue=0,_e("Apple downstream reset",!0),void un();if("number"==typeof n.lxff){if(n.lxff<=ue)return;return ue=n.lxff,void vn(n.m)}vn(e)}}else ke("Apple downstream closed")}function Le(){if(!be()||de)return;if(se)return;xe();let e=!1;se=async function(){if(!z)throw new Error("Apple downstream URL is not configured");const e=new AbortController;ae=e;const n=z.includes("?")?"&":"?",t=`${z}${n}from=${ue}&doc=${pe}`;me=Date.now();const o=await fetch(t,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal});if(!o.ok)throw new Error(`Apple downstream HTTP ${o.status}`);if("1"===o.headers.get("X-LingXia-Bridge-Shutdown"))return void ke("Apple downstream closed");if(!o.body)throw new Error("Apple downstream response body unavailable");ie=!0,ce=200,fe=Date.now(),K("proto")&&Q("Apple downstream connected"),un();const r=o.body.getReader(),i=new TextDecoder;let s="";try{for(;;){const{value:e,done:n}=await r.read();if(n)break;s+=i.decode(e,{stream:!0}),s=Ie(s)}s+=i.decode();const e=s.trim();if(e)try{Ce(JSON.parse(e))}catch(n){Z("Apple downstream trailing parse error:",n,e)}}catch(n){if(e.signal.aborted)return;throw n}finally{try{r.releaseLock()}catch{}}}().then(()=>{e=!0}).catch(e=>{ae?.signal.aborted||Z("Apple downstream failed:",e)}).finally(()=>{const n=ae?.signal.aborted??!1;se=null,ae=null,ie=!1,n||de||function(e,n=!1){if(!be()||de)return;xe();const t=n?0:ce;n||(ce=Math.min(2*ce,2e3));const o=n?`Apple downstream completed, reconnecting immediately: ${e}`:`Apple downstream disconnected, retrying in ${t}ms: ${e}`;t<=200?Q(o):Z(o),le=setTimeout(()=>{le=null,Le()},t)}("stream closed",e)})}let Se=!1;function Te(){if(!be()||de)return;if(Se)return;Se=!0;const e=se;ae?.abort();const n=()=>{Se=!1,Le()};e?e.finally(n):n()}function Ne(){"visible"===document.visibilityState&&Te()}function Ae(e){const n=function(e){if("blocked"===W.kind)return null;if("v2"===W.kind)return e;if(!e||"object"!=typeof e)return null;const{v:n,kind:t,...o}=e;if("string"!=typeof t)return null;const r=W.codec.encode(t,o);return r.ok?r.value:null}(e);if(!n)return null;const t=e.kind;"req"!==t&&"notify"!==t||Q(`postToNative: ${t} ${e.method}`),K("proto")&&U.log("→",JSON.stringify(e,null,2));try{const e=ne(n),t=function(e){if("function"==typeof TextEncoder)return(new TextEncoder).encode(e).length;let n=0;for(let t=0;t<e.length;t+=1){const o=e.charCodeAt(t);o<128?n+=1:o<2048?n+=2:o>=55296&&o<=56319?(n+=4,t+=1):n+=3}return n}(e);if(t>65536)return{code:d,message:`Bridge message of ${t} bytes exceeds the 65536-byte native limit`};if("webkit"===oe)return window.webkit?.messageHandlers.LingXia?.postMessage(e),null;if(oe===$&&re)return re.postMessage(e),null;if((oe===X||oe===q)&&window.LingXiaProxy?.postMessage)return window.LingXiaProxy.postMessage(e),null;Z("Transport not ready")}catch(e){"required-v3"===W.kind?ee("Send error"):ee("Send error:",e)}return null}function Me(e){const n=e.map(e=>{if("string"==typeof e)return e;try{const n=ne(e);return"string"==typeof n?n:String(e)}catch{return"[Unserializable]"}}).join(" ");return n.length<=12288?n:`${n.slice(0,12288)}…`}let Oe=null,Pe=!1,De=!1,Be=!1,Re=0,je=null,Fe=0;function $e(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function Xe(e,n){const t=$e();let o=!1,r=!1,i=()=>{},s=()=>{};const a=[],l=[],c=new Promise((e,n)=>{i=e,s=n}),d={id:e,result:c,on(e,n){return"data"===e&&t.data.add(n),"end"===e&&t.end.add(n),"error"===e&&t.error.add(n),this},[Symbol.asyncIterator]:()=>(r=!0,{next:()=>a.length>0?Promise.resolve({done:!1,value:a.shift()}):o?c.then(e=>({done:!0,value:e}),e=>Promise.reject(e)):new Promise((e,n)=>{l.push({resolve:e,reject:n})}),return:()=>(r=!1,a.length=0,c.catch(()=>{}),d.cancel(),Promise.resolve({done:!0,value:void 0}))}),cancel(){o||n()},_emitData(e){if(!o){l.length>0?l.shift().resolve({done:!1,value:e}):r&&a.push(e);for(const n of t.data)try{n(e)}catch(e){Z("Stream data listener failed:",e)}}},_resolve(e){if(!o){for(o=!0,i(e);l.length>0;)l.shift().resolve({done:!0,value:e});for(const n of t.end)try{n(e)}catch(e){Z("Stream end listener failed:",e)}}},_reject(e){if(!o){for(o=!0,s(e);l.length>0;)l.shift().reject(e);for(const n of t.error)try{n(e)}catch(e){Z("Stream error listener failed:",e)}}}};return d}const qe=new Map,ze=new Map,Ue=new Map,Ge=[];let He=-1,We={};const Ve=new Set,Je=new WeakMap,Ye=new Map;function Ke(e,n){Ye.set(e,n)}function Qe(e){if(e.startsWith("host."))return"host";const n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function Ze(e){if(null!=e)return e}function en(){return oe===$?!!re:be()?ie:"webkit"===oe||oe===X||oe===q}function nn(){return!!De&&(!!be()||en())}function tn(e,n){const t=qe.get(e);if(t){qe.delete(e),null!==t.timerId&&clearTimeout(t.timerId);const o=f(n);if("stream"===t.mode&&t.stream)return void t.stream._reject(o);t.reject?.(o)}}function on(e,n){const t=ze.get(e);if(!t)return;ze.delete(e),null!==t.timerId&&clearTimeout(t.timerId);const o=f(n);t.channel._reject(o),t.reject(o)}function rn(e,n){qe.has(e)?tn(e,n):ze.has(e)&&on(e,n)}function sn(e){qe.has(e)?function(e){const t=qe.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(()=>{qe.has(e)&&tn(e,{code:n,message:`'${t.method}' timed out`})},t.timeoutMs)))}(e):ze.has(e)&&function(e){const t=ze.get(e);t&&(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(()=>{on(e,{code:n,message:`Channel '${t.topic}' timed out`})},j))}(e)}function an(e){for(let n=Ge.length-1;n>=0;n--)if(Ge[n]?.reqId===e)return Ge.splice(n,1),!0;return!1}function ln(e,n){const t=e.kind,o="hello"===t||"helloAck"===t||"ready"===t;if(!nn()&&!o)return Ge.length>=256?(ee("Outbox full"),void(n&&rn(n,{code:l,message:"Bridge outbox is full"}))):void Ge.push({msg:e,reqId:n});n&&sn(n),cn(Ae(e),n)}function cn(e,n){e&&(ee(e.message),n&&rn(n,e))}function dn(){null!==je&&(clearTimeout(je),je=null)}function un(){if(De)return;if(!V)return;if("blocked"===W.kind)return;if(!en())return;dn();const e={v:2,kind:"hello",nonce:w.nonce||"",role:"view",protocolsSupported:"required-v3"===W.kind?[3]:[2]};Be=!0,Ae(e),je=setTimeout(()=>{if(!De)if(Re++,Re<3)Z(`Handshake timeout (${Re}/3), retrying...`),Be=!1,un();else{for(ee("Handshake failed"),dn(),Be=!1,Re=0;Ge.length;){const e=Ge.shift();e?.reqId&&rn(e.reqId,{code:o,message:"Bridge handshake failed"})}for(const e of Array.from(ze.keys()))on(e,{code:o,message:"Bridge handshake failed"})}},1e4)}function fn(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function mn(e,n,t=!1){const o=function(e){if(""===e)return[];if(!e.startsWith("/"))throw new Error(`Invalid JSON pointer: ${e}`);return e.split("/").slice(1).map(fn)}(n);if(0===o.length)return{container:{$root:e},key:"$root"};let r=e;for(let e=0;e<o.length-1;e++){const n=o[e];if(Array.isArray(r))r=r[Number(n)];else{if(!r||"object"!=typeof r)throw new Error(`Invalid container at ${n}`);{const i=r;if(t&&void 0===i[n]){const t=o[e+1];i[n]=t&&/^\d+$/.test(t)?[]:{}}r=i[n]}}}return{container:r,key:o[o.length-1]}}function pn(e){Ve.forEach(n=>{try{if(!Je.has(n))return Je.set(n,!0),void n(te(We),{rev:He,initial:!0});n(te(We),{rev:He,initial:e})}catch(e){Z("Subscriber error:",e)}})}function hn(e){if("function"!=typeof e)return()=>{};if(Ve.add(e),He>=0){Je.set(e,!0);try{e(te(We),{rev:He,initial:!0})}catch(e){ee("Callback error:",e)}}return()=>{Ve.delete(e),Je.delete(e)}}function gn(e){Ln.call("state.getSnapshot",{scope:e}).catch(()=>{})}function vn(e){let n=e;if("v2"===W.kind&&"string"==typeof n)try{n=JSON.parse(n)}catch{n=null}if("v2"===W.kind&&n&&"object"==typeof n){const e=n;if("event"===e.type&&"nativecomponent"===e.name&&e.payload){const n=e.payload,t=n.id||n.componentId;if("string"==typeof t){const e=yn.get(t);if(e)try{e(n)}catch(e){ee("NC handler error:",e)}}return}}const t=function(e){if("blocked"===W.kind)return null;if("required-v3"===W.kind){const n="string"==typeof e?e:ne(e),t=W.codec.parse(n);return t.ok?{v:3,kind:t.value.kind,...t.value.payload}:null}if("string"==typeof e)try{e=JSON.parse(e)}catch{return null}if(!e||"object"!=typeof e)return null;const n=e.v,t=e.kind;return 2!==n||"string"!=typeof t?null:e}(n);if(t)switch(t.kind){case"helloAck":return t.protocol!==("required-v3"===W.kind?3:2)||t.nonce!==(w.nonce||"")?void Z("Invalid helloAck"):"required-v3"===W.kind?void(Pe=!0):Oe&&t.sessionId!==Oe?void Z("sessionId mismatch"):(Oe||(Oe=t.sessionId),void(Pe=!0));case"ready":if(!Pe)return;return"v2"===W.kind&&Oe&&t.sessionId!==Oe?void Z("sessionId mismatch"):(dn(),De=!0,Re=0,K("proto")&&Q("Handshake complete, host routes:",Object.keys(t.hostMethods||{}).length+(t.hostChannels||[]).length),void function(){if(nn())for(;Ge.length;){const e=Ge.shift();e&&(e.reqId&&sn(e.reqId),cn(Ae(e.msg),e.reqId))}}());case"res":{const e=qe.get(t.id);if(!e)return;if(qe.delete(t.id),null!==e.timerId&&clearTimeout(e.timerId),t.ok){if("state.getSnapshot"===e.method&&(function(e){if(!e||"object"!=typeof e)return!1;const n=e;return!("number"!=typeof n.rev||!Number.isFinite(n.rev)||!n.state||"object"!=typeof n.state||(We=n.state,He=n.rev,K("data")&&(U.group("[LX] snapshot(res)"),U.log("rev:",He,"state:",te(We)),U.groupEnd()),pn(!0),0))}(t.result)||Z("Invalid state.getSnapshot result")),"stream"===e.mode&&e.stream)return void e.stream._resolve(t.result);e.resolve?.(t.result)}else{const n=f(t.error);if("stream"===e.mode&&e.stream)return void e.stream._reject(n);e.reject?.(n)}return}case"event":if(qe.has(t.id)){const e=qe.get(t.id);return void("stream"===e?.mode&&e.stream?(null!==e.timerId&&(clearTimeout(e.timerId),e.timerId=null),e.timeoutMs=0,e.stream._emitData(t.payload)):Z(`Received event for non-stream request '${t.id}'`))}return;case"state.snapshot":return We=t.state||{},He=t.rev,K("data")&&(U.group("[LX] snapshot"),U.log("rev:",He,"state:",te(We)),U.groupEnd()),void pn(!0);case"state.patch":if(t.baseRev!==He)return Z("baseRev mismatch",{have:He,want:t.baseRev}),void gn(t.scope);try{!function(e,n){for(const t of n){const n="add"===t.op||"replace"===t.op,{container:o,key:r}=mn(e,t.path,n);if("$root"===r){for(const n of Object.keys(e))delete e[n];if("remove"!==t.op){const n=t.value;n&&"object"==typeof n&&Object.assign(e,n)}continue}if(Array.isArray(o)){const e="-"===r?o.length:Number(r);if(!Number.isFinite(e)||e<0)throw new Error("Invalid index");"remove"===t.op?o.splice(e,1):"add"===t.op?o.splice(e,0,t.value):"replace"===t.op&&(o[e]=t.value);continue}if(!o||"object"!=typeof o)throw new Error("Invalid container");const i=o;"remove"===t.op?delete i[r]:i[r]=t.value}}(We,t.ops||[]),He=t.rev}catch(e){return ee("Patch failed:",e),void gn(t.scope)}return K("data")&&(U.group("[LX] patch"),U.log("rev:",He,"ops:",t.ops),U.groupEnd()),pn(!1),void(t.ack&&ln({v:2,kind:"state.ack",scope:t.scope,rev:t.rev}));case"ch.ack":{const e=ze.get(t.id);if(!e)return;if(ze.delete(t.id),null!==e.timerId&&clearTimeout(e.timerId),t.ok)e.channel._markOpen(),Ue.set(t.id,e.channel),e.resolve(e.channel);else{const n=f(t.error);e.channel._reject(n),e.reject(n)}return}case"ch.data":{const e=Ue.get(t.id);if(!e)return;return void e._emitData(t.payload)}case"ch.close":{if(ze.get(t.id))return void on(t.id,{code:t.code??c,message:t.reason??"Channel closed before opening"});const e=Ue.get(t.id);if(!e)return;return Ue.delete(t.id),void e._emitClose(t.code,t.reason)}case"req":{const e=t,n=Qe(e.method);if(!e.cap||e.cap!==n)return void ln({v:2,kind:"res",id:e.id,ok:!1,error:{code:s,message:`Invalid cap for ${e.method}`}});const o=Ye.get(e.method);return o?void Promise.resolve().then(()=>o(e.params)).then(n=>{ln({v:2,kind:"res",id:e.id,ok:!0,result:n})}).catch(n=>{ln({v:2,kind:"res",id:e.id,ok:!1,error:f(n)})}):void ln({v:2,kind:"res",id:e.id,ok:!1,error:{code:i,message:`View handler not found: ${e.method}`}})}}else Z("Invalid bridge message")}const yn=new Map,wn=[];let bn=!1;function xn(){return"undefined"!=typeof window&&!!(window.webkit?.messageHandlers?.NativeComponent||window.NativeComponentBridge?.postMessage||window.LingXiaProxy?.nativeComponentUpdate)}function kn(e){try{if(window.webkit?.messageHandlers?.NativeComponent)return void window.webkit.messageHandlers.NativeComponent.postMessage(e);if(window.NativeComponentBridge?.postMessage)return void window.NativeComponentBridge.postMessage(ne(e));const n=window.LingXiaProxy?.nativeComponentUpdate;if("function"==typeof n){const t=e.id||"island",o=ne({...e,componentId:t});try{n.call(window.LingXiaProxy,o)}catch{n.call(window.LingXiaProxy,t,o)}return}}catch(e){ee("NativeComponent send error:",e)}}function En(){if(xn()&&0!==wn.length)for(bn=!0;wn.length;){const e=wn.shift();try{kn(e)}catch{break}}}function _n(e){try{if(!xn())return void wn.push(e);bn||En(),kn(e)}catch(e){ee("NC send failed:",e)}}function In(e){return`${e}_${Date.now()}_${Fe++}`}function Cn(e,n,t){if(!n)return;if(n.aborted)return void t();let o={handleEvent:()=>{n.removeEventListener("abort",o),t()}};n.addEventListener("abort",o)}const Ln={call:(e,n,o)=>new Promise((i,s)=>{if(!e||"string"!=typeof e)return void s({code:r,message:"Method name must be a non-empty string"});Be||un();const a=In("c"),l=o?.cap||Qe(e),c=o?.timeoutMs??j;qe.set(a,{method:e,mode:"call",resolve:i,reject:e=>s(e),timeoutMs:c,timerId:null}),ln({v:2,kind:"req",id:a,method:e,params:Ze(n),cap:l},a),Cn(0,o?.signal,()=>{const e=an(a);tn(a,{code:t,message:"Bridge request aborted"}),!e&&De&&ln({v:2,kind:"cancel",id:a})})}),stream(e,n,o){if(!e||"string"!=typeof e){const e=Xe("invalid",()=>{});return e._reject({code:r,message:"Method name must be a non-empty string"}),e}Be||un();const i=In("c"),s=Xe(i,()=>{an(i)?tn(i,{code:t,message:"Bridge request aborted"}):De&&ln({v:2,kind:"cancel",id:i})}),a=o?.cap||Qe(e),l=o?.timeoutMs??j;return qe.set(i,{method:e,mode:"stream",stream:s,timeoutMs:l,timerId:null}),ln({v:2,kind:"req",id:i,method:e,params:Ze(n),cap:a},i),Cn(0,o?.signal,()=>s.cancel()),s},notify(e,n,t){e&&"string"==typeof e&&(Be||un(),ln({v:2,kind:"notify",method:e,params:Ze(n),cap:t?.cap||Qe(e)}))},state:{subscribe:hn},channel:{open:(e,n,t)=>e&&"string"==typeof e?(Be||un(),new Promise((o,r)=>{const i=In("ch"),s=function(e,n,t){const o=$e();let r=!1,i=0,s=!1,a=!1,l=!1;const d=[],u=[],f={id:e,send(t){r?n(t,i++):f._reject({code:c,message:`Channel '${e}' is closed`})},on(e,n){if("data"===e&&(o.data.add(n),d.length>0)){const e=d.splice(0);for(const t of e)try{n(t)}catch(e){Z("Channel listener failed:",e)}}return"close"===e&&o.close.add(n),"error"===e&&o.error.add(n),this},[Symbol.asyncIterator]:()=>(l=!0,{next:()=>d.length>0?Promise.resolve({done:!1,value:d.shift()}):s?Promise.resolve({done:!0,value:void 0}):new Promise((e,n)=>{u.push({resolve:e,reject:n})}),return:()=>(l=!1,d.length=0,f.close(),Promise.resolve({done:!0,value:void 0}))}),close(e,n){r&&(r=!1,t(e,n),f._emitClose(e,n))},_emitData(e){if(r){u.length>0?u.shift().resolve({done:!1,value:e}):(l||0===o.data.size)&&d.push(e);for(const n of o.data)try{n(e)}catch(e){Z("Channel listener failed:",e)}}},_emitClose(e,n){if(r=!1,s=!0,!a){for(a=!0;u.length>0;)u.shift().resolve({done:!0,value:void 0});for(const t of o.close)try{t(e,n)}catch(e){Z("Channel close listener failed:",e)}}},_reject(e){for(r=!1,s=!0;u.length>0;)u.shift().reject(e);for(const n of o.error)try{n(e)}catch(e){Z("Channel error listener failed:",e)}},_markOpen(){r=!0,s=!1},_isOpen:()=>r,_nextSeq:()=>i++};return f}(i,(e,n)=>{ln({v:2,kind:"ch.data",id:i,seq:n,payload:e})},(e,n)=>{const t=ze.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),ze.delete(i),Ue.delete(i),ln({v:2,kind:"ch.close",id:i,code:e,reason:n})});ze.set(i,{topic:e,channel:s,resolve:o,reject:r,timerId:null}),ln({v:2,kind:"ch.open",id:i,topic:e,params:Ze(n),cap:t?.cap||Qe(e)},i)})):Promise.reject({code:r,message:"Topic name must be a non-empty string"})}},Sn={invoke:(e,n,t)=>Ln.call(Tn(e),n,Nn(t)).then(e=>e).catch(e=>Promise.reject(m(e))),notify(e,n,t){Ln.notify(Tn(e),n,Nn(t))},stream:(e,n,t)=>An(Ln.stream(Tn(e),n,Nn(t))),channel:(e,n,t)=>Ln.channel.open(Tn(e),n,Nn(t)).then(e=>function(e){const n=new Set,t=new Set;let o=[];return setTimeout(()=>{o=null},0),e.on("data",e=>{if(0!==n.size)for(const t of n)t(e);else o?.push(e)}),e.on("close",(e,n)=>{const o={code:e,reason:n};for(const e of t)e(o)}),{send(n){e.send(n)},onMessage(e){n.add(e);const t=o;o=null;for(const n of t??[])e(n);return()=>{n.delete(e)}},onClose:e=>(t.add(e),()=>{t.delete(e)}),close(n,t){e.close(n,t)}}}(e)).catch(e=>Promise.reject(m(e))),raw:Ln,state:{subscribe:hn},_connectWebMessagePort(e){if(oe===$){if(re&&re!==e)try{re.onmessage=null,re.close()}catch{}re=e,e.onmessage=e=>{vn(e.data)};try{e.start()}catch{}Q("Port connected"),un()}},_receiveEvaluateMessage(e){e&&vn(e)},debug:function(e){const n={};return Object.keys(e).forEach(t=>{Object.defineProperty(n,t,{enumerable:!0,configurable:!1,get:()=>e[t],set(n){e[t]=!!n,U.log(`[LX] ${t}: ${n}`)}})}),n}(G),host:{get:D,subscribe:B},platform:{isHarmony:function(){return"Harmony"===w.os},isIOS:C,isAndroid:function(){return"Android"===w.os},isMacOS:L,isWindows:function(){return"Windows"===w.os},isDesktop:S,isMobile:function(){return"mobile"===I()},isApple:function(){return C()||L()},isRunner:function(){return!0===w.runner},getOS:_},dom:{measureById(e){try{if(!e)return null;const n=document.getElementById(e);if(!n)return null;const t=n.getBoundingClientRect();let o=0;try{o=parseFloat(getComputedStyle(n).borderRadius)||0}catch{}return[t.left+window.scrollX,t.top+window.scrollY,t.width,t.height,o]}catch{return null}}},nativeComponents:{send:_n,hasHandler:xn,flush:En,register:(e,n)=>e&&"function"==typeof n?(yn.set(e,n),()=>yn.delete(e)):()=>{},unregister(e){yn.delete(e)}},isReady:()=>De};function Tn(e){return e.startsWith("host.")?e:`host.${e}`}function Nn(e){return{...e||{},cap:e?.cap||"host"}}function An(e){const n=new Set,t=new Set;return e.on("data",e=>{for(const t of n)t(e)}),e.on("error",e=>{const n=m(e);for(const e of t)e(n)}),{onEvent:e=>(n.add(e),()=>{n.delete(e)}),onError:e=>(t.add(e),()=>{t.delete(e)}),result:e.result.catch(e=>Promise.reject(m(e))),cancel(){e.cancel()}}}function Mn(){if(window.__LX_BRIDGE_INIT_STATE)Q(`Bridge already ${window.__LX_BRIDGE_INIT_STATE}, skipping duplicate init`);else{window.__LX_BRIDGE_INIT_STATE="initializing";try{if(!V){const e=function(){if("undefined"==typeof window)return{kind:"absent"};const e=window.__LingXiaTakeControlBootstrap;if("function"!=typeof e)return{kind:"absent"};try{const n=e();if(!n||3!==n.requiredProtocol||"string"!=typeof n.publicSessionId||0===n.publicSessionId.length||"string"!=typeof n.secret||0===n.secret.length)return{kind:"blocked"};const t=y({sessionId:n.publicSessionId,secret:n.secret});return t.ok?{kind:"required",codec:t.value}:{kind:"blocked"}}catch{return{kind:"blocked"}}finally{try{delete window.__LingXiaTakeControlBootstrap}catch{}}}();W="required"===e.kind?{kind:"required-v3",codec:e.codec}:{kind:"absent"===e.kind?"v2":"blocked"},V=!0}if(function(){if("required-v3"===W.kind)for(const e of["log","error","warn","info","debug"]){const n=U[e];console[e]=(...t)=>{n(...t),De&&Ae({kind:"console",__lingxia_console__:!0,level:e,message:Me(t)})}}}(),Q(`Method: ${oe}`),e=Sn._receiveEvaluateMessage,"undefined"!=typeof window&&(window[R]=n=>{Y(e),e(n)},Y(e)),be())Le(),be()&&!de&&null===he&&(he=setInterval(()=>{0!==fe?Date.now()-fe>35e3&&(Z("Apple downstream stale (no heartbeat), forcing reconnect"),Te()):se&&0!==me&&Date.now()-me>1e4&&(Z("Apple downstream did not connect, forcing reconnect"),Te())},5e3)),be()&&"undefined"!=typeof document&&document.addEventListener("visibilitychange",Ne);else if(oe===$){ye();const e=n=>{(function(){if(re)return Promise.resolve(re);if(ge.promise)return ge.promise;ye(),ge.promise=new Promise((e,n)=>{ge.resolve=n=>{we(),e(n)},ge.reject=e=>{we(),n(e)},ge.timer=window.setTimeout(()=>{ge.reject?.(new Error("MessagePort init timed out after 5000ms"))},5e3)});try{window.LingXiaProxy?.getPort("LingXiaPort")}catch(e){ge.reject?.(e)}return ge.promise})().catch(t=>{Z("Port init failed:",t),n<3&&window.setTimeout(()=>e(n+1),500*n)})};e(1)}else"webkit"===oe||oe===X||oe===q?un():Z("Unknown method");window.LingXiaBridge=Sn,window.__lxForceDownstreamReconnect=Te,p({os:_(),send:_n}),window.__LX_BRIDGE_INIT_STATE="initialized",Q("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}var e}}const On="\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";function Pn(e){const n=document.createElement("div");return n.textContent=e,n.innerHTML}function Dn(e){!function({code:e,title:n,description:t,detail:o,reason:r}){const i=document.createElement("style");i.textContent=On,document.head.appendChild(i),document.body.innerHTML="",document.body.style.cssText="";const s=document.createElement("div");s.className="lx-error";let a=`<div class="lx-error-code">${Pn(e)}</div>`;a+=`<h1 class="lx-error-title">${Pn(n)}</h1>`,a+=`<p class="lx-error-desc">${Pn(t)}</p>`,o&&(a+=`<div class="lx-error-path">${Pn(o)}</div>`),r&&(a+=`<p class="lx-error-desc" style="margin-top:12px">${Pn(r)}</p>`),s.innerHTML=a,document.body.appendChild(s)}({code:"404",title:"Page Not Found",description:"The page you're looking for doesn't exist.",detail:e.failedPath,reason:e.reason})}function Bn(){const e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function Rn(){return window.__LX_RUNTIME_CONFIG?.error||null}const jn={handleEvent:()=>Fn()};function Fn(){if(Bn()){const e=Rn();e&&Dn(e)}}function $n(){Mn(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",jn):Fn()}const Xn="lx-action-sheet-style";let qn=null;function zn(e){const n=e,t=n?.itemList??[],o=n?.cancelText??"Cancel",r=n?.itemColor??"#007AFF",i=(qn??Promise.resolve()).then(()=>Un(t,o,r),()=>Un(t,o,r));return qn=i,i}function Un(e,n,t){return new Promise(o=>{let r=!1;const i=S();!function(){if(document.getElementById(Xn))return;const e=document.createElement("style");e.id=Xn,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 300ms 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 300ms 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)}();const s=document.createElement("div");s.className="lx-as-backdrop";const a=document.createElement("div");a.className="lx-as-sheet",i&&a.classList.add("lx-as-desktop");const l=document.createElement("div");l.className="lx-as-container",i&&l.classList.add("lx-as-desktop"),e.forEach((e,n)=>{const o=document.createElement("button");o.className="lx-as-item",o.textContent=e,o.style.color=t,o.addEventListener("click",()=>u(n)),l.appendChild(o)});const c=document.createElement("div");c.className="lx-as-separator",l.appendChild(c);const d=document.createElement("button");function u(e){r||(r=!0,s.classList.remove("lx-as-visible"),a.classList.remove("lx-as-visible"),setTimeout(()=>{s.remove(),a.remove(),o({tapIndex:e})},300))}d.className="lx-as-item lx-as-cancel-btn",d.textContent=n,d.addEventListener("click",()=>u(-1)),l.appendChild(d),a.appendChild(l),document.body.appendChild(s),document.body.appendChild(a),requestAnimationFrame(()=>{s.classList.add("lx-as-visible"),a.classList.add("lx-as-visible")}),s.addEventListener("click",()=>u(-1))})}const Gn=200,Hn="lx-modal-style";let Wn=null;function Vn(e){const n=e,t=n?.title??"",o=n?.content??"",r=n?.showCancel??!0,i=n?.cancelText??"Cancel",s=n?.cancelColor,a=n?.confirmText??"OK",l=n?.confirmColor??"#007AFF",c=(Wn??Promise.resolve()).then(()=>Jn(t,o,r,i,s,a,l),()=>Jn(t,o,r,i,s,a,l));return Wn=c,c}function Jn(e,n,t,o,r,i,s){return new Promise(a=>{let l=!1;!function(){if(document.getElementById(Hn))return;const e=document.createElement("style");e.id=Hn,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 200ms 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 200ms ease, opacity 200ms 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)}();const c=document.createElement("div");c.className="lx-modal-backdrop";const d=document.createElement("div");d.className="lx-modal-dialog";const u=document.createElement("div");u.className="lx-modal-body";const f=document.createElement("div");if(f.className="lx-modal-title",f.textContent=e,u.appendChild(f),n){const e=document.createElement("p");e.className="lx-modal-content",e.textContent=n,u.appendChild(e)}d.appendChild(u);const m=document.createElement("div");if(m.className="lx-modal-footer",t){const e=document.createElement("button");e.className="lx-modal-btn lx-modal-btn-cancel",e.textContent=o,r&&(e.style.color=r),e.addEventListener("click",()=>h(!1)),m.appendChild(e)}const p=document.createElement("button");function h(e){l||(l=!0,c.classList.remove("lx-modal-visible"),setTimeout(()=>{c.remove(),a({confirm:e,cancel:!e})},Gn))}p.className="lx-modal-btn lx-modal-btn-confirm",p.textContent=i,p.style.color=s,p.addEventListener("click",()=>h(!0)),m.appendChild(p),d.appendChild(m),c.appendChild(d),document.body.appendChild(c),requestAnimationFrame(()=>{c.classList.add("lx-modal-visible")})})}const Yn="lx-toast-style";let Kn=null;function Qn(e){const n=e,t=n?.title??"",o=n?.icon??"none",r=n?.duration??1500,i=n?.mask??!1,s=n?.position??"center";if(Kn&&Kn.icon===o&&Kn.position===s&&Kn.mask===i){const e=Kn;return e.titleEl.textContent=t,e.timer&&clearTimeout(e.timer),e.timer=r>0?setTimeout(e.dismiss,r):null,Promise.resolve()}Kn&&(Kn.dismiss(),Kn=null),function(){if(document.getElementById(Yn))return;const e=document.createElement("style");e.id=Yn,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 200ms ease, opacity 200ms 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)}();let a=null;i&&(a=document.createElement("div"),a.className="lx-toast-mask",document.body.appendChild(a));const l=document.createElement("div");l.className="lx-toast-container","top"===s?l.classList.add("lx-toast-top"):"bottom"===s?l.classList.add("lx-toast-bottom"):l.classList.add("lx-toast-center");const c=document.createElement("div");c.className="lx-toast-box";const d="none"!==o;if(d||c.classList.add("lx-toast-no-icon"),d){const e=document.createElement("div");e.className="lx-toast-icon","success"===o?e.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"===o?e.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"===o&&(e.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>'),c.appendChild(e)}const u=document.createElement("div");u.className="lx-toast-title",u.textContent=t,c.appendChild(u),l.appendChild(c),document.body.appendChild(l),requestAnimationFrame(()=>{c.classList.add("lx-toast-visible")});let f=!1;function m(){f||(f=!0,p.timer&&clearTimeout(p.timer),Kn===p&&(Kn=null),c.classList.remove("lx-toast-visible"),setTimeout(()=>{l.remove(),a?.remove()},200))}const p={dismiss:m,timer:null,titleEl:u,icon:o,position:s,mask:i};return r>0&&(p.timer=setTimeout(m,r)),Kn=p,Promise.resolve()}function Zn(){return Kn&&(Kn.dismiss(),Kn=null),Promise.resolve()}return Ke("ui.showActionSheet",zn),Ke("ui.showModal",Vn),Ke("ui.showToast",Qn),Ke("ui.hideToast",Zn),$n(),e.LingXiaBridge=Sn,e.boot=function(){Mn(),Fn()},e.bootWhenReady=$n,e.channel=function(e,n,t){return Sn.channel(e,n,t)},e.getErrorInfo=Rn,e.getHost=D,e.hasError=Bn,e.initBridge=Mn,e.invoke=function(e,n,t){return Sn.invoke(e,n,t)},e.isNativeError=function(e,n){if(!e||"object"!=typeof e)return!1;const 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){Ln.notify(Tn(e),n,Nn(t))},e.renderErrorUI=Dn,e.renderPageFault=function(e,n){const t=document.createElement("style");t.textContent=`\n.lx-page-fault { position: fixed; inset: 0; z-index: 2147483647; overflow: auto;\n background: #fff; color: #1d1d1f; }\n@media (prefers-color-scheme: dark) { .lx-page-fault { background: #000; color: #f5f5f7; } }\n${On.replace(/\bbody\b/g,".lx-page-fault")}`,document.head.appendChild(t);const o=document.createElement("div");o.className="lx-page-fault",o.setAttribute("role","alert");const r=document.createElement("div");r.className="lx-error";let i='<div class="lx-error-code">Page</div>';return i+=`<h1 class="lx-error-title">${Pn("This page couldn't start")}</h1>`,i+=`<p class="lx-error-desc">${Pn("Its Logic has not delivered the page state. Check the Logic log for an error.")}</p>`,e&&(i+=`<div class="lx-error-path">${Pn(e)}</div>`),i+=`<p class="lx-error-desc" style="margin-top:12px">${Pn(n)}</p>`,r.innerHTML=i,o.appendChild(r),document.body.appendChild(o),()=>{o.remove(),t.remove()}},e.stream=function(e,n,t){return An(Ln.stream(Tn(e),n,Nn(t)))},e.subscribeHost=B,e}({});
|
|
1
|
+
const __LX_RUNTIME_PLATFORM__="all";var __LingXiaBridgeBundle=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});const n="BRIDGE_TIMEOUT",t="BRIDGE_CANCELED",o="BRIDGE_HANDSHAKE_FAILED",r="BRIDGE_MALFORMED_MESSAGE",i="BRIDGE_METHOD_NOT_FOUND",s="BRIDGE_CAPABILITY_DENIED",a="BRIDGE_INTERNAL_ERROR",l="BRIDGE_OUTBOX_FULL",c="BRIDGE_STREAM_CLOSED",d="BRIDGE_MESSAGE_TOO_LARGE";var u=class extends Error{constructor(e,n,t){super(n),this.name="BridgeInvocationError",this.code=e,this.data=t}};function f(e){if(e instanceof u)return e;if(e&&"object"==typeof e){const n=e;let t=a;("string"==typeof n.code&&""!==n.code.trim()||"number"==typeof n.code&&Number.isFinite(n.code))&&(t=n.code);const o="string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error";return new u(t,o,"data"in n?n.data:void 0)}const n=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new u(a,n)}function m(e){const n=f(e);return{code:String(n.code||a),message:"string"==typeof n.message&&""!==n.message.trim()?n.message:"Unknown error",...void 0===n.data?{}:{data:n.data}}}function p({os:e,send:n}){if("undefined"==typeof window)return;if("undefined"==typeof document)return;const t="iOS"===e;if(!t&&"Android"!==e)return;const o=Symbol.for("LingXia.NativeComponentCoverageMonitor");if(window[o]?.installed)return;const r={installed:!0,coveredById:new Map,coveredCount:0,anyCovered:!1,scheduled:!1,hasAnyVideo:!1,scrollLocked:!1,scrollY:0,htmlOverflow:"",bodyOverflow:"",bodyPosition:"",bodyTop:"",bodyWidth:""};function i(e){const n=e.getBoundingClientRect?.();if(!n)return!1;if(n.width<2||n.height<2)return!1;const t=n.left+n.width/2,o=n.top+n.height/2;if(t<0||o<0||t>=window.innerWidth||o>=window.innerHeight)return!1;const r=document.elementFromPoint?.(t,o);return!!r&&(r!==document.documentElement&&r!==document.body&&!(r===e||e.contains(r)))}function s(){r.scheduled=!1;const e=document.querySelectorAll("lx-video[id]");if(r.hasAnyVideo=e.length>0,!r.hasAnyVideo&&0===r.coveredById.size&&!r.anyCovered)return;const o=new Set;for(const t of Array.from(e)){const e=t.id;if(!e)continue;o.add(e);const s=i(t),a=r.coveredById.get(e);a!==s&&(!0===a&&(r.coveredCount-=1),!0===s&&(r.coveredCount+=1),r.coveredById.set(e,s),n({id:e,action:"component.coverage",covered:s}))}const s=[];for(const[e,n]of r.coveredById.entries())o.has(e)||(s.push(e),!0===n&&(r.coveredCount-=1));for(const e of s)r.coveredById.delete(e),n({id:e,action:"component.coverage",covered:!1});const a=r.coveredCount>0;a!==r.anyCovered&&(r.anyCovered=a,t&&(a?function(){if(!t)return;if(r.scrollLocked)return;const e=document.documentElement,n=document.body;e&&n&&(r.scrollLocked=!0,r.scrollY=window.scrollY||e.scrollTop||0,r.htmlOverflow=e.style.overflow||"",r.bodyOverflow=n.style.overflow||"",r.bodyPosition=n.style.position||"",r.bodyTop=n.style.top||"",r.bodyWidth=n.style.width||"",e.style.overflow="hidden",n.style.overflow="hidden",n.style.position="fixed",n.style.top=-r.scrollY+"px",n.style.width="100%")}():function(){if(!t)return;if(!r.scrollLocked)return;const e=document.documentElement,n=document.body;e&&n&&(r.scrollLocked=!1,e.style.overflow=r.htmlOverflow,n.style.overflow=r.bodyOverflow,n.style.position=r.bodyPosition,n.style.top=r.bodyTop,n.style.width=r.bodyWidth,window.scrollTo(0,r.scrollY))}()))}function a(){r.scheduled||(r.scheduled=!0,requestAnimationFrame(s))}window[o]=r,new MutationObserver(a).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0});const l={handleEvent:()=>{(r.hasAnyVideo||0!==r.coveredById.size)&&a()}},c={handleEvent:()=>a()};window.addEventListener("scroll",l,{capture:!0,passive:!0}),window.addEventListener("resize",c),a()}const h=new Set(["hello","req","res","notify","cancel","ch.open","ch.data","ch.close","state.ack","console"]),g=new Set(["helloAck","ready","req","res","event","state.snapshot","state.patch","ch.ack","ch.data","ch.close"]);function v(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function w(e){if(!v(e)||"string"!=typeof e.sessionId||0===e.sessionId.length||"string"!=typeof e.secret||0===e.secret.length)return{ok:!1,error:"INVALID_DOCUMENT_BINDING"};const{sessionId:n,secret:t}=e;return{ok:!0,value:{encode:(e,o)=>h.has(e)&&v(o)?["v","kind","sessionId","secret"].some(e=>e in o)?{ok:!1,error:"SECURITY_FIELD_IN_PAYLOAD"}:{ok:!0,value:{...o,v:3,kind:e,sessionId:n,secret:t}}:{ok:!1,error:"INVALID_DOCUMENT_PAYLOAD"},parse(e,t=65536){if((new TextEncoder).encode(e).byteLength>t)return{ok:!1,error:"FRAME_TOO_LARGE"};if(function(e){const n=new Set(["v","kind","sessionId","secret"]),t=new Set;let o=0;for(let r=0;r<e.length;r++){const i=e[r];if("{"===i||"["===i){o++;continue}if("}"===i||"]"===i){o--;continue}if('"'!==i)continue;const s=r;for(r++;r<e.length;)if("\\"!==e[r]){if('"'===e[r])break;r++}else r+=2;if(r>=e.length)return!1;if(1!==o)continue;let a,l=r+1;for(;/\s/.test(e[l]??"");)l++;if(":"===e[l]){try{a=JSON.parse(e.slice(s,r+1))}catch{return!1}if("string"==typeof a&&n.has(a)){if(t.has(a))return!0;t.add(a)}}}return!1}(e))return{ok:!1,error:"MALFORMED_ENVELOPE"};let o;try{o=JSON.parse(e)}catch{return{ok:!1,error:"MALFORMED_ENVELOPE"}}if(!v(o))return{ok:!1,error:"MALFORMED_ENVELOPE"};if(3!==o.v)return{ok:!1,error:"UNSUPPORTED_VERSION"};if("string"!=typeof o.kind||!g.has(o.kind))return{ok:!1,error:"UNSUPPORTED_NATIVE_KIND"};if("string"!=typeof o.sessionId||0===o.sessionId.length)return{ok:!1,error:"MALFORMED_ENVELOPE"};if(o.sessionId!==n)return{ok:!1,error:"SESSION_MISMATCH"};if(Object.prototype.hasOwnProperty.call(o,"secret"))return{ok:!1,error:"UNEXPECTED_SECRET"};const{v:r,kind:i,sessionId:s,...a}=o;return{ok:!0,value:{kind:o.kind,payload:a}}}}}}const y="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{},b={value:y.displayLanguage?.trim()||"en-US",listeners:new Set};function x(){return"undefined"==typeof window?b:(window.__lxDisplayLanguage||(window.__lxDisplayLanguage={value:y.displayLanguage?.trim()||"en-US",listeners:new Set}),window.__lxDisplayLanguage)}const k=new Set(["ar","ckb","dv","fa","he","ps","sd","ug","ur","yi"]);function E(){if("undefined"!=typeof document&&document.documentElement){const e=x().value;document.documentElement.lang=e,document.documentElement.dir=function(e){try{const n=new Intl.Locale(e),t="function"==typeof n.getTextInfo?n.getTextInfo():n.textInfo;if("rtl"===t?.direction||"ltr"===t?.direction)return t.direction}catch{}return k.has(e.split(/[-_]/)[0].toLowerCase())?"rtl":"ltr"}(e)}}function _(){return y.os||"unknown"}function I(){return"mobile"===y.hostClass||"desktop"===y.hostClass?y.hostClass:"macOS"===y.os||"Windows"===y.os?"desktop":"mobile"}function C(){return"iOS"===y.os}function L(){return"macOS"===y.os}function S(){return"desktop"===I()}E(),"undefined"==typeof window||window.__lingxiaApplyDisplayLanguage||Object.defineProperty(window,"__lingxiaApplyDisplayLanguage",{configurable:!1,enumerable:!1,value:function(e,n){const t="string"==typeof e?e.trim():"",o=x();if("number"==typeof n&&Number.isFinite(n)){if(n<=(o.revision??0))return;o.revision=n}if(t&&t!==o.value){o.value=t,E();for(const e of[...o.listeners])e(t)}}});const T={sizeClass:"compact",width:0,height:0,aside:!1};function N(){if("undefined"==typeof window)return A;if(!window.__lxSurfaceContext){const e=window.__LX_BRIDGE_CFG;window.__lxSurfaceContext={value:M(e?.surfaceContext)??T,revision:"number"==typeof e?.surfaceContextRevision?e.surfaceContextRevision:0,listeners:new Set}}return window.__lxSurfaceContext}const A={value:T,revision:0,listeners:new Set};function M(e){if("object"!=typeof e||null===e)return null;const{sizeClass:n,width:t,height:o,aside:r}=e;return"compact"!==n&&"regular"!==n||"number"!=typeof t||"number"!=typeof o?null:{sizeClass:n,width:t,height:o,aside:!0===r}}"undefined"==typeof window||window.__lingxiaApplySurfaceContext||Object.defineProperty(window,"__lingxiaApplySurfaceContext",{configurable:!1,enumerable:!1,value:function(e,n){const t=M(e),o=N();if(t){if("number"==typeof n){if(n<=o.revision)return;o.revision=n}if(r=o.value,i=t,r.sizeClass!==i.sizeClass||r.width!==i.width||r.height!==i.height||r.aside!==i.aside){var r,i;o.value=t;for(const e of[...o.listeners])e()}}}});let O=null;function P(){const e=N().value;return{sizeClass:e.sizeClass,aside:e.aside,displayLanguage:x().value,formFactor:S()?"desktop":"mobile",os:_(),runner:!0===y.runner}}function D(){const e=P();var n,t;return null!==O&&(t=e,(n=O).sizeClass===t.sizeClass&&n.aside===t.aside&&n.displayLanguage===t.displayLanguage&&n.formFactor===t.formFactor&&n.os===t.os&&n.runner===t.runner)||(O=e),O}function B(e){let n=D();const t=()=>{const t=D();t!==n&&(n=t,e())},o=function(e){const n=x().listeners;return n.add(e),()=>{n.delete(e)}}(t),r=function(e){const n=N().listeners;return n.add(e),()=>{n.delete(e)}}(t);return()=>{o(),r()}}function j(){return{holders:[],sent:!1,tail:Promise.resolve(),asking:!1}}const R=j();function F(){if("undefined"==typeof window)return R;const e=window;return e.__lxLeaveGuard||(e.__lxLeaveGuard=j()),e.__lxLeaveGuard}function $(){const e=F();e.tail=e.tail.then(()=>{const n=e.holders.length>0;if(n!==e.sent)return e.sent=n,q("navigation.setLeaveGuard",{enabled:n}).catch(t=>{e.sent=!n,console.warn("[lingxia] leave guard not applied; the page is not guarded",t)})})}function X(e){const n=F(),t=n=>e(n);return n.holders.push(t),$(),()=>{const e=n.holders.indexOf(t);e<0||(n.holders.splice(e,1),$())}}function q(e,n){const t="undefined"!=typeof window?window.LingXiaBridge:void 0;if(!t)return Promise.reject(new Error("LingXiaBridge is not available"));try{return t.invoke(e,n)}catch(e){return Promise.reject(e)}}"undefined"==typeof window||window.__lingxiaDispatchLeaveRequest||Object.defineProperty(window,"__lingxiaDispatchLeaveRequest",{configurable:!1,enumerable:!1,value:function(e){const n=F();if(n.asking)return;n.asking=!0;const t={reason:e},o=n.holders.slice().reverse();let r=Promise.resolve(!0);o.forEach(e=>{r=r.then(n=>!!n&&e(t))}),r.then(e=>!0===e,e=>(console.error("[lingxia] leave guard handler failed; staying on the page",e),!1)).then(t=>{if(n.asking=!1,t)return q("navigation.leave",{reason:e}).catch(e=>{console.warn("[lingxia] leaving the page failed",e)})})}});const z="__LingXiaRecvMessage",G=5e3,U="[LX.Bridge]",H="messageport",W="jsinterface",V="webmessage",J=y.appleDownstreamURL,Y={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:(console.info||console.log).bind(console),debug:(console.debug||console.log).bind(console),group:(console.group||console.log).bind(console),groupEnd:(console.groupEnd||(()=>{})).bind(console)},K={data:!1,proto:!1,all:!1},Q=[];let Z={kind:"v2"},ee=!1;function ne(){if("undefined"==typeof window)return;const e=window.__LingXiaEarlyNativeMessages;if(Array.isArray(e)&&0!==e.length){window.__LingXiaEarlyNativeMessages=[];for(const n of e)"string"==typeof n&&Q.push(n)}}function te(e){if(ne(),0===Q.length)return;const n=Q.splice(0,Q.length);for(const t of n)try{e(t)}catch(e){ie("Failed to replay queued native message:",e)}}function oe(e){return K.all||K[e]}function re(...e){(!0===y.dev||K.all||K.proto||K.data)&&Y.log(U,...e)}function ie(...e){Y.warn(U,...e)}function se(...e){Y.error(U,...e)}function ae(e){try{return JSON.stringify(e)}catch{return function(e,n){const t=new WeakSet;return JSON.stringify(e,(e,n)=>{if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},n)}(e)}}function le(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch{return{}}}const ce="iOS"===y.os||"macOS"===y.os?"webkit":"Harmony"===y.os?"messageport":"Windows"===y.os?"webmessage":"Android"===y.os?window.LingXiaProxy?.supportsMessagePort?.()?"messageport":"jsinterface":"unknown";!function(){if("undefined"==typeof window)return;ne();const e=window[z];if("function"==typeof e){if(0===Q.length)return;const n=Q.splice(0,Q.length);for(const t of n)try{e(t)}catch(e){ie("Failed to replay queued native message:",e)}return}window[z]=e=>{Q.push(e)}}();let de=null,ue=!1,fe=null,me=null,pe=null,he=200,ge=!1,ve=0;let we=0,ye=0;const be=`${Date.now().toString(36)}${Math.random().toString(36).slice(2,10)}`;let xe=null;const ke={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},Ee={handleEvent:e=>{const n=e;if("LingXia-port-init"!==n.data)return;const t=n.ports?.[0];t&&(Pn._connectWebMessagePort(t),ke.resolve?.(t))}};function _e(){ke.listenerInstalled||(ke.listenerInstalled=!0,window.addEventListener("message",Ee))}function Ie(){null!==ke.timer&&(window.clearTimeout(ke.timer),ke.timer=null),ke.resolve=null,ke.reject=null,ke.promise=null}function Ce(){return"webkit"===ce&&(C()||L())}function Le(){null!==pe&&(clearTimeout(pe),pe=null)}function Se(e){Ce()&&!ge&&(ge=!0,Le(),null!==xe&&(clearInterval(xe),xe=null),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",Be),Pe=!1,me?.abort(),ue=!1,Ne(e,!0))}function Te(e){for(const n of Array.from(Ve.keys()))cn(n,{code:c,message:e});for(const n of Array.from(Je.keys()))dn(n,{code:c,message:e});!function(e){for(const[n,t]of Array.from(Ye.entries()))Ye.delete(n),t._emitClose(c,e)}(e)}function Ne(e,n){gn(),"required-v3"!==Z.kind&&(Fe=null),$e=!1,Xe=!1,qe=!1,ze=0,n&&Te(e)}function Ae(e){let n=e;for(;;){const e=n.indexOf("\n");if(e<0)break;const t=n.slice(0,e).trim();if(n=n.slice(e+1),t)try{Me(JSON.parse(t))}catch(e){ie("Apple downstream parse error:",e,t)}}return n}function Me(e){if(!e||"object"!=typeof e)return;we=Date.now();const n=e;if(!0!==n.lxshutdown){if(void 0===n.lxhb){if(!0===n.lxreset)return ve=0,Ne("Apple downstream reset",!0),void vn();if("number"==typeof n.lxff){if(n.lxff<=ve)return;return ve=n.lxff,void En(n.m)}En(e)}}else Se("Apple downstream closed")}function Oe(){if(!Ce()||ge)return;if(fe)return;Le();let e=!1;fe=async function(){if(!J)throw new Error("Apple downstream URL is not configured");const e=new AbortController;me=e;const n=J.includes("?")?"&":"?",t=`${J}${n}from=${ve}&doc=${be}`;ye=Date.now();const o=await fetch(t,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal});if(!o.ok)throw new Error(`Apple downstream HTTP ${o.status}`);if("1"===o.headers.get("X-LingXia-Bridge-Shutdown"))return void Se("Apple downstream closed");if(!o.body)throw new Error("Apple downstream response body unavailable");ue=!0,he=200,we=Date.now(),oe("proto")&&re("Apple downstream connected"),vn();const r=o.body.getReader(),i=new TextDecoder;let s="";try{for(;;){const{value:e,done:n}=await r.read();if(n)break;s+=i.decode(e,{stream:!0}),s=Ae(s)}s+=i.decode();const e=s.trim();if(e)try{Me(JSON.parse(e))}catch(n){ie("Apple downstream trailing parse error:",n,e)}}catch(n){if(e.signal.aborted)return;throw n}finally{try{r.releaseLock()}catch{}}}().then(()=>{e=!0}).catch(e=>{me?.signal.aborted||ie("Apple downstream failed:",e)}).finally(()=>{const n=me?.signal.aborted??!1;fe=null,me=null,ue=!1,n||ge||function(e,n=!1){if(!Ce()||ge)return;Le();const t=n?0:he;n||(he=Math.min(2*he,2e3));const o=n?`Apple downstream completed, reconnecting immediately: ${e}`:`Apple downstream disconnected, retrying in ${t}ms: ${e}`;t<=200?re(o):ie(o),pe=setTimeout(()=>{pe=null,Oe()},t)}("stream closed",e)})}let Pe=!1;function De(){if(!Ce()||ge)return;if(Pe)return;Pe=!0;const e=fe;me?.abort();const n=()=>{Pe=!1,Oe()};e?e.finally(n):n()}function Be(){"visible"===document.visibilityState&&De()}function je(e){const n=function(e){if("blocked"===Z.kind)return null;if("v2"===Z.kind)return e;if(!e||"object"!=typeof e)return null;const{v:n,kind:t,...o}=e;if("string"!=typeof t)return null;const r=Z.codec.encode(t,o);return r.ok?r.value:null}(e);if(!n)return null;const t=e.kind;"req"!==t&&"notify"!==t||re(`postToNative: ${t} ${e.method}`),oe("proto")&&Y.log("→",JSON.stringify(e,null,2));try{const e=ae(n),t=function(e){if("function"==typeof TextEncoder)return(new TextEncoder).encode(e).length;let n=0;for(let t=0;t<e.length;t+=1){const o=e.charCodeAt(t);o<128?n+=1:o<2048?n+=2:o>=55296&&o<=56319?(n+=4,t+=1):n+=3}return n}(e);if(t>65536)return{code:d,message:`Bridge message of ${t} bytes exceeds the 65536-byte native limit`};if("webkit"===ce)return window.webkit?.messageHandlers.LingXia?.postMessage(e),null;if(ce===H&&de)return de.postMessage(e),null;if((ce===W||ce===V)&&window.LingXiaProxy?.postMessage)return window.LingXiaProxy.postMessage(e),null;ie("Transport not ready")}catch(e){"required-v3"===Z.kind?se("Send error"):se("Send error:",e)}return null}function Re(e){const n=e.map(e=>{if("string"==typeof e)return e;try{const n=ae(e);return"string"==typeof n?n:String(e)}catch{return"[Unserializable]"}}).join(" ");return n.length<=12288?n:`${n.slice(0,12288)}…`}let Fe=null,$e=!1,Xe=!1,qe=!1,ze=0,Ge=null,Ue=0;function He(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function We(e,n){const t=He();let o=!1,r=!1,i=()=>{},s=()=>{};const a=[],l=[],c=new Promise((e,n)=>{i=e,s=n}),d={id:e,result:c,on(e,n){return"data"===e&&t.data.add(n),"end"===e&&t.end.add(n),"error"===e&&t.error.add(n),this},[Symbol.asyncIterator]:()=>(r=!0,{next:()=>a.length>0?Promise.resolve({done:!1,value:a.shift()}):o?c.then(e=>({done:!0,value:e}),e=>Promise.reject(e)):new Promise((e,n)=>{l.push({resolve:e,reject:n})}),return:()=>(r=!1,a.length=0,c.catch(()=>{}),d.cancel(),Promise.resolve({done:!0,value:void 0}))}),cancel(){o||n()},_emitData(e){if(!o){l.length>0?l.shift().resolve({done:!1,value:e}):r&&a.push(e);for(const n of t.data)try{n(e)}catch(e){ie("Stream data listener failed:",e)}}},_resolve(e){if(!o){for(o=!0,i(e);l.length>0;)l.shift().resolve({done:!0,value:e});for(const n of t.end)try{n(e)}catch(e){ie("Stream end listener failed:",e)}}},_reject(e){if(!o){for(o=!0,s(e);l.length>0;)l.shift().reject(e);for(const n of t.error)try{n(e)}catch(e){ie("Stream error listener failed:",e)}}}};return d}const Ve=new Map,Je=new Map,Ye=new Map,Ke=[];let Qe=-1,Ze={};const en=new Set,nn=new WeakMap,tn=new Map;function on(e,n){tn.set(e,n)}function rn(e){if(e.startsWith("host."))return"host";const n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function sn(e){if(null!=e)return e}function an(){return ce===H?!!de:Ce()?ue:"webkit"===ce||ce===W||ce===V}function ln(){return!!Xe&&(!!Ce()||an())}function cn(e,n){const t=Ve.get(e);if(t){Ve.delete(e),null!==t.timerId&&clearTimeout(t.timerId);const o=f(n);if("stream"===t.mode&&t.stream)return void t.stream._reject(o);t.reject?.(o)}}function dn(e,n){const t=Je.get(e);if(!t)return;Je.delete(e),null!==t.timerId&&clearTimeout(t.timerId);const o=f(n);t.channel._reject(o),t.reject(o)}function un(e,n){Ve.has(e)?cn(e,n):Je.has(e)&&dn(e,n)}function fn(e){Ve.has(e)?function(e){const t=Ve.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(()=>{Ve.has(e)&&cn(e,{code:n,message:`'${t.method}' timed out`})},t.timeoutMs)))}(e):Je.has(e)&&function(e){const t=Je.get(e);t&&(null!==t.timerId&&clearTimeout(t.timerId),t.timerId=setTimeout(()=>{dn(e,{code:n,message:`Channel '${t.topic}' timed out`})},G))}(e)}function mn(e){for(let n=Ke.length-1;n>=0;n--)if(Ke[n]?.reqId===e)return Ke.splice(n,1),!0;return!1}function pn(e,n){const t=e.kind,o="hello"===t||"helloAck"===t||"ready"===t;if(!ln()&&!o)return Ke.length>=256?(se("Outbox full"),void(n&&un(n,{code:l,message:"Bridge outbox is full"}))):void Ke.push({msg:e,reqId:n});n&&fn(n),hn(je(e),n)}function hn(e,n){e&&(se(e.message),n&&un(n,e))}function gn(){null!==Ge&&(clearTimeout(Ge),Ge=null)}function vn(){if(Xe)return;if(!ee)return;if("blocked"===Z.kind)return;if(!an())return;gn();const e={v:2,kind:"hello",nonce:y.nonce||"",role:"view",protocolsSupported:"required-v3"===Z.kind?[3]:[2]};qe=!0,je(e),Ge=setTimeout(()=>{if(!Xe)if(ze++,ze<3)ie(`Handshake timeout (${ze}/3), retrying...`),qe=!1,vn();else{for(se("Handshake failed"),gn(),qe=!1,ze=0;Ke.length;){const e=Ke.shift();e?.reqId&&un(e.reqId,{code:o,message:"Bridge handshake failed"})}for(const e of Array.from(Je.keys()))dn(e,{code:o,message:"Bridge handshake failed"})}},1e4)}function wn(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function yn(e,n,t=!1){const o=function(e){if(""===e)return[];if(!e.startsWith("/"))throw new Error(`Invalid JSON pointer: ${e}`);return e.split("/").slice(1).map(wn)}(n);if(0===o.length)return{container:{$root:e},key:"$root"};let r=e;for(let e=0;e<o.length-1;e++){const n=o[e];if(Array.isArray(r))r=r[Number(n)];else{if(!r||"object"!=typeof r)throw new Error(`Invalid container at ${n}`);{const i=r;if(t&&void 0===i[n]){const t=o[e+1];i[n]=t&&/^\d+$/.test(t)?[]:{}}r=i[n]}}}return{container:r,key:o[o.length-1]}}function bn(e){en.forEach(n=>{try{if(!nn.has(n))return nn.set(n,!0),void n(le(Ze),{rev:Qe,initial:!0});n(le(Ze),{rev:Qe,initial:e})}catch(e){ie("Subscriber error:",e)}})}function xn(e){if("function"!=typeof e)return()=>{};if(en.add(e),Qe>=0){nn.set(e,!0);try{e(le(Ze),{rev:Qe,initial:!0})}catch(e){se("Callback error:",e)}}return()=>{en.delete(e),nn.delete(e)}}function kn(e){On.call("state.getSnapshot",{scope:e}).catch(()=>{})}function En(e){let n=e;if("v2"===Z.kind&&"string"==typeof n)try{n=JSON.parse(n)}catch{n=null}if("v2"===Z.kind&&n&&"object"==typeof n){const e=n;if("event"===e.type&&"nativecomponent"===e.name&&e.payload){const n=e.payload,t=n.id||n.componentId;if("string"==typeof t){const e=_n.get(t);if(e)try{e(n)}catch(e){se("NC handler error:",e)}}return}}const t=function(e){if("blocked"===Z.kind)return null;if("required-v3"===Z.kind){const n="string"==typeof e?e:ae(e),t=Z.codec.parse(n);return t.ok?{v:3,kind:t.value.kind,...t.value.payload}:null}if("string"==typeof e)try{e=JSON.parse(e)}catch{return null}if(!e||"object"!=typeof e)return null;const n=e.v,t=e.kind;return 2!==n||"string"!=typeof t?null:e}(n);if(t)switch(t.kind){case"helloAck":return t.protocol!==("required-v3"===Z.kind?3:2)||t.nonce!==(y.nonce||"")?void ie("Invalid helloAck"):"required-v3"===Z.kind?void($e=!0):Fe&&t.sessionId!==Fe?void ie("sessionId mismatch"):(Fe||(Fe=t.sessionId),void($e=!0));case"ready":if(!$e)return;return"v2"===Z.kind&&Fe&&t.sessionId!==Fe?void ie("sessionId mismatch"):(gn(),Xe=!0,ze=0,oe("proto")&&re("Handshake complete, host routes:",Object.keys(t.hostMethods||{}).length+(t.hostChannels||[]).length),void function(){if(ln())for(;Ke.length;){const e=Ke.shift();e&&(e.reqId&&fn(e.reqId),hn(je(e.msg),e.reqId))}}());case"res":{const e=Ve.get(t.id);if(!e)return;if(Ve.delete(t.id),null!==e.timerId&&clearTimeout(e.timerId),t.ok){if("state.getSnapshot"===e.method&&(function(e){if(!e||"object"!=typeof e)return!1;const n=e;return!("number"!=typeof n.rev||!Number.isFinite(n.rev)||!n.state||"object"!=typeof n.state||(Ze=n.state,Qe=n.rev,oe("data")&&(Y.group("[LX] snapshot(res)"),Y.log("rev:",Qe,"state:",le(Ze)),Y.groupEnd()),bn(!0),0))}(t.result)||ie("Invalid state.getSnapshot result")),"stream"===e.mode&&e.stream)return void e.stream._resolve(t.result);e.resolve?.(t.result)}else{const n=f(t.error);if("stream"===e.mode&&e.stream)return void e.stream._reject(n);e.reject?.(n)}return}case"event":if(Ve.has(t.id)){const e=Ve.get(t.id);return void("stream"===e?.mode&&e.stream?(null!==e.timerId&&(clearTimeout(e.timerId),e.timerId=null),e.timeoutMs=0,e.stream._emitData(t.payload)):ie(`Received event for non-stream request '${t.id}'`))}return;case"state.snapshot":return Ze=t.state||{},Qe=t.rev,oe("data")&&(Y.group("[LX] snapshot"),Y.log("rev:",Qe,"state:",le(Ze)),Y.groupEnd()),void bn(!0);case"state.patch":if(t.baseRev!==Qe)return ie("baseRev mismatch",{have:Qe,want:t.baseRev}),void kn(t.scope);try{!function(e,n){for(const t of n){const n="add"===t.op||"replace"===t.op,{container:o,key:r}=yn(e,t.path,n);if("$root"===r){for(const n of Object.keys(e))delete e[n];if("remove"!==t.op){const n=t.value;n&&"object"==typeof n&&Object.assign(e,n)}continue}if(Array.isArray(o)){const e="-"===r?o.length:Number(r);if(!Number.isFinite(e)||e<0)throw new Error("Invalid index");"remove"===t.op?o.splice(e,1):"add"===t.op?o.splice(e,0,t.value):"replace"===t.op&&(o[e]=t.value);continue}if(!o||"object"!=typeof o)throw new Error("Invalid container");const i=o;"remove"===t.op?delete i[r]:i[r]=t.value}}(Ze,t.ops||[]),Qe=t.rev}catch(e){return se("Patch failed:",e),void kn(t.scope)}return oe("data")&&(Y.group("[LX] patch"),Y.log("rev:",Qe,"ops:",t.ops),Y.groupEnd()),bn(!1),void(t.ack&&pn({v:2,kind:"state.ack",scope:t.scope,rev:t.rev}));case"ch.ack":{const e=Je.get(t.id);if(!e)return;if(Je.delete(t.id),null!==e.timerId&&clearTimeout(e.timerId),t.ok)e.channel._markOpen(),Ye.set(t.id,e.channel),e.resolve(e.channel);else{const n=f(t.error);e.channel._reject(n),e.reject(n)}return}case"ch.data":{const e=Ye.get(t.id);if(!e)return;return void e._emitData(t.payload)}case"ch.close":{if(Je.get(t.id))return void dn(t.id,{code:t.code??c,message:t.reason??"Channel closed before opening"});const e=Ye.get(t.id);if(!e)return;return Ye.delete(t.id),void e._emitClose(t.code,t.reason)}case"req":{const e=t,n=rn(e.method);if(!e.cap||e.cap!==n)return void pn({v:2,kind:"res",id:e.id,ok:!1,error:{code:s,message:`Invalid cap for ${e.method}`}});const o=tn.get(e.method);return o?void Promise.resolve().then(()=>o(e.params)).then(n=>{pn({v:2,kind:"res",id:e.id,ok:!0,result:n})}).catch(n=>{pn({v:2,kind:"res",id:e.id,ok:!1,error:f(n)})}):void pn({v:2,kind:"res",id:e.id,ok:!1,error:{code:i,message:`View handler not found: ${e.method}`}})}}else ie("Invalid bridge message")}const _n=new Map,In=[];let Cn=!1;function Ln(){return"undefined"!=typeof window&&!!(window.webkit?.messageHandlers?.NativeComponent||window.NativeComponentBridge?.postMessage||window.LingXiaProxy?.nativeComponentUpdate)}function Sn(e){try{if(window.webkit?.messageHandlers?.NativeComponent)return void window.webkit.messageHandlers.NativeComponent.postMessage(e);if(window.NativeComponentBridge?.postMessage)return void window.NativeComponentBridge.postMessage(ae(e));const n=window.LingXiaProxy?.nativeComponentUpdate;if("function"==typeof n){const t=e.id||"island",o=ae({...e,componentId:t});try{n.call(window.LingXiaProxy,o)}catch{n.call(window.LingXiaProxy,t,o)}return}}catch(e){se("NativeComponent send error:",e)}}function Tn(){if(Ln()&&0!==In.length)for(Cn=!0;In.length;){const e=In.shift();try{Sn(e)}catch{break}}}function Nn(e){try{if(!Ln())return void In.push(e);Cn||Tn(),Sn(e)}catch(e){se("NC send failed:",e)}}function An(e){return`${e}_${Date.now()}_${Ue++}`}function Mn(e,n,t){if(!n)return;if(n.aborted)return void t();let o={handleEvent:()=>{n.removeEventListener("abort",o),t()}};n.addEventListener("abort",o)}const On={call:(e,n,o)=>new Promise((i,s)=>{if(!e||"string"!=typeof e)return void s({code:r,message:"Method name must be a non-empty string"});qe||vn();const a=An("c"),l=o?.cap||rn(e),c=o?.timeoutMs??G;Ve.set(a,{method:e,mode:"call",resolve:i,reject:e=>s(e),timeoutMs:c,timerId:null}),pn({v:2,kind:"req",id:a,method:e,params:sn(n),cap:l},a),Mn(0,o?.signal,()=>{const e=mn(a);cn(a,{code:t,message:"Bridge request aborted"}),!e&&Xe&&pn({v:2,kind:"cancel",id:a})})}),stream(e,n,o){if(!e||"string"!=typeof e){const e=We("invalid",()=>{});return e._reject({code:r,message:"Method name must be a non-empty string"}),e}qe||vn();const i=An("c"),s=We(i,()=>{mn(i)?cn(i,{code:t,message:"Bridge request aborted"}):Xe&&pn({v:2,kind:"cancel",id:i})}),a=o?.cap||rn(e),l=o?.timeoutMs??G;return Ve.set(i,{method:e,mode:"stream",stream:s,timeoutMs:l,timerId:null}),pn({v:2,kind:"req",id:i,method:e,params:sn(n),cap:a},i),Mn(0,o?.signal,()=>s.cancel()),s},notify(e,n,t){e&&"string"==typeof e&&(qe||vn(),pn({v:2,kind:"notify",method:e,params:sn(n),cap:t?.cap||rn(e)}))},state:{subscribe:xn},channel:{open:(e,n,t)=>e&&"string"==typeof e?(qe||vn(),new Promise((o,r)=>{const i=An("ch"),s=function(e,n,t){const o=He();let r=!1,i=0,s=!1,a=!1,l=!1;const d=[],u=[],f={id:e,send(t){r?n(t,i++):f._reject({code:c,message:`Channel '${e}' is closed`})},on(e,n){if("data"===e&&(o.data.add(n),d.length>0)){const e=d.splice(0);for(const t of e)try{n(t)}catch(e){ie("Channel listener failed:",e)}}return"close"===e&&o.close.add(n),"error"===e&&o.error.add(n),this},[Symbol.asyncIterator]:()=>(l=!0,{next:()=>d.length>0?Promise.resolve({done:!1,value:d.shift()}):s?Promise.resolve({done:!0,value:void 0}):new Promise((e,n)=>{u.push({resolve:e,reject:n})}),return:()=>(l=!1,d.length=0,f.close(),Promise.resolve({done:!0,value:void 0}))}),close(e,n){r&&(r=!1,t(e,n),f._emitClose(e,n))},_emitData(e){if(r){u.length>0?u.shift().resolve({done:!1,value:e}):(l||0===o.data.size)&&d.push(e);for(const n of o.data)try{n(e)}catch(e){ie("Channel listener failed:",e)}}},_emitClose(e,n){if(r=!1,s=!0,!a){for(a=!0;u.length>0;)u.shift().resolve({done:!0,value:void 0});for(const t of o.close)try{t(e,n)}catch(e){ie("Channel close listener failed:",e)}}},_reject(e){for(r=!1,s=!0;u.length>0;)u.shift().reject(e);for(const n of o.error)try{n(e)}catch(e){ie("Channel error listener failed:",e)}},_markOpen(){r=!0,s=!1},_isOpen:()=>r,_nextSeq:()=>i++};return f}(i,(e,n)=>{pn({v:2,kind:"ch.data",id:i,seq:n,payload:e})},(e,n)=>{const t=Je.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),Je.delete(i),Ye.delete(i),pn({v:2,kind:"ch.close",id:i,code:e,reason:n})});Je.set(i,{topic:e,channel:s,resolve:o,reject:r,timerId:null}),pn({v:2,kind:"ch.open",id:i,topic:e,params:sn(n),cap:t?.cap||rn(e)},i)})):Promise.reject({code:r,message:"Topic name must be a non-empty string"})}},Pn={invoke:(e,n,t)=>On.call(Dn(e),n,Bn(t)).then(e=>e).catch(e=>Promise.reject(m(e))),notify(e,n,t){On.notify(Dn(e),n,Bn(t))},stream:(e,n,t)=>jn(On.stream(Dn(e),n,Bn(t))),channel:(e,n,t)=>On.channel.open(Dn(e),n,Bn(t)).then(e=>function(e){const n=new Set,t=new Set;let o=[];return setTimeout(()=>{o=null},0),e.on("data",e=>{if(0!==n.size)for(const t of n)t(e);else o?.push(e)}),e.on("close",(e,n)=>{const o={code:e,reason:n};for(const e of t)e(o)}),{send(n){e.send(n)},onMessage(e){n.add(e);const t=o;o=null;for(const n of t??[])e(n);return()=>{n.delete(e)}},onClose:e=>(t.add(e),()=>{t.delete(e)}),close(n,t){e.close(n,t)}}}(e)).catch(e=>Promise.reject(m(e))),raw:On,state:{subscribe:xn},_connectWebMessagePort(e){if(ce===H){if(de&&de!==e)try{de.onmessage=null,de.close()}catch{}de=e,e.onmessage=e=>{En(e.data)};try{e.start()}catch{}re("Port connected"),vn()}},_receiveEvaluateMessage(e){e&&En(e)},debug:function(e){const n={};return Object.keys(e).forEach(t=>{Object.defineProperty(n,t,{enumerable:!0,configurable:!1,get:()=>e[t],set(n){e[t]=!!n,Y.log(`[LX] ${t}: ${n}`)}})}),n}(K),host:{get:D,subscribe:B},leaveGuard:{hold:X},platform:{isHarmony:function(){return"Harmony"===y.os},isIOS:C,isAndroid:function(){return"Android"===y.os},isMacOS:L,isWindows:function(){return"Windows"===y.os},isDesktop:S,isMobile:function(){return"mobile"===I()},isApple:function(){return C()||L()},isRunner:function(){return!0===y.runner},getOS:_},dom:{measureById(e){try{if(!e)return null;const n=document.getElementById(e);if(!n)return null;const t=n.getBoundingClientRect();let o=0;try{o=parseFloat(getComputedStyle(n).borderRadius)||0}catch{}return[t.left+window.scrollX,t.top+window.scrollY,t.width,t.height,o]}catch{return null}}},nativeComponents:{send:Nn,hasHandler:Ln,flush:Tn,register:(e,n)=>e&&"function"==typeof n?(_n.set(e,n),()=>_n.delete(e)):()=>{},unregister(e){_n.delete(e)}},isReady:()=>Xe};function Dn(e){return e.startsWith("host.")?e:`host.${e}`}function Bn(e){return{...e||{},cap:e?.cap||"host"}}function jn(e){const n=new Set,t=new Set;return e.on("data",e=>{for(const t of n)t(e)}),e.on("error",e=>{const n=m(e);for(const e of t)e(n)}),{onEvent:e=>(n.add(e),()=>{n.delete(e)}),onError:e=>(t.add(e),()=>{t.delete(e)}),result:e.result.catch(e=>Promise.reject(m(e))),cancel(){e.cancel()}}}function Rn(){if(window.__LX_BRIDGE_INIT_STATE)re(`Bridge already ${window.__LX_BRIDGE_INIT_STATE}, skipping duplicate init`);else{window.__LX_BRIDGE_INIT_STATE="initializing";try{if(!ee){const e=function(){if("undefined"==typeof window)return{kind:"absent"};const e=window.__LingXiaTakeControlBootstrap;if("function"!=typeof e)return{kind:"absent"};try{const n=e();if(!n||3!==n.requiredProtocol||"string"!=typeof n.publicSessionId||0===n.publicSessionId.length||"string"!=typeof n.secret||0===n.secret.length)return{kind:"blocked"};const t=w({sessionId:n.publicSessionId,secret:n.secret});return t.ok?{kind:"required",codec:t.value}:{kind:"blocked"}}catch{return{kind:"blocked"}}finally{try{delete window.__LingXiaTakeControlBootstrap}catch{}}}();Z="required"===e.kind?{kind:"required-v3",codec:e.codec}:{kind:"absent"===e.kind?"v2":"blocked"},ee=!0}if(function(){if("required-v3"===Z.kind)for(const e of["log","error","warn","info","debug"]){const n=Y[e];console[e]=(...t)=>{n(...t),Xe&&je({kind:"console",__lingxia_console__:!0,level:e,message:Re(t)})}}}(),re(`Method: ${ce}`),e=Pn._receiveEvaluateMessage,"undefined"!=typeof window&&(window[z]=n=>{te(e),e(n)},te(e)),Ce())Oe(),Ce()&&!ge&&null===xe&&(xe=setInterval(()=>{0!==we?Date.now()-we>35e3&&(ie("Apple downstream stale (no heartbeat), forcing reconnect"),De()):fe&&0!==ye&&Date.now()-ye>1e4&&(ie("Apple downstream did not connect, forcing reconnect"),De())},5e3)),Ce()&&"undefined"!=typeof document&&document.addEventListener("visibilitychange",Be);else if(ce===H){_e();const e=n=>{(function(){if(de)return Promise.resolve(de);if(ke.promise)return ke.promise;_e(),ke.promise=new Promise((e,n)=>{ke.resolve=n=>{Ie(),e(n)},ke.reject=e=>{Ie(),n(e)},ke.timer=window.setTimeout(()=>{ke.reject?.(new Error("MessagePort init timed out after 5000ms"))},5e3)});try{window.LingXiaProxy?.getPort("LingXiaPort")}catch(e){ke.reject?.(e)}return ke.promise})().catch(t=>{ie("Port init failed:",t),n<3&&window.setTimeout(()=>e(n+1),500*n)})};e(1)}else"webkit"===ce||ce===W||ce===V?vn():ie("Unknown method");window.LingXiaBridge=Pn,window.__lxForceDownstreamReconnect=De,p({os:_(),send:Nn}),window.__LX_BRIDGE_INIT_STATE="initialized",re("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}var e}}const Fn="\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";function $n(e){const n=document.createElement("div");return n.textContent=e,n.innerHTML}function Xn(e){!function({code:e,title:n,description:t,detail:o,reason:r}){const i=document.createElement("style");i.textContent=Fn,document.head.appendChild(i),document.body.innerHTML="",document.body.style.cssText="";const s=document.createElement("div");s.className="lx-error";let a=`<div class="lx-error-code">${$n(e)}</div>`;a+=`<h1 class="lx-error-title">${$n(n)}</h1>`,a+=`<p class="lx-error-desc">${$n(t)}</p>`,o&&(a+=`<div class="lx-error-path">${$n(o)}</div>`),r&&(a+=`<p class="lx-error-desc" style="margin-top:12px">${$n(r)}</p>`),s.innerHTML=a,document.body.appendChild(s)}({code:"404",title:"Page Not Found",description:"The page you're looking for doesn't exist.",detail:e.failedPath,reason:e.reason})}function qn(){const e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function zn(){return window.__LX_RUNTIME_CONFIG?.error||null}const Gn={handleEvent:()=>Un()};function Un(){if(qn()){const e=zn();e&&Xn(e)}}function Hn(){Rn(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Gn):Un()}const Wn="lx-action-sheet-style";let Vn=null;function Jn(e){const n=e,t=n?.itemList??[],o=n?.cancelText??"Cancel",r=n?.itemColor??"#007AFF",i=(Vn??Promise.resolve()).then(()=>Yn(t,o,r),()=>Yn(t,o,r));return Vn=i,i}function Yn(e,n,t){return new Promise(o=>{let r=!1;const i=S();!function(){if(document.getElementById(Wn))return;const e=document.createElement("style");e.id=Wn,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 300ms 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 300ms 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)}();const s=document.createElement("div");s.className="lx-as-backdrop";const a=document.createElement("div");a.className="lx-as-sheet",i&&a.classList.add("lx-as-desktop");const l=document.createElement("div");l.className="lx-as-container",i&&l.classList.add("lx-as-desktop"),e.forEach((e,n)=>{const o=document.createElement("button");o.className="lx-as-item",o.textContent=e,o.style.color=t,o.addEventListener("click",()=>u(n)),l.appendChild(o)});const c=document.createElement("div");c.className="lx-as-separator",l.appendChild(c);const d=document.createElement("button");function u(e){r||(r=!0,s.classList.remove("lx-as-visible"),a.classList.remove("lx-as-visible"),setTimeout(()=>{s.remove(),a.remove(),o({tapIndex:e})},300))}d.className="lx-as-item lx-as-cancel-btn",d.textContent=n,d.addEventListener("click",()=>u(-1)),l.appendChild(d),a.appendChild(l),document.body.appendChild(s),document.body.appendChild(a),requestAnimationFrame(()=>{s.classList.add("lx-as-visible"),a.classList.add("lx-as-visible")}),s.addEventListener("click",()=>u(-1))})}const Kn=200,Qn="lx-modal-style";let Zn=null;function et(e){const n=e,t=n?.title??"",o=n?.content??"",r=n?.showCancel??!0,i=n?.cancelText??"Cancel",s=n?.cancelColor,a=n?.confirmText??"OK",l=n?.confirmColor??"#007AFF",c=(Zn??Promise.resolve()).then(()=>nt(t,o,r,i,s,a,l),()=>nt(t,o,r,i,s,a,l));return Zn=c,c}function nt(e,n,t,o,r,i,s){return new Promise(a=>{let l=!1;!function(){if(document.getElementById(Qn))return;const e=document.createElement("style");e.id=Qn,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 200ms 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 200ms ease, opacity 200ms 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)}();const c=document.createElement("div");c.className="lx-modal-backdrop";const d=document.createElement("div");d.className="lx-modal-dialog";const u=document.createElement("div");u.className="lx-modal-body";const f=document.createElement("div");if(f.className="lx-modal-title",f.textContent=e,u.appendChild(f),n){const e=document.createElement("p");e.className="lx-modal-content",e.textContent=n,u.appendChild(e)}d.appendChild(u);const m=document.createElement("div");if(m.className="lx-modal-footer",t){const e=document.createElement("button");e.className="lx-modal-btn lx-modal-btn-cancel",e.textContent=o,r&&(e.style.color=r),e.addEventListener("click",()=>h(!1)),m.appendChild(e)}const p=document.createElement("button");function h(e){l||(l=!0,c.classList.remove("lx-modal-visible"),setTimeout(()=>{c.remove(),a({confirm:e,cancel:!e})},Kn))}p.className="lx-modal-btn lx-modal-btn-confirm",p.textContent=i,p.style.color=s,p.addEventListener("click",()=>h(!0)),m.appendChild(p),d.appendChild(m),c.appendChild(d),document.body.appendChild(c),requestAnimationFrame(()=>{c.classList.add("lx-modal-visible")})})}const tt="lx-toast-style";let ot=null;function rt(e){const n=e,t=n?.title??"",o=n?.icon??"none",r=n?.duration??1500,i=n?.mask??!1,s=n?.position??"center";if(ot&&ot.icon===o&&ot.position===s&&ot.mask===i){const e=ot;return e.titleEl.textContent=t,e.timer&&clearTimeout(e.timer),e.timer=r>0?setTimeout(e.dismiss,r):null,Promise.resolve()}ot&&(ot.dismiss(),ot=null),function(){if(document.getElementById(tt))return;const e=document.createElement("style");e.id=tt,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 200ms ease, opacity 200ms 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)}();let a=null;i&&(a=document.createElement("div"),a.className="lx-toast-mask",document.body.appendChild(a));const l=document.createElement("div");l.className="lx-toast-container","top"===s?l.classList.add("lx-toast-top"):"bottom"===s?l.classList.add("lx-toast-bottom"):l.classList.add("lx-toast-center");const c=document.createElement("div");c.className="lx-toast-box";const d="none"!==o;if(d||c.classList.add("lx-toast-no-icon"),d){const e=document.createElement("div");e.className="lx-toast-icon","success"===o?e.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"===o?e.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"===o&&(e.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>'),c.appendChild(e)}const u=document.createElement("div");u.className="lx-toast-title",u.textContent=t,c.appendChild(u),l.appendChild(c),document.body.appendChild(l),requestAnimationFrame(()=>{c.classList.add("lx-toast-visible")});let f=!1;function m(){f||(f=!0,p.timer&&clearTimeout(p.timer),ot===p&&(ot=null),c.classList.remove("lx-toast-visible"),setTimeout(()=>{l.remove(),a?.remove()},200))}const p={dismiss:m,timer:null,titleEl:u,icon:o,position:s,mask:i};return r>0&&(p.timer=setTimeout(m,r)),ot=p,Promise.resolve()}function it(){return ot&&(ot.dismiss(),ot=null),Promise.resolve()}return on("ui.showActionSheet",Jn),on("ui.showModal",et),on("ui.showToast",rt),on("ui.hideToast",it),Hn(),e.LingXiaBridge=Pn,e.boot=function(){Rn(),Un()},e.bootWhenReady=Hn,e.channel=function(e,n,t){return Pn.channel(e,n,t)},e.getErrorInfo=zn,e.getHost=D,e.hasError=qn,e.holdLeaveGuard=X,e.initBridge=Rn,e.invoke=function(e,n,t){return Pn.invoke(e,n,t)},e.isNativeError=function(e,n){if(!e||"object"!=typeof e)return!1;const 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){On.notify(Dn(e),n,Bn(t))},e.renderErrorUI=Xn,e.renderPageFault=function(e,n){const t=document.createElement("style");t.textContent=`\n.lx-page-fault { position: fixed; inset: 0; z-index: 2147483647; overflow: auto;\n background: #fff; color: #1d1d1f; }\n@media (prefers-color-scheme: dark) { .lx-page-fault { background: #000; color: #f5f5f7; } }\n${Fn.replace(/\bbody\b/g,".lx-page-fault")}`,document.head.appendChild(t);const o=document.createElement("div");o.className="lx-page-fault",o.setAttribute("role","alert");const r=document.createElement("div");r.className="lx-error";let i='<div class="lx-error-code">Page</div>';return i+=`<h1 class="lx-error-title">${$n("This page couldn't start")}</h1>`,i+=`<p class="lx-error-desc">${$n("Its Logic has not delivered the page state. Check the Logic log for an error.")}</p>`,e&&(i+=`<div class="lx-error-path">${$n(e)}</div>`),i+=`<p class="lx-error-desc" style="margin-top:12px">${$n(n)}</p>`,r.innerHTML=i,o.appendChild(r),document.body.appendChild(o),()=>{o.remove(),t.remove()}},e.stream=function(e,n,t){return jn(On.stream(Dn(e),n,Bn(t)))},e.subscribeHost=B,e}({});
|
|
@@ -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 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{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(a,l)}c((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=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(c){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,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=n.call(e,i)}catch(e){l=[6,e],r=0}finally{t=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,c])}}},__rest=this&&this.__rest||function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t},__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){var n;Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t="BRIDGE_TIMEOUT",r="BRIDGE_CANCELED",o="BRIDGE_HANDSHAKE_FAILED",i="BRIDGE_MALFORMED_MESSAGE",a="BRIDGE_METHOD_NOT_FOUND",l="BRIDGE_CAPABILITY_DENIED",c="BRIDGE_INTERNAL_ERROR",s="BRIDGE_OUTBOX_FULL",d="BRIDGE_STREAM_CLOSED",u="BRIDGE_MESSAGE_TOO_LARGE",f=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 v(e){if(e instanceof f)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 f(t,r,"data"in n?n.data:void 0)}var o=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new f(c,o)}function p(e){var n=v(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 h(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 l={handleEvent:function(){(a.hasAnyVideo||0!==a.coveredById.size)&&u()}},c={handleEvent:function(){return u()}};window.addEventListener("scroll",l,{capture:!0,passive:!0}),window.addEventListener("resize",c),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 l=i[t];if(h=l.id){n.add(h);var c=s(l),d=a.coveredById.get(h);d!==c&&(!0===d&&(a.coveredCount-=1),!0===c&&(a.coveredCount+=1),a.coveredById.set(h,c),r({id:h,action:"component.coverage",covered:c}))}}for(var u=[],f=0,v=a.coveredById.entries();f<v.length;f++){var p=v[f],h=p[0];c=p[1];n.has(h)||(u.push(h),!0===c&&(a.coveredCount-=1))}for(var g=0,m=u;g<m.length;g++){h=m[g];a.coveredById.delete(h),r({id:h,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 g=new Set(["hello","req","res","notify","cancel","ch.open","ch.data","ch.close","state.ack","console"]),m=new Set(["helloAck","ready","req","res","event","state.snapshot","state.patch","ch.ack","ch.data","ch.close"]);function y(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function w(e){if(!y(e)||"string"!=typeof e.sessionId||0===e.sessionId.length||"string"!=typeof e.secret||0===e.secret.length)return{ok:!1,error:"INVALID_DOCUMENT_BINDING"};var n=e.sessionId,t=e.secret;return{ok:!0,value:{encode:function(e,r){return g.has(e)&&y(r)?["v","kind","sessionId","secret"].some(function(e){return e in r})?{ok:!1,error:"SECURITY_FIELD_IN_PAYLOAD"}:{ok:!0,value:__assign(__assign({},r),{v:3,kind:e,sessionId:n,secret:t})}:{ok:!1,error:"INVALID_DOCUMENT_PAYLOAD"}},parse:function(e,t){if(void 0===t&&(t=65536),(new TextEncoder).encode(e).byteLength>t)return{ok:!1,error:"FRAME_TOO_LARGE"};if(function(e){for(var n,t=new Set(["v","kind","sessionId","secret"]),r=new Set,o=0,i=0;i<e.length;i++){var a=e[i];if("{"!==a&&"["!==a)if("}"!==a&&"]"!==a){if('"'===a){var l=i;for(i++;i<e.length;)if("\\"!==e[i]){if('"'===e[i])break;i++}else i+=2;if(i>=e.length)return!1;if(1===o){for(var c=i+1;/\s/.test(null!==(n=e[c])&&void 0!==n?n:"");)c++;if(":"===e[c]){var s=void 0;try{s=JSON.parse(e.slice(l,i+1))}catch(e){return!1}if("string"==typeof s&&t.has(s)){if(r.has(s))return!0;r.add(s)}}}}}else o--;else o++}return!1}(e))return{ok:!1,error:"MALFORMED_ENVELOPE"};var r;try{r=JSON.parse(e)}catch(e){return{ok:!1,error:"MALFORMED_ENVELOPE"}}if(!y(r))return{ok:!1,error:"MALFORMED_ENVELOPE"};if(3!==r.v)return{ok:!1,error:"UNSUPPORTED_VERSION"};if("string"!=typeof r.kind||!m.has(r.kind))return{ok:!1,error:"UNSUPPORTED_NATIVE_KIND"};if("string"!=typeof r.sessionId||0===r.sessionId.length)return{ok:!1,error:"MALFORMED_ENVELOPE"};if(r.sessionId!==n)return{ok:!1,error:"SESSION_MISMATCH"};if(Object.prototype.hasOwnProperty.call(r,"secret"))return{ok:!1,error:"UNEXPECTED_SECRET"};r.v,r.kind,r.sessionId;var o=__rest(r,["v","kind","sessionId"]);return{ok:!0,value:{kind:r.kind,payload:o}}}}}}var _="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{},b={value:(null===(n=_.displayLanguage)||void 0===n?void 0:n.trim())||"en-US",listeners:new Set};function k(){var e;return"undefined"==typeof window?b:(window.__lxDisplayLanguage||(window.__lxDisplayLanguage={value:(null===(e=_.displayLanguage)||void 0===e?void 0:e.trim())||"en-US",listeners:new Set}),window.__lxDisplayLanguage)}var I=new Set(["ar","ckb","dv","fa","he","ps","sd","ug","ur","yi"]);function E(){if("undefined"!=typeof document&&document.documentElement){var e=k().value;document.documentElement.lang=e,document.documentElement.dir=function(e){try{var n=new Intl.Locale(e),t="function"==typeof n.getTextInfo?n.getTextInfo():n.textInfo;if("rtl"===(null==t?void 0:t.direction)||"ltr"===(null==t?void 0:t.direction))return t.direction}catch(e){}return I.has(e.split(/[-_]/)[0].toLowerCase())?"rtl":"ltr"}(e)}}function x(){return _.os||"unknown"}function S(){return"mobile"===_.hostClass||"desktop"===_.hostClass?_.hostClass:"macOS"===_.os||"Windows"===_.os?"desktop":"mobile"}function L(){return"iOS"===_.os}function O(){return"macOS"===_.os}function C(){return"desktop"===S()}E(),"undefined"==typeof window||window.__lingxiaApplyDisplayLanguage||Object.defineProperty(window,"__lingxiaApplyDisplayLanguage",{configurable:!1,enumerable:!1,value:function(e,n){var t,r="string"==typeof e?e.trim():"",o=k();if("number"==typeof n&&Number.isFinite(n)){if(n<=(null!==(t=o.revision)&&void 0!==t?t:0))return;o.revision=n}if(r&&r!==o.value){o.value=r,E();for(var i=0,a=__spreadArray([],o.listeners,!0);i<a.length;i++){(0,a[i])(r)}}}});var A={sizeClass:"compact",width:0,height:0,aside:!1};function T(){var e;if("undefined"==typeof window)return M;if(!window.__lxSurfaceContext){var n=window.__LX_BRIDGE_CFG;window.__lxSurfaceContext={value:null!==(e=N(null==n?void 0:n.surfaceContext))&&void 0!==e?e:A,revision:"number"==typeof(null==n?void 0:n.surfaceContextRevision)?n.surfaceContextRevision:0,listeners:new Set}}return window.__lxSurfaceContext}var M={value:A,revision:0,listeners:new Set};function N(e){if("object"!=typeof e||null===e)return null;var n=e.sizeClass,t=e.width,r=e.height,o=e.aside;return"compact"!==n&&"regular"!==n||"number"!=typeof t||"number"!=typeof r?null:{sizeClass:n,width:t,height:r,aside:!0===o}}"undefined"==typeof window||window.__lingxiaApplySurfaceContext||Object.defineProperty(window,"__lingxiaApplySurfaceContext",{configurable:!1,enumerable:!1,value:function(e,n){var t=N(e),r=T();if(t){if("number"==typeof n){if(n<=r.revision)return;r.revision=n}if(o=r.value,i=t,o.sizeClass!==i.sizeClass||o.width!==i.width||o.height!==i.height||o.aside!==i.aside){var o,i;r.value=t;for(var a=0,l=__spreadArray([],r.listeners,!0);a<l.length;a++){(0,l[a])()}}}}});var P=null;function j(){var e=T().value;return{sizeClass:e.sizeClass,aside:e.aside,displayLanguage:k().value,formFactor:C()?"desktop":"mobile",os:x(),runner:!0===_.runner}}function D(){var e,n,t=j();return null!==P&&(n=t,(e=P).sizeClass===n.sizeClass&&e.aside===n.aside&&e.displayLanguage===n.displayLanguage&&e.formFactor===n.formFactor&&e.os===n.os&&e.runner===n.runner)||(P=t),P}function R(e){var n=D(),t=function(){var t=D();t!==n&&(n=t,e())},r=function(e){var n=k().listeners;return n.add(e),function(){n.delete(e)}}(t),o=function(e){var n=T().listeners;return n.add(e),function(){n.delete(e)}}(t);return function(){r(),o()}}var B="__LingXiaRecvMessage",X=5e3,F="[LX.Bridge]",q="messageport",G="jsinterface",U="webmessage",z=_.appleDownstreamURL,H={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:(console.info||console.log).bind(console),debug:(console.debug||console.log).bind(console),group:(console.group||console.log).bind(console),groupEnd:(console.groupEnd||function(){}).bind(console)},W={data:!1,proto:!1,all:!1},V=[],J={kind:"v2"},Y=!1;function $(){if("undefined"!=typeof window){var e=window.__LingXiaEarlyNativeMessages;if(Array.isArray(e)&&0!==e.length){window.__LingXiaEarlyNativeMessages=[];for(var n=0,t=e;n<t.length;n++){var r=t[n];"string"==typeof r&&V.push(r)}}}}function K(e){if($(),0!==V.length)for(var n=0,t=V.splice(0,V.length);n<t.length;n++){var r=t[n];try{e(r)}catch(e){ee("Failed to replay queued native message:",e)}}}function Q(e){return W.all||W[e]}function Z(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(!0===_.dev||W.all||W.proto||W.data)&&H.log.apply(H,__spreadArray([F],e,!1))}function ee(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];H.warn.apply(H,__spreadArray([F],e,!1))}function ne(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];H.error.apply(H,__spreadArray([F],e,!1))}function te(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 re(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch(e){return{}}}var oe=function(){var e,n;return"iOS"===_.os||"macOS"===_.os?"webkit":"Harmony"===_.os?"messageport":"Windows"===_.os?"webmessage":"Android"===_.os?(null===(n=null===(e=window.LingXiaProxy)||void 0===e?void 0:e.supportsMessagePort)||void 0===n?void 0:n.call(e))?"messageport":"jsinterface":"unknown"}();!function(){if("undefined"!=typeof window){$();var e=window[B];if("function"!=typeof e)window[B]=function(e){V.push(e)};else{if(0===V.length)return;for(var n=0,t=V.splice(0,V.length);n<t.length;n++){var r=t[n];try{e(r)}catch(e){ee("Failed to replay queued native message:",e)}}}}}();var ie=null,ae=!1,le=null,ce=null,se=null,de=200,ue=!1,fe=0,ve=0,pe=0,he="".concat(Date.now().toString(36)).concat(Math.random().toString(36).slice(2,10)),ge=null,me={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},ye={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&&(An._connectWebMessagePort(o),null===(t=me.resolve)||void 0===t||t.call(me,o))}}};function we(){me.listenerInstalled||(me.listenerInstalled=!0,window.addEventListener("message",ye))}function _e(){null!==me.timer&&(window.clearTimeout(me.timer),me.timer=null),me.resolve=null,me.reject=null,me.promise=null}function be(){return"webkit"===oe&&(L()||O())}function ke(){null!==se&&(clearTimeout(se),se=null)}function Ie(e){be()&&!ue&&(ue=!0,ke(),null!==ge&&(clearInterval(ge),ge=null),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",Te),Ce=!1,null==ce||ce.abort(),ae=!1,xe(e,!0))}function Ee(e){for(var n=0,t=Array.from(Ue.keys());n<t.length;n++){tn(t[n],{code:d,message:e})}for(var r=0,o=Array.from(ze.keys());r<o.length;r++){rn(o[r],{code:d,message:e})}!function(e){for(var n=0,t=Array.from(He.entries());n<t.length;n++){var r=t[n],o=r[0],i=r[1];He.delete(o),i._emitClose(d,e)}}(e)}function xe(e,n){dn(),"required-v3"!==J.kind&&(Pe=null),je=!1,De=!1,Re=!1,Be=0,n&&Ee(e)}function Se(e){if(e&&"object"==typeof e){ve=Date.now();var n=e;if(!0!==n.lxshutdown){if(void 0===n.lxhb){if(!0===n.lxreset)return fe=0,xe("Apple downstream reset",!0),void un();if("number"==typeof n.lxff){if(n.lxff<=fe)return;return fe=n.lxff,void mn(n.m)}mn(e)}}else Ie("Apple downstream closed")}}function Le(){return __awaiter(this,void 0,void 0,function(){var e,n,t,r,o,i,a,l,c,s,d;return __generator(this,function(u){switch(u.label){case 0:if(!z)throw new Error("Apple downstream URL is not configured");return e=new AbortController,ce=e,n=z.includes("?")?"&":"?",t="".concat(z).concat(n,"from=").concat(fe,"&doc=").concat(he),pe=Date.now(),[4,fetch(t,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal})];case 1:if(!(r=u.sent()).ok)throw new Error("Apple downstream HTTP ".concat(r.status));if("1"===r.headers.get("X-LingXia-Bridge-Shutdown"))return Ie("Apple downstream closed"),[2];if(!r.body)throw new Error("Apple downstream response body unavailable");ae=!0,de=200,ve=Date.now(),Q("proto")&&Z("Apple downstream connected"),un(),o=r.body.getReader(),i=new TextDecoder,a="",u.label=2;case 2:u.trys.push([2,6,7,8]),u.label=3;case 3:return[4,o.read()];case 4:return l=u.sent(),c=l.value,l.done?[3,5]:(a=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{Se(JSON.parse(r))}catch(e){ee("Apple downstream parse error:",e,r)}}return n}(a+=i.decode(c,{stream:!0})),[3,3]);case 5:if(a+=i.decode(),s=a.trim())try{Se(JSON.parse(s))}catch(e){ee("Apple downstream trailing parse error:",e,s)}return[3,8];case 6:if(d=u.sent(),e.signal.aborted)return[2];throw d;case 7:try{o.releaseLock()}catch(e){}return[7];case 8:return[2]}})})}function Oe(){if(be()&&!ue&&!le){ke();var e=!1;le=Le().then(function(){e=!0}).catch(function(e){(null==ce?void 0:ce.signal.aborted)||ee("Apple downstream failed:",e)}).finally(function(){var n,t=null!==(n=null==ce?void 0:ce.signal.aborted)&&void 0!==n&&n;le=null,ce=null,ae=!1,t||ue||function(e,n){if(void 0===n&&(n=!1),be()&&!ue){ke();var t=n?0:de;n||(de=Math.min(2*de,2e3));var r=n?"Apple downstream completed, reconnecting immediately: ".concat(e):"Apple downstream disconnected, retrying in ".concat(t,"ms: ").concat(e);t<=200?Z(r):ee(r),se=setTimeout(function(){se=null,Oe()},t)}}("stream closed",e)})}}var Ce=!1;function Ae(){if(be()&&!ue&&!Ce){Ce=!0;var e=le;null==ce||ce.abort();var n=function(){Ce=!1,Oe()};e?e.finally(n):n()}}function Te(){"visible"===document.visibilityState&&Ae()}function Me(e){var n,t,r,o=function(e){if("blocked"===J.kind)return null;if("v2"===J.kind)return e;if(!e||"object"!=typeof e)return null;e.v;var n=e.kind,t=__rest(e,["v","kind"]);if("string"!=typeof n)return null;var r=J.codec.encode(n,t);return r.ok?r.value:null}(e);if(!o)return null;var i=e.kind;"req"!==i&&"notify"!==i||Z("postToNative: ".concat(i," ").concat(e.method)),Q("proto")&&H.log("→",JSON.stringify(e,null,2));try{var a=te(o),l=function(e){if("function"==typeof TextEncoder)return(new TextEncoder).encode(e).length;for(var n=0,t=0;t<e.length;t+=1){var r=e.charCodeAt(t);r<128?n+=1:r<2048?n+=2:r>=55296&&r<=56319?(n+=4,t+=1):n+=3}return n}(a);if(l>65536)return{code:u,message:"Bridge message of ".concat(l," bytes exceeds the ").concat(65536,"-byte native limit")};if("webkit"===oe)return null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers.LingXia)||void 0===t||t.postMessage(a),null;if(oe===q&&ie)return ie.postMessage(a),null;if((oe===G||oe===U)&&(null===(r=window.LingXiaProxy)||void 0===r?void 0:r.postMessage))return window.LingXiaProxy.postMessage(a),null;ee("Transport not ready")}catch(e){"required-v3"===J.kind?ne("Send error"):ne("Send error:",e)}return null}function Ne(e){var n=e.map(function(e){if("string"==typeof e)return e;try{var n=te(e);return"string"==typeof n?n:String(e)}catch(e){return"[Unserializable]"}}).join(" ");return n.length<=12288?n:"".concat(n.slice(0,12288),"…")}var Pe=null,je=!1,De=!1,Re=!1,Be=0,Xe=null,Fe=0;function qe(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function Ge(e,n){var t,r=qe(),o=!1,i=!1,a=function(){},l=function(){},c=[],s=[],d=new Promise(function(e,n){a=e,l=n}),u=((t={id:e,result:d,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 i=!0,{next:function(){return c.length>0?Promise.resolve({done:!1,value:c.shift()}):o?d.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})})},return:function(){return i=!1,c.length=0,d.catch(function(){}),u.cancel(),Promise.resolve({done:!0,value:void 0})}}},t.cancel=function(){o||n()},t._emitData=function(e){if(!o){s.length>0?s.shift().resolve({done:!1,value:e}):i&&c.push(e);for(var n=0,t=r.data;n<t.length;n++){var a=t[n];try{a(e)}catch(e){ee("Stream data listener failed:",e)}}}},t._resolve=function(e){if(!o){for(o=!0,a(e);s.length>0;)s.shift().resolve({done:!0,value:e});for(var n=0,t=r.end;n<t.length;n++){var i=t[n];try{i(e)}catch(e){ee("Stream end listener failed:",e)}}}},t._reject=function(e){if(!o){for(o=!0,l(e);s.length>0;)s.shift().reject(e);for(var n=0,t=r.error;n<t.length;n++){var i=t[n];try{i(e)}catch(e){ee("Stream error listener failed:",e)}}}},t);return u}var Ue=new Map,ze=new Map,He=new Map,We=[],Ve=-1,Je={},Ye=new Set,$e=new WeakMap,Ke=new Map;function Qe(e){if(e.startsWith("host."))return"host";var n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function Ze(e){if(null!=e)return e}function en(){return oe===q?!!ie:be()?ae:"webkit"===oe||oe===G||oe===U}function nn(){return!!De&&(!!be()||en())}function tn(e,n){var t,r=Ue.get(e);if(r){Ue.delete(e),null!==r.timerId&&clearTimeout(r.timerId);var o=v(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 rn(e,n){var t=ze.get(e);if(t){ze.delete(e),null!==t.timerId&&clearTimeout(t.timerId);var r=v(n);t.channel._reject(r),t.reject(r)}}function on(e,n){Ue.has(e)?tn(e,n):ze.has(e)&&rn(e,n)}function an(e){if(Ue.has(e))return n=e,void((r=Ue.get(n))&&(!Number.isFinite(r.timeoutMs)||r.timeoutMs<=0?null!==r.timerId&&(clearTimeout(r.timerId),r.timerId=null):(null!==r.timerId&&clearTimeout(r.timerId),r.timerId=setTimeout(function(){Ue.has(n)&&tn(n,{code:t,message:"'".concat(r.method,"' timed out")})},r.timeoutMs))));var n,r;ze.has(e)&&function(e){var n=ze.get(e);n&&(null!==n.timerId&&clearTimeout(n.timerId),n.timerId=setTimeout(function(){rn(e,{code:t,message:"Channel '".concat(n.topic,"' timed out")})},X))}(e)}function ln(e){for(var n,t=We.length-1;t>=0;t--)if((null===(n=We[t])||void 0===n?void 0:n.reqId)===e)return We.splice(t,1),!0;return!1}function cn(e,n){var t=e.kind,r="hello"===t||"helloAck"===t||"ready"===t;if(!nn()&&!r)return We.length>=256?(ne("Outbox full"),void(n&&on(n,{code:s,message:"Bridge outbox is full"}))):void We.push({msg:e,reqId:n});n&&an(n),sn(Me(e),n)}function sn(e,n){e&&(ne(e.message),n&&on(n,e))}function dn(){null!==Xe&&(clearTimeout(Xe),Xe=null)}function un(){if(!De&&Y&&"blocked"!==J.kind&&en()){dn();var e={v:2,kind:"hello",nonce:_.nonce||"",role:"view",protocolsSupported:"required-v3"===J.kind?[3]:[2]};Re=!0,Me(e),Xe=setTimeout(function(){if(!De)if(++Be<3)ee("Handshake timeout (".concat(Be,"/").concat(3,"), retrying...")),Re=!1,un();else{for(ne("Handshake failed"),dn(),Re=!1,Be=0;We.length;){var e=We.shift();(null==e?void 0:e.reqId)&&on(e.reqId,{code:o,message:"Bridge handshake failed"})}for(var n=0,t=Array.from(ze.keys());n<t.length;n++){rn(t[n],{code:o,message:"Bridge handshake failed"})}}},1e4)}}function fn(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function vn(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(fn)}(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 l=o;if(t&&void 0===l[a]){var c=r[i+1];l[a]=c&&/^\d+$/.test(c)?[]:{}}o=l[a]}}return{container:o,key:r[r.length-1]}}function pn(e){Ye.forEach(function(n){try{if(!$e.has(n))return $e.set(n,!0),void n(re(Je),{rev:Ve,initial:!0});n(re(Je),{rev:Ve,initial:e})}catch(e){ee("Subscriber error:",e)}})}function hn(e){if("function"!=typeof e)return function(){};if(Ye.add(e),Ve>=0){$e.set(e,!0);try{e(re(Je),{rev:Ve,initial:!0})}catch(e){ne("Callback error:",e)}}return function(){Ye.delete(e),$e.delete(e)}}function gn(e){Cn.call("state.getSnapshot",{scope:e}).catch(function(){})}function mn(e){var n,t,r,o,i=e;if("v2"===J.kind&&"string"==typeof i)try{i=JSON.parse(i)}catch(e){i=null}if("v2"===J.kind&&i&&"object"==typeof i){var c=i;if("event"===c.type&&"nativecomponent"===c.name&&c.payload){var s=c.payload,u=s.id||s.componentId;if("string"==typeof u){var f=yn.get(u);if(f)try{f(s)}catch(e){ne("NC handler error:",e)}}return}}var p=function(e){if("blocked"===J.kind)return null;if("required-v3"===J.kind){var n="string"==typeof e?e:te(e),t=J.codec.parse(n);return t.ok?__assign({v:3,kind:t.value.kind},t.value.payload):null}if("string"==typeof e)try{e=JSON.parse(e)}catch(e){return null}if(!e||"object"!=typeof e)return null;var r=e.v,o=e.kind;return 2!==r||"string"!=typeof o?null:e}(i);if(p)switch(p.kind){case"helloAck":return p.protocol!==("required-v3"===J.kind?3:2)||p.nonce!==(_.nonce||"")?void ee("Invalid helloAck"):"required-v3"===J.kind?void(je=!0):Pe&&p.sessionId!==Pe?void ee("sessionId mismatch"):(Pe||(Pe=p.sessionId),void(je=!0));case"ready":if(!je)return;return"v2"===J.kind&&Pe&&p.sessionId!==Pe?void ee("sessionId mismatch"):(dn(),De=!0,Be=0,Q("proto")&&Z("Handshake complete, host routes:",Object.keys(p.hostMethods||{}).length+(p.hostChannels||[]).length),void function(){if(nn())for(;We.length;){var e=We.shift();e&&(e.reqId&&an(e.reqId),sn(Me(e.msg),e.reqId))}}());case"res":var h=Ue.get(p.id);if(!h)return;if(Ue.delete(p.id),null!==h.timerId&&clearTimeout(h.timerId),p.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||(Je=n.state,Ve=n.rev,Q("data")&&(H.group("[LX] snapshot(res)"),H.log("rev:",Ve,"state:",re(Je)),H.groupEnd()),pn(!0),0))}(p.result)||ee("Invalid state.getSnapshot result")),"stream"===h.mode&&h.stream)return void h.stream._resolve(p.result);null===(n=h.resolve)||void 0===n||n.call(h,p.result)}else{var g=v(p.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(Ue.has(p.id)){var m=Ue.get(p.id);return void("stream"===(null==m?void 0:m.mode)&&m.stream?(null!==m.timerId&&(clearTimeout(m.timerId),m.timerId=null),m.timeoutMs=0,m.stream._emitData(p.payload)):ee("Received event for non-stream request '".concat(p.id,"'")))}return;case"state.snapshot":return Je=p.state||{},Ve=p.rev,Q("data")&&(H.group("[LX] snapshot"),H.log("rev:",Ve,"state:",re(Je)),H.groupEnd()),void pn(!0);case"state.patch":if(p.baseRev!==Ve)return ee("baseRev mismatch",{have:Ve,want:p.baseRev}),void gn(p.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=vn(e,o.path,i),l=a.container,c=a.key;if("$root"!==c)if(Array.isArray(l)){var s="-"===c?l.length:Number(c);if(!Number.isFinite(s)||s<0)throw new Error("Invalid index");"remove"===o.op?l.splice(s,1):"add"===o.op?l.splice(s,0,o.value):"replace"===o.op&&(l[s]=o.value)}else{if(!l||"object"!=typeof l)throw new Error("Invalid container");var d=l;"remove"===o.op?delete d[c]:d[c]=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)}}}}(Je,p.ops||[]),Ve=p.rev}catch(e){return ne("Patch failed:",e),void gn(p.scope)}return Q("data")&&(H.group("[LX] patch"),H.log("rev:",Ve,"ops:",p.ops),H.groupEnd()),pn(!1),void(p.ack&&cn({v:2,kind:"state.ack",scope:p.scope,rev:p.rev}));case"ch.ack":var y=ze.get(p.id);if(!y)return;if(ze.delete(p.id),null!==y.timerId&&clearTimeout(y.timerId),p.ok)y.channel._markOpen(),He.set(p.id,y.channel),y.resolve(y.channel);else{g=v(p.error);y.channel._reject(g),y.reject(g)}return;case"ch.data":var w=He.get(p.id);if(!w)return;return void w._emitData(p.payload);case"ch.close":if(ze.get(p.id))return void rn(p.id,{code:null!==(r=p.code)&&void 0!==r?r:d,message:null!==(o=p.reason)&&void 0!==o?o:"Channel closed before opening"});var b=He.get(p.id);if(!b)return;return He.delete(p.id),void b._emitClose(p.code,p.reason);case"req":var k=p,I=Qe(k.method);if(!k.cap||k.cap!==I)return void cn({v:2,kind:"res",id:k.id,ok:!1,error:{code:l,message:"Invalid cap for ".concat(k.method)}});var E=Ke.get(k.method);return E?void Promise.resolve().then(function(){return E(k.params)}).then(function(e){cn({v:2,kind:"res",id:k.id,ok:!0,result:e})}).catch(function(e){cn({v:2,kind:"res",id:k.id,ok:!1,error:v(e)})}):void cn({v:2,kind:"res",id:k.id,ok:!1,error:{code:a,message:"View handler not found: ".concat(k.method)}})}else ee("Invalid bridge message")}var yn=new Map,wn=[],_n=!1;function bn(){var e,n,t,r;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)||(null===(r=window.LingXiaProxy)||void 0===r?void 0:r.nativeComponentUpdate))}function kn(e){var n,t,r,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===(r=window.NativeComponentBridge)||void 0===r?void 0:r.postMessage)return void window.NativeComponentBridge.postMessage(te(e));var i=null===(o=window.LingXiaProxy)||void 0===o?void 0:o.nativeComponentUpdate;if("function"==typeof i){var a=e.id||"island",l=te(__assign(__assign({},e),{componentId:a}));try{i.call(window.LingXiaProxy,l)}catch(e){i.call(window.LingXiaProxy,a,l)}return}}catch(e){ne("NativeComponent send error:",e)}}function In(){if(bn()&&0!==wn.length)for(_n=!0;wn.length;){var e=wn.shift();try{kn(e)}catch(e){break}}}function En(e){try{if(!bn())return void wn.push(e);_n||In(),kn(e)}catch(e){ne("NC send failed:",e)}}function xn(e){return"".concat(e,"_").concat(Date.now(),"_").concat(Fe++)}function Sn(e,n,t){if(n)if(n.aborted)t();else{var r={handleEvent:function(){n.removeEventListener("abort",r),t()}};n.addEventListener("abort",r)}}var Ln,On,Cn={call:function(e,n,t){return new Promise(function(o,a){var l;if(e&&"string"==typeof e){Re||un();var c=xn("c"),s=(null==t?void 0:t.cap)||Qe(e),d=null!==(l=null==t?void 0:t.timeoutMs)&&void 0!==l?l:X;Ue.set(c,{method:e,mode:"call",resolve:o,reject:function(e){return a(e)},timeoutMs:d,timerId:null}),cn({v:2,kind:"req",id:c,method:e,params:Ze(n),cap:s},c),Sn(0,null==t?void 0:t.signal,function(){var e=ln(c);tn(c,{code:r,message:"Bridge request aborted"}),!e&&De&&cn({v:2,kind:"cancel",id:c})})}else a({code:i,message:"Method name must be a non-empty string"})})},stream:function(e,n,t){var o;if(!e||"string"!=typeof e){var a=Ge("invalid",function(){});return a._reject({code:i,message:"Method name must be a non-empty string"}),a}Re||un();var l=xn("c"),c=Ge(l,function(){ln(l)?tn(l,{code:r,message:"Bridge request aborted"}):De&&cn({v:2,kind:"cancel",id:l})}),s=(null==t?void 0:t.cap)||Qe(e),d=null!==(o=null==t?void 0:t.timeoutMs)&&void 0!==o?o:X;return Ue.set(l,{method:e,mode:"stream",stream:c,timeoutMs:d,timerId:null}),cn({v:2,kind:"req",id:l,method:e,params:Ze(n),cap:s},l),Sn(0,null==t?void 0:t.signal,function(){return c.cancel()}),c},notify:function(e,n,t){e&&"string"==typeof e&&(Re||un(),cn({v:2,kind:"notify",method:e,params:Ze(n),cap:(null==t?void 0:t.cap)||Qe(e)}))},state:{subscribe:hn},channel:{open:function(e,n,t){return e&&"string"==typeof e?(Re||un(),new Promise(function(r,o){var i=xn("ch"),a=function(e,n,t){var r,o=qe(),i=!1,a=0,l=!1,c=!1,s=!1,u=[],f=[],v=((r={id:e,send:function(t){i?n(t,a++):v._reject({code:d,message:"Channel '".concat(e,"' is closed")})},on:function(e,n){if("data"===e&&(o.data.add(n),u.length>0))for(var t=0,r=u.splice(0);t<r.length;t++){var i=r[t];try{n(i)}catch(e){ee("Channel listener failed:",e)}}return"close"===e&&o.close.add(n),"error"===e&&o.error.add(n),this}})[Symbol.asyncIterator]=function(){return s=!0,{next:function(){return u.length>0?Promise.resolve({done:!1,value:u.shift()}):l?Promise.resolve({done:!0,value:void 0}):new Promise(function(e,n){f.push({resolve:e,reject:n})})},return:function(){return s=!1,u.length=0,v.close(),Promise.resolve({done:!0,value:void 0})}}},r.close=function(e,n){i&&(i=!1,t(e,n),v._emitClose(e,n))},r._emitData=function(e){if(i){f.length>0?f.shift().resolve({done:!1,value:e}):(s||0===o.data.size)&&u.push(e);for(var n=0,t=o.data;n<t.length;n++){var r=t[n];try{r(e)}catch(e){ee("Channel listener failed:",e)}}}},r._emitClose=function(e,n){if(i=!1,l=!0,!c){for(c=!0;f.length>0;)f.shift().resolve({done:!0,value:void 0});for(var t=0,r=o.close;t<r.length;t++){var a=r[t];try{a(e,n)}catch(e){ee("Channel close listener failed:",e)}}}},r._reject=function(e){for(i=!1,l=!0;f.length>0;)f.shift().reject(e);for(var n=0,t=o.error;n<t.length;n++){var r=t[n];try{r(e)}catch(e){ee("Channel error listener failed:",e)}}},r._markOpen=function(){i=!0,l=!1},r._isOpen=function(){return i},r._nextSeq=function(){return a++},r);return v}(i,function(e,n){cn({v:2,kind:"ch.data",id:i,seq:n,payload:e})},function(e,n){var t=ze.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),ze.delete(i),He.delete(i),cn({v:2,kind:"ch.close",id:i,code:e,reason:n})});ze.set(i,{topic:e,channel:a,resolve:r,reject:o,timerId:null}),cn({v:2,kind:"ch.open",id:i,topic:e,params:Ze(n),cap:(null==t?void 0:t.cap)||Qe(e)},i)})):Promise.reject({code:i,message:"Topic name must be a non-empty string"})}}},An={invoke:function(e,n,t){return Cn.call(Tn(e),n,Mn(t)).then(function(e){return e}).catch(function(e){return Promise.reject(p(e))})},notify:function(e,n,t){Cn.notify(Tn(e),n,Mn(t))},stream:function(e,n,t){return Nn(Cn.stream(Tn(e),n,Mn(t)))},channel:function(e,n,t){return Cn.channel.open(Tn(e),n,Mn(t)).then(function(e){return function(e){var n=new Set,t=new Set,r=[];return setTimeout(function(){r=null},0),e.on("data",function(e){if(0!==n.size)for(var t=0,o=n;t<o.length;t++){(0,o[t])(e)}else null==r||r.push(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){n.add(e);var t=r;r=null;for(var o=0,i=null!=t?t:[];o<i.length;o++){var a=i[o];e(a)}return 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(p(e))})},raw:Cn,state:{subscribe:hn},_connectWebMessagePort:function(e){if(oe===q){if(ie&&ie!==e)try{ie.onmessage=null,ie.close()}catch(e){}ie=e,e.onmessage=function(e){mn(e.data)};try{e.start()}catch(e){}Z("Port connected"),un()}},_receiveEvaluateMessage:function(e){e&&mn(e)},debug:(Ln=W,On={},Object.keys(Ln).forEach(function(e){Object.defineProperty(On,e,{enumerable:!0,configurable:!1,get:function(){return Ln[e]},set:function(n){Ln[e]=!!n,H.log("[LX] ".concat(e,": ").concat(n))}})}),On),host:{get:D,subscribe:R},platform:{isHarmony:function(){return"Harmony"===_.os},isIOS:L,isAndroid:function(){return"Android"===_.os},isMacOS:O,isWindows:function(){return"Windows"===_.os},isDesktop:C,isMobile:function(){return"mobile"===S()},isApple:function(){return L()||O()},isRunner:function(){return!0===_.runner},getOS:x},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:En,hasHandler:bn,flush:In,register:function(e,n){return e&&"function"==typeof n?(yn.set(e,n),function(){return yn.delete(e)}):function(){}},unregister:function(e){yn.delete(e)}},isReady:function(){return De}};function Tn(e){return e.startsWith("host.")?e:"host.".concat(e)}function Mn(e){return __assign(__assign({},e||{}),{cap:(null==e?void 0:e.cap)||"host"})}function Nn(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=p(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(p(e))}),cancel:function(){e.cancel()}}}function Pn(){if(window.__LX_BRIDGE_INIT_STATE)Z("Bridge already ".concat(window.__LX_BRIDGE_INIT_STATE,", skipping duplicate init"));else{window.__LX_BRIDGE_INIT_STATE="initializing";try{if(!Y){var e=function(){if("undefined"==typeof window)return{kind:"absent"};var e=window.__LingXiaTakeControlBootstrap;if("function"!=typeof e)return{kind:"absent"};try{var n=e();if(!n||3!==n.requiredProtocol||"string"!=typeof n.publicSessionId||0===n.publicSessionId.length||"string"!=typeof n.secret||0===n.secret.length)return{kind:"blocked"};var t=w({sessionId:n.publicSessionId,secret:n.secret});return t.ok?{kind:"required",codec:t.value}:{kind:"blocked"}}catch(e){return{kind:"blocked"}}finally{try{delete window.__LingXiaTakeControlBootstrap}catch(e){}}}();J="required"===e.kind?{kind:"required-v3",codec:e.codec}:{kind:"absent"===e.kind?"v2":"blocked"},Y=!0}if(function(){if("required-v3"===J.kind)for(var e=function(e){var n=H[e];console[e]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];n.apply(void 0,t),De&&Me({kind:"console",__lingxia_console__:!0,level:e,message:Ne(t)})}},n=0,t=["log","error","warn","info","debug"];n<t.length;n++)e(t[n])}(),Z("Method: ".concat(oe)),t=An._receiveEvaluateMessage,"undefined"!=typeof window&&(window[B]=function(e){K(t),t(e)},K(t)),be())Oe(),be()&&!ue&&null===ge&&(ge=setInterval(function(){0!==ve?Date.now()-ve>35e3&&(ee("Apple downstream stale (no heartbeat), forcing reconnect"),Ae()):le&&0!==pe&&Date.now()-pe>1e4&&(ee("Apple downstream did not connect, forcing reconnect"),Ae())},5e3)),be()&&"undefined"!=typeof document&&document.addEventListener("visibilitychange",Te);else if(oe===q){we();var n=function(e){(function(){var e,n;if(ie)return Promise.resolve(ie);if(me.promise)return me.promise;we(),me.promise=new Promise(function(e,n){me.resolve=function(n){_e(),e(n)},me.reject=function(e){_e(),n(e)},me.timer=window.setTimeout(function(){var e;null===(e=me.reject)||void 0===e||e.call(me,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=me.reject)||void 0===n||n.call(me,e)}return me.promise})().catch(function(t){ee("Port init failed:",t),e<3&&window.setTimeout(function(){return n(e+1)},500*e)})};n(1)}else"webkit"===oe||oe===G||oe===U?un():ee("Unknown method");window.LingXiaBridge=An,window.__lxForceDownstreamReconnect=Ae,h({os:x(),send:En}),window.__LX_BRIDGE_INIT_STATE="initialized",Z("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}var t}}var jn="\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";function Dn(e){var n=document.createElement("div");return n.textContent=e,n.innerHTML}function Rn(e){!function(e){var n=e.code,t=e.title,r=e.description,o=e.detail,i=e.reason,a=document.createElement("style");a.textContent=jn,document.head.appendChild(a),document.body.innerHTML="",document.body.style.cssText="";var l=document.createElement("div");l.className="lx-error";var c='<div class="lx-error-code">'.concat(Dn(n),"</div>");c+='<h1 class="lx-error-title">'.concat(Dn(t),"</h1>"),c+='<p class="lx-error-desc">'.concat(Dn(r),"</p>"),o&&(c+='<div class="lx-error-path">'.concat(Dn(o),"</div>")),i&&(c+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Dn(i),"</p>")),l.innerHTML=c,document.body.appendChild(l)}({code:"404",title:"Page Not Found",description:"The page you're looking for doesn't exist.",detail:e.failedPath,reason:e.reason})}function Bn(){var e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function Xn(){var e;return(null===(e=window.__LX_RUNTIME_CONFIG)||void 0===e?void 0:e.error)||null}var Fn={handleEvent:function(){return qn()}};function qn(){if(Bn()){var e=Xn();e&&Rn(e)}}function Gn(){Pn(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Fn):qn()}return Gn(),e.LingXiaBridge=An,e.boot=function(){Pn(),qn()},e.bootWhenReady=Gn,e.channel=function(e,n,t){return An.channel(e,n,t)},e.getErrorInfo=Xn,e.getHost=D,e.hasError=Bn,e.initBridge=Pn,e.invoke=function(e,n,t){return An.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){Cn.notify(Tn(e),n,Mn(t))},e.renderErrorUI=Rn,e.renderPageFault=function(e,n){var t=document.createElement("style");t.textContent="\n.lx-page-fault { position: fixed; inset: 0; z-index: 2147483647; overflow: auto;\n background: #fff; color: #1d1d1f; }\n@media (prefers-color-scheme: dark) { .lx-page-fault { background: #000; color: #f5f5f7; } }\n".concat(jn.replace(/\bbody\b/g,".lx-page-fault")),document.head.appendChild(t);var r=document.createElement("div");r.className="lx-page-fault",r.setAttribute("role","alert");var o=document.createElement("div");o.className="lx-error";var i='<div class="lx-error-code">Page</div>';return i+='<h1 class="lx-error-title">'.concat(Dn("This page couldn't start"),"</h1>"),i+='<p class="lx-error-desc">'.concat(Dn("Its Logic has not delivered the page state. Check the Logic log for an error."),"</p>"),e&&(i+='<div class="lx-error-path">'.concat(Dn(e),"</div>")),i+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Dn(n),"</p>"),o.innerHTML=i,r.appendChild(o),document.body.appendChild(r),function(){r.remove(),t.remove()}},e.stream=function(e,n,t){return Nn(Cn.stream(Tn(e),n,Mn(t)))},e.subscribeHost=R,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{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(a,l)}c((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=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(c){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,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=n.call(e,i)}catch(e){l=[6,e],r=0}finally{t=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,c])}}},__rest=this&&this.__rest||function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t},__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){var n;Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t="BRIDGE_TIMEOUT",r="BRIDGE_CANCELED",o="BRIDGE_HANDSHAKE_FAILED",i="BRIDGE_MALFORMED_MESSAGE",a="BRIDGE_METHOD_NOT_FOUND",l="BRIDGE_CAPABILITY_DENIED",c="BRIDGE_INTERNAL_ERROR",s="BRIDGE_OUTBOX_FULL",d="BRIDGE_STREAM_CLOSED",u="BRIDGE_MESSAGE_TOO_LARGE",f=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 v(e){if(e instanceof f)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 f(t,r,"data"in n?n.data:void 0)}var o=e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";return new f(c,o)}function p(e){var n=v(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 h(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 l={handleEvent:function(){(a.hasAnyVideo||0!==a.coveredById.size)&&u()}},c={handleEvent:function(){return u()}};window.addEventListener("scroll",l,{capture:!0,passive:!0}),window.addEventListener("resize",c),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 l=i[t];if(h=l.id){n.add(h);var c=s(l),d=a.coveredById.get(h);d!==c&&(!0===d&&(a.coveredCount-=1),!0===c&&(a.coveredCount+=1),a.coveredById.set(h,c),r({id:h,action:"component.coverage",covered:c}))}}for(var u=[],f=0,v=a.coveredById.entries();f<v.length;f++){var p=v[f],h=p[0];c=p[1];n.has(h)||(u.push(h),!0===c&&(a.coveredCount-=1))}for(var g=0,m=u;g<m.length;g++){h=m[g];a.coveredById.delete(h),r({id:h,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 g=new Set(["hello","req","res","notify","cancel","ch.open","ch.data","ch.close","state.ack","console"]),m=new Set(["helloAck","ready","req","res","event","state.snapshot","state.patch","ch.ack","ch.data","ch.close"]);function y(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function w(e){if(!y(e)||"string"!=typeof e.sessionId||0===e.sessionId.length||"string"!=typeof e.secret||0===e.secret.length)return{ok:!1,error:"INVALID_DOCUMENT_BINDING"};var n=e.sessionId,t=e.secret;return{ok:!0,value:{encode:function(e,r){return g.has(e)&&y(r)?["v","kind","sessionId","secret"].some(function(e){return e in r})?{ok:!1,error:"SECURITY_FIELD_IN_PAYLOAD"}:{ok:!0,value:__assign(__assign({},r),{v:3,kind:e,sessionId:n,secret:t})}:{ok:!1,error:"INVALID_DOCUMENT_PAYLOAD"}},parse:function(e,t){if(void 0===t&&(t=65536),(new TextEncoder).encode(e).byteLength>t)return{ok:!1,error:"FRAME_TOO_LARGE"};if(function(e){for(var n,t=new Set(["v","kind","sessionId","secret"]),r=new Set,o=0,i=0;i<e.length;i++){var a=e[i];if("{"!==a&&"["!==a)if("}"!==a&&"]"!==a){if('"'===a){var l=i;for(i++;i<e.length;)if("\\"!==e[i]){if('"'===e[i])break;i++}else i+=2;if(i>=e.length)return!1;if(1===o){for(var c=i+1;/\s/.test(null!==(n=e[c])&&void 0!==n?n:"");)c++;if(":"===e[c]){var s=void 0;try{s=JSON.parse(e.slice(l,i+1))}catch(e){return!1}if("string"==typeof s&&t.has(s)){if(r.has(s))return!0;r.add(s)}}}}}else o--;else o++}return!1}(e))return{ok:!1,error:"MALFORMED_ENVELOPE"};var r;try{r=JSON.parse(e)}catch(e){return{ok:!1,error:"MALFORMED_ENVELOPE"}}if(!y(r))return{ok:!1,error:"MALFORMED_ENVELOPE"};if(3!==r.v)return{ok:!1,error:"UNSUPPORTED_VERSION"};if("string"!=typeof r.kind||!m.has(r.kind))return{ok:!1,error:"UNSUPPORTED_NATIVE_KIND"};if("string"!=typeof r.sessionId||0===r.sessionId.length)return{ok:!1,error:"MALFORMED_ENVELOPE"};if(r.sessionId!==n)return{ok:!1,error:"SESSION_MISMATCH"};if(Object.prototype.hasOwnProperty.call(r,"secret"))return{ok:!1,error:"UNEXPECTED_SECRET"};r.v,r.kind,r.sessionId;var o=__rest(r,["v","kind","sessionId"]);return{ok:!0,value:{kind:r.kind,payload:o}}}}}}var _="undefined"!=typeof window&&window.__LX_BRIDGE_CFG||{},b={value:(null===(n=_.displayLanguage)||void 0===n?void 0:n.trim())||"en-US",listeners:new Set};function k(){var e;return"undefined"==typeof window?b:(window.__lxDisplayLanguage||(window.__lxDisplayLanguage={value:(null===(e=_.displayLanguage)||void 0===e?void 0:e.trim())||"en-US",listeners:new Set}),window.__lxDisplayLanguage)}var I=new Set(["ar","ckb","dv","fa","he","ps","sd","ug","ur","yi"]);function E(){if("undefined"!=typeof document&&document.documentElement){var e=k().value;document.documentElement.lang=e,document.documentElement.dir=function(e){try{var n=new Intl.Locale(e),t="function"==typeof n.getTextInfo?n.getTextInfo():n.textInfo;if("rtl"===(null==t?void 0:t.direction)||"ltr"===(null==t?void 0:t.direction))return t.direction}catch(e){}return I.has(e.split(/[-_]/)[0].toLowerCase())?"rtl":"ltr"}(e)}}function x(){return _.os||"unknown"}function L(){return"mobile"===_.hostClass||"desktop"===_.hostClass?_.hostClass:"macOS"===_.os||"Windows"===_.os?"desktop":"mobile"}function S(){return"iOS"===_.os}function O(){return"macOS"===_.os}function C(){return"desktop"===L()}E(),"undefined"==typeof window||window.__lingxiaApplyDisplayLanguage||Object.defineProperty(window,"__lingxiaApplyDisplayLanguage",{configurable:!1,enumerable:!1,value:function(e,n){var t,r="string"==typeof e?e.trim():"",o=k();if("number"==typeof n&&Number.isFinite(n)){if(n<=(null!==(t=o.revision)&&void 0!==t?t:0))return;o.revision=n}if(r&&r!==o.value){o.value=r,E();for(var i=0,a=__spreadArray([],o.listeners,!0);i<a.length;i++){(0,a[i])(r)}}}});var A={sizeClass:"compact",width:0,height:0,aside:!1};function T(){var e;if("undefined"==typeof window)return M;if(!window.__lxSurfaceContext){var n=window.__LX_BRIDGE_CFG;window.__lxSurfaceContext={value:null!==(e=P(null==n?void 0:n.surfaceContext))&&void 0!==e?e:A,revision:"number"==typeof(null==n?void 0:n.surfaceContextRevision)?n.surfaceContextRevision:0,listeners:new Set}}return window.__lxSurfaceContext}var M={value:A,revision:0,listeners:new Set};function P(e){if("object"!=typeof e||null===e)return null;var n=e.sizeClass,t=e.width,r=e.height,o=e.aside;return"compact"!==n&&"regular"!==n||"number"!=typeof t||"number"!=typeof r?null:{sizeClass:n,width:t,height:r,aside:!0===o}}"undefined"==typeof window||window.__lingxiaApplySurfaceContext||Object.defineProperty(window,"__lingxiaApplySurfaceContext",{configurable:!1,enumerable:!1,value:function(e,n){var t=P(e),r=T();if(t){if("number"==typeof n){if(n<=r.revision)return;r.revision=n}if(o=r.value,i=t,o.sizeClass!==i.sizeClass||o.width!==i.width||o.height!==i.height||o.aside!==i.aside){var o,i;r.value=t;for(var a=0,l=__spreadArray([],r.listeners,!0);a<l.length;a++){(0,l[a])()}}}}});var N=null;function j(){var e=T().value;return{sizeClass:e.sizeClass,aside:e.aside,displayLanguage:k().value,formFactor:C()?"desktop":"mobile",os:x(),runner:!0===_.runner}}function D(){var e,n,t=j();return null!==N&&(n=t,(e=N).sizeClass===n.sizeClass&&e.aside===n.aside&&e.displayLanguage===n.displayLanguage&&e.formFactor===n.formFactor&&e.os===n.os&&e.runner===n.runner)||(N=t),N}function R(e){var n=D(),t=function(){var t=D();t!==n&&(n=t,e())},r=function(e){var n=k().listeners;return n.add(e),function(){n.delete(e)}}(t),o=function(e){var n=T().listeners;return n.add(e),function(){n.delete(e)}}(t);return function(){r(),o()}}function B(){return{holders:[],sent:!1,tail:Promise.resolve(),asking:!1}}var X=B();function q(){if("undefined"==typeof window)return X;var e=window;return e.__lxLeaveGuard||(e.__lxLeaveGuard=B()),e.__lxLeaveGuard}function F(){var e=q();e.tail=e.tail.then(function(){var n=e.holders.length>0;if(n!==e.sent)return e.sent=n,U("navigation.setLeaveGuard",{enabled:n}).catch(function(t){e.sent=!n,console.warn("[lingxia] leave guard not applied; the page is not guarded",t)})})}function G(e){var n=q(),t=function(n){return e(n)};return n.holders.push(t),F(),function(){var e=n.holders.indexOf(t);e<0||(n.holders.splice(e,1),F())}}function U(e,n){var t="undefined"!=typeof window?window.LingXiaBridge:void 0;if(!t)return Promise.reject(new Error("LingXiaBridge is not available"));try{return t.invoke(e,n)}catch(e){return Promise.reject(e)}}"undefined"==typeof window||window.__lingxiaDispatchLeaveRequest||Object.defineProperty(window,"__lingxiaDispatchLeaveRequest",{configurable:!1,enumerable:!1,value:function(e){var n=q();if(!n.asking){n.asking=!0;var t={reason:e},r=n.holders.slice().reverse(),o=Promise.resolve(!0);r.forEach(function(e){o=o.then(function(n){return!!n&&e(t)})}),o.then(function(e){return!0===e},function(e){return console.error("[lingxia] leave guard handler failed; staying on the page",e),!1}).then(function(t){if(n.asking=!1,t)return U("navigation.leave",{reason:e}).catch(function(e){console.warn("[lingxia] leaving the page failed",e)})})}}});var z="__LingXiaRecvMessage",H=5e3,W="[LX.Bridge]",V="messageport",J="jsinterface",Y="webmessage",$=_.appleDownstreamURL,K={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),info:(console.info||console.log).bind(console),debug:(console.debug||console.log).bind(console),group:(console.group||console.log).bind(console),groupEnd:(console.groupEnd||function(){}).bind(console)},Q={data:!1,proto:!1,all:!1},Z=[],ee={kind:"v2"},ne=!1;function te(){if("undefined"!=typeof window){var e=window.__LingXiaEarlyNativeMessages;if(Array.isArray(e)&&0!==e.length){window.__LingXiaEarlyNativeMessages=[];for(var n=0,t=e;n<t.length;n++){var r=t[n];"string"==typeof r&&Z.push(r)}}}}function re(e){if(te(),0!==Z.length)for(var n=0,t=Z.splice(0,Z.length);n<t.length;n++){var r=t[n];try{e(r)}catch(e){ae("Failed to replay queued native message:",e)}}}function oe(e){return Q.all||Q[e]}function ie(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(!0===_.dev||Q.all||Q.proto||Q.data)&&K.log.apply(K,__spreadArray([W],e,!1))}function ae(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];K.warn.apply(K,__spreadArray([W],e,!1))}function le(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];K.error.apply(K,__spreadArray([W],e,!1))}function ce(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 se(e){try{return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}catch(e){return{}}}var de=function(){var e,n;return"iOS"===_.os||"macOS"===_.os?"webkit":"Harmony"===_.os?"messageport":"Windows"===_.os?"webmessage":"Android"===_.os?(null===(n=null===(e=window.LingXiaProxy)||void 0===e?void 0:e.supportsMessagePort)||void 0===n?void 0:n.call(e))?"messageport":"jsinterface":"unknown"}();!function(){if("undefined"!=typeof window){te();var e=window[z];if("function"!=typeof e)window[z]=function(e){Z.push(e)};else{if(0===Z.length)return;for(var n=0,t=Z.splice(0,Z.length);n<t.length;n++){var r=t[n];try{e(r)}catch(e){ae("Failed to replay queued native message:",e)}}}}}();var ue=null,fe=!1,ve=null,pe=null,he=null,ge=200,me=!1,ye=0,we=0,_e=0,be="".concat(Date.now().toString(36)).concat(Math.random().toString(36).slice(2,10)),ke=null,Ie={listenerInstalled:!1,promise:null,resolve:null,reject:null,timer:null},Ee={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&&(Dn._connectWebMessagePort(o),null===(t=Ie.resolve)||void 0===t||t.call(Ie,o))}}};function xe(){Ie.listenerInstalled||(Ie.listenerInstalled=!0,window.addEventListener("message",Ee))}function Le(){null!==Ie.timer&&(window.clearTimeout(Ie.timer),Ie.timer=null),Ie.resolve=null,Ie.reject=null,Ie.promise=null}function Se(){return"webkit"===de&&(S()||O())}function Oe(){null!==he&&(clearTimeout(he),he=null)}function Ce(e){Se()&&!me&&(me=!0,Oe(),null!==ke&&(clearInterval(ke),ke=null),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",Re),je=!1,null==pe||pe.abort(),fe=!1,Te(e,!0))}function Ae(e){for(var n=0,t=Array.from(Ye.keys());n<t.length;n++){sn(t[n],{code:d,message:e})}for(var r=0,o=Array.from($e.keys());r<o.length;r++){dn(o[r],{code:d,message:e})}!function(e){for(var n=0,t=Array.from(Ke.entries());n<t.length;n++){var r=t[n],o=r[0],i=r[1];Ke.delete(o),i._emitClose(d,e)}}(e)}function Te(e,n){gn(),"required-v3"!==ee.kind&&(qe=null),Fe=!1,Ge=!1,Ue=!1,ze=0,n&&Ae(e)}function Me(e){if(e&&"object"==typeof e){we=Date.now();var n=e;if(!0!==n.lxshutdown){if(void 0===n.lxhb){if(!0===n.lxreset)return ye=0,Te("Apple downstream reset",!0),void mn();if("number"==typeof n.lxff){if(n.lxff<=ye)return;return ye=n.lxff,void In(n.m)}In(e)}}else Ce("Apple downstream closed")}}function Pe(){return __awaiter(this,void 0,void 0,function(){var e,n,t,r,o,i,a,l,c,s,d;return __generator(this,function(u){switch(u.label){case 0:if(!$)throw new Error("Apple downstream URL is not configured");return e=new AbortController,pe=e,n=$.includes("?")?"&":"?",t="".concat($).concat(n,"from=").concat(ye,"&doc=").concat(be),_e=Date.now(),[4,fetch(t,{method:"GET",cache:"no-store",headers:{Accept:"application/x-ndjson"},signal:e.signal})];case 1:if(!(r=u.sent()).ok)throw new Error("Apple downstream HTTP ".concat(r.status));if("1"===r.headers.get("X-LingXia-Bridge-Shutdown"))return Ce("Apple downstream closed"),[2];if(!r.body)throw new Error("Apple downstream response body unavailable");fe=!0,ge=200,we=Date.now(),oe("proto")&&ie("Apple downstream connected"),mn(),o=r.body.getReader(),i=new TextDecoder,a="",u.label=2;case 2:u.trys.push([2,6,7,8]),u.label=3;case 3:return[4,o.read()];case 4:return l=u.sent(),c=l.value,l.done?[3,5]:(a=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{Me(JSON.parse(r))}catch(e){ae("Apple downstream parse error:",e,r)}}return n}(a+=i.decode(c,{stream:!0})),[3,3]);case 5:if(a+=i.decode(),s=a.trim())try{Me(JSON.parse(s))}catch(e){ae("Apple downstream trailing parse error:",e,s)}return[3,8];case 6:if(d=u.sent(),e.signal.aborted)return[2];throw d;case 7:try{o.releaseLock()}catch(e){}return[7];case 8:return[2]}})})}function Ne(){if(Se()&&!me&&!ve){Oe();var e=!1;ve=Pe().then(function(){e=!0}).catch(function(e){(null==pe?void 0:pe.signal.aborted)||ae("Apple downstream failed:",e)}).finally(function(){var n,t=null!==(n=null==pe?void 0:pe.signal.aborted)&&void 0!==n&&n;ve=null,pe=null,fe=!1,t||me||function(e,n){if(void 0===n&&(n=!1),Se()&&!me){Oe();var t=n?0:ge;n||(ge=Math.min(2*ge,2e3));var r=n?"Apple downstream completed, reconnecting immediately: ".concat(e):"Apple downstream disconnected, retrying in ".concat(t,"ms: ").concat(e);t<=200?ie(r):ae(r),he=setTimeout(function(){he=null,Ne()},t)}}("stream closed",e)})}}var je=!1;function De(){if(Se()&&!me&&!je){je=!0;var e=ve;null==pe||pe.abort();var n=function(){je=!1,Ne()};e?e.finally(n):n()}}function Re(){"visible"===document.visibilityState&&De()}function Be(e){var n,t,r,o=function(e){if("blocked"===ee.kind)return null;if("v2"===ee.kind)return e;if(!e||"object"!=typeof e)return null;e.v;var n=e.kind,t=__rest(e,["v","kind"]);if("string"!=typeof n)return null;var r=ee.codec.encode(n,t);return r.ok?r.value:null}(e);if(!o)return null;var i=e.kind;"req"!==i&&"notify"!==i||ie("postToNative: ".concat(i," ").concat(e.method)),oe("proto")&&K.log("→",JSON.stringify(e,null,2));try{var a=ce(o),l=function(e){if("function"==typeof TextEncoder)return(new TextEncoder).encode(e).length;for(var n=0,t=0;t<e.length;t+=1){var r=e.charCodeAt(t);r<128?n+=1:r<2048?n+=2:r>=55296&&r<=56319?(n+=4,t+=1):n+=3}return n}(a);if(l>65536)return{code:u,message:"Bridge message of ".concat(l," bytes exceeds the ").concat(65536,"-byte native limit")};if("webkit"===de)return null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers.LingXia)||void 0===t||t.postMessage(a),null;if(de===V&&ue)return ue.postMessage(a),null;if((de===J||de===Y)&&(null===(r=window.LingXiaProxy)||void 0===r?void 0:r.postMessage))return window.LingXiaProxy.postMessage(a),null;ae("Transport not ready")}catch(e){"required-v3"===ee.kind?le("Send error"):le("Send error:",e)}return null}function Xe(e){var n=e.map(function(e){if("string"==typeof e)return e;try{var n=ce(e);return"string"==typeof n?n:String(e)}catch(e){return"[Unserializable]"}}).join(" ");return n.length<=12288?n:"".concat(n.slice(0,12288),"…")}var qe=null,Fe=!1,Ge=!1,Ue=!1,ze=0,He=null,We=0;function Ve(){return{data:new Set,end:new Set,error:new Set,close:new Set}}function Je(e,n){var t,r=Ve(),o=!1,i=!1,a=function(){},l=function(){},c=[],s=[],d=new Promise(function(e,n){a=e,l=n}),u=((t={id:e,result:d,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 i=!0,{next:function(){return c.length>0?Promise.resolve({done:!1,value:c.shift()}):o?d.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})})},return:function(){return i=!1,c.length=0,d.catch(function(){}),u.cancel(),Promise.resolve({done:!0,value:void 0})}}},t.cancel=function(){o||n()},t._emitData=function(e){if(!o){s.length>0?s.shift().resolve({done:!1,value:e}):i&&c.push(e);for(var n=0,t=r.data;n<t.length;n++){var a=t[n];try{a(e)}catch(e){ae("Stream data listener failed:",e)}}}},t._resolve=function(e){if(!o){for(o=!0,a(e);s.length>0;)s.shift().resolve({done:!0,value:e});for(var n=0,t=r.end;n<t.length;n++){var i=t[n];try{i(e)}catch(e){ae("Stream end listener failed:",e)}}}},t._reject=function(e){if(!o){for(o=!0,l(e);s.length>0;)s.shift().reject(e);for(var n=0,t=r.error;n<t.length;n++){var i=t[n];try{i(e)}catch(e){ae("Stream error listener failed:",e)}}}},t);return u}var Ye=new Map,$e=new Map,Ke=new Map,Qe=[],Ze=-1,en={},nn=new Set,tn=new WeakMap,rn=new Map;function on(e){if(e.startsWith("host."))return"host";var n=e.indexOf(".");return n>0?e.slice(0,n):"page"}function an(e){if(null!=e)return e}function ln(){return de===V?!!ue:Se()?fe:"webkit"===de||de===J||de===Y}function cn(){return!!Ge&&(!!Se()||ln())}function sn(e,n){var t,r=Ye.get(e);if(r){Ye.delete(e),null!==r.timerId&&clearTimeout(r.timerId);var o=v(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 dn(e,n){var t=$e.get(e);if(t){$e.delete(e),null!==t.timerId&&clearTimeout(t.timerId);var r=v(n);t.channel._reject(r),t.reject(r)}}function un(e,n){Ye.has(e)?sn(e,n):$e.has(e)&&dn(e,n)}function fn(e){if(Ye.has(e))return n=e,void((r=Ye.get(n))&&(!Number.isFinite(r.timeoutMs)||r.timeoutMs<=0?null!==r.timerId&&(clearTimeout(r.timerId),r.timerId=null):(null!==r.timerId&&clearTimeout(r.timerId),r.timerId=setTimeout(function(){Ye.has(n)&&sn(n,{code:t,message:"'".concat(r.method,"' timed out")})},r.timeoutMs))));var n,r;$e.has(e)&&function(e){var n=$e.get(e);n&&(null!==n.timerId&&clearTimeout(n.timerId),n.timerId=setTimeout(function(){dn(e,{code:t,message:"Channel '".concat(n.topic,"' timed out")})},H))}(e)}function vn(e){for(var n,t=Qe.length-1;t>=0;t--)if((null===(n=Qe[t])||void 0===n?void 0:n.reqId)===e)return Qe.splice(t,1),!0;return!1}function pn(e,n){var t=e.kind,r="hello"===t||"helloAck"===t||"ready"===t;if(!cn()&&!r)return Qe.length>=256?(le("Outbox full"),void(n&&un(n,{code:s,message:"Bridge outbox is full"}))):void Qe.push({msg:e,reqId:n});n&&fn(n),hn(Be(e),n)}function hn(e,n){e&&(le(e.message),n&&un(n,e))}function gn(){null!==He&&(clearTimeout(He),He=null)}function mn(){if(!Ge&&ne&&"blocked"!==ee.kind&&ln()){gn();var e={v:2,kind:"hello",nonce:_.nonce||"",role:"view",protocolsSupported:"required-v3"===ee.kind?[3]:[2]};Ue=!0,Be(e),He=setTimeout(function(){if(!Ge)if(++ze<3)ae("Handshake timeout (".concat(ze,"/").concat(3,"), retrying...")),Ue=!1,mn();else{for(le("Handshake failed"),gn(),Ue=!1,ze=0;Qe.length;){var e=Qe.shift();(null==e?void 0:e.reqId)&&un(e.reqId,{code:o,message:"Bridge handshake failed"})}for(var n=0,t=Array.from($e.keys());n<t.length;n++){dn(t[n],{code:o,message:"Bridge handshake failed"})}}},1e4)}}function yn(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function wn(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(yn)}(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 l=o;if(t&&void 0===l[a]){var c=r[i+1];l[a]=c&&/^\d+$/.test(c)?[]:{}}o=l[a]}}return{container:o,key:r[r.length-1]}}function _n(e){nn.forEach(function(n){try{if(!tn.has(n))return tn.set(n,!0),void n(se(en),{rev:Ze,initial:!0});n(se(en),{rev:Ze,initial:e})}catch(e){ae("Subscriber error:",e)}})}function bn(e){if("function"!=typeof e)return function(){};if(nn.add(e),Ze>=0){tn.set(e,!0);try{e(se(en),{rev:Ze,initial:!0})}catch(e){le("Callback error:",e)}}return function(){nn.delete(e),tn.delete(e)}}function kn(e){jn.call("state.getSnapshot",{scope:e}).catch(function(){})}function In(e){var n,t,r,o,i=e;if("v2"===ee.kind&&"string"==typeof i)try{i=JSON.parse(i)}catch(e){i=null}if("v2"===ee.kind&&i&&"object"==typeof i){var c=i;if("event"===c.type&&"nativecomponent"===c.name&&c.payload){var s=c.payload,u=s.id||s.componentId;if("string"==typeof u){var f=En.get(u);if(f)try{f(s)}catch(e){le("NC handler error:",e)}}return}}var p=function(e){if("blocked"===ee.kind)return null;if("required-v3"===ee.kind){var n="string"==typeof e?e:ce(e),t=ee.codec.parse(n);return t.ok?__assign({v:3,kind:t.value.kind},t.value.payload):null}if("string"==typeof e)try{e=JSON.parse(e)}catch(e){return null}if(!e||"object"!=typeof e)return null;var r=e.v,o=e.kind;return 2!==r||"string"!=typeof o?null:e}(i);if(p)switch(p.kind){case"helloAck":return p.protocol!==("required-v3"===ee.kind?3:2)||p.nonce!==(_.nonce||"")?void ae("Invalid helloAck"):"required-v3"===ee.kind?void(Fe=!0):qe&&p.sessionId!==qe?void ae("sessionId mismatch"):(qe||(qe=p.sessionId),void(Fe=!0));case"ready":if(!Fe)return;return"v2"===ee.kind&&qe&&p.sessionId!==qe?void ae("sessionId mismatch"):(gn(),Ge=!0,ze=0,oe("proto")&&ie("Handshake complete, host routes:",Object.keys(p.hostMethods||{}).length+(p.hostChannels||[]).length),void function(){if(cn())for(;Qe.length;){var e=Qe.shift();e&&(e.reqId&&fn(e.reqId),hn(Be(e.msg),e.reqId))}}());case"res":var h=Ye.get(p.id);if(!h)return;if(Ye.delete(p.id),null!==h.timerId&&clearTimeout(h.timerId),p.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||(en=n.state,Ze=n.rev,oe("data")&&(K.group("[LX] snapshot(res)"),K.log("rev:",Ze,"state:",se(en)),K.groupEnd()),_n(!0),0))}(p.result)||ae("Invalid state.getSnapshot result")),"stream"===h.mode&&h.stream)return void h.stream._resolve(p.result);null===(n=h.resolve)||void 0===n||n.call(h,p.result)}else{var g=v(p.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(Ye.has(p.id)){var m=Ye.get(p.id);return void("stream"===(null==m?void 0:m.mode)&&m.stream?(null!==m.timerId&&(clearTimeout(m.timerId),m.timerId=null),m.timeoutMs=0,m.stream._emitData(p.payload)):ae("Received event for non-stream request '".concat(p.id,"'")))}return;case"state.snapshot":return en=p.state||{},Ze=p.rev,oe("data")&&(K.group("[LX] snapshot"),K.log("rev:",Ze,"state:",se(en)),K.groupEnd()),void _n(!0);case"state.patch":if(p.baseRev!==Ze)return ae("baseRev mismatch",{have:Ze,want:p.baseRev}),void kn(p.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=wn(e,o.path,i),l=a.container,c=a.key;if("$root"!==c)if(Array.isArray(l)){var s="-"===c?l.length:Number(c);if(!Number.isFinite(s)||s<0)throw new Error("Invalid index");"remove"===o.op?l.splice(s,1):"add"===o.op?l.splice(s,0,o.value):"replace"===o.op&&(l[s]=o.value)}else{if(!l||"object"!=typeof l)throw new Error("Invalid container");var d=l;"remove"===o.op?delete d[c]:d[c]=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)}}}}(en,p.ops||[]),Ze=p.rev}catch(e){return le("Patch failed:",e),void kn(p.scope)}return oe("data")&&(K.group("[LX] patch"),K.log("rev:",Ze,"ops:",p.ops),K.groupEnd()),_n(!1),void(p.ack&&pn({v:2,kind:"state.ack",scope:p.scope,rev:p.rev}));case"ch.ack":var y=$e.get(p.id);if(!y)return;if($e.delete(p.id),null!==y.timerId&&clearTimeout(y.timerId),p.ok)y.channel._markOpen(),Ke.set(p.id,y.channel),y.resolve(y.channel);else{g=v(p.error);y.channel._reject(g),y.reject(g)}return;case"ch.data":var w=Ke.get(p.id);if(!w)return;return void w._emitData(p.payload);case"ch.close":if($e.get(p.id))return void dn(p.id,{code:null!==(r=p.code)&&void 0!==r?r:d,message:null!==(o=p.reason)&&void 0!==o?o:"Channel closed before opening"});var b=Ke.get(p.id);if(!b)return;return Ke.delete(p.id),void b._emitClose(p.code,p.reason);case"req":var k=p,I=on(k.method);if(!k.cap||k.cap!==I)return void pn({v:2,kind:"res",id:k.id,ok:!1,error:{code:l,message:"Invalid cap for ".concat(k.method)}});var E=rn.get(k.method);return E?void Promise.resolve().then(function(){return E(k.params)}).then(function(e){pn({v:2,kind:"res",id:k.id,ok:!0,result:e})}).catch(function(e){pn({v:2,kind:"res",id:k.id,ok:!1,error:v(e)})}):void pn({v:2,kind:"res",id:k.id,ok:!1,error:{code:a,message:"View handler not found: ".concat(k.method)}})}else ae("Invalid bridge message")}var En=new Map,xn=[],Ln=!1;function Sn(){var e,n,t,r;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)||(null===(r=window.LingXiaProxy)||void 0===r?void 0:r.nativeComponentUpdate))}function On(e){var n,t,r,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===(r=window.NativeComponentBridge)||void 0===r?void 0:r.postMessage)return void window.NativeComponentBridge.postMessage(ce(e));var i=null===(o=window.LingXiaProxy)||void 0===o?void 0:o.nativeComponentUpdate;if("function"==typeof i){var a=e.id||"island",l=ce(__assign(__assign({},e),{componentId:a}));try{i.call(window.LingXiaProxy,l)}catch(e){i.call(window.LingXiaProxy,a,l)}return}}catch(e){le("NativeComponent send error:",e)}}function Cn(){if(Sn()&&0!==xn.length)for(Ln=!0;xn.length;){var e=xn.shift();try{On(e)}catch(e){break}}}function An(e){try{if(!Sn())return void xn.push(e);Ln||Cn(),On(e)}catch(e){le("NC send failed:",e)}}function Tn(e){return"".concat(e,"_").concat(Date.now(),"_").concat(We++)}function Mn(e,n,t){if(n)if(n.aborted)t();else{var r={handleEvent:function(){n.removeEventListener("abort",r),t()}};n.addEventListener("abort",r)}}var Pn,Nn,jn={call:function(e,n,t){return new Promise(function(o,a){var l;if(e&&"string"==typeof e){Ue||mn();var c=Tn("c"),s=(null==t?void 0:t.cap)||on(e),d=null!==(l=null==t?void 0:t.timeoutMs)&&void 0!==l?l:H;Ye.set(c,{method:e,mode:"call",resolve:o,reject:function(e){return a(e)},timeoutMs:d,timerId:null}),pn({v:2,kind:"req",id:c,method:e,params:an(n),cap:s},c),Mn(0,null==t?void 0:t.signal,function(){var e=vn(c);sn(c,{code:r,message:"Bridge request aborted"}),!e&&Ge&&pn({v:2,kind:"cancel",id:c})})}else a({code:i,message:"Method name must be a non-empty string"})})},stream:function(e,n,t){var o;if(!e||"string"!=typeof e){var a=Je("invalid",function(){});return a._reject({code:i,message:"Method name must be a non-empty string"}),a}Ue||mn();var l=Tn("c"),c=Je(l,function(){vn(l)?sn(l,{code:r,message:"Bridge request aborted"}):Ge&&pn({v:2,kind:"cancel",id:l})}),s=(null==t?void 0:t.cap)||on(e),d=null!==(o=null==t?void 0:t.timeoutMs)&&void 0!==o?o:H;return Ye.set(l,{method:e,mode:"stream",stream:c,timeoutMs:d,timerId:null}),pn({v:2,kind:"req",id:l,method:e,params:an(n),cap:s},l),Mn(0,null==t?void 0:t.signal,function(){return c.cancel()}),c},notify:function(e,n,t){e&&"string"==typeof e&&(Ue||mn(),pn({v:2,kind:"notify",method:e,params:an(n),cap:(null==t?void 0:t.cap)||on(e)}))},state:{subscribe:bn},channel:{open:function(e,n,t){return e&&"string"==typeof e?(Ue||mn(),new Promise(function(r,o){var i=Tn("ch"),a=function(e,n,t){var r,o=Ve(),i=!1,a=0,l=!1,c=!1,s=!1,u=[],f=[],v=((r={id:e,send:function(t){i?n(t,a++):v._reject({code:d,message:"Channel '".concat(e,"' is closed")})},on:function(e,n){if("data"===e&&(o.data.add(n),u.length>0))for(var t=0,r=u.splice(0);t<r.length;t++){var i=r[t];try{n(i)}catch(e){ae("Channel listener failed:",e)}}return"close"===e&&o.close.add(n),"error"===e&&o.error.add(n),this}})[Symbol.asyncIterator]=function(){return s=!0,{next:function(){return u.length>0?Promise.resolve({done:!1,value:u.shift()}):l?Promise.resolve({done:!0,value:void 0}):new Promise(function(e,n){f.push({resolve:e,reject:n})})},return:function(){return s=!1,u.length=0,v.close(),Promise.resolve({done:!0,value:void 0})}}},r.close=function(e,n){i&&(i=!1,t(e,n),v._emitClose(e,n))},r._emitData=function(e){if(i){f.length>0?f.shift().resolve({done:!1,value:e}):(s||0===o.data.size)&&u.push(e);for(var n=0,t=o.data;n<t.length;n++){var r=t[n];try{r(e)}catch(e){ae("Channel listener failed:",e)}}}},r._emitClose=function(e,n){if(i=!1,l=!0,!c){for(c=!0;f.length>0;)f.shift().resolve({done:!0,value:void 0});for(var t=0,r=o.close;t<r.length;t++){var a=r[t];try{a(e,n)}catch(e){ae("Channel close listener failed:",e)}}}},r._reject=function(e){for(i=!1,l=!0;f.length>0;)f.shift().reject(e);for(var n=0,t=o.error;n<t.length;n++){var r=t[n];try{r(e)}catch(e){ae("Channel error listener failed:",e)}}},r._markOpen=function(){i=!0,l=!1},r._isOpen=function(){return i},r._nextSeq=function(){return a++},r);return v}(i,function(e,n){pn({v:2,kind:"ch.data",id:i,seq:n,payload:e})},function(e,n){var t=$e.get(i);t&&null!==t.timerId&&clearTimeout(t.timerId),$e.delete(i),Ke.delete(i),pn({v:2,kind:"ch.close",id:i,code:e,reason:n})});$e.set(i,{topic:e,channel:a,resolve:r,reject:o,timerId:null}),pn({v:2,kind:"ch.open",id:i,topic:e,params:an(n),cap:(null==t?void 0:t.cap)||on(e)},i)})):Promise.reject({code:i,message:"Topic name must be a non-empty string"})}}},Dn={invoke:function(e,n,t){return jn.call(Rn(e),n,Bn(t)).then(function(e){return e}).catch(function(e){return Promise.reject(p(e))})},notify:function(e,n,t){jn.notify(Rn(e),n,Bn(t))},stream:function(e,n,t){return Xn(jn.stream(Rn(e),n,Bn(t)))},channel:function(e,n,t){return jn.channel.open(Rn(e),n,Bn(t)).then(function(e){return function(e){var n=new Set,t=new Set,r=[];return setTimeout(function(){r=null},0),e.on("data",function(e){if(0!==n.size)for(var t=0,o=n;t<o.length;t++){(0,o[t])(e)}else null==r||r.push(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){n.add(e);var t=r;r=null;for(var o=0,i=null!=t?t:[];o<i.length;o++){var a=i[o];e(a)}return 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(p(e))})},raw:jn,state:{subscribe:bn},_connectWebMessagePort:function(e){if(de===V){if(ue&&ue!==e)try{ue.onmessage=null,ue.close()}catch(e){}ue=e,e.onmessage=function(e){In(e.data)};try{e.start()}catch(e){}ie("Port connected"),mn()}},_receiveEvaluateMessage:function(e){e&&In(e)},debug:(Pn=Q,Nn={},Object.keys(Pn).forEach(function(e){Object.defineProperty(Nn,e,{enumerable:!0,configurable:!1,get:function(){return Pn[e]},set:function(n){Pn[e]=!!n,K.log("[LX] ".concat(e,": ").concat(n))}})}),Nn),host:{get:D,subscribe:R},leaveGuard:{hold:G},platform:{isHarmony:function(){return"Harmony"===_.os},isIOS:S,isAndroid:function(){return"Android"===_.os},isMacOS:O,isWindows:function(){return"Windows"===_.os},isDesktop:C,isMobile:function(){return"mobile"===L()},isApple:function(){return S()||O()},isRunner:function(){return!0===_.runner},getOS:x},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:An,hasHandler:Sn,flush:Cn,register:function(e,n){return e&&"function"==typeof n?(En.set(e,n),function(){return En.delete(e)}):function(){}},unregister:function(e){En.delete(e)}},isReady:function(){return Ge}};function Rn(e){return e.startsWith("host.")?e:"host.".concat(e)}function Bn(e){return __assign(__assign({},e||{}),{cap:(null==e?void 0:e.cap)||"host"})}function Xn(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=p(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(p(e))}),cancel:function(){e.cancel()}}}function qn(){if(window.__LX_BRIDGE_INIT_STATE)ie("Bridge already ".concat(window.__LX_BRIDGE_INIT_STATE,", skipping duplicate init"));else{window.__LX_BRIDGE_INIT_STATE="initializing";try{if(!ne){var e=function(){if("undefined"==typeof window)return{kind:"absent"};var e=window.__LingXiaTakeControlBootstrap;if("function"!=typeof e)return{kind:"absent"};try{var n=e();if(!n||3!==n.requiredProtocol||"string"!=typeof n.publicSessionId||0===n.publicSessionId.length||"string"!=typeof n.secret||0===n.secret.length)return{kind:"blocked"};var t=w({sessionId:n.publicSessionId,secret:n.secret});return t.ok?{kind:"required",codec:t.value}:{kind:"blocked"}}catch(e){return{kind:"blocked"}}finally{try{delete window.__LingXiaTakeControlBootstrap}catch(e){}}}();ee="required"===e.kind?{kind:"required-v3",codec:e.codec}:{kind:"absent"===e.kind?"v2":"blocked"},ne=!0}if(function(){if("required-v3"===ee.kind)for(var e=function(e){var n=K[e];console[e]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];n.apply(void 0,t),Ge&&Be({kind:"console",__lingxia_console__:!0,level:e,message:Xe(t)})}},n=0,t=["log","error","warn","info","debug"];n<t.length;n++)e(t[n])}(),ie("Method: ".concat(de)),t=Dn._receiveEvaluateMessage,"undefined"!=typeof window&&(window[z]=function(e){re(t),t(e)},re(t)),Se())Ne(),Se()&&!me&&null===ke&&(ke=setInterval(function(){0!==we?Date.now()-we>35e3&&(ae("Apple downstream stale (no heartbeat), forcing reconnect"),De()):ve&&0!==_e&&Date.now()-_e>1e4&&(ae("Apple downstream did not connect, forcing reconnect"),De())},5e3)),Se()&&"undefined"!=typeof document&&document.addEventListener("visibilitychange",Re);else if(de===V){xe();var n=function(e){(function(){var e,n;if(ue)return Promise.resolve(ue);if(Ie.promise)return Ie.promise;xe(),Ie.promise=new Promise(function(e,n){Ie.resolve=function(n){Le(),e(n)},Ie.reject=function(e){Le(),n(e)},Ie.timer=window.setTimeout(function(){var e;null===(e=Ie.reject)||void 0===e||e.call(Ie,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=Ie.reject)||void 0===n||n.call(Ie,e)}return Ie.promise})().catch(function(t){ae("Port init failed:",t),e<3&&window.setTimeout(function(){return n(e+1)},500*e)})};n(1)}else"webkit"===de||de===J||de===Y?mn():ae("Unknown method");window.LingXiaBridge=Dn,window.__lxForceDownstreamReconnect=De,h({os:x(),send:An}),window.__LX_BRIDGE_INIT_STATE="initialized",ie("Init complete")}catch(e){throw delete window.__LX_BRIDGE_INIT_STATE,e}var t}}var Fn="\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";function Gn(e){var n=document.createElement("div");return n.textContent=e,n.innerHTML}function Un(e){!function(e){var n=e.code,t=e.title,r=e.description,o=e.detail,i=e.reason,a=document.createElement("style");a.textContent=Fn,document.head.appendChild(a),document.body.innerHTML="",document.body.style.cssText="";var l=document.createElement("div");l.className="lx-error";var c='<div class="lx-error-code">'.concat(Gn(n),"</div>");c+='<h1 class="lx-error-title">'.concat(Gn(t),"</h1>"),c+='<p class="lx-error-desc">'.concat(Gn(r),"</p>"),o&&(c+='<div class="lx-error-path">'.concat(Gn(o),"</div>")),i&&(c+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Gn(i),"</p>")),l.innerHTML=c,document.body.appendChild(l)}({code:"404",title:"Page Not Found",description:"The page you're looking for doesn't exist.",detail:e.failedPath,reason:e.reason})}function zn(){var e=window.__LX_RUNTIME_CONFIG;return!(!e||!e.error)}function Hn(){var e;return(null===(e=window.__LX_RUNTIME_CONFIG)||void 0===e?void 0:e.error)||null}var Wn={handleEvent:function(){return Vn()}};function Vn(){if(zn()){var e=Hn();e&&Un(e)}}function Jn(){qn(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Wn):Vn()}return Jn(),e.LingXiaBridge=Dn,e.boot=function(){qn(),Vn()},e.bootWhenReady=Jn,e.channel=function(e,n,t){return Dn.channel(e,n,t)},e.getErrorInfo=Hn,e.getHost=D,e.hasError=zn,e.holdLeaveGuard=G,e.initBridge=qn,e.invoke=function(e,n,t){return Dn.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){jn.notify(Rn(e),n,Bn(t))},e.renderErrorUI=Un,e.renderPageFault=function(e,n){var t=document.createElement("style");t.textContent="\n.lx-page-fault { position: fixed; inset: 0; z-index: 2147483647; overflow: auto;\n background: #fff; color: #1d1d1f; }\n@media (prefers-color-scheme: dark) { .lx-page-fault { background: #000; color: #f5f5f7; } }\n".concat(Fn.replace(/\bbody\b/g,".lx-page-fault")),document.head.appendChild(t);var r=document.createElement("div");r.className="lx-page-fault",r.setAttribute("role","alert");var o=document.createElement("div");o.className="lx-error";var i='<div class="lx-error-code">Page</div>';return i+='<h1 class="lx-error-title">'.concat(Gn("This page couldn't start"),"</h1>"),i+='<p class="lx-error-desc">'.concat(Gn("Its Logic has not delivered the page state. Check the Logic log for an error."),"</p>"),e&&(i+='<div class="lx-error-path">'.concat(Gn(e),"</div>")),i+='<p class="lx-error-desc" style="margin-top:12px">'.concat(Gn(n),"</p>"),o.innerHTML=i,r.appendChild(o),document.body.appendChild(r),function(){r.remove(),t.remove()}},e.stream=function(e,n,t){return Xn(jn.stream(Rn(e),n,Bn(t)))},e.subscribeHost=R,e}({});
|
package/dist/es2020/bridge.js
CHANGED
|
@@ -3,6 +3,7 @@ import { toBridgeError, toNativeError } from "./invocation";
|
|
|
3
3
|
import { installNativeComponentCoverageMonitor } from "./nativecomponents/coverage-monitor";
|
|
4
4
|
import { consumeV3Bootstrap, } from "./protocol-v3";
|
|
5
5
|
import { getHost, subscribeHost } from "./host";
|
|
6
|
+
import { holdLeaveGuard } from "./leave-guard";
|
|
6
7
|
import { BRIDGE_CONFIG, getCommunicationMethod, getPlatformOS, isAndroid, isHarmony, isIOS, isMacOS, isWindows, isDesktop, isMobile, isApple, isDevSession, isRunner, } from "./runtime-env";
|
|
7
8
|
const NATIVE_HANDLER_NAME = "LingXia";
|
|
8
9
|
const GLOBAL_RECEIVER_NAME = "__LingXiaRecvMessage";
|
|
@@ -1882,6 +1883,10 @@ export const LingXiaBridge = {
|
|
|
1882
1883
|
get: getHost,
|
|
1883
1884
|
subscribe: subscribeHost,
|
|
1884
1885
|
},
|
|
1886
|
+
// The leave guard, for the same plain-HTML documents.
|
|
1887
|
+
leaveGuard: {
|
|
1888
|
+
hold: holdLeaveGuard,
|
|
1889
|
+
},
|
|
1885
1890
|
platform: {
|
|
1886
1891
|
isHarmony,
|
|
1887
1892
|
isIOS,
|
package/dist/es2020/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export { LingXiaBridge, channel, initBridge, invoke, notify, stream, } from './bridge';
|
|
9
9
|
export { isNativeError } from './invocation';
|
|
10
10
|
export { getHost, subscribeHost } from './host';
|
|
11
|
+
export { holdLeaveGuard } from './leave-guard';
|
|
11
12
|
export { renderErrorUI, renderPageFault, hasError, getErrorInfo } from './error';
|
|
12
13
|
export { boot, bootWhenReady } from './boot';
|
|
13
14
|
import { bootWhenReady } from './boot';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarding a page against being left with unsaved changes.
|
|
3
|
+
*
|
|
4
|
+
* While a page holds the guard, a user back or home (navigation bar buttons,
|
|
5
|
+
* Android/Harmony system back, the iOS/Harmony edge swipe) does not leave it.
|
|
6
|
+
* The host asks here instead, each holder answers, and when all agree the
|
|
7
|
+
* host carries out what the user asked for.
|
|
8
|
+
*
|
|
9
|
+
* Works without Logic: a View-only (`logic: false`) page owns its drafts, so
|
|
10
|
+
* the guard is held from the View.
|
|
11
|
+
*
|
|
12
|
+
* Its only import-time effect is installing the host hook (idempotent, shared
|
|
13
|
+
* across bundle copies). It reaches the host through the already-booted
|
|
14
|
+
* `window.LingXiaBridge` at call time and never imports the bridge module, so
|
|
15
|
+
* the plain-HTML global build can include it without booting a second bridge.
|
|
16
|
+
*/
|
|
17
|
+
function newStore() {
|
|
18
|
+
return { holders: [], sent: false, tail: Promise.resolve(), asking: false };
|
|
19
|
+
}
|
|
20
|
+
const fallbackStore = newStore();
|
|
21
|
+
function store() {
|
|
22
|
+
if (typeof window === 'undefined')
|
|
23
|
+
return fallbackStore;
|
|
24
|
+
// Shared by every copy of the bridge module in this document.
|
|
25
|
+
const host = window;
|
|
26
|
+
if (!host.__lxLeaveGuard)
|
|
27
|
+
host.__lxLeaveGuard = newStore();
|
|
28
|
+
return host.__lxLeaveGuard;
|
|
29
|
+
}
|
|
30
|
+
// The host keeps one flag per page. Tell it whether anyone holds, one call at
|
|
31
|
+
// a time so a quick hold → release cannot land reversed.
|
|
32
|
+
function syncGuard() {
|
|
33
|
+
const s = store();
|
|
34
|
+
s.tail = s.tail.then(() => {
|
|
35
|
+
const want = s.holders.length > 0;
|
|
36
|
+
if (want === s.sent)
|
|
37
|
+
return undefined;
|
|
38
|
+
s.sent = want;
|
|
39
|
+
return callHost('navigation.setLeaveGuard', { enabled: want }).catch((error) => {
|
|
40
|
+
s.sent = !want;
|
|
41
|
+
// A refused guard (bridge not ready, a runtime without the route)
|
|
42
|
+
// leaves the page unguarded; say so rather than fail silently.
|
|
43
|
+
console.warn('[lingxia] leave guard not applied; the page is not guarded', error);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Host entry point: the user tried to leave a guarded page. */
|
|
48
|
+
function dispatchLeaveRequest(reason) {
|
|
49
|
+
const s = store();
|
|
50
|
+
// One question at a time: a second back while a dialog is open is dropped.
|
|
51
|
+
if (s.asking)
|
|
52
|
+
return;
|
|
53
|
+
s.asking = true;
|
|
54
|
+
const request = { reason };
|
|
55
|
+
// Newest holder first; the first refusal keeps the page.
|
|
56
|
+
const holders = s.holders.slice().reverse();
|
|
57
|
+
let agreed = Promise.resolve(true);
|
|
58
|
+
holders.forEach((handler) => {
|
|
59
|
+
agreed = agreed.then((leave) => (leave ? handler(request) : false));
|
|
60
|
+
});
|
|
61
|
+
agreed
|
|
62
|
+
.then((leave) => leave === true, (error) => {
|
|
63
|
+
console.error('[lingxia] leave guard handler failed; staying on the page', error);
|
|
64
|
+
return false;
|
|
65
|
+
})
|
|
66
|
+
.then((leave) => {
|
|
67
|
+
s.asking = false;
|
|
68
|
+
if (!leave)
|
|
69
|
+
return undefined;
|
|
70
|
+
return callHost('navigation.leave', { reason }).catch((error) => {
|
|
71
|
+
console.warn('[lingxia] leaving the page failed', error);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (typeof window !== 'undefined' && !window.__lingxiaDispatchLeaveRequest) {
|
|
76
|
+
Object.defineProperty(window, '__lingxiaDispatchLeaveRequest', {
|
|
77
|
+
configurable: false,
|
|
78
|
+
enumerable: false,
|
|
79
|
+
value: dispatchLeaveRequest,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Hold this page against user back and home until the returned function is
|
|
84
|
+
* called. Hold while there are unsaved changes; `onRequest` is asked when the
|
|
85
|
+
* user tries to leave and returns whether they may.
|
|
86
|
+
*
|
|
87
|
+
* Holds are independent: each part of a page holds for itself, the page stays
|
|
88
|
+
* guarded while any hold is live, and every holder must agree to leave. A
|
|
89
|
+
* reloaded document, or a page that has left the stack, starts unguarded.
|
|
90
|
+
*/
|
|
91
|
+
export function holdLeaveGuard(onRequest) {
|
|
92
|
+
const s = store();
|
|
93
|
+
// A wrapper, so the same function held twice is two holds.
|
|
94
|
+
const handler = (request) => onRequest(request);
|
|
95
|
+
s.holders.push(handler);
|
|
96
|
+
syncGuard();
|
|
97
|
+
return () => {
|
|
98
|
+
const index = s.holders.indexOf(handler);
|
|
99
|
+
if (index < 0)
|
|
100
|
+
return;
|
|
101
|
+
s.holders.splice(index, 1);
|
|
102
|
+
syncGuard();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// A plain function rather than an `async` one: this module also builds for
|
|
106
|
+
// ES5. A missing bridge surfaces as a rejection, never a synchronous throw.
|
|
107
|
+
function callHost(route, input) {
|
|
108
|
+
const bridge = typeof window !== 'undefined' ? window.LingXiaBridge : undefined;
|
|
109
|
+
if (!bridge)
|
|
110
|
+
return Promise.reject(new Error('LingXiaBridge is not available'));
|
|
111
|
+
try {
|
|
112
|
+
return bridge.invoke(route, input);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return Promise.reject(error);
|
|
116
|
+
}
|
|
117
|
+
}
|
package/dist/es5/bridge.js
CHANGED
|
@@ -97,6 +97,7 @@ import { toBridgeError, toNativeError } from "./invocation";
|
|
|
97
97
|
import { installNativeComponentCoverageMonitor } from "./nativecomponents/coverage-monitor";
|
|
98
98
|
import { consumeV3Bootstrap, } from "./protocol-v3";
|
|
99
99
|
import { getHost, subscribeHost } from "./host";
|
|
100
|
+
import { holdLeaveGuard } from "./leave-guard";
|
|
100
101
|
import { BRIDGE_CONFIG, getCommunicationMethod, getPlatformOS, isAndroid, isHarmony, isIOS, isMacOS, isWindows, isDesktop, isMobile, isApple, isDevSession, isRunner, } from "./runtime-env";
|
|
101
102
|
var NATIVE_HANDLER_NAME = "LingXia";
|
|
102
103
|
var GLOBAL_RECEIVER_NAME = "__LingXiaRecvMessage";
|
|
@@ -2212,6 +2213,10 @@ export var LingXiaBridge = {
|
|
|
2212
2213
|
get: getHost,
|
|
2213
2214
|
subscribe: subscribeHost,
|
|
2214
2215
|
},
|
|
2216
|
+
// The leave guard, for the same plain-HTML documents.
|
|
2217
|
+
leaveGuard: {
|
|
2218
|
+
hold: holdLeaveGuard,
|
|
2219
|
+
},
|
|
2215
2220
|
platform: {
|
|
2216
2221
|
isHarmony: isHarmony,
|
|
2217
2222
|
isIOS: isIOS,
|
package/dist/es5/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export { LingXiaBridge, channel, initBridge, invoke, notify, stream, } from './bridge';
|
|
9
9
|
export { isNativeError } from './invocation';
|
|
10
10
|
export { getHost, subscribeHost } from './host';
|
|
11
|
+
export { holdLeaveGuard } from './leave-guard';
|
|
11
12
|
export { renderErrorUI, renderPageFault, hasError, getErrorInfo } from './error';
|
|
12
13
|
export { boot, bootWhenReady } from './boot';
|
|
13
14
|
import { bootWhenReady } from './boot';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarding a page against being left with unsaved changes.
|
|
3
|
+
*
|
|
4
|
+
* While a page holds the guard, a user back or home (navigation bar buttons,
|
|
5
|
+
* Android/Harmony system back, the iOS/Harmony edge swipe) does not leave it.
|
|
6
|
+
* The host asks here instead, each holder answers, and when all agree the
|
|
7
|
+
* host carries out what the user asked for.
|
|
8
|
+
*
|
|
9
|
+
* Works without Logic: a View-only (`logic: false`) page owns its drafts, so
|
|
10
|
+
* the guard is held from the View.
|
|
11
|
+
*
|
|
12
|
+
* Its only import-time effect is installing the host hook (idempotent, shared
|
|
13
|
+
* across bundle copies). It reaches the host through the already-booted
|
|
14
|
+
* `window.LingXiaBridge` at call time and never imports the bridge module, so
|
|
15
|
+
* the plain-HTML global build can include it without booting a second bridge.
|
|
16
|
+
*/
|
|
17
|
+
function newStore() {
|
|
18
|
+
return { holders: [], sent: false, tail: Promise.resolve(), asking: false };
|
|
19
|
+
}
|
|
20
|
+
var fallbackStore = newStore();
|
|
21
|
+
function store() {
|
|
22
|
+
if (typeof window === 'undefined')
|
|
23
|
+
return fallbackStore;
|
|
24
|
+
// Shared by every copy of the bridge module in this document.
|
|
25
|
+
var host = window;
|
|
26
|
+
if (!host.__lxLeaveGuard)
|
|
27
|
+
host.__lxLeaveGuard = newStore();
|
|
28
|
+
return host.__lxLeaveGuard;
|
|
29
|
+
}
|
|
30
|
+
// The host keeps one flag per page. Tell it whether anyone holds, one call at
|
|
31
|
+
// a time so a quick hold → release cannot land reversed.
|
|
32
|
+
function syncGuard() {
|
|
33
|
+
var s = store();
|
|
34
|
+
s.tail = s.tail.then(function () {
|
|
35
|
+
var want = s.holders.length > 0;
|
|
36
|
+
if (want === s.sent)
|
|
37
|
+
return undefined;
|
|
38
|
+
s.sent = want;
|
|
39
|
+
return callHost('navigation.setLeaveGuard', { enabled: want }).catch(function (error) {
|
|
40
|
+
s.sent = !want;
|
|
41
|
+
// A refused guard (bridge not ready, a runtime without the route)
|
|
42
|
+
// leaves the page unguarded; say so rather than fail silently.
|
|
43
|
+
console.warn('[lingxia] leave guard not applied; the page is not guarded', error);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Host entry point: the user tried to leave a guarded page. */
|
|
48
|
+
function dispatchLeaveRequest(reason) {
|
|
49
|
+
var s = store();
|
|
50
|
+
// One question at a time: a second back while a dialog is open is dropped.
|
|
51
|
+
if (s.asking)
|
|
52
|
+
return;
|
|
53
|
+
s.asking = true;
|
|
54
|
+
var request = { reason: reason };
|
|
55
|
+
// Newest holder first; the first refusal keeps the page.
|
|
56
|
+
var holders = s.holders.slice().reverse();
|
|
57
|
+
var agreed = Promise.resolve(true);
|
|
58
|
+
holders.forEach(function (handler) {
|
|
59
|
+
agreed = agreed.then(function (leave) { return (leave ? handler(request) : false); });
|
|
60
|
+
});
|
|
61
|
+
agreed
|
|
62
|
+
.then(function (leave) { return leave === true; }, function (error) {
|
|
63
|
+
console.error('[lingxia] leave guard handler failed; staying on the page', error);
|
|
64
|
+
return false;
|
|
65
|
+
})
|
|
66
|
+
.then(function (leave) {
|
|
67
|
+
s.asking = false;
|
|
68
|
+
if (!leave)
|
|
69
|
+
return undefined;
|
|
70
|
+
return callHost('navigation.leave', { reason: reason }).catch(function (error) {
|
|
71
|
+
console.warn('[lingxia] leaving the page failed', error);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (typeof window !== 'undefined' && !window.__lingxiaDispatchLeaveRequest) {
|
|
76
|
+
Object.defineProperty(window, '__lingxiaDispatchLeaveRequest', {
|
|
77
|
+
configurable: false,
|
|
78
|
+
enumerable: false,
|
|
79
|
+
value: dispatchLeaveRequest,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Hold this page against user back and home until the returned function is
|
|
84
|
+
* called. Hold while there are unsaved changes; `onRequest` is asked when the
|
|
85
|
+
* user tries to leave and returns whether they may.
|
|
86
|
+
*
|
|
87
|
+
* Holds are independent: each part of a page holds for itself, the page stays
|
|
88
|
+
* guarded while any hold is live, and every holder must agree to leave. A
|
|
89
|
+
* reloaded document, or a page that has left the stack, starts unguarded.
|
|
90
|
+
*/
|
|
91
|
+
export function holdLeaveGuard(onRequest) {
|
|
92
|
+
var s = store();
|
|
93
|
+
// A wrapper, so the same function held twice is two holds.
|
|
94
|
+
var handler = function (request) { return onRequest(request); };
|
|
95
|
+
s.holders.push(handler);
|
|
96
|
+
syncGuard();
|
|
97
|
+
return function () {
|
|
98
|
+
var index = s.holders.indexOf(handler);
|
|
99
|
+
if (index < 0)
|
|
100
|
+
return;
|
|
101
|
+
s.holders.splice(index, 1);
|
|
102
|
+
syncGuard();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// A plain function rather than an `async` one: this module also builds for
|
|
106
|
+
// ES5. A missing bridge surfaces as a rejection, never a synchronous throw.
|
|
107
|
+
function callHost(route, input) {
|
|
108
|
+
var bridge = typeof window !== 'undefined' ? window.LingXiaBridge : undefined;
|
|
109
|
+
if (!bridge)
|
|
110
|
+
return Promise.reject(new Error('LingXiaBridge is not available'));
|
|
111
|
+
try {
|
|
112
|
+
return bridge.invoke(route, input);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return Promise.reject(error);
|
|
116
|
+
}
|
|
117
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export type { BridgeConfig, CallOptions, ChannelCloseEvent, ChannelOptions, Chan
|
|
|
9
9
|
export { LingXiaBridge, channel, initBridge, invoke, notify, stream, } from './bridge';
|
|
10
10
|
export { isNativeError } from './invocation';
|
|
11
11
|
export { getHost, subscribeHost, type LxHost } from './host';
|
|
12
|
+
export { holdLeaveGuard } from './leave-guard';
|
|
13
|
+
export type { LxLeaveHandler, LxLeaveReason, LxLeaveRequest } from './leave-guard';
|
|
12
14
|
export { renderErrorUI, renderPageFault, hasError, getErrorInfo } from './error';
|
|
13
15
|
export { boot, bootWhenReady } from './boot';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarding a page against being left with unsaved changes.
|
|
3
|
+
*
|
|
4
|
+
* While a page holds the guard, a user back or home (navigation bar buttons,
|
|
5
|
+
* Android/Harmony system back, the iOS/Harmony edge swipe) does not leave it.
|
|
6
|
+
* The host asks here instead, each holder answers, and when all agree the
|
|
7
|
+
* host carries out what the user asked for.
|
|
8
|
+
*
|
|
9
|
+
* Works without Logic: a View-only (`logic: false`) page owns its drafts, so
|
|
10
|
+
* the guard is held from the View.
|
|
11
|
+
*
|
|
12
|
+
* Its only import-time effect is installing the host hook (idempotent, shared
|
|
13
|
+
* across bundle copies). It reaches the host through the already-booted
|
|
14
|
+
* `window.LingXiaBridge` at call time and never imports the bridge module, so
|
|
15
|
+
* the plain-HTML global build can include it without booting a second bridge.
|
|
16
|
+
*/
|
|
17
|
+
/** What the user did: `back` (bar, system, or swipe) or the bar's `home`. */
|
|
18
|
+
export type LxLeaveReason = 'back' | 'home';
|
|
19
|
+
export interface LxLeaveRequest {
|
|
20
|
+
reason: LxLeaveReason;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Answers a leave request: `true` lets the user leave, `false` keeps the
|
|
24
|
+
* page. May be async — show a dialog and resolve with the choice.
|
|
25
|
+
*/
|
|
26
|
+
export type LxLeaveHandler = (request: LxLeaveRequest) => boolean | Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Hold this page against user back and home until the returned function is
|
|
29
|
+
* called. Hold while there are unsaved changes; `onRequest` is asked when the
|
|
30
|
+
* user tries to leave and returns whether they may.
|
|
31
|
+
*
|
|
32
|
+
* Holds are independent: each part of a page holds for itself, the page stays
|
|
33
|
+
* guarded while any hold is live, and every holder must agree to leave. A
|
|
34
|
+
* reloaded document, or a page that has left the stack, starts unguarded.
|
|
35
|
+
*/
|
|
36
|
+
export declare function holdLeaveGuard(onRequest: LxLeaveHandler): () => void;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LxLeaveHandler } from './leave-guard';
|
|
1
2
|
export interface BridgeConfig {
|
|
2
3
|
os?: 'Harmony' | 'iOS' | 'Android' | 'macOS' | 'Windows';
|
|
3
4
|
/**
|
|
@@ -142,6 +143,8 @@ declare global {
|
|
|
142
143
|
__LX_BRIDGE_CFG?: BridgeConfig;
|
|
143
144
|
/** Host push for a display language changed while the page is open. */
|
|
144
145
|
__lingxiaApplyDisplayLanguage?: (language: string, revision?: number) => void;
|
|
146
|
+
/** Host push: the user tried to leave a page that holds the leave guard. */
|
|
147
|
+
__lingxiaDispatchLeaveRequest?: (reason: 'back' | 'home') => void;
|
|
145
148
|
/** Shared by every copy of the bridge module in this document. */
|
|
146
149
|
__lxDisplayLanguage?: {
|
|
147
150
|
value: string;
|
|
@@ -210,6 +213,11 @@ export interface LingXiaBridgeInterface {
|
|
|
210
213
|
/** Change-only; read the current value with `get()`. */
|
|
211
214
|
subscribe(listener: () => void): () => void;
|
|
212
215
|
};
|
|
216
|
+
/** Guard this page against being left with unsaved changes; see `leave-guard.ts`. */
|
|
217
|
+
leaveGuard: {
|
|
218
|
+
/** Hold until the returned function is called; `onRequest` answers a leave. */
|
|
219
|
+
hold(onRequest: LxLeaveHandler): () => void;
|
|
220
|
+
};
|
|
213
221
|
platform: {
|
|
214
222
|
isHarmony(): boolean;
|
|
215
223
|
isIOS(): boolean;
|