@open-wxa/wxa-runner-core 0.8.2 → 0.10.0
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 +119 -3
- package/dist/index.d.ts +119 -3
- package/dist/index.js +478 -170
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +478 -170
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/frame.js +90 -77
- package/dist/runtime/frame.js.map +1 -1
- package/dist/runtime/host.js +63 -44
- package/dist/runtime/host.js.map +1 -1
- package/package.json +6 -3
package/dist/runtime/host.js
CHANGED
|
@@ -1299,9 +1299,9 @@ ${frames}` : "");
|
|
|
1299
1299
|
}
|
|
1300
1300
|
function sleep(ms, signal) {
|
|
1301
1301
|
return new Promise((resolve, reject) => {
|
|
1302
|
-
if (signal
|
|
1302
|
+
if (signal.aborted) return reject(signal.reason);
|
|
1303
1303
|
const timer = setTimeout(resolve, ms);
|
|
1304
|
-
signal
|
|
1304
|
+
signal.addEventListener("abort", () => {
|
|
1305
1305
|
clearTimeout(timer);
|
|
1306
1306
|
reject(signal.reason);
|
|
1307
1307
|
}, { once: true });
|
|
@@ -2144,6 +2144,29 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2144
2144
|
}
|
|
2145
2145
|
};
|
|
2146
2146
|
|
|
2147
|
+
// src/runtime/host/ui/tabBarView.ts
|
|
2148
|
+
function tabBarView(config, selectedPath) {
|
|
2149
|
+
return {
|
|
2150
|
+
background: config.backgroundColor || "#f7f7f7",
|
|
2151
|
+
borderTopColor: config.borderStyle === "white" ? "rgba(255,255,255,.3)" : "rgba(0,0,0,.1)",
|
|
2152
|
+
items: config.list.map((item) => itemView(config, item, item.pagePath === selectedPath))
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
function itemView(config, item, selected) {
|
|
2156
|
+
const icon = selected ? item.selectedIconPath || item.iconPath : item.iconPath;
|
|
2157
|
+
return {
|
|
2158
|
+
pagePath: item.pagePath,
|
|
2159
|
+
selected,
|
|
2160
|
+
color: selected ? config.selectedColor || "#07c160" : config.color || "#7a7e83",
|
|
2161
|
+
icon: icon ? iconUrl(icon) : null,
|
|
2162
|
+
text: item.text || "",
|
|
2163
|
+
mark: item.mark || null
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
function iconUrl(path) {
|
|
2167
|
+
return /^https?:\/\//.test(path) ? path : "/" + path.replace(/^\//, "");
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2147
2170
|
// src/runtime/host/ui/PhoneShell.ts
|
|
2148
2171
|
var SCALE_STORAGE_KEY = "wxa-runner:scale";
|
|
2149
2172
|
var MIN_SCALE = 0.5;
|
|
@@ -2324,29 +2347,27 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2324
2347
|
const visible = this.tabBarVisible();
|
|
2325
2348
|
this.tabBar.classList.toggle("is-hidden", !visible);
|
|
2326
2349
|
if (!config || !visible) return;
|
|
2327
|
-
|
|
2328
|
-
this.tabBar.style.
|
|
2329
|
-
this.tabBar.
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
this.tabBar.appendChild(el);
|
|
2349
|
-
});
|
|
2350
|
+
const view = tabBarView(config, selectedPath);
|
|
2351
|
+
this.tabBar.style.background = view.background;
|
|
2352
|
+
this.tabBar.style.borderTopColor = view.borderTopColor;
|
|
2353
|
+
this.tabBar.replaceChildren(...view.items.map((item, index) => this.tabBarItemElement(item, index)));
|
|
2354
|
+
}
|
|
2355
|
+
tabBarItemElement(item, index) {
|
|
2356
|
+
const el = element("div", "wxa-tabbar-item" + (item.selected ? " is-selected" : ""));
|
|
2357
|
+
el.dataset.pagePath = item.pagePath;
|
|
2358
|
+
el.style.color = item.color;
|
|
2359
|
+
const iconBox = element("span", "wxa-tabbar-icon");
|
|
2360
|
+
if (item.icon) {
|
|
2361
|
+
const img = document.createElement("img");
|
|
2362
|
+
img.src = item.icon;
|
|
2363
|
+
iconBox.appendChild(img);
|
|
2364
|
+
el.appendChild(iconBox);
|
|
2365
|
+
}
|
|
2366
|
+
const text = element("span", "wxa-tabbar-text", item.text);
|
|
2367
|
+
el.appendChild(text);
|
|
2368
|
+
if (item.mark) (item.icon ? iconBox : text).appendChild(markElement(item.mark));
|
|
2369
|
+
el.addEventListener("click", () => this.onTabTap(item.pagePath, index));
|
|
2370
|
+
return el;
|
|
2350
2371
|
}
|
|
2351
2372
|
tabBarVisible() {
|
|
2352
2373
|
return this.tabBarPath !== null && this.hasTabBar(this.tabBarPath);
|
|
@@ -2997,32 +3018,30 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2997
3018
|
|
|
2998
3019
|
// src/runtime/host/hmr.ts
|
|
2999
3020
|
async function applyHotUpdate(host, update) {
|
|
3000
|
-
const
|
|
3001
|
-
const hasStyles = update.styles.length > 0;
|
|
3002
|
-
const v = `?v=${update.version}`;
|
|
3003
|
-
const [pageStyles, pageTemplates, serviceTemplates, moduleScripts] = await Promise.all([
|
|
3004
|
-
hasStyles ? fetchText(`/__wxa__/page-styles.js${v}`) : "",
|
|
3005
|
-
hasTemplates ? fetchText(`/__wxa__/page-templates.js${v}`) : "",
|
|
3006
|
-
hasTemplates ? fetchText(`/__wxa__/service-templates.js${v}`) : "",
|
|
3007
|
-
Promise.all(update.scripts.map((id) => fetchText(`/__wxa__/module/${encodeURI(id)}.js${v}`)))
|
|
3008
|
-
]);
|
|
3021
|
+
const code = await fetchHotCode(update);
|
|
3009
3022
|
await host.enqueueRoute(async () => {
|
|
3010
3023
|
const service = host.serviceWindow();
|
|
3011
3024
|
if (!service?.__virtualDOM__?.updateWxAppCode) throw new Error("\u57FA\u7840\u5E93\u7684\u70ED\u66F4\u65B0\u5F00\u5173\u6CA1\u6709\u6253\u5F00");
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
}
|
|
3025
|
+
const pageWindows = host.livePages().flatMap((page) => page.win ? [page.win] : []);
|
|
3026
|
+
if (code.pageStyles !== null) {
|
|
3027
|
+
for (const win of pageWindows) updateStyles(win, code.pageStyles);
|
|
3016
3028
|
}
|
|
3017
|
-
if (
|
|
3018
|
-
for (const
|
|
3019
|
-
|
|
3020
|
-
}
|
|
3021
|
-
updateTemplates(service, serviceTemplates, update.templates);
|
|
3029
|
+
if (code.templates) {
|
|
3030
|
+
for (const win of pageWindows) updateTemplates(win, code.templates.page, update.templates);
|
|
3031
|
+
updateTemplates(service, code.templates.service, update.templates);
|
|
3022
3032
|
}
|
|
3023
|
-
update.scripts.forEach((id, index) => updateScript(service, host, id,
|
|
3033
|
+
update.scripts.forEach((id, index) => updateScript(service, host, id, code.scripts[index]));
|
|
3024
3034
|
});
|
|
3025
3035
|
}
|
|
3036
|
+
async function fetchHotCode(update) {
|
|
3037
|
+
const v = `?v=${update.version}`;
|
|
3038
|
+
const [pageStyles, templates, scripts] = await Promise.all([
|
|
3039
|
+
update.styles.length > 0 ? fetchText(`/__wxa__/page-styles.js${v}`) : null,
|
|
3040
|
+
update.templates.length > 0 ? Promise.all([fetchText(`/__wxa__/page-templates.js${v}`), fetchText(`/__wxa__/service-templates.js${v}`)]).then(([page, service]) => ({ page, service })) : null,
|
|
3041
|
+
Promise.all(update.scripts.map((id) => fetchText(`/__wxa__/module/${encodeURI(id)}.js${v}`)))
|
|
3042
|
+
]);
|
|
3043
|
+
return { pageStyles, templates, scripts };
|
|
3044
|
+
}
|
|
3026
3045
|
function updateStyles(win, code) {
|
|
3027
3046
|
const sheets = win.__styleSheetManager2__?._pathMap;
|
|
3028
3047
|
if (!sheets) throw new Error("\u57FA\u7840\u5E93\u6CA1\u6709\u6837\u5F0F\u8868\u7BA1\u7406\u5668\uFF0C\u65E0\u6CD5\u70ED\u66FF\u6362\u6837\u5F0F");
|