basalt-ui 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +46 -0
- package/README.md +64 -8
- package/agent/rules/basalt-app.md +126 -0
- package/agent/rules/basalt-content.md +3 -1
- package/agent/rules/basalt-tokens.md +14 -5
- package/agent/skills/basalt-app/SKILL.md +28 -7
- 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 +29 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +80 -9
- 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 +266 -38
- 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 +22 -11
- package/dist/surfaces.d.ts +21 -11
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +10 -3
- 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 +143 -7
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +322 -48
- 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/tokens.css +248 -0
- 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 +14 -4
- package/package.json +41 -10
- 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 +129 -6
- package/src/cli/tokens-css.test.ts +90 -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 +483 -15
- package/src/guard/index.ts +426 -47
- 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 +22 -11
- package/src/surfaces.ts +24 -10
- 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 +534 -48
- 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,258 @@ 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
|
+
/**
|
|
492
|
+
* The `--vx-space-*` names that survive `only: 'core'` — DERIVED from the `SPACE` anchor keys, never
|
|
493
|
+
* hand-listed, so a new `SPACE_STEP` one-off is excluded the moment it is added and a renamed anchor
|
|
494
|
+
* follows automatically. `SPACE` is the generic ladder (the stack rhythm, the two control heights,
|
|
495
|
+
* the row insets); everything else `spaceDecls` emits is named for a basalt COMPONENT and is dead
|
|
496
|
+
* weight outside this framework — including `--vx-space-row-line-height`, which is the NavLink row's
|
|
497
|
+
* line-height rather than a general anchor and so is (deliberately) in neither set.
|
|
498
|
+
*/
|
|
499
|
+
const CORE_SPACE_VARS = new Set(
|
|
500
|
+
Object.keys(SPACE).map((key) => `space-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`),
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Does this `spaceDecls` line declare a core anchor? The name is read back out of the emitted line
|
|
505
|
+
* because {@link decl} is the single formatter for every one of them — the shape is fixed at one
|
|
506
|
+
* call site, so parsing it cannot drift, whereas tagging 104 declarations by hand could.
|
|
507
|
+
*/
|
|
508
|
+
function isCoreSpaceDecl(line: string): boolean {
|
|
509
|
+
const name = /^ {2}--vx-([\w-]+):/.exec(line)?.[1]
|
|
510
|
+
return name !== undefined && CORE_SPACE_VARS.has(name)
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** The shipped, level-0 spacing values — `frameworkDerived`'s `spaceDecls(...)` call below. No
|
|
514
|
+
* `createBasaltTheme({ density })` retuning applies here; that path calls `buildDensityCss` with a
|
|
515
|
+
* different resolved {@link SpaceValues} instead (see `../theme` and `../provider`). */
|
|
516
|
+
const DEFAULT_SPACE_VALUES: SpaceValues = {
|
|
517
|
+
anchors: SPACE,
|
|
518
|
+
scale: SPACE_SCALE,
|
|
519
|
+
step: SPACE_STEP,
|
|
520
|
+
rowLineHeight: ROW_LINE_HEIGHT,
|
|
521
|
+
}
|
|
522
|
+
|
|
256
523
|
/**
|
|
257
524
|
* Theme-independent scalars + semantic fills, defined once on `:root`.
|
|
258
525
|
*
|
|
259
526
|
* Area-gradient strength is a global knob (the theme lab overrides these two on `:root`
|
|
260
527
|
* to retune every line-area fill live). 0%/0% disables gradients app-wide.
|
|
261
528
|
*/
|
|
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
|
-
|
|
529
|
+
function frameworkDerived(data: PaletteData, only: 'core' | 'all'): string {
|
|
530
|
+
const space = spaceDecls(DEFAULT_SPACE_VALUES)
|
|
531
|
+
return [
|
|
532
|
+
decl('radius-card', `${RADIUS.card}px`),
|
|
533
|
+
decl('radius-ctrl', `${RADIUS.ctrl}px`),
|
|
534
|
+
// The two offset tiers (SegmentedControl indicator/Kbd/Code, Progress/scale-sm) — added so a
|
|
535
|
+
// component's inline `styles`/`style` can read the SAME source as `RADIUS_STEP.tight`/`.fine`
|
|
536
|
+
// instead of a hand-typed literal (see `theme/index.ts`'s component sweep).
|
|
537
|
+
decl('radius-tight', `${RADIUS_STEP.tight}px`),
|
|
538
|
+
decl('radius-fine', `${RADIUS_STEP.fine}px`),
|
|
539
|
+
// The floating tier (Modal/Tooltip/Popover/Notification, content code/mermaid blocks).
|
|
540
|
+
decl('radius-floating', `${RADIUS_STEP.floating}px`),
|
|
541
|
+
// The pill affordance (scroll-to-bottom button, chips) — fixed, level-invariant, so it lives
|
|
542
|
+
// only in this static block, never in `buildRadiusCss`'s dynamic override (see
|
|
543
|
+
// `RADIUS_STEP.pill`'s doc).
|
|
544
|
+
decl('radius-pill', `${RADIUS_STEP.pill}px`),
|
|
545
|
+
...(only === 'core' ? space.filter(isCoreSpaceDecl) : space),
|
|
546
|
+
// Article-density Prose measure (docs/CONTENT-SPEC.md §5) — theme-independent, like the radii.
|
|
547
|
+
decl('prose-measure', '72ch'),
|
|
548
|
+
// The fill band (see FILL in palette.ts). Emitted on `:root`, NOT per scheme — a filled surface
|
|
549
|
+
// is the same hex in both, which is the whole point: it is squeezed between its white label and
|
|
550
|
+
// the page behind it, and only one luminance band satisfies both on both pages.
|
|
551
|
+
...Object.entries(data.FILL).map(([name, hex]) => decl(`fill-${name}`, hex)),
|
|
552
|
+
// Hover is DERIVED from the fill, so retuning a fill (in the theme lab, or here) carries its
|
|
553
|
+
// hover along instead of leaving a stale pair. 88% of the fill over black lands ~0.128 luminance:
|
|
554
|
+
// a visible press-darkening that still clears AA for the white label (~5.9:1).
|
|
555
|
+
...Object.keys(data.FILL).map((name) =>
|
|
556
|
+
decl(`fillHover-${name}`, `color-mix(in srgb, var(--vx-fill-${name}) 88%, #000)`),
|
|
557
|
+
),
|
|
558
|
+
// The type scale, emitted from the SAME `TEXT` object `VX.text` reads — CSS modules and the
|
|
559
|
+
// Mantine theme consume these; inline styles / visx read the numbers. One ladder, two forms.
|
|
560
|
+
...Object.entries(TEXT).map(([step, px]) => decl(`text-${step}`, `${px}px`)),
|
|
561
|
+
decl('area-top', '22%'),
|
|
562
|
+
decl('area-bottom', '1%'),
|
|
563
|
+
decl('good', 'color-mix(in srgb, var(--vx-goodSolid) 18%, transparent)'),
|
|
564
|
+
decl('goodSoft', 'color-mix(in srgb, var(--vx-goodSolid) 8%, transparent)'),
|
|
565
|
+
decl('bad', 'color-mix(in srgb, var(--vx-badSolid) 18%, transparent)'),
|
|
566
|
+
decl('warn', 'color-mix(in srgb, var(--vx-warnSolid) 8%, transparent)'),
|
|
567
|
+
decl('goodRef', 'color-mix(in srgb, var(--vx-goodSolid) 30%, transparent)'),
|
|
568
|
+
decl('badRef', 'color-mix(in srgb, var(--vx-badSolid) 30%, transparent)'),
|
|
569
|
+
decl('warnRef', 'color-mix(in srgb, var(--vx-warnSolid) 20%, transparent)'),
|
|
570
|
+
].join('\n')
|
|
571
|
+
}
|
|
290
572
|
|
|
291
573
|
/**
|
|
292
574
|
* Wrap a map of `{ name: ColorPair }` into `var(--vx-<prefix><name>)` token refs — the runtime
|
|
@@ -326,14 +608,89 @@ export function groupTokens<const T extends SeriesMap>(
|
|
|
326
608
|
return seriesTokens(map, `${name}-`)
|
|
327
609
|
}
|
|
328
610
|
|
|
611
|
+
/**
|
|
612
|
+
* The attribute + values the per-scheme blocks key off. Defaults reproduce Mantine's own toggle
|
|
613
|
+
* (`data-mantine-color-scheme` = `dark` / `light`), so a consumer only names the axis it differs
|
|
614
|
+
* on. Supplying this object at all switches the emitter onto the framework-neutral selector shape
|
|
615
|
+
* — see {@link BuildPaletteOpts.scheme}.
|
|
616
|
+
*/
|
|
617
|
+
export type ColorSchemeSelector = {
|
|
618
|
+
attribute?: string
|
|
619
|
+
darkValue?: string
|
|
620
|
+
lightValue?: string
|
|
621
|
+
}
|
|
622
|
+
|
|
329
623
|
/** Options for {@link buildPaletteCss}. */
|
|
330
624
|
export type BuildPaletteOpts = {
|
|
331
625
|
/** Extra named series maps to emit under the given prefixes (e.g. `{ '': SERIES, 'activity-': ACTIVITY }`). */
|
|
332
626
|
groups?: Record<string, SeriesMap>
|
|
333
627
|
/** Theme-independent derived declarations (gradients, semantic fills) emitted once on `:root`. */
|
|
334
628
|
derived?: string[]
|
|
629
|
+
/**
|
|
630
|
+
* Attribute + values the per-scheme blocks key off — for a consumer whose scheme toggle is not
|
|
631
|
+
* Mantine's (a static site on `data-theme`, say). Default: Mantine's own
|
|
632
|
+
* `data-mantine-color-scheme` = `dark` / `light`.
|
|
633
|
+
*
|
|
634
|
+
* Setting ANY of `scheme` / `defaultScheme` / `mediaFallback` moves the emitter off the legacy
|
|
635
|
+
* `html[…]` selector onto `:root[…]`. That is deliberate and load-bearing, NOT cosmetic:
|
|
636
|
+
*
|
|
637
|
+
* `:root[data-theme='dark']` 0-2-0 ← what this path emits
|
|
638
|
+
* `html[data-theme='dark']` 0-1-1
|
|
639
|
+
* `[data-theme='dark']` 0-1-0 ← same as a bare `:root`, so source order decides
|
|
640
|
+
*
|
|
641
|
+
* A light-default site whose own `:root` block happens to come last would beat the third form
|
|
642
|
+
* outright — dark mode silently does nothing. `:root[…]` sits above both a bare `:root` and
|
|
643
|
+
* `html[…]`, and carries no assumption about the element the attribute lands on.
|
|
644
|
+
*
|
|
645
|
+
* The no-options path keeps emitting `html[data-mantine-color-scheme='…']` verbatim, because a
|
|
646
|
+
* basalt consumer may already override `--vx-*` under that exact selector — raising basalt's own
|
|
647
|
+
* specificity would silently win over their override.
|
|
648
|
+
*/
|
|
649
|
+
scheme?: ColorSchemeSelector
|
|
650
|
+
/**
|
|
651
|
+
* Which scheme rides along on the bare `:root` block — the one that applies when the attribute
|
|
652
|
+
* is absent. Default: `'dark'` (the framework's own default scheme).
|
|
653
|
+
*
|
|
654
|
+
* `'none'` emits no bare-`:root` primitives at all: each scheme gets only its attribute block,
|
|
655
|
+
* and an unattributed document falls back to the theme-independent scalars alone. Pair it with
|
|
656
|
+
* `mediaFallback` unless the consumer always sets the attribute.
|
|
657
|
+
*/
|
|
658
|
+
defaultScheme?: 'dark' | 'light' | 'none'
|
|
659
|
+
/**
|
|
660
|
+
* Also emit an `@media (prefers-color-scheme: …)` block for every scheme that is not the bare
|
|
661
|
+
* `:root` default, so a document with no attribute set follows the OS. Default: `false`.
|
|
662
|
+
*
|
|
663
|
+
* The block is a bare `:root` (0-1-0), so an explicit attribute block (0-2-0) always wins over
|
|
664
|
+
* it regardless of source order — the OS preference is a fallback, never an override.
|
|
665
|
+
*/
|
|
666
|
+
mediaFallback?: boolean
|
|
667
|
+
/**
|
|
668
|
+
* How much of the SPACING set to emit. Default: `'all'` (every one of the 104 `--vx-space-*`
|
|
669
|
+
* declarations the framework's own components read).
|
|
670
|
+
*
|
|
671
|
+
* `'core'` keeps the 9 generic anchors — the stack rhythm, the two control heights, the row
|
|
672
|
+
* insets — and drops the 95 named for a specific basalt component
|
|
673
|
+
* (`--vx-space-agent-transcript-inset`, `--vx-space-toc-sub-indent`, …), taking the emitted set
|
|
674
|
+
* from 197 variables to 102. Nothing outside basalt's own React components reads those, so a
|
|
675
|
+
* framework-free consumer is carrying them for nothing.
|
|
676
|
+
*
|
|
677
|
+
* This is a SPACING filter only: color, radius, shadow, type and status variables are identical
|
|
678
|
+
* in both modes. The partition is derived from the `SPACE` key set rather than a maintained list
|
|
679
|
+
* — see {@link CORE_SPACE_VARS}.
|
|
680
|
+
*/
|
|
681
|
+
only?: 'core' | 'all'
|
|
335
682
|
}
|
|
336
683
|
|
|
684
|
+
/** Mantine's own color-scheme attribute — the default {@link ColorSchemeSelector.attribute}. */
|
|
685
|
+
const MANTINE_SCHEME_ATTRIBUTE = 'data-mantine-color-scheme'
|
|
686
|
+
|
|
687
|
+
/** Indent an already-2-space-indented declaration block one level deeper (for `@media` nesting). */
|
|
688
|
+
const indent = (block: string): string =>
|
|
689
|
+
block
|
|
690
|
+
.split('\n')
|
|
691
|
+
.map((line) => (line === '' ? line : ` ${line}`))
|
|
692
|
+
.join('\n')
|
|
693
|
+
|
|
337
694
|
/**
|
|
338
695
|
* Emit the `--vx-*` stylesheet: a `:root` block of theme-independent scalars, then the
|
|
339
696
|
* dark (default) and light primitive blocks under `html[data-mantine-color-scheme='…']`.
|
|
@@ -342,23 +699,42 @@ export type BuildPaletteOpts = {
|
|
|
342
699
|
* built in, so an empty `buildPaletteCss()` already emits every framework var. Consumer
|
|
343
700
|
* `opts.groups` / `opts.derived` append on top (e.g. argo's domain SERIES/ACTIVITY/USAGE).
|
|
344
701
|
*
|
|
702
|
+
* `data` defaults to the static, shipped palette (`buildPaletteData()` at `DEFAULT_DERIVE_CONFIG`)
|
|
703
|
+
* — pass the result of `buildPaletteData(config)` to emit CSS for a retuned derive config instead
|
|
704
|
+
* (this is how `BasaltProvider` follows `createBasaltTheme`'s `{ derive }` option; see `../theme`
|
|
705
|
+
* and `../provider`).
|
|
706
|
+
*
|
|
345
707
|
* Dark is the default (`:root`) since the framework defaults to dark; the
|
|
346
708
|
* `[data-mantine-color-scheme]` selectors track Mantine's toggle on `<html>`.
|
|
709
|
+
*
|
|
710
|
+
* A non-Mantine consumer retargets all three of those choices — the attribute, which scheme rides
|
|
711
|
+
* the bare `:root`, and whether the OS preference is honoured — via `opts.scheme` /
|
|
712
|
+
* `opts.defaultScheme` / `opts.mediaFallback`. Setting any of them also moves the per-scheme
|
|
713
|
+
* selector from `html[…]` to the framework-neutral, higher-specificity `:root[…]`; see
|
|
714
|
+
* `BuildPaletteOpts.scheme` for why that is not cosmetic. With none of them set the output is
|
|
715
|
+
* byte-identical to what the framework has always emitted (pinned by
|
|
716
|
+
* `tests/palette-css.test.ts`).
|
|
347
717
|
*/
|
|
348
|
-
export function buildPaletteCss(
|
|
718
|
+
export function buildPaletteCss(
|
|
719
|
+
opts: BuildPaletteOpts = {},
|
|
720
|
+
data: PaletteData = buildPaletteData(),
|
|
721
|
+
): string {
|
|
349
722
|
const groups = opts.groups ?? {}
|
|
350
723
|
const extraDerived = (opts.derived ?? []).map((d) => ` ${d}`).join('\n')
|
|
351
|
-
const
|
|
724
|
+
const derivedBlock = frameworkDerived(data, opts.only ?? 'all')
|
|
725
|
+
const derived = extraDerived ? `${derivedBlock}\n${extraDerived}` : derivedBlock
|
|
352
726
|
const side = (s: Side): string => {
|
|
353
727
|
const extra = Object.entries(groups)
|
|
354
728
|
.map(([prefix, map]) => groupSide(prefix, map, s))
|
|
355
729
|
.join('\n')
|
|
356
|
-
const framework = frameworkPrimitives(s)
|
|
730
|
+
const framework = frameworkPrimitives(s, data)
|
|
357
731
|
return extra ? `${framework}\n${extra}` : framework
|
|
358
732
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
733
|
+
const rootBlock = `:root {\n${derived}\n}`
|
|
734
|
+
|
|
735
|
+
// The legacy shape — kept verbatim, and only reachable when the caller asked for nothing.
|
|
736
|
+
if (opts.scheme === undefined && opts.defaultScheme === undefined && !opts.mediaFallback) {
|
|
737
|
+
return `${rootBlock}
|
|
362
738
|
:root,
|
|
363
739
|
html[data-mantine-color-scheme='dark'] {
|
|
364
740
|
${side('dark')}
|
|
@@ -366,4 +742,114 @@ ${side('dark')}
|
|
|
366
742
|
html[data-mantine-color-scheme='light'] {
|
|
367
743
|
${side('light')}
|
|
368
744
|
}`
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const attribute = opts.scheme?.attribute ?? MANTINE_SCHEME_ATTRIBUTE
|
|
748
|
+
const value: Record<Side, string> = {
|
|
749
|
+
dark: opts.scheme?.darkValue ?? 'dark',
|
|
750
|
+
light: opts.scheme?.lightValue ?? 'light',
|
|
751
|
+
}
|
|
752
|
+
const defaultScheme = opts.defaultScheme ?? 'dark'
|
|
753
|
+
// Default scheme first, so its attribute block can absorb the bare `:root` instead of repeating
|
|
754
|
+
// ~40 declarations; `'none'` keeps the framework's dark-then-light order.
|
|
755
|
+
const order: Side[] = defaultScheme === 'light' ? ['light', 'dark'] : ['dark', 'light']
|
|
756
|
+
|
|
757
|
+
const blocks = [rootBlock]
|
|
758
|
+
for (const s of order) {
|
|
759
|
+
const selector =
|
|
760
|
+
s === defaultScheme
|
|
761
|
+
? `:root,\n:root[${attribute}='${value[s]}']`
|
|
762
|
+
: `:root[${attribute}='${value[s]}']`
|
|
763
|
+
// The OS fallback for a scheme goes immediately before that scheme's own attribute block. It is
|
|
764
|
+
// a bare `:root` (0-1-0), so the attribute block (0-2-0) outranks it on specificity rather than
|
|
765
|
+
// on order — an explicit toggle always beats the OS preference, and the OS preference always
|
|
766
|
+
// beats the hardcoded default that a bare `:root` above it carries.
|
|
767
|
+
if (opts.mediaFallback === true && s !== defaultScheme) {
|
|
768
|
+
blocks.push(`@media (prefers-color-scheme: ${s}) {\n :root {\n${indent(side(s))}\n }\n}`)
|
|
769
|
+
}
|
|
770
|
+
blocks.push(`${selector} {\n${side(s)}\n}`)
|
|
771
|
+
}
|
|
772
|
+
return blocks.join('\n')
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* The `fonts` option's resolved shape — a full CSS font-family stack string per slot (with its own
|
|
777
|
+
* fallback chain), riding the `--basalt-font-sans/head/mono` override seam `styles.css` ships
|
|
778
|
+
* fallbacks for. Omitted keys keep the shipped fallback untouched. Lives here (not in `../theme`,
|
|
779
|
+
* which only RE-EXPORTS it) because its builder `buildFontsCss` below is a pure, Mantine-free
|
|
780
|
+
* string builder that belongs in the tokens layer — see `../theme`'s
|
|
781
|
+
* `CreateBasaltThemeOptions.fonts` for the production entry point that sets it.
|
|
782
|
+
*/
|
|
783
|
+
export type BasaltFontsConfig = {
|
|
784
|
+
sans?: string
|
|
785
|
+
head?: string
|
|
786
|
+
mono?: string
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/** `{ basaltFonts key → --basalt-font-* var name }` — the one place the mapping is spelled out. */
|
|
790
|
+
const FONT_VAR_NAMES = {
|
|
791
|
+
sans: '--basalt-font-sans',
|
|
792
|
+
head: '--basalt-font-head',
|
|
793
|
+
mono: '--basalt-font-mono',
|
|
794
|
+
} as const satisfies Record<keyof BasaltFontsConfig, string>
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Build the `:root` block of `--basalt-font-*` declarations for a resolved `basaltFonts` config —
|
|
798
|
+
* only for the keys the consumer actually set (`createBasaltTheme(overrides, { fonts })`); an
|
|
799
|
+
* omitted key keeps the shipped `styles.css` fallback chain untouched. Empty string when `fonts` is
|
|
800
|
+
* absent or every key is omitted, so callers can unconditionally concatenate the result. Importable
|
|
801
|
+
* from `basalt-ui/tokens` — `BasaltProvider`'s bridge (`../provider`) calls this directly to append
|
|
802
|
+
* declarations to its injected `<style>`; an SSR/custom-injection consumer with
|
|
803
|
+
* `injectPalette={false}` calls it themselves (see the JSDoc on that prop).
|
|
804
|
+
*/
|
|
805
|
+
export function buildFontsCss(fonts: BasaltFontsConfig | undefined): string {
|
|
806
|
+
if (!fonts) return ''
|
|
807
|
+
const decls = (Object.keys(FONT_VAR_NAMES) as (keyof BasaltFontsConfig)[])
|
|
808
|
+
.filter((key) => fonts[key] !== undefined)
|
|
809
|
+
.map((key) => {
|
|
810
|
+
const value = fonts[key] as string
|
|
811
|
+
// A font stack is a plain declaration value — `{`/`}`/`;`/comment openers would let a
|
|
812
|
+
// config string break out of the emitted `<style>` declaration. Throw, don't sanitize,
|
|
813
|
+
// per the repo's validation convention (see `deriveTokens`'s accent-hex assert).
|
|
814
|
+
if (/[{};]|\/\*/.test(value)) {
|
|
815
|
+
throw new Error(
|
|
816
|
+
`Invalid fonts.${key}: a font-family stack must not contain "{", "}", ";" or "/*" — got ${JSON.stringify(value)}`,
|
|
817
|
+
)
|
|
818
|
+
}
|
|
819
|
+
return ` ${FONT_VAR_NAMES[key]}: ${value};`
|
|
820
|
+
})
|
|
821
|
+
if (decls.length === 0) return ''
|
|
822
|
+
return `:root {\n${decls.join('\n')}\n}`
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Build the `:root` block of overriding `--vx-radius-*` declarations for a resolved
|
|
827
|
+
* `basaltRadius` value (`createBasaltTheme(overrides, { radius })`) — analog of {@link buildFontsCss}.
|
|
828
|
+
* Empty string when `radius` is absent (the default level-0 path never sets `theme.other.basaltRadius`
|
|
829
|
+
* in the first place), so callers can unconditionally concatenate the result. Importable from
|
|
830
|
+
* `basalt-ui/tokens`, same SSR/custom-injection use as `buildFontsCss` above.
|
|
831
|
+
*/
|
|
832
|
+
export function buildRadiusCss(radius: RadiusValues | undefined): string {
|
|
833
|
+
if (!radius) return ''
|
|
834
|
+
return `:root {
|
|
835
|
+
--vx-radius-card: ${radius.card}px;
|
|
836
|
+
--vx-radius-ctrl: ${radius.ctrl}px;
|
|
837
|
+
--vx-radius-tight: ${radius.tight}px;
|
|
838
|
+
--vx-radius-fine: ${radius.fine}px;
|
|
839
|
+
--vx-radius-floating: ${radius.floating}px;
|
|
840
|
+
}`
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Build the `:root` block of overriding `--vx-space-*` declarations for a resolved `basaltDensity`
|
|
845
|
+
* value (`createBasaltTheme(overrides, { density })`) — analog of {@link buildRadiusCss}, reusing
|
|
846
|
+
* the SAME `spaceDecls` list `frameworkDerived` emits the shipped defaults from (so the two can
|
|
847
|
+
* never drift). Empty string when `space` is absent (the default level-0 path never sets
|
|
848
|
+
* `theme.other.basaltDensity` in the first place), so callers can unconditionally concatenate the
|
|
849
|
+
* result. Importable from `basalt-ui/tokens`, same SSR/custom-injection use as `buildRadiusCss`
|
|
850
|
+
* above.
|
|
851
|
+
*/
|
|
852
|
+
export function buildDensityCss(space: SpaceValues | undefined): string {
|
|
853
|
+
if (!space) return ''
|
|
854
|
+
return `:root {\n${spaceDecls(space).join('\n')}\n}`
|
|
369
855
|
}
|