@blueking/bk-weweb 0.0.28-beta.2 → 0.0.29-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/base-app/collect-source.esm.js +125 -95
- package/dist/base-app/collect-source.esm.js.map +1 -1
- package/dist/index.d.mts +14 -8
- package/dist/index.esm.js +125 -95
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ function setCurrentRunningApp(appInstance) {
|
|
|
7
7
|
currentRunningApp = appInstance;
|
|
8
8
|
}
|
|
9
9
|
var windowNativeFuncMap = /* @__PURE__ */ new Map();
|
|
10
|
-
var
|
|
10
|
+
var list = [
|
|
11
11
|
"Array",
|
|
12
12
|
"ArrayBuffer",
|
|
13
13
|
"Boolean",
|
|
@@ -65,7 +65,8 @@ var globalContextCode = `const { ${[
|
|
|
65
65
|
"valueOf",
|
|
66
66
|
"WeakMap",
|
|
67
67
|
"WeakSet"
|
|
68
|
-
]
|
|
68
|
+
];
|
|
69
|
+
var globalContextCode = list.join(",");
|
|
69
70
|
var getGlobalContextCode = () => {
|
|
70
71
|
return globalContextCode;
|
|
71
72
|
};
|
|
@@ -74,8 +75,12 @@ var collectNativeWindowFunc = () => {
|
|
|
74
75
|
for (const key of keyList) {
|
|
75
76
|
if (!windowNativeFuncMap.has(key) && key.match(/^[A-Z]/) && typeof window[key] === "function" && window[key].toString().includes("[native code]")) {
|
|
76
77
|
windowNativeFuncMap.set(key, true);
|
|
78
|
+
if (!list.includes(key)) {
|
|
79
|
+
globalContextCode += `,${key}`;
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
globalContextCode = `const { ${globalContextCode} }= window.rawWindow;`;
|
|
79
84
|
};
|
|
80
85
|
collectNativeWindowFunc();
|
|
81
86
|
|
|
@@ -462,7 +467,7 @@ var SandBox = class {
|
|
|
462
467
|
return Reflect.defineProperty(target, key, value);
|
|
463
468
|
},
|
|
464
469
|
deleteProperty: (target, key) => {
|
|
465
|
-
if (
|
|
470
|
+
if (Object.hasOwn(target, key)) {
|
|
466
471
|
this.sameRawWindowKeySet.has(key) && this.sameRawWindowKeySet.delete(key);
|
|
467
472
|
this.inRawWindowKeySet.has(key) && Reflect.deleteProperty(rawWindow, key);
|
|
468
473
|
return Reflect.deleteProperty(target, key);
|
|
@@ -485,7 +490,7 @@ var SandBox = class {
|
|
|
485
490
|
return this.app.iframe.contentWindow?.[key];
|
|
486
491
|
}
|
|
487
492
|
if (key === "hasOwnProperty")
|
|
488
|
-
return (key2) => this.fakeWindow
|
|
493
|
+
return (key2) => Object.hasOwn(this.fakeWindow, key2) || Object.hasOwn(rawWindow, key2);
|
|
489
494
|
if (key === "top" || key === "parent") {
|
|
490
495
|
if (rawWindow === rawWindow.parent) {
|
|
491
496
|
return this.proxyWindow;
|
|
@@ -505,10 +510,10 @@ var SandBox = class {
|
|
|
505
510
|
return bindFunctionToRawWindow(rawWindow, rawValue);
|
|
506
511
|
},
|
|
507
512
|
getOwnPropertyDescriptor: (target, key) => {
|
|
508
|
-
if (
|
|
513
|
+
if (Object.hasOwn(target, key)) {
|
|
509
514
|
return Object.getOwnPropertyDescriptor(target, key);
|
|
510
515
|
}
|
|
511
|
-
if (
|
|
516
|
+
if (Object.hasOwn(rawWindow, key)) {
|
|
512
517
|
windowDescriptorSet.add(key);
|
|
513
518
|
const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
|
|
514
519
|
if (descriptor && !descriptor.configurable) {
|
|
@@ -528,7 +533,7 @@ var SandBox = class {
|
|
|
528
533
|
}
|
|
529
534
|
if (key === "location") {
|
|
530
535
|
Reflect.set(rawWindow, key, value);
|
|
531
|
-
} else if (!
|
|
536
|
+
} else if (!Object.hasOwn(target, key) && Object.hasOwn(rawWindow, key) && !BK_WEWEB_INJECT_KEY_LIST.includes(key)) {
|
|
532
537
|
const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
|
|
533
538
|
const { configurable, enumerable, writable } = descriptor;
|
|
534
539
|
if (writable) {
|
|
@@ -570,7 +575,7 @@ var SandBox = class {
|
|
|
570
575
|
* @param data data for sandbox
|
|
571
576
|
* @description active hook for sandbox
|
|
572
577
|
*/
|
|
573
|
-
|
|
578
|
+
activated(data) {
|
|
574
579
|
if (!this.active) {
|
|
575
580
|
this.active = true;
|
|
576
581
|
this.rawDocument = createProxyDocument(document, this.app);
|
|
@@ -587,7 +592,9 @@ var SandBox = class {
|
|
|
587
592
|
if (!this.active) return;
|
|
588
593
|
this.active = false;
|
|
589
594
|
this.resetWindowFunction();
|
|
590
|
-
|
|
595
|
+
for (const key of this.inRawWindowKeySet) {
|
|
596
|
+
Reflect.deleteProperty(window, key);
|
|
597
|
+
}
|
|
591
598
|
this.inRawWindowKeySet.clear();
|
|
592
599
|
this.resetDocumentAndBodyEvent?.();
|
|
593
600
|
}
|
|
@@ -665,7 +672,7 @@ function resetNewElement(parent, child, app) {
|
|
|
665
672
|
return child;
|
|
666
673
|
}
|
|
667
674
|
if (replaceInfo.script) {
|
|
668
|
-
replaceInfo.script.
|
|
675
|
+
replaceInfo.script.executeCode(app);
|
|
669
676
|
}
|
|
670
677
|
if (replaceInfo.replace !== child) {
|
|
671
678
|
return replaceInfo.replace;
|
|
@@ -683,7 +690,7 @@ function resetNewElement(parent, child, app) {
|
|
|
683
690
|
return;
|
|
684
691
|
}
|
|
685
692
|
if (scriptInfo?.script) {
|
|
686
|
-
scriptInfo.script.
|
|
693
|
+
scriptInfo.script.executeCode(app);
|
|
687
694
|
}
|
|
688
695
|
child.remove();
|
|
689
696
|
} else if (child.textContent) {
|
|
@@ -697,7 +704,7 @@ function resetNewElement(parent, child, app) {
|
|
|
697
704
|
});
|
|
698
705
|
app.source.scripts.set(randomUrl(), scriptInstance);
|
|
699
706
|
try {
|
|
700
|
-
scriptInstance.
|
|
707
|
+
scriptInstance.executeCode(app);
|
|
701
708
|
} catch (e) {
|
|
702
709
|
console.error(e);
|
|
703
710
|
} finally {
|
|
@@ -713,15 +720,15 @@ function resetNewElement(parent, child, app) {
|
|
|
713
720
|
}
|
|
714
721
|
return child;
|
|
715
722
|
}
|
|
716
|
-
function
|
|
723
|
+
function isSpecialElement(node) {
|
|
717
724
|
return node instanceof HTMLScriptElement || node instanceof HTMLStyleElement || node instanceof HTMLLinkElement;
|
|
718
725
|
}
|
|
719
|
-
function
|
|
726
|
+
function elementAppendHandler(parent, newChild, rawMethod) {
|
|
720
727
|
if (newChild.__BK_WEWEB_APP_KEY__) {
|
|
721
728
|
const app = appCache.getApp(newChild.__BK_WEWEB_APP_KEY__);
|
|
722
729
|
if (app?.container) {
|
|
723
730
|
const targetChild = resetNewElement(parent, newChild, app);
|
|
724
|
-
const needKeepAlive =
|
|
731
|
+
const needKeepAlive = isSpecialElement(newChild) && !!app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
725
732
|
const container = needKeepAlive ? document.head : app?.container;
|
|
726
733
|
setMarkElement(targetChild, app, needKeepAlive);
|
|
727
734
|
return rawMethod.call(container, targetChild);
|
|
@@ -733,7 +740,7 @@ function elementInsertHandler(parent, newChild, passiveChild, rawMethod) {
|
|
|
733
740
|
if (newChild.__BK_WEWEB_APP_KEY__) {
|
|
734
741
|
const app = appCache.getApp(newChild.__BK_WEWEB_APP_KEY__);
|
|
735
742
|
if (app?.container) {
|
|
736
|
-
const needKeepAlive =
|
|
743
|
+
const needKeepAlive = isSpecialElement(newChild) && app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
737
744
|
const container = needKeepAlive ? document.head : app?.container;
|
|
738
745
|
const targetChild = resetNewElement(parent, newChild, app);
|
|
739
746
|
if (needKeepAlive) {
|
|
@@ -784,15 +791,15 @@ function rewriteBodyAndHeaderMethods() {
|
|
|
784
791
|
}
|
|
785
792
|
};
|
|
786
793
|
HTMLBodyElement.prototype.appendChild = function appendChildNew(newChild) {
|
|
787
|
-
if (newChild.__KEEP_ALIVE__ &&
|
|
788
|
-
return
|
|
794
|
+
if (newChild.__KEEP_ALIVE__ && isSpecialElement(newChild)) return headAppendChild.call(rawHead, newChild);
|
|
795
|
+
return elementAppendHandler(this, newChild, bodyAppendChild2);
|
|
789
796
|
};
|
|
790
797
|
HTMLBodyElement.prototype.append = function(...nodes) {
|
|
791
798
|
nodes.forEach((node) => {
|
|
792
|
-
if (node.__KEEP_ALIVE__ &&
|
|
799
|
+
if (node.__KEEP_ALIVE__ && isSpecialElement(node)) {
|
|
793
800
|
return headAppendChild.call(rawHead, node);
|
|
794
801
|
}
|
|
795
|
-
|
|
802
|
+
elementAppendHandler(this, node, bodyAppendChild2);
|
|
796
803
|
});
|
|
797
804
|
};
|
|
798
805
|
HTMLHeadElement.prototype.appendChild = HTMLBodyElement.prototype.appendChild;
|
|
@@ -1076,7 +1083,10 @@ var weWeb = new WeWeb();
|
|
|
1076
1083
|
var src_default = weWeb;
|
|
1077
1084
|
|
|
1078
1085
|
// src/utils/fetch.ts
|
|
1079
|
-
function fetchSource(url, options = {}) {
|
|
1086
|
+
function fetchSource(url, options = {}, app) {
|
|
1087
|
+
if (typeof app?.fetchSource === "function") {
|
|
1088
|
+
return app.fetchSource(url, options).catch(() => "");
|
|
1089
|
+
}
|
|
1080
1090
|
if (src_default.fetchSource) {
|
|
1081
1091
|
return src_default.fetchSource(url, options);
|
|
1082
1092
|
}
|
|
@@ -1139,14 +1149,16 @@ var Style = class {
|
|
|
1139
1149
|
}
|
|
1140
1150
|
createStyleElement() {
|
|
1141
1151
|
const styleElement = document.createElement("style");
|
|
1142
|
-
if (styleElement.__BK_WEWEB_APP_KEY__)
|
|
1152
|
+
if (styleElement.__BK_WEWEB_APP_KEY__) {
|
|
1153
|
+
styleElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
1154
|
+
}
|
|
1143
1155
|
return styleElement;
|
|
1144
1156
|
}
|
|
1145
1157
|
/**
|
|
1146
1158
|
* @param app 应用实例
|
|
1147
1159
|
* @returns 返回执行后的style标签
|
|
1148
1160
|
*/
|
|
1149
|
-
async
|
|
1161
|
+
async executeCode(app) {
|
|
1150
1162
|
app.registerRunningApp();
|
|
1151
1163
|
let styleElement = this.createStyleElement();
|
|
1152
1164
|
styleElement.setAttribute("type", "text/css");
|
|
@@ -1173,7 +1185,7 @@ var Style = class {
|
|
|
1173
1185
|
code = style?.code || "";
|
|
1174
1186
|
}
|
|
1175
1187
|
if (!code) {
|
|
1176
|
-
code = await fetchSource(this.url).catch(() => "");
|
|
1188
|
+
code = await fetchSource(this.url, {}, app).catch(() => "");
|
|
1177
1189
|
}
|
|
1178
1190
|
this.code = code;
|
|
1179
1191
|
return code;
|
|
@@ -1192,13 +1204,14 @@ var Style = class {
|
|
|
1192
1204
|
const result = this.scopeRule(Array.from(rule.cssRules), prefix);
|
|
1193
1205
|
return `@${packName} ${rule.conditionText} {${result}}`;
|
|
1194
1206
|
}
|
|
1195
|
-
resetUrlHost(cssText,
|
|
1207
|
+
resetUrlHost(cssText, uri, linkPath) {
|
|
1208
|
+
let baseURI = uri;
|
|
1196
1209
|
return cssText.replace(/url\(["']?([^)"']+)["']?\)/gm, (text, $1) => {
|
|
1197
1210
|
if (/^(data|blob):/.test($1) || /^(https?:)?\/\//.test($1)) {
|
|
1198
1211
|
return text;
|
|
1199
1212
|
}
|
|
1200
|
-
if (/^((\.\.?\/)|[^/])/.test($1) &&
|
|
1201
|
-
const pathArr =
|
|
1213
|
+
if (/^((\.\.?\/)|[^/])/.test($1) && linkPath) {
|
|
1214
|
+
const pathArr = linkPath.split("/");
|
|
1202
1215
|
pathArr.pop();
|
|
1203
1216
|
baseURI = addUrlProtocol(`${pathArr.join("/")}/`);
|
|
1204
1217
|
}
|
|
@@ -1308,18 +1321,18 @@ var Style = class {
|
|
|
1308
1321
|
return styleElement;
|
|
1309
1322
|
}
|
|
1310
1323
|
};
|
|
1311
|
-
async function
|
|
1324
|
+
async function executeAppStyles(app, container) {
|
|
1312
1325
|
const styleList = Array.from(app.source.styles.values());
|
|
1313
1326
|
const promiseList = [];
|
|
1314
|
-
|
|
1315
|
-
promiseList.push(style.
|
|
1316
|
-
}
|
|
1327
|
+
for (const style of styleList) {
|
|
1328
|
+
promiseList.push(style.executeCode(app));
|
|
1329
|
+
}
|
|
1317
1330
|
await Promise.all(promiseList).then((styleElementList) => {
|
|
1318
|
-
const
|
|
1319
|
-
if (app.keepAlive && !(
|
|
1331
|
+
const parentElement = container || app.container;
|
|
1332
|
+
if (app.keepAlive && !(parentElement instanceof ShadowRoot)) {
|
|
1320
1333
|
document.head.append(...styleElementList);
|
|
1321
1334
|
} else {
|
|
1322
|
-
|
|
1335
|
+
parentElement?.append(...styleElementList);
|
|
1323
1336
|
}
|
|
1324
1337
|
});
|
|
1325
1338
|
}
|
|
@@ -1354,6 +1367,7 @@ var MicroInstanceModel = class {
|
|
|
1354
1367
|
// 入口资源
|
|
1355
1368
|
url;
|
|
1356
1369
|
// url
|
|
1370
|
+
fetchSource;
|
|
1357
1371
|
constructor(props) {
|
|
1358
1372
|
this.name = props.id !== props.url ? props.id : random(5);
|
|
1359
1373
|
this.appCacheKey = props.id || this.name;
|
|
@@ -1368,6 +1382,7 @@ var MicroInstanceModel = class {
|
|
|
1368
1382
|
if (this.scopeJs) {
|
|
1369
1383
|
this.sandBox = new SandBox(this);
|
|
1370
1384
|
}
|
|
1385
|
+
this.fetchSource = props.fetchSource;
|
|
1371
1386
|
}
|
|
1372
1387
|
activated(container, callback) {
|
|
1373
1388
|
this.isPreLoad = false;
|
|
@@ -1375,12 +1390,12 @@ var MicroInstanceModel = class {
|
|
|
1375
1390
|
if (this.container && container) {
|
|
1376
1391
|
if (container instanceof Element) container?.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1377
1392
|
const fragment = document.createDocumentFragment();
|
|
1378
|
-
Array.from(this.container.childNodes)
|
|
1393
|
+
for (const node of Array.from(this.container.childNodes)) {
|
|
1379
1394
|
fragment.appendChild(node);
|
|
1380
|
-
}
|
|
1395
|
+
}
|
|
1381
1396
|
container.appendChild(fragment);
|
|
1382
1397
|
this.container = container;
|
|
1383
|
-
this.sandBox?.
|
|
1398
|
+
this.sandBox?.activated();
|
|
1384
1399
|
const scriptInfo = this.source?.getScript(this.url);
|
|
1385
1400
|
callback?.(this, scriptInfo?.exportInstance);
|
|
1386
1401
|
}
|
|
@@ -1394,17 +1409,17 @@ var MicroInstanceModel = class {
|
|
|
1394
1409
|
this.container = container ?? this.container;
|
|
1395
1410
|
this.state = "MOUNTING" /* MOUNTING */;
|
|
1396
1411
|
if (this.container instanceof HTMLElement) {
|
|
1397
|
-
this.container
|
|
1412
|
+
this.container?.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1398
1413
|
}
|
|
1399
1414
|
this.container.innerHTML = "";
|
|
1400
1415
|
const instanceWrap = document.createElement("div");
|
|
1401
1416
|
const wrapId = `${this.name}-wrapper`;
|
|
1402
1417
|
instanceWrap.setAttribute("id", wrapId);
|
|
1403
1418
|
if (this.source?.styles.size) {
|
|
1404
|
-
|
|
1419
|
+
executeAppStyles(this, this.container);
|
|
1405
1420
|
}
|
|
1406
1421
|
this.container.appendChild(instanceWrap);
|
|
1407
|
-
this.sandBox?.
|
|
1422
|
+
this.sandBox?.activated();
|
|
1408
1423
|
execAppScripts(this).finally(() => {
|
|
1409
1424
|
this.state = "MOUNTED" /* MOUNTED */;
|
|
1410
1425
|
const scriptInfo = this.source?.getScript(this.url);
|
|
@@ -1429,7 +1444,7 @@ var MicroInstanceModel = class {
|
|
|
1429
1444
|
async start() {
|
|
1430
1445
|
if (!this.source || ["ERROR" /* ERROR */, "UNSET" /* UNSET */].includes(this.status)) {
|
|
1431
1446
|
this.source = new EntrySource(this.url);
|
|
1432
|
-
await this.source.
|
|
1447
|
+
await this.source.importEntry(this);
|
|
1433
1448
|
}
|
|
1434
1449
|
}
|
|
1435
1450
|
unmount(needDestroy) {
|
|
@@ -1455,6 +1470,7 @@ var Script = class {
|
|
|
1455
1470
|
async = false;
|
|
1456
1471
|
code = "";
|
|
1457
1472
|
defer = false;
|
|
1473
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1458
1474
|
exportInstance;
|
|
1459
1475
|
fromHtml;
|
|
1460
1476
|
initial;
|
|
@@ -1473,39 +1489,41 @@ var Script = class {
|
|
|
1473
1489
|
}
|
|
1474
1490
|
/**
|
|
1475
1491
|
* @param app 应用
|
|
1476
|
-
* @param
|
|
1492
|
+
* @param needReplaceScriptElement 是否需要替换script标签
|
|
1477
1493
|
* @returns 返回执行后的script标签或注释
|
|
1478
1494
|
*/
|
|
1479
|
-
async
|
|
1495
|
+
async executeCode(app, needReplaceScriptElement = false) {
|
|
1480
1496
|
try {
|
|
1481
1497
|
if (!this.code) await this.getCode(app);
|
|
1482
1498
|
if (app instanceof MicroInstanceModel) {
|
|
1483
|
-
const
|
|
1484
|
-
noteGlobalProps(
|
|
1499
|
+
const globalWindow = app.scopeJs ? app.sandBox?.proxyWindow || window : window;
|
|
1500
|
+
noteGlobalProps(globalWindow);
|
|
1485
1501
|
}
|
|
1486
1502
|
let scopedCode = this.code;
|
|
1487
1503
|
scopedCode = this.transformCode(app);
|
|
1488
1504
|
if (app.showSourceCode || this.isModule) {
|
|
1489
1505
|
const scriptElement = document.createElement("script");
|
|
1490
|
-
if (scriptElement.__BK_WEWEB_APP_KEY__)
|
|
1506
|
+
if (scriptElement.__BK_WEWEB_APP_KEY__) {
|
|
1507
|
+
scriptElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
1508
|
+
}
|
|
1491
1509
|
app.registerRunningApp();
|
|
1492
1510
|
this.executeSourceScript(scriptElement, scopedCode);
|
|
1493
|
-
if (
|
|
1511
|
+
if (needReplaceScriptElement) return scriptElement;
|
|
1494
1512
|
const needKeepAlive = !!app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
1495
1513
|
const container = needKeepAlive ? document.head : app.container;
|
|
1496
1514
|
setMarkElement(scriptElement, app, needKeepAlive);
|
|
1497
1515
|
container.appendChild(scriptElement);
|
|
1498
1516
|
} else {
|
|
1499
1517
|
this.executeMemoryScript(app, scopedCode);
|
|
1500
|
-
if (
|
|
1518
|
+
if (needReplaceScriptElement) return document.createComment("\u3010bk-weweb\u3011dynamic script");
|
|
1501
1519
|
}
|
|
1502
1520
|
if (app instanceof MicroInstanceModel) {
|
|
1503
|
-
const
|
|
1504
|
-
const exportProp = getGlobalProp(
|
|
1521
|
+
const globalWindow = app.scopeJs ? app.sandBox?.proxyWindow || window : window;
|
|
1522
|
+
const exportProp = getGlobalProp(globalWindow);
|
|
1505
1523
|
if (exportProp) {
|
|
1506
|
-
this.exportInstance =
|
|
1524
|
+
this.exportInstance = globalWindow[exportProp];
|
|
1507
1525
|
if (!app.scopeJs) {
|
|
1508
|
-
delete
|
|
1526
|
+
delete globalWindow[exportProp];
|
|
1509
1527
|
}
|
|
1510
1528
|
}
|
|
1511
1529
|
}
|
|
@@ -1531,7 +1549,7 @@ var Script = class {
|
|
|
1531
1549
|
// 脚本标签执行
|
|
1532
1550
|
executeSourceScript(scriptElement, scopedCode) {
|
|
1533
1551
|
if (this.isModule) {
|
|
1534
|
-
scriptElement.src = this.url
|
|
1552
|
+
scriptElement.src = `${this.url}?key=${Date.now()}`;
|
|
1535
1553
|
scriptElement.setAttribute("type", "module");
|
|
1536
1554
|
} else {
|
|
1537
1555
|
scriptElement.textContent = scopedCode;
|
|
@@ -1551,7 +1569,7 @@ var Script = class {
|
|
|
1551
1569
|
code = appCache.getCacheScript(this.url)?.code || "";
|
|
1552
1570
|
}
|
|
1553
1571
|
if (!code) {
|
|
1554
|
-
code = await fetchSource(this.url).catch((e) => {
|
|
1572
|
+
code = await fetchSource(this.url, {}, app).catch((e) => {
|
|
1555
1573
|
console.error(`fetch script ${this.url} error`, e);
|
|
1556
1574
|
return "";
|
|
1557
1575
|
});
|
|
@@ -1565,11 +1583,14 @@ var Script = class {
|
|
|
1565
1583
|
}
|
|
1566
1584
|
// 转换脚本内容
|
|
1567
1585
|
transformCode(app) {
|
|
1586
|
+
const sourceMapUrl = this.url ? `//# sourceURL=${this.url}
|
|
1587
|
+
` : "";
|
|
1568
1588
|
if (app.sandBox) {
|
|
1569
1589
|
if (this.isModule) {
|
|
1570
1590
|
return ` with(window.${app.sandBox.windowSymbolKey}){
|
|
1571
1591
|
;${this.code}
|
|
1572
1592
|
|
|
1593
|
+
${sourceMapUrl}
|
|
1573
1594
|
}`;
|
|
1574
1595
|
}
|
|
1575
1596
|
if (app.showSourceCode) {
|
|
@@ -1579,6 +1600,7 @@ var Script = class {
|
|
|
1579
1600
|
|
|
1580
1601
|
${this.code}
|
|
1581
1602
|
|
|
1603
|
+
${sourceMapUrl}
|
|
1582
1604
|
}
|
|
1583
1605
|
}).call(window.${app.sandBox.windowSymbolKey},
|
|
1584
1606
|
window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey});`;
|
|
@@ -1589,6 +1611,8 @@ var Script = class {
|
|
|
1589
1611
|
${getGlobalContextCode()}
|
|
1590
1612
|
|
|
1591
1613
|
${this.code}
|
|
1614
|
+
|
|
1615
|
+
${sourceMapUrl}
|
|
1592
1616
|
}
|
|
1593
1617
|
catch(e) {
|
|
1594
1618
|
console.error(e)
|
|
@@ -1600,7 +1624,10 @@ var Script = class {
|
|
|
1600
1624
|
}
|
|
1601
1625
|
};
|
|
1602
1626
|
function shouldSkipProperty(global, p) {
|
|
1603
|
-
return
|
|
1627
|
+
return (
|
|
1628
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
1629
|
+
!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
|
|
1630
|
+
);
|
|
1604
1631
|
}
|
|
1605
1632
|
function getGlobalProp(global, useFirstGlobalProp) {
|
|
1606
1633
|
let cnt = 0;
|
|
@@ -1632,16 +1659,16 @@ function noteGlobalProps(global) {
|
|
|
1632
1659
|
}
|
|
1633
1660
|
async function execAppScripts(app) {
|
|
1634
1661
|
const appScriptList = Array.from(app.source.scripts.values()).filter((script) => script.fromHtml || script.initial);
|
|
1635
|
-
const
|
|
1636
|
-
await Promise.all(
|
|
1637
|
-
await Promise.all(
|
|
1662
|
+
const commonList = appScriptList.filter((script) => !script.async && !script.defer || script.isModule);
|
|
1663
|
+
await Promise.all(commonList.map((script) => script.getCode(app)));
|
|
1664
|
+
await Promise.all(commonList.map((script) => script.executeCode(app)));
|
|
1638
1665
|
const deferScriptList = [];
|
|
1639
1666
|
const asyncScriptList = [];
|
|
1640
1667
|
for (const script of appScriptList) {
|
|
1641
1668
|
if (script.defer || script.async) {
|
|
1642
1669
|
if (!script.code && script.defer) {
|
|
1643
|
-
deferScriptList.push(script.
|
|
1644
|
-
} else asyncScriptList.push(script.
|
|
1670
|
+
deferScriptList.push(script.executeCode(app));
|
|
1671
|
+
} else asyncScriptList.push(script.executeCode(app));
|
|
1645
1672
|
}
|
|
1646
1673
|
}
|
|
1647
1674
|
await Promise.all([...asyncScriptList, ...deferScriptList]).catch((e) => {
|
|
@@ -1713,7 +1740,8 @@ var MicroAppModel = class {
|
|
|
1713
1740
|
if (container && this.container) {
|
|
1714
1741
|
if (container instanceof Element) container.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1715
1742
|
const fragment = document.createDocumentFragment();
|
|
1716
|
-
Array.from(this.container.childNodes)
|
|
1743
|
+
const list2 = Array.from(this.container.childNodes);
|
|
1744
|
+
for (const node of list2) {
|
|
1717
1745
|
node.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
|
|
1718
1746
|
Object.defineProperties(node, {
|
|
1719
1747
|
ownerDocument: {
|
|
@@ -1723,12 +1751,12 @@ var MicroAppModel = class {
|
|
|
1723
1751
|
}
|
|
1724
1752
|
});
|
|
1725
1753
|
fragment.appendChild(node);
|
|
1726
|
-
}
|
|
1754
|
+
}
|
|
1727
1755
|
container.innerHTML = "";
|
|
1728
1756
|
container.appendChild(fragment);
|
|
1729
1757
|
this.container = container;
|
|
1730
1758
|
this.initShadowRootContainer();
|
|
1731
|
-
this.sandBox?.
|
|
1759
|
+
this.sandBox?.activated(this.data);
|
|
1732
1760
|
callback?.(this);
|
|
1733
1761
|
}
|
|
1734
1762
|
}
|
|
@@ -1783,7 +1811,7 @@ var MicroAppModel = class {
|
|
|
1783
1811
|
if (this.container instanceof Element) this.container.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1784
1812
|
const clonedNode = this.source.html.cloneNode(true);
|
|
1785
1813
|
const fragment = document.createDocumentFragment();
|
|
1786
|
-
Array.from(clonedNode.childNodes)
|
|
1814
|
+
for (const node of Array.from(clonedNode.childNodes)) {
|
|
1787
1815
|
node.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
|
|
1788
1816
|
Object.defineProperties(node, {
|
|
1789
1817
|
ownerDocument: {
|
|
@@ -1793,10 +1821,10 @@ var MicroAppModel = class {
|
|
|
1793
1821
|
}
|
|
1794
1822
|
});
|
|
1795
1823
|
fragment.appendChild(node);
|
|
1796
|
-
}
|
|
1824
|
+
}
|
|
1797
1825
|
this.container.innerHTML = "";
|
|
1798
1826
|
this.container.appendChild(fragment);
|
|
1799
|
-
this.sandBox?.
|
|
1827
|
+
this.sandBox?.activated(this.data);
|
|
1800
1828
|
execAppScripts(this).finally(() => {
|
|
1801
1829
|
this.state = "MOUNTED" /* MOUNTED */;
|
|
1802
1830
|
callback?.(this);
|
|
@@ -1823,7 +1851,7 @@ var MicroAppModel = class {
|
|
|
1823
1851
|
this.iframe = iframe;
|
|
1824
1852
|
}
|
|
1825
1853
|
this.source = new EntrySource(this.url);
|
|
1826
|
-
await this.source.
|
|
1854
|
+
await this.source.importEntry(this);
|
|
1827
1855
|
}
|
|
1828
1856
|
}
|
|
1829
1857
|
unmount(needDestroy = false) {
|
|
@@ -1941,7 +1969,7 @@ var EntrySource = class {
|
|
|
1941
1969
|
url: nonceStr
|
|
1942
1970
|
});
|
|
1943
1971
|
this.scripts.set(nonceStr, scriptInstance);
|
|
1944
|
-
replaceElement = document.createComment("\u3010bk-weweb\u3011script with
|
|
1972
|
+
replaceElement = document.createComment("\u3010bk-weweb\u3011script with text content");
|
|
1945
1973
|
!needReplaceELement && parent.replaceChild(replaceElement, script);
|
|
1946
1974
|
return {
|
|
1947
1975
|
replace: replaceElement,
|
|
@@ -1952,11 +1980,11 @@ var EntrySource = class {
|
|
|
1952
1980
|
}
|
|
1953
1981
|
collectScriptAndStyle(parent) {
|
|
1954
1982
|
const links = Array.from(parent.querySelectorAll("link"));
|
|
1955
|
-
|
|
1983
|
+
for (const link of links || []) {
|
|
1956
1984
|
this.collectLink(link, link.parentElement);
|
|
1957
|
-
}
|
|
1985
|
+
}
|
|
1958
1986
|
const styles = Array.from(parent.querySelectorAll("style"));
|
|
1959
|
-
|
|
1987
|
+
for (const style of styles || []) {
|
|
1960
1988
|
if (!style.hasAttribute("exclude") && !style.hasAttribute("ignore")) {
|
|
1961
1989
|
this.styles.set(
|
|
1962
1990
|
randomUrl(),
|
|
@@ -1968,21 +1996,21 @@ var EntrySource = class {
|
|
|
1968
1996
|
);
|
|
1969
1997
|
style.remove();
|
|
1970
1998
|
}
|
|
1971
|
-
}
|
|
1999
|
+
}
|
|
1972
2000
|
const scripts = Array.from(parent.querySelectorAll("script"));
|
|
1973
|
-
|
|
2001
|
+
for (const script of scripts) {
|
|
1974
2002
|
this.collectScript(script, script.parentElement);
|
|
1975
|
-
}
|
|
2003
|
+
}
|
|
1976
2004
|
const metas = Array.from(parent.querySelectorAll("meta"));
|
|
1977
|
-
|
|
2005
|
+
for (const meta of metas) {
|
|
1978
2006
|
meta.parentElement.removeChild(meta);
|
|
1979
|
-
}
|
|
2007
|
+
}
|
|
1980
2008
|
const imgs = Array.from(parent.querySelectorAll("img"));
|
|
1981
|
-
|
|
2009
|
+
for (const img of imgs) {
|
|
1982
2010
|
if (img.hasAttribute("src")) {
|
|
1983
2011
|
img.setAttribute("src", fillUpPath(img.getAttribute("src"), this.url));
|
|
1984
2012
|
}
|
|
1985
|
-
}
|
|
2013
|
+
}
|
|
1986
2014
|
}
|
|
1987
2015
|
getScript(url) {
|
|
1988
2016
|
return this.scripts.get(url);
|
|
@@ -1990,7 +2018,7 @@ var EntrySource = class {
|
|
|
1990
2018
|
getStyle(urlOrCode) {
|
|
1991
2019
|
return this.styles.get(urlOrCode) || Array.from(this.styles.values()).find((style) => style.code === urlOrCode);
|
|
1992
2020
|
}
|
|
1993
|
-
async
|
|
2021
|
+
async importEntry(app) {
|
|
1994
2022
|
if (app.initSource?.length) {
|
|
1995
2023
|
const { collectScript, collectStyle } = await collectSource(app.initSource);
|
|
1996
2024
|
if (collectScript) {
|
|
@@ -2001,32 +2029,34 @@ var EntrySource = class {
|
|
|
2001
2029
|
}
|
|
2002
2030
|
}
|
|
2003
2031
|
if (app instanceof MicroAppModel) await this.importHtmlEntry(app);
|
|
2004
|
-
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry();
|
|
2032
|
+
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry(app);
|
|
2005
2033
|
}
|
|
2006
2034
|
async importHtmlEntry(app) {
|
|
2007
2035
|
let htmlStr = appCache.getCacheHtml(this.url);
|
|
2008
2036
|
if (!htmlStr) {
|
|
2009
|
-
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" });
|
|
2037
|
+
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" }, app);
|
|
2010
2038
|
if (!htmlStr) {
|
|
2011
|
-
console.error("load app entry error,
|
|
2039
|
+
console.error("load app entry error, place check");
|
|
2012
2040
|
return Promise.reject();
|
|
2013
2041
|
}
|
|
2014
2042
|
}
|
|
2015
2043
|
this.rawHtml = htmlStr;
|
|
2016
2044
|
const wrapElement = document.createElement("div");
|
|
2017
|
-
if (wrapElement.__BK_WEWEB_APP_KEY__)
|
|
2045
|
+
if (wrapElement.__BK_WEWEB_APP_KEY__) {
|
|
2046
|
+
wrapElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
2047
|
+
}
|
|
2018
2048
|
wrapElement.innerHTML = htmlStr.replace(/<\/?head>/gim, "").replace(/<\/?body>/i, "");
|
|
2019
2049
|
this.collectScriptAndStyle(wrapElement);
|
|
2020
|
-
await
|
|
2050
|
+
await executeAppStyles(app, wrapElement);
|
|
2021
2051
|
this.html = wrapElement;
|
|
2022
2052
|
}
|
|
2023
|
-
async importInstanceEntry() {
|
|
2053
|
+
async importInstanceEntry(app) {
|
|
2024
2054
|
let jsStr = appCache.getCacheScript(this.url)?.code;
|
|
2025
2055
|
if (!jsStr) {
|
|
2026
|
-
jsStr = await fetchSource(this.url, { cache: "no-cache" });
|
|
2056
|
+
jsStr = await fetchSource(this.url, { cache: "no-cache" }, app);
|
|
2027
2057
|
}
|
|
2028
2058
|
if (!jsStr) {
|
|
2029
|
-
console.error("load app entry error,
|
|
2059
|
+
console.error("load app entry error, place check");
|
|
2030
2060
|
return Promise.reject();
|
|
2031
2061
|
}
|
|
2032
2062
|
this.scripts.set(
|
|
@@ -2074,16 +2104,16 @@ var AppCache = class {
|
|
|
2074
2104
|
return this.baseSource.getStyle(urlOrCode);
|
|
2075
2105
|
}
|
|
2076
2106
|
getCacheHtml(url) {
|
|
2077
|
-
const
|
|
2078
|
-
const app =
|
|
2107
|
+
const list2 = Array.from(this.cache.values());
|
|
2108
|
+
const app = list2.find((item) => item.url === url);
|
|
2079
2109
|
if (app) return app.source?.rawHtml || "";
|
|
2080
2110
|
return "";
|
|
2081
2111
|
}
|
|
2082
2112
|
getCacheScript(url) {
|
|
2083
2113
|
let script = this.baseSource.getScript(url);
|
|
2084
2114
|
if (script) return;
|
|
2085
|
-
const
|
|
2086
|
-
|
|
2115
|
+
const list2 = Array.from(this.cache.values());
|
|
2116
|
+
list2.some((app) => {
|
|
2087
2117
|
script = app.source?.getScript(url);
|
|
2088
2118
|
return !!script;
|
|
2089
2119
|
});
|
|
@@ -2092,8 +2122,8 @@ var AppCache = class {
|
|
|
2092
2122
|
getCacheStyle(url) {
|
|
2093
2123
|
let style = this.baseSource.getStyle(url);
|
|
2094
2124
|
if (style) return;
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2125
|
+
const list2 = Array.from(this.cache.values());
|
|
2126
|
+
list2.some((app) => {
|
|
2097
2127
|
style = app.source?.getStyle(url);
|
|
2098
2128
|
return !!style;
|
|
2099
2129
|
});
|
|
@@ -2221,7 +2251,7 @@ function collectBaseSource() {
|
|
|
2221
2251
|
};
|
|
2222
2252
|
window.addEventListener("load", () => {
|
|
2223
2253
|
const nodeList = document.head.querySelectorAll("style");
|
|
2224
|
-
|
|
2254
|
+
for (const node of Array.from(nodeList)) {
|
|
2225
2255
|
node.textContent && appCache.setBaseAppStyle(
|
|
2226
2256
|
randomUrl(),
|
|
2227
2257
|
new Style({
|
|
@@ -2230,7 +2260,7 @@ function collectBaseSource() {
|
|
|
2230
2260
|
url: ""
|
|
2231
2261
|
})
|
|
2232
2262
|
);
|
|
2233
|
-
}
|
|
2263
|
+
}
|
|
2234
2264
|
});
|
|
2235
2265
|
}
|
|
2236
2266
|
export {
|