Commit ea9cae3
authored
fix(eds-tokens): emit nested typography TS with inlined size extras (#4915)
* fix(eds-tokens): emit nested typography TS with inlined size extras
Closes #4901.
The per-axis TS files (font-weight-*, line-height-*, tracking-*) and
the per-size files (font-size-*) silently picked one cell of the
family × size matrix because Style Dictionary cannot represent runtime
mode switching. These files are now removed; the two font-family files
become the only TS surface.
Each size cell in font-family-{ui,header}.ts is now self-contained:
nested fontWeight/tracking/lineHeight objects (so consumers can derive
variant types via keyof) plus inlined iconSize/gapHorizontal/gapVertical
extras. Implementation:
- New splitLeafPrefixes option on typescriptNestedFormat splits
hyphenated leaf segments (font-weight-lighter → fontWeight.lighter)
before nesting. Affects TS output only; CSS variable names unchanged.
- Per-size builds still emit temporary TS files which a post-step
parses for the three family-independent extras and splices into each
size cell of both family files. The regex is line-anchored to avoid
matching nested-axis closers and throws if a size cell can't be
located.
- Smoke tests in src/__tests__/typography-shape.test.ts assert the
emitted structure: every size cell has the expected nested keys,
inlined extras are family-independent (ui matches header per size),
and keyof narrows to the expected literal types.
* docs(eds-tokens): document the nested typography TS surface
- README.md: add a "Typography (non-CSS targets)" subsection describing
direct matrix import via @equinor/eds-tokens/ts/typography/font-family-*,
with a keyof example for variant types and a React Native note. Also
fix pre-existing data-text-size → data-font-size typos in the data
attribute examples.
- CLAUDE.md: expand the Typography output section to explain the
nested shape, the splitLeafPrefixes mechanism, the build-time splice
of family-independent size extras, and the build-order dependency on
build/ts/typography/.
- instructions/typography.md: replace the previous TypeScript Tokens
section (which documented importing the now-removed per-axis files)
with Direct token import + Deriving variant types + React Native
subsections, plus a "What's not exported" note explaining why other
axis files don't ship as TS.
* refactor(eds-tokens): apply review feedback on typography build
Per Claude review on #4915:
- Replace the local sizeKeyToCamel map with a call to toCamelCase
(re-exported from @equinor/eds-tokens-build) so the size-key →
identifier conversion has a single source of truth.
- Derive the splice loop's family list from fontFamilyConfig instead
of a hardcoded ['ui', 'header'] literal — adding a third family now
automatically extends the splice.
- Add a smoke-test assertion that build/ts/typography/ contains only
the two family files, catching cleanup-whitelist regressions.
- Document splitLeafPrefixes first-match-wins semantics on
BuildNestedObjectOptions.
Emitted font-family-{ui,header}.ts files are byte-identical to before
the refactor — verified by diff against pre-refactor snapshots.1 parent 7226fc4 commit ea9cae3
35 files changed
Lines changed: 1490 additions & 1156 deletions
File tree
- packages
- eds-tokens-build/src
- __tests__
- format
- eds-tokens
- build-generate-variables
- build/ts/typography
- instructions
- src
- __tests__
- generate-variables
Lines changed: 149 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
126 | 228 | | |
127 | 229 | | |
128 | 230 | | |
| |||
286 | 388 | | |
287 | 389 | | |
288 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
289 | 438 | | |
290 | 439 | | |
291 | 440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
57 | 96 | | |
58 | 97 | | |
59 | 98 | | |
60 | 99 | | |
61 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
62 | 104 | | |
| 105 | + | |
63 | 106 | | |
64 | 107 | | |
65 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
66 | 112 | | |
67 | 113 | | |
68 | 114 | | |
| |||
115 | 161 | | |
116 | 162 | | |
117 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
118 | 167 | | |
119 | 168 | | |
120 | 169 | | |
121 | 170 | | |
122 | 171 | | |
123 | 172 | | |
124 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
125 | 177 | | |
126 | 178 | | |
127 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
113 | 149 | | |
114 | 150 | | |
115 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
117 | 148 | | |
118 | 149 | | |
119 | 150 | | |
| |||
167 | 198 | | |
168 | 199 | | |
169 | 200 | | |
170 | | - | |
| 201 | + | |
171 | 202 | | |
172 | 203 | | |
173 | 204 | | |
| |||
194 | 225 | | |
195 | 226 | | |
196 | 227 | | |
197 | | - | |
| 228 | + | |
198 | 229 | | |
199 | 230 | | |
200 | 231 | | |
201 | 232 | | |
202 | | - | |
| 233 | + | |
203 | 234 | | |
204 | 235 | | |
205 | 236 | | |
206 | 237 | | |
207 | | - | |
| 238 | + | |
208 | 239 | | |
209 | 240 | | |
210 | 241 | | |
| |||
269 | 300 | | |
270 | 301 | | |
271 | 302 | | |
272 | | - | |
| 303 | + | |
273 | 304 | | |
274 | 305 | | |
275 | 306 | | |
| |||
0 commit comments