@design-parity/adapter-claude-design

中文文档
1.18.0发布于 2026/11/07Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 4109

Claude Design reference adapter: resolves a committed HTML export via design-map.json, rasterizes it headlessly, and normalizes to a DesignReference. Claude Design has no read API and no Figma export.

原始使用文档
文档目录8 节
  1. There is no Claude Design read API
  2. Push-back is /design-sync , not a CanvasWriter
  3. The HTML export
  4. The synced token artifact ( .json ref)
  5. Live-render a prototype ( live: ref, #85)
  6. Usage
  7. Rasterization
  8. Errors

@design-parity/adapter-claude-design

The Claude Design ReferenceAdapter for design-parity. Depends only on @design-parity/core.

There is no Claude Design read API

Claude Design (beta since 2026-06) exposes no read API and no Figma export, so — unlike the Figma adapter (REST + Code Connect) or even Stitch (SDK) — there is nothing to fetch at run time. The reference is consumed as a committed HTML export checked into the consumer repo. Because there is no machine link to call, the correspondence is always a design-map.json entry and the resulting DesignReference always has linkMethod: "manifest".

/design-sync (2026-06): Claude Code's /design-sync now syncs a design system between the canvas and the repo — including pushing built UI back into Claude Design (the reverse direction the compose-preview-design-board skill used to own) and emitting committed, machine-readable tokens/components. This is a governed read → plan → write skill, not a read API the adapter can call, so the committed-export shape below is unchanged. But it does make the input machine-generated-and-committed rather than hand-authored, and opens a richer reference (synced tokens, see below) and a ref → code reverse index (already shipped: buildReverseIndex in @design-parity/resolver). See docs/claude-design-sync-impact.md.

Push-back is /design-sync, not a CanvasWriter

design-parity ships no claude-design CanvasWriter and runs no Code-to-Canvas push-back for this source. There is no Claude Design write API, and /design-sync's canvas push-back is an interactive, human-run terminal skill — it has no place on design-parity's unattended GitHub Action path (PRINCIPLES.md 1 "no AI in the CI loop", 4 "unattended in steady state", 5). So the reverse direction — getting what you built into Claude Design — is /design-sync itself, run by a person, and supersedes the older compose-preview-design-board skill that hand-built HTML to import. The Action's read-only job stays the same: resolve a committed reference and diff it. (Contrast Figma, where FigmaCanvasWriter + the opt-in code-led push-back exist precisely because that bridge is a non-interactive REST/plugin write.)

design-map.json ──▶ design/reference/*.html ──▶ rasterize ─┐
   (manifest)         (committed export)        (headless)  ├─▶ DesignReference
                          └─ handoff manifest ──▶ tokens ───┘     (manifest)

The HTML export

A committed export is an ordinary HTML document carrying one embedded handoff manifest:

<script type="application/design-parity+json">
  {
    "componentId": "ui/Card.kt#OfferCard",
    "tokens": { "spacing": { "padding": 16 }, "radius": { "corner": 12 } },
    "images": [
      { "state": "default", "theme": "light", "size": "medium",
        "src": "./offer-card.light.png" }
    ]
  }
</script>
  • images[].src — a pre-rendered PNG, resolved relative to the HTML file. Its width/height are read from the PNG itself, so reference dimensions can never drift from the committed bytes. A variant with no src (or an export with no images at all) is rasterized headlessly from the document.
  • tokens — inline DesignTokens, or a string path to a handoff token file (relative to the HTML) for token-compliance checks.
  • componentId — optional; when present it must match the component the resolver asked for, else resolve throws.

The synced token artifact (.json ref)

When a design-map.json ref ends in .json, the adapter treats it as a synced design-system token artifact — a committed W3C DTCG document, typically emitted by Claude Code's /design-sync — instead of an HTML export. It is loaded through @design-parity/core's loadDtcgTokens into a token-only DesignReference:

  • referenceImages is [] and nothing rasterizes (no HTML, no layout capture) — the reference feeds the token-compliance diff only.
  • linkMethod is still "manifest" (there is no read API; this is a committed file).
  • resolve throws a claude-design-prefixed error if the file is missing, isn't JSON, or fails DTCG schema validation.
// design-map.json — point the ref at the synced DTCG document
{ "code": "ui/Card.kt#OfferCard", "source": "claude-design",
  "ref": "design/design-system.tokens.json" }

This is the richer of the two shapes: the token table comes straight from the synced design system rather than an export's embedded handoff block. See docs/claude-design-sync-impact.md.

Live-render a prototype (live: ref, #85)

A committed export is a single flattened frame. When a design-map.json ref is prefixed live:, the adapter instead drives the actual clickable prototype in a browser and captures it at each configured viewport — a truer reference that also picks up whatever the static export flattened, and one that pairs per-cell against the candidate's device × breakpoint render matrix.

// design-map.json — opt one component into live-render
{ "code": "ui/Card.kt#OfferCard", "source": "claude-design",
  "ref": "live:design/prototypes/offer-card.html" }
  • Opt-in. Only a live:-prefixed ref takes this path; every unprefixed ref stays on the lighter static-export path, unchanged. Mirrors the figma: / stitch: ref schemes.
  • Multi-viewport. Each configured LiveViewport becomes one Image keyed by its size slot (compact / medium / expanded). The default is a single compact frame; pass liveViewports for a wider matrix.
  • Same contract. The result is a normal DesignReference with linkMethod: "manifest" — the diff engine can't tell it from a static export.
  • Injectable renderer. The default browserLiveRenderer drives headless Chrome/Chromium on PATH (set CHROME_BIN), identical in spirit to the rasterizer — no browser-automation dependency is bundled. A caller already running Playwright (or a hosted renderer) injects its own liveRenderer:
new ClaudeDesignAdapter({
  liveRenderer: myPlaywrightRenderer,
  liveViewports: [
    { size: "compact", width: 412 },
    { size: "expanded", width: 1280 },
  ],
});

resolve throws a prefixed error when the live: ref names no path, the prototype is unreadable, or a configured viewport fails to render.

Usage

import { ClaudeDesignAdapter } from "@design-parity/adapter-claude-design";

const adapter = new ClaudeDesignAdapter();
const ref = await adapter.resolve(
  "ui/Card.kt#OfferCard",          // resolver-supplied code handle
  "design/reference/offer-card.html", // the design-map ref (repo-relative)
  { repoRoot: process.cwd(), env: process.env },
);

Rasterization

Rasterizing raw HTML variants defaults to browserRasterizer, which drives a headless Chrome/Chromium already on PATH (set CHROME_BIN to point at a specific binary) — no browser-automation dependency is bundled, keeping the package's only runtime dependency @design-parity/core. Inject your own to render inside an existing harness:

new ClaudeDesignAdapter({ rasterizer: myRasterizer });

Exports that ship pre-rendered src images never invoke a rasterizer.

Errors

resolve throws a clear, prefixed error when the export is missing, its handoff block is malformed, a referenced token file or image is missing, or the export's componentId contradicts the resolver.

版本与发布记录

@design-parity/adapter-claude-design 共发布 102 个版本,首次发布于 2026/06/14;过去 12 个月发布了 102 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.18.0latest2026/11/074 天前
1.17.02026/10/2617 天前
1.16.12026/10/1824 天前
1.16.02026/10/1726 天前
1.15.02026/10/1528 天前
1.14.12026/10/1230 天前

关于 @design-parity/adapter-claude-design 的常见问题

@design-parity/adapter-claude-design 是什么?

Claude Design reference adapter: resolves a committed HTML export via design-map.json, rasterizes it headlessly, and normalizes to a DesignReference. Claude Design has no read API and no Figma export.

如何安装 @design-parity/adapter-claude-design?

在项目目录运行 npm install @design-parity/adapter-claude-design,或使用 pnpm add / yarn add / bun add。

@design-parity/adapter-claude-design 支持 TypeScript 吗?

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

@design-parity/adapter-claude-design 支持 ESM 还是 CommonJS?

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

@design-parity/adapter-claude-design 可以商用吗?

@design-parity/adapter-claude-design 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@design-parity/adapter-claude-design 的下载量有多少?

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

@design-parity/adapter-claude-design 还在维护吗?

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