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
|
@@ -8,6 +8,18 @@
|
|
|
8
8
|
* `tone` inks the VALUE only, for a verdict; a null reading is `—`. A cell may carry BOTH: the hero
|
|
9
9
|
* (e.g. VO2max) with `rows` under it; omit `value` to render the rows alone.
|
|
10
10
|
*
|
|
11
|
+
* `state` replaces the readings (hero, visual, rows, footer) with the cell's empty or error body, at
|
|
12
|
+
* the cell's size. Empty: `—` in the value position and the reason, muted. Error: the shared error
|
|
13
|
+
* anatomy compact — status dot, the word `Failed`, the message, the shared Retry. The caption stays.
|
|
14
|
+
* A `visual` is a hero host: a zoned `Meter` in it does not repeat the value at its marker.
|
|
15
|
+
*
|
|
16
|
+
* Alignment: cells of one row align by PART (caption, value, hero footer, visual, rows, footer share
|
|
17
|
+
* tracks via subgrid), and each cell spans only down to its last part, so its own box ends at its
|
|
18
|
+
* content. A footer rides with what it captions (under the hero: its own track right below it).
|
|
19
|
+
* The dividers belong to a row-high slot around the cell, so they run the whole row and the area
|
|
20
|
+
* under a short cell is the strip's own surface. `action` sits at the end of the caption line (the
|
|
21
|
+
* caption truncates first); a row with `hideValue` prints its label alone.
|
|
22
|
+
*
|
|
11
23
|
* Anchors: each cell is `data-shot="strip-<key>"` and each footer cell
|
|
12
24
|
* `data-shot="strip-footer-<key>"` (derived — a consumer cannot choose another name).
|
|
13
25
|
*
|
|
@@ -18,11 +30,15 @@
|
|
|
18
30
|
import { Card, Skeleton } from '@mantine/core'
|
|
19
31
|
import { useId } from 'react'
|
|
20
32
|
import type { CSSProperties, ReactNode } from 'react'
|
|
33
|
+
import { toErrorMessage } from '../common/errors'
|
|
21
34
|
import { cx } from '../common/props'
|
|
22
35
|
import type { BasaltProps, Tone } from '../common/props'
|
|
36
|
+
import { RetryButton } from '../common/retry-button'
|
|
37
|
+
import { StatusDot } from '../theme/status-dot'
|
|
23
38
|
import { VX } from '../tokens'
|
|
24
39
|
import { InfoGlyph } from './widget-header'
|
|
25
40
|
import classes from './stat-strip.module.css'
|
|
41
|
+
import { HOSTED, VisualSlotContext } from './visual-slot'
|
|
26
42
|
|
|
27
43
|
export type StatStripRow = {
|
|
28
44
|
key: string
|
|
@@ -32,13 +48,36 @@ export type StatStripRow = {
|
|
|
32
48
|
visual?: ReactNode
|
|
33
49
|
/** A `DeltaBadge`. */
|
|
34
50
|
delta?: ReactNode
|
|
51
|
+
/** The reading is already shown (the hero): print the label alone. `value` is ignored. */
|
|
52
|
+
hideValue?: boolean
|
|
35
53
|
}
|
|
36
54
|
|
|
55
|
+
/** What a cell shows instead of its readings. Mirrors `StatCard`'s `query` branches. */
|
|
56
|
+
type StatStripCellState =
|
|
57
|
+
| {
|
|
58
|
+
kind: 'empty'
|
|
59
|
+
/** Why there is no reading, one muted line (`'No sleep logged'`). */
|
|
60
|
+
reason?: string
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
kind: 'error'
|
|
64
|
+
/** Whatever was thrown; decoded like `ErrorState`'s. */
|
|
65
|
+
error?: unknown
|
|
66
|
+
/** Renders the shared Retry button. */
|
|
67
|
+
onRetry?: () => void
|
|
68
|
+
/** A refetch is in flight: Retry is inert. */
|
|
69
|
+
retrying?: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
37
72
|
export type StatStripCell = {
|
|
38
73
|
key: string
|
|
39
74
|
caption: string
|
|
40
|
-
/** Muted, on the caption line: `CAPTION · qualifier`.
|
|
75
|
+
/** Muted, on the caption line: `CAPTION · qualifier`. It wraps whole under the caption when it
|
|
76
|
+
* does not fit (by design: no truncation, so no `title`). */
|
|
41
77
|
qualifier?: string
|
|
78
|
+
/** A control at the end of the caption line (a popover trigger). Never wraps the line: the
|
|
79
|
+
* caption truncates first. */
|
|
80
|
+
action?: ReactNode
|
|
42
81
|
/** The definition behind the caption, in the info-glyph tooltip. */
|
|
43
82
|
info?: string
|
|
44
83
|
/** `null` = no reading, printed as `—`. Omit only when `rows` carries the cell. */
|
|
@@ -58,6 +97,8 @@ export type StatStripCell = {
|
|
|
58
97
|
loading?: boolean
|
|
59
98
|
/** Dims the cell while placeholder data shows. */
|
|
60
99
|
stale?: boolean
|
|
100
|
+
/** Empty or failed: replaces the readings; `loading` wins while pending. */
|
|
101
|
+
state?: StatStripCellState
|
|
61
102
|
}
|
|
62
103
|
|
|
63
104
|
export type StatStripProps = BasaltProps & {
|
|
@@ -72,70 +113,155 @@ export type StatStripProps = BasaltProps & {
|
|
|
72
113
|
|
|
73
114
|
const EMPTY = '—'
|
|
74
115
|
|
|
116
|
+
function CellState({ state }: { state: StatStripCellState }) {
|
|
117
|
+
if (state.kind === 'empty') {
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
<div className={classes.valueRow}>
|
|
121
|
+
<span className={classes.value} data-strip-value>
|
|
122
|
+
{EMPTY}
|
|
123
|
+
</span>
|
|
124
|
+
</div>
|
|
125
|
+
{state.reason !== undefined && <p className={classes.reason}>{state.reason}</p>}
|
|
126
|
+
</>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
const message = toErrorMessage(state.error, 'The request failed.')
|
|
130
|
+
return (
|
|
131
|
+
<div className={classes.error} role="alert" data-strip-state="error">
|
|
132
|
+
<span className={classes.errorHead}>
|
|
133
|
+
<StatusDot color={VX.status.bad} />
|
|
134
|
+
Failed
|
|
135
|
+
</span>
|
|
136
|
+
<p className={classes.reason}>{message}</p>
|
|
137
|
+
{state.onRetry !== undefined && (
|
|
138
|
+
<RetryButton onClick={state.onRetry} retrying={state.retrying ?? false} />
|
|
139
|
+
)}
|
|
140
|
+
</div>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The last of the six shared tracks (caption, hero, hero footer, visual, rows, footer) a cell paints into. */
|
|
145
|
+
function lastTrackOf(cell: StatStripCell, state: StatStripCellState | undefined) {
|
|
146
|
+
if (state !== undefined) return state.kind === 'empty' && state.reason !== undefined ? 4 : 2
|
|
147
|
+
if (cell.rows !== undefined)
|
|
148
|
+
return cell.footer !== undefined ? 6 : cell.visual !== undefined ? 5 : 4
|
|
149
|
+
if (cell.visual !== undefined) return 4
|
|
150
|
+
return cell.footer !== undefined ? 3 : 2
|
|
151
|
+
}
|
|
152
|
+
|
|
75
153
|
function StripCell({ cell }: { cell: StatStripCell }) {
|
|
76
154
|
const captionId = useId()
|
|
77
155
|
const { rows, loading } = cell
|
|
156
|
+
const state = loading ? undefined : cell.state
|
|
78
157
|
const hasHero = cell.value !== undefined || rows === undefined
|
|
158
|
+
// A footer under a visual (and no rows) rides with it, so it hugs that visual instead of dropping
|
|
159
|
+
// to a taller sibling's; under a hero alone it rides with the value; only under rows does it take
|
|
160
|
+
// the row's shared footer track.
|
|
161
|
+
const ownFooter = cell.visual !== undefined && rows === undefined
|
|
162
|
+
const heroFooter = hasHero && cell.visual === undefined && rows === undefined
|
|
163
|
+
// The cell spans the tracks down to its last part, so its box ends at its content (the slot
|
|
164
|
+
// around it still runs the whole row for the dividers).
|
|
165
|
+
// The cell's verdict colours a plain Meter in its visual too (a hero host only).
|
|
166
|
+
const hostSlot = !hasHero ? null : cell.tone === undefined ? HOSTED : { tone: cell.tone }
|
|
167
|
+
const lastTrack = lastTrackOf(cell, state)
|
|
168
|
+
const footerEl = cell.footer !== undefined && (
|
|
169
|
+
<div className={cx(classes.footer, heroFooter && classes.heroFooter)} data-strip-footer>
|
|
170
|
+
{cell.footer}
|
|
171
|
+
</div>
|
|
172
|
+
)
|
|
173
|
+
const heroEl = loading ? (
|
|
174
|
+
<Skeleton className={classes.skeletonValue} radius="sm" />
|
|
175
|
+
) : (
|
|
176
|
+
<div className={classes.valueRow}>
|
|
177
|
+
<span
|
|
178
|
+
className={classes.value}
|
|
179
|
+
data-strip-value
|
|
180
|
+
style={cell.tone !== undefined ? { color: VX.status[cell.tone] } : undefined}
|
|
181
|
+
>
|
|
182
|
+
{cell.value ?? EMPTY}
|
|
183
|
+
</span>
|
|
184
|
+
{cell.value !== undefined && cell.value !== null && cell.unit !== undefined && (
|
|
185
|
+
<span className={classes.unit}>{cell.unit}</span>
|
|
186
|
+
)}
|
|
187
|
+
{cell.delta}
|
|
188
|
+
</div>
|
|
189
|
+
)
|
|
79
190
|
return (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
className={classes.value}
|
|
106
|
-
data-strip-value
|
|
107
|
-
style={cell.tone !== undefined ? { color: VX.status[cell.tone] } : undefined}
|
|
108
|
-
>
|
|
109
|
-
{cell.value ?? EMPTY}
|
|
191
|
+
// The slot owns the dividers and stretches to the row; the article inside ends at its content.
|
|
192
|
+
<div className={classes.cell} data-strip-slot>
|
|
193
|
+
<article
|
|
194
|
+
className={classes.content}
|
|
195
|
+
style={{ '--basalt-strip-span': lastTrack } as CSSProperties}
|
|
196
|
+
data-strip-cell={cell.key}
|
|
197
|
+
data-shot={`strip-${cell.key}`}
|
|
198
|
+
aria-labelledby={captionId}
|
|
199
|
+
{...(state === undefined && cell.visual !== undefined && { 'data-strip-has-visual': '' })}
|
|
200
|
+
{...(state === undefined && rows !== undefined && { 'data-strip-has-rows': '' })}
|
|
201
|
+
{...(cell.stale && { 'data-stale': 'true' })}
|
|
202
|
+
>
|
|
203
|
+
<div className={classes.captionLine}>
|
|
204
|
+
<div className={classes.captionMain}>
|
|
205
|
+
{/* The caption and its info glyph are one unit: the qualifier wraps whole, never between them. */}
|
|
206
|
+
<span className={classes.lead}>
|
|
207
|
+
<span
|
|
208
|
+
className={classes.caption}
|
|
209
|
+
id={captionId}
|
|
210
|
+
title={cell.caption}
|
|
211
|
+
data-strip-caption
|
|
212
|
+
>
|
|
213
|
+
{cell.caption}
|
|
214
|
+
</span>
|
|
215
|
+
{cell.info !== undefined && <InfoGlyph text={cell.info} />}
|
|
110
216
|
</span>
|
|
111
|
-
{cell.
|
|
112
|
-
<span className={classes.
|
|
217
|
+
{cell.qualifier !== undefined && (
|
|
218
|
+
<span className={classes.qualifier}>{cell.qualifier}</span>
|
|
113
219
|
)}
|
|
114
|
-
{cell.delta}
|
|
115
220
|
</div>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
221
|
+
{cell.action !== undefined && (
|
|
222
|
+
<span className={classes.action} data-strip-action>
|
|
223
|
+
{cell.action}
|
|
224
|
+
</span>
|
|
225
|
+
)}
|
|
226
|
+
</div>
|
|
227
|
+
{state !== undefined && <CellState state={state} />}
|
|
228
|
+
{state === undefined && hasHero && heroEl}
|
|
229
|
+
{state === undefined && heroFooter && footerEl}
|
|
230
|
+
{state === undefined && cell.visual !== undefined && (
|
|
231
|
+
<div className={classes.visualStack}>
|
|
232
|
+
<div className={classes.visual} data-strip-visual>
|
|
233
|
+
<VisualSlotContext.Provider value={hostSlot}>
|
|
234
|
+
{cell.visual}
|
|
235
|
+
</VisualSlotContext.Provider>
|
|
236
|
+
</div>
|
|
237
|
+
{ownFooter && footerEl}
|
|
124
238
|
</div>
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
239
|
+
)}
|
|
240
|
+
{state === undefined &&
|
|
241
|
+
rows !== undefined &&
|
|
242
|
+
(loading ? (
|
|
243
|
+
<div className={classes.rows} aria-hidden="true">
|
|
244
|
+
{rows.map((row) => (
|
|
245
|
+
<Skeleton key={row.key} className={classes.skeletonRow} radius="sm" />
|
|
246
|
+
))}
|
|
247
|
+
</div>
|
|
248
|
+
) : (
|
|
249
|
+
<ul className={classes.rows} data-strip-rows>
|
|
250
|
+
{rows.map((row) => (
|
|
251
|
+
<li key={row.key} className={classes.row} data-strip-row={row.key}>
|
|
252
|
+
<span className={classes.rowLabel}>{row.label}</span>
|
|
253
|
+
<span className={classes.visual}>{row.visual}</span>
|
|
254
|
+
<span className={classes.rowValue}>
|
|
255
|
+
{row.hideValue ? null : (row.value ?? EMPTY)}
|
|
256
|
+
</span>
|
|
257
|
+
<span>{row.delta}</span>
|
|
258
|
+
</li>
|
|
259
|
+
))}
|
|
260
|
+
</ul>
|
|
261
|
+
))}
|
|
262
|
+
{state === undefined && !ownFooter && !heroFooter && footerEl}
|
|
263
|
+
</article>
|
|
264
|
+
</div>
|
|
139
265
|
)
|
|
140
266
|
}
|
|
141
267
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set by a host that already shows the reading as its hero (a `StatCard` sparkline slot, a strip
|
|
3
|
+
* cell's `visual`). A `Meter` reads it: a zoned track drops the reading it would draw at the marker
|
|
4
|
+
* (the headline is not printed twice; `reading` overrides), and a plain bar or ring with no `tone` or
|
|
5
|
+
* `color` of its own takes the host's `tone` as its verdict colour. Internal: never exported.
|
|
6
|
+
*/
|
|
7
|
+
import { createContext } from 'react'
|
|
8
|
+
import type { Tone } from '../common/props'
|
|
9
|
+
|
|
10
|
+
export interface VisualSlot {
|
|
11
|
+
readonly tone?: Tone
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A host with no verdict of its own: one shared object, so a provider never re-renders its readers. */
|
|
15
|
+
export const HOSTED: VisualSlot = {}
|
|
16
|
+
|
|
17
|
+
export const VisualSlotContext = createContext<VisualSlot | null>(null)
|
package/src/guard/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (`tokens/space-scale`, `common/*`), never `tokens/palette` or `derive` (colour math on every
|
|
4
4
|
* Write/Edit).
|
|
5
5
|
*
|
|
6
|
-
* GUARD_RULES: the closed registry of all
|
|
6
|
+
* GUARD_RULES: the closed registry of all 27 violation kinds.
|
|
7
7
|
* checkSource: pure (text, relPath, cfg) → Finding[]. No FS, no walk, no console.
|
|
8
8
|
*/
|
|
9
9
|
import type { Finding, GuardConfig, GuardKind, GuardSeverity } from './types'
|
|
@@ -911,10 +911,15 @@ export const GRACE_PERIOD_KINDS: Partial<Record<GuardKind, GraceEntry>> = {
|
|
|
911
911
|
promote: '2.24.0',
|
|
912
912
|
why: 'The scale moved to 8/12/16/20/24 and the CSS micro ceiling dropped 10 → 7 in 2.16.0: a literal 8px/10px in CSS is newly a finding.',
|
|
913
913
|
},
|
|
914
|
+
'series-palette': {
|
|
915
|
+
since: '2.21.0',
|
|
916
|
+
promote: '2.23.0',
|
|
917
|
+
why: 'New in 2.21.0: the series file is judged by computed lightness, chroma, colour-blind separation and contrast; a palette that was tuned by eye is newly a finding.',
|
|
918
|
+
},
|
|
914
919
|
}
|
|
915
920
|
|
|
916
921
|
/** A kind's effective severity: consumer override first, then the grace table, then `error`. */
|
|
917
|
-
function severityOf(kind: GuardKind, cfg: GuardConfig): GuardSeverity {
|
|
922
|
+
export function severityOf(kind: GuardKind, cfg: GuardConfig): GuardSeverity {
|
|
918
923
|
return cfg.severity?.[kind] ?? (Object.hasOwn(GRACE_PERIOD_KINDS, kind) ? 'warn' : 'error')
|
|
919
924
|
}
|
|
920
925
|
|
|
@@ -985,7 +990,7 @@ function exemptPatternMatches(pattern: string, relPath: string): boolean {
|
|
|
985
990
|
* Whether `kind` is exempted at `relPath` via `cfg.exemptRules` — the config-driven, per-rule
|
|
986
991
|
* counterpart to `isChartFile`'s hardcoded path scoping.
|
|
987
992
|
*/
|
|
988
|
-
function isRuleExempt(
|
|
993
|
+
export function isRuleExempt(
|
|
989
994
|
kind: GuardKind,
|
|
990
995
|
relPath: string,
|
|
991
996
|
exemptRules: GuardConfig['exemptRules'],
|
|
@@ -1982,7 +1987,7 @@ type GuardRule = {
|
|
|
1982
1987
|
}
|
|
1983
1988
|
|
|
1984
1989
|
/**
|
|
1985
|
-
* The closed registry of all
|
|
1990
|
+
* The closed registry of all 27 guard kinds. The triad test asserts
|
|
1986
1991
|
* `surface.guardKinds ⊆ keyof GUARD_RULES` at runtime.
|
|
1987
1992
|
*
|
|
1988
1993
|
* raw-surface, raw-html-layout, and sub-16-input-font are handled inline in checkSource
|
|
@@ -2208,6 +2213,13 @@ export const GUARD_RULES = {
|
|
|
2208
2213
|
pattern: VX_VAR_REF, // handled inline (basalt-owned families); entry keeps the registry complete
|
|
2209
2214
|
message: `var() names a --vx-* token basalt does not emit, so it resolves to its fallback (or to nothing) with no error anywhere. Judged: every name inside a basalt-owned family (${[...BASALT_VX_FAMILY_SET].join(', ')}), plus any name basalt used to emit in any family — pick the token from the stylesheet basalt-ui tokens:css emits; your own series belong in a family of their own (groupTokens throws on one inside basalt's, in dev builds). A removed name is reported with its replacement on the finding line (MIGRATING.md has the table). Any other name outside a basalt family is never judged, because groupTokens may declare it in a file this scan cannot see.`,
|
|
2210
2215
|
},
|
|
2216
|
+
'series-palette': {
|
|
2217
|
+
kind: 'series-palette',
|
|
2218
|
+
pattern: /(?!)/, // never matches: judged over the whole series FILE by `series-file.ts`, not per line
|
|
2219
|
+
appliesTo: () => false,
|
|
2220
|
+
message:
|
|
2221
|
+
"The series file's palette fails a computed check (OKLCH lightness band, chroma floor, colour-blind separation of neighbours, worst-pair separation, 3:1 contrast against the surface, ≤ 8 series without a repeat) — retune the hex in the series file; it is judged per scheme, light against the light panel and dark against the dark one. A deliberately neutral series is keyed `other`.",
|
|
2222
|
+
},
|
|
2211
2223
|
} as const satisfies Record<GuardKind, GuardRule>
|
|
2212
2224
|
|
|
2213
2225
|
/**
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `series-palette` — the series file's palette is computed, never eyeballed.
|
|
3
|
+
*
|
|
4
|
+
* Pure: source text and the two scheme surfaces in, issues out. Reads every
|
|
5
|
+
* `defineSeries({ key: { light, dark } })` call as one ordered categorical group and judges each
|
|
6
|
+
* scheme against its own surface. The surfaces are the CALLER's to supply: this module is on the
|
|
7
|
+
* guard's import graph, which never loads the `derive` engine (see `guard/index.ts`'s header) —
|
|
8
|
+
* `series-file.ts` computes them. Colour math lives in `../tokens/oklab`; contrast is `hct.ts`'s
|
|
9
|
+
* WCAG ratio.
|
|
10
|
+
*/
|
|
11
|
+
import { contrastRatio } from '../tokens/hct'
|
|
12
|
+
import { deltaEOk, deltaEOkCvd, hexToOklch } from '../tokens/oklab'
|
|
13
|
+
|
|
14
|
+
export type SeriesScheme = 'light' | 'dark'
|
|
15
|
+
/** The surface each scheme's series are judged against. */
|
|
16
|
+
export type SeriesSurfaces = Record<SeriesScheme, string>
|
|
17
|
+
|
|
18
|
+
export type SeriesCheck =
|
|
19
|
+
| 'format'
|
|
20
|
+
| 'lightness'
|
|
21
|
+
| 'chroma'
|
|
22
|
+
| 'cvd'
|
|
23
|
+
| 'separation'
|
|
24
|
+
| 'contrast'
|
|
25
|
+
| 'order'
|
|
26
|
+
|
|
27
|
+
export type SeriesEntry = {
|
|
28
|
+
readonly key: string
|
|
29
|
+
readonly light: string
|
|
30
|
+
readonly dark: string
|
|
31
|
+
/** 1-based line of the entry in the scanned source. */
|
|
32
|
+
readonly line: number
|
|
33
|
+
}
|
|
34
|
+
export type SeriesGroup = { readonly line: number; readonly entries: readonly SeriesEntry[] }
|
|
35
|
+
|
|
36
|
+
export type SeriesIssue = {
|
|
37
|
+
readonly check: SeriesCheck
|
|
38
|
+
readonly scheme: SeriesScheme
|
|
39
|
+
readonly keys: readonly string[]
|
|
40
|
+
readonly measured: number
|
|
41
|
+
readonly threshold: number
|
|
42
|
+
/** Line of the first named key. */
|
|
43
|
+
readonly line: number
|
|
44
|
+
readonly message: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* OKLCH lightness bands, per scheme.
|
|
49
|
+
* - light [0.43, 0.77] — the brief's band: below 0.43 a series reads as ink, above 0.77 it washes
|
|
50
|
+
* out on the panel (3:1 bites earlier, near L 0.67, on the default light panel).
|
|
51
|
+
* - dark [0.58, 0.88] — lower bound is where a hue clears 3:1 against the default dark panel
|
|
52
|
+
* (#2b2b2e, L 0.29 → L ≈ 0.56, rounded up for margin); the upper bound keeps a clear step below
|
|
53
|
+
* white so a bright series does not glow against the dark page.
|
|
54
|
+
*/
|
|
55
|
+
export const LIGHTNESS_BAND: Record<SeriesScheme, readonly [number, number]> = {
|
|
56
|
+
light: [0.43, 0.77],
|
|
57
|
+
dark: [0.58, 0.88],
|
|
58
|
+
}
|
|
59
|
+
/** Minimum OKLCH chroma of a categorical hue. */
|
|
60
|
+
export const CHROMA_FLOOR = 0.1
|
|
61
|
+
/** Minimum OKLab ΔE×100 between ADJACENT series under protanopia and deuteranopia. */
|
|
62
|
+
export const CVD_ADJACENT_MIN = 8
|
|
63
|
+
/** Minimum OKLab ΔE×100 of the worst pair in a group, normal vision. */
|
|
64
|
+
export const SEPARATION_MIN = 15
|
|
65
|
+
/** Minimum WCAG contrast of a series against its scheme's surface. */
|
|
66
|
+
export const CONTRAST_MIN = 3
|
|
67
|
+
/** More categorical series than this and the next one folds into Other. */
|
|
68
|
+
export const MAX_SERIES = 8
|
|
69
|
+
/** The one escape: a series keyed `other` is deliberately neutral — exempt from the chroma floor only. */
|
|
70
|
+
export const NEUTRAL_KEY = 'other'
|
|
71
|
+
|
|
72
|
+
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i
|
|
73
|
+
|
|
74
|
+
/** The string literal after `light:` / `dark:`, in either order. */
|
|
75
|
+
const ENTRY =
|
|
76
|
+
/([A-Za-z_$][\w$]*|'[^']+'|"[^"]+")\s*:\s*\{\s*(?:light\s*:\s*(['"])(.*?)\2\s*,\s*dark\s*:\s*(['"])(.*?)\4|dark\s*:\s*(['"])(.*?)\6\s*,\s*light\s*:\s*(['"])(.*?)\8)/g
|
|
77
|
+
|
|
78
|
+
const lineOf = (text: string, at: number): number => text.slice(0, at).split('\n').length
|
|
79
|
+
|
|
80
|
+
/** Every `defineSeries(...)` call in `source`, as an ordered group of its literal `{ light, dark }` hex pairs. */
|
|
81
|
+
export function parseSeriesGroups(source: string): SeriesGroup[] {
|
|
82
|
+
const groups: SeriesGroup[] = []
|
|
83
|
+
for (const call of source.matchAll(/\bdefineSeries\s*\(/g)) {
|
|
84
|
+
const open = (call.index ?? 0) + call[0].length
|
|
85
|
+
const lineStart = source.lastIndexOf('\n', call.index ?? 0) + 1
|
|
86
|
+
if (/^\s*(?:\/\/|\*|\/\*)/.test(source.slice(lineStart, call.index))) continue
|
|
87
|
+
let depth = 1
|
|
88
|
+
let end = open
|
|
89
|
+
while (end < source.length && depth > 0) {
|
|
90
|
+
const ch = source[end]
|
|
91
|
+
if (ch === '(') depth += 1
|
|
92
|
+
else if (ch === ')') depth -= 1
|
|
93
|
+
end += 1
|
|
94
|
+
}
|
|
95
|
+
const body = source.slice(open, end)
|
|
96
|
+
const entries = [...body.matchAll(ENTRY)].map((m): SeriesEntry => {
|
|
97
|
+
const light = m[3] ?? m[9] ?? ''
|
|
98
|
+
const dark = m[5] ?? m[7] ?? ''
|
|
99
|
+
return {
|
|
100
|
+
key: (m[1] ?? '').replace(/^['"]|['"]$/g, ''),
|
|
101
|
+
light: light.trim(),
|
|
102
|
+
dark: dark.trim(),
|
|
103
|
+
line: lineOf(source, open + (m.index ?? 0)),
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
groups.push({ line: lineOf(source, call.index ?? 0), entries })
|
|
107
|
+
}
|
|
108
|
+
return groups
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fix = (n: number, digits = 2): string => n.toFixed(digits)
|
|
112
|
+
|
|
113
|
+
/** Judge every group against the six checks. */
|
|
114
|
+
export function auditSeriesGroups(
|
|
115
|
+
groups: readonly SeriesGroup[],
|
|
116
|
+
surfaces: SeriesSurfaces,
|
|
117
|
+
): SeriesIssue[] {
|
|
118
|
+
const issues: SeriesIssue[] = []
|
|
119
|
+
for (const group of groups) {
|
|
120
|
+
const { entries: allEntries } = group
|
|
121
|
+
const lineOfKey = (key: string) => allEntries.find((e) => e.key === key)?.line ?? group.line
|
|
122
|
+
|
|
123
|
+
const categorical = allEntries.filter((e) => e.key !== NEUTRAL_KEY)
|
|
124
|
+
if (categorical.length > MAX_SERIES) {
|
|
125
|
+
const extra = categorical.slice(MAX_SERIES).map((e) => e.key)
|
|
126
|
+
issues.push({
|
|
127
|
+
check: 'order',
|
|
128
|
+
scheme: 'light',
|
|
129
|
+
keys: extra,
|
|
130
|
+
measured: categorical.length,
|
|
131
|
+
threshold: MAX_SERIES,
|
|
132
|
+
line: lineOfKey(extra[0] ?? ''),
|
|
133
|
+
message: `${categorical.length} series in one group (max ${MAX_SERIES}) — ${extra.join(', ')} should fold into \`${NEUTRAL_KEY}\``,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (const scheme of ['light', 'dark'] as const) {
|
|
138
|
+
const [lo, hi] = LIGHTNESS_BAND[scheme]
|
|
139
|
+
const value = (e: SeriesEntry) => e[scheme]
|
|
140
|
+
// A value that is not `#rgb` / `#rrggbb` (an alpha hex, a colour name, a typo) cannot be
|
|
141
|
+
// measured — it is reported, and left out of this scheme's other checks rather than guessed at.
|
|
142
|
+
const entries = allEntries.filter((e) => {
|
|
143
|
+
if (HEX.test(value(e))) return true
|
|
144
|
+
issues.push({
|
|
145
|
+
check: 'format',
|
|
146
|
+
scheme,
|
|
147
|
+
keys: [e.key],
|
|
148
|
+
measured: 0,
|
|
149
|
+
threshold: 0,
|
|
150
|
+
line: e.line,
|
|
151
|
+
message: `${e.key} (${scheme}) "${value(e)}" is not a #rgb or #rrggbb hex — it cannot be checked`,
|
|
152
|
+
})
|
|
153
|
+
return false
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
for (const e of entries) {
|
|
157
|
+
const { L, C } = hexToOklch(value(e))
|
|
158
|
+
if (L < lo || L > hi) {
|
|
159
|
+
issues.push({
|
|
160
|
+
check: 'lightness',
|
|
161
|
+
scheme,
|
|
162
|
+
keys: [e.key],
|
|
163
|
+
measured: L,
|
|
164
|
+
threshold: L < lo ? lo : hi,
|
|
165
|
+
line: e.line,
|
|
166
|
+
message: `${e.key} (${scheme}) OKLCH lightness ${fix(L)} is outside ${lo}–${hi}`,
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
if (e.key !== NEUTRAL_KEY && C < CHROMA_FLOOR) {
|
|
170
|
+
issues.push({
|
|
171
|
+
check: 'chroma',
|
|
172
|
+
scheme,
|
|
173
|
+
keys: [e.key],
|
|
174
|
+
measured: C,
|
|
175
|
+
threshold: CHROMA_FLOOR,
|
|
176
|
+
line: e.line,
|
|
177
|
+
message: `${e.key} (${scheme}) OKLCH chroma ${fix(C, 3)} is below ${CHROMA_FLOOR} — a categorical hue must read as a hue (key a deliberately neutral series \`${NEUTRAL_KEY}\`)`,
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
const ratio = contrastRatio(value(e), surfaces[scheme])
|
|
181
|
+
if (ratio < CONTRAST_MIN) {
|
|
182
|
+
issues.push({
|
|
183
|
+
check: 'contrast',
|
|
184
|
+
scheme,
|
|
185
|
+
keys: [e.key],
|
|
186
|
+
measured: ratio,
|
|
187
|
+
threshold: CONTRAST_MIN,
|
|
188
|
+
line: e.line,
|
|
189
|
+
message: `${e.key} (${scheme}) contrast ${fix(ratio)}:1 against the surface is below ${CONTRAST_MIN}:1`,
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Cycling: an identical colour twice in one scheme is one series standing in for two.
|
|
195
|
+
const seen = new Map<string, string>()
|
|
196
|
+
const duplicated = new Set<string>()
|
|
197
|
+
for (const e of entries) {
|
|
198
|
+
const first = seen.get(value(e).toLowerCase())
|
|
199
|
+
if (first === undefined) seen.set(value(e).toLowerCase(), e.key)
|
|
200
|
+
else {
|
|
201
|
+
duplicated.add(`${first}|${e.key}`)
|
|
202
|
+
issues.push({
|
|
203
|
+
check: 'order',
|
|
204
|
+
scheme,
|
|
205
|
+
keys: [first, e.key],
|
|
206
|
+
measured: 0,
|
|
207
|
+
threshold: SEPARATION_MIN,
|
|
208
|
+
line: e.line,
|
|
209
|
+
message: `${first} and ${e.key} (${scheme}) are the same colour ${value(e)} — a group does not cycle`,
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Adjacent pairs, worst of the two dichromacies.
|
|
215
|
+
for (let i = 1; i < entries.length; i += 1) {
|
|
216
|
+
const a = entries[i - 1] as SeriesEntry
|
|
217
|
+
const b = entries[i] as SeriesEntry
|
|
218
|
+
if (duplicated.has(`${a.key}|${b.key}`)) continue
|
|
219
|
+
const sims = (['protan', 'deutan'] as const).map(
|
|
220
|
+
(kind) => [kind, deltaEOkCvd(value(a), value(b), kind)] as const,
|
|
221
|
+
)
|
|
222
|
+
const [kind, worst] = sims.reduce((m, s) => (s[1] < m[1] ? s : m))
|
|
223
|
+
if (worst < CVD_ADJACENT_MIN) {
|
|
224
|
+
issues.push({
|
|
225
|
+
check: 'cvd',
|
|
226
|
+
scheme,
|
|
227
|
+
keys: [a.key, b.key],
|
|
228
|
+
measured: worst,
|
|
229
|
+
threshold: CVD_ADJACENT_MIN,
|
|
230
|
+
line: b.line,
|
|
231
|
+
message: `${a.key} → ${b.key} (${scheme}) are ΔE ${fix(worst, 1)} apart under ${kind === 'protan' ? 'protanopia' : 'deuteranopia'}, below ${CVD_ADJACENT_MIN}`,
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Worst pair over the whole group, normal vision (identical pairs are `order`'s).
|
|
237
|
+
let worstPair: { a: SeriesEntry; b: SeriesEntry; de: number } | null = null
|
|
238
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
239
|
+
for (let j = i + 1; j < entries.length; j += 1) {
|
|
240
|
+
const a = entries[i] as SeriesEntry
|
|
241
|
+
const b = entries[j] as SeriesEntry
|
|
242
|
+
if (duplicated.has(`${a.key}|${b.key}`)) continue
|
|
243
|
+
const de = deltaEOk(value(a), value(b))
|
|
244
|
+
if (worstPair === null || de < worstPair.de) worstPair = { a, b, de }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (worstPair !== null && worstPair.de < SEPARATION_MIN) {
|
|
248
|
+
issues.push({
|
|
249
|
+
check: 'separation',
|
|
250
|
+
scheme,
|
|
251
|
+
keys: [worstPair.a.key, worstPair.b.key],
|
|
252
|
+
measured: worstPair.de,
|
|
253
|
+
threshold: SEPARATION_MIN,
|
|
254
|
+
line: worstPair.b.line,
|
|
255
|
+
message: `${worstPair.a.key} and ${worstPair.b.key} (${scheme}) are only ΔE ${fix(worstPair.de, 1)} apart, below ${SEPARATION_MIN}`,
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return issues
|
|
261
|
+
}
|