docs(screenshots): add the page tour, phone strip and animations

tools/screenshots.mjs now also captures, per language, five page tour
stills cropped to the content panel, a strip of three phones at 390x844,
and two animated WebP files (arranging a node into a group, selecting a
path on the routing map) built with img2webp. A fixed clock keeps the
mock timestamps stable. The activity pages waited for recharts sectors,
which no longer exist; they now wait for the donut's paths.
This commit is contained in:
Zakk committed 2026-09-26 05:25:30 +10:00
1 parent 34d362ef59
commit d4fafe80e5
25 files changed
+201 -4

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

+201 -4
View File
@@ -1,8 +1,10 @@
// Usage: node tools/screenshots.mjs [URL] [DIR]; captures README pages in each language plus light/dark activity views.
// Also builds a palette sheet and English theme gallery from mock-backed screenshots.
// Also builds a palette sheet, the English theme gallery, and per language the phone strip, the page tour stills and
// its two animations (cwebp and img2webp), all from mock-backed screenshots.
import {execFileSync} from 'node:child_process';
import {mkdirSync} from 'node:fs';
import {mkdirSync, mkdtempSync, rmSync, writeFileSync} from 'node:fs';
import {createRequire} from 'node:module';
import {tmpdir} from 'node:os';
import {dirname, join} from 'node:path';
const require = createRequire(import.meta.url);
@@ -53,11 +55,198 @@ const gallery = new Map([
['Glass Light', 'glass-light'],
['Glass Dark', 'glass-dark']
]);
// The page tour: the content panel without the side navigation, from its top down to the bottom of `until`.
const tour = [
['connections-traffic', '#/connections', '.rp-scatter', '.rp-content section.rp-titled >> nth=0'],
['connections-list', '#/connections?tab=list', '.rp-table [role=row] >> nth=4', '.rp-content .rp-table'],
['dns', '#/dns', '.rp-waffle', '.rp-content section.rp-titled >> nth=0'],
['logs', '#/logs', '.rp-heatmap', '.rp-content section.rp-titled'],
['latency', '#/nodes?tab=latency', '.rp-markerplot', '.rp-content section.rp-titled']
];
// Mock timestamps derive from the clock; a fixed one keeps the tour and phone images the same from run to run.
const fixedTime = new Date('2026-09-01T09:30:00Z');
execFileSync('cwebp', ['-version'], {stdio: 'ignore'});
execFileSync('img2webp', ['-version'], {stdio: 'ignore'});
async function screenshot(page, path, options = {}, lossy = false) {
const png = await page.screenshot(options);
execFileSync('cwebp', ['-quiet', ...(lossy ? ['-q', '78'] : ['-lossless', '-z', '9']), '-o', path + '.webp', '--', '-'], {input: png});
}
async function openPage(browser, lang, route, ready, options = {}) {
const context = await browser.newContext({
viewport: {width: 1280, height: 900},
colorScheme: 'light',
reducedMotion: 'reduce',
serviceWorkers: 'block',
timezoneId: 'UTC',
...options
});
await context.clock.setFixedTime(fixedTime);
await context.addInitScript(lang => {
localStorage.setItem('doona-api', 'mock');
localStorage.setItem('doona-lang', lang);
localStorage.setItem('doona-scheme', 'light');
localStorage.setItem('doona-palette', 'rose-pine/moon');
}, lang);
const page = await context.newPage();
await page.goto(`${baseURL}/${route}`);
await page.locator(ready).first().waitFor();
await page.waitForFunction(() => !document.querySelector('.rp-content .rp-empty[role=status]'));
await page.evaluate(() => document.fonts.ready);
return page;
}
// The content panel from its top edge to 12px below the element `until`.
async function panelClip(page, until) {
const panel = await page.locator('.rp-main').boundingBox();
const end = await page.locator(until).boundingBox();
return {x: panel.x, y: panel.y, width: panel.width, height: Math.ceil(end.y + end.height + 12 - panel.y)};
}
async function center(locator) {
const box = await locator.boundingBox();
return {x: box.x + box.width / 2, y: box.y + box.height / 2};
}
// A drawn pointer, since screenshots leave out the system cursor and the browser's drag image; `label` shows a chip
// beside it for the item being dragged.
async function pointer(page, {x, y}, label = '') {
await page.evaluate(
([x, y, label]) => {
let el = document.getElementById('readme-pointer');
if (!el) {
el = document.createElement('div');
el.id = 'readme-pointer';
el.style.cssText = 'position:fixed;left:0;top:0;z-index:9999;pointer-events:none;display:flex;align-items:flex-start;gap:4px';
el.innerHTML =
'<svg width="20" height="24" viewBox="0 0 20 24"><path d="M2 2v17l4.5-4.2 3 6.7 3-1.4-3-6.6H16z" fill="#1f1d2e" stroke="#fff" stroke-width="1.6" stroke-linejoin="round"/></svg>' +
'<span style="margin-top:14px;padding:4px 10px;border-radius:6px;background:var(--rp-surface);border:1px solid var(--rp-hl-high);box-shadow:0 4px 12px rgba(0,0,0,.16);font-size:14px;color:var(--rp-text)"></span>';
document.body.append(el);
}
el.style.transform = `translate(${x - 2}px, ${y - 2}px)`;
const chip = el.querySelector('span');
chip.textContent = label;
chip.style.display = label ? '' : 'none';
},
[x, y, label]
);
}
// Frames for img2webp, each shown for its own duration.
function recorder(page, clip) {
const frames = [];
return {
async frame(ms) {
frames.push([await page.screenshot({clip}), ms]);
},
// Moves the real mouse, which drives hover and drag, and the drawn pointer with it in eased steps.
async glide(from, to, label = '', steps = 10) {
for (let i = 1; i <= steps; i++) {
const k = i / steps;
const e = k < 0.5 ? 2 * k * k : 1 - (-2 * k + 2) ** 2 / 2;
const at = {x: from.x + (to.x - from.x) * e, y: from.y + (to.y - from.y) * e};
await page.mouse.move(at.x, at.y);
await pointer(page, at, label);
await this.frame(40);
}
},
encode(path) {
const work = mkdtempSync(join(tmpdir(), 'doona-shots-'));
try {
const args = ['-loop', '0', '-min_size', '-lossless', '-q', '100', '-m', '6'];
frames.forEach(([png, ms], i) => {
writeFileSync(join(work, `${i}.png`), png);
args.push('-d', String(ms), join(work, `${i}.png`));
});
execFileSync('img2webp', [...args, '-o', path + '.webp'], {stdio: 'ignore'});
} finally {
rmSync(work, {recursive: true, force: true});
}
}
};
}
// Drags a node from the tray onto a group on the arrange tab. The viewport is tall enough that the bar for pending
// changes sits below the clip.
async function recordArrange(browser, lang, path) {
const page = await openPage(browser, lang, '#/policies?tab=arrange', '.rp-drop', {viewport: {width: 1280, height: 1100}});
const group = page.locator('.rp-drop').filter({has: page.getByRole('heading', {name: 'gaming', exact: true})});
const clip = await panelClip(page, '.rp-drop >> nth=-1');
const row = await page.getByRole('row').filter({hasText: 'us-01'}).boundingBox();
const handle = {x: row.x + 16, y: row.y + row.height / 2};
const anim = recorder(page, clip);
const start = {x: clip.x + clip.width - 120, y: clip.y + 160};
await page.mouse.move(start.x, start.y);
await pointer(page, start);
await anim.frame(900);
await anim.glide(start, handle);
await page.mouse.down();
await anim.frame(250);
await anim.glide(handle, await center(group), 'us-01', 16);
await anim.frame(700);
await page.mouse.up();
await pointer(page, await center(group));
await group.getByText('us-01').waitFor();
await anim.frame(2400);
anim.encode(path);
await page.context().close();
}
// Selects a rule, then a node, on the routing map, then clears the selection so the loop starts where it ends.
async function recordRouting(browser, lang, path) {
const page = await openPage(browser, lang, '#/rules?tab=map', '.rp-tree-tile');
const tile = (stage, text) => page.locator(`.rp-tree-tile[data-stage=${stage}]`).filter({hasText: text}).first();
const rule = tile('rule', 'fallback');
const node = tile('node', 'hk-01');
// A selection adds a row of path actions under the map; measure with it shown so no frame cuts it off.
await rule.click();
const clip = await panelClip(page, '.rp-tabpanel');
await rule.click();
const start = {x: clip.x + clip.width / 2, y: clip.y + 60};
await page.mouse.move(start.x, start.y);
await pointer(page, start);
const anim = recorder(page, clip);
await anim.frame(900);
let at = start;
for (const target of [rule, node]) {
const to = await center(target);
await anim.glide(at, to);
await page.mouse.click(to.x, to.y);
await anim.frame(1800);
at = to;
}
await page.mouse.click(at.x, at.y);
await anim.glide(at, start, '', 12);
await anim.frame(300);
anim.encode(path);
await page.context().close();
}
// Three phones side by side: a table page, the top bar's overflow menu, and its palette submenu.
async function recordPhones(browser, lang, path) {
const phone = {viewport: {width: 390, height: 844}, deviceScaleFactor: 2, isMobile: true, hasTouch: true};
const shots = [];
for (const [route, ready, submenu] of [
['#/connections?tab=list', '.rp-table [role=row] >> nth=4'],
['#/activity', '.rp-donut path', false],
['#/policies', '.rp-nodes', true]
]) {
const page = await openPage(browser, lang, route, ready, phone);
if (submenu !== undefined) {
await page.locator('header .rp-narrow-only button').click();
await page.getByRole('menuitem').first().waitFor();
if (submenu) {
await page.getByRole('menuitem').nth(2).click();
await page.getByRole('menuitemradio').first().waitFor();
}
await page.waitForTimeout(300);
}
shots.push(await page.screenshot());
await page.context().close();
}
const sheet = await browser.newPage({viewport: {width: 1234, height: 868}, deviceScaleFactor: 2});
await sheet.setContent(`<!doctype html><style>
body { margin: 0; padding: 12px; background: transparent; }
main { display: flex; gap: 20px; }
img { display: block; width: 390px; height: 844px; border-radius: 24px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.16); }
</style><main>${shots.map(png => `<img src="data:image/png;base64,${png.toString('base64')}">`).join('')}</main>`);
await sheet.waitForTimeout(500);
const png = await sheet.screenshot({omitBackground: true});
execFileSync('cwebp', ['-quiet', '-q', '84', '-alpha_q', '100', '-o', path + '.webp', '--', '-'], {input: png});
await sheet.close();
}
const browser = await chromium.launch();
try {
const tiles = [];
@@ -81,7 +270,7 @@ try {
);
const page = await context.newPage();
await page.goto(`${baseURL}/#/activity`);
await page.locator('.rp-donut .recharts-sector').first().waitFor();
await page.locator('.rp-donut path').first().waitFor();
await page.waitForFunction(() => !document.querySelector('.rp-content .rp-empty[role=status]'));
await page.evaluate(() => document.fonts.ready);
tiles.push(await page.screenshot());
@@ -116,7 +305,7 @@ try {
const page = await context.newPage();
await page.goto(`${baseURL}/${route}`);
await page
.locator(name === 'policies' ? '.rp-nodes' : name === 'rules' ? '.rp-tree-tile' : '.rp-donut .recharts-sector')
.locator(name === 'policies' ? '.rp-nodes' : name === 'rules' ? '.rp-tree-tile' : '.rp-donut path')
.first()
.waitFor();
await page.waitForFunction(() => !document.querySelector('.rp-content .rp-empty[role=status]'));
@@ -124,6 +313,14 @@ try {
await screenshot(page, join(dir, lang, `${name}-${scheme}`));
await context.close();
}
for (const [name, route, ready, until] of tour) {
const page = await openPage(browser, lang, route, ready);
await screenshot(page, join(dir, lang, name), {clip: await panelClip(page, until), fullPage: true});
await page.context().close();
}
await recordPhones(browser, lang, join(dir, lang, 'phone'));
await recordArrange(browser, lang, join(dir, lang, 'arrange'));
await recordRouting(browser, lang, join(dir, lang, 'routing'));
}
} finally {
await browser.close();