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