@eraserlabs/diagrams

中文文档
0.5.2发布于 2026/11/12MITTypeScriptES Module构建来源已验证近 30 天下载 1万

The impure conductor: owns Chromium, network, the font lifecycle, and the Eraser template library.

原始使用文档

@eraserlabs/diagrams

Introduction

@eraserlabs/diagrams is the batteries-included entry point of the rendering pipeline: the one package that owns everything impure. It drives Chromium (via playwright-core), stages and injects fonts, fetches icons, and ships the stock Eraser component library, wiring @eraserlabs/resolve and @eraserlabs/render into a single call that turns diagram JSON into PNG, measured JSON, or standalone HTML.

The pure pieces live below it: contracts in @eraserlabs/protocol, validation and resolution in @eraserlabs/resolve, in-page measurement and layout in @eraserlabs/render and @eraserlabs/layout. Use those directly when you need the pipeline without a browser; use this package when you want a picture.

Usage

import { createRenderer } from '@eraserlabs/diagrams';

const renderer = await createRenderer({ chromiumPath: '/path/to/chromium' });

const result = await renderer.render({
  entities: [{ tag: 'Textbox', id: 't1', x: 40, y: 40, text: 'Hello' }],
  connections: [],
  outputs: { png: true, json: true },
});

if (result.ok) {
  await writeFile('diagram.png', result.png);
}

await renderer.close();

Chromium is caller-owned: pass a local chromiumPath, or a browser provider for caller-managed and remote browsers (chromium.connectOverCDP(...)). A provider owns its browser's flags — if you use url font faces served from localhost or a private network, launch with --disable-features=LocalNetworkAccessChecks,BlockInsecurePrivateNetworkRequests, since the origin-less render page otherwise has its font fetches silently blocked by Chromium's Local Network Access checks (the chromiumPath path applies these flags for you). Everything else defaults to stock: the Eraser component library, the vendored fonts (Shantell Sans, Inter, JetBrains Mono — all SIL OFL 1.1, under fonts/), and Eraser's hosted icon catalog (which needs network access; supply iconLoader for offline or custom icons).

Set theme: 'dark' on createRenderer for its default presentation, or on an individual renderer.render({ ...document, theme: 'dark' }) request. The selection controls stock-template paints, text, code, watercolor and the scene background together. JSON output retains authored colors. HTML is self-contained, with the same themed roots and styles used for PNG.

PNG output has a white background in light mode and #171717 in dark mode. Pass transparent: true to createRenderer to preserve background transparency; authored fills remain visible and HTML output is unaffected.

renderer.validate runs the same validation as render without touching the browser. Rendering guides live in the repo root: GETTING_STARTED.md for authoring and CUSTOMIZATION.md for bringing your own component library, palette, and fonts.

版本与发布记录

@eraserlabs/diagrams 共发布 11 个版本,首次发布于 2026/08/19;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.2latest2026/11/122 天前
0.5.12026/11/059 天前
0.5.02026/11/0311 天前
0.4.32026/10/2816 天前
0.4.22026/10/2817 天前
0.4.12026/10/2817 天前

关于 @eraserlabs/diagrams 的常见问题

@eraserlabs/diagrams 是什么?

The impure conductor: owns Chromium, network, the font lifecycle, and the Eraser template library.

如何安装 @eraserlabs/diagrams?

在项目目录运行 npm install @eraserlabs/diagrams,或使用 pnpm add / yarn add / bun add。

@eraserlabs/diagrams 支持 TypeScript 吗?

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

@eraserlabs/diagrams 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eraserlabs/diagrams 需要什么版本的 Node.js?

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

@eraserlabs/diagrams 可以商用吗?

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

@eraserlabs/diagrams 的下载量有多少?

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

@eraserlabs/diagrams 还在维护吗?

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