basalt-ui 1.1.0 → 1.2.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 +37 -0
  3. package/README.md +47 -5
  4. package/agent/rules/basalt-app.md +126 -0
  5. package/agent/rules/basalt-content.md +3 -1
  6. package/agent/skills/basalt-app/SKILL.md +32 -10
  7. package/configs/check.yml +3 -1
  8. package/configs/oxlint.json +1 -1
  9. package/dist/agent/part-list.d.ts.map +1 -1
  10. package/dist/agent/part-list.js +17 -7
  11. package/dist/agent/stick-to-bottom.js +2 -2
  12. package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
  13. package/dist/agent-chat/thread-detail-panel.js +37 -33
  14. package/dist/agent-chat/thread-message.d.ts.map +1 -1
  15. package/dist/agent-chat/thread-message.js +8 -5
  16. package/dist/agent-chat/thread-outcome-card.js +3 -3
  17. package/dist/agent-chat/thread-workspace.js +1 -1
  18. package/dist/charts/primitives/ChartLegend.js +2 -0
  19. package/dist/charts/primitives/ChartTooltip.js +2 -1
  20. package/dist/cli/index.d.ts +21 -1
  21. package/dist/cli/index.d.ts.map +1 -1
  22. package/dist/cli/index.js +50 -12
  23. package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
  24. package/dist/connectivity/connectivity-indicator.js +3 -3
  25. package/dist/content/article-card.module.css +7 -5
  26. package/dist/content/article-layout.module.css +16 -12
  27. package/dist/content/callout.module.css +4 -4
  28. package/dist/content/code-block.module.css +8 -7
  29. package/dist/content/guide.module.css +3 -3
  30. package/dist/content/mermaid.module.css +2 -2
  31. package/dist/content/prose.module.css +59 -29
  32. package/dist/content/reading-progress.module.css +2 -0
  33. package/dist/content/toc.module.css +6 -3
  34. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  35. package/dist/dashboard/delta-badge.js +10 -2
  36. package/dist/dashboard/empty-state.d.ts.map +1 -1
  37. package/dist/dashboard/empty-state.js +3 -16
  38. package/dist/dashboard/settings-section.js +2 -2
  39. package/dist/dashboard/settings-section.module.css +2 -2
  40. package/dist/dashboard/stat-card.js +2 -1
  41. package/dist/data/virtual-list.d.ts.map +1 -1
  42. package/dist/data/virtual-list.js +12 -2
  43. package/dist/forms/FormErrorSummary.js +2 -2
  44. package/dist/guard/index.d.ts +20 -4
  45. package/dist/guard/index.d.ts.map +1 -1
  46. package/dist/guard/index.js +250 -37
  47. package/dist/guard/types.d.ts +24 -3
  48. package/dist/guard/types.d.ts.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/provider/index.d.ts +30 -1
  52. package/dist/provider/index.d.ts.map +1 -1
  53. package/dist/provider/index.js +32 -7
  54. package/dist/provider/lab-theme.d.ts +39 -0
  55. package/dist/provider/lab-theme.d.ts.map +1 -0
  56. package/dist/provider/lab-theme.js +52 -0
  57. package/dist/shell/app-header.module.css +2 -2
  58. package/dist/shell/app-mobile-nav.module.css +1 -1
  59. package/dist/shell/app-sidebar-account.d.ts.map +1 -1
  60. package/dist/shell/app-sidebar-account.js +4 -2
  61. package/dist/shell/app-sidebar.d.ts.map +1 -1
  62. package/dist/shell/app-sidebar.js +4 -2
  63. package/dist/shell/app-sidebar.module.css +36 -26
  64. package/dist/shell/index.d.ts.map +1 -1
  65. package/dist/shell/index.js +11 -4
  66. package/dist/shell/sidebar-search.module.css +16 -4
  67. package/dist/styles.css +1 -1
  68. package/dist/surfaces.d.ts +16 -12
  69. package/dist/surfaces.d.ts.map +1 -1
  70. package/dist/surfaces.js +12 -4
  71. package/dist/theme/controls.module.css +1 -1
  72. package/dist/theme/floating.module.css +1 -1
  73. package/dist/theme/index.d.ts +116 -11
  74. package/dist/theme/index.d.ts.map +1 -1
  75. package/dist/theme/index.js +703 -566
  76. package/dist/theme/nav-link.module.css +1 -1
  77. package/dist/theme/use-basalt-spacing.d.ts +3 -0
  78. package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
  79. package/dist/theme/use-basalt-spacing.js +8 -0
  80. package/dist/theme-lab/derive-controls.d.ts +13 -0
  81. package/dist/theme-lab/derive-controls.d.ts.map +1 -0
  82. package/dist/theme-lab/derive-controls.js +137 -0
  83. package/dist/theme-lab/derive-state.d.ts +55 -0
  84. package/dist/theme-lab/derive-state.d.ts.map +1 -0
  85. package/dist/theme-lab/derive-state.js +81 -0
  86. package/dist/theme-lab/index.d.ts +12 -2
  87. package/dist/theme-lab/index.d.ts.map +1 -1
  88. package/dist/theme-lab/index.js +13 -62
  89. package/dist/theme-toggle/index.d.ts.map +1 -1
  90. package/dist/theme-toggle/index.js +3 -2
  91. package/dist/tokens/derive.d.ts +89 -0
  92. package/dist/tokens/derive.d.ts.map +1 -0
  93. package/dist/tokens/derive.js +250 -0
  94. package/dist/tokens/hct.d.ts +34 -0
  95. package/dist/tokens/hct.d.ts.map +1 -0
  96. package/dist/tokens/hct.js +159 -0
  97. package/dist/tokens/index.d.ts +71 -7
  98. package/dist/tokens/index.d.ts.map +1 -1
  99. package/dist/tokens/index.js +284 -46
  100. package/dist/tokens/palette.d.ts +984 -167
  101. package/dist/tokens/palette.d.ts.map +1 -1
  102. package/dist/tokens/palette.js +617 -119
  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 +5 -4
  110. package/package.json +24 -9
  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 +112 -20
  121. package/src/cli/init-sync.test.ts +68 -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 +416 -5
  141. package/src/guard/index.ts +367 -45
  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 +1 -1
  156. package/src/surfaces.ts +25 -11
  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 +395 -45
  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
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Cross-level RELATION tests for the density knob — the audit that drove the Fix 1-7 pass in this
3
+ * commit found the knob correct only at level 0 because every prior test was a level-0 snapshot, not
4
+ * a relation that has to hold at every level. These loop over the full accepted range instead of
5
+ * spot-checking one or two levels, so a future edit that reintroduces one of the audited defects
6
+ * fails here regardless of which level it breaks first.
7
+ *
8
+ * `ALL_LEVELS` is derived from {@link DENSITY_LEVEL_RANGE} (`deriveSpacing`'s accepted `[-3, 3]`
9
+ * range, narrowed from `[-5, 5]` by Fix 7 in this same commit — see `deriveSpacing`'s JSDoc in
10
+ * `../tokens/palette` for why) rather than a hardcoded literal, so a future range change is picked
11
+ * up here automatically instead of silently narrowing this file's own coverage. `ALL_RADIUS_LEVELS`
12
+ * is the same derivation off {@link RADIUS_LEVEL_RANGE} — `deriveRadius` still accepts the wider
13
+ * `[-5, 5]`, so the radius-only relation test below (Fix 3) samples MORE points than the density
14
+ * tests, every one of them a real, valid radius level.
15
+ */
16
+ import { DEFAULT_THEME, mergeMantineTheme } from '@mantine/core'
17
+ import type { MantineTheme } from '@mantine/core'
18
+ import { describe, expect, test } from 'bun:test'
19
+ import { VX } from '../tokens'
20
+ import {
21
+ DENSITY_LEVEL_RANGE,
22
+ RADIUS_LEVEL_RANGE,
23
+ deriveRadius,
24
+ deriveSpacing,
25
+ scaleSpace,
26
+ SPACE,
27
+ SPACE_FIXED,
28
+ SPACE_SCALE,
29
+ SPACE_STEP,
30
+ } from '../tokens/palette'
31
+ import { baseTheme } from './index'
32
+
33
+ const theme: MantineTheme = mergeMantineTheme(DEFAULT_THEME, baseTheme)
34
+ const ALL_LEVELS = Array.from(
35
+ { length: DENSITY_LEVEL_RANGE.max - DENSITY_LEVEL_RANGE.min + 1 },
36
+ (_, i) => DENSITY_LEVEL_RANGE.min + i,
37
+ )
38
+ const ALL_RADIUS_LEVELS = Array.from(
39
+ { length: RADIUS_LEVEL_RANGE.max - RADIUS_LEVEL_RANGE.min + 1 },
40
+ (_, i) => RADIUS_LEVEL_RANGE.min + i,
41
+ )
42
+
43
+ /** Flatten `deriveSpacing(level)`'s anchors + scale + step into one numeric record — `rowLineHeight`
44
+ * is excluded (it is additive, not routed through `scaleSpace`, and always moves, which would
45
+ * inflate a change ratio and can never be "frozen"). Used by the "Fix 7" resolution-honesty block. */
46
+ function flattenSpacing(level: number): Record<string, number> {
47
+ const { anchors, scale, step } = deriveSpacing(level)
48
+ return { ...anchors, ...scale, ...step }
49
+ }
50
+
51
+ describe('Fix 1 — input height, button height, and ActionIcon size never drift', () => {
52
+ test('every level: controlHeight AND inputHeight resolve to the exact scaled anchor, not merely to each other', () => {
53
+ // The old form of this test (`controlHeight === inputHeight`) is true BY CONSTRUCTION — both
54
+ // keys hold the literal same `CONTROL_HEIGHT_BASE` and are scaled by the SAME deterministic
55
+ // `scaleSpace(value, level, multiplier)` call, so they can never disagree regardless of what the
56
+ // multiplier law actually computes. Assert each against its own hardcoded expected value instead
57
+ // — this bites on a change to `CONTROL_HEIGHT_BASE`, the multiplier law, OR a divergence between
58
+ // the two keys, none of which the old form could catch.
59
+ const expected: Record<number, number> = {
60
+ [-3]: 29,
61
+ [-2]: 34,
62
+ [-1]: 38,
63
+ 0: 42,
64
+ 1: 46,
65
+ 2: 50,
66
+ 3: 55,
67
+ }
68
+ for (const level of ALL_LEVELS) {
69
+ const { anchors } = deriveSpacing(level)
70
+ expect(anchors.inputHeight).toBe(expected[level])
71
+ expect(anchors.controlHeight).toBe(expected[level])
72
+ }
73
+ })
74
+
75
+ test('every level: Input/Button/ActionIcon vars() resolve to the SAME calc() shape at size=md', () => {
76
+ // The three overrides read different CSS custom properties (`--vx-space-input-height` vs.
77
+ // `--vx-space-control-height`) but the same anchor, so their `calc(...)` bodies differ only in
78
+ // var NAME, never in the numeric anchor they carry.
79
+ const inputVars = baseTheme.components?.['Input']?.vars
80
+ const buttonVars = baseTheme.components?.['Button']?.vars
81
+ const actionIconVars = baseTheme.components?.['ActionIcon']?.vars
82
+ const inputResult = inputVars?.(theme, { size: 'md' } as never, {} as never)
83
+ const buttonResult = buttonVars?.(theme, { size: 'md' } as never, {} as never)
84
+ const actionIconResult = actionIconVars?.(theme, { size: 'md' } as never, {} as never)
85
+ expect(inputResult?.wrapper?.['--input-height']).toBe(
86
+ 'calc(var(--vx-space-input-height) * var(--mantine-scale))',
87
+ )
88
+ expect(buttonResult?.root?.['--button-height']).toBe(
89
+ 'calc(var(--vx-space-control-height) * var(--mantine-scale))',
90
+ )
91
+ expect(actionIconResult?.root?.['--ai-size']).toBe(
92
+ 'calc(var(--vx-space-control-height) * var(--mantine-scale))',
93
+ )
94
+ })
95
+ })
96
+
97
+ describe('Fix 2 — the 4px stack rhythm holds its 2:1 pairs at every level', () => {
98
+ test('stackXl = 2 * stackMd, stackLg = 2 * stackSm, and every step is its documented multiple of stackXs', () => {
99
+ for (const level of ALL_LEVELS) {
100
+ const { anchors } = deriveSpacing(level)
101
+ expect(anchors.stackXl).toBe(2 * anchors.stackMd)
102
+ expect(anchors.stackLg).toBe(2 * anchors.stackSm)
103
+ // The DOCUMENTED law (`deriveSpacing`'s JSDoc): stackSm/stackMd/stackLg/stackXl are exactly
104
+ // 2x/3x/4x/6x stackXs. A real equality against that documented multiple — not a `% === 0`
105
+ // divisibility check, which the two ratio assertions above already guarantee for free (any
106
+ // value that IS `stackXs * N` trivially divides `stackXs`) and so adds zero independent
107
+ // coverage on top of them.
108
+ expect(anchors.stackSm).toBe(2 * anchors.stackXs)
109
+ expect(anchors.stackMd).toBe(3 * anchors.stackXs)
110
+ expect(anchors.stackLg).toBe(4 * anchors.stackXs)
111
+ expect(anchors.stackXl).toBe(6 * anchors.stackXs)
112
+ }
113
+ })
114
+ })
115
+
116
+ describe('Fix 3 — SegmentedControl concentricity holds at every RADIUS level', () => {
117
+ test('RADIUS.card === RADIUS_STEP.tight + segmentedTrackInset, every RADIUS level (the full [-5, 5] range, not the narrower density range)', () => {
118
+ for (const level of ALL_RADIUS_LEVELS) {
119
+ const radius = deriveRadius(level)
120
+ expect(radius.card).toBe(radius.tight + SPACE_FIXED.segmentedTrackInset)
121
+ }
122
+ })
123
+
124
+ test('at the radius floor (-5), tight is clamped exactly to 0 while card is not — the closest the accepted range gets to breaking concentricity', () => {
125
+ const radius = deriveRadius(RADIUS_LEVEL_RANGE.min)
126
+ expect(radius.tight).toBe(0) // clampRadius(ctrl - 1) = clampRadius((6 - 5) - 1) = clampRadius(0)
127
+ expect(radius.card).toBe(2) // clampRadius(7 - 5) = 2, still positive — the clamp doesn't engage
128
+ // Concentricity holds here only because `ctrl - 1` landed EXACTLY on the clamp floor (0), not
129
+ // below it: one level further down (out of the accepted range) would clamp `tight` to 0 while
130
+ // `card` kept falling, breaking `card === tight + 2` — which is exactly why the range stops here.
131
+ expect(radius.card).toBe(radius.tight + SPACE_FIXED.segmentedTrackInset)
132
+ })
133
+
134
+ test("segmentedTrackInset never moves with density — it's a SPACE_FIXED constant, not part of deriveSpacing's step output at ANY level", () => {
135
+ // Claim 1 (the constant itself): the shipped value.
136
+ expect(SPACE_FIXED.segmentedTrackInset).toBe(2)
137
+ // Claim 2 (deriveSpacing has no such key any more): a bare `.toBe(2)` on the constant alone would
138
+ // still pass even if `segmentedTrackInset` were ALSO reintroduced into `SPACE_STEP_BASE` at a
139
+ // level-0 value of 2 — it would just happen to coincide there. Assert its actual absence from
140
+ // `step` at every level instead, which a reintroduction WOULD break immediately.
141
+ for (const level of ALL_LEVELS) {
142
+ expect(deriveSpacing(level).step).not.toHaveProperty('segmentedTrackInset')
143
+ }
144
+ })
145
+ })
146
+
147
+ describe('Fix 4 — every interactive target clears the WCAG 2.5.8 24px floor at every level', () => {
148
+ test('sidebar search trigger (and its collapsed rail ActionIcon, which reads the same value)', () => {
149
+ for (const level of ALL_LEVELS) {
150
+ expect(deriveSpacing(level).step.sidebarSearchTriggerHeight).toBeGreaterThanOrEqual(24)
151
+ }
152
+ })
153
+
154
+ test('a NavLink/Menu row (2 * rowInsetY padding + rowLineHeight * the fixed md text step)', () => {
155
+ for (const level of ALL_LEVELS) {
156
+ const { anchors, rowLineHeight } = deriveSpacing(level)
157
+ const rowHeight = 2 * anchors.rowInsetY + rowLineHeight * VX.text.md
158
+ expect(rowHeight).toBeGreaterThanOrEqual(24)
159
+ }
160
+ })
161
+
162
+ test('the mobile header actions row (appHeaderMobileActionsHeight — the closest in-scope, density-tracked mobile nav target size; the app-mobile-nav tab bar itself is a fixed AppShell footer height, out of scope for this pass)', () => {
163
+ for (const level of ALL_LEVELS) {
164
+ expect(deriveSpacing(level).step.appHeaderMobileActionsHeight).toBeGreaterThanOrEqual(24)
165
+ }
166
+ })
167
+
168
+ test('the resolved control/input height (size="md" Button/ActionIcon/Input) clears the floor too', () => {
169
+ for (const level of ALL_LEVELS) {
170
+ const { anchors } = deriveSpacing(level)
171
+ expect(anchors.controlHeight).toBeGreaterThanOrEqual(24)
172
+ expect(anchors.inputHeight).toBeGreaterThanOrEqual(24)
173
+ }
174
+ })
175
+ })
176
+
177
+ describe('Fix 5 — scaleSpace floors a sub-1 base at 1 (the inverted-clamp regression)', () => {
178
+ test('a base below 1 that would round to 0 floors at 1 instead', () => {
179
+ // round(0.5 * 0.35) = round(0.175) = 0 without the unconditional floor — the exact regression
180
+ // the old `value >= 1 ? ... : scaled` guard let through (see `scaleSpace`'s doc).
181
+ expect(scaleSpace(0.5, -5, 0.35)).toBe(1)
182
+ })
183
+
184
+ test('a base below 1 at level 0 still returns verbatim (bypasses scaling entirely)', () => {
185
+ expect(scaleSpace(0.5, 0, 1)).toBe(0.5)
186
+ })
187
+ })
188
+
189
+ /**
190
+ * Faithful reconstruction of the pre-Fix-7 law: IDENTICAL structural shape to the current
191
+ * `deriveSpacing` (shared stack-unit rebuild, the WCAG floor, the sticky-clearance derivation) —
192
+ * ONLY the multiplier coefficient (0.1 -> 0.06) and the accepted range ([-3,3] -> [-5,5]) revert,
193
+ * exactly the regression the "Fix 7" resolution-floor block below exists to catch.
194
+ */
195
+ function oldLawFlatten(level: number): Record<string, number> {
196
+ const multiplier = 1 + 0.06 * level
197
+ const anchors: Record<string, number> = {}
198
+ for (const [k, v] of Object.entries(SPACE)) anchors[k] = scaleSpace(v, level, multiplier)
199
+ const stackUnit = scaleSpace(4, level, multiplier)
200
+ anchors['stackXs'] = stackUnit
201
+ anchors['stackSm'] = stackUnit * 2
202
+ anchors['stackMd'] = stackUnit * 3
203
+ anchors['stackLg'] = stackUnit * 4
204
+ anchors['stackXl'] = stackUnit * 6
205
+ const scale: Record<string, number> = {}
206
+ for (const [k, v] of Object.entries(SPACE_SCALE)) scale[k] = scaleSpace(v, level, multiplier)
207
+ const step: Record<string, number> = {}
208
+ for (const [k, v] of Object.entries(SPACE_STEP)) {
209
+ if (k === 'stickyHeaderClearance' || k === 'stickyHeaderClearanceMobile') continue
210
+ step[k] = scaleSpace(v, level, multiplier)
211
+ }
212
+ step['sidebarSearchTriggerHeight'] = Math.max(24, step['sidebarSearchTriggerHeight']!)
213
+ step['stickyHeaderClearance'] = step['appShellHeaderHeight']! + anchors['stackMd']!
214
+ step['stickyHeaderClearanceMobile'] = step['appShellHeaderMobileHeight']! + anchors['stackMd']!
215
+ return { ...anchors, ...scale, ...step }
216
+ }
217
+
218
+ describe("Fix 7 — the knob's resolution is honest at every notch", () => {
219
+ test('adjacent-notch resolution floor: more than 70% of the flattened spacing set changes at every step', () => {
220
+ for (let i = 0; i < ALL_LEVELS.length - 1; i++) {
221
+ const a = flattenSpacing(ALL_LEVELS[i]!)
222
+ const b = flattenSpacing(ALL_LEVELS[i + 1]!)
223
+ const keys = Object.keys(a)
224
+ const changed = keys.filter((k) => a[k] !== b[k]).length
225
+ // Observed minimum under the current 0.1/±3 law is ~0.759 (level -3 -> -2) — the 0.7 floor
226
+ // leaves a small margin for legitimate retuning while still catching the regression the next
227
+ // test proves it catches.
228
+ expect(changed / keys.length).toBeGreaterThan(0.7)
229
+ }
230
+ })
231
+
232
+ test('regression proof: the OLD 0.06/±5 law fails the SAME 0.7 floor — confirms the floor above actually bites', () => {
233
+ // Run here, not merely claimed, so a future edit to the CURRENT law can't silently make this
234
+ // proof stale without failing too — see `oldLawFlatten`'s own doc above.
235
+ const oldLawLevels = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
236
+ let minRatio = 1
237
+ for (let i = 0; i < oldLawLevels.length - 1; i++) {
238
+ const a = oldLawFlatten(oldLawLevels[i]!)
239
+ const b = oldLawFlatten(oldLawLevels[i + 1]!)
240
+ const keys = Object.keys(a)
241
+ const changed = keys.filter((k) => a[k] !== b[k]).length
242
+ minRatio = Math.min(minRatio, changed / keys.length)
243
+ }
244
+ // Observed: ~0.491 (level -4 -> -3 and level 3 -> 4), well under the 0.7 floor above — the old
245
+ // law's dead zone this whole fix replaced.
246
+ expect(minRatio).toBeLessThan(0.7)
247
+ })
248
+
249
+ test('frozen-vs-baseline ceiling: fewer than 25 of the ~108 values equal their level-0 value at any non-zero level', () => {
250
+ // Measured under the 0.1/±3 law: worst case is 22 (at level ±1) — down from 43 under the old
251
+ // 0.06/±5 law. The ceiling of 25 leaves margin while still catching a future step reduction
252
+ // that reintroduces that dead zone.
253
+ const baseline = flattenSpacing(0)
254
+ const keys = Object.keys(baseline)
255
+ for (const level of ALL_LEVELS) {
256
+ if (level === 0) continue
257
+ const values = flattenSpacing(level)
258
+ const frozen = keys.filter((k) => values[k] === baseline[k]).length
259
+ expect(frozen).toBeLessThan(25)
260
+ }
261
+ })
262
+
263
+ test('monotonicity: every flattened value is non-decreasing across adjacent levels', () => {
264
+ for (let i = 0; i < ALL_LEVELS.length - 1; i++) {
265
+ const a = flattenSpacing(ALL_LEVELS[i]!)
266
+ const b = flattenSpacing(ALL_LEVELS[i + 1]!)
267
+ for (const key of Object.keys(a)) {
268
+ expect(b[key]!).toBeGreaterThanOrEqual(a[key]!)
269
+ }
270
+ }
271
+ })
272
+
273
+ test('endpoint preservation: deriveSpacing(±3) reproduces the exact value set the old deriveSpacing(±5) produced', () => {
274
+ expect(deriveSpacing(-3).anchors.inputHeight).toBe(29)
275
+ expect(deriveSpacing(3).anchors.inputHeight).toBe(55)
276
+ expect(deriveSpacing(-3).anchors.rowInsetX).toBe(7)
277
+ expect(deriveSpacing(3).anchors.rowInsetX).toBe(13)
278
+ // `stickyHeaderClearance`/`stickyHeaderClearanceMobile` are EXCLUDED here on purpose — since both
279
+ // now DERIVE from their own AppShell header instead of scaling off an independent base (see
280
+ // `deriveSpacing`'s doc, third bullet, Decision 3), neither reproduced the old ±5 envelope to
281
+ // begin with; their own law is asserted by the dedicated describe block in `tokens/density.test.ts`
282
+ // (specific low/zero/high values) AND by the "Fix 8" describe block below in this same file
283
+ // (the generic `clearance = header + anchors.stackMd` relation, looped over every level).
284
+ expect(deriveSpacing(-3).rowLineHeight).toBe(1.25)
285
+ expect(deriveSpacing(3).rowLineHeight).toBe(1.45)
286
+ })
287
+ })
288
+
289
+ describe('Fix 8 — the sticky-header clearance clears its OWN breakpoint header, exactly (Decision 3 — desktop/mobile split)', () => {
290
+ test('desktop clearance = appShellHeaderHeight + stackMd, exactly, at every level', () => {
291
+ for (const level of ALL_LEVELS) {
292
+ const { step, anchors } = deriveSpacing(level)
293
+ expect(step.stickyHeaderClearance).toBe(step.appShellHeaderHeight + anchors.stackMd)
294
+ }
295
+ })
296
+
297
+ test('mobile clearance = appShellHeaderMobileHeight + stackMd, exactly, at every level', () => {
298
+ for (const level of ALL_LEVELS) {
299
+ const { step, anchors } = deriveSpacing(level)
300
+ expect(step.stickyHeaderClearanceMobile).toBe(
301
+ step.appShellHeaderMobileHeight + anchors.stackMd,
302
+ )
303
+ }
304
+ })
305
+
306
+ test('mobile clearance exceeds desktop clearance at every level — catches a swap of the two formulas', () => {
307
+ // Both formulas add the SAME `anchors.stackMd` breathing room, so this reduces to
308
+ // `mobileHeader > desktopHeader`, which holds at every level today — but a bug that swapped
309
+ // which header feeds which key would flip this comparison immediately.
310
+ for (const level of ALL_LEVELS) {
311
+ const { step } = deriveSpacing(level)
312
+ expect(step.stickyHeaderClearanceMobile).toBeGreaterThan(step.stickyHeaderClearance)
313
+ }
314
+ })
315
+
316
+ // The "both breathing-room margins (clearance minus own header) are monotonically non-decreasing"
317
+ // check used to live here as its own test — deleted, not merely renamed: the two tests above this
318
+ // one already assert `clearance = header + anchors.stackMd` EXACTLY at every level, so
319
+ // `clearance - header` is identically `anchors.stackMd` — its monotonicity adds no coverage beyond
320
+ // what "Fix 7"'s global "every flattened value is non-decreasing across adjacent levels" test
321
+ // already guarantees (`stackMd` is one of the flattened anchors that test loops over). A bug this
322
+ // block could catch independently of both of those would have to leave `clearance - header`
323
+ // non-monotonic while `clearance = header + stackMd` still holds exactly and `stackMd` itself still
324
+ // stays monotonic — impossible by substitution.
325
+ })
326
+
327
+ describe('Fix 6 — BasaltShell AppShell dimensions track density', () => {
328
+ test('desktop header always holds a size="md" control', () => {
329
+ for (const level of ALL_LEVELS) {
330
+ const { step, anchors } = deriveSpacing(level)
331
+ expect(step.appShellHeaderHeight).toBeGreaterThanOrEqual(anchors.controlHeight)
332
+ }
333
+ })
334
+
335
+ test('the collapsed rail content box (rail width minus its own row inset) stays positive', () => {
336
+ for (const level of ALL_LEVELS) {
337
+ const { step, anchors } = deriveSpacing(level)
338
+ expect(step.appShellNavbarRailWidth - 2 * anchors.rowInsetX).toBeGreaterThan(0)
339
+ }
340
+ })
341
+
342
+ test("mobile header row-1 budget never falls below Mantine's static default ActionIcon (22px)", () => {
343
+ // The 22px floor is `--ai-size-sm` — verified directly against the INSTALLED Mantine source
344
+ // (`@mantine/core/styles/ActionIcon.css`: `--ai-size-xs: 18px; --ai-size-sm: 22px; --ai-size-md:
345
+ // 28px; ...`), not recalled from memory. The budget at every level in `[-3, 3]` under the current
346
+ // law: 23 / 26 / 28 / 32 / 36 / 38 / 41 (level -3 through +3) — never below the floor, with the
347
+ // smallest margin (1px) at level -3, not at -2 as sometimes assumed by eye.
348
+ //
349
+ // Row 1 is the REMAINDER of `appShellHeaderMobileHeight`'s documented sum (row 1 + `SPACE_SCALE.sm`
350
+ // + `appHeaderMobileActionsHeight`), so raising an addend without raising the total takes the
351
+ // difference straight out of this budget. That is exactly what the component-roominess retune did
352
+ // — `SPACE_SCALE.sm` 12 -> 13 briefly drove level -3 to 22, flush against the floor — and why the
353
+ // mobile header went 96 -> 97 in the same change. See that constant's JSDoc (`tokens/palette.ts`):
354
+ // it names this test as the thing that measures the drift, and computing the header from its
355
+ // addends as the fix that would make the drift impossible.
356
+ for (const level of ALL_LEVELS) {
357
+ const { step, scale } = deriveSpacing(level)
358
+ const budget = step.appShellHeaderMobileHeight - step.appHeaderMobileActionsHeight - scale.sm
359
+ expect(budget).toBeGreaterThanOrEqual(22)
360
+ }
361
+ })
362
+
363
+ test('the mobile header row-1 budget is monotonically non-decreasing across levels', () => {
364
+ const budgets = ALL_LEVELS.map((level) => {
365
+ const { step, scale } = deriveSpacing(level)
366
+ return step.appShellHeaderMobileHeight - step.appHeaderMobileActionsHeight - scale.sm
367
+ })
368
+ for (let i = 1; i < budgets.length; i++) {
369
+ expect(budgets[i]).toBeGreaterThanOrEqual(budgets[i - 1]!)
370
+ }
371
+ })
372
+
373
+ test('the collapsed-rail content box is monotonically non-decreasing across levels', () => {
374
+ const boxes = ALL_LEVELS.map((level) => {
375
+ const { step, anchors } = deriveSpacing(level)
376
+ return step.appShellNavbarRailWidth - 2 * anchors.rowInsetX
377
+ })
378
+ for (let i = 1; i < boxes.length; i++) {
379
+ expect(boxes[i]).toBeGreaterThanOrEqual(boxes[i - 1]!)
380
+ }
381
+ })
382
+
383
+ test('the navbar label column never shrinks as density rises', () => {
384
+ const columns = ALL_LEVELS.map((level) => {
385
+ const { step, anchors } = deriveSpacing(level)
386
+ return step.appShellNavbarWidth - (4 * anchors.rowInsetX + step.navIconGap)
387
+ })
388
+ for (let i = 1; i < columns.length; i++) {
389
+ expect(columns[i]).toBeGreaterThanOrEqual(columns[i - 1]!)
390
+ }
391
+ })
392
+
393
+ // The "header/rail 48-coincidence at level 0" check that used to live here is deleted, not
394
+ // rewritten: it asserted `appShellHeaderHeight === appShellNavbarRailWidth` at level 0, which is
395
+ // true BY CONSTRUCTION (both `SPACE_STEP_BASE` entries hold the literal same base, 48, and are
396
+ // mapped through the same deterministic `scaleSpace` call) and stays true at every OTHER level for
397
+ // the identical reason — no value-based assertion can distinguish "these two happen to share a
398
+ // base" (a coincidence) from "one is derived from the other" (a law) without mutating the source,
399
+ // which is out of scope for a value-level test. The actual claim (they are two INDEPENDENT
400
+ // `SPACE_STEP_BASE` entries, not one derived from the other) is already documented at the source —
401
+ // see `appShellHeaderHeight`'s own JSDoc in `tokens/palette.ts`.
402
+
403
+ test('the footer stays a structural literal — no density-tracking entry for it, and the sm:0 landmine stays fenced', () => {
404
+ for (const level of ALL_LEVELS) {
405
+ expect(deriveSpacing(level).step).not.toHaveProperty('appShellFooterHeight')
406
+ }
407
+ // `scaleSpace(0, level, m)` floors at 1 for any non-zero level — this is why `shell/index.tsx`'s
408
+ // `footer.sm` stays a literal 0, never routed through the density law (it would paint a 1px
409
+ // desktop footer strip at every non-zero level).
410
+ expect(scaleSpace(0, -5, 0.7)).toBe(1)
411
+ expect(scaleSpace(0, 5, 1.3)).toBe(1)
412
+ })
413
+ })
414
+
415
+ describe('Fix 9 — the Mantine spacing scale keeps its strict xs < sm < md < lg < xl ordering at every level', () => {
416
+ test('every level: the five scale stops are strictly increasing, never tying or inverting', () => {
417
+ // Every consumer `p=`/`m=`/`gap=` prop app-wide resolves through this scale, and its five stops
418
+ // are independently rounded (unlike the anchor group's shared-unit stack rhythm) — a retune plus
419
+ // rounding could tie or invert two adjacent stops with nothing else in this file catching it.
420
+ for (const level of ALL_LEVELS) {
421
+ const { scale } = deriveSpacing(level)
422
+ expect(scale.xs).toBeLessThan(scale.sm)
423
+ expect(scale.sm).toBeLessThan(scale.md)
424
+ expect(scale.md).toBeLessThan(scale.lg)
425
+ expect(scale.lg).toBeLessThan(scale.xl)
426
+ }
427
+ })
428
+ })
@@ -0,0 +1,101 @@
1
+ /**
2
+ * `createBasaltTheme`'s `{ derive }` option — the graduation of the six-knob derive config into a
3
+ * first-class consumer API. Two invariants:
4
+ *
5
+ * 1. The DEFAULT path (no `options`, or a `derive` that resolves back to
6
+ * `DEFAULT_DERIVE_CONFIG`) stays byte-identical to the pre-baked static palette — zero extra
7
+ * derivation work, and `theme.other.basaltDerive` stays unset (the provider's "or is absent"
8
+ * tolerance).
9
+ * 2. A NON-default config lands the fully-resolved `DeriveConfig` on `theme.other.basaltDerive`
10
+ * (so `BasaltProvider` can inject the matching stylesheet) and produces `--vx-*` CSS that
11
+ * differs from the shipped default.
12
+ */
13
+ import { describe, expect, test } from 'bun:test'
14
+ import { buildPaletteCss } from '../tokens'
15
+ import { DEFAULT_DERIVE_CONFIG, resolveDeriveConfig } from '../tokens/derive'
16
+ import { buildPaletteData } from '../tokens/palette'
17
+ import { createBasaltTheme } from './index'
18
+
19
+ describe('the default derive config stays on the static path', () => {
20
+ test('createBasaltTheme() carries no theme.other.basaltDerive', () => {
21
+ expect(createBasaltTheme().other?.['basaltDerive']).toBeUndefined()
22
+ })
23
+
24
+ test('createBasaltTheme(undefined, {}) resolves to the same default', () => {
25
+ expect(createBasaltTheme(undefined, {}).other?.['basaltDerive']).toBeUndefined()
26
+ })
27
+
28
+ test('a derive option that resolves back to the default also carries no basaltDerive', () => {
29
+ const theme = createBasaltTheme(undefined, { derive: { ...DEFAULT_DERIVE_CONFIG } })
30
+ expect(theme.other?.['basaltDerive']).toBeUndefined()
31
+ })
32
+
33
+ test('the default palette CSS is byte-identical to the static path', () => {
34
+ expect(buildPaletteCss(undefined, buildPaletteData(DEFAULT_DERIVE_CONFIG))).toBe(
35
+ buildPaletteCss(),
36
+ )
37
+ })
38
+ })
39
+
40
+ describe('a non-default derive config graduates onto the theme', () => {
41
+ const partial = { accent: '#16a34a' }
42
+ const theme = createBasaltTheme(undefined, { derive: partial })
43
+
44
+ test('the resolved config lands on theme.other.basaltDerive', () => {
45
+ expect(theme.other?.['basaltDerive']).toEqual(resolveDeriveConfig(partial))
46
+ })
47
+
48
+ test('its palette CSS differs from the shipped default', () => {
49
+ const resolved = resolveDeriveConfig(partial)
50
+ const customCss = buildPaletteCss(undefined, buildPaletteData(resolved))
51
+ expect(customCss).not.toBe(buildPaletteCss())
52
+ })
53
+
54
+ test('the accent fill in theme.colors.blue follows the custom seed', () => {
55
+ const resolved = resolveDeriveConfig(partial)
56
+ const data = buildPaletteData(resolved)
57
+ const blue = theme.colors?.['blue']
58
+ expect(blue?.[6]).toBe(data.ACCENT.accentFill.light)
59
+ })
60
+ })
61
+
62
+ describe('consumer overrides still win on top of a derive config', () => {
63
+ test('an explicit override merges onto the derived theme', () => {
64
+ const theme = createBasaltTheme({ primaryColor: 'green' }, { derive: { accent: '#16a34a' } })
65
+ expect(theme.primaryColor).toBe('green')
66
+ expect(theme.other?.['basaltDerive']).toEqual(resolveDeriveConfig({ accent: '#16a34a' }))
67
+ })
68
+ })
69
+
70
+ describe('a non-default derive config yields a dark tuple that tracks its own derived data', () => {
71
+ // `accent` alone doesn't move the dark tuple (it's built from INK/SURFACE, which key off
72
+ // `neutral` + `darkLevel`, not the accent seed) — vary `darkLevel` so the tuple's surface-based
73
+ // stops (border/hover/panel/body) actually diverge from the shipped default's.
74
+ const partial = { darkLevel: 3 }
75
+ const resolved = resolveDeriveConfig(partial)
76
+ const data = buildPaletteData(resolved)
77
+ const theme = createBasaltTheme(undefined, { derive: partial })
78
+
79
+ test('theme.colors.dark follows the derived data', () => {
80
+ expect(theme.colors?.['dark']?.[0]).toBe(data.INK.ink.dark)
81
+ expect(theme.colors?.['dark']?.[7]).toBe(data.SURFACE.bg.dark)
82
+ })
83
+
84
+ test("a non-default config yields a dark tuple that differs from the DEFAULT theme's", () => {
85
+ expect(theme.colors?.['dark']).not.toEqual(createBasaltTheme().colors?.['dark'])
86
+ })
87
+ })
88
+
89
+ describe('a malformed accent seed throws through createBasaltTheme', () => {
90
+ test('rejects a non-hex color name', () => {
91
+ expect(() => createBasaltTheme(undefined, { derive: { accent: 'red' } })).toThrow()
92
+ })
93
+
94
+ test('rejects a truncated hex', () => {
95
+ expect(() => createBasaltTheme(undefined, { derive: { accent: '#12' } })).toThrow()
96
+ })
97
+
98
+ test('rejects a non-hex-digit hex', () => {
99
+ expect(() => createBasaltTheme(undefined, { derive: { accent: '#zzzzzz' } })).toThrow()
100
+ })
101
+ })
@@ -14,7 +14,7 @@
14
14
  */
