/** * Write a standalone page to tune the source strip live: pick an example, drag the module size * and opacity, and see the band at real size with a decode check after JPEG or WebP. * * node scripts/strip-preview.ts [--out tmp/strip-preview/index.html] */ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import { stripTypeScriptTypes } from 'node:module'; import path from 'node:path'; const root = path.resolve(import.meta.dirname, '..'); const args = process.argv.slice(2); const out = args.includes('--out') ? args[args.indexOf('--out') + 1] : 'tmp/strip-preview/index.html'; const names = fs .readdirSync(path.join(root, 'examples')) .filter(f => f.endsWith('.draft')) .sort(); const examples = names.map(f => ({ name: f.replace('.draft', ''), source: fs.readFileSync(path.join(root, 'examples', f), 'utf8'), svg: execFileSync( process.execPath, [path.join(root, 'scripts/draftably.mjs'), 'inspect', path.join('examples', f), '--svg'], { encoding: 'utf8', maxBuffer: 1 << 26 }, ), })); const strip = stripTypeScriptTypes( fs.readFileSync(path.join(root, 'src/model/strip.ts'), 'utf8'), ).replace(/^export /gm, ''); const html = ` Source strip preview
`; fs.mkdirSync(path.dirname(out), { recursive: true }); fs.writeFileSync(out, html); console.log(path.resolve(out), (html.length / 1e6).toFixed(1) + ' MB');