Files
piik/scripts/update-guide-images.mjs
T
AAA f730e84bc8 fix(ui): keep room controls usable through layout changes
The shared room sweep fixes narrow stage sizing, caption overlap, covered chat reads, phone history, focus restoration, settings error placement and row alignment at their existing owners. Room and Network settings share one draft and save action. The two shell stylesheets are consolidated; hidden current-room links and obsolete grid rules are removed. The handbook, matching guides and four generated room screenshots follow the shared components.

Chrome 156 interaction checks covered both themes, 320px phones, short windows, classic scrollbars, native-caption simulation, eight retained players, nested Back/Escape and room-tool popout. Full Web validation passed 2485 cases and exposed one assertion on removed hidden local-preview text; the preview identity now lives in the player accessible label and all 15 affected playback/layout checks pass. TypeScript and Browser SDK types pass. Actual WebView caption dragging and physical mobile capture are outside this browser check.
2026-11-26 18:57:48 -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', 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-lead button[aria-expanded="false"]');
await run('click', '#c3-people-trigger');
await capture('.c3-room-preview', `channel-room.${suffix}`);
await run('set', 'viewport', '1280', '900');
}
}
}
} finally {
await run('close');
}