@md-code/styles 0.0.0-stage → 0.0.1

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 (81) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +771 -2
  3. package/dist/colors-0AY7L5dk.js +244 -0
  4. package/dist/index.js +129 -0
  5. package/dist/themes/colors.js +1 -0
  6. package/dist/themes-BJwXZ1XG.js +419 -0
  7. package/dist/themes.js +3 -0
  8. package/dist/types/GlobalStyles.d.ts +9 -0
  9. package/dist/types/GlobalStyles.d.ts.map +1 -0
  10. package/dist/types/ThemeProviderWrapper.d.ts +4 -0
  11. package/dist/types/ThemeProviderWrapper.d.ts.map +1 -0
  12. package/dist/types/helpers/font.d.ts +2 -0
  13. package/dist/types/helpers/font.d.ts.map +1 -0
  14. package/dist/types/helpers/fullWidth.d.ts +3 -0
  15. package/dist/types/helpers/fullWidth.d.ts.map +1 -0
  16. package/dist/types/helpers/index.d.ts +5 -0
  17. package/dist/types/helpers/index.d.ts.map +1 -0
  18. package/dist/types/helpers/offsets.d.ts +3 -0
  19. package/dist/types/helpers/offsets.d.ts.map +1 -0
  20. package/dist/types/helpers/spaceBetween.d.ts +3 -0
  21. package/dist/types/helpers/spaceBetween.d.ts.map +1 -0
  22. package/dist/types/index.d.ts +9 -0
  23. package/dist/types/index.d.ts.map +1 -0
  24. package/dist/types/theme-provider/styles.d.ts +19 -0
  25. package/dist/types/theme-provider/styles.d.ts.map +1 -0
  26. package/dist/types/themes/baseTheme.d.ts +166 -0
  27. package/dist/types/themes/baseTheme.d.ts.map +1 -0
  28. package/dist/types/themes/board.d.ts +287 -0
  29. package/dist/types/themes/board.d.ts.map +1 -0
  30. package/dist/types/themes/colors.d.ts +3 -0
  31. package/dist/types/themes/colors.d.ts.map +1 -0
  32. package/dist/types/themes/contract/defineTheme.d.ts +17 -0
  33. package/dist/types/themes/contract/defineTheme.d.ts.map +1 -0
  34. package/dist/types/themes/contract/index.d.ts +102 -0
  35. package/dist/types/themes/contract/index.d.ts.map +1 -0
  36. package/dist/types/themes/editor.d.ts +170 -0
  37. package/dist/types/themes/editor.d.ts.map +1 -0
  38. package/dist/types/themes/index.d.ts +12 -0
  39. package/dist/types/themes/index.d.ts.map +1 -0
  40. package/dist/types/themes/liquidGlass.d.ts +157 -0
  41. package/dist/types/themes/liquidGlass.d.ts.map +1 -0
  42. package/dist/types/themes/tokens/base/animation.d.ts +17 -0
  43. package/dist/types/themes/tokens/base/animation.d.ts.map +1 -0
  44. package/dist/types/themes/tokens/base/colors.d.ts +10 -0
  45. package/dist/types/themes/tokens/base/colors.d.ts.map +1 -0
  46. package/dist/types/themes/tokens/base/effects.d.ts +11 -0
  47. package/dist/types/themes/tokens/base/effects.d.ts.map +1 -0
  48. package/dist/types/themes/tokens/base/offsets.d.ts +8 -0
  49. package/dist/types/themes/tokens/base/offsets.d.ts.map +1 -0
  50. package/dist/types/themes/tokens/base/shadows.d.ts +7 -0
  51. package/dist/types/themes/tokens/base/shadows.d.ts.map +1 -0
  52. package/dist/types/themes/tokens/base/shape.d.ts +10 -0
  53. package/dist/types/themes/tokens/base/shape.d.ts.map +1 -0
  54. package/dist/types/themes/tokens/base/typography.d.ts +22 -0
  55. package/dist/types/themes/tokens/base/typography.d.ts.map +1 -0
  56. package/dist/types/themes/tokens/board.d.ts +298 -0
  57. package/dist/types/themes/tokens/board.d.ts.map +1 -0
  58. package/dist/types/themes/tokens/elements.d.ts +24 -0
  59. package/dist/types/themes/tokens/elements.d.ts.map +1 -0
  60. package/dist/types/themes/tokens/offsets.d.ts +20 -0
  61. package/dist/types/themes/tokens/offsets.d.ts.map +1 -0
  62. package/dist/types/themes/tokens/report.d.ts +241 -0
  63. package/dist/types/themes/tokens/report.d.ts.map +1 -0
  64. package/dist/types/themes/tokens/screens.d.ts +24 -0
  65. package/dist/types/themes/tokens/screens.d.ts.map +1 -0
  66. package/dist/types/themes/tokens/variables.d.ts +39 -0
  67. package/dist/types/themes/tokens/variables.d.ts.map +1 -0
  68. package/dist/types/themes/tokens/zIndexes.d.ts +13 -0
  69. package/dist/types/themes/tokens/zIndexes.d.ts.map +1 -0
  70. package/dist/types/themes/types/index.d.ts +8 -0
  71. package/dist/types/themes/types/index.d.ts.map +1 -0
  72. package/dist/types/themes/viking.d.ts +157 -0
  73. package/dist/types/themes/viking.d.ts.map +1 -0
  74. package/dist/types/themes/zones/pair.d.ts +297 -0
  75. package/dist/types/themes/zones/pair.d.ts.map +1 -0
  76. package/dist/types/themes/zones/report.d.ts +451 -0
  77. package/dist/types/themes/zones/report.d.ts.map +1 -0
  78. package/dist/types/types.d.ts +179 -0
  79. package/dist/types/types.d.ts.map +1 -0
  80. package/dist/types.js +0 -0
  81. package/package.json +325 -5
