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

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,8 +155,10 @@ 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;
161
+ export function isWebComponentElement(target: unknown): boolean;
160
162
  export function isProxyDocument(target: unknown): target is Document;
161
163
  export function isTargetExtension(path: string, suffix: string): boolean;
162
164
  export function includes(target: unknown[], searchElement: unknown, fromIndex?: number): boolean;
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.12';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -122,12 +122,23 @@ 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
  }
128
131
  function isMicroAppHead(target) {
129
132
  return isElement(target) && target.tagName.toUpperCase() === 'MICRO-APP-HEAD';
130
133
  }
134
+ function isWebComponentElement(target) {
135
+ let result = toTypeString(target) === '[object HTMLElement]';
136
+ if (result) {
137
+ const tagName = target.tagName.toUpperCase();
138
+ result = result && !tagName.startsWith('MICRO-APP');
139
+ }
140
+ return result;
141
+ }
131
142
  // is ProxyDocument
132
143
  function isProxyDocument(target) {
133
144
  return toTypeString(target) === '[object ProxyDocument]';
@@ -3004,10 +3015,6 @@ function updateElementInfo(node, appName) {
3004
3015
  };
3005
3016
  }
3006
3017
  }
3007
- if (isImageElement(node) || isVideoElement(node) || isAudioElement(node)) {
3008
- // @ts-ignore
3009
- node.crossOrigin = 'anonymous';
3010
- }
3011
3018
  rawDefineProperties(node, props);
3012
3019
  /**
3013
3020
  * In FireFox, iframe Node.prototype will point to native Node.prototype after insert to document
@@ -5480,6 +5487,7 @@ function patchRouter(appName, url, microAppWindow, browserHost) {
5480
5487
  }
5481
5488
 
5482
5489
  const escape2RawWindowKeys = [
5490
+ 'Array',
5483
5491
  'getComputedStyle',
5484
5492
  // FIX ISSUE: https://github.com/micro-zoe/micro-app/issues/1292
5485
5493
  'DOMParser',
@@ -5605,8 +5613,15 @@ function urlFromScript(script) {
5605
5613
  // @ts-ignore
5606
5614
  const WorkerProxy = new Proxy(originalWorker, {
5607
5615
  construct(Target, args) {
5608
- const [scriptURL, options] = args;
5609
- if (!isSameOrigin(scriptURL)) {
5616
+ let [scriptURL, options] = args;
5617
+ options = options || {};
5618
+ const appName = getCurrentAppName();
5619
+ let url = scriptURL;
5620
+ if (appName) {
5621
+ const app = appInstanceMap.get(appName);
5622
+ url = CompletionPath(scriptURL, app.url);
5623
+ }
5624
+ if (url && !isSameOrigin(url)) {
5610
5625
  // 如果 scriptURL 是跨域的,使用 Blob URL 加载并执行 worker
5611
5626
  const script = `import "${scriptURL}";`;
5612
5627
  const workerPath = urlFromScript(script);
@@ -5619,8 +5634,6 @@ const WorkerProxy = new Proxy(originalWorker, {
5619
5634
  }
5620
5635
  },
5621
5636
  });
5622
- // @ts-ignore
5623
- window.Worker = WorkerProxy;
5624
5637
 
5625
5638
  /**
5626
5639
  * patch window of child app
@@ -5918,7 +5931,10 @@ function patchDocumentPrototype(appName, microAppWindow) {
5918
5931
  return range;
5919
5932
  };
5920
5933
  microRootDocument.prototype.createElement = function createElement(tagName, options) {
5921
- const element = rawMicroCreateElement.call(this, tagName, options);
5934
+ let element = rawMicroCreateElement.call(this, tagName, options);
5935
+ if (isWebComponentElement(element)) {
5936
+ element = rawMicroCreateElement.call(rawDocument, tagName, options);
5937
+ }
5922
5938
  return updateElementInfo(element, appName);
5923
5939
  };
5924
5940
  microRootDocument.prototype.createElementNS = function createElementNS(namespaceURI, name, options) {
@@ -7766,10 +7782,14 @@ function patchElementAndDocument() {
7766
7782
  };
7767
7783
  rawDocumentFragment.prototype.prepend = rawRootElement.prototype.prepend = function prepend(...nodes) {
7768
7784
  let i = nodes.length;
7785
+ let target = globalEnv.rawPrepend;
7786
+ if (isDocumentFragment(this) || isDocumentShadowRoot(this)) {
7787
+ target = globalEnv.rawFragmentPrepend;
7788
+ }
7769
7789
  while (i > 0) {
7770
7790
  let node = nodes[i - 1];
7771
7791
  node = isNode(node) ? node : globalEnv.rawCreateTextNode.call(globalEnv.rawDocument, node);
7772
- commonElementHandler(this, markElement(node), null, isDocumentFragment(this) ? globalEnv.rawFragmentPrepend : globalEnv.rawPrepend);
7792
+ commonElementHandler(this, markElement(node), null, target);
7773
7793
  i--;
7774
7794
  }
7775
7795
  };
@@ -7851,6 +7871,7 @@ function patchElementAndDocument() {
7851
7871
  };
7852
7872
  // rewrite setAttribute, complete resource address
7853
7873
  rawRootElement.prototype.setAttribute = function setAttribute(key, value) {
7874
+ var _a;
7854
7875
  if (/^micro-app(-\S+)?/i.test(this.tagName) &&
7855
7876
  key === 'data' &&
7856
7877
  this.setAttribute !== rawRootElement.prototype.setAttribute) {
@@ -7866,6 +7887,14 @@ function patchElementAndDocument() {
7866
7887
  value = CompletionPath(value, app.url);
7867
7888
  }
7868
7889
  globalEnv.rawSetAttribute.call(this, key, value);
7890
+ if (isImageElement(this) || isVideoElement(this) || isAudioElement(this)) {
7891
+ let includeCrossOrigin = false;
7892
+ if (((_a = microApp === null || microApp === void 0 ? void 0 : microApp.options) === null || _a === void 0 ? void 0 : _a.includeCrossOrigin) && isFunction(microApp.options.includeCrossOrigin)) {
7893
+ includeCrossOrigin = microApp.options.includeCrossOrigin(value);
7894
+ }
7895
+ // @ts-ignore
7896
+ includeCrossOrigin && (node.crossOrigin = 'anonymous');
7897
+ }
7869
7898
  }
7870
7899
  };
7871
7900
  /**