diff --git a/docs/screenshots/en/arrange.webp b/docs/screenshots/en/arrange.webp new file mode 100644 index 00000000..0feae087 Binary files /dev/null and b/docs/screenshots/en/arrange.webp differ diff --git a/docs/screenshots/en/connections-list.webp b/docs/screenshots/en/connections-list.webp new file mode 100644 index 00000000..1cf42aa8 Binary files /dev/null and b/docs/screenshots/en/connections-list.webp differ diff --git a/docs/screenshots/en/connections-traffic.webp b/docs/screenshots/en/connections-traffic.webp new file mode 100644 index 00000000..c15751ad Binary files /dev/null and b/docs/screenshots/en/connections-traffic.webp differ diff --git a/docs/screenshots/en/dns.webp b/docs/screenshots/en/dns.webp new file mode 100644 index 00000000..84d10d3f Binary files /dev/null and b/docs/screenshots/en/dns.webp differ diff --git a/docs/screenshots/en/latency.webp b/docs/screenshots/en/latency.webp new file mode 100644 index 00000000..b54ecbe3 Binary files /dev/null and b/docs/screenshots/en/latency.webp differ diff --git a/docs/screenshots/en/logs.webp b/docs/screenshots/en/logs.webp new file mode 100644 index 00000000..a564ec8d Binary files /dev/null and b/docs/screenshots/en/logs.webp differ diff --git a/docs/screenshots/en/phone.webp b/docs/screenshots/en/phone.webp new file mode 100644 index 00000000..55afc508 Binary files /dev/null and b/docs/screenshots/en/phone.webp differ diff --git a/docs/screenshots/en/routing.webp b/docs/screenshots/en/routing.webp new file mode 100644 index 00000000..1314f5a5 Binary files /dev/null and b/docs/screenshots/en/routing.webp differ diff --git a/docs/screenshots/zh-CN/arrange.webp b/docs/screenshots/zh-CN/arrange.webp new file mode 100644 index 00000000..ea6641e2 Binary files /dev/null and b/docs/screenshots/zh-CN/arrange.webp differ diff --git a/docs/screenshots/zh-CN/connections-list.webp b/docs/screenshots/zh-CN/connections-list.webp new file mode 100644 index 00000000..84dee586 Binary files /dev/null and b/docs/screenshots/zh-CN/connections-list.webp differ diff --git a/docs/screenshots/zh-CN/connections-traffic.webp b/docs/screenshots/zh-CN/connections-traffic.webp new file mode 100644 index 00000000..05a0f9bc Binary files /dev/null and b/docs/screenshots/zh-CN/connections-traffic.webp differ diff --git a/docs/screenshots/zh-CN/dns.webp b/docs/screenshots/zh-CN/dns.webp new file mode 100644 index 00000000..70ffea5f Binary files /dev/null and b/docs/screenshots/zh-CN/dns.webp differ diff --git a/docs/screenshots/zh-CN/latency.webp b/docs/screenshots/zh-CN/latency.webp new file mode 100644 index 00000000..9d8c45f9 Binary files /dev/null and b/docs/screenshots/zh-CN/latency.webp differ diff --git a/docs/screenshots/zh-CN/logs.webp b/docs/screenshots/zh-CN/logs.webp new file mode 100644 index 00000000..ae2f588e Binary files /dev/null and b/docs/screenshots/zh-CN/logs.webp differ diff --git a/docs/screenshots/zh-CN/phone.webp b/docs/screenshots/zh-CN/phone.webp new file mode 100644 index 00000000..96142999 Binary files /dev/null and b/docs/screenshots/zh-CN/phone.webp differ diff --git a/docs/screenshots/zh-CN/routing.webp b/docs/screenshots/zh-CN/routing.webp new file mode 100644 index 00000000..4fc29a32 Binary files /dev/null and b/docs/screenshots/zh-CN/routing.webp differ diff --git a/docs/screenshots/zh-TW/arrange.webp b/docs/screenshots/zh-TW/arrange.webp new file mode 100644 index 00000000..b8ddc156 Binary files /dev/null and b/docs/screenshots/zh-TW/arrange.webp differ diff --git a/docs/screenshots/zh-TW/connections-list.webp b/docs/screenshots/zh-TW/connections-list.webp new file mode 100644 index 00000000..d0fb7c93 Binary files /dev/null and b/docs/screenshots/zh-TW/connections-list.webp differ diff --git a/docs/screenshots/zh-TW/connections-traffic.webp b/docs/screenshots/zh-TW/connections-traffic.webp new file mode 100644 index 00000000..9065477f Binary files /dev/null and b/docs/screenshots/zh-TW/connections-traffic.webp differ diff --git a/docs/screenshots/zh-TW/dns.webp b/docs/screenshots/zh-TW/dns.webp new file mode 100644 index 00000000..7dd659c6 Binary files /dev/null and b/docs/screenshots/zh-TW/dns.webp differ diff --git a/docs/screenshots/zh-TW/latency.webp b/docs/screenshots/zh-TW/latency.webp new file mode 100644 index 00000000..ff062935 Binary files /dev/null and b/docs/screenshots/zh-TW/latency.webp differ diff --git a/docs/screenshots/zh-TW/logs.webp b/docs/screenshots/zh-TW/logs.webp new file mode 100644 index 00000000..beb3cc02 Binary files /dev/null and b/docs/screenshots/zh-TW/logs.webp differ diff --git a/docs/screenshots/zh-TW/phone.webp b/docs/screenshots/zh-TW/phone.webp new file mode 100644 index 00000000..dc415534 Binary files /dev/null and b/docs/screenshots/zh-TW/phone.webp differ diff --git a/docs/screenshots/zh-TW/routing.webp b/docs/screenshots/zh-TW/routing.webp new file mode 100644 index 00000000..9d073bba Binary files /dev/null and b/docs/screenshots/zh-TW/routing.webp differ diff --git a/tools/screenshots.mjs b/tools/screenshots.mjs index 7e3c2e88..96e4f417 100644 --- a/tools/screenshots.mjs +++ b/tools/screenshots.mjs @@ -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 = + '' + + ''; + 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(`
${shots.map(png => ``).join('')}
`); + 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();