Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: make the contrast slider reach text and hover states (#11647)

Michael Han6f7868dbb7a1
diff --git a/studio/frontend/public/reload-snapshot.js b/studio/frontend/public/reload-snapshot.js
index 6bc6f7aa986..ff0944c276b 100644
--- a/studio/frontend/public/reload-snapshot.js
+++ b/studio/frontend/public/reload-snapshot.js
@@ -47,7 +47,12 @@
"--chart-1",
"--contrast-control-mix",
"--contrast-edge-gain",
+ "--contrast-fill-mix",
+ "--contrast-ink-mix",
+ "--contrast-ink-target",
"--contrast-line-mix",
+ "--contrast-panel-ink-target",
+ "--contrast-panel-target",
"--contrast-state-mix",
"--contrast-surface-mix",
"--contrast-target",
@@ -63,6 +68,7 @@
"--font-mono",
"--font-sans",
"--foreground",
+ "--foreground-base",
"--primary",
"--primary-foreground",
"--ui-font-size-scale",
diff --git a/studio/frontend/src/features/settings/stores/appearance-custom-store.ts b/studio/frontend/src/features/settings/stores/appearance-custom-store.ts
index de9f3d777dd..8d839662297 100644
--- a/studio/frontend/src/features/settings/stores/appearance-custom-store.ts
+++ b/studio/frontend/src/features/settings/stores/appearance-custom-store.ts
@@ -288,9 +288,18 @@ export const CONTRAST_SURFACE_MIX_VAR = "--contrast-surface-mix";
export const CONTRAST_LINE_MIX_VAR = "--contrast-line-mix";
/** Control outlines and switch tracks, which fade less far than a divider. */
export const CONTRAST_CONTROL_MIX_VAR = "--contrast-control-mix";
+/** Chips, secondary buttons and muted hovers, between the planes and the states. */
+export const CONTRAST_FILL_MIX_VAR = "--contrast-fill-mix";
/** Hover and selection fills, which fade less far than the surface under them. */
export const CONTRAST_STATE_MIX_VAR = "--contrast-state-mix";
export const CONTRAST_TEXT_MIX_VAR = "--contrast-text-mix";
+/** Primary ink: how far it heads for pure black/white, or into the page. */
+export const CONTRAST_INK_MIX_VAR = "--contrast-ink-mix";
+export const CONTRAST_INK_TARGET_VAR = "--contrast-ink-target";
+/** Ink on palette surfaces (cards, menus, sidebar), which custom colors keep. */
+export const CONTRAST_PANEL_INK_TARGET_VAR = "--contrast-panel-ink-target";
+/** Surfaces, fills and lines on those palette surfaces. */
+export const CONTRAST_PANEL_TARGET_VAR = "--contrast-panel-target";
/** Multipliers for the hand-written washes that stand in for those tokens. */
export const CONTRAST_WASH_GAIN_VAR = "--contrast-wash-gain";
export const CONTRAST_EDGE_GAIN_VAR = "--contrast-edge-gain";
@@ -678,6 +687,14 @@ const PALETTE_SURFACES: Record<
dark: { background: "#181818", elevated: "#272727" },
};
+/**
+ * Black for ink darker than its page, white for lighter. Raising pushes ink
+ * away from the surface it sits on, so a mid grey never heads into its page.
+ */
+function inkPole(ink: string, page: string): string {
+ return hexLuminance(ink) <= hexLuminance(page) ? "#000000" : "#ffffff";
+}
+
function minimumAccentTextContrast(
accent: string,
backgrounds: readonly string[],
@@ -862,7 +879,10 @@ export function applyCustomizationToDocument(
setVar(name, accent ? readableForeground(accent) : null);
}
setVar("--background", colors.background);
- setVar("--foreground", colors.foreground);
+ // Written as the base so a custom foreground still follows the contrast curve.
+ setVar("--foreground-base", colors.foreground);
+ // Clear the token older builds wrote inline; it would pin the ink.
+ setVar("--foreground", null);
// keep the full-width inset from making narrow panes smaller than wide.
setVar(
"--custom-chat-max-width",
@@ -962,40 +982,63 @@ export function applyCustomizationToDocument(
"--contrast-target",
raising ? "var(--foreground)" : "var(--background)",
);
- // Not symmetric. Lowering flattens, so surfaces and lines collapse most
- // of the way into the page. Raising only needs a nudge: a card mixed far
- // toward the foreground reads as a block, not a surface. Neither floor
- // reaches the page colour, a menu still has to be findable at 0.
- setVar(CONTRAST_SURFACE_MIX_VAR, mix(raising ? 8 : 70));
+ // Not symmetric. Lowering flattens surfaces most of the way into the page.
+ // Raising only nudges them: a card pushed far toward the foreground reads
+ // as a block. Neither floor reaches the page, so a menu stays findable.
+ setVar(CONTRAST_SURFACE_MIX_VAR, mix(raising ? 4 : 70));
+ setVar(CONTRAST_FILL_MIX_VAR, mix(raising ? 10 : 62));
setVar(CONTRAST_LINE_MIX_VAR, mix(raising ? 45 : 80));
setVar(CONTRAST_CONTROL_MIX_VAR, mix(raising ? 45 : 55));
- // Hover and selection fills stop well short of the surfaces they sit on.
- // On the surface curve they collapsed toward the page faster than the
- // sidebar and cards did, so at the bottom the lit row was darker than its
- // own background: the pointer stopped telling you where it was.
- setVar(CONTRAST_STATE_MIX_VAR, mix(raising ? 8 : 30));
- // Text sits on a gentler curve at both ends: it has to stay readable.
- setVar(CONTRAST_TEXT_MIX_VAR, mix(40));
- // Controls that wash the page with translucent white or black instead of
- // taking a token multiply their authored alpha by these, so they move in
- // step with the tokens above.
+ // Hover and selection: steepest curve when raising, so the step to the lit
+ // row grows; short of the surfaces when lowering, so it never sinks below.
+ setVar(CONTRAST_STATE_MIX_VAR, mix(raising ? 16 : 55));
+ // Secondary text stays readable at both ends.
+ setVar(CONTRAST_TEXT_MIX_VAR, mix(raising ? 40 : 30));
+ // Primary ink heads for pure black/white raising, and into the page
+ // lowering, stopping well short so body copy stays readable at 0.
+ const palettePole = resolved === "light" ? "#000000" : "#ffffff";
+ // Palette surfaces keep their colours under a custom foreground, so they
+ // raise toward the palette pole. Unset, they share --contrast-target.
+ setVar(
+ CONTRAST_PANEL_TARGET_VAR,
+ raising && colors.foreground ? palettePole : null,
+ );
+ setVar(
+ CONTRAST_INK_TARGET_VAR,
+ raising
+ ? colors.foreground
+ ? inkPole(
+ colors.foreground,
+ colors.background ?? paletteSurfaces.background,
+ )
+ : palettePole
+ : "var(--background)",
+ );
+ setVar(
+ CONTRAST_PANEL_INK_TARGET_VAR,
+ raising ? palettePole : "var(--background)",
+ );
+ setVar(CONTRAST_INK_MIX_VAR, mix(raising ? 70 : 30));
+ // Hand-written washes multiply their alpha by these to match the tokens.
const gain = (span: number) =>
(raising ? 1 + distance * span : 1 - distance * span).toFixed(3);
- // Lowering keeps most of a wash rather than a quarter of it. These washes
- // are the chrome you aim at, not decoration: tab tracks, header pills,
- // chips, filter triggers. At a quarter strength a 4% fill landed 2 levels
- // off the page, so the unselected half of a segmented control and the whole
- // Hub toolbar read as bare background.
- setVar(CONTRAST_WASH_GAIN_VAR, gain(raising ? 0.7 : 0.4));
+ // Lowering keeps most of a wash: tab tracks, chips and filter triggers are
+ // chrome you aim at. Raising doubles it, level with the state tokens.
+ setVar(CONTRAST_WASH_GAIN_VAR, gain(raising ? 1 : 0.4));
setVar(CONTRAST_EDGE_GAIN_VAR, gain(raising ? 0.9 : 0.8));
} else {
el.removeAttribute("data-contrast-adjust");
setVar("--contrast-target", null);
setVar(CONTRAST_SURFACE_MIX_VAR, null);
+ setVar(CONTRAST_FILL_MIX_VAR, null);
setVar(CONTRAST_LINE_MIX_VAR, null);
setVar(CONTRAST_CONTROL_MIX_VAR, null);
setVar(CONTRAST_STATE_MIX_VAR, null);
setVar(CONTRAST_TEXT_MIX_VAR, null);
+ setVar(CONTRAST_INK_TARGET_VAR, null);
+ setVar(CONTRAST_PANEL_INK_TARGET_VAR, null);
+ setVar(CONTRAST_PANEL_TARGET_VAR, null);
+ setVar(CONTRAST_INK_MIX_VAR, null);
setVar(CONTRAST_WASH_GAIN_VAR, null);
setVar(CONTRAST_EDGE_GAIN_VAR, null);
}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index b228d14f471..92a7b3e804e 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -180,21 +180,21 @@
/* Slightly warm off white; every page (and the chat surface) shares it. */
--background: #fefefd;
- --foreground: oklch(0.2686 0 0);
+ --foreground-base: oklch(0.2686 0 0);
--card-base: oklch(1 0 0);
- --card-foreground: oklch(0.1281 0.0179 169.2764);
+ --card-foreground-base: oklch(0.1281 0.0179 169.2764);
--popover-base: oklch(1 0 0);
- --popover-foreground: oklch(0.1281 0.0179 169.2764);
+ --popover-foreground-base: oklch(0.1281 0.0179 169.2764);
--primary: #17b88b;
--primary-foreground: oklch(1 0 0);
--secondary-base: oklch(0.9596 0.0275 167.8295);
- --secondary-foreground: oklch(0.2868 0.0649 159.9823);
+ --secondary-foreground-base: oklch(0.2868 0.0649 159.9823);
--muted-base: oklch(0.9702 0 0);
--muted-foreground: oklch(0.5486 0 0);
/* Hover/active washes are neutral grey (matches the sidebar), not the
brand green; green stays on primary controls only. */
--accent-base: #ececec;
- --accent-foreground: #262626;
+ --accent-foreground-base: #262626;
--destructive: oklch(0.6368 0.2078 25.3313);
/* Bypass permissions accent: bright, saturated yellow (not dark gold). */
--bypass: #c99d00;
@@ -216,11 +216,11 @@
/* White sidebar against the warm off-white page; the tone difference is
the separator now that the right-edge divider is gone. */
--sidebar-base: #ffffff;
- --sidebar-foreground: oklch(0.1281 0.0179 169.2764);
+ --sidebar-foreground-base: oklch(0.1281 0.0179 169.2764);
--sidebar-primary: #17b88b;
--sidebar-primary-foreground: oklch(1 0 0);
--sidebar-accent-base: #ececec;
- --sidebar-accent-foreground: #262626;
+ --sidebar-accent-foreground-base: #262626;
/* Selected tab on the line variant, a step above the page. */
--tabs-line-indicator-base: #ececec;
--sidebar-border-base: #f2f2f2;
@@ -263,10 +263,10 @@
--tracking-normal: 0em;
/* Hex (not OKLCH) so the rendered surface matches the design mockup pixel-for-pixel. */
- --nav-fg: #383835;
- --nav-fg-muted: #858279;
+ --nav-fg-base: #383835;
+ --nav-fg-muted-base: #858279;
--nav-surface-hover-base: #f0f0f0;
- --nav-icon-idle: #8f8f8f;
+ --nav-icon-idle-base: #8f8f8f;
--nav-beta-border: #e0ded6;
--panel-surface-hover-base: #ebebeb;
/* Right-side chat-parameters panel: matches the chat content
@@ -295,7 +295,7 @@
Mid-dark gray on the light surface — visible enough to read as
active controls, not so dark that they compete with message
text. */
- --chat-icon-fg: #555555;
+ --chat-icon-fg-base: #555555;
--chat-icon-fg-hover: var(--foreground);
--chat-icon-bg-hover-base: #ededec;
@@ -389,22 +389,22 @@
sidebar/cards, #3a3a3a hover, #dfdfdf ink. Palette dark blocks override
only accent tokens so dark mode stays consistent across themes. */
--background: #181818;
- --foreground: #dfdfdf;
+ --foreground-base: #dfdfdf;
--card-base: #272727;
- --card-foreground: #dfdfdf;
+ --card-foreground-base: #dfdfdf;
--popover-base: #272727;
- --popover-foreground: #dfdfdf;
+ --popover-foreground-base: #dfdfdf;
--primary: #17b88b;
--primary-foreground: oklch(1 0 0);
--secondary-base: #303030;
- --secondary-foreground: #dfdfdf;
+ --secondary-foreground-base: #dfdfdf;
--muted-base: #303030;
/* Secondary text: settings descriptions, empty states, captions.
Under the ink, still ~7:1 on the dialog surface. */
--muted-foreground: #b0b0b0;
/* Shared hover tone: one step over --popover. */
--accent-base: #3a3a3a;
- --accent-foreground: #dfdfdf;
+ --accent-foreground-base: #dfdfdf;
--destructive: oklch(0.6368 0.2078 25.3313);
/* Bypass permissions accent: bright, saturated neon yellow on dark. */
--bypass: #ffd60a;
@@ -423,11 +423,11 @@
/* A step over --background; the tone difference is the separator.
Matches --card, so every elevated surface reads as one plane. */
--sidebar-base: #272727;
- --sidebar-foreground: #dfdfdf;
+ --sidebar-foreground-base: #dfdfdf;
--sidebar-primary: #17b88b;
--sidebar-primary-foreground: oklch(1 0 0);
--sidebar-accent-base: #3a3a3a;
- --sidebar-accent-foreground: #dfdfdf;
+ --sidebar-accent-foreground-base: #dfdfdf;
--tabs-line-indicator-base: #3a3a3a;
--sidebar-border-base: #3a3a3a;
--sidebar-ring: #dfdfdf;
@@ -455,11 +455,11 @@
--shadow-xl: 0px 0px 0px 0px hsl(0 0% 0% / 0), 0px 8px 10px 0px hsl(0 0% 0% / 0);
--shadow-2xl: 0px 0px 0px 0px hsl(0 0% 0% / 0);
- --nav-fg: #dfdfdf;
- --nav-fg-muted: #b0b0b0;
+ --nav-fg-base: #dfdfdf;
+ --nav-fg-muted-base: #b0b0b0;
--nav-surface-hover-base: #3a3a3a;
/* Lifted with the surfaces: the sidebar is #272727, not #1f1f1f. */
- --nav-icon-idle: #767676;
+ --nav-icon-idle-base: #767676;
--nav-beta-border: #3a3a3a;
--panel-surface-hover-base: #3a3a3a;
/* Right-side chat-parameters panel: matches the chat content
@@ -479,7 +479,7 @@
--panel-slider-fg-base: #b0b0b0;
/* Chat action icons: under the ink so they read as controls, not text.
Hover restores full --foreground. */
- --chat-icon-fg: #c4c4c4;
+ --chat-icon-fg-base: #c4c4c4;
--chat-icon-fg-hover: var(--foreground);
--chat-icon-bg-hover-base: #3a3a3a;
}
@@ -506,11 +506,11 @@
surfaces in dark, neutral gray hovers, and blue (#339cff) as the accent. */
:root[data-palette="classic"]:not(.dark) {
--background: #ffffff;
- --foreground: #1a1c1f;
+ --foreground-base: #1a1c1f;
--card-base: #ffffff;
- --card-foreground: #1a1c1f;
+ --card-foreground-base: #1a1c1f;
--popover-base: #ffffff;
- --popover-foreground: #1a1c1f;
+ --popover-foreground-base: #1a1c1f;
/* Neutral black primary; blue is reserved for small controls via
--control-accent (toggles, badges, focus rings). */
--primary: #0d0d0d;
@@ -518,13 +518,13 @@
--control-accent: #339cff;
--control-accent-foreground: #ffffff;
--secondary-base: #f5f5f5;
- --secondary-foreground: #1a1c1f;
+ --secondary-foreground-base: #1a1c1f;
--muted-base: #f7f7f7;
/* 4.88:1 on white. #8f8f8f was 3.23:1, under AA for normal text and the
only light palette below it; standard is 4.84:1 and minimal 5.02:1. */
--muted-foreground: #717171;
--accent-base: #ececec;
- --accent-foreground: #1a1c1f;
+ --accent-foreground-base: #1a1c1f;
--bypass: #9a7b1e;
--border-base: #e6e6e6;
--input-base: #e6e6e6;
@@ -537,18 +537,18 @@
/* Same as the standard palette; the sidebar surface does not change
with the palette. */
--sidebar-base: #ffffff;
- --sidebar-foreground: #1a1c1f;
+ --sidebar-foreground-base: #1a1c1f;
--sidebar-primary: #0d0d0d;
--sidebar-primary-foreground: #ffffff;
--sidebar-accent-base: #ececec;
- --sidebar-accent-foreground: #1a1c1f;
+ --sidebar-accent-foreground-base: #1a1c1f;
--sidebar-border-base: #f2f2f2;
--sidebar-ring: #1a1c1f;
- --nav-fg: #2d2f31;
- --nav-fg-muted: #8f8f8f;
+ --nav-fg-base: #2d2f31;
+ --nav-fg-muted-base: #8f8f8f;
--nav-surface-hover-base: #ececec;
- --nav-icon-idle: #8f8f8f;
+ --nav-icon-idle-base: #8f8f8f;
--nav-beta-border: #e0e0e0;
--panel-surface-hover-base: #ececec;
--panel-input-surface-base: #f4f4f4;
@@ -556,7 +556,7 @@
/* Same lift on the contrast-slider base: #7a7c7e was 4.19:1. Now 4.90:1. */
--panel-surface-fg-muted: #6f7174;
--panel-slider-fg-base: #9b9d9f;
- --chat-icon-fg: #5d5f61;
+ --chat-icon-fg-base: #5d5f61;
--chat-icon-bg-hover-base: #ececec;
}
@@ -583,19 +583,19 @@
/* -------------------------------- Minimal -------------------------------- */
:root[data-palette="minimal"]:not(.dark) {
--background: #ffffff;
- --foreground: #171717;
+ --foreground-base: #171717;
--card-base: #ffffff;
- --card-foreground: #171717;
+ --card-foreground-base: #171717;
--popover-base: #ffffff;
- --popover-foreground: #171717;
+ --popover-foreground-base: #171717;
--primary: #171717;
--primary-foreground: #ffffff;
--secondary-base: #f5f5f5;
- --secondary-foreground: #262626;
+ --secondary-foreground-base: #262626;
--muted-base: #f5f5f5;
--muted-foreground: #6f6f6f;
--accent-base: #ebebeb;
- --accent-foreground: #171717;
+ --accent-foreground-base: #171717;
--bypass: #6f6f6f;
--border-base: #e2e2e2;
--input-base: #e2e2e2;
@@ -607,25 +607,25 @@
--chart-5: #d1d1d1;
/* White sidebar on white content; the border alone is the separator. */
--sidebar-base: #ffffff;
- --sidebar-foreground: #171717;
+ --sidebar-foreground-base: #171717;
--sidebar-primary: #171717;
--sidebar-primary-foreground: #ffffff;
--sidebar-accent-base: #ebebeb;
- --sidebar-accent-foreground: #171717;
+ --sidebar-accent-foreground-base: #171717;
--sidebar-border-base: #e8e8e8;
--sidebar-ring: #171717;
- --nav-fg: #333333;
- --nav-fg-muted: #8a8a8a;
+ --nav-fg-base: #333333;
+ --nav-fg-muted-base: #8a8a8a;
--nav-surface-hover-base: #efefef;
- --nav-icon-idle: #8f8f8f;
+ --nav-icon-idle-base: #8f8f8f;
--nav-beta-border: #dddddd;
--panel-surface-hover-base: #ececec;
--panel-input-surface-base: #f4f4f4;
--panel-input-surface-hover-base: #ededed;
--panel-surface-fg-muted: #757575;
--panel-slider-fg-base: #9b9b9b;
- --chat-icon-fg: #555555;
+ --chat-icon-fg-base: #555555;
--chat-icon-bg-hover-base: #ececec;
}
@@ -657,11 +657,8 @@
/* Contrast slider (Settings > Appearance).
- The palettes above author their surfaces and lines as --*-base; these two
- rules are what the app reads, so the slider retunes every card, menu row,
- button, input pill and hairline from one place. At the default the store
- sets nothing, this rule is the identity, and the palettes render as
- authored. */
+ Palettes author surfaces, lines and text as --*-base; the app reads the
+ tokens derived below. At the default this block is the identity. */
:root {
/* Boxes and buttons: the fill that lifts a surface off the page. */
--card: var(--card-base);
@@ -686,39 +683,66 @@
--sidebar-border: var(--sidebar-border-base);
/* Slider fill and thumb, the one panel control that takes neither. */
--panel-slider-fg: var(--panel-slider-fg-base);
+ /* Ink: body copy, headings, menu and sidebar labels. */
+ --foreground: var(--foreground-base);
+ --card-foreground: var(--card-foreground-base);
+ --popover-foreground: var(--popover-foreground-base);
+ --secondary-foreground: var(--secondary-foreground-base);
+ --accent-foreground: var(--accent-foreground-base);
+ --sidebar-foreground: var(--sidebar-foreground-base);
+ --sidebar-accent-foreground: var(--sidebar-accent-foreground-base);
+ --nav-fg: var(--nav-fg-base);
+ /* Quiet ink: idle nav labels and icons, chat action icons. */
+ --nav-fg-muted: var(--nav-fg-muted-base);
+ --nav-icon-idle: var(--nav-icon-idle-base);
+ --chat-icon-fg: var(--chat-icon-fg-base);
}
-/* Off the default, each token is mixed toward --contrast-target (foreground
- above 50, background below) by the amount its group takes. See
- applyCustomizationToDocument for the curves. Beats the palette blocks on
- specificity, so it reaches all three palettes. */
+/* Off the default, each token mixes toward --contrast-target (foreground
+ above 50, background below). Curves live in applyCustomizationToDocument.
+ Ink mixes toward pure black or white instead when raising, so text gets
+ crisper rather than the surfaces going grey. Palette surfaces and fills
+ take --contrast-panel-target when set, so a custom foreground of the other
+ polarity cannot wash them into themselves. Lines are drawn on the page too,
+ so they take the page target here and the panel one on palette surfaces. */
html[data-contrast-adjust] {
- --card: color-mix(in oklab, var(--card-base), var(--contrast-target) var(--contrast-surface-mix));
+ --card: color-mix(in oklab, var(--card-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
/* Same curve as its rows, so the step between them survives the slider. */
- --sidebar: color-mix(in oklab, var(--sidebar-base), var(--contrast-target) var(--contrast-surface-mix));
- --popover: color-mix(in oklab, var(--popover-base), var(--contrast-target) var(--contrast-surface-mix));
- --secondary: color-mix(in oklab, var(--secondary-base), var(--contrast-target) var(--contrast-surface-mix));
- --muted: color-mix(in oklab, var(--muted-base), var(--contrast-target) var(--contrast-surface-mix));
- /* Hover and selection fills take --contrast-state-mix, a shorter curve than
- the surfaces they sit on. Sharing the surface curve, they fell toward the
- page at the same rate as the sidebar and the cards, so near the bottom a
- lit row was no lighter than its own background. The fallback keeps a
- snapshot written before this token on the old behaviour. */
- --accent: color-mix(in oklab, var(--accent-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));
- --nav-surface-hover: color-mix(in oklab, var(--nav-surface-hover-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));
- --panel-surface-hover: color-mix(in oklab, var(--panel-surface-hover-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));
- --panel-input-surface: color-mix(in oklab, var(--panel-input-surface-base), var(--contrast-target) var(--contrast-surface-mix));
+ --sidebar: color-mix(in oklab, var(--sidebar-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
+ --popover: color-mix(in oklab, var(--popover-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
+ /* Chips and secondary buttons: between the planes and the lit rows. */
+ --secondary: color-mix(in oklab, var(--secondary-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-fill-mix, var(--contrast-surface-mix)));
+ --muted: color-mix(in oklab, var(--muted-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-fill-mix, var(--contrast-surface-mix)));
+ /* Hover and selection fills: shorter than the surfaces when lowering, so a
+ lit row never sinks below its background; longest when raising, so the
+ step to the lit row grows with the slider. */
+ --accent: color-mix(in oklab, var(--accent-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-state-mix, var(--contrast-surface-mix)));
+ --nav-surface-hover: color-mix(in oklab, var(--nav-surface-hover-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-state-mix, var(--contrast-surface-mix)));
+ --panel-surface-hover: color-mix(in oklab, var(--panel-surface-hover-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-state-mix, var(--contrast-surface-mix)));
+ --panel-input-surface: color-mix(in oklab, var(--panel-input-surface-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
/* Same curve as its resting twin, or the hover inverts at high contrast. */
- --panel-input-surface-hover: color-mix(in oklab, var(--panel-input-surface-hover-base), var(--contrast-target) var(--contrast-surface-mix));
- /* Sidebar and model picker rows, and the chat control hovers. */
- --sidebar-accent: color-mix(in oklab, var(--sidebar-accent-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));
+ --panel-input-surface-hover: color-mix(in oklab, var(--panel-input-surface-hover-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
+ /* Sidebar and model picker rows, and the chat control hovers. Those sit
+ on the page, so they take the page target like the chat icons. */
+ --sidebar-accent: color-mix(in oklab, var(--sidebar-accent-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-state-mix, var(--contrast-surface-mix)));
--chat-icon-bg-hover: color-mix(in oklab, var(--chat-icon-bg-hover-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));
- --tabs-line-indicator: color-mix(in oklab, var(--tabs-line-indicator-base), var(--contrast-target) var(--contrast-surface-mix));
+ --tabs-line-indicator: color-mix(in oklab, var(--tabs-line-indicator-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-surface-mix));
--border: color-mix(in oklab, var(--border-base), var(--contrast-target) var(--contrast-line-mix));
/* Control outlines and switch tracks stop short of the hairlines: an
affordance still has to be findable at the bottom of the range. */
--input: color-mix(in oklab, var(--input-base), var(--contrast-target) var(--contrast-control-mix));
- --sidebar-border: color-mix(in oklab, var(--sidebar-border-base), var(--contrast-target) var(--contrast-line-mix));
+ --sidebar-border: color-mix(in oklab, var(--sidebar-border-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-line-mix));
+ /* Ink. The 0% fallback is the identity for older reload snapshots. Palette
+ surfaces keep their colours under a custom page, so their ink takes its
+ own target. */
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-ink-target, transparent) var(--contrast-ink-mix, 0%));
+ --card-foreground: color-mix(in oklab, var(--card-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --popover-foreground: color-mix(in oklab, var(--popover-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --secondary-foreground: color-mix(in oklab, var(--secondary-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --accent-foreground: color-mix(in oklab, var(--accent-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --sidebar-foreground: color-mix(in oklab, var(--sidebar-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --sidebar-accent-foreground: color-mix(in oklab, var(--sidebar-accent-foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --nav-fg: color-mix(in oklab, var(--nav-fg-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
/* Secondary text keeps a gentler curve, it has to stay readable at both
ends. --panel-surface-fg-muted is its stable base. */
--muted-foreground: color-mix(
@@ -726,6 +750,11 @@ html[data-contrast-adjust] {
var(--panel-surface-fg-muted),
var(--contrast-target) var(--contrast-text-mix)
);
+ /* Quiet ink, on the --muted-foreground curve. Nav ink sits on palette
+ surfaces, so it takes their target; chat icons sit on the page. */
+ --nav-fg-muted: color-mix(in oklab, var(--nav-fg-muted-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix));
+ --nav-icon-idle: color-mix(in oklab, var(--nav-icon-idle-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix));
+ --chat-icon-fg: color-mix(in oklab, var(--chat-icon-fg-base), var(--contrast-target) var(--contrast-text-mix));
/* Slider fill and thumb read as marks on the panel, so they take the
text curve rather than the surface one. */
--panel-slider-fg: color-mix(
@@ -735,6 +764,84 @@ html[data-contrast-adjust] {
);
}
+/* Body text, muted text and lines on palette surfaces head for their pole,
+ and back to the page target on a page-coloured pane inside one. Menus
+ paint their surface in CSS, so they are listed by class, as is the Hub's
+ download button. Without a custom foreground both targets match the root,
+ so every rule here equals the root value. */
+html[data-contrast-adjust] :is(.bg-card, .bg-popover, .bg-sidebar, .hub-download-fab, .hub-download-panel, .menu-soft-surface-up, .menu-soft-surface) {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-control-mix));
+}
+html[data-contrast-adjust] :is(.bg-card, .bg-popover, .bg-sidebar, .hub-download-fab, .hub-download-panel, .menu-soft-surface-up, .menu-soft-surface) .bg-background:not(.dark [class*="dark:bg-"]:not([class*="dark:bg-background"])) {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-ink-target, transparent) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-target) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-target) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-target) var(--contrast-control-mix));
+}
+/* Surfaces the stylesheet paints as cards in dark only. Their page panes
+ (the Settings content pane) return to the page. A bg-background that
+ repaints itself in dark (dark:bg-*) is not the page there, in either rule. */
+html[data-contrast-adjust].dark :is(.dialog-soft-surface, .settings-surface, .chat-composer-surface, .unsloth-composer-surface, .unsloth-plus-menu, [data-sonner-toast]) .bg-background:not([class*="dark:bg-"]:not([class*="dark:bg-background"])) {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-ink-target, transparent) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-target) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-target) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-target) var(--contrast-control-mix));
+}
+/* Card spellings from half opacity up are cards too: their ink is palette
+ ink, so it has to head the palette's way. Dark-only ones only in dark.
+ After the resets, so a page pane that is a card in dark takes this. */
+html[data-contrast-adjust] :is(.bg-card\/50, .bg-card\/55, .bg-card\/60, .bg-card\/65, .bg-card\/70, .bg-card\/85, .bg-card\/90, .bg-card\/95, .bg-card\/96),
+html[data-contrast-adjust].dark :is(.dark\:bg-card, .dark\:bg-card\/85, .dark\:bg-card\/90, .dialog-soft-surface, .settings-surface, .chat-composer-surface, .unsloth-composer-surface, .unsloth-plus-menu, [data-sonner-toast]) {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-control-mix));
+}
+/* Hub result rows are cards in light only; dark paints them as a wash over
+ the page, which the page target already suits. */
+html[data-contrast-adjust]:not(.dark) .hub-page .hub-result-row {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-control-mix));
+}
+/* The dark Hub repaints [class*="bg-background"] and [class*="bg-card"] as
+ popovers from @layer base, so any background utility still wins. Only an
+ element with none in play (hover:bg-background at rest) is a popover. */
+html[data-contrast-adjust].dark .hub-page :is([class*="bg-background"], [class*="bg-card"]):not([class^="bg-"], [class*=" bg-"], [class*="dark:bg-"], :hover) {
+ --foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));
+ --muted-foreground: color-mix(
+ in oklab,
+ var(--panel-surface-fg-muted),
+ var(--contrast-panel-target, var(--contrast-target)) var(--contrast-text-mix)
+ );
+ --border: color-mix(in oklab, var(--border-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-line-mix));
+ --input: color-mix(in oklab, var(--input-base), var(--contrast-panel-target, var(--contrast-target)) var(--contrast-control-mix));
+}
+
/* Code font size: only overrides when the user sets an explicit size, so the
per-element Tailwind sizes stay authoritative by default. */
html[data-code-font-size] :is(pre, code, kbd, samp) {
@@ -1340,8 +1447,8 @@ html[data-chat-font] .aui-root {
@apply rounded-none bg-sidebar pt-0 pb-[calc(8px*var(--ui-space-scale,1))] pl-[calc(16px*var(--ui-space-scale,1))] pr-3 text-ui-14! leading-ui-17 font-medium normal-case focus-visible:ring-0! focus-visible:outline-none transition-shadow duration-150;
/* Muted section-header gray, matching Gemini's "Notebooks"/"Recents".
Lightened from #5f6368 so the label reads as a header, clearly
- lighter than the near-black nav items. */
- color: #80868b;
+ lighter than the near-black nav items. Follows the contrast slider. */
+ color: color-mix(in oklab, #80868b, var(--contrast-panel-target, var(--contrast-target, transparent)) var(--contrast-text-mix, 0%));
letter-spacing: 0;
}
/* These compound selectors must beat the base label's pr-3 declaration.
@@ -1359,7 +1466,7 @@ html[data-chat-font] .aui-root {
.dark .sidebar-sticky-label {
/* Muted gray, clearly dimmer than the near-white nav items (#ececee) so
"Train"/"Recents" read as section headers — like Gemini's dark mode. */
- color: #9aa0a6;
+ color: color-mix(in oklab, #9aa0a6, var(--contrast-panel-target, var(--contrast-target, transparent)) var(--contrast-text-mix, 0%));
letter-spacing: 0;
}
/* Panel input fields. Light mode matches the settings fields: white
@@ -4104,7 +4211,7 @@ body.sidebar-row-dragging * {
.dark .find-bar-surface {
/* #2c2c2c, on the same curve as --card: the bar has to stay above the
cards it floats over at every contrast, not just the default. */
- background-color: color-mix(in oklab, #2c2c2c, var(--contrast-target, transparent) var(--contrast-surface-mix, 0%));
+ background-color: color-mix(in oklab, #2c2c2c, var(--contrast-panel-target, var(--contrast-target, transparent)) var(--contrast-surface-mix, 0%));
box-shadow: 0 4px 20px 6px var(--background);
}
diff --git a/studio/frontend/tests/contrast-slider.test.ts b/studio/frontend/tests/contrast-slider.test.ts
index 737d944d132..463ce4c88d6 100644
--- a/studio/frontend/tests/contrast-slider.test.ts
+++ b/studio/frontend/tests/contrast-slider.test.ts
@@ -36,12 +36,12 @@ const SURFACE_TOKENS = [
// darker than the sidebar behind it.
"sidebar",
"popover",
- "secondary",
- "muted",
"panel-input-surface",
"panel-input-surface-hover",
"tabs-line-indicator",
];
+/** Chips, secondary buttons and the muted hovers, between planes and states. */
+const CHIP_TOKENS = ["secondary", "muted"];
/** Hover and selection fills, on a shorter curve so the state stays findable. */
const STATE_TOKENS = [
"accent",
@@ -51,7 +51,22 @@ const STATE_TOKENS = [
"chat-icon-bg-hover",
];
const LINE_TOKENS = ["border", "input", "sidebar-border"];
-const FILL_TOKENS = [...SURFACE_TOKENS, ...STATE_TOKENS];
+/** Where palette fills and lines head, so a custom foreground cannot steer them. */
+const PANEL_TARGET = "var(--contrast-panel-target, var(--contrast-target))";
+const FILL_TOKENS = [...SURFACE_TOKENS, ...CHIP_TOKENS, ...STATE_TOKENS];
+/** Body copy and labels: head for pure black/white raising, into the page lowering. */
+const INK_TOKENS = [
+ "foreground",
+ "card-foreground",
+ "popover-foreground",
+ "secondary-foreground",
+ "accent-foreground",
+ "sidebar-foreground",
+ "sidebar-accent-foreground",
+ "nav-fg",
+];
+/** Idle labels and icons, on the same curve as --muted-foreground. */
+const QUIET_INK_TOKENS = ["nav-fg-muted", "nav-icon-idle", "chat-icon-fg"];
function block(marker: string): string {
const at = CSS.indexOf(marker);
@@ -61,7 +76,12 @@ function block(marker: string): string {
}
test("the palettes author base values, never the token the app reads", () => {
- for (const token of [...FILL_TOKENS, ...LINE_TOKENS]) {
+ for (const token of [
+ ...FILL_TOKENS,
+ ...LINE_TOKENS,
+ ...INK_TOKENS,
+ ...QUIET_INK_TOKENS,
+ ]) {
const authored = CSS.match(new RegExp(`^\\t--${token}-base:`, "gm")) ?? [];
assert.ok(
authored.length >= 2,
@@ -81,7 +101,12 @@ test("the palettes author base values, never the token the app reads", () => {
test("at the default the derivation is the identity", () => {
const identity = block("--card: var(--card-base);");
- for (const token of [...FILL_TOKENS, ...LINE_TOKENS]) {
+ for (const token of [
+ ...FILL_TOKENS,
+ ...LINE_TOKENS,
+ ...INK_TOKENS,
+ ...QUIET_INK_TOKENS,
+ ]) {
assert.ok(
identity.includes(`--${token}: var(--${token}-base);`),
`--${token} does not fall back to its authored value`,
@@ -94,16 +119,26 @@ test("off the default, fills and lines each take their own curve", () => {
for (const token of SURFACE_TOKENS) {
assert.ok(
adjusted.includes(
- `--${token}: color-mix(in oklab, var(--${token}-base), var(--contrast-target) var(--contrast-surface-mix));`,
+ `--${token}: color-mix(in oklab, var(--${token}-base), ${PANEL_TARGET} var(--contrast-surface-mix));`,
),
`--${token} is not on the surface curve`,
);
}
+ for (const token of CHIP_TOKENS) {
+ assert.ok(
+ adjusted.includes(
+ `--${token}: color-mix(in oklab, var(--${token}-base), ${PANEL_TARGET} var(--contrast-fill-mix, var(--contrast-surface-mix)));`,
+ ),
+ `--${token} is not on the fill curve`,
+ );
+ }
// A hover nobody can find is the same failure as an outline nobody can find.
for (const token of STATE_TOKENS) {
+ // Chat control hovers sit on the page, like the chat icons.
+ const target = token === "chat-icon-bg-hover" ? "var(--contrast-target)" : PANEL_TARGET;
assert.ok(
adjusted.includes(
- `--${token}: color-mix(in oklab, var(--${token}-base), var(--contrast-target) var(--contrast-state-mix, var(--contrast-surface-mix)));`,
+ `--${token}: color-mix(in oklab, var(--${token}-base), ${target} var(--contrast-state-mix, var(--contrast-surface-mix)));`,
),
`--${token} is not on the state curve`,
);
@@ -112,7 +147,7 @@ test("off the default, fills and lines each take their own curve", () => {
adjusted.includes("--border: color-mix(in oklab, var(--border-base), var(--contrast-target) var(--contrast-line-mix));"),
);
assert.ok(
- adjusted.includes("--sidebar-border: color-mix(in oklab, var(--sidebar-border-base), var(--contrast-target) var(--contrast-line-mix));"),
+ adjusted.includes(`--sidebar-border: color-mix(in oklab, var(--sidebar-border-base), ${PANEL_TARGET} var(--contrast-line-mix));`),
);
// A control outline nobody can find is not low contrast, it is broken, so
// --input stops short of the hairlines.
@@ -133,6 +168,7 @@ test("lowering flattens further than raising lifts", () => {
};
for (const name of [
"CONTRAST_SURFACE_MIX_VAR",
+ "CONTRAST_FILL_MIX_VAR",
"CONTRAST_LINE_MIX_VAR",
"CONTRAST_CONTROL_MIX_VAR",
"CONTRAST_STATE_MIX_VAR",
@@ -161,6 +197,153 @@ test("a lit row never sinks below the surface it sits on", () => {
);
});
+test("raising widens the step from a row to the lit row", () => {
+ // The lit row and the surface under it both head for the foreground. While
+ // they shared a ceiling the step between them held still, and in light mode
+ // it closed: raising the slider made hover and selection harder to see. The
+ // states take the steepest curve, the chips the next, the planes a nudge.
+ const raising = (name: string) => {
+ const hit = new RegExp(`${name}, mix\\(raising \\? (\\d+) :`).exec(STORE);
+ assert.ok(hit, `${name} is not set from the two ceilings`);
+ return Number(hit[1]);
+ };
+ const surface = raising("CONTRAST_SURFACE_MIX_VAR");
+ const fill = raising("CONTRAST_FILL_MIX_VAR");
+ const state = raising("CONTRAST_STATE_MIX_VAR");
+ assert.ok(surface < fill, "chips lift no further than the planes");
+ assert.ok(fill < state, "hovers lift no further than the chips under them");
+ assert.ok(state >= 2 * surface, "the lit row barely separates from its row");
+});
+
+test("ink follows the slider", () => {
+ // Contrast is first of all text against its background. Held fixed, a
+ // raised slider only greyed the surfaces behind the text and lowered it.
+ const adjusted = block("--card: color-mix(in oklab, var(--card-base)");
+ assert.ok(
+ adjusted.includes(
+ "--foreground: color-mix(in oklab, var(--foreground-base), var(--contrast-ink-target, transparent) var(--contrast-ink-mix, 0%));",
+ ),
+ "--foreground is not on the ink curve",
+ );
+ for (const token of INK_TOKENS.filter((token) => token !== "foreground")) {
+ assert.ok(
+ adjusted.includes(
+ `--${token}: color-mix(in oklab, var(--${token}-base), var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent)) var(--contrast-ink-mix, 0%));`,
+ ),
+ `--${token} is not on the panel ink curve`,
+ );
+ }
+ for (const token of QUIET_INK_TOKENS) {
+ // Nav ink sits on palette surfaces; chat icons sit on the page.
+ const target = token.startsWith("nav-") ? PANEL_TARGET : "var(--contrast-target)";
+ assert.ok(
+ adjusted.includes(
+ `--${token}: color-mix(in oklab, var(--${token}-base), ${target} var(--contrast-text-mix));`,
+ ),
+ `--${token} is not on the text curve`,
+ );
+ }
+ // Lowering stops well short of the page, or body copy stops being legible.
+ const hit = /CONTRAST_INK_MIX_VAR, mix\(raising \? (\d+) : (\d+)\)/.exec(
+ STORE,
+ );
+ assert.ok(hit, "the ink mix is not set from the two ceilings");
+ assert.ok(Number(hit[2]) <= 35, "lowering washes the ink into the page");
+ // A custom foreground is written as the base, so it takes the curve too.
+ assert.match(STORE, /setVar\("--foreground-base", colors\.foreground\)/);
+ assert.doesNotMatch(STORE, /setVar\("--foreground", colors\.foreground\)/);
+ assert.ok(SNAPSHOT.includes('"--foreground-base"'));
+});
+
+test("raising pushes ink its own way, never toward its surface", () => {
+ // Picked from the page, a dark custom background in light mode sent card,
+ // menu and sidebar text toward white on their white surfaces (2.3:1).
+ assert.match(
+ STORE,
+ /CONTRAST_PANEL_INK_TARGET_VAR,\s*raising \? palettePole : "var\(--background\)"/,
+ );
+ assert.match(
+ STORE,
+ /const palettePole = resolved === "light" \? "#000000" : "#ffffff";/,
+ );
+ // --foreground heads away from its page: #767676 on white is nearer white
+ // by luminance, and pushed there it fell from 4.5:1 to 1.5:1.
+ assert.match(
+ STORE,
+ /raising\s*\?\s*colors\.foreground\s*\?\s*inkPole\(\s*colors\.foreground,\s*colors\.background \?\? paletteSurfaces\.background,?\s*\)\s*:\s*palettePole/,
+ );
+ assert.match(
+ STORE,
+ /hexLuminance\(ink\) <= hexLuminance\(page\) \? "#000000" : "#ffffff"/,
+ );
+ assert.doesNotMatch(STORE, /\.background \?\? PALETTE_SURFACES\[resolved\]\.background;\s*const page/);
+ assert.ok(SNAPSHOT.includes('"--contrast-panel-ink-target"'));
+});
+
+test("raising lifts palette fills away from their surfaces under any foreground", () => {
+ // A white custom foreground on a dark custom page in light mode sent the
+ // white sidebar's lit row toward white: its step fell from 1.18:1 to 1.16:1.
+ assert.match(
+ STORE,
+ /CONTRAST_PANEL_TARGET_VAR,\s*raising && colors\.foreground \? palettePole : null/,
+ );
+ assert.match(STORE, /setVar\(CONTRAST_PANEL_TARGET_VAR, null\);/);
+ assert.ok(SNAPSHOT.includes('"--contrast-panel-target"'));
+ // The dark find bar stands in for --card, so it follows the same target.
+ assert.ok(
+ CSS.includes(
+ "background-color: color-mix(in oklab, #2c2c2c, var(--contrast-panel-target, var(--contrast-target, transparent)) var(--contrast-surface-mix, 0%));",
+ ),
+ );
+});
+
+test("text and lines head away from whatever they are drawn on", () => {
+ // Lines sit on the page as well as on cards. Sent to the panel pole
+ // everywhere, a dark border on a light custom page in dark mode fell from
+ // 10:1 at 50 to 2.9:1 at 100; sent to the page target everywhere, borders
+ // on cards fell to 1.1:1. Every surface scope carries its own lines.
+ const scopes = CSS.slice(
+ CSS.indexOf("/* Body text, muted text and lines on palette surfaces"),
+ CSS.indexOf("/* Code font size"),
+ );
+ const rules = [...scopes.matchAll(/\{([^}]*)\}/g)].map((m) => m[1] ?? "");
+ assert.equal(rules.length, 6);
+ for (const rule of rules) {
+ const target = /--muted-foreground: color-mix\(\s*in oklab,\s*var\(--panel-surface-fg-muted\),\s*(var\(--contrast-panel-target, var\(--contrast-target\)\)|var\(--contrast-target\)) var/.exec(rule)?.[1];
+ assert.ok(target, "scope without muted text");
+ assert.ok(rule.includes(`--border: color-mix(in oklab, var(--border-base), ${target} var(--contrast-line-mix));`));
+ assert.ok(rule.includes(`--input: color-mix(in oklab, var(--input-base), ${target} var(--contrast-control-mix));`));
+ // Body text too: text-foreground on a card is card text. A mid grey custom
+ // foreground on a dark page went from 4.5:1 to 1.3:1 on white cards.
+ const ink =
+ target === PANEL_TARGET
+ ? "var(--contrast-panel-ink-target, var(--contrast-ink-target, transparent))"
+ : "var(--contrast-ink-target, transparent)";
+ assert.ok(
+ rule.includes(`--foreground: color-mix(in oklab, var(--foreground-base), ${ink} var(--contrast-ink-mix, 0%));`),
+ "a surface scope leaves body text on the other surface's target",
+ );
+ }
+ // The Images page redoes the derivation for its own base, on the page.
+ assert.match(
+ CSS,
+ /html\[data-contrast-adjust\]:not\(\.dark\) \.diffusion-surface \{\s*--border: color-mix\(in oklab, var\(--border-base\), var\(--contrast-target\) var\(--contrast-line-mix\)\);\s*--input: color-mix\(in oklab, var\(--input-base\), var\(--contrast-target\) var\(--contrast-control-mix\)\);/,
+ );
+});
+
+test("the sidebar section labels follow the slider", () => {
+ // Authored as fixed greys, "Recents" and "Train" held still while every
+ // label around them moved.
+ for (const grey of ["#80868b", "#9aa0a6"]) {
+ assert.ok(
+ CSS.includes(
+ `color: color-mix(in oklab, ${grey}, var(--contrast-panel-target, var(--contrast-target, transparent)) var(--contrast-text-mix, 0%));`,
+ ),
+ `${grey} is not on the text curve`,
+ );
+ }
+});
+
test("a dark selection fill takes the token, not a wash", () => {
// A wash is scaled by --contrast-wash-gain, which still falls further at the
// bottom of the range than --contrast-state-mix does. Painted as washes, the
@@ -334,3 +517,124 @@ test("a reload repaints at the contrast the user chose", () => {
);
}
});
+
+test("muted text on a palette surface heads away from that surface", () => {
+ // A white custom foreground on a dark page took muted card text from
+ // 4.9:1 to 2.1:1 on white cards at 100.
+ const panel = CSS.match(
+ /html\[data-contrast-adjust\] :is\(\.bg-card, \.bg-popover, \.bg-sidebar[^)]*\) \{([^}]*)\}/,
+ );
+ assert.ok(panel, "palette surfaces do not re-derive muted text");
+ assert.match(
+ panel[1] ?? "",
+ /--muted-foreground: color-mix\(\s*in oklab,\s*var\(--panel-surface-fg-muted\),\s*var\(--contrast-panel-target, var\(--contrast-target\)\) var\(--contrast-text-mix\)/,
+ );
+ // A page-coloured pane inside one is the page again.
+ const pane = CSS.match(
+ /html\[data-contrast-adjust\] :is\(\.bg-card, \.bg-popover, \.bg-sidebar[^)]*\) \.bg-background:not\([^{]*\) \{([^}]*)\}/,
+ );
+ assert.ok(pane, "page panes inside palette surfaces keep the panel target");
+ assert.match(pane[1] ?? "", /var\(--contrast-target\) var\(--contrast-text-mix\)/);
+ assert.doesNotMatch(pane[1] ?? "", /--contrast-panel-target/);
+});
+
+test("every near-opaque card spelling takes the panel muted text", () => {
+ // bg-card/96 or dark:bg-card is a distinct class, so the plain .bg-card
+ // scope missed them and their muted labels followed the page instead.
+ const scoped = CSS.match(
+ /html\[data-contrast-adjust\] :is\(([^)]*)\),\s*html\[data-contrast-adjust\]\.dark :is\(([^)]*)\) \{([^}]*)\}/,
+ );
+ assert.ok(scoped, "opacity and dark card spellings are not scoped");
+ assert.match(scoped[3] ?? "", /var\(--contrast-panel-target, var\(--contrast-target\)\)/);
+ const light = (scoped[1] ?? "").replaceAll("\\", "");
+ const dark = (scoped[2] ?? "").replaceAll("\\", "");
+ for (const file of SOURCES.filter((f) => f.endsWith(".tsx"))) {
+ for (const [spelling, isDark, alpha] of readSrc(file).matchAll(
+ /(?<![\w:-])(dark:)?bg-card(?:\/(\d+))?(?![\w/-])/g,
+ )) {
+ if (alpha === undefined ? !isDark : Number(alpha) < 50) continue;
+ assert.ok(
+ (isDark ? dark : light).includes(`.${spelling}`),
+ `${file} paints ${spelling} outside the panel scope`,
+ );
+ }
+ }
+});
+
+test("surfaces the stylesheet paints take the panel muted text too", () => {
+ // .menu-soft-surface gets bg-popover through @apply, so no class matched it
+ // and model picker and Hub menu labels followed the page instead.
+ const always = CSS.match(
+ /html\[data-contrast-adjust\] :is\(\.bg-card, \.bg-popover, \.bg-sidebar, ([^)]*)\) \{/,
+ );
+ assert.ok(always);
+ for (const surface of [
+ ".menu-soft-surface",
+ ".menu-soft-surface-up",
+ ".hub-download-panel",
+ ".hub-download-fab",
+ ]) {
+ assert.ok(always[1]?.includes(surface), `${surface} is not a panel`);
+ assert.match(
+ CSS + HUB_CSS,
+ new RegExp(
+ `^\\s*(?:\\.[\\w-]+ )?${surface.replace(".", "\\.")}[,\\s{][^}]*(bg-popover|var\\(--(popover|card)\\))`,
+ "m",
+ ),
+ `${surface} no longer paints a palette surface`,
+ );
+ }
+ // Hub rows are cards in light only: dark paints them over the page, and
+ // the panel target there took their muted text from 4.1:1 to 1.0:1.
+ assert.match(
+ CSS,
+ /html\[data-contrast-adjust\]:not\(\.dark\) \.hub-page \.hub-result-row \{[^}]*var\(--contrast-panel-target, var\(--contrast-target\)\)/,
+ );
+ assert.match(HUB_CSS, /^ \.hub-page \.hub-result-row \{[^}]*background-color: var\(--card\)/m);
+ assert.match(
+ HUB_CSS,
+ /html\.dark \.hub-page \.hub-result-row \{\s*background-color: color-mix\(in srgb, var\(--foreground\) [^;]*, var\(--background\)\);/,
+ );
+ assert.doesNotMatch(always[1] ?? "", /hub-result-row/);
+ // Painted as cards only in dark, so scoped to dark, with their page panes
+ // (the Settings content pane) sent back unless a card in dark as well.
+ const dark = [".settings-surface", ".chat-composer-surface", ".unsloth-composer-surface", ".unsloth-plus-menu", ".dialog-soft-surface"];
+ const reset = CSS.match(
+ /html\[data-contrast-adjust\]\.dark :is\(([^)]*)\) \.bg-background:not\(\[class\*="dark:bg-"\]:not\(\[class\*="dark:bg-background"\]\)\) \{([^}]*)\}/,
+ );
+ assert.ok(reset, "dark card surfaces keep their page panes on the panel target");
+ assert.match(reset[2] ?? "", /var\(--contrast-target\) var\(--contrast-text-mix\)/);
+ const cards = CSS.match(/html\[data-contrast-adjust\]\.dark :is\(\.dark\\:bg-card([^)]*)\) \{/);
+ for (const surface of dark) {
+ assert.ok(reset[1]?.includes(surface), `${surface} page panes are not reset`);
+ assert.ok(cards?.[1]?.includes(surface), `${surface} is not a panel in dark`);
+ }
+ // The card rule comes after both resets, so a pane that is a card in dark wins.
+ assert.ok(CSS.indexOf(cards?.[0] ?? "@") > CSS.indexOf(reset[0]));
+});
+
+test("a pane that repaints itself in dark is not reset to the page there", () => {
+ // The Settings search keeps bg-background but paints a white wash over the
+ // sidebar in dark; reset to the page, its placeholder fell to 1.7:1 at 100.
+ assert.ok(
+ CSS.includes(
+ '.menu-soft-surface-up, .menu-soft-surface) .bg-background:not(.dark [class*="dark:bg-"]:not([class*="dark:bg-background"])) {',
+ ),
+ );
+ assert.match(
+ readSrc("features/settings/settings-dialog.tsx"),
+ /bg-background[^"]*dark:bg-\[rgb\(255_255_255/,
+ );
+});
+
+test("the dark Hub's popover repaint is scoped only where it wins", () => {
+ // hub.css repaints from @layer base, so bg-background/70 stays the page
+ // (its ink rises on the page target) while hover:bg-background at rest is a
+ // popover, whose muted icon fell from 9:1 to 2.5:1 on the page target.
+ assert.match(HUB_CSS, /@layer base \{[\s\S]*html\.dark \.hub-page \[class\*="bg-card"\],\s*html\.dark \.hub-page \[class\*="bg-background"\] \{\s*background-color: var\(--popover\);/);
+ const rule = CSS.match(
+ /html\[data-contrast-adjust\]\.dark \.hub-page :is\(\[class\*="bg-background"\], \[class\*="bg-card"\]\):not\(\[class\^="bg-"\], \[class\*=" bg-"\], \[class\*="dark:bg-"\], :hover\) \{([^}]*)\}/,
+ );
+ assert.ok(rule, "the repainted Hub popovers are not scoped");
+ assert.match(rule[1] ?? "", /var\(--contrast-panel-target, var\(--contrast-target\)\) var\(--contrast-text-mix\)/);
+});