basalt-ui 1.1.1 → 1.3.0

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 (191) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +46 -0
  3. package/README.md +64 -8
  4. package/agent/rules/basalt-app.md +126 -0
  5. package/agent/rules/basalt-content.md +3 -1
  6. package/agent/rules/basalt-tokens.md +14 -5
  7. package/agent/skills/basalt-app/SKILL.md +28 -7
  8. package/dist/agent/part-list.d.ts.map +1 -1
  9. package/dist/agent/part-list.js +17 -7
  10. package/dist/agent/stick-to-bottom.js +2 -2
  11. package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
  12. package/dist/agent-chat/thread-detail-panel.js +37 -33
  13. package/dist/agent-chat/thread-message.d.ts.map +1 -1
  14. package/dist/agent-chat/thread-message.js +8 -5
  15. package/dist/agent-chat/thread-outcome-card.js +3 -3
  16. package/dist/agent-chat/thread-workspace.js +1 -1
  17. package/dist/charts/primitives/ChartLegend.js +2 -0
  18. package/dist/charts/primitives/ChartTooltip.js +2 -1
  19. package/dist/cli/index.d.ts +29 -0
  20. package/dist/cli/index.d.ts.map +1 -1
  21. package/dist/cli/index.js +80 -9
  22. package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
  23. package/dist/connectivity/connectivity-indicator.js +3 -3
  24. package/dist/content/article-card.module.css +7 -5
  25. package/dist/content/article-layout.module.css +16 -12
  26. package/dist/content/callout.module.css +4 -4
  27. package/dist/content/code-block.module.css +8 -7
  28. package/dist/content/guide.module.css +3 -3
  29. package/dist/content/mermaid.module.css +2 -2
  30. package/dist/content/prose.module.css +59 -29
  31. package/dist/content/reading-progress.module.css +2 -0
  32. package/dist/content/toc.module.css +6 -3
  33. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  34. package/dist/dashboard/delta-badge.js +10 -2
  35. package/dist/dashboard/empty-state.d.ts.map +1 -1
  36. package/dist/dashboard/empty-state.js +3 -16
  37. package/dist/dashboard/settings-section.js +2 -2
  38. package/dist/dashboard/settings-section.module.css +2 -2
  39. package/dist/dashboard/stat-card.js +2 -1
  40. package/dist/data/virtual-list.d.ts.map +1 -1
  41. package/dist/data/virtual-list.js +12 -2
  42. package/dist/forms/FormErrorSummary.js +2 -2
  43. package/dist/guard/index.d.ts +20 -4
  44. package/dist/guard/index.d.ts.map +1 -1
  45. package/dist/guard/index.js +266 -38
  46. package/dist/guard/types.d.ts +24 -3
  47. package/dist/guard/types.d.ts.map +1 -1
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/provider/index.d.ts +30 -1
  51. package/dist/provider/index.d.ts.map +1 -1
  52. package/dist/provider/index.js +32 -7
  53. package/dist/provider/lab-theme.d.ts +39 -0
  54. package/dist/provider/lab-theme.d.ts.map +1 -0
  55. package/dist/provider/lab-theme.js +52 -0
  56. package/dist/shell/app-header.module.css +2 -2
  57. package/dist/shell/app-mobile-nav.module.css +1 -1
  58. package/dist/shell/app-sidebar-account.d.ts.map +1 -1
  59. package/dist/shell/app-sidebar-account.js +4 -2
  60. package/dist/shell/app-sidebar.d.ts.map +1 -1
  61. package/dist/shell/app-sidebar.js +4 -2
  62. package/dist/shell/app-sidebar.module.css +36 -26
  63. package/dist/shell/index.d.ts.map +1 -1
  64. package/dist/shell/index.js +11 -4
  65. package/dist/shell/sidebar-search.module.css +16 -4
  66. package/dist/styles.css +22 -11
  67. package/dist/surfaces.d.ts +21 -11
  68. package/dist/surfaces.d.ts.map +1 -1
  69. package/dist/surfaces.js +10 -3
  70. package/dist/theme/controls.module.css +1 -1
  71. package/dist/theme/floating.module.css +1 -1
  72. package/dist/theme/index.d.ts +116 -11
  73. package/dist/theme/index.d.ts.map +1 -1
  74. package/dist/theme/index.js +703 -566
  75. package/dist/theme/nav-link.module.css +1 -1
  76. package/dist/theme/use-basalt-spacing.d.ts +3 -0
  77. package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
  78. package/dist/theme/use-basalt-spacing.js +8 -0
  79. package/dist/theme-lab/derive-controls.d.ts +13 -0
  80. package/dist/theme-lab/derive-controls.d.ts.map +1 -0
  81. package/dist/theme-lab/derive-controls.js +137 -0
  82. package/dist/theme-lab/derive-state.d.ts +55 -0
  83. package/dist/theme-lab/derive-state.d.ts.map +1 -0
  84. package/dist/theme-lab/derive-state.js +81 -0
  85. package/dist/theme-lab/index.d.ts +12 -2
  86. package/dist/theme-lab/index.d.ts.map +1 -1
  87. package/dist/theme-lab/index.js +13 -62
  88. package/dist/theme-toggle/index.d.ts.map +1 -1
  89. package/dist/theme-toggle/index.js +3 -2
  90. package/dist/tokens/derive.d.ts +89 -0
  91. package/dist/tokens/derive.d.ts.map +1 -0
  92. package/dist/tokens/derive.js +250 -0
  93. package/dist/tokens/hct.d.ts +34 -0
  94. package/dist/tokens/hct.d.ts.map +1 -0
  95. package/dist/tokens/hct.js +159 -0
  96. package/dist/tokens/index.d.ts +143 -7
  97. package/dist/tokens/index.d.ts.map +1 -1
  98. package/dist/tokens/index.js +322 -48
  99. package/dist/tokens/palette.d.ts +984 -167
  100. package/dist/tokens/palette.d.ts.map +1 -1
  101. package/dist/tokens/palette.js +617 -119
  102. package/dist/tokens.css +248 -0
  103. package/dist/vite-color-mix.d.ts +30 -0
  104. package/dist/vite-color-mix.d.ts.map +1 -0
  105. package/dist/vite-color-mix.js +80 -0
  106. package/dist/vite.d.ts +82 -1
  107. package/dist/vite.d.ts.map +1 -1
  108. package/dist/vite.js +312 -0
  109. package/llms.txt +14 -4
  110. package/package.json +41 -10
  111. package/src/agent/part-list.tsx +13 -7
  112. package/src/agent/stick-to-bottom.tsx +2 -2
  113. package/src/agent-chat/thread-detail-panel.tsx +13 -10
  114. package/src/agent-chat/thread-message.tsx +8 -5
  115. package/src/agent-chat/thread-outcome-card.tsx +2 -2
  116. package/src/agent-chat/thread-workspace.tsx +2 -2
  117. package/src/charts/primitives/ChartLegend.tsx +2 -2
  118. package/src/charts/primitives/ChartTooltip.tsx +2 -2
  119. package/src/cli/check-theme.test.ts +18 -0
  120. package/src/cli/index.ts +129 -6
  121. package/src/cli/tokens-css.test.ts +90 -0
  122. package/src/connectivity/connectivity-indicator.tsx +8 -2
  123. package/src/content/article-card.module.css +7 -5
  124. package/src/content/article-layout.module.css +16 -12
  125. package/src/content/callout.module.css +4 -4
  126. package/src/content/code-block.module.css +8 -7
  127. package/src/content/guide.module.css +3 -3
  128. package/src/content/mermaid.module.css +2 -2
  129. package/src/content/prose.module.css +59 -29
  130. package/src/content/prose.module.css.test.ts +55 -0
  131. package/src/content/reading-progress.module.css +2 -0
  132. package/src/content/toc.module.css +6 -3
  133. package/src/dashboard/delta-badge.tsx +10 -4
  134. package/src/dashboard/empty-state.tsx +3 -16
  135. package/src/dashboard/settings-section.module.css +2 -2
  136. package/src/dashboard/settings-section.tsx +2 -2
  137. package/src/dashboard/stat-card.tsx +2 -2
  138. package/src/data/virtual-list.tsx +12 -2
  139. package/src/forms/FormErrorSummary.tsx +1 -1
  140. package/src/guard/check-source.test.ts +483 -15
  141. package/src/guard/index.ts +426 -47
  142. package/src/guard/types.ts +24 -2
  143. package/src/index.ts +1 -0
  144. package/src/provider/index.test.tsx +100 -0
  145. package/src/provider/index.tsx +79 -7
  146. package/src/provider/lab-theme.test.ts +147 -0
  147. package/src/provider/lab-theme.ts +166 -0
  148. package/src/shell/app-header.module.css +2 -2
  149. package/src/shell/app-mobile-nav.module.css +1 -1
  150. package/src/shell/app-sidebar-account.tsx +9 -2
  151. package/src/shell/app-sidebar.module.css +36 -26
  152. package/src/shell/app-sidebar.tsx +12 -2
  153. package/src/shell/index.tsx +14 -3
  154. package/src/shell/sidebar-search.module.css +16 -4
  155. package/src/styles.css +22 -11
  156. package/src/surfaces.ts +24 -10
  157. package/src/theme/contrast.test.ts +19 -3
  158. package/src/theme/controls.module.css +1 -1
  159. package/src/theme/density-option.test.ts +96 -0
  160. package/src/theme/density-relations.test.ts +428 -0
  161. package/src/theme/derive-theme.test.ts +101 -0
  162. package/src/theme/floating.module.css +1 -1
  163. package/src/theme/fonts-option.test.ts +69 -0
  164. package/src/theme/index.ts +930 -563
  165. package/src/theme/nav-link.module.css +1 -1
  166. package/src/theme/radius-option.test.ts +86 -0
  167. package/src/theme/radius.test.ts +132 -0
  168. package/src/theme/spacing.test.ts +432 -0
  169. package/src/theme/use-basalt-spacing.test.tsx +51 -0
  170. package/src/theme/use-basalt-spacing.ts +38 -0
  171. package/src/theme-lab/derive-controls.test.ts +94 -0
  172. package/src/theme-lab/derive-controls.tsx +227 -0
  173. package/src/theme-lab/derive-state.test.ts +71 -0
  174. package/src/theme-lab/derive-state.ts +163 -0
  175. package/src/theme-lab/index.tsx +29 -68
  176. package/src/theme-lab/theme-lab.test.ts +4 -18
  177. package/src/theme-toggle/index.tsx +9 -4
  178. package/src/tokens/build-fonts-css.test.ts +51 -0
  179. package/src/tokens/build-radius-css.test.ts +25 -0
  180. package/src/tokens/density.test.ts +274 -0
  181. package/src/tokens/derive-radius.test.ts +62 -0
  182. package/src/tokens/derive.test.ts +30 -0
  183. package/src/tokens/derive.ts +481 -0
  184. package/src/tokens/hct.ts +231 -0
  185. package/src/tokens/index.ts +534 -48
  186. package/src/tokens/palette.test.ts +114 -0
  187. package/src/tokens/palette.ts +1118 -180
  188. package/src/vite-color-mix.test.ts +46 -0
  189. package/src/vite-color-mix.ts +137 -0
  190. package/src/vite.test.ts +192 -0
  191. package/src/vite.ts +502 -1
@@ -4,10 +4,10 @@
4
4
  *
5
5
  * Identity: modern zinc (2026-07 redesign, see `docs/DESIGN-SPEC.md`). Cool-neutral zinc surfaces
6
6
  * (Tailwind zinc family) — a low-contrast panel lift on a slightly darker page, depth via a
7
- * whisper `shadow-card` (never a hairline-only border), and ONE saturated sky-blue accent
8
- * (#0077bd light / #8ec5ff dark) used with intent (primary series, active-nav icon, links, primary
9
- * actions, focus rings, meter leaders) — chrome stays zinc-neutral otherwise. Status hues stay
10
- * UI-tuned (muted, not raw Material/AntD/Tailwind defaults).
7
+ * whisper `shadow-card` (never a hairline-only border), and ONE saturated sky-blue accent used
8
+ * with intent (primary series, active-nav icon, links, primary actions, focus rings, meter
9
+ * leaders) — chrome stays zinc-neutral otherwise. Status hues stay UI-tuned (muted, not raw
10
+ * Material/AntD/Tailwind defaults).
11
11
  *
12
12
  * Design rules baked in (see `docs/DESIGN-SPEC.md`):
13
13
  * - Neutral zinc greys carry ~90% of the surface — chrome is monochrome, accent only points.
@@ -20,8 +20,17 @@
20
20
  *
21
21
  * This module is pure data — no React, no Mantine, no browser APIs. It is consumed by
22
22
  * the token layer (emits the CSS custom properties) and by the Mantine theme.
23
+ *
24
+ * GENERATED vs hand-authored: the accent family, the 12 categorical fills, the surface stops
25
+ * (bg/panel/panelHover/elevated/subtle/field/border/hairline), the ink ramp, and the status
26
+ * solids are COMPUTED at module load from `deriveTokens(DEFAULT_DERIVE_CONFIG)` (`./derive.ts`) —
27
+ * never hand-edit a hex for one of those; retune the derive config or its calibrated constants
28
+ * instead. Everything else here (shadows, dividers, tooltip chrome, the raw `BP` hue ramps,
29
+ * `STATUS.excellent`/`STATUS.neutral`) stays hand-authored, unchanged.
23
30
  */
24
31
 
