@micro-zoe/micro-app 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '0.6.2';
1
+ const version = '0.7.0';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -41,6 +41,9 @@ function isBoundFunction(target) {
41
41
  function isShadowRoot(target) {
42
42
  return typeof ShadowRoot !== 'undefined' && target instanceof ShadowRoot;
43
43
  }
44
+ const rawDefineProperty = Object.defineProperty;
45
+ const rawDefineProperties = Object.defineProperties;
46
+ const rawHasOwnProperty = Object.prototype.hasOwnProperty;
44
47
  /**
45
48
  * format error log
46
49
  * @param msg message
@@ -230,6 +233,17 @@ let currentMicroAppName = null;
230
233
  function setCurrentAppName(appName) {
231
234
  currentMicroAppName = appName;
232
235
  }
236
+ let isWaitingForReset = false;
237
+ function throttleDeferForSetAppName(appName) {
238
+ if (!isWaitingForReset || currentMicroAppName !== appName) {
239
+ isWaitingForReset = true;
240
+ setCurrentAppName(appName);
241
+ defer(() => {
242
+ isWaitingForReset = false;
243
+ setCurrentAppName(null);
244
+ });
245
+ }
246
+ }
233
247
  // get the currently running app.name
234
248
  function getCurrentAppName() {
235
249
  return currentMicroAppName;
@@ -326,6 +340,7 @@ var keepAliveStates;
326
340
  keepAliveStates["KEEP_ALIVE_SHOW"] = "KEEP_ALIVE_SHOW";
327
341
  keepAliveStates["KEEP_ALIVE_HIDDEN"] = "KEEP_ALIVE_HIDDEN";
328
342
  })(keepAliveStates || (keepAliveStates = {}));
343
+ const globalKeyToBeCached = 'window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakRef,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined';
329
344
 
330
345
  /**
331
346
  * fetch source of html, js, css
@@ -343,6 +358,10 @@ function fetchSource(url, appName = null, options = {}) {
343
358
  }
344
359
 
345
360
  const globalEnv = {};
361
+ /**
362
+ * Note loop nesting
363
+ * Only prototype or unique values can be put here
364
+ */
346
365
  function initGlobalEnv() {
347
366
  if (isBrowser) {
348
367
  /**
@@ -429,13 +448,6 @@ function initGlobalEnv() {
429
448
  }
430
449
  }
431
450
 
432
- // https://developer.mozilla.org/zh-CN/docs/Web/API/CSSRule
433
- var CSSRuleType;
434
- (function (CSSRuleType) {
435
- CSSRuleType[CSSRuleType["STYLE_RULE"] = 1] = "STYLE_RULE";
436
- CSSRuleType[CSSRuleType["MEDIA_RULE"] = 4] = "MEDIA_RULE";
437
- CSSRuleType[CSSRuleType["SUPPORTS_RULE"] = 12] = "SUPPORTS_RULE";
438
- })(CSSRuleType || (CSSRuleType = {}));
439
451
  /**
440
452
  * Bind css scope
441
453
  * Special case:
@@ -516,14 +528,15 @@ function scopedPackRule(rule, prefix, packName) {
516
528
  function scopedRule(rules, prefix) {
517
529
  let result = '';
518
530
  for (const rule of rules) {
519
- switch (rule.type) {
520
- case CSSRuleType.STYLE_RULE:
531
+ // https://developer.mozilla.org/zh-CN/docs/Web/API/CSSRule
532
+ switch (rule.constructor.name) {
533
+ case 'CSSStyleRule':
521
534
  result += scopedStyleRule(rule, prefix);
522
535
  break;
523
- case CSSRuleType.MEDIA_RULE:
536
+ case 'CSSMediaRule':
524
537
  result += scopedPackRule(rule, prefix, 'media');
525
538
  break;
526
- case CSSRuleType.SUPPORTS_RULE:
539
+ case 'CSSSupportsRule':
527
540
  result += scopedPackRule(rule, prefix, 'supports');
528
541
  break;
529
542
  default:
@@ -917,17 +930,21 @@ function execScripts(scriptList, app, initedHook) {
917
930
  }
918
931
  }
919
932
  if (deferScriptPromise.length) {
920
- Promise.all(deferScriptPromise).then((res) => {
921
- res.forEach((code, index) => {
922
- const [url, info] = deferScriptInfo[index];
923
- info.code = info.code || code;
924
- runScript(url, app, info, false, initedHook);
925
- !info.module && initedHook(false);
926
- });
927
- initedHook(isUndefined(initedHook.moduleCount));
928
- }).catch((err) => {
933
+ promiseStream(deferScriptPromise, (res) => {
934
+ const info = deferScriptInfo[res.index][1];
935
+ info.code = info.code || res.data;
936
+ }, (err) => {
937
+ initedHook.errorCount = initedHook.errorCount ? ++initedHook.errorCount : 1;
929
938
  logError(err, app.name);
930
- initedHook(true);
939
+ }, () => {
940
+ deferScriptInfo.forEach(([url, info]) => {
941
+ if (info.code) {
942
+ runScript(url, app, info, false, initedHook);
943
+ !info.module && initedHook(false);
944
+ }
945
+ });
946
+ initedHook(isUndefined(initedHook.moduleCount) ||
947
+ initedHook.errorCount === deferScriptPromise.length);
931
948
  });
932
949
  }
933
950
  else {
@@ -1062,7 +1079,7 @@ function bindScope(url, app, code, module) {
1062
1079
  }
1063
1080
  if (app.sandBox && !module) {
1064
1081
  globalEnv.rawWindow.__MICRO_APP_PROXY_WINDOW__ = app.sandBox.proxyWindow;
1065
- return `;(function(window, self){with(window){;${code}\n}}).call(window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__, window.__MICRO_APP_PROXY_WINDOW__);`;
1082
+ return `;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${globalKeyToBeCached}){;${code}\n}).call(proxyWindow,${globalKeyToBeCached})}})(window.__MICRO_APP_PROXY_WINDOW__);`;
1066
1083
  }
1067
1084
  return code;
1068
1085
  }
@@ -1481,46 +1498,41 @@ function rebuildDataCenterSnapshot(microAppEventCneter) {
1481
1498
  }
1482
1499
  }
1483
1500
 
1484
- const boundedMap = new WeakMap();
1501
+ /* eslint-disable no-return-assign */
1485
1502
  function isBoundedFunction(value) {
1486
- if (boundedMap.has(value)) {
1487
- return boundedMap.get(value);
1488
- }
1489
- // bind function
1490
- const boundFunction = isBoundFunction(value);
1491
- boundedMap.set(value, boundFunction);
1492
- return boundFunction;
1503
+ if (isBoolean(value.__MICRO_APP_ISBOUND_FUNCTION))
1504
+ return value.__MICRO_APP_ISBOUND_FUNCTION;
1505
+ return value.__MICRO_APP_ISBOUND_FUNCTION = isBoundFunction(value);
1493
1506
  }
1494
- const constructorMap = new WeakMap();
1495
1507
  function isConstructor(value) {
1496
- if (constructorMap.has(value)) {
1497
- return constructorMap.get(value);
1498
- }
1508
+ var _a;
1509
+ if (isBoolean(value.__MICRO_APP_ISCONSTRUCTOR))
1510
+ return value.__MICRO_APP_ISCONSTRUCTOR;
1499
1511
  const valueStr = value.toString();
1500
- const result = (value.prototype &&
1501
- value.prototype.constructor === value &&
1512
+ const result = (((_a = value.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === value &&
1502
1513
  Object.getOwnPropertyNames(value.prototype).length > 1) ||
1503
1514
  /^function\s+[A-Z]/.test(valueStr) ||
1504
1515
  /^class\s+/.test(valueStr);
1505
- constructorMap.set(value, result);
1506
- return result;
1516
+ return value.__MICRO_APP_ISCONSTRUCTOR = result;
1507
1517
  }
1508
- const rawWindowMethodMap = new WeakMap();
1509
1518
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1510
- function bindFunctionToRawWidow(rawWindow, value) {
1511
- if (rawWindowMethodMap.has(value)) {
1512
- return rawWindowMethodMap.get(value);
1513
- }
1514
- if (isFunction(value) && !isConstructor(value) && !isBoundedFunction(value)) {
1519
+ function bindFunctionToRawWindow(rawWindow, value) {
1520
+ if (value.__MICRO_APP_BOUND_WINDOW_FUNCTION)
1521
+ return value.__MICRO_APP_BOUND_WINDOW_FUNCTION;
1522
+ if (!isConstructor(value) && !isBoundedFunction(value)) {
1515
1523
  const bindRawWindowValue = value.bind(rawWindow);
1516
1524
  for (const key in value) {
1517
1525
  bindRawWindowValue[key] = value[key];
1518
1526
  }
1519
- if (value.hasOwnProperty('prototype') && !bindRawWindowValue.hasOwnProperty('prototype')) {
1520
- bindRawWindowValue.prototype = value.prototype;
1527
+ if (value.hasOwnProperty('prototype')) {
1528
+ rawDefineProperty(bindRawWindowValue, 'prototype', {
1529
+ value: value.prototype,
1530
+ configurable: true,
1531
+ enumerable: false,
1532
+ writable: true,
1533
+ });
1521
1534
  }
1522
- rawWindowMethodMap.set(value, bindRawWindowValue);
1523
- return bindRawWindowValue;
1535
+ return value.__MICRO_APP_BOUND_WINDOW_FUNCTION = bindRawWindowValue;
1524
1536
  }
1525
1537
  return value;
1526
1538
  }
@@ -1544,7 +1556,7 @@ function overwriteDocumentOnClick() {
1544
1556
  isFunction(f) && f.call(document, e);
1545
1557
  });
1546
1558
  }
1547
- Object.defineProperty(document, 'onclick', {
1559
+ rawDefineProperty(document, 'onclick', {
1548
1560
  configurable: true,
1549
1561
  enumerable: true,
1550
1562
  get() {
@@ -1594,7 +1606,7 @@ function effectDocumentEvent() {
1594
1606
  else {
1595
1607
  documentEventListenerMap.set(appName, new Map([[type, new Set([listener])]]));
1596
1608
  }
1597
- listener && (listener.__MICRO_MARK_OPTIONS__ = options);
1609
+ listener && (listener.__MICRO_APP_MARK_OPTIONS__ = options);
1598
1610
  }
1599
1611
  rawDocumentAddEventListener.call(rawDocument, type, listener, options);
1600
1612
  };
@@ -1623,27 +1635,27 @@ const formatEventList = ['unmount', 'appstate-change'];
1623
1635
  /**
1624
1636
  * Format event name
1625
1637
  * @param type event name
1626
- * @param microWindow micro window
1638
+ * @param microAppWindow micro window
1627
1639
  */
1628
- function formatEventType(type, microWindow) {
1640
+ function formatEventType(type, microAppWindow) {
1629
1641
  if (formatEventList.includes(type)) {
1630
- return `${type}-${microWindow.__MICRO_APP_NAME__}`;
1642
+ return `${type}-${microAppWindow.__MICRO_APP_NAME__}`;
1631
1643
  }
1632
1644
  return type;
1633
1645
  }
1634
1646
  /**
1635
1647
  * Rewrite side-effect events
1636
- * @param microWindow micro window
1648
+ * @param microAppWindow micro window
1637
1649
  */
1638
- function effect(microWindow) {
1639
- const appName = microWindow.__MICRO_APP_NAME__;
1650
+ function effect(microAppWindow) {
1651
+ const appName = microAppWindow.__MICRO_APP_NAME__;
1640
1652
  const eventListenerMap = new Map();
1641
1653
  const intervalIdMap = new Map();
1642
1654
  const timeoutIdMap = new Map();
1643
1655
  const { rawWindow, rawDocument, rawWindowAddEventListener, rawWindowRemoveEventListener, rawSetInterval, rawSetTimeout, rawClearInterval, rawClearTimeout, rawDocumentRemoveEventListener, } = globalEnv;
1644
1656
  // listener may be null, e.g test-passive
1645
- microWindow.addEventListener = function (type, listener, options) {
1646
- type = formatEventType(type, microWindow);
1657
+ microAppWindow.addEventListener = function (type, listener, options) {
1658
+ type = formatEventType(type, microAppWindow);
1647
1659
  const listenerList = eventListenerMap.get(type);
1648
1660
  if (listenerList) {
1649
1661
  listenerList.add(listener);
@@ -1651,32 +1663,32 @@ function effect(microWindow) {
1651
1663
  else {
1652
1664
  eventListenerMap.set(type, new Set([listener]));
1653
1665
  }
1654
- listener && (listener.__MICRO_MARK_OPTIONS__ = options);
1666
+ listener && (listener.__MICRO_APP_MARK_OPTIONS__ = options);
1655
1667
  rawWindowAddEventListener.call(rawWindow, type, listener, options);
1656
1668
  };
1657
- microWindow.removeEventListener = function (type, listener, options) {
1658
- type = formatEventType(type, microWindow);
1669
+ microAppWindow.removeEventListener = function (type, listener, options) {
1670
+ type = formatEventType(type, microAppWindow);
1659
1671
  const listenerList = eventListenerMap.get(type);
1660
1672
  if ((listenerList === null || listenerList === void 0 ? void 0 : listenerList.size) && listenerList.has(listener)) {
1661
1673
  listenerList.delete(listener);
1662
1674
  }
1663
1675
  rawWindowRemoveEventListener.call(rawWindow, type, listener, options);
1664
1676
  };
1665
- microWindow.setInterval = function (handler, timeout, ...args) {
1677
+ microAppWindow.setInterval = function (handler, timeout, ...args) {
1666
1678
  const intervalId = rawSetInterval.call(rawWindow, handler, timeout, ...args);
1667
1679
  intervalIdMap.set(intervalId, { handler, timeout, args });
1668
1680
  return intervalId;
1669
1681
  };
1670
- microWindow.setTimeout = function (handler, timeout, ...args) {
1682
+ microAppWindow.setTimeout = function (handler, timeout, ...args) {
1671
1683
  const timeoutId = rawSetTimeout.call(rawWindow, handler, timeout, ...args);
1672
1684
  timeoutIdMap.set(timeoutId, { handler, timeout, args });
1673
1685
  return timeoutId;
1674
1686
  };
1675
- microWindow.clearInterval = function (intervalId) {
1687
+ microAppWindow.clearInterval = function (intervalId) {
1676
1688
  intervalIdMap.delete(intervalId);
1677
1689
  rawClearInterval.call(rawWindow, intervalId);
1678
1690
  };
1679
- microWindow.clearTimeout = function (timeoutId) {
1691
+ microAppWindow.clearTimeout = function (timeoutId) {
1680
1692
  timeoutIdMap.delete(timeoutId);
1681
1693
  rawClearTimeout.call(rawWindow, timeoutId);
1682
1694
  };
@@ -1717,15 +1729,15 @@ function effect(microWindow) {
1717
1729
  // rebuild window event
1718
1730
  umdWindowListenerMap.forEach((listenerList, type) => {
1719
1731
  for (const listener of listenerList) {
1720
- microWindow.addEventListener(type, listener, listener === null || listener === void 0 ? void 0 : listener.__MICRO_MARK_OPTIONS__);
1732
+ microAppWindow.addEventListener(type, listener, listener === null || listener === void 0 ? void 0 : listener.__MICRO_APP_MARK_OPTIONS__);
1721
1733
  }
1722
1734
  });
1723
1735
  // rebuild timer
1724
1736
  umdIntervalIdMap.forEach((info) => {
1725
- microWindow.setInterval(info.handler, info.timeout, ...info.args);
1737
+ microAppWindow.setInterval(info.handler, info.timeout, ...info.args);
1726
1738
  });
1727
1739
  umdTimeoutIdMap.forEach((info) => {
1728
- microWindow.setTimeout(info.handler, info.timeout, ...info.args);
1740
+ microAppWindow.setTimeout(info.handler, info.timeout, ...info.args);
1729
1741
  });
1730
1742
  // rebuild onclick event
1731
1743
  umdOnClickHandler && documentClickListMap.set(appName, umdOnClickHandler);
@@ -1733,7 +1745,7 @@ function effect(microWindow) {
1733
1745
  setCurrentAppName(appName);
1734
1746
  umdDocumentListenerMap.forEach((listenerList, type) => {
1735
1747
  for (const listener of listenerList) {
1736
- document.addEventListener(type, listener, listener === null || listener === void 0 ? void 0 : listener.__MICRO_MARK_OPTIONS__);
1748
+ document.addEventListener(type, listener, listener === null || listener === void 0 ? void 0 : listener.__MICRO_APP_MARK_OPTIONS__);
1737
1749
  }
1738
1750
  });
1739
1751
  setCurrentAppName(null);
@@ -1781,181 +1793,70 @@ function effect(microWindow) {
1781
1793
  releaseEffect,
1782
1794
  };
1783
1795
  }
1796
+ // window.addEventListener('mousedown', (e: Event) => {
1797
+ // const targetNode = e.target
1798
+ // const activeApps = getActiveApps(true)
1799
+ // let isScopeOfMicroApp = false
1800
+ // for (const appName of activeApps) {
1801
+ // const app = appInstanceMap.get(appName)!
1802
+ // if (targetNode instanceof Node && app.container!.contains(targetNode)) {
1803
+ // isScopeOfMicroApp = true
1804
+ // // console.log(111111, appName)
1805
+ // setCurrentAppName(appName)
1806
+ // break
1807
+ // }
1808
+ // }
1809
+ // if (!isScopeOfMicroApp) {
1810
+ // setCurrentAppName(null)
1811
+ // }
1812
+ // }, false)
1813
+ // let isWaitingForMacroReset = false
1814
+ // window.addEventListener('mouseup', () => {
1815
+ // if (!isWaitingForMacroReset && getCurrentAppName()) {
1816
+ // isWaitingForMacroReset = true
1817
+ // setTimeout(() => {
1818
+ // setCurrentAppName(null)
1819
+ // isWaitingForMacroReset = false
1820
+ // })
1821
+ // }
1822
+ // }, false)
1784
1823
 
1785
1824
  // Variables that can escape to rawWindow
1786
1825
  const staticEscapeProperties = [
1787
1826
  'System',
1788
1827
  '__cjsWrapper',
1789
- '__REACT_ERROR_OVERLAY_GLOBAL_HOOK__',
1790
1828
  ];
1791
1829
  // Variables that can only assigned to rawWindow
1792
1830
  const escapeSetterKeyList = [
1793
1831
  'location',
1794
1832
  ];
1795
- const unscopables = {
1796
- undefined: true,
1797
- Array: true,
1798
- Object: true,
1799
- String: true,
1800
- Boolean: true,
1801
- Math: true,
1802
- Number: true,
1803
- Symbol: true,
1804
- parseFloat: true,
1805
- Float32Array: true,
1806
- };
1807
- /**
1808
- * macro task to solve the rendering problem of vue3
1809
- */
1810
- let macroTimer;
1811
- function macroTask(fn) {
1812
- macroTimer && clearTimeout(macroTimer);
1813
- macroTimer = setTimeout(fn, 0);
1814
- }
1833
+ const globalPropertyList = ['window', 'self', 'globalThis'];
1815
1834
  class SandBox {
1816
- constructor(appName, url, macro) {
1817
- // Scoped global Properties(Properties that can only get and set in microWindow, will not escape to rawWindow)
1835
+ constructor(appName, url) {
1836
+ // Scoped global Properties(Properties that can only get and set in microAppWindow, will not escape to rawWindow)
1818
1837
  this.scopeProperties = ['webpackJsonp'];
1819
1838
  // Properties that can be escape to rawWindow
1820
1839
  this.escapeProperties = [];
1821
- // Properties newly added to microWindow
1840
+ // Properties newly added to microAppWindow
1822
1841
  this.injectedKeys = new Set();
1823
1842
  // Properties escape to rawWindow, cleared when unmount
1824
1843
  this.escapeKeys = new Set();
1825
1844
  // sandbox state
1826
1845
  this.active = false;
1827
- this.microWindow = {}; // Proxy target
1828
- const rawWindow = globalEnv.rawWindow;
1829
- const rawDocument = globalEnv.rawDocument;
1830
- const descriptorTargetMap = new Map();
1831
- const hasOwnProperty = (key) => this.microWindow.hasOwnProperty(key) || rawWindow.hasOwnProperty(key);
1846
+ this.microAppWindow = {}; // Proxy target
1832
1847
  // get scopeProperties and escapeProperties from plugins
1833
1848
  this.getScopeProperties(appName);
1849
+ // create proxyWindow with Proxy(microAppWindow)
1850
+ this.proxyWindow = this.createProxyWindow();
1834
1851
  // inject global properties
1835
- this.inject(this.microWindow, appName, url);
1852
+ this.initMicroAppWindow(this.microAppWindow, appName, url);
1836
1853
  // Rewrite global event listener & timeout
1837
- Object.assign(this, effect(this.microWindow));
1838
- this.proxyWindow = new Proxy(this.microWindow, {
1839
- get: (target, key) => {
1840
- if (key === Symbol.unscopables)
1841
- return unscopables;
1842
- if (['window', 'self', 'globalThis'].includes(key)) {
1843
- return this.proxyWindow;
1844
- }
1845
- if (key === 'top' || key === 'parent') {
1846
- if (rawWindow === rawWindow.parent) { // not in iframe
1847
- return this.proxyWindow;
1848
- }
1849
- return Reflect.get(rawWindow, key); // iframe
1850
- }
1851
- if (key === 'hasOwnProperty')
1852
- return hasOwnProperty;
1853
- if (key === 'document' || key === 'eval' || key === 'Image') {
1854
- if (this.active) {
1855
- setCurrentAppName(appName);
1856
- (macro ? macroTask : defer)(() => setCurrentAppName(null));
1857
- }
1858
- switch (key) {
1859
- case 'document':
1860
- return rawDocument;
1861
- case 'eval':
1862
- return eval;
1863
- case 'Image':
1864
- return globalEnv.ImageProxy;
1865
- }
1866
- }
1867
- if (Reflect.has(target, key)) {
1868
- return Reflect.get(target, key);
1869
- }
1870
- if (this.scopeProperties.includes(key) ||
1871
- (isString(key) && /^__MICRO_APP_/.test(key))) {
1872
- return Reflect.get(target, key);
1873
- }
1874
- const rawValue = Reflect.get(rawWindow, key);
1875
- return bindFunctionToRawWidow(rawWindow, rawValue);
1876
- },
1877
- set: (target, key, value) => {
1878
- if (this.active) {
1879
- if (escapeSetterKeyList.includes(key)) {
1880
- Reflect.set(rawWindow, key, value);
1881
- }
1882
- else if (!target.hasOwnProperty(key) &&
1883
- rawWindow.hasOwnProperty(key) &&
1884
- !this.scopeProperties.includes(key)) {
1885
- const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
1886
- const { writable, configurable, enumerable } = descriptor;
1887
- if (writable) {
1888
- Object.defineProperty(target, key, {
1889
- configurable,
1890
- enumerable,
1891
- writable,
1892
- value,
1893
- });
1894
- this.injectedKeys.add(key);
1895
- }
1896
- }
1897
- else {
1898
- Reflect.set(target, key, value);
1899
- this.injectedKeys.add(key);
1900
- }
1901
- if ((this.escapeProperties.includes(key) ||
1902
- (staticEscapeProperties.includes(key) && !Reflect.has(rawWindow, key))) &&
1903
- !this.scopeProperties.includes(key)) {
1904
- Reflect.set(rawWindow, key, value);
1905
- this.escapeKeys.add(key);
1906
- }
1907
- }
1908
- return true;
1909
- },
1910
- has: (target, key) => {
1911
- if (this.scopeProperties.includes(key))
1912
- return key in target;
1913
- return key in unscopables || key in target || key in rawWindow;
1914
- },
1915
- // Object.getOwnPropertyDescriptor(window, key)
1916
- // TODO: use set
1917
- getOwnPropertyDescriptor: (target, key) => {
1918
- if (target.hasOwnProperty(key)) {
1919
- descriptorTargetMap.set(key, 'target');
1920
- return Object.getOwnPropertyDescriptor(target, key);
1921
- }
1922
- if (rawWindow.hasOwnProperty(key)) {
1923
- // like console, alert ...
1924
- descriptorTargetMap.set(key, 'rawWindow');
1925
- const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
1926
- if (descriptor && !descriptor.configurable) {
1927
- descriptor.configurable = true;
1928
- }
1929
- return descriptor;
1930
- }
1931
- return undefined;
1932
- },
1933
- // Object.defineProperty(window, key, Descriptor)
1934
- defineProperty: (target, key, value) => {
1935
- const from = descriptorTargetMap.get(key);
1936
- if (from === 'rawWindow') {
1937
- return Reflect.defineProperty(rawWindow, key, value);
1938
- }
1939
- return Reflect.defineProperty(target, key, value);
1940
- },
1941
- // Object.getOwnPropertyNames(window)
1942
- ownKeys: (target) => {
1943
- return unique(Reflect.ownKeys(rawWindow).concat(Reflect.ownKeys(target)));
1944
- },
1945
- deleteProperty: (target, key) => {
1946
- if (target.hasOwnProperty(key)) {
1947
- this.injectedKeys.has(key) && this.injectedKeys.delete(key);
1948
- this.escapeKeys.has(key) && Reflect.deleteProperty(rawWindow, key);
1949
- return Reflect.deleteProperty(target, key);
1950
- }
1951
- return true;
1952
- },
1953
- });
1854
+ Object.assign(this, effect(this.microAppWindow));
1954
1855
  }
1955
1856
  start(baseroute) {
1956
1857
  if (!this.active) {
1957
1858
  this.active = true;
1958
- this.microWindow.__MICRO_APP_BASE_ROUTE__ = this.microWindow.__MICRO_APP_BASE_URL__ = baseroute;
1859
+ this.microAppWindow.__MICRO_APP_BASE_ROUTE__ = this.microAppWindow.__MICRO_APP_BASE_URL__ = baseroute;
1959
1860
  // BUG FIX: bable-polyfill@6.x
1960
1861
  globalEnv.rawWindow._babelPolyfill && (globalEnv.rawWindow._babelPolyfill = false);
1961
1862
  if (++SandBox.activeCount === 1) {
@@ -1967,10 +1868,10 @@ class SandBox {
1967
1868
  if (this.active) {
1968
1869
  this.active = false;
1969
1870
  this.releaseEffect();
1970
- this.microWindow.microApp.clearDataListener();
1971
- this.microWindow.microApp.clearGlobalDataListener();
1871
+ this.microAppWindow.microApp.clearDataListener();
1872
+ this.microAppWindow.microApp.clearGlobalDataListener();
1972
1873
  this.injectedKeys.forEach((key) => {
1973
- Reflect.deleteProperty(this.microWindow, key);
1874
+ Reflect.deleteProperty(this.microAppWindow, key);
1974
1875
  });
1975
1876
  this.injectedKeys.clear();
1976
1877
  this.escapeKeys.forEach((key) => {
@@ -1984,12 +1885,12 @@ class SandBox {
1984
1885
  }
1985
1886
  // record umd snapshot before the first execution of umdHookMount
1986
1887
  recordUmdSnapshot() {
1987
- this.microWindow.__MICRO_APP_UMD_MODE__ = true;
1888
+ this.microAppWindow.__MICRO_APP_UMD_MODE__ = true;
1988
1889
  this.recordUmdEffect();
1989
- recordDataCenterSnapshot(this.microWindow.microApp);
1890
+ recordDataCenterSnapshot(this.microAppWindow.microApp);
1990
1891
  this.recordUmdinjectedValues = new Map();
1991
1892
  this.injectedKeys.forEach((key) => {
1992
- this.recordUmdinjectedValues.set(key, Reflect.get(this.microWindow, key));
1893
+ this.recordUmdinjectedValues.set(key, Reflect.get(this.microAppWindow, key));
1993
1894
  });
1994
1895
  }
1995
1896
  // rebuild umd snapshot before remount umd app
@@ -1998,7 +1899,7 @@ class SandBox {
1998
1899
  Reflect.set(this.proxyWindow, key, value);
1999
1900
  });
2000
1901
  this.rebuildUmdEffect();
2001
- rebuildDataCenterSnapshot(this.microWindow.microApp);
1902
+ rebuildDataCenterSnapshot(this.microAppWindow.microApp);
2002
1903
  }
2003
1904
  /**
2004
1905
  * get scopeProperties and escapeProperties from plugins
@@ -2033,20 +1934,178 @@ class SandBox {
2033
1934
  }
2034
1935
  }
2035
1936
  }
1937
+ // create proxyWindow with Proxy(microAppWindow)
1938
+ createProxyWindow() {
1939
+ const rawWindow = globalEnv.rawWindow;
1940
+ const descriptorTargetMap = new Map();
1941
+ // window.xxx will trigger proxy
1942
+ return new Proxy(this.microAppWindow, {
1943
+ get: (target, key) => {
1944
+ if (Reflect.has(target, key) ||
1945
+ (isString(key) && /^__MICRO_APP_/.test(key)) ||
1946
+ this.scopeProperties.includes(key))
1947
+ return Reflect.get(target, key);
1948
+ const rawValue = Reflect.get(rawWindow, key);
1949
+ return isFunction(rawValue) ? bindFunctionToRawWindow(rawWindow, rawValue) : rawValue;
1950
+ },
1951
+ set: (target, key, value) => {
1952
+ if (this.active) {
1953
+ if (escapeSetterKeyList.includes(key)) {
1954
+ Reflect.set(rawWindow, key, value);
1955
+ }
1956
+ else if (
1957
+ // target.hasOwnProperty has been rewritten
1958
+ !rawHasOwnProperty.call(target, key) &&
1959
+ rawHasOwnProperty.call(rawWindow, key) &&
1960
+ !this.scopeProperties.includes(key)) {
1961
+ const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
1962
+ const { configurable, enumerable, writable, set } = descriptor;
1963
+ // set value because it can be set
1964
+ rawDefineProperty(target, key, {
1965
+ value,
1966
+ configurable,
1967
+ enumerable,
1968
+ writable: writable !== null && writable !== void 0 ? writable : !!set,
1969
+ });
1970
+ this.injectedKeys.add(key);
1971
+ }
1972
+ else {
1973
+ Reflect.set(target, key, value);
1974
+ this.injectedKeys.add(key);
1975
+ }
1976
+ if ((this.escapeProperties.includes(key) ||
1977
+ (staticEscapeProperties.includes(key) && !Reflect.has(rawWindow, key))) &&
1978
+ !this.scopeProperties.includes(key)) {
1979
+ Reflect.set(rawWindow, key, value);
1980
+ this.escapeKeys.add(key);
1981
+ }
1982
+ }
1983
+ return true;
1984
+ },
1985
+ has: (target, key) => {
1986
+ if (this.scopeProperties.includes(key))
1987
+ return key in target;
1988
+ return key in target || key in rawWindow;
1989
+ },
1990
+ // Object.getOwnPropertyDescriptor(window, key)
1991
+ getOwnPropertyDescriptor: (target, key) => {
1992
+ if (rawHasOwnProperty.call(target, key)) {
1993
+ descriptorTargetMap.set(key, 'target');
1994
+ return Object.getOwnPropertyDescriptor(target, key);
1995
+ }
1996
+ if (rawHasOwnProperty.call(rawWindow, key)) {
1997
+ descriptorTargetMap.set(key, 'rawWindow');
1998
+ const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
1999
+ if (descriptor && !descriptor.configurable) {
2000
+ descriptor.configurable = true;
2001
+ }
2002
+ return descriptor;
2003
+ }
2004
+ return undefined;
2005
+ },
2006
+ // Object.defineProperty(window, key, Descriptor)
2007
+ defineProperty: (target, key, value) => {
2008
+ const from = descriptorTargetMap.get(key);
2009
+ if (from === 'rawWindow') {
2010
+ return Reflect.defineProperty(rawWindow, key, value);
2011
+ }
2012
+ return Reflect.defineProperty(target, key, value);
2013
+ },
2014
+ // Object.getOwnPropertyNames(window)
2015
+ ownKeys: (target) => {
2016
+ return unique(Reflect.ownKeys(rawWindow).concat(Reflect.ownKeys(target)));
2017
+ },
2018
+ deleteProperty: (target, key) => {
2019
+ if (rawHasOwnProperty.call(target, key)) {
2020
+ this.injectedKeys.has(key) && this.injectedKeys.delete(key);
2021
+ this.escapeKeys.has(key) && Reflect.deleteProperty(rawWindow, key);
2022
+ return Reflect.deleteProperty(target, key);
2023
+ }
2024
+ return true;
2025
+ },
2026
+ });
2027
+ }
2036
2028
  /**
2037
- * inject global properties to microWindow
2038
- * @param microWindow micro window
2029
+ * inject global properties to microAppWindow
2030
+ * @param microAppWindow micro window
2039
2031
  * @param appName app name
2040
2032
  * @param url app url
2041
2033
  */
2042
- inject(microWindow, appName, url) {
2043
- microWindow.__MICRO_APP_ENVIRONMENT__ = true;
2044
- microWindow.__MICRO_APP_NAME__ = appName;
2045
- microWindow.__MICRO_APP_PUBLIC_PATH__ = getEffectivePath(url);
2046
- microWindow.microApp = new EventCenterForMicroApp(appName);
2047
- microWindow.rawWindow = globalEnv.rawWindow;
2048
- microWindow.rawDocument = globalEnv.rawDocument;
2049
- microWindow.removeDomScope = removeDomScope;
2034
+ initMicroAppWindow(microAppWindow, appName, url) {
2035
+ microAppWindow.__MICRO_APP_ENVIRONMENT__ = true;
2036
+ microAppWindow.__MICRO_APP_NAME__ = appName;
2037
+ microAppWindow.__MICRO_APP_PUBLIC_PATH__ = getEffectivePath(url);
2038
+ microAppWindow.__MICRO_APP_WINDOW__ = microAppWindow;
2039
+ microAppWindow.microApp = new EventCenterForMicroApp(appName);
2040
+ microAppWindow.rawWindow = globalEnv.rawWindow;
2041
+ microAppWindow.rawDocument = globalEnv.rawDocument;
2042
+ microAppWindow.removeDomScope = removeDomScope;
2043
+ microAppWindow.hasOwnProperty = (key) => rawHasOwnProperty.call(microAppWindow, key) || rawHasOwnProperty.call(globalEnv.rawWindow, key);
2044
+ this.setMappingPropertiesWithRawDescriptor(microAppWindow);
2045
+ this.setHijackProperties(microAppWindow, appName);
2046
+ }
2047
+ // properties associated with the native window
2048
+ setMappingPropertiesWithRawDescriptor(microAppWindow) {
2049
+ let topValue, parentValue;
2050
+ const rawWindow = globalEnv.rawWindow;
2051
+ if (rawWindow === rawWindow.parent) { // not in iframe
2052
+ topValue = parentValue = this.proxyWindow;
2053
+ }
2054
+ else { // in iframe
2055
+ topValue = rawWindow.top;
2056
+ parentValue = rawWindow.parent;
2057
+ }
2058
+ rawDefineProperty(microAppWindow, 'top', this.createDescriptorFormicroAppWindow('top', topValue));
2059
+ rawDefineProperty(microAppWindow, 'parent', this.createDescriptorFormicroAppWindow('parent', parentValue));
2060
+ globalPropertyList.forEach((key) => {
2061
+ rawDefineProperty(microAppWindow, key, this.createDescriptorFormicroAppWindow(key, this.proxyWindow));
2062
+ });
2063
+ }
2064
+ createDescriptorFormicroAppWindow(key, value) {
2065
+ const { configurable = true, enumerable = true, writable, set } = Object.getOwnPropertyDescriptor(globalEnv.rawWindow, key) || {};
2066
+ const descriptor = {
2067
+ value,
2068
+ configurable,
2069
+ enumerable,
2070
+ writable: writable !== null && writable !== void 0 ? writable : !!set
2071
+ };
2072
+ return descriptor;
2073
+ }
2074
+ // set hijack Properties to microAppWindow
2075
+ setHijackProperties(microAppWindow, appName) {
2076
+ let modifiedEval, modifiedImage;
2077
+ rawDefineProperties(microAppWindow, {
2078
+ document: {
2079
+ get() {
2080
+ throttleDeferForSetAppName(appName);
2081
+ return globalEnv.rawDocument;
2082
+ },
2083
+ configurable: false,
2084
+ enumerable: true,
2085
+ },
2086
+ eval: {
2087
+ get() {
2088
+ throttleDeferForSetAppName(appName);
2089
+ return modifiedEval || eval;
2090
+ },
2091
+ set: (value) => {
2092
+ modifiedEval = value;
2093
+ },
2094
+ configurable: true,
2095
+ enumerable: false,
2096
+ },
2097
+ Image: {
2098
+ get() {
2099
+ throttleDeferForSetAppName(appName);
2100
+ return modifiedImage || globalEnv.ImageProxy;
2101
+ },
2102
+ set: (value) => {
2103
+ modifiedImage = value;
2104
+ },
2105
+ configurable: true,
2106
+ enumerable: false,
2107
+ },
2108
+ });
2050
2109
  }
2051
2110
  }
2052
2111
  SandBox.activeCount = 0; // number of active sandbox
@@ -2115,7 +2174,7 @@ function dispatchCustomEventToMicroApp(eventName, appName, detail = {}) {
2115
2174
  // micro app instances
2116
2175
  const appInstanceMap = new Map();
2117
2176
  class CreateApp {
2118
- constructor({ name, url, ssrUrl, container, inline, scopecss, useSandbox, macro, baseroute, }) {
2177
+ constructor({ name, url, ssrUrl, container, inline, scopecss, useSandbox, baseroute, }) {
2119
2178
  this.state = appStates.NOT_LOADED;
2120
2179
  this.keepAliveState = null;
2121
2180
  this.keepAliveContainer = null;
@@ -2126,7 +2185,6 @@ class CreateApp {
2126
2185
  this.umdMode = false;
2127
2186
  this.isPrefetch = false;
2128
2187
  this.container = null;
2129
- this.macro = false;
2130
2188
  this.baseroute = '';
2131
2189
  this.sandBox = null;
2132
2190
  this.container = container !== null && container !== void 0 ? container : null;
@@ -2138,13 +2196,12 @@ class CreateApp {
2138
2196
  this.url = url;
2139
2197
  this.useSandbox = useSandbox;
2140
2198
  this.scopecss = this.useSandbox && scopecss;
2141
- this.macro = macro !== null && macro !== void 0 ? macro : false;
2142
2199
  this.source = {
2143
2200
  links: new Map(),
2144
2201
  scripts: new Map(),
2145
2202
  };
2146
2203
  this.loadSourceCode();
2147
- this.useSandbox && (this.sandBox = new SandBox(name, url, this.macro));
2204
+ this.useSandbox && (this.sandBox = new SandBox(name, url));
2148
2205
  }
2149
2206
  // Load resources
2150
2207
  loadSourceCode() {
@@ -2312,7 +2369,7 @@ class CreateApp {
2312
2369
  var _a;
2313
2370
  (_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.stop();
2314
2371
  if (destroy) {
2315
- this.actionsForCompletelyDestory();
2372
+ this.actionsForCompletelyDestroy();
2316
2373
  }
2317
2374
  else if (this.umdMode && this.container.childElementCount) {
2318
2375
  cloneContainer(this.container, this.source.html, false);
@@ -2324,7 +2381,7 @@ class CreateApp {
2324
2381
  unmountcb && unmountcb();
2325
2382
  }
2326
2383
  // actions for completely destroy
2327
- actionsForCompletelyDestory() {
2384
+ actionsForCompletelyDestroy() {
2328
2385
  if (!this.useSandbox && this.umdMode) {
2329
2386
  delete window[this.libraryName];
2330
2387
  }
@@ -2390,92 +2447,6 @@ class CreateApp {
2390
2447
  return {};
2391
2448
  }
2392
2449
  }
2393
- // if app not prefetch & not unmount, then app is active
2394
- function getActiveApps() {
2395
- const activeApps = [];
2396
- appInstanceMap.forEach((app, appName) => {
2397
- if (appStates.UNMOUNT !== app.getAppState() && !app.isPrefetch) {
2398
- activeApps.push(appName);
2399
- }
2400
- });
2401
- return activeApps;
2402
- }
2403
- // get all registered apps
2404
- function getAllApps() {
2405
- return Array.from(appInstanceMap.keys());
2406
- }
2407
- /**
2408
- * unmount app by appname
2409
- * @param appName
2410
- * @param options unmountAppParams
2411
- * @returns Promise<void>
2412
- */
2413
- function unmountApp(appName, options) {
2414
- const app = appInstanceMap.get(formatAppName(appName));
2415
- return new Promise((reslove) => {
2416
- if (app) {
2417
- if (app.getAppState() === appStates.UNMOUNT || app.isPrefetch) {
2418
- if (options === null || options === void 0 ? void 0 : options.destroy) {
2419
- app.actionsForCompletelyDestory();
2420
- }
2421
- reslove();
2422
- }
2423
- else if (app.getKeepAliveState() === keepAliveStates.KEEP_ALIVE_HIDDEN) {
2424
- if (options === null || options === void 0 ? void 0 : options.destroy) {
2425
- app.unmount(true, reslove);
2426
- }
2427
- else if (options === null || options === void 0 ? void 0 : options.clearAliveState) {
2428
- app.unmount(false, reslove);
2429
- }
2430
- else {
2431
- reslove();
2432
- }
2433
- }
2434
- else {
2435
- const container = getRootContainer(app.container);
2436
- const unmountHandler = () => {
2437
- container.removeEventListener('unmount', unmountHandler);
2438
- container.removeEventListener('afterhidden', afterhiddenHandler);
2439
- reslove();
2440
- };
2441
- const afterhiddenHandler = () => {
2442
- container.removeEventListener('unmount', unmountHandler);
2443
- container.removeEventListener('afterhidden', afterhiddenHandler);
2444
- reslove();
2445
- };
2446
- container.addEventListener('unmount', unmountHandler);
2447
- container.addEventListener('afterhidden', afterhiddenHandler);
2448
- if (options === null || options === void 0 ? void 0 : options.destroy) {
2449
- let destroyAttrValue, destoryAttrValue;
2450
- container.hasAttribute('destroy') && (destroyAttrValue = container.getAttribute('destroy'));
2451
- container.hasAttribute('destory') && (destoryAttrValue = container.getAttribute('destory'));
2452
- container.setAttribute('destroy', 'true');
2453
- container.parentNode.removeChild(container);
2454
- container.removeAttribute('destroy');
2455
- typeof destroyAttrValue === 'string' && container.setAttribute('destroy', destroyAttrValue);
2456
- typeof destoryAttrValue === 'string' && container.setAttribute('destory', destoryAttrValue);
2457
- }
2458
- else if ((options === null || options === void 0 ? void 0 : options.clearAliveState) && container.hasAttribute('keep-alive')) {
2459
- const keepAliveAttrValue = container.getAttribute('keep-alive');
2460
- container.removeAttribute('keep-alive');
2461
- container.parentNode.removeChild(container);
2462
- container.setAttribute('keep-alive', keepAliveAttrValue);
2463
- }
2464
- else {
2465
- container.parentNode.removeChild(container);
2466
- }
2467
- }
2468
- }
2469
- else {
2470
- logWarn(`app ${appName} does not exist`);
2471
- reslove();
2472
- }
2473
- });
2474
- }
2475
- // unmount all apps in turn
2476
- function unmountAllApps(options) {
2477
- return Array.from(appInstanceMap.keys()).reduce((pre, next) => pre.then(() => unmountApp(next, options)), Promise.resolve());
2478
- }
2479
2450
 
2480
2451
  // Record element and map element
2481
2452
  const dynamicElementInMicroAppMap = new WeakMap();
@@ -2946,7 +2917,6 @@ function defineElement(tagName) {
2946
2917
  // inline: whether js runs in inline script mode, default is false
2947
2918
  // disableScopecss: whether disable css scoped, default is false
2948
2919
  // disableSandbox: whether disable sandbox, default is false
2949
- // macro: used to solve the async render problem of vue3, default is false
2950
2920
  // baseRoute: route prefix, default is ''
2951
2921
  // keep-alive: open keep-alive mode
2952
2922
  connectedCallback() {
@@ -3144,7 +3114,7 @@ function defineElement(tagName) {
3144
3114
  * fix of unmounted umd app with disableSandbox
3145
3115
  */
3146
3116
  if (appInstanceMap.has(this.appName)) {
3147
- appInstanceMap.get(this.appName).actionsForCompletelyDestory();
3117
+ appInstanceMap.get(this.appName).actionsForCompletelyDestroy();
3148
3118
  }
3149
3119
  const instance = new CreateApp({
3150
3120
  name: this.appName,
@@ -3154,7 +3124,6 @@ function defineElement(tagName) {
3154
3124
  inline: this.getDisposeResult('inline'),
3155
3125
  scopecss: !(this.getDisposeResult('disableScopecss') || this.getDisposeResult('shadowDOM')),
3156
3126
  useSandbox: !this.getDisposeResult('disableSandbox'),
3157
- macro: this.getDisposeResult('macro'),
3158
3127
  baseroute: this.getBaseRouteCompatible(),
3159
3128
  });
3160
3129
  appInstanceMap.set(this.appName, instance);
@@ -3279,13 +3248,12 @@ function filterPreFetchTarget(apps) {
3279
3248
  * url: string,
3280
3249
  * disableScopecss?: boolean,
3281
3250
  * disableSandbox?: boolean,
3282
- * macro?: boolean,
3283
3251
  * },
3284
3252
  * ...
3285
3253
  * ])
3286
3254
  * Note:
3287
3255
  * 1: preFetch is asynchronous and is performed only when the browser is idle
3288
- * 2: disableScopecss, disableSandbox, macro must be same with micro-app element, if conflict, the one who executes first shall prevail
3256
+ * 2: disableScopecss, disableSandbox must be same with micro-app element, if conflict, the one who executes first shall prevail
3289
3257
  * @param apps micro apps
3290
3258
  */
3291
3259
  function preFetch(apps) {
@@ -3295,13 +3263,12 @@ function preFetch(apps) {
3295
3263
  requestIdleCallback(() => {
3296
3264
  isFunction(apps) && (apps = apps());
3297
3265
  filterPreFetchTarget(apps).forEach((item) => {
3298
- var _a, _b, _c;
3266
+ var _a, _b;
3299
3267
  const app = new CreateApp({
3300
3268
  name: item.name,
3301
3269
  url: item.url,
3302
3270
  scopecss: !((_a = item.disableScopecss) !== null && _a !== void 0 ? _a : microApp.disableScopecss),
3303
3271
  useSandbox: !((_b = item.disableSandbox) !== null && _b !== void 0 ? _b : microApp.disableSandbox),
3304
- macro: (_c = item.macro) !== null && _c !== void 0 ? _c : microApp.macro,
3305
3272
  });
3306
3273
  app.isPrefetch = true;
3307
3274
  appInstanceMap.set(item.name, app);
@@ -3351,6 +3318,99 @@ function getGlobalAssets(assets) {
3351
3318
  }
3352
3319
  }
3353
3320
 
3321
+ /**
3322
+ * if app not prefetch & not unmount, then app is active
3323
+ * @param excludeHiddenApp exclude hidden keep-alive app
3324
+ * @returns active apps
3325
+ */
3326
+ function getActiveApps(excludeHiddenApp) {
3327
+ const activeApps = [];
3328
+ appInstanceMap.forEach((app, appName) => {
3329
+ if (appStates.UNMOUNT !== app.getAppState() &&
3330
+ !app.isPrefetch &&
3331
+ (!excludeHiddenApp ||
3332
+ keepAliveStates.KEEP_ALIVE_HIDDEN !== app.getKeepAliveState())) {
3333
+ activeApps.push(appName);
3334
+ }
3335
+ });
3336
+ return activeApps;
3337
+ }
3338
+ // get all registered apps
3339
+ function getAllApps() {
3340
+ return Array.from(appInstanceMap.keys());
3341
+ }
3342
+ /**
3343
+ * unmount app by appname
3344
+ * @param appName
3345
+ * @param options unmountAppParams
3346
+ * @returns Promise<void>
3347
+ */
3348
+ function unmountApp(appName, options) {
3349
+ const app = appInstanceMap.get(formatAppName(appName));
3350
+ return new Promise((reslove) => {
3351
+ if (app) {
3352
+ if (app.getAppState() === appStates.UNMOUNT || app.isPrefetch) {
3353
+ if (options === null || options === void 0 ? void 0 : options.destroy) {
3354
+ app.actionsForCompletelyDestroy();
3355
+ }
3356
+ reslove();
3357
+ }
3358
+ else if (app.getKeepAliveState() === keepAliveStates.KEEP_ALIVE_HIDDEN) {
3359
+ if (options === null || options === void 0 ? void 0 : options.destroy) {
3360
+ app.unmount(true, reslove);
3361
+ }
3362
+ else if (options === null || options === void 0 ? void 0 : options.clearAliveState) {
3363
+ app.unmount(false, reslove);
3364
+ }
3365
+ else {
3366
+ reslove();
3367
+ }
3368
+ }
3369
+ else {
3370
+ const container = getRootContainer(app.container);
3371
+ const unmountHandler = () => {
3372
+ container.removeEventListener('unmount', unmountHandler);
3373
+ container.removeEventListener('afterhidden', afterhiddenHandler);
3374
+ reslove();
3375
+ };
3376
+ const afterhiddenHandler = () => {
3377
+ container.removeEventListener('unmount', unmountHandler);
3378
+ container.removeEventListener('afterhidden', afterhiddenHandler);
3379
+ reslove();
3380
+ };
3381
+ container.addEventListener('unmount', unmountHandler);
3382
+ container.addEventListener('afterhidden', afterhiddenHandler);
3383
+ if (options === null || options === void 0 ? void 0 : options.destroy) {
3384
+ let destroyAttrValue, destoryAttrValue;
3385
+ container.hasAttribute('destroy') && (destroyAttrValue = container.getAttribute('destroy'));
3386
+ container.hasAttribute('destory') && (destoryAttrValue = container.getAttribute('destory'));
3387
+ container.setAttribute('destroy', 'true');
3388
+ container.parentNode.removeChild(container);
3389
+ container.removeAttribute('destroy');
3390
+ typeof destroyAttrValue === 'string' && container.setAttribute('destroy', destroyAttrValue);
3391
+ typeof destoryAttrValue === 'string' && container.setAttribute('destory', destoryAttrValue);
3392
+ }
3393
+ else if ((options === null || options === void 0 ? void 0 : options.clearAliveState) && container.hasAttribute('keep-alive')) {
3394
+ const keepAliveAttrValue = container.getAttribute('keep-alive');
3395
+ container.removeAttribute('keep-alive');
3396
+ container.parentNode.removeChild(container);
3397
+ container.setAttribute('keep-alive', keepAliveAttrValue);
3398
+ }
3399
+ else {
3400
+ container.parentNode.removeChild(container);
3401
+ }
3402
+ }
3403
+ }
3404
+ else {
3405
+ logWarn(`app ${appName} does not exist`);
3406
+ reslove();
3407
+ }
3408
+ });
3409
+ }
3410
+ // unmount all apps in turn
3411
+ function unmountAllApps(options) {
3412
+ return Array.from(appInstanceMap.keys()).reduce((pre, next) => pre.then(() => unmountApp(next, options)), Promise.resolve());
3413
+ }
3354
3414
  class MicroApp extends EventCenterForBaseApp {
3355
3415
  constructor() {
3356
3416
  super(...arguments);
@@ -3385,7 +3445,6 @@ class MicroApp extends EventCenterForBaseApp {
3385
3445
  this.inline = options.inline;
3386
3446
  this.disableScopecss = options.disableScopecss;
3387
3447
  this.disableSandbox = options.disableSandbox;
3388
- this.macro = options.macro;
3389
3448
  this.ssr = options.ssr;
3390
3449
  isFunction(options.fetch) && (this.fetch = options.fetch);
3391
3450
  isPlainObject(options.lifeCycles) && (this.lifeCycles = options.lifeCycles);
@@ -3414,5 +3473,5 @@ class MicroApp extends EventCenterForBaseApp {
3414
3473
  var microApp = new MicroApp();
3415
3474
 
3416
3475
  export default microApp;
3417
- export { EventCenterForMicroApp, getActiveApps, getAllApps, preFetch, pureCreateElement, removeDomScope, unmountAllApps, unmountApp, version };
3476
+ export { EventCenterForMicroApp, MicroApp, getActiveApps, getAllApps, preFetch, pureCreateElement, removeDomScope, unmountAllApps, unmountApp, version };
3418
3477
  //# sourceMappingURL=index.esm.js.map