mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
16 lines
112 KiB
JavaScript
Vendored
16 lines
112 KiB
JavaScript
Vendored
const vn="1.0.0-rc.24",rt=typeof window!="undefined",nr=typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Function("return this")(),En=()=>!1,se=Array.isArray,Z=Object.assign,H=Object.defineProperty,k=Object.defineProperties,wn=Object.prototype.toString,ge=Object.prototype.hasOwnProperty,q=t=>wn.call(t);function pe(t){return t===void 0}function xe(t){return t===null}function B(t){return typeof t=="string"}function or(t){return typeof t=="boolean"}function pt(t){return typeof t=="number"}function R(t){return typeof t=="function"}function U(t){return q(t)==="[object Object]"}function An(t){return!xe(t)&&typeof t=="object"}function mt(t){return q(t)==="[object Promise]"}function bn(t){var e;return R(t)&&((e=t.name)===null||e===void 0?void 0:e.indexOf("bound "))===0&&!t.hasOwnProperty("prototype")}function nt(t){var e;if(R(t)){const r=t.toString();return((e=t.prototype)===null||e===void 0?void 0:e.constructor)===t&&Object.getOwnPropertyNames(t.prototype).length>1||/^function\s+[A-Z]/.test(r)||/^class\s+/.test(r)}return!1}function Pn(t){return typeof ShadowRoot!="undefined"&&t instanceof ShadowRoot}function ot(t){var e;return t instanceof URL||!!(!((e=t)===null||e===void 0)&&e.href)}function ce(t){var e;return t instanceof Element||B((e=t)===null||e===void 0?void 0:e.tagName)}function ye(t){var e;return t instanceof Node||pt((e=t)===null||e===void 0?void 0:e.nodeType)}function Rn(t){return q(t)==="[object HTMLAnchorElement]"}function Sn(t){return q(t)==="[object HTMLAudioElement]"}function yn(t){return q(t)==="[object HTMLVideoElement]"}function Mn(t){return q(t)==="[object HTMLLinkElement]"}function On(t){return q(t)==="[object HTMLBodyElement]"}function ir(t){return q(t)==="[object HTMLStyleElement]"}function be(t){return q(t)==="[object HTMLScriptElement]"}function Dn(t){return q(t)==="[object HTMLDivElement]"}function Cn(t){return q(t)==="[object HTMLImageElement]"}function In(t){return q(t)==="[object HTMLBaseElement]"}function ze(t){return q(t)==="[object DocumentFragment]"}function Ln(t){return q(t)==="[object ShadowRoot]"}function Ye(t){return ce(t)&&t.tagName.toUpperCase()==="MICRO-APP-BODY"}function Tn(t){return ce(t)&&t.tagName.toUpperCase()==="MICRO-APP-HEAD"}function xn(t){let e=q(t)==="[object HTMLElement]";if(e){const r=t.tagName.toUpperCase();e=e&&!r.startsWith("MICRO-APP")}return e}function Nn(t){return q(t)==="[object ProxyDocument]"}function sr(t,e){try{return W(t).pathname.split(".").pop()===e}catch{return!1}}function te(t,e,r){if(t==null)throw new TypeError("includes target is null or undefined");const n=Object(t),o=parseInt(n.length,10)||0;if(o===0)return!1;r=parseInt(r,10)||0;let i=Math.max(r>=0?r:o+r,0);for(;i<o;){if(e===n[i]||e!==e&&n[i]!==n[i])return!0;i++}return!1}function I(t,e=null,...r){const n=e&&B(e)?` app ${e}:`:"";B(t)?console.error(`[micro-app]${n} ${t}`,...r):console.error(`[micro-app]${n}`,t,...r)}function me(t,e=null,...r){const n=e&&B(e)?` app ${e}:`:"";B(t)?console.warn(`[micro-app]${n} ${t}`,...r):console.warn(`[micro-app]${n}`,t,...r)}function ee(t,...e){Promise.resolve().then(t.bind(null,...e))}function Bn(t,e=0,...r){setTimeout(t.bind(null,...r),e)}const W=function(){class t extends URL{}return(e,r)=>r?new t(""+e,r):new t(""+e)}();function Pt(t){return t.startsWith("//")?`${nr.location.protocol}${t}`:t}function _t(t,e=null){if(!B(t)||!t)return"";try{const{origin:r,pathname:n,search:o}=W(Pt(t),(window.rawWindow||window).location.href),i=`${r}${n}${o}`;return/^https?:\/\//.test(i)?i:""}catch(r){return I(r,e),""}}function $(t){return!B(t)||!t?"":t.replace(/(^\d+)|([^\w\d-_])/gi,"")}function it(t){const{origin:e,pathname:r}=W(t);if(/\.(\w+)$/.test(r)){const n=`${e}${r}`.split("/");return n.pop(),n.join("/")+"/"}return`${e}${r}/`.replace(/\/\/$/,"/")}function X(t,e){return!t||/^((((ht|f)tps?)|file):)?\/\//.test(t)||/^(data|blob):/.test(t)?t:W(t,it(Pt(e))).toString()}function Un(t){const e=t.split("/");return e.pop(),Pt(e.join("/")+"/")}function st(t,e,r,n){let o=0;function i(){++o===t.length&&n&&n()}t.forEach((s,a)=>{mt(s)?s.then(c=>{e({data:c,index:a}),i()}).catch(c=>{r({error:c,index:a}),i()}):(e({data:s,index:a}),i())})}function Wn(){const t=document.createElement("script");return"noModule"in t}function Fn(){return"inline-"+Math.random().toString(36).substr(2,15)}function Hn(t){return t.filter(function(e){return e in this?!1:this[e]=!0},Object.create(null))}const at=nr.requestIdleCallback||function(t){const e=Date.now();return setTimeout(function(){t({didTimeout:!1,timeRemaining(){return Math.max(0,50-(Date.now()-e))}})},1)};function ar(t){return new Promise(e=>{at(()=>{t(e)})})}let Rt=null;function gt(t){Rt=t}function Q(){return Rt}function Ne(t){Rt!==t&&!Mt()&&(gt(t),ee(()=>{gt(null)}))}let St=null;function vt(t){St=t}function Ve(){return St}function yt(t){St!==t&&!Mt()&&(vt(t),ee(()=>{vt(null)}))}let Ce=!1;function Mt(){return Ce}function G(t){t!==!1?(gt(null),vt(null),t&&!Ce&&(Ce=!0,ee(()=>{Ce=!1}))):Ce=!1}function z(t,e){const r=(window.rawDocument||document).createElement(t,e);return r.__MICRO_APP_NAME__&&delete r.__MICRO_APP_NAME__,r.__PURE_ELEMENT__=!0,r}function he(t){return!t||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(t)}function Pe(t){return/^body$/i.test(t)||/^head$/i.test(t)||/^html$/i.test(t)||/^title$/i.test(t)||/^:root$/i.test(t)}function le(t){return Pn(t)?t.host:t}function ft(t){return t?t.replace(/^\s+|\s+$/g,""):""}function Wt(){return navigator.userAgent.indexOf("Firefox")>-1}function Ft(t){const e={},r=t.split("&");for(const n of r){const o=n.indexOf("="),i=o<0?n:n.slice(0,o),s=o<0?null:n.slice(o+1);if(i in e){let a=e[i];se(a)||(a=e[i]=[a]),a.push(s)}else e[i]=s}return e}function Je(t){let e="";for(const r in t){const n=t[r];xe(n)?e+=(e.length?"&":"")+r:(se(n)?n:[n]).forEach(i=>{pe(i)||(e+=(e.length?"&":"")+r,xe(i)||(e+="="+i))})}return e}function Ht(){const t=new Set;function e(r){return t.add(r),()=>t.has(r)?t.delete(r):!1}return{add:e,list:()=>t}}function jn(){const t=new Map;function e(r,n){return t.set(r,n),()=>t.has(r)?t.delete(r):!1}return{add:e,get:r=>t.get(r),delete:r=>t.has(r)?t.delete(r):!1}}function Et(t){const e=t.attributes,r=new Map;for(let n=0;n<e.length;n++)r.set(e[n].name,e[n].value);return r}function Be(t,e){t?t.push(()=>ar(r=>{e(),r()})):e()}function Ue(t){return(t==null?void 0:t.reduce((e,r)=>e.then(r),Promise.resolve()))||null}function We(t){return t.startsWith("inline-")}function jt(t,e,r,...n){try{R(t)&&t(...n)}catch(o){I(`An error occurred in app ${e} window.${r}
|
|
`,null,o)}}function $n(t){for(;t!=null&&t.firstChild;)t.removeChild(t.firstChild)}function $t(t,e){if(t==null)return!1;if(R(e)){if(typeof t=="number"||typeof t=="string"||typeof t=="boolean")return!1}else throw new TypeError("Right-hand side of 'instanceof' is not callable");let r=Object.getPrototypeOf(t);for(;r;){if(r===e.prototype)return!0;r=Object.getPrototypeOf(r)}return!1}const Gn=["mounted","unmount"];function wt(t,e){return Gn.includes(t)?`${t}-${e}`:t}function Kn(t){return U(t)?!Object.keys(t).length:!0}function qn(t,e){Object.defineProperties(t,{currentTarget:{get(){return e}},target:{get(){return e}}})}function ue(t,e,r,n){var o;if(!t)return me(`element does not exist in lifecycle ${r}`,e);t=le(t),G();const i=Z({name:e,container:t},n&&{error:n}),s=new CustomEvent(r,{detail:i});qn(s,t),R((o=v.options.lifeCycles)===null||o===void 0?void 0:o[r])&&v.options.lifeCycles[r](s,e),t.dispatchEvent(s)}function oe(t,e,r={}){var n;const o=new CustomEvent(wt(e,t.name),{detail:r});(n=t.sandBox)===null||n===void 0||n.microAppWindow.dispatchEvent(o)}function ve(t,e=null,r={}){return G(),R(v.options.fetch)?v.options.fetch(t,r,e):window.fetch(t,r).then(n=>n.text())}class Ot{static getInstance(){return this.instance||(this.instance=new Ot),this.instance}run(e,r){const n=e.name,o=e.ssrUrl||e.url;(sr(o,"js")?Promise.resolve(`<micro-app-head><script src='${o}'><\/script></micro-app-head><micro-app-body></micro-app-body>`):ve(o,n,{cache:"no-cache"})).then(a=>{if(!a){const c="html is empty, please check in detail";return e.onerror(new Error(c)),I(c,n)}a=this.formatHTML(o,a,n),r(a,e)}).catch(a=>{I(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n,a),e.onLoadError(a)})}formatHTML(e,r,n){return this.processHtml(e,r,n,v.options.plugins).replace(/<head[^>]*>[\s\S]*?<\/head>/i,o=>o.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>")).replace(/<body[^>]*>[\s\S]*?<\/body>/i,o=>o.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))}processHtml(e,r,n,o){var i;if(!o)return r;const s=[];return o.global&&s.push(...o.global),!((i=o.modules)===null||i===void 0)&&i[n]&&s.push(...o.modules[n]),s.length>0?s.reduce((a,c)=>U(c)&&R(c.processHtml)?c.processHtml(a,e):a,r):r}}const Qn=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,Gt=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function Vn(t,e){t=e?`${e} ${t}`:t;const r=new Error(t);throw r.reason=t,e&&(r.filename=e),r}class Xn{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForRuleWithChildRule(/^@media *([^{]+)/,"@media"),this.supportsRule=this.createMatcherForRuleWithChildRule(/^@supports *([^{]+)/,"@supports"),this.documentRule=this.createMatcherForRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"@document"),this.hostRule=this.createMatcherForRuleWithChildRule(/^@host\s*/,"@host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace"),this.containerRule=this.createMatcherForRuleWithChildRule(/^@container *([^{]+)/,"@container")}exec(e,r,n,o){return this.cssText=e,this.prefix=r,this.baseURI=n,this.linkPath=o||"",this.matchRules(),Wt()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&this.cssText.charAt(0)!=="}"&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):this.printError("selector missing",this.linkPath)}formatSelector(e){const r=this.commonMatch(/^[^{]+/,e);if(!r)return!1;const n={};return r[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g,(i,s,a)=>{const c=`__mock_${s}Value__`;return n[c]=a,i.replace(a,c)}).replace(/(^|,[\n\s]*)([^,]+)/g,(i,s,a)=>(a=ft(a),a=a.replace(/\[[^\]=]+(?:=([^\]]+))?\]/g,(c,h)=>n[h]?c.replace(h,n[h]):c),a&&!(this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(a))||Qn.test(a))&&(Gt.test(a)?a=a.replace(Gt,this.prefix+" micro-app-body"):a=this.prefix+" "+a),s+a))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?!0:this.printError("Declaration missing '}'",this.linkPath)):this.printError("Declaration missing '{'",this.linkPath)}matchAllDeclarations(e=0){let r=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^{}/])*/,!0)[0];if(r&&(!this.scopecssDisableNextLine&&(!this.scopecssDisable||this.scopecssDisableSelectors.length)&&(r=r.replace(/url\((["']?)(.*?)\1\)/gm,(n,o,i)=>/^((data|blob):|#|%23)/.test(i)||/^(https?:)?\/\//.test(i)?n:(/^((\.\.?\/)|[^/])/.test(i)&&this.linkPath&&(this.baseURI=Un(this.linkPath)),`url("${X(i,this.baseURI)}")`))),this.recordResult(r)),this.scopecssDisableNextLine=!1,!!this.cssText.length){if(this.cssText.charAt(0)==="/")this.cssText.charAt(1)==="*"?this.matchComments():this.commonMatch(/\/+/);else if(this.cssText.charAt(0)==="{")this.matchOpenBrace(),e++;else if(this.cssText.charAt(0)==="}"){if(e<1)return;this.matchCloseBrace(),e--}return this.matchAllDeclarations(e)}}matchAtRule(){return this.cssText[0]!=="@"?!1:(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.containerRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule()||this.layerRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^[^{]+/))return this.printError("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return this.printError("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):this.printError("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const r=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)r.push(e[1]),this.commonMatch(/^,\s*/);return r.length?(this.styleDeclarations(),this.matchLeadingSpaces(),!0):!1}customMediaRule(){return this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)?(this.matchLeadingSpaces(),!0):!1}pageRule(){return this.commonMatch(/^@page */)?(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page")):!1}fontFaceRule(){return this.commonMatch(/^@font-face\s*/)?this.commonHandlerForAtRuleWithSelfRule("font-face"):!1}layerRule(){return this.commonMatch(/^@layer\s*([^{;]+)/)?this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):this.printError("@layer missing '}'",this.linkPath)):!!this.commonMatch(/^[;]+/):!1}createMatcherForRuleWithChildRule(e,r){return()=>this.commonMatch(e)?this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):this.printError(`${r} missing '}'`,this.linkPath)):this.printError(`${r} missing '{'`,this.linkPath):!1}createMatcherForNoneBraceAtRule(e){const r=new RegExp("^@"+e+"\\s*([^;]+);");return()=>this.commonMatch(r)?(this.matchLeadingSpaces(),!0):!1}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):this.printError(`@${e} missing '}'`,this.linkPath)):this.printError(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if(this.cssText.charAt(0)!=="/"||this.cssText.charAt(1)!=="*")return!1;this.scopecssDisableNextLine=!1;let e=2;for(;this.cssText.charAt(e)!==""&&(this.cssText.charAt(e)!=="*"||this.cssText.charAt(e+1)!=="/");)++e;if(e+=2,this.cssText.charAt(e-1)==="")return this.printError("End of comment missing",this.linkPath);let r=this.cssText.slice(2,e-2);return this.recordResult(`/*${r}*/`),r=ft(r.replace(/^\s*!/,"")),r==="scopecss-disable-next-line"?this.scopecssDisableNextLine=!0:/^scopecss-disable/.test(r)?r==="scopecss-disable"?this.scopecssDisable=!0:(this.scopecssDisable=!0,r.replace("scopecss-disable","").split(",").forEach(o=>{this.scopecssDisableSelectors.push(ft(o))})):r==="scopecss-enable"&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]),this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,r=!1){const n=e.exec(this.cssText);if(!n)return;const o=n[0];return this.cssText=this.cssText.slice(o.length),r||this.recordResult(o),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}\s*/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){Wt()?this.result+=encodeURIComponent(e):this.result+=e}printError(e,r){this.cssText.length&&Vn(e,r)}}function Kt(t,e,r,n,o){if(!t.__MICRO_APP_HAS_SCOPED__){t.__MICRO_APP_HAS_SCOPED__=!0;let i=null;try{i=Ie.exec(t.textContent,r,n,o),Ie.reset()}catch(s){Ie.reset(),I(`An error occurred while parsing CSS:
|
|
`,e,s)}i&&(t.textContent=i)}}let Ie;function ct(t,e,r){if(e.scopecss){const n=Dt(e.name);Ie||(Ie=new Xn);const o=i=>i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(t.textContent){Kt(t,e.name,n,e.url,r);const i=new MutationObserver(()=>{const s=o(n),a=t.textContent&&new RegExp(s).test(t.textContent);i.disconnect(),a||(t.__MICRO_APP_HAS_SCOPED__=!1,ct(t,e,r))});i.observe(t,{childList:!0,characterData:!0})}else{const i=new MutationObserver(function(){i.disconnect(),t.textContent&&!t.hasAttribute("data-styled")&&Kt(t,e.name,n,e.url,r)});i.observe(t,{childList:!0})}}return t}function Dt(t,e=!1){const r=e?"\\":"";return`${v.tagName}${r}[name=${t}${r}]`}function cr(t,e){Object.defineProperties(t,{currentTarget:{get(){return e}},srcElement:{get(){return e}},target:{get(){return e}}})}function lr(t){const e=new CustomEvent("load");cr(e,t),R(t.onload)?t.onload(e):t.dispatchEvent(e)}function ur(t){const e=new CustomEvent("error");cr(e,t),R(t.onerror)?t.onerror(e):t.dispatchEvent(e)}function zn(){const t=new Map,e=new Map;function r(n){return{setInfo(o,i){n.set(o,i)},getInfo(o){var i;return(i=n.get(o))!==null&&i!==void 0?i:null},hasInfo(o){return n.has(o)},deleteInfo(o){return n.delete(o)}}}return{link:r(t),script:Object.assign(Object.assign({},r(e)),{deleteInlineInfo(n){n.forEach(o=>{We(o)&&e.delete(o)})}})}}var Y=zn();function Yn(t,e,r){const n=r.appSpace;for(const o in n)if(o!==t){const i=n[o];if(i.parsedCode)return i.parsedCode.replace(new RegExp(Dt(o,!0),"g"),e)}}function Jn(t,e){e.forEach((r,n)=>{n!=="rel"&&(n==="href"&&(n="data-origin-href"),l.rawSetAttribute.call(t,n,r))})}function hr(t,e,r,n=!1){const o=t.getAttribute("rel");let i=t.getAttribute("href"),s=null;if(o==="stylesheet"&&i){i=X(i,r.url);let a=Y.link.getInfo(i);const c={attrs:Et(t)};if(a?a.appSpace[r.name]=a.appSpace[r.name]||c:a={code:"",appSpace:{[r.name]:c}},Y.link.setInfo(i,a),!n)r.source.links.add(i),s=document.createComment(`link element with href=${i} move to micro-app-head as style element`),a.appSpace[r.name].placeholder=s;else return{address:i,linkInfo:a}}else o&&["prefetch","preload","prerender","modulepreload","icon"].includes(o)?n?s=document.createComment(`link element with rel=${o}${i?" & href="+i:""} removed by micro-app`):e==null||e.removeChild(t):i&&l.rawSetAttribute.call(t,"href",X(i,r.url));if(n)return{replaceComment:s};if(s)return e==null?void 0:e.replaceChild(s,t)}function Zn(t,e,r,n){const o=Array.from(e.source.links),i=o.map(a=>{const c=Y.link.getInfo(a);return c.code?c.code:ve(a,e.name)}),s=n?[]:null;st(i,a=>{Be(s,()=>kn(o[a.index],a.data,r,e))},a=>{I(a,e.name)},()=>{n?n.then(()=>{s.push(()=>Promise.resolve(e.onLoad({html:t}))),Ue(s)}):e.onLoad({html:t})})}function kn(t,e,r,n){const o=Y.link.getInfo(t);o.code=e;const i=o.appSpace[n.name],s=i.placeholder;if(s){const a=z("style");dr(n,t,a,o,i.attrs),s.parentNode?s.parentNode.replaceChild(a,s):r.appendChild(a),i.placeholder=null}}function dr(t,e,r,n,o){if(t.scopecss){const i=n.appSpace[t.name];if(i.prefix=i.prefix||Dt(t.name),i.parsedCode)r.textContent=i.parsedCode;else{const s=Yn(t.name,i.prefix,n);s?r.textContent=s:(r.textContent=n.code,ct(r,t,e)),i.parsedCode=r.textContent}}else r.textContent=n.code;Jn(r,o)}function eo(t,e,r,n){const o=z("style"),i=()=>{dr(e,t,o,r,r.appSpace[e.name].attrs),lr(n)};return r.code?ee(i):ve(t,e.name).then(s=>{r.code=s,i()}).catch(s=>{I(s,e.name),ur(n)}),o}var Le;(function(t){t.NAME="name",t.URL="url"})(Le||(Le={}));var j;(function(t){t.CREATED="created",t.LOADING="loading",t.LOAD_FAILED="load_failed",t.BEFORE_MOUNT="before_mount",t.MOUNTING="mounting",t.MOUNTED="mounted",t.UNMOUNT="unmount"})(j||(j={}));var N;(function(t){t.CREATED="created",t.BEFOREMOUNT="beforemount",t.MOUNTED="mounted",t.UNMOUNT="unmount",t.ERROR="error",t.BEFORESHOW="beforeshow",t.AFTERSHOW="aftershow",t.AFTERHIDDEN="afterhidden"})(N||(N={}));var we;(function(t){t.ONMOUNT="onmount",t.ONUNMOUNT="onunmount"})(we||(we={}));var Te;(function(t){t.KEEP_ALIVE_SHOW="keep_alive_show",t.KEEP_ALIVE_HIDDEN="keep_alive_hidden"})(Te||(Te={}));var qt;(function(t){t.DESTROY="destroy",t.DESTORY="destory",t.INLINE="inline",t.DISABLESCOPECSS="disableScopecss",t.DISABLESANDBOX="disableSandbox",t.DISABLE_SCOPECSS="disable-scopecss",t.DISABLE_SANDBOX="disable-sandbox",t.DISABLE_MEMORY_ROUTER="disable-memory-router",t.DISABLE_PATCH_REQUEST="disable-patch-request",t.KEEP_ROUTER_STATE="keep-router-state",t.KEEP_ALIVE="keep-alive",t.CLEAR_DATA="clear-data",t.SSR="ssr",t.FIBER="fiber"})(qt||(qt={}));const Qt="window,self,globalThis,document,Document,Array,Object,String,Boolean,Math,Number,Symbol,Date,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,navigator,undefined,location,history",Vt=[1,2,3],fr="state",Fe="search",Ze="native",pr="native-scope",mr="pure",to=[Fe,fr,Ze,pr,mr],_r=["popstate","hashchange","load","unload","unmount","appstate-change","statechange","mounted","error"],ro=_r,no=_r.concat(["unhandledrejection","message"]),gr=["onpopstate","onhashchange","onload","onunload","onerror"],oo=gr,io=gr.concat(["onunhandledrejection"]),so=["DOMContentLoaded","readystatechange"],ao=["onreadystatechange"],vr=["window","self","globalThis"],co=["rawWindow","rawDocument"],lo=["host","hostname","port","protocol","origin"],uo=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module","systemjs-module","systemjs-importmap"];function de(t,e){return e.appSpace[t.name].module&&(!t.useSandbox||t.iframe)}function ho(t,e){return e.appSpace[t.name].attrs.has("id")}function lt(t,e){return t.inline||e.appSpace[t.name].inline||de(t,e)||ho(t,e)}function Er(t){return t.iframe?t.sandBox.microAppWindow:l.rawWindow}function fo(t,e){const r=Er(t);return new r.Function(e)}function po(t,e,r){const n=e.appSpace;for(const o in n)if(o!==t.name){const i=n[o];if(i.parsedCode===r&&i.parsedFunction)return i.parsedFunction}}function wr(t,e,r){return po(t,e,r)||fo(t,r)}function Ar(){const t=Fn();return Y.script.hasInfo(t)?Ar():t}function mo(t,e){e.forEach((r,n)=>{n==="type"&&r==="module"||n==="defer"||n==="async"||(n==="src"&&(n="data-origin-src"),l.rawSetAttribute.call(t,n,r))})}function br(t,e){return t.useSandbox&&!de(t,e)}function Pr(t,e){return br(t,e)?t.iframe?"iframe":"with":"disable"}function Rr(t,e,r,n=!1){var o;let i=null,s=t.getAttribute("src");if(s&&(s=X(s,r.url)),t.hasAttribute("exclude")||Ct(s,r.name))i=document.createComment("script element with exclude attribute removed by micro-app");else{if(t.type&&!uo.includes(t.type)||t.hasAttribute("ignore")||It(s,r.name))return!((o=l.rawDocument)===null||o===void 0)&&o.currentScript&&delete l.rawDocument.currentScript,null;if(l.supportModuleScript&&t.noModule||!l.supportModuleScript&&t.type==="module")i=document.createComment(`${t.noModule?"noModule":"module"} script ignored by micro-app`);else if(s){let a=Y.script.getInfo(s);const c={async:t.hasAttribute("async"),defer:t.defer||t.type==="module",module:t.type==="module",inline:t.hasAttribute("inline"),pure:t.hasAttribute("pure"),attrs:Et(t)};if(a?a.appSpace[r.name]=a.appSpace[r.name]||c:a={code:"",isExternal:!0,appSpace:{[r.name]:c}},Y.script.setInfo(s,a),!n)r.source.scripts.add(s),i=document.createComment(`script with src='${s}' extract by micro-app`);else return{address:s,scriptInfo:a}}else if(t.textContent){const a=Ar(),c={code:t.textContent,isExternal:!1,appSpace:{[r.name]:{async:!1,defer:t.type==="module",module:t.type==="module",inline:t.hasAttribute("inline"),pure:t.hasAttribute("pure"),attrs:Et(t)}}};if(!n)r.source.scripts.add(a),Y.script.setInfo(a,c),i=document.createComment("inline script extract by micro-app");else return{address:a,scriptInfo:c}}else n||(i=document.createComment("script element removed by micro-app"))}return n?{replaceComment:i}:e==null?void 0:e.replaceChild(i,t)}function Sr(t){var e,r,n;const o=((e=v.options.plugins)===null||e===void 0?void 0:e.global)||[],i=((n=(r=v.options.plugins)===null||r===void 0?void 0:r.modules)===null||n===void 0?void 0:n[t])||[];return[...o,...i]}function Ct(t,e){return t?(Sr(e)||[]).some(n=>n.excludeChecker?n.excludeChecker(t):!1):!1}function It(t,e){return t?(Sr(e)||[]).some(n=>n.ignoreChecker?n.ignoreChecker(t):!1):!1}function _o(t,e){const r=Array.from(e.source.scripts),n=[],o=[];for(const s of r){const a=Y.script.getInfo(s),c=a.appSpace[e.name];(!c.defer&&!c.async||e.isPrefetch&&!e.isPrerender)&&(n.push(a.code?a.code:ve(s,e.name)),o.push([s,a]))}const i=e.isPrefetch||e.fiber?[]:null;n.length?st(n,s=>{Be(i,()=>go(o[s.index][0],o[s.index][1],s.data,e))},s=>{I(s,e.name)},()=>{i?(i.push(()=>Promise.resolve(e.onLoad({html:t}))),Ue(i)):e.onLoad({html:t})}):e.onLoad({html:t})}function go(t,e,r,n){if(e.code=r,n.isPrefetch&&n.prefetchLevel===2){const o=e.appSpace[n.name];if(!o.parsedCode&&(o.parsedCode=yr(t,n,r,e),o.sandboxType=Pr(n,e),!lt(n,e)))try{o.parsedFunction=wr(n,e,o.parsedCode)}catch(i){I("Something went wrong while handling preloaded resources",n.name,`
|
|
`,i)}}}function vo(t,e){const r=t.fiber?[]:null,n=Array.from(t.source.scripts),o=[],i=[];for(const s of n){const a=Y.script.getInfo(s),c=a.appSpace[t.name];c.defer||c.async?(a.isExternal&&!a.code&&!de(t,a)?o.push(ve(s,t.name)):o.push(a.code),i.push([s,a]),de(t,a)&&(e.moduleCount=e.moduleCount?++e.moduleCount:1)):Be(r,()=>{ke(s,t,a),e(!1)})}o.length?st(o,s=>{const a=i[s.index][1];a.code=a.code||s.data},s=>{e.errorCount=e.errorCount?++e.errorCount:1,I(s,t.name)},()=>{i.forEach(([s,a])=>{B(a.code)&&Be(r,()=>{ke(s,t,a,e),!de(t,a)&&e(!1)})}),r?(r.push(()=>Promise.resolve(e(pe(e.moduleCount)||e.errorCount===o.length))),Ue(r)):e(pe(e.moduleCount)||e.errorCount===o.length)}):r?(r.push(()=>Promise.resolve(e(!0))),Ue(r)):e(!0)}function ke(t,e,r,n,o){var i,s;try{Po(e);const a=r.appSpace[e.name],c=Pr(e,r);if((!a.parsedCode||a.sandboxType!==c)&&(a.parsedCode=yr(t,e,r.code,r),a.sandboxType=c,a.parsedFunction=null),lt(e,r)){const h=o||z("script");if(Ao(t,a.parsedCode,de(e,r),h,a.attrs,n),!o){const d=e.iframe?(i=e.sandBox)===null||i===void 0?void 0:i.microBody:e.querySelector("micro-app-body");d==null||d.appendChild(h)}}else bo(e,r)}catch(a){console.warn(`[micro-app from ${o?"runDynamicScript":"runScript"}] app ${e.name}: `,a,t);const c=a;let h=!0;if(typeof((s=v==null?void 0:v.options)===null||s===void 0?void 0:s.excludeRunScriptFilter)=="function"&&(h=v.options.excludeRunScriptFilter(t,c,e.name,e.url)!==!0),h)throw a}}function Eo(t,e,r,n){const o=lt(e,r)?z("script"):document.createComment(`dynamic script with src='${t}' extract by micro-app`),i=()=>lr(n),s=()=>{const a=Object.getOwnPropertyDescriptor(l.rawDocument,"currentScript");(!a||a.configurable)&&Object.defineProperty(l.rawDocument,"currentScript",{value:n,configurable:!0}),ke(t,e,r,i,o),!de(e,r)&&i()};return r.code||de(e,r)?ee(s):ve(t,e.name).then(a=>{r.code=a,s()}).catch(a=>{I(a,e.name),ur(n)}),o}function wo(t,e,r){const n=lt(e,r)?z("script"):document.createComment("dynamic inline script extract by micro-app");return ke(t,e,r,void 0,n),n}function Ao(t,e,r,n,o,i){if(r){if(l.rawSetAttribute.call(n,"type","module"),We(t)?n.textContent=e:n.src=t,i){const s=()=>{i.moduleCount&&i.moduleCount--,i(i.moduleCount===0)};We(t)?ee(s):n.onload=s}}else n.textContent=e;mo(n,o)}function bo(t,e){const r=e.appSpace[t.name];r.parsedFunction||(r.parsedFunction=wr(t,e,r.parsedCode)),r.parsedFunction.call(Er(t))}function yr(t,e,r,n){return U(v.options.plugins)&&(r=So(t,r,e.name,v.options.plugins)),br(e,n)?e.iframe?`(function(window,self,global,location){;${r}
|
|
${We(t)?"":`//# sourceURL=${t}
|
|
`}}).call(window.__MICRO_APP_SANDBOX__.proxyWindow,window.__MICRO_APP_SANDBOX__.proxyWindow,window.__MICRO_APP_SANDBOX__.proxyWindow,window.__MICRO_APP_SANDBOX__.proxyWindow,window.__MICRO_APP_SANDBOX__.proxyLocation);`:`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${Qt}){;${r}
|
|
${We(t)?"":`//# sourceURL=${t}
|
|
`}}).call(proxyWindow,${Qt})}})(window.__MICRO_APP_PROXY_WINDOW__);`:r}function Po(t){Ro(t)}function Ro(t){t.sandBox&&(l.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow)}function So(t,e,r,n){var o;const i=Xt(n.global,e,t);return Xt((o=n.modules)===null||o===void 0?void 0:o[r],i,t)}function Xt(t,e,r){return se(t)?t.reduce((n,o)=>U(o)&&R(o.loader)?o.loader(n,r):n,e):e}function yo(t,e,r){if(!t||!On(t))return;Array.from(t.getElementsByTagName("link")).map(a=>(a.hasAttribute("exclude")||Ct(a.getAttribute("href"),e.name)?a.parentElement.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),a):a.hasAttribute("ignore")||It(a.getAttribute("href"),e.name)?a.hasAttribute("href")&&l.rawSetAttribute.call(a,"href",X(a.getAttribute("href"),e.url)):hr(a,a.parentElement,e),a)),Array.from(t.getElementsByTagName("style")).map(a=>(a.hasAttribute("exclude")?a.parentElement.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),a):e.scopecss&&!a.hasAttribute("ignore")&&Be(r,()=>ct(a,e)),a)),Array.from(t.getElementsByTagName("script")).map(a=>(Rr(a,a.parentElement,e),a)),Array.from(t.getElementsByTagName("img")).map(a=>(a.hasAttribute("src")&&l.rawSetAttribute.call(a,"src",X(a.getAttribute("src"),e.url)),a))}function Mo(t,e){const r=e.parseHtmlString(t),n=l.rawElementQuerySelector.call(r,"micro-app-head"),o=l.rawElementQuerySelector.call(r,"micro-app-body");if(!n||!o){const a=`element ${n?"body":"head"} is missing`;return e.onerror(new Error(a)),I(a,e.name)}const i=e.isPrefetch||e.fiber?[]:null;yo(r,e,i);const s=Ue(i);e.source.links.size?Zn(r,e,n,s):s?s.then(()=>e.onLoad({html:r})):e.onLoad({html:r}),e.source.scripts.size?_o(r,e):e.onLoad({html:r})}class Oo{constructor(){this.eventList=new Map,this.queue=[],this.recordStep={},this.process=()=>{var e,r;let n;const o=this.recordStep,i=this.queue;for(this.recordStep={},this.queue=[];n=i.shift();){const s=this.eventList.get(n),a=s.tempData,c=s.force;s.tempData=null,s.force=!1;let h;if(c||!this.isEqual(s.data,a)){s.data=a||s.data;for(const d of s.callbacks){const w=d(s.data);w&&(h!=null?h:h=[]).push(w)}(r=(e=o[n]).dispatchDataEvent)===null||r===void 0||r.call(e),o[n].nextStepList.forEach(d=>d(h))}}}}isLegalName(e){return e?!0:(I("event-center: Invalid name"),!1)}enqueue(e,r,n){this.recordStep[e]?(this.recordStep[e].nextStepList.push(r),n&&(this.recordStep[e].dispatchDataEvent=n)):this.recordStep[e]={nextStepList:[r],dispatchDataEvent:n},!this.queue.includes(e)&&this.queue.push(e)===1&&ee(this.process)}isEqual(e,r){if(!r||Object.keys(e).length!==Object.keys(r).length)return!1;for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&e[n]!==r[n])return!1;return!0}on(e,r,n=!1){if(this.isLegalName(e)){if(!R(r))return I("event-center: Invalid callback function");let o=this.eventList.get(e);o?n&&Object.keys(o.data).length&&(!this.queue.includes(e)||this.isEqual(o.data,o.tempData))&&r(o.data):(o={data:{},callbacks:new Set},this.eventList.set(e,o)),o.callbacks.add(r)}}off(e,r){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(R(r)?n.callbacks.delete(r):n.callbacks.clear())}}clearData(e){if(this.isLegalName(e)){const r=this.eventList.get(e);r&&(r.data={})}}dispatch(e,r,n,o,i){if(this.isLegalName(e)){if(!U(r))return I("event-center: data must be object");let s=this.eventList.get(e);s?(s.tempData=Z({},s.tempData||s.data,r),!s.force&&(s.force=!!o)):(s={data:r,callbacks:new Set},this.eventList.set(e,s),s.force=!0),this.enqueue(e,n,i)}}getData(e){var r;const n=this.eventList.get(e);return(r=n==null?void 0:n.data)!==null&&r!==void 0?r:null}}const x=new Oo;function K(t,e){return!B(t)||!t?"":e?`__${t}_from_base_app__`:`__${t}_from_micro_app__`}class Mr{addGlobalDataListener(e,r){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=r),x.on("global",e,r)}removeGlobalDataListener(e){R(e)&&x.off("global",e)}setGlobalData(e,r,n){G(),x.dispatch("global",e,o=>R(r)&&r(o),n)}forceSetGlobalData(e,r){this.setGlobalData(e,r,!0)}getGlobalData(){return x.getData("global")}clearGlobalData(){x.clearData("global")}clearGlobalDataListener(){const e=this.appName,r=x.eventList.get("global");if(r)for(const n of r.callbacks)(e&&e===n.__APP_NAME__||!(e||n.__APP_NAME__))&&r.callbacks.delete(n)}}class Do extends Mr{addDataListener(e,r,n){x.on(K($(e),!1),r,n)}removeDataListener(e,r){R(r)&&x.off(K($(e),!1),r)}getData(e,r=!1){return x.getData(K($(e),r))}setData(e,r,n,o){x.dispatch(K($(e),!0),r,i=>R(n)&&n(i),o)}forceSetData(e,r,n){this.setData(e,r,n,!0)}clearData(e,r=!0){x.clearData(K($(e),r))}clearDataListener(e){x.off(K($(e),!1))}changeEventAppName(e,r){const n=K($(e),!0),o=K($(r),!0);x.eventList.has(o)&&(x.eventList.set(n,x.eventList.get(o)),x.eventList.delete(o))}}class Or extends Mr{constructor(e){super(),this.appName=$(e),!this.appName&&I(`Invalid appName ${e}`)}addDataListener(e,r){e.__AUTO_TRIGGER__=r,x.on(K(this.appName,!0),e,r)}removeDataListener(e){R(e)&&x.off(K(this.appName,!0),e)}getData(e=!0){return x.getData(K(this.appName,e))}dispatch(e,r,n){G(),x.dispatch(K(this.appName,!1),e,o=>R(r)&&r(o),n,()=>{const o=y.get(this.appName);if((o==null?void 0:o.container)&&U(e)){const i=new CustomEvent("datachange",{detail:{data:x.getData(K(this.appName,!1))}});le(o.container).dispatchEvent(i)}})}forceDispatch(e,r){this.dispatch(e,r,!0)}clearData(e=!1){x.clearData(K(this.appName,e))}clearDataListener(){x.off(K(this.appName,!0))}}function Dr(t){var e,r;if(t){t.umdDataListeners={global:new Set((e=t.umdDataListeners)===null||e===void 0?void 0:e.global),normal:new Set((r=t.umdDataListeners)===null||r===void 0?void 0:r.normal)};const n=x.eventList.get("global");if(n)for(const i of n.callbacks)t.appName===i.__APP_NAME__&&t.umdDataListeners.global.add(i);const o=x.eventList.get(K(t.appName,!0));if(o)for(const i of o.callbacks)t.umdDataListeners.normal.add(i)}}function Cr(t){if(t!=null&&t.umdDataListeners){for(const e of t.umdDataListeners.global)t.addGlobalDataListener(e,e.__AUTO_TRIGGER__);for(const e of t.umdDataListeners.normal)t.addDataListener(e,e.__AUTO_TRIGGER__);Lt(t)}}function Lt(t){t==null||delete t.umdDataListeners}class He{constructor(){this.appInstanceMap=y}static getInstance(){return this.instance||(this.instance=new He),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,r){this.appInstanceMap.set(e,r)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function Ir(){Lr(),He.getInstance().getAll().forEach(t=>{t.container&&le(t.container).disconnectedCallback()}),!window.__MICRO_APP_UMD_MODE__&&He.getInstance().clear()}function Lr(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",Ir,!1)}function Co(){window.__MICRO_APP_ENVIRONMENT__&&(Lr(),window.addEventListener("unmount",Ir,!1))}function Io(t){return or(t.__MICRO_APP_IS_BOUND_FUNCTION__)?t.__MICRO_APP_IS_BOUND_FUNCTION__:t.__MICRO_APP_IS_BOUND_FUNCTION__=bn(t)}function Lo(t){return or(t.__MICRO_APP_IS_CONSTRUCTOR__)?t.__MICRO_APP_IS_CONSTRUCTOR__:t.__MICRO_APP_IS_CONSTRUCTOR__=nt(t)}function J(t,e,r="WINDOW"){if(R(t)&&!Lo(t)&&!Io(t)&&t.bind){const n=`__MICRO_APP_BOUND_${r}_FUNCTION__`;if(t[n])return t[n];const o=t.bind(e);for(const i in t)o[i]=t[i];return t.hasOwnProperty("prototype")&&H(o,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t[n]=o}return t}class To{constructor(e,r){this.rawWindowScopeKeyList=["location"],this.staticEscapeProperties=["System","__cjsWrapper"],this.staticScopeProperties=["webpackJsonp","webpackHotUpdate","Vue","onpopstate","onhashchange","event"],this.scopeProperties=Array.from(this.staticScopeProperties),this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.appName=e,this.url=r,this.injectReactHMRProperty()}injectReactHMRProperty(){}}class xo{}function No(){l.rawWindow._babelPolyfill&&(l.rawWindow._babelPolyfill=!1)}function Tt(t,e){const r=Array.from(t.childNodes);r.length&&r.forEach(n=>{Tt(n,e)}),F(t,e)}function F(t,e){var r,n;if(e&&ye(t)&&t.__MICRO_APP_NAME__!==e&&!t.__PURE_ELEMENT__&&!Mt()){const o={__MICRO_APP_NAME__:{configurable:!0,enumerable:!0,writable:!0,value:e}};if(Rn(t)&&He.getInstance().get(e)&&(o.href={get(){return this.getAttribute("href")},set(s){s!==void 0&&this.setAttribute("href",s)}}),k(t,o),Ee(e)){const i=(n=(r=y.get(e))===null||r===void 0?void 0:r.sandBox)===null||n===void 0?void 0:n.proxyWindow;i&&k(t,{baseURI:{configurable:!0,enumerable:!0,get:()=>i.location.href},ownerDocument:{configurable:!0,enumerable:!0,get:()=>t!==i.document?i.document:null},parentNode:Tr(e,l.rawParentNodeDesc),getRootNode:{configurable:!0,enumerable:!0,writable:!0,value:function(){return i.document}}})}}return t}function Tr(t,e){return{configurable:!0,enumerable:!0,get(){var r,n,o,i;yt(t);const s=(r=e.get)===null||r===void 0?void 0:r.call(this);return Ye(s)&&((n=y.get(t))===null||n===void 0?void 0:n.container)?((i=(o=v.options).getRootElementParentNode)===null||i===void 0?void 0:i.call(o,this,t))||l.rawDocument.body:s}}}function Bo(t,e,r){const{proxyDocument:n,documentEffect:o}=Uo(t,r),i=Wo(t,n);return k(e,{document:{configurable:!1,enumerable:!0,get(){return n}},Document:{configurable:!1,enumerable:!1,get(){return i}}}),o}function Uo(t,e){const r=new Map,n=new Map;let o=null,i=null;const{rawDocument:s,rawCreateElement:a,rawCreateElementNS:c,rawAddEventListener:h,rawRemoveEventListener:d}=l;function w(p,m){const P=a.call(s,p,m);return F(P,t)}function A(p,m,P){const T=c.call(s,p,m,P);return F(T,t)}function O(p,m,P){const T=r.get(p);T?T.add(m):r.set(p,new Set([m])),m&&(m.__MICRO_APP_MARK_OPTIONS__=P),h.call(s,p,m,P)}function D(p,m,P){const T=r.get(p);(T==null?void 0:T.size)&&T.has(m)&&T.delete(m),d.call(s,p,m,P)}const E=()=>{n.clear(),i=null},M=()=>{i=o||i,r.forEach((p,m)=>{if(p.size){const P=n.get(m)||[];n.set(m,new Set([...P,...p]))}})},b=()=>{i&&!o&&(g.onclick=i),n.forEach((p,m)=>{for(const P of p)g.addEventListener(m,P,P==null?void 0:P.__MICRO_APP_MARK_OPTIONS__)}),E()},_=()=>{R(o)&&d.call(s,"click",o),o=null,r.size&&(r.forEach((p,m)=>{for(const P of p)d.call(s,m,P)}),r.clear())},f=(()=>{var p;const m=new Map([["onclick",L=>{R(o)&&d.call(s,"click",o,!1),R(L)&&h.call(s,"click",L,!1),o=L}]]),P=((p=v.options)===null||p===void 0?void 0:p.customProxyDocumentProps)||new Map;return new Map([...m,...P])})(),g=new Proxy(s,{get:(p,m)=>{var P;return Ne(t),m==="createElement"?w:m==="createElementNS"?A:m===Symbol.toStringTag?"ProxyDocument":m==="defaultView"?e.proxyWindow:m==="onclick"?o:m==="addEventListener"?O:m==="removeEventListener"?D:m==="microAppElement"?(P=y.get(t))===null||P===void 0?void 0:P.container:m==="__MICRO_APP_NAME__"?t:J(Reflect.get(p,m),s,"DOCUMENT")},set:(p,m,P)=>(f.has(m)?f.get(m)(P):m!=="microAppElement"&&Reflect.set(p,m,P),!0)});return{proxyDocument:g,documentEffect:{reset:E,record:M,rebuild:b,release:_}}}function Wo(t,e){const{rawDocument:r,rawRootDocument:n}=l;class o{static[Symbol.hasInstance](s){let a=s;for(;a;)if(a=Object.getPrototypeOf(a),a===o.prototype)return!0;return s===e||s instanceof n}}return Object.setPrototypeOf(o,n),Object.setPrototypeOf(o.prototype,new Proxy(n.prototype,{get(i,s){return Ne(t),J(Reflect.get(i,s),r,"DOCUMENT")},set(i,s,a){return Reflect.set(i,s,a),!0}})),o}function Fo(t,e,r){return Ho(e),jo(t,e,r),$o(e,t)}function Ho(t){const e=l.rawWindow;Object.getOwnPropertyNames(e).filter(r=>/^on/.test(r)&&!oo.includes(r)).forEach(r=>{const{enumerable:n,writable:o,set:i}=Object.getOwnPropertyDescriptor(e,r)||{enumerable:!0,writable:!0};H(t,r,{enumerable:n,configurable:!0,get:()=>e[r],set:(o!=null?o:!!i)?s=>{e[r]=s}:void 0})})}function jo(t,e,r){const n=l.rawWindow,o=new Map,i=new Proxy(e,{get:(s,a)=>(Ne(t),Reflect.has(s,a)||B(a)&&/^__MICRO_APP_/.test(a)||te(r.scopeProperties,a)?(te(co,a)&&G(),Reflect.get(s,a)):J(Reflect.get(n,a),n)),set:(s,a,c)=>{if(te(r.rawWindowScopeKeyList,a))Reflect.set(n,a,c);else if(!ge.call(s,a)&&ge.call(n,a)&&!te(r.scopeProperties,a)){const h=Object.getOwnPropertyDescriptor(n,a),{configurable:d,enumerable:w,writable:A,set:O}=h;H(s,a,{value:c,configurable:d,enumerable:w,writable:A!=null?A:!!O}),r.injectedKeys.add(a)}else(!Reflect.has(s,a)||te(r.scopeProperties,a))&&r.injectedKeys.add(a),Reflect.set(s,a,c);return(te(r.escapeProperties,a)||te(r.staticEscapeProperties,a)&&!Reflect.has(n,a))&&!te(r.scopeProperties,a)&&(!Reflect.has(n,a)&&r.escapeKeys.add(a),Reflect.set(n,a,c)),!0},has:(s,a)=>te(r.scopeProperties,a)?r.injectedKeys.has(a)?Reflect.has(s,a):!!s[a]:Reflect.has(s,a)||Reflect.has(n,a),getOwnPropertyDescriptor:(s,a)=>{if(ge.call(s,a))return o.set(a,"target"),Object.getOwnPropertyDescriptor(s,a);if(ge.call(n,a)){o.set(a,"rawWindow");const c=Object.getOwnPropertyDescriptor(n,a);return c&&!c.configurable&&(c.configurable=!0),c}},defineProperty:(s,a,c)=>o.get(a)==="rawWindow"?Reflect.defineProperty(n,a,c):Reflect.defineProperty(s,a,c),ownKeys:s=>Hn(Reflect.ownKeys(n).concat(Reflect.ownKeys(s))),deleteProperty:(s,a)=>ge.call(s,a)?(r.injectedKeys.has(a)&&r.injectedKeys.delete(a),r.escapeKeys.has(a)&&Reflect.deleteProperty(n,a),Reflect.deleteProperty(s,a)):!0});r.proxyWindow=i}function $o(t,e){const r=new Map,n=new Map,o=new Map,i=new Map,{rawWindow:s,rawAddEventListener:a,rawRemoveEventListener:c,rawDispatchEvent:h,rawSetInterval:d,rawSetTimeout:w,rawClearInterval:A,rawClearTimeout:O}=l;function D(u){var f;return ro.includes(u)&&((f=y.get(e))===null||f===void 0?void 0:f.container)?le(y.get(e).container):s}t.addEventListener=function(u,f,g){u=wt(u,e);const p=r.get(u);p?p.add(f):r.set(u,new Set([f])),f&&(f.__MICRO_APP_MARK_OPTIONS__=g),a.call(D(u),u,f,g)},t.removeEventListener=function(u,f,g){u=wt(u,e);const p=r.get(u);(p==null?void 0:p.size)&&p.has(f)&&p.delete(f),c.call(D(u),u,f,g)},t.dispatchEvent=function(u){return h.call(D(u==null?void 0:u.type),u)},t.setInterval=function(u,f,...g){const p=d.call(s,u,f,...g);return o.set(p,{handler:u,timeout:f,args:g}),p},t.setTimeout=function(u,f,...g){const m=typeof u=="string"?u:function(...T){i.delete(P),typeof u=="function"&&u(...T)},P=w.call(s,m,f,...g);return i.set(P,{handler:m,timeout:f,args:g}),P},t.clearInterval=function(u){o.delete(u),A.call(s,u)},t.clearTimeout=function(u){i.delete(u),O.call(s,u)};const E=()=>{n.clear()};return{reset:E,record:()=>{r.forEach((u,f)=>{if(u.size){const g=n.get(f)||[];n.set(f,new Set([...g,...u]))}})},rebuild:()=>{n.forEach((u,f)=>{for(const g of u)t.addEventListener(f,g,g==null?void 0:g.__MICRO_APP_MARK_OPTIONS__)}),E()},release:u=>{r.size&&(r.forEach((f,g)=>{for(const p of f)c.call(D(g),g,p)}),r.clear()),u&&(o.forEach((f,g)=>{A.call(s,g)}),i.forEach((f,g)=>{O.call(s,g)}),o.clear(),i.clear())}}}function ie(t,e,r){const n=l.rawWindow.history.state,o={__MICRO_APP_STATE__:Z({},n==null?void 0:n.__MICRO_APP_STATE__,{[t]:{fullPath:r?r.pathname+r.search+r.hash:null,state:e!=null?e:null,mode:Me(t)}})};return Z({},n,o)}function Go(t,e){return U(e==null?void 0:e.__MICRO_APP_STATE__)&&(pe(e.__MICRO_APP_STATE__[t])||delete e.__MICRO_APP_STATE__[t],Object.keys(e.__MICRO_APP_STATE__).length||delete e.__MICRO_APP_STATE__),Kn(e)?null:Z({},e)}function Ke(t){var e,r;const n=l.rawWindow.history.state;return((r=(e=n==null?void 0:n.__MICRO_APP_STATE__)===null||e===void 0?void 0:e[t])===null||r===void 0?void 0:r.state)||null}function xr(t){var e;const r=l.rawWindow.history.state;return((e=r==null?void 0:r.__MICRO_APP_STATE__)===null||e===void 0?void 0:e[t])||null}const Ko=/&/g,qo=/=/g,Nr=/%M1/g,Br=/%M2/g;function Ur(t){return encodeURIComponent(xt(t).replace(Ko,"%M1").replace(qo,"%M2"))}function Wr(t){return xt(t).replace(Nr,"&").replace(Br,"=")}function xt(t){try{const e=decodeURIComponent(t);return t===e||Nr.test(e)||Br.test(e)?e:xt(e)}catch{return t}}function qe(t){var e,r,n,o;const i=l.rawWindow.location,s=l.rawWindow.history.state;if(V(t)){const a=Nt(i.search,i.hash),c=((e=a.hashQuery)===null||e===void 0?void 0:e[t])||((r=a.searchQuery)===null||r===void 0?void 0:r[t]);return B(c)?Wr(c):null}return((o=(n=s==null?void 0:s.__MICRO_APP_STATE__)===null||n===void 0?void 0:n[t])===null||o===void 0?void 0:o.fullPath)||(ne(t)?i.pathname+i.search+i.hash:null)}function fe(t,e){const r=l.rawWindow.location;let n=e.pathname+e.search+e.hash,o=!1;if(V(t)){let{pathname:i,search:s,hash:a}=r;const c=Nt(s,a),h=Ur(n);return a&&!s?(o=!0,c.hashQuery?c.hashQuery[t]=h:c.hashQuery={[t]:h},a=(a.includes("?")?a.slice(0,a.indexOf("?")+1):a+"?")+Je(c.hashQuery)):(c.searchQuery?c.searchQuery[t]=h:c.searchQuery={[t]:h},s="?"+Je(c.searchQuery)),{fullPath:i+s+a,isAttach2Hash:o}}return(Bt(t)||re(t))&&(n=r.pathname+r.search+r.hash),{fullPath:n,isAttach2Hash:o}}function Qo(t){var e,r,n,o;let{pathname:i,search:s,hash:a}=l.rawWindow.location,c=!1;if(V(t)){const h=Nt(s,a);if(!((e=h.hashQuery)===null||e===void 0)&&e[t]){c=!0,(r=h.hashQuery)===null||r===void 0||delete r[t];const d=Je(h.hashQuery);a=a.slice(0,a.indexOf("?")+Number(Boolean(d)))+d}else if(!((n=h.searchQuery)===null||n===void 0)&&n[t]){(o=h.searchQuery)===null||o===void 0||delete o[t];const d=Je(h.searchQuery);s=d?"?"+d:""}}return{fullPath:i+s+a,isAttach2Hash:c}}function Nt(t,e){const r={};return t!==""&&t!=="?"&&(r.searchQuery=Ft(t.slice(1))),e.includes("?")&&(r.hashQuery=Ft(e.slice(e.indexOf("?")+1))),r}function Vo(t,e){const r=qe(t);if(!r)return"";const n=W(r,e);return n.origin+n.pathname+n.search}function je(t){const e=y.get(t);return!!(e&&!e.isPrefetch)}function Me(t){var e;return(e=y.get(t))===null||e===void 0?void 0:e.routerMode}function V(t){return Me(t)===Fe}function Bt(t){return Me(t)===fr}function At(t){return Me(t)===Ze}function Xo(t){return Me(t)===pr}function re(t){return Me(t)===mr}function ne(t){return At(t)||Xo(t)}function Fr(t,e){const r=e&&Ze||t||v.options["disable-memory-router"]&&Ze||v.options["router-mode"]||Fe;return to.includes(r)?r:Fe}function Hr(t){const e=l.rawWindow,r=n=>{var o,i,s;if(Se({excludeHiddenApp:!0,excludePreRender:!0}).includes(t)&&!n.onlyForBrowser&&(!ne(t)||!l.rawWindow.history.state||xr(t))){const a=(o=y.get(t))===null||o===void 0?void 0:o.container;Bn(()=>et(t,qe(t)),(s=(i=a&&le(a))===null||i===void 0?void 0:i.getRouterEventDelay())!==null&&s!==void 0?s:0)}};return e.addEventListener("popstate",r),()=>{e.removeEventListener("popstate",r)}}function et(t,e){const r=y.get(t);if(r!=null&&r.sandBox){const n=r.sandBox.proxyWindow,o=r.sandBox.microAppWindow;let i=!1;const s=n.location.href;if(e){const a=n.location.hash;Oe(t,e,o.location),i=n.location.hash!==a}zo(t,n,o),i&&Yo(t,n,o,s),G()}}function zo(t,e,r){const n=new PopStateEvent("popstate",{state:Ke(t)});r.dispatchEvent(n),Ee(t)||R(e.onpopstate)&&e.onpopstate(n)}function Yo(t,e,r,n){const o=new HashChangeEvent("hashchange",{newURL:e.location.href,oldURL:n});r.dispatchEvent(o),Ee(t)||R(e.onhashchange)&&e.onhashchange(o)}function Jo(t){const e=new PopStateEvent("popstate",{state:null});t&&(e.onlyForBrowser=!0),l.rawWindow.dispatchEvent(e)}function Zo(t){const e=new HashChangeEvent("hashchange",{newURL:l.rawWindow.location.href,oldURL:t});l.rawWindow.dispatchEvent(e)}function bt(t,e,r){G(),je(t)&&(Jo(e),r&&Zo(r))}function jr(t,e){const r=l.rawWindow.history;function n(i){return function(...s){var a,c,h;s[2]=pe(s[2])||xe(s[2])||""+s[2]==""?e.href:""+s[2];const d=W(s[2],e.href),w=d.pathname+d.search+d.hash;re(t)||ut(t,i,fe(t,d),!0,ie(t,s[0],d),s[1]),w!==e.fullPath&&Oe(t,w,e),(h=(a=y.get(t))===null||a===void 0?void 0:(c=a.sandBox).updateIframeBase)===null||h===void 0||h.call(c)}}const o={pushState:n("pushState"),replaceState:n("replaceState")};return Ee(t)?Z({go(i){return r.go(i)}},o):new Proxy(r,{get(i,s){return s==="pushState"||s==="replaceState"?o[s]:s==="state"?Ke(t):J(Reflect.get(i,s),i,"HISTORY")},set(i,s,a){return s==="pushState"||s==="replaceState"?o[s]=a:Reflect.set(i,s,a),!0}})}function Re(t,e,r,n=null,o=""){je(t)&&(e==="pushState"?l.rawPushState:l.rawReplaceState).call(l.rawWindow.history,n,o,r)}function ut(t,e,r,n,o,i){if(je(t)){const s=l.rawWindow.location,a=s.pathname+s.search+s.hash,c=r.isAttach2Hash&&a!==r.fullPath?s.href:null;Re(t,e,r.fullPath,o,i),a!==r.fullPath&&V(t)&&bt(t,n,c)}}function ht(t,e,r){ut(t,"replaceState",e,!0,r)}function zt(t){const e=l.rawWindow;return function(...r){var n;if(((n=e.history.state)===null||n===void 0?void 0:n.__MICRO_APP_STATE__)&&(!U(r[0])||!r[0].__MICRO_APP_STATE__)&&(B(r[2])||ot(r[2]))){const o=e.location.href;W(r[2],o).href===o&&(r[0]=Z({},r[0],{__MICRO_APP_STATE__:e.history.state.__MICRO_APP_STATE__}))}t.apply(e.history,r),Se({excludeHiddenApp:!0,excludePreRender:!0}).forEach(o=>{if((V(o)||Bt(o))&&!qe(o)){const i=y.get(o);ht(o,fe(o,i.sandBox.proxyWindow.location),ie(o,Ke(o),i.sandBox.proxyWindow.location))}ne(o)&&!xr(o)&&Re(o,"replaceState",e.location.href,ie(o))}),G()}}function $r(){const t=l.rawWindow;t.history.pushState=zt(l.rawPushState),t.history.replaceState=zt(l.rawReplaceState)}function Gr(){const t=l.rawWindow;t.history.pushState=l.rawPushState,t.history.replaceState=l.rawReplaceState}function ko(){function t(E,M,b,_){ut(E,M,fe(E,b),!1,ie(E,_!=null?_:null,b)),G()}function e(E,M,b,_){const u=M.sandBox.proxyWindow.location,f=W(b.path,u.href),g=u.pathname+u.search+u.hash,p=f.pathname+f.search+f.hash;if(g!==p||qe(E)!==p){if(!re(E)){const m=_&&b.replace!==!1||b.replace===!0?"replaceState":"pushState";t(E,m,f,b.state)}V(E)||et(E,p)}}function r(E){return function(M){return new Promise((b,_)=>{const u=$(M.name);if(u&&B(M.path))if(Se({excludeHiddenApp:!0,excludePreRender:!0}).includes(u)){const f=y.get(u);b(f.sandBox.sandboxReady.then(()=>e(u,f,M,E)))}else _(I("\u5BFC\u822A\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u5B50\u5E94\u7528\u6E32\u67D3\u540E\u518D\u8C03\u7528\u6B64\u65B9\u6CD5"));else _(I(`navigation failed, name & path are required when use router.${E?"replace":"push"}`))})}}function n(E){return function(...M){return l.rawWindow.history[E](...M)}}const o=Ht(),i=Ht();function s(E,M,b,_){G();for(const u of _)R(u)?u(M,b,E):U(u)&&R(u[E])&&u[E](M,b)}function a(E,M,b){D.current.set(E,M),s(E,M,b,o.list()),at(()=>{s(E,M,b,i.list())})}function c(E){D.current.delete(E)}function h(E){if(V(E)||Bt(E)){const M=y.get(E);ht(E,fe(E,M.sandBox.proxyWindow.location),ie(E,Ke(E),M.sandBox.proxyWindow.location))}}function d(E){E=$(E),E&&Se().includes(E)&&h(E)}function w({includeHiddenApp:E=!1,includePreRender:M=!1}){Se({excludeHiddenApp:!E,excludePreRender:!M}).forEach(b=>h(b))}function A(){const E=jn();function M(_){const u=$(_.name);return!u||!_.path?En:E.add(u,_.path)}function b(_){return _=$(_),_?E.delete(_):!1}return{setDefaultPage:M,removeDefaultPage:b,getDefaultPage:E.get}}function O(){let E=null;function M(b){An(b)&&(E=new Proxy(b,{get(_,u){return G(),J(Reflect.get(_,u),_,"BASEROUTER")},set(_,u,f){return Reflect.set(_,u,f),!0}}))}return{setBaseAppRouter:M,getBaseAppRouter:()=>E}}const D=Object.assign(Object.assign({current:new Map,encode:Ur,decode:Wr,push:r(!1),replace:r(!0),go:n("go"),back:n("back"),forward:n("forward"),beforeEach:o.add,afterEach:i.add,attachToURL:d,attachAllToURL:w},A()),O());return{router:D,executeNavigationGuard:a,clearRouterWhenUnmount:c}}const{router:Qe,executeNavigationGuard:Kr,clearRouterWhenUnmount:ei}=ko(),ti=["href","pathname","search","hash","host","hostname","port","protocol","search"],ri=[...ti,"origin","fullPath"];function qr(t,e,r,n,o,i){const a=l.rawWindow.location,c=!!r,h=W(e);function d(){return c?r.location:h}function w(_,u){const f=W(_,b.href);if(f.origin===b.origin){const g=fe(t,f);if(!ne(t)){if(u=re(t)?"replaceState":u,f.pathname===b.pathname&&f.search===b.search){let p=null;(f.hash!==b.hash||re(t))&&(g.isAttach2Hash&&(p=a.href),(!re(t)||!f.hash)&&Re(t,u,g.fullPath,V(t)?null:ie(t,null,f))),f.hash?V(t)?bt(t,!1,p):et(t,f.pathname+f.search+f.hash):M();return}Re(t,u,g.fullPath,V(t)?null:ie(t,null,f)),M();return}return g.fullPath}return _}function A(_,u){const f=W(_,e);f[u]===b[u]&&b.hash?bt(t,!1):(Re(t,f[u]===b[u]||re(t)?"replaceState":"pushState",fe(t,f).fullPath,V(t)?null:ie(t,null,f)),M())}const O=_=>function(u){if(je(t)){const f=w(u,_==="assign"?"pushState":"replaceState");f&&a[_](W(f,a.origin).href)}},D=O("assign"),E=O("replace"),M=_=>a.reload(_);H(d(),"fullPath",{enumerable:!0,configurable:!0,get:()=>b.pathname+b.search+b.hash});const b=new Proxy({},{get:(_,u)=>{const f=d();if(u==="assign")return D;if(u==="replace")return E;if(u==="reload")return M;if(u==="self")return f;if(u==="fullPath")return f.fullPath;if(lo.includes(u)){if(At(t))return a[u];if(c)return n[u]}if(u==="href"){if(At(t))return f[u].replace(f.origin,a.origin);if(c)return f[u].replace(o,i)}return J(Reflect.get(f,u),f,"LOCATION")},set:(_,u,f)=>{if(je(t)){const g=d();if(u==="href"){const p=w(f,"pushState");p&&(a.href=W(p,a.origin).href)}else if(u==="pathname")if(ne(t))a.pathname=f;else{const p=("/"+f).replace(/^\/+/,"/")+b.search+b.hash;A(p,"pathname")}else if(u==="search")if(ne(t))a.search=f;else{const p=b.pathname+("?"+f).replace(/^\?+/,"?")+b.hash;A(p,"search")}else if(u==="hash")if(ne(t))a.hash=f;else{const p=b.pathname+b.search+("#"+f).replace(/^#+/,"#"),m=W(p,e);m.hash!==b.hash&&(re(t)||ut(t,"pushState",fe(t,m),!1,ie(t,null,m)),V(t)||et(t,m.pathname+m.search+m.hash))}else Reflect.set(g,u,f)}return!0}});return b}function tt(t,e){const r=Z({name:t},e);for(const n of ri)r[n]=e[n];return r}function ni(t,e){Kr(t,tt(t,e),tt(t,e))}function Oe(t,e,r,n){var o;const i=tt(t,r),s=W(e,r.href);if(Ee(t)){const h=y.get(t).sandBox.microAppWindow;(o=h.rawReplaceState)===null||o===void 0||o.call(h.history,Ke(t),"",s.href)}else{let h=s.href;r.self.origin!==s.origin&&(h=h.replace(s.origin,r.self.origin)),r.self.href=h}const a=l.rawWindow.location;ne(t)&&e!==a.pathname+a.search+a.hash&&n!=="prevent"&&Re(t,"replaceState",e,l.rawWindow.history.state);const c=tt(t,r);(n==="auto"||i.fullPath!==c.fullPath&&n!=="prevent")&&Kr(t,c,i)}function oi(t,e){const r=qr(t,e);return{microLocation:r,microHistory:jr(t,r)}}function Qr(t,e,r){const n=qe(t);n?(Oe(t,n,e,"auto"),re(t)&&dt(t)):Ut(t,e,r)}function Ut(t,e,r){r&&Oe(t,r,e,"prevent"),re(t)||ht(t,fe(t,e),ie(t,null,e)),ni(t,e)}function Vr(t,e,r,n){if(!n&&!ne(t)){const{pathname:o,search:i,hash:s}=W(e);Oe(t,o+i+s,r,"prevent")}re(t)||dt(t),ei(t)}function dt(t){ht(t,Qo(t),Go(t,l.rawWindow.history.state))}function Yt(t,e){const r=pe(e)?l.rawWindow.fetch:e;return R(r)?function(o,i,...s){return(B(o)||ot(o))&&(o=W(o,t).toString()),G(),r.call(l.rawWindow,o,i,...s)}:r}function Jt(t,e){const r=pe(e)?l.rawWindow.XMLHttpRequest:e;return nt(r)?class extends r{open(o,i,...s){(B(i)&&!/^f(ile|tp):\/\//.test(i)||ot(i))&&(i=W(i,t).toString()),G(),super.open(o,i,...s)}}:r}function ii(){let t;function e(n,o,i){const s=pe(i)?l.rawWindow.EventSource:i;return nt(s)?class extends s{constructor(c,h,...d){if((B(c)||ot(c))&&(c=W(c,o).toString()),G(),super(c,h,...d),t){const w=t.get(n);w?w.add(this):t.set(n,new Set([this]))}else t=new Map([[n,new Set([this])]])}close(){var c;super.close(),(c=t.get(n))===null||c===void 0||c.delete(this)}}:s}function r(n){const o=t==null?void 0:t.get(n);o!=null&&o.size&&(o.forEach(i=>{i.close()}),o.clear())}return{createMicroEventSource:e,clearMicroEventSource:r}}const{createMicroEventSource:Zt,clearMicroEventSource:si}=ii();class $e extends To{constructor(e,r){super(e,r),this.active=!1,this.microAppWindow=new xo,this.patchWith(n=>{this.getSpecialProperties(e),this.patchRouter(e,r,this.microAppWindow),this.windowEffect=Fo(e,this.microAppWindow,this),this.documentEffect=Bo(e,this.microAppWindow,this),this.setMappingPropertiesWithRawDescriptor(this.microAppWindow),this.initStaticGlobalKeys(e,r,this.microAppWindow),n()})}start({umdMode:e,baseroute:r,defaultPage:n,disablePatchRequest:o}){this.active||(this.active=!0,this.initRouteState(n),this.removeHistoryListener=Hr(this.microAppWindow.__MICRO_APP_NAME__),ne(this.microAppWindow.__MICRO_APP_NAME__)&&(this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=r),e||this.initGlobalKeysWhenStart(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.__MICRO_APP_URL__,this.microAppWindow,o),++l.activeSandbox===1&&(kr(),$r()),++$e.activeCount===1&&Co(),No())}stop({umdMode:e,keepRouteState:r,destroy:n,clearData:o}){var i;!this.active||(this.recordAndReleaseEffect({umdMode:e,clearData:o,destroy:n},!e||n),this.clearRouteState(r),(i=this.removeHistoryListener)===null||i===void 0||i.call(this),(!e||n)&&(si(this.microAppWindow.__MICRO_APP_NAME__),this.injectedKeys.forEach(s=>{Reflect.deleteProperty(this.microAppWindow,s)}),this.injectedKeys.clear(),this.escapeKeys.forEach(s=>{Reflect.deleteProperty(l.rawWindow,s)}),this.escapeKeys.clear(),this.clearHijackUmdHooks()),--l.activeSandbox===0&&(en(),Gr()),--$e.activeCount,this.active=!1)}initStaticGlobalKeys(e,r,n){n.__MICRO_APP_ENVIRONMENT__=!0,n.__MICRO_APP_NAME__=e,n.__MICRO_APP_URL__=r,n.__MICRO_APP_PUBLIC_PATH__=it(r),n.__MICRO_APP_BASE_ROUTE__="",n.__MICRO_APP_WINDOW__=n,n.__MICRO_APP_PRE_RENDER__=!1,n.__MICRO_APP_UMD_MODE__=!1,n.__MICRO_APP_PROXY_WINDOW__=this.proxyWindow,n.__MICRO_APP_SANDBOX__=this,n.__MICRO_APP_SANDBOX_TYPE__="with",n.rawWindow=l.rawWindow,n.rawDocument=l.rawDocument,n.microApp=Z(new Or(e),{removeDomScope:G,pureCreateElement:z,location:n.location,router:Qe})}recordAndReleaseEffect(e,r=!1){r?this.resetEffectSnapshot():this.recordEffectSnapshot(),this.releaseGlobalEffect(e)}resetEffectSnapshot(){this.windowEffect.reset(),this.documentEffect.reset(),Lt(this.microAppWindow.microApp)}recordEffectSnapshot(){this.windowEffect.record(),this.documentEffect.record(),Dr(this.microAppWindow.microApp)}rebuildEffectSnapshot(){this.windowEffect.rebuild(),this.documentEffect.rebuild(),Cr(this.microAppWindow.microApp)}releaseGlobalEffect({umdMode:e=!1,clearData:r=!1,isPrerender:n=!1,keepAlive:o=!1,destroy:i=!1}){var s,a,c;this.windowEffect.release(!e&&!o&&!n||i),this.documentEffect.release(),(s=this.microAppWindow.microApp)===null||s===void 0||s.clearDataListener(),(a=this.microAppWindow.microApp)===null||a===void 0||a.clearGlobalDataListener(),r&&(v.clearData(this.microAppWindow.__MICRO_APP_NAME__),(c=this.microAppWindow.microApp)===null||c===void 0||c.clearData())}getSpecialProperties(e){var r;U(v.options.plugins)&&(this.commonActionForSpecialProperties(v.options.plugins.global),this.commonActionForSpecialProperties((r=v.options.plugins.modules)===null||r===void 0?void 0:r[e]))}commonActionForSpecialProperties(e){if(se(e))for(const r of e)U(r)&&(se(r.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(r.scopeProperties)),se(r.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(r.escapeProperties)))}setPreRenderState(e){this.microAppWindow.__MICRO_APP_PRE_RENDER__=e}markUmdMode(e){this.microAppWindow.__MICRO_APP_UMD_MODE__=e}patchWith(e){this.sandboxReady=new Promise(r=>e(r))}setMappingPropertiesWithRawDescriptor(e){let r,n;const o=l.rawWindow;o===o.parent?r=n=this.proxyWindow:(r=o.top,n=o.parent),k(e,{top:this.createDescriptorForMicroAppWindow("top",r),parent:this.createDescriptorForMicroAppWindow("parent",n)}),vr.forEach(i=>{H(e,i,this.createDescriptorForMicroAppWindow(i,this.proxyWindow))})}createDescriptorForMicroAppWindow(e,r){const{configurable:n=!0,enumerable:o=!0,writable:i,set:s}=Object.getOwnPropertyDescriptor(l.rawWindow,e)||{writable:!0};return{value:r,configurable:n,enumerable:o,writable:i!=null?i:!!s}}initGlobalKeysWhenStart(e,r,n,o){n.hasOwnProperty=i=>ge.call(n,i)||ge.call(l.rawWindow,i),this.setHijackProperty(e,n),o||this.patchRequestApi(e,r,n),this.setScopeProperties(n)}setHijackProperty(e,r){let n,o;k(r,{eval:{configurable:!0,enumerable:!1,get(){return Ne(e),n||l.rawWindow.eval},set:i=>{n=i}},Image:{configurable:!0,enumerable:!1,get(){return Ne(e),o||l.ImageProxy},set:i=>{o=i}}})}patchRequestApi(e,r,n){let o=Yt(r),i=Jt(r),s=Zt(e,r);k(n,{fetch:{configurable:!0,enumerable:!0,get(){return o},set(a){o=Yt(r,a)}},XMLHttpRequest:{configurable:!0,enumerable:!0,get(){return i},set(a){i=Jt(r,a)}},EventSource:{configurable:!0,enumerable:!0,get(){return s},set(a){s=Zt(e,r,a)}}})}setScopeProperties(e){this.scopeProperties.forEach(r=>{Reflect.set(e,r,e[r])})}patchRouter(e,r,n){const{microLocation:o,microHistory:i}=oi(e,r);k(n,{location:{configurable:!1,enumerable:!0,get(){return o},set:s=>{l.rawWindow.location=s}},history:{configurable:!0,enumerable:!0,get(){return i}}})}initRouteState(e){Qr(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.location,e)}clearRouteState(e){Vr(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.__MICRO_APP_URL__,this.microAppWindow.location,e)}setRouteInfoForKeepAliveApp(){Ut(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.location)}removeRouteInfoForKeepAliveApp(){dt(this.microAppWindow.__MICRO_APP_NAME__)}patchStaticElement(e){Tt(e,this.microAppWindow.__MICRO_APP_NAME__)}actionsBeforeExecScripts(e,r){this.patchStaticElement(e),this.clearHijackUmdHooks=this.hijackUmdHooks(this.appName,this.microAppWindow,r)}hijackUmdHooks(e,r,n){let o,i,s;return k(r,{mount:{configurable:!0,get:()=>o,set:a=>{this.active&&R(a)&&!o&&n(o=a,i)}},unmount:{configurable:!0,get:()=>i,set:a=>{this.active&&R(a)&&!i&&n(o,i=a)}},[`micro-app-${e}`]:{configurable:!0,get:()=>s,set:a=>{this.active&&U(a)&&!s&&(s=a,n(s.mount,s.unmount))}}}),()=>{o=i=s=null}}setStaticAppState(e){this.microAppWindow.__MICRO_APP_STATE__=e}}$e.activeCount=0;function ai(t,e,r,n){const o=l.rawWindow.history,i=W(e),s=i.protocol+"//"+i.host,a=i.pathname+i.search+i.hash,c=r.history;return r.rawReplaceState=c.replaceState,Z(c,jr(t,r.location)),k(c,{scrollRestoration:{configurable:!0,enumerable:!0,get(){return o.scrollRestoration},set(h){o.scrollRestoration=h}}}),Oe(t,a,r.location,"prevent"),qr(t,e,r,i,n,s)}const ci=["Array"],li=["getComputedStyle","DOMParser","visualViewport","matchMedia","ResizeObserver","IntersectionObserver"],ui=[/animationFrame$/i,/mutationObserver$/i,/height$|width$/i,/offset$/i,/selection$/i,/^range/i,/^screen/i,/^scroll/i,/X$|Y$/],hi=["body","head","html","title"],di=["childElementCount","children","firstElementChild","firstChild","lastElementChild","activeElement","fullscreenElement","pictureInPictureElement","pointerLockElement","styleSheets"],fi=["append","contains","replaceChildren","createRange","getSelection","elementFromPoint","elementsFromPoint","getAnimations"],pi=["characterSet","compatMode","contentType","designMode","dir","doctype","embeds","fullscreenEnabled","hidden","implementation","lastModified","pictureInPictureEnabled","plugins","readyState","referrer","visibilityState","fonts"],mi=["execCommand","createRange","exitFullscreen","exitPictureInPicture","getElementsByTagNameNS","hasFocus","prepend"],_i=["blob:"],gi=window.Worker;function vi(t){try{const e=t instanceof URL?t:new URL(t);return _i.includes(e.protocol)?!0:e.protocol===window.location.protocol&&e.hostname===window.location.hostname&&e.port===window.location.port}catch{return!1}}function Ei(t){let e;try{e=new Blob([t],{type:"application/javascript"})}catch{const o=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,i=new o;i.append(t),e=i.getBlob("application/javascript")}return(window.URL||window.webkitURL).createObjectURL(e)}const kt=new Proxy(gi,{construct(t,e){let[r,n]=e;n=n||{};const o=Q();let i=r;if(o){const s=y.get(o);i=X(r,s.url)}if(i&&!vi(i)){const s=`import "${r}";`,a=Ei(s);return n.type="module",new t(a,n)}else return new t(r,n)}});function wi(t,e,r){return Ai(t,e,r),bi(e,r),Pi(e)}function Ai(t,e,r){const n=l.rawWindow;li.forEach(o=>{e[o]=J(n[o],n)}),Object.getOwnPropertyNames(e).filter(o=>(ui.some(i=>{if(i.test(o)&&o in e.parent){if(R(n[o]))e[o]=J(n[o],n);else{const{configurable:s,enumerable:a}=Object.getOwnPropertyDescriptor(e,o)||{configurable:!0,enumerable:!0};s&&H(e,o,{configurable:s,enumerable:a,get:()=>n[o],set:c=>{n[o]=c}})}return!0}return!1}),nt(e[o])&&o in n&&!ci.includes(o)&&H(e[o],Symbol.hasInstance,{configurable:!0,enumerable:!1,value(i){return $t(i,n[o])||$t(i,e[o])}}),/^on/.test(o)&&!io.includes(o))).forEach(o=>{const{enumerable:i,writable:s,set:a}=Object.getOwnPropertyDescriptor(e,o)||{enumerable:!0,writable:!0};try{H(e,o,{enumerable:i,configurable:!0,get:()=>n[o],set:(s!=null?s:!!a)?c=>{n[o]=R(c)?c.bind(e):c}:void 0})}catch(c){me(c,t)}}),r.escapeProperties.forEach(o=>{let i=e[o];H(e,o,{enumerable:!0,configurable:!0,get(){return i!=null?i:J(n[o],n)},set(s){i=s}})})}function bi(t,e){const r=l.rawWindow,n=new Set;Object.defineProperty(t,"Worker",{value:kt,configurable:!0,writable:!0});const o=new Proxy(t,{get:(i,s)=>s==="Worker"?kt:s==="location"?e.proxyLocation:te(vr,s)?o:n.has(s)?Reflect.get(i,s):te(e.escapeProperties,s)&&!Reflect.get(i,s)?J(Reflect.get(r,s),r):J(Reflect.get(i,s),i),set:(i,s,a)=>s==="location"?Reflect.set(r,s,a):(Reflect.has(i,s)||n.add(s),Reflect.set(i,s,a),!0),has:(i,s)=>s in i,deleteProperty:(i,s)=>Reflect.has(i,s)?Reflect.deleteProperty(i,s):!0});e.proxyWindow=o}function Pi(t){const{rawWindow:e,rawAddEventListener:r,rawRemoveEventListener:n,rawDispatchEvent:o}=l,i=new Map,s=new Map;function a(A){return no.includes(A)?t:e}t.addEventListener=function(A,O,D){const E=i.get(A);E?E.add(O):i.set(A,new Set([O])),O&&(O.__MICRO_APP_MARK_OPTIONS__=D),r.call(a(A),A,O,D)},t.removeEventListener=function(A,O,D){const E=i.get(A);(E==null?void 0:E.size)&&E.has(O)&&E.delete(O),n.call(a(A),A,O,D)},t.dispatchEvent=function(A){return o.call(a(A==null?void 0:A.type),A)};const c=()=>{s.clear()};return{reset:c,record:()=>{i.forEach((A,O)=>{if(A.size){const D=s.get(O)||[];s.set(O,new Set([...D,...A]))}})},rebuild:()=>{s.forEach((A,O)=>{for(const D of A)t.addEventListener(O,D,D==null?void 0:D.__MICRO_APP_MARK_OPTIONS__)}),c()},release:()=>{i.size&&(i.forEach((A,O)=>{for(const D of A)n.call(a(O),O,D)}),i.clear())}}}function Ri(t,e,r){return Si(t,e),yi(t,e,r),Mi(t,e)}function Si(t,e){const r=l.rawDocument,n=e.Document,o=e.document,i=n.prototype.createElement,s=n.prototype.createElementNS,a=n.prototype.createTextNode,c=n.prototype.createDocumentFragment,h=n.prototype.createComment,d=n.prototype.querySelector,w=n.prototype.querySelectorAll,A=n.prototype.getElementById,O=n.prototype.getElementsByClassName,D=n.prototype.getElementsByTagName,E=n.prototype.getElementsByName,M=n.prototype.elementFromPoint,b=n.prototype.caretRangeFromPoint;n.prototype.caretRangeFromPoint=function(p,m){const P=M.call(r,p,m),T=b.call(r,p,m);return F(P,t),T},n.prototype.createElement=function(p,m){let P=i.call(this,p,m);return xn(P)&&(P=i.call(r,p,m)),F(P,t)},n.prototype.createElementNS=function(p,m,P){const T=s.call(this,p,m,P);return F(T,t)},n.prototype.createTextNode=function(p){const m=a.call(this,p);return F(m,t)},n.prototype.createDocumentFragment=function(){const p=c.call(this);return F(p,t)},n.prototype.createComment=function(p){const m=h.call(this,p);return F(m,t)};function _(g){return yt(t),o===g?r:g}function u(g){var p,m;const P=_(this);if(g==="body"&&((p=v==null?void 0:v.options)===null||p===void 0?void 0:p.inheritBaseBody)!==!0)return this.body;if(!g||Pe(g)||r!==P)return d.call(P,g);const T=(m=y.get(t))===null||m===void 0?void 0:m.querySelector(g);return T||g==="base"?T:d.call(o,g)}function f(g){var p,m;const P=_(this);if(!g||Pe(g)||r!==P)return w.call(P,g);const T=(m=(p=y.get(t))===null||p===void 0?void 0:p.querySelectorAll(g))!==null&&m!==void 0?m:[];return T.length||g==="base"?T:w.call(o,g)}n.prototype.querySelector=u,n.prototype.querySelectorAll=f,n.prototype.getElementById=function(p){const m=_(this);if(he(p))return A.call(m,p);try{return u.call(this,`#${p}`)}catch{return A.call(m,p)}},n.prototype.getElementsByClassName=function(p){const m=_(this);if(he(p))return O.call(m,p);try{return f.call(this,`.${p}`)}catch{return O.call(m,p)}},n.prototype.getElementsByTagName=function(p){const m=_(this);if(Pe(p)||he(p))return D.call(m,p);if(/^script$/i.test(p))return D.call(o,p);try{return f.call(this,p)}catch{return D.call(m,p)}},n.prototype.getElementsByName=function(p){const m=_(this);if(he(p))return E.call(m,p);try{return f.call(this,`[name=${p}]`)}catch{return E.call(m,p)}}}function yi(t,e,r){const n=l.rawDocument,o=e.Document,i=e.document,s=(c,h)=>{const{enumerable:d}=Object.getOwnPropertyDescriptor(o.prototype,c)||{enumerable:!0};return{configurable:!0,enumerable:d,get:h}},a=()=>{const c={};return[["documentURI",()=>r.proxyLocation.href],["URL",()=>r.proxyLocation.href],["documentElement",()=>n.documentElement],["scrollingElement",()=>n.scrollingElement],["forms",()=>o.prototype.querySelectorAll.call(i,"form")],["images",()=>o.prototype.querySelectorAll.call(i,"img")],["links",()=>o.prototype.querySelectorAll.call(i,"a")],["microAppElement",()=>{var d;return(d=y.get(t))===null||d===void 0?void 0:d.container}],["__MICRO_APP_NAME__",()=>t]].forEach(d=>{c[d[0]]=s(d[0],d[1])}),di.forEach(d=>{c[d]=s(d,()=>n[d])}),fi.forEach(d=>{c[d]=s(d,()=>J(n[d],n,"DOCUMENT"))}),pi.forEach(d=>{c[d]=s(d,()=>n[d])}),mi.forEach(d=>{c[d]=s(d,()=>J(n[d],n,"DOCUMENT"))}),c};k(o.prototype,a()),hi.forEach(c=>{H(i,c,{enumerable:!0,configurable:!0,get:()=>{var h,d;return yt(t),c==="body"&&((h=v==null?void 0:v.options)===null||h===void 0?void 0:h.inheritBaseBody)!==!0&&((d=r.options.container)===null||d===void 0?void 0:d.querySelector("micro-app-body"))||n[c]},set:h=>{n[c]=h}})})}function Mi(t,e){const{rawDocument:r,rawAddEventListener:n,rawRemoveEventListener:o,rawDispatchEvent:i}=l,s=new Map,a=new Map;let c=null,h=null;const d=e.Document,w=e.document;function A(_,u){return so.includes(_)?u:r}d.prototype.addEventListener=function(_,u,f){const g=R(u)?u.__MICRO_APP_BOUND_FUNCTION__=u.__MICRO_APP_BOUND_FUNCTION__||u.bind(this):u,p=s.get(_);p?p.add(u):s.set(_,new Set([u])),u&&(u.__MICRO_APP_MARK_OPTIONS__=f),n.call(A(_,this),_,g,f)},d.prototype.removeEventListener=function(_,u,f){const g=s.get(_);(g==null?void 0:g.size)&&g.has(u)&&g.delete(u);const p=(u==null?void 0:u.__MICRO_APP_BOUND_FUNCTION__)||u;o.call(A(_,this),_,p,f)},d.prototype.dispatchEvent=function(_){return i.call(A(_==null?void 0:_.type,this),_)};function O(_){return _==="onclick"?u=>{R(c)&&o.call(r,"click",c,!1),R(u)?(c=u.bind(w),n.call(r,"click",c,!1)):c=u}:u=>{r[_]=R(u)?u.bind(w):u}}Object.getOwnPropertyNames(d.prototype).filter(_=>/^on/.test(_)&&!ao.includes(_)).forEach(_=>{const{enumerable:u,writable:f,set:g}=Object.getOwnPropertyDescriptor(d.prototype,_)||{enumerable:!0,writable:!0};try{H(d.prototype,_,{enumerable:u,configurable:!0,get:()=>_==="onclick"?c:r[_],set:(f!=null?f:!!g)?O(_):void 0})}catch(p){me(p,t)}});const D=()=>{a.clear(),h=null};return{reset:D,record:()=>{h=c||h,s.forEach((_,u)=>{if(_.size){const f=a.get(u)||[];a.set(u,new Set([...f,..._]))}})},rebuild:()=>{h&&!c&&(w.onclick=h),a.forEach((_,u)=>{for(const f of _)w.addEventListener(u,f,f==null?void 0:f.__MICRO_APP_MARK_OPTIONS__)}),D()},release:()=>{R(c)&&o.call(r,"click",c),c=null,s.size&&(s.forEach((_,u)=>{for(const f of _)o.call(A(u,w),u,(f==null?void 0:f.__MICRO_APP_BOUND_FUNCTION__)||f)}),s.clear())}}}function Oi(t,e,r,n){Di(t,r,n),Ci(e,r,t)}function Di(t,e,r){const n=l.rawRootElement,o=l.rawRootNode,i=l.rawDocument,s=e.document,a=e.Node,c=e.Element,h=e.DocumentFragment,d=a.prototype.appendChild,w=a.prototype.insertBefore,A=a.prototype.replaceChild,O=a.prototype.removeChild,D=c.prototype.append,E=c.prototype.prepend,M=h.prototype.append,b=h.prototype.prepend,_=c.prototype.insertAdjacentElement,u=a.prototype.cloneNode,f=Object.getOwnPropertyDescriptor(c.prototype,"innerHTML"),g=Object.getOwnPropertyDescriptor(a.prototype,"parentNode"),p=Object.getOwnPropertyDescriptor(a.prototype,"ownerDocument"),m=L=>(be(L)||In(L))&&L.__PURE_ELEMENT__,P=L=>L===r.microHead?i.head:L===r.microBody?i.body:L;a.prototype.appendChild=function(S){return F(S,t),m(S)?d.call(this,S):o.prototype.appendChild.call(P(this),S)},a.prototype.insertBefore=function(S,C){return F(S,t),m(S)?w.call(this,S,C):o.prototype.insertBefore.call(P(this),S,C)},a.prototype.replaceChild=function(S,C){return F(S,t),m(S)?A.call(this,S,C):o.prototype.replaceChild.call(P(this),S,C)},a.prototype.removeChild=function(S){return m(S)||this.contains(S)?O.call(this,S):o.prototype.removeChild.call(P(this),S)},h.prototype.append=c.prototype.append=function(...S){let C=0,_e=!1;for(;C<S.length;)S[C]=ye(S[C])?S[C]:s.createTextNode(S[C]),m(S[C])&&(_e=!0),C++;return _e?(ze(this)?M:D).call(this,...S):n.prototype.append.call(P(this),...S)},h.prototype.prepend=c.prototype.prepend=function(...S){let C=0,_e=!1;for(;C<S.length;)S[C]=ye(S[C])?S[C]:s.createTextNode(S[C]),m(S[C])&&(_e=!0),C++;return _e?(ze(this)?b:E).call(this,...S):n.prototype.prepend.call(P(this),...S)},c.prototype.insertAdjacentElement=function(S,C){return F(C,t),m(C)?_.call(this,S,C):n.prototype.insertAdjacentElement.call(P(this),S,C)},H(a.prototype,"baseURI",{configurable:!0,enumerable:!0,get(){return r.proxyWindow.location.href}}),H(a.prototype,"ownerDocument",{configurable:!0,enumerable:!0,get(){var L;return this.__PURE_ELEMENT__||this===s?(L=p.get)===null||L===void 0?void 0:L.call(this):s}}),H(a.prototype,"parentNode",Tr(t,g)),a.prototype.getRootNode=function(){return s},a.prototype.cloneNode=function(S){const C=u.call(this,S);return F(C,t)},H(c.prototype,"innerHTML",{configurable:!0,enumerable:!0,get(){var L;return(L=f.get)===null||L===void 0?void 0:L.call(this)},set(L){var S;(S=f.set)===null||S===void 0||S.call(this,L),Array.from(this.children).forEach(C=>{ce(C)&&F(C,t)})}});const T=new Proxy(e.Image,{construct(L,S){const C=new L(...S);return F(C,t),C}});H(e,"Image",{configurable:!0,writable:!0,value:T})}function Ci(t,e,r){const n=e.Element,o=n.prototype.setAttribute;n.prototype.setAttribute=function(a,c){var h;if(/^micro-app(-\S+)?/i.test(this.tagName)&&a==="data"&&this.setAttribute!==n.prototype.setAttribute)this.setAttribute(a,c);else{const d=(h=v==null?void 0:v.options)===null||h===void 0?void 0:h.aHrefResolver;if(a==="href"&&/^a$/i.test(this.tagName)&&typeof d=="function")c=d(c,r,t);else if((a==="src"||a==="srcset")&&/^(img|script|video|audio|source|embed)$/i.test(this.tagName)||a==="href"&&/^(link|image)$/i.test(this.tagName)||a==="href"&&/^(a)$/i.test(this.tagName)&&!/^#/.test(c)){let w=t;rt&&a==="href"&&/^a$/i.test(this.tagName)&&R(v.options.excludeAssetFilter)&&v.options.excludeAssetFilter(c)&&(w=document.baseURI),c=X(c,w)}o.call(this,a,c)}},[[e.HTMLImageElement.prototype,"src"],[e.HTMLScriptElement.prototype,"src"],[e.HTMLLinkElement.prototype,"href"],[e.SVGImageElement.prototype,"href"]].forEach(([s,a])=>{const{enumerable:c,configurable:h,get:d,set:w}=Object.getOwnPropertyDescriptor(s,a)||{enumerable:!0,configurable:!0};H(s,a,{enumerable:c,configurable:h,get:function(){return d==null?void 0:d.call(this)},set:function(A){w==null||w.call(this,X(A,t))}})})}class Ge{constructor(e,r,n){this.active=!1,this.escapeProperties=[],this.updateIframeBase=()=>{var s;(s=this.baseElement)===null||s===void 0||s.setAttribute("href",W(this.url).origin+this.proxyLocation.pathname)},this.appName=e,this.url=r,this.options=n;const o=l.rawWindow.location,i=o.protocol+"//"+o.host;this.deleteIframeElement=this.createIframeElement(e,i+o.pathname,n),this.microAppWindow=this.iframe.contentWindow,this.patchIframe(this.microAppWindow,s=>{this.microAppWindow=this.iframe.contentWindow,this.createIframeTemplate(this.microAppWindow),this.getSpecialProperties(e),this.proxyLocation=ai(e,r,this.microAppWindow,i),this.windowEffect=wi(e,this.microAppWindow,this),this.documentEffect=Ri(e,this.microAppWindow,this),Oi(e,r,this.microAppWindow,this),this.initStaticGlobalKeys(e,r,this.microAppWindow),s()})}createIframeElement(e,r,n){this.iframe=z("iframe");const o=Object.assign(Object.assign({},n==null?void 0:n.attrs),{id:e,src:v.options.iframeSrc||r,style:"display: none","powered-by":"micro-app"});return Object.keys(o).forEach(i=>this.iframe.setAttribute(i,o[i])),l.rawDocument.body.appendChild(this.iframe),()=>ee(()=>{var i,s;(s=(i=this.iframe)===null||i===void 0?void 0:i.parentNode)===null||s===void 0||s.removeChild(this.iframe),this.iframe=null})}start({baseroute:e,defaultPage:r,disablePatchRequest:n}){this.active||(this.active=!0,this.initRouteState(r),this.removeHistoryListener=Hr(this.microAppWindow.__MICRO_APP_NAME__),ne(this.microAppWindow.__MICRO_APP_NAME__)&&(this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e),n||this.createIframeBase(),++l.activeSandbox===1&&(kr(),$r()),++Ge.activeCount)}stop({umdMode:e,keepRouteState:r,destroy:n,clearData:o}){var i;!this.active||(this.recordAndReleaseEffect({clearData:o},!e||n),this.clearRouteState(r),(i=this.removeHistoryListener)===null||i===void 0||i.call(this),(!e||n)&&(this.deleteIframeElement(),this.clearHijackUmdHooks()),--l.activeSandbox===0&&(en(),Gr()),--Ge.activeCount,this.active=!1)}initStaticGlobalKeys(e,r,n){n.__MICRO_APP_ENVIRONMENT__=!0,n.__MICRO_APP_NAME__=e,n.__MICRO_APP_URL__=r,n.__MICRO_APP_PUBLIC_PATH__=it(r),n.__MICRO_APP_BASE_ROUTE__="",n.__MICRO_APP_WINDOW__=n,n.__MICRO_APP_PRE_RENDER__=!1,n.__MICRO_APP_UMD_MODE__=!1,n.__MICRO_APP_PROXY_WINDOW__=this.proxyWindow,n.__MICRO_APP_SANDBOX__=this,n.__MICRO_APP_SANDBOX_TYPE__="iframe",n.rawWindow=l.rawWindow,n.rawDocument=l.rawDocument,n.microApp=Z(new Or(e),{removeDomScope:G,pureCreateElement:z,location:this.proxyLocation,router:Qe})}recordAndReleaseEffect(e,r=!1){r?this.resetEffectSnapshot():this.recordEffectSnapshot(),this.releaseGlobalEffect(e)}resetEffectSnapshot(){var e,r;(e=this.windowEffect)===null||e===void 0||e.reset(),(r=this.documentEffect)===null||r===void 0||r.reset(),Lt(this.microAppWindow.microApp)}recordEffectSnapshot(){var e,r;(e=this.windowEffect)===null||e===void 0||e.record(),(r=this.documentEffect)===null||r===void 0||r.record(),Dr(this.microAppWindow.microApp)}rebuildEffectSnapshot(){var e,r;(e=this.windowEffect)===null||e===void 0||e.rebuild(),(r=this.documentEffect)===null||r===void 0||r.rebuild(),Cr(this.microAppWindow.microApp)}releaseGlobalEffect({clearData:e=!1}){var r,n,o,i,s;(r=this.windowEffect)===null||r===void 0||r.release(),(n=this.documentEffect)===null||n===void 0||n.release(),(o=this.microAppWindow.microApp)===null||o===void 0||o.clearDataListener(),(i=this.microAppWindow.microApp)===null||i===void 0||i.clearGlobalDataListener(),e&&(v.clearData(this.microAppWindow.__MICRO_APP_NAME__),(s=this.microAppWindow.microApp)===null||s===void 0||s.clearData())}setPreRenderState(e){this.microAppWindow.__MICRO_APP_PRE_RENDER__=e}markUmdMode(e){this.microAppWindow.__MICRO_APP_UMD_MODE__=e}patchIframe(e,r){const n=e.document;this.sandboxReady=new Promise(o=>{(function i(){setTimeout(()=>{try{e.document===n?i():(e.stop(),r(o))}catch{i()}},0)})()})}createIframeTemplate(e){const r=e.document;$n(r);const n=r.createElement("html");n.innerHTML="<head></head><body></body>",r.appendChild(n),this.microBody=r.body,this.microHead=r.head}createIframeBase(){this.baseElement=z("base"),this.updateIframeBase(),this.microHead.appendChild(this.baseElement)}getSpecialProperties(e){var r;U(v.options.plugins)&&(this.commonActionForSpecialProperties(v.options.plugins.global),this.commonActionForSpecialProperties((r=v.options.plugins.modules)===null||r===void 0?void 0:r[e]))}commonActionForSpecialProperties(e){if(se(e))for(const r of e)U(r)&&se(r.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(r.escapeProperties))}initRouteState(e){Qr(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.location,e)}clearRouteState(e){Vr(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.__MICRO_APP_URL__,this.microAppWindow.location,e)}setRouteInfoForKeepAliveApp(){Ut(this.microAppWindow.__MICRO_APP_NAME__,this.microAppWindow.location)}removeRouteInfoForKeepAliveApp(){dt(this.microAppWindow.__MICRO_APP_NAME__)}patchStaticElement(e){Tt(e,this.microAppWindow.__MICRO_APP_NAME__)}actionsBeforeExecScripts(e,r){this.patchStaticElement(e),this.clearHijackUmdHooks=this.hijackUmdHooks(this.appName,this.microAppWindow,r)}hijackUmdHooks(e,r,n){let o,i,s;return k(r,{mount:{configurable:!0,get:()=>o,set:a=>{this.active&&R(a)&&!o&&n(o=a,i)}},unmount:{configurable:!0,get:()=>i,set:a=>{this.active&&R(a)&&!i&&n(o,i=a)}},[`micro-app-${e}`]:{configurable:!0,get:()=>s,set:a=>{this.active&&U(a)&&!s&&(s=a,n(s.mount,s.unmount))}}}),()=>{o=i=s=null}}setStaticAppState(e){this.microAppWindow.__MICRO_APP_STATE__=e}}Ge.activeCount=0;const y=new Map;class Xr{constructor({name:e,url:r,container:n,scopecss:o,useSandbox:i,inline:s,iframe:a,ssrUrl:c,isPrefetch:h,prefetchLevel:d,routerMode:w,attrs:A}){this.state=j.CREATED,this.keepAliveState=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.umdMode=!1,this.sandBox=null,this.fiber=!1,this.isReloading=!1,y.set(e,this),this.name=e,this.url=r,this.useSandbox=i,this.scopecss=this.useSandbox&&o,this.attrs=A,this.iframe=a!=null?a:!1,this.inline=this.getInlineModeState(s),this.isReloading=!1,this.routerMode=w||Fe,this.container=n!=null?n:null,this.ssrUrl=c!=null?c:"",this.isPrefetch=h!=null?h:!1,this.isPrerender=d===3,this.prefetchLevel=d,this.source={html:null,links:new Set,scripts:new Set},this.loadSourceCode(),this.createSandbox()}loadSourceCode(){this.setAppState(j.LOADING),Ot.getInstance().run(this,Mo)}onLoad({html:e,defaultPage:r,routerMode:n,baseroute:o,disablePatchRequest:i}){var s;if(++this.loadSourceLevel===2){if(this.source.html=e,this.isUnmounted())return;if(!this.isPrefetch)le(this.container).mount(this);else if(this.isPrerender){const a=z("div");a.setAttribute("prerender","true"),(s=this.sandBox)===null||s===void 0||s.setPreRenderState(!0),this.mount({container:a,inline:this.inline,fiber:!0,defaultPage:r||"",disablePatchRequest:i!=null?i:!1,routerMode:n,baseroute:o||""})}}}onLoadError(e){this.loadSourceLevel=-1,this.isUnmounted()||(this.onerror(e),this.setAppState(j.LOAD_FAILED))}mount({container:e,inline:r,routerMode:n,defaultPage:o,baseroute:i,disablePatchRequest:s,fiber:a}){if(this.loadSourceLevel!==2)return this.container=e,this.isPrerender=!1,oe(this,"statechange",{appState:j.LOADING}),this.setAppState(j.LOADING);this.createSandbox();const c=()=>{var h,d,w,A,O,D,E;if(this.setAppState(j.BEFORE_MOUNT),this.isPrerender&&Dn(this.container)&&this.container.hasAttribute("prerender"))this.container=this.cloneContainer(e,this.container,!1),(h=this.sandBox)===null||h===void 0||h.rebuildEffectSnapshot(),(d=this.preRenderEvents)===null||d===void 0||d.forEach(M=>M()),this.isPrerender=!1,this.preRenderEvents=null,Qe.attachToURL(this.name),(w=this.sandBox)===null||w===void 0||w.setPreRenderState(!1);else{this.container=e,this.inline=this.getInlineModeState(r),this.fiber=a,this.routerMode=n;const M=()=>{ue(this.container,this.name,N.BEFOREMOUNT)};if(this.isPrerender?((A=this.preRenderEvents)!==null&&A!==void 0?A:this.preRenderEvents=[]).push(M):M(),this.setAppState(j.MOUNTING),oe(this,"statechange",{appState:j.MOUNTING}),this.cloneContainer(this.container,this.source.html,!this.umdMode),(O=this.sandBox)===null||O===void 0||O.start({umdMode:this.umdMode,baseroute:i,defaultPage:o,disablePatchRequest:s}),!this.umdMode)(D=this.sandBox)===null||D===void 0||D.actionsBeforeExecScripts(this.container,(b,_)=>{var u;if(!this.umdMode&&!this.isUnmounted()&&(this.umdHookMount=R(b)?b:null,this.umdHookUnmount=R(_)?_:null,R(this.umdHookMount)&&R(this.umdHookUnmount))){(u=this.sandBox)===null||u===void 0||u.markUmdMode(this.umdMode=!0);try{this.getAppState()===j.MOUNTED?this.umdHookMount(v.getData(this.name,!0)):this.handleMounted(this.umdHookMount(v.getData(this.name,!0)))}catch(f){I(`An error occurred when mount
|
|
`,this.name,f)}}}),vo(this,b=>{!this.umdMode&&b===!0&&this.handleMounted()});else{(E=this.sandBox)===null||E===void 0||E.rebuildEffectSnapshot();try{this.handleMounted(this.umdHookMount(v.getData(this.name,!0)))}catch(b){I(`An error occurred when mount
|
|
`,this.name,b)}}}};this.sandBox?this.sandBox.sandboxReady.then(()=>!this.isUnmounted()&&c()):c()}handleMounted(e){var r,n;const o=()=>{const i=()=>this.actionsAfterMounted();mt(e)?e.then(i).catch(s=>{I(`An error occurred in window.mount
|
|
`,this.name,s),i()}):i()};this.isPrerender?((r=this.preRenderEvents)===null||r===void 0||r.push(o),(n=this.sandBox)===null||n===void 0||n.recordAndReleaseEffect({isPrerender:!0})):o()}actionsAfterMounted(){var e;this.isUnmounted()||(this.setAppState(j.MOUNTED),jt(this.getMicroAppGlobalHook(we.ONMOUNT),this.name,we.ONMOUNT,v.getData(this.name,!0)),oe(this,"statechange",{appState:j.MOUNTED}),oe(this,"mounted"),ue(this.container,this.name,N.MOUNTED),this.isHidden()&&((e=this.sandBox)===null||e===void 0||e.recordAndReleaseEffect({keepAlive:!0})))}unmount({destroy:e,clearData:r,keepRouteState:n,unmountcb:o}){var i;e=e||this.state===j.LOAD_FAILED,this.setAppState(j.UNMOUNT);try{this.handleUnmounted(e,r,n,o,(i=this.umdHookUnmount)===null||i===void 0?void 0:i.call(this,v.getData(this.name,!0)))}catch(s){I(`An error occurred when unmount
|
|
`,this.name,s)}}handleUnmounted(e,r,n,o,i){oe(this,"statechange",{appState:j.UNMOUNT}),oe(this,"unmount"),jt(this.getMicroAppGlobalHook(we.ONUNMOUNT),this.name,we.ONUNMOUNT);const s=()=>this.actionsAfterUnmounted({destroy:e,clearData:r,keepRouteState:n,unmountcb:o});mt(i)?(G(),i.then(s).catch(a=>{I(`An error occurred in window.unmount
|
|
`,this.name,a),s()})):s()}actionsAfterUnmounted({destroy:e,clearData:r,keepRouteState:n,unmountcb:o}){var i;this.umdMode&&this.container&&!e&&this.cloneContainer(this.source.html,this.container,!1);const s=this.isReloading?!1:r||e;(i=this.sandBox)===null||i===void 0||i.stop({umdMode:this.umdMode,keepRouteState:n&&!e,destroy:e,clearData:s}),ue(this.container,this.name,N.UNMOUNT),this.clearOptions(e),o==null||o()}clearOptions(e){var r,n;this.isPrerender=!1,this.preRenderEvents=null,this.setKeepAliveState(null),this.container?(this.container.innerHTML="",this.container=null):this.umdMode||(n=(r=this.sandBox)===null||r===void 0?void 0:r.deleteIframeElement)===null||n===void 0||n.call(r),this.iframe&&!this.umdMode&&(this.sandBox=null),e&&this.actionsForCompletelyDestroy(),G()}actionsForCompletelyDestroy(){var e,r;(r=(e=this.sandBox)===null||e===void 0?void 0:e.deleteIframeElement)===null||r===void 0||r.call(e),Y.script.deleteInlineInfo(this.source.scripts),y.delete(this.name)}hiddenKeepAliveApp(e){var r,n;this.setKeepAliveState(Te.KEEP_ALIVE_HIDDEN),oe(this,"appstate-change",{appState:"afterhidden"}),ue(this.container,this.name,N.AFTERHIDDEN),V(this.name)&&((r=this.sandBox)===null||r===void 0||r.removeRouteInfoForKeepAliveApp()),this.loadSourceLevel!==2?le(this.container).unmount():(this.container=this.cloneContainer(z("div"),this.container,!1),(n=this.sandBox)===null||n===void 0||n.recordAndReleaseEffect({keepAlive:!0})),e==null||e()}showKeepAliveApp(e){var r,n;const o=this.container;this.container=e,(r=this.sandBox)===null||r===void 0||r.rebuildEffectSnapshot(),oe(this,"appstate-change",{appState:"beforeshow"}),ue(e,this.name,N.BEFORESHOW),this.setKeepAliveState(Te.KEEP_ALIVE_SHOW),this.cloneContainer(this.container,o,!1),V(this.name)&&((n=this.sandBox)===null||n===void 0||n.setRouteInfoForKeepAliveApp()),oe(this,"appstate-change",{appState:"aftershow"}),ue(this.container,this.name,N.AFTERSHOW)}onerror(e){oe(this,"statechange",{appState:j.LOAD_FAILED}),ue(this.container,this.name,N.ERROR,e)}parseHtmlString(e){var r;const n=!((r=this.sandBox)===null||r===void 0)&&r.proxyWindow?this.sandBox.proxyWindow.DOMParser:l.rawWindow.DOMParser;return new n().parseFromString(e,"text/html").body}cloneContainer(e,r,n){return r&&e&&(e.innerHTML="",Array.from(n?this.parseHtmlString(r.innerHTML).childNodes:r.childNodes).forEach(o=>{e.appendChild(o)})),e}createSandbox(){if(this.useSandbox&&!this.sandBox){const e={attrs:this.attrs,container:this.container};this.sandBox=this.iframe?new Ge(this.name,this.url,e):new $e(this.name,this.url)}}setAppState(e){var r;this.state=e,(r=this.sandBox)===null||r===void 0||r.setStaticAppState(e)}getAppState(){return this.state}setKeepAliveState(e){this.keepAliveState=e}getKeepAliveState(){return this.keepAliveState}isUnmounted(){return j.UNMOUNT===this.state}isHidden(){return Te.KEEP_ALIVE_HIDDEN===this.keepAliveState}getMicroAppGlobalHook(e){var r,n;const o=(n=(r=this.sandBox)===null||r===void 0?void 0:r.proxyWindow)===null||n===void 0?void 0:n[e];return R(o)?o:null}querySelector(e){return this.container?l.rawElementQuerySelector.call(this.container,e):null}querySelectorAll(e){return this.container?l.rawElementQuerySelectorAll.call(this.container,e):[]}getInlineModeState(e){var r;return(r=this.iframe||e)!==null&&r!==void 0?r:!1}}function Ee(t){var e,r;return(r=(e=y.get(t))===null||e===void 0?void 0:e.iframe)!==null&&r!==void 0?r:!1}const ae=new WeakMap;function zr(t){var e;return(e=ae.get(t))!==null&&e!==void 0?e:t}function Yr(t,e){if(ae.has(t))return ae.get(t);if(ir(t)){if(t.hasAttribute("exclude")){const r=document.createComment("style element with exclude attribute ignored by micro-app");return ae.set(t,r),r}else if(e.scopecss&&!t.hasAttribute("ignore"))return ct(t,e);return t}else if(Mn(t)){if(t.hasAttribute("exclude")||Ct(t.getAttribute("href"),e.name)){const i=document.createComment("link element with exclude attribute ignored by micro-app");return ae.set(t,i),i}else if(t.hasAttribute("ignore")||It(t.getAttribute("href"),e.name)||t.href&&R(v.options.excludeAssetFilter)&&v.options.excludeAssetFilter(t.href))return t;const{address:r,linkInfo:n,replaceComment:o}=hr(t,null,e,!0);if(r&&n){const i=eo(r,e,n,t);return ae.set(t,i),i}else if(o)return ae.set(t,o),o;return t}else if(be(t)){if(t.src&&R(v.options.excludeAssetFilter)&&v.options.excludeAssetFilter(t.src))return t;const{replaceComment:r,address:n,scriptInfo:o}=Rr(t,null,e,!0)||{};if(n&&o){const i=o.isExternal?Eo(n,e,o,t):wo(n,e,o);return ae.set(t,i),i}else if(r)return ae.set(t,r),r;return t}return t}function Jr(t,e,r,n,o){const i=Zr(r,n,t);if(i){if(!Ee(t.name)&&Ye(i)&&e!==l.rawRemoveChild){const s=Object.getOwnPropertyDescriptor(n,"parentNode");(!s||s.configurable)&&!n.__MICRO_APP_HAS_DPN__&&k(n,{parentNode:{configurable:!0,get(){var a,c;const h=l.rawParentNodeDesc.get.call(this);return Ye(h)&&t.container?((c=(a=v.options).getRootElementParentNode)===null||c===void 0?void 0:c.call(a,this,t.name))||document.body:h}},__MICRO_APP_HAS_DPN__:{configurable:!0,get:()=>!0}})}if(o&&!i.contains(o)){if(e===l.rawInsertBefore&&r.contains(o)){const s=Array.from(r.childNodes).indexOf(o);if(i.childNodes[s])return Xe(e,i,n,i.childNodes[s],t)}return l.rawAppendChild.call(i,n)}else if(e===l.rawRemoveChild&&!i.contains(n))return r.contains(n)?e.call(n.parentElement,n):n;return Xe(e,i,n,o,t)}return Xe(e,r,n,o,t)}function Zr(t,e,r){if(r){if(t===document.head)return r.iframe&&be(e)?r.sandBox.microHead:r.querySelector("micro-app-head");if(t===document.body||t===document.body.parentNode)return r.iframe&&be(e)?r.sandBox.microBody:r.querySelector("micro-app-body");if(r.iframe&&be(e))return r.sandBox.microBody}return null}function Xe(t,e,r,n,o){return Ii(t)?((o==null?void 0:o.iframe)&&be(r)&&(t===l.rawFragmentAppend?t=l.rawAppend:t===l.rawFragmentPrepend&&(t=l.rawPrepend)),t.call(e,r)):t.call(e,r,n)}function Ii(t){return t===l.rawAppend||t===l.rawPrepend||t===l.rawFragmentAppend||t===l.rawFragmentPrepend}function Li(t,e){var r;if(ce(e)){if(/^(img|script)$/i.test(e.tagName))e.hasAttribute("src")&&l.rawSetAttribute.call(e,"src",X(e.getAttribute("src"),t.url)),e.hasAttribute("srcset")&&l.rawSetAttribute.call(e,"srcset",X(e.getAttribute("srcset"),t.url));else if(/^(link|image)$/i.test(e.tagName)&&e.hasAttribute("href")||/^(a)$/i.test(e.tagName)&&e.hasAttribute("href")&&!/^#/.test(e.getAttribute("href")||"")){const n=(r=v==null?void 0:v.options)===null||r===void 0?void 0:r.aHrefResolver,o=e.getAttribute("href");let i;/^(a)$/i.test(e.tagName)&&typeof n=="function"?i=n(o,t.name,t.url):i=X(o,t.url),l.rawSetAttribute.call(e,"href",i)}}}function De(t,e,r,n){const o=Q();if(ye(e)&&!e.__PURE_ELEMENT__&&(e.__MICRO_APP_NAME__||o)){F(e,e.__MICRO_APP_NAME__||o);const i=y.get(e.__MICRO_APP_NAME__);if(i!=null&&i.container)return ir(e)&&t.getRootNode()instanceof ShadowRoot&&e.setAttribute("ignore","true"),Li(i,e),Jr(i,n,t,Yr(e,i),r&&zr(r))}return Xe(n,t,e,r)}function kr(){Ti();const t=l.rawRootElement,e=l.rawRootNode,r=l.rawDocumentFragment;e.prototype.appendChild=function(s){return De(this,s,null,l.rawAppendChild)},e.prototype.insertBefore=function(s,a){return De(this,s,a,l.rawInsertBefore)},e.prototype.replaceChild=function(s,a){return De(this,s,a,l.rawReplaceChild)},e.prototype.removeChild=function(s){if(s!=null&&s.__MICRO_APP_NAME__){const a=y.get(s.__MICRO_APP_NAME__);if(a!=null&&a.container)return Jr(a,l.rawRemoveChild,this,zr(s));try{return l.rawRemoveChild.call(this,s)}catch{return(s==null?void 0:s.parentNode)&&l.rawRemoveChild.call(s.parentNode,s)}}return l.rawRemoveChild.call(this,s)},r.prototype.append=t.prototype.append=function(...s){let a=0;for(;a<s.length;){let c=s[a];c=ye(c)?c:l.rawCreateTextNode.call(l.rawDocument,c),De(this,Ae(c),null,ze(this)?l.rawFragmentAppend:l.rawAppend),a++}},r.prototype.prepend=t.prototype.prepend=function(...s){let a=s.length,c=l.rawPrepend;for((ze(this)||Ln(this))&&(c=l.rawFragmentPrepend);a>0;){let h=s[a-1];h=ye(h)?h:l.rawCreateTextNode.call(l.rawDocument,h),De(this,Ae(h),null,c),a--}},t.prototype.insertAdjacentElement=function(i,s){var a;if((s==null?void 0:s.__MICRO_APP_NAME__)&&ce(s)){const c=y.get(s.__MICRO_APP_NAME__);if(c!=null&&c.container){const h=Yr(s,c);if(!ce(h))return s;const d=(a=Zr(this,h,c))!==null&&a!==void 0?a:this;return l.rawInsertAdjacentElement.call(d,i,h)}}return l.rawInsertAdjacentElement.call(this,i,s)};function n(i){const s=Ve()||Q();if((i===document.body||i===document.head)&&s){const a=y.get(s);if(a!=null&&a.container){if(i===document.body)return a.querySelector("micro-app-body");if(i===document.head)return a.querySelector("micro-app-head")}}return i}function o(i,s,a,c,h){if(i){const d=Ve()||Q();if(d&&Ee(d)){const w=y.get(d);if(Tn(s))return w.sandBox.microHead[h](c);if(Ye(s))return w.sandBox.microBody[h](c)}}return a}t.prototype.querySelector=function(s){var a;const c=(a=n(this))!==null&&a!==void 0?a:this,h=l.rawElementQuerySelector.call(c,s);return o(xe(h)&&c!==this,c,h,s,"querySelector")},t.prototype.querySelectorAll=function(s){var a;const c=(a=n(this))!==null&&a!==void 0?a:this,h=l.rawElementQuerySelectorAll.call(c,s);return o(!h.length&&c!==this,c,h,s,"querySelectorAll")},t.prototype.setAttribute=function(s,a){var c,h;if(/^micro-app(-\S+)?/i.test(this.tagName)&&s==="data"&&this.setAttribute!==t.prototype.setAttribute)this.setAttribute(s,a);else{const d=this.__MICRO_APP_NAME__||Q();if(d&&y.has(d)&&((s==="src"||s==="srcset")&&/^(img|script|video|audio|source|embed)$/i.test(this.tagName)||s==="href"&&/^(link|image)$/i.test(this.tagName)||s==="href"&&/^(a)$/i.test(this.tagName)&&!/^#/.test(a))){const w=y.get(d),A=(c=v==null?void 0:v.options)===null||c===void 0?void 0:c.aHrefResolver;s==="href"&&/^a$/i.test(this.tagName)&&typeof A=="function"?a=A(a,d,w.url):a=X(a,w.url)}if(l.rawSetAttribute.call(this,s,a),Cn(this)||yn(this)||Sn(this)){let w=!1;((h=v==null?void 0:v.options)===null||h===void 0?void 0:h.includeCrossOrigin)&&R(v.options.includeCrossOrigin)&&(w=v.options.includeCrossOrigin(a)),w&&(node.crossOrigin="anonymous")}}},H(e.prototype,"parentNode",{configurable:!0,enumerable:!0,get(){var i,s,a;const c=Ve()||Q();if(c&&this===l.rawDocument.firstElementChild){const d=(a=(s=(i=y.get(c))===null||i===void 0?void 0:i.sandBox)===null||s===void 0?void 0:s.proxyWindow)===null||a===void 0?void 0:a.document;if(d)return d}return l.rawParentNodeDesc.get.call(this)}}),H(t.prototype,"innerHTML",{configurable:!0,enumerable:!0,get(){return l.rawInnerHTMLDesc.get.call(this)},set(i){l.rawInnerHTMLDesc.set.call(this,i);const s=this.__MICRO_APP_NAME__||Ve()||Q();Array.from(this.children).forEach(a=>{ce(a)&&s&&F(a,s)})}}),e.prototype.cloneNode=function(s){const a=l.rawCloneNode.call(this,s);return F(a,this.__MICRO_APP_NAME__)}}function Ae(t){return F(t,Q())}function Ti(){const t=l.rawDocument,e=l.rawRootDocument;function r(i){return Nn(i)?t:i}e.prototype.createElement=function(s,a){const c=l.rawCreateElement.call(r(this),s,a);return Ae(c)},e.prototype.createElementNS=function(s,a,c){const h=l.rawCreateElementNS.call(r(this),s,a,c);return Ae(h)},e.prototype.createDocumentFragment=function(){const s=l.rawCreateDocumentFragment.call(r(this));return Ae(s)},e.prototype.createComment=function(s){const a=l.rawCreateComment.call(r(this),s);return Ae(a)};function n(i){var s,a;const c=r(this),h=Q();return!h||!i||Pe(i)||t!==c?l.rawQuerySelector.call(c,i):(a=(s=y.get(h))===null||s===void 0?void 0:s.querySelector(i))!==null&&a!==void 0?a:null}function o(i){var s,a;const c=r(this),h=Q();return!h||!i||Pe(i)||t!==c?l.rawQuerySelectorAll.call(c,i):(a=(s=y.get(h))===null||s===void 0?void 0:s.querySelectorAll(i))!==null&&a!==void 0?a:[]}e.prototype.querySelector=n,e.prototype.querySelectorAll=o,e.prototype.getElementById=function(s){const a=r(this);if(!Q()||he(s))return l.rawGetElementById.call(a,s);try{return n.call(a,`#${s}`)}catch{return l.rawGetElementById.call(a,s)}},e.prototype.getElementsByClassName=function(s){const a=r(this);if(!Q()||he(s))return l.rawGetElementsByClassName.call(a,s);try{return o.call(a,`.${s}`)}catch{return l.rawGetElementsByClassName.call(a,s)}},e.prototype.getElementsByTagName=function(s){var a;const c=r(this),h=Q();if(!h||Pe(s)||he(s)||!(!((a=y.get(h))===null||a===void 0)&&a.inline)&&/^script$/i.test(s))return l.rawGetElementsByTagName.call(c,s);try{return o.call(c,s)}catch{return l.rawGetElementsByTagName.call(c,s)}},e.prototype.getElementsByName=function(s){const a=r(this);if(!Q()||he(s))return l.rawGetElementsByName.call(a,s);try{return o.call(a,`[name=${s}]`)}catch{return l.rawGetElementsByName.call(a,s)}}}function xi(){const t=l.rawRootDocument;t.prototype.createElement=l.rawCreateElement,t.prototype.createElementNS=l.rawCreateElementNS,t.prototype.createDocumentFragment=l.rawCreateDocumentFragment,t.prototype.querySelector=l.rawQuerySelector,t.prototype.querySelectorAll=l.rawQuerySelectorAll,t.prototype.getElementById=l.rawGetElementById,t.prototype.getElementsByClassName=l.rawGetElementsByClassName,t.prototype.getElementsByTagName=l.rawGetElementsByTagName,t.prototype.getElementsByName=l.rawGetElementsByName}function en(){G(),xi();const t=l.rawRootElement,e=l.rawRootNode;e.prototype.appendChild=l.rawAppendChild,e.prototype.insertBefore=l.rawInsertBefore,e.prototype.replaceChild=l.rawReplaceChild,e.prototype.removeChild=l.rawRemoveChild,e.prototype.cloneNode=l.rawCloneNode,t.prototype.append=l.rawAppend,t.prototype.prepend=l.rawPrepend,t.prototype.querySelector=l.rawElementQuerySelector,t.prototype.querySelectorAll=l.rawElementQuerySelectorAll,t.prototype.setAttribute=l.rawSetAttribute,H(e.prototype,"parentNode",l.rawParentNodeDesc),H(t.prototype,"innerHTML",l.rawInnerHTMLDesc)}let er=!1;function Ni(){if(!er){er=!0;const t=z("style");l.rawSetAttribute.call(t,"type","text/css"),t.textContent=`
|
|
${v.tagName}, micro-app-body { display: block; }
|
|
micro-app-head { display: none; }`,l.rawDocument.head.appendChild(t)}}const l={activeSandbox:0};function Bi(){if(rt){const t=window.rawWindow||Function("return window")(),e=window.rawDocument||Function("return document")(),r=t.Document||Function("return Document")(),n=t.Element,o=t.Node,i=t.EventTarget,s=t.DocumentFragment,a=o.prototype.appendChild,c=o.prototype.insertBefore,h=o.prototype.replaceChild,d=o.prototype.removeChild,w=n.prototype.setAttribute,A=n.prototype.append,O=n.prototype.prepend,D=s.prototype.append,E=s.prototype.prepend,M=o.prototype.cloneNode,b=n.prototype.querySelector,_=n.prototype.querySelectorAll,u=n.prototype.insertAdjacentElement,f=Object.getOwnPropertyDescriptor(n.prototype,"innerHTML"),g=Object.getOwnPropertyDescriptor(o.prototype,"parentNode"),p=r.prototype.createElement,m=r.prototype.createElementNS,P=r.prototype.createTextNode,T=r.prototype.createDocumentFragment,L=r.prototype.createComment,S=r.prototype.querySelector,C=r.prototype.querySelectorAll,_e=r.prototype.getElementById,rn=r.prototype.getElementsByClassName,nn=r.prototype.getElementsByTagName,on=r.prototype.getElementsByName,sn=new Proxy(t.Image,{construct(_n,gn){return F(new _n(...gn),Q())}}),an=t.setInterval,cn=t.setTimeout,ln=t.clearInterval,un=t.clearTimeout,hn=t.history.pushState,dn=t.history.replaceState,fn=i.prototype.addEventListener,pn=i.prototype.removeEventListener,mn=i.prototype.dispatchEvent;window.__MICRO_APP_BASE_APPLICATION__=!0,Z(l,{supportModuleScript:Wn(),rawWindow:t,rawDocument:e,rawRootDocument:r,rawRootElement:n,rawRootNode:o,rawDocumentFragment:s,rawSetAttribute:w,rawAppendChild:a,rawInsertBefore:c,rawReplaceChild:h,rawRemoveChild:d,rawAppend:A,rawPrepend:O,rawFragmentAppend:D,rawFragmentPrepend:E,rawCloneNode:M,rawElementQuerySelector:b,rawElementQuerySelectorAll:_,rawInsertAdjacentElement:u,rawInnerHTMLDesc:f,rawParentNodeDesc:g,rawCreateElement:p,rawCreateElementNS:m,rawCreateDocumentFragment:T,rawCreateTextNode:P,rawCreateComment:L,rawQuerySelector:S,rawQuerySelectorAll:C,rawGetElementById:_e,rawGetElementsByClassName:rn,rawGetElementsByTagName:nn,rawGetElementsByName:on,ImageProxy:sn,rawSetInterval:an,rawSetTimeout:cn,rawClearInterval:ln,rawClearTimeout:un,rawPushState:hn,rawReplaceState:dn,rawAddEventListener:fn,rawRemoveEventListener:pn,rawDispatchEvent:mn}),Ni()}}function Ui(t){class e extends HTMLElement{constructor(){super(...arguments),this.isWaiting=!1,this.cacheData=null,this.connectedCount=0,this.connectStateMap=new Map,this._appName="",this.appUrl="",this.ssrUrl="",this.version=vn,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const n=$(this.getAttribute("name")),o=_t(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",n)&&this.legalAttribute("url",o)){const i=y.get(n);if(n!==this.appName&&i&&!i.isUnmounted()&&!i.isHidden()&&!i.isPrefetch)return this.setAttribute("name",this.appName),I(`app name conflict, an app named ${n} is running`);(n!==this.appName||o!==this.appUrl)&&(n===this.appName?this.unmount(!0,()=>{this.actionsForAttributeChange(n,o,i)}):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(n,o,i)):this.unmount(!1,()=>{this.actionsForAttributeChange(n,o,i)}))}else n!==this.appName&&this.setAttribute("name",this.appName)}}static get observedAttributes(){return["name","url"]}connectedCallback(){Object.getPrototypeOf(this)!==e.prototype&&Object.setPrototypeOf(this,e.prototype);const n=++this.connectedCount;this.connectStateMap.set(n,!0);const o=this.appName&&this.appUrl;ee(()=>{this.connectStateMap.get(n)&&(ue(this,this.appName,N.CREATED),o&&this.handleConnected())})}disconnectedCallback(){this.connectStateMap.set(this.connectedCount,!1),this.handleDisconnected()}reload(n){return new Promise(o=>{const i=()=>{this.removeEventListener(N.MOUNTED,i),this.removeEventListener(N.AFTERSHOW,i),o(!0)};this.addEventListener(N.MOUNTED,i),this.addEventListener(N.AFTERSHOW,i),this.handleDisconnected(n,()=>{this.handleConnected()})})}handleDisconnected(n=!1,o){const i=y.get(this.appName);i&&!i.isUnmounted()&&!i.isHidden()&&(this.getKeepAliveModeResult()&&!n?this.handleHiddenKeepAliveApp(o):this.unmount(n,o))}attributeChangedCallback(n,o,i){if(this.legalAttribute(n,i)&&this[n===Le.NAME?"appName":"appUrl"]!==i)if(n===Le.URL&&(!this.appUrl||!this.connectStateMap.get(this.connectedCount))){if(i=_t(i,this.appName),!i)return I(`Invalid attribute url ${i}`,this.appName);this.appUrl=i,this.handleInitialNameAndUrl()}else if(n===Le.NAME&&(!this.appName||!this.connectStateMap.get(this.connectedCount))){const s=$(i);if(!s)return I(`Invalid attribute name ${i}`,this.appName);this.cacheData&&(v.setData(s,this.cacheData),this.cacheData=null),this.appName=s,s!==i&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else this.isWaiting||(this.isWaiting=!0,ee(this.handleAttributeUpdate))}handleInitialNameAndUrl(){this.connectStateMap.get(this.connectedCount)&&this.handleConnected()}handleConnected(){if(!(!this.appName||!this.appUrl))if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&R(this.attachShadow)&&this.attachShadow({mode:"open"}),this.updateSsrUrl(this.appUrl),y.has(this.appName)){const n=y.get(this.appName),o=n.ssrUrl||n.url,i=this.ssrUrl||this.appUrl;n.isHidden()&&n.url===this.appUrl?this.handleShowKeepAliveApp(n):o===i&&(n.isUnmounted()||n.isPrefetch&&this.sameCoreOptions(n))?this.handleMount(n):n.isPrefetch||n.isUnmounted()?this.handleCreateApp():I(`app name conflict, an app named ${this.appName} with url ${o} is running`)}else this.handleCreateApp()}actionsForAttributeChange(n,o,i){var s;this.updateSsrUrl(o),this.appName=n,this.appUrl=o,((s=this.shadowRoot)!==null&&s!==void 0?s:this).innerHTML="",n!==this.getAttribute("name")&&this.setAttribute("name",this.appName),i?i.isHidden()?i.url===this.appUrl?this.handleShowKeepAliveApp(i):I(`app name conflict, an app named ${this.appName} is running`):i.url===this.appUrl&&i.ssrUrl===this.ssrUrl?this.handleMount(i):this.handleCreateApp():this.handleCreateApp()}legalAttribute(n,o){return!B(o)||!o?(I(`unexpected attribute ${n}, please check again`,this.appName),!1):!0}handleCreateApp(){const n={};Array.prototype.slice.call(this.attributes).forEach(({name:s,value:a})=>{s.startsWith("data-")&&(n[s]=a)});const o=()=>{var s;return new Xr({name:this.appName,url:this.appUrl,container:(s=this.shadowRoot)!==null&&s!==void 0?s:this,scopecss:this.useScopecss(),useSandbox:this.useSandbox(),inline:this.getDisposeResult("inline"),iframe:this.getDisposeResult("iframe"),ssrUrl:this.ssrUrl,routerMode:this.getMemoryRouterMode(),attrs:n})},i=y.get(this.appName);i?i.isPrerender?this.unmount(!0,o):(i.actionsForCompletelyDestroy(),o()):o()}handleMount(n){n.isPrefetch=!1,n.setAppState(j.BEFORE_MOUNT),ee(()=>this.mount(n))}mount(n){var o;n.mount({container:(o=this.shadowRoot)!==null&&o!==void 0?o:this,inline:this.getDisposeResult("inline"),routerMode:this.getMemoryRouterMode(),baseroute:this.getBaseRouteCompatible(),defaultPage:this.getDefaultPage(),disablePatchRequest:this.getDisposeResult("disable-patch-request"),fiber:this.getDisposeResult("fiber")})}unmount(n,o){const i=y.get(this.appName);i&&!i.isUnmounted()&&i.unmount({destroy:n||this.getDestroyCompatibleResult(),clearData:this.getDisposeResult("clear-data"),keepRouteState:this.getDisposeResult("keep-router-state"),unmountcb:o}),delete this.__MICRO_APP_NAME__}handleHiddenKeepAliveApp(n){const o=y.get(this.appName);o&&!o.isUnmounted()&&!o.isHidden()&&o.hiddenKeepAliveApp(n)}handleShowKeepAliveApp(n){ee(()=>{var o;return n.showKeepAliveApp((o=this.shadowRoot)!==null&&o!==void 0?o:this)})}getDisposeResult(n){return(this.compatibleProperties(n)||!!v.options[n])&&this.compatibleDisableProperties(n)}compatibleProperties(n){return n==="disable-scopecss"?this.hasAttribute("disable-scopecss")||this.hasAttribute("disableScopecss"):n==="disable-sandbox"?this.hasAttribute("disable-sandbox")||this.hasAttribute("disableSandbox"):this.hasAttribute(n)}compatibleDisableProperties(n){return n==="disable-scopecss"?this.getAttribute("disable-scopecss")!=="false"&&this.getAttribute("disableScopecss")!=="false":n==="disable-sandbox"?this.getAttribute("disable-sandbox")!=="false"&&this.getAttribute("disableSandbox")!=="false":this.getAttribute(n)!=="false"}useScopecss(){return!(this.getDisposeResult("disable-scopecss")||this.getDisposeResult("shadowDOM"))}useSandbox(){return!this.getDisposeResult("disable-sandbox")}sameCoreOptions(n){return n.scopecss===this.useScopecss()&&n.useSandbox===this.useSandbox()&&n.iframe===this.getDisposeResult("iframe")}getBaseRouteCompatible(){var n,o;return(o=(n=this.getAttribute("baseroute"))!==null&&n!==void 0?n:this.getAttribute("baseurl"))!==null&&o!==void 0?o:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}updateSsrUrl(n){if(this.getDisposeResult("ssr"))if(this.getDisposeResult("disable-memory-router")||this.getDisposeResult("disableSandbox")){const o=l.rawWindow.location;this.ssrUrl=X(o.pathname+o.search,n)}else{let o=Vo(this.appName,n);const i=this.getDefaultPage();if(!o&&i){const s=W(i,n);o=s.origin+s.pathname+s.search}this.ssrUrl=o}else this.ssrUrl&&(this.ssrUrl="")}getDefaultPage(){return Qe.getDefaultPage(this.appName)||this.getAttribute("default-page")||this.getAttribute("defaultPage")||""}getMemoryRouterMode(){return Fr(this.getAttribute("router-mode"),this.compatibleProperties("disable-memory-router")&&this.compatibleDisableProperties("disable-memory-router"))}setAttribute(n,o){if(n==="data")if(U(o)){const i={};Object.getOwnPropertyNames(o).forEach(s=>{B(s)&&s.indexOf("__")===0||(i[s]=o[s])}),this.data=i}else o!=="[object Object]"&&me("property data must be an object",this.appName);else l.rawSetAttribute.call(this,n,o)}getRouterEventDelay(){let n=parseInt(this.getAttribute("router-event-delay"));return isNaN(n)&&(n=parseInt(R(v.options["router-event-delay"])?v.options["router-event-delay"](this.appName):v.options["router-event-delay"])),isNaN(n)?0:n}set data(n){this.appName?v.setData(this.appName,n):this.cacheData=n}get data(){return this.appName?v.getData(this.appName,!0):this.cacheData?this.cacheData:null}set appName(n){n!==this._appName&&(v.changeEventAppName(n,this._appName),this._appName=n)}get appName(){return this._appName}get publicPath(){return it(this.appUrl)}get baseRoute(){return this.getBaseRouteCompatible()}}window.customElements.define(t,e)}function tr(t,e){if(!rt)return I("preFetch is only supported in browser environment");at(()=>{const r=pt(e)?e:v.options.prefetchDelay;setTimeout(()=>{Wi(t)},pt(r)?r:3e3)})}function Wi(t){R(t)&&(t=t()),se(t)&&t.reduce((e,r)=>e.then(()=>Fi(r)),Promise.resolve())}function Fi(t){return ar(e=>{var r,n,o,i,s,a;if(U(t)&&navigator.onLine)if(t.name=$(t.name),t.url=_t(t.url,t.name),t.name&&t.url&&!y.has(t.name)){const c=new Xr({name:t.name,url:t.url,isPrefetch:!0,scopecss:!((n=(r=t["disable-scopecss"])!==null&&r!==void 0?r:t.disableScopecss)!==null&&n!==void 0?n:v.options["disable-scopecss"]),useSandbox:!((i=(o=t["disable-sandbox"])!==null&&o!==void 0?o:t.disableSandbox)!==null&&i!==void 0?i:v.options["disable-sandbox"]),inline:(s=t.inline)!==null&&s!==void 0?s:v.options.inline,iframe:(a=t.iframe)!==null&&a!==void 0?a:v.options.iframe,prefetchLevel:t.level&&Vt.includes(t.level)?t.level:v.options.prefetchLevel&&Vt.includes(v.options.prefetchLevel)?v.options.prefetchLevel:2}),h=c.onLoad,d=c.onLoadError;c.onLoad=w=>{c.isPrerender&&Z(w,{defaultPage:t["default-page"],routerMode:Fr(t["router-mode"]),baseroute:t.baseroute,disablePatchRequest:t["disable-patch-request"]}),e(),h.call(c,w)},c.onLoadError=(...w)=>{e(),d.call(c,...w)}}else e();else e()})}function Hi(t){U(t)&&at(()=>{rr(t.js,"js",Y.script),rr(t.css,"css",Y.link)})}function rr(t,e,r){if(se(t)){const n=t.filter(i=>B(i)&&sr(i,e)&&!r.hasInfo(i)),o=n.map(i=>ve(i));st(o,i=>{const s=n[i.index];e==="js"?r.hasInfo(s)||r.setInfo(s,{code:i.data,isExternal:!1,appSpace:{}}):r.hasInfo(s)||r.setInfo(s,{code:i.data,appSpace:{}})},i=>{I(i)})}}function Se({excludeHiddenApp:t=!1,excludePreRender:e=!1}={}){const r=[];return y.forEach((n,o)=>{!n.isUnmounted()&&(!n.isPrefetch||n.isPrerender&&!e)&&(!t||!n.isHidden())&&r.push(o)}),r}function ji(){return Array.from(y.keys())}function tn(t,e){const r=y.get($(t));return new Promise(n=>{if(r)if(r.isUnmounted()||r.isPrefetch)r.isPrerender?r.unmount({destroy:!!(e!=null&&e.destroy),clearData:!!(e!=null&&e.clearData),keepRouteState:!1,unmountcb:n.bind(null,!0)}):(e!=null&&e.destroy&&r.actionsForCompletelyDestroy(),n(!0));else if(r.isHidden())e!=null&&e.destroy?r.unmount({destroy:!0,clearData:!0,keepRouteState:!0,unmountcb:n.bind(null,!0)}):e!=null&&e.clearAliveState?r.unmount({destroy:!1,clearData:!!e.clearData,keepRouteState:!0,unmountcb:n.bind(null,!0)}):n(!0);else{const o=le(r.container),i=()=>{o.removeEventListener(N.UNMOUNT,i),o.removeEventListener(N.AFTERHIDDEN,s),n(!0)},s=()=>{o.removeEventListener(N.UNMOUNT,i),o.removeEventListener(N.AFTERHIDDEN,s),n(!0)};if(o.addEventListener(N.UNMOUNT,i),o.addEventListener(N.AFTERHIDDEN,s),e!=null&&e.destroy){let a,c;o.hasAttribute("destroy")&&(a=o.getAttribute("destroy")),o.hasAttribute("destory")&&(c=o.getAttribute("destory")),o.setAttribute("destroy","true"),o.parentNode.removeChild(o),o.removeAttribute("destroy"),B(a)&&o.setAttribute("destroy",a),B(c)&&o.setAttribute("destory",c)}else if((e==null?void 0:e.clearAliveState)&&o.hasAttribute("keep-alive")){const a=o.getAttribute("keep-alive");o.removeAttribute("keep-alive");let c=null;e.clearData&&(c=o.getAttribute("clear-data"),o.setAttribute("clear-data","true")),o.parentNode.removeChild(o),o.setAttribute("keep-alive",a),B(c)&&o.setAttribute("clear-data",c)}else{let a=null;e!=null&&e.clearData&&(a=o.getAttribute("clear-data"),o.setAttribute("clear-data","true")),o.parentNode.removeChild(o),B(a)&&o.setAttribute("clear-data",a)}}else me(`app ${t} does not exist when unmountApp`),n(!1)})}function $i(t){return Array.from(y.keys()).reduce((e,r)=>e.then(()=>tn(r,t)),Promise.resolve(!0))}function Gi(t,e){return new Promise(r=>{const n=y.get($(t));if(n){const o=n.container&&le(n.container);if(o){const i=v.getData(t);n.isReloading=!0,o.reload(e).then(()=>{i&&v.setData(t,i),n.isReloading=!1,r(!0)})}else me(`app ${t} is not rendered, cannot use reload`),r(!1)}else me(`app ${t} does not exist when reload app`),r(!1)})}function Ki(t){return new Promise(e=>{if(!U(t))return I("renderApp options must be an object");const r=ce(t.container)?t.container:B(t.container)?document.querySelector(t.container):null;if(!ce(r))return I("Target container is not a DOM element.");const n=z(v.tagName);for(const a in t)if(a==="onDataChange")R(t[a])&&n.addEventListener("datachange",t[a]);else if(a==="lifeCycles"){const c=t[a];if(U(c))for(const h in c)h.toUpperCase()in N&&R(c[h])&&n.addEventListener(h.toLowerCase(),c[h])}else a!=="container"&&n.setAttribute(a,t[a]);const o=()=>{s(),e(!0)},i=()=>{s(),e(!1)},s=()=>{n.removeEventListener(N.MOUNTED,o),n.removeEventListener(N.ERROR,i)};n.addEventListener(N.MOUNTED,o),n.addEventListener(N.ERROR,i),r.appendChild(n)})}class qi extends Do{constructor(){super(...arguments),this.tagName="micro-app",this.hasInit=!1,this.options={},this.router=Qe,this.preFetch=tr,this.unmountApp=tn,this.unmountAllApps=$i,this.getActiveApps=Se,this.getAllApps=ji,this.reload=Gi,this.renderApp=Ki}start(e){var r,n;if(!rt||!window.customElements)return I("micro-app is not supported in this environment");if(this.hasInit)return I("microApp.start executed repeatedly");if(this.hasInit=!0,e!=null&&e.tagName)if(/^micro-app(-\S+)?/.test(e.tagName))this.tagName=e.tagName;else return I(`${e.tagName} is invalid tagName`);if(Bi(),window.customElements.get(this.tagName))return me(`element ${this.tagName} is already defined`);if(U(e)&&(this.options=e,e["disable-scopecss"]=(r=e["disable-scopecss"])!==null&&r!==void 0?r:e.disableScopecss,e["disable-sandbox"]=(n=e["disable-sandbox"])!==null&&n!==void 0?n:e.disableSandbox,e.preFetchApps&&tr(e.preFetchApps),e.globalAssets&&Hi(e.globalAssets),U(e.plugins))){const o=e.plugins.modules;if(U(o))for(const i in o){const s=$(i);s&&i!==s&&(o[s]=o[i],delete o[i])}}Ui(this.tagName)}}const v=new qi;export{v as m};
|