import { ScriptResultList } from "./entry"; import { SandboxCache } from "./common"; import { EventBus, EventObj } from "./event"; import { EventCleanupTracker } from "./tracker"; import { plugin, loadErrorHandler } from "./index"; export type lifecycle = (appWindow: Window) => any; type lifecycles = { beforeLoad: lifecycle; beforeMount: lifecycle; afterMount: lifecycle; beforeUnmount: lifecycle; afterUnmount: lifecycle; activated: lifecycle; deactivated: lifecycle; loadError: loadErrorHandler; }; /** * 基于 Proxy和iframe 实现的沙箱 */ export default class Wujie { id: string; /** 激活时路由地址 */ url: string; /** 子应用保活 */ alive: boolean; /** window代理 */ proxy: WindowProxy; /** document代理 */ proxyDocument: Object; /** location代理 */ proxyLocation: Object; /** * 释放 window / document / location 代理。 * 代理的 handler 闭包捕获了 iframe / urlElement 等 DOM 引用,destroy 时调用此函数 * 解除代理与 handler 的关联,斩断「主应用 → 代理闭包 → iframe」的引用链。 */ proxyRevoke: () => void; /** 事件中心 */ bus: EventBus; /** 容器 */ el: HTMLElement; /** js沙箱 */ iframe: HTMLIFrameElement; /** css沙箱 */ shadowRoot: ShadowRoot; /** 子应用的template */ template: string; /** 子应用代码替换钩子 */ replace: (code: string) => string; /** 子应用自定义fetch */ fetch: (input: RequestInfo, init?: RequestInit) => Promise; /** 子应用的生命周期 */ lifecycles: lifecycles; /** 子应用的插件 */ plugins: Array; /** js沙箱ready态 */ iframeReady: Promise; /** 子应用预加载态 */ preload: Promise; /** 降级时渲染iframe的属性 */ degradeAttrs: { [key: string]: any; }; /** 子应用js执行队列 */ execQueue: Array; /** 子应用执行过标志 */ execFlag: boolean; /** 子应用激活标志 */ activeFlag: boolean; /** 子应用mount标志 */ mountFlag: boolean; /** 路由同步标志 */ sync: boolean; /** 子应用短路径替换,路由同步时生效 */ prefix: { [key: string]: string; }; /** 子应用跳转标志 */ hrefFlag: boolean; /** 子应用采用fiber模式执行 */ fiber: boolean; /** 子应用降级标志 */ degrade: boolean; /** 子应用降级document */ document: Document; /** 子应用styleSheet元素 */ styleSheetElements: Array; /** * 子应用通过 document.head.appendChild(