refract v0.1 · beta
Delivery / DTCG interop

DTCG interop

DTCG — the Design Tokens Community Group format — is the standard interchange for design tokens; Figma, Style Dictionary and the wider token ecosystem speak it. refract speaks it both ways. It is not an adapter: it's a small, format-neutral interop boundary at the @theme-registry/refract/dtcg subpath, so a Node / build script can use it without pulling the runtime graph.

Export carries property tokens only. DTCG has no component/recipe model, so recipes and composition don't round-trip through a standard DTCG document — toDTCG emits your colour, type, spacing and other property tokens (synthesized steps included), not your rule-sets. Tokens survive a trip through any DTCG tool; recipes are refract-specific and stay in the RawTheme.
DirectionFunctionWhat it is
ImportfromDTCG(doc)A transform into a RawTheme — you then call createTheme.
ExporttoDTCG(theme)A built theme's property tokens out as a DTCG document (also the refract tokens CLI).
ResolveparseDTCGDocument(doc)Flatten a DTCG doc, resolving its { ref } chains → resolved tokens.

Import — DTCG → RawTheme

fromDTCG returns a plain RawTheme input you pass to createTheme — and can edit first. Import is a build-time transform, not a runtime step: DTCG groups are mapped to subsystems (auto-detected from $type and group name by default).

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

const raw = fromDTCG(dtcgDoc);   // a RawTheme input — edit it freely
const theme = createTheme(raw, { adapter: createCssAdapter() });
OptionTypeDescription
groupMappingRecord<string, "colors"|"typography"|"effects"|"borders"|"layout"|"ignore">Map a DTCG group to a subsystem (or "ignore"). Default: auto-detect from $type + name.
breakpointsRecord<string, number>Breakpoints as name → px — DTCG has no breakpoint type, so supply them here.
breakpointGroupstringA DTCG group path to source breakpoints from (its dimension tokens are parsed to px).

Export — Theme → DTCG

toDTCG walks the flat theme.tokens map, resolves each path to a concrete literal (following aliases and running lighten/darken), and re-groups into DTCG. Property tokens only — recipes and composition are out of standard scope; colours emit as hex (the DTCG convention); synthesized tonal steps are included.

Recipe round-trip (opt-in). toDTCG(theme, { includeRecipes: true }) additionally stashes the built rule-set IR under a reverse-DNS $extensions key — com.theme-registry.refract (with a version) — so a document can round-trip refract → DTCG → refract without losing recipes. Restore it with fromDTCGTheme(doc, { adapter }) (property tokens and recipes in one call), or read the raw payload with readRefractExtension(doc). This is refract-specific and not portable: other DTCG tools ignore the extension and see property tokens only, and standard output is byte-identical when the flag is off.

export.ts
import { toDTCG } from "@theme-registry/refract/dtcg";

const doc = toDTCG(theme, { name: "acme" });   // a DTCG document

// …or at build time, the CLI sugar over the same call:
// $ refract tokens --out tokens.json
tokens.json (emitted)
{
  "$name": "acme",
  "color": {
    "$type": "color",
    "brand": {
      "base":  { "$value": "#4c6ef5" },
      "light": { "$value": "#708bf7" },   // synthesized, resolved to hex
      "dark":  { "$value": "#3d58c4" },
      "text":  { "$value": "#ffffff" }
    }
  },
  "breakpoint": { "$type": "dimension", "md": { "$value": "768px" } /* … */ }
}
OptionDefaultDescription
nameThe document's $name.
includeBreakpointstrueEmit breakpoints as a dimension group.

Supported token types

Import and export cover the DTCG $types that map onto refract's subsystems:

color · dimension · fontFamily · fontWeight · duration · cubicBezier · number · typography · shadow · border · transition · strokeStyle · gradient

Not the JSON adapter. The JSON adapter emits refract's own richer document — tokens plus rule-sets, keyframes and composition — through the adapter contract. DTCG interop is standardized, property-token-only interchange via fromDTCG / toDTCG, with no adapter involved. Use the JSON adapter to consume a theme in an app; use DTCG to exchange tokens with the design-token ecosystem.
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.