- Added `6x12-dim`, `8x13-bw`, `8on16-bw`, `doc-8on16-bw`, `doc-8on16-sent`, and `doc-8on16-sent-dim` to `SHAPE_VARIANTS`, backed by new `Shape` fields `stretch`, `columns`, and `stopwordDim` and the X.org `6x12`/`8x13` fonts. - Added `dimStopwords()` (high-frequency function words printed in dim ink via zero-width markers, skipping already-dim spans) and `wrap()`, the greedy word-wrap used to typeset doc-layout pages; `geometry`/`render`/`renderMany`/`frames`/`compact` paginate doc shapes into `2 * rows`-line pages and persist `columns`/`stopwordDim` on compaction frames for mixed-shape detection. - Changed `normalize()` to keep line structure (whitespace runs containing a line break collapse to `NEWLINE_GLYPH`, U+2588 FULL BLOCK) and to drop unrenderable characters — ANSI escape sequences, control characters, zero-width format characters, combining marks, lone surrogates — instead of printing `?` blanks. - Explained the line-break marker in the frame-reading prompt `snapcompact-summary.md` and extended `snapcompact.test.ts` for the new variants, wrapping, and normalization. - Added the `research/parity_check.py` and `research/parity_render.ts` parity tooling for the native renderer. - Recorded the snapcompact changelog entries.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
/**
|
|
* Production-side renderer for the parity check (`parity_check.py` drives it).
|
|
*
|
|
* Usage: bun parity_render.ts <text-file> <shape-json> <out-png>
|
|
*
|
|
* Renders the FIRST frame of `text` with the production snapcompact pipeline
|
|
* (`renderMany`, so doc pagination and stopword dimming take the exact code
|
|
* path the agent ships) and writes the PNG bytes to `out-png`.
|
|
*/
|
|
import * as snapcompact from "../src/snapcompact";
|
|
|
|
const [textFile, shapeJson, outPng] = Bun.argv.slice(2);
|
|
if (!textFile || !shapeJson || !outPng) {
|
|
throw new Error("usage: bun parity_render.ts <text-file> <shape-json> <out-png>");
|
|
}
|
|
|
|
const text = await Bun.file(textFile).text();
|
|
const shape = JSON.parse(shapeJson) as snapcompact.Shape;
|
|
if (!snapcompact.isShape(shape)) {
|
|
throw new Error(`shape json is not a complete Shape: ${shapeJson}`);
|
|
}
|
|
|
|
const frames = snapcompact.renderMany(text, { shape, maxFrames: 1 });
|
|
if (frames.length === 0) {
|
|
throw new Error("renderMany produced no frames");
|
|
}
|
|
await Bun.write(outPng, Buffer.from(frames[0].data, "base64"));
|