@dloizides/poster-render

中文文档
0.14.0发布于 2026/10/30MITTypeScriptESM + CJS零依赖近 30 天下载 4973

Poster and flier rendering from one JSON document: FlierDoc JSON Schema + validator, a pure canvas render(doc, assets, canvas) with layouts, formats, palette and font sets, and PNG export. The picture is placed contain + anchor, never cropped, and nothing

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Canvas injection
  4. Fonts
  5. Type floor
  6. Per-line style and ties
  7. Schema version policy

@dloizides/poster-render

One JSON document (FlierDoc) in, one poster out. Used by Flier Studio (FLIER-1 "Flier Studio").

  • flierDocSchema: JSON Schema of FlierDoc (give it to an LLM as response_format).
  • validateFlierDoc(input): { ok, doc } or { ok: false, errors }; errors read blocks.title: is required.
  • render(doc, assets, canvas): validates first (throws FlierDocError before touching the canvas), resizes the canvas to the format, draws, returns a RenderReport (picture rect, text and card boxes).
  • exportPng(canvas): PNG Blob of the canvas size.
  • Formats: story 1080x1920, post 1080x1350, square 1080x1080, phone 1170x2532, desktop 2560x1440.
  • Layouts: picture-right (E-A "Picture right"), picture-left (E-B "Picture left"), arch (E-C "Arch"), picture-bottom, list, phone-clock-safe (P-A "Phone, clock clear": top kept clear for the lock-screen clock), phone-arch (P-B "Phone arch"), desktop-safe (D-A "Desktop, icons clear": text clear of desktop icons and the taskbar), desktop-arch (D-B "Desktop arch"). LAYOUT_CATALOGUE lists id, design id, label, description and designed formats (for the app picker and the LLM prompt); defaultLayoutFor(format) gives E-A "Picture right" / P-A "Phone, clock clear" / D-A "Desktop, icons clear" (D4 "Layouts: keep all").
  • Arch layouts paint a soft arch (palette arch, about 4% off the ground) behind the picture only, inside the picture region; prices sit large on either side. The includes block is set at one size for every line. Palettes: sand, night, sea, rose. Font sets: classic, modern, elegant (the app loads the web fonts).
  • Optional tuning (per-theme overrides, absent = layout default): headerGap (0-200 px at a 1080 short edge) starts the body that far under the last header line when the header sits above it; itemDateScale (0.5-2) scales the list date script.
  • The picture is placed contain + anchor in its own region: never cropped, never faded, drawn last, and no text or card is laid out in its region. Text shrinks to fit, never overflows.
  • Example: kizombaWorkshopDocs (3 workshops + list flier), kizombaWorkshop (the list flier).

Install

npm install @dloizides/poster-render

Usage

import { exportPng, kizombaWorkshop, render, validateFlierDoc } from '@dloizides/poster-render';

const checked = validateFlierDoc(kizombaWorkshop);
if (!checked.ok) {
  throw new Error(checked.errors.join('\n'));
}
const canvas = document.createElement('canvas');
const report = render(checked.doc, { dancers: pictureImage, logo: logoImage }, canvas);
const png = await exportPng(canvas);

Canvas injection

render takes any canvas with a 2d context; the package has no canvas dependency.

  • Browser: an HTMLCanvasElement (or OffscreenCanvas); assets are loaded HTMLImageElement / ImageBitmap.
  • Node: @napi-rs/canvas (createCanvas(1, 1), loadImage(path)); render resizes the canvas to the format.

Fonts

The font sets name CSS families (FONT_SETS). The host loads them before render: in a browser with document.fonts.load(...) / @font-face, in Node with GlobalFonts.registerFromPath from @napi-rs/canvas. A missing font falls back to the default family and the text still fits.

Type floor

Every text run is at least 30px at a 1080 short edge (40px on desktop 2560x1440). When a layout cannot fit its text at the floor, the picture gives space to the text.

Per-line style and ties

import { LineAlign, sameSize, sameWidth } from '@dloizides/poster-render';

let doc = { ...base, lineStyles: { footer: { font: 'Georgia', sizeScale: 1.2, color: '#1f2a44', weight: 600, italic: true, letterSpacing: 0.05, align: LineAlign.Center } } };
doc = sameWidth(doc, 'title', 'titleBottom');
doc = sameSize(doc, 'venue.1', 'footer');
  • Keys: title, titleBottom, script, footer, includes.heading, includes.items.N, venue.N, schedule.N.label|time, prices.N.amount|label, items.N.date|price|schedule.M (LINE_KEY_PATTERN).
  • When rows are set on one line (compact), the merged row takes the style of schedule.N.label / prices.N.amount.
  • A width tie grows the narrower line to the wider one, capped at the column; a size tie takes the larger size where both still fit. Ties act inside one text zone (header, body or a flank).
  • A doc without lineStyles and lineTies renders exactly as before.

Schema version policy

FlierDoc.version is 1. A field added as optional keeps version 1; a removed, renamed or retyped field raises the version and validateFlierDoc rejects the other version with version: must be 1 (got N). A package major release goes with a new doc version.

版本与发布记录

@dloizides/poster-render 共发布 27 个版本,首次发布于 2026/10/28;过去 12 个月发布了 27 个版本。

版本发布日期距今
0.14.0latest2026/10/3012 天前
0.13.12026/10/3013 天前
0.13.02026/10/3013 天前
0.12.02026/10/3013 天前
0.11.32026/10/3013 天前
0.11.22026/10/3013 天前

关于 @dloizides/poster-render 的常见问题

@dloizides/poster-render 是什么?

Poster and flier rendering from one JSON document: FlierDoc JSON Schema + validator, a pure canvas render(doc, assets, canvas) with layouts, formats, palette and font sets, and PNG export. The picture is placed contain + anchor, never cropped, and nothing

如何安装 @dloizides/poster-render?

在项目目录运行 npm install @dloizides/poster-render,或使用 pnpm add / yarn add / bun add。

@dloizides/poster-render 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dloizides/poster-render 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dloizides/poster-render 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dloizides/poster-render 可以商用吗?

@dloizides/poster-render 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dloizides/poster-render 的下载量有多少?

根据 npm 官方下载统计,@dloizides/poster-render 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,973 次,日均约 166 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dloizides/poster-render 还在维护吗?

最新版本 0.14.0 发布于 2026/10/30(12 天前);至今共发布 27 个版本,其中过去 12 个月发布了 27 个;首次发布于 2026/10/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。