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
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * Unit tests for checkSource — the pure (text, relPath, cfg) → Finding[] core.
3
3
  *
4
- * Covers all 18 guard kinds. Co-located with the guard, excluded from tsc
4
+ * Covers all 19 guard kinds. Co-located with the guard, excluded from tsc
5
5
  * (tsconfig exclude: src/**\/*.test.ts), run via `bun test`.
6
6
  *
7
7
  * The walker/reporter half is covered by the integration test in
8
8
  * src/cli/check-theme.test.ts (temp-dir + exit-code contract).
9
9
  */
10
10
  import { describe, expect, it } from 'bun:test'
11
+ import { SPACE_SCALE } from '../tokens/palette'
11
12
  import { checkSource, DEFAULT_GUARD_CONFIG } from './index'
12
13
  import type { Finding, GuardKind } from './types'
13
14
 
@@ -82,8 +83,8 @@ describe('raw-color-fn', () => {
82
83
  expect(kinds(f)).not.toContain('raw-color-fn')
83
84
  })
84
85
 
85
- it('does NOT flag a pure block comment line', () => {
86
- const f = find(`* use rgba() for opacity`)
86
+ it('does NOT flag rgba() mentioned inside a real block comment', () => {
87
+ const f = find('/*\n * use rgba() for opacity\n */')
87
88
  expect(kinds(f)).not.toContain('raw-color-fn')
88
89
  })
89
90
  })
@@ -155,17 +156,15 @@ describe('off-identity-accent', () => {
155
156
  // ── 5. raw-spacing ───────────────────────────────────────────────────────────
156
157
 
157
158
  describe('raw-spacing', () => {
158
- it('flags p={16} (default spacing step)', () => {
159
- const f = find(`<Box p={16} />`)
160
- expect(kinds(f)).toContain('raw-spacing')
159
+ // Interpolated from the real scale, never typed as literals: the previous versions of these tests
160
+ // hardcoded 16 and 12 and so PASSED against a guard whose step list had gone stale — they encoded
161
+ // the drift instead of catching it.
162
+ it('flags a prop value equal to a scale step', () => {
163
+ expect(kinds(find(`<Box p={${SPACE_SCALE.md}} />`))).toContain('raw-spacing')
164
+ expect(kinds(find(`<Stack gap={${SPACE_SCALE.sm}} />`))).toContain('raw-spacing')
161
165
  })
162
166
 
163
- it('flags gap={12}', () => {
164
- const f = find(`<Stack gap={12} />`)
165
- expect(kinds(f)).toContain('raw-spacing')
166
- })
167
-
168
- it('does NOT flag p={8} (not a default step)', () => {
167
+ it('does NOT flag p={8} (sub-scale micro-spacing, no token to prefer)', () => {
169
168
  const f = find(`<Box p={8} />`)
170
169
  expect(kinds(f)).not.toContain('raw-spacing')
171
170
  })
@@ -176,7 +175,7 @@ describe('raw-spacing', () => {
176
175
  })
177
176
 
178
177
  it('does NOT flag a theme-allow line', () => {
179
- const f = find(`<Box p={16} /> // theme-allow`)
178
+ const f = find(`<Box p={${SPACE_SCALE.md}} /> // theme-allow`)
180
179
  expect(kinds(f)).not.toContain('raw-spacing')
181
180
  })
182
181
  })
@@ -233,6 +232,32 @@ describe('raw-surface', () => {
233
232
  expect(kinds(f)).not.toContain('raw-surface')
234
233
  })
235
234
 
235
+ it('does NOT flag a ${…}-composed border (token-driven, e.g. VX.divider)', () => {
236
+ const f = find('const s = { borderLeft: `2px solid ${VX.divider}` }')
237
+ expect(kinds(f)).not.toContain('raw-surface')
238
+ })
239
+
240
+ it('does NOT flag a ${…}-composed boxShadow (VX.shadowCard + a token ring)', () => {
241
+ const f = find(
242
+ 'const s = { boxShadow: `${VX.shadowCard}, 0 0 0 1px ${alpha(VX.status.bad, 0.25)}` }',
243
+ )
244
+ expect(kinds(f)).not.toContain('raw-surface')
245
+ })
246
+
247
+ it('does NOT flag a border reset keyword (none/transparent)', () => {
248
+ expect(kinds(find(`<button style={{ border: 'none' }} />`))).not.toContain('raw-surface')
249
+ expect(kinds(find(`<div style={{ border: 'transparent' }} />`))).not.toContain('raw-surface')
250
+ })
251
+
252
+ it('STILL flags a genuinely raw ${…}-free literal border/shadow', () => {
253
+ // A template literal escapes only because its color is separately caught by raw-hex/raw-color-fn;
254
+ // a plain quoted literal has no such backstop, so it must still fire.
255
+ expect(kinds(find(`<div style={{ border: '2px solid red' }} />`))).toContain('raw-surface')
256
+ expect(kinds(find(`<div style={{ boxShadow: '0 2px 4px rgba(0,0,0,.1)' }} />`))).toContain(
257
+ 'raw-surface',
258
+ )
259
+ })
260
+
236
261
  it('does NOT flag when rawSurface is false', () => {
237
262
  const f = checkSource(`<div style={{ borderRadius: 8 }} />`, PATH, {
238
263
  ...DEFAULT_GUARD_CONFIG,
@@ -771,6 +796,85 @@ describe('sub-16-input-font', () => {
771
796
  })
772
797
  })
773
798
 
799
+ // ── 19. raw-font-family ──────────────────────────────────────────────────────
800
+
801
+ describe('raw-font-family', () => {
802
+ it('flags a quoted fontFamily object property', () => {
803
+ const f = find(`const s = { fontFamily: 'Inter, sans-serif' }`)
804
+ expect(kinds(f)).toContain('raw-font-family')
805
+ })
806
+
807
+ it('flags a quoted fontFamily JSX prop', () => {
808
+ const f = find(`<Text style={{ fontFamily: "Arial" }}>hi</Text>`)
809
+ expect(kinds(f)).toContain('raw-font-family')
810
+ })
811
+
812
+ it('flags a bare kebab-case font-family CSS declaration', () => {
813
+ const f = find(`font-family: Inter;`)
814
+ expect(kinds(f)).toContain('raw-font-family')
815
+ })
816
+
817
+ it('does NOT flag a fontFamily bound to a var(--basalt-font-…) reference', () => {
818
+ const f = find(`fontFamily: 'var(--basalt-font-sans, ui-sans-serif, system-ui, sans-serif)',`)
819
+ expect(kinds(f)).not.toContain('raw-font-family')
820
+ })
821
+
822
+ it('does NOT flag a kebab-case font-family bound to var(…)', () => {
823
+ const f = find(`font-family: var(--basalt-font-mono);`)
824
+ expect(kinds(f)).not.toContain('raw-font-family')
825
+ })
826
+
827
+ it('does NOT flag an unquoted fontFamily identifier reference (a token ref, not a literal)', () => {
828
+ const f = find(`fontFamily: LABEL_FONT_FAMILY,`)
829
+ expect(kinds(f)).not.toContain('raw-font-family')
830
+ })
831
+
832
+ it('does NOT flag a theme-allow line', () => {
833
+ const f = find(`fontFamily: 'Inter, sans-serif', // theme-allow: legacy widget`)
834
+ expect(kinds(f)).not.toContain('raw-font-family')
835
+ })
836
+
837
+ it('flags a quoted kebab-case font-family CSS value (the (a) bypass)', () => {
838
+ const f = find(`font-family: 'Inter', sans-serif;`)
839
+ expect(kinds(f)).toContain('raw-font-family')
840
+ })
841
+
842
+ it('flags a fontFamily bound to a var(...) reference OUTSIDE the two allowed prefixes (the (b) bypass)', () => {
843
+ const f = find(`fontFamily: 'var(--some-other-var)'`)
844
+ expect(kinds(f)).toContain('raw-font-family')
845
+ })
846
+
847
+ it('flags a kebab-case font-family bound to a var(...) reference outside the allowed prefixes', () => {
848
+ const f = find(`font-family: var(--some-other-var);`)
849
+ expect(kinds(f)).toContain('raw-font-family')
850
+ })
851
+
852
+ it('does NOT flag a kebab-case font-family bound to var(--mantine-font-family-…)', () => {
853
+ const f = find(`fontFamily: 'var(--mantine-font-family-monospace)',`)
854
+ expect(kinds(f)).not.toContain('raw-font-family')
855
+ })
856
+
857
+ it('does NOT flag the CSS-wide keyword inherit (camelCase, quoted)', () => {
858
+ const f = find(`fontFamily: 'inherit'`)
859
+ expect(kinds(f)).not.toContain('raw-font-family')
860
+ })
861
+
862
+ it('does NOT flag the CSS-wide keyword initial (kebab-case, bare)', () => {
863
+ const f = find(`font-family: initial;`)
864
+ expect(kinds(f)).not.toContain('raw-font-family')
865
+ })
866
+
867
+ it('does NOT flag the CSS-wide keyword unset', () => {
868
+ const f = find(`font-family: unset;`)
869
+ expect(kinds(f)).not.toContain('raw-font-family')
870
+ })
871
+
872
+ it('does NOT flag the CSS-wide keyword revert', () => {
873
+ const f = find(`font-family: revert;`)
874
+ expect(kinds(f)).not.toContain('raw-font-family')
875
+ })
876
+ })
877
+
774
878
  // ── theme-allow skip ─────────────────────────────────────────────────────────
775
879
 
776
880
  describe('theme-allow skip', () => {
@@ -802,8 +906,8 @@ describe('pure-comment skip', () => {
802
906
  expect(kinds(f)).not.toContain('raw-hex')
803
907
  })
804
908
 
805
- it('skips a * JSDoc body line', () => {
806
- const f = find(` * Use rgba() for opacity, not raw hex`)
909
+ it('skips a JSDoc body line that is genuinely inside a block comment', () => {
910
+ const f = find('/**\n * Use rgba() for opacity, not raw hex\n */')
807
911
  expect(kinds(f)).not.toContain('raw-color-fn')
808
912
  })
809
913
 
@@ -819,6 +923,155 @@ describe('pure-comment skip', () => {
819
923
  })
820
924
  })
821
925
 
926
+ // ── stripComments pre-pass: real block/line-comment awareness ───────────────────
927
+ //
928
+ // checkSource used to decide "is this a comment?" per line, from that line's OWN leading prefix
929
+ // (`//` / `*` / `/*`). A block-comment CONTINUATION line that didn't happen to start with `*` (the
930
+ // common "wrapped prose" style, e.g. styles.css) slipped straight through as code — a real
931
+ // false-positive, not a hypothetical one (see the 3 real sites this fixed, asserted in
932
+ // index.test.ts / reproduced below). These cases prove the replacement — an actual comment-
933
+ // stripping pre-pass — neither under- nor over-strips.
934
+
935
+ describe('stripComments pre-pass', () => {
936
+ it('does NOT flag a hex on a block-comment CONTINUATION line with no leading *', () => {
937
+ // This is exactly the styles.css shape: a /* ... */ block whose middle lines are wrapped
938
+ // prose, not `* `-prefixed. The old per-line prefix heuristic missed this entirely.
939
+ const text = ['/* line one', ' #e5e5e5 in the middle, no leading star', 'line three */'].join(
940
+ '\n',
941
+ )
942
+ const f = find(text)
943
+ expect(kinds(f)).not.toContain('raw-hex')
944
+ })
945
+
946
+ it('flags a real hex that follows a same-line /* */ comment', () => {
947
+ const f = find(`/* note */ const c = '#ff0000'`)
948
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
949
+ })
950
+
951
+ it('flags a hex inside a single-quoted string with a trailing // comment', () => {
952
+ const f = find(`const c = '#ff0000' // trailing note`)
953
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
954
+ expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
955
+ })
956
+
957
+ it('does not mangle a URL hash-fragment inside a quoted string via // handling', () => {
958
+ // The `//` in `https://` sits INSIDE a single-quoted string, so it must not be treated as a
959
+ // line-comment opener. The guard's raw-hex regex has no URL awareness (never did — that's
960
+ // unrelated to this fix), so it still matches the `#aabbcc` fragment literally: the real-code
961
+ // semantics here are "1 finding", proving the string content survived the strip untouched
962
+ // rather than being blanked out by an over-eager `//` rule.
963
+ const f = find(`const u = 'https://example.com/#aabbcc'`)
964
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
965
+ })
966
+
967
+ it('preserves the exact original line number across a preceding multi-line block comment', () => {
968
+ const text = ['/*', 'line2', 'line3', 'line4', 'end */', '', "const c = '#ff0000'"].join('\n')
969
+ const f = find(text)
970
+ const hit = f.find((x) => x.kind === 'raw-hex')
971
+ expect(hit?.line).toBe(7)
972
+ })
973
+
974
+ it('still honors the theme-allow escape on a code line', () => {
975
+ const f = find(`const c = '#ff0000' // theme-allow: legacy`)
976
+ expect(kinds(f)).not.toContain('raw-hex')
977
+ })
978
+
979
+ it('does not crash on an unterminated block comment at EOF, and strips everything after it', () => {
980
+ const text = `const before = '#ff0000'\n/* unterminated\nconst c = '#00ff00'`
981
+ const f = find(text)
982
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
983
+ expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
984
+ })
985
+
986
+ it('still finds a hex inside a backtick template literal containing ${}', () => {
987
+ const f = find('const s = `value ${x} is #ff0000`')
988
+ expect(kinds(f)).toContain('raw-hex')
989
+ })
990
+
991
+ it('CSS-shaped input: flags only the real declaration, not the comment mention', () => {
992
+ const text = '/* comment with #e5e5e5 */\n.a { color: #ff0000; }'
993
+ const f = find(text)
994
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
995
+ expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
996
+ })
997
+
998
+ // ── regex-literal disambiguation (BUG 1: a `/*`- or `//`-shaped sequence INSIDE a regex body
999
+ // must never be misread as opening a comment — the char-class case ran away to EOF and silently
1000
+ // deleted guard coverage for the rest of the file) ──────────────────────────────────────────────
1001
+
1002
+ it('does not treat a `/*` inside a regex character class as a block-comment opener (BUG 1 repro)', () => {
1003
+ const text = "const RE = /[/*]/\nconst c = '#ff0000'"
1004
+ const f = find(text)
1005
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1006
+ })
1007
+
1008
+ it('does not treat two `/` inside a regex character class as a line-comment opener', () => {
1009
+ const text = "const RE = /[//]/\nconst c = '#ff0000'"
1010
+ const f = find(text)
1011
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1012
+ })
1013
+
1014
+ it('treats a `/` between identifiers as division, not a regex open', () => {
1015
+ const text = "const a = x / y\nconst c = '#ff0000'"
1016
+ const f = find(text)
1017
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1018
+ })
1019
+
1020
+ it('treats a `/` as division and still finds a REAL // comment later on the same line', () => {
1021
+ const text = "const a = x / y // #aabbcc\nconst c = '#ff0000'"
1022
+ const f = find(text)
1023
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1024
+ })
1025
+
1026
+ it('consumes a regex literal with an escaped slash without closing early', () => {
1027
+ const text = "const RE = /a\\/b/\nconst c = '#ff0000'"
1028
+ const f = find(text)
1029
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1030
+ })
1031
+
1032
+ it('still recognizes a real block comment right after a regex literal (regex handling did not break comment handling)', () => {
1033
+ const text = 'const RE = /abc/\n/* #ff0000 */'
1034
+ const f = find(text)
1035
+ expect(kinds(f)).not.toContain('raw-hex')
1036
+ })
1037
+
1038
+ // ── CSS vs TS syntax split (BUG 2: an unquoted `//` in CSS, e.g. inside `url(https://…)`,
1039
+ // is real CSS text, not a comment opener — CSS has no `//` comment syntax at all) ───────────────
1040
+
1041
+ it('does not treat an unquoted "//" inside a CSS url() as a comment opener (BUG 2 repro)', () => {
1042
+ const f = checkSource(
1043
+ '.a { background: url(https://x.com/a.png); color: #ff0000; }',
1044
+ 'src/styles.css',
1045
+ DEFAULT_GUARD_CONFIG,
1046
+ )
1047
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1048
+ })
1049
+
1050
+ it('still strips a real /* */ block comment in a .css file alongside an unquoted url()', () => {
1051
+ const f = checkSource(
1052
+ '.a { background: url(https://x.com/a.png); /* #aabbcc */ color: #ff0000; }',
1053
+ 'src/styles.css',
1054
+ DEFAULT_GUARD_CONFIG,
1055
+ )
1056
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1057
+ expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
1058
+ })
1059
+
1060
+ it('resolves a .module.css path to CSS syntax too (suffix match, not a naive split)', () => {
1061
+ const f = checkSource(
1062
+ '.a { background: url(https://x.com/a.png); color: #ff0000; }',
1063
+ 'src/Card.module.css',
1064
+ DEFAULT_GUARD_CONFIG,
1065
+ )
1066
+ expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
1067
+ })
1068
+
1069
+ it('a .ts file still strips a real // line comment (the CSS/TS syntax split did not disable TS)', () => {
1070
+ const f = checkSource('// #ff0000\nconst ok = 1', 'src/x.ts', DEFAULT_GUARD_CONFIG)
1071
+ expect(kinds(f)).not.toContain('raw-hex')
1072
+ })
1073
+ })
1074
+
822
1075
  // ── isChartFile gates raw-visx-axis ──────────────────────────────────────────
823
1076
 
824
1077
  describe('isChartFile path gate', () => {
@@ -832,3 +1085,218 @@ describe('isChartFile path gate', () => {
832
1085
  expect(kinds(f)).not.toContain('raw-visx-axis')
833
1086
  })
834
1087
  })
1088
+
1089
+ // ── CSS applicability — the CLI walker now scans .css, so checkSource's per-kind gating over
1090
+ // CSS-shaped input matters for real: color-meaningful kinds must still fire, JSX/tag-shaped kinds
1091
+ // must not false-positive on genuine CSS syntax ──────────────────────────────────────────────────
1092
+
1093
+ describe('CSS applicability', () => {
1094
+ it('flags a raw hex in a real CSS declaration (proves .css is genuinely scanned)', () => {
1095
+ const f = checkSource(
1096
+ '.input {\n color: #ff0000;\n}\n',
1097
+ 'src/Card.module.css',
1098
+ DEFAULT_GUARD_CONFIG,
1099
+ )
1100
+ expect(kinds(f)).toContain('raw-hex')
1101
+ })
1102
+
1103
+ it('does NOT false-positive inline-display/raw-html-layout/raw-surface on genuine CSS shapes', () => {
1104
+ const f = checkSource(
1105
+ '.foo {\n display: flex;\n padding: 8px;\n border-radius: 8px;\n}\n',
1106
+ 'src/Card.module.css',
1107
+ DEFAULT_GUARD_CONFIG,
1108
+ )
1109
+ expect(kinds(f)).not.toContain('inline-display')
1110
+ expect(kinds(f)).not.toContain('raw-html-layout')
1111
+ expect(kinds(f)).not.toContain('raw-surface')
1112
+ })
1113
+
1114
+ it('still flags off-system-surface-var on a raw Mantine ramp step inside CSS', () => {
1115
+ const f = checkSource(
1116
+ '.foo {\n background: var(--mantine-color-gray-3);\n}\n',
1117
+ 'src/Card.module.css',
1118
+ DEFAULT_GUARD_CONFIG,
1119
+ )
1120
+ expect(kinds(f)).toContain('off-system-surface-var')
1121
+ })
1122
+
1123
+ it('still flags raw-font-family on a kebab-case CSS font-family declaration', () => {
1124
+ const f = checkSource(
1125
+ '.foo {\n font-family: system-ui;\n}\n',
1126
+ 'src/Card.module.css',
1127
+ DEFAULT_GUARD_CONFIG,
1128
+ )
1129
+ expect(kinds(f)).toContain('raw-font-family')
1130
+ })
1131
+
1132
+ it('still flags inline-spacing on a genuine CSS padding/margin/gap declaration (the pattern is CSS-shaped, not JSX-only, despite the name)', () => {
1133
+ const f = checkSource(
1134
+ '.foo {\n padding: 18px;\n margin: 13px;\n gap: 26px;\n}\n',
1135
+ 'src/Card.module.css',
1136
+ DEFAULT_GUARD_CONFIG,
1137
+ )
1138
+ expect(kinds(f).filter((k) => k === 'inline-spacing')).toHaveLength(3)
1139
+ })
1140
+
1141
+ // ── The CSS-only sub-scale escape ───────────────────────────────────────────
1142
+ //
1143
+ // basalt-tokens.md blesses 2-8px micro-spacing raw, but that permission only ever held for JSX
1144
+ // PROPS: `pl={4}` is not a `prop: value` pair and never matched the pattern. In CSS every
1145
+ // declaration is `prop: value`, so a consumer's 4px cluster gap was flagged with nothing legal to
1146
+ // do about it — no token exists below the scale floor, and `exemptRules` matches whole path
1147
+ // segments so it cannot express `*.module.css`.
1148
+
1149
+ const cssSpacing = (decl: string): GuardKind[] =>
1150
+ kinds(
1151
+ checkSource(`.foo {\n ${decl};\n}\n`, 'src/Card.module.css', DEFAULT_GUARD_CONFIG),
1152
+ ).filter((k) => k === 'inline-spacing')
1153
+
1154
+ it('does NOT flag sub-scale micro-spacing in CSS — there is no token to prefer below the floor', () => {
1155
+ for (const decl of ['gap: 2px', 'padding: 4px', 'margin-bottom: 6px', 'padding: 8px']) {
1156
+ expect(cssSpacing(decl)).toEqual([])
1157
+ }
1158
+ })
1159
+
1160
+ it('judges a multi-value shorthand as a whole', () => {
1161
+ expect(cssSpacing('padding: 4px 8px')).toEqual([])
1162
+ // 16px has a scale stop; one non-micro component makes the whole declaration a finding.
1163
+ expect(cssSpacing('padding: 4px 16px')).toEqual(['inline-spacing'])
1164
+ })
1165
+
1166
+ it('drops var() components before judging — a mixed value is already tokenized where it counts', () => {
1167
+ expect(cssSpacing('padding: 4px var(--vx-space-stack-xs)')).toEqual([])
1168
+ })
1169
+
1170
+ it('does not extend the escape to other units — the doctrine is stated in px', () => {
1171
+ expect(cssSpacing('padding: 1.5rem')).toEqual(['inline-spacing'])
1172
+ expect(cssSpacing('padding: 2em')).toEqual(['inline-spacing'])
1173
+ })
1174
+
1175
+ it('keeps the default spacing steps in lockstep with the real scale', () => {
1176
+ // The guard's copy of the xs..xl ladder drifted once already (it still read 10/12/16/20/32
1177
+ // after the level-0 retune, so `p={16}` was flagged in favour of a `p="md"` worth 18, and the
1178
+ // genuine `p={18}` went unflagged). The copy exists to keep the headless core one file; this
1179
+ // asserts it stays honest.
1180
+ expect(DEFAULT_GUARD_CONFIG.spacingSteps).toEqual(Object.values(SPACE_SCALE))
1181
+ })
1182
+
1183
+ it('keeps the ceiling below the smallest scale stop, so it can never strand a real token', () => {
1184
+ // The relationship, not the number: if a density retune moves SPACE_SCALE.xs, this still holds.
1185
+ expect(cssSpacing(`gap: ${SPACE_SCALE.xs}px`)).toEqual(['inline-spacing'])
1186
+ expect(cssSpacing(`gap: ${SPACE_SCALE.xs - 1}px`)).toEqual([])
1187
+ })
1188
+
1189
+ it('leaves TSX untouched — an inline style object still has a prop form to prefer', () => {
1190
+ // `pl={4}` is a prop and never matched; `style={{ padding: 4 }}` did, and still should.
1191
+ expect(
1192
+ kinds(checkSource('<Box style={{ padding: 4 }} />', PATH, DEFAULT_GUARD_CONFIG)),
1193
+ ).toContain('inline-spacing')
1194
+ expect(kinds(checkSource('<Box pl={4} />', PATH, DEFAULT_GUARD_CONFIG))).not.toContain(
1195
+ 'inline-spacing',
1196
+ )
1197
+ })
1198
+
1199
+ it('does NOT false-positive raw-form-control on a CSS element selector (input, select, textarea)', () => {
1200
+ const f = checkSource(
1201
+ 'input, select, textarea {\n color: red;\n}\n',
1202
+ 'src/Card.module.css',
1203
+ DEFAULT_GUARD_CONFIG,
1204
+ )
1205
+ expect(kinds(f)).not.toContain('raw-form-control')
1206
+ })
1207
+
1208
+ it('does NOT false-positive raw-spacing/raw-radius/off-identity-accent/raw-motion-value on CSS property syntax', () => {
1209
+ const f = checkSource(
1210
+ '.foo {\n border-radius: 6px;\n transition: all 0.3s ease;\n color: teal;\n gap: 16px;\n}\n',
1211
+ 'src/Card.module.css',
1212
+ DEFAULT_GUARD_CONFIG,
1213
+ )
1214
+ expect(kinds(f)).not.toContain('raw-radius')
1215
+ expect(kinds(f)).not.toContain('raw-motion-value')
1216
+ expect(kinds(f)).not.toContain('off-identity-accent')
1217
+ })
1218
+
1219
+ it('does NOT false-positive card-with-border/unframed-chart/chart-missing-aria-label/raw-visx-axis on CSS class selectors that echo JSX names', () => {
1220
+ const f = checkSource(
1221
+ '.Card {\n border: 1px solid red;\n}\n.ChartLegend {\n display: flex;\n}\n.AxisLeft {\n color: red;\n}\n',
1222
+ 'src/charts/kinds/Card.module.css',
1223
+ DEFAULT_GUARD_CONFIG,
1224
+ )
1225
+ expect(kinds(f)).not.toContain('card-with-border')
1226
+ expect(kinds(f)).not.toContain('unframed-chart')
1227
+ expect(kinds(f)).not.toContain('chart-missing-aria-label')
1228
+ expect(kinds(f)).not.toContain('raw-visx-axis')
1229
+ })
1230
+
1231
+ it('does NOT false-positive localstorage-theme on CSS text', () => {
1232
+ const f = checkSource(
1233
+ "/* localStorage.getItem('theme') example */\n.foo { color: red; }\n",
1234
+ 'src/Card.module.css',
1235
+ DEFAULT_GUARD_CONFIG,
1236
+ )
1237
+ expect(kinds(f)).not.toContain('localstorage-theme')
1238
+ })
1239
+ })
1240
+
1241
+ // ── exemptRules — per-rule, per-path guard exemptions ────────────────────────
1242
+
1243
+ describe('exemptRules', () => {
1244
+ const TEXT = `<div style={{ display: 'flex' }} />`
1245
+
1246
+ it('drops a finding of an exempted kind at a matching path', () => {
1247
+ const f = checkSource(TEXT, 'src/agent/x.tsx', {
1248
+ ...DEFAULT_GUARD_CONFIG,
1249
+ exemptRules: { 'inline-display': ['agent'] },
1250
+ })
1251
+ expect(kinds(f)).not.toContain('inline-display')
1252
+ })
1253
+
1254
+ it('still fires at a non-matching path (path-scoped, not global)', () => {
1255
+ const f = checkSource(TEXT, 'src/dashboard/x.tsx', {
1256
+ ...DEFAULT_GUARD_CONFIG,
1257
+ exemptRules: { 'inline-display': ['agent'] },
1258
+ })
1259
+ expect(kinds(f)).toContain('inline-display')
1260
+ })
1261
+
1262
+ it('a trailing-slash pattern matches identically to the bare segment', () => {
1263
+ const f = checkSource(TEXT, 'src/agent/x.tsx', {
1264
+ ...DEFAULT_GUARD_CONFIG,
1265
+ exemptRules: { 'inline-display': ['agent/'] },
1266
+ })
1267
+ expect(kinds(f)).not.toContain('inline-display')
1268
+ })
1269
+
1270
+ it('does NOT match a substring of a segment (not a whole-segment match)', () => {
1271
+ const f = checkSource(TEXT, 'src/agent/x.tsx', {
1272
+ ...DEFAULT_GUARD_CONFIG,
1273
+ exemptRules: { 'inline-display': ['age'] },
1274
+ })
1275
+ expect(kinds(f)).toContain('inline-display')
1276
+ })
1277
+
1278
+ it('does NOT suppress a different kind on the same line/path', () => {
1279
+ const f = checkSource(`const c = '#ff0000'; ${TEXT}`, 'src/agent/x.tsx', {
1280
+ ...DEFAULT_GUARD_CONFIG,
1281
+ exemptRules: { 'inline-display': ['agent'] },
1282
+ })
1283
+ expect(kinds(f)).not.toContain('inline-display')
1284
+ expect(kinds(f)).toContain('raw-hex')
1285
+ })
1286
+
1287
+ it('exempts raw-html-layout, an INLINE-handled kind — proves the post-filter covers those too', () => {
1288
+ const f = checkSource(TEXT, 'src/agent/x.tsx', {
1289
+ ...DEFAULT_GUARD_CONFIG,
1290
+ exemptRules: { 'raw-html-layout': ['agent'] },
1291
+ })
1292
+ expect(kinds(f)).not.toContain('raw-html-layout')
1293
+ // inline-display isn't exempted here, so it still fires from the same text.
1294
+ expect(kinds(f)).toContain('inline-display')
1295
+ })
1296
+
1297
+ it('default (no exemptRules) behavior is unchanged', () => {
1298
+ const f = find(TEXT, 'src/agent/x.tsx')
1299
+ expect(kinds(f)).toContain('inline-display')
1300
+ expect(kinds(f)).toContain('raw-html-layout')
1301
+ })
1302
+ })