diff --git a/packages/app/src/styles/derive-colors.ts b/packages/app/src/styles/derive-colors.ts index 7e00701b90..6ed1646222 100644 --- a/packages/app/src/styles/derive-colors.ts +++ b/packages/app/src/styles/derive-colors.ts @@ -29,6 +29,8 @@ const NEUTRAL_FILL_STEPS = { // the contrast the theme gives its own text: foreground stays at least this readable on it. The // margin over 3:1 absorbs the rounding of the fill to 8-bit channels. const NEUTRAL_FILL_TEXT_FLOOR = 3.05; +// A theme whose own text is quieter than that still gets a fill that separates from the page. +const NEUTRAL_FILL_MIN_STEP = 1.25; // Tertiary text: muted text, that fraction of the way toward the background, but never quieter // than this contrast against it (or than the muted text itself, when that is already quieter). The @@ -63,7 +65,11 @@ export function deriveNeutralFills( // Foreground on the fill is about (foreground on background) / step. const textBound = contrastRatio(background, foreground) / NEUTRAL_FILL_TEXT_FLOOR; return { - surface3: stepContrast(background, foreground, Math.min(steps.surface3, textBound)), + surface3: stepContrast( + background, + foreground, + Math.max(NEUTRAL_FILL_MIN_STEP, Math.min(steps.surface3, textBound)), + ), surface4: stepContrast(background, foreground, steps.surface4), }; } diff --git a/packages/app/src/styles/theme-contrast.test.ts b/packages/app/src/styles/theme-contrast.test.ts index 8fbb89e59a..05098e8b6f 100644 --- a/packages/app/src/styles/theme-contrast.test.ts +++ b/packages/app/src/styles/theme-contrast.test.ts @@ -169,6 +169,18 @@ describe.each(themes.filter(({ name }) => name.startsWith("plugin ")))( }, ); +describe("a plugin theme whose own text is quiet", () => { + it("still separates the neutral fill from the page", () => { + const { colors } = buildPluginTheme({ + ...MOCHA, + colors: { ...MOCHA.colors, background: "#202020", foreground: "#6a6a6a" }, + }); + expect(contrastRatio(colors.surface0, colors.surface3)).toBeGreaterThanOrEqual( + NEUTRAL_FILL_STEP, + ); + }); +}); + describe("built-in themes", () => { it.each(themes.filter(({ name }) => !name.startsWith("plugin ")))( "$name keeps a control hover visible on the workspace surface",