gongxiangp2/workers/detail-renderer

Isolated detail-page renderer

This package pins Fabric.js 7.4.0, Canvas 3.2.0, Sharp 0.34.4, and ag-psd 28.4.1. It deliberately has its own dependency tree, because the existing application optionally uses Canvas 2.x for older media workflows.

Run npm ci in this directory with Node.js 22 or newer. Run npm test for native image/PSD tests. Set DETAIL_RENDER_TEST_ARTIFACTS=1 to retain the synthetic PNG, long image, and PSD under the ignored output/detail-generator-render directory for visual inspection.

The application invokes cli.mjs as a child process. Production must set DETAIL_RENDERER_NODE to the isolated Node.js binary and DETAIL_RENDERER_ENTRY to the copied CLI entry. DETAIL_FONT_DIR points to the unmodified files from public/detail-generator/fonts. The Docker stages install native Canvas dependencies separately and retain the app's existing Node.js/Canvas versions.

The input is a bounded JSON document and a map of previously authorized image bytes encoded as base64. The renderer never reads URLs from the document and does not fetch assets. Rendering validates dimensions, colors, text layout, source MIME types, and missing assets before export. The parent process imposes an input/output cap, timeout, and separate 768 MiB JS heap.

Each screen uses an explicit left/top Fabric origin, centered proportion-preserving image crops, and the same complete Chinese font as the browser. PSD contains one group per screen, a background layer, raster scene/logo layers, and editable horizontal text with actual PostScript font names and explicit initial line breaks. Native text line spacing uses Fabric's measured line height. The saved composite and text raster layers preserve the initial pixels.

Automated tests verify exported PNG/JPEG pixels, stitched-image parity, font internal names, PSD composite parity, native text and group metadata, CLI transport, and explicit failure on overflowing copy or unavailable images. Photoshop opening, editing, and save/reopen acceptance requires the actual Photoshop application and is a separate manual gate; ag-psd can request a text-layer redraw on open. Install the matching font files before editing PSD text.