//#region src/token-value-types.d.ts /** * Typed envelopes for DTCG 2025.10 composite `$value` shapes, one per * `$type` the packages that render tokens consume. `RealisedToken`'s * top-level `$value` is typed per `$type` via the `TokenValue` mapped * type below; sub-values stay `unknown` because each may be a primitive * (number / string), a sub-value alias (string in `{token.path}` form, * post-resolution flattened to a string), or a nested composite. The win * over `Record` isn't value-level narrowing: it's that * typo-ing a key (`fontFamlly`) becomes a compile error. * * The DTCG spec is the source of truth for the keys; this file * translates that into TypeScript without re-deriving the spec at * every consuming site. */ /** * `typography.$value` per DTCG 2025.10 §8.7. All fields optional — * partial specs are valid (e.g. a token may set only `fontSize` + * `lineHeight` and inherit the rest). */ interface TypographyValue { fontFamily?: unknown; fontSize?: unknown; fontWeight?: unknown; lineHeight?: unknown; letterSpacing?: unknown; } /** `border.$value` per DTCG 2025.10 §8.4. */ interface BorderValue { color?: unknown; width?: unknown; style?: unknown; } /** `transition.$value` per DTCG 2025.10 §8.5. */ interface TransitionValue { duration?: unknown; timingFunction?: unknown; delay?: unknown; } /** * Single layer of `shadow.$value`. Per DTCG 2025.10 §8.6, `shadow` * may be a single object or an array of layers; consumers should * normalize via `Array.isArray(...) ? value : [value]` and then iterate * `ShadowLayer[]`. */ interface ShadowLayer { color?: unknown; offsetX?: unknown; offsetY?: unknown; blur?: unknown; spread?: unknown; inset?: unknown; } /** Single stop of `gradient.$value` per DTCG 2025.10 §8.3. */ interface GradientStop { color?: unknown; position?: unknown; } /** `dimension` / `duration` object form per DTCG 2025.10 (`{ value, unit }`). */ interface DimensionValue { value?: unknown; unit?: unknown; } /** * `color.$value` per DTCG 2025.10 §8.1. Either the explicit * `colorSpace + components` form, or the legacy `hex` short-form * that pre-DTCG-2025 fixtures still use. `channels` is the older * alias for `components` retained for back-compat with token sources * that haven't migrated. */ interface ColorValue { colorSpace?: unknown; components?: unknown; channels?: unknown; alpha?: unknown; hex?: unknown; } /** * `strokeStyle.$value` per DTCG 2025.10 §8.2 — either a literal string * (`'solid' | 'dashed' | ...`) or an object describing a dashed * pattern. Object form is typed here; consumers handle the string * form via a runtime `typeof === 'string'` check. */ interface DashedStrokeStyleValue { dashArray?: unknown; lineCap?: unknown; } /** Every DTCG `$type` swatchbook presents. */ type TokenType = 'color' | 'gradient' | 'dimension' | 'shadow' | 'border' | 'transition' | 'typography' | 'fontFamily' | 'fontWeight' | 'strokeStyle' | 'number' | 'duration' | 'cubicBezier'; /** * The realised top-level `$value` shape per `$type`. Narrows the envelope a * presenter reads without re-casting; sub-values stay `unknown` (a sub-value * may be a primitive, a resolved alias string, or a nested composite), same * as the envelopes themselves. */ type TokenValue = T extends 'color' ? ColorValue : T extends 'gradient' ? GradientStop[] : T extends 'shadow' ? ShadowLayer | ShadowLayer[] : T extends 'border' ? BorderValue : T extends 'transition' ? TransitionValue : T extends 'typography' ? TypographyValue : T extends 'strokeStyle' ? string | DashedStrokeStyleValue : T extends 'fontFamily' ? string | string[] : T extends 'fontWeight' ? number | string : T extends 'number' ? number : T extends 'cubicBezier' ? number[] : T extends 'dimension' | 'duration' ? string | number | DimensionValue : unknown; /** * A fully-realised token: concrete `$value` (aliases already resolved, no * graph lookup), typed per `$type` via `TokenValue`, plus DTCG metadata a * presenter may show. The presenter tier consumes this; resolution is the * caller's job. Typing `$value` per `$type` lets a presenter holding a * concrete `RealisedToken` read the envelope without re-casting, and makes * a wrong-shape literal a compile error. * * Distributive over `T`, so the default `RealisedToken` (T = `TokenType`) is a * discriminated union that couples each `$type` to its own `$value` rather than * pairing an arbitrary `$type` with an arbitrary envelope. */ type RealisedToken = T extends TokenType ? { $type: T; $value: TokenValue; $description?: string; $deprecated?: string | boolean; } : never; //#endregion export { BorderValue, ColorValue, DashedStrokeStyleValue, DimensionValue, GradientStop, RealisedToken, ShadowLayer, TokenType, TokenValue, TransitionValue, TypographyValue }; //# sourceMappingURL=token-value-types.d.mts.map