basalt-ui 2.28.0 → 2.29.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 +461 -401
- package/MIGRATING.md +202 -12
- package/agent/skills/basalt-app/SKILL.md +3 -3
- package/agent/skills/basalt-charts/SKILL.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +11 -5
- package/agent/skills/basalt-design/references/catalogue.md +3 -1
- package/agent/skills/basalt-design/references/recipes.md +1 -1
- package/agent/skills/basalt-design/references/states.md +1 -1
- package/configs/oxlint-plugin.js +2 -1
- package/configs/oxlint.json +1 -0
- package/dist/charts/ChartCard.d.ts +9 -5
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +68 -12
- package/dist/charts/Sparkline.d.ts +5 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +53 -5
- package/dist/charts/chart-box.module.css +9 -2
- package/dist/charts/chart-card.module.css +16 -13
- package/dist/charts/chart-card.module.css.d.ts +2 -0
- package/dist/charts/compile.d.ts +1 -1
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +18 -9
- package/dist/charts/ref-label.d.ts +6 -0
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +19 -5
- package/dist/charts/sparkline.module.css +44 -0
- package/dist/charts/sparkline.module.css.d.ts +3 -0
- package/dist/charts/state.d.ts +1 -1
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +3 -3
- package/dist/cli/doctor-upgrade.d.ts +11 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +54 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +32 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -3
- package/dist/cli/index.d.ts +13 -13
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +36 -2
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +118 -27
- package/dist/cli/router-wiring.d.ts +3 -0
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/shot/capture.d.ts +28 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +77 -7
- package/dist/cli/shot/detect.d.ts +4 -1
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +38 -16
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +9 -2
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +11 -2
- package/dist/cli/shot/types.d.ts +4 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +10 -2
- package/dist/common/could-not-load.d.ts +13 -0
- package/dist/common/could-not-load.d.ts.map +1 -0
- package/dist/common/could-not-load.js +14 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +3 -0
- package/dist/common/props.d.ts +20 -0
- package/dist/common/props.d.ts.map +1 -1
- package/dist/common/props.js +13 -1
- package/dist/common/retry-button.module.css +7 -3
- package/dist/dashboard/bar-list.d.ts +4 -4
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +10 -7
- package/dist/dashboard/bar-list.module.css +21 -3
- package/dist/dashboard/board.d.ts +2 -2
- package/dist/dashboard/board.d.ts.map +1 -1
- package/dist/dashboard/board.js +31 -12
- package/dist/dashboard/board.module.css +19 -0
- package/dist/dashboard/board.module.css.d.ts +2 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +4 -2
- package/dist/dashboard/event-list-model.d.ts +3 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -1
- package/dist/dashboard/event-list-model.js +5 -1
- package/dist/dashboard/event-list-rows.d.ts.map +1 -1
- package/dist/dashboard/event-list-rows.js +2 -6
- package/dist/dashboard/event-list-scroll.d.ts +32 -4
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -1
- package/dist/dashboard/event-list-scroll.js +117 -4
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -1
- package/dist/dashboard/event-list-skeleton.js +2 -4
- package/dist/dashboard/event-list.d.ts +4 -4
- package/dist/dashboard/event-list.d.ts.map +1 -1
- package/dist/dashboard/event-list.js +53 -23
- package/dist/dashboard/event-list.module.css +90 -37
- package/dist/dashboard/event-list.module.css.d.ts +1 -0
- package/dist/dashboard/meter-model.d.ts +6 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +9 -4
- package/dist/dashboard/meter-parts.d.ts +3 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +32 -4
- package/dist/dashboard/meter.d.ts +3 -3
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +10 -2
- package/dist/dashboard/meter.module.css +18 -11
- package/dist/dashboard/meter.module.css.d.ts +0 -1
- package/dist/dashboard/page-summary.d.ts +3 -3
- package/dist/dashboard/page-summary.d.ts.map +1 -1
- package/dist/dashboard/page-summary.js +7 -2
- package/dist/dashboard/page-summary.module.css +5 -2
- package/dist/dashboard/query-state.d.ts +9 -8
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +28 -10
- package/dist/dashboard/section.d.ts +11 -3
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +34 -7
- package/dist/dashboard/settings-section.d.ts +4 -4
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +11 -7
- package/dist/dashboard/settings-section.module.css +6 -0
- package/dist/dashboard/settings-section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card.d.ts +3 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +24 -8
- package/dist/dashboard/stat-card.module.css +11 -0
- package/dist/dashboard/stat-group.d.ts +2 -2
- package/dist/dashboard/stat-group.d.ts.map +1 -1
- package/dist/dashboard/stat-group.js +10 -3
- package/dist/dashboard/stat-strip.d.ts +5 -4
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +41 -31
- package/dist/dashboard/stat-strip.module.css +4 -5
- package/dist/dashboard/visual-slot.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +2 -0
- package/dist/dashboard/widget-header.d.ts +6 -6
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +4 -2
- package/dist/dashboard/widget-header.module.css +6 -25
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +24 -1
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -1
- package/dist/styles.css +23 -0
- package/dist/table/cell-kinds.d.ts +10 -7
- package/dist/table/cell-kinds.d.ts.map +1 -1
- package/dist/table/cell-kinds.js +18 -7
- package/dist/table/data-table-fold.d.ts +13 -5
- package/dist/table/data-table-fold.d.ts.map +1 -1
- package/dist/table/data-table-fold.js +48 -16
- package/dist/table/data-table.d.ts +2 -2
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +16 -9
- package/dist/table/data-table.module.css +74 -2
- package/dist/table/data-table.module.css.d.ts +4 -0
- package/dist/theme/controls.module.css +23 -2
- package/llms.txt +263 -2
- package/package.json +1 -1
- package/src/charts/ChartCard.tsx +98 -16
- package/src/charts/Sparkline.tsx +84 -5
- package/src/charts/chart-box.module.css +9 -2
- package/src/charts/chart-card.module.css +16 -13
- package/src/charts/chart-card.module.css.d.ts +2 -0
- package/src/charts/compile.ts +37 -15
- package/src/charts/ref-label.ts +36 -9
- package/src/charts/sparkline.module.css +44 -0
- package/src/charts/sparkline.module.css.d.ts +3 -0
- package/src/charts/state.tsx +4 -3
- package/src/cli/doctor-upgrade.ts +75 -0
- package/src/cli/doctor.ts +36 -0
- package/src/cli/help.ts +16 -6
- package/src/cli/index.ts +73 -67
- package/src/cli/init.ts +157 -36
- package/src/cli/router-wiring.ts +2 -2
- package/src/cli/shot/capture.ts +109 -10
- package/src/cli/shot/detect.ts +46 -22
- package/src/cli/shot/index.ts +8 -2
- package/src/cli/shot/measure.ts +11 -2
- package/src/cli/shot/types.ts +4 -1
- package/src/cli/sync.ts +12 -2
- package/src/common/could-not-load.ts +22 -0
- package/src/common/index.ts +1 -0
- package/src/common/props.ts +30 -0
- package/src/common/retry-button.module.css +7 -3
- package/src/dashboard/bar-list.module.css +21 -3
- package/src/dashboard/bar-list.tsx +46 -41
- package/src/dashboard/board.module.css +19 -0
- package/src/dashboard/board.module.css.d.ts +2 -0
- package/src/dashboard/board.tsx +69 -48
- package/src/dashboard/empty-state.tsx +5 -2
- package/src/dashboard/event-list-model.ts +13 -1
- package/src/dashboard/event-list-rows.tsx +3 -6
- package/src/dashboard/event-list-scroll.ts +154 -8
- package/src/dashboard/event-list-skeleton.tsx +5 -1
- package/src/dashboard/event-list.module.css +90 -37
- package/src/dashboard/event-list.module.css.d.ts +1 -0
- package/src/dashboard/event-list.tsx +92 -65
- package/src/dashboard/meter-model.ts +16 -7
- package/src/dashboard/meter-parts.tsx +45 -13
- package/src/dashboard/meter.module.css +18 -11
- package/src/dashboard/meter.module.css.d.ts +0 -1
- package/src/dashboard/meter.tsx +36 -18
- package/src/dashboard/page-summary.module.css +5 -2
- package/src/dashboard/page-summary.tsx +13 -6
- package/src/dashboard/query-state.tsx +54 -29
- package/src/dashboard/section.tsx +83 -41
- package/src/dashboard/settings-section.module.css +6 -0
- package/src/dashboard/settings-section.module.css.d.ts +1 -0
- package/src/dashboard/settings-section.tsx +11 -6
- package/src/dashboard/stat-card.module.css +11 -0
- package/src/dashboard/stat-card.tsx +31 -8
- package/src/dashboard/stat-group.tsx +22 -14
- package/src/dashboard/stat-strip.module.css +4 -5
- package/src/dashboard/stat-strip.tsx +29 -20
- package/src/dashboard/visual-slot.ts +5 -0
- package/src/dashboard/widget-header.module.css +6 -25
- package/src/dashboard/widget-header.tsx +8 -5
- package/src/format/shared.ts +30 -1
- package/src/guard/index.ts +5 -1
- package/src/styles.css +23 -0
- package/src/table/cell-kinds.tsx +42 -13
- package/src/table/data-table-fold.tsx +65 -12
- package/src/table/data-table.module.css +74 -2
- package/src/table/data-table.module.css.d.ts +4 -0
- package/src/table/data-table.tsx +34 -13
- package/src/theme/controls.module.css +23 -2
package/src/charts/Sparkline.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import type { CartesianDefinition } from './compile'
|
|
|
22
22
|
import { chartCurve } from './curves'
|
|
23
23
|
import { barMark } from './marks'
|
|
24
24
|
import { VisualSlotContext } from '../dashboard/visual-slot'
|
|
25
|
+
import type { VisualSlot } from '../dashboard/visual-slot'
|
|
25
26
|
import { bucketDay, dayGranular, defaultNumberFormat } from './compile'
|
|
26
27
|
import { referenceLabelPlacement } from './ref-label'
|
|
27
28
|
import { readoutClock, readoutDay } from './chart-dates'
|
|
@@ -73,6 +74,11 @@ export type SparklineProps = BasaltProps & {
|
|
|
73
74
|
* and the readout reads `3 items · 12 Oct` beside the point. Omitted: the moment of an `{ at }`
|
|
74
75
|
* point, else the value alone. */
|
|
75
76
|
labels?: readonly string[] | undefined
|
|
77
|
+
/** The span the series covers, stated quietly under the plot (`12 wk`). Default inside a `StatCard`
|
|
78
|
+
* or strip cell: the first and last of `labels`, or of an `{ at }` series' days (`3 Aug – 19 Oct`; an hourly series states none);
|
|
79
|
+
* plain values state none. `false` or a blank string states none. With a `referenceLabel`, a stated window also takes
|
|
80
|
+
* that label out of the plot into the same row, where no line can run through it. */
|
|
81
|
+
window?: string | false | undefined
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
type Point = { i: number; v: number | null }
|
|
@@ -137,6 +143,44 @@ function momentsOf(data: SparklineProps['data']): readonly (string | undefined)[
|
|
|
137
143
|
})
|
|
138
144
|
}
|
|
139
145
|
|
|
146
|
+
/** Whether `{ at }` points are a day or more apart: the span of an hourly series is the host's to state. */
|
|
147
|
+
function isDayWindow(data: SparklineProps['data']): boolean {
|
|
148
|
+
const known: Date[] = []
|
|
149
|
+
for (const d of data) {
|
|
150
|
+
const at = typeof d === 'object' && d !== null ? toDate(d.at) : null
|
|
151
|
+
if (at !== null) known.push(at)
|
|
152
|
+
}
|
|
153
|
+
return known.length > 0 && dayGranular(known)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** `first – last` of a series' day labels, or `undefined` when there are fewer than two distinct ones. */
|
|
157
|
+
function spanOf(names: readonly (string | undefined)[] | undefined): string | undefined {
|
|
158
|
+
const first = names?.find((n) => n !== undefined)
|
|
159
|
+
const last = names?.findLast((n) => n !== undefined)
|
|
160
|
+
return first === undefined || last === undefined || first === last
|
|
161
|
+
? undefined
|
|
162
|
+
: `${first} – ${last}`
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The window caption under a hosted plot, or `undefined`. A stated `window` wins (blank or `false`:
|
|
167
|
+
* none); otherwise a host with room for it (not `compact`) gets `first – last` of the `labels`, or of a
|
|
168
|
+
* day-dated series' days.
|
|
169
|
+
*/
|
|
170
|
+
function windowCaption(opts: {
|
|
171
|
+
prop: string | false | undefined
|
|
172
|
+
slot: VisualSlot | null
|
|
173
|
+
data: SparklineProps['data']
|
|
174
|
+
labels: readonly string[] | undefined
|
|
175
|
+
moments: readonly (string | undefined)[] | undefined
|
|
176
|
+
}): string | undefined {
|
|
177
|
+
const { prop, slot, data, labels, moments } = opts
|
|
178
|
+
if (prop === false) return undefined
|
|
179
|
+
if (prop !== undefined) return prop.trim() === '' ? undefined : prop.trim()
|
|
180
|
+
if (slot === null || slot.compact === true) return undefined
|
|
181
|
+
return spanOf(labels ?? (isDayWindow(data) ? moments : undefined))
|
|
182
|
+
}
|
|
183
|
+
|
|
140
184
|
/** Min and max of the finite values, by loop (a spread overflows the stack on long series). */
|
|
141
185
|
function extent(rows: readonly Point[]): readonly [number, number] | null {
|
|
142
186
|
let lo = Number.POSITIVE_INFINITY
|
|
@@ -635,11 +679,21 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
635
679
|
band,
|
|
636
680
|
format = defaultNumberFormat,
|
|
637
681
|
labels,
|
|
682
|
+
window: windowProp,
|
|
638
683
|
className,
|
|
639
684
|
style,
|
|
640
685
|
} = props
|
|
641
686
|
const id = useId()
|
|
642
|
-
const
|
|
687
|
+
const slot = useContext(VisualSlotContext)
|
|
688
|
+
const hosted = slot !== null
|
|
689
|
+
const moments = useMemo(() => momentsOf(data), [data])
|
|
690
|
+
const windowText = useMemo(
|
|
691
|
+
() => windowCaption({ prop: windowProp, slot, data, labels, moments }),
|
|
692
|
+
[windowProp, slot, data, labels, moments],
|
|
693
|
+
)
|
|
694
|
+
// The window's row also holds the reference label: out of the plot, no line can run through it.
|
|
695
|
+
const labelInRow = windowText !== undefined && referenceLabel !== undefined
|
|
696
|
+
const plotLabel = labelInRow ? undefined : referenceLabel
|
|
643
697
|
// Two sources, so a pointer leaving a focused chart hands the readout back to the focused point.
|
|
644
698
|
const [hover, setHover] = useState<number | null>(null)
|
|
645
699
|
const [keyed, setKeyed] = useState<number | null>(null)
|
|
@@ -677,7 +731,7 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
677
731
|
const bandEdges = full[0] < range[0] || full[1] > range[1]
|
|
678
732
|
return {
|
|
679
733
|
rows,
|
|
680
|
-
moments
|
|
734
|
+
moments,
|
|
681
735
|
frame: frameOf(full, mark, rows.length, end !== null, bandSpan !== null && bandEdges),
|
|
682
736
|
definition: compileSparkline(
|
|
683
737
|
rows,
|
|
@@ -686,12 +740,23 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
686
740
|
color,
|
|
687
741
|
end,
|
|
688
742
|
ref,
|
|
689
|
-
|
|
743
|
+
plotLabel,
|
|
690
744
|
bandSpan,
|
|
691
745
|
bandSpan !== null && bandEdges,
|
|
692
746
|
),
|
|
693
747
|
}
|
|
694
|
-
}, [
|
|
748
|
+
}, [
|
|
749
|
+
data,
|
|
750
|
+
moments,
|
|
751
|
+
mark,
|
|
752
|
+
color,
|
|
753
|
+
emphasizeLast,
|
|
754
|
+
emphasisColor,
|
|
755
|
+
reference,
|
|
756
|
+
plotLabel,
|
|
757
|
+
bandFrom,
|
|
758
|
+
bandTo,
|
|
759
|
+
])
|
|
695
760
|
const resolved = resolveChartState(state)
|
|
696
761
|
const rows = model?.rows
|
|
697
762
|
const interactive = resolved === null && model !== null
|
|
@@ -810,7 +875,7 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
810
875
|
}),
|
|
811
876
|
...(at.fy > 0.5 ? { top: 0 } : { bottom: 0 }),
|
|
812
877
|
}
|
|
813
|
-
|
|
878
|
+
const plot = (
|
|
814
879
|
<div
|
|
815
880
|
data-basalt-sparkline=""
|
|
816
881
|
{...(hosted && { 'data-basalt-hosted': '' })}
|
|
@@ -875,4 +940,18 @@ export function Sparkline(props: SparklineProps): ReactElement {
|
|
|
875
940
|
)}
|
|
876
941
|
</div>
|
|
877
942
|
)
|
|
943
|
+
if (windowText === undefined) return plot
|
|
944
|
+
return (
|
|
945
|
+
<div className={classes.frame} style={{ width: width ?? '100%' }}>
|
|
946
|
+
{plot}
|
|
947
|
+
<div className={classes.caption} data-basalt-sparkline-caption="">
|
|
948
|
+
<span data-basalt-sparkline-window="">{windowText}</span>
|
|
949
|
+
{labelInRow && (
|
|
950
|
+
<span className={classes.key} data-basalt-sparkline-key="">
|
|
951
|
+
{referenceLabel}
|
|
952
|
+
</span>
|
|
953
|
+
)}
|
|
954
|
+
</div>
|
|
955
|
+
</div>
|
|
956
|
+
)
|
|
878
957
|
}
|
|
@@ -219,9 +219,16 @@
|
|
|
219
219
|
|
|
220
220
|
/* The engine focuses the plot's `svg.ts-chart` (tabindex 0), not the `.basalt-chart` wrapper
|
|
221
221
|
* `styles.css` rings, so the UA's `auto` ring paints (a 5px white double ring in dark): the same
|
|
222
|
-
* 2px accent ring
|
|
222
|
+
* 2px accent ring. The ring is INSET: an outer one is clipped by the card body's overflow at the
|
|
223
|
+
* plot's right and bottom edges (partial edges), an inset one is whole wherever the chart sits. */
|
|
223
224
|
:global(.basalt-chart .ts-chart:focus-visible) {
|
|
224
225
|
outline: 2px solid var(--vx-accent);
|
|
226
|
+
outline-offset: calc(-0.125rem * var(--mantine-scale));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* A Sparkline keeps the outer ring: its cell reserves the clearance (the readout chip and the end
|
|
230
|
+
* marker are placed against it) and an inset ring would cross the end marker. */
|
|
231
|
+
:global([data-basalt-sparkline] .basalt-chart .ts-chart:focus-visible) {
|
|
225
232
|
outline-offset: calc(0.125rem * var(--mantine-scale));
|
|
226
233
|
}
|
|
227
234
|
|
|
@@ -238,7 +245,7 @@
|
|
|
238
245
|
box-sizing: border-box;
|
|
239
246
|
width: max-content;
|
|
240
247
|
/* The line the cell reserves (1.125rem) less the focus ring's clearance (2px outline + 0.125rem offset) and 1px of air, so
|
|
241
|
-
* the chip sits clear of the ring and still inside the reserve. */
|
|
248
|
+
* the chip sits clear of the ring and still inside the reserve. The Sparkline's ring is the outer one. */
|
|
242
249
|
block-size: calc(1.125rem - 0.3125rem);
|
|
243
250
|
padding: 0 4px !important;
|
|
244
251
|
overflow: hidden;
|
|
@@ -15,13 +15,8 @@
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/* A short card
|
|
19
|
-
*
|
|
20
|
-
/* (`data-basalt-chart-short` is written by `ChartBox`, `box.tsx`; the same `:is` is in
|
|
21
|
-
* `dashboard/widget-header.module.css`.) */
|
|
22
|
-
:is([data-basalt-card-short], [data-basalt-chart-card]:has([data-basalt-chart-short])) .header {
|
|
23
|
-
padding-top: 4px;
|
|
24
|
-
}
|
|
18
|
+
/* A short card keeps this inset too, so its title shares a baseline with a tall neighbour in the
|
|
19
|
+
* row; its other short-state rules (the folded subtitle) live in `dashboard/widget-header.module.css`. */
|
|
25
20
|
|
|
26
21
|
/*
|
|
27
22
|
* The facts line (`facts` prop): the headline figure under the title, in place of a subtitle. It wraps
|
|
@@ -71,26 +66,34 @@
|
|
|
71
66
|
}
|
|
72
67
|
|
|
73
68
|
/*
|
|
74
|
-
* A fact's tone is INK only (
|
|
75
|
-
*
|
|
69
|
+
* A fact's tone is INK only (never a fill) and rides the DELTA alone: the comparison, with its direction
|
|
70
|
+
* glyph. The value, unit and period stay ink and muted. A fact with no comparison has no delta, so its
|
|
71
|
+
* tone inks the value (`.factTone` is on whichever element carries it). The status solids are the
|
|
72
|
+
* text-safe ones (`status-text.ts`). `stale` is the strip cell's dimmed value, verbatim
|
|
76
73
|
* (`stat-strip.module.css` `.cell[data-stale]`).
|
|
77
74
|
*/
|
|
78
|
-
.fact[data-tone='good']
|
|
75
|
+
.fact[data-tone='good'] .factTone {
|
|
79
76
|
color: var(--vx-status-good);
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
.fact[data-tone='warn']
|
|
79
|
+
.fact[data-tone='warn'] .factTone {
|
|
83
80
|
color: var(--vx-status-warn);
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
.fact[data-tone='bad']
|
|
83
|
+
.fact[data-tone='bad'] .factTone {
|
|
87
84
|
color: var(--vx-status-bad);
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
.fact[data-tone='muted']
|
|
87
|
+
.fact[data-tone='muted'] .factTone {
|
|
91
88
|
color: var(--vx-muted);
|
|
92
89
|
}
|
|
93
90
|
|
|
91
|
+
/* The direction glyph of a plain-text comparison: DeltaBadge's (`widget-header.module.css` `.deltaGlyph`). */
|
|
92
|
+
.factGlyph {
|
|
93
|
+
margin-inline-end: 3px;
|
|
94
|
+
font-size: var(--vx-text-micro);
|
|
95
|
+
}
|
|
96
|
+
|
|
94
97
|
.factsRow[data-stale] {
|
|
95
98
|
opacity: 0.55;
|
|
96
99
|
}
|
|
@@ -11,6 +11,8 @@ declare const classes: {
|
|
|
11
11
|
readonly factValue: string
|
|
12
12
|
readonly factUnit: string
|
|
13
13
|
readonly factPeriod: string
|
|
14
|
+
readonly factTone: string
|
|
15
|
+
readonly factGlyph: string
|
|
14
16
|
readonly skeletonFigure: string
|
|
15
17
|
readonly skeletonBasis: string
|
|
16
18
|
readonly legendReserve: string
|
package/src/charts/compile.ts
CHANGED
|
@@ -39,7 +39,7 @@ import { cursorDots } from './marks'
|
|
|
39
39
|
import { bucketTicks, strideEvery } from './ticks'
|
|
40
40
|
import { MAIN_PANE, plotAccess, plotContext } from './plot-context'
|
|
41
41
|
import { claimedLabelBoxes } from './labels'
|
|
42
|
-
import { refLabelPosition } from './ref-label'
|
|
42
|
+
import { refLabelDy, refLabelPosition } from './ref-label'
|
|
43
43
|
import type { LabelBox, RefLabelPoint } from './ref-label'
|
|
44
44
|
import type { PlotSizes } from './plot-context'
|
|
45
45
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
@@ -327,10 +327,15 @@ function wholeStepFormat<T>(
|
|
|
327
327
|
/** A fixed domain's end this near the last round tick (as a share of the tick step) stays unlabelled. */
|
|
328
328
|
const END_TICK_MIN_GAP = 0.4
|
|
329
329
|
|
|
330
|
+
/** A label without its digits (any script), separators and spaces: the unit or symbol text it carries. */
|
|
331
|
+
const labelShape = (label: string): string => label.replace(/[\p{Nd}.,\s]/gu, '')
|
|
332
|
+
|
|
330
333
|
/**
|
|
331
|
-
* The compact ladder's
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
+
* The compact ladder's few ticks can stop short of a fixed domain's end (`[0, 25]` ticks `0 10 20`).
|
|
335
|
+
* The end joins them only when it carries something the round ticks do not: a formatter that states
|
|
336
|
+
* the unit on the end alone (`25 days`) would lose it otherwise. A uniform formatter (`77 kg` beside
|
|
337
|
+
* `76 kg`) gains nothing from a tick off the step, so the end stays unlabelled and every label sits
|
|
338
|
+
* on an even step.
|
|
334
339
|
*/
|
|
335
340
|
function withEndTick<T>(
|
|
336
341
|
cfg: AxisConfig<T> | undefined,
|
|
@@ -340,11 +345,12 @@ function withEndTick<T>(
|
|
|
340
345
|
if (!Array.isArray(cfg?.domain) || cfg.scale === 'log' || cfg.nice === true) return null
|
|
341
346
|
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)]
|
|
342
347
|
const round = scaleLinear().domain([lo, hi]).ticks(count)
|
|
343
|
-
const last = round.at(-1)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
const [first, next, last] = [round.at(0), round.at(1), round.at(-1)]
|
|
349
|
+
if (first === undefined || next === undefined || last === undefined || last >= hi) return null
|
|
350
|
+
if (hi - last < (next - first) * END_TICK_MIN_GAP) return null
|
|
351
|
+
return labelShape(axis.format(hi)) === labelShape(axis.format(last))
|
|
352
|
+
? null
|
|
353
|
+
: { values: [...round, hi] }
|
|
348
354
|
}
|
|
349
355
|
|
|
350
356
|
export function yGuide<T>(opts: {
|
|
@@ -788,8 +794,6 @@ function underlayMarks<T, X extends ChartX>(
|
|
|
788
794
|
/** A band's bar spans this share of its half step (`paddingInner` 0.2 leaves 0.8 of the step). */
|
|
789
795
|
const BAR_BODY = 0.8
|
|
790
796
|
const REF_LABEL_DX = 6
|
|
791
|
-
const REF_LABEL_DY_ABOVE = -5
|
|
792
|
-
const REF_LABEL_DY_BELOW = 11
|
|
793
797
|
|
|
794
798
|
/** What a reference line's caption needs to choose its spot: the plot in px and the data on its axis. */
|
|
795
799
|
type RefLabelContext<T, X extends ChartX> = {
|
|
@@ -836,7 +840,7 @@ const refLabelMark = <T, X extends ChartX>(
|
|
|
836
840
|
fontSize: VX.text.micro,
|
|
837
841
|
anchor: atStart ? 'start' : 'end',
|
|
838
842
|
dx: atStart ? REF_LABEL_DX : -REF_LABEL_DX,
|
|
839
|
-
dy: position.
|
|
843
|
+
dy: refLabelDy(position, VX.text.micro),
|
|
840
844
|
}),
|
|
841
845
|
)
|
|
842
846
|
}
|
|
@@ -1031,6 +1035,8 @@ const stripAnchor = (
|
|
|
1031
1035
|
}
|
|
1032
1036
|
const STRIP_TOOLTIP_PLACEMENT = ['bottom', 'top'] as const
|
|
1033
1037
|
const STRIP_TOOLTIP_OFFSET = 8
|
|
1038
|
+
/** Air between a strip tooltip opened below and the scene's bottom edge (under the tick labels), px. */
|
|
1039
|
+
const STRIP_TICK_AIR = 2
|
|
1034
1040
|
/**
|
|
1035
1041
|
* A slotted `Bars` (`tooltipBelow` and `bare`): a micro-visual whose tooltip is the one-line chip
|
|
1036
1042
|
* (`chart-box.module.css`, `data-basalt-slot`) in the line the cell reserves above the plot. It
|
|
@@ -1045,7 +1051,7 @@ const slotAnchor = (
|
|
|
1045
1051
|
return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y }
|
|
1046
1052
|
}
|
|
1047
1053
|
const SLOT_TOOLTIP_PLACEMENT = ['top'] as const
|
|
1048
|
-
/** The plot's focus ring (`svg.ts-chart:focus-visible`, `chart-box.module.css`) is a 2px outline at a 0.125rem offset, and the chip keeps 1px of air above it. Mirrors that CSS ring at `--mantine-scale` 1; the chip's `block-size` in the same file is the reserve less this. */
|
|
1054
|
+
/** The plot's focus ring (`svg.ts-chart:focus-visible`, `chart-box.module.css`) is a 2px outline at a 0.125rem offset, and the chip keeps 1px of air above it. Mirrors that CSS ring at `--mantine-scale` 1; the chip's `block-size` in the same file is the reserve less this. A chart's ring is inset (W49) but a Sparkline's stays outer, and the chip is sized to the Sparkline's reserve. */
|
|
1049
1055
|
const SLOT_RING_CLEARANCE = 2 + 2 + 1
|
|
1050
1056
|
|
|
1051
1057
|
/** A tooltip's chrome (title row, padding) and each series row, px: the guess the bar anchor reserves. */
|
|
@@ -1085,6 +1091,8 @@ const barAnchor =
|
|
|
1085
1091
|
const TIP_CARD = '[data-basalt-chart-card], [data-strip-cell], .mantine-Card-root'
|
|
1086
1092
|
/** Air between a card-clamped tooltip and the card's edge, px. */
|
|
1087
1093
|
const TIP_CARD_AIR = 4
|
|
1094
|
+
/** Air between the plot's left edge and a tooltip, so the first point's cursor dot stays visible, px. */
|
|
1095
|
+
const TIP_DOT_AIR = 10
|
|
1088
1096
|
/** A card narrower than this keeps the engine's width and horizontal placement (a ~120px strip
|
|
1089
1097
|
* cell would squeeze a tooltip to its 6rem label floor); the vertical rule applies to every card. */
|
|
1090
1098
|
const TIP_CARD_ROOMY = 192
|
|
@@ -1096,7 +1104,7 @@ const TIP_CARD_ROOMY = 192
|
|
|
1096
1104
|
* `top`, so each write is followed by a settle inside the card (`settleInCard`).
|
|
1097
1105
|
*/
|
|
1098
1106
|
/** What a card clamp does: `card` a chart tooltip (both axes, the card's width), `slot` a slotted
|
|
1099
|
-
* `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways
|
|
1107
|
+
* `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways, and below the x tick labels when it opens under the strip). */
|
|
1100
1108
|
type TipMode = 'card' | 'slot' | 'strip'
|
|
1101
1109
|
|
|
1102
1110
|
const cardPortal = (mode: TipMode): ChartTooltipPortalExtension => ({
|
|
@@ -1154,10 +1162,13 @@ export function settleInCard(
|
|
|
1154
1162
|
y: surface.top + (p.y / sceneH) * surface.height,
|
|
1155
1163
|
})
|
|
1156
1164
|
if (mode === 'strip') {
|
|
1157
|
-
// A `BandStrip`: sideways
|
|
1165
|
+
// A `BandStrip`: sideways, and clear of the tick labels below; the engine's width stands.
|
|
1158
1166
|
if (w0 + 2 * TIP_CARD_AIR <= card.width)
|
|
1159
1167
|
left = Math.min(Math.max(left, card.left + TIP_CARD_AIR), card.right - w0 - TIP_CARD_AIR)
|
|
1160
1168
|
if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`
|
|
1169
|
+
// Opening below the strip, it starts under the scene (the x tick labels sit in its bottom margin).
|
|
1170
|
+
const clear = surface.bottom + STRIP_TICK_AIR
|
|
1171
|
+
if (tip.dataset['placement'] === 'bottom' && top < clear) tip.style.top = `${clear}px`
|
|
1161
1172
|
return
|
|
1162
1173
|
}
|
|
1163
1174
|
const roomy = card.width >= TIP_CARD_ROOMY
|
|
@@ -1181,6 +1192,14 @@ export function settleInCard(
|
|
|
1181
1192
|
const [w, h] = [tip.offsetWidth, tip.offsetHeight]
|
|
1182
1193
|
const anchor = toClient(ctx.anchor)
|
|
1183
1194
|
const gap = Math.max(0, Number.isFinite(ctx.offset) ? (ctx.offset ?? 10) : 10)
|
|
1195
|
+
// The plot's rect: the axis tick labels sit in the margins around it, so a card tooltip stays inside
|
|
1196
|
+
// it when it fits (a first-point tooltip would otherwise cover the y ticks and an x tick).
|
|
1197
|
+
const margin = ctx.scene.margin ?? { top: 0, right: 0, bottom: 0, left: 0 }
|
|
1198
|
+
const plotTL = toClient({ x: margin.left, y: margin.top })
|
|
1199
|
+
const plotBR = toClient({ x: sceneW - margin.right, y: sceneH - margin.bottom })
|
|
1200
|
+
// Per axis: a tooltip taller than a short plot still keeps its left edge clear of the y tick labels.
|
|
1201
|
+
const fenceX = !slot && plotBR.x - plotTL.x >= w + TIP_DOT_AIR
|
|
1202
|
+
const fenceY = !slot && plotBR.y - plotTL.y >= h
|
|
1184
1203
|
const maxTop = card.bottom - TIP_CARD_AIR - h
|
|
1185
1204
|
// The card's header (title and facts) is off-limits while the plot area below it can hold the tooltip.
|
|
1186
1205
|
const headerBottom = slot
|
|
@@ -1207,6 +1226,9 @@ export function settleInCard(
|
|
|
1207
1226
|
if (roomy) left = anchor.x - w / 2
|
|
1208
1227
|
}
|
|
1209
1228
|
if (!slot) top = maxTop < minTop ? minTop : Math.min(Math.max(top, minTop), maxTop)
|
|
1229
|
+
if (fenceY) top = Math.min(Math.max(top, plotTL.y), plotBR.y - h)
|
|
1230
|
+
// The left bound also clears the focused point's dot, drawn on the plot's edge at the first point.
|
|
1231
|
+
if (fenceX) left = Math.min(Math.max(left, plotTL.x + TIP_DOT_AIR), plotBR.x - w)
|
|
1210
1232
|
if (grown || w + 2 * TIP_CARD_AIR <= card.width)
|
|
1211
1233
|
left = Math.min(
|
|
1212
1234
|
Math.max(left, card.left + TIP_CARD_AIR),
|
package/src/charts/ref-label.ts
CHANGED
|
@@ -63,6 +63,15 @@ export function yRangeWithin(
|
|
|
63
63
|
return lo <= hi ? [lo, hi] : null
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The `dy` that puts a caption's box clear of its line. The engine centres the text on its y and
|
|
68
|
+
* its line box is a little taller than the glyphs, so a full font size off the line leaves the
|
|
69
|
+
* box half a font size plus its leading clear (the old −5 put the centre ON the dashes).
|
|
70
|
+
*/
|
|
71
|
+
export function refLabelDy(position: RefLabelPosition, fontSize: number): number {
|
|
72
|
+
return position.endsWith('above') ? -fontSize : fontSize
|
|
73
|
+
}
|
|
74
|
+
|
|
66
75
|
export function refLabelPosition(opts: {
|
|
67
76
|
/** `RefLine.labelPosition`: wins over everything. */
|
|
68
77
|
pinned: RefLabelPosition | undefined
|
|
@@ -115,7 +124,7 @@ export function refLabelPosition(opts: {
|
|
|
115
124
|
}
|
|
116
125
|
|
|
117
126
|
/** The gap between a sparkline reference label's box and its line, px. */
|
|
118
|
-
const SPARK_LABEL_GAP =
|
|
127
|
+
const SPARK_LABEL_GAP = 4
|
|
119
128
|
/** Air between a sparkline label's box and the data line (stroke and end dot included), px. */
|
|
120
129
|
const SPARK_LINE_AIR = 5
|
|
121
130
|
|
|
@@ -182,19 +191,37 @@ export function referenceLabelPlacement(opts: {
|
|
|
182
191
|
side,
|
|
183
192
|
end,
|
|
184
193
|
top,
|
|
194
|
+
range,
|
|
185
195
|
shift: Math.abs(top - nominal),
|
|
186
196
|
fits: top >= 0 && top + boxH <= height,
|
|
187
197
|
}
|
|
188
198
|
}),
|
|
189
199
|
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
// The box stays inside the plot (the top edge last, so a box taller than the plot starts at 0).
|
|
201
|
+
const scored = candidates.map((c) => {
|
|
202
|
+
const top = Math.max(0, Math.min(c.top, height - boxH))
|
|
203
|
+
const covered =
|
|
204
|
+
c.range === null
|
|
205
|
+
? 0
|
|
206
|
+
: Math.max(0, Math.min(top + boxH, c.range[1]) - Math.max(top, c.range[0]))
|
|
207
|
+
return { ...c, top, strikesRule: top < at && top + boxH > at, covered }
|
|
208
|
+
})
|
|
209
|
+
type Spot = (typeof scored)[number]
|
|
210
|
+
// The fitting spot that stays nearest the reference (the first of the four on a tie).
|
|
211
|
+
const nearer = (c: Spot, best: Spot): boolean => c.shift < best.shift
|
|
212
|
+
// Nothing fits (the line peaks on the reference in a short box): the spot that clears the
|
|
213
|
+
// reference rule first, then covers the least of the data line.
|
|
214
|
+
const better = (c: Spot, best: Spot): boolean =>
|
|
215
|
+
c.strikesRule === best.strikesRule ? c.covered < best.covered : best.strikesRule
|
|
216
|
+
const pick = (spots: Spot[], beats: (c: Spot, best: Spot) => boolean): Spot | undefined =>
|
|
217
|
+
spots.reduce<Spot | undefined>(
|
|
218
|
+
(best, c) => (best === undefined || beats(c, best) ? c : best),
|
|
219
|
+
undefined,
|
|
220
|
+
)
|
|
221
|
+
const { side, end, top } = (pick(
|
|
222
|
+
scored.filter((c) => c.fits),
|
|
223
|
+
nearer,
|
|
224
|
+
) ?? pick(scored, better)) as Spot
|
|
198
225
|
const dy = top + boxH / 2 - at
|
|
199
226
|
return { side, end, dy }
|
|
200
227
|
}
|
|
@@ -120,3 +120,47 @@
|
|
|
120
120
|
.root[data-basalt-readout] [data-ts-key='reference-label'] {
|
|
121
121
|
visibility: hidden;
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
/* The window caption under a hosted plot: the span on the start edge, the reference's key on the end. */
|
|
125
|
+
.frame {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
min-width: 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* The plot keeps its stated height whatever box the frame sits in. */
|
|
132
|
+
.frame > :first-child {
|
|
133
|
+
flex: none;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.caption {
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: baseline;
|
|
139
|
+
justify-content: space-between;
|
|
140
|
+
/* The key keeps a word's air from the span and drops to its own line when the two cannot share one
|
|
141
|
+
* (a ~160px cell at 390), rather than touching it. */
|
|
142
|
+
flex-wrap: wrap;
|
|
143
|
+
column-gap: var(--vx-space-stack-lg, 1rem);
|
|
144
|
+
margin-block-start: var(--vx-space-stack-xs, 0.25rem);
|
|
145
|
+
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
146
|
+
font-variant-numeric: lining-nums;
|
|
147
|
+
font-size: var(--vx-text-micro);
|
|
148
|
+
line-height: 1.25;
|
|
149
|
+
color: var(--vx-muted);
|
|
150
|
+
white-space: nowrap;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* The reference's key follows the drawn line: a short dash, then its name. */
|
|
154
|
+
.key {
|
|
155
|
+
display: inline-flex;
|
|
156
|
+
align-items: center;
|
|
157
|
+
column-gap: var(--vx-space-stack-xs, 0.25rem);
|
|
158
|
+
margin-inline-start: auto;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.key::before {
|
|
162
|
+
content: '';
|
|
163
|
+
inline-size: 0.75rem;
|
|
164
|
+
block-size: 1px;
|
|
165
|
+
background: repeating-linear-gradient(to right, var(--vx-line) 0 3px, transparent 3px 5px);
|
|
166
|
+
}
|
package/src/charts/state.tsx
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { CSSProperties, ReactElement, ReactNode } from 'react'
|
|
6
6
|
import { splitEmptyCopy } from '../common/empty-copy'
|
|
7
|
+
import { couldNotLoad } from '../common/could-not-load'
|
|
7
8
|
import { toErrorMessage } from '../common/errors'
|
|
8
9
|
import { RetryButton } from '../common/retry-button'
|
|
9
10
|
import { VX } from '../tokens'
|
|
@@ -120,7 +121,7 @@ const errorHeadStyle: CSSProperties = {
|
|
|
120
121
|
const errorMessageStyle: CSSProperties = { color: VX.muted }
|
|
121
122
|
|
|
122
123
|
const emptyLabel = (state: ChartState | undefined): string =>
|
|
123
|
-
typeof state?.empty === 'string' ? state.empty : 'Nothing
|
|
124
|
+
typeof state?.empty === 'string' ? state.empty : 'Nothing plotted in this range.'
|
|
124
125
|
|
|
125
126
|
/** Fills the same {@link ChartBox} the chart will, so a pending, failed or empty chart (and a
|
|
126
127
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
@@ -138,7 +139,7 @@ export function ChartPlaceholder(props: {
|
|
|
138
139
|
/** For a box too small to hold a sentence (a sparkline): error and empty show a `—` and carry the
|
|
139
140
|
* label as the accessible name and the hover title. */
|
|
140
141
|
compact?: boolean
|
|
141
|
-
/** Error only: what failed to load, "Could not load {noun}". Default:
|
|
142
|
+
/** Error only: what failed to load, "Could not load {noun}" (see `couldNotLoad`). Default: bare. */
|
|
142
143
|
noun?: string
|
|
143
144
|
/** Pending only: the ghost's shape. Default `'bars'`. */
|
|
144
145
|
ghost?: PlotGhostShape
|
|
@@ -179,7 +180,7 @@ export function ChartPlaceholder(props: {
|
|
|
179
180
|
{kind === 'error' && (
|
|
180
181
|
<span style={errorHeadStyle}>
|
|
181
182
|
<span aria-hidden="true" data-basalt-status-dot="" style={dotStyle} />
|
|
182
|
-
|
|
183
|
+
{couldNotLoad(props.noun)}
|
|
183
184
|
</span>
|
|
184
185
|
)}
|
|
185
186
|
<span style={errorMessageStyle}>{label}</span>
|
|
@@ -660,3 +660,78 @@ export function subpathPeersCheck(cwd: string, scanned: string[], install: Basal
|
|
|
660
660
|
}
|
|
661
661
|
})
|
|
662
662
|
}
|
|
663
|
+
|
|
664
|
+
/** Emitted `tokens:css` / `fonts:css` sheets from another version; the header names the re-emit command. */
|
|
665
|
+
export function staleEmittedSheets(
|
|
666
|
+
cwd: string,
|
|
667
|
+
files: readonly string[],
|
|
668
|
+
installedVersion: string | null,
|
|
669
|
+
): string[] {
|
|
670
|
+
if (installedVersion === null) return []
|
|
671
|
+
const out: string[] = []
|
|
672
|
+
for (const rel of files) {
|
|
673
|
+
if (!rel.endsWith('.css')) continue
|
|
674
|
+
const provenance = (readIfExists(resolve(cwd, rel)) ?? '').split('\n')[1]?.trim() ?? ''
|
|
675
|
+
const m = /^\/\* basalt-ui (\S+) — `(basalt-ui (?:tokens|fonts):css[^`]*)` \*\/$/.exec(
|
|
676
|
+
provenance,
|
|
677
|
+
)
|
|
678
|
+
if (m === null || m[1] === installedVersion) continue
|
|
679
|
+
out.push(
|
|
680
|
+
`emitted-sheets: ${rel} was emitted by ${m[1]}, installed is ${installedVersion} — ` +
|
|
681
|
+
`\`--check\` fails until it is re-emitted. Fix: \`${m[2]}\``,
|
|
682
|
+
)
|
|
683
|
+
}
|
|
684
|
+
return out
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** `a` versus `b` as dotted numbers: negative when `a` is older. */
|
|
688
|
+
export function compareVersions(a: string, b: string): number {
|
|
689
|
+
const y = b.split('.').map(Number)
|
|
690
|
+
return (
|
|
691
|
+
a
|
|
692
|
+
.split('.')
|
|
693
|
+
.map((n, i) => Number(n) - (y[i] ?? 0))
|
|
694
|
+
.find((d) => d !== 0) ?? 0
|
|
695
|
+
)
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const VISIBLE_HEADING = /^#{2,4}\s+Visible without code change/i
|
|
699
|
+
const CONSUMER_VISIBLE = /basalt\/[a-z][\w-]*|--vx-[\w-]+|\berror\b|\bpromoted?\b/i
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* The consumer-visible lines of every MIGRATING.md section with `from < version <= to` (`to`
|
|
703
|
+
* null: no upper bound), newest first as the file is ordered: lines naming a `basalt/*` rule id, a
|
|
704
|
+
* `--vx-*` token, `error` or `promoted`, plus the whole `Visible without code change` subsection.
|
|
705
|
+
* Fenced code and table separators are skipped; only long table rows are cut, never a bullet.
|
|
706
|
+
*/
|
|
707
|
+
export function migratingSince(markdown: string, from: string, to: string | null): string[] {
|
|
708
|
+
const out: string[] = []
|
|
709
|
+
let version: string | null = null
|
|
710
|
+
let visible = false
|
|
711
|
+
let fenced = false
|
|
712
|
+
for (const line of markdown.split('\n')) {
|
|
713
|
+
const h2 = /^## (\d+\.\d+\.\d+)\b(.*)$/.exec(line)
|
|
714
|
+
if (h2 !== null || line.startsWith('## ')) {
|
|
715
|
+
const v = h2?.[1] ?? null
|
|
716
|
+
version =
|
|
717
|
+
v !== null && compareVersions(v, from) > 0 && (to === null || compareVersions(v, to) <= 0)
|
|
718
|
+
? v
|
|
719
|
+
: null
|
|
720
|
+
visible = false
|
|
721
|
+
fenced = false
|
|
722
|
+
if (version !== null) out.push(`\n## ${version}${h2?.[2] ?? ''}`)
|
|
723
|
+
continue
|
|
724
|
+
}
|
|
725
|
+
if (version === null) continue
|
|
726
|
+
if (line.startsWith('```')) fenced = !fenced
|
|
727
|
+
if (fenced || line.startsWith('```')) continue
|
|
728
|
+
if (/^#{3,4}\s/.test(line)) visible = VISIBLE_HEADING.test(line)
|
|
729
|
+
const trimmed = line.trim()
|
|
730
|
+
if (trimmed === '' || /^\|[-\s|:]+\|$/.test(trimmed)) continue
|
|
731
|
+
if (!visible && !CONSUMER_VISIBLE.test(line)) continue
|
|
732
|
+
out.push(
|
|
733
|
+
trimmed.startsWith('|') && trimmed.length > 240 ? `${trimmed.slice(0, 240)}…` : trimmed,
|
|
734
|
+
)
|
|
735
|
+
}
|
|
736
|
+
return out
|
|
737
|
+
}
|