@micro-zoe/micro-app 1.0.0-alpha.0 → 1.0.0-alpha.10

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