Files
MichilisandClaude Opus 5.5 f09445b6ad
ci / check (push) Canceled after 0s
ci / images (push) Canceled after 0s
ci / e2e (push) Canceled after 0s
Initial commit
Paper Sats: design and print paper notes that carry sats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 05:15:30 +00:00

51 lines
2.1 KiB
JavaScript

/**
* Renders the hero notes to public/hero/*.webp from /ui-kit/hero-source, drawn by the app's own
* note renderer with sample values. Run against a running server after a template changes:
* node apps/web/scripts/render-hero.mjs http://localhost:3300
*/
/* global document, Image */
import { chromium } from '@playwright/test';
import { mkdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const base = process.argv[2] ?? 'http://localhost:3300';
const out = path.join(path.dirname(fileURLToPath(import.meta.url)), '../public/hero');
mkdirSync(out, { recursive: true });
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1400, height: 1000 } });
await page.goto(`${base}/ui-kit/hero-source`, { waitUntil: 'load', timeout: 120_000 });
await page.evaluate(() => document.fonts.ready);
await page.waitForTimeout(1500);
// Each note at full width, plus a smaller file phones can pick through srcset.
for (const [name, source, scale] of [
['classic', 'classic', 1],
['classic-600', 'classic', 0.6],
['vertical', 'vertical', 1],
['vertical-240', 'vertical', 0.6],
['coupon', 'coupon', 1],
['coupon-336', 'coupon', 0.6],
]) {
const png = await page
.locator(`[data-hero="${source}"] svg`)
.screenshot({ type: 'png', omitBackground: true });
// Encoded by the browser so no image library is needed. WebP keeps the rounded corners transparent.
const dataUrl = await page.evaluate(
async ([b64, k]) => {
const img = new Image();
img.src = `data:image/png;base64,${b64}`;
await img.decode();
const canvas = document.createElement('canvas');
canvas.width = Math.round(img.naturalWidth * k);
canvas.height = Math.round(img.naturalHeight * k);
canvas.getContext('2d').drawImage(img, 0, 0, canvas.width, canvas.height);
return canvas.toDataURL('image/webp', 0.85);
},
[png.toString('base64'), scale],
);
const bytes = Buffer.from(dataUrl.split(',')[1], 'base64');
writeFileSync(path.join(out, `${name}.webp`), bytes);
console.log(name, Math.round(bytes.length / 1024), 'KB');
}
await browser.close();