@blueking/bk-weweb 0.0.27-beta.1 → 0.0.28-beta.2

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.
@@ -7,12 +7,75 @@ function setCurrentRunningApp(appInstance) {
7
7
  currentRunningApp = appInstance;
8
8
  }
9
9
  var windowNativeFuncMap = /* @__PURE__ */ new Map();
10
+ var globalContextCode = `const { ${[
11
+ "Array",
12
+ "ArrayBuffer",
13
+ "Boolean",
14
+ "constructor",
15
+ "DataView",
16
+ "Date",
17
+ "decodeURI",
18
+ "decodeURIComponent",
19
+ "encodeURI",
20
+ "encodeURIComponent",
21
+ "Error",
22
+ "escape",
23
+ "eval",
24
+ "EvalError",
25
+ "Float32Array",
26
+ "Float64Array",
27
+ "Function",
28
+ "hasOwnProperty",
29
+ "Infinity",
30
+ "Int16Array",
31
+ "Int32Array",
32
+ "Int8Array",
33
+ "isFinite",
34
+ "isNaN",
35
+ "isPrototypeOf",
36
+ "JSON",
37
+ "Map",
38
+ "Math",
39
+ "NaN",
40
+ "Number",
41
+ "Object",
42
+ "parseFloat",
43
+ "parseInt",
44
+ "Promise",
45
+ "propertyIsEnumerable",
46
+ "Proxy",
47
+ "RangeError",
48
+ "ReferenceError",
49
+ "Reflect",
50
+ "RegExp",
51
+ "Set",
52
+ "String",
53
+ "Symbol",
54
+ "SyntaxError",
55
+ "toLocaleString",
56
+ "toString",
57
+ "TypeError",
58
+ "Uint16Array",
59
+ "Uint32Array",
60
+ "Uint8Array",
61
+ "Uint8ClampedArray",
62
+ "undefined",
63
+ "unescape",
64
+ "URIError",
65
+ "valueOf",
66
+ "WeakMap",
67
+ "WeakSet"
68
+ ].join(",")} }= this;`;
69
+ var getGlobalContextCode = () => {
70
+ return globalContextCode;
71
+ };
10
72
  var collectNativeWindowFunc = () => {
11
- Object.getOwnPropertyNames(window).forEach((key) => {
73
+ const keyList = Object.getOwnPropertyNames(window);
74
+ for (const key of keyList) {
12
75
  if (!windowNativeFuncMap.has(key) && key.match(/^[A-Z]/) && typeof window[key] === "function" && window[key].toString().includes("[native code]")) {
13
76
  windowNativeFuncMap.set(key, true);
14
77
  }
15
- });
78
+ }
16
79
  };
17
80
  collectNativeWindowFunc();
18
81
 
@@ -407,7 +470,7 @@ var SandBox = class {
407
470
  return true;
408
471
  },
409
472
  get: (target, key) => {
410
- if (windowNativeFuncMap.has(key) || key === Symbol.unscopables) return rawWindow[key];
473
+ if (key === Symbol.unscopables || windowNativeFuncMap.has(key)) return rawWindow[key];
411
474
  if (DEV_MICRO_APP_WINDOE_KEY_MAP[key]) return this.fakeWindow[key];
412
475
  if (WINDOW_ALIAS_LIST.includes(key)) return this.proxyWindow;
413
476
  if (key === "document") {
@@ -489,9 +552,7 @@ var SandBox = class {
489
552
  return true;
490
553
  }
491
554
  });
492
- if (app.showSourceCode) {
493
- rawWindow[this.windowSymbolKey] = this.proxyWindow;
494
- }
555
+ rawWindow[this.windowSymbolKey] = this.proxyWindow;
495
556
  }
496
557
  active = false;
497
558
  inRawWindowKeySet = /* @__PURE__ */ new Set();
@@ -1015,10 +1076,7 @@ var weWeb = new WeWeb();
1015
1076
  var src_default = weWeb;
1016
1077
 
1017
1078
  // src/utils/fetch.ts
