From 3a193423b6fa3babbaa9e46fa2ce7894fa59cb72 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 30 Sep 2026 14:27:19 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20a=20UI=20preview's=20close-up=20keeps=20w?= =?UTF-8?q?hat's=20around=20the=20thing=20it=20shows=20(at=20least=20560?= =?UTF-8?q?=C3=97340)=20and=20no=20screenshot=20is=20stretched=20past=20it?= =?UTF-8?q?s=20own=20size=20in=20the=20PR=20=E2=80=94=20the=20first=20real?= =?UTF-8?q?=20run=20(#289)=20cropped=20a=20hover=20to=20the=20button=20alo?= =?UTF-8?q?ne,=20100=C3=9768,=20then=20showed=20it=20760=20wide.=20Checked?= =?UTF-8?q?=20on=20#289=20with=20workflow=5Fdispatch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ui-preview/publish.mjs | 3 ++- .github/ui-preview/record.mjs | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/ui-preview/publish.mjs b/.github/ui-preview/publish.mjs index afbfce8f7..deb1f15ec 100644 --- a/.github/ui-preview/publish.mjs +++ b/.github/ui-preview/publish.mjs @@ -174,7 +174,8 @@ async function publish() { for (const s of m.scenes) { if (!s.shots.length) continue; md += `#### ${s.title}\n\n`; - for (const x of s.shots) md += `${esc(x.caption)}\n\n${x.caption}\n\n`; + // shown at its own size (they're taken at 2x), a full page no wider than 760 + for (const x of s.shots) md += `${esc(x.caption)}\n\n${x.caption}\n\n`; } if (m.errors?.length) md += `
⚠️ 有 ${m.errors.length} 步没能照计划执行\n\n${m.errors.map((e) => "- " + e).join("\n")}\n
\n`; await setBlock(md); diff --git a/.github/ui-preview/record.mjs b/.github/ui-preview/record.mjs index 12be22426..38616e825 100644 --- a/.github/ui-preview/record.mjs +++ b/.github/ui-preview/record.mjs @@ -230,16 +230,19 @@ async function runStep(page, step, scene) { if (step.target) { const b = await (await locate(page, step)).boundingBox(); if (b) { - const m = 24; - const x = Math.max(0, b.x - m), y = Math.max(0, b.y - m); - clip = { x, y, width: Math.min(VIEW.width - x, b.width + 2 * m), height: Math.min(VIEW.height - y, b.height + 2 * m) }; + // the target with room around it, never so small that a button + // is shown without where it is + const w = Math.min(VIEW.width, Math.max(560, b.width + 48)), h = Math.min(VIEW.height, Math.max(340, b.height + 48)); + const x = Math.min(VIEW.width - w, Math.max(0, b.x + b.width / 2 - w / 2)); + const y = Math.min(VIEW.height - h, Math.max(0, b.y + b.height / 2 - h / 2)); + clip = { x, y, width: w, height: h }; } } await page.screenshot({ path: path.join(OUT, file), clip }); } finally { await page.evaluate(() => document.querySelector("[data-ui-preview]")?.style.removeProperty("visibility")); } - scene.shots.push({ file, caption: step.caption || step.name || "" }); + scene.shots.push({ file, caption: step.caption || step.name || "", width: 2 * (clip?.width ?? VIEW.width) }); break; } default: