function escapeHtml(text) {
return text.replace(/[&<>"]/g, (char) => {
if (char === "&")
return "&";
if (char === "<")
return "<";
if (char === ">")
return ">";
return """;
});
}
function time(at) {
return new Date(at).toLocaleTimeString("zh-CN", { hour12: false });
}
function size(bytes) {
if (bytes <= 0)
return "未实测";
if (bytes < 1024 * 1024)
return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
}
function checkRow(check) {
return `
${check.pass ? "PASS" : "FAIL"}
${escapeHtml(check.label)}
${escapeHtml(check.detail)}
`;
}
function layerRow(layer, index) {
return `
${index + 1}
${escapeHtml(layer.title)}
→ ${escapeHtml(layer.output)}
${escapeHtml(layer.note)}
`;
}
function artifactRow(row) {
return `
${escapeHtml(row.id)} |
${escapeHtml(row.platform)} |
${escapeHtml(row.installer)} |
${row.updateSource ? "是" : "否"} |
${escapeHtml(row.tool)} |
`;
}
function toolRow(row) {
return `
| ${escapeHtml(row.name)} |
${escapeHtml(row.configLines)} |
${escapeHtml(row.targets)} |
${escapeHtml(row.update)} |
`;
}
function measureRow(label, bytes, max) {
const width = max > 0 ? Math.max(3, Math.round((bytes / max) * 100)) : 3;
return `
${escapeHtml(label)}
${size(bytes)}
`;
}
export function mountApp(root) {
root.innerHTML = `
—
四个层次
package → make → distribute → update
`;
const score = root.querySelector('[data-testid="score"]');
const banner = root.querySelector('[data-testid="banner"]');
const artifactCount = root.querySelector('[data-testid="artifact-count"]');
const layersEl = root.querySelector('[data-testid="layers"]');
const artifactsEl = root.querySelector('[data-testid="artifacts"]');
const measuredAt = root.querySelector('[data-testid="measured-at"]');
const measuresEl = root.querySelector('[data-testid="measures"]');
const measureMeta = root.querySelector('[data-testid="measure-meta"]');
const measureNote = root.querySelector('[data-testid="measure-note"]');
const toolsEl = root.querySelector('[data-testid="tools"]');
const checksEl = root.querySelector('[data-testid="checks"]');
const checkCount = root.querySelector('[data-testid="check-count"]');
const eventsEl = root.querySelector('[data-testid="events"]');
let state = null;
function renderLayers() {
if (!state)
return;
if (layersEl) {
layersEl.innerHTML = state.layers.map(layerRow).join("");
}
if (artifactsEl) {
artifactsEl.innerHTML = state.artifacts.map(artifactRow).join("");
}
if (artifactCount) {
artifactCount.textContent = `${state.artifacts.length} 项 · ${state.artifacts.filter((row) => row.updateSource).length} 个更新源`;
}
if (banner) {
const m = state.measurements;
banner.textContent =
m.appBytes > 0
? `${m.appName} · ${m.arch} · app ${size(m.appBytes)} / asar ${size(m.asarBytes)} / zip ${size(m.zipBytes)} / dmg ${size(m.dmgBytes)}`
: "尚未读取到实测产物;先运行 pnpm package 再刷新";
banner.className = `banner ${m.appBytes > 0 ? "ok" : "warn"}`;
}
}
function renderMeasures() {
if (!state)
return;
const m = state.measurements;
if (measuredAt) {
measuredAt.textContent = m.measuredAt || "未记录";
}
if (measuresEl) {
const max = Math.max(m.appBytes, m.zipBytes, m.dmgBytes, 1);
measuresEl.innerHTML = [
measureRow("app 目录", m.appBytes, max),
measureRow("app.asar", m.asarBytes, max),
measureRow("zip", m.zipBytes, max),
measureRow("dmg", m.dmgBytes, max),
].join("");
}
if (measureMeta) {
measureMeta.innerHTML = `
arch${escapeHtml(m.arch || "—")}
appName${escapeHtml(m.appName)}
`;
}
if (measureNote)
measureNote.textContent = m.note;
}
function renderTools() {
if (!state || !toolsEl)
return;
toolsEl.innerHTML = state.tools.map(toolRow).join("");
}
function renderChecks() {
if (!state)
return;
if (checksEl)
checksEl.innerHTML = state.checks.map(checkRow).join("");
if (checkCount) {
const passed = state.checks.filter((check) => check.pass).length;
checkCount.textContent = `${passed}/${state.checks.length} 通过`;
}
if (score) {
score.textContent = `${state.score} / 100`;
score.className = `pill ${state.score === 100 ? "ok-pill" : "bad-pill"}`;
}
}
function renderEvents() {
if (!eventsEl || !state)
return;
eventsEl.innerHTML =
state.events.length === 0
? `暂无活动`
: state.events
.slice(0, 8)
.map((row) => `
${time(row.at)}
${escapeHtml(row.kind)}
${escapeHtml(row.detail)}
`)
.join("");
}
function render(next) {
state = next;
renderLayers();
renderMeasures();
renderTools();
renderChecks();
renderEvents();
}
void window.api.packaging.snapshot().then(render);
window.api.packaging.onEvent(() => {
void window.api.packaging.snapshot().then(render);
});
root
.querySelector('[data-testid="refresh"]')
?.addEventListener("click", async () => {
render(await window.api.packaging.refresh());
});
window.__prepareShots = async (stage) => {
document.body.dataset.shot = stage;
render(await window.api.packaging.refresh());
if (stage === "macos") {
document
.querySelector(".measure-card")
?.scrollIntoView({ block: "start" });
}
else if (stage === "tools") {
document.querySelector(".tools-card")?.scrollIntoView({ block: "start" });
}
else {
document
.querySelector(".layers-card")
?.scrollIntoView({ block: "start" });
}
};
window.__demo = async () => {
const next = await window.api.packaging.snapshot();
state = next;
return {
score: next.score,
checks: next.checks.length,
passed: next.checks.filter((check) => check.pass).length,
layers: next.layers.length,
artifacts: next.artifacts.length,
macRows: next.artifacts.filter((row) => row.platform === "macOS").length,
updateRows: next.artifacts.filter((row) => row.updateSource).length,
appBytes: next.measurements.appBytes,
asarBytes: next.measurements.asarBytes,
zipBytes: next.measurements.zipBytes,
dmgBytes: next.measurements.dmgBytes,
arch: next.measurements.arch,
tools: next.tools.length,
};
};
}
//# sourceMappingURL=App.js.map