basalt-ui 2.16.0 → 2.18.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 +165 -124
- package/MIGRATING.md +133 -15
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +3 -3
- package/configs/oxlint-plugin.js +2 -2
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +2 -2
- package/dist/charts/DualPanel.js +2 -2
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +2 -2
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/Sparkline.d.ts +4 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +3 -3
- package/dist/charts/compile.d.ts +8 -3
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +19 -9
- package/dist/charts/cursor.d.ts +14 -1
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +29 -3
- package/dist/charts/date-tick-format.d.ts +17 -0
- package/dist/charts/date-tick-format.d.ts.map +1 -0
- package/dist/charts/date-tick-format.js +81 -0
- package/dist/charts/panel.d.ts +2 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +3 -2
- package/dist/charts/types.d.ts +5 -1
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -2
- 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 +96 -13
- package/dist/cli/shot/index.d.ts +10 -1
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +40 -5
- package/dist/cli/shot/playwright.d.ts +4 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/real-data.d.ts +35 -0
- package/dist/cli/shot/real-data.d.ts.map +1 -0
- package/dist/cli/shot/real-data.js +120 -0
- package/dist/cli/shot/serve.d.ts +2 -2
- package/dist/cli/shot/serve.d.ts.map +1 -1
- package/dist/cli/shot/serve.js +16 -2
- package/dist/dashboard/bar-list.d.ts +29 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -0
- package/dist/dashboard/bar-list.js +52 -0
- package/dist/dashboard/bar-list.module.css +73 -0
- package/dist/dashboard/bar-list.module.css.d.ts +16 -0
- package/dist/dashboard/delta-badge.d.ts +2 -2
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +12 -14
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-model.d.ts +78 -0
- package/dist/dashboard/meter-model.d.ts.map +1 -0
- package/dist/dashboard/meter-model.js +91 -0
- package/dist/dashboard/meter-parts.d.ts +42 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -0
- package/dist/dashboard/meter-parts.js +163 -0
- package/dist/dashboard/meter.d.ts +112 -0
- package/dist/dashboard/meter.d.ts.map +1 -0
- package/dist/dashboard/meter.js +43 -0
- package/dist/dashboard/meter.module.css +150 -0
- package/dist/dashboard/meter.module.css.d.ts +28 -0
- package/dist/dashboard/query-state.d.ts +35 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +12 -1
- package/dist/dashboard/scale.d.ts +9 -0
- package/dist/dashboard/scale.d.ts.map +1 -0
- package/dist/dashboard/scale.js +10 -0
- package/dist/dashboard/stat-card-parts.d.ts +40 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -0
- package/dist/dashboard/stat-card-parts.js +55 -0
- package/dist/dashboard/stat-card.d.ts +46 -34
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +148 -79
- package/dist/dashboard/stat-card.module.css +220 -7
- package/dist/dashboard/stat-card.module.css.d.ts +20 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +73 -9
- package/dist/dashboard/widget-header.module.css +25 -17
- package/dist/guard/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/theme/chrome-vars.d.ts +82 -0
- package/dist/theme/chrome-vars.d.ts.map +1 -0
- package/dist/theme/chrome-vars.js +36 -0
- package/dist/theme/controls.module.css +20 -1
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +30 -33
- package/dist/tokens/derive.d.ts +11 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +9 -24
- package/dist/tokens/status-text.d.ts +26 -0
- package/dist/tokens/status-text.d.ts.map +1 -0
- package/dist/tokens/status-text.js +68 -0
- package/llms.txt +36 -4
- package/package.json +1 -1
- package/src/charts/Donut.tsx +2 -2
- package/src/charts/DualPanel.tsx +2 -2
- package/src/charts/Heatmap.tsx +2 -2
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/Sparkline.tsx +7 -5
- package/src/charts/compile.ts +31 -11
- package/src/charts/cursor.ts +48 -3
- package/src/charts/date-tick-format.ts +132 -0
- package/src/charts/panel.tsx +5 -3
- package/src/charts/types.ts +5 -1
- package/src/cli/help.ts +22 -2
- package/src/cli/shot/capture.ts +133 -12
- package/src/cli/shot/index.ts +50 -4
- package/src/cli/shot/playwright.ts +1 -1
- package/src/cli/shot/real-data.ts +165 -0
- package/src/cli/shot/serve.ts +28 -3
- package/src/dashboard/bar-list.module.css +73 -0
- package/src/dashboard/bar-list.module.css.d.ts +16 -0
- package/src/dashboard/bar-list.tsx +112 -0
- package/src/dashboard/delta-badge.tsx +24 -18
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +161 -0
- package/src/dashboard/meter-parts.tsx +223 -0
- package/src/dashboard/meter.module.css +150 -0
- package/src/dashboard/meter.module.css.d.ts +28 -0
- package/src/dashboard/meter.tsx +162 -0
- package/src/dashboard/query-state.tsx +38 -0
- package/src/dashboard/scale.ts +13 -0
- package/src/dashboard/stat-card-parts.tsx +108 -0
- package/src/dashboard/stat-card.module.css +220 -7
- package/src/dashboard/stat-card.module.css.d.ts +20 -0
- package/src/dashboard/stat-card.tsx +282 -174
- package/src/dashboard/widget-header.module.css +25 -17
- package/src/dashboard/widget-header.tsx +103 -7
- package/src/guard/index.ts +2 -2
- package/src/index.ts +4 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +128 -40
- package/src/theme/chrome-vars.ts +111 -0
- package/src/theme/controls.module.css +20 -1
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +39 -101
- package/src/tokens/derive.ts +19 -26
- package/src/tokens/status-text.ts +85 -0
|
@@ -276,7 +276,7 @@ html .accordionItem {
|
|
|
276
276
|
/*
|
|
277
277
|
* Tabs: the tab-list rule (and the inactive-tab hover underline) is a layout separator — the
|
|
278
278
|
* divider token, not the heavy gray-3/dark-4 line. Mantine's scheme rules sit at (0,2,0); the
|
|
279
|
-
* `html[...]` prefix lands (0,2,1). The active underline
|
|
279
|
+
* `html[...]` prefix lands (0,2,1). The active underline's colour is set in the theme's Tabs `vars`.
|
|
280
280
|
*/
|
|
281
281
|
html[data-mantine-color-scheme] .tabsRoot {
|
|
282
282
|
--tab-border-color: var(--vx-divider);
|
|
@@ -304,3 +304,22 @@ html .tableRoot {
|
|
|
304
304
|
html .tableRoot tbody tr:last-of-type {
|
|
305
305
|
border-bottom: none;
|
|
306
306
|
}
|
|
307
|
+
|
|
308
|
+
/*
|
|
309
|
+
* Badge leading glyph (`leftSection`): the state encoded by shape. 12px on a 20px chip, 4px gap
|
|
310
|
+
* (Mantine's own section margin is spacing.xs / 2 = 4), centred on the label.
|
|
311
|
+
*/
|
|
312
|
+
.badgeSection {
|
|
313
|
+
--badge-section-margin: calc(0.25rem * var(--mantine-scale));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.badgeSection svg,
|
|
317
|
+
.badgeSection img {
|
|
318
|
+
width: calc(0.75rem * var(--mantine-scale));
|
|
319
|
+
height: calc(0.75rem * var(--mantine-scale));
|
|
320
|
+
flex-shrink: 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.badgeSection img {
|
|
324
|
+
object-fit: contain;
|
|
325
|
+
}
|
package/src/theme/index.ts
CHANGED
|
@@ -86,6 +86,7 @@ import { CTL_HEIGHT_VARS } from '../tokens/ctl-vars'
|
|
|
86
86
|
import type { CtlHeightVar } from '../tokens/ctl-vars'
|
|
87
87
|
import { SIZE_CLASS_BREAKPOINTS } from '../tokens/size-classes'
|
|
88
88
|
import type { BasaltFontsConfig } from '../tokens/core'
|
|
89
|
+
import { onColor, onColorFor, subtleInkVars, tabsVars } from './chrome-vars'
|
|
89
90
|
import controlsClasses from './controls.module.css'
|
|
90
91
|
import floatingClasses from './floating.module.css'
|
|
91
92
|
import navLinkClasses from './nav-link.module.css'
|
|
@@ -229,60 +230,6 @@ function buildDarkTuple(data: PaletteData): MantineColorsTuple {
|
|
|
229
230
|
] as unknown as MantineColorsTuple
|
|
230
231
|
}
|
|
231
232
|
|
|
232
|
-
/**
|
|
233
|
-
* ON-COLOR: the foreground for a filled surface, decided in CSS. THE fix for Mantine's
|
|
234
|
-
* scheme-blind, contrast-blind `autoContrast`.
|
|
235
|
-
*
|
|
236
|
-
* Mantine picks the filled-variant text color ONCE, in JS, via `parseThemeColor({ color, theme })`
|
|
237
|
-
* — with NO `colorScheme` argument, so it resolves against the LIGHT `primaryShade` and bakes a
|
|
238
|
-
* static `color: var(--mantine-color-white)` into the element, while the BACKGROUND it pairs that
|
|
239
|
-
* with (`--mantine-color-{c}-filled`) stays a scheme-reactive CSS var. It gets away with it
|
|
240
|
-
* upstream only because Mantine's default `primaryShade` is `{ light: 6, dark: 8 }` — DARKER on
|
|
241
|
-
* dark, so white happens to stay right. It is luck, not logic: point `primaryShade.dark` at a
|
|
242
|
-
* lighter shade (as Basalt originally did) and every filled control in dark mode turns white-on-
|
|
243
|
-
* light. And even in one scheme the pick is wrong, because `isLightColor` is a BT.601 BRIGHTNESS
|
|
244
|
-
* test that does not track WCAG contrast — it handed white to lime `#97ba2e` at 2.24:1.
|
|
245
|
-
*
|
|
246
|
-
* Basalt removes the JS decision entirely. A fill is now scheme-INDEPENDENT and sits in a
|
|
247
|
-
* luminance band chosen so a WHITE label always clears AA (see `FILL` / `ACCENT` in
|
|
248
|
-
* tokens/palette.ts), so the on-color is a token, not a computation. `--vx-on-{color}` is emitted
|
|
249
|
-
* per color and resolves in pure CSS at paint time — the same discipline the rest of the `--vx-*`
|
|
250
|
-
* system follows. It is still MEASURED here (`legibleOn`) rather than hardcoded to white, so a
|
|
251
|
-
* consumer that retunes a family outside the band still gets the legible foreground.
|
|
252
|
-
*
|
|
253
|
-
* The palette already KNEW the answer: `ACCENT.onAccent` ("text on an accent fill") existed, and
|
|
254
|
-
* `Composer`'s send button hand-wired `color: var(--vx-on-accent)` — which was the ONLY reason that
|
|
255
|
-
* one control stayed legible while every generic Mantine control did not. The token was right;
|
|
256
|
-
* nothing bound the chrome to it. It is bound now (see `accentBridge` / `familyBridge`), and the
|
|
257
|
-
* Composer no longer needs the override.
|
|
258
|
-
*
|
|
259
|
-
* Fix: never let a foreground be decided in JS. `--vx-on-{color}` is emitted per color under BOTH
|
|
260
|
-
* scheme blocks of `cssVariablesResolver` (each resolved against the shade that scheme actually
|
|
261
|
-
* paints), so the foreground resolves in pure CSS at paint time — the same discipline the rest of
|
|
262
|
-
* the `--vx-*` system already follows. `basaltVariantColorResolver` re-points every filled variant
|
|
263
|
-
* at it, and the components that bypass the variant resolver (Checkbox / Radio / Tabs / Pagination /
|
|
264
|
-
* Stepper / Indicator / Timeline all call Mantine's `getContrastColor` directly) are re-pointed at
|
|
265
|
-
* it too, in `components` below. Regression-locked by `contrast.test.ts`.
|
|
266
|
-
*/
|
|
267
|
-
function onColor(theme: MantineTheme, color: string | undefined): string | undefined {
|
|
268
|
-
const name = color ?? theme.primaryColor
|
|
269
|
-
if (!Object.prototype.hasOwnProperty.call(theme.colors, name)) return undefined // hex / `blue.5`
|
|
270
|
-
return `var(--vx-on-${name})`
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* The on-color for a component that bypasses the variant resolver and calls Mantine's
|
|
275
|
-
* `getContrastColor` directly. `undefined` (autoContrast off, or a hex / indexed color) leaves
|
|
276
|
-
* Mantine's own value in place — `mergeVars` strips undefined before merging.
|
|
277
|
-
*/
|
|
278
|
-
function onColorFor(
|
|
279
|
-
theme: MantineTheme,
|
|
280
|
-
props: { color?: string | undefined; autoContrast?: boolean | undefined },
|
|
281
|
-
): string | undefined {
|
|
282
|
-
const autoContrast = props.autoContrast ?? theme.autoContrast
|
|
283
|
-
return autoContrast ? onColor(theme, props.color) : undefined
|
|
284
|
-
}
|
|
285
|
-
|
|
286
233
|
/** WCAG 2.x relative luminance. */
|
|
287
234
|
function relativeLuminance(hex: string): number {
|
|
288
235
|
const channels = hexToRgb(hex).map((c) => {
|
|
@@ -367,24 +314,9 @@ const basaltVariantColorResolver: VariantColorsResolver = (input) => {
|
|
|
367
314
|
return autoContrast ? { ...resolved, color: on } : resolved
|
|
368
315
|
}
|
|
369
316
|
|
|
370
|
-
// `subtle
|
|
371
|
-
// (
|
|
372
|
-
//
|
|
373
|
-
// accent block that read as a filled control appearing under the cursor. Fixing it HERE rather
|
|
374
|
-
// than in controls.module.css is what makes Button and ActionIcon agree: both resolve `subtle`
|
|
375
|
-
// through this one function, and §5's ghost icon button and a `variant="subtle"` Button are meant
|
|
376
|
-
// to be the same idiom at two sizes.
|
|
377
|
-
//
|
|
378
|
-
// Scoped to the DEFAULT color on purpose. An explicitly-colored subtle control (`color="red"` on a
|
|
379
|
-
// destructive text action) carries its hue as the whole signal, so neutralizing its hover would
|
|
380
|
-
// erase the one thing that marks it dangerous — those keep Mantine's own tinted hover.
|
|
381
|
-
if (input.variant === 'subtle') {
|
|
382
|
-
const isDefaultColor = input.color === undefined || input.color === input.theme.primaryColor
|
|
383
|
-
return isDefaultColor
|
|
384
|
-
? { ...resolved, hover: `color-mix(in srgb, var(--vx-ink) 6%, transparent)` }
|
|
385
|
-
: resolved
|
|
386
|
-
}
|
|
387
|
-
|
|
317
|
+
// `subtle` stays Mantine's: Button and ActionIcon get their ink label + hover in `subtleInkVars`
|
|
318
|
+
// (the resolver is always handed `color || primaryColor`, so it cannot tell "unnamed" from an
|
|
319
|
+
// explicit primary colour — only the component props can).
|
|
388
320
|
// `outline`: the tone's own text colour, pulled toward ink so the label keeps its hue at AA
|
|
389
321
|
// (grey outline badges measured 3.9:1 on the light page).
|
|
390
322
|
if (input.variant === 'outline') {
|
|
@@ -566,10 +498,12 @@ function buildTheme(data: PaletteData, options: BuildThemeOptions = {}): Mantine
|
|
|
566
498
|
},
|
|
567
499
|
},
|
|
568
500
|
}),
|
|
569
|
-
//
|
|
570
|
-
//
|
|
571
|
-
|
|
572
|
-
|
|
501
|
+
// Status chip (SPEC § 6.10): `light` + `tight`, neutral until `color=` opts in (the accent is
|
|
502
|
+
// never a status chip's default); a `leftSection` glyph is sized in `badgeSection`.
|
|
503
|
+
Badge: ext<typeof Badge>({
|
|
504
|
+
defaultProps: { variant: 'light', color: 'gray', radius: radius.tight },
|
|
505
|
+
classNames: { section: controlsClasses.badgeSection },
|
|
506
|
+
}),
|
|
573
507
|
// Alert renders its title in the body font by default; bring it onto the head-font idiom
|
|
574
508
|
// (docs/DESIGN-SPEC.md §5) like every other titled surface. Radius/padding/color tint are
|
|
575
509
|
// already on-system (defaultRadius 'md' control tier + the variant color resolver), so only
|
|
@@ -741,25 +675,35 @@ function buildTheme(data: PaletteData, options: BuildThemeOptions = {}): Mantine
|
|
|
741
675
|
// `size="xs"`) on Mantine's own static height.
|
|
742
676
|
Button: ext<typeof Button>({
|
|
743
677
|
classNames: { root: controlsClasses.buttonRoot },
|
|
744
|
-
vars: (_theme, props) =>
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
678
|
+
vars: (_theme, props) => {
|
|
679
|
+
const ink = subtleInkVars(props)
|
|
680
|
+
return {
|
|
681
|
+
root: {
|
|
682
|
+
'--button-height':
|
|
683
|
+
props.size === 'md'
|
|
684
|
+
? 'calc(var(--vx-space-control-height) * var(--mantine-scale))'
|
|
685
|
+
: undefined,
|
|
686
|
+
'--button-color': ink.color,
|
|
687
|
+
'--button-hover': ink.hover,
|
|
688
|
+
},
|
|
689
|
+
}
|
|
690
|
+
},
|
|
752
691
|
}),
|
|
753
692
|
ActionIcon: ext<typeof ActionIcon>({
|
|
754
693
|
classNames: { root: controlsClasses.actionIconRoot },
|
|
755
|
-
vars: (_theme, props) =>
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
694
|
+
vars: (_theme, props) => {
|
|
695
|
+
const ink = subtleInkVars(props)
|
|
696
|
+
return {
|
|
697
|
+
root: {
|
|
698
|
+
'--ai-size':
|
|
699
|
+
props.size === 'md'
|
|
700
|
+
? 'calc(var(--vx-space-control-height) * var(--mantine-scale))'
|
|
701
|
+
: undefined,
|
|
702
|
+
'--ai-color': ink.color,
|
|
703
|
+
'--ai-hover': ink.hover,
|
|
704
|
+
},
|
|
705
|
+
}
|
|
706
|
+
},
|
|
763
707
|
}),
|
|
764
708
|
// CheckboxCard / RadioCard (`withBorder`, true by default): same live regression as Button/
|
|
765
709
|
// ActionIcon before this pass — Mantine ships `border: 1px solid transparent` as the BASE
|
|
@@ -1125,17 +1069,11 @@ function buildTheme(data: PaletteData, options: BuildThemeOptions = {}): Mantine
|
|
|
1125
1069
|
// The tab-list bottom rule (and the inactive-tab hover underline) is a layout separator, not
|
|
1126
1070
|
// control chrome — it reads the divider token instead of the heavy gray-3/dark-4 line
|
|
1127
1071
|
// (controls.module.css; custom properties are stripped from `styles` objects). The active tab
|
|
1128
|
-
// underline
|
|
1072
|
+
// underline takes ink, not the accent (SPEC § 6.12; DESIGN-CORE § Accent discipline);
|
|
1073
|
+
// `color=` opts back in. Only the underline `default` variant — `pills` fills with the colour.
|
|
1129
1074
|
Tabs: ext<typeof Tabs>({
|
|
1130
1075
|
classNames: { root: controlsClasses.tabsRoot },
|
|
1131
|
-
|
|
1132
|
-
// `--tabs-color` / `--tabs-radius`, yet Tabs' OWN varsResolver writes `--tabs-text-color` —
|
|
1133
|
-
// an upstream type gap, so the var it actually paints the active tab with is otherwise
|
|
1134
|
-
// unreachable from the theme.
|
|
1135
|
-
vars: (theme, props) =>
|
|
1136
|
-
({ root: { '--tabs-text-color': onColorFor(theme, props) } }) as unknown as {
|
|
1137
|
-
root: Record<'--tabs-color' | '--tabs-radius', string | undefined>
|
|
1138
|
-
},
|
|
1076
|
+
vars: tabsVars,
|
|
1139
1077
|
}),
|
|
1140
1078
|
|
|
1141
1079
|
// ── ON-COLOR re-points (see the ON-COLOR doctrine above) ────────────────────────────────
|
package/src/tokens/derive.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* constants below, never hand-editing a hex in `palette.ts`.
|
|
11
11
|
*/
|
|
12
12
|
import { contrastRatio, hctToHex, hexToHct, yToTone } from './hct'
|
|
13
|
+
import { deriveStatusHexes } from './status-text'
|
|
13
14
|
import type { ColorPair } from './core'
|
|
14
15
|
|
|
15
16
|
export type DeriveConfig = {
|
|
@@ -316,13 +317,6 @@ const INK_TONE: Record<Side, Record<InkKey, number>> = {
|
|
|
316
317
|
// ── Status/semantic — three baked hues, each with its own calibrated tone+chroma stop per scheme.
|
|
317
318
|
export type StatusKey = 'good' | 'warn' | 'bad'
|
|
318
319
|
|
|
319
|
-
const STATUS_HUE: Record<StatusKey, number> = { good: 151.975, warn: 76.64, bad: 29.905 }
|
|
320
|
-
const STATUS_STOP: Record<StatusKey, Record<Side, { tone: number; chroma: number }>> = {
|
|
321
|
-
good: { light: { tone: 45.75, chroma: 37.75 }, dark: { tone: 70.23, chroma: 53.23 } },
|
|
322
|
-
warn: { light: { tone: 54.64, chroma: 61.12 }, dark: { tone: 72.34, chroma: 62.55 } },
|
|
323
|
-
bad: { light: { tone: 43.86, chroma: 54.46 }, dark: { tone: 58.58, chroma: 53.79 } },
|
|
324
|
-
}
|
|
325
|
-
|
|
326
320
|
/**
|
|
327
321
|
* Continuous derivation parameters — the derivation CORE's inputs, decoupled from the -5..5
|
|
328
322
|
* slider levels. `deriveTokens` maps levels onto these (with the re-centered baselines baked in).
|
|
@@ -352,16 +346,30 @@ export type DerivedPalette = {
|
|
|
352
346
|
status: Record<StatusKey, ColorPair>
|
|
353
347
|
}
|
|
354
348
|
|
|
349
|
+
/** The accepted `lightLevel` / `darkLevel` range; `deriveTokens` clamps to it. */
|
|
350
|
+
export const DERIVE_LEVEL_RANGE = { min: -5, max: 5 } as const
|
|
351
|
+
|
|
352
|
+
function clampLevel(level: number): number {
|
|
353
|
+
return Number.isFinite(level) ? clamp(level, DERIVE_LEVEL_RANGE.min, DERIVE_LEVEL_RANGE.max) : 0
|
|
354
|
+
}
|
|
355
|
+
|
|
355
356
|
/** Derive the full palette from a seed accent + neutral family + surface levels.
|
|
356
357
|
* Public level-based entry: maps the -5..5 sliders onto `DeriveParams` (vibrancy x0.72 center,
|
|
357
|
-
* surface +2 baseline) and delegates to `deriveTokensRaw`.
|
|
358
|
+
* surface +2 baseline) and delegates to `deriveTokensRaw`.
|
|
359
|
+
*
|
|
360
|
+
* `lightLevel` / `darkLevel` are clamped to {@link DERIVE_LEVEL_RANGE} (non-finite → 0).
|
|
361
|
+
* @throws Error when no status tone clears 4.5:1 on every text surface — unreachable for clamped
|
|
362
|
+
* levels (the test grid proves it); only a raw shift outside the slider range gets there.
|
|
363
|
+
*/
|
|
358
364
|
export function deriveTokens(config: DeriveConfig): DerivedPalette {
|
|
359
365
|
assertValidAccentHex(config.accent)
|
|
360
366
|
return deriveTokensRaw(config, {
|
|
361
367
|
chromaMult: vibrancyChromaMult(config.vibrancy),
|
|
362
368
|
accentToneShift: config.accentBrightness * ACCENT_BRIGHTNESS_TONE_STEP,
|
|
363
|
-
lightSurfaceShift:
|
|
364
|
-
|
|
369
|
+
lightSurfaceShift:
|
|
370
|
+
SURFACE_LEVEL_TONE_STEP * clampLevel(config.lightLevel) + SURFACE_BASELINE_TONE_SHIFT,
|
|
371
|
+
darkSurfaceShift:
|
|
372
|
+
SURFACE_LEVEL_TONE_STEP * clampLevel(config.darkLevel) + SURFACE_BASELINE_TONE_SHIFT,
|
|
365
373
|
})
|
|
366
374
|
}
|
|
367
375
|
|
|
@@ -452,22 +460,7 @@ export function deriveTokensRaw(
|
|
|
452
460
|
}
|
|
453
461
|
}
|
|
454
462
|
|
|
455
|
-
const status =
|
|
456
|
-
for (const key of Object.keys(STATUS_HUE) as StatusKey[]) {
|
|
457
|
-
const hue = STATUS_HUE[key]
|
|
458
|
-
status[key] = {
|
|
459
|
-
light: hctToHex({
|
|
460
|
-
hue,
|
|
461
|
-
chroma: STATUS_STOP[key].light.chroma,
|
|
462
|
-
tone: STATUS_STOP[key].light.tone,
|
|
463
|
-
}),
|
|
464
|
-
dark: hctToHex({
|
|
465
|
-
hue,
|
|
466
|
-
chroma: STATUS_STOP[key].dark.chroma,
|
|
467
|
-
tone: STATUS_STOP[key].dark.tone,
|
|
468
|
-
}),
|
|
469
|
-
}
|
|
470
|
-
}
|
|
463
|
+
const status = deriveStatusHexes(surface)
|
|
471
464
|
|
|
472
465
|
return {
|
|
473
466
|
accent: { light: accentFill, dark: accentInkDark },
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status text solver — the `--vx-status-good|warn|bad` solids are painted as TEXT (`DeltaBadge`,
|
|
3
|
+
* a toned breakdown row), so each must clear WCAG AA on every text surface of the palette it ships
|
|
4
|
+
* in. The calibrated stops below are kept unchanged when they already clear every surface (the
|
|
5
|
+
* default config); otherwise each walks along its lightness axis only — light darkens, dark
|
|
6
|
+
* lightens, hue preserved (chroma may clip at the gamut edge) — to the first tone that does.
|
|
7
|
+
*/
|
|
8
|
+
import type { ColorPair } from './core'
|
|
9
|
+
import type { StatusKey, SurfaceKey } from './derive'
|
|
10
|
+
import { contrastRatio, hctToHex } from './hct'
|
|
11
|
+
|
|
12
|
+
type Side = 'light' | 'dark'
|
|
13
|
+
type Stop = { readonly tone: number; readonly chroma: number }
|
|
14
|
+
|
|
15
|
+
export const STATUS_HUE: Readonly<Record<StatusKey, number>> = {
|
|
16
|
+
good: 151.975,
|
|
17
|
+
warn: 76.64,
|
|
18
|
+
bad: 29.905,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const STATUS_STOP: Readonly<Record<StatusKey, Readonly<Record<Side, Stop>>>> = {
|
|
22
|
+
good: { light: { tone: 45.75, chroma: 37.75 }, dark: { tone: 70.23, chroma: 53.23 } },
|
|
23
|
+
warn: { light: { tone: 46, chroma: 61.12 }, dark: { tone: 72.34, chroma: 62.55 } },
|
|
24
|
+
bad: { light: { tone: 43.86, chroma: 54.46 }, dark: { tone: 66.5, chroma: 53.79 } },
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The surfaces status text is painted on — exhaustive, so a new `SurfaceKey` must pick a side. */
|
|
28
|
+
export const STATUS_TEXT_SURFACES: Readonly<Record<SurfaceKey, boolean>> = {
|
|
29
|
+
bg: true,
|
|
30
|
+
panel: true,
|
|
31
|
+
panelHover: true,
|
|
32
|
+
elevated: true,
|
|
33
|
+
subtle: true,
|
|
34
|
+
field: true,
|
|
35
|
+
border: false,
|
|
36
|
+
hairline: false,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const STATUS_TEXT_CONTRAST_MIN = 4.5
|
|
40
|
+
export const STATUS_TONE_STEP = 0.25
|
|
41
|
+
|
|
42
|
+
const TEXT_SURFACE_KEYS = (Object.keys(STATUS_TEXT_SURFACES) as SurfaceKey[]).filter(
|
|
43
|
+
(key) => STATUS_TEXT_SURFACES[key],
|
|
44
|
+
)
|
|
45
|
+
const STATUS_KEYS = Object.keys(STATUS_HUE) as StatusKey[]
|
|
46
|
+
|
|
47
|
+
/** The hex at the `step`-th tone from `stop` along the side's lightness axis (0 = the stop). */
|
|
48
|
+
export function statusHexAtStep(key: StatusKey, side: Side, step: number): string {
|
|
49
|
+
const stop = STATUS_STOP[key][side]
|
|
50
|
+
const direction = side === 'light' ? -1 : 1
|
|
51
|
+
return hctToHex({
|
|
52
|
+
hue: STATUS_HUE[key],
|
|
53
|
+
chroma: stop.chroma,
|
|
54
|
+
tone: stop.tone + direction * step * STATUS_TONE_STEP,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function clearsEverySurface(hex: string, side: Side, surfaces: Record<SurfaceKey, ColorPair>) {
|
|
59
|
+
return TEXT_SURFACE_KEYS.every(
|
|
60
|
+
(key) => contrastRatio(hex, surfaces[key][side]) >= STATUS_TEXT_CONTRAST_MIN,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function solve(key: StatusKey, side: Side, surfaces: Record<SurfaceKey, ColorPair>): string {
|
|
65
|
+
const { tone } = STATUS_STOP[key][side]
|
|
66
|
+
const maxSteps = Math.floor((side === 'light' ? tone : 100 - tone) / STATUS_TONE_STEP)
|
|
67
|
+
for (let step = 0; step <= maxSteps; step++) {
|
|
68
|
+
const hex = statusHexAtStep(key, side, step)
|
|
69
|
+
if (clearsEverySurface(hex, side, surfaces)) return hex
|
|
70
|
+
}
|
|
71
|
+
throw new Error(
|
|
72
|
+
`status text: no ${side} ${key} tone reaches ${STATUS_TEXT_CONTRAST_MIN}:1 on every surface`,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The three status solids for a derived palette's surfaces. */
|
|
77
|
+
export function deriveStatusHexes(
|
|
78
|
+
surfaces: Record<SurfaceKey, ColorPair>,
|
|
79
|
+
): Record<StatusKey, ColorPair> {
|
|
80
|
+
const status = {} as Record<StatusKey, ColorPair>
|
|
81
|
+
for (const key of STATUS_KEYS) {
|
|
82
|
+
status[key] = { light: solve(key, 'light', surfaces), dark: solve(key, 'dark', surfaces) }
|
|
83
|
+
}
|
|
84
|
+
return status
|
|
85
|
+
}
|