ci: a UI preview's close-up keeps what's around the thing it shows (at least 560×340) and no screenshot is stretched past its own size in the PR — the first real run (#289) cropped a hover to the button alone, 100×68, then showed it 760 wide. Checked on #289 with workflow_dispatch.
This commit is contained in:
@@ -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 += `<img src="${raw}${x.file}" width="760" alt="${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 += `<img src="${raw}${x.file}" width="${Math.min(760, Math.round((x.width || 1520) / 2))}" alt="${esc(x.caption)}">\n\n${x.caption}\n\n`;
|
||||
}
|
||||
if (m.errors?.length) md += `<details><summary>⚠️ 有 ${m.errors.length} 步没能照计划执行</summary>\n\n${m.errors.map((e) => "- " + e).join("\n")}\n</details>\n`;
|
||||
await setBlock(md);
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user