refract v0.1 · beta
Cookbook / DTCG round-trip

DTCG round-trip

Design tools and token pipelines speak DTCG. The full loop: bring tokens in from Figma / Style Dictionary, compile a theme, and (optionally) send tokens back out — all through the ./dtcg interop boundary.

round-trip.ts
import { fromDTCG, toDTCG } from "@theme-registry/refract/dtcg";
import { createTheme } from "@theme-registry/refract";
import { createCssAdapter } from "@theme-registry/refract-css";

// 1 · IN — a DTCG export (Figma / Style Dictionary) → a RawTheme input
const raw = fromDTCG(dtcgFromDesign);

// 2 · enrich — add what DTCG can't carry: recipes, states, composition
raw.colors.recipes = { solid: { brand: { background: "brand", color: "brand.text" } } };

// 3 · compile — a real theme, any adapter
const theme = createTheme(raw, { adapter: createCssAdapter() });

// 4 · OUT — property tokens back to DTCG for the design tool (or `refract tokens`)
const doc = toDTCG(theme, { name: "acme" });
The seam is deliberate: import is a transform into RawTheme (edit it freely), export is property-tokens-only for interop. Recipes / composition are refract-specific, but survive a refract → DTCG → refract trip via the opt-in includeRecipes extension + fromDTCGTheme — they just aren't portable to other tools. Full option tables are on the DTCG interop page.
Technical documentation for @theme-registry/refract · all output is compiled client-side by the real library (CSS adapter). The chrome is theme-aware; the render panes carry each preset's own world. · MIT licensed.