@cdx-ui/styles 0.0.1-beta.61 → 0.0.1-beta.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +74 -9
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -53,7 +53,7 @@ import pulse from '@cdx-ui/styles/presets/pulse.json';
53
53
 
54
54
  ### TypeScript exports
55
55
 
56
- The package exports DTCG-compatible type definitions, runtime constants for the override contract, and the `useForgeFonts` hook:
56
+ The package exports DTCG-compatible type definitions, runtime constants, palette generation utilities, theming functions, and the `useForgeFonts` hook:
57
57
 
58
58
  ```typescript
59
59
  import type {
@@ -66,6 +66,14 @@ import type {
66
66
  Preset,
67
67
  Mode,
68
68
  Platform,
69
+ CssVariableMaps,
70
+ RuntimeMap,
71
+ PaletteCategory,
72
+ PaletteScale,
73
+ PaletteStep,
74
+ PaletteTokenMap,
75
+ ApplyThemeOverrideOptions,
76
+ ApplyThemeOverrideResult,
69
77
  } from '@cdx-ui/styles';
70
78
 
71
79
  import {
@@ -74,6 +82,14 @@ import {
74
82
  SUPPORTED_OVERRIDE_SCHEMA_VERSIONS,
75
83
  INPUT_TOKEN_MAP,
76
84
  presetFonts,
85
+ DEFAULT_PRESET,
86
+ generateColorScale,
87
+ generatePalettesFromInputs,
88
+ deriveBaseColorKey,
89
+ applyThemeOverride,
90
+ isSchemaVersionSupported,
91
+ presetPatchToUniwindMaps,
92
+ themeOverrideToUniwindMaps,
77
93
  } from '@cdx-ui/styles';
78
94
  ```
79
95
 
