Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔅 fix: Quiet Form-Control Outlines in the Stock Palettes (#16400)

Marco Berettae232b1b398ff
diff --git a/client/src/components/SidePanel/Agents/Tools/SkillsSection.tsx b/client/src/components/SidePanel/Agents/Tools/SkillsSection.tsx
index 2cb63ee1e9..cc8dc0d1ea 100644
--- a/client/src/components/SidePanel/Agents/Tools/SkillsSection.tsx
+++ b/client/src/components/SidePanel/Agents/Tools/SkillsSection.tsx
@@ -413,7 +413,7 @@ export default function SkillsSection({ items, onInfo, onRemove, onAdd }: Props)
<button
type="button"
onClick={onAdd}
- className="border-border-light text-text-secondary hover:border-border-medium hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
+ className="border-border-medium text-text-secondary hover:border-border-heavy hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
>
<Plus className="h-4 w-4" aria-hidden="true" />
<span className="text-xs">{localize('com_ui_skills_add_row')}</span>
diff --git a/client/src/components/SidePanel/Agents/Tools/ToolsSection.tsx b/client/src/components/SidePanel/Agents/Tools/ToolsSection.tsx
index dee69293e8..7a0b07546b 100644
--- a/client/src/components/SidePanel/Agents/Tools/ToolsSection.tsx
+++ b/client/src/components/SidePanel/Agents/Tools/ToolsSection.tsx
@@ -371,7 +371,7 @@ function SelectedSection({
<button
type="button"
onClick={onAdd}
- className="border-border-light text-text-secondary hover:border-border-medium hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
+ className="border-border-medium text-text-secondary hover:border-border-heavy hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
>
<Plus className="h-4 w-4" aria-hidden="true" />
<span className="text-xs">{emptyLabel}</span>
diff --git a/e2e/specs/mock/scenarios/control-border.spec.ts b/e2e/specs/mock/scenarios/control-border.spec.ts
index c9546a9837..cecdf6f920 100644
--- a/e2e/specs/mock/scenarios/control-border.spec.ts
+++ b/e2e/specs/mock/scenarios/control-border.spec.ts
@@ -2,14 +2,16 @@ import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
import { darkTheme } from '../../../../packages/client/src/theme/themes/dark';
+import { openAgentBuilder } from '../agents.helpers';
import { themeValue } from './style.helpers';
/**
- * A form control's outline is the only edge it has, so it owes the WCAG 1.4.11
- * 3:1 non-text floor against whatever the control is painted on. The separators
- * are a different role and stay quiet. The probe is a real control, the week
+ * A form control's outline is the only edge it has. The stock light and dark
+ * palettes keep it at their quiet light border, and the high contrast and
+ * ClickHouse palettes hold it to the WCAG 1.4.11 3:1 non-text floor against
+ * whatever the control is painted on. The probe is a real control, the week
* start `Dropdown` in the settings dialog, measured against the first opaque
- * surface behind it, in every palette the app ships.
+ * surface behind it.
*/
type Rgb = [number, number, number];
@@ -84,16 +86,6 @@ const PALETTES: Array<{
appearance: Appearance;
definition?: unknown;
}> = [
- {
- name: 'default light',
- tag: '@scenario:control-outline-clears-3-to-1-default-light',
- appearance: 'light',
- },
- {
- name: 'default dark',
- tag: '@scenario:control-outline-clears-3-to-1-default-dark',
- appearance: 'dark',
- },
{
name: 'high contrast light',
tag: '@scenario:control-outline-clears-3-to-1-high-contrast-light',
@@ -148,13 +140,82 @@ test.describe('form control outline', () => {
expect(await themeValue(page, '--border-control')).toBe(darkTheme['rgb-border-control']);
});
+ /** Each tag is written out whole: the runner finds a scenario by its literal tag. */
+ const STOCK: Array<{ appearance: Appearance; title: string }> = [
+ {
+ appearance: 'light',
+ title:
+ 'a stock light dropdown outline matches the card border @scenario:stock-control-outline-matches-card-border-light',
+ },
+ {
+ appearance: 'dark',
+ title:
+ 'a stock dark dropdown outline matches the card border @scenario:stock-control-outline-matches-card-border-dark',
+ },
+ ];
+
+ for (const { appearance, title } of STOCK) {
+ test(title, async ({ page }) => {
+ await installAppearance(page, appearance);
+ await openSettings(page);
+
+ const light = await themeValue(page, '--border-light');
+ expect(await themeValue(page, '--border-control')).toBe(light);
+ expect((await outlineAgainstSurface(page)).border).toBe(
+ `rgb(${light.split(/\s+/).join(', ')})`,
+ );
+ });
+ }
+
+ test('a legacy theme that painted only its medium border keeps it on controls @scenario:legacy-medium-border-theme-keeps-its-control-outline', async ({
+ page,
+ }) => {
+ const definition = {
+ version: 1,
+ name: 'legacy-medium-outline',
+ modes: { light: { colors: { 'rgb-border-medium': '70 90 110' } } },
+ };
+ await installAppearance(page, 'light', definition);
+ await openSettings(page);
+
+ await expect(page.locator('html')).toHaveAttribute('data-theme', 'legacy-medium-outline');
+ expect(await themeValue(page, '--border-control')).toBe('70 90 110');
+ expect((await outlineAgainstSurface(page)).border).toBe('rgb(70, 90, 110)');
+ });
+
+ test('the empty tools card edge sits one step above the field outline @scenario:empty-tools-card-edge-steps-above-field-outline', async ({
+ page,
+ }) => {
+ await installAppearance(page, 'dark');
+ let form = await openAgentBuilder(page);
+ const createNew = form.getByRole('button', { name: 'Create New Agent' });
+ if (await createNew.isVisible().catch(() => false)) {
+ await createNew.click();
+ form = page.getByRole('form', { name: 'Agent configuration form' });
+ }
+
+ const emptyTools = form.getByRole('button', { name: /No tools yet/ });
+ await expect(emptyTools).toBeVisible();
+ const medium = await themeValue(page, '--border-medium');
+ const edge = await emptyTools.evaluate((node) => {
+ const style = getComputedStyle(node);
+ return { color: style.borderTopColor, style: style.borderTopStyle };
+ });
+ const field = await form
+ .getByRole('textbox', { name: 'Agent name' })
+ .evaluate((node) => getComputedStyle(node).borderTopColor);
+
+ expect(edge).toEqual({ color: `rgb(${medium.split(/\s+/).join(', ')})`, style: 'dashed' });
+ expect(field).not.toBe(edge.color);
+ });
+
test('a custom theme without the control role keeps the outline it drew @scenario:custom-theme-keeps-its-control-outline', async ({
page,
}) => {
const definition = {
version: 1,
name: 'legacy-outline',
- modes: { light: { colors: { 'rgb-border-medium': '70 90 110' } } },
+ modes: { light: { colors: { 'rgb-border-light': '70 90 110' } } },
};
await installAppearance(page, 'light', definition);
await openSettings(page);
diff --git a/packages/client/src/components/Field.ts b/packages/client/src/components/Field.ts
index 687d7faf33..de83c9d3c8 100644
--- a/packages/client/src/components/Field.ts
+++ b/packages/client/src/components/Field.ts
@@ -3,8 +3,8 @@
* treatment. Owned here so `Input`, `Textarea`, and the select/combobox triggers
* that have to sit beside them in a form cannot drift apart as the theme evolves.
* Callers compose a variant rather than restating these classes locally. The
- * border is `border-control` because it is the only edge the control has, so it
- * owes the 3:1 non-text floor that the separator roles deliberately do not.
+ * border is `border-control` because it is the only edge the control has, so a
+ * palette can raise it to the 3:1 non-text floor without touching separators.
*/
export const fieldBase: string =
'lc-field flex w-full rounded-lg border border-border-control px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-text-primary disabled:cursor-not-allowed disabled:opacity-50';
diff --git a/packages/client/src/theme/controls.css b/packages/client/src/theme/controls.css
index f409aeac63..a2f562e7ff 100644
--- a/packages/client/src/theme/controls.css
+++ b/packages/client/src/theme/controls.css
@@ -3,16 +3,16 @@
*
* Every other color role is declared by the app stylesheet, but this one ships
* with the package so a consumer rendering `Input`, `Select` or `InputOTP` gets
- * an outline that clears the WCAG 1.4.11 3:1 floor without restating it.
+ * an outline without restating it. The stock values match `border-light`.
* `ThemeProvider` paints the registry value inline whenever a theme is active,
* which outranks these; they only cover the stock palette before and without a
* theme definition, and `semanticTokens.spec.ts` keeps them in step with
* `themes/default.ts` and `themes/dark.ts`.
*/
html {
- --border-control: 133 133 133;
+ --border-control: 227 227 227;
}
.dark {
- --border-control: 125 125 125;
+ --border-control: 33 33 33;
}
diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.ts
index 9bfbe8a063..2dd7e3c5b1 100644
--- a/packages/client/src/theme/registry.spec.ts
+++ b/packages/client/src/theme/registry.spec.ts
@@ -250,20 +250,7 @@ describe('theme registry', () => {
expect(resolved.colors['rgb-chart-widget-stroke']).toBe('50 51 52');
});
- it('keeps the control outline a theme drew with its own medium border', () => {
- const resolved = resolveTheme(
- {
- version: 1,
- name: 'legacy-control-border-reference',
- modes: { dark: { colors: { 'rgb-border-medium': '150 151 152' } } },
- },
- 'dark',
- );
-
- expect(resolved.colors['rgb-border-control']).toBe('150 151 152');
- });
-
- it('keeps a legacy light border that clears 3:1, the role most controls drew', () => {
+ it('keeps the light border a legacy theme drew its controls with', () => {
const resolved = resolveTheme(
{
version: 1,
@@ -278,64 +265,17 @@ describe('theme registry', () => {
expect(resolved.colors['rgb-border-control']).toBe('110 111 112');
});
- it('passes over quiet legacy borders to the bundled outline where it clears 3:1', () => {
- const resolved = resolveTheme(
- {
- version: 1,
- name: 'quiet-border-reference',
- modes: {
- light: {
- colors: { 'rgb-border-light': '245 245 245', 'rgb-border-medium': '240 240 240' },
- },
- },
- },
- 'light',
- );
-
- expect(resolved.colors['rgb-border-control']).toBe(defaultTheme['rgb-border-control']);
- });
-
- it('falls to the candidate that comes closest when nothing clears 3:1', () => {
+ it('keeps the medium border a legacy theme drew its selects with', () => {
const resolved = resolveTheme(
{
version: 1,
- name: 'illegible-reference',
- modes: {
- light: {
- colors: {
- 'rgb-surface-primary': '140 140 140',
- 'rgb-border-medium': '150 150 150',
- 'rgb-text-secondary': '120 120 120',
- 'rgb-text-primary': '90 90 90',
- },
- },
- },
- },
- 'light',
- );
-
- expect(resolved.colors['rgb-border-control']).toBe('90 90 90');
- });
-
- it('outlines controls with secondary text when no border clears its canvases', () => {
- const resolved = resolveTheme(
- {
- version: 1,
- name: 'mid-gray-canvas-reference',
- modes: {
- light: {
- colors: {
- 'rgb-surface-primary': '140 140 140',
- 'rgb-border-medium': '150 150 150',
- 'rgb-text-secondary': '20 21 22',
- },
- },
- },
+ name: 'medium-border-reference',
+ modes: { dark: { colors: { 'rgb-border-medium': '150 151 152' } } },
},
- 'light',
+ 'dark',
);
- expect(resolved.colors['rgb-border-control']).toBe('20 21 22');
+ expect(resolved.colors['rgb-border-control']).toBe('150 151 152');
});
it('gives a theme that leaves every border alone the bundled control outline', () => {
@@ -343,12 +283,12 @@ describe('theme registry', () => {
{
version: 1,
name: 'surface-only-reference',
- modes: { light: { colors: { 'rgb-surface-primary': '250 250 250' } } },
+ modes: { dark: { colors: { 'rgb-surface-primary': '10 10 10' } } },
},
- 'light',
+ 'dark',
);
- expect(resolved.colors['rgb-border-control']).toBe(defaultTheme['rgb-border-control']);
+ expect(resolved.colors['rgb-border-control']).toBe(darkTheme['rgb-border-control']);
});
it('preserves an explicit control outline', () => {
diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts
index 6824ea4fb7..3c8fac068e 100644
--- a/packages/client/src/theme/registry.ts
+++ b/packages/client/src/theme/registry.ts
@@ -9,7 +9,6 @@ import type {
ThemeMode,
} from './types';
import { highContrastDarkTheme, highContrastLightTheme } from './themes/highContrast';
-import { contrastRatio } from './utils/contrast';
import { defaultTheme } from './themes/default';
import { darkTheme } from './themes/dark';
export const THEME_VERSION = 1 as const;
@@ -47,68 +46,19 @@ export const MARK_NEIGHBOURHOOD: readonly (keyof IThemeRGB)[] = Object.freeze([
'rgb-surface-tertiary',
]);
-const NON_TEXT_CONTRAST = 3;
-
-/** The canvases a form control is painted on, which its outline is measured against. */
-const CONTROL_CANVASES: readonly (keyof IThemeRGB)[] = Object.freeze([
- 'rgb-surface-primary',
- 'rgb-surface-secondary',
- 'rgb-surface-tertiary',
- 'rgb-surface-dialog',
- 'rgb-surface-chat',
-]);
-
-/** What a theme has to paint to have coordinated the outline its controls wore. */
-const CONTROL_SURROUNDINGS: readonly (keyof IThemeRGB)[] = Object.freeze([
- 'rgb-border-light',
- 'rgb-border-medium',
- ...CONTROL_CANVASES,
-]);
-
-/** The outline's lowest contrast across the canvases a theme paints. */
-const weakestContrast = (outline: string, palette: IThemeRGB): number =>
- CONTROL_CANVASES.reduce((weakest, canvas) => {
- const surface = palette[canvas];
- const ratio = surface === undefined ? undefined : contrastRatio(outline, surface);
- return ratio === undefined ? weakest : Math.min(weakest, ratio);
- }, Number.POSITIVE_INFINITY);
-
/**
* The control outline for a stored or environment theme that predates
- * `rgb-border-control`. Controls drew `border-light` (fields, dropdowns,
- * comboboxes) or `border-medium` (select, OTP) before the role existed, so a
- * theme that painted either, or the canvases they sit on, coordinated an
- * outline this role now replaces. The first candidate that clears the 3:1
- * non-text floor on the theme's own canvases wins: its light border, its
- * medium border, the bundled role, then its secondary and primary text. When
- * none clears, the one that comes closest does. A theme that names none of
- * these keeps the bundled role, and one that names the role keeps it as written.
- * `base` is the bundled palette for the mode, which the theme is painted over.
+ * `rgb-border-control`. Fields, dropdowns and comboboxes drew `border-light`
+ * and selects and OTP slots drew `border-medium` before the role existed, so a
+ * theme that painted either keeps that edge on its controls, the light border
+ * first. A theme that painted neither keeps the bundled role, and one that
+ * names the role keeps it as written.
*/
-export function controlBorderFallback(colors: IThemeRGB, base: IThemeRGB = {}): string | undefined {
+export function controlBorderFallback(colors: IThemeRGB): string | undefined {
if (colors['rgb-border-control'] !== undefined) {
return undefined;
}
- const ownsControlSurroundings = CONTROL_SURROUNDINGS.some((token) => colors[token] !== undefined);
- if (!ownsControlSurroundings) {
- return undefined;
- }
- const palette: IThemeRGB = { ...base, ...colors };
- const ranked = [
- colors['rgb-border-light'],
- colors['rgb-border-medium'],
- base['rgb-border-control'],
- palette['rgb-text-secondary'],
- palette['rgb-text-primary'],
- ]
- .filter((value): value is string => value !== undefined)
- .map((outline) => ({ outline, contrast: weakestContrast(outline, palette) }));
- const clearing = ranked.find(({ contrast }) => contrast >= NON_TEXT_CONTRAST);
- const closest = ranked.reduce<(typeof ranked)[number] | undefined>(
- (best, entry) => (best === undefined || entry.contrast > best.contrast ? entry : best),
- undefined,
- );
- return (clearing ?? closest)?.outline;
+ return colors['rgb-border-light'] ?? colors['rgb-border-medium'];
}
export const themeAppearanceProperties: Readonly<
@@ -646,7 +596,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
? { 'rgb-chart-widget-stroke': customColors['rgb-border-light'] }
: {};
const borderControlSource =
- customColors != null ? controlBorderFallback(customColors, baseColors) : undefined;
+ customColors != null ? controlBorderFallback(customColors) : undefined;
const borderControlFallback =
borderControlSource !== undefined ? { 'rgb-border-control': borderControlSource } : {};
/**
diff --git a/packages/client/src/theme/semanticTokens.spec.ts b/packages/client/src/theme/semanticTokens.spec.ts
index d1dc867930..311e962f87 100644
--- a/packages/client/src/theme/semanticTokens.spec.ts
+++ b/packages/client/src/theme/semanticTokens.spec.ts
@@ -613,14 +613,12 @@ describe('syntax highlighting palette', () => {
});
/** `border-control` is the only edge a form control has (`Field`, `Select`,
- * `InputOTP`, the dropdown and combobox triggers), so it is a UI component
- * boundary under WCAG 1.4.11 and owes 3:1 on every canvas a form can sit on.
- * The separator roles are deliberately quieter and are not held to this. */
+ * `InputOTP`, the dropdown and combobox triggers). The stock light and dark
+ * palettes keep it at their quiet `border-light` value by design; the high
+ * contrast and ClickHouse palettes hold it to the WCAG 1.4.11 3:1 floor. */
const controlCanvases: Array<keyof IThemeRGB> = [...canvasSurfaces, 'rgb-surface-tertiary'];
describe.each([
- ['default', defaultTheme],
- ['dark', darkTheme],
['high contrast light', highContrastLightTheme],
['high contrast dark', highContrastDarkTheme],
['clickhouse light', clickHouseLightTheme],
diff --git a/packages/client/src/theme/themes/dark.ts b/packages/client/src/theme/themes/dark.ts
index 0278ebfccd..1365fba855 100644
--- a/packages/client/src/theme/themes/dark.ts
+++ b/packages/client/src/theme/themes/dark.ts
@@ -69,7 +69,7 @@ export const darkTheme: IThemeRGB = {
'rgb-border-heavy': '89 89 89', // #595959 (gray-500)
'rgb-border-xheavy': '153 150 150', // #999696 (gray-400)
'rgb-border-destructive': '239 68 68', // #ef4444 (red-500)
- 'rgb-border-control': '125 125 125', // #7d7d7d, 3.25:1 on gray-700, the lightest canvas
+ 'rgb-border-control': '33 33 33', // #212121 (gray-800), the stock field edge
// Status colors
'rgb-status-success': '110 231 183', // #6ee7b7 (green-300)
diff --git a/packages/client/src/theme/themes/default.ts b/packages/client/src/theme/themes/default.ts
index ca70e41553..29659facff 100644
--- a/packages/client/src/theme/themes/default.ts
+++ b/packages/client/src/theme/themes/default.ts
@@ -69,7 +69,7 @@ export const defaultTheme: IThemeRGB = {
'rgb-border-heavy': '153 150 150', // #999696 (gray-400)
'rgb-border-xheavy': '89 89 89', // #595959 (gray-500)
'rgb-border-destructive': '220 38 38', // #dc2626 (red-600)
- 'rgb-border-control': '133 133 133', // #858585, 3.12:1 on gray-100, the lightest canvas
+ 'rgb-border-control': '227 227 227', // #e3e3e3 (gray-200), the stock field edge
// Status colors
'rgb-status-success': '4 120 87', // #047857 (green-700)
diff --git a/packages/client/src/theme/utils/applyTheme.spec.ts b/packages/client/src/theme/utils/applyTheme.spec.ts
index e688872c97..9ad799d4f6 100644
--- a/packages/client/src/theme/utils/applyTheme.spec.ts
+++ b/packages/client/src/theme/utils/applyTheme.spec.ts
@@ -332,30 +332,28 @@ describe('applyTheme', () => {
expect(root.style.getPropertyValue('--chart-widget-stroke')).toBe('50 51 52');
});
- it('carries a legacy medium border onto the control outline', () => {
+ it('carries a legacy light border onto the control outline', () => {
const root = document.documentElement;
- applyTheme({ 'rgb-border-medium': '60 61 62' }, root);
+ applyTheme({ 'rgb-border-light': '110 111 112' }, root, defaultTheme);
- expect(root.style.getPropertyValue('--border-control')).toBe('60 61 62');
+ expect(root.style.getPropertyValue('--border-control')).toBe('110 111 112');
});
- it('carries a legacy light border onto the control outline', () => {
+ it('carries a legacy medium border onto the control outline', () => {
const root = document.documentElement;
- applyTheme({ 'rgb-border-light': '110 111 112' }, root, defaultTheme);
+ applyTheme({ 'rgb-border-medium': '60 61 62' }, root, defaultTheme);
- expect(root.style.getPropertyValue('--border-control')).toBe('110 111 112');
+ expect(root.style.getPropertyValue('--border-control')).toBe('60 61 62');
});
- it('keeps the bundled outline when the legacy borders are too quiet', () => {
+ it('leaves the bundled outline when the theme paints no border', () => {
const root = document.documentElement;
- applyTheme({ 'rgb-border-medium': '240 240 240' }, root, defaultTheme);
+ applyTheme({ 'rgb-surface-primary': '250 250 250' }, root, defaultTheme);
- expect(root.style.getPropertyValue('--border-control')).toBe(
- defaultTheme['rgb-border-control'],
- );
+ expect(root.style.getPropertyValue('--border-control')).toBe('');
});
it('leaves an explicit control outline alone', () => {
diff --git a/packages/client/src/theme/utils/applyTheme.ts b/packages/client/src/theme/utils/applyTheme.ts
index 71aa8b72cf..d0978925f9 100644
--- a/packages/client/src/theme/utils/applyTheme.ts
+++ b/packages/client/src/theme/utils/applyTheme.ts
@@ -71,7 +71,7 @@ function mapColors(colors: IThemeRGB, base?: IThemeRGB): Array<[string, string]>
variables.push(['--chart-widget-stroke', colors['rgb-border-light']]);
}
- const legacyControlBorder = controlBorderFallback(colors, base);
+ const legacyControlBorder = controlBorderFallback(colors);
if (legacyControlBorder !== undefined) {
variables.push(['--border-control', legacyControlBorder]);
}
diff --git a/packages/client/src/theme/utils/contrast.ts b/packages/client/src/theme/utils/contrast.ts
deleted file mode 100644
index f3a485b34e..0000000000
--- a/packages/client/src/theme/utils/contrast.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-const channel = (value: number): number => {
- const c = value / 255;
- return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
-};
-
-function luminance(triplet: string): number | undefined {
- const parts = triplet.trim().split(/\s+/).map(Number);
- if (parts.length !== 3 || parts.some(Number.isNaN)) {
- return undefined;
- }
- const [r, g, b] = parts;
- return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
-}
-
-/** WCAG contrast ratio between two `R G B` triplets; `undefined` when either is malformed. */
-export function contrastRatio(a: string, b: string): number | undefined {
- const [first, second] = [luminance(a), luminance(b)];
- if (first === undefined || second === undefined) {
- return undefined;
- }
- const [lighter, darker] = first > second ? [first, second] : [second, first];
- return (lighter + 0.05) / (darker + 0.05);
-}