import { readFile } from 'node:fs/promises'; import path from 'node:path'; /** * The 1-bit wordmark, inlined as a data URI. * * Read from the committed `public/brand/logo-eink.png` and embedded in the * SVG rather than linked: the renderer must not depend on the network, and an * image the rasteriser silently failed to fetch would leave a hole in the shop * window. Regenerate the file with `npm run brand`. * * Its dimensions are read from the file rather than kept as constants beside * it. The letter-spacing of the wordmark is adjustable, and every adjustment * changes the height — a number copied here would drift and squash the logo * without anything failing. */ export type Logo = { dataUri: string; width: number; height: number }; let cached: Logo | null | undefined; export async function loadLogo(): Promise { if (cached !== undefined) { return cached; } try { const file = path.join(process.cwd(), 'public', 'brand', 'logo-eink.png'); const bytes = await readFile(file); cached = { dataUri: `data:image/png;base64,${bytes.toString('base64')}`, ...readPngSize(bytes), }; } catch { // Not fatal: the header falls back to the shop name from the settings, // which is plainer but still a working screen. cached = null; } return cached; } /** A PNG states its size in the IHDR chunk, at a fixed offset. */ export function readPngSize(bytes: Buffer): { width: number; height: number } { return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) }; }