Socket
Socket
Sign inDemoInstall

@micro-zoe/micro-app

Package Overview
Dependencies
Maintainers
1
Versions
66
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.8.5 to 1.0.0-alpha.0

84

lib/index.d.ts

@@ -14,3 +14,3 @@ /// <reference path="../typings/global.d.ts" />

declare module '@micro-zoe/micro-app/micro_app' {
import type { OptionsType, MicroAppConfigType, lifeCyclesType, plugins, fetchType } from '@micro-app/types';
import type { OptionsType, MicroAppConfigType, lifeCyclesType, plugins, fetchType, Router } from '@micro-app/types';
import preFetch from '@micro-zoe/micro-app/prefetch';

@@ -25,14 +25,14 @@ import { EventCenterForBaseApp } from '@micro-zoe/micro-app/interact';

export function getAllApps(): string[];
export interface unmountAppParams {
type unmountAppOptions = {
destroy?: boolean;
clearAliveState?: boolean;
}
};
/**
* unmount app by appName
* @param appName
* @param options unmountAppParams
* @param options unmountAppOptions
* @returns Promise<void>
*/
export function unmountApp(appName: string, options?: unmountAppParams): Promise<void>;
export function unmountAllApps(options?: unmountAppParams): Promise<void>;
export function unmountApp(appName: string, options?: unmountAppOptions): Promise<void>;
export function unmountAllApps(options?: unmountAppOptions): Promise<void>;
export class MicroApp extends EventCenterForBaseApp implements MicroAppConfigType {

@@ -45,2 +45,3 @@ tagName: string;

disableSandbox?: boolean;
disableMemoryRouter?: boolean;
ssr?: boolean;

@@ -51,2 +52,3 @@ lifeCycles?: lifeCyclesType;

preFetch: typeof preFetch;
router: Router;
start(options?: OptionsType): void;

@@ -67,2 +69,3 @@ }

* disableSandbox?: boolean,
* disableMemoryRouter?: boolean,
* },

@@ -73,3 +76,3 @@ * ...

* 1: preFetch is asynchronous and is performed only when the browser is idle
* 2: disableScopecss, disableSandbox must be same with micro-app element, if conflict, the one who executes first shall prevail
* 2: disableScopecss, disableSandbox, disableMemoryRouter must be same with micro-app element, if conflict, the one who executes first shall prevail
* @param apps micro apps

@@ -86,6 +89,18 @@ */

