@micro-zoe/micro-app 1.0.0-rc.10 → 1.0.0-rc.11

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.d.ts CHANGED
@@ -155,6 +155,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
155
155
  export function isImageElement(target: unknown): target is HTMLImageElement;
156
156
  export function isBaseElement(target: unknown): target is HTMLBaseElement;
157
157
  export function isDocumentFragment(target: unknown): target is DocumentFragment;
158
+ export function isDocumentShadowRoot(target: unknown): target is DocumentFragment;
158
159
  export function isMicroAppBody(target: unknown): target is HTMLElement;
159
160
  export function isMicroAppHead(target: unknown): target is HTMLElement;
160
161
  export function isProxyDocument(target: unknown): target is Document;
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.10';
1
+ const version = '1.0.0-rc.11';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -122,6 +122,9 @@ function isBaseElement(target) {
122
122
  function isDocumentFragment(target) {
123
123
  return toTypeString(target) === '[object DocumentFragment]';
124
124
  }
125
+ function isDocumentShadowRoot(target) {
126
+ return toTypeString(target) === '[object ShadowRoot]';
127
+ }
125
128
  function isMicroAppBody(target) {
126
129
  return isElement(target) && target.tagName.toUpperCase() === 'MICRO-APP-BODY';
127
130
  }
@@ -5480,6 +5483,7 @@ function patchRouter(appName, url, microAppWindow, browserHost) {
5480
5483
  }
5481
5484
 
5482
5485
  const escape2RawWindowKeys = [
5486
+ 'Array',
5483
5487
  'getComputedStyle',
5484
5488
  // FIX ISSUE: https://github.com/micro-zoe/micro-app/issues/1292
5485
5489
  'DOMParser',
@@ -5605,8 +5609,15 @@ function urlFromScript(script) {
5605
5609
  // @ts-ignore
5606
5610
  const WorkerProxy = new Proxy(originalWorker, {
5607
5611
  construct(Target, args) {
5608
- const [scriptURL, options] = args;
5609
- if (!isSameOrigin(scriptURL)) {
5612
+ let [scriptURL, options] = args;
5613
+ options = options || {};
5614
+ const appName = getCurrentAppName();
5615
+ let url = scriptURL;
5616
+ if (appName) {
5617
+ const app = appInstanceMap.get(appName);
5618
+ url = CompletionPath(scriptURL, app.url);
5619
+ }
5620
+ if (url && !isSameOrigin(url)) {
5610
5621
  // 如果 scriptURL 是跨域的,使用 Blob URL 加载并执行 worker
5611
5622
  const script = `import "${scriptURL}";`;
5612
5623
  const workerPath = urlFromScript(script);
@@ -5619,8 +5630,6 @@ const WorkerProxy = new Proxy(originalWorker, {
5619
5630
  }
5620
5631
  },
5621
5632
  });
5622
- // @ts-ignore
5623
- window.Worker = WorkerProxy;
5624
5633
 
5625
5634
  /**
5626
5635
  * patch window of child app
@@ -7766,10 +7775,14 @@ function patchElementAndDocument() {
7766
7775
  };
7767
7776
  rawDocumentFragment.prototype.prepend = rawRootElement.prototype.prepend = function prepend(...nodes) {
7768
7777
  let i = nodes.length;
7778
+ let target = globalEnv.rawPrepend;
7779
+ if (isDocumentFragment(this) || isDocumentShadowRoot(this)) {
7780
+ target = globalEnv.rawFragmentPrepend;
7781
+ }
7769
7782
  while (i > 0) {
7770
7783
  let node = nodes[i - 1];
7771
7784
  node = isNode(node) ? node : globalEnv.rawCreateTextNode.call(globalEnv.rawDocument, node);
7772
- commonElementHandler(this, markElement(node), null, isDocumentFragment(this) ? globalEnv.rawFragmentPrepend : globalEnv.rawPrepend);
7785
+ commonElementHandler(this, markElement(node), null, target);
7773
7786
  i--;
7774
7787
  }
7775
7788
  };
@@ -7851,6 +7864,7 @@ function patchElementAndDocument() {
7851
7864
  };
7852
7865
  // rewrite setAttribute, complete resource address
7853
7866
  rawRootElement.prototype.setAttribute = function setAttribute(key, value) {
7867
+ var _a;
7854
7868
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
7855
7869
  key === 'data' &&
7856
7870
  this.setAttribute !== rawRootElement.prototype.setAttribute) {
@@ -7866,6 +7880,14 @@ function patchElementAndDocument() {
7866
7880
  value = CompletionPath(value, app.url);
7867
7881
  }
7868
7882
  globalEnv.rawSetAttribute.call(this, key, value);
7883
+ if (isImageElement(this) || isVideoElement(this) || isAudioElement(this)) {
7884
+ let includeCrossOrigin = false;
7885
+ if (((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.includeCrossOrigin) && isFunction(microApp.options.includeCrossOrigin)) {
7886
+ includeCrossOrigin = microApp.options.includeCrossOrigin(value);
7887
+ }
7888
+ // @ts-ignore
7889
+ includeCrossOrigin && (node.crossOrigin = 'anonymous');
7890
+ }
7869
7891
  }
7870
7892
  };
7871
7893
  /**