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