Skip to content

pantoken / formats/dtcg/src / toDtcg

Function: toDtcg()

toDtcg(tokens, mode?): Record<string, DtcgNode>

Beta

Convert an IR token list into a DTCG document.

Parameters

tokens

readonly Token[]

The IR (e.g. from @pantoken/tokens).

mode?

Mode = "light"

Which colour mode to resolve (default "light").

Returns

Record<string, DtcgNode>

A nested DTCG token tree.

Examples

Convert the default IR to a DTCG tree

ts
import { toDtcg } from "@pantoken/dtcg";
import { tokens } from "@pantoken/tokens";

const doc = toDtcg(tokens);
// doc.color.background.brand === { $value: "#0374b5", $type: "color" }

Resolve the dark mode of another theme

ts
import { toDtcg } from "@pantoken/dtcg";
import { byTheme } from "@pantoken/tokens";

toDtcg(byTheme("canvas"), "dark");