A lightweight design agent built with libfx. Describe a page and an agent writes it as one HTML file.
TypeScript
// Regenerates lib/vendor/fast-html-to-image.ts from a vercel-labs/fast-snap checkout, whose
// vendor/fast-html-to-image/ holds the patched fork (MIT):
// node scripts/vendor-fast-html-to-image.mjs ../fast-snap
// The bundle is inlined into a <script> in every design preview, so it must not
// contain text that would end that script or open a comment there.
import { execFileSync } from 'node:child_process'
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { join, resolve } from 'node:path'
const snap = resolve(process.argv[2] ?? '../fast-snap')
const fork = join(snap, 'vendor/fast-html-to-image')
const bundle = execFileSync(join(snap, 'node_modules/.bin/esbuild'), [
join(fork, 'src/index.js'), '--bundle', '--minify', '--format=iife', '--global-name=FastHtmlToImage', '--log-level=warning',
], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }).trim()
if (/<\/script|<!--/i.test(bundle)) throw new Error('bundle contains text that would break an inline <script>')
const commit = execFileSync('git', ['-C', snap, 'rev-parse', '--short', 'HEAD'], { encoding: 'utf8' }).trim()
const license = readFileSync(join(fork, 'LICENSE'), 'utf8').trim().split('\n').map((line) => `// ${line}`.trimEnd()).join('\n')
const out = new URL('../lib/vendor/fast-html-to-image.ts', import.meta.url)
mkdirSync(new URL('./', out), { recursive: true })
writeFileSync(out, `// Generated by scripts/vendor-fast-html-to-image.mjs from fast-snap ${commit}. Do not edit.
// fast-html-to-image (patched fork), browser IIFE exposing the global FastHtmlToImage.
//
${license}
export const FAST_HTML_TO_IMAGE = ${JSON.stringify(bundle)}
`)
console.log(`wrote lib/vendor/fast-html-to-image.ts (${bundle.length} bytes, fast-snap ${commit})`)