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