basalt-ui 1.2.0 → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ # [1.4.0](https://github.com/jkrumm/basalt-ui/compare/v1.3.0...v1.4.0) (2026-07-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * let the shipped pre-commit hook see CSS ([fd3341f](https://github.com/jkrumm/basalt-ui/commit/fd3341fd9e648ee30e512f38d47596c4d67b2d00))
7
+ * make inline-spacing read the CSS a consumer actually writes ([77c930d](https://github.com/jkrumm/basalt-ui/commit/77c930d16fe27b0e98bb0ac05c92e8e0653df723)), closes [#25](https://github.com/jkrumm/basalt-ui/issues/25)
8
+ * widen this repo's own pre-commit formatter to match its CI ([b25455e](https://github.com/jkrumm/basalt-ui/commit/b25455ef918b2953c10c996f468eb1fd41f91dae))
9
+
10
+
11
+ ### Features
12
+
13
+ * give guard findings a severity so new rules can land soft ([1142ded](https://github.com/jkrumm/basalt-ui/commit/1142ded3f049054d316b3a8857c3fedc98a2fe46))
14
+ * have doctor report a spacing scale that moved under the app ([1e0ee4f](https://github.com/jkrumm/basalt-ui/commit/1e0ee4f1726fa4c358ec9bf6c22f075d1aebb665))
15
+
16
+ # [1.3.0](https://github.com/jkrumm/basalt-ui/compare/v1.2.0...v1.3.0) (2026-07-27)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * realign the spacing guard with the retuned scale and CSS reality ([dc6918a](https://github.com/jkrumm/basalt-ui/commit/dc6918a8e5753ce6b5ebb187ccc97421293a0014))
22
+ * stop styles.css reaching past the framework's own chrome ([24f66dc](https://github.com/jkrumm/basalt-ui/commit/24f66dc0e0bb9bd8386235ee3a9e2974eb6b452c))
23
+
24
+
25
+ ### Features
26
+
27
+ * add a core-only spacing emission mode to buildPaletteCss ([1a3d59b](https://github.com/jkrumm/basalt-ui/commit/1a3d59bb1558bb66771d3a51295993ab18084015))
28
+ * let buildPaletteCss target a custom color-scheme selector ([944a674](https://github.com/jkrumm/basalt-ui/commit/944a674c02a47b32c6badf7a2e000e4b0ccb26b3))
29
+ * make the react and mantine peers optional ([841f88f](https://github.com/jkrumm/basalt-ui/commit/841f88fdfed2ba946a72921b231bcdc427af173c))
30
+ * ship a prebuilt tokens.css and a tokens:css subcommand ([b23aca3](https://github.com/jkrumm/basalt-ui/commit/b23aca32b81cf4c9d580562cfc46b89a9c5a38da))
31
+
1
32
  # [1.2.0](https://github.com/jkrumm/basalt-ui/compare/v1.1.1...v1.2.0) (2026-07-27)
2
33
 
3
34
 
package/README.md CHANGED
@@ -22,13 +22,26 @@ bun add basalt-ui
22
22
  bun add react react-dom @mantine/core @mantine/hooks @tanstack/react-query
23
23
  ```
24
24
 
25
- Peer requirements: `react` / `react-dom` `^19`, `@mantine/core` + `@mantine/hooks` `^9.3`,
26
- `@tanstack/react-query` (`BasaltProvider` hard-requires it at build time). Bun auto-installs
27
- peers, but pnpm/npm consumers must add it explicitly or hit an unexplained build failure.
25
+ The root `.` entry needs all five: `react` / `react-dom` `^19`, `@mantine/core` +
26
+ `@mantine/hooks` `^9.3`, and `@tanstack/react-query` (`BasaltProvider` hard-requires it at build
27
+ time). **Install them yourself — every peer is declared `optional`**, so no package manager adds
28
+ them for you and a missing one surfaces as an unresolved import when you build, not as a warning
29
+ when you install. That optionality is what lets the Mantine-free subpaths cost nothing (below);
30
+ version mismatches on an installed peer still warn.
28
31
 
29
32
  A real app also needs `@types/react @types/react-dom` (dev) and a standard Vite `vite-env.d.ts`
30
33
  for `tsc --noEmit` to pass.
31
34
 
35
+ **No React?** `./tokens`, `./charts`, `./state` and `./guard` resolve with none of the five
36
+ installed, and the token system is consumable with no package at all:
37
+
38
+ ```bash
39
+ bunx basalt-ui tokens:css --selector-attribute data-theme --only core --out src/tokens.css
40
+ ```
41
+
42
+ See [`docs/FRAMEWORK-FREE.md`](https://github.com/jkrumm/basalt-ui/blob/master/docs/FRAMEWORK-FREE.md)
43
+ for the selector-specificity trap, the `color-mix` opacity law, and the surface-token roles.
44
+
32
45
  ### 2. Scaffold the repo doctrine (`basalt-ui init`)
33
46
 
34
47
  ```bash
@@ -199,6 +212,7 @@ scanned files. Other `"basalt"` config keys (`exempt`,
199
212
  | `./connectivity` | coupled | `ConnectivityProvider` (aggregates browser/React-Query/SSE/health-check status), `useConnectivity`, `ConnectivityIndicator` — auto-mounted by `BasaltProvider` |
200
213
  | `./content` | coupled | `Prose`, `CodeBlock`, `Callout`, `TableOfContents`, `ReadingProgress`, `Markdown`, `MermaidDiagram`, `ArticleLayout`, `ArticleCard` / `ArticleGrid`, `GuideLink` / `GuideDrawer`, `mdxComponents` |
201
214
  | `./styles.css` | — | `@layer basalt` base styles, iOS input safety net, font stack |
215
+ | `./tokens.css` | **free** | Prebuilt `--vx-*` stylesheet — the default `buildPaletteCss()` output as a plain file, for a consumer with no bundler, React or Mantine; `basalt-ui tokens:css` re-emits it with a custom scheme selector |
202
216
  | `./configs/*` | — | Raw toolchain presets — oxlint, oxfmt, tsconfig (base/react-app/node), lefthook |
203
217
  | `./llms.txt` | — | Machine-readable surface map — one entry per published subpath with import specifier, description, layer, and optional peers |
204
218
 
@@ -93,10 +93,12 @@ Popover, Accordion, cards) renders one border shade, one card background, and on
93
93
 
94
94
  ## Spacing & radius — prefer the scale token
95
95
 
96
- - `baseTheme` owns the scales: `spacing` 10/12/16/20/32 → `xs…xl`, `radius` 2/4/8/16/32 → `xs…xl`.
97
- **Use the token**, not the raw number, when a value equals a step: `p="md"` not `p={16}`,
98
- `gap="sm"` not `gap={12}`, `radius="sm"` not `radius={4}`. The guard flags exact token-equals
99
- (`p={16}`, any numeric `radius`).
96
+ - `baseTheme` owns the scales: `spacing` 11/13/18/20/26 → `xs…xl`, `radius` 2/4/6/16/32 → `xs…xl`.
97
+ Both are DERIVED — `deriveSpacing(level)` / `deriveRadius(level)` in `tokens/palette.ts` move them
98
+ with `createBasaltTheme`'s `density` / `radius` knobs, so read the numbers as level-0 values, not
99
+ as constants. **Use the token**, not the raw number, when a value equals a step: `p="md"` not
100
+ `p={18}`, `gap="sm"` not `gap={13}`, `radius="sm"` not `radius={4}`. The guard flags exact
101
+ token-equals (`p={18}`, any numeric `radius`).
100
102
  - **Card radius has one source: `--vx-radius-card` (7px) = `VX.radiusCard`.** Every
101
103
  card corner — the Mantine chrome (`Card`/`Paper`, `radius="md"`) and the Mantine-free `ChartCard`
102
104
  (`var(--vx-radius-card)`) — resolves to this single token; cards must never diverge. Don't inline
@@ -105,8 +107,17 @@ Popover, Accordion, cards) renders one border shade, one card background, and on
105
107
  spacing step (`sm`/`xs`) for shell, nav, and card padding rather than `md`/`lg` air (see
106
108
  basalt-mantine.md for the shipped dense defaults).
107
109
  - **Sub-scale micro-spacing is legitimate and allowed raw** — `gap={2}`, `pl={4}`, `mt={6}` have no
108
- token equivalent (the scale starts at 10). Use them freely for tight clusters; don't invent
110
+ token equivalent (the scale starts at 11). Use them freely for tight clusters; don't invent
109
111
  micro-tokens or pepper `theme-allow`. One-off layout dims (`h={36}`, `w={64}`) are also fine raw.
112
+ **The same permission holds in CSS modules**, where it has to be enforced differently: there is no
113
+ prop form to prefer, so `inline-spacing` simply does not fire on a declaration whose every literal
114
+ is ≤ 10px (`gap: 2px`, `padding: 4px 8px`). It reads longhands and logical properties too
115
+ (`padding-top`, `margin-inline`, `row-gap`, `padding-inline-start`), not just the shorthands.
116
+ `rem` resolves against the 16px root, so `0.25rem` and `4px` get the same answer; units that need
117
+ layout context (`em`, `%`, `ch`, `vw`) are not micro-spacing claims and flag. A `var()` component
118
+ is dropped before that judgement; one non-micro value makes the whole declaration a finding
119
+ (`padding: 4px 16px` flags). An inline style OBJECT in TSX (`style={{ padding: 4 }}`) also still
120
+ flags: there the Mantine prop exists and should have been used.
110
121
  - **Icons** size via the icon's own `size` prop (`size={16}`), not spacing tokens — that's not spacing.
111
122
 
112
123
  ## Type
@@ -12,14 +12,21 @@ pre-commit:
12
12
  oxlint:
13
13
  glob: '*.{ts,tsx,js,jsx}'
14
14
  run: bunx oxlint {staged_files}
15
+ # `css` is load-bearing, not tidiness: oxfmt formats stylesheets, so without it a CSS-only
16
+ # commit passes the hook and then fails the same check in CI. `oxlint` above deliberately
17
+ # stops at JS — it has nothing to say about CSS.
15
18
  oxfmt:
16
- glob: '*.{ts,tsx,js,jsx,json,md,yml,yaml}'
19
+ glob: '*.{ts,tsx,js,jsx,css,json,md,yml,yaml}'
17
20
  run: bunx oxfmt --check {staged_files}
18
21
 
19
- # Scans the configured `basalt.roots`, not {staged_files}. A guard that only runs when
20
- # someone remembers to run it is not a guard: without this, a consumer can accumulate
21
- # violations indefinitely while `check-theme` is never invoked, and the kinds it never
22
- # ran are indistinguishable from the kinds that found nothing.
22
+ # NO glob, deliberately. This command scans the configured `basalt.roots` — it never reads
23
+ # {staged_files} — so any glob here is a gate on WHETHER the guard runs, decided by the file
24
+ # extensions that happen to be in one commit. It shipped as `*.{ts,tsx}`, which meant a commit
25
+ # touching only CSS modules skipped the guard entirely; the guard reads CSS (raw-hex,
26
+ # inline-spacing, raw-font-family and the surface kinds all fire there), so the rule was
27
+ # invisible to the hook meant to enforce it. That is precisely the failure the next sentence
28
+ # was written against: a guard that only runs when someone remembers to run it is not a guard.
29
+ # Without this, a consumer accumulates violations indefinitely while `check-theme` is never
30
+ # invoked, and the kinds it never ran are indistinguishable from the kinds that found nothing.
23
31
  check-theme:
24
- glob: '*.{ts,tsx}'
25
32
  run: bunx basalt-ui check-theme
@@ -1,4 +1,4 @@
1
- import type { GuardKind } from '../guard/index.js';
1
+ import type { GuardKind, GuardSeverity } from '../guard/index.js';
2
2
  import { RULE_NAMES, SKILL_NAMES } from '../surfaces.js';
3
3
  /** Shape of the optional `"basalt"` key in a consumer's package.json. */
4
4
  export type BasaltConfig = {
@@ -8,6 +8,9 @@ export type BasaltConfig = {
8
8
  exempt?: string[];
9
9
  /** Named spacing-scale steps (px) flagged when used as a raw spacing prop. Default: 10/12/16/20/32. */
10
10
  spacingSteps?: number[];
11
+ /** Per-kind severity override — `'warn'` reports without failing, `'error'` fails the build.
12
+ * See `GuardSeverity` in ../guard/types for the grace-minor doctrine behind it. */
13
+ severity?: Partial<Record<GuardKind, GuardSeverity>>;
11
14
  /** Off-identity Mantine accent families forbidden as chrome accents. Default: argo's set. */
12
15
  forbiddenAccents?: string[];
13
16
  /** Earned accent hue recorded in DESIGN.md `{{ACCENT_HUE}}`. Default: `blue`. */
@@ -201,6 +204,19 @@ type Manifest = {
201
204
  basaltVersion?: string;
202
205
  /** dest path → sha256 of the managed unit (file bytes, block body, or stanza) at last write. */
203
206
  files: Record<string, string>;
207
+ /**
208
+ * The resolved level-0 spacing scale (`xs`..`xl`, px) at last write — `doctor`'s second
209
+ * reconciliation axis, and the only one that reports a change in RENDERED OUTPUT rather than in
210
+ * placed files.
211
+ *
212
+ * A retune of the spacing bases moves every surface in every consumer calling
213
+ * `createBasaltTheme()` bare. basalt-ui bans majors by design, so the changelog is the only
214
+ * channel that carries that, and a one-line `feat:` subject cannot convey blast radius: the
215
+ * 1.2.0 retune shipped as "tighten the sidebar, open up components" and went unverified in
216
+ * production for a day because nothing said "every padding moved". Recording the scale makes the
217
+ * move mechanically visible on the next `doctor` run instead of depending on a subject line.
218
+ */
219
+ spacingScale?: Record<string, number>;
204
220
  };
205
221
  /**
206
222
  * Normalize a managed unit's rendered bytes for the ledger comparison below — makes a delta that is
@@ -283,9 +299,11 @@ type DoctorResult = {
283
299
  * 2. The installed node_modules/basalt-ui version matches the manifest's basaltVersion
284
300
  * (a mismatch means the package was upgraded but `sync` never ran — the placed doctrine is
285
301
  * stale).
286
- * 3. The running CLI's own version matches the installed basalt-ui (catches a stale
302
+ * 3. The spacing scale still matches the one stamped into the manifest at the last init/sync
303
+ * (skipped when this CLI is demonstrably not the installed package — see the check).
304
+ * 4. The running CLI's own version matches the installed basalt-ui (catches a stale
287
305
  * `bunx basalt-ui` npm fetch; best-effort, skipped if node_modules is absent).
288
- * 4. `basaltAppPlugin`'s (basalt-ui/vite) default icon filenames exist under public/ (only when
306
+ * 5. `basaltAppPlugin`'s (basalt-ui/vite) default icon filenames exist under public/ (only when
289
307
  * a public/ dir exists at all — skipped otherwise).
290
308
  *
291
309
  * Returns the exit code: 0 = all good, 1 = one or more hard failures.
@@ -314,6 +332,20 @@ export type InfoOutput = {
314
332
  * `basalt info --json` → stable JSON (InfoOutput shape)
315
333
  */
316
334
  export declare function info(flags: string[]): number;
335
+ /**
336
+ * tokens:css — emit the `--vx-*` stylesheet, optionally retargeted.
337
+ *
338
+ * The escape hatch from installing anything: a static site runs this once (`bunx basalt-ui
339
+ * tokens:css --selector-attribute data-theme --out src/tokens.css`) and consumes basalt's token
340
+ * system as plain CSS, with no package in its dependency tree at all. `basalt-ui/tokens.css` is the
341
+ * same artifact for a consumer that does install; this command exists for the ones that shouldn't
342
+ * have to just to change a selector.
343
+ *
344
+ * It parses flags and calls `buildPaletteCss` — nothing else. No emission logic, no post-processing
345
+ * of the returned string: the CLI and the API must not be able to disagree about what basalt's
346
+ * tokens are.
347
+ */
348
+ export declare function tokensCss(flags: string[], cwd?: string): number;
317
349
  /**
318
350
  * guard-hook — PreToolUse stdin adapter.
319
351
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,UAAU,CAAA;AAE/D,OAAO,EAAE,UAAU,EAAE,WAAW,EAA2C,MAAM,aAAa,CAAA;AAG9F,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG;IACzB,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,uGAAuG;IACvG,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAA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CHANGED
@@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url";
13
13
  import { checkSource, DEFAULT_GUARD_CONFIG, GUARD_RULES } from "../guard/index.js";
14
14
  import { evaluateGuardHook } from "../guard/guard-hook.js";
15
15
  import { RULE_NAMES, SKILL_NAMES, SURFACES, TOKEN_LAYER_BOUNDARY_SURFACES } from "../surfaces.js";
16
+ import { buildPaletteCss, deriveSpacing } from "../tokens/index.js";
16
17
  const DEFAULT_ROOT = "src";
17
18
  const DEFAULT_ROOTS = [DEFAULT_ROOT];
18
19
  function resolveRoots(cfg) {
@@ -31,10 +32,31 @@ function defaultExempt(cfg) {
31
32
  }
32
33
  const SKIP = /\.gen\.ts$|\.test\.[tj]sx?$|\.d\.ts$/;
33
34
  const SERIES_MODULE_HINT_RE = /(series|palette)\.tsx?$/i;
35
+ const SEVERITY_VALUES = ["warn", "error"];
36
+ function sanitizeSeverity(cfg) {
37
+ const raw = cfg.severity;
38
+ if (raw === void 0) return cfg;
39
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
40
+ console.error("\u26A0 basalt.severity is not an object \u2014 ignoring it; every kind keeps its default.");
41
+ const { severity: _dropped, ...rest } = cfg;
42
+ return rest;
43
+ }
44
+ const kept = {};
45
+ for (const [kind, value] of Object.entries(raw)) {
46
+ if (typeof value === "string" && SEVERITY_VALUES.includes(value)) {
47
+ kept[kind] = value;
48
+ continue;
49
+ }
50
+ console.error(
51
+ `\u26A0 basalt.severity["${kind}"] is ${JSON.stringify(value)}, not 'warn' or 'error' \u2014 ignoring it; that kind keeps its default severity.`
52
+ );
53
+ }
54
+ return { ...cfg, severity: kept };
55
+ }
34
56
  function readBasaltConfig(cwd) {
35
57
  try {
36
58
  const pkg = JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
37
- return pkg.basalt ?? {};
59
+ return sanitizeSeverity(pkg.basalt ?? {});
38
60
  } catch {
39
61
  return {};
40
62
  }
@@ -100,7 +122,8 @@ function checkTheme(cwd = process.cwd()) {
100
122
  rawFormControl: cfg.rawFormControl ?? DEFAULT_GUARD_CONFIG.rawFormControl,
101
123
  sub16InputFont: cfg.sub16InputFont ?? DEFAULT_GUARD_CONFIG.sub16InputFont,
102
124
  allowComment: "theme-allow",
103
- exemptRules: cfg.exemptRules ?? DEFAULT_GUARD_CONFIG.exemptRules
125
+ exemptRules: cfg.exemptRules ?? DEFAULT_GUARD_CONFIG.exemptRules,
126
+ severity: cfg.severity ?? DEFAULT_GUARD_CONFIG.severity
104
127
  };
105
128
  const findings = [];
106
129
  let scannedCount = 0;
@@ -129,20 +152,37 @@ function checkTheme(cwd = process.cwd()) {
129
152
  console.log("\u2713 Theme guard: no off-palette colors.");
130
153
  return 0;
131
154
  }
132
- const byFile = /* @__PURE__ */ new Map();
133
- for (const f of findings) {
134
- const list = byFile.get(f.relPath) ?? [];
135
- list.push(f);
136
- byFile.set(f.relPath, list);
155
+ const errors = findings.filter((f) => f.severity === "error");
156
+ const warnings = findings.filter((f) => f.severity === "warn");
157
+ const report = (group, heading) => {
158
+ const byFile = /* @__PURE__ */ new Map();
159
+ for (const f of group) {
160
+ const list = byFile.get(f.relPath) ?? [];
161
+ list.push(f);
162
+ byFile.set(f.relPath, list);
163
+ }
164
+ console.error(heading);
165
+ for (const [file, vs] of [...byFile].toSorted()) {
166
+ console.error(file);
167
+ for (const v of vs.toSorted((a, b) => a.line - b.line)) {
168
+ console.error(` ${String(v.line).padStart(4)} ${v.kind.padEnd(22)} ${v.token}`);
169
+ }
170
+ console.error("");
171
+ }
172
+ };
173
+ if (warnings.length > 0) {
174
+ report(
175
+ warnings,
176
+ // Deliberately neutral about WHY a kind is a warning. Two origins reach this block — a kind
177
+ // in its grace minor, and a consumer's own `basalt.severity` override — and the finding
178
+ // doesn't carry which. Promising promotion next minor would be wrong for the second.
179
+ `\u26A0 Theme guard: ${warnings.length} warning(s) \u2014 reported, not fatal. A kind warns while it is in its grace minor, or because \`basalt.severity\` turned it down; fix on your own schedule.
180
+ `
181
+ );
137
182
  }
138
- console.error(`\u2716 Theme guard: ${findings.length} off-palette / off-identity violation(s)
183
+ if (errors.length > 0) {
184
+ report(errors, `\u2716 Theme guard: ${errors.length} off-palette / off-identity violation(s)
139
185
  `);
140
- for (const [file, vs] of [...byFile].toSorted()) {
141
- console.error(file);
142
- for (const v of vs.toSorted((a, b) => a.line - b.line)) {
143
- console.error(` ${String(v.line).padStart(4)} ${v.kind.padEnd(22)} ${v.token}`);
144
- }
145
- console.error("");
146
186
  }
147
187
  const presentKinds = new Set(findings.map((f) => f.kind));
148
188
  const explanations = Object.keys(GUARD_KIND_EXPLANATIONS).filter((kind) => presentKinds.has(kind)).map((kind) => GUARD_KIND_EXPLANATIONS[kind]);
@@ -152,12 +192,12 @@ function checkTheme(cwd = process.cwd()) {
152
192
  "Add a `theme-allow` comment for a deliberate exception."
153
193
  ];
154
194
  console.error(fixLine.join(" "));
155
- if ([...byFile.keys()].some((f) => SERIES_MODULE_HINT_RE.test(f))) {
195
+ if (findings.some((f) => SERIES_MODULE_HINT_RE.test(f.relPath))) {
156
196
  console.error(
157
197
  'Hint: if a flagged file IS your palette/series source, exempt it via "basalt": { "exempt": ["<path>"] } in package.json.'
158
198
  );
159
199
  }
160
- return 1;
200
+ return errors.length > 0 ? 1 : 0;
161
201
  }
162
202
  const BLOCK_BEGIN_PREFIX = "<!-- basalt:begin";
163
203
  const BLOCK_END = "<!-- basalt:end -->";
@@ -340,6 +380,10 @@ function readManifest(cwd) {
340
380
  const parsed = JSON.parse(raw);
341
381
  const manifest = { version: 1, files: parsed.files ?? {} };
342
382
  if (typeof parsed.basaltVersion === "string") manifest.basaltVersion = parsed.basaltVersion;
383
+ const scale = parsed.spacingScale;
384
+ if (scale !== null && scale !== void 0 && typeof scale === "object" && !Array.isArray(scale) && Object.values(scale).every((v) => typeof v === "number")) {
385
+ manifest.spacingScale = scale;
386
+ }
343
387
  return manifest;
344
388
  } catch {
345
389
  return { version: 1, files: {} };
@@ -438,6 +482,7 @@ function init(cwd = process.cwd(), scaffoldFlags = {}) {
438
482
  written++;
439
483
  }
440
484
  manifest.basaltVersion = ctx.vars.BASALT_VERSION;
485
+ manifest.spacingScale = { ...deriveSpacing(0).scale };
441
486
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}
442
487
  `);
443
488
  console.log(`basalt-ui init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`);
@@ -528,6 +573,7 @@ function sync(opts = {}, cwd = process.cwd()) {
528
573
  return 0;
529
574
  }
530
575
  manifest.basaltVersion = ctx.vars.BASALT_VERSION;
576
+ manifest.spacingScale = { ...deriveSpacing(0).scale };
531
577
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}
532
578
  `);
533
579
  console.log(
@@ -703,6 +749,28 @@ basalt-ui doctor \u2014 ${cwd}
703
749
  }
704
750
  }
705
751
  const cliVersion = readFrameworkVersion(packageRoot());
752
+ const cliIsTheInstall = installedVersion === null || installedVersion === cliVersion;
753
+ if (manifestExists && !cliIsTheInstall) {
754
+ pass(
755
+ `spacing scale not compared \u2014 this CLI (${cliVersion}) is not the installed basalt-ui (${installedVersion}), so its scale is not the one the app renders with`
756
+ );
757
+ } else if (manifestExists) {
758
+ const recorded = readManifest(cwd).spacingScale;
759
+ const current = deriveSpacing(0).scale;
760
+ if (recorded === void 0) {
761
+ pass("spacing scale not yet recorded \u2014 `basalt-ui sync` will stamp it");
762
+ } else {
763
+ const steps = [.../* @__PURE__ */ new Set([...Object.keys(current), ...Object.keys(recorded)])].toSorted();
764
+ const moved = steps.filter((step) => recorded[step] !== current[step]).map((step) => `${step} ${recorded[step] ?? "(none)"}\u2192${current[step] ?? "(removed)"}`);
765
+ if (moved.length > 0) {
766
+ warn(
767
+ `the spacing scale moved since the last sync (${moved.join(", ")}) \u2014 every surface in an app calling createBasaltTheme() bare shifts with it. Review the app visually, then run \`basalt-ui sync\` to record the new scale.`
768
+ );
769
+ } else {
770
+ pass("spacing scale matches the last sync");
771
+ }
772
+ }
773
+ }
706
774
  if (installedVersion !== null) {
707
775
  if (installedVersion !== cliVersion) {
708
776
  warn(
@@ -814,6 +882,51 @@ basalt-ui v${pkgVersion} \u2014 published surface
814
882
  console.log("");
815
883
  return 0;
816
884
  }
885
+ function flagValue(flags, name) {
886
+ const i = flags.indexOf(name);
887
+ if (i === -1) return void 0;
888
+ const value = flags[i + 1];
889
+ return value === void 0 || value.startsWith("--") ? void 0 : value;
890
+ }
891
+ function tokensCss(flags, cwd = process.cwd()) {
892
+ const attribute = flagValue(flags, "--selector-attribute");
893
+ const darkValue = flagValue(flags, "--dark-value");
894
+ const lightValue = flagValue(flags, "--light-value");
895
+ const defaultScheme = flagValue(flags, "--default-scheme");
896
+ const only = flagValue(flags, "--only");
897
+ if (defaultScheme !== void 0 && !["dark", "light", "none"].includes(defaultScheme)) {
898
+ console.error(
899
+ `tokens:css: --default-scheme must be dark, light or none (got '${defaultScheme}')`
900
+ );
901
+ return 1;
902
+ }
903
+ if (only !== void 0 && !["core", "all"].includes(only)) {
904
+ console.error(`tokens:css: --only must be core or all (got '${only}')`);
905
+ return 1;
906
+ }
907
+ const scheme = {
908
+ ...attribute === void 0 ? {} : { attribute },
909
+ ...darkValue === void 0 ? {} : { darkValue },
910
+ ...lightValue === void 0 ? {} : { lightValue }
911
+ };
912
+ const css = buildPaletteCss({
913
+ ...Object.keys(scheme).length === 0 ? {} : { scheme },
914
+ ...defaultScheme === void 0 ? {} : { defaultScheme },
915
+ ...flags.includes("--media-fallback") ? { mediaFallback: true } : {},
916
+ ...only === void 0 ? {} : { only }
917
+ });
918
+ const out = flagValue(flags, "--out");
919
+ if (out === void 0) {
920
+ process.stdout.write(`${css}
921
+ `);
922
+ return 0;
923
+ }
924
+ const target = isAbsolute(out) ? out : resolve(cwd, out);
925
+ mkdirSync(dirname(target), { recursive: true });
926
+ writeFileSync(target, css);
927
+ console.log(`wrote ${css.split("\n").length} lines \u2192 ${relative(cwd, target) || target}`);
928
+ return 0;
929
+ }
817
930
  async function guardHook(cwd = process.cwd()) {
818
931
  let raw;
819
932
  try {
@@ -857,7 +970,8 @@ async function guardHook(cwd = process.cwd()) {
857
970
  rawFormControl: cfg.rawFormControl ?? DEFAULT_GUARD_CONFIG.rawFormControl,
858
971
  sub16InputFont: cfg.sub16InputFont ?? DEFAULT_GUARD_CONFIG.sub16InputFont,
859
972
  allowComment: "theme-allow",
860
- exemptRules: cfg.exemptRules ?? DEFAULT_GUARD_CONFIG.exemptRules
973
+ exemptRules: cfg.exemptRules ?? DEFAULT_GUARD_CONFIG.exemptRules,
974
+ severity: cfg.severity ?? DEFAULT_GUARD_CONFIG.severity
861
975
  };
862
976
  const roots = cfg.roots ?? DEFAULT_ROOTS;
863
977
  const exempt = new Set(cfg.exempt ?? defaultExempt(cfg));
@@ -889,7 +1003,7 @@ async function guardHook(cwd = process.cwd()) {
889
1003
  }
890
1004
  return 0;
891
1005
  }
892
- const USAGE = "Usage: basalt-ui <init [--with-router] [--with-query] | sync [--force] [--check] | check-theme | check-coverage | info [--json] | doctor | guard-hook | help>\n\nEvery subcommand accepts --help / -h to print this message and exit without running.";
1006
+ const USAGE = "Usage: basalt-ui <init [--with-router] [--with-query] | sync [--force] [--check] | check-theme | check-coverage | info [--json] | doctor | guard-hook | tokens:css | help>\n\ntokens:css [--out <path>] [--selector-attribute <attr>] [--dark-value <v>] [--light-value <v>]\n [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n Emit the --vx-* stylesheet (stdout unless --out). Defaults reproduce basalt-ui/tokens.css.\n\nEvery subcommand accepts --help / -h to print this message and exit without running.";
893
1007
  function run(argv, cwd = process.cwd()) {
894
1008
  const [cmd, ...flags] = argv;
895
1009
  if (cmd === "help" || cmd === "--help" || cmd === "-h" || flags.includes("--help") || flags.includes("-h")) {
@@ -914,6 +1028,8 @@ function run(argv, cwd = process.cwd()) {
914
1028
  return doctor(cwd);
915
1029
  case "guard-hook":
916
1030
  return guardHook(cwd);
1031
+ case "tokens:css":
1032
+ return tokensCss(flags, cwd);
917
1033
  default:
918
1034
  console.error(USAGE);
919
1035
  return 1;
@@ -932,5 +1048,6 @@ export {
932
1048
  managedFiles,
933
1049
  normalizeForLedger,
934
1050
  run,
935
- sync
1051
+ sync,
1052
+ tokensCss
936
1053
  };
@@ -1 +1 @@
1
- {"version":3,"file":"guard-hook.d.ts","sourceRoot":"","sources":["../../src/guard/guard-hook.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAmDrE;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,EAAE,OAAO,GAAG,MAAM,CAAA;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,qCAAqC;AACrC,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAA;CACzC,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,WAAW,EAChB,IAAI,CAAC,EAAE,wBAAwB,GAC9B,eAAe,CAqBjB"}
1
+ {"version":3,"file":"guard-hook.d.ts","sourceRoot":"","sources":["../../src/guard/guard-hook.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAmDrE;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,EAAE,OAAO,GAAG,MAAM,CAAA;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,qCAAqC;AACrC,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAA;CACzC,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,WAAW,EAChB,IAAI,CAAC,EAAE,wBAAwB,GAC9B,eAAe,CA0BjB"}
@@ -40,7 +40,9 @@ function evaluateGuardHook(payload, cfg, opts) {
40
40
  if (opts?.isInScope !== void 0 && !opts.isInScope(target.relPath)) {
41
41
  return { permissionDecision: "allow" };
42
42
  }
43
- const findings = checkSource(target.text, target.relPath, cfg);
43
+ const findings = checkSource(target.text, target.relPath, cfg).filter(
44
+ (f) => f.severity === "error"
45
+ );
44
46
  if (findings.length === 0) return { permissionDecision: "allow" };
45
47
  const shown = findings.slice(0, 10);
46
48
  const lines = shown.map((f) => `${f.kind} @ ${f.line}: ${f.token}`);
@@ -4,8 +4,8 @@
4
4
  * GUARD_RULES: the closed registry of all 19 violation kinds.
5
5
  * checkSource: pure (text, relPath, cfg) → Finding[]. No FS, no walk, no console.
6
6
  */
7
- import type { Finding, GuardConfig, GuardKind } from './types.js';
8
- export type { Finding, GuardConfig, GuardKind };
7
+ import type { Finding, GuardConfig, GuardKind, GuardSeverity } from './types.js';
8
+ export type { Finding, GuardConfig, GuardKind, GuardSeverity };
9
9
  /** Shared default config — CLI and tests import this to avoid duplication. */
10
10
  export declare const DEFAULT_GUARD_CONFIG: GuardConfig;
11
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAE9D,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;AAgI/C,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,EAAE,WAkBlC,CAAA;AA0QD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;gCA0BL,WAAW;;;;;;gCAaX,WAAW;;;;;;;gCAaX,WAAW;;;;;;;gCAQX,WAAW;;;;;;gCAOX,WAAW;;;;;;;gCASX,WAAW;;;;;;gCAOX,WAAW;;;;;;;gCASX,WAAW;;;;;;gCAMX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCAUX,WAAW;;;;;;;gCAUX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCAUX,WAAW;;;;CAOmB,CAAA;AAUjD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,EAAE,CAqNtF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7E,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA;AA6N9D,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,EAAE,WAmBlC,CAAA;AAgSD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;gCA0BL,WAAW;;;;;;gCAaX,WAAW;;;;;;;gCAaX,WAAW;;;;;;;gCAQX,WAAW;;;;;;gCAOX,WAAW;;;;;;;gCASX,WAAW;;;;;;gCAOX,WAAW;;;;;;;gCASX,WAAW;;;;;;gCAMX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCAUX,WAAW;;;;;;;gCAUX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCASX,WAAW;;;;;;;gCAUX,WAAW;;;;CAOmB,CAAA;AAUjD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,EAAE,CA2NtF"}
@@ -16,7 +16,29 @@ const OFF_SYSTEM_SURFACE_VAR = /var\(--mantine-color-(gray|dark)-\d/g;
16
16
  const RAW_HTML_TAG = /<(?:div|span|section|header|nav|footer|aside|main|article|ul|ol)\b/;
17
17
  const INLINE_STYLE = /style=\{\{/;
18
18
  const LAYOUT_SURFACE_PROP = /\b(?:display|padding|margin|gap|flex|grid|border|background|width|height)\b/;
19
- const INLINE_SPACING = /\b(?:padding(?:Top|Bottom|Left|Right)?|margin(?:Top|Bottom|Left|Right)?|gap|rowGap|columnGap)\s*:\s*(?!var\()['"]?-?(?!0\b)\d/g;
19
+ const BOX_SIDE = "(?:Top|Bottom|Left|Right|Block|Inline)(?:Start|End)?";
20
+ const BOX_SIDE_KEBAB = "(?:top|bottom|left|right|block|inline)(?:-(?:start|end))?";
21
+ const SPACING_PROP = `(?:padding|margin)(?:${BOX_SIDE}|-${BOX_SIDE_KEBAB})?|gap|rowGap|columnGap|row-gap|column-gap`;
22
+ const INLINE_SPACING = new RegExp(
23
+ `(?<![\\w-])(?:${SPACING_PROP})\\s*:\\s*(?!var\\()['"]?[-+]?(?!0(?![.\\d]))(?:\\d|\\.\\d)`,
24
+ "g"
25
+ );
26
+ const MICRO_SPACING_CEILING_PX = 10;
27
+ const ROOT_FONT_SIZE_PX = 16;
28
+ function isSubScaleCssSpacing(line, matchIndex) {
29
+ const colon = line.indexOf(":", matchIndex);
30
+ if (colon === -1) return false;
31
+ const rest = line.slice(colon + 1);
32
+ const end = rest.search(/[;}]/);
33
+ const value = (end === -1 ? rest : rest.slice(0, end)).replace(/var\([^)]*\)/g, " ").trim();
34
+ if (value === "") return true;
35
+ return value.split(/\s+/).every((part) => {
36
+ const literal = /^[-+]?(\d+(?:\.\d+)?|\.\d+)(px|rem)?$/.exec(part);
37
+ if (literal === null) return false;
38
+ const px = literal[2] === "rem" ? Number(literal[1]) * ROOT_FONT_SIZE_PX : Number(literal[1]);
39
+ return px <= MICRO_SPACING_CEILING_PX;
40
+ });
41
+ }
20
42
  const INLINE_DISPLAY = /\bdisplay\s*:\s*['"](?:inline-)?(?:flex|grid)['"]/g;
21
43
  const RAW_VISX_AXIS = /<Axis(?:Left|Bottom|Right)\b/g;
22
44
  const AXIS_WRAPPER_FILE = /(?:^|\/)Axes\.tsx$/;
@@ -30,7 +52,7 @@ const RAW_FORM_CONTROL = /<(?:input|select|textarea)\b/g;
30
52
  const RAW_FORM_CONTROL_TAG = /<(?:input|select|textarea)\b(?:=>|[^>])*?>/g;
31
53
  const STYLES_INPUT_PART = /\bstyles\s*=\s*\{\{\s*input\s*:\s*\{([^}]*)\}/g;
32
54
  const SUB_16_FONT_SIZE = /font-?[Ss]ize\s*:\s*['"]?(-?\d+(?:\.\d+)?)(?:px)?['"]?(?=[,\s}]|$)/g;
33
- const DEFAULT_SPACING_STEPS = [10, 12, 16, 20, 32];
55
+ const DEFAULT_SPACING_STEPS = [11, 13, 18, 20, 26];
34
56
  const DEFAULT_FORBIDDEN_ACCENTS = ["teal", "violet", "grape", "indigo", "pink"];
35
57
  const DEFAULT_GUARD_CONFIG = {
36
58
  spacingSteps: DEFAULT_SPACING_STEPS,
@@ -49,8 +71,13 @@ const DEFAULT_GUARD_CONFIG = {
49
71
  rawFormControl: true,
50
72
  sub16InputFont: true,
51
73
  allowComment: "theme-allow",
52
- exemptRules: {}
74
+ exemptRules: {},
75
+ severity: {}
53
76
  };
77
+ const GRACE_PERIOD_KINDS = {};
78
+ function severityOf(kind, cfg) {
79
+ return cfg.severity?.[kind] ?? (kind in GRACE_PERIOD_KINDS ? "warn" : "error");
80
+ }
54
81
  function isChartFile(relPath) {
55
82
  return relPath.includes("/charts/") && !AXIS_WRAPPER_FILE.test(relPath);
56
83
  }
@@ -384,7 +411,8 @@ function checkSource(text, relPath, cfg) {
384
411
  GUARD_RULES["raw-radius"].pattern.flags
385
412
  );
386
413
  const lines = text.split("\n");
387
- const codeText = stripComments(text, guardSyntaxFor(relPath));
414
+ const syntax = guardSyntaxFor(relPath);
415
+ const codeText = stripComments(text, syntax);
388
416
  const codeLines = codeText.split("\n");
389
417
  for (let i = 0; i < lines.length; i++) {
390
418
  const line = codeLines[i] ?? "";
@@ -439,6 +467,7 @@ function checkSource(text, relPath, cfg) {
439
467
  }
440
468
  if (GUARD_RULES["inline-spacing"].enabled(cfg)) {
441
469
  for (const m of line.matchAll(GUARD_RULES["inline-spacing"].pattern)) {
470
+ if (syntax === "css" && isSubScaleCssSpacing(line, m.index)) continue;
442
471
  findings.push({ relPath, line: i + 1, token: m[0], kind: "inline-spacing" });
443
472
  }
444
473
  }
@@ -519,7 +548,7 @@ function checkSource(text, relPath, cfg) {
519
548
  findings.push({ relPath, line: lineNo, token: fontSizeMatch[0], kind: "sub-16-input-font" });
520
549
  }
521
550
  }
522
- return findings.filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules));
551
+ return findings.filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules)).map((f) => ({ ...f, severity: severityOf(f.kind, cfg) }));
523
552
  }
524
553
  export {
525
554
  DEFAULT_GUARD_CONFIG,