1018
- function fetchSource(url, options = {}, app) {
1019
- if (typeof app?.fetchSource === "function") {
1020
- return app.fetchSource(url, options);
1021
- }
1079
+ function fetchSource(url, options = {}) {
1022
1080
  if (src_default.fetchSource) {
1023
1081
  return src_default.fetchSource(url, options);
1024
1082
  }
@@ -1115,7 +1173,7 @@ var Style = class {
1115
1173
  code = style?.code || "";
1116
1174
  }
1117
1175
  if (!code) {
1118
- code = await fetchSource(this.url, {}, app).catch(() => "");
1176
+ code = await fetchSource(this.url).catch(() => "");
1119
1177
  }
1120
1178
  this.code = code;
1121
1179
  return code;
@@ -1296,7 +1354,6 @@ var MicroInstanceModel = class {
1296
1354
  // 入口资源
1297
1355
  url;
1298
1356
  // url
1299
- fetchSource;
1300
1357
  constructor(props) {
1301
1358
  this.name = props.id !== props.url ? props.id : random(5);
1302
1359
  this.appCacheKey = props.id || this.name;
@@ -1311,7 +1368,6 @@ var MicroInstanceModel = class {
1311
1368
  if (this.scopeJs) {
1312
1369
  this.sandBox = new SandBox(this);
1313
1370
  }
1314
- this.fetchSource = props.fetchSource;
1315
1371
  }
1316
1372
  activated(container, callback) {
1317
1373
  this.isPreLoad = false;
@@ -1495,11 +1551,12 @@ var Script = class {
1495
1551
  code = appCache.getCacheScript(this.url)?.code || "";
1496
1552
  }
1497
1553
  if (!code) {
1498
- code = await fetchSource(this.url, {}, app).catch((e) => {
1554
+ code = await fetchSource(this.url).catch((e) => {
1499
1555
  console.error(`fetch script ${this.url} error`, e);
1500
1556
  return "";
1501
1557
  });
1502
1558
  }
1559
+ code = code.replace(/^"use\sstrict";$/gim, "");
1503
1560
  this.code = code;
1504
1561
  return code;
1505
1562
  }
@@ -1516,17 +1573,21 @@ var Script = class {
1516
1573
  }`;
1517
1574
  }
1518
1575
  if (app.showSourceCode) {
1519
- return `;(function(window, self){
1576
+ return `;(function(window, self, globalThis){
1520
1577
  with(window){
1521
- ;${this.code}
1578
+ ${getGlobalContextCode()}
1579
+
1580
+ ${this.code}
1522
1581
 
1523
1582
  }
1524
1583
  }).call(window.${app.sandBox.windowSymbolKey},
1525
- window.${app.sandBox.windowSymbolKey});`;
1584
+ window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey});`;
1526
1585
  }
1527
1586
  return `
1528
1587
  with(window) {
1529
- try {
1588
+ try {
1589
+ ${getGlobalContextCode()}
1590
+
1530
1591
  ${this.code}
1531
1592
  }
1532
1593
  catch(e) {
@@ -1539,7 +1600,7 @@ var Script = class {
1539
1600
  }
1540
1601
  };
1541
1602
  function shouldSkipProperty(global, p) {
1542
- return !global.hasOwnProperty(p) || !isNaN(p) && p < global.length || typeof navigator !== "undefined" && navigator.userAgent.indexOf("Trident") !== -1 && global[p] && typeof window !== "undefined" && global[p].parent === window;
1603
+ return !global.hasOwnProperty(p) || !Number.isNaN(p) && p < global.length || typeof navigator !== "undefined" && navigator.userAgent.indexOf("Trident") !== -1 && global[p] && typeof window !== "undefined" && global[p].parent === window;
1543
1604
  }
1544
1605
  function getGlobalProp(global, useFirstGlobalProp) {
1545
1606
  let cnt = 0;
@@ -1576,13 +1637,13 @@ async function execAppScripts(app) {
1576
1637
  await Promise.all(commomList.map((script) => script.excuteCode(app)));
1577
1638
  const deferScriptList = [];
1578
1639
  const asyncScriptList = [];
1579
- appScriptList.forEach((script) => {
1640
+ for (const script of appScriptList) {
1580
1641
  if (script.defer || script.async) {
1581
1642
  if (!script.code && script.defer) {
1582
1643
  deferScriptList.push(script.excuteCode(app));
1583
1644
  } else asyncScriptList.push(script.excuteCode(app));
1584
1645
  }
1585
- });
1646
+ }
1586
1647
  await Promise.all([...asyncScriptList, ...deferScriptList]).catch((e) => {
1587
1648
  console.error(e);
1588
1649
  });
@@ -1940,12 +2001,12 @@ var EntrySource = class {
1940
2001
  }
1941
2002
  }
1942
2003
  if (app instanceof MicroAppModel) await this.importHtmlEntry(app);
1943
- else if (app instanceof MicroInstanceModel) await this.importInstanceEntry(app);
2004
+ else if (app instanceof MicroInstanceModel) await this.importInstanceEntry();
1944
2005
  }
1945
2006
  async importHtmlEntry(app) {
1946
2007
  let htmlStr = appCache.getCacheHtml(this.url);
1947
2008
  if (!htmlStr) {
1948
- htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" }, app);
2009
+ htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" });
1949
2010
  if (!htmlStr) {
1950
2011
  console.error("load app entry error, pleace check");
1951
2012
  return Promise.reject();
@@ -1959,10 +2020,10 @@ var EntrySource = class {
1959
2020
  await excuteAppStyles(app, wrapElement);
1960
2021
  this.html = wrapElement;
1961
2022
  }
1962
- async importInstanceEntry(app) {
2023
+ async importInstanceEntry() {
1963
2024
  let jsStr = appCache.getCacheScript(this.url)?.code;
1964
2025
  if (!jsStr) {
1965
- jsStr = await fetchSource(this.url, { cache: "no-cache" }, app);
2026
+ jsStr = await fetchSource(this.url, { cache: "no-cache" });
1966
2027
  }
1967
2028
  if (!jsStr) {
1968
2029
  console.error("load app entry error, pleace check");