Branchwell

PulseCanvas / app · pulsecanvas.ai / assets / app-store / mobile-marketing-1.1.5 / render-header.mjs

1// Renders the search-results image and the looping header animation.
2// Usage: PLAYWRIGHT=/path/to/playwright/index.mjs node render-header.mjs [stills|video] [header|header-dark]
3import { fileURLToPath, pathToFileURL } from 'node:url';
4import { dirname, join } from 'node:path';
5import { mkdirSync, rmSync } from 'node:fs';
6import { execFileSync } from 'node:child_process';
7
8const { chromium } = await import(process.env.PLAYWRIGHT ?? 'playwright');
9const here = dirname(fileURLToPath(import.meta.url));
10const mode = process.argv[2] ?? 'stills';
11const variant = process.argv[3] ?? 'header'; // header (light) or header-dark
12const suffix = variant === 'header' ? '' : '-' + variant.replace('header-', '');
13const fps = 30, loop = 12;
14const out = join(here, 'release', 'en-US');
15mkdirSync(out, { recursive: true });
16const browser = await chromium.launch();
17
18const search = await browser.newPage({ viewport: { width: 3840, height: 2560 } });
19await search.goto(pathToFileURL(join(here, 'search.html')).href);
20await search.evaluate(() => Promise.all([...document.images].map(i => i.decode())));
21await search.screenshot({ path: join(out, 'search-results-3840x2560.png') });
22
23const page = await browser.newPage({ viewport: { width: 3840, height: 1646 } });
24await page.goto(pathToFileURL(join(here, variant + '.html')).href + `?loop=${loop}`);
25await page.evaluate(() => Promise.all([...document.images].map(i => i.decode())));
26if (mode === 'stills') {
27 for (const t of [0, 4, 8]) { await page.evaluate(t => render(t), t); await page.screenshot({ path: join(here, `${variant}-t${t}.png`) }); }
28} else {
29 const frames = join(here, '.header-frames');
30 rmSync(frames, { recursive: true, force: true }); mkdirSync(frames, { recursive: true });
31 for (let i = 0; i < fps * loop; i++) {
32 await page.evaluate(t => render(t), i / fps);
33 await page.screenshot({ path: join(frames, String(i).padStart(4, '0') + '.png') });
34 }
35 execFileSync('ffmpeg', ['-v', 'error', '-y', '-framerate', String(fps), '-i', join(frames, '%04d.png'), '-c:v', 'libx264', '-profile:v', 'high', '-crf', '14', '-preset', 'slow', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-an', join(out, `header-animated${suffix}-3840x1646.mp4`)]);
36 rmSync(frames, { recursive: true, force: true });
37}
38await browser.close();