Files
piik/scripts/update-guide-images.mjs
T
AAA 77c45c613b refactor(ui): replace the old layouts with one living room shell
Full and minimal are two forms of the same room, with shared players, conversation and voice lifetimes. The room list now discloses room membership; the couch owns current-room interaction and the people panel keeps the site-wide directory. Retire the old workspace and quick branches and their private preference values without aliases.

Keep remote-input state mounted when its picture is hidden and expose requests directly on narrow cards. Preserve the common menu in the rail, relocate the voice-name style to its surviving owner, and regenerate guide screenshots from the production room view. Real room voice/draft controls, responsive media-node checks, types and the full Rust/Web/protocol gate pass. Existing Git-heavy Web fixtures pass when rerun serially after parallel timeout.
2026-11-26 11:14:03 -05:00

122 lines
6.6 KiB
JavaScript

import { spawn } from 'node:child_process';
import { mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
// 3.0 guide images have one source: production components in the dev catalogue.
// The maintenance branch owns its 2.x screenshots and README film stills.
const { values, positionals } = parseArgs({ allowPositionals: true, options: { only: { type: 'string' } } });
const scenes = new Set((values.only ?? 'room,invitation,source,quality').split(','));
if (positionals.length > 1 || [...scenes].some(scene => !['room', 'invitation', 'source', 'quality'].includes(scene)))
throw new Error('Usage: node scripts/update-guide-images.mjs [dev-origin] [--only room,invitation,source,quality]');
const preview = new URL('/__tooltip-preview', positionals[0] || 'http://127.0.0.1:8787');
const roomPreview = new URL('?channel-room&image', preview);
const output = fileURLToPath(new URL('../docs/assets/guide/', import.meta.url));
const browser = process.env.AGENT_BROWSER_PATH || (process.platform === 'win32'
? join(process.env.APPDATA, 'npm/node_modules/agent-browser/bin/agent-browser-win32-x64.exe')
: 'agent-browser');
const session = `piik-guide-images-${process.pid}`;
async function execute(command, args, timeout = 30000) {
const child = spawn(command, args, { windowsHide: true, timeout, stdio: ['ignore', 'pipe', 'pipe'] });
let stdout = '', stderr = '';
child.stdout.on('data', bytes => { stdout += bytes; });
child.stderr.on('data', bytes => { stderr += bytes; });
const code = await new Promise((resolve, reject) => { child.once('error', reject); child.once('exit', resolve); });
// A newly launched browser daemon can inherit these pipes after its CLI exits.
child.stdout.destroy(); child.stderr.destroy();
if (code !== 0) throw new Error(stderr || stdout || `${command} exited with ${code}`);
return stdout;
}
const run = async (...args) => {
const result = JSON.parse(await execute(browser, ['--session', session, '--json', ...args]));
if (!result.success) throw new Error(result.error);
return result.data;
};
const evaluate = script => run('eval', '-b', Buffer.from(script).toString('base64'));
async function capture(selector, name) {
await run('wait', selector);
await run('mouse', 'move', '1', '1');
await evaluate(`(async () => {
const target = document.querySelector(${JSON.stringify(selector)});
await document.fonts.ready;
await Promise.all(Array.from(target.querySelectorAll('img')).map(img => img.decode()));
await Promise.all(target.getAnimations({ subtree: true })
.filter(animation => animation.effect?.getComputedTiming().iterations !== Infinity)
.map(animation => animation.finished.catch(() => {})));
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
})()`);
const isolation = selector === '.c3-room-preview' ? null : (await evaluate(`(() => {
const guide = document.querySelector('#channel-guide-preview');
const target = document.querySelector(${JSON.stringify(selector)});
const previous = [guide, target].map(node => [node.style.getPropertyValue('visibility'), node.style.getPropertyPriority('visibility')]);
guide.style.visibility = 'hidden'; target.style.visibility = 'visible';
return previous;
})()`)).result;
try {
await run('screenshot', selector, join(output, `${name}.png`));
} finally {
if (isolation) await evaluate(`(() => {
const nodes = [document.querySelector('#channel-guide-preview'), document.querySelector(${JSON.stringify(selector)})];
${JSON.stringify(isolation)}.forEach(([value, priority], index) => nodes[index]?.style.setProperty('visibility', value, priority));
})()`);
}
console.log(`${name}.png`);
}
if (!values.only) await execute(process.execPath, [fileURLToPath(import.meta.resolve('tsx/cli')), '--tsconfig',
fileURLToPath(new URL('./tsconfig.json', import.meta.url)),
fileURLToPath(new URL('./update-guide-diagrams.tsx', import.meta.url))]);
await mkdir(output, { recursive: true });
try {
await run('set', 'viewport', '1280', '900');
for (const theme of ['light', 'dark']) {
await run('set', 'media', theme, 'reduced-motion');
for (const [lang, locale] of [['en', 'en'], ['zh', 'zh-CN']]) {
await run('open', preview.href);
await run('wait', '#channel-guide-preview');
await evaluate(`localStorage.setItem("piik:ui-lang", ${JSON.stringify(lang)})`);
await run('reload');
await run('wait', '#channel-guide-preview');
if ((await evaluate('document.documentElement.dataset.theme')).result !== theme)
await run('click', '.lr-top .lr-theme-toggle');
await run('wait', '--fn', `document.querySelector('.c3-guide-title strong')?.textContent === ${JSON.stringify(lang === 'en' ? 'Friday with friends' : '周五小聚')}`);
await evaluate(`(() => {
const style = document.createElement('style');
style.textContent = '.lr-top, .lr-tooltip-preview > :not(#channel-guide-preview), #channel-guide-preview > :not(.c3-guide-room) { display:none !important }';
document.head.append(style); scrollTo(0, 0);
})()`);
const suffix = `${locale}${theme === 'dark' ? '.dark' : ''}`;
if (scenes.has('invitation')) {
await run('click', '.c3-guide-title .c3-room-invitation-entry button');
await run('wait', '.c3-room-invitation:popover-open .c3-invitation-link input');
await capture('.c3-room-invitation:popover-open', `channel-invitation.${suffix}`);
await run('press', 'Escape');
}
if (scenes.has('source')) {
await run('find', 'role', 'button', 'click', '--name', lang === 'en' ? 'Start sharing' : '开始分享', '--exact');
await run('wait', '.c3-share-picker .lr-source-picker-list img');
await capture('.c3-share-picker:popover-open', `channel-source.${suffix}`);
await run('press', 'Escape');
}
if (scenes.has('quality')) {
await run('find', 'role', 'button', 'click', '--name', lang === 'en' ? 'Share settings' : '分享设置', '--exact');
await capture('.c3-quality-picker:popover-open', `channel-quality.${suffix}`);
}
if (scenes.has('room')) {
await run('set', 'viewport', '1280', '760');
await run('open', roomPreview.href);
await run('wait', '.c3-room-preview .c3-voice-dock-rooms');
await run('click', '.c3-room-item[data-selected] .c3-room-voice-toggle button');
await run('click', '#c3-people-trigger');
await capture('.c3-room-preview', `channel-room.${suffix}`);
await run('set', 'viewport', '1280', '900');
}
}
}
} finally {
await run('close');
}