@design-parity/adapter-figma

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

Figma ReferenceAdapter: resolves a component to a Figma node via Code Connect, fetches the reference image + variables over the REST API, and normalizes to a DesignReference.

原始使用文档
文档目录4 节
  1. What it does
  2. Auth
  3. Usage
  4. Theming note

@design-parity/adapter-figma

The Figma ReferenceAdapter. Figma is the keystone source — the only one with a machine-resolvable design↔code link (Code Connect). This adapter uses the REST API + Code Connect, never the Dev Mode MCP server (that is local/desktop-session oriented and wrong for a hosted bot).

What it does

resolve(componentId, ref, ctx):

  1. Resolve the node. If ref is a handle (figma:<fileKey>/<nodeId> or a figma.com URL) it's parsed directly. Otherwise the adapter reads the repo's Code Connect output (figma.code-connect.json, or FIGMA_CODE_CONNECT_FILE) to map the component to a node.
  2. Fetch structure — GET /v1/files/:key/nodes (padding, corner radius, fills, text style).
  3. Fetch variables — GET /v1/files/:key/variables/local, mapping collection modes (Light/Dark) to themed colors. Degrades gracefully to structure-only tokens when variables aren't entitled.
  4. Render the reference image(s) — GET /v1/images, downloaded and written under outDir.
  5. Normalize to a DesignReference with linkMethod: "code-connect", including layout — the node tree's absoluteBoundingBoxes flattened to a SemanticTree (root-relative dp, frame on the root) so the structural layout diff can compare element placement. Text nodes are labelled by their visible characters, which is what matches a candidate's semantics label; other nodes fall back to their Figma layer name and so generally go unmatched until layer naming is reconciled. Absent when the node carries no bounding box.

Auth

Reads credentials from AdapterContext.env:

  • FIGMA_OAUTH_TOKEN → Authorization: Bearer (preferred), or
  • FIGMA_TOKEN / FIGMA_PAT / FIGMA_ACCESS_TOKEN → X-Figma-Token.

Missing credentials, 401/403, 429 (rate limit, with Retry-After), and a missing node each raise a typed FigmaError subclass.

Usage

import { createFigmaAdapter } from "@design-parity/adapter-figma";

const adapter = createFigmaAdapter({
  // optionally render one image per theme from separate frames
  resolveTargets: (ref) => [
    { nodeId: ref.nodeId, theme: "light", size: "compact" },
    { nodeId: "1:43", theme: "dark", size: "compact" },
  ],
});

const reference = await adapter.resolve(
  "ui/Button.kt#PrimaryButton",
  "figma:AbCdEf123456/1:42",
  { repoRoot: process.cwd(), env: process.env },
);

Network is injectable (fetch) and the client is mockable, so unit tests run fully offline (see test/).

Theming note

Figma's image render uses a node's default variable mode; the REST API can't switch modes per render. So themed tokens come from variables (all modes), while themed images come from rendering separate per-theme frames via resolveTargets.

版本与发布记录

@design-parity/adapter-figma 共发布 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-figma 的常见问题

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

Figma ReferenceAdapter: resolves a component to a Figma node via Code Connect, fetches the reference image + variables over the REST API, and normalizes to a DesignReference.

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

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

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

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

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

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

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

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

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

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

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

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