package/README.md CHANGED
@@ -1,3 +1,772 @@
1
- # Temporary Holding Version
1
+ # Styles — typed styles and themes
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > The global definition of styles in the application: the theme contract
4
+ > (`types.ts`), the themes (`themes/`), `ThemeProviderWrapper` and the CSS
5
+ > variables behind media queries. All global/reusable styles live here.
6
+
7
+ This document is the contract. The `STYLES` block of the repo-root
8
+ `architecture.yaml` enforces it on every ESLint run: what is written here is
9
+ what the linter demands from `packages/components`, `packages/sections`,
10
+ `apps` and this package itself.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i @md-code/styles react styled-components
16
+ ```
17
+
18
+ `react` `>=18 <20` and `styled-components` `>=6 <7` are peer dependencies;
19
+ `styled-reset` is installed with the package. ESM only (`"type": "module"`),
20
+ Node 18 or newer.
21
+
22
+ ---
23
+
24
+ ## 1. Philosophy: code stores logic, not values
25
+
26
+ A developer translates the customer's thoughts into the machine's language.
27
+ Copying numbers and colours out of Figma into variables loses the context the
28
+ designer had when inventing them. A month later nobody remembers why this gap
29
+ is `9px` and not `8px`, or why the shadow is exactly `0 4px 8px`.
30
+
31
+ Rules:
32
+
33
+ 1. **A variable is a meaning or an equation, not a value.**
34
+ Not `offset-1 = 8px` but `offsets.betweenElements` — "the gap between
35
+ elements". Not `9px` but a dependency like `screenWidth - columnWidth * 2`
36
+ from which 9px falls out by itself. If a value can be derived from others,
37
+ it is not stored — it is computed.
38
+ 2. **Rhythm.** Every offset is a multiple of one number (`basicOffset` in
39
+ `themes/offsets.ts`). `basicOffset` itself is only the origin point and is
40
+ never used in components. Components use semantic offsets only: `page`,
41
+ `section`, `betweenElements`, `elementContent`.
42
+ 3. **Media queries live in one place.** `ThemeProviderWrapper` (`MediaProvider`)
43
+ declares the CSS variables (`--offset-section`, `--height-header`, …) and
44
+ overrides them per device. A component writes
45
+ `padding: ${offsets.elementContent}` once — without a single `@media`.
46
+ Device differences are theme data
47
+ (`variables.offsets.*.{mobile,tablet,desktop}`), not component code.
48
+
49
+ ```diff
50
+ - Not
51
+ ```
52
+
53
+ ```jsx
54
+ const Button = styled.button`
55
+ @media (min-width: ${screens.mobile.width}px) {
56
+ padding: ${offsets.elementContent.mobile};
57
+ }
58
+ @media (min-width: ${screens.tablet.width}px) {
59
+ padding: ${offsets.elementContent.tablet};
60
+ }
61
+ @media (min-width: ${screens.desktop.width}px) {
62
+ padding: ${offsets.elementContent.desktop};
63
+ }
64
+ `;
65
+ ```
66
+
67
+ ```diff
68
+ + But
69
+ ```
70
+
71
+ ```jsx
72
+ const Button = styled.button`
73
+ padding: ${offsets.elementContent};
74
+ `;
75
+ ```
76
+
77
+ 4. **No magic numbers.** A number in a component that the theme has never
78
+ heard of is lost context. Either it is derived by a formula from existing
79
+ variables, or it is a new meaning that belongs in a theme (see §7 — first
80
+ check whether it is a theme, not a variable).
81
+
82
+ ## 2. A theme is a logical construct, not "dark/light"
83
+
84
+ A theme here is **not a user colour preference**. A theme is a complete design
85
+ context for a situation a component finds itself in. Same system, same
86
+ components, but:
87
+
88
+ - **Patient discharge summary** (`paper`): a paper surface, a handwriting
89
+ font, ink and blot effects on the text (`sectionContent`), highlighted
90
+ rows. The same theme is used by the print component — and that is all.
91
+ - **Appointment page** (`minimal`): a flat background, strict lines, a plain
92
+ readable font, black text, minimal buttons. Nothing extra, so the patient
93
+ is not overloaded.
94
+
95
+ A component is configured **once**: it knows only the theme contract
96
+ (entities, offsets, fonts, effects). All the painting — offsets, fonts,
97
+ colours, shadows, silhouettes — comes from the theme. Switching themes
98
+ requires no component edits: a `ThemeProvider` is nested around the zone and
99
+ overrides the theme for the whole subtree.
100
+
101
+ The provider hands its `theme` prop down **as is**: a theme is a COMPLETE
102
+ `ThemeInterface`, never a patch, and nothing is merged — not with `baseTheme`,
103
+ not with an outer theme (`<provider> = <complete ThemeInterface>`). A variant is
104
+ written where it is defined (`{ ...baseTheme, … }`, or by spreading the token
105
+ tables of `themes/tokens/`), not as a partial object handed to a provider.
106
+
107
+ One case is **not** a theme: a **status** (`failed`, `approval`, …). A status
108
+ is an application-owned meaning, not a design context for a zone. But a theme
109
+ is a complete design context, so statuses are **not** one global palette for
110
+ the whole app either: **each theme carries its own** `colors.status` map
111
+ (§3.4), and a component resolves a status key against the theme of its nearest
112
+ `ThemeProvider`. A status never becomes a nested `ThemeProvider` of its own.
113
+
114
+ **The main law: as FEW variables as possible, but MORE themes.**
115
+ A new visual variant is a new theme (or a nested `ThemeProvider`), never a new
116
+ variable in the contract. The narrower the contract, the easier components
117
+ are to test (§8).
118
+
119
+ ## 3. Entities: zones of application, not appearance
120
+
121
+ ### 3.1. What an entity is
122
+
123
+ An entity is a **zone where styles apply**: a surface that has content on it.
124
+ Every entity is a **pair**:
125
+
126
+ - `entity` — the surface itself (background, shape, shadow, border);
127
+ - `entityContent` — what sits ON it (text, icons).
128
+
129
+ The pair is inseparable: **everything placed on `X` is painted with
130
+ `XContent`**. Content never picks its own colour and never sets its own
131
+ background. A surface never sets text colour directly — only through its
132
+ pair.
133
+
134
+ ### 3.2. Naming rules
135
+
136
+ An entity name answers **WHERE it is used**, not WHAT it looks like.
137
+
138
+ Forbidden:
139
+
140
+ - `color-red-1`, `color-red-2`, `blue-500` — appearance instead of a zone;
141
+ - `color-brand`, `color-primary`, `color-secondary` — abstractions that do
142
+ not say where to apply them;
143
+ - `small / medium / large`, `soft / strong` for zones — intensity scales
144
+ instead of a zone (where is `small` and where is `medium`?);
145
+ - duplicates of one zone under several names (`overlay`, `overlayActive`,
146
+ `overlayBackground` — one entity smeared over three variables).
147
+
148
+ A name is allowed only if a real page/component zone exists that cannot be
149
+ expressed by the existing entities or by a theme.
150
+
151
+ ### 3.3. Entity catalog (the minimum)
152
+
153
+ | Entity | Surface (`entity`) | Content (`entityContent`) | Zone of application |
154
+ |---|---|---|---|
155
+ | `section` | background of a section/page/card | the main text and icons on it | any section: page, card, form, cell |
156
+ | `highlighted` | the accent surface | content on the accent | selection, active element, primary action, selected row |
157
+ | `overlay` | the layer above the page | content on that layer | dimming/backdrop under a modal or a drawer; **one** entity, not three |
158
+
159
+ That is the whole colour contract: two working pairs (`section`,
160
+ `highlighted`) and one service zone (`overlay`).
161
+
162
+ `disabled` is **not an entity** but a state (§4.3): a modifier of any zone,
163
+ described by `effects.interaction.disabled`. There is no
164
+ `disabled/disabledContent` pair in the contract (§5.1).
165
+
166
+ **Statuses are not entities either.** `error`, `warning`, `success`, `info` and
167
+ any other meaning the product invents are **application vocabulary**, not a
168
+ zone: they are keys of the optional open `colors.status` map each theme fills
169
+ in (§3.4). The catalog never grows a status row.
170
+
171
+ ### 3.4. Where statuses, labels and other "meaning colours" go
172
+
173
+ The old `warningBackground / errorBackground / successBackground /
174
+ labelBackground …` tokens are **deleted**: they were a legacy hardcode where
175
+ every new status demanded new contract variables and a new `switch` in every
176
+ component (`Badge`, `Button`). Statuses now live **only** in each theme's open
177
+ `colors.status` map (§5.1), and `styles` ships **zero** status names.
178
+
179
+ A status is **not a variable and not an entity**. A status is a **meaning the
180
+ consuming application owns**. The styles package knows **zero status names**:
181
+ no status key called `error`, `warning`, `success` or `info` exists anywhere in
182
+ `packages/styles` — not in the contract, not in a theme, not in code (the old
183
+ `errorBackground`-style tokens are deleted, §5.1; they were never keys of the
184
+ status map). The vocabulary belongs to the application, not to the design
185
+ system.
186
+
187
+ The contract gives one **open, optional** map on **every theme**
188
+ (`ThemeInterface<TStatus extends string = string>`, §5.1):
189
+
190
+ ```ts
191
+ colors: {
192
+ // …
193
+ status?: Partial<Record<TStatus, { background: string; content: string }>>;
194
+ }
195
+ ```
196
+
197
+ A theme is a complete design context (§2), so the map is configured **per
198
+ theme, once for that theme** — not once for the whole application. Each theme
199
+ translates its own vocabulary into pairs; two themes of the same app may name
200
+ and paint statuses differently:
201
+
202
+ ```ts
203
+ // viking theme — viking's own keys and palette
204
+ status: {
205
+ approval: { background: '…', content: '…' },
206
+ success: { background: '…', content: '…' },
207
+ failed: { background: '…', content: '…' },
208
+ }
209
+
210
+ // liquidGlass theme — its own vocabulary, its own palette
211
+ status: {
212
+ ok: { background: '…', content: '…' },
213
+ error: { background: '…', content: '…' },
214
+ pending: { background: '…', content: '…' },
215
+ }
216
+ ```
217
+
218
+ Every zone `ThemeProvider` therefore receives **its own** map: the styleguide
219
+ demo builds one map per theme in
220
+ `components/theme-editor/demoStatusTheme.ts` and never injects one global map
221
+ into all themes.
222
+
223
+ A component reads that map in **one line** and knows no names:
224
+
225
+ ```tsx
226
+ background: ${({ $status = "", theme }) =>
227
+ theme.colors.status?.[$status]?.background ?? theme.colors.section};
228
+ color: ${({ $status = "", theme }) =>
229
+ theme.colors.status?.[$status]?.content ?? theme.colors.sectionContent};
230
+ ```
231
+
232
+ No `switch`, no `case`, no status type in the component. A new status is a new
233
+ key in that theme's map — **zero component edits** (§7).
234
+
235
+ #### The `StatusPair` channels, and zone chrome
236
+
237
+ A `StatusPair` carries **two required** channels — `background` (the surface of
238
+ the status) and `content` (the ink ON it) — plus **two optional zone channels**:
239
+ `hot` (the focused wash of the ONE chain under the pointer, painted uniformly)
240
+ and `paint` (the wash behind a standing text mark of this status). A theme that
241
+ omits them lets the component derive or fall back: `hot` → `content`, `paint` →
242
+ the zone's `highlighted` accent. They are optional so **every existing theme
243
+ compiles unchanged**; they are the per-palette, hand-tuned channels a plain zone
244
+ does not need.
245
+
246
+ A **zone theme** may also declare **chrome keys** in its own status map — e.g. a
247
+ code board's `edge` / `dim` / `faint` / `ribbon` muted greys. These are the
248
+ zone's **own vocabulary** ("zone themes carry their own subset", above), not
249
+ application meanings: the component reads them as fixed keys with a fallback to
250
+ the zone pair. This keeps hand-tuned chrome pixel-exact without inventing a
251
+ contract field — §7.3's derive-don't-store applies only when a value IS
252
+ derivable, and hand-tuned per-palette greys are not.
253
+
254
+ #### Typed statuses: per-theme keys, compile-time checks
255
+
256
+ Open by default, **narrowable** by the consuming application: a status key the
257
+ current theme does not declare is then a TypeScript error instead of a silent
258
+ fallback.
259
+
260
+ ```ts
261
+ // @md-code/styles — the contract is generic over its status keys
262
+ export interface ThemeInterface<TStatus extends string = string> {
263
+ colors: { status?: Partial<Record<TStatus, StatusPair>> };
264
+ }
265
+
266
+ /** Keys a given theme type declares; `string` when un-narrowed. */
267
+ export type StatusKeyOf<TTheme> = TTheme extends {
268
+ colors: { status?: infer TStatusMap };
269
+ }
270
+ ? keyof NonNullable<TStatusMap> & string
271
+ : string;
272
+
273
+ /** App-wide form: the keys the app declared on `DefaultTheme`. */
274
+ export type ThemeStatusKeys = StatusKeyOf<DefaultTheme>;
275
+ ```
276
+
277
+ The application declares its vocabulary **once** by augmenting
278
+ `styled-components`; components type their props through `StatusKeyOf<TTheme>`
279
+ and therefore accept exactly the app's keys:
280
+
281
+ ```ts
282
+ // application styled.d.ts
283
+ declare module 'styled-components' {
284
+ export interface DefaultTheme extends ThemeInterface<AppStatus> {}
285
+ }
286
+ ```
287
+
288
+ ```ts
289
+ // components — generic over the theme type, open by default
290
+ export type ButtonTone<TTheme extends DefaultTheme = DefaultTheme> =
291
+ | 'active' | 'passive' | StatusKeyOf<TTheme>;
292
+ export interface BadgeProps<TTheme extends DefaultTheme = DefaultTheme> {
293
+ $status?: StatusKeyOf<TTheme>;
294
+ }
295
+ ```
296
+
297
+ - **The library stays open.** `TStatus = string`, so `@md-code/styles` and every
298
+ app that does not augment `DefaultTheme` compile with any status string —
299
+ the keystone template keeps compiling untouched.
300
+ - **An augmented app gets its own union.** Unknown keys fail: in the
301
+ styleguide, `tone="doesNotExist"` / `$status="doesNotExist"` are errors.
302
+ - **Per-zone narrowing.** `DefaultTheme` is app-wide (the union of the app's
303
+ themes), so a zone binds the components to its own theme type instead:
304
+ `Badge<TTheme>` inside a generic `Zone<TTheme>` wrapper — a key from another
305
+ theme is then an error in that zone. Proof, compiled with
306
+ `@ts-expect-error` so an unused directive fails the build:
307
+ `apps/_template-styleguide/types/status-typing.test.tsx`.
308
+
309
+ Rules:
310
+
311
+ - **The map is open by default.** Any key is legal until the app narrows
312
+ `DefaultTheme`; a component never declares which keys exist. Props are typed
313
+ `StatusKeyOf<DefaultTheme>`, which is `string` for an un-augmented app.
314
+ - **The map is optional.** A theme without statuses is a valid theme
315
+ (`baseTheme` ships `status: {}`); every component then paints the plain zone
316
+ pair.
317
+ - **Fallback is the zone.** A missing key is not an error at runtime: the
318
+ element is painted as the zone it stands on (`section` / `sectionContent`).
319
+ - **Zone themes carry their own subset.** A nested theme of a zone (a code
320
+ block, a patient card, a print surface) declares its own status map with
321
+ only the keys that zone can show; keys it omits fall back to that zone's own
322
+ colours. Same components, different status palettes per zone — no new
323
+ variables, no new components.
324
+ - **One source per theme.** A theme's map is the single place its statuses are
325
+ defined, so a key looks the same in every zone of that theme by
326
+ construction: one source, zero copies across components. Another theme of
327
+ the same app may paint the same key differently (that is the design
328
+ context); a nested zone theme overrides its own subset only. A status that
329
+ must look **absolutely identical** everywhere is declared in the theme's map
330
+ and nested zones do not override it.
331
+ - **Never in `styles`.** This package ships no status key. A status key added
332
+ here would make the design system the owner of the application's
333
+ vocabulary — exactly the hardcode this section removes.
334
+
335
+ `tone` stays as **syntactic sugar** where it already exists (`Button`). A tone
336
+ is either one of the two contract meanings — `active` → the `highlighted`
337
+ pair, `passive` → the `section` pair — or a key looked up in the same map:
338
+ `tone="negative"` reads `colors.status?.negative` of the **nearest theme**. The
339
+ component does **not** define what "negative" means; that theme's map does. An
340
+ absent tone key falls back to the zone pair. `Badge`'s `$status` is the same
341
+ lookup under another prop name.
342
+
343
+ `label …` and `overlayActive` go the same way: the active state of a backdrop
344
+ is a **state**, described in `effects.interaction` (§4.3), not stored as a
345
+ separate colour; a "label" surface is a zone theme, not a new pair.
346
+
347
+ ## 4. CSS properties split: entity / entityContent / states / layout
348
+
349
+ Every CSS property belongs to exactly one category. The category decides
350
+ where the value comes from and who may set it. TypeScript checks which FIELDS
351
+ a theme declares; whether the VALUE a field holds is legal CSS is checked by
352
+ the architecture linter's generic resolver, per theme (§5.6).
353
+
354
+ ### 4.1. Entity properties (the surface)
355
+
356
+ Set on the zone's container. Values come from `colors.<entity>`, `border`,
357
+ `geometry`, `shadows`, `effects.texture` (one string: the theme's surface
358
+ texture), `offsets.elementContent`.
359
+
360
+ | Property | Value source |
361
+ |---|---|
362
+ | `background-color`, `background` | `colors.<entity>` |
363
+ | `background-image` | `effects.texture` (surface texture: paper, noise) |
364
+ | `border`, `border-width`, `border-color` | `border.size` + a pair colour (`<entityContent>` or `<entity>`) |
365
+ | `border-radius` | `border.radius` |
366
+ | `clip-path` | `geometry.shape` — the entity silhouette (§5.4) |
367
+ | `box-shadow` | `shadows.<zone>` (§5.2) |
368
+ | `padding` | `offsets.elementContent` |
369
+ | `width / height / min-* / max-*` | `elements.*` (through CSS variables) |
370
+ | `backdrop-filter` | `effects.texture`, when the theme is glass |
371
+
372
+ ### 4.2. Content properties (entityContent)
373
+
374
+ Set on text/icons inside the zone. Values come from `colors.<entity>Content`
375
+ and `font`.
376
+
377
+ | Property | Value source |
378
+ |---|---|
379
+ | `color` | `colors.<entity>Content` |
380
+ | `fill`, `stroke` (icons) | `colors.<entity>Content` (or `currentColor`) |
381
+ | `font-family` | `font.family.text / title` — there is no `code` role: a code surface is a zone theme whose `text` role IS monospace (§6) |
382
+ | `font-size` | `font.sizes.*` (the only allowed scale — typographic, it is universal) |
383
+ | `font-weight` | `font.weight.text / title` — weight per typographic role |
384
+ | `text-transform` | `font.transform.text / title` — casing per typographic role |
385
+ | `letter-spacing`, `line-height` | `font.spacing` / the theme |
386
+ | `text-shadow` | `shadows.content` — the content effect: ink/blots, text glow (§5.2) |
387
+ | `text-decoration` | component semantics (a link), not the theme |
388
+
389
+ ### 4.3. States (universal for any browser)
390
+
391
+ `hover`, `active`, `focus`, `disabled` are not entities and not colours. They
392
+ are states of any interactive element, described by the theme as a whole:
393
+ `effects.interaction.<state>` is a ready CSS fragment (transform, filter,
394
+ box-shadow, outline…). The component only attaches it to the selector:
395
+
396
+ ```ts
397
+ &:hover { ${({ theme }) => theme.effects.interaction.hover} }
398
+ &:active { ${({ theme }) => theme.effects.interaction.active} }
399
+ &:focus-visible { ${({ theme }) => theme.effects.interaction.focus} }
400
+ &:disabled { ${({ theme }) => theme.effects.interaction.disabled} }
401
+ ```
402
+
403
+ Same place: `cursor`, `transition`, `opacity`. A component does not invent
404
+ its own "lift by 2px and brighten" — that is the theme's decision.
405
+
406
+ **`disabled` is a modifier of any entity, not a separate zone.** A button can
407
+ be disabled on `section`, on `highlighted`, or on a surface the application
408
+ painted with a `colors.status` key (§3.4). A fixed grey
409
+ pair cannot express that: "disabled primary" and "disabled passive" would
410
+ collapse into one grey, losing the meaning of the original zone. So
411
+ `interaction.disabled` is a derivative on top of the current pair (e.g.
412
+ `opacity + grayscale + cursor: not-allowed`), not stored colours (§1: derive,
413
+ don't store). If a theme needs exact solid disabled colours ("faded ink" in
414
+ `paper`), it writes `background-color`/`color` inside its own
415
+ `interaction.disabled` fragment; the contract does not grow.
416
+
417
+ ### 4.4. Layout and environment (not entities)
418
+
419
+ | Property | Value source |
420
+ |---|---|
421
+ | `margin`, `gap` between sections | `offsets.page / section` |
422
+ | `gap` between elements | `offsets.betweenElements` |
423
+ | header, form, modal, sidebar sizes | `elements.*` |
424
+ | breakpoints | `screens.*` (only in `ThemeProviderWrapper`, never in components) |
425
+ | `z-index` | `zIndex.*` — one layer table shared by every theme (below) |
426
+ | `position`, `display`, `grid-template-*`, `flex-*` | component structure — the only thing a component decides itself |
427
+
428
+ The stack is ONE table for the whole library (`themes/tokens/zIndexes.ts`): a
429
+ theme does not carry a table of its own, and a declaration names a layer
430
+ instead of typing a number.
431
+
432
+ | Layer | What sits on it |
433
+ |---|---|
434
+ | `animatedElements` | ambient decoration under the page: textures, loading marks, animated washes |
435
+ | `content` | the page itself: every surface and every element in the normal flow |
436
+ | `overlay` | what covers the page while it is open: a menu, a scrim, a header pinned on scroll |
437
+ | `alert` | the topmost notice a user must read: alerts, toasts, tooltips, popovers |
438
+
439
+ ## 5. The theme contract
440
+
441
+ This is the **current** contract, not a migration in progress: the rewrite is
442
+ complete and component code reads only these fields. Below is what stays and
443
+ what replaced the deleted legacy zones.
444
+
445
+ ### 5.1. `colors` — entity pairs + the open status map
446
+
447
+ Stays: `section/sectionContent`, `highlighted/highlightedContent`,
448
+ `overlay`, and the **open, optional** `status`
449
+ map (the only place a status lives, §3.4):
450
+
451
+ ```ts
452
+ colors: {
453
+ section: string;
454
+ sectionContent: string;
455
+ overlay: string;
456
+ highlighted: string;
457
+ highlightedContent: string;
458
+
459
+ // Application-owned meanings, PER THEME; `styles` knows no key in it (§3.4).
460
+ status?: Partial<Record<TStatus, StatusPair>>;
461
+ }
462
+ ```
463
+
464
+ `TStatus` defaults to `string` (the library is open, §3.4); an app narrows it
465
+ through its `DefaultTheme` augmentation, and each theme's map declares its own
466
+ keys. The map is empty in `baseTheme` (`status: {}`) — an abstract default that
467
+ paints nothing and lets every component fall back to its zone pair.
468
+
469
+ Deleted (the migration is complete; no component reads these):
470
+
471
+ - `warningBackground/Content`, `errorBackground/Content`,
472
+ `successBackground/Content`, `labelBackground/Content`, `overlayBackground`,
473
+ `overlayActive` — these were statuses and states stored as contract
474
+ variables. Their concepts moved: every status became a key of that theme's
475
+ `status` map (§3.4); `overlayActive` became `interaction` (§4.3); `label*`
476
+ became a zone theme;
477
+ - `disabled/disabledContent` — disabled lives entirely in
478
+ `effects.interaction.disabled` (§4.3): it is a state-modifier of any zone,
479
+ not a zone of its own. Keeping it both as a colour pair and as an
480
+ `interaction` state would describe one concept twice.
481
+
482
+ ### 5.2. `shadows` — by zone of application, not by size
483
+
484
+ The old `small / medium / large` scale is **deleted**: it was a scale without
485
+ meaning — nobody knew which was which. Every reader has been migrated. A shadow
486
+ is now named only after the zone it applies to:
487
+
488
+ ```ts
489
+ shadows: {
490
+ section: string; // shadow of a resting surface: card, section, control
491
+ notification: string; // everything that floats ABOVE the page: modals, toasts, tooltips, dropdowns
492
+ content: string; // text-shadow of content: ink/blots (paper), text glow (viking)
493
+ }
494
+ ```
495
+
496
+ `notification` needs no documentation: it floats — take it. `content` is the
497
+ only shadow placed on `entityContent`, not on a surface. If a zone needs a
498
+ different shadow in another design, that is another theme, not a new
499
+ variable.
500
+
501
+ ### 5.3. `effects` — universal browser mechanisms only
502
+
503
+ `texture` and `interaction` are done right: they are basic things that exist
504
+ in any browser (a surface texture and element states). They stay, and
505
+ `interaction` gains the full set of states.
506
+
507
+ `texture` is **one CSS value**: the surface texture the theme paints
508
+ (`url(...)`, a gradient, a `blur(...)` for a glass theme) or `'none'` (the CSS
509
+ default). A component attaches it to the property that makes sense for that
510
+ theme — `background-image` for a paper/noise texture, `backdrop-filter` for a
511
+ glass theme (§4.1). Whether the value is legal for the property it reaches is
512
+ not the type's question: the linter's generic resolver checks it per theme
513
+ (§5.6).
514
+
515
+ ```ts
516
+ effects: {
517
+ texture: string; // one complete texture value, or 'none'
518
+ interaction: {
519
+ hover: string; // a CSS fragment of the state
520
+ active: string;
521
+ focus: string;
522
+ disabled: string; // replaces the disabled/disabledContent pair (§5.1)
523
+ };
524
+ }
525
+ ```
526
+
527
+ `glow` and `depth` with their `soft/medium/strong/small` scales are hardcode
528
+ and go away:
529
+
530
+ - **glow** is not a separate effect but a shadow/glow **in the accent
531
+ colour**. The colour is already in the contract: `colors.highlighted`.
532
+ The glow is derived, not stored: `box-shadow: 0 0 Npx ${theme.colors.highlighted}`
533
+ (or `color-mix(in srgb, ${theme.colors.highlighted} 40%, transparent)` for
534
+ transparency). A theme wanting a different glow changes `highlighted` or
535
+ `interaction`, it does not breed `glow.soft/medium/strong`.
536
+ - **depth.inner** (an inset shadow, "pressed in") is either the
537
+ `interaction.active` state (a press) or a zone shadow (`shadows.section`
538
+ for a sunken input in a particular theme). No separate scale is needed.
539
+ - **depth.outer** is `shadows.section` / `shadows.notification` (§5.2).
540
+
541
+ Rule: an effect enters the contract only if it is a universal browser
542
+ mechanism (texture, state, zone shadow). Invented intensity scales — no.
543
+
544
+ ### 5.4. `geometry` — the silhouette and the imprint
545
+
546
+ What it was: `geometry.radius` duplicated `border.radius`; `ragged` was a
547
+ `clip-path` of a torn edge (viking parchment); `cut` was a `clip-path` with cut
548
+ corners (used by viking modals). `border.cut` (`'10px'`) was the cut size the
549
+ polygon was built from. The whole group was **the silhouette of an entity
550
+ surface**, smeared over three fields plus a radius duplicate.
551
+
552
+ The contract is two fields:
553
+
554
+ ```ts
555
+ type {
556
+ shape: string; // 'none' | polygon(...) | path(...) — the silhouette of any entity
557
+ imprint: string; // 'none' (empty) | a ready CSS fragment placed into ::before/::after
558
+ }
559
+ ```
560
+
561
+ `shape` — the silhouette itself. The name is `shape`, not `clipPath`: the
562
+ contract names the meaning (WHAT — the surface silhouette), not the CSS
563
+ mechanism (HOW — `clip-path`). The mechanism is a component/theme detail.
564
+
565
+ - `radius` lives only in `border.radius` (the duplicate is removed);
566
+ - `ragged` and `cut` are two special cases of one silhouette; a theme picks
567
+ one `shape` for its surfaces;
568
+ - the cut size (`border.cut`) is a parameter of shape **generation** inside a
569
+ theme, not a contract field; it belongs next to the silhouette, in the
570
+ theme that builds it.
571
+
572
+ `imprint` — **what the object imprints on its surroundings**: an engraved
573
+ outline, an inner frame, the trace the object leaves on itself. It is one ready
574
+ CSS fragment (declarations only, no selector) that a component places into a
575
+ `::before`/`::after` pseudo-element. `'none'` is the empty string — the
576
+ pseudo-element then carries no declarations. Semantics:
577
+
578
+ - the fragment is **theme DATA**, computed inside the theme from that theme's
579
+ own values (`geometry.shape`, `border.size`, `colors.highlighted`,
580
+ `colors.sectionContent`, `border.radius`). A theme may build it from its own
581
+ constants; a **component may not** — it only attaches `theme.geometry.imprint`
582
+ to the pseudo-element, nothing more;
583
+ - the fragment carries the geometry of the impression itself
584
+ (`content`, `position`, `inset`, `pointer-events: none`, `border`,
585
+ `border-radius`/`clip-path`, `opacity`), so the component stays shape-agnostic;
586
+ - it is decoration of the surface, not a shadow and not a border: those stay in
587
+ `shadows.*` and `border.*`.
588
+
589
+ A group with one or two fields is fine: empty "for the future" fields are
590
+ exactly the variable breeding §7 forbids. `border` stays: `radius` + `size` is
591
+ enough. If themes ever need another geometric characteristic, run the same
592
+ filter as for `effects` first:
593
+
594
+ 1. is it a **dimension** of the zone (width/height/aspect-ratio)? → `elements.*`, not geometry;
595
+ 2. is it a **border** property (rounding, thickness)? → `border.*`;
596
+ 3. is it **derivable** from what exists (a shape generation parameter, a formula)? → computed inside the theme, not stored;
597
+ 4. only an independent silhouette characteristic that really varies between
598
+ themes earns a new field in `geometry` — plus an update of this README.
599
+
600
+ ### 5.5. What we do not touch
601
+
602
+ `zIndex` (named layers), `border.radius/size`, `font` (families by purpose:
603
+ text/title — there is no `code` role, a code surface is a zone theme whose
604
+ `text` role is monospace — plus per-role `weight`/`transform` and the
605
+ typographic scale), `offsets` (semantic zones),
606
+ `variables` (numeric sources for CSS variables), `screens`, `elements` —
607
+ already follow the rules.
608
+
609
+ ### 5.6. Typed fields, resolved values
610
+
611
+ The contract has **no CSS-value types and no value lists**. Every CSS-bearing
612
+ field is a plain `string`/`number`; the compiler checks the theme's STRUCTURE
613
+ (which fields exist, which status keys are legal via `TStatus`/`StatusKeyOf`),
614
+ and the linter checks the VALUES.
615
+
616
+ - **TypeScript checks theme STRUCTURE.** `ThemeInterface` says which fields a
617
+ theme must declare (entity pairs, `geometry.shape`, `effects.texture`,
618
+ `effects.interaction.hover/active/focus/disabled`, the status map, …) and
619
+ which status keys a narrowed `DefaultTheme` allows. A missing field or an
620
+ unknown status key is a compile error. It deliberately says nothing about
621
+ the string inside a field.
622
+ - **CSS VALUES are validated by the architecture linter's generic resolver.**
623
+ Every CSS declaration carries a `resolution` fact: its raw text, every
624
+ concrete value it reaches after walking `var(--…)`, `calc(…)` and
625
+ `${theme.…}` expressions down to the bottom, labelled with the theme and
626
+ media variant each reading belongs to, plus the real CSS grammar's verdict
627
+ and anything the resolver could not resolve. ONE invariant
628
+ (`proper-css-values`, `architecture.yaml`) reports any declaration whose
629
+ resolution contains an invalid reading or an unresolved part. There is no
630
+ rule per property and no hardcoded value list: the grammar and the themes
631
+ themselves are the source of truth, per theme.
632
+
633
+ So a typo is caught where it becomes CSS — after the theme value is
634
+ substituted — and a theme is checked against every property a component feeds
635
+ it to. The negative TYPE proof for the structure lives in
636
+ `TestingErrors/type-safety.test.ts` (with `@ts-expect-error`, so an unused
637
+ directive fails the build); value-level proofs are the resolver's and the
638
+ linter's, not TypeScript's.
639
+
640
+ ## 6. How themes are componentised
641
+
642
+ A component folder stays flat and design-agnostic:
643
+
644
+ ```
645
+ Component/
646
+ index.tsx // logic and markup, knows nothing about the visual
647
+ styles.ts // styled-components reading ONLY theme-contract fields
648
+ index.md // usage docs
649
+ ```
650
+
651
+ `styles.ts` reads **only** the contract fields of §5 — entities
652
+ (`colors.section`/`sectionContent`, `highlighted`/`highlightedContent`),
653
+ `shadows.*`, `border.*`, `geometry.*`, `effects.*`, `font.*`, `offsets.*`,
654
+ `elements.*`, `zIndex.*`. It never branches on `theme.theme` and never contains
655
+ a per-theme fragment: there are **no `themes/` folders inside components** and
656
+ **no theme-name gates** (`theme.theme === 'viking' && …`) any more. That pattern
657
+ was the antipattern this rewrite removes — it turned every component into a
658
+ catalogue of designs and made a new design an edit in every folder.
659
+
660
+ Theme-specific decoration comes from **theme data**, not from component code:
661
+
662
+ - **silhouette and imprint** — `geometry.shape` gives the surface its outline;
663
+ `geometry.imprint` is a ready `::before`/`::after` fragment the component
664
+ attaches as-is (an engraved outline, a glass frame). The theme computed it
665
+ from its own values (§5.4), the component only attaches it.
666
+ - **texture and states** — `effects.texture` is the surface texture (`none`, a
667
+ `url`, a `blur`); `effects.interaction.hover/active/focus/disabled` are ready
668
+ state fragments the component attaches to `:hover`/`:active`/`:focus-visible`/
669
+ `:disabled`. A pressed-in look therefore lives ONLY in
670
+ `interaction.active`, never in the resting styles.
671
+ - **shadows by zone** — `shadows.section` for a resting surface,
672
+ `shadows.notification` for anything that floats above the page,
673
+ `shadows.content` for a text-shadow on `entityContent` (§5.2).
674
+ - **typographic roles** — `font.family/weight/transform.{text,title}` decide the
675
+ family, weight and casing per role; a component picks the role, not the font.
676
+
677
+ Tone/weight/size props (`$tone`, `$weight`, `$size`) are component semantics. A
678
+ tone maps onto the two contract pairs (`active` → `highlighted`, `passive` →
679
+ `section`) or onto a key of the application's open status map (§3.4); weight
680
+ and size map onto offsets. Never onto "colours in general".
681
+
682
+ ### Zone themes: one situation, one nested provider
683
+
684
+ When a **subtree** is a different design situation, it gets its own **zone
685
+ theme** — a complete `ThemeInterface` (`{ ...baseTheme, … }` at the definition
686
+ site, §2) — and a nested `ThemeProvider` switches the whole subtree onto it
687
+ (§2). The component stays
688
+ unchanged: it keeps reading `theme.font.family.text`, `theme.colors.section`,
689
+ etc.; only the provider above it changed.
690
+
691
+ The reference case is `packages/styles/themes/codeEditor.ts`: a code surface is
692
+ its own situation, so both of its font roles resolve to `monospace` (there is no
693
+ `code` family in the contract). `HtmlEditor` nests
694
+ `<ThemeProvider theme={codeEditor}>` around the editor surface only — the Save
695
+ button stays outside, because it is page UI, not part of the code zone:
696
+
697
+ ```tsx
698
+ <ThemeProvider theme={codeEditor}>
699
+ <CodeEditorContainer>
700
+ <CodeEditor />
701
+ </CodeEditorContainer>
702
+ </ThemeProvider>
703
+ <Button text="Save changes" onClick={onSave} />
704
+ ```
705
+
706
+ The component itself is untouched by the switch: `styles.ts` still reads
707
+ `theme.font.family.text`, which now resolves to monospace inside the zone.
708
+
709
+ ### The zone themes in the box
710
+
711
+ Every zone follows ONE rule — it changes values, never field names, and a deeper
712
+ surface is the SAME field one step deeper (`colors.section` under a panel that
713
+ sits on `colors.section`), so a component never learns that a zone exists.
714
+
715
+ | zone theme | the situation it dresses | what it changes |
716
+ | --- | --- | --- |
717
+ | `codeEditor` | a light, standalone editor | both font roles resolve to monospace |
718
+ | `codeBoard` | a code board on a dark page | dark surfaces (`colors.section` `#1e1f22`, `overlay` `#2b2d30`), a wash behind painted ranges, its own status map (`added`, `removed`, `changed`, `conflict`, …) |
719
+ | `pairTheme` | the comparison board of two to five code columns | inherits `codeBoard`: paper `#171f2e`, the panel one step deeper `#121722`, the lane ribbon and the editor inks |
720
+ | `reportTheme` | a dense report page of cards | page `colors.section` `#0b0e14`, raised cards `colors.overlay` `#171f2e`, hairline `status.edge`, focus `highlighted`, and its own status map (the hues, the chrome trio `edge`/`dim`/`faint`, `same`/`differs`) |
721
+ | `reportPanelTheme` | a card ON that page — what `atoms/Surface` nests when it is given a `theme` | `reportTheme` with `colors.section` one step deeper (`#121722`); every other field identical |
722
+
723
+ `reportPanelTheme` is the rule in its purest form: it is `reportTheme` with ONE
724
+ field one step deeper, so a card's children read `colors.section` and get the
725
+ card's colour without naming the card.
726
+
727
+ ## 7. Checklist: a new variable or a new theme?
728
+
729
+ Before adding anything to `types.ts`:
730
+
731
+ 1. Is it a new **visual variant** of an existing zone? → a **THEME** (a new
732
+ file in `themes/` or a nested `ThemeProvider`), no new variables. A
733
+ **status** is neither: it is a key of the application's open `colors.status`
734
+ map (§3.4) — the design system stores none of it.
735
+ 2. Is it a **state** (hover/active/focus/disabled/selected)? →
736
+ `effects.interaction` or a derivative of an entity pair, not a new colour.
737
+ 3. Is it **derivable** from what exists (a formula, `calc`, `color-mix`, a
738
+ multiple of the rhythm)? → compute it, do not store it.
739
+ 4. Is it a genuinely **new zone of application** missing from the §3.3
740
+ catalog and inexpressible as a theme? → only then a new
741
+ `entity/entityContent` pair with a zone name. Update the catalog in this
742
+ README.
743
+ 5. Does the name pass the "WHERE, not WHAT" check? No `red`, `primary`,
744
+ `brand`, `small/medium/large` for zones.
745
+
746
+ Every extra variable is a new `switch` in every component and a new case in
747
+ every test. Every new theme is zero component edits.
748
+
749
+ ## 8. Why: testing
750
+
751
+ A component depends on a **fixed narrow contract**, not on a design:
752
+
753
+ - a component is tested once: layout, semantics, pair attachment
754
+ (`section → sectionContent`), state attachment. A design change does not
755
+ break its tests;
756
+ - themes are tested separately and cheaply: a snapshot/visual run of the same
757
+ component set under every theme (`paper`, `minimal`, `viking`,
758
+ `liquidGlass`) and under different `colors.status` maps; their values are
759
+ already validated by the compiler (§5.6), so a visual run never debugs a
760
+ non-existent CSS value;
761
+ - the hardcode ban in components (§4, §6) guarantees all the painting lives
762
+ in themes — and is verified there.
763
+
764
+ If a component cannot be tested without knowing a concrete design, hardcode
765
+ has leaked into the component and must go back into a theme.
766
+
767
+ ---
768
+
769
+ ## Repository
770
+
771
+ - GitHub: <https://github.com/DrBoria/md-styled>
772
+ - Licence: Apache-2.0 (`LICENSE`).