@micro-zoe/micro-app
Advanced tools
Comparing version 0.2.5 to 0.3.0
@@ -144,2 +144,8 @@ /// <reference path="../typings/global.d.ts" /> | ||
export function pureCreateElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]; | ||
/** | ||
* clone origin elements to target | ||
* @param origin Cloned element | ||
* @param target Accept cloned elements | ||
*/ | ||
export function cloneNode<T extends Node, Q extends Node>(origin: T, target: Q): void; | ||
export {}; | ||
@@ -149,2 +155,3 @@ } | ||
declare module '@micro-zoe/micro-app/interact' { | ||
import { CallableFunctionForInteract } from '@micro-app/types'; | ||
class EventCenterForGlobal { | ||
@@ -156,3 +163,3 @@ /** | ||
*/ | ||
addGlobalDataListener(cb: CallableFunction, autoTrigger?: boolean): void; | ||
addGlobalDataListener(cb: CallableFunctionForInteract, autoTrigger?: boolean): void; | ||
/** | ||
@@ -162,3 +169,3 @@ * remove listener of global data | ||
*/ | ||
removeGlobalDataListener(cb: CallableFunction): void; | ||
removeGlobalDataListener(cb: CallableFunctionForInteract): void; | ||
/** | ||
@@ -171,2 +178,4 @@ * dispatch global data | ||
* clear all listener of global data | ||
* if appName exists, only the specified functions is cleared | ||
* if appName not exists, only clear the base app functions | ||
*/ | ||
@@ -209,2 +218,6 @@ clearGlobalDataListener(): void; | ||
appName: string; | ||
umdDataListeners?: { | ||
global: Set<CallableFunctionForInteract>; | ||
normal: Set<CallableFunctionForInteract>; | ||
}; | ||
constructor(appName: string); | ||
@@ -216,3 +229,3 @@ /** | ||
*/ | ||
addDataListener(cb: CallableFunction, autoTrigger?: boolean): void; | ||
addDataListener(cb: CallableFunctionForInteract, autoTrigger?: boolean): void; | ||
/** | ||
@@ -222,3 +235,3 @@ * remove listener | ||
*/ | ||
removeDataListener(cb: CallableFunction): void; | ||
removeDataListener(cb: CallableFunctionForInteract): void; | ||
/** | ||
@@ -238,4 +251,14 @@ * get data from base app | ||
} | ||
/** | ||
* Record UMD function before exec umdHookMount | ||
* @param microAppEventCneter | ||
*/ | ||
export function recordDataCenterSnapshot(microAppEventCneter: EventCenterForMicroApp): void; | ||
/** | ||
* Rebind the UMD function of the record before remount | ||
* @param microAppEventCneter instance of EventCenterForMicroApp | ||
*/ | ||
export function rebuildDataCenterSnapshot(microAppEventCneter: EventCenterForMicroApp): void; | ||
export {}; | ||
} | ||
@@ -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 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 a(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)?e:new URL(e,c(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 b(e,n){const o=t.createElement(e,n);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}var g,E,w,_;function v(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 N(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("${a(r,t)}")`}))}function A(e,t,n){const o=O(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function O(e,t){let n="";for(const o of e)switch(o.type){case _.STYLE_RULE:n+=v(o,t);break;case _.MEDIA_RULE:n+=A(o,t,"media");break;case _.SUPPORTS_RULE:n+=A(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function C(e,t,n,o,r,i){var s,c;let a=N(O(Array.from(null!==(c=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==c?c:[]),o),r,n,i);f()&&(a=a.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=a}!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"}(_||(_={}));let S=t.body.querySelector("#micro-app-template-style");function D(e,n){const o=Ke.get(n);if(null==o?void 0:o.scopecss){const r=`${we.tagName}[name=${n}]`;if(S||(S=b("style"),S.setAttribute("id","micro-app-template-style"),t.body.appendChild(S),S.sheet.disabled=!0),e.textContent)S.textContent=e.textContent,C(S,e,e.textContent,r,o.url,e.linkpath),S.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")||C(e,e,e.textContent,r,o.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function R(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function P(e){const t=new CustomEvent("load");R(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function M(e){const t=new CustomEvent("error");R(t,e),"function"==typeof e.onerror?e.onerror(t):e.dispatchEvent(t)}const L=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 U(e,t,o){const r=Array.from(t.source.links.entries()),i=[];for(const[e]of r){const n=L.get(e);n?i.push(n):i.push(_e(e,t.name))}l(i,(e=>{!function(e,t,n,o,r){t.isGlobal&&!L.has(e)&&L.set(e,n);const i=b("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,o,t)}),(e=>{n(e)}),(()=>{t.onLoad(e)}))}const T=new Map,j="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(j&&e.noModule||!j&&"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}:t.replaceChild(r,e)}function I(e,t){const o=Array.from(t.source.scripts.entries()),r=[],i=[];for(const[e,n]of o)if(n.isExternal){const o=T.get(e);o?n.code=o:n.defer||n.async||(r.push(_e(e,t.name)),i.push([e,n]))}r.length?l(r,(e=>{!function(e,t,n){t.isGlobal&&!T.has(e)&&T.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 k(e,t,n,o,r){var i;try{if(t=B(e,t,n),n.inline){const e=b("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((0,eval)(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 we.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,we.plugins)),o.sandBox?(e.proxyWindow=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.proxyWindow, window.proxyWindow, window.proxyWindow);`):n}const W=Element.prototype.setAttribute,H=Node.prototype.appendChild,q=Node.prototype.insertBefore,G=Node.prototype.replaceChild,F=Node.prototype.removeChild,K=Element.prototype.append,z=Element.prototype.prepend,V=Document.prototype.createElement,Y=Document.prototype.createElementNS,J=Document.prototype.createDocumentFragment,Z=Document.prototype.querySelector,Q=Document.prototype.querySelectorAll,X=Document.prototype.getElementById,ee=Document.prototype.getElementsByClassName,te=Document.prototype.getElementsByTagName,ne=Document.prototype.getElementsByName,oe=new WeakMap;function re(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 oe.set(t,e),e}return o.scopecss?D(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 oe.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=b("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,D(s,o.name),void r((()=>P(i)));if(L.has(e)){const n=L.get(e);return t.code=n,o.source.links.set(e,t),s.textContent=n,D(s,o.name),void r((()=>P(i)))}_e(e,o.name).then((n=>{t.code=n,o.source.links.set(e,t),t.isGlobal&&L.set(e,n),s.textContent=n,D(s,o.name),P(i)})).catch((e=>{n(e),M(i)}))}(i,s,o,t,e),oe.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:i,url:s,info:c}=$(t,e,o,!0);if(s&&c){if(c.code){const e=k(s,c.code,o,c.module,!0);return oe.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((()=>P(i))),k(e,n.code,o,t.module,!0)}if(T.has(e)){const n=T.get(e);return t.code=n,o.source.scripts.set(e,t),r((()=>P(i))),k(e,n,o,t.module,!0)}let s;return s=o.inline?b("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),_e(e,o.name).then((n=>{t.code=n,o.source.scripts.set(e,t),t.isGlobal&&T.set(e,n);try{n=B(e,n,o),o.inline?(t.module&&s.setAttribute("type","module"),s.textContent=n):(0,eval)(n)}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}P(i)})).catch((e=>{n(e),M(i)})),s}(s,c,o,t);return oe.set(t,e),e}}return oe.set(t,i),i}return t}function ie(e,t,n,o,r){if(n instanceof HTMLHeadElement){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?H.call(i,o):t!==F||i.contains(o)?t===K||t===z?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n instanceof HTMLBodyElement){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?H.call(i,o):t!==F||i.contains(o)?t===K||t===z?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===K||t===z?t.call(n,o):t.call(n,o,r)}function se(e){var t;return null!==(t=oe.get(e))&&void 0!==t?t:e}function ce(e,t,n,o){if(null==t?void 0:t.__MICRO_APP_NAME__){const r=Ke.get(t.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?ie(r,o,e,re(e,t,r),n&&se(n)):o===K||o===z?o.call(e,t):o.call(e,t,n)}if(o===K||o===z){const n=h();if(!(t instanceof Node)&&n){const r=Ke.get(n);if(null==r?void 0:r.container){if(e instanceof HTMLHeadElement)return o.call(r.container.querySelector("micro-app-head"),t);if(e instanceof HTMLBodyElement)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function ae(){!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=Ke.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=Ke.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 le(V.call(t,e,n))},Document.prototype.createElementNS=function(e,n,o){return le(Y.call(t,e,n,o))},Document.prototype.createDocumentFragment=function(){return le(J.call(t))},Document.prototype.querySelector=e,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(n){return!h()||/^\d/.test(n)?X.call(t,n):e(`#${n}`)},Document.prototype.getElementsByClassName=function(e){return!h()||/^\d/.test(e)?ee.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=Ke.get(r))||void 0===o?void 0:o.inline)&&/^script$/i.test(e)?te.call(t,e):n(e)},Document.prototype.getElementsByName=function(e){return!h()||/^\d/.test(e)?ne.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__&&Ke.has(this.__MICRO_APP_NAME__)){const n=Ke.get(this.__MICRO_APP_NAME__);W.call(this,e,a(t,n.url))}else W.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,q)},Node.prototype.replaceChild=function(e,t){return ce(this,e,t,G)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)ce(this,e[t],null,K),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)ce(this,e[t-1],null,z),t--},Node.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ke.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ie(t,F,this,se(e)):F.call(this,e)}return F.call(this,e)}}function le(e){const t=h();return t&&(e.__MICRO_APP_NAME__=t),e}function ue(){d(null),Document.prototype.createElement=V,Document.prototype.createElementNS=Y,Document.prototype.createDocumentFragment=J,Document.prototype.querySelector=Z,Document.prototype.querySelectorAll=Q,Document.prototype.getElementById=X,Document.prototype.getElementsByClassName=ee,Document.prototype.getElementsByTagName=te,Document.prototype.getElementsByName=ne,Element.prototype.setAttribute=W,Node.prototype.appendChild=H,Node.prototype.insertBefore=q,Node.prototype.replaceChild=G,Node.prototype.removeChild=F,Element.prototype.append=K,Element.prototype.prepend=z}let pe=!1;function de(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}),c=new CustomEvent(o,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(c,e),"function"==typeof(null===(i=we.lifeCycles)||void 0===i?void 0:i[o])&&we.lifeCycles[o](c),e.dispatchEvent(c)}function he(){Ke.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),Ke.clear()}class me extends HTMLElement{constructor(){super(...arguments),this.appName="",this.appUrl="",this.version="0.2.5",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=Ke.get(t);if(t!==this.appName&&r&&r.getAppStatus()!==E.UNMOUNT&&!r.isPrefetch)return this.setAttribute("name",this.appName),n(`an app named ${t} already exists`);t===this.appName&&o===this.appUrl||(this.handleUnmount(!0),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)}}static get observedAttributes(){return["name","url"]}connectedCallback(){if(1==++me.microAppCount&&(ae(),function(){if(!pe){pe=!0;const e=b("style");e.setAttribute("type","text/css"),e.textContent=`\n${we.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,t.head.appendChild(e)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",he,!1)),r((()=>de(this,this.appName,w.CREATED))),!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Ke.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(){me.microAppCount>0&&(this.handleUnmount(this.getDisposeResult("destory")),0==--me.microAppCount&&(ue(),window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",he,!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&&(we.setData(o,this.cacheData),this.cacheData=null),this.appName=o);else{if(!(o=s(o)))return n("Invalid attribute url");this.appUrl=o}}legalAttribute(e,t){return!("string"!=typeof t||!t)||(n(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,r((()=>{var t,n;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),null!==(n=this.getAttribute("baseurl"))&&void 0!==n?n:"")}))}handleCreate(){var e,t;const n=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"),baseurl:null!==(t=this.getAttribute("baseurl"))&&void 0!==t?t:""});Ke.set(this.appName,n)}handleUnmount(e){const t=Ke.get(this.appName);t&&t.getAppStatus()!==E.UNMOUNT&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||we[e])&&"false"!==this.getAttribute(e)}set data(e){this.appName?we.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?we.getData(this.appName,!0):this.cacheData?this.cacheData:null}}me.microAppCount=0;const fe=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 ye(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class be{addGlobalDataListener(e,t){fe.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&fe.off("global",e)}setGlobalData(e){fe.dispatch("global",e)}clearGlobalDataListener(){fe.off("global")}}class ge extends be{addDataListener(e,t,n){fe.on(ye(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&fe.off(ye(e,!1),t)}getData(e,t=!1){return fe.getData(ye(e,t))}setData(e,t){fe.dispatch(ye(e,!0),t)}clearDataListener(e){fe.off(ye(e,!1))}}class Ee extends be{constructor(e){super(),this.appName=e}addDataListener(e,t){fe.on(ye(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&fe.off(ye(this.appName,!0),e)}getData(){return fe.getData(ye(this.appName,!0))}dispatch(e){m(),fe.dispatch(ye(this.appName,!1),e);const t=Ke.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(){fe.off(ye(this.appName,!0))}}var we=new class extends ge{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ve}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;r=this.tagName,(window.customElements.get(r)?(o(`element ${r} is already defined`),0):(window.customElements.define(r,me),1))&&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&&Ve(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")&&!T.has(e))),o=[];e.forEach((e=>{o.push(_e(e))})),l(o,(t=>{const n=e[t.index];T.has(n)||T.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")&&!L.has(e))),o=[];e.forEach((e=>{o.push(_e(e))})),l(o,(t=>{const n=e[t.index];L.has(n)||L.set(n,t.data)}),(e=>{n(e)}))}}))))}};function _e(e,t=null,n={}){return y(we.fetch)?we.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function ve(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{ve(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",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&&n.appendChild(D(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",a(r.getAttribute("src"),t.url))}function Ne(e,t){const o=function(e){const t=b("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)}ve(o,t,r),t.source.links.size?U(o,t,r):t.onLoad(o),t.source.scripts.size?I(o,t):t.onLoad(o)}const Ae=new WeakMap;const Oe=new WeakMap;function Ce(e,t){if(Oe.has(t))return Oe.get(t);if(y(t)&&!function(e){if(Ae.has(e))return Ae.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 Ae.set(e,n),n}(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),Oe.set(t,n),n}return t}const Se=window.addEventListener,De=window.removeEventListener,Re=window.setInterval,Pe=window.setTimeout,Me=window.clearInterval,Le=window.clearTimeout,xe=document.addEventListener,Ue=document.removeEventListener,Te=new Map;let je=!1;const $e=new Map;function Ie(){je||function(){je=!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){Te.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=h();return e?Te.get(e):Te.get("base")},set(e){const t=h();t?Te.set(t,e):Te.set("base",e),o||"function"!=typeof e||(o=!0,xe.call(document,"click",r,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(e,t,n){const o=h();if(o){const n=$e.get(o);if(n){const o=n.get(e);o?o.add(t):n.set(e,new Set([t]))}else $e.set(o,new Map([[e,new Set([t])]]))}return xe.call(document,e,t,n)},document.removeEventListener=function(e,t,n){const o=h();if(o){const n=$e.get(o);if(n){const o=n.get(e);(null==o?void 0:o.size)&&o.has(t)&&o.delete(t)}}return Ue.call(document,e,t,n)}}function ke(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const Be=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],We=["location"],He={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let qe;function Ge(e){qe&&clearTimeout(qe),qe=setTimeout(e,0)}class Fe{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,c=t=>this.microWindow.hasOwnProperty(t)||e.hasOwnProperty(t);this.getScopeProperties(n),this.inject(this.microWindow,n,o),this.releaseEffect=function(e){const t=new Map,n=new Set,o=new Set;return e.addEventListener=function(n,o,r){n=ke(n,e);const i=t.get(n);return i?i.add(o):t.set(n,new Set([o])),Se.call(window,n,o,r)},e.removeEventListener=function(n,o,r){n=ke(n,e);const i=t.get(n);return(null==i?void 0:i.size)&&i.has(o)&&i.delete(o),De.call(window,n,o,r)},e.setInterval=function(e,t,...o){const r=Re(e,t,...o);return n.add(r),r},e.setTimeout=function(e,t,...n){const r=Pe(e,t,...n);return o.add(r),r},e.clearInterval=function(e){n.delete(e),Me(e)},e.clearTimeout=function(e){o.delete(e),Le(e)},()=>{t.size&&(t.forEach(((e,t)=>{if(e.size)for(const n of e)De.call(window,t,n)})),t.clear()),n.size&&(n.forEach((e=>{Me(e)})),n.clear()),o.size&&(o.forEach((e=>{Le(e)})),o.clear());const r=e.__MICRO_APP_NAME__;Te.delete(r);const i=$e.get(r);i&&(i.forEach(((e,t)=>{if(e.size)for(const n of e)Ue.call(document,t,n)})),i.clear())}}(this.microWindow),this.proxyWindow=new Proxy(this.microWindow,{get:(o,s)=>{if(s===Symbol.unscopables)return He;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 c;if("document"===s||"eval"===s)switch(this.active&&(d(n),(i?Ge: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 a=Reflect.get(e,s);return Ce(e,a)},set:(t,n,o)=>{if(this.active){if(We.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:c}=r;i&&(Object.defineProperty(t,n,{configurable:s,enumerable:c,writable:i,value:o}),this.injectedKeys.add(n))}(this.escapeProperties.includes(n)||Be.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 He||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_URL__=t,e._babelPolyfill&&(e._babelPolyfill=!1),1==++Fe.activeCount&&Ie())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((t=>{Reflect.deleteProperty(e,t)})),this.escapeKeys.clear(),0==--Fe.activeCount&&(document.addEventListener=xe,document.removeEventListener=Ue))}getScopeProperties(e){var t;if("object"==typeof we.plugins){if("[object Array]"===toString.call(we.plugins.global))for(const e of we.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=we.plugins.modules)||void 0===t?void 0:t[e]))for(const t of we.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__=c(r),n.microApp=new Ee(o),n.rawWindow=e,n.rawDocument=t}}Fe.activeCount=0;const Ke=new Map;class ze{constructor({name:e,url:t,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseurl:c}){this.status=E.NOT_LOADED,this.loadSourceLevel=0,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseurl="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseurl=null!=c?c:"",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 Fe(e,t,this.macro))}loadSourceCode(){var e;this.status=E.LOADING_SOURCE_CODE,_e((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||this.status===E.UNMOUNT)return;this.status=E.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,this.status!==E.UNMOUNT&&(this.onerror(e),this.status=E.LOAD_SOURCE_ERROR)}mount(e,t,o){var i;if(!this.container&&e&&(this.container=e),"boolean"==typeof t&&t!==this.inline&&(this.inline=t),this.baseurl=null!=o?o:this.baseurl,2!==this.loadSourceLevel)return void(this.status=E.LOADING_SOURCE_CODE);de(this.container,this.name,w.BEFOREMOUNT),this.status=E.MOUNTING;const s=this.source.html.cloneNode(!0),c=document.createDocumentFragment();Array.from(s.childNodes).forEach((e=>{c.appendChild(e)})),this.container.appendChild(c),null===(i=this.sandBox)||void 0===i||i.start(this.baseurl),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?r.push(_e(e,t.name)):r.push(n.code),i.push([e,n])):k(e,n.code,t,n.module,!1));r.length&&Promise.all(r).then((e=>{e.forEach(((e,n)=>{k(i[n][0],e,t,i[n][1].module,!1)}))})).catch((e=>{n(e)}))}(this.source.scripts,this),this.status!==E.UNMOUNT&&(this.status=E.MOUNTED,r((()=>{this.status!==E.UNMOUNT&&de(this.container,this.name,w.MOUNTED)})))}unmount(e){var t;this.status===E.LOAD_SOURCE_ERROR&&(e=!0),this.status=E.UNMOUNT,de(this.container,this.name,w.UNMOUNT),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&&Ke.delete(this.name)}onerror(e){de(this.container,this.name,w.ERROR,e)}getAppStatus(){return this.status}}function Ve(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&&!Ke.has(e.name)&&t.push(e)})),t}(e).forEach((e=>{var t,n,o;const r=new ze({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:we.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:we.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:we.macro});r.isPrefetch=!0,Ke.set(e.name,r)}))}))}exports.default=we,exports.preFetch=Ve,exports.pureCreateElement=b,exports.removeDomScope=m,exports.version="0.2.5"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new Function("return window")(),e=new Function("return document")();function n(t,...e){"string"==typeof t?console.error(`[micro-app] ${t}`,...e):console.error("[micro-app]",t,...e)}function o(t,...e){"string"==typeof t?console.warn(`[micro-app] ${t}`,...e):console.warn("[micro-app]",t,...e)}function r(t,...e){Promise.resolve().then(t.bind(null,...e))}function i(t){return t.startsWith("//")?`${location.protocol}${t}`:t}function s(t){if("string"!=typeof t||!t)return"";try{const{origin:e,pathname:n,search:o}=new URL(i(t));if(/\.(\w+)$/.test(n))return`${e}${n}${o}`;const r=`${e}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(t){return n(t),""}}function a(t){const{origin:e,pathname:n}=new URL(t);if(/\.(\w+)$/.test(n)){const t=`${e}${n}`.split("/");return t.pop(),t.join("/")+"/"}return`${e}${n}/`.replace(/\/\/$/,"/")}function c(t,e){return/^((((ht|f)tps?)|file):)?\/\//.test(t)?t:new URL(t,a(i(e))).toString()}function l(t,e,n,o){let r=0;function i(){++r===t.length&&o&&o()}t.forEach(((t,o)=>{"[object Promise]"===toString.call(t)?t.then((t=>{e({data:t,index:o}),i()})).catch((t=>{n({error:t,index:o}),i()})):(e({data:t,index:o}),i())}))}const u=window.requestIdleCallback||function(t){const e=Date.now();return setTimeout((function(){t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})}),1)};let p=null;function d(t){p=t}function h(){return p}function m(){d(null)}function f(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function y(t){return"function"==typeof t}function b(t,n){const o=e.createElement(t,n);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function _(t,e){const n=t.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((t=>{o.appendChild(t)})),e.appendChild(o)}var g,E,w,v;function O(t,e){const{selectorText:n,cssText:o}=t;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,e);if("*"===n)return o.replace("*",`${e} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(t=>t.replace(/(^|,)([^,]+)/g,((t,n,o)=>r.test(o)?t.replace(r,e):`${n} ${e} ${o.replace(/^\s*/,"")}`))))}function N(t,e,n,o){return t.replace(/url\(["']?([^)"']+)["']?\)/gm,((t,r)=>{if(/^data:/.test(r))return t;if(/^(https?:)?\/\//.test(r)){if(!f())return t;{const e=r.replace(/^https?:/,"");if(-1!==n.indexOf(e))return t;r=r.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(r)&&o&&(e=function(t){const e=t.split("/");return e.pop(),i(e.join("/")+"/")}(o)),`url("${c(r,e)}")`}))}function A(t,e,n){const o=S(Array.from(t.cssRules),e);return`@${n} ${t.conditionText} {${o}}`}function S(t,e){let n="";for(const o of t)switch(o.type){case v.STYLE_RULE:n+=O(o,e);break;case v.MEDIA_RULE:n+=A(o,e,"media");break;case v.SUPPORTS_RULE:n+=A(o,e,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function M(t,e,n,o,r,i){var s,a;let c=N(S(Array.from(null!==(a=null===(s=t.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,((t,e,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?t:`${e}"${n}"`))),e.textContent=c}!function(t){t.NAME="name",t.URL="url"}(g||(g={})),function(t){t.NOT_LOADED="NOT_LOADED",t.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",t.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",t.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",t.MOUNTING="MOUNTING",t.MOUNTED="MOUNTED",t.UNMOUNT="UNMOUNT"}(E||(E={})),function(t){t.CREATED="created",t.BEFOREMOUNT="beforemount",t.MOUNTED="mounted",t.UNMOUNT="unmount",t.ERROR="error"}(w||(w={})),function(t){t[t.STYLE_RULE=1]="STYLE_RULE",t[t.MEDIA_RULE=4]="MEDIA_RULE",t[t.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(v||(v={}));let R=e.body.querySelector("#micro-app-template-style");function C(t,n){const o=Yt.get(n);if(null==o?void 0:o.scopecss){const r=`${wt.tagName}[name=${n}]`;if(R||(R=b("style"),R.setAttribute("id","micro-app-template-style"),e.body.appendChild(R),R.sheet.disabled=!0),t.textContent)R.textContent=t.textContent,M(R,t,t.textContent,r,o.url,t.linkpath),R.textContent="";else{const e=new MutationObserver((function(){var n,i;e.disconnect(),!t.textContent&&(null===(i=null===(n=t.sheet)||void 0===n?void 0:n.cssRules)||void 0===i?void 0:i.length)||t.hasAttribute("data-styled")||M(t,t,t.textContent,r,o.url,t.linkpath)}));e.observe(t,{childList:!0})}}return t}function D(t,e){Object.defineProperties(t,{currentTarget:{get:()=>e},srcElement:{get:()=>e},target:{get:()=>e}})}function P(t){const e=new CustomEvent("load");D(e,t),"function"==typeof t.onload?t.onload(e):t.dispatchEvent(e)}function L(t){const e=new CustomEvent("error");D(e,t),"function"==typeof t.onerror?t.onerror(e):t.dispatchEvent(e)}const U=new Map;function x(t,e,n,o,r=!1){const i=t.getAttribute("rel");let s=t.getAttribute("href"),a=null;if("stylesheet"===i&&s){if(s=c(s,n.url),r)return{url:s,info:{code:"",isGlobal:t.hasAttribute("global")}};{a=document.createComment(`the link with href=${s} move to micro-app-head as style element`);const e=document.createComment(`placeholder for link with href=${s}`);o.appendChild(e),n.source.links.set(s,{code:"",placeholder:e,isGlobal:t.hasAttribute("global")})}}else s&&t.setAttribute("href",c(s,n.url));return r?{replaceComment:a}:a?e.replaceChild(a,t):void 0}function T(t,e,o){const r=Array.from(e.source.links.entries()),i=[];for(const[t]of r){const n=U.get(t);n?i.push(n):i.push(vt(t,e.name))}l(i,(t=>{!function(t,e,n,o,r){e.isGlobal&&!U.has(t)&&U.set(t,n);const i=b("style");i.textContent=n,i.linkpath=t,o.replaceChild(C(i,r.name),e.placeholder),e.placeholder=null,e.code=n}(r[t.index][0],r[t.index][1],t.data,o,e)}),(t=>{n(t)}),(()=>{e.onLoad(t)}))}const j=new Map,I="noModule"in document.createElement("script");function $(t,e,n,o=!1){let r=null,i=t.getAttribute("src");if(t.hasAttribute("exclude"))r=document.createComment("script element with exclude attribute ignored by micro-app");else if(I&&t.noModule||!I&&"module"===t.type)r=document.createComment((t.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=c(i,n.url);const e={code:"",isExternal:!0,isDynamic:o,async:t.hasAttribute("async"),defer:t.defer||"module"===t.type,module:"module"===t.type,isGlobal:t.hasAttribute("global")};if(o)return{url:i,info:e};n.source.scripts.set(i,e),r=document.createComment(`script with src='${i}' extract by micro-app`)}else if(t.textContent){const e=Math.random().toString(36).substr(2,15),i={code:t.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===t.type,module:"module"===t.type};if(o)return{url:e,info:i};n.source.scripts.set(e,i),r=document.createComment("inline script extract by micro-app")}else r=document.createComment("script ignored by micro-app");return o?{replaceComment:r}:e.replaceChild(r,t)}function k(t,e){const o=Array.from(e.source.scripts.entries()),r=[],i=[];for(const[t,n]of o)if(n.isExternal){const o=j.get(t);o?n.code=o:n.defer||n.async||(r.push(vt(t,e.name)),i.push([t,n]))}r.length?l(r,(t=>{!function(t,e,n){e.isGlobal&&!j.has(t)&&j.set(t,n);e.code=n}(i[t.index][0],i[t.index][1],t.data)}),(t=>{n(t)}),(()=>{e.onLoad(t)})):e.onLoad(t)}function W(t,e,n,o,r){var i;try{if(e=B(t,e,n),n.inline){const t=b("script");if(o&&t.setAttribute("type","module"),t.textContent=e,r)return t;null===(i=n.container)||void 0===i||i.querySelector("micro-app-body").appendChild(t)}else if(Function(e)(),r)return document.createComment("dynamic script extract by micro-app")}catch(t){console.error("[micro-app from runScript]",t)}}function B(e,n,o){return"object"==typeof wt.plugins&&(n=function(t,e,n,o){var r;if("[object Array]"===toString.call(o.global))for(const n of o.global)"object"==typeof n&&"function"==typeof n.loader&&(e=n.loader(e,t,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&&(e=r.loader(e,t,r.options));return e}(e,n,o.name,wt.plugins)),o.sandBox?(t.__PROXY_WINDOW__=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__PROXY_WINDOW__, window.__PROXY_WINDOW__, window.__PROXY_WINDOW__);`):n}const G=Element.prototype.setAttribute,H=Node.prototype.appendChild,q=Node.prototype.insertBefore,F=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,tt=Document.prototype.getElementById,et=Document.prototype.getElementsByClassName,nt=Document.prototype.getElementsByTagName,ot=Document.prototype.getElementsByName,rt=new WeakMap;function it(t,e,o){if(e instanceof HTMLStyleElement){if(e.hasAttribute("exclude")){const t=document.createComment("style element with exclude attribute ignored by micro-app");return rt.set(e,t),t}return o.scopecss?C(e,o.name):e}if(e instanceof HTMLLinkElement){if(e.hasAttribute("exclude")){const t=document.createComment("link element with exclude attribute ignored by micro-app");return rt.set(e,t),t}if(!o.scopecss)return e;const{url:i,info:s}=x(e,t,o,null,!0);if(i&&s){const t=b("style");return t.linkpath=i,function(t,e,o,i,s){if(o.source.links.has(t))return s.textContent=o.source.links.get(t).code,C(s,o.name),void r((()=>P(i)));if(U.has(t)){const n=U.get(t);return e.code=n,o.source.links.set(t,e),s.textContent=n,C(s,o.name),void r((()=>P(i)))}vt(t,o.name).then((n=>{e.code=n,o.source.links.set(t,e),e.isGlobal&&U.set(t,n),s.textContent=n,C(s,o.name),P(i)})).catch((t=>{n(t),L(i)}))}(i,s,o,e,t),rt.set(e,t),t}return e}if(e instanceof HTMLScriptElement){const{replaceComment:i,url:s,info:a}=$(e,t,o,!0);if(s&&a){if(a.code){const t=W(s,a.code,o,a.module,!0);return rt.set(e,t),t}{const t=function(t,e,o,i){if(o.source.scripts.has(t)){const n=o.source.scripts.get(t);return r((()=>P(i))),W(t,n.code,o,e.module,!0)}if(j.has(t)){const n=j.get(t);return e.code=n,o.source.scripts.set(t,e),r((()=>P(i))),W(t,n,o,e.module,!0)}let s;return s=o.inline?b("script"):document.createComment(`dynamic script with src='${t}' extract by micro-app`),vt(t,o.name).then((n=>{e.code=n,o.source.scripts.set(t,e),e.isGlobal&&j.set(t,n);try{n=B(t,n,o),o.inline?(e.module&&s.setAttribute("type","module"),s.textContent=n):Function(n)()}catch(e){console.error("[micro-app from runDynamicScript]",e,t)}P(i)})).catch((t=>{n(t),L(i)})),s}(s,a,o,e);return rt.set(e,t),t}}return rt.set(e,i),i}return e}function st(t,e,n,o,r){if(n===document.head){const i=t.container.querySelector("micro-app-head");return r&&!i.contains(r)?H.call(i,o):e!==K||i.contains(o)?e===z||e===Y?e.call(i,o):e.call(i,o,r):n.contains(o)?e.call(n,o):o}if(n===document.body){const i=t.container.querySelector("micro-app-body");return r&&!i.contains(r)?H.call(i,o):e!==K||i.contains(o)?e===z||e===Y?e.call(i,o):e.call(i,o,r):n.contains(o)?e.call(n,o):o}return e===z||e===Y?e.call(n,o):e.call(n,o,r)}function at(t){var e;return null!==(e=rt.get(t))&&void 0!==e?e:t}function ct(t,e,n,o){if(null==e?void 0:e.__MICRO_APP_NAME__){const r=Yt.get(e.__MICRO_APP_NAME__);return(null==r?void 0:r.container)?st(r,o,t,it(t,e,r),n&&at(n)):o===z||o===Y?o.call(t,e):o.call(t,e,n)}if(o===z||o===Y){const n=h();if(!(e instanceof Node)&&n){const r=Yt.get(n);if(null==r?void 0:r.container){if(t===document.head)return o.call(r.container.querySelector("micro-app-head"),e);if(t===document.body)return o.call(r.container.querySelector("micro-app-body"),e)}}return o.call(t,e)}return o.call(t,e,n)}function lt(){!function(){function t(t){var n,o,r;const i=h();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Yt.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==r?r:null:Z.call(e,t)}function n(t){var n,o,r;const i=h();return i&&"head"!==t&&"body"!==t&&"html"!==t?null!==(r=null===(o=null===(n=Yt.get(i))||void 0===n?void 0:n.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==r?r:[]:Q.call(e,t)}Document.prototype.createElement=function(t,n){return ut(V.call(e,t,n))},Document.prototype.createElementNS=function(t,n,o){return ut(X.call(e,t,n,o))},Document.prototype.createDocumentFragment=function(){return ut(J.call(e))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(n){return!h()||/^\d/.test(n)?tt.call(e,n):t(`#${n}`)},Document.prototype.getElementsByClassName=function(t){return!h()||/^\d/.test(t)?et.call(e,t):n(`.${t}`)},Document.prototype.getElementsByTagName=function(t){var o;const r=h();return!r||/^body$/i.test(t)||/^head$/i.test(t)||/^html$/i.test(t)||!(null===(o=Yt.get(r))||void 0===o?void 0:o.inline)&&/^script$/i.test(t)?nt.call(e,t):n(t)},Document.prototype.getElementsByName=function(t){return!h()||/^\d/.test(t)?ot.call(e,t):n(`[name=${t}]`)}}(),Element.prototype.setAttribute=function(t,e){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===t)if("[object Object]"===toString.call(e)){const t={};Object.getOwnPropertyNames(e).forEach((n=>{"string"==typeof n&&0===n.indexOf("__")||(t[n]=e[n])})),this.data=t}else"[object Object]"!==e&&o("property data must be an object");else if(("src"===t&&/^(img|iframe|script)$/i.test(this.tagName)||"href"===t&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Yt.has(this.__MICRO_APP_NAME__)){const n=Yt.get(this.__MICRO_APP_NAME__);G.call(this,t,c(e,n.url))}else G.call(this,t,e)},Node.prototype.appendChild=function(t){return ct(this,t,null,H)},Node.prototype.insertBefore=function(t,e){return ct(this,t,e,q)},Node.prototype.replaceChild=function(t,e){return ct(this,t,e,F)},Element.prototype.append=function(...t){let e=0;const n=t.length;for(;e<n;)ct(this,t[e],null,z),e++},Element.prototype.prepend=function(...t){let e=t.length;for(;e>0;)ct(this,t[e-1],null,Y),e--},Node.prototype.removeChild=function(t){if(null==t?void 0:t.__MICRO_APP_NAME__){const e=Yt.get(t.__MICRO_APP_NAME__);return(null==e?void 0:e.container)?st(e,K,this,at(t)):K.call(this,t)}return K.call(this,t)}}function ut(t){const e=h();return e&&(t.__MICRO_APP_NAME__=e),t}function pt(){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=tt,Document.prototype.getElementsByClassName=et,Document.prototype.getElementsByTagName=nt,Document.prototype.getElementsByName=ot,Element.prototype.setAttribute=G,Node.prototype.appendChild=H,Node.prototype.insertBefore=q,Node.prototype.replaceChild=F,Node.prototype.removeChild=K,Element.prototype.append=z,Element.prototype.prepend=Y}let dt=!1;function ht(t,e,o,r){var i;if(!t)return n(`element does not exist in lifecycle ${o},it seems the app has unmounted`);t instanceof ShadowRoot&&(t=t.host);const s=Object.assign({name:e,container:t},r&&{error:r}),a=new CustomEvent(o,{detail:s});!function(t,e){Object.defineProperties(t,{currentTarget:{get:()=>e},target:{get:()=>e}})}(a,t),"function"==typeof(null===(i=wt.lifeCycles)||void 0===i?void 0:i[o])&&wt.lifeCycles[o](a),t.dispatchEvent(a)}function mt(){Yt.forEach((t=>{let e=t.container;e&&(e instanceof ShadowRoot&&(e=e.host),e.disconnectedCallback())})),Yt.clear()}class ft extends HTMLElement{constructor(){super(...arguments),this.appName="",this.appUrl="",this.version="0.3.0",this.isWating=!1,this.cacheData=null,this.handleAttributeUpdate=()=>{var t;this.isWating=!1;const e=this.getAttribute("name"),o=s(this.getAttribute("url"));if(this.legalAttribute("name",e)&&this.legalAttribute("url",o)){const r=Yt.get(e);if(e!==this.appName&&r&&E.UNMOUNT!==r.getAppStatus()&&!r.isPrefetch)return this.setAttribute("name",this.appName),n(`an app named ${e} already exists`);e===this.appName&&o===this.appUrl||(this.handleUnmount(e===this.appName),this.appName=e,this.appUrl=o,(null!==(t=this.shadowRoot)&&void 0!==t?t:this).innerHTML="",r&&r.url===o?this.handleAppMount(r):this.handleCreate())}else e!==this.appName&&this.setAttribute("name",this.appName)}}static get observedAttributes(){return["name","url"]}connectedCallback(){if(1==++ft.microAppCount&&(lt(),function(){if(!dt){dt=!0;const t=b("style");t.setAttribute("type","text/css"),t.textContent=`\n${wt.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,e.head.appendChild(t)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",mt,!1)),r((()=>ht(this,this.appName,w.CREATED))),!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const t=Yt.get(this.appName);t?t.url!==this.appUrl||!t.isPrefetch&&t.getAppStatus()!==E.UNMOUNT?t.isPrefetch?n(`the url: ${this.appUrl} is different from prefetch url: ${t.url}`):n(`an app named ${this.appName} already exists`):this.handleAppMount(t):this.handleCreate()}disconnectedCallback(){ft.microAppCount>0&&(this.handleUnmount(this.getDisposeResult("destory")),0==--ft.microAppCount&&(pt(),window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",mt,!1)))}attributeChangedCallback(t,e,o){if(this.legalAttribute(t,o)&&this[t===g.NAME?"appName":"appUrl"]!==o)if(t!==g.URL||this.appUrl)t!==g.NAME||this.appName?this.isWating||(this.isWating=!0,r(this.handleAttributeUpdate)):(this.cacheData&&(wt.setData(o,this.cacheData),this.cacheData=null),this.appName=o);else{if(!(o=s(o)))return n("Invalid attribute url");this.appUrl=o}}legalAttribute(t,e){return!("string"!=typeof e||!e)||(n(`unexpected attribute ${t}, please check again`),!1)}handleAppMount(t){t.isPrefetch=!1,r((()=>{var e,n;return t.mount(null!==(e=this.shadowRoot)&&void 0!==e?e:this,this.getDisposeResult("inline"),null!==(n=this.getAttribute("baseurl"))&&void 0!==n?n:"")}))}handleCreate(){var t,e;const n=new Vt({name:this.appName,url:this.appUrl,container:null!==(t=this.shadowRoot)&&void 0!==t?t:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),macro:this.getDisposeResult("macro"),baseurl:null!==(e=this.getAttribute("baseurl"))&&void 0!==e?e:""});Yt.set(this.appName,n)}handleUnmount(t){const e=Yt.get(this.appName);e&&E.UNMOUNT!==e.getAppStatus()&&e.unmount(t)}getDisposeResult(t){return(this.hasAttribute(t)||wt[t])&&"false"!==this.getAttribute(t)}set data(t){this.appName?wt.setData(this.appName,t):this.cacheData=t}get data(){return this.appName?wt.getData(this.appName,!0):this.cacheData?this.cacheData:null}}ft.microAppCount=0;const yt=new class{constructor(){this.eventList=new Map}isLegalName(t){return!!t||(n("event-center: Invalid name"),!1)}on(t,e,o=!1){if(this.isLegalName(t)){if("function"!=typeof e)return n("event-center: Invalid callback function");let r=this.eventList.get(t);r?o&&Object.getOwnPropertyNames(r.data).length&&e(r.data):(r={data:{},callbacks:new Set},this.eventList.set(t,r)),r.callbacks.add(e)}}off(t,e){if(this.isLegalName(t)){const n=this.eventList.get(t);n&&("function"==typeof e?n.callbacks.delete(e):n.callbacks.clear())}}dispatch(t,e){if(this.isLegalName(t)){if("[object Object]"!==toString.call(e))return n("event-center: data must be object");let o=this.eventList.get(t);if(o){if(o.data!==e){o.data=e;for(const t of o.callbacks)t(e)}}else o={data:e,callbacks:new Set},this.eventList.set(t,o)}}getData(t){var e;const n=this.eventList.get(t);return null!==(e=null==n?void 0:n.data)&&void 0!==e?e:null}};function bt(t,e){return"string"==typeof t&&t?e?`__from_base_app_${t}__`:`__from_micro_app_${t}__`:""}class _t{addGlobalDataListener(t,e){const n=this.appName;n&&(t.__APP_NAME__=n,t.__AUTO_TRIGGER__=e),yt.on("global",t,e)}removeGlobalDataListener(t){"function"==typeof t&&yt.off("global",t)}setGlobalData(t){yt.dispatch("global",t)}clearGlobalDataListener(){const t=this.appName,e=yt.eventList.get("global");if(e)for(const n of e.callbacks)(t&&t===n.__APP_NAME__||!t&&!n.__APP_NAME__)&&e.callbacks.delete(n)}}class gt extends _t{addDataListener(t,e,n){yt.on(bt(t,!1),e,n)}removeDataListener(t,e){"function"==typeof e&&yt.off(bt(t,!1),e)}getData(t,e=!1){return yt.getData(bt(t,e))}setData(t,e){yt.dispatch(bt(t,!0),e)}clearDataListener(t){yt.off(bt(t,!1))}}class Et extends _t{constructor(t){super(),this.appName=t}addDataListener(t,e){t.__AUTO_TRIGGER__=e,yt.on(bt(this.appName,!0),t,e)}removeDataListener(t){"function"==typeof t&&yt.off(bt(this.appName,!0),t)}getData(){return yt.getData(bt(this.appName,!0))}dispatch(t){m(),yt.dispatch(bt(this.appName,!1),t);const e=Yt.get(this.appName);if((null==e?void 0:e.container)&&"[object Object]"===toString.call(t)){const n=new CustomEvent("datachange",{detail:{data:t}});let o=e.container;o instanceof ShadowRoot&&(o=o.host),o.dispatchEvent(n)}}clearDataListener(){yt.off(bt(this.appName,!0))}}var wt=new class extends gt{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Xt}start(t){if(!(null===window||void 0===window?void 0:window.customElements))return n("customElements is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return n(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}var e,r;r=this.tagName,(window.customElements.get(r)?(o(`element ${r} is already defined`),0):(window.customElements.define(r,ft),1))&&t&&"[object Object]"===toString.call(t)&&(this.shadowDOM=t.shadowDOM,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.macro=t.macro,y(t.fetch)&&(this.fetch=t.fetch),"[object Object]"===toString.call(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),"[object Object]"===toString.call(t.plugins)&&(this.plugins=t.plugins),t.preFetchApps&&Xt(t.preFetchApps),t.globalAssets&&(e=t.globalAssets,"[object Object]"===toString.call(e)&&u((()=>{if("[object Array]"===toString.call(e.js)){const t=e.js.filter((t=>"string"==typeof t&&t.includes(".js")&&!j.has(t))),o=[];t.forEach((t=>{o.push(vt(t))})),l(o,(e=>{const n=t[e.index];j.has(n)||j.set(n,e.data)}),(t=>{n(t)}))}if("[object Array]"===toString.call(e.css)){const t=e.css.filter((t=>"string"==typeof t&&t.includes(".css")&&!U.has(t))),o=[];t.forEach((t=>{o.push(vt(t))})),l(o,(e=>{const n=t[e.index];U.has(n)||U.set(n,e.data)}),(t=>{n(t)}))}}))))}};function vt(t,e=null,n={}){return y(wt.fetch)?wt.fetch(t,n,e):fetch(t,n).then((t=>t.text()))}function Ot(t,e,n){const o=Array.from(t.children);o.length&&o.forEach((t=>{Ot(t,e,n)}));for(const r of o)r instanceof HTMLLinkElement?r.hasAttribute("exclude")?t.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),r):e.scopecss?x(r,t,e,n):r.hasAttribute("href")&&r.setAttribute("href",c(r.getAttribute("href"),e.url)):r instanceof HTMLStyleElement?r.hasAttribute("exclude")?t.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),r):e.scopecss&&n.appendChild(C(r,e.name)):r instanceof HTMLScriptElement?$(r,t,e):r instanceof HTMLMetaElement||r instanceof HTMLTitleElement?t.removeChild(r):/^(img|iframe)$/i.test(r.tagName)&&r.hasAttribute("src")&&r.setAttribute("src",c(r.getAttribute("src"),e.url))}function Nt(t,e){const o=function(t){const e=b("div");return e.innerHTML=t,e}(t),r=o.querySelector("micro-app-head"),i=o.querySelector("micro-app-body");if(!r||!i){const t=`element ${r?"body":"head"} is missing`;return e.onerror(new Error(t)),n(t)}Ot(o,e,r),e.source.links.size?T(o,e,r):e.onLoad(o),e.source.scripts.size?k(o,e):e.onLoad(o)}const At=new WeakMap;const St=new WeakMap;const Mt=new WeakMap;function Rt(t,e){if(Mt.has(e))return Mt.get(e);if(y(e)&&!function(t){if(St.has(t))return St.get(t);const e=t.toString(),n=t.prototype&&t.prototype.constructor===t&&Object.getOwnPropertyNames(t.prototype).length>1||/^function\s+[A-Z]/.test(e)||/^class\s+/.test(e);return St.set(t,n),n}(e)&&!function(t){if(At.has(t))return At.get(t);const e=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return At.set(t,e),e}(e)){const n=e.bind(t);for(const t in e)n[t]=e[t];return e.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&(n.prototype=e.prototype),Mt.set(e,n),n}return e}const Ct=window.addEventListener,Dt=window.removeEventListener,Pt=window.setInterval,Lt=window.setTimeout,Ut=window.clearInterval,xt=window.clearTimeout,Tt=document.addEventListener,jt=document.removeEventListener,It=new Map;let $t=!1;const kt=new Map;function Wt(){$t||function(){$t=!0;const t=Object.getOwnPropertyDescriptor(document,"onclick");if(!1===(null==t?void 0:t.configurable))return o("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let n=!1;function r(t){It.forEach((e=>{"function"==typeof e&&e.call(document,t)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const t=h();return t?It.get(t):It.get("base")},set(t){const e=h();e?It.set(e,t):It.set("base",t),n||"function"!=typeof t||(n=!0,Tt.call(document,"click",r,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(t,e,n){const o=h();if(o){const r=kt.get(o);if(r){const n=r.get(t);n?n.add(e):r.set(t,new Set([e]))}else kt.set(o,new Map([[t,new Set([e])]]));e&&(e.__MICRO_MARK_OPTIONS__=n)}Tt.call(document,t,e,n)},document.removeEventListener=function(t,e,n){const o=h();if(o){const n=kt.get(o);if(n){const o=n.get(t);(null==o?void 0:o.size)&&o.has(e)&&o.delete(e)}}jt.call(document,t,e,n)}}function Bt(t,e){return"unmount"===t?`unmount-${e.__MICRO_APP_NAME__}`:t}const Gt=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Ht=["location"],qt={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Ft;function Kt(t){Ft&&clearTimeout(Ft),Ft=setTimeout(t,0)}class zt{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=e=>this.microWindow.hasOwnProperty(e)||t.hasOwnProperty(e);this.getScopeProperties(n),this.inject(this.microWindow,n,o),Object.assign(this,function(t){const e=t.__MICRO_APP_NAME__,n=new Map,o=new Map,r=new Map;t.addEventListener=function(e,o,r){e=Bt(e,t);const i=n.get(e);i?i.add(o):n.set(e,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=r),Ct.call(window,e,o,r)},t.removeEventListener=function(e,o,r){e=Bt(e,t);const i=n.get(e);(null==i?void 0:i.size)&&i.has(o)&&i.delete(o),Dt.call(window,e,o,r)},t.setInterval=function(t,e,...n){const r=Pt(t,e,...n);return o.set(r,{handler:t,timeout:e,args:n}),r},t.setTimeout=function(t,e,...n){const o=Lt(t,e,...n);return r.set(o,{handler:t,timeout:e,args:n}),o},t.clearInterval=function(t){o.delete(t),Ut(t)},t.clearTimeout=function(t){r.delete(t),xt(t)};const i=new Map,s=new Map;let a,c=new Map,l=new Map;return{recordUmdEffect:()=>{n.forEach(((t,e)=>{t.size&&i.set(e,new Set(t))})),o.size&&(c=new Map(o)),r.size&&(l=new Map(r)),a=It.get(e);const t=kt.get(e);t&&t.forEach(((t,e)=>{t.size&&s.set(e,new Set(t))}))},rebuildUmdEffect:()=>{i.forEach(((e,n)=>{for(const o of e)t.addEventListener(n,o,null==o?void 0:o.__MICRO_MARK_OPTIONS__)})),c.forEach((e=>{t.setInterval(e.handler,e.timeout,...e.args)})),l.forEach((e=>{t.setTimeout(e.handler,e.timeout,...e.args)})),a&&It.set(e,a),d(e),s.forEach(((t,e)=>{for(const n of t)document.addEventListener(e,n,null==n?void 0:n.__MICRO_MARK_OPTIONS__)})),d(null)},releaseEffect:()=>{n.size&&(n.forEach(((t,e)=>{for(const n of t)Dt.call(window,e,n)})),n.clear()),o.size&&(o.forEach(((t,e)=>{Ut(e)})),o.clear()),r.size&&(r.forEach(((t,e)=>{xt(e)})),r.clear()),It.delete(e);const t=kt.get(e);t&&(t.forEach(((t,e)=>{for(const n of t)jt.call(document,e,n)})),t.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(o,s)=>{if(s===Symbol.unscopables)return qt;if(["window","self","globalThis"].includes(s))return this.proxyWindow;if("top"===s||"parent"===s)return t===t.parent?this.proxyWindow:Reflect.get(t,s);if("hasOwnProperty"===s)return a;if("document"===s||"eval"===s)switch(this.active&&(d(n),(i?Kt:r)((()=>d(null)))),s){case"document":return e;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(t,s);return Rt(t,c)},set:(e,n,o)=>{if(this.active){if(Ht.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 r=Object.getOwnPropertyDescriptor(t,n),{writable:i,configurable:s,enumerable:a}=r;i&&(Object.defineProperty(e,n,{configurable:s,enumerable:a,writable:i,value:o}),this.injectedKeys.add(n))}(this.escapeProperties.includes(n)||Gt.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 qt||n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(e.hasOwnProperty(n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(t.hasOwnProperty(n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,o)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,o):Reflect.defineProperty(e,n,o),ownKeys:e=>Reflect.ownKeys(t).concat(Reflect.ownKeys(e)).filter((function(t){return!(t in this)&&(this[t]=!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_URL__=e,t._babelPolyfill&&(t._babelPolyfill=!1),1==++zt.activeCount&&Wt())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.microWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((t=>{Reflect.deleteProperty(this.microWindow,t)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(t,e)})),this.escapeKeys.clear(),0==--zt.activeCount&&(document.addEventListener=Tt,document.removeEventListener=jt))}recordUmdSnapshot(){this.recordUmdEffect(),function(t){const e=t.appName;t.umdDataListeners={global:new Set,normal:new Set};const n=yt.eventList.get("global");if(n)for(const o of n.callbacks)e===o.__APP_NAME__&&t.umdDataListeners.global.add(o);const o=yt.eventList.get(bt(e,!0));o&&(t.umdDataListeners.normal=new Set(o.callbacks))}(this.microWindow.microApp),this.recordUmdinjectedValues=new Map,this.injectedKeys.forEach((t=>{this.recordUmdinjectedValues.set(t,Reflect.get(this.microWindow,t))}))}rebuildUmdSnapshot(){this.recordUmdinjectedValues.forEach(((t,e)=>{Reflect.set(this.proxyWindow,e,t)})),this.rebuildUmdEffect(),function(t){for(const e of t.umdDataListeners.global)t.addGlobalDataListener(e,e.__AUTO_TRIGGER__);for(const e of t.umdDataListeners.normal)t.addDataListener(e,e.__AUTO_TRIGGER__)}(this.microWindow.microApp)}getScopeProperties(t){var e;if("object"==typeof wt.plugins){if("[object Array]"===toString.call(wt.plugins.global))for(const t of wt.plugins.global)"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)));if("[object Array]"===toString.call(null===(e=wt.plugins.modules)||void 0===e?void 0:e[t]))for(const e of wt.plugins.modules[t])"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)))}}inject(n,o,r){n.__MICRO_APP_ENVIRONMENT__=!0,n.__MICRO_APP_NAME__=o,n.__MICRO_APP_PUBLIC_PATH__=a(r),n.microApp=new Et(o),n.rawWindow=t,n.rawDocument=e,n.removeDomScope=m}}zt.activeCount=0;const Yt=new Map;class Vt{constructor({name:t,url:e,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseurl: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.baseurl="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseurl=null!=a?a:"",this.name=t,this.url=e,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 zt(t,e,this.macro))}loadSourceCode(){var t;this.status=E.LOADING_SOURCE_CODE,vt((t=this).url,t.name,{cache:"no-cache"}).then((e=>{if(!e){const e="html is empty, please check in detail";return t.onerror(new Error(e)),n(e)}Nt(e=e.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(t=>t.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(t=>t.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),t)})).catch((e=>{n(`Failed to fetch data from ${t.url}, micro-app stop rendering`,e),t.onLoadError(e)}))}onLoad(t){if(2==++this.loadSourceLevel){if(this.source.html=t,this.isPrefetch||E.UNMOUNT===this.status)return;this.status=E.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(t){this.loadSourceLevel=-1,E.UNMOUNT!==this.status&&(this.onerror(t),this.status=E.LOAD_SOURCE_ERROR)}mount(t,e,o){var i,s,a,c;if("boolean"==typeof e&&e!==this.inline&&(this.inline=e),this.container=null!==(i=this.container)&&void 0!==i?i:t,this.baseurl=null!=o?o:this.baseurl,2===this.loadSourceLevel){if(ht(this.container,this.name,w.BEFOREMOUNT),this.status=E.MOUNTING,_(this.source.html,this.container),null===(s=this.sandBox)||void 0===s||s.start(this.baseurl),this.umdHookMount)null===(c=this.sandBox)||void 0===c||c.rebuildUmdSnapshot(),this.umdHookMount();else{!function(t,e){const o=Array.from(t.entries()),r=[],i=[];for(const[t,n]of o)n.isDynamic||(n.defer||n.async?(n.isExternal&&!n.code?r.push(vt(t,e.name)):r.push(n.code),i.push([t,n])):W(t,n.code,e,n.module,!1));r.length&&Promise.all(r).then((t=>{t.forEach(((t,n)=>{const[o,r]=i[n];W(o,r.code=r.code||t,e,r.module,!1)}))})).catch((t=>{n(t)}))}(this.source.scripts,this);const{mount:t,unmount:e}=this.getUmdLibraryHooks();y(t)&&y(e)&&(this.umdHookMount=t,this.umdHookunMount=e,null===(a=this.sandBox)||void 0===a||a.recordUmdSnapshot(),this.source.html.innerHTML="",_(this.container,this.source.html),l=this.source.html,p=this.name,u((()=>{var t;const e=Array.from(l.querySelectorAll("style"));for(const n of e)-1===(null===(t=n.textContent)||void 0===t?void 0:t.indexOf(`${wt.tagName}[name=${p}]`))&&C(n,p)})),this.umdHookMount())}var l,p;E.UNMOUNT!==this.status&&(this.status=E.MOUNTED,r((()=>{E.UNMOUNT!==this.status&&ht(this.container,this.name,w.MOUNTED)})))}else this.status=E.LOADING_SOURCE_CODE}unmount(t){var e;this.status===E.LOAD_SOURCE_ERROR&&(t=!0),this.status=E.UNMOUNT,ht(this.container,this.name,w.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(t){const e=new CustomEvent(`unmount-${t}`);window.dispatchEvent(e)}(this.name),null===(e=this.sandBox)||void 0===e||e.stop(),this.container=null,t&&Yt.delete(this.name)}onerror(t){ht(this.container,this.name,w.ERROR,t)}getAppStatus(){return this.status}getUmdLibraryHooks(){var e,n;if(E.UNMOUNT!==this.status){const o=null!==(n=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==n?n:t,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 Xt(t){u((()=>{"function"==typeof t&&(t=t()),function(t){const e=[];return"[object Array]"===toString.call(t)&&t.forEach((t=>{t.url=s(t.url),"[object Object]"===toString.call(t)&&t.name&&"string"==typeof t.name&&t.url&&!Yt.has(t.name)&&e.push(t)})),e}(t).forEach((t=>{var e,n,o;const r=new Vt({name:t.name,url:t.url,scopecss:!(null!==(e=t.disableScopecss)&&void 0!==e?e:wt.disableScopecss),useSandbox:!(null!==(n=t.disableSandbox)&&void 0!==n?n:wt.disableSandbox),macro:null!==(o=t.macro)&&void 0!==o?o:wt.macro});r.isPrefetch=!0,Yt.set(t.name,r)}))}))}exports.default=wt,exports.preFetch=Xt,exports.pureCreateElement=b,exports.removeDomScope=m,exports.version="0.3.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.2.5";function r(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function i(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 c(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(c(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const r=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(r)?`${r}${o}`:""}catch(e){return r(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(c(t))).toString()}function p(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 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 b(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function g(e){return"function"==typeof e}function E(e,t){const o=n.createElement(e,t);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}var w,_,v,N;function A(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,r)=>{if(/^data:/.test(r))return e;if(/^(https?:)?\/\//.test(r)){if(!b())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(),c(t.join("/")+"/")}(o)),`url("${u(r,t)}")`}))}function C(e,t,n){const o=S(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function S(e,t){let n="";for(const o of e)switch(o.type){case N.STYLE_RULE:n+=A(o,t);break;case N.MEDIA_RULE:n+=C(o,t,"media");break;case N.SUPPORTS_RULE:n+=C(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function D(e,t,n,o,r,i){var s,c;let a=O(S(Array.from(null!==(c=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==c?c:[]),o),r,n,i);b()&&(a=a.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=a}!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"}(_||(_={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(v||(v={})),function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(N||(N={}));let R=n.body.querySelector("#micro-app-template-style");function P(e,t){const o=Ve.get(t);if(null==o?void 0:o.scopecss){const r=`${ve.tagName}[name=${t}]`;if(R||(R=E("style"),R.setAttribute("id","micro-app-template-style"),n.body.appendChild(R),R.sheet.disabled=!0),e.textContent)R.textContent=e.textContent,D(R,e,e.textContent,r,o.url,e.linkpath),R.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")||D(e,e,e.textContent,r,o.url,e.linkpath)}));t.observe(e,{childList:!0})}}return e}function M(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function L(e){const t=new CustomEvent("load");M(t,e),"function"==typeof e.onload?e.onload(t):e.dispatchEvent(t)}function x(e){const t=new CustomEvent("error");M(t,e),"function"==typeof e.onerror?e.onerror(t):e.dispatchEvent(t)}const U=new Map;function T(e,t,n,o,r=!1){const i=e.getAttribute("rel");let s=e.getAttribute("href"),c=null;if("stylesheet"===i&&s){if(s=u(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",u(s,n.url));return r?{replaceComment:c}:c?t.replaceChild(c,e):void 0}function j(e,t,n){const o=Array.from(t.source.links.entries()),i=[];for(const[e]of o){const n=U.get(e);n?i.push(n):i.push(Ne(e,t.name))}p(i,(e=>{!function(e,t,n,o,r){t.isGlobal&&!U.has(e)&&U.set(e,n);const i=E("style");i.textContent=n,i.linkpath=e,o.replaceChild(P(i,r.name),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{r(e)}),(()=>{t.onLoad(e)}))}const $=new Map,I="noModule"in document.createElement("script");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(I&&e.noModule||!I&&"module"===e.type)r=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=u(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 B(e,t){const n=Array.from(t.source.scripts.entries()),o=[],i=[];for(const[e,r]of n)if(r.isExternal){const n=$.get(e);n?r.code=n:r.defer||r.async||(o.push(Ne(e,t.name)),i.push([e,r]))}o.length?p(o,(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=>{r(e)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function W(e,t,n,o,r){var i;try{if(t=H(e,t,n),n.inline){const e=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((0,eval)(t),r)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 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}(e,n,o.name,ve.plugins)),o.sandBox?(t.proxyWindow=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.proxyWindow, window.proxyWindow, window.proxyWindow);`):n}const q=Element.prototype.setAttribute,G=Node.prototype.appendChild,F=Node.prototype.insertBefore,K=Node.prototype.replaceChild,z=Node.prototype.removeChild,V=Element.prototype.append,Y=Element.prototype.prepend,J=Document.prototype.createElement,Z=Document.prototype.createElementNS,Q=Document.prototype.createDocumentFragment,X=Document.prototype.querySelector,ee=Document.prototype.querySelectorAll,te=Document.prototype.getElementById,ne=Document.prototype.getElementsByClassName,oe=Document.prototype.getElementsByTagName,re=Document.prototype.getElementsByName,ie=new WeakMap;function se(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return ie.set(t,e),e}return n.scopecss?P(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 ie.set(t,e),e}if(!n.scopecss)return t;const{url:o,info:i}=T(t,e,n,null,!0);if(o&&i){const e=E("style");return e.linkpath=o,function(e,t,n,o,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,P(i,n.name),void s((()=>L(o)));if(U.has(e)){const r=U.get(e);return t.code=r,n.source.links.set(e,t),i.textContent=r,P(i,n.name),void s((()=>L(o)))}Ne(e,n.name).then((r=>{t.code=r,n.source.links.set(e,t),t.isGlobal&&U.set(e,r),i.textContent=r,P(i,n.name),L(o)})).catch((e=>{r(e),x(o)}))}(o,i,n,t,e),ie.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:i,info:c}=k(t,e,n,!0);if(i&&c){if(c.code){const e=W(i,c.code,n,c.module,!0);return ie.set(t,e),e}{const e=function(e,t,n,o){if(n.source.scripts.has(e)){const r=n.source.scripts.get(e);return s((()=>L(o))),W(e,r.code,n,t.module,!0)}if($.has(e)){const r=$.get(e);return t.code=r,n.source.scripts.set(e,t),s((()=>L(o))),W(e,r,n,t.module,!0)}let i;return i=n.inline?E("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),Ne(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&$.set(e,r);try{r=H(e,r,n),n.inline?(t.module&&i.setAttribute("type","module"),i.textContent=r):(0,eval)(r)}catch(t){console.error("[micro-app from runDynamicScript]",t,e)}L(o)})).catch((e=>{r(e),x(o)})),i}(i,c,n,t);return ie.set(t,e),e}}return ie.set(t,o),o}return t}function ce(e,t,n,o,r){if(n instanceof HTMLHeadElement){const i=e.container.querySelector("micro-app-head");return r&&!i.contains(r)?G.call(i,o):t!==z||i.contains(o)?t===V||t===Y?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}if(n instanceof HTMLBodyElement){const i=e.container.querySelector("micro-app-body");return r&&!i.contains(r)?G.call(i,o):t!==z||i.contains(o)?t===V||t===Y?t.call(i,o):t.call(i,o,r):n.contains(o)?t.call(n,o):o}return t===V||t===Y?t.call(n,o):t.call(n,o,r)}function ae(e){var t;return null!==(t=ie.get(e))&&void 0!==t?t:e}function le(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)?ce(r,o,e,se(e,t,r),n&&ae(n)):o===V||o===Y?o.call(e,t):o.call(e,t,n)}if(o===V||o===Y){const n=f();if(!(t instanceof Node)&&n){const r=Ve.get(n);if(null==r?void 0:r.container){if(e instanceof HTMLHeadElement)return o.call(r.container.querySelector("micro-app-head"),t);if(e instanceof HTMLBodyElement)return o.call(r.container.querySelector("micro-app-body"),t)}}return o.call(e,t)}return o.call(e,t,n)}function ue(){!function(){function e(e){var t,o,r;const i=f();return i&&"head"!==e&&"body"!==e&&"html"!==e?null!==(r=null===(o=null===(t=Ve.get(i))||void 0===t?void 0:t.container)||void 0===o?void 0:o.querySelector(e))&&void 0!==r?r:null:X.call(n,e)}function t(e){var t,o,r;const i=f();return i&&"head"!==e&&"body"!==e&&"html"!==e?null!==(r=null===(o=null===(t=Ve.get(i))||void 0===t?void 0:t.container)||void 0===o?void 0:o.querySelectorAll(e))&&void 0!==r?r:[]:ee.call(n,e)}Document.prototype.createElement=function(e,t){return pe(J.call(n,e,t))},Document.prototype.createElementNS=function(e,t,o){return pe(Z.call(n,e,t,o))},Document.prototype.createDocumentFragment=function(){return pe(Q.call(n))},Document.prototype.querySelector=e,Document.prototype.querySelectorAll=t,Document.prototype.getElementById=function(t){return!f()||/^\d/.test(t)?te.call(n,t):e(`#${t}`)},Document.prototype.getElementsByClassName=function(e){return!f()||/^\d/.test(e)?ne.call(n,e):t(`.${e}`)},Document.prototype.getElementsByTagName=function(e){var o;const r=f();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)?oe.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&&i("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__);q.call(this,e,u(t,n.url))}else q.call(this,e,t)},Node.prototype.appendChild=function(e){return le(this,e,null,G)},Node.prototype.insertBefore=function(e,t){return le(this,e,t,F)},Node.prototype.replaceChild=function(e,t){return le(this,e,t,K)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)le(this,e[t],null,V),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)le(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)?ce(t,z,this,ae(e)):z.call(this,e)}return z.call(this,e)}}function pe(e){const t=f();return t&&(e.__MICRO_APP_NAME__=t),e}function de(){m(null),Document.prototype.createElement=J,Document.prototype.createElementNS=Z,Document.prototype.createDocumentFragment=Q,Document.prototype.querySelector=X,Document.prototype.querySelectorAll=ee,Document.prototype.getElementById=te,Document.prototype.getElementsByClassName=ne,Document.prototype.getElementsByTagName=oe,Document.prototype.getElementsByName=re,Element.prototype.setAttribute=q,Node.prototype.appendChild=G,Node.prototype.insertBefore=F,Node.prototype.replaceChild=K,Node.prototype.removeChild=z,Element.prototype.append=V,Element.prototype.prepend=Y}let he=!1;function me(e,t,n,o){var i;if(!e)return r(`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}),c=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(c,e),"function"==typeof(null===(i=ve.lifeCycles)||void 0===i?void 0:i[n])&&ve.lifeCycles[n](c),e.dispatchEvent(c)}function fe(){Ve.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),Ve.clear()}class ye extends HTMLElement{constructor(){super(...arguments),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=a(this.getAttribute("url"));if(this.legalAttribute("name",t)&&this.legalAttribute("url",n)){const o=Ve.get(t);if(t!==this.appName&&o&&o.getAppStatus()!==_.UNMOUNT&&!o.isPrefetch)return this.setAttribute("name",this.appName),r(`an app named ${t} already exists`);t===this.appName&&n===this.appUrl||(this.handleUnmount(!0),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)}}static get observedAttributes(){return["name","url"]}connectedCallback(){if(1==++ye.microAppCount&&(ue(),function(){if(!he){he=!0;const e=E("style");e.setAttribute("type","text/css"),e.textContent=`\n${ve.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,n.head.appendChild(e)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",fe,!1)),s((()=>me(this,this.appName,v.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()!==_.UNMOUNT?e.isPrefetch?r(`the url: ${this.appUrl} is different from prefetch url: ${e.url}`):r(`an app named ${this.appName} already exists`):this.handleAppMount(e):this.handleCreate()}disconnectedCallback(){ye.microAppCount>0&&(this.handleUnmount(this.getDisposeResult("destory")),0==--ye.microAppCount&&(de(),window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",fe,!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&&(ve.setData(n,this.cacheData),this.cacheData=null),this.appName=n);else{if(!(n=a(n)))return r("Invalid attribute url");this.appUrl=n}}legalAttribute(e,t){return!("string"!=typeof t||!t)||(r(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,s((()=>{var t,n;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),null!==(n=this.getAttribute("baseurl"))&&void 0!==n?n:"")}))}handleCreate(){var e,t;const n=new Ye({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"),baseurl:null!==(t=this.getAttribute("baseurl"))&&void 0!==t?t:""});Ve.set(this.appName,n)}handleUnmount(e){const t=Ve.get(this.appName);t&&t.getAppStatus()!==_.UNMOUNT&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||ve[e])&&"false"!==this.getAttribute(e)}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}}ye.microAppCount=0;const be=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(r("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if("function"!=typeof t)return r("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 r("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 ge(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Ee{addGlobalDataListener(e,t){be.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&be.off("global",e)}setGlobalData(e){be.dispatch("global",e)}clearGlobalDataListener(){be.off("global")}}class we extends Ee{addDataListener(e,t,n){be.on(ge(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&be.off(ge(e,!1),t)}getData(e,t=!1){return be.getData(ge(e,t))}setData(e,t){be.dispatch(ge(e,!0),t)}clearDataListener(e){be.off(ge(e,!1))}}class _e extends Ee{constructor(e){super(),this.appName=e}addDataListener(e,t){be.on(ge(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&be.off(ge(this.appName,!0),e)}getData(){return be.getData(ge(this.appName,!0))}dispatch(e){y(),be.dispatch(ge(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(){be.off(ge(this.appName,!0))}}var ve=new class extends we{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Je}start(e){if(!(null===window||void 0===window?void 0:window.customElements))return r("customElements is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return r(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}var t,n;n=this.tagName,(window.customElements.get(n)?(i(`element ${n} is already defined`),0):(window.customElements.define(n,ye),1))&&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,g(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)&&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=>{r(e)}))}if("[object Array]"===toString.call(t.css)){const e=t.css.filter((e=>"string"==typeof e&&e.includes(".css")&&!U.has(e))),n=[];e.forEach((e=>{n.push(Ne(e))})),p(n,(t=>{const n=e[t.index];U.has(n)||U.set(n,t.data)}),(e=>{r(e)}))}}))))}};function Ne(e,t=null,n={}){return g(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?T(r,e,t,n):r.hasAttribute("href")&&r.setAttribute("href",u(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(P(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",u(r.getAttribute("src"),t.url))}function Oe(e,t){const n=function(e){const t=E("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!o||!i){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),r(e)}Ae(n,t,o),t.source.links.size?j(n,t,o):t.onLoad(n),t.source.scripts.size?B(n,t):t.onLoad(n)}const Ce=new WeakMap;const Se=new WeakMap;function De(e,t){if(Se.has(t))return Se.get(t);if(g(t)&&!function(e){if(Ce.has(e))return Ce.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return Ce.set(e,n),n}(t)){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),Se.set(t,n),n}return t}const Re=window.addEventListener,Pe=window.removeEventListener,Me=window.setInterval,Le=window.setTimeout,xe=window.clearInterval,Ue=window.clearTimeout,Te=document.addEventListener,je=document.removeEventListener,$e=new Map;let Ie=!1;const ke=new Map;function Be(){Ie||function(){Ie=!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=f();return e?$e.get(e):$e.get("base")},set(e){const t=f();t?$e.set(t,e):$e.set("base",e),n||"function"!=typeof e||(n=!0,Te.call(document,"click",o,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(e,t,n){const o=f();if(o){const n=ke.get(o);if(n){const o=n.get(e);o?o.add(t):n.set(e,new Set([t]))}else ke.set(o,new Map([[e,new Set([t])]]))}return Te.call(document,e,t,n)},document.removeEventListener=function(e,t,n){const o=f();if(o){const n=ke.get(o);if(n){const o=n.get(e);(null==o?void 0:o.size)&&o.has(t)&&o.delete(t)}}return je.call(document,e,t,n)}}function We(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const He=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],qe=["location"],Ge={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let Fe;function Ke(e){Fe&&clearTimeout(Fe),Fe=setTimeout(e,0)}class ze{constructor(e,o,r){this.active=!1,this.scopeProperties=["webpackJsonp"],this.escapeProperties=[],this.microWindow={},this.injectedKeys=new Set,this.escapeKeys=new Set;const i=new Map,c=e=>this.microWindow.hasOwnProperty(e)||t.hasOwnProperty(e);this.getScopeProperties(e),this.inject(this.microWindow,e,o),this.releaseEffect=function(e){const t=new Map,n=new Set,o=new Set;return e.addEventListener=function(n,o,r){n=We(n,e);const i=t.get(n);return i?i.add(o):t.set(n,new Set([o])),Re.call(window,n,o,r)},e.removeEventListener=function(n,o,r){n=We(n,e);const i=t.get(n);return(null==i?void 0:i.size)&&i.has(o)&&i.delete(o),Pe.call(window,n,o,r)},e.setInterval=function(e,t,...o){const r=Me(e,t,...o);return n.add(r),r},e.setTimeout=function(e,t,...n){const r=Le(e,t,...n);return o.add(r),r},e.clearInterval=function(e){n.delete(e),xe(e)},e.clearTimeout=function(e){o.delete(e),Ue(e)},()=>{t.size&&(t.forEach(((e,t)=>{if(e.size)for(const n of e)Pe.call(window,t,n)})),t.clear()),n.size&&(n.forEach((e=>{xe(e)})),n.clear()),o.size&&(o.forEach((e=>{Ue(e)})),o.clear());const r=e.__MICRO_APP_NAME__;$e.delete(r);const i=ke.get(r);i&&(i.forEach(((e,t)=>{if(e.size)for(const n of e)je.call(document,t,n)})),i.clear())}}(this.microWindow),this.proxyWindow=new Proxy(this.microWindow,{get:(o,i)=>{if(i===Symbol.unscopables)return Ge;if(["window","self","globalThis"].includes(i))return this.proxyWindow;if("top"===i||"parent"===i)return t===t.parent?this.proxyWindow:Reflect.get(t,i);if("hasOwnProperty"===i)return c;if("document"===i||"eval"===i)switch(this.active&&(m(e),(r?Ke:s)((()=>m(null)))),i){case"document":return n;case"eval":return eval}if(this.scopeProperties.includes(i))return Reflect.get(o,i);if(Reflect.has(o,i))return Reflect.get(o,i);const a=Reflect.get(t,i);return De(t,a)},set:(e,n,o)=>{if(this.active){if(qe.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 r=Object.getOwnPropertyDescriptor(t,n),{writable:i,configurable:s,enumerable:c}=r;i&&(Object.defineProperty(e,n,{configurable:s,enumerable:c,writable:i,value:o}),this.injectedKeys.add(n))}(this.escapeProperties.includes(n)||He.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 Ge||n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(e.hasOwnProperty(n))return i.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(t.hasOwnProperty(n)){i.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,o)=>"rawWindow"===i.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_URL__=e,t._babelPolyfill&&(t._babelPolyfill=!1),1==++ze.activeCount&&Be())}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microWindow.microApp.clearDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(t,e)})),this.escapeKeys.clear(),0==--ze.activeCount&&(document.addEventListener=Te,document.removeEventListener=je))}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(e,o,r){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=o,e.__MICRO_APP_PUBLIC_PATH__=l(r),e.microApp=new _e(o),e.rawWindow=t,e.rawDocument=n}}ze.activeCount=0;const Ve=new Map;class Ye{constructor({name:e,url:t,container:n,inline:o,scopecss:r,useSandbox:i,macro:s,baseurl:c}){this.status=_.NOT_LOADED,this.loadSourceLevel=0,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseurl="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseurl=null!=c?c:"",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 ze(e,t,this.macro))}loadSourceCode(){var e;this.status=_.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)),r(t)}Oe(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=>{r(`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||this.status===_.UNMOUNT)return;this.status=_.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,this.status!==_.UNMOUNT&&(this.onerror(e),this.status=_.LOAD_SOURCE_ERROR)}mount(e,t,n){var o;if(!this.container&&e&&(this.container=e),"boolean"==typeof t&&t!==this.inline&&(this.inline=t),this.baseurl=null!=n?n:this.baseurl,2!==this.loadSourceLevel)return void(this.status=_.LOADING_SOURCE_CODE);me(this.container,this.name,v.BEFOREMOUNT),this.status=_.MOUNTING;const i=this.source.html.cloneNode(!0),c=document.createDocumentFragment();Array.from(i.childNodes).forEach((e=>{c.appendChild(e)})),this.container.appendChild(c),null===(o=this.sandBox)||void 0===o||o.start(this.baseurl),function(e,t){const n=Array.from(e.entries()),o=[],i=[];for(const[e,r]of n)r.isDynamic||(r.defer||r.async?(r.isExternal?o.push(Ne(e,t.name)):o.push(r.code),i.push([e,r])):W(e,r.code,t,r.module,!1));o.length&&Promise.all(o).then((e=>{e.forEach(((e,n)=>{W(i[n][0],e,t,i[n][1].module,!1)}))})).catch((e=>{r(e)}))}(this.source.scripts,this),this.status!==_.UNMOUNT&&(this.status=_.MOUNTED,s((()=>{this.status!==_.UNMOUNT&&me(this.container,this.name,v.MOUNTED)})))}unmount(e){var t;this.status===_.LOAD_SOURCE_ERROR&&(e=!0),this.status=_.UNMOUNT,me(this.container,this.name,v.UNMOUNT),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){me(this.container,this.name,v.ERROR,e)}getAppStatus(){return this.status}}function Je(e){d((()=>{"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&&!Ve.has(e.name)&&t.push(e)})),t}(e).forEach((e=>{var t,n,o;const r=new Ye({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)}))}))}e.default=ve,e.preFetch=Je,e.pureCreateElement=E,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=new Function("return window")(),n=new Function("return document")(),o="0.3.0";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 b(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function g(e){return"function"==typeof e}function _(e,t){const o=n.createElement(e,t);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function E(e,t){const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var w,v,O,N;function A(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 S(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,i)=>{if(/^data:/.test(i))return e;if(/^(https?:)?\/\//.test(i)){if(!b())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=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 N.STYLE_RULE:n+=A(o,t);break;case N.MEDIA_RULE:n+=M(o,t,"media");break;case N.SUPPORTS_RULE:n+=M(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function C(e,t,n,o,i,r){var s,a;let c=S(R(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),i,n,r);b()&&(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"}(N||(N={}));let D=n.body.querySelector("#micro-app-template-style");function P(e,t){const o=Xe.get(t);if(null==o?void 0:o.scopecss){const i=`${Oe.tagName}[name=${t}]`;if(D||(D=_("style"),D.setAttribute("id","micro-app-template-style"),n.body.appendChild(D),D.sheet.disabled=!0),e.textContent)D.textContent=e.textContent,C(D,e,e.textContent,i,o.url,e.linkpath),D.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")||C(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=_("style");r.textContent=n,r.linkpath=e,o.replaceChild(P(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=_("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 Oe.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,Oe.plugins)),o.sandBox?(t.__PROXY_WINDOW__=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__PROXY_WINDOW__, window.__PROXY_WINDOW__, window.__PROXY_WINDOW__);`):n}const q=Element.prototype.setAttribute,F=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?P(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=_("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,P(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,P(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,P(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?_("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)?F.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)?F.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=Xe.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=Xe.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=Xe.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=Xe.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=Xe.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__&&Xe.has(this.__MICRO_APP_NAME__)){const n=Xe.get(this.__MICRO_APP_NAME__);q.call(this,e,u(t,n.url))}else q.call(this,e,t)},Node.prototype.appendChild=function(e){return ue(this,e,null,F)},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=Xe.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=q,Node.prototype.appendChild=F,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=Oe.lifeCycles)||void 0===r?void 0:r[n])&&Oe.lifeCycles[n](a),e.dispatchEvent(a)}function ye(){Xe.forEach((e=>{let t=e.container;t&&(t instanceof ShadowRoot&&(t=t.host),t.disconnectedCallback())})),Xe.clear()}class be extends HTMLElement{constructor(){super(...arguments),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=Xe.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)}}static get observedAttributes(){return["name","url"]}connectedCallback(){if(1==++be.microAppCount&&(pe(),function(){if(!me){me=!0;const e=_("style");e.setAttribute("type","text/css"),e.textContent=`\n${Oe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,n.head.appendChild(e)}}(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ye,!1)),s((()=>fe(this,this.appName,O.CREATED))),!this.appName||!this.appUrl)return;this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=Xe.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(){be.microAppCount>0&&(this.handleUnmount(this.getDisposeResult("destory")),0==--be.microAppCount&&(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&&(Oe.setData(n,this.cacheData),this.cacheData=null),this.appName=n);else{if(!(n=c(n)))return i("Invalid attribute url");this.appUrl=n}}legalAttribute(e,t){return!("string"!=typeof t||!t)||(i(`unexpected attribute ${e}, please check again`),!1)}handleAppMount(e){e.isPrefetch=!1,s((()=>{var t,n;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),null!==(n=this.getAttribute("baseurl"))&&void 0!==n?n:"")}))}handleCreate(){var e,t;const n=new Je({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"),baseurl:null!==(t=this.getAttribute("baseurl"))&&void 0!==t?t:""});Xe.set(this.appName,n)}handleUnmount(e){const t=Xe.get(this.appName);t&&v.UNMOUNT!==t.getAppStatus()&&t.unmount(e)}getDisposeResult(e){return(this.hasAttribute(e)||Oe[e])&&"false"!==this.getAttribute(e)}set data(e){this.appName?Oe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Oe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}be.microAppCount=0;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 _e(e,t){return"string"==typeof e&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Ee{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 we extends Ee{addDataListener(e,t,n){ge.on(_e(e,!1),t,n)}removeDataListener(e,t){"function"==typeof t&&ge.off(_e(e,!1),t)}getData(e,t=!1){return ge.getData(_e(e,t))}setData(e,t){ge.dispatch(_e(e,!0),t)}clearDataListener(e){ge.off(_e(e,!1))}}class ve extends Ee{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ge.on(_e(this.appName,!0),e,t)}removeDataListener(e){"function"==typeof e&&ge.off(_e(this.appName,!0),e)}getData(){return ge.getData(_e(this.appName,!0))}dispatch(e){y(),ge.dispatch(_e(this.appName,!1),e);const t=Xe.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(_e(this.appName,!0))}}var Oe=new class extends we{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ze}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;n=this.tagName,(window.customElements.get(n)?(r(`element ${n} is already defined`),0):(window.customElements.define(n,be),1))&&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,g(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&&Ze(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)}))}}))))}};function Ne(e,t=null,n={}){return g(Oe.fetch)?Oe.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 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(P(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 Se(e,t){const n=function(e){const t=_("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)}Ae(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 Me=new WeakMap;const Re=new WeakMap;const Ce=new WeakMap;function De(e,t){if(Ce.has(t))return Ce.get(t);if(g(t)&&!function(e){if(Re.has(e))return Re.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 Re.set(e,n),n}(t)&&!function(e){if(Me.has(e))return Me.get(e);const t=0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype");return Me.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 Pe=window.addEventListener,Le=window.removeEventListener,Ue=window.setInterval,xe=window.setTimeout,Te=window.clearInterval,je=window.clearTimeout,Ie=document.addEventListener,$e=document.removeEventListener,ke=new Map;let We=!1;const Be=new Map;function Ge(){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){ke.forEach((t=>{"function"==typeof t&&t.call(document,e)}))}Object.defineProperty(document,"onclick",{configurable:!1,enumerable:!0,get(){const e=f();return e?ke.get(e):ke.get("base")},set(e){const t=f();t?ke.set(t,e):ke.set("base",e),n||"function"!=typeof e||(n=!0,Ie.call(document,"click",o,!1))}}),t&&(document.onclick=t)}(),document.addEventListener=function(e,t,n){const o=f();if(o){const i=Be.get(o);if(i){const n=i.get(e);n?n.add(t):i.set(e,new Set([t]))}else Be.set(o,new Map([[e,new Set([t])]]));t&&(t.__MICRO_MARK_OPTIONS__=n)}Ie.call(document,e,t,n)},document.removeEventListener=function(e,t,n){const o=f();if(o){const n=Be.get(o);if(n){const o=n.get(e);(null==o?void 0:o.size)&&o.has(t)&&o.delete(t)}}$e.call(document,e,t,n)}}function He(e,t){return"unmount"===e?`unmount-${t.__MICRO_APP_NAME__}`:e}const qe=["System","__cjsWrapper","__REACT_ERROR_OVERLAY_GLOBAL_HOOK__"],Fe=["location"],Ke={undefined:!0,Array:!0,Object:!0,String:!0,Boolean:!0,Math:!0,Number:!0,Symbol:!0,parseFloat:!0,Float32Array:!0};let ze;function Ye(e){ze&&clearTimeout(ze),ze=setTimeout(e,0)}class Ve{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=He(t,e);const r=n.get(t);r?r.add(o):n.set(t,new Set([o])),o&&(o.__MICRO_MARK_OPTIONS__=i),Pe.call(window,t,o,i)},e.removeEventListener=function(t,o,i){t=He(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(o)&&r.delete(o),Le.call(window,t,o,i)},e.setInterval=function(e,t,...n){const i=Ue(e,t,...n);return o.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const o=xe(e,t,...n);return i.set(o,{handler:e,timeout:t,args:n}),o},e.clearInterval=function(e){o.delete(e),Te(e)},e.clearTimeout=function(e){i.delete(e),je(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=ke.get(t);const e=Be.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&&ke.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)Le.call(window,t,n)})),n.clear()),o.size&&(o.forEach(((e,t)=>{Te(t)})),o.clear()),i.size&&(i.forEach(((e,t)=>{je(t)})),i.clear()),ke.delete(t);const e=Be.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)$e.call(document,t,n)})),e.clear())}}}(this.microWindow)),this.proxyWindow=new Proxy(this.microWindow,{get:(o,r)=>{if(r===Symbol.unscopables)return Ke;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?Ye: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(Fe.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 Ke||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_URL__=e,t._babelPolyfill&&(t._babelPolyfill=!1),1==++Ve.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(t,e)})),this.escapeKeys.clear(),0==--Ve.activeCount&&(document.addEventListener=Ie,document.removeEventListener=$e))}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(_e(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 Oe.plugins){if("[object Array]"===toString.call(Oe.plugins.global))for(const e of Oe.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=Oe.plugins.modules)||void 0===t?void 0:t[e]))for(const t of Oe.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 ve(o),e.rawWindow=t,e.rawDocument=n,e.removeDomScope=y}}Ve.activeCount=0;const Xe=new Map;class Je{constructor({name:e,url:t,container:n,inline:o,scopecss:i,useSandbox:r,macro:s,baseurl: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.baseurl="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseurl=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 Ve(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)}Se(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.baseurl=null!=n?n:this.baseurl,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.baseurl),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();g(e)&&g(t)&&(this.umdHookMount=e,this.umdHookunMount=t,null===(a=this.sandBox)||void 0===a||a.recordUmdSnapshot(),this.source.html.innerHTML="",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(`${Oe.tagName}[name=${u}]`))&&P(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&&Xe.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 Ze(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&&!Xe.has(e.name)&&t.push(e)})),t}(e).forEach((e=>{var t,n,o;const i=new Je({name:e.name,url:e.url,scopecss:!(null!==(t=e.disableScopecss)&&void 0!==t?t:Oe.disableScopecss),useSandbox:!(null!==(n=e.disableSandbox)&&void 0!==n?n:Oe.disableSandbox),macro:null!==(o=e.macro)&&void 0!==o?o:Oe.macro});i.isPrefetch=!0,Xe.set(e.name,i)}))}))}e.default=Oe,e.preFetch=Ze,e.pureCreateElement=_,e.removeDomScope=y,e.version=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@micro-zoe/micro-app", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "A minimalist solution for building micro front-end applications", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -60,3 +60,3 @@ <p align="center"> | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
import VueRouter from 'vue-router' // vue-router@3.x | ||
import MyPage from './my-page.vue' | ||
@@ -196,7 +196,7 @@ | ||
Yes, please see [adapt vite](https://zeroing.jd.com/micro-app/docs.html#/zh-cn/other?id=_3%e3%80%81%e9%80%82%e9%85%8dvite) for details. | ||
Yes, please see [adapt vite](https://zeroing.jd.com/micro-app/docs.html#/zh-cn/advanced?id=_2%e3%80%81%e9%80%82%e9%85%8dvite) for details. | ||
</details> | ||
# Contributors | ||
<!-- opencollective is inaccurate --> | ||
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://opencollective.com/micro-app/contributors.svg?width=890&button=false" /></a> | ||
@@ -203,0 +203,0 @@ |
@@ -63,3 +63,3 @@ <p align="center"> | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
import VueRouter from 'vue-router' // vue-router@3.x | ||
import MyPage from './my-page.vue' | ||
@@ -87,3 +87,3 @@ | ||
<h1>子应用</h1> | ||
<!-- name为应用名称,全局唯一,url为html地址 --> | ||
<!-- name为应用名称,url为html地址 --> | ||
<micro-app name='app1' url='http://localhost:3000/' baseurl='/my-page'></micro-app> | ||
@@ -201,3 +201,3 @@ </div> | ||
支持,详情请查看[适配vite](https://zeroing.jd.com/micro-app/docs.html#/zh-cn/other?id=_3%e3%80%81%e9%80%82%e9%85%8dvite) | ||
支持,详情请查看[适配vite](https://zeroing.jd.com/micro-app/docs.html#/zh-cn/advanced?id=_2%e3%80%81%e9%80%82%e9%85%8dvite) | ||
</details> | ||
@@ -207,2 +207,3 @@ | ||
<!-- opencollective is inaccurate --> | ||
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://opencollective.com/micro-app/contributors.svg?width=890&button=false" /></a> | ||
@@ -209,0 +210,0 @@ |
@@ -11,2 +11,4 @@ declare module '@micro-app/types' { | ||
proxyWindow: WindowProxy | ||
recordUmdEffect: CallableFunction | ||
rebuildUmdEffect: CallableFunction | ||
releaseEffect: CallableFunction | ||
@@ -22,2 +24,4 @@ // Scoped global Properties(Properties that can only get and set in microWindow, will not escape to rawWindow) | ||
stop(): void | ||
recordUmdSnapshot(): void | ||
rebuildUmdSnapshot(): void | ||
inject(microWindow: microWindowType, appName: string, url: string): void | ||
@@ -176,2 +180,5 @@ } | ||
} | ||
// special CallableFunction for interact | ||
type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean } | ||
} | ||
@@ -178,0 +185,0 @@ |
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
702683
3504