@@ -85,6 +101,10 @@ import {
85
101
  - `Preset` — Union type: `'poise' | 'prestige' | 'pulse'`.
86
102
  - `TokenValue` / `TokenGroup` — DTCG leaf node and recursive group types.
87
103
  - `Mode` / `Platform` — `'light' | 'dark'` and `'web' | 'ios' | 'android'`.
104
+ - `CssVariableMaps` — Per-mode CSS variable maps ready for `Uniwind.updateCSSVariables`.
105
+ - `RuntimeMap` — Token dot-paths → CSS custom property names.
106
+ - `PaletteCategory` / `PaletteScale` / `PaletteStep` / `PaletteTokenMap` — Palette generation types.
107
+ - `ApplyThemeOverrideOptions` / `ApplyThemeOverrideResult` — Options and result types for `applyThemeOverride`.
88
108
 
89
109
  **Constants:**
90
110
 
@@ -92,12 +112,49 @@ import {
92
112
  - `SUPPORTED_OVERRIDE_SCHEMA_VERSIONS` — Array of schema versions accepted by this package version (includes current and optionally one prior version during transition windows).
93
113
  - `INPUT_TOKEN_MAP` — Maps known input keys (`brandPrimary`, `accentPrimary`, `basePrimary`, `displayFont`) to the token path pattern each affects. Used by override application to route inputs to the correct palette namespace.
94
114
  - `presetFonts` — Allowed display font families per preset, used by the Theme Editor for font selection and by consuming apps for validation.
115
+ - `DEFAULT_PRESET` — The default preset (`'poise'`).
116
+
117
+ **Palette generation:**
118
+
119
+ - `generateColorScale(hex, category)` — Generates an 11-step Leonardo contrast scale (50–950) plus an `input` step from a single hex color. Categories: `'brand' | 'accent' | 'base'`. Returns a `PaletteTokenMap` keyed by token dot-paths (e.g. `color.brand.50` through `color.brand.input`).
120
+ - `generatePalettesFromInputs(inputs)` — Iterates `brandPrimary`, `accentPrimary`, `basePrimary` from an override's `inputs` object; calls `generateColorScale` for each present value. Returns a merged `PaletteTokenMap`.
121
+ - `deriveBaseColorKey(brandHex)` — Derives a neutral base color key from a brand hex (brand hue/lightness at 5% saturation). Used by the Theme Editor to automatically compute `basePrimary` from `brandPrimary`.
122
+
123
+ **Theming utilities:**
124
+
125
+ - `applyThemeOverride(override, options?)` — High-level orchestrator: validates schema version → applies preset patch (if non-default base) → generates palettes from inputs → merges FI overrides → calls `Uniwind.updateCSSVariables` per mode. Returns a discriminated union: `{ applied: true, light, dark }` or `{ applied: false, reason }`. Options: `runtimeMap`, `runtimePlatform`. Bundles the default runtime map internally. Requires `uniwind` as a peer dependency.
126
+ - `isSchemaVersionSupported(override)` — Schema version gate; returns `true` if the override's `schemaVersion` is in `SUPPORTED_OVERRIDE_SCHEMA_VERSIONS`.
127
+ - `presetPatchToUniwindMaps(patch, runtimeMap, runtimePlatform)` — Walks a nested DTCG preset patch; buckets leaves by mode/platform into per-mode CSS variable maps.
128
+ - `themeOverrideToUniwindMaps(override, runtimeMap)` — Processes a hybrid FI override: palette generation from `inputs`, font mapping, per-mode `overrides` merge, and token-reference alias resolution.
129
+
130
+ A tree-shakeable subpath is also available:
131
+
132
+ ```typescript
133
+ import {
134
+ applyThemeOverride,
135
+ presetPatchToUniwindMaps,
136
+ themeOverrideToUniwindMaps,
137
+ } from '@cdx-ui/styles/theming';
138
+ ```
95
139
 
96
140
  **Hooks:**
97
141
 
98
142
  - `useForgeFonts` — Loads all preset display fonts (nine families, three per preset) plus platform web fonts (Inter, IBM Plex Mono) via `expo-font`. Returns `{ loaded: boolean; error: Error | null }`. Call in your root layout and gate rendering on the returned `loaded` boolean. See [Getting Started](../../docs/getting-started.md) for usage.
99
143
  - `useCdxFonts` — **Deprecated** alias for `useForgeFonts`. Retained for backward compatibility during the CDX → Forge rename transition. See [Getting Started](../../docs/getting-started.md) for the migration path.
100
144
 
145
+ ### Runtime artifacts
146
+
147
+ The build produces runtime JSON artifacts importable from the package:
148
+
149
+ ```typescript
150
+ import runtimeMap from '@cdx-ui/styles/runtime/token-to-css-var.json';
151
+ import prestigePatch from '@cdx-ui/styles/runtime/prestige-vs-default.json';
152
+ import pulsePatch from '@cdx-ui/styles/runtime/pulse-vs-default.json';
153
+ ```
154
+
155
+ - **`runtime/token-to-css-var.json`** — Flat map of ~667 token dot-paths to CSS custom property names (e.g. `"color.brand.500": "--color-brand-500"`). Used internally by `applyThemeOverride`; importable for custom apply logic.
156
+ - **`runtime/prestige-vs-default.json`** / **`runtime/pulse-vs-default.json`** — Sparse preset patches (diff from build default to target preset). Used internally by `applyThemeOverride` when `basePreset` differs from the build default.
157
+
101
158
  ## Token pipeline
102
159
 
103
160
  The pipeline has two stages — **fetch** and **build** — both run from package scripts.
@@ -144,12 +201,12 @@ pnpm tokens:build
144
201
  | `utilities.css` | `@utility` blocks for composite typography (headings, body-xl through body-xs, label-sm, label-xs) |
145
202
  | `vanilla.css` | Non-Tailwind fallback — `:root` variables + `@media (prefers-color-scheme: dark)` + classes |
146
203
 
147
- **Planned artifacts** (not yet implemented — tracked for future runtime theming):
204
+ **Runtime artifacts** (generated by `tokens:build`):
148
205
 
149
- | Artifact | Purpose | Status |
150
- | -------------- | ------------------------------------------------------------------ | ------- |
151
- | Runtime map | Theme object path → CSS custom property name for sparse flattening | Planned |
152
- | Preset patches | Sparse diff from build default → each non-default preset | Planned |
206
+ | Artifact | File | Purpose |
207
+ | ------------------ | ---------------------------------- | ------------------------------------------------------------------ |
208
+ | **Runtime map** | `runtime/token-to-css-var.json` | Theme object path → CSS custom property name for sparse flattening |
209
+ | **Preset patches** | `runtime/{preset}-vs-default.json` | Sparse diff from build default → each non-default preset |
153
210
 
154
211
  ### Validating font tokens
155
212
 
@@ -175,7 +232,7 @@ Light/dark mode switching is handled by Uniwind `@variant light/dark` blocks in
175
232
 
176
233
  ### FI overrides
177
234
 
178
- Financial institution white-labelling uses the hybrid override format — brand inputs (a single hex color expanded into a full palette at runtime) plus optional per-mode semantic token overrides. The Theme API is a pass-through store; validation is performed by the Theme Editor before save. Consuming apps apply overrides at runtime via palette generation + the runtime map + `Uniwind.updateCSSVariables`. See [Override Structure](../../docs/internal/token-architecture/16-override-structure.md) for the payload format and responsibility contract, and [Theme Definition](../../docs/internal/token-architecture/02-theme-definition.md) for the full theme object schema.
235
+ Financial institution white-labelling uses the hybrid override format — brand inputs (a single hex color expanded into a full palette at runtime) plus optional per-mode semantic token overrides. The Theme API is a pass-through store; validation is performed by the Theme Editor before save. Consuming apps apply overrides at runtime via `applyThemeOverride` (which handles palette generation, runtime map lookup, and `Uniwind.updateCSSVariables` calls internally). See [Override Structure](../../docs/internal/token-architecture/16-override-structure.md) for the payload format and responsibility contract, and [Theme Definition](../../docs/internal/token-architecture/02-theme-definition.md) for the full theme object schema.
179
236
 
180
237
  ## Package structure
181
238
 
@@ -185,12 +242,20 @@ styles/
185
242
  │ ├── theme.css # Auto-generated — all token variable declarations
186
243
  │ ├── utilities.css # Auto-generated — composite typography @utility blocks
187
244
  │ └── vanilla.css # Auto-generated — non-Tailwind fallback
245
+ ├── runtime/
246
+ │ ├── token-to-css-var.json # Build-generated — token path → CSS variable name map
247
+ │ ├── prestige-vs-default.json # Build-generated — sparse preset patch (Poise → Prestige)
248
+ │ └── pulse-vs-default.json # Build-generated — sparse preset patch (Poise → Pulse)
188
249
  ├── scripts/
189
250
  │ ├── figma-fetch-variables.mjs # Figma Variables REST API fetch
190
251
  │ ├── build-tokens.mjs # Style Dictionary build + artifact generation
191
252
  │ └── validate-font-tokens.mjs # CI check: --font-* values match useForgeFonts keys
192
253
  ├── src/
193
- │ ├── index.ts # Types, override constants, hook re-exports
254
+ │ ├── index.ts # Public barrel: types, constants, palette, theming, hooks
255
+ │ ├── palette.ts # Color scale generation (Leonardo contrast algorithm)
256
+ │ ├── theming.ts # Sparse flatten helpers (presetPatchToUniwindMaps, themeOverrideToUniwindMaps)
257
+ │ ├── applyThemeOverride.ts # High-level orchestrator (schema gate → patch → palette → apply)
258
+ │ ├── types.ts # DTCG types, override contract, constants
194
259
  │ ├── useForgeFonts.ts # Font loader hook (expo-font) — loads all preset display fonts
195
260
  │ └── useCdxFonts.ts # Deprecated alias for useForgeFonts
196
261
  ├── tokens/
@@ -206,7 +271,7 @@ styles/
206
271
  └── tsconfig.build.json
207
272
  ```
208
273
 
209
- `css/` files are auto-generated — do not edit directly.
274
+ `css/` and `runtime/` files are auto-generated — do not edit directly.
210
275
 
211
276
  ## Building
212
277
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/styles",
3
- "version": "0.0.1-beta.61",
3
+ "version": "0.0.1-beta.63",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -65,7 +65,7 @@
65
65
  "@expo-google-fonts/manrope": "0.4.2",
66
66
  "@expo-google-fonts/outfit": "0.4.3",
67
67
  "@expo-google-fonts/public-sans": "0.4.2",
68
- "@cdx-ui/utils": "0.0.1-beta.61"
68
+ "@cdx-ui/utils": "0.0.1-beta.63"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "expo-font": ">=13.0.0",