@micro-zoe/micro-app
Advanced tools
Comparing version 0.8.3 to 0.8.4
@@ -193,2 +193,3 @@ /// <reference path="../typings/global.d.ts" /> | ||
export function trim(str: string): string; | ||
export function isFireFox(): boolean; | ||
} | ||
@@ -195,0 +196,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function s(e){return"boolean"==typeof e}function i(e){return"function"==typeof e}const r=Array.isArray;function o(e){return"[object Object]"===toString.call(e)}function a(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const l=Object.defineProperty,h=Object.defineProperties,u=Object.prototype.hasOwnProperty;function p(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${i} ${e}`,...s):console.error(`[micro-app]${i}`,e,...s)}function d(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${i} ${e}`,...s):console.warn(`[micro-app]${i}`,e,...s)}function m(e,...t){Promise.resolve().then(e.bind(null,...t))}function f(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function _(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(f(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return p(e,t),""}}function A(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function b(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function g(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,b(f(t))).toString()}function w(e,t,n,s){let i=0;function r(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{a(e)?e.then((e=>{t({data:e,index:s}),r()})).catch((e=>{n({error:e,index:s}),r()})):(t({data:e,index:s}),r())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let E=null;function v(e){E=e}function N(e){E!==e&&(v(e),m((()=>{v(null)})))}function C(){return E}function R(){v(null)}function D(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function P(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function M(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function O(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function S(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function I(e){return e?e.replace(/^\s+|\s+$/g,""):""}var L,x,U,T;!function(e){e.NAME="name",e.URL="url"}(L||(L={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(x||(x={})),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"}(U||(U={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(T||(T={}));const k="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function W(e,t=null,n={}){return i(ze.fetch)?ze.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const $=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,B=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function F(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class H{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),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();return this.scopecssDisableNextLine=!1,e?(this.result+=e.join(", "),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):F("selector missing",this.linkPath)}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||F("Declaration missing '}'",this.linkPath)):F("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(),f(t.join("/")+"/")}(this.linkPath)),`url("${g(t,this.baseURI)}")`)))),this.result+=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()}formatSelector(){const e=this.commonMatch(/^([^{]+)/,!0);return!!e&&I(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,(e=>e.replace(/,/g,""))).split(/\s*(?![^(]*\)),\s*/).map((e=>{const t=e.replace(/\u200C/g,",");return this.scopecssDisableNextLine?t:!this.scopecssDisable||this.scopecssDisableSelectors.length&&!this.scopecssDisableSelectors.includes(t)?"*"===t?this.prefix+" *":B.test(t)?t.replace(B,this.prefix+" micro-app-body"):$.test(t)?t:this.prefix+" "+t:t}))}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return F("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return F("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):F("@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(),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):F(`@${t} missing '}'`,this.linkPath)):F(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!1)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):F(`@${e} missing '}'`,this.linkPath)):F(`@${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 F("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.result+=`/*${t}*/`,t=I(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(I(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||(this.result+=s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}}function K(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let r=null;try{r=j.exec(e.textContent,n,s,i),j.reset()}catch(e){j.reset(),p("An error occurred while parsing CSS:\n",t,e)}r&&(e.textContent=r)}}let j;function G(e,t){if(t.scopecss){const n=`${ze.tagName}[name=${t.name}]`;if(j||(j=new H),e.textContent)K(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&K(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function V(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function q(e){const t=new CustomEvent("load");V(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function z(e){const t=new CustomEvent("error");V(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Q=new Map;function J(e,t,n,s=!1){const i=e.getAttribute("rel");let r=e.getAttribute("href"),o=null;if("stylesheet"===i&&r){if(r=g(r,n.url),s)return{url:r,info:{code:"",isGlobal:e.hasAttribute("global")}};o=document.createComment(`link element with href=${r} move to micro-app-head as style element`),n.source.links.set(r,{code:"",placeholder:o,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?o=document.createComment(`link element with rel=${i}${r?" & href="+r:""} removed by micro-app`):t.removeChild(e):r&&e.setAttribute("href",g(r,n.url));return s?{replaceComment:o}:o?t.replaceChild(o,e):void 0}function X(e,t,n){const s=Array.from(t.source.links.entries());w(s.map((([e])=>Q.has(e)?Q.get(e):W(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Q.has(e)&&Q.set(e,n);const r=D("style");r.textContent=n,r.__MICRO_APP_LINK_PATH__=e,r.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(G(r,i),t.placeholder):s.appendChild(G(r,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)}))}const Y=new WeakMap;function Z(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 Y.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?G(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 Y.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:r}=J(t,e,n,!0);if(s&&i){const e=D("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,G(i,n),void m((()=>q(s)));if(Q.has(e)){const r=Q.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,G(i,n),void m((()=>q(s)))}W(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&Q.set(e,r),i.textContent=r,G(i,n),q(s)})).catch((e=>{p(e,n.name),z(s)}))}(s,i,n,t,e),Y.set(t,e),e}return r?(Y.set(t,r),r):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:r}=de(t,e,n,!0)||{};if(i&&r){if(r.isExternal){const e=function(e,t,n,s){const i=()=>q(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&m(i),fe(e,n,t,!0,i)}if(pe.has(e)){const s=pe.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&m(i),fe(e,n,t,!0,i)}let r;r=n.inline||t.module?D("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return W(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&pe.set(e,o);try{o=be(e,n,o,t.module),n.inline||t.module?_e(e,o,t.module,r,i):Ae(o,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&q(s)})).catch((e=>{p(e,n.name),z(s)})),r}(i,r,n,t);return Y.set(t,e),e}{const e=fe(i,n,r,!0);return Y.set(t,e),e}}return s?(Y.set(t,s),s):t}return t}function ee(e,t,n,s,i){if(n===document.head){const r=e.container.querySelector("micro-app-head");return i&&!r.contains(i)?he.rawAppendChild.call(r,s):t!==he.rawRemoveChild||r.contains(s)?t===he.rawAppend||t===he.rawPrepend?t.call(r,s):t.call(r,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const r=e.container.querySelector("micro-app-body");return i&&!r.contains(i)?he.rawAppendChild.call(r,s):t!==he.rawRemoveChild||r.contains(s)?t===he.rawAppend||t===he.rawPrepend?t.call(r,s):t.call(r,s,i):n.contains(s)?t.call(n,s):s}return t===he.rawAppend||t===he.rawPrepend?t.call(n,s):t.call(n,s,i)}function te(e){var t;return null!==(t=Y.get(e))&&void 0!==t?t:e}function ne(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Be.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ee(i,s,e,Z(e,t,i),n&&te(n)):s===he.rawAppend||s===he.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===he.rawAppend||s===he.rawPrepend){const n=C();if(!(t instanceof Node)&&n){const i=Be.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function se(){!function(){const e=he.rawDocument;function t(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Be.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:he.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const r=C();return r&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Be.get(r))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:he.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ie(he.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ie(he.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ie(he.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!C()||M(e))return he.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return he.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!C()||M(e))return he.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return he.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=C();if(!s||O(e)||M(e)||!(null===(t=Be.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return he.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return he.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!C()||M(e))return he.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return he.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return ne(this,e,null,he.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return ne(this,e,t,he.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return ne(this,e,t,he.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ne(this,e[t],null,he.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ne(this,e[t-1],null,he.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Be.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ee(t,he.rawRemoveChild,this,te(e)):he.rawRemoveChild.call(this,e)}return he.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=he.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ie(e){const t=C();return t&&(e.__MICRO_APP_NAME__=t),e}let re=!1;function oe(){v(null),Document.prototype.createElement=he.rawCreateElement,Document.prototype.createElementNS=he.rawCreateElementNS,Document.prototype.createDocumentFragment=he.rawCreateDocumentFragment,Document.prototype.querySelector=he.rawQuerySelector,Document.prototype.querySelectorAll=he.rawQuerySelectorAll,Document.prototype.getElementById=he.rawGetElementById,Document.prototype.getElementsByClassName=he.rawGetElementsByClassName,Document.prototype.getElementsByTagName=he.rawGetElementsByTagName,Document.prototype.getElementsByName=he.rawGetElementsByName,Element.prototype.appendChild=he.rawAppendChild,Element.prototype.insertBefore=he.rawInsertBefore,Element.prototype.replaceChild=he.rawReplaceChild,Element.prototype.removeChild=he.rawRemoveChild,Element.prototype.append=he.rawAppend,Element.prototype.prepend=he.rawPrepend,Element.prototype.cloneNode=he.rawCloneNode}let ae=!1;function ce(){le(),Be.forEach((e=>{e.container&&S(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Be.clear()}function le(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ce,!1)}const he={};function ue(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,r=Element.prototype.append,o=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=C(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,R=b.clearInterval,P=b.clearTimeout,M=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(he,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:r,rawPrepend:o,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:R,rawClearTimeout:P,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:O}),function(){if(!ae){ae=!0;const e=D("style");he.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${ze.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,he.rawDocument.head.appendChild(e)}}(),le(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ce,!1)}}const pe=new Map;function de(e,t,n,s=!1){let i=null,r=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(he.supportModuleScript&&e.noModule||!he.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){r=g(r,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:r};n.source.scripts.set(t,r),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function me(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=pe.get(e);n?r.code=n:(!r.defer&&!r.async||t.isPrefetch)&&(s.push(W(e,t.name)),i.push([e,r]))}s.length?w(s,(e=>{!function(e,t,n){t.isGlobal&&!pe.has(e)&&pe.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function fe(e,t,n,s,i){var r;try{const o=be(e,t,n.code,n.module);if(t.inline||n.module){const a=D("script");if(_e(e,o,n.module,a,i),s)return a;null===(r=t.container)||void 0===r||r.querySelector("micro-app-body").appendChild(a)}else if(Ae(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function _e(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function Ae(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function be(e,t,n,s){return o(ze.plugins)&&(n=function(e,t,n,s){var i;const r=ge(s.global,t,e);return ge(null===(i=s.modules)||void 0===i?void 0:i[n],r,e)}(e,n,t.name,ze.plugins)),t.sandBox&&!s?(he.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${k}){;${n}\n}).call(proxyWindow,${k})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function ge(e,t,n){return r(e)?e.reduce(((e,t)=>o(t)&&i(t.loader)?t.loader(e,n,t.options):e),t):t}function we(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{we(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",g(n.getAttribute("href"),t.url)):J(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")&&G(n,t):n instanceof HTMLScriptElement?de(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",g(n.getAttribute("src"),t.url))}function ye(e,t){const n=function(e){const t=D("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),p(e,t.name)}we(n,t),t.source.links.size?X(n,t,s):t.onLoad(n),t.source.scripts.size?me(n,t):t.onLoad(n)}const Ee=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(p("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return p("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!o(t))return p("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 ve(e,t){return n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Ne{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ee.on("global",e,t)}removeGlobalDataListener(e){i(e)&&Ee.off("global",e)}setGlobalData(e){R(),Ee.dispatch("global",e)}getGlobalData(){return Ee.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ee.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 Ce extends Ne{addDataListener(e,t,n){Ee.on(ve(A(e),!1),t,n)}removeDataListener(e,t){i(t)&&Ee.off(ve(A(e),!1),t)}getData(e,t=!1){return Ee.getData(ve(A(e),t))}setData(e,t){Ee.dispatch(ve(A(e),!0),t)}clearDataListener(e){Ee.off(ve(A(e),!1))}}class Re extends Ne{constructor(e){super(),this.appName=A(e),!this.appName&&p(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ee.on(ve(this.appName,!0),e,t)}removeDataListener(e){i(e)&&Ee.off(ve(this.appName,!0),e)}getData(){return Ee.getData(ve(this.appName,!0))}dispatch(e){R(),Ee.dispatch(ve(this.appName,!1),e);const t=Be.get(this.appName);if((null==t?void 0:t.container)&&o(e)){const n=new CustomEvent("datachange",{detail:{data:e}});S(t.container).dispatchEvent(n)}}clearDataListener(){Ee.off(ve(this.appName,!0))}}function De(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(s(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),i=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=i}(t)&&!function(e){return s(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=c(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&l(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Pe=new Map;let Me=!1;const Oe=new Map;function Se(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=he;!Me&&function(){if(Me=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return d("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Pe.forEach((t=>{i(t)&&t.call(document,e)}))}l(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=C();return e?Pe.get(e):Pe.get("base")},set(e){const s=C();s?Pe.set(s,e):Pe.set("base",e),!t&&i(e)&&(t=!0,he.rawDocumentAddEventListener.call(he.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var r;const o=C();if(o&&(!(null===(r=Be.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=Oe.get(o);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Oe.set(o,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var r;const o=C();if(o&&(!(null===(r=Be.get(o))||void 0===r?void 0:r.umdMode)||!c(s))){const e=Oe.get(o);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const Ie=["unmount","appstate-change"];function Le(e,t){return Ie.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const xe=["System","__cjsWrapper"],Ue=["location"],Te=["window","self","globalThis"];class ke{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:r,rawDocument:o,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=he;e.addEventListener=function(t,s,i){t=Le(t,e);const o=n.get(t);o?o.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(r,t,s,i)},e.removeEventListener=function(t,s,i){t=Le(t,e);const o=n.get(t);(null==o?void 0:o.size)&&o.has(s)&&o.delete(s),c.call(r,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(r,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(r,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(r,e)},e.clearTimeout=function(e){i.delete(e),p.call(r,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Pe.get(t);const e=Oe.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Pe.set(t,_),v(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),v(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(r,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(r,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(r,t)})),i.clear()),Pe.delete(t);const e=Oe.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(o,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,he.rawWindow._babelPolyfill&&(he.rawWindow._babelPolyfill=!1),1==++ke.activeCount&&(Se(),se()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(he.rawWindow,e)})),this.escapeKeys.clear(),0==--ke.activeCount&&(document.addEventListener=he.rawDocumentAddEventListener,document.removeEventListener=he.rawDocumentRemoveEventListener,oe()))}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=Ee.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Ee.eventList.get(ve(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;o(ze.plugins)&&(this.commonActionForSpecialProperties(ze.plugins.global),this.commonActionForSpecialProperties(null===(t=ze.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(r(e))for(const t of e)o(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=he.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(s,r)=>{if(N(e),Reflect.has(s,r)||n(r)&&/^__MICRO_APP_/.test(r)||this.scopeProperties.includes(r))return Reflect.get(s,r);const o=Reflect.get(t,r);return i(o)?De(t,o):o},set:(e,n,s)=>{if(this.active){if(Ue.includes(n))Reflect.set(t,n,s);else if(u.call(e,n)||!u.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:r,enumerable:o,writable:a,set:c}=i;l(e,n,{value:s,configurable:r,enumerable:o,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||xe.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(u.call(e,n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(u.call(t,n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,i)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,i):Reflect.defineProperty(e,n,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))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=b(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Re(t),{removeDomScope:R,pureCreateElement:D}),e.rawWindow=he.rawWindow,e.rawDocument=he.rawDocument,e.hasOwnProperty=t=>u.call(e,t)||u.call(he.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=he.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),l(e,"top",this.createDescriptorForMicroAppWindow("top",t)),l(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Te.forEach((t=>{l(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:r}=Object.getOwnPropertyDescriptor(he.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!r}}setHijackProperties(e,t){let n,s;h(e,{document:{get:()=>(N(t),he.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(N(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(N(t),s||he.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function We(e,t,n,s){var r;if(!e)return p(`element does not exist in lifecycle ${n}`,t);e=S(e),R();const o=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:o});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),i(null===(r=ze.lifeCycles)||void 0===r?void 0:r[n])&&ze.lifeCycles[n](a),e.dispatchEvent(a)}function $e(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}ke.activeCount=0;const Be=new Map;class Fe{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:r,useSandbox:o,baseroute:a}){this.state=x.NOT_LOADED,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.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=o,this.scopecss=this.useSandbox&&r,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new ke(e,t))}loadSourceCode(){var e;this.state=x.LOADING_SOURCE_CODE,W((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)),p(t,e.name)}ye(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=>{p(`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):x.UNMOUNT!==this.state&&(this.state=x.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),x.UNMOUNT!==this.state&&(this.onerror(e),this.state=x.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,o,a;if(s(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(r=this.container)&&void 0!==r?r:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=x.LOADING_SOURCE_CODE);let c;if(We(this.container,this.name,U.BEFOREMOUNT),this.state=x.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(o=this.sandBox)||void 0===o||o.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],r=[];for(const[e,o]of s)o.isDynamic||(o.defer||o.async?(o.isExternal&&!o.code?i.push(W(e,t.name)):i.push(o.code),r.push([e,o]),o.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(fe(e,t,o,!1),n(!1)));i.length?w(i,(e=>{const t=r[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,p(e,t.name)}),(()=>{r.forEach((([e,s])=>{s.code&&(fe(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===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(i(e)&&i(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){p("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(){x.UNMOUNT!==this.state&&(this.state=x.MOUNTED,We(this.container,this.name,U.MOUNTED))}unmount(e,t){let n;if(this.state===x.LOAD_SOURCE_ERROR&&(e=!0),this.state=x.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){p("an error occurred in the unmount function \n",this.name,e)}$e("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&&P(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),Ge().length||(re=!1,Element.prototype.setAttribute=he.rawSetAttribute),We(this.container,this.name,U.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Be.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;P(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=T.KEEP_ALIVE_HIDDEN,$e("appstate-change",this.name,{appState:"afterhidden"}),We(e,this.name,U.AFTERHIDDEN)}showKeepAliveApp(e){$e("appstate-change",this.name,{appState:"beforeshow"}),We(e,this.name,U.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=T.KEEP_ALIVE_SHOW,$e("appstate-change",this.name,{appState:"aftershow"}),We(this.container,this.name,U.AFTERSHOW)}onerror(e){We(this.container,this.name,U.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(x.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:he.rawWindow;return this.libraryName=S(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function He(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.8.3",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=A(this.getAttribute("name")),t=_(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Be.get(e);if(e!==this.appName&&n&&x.UNMOUNT!==n.getAppState()&&T.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),p(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},re||(re=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(o(t)){const e={};Object.getOwnPropertyNames(t).forEach((s=>{n(s)&&0===s.indexOf("__")||(e[s]=t[s])})),this.data=e}else"[object Object]"!==t&&d("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Be.has(this.__MICRO_APP_NAME__)){const n=Be.get(this.__MICRO_APP_NAME__);he.rawSetAttribute.call(this,e,g(t,n.url))}else he.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,m((()=>We(this,this.appName,U.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===L.NAME?"appName":"appUrl"]!==n)if(e!==L.URL||this.appUrl)if(e!==L.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,m(this.handleAttributeUpdate));else{const e=A(n);if(!e)return p(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(ze.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=_(n,this.appName)))return p(`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&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=g(he.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Be.has(this.appName)){const e=Be.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===T.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==x.UNMOUNT?e.isPrefetch||e.getAppState()===x.UNMOUNT?(d(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):p(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=g(he.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===T.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):p(`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!(!n(t)||!t)||(p(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,m((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Be.has(this.appName)&&Be.get(this.appName).actionsForCompletelyDestroy();const t=new Fe({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"),baseroute:this.getBaseRouteCompatible()});Be.set(this.appName,t)}handleUnmount(e,t){const n=Be.get(this.appName);n&&n.getAppState()!==x.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Be.get(this.appName);e&&e.getAppState()!==x.UNMOUNT&&e.getKeepAliveState()!==T.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){m((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||ze[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()}set data(e){this.appName?ze.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?ze.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function Ke(t){if(!e)return p("preFetch is only supported in browser environment");y((()=>{i(t)&&(t=t()),r(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{y((()=>{var n,s;if(o(e)&&navigator.onLine)if(e.name=A(e.name),e.url=_(e.url,e.name),e.name&&e.url&&!Be.has(e.name)){const i=new Fe({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:ze.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:ze.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Be.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function je(e,t,s){if(r(e)){const i=e.filter((e=>n(e)&&e.includes(`.${t}`)&&!s.has(e)));w(i.map((e=>W(e))),(e=>{const t=i[e.index];s.has(t)||s.set(t,e.data)}),(e=>{p(e)}))}}function Ge(e){const t=[];return Be.forEach(((n,s)=>{x.UNMOUNT===n.getAppState()||n.isPrefetch||e&&T.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Ve(e,t){const n=Be.get(A(e));return new Promise((s=>{if(n)if(n.getAppState()===x.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===T.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=S(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()},r=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",r),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",r),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else d(`app ${e} does not exist`),s()}))}class qe extends Ce{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ke}start(t){if(!e||!window.customElements)return p("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return p(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return d(`element ${this.tagName} is already defined`);if(ue(),t&&o(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.ssr=t.ssr,i(t.fetch)&&(this.fetch=t.fetch),o(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&Ke(t.preFetchApps),t.globalAssets&&(o(n=t.globalAssets)&&y((()=>{je(n.js,"js",pe),je(n.css,"css",Q)}))),o(t.plugins))){const e=t.plugins.modules;if(o(e))for(const t in e){const n=A(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;He(this.tagName)}}var ze=new qe;exports.EventCenterForMicroApp=Re,exports.MicroApp=qe,exports.default=ze,exports.getActiveApps=Ge,exports.getAllApps=function(){return Array.from(Be.keys())},exports.preFetch=Ke,exports.pureCreateElement=D,exports.removeDomScope=R,exports.unmountAllApps=function(e){return Array.from(Be.keys()).reduce(((t,n)=>t.then((()=>Ve(n,e)))),Promise.resolve())},exports.unmountApp=Ve,exports.version="0.8.3"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function s(e){return"boolean"==typeof e}function i(e){return"function"==typeof e}const o=Array.isArray;function r(e){return"[object Object]"===toString.call(e)}function a(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const l=Object.defineProperty,h=Object.defineProperties,u=Object.prototype.hasOwnProperty;function p(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${i} ${e}`,...s):console.error(`[micro-app]${i}`,e,...s)}function d(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${i} ${e}`,...s):console.warn(`[micro-app]${i}`,e,...s)}function m(e,...t){Promise.resolve().then(e.bind(null,...t))}function f(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function _(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(f(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return p(e,t),""}}function A(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function b(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function g(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,b(f(t))).toString()}function w(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{a(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let E=null;function v(e){E=e}function N(e){E!==e&&(v(e),m((()=>{v(null)})))}function C(){return E}function R(){v(null)}function D(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function P(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function M(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function O(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function S(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function I(e){return e?e.replace(/^\s+|\s+$/g,""):""}function L(){return navigator.userAgent.indexOf("Firefox")>-1}var U,x,T,k;!function(e){e.NAME="name",e.URL="url"}(U||(U={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(x||(x={})),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"}(T||(T={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(k||(k={}));const W="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function $(e,t=null,n={}){return i(Qe.fetch)?Qe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const B=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,F=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function H(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class K{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),L()?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):H("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=I(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||B.test(n)||(n=F.test(n)?n.replace(F,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||H("Declaration missing '}'",this.linkPath)):H("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(),f(t.join("/")+"/")}(this.linkPath)),`url("${g(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return H("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return H("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):H("@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):H(`@${t} missing '}'`,this.linkPath)):H(`@${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):H(`@${e} missing '}'`,this.linkPath)):H(`@${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 H("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=I(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(I(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){L()?this.result+=encodeURIComponent(e):this.result+=e}}function j(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=G.exec(e.textContent,n,s,i),G.reset()}catch(e){G.reset(),p("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let G;function V(e,t){if(t.scopecss){const n=`${Qe.tagName}[name=${t.name}]`;if(G||(G=new K),e.textContent)j(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&j(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function q(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function z(e){const t=new CustomEvent("load");q(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function Q(e){const t=new CustomEvent("error");q(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const J=new Map;function X(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=g(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",g(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function Y(e,t,n){const s=Array.from(t.source.links.entries());w(s.map((([e])=>J.has(e)?J.get(e):$(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!J.has(e)&&J.set(e,n);const o=D("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(V(o,i),t.placeholder):s.appendChild(V(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)}))}const Z=new WeakMap;function ee(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 Z.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?V(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 Z.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=X(t,e,n,!0);if(s&&i){const e=D("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,V(i,n),void m((()=>z(s)));if(J.has(e)){const o=J.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,V(i,n),void m((()=>z(s)))}$(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&J.set(e,o),i.textContent=o,V(i,n),z(s)})).catch((e=>{p(e,n.name),Q(s)}))}(s,i,n,t,e),Z.set(t,e),e}return o?(Z.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=me(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>z(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&m(i),_e(e,n,t,!0,i)}if(de.has(e)){const s=de.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&m(i),_e(e,n,t,!0,i)}let o;o=n.inline||t.module?D("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return $(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&de.set(e,r);try{r=ge(e,n,r,t.module),n.inline||t.module?Ae(e,r,t.module,o,i):be(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&z(s)})).catch((e=>{p(e,n.name),Q(s)})),o}(i,o,n,t);return Z.set(t,e),e}{const e=_e(i,n,o,!0);return Z.set(t,e),e}}return s?(Z.set(t,s),s):t}return t}function te(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?ue.rawAppendChild.call(o,s):t!==ue.rawRemoveChild||o.contains(s)?t===ue.rawAppend||t===ue.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?ue.rawAppendChild.call(o,s):t!==ue.rawRemoveChild||o.contains(s)?t===ue.rawAppend||t===ue.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===ue.rawAppend||t===ue.rawPrepend?t.call(n,s):t.call(n,s,i)}function ne(e){var t;return null!==(t=Z.get(e))&&void 0!==t?t:e}function se(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Fe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?te(i,s,e,ee(e,t,i),n&&ne(n)):s===ue.rawAppend||s===ue.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===ue.rawAppend||s===ue.rawPrepend){const n=C();if(!(t instanceof Node)&&n){const i=Fe.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function ie(){!function(){const e=ue.rawDocument;function t(t){var n,s,i;const o=C();return o&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Fe.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:ue.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=C();return o&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Fe.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:ue.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return oe(ue.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return oe(ue.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return oe(ue.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!C()||M(e))return ue.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return ue.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!C()||M(e))return ue.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return ue.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=C();if(!s||O(e)||M(e)||!(null===(t=Fe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return ue.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return ue.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!C()||M(e))return ue.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return ue.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return se(this,e,null,ue.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return se(this,e,t,ue.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return se(this,e,t,ue.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)se(this,e[t],null,ue.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)se(this,e[t-1],null,ue.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Fe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?te(t,ue.rawRemoveChild,this,ne(e)):ue.rawRemoveChild.call(this,e)}return ue.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=ue.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function oe(e){const t=C();return t&&(e.__MICRO_APP_NAME__=t),e}let re=!1;function ae(){v(null),Document.prototype.createElement=ue.rawCreateElement,Document.prototype.createElementNS=ue.rawCreateElementNS,Document.prototype.createDocumentFragment=ue.rawCreateDocumentFragment,Document.prototype.querySelector=ue.rawQuerySelector,Document.prototype.querySelectorAll=ue.rawQuerySelectorAll,Document.prototype.getElementById=ue.rawGetElementById,Document.prototype.getElementsByClassName=ue.rawGetElementsByClassName,Document.prototype.getElementsByTagName=ue.rawGetElementsByTagName,Document.prototype.getElementsByName=ue.rawGetElementsByName,Element.prototype.appendChild=ue.rawAppendChild,Element.prototype.insertBefore=ue.rawInsertBefore,Element.prototype.replaceChild=ue.rawReplaceChild,Element.prototype.removeChild=ue.rawRemoveChild,Element.prototype.append=ue.rawAppend,Element.prototype.prepend=ue.rawPrepend,Element.prototype.cloneNode=ue.rawCloneNode}let ce=!1;function le(){he(),Fe.forEach((e=>{e.container&&S(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Fe.clear()}function he(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",le,!1)}const ue={};function pe(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=C(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,R=b.clearInterval,P=b.clearTimeout,M=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(ue,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:R,rawClearTimeout:P,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:O}),function(){if(!ce){ce=!0;const e=D("style");ue.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Qe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,ue.rawDocument.head.appendChild(e)}}(),he(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",le,!1)}}const de=new Map;function me(e,t,n,s=!1){let i=null,o=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(ue.supportModuleScript&&e.noModule||!ue.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(o){o=g(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function fe(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=de.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push($(e,t.name)),i.push([e,o]))}s.length?w(s,(e=>{!function(e,t,n){t.isGlobal&&!de.has(e)&&de.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function _e(e,t,n,s,i){var o;try{const r=ge(e,t,n.code,n.module);if(t.inline||n.module){const a=D("script");if(Ae(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(be(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Ae(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function be(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ge(e,t,n,s){return r(Qe.plugins)&&(n=function(e,t,n,s){var i;const o=we(s.global,t,e);return we(null===(i=s.modules)||void 0===i?void 0:i[n],o,e)}(e,n,t.name,Qe.plugins)),t.sandBox&&!s?(ue.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${W}){;${n}\n}).call(proxyWindow,${W})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function we(e,t,n){return o(e)?e.reduce(((e,t)=>r(t)&&i(t.loader)?t.loader(e,n,t.options):e),t):t}function ye(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{ye(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",g(n.getAttribute("href"),t.url)):X(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")&&V(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",g(n.getAttribute("src"),t.url))}function Ee(e,t){const n=function(e){const t=D("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),p(e,t.name)}ye(n,t),t.source.links.size?Y(n,t,s):t.onLoad(n),t.source.scripts.size?fe(n,t):t.onLoad(n)}const ve=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(p("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return p("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!r(t))return p("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 Ne(e,t){return n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Ce{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ve.on("global",e,t)}removeGlobalDataListener(e){i(e)&&ve.off("global",e)}setGlobalData(e){R(),ve.dispatch("global",e)}getGlobalData(){return ve.getData("global")}clearGlobalDataListener(){const e=this.appName,t=ve.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 Re extends Ce{addDataListener(e,t,n){ve.on(Ne(A(e),!1),t,n)}removeDataListener(e,t){i(t)&&ve.off(Ne(A(e),!1),t)}getData(e,t=!1){return ve.getData(Ne(A(e),t))}setData(e,t){ve.dispatch(Ne(A(e),!0),t)}clearDataListener(e){ve.off(Ne(A(e),!1))}}class De extends Ce{constructor(e){super(),this.appName=A(e),!this.appName&&p(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ve.on(Ne(this.appName,!0),e,t)}removeDataListener(e){i(e)&&ve.off(Ne(this.appName,!0),e)}getData(){return ve.getData(Ne(this.appName,!0))}dispatch(e){R(),ve.dispatch(Ne(this.appName,!1),e);const t=Fe.get(this.appName);if((null==t?void 0:t.container)&&r(e)){const n=new CustomEvent("datachange",{detail:{data:e}});S(t.container).dispatchEvent(n)}}clearDataListener(){ve.off(Ne(this.appName,!0))}}function Pe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(s(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),i=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=i}(t)&&!function(e){return s(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=c(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&l(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Me=new Map;let Oe=!1;const Se=new Map;function Ie(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=ue;!Oe&&function(){if(Oe=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return d("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Me.forEach((t=>{i(t)&&t.call(document,e)}))}l(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=C();return e?Me.get(e):Me.get("base")},set(e){const s=C();s?Me.set(s,e):Me.set("base",e),!t&&i(e)&&(t=!0,ue.rawDocumentAddEventListener.call(ue.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=C();if(r&&(!(null===(o=Fe.get(r))||void 0===o?void 0:o.umdMode)||!c(s))){const e=Se.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Se.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=C();if(r&&(!(null===(o=Fe.get(r))||void 0===o?void 0:o.umdMode)||!c(s))){const e=Se.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const Le=["unmount","appstate-change"];function Ue(e,t){return Le.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const xe=["System","__cjsWrapper"],Te=["location"],ke=["window","self","globalThis"];class We{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=ue;e.addEventListener=function(t,s,i){t=Ue(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=Ue(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Me.get(t);const e=Se.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Me.set(t,_),v(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),v(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Me.delete(t);const e=Se.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,ue.rawWindow._babelPolyfill&&(ue.rawWindow._babelPolyfill=!1),1==++We.activeCount&&(Ie(),ie()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(ue.rawWindow,e)})),this.escapeKeys.clear(),0==--We.activeCount&&(document.addEventListener=ue.rawDocumentAddEventListener,document.removeEventListener=ue.rawDocumentRemoveEventListener,ae()))}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=ve.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=ve.eventList.get(Ne(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;r(Qe.plugins)&&(this.commonActionForSpecialProperties(Qe.plugins.global),this.commonActionForSpecialProperties(null===(t=Qe.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(o(e))for(const t of e)r(t)&&(o(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),o(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=ue.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(s,o)=>{if(N(e),Reflect.has(s,o)||n(o)&&/^__MICRO_APP_/.test(o)||this.scopeProperties.includes(o))return Reflect.get(s,o);const r=Reflect.get(t,o);return i(r)?Pe(t,r):r},set:(e,n,s)=>{if(this.active){if(Te.includes(n))Reflect.set(t,n,s);else if(u.call(e,n)||!u.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;l(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||xe.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(u.call(e,n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(u.call(t,n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,i)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,i):Reflect.defineProperty(e,n,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))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=b(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new De(t),{removeDomScope:R,pureCreateElement:D}),e.rawWindow=ue.rawWindow,e.rawDocument=ue.rawDocument,e.hasOwnProperty=t=>u.call(e,t)||u.call(ue.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=ue.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),l(e,"top",this.createDescriptorForMicroAppWindow("top",t)),l(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),ke.forEach((t=>{l(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(ue.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;h(e,{document:{get:()=>(N(t),ue.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(N(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(N(t),s||ue.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function $e(e,t,n,s){var o;if(!e)return p(`element does not exist in lifecycle ${n}`,t);e=S(e),R();const r=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:r});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),i(null===(o=Qe.lifeCycles)||void 0===o?void 0:o[n])&&Qe.lifeCycles[n](a),e.dispatchEvent(a)}function Be(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}We.activeCount=0;const Fe=new Map;class He{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=x.NOT_LOADED,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.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new We(e,t))}loadSourceCode(){var e;this.state=x.LOADING_SOURCE_CODE,$((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)),p(t,e.name)}Ee(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=>{p(`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):x.UNMOUNT!==this.state&&(this.state=x.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),x.UNMOUNT!==this.state&&(this.onerror(e),this.state=x.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,a;if(s(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(o=this.container)&&void 0!==o?o:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=x.LOADING_SOURCE_CODE);let c;if($e(this.container,this.name,T.BEFOREMOUNT),this.state=x.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push($(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(_e(e,t,r,!1),n(!1)));i.length?w(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,p(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(_e(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===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(i(e)&&i(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){p("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(){x.UNMOUNT!==this.state&&(this.state=x.MOUNTED,$e(this.container,this.name,T.MOUNTED))}unmount(e,t){let n;if(this.state===x.LOAD_SOURCE_ERROR&&(e=!0),this.state=x.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){p("an error occurred in the unmount function \n",this.name,e)}Be("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&&P(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),Ve().length||(re=!1,Element.prototype.setAttribute=ue.rawSetAttribute),$e(this.container,this.name,T.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Fe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;P(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=k.KEEP_ALIVE_HIDDEN,Be("appstate-change",this.name,{appState:"afterhidden"}),$e(e,this.name,T.AFTERHIDDEN)}showKeepAliveApp(e){Be("appstate-change",this.name,{appState:"beforeshow"}),$e(e,this.name,T.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=k.KEEP_ALIVE_SHOW,Be("appstate-change",this.name,{appState:"aftershow"}),$e(this.container,this.name,T.AFTERSHOW)}onerror(e){$e(this.container,this.name,T.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(x.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:ue.rawWindow;return this.libraryName=S(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Ke(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.8.4",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=A(this.getAttribute("name")),t=_(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Fe.get(e);if(e!==this.appName&&n&&x.UNMOUNT!==n.getAppState()&&k.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),p(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},re||(re=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(r(t)){const e={};Object.getOwnPropertyNames(t).forEach((s=>{n(s)&&0===s.indexOf("__")||(e[s]=t[s])})),this.data=e}else"[object Object]"!==t&&d("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Fe.has(this.__MICRO_APP_NAME__)){const n=Fe.get(this.__MICRO_APP_NAME__);ue.rawSetAttribute.call(this,e,g(t,n.url))}else ue.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,m((()=>$e(this,this.appName,T.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===U.NAME?"appName":"appUrl"]!==n)if(e!==U.URL||this.appUrl)if(e!==U.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,m(this.handleAttributeUpdate));else{const e=A(n);if(!e)return p(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Qe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=_(n,this.appName)))return p(`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&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=g(ue.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Fe.has(this.appName)){const e=Fe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==x.UNMOUNT?e.isPrefetch||e.getAppState()===x.UNMOUNT?(d(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):p(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=g(ue.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):p(`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!(!n(t)||!t)||(p(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,m((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Fe.has(this.appName)&&Fe.get(this.appName).actionsForCompletelyDestroy();const t=new He({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"),baseroute:this.getBaseRouteCompatible()});Fe.set(this.appName,t)}handleUnmount(e,t){const n=Fe.get(this.appName);n&&n.getAppState()!==x.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Fe.get(this.appName);e&&e.getAppState()!==x.UNMOUNT&&e.getKeepAliveState()!==k.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){m((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Qe[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()}set data(e){this.appName?Qe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Qe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function je(t){if(!e)return p("preFetch is only supported in browser environment");y((()=>{i(t)&&(t=t()),o(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{y((()=>{var n,s;if(r(e)&&navigator.onLine)if(e.name=A(e.name),e.url=_(e.url,e.name),e.name&&e.url&&!Fe.has(e.name)){const i=new He({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Qe.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Qe.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Fe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Ge(e,t,s){if(o(e)){const i=e.filter((e=>n(e)&&e.includes(`.${t}`)&&!s.has(e)));w(i.map((e=>$(e))),(e=>{const t=i[e.index];s.has(t)||s.set(t,e.data)}),(e=>{p(e)}))}}function Ve(e){const t=[];return Fe.forEach(((n,s)=>{x.UNMOUNT===n.getAppState()||n.isPrefetch||e&&k.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function qe(e,t){const n=Fe.get(A(e));return new Promise((s=>{if(n)if(n.getAppState()===x.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=S(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),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 d(`app ${e} does not exist`),s()}))}class ze extends Re{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=je}start(t){if(!e||!window.customElements)return p("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return p(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return d(`element ${this.tagName} is already defined`);if(pe(),t&&r(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.ssr=t.ssr,i(t.fetch)&&(this.fetch=t.fetch),r(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&je(t.preFetchApps),t.globalAssets&&(r(n=t.globalAssets)&&y((()=>{Ge(n.js,"js",de),Ge(n.css,"css",J)}))),r(t.plugins))){const e=t.plugins.modules;if(r(e))for(const t in e){const n=A(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;Ke(this.tagName)}}var Qe=new ze;exports.EventCenterForMicroApp=De,exports.MicroApp=ze,exports.default=Qe,exports.getActiveApps=Ve,exports.getAllApps=function(){return Array.from(Fe.keys())},exports.preFetch=je,exports.pureCreateElement=D,exports.removeDomScope=R,exports.unmountAllApps=function(e){return Array.from(Fe.keys()).reduce(((t,n)=>t.then((()=>qe(n,e)))),Promise.resolve())},exports.unmountApp=qe,exports.version="0.8.4"; | ||
//# sourceMappingURL=index.min.js.map |
@@ -1,2 +0,2 @@ | ||
!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="0.8.3",n="undefined"!=typeof window,s="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function i(e){return"string"==typeof e}function o(e){return"boolean"==typeof e}function r(e){return"function"==typeof e}const a=Array.isArray;function c(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function h(e){return r(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const u=Object.defineProperty,p=Object.defineProperties,d=Object.prototype.hasOwnProperty;function m(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.error(`[micro-app]${s} ${e}`,...n):console.error(`[micro-app]${s}`,e,...n)}function f(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.warn(`[micro-app]${s} ${e}`,...n):console.warn(`[micro-app]${s}`,e,...n)}function _(e,...t){Promise.resolve().then(e.bind(null,...t))}function A(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function b(e,t=null){if(!i(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(A(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return m(e,t),""}}function g(e){return i(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function w(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function y(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,w(A(t))).toString()}function E(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const v=s.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let N=null;function C(e){N=e}function R(e){N!==e&&(C(e),_((()=>{C(null)})))}function D(){return N}function P(){C(null)}function M(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function O(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function S(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function I(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function L(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function U(e){return e?e.replace(/^\s+|\s+$/g,""):""}var x,T,k,W;!function(e){e.NAME="name",e.URL="url"}(x||(x={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(T||(T={})),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"}(k||(k={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(W||(W={}));const $="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function B(e,t=null,n={}){return r(Je.fetch)?Je.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const F=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,H=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function K(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class j{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),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();return this.scopecssDisableNextLine=!1,e?(this.result+=e.join(", "),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):K("selector missing",this.linkPath)}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||K("Declaration missing '}'",this.linkPath)):K("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(),A(t.join("/")+"/")}(this.linkPath)),`url("${y(t,this.baseURI)}")`)))),this.result+=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()}formatSelector(){const e=this.commonMatch(/^([^{]+)/,!0);return!!e&&U(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,(e=>e.replace(/,/g,""))).split(/\s*(?![^(]*\)),\s*/).map((e=>{const t=e.replace(/\u200C/g,",");return this.scopecssDisableNextLine?t:!this.scopecssDisable||this.scopecssDisableSelectors.length&&!this.scopecssDisableSelectors.includes(t)?"*"===t?this.prefix+" *":H.test(t)?t.replace(H,this.prefix+" micro-app-body"):F.test(t)?t:this.prefix+" "+t:t}))}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return K("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return K("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):K("@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(),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):K(`@${t} missing '}'`,this.linkPath)):K(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!1)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):K(`@${e} missing '}'`,this.linkPath)):K(`@${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 K("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.result+=`/*${t}*/`,t=U(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(U(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||(this.result+=s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}}function G(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=V.exec(e.textContent,n,s,i),V.reset()}catch(e){V.reset(),m("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let V;function q(e,t){if(t.scopecss){const n=`${Je.tagName}[name=${t.name}]`;if(V||(V=new j),e.textContent)G(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&G(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function z(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function Q(e){const t=new CustomEvent("load");z(t,e),r(e.onload)?e.onload(t):e.dispatchEvent(t)}function J(e){const t=new CustomEvent("error");z(t,e),r(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const X=new Map;function Y(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=y(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",y(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function Z(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>X.has(e)?X.get(e):B(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!X.has(e)&&X.set(e,n);const o=M("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(q(o,i),t.placeholder):s.appendChild(q(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)}))}const ee=new WeakMap;function te(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 ee.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?q(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 ee.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=Y(t,e,n,!0);if(s&&i){const e=M("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,q(i,n),void _((()=>Q(s)));if(X.has(e)){const o=X.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,q(i,n),void _((()=>Q(s)))}B(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&X.set(e,o),i.textContent=o,q(i,n),Q(s)})).catch((e=>{m(e,n.name),J(s)}))}(s,i,n,t,e),ee.set(t,e),e}return o?(ee.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=fe(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>Q(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),Ae(e,n,t,!0,i)}if(me.has(e)){const s=me.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),Ae(e,n,t,!0,i)}let o;o=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return B(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&me.set(e,r);try{r=we(e,n,r,t.module),n.inline||t.module?be(e,r,t.module,o,i):ge(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&Q(s)})).catch((e=>{m(e,n.name),J(s)})),o}(i,o,n,t);return ee.set(t,e),e}{const e=Ae(i,n,o,!0);return ee.set(t,e),e}}return s?(ee.set(t,s),s):t}return t}function ne(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?pe.rawAppendChild.call(o,s):t!==pe.rawRemoveChild||o.contains(s)?t===pe.rawAppend||t===pe.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?pe.rawAppendChild.call(o,s):t!==pe.rawRemoveChild||o.contains(s)?t===pe.rawAppend||t===pe.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===pe.rawAppend||t===pe.rawPrepend?t.call(n,s):t.call(n,s,i)}function se(e){var t;return null!==(t=ee.get(e))&&void 0!==t?t:e}function ie(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=He.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ne(i,s,e,te(e,t,i),n&&se(n)):s===pe.rawAppend||s===pe.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===pe.rawAppend||s===pe.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=He.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function oe(){!function(){const e=pe.rawDocument;function t(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=He.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:pe.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=He.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:pe.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return re(pe.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return re(pe.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return re(pe.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(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(!D()||S(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 s=D();if(!s||I(e)||S(e)||!(null===(t=He.get(s))||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(!D()||S(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 ie(this,e,null,pe.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return ie(this,e,t,pe.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return ie(this,e,t,pe.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ie(this,e[t],null,pe.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ie(this,e[t-1],null,pe.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=He.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ne(t,pe.rawRemoveChild,this,se(e)):pe.rawRemoveChild.call(this,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 re(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ae=!1;function ce(){C(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 le=!1;function he(){ue(),He.forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&He.clear()}function ue(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",he,!1)}const pe={};function de(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=D(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,C=b.clearInterval,R=b.clearTimeout,P=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(pe,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:R,rawDocumentAddEventListener:P,rawDocumentRemoveEventListener:O}),function(){if(!le){le=!0;const e=M("style");pe.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Je.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,pe.rawDocument.head.appendChild(e)}}(),ue(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",he,!1)}}const me=new Map;function fe(e,t,n,s=!1){let i=null,o=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(o){o=y(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function _e(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=me.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push(B(e,t.name)),i.push([e,o]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!me.has(e)&&me.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Ae(e,t,n,s,i){var o;try{const r=we(e,t,n.code,n.module);if(t.inline||n.module){const a=M("script");if(be(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(ge(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function be(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function ge(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function we(e,t,n,s){return c(Je.plugins)&&(n=function(e,t,n,s){var i;const o=ye(s.global,t,e);return ye(null===(i=s.modules)||void 0===i?void 0:i[n],o,e)}(e,n,t.name,Je.plugins)),t.sandBox&&!s?(pe.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${$}){;${n}\n}).call(proxyWindow,${$})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function ye(e,t,n){return a(e)?e.reduce(((e,t)=>c(t)&&r(t.loader)?t.loader(e,n,t.options):e),t):t}function Ee(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{Ee(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):Y(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")&&q(n,t):n instanceof HTMLScriptElement?fe(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",y(n.getAttribute("src"),t.url))}function ve(e,t){const n=function(e){const t=M("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),m(e,t.name)}Ee(n,t),t.source.links.size?Z(n,t,s):t.onLoad(n),t.source.scripts.size?_e(n,t):t.onLoad(n)}const Ne=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(m("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!r(t))return m("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(r(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!c(t))return m("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 Ce(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Re{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ne.on("global",e,t)}removeGlobalDataListener(e){r(e)&&Ne.off("global",e)}setGlobalData(e){P(),Ne.dispatch("global",e)}getGlobalData(){return Ne.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ne.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 De extends Re{addDataListener(e,t,n){Ne.on(Ce(g(e),!1),t,n)}removeDataListener(e,t){r(t)&&Ne.off(Ce(g(e),!1),t)}getData(e,t=!1){return Ne.getData(Ce(g(e),t))}setData(e,t){Ne.dispatch(Ce(g(e),!0),t)}clearDataListener(e){Ne.off(Ce(g(e),!1))}}class Pe extends Re{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ne.on(Ce(this.appName,!0),e,t)}removeDataListener(e){r(e)&&Ne.off(Ce(this.appName,!0),e)}getData(){return Ne.getData(Ce(this.appName,!0))}dispatch(e){P(),Ne.dispatch(Ce(this.appName,!1),e);const t=He.get(this.appName);if((null==t?void 0:t.container)&&c(e)){const n=new CustomEvent("datachange",{detail:{data:e}});L(t.container).dispatchEvent(n)}}clearDataListener(){Ne.off(Ce(this.appName,!0))}}function Me(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(o(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),s=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=s}(t)&&!function(e){return o(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=h(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&u(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Oe=new Map;let Se=!1;const Ie=new Map;function Le(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=pe;!Se&&function(){if(Se=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return f("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Oe.forEach((t=>{r(t)&&t.call(document,e)}))}u(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?Oe.get(e):Oe.get("base")},set(e){const s=D();s?Oe.set(s,e):Oe.set("base",e),!t&&r(e)&&(t=!0,pe.rawDocumentAddEventListener.call(pe.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=D();if(r&&(!(null===(o=He.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Ie.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Ie.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=D();if(r&&(!(null===(o=He.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Ie.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const Ue=["unmount","appstate-change"];function xe(e,t){return Ue.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Te=["System","__cjsWrapper"],ke=["location"],We=["window","self","globalThis"];class $e{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=pe;e.addEventListener=function(t,s,i){t=xe(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=xe(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Oe.get(t);const e=Ie.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Oe.set(t,_),C(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),C(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Oe.delete(t);const e=Ie.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,pe.rawWindow._babelPolyfill&&(pe.rawWindow._babelPolyfill=!1),1==++$e.activeCount&&(Le(),oe()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(pe.rawWindow,e)})),this.escapeKeys.clear(),0==--$e.activeCount&&(document.addEventListener=pe.rawDocumentAddEventListener,document.removeEventListener=pe.rawDocumentRemoveEventListener,ce()))}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=Ne.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Ne.eventList.get(Ce(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;c(Je.plugins)&&(this.commonActionForSpecialProperties(Je.plugins.global),this.commonActionForSpecialProperties(null===(t=Je.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(a(e))for(const t of e)c(t)&&(a(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),a(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=pe.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,s)=>{if(R(e),Reflect.has(n,s)||i(s)&&/^__MICRO_APP_/.test(s)||this.scopeProperties.includes(s))return Reflect.get(n,s);const o=Reflect.get(t,s);return r(o)?Me(t,o):o},set:(e,n,s)=>{if(this.active){if(ke.includes(n))Reflect.set(t,n,s);else if(d.call(e,n)||!d.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;u(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||Te.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,s)=>{if(d.call(e,s))return n.set(s,"target"),Object.getOwnPropertyDescriptor(e,s);if(d.call(t,s)){n.set(s,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,s);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,s,i)=>"rawWindow"===n.get(s)?Reflect.defineProperty(t,s,i):Reflect.defineProperty(e,s,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)=>!d.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=w(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Pe(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=pe.rawWindow,e.rawDocument=pe.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(pe.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=pe.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),u(e,"top",this.createDescriptorForMicroAppWindow("top",t)),u(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),We.forEach((t=>{u(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(pe.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),pe.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||pe.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Be(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const o=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:o});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),r(null===(i=Je.lifeCycles)||void 0===i?void 0:i[n])&&Je.lifeCycles[n](a),e.dispatchEvent(a)}function Fe(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}$e.activeCount=0;const He=new Map;class Ke{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=T.NOT_LOADED,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.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new $e(e,t))}loadSourceCode(){var e;this.state=T.LOADING_SOURCE_CODE,B((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)),m(t,e.name)}ve(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=>{m(`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):T.UNMOUNT!==this.state&&(this.state=T.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),T.UNMOUNT!==this.state&&(this.onerror(e),this.state=T.LOAD_SOURCE_ERROR)}mount(e,t,n){var s,i,a;if(o(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=T.LOADING_SOURCE_CODE);let c;if(Be(this.container,this.name,k.BEFOREMOUNT),this.state=T.MOUNTING,O(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push(B(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ae(e,t,r,!1),n(!1)));i.length?E(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(Ae(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===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(r(e)&&r(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){m("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){T.UNMOUNT!==this.state&&(this.state=T.MOUNTED,Be(this.container,this.name,k.MOUNTED))}unmount(e,t){let n;if(this.state===T.LOAD_SOURCE_ERROR&&(e=!0),this.state=T.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){m("an error occurred in the unmount function \n",this.name,e)}Fe("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){l(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&&O(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),qe().length||(ae=!1,Element.prototype.setAttribute=pe.rawSetAttribute),Be(this.container,this.name,k.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],He.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;O(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=W.KEEP_ALIVE_HIDDEN,Fe("appstate-change",this.name,{appState:"afterhidden"}),Be(e,this.name,k.AFTERHIDDEN)}showKeepAliveApp(e){Fe("appstate-change",this.name,{appState:"beforeshow"}),Be(e,this.name,k.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=W.KEEP_ALIVE_SHOW,Fe("appstate-change",this.name,{appState:"aftershow"}),Be(this.container,this.name,k.AFTERSHOW)}onerror(e){Be(this.container,this.name,k.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(T.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=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function je(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=g(this.getAttribute("name")),t=b(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=He.get(e);if(e!==this.appName&&n&&T.UNMOUNT!==n.getAppState()&&W.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),m(`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)},ae||(ae=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(c(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{i(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&f("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&He.has(this.__MICRO_APP_NAME__)){const n=He.get(this.__MICRO_APP_NAME__);pe.rawSetAttribute.call(this,e,y(t,n.url))}else pe.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>Be(this,this.appName,k.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===x.NAME?"appName":"appUrl"]!==n)if(e!==x.URL||this.appUrl)if(e!==x.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,_(this.handleAttributeUpdate));else{const e=g(n);if(!e)return m(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Je.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=b(n,this.appName)))return m(`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&&r(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(pe.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),He.has(this.appName)){const e=He.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===W.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==T.UNMOUNT?e.isPrefetch||e.getAppState()===T.UNMOUNT?(f(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):m(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=y(pe.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===W.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):m(`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!(!i(t)||!t)||(m(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,_((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;He.has(this.appName)&&He.get(this.appName).actionsForCompletelyDestroy();const t=new Ke({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"),baseroute:this.getBaseRouteCompatible()});He.set(this.appName,t)}handleUnmount(e,t){const n=He.get(this.appName);n&&n.getAppState()!==T.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=He.get(this.appName);e&&e.getAppState()!==T.UNMOUNT&&e.getKeepAliveState()!==W.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){_((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Je[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()}set data(e){this.appName?Je.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Je.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ge(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{r(e)&&(e=e()),a(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{v((()=>{var n,s;if(c(e)&&navigator.onLine)if(e.name=g(e.name),e.url=b(e.url,e.name),e.name&&e.url&&!He.has(e.name)){const i=new Ke({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Je.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Je.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,He.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Ve(e,t,n){if(a(e)){const s=e.filter((e=>i(e)&&e.includes(`.${t}`)&&!n.has(e)));E(s.map((e=>B(e))),(e=>{const t=s[e.index];n.has(t)||n.set(t,e.data)}),(e=>{m(e)}))}}function qe(e){const t=[];return He.forEach(((n,s)=>{T.UNMOUNT===n.getAppState()||n.isPrefetch||e&&W.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function ze(e,t){const n=He.get(g(e));return new Promise((s=>{if(n)if(n.getAppState()===T.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===W.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=L(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),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 f(`app ${e} does not exist`),s()}))}class Qe extends De{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ge}start(e){if(!n||!window.customElements)return m("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return m(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return f(`element ${this.tagName} is already defined`);if(de(),e&&c(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.ssr=e.ssr,r(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ge(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{Ve(t.js,"js",me),Ve(t.css,"css",X)}))),c(e.plugins))){const t=e.plugins.modules;if(c(t))for(const e in t){const n=g(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;je(this.tagName)}}var Je=new Qe;e.EventCenterForMicroApp=Pe,e.MicroApp=Qe,e.default=Je,e.getActiveApps=qe,e.getAllApps=function(){return Array.from(He.keys())},e.preFetch=Ge,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(He.keys()).reduce(((t,n)=>t.then((()=>ze(n,e)))),Promise.resolve())},e.unmountApp=ze,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!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="0.8.4",n="undefined"!=typeof window,s="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function i(e){return"string"==typeof e}function o(e){return"boolean"==typeof e}function r(e){return"function"==typeof e}const a=Array.isArray;function c(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function h(e){return r(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const u=Object.defineProperty,p=Object.defineProperties,d=Object.prototype.hasOwnProperty;function m(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.error(`[micro-app]${s} ${e}`,...n):console.error(`[micro-app]${s}`,e,...n)}function f(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.warn(`[micro-app]${s} ${e}`,...n):console.warn(`[micro-app]${s}`,e,...n)}function _(e,...t){Promise.resolve().then(e.bind(null,...t))}function A(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function b(e,t=null){if(!i(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(A(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return m(e,t),""}}function g(e){return i(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function w(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function y(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,w(A(t))).toString()}function E(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const v=s.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let N=null;function C(e){N=e}function R(e){N!==e&&(C(e),_((()=>{C(null)})))}function D(){return N}function P(){C(null)}function M(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function O(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function S(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function I(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function L(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function U(e){return e?e.replace(/^\s+|\s+$/g,""):""}function x(){return navigator.userAgent.indexOf("Firefox")>-1}var T,k,W,$;!function(e){e.NAME="name",e.URL="url"}(T||(T={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(k||(k={})),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"}(W||(W={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}($||($={}));const B="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function F(e,t=null,n={}){return r(Xe.fetch)?Xe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const H=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,K=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function j(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class G{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),x()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&"}"!==this.cssText.charAt(0)&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):j("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=U(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||H.test(n)||(n=K.test(n)?n.replace(K,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||j("Declaration missing '}'",this.linkPath)):j("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),A(t.join("/")+"/")}(this.linkPath)),`url("${y(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return j("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return j("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${t} missing '}'`,this.linkPath)):j(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${e} missing '}'`,this.linkPath)):j(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if("/"!==this.cssText.charAt(0)||"*"!==this.cssText.charAt(1))return!1;this.scopecssDisableNextLine=!1;let e=2;for(;""!==this.cssText.charAt(e)&&("*"!==this.cssText.charAt(e)||"/"!==this.cssText.charAt(e+1));)++e;if(e+=2,""===this.cssText.charAt(e-1))return j("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=U(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(U(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){x()?this.result+=encodeURIComponent(e):this.result+=e}}function V(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=q.exec(e.textContent,n,s,i),q.reset()}catch(e){q.reset(),m("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let q;function z(e,t){if(t.scopecss){const n=`${Xe.tagName}[name=${t.name}]`;if(q||(q=new G),e.textContent)V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function Q(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function J(e){const t=new CustomEvent("load");Q(t,e),r(e.onload)?e.onload(t):e.dispatchEvent(t)}function X(e){const t=new CustomEvent("error");Q(t,e),r(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Y=new Map;function Z(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=y(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",y(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ee(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>Y.has(e)?Y.get(e):F(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Y.has(e)&&Y.set(e,n);const o=M("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(z(o,i),t.placeholder):s.appendChild(z(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)}))}const te=new WeakMap;function ne(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 te.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?z(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 te.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=Z(t,e,n,!0);if(s&&i){const e=M("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,z(i,n),void _((()=>J(s)));if(Y.has(e)){const o=Y.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,z(i,n),void _((()=>J(s)))}F(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&Y.set(e,o),i.textContent=o,z(i,n),J(s)})).catch((e=>{m(e,n.name),X(s)}))}(s,i,n,t,e),te.set(t,e),e}return o?(te.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=_e(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>J(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),be(e,n,t,!0,i)}if(fe.has(e)){const s=fe.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),be(e,n,t,!0,i)}let o;o=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return F(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&fe.set(e,r);try{r=ye(e,n,r,t.module),n.inline||t.module?ge(e,r,t.module,o,i):we(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&J(s)})).catch((e=>{m(e,n.name),X(s)})),o}(i,o,n,t);return te.set(t,e),e}{const e=be(i,n,o,!0);return te.set(t,e),e}}return s?(te.set(t,s),s):t}return t}function se(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===de.rawAppend||t===de.rawPrepend?t.call(n,s):t.call(n,s,i)}function ie(e){var t;return null!==(t=te.get(e))&&void 0!==t?t:e}function oe(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Ke.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?se(i,s,e,ne(e,t,i),n&&ie(n)):s===de.rawAppend||s===de.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===de.rawAppend||s===de.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=Ke.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function re(){!function(){const e=de.rawDocument;function t(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:de.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:de.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ae(de.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ae(de.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ae(de.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(e))return de.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return de.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!D()||S(e))return de.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return de.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=D();if(!s||I(e)||S(e)||!(null===(t=Ke.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return de.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return de.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!D()||S(e))return de.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return de.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return oe(this,e,null,de.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return oe(this,e,t,de.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return oe(this,e,t,de.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)oe(this,e[t],null,de.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)oe(this,e[t-1],null,de.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ke.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?se(t,de.rawRemoveChild,this,ie(e)):de.rawRemoveChild.call(this,e)}return de.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=de.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ae(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ce=!1;function le(){C(null),Document.prototype.createElement=de.rawCreateElement,Document.prototype.createElementNS=de.rawCreateElementNS,Document.prototype.createDocumentFragment=de.rawCreateDocumentFragment,Document.prototype.querySelector=de.rawQuerySelector,Document.prototype.querySelectorAll=de.rawQuerySelectorAll,Document.prototype.getElementById=de.rawGetElementById,Document.prototype.getElementsByClassName=de.rawGetElementsByClassName,Document.prototype.getElementsByTagName=de.rawGetElementsByTagName,Document.prototype.getElementsByName=de.rawGetElementsByName,Element.prototype.appendChild=de.rawAppendChild,Element.prototype.insertBefore=de.rawInsertBefore,Element.prototype.replaceChild=de.rawReplaceChild,Element.prototype.removeChild=de.rawRemoveChild,Element.prototype.append=de.rawAppend,Element.prototype.prepend=de.rawPrepend,Element.prototype.cloneNode=de.rawCloneNode}let he=!1;function ue(){pe(),Ke.forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Ke.clear()}function pe(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ue,!1)}const de={};function me(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=D(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,C=b.clearInterval,R=b.clearTimeout,P=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(de,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:R,rawDocumentAddEventListener:P,rawDocumentRemoveEventListener:O}),function(){if(!he){he=!0;const e=M("style");de.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Xe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,de.rawDocument.head.appendChild(e)}}(),pe(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ue,!1)}}const fe=new Map;function _e(e,t,n,s=!1){let i=null,o=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(de.supportModuleScript&&e.noModule||!de.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(o){o=y(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function Ae(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=fe.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push(F(e,t.name)),i.push([e,o]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!fe.has(e)&&fe.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function be(e,t,n,s,i){var o;try{const r=ye(e,t,n.code,n.module);if(t.inline||n.module){const a=M("script");if(ge(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(we(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ge(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function we(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ye(e,t,n,s){return c(Xe.plugins)&&(n=function(e,t,n,s){var i;const o=Ee(s.global,t,e);return Ee(null===(i=s.modules)||void 0===i?void 0:i[n],o,e)}(e,n,t.name,Xe.plugins)),t.sandBox&&!s?(de.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${B}){;${n}\n}).call(proxyWindow,${B})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Ee(e,t,n){return a(e)?e.reduce(((e,t)=>c(t)&&r(t.loader)?t.loader(e,n,t.options):e),t):t}function ve(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{ve(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):Z(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")&&z(n,t):n instanceof HTMLScriptElement?_e(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",y(n.getAttribute("src"),t.url))}function Ne(e,t){const n=function(e){const t=M("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),m(e,t.name)}ve(n,t),t.source.links.size?ee(n,t,s):t.onLoad(n),t.source.scripts.size?Ae(n,t):t.onLoad(n)}const Ce=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(m("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!r(t))return m("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(r(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!c(t))return m("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 Re(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class De{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ce.on("global",e,t)}removeGlobalDataListener(e){r(e)&&Ce.off("global",e)}setGlobalData(e){P(),Ce.dispatch("global",e)}getGlobalData(){return Ce.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ce.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 Pe extends De{addDataListener(e,t,n){Ce.on(Re(g(e),!1),t,n)}removeDataListener(e,t){r(t)&&Ce.off(Re(g(e),!1),t)}getData(e,t=!1){return Ce.getData(Re(g(e),t))}setData(e,t){Ce.dispatch(Re(g(e),!0),t)}clearDataListener(e){Ce.off(Re(g(e),!1))}}class Me extends De{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ce.on(Re(this.appName,!0),e,t)}removeDataListener(e){r(e)&&Ce.off(Re(this.appName,!0),e)}getData(){return Ce.getData(Re(this.appName,!0))}dispatch(e){P(),Ce.dispatch(Re(this.appName,!1),e);const t=Ke.get(this.appName);if((null==t?void 0:t.container)&&c(e)){const n=new CustomEvent("datachange",{detail:{data:e}});L(t.container).dispatchEvent(n)}}clearDataListener(){Ce.off(Re(this.appName,!0))}}function Oe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(o(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),s=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=s}(t)&&!function(e){return o(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=h(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&u(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Se=new Map;let Ie=!1;const Le=new Map;function Ue(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=de;!Ie&&function(){if(Ie=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return f("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Se.forEach((t=>{r(t)&&t.call(document,e)}))}u(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?Se.get(e):Se.get("base")},set(e){const s=D();s?Se.set(s,e):Se.set("base",e),!t&&r(e)&&(t=!0,de.rawDocumentAddEventListener.call(de.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Le.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const xe=["unmount","appstate-change"];function Te(e,t){return xe.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const ke=["System","__cjsWrapper"],We=["location"],$e=["window","self","globalThis"];class Be{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=de;e.addEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Se.get(t);const e=Le.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Se.set(t,_),C(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),C(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Se.delete(t);const e=Le.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,de.rawWindow._babelPolyfill&&(de.rawWindow._babelPolyfill=!1),1==++Be.activeCount&&(Ue(),re()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(de.rawWindow,e)})),this.escapeKeys.clear(),0==--Be.activeCount&&(document.addEventListener=de.rawDocumentAddEventListener,document.removeEventListener=de.rawDocumentRemoveEventListener,le()))}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=Ce.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Ce.eventList.get(Re(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))}))}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach(((e,t)=>{Reflect.set(this.proxyWindow,t,e)})),this.rebuildUmdEffect(),function(e){for(const t of e.umdDataListeners.global)e.addGlobalDataListener(t,t.__AUTO_TRIGGER__);for(const t of e.umdDataListeners.normal)e.addDataListener(t,t.__AUTO_TRIGGER__)}(this.microAppWindow.microApp)}getSpecialProperties(e){var t;c(Xe.plugins)&&(this.commonActionForSpecialProperties(Xe.plugins.global),this.commonActionForSpecialProperties(null===(t=Xe.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(a(e))for(const t of e)c(t)&&(a(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),a(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=de.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,s)=>{if(R(e),Reflect.has(n,s)||i(s)&&/^__MICRO_APP_/.test(s)||this.scopeProperties.includes(s))return Reflect.get(n,s);const o=Reflect.get(t,s);return r(o)?Oe(t,o):o},set:(e,n,s)=>{if(this.active){if(We.includes(n))Reflect.set(t,n,s);else if(d.call(e,n)||!d.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;u(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||ke.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,s)=>{if(d.call(e,s))return n.set(s,"target"),Object.getOwnPropertyDescriptor(e,s);if(d.call(t,s)){n.set(s,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,s);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,s,i)=>"rawWindow"===n.get(s)?Reflect.defineProperty(t,s,i):Reflect.defineProperty(e,s,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)=>!d.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=w(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Me(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=de.rawWindow,e.rawDocument=de.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(de.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=de.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),u(e,"top",this.createDescriptorForMicroAppWindow("top",t)),u(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),$e.forEach((t=>{u(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(de.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),de.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||de.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Fe(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const o=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:o});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),r(null===(i=Xe.lifeCycles)||void 0===i?void 0:i[n])&&Xe.lifeCycles[n](a),e.dispatchEvent(a)}function He(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}Be.activeCount=0;const Ke=new Map;class je{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=k.NOT_LOADED,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.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Be(e,t))}loadSourceCode(){var e;this.state=k.LOADING_SOURCE_CODE,F((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)),m(t,e.name)}Ne(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=>{m(`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):k.UNMOUNT!==this.state&&(this.state=k.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),k.UNMOUNT!==this.state&&(this.onerror(e),this.state=k.LOAD_SOURCE_ERROR)}mount(e,t,n){var s,i,a;if(o(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=k.LOADING_SOURCE_CODE);let c;if(Fe(this.container,this.name,W.BEFOREMOUNT),this.state=k.MOUNTING,O(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push(F(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(be(e,t,r,!1),n(!1)));i.length?E(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(be(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===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(r(e)&&r(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){m("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){k.UNMOUNT!==this.state&&(this.state=k.MOUNTED,Fe(this.container,this.name,W.MOUNTED))}unmount(e,t){let n;if(this.state===k.LOAD_SOURCE_ERROR&&(e=!0),this.state=k.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){m("an error occurred in the unmount function \n",this.name,e)}He("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){l(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&&O(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),ze().length||(ce=!1,Element.prototype.setAttribute=de.rawSetAttribute),Fe(this.container,this.name,W.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Ke.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;O(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=$.KEEP_ALIVE_HIDDEN,He("appstate-change",this.name,{appState:"afterhidden"}),Fe(e,this.name,W.AFTERHIDDEN)}showKeepAliveApp(e){He("appstate-change",this.name,{appState:"beforeshow"}),Fe(e,this.name,W.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=$.KEEP_ALIVE_SHOW,He("appstate-change",this.name,{appState:"aftershow"}),Fe(this.container,this.name,W.AFTERSHOW)}onerror(e){Fe(this.container,this.name,W.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(k.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:de.rawWindow;return this.libraryName=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Ge(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=g(this.getAttribute("name")),t=b(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Ke.get(e);if(e!==this.appName&&n&&k.UNMOUNT!==n.getAppState()&&$.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),m(`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)},ce||(ce=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(c(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{i(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&f("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ke.has(this.__MICRO_APP_NAME__)){const n=Ke.get(this.__MICRO_APP_NAME__);de.rawSetAttribute.call(this,e,y(t,n.url))}else de.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>Fe(this,this.appName,W.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===T.NAME?"appName":"appUrl"]!==n)if(e!==T.URL||this.appUrl)if(e!==T.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,_(this.handleAttributeUpdate));else{const e=g(n);if(!e)return m(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Xe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=b(n,this.appName)))return m(`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&&r(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Ke.has(this.appName)){const e=Ke.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==k.UNMOUNT?e.isPrefetch||e.getAppState()===k.UNMOUNT?(f(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):m(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):m(`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!(!i(t)||!t)||(m(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,_((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Ke.has(this.appName)&&Ke.get(this.appName).actionsForCompletelyDestroy();const t=new je({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"),baseroute:this.getBaseRouteCompatible()});Ke.set(this.appName,t)}handleUnmount(e,t){const n=Ke.get(this.appName);n&&n.getAppState()!==k.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Ke.get(this.appName);e&&e.getAppState()!==k.UNMOUNT&&e.getKeepAliveState()!==$.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){_((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Xe[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()}set data(e){this.appName?Xe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Xe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ve(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{r(e)&&(e=e()),a(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{v((()=>{var n,s;if(c(e)&&navigator.onLine)if(e.name=g(e.name),e.url=b(e.url,e.name),e.name&&e.url&&!Ke.has(e.name)){const i=new je({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Xe.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Xe.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Ke.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function qe(e,t,n){if(a(e)){const s=e.filter((e=>i(e)&&e.includes(`.${t}`)&&!n.has(e)));E(s.map((e=>F(e))),(e=>{const t=s[e.index];n.has(t)||n.set(t,e.data)}),(e=>{m(e)}))}}function ze(e){const t=[];return Ke.forEach(((n,s)=>{k.UNMOUNT===n.getAppState()||n.isPrefetch||e&&$.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Qe(e,t){const n=Ke.get(g(e));return new Promise((s=>{if(n)if(n.getAppState()===k.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=L(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),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 f(`app ${e} does not exist`),s()}))}class Je extends Pe{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ve}start(e){if(!n||!window.customElements)return m("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return m(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return f(`element ${this.tagName} is already defined`);if(me(),e&&c(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.ssr=e.ssr,r(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ve(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{qe(t.js,"js",fe),qe(t.css,"css",Y)}))),c(e.plugins))){const t=e.plugins.modules;if(c(t))for(const e in t){const n=g(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Ge(this.tagName)}}var Xe=new Je;e.EventCenterForMicroApp=Me,e.MicroApp=Je,e.default=Xe,e.getActiveApps=ze,e.getAllApps=function(){return Array.from(Ke.keys())},e.preFetch=Ve,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(Ke.keys()).reduce(((t,n)=>t.then((()=>Qe(n,e)))),Promise.resolve())},e.unmountApp=Qe,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@micro-zoe/micro-app", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "A lightweight, efficient and powerful micro front-end framework", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
953806
4587