@adobe/design-data-wasm

中文文档
0.15.0发布于 2026/11/07Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 2389

WebAssembly bindings for design-data-core — query, validate, resolve, diff, and registry helpers for Spectrum design tokens

原始使用文档
文档目录12 节
  1. Installation
  2. Release verification
  3. Usage
  4. Node.js (synchronous — no init() required)
  5. Browser / bundler (requires await init() )
  6. API
  7. Legacy compatibility output
  8. Dataset
  9. Registry helpers
  10. Embedded registry helpers
  11. TypeScript
  12. License

@adobe/design-data-wasm

WebAssembly bindings for design-data-core — query, validate, resolve, and diff Spectrum design tokens from JavaScript or TypeScript, with zero native dependencies.

Generated TypeScript types are derived directly from the Rust types via tsify-next — no hand-maintained parallel type surface.

Installation

pnpm add @adobe/design-data-wasm

Release verification

Run moon run sdk-wasm:verify-package to build both targets and check the packed package before publishing. The check installs the tarball in a temporary consumer outside the workspace and runs embedded-data queries through the Node and web entrypoints. It also checks that the bindings, types, and wasm binaries are present and valid. It does not publish packages.

Snapshot and stable release workflows run the same check after downloading their wasm build artifacts.

Usage

Node.js (synchronous — no init() required)

The node export condition resolves to a synchronous CommonJS build; named imports work in ESM via cjs-module-lexer.

import { Dataset, getValues, findValue } from "@adobe/design-data-wasm";

// Use the canonical embedded Spectrum dataset (zero config):
const ds = Dataset.embedded();

// Or build a dataset from your own token objects:
const tokens = JSON.parse(fs.readFileSync("my-tokens.json", "utf-8"));
const customDs = Dataset.fromTokens(tokens);

// Query
const colorTokens = ds.query("property=color,colorScheme=dark");
console.log(colorTokens[0].name, colorTokens[0].raw.value);

// Validate (relational rules — structural/JSON-Schema checks require the CLI)
const { valid, errors } = ds.validate();

// Resolve a property in a given context
const result = ds.resolve("background", {
  colorScheme: "dark",
  scale: "medium",
});
if (result)
  console.log(result.token.raw.value, "specificity:", result.specificity);

// Diff two datasets
const oldDs = Dataset.fromTokens(oldTokens);
const newDs = Dataset.fromTokens(newTokens);
const diff = oldDs.diff(newDs);
console.log(`${diff.added.length} added, ${diff.deleted.length} deleted`);

Browser / bundler (requires await init())

The browser export condition resolves to a browser ESM build. Call init() with the URL of the .wasm file before using any API.

Note for Deno, Bun, and non-standard bundlers: the package's default export condition also resolves to the web (browser ESM) build, so runtimes or bundlers that don't honour the node or browser condition will get this build and must call await init() before using any API.

import init, { Dataset } from "@adobe/design-data-wasm";
// or explicit browser path:
import init, {
  Dataset,
} from "@adobe/design-data-wasm/pkg/web/design_data_wasm.js";

await init(); // pass wasm URL if needed: await init(new URL('./wasm/design_data_wasm_bg.wasm', import.meta.url))

const ds = Dataset.fromTokens(tokens);
const results = ds.query("property=color");

API

Legacy compatibility output

ds.legacyOutput() returns a plain object keyed by legacy output filename. Each file contains token entries keyed by legacy name, including reconstructed mode sets and aliases. The embedded dataset includes component/token relationships. Non-default contrast records are excluded, matching native graph legacy output.

const byFile = ds.legacyOutput();
const flat = Object.assign({}, ...Object.values(byFile));
console.log(flat['picker-border-width'].value);

Dataset

MethodReturnsDescription
Dataset.embedded()DatasetOpen the canonical embedded Spectrum dataset (prebuilt .redb cache — zero config). The full token dataset is compiled into the .wasm binary via include_bytes!; use fromTokens() instead if binary size is a concern.
Dataset.fromTokens(tokens)DatasetBuild a dataset from an array of raw token JSON objects
ds.query(filterExpr)TokenResult[]Filter tokens. Syntax: key=value pairs joined with , (AND) or | (OR); != negation; * wildcard
ds.validate()ValidationResultRelational validation. valid, errors[], warnings[]
ds.resolve(property, context)ResolveResult | undefinedResolve a property in a mode-set context, e.g. { colorScheme: 'dark' }
ds.diff(otherDataset)DiffResultSemantic diff. Fields: renamed, deprecated, reverted, added, deleted, updated
ds.tokenCount()numberNumber of tokens in the dataset

Registry helpers

These match the deprecated @adobe/design-system-registry API, accepting the { values: [...] } JSON shape from @adobe/spectrum-design-data/registry/*.json.

FunctionDescription
getValues(registry)Return all value IDs
findValue(registry, term)Find an entry by ID or alias
hasValue(registry, term)Check if an ID or alias exists
getDefault(registry)Return the default entry
getActiveValues(registry)Return all non-deprecated entries

Embedded registry helpers

Fast lookups backed by the compile-time-embedded registry data (no JSON argument needed):

FunctionDescription
getFieldValues(fieldName)All IDs+aliases for a name field ("property", "component", …)
hasFieldValue(fieldName, value)Membership check for a name field
getAdvisoryFields()Names of advisory (non-normative) fields

TypeScript

Types are generated from the Rust structs; no parallel declaration needed.

import type {
  TokenResult,
  ValidationResult,
  DiffResult,
  ResolveResult,
} from "@adobe/design-data-wasm";

License

Apache-2.0 — see LICENSE.

版本与发布记录

@adobe/design-data-wasm 共发布 31 个版本,首次发布于 2026/07/21;过去 12 个月发布了 31 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.15.0latest2026/11/07今天
0.14.32026/11/052 天前
0.14.22026/11/052 天前
0.14.12026/11/052 天前
0.14.02026/11/052 天前
0.13.02026/11/043 天前

其他发布通道:size-token-taxonomy → 0.0.0-size-token-taxonomy-20261029173424。

关于 @adobe/design-data-wasm 的常见问题

@adobe/design-data-wasm 是什么?

WebAssembly bindings for design-data-core — query, validate, resolve, diff, and registry helpers for Spectrum design tokens

如何安装 @adobe/design-data-wasm?

在项目目录运行 npm install @adobe/design-data-wasm,或使用 pnpm add / yarn add / bun add。

@adobe/design-data-wasm 支持 TypeScript 吗?

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

@adobe/design-data-wasm 支持 ESM 还是 CommonJS?

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

@adobe/design-data-wasm 需要什么版本的 Node.js?

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

@adobe/design-data-wasm 可以商用吗?

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

@adobe/design-data-wasm 的下载量有多少?

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

@adobe/design-data-wasm 还在维护吗?

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