Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@micro-zoe/micro-app

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@micro-zoe/micro-app - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

2

lib/index.min.js

@@ -1,2 +0,2 @@

"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.1",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;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)}))}})))),r=this.tagName,window.customElements.get(r)?o(`element ${r} is already defined`):window.customElements.define(r,ft)}};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.1";
"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 _(t,n){const o=e.createElement(t,n);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function b(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 A(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 N(t,e,n){const o=R(Array.from(t.cssRules),e);return`@${n} ${t.conditionText} {${o}}`}function R(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+=N(o,e,"media");break;case v.SUPPORTS_RULE:n+=N(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=A(R(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 P=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(P||(P=_("style"),P.setAttribute("id","micro-app-template-style"),e.body.appendChild(P),P.sheet.disabled=!0),t.textContent)P.textContent=t.textContent,M(P,t,t.textContent,r,o.url,t.linkpath),P.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 S(t,e){Object.defineProperties(t,{currentTarget:{get:()=>e},srcElement:{get:()=>e},target:{get:()=>e}})}function D(t){const e=new CustomEvent("load");S(e,t),"function"==typeof t.onload?t.onload(e):t.dispatchEvent(e)}function L(t){const e=new CustomEvent("error");S(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=_("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=_("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.__MICRO_APP_PROXY_WINDOW__=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}const G=Element.prototype.setAttribute,H=Node.prototype.appendChild,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=_("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((()=>D(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((()=>D(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),D(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((()=>D(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((()=>D(i))),W(t,n,o,e.module,!0)}let s;return s=o.inline?_("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)}D(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.2",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=_("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;return t.mount(null!==(e=this.shadowRoot)&&void 0!==e?e:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var t;const e=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"),baseroute:this.getBaseRouteCompatible()});Yt.set(this.appName,e)}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)}getBaseRouteCompatible(){var t,e;return null!==(e=null!==(t=this.getAttribute("baseroute"))&&void 0!==t?t:this.getAttribute("baseurl"))&&void 0!==e?e:""}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 _t(t,e){return"string"==typeof t&&t?e?`__from_base_app_${t}__`:`__from_micro_app_${t}__`:""}class bt{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 bt{addDataListener(t,e,n){yt.on(_t(t,!1),e,n)}removeDataListener(t,e){"function"==typeof e&&yt.off(_t(t,!1),e)}getData(t,e=!1){return yt.getData(_t(t,e))}setData(t,e){yt.dispatch(_t(t,!0),e)}clearDataListener(t){yt.off(_t(t,!1))}}class Et extends bt{constructor(t){super(),this.appName=t}addDataListener(t,e){t.__AUTO_TRIGGER__=e,yt.on(_t(this.appName,!0),t,e)}removeDataListener(t){"function"==typeof t&&yt.off(_t(this.appName,!0),t)}getData(){return yt.getData(_t(this.appName,!0))}dispatch(t){m(),yt.dispatch(_t(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(_t(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;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)}))}})))),r=this.tagName,window.customElements.get(r)?o(`element ${r} is already defined`):window.customElements.define(r,ft)}};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 At(t,e){const o=function(t){const e=_("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 Nt=new WeakMap;const Rt=new WeakMap;const Mt=new WeakMap;function Pt(t,e){if(Mt.has(e))return Mt.get(e);if(y(e)&&!function(t){if(Rt.has(t))return Rt.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 Rt.set(t,n),n}(e)&&!function(t){if(Nt.has(t))return Nt.get(t);const e=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return Nt.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,St=window.removeEventListener,Dt=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),St.call(window,e,o,r)},t.setInterval=function(t,e,...n){const r=Dt(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)St.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 Pt(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_ROUTE__=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(_t(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,baseroute:a}){this.status=E.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=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)}At(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.baseroute=null!=o?o:this.baseroute,2===this.loadSourceLevel){if(ht(this.container,this.name,w.BEFOREMOUNT),this.status=E.MOUNTING,b(this.source.html,this.container),null===(s=this.sandBox)||void 0===s||s.start(this.baseroute),this.umdHookMount)null===(c=this.sandBox)||void 0===c||c.rebuildUmdSnapshot(),this.umdHookMount();else{!function(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="",b(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=_,exports.removeDomScope=m,exports.version="0.3.2";
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microApp={})}(this,(function(e){"use strict";const t=new Function("return window")(),n=new Function("return document")(),o="0.3.1";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;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)}))}})))),n=this.tagName,window.customElements.get(n)?r(`element ${n} is already defined`):window.customElements.define(n,be)}};function Ne(e,t=null,n={}){return 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})}));
!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.2";function i(e,...t){"string"==typeof e?console.error(`[micro-app] ${e}`,...t):console.error("[micro-app]",e,...t)}function r(e,...t){"string"==typeof e?console.warn(`[micro-app] ${e}`,...t):console.warn("[micro-app]",e,...t)}function s(e,...t){Promise.resolve().then(e.bind(null,...t))}function a(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function c(e){if("string"!=typeof e||!e)return"";try{const{origin:t,pathname:n,search:o}=new URL(a(e));if(/\.(\w+)$/.test(n))return`${t}${n}${o}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${o}`:""}catch(e){return i(e),""}}function l(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function u(e,t){return/^((((ht|f)tps?)|file):)?\/\//.test(e)?e:new URL(e,l(a(t))).toString()}function p(e,t,n,o){let i=0;function r(){++i===e.length&&o&&o()}e.forEach(((e,o)=>{"[object Promise]"===toString.call(e)?e.then((e=>{t({data:e,index:o}),r()})).catch((e=>{n({error:e,index:o}),r()})):(t({data:e,index:o}),r())}))}const d=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)};let h=null;function m(e){h=e}function f(){return h}function y(){m(null)}function _(){return/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)}function b(e){return"function"==typeof e}function g(e,t){const o=n.createElement(e,t);return o.__MICRO_APP_NAME__&&delete o.__MICRO_APP_NAME__,o}function E(e,t){const n=e.cloneNode(!0),o=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{o.appendChild(e)})),t.appendChild(o)}var w,v,O,A;function N(e,t){const{selectorText:n,cssText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(n))return o.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===n)return o.replace("*",`${t} *`);const i=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return o.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>i.test(o)?e.replace(i,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}function R(e,t,n,o){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,i)=>{if(/^data:/.test(i))return e;if(/^(https?:)?\/\//.test(i)){if(!_())return e;{const t=i.replace(/^https?:/,"");if(-1!==n.indexOf(t))return e;i=i.replace(window.location.origin,"")}}return/^((\.\.?\/)|[^/])/.test(i)&&o&&(t=function(e){const t=e.split("/");return t.pop(),a(t.join("/")+"/")}(o)),`url("${u(i,t)}")`}))}function M(e,t,n){const o=P(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}function P(e,t){let n="";for(const o of e)switch(o.type){case A.STYLE_RULE:n+=N(o,t);break;case A.MEDIA_RULE:n+=M(o,t,"media");break;case A.SUPPORTS_RULE:n+=M(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}function C(e,t,n,o,i,r){var s,a;let c=R(P(Array.from(null!==(a=null===(s=e.sheet)||void 0===s?void 0:s.cssRules)&&void 0!==a?a:[]),o),i,n,r);_()&&(c=c.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm,((e,t,n)=>"none"===n||/^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test(n)?e:`${t}"${n}"`))),t.textContent=c}!function(e){e.NAME="name",e.URL="url"}(w||(w={})),function(e){e.NOT_LOADED="NOT_LOADED",e.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",e.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",e.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",e.MOUNTING="MOUNTING",e.MOUNTED="MOUNTED",e.UNMOUNT="UNMOUNT"}(v||(v={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error"}(O||(O={})),function(e){e[e.STYLE_RULE=1]="STYLE_RULE",e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(A||(A={}));let S=n.body.querySelector("#micro-app-template-style");function D(e,t){const o=Xe.get(t);if(null==o?void 0:o.scopecss){const i=`${Oe.tagName}[name=${t}]`;if(S||(S=g("style"),S.setAttribute("id","micro-app-template-style"),n.body.appendChild(S),S.sheet.disabled=!0),e.textContent)S.textContent=e.textContent,C(S,e,e.textContent,i,o.url,e.linkpath),S.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(Ae(e,t.name))}p(r,(e=>{!function(e,t,n,o,i){t.isGlobal&&!T.has(e)&&T.set(e,n);const r=g("style");r.textContent=n,r.linkpath=e,o.replaceChild(D(r,i.name),t.placeholder),t.placeholder=null,t.code=n}(o[e.index][0],o[e.index][1],e.data,n,t)}),(e=>{i(e)}),(()=>{t.onLoad(e)}))}const $=new Map,k="noModule"in document.createElement("script");function W(e,t,n,o=!1){let i=null,r=e.getAttribute("src");if(e.hasAttribute("exclude"))i=document.createComment("script element with exclude attribute ignored by micro-app");else if(k&&e.noModule||!k&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(r){r=u(r,n.url);const t={code:"",isExternal:!0,isDynamic:o,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(o)return{url:r,info:t};n.source.scripts.set(r,t),i=document.createComment(`script with src='${r}' extract by micro-app`)}else if(e.textContent){const t=Math.random().toString(36).substr(2,15),r={code:e.textContent,isExternal:!1,isDynamic:o,async:!1,defer:"module"===e.type,module:"module"===e.type};if(o)return{url:t,info:r};n.source.scripts.set(t,r),i=document.createComment("inline script extract by micro-app")}else i=document.createComment("script ignored by micro-app");return o?{replaceComment:i}:t.replaceChild(i,e)}function B(e,t){const n=Array.from(t.source.scripts.entries()),o=[],r=[];for(const[e,i]of n)if(i.isExternal){const n=$.get(e);n?i.code=n:i.defer||i.async||(o.push(Ae(e,t.name)),r.push([e,i]))}o.length?p(o,(e=>{!function(e,t,n){t.isGlobal&&!$.has(e)&&$.set(e,n);t.code=n}(r[e.index][0],r[e.index][1],e.data)}),(e=>{i(e)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function G(e,t,n,o,i){var r;try{if(t=H(e,t,n),n.inline){const e=g("script");if(o&&e.setAttribute("type","module"),e.textContent=t,i)return e;null===(r=n.container)||void 0===r||r.querySelector("micro-app-body").appendChild(e)}else if(Function(t)(),i)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error("[micro-app from runScript]",e)}}function H(e,n,o){return"object"==typeof 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.__MICRO_APP_PROXY_WINDOW__=o.sandBox.proxyWindow,`;(function(window, self){with(window){;${n}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`):n}const 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?D(t,n.name):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return se.set(t,e),e}if(!n.scopecss)return t;const{url:o,info:r}=j(t,e,n,null,!0);if(o&&r){const e=g("style");return e.linkpath=o,function(e,t,n,o,r){if(n.source.links.has(e))return r.textContent=n.source.links.get(e).code,D(r,n.name),void s((()=>U(o)));if(T.has(e)){const i=T.get(e);return t.code=i,n.source.links.set(e,t),r.textContent=i,D(r,n.name),void s((()=>U(o)))}Ae(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&T.set(e,i),r.textContent=i,D(r,n.name),U(o)})).catch((e=>{i(e),x(o)}))}(o,r,n,t,e),se.set(t,e),e}return t}if(t instanceof HTMLScriptElement){const{replaceComment:o,url:r,info:a}=W(t,e,n,!0);if(r&&a){if(a.code){const e=G(r,a.code,n,a.module,!0);return se.set(t,e),e}{const e=function(e,t,n,o){if(n.source.scripts.has(e)){const i=n.source.scripts.get(e);return s((()=>U(o))),G(e,i.code,n,t.module,!0)}if($.has(e)){const i=$.get(e);return t.code=i,n.source.scripts.set(e,t),s((()=>U(o))),G(e,i,n,t.module,!0)}let r;return r=n.inline?g("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`),Ae(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 _e 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==++_e.microAppCount&&(pe(),function(){if(!me){me=!0;const e=g("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(){_e.microAppCount>0&&(this.handleUnmount(this.getDisposeResult("destory")),0==--_e.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;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreate(){var e;const t=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"),baseroute:this.getBaseRouteCompatible()});Xe.set(this.appName,t)}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)}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?Oe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Oe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}_e.microAppCount=0;const be=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 ge(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),be.on("global",e,t)}removeGlobalDataListener(e){"function"==typeof e&&be.off("global",e)}setGlobalData(e){be.dispatch("global",e)}clearGlobalDataListener(){const e=this.appName,t=be.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){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 ve extends Ee{constructor(e){super(),this.appName=e}addDataListener(e,t){e.__AUTO_TRIGGER__=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=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(){be.off(ge(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;e&&"[object Object]"===toString.call(e)&&(this.shadowDOM=e.shadowDOM,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.macro=e.macro,b(e.fetch)&&(this.fetch=e.fetch),"[object Object]"===toString.call(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),"[object Object]"===toString.call(e.plugins)&&(this.plugins=e.plugins),e.preFetchApps&&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(Ae(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(Ae(e))})),p(n,(t=>{const n=e[t.index];T.has(n)||T.set(n,t.data)}),(e=>{i(e)}))}})))),n=this.tagName,window.customElements.get(n)?r(`element ${n} is already defined`):window.customElements.define(n,_e)}};function Ae(e,t=null,n={}){return b(Oe.fetch)?Oe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}function Ne(e,t,n){const o=Array.from(e.children);o.length&&o.forEach((e=>{Ne(e,t,n)}));for(const i of o)i instanceof HTMLLinkElement?i.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),i):t.scopecss?j(i,e,t,n):i.hasAttribute("href")&&i.setAttribute("href",u(i.getAttribute("href"),t.url)):i instanceof HTMLStyleElement?i.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),i):t.scopecss&&n.appendChild(D(i,t.name)):i instanceof HTMLScriptElement?W(i,e,t):i instanceof HTMLMetaElement||i instanceof HTMLTitleElement?e.removeChild(i):/^(img|iframe)$/i.test(i.tagName)&&i.hasAttribute("src")&&i.setAttribute("src",u(i.getAttribute("src"),t.url))}function Re(e,t){const n=function(e){const t=g("div");return t.innerHTML=e,t}(e),o=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!o||!r){const e=`element ${o?"body":"head"} is missing`;return t.onerror(new Error(e)),i(e)}Ne(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 Pe=new WeakMap;const Ce=new WeakMap;function Se(e,t){if(Ce.has(t))return Ce.get(t);if(b(t)&&!function(e){if(Pe.has(e))return Pe.get(e);const t=e.toString(),n=e.prototype&&e.prototype.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(t)||/^class\s+/.test(t);return Pe.set(e,n),n}(t)&&!function(e){if(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 De=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),De.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 Se(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_ROUTE__=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=be.eventList.get("global");if(n)for(const o of n.callbacks)t===o.__APP_NAME__&&e.umdDataListeners.global.add(o);const o=be.eventList.get(ge(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,baseroute:a}){this.status=v.NOT_LOADED,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookunMount=null,this.isPrefetch=!1,this.container=null,this.macro=!1,this.baseroute="",this.sandBox=null,this.container=null!=n?n:null,this.inline=null!=o&&o,this.baseroute=null!=a?a:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&i,this.macro=null!=s&&s,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ve(e,t,this.macro))}loadSourceCode(){var e;this.status=v.LOADING_SOURCE_CODE,Ae((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)}Re(t=t.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(e=>e.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(e=>e.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),e)})).catch((t=>{i(`Failed to fetch data from ${e.url}, micro-app stop rendering`,t),e.onLoadError(t)}))}onLoad(e){if(2==++this.loadSourceLevel){if(this.source.html=e,this.isPrefetch||v.UNMOUNT===this.status)return;this.status=v.LOAD_SOURCE_FINISHED,this.mount()}}onLoadError(e){this.loadSourceLevel=-1,v.UNMOUNT!==this.status&&(this.onerror(e),this.status=v.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,a,c;if("boolean"==typeof t&&t!==this.inline&&(this.inline=t),this.container=null!==(o=this.container)&&void 0!==o?o:e,this.baseroute=null!=n?n:this.baseroute,2===this.loadSourceLevel){if(fe(this.container,this.name,O.BEFOREMOUNT),this.status=v.MOUNTING,E(this.source.html,this.container),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdHookMount)null===(c=this.sandBox)||void 0===c||c.rebuildUmdSnapshot(),this.umdHookMount();else{!function(e,t){const n=Array.from(e.entries()),o=[],r=[];for(const[e,i]of n)i.isDynamic||(i.defer||i.async?(i.isExternal&&!i.code?o.push(Ae(e,t.name)):o.push(i.code),r.push([e,i])):G(e,i.code,t,i.module,!1));o.length&&Promise.all(o).then((e=>{e.forEach(((e,n)=>{const[o,i]=r[n];G(o,i.code=i.code||e,t,i.module,!1)}))})).catch((e=>{i(e)}))}(this.source.scripts,this);const{mount:e,unmount:t}=this.getUmdLibraryHooks();b(e)&&b(t)&&(this.umdHookMount=e,this.umdHookunMount=t,null===(a=this.sandBox)||void 0===a||a.recordUmdSnapshot(),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}]`))&&D(n,u)})),this.umdHookMount())}var l,u;v.UNMOUNT!==this.status&&(this.status=v.MOUNTED,s((()=>{v.UNMOUNT!==this.status&&fe(this.container,this.name,O.MOUNTED)})))}else this.status=v.LOADING_SOURCE_CODE}unmount(e){var t;this.status===v.LOAD_SOURCE_ERROR&&(e=!0),this.status=v.UNMOUNT,fe(this.container,this.name,O.UNMOUNT),this.umdHookunMount&&this.umdHookunMount(),function(e){const t=new CustomEvent(`unmount-${e}`);window.dispatchEvent(t)}(this.name),null===(t=this.sandBox)||void 0===t||t.stop(),this.container=null,e&&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=g,e.removeDomScope=y,e.version=o,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@micro-zoe/micro-app",
"version": "0.3.1",
"version": "0.3.2",
"description": "A minimalist solution for building micro front-end applications",

@@ -5,0 +5,0 @@ "private": false,

@@ -28,3 +28,3 @@ <p align="center">

English|[简体中文](https://github.com/micro-zoe/micro-app/blob/master/README.zh-cn.md)|[Documentation](https://micro-zoe.github.io/micro-app/)|[Discussions](https://github.com/micro-zoe/micro-app/discussions)|[Gitter](https://gitter.im/microzoe/micro-app)
English|[简体中文](./README.zh-cn.md)|[Documentation](https://micro-zoe.github.io/micro-app/)|[Discussions](https://github.com/micro-zoe/micro-app/discussions)|[Gitter](https://gitter.im/microzoe/micro-app)

@@ -84,4 +84,4 @@ # 📖Introduction

<h1>micro application</h1>
<!-- name is the application name, globally unique, url is the html address -->
<micro-app name='app1' url='http://localhost:3000/' baseurl='/my-page'></micro-app>
<!-- 👇 name is the application name, globally unique, url is the html address -->
<micro-app name='app1' url='http://localhost:3000/' baseroute='/my-page'></micro-app>
</div>

@@ -96,3 +96,3 @@ </template>

1、Add basename for route(If the base application is history route and the micro application is hash route, it is not necessary to set the baseurl, this step can be skipped)
1、Add basename for route(If the base application is history route and the micro application is hash route, it is not necessary to set the baseroute, this step can be skipped)

@@ -105,4 +105,4 @@ ```js

return (
// 👇 the micro application can get the baseurl issued by the base application through window.__MICRO_APP_BASE_URL__
<BrowserRouter basename={window.__MICRO_APP_BASE_URL__ || '/'}>
// 👇 the micro application can get the baseroute issued by the base application through window.__MICRO_APP_BASE_ROUTE__
<BrowserRouter basename={window.__MICRO_APP_BASE_ROUTE__ || '/'}>
<Switch>

@@ -203,6 +203,7 @@ ...

# Contributors
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="./.github/contributors.svg" /></a>
<!-- 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>
<!-- <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> -->
# License
[MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)

@@ -86,4 +86,4 @@ <p align="center">

<h1>子应用</h1>
<!-- name为应用名称,url为html地址 -->
<micro-app name='app1' url='http://localhost:3000/' baseurl='/my-page'></micro-app>
<!-- 👇 name为应用名称,url为html地址 -->
<micro-app name='app1' url='http://localhost:3000/' baseroute='/my-page'></micro-app>
</div>

@@ -106,4 +106,4 @@ </template>

return (
// 👇 添加路由前缀,子应用可以通过window.__MICRO_APP_BASE_URL__获取基座应用下发的baseurl
<BrowserRouter basename={window.__MICRO_APP_BASE_URL__ || '/'}>
// 👇 添加路由前缀,子应用可以通过window.__MICRO_APP_BASE_ROUTE__获取基座应用下发的baseroute
<BrowserRouter basename={window.__MICRO_APP_BASE_ROUTE__ || '/'}>
<Switch>

@@ -205,7 +205,7 @@ ...

# 贡献者们
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="./.github/contributors.svg" /></a>
<!-- 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>
<!-- <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> -->
# License
[MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)

@@ -21,3 +21,3 @@ declare module '@micro-app/types' {

escapeKeys: Set<PropertyKey> // Properties escape to rawWindow, cleared when unmount
start(baseurl: string): void
start(baseroute: string): void
stop(): void

@@ -61,3 +61,3 @@ recordUmdSnapshot(): void

macro: boolean // used to solve the async render problem of vue3, default is false
baseurl: string // route prefix, default is ''
baseroute: string // route prefix, default is ''
source: sourceType // sources of css, js, html

@@ -71,3 +71,3 @@ sandBox: SandBoxInterface | null // sanxbox

inline?: boolean,
baseurl?: string,
baseroute?: string,
): void // mount app

@@ -74,0 +74,0 @@ unmount(destory: boolean): void // unmount app

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc