@micro-zoe/micro-app 0.8.5 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microApp={})}(this,(function(e){"use strict";const t="0.8.5",n="undefined"!=typeof window,s="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function i(e){return"string"==typeof e}function o(e){return"boolean"==typeof e}function r(e){return"function"==typeof e}const a=Array.isArray;function c(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function h(e){return r(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const u=Object.defineProperty,p=Object.defineProperties,d=Object.prototype.hasOwnProperty;function m(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.error(`[micro-app]${s} ${e}`,...n):console.error(`[micro-app]${s}`,e,...n)}function f(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.warn(`[micro-app]${s} ${e}`,...n):console.warn(`[micro-app]${s}`,e,...n)}function _(e,...t){Promise.resolve().then(e.bind(null,...t))}function A(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function b(e,t=null){if(!i(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(A(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return m(e,t),""}}function g(e){return i(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function w(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function y(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,w(A(t))).toString()}function E(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const v=s.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let N=null;function C(e){N=e}function R(e){N!==e&&(C(e),_((()=>{C(null)})))}function D(){return N}function P(){C(null)}function M(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function O(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function S(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function I(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function L(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function U(e){return e?e.replace(/^\s+|\s+$/g,""):""}function x(){return navigator.userAgent.indexOf("Firefox")>-1}var T,k,W,$;!function(e){e.NAME="name",e.URL="url"}(T||(T={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(k||(k={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(W||(W={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}($||($={}));const B="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function F(e,t=null,n={}){return r(Xe.fetch)?Xe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const H=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,K=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function j(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class G{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),x()?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):j("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=U(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||H.test(n)||(n=K.test(n)?n.replace(K,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||j("Declaration missing '}'",this.linkPath)):j("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),A(t.join("/")+"/")}(this.linkPath)),`url("${y(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return j("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return j("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${t} missing '}'`,this.linkPath)):j(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${e} missing '}'`,this.linkPath)):j(`@${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 j("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=U(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(U(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){x()?this.result+=encodeURIComponent(e):this.result+=e}}function V(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=q.exec(e.textContent,n,s,i),q.reset()}catch(e){q.reset(),m("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let q;function z(e,t){if(t.scopecss){const n=`${Xe.tagName}[name=${t.name}]`;if(q||(q=new G),e.textContent)V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function Q(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function J(e){const t=new CustomEvent("load");Q(t,e),r(e.onload)?e.onload(t):e.dispatchEvent(t)}function X(e){const t=new CustomEvent("error");Q(t,e),r(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Y=new Map;function Z(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=y(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",y(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ee(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>Y.has(e)?Y.get(e):F(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Y.has(e)&&Y.set(e,n);const o=M("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(z(o,i),t.placeholder):s.appendChild(z(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)}))}const te=new WeakMap;function ne(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return te.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?z(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return te.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=Z(t,e,n,!0);if(s&&i){const e=M("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,z(i,n),void _((()=>J(s)));if(Y.has(e)){const o=Y.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,z(i,n),void _((()=>J(s)))}F(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&Y.set(e,o),i.textContent=o,z(i,n),J(s)})).catch((e=>{m(e,n.name),X(s)}))}(s,i,n,t,e),te.set(t,e),e}return o?(te.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=_e(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>J(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),be(e,n,t,!0,i)}if(fe.has(e)){const s=fe.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),be(e,n,t,!0,i)}let o;o=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return F(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&fe.set(e,r);try{r=ye(e,n,r,t),n.inline||t.module?ge(e,r,t.module,o,i):we(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&J(s)})).catch((e=>{m(e,n.name),X(s)})),o}(i,o,n,t);return te.set(t,e),e}{const e=be(i,n,o,!0);return te.set(t,e),e}}return s?(te.set(t,s),s):t}return t}function se(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===de.rawAppend||t===de.rawPrepend?t.call(n,s):t.call(n,s,i)}function ie(e){var t;return null!==(t=te.get(e))&&void 0!==t?t:e}function oe(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Ke.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?se(i,s,e,ne(e,t,i),n&&ie(n)):s===de.rawAppend||s===de.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===de.rawAppend||s===de.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=Ke.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function re(){!function(){const e=de.rawDocument;function t(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:de.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:de.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ae(de.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ae(de.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ae(de.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(e))return de.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return de.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!D()||S(e))return de.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return de.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=D();if(!s||I(e)||S(e)||!(null===(t=Ke.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return de.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return de.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!D()||S(e))return de.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return de.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return oe(this,e,null,de.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return oe(this,e,t,de.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return oe(this,e,t,de.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)oe(this,e[t],null,de.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)oe(this,e[t-1],null,de.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ke.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?se(t,de.rawRemoveChild,this,ie(e)):de.rawRemoveChild.call(this,e)}return de.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=de.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ae(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ce=!1;function le(){C(null),Document.prototype.createElement=de.rawCreateElement,Document.prototype.createElementNS=de.rawCreateElementNS,Document.prototype.createDocumentFragment=de.rawCreateDocumentFragment,Document.prototype.querySelector=de.rawQuerySelector,Document.prototype.querySelectorAll=de.rawQuerySelectorAll,Document.prototype.getElementById=de.rawGetElementById,Document.prototype.getElementsByClassName=de.rawGetElementsByClassName,Document.prototype.getElementsByTagName=de.rawGetElementsByTagName,Document.prototype.getElementsByName=de.rawGetElementsByName,Element.prototype.appendChild=de.rawAppendChild,Element.prototype.insertBefore=de.rawInsertBefore,Element.prototype.replaceChild=de.rawReplaceChild,Element.prototype.removeChild=de.rawRemoveChild,Element.prototype.append=de.rawAppend,Element.prototype.prepend=de.rawPrepend,Element.prototype.cloneNode=de.rawCloneNode}let he=!1;function ue(){pe(),Ke.forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Ke.clear()}function pe(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ue,!1)}const de={};function me(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=D(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,C=b.clearInterval,R=b.clearTimeout,P=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(de,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:R,rawDocumentAddEventListener:P,rawDocumentRemoveEventListener:O}),function(){if(!he){he=!0;const e=M("style");de.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Xe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,de.rawDocument.head.appendChild(e)}}(),pe(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ue,!1)}}const fe=new Map;function _e(e,t,n,s=!1){let i=null,o=e.getAttribute("src");if(e.hasAttribute("exclude"))i=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(de.supportModuleScript&&e.noModule||!de.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(o){o=y(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function Ae(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=fe.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push(F(e,t.name)),i.push([e,o]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!fe.has(e)&&fe.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function be(e,t,n,s,i){var o;try{const r=ye(e,t,n.code,n);if(t.inline||n.module){const a=M("script");if(ge(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(we(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ge(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function we(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ye(e,t,n,s){return c(Xe.plugins)&&(n=function(e,t,n,s,i){var o;const r=Ee(s.global,t,e,i);return Ee(null===(o=s.modules)||void 0===o?void 0:o[n],r,e,i)}(e,n,t.name,Xe.plugins,s)),t.sandBox&&!s.module?(de.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${B}){;${n}\n}).call(proxyWindow,${B})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Ee(e,t,n,s){return a(e)?e.reduce(((e,t)=>c(t)&&r(t.loader)?t.loader(e,n,t.options,s):e),t):t}function ve(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{ve(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):Z(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&z(n,t):n instanceof HTMLScriptElement?_e(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",y(n.getAttribute("src"),t.url))}function Ne(e,t){const n=function(e){const t=M("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),m(e,t.name)}ve(n,t),t.source.links.size?ee(n,t,s):t.onLoad(n),t.source.scripts.size?Ae(n,t):t.onLoad(n)}const Ce=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(m("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!r(t))return m("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(r(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!c(t))return m("event-center: data must be object");let n=this.eventList.get(e);if(n){if(n.data!==t){n.data=t;for(const e of n.callbacks)e(t)}}else n={data:t,callbacks:new Set},this.eventList.set(e,n)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function Re(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class De{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ce.on("global",e,t)}removeGlobalDataListener(e){r(e)&&Ce.off("global",e)}setGlobalData(e){P(),Ce.dispatch("global",e)}getGlobalData(){return Ce.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ce.eventList.get("global");if(t)for(const n of t.callbacks)(e&&e===n.__APP_NAME__||!e&&!n.__APP_NAME__)&&t.callbacks.delete(n)}}class Pe extends De{addDataListener(e,t,n){Ce.on(Re(g(e),!1),t,n)}removeDataListener(e,t){r(t)&&Ce.off(Re(g(e),!1),t)}getData(e,t=!1){return Ce.getData(Re(g(e),t))}setData(e,t){Ce.dispatch(Re(g(e),!0),t)}clearDataListener(e){Ce.off(Re(g(e),!1))}}class Me extends De{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ce.on(Re(this.appName,!0),e,t)}removeDataListener(e){r(e)&&Ce.off(Re(this.appName,!0),e)}getData(){return Ce.getData(Re(this.appName,!0))}dispatch(e){P(),Ce.dispatch(Re(this.appName,!1),e);const t=Ke.get(this.appName);if((null==t?void 0:t.container)&&c(e)){const n=new CustomEvent("datachange",{detail:{data:e}});L(t.container).dispatchEvent(n)}}clearDataListener(){Ce.off(Re(this.appName,!0))}}function Oe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(o(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),s=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=s}(t)&&!function(e){return o(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=h(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&u(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Se=new Map;let Ie=!1;const Le=new Map;function Ue(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=de;!Ie&&function(){if(Ie=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return f("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Se.forEach((t=>{r(t)&&t.call(document,e)}))}u(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?Se.get(e):Se.get("base")},set(e){const s=D();s?Se.set(s,e):Se.set("base",e),!t&&r(e)&&(t=!0,de.rawDocumentAddEventListener.call(de.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Le.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const xe=["unmount","appstate-change"];function Te(e,t){return xe.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const ke=["System","__cjsWrapper"],We=["location"],$e=["window","self","globalThis"];class Be{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=de;e.addEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Se.get(t);const e=Le.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Se.set(t,_),C(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),C(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Se.delete(t);const e=Le.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,de.rawWindow._babelPolyfill&&(de.rawWindow._babelPolyfill=!1),1==++Be.activeCount&&(Ue(),re()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(de.rawWindow,e)})),this.escapeKeys.clear(),0==--Be.activeCount&&(document.addEventListener=de.rawDocumentAddEventListener,document.removeEventListener=de.rawDocumentRemoveEventListener,le()))}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=Ce.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Ce.eventList.get(Re(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;c(Xe.plugins)&&(this.commonActionForSpecialProperties(Xe.plugins.global),this.commonActionForSpecialProperties(null===(t=Xe.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(a(e))for(const t of e)c(t)&&(a(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),a(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=de.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,s)=>{if(R(e),Reflect.has(n,s)||i(s)&&/^__MICRO_APP_/.test(s)||this.scopeProperties.includes(s))return Reflect.get(n,s);const o=Reflect.get(t,s);return r(o)?Oe(t,o):o},set:(e,n,s)=>{if(this.active){if(We.includes(n))Reflect.set(t,n,s);else if(d.call(e,n)||!d.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;u(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||ke.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,s)=>{if(d.call(e,s))return n.set(s,"target"),Object.getOwnPropertyDescriptor(e,s);if(d.call(t,s)){n.set(s,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,s);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,s,i)=>"rawWindow"===n.get(s)?Reflect.defineProperty(t,s,i):Reflect.defineProperty(e,s,i),ownKeys:e=>Reflect.ownKeys(t).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,n)=>!d.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=w(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Me(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=de.rawWindow,e.rawDocument=de.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(de.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=de.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),u(e,"top",this.createDescriptorForMicroAppWindow("top",t)),u(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),$e.forEach((t=>{u(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(de.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),de.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||de.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Fe(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const o=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:o});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),r(null===(i=Xe.lifeCycles)||void 0===i?void 0:i[n])&&Xe.lifeCycles[n](a),e.dispatchEvent(a)}function He(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}Be.activeCount=0;const Ke=new Map;class je{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=k.NOT_LOADED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Be(e,t))}loadSourceCode(){var e;this.state=k.LOADING_SOURCE_CODE,F((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),m(t,e.name)}Ne(t=t.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(e=>e.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(e=>e.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),e)})).catch((t=>{m(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):k.UNMOUNT!==this.state&&(this.state=k.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),k.UNMOUNT!==this.state&&(this.onerror(e),this.state=k.LOAD_SOURCE_ERROR)}mount(e,t,n){var s,i,a;if(o(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=k.LOADING_SOURCE_CODE);let c;if(Fe(this.container,this.name,W.BEFOREMOUNT),this.state=k.MOUNTING,O(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push(F(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(be(e,t,r,!1),n(!1)));i.length?E(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(be(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===n.moduleCount||n.errorCount===i.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(r(e)&&r(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){k.UNMOUNT!==this.state&&(this.state=k.MOUNTED,Fe(this.container,this.name,W.MOUNTED))}unmount(e,t){let n;if(this.state===k.LOAD_SOURCE_ERROR&&(e=!0),this.state=k.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){m("an error occurred in the unmount function \n",this.name,e)}He("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){l(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&O(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),ze().length||(ce=!1,Element.prototype.setAttribute=de.rawSetAttribute),Fe(this.container,this.name,W.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Ke.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;O(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=$.KEEP_ALIVE_HIDDEN,He("appstate-change",this.name,{appState:"afterhidden"}),Fe(e,this.name,W.AFTERHIDDEN)}showKeepAliveApp(e){He("appstate-change",this.name,{appState:"beforeshow"}),Fe(e,this.name,W.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=$.KEEP_ALIVE_SHOW,He("appstate-change",this.name,{appState:"aftershow"}),Fe(this.container,this.name,W.AFTERSHOW)}onerror(e){Fe(this.container,this.name,W.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(k.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:de.rawWindow;return this.libraryName=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Ge(e){class n extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=g(this.getAttribute("name")),t=b(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Ke.get(e);if(e!==this.appName&&n&&k.UNMOUNT!==n.getAppState()&&$.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),m(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},ce||(ce=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(c(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{i(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&f("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ke.has(this.__MICRO_APP_NAME__)){const n=Ke.get(this.__MICRO_APP_NAME__);de.rawSetAttribute.call(this,e,y(t,n.url))}else de.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>Fe(this,this.appName,W.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===T.NAME?"appName":"appUrl"]!==n)if(e!==T.URL||this.appUrl)if(e!==T.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,_(this.handleAttributeUpdate));else{const e=g(n);if(!e)return m(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Xe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=b(n,this.appName)))return m(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&r(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Ke.has(this.appName)){const e=Ke.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==k.UNMOUNT?e.isPrefetch||e.getAppState()===k.UNMOUNT?(f(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):m(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):m(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!i(t)||!t)||(m(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,_((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Ke.has(this.appName)&&Ke.get(this.appName).actionsForCompletelyDestroy();const t=new je({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),baseroute:this.getBaseRouteCompatible()});Ke.set(this.appName,t)}handleUnmount(e,t){const n=Ke.get(this.appName);n&&n.getAppState()!==k.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Ke.get(this.appName);e&&e.getAppState()!==k.UNMOUNT&&e.getKeepAliveState()!==$.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){_((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Xe[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}set data(e){this.appName?Xe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Xe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ve(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{r(e)&&(e=e()),a(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{v((()=>{var n,s;if(c(e)&&navigator.onLine)if(e.name=g(e.name),e.url=b(e.url,e.name),e.name&&e.url&&!Ke.has(e.name)){const i=new je({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Xe.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Xe.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Ke.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function qe(e,t,n){if(a(e)){const s=e.filter((e=>i(e)&&e.includes(`.${t}`)&&!n.has(e)));E(s.map((e=>F(e))),(e=>{const t=s[e.index];n.has(t)||n.set(t,e.data)}),(e=>{m(e)}))}}function ze(e){const t=[];return Ke.forEach(((n,s)=>{k.UNMOUNT===n.getAppState()||n.isPrefetch||e&&$.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Qe(e,t){const n=Ke.get(g(e));return new Promise((s=>{if(n)if(n.getAppState()===k.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=L(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else f(`app ${e} does not exist`),s()}))}class Je extends Pe{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ve}start(e){if(!n||!window.customElements)return m("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return m(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return f(`element ${this.tagName} is already defined`);if(me(),e&&c(e)&&(this.shadowDOM=e.shadowDOM,this.destroy=e.destroy,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.ssr=e.ssr,r(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ve(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{qe(t.js,"js",fe),qe(t.css,"css",Y)}))),c(e.plugins))){const t=e.plugins.modules;if(c(t))for(const e in t){const n=g(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Ge(this.tagName)}}var Xe=new Je;e.EventCenterForMicroApp=Me,e.MicroApp=Je,e.default=Xe,e.getActiveApps=ze,e.getAllApps=function(){return Array.from(Ke.keys())},e.preFetch=Ve,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(Ke.keys()).reduce(((t,n)=>t.then((()=>Qe(n,e)))),Promise.resolve())},e.unmountApp=Qe,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microApp={})}(this,(function(e){"use strict";const t="1.0.0-alpha.1",n="undefined"!=typeof window,i="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")(),o=()=>{},s=()=>!1,r=Array.isArray,a=Object.assign,c=Object.defineProperty,l=Object.defineProperties,u=Object.prototype.hasOwnProperty;function h(e){return void 0===e}function p(e){return null===e}function d(e){return"string"==typeof e}function m(e){return"boolean"==typeof e}function f(e){return"function"==typeof e}function _(e){return"[object Object]"===toString.call(e)}function A(e){return"[object Promise]"===toString.call(e)}function g(e){return f(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function w(e){return e instanceof URL}function y(e,t=null,...n){const i=t&&d(t)?` app ${t}:`:"";d(e)?console.error(`[micro-app]${i} ${e}`,...n):console.error(`[micro-app]${i}`,e,...n)}function b(e,t=null,...n){const i=t&&d(t)?` app ${t}:`:"";d(e)?console.warn(`[micro-app]${i} ${e}`,...n):console.warn(`[micro-app]${i}`,e,...n)}function v(e,...t){Promise.resolve().then(e.bind(null,...t))}const E=function(){class e extends URL{}return(t,n)=>n?new e(""+t,n):new e(""+t)}();function R(e){return e.startsWith("//")?`${i.location.protocol}${e}`:e}function P(e,t=null){if(!d(e)||!e)return"";try{const{origin:t,pathname:n,search:i}=E(R(e));if(/\.(\w+)$/.test(n))return`${t}${n}${i}`;const o=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(o)?`${o}${i}`:""}catch(e){return y(e,t),""}}function N(e){return d(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function C(e){const{origin:t,pathname:n}=E(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function M(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:E(e,C(R(t))).toString()}function S(e,t,n,i){let o=0;function s(){++o===e.length&&i&&i()}e.forEach(((e,i)=>{A(e)?e.then((e=>{t({data:e,index:i}),s()})).catch((e=>{n({error:e,index:i}),s()})):(t({data:e,index:i}),s())}))}const D=i.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let O=null;function L(e){O=e}function I(e){O!==e&&(L(e),v((()=>{L(null)})))}function x(){return O}function U(){L(null)}function T(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function W(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),i=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{i.appendChild(e)})),t.appendChild(i)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function k(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function B(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function H(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function F(e){return e?e.replace(/^\s+|\s+$/g,""):""}function $(){return navigator.userAgent.indexOf("Firefox")>-1}function K(e){const t={},n=e.split("&");for(const e of n){const n=e.indexOf("="),i=n<0?e:e.slice(0,n),o=n<0?null:e.slice(n+1);if(i in t){let e=t[i];r(e)||(e=t[i]=[e]),e.push(o)}else t[i]=o}return t}function G(e){let t="";for(const n in e){const i=e[n];if(p(i))t+=(t.length?"&":"")+n;else{(r(i)?i:[i]).forEach((e=>{h(e)||(t+=(t.length?"&":"")+n,p(e)||(t+="="+e))}))}}return t}function j(){const e=new Set;return{add:function(t){return e.add(t),()=>!!e.has(t)&&e.delete(t)},list:()=>e}}var V,Q,q,z;!function(e){e.NAME="name",e.URL="url"}(V||(V={})),function(e){e.CREATED="created",e.LOADING="loading",e.LOADED="loaded",e.LOAD_FAILED="load_failed",e.MOUNTING="mounting",e.MOUNTED="mounted",e.UNMOUNT="unmount"}(Q||(Q={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(q||(q={})),function(e){e.KEEP_ALIVE_SHOW="keep_alive_show",e.KEEP_ALIVE_HIDDEN="keep_alive_hidden"}(z||(z={}));const Y="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,navigator,undefined,location,history";function X(e,t=null,n={}){return f(Kt.fetch)?Kt.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const J=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,Z=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function ee(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class te{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,i){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=i||"",this.matchRules(),$()?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):ee("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=F(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||J.test(n)||(n=Z.test(n)?n.replace(Z,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||ee("Declaration missing '}'",this.linkPath)):ee("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),R(t.join("/")+"/")}(this.linkPath)),`url("${M(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return ee("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return ee("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee(`@${t} missing '}'`,this.linkPath)):ee(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee(`@${e} missing '}'`,this.linkPath)):ee(`@${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 ee("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=F(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(F(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const i=n[0];return this.cssText=this.cssText.slice(i.length),t||this.recordResult(i),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){$()?this.result+=encodeURIComponent(e):this.result+=e}}function ne(e,t,n,i,o){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let s=null;try{s=ie.exec(e.textContent,n,i,o),ie.reset()}catch(e){ie.reset(),y("An error occurred while parsing CSS:\n",t,e)}s&&(e.textContent=s)}}let ie;function oe(e,t){if(t.scopecss){const n=`${Kt.tagName}[name=${t.name}]`;if(ie||(ie=new te),e.textContent)ne(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const i=new MutationObserver((function(){i.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&ne(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));i.observe(e,{childList:!0})}}return e}function se(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function re(e){const t=new CustomEvent("load");se(t,e),f(e.onload)?e.onload(t):e.dispatchEvent(t)}function ae(e){const t=new CustomEvent("error");se(t,e),f(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const ce=new Map;function le(e,t,n,i=!1){const o=e.getAttribute("rel");let s=e.getAttribute("href"),r=null;if("stylesheet"===o&&s){if(s=M(s,n.url),i)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${s} move to micro-app-head as style element`),n.source.links.set(s,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else o&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(o)?i?r=document.createComment(`link element with rel=${o}${s?" & href="+s:""} removed by micro-app`):t.removeChild(e):s&&e.setAttribute("href",M(s,n.url));return i?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ue(e,t,n){const i=Array.from(t.source.links.entries());S(i.map((([e])=>ce.has(e)?ce.get(e):X(e,t.name))),(e=>{!function(e,t,n,i,o){t.isGlobal&&!ce.has(e)&&ce.set(e,n);const s=T("style");s.textContent=n,s.__MICRO_APP_LINK_PATH__=e,s.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(oe(s,o),t.placeholder):i.appendChild(oe(s,o));t.placeholder=null,t.code=n}(i[e.index][0],i[e.index][1],e.data,n,t)}),(e=>{y(e,t.name)}),(()=>{t.onLoad(e)}))}class he{constructor(){this.escapeSetterKeyList=["location"],this.staticEscapeProperties=["System","__cjsWrapper"],this.staticScopeProperties=["webpackJsonp","webpackHotUpdate","Vue"],this.injectReactHRMProperty()}injectReactHRMProperty(){"production"!==process.env.NODE_ENV&&(this.staticEscapeProperties.push("__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"),Ee.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__&&(this.staticScopeProperties=this.staticScopeProperties.concat(["__REACT_ERROR_OVERLAY_GLOBAL_HOOK__","__reactRefreshInjected"])))}}const pe=new WeakMap;function de(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return pe.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?oe(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return pe.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:i,info:o,replaceComment:s}=le(t,e,n,!0);if(i&&o){const e=T("style");return e.__MICRO_APP_LINK_PATH__=i,function(e,t,n,i,o){if(n.source.links.has(e))return o.textContent=n.source.links.get(e).code,oe(o,n),void v((()=>re(i)));if(ce.has(e)){const s=ce.get(e);return t.code=s,n.source.links.set(e,t),o.textContent=s,oe(o,n),void v((()=>re(i)))}X(e,n.name).then((s=>{t.code=s,n.source.links.set(e,t),t.isGlobal&&ce.set(e,s),o.textContent=s,oe(o,n),re(i)})).catch((e=>{y(e,n.name),ae(i)}))}(i,o,n,t,e),pe.set(t,e),e}return s?(pe.set(t,s),s):t}if(t instanceof HTMLScriptElement){const{replaceComment:i,url:o,info:s}=Ne(t,e,n,!0)||{};if(o&&s){if(s.isExternal){const e=function(e,t,n,i){const o=()=>re(i);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&v(o),Me(e,n,t,!0,o)}if(Pe.has(e)){const i=Pe.get(e);return t.code=i,n.source.scripts.set(e,t),!t.module&&v(o),Me(e,n,t,!0,o)}let s;s=n.inline||t.module?T("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return X(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&Pe.set(e,r);try{r=Oe(e,n,r,t),n.inline||t.module?Se(e,r,t.module,s,o):De(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&re(i)})).catch((e=>{y(e,n.name),ae(i)})),s}(o,s,n,t);return pe.set(t,e),e}{const e=Me(o,n,s,!0);return pe.set(t,e),e}}return i?(pe.set(t,i),i):t}return t}function me(e,t,n,i,o){const s=function(e,t){var n,i;if(e===document.head)return null===(n=null==t?void 0:t.container)||void 0===n?void 0:n.querySelector("micro-app-head");if(e===document.body)return null===(i=null==t?void 0:t.container)||void 0===i?void 0:i.querySelector("micro-app-body");return null}(n,e);return s?o&&!s.contains(o)?Ee.rawAppendChild.call(s,i):t!==Ee.rawRemoveChild||s.contains(i)?("production"!==process.env.NODE_ENV&&i instanceof HTMLIFrameElement&&t===Ee.rawAppendChild&&function(e){var t;if("production"!==process.env.NODE_ENV){const n=Ee.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__,i=null===(t=e.sandBox)||void 0===t?void 0:t.proxyWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__;n&&i&&(Ee.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__=i,v((()=>{Ee.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__=n})))}}(e),fe(t,s,i,o)):n.contains(i)?t.call(n,i):i:fe(t,n,i,o)}function fe(e,t,n,i){return(o=e)===Ee.rawAppend||o===Ee.rawPrepend?e.call(t,n):e.call(t,n,i);var o}function _e(e){var t;return null!==(t=pe.get(e))&&void 0!==t?t:e}function Ae(e,t,n,i){if(null==t?void 0:t.__MICRO_APP_NAME__){const o=Ut.get(t.__MICRO_APP_NAME__);return(null==o?void 0:o.container)?me(o,i,e,de(e,t,o),n&&_e(n)):i===Ee.rawAppend||i===Ee.rawPrepend?i.call(e,t):i.call(e,t,n)}if(i===Ee.rawAppend||i===Ee.rawPrepend){const n=x();if(!(t instanceof Node)&&n){const o=Ut.get(n);if(null==o?void 0:o.container){if(e===document.head)return i.call(o.container.querySelector("micro-app-head"),t);if(e===document.body)return i.call(o.container.querySelector("micro-app-body"),t)}}return i.call(e,t)}return i.call(e,t,n)}function ge(){!function(){const e=Ee.rawDocument;function t(t){var n,i,o,s;const r=x();return r&&(null===(n=Ut.get(r))||void 0===n?void 0:n.container)&&t&&!B(t)&&e===this?null!==(s=null===(o=null===(i=Ut.get(r))||void 0===i?void 0:i.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==s?s:null:Ee.rawQuerySelector.call(this,t)}function n(t){var n,i,o,s;const r=x();return r&&(null===(n=Ut.get(r))||void 0===n?void 0:n.container)&&t&&!B(t)&&e===this?null!==(s=null===(o=null===(i=Ut.get(r))||void 0===i?void 0:i.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==s?s:[]:Ee.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return we(Ee.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return we(Ee.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return we(Ee.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!x()||k(e))return Ee.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return Ee.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!x()||k(e))return Ee.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return Ee.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const i=x();if(!i||B(e)||k(e)||!(null===(t=Ut.get(i))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return Ee.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return Ee.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!x()||k(e))return Ee.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return Ee.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return Ae(this,e,null,Ee.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return Ae(this,e,t,Ee.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return Ae(this,e,t,Ee.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)Ae(this,e[t],null,Ee.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)Ae(this,e[t-1],null,Ee.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ut.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?me(t,Ee.rawRemoveChild,this,_e(e)):Ee.rawRemoveChild.call(this,e)}return Ee.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=Ee.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function we(e){const t=x();return t&&(e.__MICRO_APP_NAME__=t),e}let ye=!1;function be(){L(null),Document.prototype.createElement=Ee.rawCreateElement,Document.prototype.createElementNS=Ee.rawCreateElementNS,Document.prototype.createDocumentFragment=Ee.rawCreateDocumentFragment,Document.prototype.querySelector=Ee.rawQuerySelector,Document.prototype.querySelectorAll=Ee.rawQuerySelectorAll,Document.prototype.getElementById=Ee.rawGetElementById,Document.prototype.getElementsByClassName=Ee.rawGetElementsByClassName,Document.prototype.getElementsByTagName=Ee.rawGetElementsByTagName,Document.prototype.getElementsByName=Ee.rawGetElementsByName,Element.prototype.appendChild=Ee.rawAppendChild,Element.prototype.insertBefore=Ee.rawInsertBefore,Element.prototype.replaceChild=Ee.rawReplaceChild,Element.prototype.removeChild=Ee.rawRemoveChild,Element.prototype.append=Ee.rawAppend,Element.prototype.prepend=Ee.rawPrepend,Element.prototype.cloneNode=Ee.rawCloneNode}let ve=!1;const Ee={};function Re(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,i=Element.prototype.replaceChild,o=Element.prototype.removeChild,s=Element.prototype.append,r=Element.prototype.prepend,c=Element.prototype.cloneNode,l=Document.prototype.createElement,u=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,m=Document.prototype.getElementById,f=Document.prototype.getElementsByClassName,_=Document.prototype.getElementsByTagName,A=Document.prototype.getElementsByName,g=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=x(),n}}),w=Function("return window")(),y=Function("return document")(),b="noModule"in document.createElement("script"),v=w.addEventListener,E=w.removeEventListener,R=w.setInterval,P=w.setTimeout,N=w.clearInterval,C=w.clearTimeout,M=y.addEventListener,S=y.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,a(Ee,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:i,rawRemoveChild:o,rawAppend:s,rawPrepend:r,rawCloneNode:c,rawCreateElement:l,rawCreateElementNS:u,rawCreateDocumentFragment:h,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:m,rawGetElementsByClassName:f,rawGetElementsByTagName:_,rawGetElementsByName:A,ImageProxy:g,rawWindow:w,rawDocument:y,supportModuleScript:b,rawWindowAddEventListener:v,rawWindowRemoveEventListener:E,rawSetInterval:R,rawSetTimeout:P,rawClearInterval:N,rawClearTimeout:C,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:S}),function(){if(!ve){ve=!0;const e=T("style");Ee.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Kt.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,Ee.rawDocument.head.appendChild(e)}}()}}const Pe=new Map;function Ne(e,t,n,i=!1){let o=null,s=e.getAttribute("src");if(e.hasAttribute("exclude"))o=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(Ee.supportModuleScript&&e.noModule||!Ee.supportModuleScript&&"module"===e.type)o=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(s){s=M(s,n.url);const t={code:"",isExternal:!0,isDynamic:i,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(i)return{url:s,info:t};n.source.scripts.set(s,t),o=document.createComment(`script with src='${s}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),s={code:e.textContent,isExternal:!1,isDynamic:i,async:!1,defer:"module"===e.type,module:"module"===e.type};if(i)return{url:t,info:s};n.source.scripts.set(t,s),o=document.createComment("inline script extract by micro-app")}else i||(o=document.createComment("script element removed by micro-app"))}return i?{replaceComment:o}:t.replaceChild(o,e)}function Ce(e,t){const n=Array.from(t.source.scripts.entries()),i=[],o=[];for(const[e,s]of n)if(s.isExternal){const n=Pe.get(e);n?s.code=n:(!s.defer&&!s.async||t.isPrefetch)&&(i.push(X(e,t.name)),o.push([e,s]))}i.length?S(i,(e=>{!function(e,t,n){t.isGlobal&&!Pe.has(e)&&Pe.set(e,n);t.code=n}(o[e.index][0],o[e.index][1],e.data)}),(e=>{y(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Me(e,t,n,i,o){var s;try{const r=Oe(e,t,n.code,n);if(t.inline||n.module){const a=T("script");if(Se(e,r,n.module,a,o),i)return a;null===(s=t.container)||void 0===s||s.querySelector("micro-app-body").appendChild(a)}else if(De(r,n),i)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Se(e,t,n,i,o){if(n){const e=new Blob([t],{type:"text/javascript"});i.src=URL.createObjectURL(e),i.setAttribute("type","module"),o&&(o.moduleCount&&o.moduleCount--,i.onload=o.bind(i,0===o.moduleCount))}else i.textContent=t;e.startsWith("inline-")||i.setAttribute("data-origin-src",e)}function De(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function Oe(e,t,n,i){return _(Kt.plugins)&&(n=function(e,t,n,i,o){var s;const r=Le(i.global,t,e,o);return Le(null===(s=i.modules)||void 0===s?void 0:s[n],r,e,o)}(e,n,t.name,Kt.plugins,i)),t.sandBox&&!i.module?(Ee.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${Y}){;${n}\n}).call(proxyWindow,${Y})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Le(e,t,n,i){return r(e)?e.reduce(((e,t)=>_(t)&&f(t.loader)?t.loader(e,n,t.options,i):e),t):t}function Ie(e,t,n){const i=Array.from(e.children);i.length&&i.forEach((e=>{Ie(e,t)}));for(const n of i)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",M(n.getAttribute("href"),t.url)):le(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&oe(n,t):n instanceof HTMLScriptElement?Ne(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",M(n.getAttribute("src"),t.url))}function xe(e,t){const n=function(e){const t=T("div");return t.innerHTML=e,t}(e),i=n.querySelector("micro-app-head"),o=n.querySelector("micro-app-body");if(!i||!o){const e=`element ${i?"body":"head"} is missing`;return t.onerror(new Error(e)),y(e,t.name)}Ie(n,t),t.source.links.size?ue(n,t,i):t.onLoad(n),t.source.scripts.size?Ce(n,t):t.onLoad(n)}const Ue=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(y("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!f(t))return y("event-center: Invalid callback function");let i=this.eventList.get(e);i?n&&Object.getOwnPropertyNames(i.data).length&&t(i.data):(i={data:{},callbacks:new Set},this.eventList.set(e,i)),i.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(f(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!_(t))return y("event-center: data must be object");let n=this.eventList.get(e);if(n){if(n.data!==t){n.data=t;for(const e of n.callbacks)e(t)}}else n={data:t,callbacks:new Set},this.eventList.set(e,n)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function Te(e,t){return d(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class We{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ue.on("global",e,t)}removeGlobalDataListener(e){f(e)&&Ue.off("global",e)}setGlobalData(e){U(),Ue.dispatch("global",e)}getGlobalData(){return Ue.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ue.eventList.get("global");if(t)for(const n of t.callbacks)(e&&e===n.__APP_NAME__||!e&&!n.__APP_NAME__)&&t.callbacks.delete(n)}}class ke extends We{addDataListener(e,t,n){Ue.on(Te(N(e),!1),t,n)}removeDataListener(e,t){f(t)&&Ue.off(Te(N(e),!1),t)}getData(e,t=!1){return Ue.getData(Te(N(e),t))}setData(e,t){Ue.dispatch(Te(N(e),!0),t)}clearDataListener(e){Ue.off(Te(N(e),!1))}}class Be extends We{constructor(e){super(),this.appName=N(e),!this.appName&&y(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ue.on(Te(this.appName,!0),e,t)}removeDataListener(e){f(e)&&Ue.off(Te(this.appName,!0),e)}getData(){return Ue.getData(Te(this.appName,!0))}dispatch(e){U(),Ue.dispatch(Te(this.appName,!1),e);const t=Ut.get(this.appName);if((null==t?void 0:t.container)&&_(e)){const n=new CustomEvent("datachange",{detail:{data:e}});H(t.container).dispatchEvent(n)}}clearDataListener(){Ue.off(Te(this.appName,!0))}}function He(){Ut.forEach((e=>{e.container&&H(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Ut.clear()}function Fe(){window.__MICRO_APP_ENVIRONMENT__&&(window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",He,!1),window.addEventListener("unmount",He,!1))}function $e(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(m(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),i=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=i}(t)&&!function(e){return m(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=g(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&c(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Ke=["unmount","appstate-change"];function Ge(e,t){var n;return Ke.includes(e)||("popstate"===e||"hashchange"===e)&&(null===(n=Ut.get(t))||void 0===n?void 0:n.useMemoryRouter)?`${e}-${t}`:e}const je=new Map;let Ve=!1;const Qe=new Map;function qe(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=Ee;!Ve&&function(){if(Ve=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return b("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){je.forEach((t=>{f(t)&&t.call(document,e)}))}c(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=x();return e?je.get(e):je.get("base")},set(e){const i=x();i?je.set(i,e):je.set("base",e),!t&&f(e)&&(t=!0,Ee.rawDocumentAddEventListener.call(Ee.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,i,o){var s;const r=x();if(r&&(!(null===(s=Ut.get(r))||void 0===s?void 0:s.umdMode)||!g(i))){const e=Qe.get(r);if(e){const t=e.get(n);t?t.add(i):e.set(n,new Set([i]))}else Qe.set(r,new Map([[n,new Set([i])]]));i&&(i.__MICRO_APP_MARK_OPTIONS__=o)}t.call(e,n,i,o)},document.removeEventListener=function(t,i,o){var s;const r=x();if(r&&(!(null===(s=Ut.get(r))||void 0===s?void 0:s.umdMode)||!g(i))){const e=Qe.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(i)&&n.delete(i)}}n.call(e,t,i,o)}}function ze(e,t,n){const i={microAppState:a({},null==t?void 0:t.microAppState,{[e]:n})};return a({},t,i)}function Ye(e,t){var n;return(null===(n=null==t?void 0:t.microAppState)||void 0===n?void 0:n[e])||null}const Xe=/&/g,Je=/=/g,Ze=/%M1/g,et=/%M2/g;function tt(e){return encodeURIComponent(it(e).replace(Xe,"%M1").replace(Je,"%M2"))}function nt(e){return it(e).replace(Ze,"&").replace(et,"=")}function it(e){try{const t=decodeURIComponent(e);return e===t||Ze.test(t)||et.test(t)?t:it(t)}catch(t){return e}}function ot(e){return`app-${e}`}function st(e){var t,n;const i=Ee.rawWindow.location,o=at(i.search,i.hash),s=(null===(t=o.hashQuery)||void 0===t?void 0:t[ot(e)])||(null===(n=o.searchQuery)||void 0===n?void 0:n[ot(e)]);return d(s)?nt(s):null}function rt(e,t){let{pathname:n,search:i,hash:o}=Ee.rawWindow.location;const s=at(i,o),r=tt(t.pathname+t.search+t.hash);let a=!1;if(o&&!i){a=!0,s.hashQuery?s.hashQuery[ot(e)]=r:s.hashQuery={[ot(e)]:r};const t=o.includes("?")?o.slice(0,o.indexOf("?")+1):o+"?";o=t+G(s.hashQuery)}else s.searchQuery?s.searchQuery[ot(e)]=r:s.searchQuery={[ot(e)]:r},i="?"+G(s.searchQuery);return{fullPath:n+i+o,isAttach2Hash:a}}function at(e,t){const n={};return""!==e&&"?"!==e&&(n.searchQuery=K(e.slice(1))),t.includes("?")&&(n.hashQuery=K(t.slice(t.indexOf("?")+1))),n}function ct(e){const t=Ee.rawWindow,n=n=>{if(Ht(!0).includes(e)&&!n.onlyForBrowser){const n=st(e),i=Ut.get(e).sandBox.proxyWindow;let o=!1;const s=i.location.href;if(n){const t=i.location.hash;Et(e,n,i.location),o=i.location.hash!==t}!function(e,t,n){const i=new PopStateEvent(Ge("popstate",e),{state:Ye(e,n)});Ee.rawWindow.dispatchEvent(i),"function"==typeof t.onpopstate&&t.onpopstate(i)}(e,i,t.history.state),o&&function(e,t,n){const i=new HashChangeEvent(Ge("hashchange",e),{newURL:t.location.href,oldURL:n});Ee.rawWindow.dispatchEvent(i),"function"==typeof t.onhashchange&&t.onhashchange(i)}(e,i,s),U()}};return t.addEventListener("popstate",n),()=>{t.removeEventListener("popstate",n)}}function lt(e,t){U(),function(e){const t=new PopStateEvent("popstate",{state:null});e&&(t.onlyForBrowser=!0),Ee.rawWindow.dispatchEvent(t)}(e),t&&function(e){const t=new HashChangeEvent("hashchange",{newURL:Ee.rawWindow.location.href,oldURL:e});Ee.rawWindow.dispatchEvent(t)}(t)}function ut(e,t){const n=Ee.rawWindow.history;return new Proxy(n,{get(i,o){return"state"===o?Ye(e,n.state):f(Reflect.get(i,o))?(s=o,function(...i){if("pushState"!==s&&"replaceState"!==s||!d(i[2])&&!w(i[2]))n[s].apply(n,i);else{const o=E(i[2],t.href);if(o.origin===t.origin){pt(s,rt(e,o),!0,ze(e,n.state,i[0]),i[1]);const r=o.pathname+o.search+o.hash;r!==t.fullPath&&Et(e,r,t)}else n[s].apply(n,i)}}):Reflect.get(i,o);var s},set:(e,t,n)=>Reflect.set(e,t,n)})}function ht(e,t,n=null,i=""){Ee.rawWindow.history[e](n,i,t)}function pt(e,t,n,i,o){const s=Ee.rawWindow.location,r=s.pathname+s.search+s.hash,a=t.isAttach2Hash&&r!==t.fullPath?s.href:null;ht(e,t.fullPath,i,o),r!==t.fullPath&&lt(n,a)}function dt(e,t){pt("replaceState",e,!0,t)}function mt(e){const t=Ee.rawWindow;return function(...n){var i;if((null===(i=t.history.state)||void 0===i?void 0:i.microAppState)&&(!_(n[0])||!n[0].microAppState)&&(d(n[2])||w(n[2]))){const e=t.location.href;E(n[2],e).href===e&&(n[0]=a({},n[0],{microAppState:t.history.state.microAppState}))}e.apply(t.history,n)}}let ft=!1;const{router:_t,executeNavigationGuard:At,clearRouterWhenUnmount:gt}=function(){function e(e,t,n,i){pt(t,rt(e,n),!1,ze(e,Ee.rawWindow.history.state,null!=i?i:null)),U()}function t(t){return function(n){const i=N(n.name);if(i&&d(n.path)){const o=Ut.get(i);if(o&&!o.sandBox)return y(`navigation failed, sandBox of app ${i} is closed`);if(Ht().includes(i)){const s=o.sandBox.proxyWindow.location,r=E(n.path,s.href),a=r.pathname+r.search+r.hash;if(s.fullPath!==a||st(i)!==a){e(i,t&&!1!==n.replace||!0===n.replace?"replaceState":"pushState",r,n.state)}}else{const t=Ee.rawWindow.location,o=E(n.path,t.origin),s=o.pathname+o.search+o.hash;st(i)!==s&&e(i,!1===n.replace?"pushState":"replaceState",o,n.state)}}else y("navigation failed, name & path are required when use router."+(t?"replace":"push"))}}function n(e){return function(...t){return Ee.rawWindow.history[e](...t)}}const i=j(),o=j();function r(e,t,n,i){U();for(const o of i)f(o)?o(e,t,n):_(o)&&f(o[e])&&o[e](t,n)}const a=function(){const e=new Map;return{add:function(t,n){return e.set(t,n),()=>!!e.has(t)&&e.delete(t)},get:t=>e.get(t),delete:t=>!!e.has(t)&&e.delete(t)}}(),c={current:new Map,encode:tt,decode:nt,push:t(!1),replace:t(!0),go:n("go"),back:n("back"),forward:n("forward"),beforeEach:i.add,afterEach:o.add,setDefaultPage:function(e,t){return(e=N(e))?a.add(e,t):s},removeDefaultPage:function(e){return!!(e=N(e))&&a.delete(e)},getDefaultPage:a.get};return{router:c,executeNavigationGuard:function(e,t,n){c.current.set(e,t),r(e,t,n,i.list()),D((()=>{r(e,t,n,o.list())}))},clearRouterWhenUnmount:function(e){c.current.delete(e)}}}(),wt=["href","pathname","search","hash"],yt=[...wt,"host","hostname","port","protocol","search"],bt=[...yt,"origin","fullPath"];function vt(e,t){const n=a({name:e},t);for(const e of bt)n[e]=t[e];return n}function Et(e,t,n,i){const o=E(t,n.href),s=vt(e,n);for(const e of yt)wt.includes(e)?n.shadowLocation[e]=o[e]:n[e]=o[e];const r=vt(e,n);("auto"===i||s.fullPath!==r.fullPath&&"prevent"!==i)&&At(e,r,s)}function Rt(e,t){!function(){if(!ft&&!window.__MICRO_APP_ENVIRONMENT__){ft=!0;const e=Ee.rawWindow;e.history.pushState=mt(e.history.pushState),e.history.replaceState=mt(e.history.replaceState)}}();const n=function(e,t){const n=Ee.rawWindow.location,i=E(t),s={href:i.href,pathname:i.pathname,search:i.search,hash:i.hash},r=(t,o)=>{const r=E(t,i.href);if(r.origin===i.origin){const i=rt(e,r);if(r.pathname===s.pathname&&r.search===s.search){let e=null;return r.hash!==s.hash&&(i.isAttach2Hash&&(e=n.href),ht(o,i.fullPath)),void(r.hash?lt(!1,e):n.reload())}if(i.isAttach2Hash)return ht(o,i.fullPath),void n.reload();t=i.fullPath}return t};function c(e,t){return{enumerable:!0,configurable:!0,get:e,set:t}}function u(i,o){const r=E(i,t);r[o]===s[o]&&s.hash?lt(!1):(ht(r[o]===s[o]?"replaceState":"pushState",rt(e,r).fullPath),n.reload())}l(i,{href:c((()=>s.href),(e=>{const t=r(e,"pushState");t&&(n.href=t)})),pathname:c((()=>s.pathname),(e=>{u(("/"+e).replace(/^\/+/,"/")+s.search+s.hash,"pathname")})),search:c((()=>s.search),(e=>{u(s.pathname+("?"+e).replace(/^\?+/,"?")+s.hash,"search")})),hash:c((()=>s.hash),(n=>{const i=s.pathname+s.search+("#"+n).replace(/^#+/,"#"),o=E(i,t);o.hash!==s.hash&&pt("pushState",rt(e,o),!1)})),fullPath:c((()=>s.pathname+s.search+s.hash),o)});const h=e=>function(t){const i=r(t,"assign"===e?"pushState":"replaceState");i&&n[e](i)};return a(i,{assign:h("assign"),replace:h("replace"),reload:e=>n.reload(e),shadowLocation:s})}(e,t);return{microLocation:n,microHistory:ut(e,n)}}function Pt(e,t,n){n&&Et(e,n,t,"prevent"),dt(rt(e,t),ze(e,Ee.rawWindow.history.state,null)),function(e,t){At(e,vt(e,t),vt(e,t))}(e,t)}function Nt(e){dt(function(e,t){var n,i,o,s;let{pathname:r,search:a,hash:c}=t||Ee.rawWindow.location;const l=at(a,c);let u=!1;if(null===(n=l.hashQuery)||void 0===n?void 0:n[ot(e)]){u=!0,null===(i=l.hashQuery)||void 0===i||delete i[ot(e)];const t=G(l.hashQuery);c=c.slice(0,c.indexOf("?")+Number(Boolean(t)))+t}else if(null===(o=l.searchQuery)||void 0===o?void 0:o[ot(e)]){null===(s=l.searchQuery)||void 0===s||delete s[ot(e)];const t=G(l.searchQuery);a=t?"?"+t:""}return{fullPath:r+a+c,isAttach2Hash:u}}(e),function(e,t){return _(null==t?void 0:t.microAppState)&&(h(t.microAppState[e])||delete t.microAppState[e],Object.keys(t.microAppState).length||delete t.microAppState),a({},t)}(e,Ee.rawWindow.history.state))}function Ct(e,t){if(!h(t)&&!f(t))return t;const n=t||Ee.rawWindow.fetch;return function(t,i,...o){return(d(t)||w(t))&&(t=E(t,e).toString()),n.call(Ee.rawWindow,t,i,...o)}}function Mt(e,t){if(!h(t)&&!f(t))return t;const n=t||Ee.rawWindow.XMLHttpRequest;return class extends n{open(t,n,...i){(d(n)&&!/^f(ile|tp):\/\//.test(n)||w(n))&&(n=E(n,e).toString()),super.open(t,n,...i)}}}const{createMicroEventSource:St,clearMicroEventSource:Dt}=function(){let e;return{createMicroEventSource:function(t,n,i){if(!h(i)&&!f(i))return i;const o=i||Ee.rawWindow.EventSource;return class extends o{constructor(i,o,...s){if((d(i)||w(i))&&(i=E(i,n).toString()),super(i,o,...s),e){const n=e.get(t);n?n.add(this):e.set(t,new Set([this]))}else e=new Map([[t,new Set([this])]])}close(){var n;super.close(),null===(n=e.get(t))||void 0===n||n.delete(this)}}},clearMicroEventSource:function(t){const n=null==e?void 0:e.get(t);(null==n?void 0:n.size)&&(n.forEach((e=>{e.close()})),n.clear())}}}(),Ot=["window","self","globalThis"];class Lt{constructor(e,t,n=!0){this.scopeProperties=[],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.adapter=new he,this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),a(this,function(e,t){const n=new Map,i=new Map,o=new Map,{rawWindow:s,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=Ee;t.addEventListener=function(t,i,o){t=Ge(t,e);const r=n.get(t);r?r.add(i):n.set(t,new Set([i])),i&&(i.__MICRO_APP_MARK_OPTIONS__=o),a.call(s,t,i,o)},t.removeEventListener=function(t,i,o){t=Ge(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(i)&&r.delete(i),c.call(s,t,i,o)},t.setInterval=function(e,t,...n){const o=l.call(s,e,t,...n);return i.set(o,{handler:e,timeout:t,args:n}),o},t.setTimeout=function(e,t,...n){const i=u.call(s,e,t,...n);return o.set(i,{handler:e,timeout:t,args:n}),i},t.clearInterval=function(e){i.delete(e),h.call(s,e)},t.clearTimeout=function(e){o.delete(e),p.call(s,e)};const m=new Map,f=new Map;let _,A=new Map,g=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),i.size&&(A=new Map(i)),o.size&&(g=new Map(o)),_=je.get(e);const t=Qe.get(e);t&&t.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((e,n)=>{for(const i of e)t.addEventListener(n,i,null==i?void 0:i.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((e=>{t.setInterval(e.handler,e.timeout,...e.args)})),g.forEach((e=>{t.setTimeout(e.handler,e.timeout,...e.args)})),_&&je.set(e,_),L(e),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),L(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(s,t,n)})),n.clear()),i.size&&(i.forEach(((e,t)=>{h.call(s,t)})),i.clear()),o.size&&(o.forEach(((e,t)=>{p.call(s,t)})),o.clear()),je.delete(e);const t=Qe.get(e);t&&(t.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),t.clear())}}}(e,this.microAppWindow)),this.initStaticGlobalKeys(this.microAppWindow,e,t,n)}start(e,t=!0,n=""){this.active||(this.active=!0,t?(this.initRouteState(n),this.removeHistoryListener=ct(this.proxyWindow.__MICRO_APP_NAME__)):this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,this.initGlobalKeysWhenStart(this.microAppWindow,this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.__MICRO_APP_URL__),1==++Lt.activeCount&&(qe(),ge(),Fe()),Ee.rawWindow._babelPolyfill&&(Ee.rawWindow._babelPolyfill=!1))}stop(e,t){this.active&&(this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.removeHistoryListener&&(this.clearRouteState(e),this.removeHistoryListener()),t&&Dt(this.proxyWindow.__MICRO_APP_NAME__),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(Ee.rawWindow,e)})),this.escapeKeys.clear(),0==--Lt.activeCount&&(document.addEventListener=Ee.rawDocumentAddEventListener,document.removeEventListener=Ee.rawDocumentRemoveEventListener,be()),this.active=!1)}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=Ue.eventList.get("global");if(n)for(const i of n.callbacks)t===i.__APP_NAME__&&e.umdDataListeners.global.add(i);const i=Ue.eventList.get(Te(t,!0));i&&(e.umdDataListeners.normal=new Set(i.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;this.scopeProperties=this.scopeProperties.concat(this.adapter.staticScopeProperties),_(Kt.plugins)&&(this.commonActionForSpecialProperties(Kt.plugins.global),this.commonActionForSpecialProperties(null===(t=Kt.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(r(e))for(const t of e)_(t)&&(r(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),r(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=Ee.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,i)=>{if(I(e),Reflect.has(n,i)||d(i)&&/^__MICRO_APP_/.test(i)||this.scopeProperties.includes(i))return Reflect.get(n,i);const o=Reflect.get(t,i);return f(o)?$e(t,o):o},set:(e,n,i)=>{if(this.active){if(this.adapter.escapeSetterKeyList.includes(n))Reflect.set(t,n,i);else if(u.call(e,n)||!u.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,i),this.injectedKeys.add(n);else{const o=Object.getOwnPropertyDescriptor(t,n),{configurable:s,enumerable:r,writable:a,set:l}=o;c(e,n,{value:i,configurable:s,enumerable:r,writable:null!=a?a:!!l}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||this.adapter.staticEscapeProperties.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,i),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,i)=>{if(u.call(e,i))return n.set(i,"target"),Object.getOwnPropertyDescriptor(e,i);if(u.call(t,i)){n.set(i,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,i);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,i,o)=>"rawWindow"===n.get(i)?Reflect.defineProperty(t,i,o):Reflect.defineProperty(e,i,o),ownKeys:e=>Reflect.ownKeys(t).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,n)=>!u.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initStaticGlobalKeys(e,t,n,i){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_URL__=n,e.__MICRO_APP_PUBLIC_PATH__=C(n),e.__MICRO_APP_WINDOW__=e,e.rawWindow=Ee.rawWindow,e.rawDocument=Ee.rawDocument,e.microApp=a(new Be(t),{removeDomScope:U,pureCreateElement:T,router:_t}),this.setMappingPropertiesWithRawDescriptor(e),i&&this.setMicroAppRouter(e,t,n)}initGlobalKeysWhenStart(e,t,n){e.hasOwnProperty=t=>u.call(e,t)||u.call(Ee.rawWindow,t),this.setHijackProperties(e,t),this.patchHijackRequest(e,t,n)}setMappingPropertiesWithRawDescriptor(e){let t,n;const i=Ee.rawWindow;i===i.parent?t=n=this.proxyWindow:(t=i.top,n=i.parent),c(e,"top",this.createDescriptorForMicroAppWindow("top",t)),c(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Ot.forEach((t=>{c(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:i=!0,writable:o,set:s}=Object.getOwnPropertyDescriptor(Ee.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:i,writable:null!=o?o:!!s}}setHijackProperties(e,t){let n,i;l(e,{document:{configurable:!0,enumerable:!0,get:()=>(I(t),Ee.rawDocument)},eval:{configurable:!0,enumerable:!1,get:()=>(I(t),n||eval),set:e=>{n=e}},Image:{configurable:!0,enumerable:!1,get:()=>(I(t),i||Ee.ImageProxy),set:e=>{i=e}}})}patchHijackRequest(e,t,n){let i=Ct(n),o=Mt(n),s=St(t,n);l(e,{fetch:{configurable:!0,enumerable:!0,get:()=>i,set(e){i=Ct(n,e)}},XMLHttpRequest:{configurable:!0,enumerable:!0,get:()=>o,set(e){o=Mt(n,e)}},EventSource:{configurable:!0,enumerable:!0,get:()=>s,set(e){s=St(t,n,e)}}})}setMicroAppRouter(e,t,n){const{microLocation:i,microHistory:o}=Rt(t,n);l(e,{location:{configurable:!1,enumerable:!0,get:()=>i,set:e=>{Ee.rawWindow.location=e}},history:{configurable:!0,enumerable:!0,get:()=>o}})}initRouteState(e){!function(e,t,n){const i=st(e);i?Et(e,i,t,"auto"):Pt(e,t,n)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location,e)}clearRouteState(e){!function(e,t,n,i){if(!i){const{pathname:i,search:o,hash:s}=E(t);Et(e,i+o+s,n,"prevent")}Nt(e),gt(e)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.__MICRO_APP_URL__,this.proxyWindow.location,e)}setRouteInfoForKeepAliveApp(){Pt(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location)}removeRouteInfoForKeepAliveApp(){Nt(this.proxyWindow.__MICRO_APP_NAME__)}}function It(e,t,n,i){var o;if(!e)return y(`element does not exist in lifecycle ${n}`,t);e=H(e),U();const s=a({name:t,container:e},i&&{error:i}),r=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(r,e),f(null===(o=Kt.lifeCycles)||void 0===o?void 0:o[n])&&Kt.lifeCycles[n](r),e.dispatchEvent(r)}function xt(e,t,n={}){const i=new CustomEvent(Ge(e,t),{detail:n});window.dispatchEvent(i)}Lt.activeCount=0;const Ut=new Map;class Tt{constructor({name:e,url:t,ssrUrl:n,container:i,inline:o,scopecss:s,useSandbox:r,useMemoryRouter:a,baseroute:c,keepRouteState:l,defaultPage:u}){this.state=Q.CREATED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.sandBox=null,this.container=null!=i?i:null,this.inline=null!=o&&o,this.baseroute=null!=c?c:"",this.keepRouteState=null!=l&&l,this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&s,this.useMemoryRouter=this.useSandbox&&a,this.defaultPage=null!=u?u:"",this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Lt(e,t,this.useMemoryRouter))}loadSourceCode(){var e;this.state=Q.LOADING,X((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),y(t,e.name)}xe(t=t.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(e=>e.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(e=>e.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),e)})).catch((t=>{y(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):Q.UNMOUNT!==this.state&&(this.state=Q.LOADED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),Q.UNMOUNT!==this.state&&(this.onerror(e),this.state=Q.LOAD_FAILED)}mount(e,t,n,i,o){var s,r,a;if(m(t)&&(this.inline=t),m(i)&&(this.keepRouteState=i),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,this.defaultPage=null!=o?o:this.defaultPage,2!==this.loadSourceLevel)return void(this.state=Q.LOADING);let c;if(It(this.container,this.name,q.BEFOREMOUNT),this.state=Q.MOUNTING,W(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute,this.useMemoryRouter,this.defaultPage),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){y("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const i=Array.from(e.entries()),o=[],s=[];for(const[e,r]of i)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?o.push(X(e,t.name)):o.push(r.code),s.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Me(e,t,r,!1),n(!1)));o.length?S(o,(e=>{const t=s[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,y(e,t.name)}),(()=>{s.forEach((([e,i])=>{i.code&&(Me(e,t,i,!1,n),!i.module&&n(!1))})),n(h(n.moduleCount)||n.errorCount===o.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(f(e)&&f(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){y("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){A(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){Q.UNMOUNT!==this.state&&(this.state=Q.MOUNTED,It(this.container,this.name,q.MOUNTED))}unmount(e,t){let n;if(this.state===Q.LOAD_FAILED&&(e=!0),this.state=Q.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){y("an error occurred in the unmount function \n",this.name,e)}xt("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){A(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&W(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(this.keepRouteState&&!e,!this.umdMode||e),Ht().length||(ye=!1,Element.prototype.setAttribute=Ee.rawSetAttribute),It(this.container,this.name,q.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Ut.delete(this.name)}hiddenKeepAliveApp(){var e;const t=this.container;W(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=z.KEEP_ALIVE_HIDDEN,xt("appstate-change",this.name,{appState:"afterhidden"}),It(t,this.name,q.AFTERHIDDEN),null===(e=this.sandBox)||void 0===e||e.removeRouteInfoForKeepAliveApp()}showKeepAliveApp(e){var t;xt("appstate-change",this.name,{appState:"beforeshow"}),It(e,this.name,q.BEFORESHOW),W(this.container,e,!1),this.container=e,this.keepAliveState=z.KEEP_ALIVE_SHOW,null===(t=this.sandBox)||void 0===t||t.setRouteInfoForKeepAliveApp(),xt("appstate-change",this.name,{appState:"aftershow"}),It(this.container,this.name,q.AFTERSHOW)}onerror(e){It(this.container,this.name,q.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(Q.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:Ee.rawWindow;return this.libraryName=H(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Wt(e){class n extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=N(this.getAttribute("name")),t=P(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Ut.get(e);if(e!==this.appName&&n&&Q.UNMOUNT!==n.getAppState()&&z.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),y(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},ye||(ye=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(_(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{d(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&b("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ut.has(this.__MICRO_APP_NAME__)){const n=Ut.get(this.__MICRO_APP_NAME__);Ee.rawSetAttribute.call(this,e,M(t,n.url))}else Ee.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,v((()=>It(this,this.appName,q.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1;const e=Ut.get(this.appName);e&&e.getAppState()!==Q.UNMOUNT&&e.getKeepAliveState()!==z.KEEP_ALIVE_HIDDEN&&(this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult()))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===V.NAME?"appName":"appUrl"]!==n)if(e!==V.URL||this.appUrl)if(e!==V.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,v(this.handleAttributeUpdate));else{const e=N(n);if(!e)return y(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Kt.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=P(n,this.appName)))return y(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&f(this.attachShadow)&&this.attachShadow({mode:"open"}),this.updateSsrUrl(this.appUrl),Ut.has(this.appName)){const e=Ut.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==Q.UNMOUNT?e.isPrefetch||e.getAppState()===Q.UNMOUNT?(b(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):y(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var i;this.updateSsrUrl(t),this.appName=e,this.appUrl=t,(null!==(i=this.shadowRoot)&&void 0!==i?i:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):y(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!d(t)||!t)||(y(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,v((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible(),this.getDisposeResult("keep-router-state"),this.getDefaultPageValue())}))}handleCreateApp(){var e;Ut.has(this.appName)&&Ut.get(this.appName).actionsForCompletelyDestroy();const t=new Tt({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),useMemoryRouter:!this.getDisposeResult("disable-memory-router"),baseroute:this.getBaseRouteCompatible(),keepRouteState:this.getDisposeResult("keep-router-state"),defaultPage:this.getDefaultPageValue()});Ut.set(this.appName,t)}handleUnmount(e,t){const n=Ut.get(this.appName);n&&n.getAppState()!==Q.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Ut.get(this.appName);e&&e.getAppState()!==Q.UNMOUNT&&e.getKeepAliveState()!==z.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){v((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Kt[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}updateSsrUrl(e){if(this.getDisposeResult("ssr"))if(this.getDisposeResult("disable-memory-router")){const t=Ee.rawWindow.location;this.ssrUrl=M(t.pathname+t.search,e)}else{let t=function(e,t){const n=st(e);if(!n)return"";const i=E(n,t);return i.origin+i.pathname+i.search}(this.appName,e);const n=this.getDefaultPageValue();if(!t&&n){const i=E(n,e);t=i.origin+i.pathname+i.search}this.ssrUrl=t}else this.ssrUrl&&(this.ssrUrl="")}getDefaultPageValue(){var e,t,n;return null!==(n=null!==(t=null!==(e=_t.getDefaultPage(this.appName))&&void 0!==e?e:this.getAttribute("default-page"))&&void 0!==t?t:this.getAttribute("defaultPage"))&&void 0!==n?n:""}set data(e){this.appName?Kt.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Kt.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function kt(e){if(!n)return y("preFetch is only supported in browser environment");D((()=>{f(e)&&(e=e()),r(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{D((()=>{var n,i,o;if(_(e)&&navigator.onLine)if(e.name=N(e.name),e.url=P(e.url,e.name),e.name&&e.url&&!Ut.has(e.name)){const s=new Tt({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Kt.disableScopecss),useSandbox:!(null!==(i=e.disableSandbox)&&void 0!==i?i:Kt.disableSandbox),useMemoryRouter:!(null!==(o=e.disableMemoryRouter)&&void 0!==o?o:Kt.disableMemoryRouter)});s.isPrefetch=!0,s.prefetchResolve=t,Ut.set(e.name,s)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Bt(e,t,n){if(r(e)){const i=e.filter((e=>d(e)&&e.includes(`.${t}`)&&!n.has(e)));S(i.map((e=>X(e))),(e=>{const t=i[e.index];n.has(t)||n.set(t,e.data)}),(e=>{y(e)}))}}function Ht(e){const t=[];return Ut.forEach(((n,i)=>{Q.UNMOUNT===n.getAppState()||n.isPrefetch||e&&z.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(i)})),t}function Ft(e,t){const n=Ut.get(N(e));return new Promise((i=>{if(n)if(n.getAppState()===Q.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),i();else if(n.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,i):(null==t?void 0:t.clearAliveState)?n.unmount(!1,i):i();else{const e=H(n.container),o=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",s),i()},s=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",s),i()};if(e.addEventListener("unmount",o),e.addEventListener("afterhidden",s),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else b(`app ${e} does not exist`),i()}))}class $t extends ke{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=kt,this.router=_t}start(e){if(!n||!window.customElements)return y("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return y(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return b(`element ${this.tagName} is already defined`);if(Re(),e&&_(e)&&(this.shadowDOM=e.shadowDOM,this.destroy=e.destroy,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.disableMemoryRouter=e.disableMemoryRouter,this.ssr=e.ssr,f(e.fetch)&&(this.fetch=e.fetch),_(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&kt(e.preFetchApps),e.globalAssets&&(_(t=e.globalAssets)&&D((()=>{Bt(t.js,"js",Pe),Bt(t.css,"css",ce)}))),_(e.plugins))){const t=e.plugins.modules;if(_(t))for(const e in t){const n=N(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Wt(this.tagName)}}var Kt=new $t;e.EventCenterForMicroApp=Be,e.MicroApp=$t,e.default=Kt,e.getActiveApps=Ht,e.getAllApps=function(){return Array.from(Ut.keys())},e.preFetch=kt,e.pureCreateElement=T,e.removeDomScope=U,e.unmountAllApps=function(e){return Array.from(Ut.keys()).reduce(((t,n)=>t.then((()=>Ft(n,e)))),Promise.resolve())},e.unmountApp=Ft,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=index.umd.js.map