/** * TokenDef -- design token primitive for constraint-based adaptive rendering. * * A token defines a named design value that varies across axes (e.g. theme, * density, contrast). Content-addressed via FNV-1a. * * @module */ import type { ContentAddress } from './brands.js'; /** Design-system category of a {@link Token} — governs compilation strategy and CSS property prefix. */ export type TokenCategory = 'color' | 'spacing' | 'typography' | 'shadow' | 'radius' | 'animation' | 'effect'; interface TokenDef { readonly _tag: 'TokenDef'; readonly _version: 1; readonly id: ContentAddress; readonly name: N; readonly category: TokenCategory; readonly axes: Axes; readonly values: Record; readonly fallback: unknown; readonly cssProperty: `--${string}`; } interface TokenFactory { make(config: { readonly name: N; readonly category: TokenCategory; /** Single-value shorthand — derives `axes: []`, `values: {}`, `fallback: value`. */ readonly value: unknown; }): TokenDef; make(config: { readonly name: N; readonly category: TokenCategory; /** Default: ['default'] — single-value tokens need no axis declaration. */ readonly axes?: A; readonly values: Record; /** Default: derived from values.default when omitted; omitting both is a validation error. */ readonly fallback?: unknown; }): TokenDef; } /** * Resolve a token's value for the given axis values. Builds a sorted lookup key. * * Axes are sorted alphabetically and joined with ':' to form the lookup key. * Falls back to the token's fallback value if no match is found. * * The optional type parameter `T` lets callers narrow the return value when * they know the value shape; without it, the return is `unknown` (the * underlying `TokenDef.values` is `Record` because token * values can be any JSON shape — colors as strings, spacing as numbers, * shadow records as objects). Pass `Token.tap(...)` for a color * token, etc. * * @example * ```ts * const token = Token.make({ * name: 'primary', category: 'color', * axes: ['theme'], * values: { 'light': '#000', 'dark': '#fff' }, * fallback: '#888', * }); * const value = Token.tap(token, { theme: 'dark' }); * // value === '#fff' (typed as string) * ``` */ declare function _tap(token: TokenDef, axisValues: Record): T; /** * Generate a CSS var() reference for a token. * * Returns a `var(--czap-)` string suitable for use in CSS properties. * * @example * ```ts * const token = Token.make({ * name: 'primary', category: 'color', * axes: ['theme'], * values: { 'light': '#000' }, * fallback: '#888', * }); * const ref = Token.cssVar(token); * // ref === 'var(--czap-primary)' * ``` */ declare function _cssVar(token: TokenDef): `var(--czap-${N})`; /** * Token namespace -- design token primitive for adaptive rendering. * * Create named design values that vary across axes (theme, density, contrast). * Tokens are content-addressed and produce CSS custom property references. * * @example * ```ts * import { Token } from '@czap/core'; * * const spacing = Token.make({ * name: 'gap', category: 'spacing', * axes: ['density'], * values: { 'compact': '4px', 'comfortable': '8px' }, * fallback: '6px', * }); * const resolved = Token.tap(spacing, { density: 'compact' }); * // resolved === '4px' * const cssRef = Token.cssVar(spacing); * // cssRef === 'var(--czap-gap)' * ``` */ export declare const Token: TokenFactory & { tap: typeof _tap; cssVar: typeof _cssVar; }; export declare namespace Token { /** Structural shape of a token definition parameterized by its name `N` and axis tuple `Axes`. */ type Shape = TokenDef; } export {}; //# sourceMappingURL=token.d.ts.map