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