@micro-zoe/micro-app
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -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 o(e){return"function"==typeof e}const r=Array.isArray;function i(e){return"[object Object]"===toString.call(e)}function s(e){return"[object Promise]"===toString.call(e)}function a(e){return o(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function l(e,t=null,...o){const r=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${r} ${e}`,...o):console.error(`[micro-app]${r}`,e,...o)}function c(e,t=null,...o){const r=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${r} ${e}`,...o):console.warn(`[micro-app]${r}`,e,...o)}function u(e,...t){Promise.resolve().then(e.bind(null,...t))}function p(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function d(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(p(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return l(e,t),""}}function h(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function m(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 f(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,m(p(t))).toString()}function _(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{s(e)?e.then((e=>{t({data:e,index:o}),i()})).catch((e=>{n({error:e,index:o}),i()})):(t({data:e,index:o}),i())}))}const w=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let y=null;function b(e){y=e}function A(){return y}function E(){b(null)}function g(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function v(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function N(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function C(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function P(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function O(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}var R,D,M,S;function L(e,t=null,n={}){return o(je.fetch)?je.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}!function(e){e.NAME="name",e.URL="url"}(R||(R={})),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"}(D||(D={})),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"}(M||(M={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(S||(S={}));const U={};function I(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,o=Element.prototype.replaceChild,r=Element.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Element.prototype.cloneNode,l=Document.prototype.createElement,c=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,h=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,w=Function("return window")(),y=Function("return document")(),b="noModule"in document.createElement("script"),A=y.body.querySelector("#micro-app-template-style"),E=w.addEventListener,g=w.removeEventListener,v=w.setInterval,N=w.setTimeout,C=w.clearInterval,P=w.clearTimeout,O=y.addEventListener,R=y.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(U,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCloneNode:a,rawCreateElement:l,rawCreateElementNS:c,rawCreateDocumentFragment:u,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:h,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,rawWindow:w,rawDocument:y,supportModuleScript:b,templateStyle:A,rawWindowAddEventListener:E,rawWindowRemoveEventListener:g,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:P,rawDocumentAddEventListener:O,rawDocumentRemoveEventListener:R})}}var x;function T(e,t){const{selectorText:n,cssText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===n)return o.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function $(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^(data|blob):/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!g())return e;{const t=r.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;r=r.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(r)&&o&&(t=function(e){const t=e.split("/");return t.pop(),p(t.join("/")+"/")}(o)),`url("${f(r,t)}")`}))}function k(e,t,n){const o=W(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function W(e,t){let n="";for(const o of e)switch(o.type){case x.STYLE_RULE:n+=T(o,t);break;case x.MEDIA_RULE:n+=k(o,t,"media");break;case x.SUPPORTS_RULE:n+=k(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function B(e,t,n,o,r,i){var s,a;if(!t.__MICRO_APP_HAS_SCOPED__){let l=$(W(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);g()&&(l=l.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm,((e,t,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?e:`${t}"${n}"`))),t.textContent=l,t.__MICRO_APP_HAS_SCOPED__=!0}}function H(e,t){if(t.scopecss){const n=`${je.tagName}[name=${t.name}]`;let o=U.templateStyle;if(o||(U.templateStyle=o=v("style"),o.setAttribute("id","micro-app-template-style"),U.rawDocument.body.appendChild(o),o.sheet.disabled=!0),e.textContent)o.textContent=e.textContent,B(o,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__),o.textContent="";else{const o=new MutationObserver((function(){var r,i;o.disconnect(),!e.textContent&&(null===(i=null===(r=e.sheet)||void 0===r?void 0:r.cssRules)||void 0===i?void 0:i.length)||e.hasAttribute("data-styled")||B(e,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__)}));o.observe(e,{childList:!0})}}return e}function K(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function F(e){const t=new CustomEvent("load");K(t,e),o(e.onload)?e.onload(t):e.dispatchEvent(t)}function j(e){const t=new CustomEvent("error");K(t,e),o(e.onerror)?e.onerror(t):e.dispatchEvent(t)}!function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(x||(x={}));const G=new Map;function q(e,t,n,o=!1){const r=e.getAttribute("rel");let i=e.getAttribute("href"),s=null;if("stylesheet"===r&&i){if(i=f(i,n.url),o)return{url:i,info:{code:"",isGlobal:e.hasAttribute("global")}};s=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:s,isGlobal:e.hasAttribute("global")})}else r&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(r)?o?s=document.createComment(`link element with rel=${r}${i?" & href="+i:""} removed by micro-app`):t.removeChild(e):i&&e.setAttribute("href",f(i,n.url));return o?{replaceComment:s}:s?t.replaceChild(s,e):void 0}function V(e,t,n){const o=Array.from(t.source.links.entries()),r=[];for(const[e]of o){const n=G.get(e);n?r.push(n):r.push(L(e,t.name))}_(r,(e=>{!function(e,t,n,o,r){t.isGlobal&&!G.has(e)&&G.set(e,n);const i=v("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=e,i.setAttribute("data-origin-href",e),o.replaceChild(H(i,r),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{l(e,t.name)}),(()=>{t.onLoad(e)}))}const z=new Map;function Y(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=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(U.supportModuleScript&&e.noModule||!U.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=f(i,n.url);const t={code:"",isExternal:!0,isDynamic:o,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(o)return{url:i,info:t};n.source.scripts.set(i,t),r=document.createComment(`script with src='${i}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),i={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:i};n.source.scripts.set(t,i),r=document.createComment("inline script extract by micro-app")}else o||(r=document.createComment("script element removed by micro-app"))}return o?{replaceComment:r}:t.replaceChild(r,e)}function Q(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=z.get(e);n?i.code=n:i.defer||i.async||(o.push(L(e,t.name)),r.push([e,i]))}o.length?_(o,(e=>{!function(e,t,n){t.isGlobal&&!z.has(e)&&z.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{l(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function X(e,t,n,o,r){var i;try{const s=ee(e,t,n.code,n.module);if(t.inline||n.module){const a=v("script");if(J(e,s,n.module,a,r),o)return a;null===(i=t.container)||void 0===i||i.querySelector("micro-app-body").appendChild(a)}else if(Z(s,n),o)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function J(e,t,n,o,r){if(n){const e=new Blob([t],{type:"text/javascript"});o.src=URL.createObjectURL(e),o.setAttribute("type","module"),r&&(r.moduleCount&&r.moduleCount--,o.onload=r.bind(o,0===r.moduleCount))}else o.textContent=t;e.startsWith("inline-")||o.setAttribute("data-origin-src",e)}function Z(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ee(e,t,n,s){return i(je.plugins)&&(n=function(e,t,n,s){var a;if(r(s.global))for(const n of s.global)i(n)&&o(n.loader)&&(t=n.loader(t,e,n.options));if(r(null===(a=s.modules)||void 0===a?void 0:a[n]))for(const r of s.modules[n])i(r)&&o(r.loader)&&(t=r.loader(t,e,r.options));return t}(e,n,t.name,je.plugins)),t.sandBox&&!s?(U.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}function te(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{te(e,t)}));for(const n of o)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",f(n.getAttribute("href"),t.url)):q(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")&&H(n,t):n instanceof HTMLScriptElement?Y(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",f(n.getAttribute("src"),t.url))}function ne(e,t){const n=function(e){const t=v("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!o||!r){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),l(e,t.name)}te(n,t),t.source.links.size?V(n,t,o):t.onLoad(n),t.source.scripts.size?Q(n,t):t.onLoad(n)}const oe=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(l("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!o(t))return l("event-center: Invalid callback function");let r=this.eventList.get(e);r?n&&Object.getOwnPropertyNames(r.data).length&&t(r.data):(r={data:{},callbacks:new Set},this.eventList.set(e,r)),r.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(o(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!i(t))return l("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 n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class ie{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),oe.on("global",e,t)}removeGlobalDataListener(e){o(e)&&oe.off("global",e)}setGlobalData(e){E(),oe.dispatch("global",e)}getGlobalData(){return oe.getData("global")}clearGlobalDataListener(){const e=this.appName,t=oe.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 se extends ie{addDataListener(e,t,n){oe.on(re(h(e),!1),t,n)}removeDataListener(e,t){o(t)&&oe.off(re(h(e),!1),t)}getData(e,t=!1){return oe.getData(re(h(e),t))}setData(e,t){oe.dispatch(re(h(e),!0),t)}clearDataListener(e){oe.off(re(h(e),!1))}}class ae extends ie{constructor(e){super(),this.appName=h(e),!this.appName&&l(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,oe.on(re(this.appName,!0),e,t)}removeDataListener(e){o(e)&&oe.off(re(this.appName,!0),e)}getData(){return oe.getData(re(this.appName,!0))}dispatch(e){E(),oe.dispatch(re(this.appName,!1),e);const t=Oe.get(this.appName);if((null==t?void 0:t.container)&&i(e)){const n=new CustomEvent("datachange",{detail:{data:e}});O(t.container).dispatchEvent(n)}}clearDataListener(){oe.off(re(this.appName,!0))}}const le=new WeakMap;const ce=new WeakMap;const ue=new WeakMap;function pe(e,t){if(ue.has(t))return ue.get(t);if(o(t)&&!function(e){if(ce.has(e))return ce.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return ce.set(e,n),n}(t)&&!function(e){if(le.has(e))return le.get(e);const t=a(e);return le.set(e,t),t}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&(n.prototype=t.prototype),ue.set(t,n),n}return t}const de=new Map;let he=!1;const me=new Map;function fe(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=U;!he&&function(){if(he=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return c("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){de.forEach((t=>{o(t)&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=A();return e?de.get(e):de.get("base")},set(e){const r=A();r?de.set(r,e):de.set("base",e),!t&&o(e)&&(t=!0,U.rawDocumentAddEventListener.call(U.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,o,r){var i;const s=A();if(s&&(!(null===(i=Oe.get(s))||void 0===i?void 0:i.umdMode)||!a(o))){const e=me.get(s);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else me.set(s,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,o,r){var i;const s=A();if(s&&(!(null===(i=Oe.get(s))||void 0===i?void 0:i.umdMode)||!a(o))){const e=me.get(s);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(o)&&n.delete(o)}}n.call(e,t,o,r)}}const _e=["unmount","appstate-change"];function we(e,t){return _e.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const ye=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=A(),n}}),be=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ae=["location"],Ee={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let ge;function ve(e){ge&&clearTimeout(ge),ge=setTimeout(e,0)}class Ne{constructor(e,t,o){this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microWindow={};const r=U.rawWindow,i=U.rawDocument,s=new Map,a=e=>this.microWindow.hasOwnProperty(e)||r.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map,{rawWindow:i,rawDocument:s,rawWindowAddEventListener:a,rawWindowRemoveEventListener:l,rawSetInterval:c,rawSetTimeout:u,rawClearInterval:p,rawClearTimeout:d,rawDocumentRemoveEventListener:h}=U;e.addEventListener=function(t,o,r){t=we(t,e);const s=n.get(t);s?s.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),a.call(i,t,o,r)},e.removeEventListener=function(t,o,r){t=we(t,e);const s=n.get(t);(null==s?void 0:s.size)&&s.has(o)&&s.delete(o),l.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=c.call(i,e,t,...n);return o.set(r,{handler:e,timeout:t,args:n}),r},e.setTimeout=function(e,t,...n){const o=u.call(i,e,t,...n);return r.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),p.call(i,e)},e.clearTimeout=function(e){r.delete(e),d.call(i,e)};const m=new Map,f=new Map;let _,w=new Map,y=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),o.size&&(w=new Map(o)),r.size&&(y=new Map(r)),_=de.get(t);const e=me.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),w.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),y.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&de.set(t,_),b(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),b(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)l.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{d.call(i,t)})),r.clear()),de.delete(t);const e=me.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)h.call(s,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(t,s)=>{if(s===Symbol.unscopables)return Ee;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return r===r.parent?this.proxyWindow:Reflect.get(r,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s||"Image"===s)switch(this.active&&(b(e),(o?ve:u)((()=>b(null)))),s){case"document":return i;case"eval":return eval;case"Image":return ye}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||n(s)&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const l=Reflect.get(r,s);return pe(r,l)},set:(e,t,n)=>{if(this.active){if(Ae.includes(t))Reflect.set(r,t,n);else if(e.hasOwnProperty(t)||!r.hasOwnProperty(t)||this.scopeProperties.includes(t))Reflect.set(e,t,n),this.injectedKeys.add(t);else{const o=Object.getOwnPropertyDescriptor(r,t),{writable:i,configurable:s,enumerable:a}=o;i&&(Object.defineProperty(e,t,{configurable:s,enumerable:a,writable:i,value:n}),this.injectedKeys.add(t))}(this.escapeProperties.includes(t)||be.includes(t)&&!Reflect.has(r,t))&&!this.scopeProperties.includes(t)&&(Reflect.set(r,t,n),this.escapeKeys.add(t))}return!0},has:(e,t)=>this.scopeProperties.includes(t)?t in e:t in Ee||t in e||t in r,getOwnPropertyDescriptor:(e,t)=>{if(e.hasOwnProperty(t))return s.set(t,"target"),Object.getOwnPropertyDescriptor(e,t);if(r.hasOwnProperty(t)){s.set(t,"rawWindow");const e=Object.getOwnPropertyDescriptor(r,t);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,t,n)=>"rawWindow"===s.get(t)?Reflect.defineProperty(r,t,n):Reflect.defineProperty(e,t,n),ownKeys:e=>Reflect.ownKeys(r).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.injectedKeys.has(t)&&this.injectedKeys.delete(t),this.escapeKeys.has(t)&&Reflect.deleteProperty(r,t),Reflect.deleteProperty(e,t))})}start(e){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=e,U.rawWindow._babelPolyfill&&(U.rawWindow._babelPolyfill=!1),1==++Ne.activeCount&&fe())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.microWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(U.rawWindow,e)})),this.escapeKeys.clear(),0==--Ne.activeCount&&(document.addEventListener=U.rawDocumentAddEventListener,document.removeEventListener=U.rawDocumentRemoveEventListener))}recordUmdSnapshot(){this.microWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=oe.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=oe.eventList.get(re(t,!0));o&&(e.umdDataListeners.normal=new Set(o.callbacks))}(this.microWindow.microApp),this.recordUmdinjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdinjectedValues.set(e,Reflect.get(this.microWindow,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.microWindow.microApp)}getScopeProperties(e){var t;if(i(je.plugins)){if(r(je.plugins.global))for(const e of je.plugins.global)i(e)&&(r(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),r(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if(r(null===(t=je.plugins.modules)||void 0===t?void 0:t[e]))for(const t of je.plugins.modules[e])i(t)&&(r(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),r(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=m(n),e.microApp=new ae(t),e.rawWindow=U.rawWindow,e.rawDocument=U.rawDocument,e.removeDomScope=E}}function Ce(e,t,n,r){var i;if(!e)return l(`element does not exist in lifecycle ${n}`,t);e=O(e),E();const s=Object.assign({name:t,container:e},r&&{error:r}),a=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),o(null===(i=je.lifeCycles)||void 0===i?void 0:i[n])&&je.lifeCycles[n](a),e.dispatchEvent(a)}function Pe(e,t,n={}){const o=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(o)}Ne.activeCount=0;const Oe=new Map;class Re{constructor({name:e,url:t,ssrUrl:n,container:o,inline:r,scopecss:i,useSandbox:s,macro:a,baseroute:l}){this.state=D.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.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=o?o:null,this.inline=null!=r&&r,this.baseroute=null!=l?l:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=s,this.scopecss=this.useSandbox&&i,this.macro=null!=a&&a,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ne(e,t,this.macro))}loadSourceCode(){var e;this.state=D.LOADING_SOURCE_CODE,L((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)),l(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=>{l(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||D.UNMOUNT===this.state)return;this.state=D.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,D.UNMOUNT!==this.state&&(this.onerror(e),this.state=D.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,i,s;if("boolean"==typeof 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=D.LOADING_SOURCE_CODE);let a;if(Ce(this.container,this.name,M.BEFOREMOUNT),this.state=D.MOUNTING,N(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(s=this.sandBox)||void 0===s||s.rebuildUmdSnapshot();try{a=this.umdHookMount()}catch(e){l("an error occurred in the mount function \n",this.name,e)}this.handleMounted(a)}else{let e=!1;!function(e,t,n){const o=Array.from(e.entries()),r=[],i=[];for(const[e,s]of o)s.isDynamic||(s.defer||s.async?(s.isExternal&&!s.code?r.push(L(e,t.name)):r.push(s.code),i.push([e,s]),s.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(X(e,t,s,!1),n(!1)));r.length?Promise.all(r).then((e=>{e.forEach(((e,o)=>{const[r,s]=i[o];s.code=s.code||e,X(r,t,s,!1,n),!s.module&&n(!1)})),n(void 0===n.moduleCount)})).catch((e=>{l(e,t.name),n(!0)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(o(e)&&o(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{a=this.umdHookMount()}catch(e){l("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(a))}))}}handleMounted(e){s(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){D.UNMOUNT!==this.state&&(this.state=D.MOUNTED,Ce(this.container,this.name,M.MOUNTED))}unmount(e,t){let n;if(this.state===D.LOAD_SOURCE_ERROR&&(e=!0),this.state=D.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){l("an error occurred in the unmount function \n",this.name,e)}Pe("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){s(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;null===(n=this.sandBox)||void 0===n||n.stop(),e?this.actionsForCompletelyDestory():this.umdMode&&this.container.childElementCount&&N(this.container,this.source.html,!1),Ce(this.container,this.name,M.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestory(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Oe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;N(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=S.KEEP_ALIVE_HIDDEN,Pe("appstate-change",this.name,{appState:"afterhidden"}),Ce(e,this.name,M.AFTERHIDDEN)}showKeepAliveApp(e){Pe("appstate-change",this.name,{appState:"beforeshow"}),Ce(e,this.name,M.BEFORESHOW),N(this.container,e,!1),this.container=e,this.keepAliveState=S.KEEP_ALIVE_SHOW,Pe("appstate-change",this.name,{appState:"aftershow"}),Ce(this.container,this.name,M.AFTERSHOW)}onerror(e){Ce(this.container,this.name,M.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(D.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:U.rawWindow;return this.libraryName=O(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function De(e,t){const n=Oe.get(h(e));return new Promise((o=>{if(n)if(n.getAppState()===D.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestory(),o();else if(n.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,o):(null==t?void 0:t.clearAliveState)?n.unmount(!1,o):o();else{const e=O(n.container),r=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()},i=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()};if(e.addEventListener("unmount",r),e.addEventListener("afterhidden",i),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else c(`app ${e} does not exist`),o()}))}const Me=new WeakMap;function Se(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return Me.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?H(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return Me.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:o,info:r,replaceComment:i}=q(t,e,n,!0);if(o&&r){const e=v("style");return e.__MICRO_APP_LINK_PATH__=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,H(r,n),void u((()=>F(o)));if(G.has(e)){const i=G.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,H(r,n),void u((()=>F(o)))}L(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&G.set(e,i),r.textContent=i,H(r,n),F(o)})).catch((e=>{l(e,n.name),j(o)}))}(o,r,n,t,e),Me.set(t,e),e}return i?(Me.set(t,i),i):t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:i}=Y(t,e,n,!0)||{};if(r&&i){if(i.isExternal){const e=function(e,t,n,o){const r=()=>F(o);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&u(r),X(e,n,t,!0,r)}if(z.has(e)){const o=z.get(e);return t.code=o,n.source.scripts.set(e,t),!t.module&&u(r),X(e,n,t,!0,r)}let i;return i=n.inline||t.module?v("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),L(e,n.name).then((s=>{t.code=s,n.source.scripts.set(e,t),t.isGlobal&&z.set(e,s);try{s=ee(e,n,s,t.module),n.inline||t.module?J(e,s,t.module,i,r):Z(s,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&F(o)})).catch((e=>{l(e,n.name),j(o)})),i}(r,i,n,t);return Me.set(t,e),e}{const e=X(r,n,i,!0);return Me.set(t,e),e}}return o?(Me.set(t,o),o):t}return t}function Le(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?U.rawAppendChild.call(i,o):t!==U.rawRemoveChild||i.contains(o)?t===U.rawAppend||t===U.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n===document.body){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?U.rawAppendChild.call(i,o):t!==U.rawRemoveChild||i.contains(o)?t===U.rawAppend||t===U.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===U.rawAppend||t===U.rawPrepend?t.call(n,o):t.call(n,o,r)}function Ue(e){var t;return null!==(t=Me.get(e))&&void 0!==t?t:e}function Ie(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Oe.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?Le(r,o,e,Se(e,t,r),n&&Ue(n)):o===U.rawAppend||o===U.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===U.rawAppend||o===U.rawPrepend){const n=A();if(!(t instanceof Node)&&n){const r=Oe.get(n);if(null==r?void 0:r.container){if(e===document.head)return o.call(r.container.querySelector("micro-app-head"),t);if(e===document.body)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function xe(){!function(){const e=U.rawDocument;function t(t){var n,o,r;const i=A();return i&&t&&!P(t)&&e===this?null!==(r=null===(o=null===(n=Oe.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:U.rawQuerySelector.call(this,t)}function n(t){var n,o,r;const i=A();return i&&t&&!P(t)&&e===this?null!==(r=null===(o=null===(n=Oe.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:U.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return Te(U.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return Te(U.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return Te(U.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!A()||C(e))return U.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return U.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!A()||C(e))return U.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return U.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const o=A();if(!o||P(e)||C(e)||!(null===(t=Oe.get(o))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return U.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return U.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!A()||C(e))return U.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return U.rawGetElementsByName.call(this,e)}}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(i(t)){const e={};Object.getOwnPropertyNames(t).forEach((o=>{n(o)&&0===o.indexOf("__")||(e[o]=t[o])})),this.data=e}else"[object Object]"!==t&&c("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__&&Oe.has(this.__MICRO_APP_NAME__)){const n=Oe.get(this.__MICRO_APP_NAME__);U.rawSetAttribute.call(this,e,f(t,n.url))}else U.rawSetAttribute.call(this,e,t)},Element.prototype.appendChild=function(e){return Ie(this,e,null,U.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return Ie(this,e,t,U.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return Ie(this,e,t,U.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)Ie(this,e[t],null,U.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)Ie(this,e[t-1],null,U.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Oe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?Le(t,U.rawRemoveChild,this,Ue(e)):U.rawRemoveChild.call(this,e)}return U.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=U.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function Te(e){const t=A();return t&&(e.__MICRO_APP_NAME__=t),e}function $e(){b(null),Document.prototype.createElement=U.rawCreateElement,Document.prototype.createElementNS=U.rawCreateElementNS,Document.prototype.createDocumentFragment=U.rawCreateDocumentFragment,Document.prototype.querySelector=U.rawQuerySelector,Document.prototype.querySelectorAll=U.rawQuerySelectorAll,Document.prototype.getElementById=U.rawGetElementById,Document.prototype.getElementsByClassName=U.rawGetElementsByClassName,Document.prototype.getElementsByTagName=U.rawGetElementsByTagName,Document.prototype.getElementsByName=U.rawGetElementsByName,Element.prototype.setAttribute=U.rawSetAttribute,Element.prototype.appendChild=U.rawAppendChild,Element.prototype.insertBefore=U.rawInsertBefore,Element.prototype.replaceChild=U.rawReplaceChild,Element.prototype.removeChild=U.rawRemoveChild,Element.prototype.append=U.rawAppend,Element.prototype.prepend=U.rawPrepend,Element.prototype.cloneNode=U.rawCloneNode}let ke=!1;function We(){Be(),Oe.forEach((e=>{e.container&&O(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Oe.clear(),He.size&&(He.clear(),$e())}function Be(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",We,!1)}const He=new Map;function Ke(e){class t extends HTMLElement{constructor(){super(),this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.6.1",this.handleAttributeUpdate=()=>{this.isWating=!1;const e=h(this.getAttribute("name")),t=d(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Oe.get(e);if(e!==this.appName&&n&&D.UNMOUNT!==n.getAppState()&&S.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),l(`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)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,He.has(this)||this.performWhenFirstCreated(),u((()=>Ce(this,this.appName,M.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():(He.delete(this),this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{0===He.size&&$e()})))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===R.NAME?"appName":"appUrl"]!==n)if(e!==R.URL||this.appUrl)if(e!==R.NAME||this.appName)this.isWating||(this.isWating=!0,u(this.handleAttributeUpdate));else{const e=h(n);if(!e)return l(`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=d(n,this.appName)))return l(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===He.set(this,!0).size&&(xe(),function(){if(!ke){ke=!0;const e=v("style");e.setAttribute("type","text/css"),e.textContent=`\n${je.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,U.rawDocument.head.appendChild(e)}}(),Be(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",We,!1))}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&o(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=f(U.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Oe.has(this.appName)){const e=Oe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==D.UNMOUNT?e.isPrefetch||e.getAppState()===D.UNMOUNT?(c(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):l(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var o;this.getDisposeResult("ssr")?this.ssrUrl=f(U.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(o=this.shadowRoot)&&void 0!==o?o:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):l(`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)||(l(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,u((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Oe.has(this.appName)&&Oe.get(this.appName).actionsForCompletelyDestory();const t=new Re({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"),macro:this.getDisposeResult("macro"),baseroute:this.getBaseRouteCompatible()});Oe.set(this.appName,t)}handleUnmount(e,t){const n=Oe.get(this.appName);n&&n.getAppState()!==D.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Oe.get(this.appName);e&&e.getAppState()!==D.UNMOUNT&&e.getKeepAliveState()!==S.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){u((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||je[e])&&this.compatibleDisablSpecialProperties(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)}compatibleDisablSpecialProperties(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,t)}function Fe(t){if(!e)return l("preFetch is only supported in browser environment");w((()=>{o(t)&&(t=t()),function(e){const t=[];return r(e)&&e.forEach((e=>{i(e)&&(e.name=h(e.name),e.url=d(e.url,e.name),e.name&&e.url&&!Oe.has(e.name)&&t.push(e))})),t}(t).forEach((e=>{var t,n,o;const r=new Re({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:je.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:je.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:je.macro});r.isPrefetch=!0,Oe.set(e.name,r)}))}))}var je=new class extends se{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Fe}start(t){if(!e||!window.customElements)return l("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return l(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return c(`element ${this.tagName} is already defined`);if(I(),t&&i(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.macro=t.macro,this.ssr=t.ssr,o(t.fetch)&&(this.fetch=t.fetch),i(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&Fe(t.preFetchApps),t.globalAssets&&(i(s=t.globalAssets)&&w((()=>{if(r(s.js)){const e=s.js.filter((e=>n(e)&&e.includes(".js")&&!z.has(e))),t=[];e.forEach((e=>{t.push(L(e))})),_(t,(t=>{const n=e[t.index];z.has(n)||z.set(n,t.data)}),(e=>{l(e)}))}if(r(s.css)){const e=s.css.filter((e=>n(e)&&e.includes(".css")&&!G.has(e))),t=[];e.forEach((e=>{t.push(L(e))})),_(t,(t=>{const n=e[t.index];G.has(n)||G.set(n,t.data)}),(e=>{l(e)}))}}))),i(t.plugins))){const e=t.plugins.modules;if(i(e))for(const t in e){const n=h(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var s;Ke(this.tagName)}};exports.EventCenterForMicroApp=ae,exports.default=je,exports.getActiveApps=function(){const e=[];return Oe.forEach(((t,n)=>{D.UNMOUNT===t.getAppState()||t.isPrefetch||e.push(n)})),e},exports.getAllApps=function(){return Array.from(Oe.keys())},exports.preFetch=Fe,exports.pureCreateElement=v,exports.removeDomScope=E,exports.unmountAllApps=function(e){return Array.from(Oe.keys()).reduce(((t,n)=>t.then((()=>De(n,e)))),Promise.resolve())},exports.unmountApp=De,exports.version="0.6.1"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function o(e){return"function"==typeof e}const r=Array.isArray;function i(e){return"[object Object]"===toString.call(e)}function s(e){return"[object Promise]"===toString.call(e)}function a(e){return o(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function l(e,t=null,...o){const r=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${r} ${e}`,...o):console.error(`[micro-app]${r}`,e,...o)}function c(e,t=null,...o){const r=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${r} ${e}`,...o):console.warn(`[micro-app]${r}`,e,...o)}function u(e,...t){Promise.resolve().then(e.bind(null,...t))}function p(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function d(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(p(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return l(e,t),""}}function h(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function m(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 f(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,m(p(t))).toString()}function _(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{s(e)?e.then((e=>{t({data:e,index:o}),i()})).catch((e=>{n({error:e,index:o}),i()})):(t({data:e,index:o}),i())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let w=null;function b(e){w=e}function A(){return w}function E(){b(null)}function g(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function v(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function N(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function C(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function P(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function O(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}var R,D,M,S;function L(e,t=null,n={}){return o(Fe.fetch)?Fe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}!function(e){e.NAME="name",e.URL="url"}(R||(R={})),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"}(D||(D={})),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"}(M||(M={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(S||(S={}));const U={};function I(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,o=Element.prototype.replaceChild,r=Element.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Element.prototype.cloneNode,l=Document.prototype.createElement,c=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,h=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,y=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=A(),n}}),w=Function("return window")(),b=Function("return document")(),E="noModule"in document.createElement("script"),g=b.body.querySelector("#micro-app-template-style"),v=w.addEventListener,N=w.removeEventListener,C=w.setInterval,P=w.setTimeout,O=w.clearInterval,R=w.clearTimeout,D=b.addEventListener,M=b.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(U,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCloneNode:a,rawCreateElement:l,rawCreateElementNS:c,rawCreateDocumentFragment:u,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:h,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:y,rawWindow:w,rawDocument:b,supportModuleScript:E,templateStyle:g,rawWindowAddEventListener:v,rawWindowRemoveEventListener:N,rawSetInterval:C,rawSetTimeout:P,rawClearInterval:O,rawClearTimeout:R,rawDocumentAddEventListener:D,rawDocumentRemoveEventListener:M})}}var x;function T(e,t){const{selectorText:n,cssText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===n)return o.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function $(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^(data|blob):/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!g())return e;{const t=r.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;r=r.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(r)&&o&&(t=function(e){const t=e.split("/");return t.pop(),p(t.join("/")+"/")}(o)),`url("${f(r,t)}")`}))}function k(e,t,n){const o=W(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function W(e,t){let n="";for(const o of e)switch(o.type){case x.STYLE_RULE:n+=T(o,t);break;case x.MEDIA_RULE:n+=k(o,t,"media");break;case x.SUPPORTS_RULE:n+=k(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function B(e,t,n,o,r,i){var s,a;if(!t.__MICRO_APP_HAS_SCOPED__){let l=$(W(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);g()&&(l=l.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm,((e,t,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?e:`${t}"${n}"`))),t.textContent=l,t.__MICRO_APP_HAS_SCOPED__=!0}}function H(e,t){if(t.scopecss){const n=`${Fe.tagName}[name=${t.name}]`;let o=U.templateStyle;if(o||(U.templateStyle=o=v("style"),o.setAttribute("id","micro-app-template-style"),U.rawDocument.body.appendChild(o),o.sheet.disabled=!0),e.textContent)o.textContent=e.textContent,B(o,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__),o.textContent="";else{const o=new MutationObserver((function(){var r,i;o.disconnect(),!e.textContent&&(null===(i=null===(r=e.sheet)||void 0===r?void 0:r.cssRules)||void 0===i?void 0:i.length)||e.hasAttribute("data-styled")||B(e,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__)}));o.observe(e,{childList:!0})}}return e}function K(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function F(e){const t=new CustomEvent("load");K(t,e),o(e.onload)?e.onload(t):e.dispatchEvent(t)}function j(e){const t=new CustomEvent("error");K(t,e),o(e.onerror)?e.onerror(t):e.dispatchEvent(t)}!function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(x||(x={}));const G=new Map;function q(e,t,n,o=!1){const r=e.getAttribute("rel");let i=e.getAttribute("href"),s=null;if("stylesheet"===r&&i){if(i=f(i,n.url),o)return{url:i,info:{code:"",isGlobal:e.hasAttribute("global")}};s=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:s,isGlobal:e.hasAttribute("global")})}else r&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(r)?o?s=document.createComment(`link element with rel=${r}${i?" & href="+i:""} removed by micro-app`):t.removeChild(e):i&&e.setAttribute("href",f(i,n.url));return o?{replaceComment:s}:s?t.replaceChild(s,e):void 0}function V(e,t,n){const o=Array.from(t.source.links.entries()),r=[];for(const[e]of o){const n=G.get(e);n?r.push(n):r.push(L(e,t.name))}_(r,(e=>{!function(e,t,n,o,r){t.isGlobal&&!G.has(e)&&G.set(e,n);const i=v("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=e,i.setAttribute("data-origin-href",e),o.replaceChild(H(i,r),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{l(e,t.name)}),(()=>{t.onLoad(e)}))}const z=new Map;function Y(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=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(U.supportModuleScript&&e.noModule||!U.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=f(i,n.url);const t={code:"",isExternal:!0,isDynamic:o,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(o)return{url:i,info:t};n.source.scripts.set(i,t),r=document.createComment(`script with src='${i}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),i={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:i};n.source.scripts.set(t,i),r=document.createComment("inline script extract by micro-app")}else o||(r=document.createComment("script element removed by micro-app"))}return o?{replaceComment:r}:t.replaceChild(r,e)}function Q(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=z.get(e);n?i.code=n:i.defer||i.async||(o.push(L(e,t.name)),r.push([e,i]))}o.length?_(o,(e=>{!function(e,t,n){t.isGlobal&&!z.has(e)&&z.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{l(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function X(e,t,n,o,r){var i;try{const s=ee(e,t,n.code,n.module);if(t.inline||n.module){const a=v("script");if(J(e,s,n.module,a,r),o)return a;null===(i=t.container)||void 0===i||i.querySelector("micro-app-body").appendChild(a)}else if(Z(s,n),o)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function J(e,t,n,o,r){if(n){const e=new Blob([t],{type:"text/javascript"});o.src=URL.createObjectURL(e),o.setAttribute("type","module"),r&&(r.moduleCount&&r.moduleCount--,o.onload=r.bind(o,0===r.moduleCount))}else o.textContent=t;e.startsWith("inline-")||o.setAttribute("data-origin-src",e)}function Z(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ee(e,t,n,s){return i(Fe.plugins)&&(n=function(e,t,n,s){var a;if(r(s.global))for(const n of s.global)i(n)&&o(n.loader)&&(t=n.loader(t,e,n.options));if(r(null===(a=s.modules)||void 0===a?void 0:a[n]))for(const r of s.modules[n])i(r)&&o(r.loader)&&(t=r.loader(t,e,r.options));return t}(e,n,t.name,Fe.plugins)),t.sandBox&&!s?(U.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}function te(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{te(e,t)}));for(const n of o)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",f(n.getAttribute("href"),t.url)):q(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")&&H(n,t):n instanceof HTMLScriptElement?Y(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",f(n.getAttribute("src"),t.url))}function ne(e,t){const n=function(e){const t=v("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!o||!r){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),l(e,t.name)}te(n,t),t.source.links.size?V(n,t,o):t.onLoad(n),t.source.scripts.size?Q(n,t):t.onLoad(n)}const oe=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(l("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!o(t))return l("event-center: Invalid callback function");let r=this.eventList.get(e);r?n&&Object.getOwnPropertyNames(r.data).length&&t(r.data):(r={data:{},callbacks:new Set},this.eventList.set(e,r)),r.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(o(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!i(t))return l("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 n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class ie{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),oe.on("global",e,t)}removeGlobalDataListener(e){o(e)&&oe.off("global",e)}setGlobalData(e){E(),oe.dispatch("global",e)}getGlobalData(){return oe.getData("global")}clearGlobalDataListener(){const e=this.appName,t=oe.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 se extends ie{addDataListener(e,t,n){oe.on(re(h(e),!1),t,n)}removeDataListener(e,t){o(t)&&oe.off(re(h(e),!1),t)}getData(e,t=!1){return oe.getData(re(h(e),t))}setData(e,t){oe.dispatch(re(h(e),!0),t)}clearDataListener(e){oe.off(re(h(e),!1))}}class ae extends ie{constructor(e){super(),this.appName=h(e),!this.appName&&l(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,oe.on(re(this.appName,!0),e,t)}removeDataListener(e){o(e)&&oe.off(re(this.appName,!0),e)}getData(){return oe.getData(re(this.appName,!0))}dispatch(e){E(),oe.dispatch(re(this.appName,!1),e);const t=Pe.get(this.appName);if((null==t?void 0:t.container)&&i(e)){const n=new CustomEvent("datachange",{detail:{data:e}});O(t.container).dispatchEvent(n)}}clearDataListener(){oe.off(re(this.appName,!0))}}const le=new WeakMap;const ce=new WeakMap;const ue=new WeakMap;function pe(e,t){if(ue.has(t))return ue.get(t);if(o(t)&&!function(e){if(ce.has(e))return ce.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return ce.set(e,n),n}(t)&&!function(e){if(le.has(e))return le.get(e);const t=a(e);return le.set(e,t),t}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&(n.prototype=t.prototype),ue.set(t,n),n}return t}const de=new Map;let he=!1;const me=new Map;function fe(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=U;!he&&function(){if(he=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return c("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){de.forEach((t=>{o(t)&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=A();return e?de.get(e):de.get("base")},set(e){const r=A();r?de.set(r,e):de.set("base",e),!t&&o(e)&&(t=!0,U.rawDocumentAddEventListener.call(U.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,o,r){var i;const s=A();if(s&&(!(null===(i=Pe.get(s))||void 0===i?void 0:i.umdMode)||!a(o))){const e=me.get(s);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else me.set(s,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,o,r){var i;const s=A();if(s&&(!(null===(i=Pe.get(s))||void 0===i?void 0:i.umdMode)||!a(o))){const e=me.get(s);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(o)&&n.delete(o)}}n.call(e,t,o,r)}}const _e=["unmount","appstate-change"];function ye(e,t){return _e.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const we=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],be=["location"],Ae={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ee;function ge(e){Ee&&clearTimeout(Ee),Ee=setTimeout(e,0)}class ve{constructor(e,t,o){this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microWindow={};const r=U.rawWindow,i=U.rawDocument,s=new Map,a=e=>this.microWindow.hasOwnProperty(e)||r.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map,{rawWindow:i,rawDocument:s,rawWindowAddEventListener:a,rawWindowRemoveEventListener:l,rawSetInterval:c,rawSetTimeout:u,rawClearInterval:p,rawClearTimeout:d,rawDocumentRemoveEventListener:h}=U;e.addEventListener=function(t,o,r){t=ye(t,e);const s=n.get(t);s?s.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),a.call(i,t,o,r)},e.removeEventListener=function(t,o,r){t=ye(t,e);const s=n.get(t);(null==s?void 0:s.size)&&s.has(o)&&s.delete(o),l.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=c.call(i,e,t,...n);return o.set(r,{handler:e,timeout:t,args:n}),r},e.setTimeout=function(e,t,...n){const o=u.call(i,e,t,...n);return r.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),p.call(i,e)},e.clearTimeout=function(e){r.delete(e),d.call(i,e)};const m=new Map,f=new Map;let _,y=new Map,w=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),o.size&&(y=new Map(o)),r.size&&(w=new Map(r)),_=de.get(t);const e=me.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),y.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),w.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&de.set(t,_),b(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),b(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)l.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{d.call(i,t)})),r.clear()),de.delete(t);const e=me.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)h.call(s,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(t,s)=>{if(s===Symbol.unscopables)return Ae;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return r===r.parent?this.proxyWindow:Reflect.get(r,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s||"Image"===s)switch(this.active&&(b(e),(o?ge:u)((()=>b(null)))),s){case"document":return i;case"eval":return eval;case"Image":return U.ImageProxy}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||n(s)&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const l=Reflect.get(r,s);return pe(r,l)},set:(e,t,n)=>{if(this.active){if(be.includes(t))Reflect.set(r,t,n);else if(e.hasOwnProperty(t)||!r.hasOwnProperty(t)||this.scopeProperties.includes(t))Reflect.set(e,t,n),this.injectedKeys.add(t);else{const o=Object.getOwnPropertyDescriptor(r,t),{writable:i,configurable:s,enumerable:a}=o;i&&(Object.defineProperty(e,t,{configurable:s,enumerable:a,writable:i,value:n}),this.injectedKeys.add(t))}(this.escapeProperties.includes(t)||we.includes(t)&&!Reflect.has(r,t))&&!this.scopeProperties.includes(t)&&(Reflect.set(r,t,n),this.escapeKeys.add(t))}return!0},has:(e,t)=>this.scopeProperties.includes(t)?t in e:t in Ae||t in e||t in r,getOwnPropertyDescriptor:(e,t)=>{if(e.hasOwnProperty(t))return s.set(t,"target"),Object.getOwnPropertyDescriptor(e,t);if(r.hasOwnProperty(t)){s.set(t,"rawWindow");const e=Object.getOwnPropertyDescriptor(r,t);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,t,n)=>"rawWindow"===s.get(t)?Reflect.defineProperty(r,t,n):Reflect.defineProperty(e,t,n),ownKeys:e=>Reflect.ownKeys(r).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.injectedKeys.has(t)&&this.injectedKeys.delete(t),this.escapeKeys.has(t)&&Reflect.deleteProperty(r,t),Reflect.deleteProperty(e,t))})}start(e){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=e,U.rawWindow._babelPolyfill&&(U.rawWindow._babelPolyfill=!1),1==++ve.activeCount&&fe())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.microWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(U.rawWindow,e)})),this.escapeKeys.clear(),0==--ve.activeCount&&(document.addEventListener=U.rawDocumentAddEventListener,document.removeEventListener=U.rawDocumentRemoveEventListener))}recordUmdSnapshot(){this.microWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=oe.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=oe.eventList.get(re(t,!0));o&&(e.umdDataListeners.normal=new Set(o.callbacks))}(this.microWindow.microApp),this.recordUmdinjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdinjectedValues.set(e,Reflect.get(this.microWindow,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.microWindow.microApp)}getScopeProperties(e){var t;if(i(Fe.plugins)){if(r(Fe.plugins.global))for(const e of Fe.plugins.global)i(e)&&(r(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),r(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if(r(null===(t=Fe.plugins.modules)||void 0===t?void 0:t[e]))for(const t of Fe.plugins.modules[e])i(t)&&(r(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),r(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=m(n),e.microApp=new ae(t),e.rawWindow=U.rawWindow,e.rawDocument=U.rawDocument,e.removeDomScope=E}}function Ne(e,t,n,r){var i;if(!e)return l(`element does not exist in lifecycle ${n}`,t);e=O(e),E();const s=Object.assign({name:t,container:e},r&&{error:r}),a=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),o(null===(i=Fe.lifeCycles)||void 0===i?void 0:i[n])&&Fe.lifeCycles[n](a),e.dispatchEvent(a)}function Ce(e,t,n={}){const o=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(o)}ve.activeCount=0;const Pe=new Map;class Oe{constructor({name:e,url:t,ssrUrl:n,container:o,inline:r,scopecss:i,useSandbox:s,macro:a,baseroute:l}){this.state=D.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.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=o?o:null,this.inline=null!=r&&r,this.baseroute=null!=l?l:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=s,this.scopecss=this.useSandbox&&i,this.macro=null!=a&&a,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new ve(e,t,this.macro))}loadSourceCode(){var e;this.state=D.LOADING_SOURCE_CODE,L((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)),l(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=>{l(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||D.UNMOUNT===this.state)return;this.state=D.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,D.UNMOUNT!==this.state&&(this.onerror(e),this.state=D.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,i,s;if("boolean"==typeof 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=D.LOADING_SOURCE_CODE);let a;if(Ne(this.container,this.name,M.BEFOREMOUNT),this.state=D.MOUNTING,N(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(s=this.sandBox)||void 0===s||s.rebuildUmdSnapshot();try{a=this.umdHookMount()}catch(e){l("an error occurred in the mount function \n",this.name,e)}this.handleMounted(a)}else{let e=!1;!function(e,t,n){const o=Array.from(e.entries()),r=[],i=[];for(const[e,s]of o)s.isDynamic||(s.defer||s.async?(s.isExternal&&!s.code?r.push(L(e,t.name)):r.push(s.code),i.push([e,s]),s.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(X(e,t,s,!1),n(!1)));r.length?Promise.all(r).then((e=>{e.forEach(((e,o)=>{const[r,s]=i[o];s.code=s.code||e,X(r,t,s,!1,n),!s.module&&n(!1)})),n(void 0===n.moduleCount)})).catch((e=>{l(e,t.name),n(!0)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(o(e)&&o(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{a=this.umdHookMount()}catch(e){l("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(a))}))}}handleMounted(e){s(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){D.UNMOUNT!==this.state&&(this.state=D.MOUNTED,Ne(this.container,this.name,M.MOUNTED))}unmount(e,t){let n;if(this.state===D.LOAD_SOURCE_ERROR&&(e=!0),this.state=D.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){l("an error occurred in the unmount function \n",this.name,e)}Ce("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){s(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;null===(n=this.sandBox)||void 0===n||n.stop(),e?this.actionsForCompletelyDestory():this.umdMode&&this.container.childElementCount&&N(this.container,this.source.html,!1),Ne(this.container,this.name,M.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestory(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Pe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;N(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=S.KEEP_ALIVE_HIDDEN,Ce("appstate-change",this.name,{appState:"afterhidden"}),Ne(e,this.name,M.AFTERHIDDEN)}showKeepAliveApp(e){Ce("appstate-change",this.name,{appState:"beforeshow"}),Ne(e,this.name,M.BEFORESHOW),N(this.container,e,!1),this.container=e,this.keepAliveState=S.KEEP_ALIVE_SHOW,Ce("appstate-change",this.name,{appState:"aftershow"}),Ne(this.container,this.name,M.AFTERSHOW)}onerror(e){Ne(this.container,this.name,M.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(D.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:U.rawWindow;return this.libraryName=O(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Re(e,t){const n=Pe.get(h(e));return new Promise((o=>{if(n)if(n.getAppState()===D.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestory(),o();else if(n.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,o):(null==t?void 0:t.clearAliveState)?n.unmount(!1,o):o();else{const e=O(n.container),r=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()},i=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()};if(e.addEventListener("unmount",r),e.addEventListener("afterhidden",i),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else c(`app ${e} does not exist`),o()}))}const De=new WeakMap;function Me(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return De.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?H(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 De.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:o,info:r,replaceComment:i}=q(t,e,n,!0);if(o&&r){const e=v("style");return e.__MICRO_APP_LINK_PATH__=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,H(r,n),void u((()=>F(o)));if(G.has(e)){const i=G.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,H(r,n),void u((()=>F(o)))}L(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&G.set(e,i),r.textContent=i,H(r,n),F(o)})).catch((e=>{l(e,n.name),j(o)}))}(o,r,n,t,e),De.set(t,e),e}return i?(De.set(t,i),i):t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:i}=Y(t,e,n,!0)||{};if(r&&i){if(i.isExternal){const e=function(e,t,n,o){const r=()=>F(o);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&u(r),X(e,n,t,!0,r)}if(z.has(e)){const o=z.get(e);return t.code=o,n.source.scripts.set(e,t),!t.module&&u(r),X(e,n,t,!0,r)}let i;return i=n.inline||t.module?v("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),L(e,n.name).then((s=>{t.code=s,n.source.scripts.set(e,t),t.isGlobal&&z.set(e,s);try{s=ee(e,n,s,t.module),n.inline||t.module?J(e,s,t.module,i,r):Z(s,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&F(o)})).catch((e=>{l(e,n.name),j(o)})),i}(r,i,n,t);return De.set(t,e),e}{const e=X(r,n,i,!0);return De.set(t,e),e}}return o?(De.set(t,o),o):t}return t}function Se(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?U.rawAppendChild.call(i,o):t!==U.rawRemoveChild||i.contains(o)?t===U.rawAppend||t===U.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n===document.body){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?U.rawAppendChild.call(i,o):t!==U.rawRemoveChild||i.contains(o)?t===U.rawAppend||t===U.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===U.rawAppend||t===U.rawPrepend?t.call(n,o):t.call(n,o,r)}function Le(e){var t;return null!==(t=De.get(e))&&void 0!==t?t:e}function Ue(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Pe.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?Se(r,o,e,Me(e,t,r),n&&Le(n)):o===U.rawAppend||o===U.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===U.rawAppend||o===U.rawPrepend){const n=A();if(!(t instanceof Node)&&n){const r=Pe.get(n);if(null==r?void 0:r.container){if(e===document.head)return o.call(r.container.querySelector("micro-app-head"),t);if(e===document.body)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function Ie(){!function(){const e=U.rawDocument;function t(t){var n,o,r;const i=A();return i&&t&&!P(t)&&e===this?null!==(r=null===(o=null===(n=Pe.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:U.rawQuerySelector.call(this,t)}function n(t){var n,o,r;const i=A();return i&&t&&!P(t)&&e===this?null!==(r=null===(o=null===(n=Pe.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:U.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return xe(U.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return xe(U.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return xe(U.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!A()||C(e))return U.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return U.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!A()||C(e))return U.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return U.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const o=A();if(!o||P(e)||C(e)||!(null===(t=Pe.get(o))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return U.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return U.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!A()||C(e))return U.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return U.rawGetElementsByName.call(this,e)}}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(i(t)){const e={};Object.getOwnPropertyNames(t).forEach((o=>{n(o)&&0===o.indexOf("__")||(e[o]=t[o])})),this.data=e}else"[object Object]"!==t&&c("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__&&Pe.has(this.__MICRO_APP_NAME__)){const n=Pe.get(this.__MICRO_APP_NAME__);U.rawSetAttribute.call(this,e,f(t,n.url))}else U.rawSetAttribute.call(this,e,t)},Element.prototype.appendChild=function(e){return Ue(this,e,null,U.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return Ue(this,e,t,U.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return Ue(this,e,t,U.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)Ue(this,e[t],null,U.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)Ue(this,e[t-1],null,U.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Pe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?Se(t,U.rawRemoveChild,this,Le(e)):U.rawRemoveChild.call(this,e)}return U.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=U.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function xe(e){const t=A();return t&&(e.__MICRO_APP_NAME__=t),e}function Te(){b(null),Document.prototype.createElement=U.rawCreateElement,Document.prototype.createElementNS=U.rawCreateElementNS,Document.prototype.createDocumentFragment=U.rawCreateDocumentFragment,Document.prototype.querySelector=U.rawQuerySelector,Document.prototype.querySelectorAll=U.rawQuerySelectorAll,Document.prototype.getElementById=U.rawGetElementById,Document.prototype.getElementsByClassName=U.rawGetElementsByClassName,Document.prototype.getElementsByTagName=U.rawGetElementsByTagName,Document.prototype.getElementsByName=U.rawGetElementsByName,Element.prototype.setAttribute=U.rawSetAttribute,Element.prototype.appendChild=U.rawAppendChild,Element.prototype.insertBefore=U.rawInsertBefore,Element.prototype.replaceChild=U.rawReplaceChild,Element.prototype.removeChild=U.rawRemoveChild,Element.prototype.append=U.rawAppend,Element.prototype.prepend=U.rawPrepend,Element.prototype.cloneNode=U.rawCloneNode}let $e=!1;function ke(){We(),Pe.forEach((e=>{e.container&&O(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Pe.clear(),Be.size&&(Be.clear(),Te())}function We(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ke,!1)}const Be=new Map;function He(e){class t extends HTMLElement{constructor(){super(),this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.6.2",this.handleAttributeUpdate=()=>{this.isWating=!1;const e=h(this.getAttribute("name")),t=d(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Pe.get(e);if(e!==this.appName&&n&&D.UNMOUNT!==n.getAppState()&&S.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),l(`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)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,Be.has(this)||this.performWhenFirstCreated(),u((()=>Ne(this,this.appName,M.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():(Be.delete(this),this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{0===Be.size&&Te()})))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===R.NAME?"appName":"appUrl"]!==n)if(e!==R.URL||this.appUrl)if(e!==R.NAME||this.appName)this.isWating||(this.isWating=!0,u(this.handleAttributeUpdate));else{const e=h(n);if(!e)return l(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Fe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=d(n,this.appName)))return l(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===Be.set(this,!0).size&&(Ie(),function(){if(!$e){$e=!0;const e=v("style");e.setAttribute("type","text/css"),e.textContent=`\n${Fe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,U.rawDocument.head.appendChild(e)}}(),We(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ke,!1))}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&o(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=f(U.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Pe.has(this.appName)){const e=Pe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==D.UNMOUNT?e.isPrefetch||e.getAppState()===D.UNMOUNT?(c(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):l(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var o;this.getDisposeResult("ssr")?this.ssrUrl=f(U.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(o=this.shadowRoot)&&void 0!==o?o:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===S.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):l(`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)||(l(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,u((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Pe.has(this.appName)&&Pe.get(this.appName).actionsForCompletelyDestory();const t=new Oe({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"),macro:this.getDisposeResult("macro"),baseroute:this.getBaseRouteCompatible()});Pe.set(this.appName,t)}handleUnmount(e,t){const n=Pe.get(this.appName);n&&n.getAppState()!==D.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Pe.get(this.appName);e&&e.getAppState()!==D.UNMOUNT&&e.getKeepAliveState()!==S.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){u((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Fe[e])&&this.compatibleDisablSpecialProperties(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)}compatibleDisablSpecialProperties(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?Fe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Fe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function Ke(t){if(!e)return l("preFetch is only supported in browser environment");y((()=>{o(t)&&(t=t()),function(e){const t=[];return r(e)&&e.forEach((e=>{i(e)&&(e.name=h(e.name),e.url=d(e.url,e.name),e.name&&e.url&&!Pe.has(e.name)&&t.push(e))})),t}(t).forEach((e=>{var t,n,o;const r=new Oe({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:Fe.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:Fe.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:Fe.macro});r.isPrefetch=!0,Pe.set(e.name,r)}))}))}var Fe=new class extends se{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ke}start(t){if(!e||!window.customElements)return l("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return l(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return c(`element ${this.tagName} is already defined`);if(I(),t&&i(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.macro=t.macro,this.ssr=t.ssr,o(t.fetch)&&(this.fetch=t.fetch),i(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&Ke(t.preFetchApps),t.globalAssets&&(i(s=t.globalAssets)&&y((()=>{if(r(s.js)){const e=s.js.filter((e=>n(e)&&e.includes(".js")&&!z.has(e))),t=[];e.forEach((e=>{t.push(L(e))})),_(t,(t=>{const n=e[t.index];z.has(n)||z.set(n,t.data)}),(e=>{l(e)}))}if(r(s.css)){const e=s.css.filter((e=>n(e)&&e.includes(".css")&&!G.has(e))),t=[];e.forEach((e=>{t.push(L(e))})),_(t,(t=>{const n=e[t.index];G.has(n)||G.set(n,t.data)}),(e=>{l(e)}))}}))),i(t.plugins))){const e=t.plugins.modules;if(i(e))for(const t in e){const n=h(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var s;He(this.tagName)}};exports.EventCenterForMicroApp=ae,exports.default=Fe,exports.getActiveApps=function(){const e=[];return Pe.forEach(((t,n)=>{D.UNMOUNT===t.getAppState()||t.isPrefetch||e.push(n)})),e},exports.getAllApps=function(){return Array.from(Pe.keys())},exports.preFetch=Ke,exports.pureCreateElement=v,exports.removeDomScope=E,exports.unmountAllApps=function(e){return Array.from(Pe.keys()).reduce(((t,n)=>t.then((()=>Re(n,e)))),Promise.resolve())},exports.unmountApp=Re,exports.version="0.6.2"; | ||
//# 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.6.1",n="undefined"!=typeof window,o="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function r(e){return"string"==typeof e}function i(e){return"function"==typeof e}const s=Array.isArray;function a(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function u(e,t=null,...n){const o=t&&r(t)?` app ${t}:`:"";r(e)?console.error(`[micro-app]${o} ${e}`,...n):console.error(`[micro-app]${o}`,e,...n)}function p(e,t=null,...n){const o=t&&r(t)?` app ${t}:`:"";r(e)?console.warn(`[micro-app]${o} ${e}`,...n):console.warn(`[micro-app]${o}`,e,...n)}function d(e,...t){Promise.resolve().then(e.bind(null,...t))}function h(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function m(e,t=null){if(!r(e)||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(h(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return u(e,t),""}}function f(e){return r(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function _(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,_(h(t))).toString()}function w(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{l(e)?e.then((e=>{t({data:e,index:o}),i()})).catch((e=>{n({error:e,index:o}),i()})):(t({data:e,index:o}),i())}))}const b=o.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let A=null;function E(e){A=e}function g(){return A}function v(){E(null)}function N(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function C(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),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function O(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function R(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function D(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}var M,S,L,U;function I(e,t=null,n={}){return i(qe.fetch)?qe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}!function(e){e.NAME="name",e.URL="url"}(M||(M={})),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"}(S||(S={})),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"}(L||(L={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(U||(U={}));const T={};function x(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,o=Element.prototype.replaceChild,r=Element.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Element.prototype.cloneNode,l=Document.prototype.createElement,c=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,h=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,y=Function("return window")(),w=Function("return document")(),b="noModule"in document.createElement("script"),A=w.body.querySelector("#micro-app-template-style"),E=y.addEventListener,g=y.removeEventListener,v=y.setInterval,N=y.setTimeout,C=y.clearInterval,P=y.clearTimeout,O=w.addEventListener,R=w.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(T,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCloneNode:a,rawCreateElement:l,rawCreateElementNS:c,rawCreateDocumentFragment:u,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:h,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,rawWindow:y,rawDocument:w,supportModuleScript:b,templateStyle:A,rawWindowAddEventListener:E,rawWindowRemoveEventListener:g,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:P,rawDocumentAddEventListener:O,rawDocumentRemoveEventListener:R})}}var $;function k(e,t){const{selectorText:n,cssText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===n)return o.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function W(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^(data|blob):/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!N())return e;{const t=r.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;r=r.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(r)&&o&&(t=function(e){const t=e.split("/");return t.pop(),h(t.join("/")+"/")}(o)),`url("${y(r,t)}")`}))}function B(e,t,n){const o=H(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function H(e,t){let n="";for(const o of e)switch(o.type){case $.STYLE_RULE:n+=k(o,t);break;case $.MEDIA_RULE:n+=B(o,t,"media");break;case $.SUPPORTS_RULE:n+=B(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function K(e,t,n,o,r,i){var s,a;if(!t.__MICRO_APP_HAS_SCOPED__){let l=W(H(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);N()&&(l=l.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm,((e,t,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?e:`${t}"${n}"`))),t.textContent=l,t.__MICRO_APP_HAS_SCOPED__=!0}}function j(e,t){if(t.scopecss){const n=`${qe.tagName}[name=${t.name}]`;let o=T.templateStyle;if(o||(T.templateStyle=o=C("style"),o.setAttribute("id","micro-app-template-style"),T.rawDocument.body.appendChild(o),o.sheet.disabled=!0),e.textContent)o.textContent=e.textContent,K(o,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__),o.textContent="";else{const o=new MutationObserver((function(){var r,i;o.disconnect(),!e.textContent&&(null===(i=null===(r=e.sheet)||void 0===r?void 0:r.cssRules)||void 0===i?void 0:i.length)||e.hasAttribute("data-styled")||K(e,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__)}));o.observe(e,{childList:!0})}}return e}function F(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function G(e){const t=new CustomEvent("load");F(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function q(e){const t=new CustomEvent("error");F(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}!function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}($||($={}));const V=new Map;function z(e,t,n,o=!1){const r=e.getAttribute("rel");let i=e.getAttribute("href"),s=null;if("stylesheet"===r&&i){if(i=y(i,n.url),o)return{url:i,info:{code:"",isGlobal:e.hasAttribute("global")}};s=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:s,isGlobal:e.hasAttribute("global")})}else r&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(r)?o?s=document.createComment(`link element with rel=${r}${i?" & href="+i:""} removed by micro-app`):t.removeChild(e):i&&e.setAttribute("href",y(i,n.url));return o?{replaceComment:s}:s?t.replaceChild(s,e):void 0}function Y(e,t,n){const o=Array.from(t.source.links.entries()),r=[];for(const[e]of o){const n=V.get(e);n?r.push(n):r.push(I(e,t.name))}w(r,(e=>{!function(e,t,n,o,r){t.isGlobal&&!V.has(e)&&V.set(e,n);const i=C("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=e,i.setAttribute("data-origin-href",e),o.replaceChild(j(i,r),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{u(e,t.name)}),(()=>{t.onLoad(e)}))}const Q=new Map;function X(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=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(T.supportModuleScript&&e.noModule||!T.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=y(i,n.url);const t={code:"",isExternal:!0,isDynamic:o,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(o)return{url:i,info:t};n.source.scripts.set(i,t),r=document.createComment(`script with src='${i}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),i={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:i};n.source.scripts.set(t,i),r=document.createComment("inline script extract by micro-app")}else o||(r=document.createComment("script element removed by micro-app"))}return o?{replaceComment:r}:t.replaceChild(r,e)}function J(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=Q.get(e);n?i.code=n:i.defer||i.async||(o.push(I(e,t.name)),r.push([e,i]))}o.length?w(o,(e=>{!function(e,t,n){t.isGlobal&&!Q.has(e)&&Q.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{u(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Z(e,t,n,o,r){var i;try{const s=ne(e,t,n.code,n.module);if(t.inline||n.module){const a=C("script");if(ee(e,s,n.module,a,r),o)return a;null===(i=t.container)||void 0===i||i.querySelector("micro-app-body").appendChild(a)}else if(te(s,n),o)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ee(e,t,n,o,r){if(n){const e=new Blob([t],{type:"text/javascript"});o.src=URL.createObjectURL(e),o.setAttribute("type","module"),r&&(r.moduleCount&&r.moduleCount--,o.onload=r.bind(o,0===r.moduleCount))}else o.textContent=t;e.startsWith("inline-")||o.setAttribute("data-origin-src",e)}function te(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ne(e,t,n,o){return a(qe.plugins)&&(n=function(e,t,n,o){var r;if(s(o.global))for(const n of o.global)a(n)&&i(n.loader)&&(t=n.loader(t,e,n.options));if(s(null===(r=o.modules)||void 0===r?void 0:r[n]))for(const r of o.modules[n])a(r)&&i(r.loader)&&(t=r.loader(t,e,r.options));return t}(e,n,t.name,qe.plugins)),t.sandBox&&!o?(T.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}function oe(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{oe(e,t)}));for(const n of o)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",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")&&j(n,t):n instanceof HTMLScriptElement?X(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 re(e,t){const n=function(e){const t=C("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!o||!r){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),u(e,t.name)}oe(n,t),t.source.links.size?Y(n,t,o):t.onLoad(n),t.source.scripts.size?J(n,t):t.onLoad(n)}const ie=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(u("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return u("event-center: Invalid callback function");let o=this.eventList.get(e);o?n&&Object.getOwnPropertyNames(o.data).length&&t(o.data):(o={data:{},callbacks:new Set},this.eventList.set(e,o)),o.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!a(t))return u("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 se(e,t){return r(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class ae{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ie.on("global",e,t)}removeGlobalDataListener(e){i(e)&&ie.off("global",e)}setGlobalData(e){v(),ie.dispatch("global",e)}getGlobalData(){return ie.getData("global")}clearGlobalDataListener(){const e=this.appName,t=ie.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 le extends ae{addDataListener(e,t,n){ie.on(se(f(e),!1),t,n)}removeDataListener(e,t){i(t)&&ie.off(se(f(e),!1),t)}getData(e,t=!1){return ie.getData(se(f(e),t))}setData(e,t){ie.dispatch(se(f(e),!0),t)}clearDataListener(e){ie.off(se(f(e),!1))}}class ce extends ae{constructor(e){super(),this.appName=f(e),!this.appName&&u(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ie.on(se(this.appName,!0),e,t)}removeDataListener(e){i(e)&&ie.off(se(this.appName,!0),e)}getData(){return ie.getData(se(this.appName,!0))}dispatch(e){v(),ie.dispatch(se(this.appName,!1),e);const t=De.get(this.appName);if((null==t?void 0:t.container)&&a(e)){const n=new CustomEvent("datachange",{detail:{data:e}});D(t.container).dispatchEvent(n)}}clearDataListener(){ie.off(se(this.appName,!0))}}const ue=new WeakMap;const pe=new WeakMap;const de=new WeakMap;function he(e,t){if(de.has(t))return de.get(t);if(i(t)&&!function(e){if(pe.has(e))return pe.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return pe.set(e,n),n}(t)&&!function(e){if(ue.has(e))return ue.get(e);const t=c(e);return ue.set(e,t),t}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&(n.prototype=t.prototype),de.set(t,n),n}return t}const me=new Map;let fe=!1;const _e=new Map;function ye(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=T;!fe&&function(){if(fe=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return p("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)}))}Object.defineProperty(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=g();return e?me.get(e):me.get("base")},set(e){const o=g();o?me.set(o,e):me.set("base",e),!t&&i(e)&&(t=!0,T.rawDocumentAddEventListener.call(T.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,o,r){var i;const s=g();if(s&&(!(null===(i=De.get(s))||void 0===i?void 0:i.umdMode)||!c(o))){const e=_e.get(s);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else _e.set(s,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,o,r){var i;const s=g();if(s&&(!(null===(i=De.get(s))||void 0===i?void 0:i.umdMode)||!c(o))){const e=_e.get(s);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(o)&&n.delete(o)}}n.call(e,t,o,r)}}const we=["unmount","appstate-change"];function be(e,t){return we.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Ae=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=g(),n}}),Ee=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],ge=["location"],ve={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ne;function Ce(e){Ne&&clearTimeout(Ne),Ne=setTimeout(e,0)}class Pe{constructor(e,t,n){this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microWindow={};const o=T.rawWindow,i=T.rawDocument,s=new Map,a=e=>this.microWindow.hasOwnProperty(e)||o.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map,{rawWindow:i,rawDocument:s,rawWindowAddEventListener:a,rawWindowRemoveEventListener:l,rawSetInterval:c,rawSetTimeout:u,rawClearInterval:p,rawClearTimeout:d,rawDocumentRemoveEventListener:h}=T;e.addEventListener=function(t,o,r){t=be(t,e);const s=n.get(t);s?s.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),a.call(i,t,o,r)},e.removeEventListener=function(t,o,r){t=be(t,e);const s=n.get(t);(null==s?void 0:s.size)&&s.has(o)&&s.delete(o),l.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=c.call(i,e,t,...n);return o.set(r,{handler:e,timeout:t,args:n}),r},e.setTimeout=function(e,t,...n){const o=u.call(i,e,t,...n);return r.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),p.call(i,e)},e.clearTimeout=function(e){r.delete(e),d.call(i,e)};const m=new Map,f=new Map;let _,y=new Map,w=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),o.size&&(y=new Map(o)),r.size&&(w=new Map(r)),_=me.get(t);const e=_e.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),y.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),w.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&me.set(t,_),E(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),E(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)l.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{d.call(i,t)})),r.clear()),me.delete(t);const e=_e.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)h.call(s,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(t,s)=>{if(s===Symbol.unscopables)return ve;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return o===o.parent?this.proxyWindow:Reflect.get(o,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s||"Image"===s)switch(this.active&&(E(e),(n?Ce:d)((()=>E(null)))),s){case"document":return i;case"eval":return eval;case"Image":return Ae}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||r(s)&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const l=Reflect.get(o,s);return he(o,l)},set:(e,t,n)=>{if(this.active){if(ge.includes(t))Reflect.set(o,t,n);else if(e.hasOwnProperty(t)||!o.hasOwnProperty(t)||this.scopeProperties.includes(t))Reflect.set(e,t,n),this.injectedKeys.add(t);else{const r=Object.getOwnPropertyDescriptor(o,t),{writable:i,configurable:s,enumerable:a}=r;i&&(Object.defineProperty(e,t,{configurable:s,enumerable:a,writable:i,value:n}),this.injectedKeys.add(t))}(this.escapeProperties.includes(t)||Ee.includes(t)&&!Reflect.has(o,t))&&!this.scopeProperties.includes(t)&&(Reflect.set(o,t,n),this.escapeKeys.add(t))}return!0},has:(e,t)=>this.scopeProperties.includes(t)?t in e:t in ve||t in e||t in o,getOwnPropertyDescriptor:(e,t)=>{if(e.hasOwnProperty(t))return s.set(t,"target"),Object.getOwnPropertyDescriptor(e,t);if(o.hasOwnProperty(t)){s.set(t,"rawWindow");const e=Object.getOwnPropertyDescriptor(o,t);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,t,n)=>"rawWindow"===s.get(t)?Reflect.defineProperty(o,t,n):Reflect.defineProperty(e,t,n),ownKeys:e=>Reflect.ownKeys(o).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.injectedKeys.has(t)&&this.injectedKeys.delete(t),this.escapeKeys.has(t)&&Reflect.deleteProperty(o,t),Reflect.deleteProperty(e,t))})}start(e){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=e,T.rawWindow._babelPolyfill&&(T.rawWindow._babelPolyfill=!1),1==++Pe.activeCount&&ye())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.microWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(T.rawWindow,e)})),this.escapeKeys.clear(),0==--Pe.activeCount&&(document.addEventListener=T.rawDocumentAddEventListener,document.removeEventListener=T.rawDocumentRemoveEventListener))}recordUmdSnapshot(){this.microWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=ie.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=ie.eventList.get(se(t,!0));o&&(e.umdDataListeners.normal=new Set(o.callbacks))}(this.microWindow.microApp),this.recordUmdinjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdinjectedValues.set(e,Reflect.get(this.microWindow,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.microWindow.microApp)}getScopeProperties(e){var t;if(a(qe.plugins)){if(s(qe.plugins.global))for(const e of qe.plugins.global)a(e)&&(s(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),s(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if(s(null===(t=qe.plugins.modules)||void 0===t?void 0:t[e]))for(const t of qe.plugins.modules[e])a(t)&&(s(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),s(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=_(n),e.microApp=new ce(t),e.rawWindow=T.rawWindow,e.rawDocument=T.rawDocument,e.removeDomScope=v}}function Oe(e,t,n,o){var r;if(!e)return u(`element does not exist in lifecycle ${n}`,t);e=D(e),v();const s=Object.assign({name:t,container:e},o&&{error:o}),a=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),i(null===(r=qe.lifeCycles)||void 0===r?void 0:r[n])&&qe.lifeCycles[n](a),e.dispatchEvent(a)}function Re(e,t,n={}){const o=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(o)}Pe.activeCount=0;const De=new Map;class Me{constructor({name:e,url:t,ssrUrl:n,container:o,inline:r,scopecss:i,useSandbox:s,macro:a,baseroute:l}){this.state=S.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.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=o?o:null,this.inline=null!=r&&r,this.baseroute=null!=l?l:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=s,this.scopecss=this.useSandbox&&i,this.macro=null!=a&&a,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Pe(e,t,this.macro))}loadSourceCode(){var e;this.state=S.LOADING_SOURCE_CODE,I((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)),u(t,e.name)}re(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=>{u(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||S.UNMOUNT===this.state)return;this.state=S.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,S.UNMOUNT!==this.state&&(this.onerror(e),this.state=S.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,s;if("boolean"==typeof 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=S.LOADING_SOURCE_CODE);let a;if(Oe(this.container,this.name,L.BEFOREMOUNT),this.state=S.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdMode){null===(s=this.sandBox)||void 0===s||s.rebuildUmdSnapshot();try{a=this.umdHookMount()}catch(e){u("an error occurred in the mount function \n",this.name,e)}this.handleMounted(a)}else{let e=!1;!function(e,t,n){const o=Array.from(e.entries()),r=[],i=[];for(const[e,s]of o)s.isDynamic||(s.defer||s.async?(s.isExternal&&!s.code?r.push(I(e,t.name)):r.push(s.code),i.push([e,s]),s.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Z(e,t,s,!1),n(!1)));r.length?Promise.all(r).then((e=>{e.forEach(((e,o)=>{const[r,s]=i[o];s.code=s.code||e,Z(r,t,s,!1,n),!s.module&&n(!1)})),n(void 0===n.moduleCount)})).catch((e=>{u(e,t.name),n(!0)})):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{a=this.umdHookMount()}catch(e){u("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(a))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){S.UNMOUNT!==this.state&&(this.state=S.MOUNTED,Oe(this.container,this.name,L.MOUNTED))}unmount(e,t){let n;if(this.state===S.LOAD_SOURCE_ERROR&&(e=!0),this.state=S.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){u("an error occurred in the unmount function \n",this.name,e)}Re("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;null===(n=this.sandBox)||void 0===n||n.stop(),e?this.actionsForCompletelyDestory():this.umdMode&&this.container.childElementCount&&P(this.container,this.source.html,!1),Oe(this.container,this.name,L.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestory(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],De.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=U.KEEP_ALIVE_HIDDEN,Re("appstate-change",this.name,{appState:"afterhidden"}),Oe(e,this.name,L.AFTERHIDDEN)}showKeepAliveApp(e){Re("appstate-change",this.name,{appState:"beforeshow"}),Oe(e,this.name,L.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=U.KEEP_ALIVE_SHOW,Re("appstate-change",this.name,{appState:"aftershow"}),Oe(this.container,this.name,L.AFTERSHOW)}onerror(e){Oe(this.container,this.name,L.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(S.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:T.rawWindow;return this.libraryName=D(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Se(e,t){const n=De.get(f(e));return new Promise((o=>{if(n)if(n.getAppState()===S.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestory(),o();else if(n.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,o):(null==t?void 0:t.clearAliveState)?n.unmount(!1,o):o();else{const e=D(n.container),r=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()},i=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()};if(e.addEventListener("unmount",r),e.addEventListener("afterhidden",i),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else p(`app ${e} does not exist`),o()}))}const Le=new WeakMap;function Ue(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 Le.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?j(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 Le.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:o,info:r,replaceComment:i}=z(t,e,n,!0);if(o&&r){const e=C("style");return e.__MICRO_APP_LINK_PATH__=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,j(r,n),void d((()=>G(o)));if(V.has(e)){const i=V.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,j(r,n),void d((()=>G(o)))}I(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&V.set(e,i),r.textContent=i,j(r,n),G(o)})).catch((e=>{u(e,n.name),q(o)}))}(o,r,n,t,e),Le.set(t,e),e}return i?(Le.set(t,i),i):t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:i}=X(t,e,n,!0)||{};if(r&&i){if(i.isExternal){const e=function(e,t,n,o){const r=()=>G(o);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&d(r),Z(e,n,t,!0,r)}if(Q.has(e)){const o=Q.get(e);return t.code=o,n.source.scripts.set(e,t),!t.module&&d(r),Z(e,n,t,!0,r)}let i;return i=n.inline||t.module?C("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),I(e,n.name).then((s=>{t.code=s,n.source.scripts.set(e,t),t.isGlobal&&Q.set(e,s);try{s=ne(e,n,s,t.module),n.inline||t.module?ee(e,s,t.module,i,r):te(s,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&G(o)})).catch((e=>{u(e,n.name),q(o)})),i}(r,i,n,t);return Le.set(t,e),e}{const e=Z(r,n,i,!0);return Le.set(t,e),e}}return o?(Le.set(t,o),o):t}return t}function Ie(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?T.rawAppendChild.call(i,o):t!==T.rawRemoveChild||i.contains(o)?t===T.rawAppend||t===T.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n===document.body){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?T.rawAppendChild.call(i,o):t!==T.rawRemoveChild||i.contains(o)?t===T.rawAppend||t===T.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===T.rawAppend||t===T.rawPrepend?t.call(n,o):t.call(n,o,r)}function Te(e){var t;return null!==(t=Le.get(e))&&void 0!==t?t:e}function xe(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=De.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?Ie(r,o,e,Ue(e,t,r),n&&Te(n)):o===T.rawAppend||o===T.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===T.rawAppend||o===T.rawPrepend){const n=g();if(!(t instanceof Node)&&n){const r=De.get(n);if(null==r?void 0:r.container){if(e===document.head)return o.call(r.container.querySelector("micro-app-head"),t);if(e===document.body)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function $e(){!function(){const e=T.rawDocument;function t(t){var n,o,r;const i=g();return i&&t&&!R(t)&&e===this?null!==(r=null===(o=null===(n=De.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:T.rawQuerySelector.call(this,t)}function n(t){var n,o,r;const i=g();return i&&t&&!R(t)&&e===this?null!==(r=null===(o=null===(n=De.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:T.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ke(T.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ke(T.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ke(T.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!g()||O(e))return T.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return T.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!g()||O(e))return T.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return T.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const o=g();if(!o||R(e)||O(e)||!(null===(t=De.get(o))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return T.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return T.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!g()||O(e))return T.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return T.rawGetElementsByName.call(this,e)}}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(a(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{r(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&p("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__&&De.has(this.__MICRO_APP_NAME__)){const n=De.get(this.__MICRO_APP_NAME__);T.rawSetAttribute.call(this,e,y(t,n.url))}else T.rawSetAttribute.call(this,e,t)},Element.prototype.appendChild=function(e){return xe(this,e,null,T.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return xe(this,e,t,T.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return xe(this,e,t,T.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)xe(this,e[t],null,T.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)xe(this,e[t-1],null,T.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=De.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?Ie(t,T.rawRemoveChild,this,Te(e)):T.rawRemoveChild.call(this,e)}return T.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=T.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ke(e){const t=g();return t&&(e.__MICRO_APP_NAME__=t),e}function We(){E(null),Document.prototype.createElement=T.rawCreateElement,Document.prototype.createElementNS=T.rawCreateElementNS,Document.prototype.createDocumentFragment=T.rawCreateDocumentFragment,Document.prototype.querySelector=T.rawQuerySelector,Document.prototype.querySelectorAll=T.rawQuerySelectorAll,Document.prototype.getElementById=T.rawGetElementById,Document.prototype.getElementsByClassName=T.rawGetElementsByClassName,Document.prototype.getElementsByTagName=T.rawGetElementsByTagName,Document.prototype.getElementsByName=T.rawGetElementsByName,Element.prototype.setAttribute=T.rawSetAttribute,Element.prototype.appendChild=T.rawAppendChild,Element.prototype.insertBefore=T.rawInsertBefore,Element.prototype.replaceChild=T.rawReplaceChild,Element.prototype.removeChild=T.rawRemoveChild,Element.prototype.append=T.rawAppend,Element.prototype.prepend=T.rawPrepend,Element.prototype.cloneNode=T.rawCloneNode}let Be=!1;function He(){Ke(),De.forEach((e=>{e.container&&D(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&De.clear(),je.size&&(je.clear(),We())}function Ke(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",He,!1)}const je=new Map;function Fe(e){class n extends HTMLElement{constructor(){super(),this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWating=!1;const e=f(this.getAttribute("name")),t=m(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=De.get(e);if(e!==this.appName&&n&&S.UNMOUNT!==n.getAppState()&&U.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),u(`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)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,je.has(this)||this.performWhenFirstCreated(),d((()=>Oe(this,this.appName,L.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():(je.delete(this),this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{0===je.size&&We()})))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===M.NAME?"appName":"appUrl"]!==n)if(e!==M.URL||this.appUrl)if(e!==M.NAME||this.appName)this.isWating||(this.isWating=!0,d(this.handleAttributeUpdate));else{const e=f(n);if(!e)return u(`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=m(n,this.appName)))return u(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===je.set(this,!0).size&&($e(),function(){if(!Be){Be=!0;const e=C("style");e.setAttribute("type","text/css"),e.textContent=`\n${qe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,T.rawDocument.head.appendChild(e)}}(),Ke(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",He,!1))}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(T.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),De.has(this.appName)){const e=De.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==S.UNMOUNT?e.isPrefetch||e.getAppState()===S.UNMOUNT?(p(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):u(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var o;this.getDisposeResult("ssr")?this.ssrUrl=y(T.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(o=this.shadowRoot)&&void 0!==o?o:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):u(`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!(!r(t)||!t)||(u(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,d((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;De.has(this.appName)&&De.get(this.appName).actionsForCompletelyDestory();const t=new Me({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"),macro:this.getDisposeResult("macro"),baseroute:this.getBaseRouteCompatible()});De.set(this.appName,t)}handleUnmount(e,t){const n=De.get(this.appName);n&&n.getAppState()!==S.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=De.get(this.appName);e&&e.getAppState()!==S.UNMOUNT&&e.getKeepAliveState()!==U.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){d((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||qe[e])&&this.compatibleDisablSpecialProperties(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)}compatibleDisablSpecialProperties(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,n)}function Ge(e){if(!n)return u("preFetch is only supported in browser environment");b((()=>{i(e)&&(e=e()),function(e){const t=[];return s(e)&&e.forEach((e=>{a(e)&&(e.name=f(e.name),e.url=m(e.url,e.name),e.name&&e.url&&!De.has(e.name)&&t.push(e))})),t}(e).forEach((e=>{var t,n,o;const r=new Me({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:qe.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:qe.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:qe.macro});r.isPrefetch=!0,De.set(e.name,r)}))}))}var qe=new class extends le{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ge}start(e){if(!n||!window.customElements)return u("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return u(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return p(`element ${this.tagName} is already defined`);if(x(),e&&a(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.macro=e.macro,this.ssr=e.ssr,i(e.fetch)&&(this.fetch=e.fetch),a(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ge(e.preFetchApps),e.globalAssets&&(a(t=e.globalAssets)&&b((()=>{if(s(t.js)){const e=t.js.filter((e=>r(e)&&e.includes(".js")&&!Q.has(e))),n=[];e.forEach((e=>{n.push(I(e))})),w(n,(t=>{const n=e[t.index];Q.has(n)||Q.set(n,t.data)}),(e=>{u(e)}))}if(s(t.css)){const e=t.css.filter((e=>r(e)&&e.includes(".css")&&!V.has(e))),n=[];e.forEach((e=>{n.push(I(e))})),w(n,(t=>{const n=e[t.index];V.has(n)||V.set(n,t.data)}),(e=>{u(e)}))}}))),a(e.plugins))){const t=e.plugins.modules;if(a(t))for(const e in t){const n=f(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Fe(this.tagName)}};e.EventCenterForMicroApp=ce,e.default=qe,e.getActiveApps=function(){const e=[];return De.forEach(((t,n)=>{S.UNMOUNT===t.getAppState()||t.isPrefetch||e.push(n)})),e},e.getAllApps=function(){return Array.from(De.keys())},e.preFetch=Ge,e.pureCreateElement=C,e.removeDomScope=v,e.unmountAllApps=function(e){return Array.from(De.keys()).reduce(((t,n)=>t.then((()=>Se(n,e)))),Promise.resolve())},e.unmountApp=Se,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.6.2",n="undefined"!=typeof window,o="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function r(e){return"string"==typeof e}function i(e){return"function"==typeof e}const s=Array.isArray;function a(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function u(e,t=null,...n){const o=t&&r(t)?` app ${t}:`:"";r(e)?console.error(`[micro-app]${o} ${e}`,...n):console.error(`[micro-app]${o}`,e,...n)}function p(e,t=null,...n){const o=t&&r(t)?` app ${t}:`:"";r(e)?console.warn(`[micro-app]${o} ${e}`,...n):console.warn(`[micro-app]${o}`,e,...n)}function d(e,...t){Promise.resolve().then(e.bind(null,...t))}function h(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function m(e,t=null){if(!r(e)||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(h(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return u(e,t),""}}function f(e){return r(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function _(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,_(h(t))).toString()}function w(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{l(e)?e.then((e=>{t({data:e,index:o}),i()})).catch((e=>{n({error:e,index:o}),i()})):(t({data:e,index:o}),i())}))}const b=o.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let A=null;function E(e){A=e}function g(){return A}function v(){E(null)}function N(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function C(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),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function O(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function R(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function D(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}var M,S,L,U;function I(e,t=null,n={}){return i(Ge.fetch)?Ge.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}!function(e){e.NAME="name",e.URL="url"}(M||(M={})),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"}(S||(S={})),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"}(L||(L={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(U||(U={}));const T={};function x(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,o=Element.prototype.replaceChild,r=Element.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Element.prototype.cloneNode,l=Document.prototype.createElement,c=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,h=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,y=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=g(),n}}),w=Function("return window")(),b=Function("return document")(),A="noModule"in document.createElement("script"),E=b.body.querySelector("#micro-app-template-style"),v=w.addEventListener,N=w.removeEventListener,C=w.setInterval,P=w.setTimeout,O=w.clearInterval,R=w.clearTimeout,D=b.addEventListener,M=b.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(T,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCloneNode:a,rawCreateElement:l,rawCreateElementNS:c,rawCreateDocumentFragment:u,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:h,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:y,rawWindow:w,rawDocument:b,supportModuleScript:A,templateStyle:E,rawWindowAddEventListener:v,rawWindowRemoveEventListener:N,rawSetInterval:C,rawSetTimeout:P,rawClearInterval:O,rawClearTimeout:R,rawDocumentAddEventListener:D,rawDocumentRemoveEventListener:M})}}var $;function k(e,t){const{selectorText:n,cssText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===n)return o.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function W(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^(data|blob):/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!N())return e;{const t=r.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;r=r.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(r)&&o&&(t=function(e){const t=e.split("/");return t.pop(),h(t.join("/")+"/")}(o)),`url("${y(r,t)}")`}))}function B(e,t,n){const o=H(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function H(e,t){let n="";for(const o of e)switch(o.type){case $.STYLE_RULE:n+=k(o,t);break;case $.MEDIA_RULE:n+=B(o,t,"media");break;case $.SUPPORTS_RULE:n+=B(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function K(e,t,n,o,r,i){var s,a;if(!t.__MICRO_APP_HAS_SCOPED__){let l=W(H(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);N()&&(l=l.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm,((e,t,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?e:`${t}"${n}"`))),t.textContent=l,t.__MICRO_APP_HAS_SCOPED__=!0}}function j(e,t){if(t.scopecss){const n=`${Ge.tagName}[name=${t.name}]`;let o=T.templateStyle;if(o||(T.templateStyle=o=C("style"),o.setAttribute("id","micro-app-template-style"),T.rawDocument.body.appendChild(o),o.sheet.disabled=!0),e.textContent)o.textContent=e.textContent,K(o,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__),o.textContent="";else{const o=new MutationObserver((function(){var r,i;o.disconnect(),!e.textContent&&(null===(i=null===(r=e.sheet)||void 0===r?void 0:r.cssRules)||void 0===i?void 0:i.length)||e.hasAttribute("data-styled")||K(e,e,e.textContent,n,t.url,e.__MICRO_APP_LINK_PATH__)}));o.observe(e,{childList:!0})}}return e}function F(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function G(e){const t=new CustomEvent("load");F(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function q(e){const t=new CustomEvent("error");F(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}!function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}($||($={}));const V=new Map;function z(e,t,n,o=!1){const r=e.getAttribute("rel");let i=e.getAttribute("href"),s=null;if("stylesheet"===r&&i){if(i=y(i,n.url),o)return{url:i,info:{code:"",isGlobal:e.hasAttribute("global")}};s=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:s,isGlobal:e.hasAttribute("global")})}else r&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(r)?o?s=document.createComment(`link element with rel=${r}${i?" & href="+i:""} removed by micro-app`):t.removeChild(e):i&&e.setAttribute("href",y(i,n.url));return o?{replaceComment:s}:s?t.replaceChild(s,e):void 0}function Y(e,t,n){const o=Array.from(t.source.links.entries()),r=[];for(const[e]of o){const n=V.get(e);n?r.push(n):r.push(I(e,t.name))}w(r,(e=>{!function(e,t,n,o,r){t.isGlobal&&!V.has(e)&&V.set(e,n);const i=C("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=e,i.setAttribute("data-origin-href",e),o.replaceChild(j(i,r),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{u(e,t.name)}),(()=>{t.onLoad(e)}))}const Q=new Map;function X(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=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(T.supportModuleScript&&e.noModule||!T.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=y(i,n.url);const t={code:"",isExternal:!0,isDynamic:o,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(o)return{url:i,info:t};n.source.scripts.set(i,t),r=document.createComment(`script with src='${i}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),i={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:i};n.source.scripts.set(t,i),r=document.createComment("inline script extract by micro-app")}else o||(r=document.createComment("script element removed by micro-app"))}return o?{replaceComment:r}:t.replaceChild(r,e)}function J(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=Q.get(e);n?i.code=n:i.defer||i.async||(o.push(I(e,t.name)),r.push([e,i]))}o.length?w(o,(e=>{!function(e,t,n){t.isGlobal&&!Q.has(e)&&Q.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{u(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Z(e,t,n,o,r){var i;try{const s=ne(e,t,n.code,n.module);if(t.inline||n.module){const a=C("script");if(ee(e,s,n.module,a,r),o)return a;null===(i=t.container)||void 0===i||i.querySelector("micro-app-body").appendChild(a)}else if(te(s,n),o)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ee(e,t,n,o,r){if(n){const e=new Blob([t],{type:"text/javascript"});o.src=URL.createObjectURL(e),o.setAttribute("type","module"),r&&(r.moduleCount&&r.moduleCount--,o.onload=r.bind(o,0===r.moduleCount))}else o.textContent=t;e.startsWith("inline-")||o.setAttribute("data-origin-src",e)}function te(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ne(e,t,n,o){return a(Ge.plugins)&&(n=function(e,t,n,o){var r;if(s(o.global))for(const n of o.global)a(n)&&i(n.loader)&&(t=n.loader(t,e,n.options));if(s(null===(r=o.modules)||void 0===r?void 0:r[n]))for(const r of o.modules[n])a(r)&&i(r.loader)&&(t=r.loader(t,e,r.options));return t}(e,n,t.name,Ge.plugins)),t.sandBox&&!o?(T.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}function oe(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{oe(e,t)}));for(const n of o)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",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")&&j(n,t):n instanceof HTMLScriptElement?X(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 re(e,t){const n=function(e){const t=C("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!o||!r){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),u(e,t.name)}oe(n,t),t.source.links.size?Y(n,t,o):t.onLoad(n),t.source.scripts.size?J(n,t):t.onLoad(n)}const ie=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(u("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return u("event-center: Invalid callback function");let o=this.eventList.get(e);o?n&&Object.getOwnPropertyNames(o.data).length&&t(o.data):(o={data:{},callbacks:new Set},this.eventList.set(e,o)),o.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!a(t))return u("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 se(e,t){return r(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class ae{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ie.on("global",e,t)}removeGlobalDataListener(e){i(e)&&ie.off("global",e)}setGlobalData(e){v(),ie.dispatch("global",e)}getGlobalData(){return ie.getData("global")}clearGlobalDataListener(){const e=this.appName,t=ie.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 le extends ae{addDataListener(e,t,n){ie.on(se(f(e),!1),t,n)}removeDataListener(e,t){i(t)&&ie.off(se(f(e),!1),t)}getData(e,t=!1){return ie.getData(se(f(e),t))}setData(e,t){ie.dispatch(se(f(e),!0),t)}clearDataListener(e){ie.off(se(f(e),!1))}}class ce extends ae{constructor(e){super(),this.appName=f(e),!this.appName&&u(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ie.on(se(this.appName,!0),e,t)}removeDataListener(e){i(e)&&ie.off(se(this.appName,!0),e)}getData(){return ie.getData(se(this.appName,!0))}dispatch(e){v(),ie.dispatch(se(this.appName,!1),e);const t=Re.get(this.appName);if((null==t?void 0:t.container)&&a(e)){const n=new CustomEvent("datachange",{detail:{data:e}});D(t.container).dispatchEvent(n)}}clearDataListener(){ie.off(se(this.appName,!0))}}const ue=new WeakMap;const pe=new WeakMap;const de=new WeakMap;function he(e,t){if(de.has(t))return de.get(t);if(i(t)&&!function(e){if(pe.has(e))return pe.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return pe.set(e,n),n}(t)&&!function(e){if(ue.has(e))return ue.get(e);const t=c(e);return ue.set(e,t),t}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&(n.prototype=t.prototype),de.set(t,n),n}return t}const me=new Map;let fe=!1;const _e=new Map;function ye(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=T;!fe&&function(){if(fe=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return p("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)}))}Object.defineProperty(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=g();return e?me.get(e):me.get("base")},set(e){const o=g();o?me.set(o,e):me.set("base",e),!t&&i(e)&&(t=!0,T.rawDocumentAddEventListener.call(T.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,o,r){var i;const s=g();if(s&&(!(null===(i=Re.get(s))||void 0===i?void 0:i.umdMode)||!c(o))){const e=_e.get(s);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else _e.set(s,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,o,r){var i;const s=g();if(s&&(!(null===(i=Re.get(s))||void 0===i?void 0:i.umdMode)||!c(o))){const e=_e.get(s);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(o)&&n.delete(o)}}n.call(e,t,o,r)}}const we=["unmount","appstate-change"];function be(e,t){return we.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const Ae=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ee=["location"],ge={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let ve;function Ne(e){ve&&clearTimeout(ve),ve=setTimeout(e,0)}class Ce{constructor(e,t,n){this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microWindow={};const o=T.rawWindow,i=T.rawDocument,s=new Map,a=e=>this.microWindow.hasOwnProperty(e)||o.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map,{rawWindow:i,rawDocument:s,rawWindowAddEventListener:a,rawWindowRemoveEventListener:l,rawSetInterval:c,rawSetTimeout:u,rawClearInterval:p,rawClearTimeout:d,rawDocumentRemoveEventListener:h}=T;e.addEventListener=function(t,o,r){t=be(t,e);const s=n.get(t);s?s.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),a.call(i,t,o,r)},e.removeEventListener=function(t,o,r){t=be(t,e);const s=n.get(t);(null==s?void 0:s.size)&&s.has(o)&&s.delete(o),l.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=c.call(i,e,t,...n);return o.set(r,{handler:e,timeout:t,args:n}),r},e.setTimeout=function(e,t,...n){const o=u.call(i,e,t,...n);return r.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),p.call(i,e)},e.clearTimeout=function(e){r.delete(e),d.call(i,e)};const m=new Map,f=new Map;let _,y=new Map,w=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),o.size&&(y=new Map(o)),r.size&&(w=new Map(r)),_=me.get(t);const e=_e.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),y.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),w.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&me.set(t,_),E(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),E(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)l.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{d.call(i,t)})),r.clear()),me.delete(t);const e=_e.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)h.call(s,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(t,s)=>{if(s===Symbol.unscopables)return ge;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return o===o.parent?this.proxyWindow:Reflect.get(o,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s||"Image"===s)switch(this.active&&(E(e),(n?Ne:d)((()=>E(null)))),s){case"document":return i;case"eval":return eval;case"Image":return T.ImageProxy}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||r(s)&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const l=Reflect.get(o,s);return he(o,l)},set:(e,t,n)=>{if(this.active){if(Ee.includes(t))Reflect.set(o,t,n);else if(e.hasOwnProperty(t)||!o.hasOwnProperty(t)||this.scopeProperties.includes(t))Reflect.set(e,t,n),this.injectedKeys.add(t);else{const r=Object.getOwnPropertyDescriptor(o,t),{writable:i,configurable:s,enumerable:a}=r;i&&(Object.defineProperty(e,t,{configurable:s,enumerable:a,writable:i,value:n}),this.injectedKeys.add(t))}(this.escapeProperties.includes(t)||Ae.includes(t)&&!Reflect.has(o,t))&&!this.scopeProperties.includes(t)&&(Reflect.set(o,t,n),this.escapeKeys.add(t))}return!0},has:(e,t)=>this.scopeProperties.includes(t)?t in e:t in ge||t in e||t in o,getOwnPropertyDescriptor:(e,t)=>{if(e.hasOwnProperty(t))return s.set(t,"target"),Object.getOwnPropertyDescriptor(e,t);if(o.hasOwnProperty(t)){s.set(t,"rawWindow");const e=Object.getOwnPropertyDescriptor(o,t);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,t,n)=>"rawWindow"===s.get(t)?Reflect.defineProperty(o,t,n):Reflect.defineProperty(e,t,n),ownKeys:e=>Reflect.ownKeys(o).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.injectedKeys.has(t)&&this.injectedKeys.delete(t),this.escapeKeys.has(t)&&Reflect.deleteProperty(o,t),Reflect.deleteProperty(e,t))})}start(e){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=e,T.rawWindow._babelPolyfill&&(T.rawWindow._babelPolyfill=!1),1==++Ce.activeCount&&ye())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.microWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(T.rawWindow,e)})),this.escapeKeys.clear(),0==--Ce.activeCount&&(document.addEventListener=T.rawDocumentAddEventListener,document.removeEventListener=T.rawDocumentRemoveEventListener))}recordUmdSnapshot(){this.microWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=ie.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=ie.eventList.get(se(t,!0));o&&(e.umdDataListeners.normal=new Set(o.callbacks))}(this.microWindow.microApp),this.recordUmdinjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdinjectedValues.set(e,Reflect.get(this.microWindow,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.microWindow.microApp)}getScopeProperties(e){var t;if(a(Ge.plugins)){if(s(Ge.plugins.global))for(const e of Ge.plugins.global)a(e)&&(s(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),s(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if(s(null===(t=Ge.plugins.modules)||void 0===t?void 0:t[e]))for(const t of Ge.plugins.modules[e])a(t)&&(s(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),s(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=_(n),e.microApp=new ce(t),e.rawWindow=T.rawWindow,e.rawDocument=T.rawDocument,e.removeDomScope=v}}function Pe(e,t,n,o){var r;if(!e)return u(`element does not exist in lifecycle ${n}`,t);e=D(e),v();const s=Object.assign({name:t,container:e},o&&{error:o}),a=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),i(null===(r=Ge.lifeCycles)||void 0===r?void 0:r[n])&&Ge.lifeCycles[n](a),e.dispatchEvent(a)}function Oe(e,t,n={}){const o=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(o)}Ce.activeCount=0;const Re=new Map;class De{constructor({name:e,url:t,ssrUrl:n,container:o,inline:r,scopecss:i,useSandbox:s,macro:a,baseroute:l}){this.state=S.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.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=o?o:null,this.inline=null!=r&&r,this.baseroute=null!=l?l:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=s,this.scopecss=this.useSandbox&&i,this.macro=null!=a&&a,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ce(e,t,this.macro))}loadSourceCode(){var e;this.state=S.LOADING_SOURCE_CODE,I((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)),u(t,e.name)}re(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=>{u(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||S.UNMOUNT===this.state)return;this.state=S.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,S.UNMOUNT!==this.state&&(this.onerror(e),this.state=S.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,s;if("boolean"==typeof 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=S.LOADING_SOURCE_CODE);let a;if(Pe(this.container,this.name,L.BEFOREMOUNT),this.state=S.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdMode){null===(s=this.sandBox)||void 0===s||s.rebuildUmdSnapshot();try{a=this.umdHookMount()}catch(e){u("an error occurred in the mount function \n",this.name,e)}this.handleMounted(a)}else{let e=!1;!function(e,t,n){const o=Array.from(e.entries()),r=[],i=[];for(const[e,s]of o)s.isDynamic||(s.defer||s.async?(s.isExternal&&!s.code?r.push(I(e,t.name)):r.push(s.code),i.push([e,s]),s.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Z(e,t,s,!1),n(!1)));r.length?Promise.all(r).then((e=>{e.forEach(((e,o)=>{const[r,s]=i[o];s.code=s.code||e,Z(r,t,s,!1,n),!s.module&&n(!1)})),n(void 0===n.moduleCount)})).catch((e=>{u(e,t.name),n(!0)})):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{a=this.umdHookMount()}catch(e){u("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(a))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){S.UNMOUNT!==this.state&&(this.state=S.MOUNTED,Pe(this.container,this.name,L.MOUNTED))}unmount(e,t){let n;if(this.state===S.LOAD_SOURCE_ERROR&&(e=!0),this.state=S.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){u("an error occurred in the unmount function \n",this.name,e)}Oe("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;null===(n=this.sandBox)||void 0===n||n.stop(),e?this.actionsForCompletelyDestory():this.umdMode&&this.container.childElementCount&&P(this.container,this.source.html,!1),Pe(this.container,this.name,L.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestory(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Re.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=U.KEEP_ALIVE_HIDDEN,Oe("appstate-change",this.name,{appState:"afterhidden"}),Pe(e,this.name,L.AFTERHIDDEN)}showKeepAliveApp(e){Oe("appstate-change",this.name,{appState:"beforeshow"}),Pe(e,this.name,L.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=U.KEEP_ALIVE_SHOW,Oe("appstate-change",this.name,{appState:"aftershow"}),Pe(this.container,this.name,L.AFTERSHOW)}onerror(e){Pe(this.container,this.name,L.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(S.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:T.rawWindow;return this.libraryName=D(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Me(e,t){const n=Re.get(f(e));return new Promise((o=>{if(n)if(n.getAppState()===S.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestory(),o();else if(n.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,o):(null==t?void 0:t.clearAliveState)?n.unmount(!1,o):o();else{const e=D(n.container),r=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()},i=()=>{e.removeEventListener("unmount",r),e.removeEventListener("afterhidden",i),o()};if(e.addEventListener("unmount",r),e.addEventListener("afterhidden",i),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else p(`app ${e} does not exist`),o()}))}const Se=new WeakMap;function Le(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 Se.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?j(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 Se.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:o,info:r,replaceComment:i}=z(t,e,n,!0);if(o&&r){const e=C("style");return e.__MICRO_APP_LINK_PATH__=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,j(r,n),void d((()=>G(o)));if(V.has(e)){const i=V.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,j(r,n),void d((()=>G(o)))}I(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&V.set(e,i),r.textContent=i,j(r,n),G(o)})).catch((e=>{u(e,n.name),q(o)}))}(o,r,n,t,e),Se.set(t,e),e}return i?(Se.set(t,i),i):t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:i}=X(t,e,n,!0)||{};if(r&&i){if(i.isExternal){const e=function(e,t,n,o){const r=()=>G(o);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&d(r),Z(e,n,t,!0,r)}if(Q.has(e)){const o=Q.get(e);return t.code=o,n.source.scripts.set(e,t),!t.module&&d(r),Z(e,n,t,!0,r)}let i;return i=n.inline||t.module?C("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),I(e,n.name).then((s=>{t.code=s,n.source.scripts.set(e,t),t.isGlobal&&Q.set(e,s);try{s=ne(e,n,s,t.module),n.inline||t.module?ee(e,s,t.module,i,r):te(s,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&G(o)})).catch((e=>{u(e,n.name),q(o)})),i}(r,i,n,t);return Se.set(t,e),e}{const e=Z(r,n,i,!0);return Se.set(t,e),e}}return o?(Se.set(t,o),o):t}return t}function Ue(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?T.rawAppendChild.call(i,o):t!==T.rawRemoveChild||i.contains(o)?t===T.rawAppend||t===T.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n===document.body){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?T.rawAppendChild.call(i,o):t!==T.rawRemoveChild||i.contains(o)?t===T.rawAppend||t===T.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===T.rawAppend||t===T.rawPrepend?t.call(n,o):t.call(n,o,r)}function Ie(e){var t;return null!==(t=Se.get(e))&&void 0!==t?t:e}function Te(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Re.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?Ue(r,o,e,Le(e,t,r),n&&Ie(n)):o===T.rawAppend||o===T.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===T.rawAppend||o===T.rawPrepend){const n=g();if(!(t instanceof Node)&&n){const r=Re.get(n);if(null==r?void 0:r.container){if(e===document.head)return o.call(r.container.querySelector("micro-app-head"),t);if(e===document.body)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function xe(){!function(){const e=T.rawDocument;function t(t){var n,o,r;const i=g();return i&&t&&!R(t)&&e===this?null!==(r=null===(o=null===(n=Re.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:T.rawQuerySelector.call(this,t)}function n(t){var n,o,r;const i=g();return i&&t&&!R(t)&&e===this?null!==(r=null===(o=null===(n=Re.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:T.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return $e(T.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return $e(T.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return $e(T.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!g()||O(e))return T.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return T.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!g()||O(e))return T.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return T.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const o=g();if(!o||R(e)||O(e)||!(null===(t=Re.get(o))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return T.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return T.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!g()||O(e))return T.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return T.rawGetElementsByName.call(this,e)}}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(a(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{r(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&p("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__&&Re.has(this.__MICRO_APP_NAME__)){const n=Re.get(this.__MICRO_APP_NAME__);T.rawSetAttribute.call(this,e,y(t,n.url))}else T.rawSetAttribute.call(this,e,t)},Element.prototype.appendChild=function(e){return Te(this,e,null,T.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return Te(this,e,t,T.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return Te(this,e,t,T.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)Te(this,e[t],null,T.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)Te(this,e[t-1],null,T.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Re.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?Ue(t,T.rawRemoveChild,this,Ie(e)):T.rawRemoveChild.call(this,e)}return T.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=T.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function $e(e){const t=g();return t&&(e.__MICRO_APP_NAME__=t),e}function ke(){E(null),Document.prototype.createElement=T.rawCreateElement,Document.prototype.createElementNS=T.rawCreateElementNS,Document.prototype.createDocumentFragment=T.rawCreateDocumentFragment,Document.prototype.querySelector=T.rawQuerySelector,Document.prototype.querySelectorAll=T.rawQuerySelectorAll,Document.prototype.getElementById=T.rawGetElementById,Document.prototype.getElementsByClassName=T.rawGetElementsByClassName,Document.prototype.getElementsByTagName=T.rawGetElementsByTagName,Document.prototype.getElementsByName=T.rawGetElementsByName,Element.prototype.setAttribute=T.rawSetAttribute,Element.prototype.appendChild=T.rawAppendChild,Element.prototype.insertBefore=T.rawInsertBefore,Element.prototype.replaceChild=T.rawReplaceChild,Element.prototype.removeChild=T.rawRemoveChild,Element.prototype.append=T.rawAppend,Element.prototype.prepend=T.rawPrepend,Element.prototype.cloneNode=T.rawCloneNode}let We=!1;function Be(){He(),Re.forEach((e=>{e.container&&D(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Re.clear(),Ke.size&&(Ke.clear(),ke())}function He(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",Be,!1)}const Ke=new Map;function je(e){class n extends HTMLElement{constructor(){super(),this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWating=!1;const e=f(this.getAttribute("name")),t=m(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Re.get(e);if(e!==this.appName&&n&&S.UNMOUNT!==n.getAppState()&&U.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),u(`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)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,Ke.has(this)||this.performWhenFirstCreated(),d((()=>Pe(this,this.appName,L.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():(Ke.delete(this),this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{0===Ke.size&&ke()})))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===M.NAME?"appName":"appUrl"]!==n)if(e!==M.URL||this.appUrl)if(e!==M.NAME||this.appName)this.isWating||(this.isWating=!0,d(this.handleAttributeUpdate));else{const e=f(n);if(!e)return u(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Ge.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=m(n,this.appName)))return u(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===Ke.set(this,!0).size&&(xe(),function(){if(!We){We=!0;const e=C("style");e.setAttribute("type","text/css"),e.textContent=`\n${Ge.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,T.rawDocument.head.appendChild(e)}}(),He(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",Be,!1))}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(T.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Re.has(this.appName)){const e=Re.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==S.UNMOUNT?e.isPrefetch||e.getAppState()===S.UNMOUNT?(p(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):u(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var o;this.getDisposeResult("ssr")?this.ssrUrl=y(T.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(o=this.shadowRoot)&&void 0!==o?o:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===U.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):u(`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!(!r(t)||!t)||(u(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,d((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Re.has(this.appName)&&Re.get(this.appName).actionsForCompletelyDestory();const t=new De({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"),macro:this.getDisposeResult("macro"),baseroute:this.getBaseRouteCompatible()});Re.set(this.appName,t)}handleUnmount(e,t){const n=Re.get(this.appName);n&&n.getAppState()!==S.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Re.get(this.appName);e&&e.getAppState()!==S.UNMOUNT&&e.getKeepAliveState()!==U.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){d((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Ge[e])&&this.compatibleDisablSpecialProperties(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)}compatibleDisablSpecialProperties(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?Ge.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Ge.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Fe(e){if(!n)return u("preFetch is only supported in browser environment");b((()=>{i(e)&&(e=e()),function(e){const t=[];return s(e)&&e.forEach((e=>{a(e)&&(e.name=f(e.name),e.url=m(e.url,e.name),e.name&&e.url&&!Re.has(e.name)&&t.push(e))})),t}(e).forEach((e=>{var t,n,o;const r=new De({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:Ge.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:Ge.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:Ge.macro});r.isPrefetch=!0,Re.set(e.name,r)}))}))}var Ge=new class extends le{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Fe}start(e){if(!n||!window.customElements)return u("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return u(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return p(`element ${this.tagName} is already defined`);if(x(),e&&a(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.macro=e.macro,this.ssr=e.ssr,i(e.fetch)&&(this.fetch=e.fetch),a(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Fe(e.preFetchApps),e.globalAssets&&(a(t=e.globalAssets)&&b((()=>{if(s(t.js)){const e=t.js.filter((e=>r(e)&&e.includes(".js")&&!Q.has(e))),n=[];e.forEach((e=>{n.push(I(e))})),w(n,(t=>{const n=e[t.index];Q.has(n)||Q.set(n,t.data)}),(e=>{u(e)}))}if(s(t.css)){const e=t.css.filter((e=>r(e)&&e.includes(".css")&&!V.has(e))),n=[];e.forEach((e=>{n.push(I(e))})),w(n,(t=>{const n=e[t.index];V.has(n)||V.set(n,t.data)}),(e=>{u(e)}))}}))),a(e.plugins))){const t=e.plugins.modules;if(a(t))for(const e in t){const n=f(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;je(this.tagName)}};e.EventCenterForMicroApp=ce,e.default=Ge,e.getActiveApps=function(){const e=[];return Re.forEach(((t,n)=>{S.UNMOUNT===t.getAppState()||t.isPrefetch||e.push(n)})),e},e.getAllApps=function(){return Array.from(Re.keys())},e.preFetch=Fe,e.pureCreateElement=C,e.removeDomScope=v,e.unmountAllApps=function(e){return Array.from(Re.keys()).reduce(((t,n)=>t.then((()=>Me(n,e)))),Promise.resolve())},e.unmountApp=Me,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@micro-zoe/micro-app", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "A lightweight, efficient and powerful micro front-end framework", | ||
@@ -46,3 +46,4 @@ "private": false, | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage" | ||
"test:coverage": "jest --coverage", | ||
"prepublishOnly": "yarn lint && yarn test && yarn build" | ||
}, | ||
@@ -49,0 +50,0 @@ "repository": { |
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
883813
4339