Socket
Socket
Sign inDemoInstall

@micro-zoe/micro-app

Package Overview
Dependencies
0
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.7 to 0.8.8

2

lib/index.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function s(e){return"boolean"==typeof e}function i(e){return"function"==typeof e}const r=Array.isArray;function o(e){return"[object Object]"===toString.call(e)}function a(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const l=Object.defineProperty,u=Object.defineProperties,h=Object.prototype.hasOwnProperty;function p(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${i} ${e}`,...s):console.error(`[micro-app]${i}`,e,...s)}function d(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${i} ${e}`,...s):console.warn(`[micro-app]${i}`,e,...s)}function m(e,...t){Promise.resolve().then(e.bind(null,...t))}function f(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function _(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(f(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return p(e,t),""}}function A(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function b(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 g(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,b(f(t))).toString()}function w(e,t,n,s){let i=0;function r(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{a(e)?e.then((e=>{t({data:e,index:s}),r()})).catch((e=>{n({error:e,index:s}),r()})):(t({data:e,index:s}),r())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let E=null;function v(e){E=e}function N(e){E!==e&&(v(e),m((()=>{v(null)})))}function C(){return E}function R(){v(null)}function D(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function P(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 M(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function O(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function S(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function I(e){return e?e.replace(/^\s+|\s+$/g,""):""}function L(){return navigator.userAgent.indexOf("Firefox")>-1}var x,U,T,k;!function(e){e.NAME="name",e.URL="url"}(x||(x={})),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"}(U||(U={})),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"}(T||(T={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(k||(k={}));const W="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 $(e,t=null,n={}){return i(tt.fetch)?tt.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}class B{static getInstance(){return this.instance||(this.instance=new B),this.instance}run(e,t){const n=e.name,s=e.ssrUrl||e.url;$(s,n,{cache:"no-cache"}).then((i=>{if(!i){const t="html is empty, please check in detail";return e.onerror(new Error(t)),p(t,n)}i=this.formatHTML(s,i,n),t(i,e)})).catch((t=>{p(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n,t),e.onLoadError(t)}))}formatHTML(e,t,n){return this.processHtml(e,t,n,tt.plugins).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>")))}processHtml(e,t,n,s){var r;if(!s)return t;const a=[];return s.global&&a.push(...s.global),(null===(r=s.modules)||void 0===r?void 0:r[n])&&a.push(...s.modules[n]),a.length>0?a.reduce(((t,n)=>o(n)&&i(n.processHtml)?n.processHtml(t,e,n.options):t),t):t}}const F=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,H=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function K(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class j{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(),L()?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):K("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=I(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||F.test(n)||(n=H.test(n)?n.replace(H,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||K("Declaration missing '}'",this.linkPath)):K("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(),f(t.join("/")+"/")}(this.linkPath)),`url("${g(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 K("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return K("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):K("@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):K(`@${t} missing '}'`,this.linkPath)):K(`@${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):K(`@${e} missing '}'`,this.linkPath)):K(`@${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 K("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=I(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(I(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){L()?this.result+=encodeURIComponent(e):this.result+=e}}function G(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let r=null;try{r=V.exec(e.textContent,n,s,i),V.reset()}catch(e){V.reset(),p("An error occurred while parsing CSS:\n",t,e)}r&&(e.textContent=r)}}let V;function q(e,t){if(t.scopecss){const n=`${tt.tagName}[name=${t.name}]`;if(V||(V=new j),e.textContent)G(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")&&G(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function z(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function Q(e){const t=new CustomEvent("load");z(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function J(e){const t=new CustomEvent("error");z(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const X=new Map;function Y(e,t,n,s=!1){const i=e.getAttribute("rel");let r=e.getAttribute("href"),o=null;if("stylesheet"===i&&r){if(r=g(r,n.url),s)return{url:r,info:{code:"",isGlobal:e.hasAttribute("global")}};o=document.createComment(`link element with href=${r} move to micro-app-head as style element`),n.source.links.set(r,{code:"",placeholder:o,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?o=document.createComment(`link element with rel=${i}${r?" & href="+r:""} removed by micro-app`):t.removeChild(e):r&&e.setAttribute("href",g(r,n.url));return s?{replaceComment:o}:o?t.replaceChild(o,e):void 0}function Z(e,t,n){const s=Array.from(t.source.links.entries());w(s.map((([e])=>X.has(e)?X.get(e):$(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!X.has(e)&&X.set(e,n);const r=D("style");r.textContent=n,r.__MICRO_APP_LINK_PATH__=e,r.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(q(r,i),t.placeholder):s.appendChild(q(r,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)}))}const ee=new WeakMap;function te(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 ee.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?q(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")||ge(t.getAttribute("href"),n.name)){const e=document.createComment("link element with exclude attribute ignored by micro-app");return ee.set(t,e),e}if(t.hasAttribute("ignore")||we(t.getAttribute("href"),n.name))return t;const{url:s,info:i,replaceComment:r}=Y(t,e,n,!0);if(s&&i){const e=D("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,q(i,n),void m((()=>Q(s)));if(X.has(e)){const r=X.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,q(i,n),void m((()=>Q(s)))}$(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&X.set(e,r),i.textContent=r,q(i,n),Q(s)})).catch((e=>{p(e,n.name),J(s)}))}(s,i,n,t,e),ee.set(t,e),e}return r?(ee.set(t,r),r):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:r}=Ae(t,e,n,!0)||{};if(i&&r){if(r.isExternal){const e=function(e,t,n,s){const i=()=>Q(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&m(i),Ee(e,n,t,!0,i)}if(_e.has(e)){const s=_e.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&m(i),Ee(e,n,t,!0,i)}let r;r=n.inline||t.module?D("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return $(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&_e.set(e,o);try{o=Ce(e,n,o,t),n.inline||t.module?ve(e,o,t.module,r,i):Ne(o,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&Q(s)})).catch((e=>{p(e,n.name),J(s)})),r}(i,r,n,t);return ee.set(t,e),e}{const e=Ee(i,n,r,!0);return ee.set(t,e),e}}return s?(ee.set(t,s),s):t}return t}function ne(e,t,n,s,i){const r=function(e,t){var n,s;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===(s=null==t?void 0:t.container)||void 0===s?void 0:s.querySelector("micro-app-body");return null}(n,e);return r?i&&!r.contains(i)?me.rawAppendChild.call(r,s):t!==me.rawRemoveChild||r.contains(s)?se(t,r,s,i):n.contains(s)?t.call(n,s):s:se(t,n,s,i)}function se(e,t,n,s){return(i=e)===me.rawAppend||i===me.rawPrepend?e.call(t,n):e.call(t,n,s);var i}function ie(e){var t;return null!==(t=ee.get(e))&&void 0!==t?t:e}function re(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=qe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ne(i,s,e,te(e,t,i),n&&ie(n)):s===me.rawAppend||s===me.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===me.rawAppend||s===me.rawPrepend){const n=C();if(!(t instanceof Node)&&n){const i=qe.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 oe(){!function(){const e=me.rawDocument;function t(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:me.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:me.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ae(me.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ae(me.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ae(me.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!C()||M(e))return me.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return me.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!C()||M(e))return me.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return me.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=C();if(!s||O(e)||M(e)||!(null===(t=qe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return me.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return me.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!C()||M(e))return me.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return me.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return re(this,e,null,me.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return re(this,e,t,me.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return re(this,e,t,me.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)re(this,e[t],null,me.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)re(this,e[t-1],null,me.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=qe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ne(t,me.rawRemoveChild,this,ie(e)):me.rawRemoveChild.call(this,e)}return me.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=me.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ae(e){const t=C();return t&&(e.__MICRO_APP_NAME__=t),e}let ce=!1;function le(){v(null),Document.prototype.createElement=me.rawCreateElement,Document.prototype.createElementNS=me.rawCreateElementNS,Document.prototype.createDocumentFragment=me.rawCreateDocumentFragment,Document.prototype.querySelector=me.rawQuerySelector,Document.prototype.querySelectorAll=me.rawQuerySelectorAll,Document.prototype.getElementById=me.rawGetElementById,Document.prototype.getElementsByClassName=me.rawGetElementsByClassName,Document.prototype.getElementsByTagName=me.rawGetElementsByTagName,Document.prototype.getElementsByName=me.rawGetElementsByName,Element.prototype.appendChild=me.rawAppendChild,Element.prototype.insertBefore=me.rawInsertBefore,Element.prototype.replaceChild=me.rawReplaceChild,Element.prototype.removeChild=me.rawRemoveChild,Element.prototype.append=me.rawAppend,Element.prototype.prepend=me.rawPrepend,Element.prototype.cloneNode=me.rawCloneNode}let ue=!1;class he{constructor(){this.appInstanceMap=qe}static getInstance(){return this.instance||(this.instance=new he),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,t){this.appInstanceMap.set(e,t)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function pe(){de(),he.getInstance().getAll().forEach((e=>{e.container&&S(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&he.getInstance().clear()}function de(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",pe,!1)}const me={};function fe(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,r=Element.prototype.append,o=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,h=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__=C(),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,R=b.clearInterval,P=b.clearTimeout,M=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(me,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:r,rawPrepend:o,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:u,rawQuerySelector:h,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:R,rawClearTimeout:P,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:O}),function(){if(!ue){ue=!0;const e=D("style");me.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${tt.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,me.rawDocument.head.appendChild(e)}}(),de(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",pe,!1)}}const _e=new Map;function Ae(e,t,n,s=!1){let i=null,r=e.getAttribute("src");if(r&&(r=g(r,n.url)),e.hasAttribute("exclude")||ge(r,n.name))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")||we(r,n.name))return null;if(me.supportModuleScript&&e.noModule||!me.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){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:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:r};n.source.scripts.set(t,r),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 be(e){var t,n,s;return[...(null===(t=tt.plugins)||void 0===t?void 0:t.global)||[],...(null===(s=null===(n=tt.plugins)||void 0===n?void 0:n.modules)||void 0===s?void 0:s[e])||[]]}function ge(e,t){if(!e)return!1;return(be(t)||[]).some((t=>!!t.excludeChecker&&t.excludeChecker(e)))}function we(e,t){if(!e)return!1;return(be(t)||[]).some((t=>!!t.ignoreChecker&&t.ignoreChecker(e)))}function ye(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=_e.get(e);n?r.code=n:(!r.defer&&!r.async||t.isPrefetch)&&(s.push($(e,t.name)),i.push([e,r]))}s.length?w(s,(e=>{!function(e,t,n){t.isGlobal&&!_e.has(e)&&_e.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Ee(e,t,n,s,i){var r;try{const o=Ce(e,t,n.code,n);if(t.inline||n.module){const a=D("script");if(ve(e,o,n.module,a,i),s)return a;null===(r=t.container)||void 0===r||r.querySelector("micro-app-body").appendChild(a)}else if(Ne(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ve(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 Ne(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function Ce(e,t,n,s){return o(tt.plugins)&&(n=function(e,t,n,s,i){var r;const o=Re(s.global,t,e,i);return Re(null===(r=s.modules)||void 0===r?void 0:r[n],o,e,i)}(e,n,t.name,tt.plugins,s)),t.sandBox&&!s.module?(me.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${W}){;${n}\n}).call(proxyWindow,${W})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Re(e,t,n,s){return r(e)?e.reduce(((e,t)=>o(t)&&i(t.loader)?t.loader(e,n,t.options,s):e),t):t}function De(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{De(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")||ge(n.getAttribute("href"),t.name)?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")||we(n.getAttribute("href"),t.name)?n.hasAttribute("href")&&n.setAttribute("href",g(n.getAttribute("href"),t.url)):Y(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")&&q(n,t):n instanceof HTMLScriptElement?Ae(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",g(n.getAttribute("src"),t.url))}function Pe(e,t){const n=function(e){const t=D("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)),p(e,t.name)}De(n,t),t.source.links.size?Z(n,t,s):t.onLoad(n),t.source.scripts.size?ye(n,t):t.onLoad(n)}const Me=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(p("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return p("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&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!o(t))return p("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 Oe(e,t){return n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Se{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Me.on("global",e,t)}removeGlobalDataListener(e){i(e)&&Me.off("global",e)}setGlobalData(e){R(),Me.dispatch("global",e)}getGlobalData(){return Me.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Me.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 Ie extends Se{addDataListener(e,t,n){Me.on(Oe(A(e),!1),t,n)}removeDataListener(e,t){i(t)&&Me.off(Oe(A(e),!1),t)}getData(e,t=!1){return Me.getData(Oe(A(e),t))}setData(e,t){Me.dispatch(Oe(A(e),!0),t)}clearDataListener(e){Me.off(Oe(A(e),!1))}}class Le extends Se{constructor(e){super(),this.appName=A(e),!this.appName&&p(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Me.on(Oe(this.appName,!0),e,t)}removeDataListener(e){i(e)&&Me.off(Oe(this.appName,!0),e)}getData(){return Me.getData(Oe(this.appName,!0))}dispatch(e){R(),Me.dispatch(Oe(this.appName,!1),e);const t=qe.get(this.appName);if((null==t?void 0:t.container)&&o(e)){const n=new CustomEvent("datachange",{detail:{data:e}});S(t.container).dispatchEvent(n)}}clearDataListener(){Me.off(Oe(this.appName,!0))}}function xe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(s(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 s(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=c(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&l(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Ue=new Map;let Te=!1;const ke=new Map;function We(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=me;!Te&&function(){if(Te=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return d("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Ue.forEach((t=>{i(t)&&t.call(document,e)}))}l(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=C();return e?Ue.get(e):Ue.get("base")},set(e){const s=C();s?Ue.set(s,e):Ue.set("base",e),!t&&i(e)&&(t=!0,me.rawDocumentAddEventListener.call(me.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var r;const o=C();if(o&&(!(null===(r=qe.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=ke.get(o);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else ke.set(o,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 r;const o=C();if(o&&(!(null===(r=qe.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=ke.get(o);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 $e=["unmount","appstate-change"];function Be(e,t){return $e.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Fe=["System","__cjsWrapper"],He=["location"],Ke=["window","self","globalThis"];class je{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:r,rawDocument:o,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=me;e.addEventListener=function(t,s,i){t=Be(t,e);const o=n.get(t);o?o.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(r,t,s,i)},e.removeEventListener=function(t,s,i){t=Be(t,e);const o=n.get(t);(null==o?void 0:o.size)&&o.has(s)&&o.delete(s),c.call(r,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(r,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=u.call(r,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),h.call(r,e)},e.clearTimeout=function(e){i.delete(e),p.call(r,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)),_=Ue.get(t);const e=ke.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)})),_&&Ue.set(t,_),v(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),v(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(r,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{h.call(r,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(r,t)})),i.clear()),Ue.delete(t);const e=ke.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(o,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,me.rawWindow._babelPolyfill&&(me.rawWindow._babelPolyfill=!1),1==++je.activeCount&&(We(),oe()))}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(me.rawWindow,e)})),this.escapeKeys.clear(),0==--je.activeCount&&(document.addEventListener=me.rawDocumentAddEventListener,document.removeEventListener=me.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=Me.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Me.eventList.get(Oe(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;o(tt.plugins)&&(this.commonActionForSpecialProperties(tt.plugins.global),this.commonActionForSpecialProperties(null===(t=tt.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(r(e))for(const t of e)o(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=me.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(s,r)=>{if(N(e),Reflect.has(s,r)||n(r)&&/^__MICRO_APP_/.test(r)||this.scopeProperties.includes(r))return Reflect.get(s,r);const o=Reflect.get(t,r);return i(o)?xe(t,o):o},set:(e,n,s)=>{if(this.active){if(He.includes(n))Reflect.set(t,n,s);else if(h.call(e,n)||!h.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:r,enumerable:o,writable:a,set:c}=i;l(e,n,{value:s,configurable:r,enumerable:o,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||Fe.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,n)=>{if(h.call(e,n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(h.call(t,n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,i)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,i):Reflect.defineProperty(e,n,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)=>!h.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__=b(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Le(t),{removeDomScope:R,pureCreateElement:D}),e.rawWindow=me.rawWindow,e.rawDocument=me.rawDocument,e.hasOwnProperty=t=>h.call(e,t)||h.call(me.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=me.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),l(e,"top",this.createDescriptorForMicroAppWindow("top",t)),l(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Ke.forEach((t=>{l(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:r}=Object.getOwnPropertyDescriptor(me.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!r}}setHijackProperties(e,t){let n,s;u(e,{document:{get:()=>(N(t),me.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(N(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(N(t),s||me.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Ge(e,t,n,s){var r;if(!e)return p(`element does not exist in lifecycle ${n}`,t);e=S(e),R();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),i(null===(r=tt.lifeCycles)||void 0===r?void 0:r[n])&&tt.lifeCycles[n](a),e.dispatchEvent(a)}function Ve(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}je.activeCount=0;const qe=new Map;class ze{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:r,useSandbox:o,baseroute:a}){this.state=U.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=o,this.scopecss=this.useSandbox&&r,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new je(e,t))}loadSourceCode(){this.state=U.LOADING_SOURCE_CODE,B.getInstance().run(this,Pe)}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):U.UNMOUNT!==this.state&&(this.state=U.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),U.UNMOUNT!==this.state&&(this.onerror(e),this.state=U.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,o,a;if(s(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(r=this.container)&&void 0!==r?r:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=U.LOADING_SOURCE_CODE);let c;if(Ge(this.container,this.name,T.BEFOREMOUNT),this.state=U.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(o=this.sandBox)||void 0===o||o.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("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=[],r=[];for(const[e,o]of s)o.isDynamic||(o.defer||o.async?(o.isExternal&&!o.code?i.push($(e,t.name)):i.push(o.code),r.push([e,o]),o.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ee(e,t,o,!1),n(!1)));i.length?w(i,(e=>{const t=r[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,p(e,t.name)}),(()=>{r.forEach((([e,s])=>{s.code&&(Ee(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(i(e)&&i(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){p("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(){U.UNMOUNT!==this.state&&(this.state=U.MOUNTED,Ge(this.container,this.name,T.MOUNTED))}unmount(e,t){let n;if(this.state===U.LOAD_SOURCE_ERROR&&(e=!0),this.state=U.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){p("an error occurred in the unmount function \n",this.name,e)}Ve("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&&P(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),Ye().length||(ce=!1,Element.prototype.setAttribute=me.rawSetAttribute),Ge(this.container,this.name,T.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],qe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;P(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=k.KEEP_ALIVE_HIDDEN,Ve("appstate-change",this.name,{appState:"afterhidden"}),Ge(e,this.name,T.AFTERHIDDEN)}showKeepAliveApp(e){Ve("appstate-change",this.name,{appState:"beforeshow"}),Ge(e,this.name,T.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=k.KEEP_ALIVE_SHOW,Ve("appstate-change",this.name,{appState:"aftershow"}),Ge(this.container,this.name,T.AFTERSHOW)}onerror(e){Ge(this.container,this.name,T.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(U.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:me.rawWindow;return this.libraryName=S(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Qe(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.8.7",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=A(this.getAttribute("name")),t=_(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=qe.get(e);if(e!==this.appName&&n&&U.UNMOUNT!==n.getAppState()&&k.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),p(`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(o(t)){const e={};Object.getOwnPropertyNames(t).forEach((s=>{n(s)&&0===s.indexOf("__")||(e[s]=t[s])})),this.data=e}else"[object Object]"!==t&&d("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__&&qe.has(this.__MICRO_APP_NAME__)){const n=qe.get(this.__MICRO_APP_NAME__);me.rawSetAttribute.call(this,e,g(t,n.url))}else me.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,m((()=>Ge(this,this.appName,T.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===x.NAME?"appName":"appUrl"]!==n)if(e!==x.URL||this.appUrl)if(e!==x.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,m(this.handleAttributeUpdate));else{const e=A(n);if(!e)return p(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(tt.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=_(n,this.appName)))return p(`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&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=g(me.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),qe.has(this.appName)){const e=qe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==U.UNMOUNT?e.isPrefetch||e.getAppState()===U.UNMOUNT?(d(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):p(`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=g(me.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()===k.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):p(`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!(!n(t)||!t)||(p(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,m((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;qe.has(this.appName)&&qe.get(this.appName).actionsForCompletelyDestroy();const t=new ze({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()});qe.set(this.appName,t)}handleUnmount(e,t){const n=qe.get(this.appName);n&&n.getAppState()!==U.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=qe.get(this.appName);e&&e.getAppState()!==U.UNMOUNT&&e.getKeepAliveState()!==k.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){m((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||tt[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?tt.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?tt.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function Je(t){if(!e)return p("preFetch is only supported in browser environment");y((()=>{i(t)&&(t=t()),r(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{y((()=>{var n,s;if(o(e)&&navigator.onLine)if(e.name=A(e.name),e.url=_(e.url,e.name),e.name&&e.url&&!qe.has(e.name)){const i=new ze({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:tt.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:tt.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,qe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Xe(e,t,s){if(r(e)){const i=e.filter((e=>n(e)&&e.includes(`.${t}`)&&!s.has(e)));w(i.map((e=>$(e))),(e=>{const t=i[e.index];s.has(t)||s.set(t,e.data)}),(e=>{p(e)}))}}function Ye(e){const t=[];return qe.forEach(((n,s)=>{U.UNMOUNT===n.getAppState()||n.isPrefetch||e&&k.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Ze(e,t){const n=qe.get(A(e));return new Promise((s=>{if(n)if(n.getAppState()===U.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===k.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=S(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()},r=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",r),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 d(`app ${e} does not exist`),s()}))}class et extends Ie{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Je}start(t){if(!e||!window.customElements)return p("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return p(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return d(`element ${this.tagName} is already defined`);if(fe(),t&&o(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.ssr=t.ssr,i(t.fetch)&&(this.fetch=t.fetch),o(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&Je(t.preFetchApps),t.globalAssets&&(o(n=t.globalAssets)&&y((()=>{Xe(n.js,"js",_e),Xe(n.css,"css",X)}))),o(t.plugins))){const e=t.plugins.modules;if(o(e))for(const t in e){const n=A(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;Qe(this.tagName)}}var tt=new et;exports.EventCenterForMicroApp=Le,exports.MicroApp=et,exports.default=tt,exports.getActiveApps=Ye,exports.getAllApps=function(){return Array.from(qe.keys())},exports.preFetch=Je,exports.pureCreateElement=D,exports.removeDomScope=R,exports.unmountAllApps=function(e){return Array.from(qe.keys()).reduce(((t,n)=>t.then((()=>Ze(n,e)))),Promise.resolve())},exports.unmountApp=Ze,exports.version="0.8.7";
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function s(e){return"boolean"==typeof e}function i(e){return"function"==typeof e}const r=Array.isArray;function o(e){return"[object Object]"===toString.call(e)}function a(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const l=Object.defineProperty,u=Object.defineProperties,h=Object.prototype.hasOwnProperty;function p(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${i} ${e}`,...s):console.error(`[micro-app]${i}`,e,...s)}function d(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${i} ${e}`,...s):console.warn(`[micro-app]${i}`,e,...s)}function m(e,...t){Promise.resolve().then(e.bind(null,...t))}function f(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function _(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(f(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return p(e,t),""}}function A(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function b(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 g(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,b(f(t))).toString()}function w(e,t,n,s){let i=0;function r(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{a(e)?e.then((e=>{t({data:e,index:s}),r()})).catch((e=>{n({error:e,index:s}),r()})):(t({data:e,index:s}),r())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let E=null;function v(e){E=e}function N(e){E!==e&&(v(e),m((()=>{v(null)})))}function C(){return E}function R(){v(null)}function D(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function P(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 M(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function O(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function S(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function I(e){return e?e.replace(/^\s+|\s+$/g,""):""}function L(){return navigator.userAgent.indexOf("Firefox")>-1}var x,U,T,k;!function(e){e.NAME="name",e.URL="url"}(x||(x={})),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"}(U||(U={})),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"}(T||(T={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(k||(k={}));const W="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 $(e,t=null,n={}){return i(tt.fetch)?tt.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}class B{static getInstance(){return this.instance||(this.instance=new B),this.instance}run(e,t){const n=e.name,s=e.ssrUrl||e.url;$(s,n,{cache:"no-cache"}).then((i=>{if(!i){const t="html is empty, please check in detail";return e.onerror(new Error(t)),p(t,n)}i=this.formatHTML(s,i,n),t(i,e)})).catch((t=>{p(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n,t),e.onLoadError(t)}))}formatHTML(e,t,n){return this.processHtml(e,t,n,tt.plugins).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>")))}processHtml(e,t,n,s){var r;if(!s)return t;const a=[];return s.global&&a.push(...s.global),(null===(r=s.modules)||void 0===r?void 0:r[n])&&a.push(...s.modules[n]),a.length>0?a.reduce(((t,n)=>o(n)&&i(n.processHtml)?n.processHtml(t,e,n.options):t),t):t}}const F=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,H=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function K(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class j{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(),L()?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):K("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=I(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||F.test(n)||(n=H.test(n)?n.replace(H,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||K("Declaration missing '}'",this.linkPath)):K("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(),f(t.join("/")+"/")}(this.linkPath)),`url("${g(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 K("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return K("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):K("@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):K(`@${t} missing '}'`,this.linkPath)):K(`@${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):K(`@${e} missing '}'`,this.linkPath)):K(`@${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 K("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=I(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(I(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){L()?this.result+=encodeURIComponent(e):this.result+=e}}function G(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let r=null;try{r=V.exec(e.textContent,n,s,i),V.reset()}catch(e){V.reset(),p("An error occurred while parsing CSS:\n",t,e)}r&&(e.textContent=r)}}let V;function q(e,t){if(t.scopecss){const n=`${tt.tagName}[name=${t.name}]`;if(V||(V=new j),e.textContent)G(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")&&G(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function z(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function Q(e){const t=new CustomEvent("load");z(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function J(e){const t=new CustomEvent("error");z(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const X=new Map;function Y(e,t,n,s=!1){const i=e.getAttribute("rel");let r=e.getAttribute("href"),o=null;if("stylesheet"===i&&r){if(r=g(r,n.url),s)return{url:r,info:{code:"",isGlobal:e.hasAttribute("global")}};o=document.createComment(`link element with href=${r} move to micro-app-head as style element`),n.source.links.set(r,{code:"",placeholder:o,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?o=document.createComment(`link element with rel=${i}${r?" & href="+r:""} removed by micro-app`):t.removeChild(e):r&&e.setAttribute("href",g(r,n.url));return s?{replaceComment:o}:o?t.replaceChild(o,e):void 0}function Z(e,t,n){const s=Array.from(t.source.links.entries());w(s.map((([e])=>X.has(e)?X.get(e):$(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!X.has(e)&&X.set(e,n);const r=D("style");r.textContent=n,r.__MICRO_APP_LINK_PATH__=e,r.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(q(r,i),t.placeholder):s.appendChild(q(r,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)}))}const ee=new WeakMap;function te(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 ee.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?q(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")||ge(t.getAttribute("href"),n.name)){const e=document.createComment("link element with exclude attribute ignored by micro-app");return ee.set(t,e),e}if(t.hasAttribute("ignore")||we(t.getAttribute("href"),n.name))return t;const{url:s,info:i,replaceComment:r}=Y(t,e,n,!0);if(s&&i){const e=D("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,q(i,n),void m((()=>Q(s)));if(X.has(e)){const r=X.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,q(i,n),void m((()=>Q(s)))}$(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&X.set(e,r),i.textContent=r,q(i,n),Q(s)})).catch((e=>{p(e,n.name),J(s)}))}(s,i,n,t,e),ee.set(t,e),e}return r?(ee.set(t,r),r):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:r}=Ae(t,e,n,!0)||{};if(i&&r){if(r.isExternal){const e=function(e,t,n,s){const i=()=>Q(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&m(i),Ee(e,n,t,!0,i)}if(_e.has(e)){const s=_e.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&m(i),Ee(e,n,t,!0,i)}let r;r=n.inline||t.module?D("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return $(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&_e.set(e,o);try{o=Ce(e,n,o,t),n.inline||t.module?ve(e,o,t.module,r,i):Ne(o,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&Q(s)})).catch((e=>{p(e,n.name),J(s)})),r}(i,r,n,t);return ee.set(t,e),e}{const e=Ee(i,n,r,!0);return ee.set(t,e),e}}return s?(ee.set(t,s),s):t}return t}function ne(e,t,n,s,i){const r=function(e,t){var n,s;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===(s=null==t?void 0:t.container)||void 0===s?void 0:s.querySelector("micro-app-body");return null}(n,e);return r?i&&!r.contains(i)?me.rawAppendChild.call(r,s):t!==me.rawRemoveChild||r.contains(s)?se(t,r,s,i):n.contains(s)?t.call(n,s):s:se(t,n,s,i)}function se(e,t,n,s){return(i=e)===me.rawAppend||i===me.rawPrepend?e.call(t,n):e.call(t,n,s);var i}function ie(e){var t;return null!==(t=ee.get(e))&&void 0!==t?t:e}function re(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=qe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ne(i,s,e,te(e,t,i),n&&ie(n)):s===me.rawAppend||s===me.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===me.rawAppend||s===me.rawPrepend){const n=C();if(!(t instanceof Node)&&n){const i=qe.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 oe(){!function(){const e=me.rawDocument;function t(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:me.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:me.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ae(me.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ae(me.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ae(me.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!C()||M(e))return me.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return me.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!C()||M(e))return me.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return me.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=C();if(!s||O(e)||M(e)||!(null===(t=qe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return me.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return me.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!C()||M(e))return me.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return me.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return re(this,e,null,me.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return re(this,e,t,me.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return re(this,e,t,me.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)re(this,e[t],null,me.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)re(this,e[t-1],null,me.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=qe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ne(t,me.rawRemoveChild,this,ie(e)):me.rawRemoveChild.call(this,e)}return me.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=me.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ae(e){const t=C();return t&&(e.__MICRO_APP_NAME__=t),e}let ce=!1;function le(){v(null),Document.prototype.createElement=me.rawCreateElement,Document.prototype.createElementNS=me.rawCreateElementNS,Document.prototype.createDocumentFragment=me.rawCreateDocumentFragment,Document.prototype.querySelector=me.rawQuerySelector,Document.prototype.querySelectorAll=me.rawQuerySelectorAll,Document.prototype.getElementById=me.rawGetElementById,Document.prototype.getElementsByClassName=me.rawGetElementsByClassName,Document.prototype.getElementsByTagName=me.rawGetElementsByTagName,Document.prototype.getElementsByName=me.rawGetElementsByName,Element.prototype.appendChild=me.rawAppendChild,Element.prototype.insertBefore=me.rawInsertBefore,Element.prototype.replaceChild=me.rawReplaceChild,Element.prototype.removeChild=me.rawRemoveChild,Element.prototype.append=me.rawAppend,Element.prototype.prepend=me.rawPrepend,Element.prototype.cloneNode=me.rawCloneNode}let ue=!1;class he{constructor(){this.appInstanceMap=qe}static getInstance(){return this.instance||(this.instance=new he),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,t){this.appInstanceMap.set(e,t)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function pe(){de(),he.getInstance().getAll().forEach((e=>{e.container&&S(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&he.getInstance().clear()}function de(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",pe,!1)}const me={};function fe(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,r=Element.prototype.append,o=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,h=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__=C(),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,R=b.clearInterval,P=b.clearTimeout,M=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(me,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:r,rawPrepend:o,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:u,rawQuerySelector:h,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:R,rawClearTimeout:P,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:O}),function(){if(!ue){ue=!0;const e=D("style");me.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${tt.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,me.rawDocument.head.appendChild(e)}}(),de(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",pe,!1)}}const _e=new Map;function Ae(e,t,n,s=!1){let i=null,r=e.getAttribute("src");if(r&&(r=g(r,n.url)),e.hasAttribute("exclude")||ge(r,n.name))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","systemjs-module","systemjs-importmap"].includes(e.type)||e.hasAttribute("ignore")||we(r,n.name))return null;if(me.supportModuleScript&&e.noModule||!me.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){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:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:r};n.source.scripts.set(t,r),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 be(e){var t,n,s;return[...(null===(t=tt.plugins)||void 0===t?void 0:t.global)||[],...(null===(s=null===(n=tt.plugins)||void 0===n?void 0:n.modules)||void 0===s?void 0:s[e])||[]]}function ge(e,t){if(!e)return!1;return(be(t)||[]).some((t=>!!t.excludeChecker&&t.excludeChecker(e)))}function we(e,t){if(!e)return!1;return(be(t)||[]).some((t=>!!t.ignoreChecker&&t.ignoreChecker(e)))}function ye(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=_e.get(e);n?r.code=n:(!r.defer&&!r.async||t.isPrefetch)&&(s.push($(e,t.name)),i.push([e,r]))}s.length?w(s,(e=>{!function(e,t,n){t.isGlobal&&!_e.has(e)&&_e.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Ee(e,t,n,s,i){var r;try{const o=Ce(e,t,n.code,n);if(t.inline||n.module){const a=D("script");if(ve(e,o,n.module,a,i),s)return a;null===(r=t.container)||void 0===r||r.querySelector("micro-app-body").appendChild(a)}else if(Ne(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ve(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 Ne(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function Ce(e,t,n,s){return o(tt.plugins)&&(n=function(e,t,n,s,i){var r;const o=Re(s.global,t,e,i);return Re(null===(r=s.modules)||void 0===r?void 0:r[n],o,e,i)}(e,n,t.name,tt.plugins,s)),t.sandBox&&!s.module?(me.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${W}){;${n}\n}).call(proxyWindow,${W})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Re(e,t,n,s){return r(e)?e.reduce(((e,t)=>o(t)&&i(t.loader)?t.loader(e,n,t.options,s):e),t):t}function De(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{De(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")||ge(n.getAttribute("href"),t.name)?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")||we(n.getAttribute("href"),t.name)?n.hasAttribute("href")&&n.setAttribute("href",g(n.getAttribute("href"),t.url)):Y(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")&&q(n,t):n instanceof HTMLScriptElement?Ae(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",g(n.getAttribute("src"),t.url))}function Pe(e,t){const n=function(e){const t=D("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)),p(e,t.name)}De(n,t),t.source.links.size?Z(n,t,s):t.onLoad(n),t.source.scripts.size?ye(n,t):t.onLoad(n)}const Me=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(p("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return p("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&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!o(t))return p("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 Oe(e,t){return n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Se{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Me.on("global",e,t)}removeGlobalDataListener(e){i(e)&&Me.off("global",e)}setGlobalData(e){R(),Me.dispatch("global",e)}getGlobalData(){return Me.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Me.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 Ie extends Se{addDataListener(e,t,n){Me.on(Oe(A(e),!1),t,n)}removeDataListener(e,t){i(t)&&Me.off(Oe(A(e),!1),t)}getData(e,t=!1){return Me.getData(Oe(A(e),t))}setData(e,t){Me.dispatch(Oe(A(e),!0),t)}clearDataListener(e){Me.off(Oe(A(e),!1))}}class Le extends Se{constructor(e){super(),this.appName=A(e),!this.appName&&p(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Me.on(Oe(this.appName,!0),e,t)}removeDataListener(e){i(e)&&Me.off(Oe(this.appName,!0),e)}getData(){return Me.getData(Oe(this.appName,!0))}dispatch(e){R(),Me.dispatch(Oe(this.appName,!1),e);const t=qe.get(this.appName);if((null==t?void 0:t.container)&&o(e)){const n=new CustomEvent("datachange",{detail:{data:e}});S(t.container).dispatchEvent(n)}}clearDataListener(){Me.off(Oe(this.appName,!0))}}function xe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(s(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 s(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=c(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&l(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Ue=new Map;let Te=!1;const ke=new Map;function We(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=me;!Te&&function(){if(Te=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return d("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Ue.forEach((t=>{i(t)&&t.call(document,e)}))}l(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=C();return e?Ue.get(e):Ue.get("base")},set(e){const s=C();s?Ue.set(s,e):Ue.set("base",e),!t&&i(e)&&(t=!0,me.rawDocumentAddEventListener.call(me.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var r;const o=C();if(o&&(!(null===(r=qe.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=ke.get(o);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else ke.set(o,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 r;const o=C();if(o&&(!(null===(r=qe.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=ke.get(o);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 $e=["unmount","appstate-change"];function Be(e,t){return $e.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Fe=["System","__cjsWrapper"],He=["location"],Ke=["window","self","globalThis"];class je{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:r,rawDocument:o,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=me;e.addEventListener=function(t,s,i){t=Be(t,e);const o=n.get(t);o?o.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(r,t,s,i)},e.removeEventListener=function(t,s,i){t=Be(t,e);const o=n.get(t);(null==o?void 0:o.size)&&o.has(s)&&o.delete(s),c.call(r,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(r,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=u.call(r,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),h.call(r,e)},e.clearTimeout=function(e){i.delete(e),p.call(r,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)),_=Ue.get(t);const e=ke.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)})),_&&Ue.set(t,_),v(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),v(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(r,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{h.call(r,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(r,t)})),i.clear()),Ue.delete(t);const e=ke.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(o,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,me.rawWindow._babelPolyfill&&(me.rawWindow._babelPolyfill=!1),1==++je.activeCount&&(We(),oe()))}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(me.rawWindow,e)})),this.escapeKeys.clear(),0==--je.activeCount&&(document.addEventListener=me.rawDocumentAddEventListener,document.removeEventListener=me.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=Me.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Me.eventList.get(Oe(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;o(tt.plugins)&&(this.commonActionForSpecialProperties(tt.plugins.global),this.commonActionForSpecialProperties(null===(t=tt.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(r(e))for(const t of e)o(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=me.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(s,r)=>{if(N(e),Reflect.has(s,r)||n(r)&&/^__MICRO_APP_/.test(r)||this.scopeProperties.includes(r))return Reflect.get(s,r);const o=Reflect.get(t,r);return i(o)?xe(t,o):o},set:(e,n,s)=>{if(this.active){if(He.includes(n))Reflect.set(t,n,s);else if(h.call(e,n)||!h.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:r,enumerable:o,writable:a,set:c}=i;l(e,n,{value:s,configurable:r,enumerable:o,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||Fe.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,n)=>{if(h.call(e,n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(h.call(t,n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,i)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,i):Reflect.defineProperty(e,n,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)=>!h.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__=b(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Le(t),{removeDomScope:R,pureCreateElement:D}),e.rawWindow=me.rawWindow,e.rawDocument=me.rawDocument,e.hasOwnProperty=t=>h.call(e,t)||h.call(me.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=me.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),l(e,"top",this.createDescriptorForMicroAppWindow("top",t)),l(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Ke.forEach((t=>{l(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:r}=Object.getOwnPropertyDescriptor(me.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!r}}setHijackProperties(e,t){let n,s;u(e,{document:{get:()=>(N(t),me.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(N(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(N(t),s||me.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Ge(e,t,n,s){var r;if(!e)return p(`element does not exist in lifecycle ${n}`,t);e=S(e),R();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),i(null===(r=tt.lifeCycles)||void 0===r?void 0:r[n])&&tt.lifeCycles[n](a),e.dispatchEvent(a)}function Ve(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}je.activeCount=0;const qe=new Map;class ze{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:r,useSandbox:o,baseroute:a}){this.state=U.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=o,this.scopecss=this.useSandbox&&r,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new je(e,t))}loadSourceCode(){this.state=U.LOADING_SOURCE_CODE,B.getInstance().run(this,Pe)}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):U.UNMOUNT!==this.state&&(this.state=U.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),U.UNMOUNT!==this.state&&(this.onerror(e),this.state=U.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,o,a;if(s(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(r=this.container)&&void 0!==r?r:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=U.LOADING_SOURCE_CODE);let c;if(Ge(this.container,this.name,T.BEFOREMOUNT),this.state=U.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(o=this.sandBox)||void 0===o||o.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("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=[],r=[];for(const[e,o]of s)o.isDynamic||(o.defer||o.async?(o.isExternal&&!o.code?i.push($(e,t.name)):i.push(o.code),r.push([e,o]),o.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ee(e,t,o,!1),n(!1)));i.length?w(i,(e=>{const t=r[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,p(e,t.name)}),(()=>{r.forEach((([e,s])=>{s.code&&(Ee(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(i(e)&&i(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){p("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(){U.UNMOUNT!==this.state&&(this.state=U.MOUNTED,Ge(this.container,this.name,T.MOUNTED))}unmount(e,t){let n;if(this.state===U.LOAD_SOURCE_ERROR&&(e=!0),this.state=U.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){p("an error occurred in the unmount function \n",this.name,e)}Ve("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&&P(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),Ye().length||(ce=!1,Element.prototype.setAttribute=me.rawSetAttribute),Ge(this.container,this.name,T.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],qe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;P(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=k.KEEP_ALIVE_HIDDEN,Ve("appstate-change",this.name,{appState:"afterhidden"}),Ge(e,this.name,T.AFTERHIDDEN)}showKeepAliveApp(e){Ve("appstate-change",this.name,{appState:"beforeshow"}),Ge(e,this.name,T.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=k.KEEP_ALIVE_SHOW,Ve("appstate-change",this.name,{appState:"aftershow"}),Ge(this.container,this.name,T.AFTERSHOW)}onerror(e){Ge(this.container,this.name,T.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(U.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:me.rawWindow;return this.libraryName=S(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Qe(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.8.8",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=A(this.getAttribute("name")),t=_(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=qe.get(e);if(e!==this.appName&&n&&U.UNMOUNT!==n.getAppState()&&k.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),p(`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(o(t)){const e={};Object.getOwnPropertyNames(t).forEach((s=>{n(s)&&0===s.indexOf("__")||(e[s]=t[s])})),this.data=e}else"[object Object]"!==t&&d("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__&&qe.has(this.__MICRO_APP_NAME__)){const n=qe.get(this.__MICRO_APP_NAME__);me.rawSetAttribute.call(this,e,g(t,n.url))}else me.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,m((()=>Ge(this,this.appName,T.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===x.NAME?"appName":"appUrl"]!==n)if(e!==x.URL||this.appUrl)if(e!==x.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,m(this.handleAttributeUpdate));else{const e=A(n);if(!e)return p(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(tt.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=_(n,this.appName)))return p(`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&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=g(me.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),qe.has(this.appName)){const e=qe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==U.UNMOUNT?e.isPrefetch||e.getAppState()===U.UNMOUNT?(d(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):p(`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=g(me.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()===k.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):p(`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!(!n(t)||!t)||(p(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,m((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;qe.has(this.appName)&&qe.get(this.appName).actionsForCompletelyDestroy();const t=new ze({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()});qe.set(this.appName,t)}handleUnmount(e,t){const n=qe.get(this.appName);n&&n.getAppState()!==U.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=qe.get(this.appName);e&&e.getAppState()!==U.UNMOUNT&&e.getKeepAliveState()!==k.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){m((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||tt[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?tt.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?tt.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function Je(t){if(!e)return p("preFetch is only supported in browser environment");y((()=>{i(t)&&(t=t()),r(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{y((()=>{var n,s;if(o(e)&&navigator.onLine)if(e.name=A(e.name),e.url=_(e.url,e.name),e.name&&e.url&&!qe.has(e.name)){const i=new ze({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:tt.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:tt.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,qe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Xe(e,t,s){if(r(e)){const i=e.filter((e=>n(e)&&e.includes(`.${t}`)&&!s.has(e)));w(i.map((e=>$(e))),(e=>{const t=i[e.index];s.has(t)||s.set(t,e.data)}),(e=>{p(e)}))}}function Ye(e){const t=[];return qe.forEach(((n,s)=>{U.UNMOUNT===n.getAppState()||n.isPrefetch||e&&k.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Ze(e,t){const n=qe.get(A(e));return new Promise((s=>{if(n)if(n.getAppState()===U.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===k.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=S(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()},r=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",r),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 d(`app ${e} does not exist`),s()}))}class et extends Ie{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Je}start(t){if(!e||!window.customElements)return p("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return p(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return d(`element ${this.tagName} is already defined`);if(fe(),t&&o(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.ssr=t.ssr,i(t.fetch)&&(this.fetch=t.fetch),o(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&Je(t.preFetchApps),t.globalAssets&&(o(n=t.globalAssets)&&y((()=>{Xe(n.js,"js",_e),Xe(n.css,"css",X)}))),o(t.plugins))){const e=t.plugins.modules;if(o(e))for(const t in e){const n=A(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;Qe(this.tagName)}}var tt=new et;exports.EventCenterForMicroApp=Le,exports.MicroApp=et,exports.default=tt,exports.getActiveApps=Ye,exports.getAllApps=function(){return Array.from(qe.keys())},exports.preFetch=Je,exports.pureCreateElement=D,exports.removeDomScope=R,exports.unmountAllApps=function(e){return Array.from(qe.keys()).reduce(((t,n)=>t.then((()=>Ze(n,e)))),Promise.resolve())},exports.unmountApp=Ze,exports.version="0.8.8";
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

!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.7",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 r(e){return"boolean"==typeof e}function o(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 u(e){return o(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const h=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 r(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),r()})).catch((e=>{n({error:e,index:s}),r()})):(t({data:e,index:s}),r())}))}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 o(st.fetch)?st.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}class H{static getInstance(){return this.instance||(this.instance=new H),this.instance}run(e,t){const n=e.name,s=e.ssrUrl||e.url;F(s,n,{cache:"no-cache"}).then((i=>{if(!i){const t="html is empty, please check in detail";return e.onerror(new Error(t)),m(t,n)}i=this.formatHTML(s,i,n),t(i,e)})).catch((t=>{m(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n,t),e.onLoadError(t)}))}formatHTML(e,t,n){return this.processHtml(e,t,n,st.plugins).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>")))}processHtml(e,t,n,s){var i;if(!s)return t;const r=[];return s.global&&r.push(...s.global),(null===(i=s.modules)||void 0===i?void 0:i[n])&&r.push(...s.modules[n]),r.length>0?r.reduce(((t,n)=>c(n)&&o(n.processHtml)?n.processHtml(t,e,n.options):t),t):t}}const K=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,j=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function G(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class V{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):G("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))||K.test(n)||(n=j.test(n)?n.replace(j,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||G("Declaration missing '}'",this.linkPath)):G("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 G("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return G("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):G("@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):G(`@${t} missing '}'`,this.linkPath)):G(`@${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):G(`@${e} missing '}'`,this.linkPath)):G(`@${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 G("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 q(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let r=null;try{r=z.exec(e.textContent,n,s,i),z.reset()}catch(e){z.reset(),m("An error occurred while parsing CSS:\n",t,e)}r&&(e.textContent=r)}}let z;function Q(e,t){if(t.scopecss){const n=`${st.tagName}[name=${t.name}]`;if(z||(z=new V),e.textContent)q(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")&&q(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function J(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function X(e){const t=new CustomEvent("load");J(t,e),o(e.onload)?e.onload(t):e.dispatchEvent(t)}function Y(e){const t=new CustomEvent("error");J(t,e),o(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Z=new Map;function ee(e,t,n,s=!1){const i=e.getAttribute("rel");let r=e.getAttribute("href"),o=null;if("stylesheet"===i&&r){if(r=y(r,n.url),s)return{url:r,info:{code:"",isGlobal:e.hasAttribute("global")}};o=document.createComment(`link element with href=${r} move to micro-app-head as style element`),n.source.links.set(r,{code:"",placeholder:o,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?o=document.createComment(`link element with rel=${i}${r?" & href="+r:""} removed by micro-app`):t.removeChild(e):r&&e.setAttribute("href",y(r,n.url));return s?{replaceComment:o}:o?t.replaceChild(o,e):void 0}function te(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>Z.has(e)?Z.get(e):F(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Z.has(e)&&Z.set(e,n);const r=M("style");r.textContent=n,r.__MICRO_APP_LINK_PATH__=e,r.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(Q(r,i),t.placeholder):s.appendChild(Q(r,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 ne=new WeakMap;function se(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 ne.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?Q(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")||ye(t.getAttribute("href"),n.name)){const e=document.createComment("link element with exclude attribute ignored by micro-app");return ne.set(t,e),e}if(t.hasAttribute("ignore")||Ee(t.getAttribute("href"),n.name))return t;const{url:s,info:i,replaceComment:r}=ee(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,Q(i,n),void _((()=>X(s)));if(Z.has(e)){const r=Z.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,Q(i,n),void _((()=>X(s)))}F(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&Z.set(e,r),i.textContent=r,Q(i,n),X(s)})).catch((e=>{m(e,n.name),Y(s)}))}(s,i,n,t,e),ne.set(t,e),e}return r?(ne.set(t,r),r):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:r}=ge(t,e,n,!0)||{};if(i&&r){if(r.isExternal){const e=function(e,t,n,s){const i=()=>X(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),Ne(e,n,t,!0,i)}if(be.has(e)){const s=be.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),Ne(e,n,t,!0,i)}let r;r=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return F(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&be.set(e,o);try{o=De(e,n,o,t),n.inline||t.module?Ce(e,o,t.module,r,i):Re(o,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&X(s)})).catch((e=>{m(e,n.name),Y(s)})),r}(i,r,n,t);return ne.set(t,e),e}{const e=Ne(i,n,r,!0);return ne.set(t,e),e}}return s?(ne.set(t,s),s):t}return t}function ie(e,t,n,s,i){const r=function(e,t){var n,s;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===(s=null==t?void 0:t.container)||void 0===s?void 0:s.querySelector("micro-app-body");return null}(n,e);return r?i&&!r.contains(i)?_e.rawAppendChild.call(r,s):t!==_e.rawRemoveChild||r.contains(s)?re(t,r,s,i):n.contains(s)?t.call(n,s):s:re(t,n,s,i)}function re(e,t,n,s){return(i=e)===_e.rawAppend||i===_e.rawPrepend?e.call(t,n):e.call(t,n,s);var i}function oe(e){var t;return null!==(t=ne.get(e))&&void 0!==t?t:e}function ae(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Qe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ie(i,s,e,se(e,t,i),n&&oe(n)):s===_e.rawAppend||s===_e.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===_e.rawAppend||s===_e.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=Qe.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 ce(){!function(){const e=_e.rawDocument;function t(t){var n,s,i;const r=D();return r&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:_e.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const r=D();return r&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:_e.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return le(_e.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return le(_e.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return le(_e.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(e))return _e.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return _e.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!D()||S(e))return _e.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return _e.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=D();if(!s||I(e)||S(e)||!(null===(t=Qe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return _e.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return _e.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!D()||S(e))return _e.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return _e.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return ae(this,e,null,_e.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return ae(this,e,t,_e.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return ae(this,e,t,_e.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ae(this,e[t],null,_e.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ae(this,e[t-1],null,_e.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Qe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ie(t,_e.rawRemoveChild,this,oe(e)):_e.rawRemoveChild.call(this,e)}return _e.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=_e.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function le(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ue=!1;function he(){C(null),Document.prototype.createElement=_e.rawCreateElement,Document.prototype.createElementNS=_e.rawCreateElementNS,Document.prototype.createDocumentFragment=_e.rawCreateDocumentFragment,Document.prototype.querySelector=_e.rawQuerySelector,Document.prototype.querySelectorAll=_e.rawQuerySelectorAll,Document.prototype.getElementById=_e.rawGetElementById,Document.prototype.getElementsByClassName=_e.rawGetElementsByClassName,Document.prototype.getElementsByTagName=_e.rawGetElementsByTagName,Document.prototype.getElementsByName=_e.rawGetElementsByName,Element.prototype.appendChild=_e.rawAppendChild,Element.prototype.insertBefore=_e.rawInsertBefore,Element.prototype.replaceChild=_e.rawReplaceChild,Element.prototype.removeChild=_e.rawRemoveChild,Element.prototype.append=_e.rawAppend,Element.prototype.prepend=_e.rawPrepend,Element.prototype.cloneNode=_e.rawCloneNode}let pe=!1;class de{constructor(){this.appInstanceMap=Qe}static getInstance(){return this.instance||(this.instance=new de),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,t){this.appInstanceMap.set(e,t)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function me(){fe(),de.getInstance().getAll().forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&de.getInstance().clear()}function fe(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",me,!1)}const _e={};function Ae(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,r=Element.prototype.append,o=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,h=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(_e,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:r,rawPrepend:o,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:u,rawQuerySelector:h,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(!pe){pe=!0;const e=M("style");_e.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${st.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,_e.rawDocument.head.appendChild(e)}}(),fe(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",me,!1)}}const be=new Map;function ge(e,t,n,s=!1){let i=null,r=e.getAttribute("src");if(r&&(r=y(r,n.url)),e.hasAttribute("exclude")||ye(r,n.name))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")||Ee(r,n.name))return null;if(_e.supportModuleScript&&e.noModule||!_e.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){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:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:r};n.source.scripts.set(t,r),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 we(e){var t,n,s;return[...(null===(t=st.plugins)||void 0===t?void 0:t.global)||[],...(null===(s=null===(n=st.plugins)||void 0===n?void 0:n.modules)||void 0===s?void 0:s[e])||[]]}function ye(e,t){if(!e)return!1;return(we(t)||[]).some((t=>!!t.excludeChecker&&t.excludeChecker(e)))}function Ee(e,t){if(!e)return!1;return(we(t)||[]).some((t=>!!t.ignoreChecker&&t.ignoreChecker(e)))}function ve(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=be.get(e);n?r.code=n:(!r.defer&&!r.async||t.isPrefetch)&&(s.push(F(e,t.name)),i.push([e,r]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!be.has(e)&&be.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 Ne(e,t,n,s,i){var r;try{const o=De(e,t,n.code,n);if(t.inline||n.module){const a=M("script");if(Ce(e,o,n.module,a,i),s)return a;null===(r=t.container)||void 0===r||r.querySelector("micro-app-body").appendChild(a)}else if(Re(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Ce(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 Re(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function De(e,t,n,s){return c(st.plugins)&&(n=function(e,t,n,s,i){var r;const o=Pe(s.global,t,e,i);return Pe(null===(r=s.modules)||void 0===r?void 0:r[n],o,e,i)}(e,n,t.name,st.plugins,s)),t.sandBox&&!s.module?(_e.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 Pe(e,t,n,s){return a(e)?e.reduce(((e,t)=>c(t)&&o(t.loader)?t.loader(e,n,t.options,s):e),t):t}function Me(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{Me(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")||ye(n.getAttribute("href"),t.name)?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")||Ee(n.getAttribute("href"),t.name)?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):ee(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")&&Q(n,t):n instanceof HTMLScriptElement?ge(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 Oe(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)}Me(n,t),t.source.links.size?te(n,t,s):t.onLoad(n),t.source.scripts.size?ve(n,t):t.onLoad(n)}const Se=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(!o(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&&(o(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 Ie(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Le{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Se.on("global",e,t)}removeGlobalDataListener(e){o(e)&&Se.off("global",e)}setGlobalData(e){P(),Se.dispatch("global",e)}getGlobalData(){return Se.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Se.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 Ue extends Le{addDataListener(e,t,n){Se.on(Ie(g(e),!1),t,n)}removeDataListener(e,t){o(t)&&Se.off(Ie(g(e),!1),t)}getData(e,t=!1){return Se.getData(Ie(g(e),t))}setData(e,t){Se.dispatch(Ie(g(e),!0),t)}clearDataListener(e){Se.off(Ie(g(e),!1))}}class xe extends Le{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Se.on(Ie(this.appName,!0),e,t)}removeDataListener(e){o(e)&&Se.off(Ie(this.appName,!0),e)}getData(){return Se.getData(Ie(this.appName,!0))}dispatch(e){P(),Se.dispatch(Ie(this.appName,!1),e);const t=Qe.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(){Se.off(Ie(this.appName,!0))}}function Te(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(r(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 r(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=u(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&h(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const ke=new Map;let We=!1;const $e=new Map;function Be(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=_e;!We&&function(){if(We=!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){ke.forEach((t=>{o(t)&&t.call(document,e)}))}h(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?ke.get(e):ke.get("base")},set(e){const s=D();s?ke.set(s,e):ke.set("base",e),!t&&o(e)&&(t=!0,_e.rawDocumentAddEventListener.call(_e.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var r;const o=D();if(o&&(!(null===(r=Qe.get(o))||void 0===r?void 0:r.umdMode)||!u(s))){const e=$e.get(o);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else $e.set(o,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 r;const o=D();if(o&&(!(null===(r=Qe.get(o))||void 0===r?void 0:r.umdMode)||!u(s))){const e=$e.get(o);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 Fe=["unmount","appstate-change"];function He(e,t){return Fe.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Ke=["System","__cjsWrapper"],je=["location"],Ge=["window","self","globalThis"];class Ve{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:r,rawDocument:o,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=_e;e.addEventListener=function(t,s,i){t=He(t,e);const o=n.get(t);o?o.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(r,t,s,i)},e.removeEventListener=function(t,s,i){t=He(t,e);const o=n.get(t);(null==o?void 0:o.size)&&o.has(s)&&o.delete(s),c.call(r,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(r,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=u.call(r,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),h.call(r,e)},e.clearTimeout=function(e){i.delete(e),p.call(r,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)),_=ke.get(t);const e=$e.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)})),_&&ke.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(r,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{h.call(r,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(r,t)})),i.clear()),ke.delete(t);const e=$e.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(o,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,_e.rawWindow._babelPolyfill&&(_e.rawWindow._babelPolyfill=!1),1==++Ve.activeCount&&(Be(),ce()))}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(_e.rawWindow,e)})),this.escapeKeys.clear(),0==--Ve.activeCount&&(document.addEventListener=_e.rawDocumentAddEventListener,document.removeEventListener=_e.rawDocumentRemoveEventListener,he()))}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=Se.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Se.eventList.get(Ie(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(st.plugins)&&(this.commonActionForSpecialProperties(st.plugins.global),this.commonActionForSpecialProperties(null===(t=st.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=_e.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 r=Reflect.get(t,s);return o(r)?Te(t,r):r},set:(e,n,s)=>{if(this.active){if(je.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:r,enumerable:o,writable:a,set:c}=i;h(e,n,{value:s,configurable:r,enumerable:o,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 xe(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=_e.rawWindow,e.rawDocument=_e.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(_e.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=_e.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),h(e,"top",this.createDescriptorForMicroAppWindow("top",t)),h(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Ge.forEach((t=>{h(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:r}=Object.getOwnPropertyDescriptor(_e.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!r}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),_e.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||_e.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function qe(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const r=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:r});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),o(null===(i=st.lifeCycles)||void 0===i?void 0:i[n])&&st.lifeCycles[n](a),e.dispatchEvent(a)}function ze(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}Ve.activeCount=0;const Qe=new Map;class Je{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:r,useSandbox:o,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=o,this.scopecss=this.useSandbox&&r,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ve(e,t))}loadSourceCode(){this.state=k.LOADING_SOURCE_CODE,H.getInstance().run(this,Oe)}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(r(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(qe(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=[],r=[];for(const[e,o]of s)o.isDynamic||(o.defer||o.async?(o.isExternal&&!o.code?i.push(F(e,t.name)):i.push(o.code),r.push([e,o]),o.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ne(e,t,o,!1),n(!1)));i.length?E(i,(e=>{const t=r[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{r.forEach((([e,s])=>{s.code&&(Ne(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(o(e)&&o(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,qe(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)}ze("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(),et().length||(ue=!1,Element.prototype.setAttribute=_e.rawSetAttribute),qe(this.container,this.name,W.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Qe.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,ze("appstate-change",this.name,{appState:"afterhidden"}),qe(e,this.name,W.AFTERHIDDEN)}showKeepAliveApp(e){ze("appstate-change",this.name,{appState:"beforeshow"}),qe(e,this.name,W.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=$.KEEP_ALIVE_SHOW,ze("appstate-change",this.name,{appState:"aftershow"}),qe(this.container,this.name,W.AFTERSHOW)}onerror(e){qe(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:_e.rawWindow;return this.libraryName=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Xe(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=Qe.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)},ue||(ue=!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__&&Qe.has(this.__MICRO_APP_NAME__)){const n=Qe.get(this.__MICRO_APP_NAME__);_e.rawSetAttribute.call(this,e,y(t,n.url))}else _e.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>qe(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&&(st.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&&o(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(_e.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Qe.has(this.appName)){const e=Qe.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(_e.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;Qe.has(this.appName)&&Qe.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()});Qe.set(this.appName,t)}handleUnmount(e,t){const n=Qe.get(this.appName);n&&n.getAppState()!==k.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Qe.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)||st[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?st.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?st.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ye(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{o(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&&!Qe.has(e.name)){const i=new Je({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:st.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:st.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Qe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Ze(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 et(e){const t=[];return Qe.forEach(((n,s)=>{k.UNMOUNT===n.getAppState()||n.isPrefetch||e&&$.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function tt(e,t){const n=Qe.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",r),s()},r=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",r),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 nt extends Ue{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ye}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(Ae(),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,o(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ye(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{Ze(t.js,"js",be),Ze(t.css,"css",Z)}))),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;Xe(this.tagName)}}var st=new nt;e.EventCenterForMicroApp=xe,e.MicroApp=nt,e.default=st,e.getActiveApps=et,e.getAllApps=function(){return Array.from(Qe.keys())},e.preFetch=Ye,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(Qe.keys()).reduce(((t,n)=>t.then((()=>tt(n,e)))),Promise.resolve())},e.unmountApp=tt,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
!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.8",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 r(e){return"boolean"==typeof e}function o(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 u(e){return o(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const h=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 r(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),r()})).catch((e=>{n({error:e,index:s}),r()})):(t({data:e,index:s}),r())}))}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 o(st.fetch)?st.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}class H{static getInstance(){return this.instance||(this.instance=new H),this.instance}run(e,t){const n=e.name,s=e.ssrUrl||e.url;F(s,n,{cache:"no-cache"}).then((i=>{if(!i){const t="html is empty, please check in detail";return e.onerror(new Error(t)),m(t,n)}i=this.formatHTML(s,i,n),t(i,e)})).catch((t=>{m(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n,t),e.onLoadError(t)}))}formatHTML(e,t,n){return this.processHtml(e,t,n,st.plugins).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>")))}processHtml(e,t,n,s){var i;if(!s)return t;const r=[];return s.global&&r.push(...s.global),(null===(i=s.modules)||void 0===i?void 0:i[n])&&r.push(...s.modules[n]),r.length>0?r.reduce(((t,n)=>c(n)&&o(n.processHtml)?n.processHtml(t,e,n.options):t),t):t}}const K=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,j=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function G(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class V{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):G("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))||K.test(n)||(n=j.test(n)?n.replace(j,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||G("Declaration missing '}'",this.linkPath)):G("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 G("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return G("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):G("@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):G(`@${t} missing '}'`,this.linkPath)):G(`@${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):G(`@${e} missing '}'`,this.linkPath)):G(`@${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 G("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 q(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let r=null;try{r=z.exec(e.textContent,n,s,i),z.reset()}catch(e){z.reset(),m("An error occurred while parsing CSS:\n",t,e)}r&&(e.textContent=r)}}let z;function Q(e,t){if(t.scopecss){const n=`${st.tagName}[name=${t.name}]`;if(z||(z=new V),e.textContent)q(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")&&q(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function J(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function X(e){const t=new CustomEvent("load");J(t,e),o(e.onload)?e.onload(t):e.dispatchEvent(t)}function Y(e){const t=new CustomEvent("error");J(t,e),o(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Z=new Map;function ee(e,t,n,s=!1){const i=e.getAttribute("rel");let r=e.getAttribute("href"),o=null;if("stylesheet"===i&&r){if(r=y(r,n.url),s)return{url:r,info:{code:"",isGlobal:e.hasAttribute("global")}};o=document.createComment(`link element with href=${r} move to micro-app-head as style element`),n.source.links.set(r,{code:"",placeholder:o,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?o=document.createComment(`link element with rel=${i}${r?" & href="+r:""} removed by micro-app`):t.removeChild(e):r&&e.setAttribute("href",y(r,n.url));return s?{replaceComment:o}:o?t.replaceChild(o,e):void 0}function te(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>Z.has(e)?Z.get(e):F(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Z.has(e)&&Z.set(e,n);const r=M("style");r.textContent=n,r.__MICRO_APP_LINK_PATH__=e,r.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(Q(r,i),t.placeholder):s.appendChild(Q(r,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 ne=new WeakMap;function se(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 ne.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?Q(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")||ye(t.getAttribute("href"),n.name)){const e=document.createComment("link element with exclude attribute ignored by micro-app");return ne.set(t,e),e}if(t.hasAttribute("ignore")||Ee(t.getAttribute("href"),n.name))return t;const{url:s,info:i,replaceComment:r}=ee(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,Q(i,n),void _((()=>X(s)));if(Z.has(e)){const r=Z.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,Q(i,n),void _((()=>X(s)))}F(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&Z.set(e,r),i.textContent=r,Q(i,n),X(s)})).catch((e=>{m(e,n.name),Y(s)}))}(s,i,n,t,e),ne.set(t,e),e}return r?(ne.set(t,r),r):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:r}=ge(t,e,n,!0)||{};if(i&&r){if(r.isExternal){const e=function(e,t,n,s){const i=()=>X(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),Ne(e,n,t,!0,i)}if(be.has(e)){const s=be.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),Ne(e,n,t,!0,i)}let r;r=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return F(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&be.set(e,o);try{o=De(e,n,o,t),n.inline||t.module?Ce(e,o,t.module,r,i):Re(o,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&X(s)})).catch((e=>{m(e,n.name),Y(s)})),r}(i,r,n,t);return ne.set(t,e),e}{const e=Ne(i,n,r,!0);return ne.set(t,e),e}}return s?(ne.set(t,s),s):t}return t}function ie(e,t,n,s,i){const r=function(e,t){var n,s;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===(s=null==t?void 0:t.container)||void 0===s?void 0:s.querySelector("micro-app-body");return null}(n,e);return r?i&&!r.contains(i)?_e.rawAppendChild.call(r,s):t!==_e.rawRemoveChild||r.contains(s)?re(t,r,s,i):n.contains(s)?t.call(n,s):s:re(t,n,s,i)}function re(e,t,n,s){return(i=e)===_e.rawAppend||i===_e.rawPrepend?e.call(t,n):e.call(t,n,s);var i}function oe(e){var t;return null!==(t=ne.get(e))&&void 0!==t?t:e}function ae(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Qe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ie(i,s,e,se(e,t,i),n&&oe(n)):s===_e.rawAppend||s===_e.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===_e.rawAppend||s===_e.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=Qe.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 ce(){!function(){const e=_e.rawDocument;function t(t){var n,s,i;const r=D();return r&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:_e.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const r=D();return r&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Qe.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:_e.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return le(_e.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return le(_e.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return le(_e.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(e))return _e.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return _e.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!D()||S(e))return _e.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return _e.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=D();if(!s||I(e)||S(e)||!(null===(t=Qe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return _e.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return _e.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!D()||S(e))return _e.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return _e.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return ae(this,e,null,_e.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return ae(this,e,t,_e.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return ae(this,e,t,_e.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ae(this,e[t],null,_e.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ae(this,e[t-1],null,_e.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Qe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ie(t,_e.rawRemoveChild,this,oe(e)):_e.rawRemoveChild.call(this,e)}return _e.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=_e.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function le(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ue=!1;function he(){C(null),Document.prototype.createElement=_e.rawCreateElement,Document.prototype.createElementNS=_e.rawCreateElementNS,Document.prototype.createDocumentFragment=_e.rawCreateDocumentFragment,Document.prototype.querySelector=_e.rawQuerySelector,Document.prototype.querySelectorAll=_e.rawQuerySelectorAll,Document.prototype.getElementById=_e.rawGetElementById,Document.prototype.getElementsByClassName=_e.rawGetElementsByClassName,Document.prototype.getElementsByTagName=_e.rawGetElementsByTagName,Document.prototype.getElementsByName=_e.rawGetElementsByName,Element.prototype.appendChild=_e.rawAppendChild,Element.prototype.insertBefore=_e.rawInsertBefore,Element.prototype.replaceChild=_e.rawReplaceChild,Element.prototype.removeChild=_e.rawRemoveChild,Element.prototype.append=_e.rawAppend,Element.prototype.prepend=_e.rawPrepend,Element.prototype.cloneNode=_e.rawCloneNode}let pe=!1;class de{constructor(){this.appInstanceMap=Qe}static getInstance(){return this.instance||(this.instance=new de),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,t){this.appInstanceMap.set(e,t)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function me(){fe(),de.getInstance().getAll().forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&de.getInstance().clear()}function fe(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",me,!1)}const _e={};function Ae(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,r=Element.prototype.append,o=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,h=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(_e,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:r,rawPrepend:o,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:u,rawQuerySelector:h,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(!pe){pe=!0;const e=M("style");_e.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${st.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,_e.rawDocument.head.appendChild(e)}}(),fe(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",me,!1)}}const be=new Map;function ge(e,t,n,s=!1){let i=null,r=e.getAttribute("src");if(r&&(r=y(r,n.url)),e.hasAttribute("exclude")||ye(r,n.name))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","systemjs-module","systemjs-importmap"].includes(e.type)||e.hasAttribute("ignore")||Ee(r,n.name))return null;if(_e.supportModuleScript&&e.noModule||!_e.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){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:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:r};n.source.scripts.set(t,r),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 we(e){var t,n,s;return[...(null===(t=st.plugins)||void 0===t?void 0:t.global)||[],...(null===(s=null===(n=st.plugins)||void 0===n?void 0:n.modules)||void 0===s?void 0:s[e])||[]]}function ye(e,t){if(!e)return!1;return(we(t)||[]).some((t=>!!t.excludeChecker&&t.excludeChecker(e)))}function Ee(e,t){if(!e)return!1;return(we(t)||[]).some((t=>!!t.ignoreChecker&&t.ignoreChecker(e)))}function ve(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=be.get(e);n?r.code=n:(!r.defer&&!r.async||t.isPrefetch)&&(s.push(F(e,t.name)),i.push([e,r]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!be.has(e)&&be.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 Ne(e,t,n,s,i){var r;try{const o=De(e,t,n.code,n);if(t.inline||n.module){const a=M("script");if(Ce(e,o,n.module,a,i),s)return a;null===(r=t.container)||void 0===r||r.querySelector("micro-app-body").appendChild(a)}else if(Re(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Ce(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 Re(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function De(e,t,n,s){return c(st.plugins)&&(n=function(e,t,n,s,i){var r;const o=Pe(s.global,t,e,i);return Pe(null===(r=s.modules)||void 0===r?void 0:r[n],o,e,i)}(e,n,t.name,st.plugins,s)),t.sandBox&&!s.module?(_e.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 Pe(e,t,n,s){return a(e)?e.reduce(((e,t)=>c(t)&&o(t.loader)?t.loader(e,n,t.options,s):e),t):t}function Me(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{Me(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")||ye(n.getAttribute("href"),t.name)?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")||Ee(n.getAttribute("href"),t.name)?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):ee(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")&&Q(n,t):n instanceof HTMLScriptElement?ge(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 Oe(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)}Me(n,t),t.source.links.size?te(n,t,s):t.onLoad(n),t.source.scripts.size?ve(n,t):t.onLoad(n)}const Se=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(!o(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&&(o(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 Ie(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Le{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Se.on("global",e,t)}removeGlobalDataListener(e){o(e)&&Se.off("global",e)}setGlobalData(e){P(),Se.dispatch("global",e)}getGlobalData(){return Se.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Se.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 Ue extends Le{addDataListener(e,t,n){Se.on(Ie(g(e),!1),t,n)}removeDataListener(e,t){o(t)&&Se.off(Ie(g(e),!1),t)}getData(e,t=!1){return Se.getData(Ie(g(e),t))}setData(e,t){Se.dispatch(Ie(g(e),!0),t)}clearDataListener(e){Se.off(Ie(g(e),!1))}}class xe extends Le{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Se.on(Ie(this.appName,!0),e,t)}removeDataListener(e){o(e)&&Se.off(Ie(this.appName,!0),e)}getData(){return Se.getData(Ie(this.appName,!0))}dispatch(e){P(),Se.dispatch(Ie(this.appName,!1),e);const t=Qe.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(){Se.off(Ie(this.appName,!0))}}function Te(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(r(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 r(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=u(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&h(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const ke=new Map;let We=!1;const $e=new Map;function Be(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=_e;!We&&function(){if(We=!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){ke.forEach((t=>{o(t)&&t.call(document,e)}))}h(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?ke.get(e):ke.get("base")},set(e){const s=D();s?ke.set(s,e):ke.set("base",e),!t&&o(e)&&(t=!0,_e.rawDocumentAddEventListener.call(_e.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var r;const o=D();if(o&&(!(null===(r=Qe.get(o))||void 0===r?void 0:r.umdMode)||!u(s))){const e=$e.get(o);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else $e.set(o,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 r;const o=D();if(o&&(!(null===(r=Qe.get(o))||void 0===r?void 0:r.umdMode)||!u(s))){const e=$e.get(o);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 Fe=["unmount","appstate-change"];function He(e,t){return Fe.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Ke=["System","__cjsWrapper"],je=["location"],Ge=["window","self","globalThis"];class Ve{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:r,rawDocument:o,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=_e;e.addEventListener=function(t,s,i){t=He(t,e);const o=n.get(t);o?o.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(r,t,s,i)},e.removeEventListener=function(t,s,i){t=He(t,e);const o=n.get(t);(null==o?void 0:o.size)&&o.has(s)&&o.delete(s),c.call(r,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(r,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=u.call(r,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),h.call(r,e)},e.clearTimeout=function(e){i.delete(e),p.call(r,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)),_=ke.get(t);const e=$e.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)})),_&&ke.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(r,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{h.call(r,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(r,t)})),i.clear()),ke.delete(t);const e=$e.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(o,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,_e.rawWindow._babelPolyfill&&(_e.rawWindow._babelPolyfill=!1),1==++Ve.activeCount&&(Be(),ce()))}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(_e.rawWindow,e)})),this.escapeKeys.clear(),0==--Ve.activeCount&&(document.addEventListener=_e.rawDocumentAddEventListener,document.removeEventListener=_e.rawDocumentRemoveEventListener,he()))}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=Se.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Se.eventList.get(Ie(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(st.plugins)&&(this.commonActionForSpecialProperties(st.plugins.global),this.commonActionForSpecialProperties(null===(t=st.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=_e.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 r=Reflect.get(t,s);return o(r)?Te(t,r):r},set:(e,n,s)=>{if(this.active){if(je.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:r,enumerable:o,writable:a,set:c}=i;h(e,n,{value:s,configurable:r,enumerable:o,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 xe(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=_e.rawWindow,e.rawDocument=_e.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(_e.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=_e.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),h(e,"top",this.createDescriptorForMicroAppWindow("top",t)),h(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Ge.forEach((t=>{h(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:r}=Object.getOwnPropertyDescriptor(_e.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!r}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),_e.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||_e.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function qe(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const r=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:r});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),o(null===(i=st.lifeCycles)||void 0===i?void 0:i[n])&&st.lifeCycles[n](a),e.dispatchEvent(a)}function ze(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}Ve.activeCount=0;const Qe=new Map;class Je{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:r,useSandbox:o,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=o,this.scopecss=this.useSandbox&&r,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ve(e,t))}loadSourceCode(){this.state=k.LOADING_SOURCE_CODE,H.getInstance().run(this,Oe)}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(r(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(qe(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=[],r=[];for(const[e,o]of s)o.isDynamic||(o.defer||o.async?(o.isExternal&&!o.code?i.push(F(e,t.name)):i.push(o.code),r.push([e,o]),o.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ne(e,t,o,!1),n(!1)));i.length?E(i,(e=>{const t=r[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{r.forEach((([e,s])=>{s.code&&(Ne(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(o(e)&&o(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,qe(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)}ze("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(),et().length||(ue=!1,Element.prototype.setAttribute=_e.rawSetAttribute),qe(this.container,this.name,W.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Qe.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,ze("appstate-change",this.name,{appState:"afterhidden"}),qe(e,this.name,W.AFTERHIDDEN)}showKeepAliveApp(e){ze("appstate-change",this.name,{appState:"beforeshow"}),qe(e,this.name,W.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=$.KEEP_ALIVE_SHOW,ze("appstate-change",this.name,{appState:"aftershow"}),qe(this.container,this.name,W.AFTERSHOW)}onerror(e){qe(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:_e.rawWindow;return this.libraryName=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Xe(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=Qe.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)},ue||(ue=!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__&&Qe.has(this.__MICRO_APP_NAME__)){const n=Qe.get(this.__MICRO_APP_NAME__);_e.rawSetAttribute.call(this,e,y(t,n.url))}else _e.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>qe(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&&(st.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&&o(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(_e.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Qe.has(this.appName)){const e=Qe.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(_e.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;Qe.has(this.appName)&&Qe.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()});Qe.set(this.appName,t)}handleUnmount(e,t){const n=Qe.get(this.appName);n&&n.getAppState()!==k.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Qe.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)||st[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?st.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?st.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ye(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{o(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&&!Qe.has(e.name)){const i=new Je({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:st.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:st.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Qe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Ze(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 et(e){const t=[];return Qe.forEach(((n,s)=>{k.UNMOUNT===n.getAppState()||n.isPrefetch||e&&$.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function tt(e,t){const n=Qe.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",r),s()},r=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",r),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 nt extends Ue{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ye}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(Ae(),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,o(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ye(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{Ze(t.js,"js",be),Ze(t.css,"css",Z)}))),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;Xe(this.tagName)}}var st=new nt;e.EventCenterForMicroApp=xe,e.MicroApp=nt,e.default=st,e.getActiveApps=et,e.getAllApps=function(){return Array.from(Qe.keys())},e.preFetch=Ye,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(Qe.keys()).reduce(((t,n)=>t.then((()=>tt(n,e)))),Promise.resolve())},e.unmountApp=tt,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@micro-zoe/micro-app",
"version": "0.8.7",
"version": "0.8.8",
"description": "A lightweight, efficient and powerful micro front-end framework",

@@ -5,0 +5,0 @@ "private": false,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc