@micro-zoe/micro-app
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -9,3 +9,3 @@ /// <reference path="../typings/global.d.ts" /> | ||
export { default } from '@micro-zoe/micro-app/micro_app'; | ||
export { removeDomScope, pureCreateElement, version } from '@micro-zoe/micro-app/libs/utils'; | ||
export { removeDomScope, pureCreateElement, version, setCurrentAppName } from '@micro-zoe/micro-app/libs/utils'; | ||
} | ||
@@ -63,20 +63,5 @@ | ||
import type { Func } from '@micro-app/types'; | ||
type RequestIdleCallbackOptions = { | ||
timeout: number; | ||
}; | ||
type RequestIdleCallbackInfo = { | ||
readonly didTimeout: boolean; | ||
timeRemaining: () => number; | ||
}; | ||
global { | ||
interface Window { | ||
requestIdleCallback(callback: (info: RequestIdleCallbackInfo) => void, opts?: RequestIdleCallbackOptions): number; | ||
_babelPolyfill: boolean; | ||
proxyWindow: WindowProxy; | ||
__MICRO_APP_ENVIRONMENT__: boolean; | ||
} | ||
} | ||
export const rawWindow: any; | ||
export const rawDocument: any; | ||
export const version = "__VERSION__"; | ||
export const isBrowser: boolean; | ||
export const globalThis: Window; | ||
/** | ||
@@ -136,3 +121,8 @@ * format error log | ||
export function unique(array: any[]): any[]; | ||
export const requestIdleCallback: (callback: (info: RequestIdleCallbackInfo) => void, opts?: RequestIdleCallbackOptions | undefined) => number; | ||
export const requestIdleCallback: (callback: (info: { | ||
readonly didTimeout: boolean; | ||
timeRemaining: () => number; | ||
}) => void, opts?: { | ||
timeout: number; | ||
} | undefined) => number; | ||
export function setCurrentAppName(appName: string | null): void; | ||
@@ -153,3 +143,2 @@ export function getCurrentAppName(): string | null; | ||
export function cloneNode<T extends Element, Q extends Element>(origin: T, target: Q): void; | ||
export {}; | ||
} | ||
@@ -156,0 +145,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=new Function("return window")(),t=new Function("return document")();function n(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function o(e,...t){"string"==typeof e?console.warn(`[micro-app] ${e}`,...t):console.warn("[micro-app]",e,...t)}function r(e,...t){Promise.resolve().then(e.bind(null,...t))}function i(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function s(e){if("string"!=typeof e||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(i(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return n(e),""}}function a(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 c(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)?e:new URL(e,a(i(t))).toString()}function l(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{"[object Promise]"===toString.call(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 u=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let p=null;function d(e){p=e}function h(){return p}function m(){d(null)}function f(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function y(e){return"function"==typeof e}function _(e,n){const o=t.createElement(e,n);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function b(e,t){t.innerHTML="";const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var g,E,w,v;function O(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 A(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^data:/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!f())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(),i(t.join("/")+"/")}(o)),`url("${c(r,t)}")`}))}function N(e,t,n){const o=R(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function R(e,t){let n="";for(const o of e)switch(o.type){case v.STYLE_RULE:n+=O(o,t);break;case v.MEDIA_RULE:n+=N(o,t,"media");break;case v.SUPPORTS_RULE:n+=N(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function M(e,t,n,o,r,i){var s,a;let c=A(R(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);f()&&(c=c.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=c}!function(e){e.NAME="name",e.URL="url"}(g||(g={})),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"}(E||(E={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(w||(w={})),function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(v||(v={}));let P=t.body.querySelector("#micro-app-template-style");function S(e,n){const o=Ve.get(n);if(null==o?void 0:o.scopecss){const r=`${ve.tagName}[name=${n}]`;if(P||(P=_("style"),P.setAttribute("id","micro-app-template-style"),t.body.appendChild(P),P.sheet.disabled=!0),e.textContent)P.textContent=e.textContent,M(P,e,e.textContent,r,o.url,e.linkpath),P.textContent="";else{const t=new MutationObserver((function(){var n,i;t.disconnect(),!e.textContent&&(null===(i=null===(n=e.sheet)||void 0===n?void 0:n.cssRules)||void 0===i?void 0:i.length)||e.hasAttribute("data-styled")||M(e,e,e.textContent,r,o.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function C(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function D(e){const t=new CustomEvent("load");C(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function L(e){const t=new CustomEvent("error");C(t,e),"function"==typeof e.onerror?e.onerror(t):e.dispatchEvent(t)}const U=new Map;function x(e,t,n,o,r=!1){const i=e.getAttribute("rel");let s=e.getAttribute("href"),a=null;if("stylesheet"===i&&s){if(s=c(s,n.url),r)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};{a=document.createComment(`the link with href=${s} move to micro-app-head as style element`);const t=document.createComment(`placeholder for link with href=${s}`);o.appendChild(t),n.source.links.set(s,{code:"",placeholder:t,isGlobal:e.hasAttribute("global")})}}else s&&e.setAttribute("href",c(s,n.url));return r?{replaceComment:a}:a?t.replaceChild(a,e):void 0}function T(e,t,o){const r=Array.from(t.source.links.entries()),i=[];for(const[e]of r){const n=U.get(e);n?i.push(n):i.push(Oe(e,t.name))}l(i,(e=>{!function(e,t,n,o,r){t.isGlobal&&!U.has(e)&&U.set(e,n);const i=_("style");i.textContent=n,i.linkpath=e,o.replaceChild(S(i,r.name),t.placeholder),t.placeholder=null,t.code=n}(r[e.index][0],r[e.index][1],e.data,o,t)}),(e=>{n(e)}),(()=>{t.onLoad(e)}))}const j=new Map,I="noModule"in document.createElement("script");function $(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=document.createComment("script element with exclude attribute ignored by micro-app");else if(I&&e.noModule||!I&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=c(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=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 r=document.createComment("script ignored by micro-app");return o?{replaceComment:r}:t.replaceChild(r,e)}function k(e,t){const o=Array.from(t.source.scripts.entries()),r=[],i=[];for(const[e,n]of o)if(n.isExternal){const o=j.get(e);o?n.code=o:n.defer||n.async||(r.push(Oe(e,t.name)),i.push([e,n]))}r.length?l(r,(e=>{!function(e,t,n){t.isGlobal&&!j.has(e)&&j.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{n(e)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function W(e,t,n,o,r){var i;try{if(t=B(e,t,n),n.inline){const e=_("script");if(o&&e.setAttribute("type","module"),e.textContent=t,r)return e;null===(i=n.container)||void 0===i||i.querySelector("micro-app-body").appendChild(e)}else if(Function(t)(),r)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error("[micro-app from runScript]",e)}}function B(t,n,o){return"object"==typeof ve.plugins&&(n=function(e,t,n,o){var r;if("[object Array]"===toString.call(o.global))for(const n of o.global)"object"==typeof n&&"function"==typeof n.loader&&(t=n.loader(t,e,n.options));if("[object Array]"===toString.call(null===(r=o.modules)||void 0===r?void 0:r[n]))for(const r of o.modules[n])"object"==typeof r&&"function"==typeof r.loader&&(t=r.loader(t,e,r.options));return t}(t,n,o.name,ve.plugins)),o.sandBox?(e.__MICRO_APP_PROXY_WINDOW__=o.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}const G=Element.prototype.setAttribute,H=Node.prototype.appendChild,F=Node.prototype.insertBefore,q=Node.prototype.replaceChild,K=Node.prototype.removeChild,z=Element.prototype.append,Y=Element.prototype.prepend,V=Document.prototype.createElement,X=Document.prototype.createElementNS,J=Document.prototype.createDocumentFragment,Z=Document.prototype.querySelector,Q=Document.prototype.querySelectorAll,ee=Document.prototype.getElementById,te=Document.prototype.getElementsByClassName,ne=Document.prototype.getElementsByTagName,oe=Document.prototype.getElementsByName,re=new WeakMap;function ie(e,t,o){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return re.set(t,e),e}return o.scopecss?S(t,o.name):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return re.set(t,e),e}if(!o.scopecss)return t;const{url:i,info:s}=x(t,e,o,null,!0);if(i&&s){const e=_("style");return e.linkpath=i,function(e,t,o,i,s){if(o.source.links.has(e))return s.textContent=o.source.links.get(e).code,S(s,o.name),void r((()=>D(i)));if(U.has(e)){const n=U.get(e);return t.code=n,o.source.links.set(e,t),s.textContent=n,S(s,o.name),void r((()=>D(i)))}Oe(e,o.name).then((n=>{t.code=n,o.source.links.set(e,t),t.isGlobal&&U.set(e,n),s.textContent=n,S(s,o.name),D(i)})).catch((e=>{n(e),L(i)}))}(i,s,o,t,e),re.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:i,url:s,info:a}=$(t,e,o,!0);if(s&&a){if(a.code){const e=W(s,a.code,o,a.module,!0);return re.set(t,e),e}{const e=function(e,t,o,i){if(o.source.scripts.has(e)){const n=o.source.scripts.get(e);return r((()=>D(i))),W(e,n.code,o,t.module,!0)}if(j.has(e)){const n=j.get(e);return t.code=n,o.source.scripts.set(e,t),r((()=>D(i))),W(e,n,o,t.module,!0)}let s;return s=o.inline?_("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),Oe(e,o.name).then((n=>{t.code=n,o.source.scripts.set(e,t),t.isGlobal&&j.set(e,n);try{n=B(e,n,o),o.inline?(t.module&&s.setAttribute("type","module"),s.textContent=n):Function(n)()}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}D(i)})).catch((e=>{n(e),L(i)})),s}(s,a,o,t);return re.set(t,e),e}}return re.set(t,i),i}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)?H.call(i,o):t!==K||i.contains(o)?t===z||t===Y?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)?H.call(i,o):t!==K||i.contains(o)?t===z||t===Y?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===z||t===Y?t.call(n,o):t.call(n,o,r)}function ae(e){var t;return null!==(t=re.get(e))&&void 0!==t?t:e}function ce(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Ve.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?se(r,o,e,ie(e,t,r),n&&ae(n)):o===z||o===Y?o.call(e,t):o.call(e,t,n)}if(o===z||o===Y){const n=h();if(!(t instanceof Node)&&n){const r=Ve.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 le(){!function(){function e(e){var n,o,r;const i=h();return i&&"head"!==e&&"body"!==e&&"html"!==e?null!==(r=null===(o=null===(n=Ve.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(e))&&void 0!==r?r:null:Z.call(t,e)}function n(e){var n,o,r;const i=h();return i&&"head"!==e&&"body"!==e&&"html"!==e?null!==(r=null===(o=null===(n=Ve.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(e))&&void 0!==r?r:[]:Q.call(t,e)}Document.prototype.createElement=function(e,n){return ue(V.call(t,e,n))},Document.prototype.createElementNS=function(e,n,o){return ue(X.call(t,e,n,o))},Document.prototype.createDocumentFragment=function(){return ue(J.call(t))},Document.prototype.querySelector=e,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(n){return!h()||/^\d/.test(n)?ee.call(t,n):e(`#${n}`)},Document.prototype.getElementsByClassName=function(e){return!h()||/^\d/.test(e)?te.call(t,e):n(`.${e}`)},Document.prototype.getElementsByTagName=function(e){var o;const r=h();return!r||/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)||!(null===(o=Ve.get(r))||void 0===o?void 0:o.inline)&&/^script$/i.test(e)?ne.call(t,e):n(e)},Document.prototype.getElementsByName=function(e){return!h()||/^\d/.test(e)?oe.call(t,e):n(`[name=${e}]`)}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if("[object Object]"===toString.call(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{"string"==typeof n&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&o("property data must be an object");else if(("src"===e&&/^(img|iframe|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ve.has(this.__MICRO_APP_NAME__)){const n=Ve.get(this.__MICRO_APP_NAME__);G.call(this,e,c(t,n.url))}else G.call(this,e,t)},Node.prototype.appendChild=function(e){return ce(this,e,null,H)},Node.prototype.insertBefore=function(e,t){return ce(this,e,t,F)},Node.prototype.replaceChild=function(e,t){return ce(this,e,t,q)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ce(this,e[t],null,z),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ce(this,e[t-1],null,Y),t--},Node.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ve.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?se(t,K,this,ae(e)):K.call(this,e)}return K.call(this,e)}}function ue(e){const t=h();return t&&(e.__MICRO_APP_NAME__=t),e}function pe(){d(null),Document.prototype.createElement=V,Document.prototype.createElementNS=X,Document.prototype.createDocumentFragment=J,Document.prototype.querySelector=Z,Document.prototype.querySelectorAll=Q,Document.prototype.getElementById=ee,Document.prototype.getElementsByClassName=te,Document.prototype.getElementsByTagName=ne,Document.prototype.getElementsByName=oe,Element.prototype.setAttribute=G,Node.prototype.appendChild=H,Node.prototype.insertBefore=F,Node.prototype.replaceChild=q,Node.prototype.removeChild=K,Element.prototype.append=z,Element.prototype.prepend=Y}let de=!1;function he(e,t,o,r){var i;if(!e)return n(`element does not exist in lifecycle ${o},it seems the app has unmounted`);e instanceof ShadowRoot&&(e=e.host);const s=Object.assign({name:t,container:e},r&&{error:r}),a=new CustomEvent(o,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),"function"==typeof(null===(i=ve.lifeCycles)||void 0===i?void 0:i[o])&&ve.lifeCycles[o](a),e.dispatchEvent(a)}function me(){Ve.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),Ve.clear()}const fe=new Map;class ye extends HTMLElement{constructor(){super(),this.appName="",this.appUrl="",this.version="0.3.3",this.isWating=!1,this.cacheData=null,this.handleAttributeUpdate=()=>{var e;this.isWating=!1;const t=this.getAttribute("name"),o=s(this.getAttribute("url"));if(this.legalAttribute("name",t)&&this.legalAttribute("url",o)){const r=Ve.get(t);if(t!==this.appName&&r&&E.UNMOUNT!==r.getAppStatus()&&!r.isPrefetch)return this.setAttribute("name",this.appName),n(`an app named ${t} already exists`);t===this.appName&&o===this.appUrl||(this.handleUnmount(t===this.appName),this.appName=t,this.appUrl=o,(null!==(e=this.shadowRoot)&&void 0!==e?e:this).innerHTML="",r&&r.url===o?this.handleAppMount(r):this.handleCreate())}else t!==this.appName&&this.setAttribute("name",this.appName)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){if(fe.has(this)||this.performWhenFirstCreated(),r((()=>he(this,this.appName,w.CREATED))),!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Ve.get(this.appName);e?e.url!==this.appUrl||!e.isPrefetch&&e.getAppStatus()!==E.UNMOUNT?e.isPrefetch?n(`the url: ${this.appUrl} is different from prefetch url: ${e.url}`):n(`an app named ${this.appName} already exists`):this.handleAppMount(e):this.handleCreate()}disconnectedCallback(){fe.delete(this),this.handleUnmount(this.getDisposeResult("destory")),0===fe.size&&(pe(),window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",me,!1))}attributeChangedCallback(e,t,o){if(this.legalAttribute(e,o)&&this[e===g.NAME?"appName":"appUrl"]!==o)if(e!==g.URL||this.appUrl)e!==g.NAME||this.appName?this.isWating||(this.isWating=!0,r(this.handleAttributeUpdate)):(this.cacheData&&(ve.setData(o,this.cacheData),this.cacheData=null),this.appName=o);else{if(!(o=s(o)))return n("Invalid attribute url");this.appUrl=o}}performWhenFirstCreated(){1===fe.set(this,!0).size&&(le(),function(){if(!de){de=!0;const e=_("style");e.setAttribute("type","text/css"),e.textContent=`\n${ve.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,t.head.appendChild(e)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",me,!1))}legalAttribute(e,t){return!("string"!=typeof t||!t)||(n(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,r((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var e;const t=new Xe({name:this.appName,url:this.appUrl,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()});Ve.set(this.appName,t)}handleUnmount(e){const t=Ve.get(this.appName);t&&E.UNMOUNT!==t.getAppStatus()&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||ve[e])&&"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:""}set data(e){this.appName?ve.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?ve.getData(this.appName,!0):this.cacheData?this.cacheData:null}}const _e=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(n("event-center: Invalid name"),!1)}on(e,t,o=!1){if(this.isLegalName(e)){if("function"!=typeof t)return n("event-center: Invalid callback function");let r=this.eventList.get(e);r?o&&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&&("function"==typeof t?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if("[object Object]"!==toString.call(t))return n("event-center: data must be object");let o=this.eventList.get(e);if(o){if(o.data!==t){o.data=t;for(const e of o.callbacks)e(t)}}else o={data:t,callbacks:new Set},this.eventList.set(e,o)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function be(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class ge{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),_e.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&_e.off("global",e)}setGlobalData(e){_e.dispatch("global",e)}clearGlobalDataListener(){const e=this.appName,t=_e.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 Ee extends ge{addDataListener(e,t,n){_e.on(be(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&_e.off(be(e,!1),t)}getData(e,t=!1){return _e.getData(be(e,t))}setData(e,t){_e.dispatch(be(e,!0),t)}clearDataListener(e){_e.off(be(e,!1))}}class we extends ge{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=t,_e.on(be(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&_e.off(be(this.appName,!0),e)}getData(){return _e.getData(be(this.appName,!0))}dispatch(e){m(),_e.dispatch(be(this.appName,!1),e);const t=Ve.get(this.appName);if((null==t?void 0:t.container)&&"[object Object]"===toString.call(e)){const n=new CustomEvent("datachange",{detail:{data:e}});let o=t.container;o instanceof ShadowRoot&&(o=o.host),o.dispatchEvent(n)}}clearDataListener(){_e.off(be(this.appName,!0))}}var ve=new class extends Ee{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Je}start(e){if(!(null===window||void 0===window?void 0:window.customElements))return n("customElements is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return n(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}var t,r;e&&"[object Object]"===toString.call(e)&&(this.shadowDOM=e.shadowDOM,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.macro=e.macro,y(e.fetch)&&(this.fetch=e.fetch),"[object Object]"===toString.call(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),"[object Object]"===toString.call(e.plugins)&&(this.plugins=e.plugins),e.preFetchApps&&Je(e.preFetchApps),e.globalAssets&&(t=e.globalAssets,"[object Object]"===toString.call(t)&&u((()=>{if("[object Array]"===toString.call(t.js)){const e=t.js.filter((e=>"string"==typeof e&&e.includes(".js")&&!j.has(e))),o=[];e.forEach((e=>{o.push(Oe(e))})),l(o,(t=>{const n=e[t.index];j.has(n)||j.set(n,t.data)}),(e=>{n(e)}))}if("[object Array]"===toString.call(t.css)){const e=t.css.filter((e=>"string"==typeof e&&e.includes(".css")&&!U.has(e))),o=[];e.forEach((e=>{o.push(Oe(e))})),l(o,(t=>{const n=e[t.index];U.has(n)||U.set(n,t.data)}),(e=>{n(e)}))}})))),r=this.tagName,window.customElements.get(r)?o(`element ${r} is already defined`):window.customElements.define(r,ye)}};function Oe(e,t=null,n={}){return y(ve.fetch)?ve.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function Ae(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{Ae(e,t,n)}));for(const r of o)r instanceof HTMLLinkElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),r):t.scopecss?x(r,e,t,n):r.hasAttribute("href")&&r.setAttribute("href",c(r.getAttribute("href"),t.url)):r instanceof HTMLStyleElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),r):t.scopecss&&n.appendChild(S(r,t.name)):r instanceof HTMLScriptElement?$(r,e,t):r instanceof HTMLMetaElement||r instanceof HTMLTitleElement?e.removeChild(r):/^(img|iframe)$/i.test(r.tagName)&&r.hasAttribute("src")&&r.setAttribute("src",c(r.getAttribute("src"),t.url))}function Ne(e,t){const o=function(e){const t=_("div");return t.innerHTML=e,t}(e),r=o.querySelector("micro-app-head"),i=o.querySelector("micro-app-body");if(!r||!i){const e=`element ${r?"body":"head"} is missing`;return t.onerror(new Error(e)),n(e)}Ae(o,t,r),t.source.links.size?T(o,t,r):t.onLoad(o),t.source.scripts.size?k(o,t):t.onLoad(o)}const Re=new WeakMap;const Me=new WeakMap;const Pe=new WeakMap;function Se(e,t){if(Pe.has(t))return Pe.get(t);if(y(t)&&!function(e){if(Me.has(e))return Me.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 Me.set(e,n),n}(t)&&!function(e){if(Re.has(e))return Re.get(e);const t=0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype");return Re.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),Pe.set(t,n),n}return t}const Ce=window.addEventListener,De=window.removeEventListener,Le=window.setInterval,Ue=window.setTimeout,xe=window.clearInterval,Te=window.clearTimeout,je=document.addEventListener,Ie=document.removeEventListener,$e=new Map;let ke=!1;const We=new Map;function Be(){ke||function(){ke=!0;const e=Object.getOwnPropertyDescriptor(document,"onclick");if(!1===(null==e?void 0:e.configurable))return o("Cannot redefine document property onclick");const t=document.onclick;document.onclick=null;let n=!1;function r(e){$e.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=h();return e?$e.get(e):$e.get("base")},set(e){const t=h();t?$e.set(t,e):$e.set("base",e),n||"function"!=typeof e||(n=!0,je.call(document,"click",r,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(e,t,n){const o=h();if(o){const r=We.get(o);if(r){const n=r.get(e);n?n.add(t):r.set(e,new Set([t]))}else We.set(o,new Map([[e,new Set([t])]]));t&&(t.__MICRO_MARK_OPTIONS__=n)}je.call(document,e,t,n)},document.removeEventListener=function(e,t,n){const o=h();if(o){const n=We.get(o);if(n){const o=n.get(e);(null==o?void 0:o.size)&&o.has(t)&&o.delete(t)}}Ie.call(document,e,t,n)}}function Ge(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const He=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Fe=["location"],qe={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ke;function ze(e){Ke&&clearTimeout(Ke),Ke=setTimeout(e,0)}class Ye{constructor(n,o,i){this.active=!1,this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.microWindow={},this.injectedKeys=new Set,this.escapeKeys=new Set;const s=new Map,a=t=>this.microWindow.hasOwnProperty(t)||e.hasOwnProperty(t);this.getScopeProperties(n),this.inject(this.microWindow,n,o),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map;e.addEventListener=function(t,o,r){t=Ge(t,e);const i=n.get(t);i?i.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),Ce.call(window,t,o,r)},e.removeEventListener=function(t,o,r){t=Ge(t,e);const i=n.get(t);(null==i?void 0:i.size)&&i.has(o)&&i.delete(o),De.call(window,t,o,r)},e.setInterval=function(e,t,...n){const r=Le(e,t,...n);return o.set(r,{handler:e,timeout:t,args:n}),r},e.setTimeout=function(e,t,...n){const o=Ue(e,t,...n);return r.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),xe(e)},e.clearTimeout=function(e){r.delete(e),Te(e)};const i=new Map,s=new Map;let a,c=new Map,l=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&i.set(t,new Set(e))})),o.size&&(c=new Map(o)),r.size&&(l=new Map(r)),a=$e.get(t);const e=We.get(t);e&&e.forEach(((e,t)=>{e.size&&s.set(t,new Set(e))}))},rebuildUmdEffect:()=>{i.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),c.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),l.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),a&&$e.set(t,a),d(t),s.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),d(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)De.call(window,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{xe(t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{Te(t)})),r.clear()),$e.delete(t);const e=We.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)Ie.call(document,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(o,s)=>{if(s===Symbol.unscopables)return qe;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return e===e.parent?this.proxyWindow:Reflect.get(e,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s)switch(this.active&&(d(n),(i?ze:r)((()=>d(null)))),s){case"document":return t;case"eval":return eval}if(this.scopeProperties.includes(s))return Reflect.get(o,s);if(Reflect.has(o,s))return Reflect.get(o,s);const c=Reflect.get(e,s);return Se(e,c)},set:(t,n,o)=>{if(this.active){if(Fe.includes(n))Reflect.set(e,n,o);else if(t.hasOwnProperty(n)||!e.hasOwnProperty(n)||this.scopeProperties.includes(n))Reflect.set(t,n,o),this.injectedKeys.add(n);else{const r=Object.getOwnPropertyDescriptor(e,n),{writable:i,configurable:s,enumerable:a}=r;i&&(Object.defineProperty(t,n,{configurable:s,enumerable:a,writable:i,value:o}),this.injectedKeys.add(n))}(this.escapeProperties.includes(n)||He.includes(n)&&!Reflect.has(e,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(e,n,o),this.escapeKeys.add(n))}return!0},has:(t,n)=>this.scopeProperties.includes(n)?n in t:n in qe||n in t||n in e,getOwnPropertyDescriptor:(t,n)=>{if(t.hasOwnProperty(n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(t,n);if(e.hasOwnProperty(n)){s.set(n,"rawWindow");const t=Object.getOwnPropertyDescriptor(e,n);return t&&!t.configurable&&(t.configurable=!0),t}},defineProperty:(t,n,o)=>"rawWindow"===s.get(n)?Reflect.defineProperty(e,n,o):Reflect.defineProperty(t,n,o),ownKeys:t=>Reflect.ownKeys(e).concat(Reflect.ownKeys(t)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(t,n)=>!t.hasOwnProperty(n)||(this.escapeKeys.has(n)&&Reflect.deleteProperty(e,n),Reflect.deleteProperty(t,n))})}start(t){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=t,e._babelPolyfill&&(e._babelPolyfill=!1),1==++Ye.activeCount&&Be())}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((t=>{Reflect.deleteProperty(e,t)})),this.escapeKeys.clear(),0==--Ye.activeCount&&(document.addEventListener=je,document.removeEventListener=Ie))}recordUmdSnapshot(){this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=_e.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=_e.eventList.get(be(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("object"==typeof ve.plugins){if("[object Array]"===toString.call(ve.plugins.global))for(const e of ve.plugins.global)"object"==typeof e&&("[object Array]"===toString.call(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),"[object Array]"===toString.call(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if("[object Array]"===toString.call(null===(t=ve.plugins.modules)||void 0===t?void 0:t[e]))for(const t of ve.plugins.modules[e])"object"==typeof t&&("[object Array]"===toString.call(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),"[object Array]"===toString.call(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(n,o,r){n.__MICRO_APP_ENVIRONMENT__=!0,n.__MICRO_APP_NAME__=o,n.__MICRO_APP_PUBLIC_PATH__=a(r),n.microApp=new we(o),n.rawWindow=e,n.rawDocument=t,n.removeDomScope=m}}Ye.activeCount=0;const Ve=new Map;class Xe{constructor({name:e,url:t,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseroute:a}){this.status=E.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=e,this.url=t,this.useSandbox=i,this.scopecss=this.useSandbox&&r,this.macro=null!=s&&s,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ye(e,t,this.macro))}loadSourceCode(){var e;this.status=E.LOADING_SOURCE_CODE,Oe((e=this).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)),n(t)}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=>{n(`Failed to fetch data from ${e.url}, micro-app stop rendering`,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||E.UNMOUNT===this.status)return;this.status=E.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,E.UNMOUNT!==this.status&&(this.onerror(e),this.status=E.LOAD_SOURCE_ERROR)}mount(e,t,o){var i,s,a,c;if("boolean"==typeof t&&t!==this.inline&&(this.inline=t),this.container=null!==(i=this.container)&&void 0!==i?i:e,this.baseroute=null!=o?o:this.baseroute,2===this.loadSourceLevel){if(he(this.container,this.name,w.BEFOREMOUNT),this.status=E.MOUNTING,b(this.source.html,this.container),null===(s=this.sandBox)||void 0===s||s.start(this.baseroute),this.umdHookMount)null===(c=this.sandBox)||void 0===c||c.rebuildUmdSnapshot(),this.umdHookMount();else{!function(e,t){const o=Array.from(e.entries()),r=[],i=[];for(const[e,n]of o)n.isDynamic||(n.defer||n.async?(n.isExternal&&!n.code?r.push(Oe(e,t.name)):r.push(n.code),i.push([e,n])):W(e,n.code,t,n.module,!1));r.length&&Promise.all(r).then((e=>{e.forEach(((e,n)=>{const[o,r]=i[n];W(o,r.code=r.code||e,t,r.module,!1)}))})).catch((e=>{n(e)}))}(this.source.scripts,this);const{mount:e,unmount:t}=this.getUmdLibraryHooks();y(e)&&y(t)&&(this.umdHookMount=e,this.umdHookunMount=t,null===(a=this.sandBox)||void 0===a||a.recordUmdSnapshot(),b(this.container,this.source.html),l=this.source.html,p=this.name,u((()=>{var e;const t=Array.from(l.querySelectorAll("style"));for(const n of t)-1===(null===(e=n.textContent)||void 0===e?void 0:e.indexOf(`${ve.tagName}[name=${p}]`))&&S(n,p)})),this.umdHookMount())}var l,p;E.UNMOUNT!==this.status&&(this.status=E.MOUNTED,r((()=>{E.UNMOUNT!==this.status&&he(this.container,this.name,w.MOUNTED)})))}else this.status=E.LOADING_SOURCE_CODE}unmount(e){var t;this.status===E.LOAD_SOURCE_ERROR&&(e=!0),this.status=E.UNMOUNT,he(this.container,this.name,w.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(e){const t=new CustomEvent(`unmount-${e}`);window.dispatchEvent(t)}(this.name),null===(t=this.sandBox)||void 0===t||t.stop(),this.container=null,e&&Ve.delete(this.name)}onerror(e){he(this.container,this.name,w.ERROR,e)}getAppStatus(){return this.status}getUmdLibraryHooks(){var t,n;if(E.UNMOUNT!==this.status){const o=null!==(n=null===(t=this.sandBox)||void 0===t?void 0:t.proxyWindow)&&void 0!==n?n:e,r=(this.container instanceof ShadowRoot?this.container.host:this.container).getAttribute("library")||`micro-app-${this.name}`;return"object"==typeof o[r]?o[r]:{}}return{}}}function Je(e){u((()=>{"function"==typeof e&&(e=e()),function(e){const t=[];return"[object Array]"===toString.call(e)&&e.forEach((e=>{e.url=s(e.url),"[object Object]"===toString.call(e)&&e.name&&"string"==typeof e.name&&e.url&&!Ve.has(e.name)&&t.push(e)})),t}(e).forEach((e=>{var t,n,o;const r=new Xe({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:ve.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:ve.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:ve.macro});r.isPrefetch=!0,Ve.set(e.name,r)}))}))}exports.default=ve,exports.preFetch=Je,exports.pureCreateElement=_,exports.removeDomScope=m,exports.version="0.3.3"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window;function t(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function n(e,...t){"string"==typeof e?console.warn(`[micro-app] ${e}`,...t):console.warn("[micro-app]",e,...t)}function o(e,...t){Promise.resolve().then(e.bind(null,...t))}function r(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function i(e){if("string"!=typeof e||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(r(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${o}`:""}catch(e){return t(e),""}}function s(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 a(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,s(r(t))).toString()}function c(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{"[object Promise]"===toString.call(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 l=function(){let e;if("undefined"!=typeof global)e=global;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("global object is unavailable in this environment")}return e}().requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let u=null;function p(e){u=e}function d(){return u}function h(){p(null)}function m(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function f(e){return"function"==typeof e}function y(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function _(e,t){t.innerHTML="";const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var w,b,g;!function(e){e.NAME="name",e.URL="url"}(w||(w={})),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"}(b||(b={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(g||(g={}));const E={};function v(){if(e){const e=Element.prototype.setAttribute,t=Node.prototype.appendChild,n=Node.prototype.insertBefore,o=Node.prototype.replaceChild,r=Node.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Document.prototype.createElement,c=Document.prototype.createElementNS,l=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,h=Document.prototype.getElementsByClassName,m=Document.prototype.getElementsByTagName,f=Document.prototype.getElementsByName,y=Function("return window")(),_=Function("return document")(),w="noModule"in document.createElement("script"),b=_.body.querySelector("#micro-app-template-style"),g=y.addEventListener,v=y.removeEventListener,A=y.setInterval,N=y.setTimeout,O=y.clearInterval,C=y.clearTimeout,R=_.addEventListener,S=_.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(E,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCreateElement:a,rawCreateElementNS:c,rawCreateDocumentFragment:l,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:h,rawGetElementsByTagName:m,rawGetElementsByName:f,rawWindow:y,rawDocument:_,supportModuleScript:w,templateStyle:b,rawWindowAddEventListener:g,rawWindowRemoveEventListener:v,rawSetInterval:A,rawSetTimeout:N,rawClearInterval:O,rawClearTimeout:C,rawDocumentAddEventListener:R,rawDocumentRemoveEventListener:S})}}var A;function N(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 O(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,i)=>{if(/^(data|blob):/.test(i))return e;if(/^(https?:)?\/\//.test(i)){if(!m())return e;{const t=i.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;i=i.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(i)&&o&&(t=function(e){const t=e.split("/");return t.pop(),r(t.join("/")+"/")}(o)),`url("${a(i,t)}")`}))}function C(e,t,n){const o=R(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function R(e,t){let n="";for(const o of e)switch(o.type){case A.STYLE_RULE:n+=N(o,t);break;case A.MEDIA_RULE:n+=C(o,t,"media");break;case A.SUPPORTS_RULE:n+=C(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function S(e,t,n,o,r,i){var s,a;let c=O(R(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);m()&&(c=c.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=c}function M(e,t){const n=Ce.get(t);if(null==n?void 0:n.scopecss){const o=`${ae.tagName}[name=${t}]`;let r=E.templateStyle;if(r||(E.templateStyle=r=y("style"),r.setAttribute("id","micro-app-template-style"),E.rawDocument.body.appendChild(r),r.sheet.disabled=!0),e.textContent)r.textContent=e.textContent,S(r,e,e.textContent,o,n.url,e.linkpath),r.textContent="";else{const t=new MutationObserver((function(){var r,i;t.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")||S(e,e,e.textContent,o,n.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function P(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function D(e){const t=new CustomEvent("load");P(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function L(e){const t=new CustomEvent("error");P(t,e),"function"==typeof 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"}(A||(A={}));const U=new Map;function x(e,t,n,o,r=!1){const i=e.getAttribute("rel");let s=e.getAttribute("href"),c=null;if("stylesheet"===i&&s){if(s=a(s,n.url),r)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};{c=document.createComment(`the link with href=${s} move to micro-app-head as style element`);const t=document.createComment(`placeholder for link with href=${s}`);o.appendChild(t),n.source.links.set(s,{code:"",placeholder:t,isGlobal:e.hasAttribute("global")})}}else s&&e.setAttribute("href",a(s,n.url));return r?{replaceComment:c}:c?t.replaceChild(c,e):void 0}function T(e,n,o){const r=Array.from(n.source.links.entries()),i=[];for(const[e]of r){const t=U.get(e);t?i.push(t):i.push(ce(e,n.name))}c(i,(e=>{!function(e,t,n,o,r){t.isGlobal&&!U.has(e)&&U.set(e,n);const i=y("style");i.textContent=n,i.linkpath=e,o.replaceChild(M(i,r.name),t.placeholder),t.placeholder=null,t.code=n}(r[e.index][0],r[e.index][1],e.data,o,n)}),(e=>{t(e)}),(()=>{n.onLoad(e)}))}const I=new Map;function j(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=document.createComment("script element with exclude attribute ignored 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(E.supportModuleScript&&e.noModule||!E.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=a(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=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 r=document.createComment("script ignored by micro-app")}return o?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function $(e,n){const o=Array.from(n.source.scripts.entries()),r=[],i=[];for(const[e,t]of o)if(t.isExternal){const o=I.get(e);o?t.code=o:t.defer||t.async||(r.push(ce(e,n.name)),i.push([e,t]))}r.length?c(r,(e=>{!function(e,t,n){t.isGlobal&&!I.has(e)&&I.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{t(e)}),(()=>{n.onLoad(e)})):n.onLoad(e)}function k(e,t,n,o,r,i){var s;try{if(t=B(e,t,n),n.inline){const a=y("script");if(W(e,t,o,a,i),r)return a;null===(s=n.container)||void 0===s||s.querySelector("micro-app-body").appendChild(a)}else if(Function(t)(),r)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error("[micro-app from runScript]",e)}}function W(e,t,n,o,r){if(n){const n=new Blob([t],{type:"text/javascript;charset=utf-8"});o.src=URL.createObjectURL(n),o.setAttribute("type","module"),o.setAttribute("originSrc",e),r&&(o.onload=r)}else o.textContent=t}function B(e,t,n){return"object"==typeof ae.plugins&&(t=function(e,t,n,o){var r;if("[object Array]"===toString.call(o.global))for(const n of o.global)"object"==typeof n&&"function"==typeof n.loader&&(t=n.loader(t,e,n.options));if("[object Array]"===toString.call(null===(r=o.modules)||void 0===r?void 0:r[n]))for(const r of o.modules[n])"object"==typeof r&&"function"==typeof r.loader&&(t=r.loader(t,e,r.options));return t}(e,t,n.name,ae.plugins)),n.sandBox?(E.rawWindow.__MICRO_APP_PROXY_WINDOW__=n.sandBox.proxyWindow,`;(function(window, self){with(window){;${t}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):t}const G=new WeakMap;function H(e,n,r){if(n instanceof HTMLStyleElement){if(n.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return G.set(n,e),e}return r.scopecss&&!n.hasAttribute("ignore")?M(n,r.name):n}if(n instanceof HTMLLinkElement){if(n.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return G.set(n,e),e}if(!r.scopecss||n.hasAttribute("ignore"))return n;const{url:i,info:s}=x(n,e,r,null,!0);if(i&&s){const e=y("style");return e.linkpath=i,function(e,n,r,i,s){if(r.source.links.has(e))return s.textContent=r.source.links.get(e).code,M(s,r.name),void o((()=>D(i)));if(U.has(e)){const t=U.get(e);return n.code=t,r.source.links.set(e,n),s.textContent=t,M(s,r.name),void o((()=>D(i)))}ce(e,r.name).then((t=>{n.code=t,r.source.links.set(e,n),n.isGlobal&&U.set(e,t),s.textContent=t,M(s,r.name),D(i)})).catch((e=>{t(e),L(i)}))}(i,s,r,n,e),G.set(n,e),e}return n}if(n instanceof HTMLScriptElement){const{replaceComment:i,url:s,info:a}=j(n,e,r,!0)||{};if(s&&a){if(a.code){const e=k(s,a.code,r,a.module,!0);return G.set(n,e),e}{const e=function(e,n,r,i){if(r.source.scripts.has(e)){const t=r.source.scripts.get(e);return o((()=>D(i))),k(e,t.code,r,n.module,!0)}if(I.has(e)){const t=I.get(e);return n.code=t,r.source.scripts.set(e,n),o((()=>D(i))),k(e,t,r,n.module,!0)}let s;return s=r.inline?y("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),ce(e,r.name).then((t=>{n.code=t,r.source.scripts.set(e,n),n.isGlobal&&I.set(e,t);try{t=B(e,t,r),r.inline?W(e,t,n.module,s):Function(t)()}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}D(i)})).catch((e=>{t(e),L(i)})),s}(s,a,r,n);return G.set(n,e),e}}return i?(G.set(n,i),i):n}return n}function F(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?E.rawAppendChild.call(i,o):t!==E.rawRemoveChild||i.contains(o)?t===E.rawAppend||t===E.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)?E.rawAppendChild.call(i,o):t!==E.rawRemoveChild||i.contains(o)?t===E.rawAppend||t===E.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===E.rawAppend||t===E.rawPrepend?t.call(n,o):t.call(n,o,r)}function q(e){var t;return null!==(t=G.get(e))&&void 0!==t?t:e}function K(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Ce.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?F(r,o,e,H(e,t,r),n&&q(n)):o===E.rawAppend||o===E.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===E.rawAppend||o===E.rawPrepend){const n=d();if(!(t instanceof Node)&&n){const r=Ce.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 z(){!function(){const e=E.rawDocument;function t(t){var n,o,r;const i=d();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Ce.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:E.rawQuerySelector.call(e,t)}function n(t){var n,o,r;const i=d();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Ce.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:E.rawQuerySelectorAll.call(e,t)}Document.prototype.createElement=function(t,n){return Y(E.rawCreateElement.call(e,t,n))},Document.prototype.createElementNS=function(t,n,o){return Y(E.rawCreateElementNS.call(e,t,n,o))},Document.prototype.createDocumentFragment=function(){return Y(E.rawCreateDocumentFragment.call(e))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(n){return!d()||/^\d/.test(n)?E.rawGetElementById.call(e,n):t(`#${n}`)},Document.prototype.getElementsByClassName=function(t){return!d()||/^\d/.test(t)?E.rawGetElementsByClassName.call(e,t):n(`.${t}`)},Document.prototype.getElementsByTagName=function(t){var o;const r=d();return!r||/^body$/i.test(t)||/^head$/i.test(t)||/^html$/i.test(t)||!(null===(o=Ce.get(r))||void 0===o?void 0:o.inline)&&/^script$/i.test(t)?E.rawGetElementsByTagName.call(e,t):n(t)},Document.prototype.getElementsByName=function(t){return!d()||/^\d/.test(t)?E.rawGetElementsByName.call(e,t):n(`[name=${t}]`)}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if("[object Object]"===toString.call(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{"string"==typeof n&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&n("property data must be an object");else if(("src"===e&&/^(img|iframe|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ce.has(this.__MICRO_APP_NAME__)){const n=Ce.get(this.__MICRO_APP_NAME__);E.rawSetAttribute.call(this,e,a(t,n.url))}else E.rawSetAttribute.call(this,e,t)},Node.prototype.appendChild=function(e){return K(this,e,null,E.rawAppendChild)},Node.prototype.insertBefore=function(e,t){return K(this,e,t,E.rawInsertBefore)},Node.prototype.replaceChild=function(e,t){return K(this,e,t,E.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)K(this,e[t],null,E.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)K(this,e[t-1],null,E.rawPrepend),t--},Node.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ce.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?F(t,E.rawRemoveChild,this,q(e)):E.rawRemoveChild.call(this,e)}return E.rawRemoveChild.call(this,e)}}function Y(e){const t=d();return t&&(e.__MICRO_APP_NAME__=t),e}function V(){p(null),Document.prototype.createElement=E.rawCreateElement,Document.prototype.createElementNS=E.rawCreateElementNS,Document.prototype.createDocumentFragment=E.rawCreateDocumentFragment,Document.prototype.querySelector=E.rawQuerySelector,Document.prototype.querySelectorAll=E.rawQuerySelectorAll,Document.prototype.getElementById=E.rawGetElementById,Document.prototype.getElementsByClassName=E.rawGetElementsByClassName,Document.prototype.getElementsByTagName=E.rawGetElementsByTagName,Document.prototype.getElementsByName=E.rawGetElementsByName,Element.prototype.setAttribute=E.rawSetAttribute,Node.prototype.appendChild=E.rawAppendChild,Node.prototype.insertBefore=E.rawInsertBefore,Node.prototype.replaceChild=E.rawReplaceChild,Node.prototype.removeChild=E.rawRemoveChild,Element.prototype.append=E.rawAppend,Element.prototype.prepend=E.rawPrepend}let Q=!1;function X(e,n,o,r){var i;if(!e)return t(`element does not exist in lifecycle ${o},it seems the app has unmounted`);e instanceof ShadowRoot&&(e=e.host);const s=Object.assign({name:n,container:e},r&&{error:r}),a=new CustomEvent(o,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),"function"==typeof(null===(i=ae.lifeCycles)||void 0===i?void 0:i[o])&&ae.lifeCycles[o](a),e.dispatchEvent(a)}function J(){Z(),Ce.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),window.__MICRO_APP_UMD_MODE__||Ce.clear(),ee.size&&(ee.clear(),V())}function Z(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",J,!1)}const ee=new Map;function te(e){class n extends HTMLElement{constructor(){super(),this.appName="",this.appUrl="",this.version="0.4.0",this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.handleAttributeUpdate=()=>{var e;this.isWating=!1;const n=this.getAttribute("name"),o=i(this.getAttribute("url"));if(this.legalAttribute("name",n)&&this.legalAttribute("url",o)){const r=Ce.get(n);if(n!==this.appName&&r&&b.UNMOUNT!==r.getAppStatus()&&!r.isPrefetch)return this.setAttribute("name",this.appName),t(`an app named ${n} already exists`);n===this.appName&&o===this.appUrl||(this.handleUnmount(n===this.appName),this.appName=n,this.appUrl=o,(null!==(e=this.shadowRoot)&&void 0!==e?e:this).innerHTML="",r&&r.url===o?this.handleAppMount(r):this.handleCreate())}else n!==this.appName&&this.setAttribute("name",this.appName)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,ee.has(this)||this.performWhenFirstCreated(),o((()=>X(this,this.appName,g.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,ee.delete(this),this.handleUnmount(this.getDisposeResult("destory")),0===ee.size&&V()}attributeChangedCallback(e,n,r){if(this.legalAttribute(e,r)&&this[e===w.NAME?"appName":"appUrl"]!==r)if(e!==w.URL||this.appUrl)e!==w.NAME||this.appName?this.isWating||(this.isWating=!0,o(this.handleAttributeUpdate)):(this.cacheData&&(ae.setData(r,this.cacheData),this.cacheData=null),this.appName=r,this.handleInitialNameAndUrl());else{if(!(r=i(r)))return t("Invalid attribute url");this.appUrl=r,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===ee.set(this,!0).size&&(z(),function(){if(!Q){Q=!0;const e=y("style");e.setAttribute("type","text/css"),e.textContent=`\n${ae.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,E.rawDocument.head.appendChild(e)}}(),Z(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",J,!1))}initialMount(){if(!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Ce.get(this.appName);e?e.url!==this.appUrl||!e.isPrefetch&&e.getAppStatus()!==b.UNMOUNT?e.isPrefetch?t(`the url: ${this.appUrl} is different from prefetch url: ${e.url}`):t(`an app named ${this.appName} already exists`):this.handleAppMount(e):this.handleCreate()}legalAttribute(e,n){return!("string"!=typeof n||!n)||(t(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,o((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var e;const t=new Re({name:this.appName,url:this.appUrl,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()});Ce.set(this.appName,t)}handleUnmount(e){const t=Ce.get(this.appName);t&&b.UNMOUNT!==t.getAppStatus()&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||ae[e])&&"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:""}set data(e){this.appName?ae.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?ae.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}const ne=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(t("event-center: Invalid name"),!1)}on(e,n,o=!1){if(this.isLegalName(e)){if("function"!=typeof n)return t("event-center: Invalid callback function");let r=this.eventList.get(e);r?o&&Object.getOwnPropertyNames(r.data).length&&n(r.data):(r={data:{},callbacks:new Set},this.eventList.set(e,r)),r.callbacks.add(n)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&("function"==typeof t?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,n){if(this.isLegalName(e)){if("[object Object]"!==toString.call(n))return t("event-center: data must be object");let o=this.eventList.get(e);if(o){if(o.data!==n){o.data=n;for(const e of o.callbacks)e(n)}}else o={data:n,callbacks:new Set},this.eventList.set(e,o)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function oe(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class re{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ne.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&ne.off("global",e)}setGlobalData(e){ne.dispatch("global",e)}clearGlobalDataListener(){const e=this.appName,t=ne.eventList.get("global");if(t)for(const n of t.callbacks)(e&&e===n.__APP_NAME__||!e&&!n.__APP_NAME__)&&t.callbacks.delete(n)}}class ie extends re{addDataListener(e,t,n){ne.on(oe(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&ne.off(oe(e,!1),t)}getData(e,t=!1){return ne.getData(oe(e,t))}setData(e,t){ne.dispatch(oe(e,!0),t)}clearDataListener(e){ne.off(oe(e,!1))}}class se extends re{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ne.on(oe(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&ne.off(oe(this.appName,!0),e)}getData(){return ne.getData(oe(this.appName,!0))}dispatch(e){h(),ne.dispatch(oe(this.appName,!1),e);const t=Ce.get(this.appName);if((null==t?void 0:t.container)&&"[object Object]"===toString.call(e)){const n=new CustomEvent("datachange",{detail:{data:e}});let o=t.container;o instanceof ShadowRoot&&(o=o.host),o.dispatchEvent(n)}}clearDataListener(){ne.off(oe(this.appName,!0))}}var ae=new class extends ie{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Se}start(o){if(!e||!window.customElements)return t("micro-app is not supported in this environment");if(null==o?void 0:o.tagName){if(!/^micro-app(-\S+)?/.test(o.tagName))return t(`${o.tagName} is invalid tagName`);this.tagName=o.tagName}if(window.customElements.get(this.tagName))return n(`element ${this.tagName} is already defined`);var r;v(),o&&"[object Object]"===toString.call(o)&&(this.shadowDOM=o.shadowDOM,this.destory=o.destory,this.inline=o.inline,this.disableScopecss=o.disableScopecss,this.disableSandbox=o.disableSandbox,this.macro=o.macro,f(o.fetch)&&(this.fetch=o.fetch),"[object Object]"===toString.call(o.lifeCycles)&&(this.lifeCycles=o.lifeCycles),"[object Object]"===toString.call(o.plugins)&&(this.plugins=o.plugins),o.preFetchApps&&Se(o.preFetchApps),o.globalAssets&&(r=o.globalAssets,"[object Object]"===toString.call(r)&&l((()=>{if("[object Array]"===toString.call(r.js)){const e=r.js.filter((e=>"string"==typeof e&&e.includes(".js")&&!I.has(e))),n=[];e.forEach((e=>{n.push(ce(e))})),c(n,(t=>{const n=e[t.index];I.has(n)||I.set(n,t.data)}),(e=>{t(e)}))}if("[object Array]"===toString.call(r.css)){const e=r.css.filter((e=>"string"==typeof e&&e.includes(".css")&&!U.has(e))),n=[];e.forEach((e=>{n.push(ce(e))})),c(n,(t=>{const n=e[t.index];U.has(n)||U.set(n,t.data)}),(e=>{t(e)}))}})))),te(this.tagName)}};function ce(e,t=null,n={}){return f(ae.fetch)?ae.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function le(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{le(e,t,n)}));for(const r of o)r instanceof HTMLLinkElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),r):t.scopecss&&!r.hasAttribute("ignore")?x(r,e,t,n):r.hasAttribute("href")&&r.setAttribute("href",a(r.getAttribute("href"),t.url)):r instanceof HTMLStyleElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),r):t.scopecss&&!r.hasAttribute("ignore")&&n.appendChild(M(r,t.name)):r instanceof HTMLScriptElement?j(r,e,t):r instanceof HTMLMetaElement||r instanceof HTMLTitleElement?e.removeChild(r):/^(img|iframe)$/i.test(r.tagName)&&r.hasAttribute("src")&&r.setAttribute("src",a(r.getAttribute("src"),t.url))}function ue(e,n){const o=function(e){const t=y("div");return t.innerHTML=e,t}(e),r=o.querySelector("micro-app-head"),i=o.querySelector("micro-app-body");if(!r||!i){const e=`element ${r?"body":"head"} is missing`;return n.onerror(new Error(e)),t(e)}le(o,n,r),n.source.links.size?T(o,n,r):n.onLoad(o),n.source.scripts.size?$(o,n):n.onLoad(o)}const pe=new WeakMap;const de=new WeakMap;const he=new WeakMap;function me(e,t){if(he.has(t))return he.get(t);if(f(t)&&!function(e){if(de.has(e))return de.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 de.set(e,n),n}(t)&&!function(e){if(pe.has(e))return pe.get(e);const t=0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype");return pe.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),he.set(t,n),n}return t}const fe=new Map;let ye=!1;const _e=new Map;function we(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:o}=E;ye||function(){ye=!0;const e=Object.getOwnPropertyDescriptor(document,"onclick");if(!1===(null==e?void 0:e.configurable))return n("Cannot redefine document property onclick");const t=document.onclick;document.onclick=null;let o=!1;function r(e){fe.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=d();return e?fe.get(e):fe.get("base")},set(e){const t=d();t?fe.set(t,e):fe.set("base",e),o||"function"!=typeof e||(o=!0,E.rawDocumentAddEventListener.call(E.rawDocument,"click",r,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(n,o,r){const i=d();if(i){const e=_e.get(i);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else _e.set(i,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,n,r){const i=d();if(i){const e=_e.get(i);if(e){const o=e.get(t);(null==o?void 0:o.size)&&o.has(n)&&o.delete(n)}}o.call(e,t,n,r)}}function be(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const ge=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ee=["location"],ve={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ae;function Ne(e){Ae&&clearTimeout(Ae),Ae=setTimeout(e,0)}class Oe{constructor(e,t,n){this.active=!1,this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.microWindow={},this.injectedKeys=new Set,this.escapeKeys=new Set;const r=E.rawWindow,i=E.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:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:d,rawClearTimeout:h,rawDocumentRemoveEventListener:m}=E;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),c.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=l.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),d.call(i,e)},e.clearTimeout=function(e){r.delete(e),h.call(i,e)};const f=new Map,y=new Map;let _,w=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))})),o.size&&(w=new Map(o)),r.size&&(b=new Map(r)),_=fe.get(t);const e=_e.get(t);e&&e.forEach(((e,t)=>{e.size&&y.set(t,new Set(e))}))},rebuildUmdEffect:()=>{f.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)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&fe.set(t,_),p(t),y.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),p(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{d.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{h.call(i,t)})),r.clear()),fe.delete(t);const e=_e.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)m.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 r===r.parent?this.proxyWindow:Reflect.get(r,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s)switch(this.active&&(p(e),(n?Ne:o)((()=>p(null)))),s){case"document":return i;case"eval":return eval}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||"string"==typeof s&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const c=Reflect.get(r,s);return me(r,c)},set:(e,t,n)=>{if(this.active){if(Ee.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)||ge.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 ve||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.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,E.rawWindow._babelPolyfill&&(E.rawWindow._babelPolyfill=!1),1==++Oe.activeCount&&we())}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(E.rawWindow,e)})),this.escapeKeys.clear(),0==--Oe.activeCount&&(document.addEventListener=E.rawDocumentAddEventListener,document.removeEventListener=E.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=ne.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=ne.eventList.get(oe(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("object"==typeof ae.plugins){if("[object Array]"===toString.call(ae.plugins.global))for(const e of ae.plugins.global)"object"==typeof e&&("[object Array]"===toString.call(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),"[object Array]"===toString.call(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if("[object Array]"===toString.call(null===(t=ae.plugins.modules)||void 0===t?void 0:t[e]))for(const t of ae.plugins.modules[e])"object"==typeof t&&("[object Array]"===toString.call(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),"[object Array]"===toString.call(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__=s(n),e.microApp=new se(t),e.rawWindow=E.rawWindow,e.rawDocument=E.rawDocument,e.removeDomScope=h}}Oe.activeCount=0;const Ce=new Map;class Re{constructor({name:e,url:t,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseroute:a}){this.status=b.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=e,this.url=t,this.useSandbox=i,this.scopecss=this.useSandbox&&r,this.macro=null!=s&&s,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Oe(e,t,this.macro))}loadSourceCode(){var e;this.status=b.LOADING_SOURCE_CODE,ce((e=this).url,e.name,{cache:"no-cache"}).then((n=>{if(!n){const n="html is empty, please check in detail";return e.onerror(new Error(n)),t(n)}ue(n=n.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((n=>{t(`Failed to fetch data from ${e.url}, micro-app stop rendering`,n),e.onLoadError(n)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||b.UNMOUNT===this.status)return;this.status=b.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,b.UNMOUNT!==this.status&&(this.onerror(e),this.status=b.LOAD_SOURCE_ERROR)}mount(e,n,r){var i,s,a;"boolean"==typeof n&&n!==this.inline&&(this.inline=n),this.container=null!==(i=this.container)&&void 0!==i?i:e,this.baseroute=null!=r?r:this.baseroute,2===this.loadSourceLevel?(X(this.container,this.name,g.BEFOREMOUNT),this.status=b.MOUNTING,_(this.source.html,this.container),null===(s=this.sandBox)||void 0===s||s.start(this.baseroute),this.umdHookMount?(null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot(),this.umdHookMount()):function(e,n,o){const r=Array.from(e.entries()),i=[],s=[];for(const[e,t]of r)t.isDynamic||(t.defer||t.async?(t.isExternal&&!t.code?i.push(ce(e,n.name)):i.push(t.code),s.push([e,t])):k(e,t.code,n,t.module,!1));i.length?Promise.all(i).then((e=>{e.forEach(((e,t)=>{const[r,i]=s[t];k(r,i.code=i.code||e,n,i.module,!1,o)})),o()})).catch((e=>{t(e),o()})):o()}(this.source.scripts,this,(()=>{var e,t,n;if(null===this.umdHookMount){const{mount:o,unmount:r}=this.getUmdLibraryHooks();f(o)&&f(r)&&(this.umdHookMount=o,this.umdHookunMount=r,null===(e=this.sandBox)||void 0===e||e.recordUmdSnapshot(),_(this.container,this.source.html),t=this.source.html,n=this.name,l((()=>{var e;const o=Array.from(t.querySelectorAll("style"));for(const t of o)-1===(null===(e=t.textContent)||void 0===e?void 0:e.indexOf(`${ae.tagName}[name=${n}]`))&&M(t,n)})),this.umdHookMount())}})),b.UNMOUNT!==this.status&&(this.status=b.MOUNTED,o((()=>{b.UNMOUNT!==this.status&&X(this.container,this.name,g.MOUNTED)})))):this.status=b.LOADING_SOURCE_CODE}unmount(e){var t;this.status===b.LOAD_SOURCE_ERROR&&(e=!0),this.status=b.UNMOUNT,X(this.container,this.name,g.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(e){const t=new CustomEvent(`unmount-${e}`);window.dispatchEvent(t)}(this.name),null===(t=this.sandBox)||void 0===t||t.stop(),this.container=null,e&&Ce.delete(this.name)}onerror(e){X(this.container,this.name,g.ERROR,e)}getAppStatus(){return this.status}getUmdLibraryHooks(){var e,t;if(b.UNMOUNT!==this.status){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:E.rawWindow,o=(this.container instanceof ShadowRoot?this.container.host:this.container).getAttribute("library")||`micro-app-${this.name}`;return"object"==typeof n[o]?n[o]:{}}return{}}}function Se(n){if(!e)return t("preFetch is only supported in browser environment");l((()=>{"function"==typeof n&&(n=n()),function(e){const t=[];return"[object Array]"===toString.call(e)&&e.forEach((e=>{e.url=i(e.url),"[object Object]"===toString.call(e)&&e.name&&"string"==typeof e.name&&e.url&&!Ce.has(e.name)&&t.push(e)})),t}(n).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:ae.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:ae.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:ae.macro});r.isPrefetch=!0,Ce.set(e.name,r)}))}))}exports.default=ae,exports.preFetch=Se,exports.pureCreateElement=y,exports.removeDomScope=h,exports.setCurrentAppName=p,exports.version="0.4.0"; | ||
//# 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=new Function("return window")(),n=new Function("return document")(),o="0.3.3";function i(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function r(e,...t){"string"==typeof e?console.warn(`[micro-app] ${e}`,...t):console.warn("[micro-app]",e,...t)}function s(e,...t){Promise.resolve().then(e.bind(null,...t))}function a(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function c(e){if("string"!=typeof e||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(a(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${o}`:""}catch(e){return i(e),""}}function l(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 u(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)?e:new URL(e,l(a(t))).toString()}function p(e,t,n,o){let i=0;function r(){++i===e.length&&o&&o()}e.forEach(((e,o)=>{"[object Promise]"===toString.call(e)?e.then((e=>{t({data:e,index:o}),r()})).catch((e=>{n({error:e,index:o}),r()})):(t({data:e,index:o}),r())}))}const d=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let h=null;function m(e){h=e}function f(){return h}function y(){m(null)}function _(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function b(e){return"function"==typeof e}function g(e,t){const o=n.createElement(e,t);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function E(e,t){t.innerHTML="";const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var w,v,O,A;function N(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 i=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>i.test(o)?e.replace(i,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function R(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,i)=>{if(/^data:/.test(i))return e;if(/^(https?:)?\/\//.test(i)){if(!_())return e;{const t=i.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;i=i.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(i)&&o&&(t=function(e){const t=e.split("/");return t.pop(),a(t.join("/")+"/")}(o)),`url("${u(i,t)}")`}))}function M(e,t,n){const o=P(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function P(e,t){let n="";for(const o of e)switch(o.type){case A.STYLE_RULE:n+=N(o,t);break;case A.MEDIA_RULE:n+=M(o,t,"media");break;case A.SUPPORTS_RULE:n+=M(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function S(e,t,n,o,i,r){var s,a;let c=R(P(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),i,n,r);_()&&(c=c.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=c}!function(e){e.NAME="name",e.URL="url"}(w||(w={})),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"}(v||(v={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(O||(O={})),function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(A||(A={}));let C=n.body.querySelector("#micro-app-template-style");function D(e,t){const o=Je.get(t);if(null==o?void 0:o.scopecss){const i=`${Ae.tagName}[name=${t}]`;if(C||(C=g("style"),C.setAttribute("id","micro-app-template-style"),n.body.appendChild(C),C.sheet.disabled=!0),e.textContent)C.textContent=e.textContent,S(C,e,e.textContent,i,o.url,e.linkpath),C.textContent="";else{const t=new MutationObserver((function(){var n,r;t.disconnect(),!e.textContent&&(null===(r=null===(n=e.sheet)||void 0===n?void 0:n.cssRules)||void 0===r?void 0:r.length)||e.hasAttribute("data-styled")||S(e,e,e.textContent,i,o.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function L(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function U(e){const t=new CustomEvent("load");L(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function x(e){const t=new CustomEvent("error");L(t,e),"function"==typeof e.onerror?e.onerror(t):e.dispatchEvent(t)}const T=new Map;function j(e,t,n,o,i=!1){const r=e.getAttribute("rel");let s=e.getAttribute("href"),a=null;if("stylesheet"===r&&s){if(s=u(s,n.url),i)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};{a=document.createComment(`the link with href=${s} move to micro-app-head as style element`);const t=document.createComment(`placeholder for link with href=${s}`);o.appendChild(t),n.source.links.set(s,{code:"",placeholder:t,isGlobal:e.hasAttribute("global")})}}else s&&e.setAttribute("href",u(s,n.url));return i?{replaceComment:a}:a?t.replaceChild(a,e):void 0}function I(e,t,n){const o=Array.from(t.source.links.entries()),r=[];for(const[e]of o){const n=T.get(e);n?r.push(n):r.push(Ne(e,t.name))}p(r,(e=>{!function(e,t,n,o,i){t.isGlobal&&!T.has(e)&&T.set(e,n);const r=g("style");r.textContent=n,r.linkpath=e,o.replaceChild(D(r,i.name),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{i(e)}),(()=>{t.onLoad(e)}))}const $=new Map,k="noModule"in document.createElement("script");function W(e,t,n,o=!1){let i=null,r=e.getAttribute("src");if(e.hasAttribute("exclude"))i=document.createComment("script element with exclude attribute ignored by micro-app");else if(k&&e.noModule||!k&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){r=u(r,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:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t=Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:r};n.source.scripts.set(t,r),i=document.createComment("inline script extract by micro-app")}else i=document.createComment("script ignored by micro-app");return o?{replaceComment:i}:t.replaceChild(i,e)}function B(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=$.get(e);n?i.code=n:i.defer||i.async||(o.push(Ne(e,t.name)),r.push([e,i]))}o.length?p(o,(e=>{!function(e,t,n){t.isGlobal&&!$.has(e)&&$.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{i(e)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function G(e,t,n,o,i){var r;try{if(t=H(e,t,n),n.inline){const e=g("script");if(o&&e.setAttribute("type","module"),e.textContent=t,i)return e;null===(r=n.container)||void 0===r||r.querySelector("micro-app-body").appendChild(e)}else if(Function(t)(),i)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error("[micro-app from runScript]",e)}}function H(e,n,o){return"object"==typeof Ae.plugins&&(n=function(e,t,n,o){var i;if("[object Array]"===toString.call(o.global))for(const n of o.global)"object"==typeof n&&"function"==typeof n.loader&&(t=n.loader(t,e,n.options));if("[object Array]"===toString.call(null===(i=o.modules)||void 0===i?void 0:i[n]))for(const i of o.modules[n])"object"==typeof i&&"function"==typeof i.loader&&(t=i.loader(t,e,i.options));return t}(e,n,o.name,Ae.plugins)),o.sandBox?(t.__MICRO_APP_PROXY_WINDOW__=o.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}const F=Element.prototype.setAttribute,q=Node.prototype.appendChild,K=Node.prototype.insertBefore,z=Node.prototype.replaceChild,Y=Node.prototype.removeChild,V=Element.prototype.append,X=Element.prototype.prepend,J=Document.prototype.createElement,Z=Document.prototype.createElementNS,Q=Document.prototype.createDocumentFragment,ee=Document.prototype.querySelector,te=Document.prototype.querySelectorAll,ne=Document.prototype.getElementById,oe=Document.prototype.getElementsByClassName,ie=Document.prototype.getElementsByTagName,re=Document.prototype.getElementsByName,se=new WeakMap;function ae(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?D(t,n.name):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(!n.scopecss)return t;const{url:o,info:r}=j(t,e,n,null,!0);if(o&&r){const e=g("style");return e.linkpath=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,D(r,n.name),void s((()=>U(o)));if(T.has(e)){const i=T.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,D(r,n.name),void s((()=>U(o)))}Ne(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&T.set(e,i),r.textContent=i,D(r,n.name),U(o)})).catch((e=>{i(e),x(o)}))}(o,r,n,t,e),se.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:a}=W(t,e,n,!0);if(r&&a){if(a.code){const e=G(r,a.code,n,a.module,!0);return se.set(t,e),e}{const e=function(e,t,n,o){if(n.source.scripts.has(e)){const i=n.source.scripts.get(e);return s((()=>U(o))),G(e,i.code,n,t.module,!0)}if($.has(e)){const i=$.get(e);return t.code=i,n.source.scripts.set(e,t),s((()=>U(o))),G(e,i,n,t.module,!0)}let r;return r=n.inline?g("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),Ne(e,n.name).then((i=>{t.code=i,n.source.scripts.set(e,t),t.isGlobal&&$.set(e,i);try{i=H(e,i,n),n.inline?(t.module&&r.setAttribute("type","module"),r.textContent=i):Function(i)()}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}U(o)})).catch((e=>{i(e),x(o)})),r}(r,a,n,t);return se.set(t,e),e}}return se.set(t,o),o}return t}function ce(e,t,n,o,i){if(n===document.head){const r=e.container.querySelector("micro-app-head");return i&&!r.contains(i)?q.call(r,o):t!==Y||r.contains(o)?t===V||t===X?t.call(r,o):t.call(r,o,i):n.contains(o)?t.call(n,o):o}if(n===document.body){const r=e.container.querySelector("micro-app-body");return i&&!r.contains(i)?q.call(r,o):t!==Y||r.contains(o)?t===V||t===X?t.call(r,o):t.call(r,o,i):n.contains(o)?t.call(n,o):o}return t===V||t===X?t.call(n,o):t.call(n,o,i)}function le(e){var t;return null!==(t=se.get(e))&&void 0!==t?t:e}function ue(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Je.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?ce(i,o,e,ae(e,t,i),n&&le(n)):o===V||o===X?o.call(e,t):o.call(e,t,n)}if(o===V||o===X){const n=f();if(!(t instanceof Node)&&n){const i=Je.get(n);if(null==i?void 0:i.container){if(e===document.head)return o.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return o.call(i.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function pe(){!function(){function e(e){var t,o,i;const r=f();return r&&"head"!==e&&"body"!==e&&"html"!==e?null!==(i=null===(o=null===(t=Je.get(r))||void 0===t?void 0:t.container)||void 0===o?void 0:o.querySelector(e))&&void 0!==i?i:null:ee.call(n,e)}function t(e){var t,o,i;const r=f();return r&&"head"!==e&&"body"!==e&&"html"!==e?null!==(i=null===(o=null===(t=Je.get(r))||void 0===t?void 0:t.container)||void 0===o?void 0:o.querySelectorAll(e))&&void 0!==i?i:[]:te.call(n,e)}Document.prototype.createElement=function(e,t){return de(J.call(n,e,t))},Document.prototype.createElementNS=function(e,t,o){return de(Z.call(n,e,t,o))},Document.prototype.createDocumentFragment=function(){return de(Q.call(n))},Document.prototype.querySelector=e,Document.prototype.querySelectorAll=t,Document.prototype.getElementById=function(t){return!f()||/^\d/.test(t)?ne.call(n,t):e(`#${t}`)},Document.prototype.getElementsByClassName=function(e){return!f()||/^\d/.test(e)?oe.call(n,e):t(`.${e}`)},Document.prototype.getElementsByTagName=function(e){var o;const i=f();return!i||/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)||!(null===(o=Je.get(i))||void 0===o?void 0:o.inline)&&/^script$/i.test(e)?ie.call(n,e):t(e)},Document.prototype.getElementsByName=function(e){return!f()||/^\d/.test(e)?re.call(n,e):t(`[name=${e}]`)}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if("[object Object]"===toString.call(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{"string"==typeof n&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&r("property data must be an object");else if(("src"===e&&/^(img|iframe|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Je.has(this.__MICRO_APP_NAME__)){const n=Je.get(this.__MICRO_APP_NAME__);F.call(this,e,u(t,n.url))}else F.call(this,e,t)},Node.prototype.appendChild=function(e){return ue(this,e,null,q)},Node.prototype.insertBefore=function(e,t){return ue(this,e,t,K)},Node.prototype.replaceChild=function(e,t){return ue(this,e,t,z)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ue(this,e[t],null,V),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ue(this,e[t-1],null,X),t--},Node.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Je.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ce(t,Y,this,le(e)):Y.call(this,e)}return Y.call(this,e)}}function de(e){const t=f();return t&&(e.__MICRO_APP_NAME__=t),e}function he(){m(null),Document.prototype.createElement=J,Document.prototype.createElementNS=Z,Document.prototype.createDocumentFragment=Q,Document.prototype.querySelector=ee,Document.prototype.querySelectorAll=te,Document.prototype.getElementById=ne,Document.prototype.getElementsByClassName=oe,Document.prototype.getElementsByTagName=ie,Document.prototype.getElementsByName=re,Element.prototype.setAttribute=F,Node.prototype.appendChild=q,Node.prototype.insertBefore=K,Node.prototype.replaceChild=z,Node.prototype.removeChild=Y,Element.prototype.append=V,Element.prototype.prepend=X}let me=!1;function fe(e,t,n,o){var r;if(!e)return i(`element does not exist in lifecycle ${n},it seems the app has unmounted`);e instanceof ShadowRoot&&(e=e.host);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),"function"==typeof(null===(r=Ae.lifeCycles)||void 0===r?void 0:r[n])&&Ae.lifeCycles[n](a),e.dispatchEvent(a)}function ye(){Je.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),Je.clear()}const _e=new Map;class be extends HTMLElement{constructor(){super(),this.appName="",this.appUrl="",this.version=o,this.isWating=!1,this.cacheData=null,this.handleAttributeUpdate=()=>{var e;this.isWating=!1;const t=this.getAttribute("name"),n=c(this.getAttribute("url"));if(this.legalAttribute("name",t)&&this.legalAttribute("url",n)){const o=Je.get(t);if(t!==this.appName&&o&&v.UNMOUNT!==o.getAppStatus()&&!o.isPrefetch)return this.setAttribute("name",this.appName),i(`an app named ${t} already exists`);t===this.appName&&n===this.appUrl||(this.handleUnmount(t===this.appName),this.appName=t,this.appUrl=n,(null!==(e=this.shadowRoot)&&void 0!==e?e:this).innerHTML="",o&&o.url===n?this.handleAppMount(o):this.handleCreate())}else t!==this.appName&&this.setAttribute("name",this.appName)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){if(_e.has(this)||this.performWhenFirstCreated(),s((()=>fe(this,this.appName,O.CREATED))),!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Je.get(this.appName);e?e.url!==this.appUrl||!e.isPrefetch&&e.getAppStatus()!==v.UNMOUNT?e.isPrefetch?i(`the url: ${this.appUrl} is different from prefetch url: ${e.url}`):i(`an app named ${this.appName} already exists`):this.handleAppMount(e):this.handleCreate()}disconnectedCallback(){_e.delete(this),this.handleUnmount(this.getDisposeResult("destory")),0===_e.size&&(he(),window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ye,!1))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===w.NAME?"appName":"appUrl"]!==n)if(e!==w.URL||this.appUrl)e!==w.NAME||this.appName?this.isWating||(this.isWating=!0,s(this.handleAttributeUpdate)):(this.cacheData&&(Ae.setData(n,this.cacheData),this.cacheData=null),this.appName=n);else{if(!(n=c(n)))return i("Invalid attribute url");this.appUrl=n}}performWhenFirstCreated(){1===_e.set(this,!0).size&&(pe(),function(){if(!me){me=!0;const e=g("style");e.setAttribute("type","text/css"),e.textContent=`\n${Ae.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,n.head.appendChild(e)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ye,!1))}legalAttribute(e,t){return!("string"!=typeof t||!t)||(i(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,s((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var e;const t=new Ze({name:this.appName,url:this.appUrl,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()});Je.set(this.appName,t)}handleUnmount(e){const t=Je.get(this.appName);t&&v.UNMOUNT!==t.getAppStatus()&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||Ae[e])&&"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:""}set data(e){this.appName?Ae.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Ae.getData(this.appName,!0):this.cacheData?this.cacheData:null}}const ge=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(i("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if("function"!=typeof t)return i("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&&("function"==typeof t?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if("[object Object]"!==toString.call(t))return i("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 Ee(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class we{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ge.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&ge.off("global",e)}setGlobalData(e){ge.dispatch("global",e)}clearGlobalDataListener(){const e=this.appName,t=ge.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 ve extends we{addDataListener(e,t,n){ge.on(Ee(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&ge.off(Ee(e,!1),t)}getData(e,t=!1){return ge.getData(Ee(e,t))}setData(e,t){ge.dispatch(Ee(e,!0),t)}clearDataListener(e){ge.off(Ee(e,!1))}}class Oe extends we{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ge.on(Ee(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&ge.off(Ee(this.appName,!0),e)}getData(){return ge.getData(Ee(this.appName,!0))}dispatch(e){y(),ge.dispatch(Ee(this.appName,!1),e);const t=Je.get(this.appName);if((null==t?void 0:t.container)&&"[object Object]"===toString.call(e)){const n=new CustomEvent("datachange",{detail:{data:e}});let o=t.container;o instanceof ShadowRoot&&(o=o.host),o.dispatchEvent(n)}}clearDataListener(){ge.off(Ee(this.appName,!0))}}var Ae=new class extends ve{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Qe}start(e){if(!(null===window||void 0===window?void 0:window.customElements))return i("customElements is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return i(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}var t,n;e&&"[object Object]"===toString.call(e)&&(this.shadowDOM=e.shadowDOM,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.macro=e.macro,b(e.fetch)&&(this.fetch=e.fetch),"[object Object]"===toString.call(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),"[object Object]"===toString.call(e.plugins)&&(this.plugins=e.plugins),e.preFetchApps&&Qe(e.preFetchApps),e.globalAssets&&(t=e.globalAssets,"[object Object]"===toString.call(t)&&d((()=>{if("[object Array]"===toString.call(t.js)){const e=t.js.filter((e=>"string"==typeof e&&e.includes(".js")&&!$.has(e))),n=[];e.forEach((e=>{n.push(Ne(e))})),p(n,(t=>{const n=e[t.index];$.has(n)||$.set(n,t.data)}),(e=>{i(e)}))}if("[object Array]"===toString.call(t.css)){const e=t.css.filter((e=>"string"==typeof e&&e.includes(".css")&&!T.has(e))),n=[];e.forEach((e=>{n.push(Ne(e))})),p(n,(t=>{const n=e[t.index];T.has(n)||T.set(n,t.data)}),(e=>{i(e)}))}})))),n=this.tagName,window.customElements.get(n)?r(`element ${n} is already defined`):window.customElements.define(n,be)}};function Ne(e,t=null,n={}){return b(Ae.fetch)?Ae.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function Re(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{Re(e,t,n)}));for(const i of o)i instanceof HTMLLinkElement?i.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),i):t.scopecss?j(i,e,t,n):i.hasAttribute("href")&&i.setAttribute("href",u(i.getAttribute("href"),t.url)):i instanceof HTMLStyleElement?i.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),i):t.scopecss&&n.appendChild(D(i,t.name)):i instanceof HTMLScriptElement?W(i,e,t):i instanceof HTMLMetaElement||i instanceof HTMLTitleElement?e.removeChild(i):/^(img|iframe)$/i.test(i.tagName)&&i.hasAttribute("src")&&i.setAttribute("src",u(i.getAttribute("src"),t.url))}function Me(e,t){const n=function(e){const t=g("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)),i(e)}Re(n,t,o),t.source.links.size?I(n,t,o):t.onLoad(n),t.source.scripts.size?B(n,t):t.onLoad(n)}const Pe=new WeakMap;const Se=new WeakMap;const Ce=new WeakMap;function De(e,t){if(Ce.has(t))return Ce.get(t);if(b(t)&&!function(e){if(Se.has(e))return Se.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 Se.set(e,n),n}(t)&&!function(e){if(Pe.has(e))return Pe.get(e);const t=0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype");return Pe.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),Ce.set(t,n),n}return t}const Le=window.addEventListener,Ue=window.removeEventListener,xe=window.setInterval,Te=window.setTimeout,je=window.clearInterval,Ie=window.clearTimeout,$e=document.addEventListener,ke=document.removeEventListener,We=new Map;let Be=!1;const Ge=new Map;function He(){Be||function(){Be=!0;const e=Object.getOwnPropertyDescriptor(document,"onclick");if(!1===(null==e?void 0:e.configurable))return r("Cannot redefine document property onclick");const t=document.onclick;document.onclick=null;let n=!1;function o(e){We.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=f();return e?We.get(e):We.get("base")},set(e){const t=f();t?We.set(t,e):We.set("base",e),n||"function"!=typeof e||(n=!0,$e.call(document,"click",o,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(e,t,n){const o=f();if(o){const i=Ge.get(o);if(i){const n=i.get(e);n?n.add(t):i.set(e,new Set([t]))}else Ge.set(o,new Map([[e,new Set([t])]]));t&&(t.__MICRO_MARK_OPTIONS__=n)}$e.call(document,e,t,n)},document.removeEventListener=function(e,t,n){const o=f();if(o){const n=Ge.get(o);if(n){const o=n.get(e);(null==o?void 0:o.size)&&o.has(t)&&o.delete(t)}}ke.call(document,e,t,n)}}function Fe(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const qe=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ke=["location"],ze={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ye;function Ve(e){Ye&&clearTimeout(Ye),Ye=setTimeout(e,0)}class Xe{constructor(e,o,i){this.active=!1,this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.microWindow={},this.injectedKeys=new Set,this.escapeKeys=new Set;const r=new Map,a=e=>this.microWindow.hasOwnProperty(e)||t.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,o),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,o=new Map,i=new Map;e.addEventListener=function(t,o,i){t=Fe(t,e);const r=n.get(t);r?r.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=i),Le.call(window,t,o,i)},e.removeEventListener=function(t,o,i){t=Fe(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(o)&&r.delete(o),Ue.call(window,t,o,i)},e.setInterval=function(e,t,...n){const i=xe(e,t,...n);return o.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const o=Te(e,t,...n);return i.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),je(e)},e.clearTimeout=function(e){i.delete(e),Ie(e)};const r=new Map,s=new Map;let a,c=new Map,l=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&r.set(t,new Set(e))})),o.size&&(c=new Map(o)),i.size&&(l=new Map(i)),a=We.get(t);const e=Ge.get(t);e&&e.forEach(((e,t)=>{e.size&&s.set(t,new Set(e))}))},rebuildUmdEffect:()=>{r.forEach(((t,n)=>{for(const o of t)e.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),c.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),l.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),a&&We.set(t,a),m(t),s.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),m(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)Ue.call(window,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{je(t)})),o.clear()),i.size&&(i.forEach(((e,t)=>{Ie(t)})),i.clear()),We.delete(t);const e=Ge.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)ke.call(document,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(o,r)=>{if(r===Symbol.unscopables)return ze;if(["window","self","globalThis"].includes(r))return this.proxyWindow;if("top"===r||"parent"===r)return t===t.parent?this.proxyWindow:Reflect.get(t,r);if("hasOwnProperty"===r)return a;if("document"===r||"eval"===r)switch(this.active&&(m(e),(i?Ve:s)((()=>m(null)))),r){case"document":return n;case"eval":return eval}if(this.scopeProperties.includes(r))return Reflect.get(o,r);if(Reflect.has(o,r))return Reflect.get(o,r);const c=Reflect.get(t,r);return De(t,c)},set:(e,n,o)=>{if(this.active){if(Ke.includes(n))Reflect.set(t,n,o);else if(e.hasOwnProperty(n)||!t.hasOwnProperty(n)||this.scopeProperties.includes(n))Reflect.set(e,n,o),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{writable:r,configurable:s,enumerable:a}=i;r&&(Object.defineProperty(e,n,{configurable:s,enumerable:a,writable:r,value:o}),this.injectedKeys.add(n))}(this.escapeProperties.includes(n)||qe.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,o),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in ze||n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(e.hasOwnProperty(n))return r.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(t.hasOwnProperty(n)){r.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,o)=>"rawWindow"===r.get(n)?Reflect.defineProperty(t,n,o):Reflect.defineProperty(e,n,o),ownKeys:e=>Reflect.ownKeys(t).concat(Reflect.ownKeys(e)).filter((function(e){return!(e in this)&&(this[e]=!0)}),Object.create(null)),deleteProperty:(e,n)=>!e.hasOwnProperty(n)||(this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}start(e){this.active||(this.active=!0,this.microWindow.__MICRO_APP_BASE_ROUTE__=this.microWindow.__MICRO_APP_BASE_URL__=e,t._babelPolyfill&&(t._babelPolyfill=!1),1==++Xe.activeCount&&He())}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,e)})),this.escapeKeys.clear(),0==--Xe.activeCount&&(document.addEventListener=$e,document.removeEventListener=ke))}recordUmdSnapshot(){this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=ge.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=ge.eventList.get(Ee(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("object"==typeof Ae.plugins){if("[object Array]"===toString.call(Ae.plugins.global))for(const e of Ae.plugins.global)"object"==typeof e&&("[object Array]"===toString.call(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),"[object Array]"===toString.call(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if("[object Array]"===toString.call(null===(t=Ae.plugins.modules)||void 0===t?void 0:t[e]))for(const t of Ae.plugins.modules[e])"object"==typeof t&&("[object Array]"===toString.call(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),"[object Array]"===toString.call(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}}inject(e,o,i){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=o,e.__MICRO_APP_PUBLIC_PATH__=l(i),e.microApp=new Oe(o),e.rawWindow=t,e.rawDocument=n,e.removeDomScope=y}}Xe.activeCount=0;const Je=new Map;class Ze{constructor({name:e,url:t,container:n,inline:o,scopecss:i,useSandbox:r,macro:s,baseroute:a}){this.status=v.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&i,this.macro=null!=s&&s,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Xe(e,t,this.macro))}loadSourceCode(){var e;this.status=v.LOADING_SOURCE_CODE,Ne((e=this).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)),i(t)}Me(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=>{i(`Failed to fetch data from ${e.url}, micro-app stop rendering`,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||v.UNMOUNT===this.status)return;this.status=v.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,v.UNMOUNT!==this.status&&(this.onerror(e),this.status=v.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,a,c;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){if(fe(this.container,this.name,O.BEFOREMOUNT),this.status=v.MOUNTING,E(this.source.html,this.container),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdHookMount)null===(c=this.sandBox)||void 0===c||c.rebuildUmdSnapshot(),this.umdHookMount();else{!function(e,t){const n=Array.from(e.entries()),o=[],r=[];for(const[e,i]of n)i.isDynamic||(i.defer||i.async?(i.isExternal&&!i.code?o.push(Ne(e,t.name)):o.push(i.code),r.push([e,i])):G(e,i.code,t,i.module,!1));o.length&&Promise.all(o).then((e=>{e.forEach(((e,n)=>{const[o,i]=r[n];G(o,i.code=i.code||e,t,i.module,!1)}))})).catch((e=>{i(e)}))}(this.source.scripts,this);const{mount:e,unmount:t}=this.getUmdLibraryHooks();b(e)&&b(t)&&(this.umdHookMount=e,this.umdHookunMount=t,null===(a=this.sandBox)||void 0===a||a.recordUmdSnapshot(),E(this.container,this.source.html),l=this.source.html,u=this.name,d((()=>{var e;const t=Array.from(l.querySelectorAll("style"));for(const n of t)-1===(null===(e=n.textContent)||void 0===e?void 0:e.indexOf(`${Ae.tagName}[name=${u}]`))&&D(n,u)})),this.umdHookMount())}var l,u;v.UNMOUNT!==this.status&&(this.status=v.MOUNTED,s((()=>{v.UNMOUNT!==this.status&&fe(this.container,this.name,O.MOUNTED)})))}else this.status=v.LOADING_SOURCE_CODE}unmount(e){var t;this.status===v.LOAD_SOURCE_ERROR&&(e=!0),this.status=v.UNMOUNT,fe(this.container,this.name,O.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(e){const t=new CustomEvent(`unmount-${e}`);window.dispatchEvent(t)}(this.name),null===(t=this.sandBox)||void 0===t||t.stop(),this.container=null,e&&Je.delete(this.name)}onerror(e){fe(this.container,this.name,O.ERROR,e)}getAppStatus(){return this.status}getUmdLibraryHooks(){var e,n;if(v.UNMOUNT!==this.status){const o=null!==(n=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==n?n:t,i=(this.container instanceof ShadowRoot?this.container.host:this.container).getAttribute("library")||`micro-app-${this.name}`;return"object"==typeof o[i]?o[i]:{}}return{}}}function Qe(e){d((()=>{"function"==typeof e&&(e=e()),function(e){const t=[];return"[object Array]"===toString.call(e)&&e.forEach((e=>{e.url=c(e.url),"[object Object]"===toString.call(e)&&e.name&&"string"==typeof e.name&&e.url&&!Je.has(e.name)&&t.push(e)})),t}(e).forEach((e=>{var t,n,o;const i=new Ze({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:Ae.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:Ae.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:Ae.macro});i.isPrefetch=!0,Je.set(e.name,i)}))}))}e.default=Ae,e.preFetch=Qe,e.pureCreateElement=g,e.removeDomScope=y,e.version=o,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.4.0",n="undefined"!=typeof window;function o(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function r(e,...t){"string"==typeof e?console.warn(`[micro-app] ${e}`,...t):console.warn("[micro-app]",e,...t)}function i(e,...t){Promise.resolve().then(e.bind(null,...t))}function s(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function a(e){if("string"!=typeof e||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(s(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return o(e),""}}function c(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 l(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,c(s(t))).toString()}function u(e,t,n,o){let r=0;function i(){++r===e.length&&o&&o()}e.forEach(((e,o)=>{"[object Promise]"===toString.call(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 p=function(){let e;if("undefined"!=typeof global)e=global;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("global object is unavailable in this environment")}return e}().requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let d=null;function h(e){d=e}function m(){return d}function f(){h(null)}function y(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function _(e){return"function"==typeof e}function w(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function b(e,t){t.innerHTML="";const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var g,E,v;!function(e){e.NAME="name",e.URL="url"}(g||(g={})),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"}(E||(E={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(v||(v={}));const A={};function N(){if(n){const e=Element.prototype.setAttribute,t=Node.prototype.appendChild,n=Node.prototype.insertBefore,o=Node.prototype.replaceChild,r=Node.prototype.removeChild,i=Element.prototype.append,s=Element.prototype.prepend,a=Document.prototype.createElement,c=Document.prototype.createElementNS,l=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,h=Document.prototype.getElementsByClassName,m=Document.prototype.getElementsByTagName,f=Document.prototype.getElementsByName,y=Function("return window")(),_=Function("return document")(),w="noModule"in document.createElement("script"),b=_.body.querySelector("#micro-app-template-style"),g=y.addEventListener,E=y.removeEventListener,v=y.setInterval,N=y.setTimeout,O=y.clearInterval,C=y.clearTimeout,R=_.addEventListener,S=_.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(A,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:o,rawRemoveChild:r,rawAppend:i,rawPrepend:s,rawCreateElement:a,rawCreateElementNS:c,rawCreateDocumentFragment:l,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:h,rawGetElementsByTagName:m,rawGetElementsByName:f,rawWindow:y,rawDocument:_,supportModuleScript:w,templateStyle:b,rawWindowAddEventListener:g,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:O,rawClearTimeout:C,rawDocumentAddEventListener:R,rawDocumentRemoveEventListener:S})}}var O;function C(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 R(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,r)=>{if(/^(data|blob):/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!y())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(),s(t.join("/")+"/")}(o)),`url("${l(r,t)}")`}))}function S(e,t,n){const o=M(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function M(e,t){let n="";for(const o of e)switch(o.type){case O.STYLE_RULE:n+=C(o,t);break;case O.MEDIA_RULE:n+=S(o,t,"media");break;case O.SUPPORTS_RULE:n+=S(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function P(e,t,n,o,r,i){var s,a;let c=R(M(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),r,n,i);y()&&(c=c.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=c}function D(e,t){const n=Se.get(t);if(null==n?void 0:n.scopecss){const o=`${le.tagName}[name=${t}]`;let r=A.templateStyle;if(r||(A.templateStyle=r=w("style"),r.setAttribute("id","micro-app-template-style"),A.rawDocument.body.appendChild(r),r.sheet.disabled=!0),e.textContent)r.textContent=e.textContent,P(r,e,e.textContent,o,n.url,e.linkpath),r.textContent="";else{const t=new MutationObserver((function(){var r,i;t.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")||P(e,e,e.textContent,o,n.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function L(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function U(e){const t=new CustomEvent("load");L(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function x(e){const t=new CustomEvent("error");L(t,e),"function"==typeof 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"}(O||(O={}));const T=new Map;function I(e,t,n,o,r=!1){const i=e.getAttribute("rel");let s=e.getAttribute("href"),a=null;if("stylesheet"===i&&s){if(s=l(s,n.url),r)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};{a=document.createComment(`the link with href=${s} move to micro-app-head as style element`);const t=document.createComment(`placeholder for link with href=${s}`);o.appendChild(t),n.source.links.set(s,{code:"",placeholder:t,isGlobal:e.hasAttribute("global")})}}else s&&e.setAttribute("href",l(s,n.url));return r?{replaceComment:a}:a?t.replaceChild(a,e):void 0}function j(e,t,n){const r=Array.from(t.source.links.entries()),i=[];for(const[e]of r){const n=T.get(e);n?i.push(n):i.push(ue(e,t.name))}u(i,(e=>{!function(e,t,n,o,r){t.isGlobal&&!T.has(e)&&T.set(e,n);const i=w("style");i.textContent=n,i.linkpath=e,o.replaceChild(D(i,r.name),t.placeholder),t.placeholder=null,t.code=n}(r[e.index][0],r[e.index][1],e.data,n,t)}),(e=>{o(e)}),(()=>{t.onLoad(e)}))}const $=new Map;function k(e,t,n,o=!1){let r=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))r=document.createComment("script element with exclude attribute ignored 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(A.supportModuleScript&&e.noModule||!A.supportModuleScript&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=l(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=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 r=document.createComment("script ignored by micro-app")}return o?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function W(e,t){const n=Array.from(t.source.scripts.entries()),r=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=$.get(e);n?o.code=n:o.defer||o.async||(r.push(ue(e,t.name)),i.push([e,o]))}r.length?u(r,(e=>{!function(e,t,n){t.isGlobal&&!$.has(e)&&$.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{o(e)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function B(e,t,n,o,r,i){var s;try{if(t=H(e,t,n),n.inline){const a=w("script");if(G(e,t,o,a,i),r)return a;null===(s=n.container)||void 0===s||s.querySelector("micro-app-body").appendChild(a)}else if(Function(t)(),r)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error("[micro-app from runScript]",e)}}function G(e,t,n,o,r){if(n){const n=new Blob([t],{type:"text/javascript;charset=utf-8"});o.src=URL.createObjectURL(n),o.setAttribute("type","module"),o.setAttribute("originSrc",e),r&&(o.onload=r)}else o.textContent=t}function H(e,t,n){return"object"==typeof le.plugins&&(t=function(e,t,n,o){var r;if("[object Array]"===toString.call(o.global))for(const n of o.global)"object"==typeof n&&"function"==typeof n.loader&&(t=n.loader(t,e,n.options));if("[object Array]"===toString.call(null===(r=o.modules)||void 0===r?void 0:r[n]))for(const r of o.modules[n])"object"==typeof r&&"function"==typeof r.loader&&(t=r.loader(t,e,r.options));return t}(e,t,n.name,le.plugins)),n.sandBox?(A.rawWindow.__MICRO_APP_PROXY_WINDOW__=n.sandBox.proxyWindow,`;(function(window, self){with(window){;${t}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):t}const F=new WeakMap;function q(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 F.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?D(t,n.name):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return F.set(t,e),e}if(!n.scopecss||t.hasAttribute("ignore"))return t;const{url:r,info:s}=I(t,e,n,null,!0);if(r&&s){const e=w("style");return e.linkpath=r,function(e,t,n,r,s){if(n.source.links.has(e))return s.textContent=n.source.links.get(e).code,D(s,n.name),void i((()=>U(r)));if(T.has(e)){const o=T.get(e);return t.code=o,n.source.links.set(e,t),s.textContent=o,D(s,n.name),void i((()=>U(r)))}ue(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&T.set(e,o),s.textContent=o,D(s,n.name),U(r)})).catch((e=>{o(e),x(r)}))}(r,s,n,t,e),F.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:r,url:s,info:a}=k(t,e,n,!0)||{};if(s&&a){if(a.code){const e=B(s,a.code,n,a.module,!0);return F.set(t,e),e}{const e=function(e,t,n,r){if(n.source.scripts.has(e)){const o=n.source.scripts.get(e);return i((()=>U(r))),B(e,o.code,n,t.module,!0)}if($.has(e)){const o=$.get(e);return t.code=o,n.source.scripts.set(e,t),i((()=>U(r))),B(e,o,n,t.module,!0)}let s;return s=n.inline?w("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),ue(e,n.name).then((o=>{t.code=o,n.source.scripts.set(e,t),t.isGlobal&&$.set(e,o);try{o=H(e,o,n),n.inline?G(e,o,t.module,s):Function(o)()}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}U(r)})).catch((e=>{o(e),x(r)})),s}(s,a,n,t);return F.set(t,e),e}}return r?(F.set(t,r),r):t}return t}function K(e,t,n,o,r){if(n===document.head){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?A.rawAppendChild.call(i,o):t!==A.rawRemoveChild||i.contains(o)?t===A.rawAppend||t===A.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)?A.rawAppendChild.call(i,o):t!==A.rawRemoveChild||i.contains(o)?t===A.rawAppend||t===A.rawPrepend?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===A.rawAppend||t===A.rawPrepend?t.call(n,o):t.call(n,o,r)}function z(e){var t;return null!==(t=F.get(e))&&void 0!==t?t:e}function Y(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Se.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?K(r,o,e,q(e,t,r),n&&z(n)):o===A.rawAppend||o===A.rawPrepend?o.call(e,t):o.call(e,t,n)}if(o===A.rawAppend||o===A.rawPrepend){const n=m();if(!(t instanceof Node)&&n){const r=Se.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 V(){!function(){const e=A.rawDocument;function t(t){var n,o,r;const i=m();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Se.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:A.rawQuerySelector.call(e,t)}function n(t){var n,o,r;const i=m();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Se.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:A.rawQuerySelectorAll.call(e,t)}Document.prototype.createElement=function(t,n){return Q(A.rawCreateElement.call(e,t,n))},Document.prototype.createElementNS=function(t,n,o){return Q(A.rawCreateElementNS.call(e,t,n,o))},Document.prototype.createDocumentFragment=function(){return Q(A.rawCreateDocumentFragment.call(e))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(n){return!m()||/^\d/.test(n)?A.rawGetElementById.call(e,n):t(`#${n}`)},Document.prototype.getElementsByClassName=function(t){return!m()||/^\d/.test(t)?A.rawGetElementsByClassName.call(e,t):n(`.${t}`)},Document.prototype.getElementsByTagName=function(t){var o;const r=m();return!r||/^body$/i.test(t)||/^head$/i.test(t)||/^html$/i.test(t)||!(null===(o=Se.get(r))||void 0===o?void 0:o.inline)&&/^script$/i.test(t)?A.rawGetElementsByTagName.call(e,t):n(t)},Document.prototype.getElementsByName=function(t){return!m()||/^\d/.test(t)?A.rawGetElementsByName.call(e,t):n(`[name=${t}]`)}}(),Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if("[object Object]"===toString.call(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{"string"==typeof n&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&r("property data must be an object");else if(("src"===e&&/^(img|iframe|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Se.has(this.__MICRO_APP_NAME__)){const n=Se.get(this.__MICRO_APP_NAME__);A.rawSetAttribute.call(this,e,l(t,n.url))}else A.rawSetAttribute.call(this,e,t)},Node.prototype.appendChild=function(e){return Y(this,e,null,A.rawAppendChild)},Node.prototype.insertBefore=function(e,t){return Y(this,e,t,A.rawInsertBefore)},Node.prototype.replaceChild=function(e,t){return Y(this,e,t,A.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)Y(this,e[t],null,A.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)Y(this,e[t-1],null,A.rawPrepend),t--},Node.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Se.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?K(t,A.rawRemoveChild,this,z(e)):A.rawRemoveChild.call(this,e)}return A.rawRemoveChild.call(this,e)}}function Q(e){const t=m();return t&&(e.__MICRO_APP_NAME__=t),e}function X(){h(null),Document.prototype.createElement=A.rawCreateElement,Document.prototype.createElementNS=A.rawCreateElementNS,Document.prototype.createDocumentFragment=A.rawCreateDocumentFragment,Document.prototype.querySelector=A.rawQuerySelector,Document.prototype.querySelectorAll=A.rawQuerySelectorAll,Document.prototype.getElementById=A.rawGetElementById,Document.prototype.getElementsByClassName=A.rawGetElementsByClassName,Document.prototype.getElementsByTagName=A.rawGetElementsByTagName,Document.prototype.getElementsByName=A.rawGetElementsByName,Element.prototype.setAttribute=A.rawSetAttribute,Node.prototype.appendChild=A.rawAppendChild,Node.prototype.insertBefore=A.rawInsertBefore,Node.prototype.replaceChild=A.rawReplaceChild,Node.prototype.removeChild=A.rawRemoveChild,Element.prototype.append=A.rawAppend,Element.prototype.prepend=A.rawPrepend}let J=!1;function Z(e,t,n,r){var i;if(!e)return o(`element does not exist in lifecycle ${n},it seems the app has unmounted`);e instanceof ShadowRoot&&(e=e.host);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),"function"==typeof(null===(i=le.lifeCycles)||void 0===i?void 0:i[n])&&le.lifeCycles[n](a),e.dispatchEvent(a)}function ee(){te(),Se.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),window.__MICRO_APP_UMD_MODE__||Se.clear(),ne.size&&(ne.clear(),X())}function te(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ee,!1)}const ne=new Map;function oe(e){class n extends HTMLElement{constructor(){super(),this.appName="",this.appUrl="",this.version=t,this.isWating=!1,this.cacheData=null,this.hasConnected=!1,this.handleAttributeUpdate=()=>{var e;this.isWating=!1;const t=this.getAttribute("name"),n=a(this.getAttribute("url"));if(this.legalAttribute("name",t)&&this.legalAttribute("url",n)){const r=Se.get(t);if(t!==this.appName&&r&&E.UNMOUNT!==r.getAppStatus()&&!r.isPrefetch)return this.setAttribute("name",this.appName),o(`an app named ${t} already exists`);t===this.appName&&n===this.appUrl||(this.handleUnmount(t===this.appName),this.appName=t,this.appUrl=n,(null!==(e=this.shadowRoot)&&void 0!==e?e:this).innerHTML="",r&&r.url===n?this.handleAppMount(r):this.handleCreate())}else t!==this.appName&&this.setAttribute("name",this.appName)},this.querySelector("micro-app-head")||this.performWhenFirstCreated()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,ne.has(this)||this.performWhenFirstCreated(),i((()=>Z(this,this.appName,v.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,ne.delete(this),this.handleUnmount(this.getDisposeResult("destory")),0===ne.size&&X()}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===g.NAME?"appName":"appUrl"]!==n)if(e!==g.URL||this.appUrl)e!==g.NAME||this.appName?this.isWating||(this.isWating=!0,i(this.handleAttributeUpdate)):(this.cacheData&&(le.setData(n,this.cacheData),this.cacheData=null),this.appName=n,this.handleInitialNameAndUrl());else{if(!(n=a(n)))return o("Invalid attribute url");this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}performWhenFirstCreated(){1===ne.set(this,!0).size&&(V(),function(){if(!J){J=!0;const e=w("style");e.setAttribute("type","text/css"),e.textContent=`\n${le.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,A.rawDocument.head.appendChild(e)}}(),te(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ee,!1))}initialMount(){if(!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Se.get(this.appName);e?e.url!==this.appUrl||!e.isPrefetch&&e.getAppStatus()!==E.UNMOUNT?e.isPrefetch?o(`the url: ${this.appUrl} is different from prefetch url: ${e.url}`):o(`an app named ${this.appName} already exists`):this.handleAppMount(e):this.handleCreate()}legalAttribute(e,t){return!("string"!=typeof t||!t)||(o(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,i((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var e;const t=new Me({name:this.appName,url:this.appUrl,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()});Se.set(this.appName,t)}handleUnmount(e){const t=Se.get(this.appName);t&&E.UNMOUNT!==t.getAppStatus()&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||le[e])&&"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:""}set data(e){this.appName?le.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?le.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}const re=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(o("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if("function"!=typeof t)return o("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&&("function"==typeof t?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if("[object Object]"!==toString.call(t))return o("event-center: data must be object");let n=this.eventList.get(e);if(n){if(n.data!==t){n.data=t;for(const e of n.callbacks)e(t)}}else n={data:t,callbacks:new Set},this.eventList.set(e,n)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function ie(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class se{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),re.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&re.off("global",e)}setGlobalData(e){re.dispatch("global",e)}clearGlobalDataListener(){const e=this.appName,t=re.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 ae extends se{addDataListener(e,t,n){re.on(ie(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&re.off(ie(e,!1),t)}getData(e,t=!1){return re.getData(ie(e,t))}setData(e,t){re.dispatch(ie(e,!0),t)}clearDataListener(e){re.off(ie(e,!1))}}class ce extends se{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=t,re.on(ie(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&re.off(ie(this.appName,!0),e)}getData(){return re.getData(ie(this.appName,!0))}dispatch(e){f(),re.dispatch(ie(this.appName,!1),e);const t=Se.get(this.appName);if((null==t?void 0:t.container)&&"[object Object]"===toString.call(e)){const n=new CustomEvent("datachange",{detail:{data:e}});let o=t.container;o instanceof ShadowRoot&&(o=o.host),o.dispatchEvent(n)}}clearDataListener(){re.off(ie(this.appName,!0))}}var le=new class extends ae{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Pe}start(e){if(!n||!window.customElements)return o("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return o(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return r(`element ${this.tagName} is already defined`);var t;N(),e&&"[object Object]"===toString.call(e)&&(this.shadowDOM=e.shadowDOM,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.macro=e.macro,_(e.fetch)&&(this.fetch=e.fetch),"[object Object]"===toString.call(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),"[object Object]"===toString.call(e.plugins)&&(this.plugins=e.plugins),e.preFetchApps&&Pe(e.preFetchApps),e.globalAssets&&(t=e.globalAssets,"[object Object]"===toString.call(t)&&p((()=>{if("[object Array]"===toString.call(t.js)){const e=t.js.filter((e=>"string"==typeof e&&e.includes(".js")&&!$.has(e))),n=[];e.forEach((e=>{n.push(ue(e))})),u(n,(t=>{const n=e[t.index];$.has(n)||$.set(n,t.data)}),(e=>{o(e)}))}if("[object Array]"===toString.call(t.css)){const e=t.css.filter((e=>"string"==typeof e&&e.includes(".css")&&!T.has(e))),n=[];e.forEach((e=>{n.push(ue(e))})),u(n,(t=>{const n=e[t.index];T.has(n)||T.set(n,t.data)}),(e=>{o(e)}))}})))),oe(this.tagName)}};function ue(e,t=null,n={}){return _(le.fetch)?le.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function pe(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{pe(e,t,n)}));for(const r of o)r instanceof HTMLLinkElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),r):t.scopecss&&!r.hasAttribute("ignore")?I(r,e,t,n):r.hasAttribute("href")&&r.setAttribute("href",l(r.getAttribute("href"),t.url)):r instanceof HTMLStyleElement?r.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),r):t.scopecss&&!r.hasAttribute("ignore")&&n.appendChild(D(r,t.name)):r instanceof HTMLScriptElement?k(r,e,t):r instanceof HTMLMetaElement||r instanceof HTMLTitleElement?e.removeChild(r):/^(img|iframe)$/i.test(r.tagName)&&r.hasAttribute("src")&&r.setAttribute("src",l(r.getAttribute("src"),t.url))}function de(e,t){const n=function(e){const t=w("div");return t.innerHTML=e,t}(e),r=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!r||!i){const e=`element ${r?"body":"head"} is missing`;return t.onerror(new Error(e)),o(e)}pe(n,t,r),t.source.links.size?j(n,t,r):t.onLoad(n),t.source.scripts.size?W(n,t):t.onLoad(n)}const he=new WeakMap;const me=new WeakMap;const fe=new WeakMap;function ye(e,t){if(fe.has(t))return fe.get(t);if(_(t)&&!function(e){if(me.has(e))return me.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 me.set(e,n),n}(t)&&!function(e){if(he.has(e))return he.get(e);const t=0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype");return he.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),fe.set(t,n),n}return t}const _e=new Map;let we=!1;const be=new Map;function ge(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=A;we||function(){we=!0;const e=Object.getOwnPropertyDescriptor(document,"onclick");if(!1===(null==e?void 0:e.configurable))return r("Cannot redefine document property onclick");const t=document.onclick;document.onclick=null;let n=!1;function o(e){_e.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=m();return e?_e.get(e):_e.get("base")},set(e){const t=m();t?_e.set(t,e):_e.set("base",e),n||"function"!=typeof e||(n=!0,A.rawDocumentAddEventListener.call(A.rawDocument,"click",o,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(n,o,r){const i=m();if(i){const e=be.get(i);if(e){const t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}else be.set(i,new Map([[n,new Set([o])]]));o&&(o.__MICRO_MARK_OPTIONS__=r)}t.call(e,n,o,r)},document.removeEventListener=function(t,o,r){const i=m();if(i){const e=be.get(i);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)}}function Ee(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const ve=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ae=["location"],Ne={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Oe;function Ce(e){Oe&&clearTimeout(Oe),Oe=setTimeout(e,0)}class Re{constructor(e,t,n){this.active=!1,this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.microWindow={},this.injectedKeys=new Set,this.escapeKeys=new Set;const o=A.rawWindow,r=A.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:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:p,rawClearTimeout:d,rawDocumentRemoveEventListener:m}=A;e.addEventListener=function(t,o,r){t=Ee(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=Ee(t,e);const s=n.get(t);(null==s?void 0:s.size)&&s.has(o)&&s.delete(o),c.call(i,t,o,r)},e.setInterval=function(e,t,...n){const r=l.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 f=new Map,y=new Map;let _,w=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))})),o.size&&(w=new Map(o)),r.size&&(b=new Map(r)),_=_e.get(t);const e=be.get(t);e&&e.forEach(((e,t)=>{e.size&&y.set(t,new Set(e))}))},rebuildUmdEffect:()=>{f.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)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&_e.set(t,_),h(t),y.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),h(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(i,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),r.size&&(r.forEach(((e,t)=>{d.call(i,t)})),r.clear()),_e.delete(t);const e=be.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)m.call(s,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(t,s)=>{if(s===Symbol.unscopables)return Ne;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)switch(this.active&&(h(e),(n?Ce:i)((()=>h(null)))),s){case"document":return r;case"eval":return eval}if(Reflect.has(t,s))return Reflect.get(t,s);if(this.scopeProperties.includes(s)||"string"==typeof s&&/^__MICRO_APP_/.test(s))return Reflect.get(t,s);const c=Reflect.get(o,s);return ye(o,c)},set:(e,t,n)=>{if(this.active){if(Ae.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)||ve.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 Ne||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.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,A.rawWindow._babelPolyfill&&(A.rawWindow._babelPolyfill=!1),1==++Re.activeCount&&ge())}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(A.rawWindow,e)})),this.escapeKeys.clear(),0==--Re.activeCount&&(document.addEventListener=A.rawDocumentAddEventListener,document.removeEventListener=A.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=re.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=re.eventList.get(ie(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("object"==typeof le.plugins){if("[object Array]"===toString.call(le.plugins.global))for(const e of le.plugins.global)"object"==typeof e&&("[object Array]"===toString.call(e.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(e.scopeProperties)),"[object Array]"===toString.call(e.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(e.escapeProperties)));if("[object Array]"===toString.call(null===(t=le.plugins.modules)||void 0===t?void 0:t[e]))for(const t of le.plugins.modules[e])"object"==typeof t&&("[object Array]"===toString.call(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),"[object Array]"===toString.call(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__=c(n),e.microApp=new ce(t),e.rawWindow=A.rawWindow,e.rawDocument=A.rawDocument,e.removeDomScope=f}}Re.activeCount=0;const Se=new Map;class Me{constructor({name:e,url:t,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseroute:a}){this.status=E.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=e,this.url=t,this.useSandbox=i,this.scopecss=this.useSandbox&&r,this.macro=null!=s&&s,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Re(e,t,this.macro))}loadSourceCode(){var e;this.status=E.LOADING_SOURCE_CODE,ue((e=this).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)),o(t)}de(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=>{o(`Failed to fetch data from ${e.url}, micro-app stop rendering`,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||E.UNMOUNT===this.status)return;this.status=E.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,E.UNMOUNT!==this.status&&(this.onerror(e),this.status=E.LOAD_SOURCE_ERROR)}mount(e,t,n){var r,s,a;"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?(Z(this.container,this.name,v.BEFOREMOUNT),this.status=E.MOUNTING,b(this.source.html,this.container),null===(s=this.sandBox)||void 0===s||s.start(this.baseroute),this.umdHookMount?(null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot(),this.umdHookMount()):function(e,t,n){const r=Array.from(e.entries()),i=[],s=[];for(const[e,n]of r)n.isDynamic||(n.defer||n.async?(n.isExternal&&!n.code?i.push(ue(e,t.name)):i.push(n.code),s.push([e,n])):B(e,n.code,t,n.module,!1));i.length?Promise.all(i).then((e=>{e.forEach(((e,o)=>{const[r,i]=s[o];B(r,i.code=i.code||e,t,i.module,!1,n)})),n()})).catch((e=>{o(e),n()})):n()}(this.source.scripts,this,(()=>{var e,t,n;if(null===this.umdHookMount){const{mount:o,unmount:r}=this.getUmdLibraryHooks();_(o)&&_(r)&&(this.umdHookMount=o,this.umdHookunMount=r,null===(e=this.sandBox)||void 0===e||e.recordUmdSnapshot(),b(this.container,this.source.html),t=this.source.html,n=this.name,p((()=>{var e;const o=Array.from(t.querySelectorAll("style"));for(const t of o)-1===(null===(e=t.textContent)||void 0===e?void 0:e.indexOf(`${le.tagName}[name=${n}]`))&&D(t,n)})),this.umdHookMount())}})),E.UNMOUNT!==this.status&&(this.status=E.MOUNTED,i((()=>{E.UNMOUNT!==this.status&&Z(this.container,this.name,v.MOUNTED)})))):this.status=E.LOADING_SOURCE_CODE}unmount(e){var t;this.status===E.LOAD_SOURCE_ERROR&&(e=!0),this.status=E.UNMOUNT,Z(this.container,this.name,v.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(e){const t=new CustomEvent(`unmount-${e}`);window.dispatchEvent(t)}(this.name),null===(t=this.sandBox)||void 0===t||t.stop(),this.container=null,e&&Se.delete(this.name)}onerror(e){Z(this.container,this.name,v.ERROR,e)}getAppStatus(){return this.status}getUmdLibraryHooks(){var e,t;if(E.UNMOUNT!==this.status){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:A.rawWindow,o=(this.container instanceof ShadowRoot?this.container.host:this.container).getAttribute("library")||`micro-app-${this.name}`;return"object"==typeof n[o]?n[o]:{}}return{}}}function Pe(e){if(!n)return o("preFetch is only supported in browser environment");p((()=>{"function"==typeof e&&(e=e()),function(e){const t=[];return"[object Array]"===toString.call(e)&&e.forEach((e=>{e.url=a(e.url),"[object Object]"===toString.call(e)&&e.name&&"string"==typeof e.name&&e.url&&!Se.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:le.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:le.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:le.macro});r.isPrefetch=!0,Se.set(e.name,r)}))}))}e.default=le,e.preFetch=Pe,e.pureCreateElement=w,e.removeDomScope=f,e.setCurrentAppName=h,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@micro-zoe/micro-app", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "A minimalist solution for building micro front-end applications", | ||
@@ -5,0 +5,0 @@ "private": false, |
<p align="center"> | ||
<a href="https://micro-zoe.github.io/micro-app/"> | ||
<img src="https://cangdu.org/micro-app/_media/logo.png" alt="logo" width="200"/> | ||
<img src="https://zeroing.jd.com/micro-app/media/logo.png" alt="logo" width="200"/> | ||
</a> | ||
@@ -132,4 +132,2 @@ </p> | ||
If you are using it, please [tell us](https://github.com/micro-zoe/micro-app/issues/35) | ||
### development | ||
@@ -136,0 +134,0 @@ 1、Clone |
<p align="center"> | ||
<a href="https://micro-zoe.github.io/micro-app/"> | ||
<img src="https://cangdu.org/micro-app/_media/logo.png" alt="logo" width="180"/> | ||
<img src="https://zeroing.jd.com/micro-app/media/logo.png" alt="logo" width="200"/> | ||
</a> | ||
@@ -65,3 +65,3 @@ </p> | ||
{ | ||
// 👇 非严格匹配,/my-page/xxx 都将匹配到 MyPage 组件 | ||
// 👇 非严格匹配,/my-page/xxx 都将匹配到 MyPage 页面 | ||
path: '/my-page/*', | ||
@@ -76,3 +76,3 @@ name: 'my-page', | ||
4、在`my-page`页面中使用组件 | ||
4、在`MyPage`页面中嵌入微前端应用 | ||
```html | ||
@@ -94,3 +94,3 @@ <!-- my-page.vue --> | ||
1、添加路由前缀(如果基座应用是history路由,子应用是hash路由,不需要设置路由前缀,这一步可以省略) | ||
1、设置基础路由(如果基座应用是history路由,子应用是hash路由,不需要设置基础路由,这一步可以省略) | ||
@@ -103,3 +103,3 @@ ```js | ||
return ( | ||
// 👇 添加路由前缀,子应用可以通过window.__MICRO_APP_BASE_ROUTE__获取基座应用下发的baseroute | ||
// 👇 设置基础路由,子应用可以通过window.__MICRO_APP_BASE_ROUTE__获取基座应用下发的baseroute | ||
<BrowserRouter basename={window.__MICRO_APP_BASE_ROUTE__ || '/'}> | ||
@@ -134,4 +134,2 @@ <Switch> | ||
如果您正在使用,请务必[告诉我们](https://github.com/micro-zoe/micro-app/issues/35) | ||
### 本地运行 | ||
@@ -138,0 +136,0 @@ 1、克隆项目 |
@@ -81,2 +81,3 @@ declare module '@micro-app/types' { | ||
cacheData: Record<PropertyKey, unknown> | null // Cache data | ||
hasConnected: boolean // element has run connectedCallback | ||
connectedCallback(): void // Hooks for element append to documents | ||
@@ -189,1 +190,3 @@ disconnectedCallback(): void // Hooks for element delete from documents | ||
} | ||
declare module '@micro-zoe/micro-app/polyfill/jsx-custom-event' |
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
749166
3673
203