32
+ import { DEFAULT_DERIVE_CONFIG, deriveTokens, isDefaultDeriveConfig } from './derive'
33
+ import type { DeriveConfig } from './derive'
25
34
  import type { ColorPair } from './index'
26
35
 
27
36
  /**
@@ -80,209 +89,1138 @@ export const p = (fam: readonly string[], light = 2, dark = 3): ColorPair => ({
80
89
  dark: fam[dark]!,
81
90
  })
82
91
 
83
- /** Spec status hues (`docs/DESIGN-SPEC.md` §2) — exact, shared by SEMANTIC + STATUS below. */
84
- const SUCCESS: ColorPair = { light: '#2f7a4f', dark: '#56c07a' }
85
- const WARNING: ColorPair = { light: '#b5750f', dark: '#e0a83a' }
86
- const DANGER: ColorPair = { light: '#b53f3f', dark: '#e0685f' }
92
+ /**
93
+ * Card / control depth shadows (`docs/DESIGN-SPEC.md` §2) — depth is a whisper shadow + a 1px
94
+ * ring baked into the SAME value (never a separate `border`). The ring embeds
95
+ * `var(--vx-surface-hairline)` so it stays single-sourced against the hairline pair below.
96
+ * Structural — independent of the derive config, unlike everything `buildPaletteData` below emits.
97
+ */
98
+ export const SHADOW = {
99
+ card: {
100
+ light: '0 1px 2px rgba(28,25,23,0.05), 0 0 0 1px var(--vx-surface-hairline)',
101
+ dark: '0 1px 3px rgba(0,0,0,0.4), inset 0 0 0 1px color-mix(in srgb, #ffffff 4%, transparent)',
102
+ },
103
+ ctrl: {
104
+ light: '0 1px 2px rgba(28,25,23,0.12)',
105
+ dark: '0 1px 2px rgba(0,0,0,0.35)',
106
+ },
107
+ // Floating-layer elevation (menus, popovers, tooltips, modals, drawers) — a REAL drop shadow, a
108
+ // step above `card`, so detached surfaces read as lifted off the page (`docs/DESIGN-SPEC.md` §5).
109
+ // Unlike `card`, no embedded ring: floating surfaces carry a real 1px `--vx-surface-border` so
110
+ // Mantine's rotated-square arrow inherits a proper edge.
111
+ overlay: {
112
+ light: '0 8px 24px rgba(28,25,23,0.10)',
113
+ dark: '0 8px 24px rgba(0,0,0,0.5)',
114
+ },
115
+ } as const
116
+
117
+ /**
118
+ * The resolved shape {@link deriveRadius} returns — the two anchors plus every offset that tracks
119
+ * one of them. The independent Mantine-scale stops (`scaleXs`/`scaleLg`/`scaleXl`) are NOT part of
120
+ * this shape — they never move with the knob (see `RADIUS_STEP` below).
121
+ */
122
+ export type RadiusValues = {
123
+ card: number
124
+ ctrl: number
125
+ floating: number
126
+ tight: number
127
+ fine: number
128
+ }
129
+
130
+ /** Clamp a derived radius number at zero — a corner radius can't go negative. */
131
+ function clampRadius(n: number): number {
132
+ return Math.max(0, n)
133
+ }
134
+
135
+ /** `deriveRadius`'s accepted level range — exported (not through the `./tokens` barrel, same
136
+ * precedent as {@link scaleSpace}) so a cross-level test can derive the levels it loops over from
137
+ * the SAME bound `deriveRadius` enforces, instead of a hardcoded literal that silently stops
138
+ * covering the real range if the range ever changes again. */
139
+ export const RADIUS_LEVEL_RANGE = { min: -5, max: 5 } as const
87
140
 
