@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.
package/dist/index.d.mts
CHANGED
|
@@ -178,13 +178,11 @@ declare class EntrySource {
|
|
|
178
178
|
getStyle(urlOrCode: string): Style | undefined;
|
|
179
179
|
importEntery(app: BaseModel): Promise<void>;
|
|
180
180
|
importHtmlEntry(app: MicroAppModel): Promise<void>;
|
|
181
|
-
importInstanceEntry(
|
|
181
|
+
importInstanceEntry(): Promise<void>;
|
|
182
182
|
setScript(url: string, script: IScriptOption | Script): void;
|
|
183
183
|
setStyle(url: string, style: Style): void;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
declare function fetchSource(url: string, options?: {}, app?: BaseModel): Promise<string>;
|
|
187
|
-
|
|
188
186
|
interface IBaseModelProps {
|
|
189
187
|
[WewebCustomAttrs.mode]?: WewebMode;
|
|
190
188
|
[WewebCustomAttrs.url]: string;
|
|
@@ -235,7 +233,6 @@ interface BaseModel {
|
|
|
235
233
|
start(): Promise<void>;
|
|
236
234
|
unmount(needDestroy?: boolean): void;
|
|
237
235
|
url: string;
|
|
238
|
-
fetchSource?: typeof fetchSource;
|
|
239
236
|
}
|
|
240
237
|
declare enum WewebMode {
|
|
241
238
|
APP = "app",
|
|
@@ -314,10 +311,7 @@ declare class MicroInstanceModel implements BaseModel {
|
|
|
314
311
|
showSourceCode: boolean;
|
|
315
312
|
source?: EntrySource;
|
|
316
313
|
url: string;
|
|
317
|
-
|
|
318
|
-
constructor(props: IJsModelProps & {
|
|
319
|
-
fetchSource?: typeof fetchSource;
|
|
320
|
-
});
|
|
314
|
+
constructor(props: IJsModelProps);
|
|
321
315
|
activated<T>(container: HTMLElement | ShadowRoot, callback?: (instance: BaseModel, exportInstance?: T) => void): void;
|
|
322
316
|
deactivated(): void;
|
|
323
317
|
mount<T>(container?: HTMLElement | ShadowRoot, callback?: (instance: MicroInstanceModel, exportInstance: T) => void): void;
|
package/dist/index.esm.js
CHANGED
|
@@ -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)
|
|
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
|
|
|
@@ -415,7 +478,7 @@ var SandBox = class {
|
|
|
415
478
|
return true;
|
|
416
479
|
},
|
|
417
480
|
get: (target, key) => {
|
|
418
|
-
if (
|
|
481
|
+
if (key === Symbol.unscopables || windowNativeFuncMap.has(key)) return rawWindow[key];
|
|
419
482
|
if (DEV_MICRO_APP_WINDOE_KEY_MAP[key]) return this.fakeWindow[key];
|
|
420
483
|
if (WINDOW_ALIAS_LIST.includes(key)) return this.proxyWindow;
|
|
421
484
|
if (key === "document") {
|
|
@@ -497,9 +560,7 @@ var SandBox = class {
|
|
|
497
560
|
return true;
|
|
498
561
|
}
|
|
499
562
|
});
|
|
500
|
-
|
|
501
|
-
rawWindow[this.windowSymbolKey] = this.proxyWindow;
|
|
502
|
-
}
|
|
563
|
+
rawWindow[this.windowSymbolKey] = this.proxyWindow;
|
|
503
564
|
}
|
|
504
565
|
active = false;
|
|
505
566
|
inRawWindowKeySet = /* @__PURE__ */ new Set();
|
|
@@ -705,10 +766,7 @@ function setMarkElement(element, app, keepAlive) {
|
|
|
705
766
|
}
|
|
706
767
|
|
|
707
768
|
// src/utils/fetch.ts
|
|
708
|
-
function fetchSource(url, options = {}
|
|
709
|
-
if (typeof app?.fetchSource === "function") {
|
|
710
|
-
return app.fetchSource(url, options);
|
|
711
|
-
}
|
|
769
|
+
function fetchSource(url, options = {}) {
|
|
712
770
|
if (src_default.fetchSource) {
|
|
713
771
|
return src_default.fetchSource(url, options);
|
|
714
772
|
}
|
|
@@ -805,7 +863,7 @@ var Style = class {
|
|
|
805
863
|
code = style?.code || "";
|
|
806
864
|
}
|
|
807
865
|
if (!code) {
|
|
808
|
-
code = await fetchSource(this.url
|
|
866
|
+
code = await fetchSource(this.url).catch(() => "");
|
|
809
867
|
}
|
|
810
868
|
this.code = code;
|
|
811
869
|
return code;
|
|
@@ -986,7 +1044,6 @@ var MicroInstanceModel = class {
|
|
|
986
1044
|
// 入口资源
|
|
987
1045
|
url;
|
|
988
1046
|
// url
|
|
989
|
-
fetchSource;
|
|
990
1047
|
constructor(props) {
|
|
991
1048
|
this.name = props.id !== props.url ? props.id : random(5);
|
|
992
1049
|
this.appCacheKey = props.id || this.name;
|
|
@@ -1001,7 +1058,6 @@ var MicroInstanceModel = class {
|
|
|
1001
1058
|
if (this.scopeJs) {
|
|
1002
1059
|
this.sandBox = new SandBox(this);
|
|
1003
1060
|
}
|
|
1004
|
-
this.fetchSource = props.fetchSource;
|
|
1005
1061
|
}
|
|
1006
1062
|
activated(container, callback) {
|
|
1007
1063
|
this.isPreLoad = false;
|
|
@@ -1185,11 +1241,12 @@ var Script = class {
|
|
|
1185
1241
|
code = appCache.getCacheScript(this.url)?.code || "";
|
|
1186
1242
|
}
|
|
1187
1243
|
if (!code) {
|
|
1188
|
-
code = await fetchSource(this.url
|
|
1244
|
+
code = await fetchSource(this.url).catch((e) => {
|
|
1189
1245
|
console.error(`fetch script ${this.url} error`, e);
|
|
1190
1246
|
return "";
|
|
1191
1247
|
});
|
|
1192
1248
|
}
|
|
1249
|
+
code = code.replace(/^"use\sstrict";$/gim, "");
|
|
1193
1250
|
this.code = code;
|
|
1194
1251
|
return code;
|
|
1195
1252
|
}
|
|
@@ -1206,17 +1263,21 @@ var Script = class {
|
|
|
1206
1263
|
}`;
|
|
1207
1264
|
}
|
|
1208
1265
|
if (app.showSourceCode) {
|
|
1209
|
-
return `;(function(window, self){
|
|
1266
|
+
return `;(function(window, self, globalThis){
|
|
1210
1267
|
with(window){
|
|
1211
|
-
|
|
1268
|
+
${getGlobalContextCode()}
|
|
1269
|
+
|
|
1270
|
+
${this.code}
|
|
1212
1271
|
|
|
1213
1272
|
}
|
|
1214
1273
|
}).call(window.${app.sandBox.windowSymbolKey},
|
|
1215
|
-
window.${app.sandBox.windowSymbolKey});`;
|
|
1274
|
+
window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey});`;
|
|
1216
1275
|
}
|
|
1217
1276
|
return `
|
|
1218
1277
|
with(window) {
|
|
1219
|
-
|
|
1278
|
+
try {
|
|
1279
|
+
${getGlobalContextCode()}
|
|
1280
|
+
|
|
1220
1281
|
${this.code}
|
|
1221
1282
|
}
|
|
1222
1283
|
catch(e) {
|
|
@@ -1229,7 +1290,7 @@ var Script = class {
|
|
|
1229
1290
|
}
|
|
1230
1291
|
};
|
|
1231
1292
|
function shouldSkipProperty(global, p) {
|
|
1232
|
-
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;
|
|
1293
|
+
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;
|
|
1233
1294
|
}
|
|
1234
1295
|
function getGlobalProp(global, useFirstGlobalProp) {
|
|
1235
1296
|
let cnt = 0;
|
|
@@ -1266,13 +1327,13 @@ async function execAppScripts(app) {
|
|
|
1266
1327
|
await Promise.all(commomList.map((script) => script.excuteCode(app)));
|
|
1267
1328
|
const deferScriptList = [];
|
|
1268
1329
|
const asyncScriptList = [];
|
|
1269
|
-
|
|
1330
|
+
for (const script of appScriptList) {
|
|
1270
1331
|
if (script.defer || script.async) {
|
|
1271
1332
|
if (!script.code && script.defer) {
|
|
1272
1333
|
deferScriptList.push(script.excuteCode(app));
|
|
1273
1334
|
} else asyncScriptList.push(script.excuteCode(app));
|
|
1274
1335
|
}
|
|
1275
|
-
}
|
|
1336
|
+
}
|
|
1276
1337
|
await Promise.all([...asyncScriptList, ...deferScriptList]).catch((e) => {
|
|
1277
1338
|
console.error(e);
|
|
1278
1339
|
});
|
|
@@ -1697,12 +1758,12 @@ var EntrySource = class {
|
|
|
1697
1758
|
}
|
|
1698
1759
|
}
|
|
1699
1760
|
if (app instanceof MicroAppModel) await this.importHtmlEntry(app);
|
|
1700
|
-
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry(
|
|
1761
|
+
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry();
|
|
1701
1762
|
}
|
|
1702
1763
|
async importHtmlEntry(app) {
|
|
1703
1764
|
let htmlStr = appCache.getCacheHtml(this.url);
|
|
1704
1765
|
if (!htmlStr) {
|
|
1705
|
-
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" }
|
|
1766
|
+
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" });
|
|
1706
1767
|
if (!htmlStr) {
|
|
1707
1768
|
console.error("load app entry error, pleace check");
|
|
1708
1769
|
return Promise.reject();
|
|
@@ -1716,10 +1777,10 @@ var EntrySource = class {
|
|
|
1716
1777
|
await excuteAppStyles(app, wrapElement);
|
|
1717
1778
|
this.html = wrapElement;
|
|
1718
1779
|
}
|
|
1719
|
-
async importInstanceEntry(
|
|
1780
|
+
async importInstanceEntry() {
|
|
1720
1781
|
let jsStr = appCache.getCacheScript(this.url)?.code;
|
|
1721
1782
|
if (!jsStr) {
|
|
1722
|
-
jsStr = await fetchSource(this.url, { cache: "no-cache" }
|
|
1783
|
+
jsStr = await fetchSource(this.url, { cache: "no-cache" });
|
|
1723
1784
|
}
|
|
1724
1785
|
if (!jsStr) {
|
|
1725
1786
|
console.error("load app entry error, pleace check");
|