declare module '@micro-zoe/micro-app/libs/utils' {
import type { Func } from '@micro-app/types';
import type { Func, LocationQueryObject, MicroLocation } from '@micro-app/types';
export const version = "__MICRO_APP_VERSION__";
export const isBrowser: boolean;
export const globalThis: any;
export const noop: () => void;
export const noopFalse: () => boolean;
export const isArray: (arg: any) => arg is any[];
export const assign: {
<T, U>(target: T, source: U): T & U;
<T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
<T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
(target: object, ...sources: any[]): any;
};
export const rawDefineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any;
export const rawDefineProperties: (o: any, properties: PropertyDescriptorMap & ThisType<any>) => any;
export const rawHasOwnProperty: (v: string | number | symbol) => boolean;
export function isUndefined(target: unknown): target is undefined;

@@ -95,11 +110,8 @@ export function isNull(target: unknown): target is null;

export function isBoolean(target: unknown): target is boolean;
export function isFunction(target: unknown): boolean;
export const isArray: (arg: any) => arg is any[];
export function isPlainObject(target: unknown): boolean;
export function isPromise(target: unknown): boolean;
export function isBoundFunction(target: any): boolean;
export function isShadowRoot(target: unknown): boolean;
export const rawDefineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any;
export const rawDefineProperties: (o: any, properties: PropertyDescriptorMap & ThisType<any>) => any;
export const rawHasOwnProperty: (v: string | number | symbol) => boolean;
export function isFunction(target: unknown): target is Function;
export function isPlainObject(target: unknown): target is Record<PropertyKey, unknown>;
export function isPromise(target: unknown): target is Promise<unknown>;
export function isBoundFunction(target: unknown): target is Function;
export function isShadowRoot(target: unknown): target is ShadowRoot;
export function isURL(target: unknown): target is URL;
/**

@@ -110,3 +122,3 @@ * format error log

*/
export function logError(msg: unknown, appName?: string | null, ...rest: any[]): void;
export function logError(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
/**

@@ -117,3 +129,3 @@ * format warn log

*/
export function logWarn(msg: unknown, appName?: string | null, ...rest: any[]): void;
export function logWarn(msg: unknown, appName?: string | null, ...rest: unknown[]): void;
/**

@@ -124,4 +136,8 @@ * async execution

*/
export function defer(fn: Func, ...args: any[]): void;
export function defer(fn: Func, ...args: unknown[]): void;
/**
* create URL as MicroLocation
*/
export const createURL: (p: string | URL, b?: string | undefined) => MicroLocation;
/**
* Add address protocol

@@ -146,2 +162,3 @@ * @param url address

* 5. plugins
* 6. router api (push, replace)
*/

@@ -206,2 +223,29 @@ export function formatAppName(name: string | null): string;

export function isFireFox(): boolean;
/**
* Transforms a queryString into object.
* @param search - search string to parse
* @returns a query object
*/
export function parseQuery(search: string): LocationQueryObject;
/**
* Transforms an object to query string
* @param queryObject - query object to stringify
* @returns query string without the leading `?`
*/
export function stringifyQuery(queryObject: LocationQueryObject): string;
/**
* Register or unregister callback/guard with Set
*/
export function useSetRecord<T>(): {
add: (handler: T) => () => boolean;
list: () => Set<T>;
};
/**
* record data with Map
*/
export function useMapRecord<T>(): {
add: (key: PropertyKey, value: T) => () => boolean;
get: (key: PropertyKey) => T | undefined;
delete: (key: PropertyKey) => boolean;
};
}

@@ -208,0 +252,0 @@

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function n(e){return"string"==typeof e}function s(e){return"boolean"==typeof e}function i(e){return"function"==typeof e}const o=Array.isArray;function r(e){return"[object Object]"===toString.call(e)}function a(e){return"[object Promise]"===toString.call(e)}function c(e){return i(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const l=Object.defineProperty,h=Object.defineProperties,u=Object.prototype.hasOwnProperty;function p(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.error(`[micro-app]${i} ${e}`,...s):console.error(`[micro-app]${i}`,e,...s)}function d(e,t=null,...s){const i=t&&n(t)?` app ${t}:`:"";n(e)?console.warn(`[micro-app]${i} ${e}`,...s):console.warn(`[micro-app]${i}`,e,...s)}function m(e,...t){Promise.resolve().then(e.bind(null,...t))}function f(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function _(e,t=null){if(!n(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(f(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return p(e,t),""}}function A(e){return n(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function b(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 g(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,b(f(t))).toString()}function w(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{a(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const y=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let E=null;function v(e){E=e}function N(e){E!==e&&(v(e),m((()=>{v(null)})))}function C(){return E}function R(){v(null)}function D(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function P(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function M(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function O(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function S(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function I(e){return e?e.replace(/^\s+|\s+$/g,""):""}function L(){return navigator.userAgent.indexOf("Firefox")>-1}var U,x,T,k;!function(e){e.NAME="name",e.URL="url"}(U||(U={})),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"}(x||(x={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(T||(T={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}(k||(k={}));const W="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function $(e,t=null,n={}){return i(Qe.fetch)?Qe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const B=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,F=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function H(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class K{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),L()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&"}"!==this.cssText.charAt(0)&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):H("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=I(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||B.test(n)||(n=F.test(n)?n.replace(F,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||H("Declaration missing '}'",this.linkPath)):H("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),f(t.join("/")+"/")}(this.linkPath)),`url("${g(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return H("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return H("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):H("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):H(`@${t} missing '}'`,this.linkPath)):H(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):H(`@${e} missing '}'`,this.linkPath)):H(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if("/"!==this.cssText.charAt(0)||"*"!==this.cssText.charAt(1))return!1;this.scopecssDisableNextLine=!1;let e=2;for(;""!==this.cssText.charAt(e)&&("*"!==this.cssText.charAt(e)||"/"!==this.cssText.charAt(e+1));)++e;if(e+=2,""===this.cssText.charAt(e-1))return H("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=I(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(I(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){L()?this.result+=encodeURIComponent(e):this.result+=e}}function j(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=G.exec(e.textContent,n,s,i),G.reset()}catch(e){G.reset(),p("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let G;function V(e,t){if(t.scopecss){const n=`${Qe.tagName}[name=${t.name}]`;if(G||(G=new K),e.textContent)j(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&j(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function q(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function z(e){const t=new CustomEvent("load");q(t,e),i(e.onload)?e.onload(t):e.dispatchEvent(t)}function Q(e){const t=new CustomEvent("error");q(t,e),i(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const J=new Map;function X(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=g(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",g(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function Y(e,t,n){const s=Array.from(t.source.links.entries());w(s.map((([e])=>J.has(e)?J.get(e):$(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!J.has(e)&&J.set(e,n);const o=D("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(V(o,i),t.placeholder):s.appendChild(V(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)}))}const Z=new WeakMap;function ee(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 Z.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?V(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return Z.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=X(t,e,n,!0);if(s&&i){const e=D("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,V(i,n),void m((()=>z(s)));if(J.has(e)){const o=J.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,V(i,n),void m((()=>z(s)))}$(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&J.set(e,o),i.textContent=o,V(i,n),z(s)})).catch((e=>{p(e,n.name),Q(s)}))}(s,i,n,t,e),Z.set(t,e),e}return o?(Z.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=me(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>z(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&m(i),_e(e,n,t,!0,i)}if(de.has(e)){const s=de.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&m(i),_e(e,n,t,!0,i)}let o;o=n.inline||t.module?D("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return $(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&de.set(e,r);try{r=ge(e,n,r,t),n.inline||t.module?Ae(e,r,t.module,o,i):be(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&z(s)})).catch((e=>{p(e,n.name),Q(s)})),o}(i,o,n,t);return Z.set(t,e),e}{const e=_e(i,n,o,!0);return Z.set(t,e),e}}return s?(Z.set(t,s),s):t}return t}function te(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?ue.rawAppendChild.call(o,s):t!==ue.rawRemoveChild||o.contains(s)?t===ue.rawAppend||t===ue.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?ue.rawAppendChild.call(o,s):t!==ue.rawRemoveChild||o.contains(s)?t===ue.rawAppend||t===ue.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===ue.rawAppend||t===ue.rawPrepend?t.call(n,s):t.call(n,s,i)}function ne(e){var t;return null!==(t=Z.get(e))&&void 0!==t?t:e}function se(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Fe.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?te(i,s,e,ee(e,t,i),n&&ne(n)):s===ue.rawAppend||s===ue.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===ue.rawAppend||s===ue.rawPrepend){const n=C();if(!(t instanceof Node)&&n){const i=Fe.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function ie(){!function(){const e=ue.rawDocument;function t(t){var n,s,i;const o=C();return o&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Fe.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:ue.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=C();return o&&t&&!O(t)&&e===this?null!==(i=null===(s=null===(n=Fe.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:ue.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return oe(ue.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return oe(ue.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return oe(ue.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!C()||M(e))return ue.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return ue.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!C()||M(e))return ue.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return ue.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=C();if(!s||O(e)||M(e)||!(null===(t=Fe.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return ue.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return ue.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!C()||M(e))return ue.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return ue.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return se(this,e,null,ue.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return se(this,e,t,ue.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return se(this,e,t,ue.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)se(this,e[t],null,ue.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)se(this,e[t-1],null,ue.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Fe.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?te(t,ue.rawRemoveChild,this,ne(e)):ue.rawRemoveChild.call(this,e)}return ue.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=ue.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function oe(e){const t=C();return t&&(e.__MICRO_APP_NAME__=t),e}let re=!1;function ae(){v(null),Document.prototype.createElement=ue.rawCreateElement,Document.prototype.createElementNS=ue.rawCreateElementNS,Document.prototype.createDocumentFragment=ue.rawCreateDocumentFragment,Document.prototype.querySelector=ue.rawQuerySelector,Document.prototype.querySelectorAll=ue.rawQuerySelectorAll,Document.prototype.getElementById=ue.rawGetElementById,Document.prototype.getElementsByClassName=ue.rawGetElementsByClassName,Document.prototype.getElementsByTagName=ue.rawGetElementsByTagName,Document.prototype.getElementsByName=ue.rawGetElementsByName,Element.prototype.appendChild=ue.rawAppendChild,Element.prototype.insertBefore=ue.rawInsertBefore,Element.prototype.replaceChild=ue.rawReplaceChild,Element.prototype.removeChild=ue.rawRemoveChild,Element.prototype.append=ue.rawAppend,Element.prototype.prepend=ue.rawPrepend,Element.prototype.cloneNode=ue.rawCloneNode}let ce=!1;function le(){he(),Fe.forEach((e=>{e.container&&S(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Fe.clear()}function he(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",le,!1)}const ue={};function pe(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=C(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,R=b.clearInterval,P=b.clearTimeout,M=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(ue,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:R,rawClearTimeout:P,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:O}),function(){if(!ce){ce=!0;const e=D("style");ue.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Qe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,ue.rawDocument.head.appendChild(e)}}(),he(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",le,!1)}}const de=new Map;function me(e,t,n,s=!1){let i=null,o=e.getAttribute("src");if(e.hasAttribute("exclude"))i=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(ue.supportModuleScript&&e.noModule||!ue.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(o){o=g(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function fe(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=de.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push($(e,t.name)),i.push([e,o]))}s.length?w(s,(e=>{!function(e,t,n){t.isGlobal&&!de.has(e)&&de.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{p(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function _e(e,t,n,s,i){var o;try{const r=ge(e,t,n.code,n);if(t.inline||n.module){const a=D("script");if(Ae(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(be(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Ae(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function be(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ge(e,t,n,s){return r(Qe.plugins)&&(n=function(e,t,n,s,i){var o;const r=we(s.global,t,e,i);return we(null===(o=s.modules)||void 0===o?void 0:o[n],r,e,i)}(e,n,t.name,Qe.plugins,s)),t.sandBox&&!s.module?(ue.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${W}){;${n}\n}).call(proxyWindow,${W})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function we(e,t,n,s){return o(e)?e.reduce(((e,t)=>r(t)&&i(t.loader)?t.loader(e,n,t.options,s):e),t):t}function ye(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{ye(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",g(n.getAttribute("href"),t.url)):X(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&V(n,t):n instanceof HTMLScriptElement?me(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",g(n.getAttribute("src"),t.url))}function Ee(e,t){const n=function(e){const t=D("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),p(e,t.name)}ye(n,t),t.source.links.size?Y(n,t,s):t.onLoad(n),t.source.scripts.size?fe(n,t):t.onLoad(n)}const ve=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(p("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!i(t))return p("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(i(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!r(t))return p("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 Ne(e,t){return n(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Ce{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),ve.on("global",e,t)}removeGlobalDataListener(e){i(e)&&ve.off("global",e)}setGlobalData(e){R(),ve.dispatch("global",e)}getGlobalData(){return ve.getData("global")}clearGlobalDataListener(){const e=this.appName,t=ve.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 Re extends Ce{addDataListener(e,t,n){ve.on(Ne(A(e),!1),t,n)}removeDataListener(e,t){i(t)&&ve.off(Ne(A(e),!1),t)}getData(e,t=!1){return ve.getData(Ne(A(e),t))}setData(e,t){ve.dispatch(Ne(A(e),!0),t)}clearDataListener(e){ve.off(Ne(A(e),!1))}}class De extends Ce{constructor(e){super(),this.appName=A(e),!this.appName&&p(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,ve.on(Ne(this.appName,!0),e,t)}removeDataListener(e){i(e)&&ve.off(Ne(this.appName,!0),e)}getData(){return ve.getData(Ne(this.appName,!0))}dispatch(e){R(),ve.dispatch(Ne(this.appName,!1),e);const t=Fe.get(this.appName);if((null==t?void 0:t.container)&&r(e)){const n=new CustomEvent("datachange",{detail:{data:e}});S(t.container).dispatchEvent(n)}}clearDataListener(){ve.off(Ne(this.appName,!0))}}function Pe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(s(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),i=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=i}(t)&&!function(e){return s(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=c(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&l(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Me=new Map;let Oe=!1;const Se=new Map;function Ie(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=ue;!Oe&&function(){if(Oe=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return d("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Me.forEach((t=>{i(t)&&t.call(document,e)}))}l(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=C();return e?Me.get(e):Me.get("base")},set(e){const s=C();s?Me.set(s,e):Me.set("base",e),!t&&i(e)&&(t=!0,ue.rawDocumentAddEventListener.call(ue.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=C();if(r&&(!(null===(o=Fe.get(r))||void 0===o?void 0:o.umdMode)||!c(s))){const e=Se.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Se.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=C();if(r&&(!(null===(o=Fe.get(r))||void 0===o?void 0:o.umdMode)||!c(s))){const e=Se.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const Le=["unmount","appstate-change"];function Ue(e,t){return Le.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const xe=["System","__cjsWrapper"],Te=["location"],ke=["window","self","globalThis"];class We{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=ue;e.addEventListener=function(t,s,i){t=Ue(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=Ue(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Me.get(t);const e=Se.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Me.set(t,_),v(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),v(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Me.delete(t);const e=Se.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,ue.rawWindow._babelPolyfill&&(ue.rawWindow._babelPolyfill=!1),1==++We.activeCount&&(Ie(),ie()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(ue.rawWindow,e)})),this.escapeKeys.clear(),0==--We.activeCount&&(document.addEventListener=ue.rawDocumentAddEventListener,document.removeEventListener=ue.rawDocumentRemoveEventListener,ae()))}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=ve.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=ve.eventList.get(Ne(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,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.microAppWindow.microApp)}getSpecialProperties(e){var t;r(Qe.plugins)&&(this.commonActionForSpecialProperties(Qe.plugins.global),this.commonActionForSpecialProperties(null===(t=Qe.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(o(e))for(const t of e)r(t)&&(o(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),o(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=ue.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(s,o)=>{if(N(e),Reflect.has(s,o)||n(o)&&/^__MICRO_APP_/.test(o)||this.scopeProperties.includes(o))return Reflect.get(s,o);const r=Reflect.get(t,o);return i(r)?Pe(t,r):r},set:(e,n,s)=>{if(this.active){if(Te.includes(n))Reflect.set(t,n,s);else if(u.call(e,n)||!u.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;l(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||xe.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,n)=>{if(u.call(e,n))return s.set(n,"target"),Object.getOwnPropertyDescriptor(e,n);if(u.call(t,n)){s.set(n,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,n);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,n,i)=>"rawWindow"===s.get(n)?Reflect.defineProperty(t,n,i):Reflect.defineProperty(e,n,i),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)=>!u.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=b(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new De(t),{removeDomScope:R,pureCreateElement:D}),e.rawWindow=ue.rawWindow,e.rawDocument=ue.rawDocument,e.hasOwnProperty=t=>u.call(e,t)||u.call(ue.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=ue.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),l(e,"top",this.createDescriptorForMicroAppWindow("top",t)),l(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),ke.forEach((t=>{l(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(ue.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;h(e,{document:{get:()=>(N(t),ue.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(N(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(N(t),s||ue.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function $e(e,t,n,s){var o;if(!e)return p(`element does not exist in lifecycle ${n}`,t);e=S(e),R();const r=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:r});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),i(null===(o=Qe.lifeCycles)||void 0===o?void 0:o[n])&&Qe.lifeCycles[n](a),e.dispatchEvent(a)}function Be(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}We.activeCount=0;const Fe=new Map;class He{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=x.NOT_LOADED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new We(e,t))}loadSourceCode(){var e;this.state=x.LOADING_SOURCE_CODE,$((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),p(t,e.name)}Ee(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=>{p(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):x.UNMOUNT!==this.state&&(this.state=x.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),x.UNMOUNT!==this.state&&(this.onerror(e),this.state=x.LOAD_SOURCE_ERROR)}mount(e,t,n){var o,r,a;if(s(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(o=this.container)&&void 0!==o?o:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=x.LOADING_SOURCE_CODE);let c;if($e(this.container,this.name,T.BEFOREMOUNT),this.state=x.MOUNTING,P(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push($(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(_e(e,t,r,!1),n(!1)));i.length?w(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,p(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(_e(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===n.moduleCount||n.errorCount===i.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(i(e)&&i(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){p("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){a(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){x.UNMOUNT!==this.state&&(this.state=x.MOUNTED,$e(this.container,this.name,T.MOUNTED))}unmount(e,t){let n;if(this.state===x.LOAD_SOURCE_ERROR&&(e=!0),this.state=x.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){p("an error occurred in the unmount function \n",this.name,e)}Be("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){a(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&P(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),Ve().length||(re=!1,Element.prototype.setAttribute=ue.rawSetAttribute),$e(this.container,this.name,T.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Fe.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;P(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=k.KEEP_ALIVE_HIDDEN,Be("appstate-change",this.name,{appState:"afterhidden"}),$e(e,this.name,T.AFTERHIDDEN)}showKeepAliveApp(e){Be("appstate-change",this.name,{appState:"beforeshow"}),$e(e,this.name,T.BEFORESHOW),P(this.container,e,!1),this.container=e,this.keepAliveState=k.KEEP_ALIVE_SHOW,Be("appstate-change",this.name,{appState:"aftershow"}),$e(this.container,this.name,T.AFTERSHOW)}onerror(e){$e(this.container,this.name,T.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(x.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:ue.rawWindow;return this.libraryName=S(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Ke(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="0.8.5",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=A(this.getAttribute("name")),t=_(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Fe.get(e);if(e!==this.appName&&n&&x.UNMOUNT!==n.getAppState()&&k.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),p(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},re||(re=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(r(t)){const e={};Object.getOwnPropertyNames(t).forEach((s=>{n(s)&&0===s.indexOf("__")||(e[s]=t[s])})),this.data=e}else"[object Object]"!==t&&d("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Fe.has(this.__MICRO_APP_NAME__)){const n=Fe.get(this.__MICRO_APP_NAME__);ue.rawSetAttribute.call(this,e,g(t,n.url))}else ue.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,m((()=>$e(this,this.appName,T.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===U.NAME?"appName":"appUrl"]!==n)if(e!==U.URL||this.appUrl)if(e!==U.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,m(this.handleAttributeUpdate));else{const e=A(n);if(!e)return p(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Qe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=_(n,this.appName)))return p(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&i(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=g(ue.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Fe.has(this.appName)){const e=Fe.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==x.UNMOUNT?e.isPrefetch||e.getAppState()===x.UNMOUNT?(d(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):p(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=g(ue.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):p(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!n(t)||!t)||(p(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,m((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Fe.has(this.appName)&&Fe.get(this.appName).actionsForCompletelyDestroy();const t=new He({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),baseroute:this.getBaseRouteCompatible()});Fe.set(this.appName,t)}handleUnmount(e,t){const n=Fe.get(this.appName);n&&n.getAppState()!==x.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Fe.get(this.appName);e&&e.getAppState()!==x.UNMOUNT&&e.getKeepAliveState()!==k.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){m((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Qe[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}set data(e){this.appName?Qe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Qe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function je(t){if(!e)return p("preFetch is only supported in browser environment");y((()=>{i(t)&&(t=t()),o(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{y((()=>{var n,s;if(r(e)&&navigator.onLine)if(e.name=A(e.name),e.url=_(e.url,e.name),e.name&&e.url&&!Fe.has(e.name)){const i=new He({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Qe.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Qe.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Fe.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Ge(e,t,s){if(o(e)){const i=e.filter((e=>n(e)&&e.includes(`.${t}`)&&!s.has(e)));w(i.map((e=>$(e))),(e=>{const t=i[e.index];s.has(t)||s.set(t,e.data)}),(e=>{p(e)}))}}function Ve(e){const t=[];return Fe.forEach(((n,s)=>{x.UNMOUNT===n.getAppState()||n.isPrefetch||e&&k.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function qe(e,t){const n=Fe.get(A(e));return new Promise((s=>{if(n)if(n.getAppState()===x.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===k.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=S(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else d(`app ${e} does not exist`),s()}))}class ze extends Re{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=je}start(t){if(!e||!window.customElements)return p("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return p(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return d(`element ${this.tagName} is already defined`);if(pe(),t&&r(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.ssr=t.ssr,i(t.fetch)&&(this.fetch=t.fetch),r(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&je(t.preFetchApps),t.globalAssets&&(r(n=t.globalAssets)&&y((()=>{Ge(n.js,"js",de),Ge(n.css,"css",J)}))),r(t.plugins))){const e=t.plugins.modules;if(r(e))for(const t in e){const n=A(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;Ke(this.tagName)}}var Qe=new ze;exports.EventCenterForMicroApp=De,exports.MicroApp=ze,exports.default=Qe,exports.getActiveApps=Ve,exports.getAllApps=function(){return Array.from(Fe.keys())},exports.preFetch=je,exports.pureCreateElement=D,exports.removeDomScope=R,exports.unmountAllApps=function(e){return Array.from(Fe.keys()).reduce(((t,n)=>t.then((()=>qe(n,e)))),Promise.resolve())},exports.unmountApp=qe,exports.version="0.8.5";
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")(),n=()=>{},s=()=>!1,o=Array.isArray,i=Object.assign,r=Object.defineProperty,a=Object.defineProperties,c=Object.prototype.hasOwnProperty;function l(e){return void 0===e}function h(e){return null===e}function u(e){return"string"==typeof e}function p(e){return"boolean"==typeof e}function d(e){return"function"==typeof e}function m(e){return"[object Object]"===toString.call(e)}function f(e){return"[object Promise]"===toString.call(e)}function _(e){return d(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function g(e){return e instanceof URL}function A(e,t=null,...n){const s=t&&u(t)?` app ${t}:`:"";u(e)?console.error(`[micro-app]${s} ${e}`,...n):console.error(`[micro-app]${s}`,e,...n)}function w(e,t=null,...n){const s=t&&u(t)?` app ${t}:`:"";u(e)?console.warn(`[micro-app]${s} ${e}`,...n):console.warn(`[micro-app]${s}`,e,...n)}function y(e,...t){Promise.resolve().then(e.bind(null,...t))}const b=function(){class e extends URL{}return(t,n)=>n?new e(""+t,n):new e(""+t)}();function v(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function E(e,t=null){if(!u(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=b(v(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const o=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(o)?`${o}${s}`:""}catch(e){return A(e,t),""}}function R(e){return u(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function P(e){const{origin:t,pathname:n}=b(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function N(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:b(e,P(v(t))).toString()}function C(e,t,n,s){let o=0;function i(){++o===e.length&&s&&s()}e.forEach(((e,s)=>{f(e)?e.then((e=>{t({data:e,index:s}),i()})).catch((e=>{n({error:e,index:s}),i()})):(t({data:e,index:s}),i())}))}const M=t.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let S=null;function D(e){S=e}function O(e){S!==e&&(D(e),y((()=>{D(null)})))}function x(){return S}function I(){D(null)}function L(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function U(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function T(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function W(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function k(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function B(e){return e?e.replace(/^\s+|\s+$/g,""):""}function $(){return navigator.userAgent.indexOf("Firefox")>-1}function F(e){const t={},n=e.split("&");for(const e of n){const n=e.indexOf("="),s=n<0?e:e.slice(0,n),i=n<0?null:e.slice(n+1);if(s in t){let e=t[s];o(e)||(e=t[s]=[e]),e.push(i)}else t[s]=i}return t}function H(e){let t="";for(const n in e){const s=e[n];if(h(s))t+=(t.length?"&":"")+n;else{(o(s)?s:[s]).forEach((e=>{l(e)||(t+=(t.length?"&":"")+n,h(e)||(t+="="+e))}))}}return t}function K(){const e=new Set;return{add:function(t){return e.add(t),()=>!!e.has(t)&&e.delete(t)},list:()=>e}}var j,G,Q,V;!function(e){e.NAME="name",e.URL="url"}(j||(j={})),function(e){e.CREATED="created",e.LOADING="loading",e.LOADED="loaded",e.LOAD_FAILED="load_failed",e.MOUNTING="mounting",e.MOUNTED="mounted",e.UNMOUNT="unmount"}(G||(G={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(Q||(Q={})),function(e){e.KEEP_ALIVE_SHOW="keep_alive_show",e.KEEP_ALIVE_HIDDEN="keep_alive_hidden"}(V||(V={}));const q="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,navigator,undefined,location,history,EventSource,fetch,XMLHttpRequest";function z(e,t=null,n={}){return d(kt.fetch)?kt.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const X=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,Y=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function J(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class Z{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),$()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&"}"!==this.cssText.charAt(0)&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):J("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=B(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||X.test(n)||(n=Y.test(n)?n.replace(Y,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||J("Declaration missing '}'",this.linkPath)):J("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),v(t.join("/")+"/")}(this.linkPath)),`url("${N(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return J("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return J("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):J("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):J(`@${t} missing '}'`,this.linkPath)):J(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):J(`@${e} missing '}'`,this.linkPath)):J(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if("/"!==this.cssText.charAt(0)||"*"!==this.cssText.charAt(1))return!1;this.scopecssDisableNextLine=!1;let e=2;for(;""!==this.cssText.charAt(e)&&("*"!==this.cssText.charAt(e)||"/"!==this.cssText.charAt(e+1));)++e;if(e+=2,""===this.cssText.charAt(e-1))return J("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=B(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(B(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){$()?this.result+=encodeURIComponent(e):this.result+=e}}function ee(e,t,n,s,o){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let i=null;try{i=te.exec(e.textContent,n,s,o),te.reset()}catch(e){te.reset(),A("An error occurred while parsing CSS:\n",t,e)}i&&(e.textContent=i)}}let te;function ne(e,t){if(t.scopecss){const n=`${kt.tagName}[name=${t.name}]`;if(te||(te=new Z),e.textContent)ee(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&ee(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function se(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function oe(e){const t=new CustomEvent("load");se(t,e),d(e.onload)?e.onload(t):e.dispatchEvent(t)}function ie(e){const t=new CustomEvent("error");se(t,e),d(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const re=new Map;function ae(e,t,n,s=!1){const o=e.getAttribute("rel");let i=e.getAttribute("href"),r=null;if("stylesheet"===o&&i){if(i=N(i,n.url),s)return{url:i,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else o&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(o)?s?r=document.createComment(`link element with rel=${o}${i?" & href="+i:""} removed by micro-app`):t.removeChild(e):i&&e.setAttribute("href",N(i,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ce(e,t,n){const s=Array.from(t.source.links.entries());C(s.map((([e])=>re.has(e)?re.get(e):z(e,t.name))),(e=>{!function(e,t,n,s,o){t.isGlobal&&!re.has(e)&&re.set(e,n);const i=L("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=e,i.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(ne(i,o),t.placeholder):s.appendChild(ne(i,o));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{A(e,t.name)}),(()=>{t.onLoad(e)}))}const le=new WeakMap;function he(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude")){const e=document.createComment("style element with exclude attribute ignored by micro-app");return le.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?ne(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return le.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:o,replaceComment:i}=ae(t,e,n,!0);if(s&&o){const e=L("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,o){if(n.source.links.has(e))return o.textContent=n.source.links.get(e).code,ne(o,n),void y((()=>oe(s)));if(re.has(e)){const i=re.get(e);return t.code=i,n.source.links.set(e,t),o.textContent=i,ne(o,n),void y((()=>oe(s)))}z(e,n.name).then((i=>{t.code=i,n.source.links.set(e,t),t.isGlobal&&re.set(e,i),o.textContent=i,ne(o,n),oe(s)})).catch((e=>{A(e,n.name),ie(s)}))}(s,o,n,t,e),le.set(t,e),e}return i?(le.set(t,i),i):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:o,info:i}=Ee(t,e,n,!0)||{};if(o&&i){if(i.isExternal){const e=function(e,t,n,s){const o=()=>oe(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&y(o),Pe(e,n,t,!0,o)}if(ve.has(e)){const s=ve.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&y(o),Pe(e,n,t,!0,o)}let i;i=n.inline||t.module?L("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return z(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&ve.set(e,r);try{r=Me(e,n,r,t),n.inline||t.module?Ne(e,r,t.module,i,o):Ce(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&oe(s)})).catch((e=>{A(e,n.name),ie(s)})),i}(o,i,n,t);return le.set(t,e),e}{const e=Pe(o,n,i,!0);return le.set(t,e),e}}return s?(le.set(t,s),s):t}return t}function ue(e,t,n,s,o){const i=function(e,t){var n,s;if(e===document.head)return null===(n=null==t?void 0:t.container)||void 0===n?void 0:n.querySelector("micro-app-head");if(e===document.body)return null===(s=null==t?void 0:t.container)||void 0===s?void 0:s.querySelector("micro-app-body");return null}(n,e);return i?o&&!i.contains(o)?ye.rawAppendChild.call(i,s):t!==ye.rawRemoveChild||i.contains(s)?pe(t,i,s,o):n.contains(s)?t.call(n,s):s:pe(t,n,s,o)}function pe(e,t,n,s){return(o=e)===ye.rawAppend||o===ye.rawPrepend?e.call(t,n):e.call(t,n,s);var o}function de(e){var t;return null!==(t=le.get(e))&&void 0!==t?t:e}function me(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const o=Dt.get(t.__MICRO_APP_NAME__);return(null==o?void 0:o.container)?ue(o,s,e,he(e,t,o),n&&de(n)):s===ye.rawAppend||s===ye.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===ye.rawAppend||s===ye.rawPrepend){const n=x();if(!(t instanceof Node)&&n){const o=Dt.get(n);if(null==o?void 0:o.container){if(e===document.head)return s.call(o.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(o.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function fe(){!function(){const e=ye.rawDocument;function t(t){var n,s,o,i;const r=x();return r&&(null===(n=Dt.get(r))||void 0===n?void 0:n.container)&&t&&!W(t)&&e===this?null!==(i=null===(o=null===(s=Dt.get(r))||void 0===s?void 0:s.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==i?i:null:ye.rawQuerySelector.call(this,t)}function n(t){var n,s,o,i;const r=x();return r&&(null===(n=Dt.get(r))||void 0===n?void 0:n.container)&&t&&!W(t)&&e===this?null!==(i=null===(o=null===(s=Dt.get(r))||void 0===s?void 0:s.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==i?i:[]:ye.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return _e(ye.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return _e(ye.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return _e(ye.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!x()||T(e))return ye.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return ye.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!x()||T(e))return ye.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return ye.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=x();if(!s||W(e)||T(e)||!(null===(t=Dt.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return ye.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return ye.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!x()||T(e))return ye.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return ye.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return me(this,e,null,ye.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return me(this,e,t,ye.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return me(this,e,t,ye.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)me(this,e[t],null,ye.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)me(this,e[t-1],null,ye.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Dt.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?ue(t,ye.rawRemoveChild,this,de(e)):ye.rawRemoveChild.call(this,e)}return ye.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=ye.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function _e(e){const t=x();return t&&(e.__MICRO_APP_NAME__=t),e}let ge=!1;function Ae(){D(null),Document.prototype.createElement=ye.rawCreateElement,Document.prototype.createElementNS=ye.rawCreateElementNS,Document.prototype.createDocumentFragment=ye.rawCreateDocumentFragment,Document.prototype.querySelector=ye.rawQuerySelector,Document.prototype.querySelectorAll=ye.rawQuerySelectorAll,Document.prototype.getElementById=ye.rawGetElementById,Document.prototype.getElementsByClassName=ye.rawGetElementsByClassName,Document.prototype.getElementsByTagName=ye.rawGetElementsByTagName,Document.prototype.getElementsByName=ye.rawGetElementsByName,Element.prototype.appendChild=ye.rawAppendChild,Element.prototype.insertBefore=ye.rawInsertBefore,Element.prototype.replaceChild=ye.rawReplaceChild,Element.prototype.removeChild=ye.rawRemoveChild,Element.prototype.append=ye.rawAppend,Element.prototype.prepend=ye.rawPrepend,Element.prototype.cloneNode=ye.rawCloneNode}let we=!1;const ye={};function be(){if(e){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,o=Element.prototype.removeChild,r=Element.prototype.append,a=Element.prototype.prepend,c=Element.prototype.cloneNode,l=Document.prototype.createElement,h=Document.prototype.createElementNS,u=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,m=Document.prototype.getElementById,f=Document.prototype.getElementsByClassName,_=Document.prototype.getElementsByTagName,g=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=x(),n}}),w=Function("return window")(),y=Function("return document")(),b="noModule"in document.createElement("script"),v=w.addEventListener,E=w.removeEventListener,R=w.setInterval,P=w.setTimeout,N=w.clearInterval,C=w.clearTimeout,M=y.addEventListener,S=y.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,i(ye,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:o,rawAppend:r,rawPrepend:a,rawCloneNode:c,rawCreateElement:l,rawCreateElementNS:h,rawCreateDocumentFragment:u,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:m,rawGetElementsByClassName:f,rawGetElementsByTagName:_,rawGetElementsByName:g,ImageProxy:A,rawWindow:w,rawDocument:y,supportModuleScript:b,rawWindowAddEventListener:v,rawWindowRemoveEventListener:E,rawSetInterval:R,rawSetTimeout:P,rawClearInterval:N,rawClearTimeout:C,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:S}),function(){if(!we){we=!0;const e=L("style");ye.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${kt.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,ye.rawDocument.head.appendChild(e)}}()}}const ve=new Map;function Ee(e,t,n,s=!1){let o=null,i=e.getAttribute("src");if(e.hasAttribute("exclude"))o=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(ye.supportModuleScript&&e.noModule||!ye.supportModuleScript&&"module"===e.type)o=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(i){i=N(i,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:i,info:t};n.source.scripts.set(i,t),o=document.createComment(`script with src='${i}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),i={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:i};n.source.scripts.set(t,i),o=document.createComment("inline script extract by micro-app")}else s||(o=document.createComment("script element removed by micro-app"))}return s?{replaceComment:o}:t.replaceChild(o,e)}function Re(e,t){const n=Array.from(t.source.scripts.entries()),s=[],o=[];for(const[e,i]of n)if(i.isExternal){const n=ve.get(e);n?i.code=n:(!i.defer&&!i.async||t.isPrefetch)&&(s.push(z(e,t.name)),o.push([e,i]))}s.length?C(s,(e=>{!function(e,t,n){t.isGlobal&&!ve.has(e)&&ve.set(e,n);t.code=n}(o[e.index][0],o[e.index][1],e.data)}),(e=>{A(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Pe(e,t,n,s,o){var i;try{const r=Me(e,t,n.code,n);if(t.inline||n.module){const a=L("script");if(Ne(e,r,n.module,a,o),s)return a;null===(i=t.container)||void 0===i||i.querySelector("micro-app-body").appendChild(a)}else if(Ce(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Ne(e,t,n,s,o){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),o&&(o.moduleCount&&o.moduleCount--,s.onload=o.bind(s,0===o.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function Ce(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function Me(e,t,n,s){return m(kt.plugins)&&(n=function(e,t,n,s,o){var i;const r=Se(s.global,t,e,o);return Se(null===(i=s.modules)||void 0===i?void 0:i[n],r,e,o)}(e,n,t.name,kt.plugins,s)),t.sandBox&&!s.module?(ye.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${q}){;${n}\n}).call(proxyWindow,${q})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Se(e,t,n,s){return o(e)?e.reduce(((e,t)=>m(t)&&d(t.loader)?t.loader(e,n,t.options,s):e),t):t}function De(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{De(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",N(n.getAttribute("href"),t.url)):ae(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&ne(n,t):n instanceof HTMLScriptElement?Ee(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",N(n.getAttribute("src"),t.url))}function Oe(e,t){const n=function(e){const t=L("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),o=n.querySelector("micro-app-body");if(!s||!o){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),A(e,t.name)}De(n,t),t.source.links.size?ce(n,t,s):t.onLoad(n),t.source.scripts.size?Re(n,t):t.onLoad(n)}const xe=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(A("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!d(t))return A("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(d(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!m(t))return A("event-center: data must be object");let n=this.eventList.get(e);if(n){if(n.data!==t){n.data=t;for(const e of n.callbacks)e(t)}}else n={data:t,callbacks:new Set},this.eventList.set(e,n)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function Ie(e,t){return u(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Le{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),xe.on("global",e,t)}removeGlobalDataListener(e){d(e)&&xe.off("global",e)}setGlobalData(e){I(),xe.dispatch("global",e)}getGlobalData(){return xe.getData("global")}clearGlobalDataListener(){const e=this.appName,t=xe.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 Ue extends Le{addDataListener(e,t,n){xe.on(Ie(R(e),!1),t,n)}removeDataListener(e,t){d(t)&&xe.off(Ie(R(e),!1),t)}getData(e,t=!1){return xe.getData(Ie(R(e),t))}setData(e,t){xe.dispatch(Ie(R(e),!0),t)}clearDataListener(e){xe.off(Ie(R(e),!1))}}class Te extends Le{constructor(e){super(),this.appName=R(e),!this.appName&&A(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,xe.on(Ie(this.appName,!0),e,t)}removeDataListener(e){d(e)&&xe.off(Ie(this.appName,!0),e)}getData(){return xe.getData(Ie(this.appName,!0))}dispatch(e){I(),xe.dispatch(Ie(this.appName,!1),e);const t=Dt.get(this.appName);if((null==t?void 0:t.container)&&m(e)){const n=new CustomEvent("datachange",{detail:{data:e}});k(t.container).dispatchEvent(n)}}clearDataListener(){xe.off(Ie(this.appName,!0))}}function We(){Dt.forEach((e=>{e.container&&k(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Dt.clear()}function ke(){window.__MICRO_APP_ENVIRONMENT__&&(window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",We,!1),window.addEventListener("unmount",We,!1))}function Be(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(p(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),s=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=s}(t)&&!function(e){return p(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=_(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&r(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const $e=["unmount","appstate-change"];function Fe(e,t){var n;return $e.includes(e)||("popstate"===e||"hashchange"===e)&&(null===(n=Dt.get(t))||void 0===n?void 0:n.useMemoryRouter)?`${e}-${t}`:e}const He=new Map;let Ke=!1;const je=new Map;function Ge(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=ye;!Ke&&function(){if(Ke=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return w("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){He.forEach((t=>{d(t)&&t.call(document,e)}))}r(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=x();return e?He.get(e):He.get("base")},set(e){const s=x();s?He.set(s,e):He.set("base",e),!t&&d(e)&&(t=!0,ye.rawDocumentAddEventListener.call(ye.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,o){var i;const r=x();if(r&&(!(null===(i=Dt.get(r))||void 0===i?void 0:i.umdMode)||!_(s))){const e=je.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else je.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=o)}t.call(e,n,s,o)},document.removeEventListener=function(t,s,o){var i;const r=x();if(r&&(!(null===(i=Dt.get(r))||void 0===i?void 0:i.umdMode)||!_(s))){const e=je.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,o)}}function Qe(e,t,n){const s={microAppState:i({},null==t?void 0:t.microAppState,{[e]:n})};return i({},t,s)}function Ve(e,t){var n;return(null===(n=null==t?void 0:t.microAppState)||void 0===n?void 0:n[e])||null}const qe=/&/g,ze=/=/g,Xe=/%M1/g,Ye=/%M2/g;function Je(e){return encodeURIComponent(et(e).replace(qe,"%M1").replace(ze,"%M2"))}function Ze(e){return et(e).replace(Xe,"&").replace(Ye,"=")}function et(e){try{const t=decodeURIComponent(e);return e===t||Xe.test(t)||Ye.test(t)?t:et(t)}catch(t){return e}}function tt(e){return`app-${e}`}function nt(e){var t,n;const s=ye.rawWindow.location,o=ot(s.search,s.hash),i=(null===(t=o.hashQuery)||void 0===t?void 0:t[tt(e)])||(null===(n=o.searchQuery)||void 0===n?void 0:n[tt(e)]);return u(i)?Ze(i):null}function st(e,t){let{pathname:n,search:s,hash:o}=ye.rawWindow.location;const i=ot(s,o),r=Je(t.pathname+t.search+t.hash);let a=!1;if(o&&!s){a=!0,i.hashQuery?i.hashQuery[tt(e)]=r:i.hashQuery={[tt(e)]:r};const t=o.includes("?")?o.slice(0,o.indexOf("?")+1):o+"?";o=t+H(i.hashQuery)}else i.searchQuery?i.searchQuery[tt(e)]=r:i.searchQuery={[tt(e)]:r},s="?"+H(i.searchQuery);return{fullPath:n+s+o,isAttach2Hash:a}}function ot(e,t){const n={};return""!==e&&"?"!==e&&(n.searchQuery=F(e.slice(1))),t.includes("?")&&(n.hashQuery=F(t.slice(t.indexOf("?")+1))),n}function it(e){const t=ye.rawWindow,n=n=>{if(Ut(!0).includes(e)&&!n.onlyForBrowser){const n=nt(e),s=Dt.get(e).sandBox.proxyWindow;let o=!1;const i=s.location.href;if(n){const t=s.location.hash;yt(e,n,s.location),o=s.location.hash!==t}!function(e,t,n){const s=new PopStateEvent(Fe("popstate",e),{state:Ve(e,n)});ye.rawWindow.dispatchEvent(s),"function"==typeof t.onpopstate&&t.onpopstate(s)}(e,s,t.history.state),o&&function(e,t,n){const s=new HashChangeEvent(Fe("hashchange",e),{newURL:t.location.href,oldURL:n});ye.rawWindow.dispatchEvent(s),"function"==typeof t.onhashchange&&t.onhashchange(s)}(e,s,i),I()}};return t.addEventListener("popstate",n),()=>{t.removeEventListener("popstate",n)}}function rt(e,t){I(),function(e){const t=new PopStateEvent("popstate",{state:null});e&&(t.onlyForBrowser=!0),ye.rawWindow.dispatchEvent(t)}(e),t&&function(e){const t=new HashChangeEvent("hashchange",{newURL:ye.rawWindow.location.href,oldURL:e});ye.rawWindow.dispatchEvent(t)}(t)}function at(e,t){const n=ye.rawWindow.history;return new Proxy(n,{get(s,o){return"state"===o?Ve(e,n.state):d(Reflect.get(s,o))?(i=o,function(...s){if("pushState"!==i&&"replaceState"!==i||!u(s[2])&&!g(s[2]))n[i].apply(n,s);else{const o=b(s[2],t.href);if(o.origin===t.origin){lt(i,st(e,o),!0,Qe(e,n.state,s[0]),s[1]);const r=o.pathname+o.search+o.hash;r!==t.fullPath&&yt(e,r,t)}else n[i].apply(n,s)}}):Reflect.get(s,o);var i},set:(e,t,n)=>Reflect.set(e,t,n)})}function ct(e,t,n=null,s=""){ye.rawWindow.history[e](n,s,t)}function lt(e,t,n,s,o){const i=ye.rawWindow.location,r=i.pathname+i.search+i.hash,a=t.isAttach2Hash&&r!==t.fullPath?i.href:null;ct(e,t.fullPath,s,o),r!==t.fullPath&&rt(n,a)}function ht(e,t){lt("replaceState",e,!0,t)}function ut(e){const t=ye.rawWindow;return function(...n){var s;if((null===(s=t.history.state)||void 0===s?void 0:s.microAppState)&&(!m(n[0])||!n[0].microAppState)&&(u(n[2])||g(n[2]))){const e=t.location.href;b(n[2],e).href===e&&(n[0]=i({},n[0],{microAppState:t.history.state.microAppState}))}e.apply(t.history,n)}}let pt=!1;const{router:dt,executeNavigationGuard:mt,clearRouterWhenUnmount:ft}=function(){function e(e,t,n,s){lt(t,st(e,n),!1,Qe(e,ye.rawWindow.history.state,null!=s?s:null)),I()}function t(t){return function(n){const s=R(n.name);if(s&&u(n.path)){const o=Dt.get(s);if(o&&!o.sandBox)return A(`navigation failed, sandBox of app ${s} is closed`);if(Ut().includes(s)){const i=o.sandBox.proxyWindow.location,r=b(n.path,i.href),a=r.pathname+r.search+r.hash;if(i.fullPath!==a||nt(s)!==a){e(s,t&&!1!==n.replace||!0===n.replace?"replaceState":"pushState",r,n.state)}}else{const t=ye.rawWindow.location,o=b(n.path,t.origin),i=o.pathname+o.search+o.hash;nt(s)!==i&&e(s,!1===n.replace?"pushState":"replaceState",o,n.state)}}else A("navigation failed, name & path are required when use router."+(t?"replace":"push"))}}function n(e){return function(...t){return ye.rawWindow.history[e](...t)}}const o=K(),i=K();function r(e,t,n,s){I();for(const o of s)d(o)?o(e,t,n):m(o)&&d(o[e])&&o[e](t,n)}const a=function(){const e=new Map;return{add:function(t,n){return e.set(t,n),()=>!!e.has(t)&&e.delete(t)},get:t=>e.get(t),delete:t=>!!e.has(t)&&e.delete(t)}}(),c={current:new Map,encode:Je,decode:Ze,push:t(!1),replace:t(!0),go:n("go"),back:n("back"),forward:n("forward"),beforeEach:o.add,afterEach:i.add,setDefaultPage:function(e,t){return(e=R(e))?a.add(e,t):s},removeDefaultPage:function(e){return!!(e=R(e))&&a.delete(e)},getDefaultPage:a.get};return{router:c,executeNavigationGuard:function(e,t,n){c.current.set(e,t),r(e,t,n,o.list()),M((()=>{r(e,t,n,i.list())}))},clearRouterWhenUnmount:function(e){c.current.delete(e)}}}(),_t=["href","pathname","search","hash"],gt=[..._t,"host","hostname","port","protocol","search"],At=[...gt,"origin","fullPath"];function wt(e,t){const n=i({name:e},t);for(const e of At)n[e]=t[e];return n}function yt(e,t,n,s){const o=b(t,n.href),i=wt(e,n);for(const e of gt)_t.includes(e)?n.shadowLocation[e]=o[e]:n[e]=o[e];const r=wt(e,n);("auto"===s||i.fullPath!==r.fullPath&&"prevent"!==s)&&mt(e,r,i)}function bt(e,t){!function(){if(!pt&&!window.__MICRO_APP_ENVIRONMENT__){pt=!0;const e=ye.rawWindow;e.history.pushState=ut(e.history.pushState),e.history.replaceState=ut(e.history.replaceState)}}();const s=function(e,t){const s=ye.rawWindow.location,o=b(t),r={href:o.href,pathname:o.pathname,search:o.search,hash:o.hash},c=(t,n)=>{const i=b(t,o.href);if(i.origin===o.origin){const o=st(e,i);if(i.pathname===r.pathname&&i.search===r.search){let e=null;return i.hash!==r.hash&&(o.isAttach2Hash&&(e=s.href),ct(n,o.fullPath)),void(i.hash?rt(!1,e):s.reload())}if(o.isAttach2Hash)return ct(n,o.fullPath),void s.reload();t=o.fullPath}return t};function l(e,t){return{enumerable:!0,configurable:!0,get:e,set:t}}function h(n,o){const i=b(n,t);i[o]===r[o]&&r.hash?rt(!1):(ct(i[o]===r[o]?"replaceState":"pushState",st(e,i).fullPath),s.reload())}a(o,{href:l((()=>r.href),(e=>{const t=c(e,"pushState");t&&(s.href=t)})),pathname:l((()=>r.pathname),(e=>{h(("/"+e).replace(/^\/+/,"/")+r.search+r.hash,"pathname")})),search:l((()=>r.search),(e=>{h(r.pathname+("?"+e).replace(/^\?+/,"?")+r.hash,"search")})),hash:l((()=>r.hash),(n=>{const s=r.pathname+r.search+("#"+n).replace(/^#+/,"#"),o=b(s,t);o.hash!==r.hash&&lt("pushState",st(e,o),!1)})),fullPath:l((()=>r.pathname+r.search+r.hash),n)});const u=e=>function(t){const n=c(t,"assign"===e?"pushState":"replaceState");n&&s[e](n)};return i(o,{assign:u("assign"),replace:u("replace"),reload:e=>s.reload(e),shadowLocation:r})}(e,t);return{microLocation:s,microHistory:at(e,s)}}function vt(e,t,n){n&&yt(e,n,t,"prevent"),ht(st(e,t),Qe(e,ye.rawWindow.history.state,null)),function(e,t){mt(e,wt(e,t),wt(e,t))}(e,t)}function Et(e){ht(function(e,t){var n,s,o,i;let{pathname:r,search:a,hash:c}=t||ye.rawWindow.location;const l=ot(a,c);let h=!1;if(null===(n=l.hashQuery)||void 0===n?void 0:n[tt(e)]){h=!0,null===(s=l.hashQuery)||void 0===s||delete s[tt(e)];const t=H(l.hashQuery);c=c.slice(0,c.indexOf("?")+Number(Boolean(t)))+t}else if(null===(o=l.searchQuery)||void 0===o?void 0:o[tt(e)]){null===(i=l.searchQuery)||void 0===i||delete i[tt(e)];const t=H(l.searchQuery);a=t?"?"+t:""}return{fullPath:r+a+c,isAttach2Hash:h}}(e),function(e,t){return m(null==t?void 0:t.microAppState)&&(l(t.microAppState[e])||delete t.microAppState[e],Object.keys(t.microAppState).length||delete t.microAppState),i({},t)}(e,ye.rawWindow.history.state))}const Rt=["__REACT_ERROR_OVERLAY_GLOBAL_HOOK__","System","__cjsWrapper"],Pt=["location"],Nt=["window","self","globalThis"];class Ct{constructor(e,t,n=!0){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t,n),i(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,o=new Map,{rawWindow:i,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=ye;e.addEventListener=function(e,s,o){e=Fe(e,t);const r=n.get(e);r?r.add(s):n.set(e,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=o),a.call(i,e,s,o)},e.removeEventListener=function(e,s,o){e=Fe(e,t);const r=n.get(e);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(i,e,s,o)},e.setInterval=function(e,t,...n){const o=l.call(i,e,t,...n);return s.set(o,{handler:e,timeout:t,args:n}),o},e.setTimeout=function(e,t,...n){const s=h.call(i,e,t,...n);return o.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(i,e)},e.clearTimeout=function(e){o.delete(e),p.call(i,e)};const m=new Map,f=new Map;let _,g=new Map,A=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(g=new Map(s)),o.size&&(A=new Map(o)),_=He.get(t);const e=je.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),g.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),A.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&He.set(t,_),D(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),D(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(i,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(i,t)})),s.clear()),o.size&&(o.forEach(((e,t)=>{p.call(i,t)})),o.clear()),He.delete(t);const e=je.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e,t=!0,n=""){this.active||(this.active=!0,t?(this.initRouteState(n),this.removeHistoryListener=it(this.proxyWindow.__MICRO_APP_NAME__)):this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,1==++Ct.activeCount&&(Ge(),fe(),ke()),ye.rawWindow._babelPolyfill&&(ye.rawWindow._babelPolyfill=!1))}stop(e=!1){this.active&&(this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(ye.rawWindow,e)})),this.escapeKeys.clear(),this.removeHistoryListener&&(this.clearRouteState(e),this.removeHistoryListener()),0==--Ct.activeCount&&(document.addEventListener=ye.rawDocumentAddEventListener,document.removeEventListener=ye.rawDocumentRemoveEventListener,Ae()),this.active=!1)}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=xe.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=xe.eventList.get(Ie(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,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.microAppWindow.microApp)}getSpecialProperties(e){var t;m(kt.plugins)&&(this.commonActionForSpecialProperties(kt.plugins.global),this.commonActionForSpecialProperties(null===(t=kt.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(o(e))for(const t of e)m(t)&&(o(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),o(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=ye.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,s)=>{if(O(e),Reflect.has(n,s)||u(s)&&/^__MICRO_APP_/.test(s)||this.scopeProperties.includes(s))return Reflect.get(n,s);const o=Reflect.get(t,s);return d(o)?Be(t,o):o},set:(e,n,s)=>{if(this.active){if(Pt.includes(n))Reflect.set(t,n,s);else if(c.call(e,n)||!c.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const o=Object.getOwnPropertyDescriptor(t,n),{configurable:i,enumerable:a,writable:c,set:l}=o;r(e,n,{value:s,configurable:i,enumerable:a,writable:null!=c?c:!!l}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||Rt.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,s)=>{if(c.call(e,s))return n.set(s,"target"),Object.getOwnPropertyDescriptor(e,s);if(c.call(t,s)){n.set(s,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,s);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,s,o)=>"rawWindow"===n.get(s)?Reflect.defineProperty(t,s,o):Reflect.defineProperty(e,s,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)=>!c.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n,s){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_URL__=n,e.__MICRO_APP_PUBLIC_PATH__=P(n),e.__MICRO_APP_WINDOW__=e,e.microApp=i(new Te(t),{removeDomScope:I,pureCreateElement:L,router:dt}),e.rawWindow=ye.rawWindow,e.rawDocument=ye.rawDocument,e.hasOwnProperty=t=>c.call(e,t)||c.call(ye.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t),s&&this.setRouterApi(e,t,n)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=ye.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),r(e,"top",this.createDescriptorForMicroAppWindow("top",t)),r(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Nt.forEach((t=>{r(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:o,set:i}=Object.getOwnPropertyDescriptor(ye.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=o?o:!!i}}setHijackProperties(e,t){let n,s;a(e,{document:{configurable:!1,enumerable:!0,get:()=>(O(t),ye.rawDocument)},eval:{configurable:!0,enumerable:!1,get:()=>(O(t),n||eval),set:e=>{n=e}},Image:{configurable:!0,enumerable:!1,get:()=>(O(t),s||ye.ImageProxy),set:e=>{s=e}}})}setRouterApi(e,t,n){const{microLocation:s,microHistory:o}=bt(t,n);a(e,{location:{configurable:!1,enumerable:!0,get:()=>s,set:e=>{ye.rawWindow.location=e}},history:{configurable:!0,enumerable:!0,get:()=>o}})}initRouteState(e){!function(e,t,n){const s=nt(e);s?yt(e,s,t,"auto"):vt(e,t,n)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location,e)}clearRouteState(e){!function(e,t,n,s){if(!s){const{pathname:s,search:o,hash:i}=b(t);yt(e,s+o+i,n,"prevent")}Et(e),ft(e)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.__MICRO_APP_URL__,this.proxyWindow.location,e)}setRouteInfoForKeepAliveApp(){vt(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location)}removeRouteInfoForKeepAliveApp(){Et(this.proxyWindow.__MICRO_APP_NAME__)}}function Mt(e,t,n,s){var o;if(!e)return A(`element does not exist in lifecycle ${n}`,t);e=k(e),I();const r=i({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:r});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),d(null===(o=kt.lifeCycles)||void 0===o?void 0:o[n])&&kt.lifeCycles[n](a),e.dispatchEvent(a)}function St(e,t,n={}){const s=new CustomEvent(Fe(e,t),{detail:n});window.dispatchEvent(s)}Ct.activeCount=0;const Dt=new Map;class Ot{constructor({name:e,url:t,ssrUrl:n,container:s,inline:o,scopecss:i,useSandbox:r,useMemoryRouter:a,baseroute:c,keepRouteState:l,defaultPage:h}){this.state=G.CREATED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=o&&o,this.baseroute=null!=c?c:"",this.keepRouteState=null!=l&&l,this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&i,this.useMemoryRouter=this.useSandbox&&a,this.defaultPage=null!=h?h:"",this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Ct(e,t,this.useMemoryRouter))}loadSourceCode(){var e;this.state=G.LOADING,z((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),A(t,e.name)}Oe(t=t.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(e=>e.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(e=>e.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),e)})).catch((t=>{A(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):G.UNMOUNT!==this.state&&(this.state=G.LOADED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),G.UNMOUNT!==this.state&&(this.onerror(e),this.state=G.LOAD_FAILED)}mount(e,t,n,s,o){var i,r,a;if(p(t)&&(this.inline=t),p(s)&&(this.keepRouteState=s),this.container=null!==(i=this.container)&&void 0!==i?i:e,this.baseroute=null!=n?n:this.baseroute,this.defaultPage=null!=o?o:this.defaultPage,2!==this.loadSourceLevel)return void(this.state=G.LOADING);let c;if(Mt(this.container,this.name,Q.BEFOREMOUNT),this.state=G.MOUNTING,U(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute,this.useMemoryRouter,this.defaultPage),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){A("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),o=[],i=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?o.push(z(e,t.name)):o.push(r.code),i.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Pe(e,t,r,!1),n(!1)));o.length?C(o,(e=>{const t=i[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,A(e,t.name)}),(()=>{i.forEach((([e,s])=>{s.code&&(Pe(e,t,s,!1,n),!s.module&&n(!1))})),n(l(n.moduleCount)||n.errorCount===o.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(d(e)&&d(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){A("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){f(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){G.UNMOUNT!==this.state&&(this.state=G.MOUNTED,Mt(this.container,this.name,Q.MOUNTED))}unmount(e,t){let n;if(this.state===G.LOAD_FAILED&&(e=!0),this.state=G.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){A("an error occurred in the unmount function \n",this.name,e)}St("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){f(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&U(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(this.keepRouteState&&!e),Ut().length||(ge=!1,Element.prototype.setAttribute=ye.rawSetAttribute),Mt(this.container,this.name,Q.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Dt.delete(this.name)}hiddenKeepAliveApp(){var e;const t=this.container;U(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=V.KEEP_ALIVE_HIDDEN,St("appstate-change",this.name,{appState:"afterhidden"}),Mt(t,this.name,Q.AFTERHIDDEN),null===(e=this.sandBox)||void 0===e||e.removeRouteInfoForKeepAliveApp()}showKeepAliveApp(e){var t;St("appstate-change",this.name,{appState:"beforeshow"}),Mt(e,this.name,Q.BEFORESHOW),U(this.container,e,!1),this.container=e,this.keepAliveState=V.KEEP_ALIVE_SHOW,null===(t=this.sandBox)||void 0===t||t.setRouteInfoForKeepAliveApp(),St("appstate-change",this.name,{appState:"aftershow"}),Mt(this.container,this.name,Q.AFTERSHOW)}onerror(e){Mt(this.container,this.name,Q.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(G.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:ye.rawWindow;return this.libraryName=k(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function xt(e){class t extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version="1.0.0-alpha.0",this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=R(this.getAttribute("name")),t=E(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Dt.get(e);if(e!==this.appName&&n&&G.UNMOUNT!==n.getAppState()&&V.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),A(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},ge||(ge=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(m(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{u(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&w("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Dt.has(this.__MICRO_APP_NAME__)){const n=Dt.get(this.__MICRO_APP_NAME__);ye.rawSetAttribute.call(this,e,N(t,n.url))}else ye.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,y((()=>Mt(this,this.appName,Q.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1;const e=Dt.get(this.appName);e&&e.getAppState()!==G.UNMOUNT&&e.getKeepAliveState()!==V.KEEP_ALIVE_HIDDEN&&(this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult()))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===j.NAME?"appName":"appUrl"]!==n)if(e!==j.URL||this.appUrl)if(e!==j.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,y(this.handleAttributeUpdate));else{const e=R(n);if(!e)return A(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(kt.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=E(n,this.appName)))return A(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&d(this.attachShadow)&&this.attachShadow({mode:"open"}),this.updateSsrUrl(this.appUrl),Dt.has(this.appName)){const e=Dt.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===V.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==G.UNMOUNT?e.isPrefetch||e.getAppState()===G.UNMOUNT?(w(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):A(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.updateSsrUrl(t),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===V.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):A(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!u(t)||!t)||(A(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,y((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible(),this.getDisposeResult("keep-router-state"),this.getDefaultPageValue())}))}handleCreateApp(){var e;Dt.has(this.appName)&&Dt.get(this.appName).actionsForCompletelyDestroy();const t=new Ot({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),useMemoryRouter:!this.getDisposeResult("disable-memory-router"),baseroute:this.getBaseRouteCompatible(),keepRouteState:this.getDisposeResult("keep-router-state"),defaultPage:this.getDefaultPageValue()});Dt.set(this.appName,t)}handleUnmount(e,t){const n=Dt.get(this.appName);n&&n.getAppState()!==G.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Dt.get(this.appName);e&&e.getAppState()!==G.UNMOUNT&&e.getKeepAliveState()!==V.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){y((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||kt[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}updateSsrUrl(e){if(this.getDisposeResult("ssr"))if(this.getDisposeResult("disable-memory-router")){const t=ye.rawWindow.location;this.ssrUrl=N(t.pathname+t.search,e)}else{let t=function(e,t){const n=nt(e);if(!n)return"";const s=b(n,t);return s.origin+s.pathname+s.search}(this.appName,e);const n=this.getDefaultPageValue();if(!t&&n){const s=b(n,e);t=s.origin+s.pathname+s.search}this.ssrUrl=t}else this.ssrUrl&&(this.ssrUrl="")}getDefaultPageValue(){var e,t,n;return null!==(n=null!==(t=null!==(e=dt.getDefaultPage(this.appName))&&void 0!==e?e:this.getAttribute("default-page"))&&void 0!==t?t:this.getAttribute("defaultPage"))&&void 0!==n?n:""}set data(e){this.appName?kt.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?kt.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,t)}function It(t){if(!e)return A("preFetch is only supported in browser environment");M((()=>{d(t)&&(t=t()),o(t)&&t.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{M((()=>{var n,s,o;if(m(e)&&navigator.onLine)if(e.name=R(e.name),e.url=E(e.url,e.name),e.name&&e.url&&!Dt.has(e.name)){const i=new Ot({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:kt.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:kt.disableSandbox),useMemoryRouter:!(null!==(o=e.disableMemoryRouter)&&void 0!==o?o:kt.disableMemoryRouter)});i.isPrefetch=!0,i.prefetchResolve=t,Dt.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Lt(e,t,n){if(o(e)){const s=e.filter((e=>u(e)&&e.includes(`.${t}`)&&!n.has(e)));C(s.map((e=>z(e))),(e=>{const t=s[e.index];n.has(t)||n.set(t,e.data)}),(e=>{A(e)}))}}function Ut(e){const t=[];return Dt.forEach(((n,s)=>{G.UNMOUNT===n.getAppState()||n.isPrefetch||e&&V.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Tt(e,t){const n=Dt.get(R(e));return new Promise((s=>{if(n)if(n.getAppState()===G.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===V.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=k(n.container),o=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",i),s()},i=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",i),s()};if(e.addEventListener("unmount",o),e.addEventListener("afterhidden",i),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else w(`app ${e} does not exist`),s()}))}class Wt extends Ue{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=It,this.router=dt}start(t){if(!e||!window.customElements)return A("micro-app is not supported in this environment");if(null==t?void 0:t.tagName){if(!/^micro-app(-\S+)?/.test(t.tagName))return A(`${t.tagName} is invalid tagName`);this.tagName=t.tagName}if(window.customElements.get(this.tagName))return w(`element ${this.tagName} is already defined`);if(be(),t&&m(t)&&(this.shadowDOM=t.shadowDOM,this.destroy=t.destroy,this.destory=t.destory,this.inline=t.inline,this.disableScopecss=t.disableScopecss,this.disableSandbox=t.disableSandbox,this.disableMemoryRouter=t.disableMemoryRouter,this.ssr=t.ssr,d(t.fetch)&&(this.fetch=t.fetch),m(t.lifeCycles)&&(this.lifeCycles=t.lifeCycles),t.preFetchApps&&It(t.preFetchApps),t.globalAssets&&(m(n=t.globalAssets)&&M((()=>{Lt(n.js,"js",ve),Lt(n.css,"css",re)}))),m(t.plugins))){const e=t.plugins.modules;if(m(e))for(const t in e){const n=R(t);n&&t!==n&&(e[n]=e[t],delete e[t])}this.plugins=t.plugins}var n;xt(this.tagName)}}var kt=new Wt;exports.EventCenterForMicroApp=Te,exports.MicroApp=Wt,exports.default=kt,exports.getActiveApps=Ut,exports.getAllApps=function(){return Array.from(Dt.keys())},exports.preFetch=It,exports.pureCreateElement=L,exports.removeDomScope=I,exports.unmountAllApps=function(e){return Array.from(Dt.keys()).reduce(((t,n)=>t.then((()=>Tt(n,e)))),Promise.resolve())},exports.unmountApp=Tt,exports.version="1.0.0-alpha.0";
//# sourceMappingURL=index.min.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microApp={})}(this,(function(e){"use strict";const t="0.8.5",n="undefined"!=typeof window,s="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")();function i(e){return"string"==typeof e}function o(e){return"boolean"==typeof e}function r(e){return"function"==typeof e}const a=Array.isArray;function c(e){return"[object Object]"===toString.call(e)}function l(e){return"[object Promise]"===toString.call(e)}function h(e){return r(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}const u=Object.defineProperty,p=Object.defineProperties,d=Object.prototype.hasOwnProperty;function m(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.error(`[micro-app]${s} ${e}`,...n):console.error(`[micro-app]${s}`,e,...n)}function f(e,t=null,...n){const s=t&&i(t)?` app ${t}:`:"";i(e)?console.warn(`[micro-app]${s} ${e}`,...n):console.warn(`[micro-app]${s}`,e,...n)}function _(e,...t){Promise.resolve().then(e.bind(null,...t))}function A(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function b(e,t=null){if(!i(e)||!e)return"";try{const{origin:t,pathname:n,search:s}=new URL(A(e));if(/\.(\w+)$/.test(n))return`${t}${n}${s}`;const i=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${s}`:""}catch(e){return m(e,t),""}}function g(e){return i(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function w(e){const{origin:t,pathname:n}=new URL(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function y(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:new URL(e,w(A(t))).toString()}function E(e,t,n,s){let i=0;function o(){++i===e.length&&s&&s()}e.forEach(((e,s)=>{l(e)?e.then((e=>{t({data:e,index:s}),o()})).catch((e=>{n({error:e,index:s}),o()})):(t({data:e,index:s}),o())}))}const v=s.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let N=null;function C(e){N=e}function R(e){N!==e&&(C(e),_((()=>{C(null)})))}function D(){return N}function P(){C(null)}function M(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function O(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),s=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{s.appendChild(e)})),t.appendChild(s)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function S(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function I(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function L(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function U(e){return e?e.replace(/^\s+|\s+$/g,""):""}function x(){return navigator.userAgent.indexOf("Firefox")>-1}var T,k,W,$;!function(e){e.NAME="name",e.URL="url"}(T||(T={})),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"}(k||(k={})),function(e){e.CREATED="created",e.BEFOREMOUNT="beforemount",e.MOUNTED="mounted",e.UNMOUNT="unmount",e.ERROR="error",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(W||(W={})),function(e){e.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",e.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"}($||($={}));const B="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function F(e,t=null,n={}){return r(Xe.fetch)?Xe.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const H=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,K=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function j(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class G{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,s){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=s||"",this.matchRules(),x()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&"}"!==this.cssText.charAt(0)&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):j("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=U(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||H.test(n)||(n=K.test(n)?n.replace(K,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||j("Declaration missing '}'",this.linkPath)):j("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),A(t.join("/")+"/")}(this.linkPath)),`url("${y(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return j("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return j("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${t} missing '}'`,this.linkPath)):j(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):j(`@${e} missing '}'`,this.linkPath)):j(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if("/"!==this.cssText.charAt(0)||"*"!==this.cssText.charAt(1))return!1;this.scopecssDisableNextLine=!1;let e=2;for(;""!==this.cssText.charAt(e)&&("*"!==this.cssText.charAt(e)||"/"!==this.cssText.charAt(e+1));)++e;if(e+=2,""===this.cssText.charAt(e-1))return j("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=U(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(U(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const s=n[0];return this.cssText=this.cssText.slice(s.length),t||this.recordResult(s),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){x()?this.result+=encodeURIComponent(e):this.result+=e}}function V(e,t,n,s,i){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let o=null;try{o=q.exec(e.textContent,n,s,i),q.reset()}catch(e){q.reset(),m("An error occurred while parsing CSS:\n",t,e)}o&&(e.textContent=o)}}let q;function z(e,t){if(t.scopecss){const n=`${Xe.tagName}[name=${t.name}]`;if(q||(q=new G),e.textContent)V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver((function(){s.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&V(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));s.observe(e,{childList:!0})}}return e}function Q(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function J(e){const t=new CustomEvent("load");Q(t,e),r(e.onload)?e.onload(t):e.dispatchEvent(t)}function X(e){const t=new CustomEvent("error");Q(t,e),r(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const Y=new Map;function Z(e,t,n,s=!1){const i=e.getAttribute("rel");let o=e.getAttribute("href"),r=null;if("stylesheet"===i&&o){if(o=y(o,n.url),s)return{url:o,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${o} move to micro-app-head as style element`),n.source.links.set(o,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else i&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(i)?s?r=document.createComment(`link element with rel=${i}${o?" & href="+o:""} removed by micro-app`):t.removeChild(e):o&&e.setAttribute("href",y(o,n.url));return s?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ee(e,t,n){const s=Array.from(t.source.links.entries());E(s.map((([e])=>Y.has(e)?Y.get(e):F(e,t.name))),(e=>{!function(e,t,n,s,i){t.isGlobal&&!Y.has(e)&&Y.set(e,n);const o=M("style");o.textContent=n,o.__MICRO_APP_LINK_PATH__=e,o.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(z(o,i),t.placeholder):s.appendChild(z(o,i));t.placeholder=null,t.code=n}(s[e.index][0],s[e.index][1],e.data,n,t)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)}))}const te=new WeakMap;function ne(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 te.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?z(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return te.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:s,info:i,replaceComment:o}=Z(t,e,n,!0);if(s&&i){const e=M("style");return e.__MICRO_APP_LINK_PATH__=s,function(e,t,n,s,i){if(n.source.links.has(e))return i.textContent=n.source.links.get(e).code,z(i,n),void _((()=>J(s)));if(Y.has(e)){const o=Y.get(e);return t.code=o,n.source.links.set(e,t),i.textContent=o,z(i,n),void _((()=>J(s)))}F(e,n.name).then((o=>{t.code=o,n.source.links.set(e,t),t.isGlobal&&Y.set(e,o),i.textContent=o,z(i,n),J(s)})).catch((e=>{m(e,n.name),X(s)}))}(s,i,n,t,e),te.set(t,e),e}return o?(te.set(t,o),o):t}if(t instanceof HTMLScriptElement){const{replaceComment:s,url:i,info:o}=_e(t,e,n,!0)||{};if(i&&o){if(o.isExternal){const e=function(e,t,n,s){const i=()=>J(s);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&_(i),be(e,n,t,!0,i)}if(fe.has(e)){const s=fe.get(e);return t.code=s,n.source.scripts.set(e,t),!t.module&&_(i),be(e,n,t,!0,i)}let o;o=n.inline||t.module?M("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return F(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&fe.set(e,r);try{r=ye(e,n,r,t),n.inline||t.module?ge(e,r,t.module,o,i):we(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&J(s)})).catch((e=>{m(e,n.name),X(s)})),o}(i,o,n,t);return te.set(t,e),e}{const e=be(i,n,o,!0);return te.set(t,e),e}}return s?(te.set(t,s),s):t}return t}function se(e,t,n,s,i){if(n===document.head){const o=e.container.querySelector("micro-app-head");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}if(n===document.body){const o=e.container.querySelector("micro-app-body");return i&&!o.contains(i)?de.rawAppendChild.call(o,s):t!==de.rawRemoveChild||o.contains(s)?t===de.rawAppend||t===de.rawPrepend?t.call(o,s):t.call(o,s,i):n.contains(s)?t.call(n,s):s}return t===de.rawAppend||t===de.rawPrepend?t.call(n,s):t.call(n,s,i)}function ie(e){var t;return null!==(t=te.get(e))&&void 0!==t?t:e}function oe(e,t,n,s){if(null==t?void 0:t.__MICRO_APP_NAME__){const i=Ke.get(t.__MICRO_APP_NAME__);return(null==i?void 0:i.container)?se(i,s,e,ne(e,t,i),n&&ie(n)):s===de.rawAppend||s===de.rawPrepend?s.call(e,t):s.call(e,t,n)}if(s===de.rawAppend||s===de.rawPrepend){const n=D();if(!(t instanceof Node)&&n){const i=Ke.get(n);if(null==i?void 0:i.container){if(e===document.head)return s.call(i.container.querySelector("micro-app-head"),t);if(e===document.body)return s.call(i.container.querySelector("micro-app-body"),t)}}return s.call(e,t)}return s.call(e,t,n)}function re(){!function(){const e=de.rawDocument;function t(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelector(t))&&void 0!==i?i:null:de.rawQuerySelector.call(this,t)}function n(t){var n,s,i;const o=D();return o&&t&&!I(t)&&e===this?null!==(i=null===(s=null===(n=Ke.get(o))||void 0===n?void 0:n.container)||void 0===s?void 0:s.querySelectorAll(t))&&void 0!==i?i:[]:de.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return ae(de.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return ae(de.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return ae(de.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!D()||S(e))return de.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return de.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!D()||S(e))return de.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return de.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const s=D();if(!s||I(e)||S(e)||!(null===(t=Ke.get(s))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return de.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return de.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!D()||S(e))return de.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return de.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return oe(this,e,null,de.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return oe(this,e,t,de.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return oe(this,e,t,de.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)oe(this,e[t],null,de.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)oe(this,e[t-1],null,de.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=Ke.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?se(t,de.rawRemoveChild,this,ie(e)):de.rawRemoveChild.call(this,e)}return de.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=de.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function ae(e){const t=D();return t&&(e.__MICRO_APP_NAME__=t),e}let ce=!1;function le(){C(null),Document.prototype.createElement=de.rawCreateElement,Document.prototype.createElementNS=de.rawCreateElementNS,Document.prototype.createDocumentFragment=de.rawCreateDocumentFragment,Document.prototype.querySelector=de.rawQuerySelector,Document.prototype.querySelectorAll=de.rawQuerySelectorAll,Document.prototype.getElementById=de.rawGetElementById,Document.prototype.getElementsByClassName=de.rawGetElementsByClassName,Document.prototype.getElementsByTagName=de.rawGetElementsByTagName,Document.prototype.getElementsByName=de.rawGetElementsByName,Element.prototype.appendChild=de.rawAppendChild,Element.prototype.insertBefore=de.rawInsertBefore,Element.prototype.replaceChild=de.rawReplaceChild,Element.prototype.removeChild=de.rawRemoveChild,Element.prototype.append=de.rawAppend,Element.prototype.prepend=de.rawPrepend,Element.prototype.cloneNode=de.rawCloneNode}let he=!1;function ue(){pe(),Ke.forEach((e=>{e.container&&L(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&Ke.clear()}function pe(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",ue,!1)}const de={};function me(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,i=Element.prototype.removeChild,o=Element.prototype.append,r=Element.prototype.prepend,a=Element.prototype.cloneNode,c=Document.prototype.createElement,l=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,u=Document.prototype.querySelector,p=Document.prototype.querySelectorAll,d=Document.prototype.getElementById,m=Document.prototype.getElementsByClassName,f=Document.prototype.getElementsByTagName,_=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=D(),n}}),b=Function("return window")(),g=Function("return document")(),w="noModule"in document.createElement("script"),y=b.addEventListener,E=b.removeEventListener,v=b.setInterval,N=b.setTimeout,C=b.clearInterval,R=b.clearTimeout,P=g.addEventListener,O=g.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(de,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:i,rawAppend:o,rawPrepend:r,rawCloneNode:a,rawCreateElement:c,rawCreateElementNS:l,rawCreateDocumentFragment:h,rawQuerySelector:u,rawQuerySelectorAll:p,rawGetElementById:d,rawGetElementsByClassName:m,rawGetElementsByTagName:f,rawGetElementsByName:_,ImageProxy:A,rawWindow:b,rawDocument:g,supportModuleScript:w,rawWindowAddEventListener:y,rawWindowRemoveEventListener:E,rawSetInterval:v,rawSetTimeout:N,rawClearInterval:C,rawClearTimeout:R,rawDocumentAddEventListener:P,rawDocumentRemoveEventListener:O}),function(){if(!he){he=!0;const e=M("style");de.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${Xe.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,de.rawDocument.head.appendChild(e)}}(),pe(),window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",ue,!1)}}const fe=new Map;function _e(e,t,n,s=!1){let i=null,o=e.getAttribute("src");if(e.hasAttribute("exclude"))i=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(de.supportModuleScript&&e.noModule||!de.supportModuleScript&&"module"===e.type)i=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(o){o=y(o,n.url);const t={code:"",isExternal:!0,isDynamic:s,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(s)return{url:o,info:t};n.source.scripts.set(o,t),i=document.createComment(`script with src='${o}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),o={code:e.textContent,isExternal:!1,isDynamic:s,async:!1,defer:"module"===e.type,module:"module"===e.type};if(s)return{url:t,info:o};n.source.scripts.set(t,o),i=document.createComment("inline script extract by micro-app")}else s||(i=document.createComment("script element removed by micro-app"))}return s?{replaceComment:i}:t.replaceChild(i,e)}function Ae(e,t){const n=Array.from(t.source.scripts.entries()),s=[],i=[];for(const[e,o]of n)if(o.isExternal){const n=fe.get(e);n?o.code=n:(!o.defer&&!o.async||t.isPrefetch)&&(s.push(F(e,t.name)),i.push([e,o]))}s.length?E(s,(e=>{!function(e,t,n){t.isGlobal&&!fe.has(e)&&fe.set(e,n);t.code=n}(i[e.index][0],i[e.index][1],e.data)}),(e=>{m(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function be(e,t,n,s,i){var o;try{const r=ye(e,t,n.code,n);if(t.inline||n.module){const a=M("script");if(ge(e,r,n.module,a,i),s)return a;null===(o=t.container)||void 0===o||o.querySelector("micro-app-body").appendChild(a)}else if(we(r,n),s)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function ge(e,t,n,s,i){if(n){const e=new Blob([t],{type:"text/javascript"});s.src=URL.createObjectURL(e),s.setAttribute("type","module"),i&&(i.moduleCount&&i.moduleCount--,s.onload=i.bind(s,0===i.moduleCount))}else s.textContent=t;e.startsWith("inline-")||s.setAttribute("data-origin-src",e)}function we(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function ye(e,t,n,s){return c(Xe.plugins)&&(n=function(e,t,n,s,i){var o;const r=Ee(s.global,t,e,i);return Ee(null===(o=s.modules)||void 0===o?void 0:o[n],r,e,i)}(e,n,t.name,Xe.plugins,s)),t.sandBox&&!s.module?(de.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${B}){;${n}\n}).call(proxyWindow,${B})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Ee(e,t,n,s){return a(e)?e.reduce(((e,t)=>c(t)&&r(t.loader)?t.loader(e,n,t.options,s):e),t):t}function ve(e,t,n){const s=Array.from(e.children);s.length&&s.forEach((e=>{ve(e,t)}));for(const n of s)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",y(n.getAttribute("href"),t.url)):Z(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&z(n,t):n instanceof HTMLScriptElement?_e(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",y(n.getAttribute("src"),t.url))}function Ne(e,t){const n=function(e){const t=M("div");return t.innerHTML=e,t}(e),s=n.querySelector("micro-app-head"),i=n.querySelector("micro-app-body");if(!s||!i){const e=`element ${s?"body":"head"} is missing`;return t.onerror(new Error(e)),m(e,t.name)}ve(n,t),t.source.links.size?ee(n,t,s):t.onLoad(n),t.source.scripts.size?Ae(n,t):t.onLoad(n)}const Ce=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(m("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!r(t))return m("event-center: Invalid callback function");let s=this.eventList.get(e);s?n&&Object.getOwnPropertyNames(s.data).length&&t(s.data):(s={data:{},callbacks:new Set},this.eventList.set(e,s)),s.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(r(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!c(t))return m("event-center: data must be object");let n=this.eventList.get(e);if(n){if(n.data!==t){n.data=t;for(const e of n.callbacks)e(t)}}else n={data:t,callbacks:new Set},this.eventList.set(e,n)}}getData(e){var t;const n=this.eventList.get(e);return null!==(t=null==n?void 0:n.data)&&void 0!==t?t:null}};function Re(e,t){return i(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class De{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Ce.on("global",e,t)}removeGlobalDataListener(e){r(e)&&Ce.off("global",e)}setGlobalData(e){P(),Ce.dispatch("global",e)}getGlobalData(){return Ce.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Ce.eventList.get("global");if(t)for(const n of t.callbacks)(e&&e===n.__APP_NAME__||!e&&!n.__APP_NAME__)&&t.callbacks.delete(n)}}class Pe extends De{addDataListener(e,t,n){Ce.on(Re(g(e),!1),t,n)}removeDataListener(e,t){r(t)&&Ce.off(Re(g(e),!1),t)}getData(e,t=!1){return Ce.getData(Re(g(e),t))}setData(e,t){Ce.dispatch(Re(g(e),!0),t)}clearDataListener(e){Ce.off(Re(g(e),!1))}}class Me extends De{constructor(e){super(),this.appName=g(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Ce.on(Re(this.appName,!0),e,t)}removeDataListener(e){r(e)&&Ce.off(Re(this.appName,!0),e)}getData(){return Ce.getData(Re(this.appName,!0))}dispatch(e){P(),Ce.dispatch(Re(this.appName,!1),e);const t=Ke.get(this.appName);if((null==t?void 0:t.container)&&c(e)){const n=new CustomEvent("datachange",{detail:{data:e}});L(t.container).dispatchEvent(n)}}clearDataListener(){Ce.off(Re(this.appName,!0))}}function Oe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(o(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),s=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=s}(t)&&!function(e){return o(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=h(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&u(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const Se=new Map;let Ie=!1;const Le=new Map;function Ue(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=de;!Ie&&function(){if(Ie=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return f("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){Se.forEach((t=>{r(t)&&t.call(document,e)}))}u(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=D();return e?Se.get(e):Se.get("base")},set(e){const s=D();s?Se.set(s,e):Se.set("base",e),!t&&r(e)&&(t=!0,de.rawDocumentAddEventListener.call(de.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const t=e.get(n);t?t.add(s):e.set(n,new Set([s]))}else Le.set(r,new Map([[n,new Set([s])]]));s&&(s.__MICRO_APP_MARK_OPTIONS__=i)}t.call(e,n,s,i)},document.removeEventListener=function(t,s,i){var o;const r=D();if(r&&(!(null===(o=Ke.get(r))||void 0===o?void 0:o.umdMode)||!h(s))){const e=Le.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(s)&&n.delete(s)}}n.call(e,t,s,i)}}const xe=["unmount","appstate-change"];function Te(e,t){return xe.includes(e)?`${e}-${t.__MICRO_APP_NAME__}`:e}const ke=["System","__cjsWrapper"],We=["location"],$e=["window","self","globalThis"];class Be{constructor(e,t){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t),Object.assign(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,s=new Map,i=new Map,{rawWindow:o,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:h,rawClearInterval:u,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=de;e.addEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);r?r.add(s):n.set(t,new Set([s])),s&&(s.__MICRO_APP_MARK_OPTIONS__=i),a.call(o,t,s,i)},e.removeEventListener=function(t,s,i){t=Te(t,e);const r=n.get(t);(null==r?void 0:r.size)&&r.has(s)&&r.delete(s),c.call(o,t,s,i)},e.setInterval=function(e,t,...n){const i=l.call(o,e,t,...n);return s.set(i,{handler:e,timeout:t,args:n}),i},e.setTimeout=function(e,t,...n){const s=h.call(o,e,t,...n);return i.set(s,{handler:e,timeout:t,args:n}),s},e.clearInterval=function(e){s.delete(e),u.call(o,e)},e.clearTimeout=function(e){i.delete(e),p.call(o,e)};const m=new Map,f=new Map;let _,A=new Map,b=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),s.size&&(A=new Map(s)),i.size&&(b=new Map(i)),_=Se.get(t);const e=Le.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const s of t)e.addEventListener(n,s,null==s?void 0:s.__MICRO_APP_MARK_OPTIONS__)})),A.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),b.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&Se.set(t,_),C(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),C(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(o,t,n)})),n.clear()),s.size&&(s.forEach(((e,t)=>{u.call(o,t)})),s.clear()),i.size&&(i.forEach(((e,t)=>{p.call(o,t)})),i.clear()),Se.delete(t);const e=Le.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,de.rawWindow._babelPolyfill&&(de.rawWindow._babelPolyfill=!1),1==++Be.activeCount&&(Ue(),re()))}stop(){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(de.rawWindow,e)})),this.escapeKeys.clear(),0==--Be.activeCount&&(document.addEventListener=de.rawDocumentAddEventListener,document.removeEventListener=de.rawDocumentRemoveEventListener,le()))}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=Ce.eventList.get("global");if(n)for(const s of n.callbacks)t===s.__APP_NAME__&&e.umdDataListeners.global.add(s);const s=Ce.eventList.get(Re(t,!0));s&&(e.umdDataListeners.normal=new Set(s.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,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.microAppWindow.microApp)}getSpecialProperties(e){var t;c(Xe.plugins)&&(this.commonActionForSpecialProperties(Xe.plugins.global),this.commonActionForSpecialProperties(null===(t=Xe.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(a(e))for(const t of e)c(t)&&(a(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),a(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=de.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,s)=>{if(R(e),Reflect.has(n,s)||i(s)&&/^__MICRO_APP_/.test(s)||this.scopeProperties.includes(s))return Reflect.get(n,s);const o=Reflect.get(t,s);return r(o)?Oe(t,o):o},set:(e,n,s)=>{if(this.active){if(We.includes(n))Reflect.set(t,n,s);else if(d.call(e,n)||!d.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,s),this.injectedKeys.add(n);else{const i=Object.getOwnPropertyDescriptor(t,n),{configurable:o,enumerable:r,writable:a,set:c}=i;u(e,n,{value:s,configurable:o,enumerable:r,writable:null!=a?a:!!c}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||ke.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,s),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,s)=>{if(d.call(e,s))return n.set(s,"target"),Object.getOwnPropertyDescriptor(e,s);if(d.call(t,s)){n.set(s,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,s);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,s,i)=>"rawWindow"===n.get(s)?Reflect.defineProperty(t,s,i):Reflect.defineProperty(e,s,i),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)=>!d.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_PUBLIC_PATH__=w(n),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new Me(t),{removeDomScope:P,pureCreateElement:M}),e.rawWindow=de.rawWindow,e.rawDocument=de.rawDocument,e.hasOwnProperty=t=>d.call(e,t)||d.call(de.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t)}setMappingPropertiesWithRawDescriptor(e){let t,n;const s=de.rawWindow;s===s.parent?t=n=this.proxyWindow:(t=s.top,n=s.parent),u(e,"top",this.createDescriptorForMicroAppWindow("top",t)),u(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),$e.forEach((t=>{u(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:s=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(de.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:s,writable:null!=i?i:!!o}}setHijackProperties(e,t){let n,s;p(e,{document:{get:()=>(R(t),de.rawDocument),configurable:!1,enumerable:!0},eval:{get:()=>(R(t),n||eval),set:e=>{n=e},configurable:!0,enumerable:!1},Image:{get:()=>(R(t),s||de.ImageProxy),set:e=>{s=e},configurable:!0,enumerable:!1}})}}function Fe(e,t,n,s){var i;if(!e)return m(`element does not exist in lifecycle ${n}`,t);e=L(e),P();const o=Object.assign({name:t,container:e},s&&{error:s}),a=new CustomEvent(n,{detail:o});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(a,e),r(null===(i=Xe.lifeCycles)||void 0===i?void 0:i[n])&&Xe.lifeCycles[n](a),e.dispatchEvent(a)}function He(e,t,n={}){const s=new CustomEvent(`${e}-${t}`,{detail:n});window.dispatchEvent(s)}Be.activeCount=0;const Ke=new Map;class je{constructor({name:e,url:t,ssrUrl:n,container:s,inline:i,scopecss:o,useSandbox:r,baseroute:a}){this.state=k.NOT_LOADED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.baseroute="",this.sandBox=null,this.container=null!=s?s:null,this.inline=null!=i&&i,this.baseroute=null!=a?a:"",this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new Be(e,t))}loadSourceCode(){var e;this.state=k.LOADING_SOURCE_CODE,F((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),m(t,e.name)}Ne(t=t.replace(/<head[^>]*>[\s\S]*?<\/head>/i,(e=>e.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>"))).replace(/<body[^>]*>[\s\S]*?<\/body>/i,(e=>e.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))),e)})).catch((t=>{m(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):k.UNMOUNT!==this.state&&(this.state=k.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),k.UNMOUNT!==this.state&&(this.onerror(e),this.state=k.LOAD_SOURCE_ERROR)}mount(e,t,n){var s,i,a;if(o(t)&&t!==this.inline&&(this.inline=t),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,2!==this.loadSourceLevel)return void(this.state=k.LOADING_SOURCE_CODE);let c;if(Fe(this.container,this.name,W.BEFOREMOUNT),this.state=k.MOUNTING,O(this.source.html,this.container,!this.umdMode),null===(i=this.sandBox)||void 0===i||i.start(this.baseroute),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const s=Array.from(e.entries()),i=[],o=[];for(const[e,r]of s)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?i.push(F(e,t.name)):i.push(r.code),o.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(be(e,t,r,!1),n(!1)));i.length?E(i,(e=>{const t=o[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,m(e,t.name)}),(()=>{o.forEach((([e,s])=>{s.code&&(be(e,t,s,!1,n),!s.module&&n(!1))})),n(void 0===n.moduleCount||n.errorCount===i.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(r(e)&&r(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){m("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){l(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){k.UNMOUNT!==this.state&&(this.state=k.MOUNTED,Fe(this.container,this.name,W.MOUNTED))}unmount(e,t){let n;if(this.state===k.LOAD_SOURCE_ERROR&&(e=!0),this.state=k.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){m("an error occurred in the unmount function \n",this.name,e)}He("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){l(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&O(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(),ze().length||(ce=!1,Element.prototype.setAttribute=de.rawSetAttribute),Fe(this.container,this.name,W.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],Ke.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;O(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=$.KEEP_ALIVE_HIDDEN,He("appstate-change",this.name,{appState:"afterhidden"}),Fe(e,this.name,W.AFTERHIDDEN)}showKeepAliveApp(e){He("appstate-change",this.name,{appState:"beforeshow"}),Fe(e,this.name,W.BEFORESHOW),O(this.container,e,!1),this.container=e,this.keepAliveState=$.KEEP_ALIVE_SHOW,He("appstate-change",this.name,{appState:"aftershow"}),Fe(this.container,this.name,W.AFTERSHOW)}onerror(e){Fe(this.container,this.name,W.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(k.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:de.rawWindow;return this.libraryName=L(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Ge(e){class n extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=g(this.getAttribute("name")),t=b(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=Ke.get(e);if(e!==this.appName&&n&&k.UNMOUNT!==n.getAppState()&&$.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),m(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},ce||(ce=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(c(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{i(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&f("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&Ke.has(this.__MICRO_APP_NAME__)){const n=Ke.get(this.__MICRO_APP_NAME__);de.rawSetAttribute.call(this,e,y(t,n.url))}else de.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,_((()=>Fe(this,this.appName,W.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===T.NAME?"appName":"appUrl"]!==n)if(e!==T.URL||this.appUrl)if(e!==T.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,_(this.handleAttributeUpdate));else{const e=g(n);if(!e)return m(`Invalid attribute name ${n}`,this.appName);this.cacheData&&(Xe.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=b(n,this.appName)))return m(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&r(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),Ke.has(this.appName)){const e=Ke.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==k.UNMOUNT?e.isPrefetch||e.getAppState()===k.UNMOUNT?(f(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):m(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var s;this.getDisposeResult("ssr")?this.ssrUrl=y(de.rawWindow.location.pathname,t):this.ssrUrl&&(this.ssrUrl=""),this.appName=e,this.appUrl=t,(null!==(s=this.shadowRoot)&&void 0!==s?s:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):m(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!i(t)||!t)||(m(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,_((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())}))}handleCreateApp(){var e;Ke.has(this.appName)&&Ke.get(this.appName).actionsForCompletelyDestroy();const t=new je({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),baseroute:this.getBaseRouteCompatible()});Ke.set(this.appName,t)}handleUnmount(e,t){const n=Ke.get(this.appName);n&&n.getAppState()!==k.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=Ke.get(this.appName);e&&e.getAppState()!==k.UNMOUNT&&e.getKeepAliveState()!==$.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){_((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||Xe[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}set data(e){this.appName?Xe.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?Xe.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ve(e){if(!n)return m("preFetch is only supported in browser environment");v((()=>{r(e)&&(e=e()),a(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{v((()=>{var n,s;if(c(e)&&navigator.onLine)if(e.name=g(e.name),e.url=b(e.url,e.name),e.name&&e.url&&!Ke.has(e.name)){const i=new je({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:Xe.disableScopecss),useSandbox:!(null!==(s=e.disableSandbox)&&void 0!==s?s:Xe.disableSandbox)});i.isPrefetch=!0,i.prefetchResolve=t,Ke.set(e.name,i)}else t();else t()}))}));var e}))),Promise.resolve())}))}function qe(e,t,n){if(a(e)){const s=e.filter((e=>i(e)&&e.includes(`.${t}`)&&!n.has(e)));E(s.map((e=>F(e))),(e=>{const t=s[e.index];n.has(t)||n.set(t,e.data)}),(e=>{m(e)}))}}function ze(e){const t=[];return Ke.forEach(((n,s)=>{k.UNMOUNT===n.getAppState()||n.isPrefetch||e&&$.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(s)})),t}function Qe(e,t){const n=Ke.get(g(e));return new Promise((s=>{if(n)if(n.getAppState()===k.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===$.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,s):(null==t?void 0:t.clearAliveState)?n.unmount(!1,s):s();else{const e=L(n.container),i=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()},o=()=>{e.removeEventListener("unmount",i),e.removeEventListener("afterhidden",o),s()};if(e.addEventListener("unmount",i),e.addEventListener("afterhidden",o),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else f(`app ${e} does not exist`),s()}))}class Je extends Pe{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ve}start(e){if(!n||!window.customElements)return m("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return m(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return f(`element ${this.tagName} is already defined`);if(me(),e&&c(e)&&(this.shadowDOM=e.shadowDOM,this.destroy=e.destroy,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.ssr=e.ssr,r(e.fetch)&&(this.fetch=e.fetch),c(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ve(e.preFetchApps),e.globalAssets&&(c(t=e.globalAssets)&&v((()=>{qe(t.js,"js",fe),qe(t.css,"css",Y)}))),c(e.plugins))){const t=e.plugins.modules;if(c(t))for(const e in t){const n=g(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Ge(this.tagName)}}var Xe=new Je;e.EventCenterForMicroApp=Me,e.MicroApp=Je,e.default=Xe,e.getActiveApps=ze,e.getAllApps=function(){return Array.from(Ke.keys())},e.preFetch=Ve,e.pureCreateElement=M,e.removeDomScope=P,e.unmountAllApps=function(e){return Array.from(Ke.keys()).reduce(((t,n)=>t.then((()=>Qe(n,e)))),Promise.resolve())},e.unmountApp=Qe,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microApp={})}(this,(function(e){"use strict";const t="1.0.0-alpha.0",n="undefined"!=typeof window,i="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:Function("return this")(),o=()=>{},s=()=>!1,r=Array.isArray,a=Object.assign,c=Object.defineProperty,l=Object.defineProperties,u=Object.prototype.hasOwnProperty;function h(e){return void 0===e}function p(e){return null===e}function d(e){return"string"==typeof e}function m(e){return"boolean"==typeof e}function f(e){return"function"==typeof e}function _(e){return"[object Object]"===toString.call(e)}function g(e){return"[object Promise]"===toString.call(e)}function A(e){return f(e)&&0===e.name.indexOf("bound ")&&!e.hasOwnProperty("prototype")}function w(e){return e instanceof URL}function y(e,t=null,...n){const i=t&&d(t)?` app ${t}:`:"";d(e)?console.error(`[micro-app]${i} ${e}`,...n):console.error(`[micro-app]${i}`,e,...n)}function b(e,t=null,...n){const i=t&&d(t)?` app ${t}:`:"";d(e)?console.warn(`[micro-app]${i} ${e}`,...n):console.warn(`[micro-app]${i}`,e,...n)}function v(e,...t){Promise.resolve().then(e.bind(null,...t))}const E=function(){class e extends URL{}return(t,n)=>n?new e(""+t,n):new e(""+t)}();function R(e){return e.startsWith("//")?`${location.protocol}${e}`:e}function P(e,t=null){if(!d(e)||!e)return"";try{const{origin:t,pathname:n,search:i}=E(R(e));if(/\.(\w+)$/.test(n))return`${t}${n}${i}`;const o=`${t}${n}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(o)?`${o}${i}`:""}catch(e){return y(e,t),""}}function N(e){return d(e)&&e?e.replace(/(^\d+)|([^\w\d-_])/gi,""):""}function C(e){const{origin:t,pathname:n}=E(e);if(/\.(\w+)$/.test(n)){const e=`${t}${n}`.split("/");return e.pop(),e.join("/")+"/"}return`${t}${n}/`.replace(/\/\/$/,"/")}function M(e,t){return!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e)?e:E(e,C(R(t))).toString()}function S(e,t,n,i){let o=0;function s(){++o===e.length&&i&&i()}e.forEach(((e,i)=>{g(e)?e.then((e=>{t({data:e,index:i}),s()})).catch((e=>{n({error:e,index:i}),s()})):(t({data:e,index:i}),s())}))}const D=i.requestIdleCallback||function(e){const t=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),50)};let O=null;function I(e){O=e}function x(e){O!==e&&(I(e),v((()=>{I(null)})))}function L(){return O}function U(){I(null)}function T(e,t){const n=document.createElement(e,t);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function W(e,t,n){if(t.innerHTML="",n){const n=e.cloneNode(!0),i=document.createDocumentFragment();Array.from(n.childNodes).forEach((e=>{i.appendChild(e)})),t.appendChild(i)}else Array.from(e.childNodes).forEach((e=>{t.appendChild(e)}))}function k(e){return!e||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(e)}function B(e){return/^body$/i.test(e)||/^head$/i.test(e)||/^html$/i.test(e)}function $(e){return function(e){return"undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot}(e)?e.host:e}function F(e){return e?e.replace(/^\s+|\s+$/g,""):""}function H(){return navigator.userAgent.indexOf("Firefox")>-1}function K(e){const t={},n=e.split("&");for(const e of n){const n=e.indexOf("="),i=n<0?e:e.slice(0,n),o=n<0?null:e.slice(n+1);if(i in t){let e=t[i];r(e)||(e=t[i]=[e]),e.push(o)}else t[i]=o}return t}function j(e){let t="";for(const n in e){const i=e[n];if(p(i))t+=(t.length?"&":"")+n;else{(r(i)?i:[i]).forEach((e=>{h(e)||(t+=(t.length?"&":"")+n,p(e)||(t+="="+e))}))}}return t}function G(){const e=new Set;return{add:function(t){return e.add(t),()=>!!e.has(t)&&e.delete(t)},list:()=>e}}var Q,V,q,z;!function(e){e.NAME="name",e.URL="url"}(Q||(Q={})),function(e){e.CREATED="created",e.LOADING="loading",e.LOADED="loaded",e.LOAD_FAILED="load_failed",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",e.BEFORESHOW="beforeshow",e.AFTERSHOW="aftershow",e.AFTERHIDDEN="afterhidden"}(q||(q={})),function(e){e.KEEP_ALIVE_SHOW="keep_alive_show",e.KEEP_ALIVE_HIDDEN="keep_alive_hidden"}(z||(z={}));const X="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,navigator,undefined,location,history,EventSource,fetch,XMLHttpRequest";function Y(e,t=null,n={}){return f($t.fetch)?$t.fetch(e,n,t):fetch(e,n).then((e=>e.text()))}const J=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,Z=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function ee(e,t){e=t?`${t} ${e}`:e;const n=new Error(e);throw n.reason=e,t&&(n.filename=t),n}class te{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,t,n,i){return this.cssText=e,this.prefix=t,this.baseURI=n,this.linkPath=i||"",this.matchRules(),H()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&"}"!==this.cssText.charAt(0)&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):ee("selector missing",this.linkPath)}formatSelector(e){const t=this.commonMatch(/^([^{]+)/,e);return!!t&&t[0].replace(/(^|,[\n\s]*)([^,]+)/g,((e,t,n)=>(n=F(n),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(n))||J.test(n)||(n=Z.test(n)?n.replace(Z,this.prefix+" micro-app-body"):this.prefix+" "+n),t+n)))}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),!!this.matchCloseBrace()||ee("Declaration missing '}'",this.linkPath)):ee("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(this.scopecssDisableNextLine||this.scopecssDisable&&!this.scopecssDisableSelectors.length||(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,t)=>/^((data|blob):|#)/.test(t)||/^(https?:)?\/\//.test(t)?e:(/^((\.\.?\/)|[^/])/.test(t)&&this.linkPath&&(this.baseURI=function(e){const t=e.split("/");return t.pop(),R(t.join("/")+"/")}(this.linkPath)),`url("${M(t,this.baseURI)}")`)))),this.recordResult(e)),this.scopecssDisableNextLine=!1,this.cssText&&"}"!==this.cssText.charAt(0))return"/"===this.cssText.charAt(0)&&"*"===this.cssText.charAt(1)?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return"@"===this.cssText[0]&&(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return ee("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return ee("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const t=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),this.commonMatch(/^,\s*/);return!!t.length&&(this.styleDeclarations(),this.matchLeadingSpaces(),!0)}customMediaRule(){return!!this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)&&(this.matchLeadingSpaces(),!0)}pageRule(){return!!this.commonMatch(/^@page */)&&(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page"))}fontFaceRule(){return!!this.commonMatch(/^@font-face\s*/)&&this.commonHandlerForAtRuleWithSelfRule("font-face")}createMatcherForAtRuleWithChildRule(e,t){return()=>!!this.commonMatch(e)&&(this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee(`@${t} missing '}'`,this.linkPath)):ee(`@${t} missing '{'`,this.linkPath))}createMatcherForNoneBraceAtRule(e){const t=new RegExp("^@"+e+"\\s*([^;]+);");return()=>!!this.commonMatch(t)&&(this.matchLeadingSpaces(),!0)}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):ee(`@${e} missing '}'`,this.linkPath)):ee(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if("/"!==this.cssText.charAt(0)||"*"!==this.cssText.charAt(1))return!1;this.scopecssDisableNextLine=!1;let e=2;for(;""!==this.cssText.charAt(e)&&("*"!==this.cssText.charAt(e)||"/"!==this.cssText.charAt(e+1));)++e;if(e+=2,""===this.cssText.charAt(e-1))return ee("End of comment missing",this.linkPath);let t=this.cssText.slice(2,e-2);if(this.recordResult(`/*${t}*/`),t=F(t.replace(/^\s*!/,"")),"scopecss-disable-next-line"===t)this.scopecssDisableNextLine=!0;else if(/^scopecss-disable/.test(t))if("scopecss-disable"===t)this.scopecssDisable=!0;else{this.scopecssDisable=!0;t.replace("scopecss-disable","").split(",").forEach((e=>{this.scopecssDisableSelectors.push(F(e))}))}else"scopecss-enable"===t&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]);return this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,t=!1){const n=e.exec(this.cssText);if(!n)return;const i=n[0];return this.cssText=this.cssText.slice(i.length),t||this.recordResult(i),n}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){H()?this.result+=encodeURIComponent(e):this.result+=e}}function ne(e,t,n,i,o){if(!e.__MICRO_APP_HAS_SCOPED__){e.__MICRO_APP_HAS_SCOPED__=!0;let s=null;try{s=ie.exec(e.textContent,n,i,o),ie.reset()}catch(e){ie.reset(),y("An error occurred while parsing CSS:\n",t,e)}s&&(e.textContent=s)}}let ie;function oe(e,t){if(t.scopecss){const n=`${$t.tagName}[name=${t.name}]`;if(ie||(ie=new te),e.textContent)ne(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__);else{const i=new MutationObserver((function(){i.disconnect(),e.textContent&&!e.hasAttribute("data-styled")&&ne(e,t.name,n,t.url,e.__MICRO_APP_LINK_PATH__)}));i.observe(e,{childList:!0})}}return e}function se(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},srcElement:{get:()=>t},target:{get:()=>t}})}function re(e){const t=new CustomEvent("load");se(t,e),f(e.onload)?e.onload(t):e.dispatchEvent(t)}function ae(e){const t=new CustomEvent("error");se(t,e),f(e.onerror)?e.onerror(t):e.dispatchEvent(t)}const ce=new Map;function le(e,t,n,i=!1){const o=e.getAttribute("rel");let s=e.getAttribute("href"),r=null;if("stylesheet"===o&&s){if(s=M(s,n.url),i)return{url:s,info:{code:"",isGlobal:e.hasAttribute("global")}};r=document.createComment(`link element with href=${s} move to micro-app-head as style element`),n.source.links.set(s,{code:"",placeholder:r,isGlobal:e.hasAttribute("global")})}else o&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(o)?i?r=document.createComment(`link element with rel=${o}${s?" & href="+s:""} removed by micro-app`):t.removeChild(e):s&&e.setAttribute("href",M(s,n.url));return i?{replaceComment:r}:r?t.replaceChild(r,e):void 0}function ue(e,t,n){const i=Array.from(t.source.links.entries());S(i.map((([e])=>ce.has(e)?ce.get(e):Y(e,t.name))),(e=>{!function(e,t,n,i,o){t.isGlobal&&!ce.has(e)&&ce.set(e,n);const s=T("style");s.textContent=n,s.__MICRO_APP_LINK_PATH__=e,s.setAttribute("data-origin-href",e),t.placeholder.parentNode?t.placeholder.parentNode.replaceChild(oe(s,o),t.placeholder):i.appendChild(oe(s,o));t.placeholder=null,t.code=n}(i[e.index][0],i[e.index][1],e.data,n,t)}),(e=>{y(e,t.name)}),(()=>{t.onLoad(e)}))}const he=new WeakMap;function pe(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 he.set(t,e),e}return n.scopecss&&!t.hasAttribute("ignore")?oe(t,n):t}if(t instanceof HTMLLinkElement){if(t.hasAttribute("exclude")){const e=document.createComment("link element with exclude attribute ignored by micro-app");return he.set(t,e),e}if(t.hasAttribute("ignore"))return t;const{url:i,info:o,replaceComment:s}=le(t,e,n,!0);if(i&&o){const e=T("style");return e.__MICRO_APP_LINK_PATH__=i,function(e,t,n,i,o){if(n.source.links.has(e))return o.textContent=n.source.links.get(e).code,oe(o,n),void v((()=>re(i)));if(ce.has(e)){const s=ce.get(e);return t.code=s,n.source.links.set(e,t),o.textContent=s,oe(o,n),void v((()=>re(i)))}Y(e,n.name).then((s=>{t.code=s,n.source.links.set(e,t),t.isGlobal&&ce.set(e,s),o.textContent=s,oe(o,n),re(i)})).catch((e=>{y(e,n.name),ae(i)}))}(i,o,n,t,e),he.set(t,e),e}return s?(he.set(t,s),s):t}if(t instanceof HTMLScriptElement){const{replaceComment:i,url:o,info:s}=Pe(t,e,n,!0)||{};if(o&&s){if(s.isExternal){const e=function(e,t,n,i){const o=()=>re(i);if(n.source.scripts.has(e)){const t=n.source.scripts.get(e);return!t.module&&v(o),Ce(e,n,t,!0,o)}if(Re.has(e)){const i=Re.get(e);return t.code=i,n.source.scripts.set(e,t),!t.module&&v(o),Ce(e,n,t,!0,o)}let s;s=n.inline||t.module?T("script"):document.createComment(`dynamic script with src='${e}' extract by micro-app`);return Y(e,n.name).then((r=>{t.code=r,n.source.scripts.set(e,t),t.isGlobal&&Re.set(e,r);try{r=De(e,n,r,t),n.inline||t.module?Me(e,r,t.module,s,o):Se(r,t)}catch(t){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,t,e)}!t.module&&re(i)})).catch((e=>{y(e,n.name),ae(i)})),s}(o,s,n,t);return he.set(t,e),e}{const e=Ce(o,n,s,!0);return he.set(t,e),e}}return i?(he.set(t,i),i):t}return t}function de(e,t,n,i,o){const s=function(e,t){var n,i;if(e===document.head)return null===(n=null==t?void 0:t.container)||void 0===n?void 0:n.querySelector("micro-app-head");if(e===document.body)return null===(i=null==t?void 0:t.container)||void 0===i?void 0:i.querySelector("micro-app-body");return null}(n,e);return s?o&&!s.contains(o)?ve.rawAppendChild.call(s,i):t!==ve.rawRemoveChild||s.contains(i)?me(t,s,i,o):n.contains(i)?t.call(n,i):i:me(t,n,i,o)}function me(e,t,n,i){return(o=e)===ve.rawAppend||o===ve.rawPrepend?e.call(t,n):e.call(t,n,i);var o}function fe(e){var t;return null!==(t=he.get(e))&&void 0!==t?t:e}function _e(e,t,n,i){if(null==t?void 0:t.__MICRO_APP_NAME__){const o=It.get(t.__MICRO_APP_NAME__);return(null==o?void 0:o.container)?de(o,i,e,pe(e,t,o),n&&fe(n)):i===ve.rawAppend||i===ve.rawPrepend?i.call(e,t):i.call(e,t,n)}if(i===ve.rawAppend||i===ve.rawPrepend){const n=L();if(!(t instanceof Node)&&n){const o=It.get(n);if(null==o?void 0:o.container){if(e===document.head)return i.call(o.container.querySelector("micro-app-head"),t);if(e===document.body)return i.call(o.container.querySelector("micro-app-body"),t)}}return i.call(e,t)}return i.call(e,t,n)}function ge(){!function(){const e=ve.rawDocument;function t(t){var n,i,o,s;const r=L();return r&&(null===(n=It.get(r))||void 0===n?void 0:n.container)&&t&&!B(t)&&e===this?null!==(s=null===(o=null===(i=It.get(r))||void 0===i?void 0:i.container)||void 0===o?void 0:o.querySelector(t))&&void 0!==s?s:null:ve.rawQuerySelector.call(this,t)}function n(t){var n,i,o,s;const r=L();return r&&(null===(n=It.get(r))||void 0===n?void 0:n.container)&&t&&!B(t)&&e===this?null!==(s=null===(o=null===(i=It.get(r))||void 0===i?void 0:i.container)||void 0===o?void 0:o.querySelectorAll(t))&&void 0!==s?s:[]:ve.rawQuerySelectorAll.call(this,t)}Document.prototype.createElement=function(e,t){return Ae(ve.rawCreateElement.call(this,e,t))},Document.prototype.createElementNS=function(e,t,n){return Ae(ve.rawCreateElementNS.call(this,e,t,n))},Document.prototype.createDocumentFragment=function(){return Ae(ve.rawCreateDocumentFragment.call(this))},Document.prototype.querySelector=t,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(e){if(!L()||k(e))return ve.rawGetElementById.call(this,e);try{return t.call(this,`#${e}`)}catch(t){return ve.rawGetElementById.call(this,e)}},Document.prototype.getElementsByClassName=function(e){if(!L()||k(e))return ve.rawGetElementsByClassName.call(this,e);try{return n.call(this,`.${e}`)}catch(t){return ve.rawGetElementsByClassName.call(this,e)}},Document.prototype.getElementsByTagName=function(e){var t;const i=L();if(!i||B(e)||k(e)||!(null===(t=It.get(i))||void 0===t?void 0:t.inline)&&/^script$/i.test(e))return ve.rawGetElementsByTagName.call(this,e);try{return n.call(this,e)}catch(t){return ve.rawGetElementsByTagName.call(this,e)}},Document.prototype.getElementsByName=function(e){if(!L()||k(e))return ve.rawGetElementsByName.call(this,e);try{return n.call(this,`[name=${e}]`)}catch(t){return ve.rawGetElementsByName.call(this,e)}}}(),Element.prototype.appendChild=function(e){return _e(this,e,null,ve.rawAppendChild)},Element.prototype.insertBefore=function(e,t){return _e(this,e,t,ve.rawInsertBefore)},Element.prototype.replaceChild=function(e,t){return _e(this,e,t,ve.rawReplaceChild)},Element.prototype.append=function(...e){let t=0;const n=e.length;for(;t<n;)_e(this,e[t],null,ve.rawAppend),t++},Element.prototype.prepend=function(...e){let t=e.length;for(;t>0;)_e(this,e[t-1],null,ve.rawPrepend),t--},Element.prototype.removeChild=function(e){if(null==e?void 0:e.__MICRO_APP_NAME__){const t=It.get(e.__MICRO_APP_NAME__);return(null==t?void 0:t.container)?de(t,ve.rawRemoveChild,this,fe(e)):ve.rawRemoveChild.call(this,e)}return ve.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const t=ve.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(t.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),t}}function Ae(e){const t=L();return t&&(e.__MICRO_APP_NAME__=t),e}let we=!1;function ye(){I(null),Document.prototype.createElement=ve.rawCreateElement,Document.prototype.createElementNS=ve.rawCreateElementNS,Document.prototype.createDocumentFragment=ve.rawCreateDocumentFragment,Document.prototype.querySelector=ve.rawQuerySelector,Document.prototype.querySelectorAll=ve.rawQuerySelectorAll,Document.prototype.getElementById=ve.rawGetElementById,Document.prototype.getElementsByClassName=ve.rawGetElementsByClassName,Document.prototype.getElementsByTagName=ve.rawGetElementsByTagName,Document.prototype.getElementsByName=ve.rawGetElementsByName,Element.prototype.appendChild=ve.rawAppendChild,Element.prototype.insertBefore=ve.rawInsertBefore,Element.prototype.replaceChild=ve.rawReplaceChild,Element.prototype.removeChild=ve.rawRemoveChild,Element.prototype.append=ve.rawAppend,Element.prototype.prepend=ve.rawPrepend,Element.prototype.cloneNode=ve.rawCloneNode}let be=!1;const ve={};function Ee(){if(n){const e=Element.prototype.setAttribute,t=Element.prototype.appendChild,n=Element.prototype.insertBefore,i=Element.prototype.replaceChild,o=Element.prototype.removeChild,s=Element.prototype.append,r=Element.prototype.prepend,c=Element.prototype.cloneNode,l=Document.prototype.createElement,u=Document.prototype.createElementNS,h=Document.prototype.createDocumentFragment,p=Document.prototype.querySelector,d=Document.prototype.querySelectorAll,m=Document.prototype.getElementById,f=Document.prototype.getElementsByClassName,_=Document.prototype.getElementsByTagName,g=Document.prototype.getElementsByName,A=new Proxy(Image,{construct(e,t){const n=new e(...t);return n.__MICRO_APP_NAME__=L(),n}}),w=Function("return window")(),y=Function("return document")(),b="noModule"in document.createElement("script"),v=w.addEventListener,E=w.removeEventListener,R=w.setInterval,P=w.setTimeout,N=w.clearInterval,C=w.clearTimeout,M=y.addEventListener,S=y.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,a(ve,{rawSetAttribute:e,rawAppendChild:t,rawInsertBefore:n,rawReplaceChild:i,rawRemoveChild:o,rawAppend:s,rawPrepend:r,rawCloneNode:c,rawCreateElement:l,rawCreateElementNS:u,rawCreateDocumentFragment:h,rawQuerySelector:p,rawQuerySelectorAll:d,rawGetElementById:m,rawGetElementsByClassName:f,rawGetElementsByTagName:_,rawGetElementsByName:g,ImageProxy:A,rawWindow:w,rawDocument:y,supportModuleScript:b,rawWindowAddEventListener:v,rawWindowRemoveEventListener:E,rawSetInterval:R,rawSetTimeout:P,rawClearInterval:N,rawClearTimeout:C,rawDocumentAddEventListener:M,rawDocumentRemoveEventListener:S}),function(){if(!be){be=!0;const e=T("style");ve.rawSetAttribute.call(e,"type","text/css"),e.textContent=`\n${$t.tagName}, micro-app-body { display: block; } \nmicro-app-head { display: none; }`,ve.rawDocument.head.appendChild(e)}}()}}const Re=new Map;function Pe(e,t,n,i=!1){let o=null,s=e.getAttribute("src");if(e.hasAttribute("exclude"))o=document.createComment("script element with exclude attribute removed by micro-app");else{if(e.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"].includes(e.type)||e.hasAttribute("ignore"))return null;if(ve.supportModuleScript&&e.noModule||!ve.supportModuleScript&&"module"===e.type)o=document.createComment((e.noModule?"noModule":"module")+" script ignored by micro-app");else if(s){s=M(s,n.url);const t={code:"",isExternal:!0,isDynamic:i,async:e.hasAttribute("async"),defer:e.defer||"module"===e.type,module:"module"===e.type,isGlobal:e.hasAttribute("global")};if(i)return{url:s,info:t};n.source.scripts.set(s,t),o=document.createComment(`script with src='${s}' extract by micro-app`)}else if(e.textContent){const t="inline-"+Math.random().toString(36).substr(2,15),s={code:e.textContent,isExternal:!1,isDynamic:i,async:!1,defer:"module"===e.type,module:"module"===e.type};if(i)return{url:t,info:s};n.source.scripts.set(t,s),o=document.createComment("inline script extract by micro-app")}else i||(o=document.createComment("script element removed by micro-app"))}return i?{replaceComment:o}:t.replaceChild(o,e)}function Ne(e,t){const n=Array.from(t.source.scripts.entries()),i=[],o=[];for(const[e,s]of n)if(s.isExternal){const n=Re.get(e);n?s.code=n:(!s.defer&&!s.async||t.isPrefetch)&&(i.push(Y(e,t.name)),o.push([e,s]))}i.length?S(i,(e=>{!function(e,t,n){t.isGlobal&&!Re.has(e)&&Re.set(e,n);t.code=n}(o[e.index][0],o[e.index][1],e.data)}),(e=>{y(e,t.name)}),(()=>{t.onLoad(e)})):t.onLoad(e)}function Ce(e,t,n,i,o){var s;try{const r=De(e,t,n.code,n);if(t.inline||n.module){const a=T("script");if(Me(e,r,n.module,a,o),i)return a;null===(s=t.container)||void 0===s||s.querySelector("micro-app-body").appendChild(a)}else if(Se(r,n),i)return document.createComment("dynamic script extract by micro-app")}catch(e){console.error(`[micro-app from runScript] app ${t.name}: `,e)}}function Me(e,t,n,i,o){if(n){const e=new Blob([t],{type:"text/javascript"});i.src=URL.createObjectURL(e),i.setAttribute("type","module"),o&&(o.moduleCount&&o.moduleCount--,i.onload=o.bind(i,0===o.moduleCount))}else i.textContent=t;e.startsWith("inline-")||i.setAttribute("data-origin-src",e)}function Se(e,t){t.code2Function||(t.code2Function=new Function(e)),t.code2Function.call(window)}function De(e,t,n,i){return _($t.plugins)&&(n=function(e,t,n,i,o){var s;const r=Oe(i.global,t,e,o);return Oe(null===(s=i.modules)||void 0===s?void 0:s[n],r,e,o)}(e,n,t.name,$t.plugins,i)),t.sandBox&&!i.module?(ve.rawWindow.__MICRO_APP_PROXY_WINDOW__=t.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${X}){;${n}\n}).call(proxyWindow,${X})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Oe(e,t,n,i){return r(e)?e.reduce(((e,t)=>_(t)&&f(t.loader)?t.loader(e,n,t.options,i):e),t):t}function Ie(e,t,n){const i=Array.from(e.children);i.length&&i.forEach((e=>{Ie(e,t)}));for(const n of i)n instanceof HTMLLinkElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),n):n.hasAttribute("ignore")?n.hasAttribute("href")&&n.setAttribute("href",M(n.getAttribute("href"),t.url)):le(n,e,t):n instanceof HTMLStyleElement?n.hasAttribute("exclude")?e.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),n):t.scopecss&&!n.hasAttribute("ignore")&&oe(n,t):n instanceof HTMLScriptElement?Pe(n,e,t):n instanceof HTMLMetaElement||n instanceof HTMLTitleElement?e.removeChild(n):n instanceof HTMLImageElement&&n.hasAttribute("src")&&n.setAttribute("src",M(n.getAttribute("src"),t.url))}function xe(e,t){const n=function(e){const t=T("div");return t.innerHTML=e,t}(e),i=n.querySelector("micro-app-head"),o=n.querySelector("micro-app-body");if(!i||!o){const e=`element ${i?"body":"head"} is missing`;return t.onerror(new Error(e)),y(e,t.name)}Ie(n,t),t.source.links.size?ue(n,t,i):t.onLoad(n),t.source.scripts.size?Ne(n,t):t.onLoad(n)}const Le=new class{constructor(){this.eventList=new Map}isLegalName(e){return!!e||(y("event-center: Invalid name"),!1)}on(e,t,n=!1){if(this.isLegalName(e)){if(!f(t))return y("event-center: Invalid callback function");let i=this.eventList.get(e);i?n&&Object.getOwnPropertyNames(i.data).length&&t(i.data):(i={data:{},callbacks:new Set},this.eventList.set(e,i)),i.callbacks.add(t)}}off(e,t){if(this.isLegalName(e)){const n=this.eventList.get(e);n&&(f(t)?n.callbacks.delete(t):n.callbacks.clear())}}dispatch(e,t){if(this.isLegalName(e)){if(!_(t))return y("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 Ue(e,t){return d(e)&&e?t?`__from_base_app_${e}__`:`__from_micro_app_${e}__`:""}class Te{addGlobalDataListener(e,t){const n=this.appName;n&&(e.__APP_NAME__=n,e.__AUTO_TRIGGER__=t),Le.on("global",e,t)}removeGlobalDataListener(e){f(e)&&Le.off("global",e)}setGlobalData(e){U(),Le.dispatch("global",e)}getGlobalData(){return Le.getData("global")}clearGlobalDataListener(){const e=this.appName,t=Le.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 Te{addDataListener(e,t,n){Le.on(Ue(N(e),!1),t,n)}removeDataListener(e,t){f(t)&&Le.off(Ue(N(e),!1),t)}getData(e,t=!1){return Le.getData(Ue(N(e),t))}setData(e,t){Le.dispatch(Ue(N(e),!0),t)}clearDataListener(e){Le.off(Ue(N(e),!1))}}class ke extends Te{constructor(e){super(),this.appName=N(e),!this.appName&&y(`Invalid appName ${e}`)}addDataListener(e,t){e.__AUTO_TRIGGER__=t,Le.on(Ue(this.appName,!0),e,t)}removeDataListener(e){f(e)&&Le.off(Ue(this.appName,!0),e)}getData(){return Le.getData(Ue(this.appName,!0))}dispatch(e){U(),Le.dispatch(Ue(this.appName,!1),e);const t=It.get(this.appName);if((null==t?void 0:t.container)&&_(e)){const n=new CustomEvent("datachange",{detail:{data:e}});$(t.container).dispatchEvent(n)}}clearDataListener(){Le.off(Ue(this.appName,!0))}}function Be(){It.forEach((e=>{e.container&&$(e.container).disconnectedCallback()})),!window.__MICRO_APP_UMD_MODE__&&It.clear()}function $e(){window.__MICRO_APP_ENVIRONMENT__&&(window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",Be,!1),window.addEventListener("unmount",Be,!1))}function Fe(e,t){if(t.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return t.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!function(e){var t;if(m(e.__MICRO_APP_IS_CONSTRUCTOR__))return e.__MICRO_APP_IS_CONSTRUCTOR__;const n=e.toString(),i=(null===(t=e.prototype)||void 0===t?void 0:t.constructor)===e&&Object.getOwnPropertyNames(e.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return e.__MICRO_APP_IS_CONSTRUCTOR__=i}(t)&&!function(e){return m(e.__MICRO_APP_IS_BOUND_FUNCTION__)?e.__MICRO_APP_IS_BOUND_FUNCTION__:e.__MICRO_APP_IS_BOUND_FUNCTION__=A(e)}(t)){const n=t.bind(e);for(const e in t)n[e]=t[e];return t.hasOwnProperty("prototype")&&c(n,"prototype",{value:t.prototype,configurable:!0,enumerable:!1,writable:!0}),t.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return t}const He=["unmount","appstate-change"];function Ke(e,t){var n;return He.includes(e)||("popstate"===e||"hashchange"===e)&&(null===(n=It.get(t))||void 0===n?void 0:n.useMemoryRouter)?`${e}-${t}`:e}const je=new Map;let Ge=!1;const Qe=new Map;function Ve(){const{rawDocument:e,rawDocumentAddEventListener:t,rawDocumentRemoveEventListener:n}=ve;!Ge&&function(){if(Ge=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return b("Cannot redefine document property onclick");const e=document.onclick;document.onclick=null;let t=!1;function n(e){je.forEach((t=>{f(t)&&t.call(document,e)}))}c(document,"onclick",{configurable:!0,enumerable:!0,get(){const e=L();return e?je.get(e):je.get("base")},set(e){const i=L();i?je.set(i,e):je.set("base",e),!t&&f(e)&&(t=!0,ve.rawDocumentAddEventListener.call(ve.rawDocument,"click",n,!1))}}),e&&(document.onclick=e)}(),document.addEventListener=function(n,i,o){var s;const r=L();if(r&&(!(null===(s=It.get(r))||void 0===s?void 0:s.umdMode)||!A(i))){const e=Qe.get(r);if(e){const t=e.get(n);t?t.add(i):e.set(n,new Set([i]))}else Qe.set(r,new Map([[n,new Set([i])]]));i&&(i.__MICRO_APP_MARK_OPTIONS__=o)}t.call(e,n,i,o)},document.removeEventListener=function(t,i,o){var s;const r=L();if(r&&(!(null===(s=It.get(r))||void 0===s?void 0:s.umdMode)||!A(i))){const e=Qe.get(r);if(e){const n=e.get(t);(null==n?void 0:n.size)&&n.has(i)&&n.delete(i)}}n.call(e,t,i,o)}}function qe(e,t,n){const i={microAppState:a({},null==t?void 0:t.microAppState,{[e]:n})};return a({},t,i)}function ze(e,t){var n;return(null===(n=null==t?void 0:t.microAppState)||void 0===n?void 0:n[e])||null}const Xe=/&/g,Ye=/=/g,Je=/%M1/g,Ze=/%M2/g;function et(e){return encodeURIComponent(nt(e).replace(Xe,"%M1").replace(Ye,"%M2"))}function tt(e){return nt(e).replace(Je,"&").replace(Ze,"=")}function nt(e){try{const t=decodeURIComponent(e);return e===t||Je.test(t)||Ze.test(t)?t:nt(t)}catch(t){return e}}function it(e){return`app-${e}`}function ot(e){var t,n;const i=ve.rawWindow.location,o=rt(i.search,i.hash),s=(null===(t=o.hashQuery)||void 0===t?void 0:t[it(e)])||(null===(n=o.searchQuery)||void 0===n?void 0:n[it(e)]);return d(s)?tt(s):null}function st(e,t){let{pathname:n,search:i,hash:o}=ve.rawWindow.location;const s=rt(i,o),r=et(t.pathname+t.search+t.hash);let a=!1;if(o&&!i){a=!0,s.hashQuery?s.hashQuery[it(e)]=r:s.hashQuery={[it(e)]:r};const t=o.includes("?")?o.slice(0,o.indexOf("?")+1):o+"?";o=t+j(s.hashQuery)}else s.searchQuery?s.searchQuery[it(e)]=r:s.searchQuery={[it(e)]:r},i="?"+j(s.searchQuery);return{fullPath:n+i+o,isAttach2Hash:a}}function rt(e,t){const n={};return""!==e&&"?"!==e&&(n.searchQuery=K(e.slice(1))),t.includes("?")&&(n.hashQuery=K(t.slice(t.indexOf("?")+1))),n}function at(e){const t=ve.rawWindow,n=n=>{if(Wt(!0).includes(e)&&!n.onlyForBrowser){const n=ot(e),i=It.get(e).sandBox.proxyWindow;let o=!1;const s=i.location.href;if(n){const t=i.location.hash;vt(e,n,i.location),o=i.location.hash!==t}!function(e,t,n){const i=new PopStateEvent(Ke("popstate",e),{state:ze(e,n)});ve.rawWindow.dispatchEvent(i),"function"==typeof t.onpopstate&&t.onpopstate(i)}(e,i,t.history.state),o&&function(e,t,n){const i=new HashChangeEvent(Ke("hashchange",e),{newURL:t.location.href,oldURL:n});ve.rawWindow.dispatchEvent(i),"function"==typeof t.onhashchange&&t.onhashchange(i)}(e,i,s),U()}};return t.addEventListener("popstate",n),()=>{t.removeEventListener("popstate",n)}}function ct(e,t){U(),function(e){const t=new PopStateEvent("popstate",{state:null});e&&(t.onlyForBrowser=!0),ve.rawWindow.dispatchEvent(t)}(e),t&&function(e){const t=new HashChangeEvent("hashchange",{newURL:ve.rawWindow.location.href,oldURL:e});ve.rawWindow.dispatchEvent(t)}(t)}function lt(e,t){const n=ve.rawWindow.history;return new Proxy(n,{get(i,o){return"state"===o?ze(e,n.state):f(Reflect.get(i,o))?(s=o,function(...i){if("pushState"!==s&&"replaceState"!==s||!d(i[2])&&!w(i[2]))n[s].apply(n,i);else{const o=E(i[2],t.href);if(o.origin===t.origin){ht(s,st(e,o),!0,qe(e,n.state,i[0]),i[1]);const r=o.pathname+o.search+o.hash;r!==t.fullPath&&vt(e,r,t)}else n[s].apply(n,i)}}):Reflect.get(i,o);var s},set:(e,t,n)=>Reflect.set(e,t,n)})}function ut(e,t,n=null,i=""){ve.rawWindow.history[e](n,i,t)}function ht(e,t,n,i,o){const s=ve.rawWindow.location,r=s.pathname+s.search+s.hash,a=t.isAttach2Hash&&r!==t.fullPath?s.href:null;ut(e,t.fullPath,i,o),r!==t.fullPath&&ct(n,a)}function pt(e,t){ht("replaceState",e,!0,t)}function dt(e){const t=ve.rawWindow;return function(...n){var i;if((null===(i=t.history.state)||void 0===i?void 0:i.microAppState)&&(!_(n[0])||!n[0].microAppState)&&(d(n[2])||w(n[2]))){const e=t.location.href;E(n[2],e).href===e&&(n[0]=a({},n[0],{microAppState:t.history.state.microAppState}))}e.apply(t.history,n)}}let mt=!1;const{router:ft,executeNavigationGuard:_t,clearRouterWhenUnmount:gt}=function(){function e(e,t,n,i){ht(t,st(e,n),!1,qe(e,ve.rawWindow.history.state,null!=i?i:null)),U()}function t(t){return function(n){const i=N(n.name);if(i&&d(n.path)){const o=It.get(i);if(o&&!o.sandBox)return y(`navigation failed, sandBox of app ${i} is closed`);if(Wt().includes(i)){const s=o.sandBox.proxyWindow.location,r=E(n.path,s.href),a=r.pathname+r.search+r.hash;if(s.fullPath!==a||ot(i)!==a){e(i,t&&!1!==n.replace||!0===n.replace?"replaceState":"pushState",r,n.state)}}else{const t=ve.rawWindow.location,o=E(n.path,t.origin),s=o.pathname+o.search+o.hash;ot(i)!==s&&e(i,!1===n.replace?"pushState":"replaceState",o,n.state)}}else y("navigation failed, name & path are required when use router."+(t?"replace":"push"))}}function n(e){return function(...t){return ve.rawWindow.history[e](...t)}}const i=G(),o=G();function r(e,t,n,i){U();for(const o of i)f(o)?o(e,t,n):_(o)&&f(o[e])&&o[e](t,n)}const a=function(){const e=new Map;return{add:function(t,n){return e.set(t,n),()=>!!e.has(t)&&e.delete(t)},get:t=>e.get(t),delete:t=>!!e.has(t)&&e.delete(t)}}(),c={current:new Map,encode:et,decode:tt,push:t(!1),replace:t(!0),go:n("go"),back:n("back"),forward:n("forward"),beforeEach:i.add,afterEach:o.add,setDefaultPage:function(e,t){return(e=N(e))?a.add(e,t):s},removeDefaultPage:function(e){return!!(e=N(e))&&a.delete(e)},getDefaultPage:a.get};return{router:c,executeNavigationGuard:function(e,t,n){c.current.set(e,t),r(e,t,n,i.list()),D((()=>{r(e,t,n,o.list())}))},clearRouterWhenUnmount:function(e){c.current.delete(e)}}}(),At=["href","pathname","search","hash"],wt=[...At,"host","hostname","port","protocol","search"],yt=[...wt,"origin","fullPath"];function bt(e,t){const n=a({name:e},t);for(const e of yt)n[e]=t[e];return n}function vt(e,t,n,i){const o=E(t,n.href),s=bt(e,n);for(const e of wt)At.includes(e)?n.shadowLocation[e]=o[e]:n[e]=o[e];const r=bt(e,n);("auto"===i||s.fullPath!==r.fullPath&&"prevent"!==i)&&_t(e,r,s)}function Et(e,t){!function(){if(!mt&&!window.__MICRO_APP_ENVIRONMENT__){mt=!0;const e=ve.rawWindow;e.history.pushState=dt(e.history.pushState),e.history.replaceState=dt(e.history.replaceState)}}();const n=function(e,t){const n=ve.rawWindow.location,i=E(t),s={href:i.href,pathname:i.pathname,search:i.search,hash:i.hash},r=(t,o)=>{const r=E(t,i.href);if(r.origin===i.origin){const i=st(e,r);if(r.pathname===s.pathname&&r.search===s.search){let e=null;return r.hash!==s.hash&&(i.isAttach2Hash&&(e=n.href),ut(o,i.fullPath)),void(r.hash?ct(!1,e):n.reload())}if(i.isAttach2Hash)return ut(o,i.fullPath),void n.reload();t=i.fullPath}return t};function c(e,t){return{enumerable:!0,configurable:!0,get:e,set:t}}function u(i,o){const r=E(i,t);r[o]===s[o]&&s.hash?ct(!1):(ut(r[o]===s[o]?"replaceState":"pushState",st(e,r).fullPath),n.reload())}l(i,{href:c((()=>s.href),(e=>{const t=r(e,"pushState");t&&(n.href=t)})),pathname:c((()=>s.pathname),(e=>{u(("/"+e).replace(/^\/+/,"/")+s.search+s.hash,"pathname")})),search:c((()=>s.search),(e=>{u(s.pathname+("?"+e).replace(/^\?+/,"?")+s.hash,"search")})),hash:c((()=>s.hash),(n=>{const i=s.pathname+s.search+("#"+n).replace(/^#+/,"#"),o=E(i,t);o.hash!==s.hash&&ht("pushState",st(e,o),!1)})),fullPath:c((()=>s.pathname+s.search+s.hash),o)});const h=e=>function(t){const i=r(t,"assign"===e?"pushState":"replaceState");i&&n[e](i)};return a(i,{assign:h("assign"),replace:h("replace"),reload:e=>n.reload(e),shadowLocation:s})}(e,t);return{microLocation:n,microHistory:lt(e,n)}}function Rt(e,t,n){n&&vt(e,n,t,"prevent"),pt(st(e,t),qe(e,ve.rawWindow.history.state,null)),function(e,t){_t(e,bt(e,t),bt(e,t))}(e,t)}function Pt(e){pt(function(e,t){var n,i,o,s;let{pathname:r,search:a,hash:c}=t||ve.rawWindow.location;const l=rt(a,c);let u=!1;if(null===(n=l.hashQuery)||void 0===n?void 0:n[it(e)]){u=!0,null===(i=l.hashQuery)||void 0===i||delete i[it(e)];const t=j(l.hashQuery);c=c.slice(0,c.indexOf("?")+Number(Boolean(t)))+t}else if(null===(o=l.searchQuery)||void 0===o?void 0:o[it(e)]){null===(s=l.searchQuery)||void 0===s||delete s[it(e)];const t=j(l.searchQuery);a=t?"?"+t:""}return{fullPath:r+a+c,isAttach2Hash:u}}(e),function(e,t){return _(null==t?void 0:t.microAppState)&&(h(t.microAppState[e])||delete t.microAppState[e],Object.keys(t.microAppState).length||delete t.microAppState),a({},t)}(e,ve.rawWindow.history.state))}const Nt=["__REACT_ERROR_OVERLAY_GLOBAL_HOOK__","System","__cjsWrapper"],Ct=["location"],Mt=["window","self","globalThis"];class St{constructor(e,t,n=!0){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,t,n),a(this,function(e){const t=e.__MICRO_APP_NAME__,n=new Map,i=new Map,o=new Map,{rawWindow:s,rawDocument:r,rawWindowAddEventListener:a,rawWindowRemoveEventListener:c,rawSetInterval:l,rawSetTimeout:u,rawClearInterval:h,rawClearTimeout:p,rawDocumentRemoveEventListener:d}=ve;e.addEventListener=function(e,i,o){e=Ke(e,t);const r=n.get(e);r?r.add(i):n.set(e,new Set([i])),i&&(i.__MICRO_APP_MARK_OPTIONS__=o),a.call(s,e,i,o)},e.removeEventListener=function(e,i,o){e=Ke(e,t);const r=n.get(e);(null==r?void 0:r.size)&&r.has(i)&&r.delete(i),c.call(s,e,i,o)},e.setInterval=function(e,t,...n){const o=l.call(s,e,t,...n);return i.set(o,{handler:e,timeout:t,args:n}),o},e.setTimeout=function(e,t,...n){const i=u.call(s,e,t,...n);return o.set(i,{handler:e,timeout:t,args:n}),i},e.clearInterval=function(e){i.delete(e),h.call(s,e)},e.clearTimeout=function(e){o.delete(e),p.call(s,e)};const m=new Map,f=new Map;let _,g=new Map,A=new Map;return{recordUmdEffect:()=>{n.forEach(((e,t)=>{e.size&&m.set(t,new Set(e))})),i.size&&(g=new Map(i)),o.size&&(A=new Map(o)),_=je.get(t);const e=Qe.get(t);e&&e.forEach(((e,t)=>{e.size&&f.set(t,new Set(e))}))},rebuildUmdEffect:()=>{m.forEach(((t,n)=>{for(const i of t)e.addEventListener(n,i,null==i?void 0:i.__MICRO_APP_MARK_OPTIONS__)})),g.forEach((t=>{e.setInterval(t.handler,t.timeout,...t.args)})),A.forEach((t=>{e.setTimeout(t.handler,t.timeout,...t.args)})),_&&je.set(t,_),I(t),f.forEach(((e,t)=>{for(const n of e)document.addEventListener(t,n,null==n?void 0:n.__MICRO_APP_MARK_OPTIONS__)})),I(null)},releaseEffect:()=>{n.size&&(n.forEach(((e,t)=>{for(const n of e)c.call(s,t,n)})),n.clear()),i.size&&(i.forEach(((e,t)=>{h.call(s,t)})),i.clear()),o.size&&(o.forEach(((e,t)=>{p.call(s,t)})),o.clear()),je.delete(t);const e=Qe.get(t);e&&(e.forEach(((e,t)=>{for(const n of e)d.call(r,t,n)})),e.clear())}}}(this.microAppWindow))}start(e,t=!0,n=""){this.active||(this.active=!0,t?(this.initRouteState(n),this.removeHistoryListener=at(this.proxyWindow.__MICRO_APP_NAME__)):this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,1==++St.activeCount&&(Ve(),ge(),$e()),ve.rawWindow._babelPolyfill&&(ve.rawWindow._babelPolyfill=!1))}stop(e=!1){this.active&&(this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),this.injectedKeys.forEach((e=>{Reflect.deleteProperty(this.microAppWindow,e)})),this.injectedKeys.clear(),this.escapeKeys.forEach((e=>{Reflect.deleteProperty(ve.rawWindow,e)})),this.escapeKeys.clear(),this.removeHistoryListener&&(this.clearRouteState(e),this.removeHistoryListener()),0==--St.activeCount&&(document.addEventListener=ve.rawDocumentAddEventListener,document.removeEventListener=ve.rawDocumentRemoveEventListener,ye()),this.active=!1)}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),function(e){const t=e.appName;e.umdDataListeners={global:new Set,normal:new Set};const n=Le.eventList.get("global");if(n)for(const i of n.callbacks)t===i.__APP_NAME__&&e.umdDataListeners.global.add(i);const i=Le.eventList.get(Ue(t,!0));i&&(e.umdDataListeners.normal=new Set(i.callbacks))}(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach((e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,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.microAppWindow.microApp)}getSpecialProperties(e){var t;_($t.plugins)&&(this.commonActionForSpecialProperties($t.plugins.global),this.commonActionForSpecialProperties(null===(t=$t.plugins.modules)||void 0===t?void 0:t[e]))}commonActionForSpecialProperties(e){if(r(e))for(const t of e)_(t)&&(r(t.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(t.scopeProperties)),r(t.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(t.escapeProperties)))}createProxyWindow(e){const t=ve.rawWindow,n=new Map;return new Proxy(this.microAppWindow,{get:(n,i)=>{if(x(e),Reflect.has(n,i)||d(i)&&/^__MICRO_APP_/.test(i)||this.scopeProperties.includes(i))return Reflect.get(n,i);const o=Reflect.get(t,i);return f(o)?Fe(t,o):o},set:(e,n,i)=>{if(this.active){if(Ct.includes(n))Reflect.set(t,n,i);else if(u.call(e,n)||!u.call(t,n)||this.scopeProperties.includes(n))Reflect.set(e,n,i),this.injectedKeys.add(n);else{const o=Object.getOwnPropertyDescriptor(t,n),{configurable:s,enumerable:r,writable:a,set:l}=o;c(e,n,{value:i,configurable:s,enumerable:r,writable:null!=a?a:!!l}),this.injectedKeys.add(n)}(this.escapeProperties.includes(n)||Nt.includes(n)&&!Reflect.has(t,n))&&!this.scopeProperties.includes(n)&&(Reflect.set(t,n,i),this.escapeKeys.add(n))}return!0},has:(e,n)=>this.scopeProperties.includes(n)?n in e:n in e||n in t,getOwnPropertyDescriptor:(e,i)=>{if(u.call(e,i))return n.set(i,"target"),Object.getOwnPropertyDescriptor(e,i);if(u.call(t,i)){n.set(i,"rawWindow");const e=Object.getOwnPropertyDescriptor(t,i);return e&&!e.configurable&&(e.configurable=!0),e}},defineProperty:(e,i,o)=>"rawWindow"===n.get(i)?Reflect.defineProperty(t,i,o):Reflect.defineProperty(e,i,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)=>!u.call(e,n)||(this.injectedKeys.has(n)&&this.injectedKeys.delete(n),this.escapeKeys.has(n)&&Reflect.deleteProperty(t,n),Reflect.deleteProperty(e,n))})}initMicroAppWindow(e,t,n,i){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=t,e.__MICRO_APP_URL__=n,e.__MICRO_APP_PUBLIC_PATH__=C(n),e.__MICRO_APP_WINDOW__=e,e.microApp=a(new ke(t),{removeDomScope:U,pureCreateElement:T,router:ft}),e.rawWindow=ve.rawWindow,e.rawDocument=ve.rawDocument,e.hasOwnProperty=t=>u.call(e,t)||u.call(ve.rawWindow,t),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,t),i&&this.setRouterApi(e,t,n)}setMappingPropertiesWithRawDescriptor(e){let t,n;const i=ve.rawWindow;i===i.parent?t=n=this.proxyWindow:(t=i.top,n=i.parent),c(e,"top",this.createDescriptorForMicroAppWindow("top",t)),c(e,"parent",this.createDescriptorForMicroAppWindow("parent",n)),Mt.forEach((t=>{c(e,t,this.createDescriptorForMicroAppWindow(t,this.proxyWindow))}))}createDescriptorForMicroAppWindow(e,t){const{configurable:n=!0,enumerable:i=!0,writable:o,set:s}=Object.getOwnPropertyDescriptor(ve.rawWindow,e)||{writable:!0};return{value:t,configurable:n,enumerable:i,writable:null!=o?o:!!s}}setHijackProperties(e,t){let n,i;l(e,{document:{configurable:!1,enumerable:!0,get:()=>(x(t),ve.rawDocument)},eval:{configurable:!0,enumerable:!1,get:()=>(x(t),n||eval),set:e=>{n=e}},Image:{configurable:!0,enumerable:!1,get:()=>(x(t),i||ve.ImageProxy),set:e=>{i=e}}})}setRouterApi(e,t,n){const{microLocation:i,microHistory:o}=Et(t,n);l(e,{location:{configurable:!1,enumerable:!0,get:()=>i,set:e=>{ve.rawWindow.location=e}},history:{configurable:!0,enumerable:!0,get:()=>o}})}initRouteState(e){!function(e,t,n){const i=ot(e);i?vt(e,i,t,"auto"):Rt(e,t,n)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location,e)}clearRouteState(e){!function(e,t,n,i){if(!i){const{pathname:i,search:o,hash:s}=E(t);vt(e,i+o+s,n,"prevent")}Pt(e),gt(e)}(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.__MICRO_APP_URL__,this.proxyWindow.location,e)}setRouteInfoForKeepAliveApp(){Rt(this.proxyWindow.__MICRO_APP_NAME__,this.proxyWindow.location)}removeRouteInfoForKeepAliveApp(){Pt(this.proxyWindow.__MICRO_APP_NAME__)}}function Dt(e,t,n,i){var o;if(!e)return y(`element does not exist in lifecycle ${n}`,t);e=$(e),U();const s=a({name:t,container:e},i&&{error:i}),r=new CustomEvent(n,{detail:s});!function(e,t){Object.defineProperties(e,{currentTarget:{get:()=>t},target:{get:()=>t}})}(r,e),f(null===(o=$t.lifeCycles)||void 0===o?void 0:o[n])&&$t.lifeCycles[n](r),e.dispatchEvent(r)}function Ot(e,t,n={}){const i=new CustomEvent(Ke(e,t),{detail:n});window.dispatchEvent(i)}St.activeCount=0;const It=new Map;class xt{constructor({name:e,url:t,ssrUrl:n,container:i,inline:o,scopecss:s,useSandbox:r,useMemoryRouter:a,baseroute:c,keepRouteState:l,defaultPage:u}){this.state=V.CREATED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.sandBox=null,this.container=null!=i?i:null,this.inline=null!=o&&o,this.baseroute=null!=c?c:"",this.keepRouteState=null!=l&&l,this.ssrUrl=null!=n?n:"",this.name=e,this.url=t,this.useSandbox=r,this.scopecss=this.useSandbox&&s,this.useMemoryRouter=this.useSandbox&&a,this.defaultPage=null!=u?u:"",this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new St(e,t,this.useMemoryRouter))}loadSourceCode(){var e;this.state=V.LOADING,Y((e=this).ssrUrl||e.url,e.name,{cache:"no-cache"}).then((t=>{if(!t){const t="html is empty, please check in detail";return e.onerror(new Error(t)),y(t,e.name)}xe(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=>{y(`Failed to fetch data from ${e.url}, micro-app stop rendering`,e.name,t),e.onLoadError(t)}))}onLoad(e){var t;2==++this.loadSourceLevel&&(this.source.html=e,this.isPrefetch?(null===(t=this.prefetchResolve)||void 0===t||t.call(this),this.prefetchResolve=null):V.UNMOUNT!==this.state&&(this.state=V.LOADED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),V.UNMOUNT!==this.state&&(this.onerror(e),this.state=V.LOAD_FAILED)}mount(e,t,n,i,o){var s,r,a;if(m(t)&&(this.inline=t),m(i)&&(this.keepRouteState=i),this.container=null!==(s=this.container)&&void 0!==s?s:e,this.baseroute=null!=n?n:this.baseroute,this.defaultPage=null!=o?o:this.defaultPage,2!==this.loadSourceLevel)return void(this.state=V.LOADING);let c;if(Dt(this.container,this.name,q.BEFOREMOUNT),this.state=V.MOUNTING,W(this.source.html,this.container,!this.umdMode),null===(r=this.sandBox)||void 0===r||r.start(this.baseroute,this.useMemoryRouter,this.defaultPage),this.umdMode){null===(a=this.sandBox)||void 0===a||a.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(e){y("an error occurred in the mount function \n",this.name,e)}this.handleMounted(c)}else{let e=!1;!function(e,t,n){const i=Array.from(e.entries()),o=[],s=[];for(const[e,r]of i)r.isDynamic||(r.defer||r.async?(r.isExternal&&!r.code?o.push(Y(e,t.name)):o.push(r.code),s.push([e,r]),r.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Ce(e,t,r,!1),n(!1)));o.length?S(o,(e=>{const t=s[e.index][1];t.code=t.code||e.data}),(e=>{n.errorCount=n.errorCount?++n.errorCount:1,y(e,t.name)}),(()=>{s.forEach((([e,i])=>{i.code&&(Ce(e,t,i,!1,n),!i.module&&n(!1))})),n(h(n.moduleCount)||n.errorCount===o.length)})):n(!0)}(this.source.scripts,this,(t=>{var n;if(!this.umdMode){const{mount:e,unmount:t}=this.getUmdLibraryHooks();if(f(e)&&f(t)){this.umdHookMount=e,this.umdHookUnmount=t,this.umdMode=!0,null===(n=this.sandBox)||void 0===n||n.recordUmdSnapshot();try{c=this.umdHookMount()}catch(e){y("an error occurred in the mount function \n",this.name,e)}}}e||!0!==t&&!this.umdMode||(e=!0,this.handleMounted(c))}))}}handleMounted(e){g(e)?e.then((()=>this.dispatchMountedEvent())).catch((e=>this.onerror(e))):this.dispatchMountedEvent()}dispatchMountedEvent(){V.UNMOUNT!==this.state&&(this.state=V.MOUNTED,Dt(this.container,this.name,q.MOUNTED))}unmount(e,t){let n;if(this.state===V.LOAD_FAILED&&(e=!0),this.state=V.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null,this.umdHookUnmount)try{n=this.umdHookUnmount()}catch(e){y("an error occurred in the unmount function \n",this.name,e)}Ot("unmount",this.name),this.handleUnmounted(e,n,t)}handleUnmounted(e,t,n){g(t)?t.then((()=>this.actionsForUnmount(e,n))).catch((()=>this.actionsForUnmount(e,n))):this.actionsForUnmount(e,n)}actionsForUnmount(e,t){var n;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&W(this.container,this.source.html,!1),null===(n=this.sandBox)||void 0===n||n.stop(this.keepRouteState&&!e),Wt().length||(we=!1,Element.prototype.setAttribute=ve.rawSetAttribute),Dt(this.container,this.name,q.UNMOUNT),this.container.innerHTML="",this.container=null,t&&t()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],It.delete(this.name)}hiddenKeepAliveApp(){var e;const t=this.container;W(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=z.KEEP_ALIVE_HIDDEN,Ot("appstate-change",this.name,{appState:"afterhidden"}),Dt(t,this.name,q.AFTERHIDDEN),null===(e=this.sandBox)||void 0===e||e.removeRouteInfoForKeepAliveApp()}showKeepAliveApp(e){var t;Ot("appstate-change",this.name,{appState:"beforeshow"}),Dt(e,this.name,q.BEFORESHOW),W(this.container,e,!1),this.container=e,this.keepAliveState=z.KEEP_ALIVE_SHOW,null===(t=this.sandBox)||void 0===t||t.setRouteInfoForKeepAliveApp(),Ot("appstate-change",this.name,{appState:"aftershow"}),Dt(this.container,this.name,q.AFTERSHOW)}onerror(e){Dt(this.container,this.name,q.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,t;if(V.UNMOUNT!==this.state){const n=null!==(t=null===(e=this.sandBox)||void 0===e?void 0:e.proxyWindow)&&void 0!==t?t:ve.rawWindow;return this.libraryName=$(this.container).getAttribute("library")||`micro-app-${this.name}`,"object"==typeof n[this.libraryName]?n[this.libraryName]:{}}return{}}}function Lt(e){class n extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=t,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const e=N(this.getAttribute("name")),t=P(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",e)&&this.legalAttribute("url",t)){const n=It.get(e);if(e!==this.appName&&n&&V.UNMOUNT!==n.getAppState()&&z.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState()&&!n.isPrefetch)return this.setAttribute("name",this.appName),y(`app name conflict, an app named ${e} is running`,this.appName);e===this.appName&&t===this.appUrl||(e===this.appName?this.handleUnmount(!0,(()=>{this.actionsForAttributeChange(e,t,n)})):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(e,t,n)):this.handleUnmount(this.getDestroyCompatibleResult(),(()=>{this.actionsForAttributeChange(e,t,n)})))}else e!==this.appName&&this.setAttribute("name",this.appName)},we||(we=!0,Element.prototype.setAttribute=function(e,t){if(/^micro-app(-\S+)?/i.test(this.tagName)&&"data"===e)if(_(t)){const e={};Object.getOwnPropertyNames(t).forEach((n=>{d(n)&&0===n.indexOf("__")||(e[n]=t[n])})),this.data=e}else"[object Object]"!==t&&b("property data must be an object",this.getAttribute("name"));else if((("src"===e||"srcset"===e)&&/^(img|script)$/i.test(this.tagName)||"href"===e&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&It.has(this.__MICRO_APP_NAME__)){const n=It.get(this.__MICRO_APP_NAME__);ve.rawSetAttribute.call(this,e,M(t,n.url))}else ve.rawSetAttribute.call(this,e,t)})}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,v((()=>Dt(this,this.appName,q.CREATED))),this.initialMount()}disconnectedCallback(){this.hasConnected=!1;const e=It.get(this.appName);e&&e.getAppState()!==V.UNMOUNT&&e.getKeepAliveState()!==z.KEEP_ALIVE_HIDDEN&&(this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult()))}attributeChangedCallback(e,t,n){if(this.legalAttribute(e,n)&&this[e===Q.NAME?"appName":"appUrl"]!==n)if(e!==Q.URL||this.appUrl)if(e!==Q.NAME||this.appName)this.isWaiting||(this.isWaiting=!0,v(this.handleAttributeUpdate));else{const e=N(n);if(!e)return y(`Invalid attribute name ${n}`,this.appName);this.cacheData&&($t.setData(e,this.cacheData),this.cacheData=null),this.appName=e,e!==n&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else{if(!(n=P(n,this.appName)))return y(`Invalid attribute url ${n}`,this.appName);this.appUrl=n,this.handleInitialNameAndUrl()}}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(this.appName&&this.appUrl)if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&f(this.attachShadow)&&this.attachShadow({mode:"open"}),this.updateSsrUrl(this.appUrl),It.has(this.appName)){const e=It.get(this.appName),t=e.ssrUrl||e.url,n=this.ssrUrl||this.appUrl;e.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN&&e.url===this.appUrl?this.handleShowKeepAliveApp(e):t!==n||!e.isPrefetch&&e.getAppState()!==V.UNMOUNT?e.isPrefetch||e.getAppState()===V.UNMOUNT?(b(`the ${e.isPrefetch?"prefetch":"unmounted"} app with url: ${t} is replaced by a new app`,this.appName),this.handleCreateApp()):y(`app name conflict, an app named ${this.appName} is running`,this.appName):this.handleAppMount(e)}else this.handleCreateApp()}actionsForAttributeChange(e,t,n){var i;this.updateSsrUrl(t),this.appName=e,this.appUrl=t,(null!==(i=this.shadowRoot)&&void 0!==i?i:this).innerHTML="",e!==this.getAttribute("name")&&this.setAttribute("name",this.appName),n?n.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN?n.url===this.appUrl?this.handleShowKeepAliveApp(n):y(`app name conflict, an app named ${this.appName} is running`,this.appName):n.url===this.appUrl&&n.ssrUrl===this.ssrUrl?this.handleAppMount(n):this.handleCreateApp():this.handleCreateApp()}legalAttribute(e,t){return!(!d(t)||!t)||(y(`unexpected attribute ${e}, please check again`,this.appName),!1)}handleAppMount(e){e.isPrefetch=!1,v((()=>{var t;return e.mount(null!==(t=this.shadowRoot)&&void 0!==t?t:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible(),this.getDisposeResult("keep-router-state"),this.getDefaultPageValue())}))}handleCreateApp(){var e;It.has(this.appName)&&It.get(this.appName).actionsForCompletelyDestroy();const t=new xt({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:null!==(e=this.shadowRoot)&&void 0!==e?e:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),useMemoryRouter:!this.getDisposeResult("disable-memory-router"),baseroute:this.getBaseRouteCompatible(),keepRouteState:this.getDisposeResult("keep-router-state"),defaultPage:this.getDefaultPageValue()});It.set(this.appName,t)}handleUnmount(e,t){const n=It.get(this.appName);n&&n.getAppState()!==V.UNMOUNT&&n.unmount(e,t)}handleHiddenKeepAliveApp(){const e=It.get(this.appName);e&&e.getAppState()!==V.UNMOUNT&&e.getKeepAliveState()!==z.KEEP_ALIVE_HIDDEN&&e.hiddenKeepAliveApp()}handleShowKeepAliveApp(e){v((()=>{var t;return e.showKeepAliveApp(null!==(t=this.shadowRoot)&&void 0!==t?t:this)}))}getDisposeResult(e){return(this.compatibleSpecialProperties(e)||$t[e])&&this.compatibleDisableSpecialProperties(e)}compatibleSpecialProperties(e){return"disableScopecss"===e?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):"disableSandbox"===e?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(e)}compatibleDisableSpecialProperties(e){return"disableScopecss"===e?"false"!==this.getAttribute("disableScopecss")&&"false"!==this.getAttribute("disable-scopecss"):"disableSandbox"===e?"false"!==this.getAttribute("disableSandbox")&&"false"!==this.getAttribute("disable-sandbox"):"false"!==this.getAttribute(e)}getBaseRouteCompatible(){var e,t;return null!==(t=null!==(e=this.getAttribute("baseroute"))&&void 0!==e?e:this.getAttribute("baseurl"))&&void 0!==t?t:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}updateSsrUrl(e){if(this.getDisposeResult("ssr"))if(this.getDisposeResult("disable-memory-router")){const t=ve.rawWindow.location;this.ssrUrl=M(t.pathname+t.search,e)}else{let t=function(e,t){const n=ot(e);if(!n)return"";const i=E(n,t);return i.origin+i.pathname+i.search}(this.appName,e);const n=this.getDefaultPageValue();if(!t&&n){const i=E(n,e);t=i.origin+i.pathname+i.search}this.ssrUrl=t}else this.ssrUrl&&(this.ssrUrl="")}getDefaultPageValue(){var e,t,n;return null!==(n=null!==(t=null!==(e=ft.getDefaultPage(this.appName))&&void 0!==e?e:this.getAttribute("default-page"))&&void 0!==t?t:this.getAttribute("defaultPage"))&&void 0!==n?n:""}set data(e){this.appName?$t.setData(this.appName,e):this.cacheData=e}get data(){return this.appName?$t.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(e,n)}function Ut(e){if(!n)return y("preFetch is only supported in browser environment");D((()=>{f(e)&&(e=e()),r(e)&&e.reduce(((e,t)=>e.then((()=>{return e=t,new Promise((t=>{D((()=>{var n,i,o;if(_(e)&&navigator.onLine)if(e.name=N(e.name),e.url=P(e.url,e.name),e.name&&e.url&&!It.has(e.name)){const s=new xt({name:e.name,url:e.url,scopecss:!(null!==(n=e.disableScopecss)&&void 0!==n?n:$t.disableScopecss),useSandbox:!(null!==(i=e.disableSandbox)&&void 0!==i?i:$t.disableSandbox),useMemoryRouter:!(null!==(o=e.disableMemoryRouter)&&void 0!==o?o:$t.disableMemoryRouter)});s.isPrefetch=!0,s.prefetchResolve=t,It.set(e.name,s)}else t();else t()}))}));var e}))),Promise.resolve())}))}function Tt(e,t,n){if(r(e)){const i=e.filter((e=>d(e)&&e.includes(`.${t}`)&&!n.has(e)));S(i.map((e=>Y(e))),(e=>{const t=i[e.index];n.has(t)||n.set(t,e.data)}),(e=>{y(e)}))}}function Wt(e){const t=[];return It.forEach(((n,i)=>{V.UNMOUNT===n.getAppState()||n.isPrefetch||e&&z.KEEP_ALIVE_HIDDEN===n.getKeepAliveState()||t.push(i)})),t}function kt(e,t){const n=It.get(N(e));return new Promise((i=>{if(n)if(n.getAppState()===V.UNMOUNT||n.isPrefetch)(null==t?void 0:t.destroy)&&n.actionsForCompletelyDestroy(),i();else if(n.getKeepAliveState()===z.KEEP_ALIVE_HIDDEN)(null==t?void 0:t.destroy)?n.unmount(!0,i):(null==t?void 0:t.clearAliveState)?n.unmount(!1,i):i();else{const e=$(n.container),o=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",s),i()},s=()=>{e.removeEventListener("unmount",o),e.removeEventListener("afterhidden",s),i()};if(e.addEventListener("unmount",o),e.addEventListener("afterhidden",s),null==t?void 0:t.destroy){let t,n;e.hasAttribute("destroy")&&(t=e.getAttribute("destroy")),e.hasAttribute("destory")&&(n=e.getAttribute("destory")),e.setAttribute("destroy","true"),e.parentNode.removeChild(e),e.removeAttribute("destroy"),"string"==typeof t&&e.setAttribute("destroy",t),"string"==typeof n&&e.setAttribute("destory",n)}else if((null==t?void 0:t.clearAliveState)&&e.hasAttribute("keep-alive")){const t=e.getAttribute("keep-alive");e.removeAttribute("keep-alive"),e.parentNode.removeChild(e),e.setAttribute("keep-alive",t)}else e.parentNode.removeChild(e)}else b(`app ${e} does not exist`),i()}))}class Bt extends We{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=Ut,this.router=ft}start(e){if(!n||!window.customElements)return y("micro-app is not supported in this environment");if(null==e?void 0:e.tagName){if(!/^micro-app(-\S+)?/.test(e.tagName))return y(`${e.tagName} is invalid tagName`);this.tagName=e.tagName}if(window.customElements.get(this.tagName))return b(`element ${this.tagName} is already defined`);if(Ee(),e&&_(e)&&(this.shadowDOM=e.shadowDOM,this.destroy=e.destroy,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.disableMemoryRouter=e.disableMemoryRouter,this.ssr=e.ssr,f(e.fetch)&&(this.fetch=e.fetch),_(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&Ut(e.preFetchApps),e.globalAssets&&(_(t=e.globalAssets)&&D((()=>{Tt(t.js,"js",Re),Tt(t.css,"css",ce)}))),_(e.plugins))){const t=e.plugins.modules;if(_(t))for(const e in t){const n=N(e);n&&e!==n&&(t[n]=t[e],delete t[e])}this.plugins=e.plugins}var t;Lt(this.tagName)}}var $t=new Bt;e.EventCenterForMicroApp=ke,e.MicroApp=Bt,e.default=$t,e.getActiveApps=Wt,e.getAllApps=function(){return Array.from(It.keys())},e.preFetch=Ut,e.pureCreateElement=T,e.removeDomScope=U,e.unmountAllApps=function(e){return Array.from(It.keys()).reduce(((t,n)=>t.then((()=>kt(n,e)))),Promise.resolve())},e.unmountApp=kt,e.version=t,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@micro-zoe/micro-app",
"version": "0.8.5",
"version": "1.0.0-alpha.0",
"description": "A lightweight, efficient and powerful micro front-end framework",

@@ -47,3 +47,3 @@ "private": false,

"test:coverage": "jest --coverage",
"prepublishOnly": "yarn lint && yarn test && yarn build"
"prepublishOnly": "yarn build"
},

@@ -50,0 +50,0 @@ "repository": {

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

For more commands, see [DEVELP](https://github.com/micro-zoe/micro-app/blob/master/DEVELOP.md)
For more commands, see [DEVELOP](https://github.com/micro-zoe/micro-app/blob/master/DEVELOP.md)

@@ -156,7 +156,7 @@ # FAQ

# Contributors
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://micro-zoe.com/contributors.svg?height=55&people=11" /></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://contrib.rocks/image?repo=micro-zoe/micro-app" />
</a>
# License
[MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)

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

# 如何使用
微前端分为基座应用(也可以叫做主应用)和子应用。
## 主应用
这里以一种比较常见的情况举例:基座应用使用vue框架,采用history路由,子应用使用react框架,采用hash路由,我们分别列出基座应用和子应用需要进行的修改,具体介绍micro-app的使用方式。
## 基座应用
**1、安装依赖**

@@ -58,7 +54,4 @@ ```bash

```html
<!-- my-page.vue -->
<template>
<!-- 👇 name为应用名称,url为应用地址 -->
<micro-app name='my-app' url='http://localhost:3000/'></micro-app>
</template>
<!-- 👇 name为应用名称,url为应用地址 -->
<micro-app name='my-app' url='http://localhost:3000/'></micro-app>
```

@@ -77,3 +70,3 @@

以上微前端基本渲染完成,效果如下:
以上即完成微前端的嵌入,效果如下:

@@ -85,3 +78,3 @@ <img src="https://img12.360buyimg.com/imagetools/jfs/t1/196940/34/1541/38365/610a14fcE46c21374/c321b9f8fa50a8fc.png" alt="result" width='900'/>

# 🤝 参与共建
如果您对这个项目感兴趣,欢迎提 pull request,也欢迎 "Star" 支持一下 ^_^
如果您对这个项目感兴趣,欢迎参与贡献,也欢迎 "Star" 支持一下 ^_^

@@ -160,7 +153,8 @@ ### 本地运行

# 贡献者们
<a href="https://github.com/micro-zoe/micro-app/graphs/contributors"><img src="https://micro-zoe.com/contributors.svg?height=55&people=11" /></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://contrib.rocks/image?repo=micro-zoe/micro-app" />
</a>
# License
[MIT License](https://github.com/micro-zoe/micro-app/blob/master/LICENSE)
declare module '@micro-app/types' {
type AttrType = string | null
type NormalKey = string | number
type Func = (...rest: any[]) => void

@@ -11,4 +13,8 @@

microAppWindow: Window // Proxy target
start (baseRoute: string): void
stop (): void
start (
baseRoute: string,
useMemoryRouter: boolean,
defaultPage: string,
): void
stop (keepRouteState: boolean): void
// record umd snapshot before the first execution of umdHookMount

@@ -18,2 +24,4 @@ recordUmdSnapshot (): void

rebuildUmdSnapshot (): void
setRouteInfoForKeepAliveApp (): void
removeRouteInfoForKeepAliveApp (): void
}

@@ -55,6 +63,9 @@

useSandbox: boolean // whether use js sandbox, default is true
useMemoryRouter: boolean // whether use memoryRouter, default is true
baseroute: string // route prefix, default is ''
keepRouteState: boolean // keep route state when unmount, default is false
source: sourceType // sources of css, js, html
sandBox: SandBoxInterface | null // sandbox
umdMode: boolean // is umd mode
defaultPage: string // default page when mount

@@ -75,2 +86,4 @@ // Load resources

baseroute?: string,
keepRouteState?: boolean,
defaultPage?: string,
): void

@@ -118,2 +131,3 @@

disableSandbox?: boolean
disableMemoryRouter?: boolean
shadowDOM?: boolean

@@ -176,2 +190,3 @@ }

disableSandbox?: boolean
disableMemoryRouter?: boolean
ssr?: boolean

@@ -193,2 +208,3 @@ lifeCycles?: lifeCyclesType

disableSandbox?: boolean
disableMemoryRouter?: boolean
ssr?: boolean

@@ -199,2 +215,3 @@ lifeCycles?: lifeCyclesType

preFetch(apps: prefetchParamList): void
router: Router // eslint-disable-line
start(options?: OptionsType): void

@@ -205,2 +222,127 @@ }

type CallableFunctionForInteract = CallableFunction & { __APP_NAME__?: string, __AUTO_TRIGGER__?: boolean }
interface ShadowLocation {
[k: string]: string
}
interface MicroLocation extends Location, URL {
// shadowLocation is the current location information (href, pathname, search, hash)
shadowLocation: ShadowLocation
fullPath: string
[key: string]: any
}
type MicroHistory = ProxyHandler<History>
type MicroState = any
type HistoryProxyValue =
Pick<
History,
'length' |
'scrollRestoration' |
'state' |
'back' |
'forward' |
'go' |
'pushState' |
'replaceState'
> | CallableFunction
interface MicroRouter {
microLocation: MicroLocation
microHistory: MicroHistory
}
type LocationQueryValue = string | null
type LocationQueryObject = Record<
string,
LocationQueryValue | LocationQueryValue[]
>
type LocationQuery = {
hashQuery?: LocationQueryObject,
searchQuery?: LocationQueryObject
}
type GuardLocation = Record<keyof MicroLocation, any>
type CurrentRoute = Map<string, GuardLocation>
interface RouterTarget {
name: string
path: string
state?: unknown
replace?: boolean
}
type navigationMethod = (to: RouterTarget) => void
interface AccurateGuard {
[appName: string]: (to: GuardLocation, from: GuardLocation) => void
}
type GlobalNormalGuard = ((appName: string, to: GuardLocation, from: GuardLocation) => void)
type RouterGuard = AccurateGuard | GlobalNormalGuard
// Router API for developer
interface Router {
// current route of all apps
readonly current: CurrentRoute
/**
* encodeURI of microApp path
* @param path url path
*/
encode(path: string): string
/**
* decodeURI of microApp path
* @param path url path
*/
decode(path: string): ReturnType<Router['encode']>
/**
* Navigate to a new URL by pushing an entry in the history
* stack.
* @param to - Route location to navigate to
*/
push: navigationMethod
/**
* Navigate to a new URL by replacing the current entry in
* the history stack.
*
* @param to - Route location to navigate to
*/
replace: navigationMethod
/**
* Move forward or backward through the history. calling `history.go()`.
*
* @param delta - The position in the history to which you want to move,
* relative to the current page
*/
go: Func
/**
* Go back in history if possible by calling `history.back()`.
*/
back: Func
/**
* Go forward in history if possible by calling `history.forward()`.
*/
forward: Func
/**
* Add a navigation guard that executes before any navigation
* @param guard global hook for
*/
beforeEach(guard: RouterGuard): () => boolean
/**
* Add a navigation guard that executes after any navigation
* @param guard global hook for
*/
afterEach(guard: RouterGuard): () => boolean
setDefaultPage(appName: string, path: string): () => boolean
removeDefaultPage(appName: string): boolean
getDefaultPage(key: PropertyKey): string | undefined
}
// result of add/remove microApp path on browser url
type HandleMicroPathResult = {
fullPath: string,
isAttach2Hash: boolean,
}
}

@@ -207,0 +349,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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