88
- /** Semantic status hues — solids + the family they fill from (alpha applied in the token layer). */
89
- export const SEMANTIC = {
90
- good: SUCCESS,
91
- bad: DANGER,
92
- warn: WARNING,
141
+ /**
142
+ * Derive the two radius anchors (`card`/`ctrl`) and their dependent offsets from a single integer
143
+ * `level` (`docs/DESIGN-SPEC.md` §4) — the radius analog of `deriveTokens`'s color knobs. `level: 0`
144
+ * reproduces the shipped identity exactly (`card: 7, ctrl: 6, floating: 8, tight: 5, fine: 4`,
145
+ * locked by `theme/radius.test.ts`).
146
+ *
147
+ * The law: `card = 7 + level`, `ctrl = 6 + level`, both clamped to `≥ 0`; every offset then follows
148
+ * its anchor — `floating = card + 1`, `tight = ctrl - 1`, `fine = ctrl - 2` — each ALSO clamped to
149
+ * `≥ 0` (so an aggressive negative level flattens the smaller tiers to square before the larger
150
+ * ones). The three independent Mantine-scale stops (`RADIUS_STEP.scaleXs/scaleLg/scaleXl`) are not
151
+ * part of this law — they stay fixed regardless of `level`.
152
+ *
153
+ * Throws on a non-integer or out-of-range (`[-5, 5]`) level — same throw-and-propagate discipline
154
+ * as `deriveTokens`'s accent-seed validation.
155
+ */
156
+ export function deriveRadius(level: number): RadiusValues {
157
+ if (
158
+ !Number.isInteger(level) ||
159
+ level < RADIUS_LEVEL_RANGE.min ||
160
+ level > RADIUS_LEVEL_RANGE.max
161
+ ) {
162
+ throw new Error(
163
+ `deriveRadius: level must be an integer in [${RADIUS_LEVEL_RANGE.min}, ${RADIUS_LEVEL_RANGE.max}], got ${level}`,
164
+ )
165
+ }
166
+ const card = clampRadius(7 + level)
167
+ const ctrl = clampRadius(6 + level)
168
+ return {
169
+ card,
170
+ ctrl,
171
+ floating: card + 1,
172
+ tight: clampRadius(ctrl - 1),
173
+ fine: clampRadius(ctrl - 2),
174
+ }
175
+ }
176
+
177
+ /** `deriveRadius(0)` — the shipped identity's radius values, computed once. `RADIUS`/`RADIUS_STEP`
178
+ * below are defined FROM this so the two can never drift apart. */
179
+ const DEFAULT_RADIUS_VALUES = deriveRadius(0)
180
+
181
+ /**
182
+ * Corner-radius anchors (`docs/DESIGN-SPEC.md` §4) — the two independent tiers the Mantine theme
183
+ * (`theme/index.ts`) resolves every component radius to. `card` mirrors the `--vx-radius-card` CSS
184
+ * var, `ctrl` mirrors `--vx-radius-ctrl` (`tokens/index.ts`'s `frameworkDerived` emits both from
185
+ * these SAME numbers), so the var and every JS `defaultProps.radius` in the theme read one source
186
+ * instead of two that can drift apart. `deriveRadius(0)`'s output — structural, independent of the
187
+ * derive config. Values are UNCHANGED from the shipped identity (locked by `theme/radius.test.ts`).
188
+ */
189
+ export const RADIUS = {
190
+ /** Card / Paper / `ChartCard` (Mantine-free chart chrome shares this token too). */
191
+ card: DEFAULT_RADIUS_VALUES.card,
192
+ /** Inputs, buttons, segmented-control track — also `defaultRadius: 'md'` in the Mantine `radius`
193
+ * size-scale below. */
194
+ ctrl: DEFAULT_RADIUS_VALUES.ctrl,
93
195
  } as const
94
196
 
95
197
  /**
96
- * Score / zone status scale (excellent → poor). `good`/`warn`/`bad` are the SAME spec
97
- * success/warning/danger pairs as `SEMANTIC` (also the direct source for Badge/Notification/delta
98
- * -badge status-tint idioms in the theme — one set of hexes, several consumers). `excellent`
99
- * (top-of-scale grade) and `neutral` keep their prior chart-only families (unchanged BP families).
198
+ * Every OTHER radius number the Mantine theme resolves to a literal, named instead of bare. Each
199
+ * key is either an explicit offset from a `RADIUS` anchor (named for what tier it belongs to — see
200
+ * `deriveRadius` for the law that carries a retune along) or, where no such relation exists, its own
201
+ * independent constant (the Mantine `radius` scale predates the card/ctrl split). `deriveRadius(0)`'s
202
+ * output for the anchor-derived keys — UNCHANGED from the shipped identity (locked by
203
+ * `theme/radius.test.ts`).
100
204
  */
101
- export const STATUS = {
102
- excellent: p(BP.forest),
103
- good: SUCCESS,
104
- warn: WARNING,
105
- bad: DANGER,
106
- neutral: p(BP.gray, 1, 2),
205
+ export const RADIUS_STEP = {
206
+ /** Tooltip / Popover / Modal / Notification (`docs/DESIGN-SPEC.md` §5 floating tier) — one step
207
+ * above the card radius. */
208
+ floating: DEFAULT_RADIUS_VALUES.floating, // 8
209
+ /** SegmentedControl's active indicator, Kbd, Code — one step below the control radius. */
210
+ tight: DEFAULT_RADIUS_VALUES.tight, // 5
211
+ /** Progress bar, and the Mantine scale's `sm` step — two steps below the control radius. */
212
+ fine: DEFAULT_RADIUS_VALUES.fine, // 4
213
+ /** The Mantine `radius` scale's `xs` step — independent of both anchors. */
214
+ scaleXs: 2,
215
+ /** The Mantine `radius` scale's `lg` step — independent of both anchors. */
216
+ scaleLg: 16,
217
+ /** The Mantine `radius` scale's `xl` step — independent of both anchors. */
218
+ scaleXl: 32,
219
+ /** Fully-rounded pill affordance (scroll-to-bottom button, chips). Fixed — a pill reads round at
220
+ * any radius level, so it does not track the knob (like the scale stops above). */
221
+ pill: 9999,
107
222
  } as const
108
223
 
109
224
  /**
110
- * Theme-resolved neutrals (line / axis / grid / tooltip chrome). Mirrors the old
111
- * useVxTheme() outputs, retuned to the zinc identity — the light-scheme opacity bases below use
112
- * the new `ink` rgb (38,38,38 = #262626) rather than the old warm near-black, so chart chrome
113
- * reads on the same cool-neutral ink as the rest of the chrome.
225
+ * The shared level-0 control-height number — Mantine's own `--input-height-md`/`--button-height-md`
226
+ * both resolve to `2.625rem` (42px at the 16px root), and `--ai-size-input-md` matches too. `SPACE_
227
+ * ANCHORS_BASE.controlHeight`/`.inputHeight` below both read THIS one constant (not two independent
228
+ * literals) so a control paired with a `size="md"` Input can never drift from it, no matter how
229
+ * either key is retuned later — see `controlHeight`'s doc for the anchor this fixes.
114
230
  */
115
- export const NEUTRAL = {
116
- line: { light: BP.gray[0], dark: BP.gray[4] }, // primary line
117
- line2: { light: BP.gray[1], dark: BP.gray[2] }, // secondary line
118
- axis: { light: 'rgba(38,38,38,0.6)', dark: 'rgba(255,255,255,0.6)' },
119
- axisStroke: { light: 'rgba(38,38,38,0.12)', dark: 'rgba(255,255,255,0.12)' },
120
- grid: { light: 'rgba(38,38,38,0.07)', dark: 'rgba(255,255,255,0.06)' },
121
- crosshair: { light: 'rgba(38,38,38,0.32)', dark: 'rgba(255,255,255,0.42)' },
122
- dotStroke: { light: BP.white, dark: BP.darkGray[1] }, // matches chart-area bg
123
- tooltipBg: { light: BP.white, dark: 'rgba(39,39,42,0.96)' },
124
- tooltipText: { light: 'rgba(38,38,38,0.88)', dark: 'rgba(255,255,255,0.88)' },
125
- tooltipMuted: { light: 'rgba(38,38,38,0.5)', dark: 'rgba(255,255,255,0.5)' },
126
- tooltipBorder: { light: `1px solid ${BP.lightGray[1]}`, dark: 'none' },
127
- tooltipShadow: { light: '0 2px 8px rgba(38,38,38,0.1)', dark: '0 2px 8px rgba(0,0,0,0.35)' },
128
- // Base neutral for hairlines / muted / DIMMED text / overlays — apply opacity via alpha().
129
- // Binds to --mantine-color-dimmed, so it is THE dimmed-text lever. Equal to `INK.muted` (the
130
- // spec's "muted (secondary text)" row) — kept as its own pair for the pre-existing `--vx-neutral`
131
- // name (never renamed), while `INK.muted` below is the new explicit spec-named token.
132
- neutral: { light: '#525252', dark: '#d4d4d4' },
231
+ const CONTROL_HEIGHT_BASE = 42
232
+
233
+ /**
234
+ * Density-tracking semantic spacing anchors — the values {@link deriveSpacing}'s `level` knob
235
+ * retunes together, the spacing analog of `RADIUS` above. Frequency-audited from the component
236
+ * sweep: `rowInsetX`/`rowInsetY` are the `6px 10px` row inset that appears verbatim in 4 places
237
+ * (NavLink root, Menu item), `stackXs`..`stackXl` are the 4px vertical rhythm (rebuilt from ONE
238
+ * scaled unit at non-zero levels — see {@link deriveSpacing}'s doc for why), and `inputHeight`/
239
+ * `controlHeight` are a `size: 'md'` Mantine Input's/Button's/ActionIcon's resolved height
240
+ * (Mantine's own default: `2.625rem` = 42px at the 16px root) — re-pointed onto `--vx-space-input-
241
+ * height`/`--vx-space-control-height` by `theme/index.ts`'s `Input.extend`/`Button.extend`/
242
+ * `ActionIcon.extend` `vars` (see `Input.extend`'s doc comment for why `--input-height`/`--button-
243
+ * height`/`--ai-size`, not `size`, is the override point). `tokens/index.ts`'s `frameworkDerived`
244
+ * emits each of these as a `--vx-space-*` CSS var from these SAME numbers, and `theme/index.ts`
245
+ * re-points its NavLink/Menu/Input/Button/ActionIcon geometry onto that var, so the var and every
246
+ * JS default read one source instead of two that can drift apart. This is the BASE (level-0) table
247
+ * {@link deriveSpacing} scales from.
248
+ */
249
+ const SPACE_ANCHORS_BASE = {
250
+ /** Horizontal inset of a nav/menu row (NavLink root, Menu item). */
251
+ rowInsetX: 10,
252
+ /** Vertical inset of a nav/menu row (NavLink root, Menu item). */
253
+ rowInsetY: 6,
254
+ /** The 4px vertical rhythm's tightest step. Rebuilt from a single scaled unit at non-zero levels
255
+ * (see {@link deriveSpacing}'s doc) — this literal is the level-0 reference only. */
256
+ stackXs: 4,
257
+ /** The 4px vertical rhythm, 2nd step — always `2 * stackXs` (see {@link deriveSpacing}'s doc). */
258
+ stackSm: 8,
259
+ /** The 4px vertical rhythm, 3rd step — always `3 * stackXs`. (It USED to coincide with
260
+ * `SPACE_SCALE.sm` at level 0; the component-roominess retune moved the scale off the rhythm, which
261
+ * is exactly the independence that constant's doc describes.) */
262
+ stackMd: 12,
263
+ /** The 4px vertical rhythm, 4th step — always `4 * stackXs`. */
264
+ stackLg: 16,
265
+ /** The 4px vertical rhythm's widest step — always `6 * stackXs`. */
266
+ stackXl: 24,
267
+ /** A `size: 'md'` Mantine Input's resolved height (see the group doc above). */
268
+ inputHeight: CONTROL_HEIGHT_BASE,
269
+ /** A `size: 'md'` Mantine Button's/ActionIcon's resolved height — the SAME number as `inputHeight`
270
+ * (both read {@link CONTROL_HEIGHT_BASE}), so a Button/ActionIcon placed beside a `size="md"`
271
+ * Input tracks it at every density level instead of only coinciding at level 0 (the defect this
272
+ * anchor fixes — Mantine's own `--button-height-md`/`--ai-size` are static, density-blind). */
273
+ controlHeight: CONTROL_HEIGHT_BASE,
133
274
  } as const
134
275
 
135
- /** Ink text ramp (`docs/DESIGN-SPEC.md` §2) — primary/emphasis/secondary/tertiary body text. */
136
- export const INK = {
137
- ink: { light: '#262626', dark: '#e5e5e5' }, // primary text
138
- ink2: { light: '#404040', dark: '#dddddd' }, // emphasis body
139
- muted: { light: '#525252', dark: '#d4d4d4' }, // secondary text (= NEUTRAL.neutral)
140
- faint: { light: '#737373', dark: '#a1a1a1' }, // tertiary text / micro-labels
276
+ /**
277
+ * The Mantine `spacing` size-scale (`xs`/`sm`/`md`/`lg`/`xl`) — the app-wide generic rhythm every
278
+ * `p=`/`m=`/`gap=` prop in every consumer resolves through. Density-tracking, like
279
+ * `SPACE_ANCHORS_BASE` above, but deliberately a SEPARATE group — and, since the
280
+ * component-roominess retune, no longer even numerically coincident with one. (`xs`/`sm`/`md`/`xl`
281
+ * used to equal `rowInsetX`/`stackMd`/`stackLg`/`stackXl`; that was a past density pass landing
282
+ * there, never a law, and this group moving alone is the proof.) An anchor is a SPECIFIC
283
+ * component's inset (NavLink/Menu row padding); a scale stop is the GENERIC scale every layout call
284
+ * site reads. Coupling them would mean retuning a nav row's inset silently reshapes every `p="xs"`
285
+ * app-wide, and {@link deriveSpacing} could never move the two at different rates if they were
286
+ * merged — the same reason `RADIUS_STEP.scaleXs`/`scaleLg`/`scaleXl` stay independent of `RADIUS`
287
+ * even though `radius.md` happens to also equal `RADIUS.ctrl` (that one IS a documented law: the
288
+ * control tier IS the `md` stop, hence `defaultRadius: 'md'` — no such relation exists here). Base
289
+ * table for {@link deriveSpacing}.
290
+ */
291
+ const SPACE_SCALE_BASE = {
292
+ xs: 11,
293
+ sm: 13,
294
+ md: 18,
295
+ lg: 20,
296
+ xl: 26,
141
297
  } as const
142
298
 
143
299
  /**
144
- * The one saturated sky-blue accent. It has TWO roles, and they are DIFFERENT COLORS — conflating
145
- * them is what made dark mode unfixable.
300
+ * Density-tracking, genuine one-offs — named insets that fit neither the anchor vertical rhythm/
301
+ * row inset nor the generic scale rhythm above. Unlike `RADIUS_STEP`'s independent scale stops,
302
+ * these DO track density; they are simply each their own single-use anchor, not part of either
303
+ * group above. Base table for {@link deriveSpacing} — level 0 is UNCHANGED from the shipped
304
+ * identity (locked by `theme/spacing.test.ts`).
146
305
  *
147
- * • `accent` — the accent as INK: link text, active-nav icon, chart lines, focus ring. It is read
148
- * AGAINST THE PAGE, so it must be LIGHT on dark (`#8ec5ff`, 8.64:1 on the dark page) and DEEP on
149
- * light (`#0077bd`, 4.60:1 on the light page). This pair inverts across schemes, as it must.
306
+ * Extended by the CSS-module spacing sweep (`docs/STATUS.md`) — every hardcoded spacing literal in
307
+ * `src/**\/*.module.css` now resolves through one of these named one-offs (or a `SPACE`/`SPACE_SCALE`
308
+ * anchor above, reused where a site is genuinely that concept — e.g. `SPACE.rowInsetX` reused for
309
+ * the sidebar frame/search/section-band/footer-row horizontal inset, `SPACE.stackXs/Sm/Md/Xl` reused
310
+ * for Prose/Callout/ArticleCard vertical-rhythm margins that land exactly on the 4px grid). Two or
311
+ * more sites sharing one entry below means they must render at the SAME value for a structural
312
+ * reason (documented per group); a value that merely coincides with another site's number gets its
313
+ * own entry instead — see `docs/STATUS.md`'s spacing-sweep note for the specific coincidental calls.
150
314
  *
151
- * • `accentFill` — the accent as SURFACE: filled buttons, a checked Switch/Checkbox, the active
152
- * Timeline bullet, the Composer send button. It CARRIES A LABEL, so it is squeezed from both
153
- * sides at once: white text needs ≥4.5:1 against the fill, AND the control needs ≥3:1 against
154
- * the page it sits on. On the dark page those two constraints leave one narrow window, and
155
- * `#0077bd` is the value in it (white 4.80:1, fill-vs-dark-page 3.26:1). Deeper (`#0069a8`,
156
- * `#04669b`) buys text contrast but drops the button to 2.5–2.7:1 against the page — the control
157
- * fades into the background. Lighter breaks white text. So the fill is the SAME hex in both
158
- * schemes, and `onAccent` is white in both.
159
- *
160
- * `onAccent` is THE foreground for any accent fill. `theme/index.ts` bridges Mantine's
161
- * `--mantine-color-<primary>-filled` onto `--vx-accentFill` and every filled foreground onto
162
- * `--vx-onAccent`, so ONE token drives the chrome — which is also what makes the theme lab able to
163
- * retune the accent live. Mantine's own `autoContrast` cannot express this (it resolves the
164
- * foreground scheme-blindly, in JS). Regression-locked by `theme/contrast.test.ts`.
315
+ * Extended again by the density pass (this commit) with the STRUCTURAL chart constants
316
+ * `tokens/index.ts`'s `VX` object used to hardcode directly (`legendGap`/`margin`/`dotR` — see the
317
+ * "charts" group below) plus `progressBarSize` (the Progress bar's numeric `defaultProps.size`,
318
+ * previously an untokenized literal `6`) — both are numeric Mantine `defaultProps`/SVG-prop sites
319
+ * with the SAME "dev slider can't reach it" limitation as `timelineBullet` (see `deriveSpacing`'s
320
+ * doc and the `theme-lab` "known constraint" note).
165
321
  */
166
- export const ACCENT = {
167
- accent: { light: '#0077bd', dark: '#8ec5ff' }, // accent as INK — inverts across schemes
168
- accentHover: { light: '#0069a8', dark: '#51a2ff' },
169
- accentFill: { light: '#0077bd', dark: '#0077bd' }, // accent as SURFACE — same hex in both schemes
170
- accentFillHover: { light: '#0069a8', dark: '#0069a8' }, // deeper on hover (white text 5.86:1)
171
- onAccent: { light: '#ffffff', dark: '#ffffff' }, // text on an accent fill — white in BOTH
322
+ const SPACE_STEP_BASE = {
323
+ /** Timeline `defaultProps.bulletSize`. */
324
+ timelineBullet: 22,
325
+
326
+ // ── Shared across ≥2 sites (structural — must render at the same value) ──────────────────────
327
+ // `stickyHeaderClearance`/`stickyHeaderClearanceMobile` USED to live here as ONE independent base
328
+ // literal (84) — they don't any more. Both are DERIVED, post-`step`, from their OWN AppShell
329
+ // header (`appShellHeaderHeight` / `appShellHeaderMobileHeight` below) instead (see
330
+ // {@link deriveSpacing}'s doc for why): an independent literal could drift from the header it's
331
+ // supposed to clear, which is exactly what happened (84 < 96, under-clearing the mobile header at
332
+ // every level before this fix) — and a SINGLE derived value still over-cleared the desktop header
333
+ // by 60px, since the desktop header is less than half the mobile one's height. `SpaceValues.step`
334
+ // still carries both keys — see that type's own doc — they're just not part of this BASE table.
335
+ /** NavLink leftSection icon-to-label gap — shared by `theme/nav-link.module.css` (every render
336
+ * path) and `shell/app-sidebar.module.css`'s own `.link` rule (belt-and-suspenders on the same
337
+ * DOM), and reused verbatim for `.footerBtn`/`.accountRow`'s icon gap (their own doc comments call
338
+ * out "IDENTICAL geometry to a nav row"). */
339
+ navIconGap: 10,
340
+ /** Sidebar region-to-region gap: `.brand`'s bottom padding and `.searchSlot`'s bottom padding (in
341
+ * both the expanded and collapsed rail variants) — the searchSlot comment explicitly says its gap
342
+ * opens the nav region "the same way the brand row's own bottom padding does". */
343
+ sidebarRegionGap: 10,
344
+
345
+ // ── content/prose.module.css ──────────────────────────────────────────────────────────────────
346
+ /** Blockquote rail's own vertical inset. */
347
+ proseQuoteInsetY: 2,
348
+ /** Blockquote text indent past the rail. */
349
+ proseQuoteIndent: 12,
350
+ /** Inline code chip vertical inset. */
351
+ proseInlineCodeInsetY: 1.5,
352
+ /** Inline code chip horizontal inset. */
353
+ proseInlineCodeInsetX: 5,
354
+ /** Raw `<pre>` fallback block vertical inset. */
355
+ proseCodeBlockInsetY: 10,
356
+ /** Raw `<pre>` fallback block horizontal inset. */
357
+ proseCodeBlockInsetX: 12,
358
+ /** Heading copy-link anchor's gap from the heading text. */
359
+ proseHeadingAnchorGap: 6,
360
+ /** Table cell vertical inset. */
361
+ proseTableCellInsetY: 5,
362
+ /** Table cell horizontal inset. */
363
+ proseTableCellInsetX: 8,
364
+ /** Chat-density list's bottom margin (top margin reuses `SPACE.stackXs`). */
365
+ proseChatListGapBottom: 10,
366
+ /** Chat-density list indent. */
367
+ proseChatListIndent: 20,
368
+ /** Chat-density list-item vertical margin. */
369
+ proseChatListItemGap: 3,
370
+ /** Chat-density nested-list vertical margin. */
371
+ proseChatNestedListGap: 2,
372
+ /** Chat-density heading top margin. */
373
+ proseChatHeadingGapTop: 14,
374
+ /** Chat-density heading bottom margin. */
375
+ proseChatHeadingGapBottom: 6,
376
+ /** Article-density paragraph bottom margin. */
377
+ proseArticleParagraphGap: 14,
378
+ /** Article-density list top margin. */
379
+ proseArticleListGapTop: 6,
380
+ /** Article-density list bottom margin. */
381
+ proseArticleListGapBottom: 14,
382
+ /** Article-density list indent. */
383
+ proseArticleListIndent: 22,
384
+ /** Article-density `h1` top margin. */
385
+ proseArticleH1GapTop: 6,
386
+ /** Article-density `h1` bottom margin. */
387
+ proseArticleH1GapBottom: 14,
388
+ /** Article-density `h2`/`h3`/`h4`-`h6` shared top margin — one heading-rhythm law repeated
389
+ * verbatim across all three selectors, not a coincidence. */
390
+ proseArticleHeadingGapTop: 30,
391
+ /** Article-density `h2`/`h3`/`h4`-`h6` shared bottom margin (see `proseArticleHeadingGapTop`). */
392
+ proseArticleHeadingGapBottom: 10,
393
+ /** Article-density `h2`'s bottom-rule padding. */
394
+ proseArticleH2RuleGap: 6,
395
+ /** Article-density block-object (blockquote/pre/table/embedded div) margin. */
396
+ proseArticleBlockGap: 18,
397
+
398
+ // ── content/article-layout.module.css ─────────────────────────────────────────────────────────
399
+ /** Content-column-to-TOC-rail column gap. The governing `@media (max-width: 1200px)` breakpoint
400
+ * (`article-layout.module.css`) is deliberately NOT density-coupled — it is a viewport-comfort
401
+ * threshold for showing the TOC rail at all, not a sum of the column tracks: the grid's first
402
+ * column is `minmax(0, var(--vx-prose-measure))`, a FLEXIBLE track that shrinks to fit rather
403
+ * than a fixed width the breakpoint would need to sum. A gap and a responsive breakpoint are
404
+ * different concepts — forcing them to move together would be the coincidence-not-law trap in
405
+ * reverse (see `articleTocRailWidth` below for the track this gap sits beside, which — unlike
406
+ * the breakpoint — IS a genuine density-tracking dimension). */
407
+ articleColumnGap: 56,
408
+ /** TOC rail's own grid-column track width (`.root`'s `grid-template-columns` second track). The
409
+ * rail's contents (`content/toc.module.css`'s link rows) already track density via
410
+ * `tocLinkInsetY`/`tocLinkIndent`/`tocSubIndent`, so a fixed-width raw literal here would squeeze
411
+ * those rows' available space as density rises instead of growing with them — the inverse of the
412
+ * AppShell navbar/rail-width tokenization, same rationale. */
413
+ articleTocRailWidth: 220,
414
+ /** Meta header's own vertical stack gap (title/description/metaRow). */
415
+ articleHeaderGap: 10,
416
+ /** Meta header's bottom padding (above its divider). */
417
+ articleHeaderPaddingBottom: 20,
418
+ /** Meta header's bottom margin (below its divider). */
419
+ articleHeaderMarginBottom: 28,
420
+ /** Meta-row icon-to-text gap. */
421
+ articleMetaRowGap: 6,
422
+ /** Prev/next footer's column gap. */
423
+ articleFooterGap: 12,
424
+ /** Prev/next footer's top margin (above its divider). */
425
+ articleFooterMarginTop: 40,
426
+ /** Prev/next footer's top padding (below its divider). */
427
+ articleFooterPaddingTop: 20,
428
+ /** Prev/next nav-target icon-to-text gap. */
429
+ articleNavTargetGap: 6,
430
+
431
+ // ── content/code-block.module.css ─────────────────────────────────────────────────────────────
432
+ /** Header's title-to-controls gap. */
433
+ codeBlockHeaderGap: 8,
434
+ /** Header's vertical inset. */
435
+ codeBlockHeaderInsetY: 6,
436
+ /** Header's right inset (before the header-right control cluster). */
437
+ codeBlockHeaderInsetRight: 10,
438
+ /** Content-column left edge — shared by the header's left inset and the body's horizontal inset,
439
+ * so the header title and the code text line up on the same left edge. */
440
+ codeBlockContentInsetX: 14,
441
+ /** Header-right control cluster's own gap. */
442
+ codeBlockHeaderRightGap: 6,
443
+ /** Body's vertical inset. */
444
+ codeBlockBodyInsetY: 10,
445
+ /** Floating copy button's corner offset — one value reused for both `top` and `right`. */
446
+ codeBlockFloatingCopyOffset: 6,
447
+
448
+ // ── content/callout.module.css ────────────────────────────────────────────────────────────────
449
+ /** Panel vertical inset. */
450
+ calloutInsetY: 10,
451
+ /** Panel horizontal inset. */
452
+ calloutInsetX: 14,
453
+ /** Title row's icon-to-text gap. */
454
+ calloutTitleRowGap: 8,
455
+
456
+ // ── content/toc.module.css ────────────────────────────────────────────────────────────────────
457
+ /** Rail's own vertical stack gap (header-to-list). */
458
+ tocRootGap: 6,
459
+ /** Link row's vertical inset. */
460
+ tocLinkInsetY: 4,
461
+ /** Link row's text indent past the rail guide. */
462
+ tocLinkIndent: 12,
463
+ /** Nested (sub-heading) link's extra indent. */
464
+ tocSubIndent: 24,
465
+
466
+ // ── content/article-card.module.css ───────────────────────────────────────────────────────────
467
+ /** Tag row's own gap. */
468
+ articleCardTagsGap: 4,
469
+ /** Tag chip's vertical inset. */
470
+ articleCardTagInsetY: 1,
471
+ /** Tag chip's horizontal inset. */
472
+ articleCardTagInsetX: 6,
473
+ /** Meta line's top gap. */
474
+ articleCardMetaGapTop: 2,
475
+
476
+ // ── content/guide.module.css ──────────────────────────────────────────────────────────────────
477
+ /** Drawer body's bottom gap (before the footer). */
478
+ guideBodyGapBottom: 8,
479
+ /** Footer's top margin (above its divider). */
480
+ guideFooterGapTop: 20,
481
+ /** Footer's top inset (below its divider). */
482
+ guideFooterInsetTop: 16,
483
+
484
+ // ── shell/sidebar-search.module.css ───────────────────────────────────────────────────────────
485
+ /** Trigger's icon-to-label gap. */
486
+ sidebarSearchGap: 7,
487
+ /** Trigger's height — floored at 24px in {@link deriveSpacing} (WCAG 2.5.8 minimum target size);
488
+ * the collapsed rail's `ActionIcon` variant reads the SAME resolved value (`shell/sidebar-
489
+ * search.module.css`'s `.railBtn`), so both states of the control stay consistent at every level. */
490
+ sidebarSearchTriggerHeight: 32,
491
+
492
+ // ── dashboard/settings-section.module.css ─────────────────────────────────────────────────────
493
+ /** Row's vertical inset. */
494
+ settingsRowInsetY: 10,
495
+ /** Row's own gap (label cluster to control). */
496
+ settingsRowGap: 16,
497
+
498
+ // ── content/mermaid.module.css ────────────────────────────────────────────────────────────────
499
+ /** Diagram container's inset (all sides). */
500
+ mermaidContainerInset: 16,
501
+
502
+ // ── shell/app-sidebar.module.css (beyond the shared/reused anchors above) ────────────────────
503
+ /** Brand row's top inset. */
504
+ sidebarBrandInsetTop: 2,
505
+ /** Brand row's horizontal inset. */
506
+ sidebarBrandInsetX: 7,
507
+ /** Gap between nav sections. */
508
+ sidebarSectionGap: 12,
509
+ /** Account row's top inset. */
510
+ sidebarAccountInsetTop: 9,
511
+ /** Account row's horizontal inset. */
512
+ sidebarAccountInsetX: 7,
513
+ /** Account row's bottom inset. */
514
+ sidebarAccountInsetBottom: 2,
515
+ /** Identity-initials avatar block's fixed size (width and height). */
516
+ sidebarAvatarSize: 28,
517
+ /** Section-label row's bottom gap (before the first nav row). */
518
+ sidebarSectionLabelGap: 2,
519
+ /** Collapsible child-list wrapper's top margin. */
520
+ sidebarChildListGapTop: 2,
521
+ /** Collapsible child-list wrapper's bottom margin. */
522
+ sidebarChildListGapBottom: 3,
523
+ /** Collapsible child-list wrapper's left indent. */
524
+ sidebarChildListIndent: 15,
525
+ /** Child NavLink row's vertical inset. */
526
+ sidebarChildRowInsetY: 4,
527
+ /** Child NavLink row's extra left indent (past the rail guide). */
528
+ sidebarChildRowIndent: 12,
529
+
530
+ // ── shell/app-sidebar.tsx & app-sidebar-account.tsx (Mantine `<Menu width={…}>` props) ────────
531
+ // Both are FIXED dropdown widths (a JSX number prop, not CSS — same "JS-consumed, no --vx-* var"
532
+ // shape as `appShellNavbarWidth` etc.) holding `Menu.Item` rows padded by `rowInsetX`/`rowInsetY`
533
+ // (`theme/index.ts`'s `Menu.extend`). Unlike `.subnavDropdown`'s `min-width: 180px`
534
+ // (`app-sidebar.module.css`, deliberately left a raw literal — a `min-width` only floors the box
535
+ // and it grows with content, so it can never squeeze), a `width` prop caps the dropdown exactly:
536
+ // as density rises the row's padding/line-height need more room than a frozen width can give,
537
+ // squeezing the label text — the same rationale `articleTocRailWidth` documents for its own
538
+ // fixed-width track.
539
+ /** Account-menu `<Menu width={…}>` (`app-sidebar-account.tsx`). */
540
+ sidebarAccountMenuWidth: 220,
541
+ /** Settings-menu `<Menu width={…}>` (`app-sidebar.tsx`). */
542
+ sidebarSettingsMenuWidth: 200,
543
+
544
+ // ── shell/app-header.module.css ───────────────────────────────────────────────────────────────
545
+ /** Mobile two-row header's page-actions row height. */
546
+ appHeaderMobileActionsHeight: 52,
547
+
548
+ // ── shell/index.tsx (AppShell dimensions) ──────────────────────────────────────────────
549
+ /** AppShell desktop header bar height — sized to hold one row of `size="md"` controls, so it
550
+ * tracks `controlHeight`. Its level-0 coincidence with `appShellNavbarRailWidth` below is a
551
+ * coincidence, not a law: this is a horizontal bar's HEIGHT (governed by control height), that
552
+ * is a vertical rail's WIDTH (governed by icon footprint). They stay separate entries. */
553
+ appShellHeaderHeight: 48,
554
+ /** AppShell mobile (two-row) header height. Not one concept but a sum: row 1 + `app-header.
555
+ * module.css`'s wrap row-gap (`--mantine-spacing-sm`) + `appHeaderMobileActionsHeight`. Two of
556
+ * those three addends already track density, so the container must too — held fixed, row 1's
557
+ * budget collapses 52px -> 12px across the level range.
558
+ *
559
+ * KEEP THIS EQUAL TO THE SUM. At level 0: 32 (row 1) + 13 (`SPACE_SCALE.sm`) + 52
560
+ * (`appHeaderMobileActionsHeight`) = 97. It was 96 while `SPACE_SCALE.sm` was 12; the
561
+ * component-roominess retune raised that addend, and leaving the total at 96 silently took the
562
+ * pixel out of row 1 instead — which is what ate the last of its WCAG 2.5.8 target-size margin at
563
+ * density -3 (`theme/density-relations.test.ts` measures row 1 as the REMAINDER of this sum, so
564
+ * the total is the only place the budget can come from). Raise this whenever `SPACE_SCALE.sm` or
565
+ * `appHeaderMobileActionsHeight` moves. Better still, make it unnecessary: computing this the way
566
+ * `stickyHeaderClearance*` already is — post-`step`, from its own addends rather than as an
567
+ * independent literal — would make the drift impossible instead of merely re-tuned. That is the
568
+ * same refactor, and the same reasoning, this PR applied to the clearances; it is worth doing to
569
+ * this one too, and it stays a follow-up only because it moves every non-zero level's value. */
570
+ appShellHeaderMobileHeight: 97,
571
+ /** AppShell navbar width, expanded — ONE entry for both the `base` (mobile drawer) and the
572
+ * expanded `sm` value: the same `.root` at full width, genuinely one concept. */
573
+ appShellNavbarWidth: 216,
574
+ /** AppShell navbar width, collapsed icon rail. Separate from `appShellHeaderHeight` above
575
+ * despite sharing 48 at level 0 (see that entry's note). */
576
+ appShellNavbarRailWidth: 48,
577
+
578
+ // ── shell/app-mobile-nav.module.css ───────────────────────────────────────────────────────────
579
+ /** Tab's icon-to-label gap. */
580
+ mobileNavTabGap: 3,
581
+
582
+ // ── charts (tokens/index.ts's `VX` object — structural, tracks density) ──────────────────────
583
+ // `VX.lineWidth`/`VX.line2Width` are DELIBERATELY absent here — they are stroke WEIGHTS (line
584
+ // thickness), not spacing/gaps/sizes, so they stay fixed regardless of density (see `VX` in
585
+ // `tokens/index.ts`). The six below are gaps/margins/a marker footprint — genuinely spacing.
586
+ /** `ChartLegend`'s column/row gap (`VX.legendGap`). */
587
+ chartLegendGap: 22,
588
+ /** Chart plot-area margin, top (`VX.margin.top`). */
589
+ chartMarginTop: 12,
590
+ /** Chart plot-area margin, right (`VX.margin.right`). */
591
+ chartMarginRight: 16,
592
+ /** Chart plot-area margin, bottom (`VX.margin.bottom`). */
593
+ chartMarginBottom: 30,
594
+ /** Chart plot-area margin, left (`VX.margin.left`). */
595
+ chartMarginLeft: 44,
596
+ /** Data-point marker radius (`VX.dotR`) — a discrete visual footprint, not a stroke weight, so
597
+ * (unlike `lineWidth`/`line2Width`) it tracks density: a judgment call, made this way because it
598
+ * reads as a "size" (closer to `sidebarAvatarSize` above) rather than a line thickness. */
599
+ chartDotR: 5,
600
+
601
+ // ── theme/index.ts's Progress `defaultProps.size` (previously an untokenized literal `6`) ──────
602
+ /** Progress bar thickness (`components.Progress.defaultProps.size`) — a numeric Mantine size prop,
603
+ * same "dev slider can't reach it, production `{ density }` rebuilds it" limitation as
604
+ * `timelineBullet` above (see `deriveSpacing`'s doc). */
605
+ progressBarSize: 6,
606
+
607
+ // ── Agent transcript / chat inline spacings — routed from the agent + agent-chat renderers and
608
+ // the dashboard/data inline styles that were raw px (the inline-spacing guard sweep) ───────────
609
+ /** `agent/part-list.tsx` + `agent-chat/thread-message.tsx` reasoning/tool-call rail's left inset. */
610
+ agentRailInsetX: 10,
611
+ /** `agent/part-list.tsx`'s `DefaultReasoning` body / both rail code blocks' top gap. */
612
+ agentPartGapTop: 6,
613
+ /** Both rail code blocks' own inset (all sides). */
614
+ agentCodeInset: 8,
615
+ /** `agent/part-list.tsx`'s `DefaultError` vertical inset. */
616
+ agentErrorInsetY: 8,
617
+ /** `agent/part-list.tsx`'s `DefaultError` horizontal inset. */
618
+ agentErrorInsetX: 10,
619
+ /** `agent/stick-to-bottom.tsx`'s scroll-to-bottom button top gap. */
620
+ agentScrollButtonGapTop: 8,
621
+ /** `agent-chat/thread-message.tsx`'s message bubble vertical inset. */
622
+ agentMessageInsetY: 10,
623
+ /** `agent-chat/thread-message.tsx`'s message bubble horizontal inset. */
624
+ agentMessageInsetX: 12,
625
+ /** `agent-chat/thread-detail-panel.tsx`'s transcript scroll container's own inset (all sides). */
626
+ agentTranscriptInset: 16,
627
+ /** `agent-chat/thread-outcome-card.tsx` + `dashboard/delta-badge.tsx`'s status badge vertical inset. */
628
+ badgeInsetY: 2,
629
+ /** `agent-chat/thread-outcome-card.tsx` + `dashboard/delta-badge.tsx`'s status badge horizontal inset. */
630
+ badgeInsetX: 7,
631
+ /** `dashboard/stat-card.tsx`'s header/value/sparkline stack gap. */
632
+ statCardGap: 8,
633
+ /** `data/virtual-list.tsx`'s skeleton row vertical inset. */
634
+ virtualRowInsetY: 8,
635
+ /** `data/virtual-list.tsx`'s skeleton row horizontal inset. */
636
+ virtualRowInsetX: 12,
172
637
  } as const
173
638
 
174
639
  /**
175
- * Filled-surface hexes for the Mantine accent families — THE FILL BAND.
176
- *
177
- * A filled control is constrained from both sides at once (the `ACCENT` note above derives this for
178
- * the accent): a white label needs ≥4.5:1 against the fill, and the control needs ≥3:1 against the
179
- * page behind it — on BOTH pages, since a fill does not invert across schemes. In WCAG terms that
180
- * pins the fill's relative luminance into one narrow band, ~0.150–0.183. There is no room for a
181
- * family to sit outside it: too light and the label dies, too dark and the button fades into the
182
- * dark page.
640
+ * Density-EXEMPT structurals — unlike `SPACE`/`SPACE_STEP` above, these never move with the density
641
+ * knob. `tokens/index.ts` does NOT emit these as `--vx-*` CSS vars (see the comment there for why: a
642
+ * var would only invite someone to think they move).
643
+ */
644
+ export const SPACE_FIXED = {
645
+ /** Timeline `defaultProps.lineWidth`; also used for 1px borders. */
646
+ hairline: 1,
647
+ /** ReadingProgress's fixed top-bar height — a hairline-like indicator line (docs/CONTENT-SPEC.md
648
+ * §7), not a spacing gap that should thicken with density. Stays a literal at its one call site
649
+ * (`content/reading-progress.module.css`), same as `hairline`. */
650
+ readingProgressHeight: 2,
651
+ /** SegmentedControl track's optical inset (`styles.root` padding) — moved OUT of `SPACE_STEP` and
652
+ * exempted from the density knob because it is load-bearing for the nested-corner law
653
+ * (docs/DESIGN-SPEC.md §4): `RADIUS.card === RADIUS_STEP.tight + segmentedTrackInset` (`7 = 5 +
654
+ * 2`). `RADIUS.card`/`RADIUS_STEP.tight` both shift together under the RADIUS knob (`card = 7 +
655
+ * level`, `tight = ctrl - 1 = 5 + level`), so their difference is ALWAYS exactly 2 regardless of
656
+ * that knob — a density-tracking inset would break concentricity in both directions (verified: this
657
+ * inset's own value, HAD it stayed density-tracking, resolves via `scaleSpace(2, level, multiplier)`
658
+ * to 1 at density's floor level -3 and 3 at its ceiling level +3 — the widest swing `deriveSpacing`'s
659
+ * `[-3, 3]` range can produce) for no compensating benefit, since the two radii it sits between
660
+ * never move independently of each other. */
661
+ segmentedTrackInset: 2,
662
+ } as const
663
+
664
+ /**
665
+ * The resolved shape {@link deriveSpacing} returns — the two anchor/scale base groups above (as
666
+ * `anchors`/`scale`) PLUS every `SPACE_STEP_BASE` one-off (as `step`) and the NavLink row
667
+ * line-height (as `rowLineHeight`), all scaled together from one integer `level`. Kept as separate
668
+ * groups rather than flattened into one object for the same reason `SPACE_SCALE_BASE`'s doc gives:
669
+ * the law must be free to move an anchor and a scale stop at different rates. The spacing analog of
670
+ * {@link RadiusValues}.
671
+ */
672
+ export type SpaceValues = {
673
+ anchors: { [K in keyof typeof SPACE_ANCHORS_BASE]: number }
674
+ scale: { [K in keyof typeof SPACE_SCALE_BASE]: number }
675
+ /** `SPACE_STEP_BASE`'s one-offs PLUS `stickyHeaderClearance`/`stickyHeaderClearanceMobile`, NEITHER
676
+ * of which is in that base table — both are computed after the rest of `step`, one from
677
+ * `appShellHeaderHeight` (desktop) and one from `appShellHeaderMobileHeight` (mobile), see
678
+ * {@link deriveSpacing}'s doc. Kept on this same `step` object (not split into a third group)
679
+ * because every consumer reads them exactly like any other one-off — only their DERIVATION
680
+ * differs. Two keys, not one, because the clearance is RESPONSIVE (Decision 3): a consumer picks
681
+ * whichever one matches the breakpoint it's rendering at — see `docs/CONTENT-SPEC.md` §5 and
682
+ * `content/prose.module.css`/`content/article-layout.module.css` for the CSS-side split. */
683
+ step: { [K in keyof typeof SPACE_STEP_BASE]: number } & {
684
+ stickyHeaderClearance: number
685
+ stickyHeaderClearanceMobile: number
686
+ }
687
+ /** NavLink row line-height (`theme/index.ts`'s row-geometry styles) — additive, not
688
+ * multiplicative; see {@link deriveSpacing}'s doc for why. */
689
+ rowLineHeight: number
690
+ }
691
+
692
+ /**
693
+ * Scale one density-tracking spacing number by `multiplier`, rounding to the nearest integer and
694
+ * clamping at an UNCONDITIONAL floor of 1 (an aggressive negative level can never collapse a real
695
+ * inset to 0 or below).
183
696
  *
184
- * So every family's fill is its own hue placed at the SAME luminance (0.165, the band's centre).
185
- * Each hex is the family's Mantine shade-6 scaled uniformly in LINEAR-light space — luminance is
186
- * linear in linear-RGB, so a uniform scale lands on the target exactly while preserving the hue and
187
- * saturation exactly. The result is a system law rather than a per-color judgement call: EVERY
188
- * filled surface reads white, on either page, at ~4.9:1 / ~3.2:1. Untuned, five families sat under
189
- * the 3:1 page floor (grape 2.17:1) and three needed black labels.
697
+ * At `level === 0` the multiplier is exactly 1 — return `value` verbatim instead of routing it
698
+ * through `Math.round`, so a non-integer base (`proseInlineCodeInsetY: 1.5`) stays byte-identical
699
+ * rather than rounding to `2` (`Math.round(1.5 * 1)` rounds half-up) — the level-0 acceptance gate
700
+ * (`theme/spacing.test.ts`) requires the EXACT shipped number, not merely an equal one.
190
701
  *
191
- * `blue` is absent on purpose — it is the accent, and its fill lives in `ACCENT.accentFill` so the
192
- * accent keeps ONE source. `dark` is absent too: `color="dark"` is a deliberately near-black
193
- * surface, not a band member. Hover is DERIVED in CSS from the fill (see `tokens/index.ts`), so
194
- * retuning a fill moves its hover with it. Regression-locked by `theme/contrast.test.ts`.
702
+ * The floor is UNREACHABLE through {@link deriveSpacing}'s public `[-3, 3]` level range TODAY: every
703
+ * `SPACE_ANCHORS_BASE`/`SPACE_SCALE_BASE`/`SPACE_STEP_BASE` value is an integer `>= 1`, the
704
+ * shallowest multiplier `deriveSpacing` ever passes is `0.7` (level `-3`), and `round(v * 0.7)` is
705
+ * already `>= 1` for every `v >= 1` (`round(1 * 0.7)` is `1`, the smallest case) — so the clamp
706
+ * never changes the result on that path YET. It is applied unconditionally (not gated behind
707
+ * `value >= 1`) precisely so a FUTURE base `< 1` doesn't silently round to 0: a gated floor only
708
+ * protects inputs that could never reach 0 in the first place and skips the one case that could
709
+ * (`round(0.5 * 0.7) = round(0.35) = 0` for a hypothetical `0.5` base at level `-3`, unguarded by a
710
+ * `value >= 1` gate). Exported (not re-exported by the `./tokens` barrel — this stays outside the
711
+ * published surface, `scripts/export-surface.json`) purely so `palette.test.ts` can drive the clamp
712
+ * directly with a `multiplier`/`value` pair `deriveSpacing` itself can never produce, and prove the
713
+ * floor still holds if a base or the level range ever changes.
195
714
  */
196
- export const FILL = {
197
- gray: '#707078',
198
- red: '#cc3c41',
199
- pink: '#d22b6a',
200
- grape: '#ad47ad',
201
- violet: '#ad47ad',
202
- indigo: '#745cda',
203
- cyan: '#1378aa',
204
- teal: '#007f75',
205
- green: '#1f8228',
206
- lime: '#617a1a',
207
- yellow: '#936a05',
208
- orange: '#a56113',
209
- } as const
715
+ export function scaleSpace(value: number, level: number, multiplier: number): number {
716
+ if (level === 0) return value
717
+ const scaled = Math.round(value * multiplier)
718
+ return Math.max(1, scaled)
719
+ }
720
+
721
+ /** Apply {@link scaleSpace} across every value of a base table, preserving its exact key set (a
722
+ * mapped type, not `Record<string, number>`, so a renamed/removed key still fails `tsc` downstream). */
723
+ function mapSpaceGroup<T extends Record<string, number>>(
724
+ base: T,
725
+ level: number,
726
+ multiplier: number,
727
+ ): { -readonly [K in keyof T]: number } {
728
+ const out = {} as { -readonly [K in keyof T]: number }
729
+ for (const key of Object.keys(base) as (keyof T)[])
730
+ out[key] = scaleSpace(base[key]!, level, multiplier)
731
+ return out
732
+ }
210
733
 
211
734
  /**
212
- * Card / control depth shadows (`docs/DESIGN-SPEC.md` §2) — depth is a whisper shadow + a 1px
213
- * ring baked into the SAME value (never a separate `border`). The ring embeds
214
- * `var(--vx-surface-hairline)` so it stays single-sourced against the hairline pair below.
735
+ * `rowLineHeight`'s own additive per-level step — see {@link deriveSpacing}'s doc for why it is a
736
+ * SEPARATE, explicitly hand-tuned constant rather than something computed from `deriveSpacing`'s
737
+ * own `multiplier`. A prior version of this law computed it as `(multiplier - 1) / 3` and
738
+ * documented that as "derived from `multiplier` itself... so retuning the multiplier's step can
739
+ * never desync this from it" — that claim was false: `/ 3` was itself a second hand-tuned
740
+ * coefficient (reverse-engineered to reproduce the old `1.25`/`1.45` endpoints), and worse, it
741
+ * silently coupled a unitless typographic ratio (line-height) to a px spacing scale factor, so a
742
+ * future purely-spatial retune of `multiplier`'s own coefficient would have moved NavLink row
743
+ * line-height with no typography decision made anywhere. This constant is the honest version of
744
+ * the same idea: still hand-picked to land on the identical `1.25`..`1.45` envelope the old
745
+ * `1.35 + 0.02 * level` law produced at the pre-narrowing `[-5, 5]` range (`0.02 * 5 ===
746
+ * ROW_LINE_HEIGHT_STEP * 3`), but as its own named number — a future edit to the spacing
747
+ * multiplier's `0.1` cannot silently drag this along with it, and a future edit to typography
748
+ * (this constant) cannot silently distort spacing.
215
749
  */
216
- export const SHADOW = {
217
- card: {
218
- light: '0 1px 2px rgba(28,25,23,0.05), 0 0 0 1px var(--vx-surface-hairline)',
219
- dark: '0 1px 3px rgba(0,0,0,0.4), inset 0 0 0 1px color-mix(in srgb, #ffffff 4%, transparent)',
220
- },
221
- ctrl: {
222
- light: '0 1px 2px rgba(28,25,23,0.12)',
223
- dark: '0 1px 2px rgba(0,0,0,0.35)',
224
- },
225
- // Floating-layer elevation (menus, popovers, tooltips, modals, drawers) — a REAL drop shadow, a
226
- // step above `card`, so detached surfaces read as lifted off the page (`docs/DESIGN-SPEC.md` §5).
227
- // Unlike `card`, no embedded ring: floating surfaces carry a real 1px `--vx-surface-border` so
228
- // Mantine's rotated-square arrow inherits a proper edge.
229
- overlay: {
230
- light: '0 8px 24px rgba(28,25,23,0.10)',
231
- dark: '0 8px 24px rgba(0,0,0,0.5)',
232
- },
233
- } as const
750
+ const ROW_LINE_HEIGHT_STEP = 1 / 30
234
751
 
235
752
  /**
236
- * App chrome surfaces — the zinc identity for the Mantine theme (`docs/DESIGN-SPEC.md` §2).
753
+ * Derive every density-tracking spacing number (anchors, scale stops, one-offs, row line-height)
754
+ * from a single integer `level` (`docs/DESIGN-SPEC.md` §4-adjacent) — the spacing analog of
755
+ * {@link deriveRadius}. `level: 0` reproduces the shipped identity exactly (locked by
756
+ * `theme/spacing.test.ts` and `tokens/density.test.ts`) for every value EXCEPT
757
+ * `step.stickyHeaderClearance`/`step.stickyHeaderClearanceMobile` — see the third bullet below for
758
+ * why those are a deliberate exception.
237
759
  *
238
- * `border` ("line") is the STRONG border used broadly for layout/control chrome (AppShell, Table,
239
- * Input, Divider, Tabs, Popover, Accordion — everything bound through `--mantine-color-default-
240
- * border` / `--mantine-color-gray-{2,3,4}` in the resolver below). `hairline` ("card ring") is a
241
- * DISTINCT, thinner pair used ONLY inside `shadow-card`'s embedded ring — cards carry no `border`
242
- * property at all, the ring lives in the shadow. Never conflate the two.
760
+ * The law: a MULTIPLIER, `1 + 0.1 * level`, applied to every `SPACE_ANCHORS_BASE`/
761
+ * `SPACE_SCALE_BASE`/`SPACE_STEP_BASE` constant, then rounded (see {@link scaleSpace}) — a
762
+ * multiplier rather than an additive step because these values span 1px to 180px; an additive
763
+ * constant would distort small and large insets by wildly different proportions.
764
+ *
765
+ * Three groups deviate from the plain per-value multiplier above:
766
+ *
767
+ * - `stackXs`..`stackXl` (the 4px vertical rhythm) are rebuilt from ONE scaled unit —
768
+ * `unit = scaleSpace(4, level, multiplier)`, then `stackXs = unit`, `stackSm = 2 * unit`,
769
+ * `stackMd = 3 * unit`, `stackLg = 4 * unit`, `stackXl = 6 * unit` — instead of each step
770
+ * independently rounding its own base. Independent rounding breaks the rhythm at non-zero levels
771
+ * (level +1 used to land 4/8/13/17/25, no common factor) and silently drifts the documented 2:1
772
+ * pairs (`stackXl`:`stackMd`, `stackLg`:`stackSm`) by a px at almost every level; the shared-unit
773
+ * rebuild keeps every step an exact multiple of `unit` and both pairs exactly 2:1, at every level
774
+ * including 0 (`unit` is 4 there, reproducing 4/8/12/16/24 verbatim). `SPACE_SCALE_BASE`'s own
775
+ * `xs`/`sm`/`md`/`lg`/`xl` stops do NOT get this treatment — that group's `sm`:`xl` 1:2 coincidence
776
+ * is documented as incidental (a past density pass landed there), not a law like the stack rhythm's,
777
+ * so it keeps the plain per-value multiplier.
778
+ * - `step.sidebarSearchTriggerHeight` is floored at 24px after scaling — WCAG 2.5.8's minimum
779
+ * interactive-target size. Without the floor, a negative level shrinks the sidebar search trigger
780
+ * (and, transitively, the collapsed rail's `ActionIcon` variant, which reads this same resolved
781
+ * value) below the accessible floor (22px at level -3) while also crowding out its fixed-size icon
782
+ * and `Kbd` chip.
783
+ * - `step.stickyHeaderClearance` (desktop) and `step.stickyHeaderClearanceMobile` (mobile) are not
784
+ * scaled off their own base AT ALL — `SPACE_STEP_BASE` has no such key any more (see that table's
785
+ * doc). Both are computed AFTER the rest of `step`, RESPONSIVELY, one per AppShell breakpoint:
786
+ * `stickyHeaderClearance = step.appShellHeaderHeight + anchors.stackMd` (desktop, `>= sm`) and
787
+ * `stickyHeaderClearanceMobile = step.appShellHeaderMobileHeight + anchors.stackMd` (mobile,
788
+ * `< sm` — the SAME `sm`/48em breakpoint the AppShell header itself switches on, `shell/index.tsx`).
789
+ * A SINGLE clearance value (this law's own prior shape) can only be tuned against ONE header, and
790
+ * whichever one it under-shoots stays broken: the original independent literal (84) was tuned only
791
+ * against the desktop header (48) and under-cleared the mobile header (96) by 12px at level 0
792
+ * already, before density entered the picture; deriving ONE value off the taller mobile header
793
+ * fixed that under-clear but then OVER-cleared the desktop header by 60px (108 vs. the 48px header
794
+ * needs) — dead space above every anchored heading and a TOC rail shoved down on the common
795
+ * (desktop) path. Splitting into two responsive values fixes both directions at once: each clears
796
+ * ONLY its own header, with the SAME `anchors.stackMd` breathing room (not a bare `+ 0`) so a
797
+ * scrolled-to heading doesn't sit flush against the header's bottom edge — density-tracking, like
798
+ * the header height it's added to, so the margin itself never freezes at one notch. Level 0:
799
+ * desktop `48 + 12 = 60` (a deliberate BREAK from the pre-split 84/108 — see `theme/spacing.test.ts`
800
+ * for why `stickyHeaderClearance` alone is exempt from the byte-identity gate every other spacing
801
+ * token is held to), mobile `96 + 12 = 108` (unchanged from the pre-split single-value law).
802
+ * **Consumer coupling (accepted, not hidden):** both values assume `BasaltShell`'s own AppShell
803
+ * header heights — a `./content` consumer NOT rendering inside `BasaltShell` (e.g. `Prose`/
804
+ * `ArticleLayout` standalone) gets clearance numbers tuned for a header it may not have, and must
805
+ * override `--vx-space-sticky-header-clearance`/`--vx-space-sticky-header-clearance-mobile`
806
+ * itself. Documented on the `./content` surface too (`docs/CONTENT-SPEC.md` §5), not only here.
807
+ *
808
+ * `rowLineHeight` is the ONE exception to the multiplier entirely: `1.35 + ROW_LINE_HEIGHT_STEP *
809
+ * level`, ADDITIVE, its own gentler, INDEPENDENT coefficient (see {@link ROW_LINE_HEIGHT_STEP}'s own
810
+ * doc for why it must stay independent of `multiplier`). It carries the NavLink row's
811
+ * `lineHeight: '1.35'` (`theme/index.ts`, load-bearing for row height) along with the row's padding,
812
+ * but the multiplier law would overshoot it — `1.35 * 1.3` at level +3 is already a much larger
813
+ * relative move than the padding it accompanies, well past the readable line-height range. The
814
+ * additive step instead lands `1.25`..`1.45` across the full range, a proportionate nudge. Rounded
815
+ * to 2 decimals (`Math.round(x * 100) / 100`) to avoid floating-point noise (`1.35 +
816
+ * ROW_LINE_HEIGHT_STEP * 3` is not exactly `1.45` in raw IEEE-754 arithmetic).
817
+ *
818
+ * `SPACE_FIXED` is NEVER part of this law — see that constant's own doc for why.
819
+ *
820
+ * **What actually tracks a retuned `level`, end to end, and what doesn't** (the real scope of the
821
+ * "dev slider gap" — bigger than "a few numeric `defaultProps`", but ALSO narrower than it looks at
822
+ * first glance — see the Input/Button/ActionIcon note below):
823
+ * - `createBasaltTheme({ density })` (`../theme`) rebuilds `theme.spacing` (the generic Mantine
824
+ * scale) AND every density-anchored `defaultProps`/`styles` number (Timeline's `bulletSize`,
825
+ * Progress's `size`) from THIS function's output — this is the one production entry point, and it
826
+ * is complete for all of those.
827
+ * - `theme-lab/DeriveControls` (the DEV-tool slider) can only move `--vx-*` CSS custom properties
828
+ * via an injected `<style>` — it CANNOT reach a numeric `defaultProps`/SVG-prop value baked into
829
+ * the theme object at all, so Timeline's `bulletSize` and Progress's `size` stay visibly static
830
+ * there. The SAME limitation applies to `theme.spacing` itself (the generic Mantine `xs`/`sm`/
831
+ * `md`/`lg`/`xl` scale): `createBasaltTheme({ density })` bakes it into the theme object as
832
+ * rem strings (`theme/index.ts`'s `buildTheme`), and `spaceDecls` (`tokens/index.ts`) deliberately
833
+ * emits no `--vx-space-scale-*`/`--mantine-spacing-*` var for it (see that function's own doc) —
834
+ * so the dev slider's injected `<style>` cannot reach it either, and a component reading
835
+ * `var(--mantine-spacing-sm)` (e.g. `shell/app-header.module.css`) stays at its level-0 value
836
+ * under the dev slider even though it correctly retunes on the production path. Input's/Button's/
837
+ * ActionIcon's `size="md"` height is NOT in this bucket, despite reading
838
+ * like the same shape of gap: `theme/index.ts`'s `Input.extend`/`Button.extend`/`ActionIcon.extend`
839
+ * resolve their height through `vars` (`--input-height`/`--button-height`/`--ai-size`, each wrapping
840
+ * `var(--vx-space-input-height)`/`var(--vx-space-control-height)` in a `calc(...)`), not a numeric
841
+ * `defaultProps` literal — a CSS custom property the dev slider's injected `<style>` CAN reach, so
842
+ * it DOES visibly follow the Density slider there too, not only in production.
843
+ * - `tokens/index.ts`'s `VX.legendGap`/`VX.margin`/`VX.dotR` (chart legend gap, plot-area margins,
844
+ * marker radius) are the ONE case that fails BOTH paths — including the PRODUCTION one. `VX` is
845
+ * built once at module load from the frozen level-0 `SPACE_STEP` snapshot (visx SVG props read
846
+ * plain JS numbers, not `var()` strings), so it never re-reads a `density` option passed to
847
+ * `createBasaltTheme` at all — a genuine, currently-unfixed production gap, not merely a
848
+ * dev-tool-only limitation like the `defaultProps` above.
849
+ *
850
+ * Throws on a non-integer or out-of-range (`[-3, 3]`) level — same throw-and-propagate discipline as
851
+ * `deriveRadius`/`deriveTokens`'s accent-seed validation.
852
+ *
853
+ * The range is `[-3, 3]`, not `[-5, 5]` like `deriveRadius` — a DELIBERATE, narrower range with a
854
+ * steeper per-notch coefficient (`0.1`, not `0.06`) chosen so the two endpoints reproduce the exact
855
+ * SAME multiplier envelope (`0.7`..`1.3`, `3 * 0.1 === 5 * 0.06`) at fewer, more meaningful notches.
856
+ * At `0.06`/±5, an integer base `v <= 8` (41 of the 108 spacing values, including the entire 4px
857
+ * stack rhythm) is BYTE-IDENTICAL to level 0 at one notch of movement (`0.06 * v < 0.5` rounds back
858
+ * to `v`) — not a dead zone at one notch, but uniform over-quantization across the whole range: the
859
+ * knob advertised more resolution than integer-px rounding could carry. `0.1`/±3 keeps the identical
860
+ * expressive envelope (nothing about how compact/spacious the knob can go changes) while dropping
861
+ * the frozen-at-one-notch count from 43 (at ±1) to 18/22 — see `Fix 7` in
862
+ * `theme/density-relations.test.ts` for the regression guards that pin this down.
243
863
  */
244
- /** Dark page-bg expression — shared by `bg` and the input `field` surface below. */
245
- const DARK_PAGE = 'color-mix(in srgb, #27272a 70%, #18181b)'
246
-
247
- export const SURFACE = {
248
- bg: {
249
- light: 'color-mix(in srgb, #f4f4f5 50%, #e4e4e7)',
250
- dark: DARK_PAGE,
251
- }, // page background
252
- panel: { light: '#f4f4f5', dark: '#27272a' }, // cards, controls
253
- panelHover: {
254
- light: '#fafafa',
255
- dark: 'color-mix(in srgb, #3f3f46 50%, #27272a)',
256
- },
257
- // Elevated surface (chart area, `--mantine-color-default-hover`) — same lift as panel-hover.
258
- elevated: {
259
- light: '#fafafa',
260
- dark: 'color-mix(in srgb, #3f3f46 50%, #27272a)',
261
- },
262
- border: {
263
- light: 'color-mix(in srgb, #e4e4e7 50%, #d4d4d8)',
264
- dark: '#3f3f46',
265
- }, // "line" — strong border (layout/control chrome, NOT the card ring)
266
- hairline: {
267
- light: '#e5e5e5',
268
- dark: 'color-mix(in srgb, #52525c 50%, #3f3f46)',
269
- }, // card ring only — consumed by `SHADOW.card`
270
- // Hover/striped/track fallback surface — a faint step between `panel` and `border`. Used by
271
- // Table hover/striped, Code, SegmentedControl track fallback, Tabs/Accordion/Menu hover.
272
- subtle: { light: '#eeeef0', dark: '#2d2d33' },
273
- // Floating-layer surface (menus, popovers, tooltips, modals, drawers). On light it reads pure
274
- // white — a clean lift above the zinc-100 panel; on dark it reuses the `panelHover` elevated step
275
- // (≈ #333338) so detached surfaces sit a shade above the panel. Paired with `SHADOW.overlay` +
276
- // a real `border` so Mantine's arrow renders a proper edge (`docs/DESIGN-SPEC.md` §5).
277
- overlay: {
278
- light: '#ffffff',
279
- dark: 'color-mix(in srgb, #3f3f46 50%, #27272a)',
280
- },
281
- // Input field surface (docs/DESIGN-SPEC.md §5 field idiom) — reads slightly inset ON a panel.
282
- // Light: pure white on the zinc-100 panel; dark: the page-bg step (one darker than panel).
283
- field: { light: '#ffffff', dark: DARK_PAGE },
284
- divider: {
285
- light: 'color-mix(in srgb, #e5e5e5 65%, transparent)',
286
- dark: 'color-mix(in srgb, #ffffff 6%, transparent)',
287
- }, // layout separators (header bottom rule, sidebar child indent)
288
- } as const
864
+ /** `deriveSpacing`'s accepted level range — exported (not through the `./tokens` barrel, same
865
+ * precedent as {@link scaleSpace}) so `density-relations.test.ts`'s `ALL_LEVELS` can derive the
866
+ * levels it loops over from the SAME bound `deriveSpacing` enforces, instead of a hardcoded literal
867
+ * that silently stops covering the real range if the range ever changes again (as it already has
868
+ * once, `[-5, 5]` -> `[-3, 3]` — see this function's own doc above). */
869
+ export const DENSITY_LEVEL_RANGE = { min: -3, max: 3 } as const
870
+
871
+ export function deriveSpacing(level: number): SpaceValues {
872
+ if (
873
+ !Number.isInteger(level) ||
874
+ level < DENSITY_LEVEL_RANGE.min ||
875
+ level > DENSITY_LEVEL_RANGE.max
876
+ ) {
877
+ throw new Error(
878
+ `deriveSpacing: level must be an integer in [${DENSITY_LEVEL_RANGE.min}, ${DENSITY_LEVEL_RANGE.max}], got ${level}`,
879
+ )
880
+ }
881
+ const multiplier = 1 + 0.1 * level
882
+ const anchors = mapSpaceGroup(SPACE_ANCHORS_BASE, level, multiplier)
883
+ // Rebuild the 4px stack rhythm from one scaled unit so the documented 2:1 pairs hold exactly at
884
+ // every level, not just level 0 (see this function's doc for why independent rounding broke it).
885
+ const stackUnit = scaleSpace(4, level, multiplier)
886
+ anchors.stackXs = stackUnit
887
+ anchors.stackSm = stackUnit * 2
888
+ anchors.stackMd = stackUnit * 3
889
+ anchors.stackLg = stackUnit * 4
890
+ anchors.stackXl = stackUnit * 6
891
+
892
+ const mappedStep = mapSpaceGroup(SPACE_STEP_BASE, level, multiplier)
893
+ // WCAG 2.5.8 minimum interactive-target size — see this function's doc for why the trigger's
894
+ // density-tracking height alone can't be trusted to stay accessible at a negative level.
895
+ mappedStep.sidebarSearchTriggerHeight = Math.max(24, mappedStep.sidebarSearchTriggerHeight)
896
+ const step: SpaceValues['step'] = {
897
+ ...mappedStep,
898
+ // RESPONSIVE, one per AppShell breakpoint — each DERIVED from its own header, plus
899
+ // density-tracking breathing room — see this function's doc (third bullet, Decision 3) for the
900
+ // full rationale, and `theme/spacing.test.ts` for why `stickyHeaderClearance` alone is exempt
901
+ // from the level-0 byte-identity gate.
902
+ stickyHeaderClearance: mappedStep.appShellHeaderHeight + anchors.stackMd,
903
+ stickyHeaderClearanceMobile: mappedStep.appShellHeaderMobileHeight + anchors.stackMd,
904
+ }
905
+
906
+ return {
907
+ anchors,
908
+ scale: mapSpaceGroup(SPACE_SCALE_BASE, level, multiplier),
909
+ step,
910
+ // Additive, gentler, INDEPENDENT law than the multiplier — see `ROW_LINE_HEIGHT_STEP`'s own doc
911
+ // for why it must NOT be computed from `multiplier`.
912
+ rowLineHeight: Math.round((1.35 + ROW_LINE_HEIGHT_STEP * level) * 100) / 100,
913
+ }
914
+ }
915
+
916
+ /** `deriveSpacing(0)` — the shipped identity's spacing values, computed once. `SPACE`/`SPACE_SCALE`/
917
+ * `SPACE_STEP`/`ROW_LINE_HEIGHT` below are defined FROM this, the same way `RADIUS`/`RADIUS_STEP`
918
+ * are defined from `DEFAULT_RADIUS_VALUES = deriveRadius(0)` — one source, so the two can never
919
+ * drift. Exported so `theme/use-basalt-spacing.ts`'s `useBasaltSpacing` can fall back to it when
920
+ * `theme.other.basaltDensity` is absent (the level-0 case — `createBasaltTheme` deliberately omits
921
+ * that key at level 0, see `theme/index.ts`'s `isDefaultDensity` short-circuit). */
922
+ export const DEFAULT_SPACE_VALUES = deriveSpacing(0)
923
+
924
+ /** Density-tracking semantic spacing anchors at the shipped identity — see `SPACE_ANCHORS_BASE`'s
925
+ * doc for what each key means. `deriveSpacing(0)`'s `anchors`, UNCHANGED from the pre-density-knob
926
+ * shipped identity (locked by `theme/spacing.test.ts`). */
927
+ export const SPACE = DEFAULT_SPACE_VALUES.anchors
928
+
929
+ /** The Mantine `spacing` size-scale at the shipped identity — see `SPACE_SCALE_BASE`'s doc.
930
+ * `deriveSpacing(0)`'s `scale`, UNCHANGED from the shipped identity (locked by
931
+ * `theme/spacing.test.ts`). */
932
+ export const SPACE_SCALE = DEFAULT_SPACE_VALUES.scale
933
+
934
+ /** Density-tracking one-offs at the shipped identity — see `SPACE_STEP_BASE`'s doc. `deriveSpacing(0)`'s
935
+ * `step`, UNCHANGED from the shipped identity (locked by `theme/spacing.test.ts`) EXCEPT
936
+ * `stickyHeaderClearance` (originally 84, then a single derived 108, now the desktop half of the
937
+ * Decision-3 responsive split at 60) and its new `stickyHeaderClearanceMobile` sibling (108) — the
938
+ * deliberate level-0 breaks in the density work; see `deriveSpacing`'s doc (third bullet) for why. */
939
+ export const SPACE_STEP = DEFAULT_SPACE_VALUES.step
940
+
941
+ /** NavLink row line-height at the shipped identity (`1.35`) — `deriveSpacing(0)`'s `rowLineHeight`,
942
+ * UNCHANGED from the shipped identity (locked by `theme/spacing.test.ts`). */
943
+ export const ROW_LINE_HEIGHT = DEFAULT_SPACE_VALUES.rowLineHeight
944
+
945
+ /**
946
+ * Assemble every derive-config-dependent palette family from a resolved {@link DeriveConfig},
947
+ * merged with the structural hand-authored tokens (neutrals' chart-chrome rgba()s, the floating
948
+ * overlay surface, the divider fade) that never vary with the config. Pure function of `config` —
949
+ * zero React, zero `@mantine/*`, zero browser API (the Mantine-free boundary applies here).
950
+ *
951
+ * `ACCENT` / `FILL` / `SURFACE` / `INK` / `SEMANTIC` / `STATUS` below are GENERATED from
952
+ * `deriveTokens(config)` (`./derive.ts`) — never hand-edit one of those hexes; retune the derive
953
+ * config or its calibrated constants instead. `SHADOW` / `BP` above are structural and unaffected.
954
+ */
955
+ /** Parse a `#rrggbb` hex to an `[r, g, b]` triplet — a local, dependency-free copy (this module
956
+ * can't reach into `theme/index.ts`'s own copy, and `hct.ts`'s is not exported). */
957
+ function hexToRgbTriplet(hex: string): [number, number, number] {
958
+ const n = Number.parseInt(hex.slice(1), 16)
959
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
960
+ }
961
+
962
+ /** `rgba(r, g, b, a)` from a hex color — re-expresses the chart-chrome opacity ramps against the
963
+ * DERIVED ink hex instead of a hand-picked one, so a custom `neutral`/seed still tracks. */
964
+ function inkRgba(hex: string, alpha: number): string {
965
+ const [r, g, b] = hexToRgbTriplet(hex)
966
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`
967
+ }
968
+
969
+ function buildPaletteDataUncached(config: DeriveConfig) {
970
+ const DERIVED = deriveTokens(config)
971
+
972
+ /** Spec status hues (`docs/DESIGN-SPEC.md` §2) — shared by SEMANTIC + STATUS below. */
973
+ const SUCCESS: ColorPair = DERIVED.status.good
974
+ const WARNING: ColorPair = DERIVED.status.warn
975
+ const DANGER: ColorPair = DERIVED.status.bad
976
+
977
+ /** Semantic status hues — solids + the family they fill from (alpha applied in the token layer). */
978
+ const SEMANTIC = {
979
+ good: SUCCESS,
980
+ bad: DANGER,
981
+ warn: WARNING,
982
+ } as const
983
+
984
+ /**
985
+ * Score / zone status scale (excellent → poor). `good`/`warn`/`bad` are the SAME spec
986
+ * success/warning/danger pairs as `SEMANTIC` (also the direct source for Badge/Notification/delta
987
+ * -badge status-tint idioms in the theme — one set of hexes, several consumers). `excellent`
988
+ * (top-of-scale grade) and `neutral` keep their prior chart-only families (unchanged BP families).
989
+ */
990
+ const STATUS = {
991
+ excellent: p(BP.forest),
992
+ good: SUCCESS,
993
+ warn: WARNING,
994
+ bad: DANGER,
995
+ neutral: p(BP.gray, 1, 2),
996
+ } as const
997
+
998
+ // The light-scheme opacity bases below key off the DERIVED light `ink` hex — not a hand-picked
999
+ // near-black — so a custom seed/neutral still tracks. At the shipped default that hex is
1000
+ // `#262629` (the old hand-tuned `#262626` this replaces was a pre-derivation approximation, 1 LSB
1001
+ // off on the blue channel); the dark-scheme bases stay flat white (chart chrome inverts to a pure
1002
+ // white ink on dark, not a derived one).
1003
+ const inkLight = DERIVED.ink.ink.light
1004
+
1005
+ /**
1006
+ * Theme-resolved neutrals (line / axis / grid / tooltip chrome). Mirrors the old
1007
+ * useVxTheme() outputs, retuned to the zinc identity.
1008
+ */
1009
+ const NEUTRAL = {
1010
+ line: { light: BP.gray[0], dark: BP.gray[4] }, // primary line
1011
+ line2: { light: BP.gray[1], dark: BP.gray[2] }, // secondary line
1012
+ axis: { light: inkRgba(inkLight, 0.6), dark: 'rgba(255,255,255,0.6)' },
1013
+ axisStroke: { light: inkRgba(inkLight, 0.12), dark: 'rgba(255,255,255,0.12)' },
1014
+ grid: { light: inkRgba(inkLight, 0.07), dark: 'rgba(255,255,255,0.06)' },
1015
+ crosshair: { light: inkRgba(inkLight, 0.32), dark: 'rgba(255,255,255,0.42)' },
1016
+ dotStroke: { light: BP.white, dark: BP.darkGray[1] }, // matches chart-area bg
1017
+ tooltipBg: { light: BP.white, dark: 'rgba(39,39,42,0.96)' },
1018
+ tooltipText: { light: inkRgba(inkLight, 0.88), dark: 'rgba(255,255,255,0.88)' },
1019
+ tooltipMuted: { light: inkRgba(inkLight, 0.5), dark: 'rgba(255,255,255,0.5)' },
1020
+ tooltipBorder: { light: `1px solid ${BP.lightGray[1]}`, dark: 'none' },
1021
+ tooltipShadow: {
1022
+ light: `0 2px 8px ${inkRgba(inkLight, 0.1)}`,
1023
+ dark: '0 2px 8px rgba(0,0,0,0.35)',
1024
+ },
1025
+ // Chart legend text — same DERIVED-ink treatment as axis/grid/tooltip* above (light keys off
1026
+ // `inkLight`; dark stays flat white like every other neutral chart-chrome pair here).
1027
+ legendText: { light: inkRgba(inkLight, 0.82), dark: 'rgba(255,255,255,0.92)' },
1028
+ // Base neutral for hairlines / muted / DIMMED text / overlays — apply opacity via alpha().
1029
+ // Binds to --mantine-color-dimmed, so it is THE dimmed-text lever. Equal to `INK.muted` (the
1030
+ // spec's "muted (secondary text)" row) — kept as its own pair for the pre-existing `--vx-neutral`
1031
+ // name (never renamed), while `INK.muted` below is the new explicit spec-named token. Both read
1032
+ // the SAME generated value (`DERIVED.ink.muted`) so a palette retune can't pull them apart.
1033
+ neutral: DERIVED.ink.muted,
1034
+ } as const
1035
+
1036
+ /** Ink text ramp (`docs/DESIGN-SPEC.md` §2) — primary/emphasis/secondary/tertiary body text. */
1037
+ const INK = {
1038
+ ink: DERIVED.ink.ink, // primary text
1039
+ ink2: DERIVED.ink.ink2, // emphasis body
1040
+ muted: DERIVED.ink.muted, // secondary text (= NEUTRAL.neutral)
1041
+ faint: DERIVED.ink.faint, // tertiary text / micro-labels
1042
+ } as const
1043
+
1044
+ /**
1045
+ * The one saturated sky-blue accent. It has TWO roles, and they are DIFFERENT COLORS —
1046
+ * conflating them is what made dark mode unfixable. The LAW below (not a hand-picked hex) is what
1047
+ * `./derive.ts` implements.
1048
+ *
1049
+ * • `accent` — the accent as INK: link text, active-nav icon, chart lines, focus ring. It is
1050
+ * read AGAINST THE PAGE, so it must be LIGHT on dark and DEEP on light. This pair inverts
1051
+ * across schemes, as it must.
1052
+ *
1053
+ * • `accentFill` — the accent as SURFACE: filled buttons, a checked Switch/Checkbox, the active
1054
+ * Timeline bullet, the Composer send button. It CARRIES A LABEL, so it is squeezed from both
1055
+ * sides at once: white text needs ≥3:1 (the codified UI-component floor — see `./derive.ts`'s
1056
+ * `ON_ACCENT_WHITE_CONTRAST_MIN`) against the fill, AND the control needs ≥3:1 against the page
1057
+ * it sits on. The generator places the fill in the Y=0.165 luminance band that satisfies both
1058
+ * on both pages, so the fill is the SAME hex in both schemes, and `onAccent` is white whenever
1059
+ * that floor holds (a near-black ink otherwise, for a fill brightened past the safety margin).
1060
+ *
1061
+ * `onAccent` is THE foreground for any accent fill. `theme/index.ts` bridges Mantine's
1062
+ * `--mantine-color-<primary>-filled` onto `--vx-accentFill` and every filled foreground onto
1063
+ * `--vx-onAccent`, so ONE token drives the chrome — which is also what makes the theme lab able to
1064
+ * retune the accent live. Mantine's own `autoContrast` cannot express this (it resolves the
1065
+ * foreground scheme-blindly, in JS). Regression-locked by `theme/contrast.test.ts`.
1066
+ */
1067
+ const ACCENT = {
1068
+ accent: DERIVED.accent, // accent as INK — inverts across schemes
1069
+ accentHover: DERIVED.accentHover,
1070
+ accentFill: DERIVED.accentFill, // accent as SURFACE — same hex in both schemes
1071
+ accentFillHover: DERIVED.accentFillHover, // deeper on hover
1072
+ onAccent: DERIVED.onAccent, // text on an accent fill
1073
+ } as const
1074
+
1075
+ /**
1076
+ * Filled-surface hexes for the Mantine accent families — THE FILL BAND. The LAW below lives in
1077
+ * `./derive.ts`, not in a hand-picked hex here.
1078
+ *
1079
+ * A filled control is constrained from both sides at once (the `ACCENT` note above derives this
1080
+ * for the accent): a white label needs ≥4.5:1 against the fill, and the control needs ≥3:1
1081
+ * against the page behind it — on BOTH pages, since a fill does not invert across schemes. In
1082
+ * WCAG terms that pins the fill's relative luminance into one narrow band, ~0.150–0.183. There is
1083
+ * no room for a family to sit outside it: too light and the label dies, too dark and the button
1084
+ * fades into the dark page.
1085
+ *
1086
+ * So every family's fill is its own hue placed at the SAME luminance (0.165, the band's centre) —
1087
+ * `./derive.ts`'s `FILL_LUMINANCE`. The result is a system law rather than a per-color judgement
1088
+ * call: EVERY filled surface reads white, on either page, at ~4.9:1 / ~3.2:1 at the shipped
1089
+ * default.
1090
+ *
1091
+ * `blue` is absent on purpose — it is the accent, and its fill lives in `ACCENT.accentFill` so the
1092
+ * accent keeps ONE source. `dark` is absent too: `color="dark"` is a deliberately near-black
1093
+ * surface, not a band member. Hover is DERIVED in CSS from the fill (see `tokens/index.ts`), so
1094
+ * retuning a fill moves its hover with it. Regression-locked by `theme/contrast.test.ts`.
1095
+ */
1096
+ const FILL = {
1097
+ gray: DERIVED.fill.gray.light,
1098
+ red: DERIVED.fill.red.light,
1099
+ pink: DERIVED.fill.pink.light,
1100
+ grape: DERIVED.fill.grape.light,
1101
+ violet: DERIVED.fill.violet.light,
1102
+ indigo: DERIVED.fill.indigo.light,
1103
+ cyan: DERIVED.fill.cyan.light,
1104
+ teal: DERIVED.fill.teal.light,
1105
+ green: DERIVED.fill.green.light,
1106
+ lime: DERIVED.fill.lime.light,
1107
+ yellow: DERIVED.fill.yellow.light,
1108
+ orange: DERIVED.fill.orange.light,
1109
+ } as const
1110
+
1111
+ /**
1112
+ * App chrome surfaces — the zinc identity for the Mantine theme (`docs/DESIGN-SPEC.md` §2). Only
1113
+ * `overlay`/`divider` (structural, not part of the generator's surface-stop set) stay
1114
+ * hand-authored below.
1115
+ *
1116
+ * `border` ("line") is the STRONG border used broadly for layout/control chrome (AppShell, Table,
1117
+ * Input, Divider, Tabs, Popover, Accordion — everything bound through `--mantine-color-default-
1118
+ * border` / `--mantine-color-gray-{2,3,4}` in the resolver below). `hairline` ("card ring") is a
1119
+ * DISTINCT, thinner pair used ONLY inside `shadow-card`'s embedded ring — cards carry no `border`
1120
+ * property at all, the ring lives in the shadow. Never conflate the two.
1121
+ */
1122
+ const SURFACE = {
1123
+ bg: DERIVED.surface.bg, // page background
1124
+ panel: DERIVED.surface.panel, // cards, controls
1125
+ panelHover: DERIVED.surface.panelHover,
1126
+ // Elevated surface (chart area, `--mantine-color-default-hover`) — same lift as panel-hover.
1127
+ elevated: DERIVED.surface.elevated,
1128
+ border: DERIVED.surface.border, // "line" — strong border (layout/control chrome, NOT the card ring)
1129
+ hairline: DERIVED.surface.hairline, // card ring only — consumed by `SHADOW.card`
1130
+ // Hover/striped/track fallback surface — a faint step between `panel` and `border`. Used by
1131
+ // Table hover/striped, Code, SegmentedControl track fallback, Tabs/Accordion/Menu hover.
1132
+ subtle: DERIVED.surface.subtle,
1133
+ // Floating-layer surface (menus, popovers, tooltips, modals, drawers). Hand-authored: the
1134
+ // generator has no `overlay` stop. On light it reads pure white — a clean lift above the panel;
1135
+ // on dark it reuses the `panelHover` elevated step so detached surfaces sit a shade above the
1136
+ // panel. Paired with `SHADOW.overlay` + a real `border` so Mantine's arrow renders a proper edge
1137
+ // (`docs/DESIGN-SPEC.md` §5).
1138
+ overlay: {
1139
+ light: '#ffffff',
1140
+ dark: 'color-mix(in srgb, #3f3f46 50%, #27272a)',
1141
+ },
1142
+ // Input field surface (docs/DESIGN-SPEC.md §5 field idiom) — reads slightly inset ON a panel.
1143
+ field: DERIVED.surface.field,
1144
+ // Hand-authored: the generator has no `divider` stop — layout separators (header bottom rule,
1145
+ // sidebar child indent) stay a fixed-opacity color-mix, distinct from the card ring.
1146
+ divider: {
1147
+ light: 'color-mix(in srgb, #e5e5e5 65%, transparent)',
1148
+ dark: 'color-mix(in srgb, #ffffff 6%, transparent)',
1149
+ },
1150
+ } as const
1151
+
1152
+ return { ACCENT, FILL, SURFACE, INK, NEUTRAL, SEMANTIC, STATUS }
1153
+ }
1154
+
1155
+ const paletteDataCache = new Map<string, ReturnType<typeof buildPaletteDataUncached>>()
1156
+ /** FIFO cap on `paletteDataCache` — bounds memory when a consumer sweeps many distinct configs
1157
+ * (e.g. a theme-lab slider drag), evicting the oldest inserted entry on overflow. */
1158
+ const PALETTE_DATA_CACHE_MAX = 32
1159
+
1160
+ /** The pinned default-config entry — built once and never stored in, or evicted from,
1161
+ * `paletteDataCache`. `theme/index.ts`'s `baseTheme` / `cssVariablesResolver` are built from this
1162
+ * ONE object at module load (`DEFAULT_PALETTE_DATA`), so this singleton must stay stable forever —
1163
+ * a second, distinct object for the same default config would mean two theme builds disagree. */
1164
+ let defaultPaletteData: ReturnType<typeof buildPaletteDataUncached> | undefined
1165
+
1166
+ /**
1167
+ * Build the full derive-config-dependent palette data for `config` (defaults to
1168
+ * {@link DEFAULT_DERIVE_CONFIG}, the shipped identity). The default config always resolves to one
1169
+ * pinned singleton (see `defaultPaletteData` above); any other config is memoized by value (not
1170
+ * reference) in `paletteDataCache`, capped at `PALETTE_DATA_CACHE_MAX` entries (FIFO eviction), so
1171
+ * repeated calls with an equal config — e.g. from `BasaltProvider` on every render — are a cache
1172
+ * hit, not a re-derivation.
1173
+ */
1174
+ export function buildPaletteData(config: DeriveConfig = DEFAULT_DERIVE_CONFIG): PaletteData {
1175
+ if (isDefaultDeriveConfig(config)) {
1176
+ defaultPaletteData ??= buildPaletteDataUncached(config)
1177
+ return defaultPaletteData
1178
+ }
1179
+ const key = JSON.stringify(config)
1180
+ const cached = paletteDataCache.get(key)
1181
+ if (cached) return cached
1182
+ const data = buildPaletteDataUncached(config)
1183
+ paletteDataCache.set(key, data)
1184
+ if (paletteDataCache.size > PALETTE_DATA_CACHE_MAX) {
1185
+ const oldestKey = paletteDataCache.keys().next().value
1186
+ if (oldestKey !== undefined) paletteDataCache.delete(oldestKey)
1187
+ }
1188
+ return data
1189
+ }
1190
+
1191
+ /** The shape {@link buildPaletteData} returns — the derive-config-dependent half of the palette. */
1192
+ export type PaletteData = ReturnType<typeof buildPaletteDataUncached>
1193
+
1194
+ /** The framework's shipped color identity — the generator's output at the default seed/knobs,
1195
+ * computed once (memoized) at module load. See `./derive.ts` for the laws. */
1196
+ const STATIC_PALETTE_DATA = buildPaletteData(DEFAULT_DERIVE_CONFIG)
1197
+
1198
+ /** Semantic status hues — solids + the family they fill from (alpha applied in the token layer).
1199
+ * GENERATED — see `buildPaletteData` above. */
1200
+ export const SEMANTIC = STATIC_PALETTE_DATA.SEMANTIC
1201
+
1202
+ /**
1203
+ * Score / zone status scale (excellent → poor). `good`/`warn`/`bad` are the SAME spec
1204
+ * success/warning/danger pairs as `SEMANTIC`. GENERATED — see `buildPaletteData` above.
1205
+ */
1206
+ export const STATUS = STATIC_PALETTE_DATA.STATUS
1207
+
1208
+ /**
1209
+ * Theme-resolved neutrals (line / axis / grid / tooltip chrome). GENERATED — see `buildPaletteData`
1210
+ * above.
1211
+ */
1212
+ export const NEUTRAL = STATIC_PALETTE_DATA.NEUTRAL
1213
+
1214
+ /** Ink text ramp (`docs/DESIGN-SPEC.md` §2). GENERATED — see `buildPaletteData` above. */
1215
+ export const INK = STATIC_PALETTE_DATA.INK
1216
+
1217
+ /** The one saturated sky-blue accent. GENERATED — see `buildPaletteData` above. */
1218
+ export const ACCENT = STATIC_PALETTE_DATA.ACCENT
1219
+
1220
+ /** Filled-surface hexes for the Mantine accent families — THE FILL BAND. GENERATED — see
1221
+ * `buildPaletteData` above. */
1222
+ export const FILL = STATIC_PALETTE_DATA.FILL
1223
+
1224
+ /** App chrome surfaces — the zinc identity for the Mantine theme (`docs/DESIGN-SPEC.md` §2).
1225
+ * GENERATED — see `buildPaletteData` above. */
1226
+ export const SURFACE = STATIC_PALETTE_DATA.SURFACE