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

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