refract v0.1 · beta
Adapters / JSON

JSON adapter createJsonAdapter

Emits refract's own format-neutral token document — tokens, rule-sets, keyframes and containers as data (recipes and composition survive, which a plain-tokens export can't represent). No CSS. Surface: theme.json. For standardized DTCG interchange instead, see DTCG interop.

OptionTypeDefaultDescription
refs"both" | "path" | "value""both"How a derived token is represented — both = the ref/fn/arg and the resolved value; path = refs only; value = resolved values only.
indentnumber2JSON indentation (spaces).
theme.ts
import { createJsonAdapter } from "@theme-registry/refract-json";

const theme = createTheme(raw, { adapter: createJsonAdapter({ refs: "both" }) });
JSON.stringify(theme.json);  // { breakpoints, containers, tokens, ruleSets, keyframes }

Every bucket is a flat map keyed by a Model address. A leaf mirrors the Model's Ref: in the default both mode a derived token carries its ref/fn/arg and the resolved value — so palette synthesis, states, responsive overrides and composition-by-reference all survive as data (things a tokens-only DTCG export cannot represent):

theme.json (emitted)
{
  "tokens": {
    "colors.brand": { "value": "rgb(76, 110, 245)" },
    // a synthesized step keeps its derivation AND the resolved value
    "colors.brand.lighter": {
      "ref": "colors.brand.light", "fn": "lighten", "arg": 14,
      "value": "rgb(160, 179, 255)"
    }
  },
  "ruleSets": {
    "components.buttons.primary": {
      "kind": "recipe",
      // composition survives as cross-subsystem token-path refs
      "references": [
        "colors:solid.brand", "typography:button.base",
        "layout:padding.button", "effects:surface.focusable", "borders:edge.button"
      ],
      "declarations": { "cursor": { "value": "pointer" } /* … */ },
      "overrides": [ /* per-state / per-breakpoint deltas */ ]
    }
  }
}
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.