basalt-ui 2.20.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/MIGRATING.md +394 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-tokens.md +3 -3
- package/agent/skills/basalt-design/SKILL.md +10 -23
- package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
- package/agent/skills/basalt-design/references/catalogue.md +49 -0
- package/agent/skills/basalt-design/references/concept.md +36 -0
- package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
- package/agent/skills/basalt-design/references/stat-tile.md +24 -0
- package/agent/templates/AGENTS-block.md.tpl +3 -3
- package/configs/oxlint-plugin.js +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +27 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +5 -0
- package/dist/charts/CartesianChart.d.ts +8 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +17 -4
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +33 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +39 -14
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +20 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +9 -0
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +17 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +145 -74
- package/dist/charts/labels.d.ts +15 -4
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +34 -10
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +26 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +63 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +10 -11
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -1
- package/dist/charts/types.d.ts +14 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +3 -0
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +3 -2
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +27 -15
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +71 -6
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +200 -33
- package/dist/cli/shot/detect.d.ts +51 -0
- package/dist/cli/shot/detect.d.ts.map +1 -0
- package/dist/cli/shot/detect.js +409 -0
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +7 -4
- package/dist/cli/shot/measure.d.ts +2 -0
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +2 -0
- package/dist/cli/shot/playwright.d.ts +5 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +6 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +4 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/common/retry-button.d.ts +12 -0
- package/dist/common/retry-button.d.ts.map +1 -0
- package/dist/common/retry-button.js +22 -0
- package/dist/common/retry-button.module.css +58 -0
- package/dist/common/retry-button.module.css.d.ts +8 -0
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts +5 -2
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +9 -10
- package/dist/dashboard/bar-list.module.css +53 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +108 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +123 -19
- package/dist/dashboard/meter-parts.d.ts +8 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +345 -146
- package/dist/dashboard/meter.d.ts +50 -63
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +24 -3
- package/dist/dashboard/meter.module.css +79 -65
- package/dist/dashboard/meter.module.css.d.ts +7 -7
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/query-state.d.ts +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +3 -2
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -4
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +24 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +97 -39
- package/dist/dashboard/stat-strip.module.css +147 -17
- package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -0
- package/dist/dashboard/visual-slot.js +7 -0
- package/dist/guard/index.d.ts +15 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +14 -0
- package/dist/guard/palette.d.ts +51 -0
- package/dist/guard/palette.d.ts.map +1 -0
- package/dist/guard/palette.js +190 -0
- package/dist/guard/series-file.d.ts +15 -0
- package/dist/guard/series-file.d.ts.map +1 -0
- package/dist/guard/series-file.js +29 -0
- package/dist/guard/types.d.ts +3 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +34 -2
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +33 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +11 -5
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/oklab.d.ts +28 -0
- package/dist/tokens/oklab.d.ts.map +1 -0
- package/dist/tokens/oklab.js +73 -0
- package/dist/tokens/palette.d.ts +4 -0
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +4 -0
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +43 -23
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +33 -3
- package/src/charts/Bars.tsx +6 -0
- package/src/charts/CartesianChart.tsx +16 -3
- package/src/charts/ChartCard.tsx +43 -7
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +50 -13
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +31 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +210 -85
- package/src/charts/labels.ts +48 -14
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +104 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +10 -11
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +12 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/check-theme.ts +3 -0
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/help.ts +18 -1
- package/src/cli/index.ts +48 -17
- package/src/cli/init.ts +102 -4
- package/src/cli/shot/capture.ts +266 -34
- package/src/cli/shot/detect.ts +550 -0
- package/src/cli/shot/index.ts +8 -4
- package/src/cli/shot/measure.ts +4 -0
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +8 -1
- package/src/cli/sync.ts +4 -2
- package/src/common/retry-button.module.css +58 -0
- package/src/common/retry-button.module.css.d.ts +8 -0
- package/src/common/retry-button.tsx +29 -0
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +53 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +88 -76
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +265 -28
- package/src/dashboard/meter-parts.tsx +424 -163
- package/src/dashboard/meter.module.css +79 -65
- package/src/dashboard/meter.module.css.d.ts +7 -7
- package/src/dashboard/meter.tsx +77 -17
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/query-state.tsx +4 -7
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +17 -0
- package/src/dashboard/stat-card.tsx +14 -5
- package/src/dashboard/stat-strip.module.css +147 -17
- package/src/dashboard/stat-strip.module.css.d.ts +8 -0
- package/src/dashboard/stat-strip.tsx +182 -56
- package/src/dashboard/visual-slot.ts +17 -0
- package/src/guard/index.ts +16 -4
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +33 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +18 -5
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/oklab.ts +97 -0
- package/src/tokens/palette.ts +4 -0
- package/src/tokens/status-text.ts +2 -0
package/src/charts/labels.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { rowX } from './types'
|
|
|
9
9
|
import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types'
|
|
10
10
|
|
|
11
11
|
const MAX_END_LABELS = 3
|
|
12
|
-
/**
|
|
12
|
+
/** Two end labels closer than this (px, vertically) are pushed apart to it. */
|
|
13
13
|
const END_LABEL_MIN_GAP = 13
|
|
14
14
|
const END_LABEL_DX = 6
|
|
15
15
|
/**
|
|
@@ -42,10 +42,15 @@ export function endLabelAnchor(opts: {
|
|
|
42
42
|
return room >= label.length * fontSize * END_LABEL_GLYPH_EM + END_LABEL_DX ? 'start' : 'end'
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** `Lines`' one naming switch: who names the series. */
|
|
46
|
+
export type LinesNaming = 'auto' | 'legend' | 'endLabels'
|
|
47
|
+
|
|
45
48
|
export type EndLabel<T, X extends ChartX> = {
|
|
46
49
|
series: ChartSeries<T>
|
|
47
50
|
row: PlotRow<T, X>
|
|
48
51
|
anchor: EndLabelAnchor
|
|
52
|
+
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
53
|
+
nudge: number
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
type LastPoint<T, X extends ChartX> = {
|
|
@@ -56,17 +61,45 @@ type LastPoint<T, X extends ChartX> = {
|
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
64
|
+
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
65
|
+
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
66
|
+
* topmost stays inside the plot. Order is kept.
|
|
67
|
+
*/
|
|
68
|
+
export function spreadLabels(ys: readonly number[], plotHeight: number): number[] {
|
|
69
|
+
const order = ys.map((y, i) => i).toSorted((a, b) => (ys[a] as number) - (ys[b] as number))
|
|
70
|
+
const placed = new Map<number, number>()
|
|
71
|
+
let floor = -Infinity
|
|
72
|
+
for (const i of order) {
|
|
73
|
+
const at = Math.max(ys[i] as number, floor)
|
|
74
|
+
placed.set(i, at)
|
|
75
|
+
floor = at + END_LABEL_MIN_GAP
|
|
76
|
+
}
|
|
77
|
+
// Pushed past the top: slide the whole stack back down, then re-sweep from the top.
|
|
78
|
+
const top = plotHeight - END_LABEL_MIN_GAP / 2
|
|
79
|
+
let ceiling = Infinity
|
|
80
|
+
for (const i of order.toReversed()) {
|
|
81
|
+
const at = Math.min(placed.get(i) as number, ceiling, top)
|
|
82
|
+
placed.set(i, at)
|
|
83
|
+
ceiling = at - END_LABEL_MIN_GAP
|
|
84
|
+
}
|
|
85
|
+
return ys.map((y, i) => (placed.get(i) as number) - y)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The end labels to draw. `auto`: on the wide class only, with ≤ {@link MAX_END_LABELS} lines and
|
|
90
|
+
* no right axis; `endLabels`: at every width and any line count (still no right axis, whose
|
|
91
|
+
* series read another scale); `legend`: none. Labels that would collide are spread apart, never
|
|
92
|
+
* dropped. A series whose last point the plot's own x scale cannot place, or places outside the plot
|
|
62
93
|
* (`plot.xFraction` outside [0, 1]: clipped by a narrower `xDomain`), has no label.
|
|
63
94
|
*/
|
|
64
95
|
export function endLabelPlan<T, X extends ChartX>(
|
|
65
96
|
plot: PlotContext<T, X>,
|
|
66
97
|
lines: readonly ChartSeries<T>[],
|
|
98
|
+
naming: LinesNaming = 'auto',
|
|
67
99
|
): EndLabel<T, X>[] {
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
100
|
+
if (naming === 'legend' || plot.y2 !== undefined || lines.length === 0) return []
|
|
101
|
+
if (naming === 'auto' && (plot.containerClass !== 'wide' || lines.length > MAX_END_LABELS))
|
|
102
|
+
return []
|
|
70
103
|
const last = lines.flatMap((series): LastPoint<T, X>[] => {
|
|
71
104
|
const row = plot.rows(series.key).findLast((r) => r.y !== null)
|
|
72
105
|
if (row === undefined || row.y === null) return []
|
|
@@ -74,14 +107,13 @@ export function endLabelPlan<T, X extends ChartX>(
|
|
|
74
107
|
if (fraction === null || fraction < 0 || fraction > 1) return []
|
|
75
108
|
return [{ series, row, y: row.y, fraction }]
|
|
76
109
|
})
|
|
77
|
-
// Collision check in pixels from the plot height: labels that would overlap are not drawn at all.
|
|
78
110
|
// No `y2` here (returned above), so every label reads the left domain.
|
|
79
111
|
const [lo, hi] = plot.yDomain
|
|
80
|
-
const
|
|
81
|
-
.map(({ y }) => ((y - lo) / (hi - lo || 1)) * plot.plotHeight)
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
return last.map(({ series, row, fraction }) => ({
|
|
112
|
+
const shifts = spreadLabels(
|
|
113
|
+
last.map(({ y }) => ((y - lo) / (hi - lo || 1)) * plot.plotHeight),
|
|
114
|
+
plot.plotHeight,
|
|
115
|
+
)
|
|
116
|
+
return last.map(({ series, row, fraction }, i) => ({
|
|
85
117
|
series,
|
|
86
118
|
row,
|
|
87
119
|
anchor: endLabelAnchor({
|
|
@@ -90,6 +122,7 @@ export function endLabelPlan<T, X extends ChartX>(
|
|
|
90
122
|
label: series.label,
|
|
91
123
|
fontSize: VX.text.micro,
|
|
92
124
|
}),
|
|
125
|
+
nudge: 0 - (shifts[i] as number),
|
|
93
126
|
}))
|
|
94
127
|
}
|
|
95
128
|
|
|
@@ -101,7 +134,7 @@ export function endLabelOffset(anchor: EndLabelAnchor): { dx: number; dy: number
|
|
|
101
134
|
}
|
|
102
135
|
|
|
103
136
|
export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>[]): ChartMarks {
|
|
104
|
-
return plan.map(({ series, row, anchor }) =>
|
|
137
|
+
return plan.map(({ series, row, anchor, nudge }) =>
|
|
105
138
|
decorative(
|
|
106
139
|
text([row], {
|
|
107
140
|
id: `${series.key}-end-label`,
|
|
@@ -111,7 +144,8 @@ export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>
|
|
|
111
144
|
fill: series.color,
|
|
112
145
|
fontSize: VX.text.micro,
|
|
113
146
|
anchor,
|
|
114
|
-
|
|
147
|
+
dx: endLabelOffset(anchor).dx,
|
|
148
|
+
dy: endLabelOffset(anchor).dy + nudge,
|
|
115
149
|
}),
|
|
116
150
|
),
|
|
117
151
|
)
|
package/src/charts/legend.tsx
CHANGED
|
@@ -49,7 +49,8 @@ const rowBaseStyle: CSSProperties = {
|
|
|
49
49
|
flexWrap: 'wrap',
|
|
50
50
|
alignItems: 'center',
|
|
51
51
|
rowGap: 4,
|
|
52
|
-
|
|
52
|
+
// The tick step: ticks, legend and tooltip are one size, so a chart card has at most three.
|
|
53
|
+
fontSize: VX.text.micro,
|
|
53
54
|
color: VX.ink2,
|
|
54
55
|
lineHeight: 1.35,
|
|
55
56
|
}
|
|
@@ -153,29 +154,15 @@ function Swatch({ s, mode }: { s: SwatchStyle; mode: LegendMode }): ReactElement
|
|
|
153
154
|
</>
|
|
154
155
|
)
|
|
155
156
|
if ((s.mark ?? 'line') === 'line') return <LineSwatch s={s} compact={mode === 'dots'} />
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<span
|
|
159
|
-
aria-hidden
|
|
160
|
-
className={classes.dot}
|
|
161
|
-
style={{
|
|
162
|
-
width: 8,
|
|
163
|
-
height: 8,
|
|
164
|
-
// theme-allow raw-surface — a legend dot is a circle, not a surface corner
|
|
165
|
-
borderRadius: '50%',
|
|
166
|
-
background: swatchFill(s),
|
|
167
|
-
opacity: s.fillOpacity ?? 1,
|
|
168
|
-
flex: 'none',
|
|
169
|
-
}}
|
|
170
|
-
/>
|
|
171
|
-
)
|
|
157
|
+
// One shape per mark kind at every width: a bar is a rounded square, compact (8) or wide (10).
|
|
158
|
+
const size = mode === 'dots' ? 8 : 10
|
|
172
159
|
return (
|
|
173
160
|
<span
|
|
174
161
|
aria-hidden
|
|
175
|
-
className={classes.chip}
|
|
162
|
+
className={mode === 'dots' ? classes.dot : classes.chip}
|
|
176
163
|
style={{
|
|
177
|
-
width:
|
|
178
|
-
height:
|
|
164
|
+
width: size,
|
|
165
|
+
height: size,
|
|
179
166
|
// theme-allow raw-surface — swatch geometry, not a surface corner
|
|
180
167
|
borderRadius: 2,
|
|
181
168
|
background: swatchFill(s),
|
|
@@ -196,6 +183,8 @@ export type ChartLegendProps<T> = {
|
|
|
196
183
|
onHighlight: (key: string | null) => void
|
|
197
184
|
/** Keeps the legend's box but shows and offers nothing: a chart with no marks names no series. */
|
|
198
185
|
concealed?: boolean
|
|
186
|
+
/** `auto` mode only: gone from the wide class up, where end labels name the lines (CSS). */
|
|
187
|
+
hideAtWide?: boolean
|
|
199
188
|
}
|
|
200
189
|
|
|
201
190
|
export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
|
|
@@ -210,6 +199,7 @@ export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null
|
|
|
210
199
|
// `aria-hidden` is belt-and-braces for a tree that ignores computed visibility.
|
|
211
200
|
{...(props.concealed && { 'aria-hidden': true })}
|
|
212
201
|
{...(auto && { className: classes.auto })}
|
|
202
|
+
{...(auto && props.hideAtWide && { 'data-hide-wide': '' })}
|
|
213
203
|
style={rowLayout(props.mode, props.concealed === true)}
|
|
214
204
|
>
|
|
215
205
|
{groups.map((group, gi) => [
|
package/src/charts/marks.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function lineMark<T, X extends ChartX>(
|
|
|
52
52
|
stroke: s.color,
|
|
53
53
|
strokeWidth: s.strokeWidth ?? LINE_STROKE_WIDTH,
|
|
54
54
|
strokeOpacity: (s.strokeOpacity ?? 1) * emphasis(plot.highlighted, s),
|
|
55
|
-
curve: chartCurve(s.curve ?? '
|
|
55
|
+
curve: chartCurve(s.curve ?? 'linear'),
|
|
56
56
|
...(s.dash === 'dashed' && { strokeDasharray: DASH }),
|
|
57
57
|
...(yScale !== undefined && { yScale }),
|
|
58
58
|
})
|
package/src/charts/panel.tsx
CHANGED
|
@@ -90,15 +90,12 @@ export const paneY = (opts: {
|
|
|
90
90
|
format: (v: number) => string
|
|
91
91
|
ticks: number
|
|
92
92
|
cls: ContainerClass
|
|
93
|
-
/** The whole chart's height ({@link chartHeightOf}). */
|
|
94
|
-
height: number
|
|
95
93
|
}): StoredChartSpec['scales'][string] => ({
|
|
96
94
|
scale: opts.scale,
|
|
97
95
|
...yGuide({
|
|
98
96
|
cfg: { ticks: opts.ticks },
|
|
99
97
|
axis: { domain: opts.domain, format: opts.format },
|
|
100
98
|
cls: opts.cls,
|
|
101
|
-
height: opts.height,
|
|
102
99
|
side: 'left',
|
|
103
100
|
grid: true,
|
|
104
101
|
}),
|
|
@@ -113,23 +110,11 @@ export const paneX = <X extends ChartX>(opts: {
|
|
|
113
110
|
/** A consumer's x format; absent, the span-aware default ({@link xTickFormat}). */
|
|
114
111
|
format?: ((v: ChartValue) => string) | undefined
|
|
115
112
|
cls: ContainerClass
|
|
116
|
-
/** The whole chart's height ({@link chartHeightOf}). */
|
|
117
|
-
height: number
|
|
118
113
|
}): StoredChartSpec['scales'][string] => ({
|
|
119
114
|
scale: opts.scale,
|
|
120
|
-
...xGuide({
|
|
121
|
-
model: opts.model,
|
|
122
|
-
xTicks: undefined,
|
|
123
|
-
format: opts.format,
|
|
124
|
-
cls: opts.cls,
|
|
125
|
-
height: opts.height,
|
|
126
|
-
}),
|
|
115
|
+
...xGuide({ model: opts.model, xTicks: undefined, format: opts.format, cls: opts.cls }),
|
|
127
116
|
})
|
|
128
117
|
|
|
129
|
-
/** The whole chart's height from one pane's: a pane gets `share` of the height less the gap. */
|
|
130
|
-
export const chartHeightOf = (paneHeight: number, share: number, gap: number): number =>
|
|
131
|
-
paneHeight > 0 && share > 0 ? paneHeight / share + gap : 0
|
|
132
|
-
|
|
133
118
|
/** One row per datum for a series: a `null` or non-finite value is kept as a gap. */
|
|
134
119
|
export function rowsOf<T, X extends ChartX>(
|
|
135
120
|
data: readonly T[],
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a reference line's caption sits. Pure, so the rule is tested without an engine: a
|
|
3
|
+
* caption takes the first of four spots (end/start of the plot, above/below its line) that stays
|
|
4
|
+
* inside the plot and that no data line runs through; `RefLine.labelPosition` pins one.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type RefLabelPosition = 'end-above' | 'end-below' | 'start-above' | 'start-below'
|
|
8
|
+
|
|
9
|
+
/** A data point as a share of the plot width and a y value on the line's own axis. */
|
|
10
|
+
export type RefLabelPoint = { fx: number; y: number }
|
|
11
|
+
|
|
12
|
+
/** A glyph's advance as a share of the font size (proportional Latin text, capitals included). */
|
|
13
|
+
const GLYPH_EM = 0.62
|
|
14
|
+
/** The inset from the plot edge (the text's `dx`) and the gap between caption and line, in px. */
|
|
15
|
+
const EDGE_INSET = 6
|
|
16
|
+
const LINE_GAP = 3
|
|
17
|
+
|
|
18
|
+
const ORDER_END: readonly RefLabelPosition[] = [
|
|
19
|
+
'end-above',
|
|
20
|
+
'end-below',
|
|
21
|
+
'start-above',
|
|
22
|
+
'start-below',
|
|
23
|
+
]
|
|
24
|
+
const ORDER_START: readonly RefLabelPosition[] = [
|
|
25
|
+
'start-above',
|
|
26
|
+
'start-below',
|
|
27
|
+
'end-above',
|
|
28
|
+
'end-below',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
/** The y range of the polyline `points` (sorted by `fx`) between `fx0` and `fx1`, or `null`. */
|
|
32
|
+
function yRangeWithin(
|
|
33
|
+
points: readonly RefLabelPoint[],
|
|
34
|
+
fx0: number,
|
|
35
|
+
fx1: number,
|
|
36
|
+
): [number, number] | null {
|
|
37
|
+
let lo = Infinity
|
|
38
|
+
let hi = -Infinity
|
|
39
|
+
const take = (y: number): void => {
|
|
40
|
+
if (y < lo) lo = y
|
|
41
|
+
if (y > hi) hi = y
|
|
42
|
+
}
|
|
43
|
+
const at = (a: RefLabelPoint, b: RefLabelPoint, fx: number): number =>
|
|
44
|
+
b.fx === a.fx ? a.y : a.y + ((b.y - a.y) * (fx - a.fx)) / (b.fx - a.fx)
|
|
45
|
+
for (let i = 0; i < points.length; i++) {
|
|
46
|
+
const p = points[i] as RefLabelPoint
|
|
47
|
+
if (p.fx >= fx0 && p.fx <= fx1) take(p.y)
|
|
48
|
+
const next = points[i + 1]
|
|
49
|
+
if (next === undefined || (p.fx < fx0 && next.fx < fx0) || (p.fx > fx1 && next.fx > fx1))
|
|
50
|
+
continue
|
|
51
|
+
// A segment entering or leaving the window contributes where it crosses its edge.
|
|
52
|
+
for (const edge of [fx0, fx1]) {
|
|
53
|
+
if ((p.fx < edge && next.fx > edge) || (p.fx > edge && next.fx < edge))
|
|
54
|
+
take(at(p.fx < next.fx ? p : next, p.fx < next.fx ? next : p, edge))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return lo <= hi ? [lo, hi] : null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function refLabelPosition(opts: {
|
|
61
|
+
/** `RefLine.labelPosition`: wins over everything. */
|
|
62
|
+
pinned: RefLabelPosition | undefined
|
|
63
|
+
/** The default end when nothing constrains it: `true` for a right-axis line. */
|
|
64
|
+
startFirst: boolean
|
|
65
|
+
value: number
|
|
66
|
+
domain: readonly [number, number]
|
|
67
|
+
plotWidth: number
|
|
68
|
+
plotHeight: number
|
|
69
|
+
label: string
|
|
70
|
+
fontSize: number
|
|
71
|
+
/** One polyline per visible series on the line's axis. */
|
|
72
|
+
series: readonly (readonly RefLabelPoint[])[]
|
|
73
|
+
}): RefLabelPosition {
|
|
74
|
+
const { pinned, startFirst, value, plotWidth, plotHeight, label, fontSize, series } = opts
|
|
75
|
+
const order = startFirst ? ORDER_START : ORDER_END
|
|
76
|
+
if (pinned !== undefined) return pinned
|
|
77
|
+
const [lo, hi] = [Math.min(...opts.domain), Math.max(...opts.domain)]
|
|
78
|
+
if (hi === lo || plotWidth <= 0 || plotHeight <= 0) return order[0] as RefLabelPosition
|
|
79
|
+
const perPx = (hi - lo) / plotHeight
|
|
80
|
+
const widthFx = (label.length * fontSize * GLYPH_EM + EDGE_INSET) / plotWidth
|
|
81
|
+
const heightPx = fontSize + 2
|
|
82
|
+
const bandOf = (position: RefLabelPosition): [number, number] =>
|
|
83
|
+
position.endsWith('above')
|
|
84
|
+
? [value + LINE_GAP * perPx, value + (LINE_GAP + heightPx) * perPx]
|
|
85
|
+
: [value - (LINE_GAP + heightPx) * perPx, value - LINE_GAP * perPx]
|
|
86
|
+
const inPlot = (position: RefLabelPosition): boolean => {
|
|
87
|
+
const [from, to] = bandOf(position)
|
|
88
|
+
return from >= lo && to <= hi
|
|
89
|
+
}
|
|
90
|
+
const clear = (position: RefLabelPosition): boolean => {
|
|
91
|
+
const [from, to] = bandOf(position)
|
|
92
|
+
const [fx0, fx1] = position.startsWith('end')
|
|
93
|
+
? [1 - widthFx, 1 - EDGE_INSET / plotWidth]
|
|
94
|
+
: [EDGE_INSET / plotWidth, widthFx]
|
|
95
|
+
return series.every((points) => {
|
|
96
|
+
const range = yRangeWithin(points, fx0, fx1)
|
|
97
|
+
return range === null || range[1] < from || range[0] > to
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
// A caption that cannot avoid the data still stays inside the plot.
|
|
101
|
+
return (
|
|
102
|
+
order.find((p) => inPlot(p) && clear(p)) ?? order.find(inPlot) ?? (order[0] as RefLabelPosition)
|
|
103
|
+
)
|
|
104
|
+
}
|
package/src/charts/scales.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
8
8
|
import { scaleLinear } from '@tanstack/charts/scales/linear'
|
|
9
9
|
import { scalePoint } from '@tanstack/charts/scales/point'
|
|
10
|
-
import { scaleLog, scaleUtc } from 'd3-scale'
|
|
10
|
+
import { scaleLinear as d3Linear, scaleLog, scaleUtc } from 'd3-scale'
|
|
11
11
|
import type { ChartPositionScaleOptions } from '@tanstack/charts/types/core'
|
|
12
12
|
import type { AxisConfig, ChartSeries, ChartX, XZoneSpec } from './types'
|
|
13
13
|
|
|
@@ -25,6 +25,23 @@ export function padAutoUpper(candidate: number, pad: number): number {
|
|
|
25
25
|
return candidate > 0 ? candidate * pad : candidate / pad
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Raises `upper` until the axis' top tick (for `count` ticks over `[lower, upper]`) reaches `max`:
|
|
30
|
+
* a padded domain can end between ticks, so the line peaks above the last label. Each step adds
|
|
31
|
+
* one tick interval, so the loop ends within a few turns.
|
|
32
|
+
*/
|
|
33
|
+
function coverTop(lower: number, upper: number, max: number, count: number): number {
|
|
34
|
+
let top = upper
|
|
35
|
+
for (let i = 0; i < 4; i++) {
|
|
36
|
+
const ticks = d3Linear().domain([lower, top]).ticks(count)
|
|
37
|
+
const last = ticks.at(-1)
|
|
38
|
+
const step = ticks.length > 1 ? (ticks[1] as number) - (ticks[0] as number) : 0
|
|
39
|
+
if (last === undefined || step <= 0 || last >= max) return top
|
|
40
|
+
top = last + step
|
|
41
|
+
}
|
|
42
|
+
return top
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
/**
|
|
29
46
|
* One y axis' domain. `extraBounds` are the finite zone and reference-line values pinned to this
|
|
30
47
|
* axis — a target past the data must stay inside the plot. Infinite bounds clamp to the domain by
|
|
@@ -35,6 +52,9 @@ export function resolveYDomain<T>(
|
|
|
35
52
|
data: readonly T[],
|
|
36
53
|
series: readonly ChartSeries<T>[],
|
|
37
54
|
extraBounds: readonly number[] = [],
|
|
55
|
+
/** The number of ticks the axis will draw (0: none, or its own tick values): when set, an AUTO
|
|
56
|
+
* domain ends on a tick at or above the data's maximum. */
|
|
57
|
+
tickCount = 0,
|
|
38
58
|
): readonly [number, number] {
|
|
39
59
|
const domain = cfg?.domain ?? 'auto'
|
|
40
60
|
if (Array.isArray(domain)) return domain as readonly [number, number]
|
|
@@ -67,7 +87,7 @@ export function resolveYDomain<T>(
|
|
|
67
87
|
const lower = padAutoLower(Math.min(min, cfg?.autoMinCeil ?? 0), pad)
|
|
68
88
|
// A flat series would be a scale with no extent: every point on one pixel.
|
|
69
89
|
if (lower === upper) return [Math.min(lower, 0), upper === 0 ? 1 : upper * pad]
|
|
70
|
-
return [lower, upper]
|
|
90
|
+
return [lower, tickCount > 0 && !cfg?.nice ? coverTop(lower, upper, max, tickCount) : upper]
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
/** A configured y scale instance for a resolved domain. */
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* a mark: the plot is the whole box, and a chip inside it would have to hide some series (a line's
|
|
5
5
|
* last segment, a bar, the end dot) wherever it landed. Above is always free inside a card or strip
|
|
6
6
|
* cell (the hero value or caption is what sits there), and the chip is opaque so it reads over it.
|
|
7
|
-
* It
|
|
7
|
+
* It rides the hovered point: its left edge is the point's fraction, shifted back by that same
|
|
8
|
+
* fraction of its own width, so it is centred on a mid point and flush with the box at either end.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
.root {
|
|
@@ -13,7 +14,9 @@
|
|
|
13
14
|
|
|
14
15
|
.readout {
|
|
15
16
|
position: absolute;
|
|
16
|
-
|
|
17
|
+
/* The layer is inset from the root by the line's plot margin; lifting by it puts the chip back
|
|
18
|
+
* on the root's top edge, the line a host slot reserves. */
|
|
19
|
+
bottom: calc(100% + var(--basalt-spark-lift, 0px));
|
|
17
20
|
z-index: 1;
|
|
18
21
|
max-width: 100%;
|
|
19
22
|
box-sizing: border-box;
|
|
@@ -35,19 +38,15 @@
|
|
|
35
38
|
border-radius: var(--vx-radius-ctrl);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
.start {
|
|
39
|
-
left: 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.end {
|
|
43
|
-
right: 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
41
|
.label {
|
|
47
|
-
font-family: var(--basalt-font-mono);
|
|
48
42
|
opacity: 0.7;
|
|
49
43
|
}
|
|
50
44
|
|
|
45
|
+
.layer {
|
|
46
|
+
position: absolute;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
}
|
|
49
|
+
|
|
51
50
|
.dot {
|
|
52
51
|
position: absolute;
|
|
53
52
|
width: 6px;
|
package/src/charts/state.tsx
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { CSSProperties, ReactElement, ReactNode } from 'react'
|
|
6
6
|
import { toErrorMessage } from '../common/errors'
|
|
7
|
+
import { RetryButton } from '../common/retry-button'
|
|
7
8
|
import { VX } from '../tokens'
|
|
8
9
|
import { ChartBox, growClass, stateClass } from './box'
|
|
9
10
|
import type { ChartBoxHeight } from './box'
|
|
@@ -74,10 +75,17 @@ const emptyLabel = (state: ChartState | undefined): string =>
|
|
|
74
75
|
export function ChartPlaceholder(props: {
|
|
75
76
|
state: ChartState | undefined
|
|
76
77
|
height?: ChartBoxHeight
|
|
78
|
+
/** Error only: the shared Retry button, the same one `ErrorState` renders. */
|
|
79
|
+
onRetry?: () => void
|
|
80
|
+
/** A refetch is in flight: Retry is inert and marked busy. */
|
|
81
|
+
retrying?: boolean
|
|
82
|
+
/** Any other action (a "clear filters" link), after Retry. */
|
|
77
83
|
action?: ReactNode
|
|
78
84
|
/** For a box too small to hold a sentence (a sparkline): error and empty show a `—` and carry the
|
|
79
85
|
* label as the accessible name and the hover title. */
|
|
80
86
|
compact?: boolean
|
|
87
|
+
/** Error only: what failed to load, "Could not load {noun}". Default: no noun. */
|
|
88
|
+
noun?: string
|
|
81
89
|
}): ReactElement | null {
|
|
82
90
|
const kind = resolveChartState(props.state)
|
|
83
91
|
if (kind === null) return null
|
|
@@ -104,10 +112,13 @@ export function ChartPlaceholder(props: {
|
|
|
104
112
|
{kind === 'error' && (
|
|
105
113
|
<span style={errorHeadStyle}>
|
|
106
114
|
<span aria-hidden="true" data-basalt-status-dot="" style={dotStyle} />
|
|
107
|
-
Could not load
|
|
115
|
+
Could not load{props.noun === undefined ? '' : ` ${props.noun}`}
|
|
108
116
|
</span>
|
|
109
117
|
)}
|
|
110
118
|
<span style={errorMessageStyle}>{label}</span>
|
|
119
|
+
{kind === 'error' && props.onRetry !== undefined && (
|
|
120
|
+
<RetryButton onClick={props.onRetry} retrying={props.retrying ?? false} />
|
|
121
|
+
)}
|
|
111
122
|
{props.action}
|
|
112
123
|
</>
|
|
113
124
|
)
|
package/src/charts/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { StoredChartSpec } from '@tanstack/charts/types/core'
|
|
|
6
6
|
import type { BasaltProps } from '../common/props'
|
|
7
7
|
import type { ContainerClass } from '../tokens/size-classes'
|
|
8
8
|
import type { CurveName } from './curves'
|
|
9
|
+
import type { RefLabelPosition } from './ref-label'
|
|
9
10
|
|
|
10
11
|
/** What `x` may return. The value type picks the x scale (§ 9.4): `Date` → time, `number` → linear,
|
|
11
12
|
* `string` → point (lines) or band (bars). */
|
|
@@ -27,8 +28,10 @@ export type ChartSeries<T> = {
|
|
|
27
28
|
mark?: 'line' | 'bar' | 'area' | undefined
|
|
28
29
|
/** Default `'solid'`; `'dashed'` is `VX.dashArray` on the line, the legend and the tooltip. */
|
|
29
30
|
dash?: 'solid' | 'dashed' | undefined
|
|
30
|
-
/** Interpolation between points. Default `'
|
|
31
|
-
*
|
|
31
|
+
/** Interpolation between points. Default `'linear'`: discrete values (a daily total, a monthly
|
|
32
|
+
* rate) are joined by straight segments, never by a smoothed curve with crossings between points
|
|
33
|
+
* that never happened. `'monotone'` is an opt-in for a continuous measure; a piecewise-constant
|
|
34
|
+
* quantity (a price tier, a config value) is a step. */
|
|
32
35
|
curve?: CurveName | undefined
|
|
33
36
|
strokeWidth?: number | undefined
|
|
34
37
|
/**
|
|
@@ -155,11 +158,17 @@ export type RefLine = {
|
|
|
155
158
|
dashed?: boolean | undefined
|
|
156
159
|
axis?: 'left' | 'right' | undefined
|
|
157
160
|
/**
|
|
158
|
-
* Names the line on the plot: a small muted caption
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
+
* Names the line on the plot: a small muted caption on one of four spots (the plot's end or
|
|
162
|
+
* start, above or below the line). It follows the legend toggle. The ink is `--vx-ink2`, never
|
|
163
|
+
* the line colour.
|
|
161
164
|
*/
|
|
162
165
|
label?: string | undefined
|
|
166
|
+
/**
|
|
167
|
+
* Pins the caption's spot. Default: the first spot (the plot's right end above the line; the left
|
|
168
|
+
* end for a right-axis line) that stays inside the plot and that no data line runs through, so a
|
|
169
|
+
* line in the top or bottom quarter, or one a series ends on, moves its caption.
|
|
170
|
+
*/
|
|
171
|
+
labelPosition?: RefLabelPosition | undefined
|
|
163
172
|
/**
|
|
164
173
|
* Names the line in the legend (its color, dashed as `dashed`; a toggle hides the line), so a
|
|
165
174
|
* threshold needs no always-`null` series. `mark` is the swatch shape. Default `'line'`. The
|
package/src/cli/check-theme.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
unmatchedExemptPatterns,
|
|
15
15
|
} from '../guard'
|
|
16
16
|
import type { Finding } from '../guard'
|
|
17
|
+
import { checkSeriesModule } from '../guard/series-file'
|
|
17
18
|
import { auditAllows } from './audit-allows'
|
|
18
19
|
import { DEFAULT_ROOTS, resolveRoots } from './config'
|
|
19
20
|
import {
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
resolveGuardConfig,
|
|
35
36
|
resolveProjectDir,
|
|
36
37
|
scannableFiles,
|
|
38
|
+
defaultExempt,
|
|
37
39
|
SERIES_MODULE_HINT_RE,
|
|
38
40
|
waiverHintFor,
|
|
39
41
|
} from './index'
|
|
@@ -116,6 +118,7 @@ export function checkTheme(
|
|
|
116
118
|
findings.push(...checkSource(readFileSync(resolve(cwd, rel), 'utf8'), rel, guardCfg))
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
findings.push(...checkSeriesModule(cwd, defaultExempt(cfg)[0] ?? '', guardCfg)) // the exempt series file: palette checks
|
|
119
122
|
if (scanned.length === 0) {
|
|
120
123
|
// A configured-but-wrong root is never intentional, and silently scanning 0 files under the
|
|
121
124
|
// built-in defaults (argo's pre-migration layout) is the same failure mode for every other
|
|
@@ -370,7 +370,7 @@ export function seedTsconfigExtends(cwd: string): string | null {
|
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
const SEED_HINT = 'node_modules/basalt-ui/agent/templates/main.tpl'
|
|
373
|
-
const ROUTER_PLUGIN_FIX =
|
|
373
|
+
export const ROUTER_PLUGIN_FIX =
|
|
374
374
|
"Fix: `bun add -D @tanstack/router-plugin`, add `tanstackRouter({ target: 'react', autoCodeSplitting: true })` " +
|
|
375
375
|
"from '@tanstack/router-plugin/vite' to `plugins` in vite.config.ts (before react()), then run vite once " +
|
|
376
376
|
'to generate src/routeTree.gen.ts — or define the tree in code (`createRootRoute` + `createRoute`), drop the routeTree.gen import and pass the tree to createBasaltRouter.'
|
package/src/cli/help.ts
CHANGED
|
@@ -57,6 +57,7 @@ export const COMMAND_OPTIONS: Record<
|
|
|
57
57
|
wait: { type: 'string' },
|
|
58
58
|
'auto-anchors': { type: 'boolean' },
|
|
59
59
|
'api-allow-writes': { type: 'boolean' },
|
|
60
|
+
lint: { type: 'string' },
|
|
60
61
|
},
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -81,7 +82,7 @@ export const USAGE =
|
|
|
81
82
|
' sync [--force] [--check] [--verbose] [--tokens-only|--framework] |\n' +
|
|
82
83
|
' check-theme [--audit-allows] |\n' +
|
|
83
84
|
' doctor [--tokens-only|--framework] | guard-hook | tokens:css | fonts:css |\n' +
|
|
84
|
-
' shot <route…> | help>\n\n' +
|
|
85
|
+
' shot <route…> | shot detect | help>\n\n' +
|
|
85
86
|
'check-theme [--tokens-only|--framework] [--audit-allows]\n' +
|
|
86
87
|
' --audit-allows reports instead of scanning: every `theme-allow` annotation and every\n' +
|
|
87
88
|
' `basalt.exemptRules` entry, with what each one still suppresses — proved by re-running the\n' +
|
|
@@ -113,6 +114,22 @@ export const USAGE =
|
|
|
113
114
|
" app holds other people's data. Example:\n" +
|
|
114
115
|
' basalt-ui shot /overview --dist dist --api /api=https://app.example.com \\\n' +
|
|
115
116
|
' --local-storage auth-token=@env:APP_TOKEN --header authorization=@env:APP_BEARER --auto-anchors\n\n' +
|
|
117
|
+
'shot detect [--out <dir>] [--lint <oxlint-json-file>]\n' +
|
|
118
|
+
' The deterministic second review pass, no browser and no model: reads <out>/metrics.json (default: the\n' +
|
|
119
|
+
' out dir in .basalt/shots/last.json) and, with --lint, the basalt/* diagnostics of `oxlint --format json`\n' +
|
|
120
|
+
' output saved to a file. Writes <out>/detect.json and a findings table, content, then layout, then style:\n' +
|
|
121
|
+
' off-scale inset/gap/radius, nested radius step under 3 px, more than 3 font sizes, an empty region of\n' +
|
|
122
|
+
' 40 % or more, contrast failures, error shots, a missing scale or no anchors.\n' +
|
|
123
|
+
' Exit codes: 0 clean (P2/P3 findings are listed, not failing), 2 a P0 or P1 finding, 1 scan failure (missing\n' +
|
|
124
|
+
' or unreadable metrics.json or lint file, or detect.json/history.json cannot be written).\n' +
|
|
125
|
+
' P0 fails: broken, unreadable or a contrast failure; an error shot; no anchors\n' +
|
|
126
|
+
' P1 fails: a rubric item fails (off-scale value, font sizes, empty region, nested radius, lint error)\n' +
|
|
127
|
+
' P2 noted, not failing: degraded: a lint warning, a contrast measured on an assumed white backdrop\n' +
|
|
128
|
+
' P3 noted, not failing: polish: an off-scale value within 1 px of a step\n' +
|
|
129
|
+
' score = 100 - (25 per P0 + 10 per P1 + 3 per P2 + 1 per P3), floored at 0. Each run appends\n' +
|
|
130
|
+
' {at, out, commit, counts, score} to .basalt/shots/history.json and prints the last 5 scores as a trend.\n' +
|
|
131
|
+
' A component can declare a rest anchor absent in a URL state with data-shot-absent="empty error": that\n' +
|
|
132
|
+
' cell is recorded `absent`, not `error`.\n\n' +
|
|
116
133
|
'doctor [--tokens-only|--framework]\n' +
|
|
117
134
|
' Checks THIS project only: the manifest exists, the oxlint preset is wired, the pre-commit\n' +
|
|
118
135
|
' hook runs check-theme (via `lefthook dump`), and the ai package major is consistent within\n' +
|