import { themeContractTree, themeVarName } from './contract.js'; /** * Recursively walks the contract tree and builds a same-shape object where each leaf holds its * stable `var(--luke-*)` reference. This keeps the public `vars` shape fully source-owned and free * of styling-engine types: no `@vanilla-extract/css` import contributes to its declarations. */ function buildVars( node: Record, segments: Array = [], ): Record { const result: Record = {}; for (const [key, value] of Object.entries(node)) { const path = [...segments, key]; result[key] = value === null ? `var(${themeVarName(path)})` : buildVars(value as Record, path); } return result; } type ContractVars = { [K in keyof T]: T[K] extends null ? string : T[K] extends Record ? ContractVars : never; }; /** * Typed access to the semantic theme custom properties. Each path resolves to a stable global * `--luke-*` variable reference, for example `vars.color.background.danger.solid.hover` is * `var(--luke-color-background-danger-solid-hover)`. Emits no CSS; values are supplied by a * theme stylesheet built with `buildTheme`. */ export const vars = buildVars(themeContractTree) as ContractVars;