basalt-ui 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +37 -0
- package/README.md +47 -5
- package/agent/rules/basalt-app.md +126 -0
- package/agent/rules/basalt-content.md +3 -1
- package/agent/skills/basalt-app/SKILL.md +32 -10
- package/configs/check.yml +3 -1
- package/configs/oxlint.json +1 -1
- package/dist/agent/part-list.d.ts.map +1 -1
- package/dist/agent/part-list.js +17 -7
- package/dist/agent/stick-to-bottom.js +2 -2
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
- package/dist/agent-chat/thread-detail-panel.js +37 -33
- package/dist/agent-chat/thread-message.d.ts.map +1 -1
- package/dist/agent-chat/thread-message.js +8 -5
- package/dist/agent-chat/thread-outcome-card.js +3 -3
- package/dist/agent-chat/thread-workspace.js +1 -1
- package/dist/charts/primitives/ChartLegend.js +2 -0
- package/dist/charts/primitives/ChartTooltip.js +2 -1
- package/dist/cli/index.d.ts +21 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +50 -12
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
- package/dist/connectivity/connectivity-indicator.js +3 -3
- package/dist/content/article-card.module.css +7 -5
- package/dist/content/article-layout.module.css +16 -12
- package/dist/content/callout.module.css +4 -4
- package/dist/content/code-block.module.css +8 -7
- package/dist/content/guide.module.css +3 -3
- package/dist/content/mermaid.module.css +2 -2
- package/dist/content/prose.module.css +59 -29
- package/dist/content/reading-progress.module.css +2 -0
- package/dist/content/toc.module.css +6 -3
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +10 -2
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +3 -16
- package/dist/dashboard/settings-section.js +2 -2
- package/dist/dashboard/settings-section.module.css +2 -2
- package/dist/dashboard/stat-card.js +2 -1
- package/dist/data/virtual-list.d.ts.map +1 -1
- package/dist/data/virtual-list.js +12 -2
- package/dist/forms/FormErrorSummary.js +2 -2
- package/dist/guard/index.d.ts +20 -4
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +250 -37
- package/dist/guard/types.d.ts +24 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/provider/index.d.ts +30 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +32 -7
- package/dist/provider/lab-theme.d.ts +39 -0
- package/dist/provider/lab-theme.d.ts.map +1 -0
- package/dist/provider/lab-theme.js +52 -0
- package/dist/shell/app-header.module.css +2 -2
- package/dist/shell/app-mobile-nav.module.css +1 -1
- package/dist/shell/app-sidebar-account.d.ts.map +1 -1
- package/dist/shell/app-sidebar-account.js +4 -2
- package/dist/shell/app-sidebar.d.ts.map +1 -1
- package/dist/shell/app-sidebar.js +4 -2
- package/dist/shell/app-sidebar.module.css +36 -26
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +11 -4
- package/dist/shell/sidebar-search.module.css +16 -4
- package/dist/styles.css +1 -1
- package/dist/surfaces.d.ts +16 -12
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +12 -4
- package/dist/theme/controls.module.css +1 -1
- package/dist/theme/floating.module.css +1 -1
- package/dist/theme/index.d.ts +116 -11
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +703 -566
- package/dist/theme/nav-link.module.css +1 -1
- package/dist/theme/use-basalt-spacing.d.ts +3 -0
- package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
- package/dist/theme/use-basalt-spacing.js +8 -0
- package/dist/theme-lab/derive-controls.d.ts +13 -0
- package/dist/theme-lab/derive-controls.d.ts.map +1 -0
- package/dist/theme-lab/derive-controls.js +137 -0
- package/dist/theme-lab/derive-state.d.ts +55 -0
- package/dist/theme-lab/derive-state.d.ts.map +1 -0
- package/dist/theme-lab/derive-state.js +81 -0
- package/dist/theme-lab/index.d.ts +12 -2
- package/dist/theme-lab/index.d.ts.map +1 -1
- package/dist/theme-lab/index.js +13 -62
- package/dist/theme-toggle/index.d.ts.map +1 -1
- package/dist/theme-toggle/index.js +3 -2
- package/dist/tokens/derive.d.ts +89 -0
- package/dist/tokens/derive.d.ts.map +1 -0
- package/dist/tokens/derive.js +250 -0
- package/dist/tokens/hct.d.ts +34 -0
- package/dist/tokens/hct.d.ts.map +1 -0
- package/dist/tokens/hct.js +159 -0
- package/dist/tokens/index.d.ts +71 -7
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +284 -46
- package/dist/tokens/palette.d.ts +984 -167
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +617 -119
- package/dist/vite-color-mix.d.ts +30 -0
- package/dist/vite-color-mix.d.ts.map +1 -0
- package/dist/vite-color-mix.js +80 -0
- package/dist/vite.d.ts +82 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +312 -0
- package/llms.txt +5 -4
- package/package.json +24 -9
- package/src/agent/part-list.tsx +13 -7
- package/src/agent/stick-to-bottom.tsx +2 -2
- package/src/agent-chat/thread-detail-panel.tsx +13 -10
- package/src/agent-chat/thread-message.tsx +8 -5
- package/src/agent-chat/thread-outcome-card.tsx +2 -2
- package/src/agent-chat/thread-workspace.tsx +2 -2
- package/src/charts/primitives/ChartLegend.tsx +2 -2
- package/src/charts/primitives/ChartTooltip.tsx +2 -2
- package/src/cli/check-theme.test.ts +18 -0
- package/src/cli/index.ts +112 -20
- package/src/cli/init-sync.test.ts +68 -0
- package/src/connectivity/connectivity-indicator.tsx +8 -2
- package/src/content/article-card.module.css +7 -5
- package/src/content/article-layout.module.css +16 -12
- package/src/content/callout.module.css +4 -4
- package/src/content/code-block.module.css +8 -7
- package/src/content/guide.module.css +3 -3
- package/src/content/mermaid.module.css +2 -2
- package/src/content/prose.module.css +59 -29
- package/src/content/prose.module.css.test.ts +55 -0
- package/src/content/reading-progress.module.css +2 -0
- package/src/content/toc.module.css +6 -3
- package/src/dashboard/delta-badge.tsx +10 -4
- package/src/dashboard/empty-state.tsx +3 -16
- package/src/dashboard/settings-section.module.css +2 -2
- package/src/dashboard/settings-section.tsx +2 -2
- package/src/dashboard/stat-card.tsx +2 -2
- package/src/data/virtual-list.tsx +12 -2
- package/src/forms/FormErrorSummary.tsx +1 -1
- package/src/guard/check-source.test.ts +416 -5
- package/src/guard/index.ts +367 -45
- package/src/guard/types.ts +24 -2
- package/src/index.ts +1 -0
- package/src/provider/index.test.tsx +100 -0
- package/src/provider/index.tsx +79 -7
- package/src/provider/lab-theme.test.ts +147 -0
- package/src/provider/lab-theme.ts +166 -0
- package/src/shell/app-header.module.css +2 -2
- package/src/shell/app-mobile-nav.module.css +1 -1
- package/src/shell/app-sidebar-account.tsx +9 -2
- package/src/shell/app-sidebar.module.css +36 -26
- package/src/shell/app-sidebar.tsx +12 -2
- package/src/shell/index.tsx +14 -3
- package/src/shell/sidebar-search.module.css +16 -4
- package/src/styles.css +1 -1
- package/src/surfaces.ts +25 -11
- package/src/theme/contrast.test.ts +19 -3
- package/src/theme/controls.module.css +1 -1
- package/src/theme/density-option.test.ts +96 -0
- package/src/theme/density-relations.test.ts +428 -0
- package/src/theme/derive-theme.test.ts +101 -0
- package/src/theme/floating.module.css +1 -1
- package/src/theme/fonts-option.test.ts +69 -0
- package/src/theme/index.ts +930 -563
- package/src/theme/nav-link.module.css +1 -1
- package/src/theme/radius-option.test.ts +86 -0
- package/src/theme/radius.test.ts +132 -0
- package/src/theme/spacing.test.ts +432 -0
- package/src/theme/use-basalt-spacing.test.tsx +51 -0
- package/src/theme/use-basalt-spacing.ts +38 -0
- package/src/theme-lab/derive-controls.test.ts +94 -0
- package/src/theme-lab/derive-controls.tsx +227 -0
- package/src/theme-lab/derive-state.test.ts +71 -0
- package/src/theme-lab/derive-state.ts +163 -0
- package/src/theme-lab/index.tsx +29 -68
- package/src/theme-lab/theme-lab.test.ts +4 -18
- package/src/theme-toggle/index.tsx +9 -4
- package/src/tokens/build-fonts-css.test.ts +51 -0
- package/src/tokens/build-radius-css.test.ts +25 -0
- package/src/tokens/density.test.ts +274 -0
- package/src/tokens/derive-radius.test.ts +62 -0
- package/src/tokens/derive.test.ts +30 -0
- package/src/tokens/derive.ts +481 -0
- package/src/tokens/hct.ts +231 -0
- package/src/tokens/index.ts +395 -45
- package/src/tokens/palette.test.ts +114 -0
- package/src/tokens/palette.ts +1118 -180
- package/src/vite-color-mix.test.ts +46 -0
- package/src/vite-color-mix.ts +137 -0
- package/src/vite.test.ts +192 -0
- package/src/vite.ts +502 -1
package/src/tokens/index.ts
CHANGED
|
@@ -9,7 +9,17 @@
|
|
|
9
9
|
* Grounded in argo `packages/charts/src/{tokens,palette,theme-vars,utils/color}.ts`.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
buildPaletteData,
|
|
14
|
+
RADIUS,
|
|
15
|
+
RADIUS_STEP,
|
|
16
|
+
ROW_LINE_HEIGHT,
|
|
17
|
+
SHADOW,
|
|
18
|
+
SPACE,
|
|
19
|
+
SPACE_SCALE,
|
|
20
|
+
SPACE_STEP,
|
|
21
|
+
} from './palette'
|
|
22
|
+
import type { PaletteData, RadiusValues, SpaceValues } from './palette'
|
|
13
23
|
|
|
14
24
|
// The raw hue families + pair-picker — the building blocks a consumer's series module composes
|
|
15
25
|
// (`hrv: p(BP.blue)`). The doctrine sends every consumer here, so they are public surface, not
|
|
@@ -17,6 +27,29 @@ import { ACCENT, FILL, INK, NEUTRAL, SEMANTIC, SHADOW, STATUS, SURFACE } from '.
|
|
|
17
27
|
// pinned by scripts/export-surface.json).
|
|
18
28
|
export { BP, p } from './palette'
|
|
19
29
|
|
|
30
|
+
// The six-knob derive engine — the generator behind the shipped default palette. Exposed so a
|
|
31
|
+
// consumer can retune the palette identity via `createBasaltTheme(overrides, { derive })` (see
|
|
32
|
+
// `../theme`) without hand-picking hexes. `buildPaletteData`/`PaletteData` stay internal (not
|
|
33
|
+
// re-exported here) — a consumer reaches a derived palette through `createBasaltTheme`, not by
|
|
34
|
+
// building `--vx-*` CSS for a custom config directly.
|
|
35
|
+
export { DEFAULT_DERIVE_CONFIG, deriveTokens, resolveDeriveConfig } from './derive'
|
|
36
|
+
export type { DeriveConfig, DerivedPalette } from './derive'
|
|
37
|
+
|
|
38
|
+
// The radius analog of the derive engine — the law behind `createBasaltTheme(overrides, { radius })`
|
|
39
|
+
// (see `../theme`). `RADIUS`/`RADIUS_STEP` stay internal to the theme layer; a consumer retunes the
|
|
40
|
+
// two anchors through `createBasaltTheme`, not by calling `deriveRadius` directly (it is exposed for
|
|
41
|
+
// the law itself to be inspectable/testable, same rationale as `deriveTokens`).
|
|
42
|
+
export { deriveRadius } from './palette'
|
|
43
|
+
export type { RadiusValues } from './palette'
|
|
44
|
+
|
|
45
|
+
// The density analog of the derive engine — the law behind `createBasaltTheme(overrides, {
|
|
46
|
+
// density })` (see `../theme`). `SPACE`/`SPACE_SCALE`/`SPACE_STEP`/`ROW_LINE_HEIGHT` stay internal
|
|
47
|
+
// to the theme layer; a consumer retunes them through `createBasaltTheme`, not by calling
|
|
48
|
+
// `deriveSpacing` directly (it is exposed for the law itself to be inspectable/testable, same
|
|
49
|
+
// rationale as `deriveRadius`).
|
|
50
|
+
export { deriveSpacing } from './palette'
|
|
51
|
+
export type { SpaceValues } from './palette'
|
|
52
|
+
|
|
20
53
|
/** A per-theme color pair: a hue keeps its identity but shifts shade across schemes. */
|
|
21
54
|
export type ColorPair = { light: string; dark: string }
|
|
22
55
|
|
|
@@ -71,14 +104,23 @@ const TEXT = {
|
|
|
71
104
|
|
|
72
105
|
export const VX = {
|
|
73
106
|
// Non-color sizing constants
|
|
107
|
+
// Stroke WEIGHTS, not spacing — deliberately fixed, never density-tracking (see
|
|
108
|
+
// `SPACE_STEP_BASE`'s "charts" group doc in tokens/palette.ts).
|
|
74
109
|
lineWidth: 2.5,
|
|
75
110
|
line2Width: 2,
|
|
76
111
|
axisFont: TEXT.micro,
|
|
77
|
-
|
|
112
|
+
// A discrete visual footprint (not a stroke weight), so — unlike `lineWidth`/`line2Width` above —
|
|
113
|
+
// it DOES track density; single-sourced from `SPACE_STEP.chartDotR` (see that constant's doc).
|
|
114
|
+
dotR: SPACE_STEP.chartDotR,
|
|
78
115
|
// The ONE dashed pattern — plotted stroke, legend swatch, tooltip swatch all read this.
|
|
79
116
|
dashArray: '6 4' as const,
|
|
80
|
-
// Legend layout —
|
|
81
|
-
|
|
117
|
+
// Legend layout — single-sourced from `SPACE_STEP.chartLegendGap` (density-tracking; see that
|
|
118
|
+
// constant's doc). Still a raw number here (not `var()`) — ChartLegend applies it via inline
|
|
119
|
+
// `style`, and this is the one static (level-0) value; `createBasaltTheme({ density })` has no
|
|
120
|
+
// wiring into chart render props yet, so this number does NOT move live with the knob (same
|
|
121
|
+
// "dev slider/production JS defaultProps" gap as Timeline's `bulletSize` — see `deriveSpacing`'s
|
|
122
|
+
// doc in tokens/palette.ts).
|
|
123
|
+
legendGap: SPACE_STEP.chartLegendGap,
|
|
82
124
|
legendFontSize: TEXT.sm,
|
|
83
125
|
|
|
84
126
|
// The type scale (px numbers — see TEXT above). Use in inline styles and visx SVG props;
|
|
@@ -90,6 +132,9 @@ export const VX = {
|
|
|
90
132
|
radiusCard: 'var(--vx-radius-card)',
|
|
91
133
|
// Single source for the control corner radius (inputs, search, buttons, segmented track).
|
|
92
134
|
radiusCtrl: 'var(--vx-radius-ctrl)',
|
|
135
|
+
// Fully-rounded pill affordance (scroll-to-bottom button, chips) — fixed, does not track the
|
|
136
|
+
// radius knob (see `RADIUS_STEP.pill`'s doc in `tokens/palette.ts`).
|
|
137
|
+
radiusPill: 'var(--vx-radius-pill)',
|
|
93
138
|
|
|
94
139
|
// Secondary-line color (back-compat alias; now theme-aware via --vx-line2)
|
|
95
140
|
line2Dark: 'var(--vx-line2)',
|
|
@@ -182,8 +227,14 @@ export const VX = {
|
|
|
182
227
|
neutral: 'var(--vx-status-neutral)',
|
|
183
228
|
},
|
|
184
229
|
|
|
185
|
-
// Shared sizing
|
|
186
|
-
|
|
230
|
+
// Shared sizing — single-sourced from `SPACE_STEP.chartMargin*` (density-tracking; same
|
|
231
|
+
// static-value/no-live-wiring note as `legendGap` above).
|
|
232
|
+
margin: {
|
|
233
|
+
top: SPACE_STEP.chartMarginTop,
|
|
234
|
+
right: SPACE_STEP.chartMarginRight,
|
|
235
|
+
bottom: SPACE_STEP.chartMarginBottom,
|
|
236
|
+
left: SPACE_STEP.chartMarginLeft,
|
|
237
|
+
},
|
|
187
238
|
minPxPerTick: 55,
|
|
188
239
|
} as const
|
|
189
240
|
|
|
@@ -192,6 +243,19 @@ type Side = 'light' | 'dark'
|
|
|
192
243
|
/** A CSS declaration line for a single `--vx-*` custom property. */
|
|
193
244
|
const decl = (name: string, value: string): string => ` --vx-${name}: ${value};`
|
|
194
245
|
|
|
246
|
+
/**
|
|
247
|
+
* A px number expressed as the plain rem STRING literal (16px base: `pxRem(6)` → `'0.375rem'`) —
|
|
248
|
+
* NOT Mantine's own `rem()` helper, which instead emits a `calc(...)` expression bound to
|
|
249
|
+
* `--mantine-scale` (a different value; that scaling happens at the Mantine-coupled call site
|
|
250
|
+
* instead — see `theme/index.ts`'s `Input.extend` `vars` for why `--vx-space-input-height` needs
|
|
251
|
+
* both halves). The SINGLE source for this conversion — `theme/index.ts` imports this instead of
|
|
252
|
+
* keeping its own copy, so the radius/spacing size-scale steps and this module's own rem-emitting
|
|
253
|
+
* vars (`--vx-space-input-height`) can never compute the conversion two different ways.
|
|
254
|
+
*/
|
|
255
|
+
export function pxRem(px: number): string {
|
|
256
|
+
return `${px / 16}rem`
|
|
257
|
+
}
|
|
258
|
+
|
|
195
259
|
/** Emit one prefixed group of pairs for a given scheme side. */
|
|
196
260
|
const groupSide = (prefix: string, map: SeriesMap, side: Side): string =>
|
|
197
261
|
Object.entries(map)
|
|
@@ -203,14 +267,14 @@ const groupSide = (prefix: string, map: SeriesMap, side: Side): string =>
|
|
|
203
267
|
* neutral line/axis/grid/tooltip chrome, legend text, and the surface ramp. Domain series
|
|
204
268
|
* (SERIES/ACTIVITY/USAGE) are NOT shipped — apps append them via `opts.groups`.
|
|
205
269
|
*/
|
|
206
|
-
function frameworkPrimitives(side: Side): string {
|
|
207
|
-
const n = NEUTRAL
|
|
208
|
-
const s = SEMANTIC
|
|
209
|
-
const su = SURFACE
|
|
210
|
-
const ink = INK
|
|
211
|
-
const ac = ACCENT
|
|
270
|
+
function frameworkPrimitives(side: Side, data: PaletteData): string {
|
|
271
|
+
const n = data.NEUTRAL
|
|
272
|
+
const s = data.SEMANTIC
|
|
273
|
+
const su = data.SURFACE
|
|
274
|
+
const ink = data.INK
|
|
275
|
+
const ac = data.ACCENT
|
|
212
276
|
return [
|
|
213
|
-
groupSide('status-', STATUS as SeriesMap, side),
|
|
277
|
+
groupSide('status-', data.STATUS as SeriesMap, side),
|
|
214
278
|
decl('goodSolid', s.good[side]),
|
|
215
279
|
decl('badSolid', s.bad[side]),
|
|
216
280
|
decl('warnSolid', s.warn[side]),
|
|
@@ -227,7 +291,7 @@ function frameworkPrimitives(side: Side): string {
|
|
|
227
291
|
decl('tooltipMuted', n.tooltipMuted[side]),
|
|
228
292
|
decl('tooltipBorder', n.tooltipBorder[side]),
|
|
229
293
|
decl('tooltipShadow', n.tooltipShadow[side]),
|
|
230
|
-
decl('legendText', side
|
|
294
|
+
decl('legendText', n.legendText[side]),
|
|
231
295
|
decl('ink', ink.ink[side]),
|
|
232
296
|
decl('ink2', ink.ink2[side]),
|
|
233
297
|
decl('muted', ink.muted[side]),
|
|
@@ -253,40 +317,235 @@ function frameworkPrimitives(side: Side): string {
|
|
|
253
317
|
].join('\n')
|
|
254
318
|
}
|
|
255
319
|
|
|
320
|
+
/**
|
|
321
|
+
* The `--vx-space-*` declaration list for a resolved {@link SpaceValues} — every anchor and one-off
|
|
322
|
+
* that has at least one real `var()` consumer, plus the row line-height. Shared by
|
|
323
|
+
* `frameworkDerived` (emits the shipped defaults unconditionally, called with `DEFAULT_SPACE_
|
|
324
|
+
* VALUES`) and {@link buildDensityCss} (emits an OVERRIDING block for a retuned density level), so
|
|
325
|
+
* the two lists can never drift apart — mirrors `frameworkDerived`'s own single-source reasoning for
|
|
326
|
+
* the radii.
|
|
327
|
+
*
|
|
328
|
+
* `SPACE_FIXED` (Timeline `lineWidth`, 1px borders, the ReadingProgress bar height, SegmentedControl's
|
|
329
|
+
* `segmentedTrackInset`) is deliberately NEVER part of this list — it never moves, so a var would
|
|
330
|
+
* only invite someone to think it does.
|
|
331
|
+
*
|
|
332
|
+
* Deliberately DOES NOT emit a var for every `SpaceValues` number — `space.scale.*` (the generic
|
|
333
|
+
* Mantine spacing scale) and fourteen `space.step.*` keys have ZERO `var()` consumers anywhere in
|
|
334
|
+
* the framework or its tests beyond the CSS-emission test itself. Each is read straight off the
|
|
335
|
+
* resolved `SpaceValues` as a JS NUMBER instead, in one of three ways:
|
|
336
|
+
* `{timelineBullet,progressBarSize}` are Mantine `defaultProps` (`theme/index.ts`'s Timeline/
|
|
337
|
+
* Progress); `{sidebarAccountMenuWidth,sidebarSettingsMenuWidth,appShellHeaderHeight,
|
|
338
|
+
* appShellHeaderMobileHeight,appShellNavbarWidth,appShellNavbarRailWidth}` are numeric Mantine
|
|
339
|
+
* component props (Menu `width`, AppShell `header`/`navbar`); and `{chartLegendGap,chartMarginTop,
|
|
340
|
+
* chartMarginRight,chartMarginBottom,chartMarginLeft,chartDotR}` are visx SVG props via
|
|
341
|
+
* `VX.legendGap`/`VX.margin`/`VX.dotR` in this file's own `VX` object. The full list is locked
|
|
342
|
+
* against the `SpaceValues` key set by `tokens/density.test.ts`'s declaration-set test, so adding a
|
|
343
|
+
* one-off silently omits nothing. A `--vx-space-*` declaration for any of them would be dead weight
|
|
344
|
+
* that only looked like the fix for
|
|
345
|
+
* the dev-slider/production gap those JS reads actually have (see `deriveSpacing`'s JSDoc in
|
|
346
|
+
* `tokens/palette.ts` for the real scope of that gap — it is materially bigger than "a var these
|
|
347
|
+
* numbers could round-trip through"). `theme.spacing` (the generic scale, JS) already resolves
|
|
348
|
+
* through `--mantine-spacing-*` on the PRODUCTION `createBasaltTheme({ density })` path
|
|
349
|
+
* (`theme/index.ts`'s `buildTheme`), so nothing downstream of the generic scale actually needed
|
|
350
|
+
* `--vx-space-scale-*` either — deleted along with the rest rather than kept as an unread alias.
|
|
351
|
+
*/
|
|
352
|
+
function spaceDecls(space: SpaceValues): string[] {
|
|
353
|
+
return [
|
|
354
|
+
decl('space-row-inset-x', `${space.anchors.rowInsetX}px`),
|
|
355
|
+
decl('space-row-inset-y', `${space.anchors.rowInsetY}px`),
|
|
356
|
+
// Additive law, not the multiplier — see `deriveSpacing`'s doc in `tokens/palette.ts`. No unit:
|
|
357
|
+
// `line-height` is a unitless CSS value.
|
|
358
|
+
decl('space-row-line-height', `${space.rowLineHeight}`),
|
|
359
|
+
// A `size: 'md'` Input's resolved height. Mantine's own `--input-height-md` is
|
|
360
|
+
// `calc(2.625rem * var(--mantine-scale))` (BOTH `styles.css` and `styles.layer.css`, verified
|
|
361
|
+
// in the installed package) — REM-relative to the root font size AND scale-aware, not a flat
|
|
362
|
+
// px. Emitting this in REM (via `pxRem`, not a bare `${…}px`) preserves the rem half; the
|
|
363
|
+
// `* var(--mantine-scale))` half is reconstructed at the Mantine-coupled call site
|
|
364
|
+
// (`theme/index.ts`'s `Input.extend` `vars`, which wraps this var in the matching `calc(...)`)
|
|
365
|
+
// — this module stays Mantine-free, so it cannot reference `--mantine-scale` itself. Flattening
|
|
366
|
+
// either half into a flat px would desync input height from the user's root font size (an
|
|
367
|
+
// accessibility regression) and from Mantine's global `--mantine-scale` knob.
|
|
368
|
+
decl('space-input-height', pxRem(space.anchors.inputHeight)),
|
|
369
|
+
// A `size: 'md'` Button's/ActionIcon's resolved height — SAME rem-plus-scale reasoning and
|
|
370
|
+
// reconstruction as `space-input-height` above (`theme/index.ts`'s `Button.extend`/
|
|
371
|
+
// `ActionIcon.extend` `vars`), single-sourced from the SAME `controlHeight` anchor
|
|
372
|
+
// `space-input-height` reads from (`SPACE_ANCHORS_BASE`'s doc in `tokens/palette.ts`).
|
|
373
|
+
decl('space-control-height', pxRem(space.anchors.controlHeight)),
|
|
374
|
+
decl('space-stack-xs', `${space.anchors.stackXs}px`),
|
|
375
|
+
decl('space-stack-sm', `${space.anchors.stackSm}px`),
|
|
376
|
+
decl('space-stack-md', `${space.anchors.stackMd}px`),
|
|
377
|
+
decl('space-stack-lg', `${space.anchors.stackLg}px`),
|
|
378
|
+
decl('space-stack-xl', `${space.anchors.stackXl}px`),
|
|
379
|
+
// The CSS-module spacing sweep's one-offs (docs/STATUS.md) — same single-source reasoning,
|
|
380
|
+
// grouped to match `SPACE_STEP_BASE`'s own grouping in tokens/palette.ts.
|
|
381
|
+
// Responsive pair (Decision 3) — `stickyHeaderClearance` is the desktop (`>= sm`) value,
|
|
382
|
+
// `stickyHeaderClearanceMobile` the mobile (`< sm`) override; a consumer CSS module picks
|
|
383
|
+
// whichever matches its own breakpoint (see `content/prose.module.css`).
|
|
384
|
+
decl('space-sticky-header-clearance', `${space.step.stickyHeaderClearance}px`),
|
|
385
|
+
decl('space-sticky-header-clearance-mobile', `${space.step.stickyHeaderClearanceMobile}px`),
|
|
386
|
+
decl('space-nav-icon-gap', `${space.step.navIconGap}px`),
|
|
387
|
+
decl('space-sidebar-region-gap', `${space.step.sidebarRegionGap}px`),
|
|
388
|
+
decl('space-prose-quote-inset-y', `${space.step.proseQuoteInsetY}px`),
|
|
389
|
+
decl('space-prose-quote-indent', `${space.step.proseQuoteIndent}px`),
|
|
390
|
+
decl('space-prose-inline-code-inset-y', `${space.step.proseInlineCodeInsetY}px`),
|
|
391
|
+
decl('space-prose-inline-code-inset-x', `${space.step.proseInlineCodeInsetX}px`),
|
|
392
|
+
decl('space-prose-code-block-inset-y', `${space.step.proseCodeBlockInsetY}px`),
|
|
393
|
+
decl('space-prose-code-block-inset-x', `${space.step.proseCodeBlockInsetX}px`),
|
|
394
|
+
decl('space-prose-heading-anchor-gap', `${space.step.proseHeadingAnchorGap}px`),
|
|
395
|
+
decl('space-prose-table-cell-inset-y', `${space.step.proseTableCellInsetY}px`),
|
|
396
|
+
decl('space-prose-table-cell-inset-x', `${space.step.proseTableCellInsetX}px`),
|
|
397
|
+
decl('space-prose-chat-list-gap-bottom', `${space.step.proseChatListGapBottom}px`),
|
|
398
|
+
decl('space-prose-chat-list-indent', `${space.step.proseChatListIndent}px`),
|
|
399
|
+
decl('space-prose-chat-list-item-gap', `${space.step.proseChatListItemGap}px`),
|
|
400
|
+
decl('space-prose-chat-nested-list-gap', `${space.step.proseChatNestedListGap}px`),
|
|
401
|
+
decl('space-prose-chat-heading-gap-top', `${space.step.proseChatHeadingGapTop}px`),
|
|
402
|
+
decl('space-prose-chat-heading-gap-bottom', `${space.step.proseChatHeadingGapBottom}px`),
|
|
403
|
+
decl('space-prose-article-paragraph-gap', `${space.step.proseArticleParagraphGap}px`),
|
|
404
|
+
decl('space-prose-article-list-gap-top', `${space.step.proseArticleListGapTop}px`),
|
|
405
|
+
decl('space-prose-article-list-gap-bottom', `${space.step.proseArticleListGapBottom}px`),
|
|
406
|
+
decl('space-prose-article-list-indent', `${space.step.proseArticleListIndent}px`),
|
|
407
|
+
decl('space-prose-article-h1-gap-top', `${space.step.proseArticleH1GapTop}px`),
|
|
408
|
+
decl('space-prose-article-h1-gap-bottom', `${space.step.proseArticleH1GapBottom}px`),
|
|
409
|
+
decl('space-prose-article-heading-gap-top', `${space.step.proseArticleHeadingGapTop}px`),
|
|
410
|
+
decl('space-prose-article-heading-gap-bottom', `${space.step.proseArticleHeadingGapBottom}px`),
|
|
411
|
+
decl('space-prose-article-h2-rule-gap', `${space.step.proseArticleH2RuleGap}px`),
|
|
412
|
+
decl('space-prose-article-block-gap', `${space.step.proseArticleBlockGap}px`),
|
|
413
|
+
decl('space-article-column-gap', `${space.step.articleColumnGap}px`),
|
|
414
|
+
decl('space-article-toc-rail-width', `${space.step.articleTocRailWidth}px`),
|
|
415
|
+
decl('space-article-header-gap', `${space.step.articleHeaderGap}px`),
|
|
416
|
+
decl('space-article-header-padding-bottom', `${space.step.articleHeaderPaddingBottom}px`),
|
|
417
|
+
decl('space-article-header-margin-bottom', `${space.step.articleHeaderMarginBottom}px`),
|
|
418
|
+
decl('space-article-meta-row-gap', `${space.step.articleMetaRowGap}px`),
|
|
419
|
+
decl('space-article-footer-gap', `${space.step.articleFooterGap}px`),
|
|
420
|
+
decl('space-article-footer-margin-top', `${space.step.articleFooterMarginTop}px`),
|
|
421
|
+
decl('space-article-footer-padding-top', `${space.step.articleFooterPaddingTop}px`),
|
|
422
|
+
decl('space-article-nav-target-gap', `${space.step.articleNavTargetGap}px`),
|
|
423
|
+
decl('space-code-block-header-gap', `${space.step.codeBlockHeaderGap}px`),
|
|
424
|
+
decl('space-code-block-header-inset-y', `${space.step.codeBlockHeaderInsetY}px`),
|
|
425
|
+
decl('space-code-block-header-inset-right', `${space.step.codeBlockHeaderInsetRight}px`),
|
|
426
|
+
decl('space-code-block-content-inset-x', `${space.step.codeBlockContentInsetX}px`),
|
|
427
|
+
decl('space-code-block-header-right-gap', `${space.step.codeBlockHeaderRightGap}px`),
|
|
428
|
+
decl('space-code-block-body-inset-y', `${space.step.codeBlockBodyInsetY}px`),
|
|
429
|
+
decl('space-code-block-floating-copy-offset', `${space.step.codeBlockFloatingCopyOffset}px`),
|
|
430
|
+
decl('space-callout-inset-y', `${space.step.calloutInsetY}px`),
|
|
431
|
+
decl('space-callout-inset-x', `${space.step.calloutInsetX}px`),
|
|
432
|
+
decl('space-callout-title-row-gap', `${space.step.calloutTitleRowGap}px`),
|
|
433
|
+
decl('space-toc-root-gap', `${space.step.tocRootGap}px`),
|
|
434
|
+
decl('space-toc-link-inset-y', `${space.step.tocLinkInsetY}px`),
|
|
435
|
+
decl('space-toc-link-indent', `${space.step.tocLinkIndent}px`),
|
|
436
|
+
decl('space-toc-sub-indent', `${space.step.tocSubIndent}px`),
|
|
437
|
+
decl('space-article-card-tags-gap', `${space.step.articleCardTagsGap}px`),
|
|
438
|
+
decl('space-article-card-tag-inset-y', `${space.step.articleCardTagInsetY}px`),
|
|
439
|
+
decl('space-article-card-tag-inset-x', `${space.step.articleCardTagInsetX}px`),
|
|
440
|
+
decl('space-article-card-meta-gap-top', `${space.step.articleCardMetaGapTop}px`),
|
|
441
|
+
decl('space-guide-body-gap-bottom', `${space.step.guideBodyGapBottom}px`),
|
|
442
|
+
decl('space-guide-footer-gap-top', `${space.step.guideFooterGapTop}px`),
|
|
443
|
+
decl('space-guide-footer-inset-top', `${space.step.guideFooterInsetTop}px`),
|
|
444
|
+
decl('space-sidebar-search-gap', `${space.step.sidebarSearchGap}px`),
|
|
445
|
+
decl('space-sidebar-search-trigger-height', `${space.step.sidebarSearchTriggerHeight}px`),
|
|
446
|
+
decl('space-settings-row-inset-y', `${space.step.settingsRowInsetY}px`),
|
|
447
|
+
decl('space-settings-row-gap', `${space.step.settingsRowGap}px`),
|
|
448
|
+
decl('space-mermaid-container-inset', `${space.step.mermaidContainerInset}px`),
|
|
449
|
+
decl('space-sidebar-brand-inset-top', `${space.step.sidebarBrandInsetTop}px`),
|
|
450
|
+
decl('space-sidebar-brand-inset-x', `${space.step.sidebarBrandInsetX}px`),
|
|
451
|
+
decl('space-sidebar-section-gap', `${space.step.sidebarSectionGap}px`),
|
|
452
|
+
decl('space-sidebar-account-inset-top', `${space.step.sidebarAccountInsetTop}px`),
|
|
453
|
+
decl('space-sidebar-account-inset-x', `${space.step.sidebarAccountInsetX}px`),
|
|
454
|
+
decl('space-sidebar-account-inset-bottom', `${space.step.sidebarAccountInsetBottom}px`),
|
|
455
|
+
decl('space-sidebar-avatar-size', `${space.step.sidebarAvatarSize}px`),
|
|
456
|
+
decl('space-sidebar-section-label-gap', `${space.step.sidebarSectionLabelGap}px`),
|
|
457
|
+
decl('space-sidebar-child-list-gap-top', `${space.step.sidebarChildListGapTop}px`),
|
|
458
|
+
decl('space-sidebar-child-list-gap-bottom', `${space.step.sidebarChildListGapBottom}px`),
|
|
459
|
+
decl('space-sidebar-child-list-indent', `${space.step.sidebarChildListIndent}px`),
|
|
460
|
+
decl('space-sidebar-child-row-inset-y', `${space.step.sidebarChildRowInsetY}px`),
|
|
461
|
+
decl('space-sidebar-child-row-indent', `${space.step.sidebarChildRowIndent}px`),
|
|
462
|
+
decl('space-app-header-mobile-actions-height', `${space.step.appHeaderMobileActionsHeight}px`),
|
|
463
|
+
decl('space-mobile-nav-tab-gap', `${space.step.mobileNavTabGap}px`),
|
|
464
|
+
decl('space-agent-rail-inset-x', `${space.step.agentRailInsetX}px`),
|
|
465
|
+
decl('space-agent-part-gap-top', `${space.step.agentPartGapTop}px`),
|
|
466
|
+
decl('space-agent-code-inset', `${space.step.agentCodeInset}px`),
|
|
467
|
+
decl('space-agent-error-inset-y', `${space.step.agentErrorInsetY}px`),
|
|
468
|
+
decl('space-agent-error-inset-x', `${space.step.agentErrorInsetX}px`),
|
|
469
|
+
decl('space-agent-scroll-button-gap-top', `${space.step.agentScrollButtonGapTop}px`),
|
|
470
|
+
decl('space-agent-message-inset-y', `${space.step.agentMessageInsetY}px`),
|
|
471
|
+
decl('space-agent-message-inset-x', `${space.step.agentMessageInsetX}px`),
|
|
472
|
+
decl('space-agent-transcript-inset', `${space.step.agentTranscriptInset}px`),
|
|
473
|
+
decl('space-badge-inset-y', `${space.step.badgeInsetY}px`),
|
|
474
|
+
decl('space-badge-inset-x', `${space.step.badgeInsetX}px`),
|
|
475
|
+
decl('space-stat-card-gap', `${space.step.statCardGap}px`),
|
|
476
|
+
decl('space-virtual-row-inset-y', `${space.step.virtualRowInsetY}px`),
|
|
477
|
+
decl('space-virtual-row-inset-x', `${space.step.virtualRowInsetX}px`),
|
|
478
|
+
// `chartLegendGap`/`chartMarginTop`/`chartMarginRight`/`chartMarginBottom`/`chartMarginLeft`/
|
|
479
|
+
// `chartDotR`/`progressBarSize`/`timelineBullet` are DELIBERATELY absent — see this function's
|
|
480
|
+
// doc for why (JS-number-only consumers, zero `var()` reads). `appShellHeaderHeight`/
|
|
481
|
+
// `appShellHeaderMobileHeight`/`appShellNavbarWidth`/`appShellNavbarRailWidth` join that list —
|
|
482
|
+
// `shell/index.tsx` reads all four as JS numbers via `useBasaltSpacing()` (Mantine's `AppShell`
|
|
483
|
+
// `header`/`navbar` props take numbers, not `var()` strings), so a `--vx-space-app-shell-*` decl
|
|
484
|
+
// here would have had zero consumers, framework-wide, the same dead-weight shape this function's
|
|
485
|
+
// doc already calls out for the chart/Progress/Timeline group. `sidebarAccountMenuWidth`/
|
|
486
|
+
// `sidebarSettingsMenuWidth` join it too — `app-sidebar-account.tsx`/`app-sidebar.tsx` read both
|
|
487
|
+
// as JS numbers via `useBasaltSpacing()` (Mantine's `<Menu width={…}>` also takes a number).
|
|
488
|
+
]
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** The shipped, level-0 spacing values — `frameworkDerived`'s `spaceDecls(...)` call below. No
|
|
492
|
+
* `createBasaltTheme({ density })` retuning applies here; that path calls `buildDensityCss` with a
|
|
493
|
+
* different resolved {@link SpaceValues} instead (see `../theme` and `../provider`). */
|
|
494
|
+
const DEFAULT_SPACE_VALUES: SpaceValues = {
|
|
495
|
+
anchors: SPACE,
|
|
496
|
+
scale: SPACE_SCALE,
|
|
497
|
+
step: SPACE_STEP,
|
|
498
|
+
rowLineHeight: ROW_LINE_HEIGHT,
|
|
499
|
+
}
|
|
500
|
+
|
|
256
501
|
/**
|
|
257
502
|
* Theme-independent scalars + semantic fills, defined once on `:root`.
|
|
258
503
|
*
|
|
259
504
|
* Area-gradient strength is a global knob (the theme lab overrides these two on `:root`
|
|
260
505
|
* to retune every line-area fill live). 0%/0% disables gradients app-wide.
|
|
261
506
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
507
|
+
function frameworkDerived(data: PaletteData): string {
|
|
508
|
+
return [
|
|
509
|
+
decl('radius-card', `${RADIUS.card}px`),
|
|
510
|
+
decl('radius-ctrl', `${RADIUS.ctrl}px`),
|
|
511
|
+
// The two offset tiers (SegmentedControl indicator/Kbd/Code, Progress/scale-sm) — added so a
|
|
512
|
+
// component's inline `styles`/`style` can read the SAME source as `RADIUS_STEP.tight`/`.fine`
|
|
513
|
+
// instead of a hand-typed literal (see `theme/index.ts`'s component sweep).
|
|
514
|
+
decl('radius-tight', `${RADIUS_STEP.tight}px`),
|
|
515
|
+
decl('radius-fine', `${RADIUS_STEP.fine}px`),
|
|
516
|
+
// The floating tier (Modal/Tooltip/Popover/Notification, content code/mermaid blocks).
|
|
517
|
+
decl('radius-floating', `${RADIUS_STEP.floating}px`),
|
|
518
|
+
// The pill affordance (scroll-to-bottom button, chips) — fixed, level-invariant, so it lives
|
|
519
|
+
// only in this static block, never in `buildRadiusCss`'s dynamic override (see
|
|
520
|
+
// `RADIUS_STEP.pill`'s doc).
|
|
521
|
+
decl('radius-pill', `${RADIUS_STEP.pill}px`),
|
|
522
|
+
...spaceDecls(DEFAULT_SPACE_VALUES),
|
|
523
|
+
// Article-density Prose measure (docs/CONTENT-SPEC.md §5) — theme-independent, like the radii.
|
|
524
|
+
decl('prose-measure', '72ch'),
|
|
525
|
+
// The fill band (see FILL in palette.ts). Emitted on `:root`, NOT per scheme — a filled surface
|
|
526
|
+
// is the same hex in both, which is the whole point: it is squeezed between its white label and
|
|
527
|
+
// the page behind it, and only one luminance band satisfies both on both pages.
|
|
528
|
+
...Object.entries(data.FILL).map(([name, hex]) => decl(`fill-${name}`, hex)),
|
|
529
|
+
// Hover is DERIVED from the fill, so retuning a fill (in the theme lab, or here) carries its
|
|
530
|
+
// hover along instead of leaving a stale pair. 88% of the fill over black lands ~0.128 luminance:
|
|
531
|
+
// a visible press-darkening that still clears AA for the white label (~5.9:1).
|
|
532
|
+
...Object.keys(data.FILL).map((name) =>
|
|
533
|
+
decl(`fillHover-${name}`, `color-mix(in srgb, var(--vx-fill-${name}) 88%, #000)`),
|
|
534
|
+
),
|
|
535
|
+
// The type scale, emitted from the SAME `TEXT` object `VX.text` reads — CSS modules and the
|
|
536
|
+
// Mantine theme consume these; inline styles / visx read the numbers. One ladder, two forms.
|
|
537
|
+
...Object.entries(TEXT).map(([step, px]) => decl(`text-${step}`, `${px}px`)),
|
|
538
|
+
decl('area-top', '22%'),
|
|
539
|
+
decl('area-bottom', '1%'),
|
|
540
|
+
decl('good', 'color-mix(in srgb, var(--vx-goodSolid) 18%, transparent)'),
|
|
541
|
+
decl('goodSoft', 'color-mix(in srgb, var(--vx-goodSolid) 8%, transparent)'),
|
|
542
|
+
decl('bad', 'color-mix(in srgb, var(--vx-badSolid) 18%, transparent)'),
|
|
543
|
+
decl('warn', 'color-mix(in srgb, var(--vx-warnSolid) 8%, transparent)'),
|
|
544
|
+
decl('goodRef', 'color-mix(in srgb, var(--vx-goodSolid) 30%, transparent)'),
|
|
545
|
+
decl('badRef', 'color-mix(in srgb, var(--vx-badSolid) 30%, transparent)'),
|
|
546
|
+
decl('warnRef', 'color-mix(in srgb, var(--vx-warnSolid) 20%, transparent)'),
|
|
547
|
+
].join('\n')
|
|
548
|
+
}
|
|
290
549
|
|
|
291
550
|
/**
|
|
292
551
|
* Wrap a map of `{ name: ColorPair }` into `var(--vx-<prefix><name>)` token refs — the runtime
|
|
@@ -342,18 +601,27 @@ export type BuildPaletteOpts = {
|
|
|
342
601
|
* built in, so an empty `buildPaletteCss()` already emits every framework var. Consumer
|
|
343
602
|
* `opts.groups` / `opts.derived` append on top (e.g. argo's domain SERIES/ACTIVITY/USAGE).
|
|
344
603
|
*
|
|
604
|
+
* `data` defaults to the static, shipped palette (`buildPaletteData()` at `DEFAULT_DERIVE_CONFIG`)
|
|
605
|
+
* — pass the result of `buildPaletteData(config)` to emit CSS for a retuned derive config instead
|
|
606
|
+
* (this is how `BasaltProvider` follows `createBasaltTheme`'s `{ derive }` option; see `../theme`
|
|
607
|
+
* and `../provider`).
|
|
608
|
+
*
|
|
345
609
|
* Dark is the default (`:root`) since the framework defaults to dark; the
|
|
346
610
|
* `[data-mantine-color-scheme]` selectors track Mantine's toggle on `<html>`.
|
|
347
611
|
*/
|
|
348
|
-
export function buildPaletteCss(
|
|
612
|
+
export function buildPaletteCss(
|
|
613
|
+
opts: BuildPaletteOpts = {},
|
|
614
|
+
data: PaletteData = buildPaletteData(),
|
|
615
|
+
): string {
|
|
349
616
|
const groups = opts.groups ?? {}
|
|
350
617
|
const extraDerived = (opts.derived ?? []).map((d) => ` ${d}`).join('\n')
|
|
351
|
-
const
|
|
618
|
+
const derivedBlock = frameworkDerived(data)
|
|
619
|
+
const derived = extraDerived ? `${derivedBlock}\n${extraDerived}` : derivedBlock
|
|
352
620
|
const side = (s: Side): string => {
|
|
353
621
|
const extra = Object.entries(groups)
|
|
354
622
|
.map(([prefix, map]) => groupSide(prefix, map, s))
|
|
355
623
|
.join('\n')
|
|
356
|
-
const framework = frameworkPrimitives(s)
|
|
624
|
+
const framework = frameworkPrimitives(s, data)
|
|
357
625
|
return extra ? `${framework}\n${extra}` : framework
|
|
358
626
|
}
|
|
359
627
|
return `:root {
|
|
@@ -367,3 +635,85 @@ html[data-mantine-color-scheme='light'] {
|
|
|
367
635
|
${side('light')}
|
|
368
636
|
}`
|
|
369
637
|
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* The `fonts` option's resolved shape — a full CSS font-family stack string per slot (with its own
|
|
641
|
+
* fallback chain), riding the `--basalt-font-sans/head/mono` override seam `styles.css` ships
|
|
642
|
+
* fallbacks for. Omitted keys keep the shipped fallback untouched. Lives here (not in `../theme`,
|
|
643
|
+
* which only RE-EXPORTS it) because its builder `buildFontsCss` below is a pure, Mantine-free
|
|
644
|
+
* string builder that belongs in the tokens layer — see `../theme`'s
|
|
645
|
+
* `CreateBasaltThemeOptions.fonts` for the production entry point that sets it.
|
|
646
|
+
*/
|
|
647
|
+
export type BasaltFontsConfig = {
|
|
648
|
+
sans?: string
|
|
649
|
+
head?: string
|
|
650
|
+
mono?: string
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** `{ basaltFonts key → --basalt-font-* var name }` — the one place the mapping is spelled out. */
|
|
654
|
+
const FONT_VAR_NAMES = {
|
|
655
|
+
sans: '--basalt-font-sans',
|
|
656
|
+
head: '--basalt-font-head',
|
|
657
|
+
mono: '--basalt-font-mono',
|
|
658
|
+
} as const satisfies Record<keyof BasaltFontsConfig, string>
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Build the `:root` block of `--basalt-font-*` declarations for a resolved `basaltFonts` config —
|
|
662
|
+
* only for the keys the consumer actually set (`createBasaltTheme(overrides, { fonts })`); an
|
|
663
|
+
* omitted key keeps the shipped `styles.css` fallback chain untouched. Empty string when `fonts` is
|
|
664
|
+
* absent or every key is omitted, so callers can unconditionally concatenate the result. Importable
|
|
665
|
+
* from `basalt-ui/tokens` — `BasaltProvider`'s bridge (`../provider`) calls this directly to append
|
|
666
|
+
* declarations to its injected `<style>`; an SSR/custom-injection consumer with
|
|
667
|
+
* `injectPalette={false}` calls it themselves (see the JSDoc on that prop).
|
|
668
|
+
*/
|
|
669
|
+
export function buildFontsCss(fonts: BasaltFontsConfig | undefined): string {
|
|
670
|
+
if (!fonts) return ''
|
|
671
|
+
const decls = (Object.keys(FONT_VAR_NAMES) as (keyof BasaltFontsConfig)[])
|
|
672
|
+
.filter((key) => fonts[key] !== undefined)
|
|
673
|
+
.map((key) => {
|
|
674
|
+
const value = fonts[key] as string
|
|
675
|
+
// A font stack is a plain declaration value — `{`/`}`/`;`/comment openers would let a
|
|
676
|
+
// config string break out of the emitted `<style>` declaration. Throw, don't sanitize,
|
|
677
|
+
// per the repo's validation convention (see `deriveTokens`'s accent-hex assert).
|
|
678
|
+
if (/[{};]|\/\*/.test(value)) {
|
|
679
|
+
throw new Error(
|
|
680
|
+
`Invalid fonts.${key}: a font-family stack must not contain "{", "}", ";" or "/*" — got ${JSON.stringify(value)}`,
|
|
681
|
+
)
|
|
682
|
+
}
|
|
683
|
+
return ` ${FONT_VAR_NAMES[key]}: ${value};`
|
|
684
|
+
})
|
|
685
|
+
if (decls.length === 0) return ''
|
|
686
|
+
return `:root {\n${decls.join('\n')}\n}`
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Build the `:root` block of overriding `--vx-radius-*` declarations for a resolved
|
|
691
|
+
* `basaltRadius` value (`createBasaltTheme(overrides, { radius })`) — analog of {@link buildFontsCss}.
|
|
692
|
+
* Empty string when `radius` is absent (the default level-0 path never sets `theme.other.basaltRadius`
|
|
693
|
+
* in the first place), so callers can unconditionally concatenate the result. Importable from
|
|
694
|
+
* `basalt-ui/tokens`, same SSR/custom-injection use as `buildFontsCss` above.
|
|
695
|
+
*/
|
|
696
|
+
export function buildRadiusCss(radius: RadiusValues | undefined): string {
|
|
697
|
+
if (!radius) return ''
|
|
698
|
+
return `:root {
|
|
699
|
+
--vx-radius-card: ${radius.card}px;
|
|
700
|
+
--vx-radius-ctrl: ${radius.ctrl}px;
|
|
701
|
+
--vx-radius-tight: ${radius.tight}px;
|
|
702
|
+
--vx-radius-fine: ${radius.fine}px;
|
|
703
|
+
--vx-radius-floating: ${radius.floating}px;
|
|
704
|
+
}`
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Build the `:root` block of overriding `--vx-space-*` declarations for a resolved `basaltDensity`
|
|
709
|
+
* value (`createBasaltTheme(overrides, { density })`) — analog of {@link buildRadiusCss}, reusing
|
|
710
|
+
* the SAME `spaceDecls` list `frameworkDerived` emits the shipped defaults from (so the two can
|
|
711
|
+
* never drift). Empty string when `space` is absent (the default level-0 path never sets
|
|
712
|
+
* `theme.other.basaltDensity` in the first place), so callers can unconditionally concatenate the
|
|
713
|
+
* result. Importable from `basalt-ui/tokens`, same SSR/custom-injection use as `buildRadiusCss`
|
|
714
|
+
* above.
|
|
715
|
+
*/
|
|
716
|
+
export function buildDensityCss(space: SpaceValues | undefined): string {
|
|
717
|
+
if (!space) return ''
|
|
718
|
+
return `:root {\n${spaceDecls(space).join('\n')}\n}`
|
|
719
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildPaletteData` is the pure function `palette.ts`'s static ACCENT/FILL/SURFACE/INK/SEMANTIC/
|
|
3
|
+
* STATUS exports are built from — this locks the two together: the static exports must be exactly
|
|
4
|
+
* `buildPaletteData(DEFAULT_DERIVE_CONFIG)`'s output, not a hand-duplicated snapshot of it.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from 'bun:test'
|
|
7
|
+
import { DEFAULT_DERIVE_CONFIG } from './derive'
|
|
8
|
+
import {
|
|
9
|
+
ACCENT,
|
|
10
|
+
buildPaletteData,
|
|
11
|
+
FILL,
|
|
12
|
+
INK,
|
|
13
|
+
NEUTRAL,
|
|
14
|
+
scaleSpace,
|
|
15
|
+
SEMANTIC,
|
|
16
|
+
STATUS,
|
|
17
|
+
SURFACE,
|
|
18
|
+
} from './palette'
|
|
19
|
+
|
|
20
|
+
describe('buildPaletteData(DEFAULT_DERIVE_CONFIG) deep-equals the static exports', () => {
|
|
21
|
+
const data = buildPaletteData(DEFAULT_DERIVE_CONFIG)
|
|
22
|
+
|
|
23
|
+
test('ACCENT', () => expect(data.ACCENT).toEqual(ACCENT))
|
|
24
|
+
test('FILL', () => expect(data.FILL).toEqual(FILL))
|
|
25
|
+
test('SURFACE', () => expect(data.SURFACE).toEqual(SURFACE))
|
|
26
|
+
test('INK', () => expect(data.INK).toEqual(INK))
|
|
27
|
+
test('NEUTRAL', () => expect(data.NEUTRAL).toEqual(NEUTRAL))
|
|
28
|
+
test('SEMANTIC', () => expect(data.SEMANTIC).toEqual(SEMANTIC))
|
|
29
|
+
test('STATUS', () => expect(data.STATUS).toEqual(STATUS))
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('buildPaletteData() defaults to DEFAULT_DERIVE_CONFIG', () => {
|
|
33
|
+
test('same result as an explicit default config', () => {
|
|
34
|
+
expect(buildPaletteData()).toEqual(buildPaletteData(DEFAULT_DERIVE_CONFIG))
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('buildPaletteData is memoized by config value', () => {
|
|
39
|
+
test('two calls with an equal (but not referentially identical) config return the same object', () => {
|
|
40
|
+
const a = buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: '#123456' })
|
|
41
|
+
const b = buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: '#123456' })
|
|
42
|
+
expect(a).toBe(b)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('a different config produces a different, non-default result', () => {
|
|
46
|
+
const custom = buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: '#16a34a' })
|
|
47
|
+
expect(custom).not.toEqual(buildPaletteData(DEFAULT_DERIVE_CONFIG))
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('buildPaletteData rejects a malformed accent seed', () => {
|
|
52
|
+
test('a non-hex color name throws', () => {
|
|
53
|
+
expect(() => buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: 'red' })).toThrow()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('a truncated hex throws', () => {
|
|
57
|
+
expect(() => buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: '#12' })).toThrow()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('a non-hex-digit hex throws', () => {
|
|
61
|
+
expect(() => buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accent: '#zzzzzz' })).toThrow()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('the default-config entry is pinned against cache eviction', () => {
|
|
66
|
+
test('buildPaletteData(DEFAULT_DERIVE_CONFIG) stays the same reference past the 32-entry cap', () => {
|
|
67
|
+
const before = buildPaletteData(DEFAULT_DERIVE_CONFIG)
|
|
68
|
+
for (let i = 0; i < 40; i++) {
|
|
69
|
+
buildPaletteData({
|
|
70
|
+
...DEFAULT_DERIVE_CONFIG,
|
|
71
|
+
accent: `#${(i + 1).toString(16).padStart(6, '0')}`,
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
const after = buildPaletteData(DEFAULT_DERIVE_CONFIG)
|
|
75
|
+
expect(after).toBe(before)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe('onAccent stays white under the fill-page contrast clamp', () => {
|
|
80
|
+
test('the default config keeps a white onAccent', () => {
|
|
81
|
+
expect(buildPaletteData(DEFAULT_DERIVE_CONFIG).ACCENT.onAccent.light).toBe('#ffffff')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Previously a high accentBrightness pushed the fill tone light enough to fail the white-label
|
|
85
|
+
// floor and flip onAccent to a dark ink. `derive.ts`'s fill-page contrast clamp now caps the fill
|
|
86
|
+
// tone before that point is ever reached (the fill-vs-page floor is always at least as strict as
|
|
87
|
+
// the fill-vs-white floor for a realistic, non-pure-white page background), so onAccent stays
|
|
88
|
+
// white at every accentBrightness level for the shipped seed/surface config.
|
|
89
|
+
test('a high accentBrightness still keeps onAccent white', () => {
|
|
90
|
+
const data = buildPaletteData({ ...DEFAULT_DERIVE_CONFIG, accentBrightness: 5 })
|
|
91
|
+
expect(data.ACCENT.onAccent.light).toBe('#ffffff')
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('scaleSpace floors a base >= 1 at 1, never lets it round down to 0', () => {
|
|
96
|
+
// No shipped base/level combination reaches this branch — `deriveSpacing`'s shallowest
|
|
97
|
+
// multiplier is 0.7 (level -5), and every current base is an integer >= 1, so
|
|
98
|
+
// `round(value * multiplier)` never drops below 1 on that path (see `scaleSpace`'s doc in
|
|
99
|
+
// `palette.ts`). Drive the clamp directly with a multiplier `deriveSpacing` can never produce,
|
|
100
|
+
// to prove the floor still holds if a base or the level range ever changes.
|
|
101
|
+
test('a value of 1 at a multiplier of 0.3 would round to 0 without the floor', () => {
|
|
102
|
+
expect(scaleSpace(1, -5, 0.3)).toBe(1)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('a larger value at a more aggressive multiplier still floors at 1, not its raw round', () => {
|
|
106
|
+
// round(2 * 0.1) = round(0.2) = 0 without the floor — proves the clamp for a value > 1 too,
|
|
107
|
+
// not just the value-of-1 edge case above.
|
|
108
|
+
expect(scaleSpace(2, -5, 0.1)).toBe(1)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('level 0 bypasses scaling (and therefore the floor) entirely, returning value verbatim', () => {
|
|
112
|
+
expect(scaleSpace(0.4, 0, 0.1)).toBe(0.4)
|
|
113
|
+
})
|
|
114
|
+
})
|