#!/usr/bin/env node // From AI & Things (https://aiandthings-film-method.vercel.app). Installed into a film by checks/add-ink-check.mjs. // Ink check: renders the film with the ink audit on (src/kit/inkaudit.tsx) and lists every text whose letters a box cuts // (an overflow/clip/mask box, or the frame) while its line fits inside that box: Arabic marks and tails, descenders, // accents. Exit code 1 when anything is cut, so it gates the final like `check`. // // node scripts/ink.mjs [--film main] [--range 0-599] // // What it does not catch: a line that is itself taller than its clipping box (a tight line-height on a clipping box). // It treats that as text passing through a mask and stays silent. So never set a tight line-height on a box that clips. import { spawn } from 'node:child_process'; import fs from 'node:fs'; const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; }; const film = arg('film', 'main'); const range = arg('range'); fs.mkdirSync('out', { recursive: true }); const args = ['remotion', 'render', 'src/index.ts', film, `out/ink-${film}.mp4`, '--props', JSON.stringify({ inkAudit: true }), '--scale', '0.25', '--muted', '--log', 'verbose']; if (range) args.push('--frames', range); if (process.env.CINETIC_GL) args.push('--gl', process.env.CINETIC_GL); const cuts = new Map(); const take = (buf) => { for (const line of buf.toString().split('\n')) { const i = line.indexOf('INKCUT '); if (i < 0) continue; try { const c = JSON.parse(line.slice(i + 7).trim()); const key = `${c.text}|${c.side}|${c.by}`; const e = cuts.get(key) ?? { ...c, frames: new Set(), max: 0 }; e.frames.add(c.f); e.max = Math.max(e.max, c.px); cuts.set(key, e); } catch {} } }; const p = spawn('npx', args, { stdio: ['ignore', 'pipe', 'pipe'] }); p.stdout.on('data', take); p.stderr.on('data', take); p.on('close', (code) => { if (code !== 0) { console.error(`ink: the render failed (exit ${code})`); process.exit(2); } const ranges = (set) => { const a = [...set].sort((x, y) => x - y); const r = []; for (const f of a) { const last = r[r.length - 1]; if (last && f === last[1] + 1) last[1] = f; else r.push([f, f]); } return r.map(([s, e]) => (s === e ? `${s}` : `${s}-${e}`)).join(', '); }; if (!cuts.size) { console.log(`ink: ${film} | no letter cut on any frame`); return; } console.log(`ink: ${film} | ${cuts.size} cut text(s): FIX every one (give the box room for the ink: 1 em above the line, 0.65 em below; see guides/arabic-type.md)`); for (const c of [...cuts.values()].sort((a, b) => Math.min(...a.frames) - Math.min(...b.frames))) console.log(` "${c.text}" ${c.side} cut up to ${c.max} px by <${c.by}> frames ${ranges(c.frames)}`); process.exit(1); });