@micro-zoe/micro-app 1.0.0-alpha.2 → 1.0.0-alpha.5

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