basalt-ui 1.2.0 → 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.
@@ -0,0 +1,248 @@
1
+ :root {
2
+ --vx-radius-card: 7px;
3
+ --vx-radius-ctrl: 6px;
4
+ --vx-radius-tight: 5px;
5
+ --vx-radius-fine: 4px;
6
+ --vx-radius-floating: 8px;
7
+ --vx-radius-pill: 9999px;
8
+ --vx-space-row-inset-x: 10px;
9
+ --vx-space-row-inset-y: 6px;
10
+ --vx-space-row-line-height: 1.35;
11
+ --vx-space-input-height: 2.625rem;
12
+ --vx-space-control-height: 2.625rem;
13
+ --vx-space-stack-xs: 4px;
14
+ --vx-space-stack-sm: 8px;
15
+ --vx-space-stack-md: 12px;
16
+ --vx-space-stack-lg: 16px;
17
+ --vx-space-stack-xl: 24px;
18
+ --vx-space-sticky-header-clearance: 60px;
19
+ --vx-space-sticky-header-clearance-mobile: 109px;
20
+ --vx-space-nav-icon-gap: 10px;
21
+ --vx-space-sidebar-region-gap: 10px;
22
+ --vx-space-prose-quote-inset-y: 2px;
23
+ --vx-space-prose-quote-indent: 12px;
24
+ --vx-space-prose-inline-code-inset-y: 1.5px;
25
+ --vx-space-prose-inline-code-inset-x: 5px;
26
+ --vx-space-prose-code-block-inset-y: 10px;
27
+ --vx-space-prose-code-block-inset-x: 12px;
28
+ --vx-space-prose-heading-anchor-gap: 6px;
29
+ --vx-space-prose-table-cell-inset-y: 5px;
30
+ --vx-space-prose-table-cell-inset-x: 8px;
31
+ --vx-space-prose-chat-list-gap-bottom: 10px;
32
+ --vx-space-prose-chat-list-indent: 20px;
33
+ --vx-space-prose-chat-list-item-gap: 3px;
34
+ --vx-space-prose-chat-nested-list-gap: 2px;
35
+ --vx-space-prose-chat-heading-gap-top: 14px;
36
+ --vx-space-prose-chat-heading-gap-bottom: 6px;
37
+ --vx-space-prose-article-paragraph-gap: 14px;
38
+ --vx-space-prose-article-list-gap-top: 6px;
39
+ --vx-space-prose-article-list-gap-bottom: 14px;
40
+ --vx-space-prose-article-list-indent: 22px;
41
+ --vx-space-prose-article-h1-gap-top: 6px;
42
+ --vx-space-prose-article-h1-gap-bottom: 14px;
43
+ --vx-space-prose-article-heading-gap-top: 30px;
44
+ --vx-space-prose-article-heading-gap-bottom: 10px;
45
+ --vx-space-prose-article-h2-rule-gap: 6px;
46
+ --vx-space-prose-article-block-gap: 18px;
47
+ --vx-space-article-column-gap: 56px;
48
+ --vx-space-article-toc-rail-width: 220px;
49
+ --vx-space-article-header-gap: 10px;
50
+ --vx-space-article-header-padding-bottom: 20px;
51
+ --vx-space-article-header-margin-bottom: 28px;
52
+ --vx-space-article-meta-row-gap: 6px;
53
+ --vx-space-article-footer-gap: 12px;
54
+ --vx-space-article-footer-margin-top: 40px;
55
+ --vx-space-article-footer-padding-top: 20px;
56
+ --vx-space-article-nav-target-gap: 6px;
57
+ --vx-space-code-block-header-gap: 8px;
58
+ --vx-space-code-block-header-inset-y: 6px;
59
+ --vx-space-code-block-header-inset-right: 10px;
60
+ --vx-space-code-block-content-inset-x: 14px;
61
+ --vx-space-code-block-header-right-gap: 6px;
62
+ --vx-space-code-block-body-inset-y: 10px;
63
+ --vx-space-code-block-floating-copy-offset: 6px;
64
+ --vx-space-callout-inset-y: 10px;
65
+ --vx-space-callout-inset-x: 14px;
66
+ --vx-space-callout-title-row-gap: 8px;
67
+ --vx-space-toc-root-gap: 6px;
68
+ --vx-space-toc-link-inset-y: 4px;
69
+ --vx-space-toc-link-indent: 12px;
70
+ --vx-space-toc-sub-indent: 24px;
71
+ --vx-space-article-card-tags-gap: 4px;
72
+ --vx-space-article-card-tag-inset-y: 1px;
73
+ --vx-space-article-card-tag-inset-x: 6px;
74
+ --vx-space-article-card-meta-gap-top: 2px;
75
+ --vx-space-guide-body-gap-bottom: 8px;
76
+ --vx-space-guide-footer-gap-top: 20px;
77
+ --vx-space-guide-footer-inset-top: 16px;
78
+ --vx-space-sidebar-search-gap: 7px;
79
+ --vx-space-sidebar-search-trigger-height: 32px;
80
+ --vx-space-settings-row-inset-y: 10px;
81
+ --vx-space-settings-row-gap: 16px;
82
+ --vx-space-mermaid-container-inset: 16px;
83
+ --vx-space-sidebar-brand-inset-top: 2px;
84
+ --vx-space-sidebar-brand-inset-x: 7px;
85
+ --vx-space-sidebar-section-gap: 12px;
86
+ --vx-space-sidebar-account-inset-top: 9px;
87
+ --vx-space-sidebar-account-inset-x: 7px;
88
+ --vx-space-sidebar-account-inset-bottom: 2px;
89
+ --vx-space-sidebar-avatar-size: 28px;
90
+ --vx-space-sidebar-section-label-gap: 2px;
91
+ --vx-space-sidebar-child-list-gap-top: 2px;
92
+ --vx-space-sidebar-child-list-gap-bottom: 3px;
93
+ --vx-space-sidebar-child-list-indent: 15px;
94
+ --vx-space-sidebar-child-row-inset-y: 4px;
95
+ --vx-space-sidebar-child-row-indent: 12px;
96
+ --vx-space-app-header-mobile-actions-height: 52px;
97
+ --vx-space-mobile-nav-tab-gap: 3px;
98
+ --vx-space-agent-rail-inset-x: 10px;
99
+ --vx-space-agent-part-gap-top: 6px;
100
+ --vx-space-agent-code-inset: 8px;
101
+ --vx-space-agent-error-inset-y: 8px;
102
+ --vx-space-agent-error-inset-x: 10px;
103
+ --vx-space-agent-scroll-button-gap-top: 8px;
104
+ --vx-space-agent-message-inset-y: 10px;
105
+ --vx-space-agent-message-inset-x: 12px;
106
+ --vx-space-agent-transcript-inset: 16px;
107
+ --vx-space-badge-inset-y: 2px;
108
+ --vx-space-badge-inset-x: 7px;
109
+ --vx-space-stat-card-gap: 8px;
110
+ --vx-space-virtual-row-inset-y: 8px;
111
+ --vx-space-virtual-row-inset-x: 12px;
112
+ --vx-prose-measure: 72ch;
113
+ --vx-fill-gray: #717176;
114
+ --vx-fill-red: #b7514e;
115
+ --vx-fill-pink: #ba4b6c;
116
+ --vx-fill-grape: #9e579c;
117
+ --vx-fill-violet: #9e579c;
118
+ --vx-fill-indigo: #7863bc;
119
+ --vx-fill-cyan: #43769a;
120
+ --vx-fill-teal: #3a7c74;
121
+ --vx-fill-green: #427e3f;
122
+ --vx-fill-lime: #687737;
123
+ --vx-fill-yellow: #8d6c2e;
124
+ --vx-fill-orange: #9a6632;
125
+ --vx-fillHover-gray: color-mix(in srgb, var(--vx-fill-gray) 88%, #000);
126
+ --vx-fillHover-red: color-mix(in srgb, var(--vx-fill-red) 88%, #000);
127
+ --vx-fillHover-pink: color-mix(in srgb, var(--vx-fill-pink) 88%, #000);
128
+ --vx-fillHover-grape: color-mix(in srgb, var(--vx-fill-grape) 88%, #000);
129
+ --vx-fillHover-violet: color-mix(in srgb, var(--vx-fill-violet) 88%, #000);
130
+ --vx-fillHover-indigo: color-mix(in srgb, var(--vx-fill-indigo) 88%, #000);
131
+ --vx-fillHover-cyan: color-mix(in srgb, var(--vx-fill-cyan) 88%, #000);
132
+ --vx-fillHover-teal: color-mix(in srgb, var(--vx-fill-teal) 88%, #000);
133
+ --vx-fillHover-green: color-mix(in srgb, var(--vx-fill-green) 88%, #000);
134
+ --vx-fillHover-lime: color-mix(in srgb, var(--vx-fill-lime) 88%, #000);
135
+ --vx-fillHover-yellow: color-mix(in srgb, var(--vx-fill-yellow) 88%, #000);
136
+ --vx-fillHover-orange: color-mix(in srgb, var(--vx-fill-orange) 88%, #000);
137
+ --vx-text-micro: 11px;
138
+ --vx-text-xs: 12.5px;
139
+ --vx-text-sm: 13.5px;
140
+ --vx-text-md: 15px;
141
+ --vx-text-lg: 16px;
142
+ --vx-text-xl: 18px;
143
+ --vx-text-h2: 21px;
144
+ --vx-text-kpi: 24px;
145
+ --vx-text-h1: 26px;
146
+ --vx-area-top: 22%;
147
+ --vx-area-bottom: 1%;
148
+ --vx-good: color-mix(in srgb, var(--vx-goodSolid) 18%, transparent);
149
+ --vx-goodSoft: color-mix(in srgb, var(--vx-goodSolid) 8%, transparent);
150
+ --vx-bad: color-mix(in srgb, var(--vx-badSolid) 18%, transparent);
151
+ --vx-warn: color-mix(in srgb, var(--vx-warnSolid) 8%, transparent);
152
+ --vx-goodRef: color-mix(in srgb, var(--vx-goodSolid) 30%, transparent);
153
+ --vx-badRef: color-mix(in srgb, var(--vx-badSolid) 30%, transparent);
154
+ --vx-warnRef: color-mix(in srgb, var(--vx-warnSolid) 20%, transparent);
155
+ }
156
+ :root,
157
+ html[data-mantine-color-scheme='dark'] {
158
+ --vx-status-excellent: #43bf4d;
159
+ --vx-status-good: #52c07c;
160
+ --vx-status-warn: #e6a53d;
161
+ --vx-status-bad: #e06761;
162
+ --vx-status-neutral: #a1a1aa;
163
+ --vx-goodSolid: #52c07c;
164
+ --vx-badSolid: #e06761;
165
+ --vx-warnSolid: #e6a53d;
166
+ --vx-neutral: #d4d4d8;
167
+ --vx-line: #e4e4e7;
168
+ --vx-line2: #a1a1aa;
169
+ --vx-axis: rgba(255,255,255,0.6);
170
+ --vx-axisStroke: rgba(255,255,255,0.12);
171
+ --vx-grid: rgba(255,255,255,0.06);
172
+ --vx-crosshair: rgba(255,255,255,0.42);
173
+ --vx-dotStroke: #27272a;
174
+ --vx-tooltipBg: rgba(39,39,42,0.96);
175
+ --vx-tooltipText: rgba(255,255,255,0.88);
176
+ --vx-tooltipMuted: rgba(255,255,255,0.5);
177
+ --vx-tooltipBorder: none;
178
+ --vx-tooltipShadow: 0 2px 8px rgba(0,0,0,0.35);
179
+ --vx-legendText: rgba(255,255,255,0.92);
180
+ --vx-ink: #e5e5e9;
181
+ --vx-ink2: #dddde1;
182
+ --vx-muted: #d4d4d8;
183
+ --vx-faint: #a1a1a4;
184
+ --vx-accent: #a2c3f0;
185
+ --vx-accentHover: #65a2e3;
186
+ --vx-accentFill: #4374a6;
187
+ --vx-accentFillHover: #3c6895;
188
+ --vx-onAccent: #ffffff;
189
+ --vx-divider: color-mix(in srgb, #ffffff 6%, transparent);
190
+ --vx-shadow-card: 0 1px 3px rgba(0,0,0,0.4), inset 0 0 0 1px color-mix(in srgb, #ffffff 4%, transparent);
191
+ --vx-shadow-ctrl: 0 1px 2px rgba(0,0,0,0.35);
192
+ --vx-shadow-overlay: 0 8px 24px rgba(0,0,0,0.5);
193
+ --vx-surface-bg: #27272a;
194
+ --vx-surface-panel: #2b2b2e;
195
+ --vx-surface-panelHover: #38383b;
196
+ --vx-surface-elevated: #38383b;
197
+ --vx-surface-subtle: #323235;
198
+ --vx-surface-overlay: color-mix(in srgb, #3f3f46 50%, #27272a);
199
+ --vx-surface-field: #27272a;
200
+ --vx-surface-border: #444447;
201
+ --vx-surface-hairline: #4e4e51;
202
+ }
203
+ html[data-mantine-color-scheme='light'] {
204
+ --vx-status-excellent: #29a634;
205
+ --vx-status-good: #327a4d;
206
+ --vx-status-warn: #b07808;
207
+ --vx-status-bad: #b5403d;
208
+ --vx-status-neutral: #71717a;
209
+ --vx-goodSolid: #327a4d;
210
+ --vx-badSolid: #b5403d;
211
+ --vx-warnSolid: #b07808;
212
+ --vx-neutral: #525255;
213
+ --vx-line: #52525c;
214
+ --vx-line2: #71717a;
215
+ --vx-axis: rgba(38, 38, 41, 0.6);
216
+ --vx-axisStroke: rgba(38, 38, 41, 0.12);
217
+ --vx-grid: rgba(38, 38, 41, 0.07);
218
+ --vx-crosshair: rgba(38, 38, 41, 0.32);
219
+ --vx-dotStroke: #ffffff;
220
+ --vx-tooltipBg: #ffffff;
221
+ --vx-tooltipText: rgba(38, 38, 41, 0.88);
222
+ --vx-tooltipMuted: rgba(38, 38, 41, 0.5);
223
+ --vx-tooltipBorder: 1px solid #e4e4e7;
224
+ --vx-tooltipShadow: 0 2px 8px rgba(38, 38, 41, 0.1);
225
+ --vx-legendText: rgba(38, 38, 41, 0.82);
226
+ --vx-ink: #262629;
227
+ --vx-ink2: #404043;
228
+ --vx-muted: #525255;
229
+ --vx-faint: #737376;
230
+ --vx-accent: #4374a6;
231
+ --vx-accentHover: #3c6895;
232
+ --vx-accentFill: #4374a6;
233
+ --vx-accentFillHover: #3c6895;
234
+ --vx-onAccent: #ffffff;
235
+ --vx-divider: color-mix(in srgb, #e5e5e5 65%, transparent);
236
+ --vx-shadow-card: 0 1px 2px rgba(28,25,23,0.05), 0 0 0 1px var(--vx-surface-hairline);
237
+ --vx-shadow-ctrl: 0 1px 2px rgba(28,25,23,0.12);
238
+ --vx-shadow-overlay: 0 8px 24px rgba(28,25,23,0.10);
239
+ --vx-surface-bg: #f2f2f5;
240
+ --vx-surface-panel: #fafafd;
241
+ --vx-surface-panelHover: #ffffff;
242
+ --vx-surface-elevated: #ffffff;
243
+ --vx-surface-subtle: #f4f4f8;
244
+ --vx-surface-overlay: #ffffff;
245
+ --vx-surface-field: #ffffff;
246
+ --vx-surface-border: #e2e2e5;
247
+ --vx-surface-hairline: #eaeaee;
248
+ }
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # basalt-ui v1.2.0
1
+ # basalt-ui v1.3.0
2
2
  # Opinionated framework for Mantine-based React apps — theme, app shell, visx charts, toolchain presets
3
3
  #
4
4
  # basalt-ui is an opinionated framework for Mantine-based React apps.
@@ -13,9 +13,13 @@
13
13
  # Subpaths: use the exact import specifier below — do not guess.
14
14
  # Charts and tokens are Mantine-free; the root (.) is Mantine-coupled.
15
15
  # Optional peers are listed per subpath; install only what you use.
16
+ # Every peer is optional: ./tokens, ./charts, ./state and ./guard resolve with
17
+ # no React and no Mantine installed. A consumer with no React at all can take the
18
+ # token system alone — `bunx basalt-ui tokens:css --out tokens.css`, or the prebuilt
19
+ # ./tokens.css subpath. Guide: docs/FRAMEWORK-FREE.md in the repo.
16
20
 
17
21
  Package: basalt-ui
18
- Version: 1.2.0
22
+ Version: 1.3.0
19
23
 
20
24
  ## basalt-ui
21
25
  Import: import { ... } from 'basalt-ui'
@@ -139,6 +143,11 @@ Asset: basalt-ui/styles.css
139
143
  Description: Mandatory CSS import (after the Mantine styles.layer.css bundles) — @layer basalt base styles, iOS input safety net, font stack
140
144
  Layer: non-js-asset
141
145
 
146
+ ## basalt-ui/tokens.css
147
+ Asset: basalt-ui/tokens.css
148
+ Description: Prebuilt --vx-* token stylesheet — the default buildPaletteCss() output as a plain file, for a consumer with no bundler, no React and no Mantine; retune the selector or trim the spacing set with `basalt-ui tokens:css`
149
+ Layer: non-js-asset
150
+
142
151
  ## basalt-ui/configs/*
143
152
  Asset: basalt-ui/configs/*
144
153
  Description: Raw toolchain presets for consumer extends: oxlint.json, oxfmt.json, tsconfig.*.json, lefthook.yml, check.yml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basalt-ui",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Opinionated framework for Mantine-based React apps — theme, app shell, visx charts, toolchain presets",
5
5
  "keywords": [
6
6
  "charts",
@@ -117,6 +117,7 @@
117
117
  "import": "./dist/connectivity/index.js"
118
118
  },
119
119
  "./styles.css": "./dist/styles.css",
120
+ "./tokens.css": "./dist/tokens.css",
120
121
  "./configs/*": "./configs/*",
121
122
  "./llms.txt": "./llms.txt"
122
123
  },
@@ -125,7 +126,7 @@
125
126
  "provenance": true
126
127
  },
127
128
  "scripts": {
128
- "build": "tsup && tsc --emitDeclarationOnly --declarationMap && bun scripts/copy-assets.mjs && bun scripts/fix-esm-extensions.mjs",
129
+ "build": "tsup && tsc --emitDeclarationOnly --declarationMap && bun scripts/copy-assets.mjs && bun scripts/gen-tokens-css.mjs && bun scripts/fix-esm-extensions.mjs",
129
130
  "typecheck": "tsc --noEmit",
130
131
  "pack-test": "bash scripts/pack-test.sh",
131
132
  "prepack": "bun run build",
@@ -195,9 +196,15 @@
195
196
  "vite-plugin-pwa": "^1.3.0"
196
197
  },
197
198
  "peerDependenciesMeta": {
199
+ "@mantine/core": {
200
+ "optional": true
201
+ },
198
202
  "@mantine/form": {
199
203
  "optional": true
200
204
  },
205
+ "@mantine/hooks": {
206
+ "optional": true
207
+ },
201
208
  "@shikijs/langs": {
202
209
  "optional": true
203
210
  },
@@ -216,6 +223,9 @@
216
223
  "@mantine/spotlight": {
217
224
  "optional": true
218
225
  },
226
+ "@tanstack/react-query": {
227
+ "optional": true
228
+ },
219
229
  "@tanstack/react-query-devtools": {
220
230
  "optional": true
221
231
  },
@@ -234,6 +244,12 @@
234
244
  "beautiful-mermaid": {
235
245
  "optional": true
236
246
  },
247
+ "react": {
248
+ "optional": true
249
+ },
250
+ "react-dom": {
251
+ "optional": true
252
+ },
237
253
  "react-markdown": {
238
254
  "optional": true
239
255
  },
package/src/cli/index.ts CHANGED
@@ -37,6 +37,7 @@ import type { Finding, GuardConfig, GuardKind } from '../guard'
37
37
  import { evaluateGuardHook } from '../guard/guard-hook'
38
38
  import { RULE_NAMES, SKILL_NAMES, SURFACES, TOKEN_LAYER_BOUNDARY_SURFACES } from '../surfaces'
39
39
  import type { DoctrineSpec, SurfaceSpec } from '../surfaces'
40
+ import { buildPaletteCss } from '../tokens'
40
41
 
41
42
  /** Shape of the optional `"basalt"` key in a consumer's package.json. */
42
43
  export type BasaltConfig = {
@@ -1571,6 +1572,73 @@ export function info(flags: string[]): number {
1571
1572
  return 0
1572
1573
  }
1573
1574
 
1575
+ /** Read the value that follows a `--flag` in an argv slice; `undefined` when absent or terminal. */
1576
+ function flagValue(flags: string[], name: string): string | undefined {
1577
+ const i = flags.indexOf(name)
1578
+ if (i === -1) return undefined
1579
+ const value = flags[i + 1]
1580
+ return value === undefined || value.startsWith('--') ? undefined : value
1581
+ }
1582
+
1583
+ /**
1584
+ * tokens:css — emit the `--vx-*` stylesheet, optionally retargeted.
1585
+ *
1586
+ * The escape hatch from installing anything: a static site runs this once (`bunx basalt-ui
1587
+ * tokens:css --selector-attribute data-theme --out src/tokens.css`) and consumes basalt's token
1588
+ * system as plain CSS, with no package in its dependency tree at all. `basalt-ui/tokens.css` is the
1589
+ * same artifact for a consumer that does install; this command exists for the ones that shouldn't
1590
+ * have to just to change a selector.
1591
+ *
1592
+ * It parses flags and calls `buildPaletteCss` — nothing else. No emission logic, no post-processing
1593
+ * of the returned string: the CLI and the API must not be able to disagree about what basalt's
1594
+ * tokens are.
1595
+ */
1596
+ export function tokensCss(flags: string[], cwd: string = process.cwd()): number {
1597
+ const attribute = flagValue(flags, '--selector-attribute')
1598
+ const darkValue = flagValue(flags, '--dark-value')
1599
+ const lightValue = flagValue(flags, '--light-value')
1600
+ const defaultScheme = flagValue(flags, '--default-scheme')
1601
+
1602
+ const only = flagValue(flags, '--only')
1603
+
1604
+ if (defaultScheme !== undefined && !['dark', 'light', 'none'].includes(defaultScheme)) {
1605
+ console.error(
1606
+ `tokens:css: --default-scheme must be dark, light or none (got '${defaultScheme}')`,
1607
+ )
1608
+ return 1
1609
+ }
1610
+ if (only !== undefined && !['core', 'all'].includes(only)) {
1611
+ console.error(`tokens:css: --only must be core or all (got '${only}')`)
1612
+ return 1
1613
+ }
1614
+
1615
+ const scheme = {
1616
+ ...(attribute === undefined ? {} : { attribute }),
1617
+ ...(darkValue === undefined ? {} : { darkValue }),
1618
+ ...(lightValue === undefined ? {} : { lightValue }),
1619
+ }
1620
+
1621
+ const css = buildPaletteCss({
1622
+ ...(Object.keys(scheme).length === 0 ? {} : { scheme }),
1623
+ ...(defaultScheme === undefined
1624
+ ? {}
1625
+ : { defaultScheme: defaultScheme as 'dark' | 'light' | 'none' }),
1626
+ ...(flags.includes('--media-fallback') ? { mediaFallback: true } : {}),
1627
+ ...(only === undefined ? {} : { only: only as 'core' | 'all' }),
1628
+ })
1629
+
1630
+ const out = flagValue(flags, '--out')
1631
+ if (out === undefined) {
1632
+ process.stdout.write(`${css}\n`)
1633
+ return 0
1634
+ }
1635
+ const target = isAbsolute(out) ? out : resolve(cwd, out)
1636
+ mkdirSync(dirname(target), { recursive: true })
1637
+ writeFileSync(target, css)
1638
+ console.log(`wrote ${css.split('\n').length} lines → ${relative(cwd, target) || target}`)
1639
+ return 0
1640
+ }
1641
+
1574
1642
  /**
1575
1643
  * guard-hook — PreToolUse stdin adapter.
1576
1644
  *
@@ -1668,7 +1736,10 @@ export async function guardHook(cwd: string = process.cwd()): Promise<number> {
1668
1736
  /** The one usage string — printed by `basalt help` / `--help` / `-h` AND the unknown-command fallback. */
1669
1737
  const USAGE =
1670
1738
  'Usage: basalt-ui <init [--with-router] [--with-query] | sync [--force] [--check] | ' +
1671
- 'check-theme | check-coverage | info [--json] | doctor | guard-hook | help>\n\n' +
1739
+ 'check-theme | check-coverage | info [--json] | doctor | guard-hook | tokens:css | help>\n\n' +
1740
+ 'tokens:css [--out <path>] [--selector-attribute <attr>] [--dark-value <v>] [--light-value <v>]\n' +
1741
+ ' [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n' +
1742
+ ' Emit the --vx-* stylesheet (stdout unless --out). Defaults reproduce basalt-ui/tokens.css.\n\n' +
1672
1743
  'Every subcommand accepts --help / -h to print this message and exit without running.'
1673
1744
 
1674
1745
  /**
@@ -1712,6 +1783,8 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
1712
1783
  return doctor(cwd)
1713
1784
  case 'guard-hook':
1714
1785
  return guardHook(cwd)
1786
+ case 'tokens:css':
1787
+ return tokensCss(flags, cwd)
1715
1788
  default:
1716
1789
  console.error(USAGE)
1717
1790
  return 1
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `basalt-ui tokens:css` — the install-free path to the token system.
3
+ *
4
+ * The contract these tests hold is that the command is a FLAG PARSER, nothing more: whatever it
5
+ * prints must be exactly what `buildPaletteCss` returns for the same options. If the CLI ever grows
6
+ * emission logic of its own, a consumer who ran `bunx basalt-ui tokens:css` and a consumer who
7
+ * imported `basalt-ui/tokens` would be looking at two different design systems.
8
+ */
9
+ import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
10
+ import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
11
+ import { tmpdir } from 'node:os'
12
+ import { join, resolve } from 'node:path'
13
+
14
+ import { buildPaletteCss } from '../tokens'
15
+ import { run, tokensCss } from './index'
16
+
17
+ const FIXTURE = join(import.meta.dir, '..', '..', 'tests', 'fixtures', 'palette-default.css')
18
+
19
+ let dir: string
20
+
21
+ beforeEach(() => {
22
+ dir = mkdtempSync(resolve(tmpdir(), 'basalt-tokens-css-'))
23
+ writeFileSync(resolve(dir, 'package.json'), JSON.stringify({ name: 'fixture' }))
24
+ })
25
+
26
+ afterEach(() => {
27
+ rmSync(dir, { recursive: true, force: true })
28
+ })
29
+
30
+ /** Run the command with `--out`, returning the written file — stdout is awkward to capture here. */
31
+ function emit(flags: string[], out = 'out.css'): string {
32
+ const code = tokensCss([...flags, '--out', out], dir)
33
+ expect(code).toBe(0)
34
+ return readFileSync(resolve(dir, out), 'utf8')
35
+ }
36
+
37
+ describe('tokens:css', () => {
38
+ it('with no flags emits the shipped default, byte for byte', () => {
39
+ expect(emit([])).toBe(readFileSync(FIXTURE, 'utf8'))
40
+ })
41
+
42
+ it('forwards the selector flags to buildPaletteCss and adds nothing of its own', () => {
43
+ const flags = ['--selector-attribute', 'data-theme', '--default-scheme', 'light']
44
+ expect(emit(flags)).toBe(
45
+ buildPaletteCss({ scheme: { attribute: 'data-theme' }, defaultScheme: 'light' }),
46
+ )
47
+ })
48
+
49
+ it('forwards the scheme VALUES and the media fallback', () => {
50
+ const flags = ['--dark-value', 'night', '--light-value', 'day', '--media-fallback']
51
+ expect(emit(flags)).toBe(
52
+ buildPaletteCss({ scheme: { darkValue: 'night', lightValue: 'day' }, mediaFallback: true }),
53
+ )
54
+ })
55
+
56
+ it('forwards --only core', () => {
57
+ expect(emit(['--only', 'core'])).toBe(buildPaletteCss({ only: 'core' }))
58
+ })
59
+
60
+ it('rejects an unknown --only instead of silently emitting everything', () => {
61
+ expect(tokensCss(['--only', 'spacing', '--out', 'out.css'], dir)).toBe(1)
62
+ expect(existsSync(resolve(dir, 'out.css'))).toBe(false)
63
+ })
64
+
65
+ it('creates the parent directory of --out', () => {
66
+ const css = emit([], 'nested/deep/tokens.css')
67
+ expect(css.startsWith(':root {')).toBe(true)
68
+ })
69
+
70
+ it('rejects an unknown --default-scheme instead of silently defaulting', () => {
71
+ const code = tokensCss(['--default-scheme', 'sepia', '--out', 'out.css'], dir)
72
+ expect(code).toBe(1)
73
+ expect(existsSync(resolve(dir, 'out.css'))).toBe(false)
74
+ })
75
+
76
+ it('`--help` short-circuits before the command runs — no file written', () => {
77
+ const originalLog = console.log
78
+ let log = ''
79
+ console.log = (...args: unknown[]) => {
80
+ log += `${args.join(' ')}\n`
81
+ }
82
+ try {
83
+ expect(run(['tokens:css', '--out', 'out.css', '--help'], dir)).toBe(0)
84
+ } finally {
85
+ console.log = originalLog
86
+ }
87
+ expect(log).toContain('Usage: basalt')
88
+ expect(readdirSync(dir)).toEqual(['package.json'])
89
+ })
90
+ })
@@ -8,6 +8,7 @@
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
 
@@ -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
  })
@@ -1132,13 +1131,71 @@ describe('CSS applicability', () => {
1132
1131
 
1133
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)', () => {
1134
1133
  const f = checkSource(
1135
- '.foo {\n padding: 8px;\n margin: 4px;\n gap: 8px;\n}\n',
1134
+ '.foo {\n padding: 18px;\n margin: 13px;\n gap: 26px;\n}\n',
1136
1135
  'src/Card.module.css',
1137
1136
  DEFAULT_GUARD_CONFIG,
1138
1137
  )
1139
1138
  expect(kinds(f).filter((k) => k === 'inline-spacing')).toHaveLength(3)
1140
1139
  })
1141
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
+
1142
1199
  it('does NOT false-positive raw-form-control on a CSS element selector (input, select, textarea)', () => {
1143
1200
  const f = checkSource(
1144
1201
  'input, select, textarea {\n color: red;\n}\n',