@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
package/dist/index.esm.js
CHANGED
|
@@ -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
|
|
|
@@ -470,7 +475,7 @@ var SandBox = class {
|
|
|
470
475
|
return Reflect.defineProperty(target, key, value);
|
|
471
476
|
},
|
|
472
477
|
deleteProperty: (target, key) => {
|
|
473
|
-
if (
|
|
478
|
+
if (Object.hasOwn(target, key)) {
|
|
474
479
|
this.sameRawWindowKeySet.has(key) && this.sameRawWindowKeySet.delete(key);
|
|
475
480
|
this.inRawWindowKeySet.has(key) && Reflect.deleteProperty(rawWindow, key);
|
|
476
481
|
return Reflect.deleteProperty(target, key);
|
|
@@ -493,7 +498,7 @@ var SandBox = class {
|
|
|
493
498
|
return this.app.iframe.contentWindow?.[key];
|
|
494
499
|
}
|
|
495
500
|
if (key === "hasOwnProperty")
|
|
496
|
-
return (key2) => this.fakeWindow
|
|
501
|
+
return (key2) => Object.hasOwn(this.fakeWindow, key2) || Object.hasOwn(rawWindow, key2);
|
|
497
502
|
if (key === "top" || key === "parent") {
|
|
498
503
|
if (rawWindow === rawWindow.parent) {
|
|
499
504
|
return this.proxyWindow;
|
|
@@ -513,10 +518,10 @@ var SandBox = class {
|
|
|
513
518
|
return bindFunctionToRawWindow(rawWindow, rawValue);
|
|
514
519
|
},
|
|
515
520
|
getOwnPropertyDescriptor: (target, key) => {
|
|
516
|
-
if (
|
|
521
|
+
if (Object.hasOwn(target, key)) {
|
|
517
522
|
return Object.getOwnPropertyDescriptor(target, key);
|
|
518
523
|
}
|
|
519
|
-
if (
|
|
524
|
+
if (Object.hasOwn(rawWindow, key)) {
|
|
520
525
|
windowDescriptorSet.add(key);
|
|
521
526
|
const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
|
|
522
527
|
if (descriptor && !descriptor.configurable) {
|
|
@@ -536,7 +541,7 @@ var SandBox = class {
|
|
|
536
541
|
}
|
|
537
542
|
if (key === "location") {
|
|
538
543
|
Reflect.set(rawWindow, key, value);
|
|
539
|
-
} else if (!
|
|
544
|
+
} else if (!Object.hasOwn(target, key) && Object.hasOwn(rawWindow, key) && !BK_WEWEB_INJECT_KEY_LIST.includes(key)) {
|
|
540
545
|
const descriptor = Object.getOwnPropertyDescriptor(rawWindow, key);
|
|
541
546
|
const { configurable, enumerable, writable } = descriptor;
|
|
542
547
|
if (writable) {
|
|
@@ -578,7 +583,7 @@ var SandBox = class {
|
|
|
578
583
|
* @param data data for sandbox
|
|
579
584
|
* @description active hook for sandbox
|
|
580
585
|
*/
|
|
581
|
-
|
|
586
|
+
activated(data) {
|
|
582
587
|
if (!this.active) {
|
|
583
588
|
this.active = true;
|
|
584
589
|
this.rawDocument = createProxyDocument(document, this.app);
|
|
@@ -595,7 +600,9 @@ var SandBox = class {
|
|
|
595
600
|
if (!this.active) return;
|
|
596
601
|
this.active = false;
|
|
597
602
|
this.resetWindowFunction();
|
|
598
|
-
|
|
603
|
+
for (const key of this.inRawWindowKeySet) {
|
|
604
|
+
Reflect.deleteProperty(window, key);
|
|
605
|
+
}
|
|
599
606
|
this.inRawWindowKeySet.clear();
|
|
600
607
|
this.resetDocumentAndBodyEvent?.();
|
|
601
608
|
}
|
|
@@ -673,7 +680,7 @@ function resetNewElement(parent, child, app) {
|
|
|
673
680
|
return child;
|
|
674
681
|
}
|
|
675
682
|
if (replaceInfo.script) {
|
|
676
|
-
replaceInfo.script.
|
|
683
|
+
replaceInfo.script.executeCode(app);
|
|
677
684
|
}
|
|
678
685
|
if (replaceInfo.replace !== child) {
|
|
679
686
|
return replaceInfo.replace;
|
|
@@ -691,7 +698,7 @@ function resetNewElement(parent, child, app) {
|
|
|
691
698
|
return;
|
|
692
699
|
}
|
|
693
700
|
if (scriptInfo?.script) {
|
|
694
|
-
scriptInfo.script.
|
|
701
|
+
scriptInfo.script.executeCode(app);
|
|
695
702
|
}
|
|
696
703
|
child.remove();
|
|
697
704
|
} else if (child.textContent) {
|
|
@@ -705,7 +712,7 @@ function resetNewElement(parent, child, app) {
|
|
|
705
712
|
});
|
|
706
713
|
app.source.scripts.set(randomUrl(), scriptInstance);
|
|
707
714
|
try {
|
|
708
|
-
scriptInstance.
|
|
715
|
+
scriptInstance.executeCode(app);
|
|
709
716
|
} catch (e) {
|
|
710
717
|
console.error(e);
|
|
711
718
|
} finally {
|
|
@@ -721,15 +728,15 @@ function resetNewElement(parent, child, app) {
|
|
|
721
728
|
}
|
|
722
729
|
return child;
|
|
723
730
|
}
|
|
724
|
-
function
|
|
731
|
+
function isSpecialElement(node) {
|
|
725
732
|
return node instanceof HTMLScriptElement || node instanceof HTMLStyleElement || node instanceof HTMLLinkElement;
|
|
726
733
|
}
|
|
727
|
-
function
|
|
734
|
+
function elementAppendHandler(parent, newChild, rawMethod) {
|
|
728
735
|
if (newChild.__BK_WEWEB_APP_KEY__) {
|
|
729
736
|
const app = appCache.getApp(newChild.__BK_WEWEB_APP_KEY__);
|
|
730
737
|
if (app?.container) {
|
|
731
738
|
const targetChild = resetNewElement(parent, newChild, app);
|
|
732
|
-
const needKeepAlive =
|
|
739
|
+
const needKeepAlive = isSpecialElement(newChild) && !!app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
733
740
|
const container = needKeepAlive ? document.head : app?.container;
|
|
734
741
|
setMarkElement(targetChild, app, needKeepAlive);
|
|
735
742
|
return rawMethod.call(container, targetChild);
|
|
@@ -741,7 +748,7 @@ function elementInsertHandler(parent, newChild, passiveChild, rawMethod) {
|
|
|
741
748
|
if (newChild.__BK_WEWEB_APP_KEY__) {
|
|
742
749
|
const app = appCache.getApp(newChild.__BK_WEWEB_APP_KEY__);
|
|
743
750
|
if (app?.container) {
|
|
744
|
-
const needKeepAlive =
|
|
751
|
+
const needKeepAlive = isSpecialElement(newChild) && app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
745
752
|
const container = needKeepAlive ? document.head : app?.container;
|
|
746
753
|
const targetChild = resetNewElement(parent, newChild, app);
|
|
747
754
|
if (needKeepAlive) {
|
|
@@ -766,7 +773,10 @@ function setMarkElement(element, app, keepAlive) {
|
|
|
766
773
|
}
|
|
767
774
|
|
|
768
775
|
// src/utils/fetch.ts
|
|
769
|
-
function fetchSource(url, options = {}) {
|
|
776
|
+
function fetchSource(url, options = {}, app) {
|
|
777
|
+
if (typeof app?.fetchSource === "function") {
|
|
778
|
+
return app.fetchSource(url, options).catch(() => "");
|
|
779
|
+
}
|
|
770
780
|
if (src_default.fetchSource) {
|
|
771
781
|
return src_default.fetchSource(url, options);
|
|
772
782
|
}
|
|
@@ -829,14 +839,16 @@ var Style = class {
|
|
|
829
839
|
}
|
|
830
840
|
createStyleElement() {
|
|
831
841
|
const styleElement = document.createElement("style");
|
|
832
|
-
if (styleElement.__BK_WEWEB_APP_KEY__)
|
|
842
|
+
if (styleElement.__BK_WEWEB_APP_KEY__) {
|
|
843
|
+
styleElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
844
|
+
}
|
|
833
845
|
return styleElement;
|
|
834
846
|
}
|
|
835
847
|
/**
|
|
836
848
|
* @param app 应用实例
|
|
837
849
|
* @returns 返回执行后的style标签
|
|
838
850
|
*/
|
|
839
|
-
async
|
|
851
|
+
async executeCode(app) {
|
|
840
852
|
app.registerRunningApp();
|
|
841
853
|
let styleElement = this.createStyleElement();
|
|
842
854
|
styleElement.setAttribute("type", "text/css");
|
|
@@ -863,7 +875,7 @@ var Style = class {
|
|
|
863
875
|
code = style?.code || "";
|
|
864
876
|
}
|
|
865
877
|
if (!code) {
|
|
866
|
-
code = await fetchSource(this.url).catch(() => "");
|
|
878
|
+
code = await fetchSource(this.url, {}, app).catch(() => "");
|
|
867
879
|
}
|
|
868
880
|
this.code = code;
|
|
869
881
|
return code;
|
|
@@ -882,13 +894,14 @@ var Style = class {
|
|
|
882
894
|
const result = this.scopeRule(Array.from(rule.cssRules), prefix);
|
|
883
895
|
return `@${packName} ${rule.conditionText} {${result}}`;
|
|
884
896
|
}
|
|
885
|
-
resetUrlHost(cssText,
|
|
897
|
+
resetUrlHost(cssText, uri, linkPath) {
|
|
898
|
+
let baseURI = uri;
|
|
886
899
|
return cssText.replace(/url\(["']?([^)"']+)["']?\)/gm, (text, $1) => {
|
|
887
900
|
if (/^(data|blob):/.test($1) || /^(https?:)?\/\//.test($1)) {
|
|
888
901
|
return text;
|
|
889
902
|
}
|
|
890
|
-
if (/^((\.\.?\/)|[^/])/.test($1) &&
|
|
891
|
-
const pathArr =
|
|
903
|
+
if (/^((\.\.?\/)|[^/])/.test($1) && linkPath) {
|
|
904
|
+
const pathArr = linkPath.split("/");
|
|
892
905
|
pathArr.pop();
|
|
893
906
|
baseURI = addUrlProtocol(`${pathArr.join("/")}/`);
|
|
894
907
|
}
|
|
@@ -998,18 +1011,18 @@ var Style = class {
|
|
|
998
1011
|
return styleElement;
|
|
999
1012
|
}
|
|
1000
1013
|
};
|
|
1001
|
-
async function
|
|
1014
|
+
async function executeAppStyles(app, container) {
|
|
1002
1015
|
const styleList = Array.from(app.source.styles.values());
|
|
1003
1016
|
const promiseList = [];
|
|
1004
|
-
|
|
1005
|
-
promiseList.push(style.
|
|
1006
|
-
}
|
|
1017
|
+
for (const style of styleList) {
|
|
1018
|
+
promiseList.push(style.executeCode(app));
|
|
1019
|
+
}
|
|
1007
1020
|
await Promise.all(promiseList).then((styleElementList) => {
|
|
1008
|
-
const
|
|
1009
|
-
if (app.keepAlive && !(
|
|
1021
|
+
const parentElement = container || app.container;
|
|
1022
|
+
if (app.keepAlive && !(parentElement instanceof ShadowRoot)) {
|
|
1010
1023
|
document.head.append(...styleElementList);
|
|
1011
1024
|
} else {
|
|
1012
|
-
|
|
1025
|
+
parentElement?.append(...styleElementList);
|
|
1013
1026
|
}
|
|
1014
1027
|
});
|
|
1015
1028
|
}
|
|
@@ -1044,6 +1057,7 @@ var MicroInstanceModel = class {
|
|
|
1044
1057
|
// 入口资源
|
|
1045
1058
|
url;
|
|
1046
1059
|
// url
|
|
1060
|
+
fetchSource;
|
|
1047
1061
|
constructor(props) {
|
|
1048
1062
|
this.name = props.id !== props.url ? props.id : random(5);
|
|
1049
1063
|
this.appCacheKey = props.id || this.name;
|
|
@@ -1058,6 +1072,7 @@ var MicroInstanceModel = class {
|
|
|
1058
1072
|
if (this.scopeJs) {
|
|
1059
1073
|
this.sandBox = new SandBox(this);
|
|
1060
1074
|
}
|
|
1075
|
+
this.fetchSource = props.fetchSource;
|
|
1061
1076
|
}
|
|
1062
1077
|
activated(container, callback) {
|
|
1063
1078
|
this.isPreLoad = false;
|
|
@@ -1065,12 +1080,12 @@ var MicroInstanceModel = class {
|
|
|
1065
1080
|
if (this.container && container) {
|
|
1066
1081
|
if (container instanceof Element) container?.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1067
1082
|
const fragment = document.createDocumentFragment();
|
|
1068
|
-
Array.from(this.container.childNodes)
|
|
1083
|
+
for (const node of Array.from(this.container.childNodes)) {
|
|
1069
1084
|
fragment.appendChild(node);
|
|
1070
|
-
}
|
|
1085
|
+
}
|
|
1071
1086
|
container.appendChild(fragment);
|
|
1072
1087
|
this.container = container;
|
|
1073
|
-
this.sandBox?.
|
|
1088
|
+
this.sandBox?.activated();
|
|
1074
1089
|
const scriptInfo = this.source?.getScript(this.url);
|
|
1075
1090
|
callback?.(this, scriptInfo?.exportInstance);
|
|
1076
1091
|
}
|
|
@@ -1084,17 +1099,17 @@ var MicroInstanceModel = class {
|
|
|
1084
1099
|
this.container = container ?? this.container;
|
|
1085
1100
|
this.state = "MOUNTING" /* MOUNTING */;
|
|
1086
1101
|
if (this.container instanceof HTMLElement) {
|
|
1087
|
-
this.container
|
|
1102
|
+
this.container?.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1088
1103
|
}
|
|
1089
1104
|
this.container.innerHTML = "";
|
|
1090
1105
|
const instanceWrap = document.createElement("div");
|
|
1091
1106
|
const wrapId = `${this.name}-wrapper`;
|
|
1092
1107
|
instanceWrap.setAttribute("id", wrapId);
|
|
1093
1108
|
if (this.source?.styles.size) {
|
|
1094
|
-
|
|
1109
|
+
executeAppStyles(this, this.container);
|
|
1095
1110
|
}
|
|
1096
1111
|
this.container.appendChild(instanceWrap);
|
|
1097
|
-
this.sandBox?.
|
|
1112
|
+
this.sandBox?.activated();
|
|
1098
1113
|
execAppScripts(this).finally(() => {
|
|
1099
1114
|
this.state = "MOUNTED" /* MOUNTED */;
|
|
1100
1115
|
const scriptInfo = this.source?.getScript(this.url);
|
|
@@ -1119,7 +1134,7 @@ var MicroInstanceModel = class {
|
|
|
1119
1134
|
async start() {
|
|
1120
1135
|
if (!this.source || ["ERROR" /* ERROR */, "UNSET" /* UNSET */].includes(this.status)) {
|
|
1121
1136
|
this.source = new EntrySource(this.url);
|
|
1122
|
-
await this.source.
|
|
1137
|
+
await this.source.importEntry(this);
|
|
1123
1138
|
}
|
|
1124
1139
|
}
|
|
1125
1140
|
unmount(needDestroy) {
|
|
@@ -1145,6 +1160,7 @@ var Script = class {
|
|
|
1145
1160
|
async = false;
|
|
1146
1161
|
code = "";
|
|
1147
1162
|
defer = false;
|
|
1163
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1148
1164
|
exportInstance;
|
|
1149
1165
|
fromHtml;
|
|
1150
1166
|
initial;
|
|
@@ -1163,39 +1179,41 @@ var Script = class {
|
|
|
1163
1179
|
}
|
|
1164
1180
|
/**
|
|
1165
1181
|
* @param app 应用
|
|
1166
|
-
* @param
|
|
1182
|
+
* @param needReplaceScriptElement 是否需要替换script标签
|
|
1167
1183
|
* @returns 返回执行后的script标签或注释
|
|
1168
1184
|
*/
|
|
1169
|
-
async
|
|
1185
|
+
async executeCode(app, needReplaceScriptElement = false) {
|
|
1170
1186
|
try {
|
|
1171
1187
|
if (!this.code) await this.getCode(app);
|
|
1172
1188
|
if (app instanceof MicroInstanceModel) {
|
|
1173
|
-
const
|
|
1174
|
-
noteGlobalProps(
|
|
1189
|
+
const globalWindow = app.scopeJs ? app.sandBox?.proxyWindow || window : window;
|
|
1190
|
+
noteGlobalProps(globalWindow);
|
|
1175
1191
|
}
|
|
1176
1192
|
let scopedCode = this.code;
|
|
1177
1193
|
scopedCode = this.transformCode(app);
|
|
1178
1194
|
if (app.showSourceCode || this.isModule) {
|
|
1179
1195
|
const scriptElement = document.createElement("script");
|
|
1180
|
-
if (scriptElement.__BK_WEWEB_APP_KEY__)
|
|
1196
|
+
if (scriptElement.__BK_WEWEB_APP_KEY__) {
|
|
1197
|
+
scriptElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
1198
|
+
}
|
|
1181
1199
|
app.registerRunningApp();
|
|
1182
1200
|
this.executeSourceScript(scriptElement, scopedCode);
|
|
1183
|
-
if (
|
|
1201
|
+
if (needReplaceScriptElement) return scriptElement;
|
|
1184
1202
|
const needKeepAlive = !!app.keepAlive && !(app.container instanceof ShadowRoot);
|
|
1185
1203
|
const container = needKeepAlive ? document.head : app.container;
|
|
1186
1204
|
setMarkElement(scriptElement, app, needKeepAlive);
|
|
1187
1205
|
container.appendChild(scriptElement);
|
|
1188
1206
|
} else {
|
|
1189
1207
|
this.executeMemoryScript(app, scopedCode);
|
|
1190
|
-
if (
|
|
1208
|
+
if (needReplaceScriptElement) return document.createComment("\u3010bk-weweb\u3011dynamic script");
|
|
1191
1209
|
}
|
|
1192
1210
|
if (app instanceof MicroInstanceModel) {
|
|
1193
|
-
const
|
|
1194
|
-
const exportProp = getGlobalProp(
|
|
1211
|
+
const globalWindow = app.scopeJs ? app.sandBox?.proxyWindow || window : window;
|
|
1212
|
+
const exportProp = getGlobalProp(globalWindow);
|
|
1195
1213
|
if (exportProp) {
|
|
1196
|
-
this.exportInstance =
|
|
1214
|
+
this.exportInstance = globalWindow[exportProp];
|
|
1197
1215
|
if (!app.scopeJs) {
|
|
1198
|
-
delete
|
|
1216
|
+
delete globalWindow[exportProp];
|
|
1199
1217
|
}
|
|
1200
1218
|
}
|
|
1201
1219
|
}
|
|
@@ -1221,7 +1239,7 @@ var Script = class {
|
|
|
1221
1239
|
// 脚本标签执行
|
|
1222
1240
|
executeSourceScript(scriptElement, scopedCode) {
|
|
1223
1241
|
if (this.isModule) {
|
|
1224
|
-
scriptElement.src = this.url
|
|
1242
|
+
scriptElement.src = `${this.url}?key=${Date.now()}`;
|
|
1225
1243
|
scriptElement.setAttribute("type", "module");
|
|
1226
1244
|
} else {
|
|
1227
1245
|
scriptElement.textContent = scopedCode;
|
|
@@ -1241,7 +1259,7 @@ var Script = class {
|
|
|
1241
1259
|
code = appCache.getCacheScript(this.url)?.code || "";
|
|
1242
1260
|
}
|
|
1243
1261
|
if (!code) {
|
|
1244
|
-
code = await fetchSource(this.url).catch((e) => {
|
|
1262
|
+
code = await fetchSource(this.url, {}, app).catch((e) => {
|
|
1245
1263
|
console.error(`fetch script ${this.url} error`, e);
|
|
1246
1264
|
return "";
|
|
1247
1265
|
});
|
|
@@ -1255,11 +1273,14 @@ var Script = class {
|
|
|
1255
1273
|
}
|
|
1256
1274
|
// 转换脚本内容
|
|
1257
1275
|
transformCode(app) {
|
|
1276
|
+
const sourceMapUrl = this.url ? `//# sourceURL=${this.url}
|
|
1277
|
+
` : "";
|
|
1258
1278
|
if (app.sandBox) {
|
|
1259
1279
|
if (this.isModule) {
|
|
1260
1280
|
return ` with(window.${app.sandBox.windowSymbolKey}){
|
|
1261
1281
|
;${this.code}
|
|
1262
1282
|
|
|
1283
|
+
${sourceMapUrl}
|
|
1263
1284
|
}`;
|
|
1264
1285
|
}
|
|
1265
1286
|
if (app.showSourceCode) {
|
|
@@ -1269,6 +1290,7 @@ var Script = class {
|
|
|
1269
1290
|
|
|
1270
1291
|
${this.code}
|
|
1271
1292
|
|
|
1293
|
+
${sourceMapUrl}
|
|
1272
1294
|
}
|
|
1273
1295
|
}).call(window.${app.sandBox.windowSymbolKey},
|
|
1274
1296
|
window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey}, window.${app.sandBox.windowSymbolKey});`;
|
|
@@ -1279,6 +1301,8 @@ var Script = class {
|
|
|
1279
1301
|
${getGlobalContextCode()}
|
|
1280
1302
|
|
|
1281
1303
|
${this.code}
|
|
1304
|
+
|
|
1305
|
+
${sourceMapUrl}
|
|
1282
1306
|
}
|
|
1283
1307
|
catch(e) {
|
|
1284
1308
|
console.error(e)
|
|
@@ -1290,7 +1314,10 @@ var Script = class {
|
|
|
1290
1314
|
}
|
|
1291
1315
|
};
|
|
1292
1316
|
function shouldSkipProperty(global, p) {
|
|
1293
|
-
return
|
|
1317
|
+
return (
|
|
1318
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
1319
|
+
!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
|
|
1320
|
+
);
|
|
1294
1321
|
}
|
|
1295
1322
|
function getGlobalProp(global, useFirstGlobalProp) {
|
|
1296
1323
|
let cnt = 0;
|
|
@@ -1322,16 +1349,16 @@ function noteGlobalProps(global) {
|
|
|
1322
1349
|
}
|
|
1323
1350
|
async function execAppScripts(app) {
|
|
1324
1351
|
const appScriptList = Array.from(app.source.scripts.values()).filter((script) => script.fromHtml || script.initial);
|
|
1325
|
-
const
|
|
1326
|
-
await Promise.all(
|
|
1327
|
-
await Promise.all(
|
|
1352
|
+
const commonList = appScriptList.filter((script) => !script.async && !script.defer || script.isModule);
|
|
1353
|
+
await Promise.all(commonList.map((script) => script.getCode(app)));
|
|
1354
|
+
await Promise.all(commonList.map((script) => script.executeCode(app)));
|
|
1328
1355
|
const deferScriptList = [];
|
|
1329
1356
|
const asyncScriptList = [];
|
|
1330
1357
|
for (const script of appScriptList) {
|
|
1331
1358
|
if (script.defer || script.async) {
|
|
1332
1359
|
if (!script.code && script.defer) {
|
|
1333
|
-
deferScriptList.push(script.
|
|
1334
|
-
} else asyncScriptList.push(script.
|
|
1360
|
+
deferScriptList.push(script.executeCode(app));
|
|
1361
|
+
} else asyncScriptList.push(script.executeCode(app));
|
|
1335
1362
|
}
|
|
1336
1363
|
}
|
|
1337
1364
|
await Promise.all([...asyncScriptList, ...deferScriptList]).catch((e) => {
|
|
@@ -1403,7 +1430,8 @@ var MicroAppModel = class {
|
|
|
1403
1430
|
if (container && this.container) {
|
|
1404
1431
|
if (container instanceof Element) container.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1405
1432
|
const fragment = document.createDocumentFragment();
|
|
1406
|
-
Array.from(this.container.childNodes)
|
|
1433
|
+
const list2 = Array.from(this.container.childNodes);
|
|
1434
|
+
for (const node of list2) {
|
|
1407
1435
|
node.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
|
|
1408
1436
|
Object.defineProperties(node, {
|
|
1409
1437
|
ownerDocument: {
|
|
@@ -1413,12 +1441,12 @@ var MicroAppModel = class {
|
|
|
1413
1441
|
}
|
|
1414
1442
|
});
|
|
1415
1443
|
fragment.appendChild(node);
|
|
1416
|
-
}
|
|
1444
|
+
}
|
|
1417
1445
|
container.innerHTML = "";
|
|
1418
1446
|
container.appendChild(fragment);
|
|
1419
1447
|
this.container = container;
|
|
1420
1448
|
this.initShadowRootContainer();
|
|
1421
|
-
this.sandBox?.
|
|
1449
|
+
this.sandBox?.activated(this.data);
|
|
1422
1450
|
callback?.(this);
|
|
1423
1451
|
}
|
|
1424
1452
|
}
|
|
@@ -1473,7 +1501,7 @@ var MicroAppModel = class {
|
|
|
1473
1501
|
if (this.container instanceof Element) this.container.setAttribute(CSS_ATTRIBUTE_KEY, this.name);
|
|
1474
1502
|
const clonedNode = this.source.html.cloneNode(true);
|
|
1475
1503
|
const fragment = document.createDocumentFragment();
|
|
1476
|
-
Array.from(clonedNode.childNodes)
|
|
1504
|
+
for (const node of Array.from(clonedNode.childNodes)) {
|
|
1477
1505
|
node.__BK_WEWEB_APP_KEY__ = this.appCacheKey;
|
|
1478
1506
|
Object.defineProperties(node, {
|
|
1479
1507
|
ownerDocument: {
|
|
@@ -1483,10 +1511,10 @@ var MicroAppModel = class {
|
|
|
1483
1511
|
}
|
|
1484
1512
|
});
|
|
1485
1513
|
fragment.appendChild(node);
|
|
1486
|
-
}
|
|
1514
|
+
}
|
|
1487
1515
|
this.container.innerHTML = "";
|
|
1488
1516
|
this.container.appendChild(fragment);
|
|
1489
|
-
this.sandBox?.
|
|
1517
|
+
this.sandBox?.activated(this.data);
|
|
1490
1518
|
execAppScripts(this).finally(() => {
|
|
1491
1519
|
this.state = "MOUNTED" /* MOUNTED */;
|
|
1492
1520
|
callback?.(this);
|
|
@@ -1513,7 +1541,7 @@ var MicroAppModel = class {
|
|
|
1513
1541
|
this.iframe = iframe;
|
|
1514
1542
|
}
|
|
1515
1543
|
this.source = new EntrySource(this.url);
|
|
1516
|
-
await this.source.
|
|
1544
|
+
await this.source.importEntry(this);
|
|
1517
1545
|
}
|
|
1518
1546
|
}
|
|
1519
1547
|
unmount(needDestroy = false) {
|
|
@@ -1698,7 +1726,7 @@ var EntrySource = class {
|
|
|
1698
1726
|
url: nonceStr
|
|
1699
1727
|
});
|
|
1700
1728
|
this.scripts.set(nonceStr, scriptInstance);
|
|
1701
|
-
replaceElement = document.createComment("\u3010bk-weweb\u3011script with
|
|
1729
|
+
replaceElement = document.createComment("\u3010bk-weweb\u3011script with text content");
|
|
1702
1730
|
!needReplaceELement && parent.replaceChild(replaceElement, script);
|
|
1703
1731
|
return {
|
|
1704
1732
|
replace: replaceElement,
|
|
@@ -1709,11 +1737,11 @@ var EntrySource = class {
|
|
|
1709
1737
|
}
|
|
1710
1738
|
collectScriptAndStyle(parent) {
|
|
1711
1739
|
const links = Array.from(parent.querySelectorAll("link"));
|
|
1712
|
-
|
|
1740
|
+
for (const link of links || []) {
|
|
1713
1741
|
this.collectLink(link, link.parentElement);
|
|
1714
|
-
}
|
|
1742
|
+
}
|
|
1715
1743
|
const styles = Array.from(parent.querySelectorAll("style"));
|
|
1716
|
-
|
|
1744
|
+
for (const style of styles || []) {
|
|
1717
1745
|
if (!style.hasAttribute("exclude") && !style.hasAttribute("ignore")) {
|
|
1718
1746
|
this.styles.set(
|
|
1719
1747
|
randomUrl(),
|
|
@@ -1725,21 +1753,21 @@ var EntrySource = class {
|
|
|
1725
1753
|
);
|
|
1726
1754
|
style.remove();
|
|
1727
1755
|
}
|
|
1728
|
-
}
|
|
1756
|
+
}
|
|
1729
1757
|
const scripts = Array.from(parent.querySelectorAll("script"));
|
|
1730
|
-
|
|
1758
|
+
for (const script of scripts) {
|
|
1731
1759
|
this.collectScript(script, script.parentElement);
|
|
1732
|
-
}
|
|
1760
|
+
}
|
|
1733
1761
|
const metas = Array.from(parent.querySelectorAll("meta"));
|
|
1734
|
-
|
|
1762
|
+
for (const meta of metas) {
|
|
1735
1763
|
meta.parentElement.removeChild(meta);
|
|
1736
|
-
}
|
|
1764
|
+
}
|
|
1737
1765
|
const imgs = Array.from(parent.querySelectorAll("img"));
|
|
1738
|
-
|
|
1766
|
+
for (const img of imgs) {
|
|
1739
1767
|
if (img.hasAttribute("src")) {
|
|
1740
1768
|
img.setAttribute("src", fillUpPath(img.getAttribute("src"), this.url));
|
|
1741
1769
|
}
|
|
1742
|
-
}
|
|
1770
|
+
}
|
|
1743
1771
|
}
|
|
1744
1772
|
getScript(url) {
|
|
1745
1773
|
return this.scripts.get(url);
|
|
@@ -1747,7 +1775,7 @@ var EntrySource = class {
|
|
|
1747
1775
|
getStyle(urlOrCode) {
|
|
1748
1776
|
return this.styles.get(urlOrCode) || Array.from(this.styles.values()).find((style) => style.code === urlOrCode);
|
|
1749
1777
|
}
|
|
1750
|
-
async
|
|
1778
|
+
async importEntry(app) {
|
|
1751
1779
|
if (app.initSource?.length) {
|
|
1752
1780
|
const { collectScript, collectStyle } = await collectSource(app.initSource);
|
|
1753
1781
|
if (collectScript) {
|
|
@@ -1758,32 +1786,34 @@ var EntrySource = class {
|
|
|
1758
1786
|
}
|
|
1759
1787
|
}
|
|
1760
1788
|
if (app instanceof MicroAppModel) await this.importHtmlEntry(app);
|
|
1761
|
-
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry();
|
|
1789
|
+
else if (app instanceof MicroInstanceModel) await this.importInstanceEntry(app);
|
|
1762
1790
|
}
|
|
1763
1791
|
async importHtmlEntry(app) {
|
|
1764
1792
|
let htmlStr = appCache.getCacheHtml(this.url);
|
|
1765
1793
|
if (!htmlStr) {
|
|
1766
|
-
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" });
|
|
1794
|
+
htmlStr = await fetchSource(addUrlProtocol(this.url), { cache: "no-cache" }, app);
|
|
1767
1795
|
if (!htmlStr) {
|
|
1768
|
-
console.error("load app entry error,
|
|
1796
|
+
console.error("load app entry error, place check");
|
|
1769
1797
|
return Promise.reject();
|
|
1770
1798
|
}
|
|
1771
1799
|
}
|
|
1772
1800
|
this.rawHtml = htmlStr;
|
|
1773
1801
|
const wrapElement = document.createElement("div");
|
|
1774
|
-
if (wrapElement.__BK_WEWEB_APP_KEY__)
|
|
1802
|
+
if (wrapElement.__BK_WEWEB_APP_KEY__) {
|
|
1803
|
+
wrapElement.__BK_WEWEB_APP_KEY__ = void 0;
|
|
1804
|
+
}
|
|
1775
1805
|
wrapElement.innerHTML = htmlStr.replace(/<\/?head>/gim, "").replace(/<\/?body>/i, "");
|
|
1776
1806
|
this.collectScriptAndStyle(wrapElement);
|
|
1777
|
-
await
|
|
1807
|
+
await executeAppStyles(app, wrapElement);
|
|
1778
1808
|
this.html = wrapElement;
|
|
1779
1809
|
}
|
|
1780
|
-
async importInstanceEntry() {
|
|
1810
|
+
async importInstanceEntry(app) {
|
|
1781
1811
|
let jsStr = appCache.getCacheScript(this.url)?.code;
|
|
1782
1812
|
if (!jsStr) {
|
|
1783
|
-
jsStr = await fetchSource(this.url, { cache: "no-cache" });
|
|
1813
|
+
jsStr = await fetchSource(this.url, { cache: "no-cache" }, app);
|
|
1784
1814
|
}
|
|
1785
1815
|
if (!jsStr) {
|
|
1786
|
-
console.error("load app entry error,
|
|
1816
|
+
console.error("load app entry error, place check");
|
|
1787
1817
|
return Promise.reject();
|
|
1788
1818
|
}
|
|
1789
1819
|
this.scripts.set(
|
|
@@ -1831,16 +1861,16 @@ var AppCache = class {
|
|
|
1831
1861
|
return this.baseSource.getStyle(urlOrCode);
|
|
1832
1862
|
}
|
|
1833
1863
|
getCacheHtml(url) {
|
|
1834
|
-
const
|
|
1835
|
-
const app =
|
|
1864
|
+
const list2 = Array.from(this.cache.values());
|
|
1865
|
+
const app = list2.find((item) => item.url === url);
|
|
1836
1866
|
if (app) return app.source?.rawHtml || "";
|
|
1837
1867
|
return "";
|
|
1838
1868
|
}
|
|
1839
1869
|
getCacheScript(url) {
|
|
1840
1870
|
let script = this.baseSource.getScript(url);
|
|
1841
1871
|
if (script) return;
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1872
|
+
const list2 = Array.from(this.cache.values());
|
|
1873
|
+
list2.some((app) => {
|
|
1844
1874
|
script = app.source?.getScript(url);
|
|
1845
1875
|
return !!script;
|
|
1846
1876
|
});
|
|
@@ -1849,8 +1879,8 @@ var AppCache = class {
|
|
|
1849
1879
|
getCacheStyle(url) {
|
|
1850
1880
|
let style = this.baseSource.getStyle(url);
|
|
1851
1881
|
if (style) return;
|
|
1852
|
-
const
|
|
1853
|
-
|
|
1882
|
+
const list2 = Array.from(this.cache.values());
|
|
1883
|
+
list2.some((app) => {
|
|
1854
1884
|
style = app.source?.getStyle(url);
|
|
1855
1885
|
return !!style;
|
|
1856
1886
|
});
|
|
@@ -1978,7 +2008,7 @@ function collectBaseSource() {
|
|
|
1978
2008
|
};
|
|
1979
2009
|
window.addEventListener("load", () => {
|
|
1980
2010
|
const nodeList = document.head.querySelectorAll("style");
|
|
1981
|
-
|
|
2011
|
+
for (const node of Array.from(nodeList)) {
|
|
1982
2012
|
node.textContent && appCache.setBaseAppStyle(
|
|
1983
2013
|
randomUrl(),
|
|
1984
2014
|
new Style({
|
|
@@ -1987,7 +2017,7 @@ function collectBaseSource() {
|
|
|
1987
2017
|
url: ""
|
|
1988
2018
|
})
|
|
1989
2019
|
);
|
|
1990
|
-
}
|
|
2020
|
+
}
|
|
1991
2021
|
});
|
|
1992
2022
|
}
|
|
1993
2023
|
|
|
@@ -2018,15 +2048,15 @@ function rewriteBodyAndHeaderMethods() {
|
|
|
2018
2048
|
}
|
|
2019
2049
|
};
|
|
2020
2050
|
HTMLBodyElement.prototype.appendChild = function appendChildNew(newChild) {
|
|
2021
|
-
if (newChild.__KEEP_ALIVE__ &&
|
|
2022
|
-
return
|
|
2051
|
+
if (newChild.__KEEP_ALIVE__ && isSpecialElement(newChild)) return headAppendChild.call(rawHead, newChild);
|
|
2052
|
+
return elementAppendHandler(this, newChild, bodyAppendChild2);
|
|
2023
2053
|
};
|
|
2024
2054
|
HTMLBodyElement.prototype.append = function(...nodes) {
|
|
2025
2055
|
nodes.forEach((node) => {
|
|
2026
|
-
if (node.__KEEP_ALIVE__ &&
|
|
2056
|
+
if (node.__KEEP_ALIVE__ && isSpecialElement(node)) {
|
|
2027
2057
|
return headAppendChild.call(rawHead, node);
|
|
2028
2058
|
}
|
|
2029
|
-
|
|
2059
|
+
elementAppendHandler(this, node, bodyAppendChild2);
|
|
2030
2060
|
});
|
|
2031
2061
|
};
|
|
2032
2062
|
HTMLHeadElement.prototype.appendChild = HTMLBodyElement.prototype.appendChild;
|