15
15
  .closeButton {
16
16
  color: var(--vx-faint) !important;
17
- border-radius: 6px !important;
17
+ border-radius: var(--vx-radius-ctrl) !important;
18
18
  }
19
19
 
20
20
  .closeButton:hover {
@@ -0,0 +1,69 @@
1
+ /**
2
+ * `createBasaltTheme`'s `{ fonts }` option — a pure pass-through onto `theme.other.basaltFonts`
3
+ * (no derivation math, unlike `{ derive }`). See `derive-theme.test.ts` for the derive-config
4
+ * equivalent this mirrors.
5
+ */
6
+ import { describe, expect, test } from 'bun:test'
7
+ import { baseTheme, createBasaltTheme } from './index'
8
+
9
+ describe('the default path carries no theme.other.basaltFonts', () => {
10
+ test('createBasaltTheme() carries no basaltFonts', () => {
11
+ expect(createBasaltTheme().other?.['basaltFonts']).toBeUndefined()
12
+ })
13
+
14
+ test('createBasaltTheme(undefined, {}) carries no basaltFonts', () => {
15
+ expect(createBasaltTheme(undefined, {}).other?.['basaltFonts']).toBeUndefined()
16
+ })
17
+ })
18
+
19
+ describe('an empty fonts object is treated as absent — stays on the static baseTheme fast path', () => {
20
+ test('createBasaltTheme(undefined, { fonts: {} }) returns the identical baseTheme reference', () => {
21
+ expect(createBasaltTheme(undefined, { fonts: {} })).toBe(baseTheme)
22
+ })
23
+
24
+ test('carries no theme.other.basaltFonts', () => {
25
+ expect(createBasaltTheme(undefined, { fonts: {} }).other?.['basaltFonts']).toBeUndefined()
26
+ })
27
+
28
+ test('an all-undefined-keys fonts object is also treated as absent', () => {
29
+ const theme = createBasaltTheme(undefined, { fonts: { sans: undefined } })
30
+ expect(theme).toBe(baseTheme)
31
+ expect(theme.other?.['basaltFonts']).toBeUndefined()
32
+ })
33
+ })
34
+
35
+ describe('a fonts option graduates onto the theme', () => {
36
+ test('exposes the exact fonts object on theme.other.basaltFonts', () => {
37
+ const theme = createBasaltTheme(undefined, { fonts: { sans: 'Inter, sans-serif' } })
38
+ expect(theme.other?.['basaltFonts']).toEqual({ sans: 'Inter, sans-serif' })
39
+ })
40
+
41
+ test('accepts all three slots', () => {
42
+ const fonts = {
43
+ sans: 'Inter, sans-serif',
44
+ head: 'Poppins, sans-serif',
45
+ mono: 'Fira Code, monospace',
46
+ }
47
+ const theme = createBasaltTheme(undefined, { fonts })
48
+ expect(theme.other?.['basaltFonts']).toEqual(fonts)
49
+ })
50
+
51
+ test('combines with a non-default derive config without dropping either', () => {
52
+ const theme = createBasaltTheme(undefined, {
53
+ derive: { accent: '#16a34a' },
54
+ fonts: { sans: 'Inter, sans-serif' },
55
+ })
56
+ expect(theme.other?.['basaltFonts']).toEqual({ sans: 'Inter, sans-serif' })
57
+ expect(theme.other?.['basaltDerive']).toBeDefined()
58
+ })
59
+ })
60
+
61
+ describe('consumer overrides still win on top of a fonts option', () => {
62
+ test('an explicit other.basaltFonts override replaces it', () => {
63
+ const theme = createBasaltTheme(
64
+ { other: { basaltFonts: { sans: 'Georgia, serif' } } },
65
+ { fonts: { sans: 'Inter, sans-serif' } },
66
+ )
67
+ expect(theme.other?.['basaltFonts']).toEqual({ sans: 'Georgia, serif' })
68
+ })
69
+ })