Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(theme): high contrast preference
Josh Corbett66fb4166b0b3
diff --git a/invokeai/frontend/webv2/index.html b/invokeai/frontend/webv2/index.htmlindex c786e1a025..fedfbf66ab 100644--- a/invokeai/frontend/webv2/index.html+++ b/invokeai/frontend/webv2/index.html@@ -19,6 +19,7 @@forest: 'dark',light: 'light',mono: 'dark',+ osakaJade: 'dark',ultradark: 'dark',};var id = localStorage.getItem('invokeai:v7:webv2:theme');@@ -38,6 +39,9 @@if (localStorage.getItem('invokeai:v7:webv2:reduce-motion') === 'true') {root.setAttribute('data-reduce-motion', 'true');}+ if (localStorage.getItem('invokeai:v7:webv2:high-contrast') === 'true') {+ root.setAttribute('data-high-contrast', 'true');+ }var language = localStorage.getItem('invokeai:v7:webv2:language');if (language) {root.setAttribute('lang', language);diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 136963c7ef..4968c2c36e 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1492,6 +1492,10 @@"label": "Theme","description": "Choose the workbench colors."},+ "highContrast": {+ "label": "High contrast",+ "description": "Strengthen text and border contrast on every theme."+ },"reduceMotion": {"label": "Reduce motion","description": "Disable transitions and animations across the workbench."diff --git a/invokeai/frontend/webv2/src/app/ThemeController.tsx b/invokeai/frontend/webv2/src/app/ThemeController.tsxindex 7ab3b19b43..eb2376f327 100644--- a/invokeai/frontend/webv2/src/app/ThemeController.tsx+++ b/invokeai/frontend/webv2/src/app/ThemeController.tsx@@ -20,10 +20,31 @@ import { useLayoutEffect } from 'react';*/const THEME_HINT_STORAGE_KEY = 'invokeai:v7:webv2:theme';const REDUCE_MOTION_HINT_STORAGE_KEY = 'invokeai:v7:webv2:reduce-motion';+const HIGH_CONTRAST_HINT_STORAGE_KEY = 'invokeai:v7:webv2:high-contrast';++/** Mirrors a boolean appearance flag onto `<html data-*>` and its pre-paint hint. */+const applyRootFlag = (dataKey: 'highContrast' | 'reduceMotion', hintKey: string, enabled: boolean): void => {+ const root = document.documentElement;+ if (enabled) {+ root.dataset[dataKey] = 'true';+ } else {+ delete root.dataset[dataKey];+ }+ try {+ if (enabled) {+ window.localStorage.setItem(hintKey, 'true');+ } else {+ window.localStorage.removeItem(hintKey);+ }+ } catch {+ // Storage unavailable — the next load just waits for settings to resolve.+ }+};export const ThemeController = () => {- const { reduceMotion, status, themeId } = useWorkbenchSettingsSelector(+ const { highContrast, reduceMotion, status, themeId } = useWorkbenchSettingsSelector((snapshot) => ({+ highContrast: snapshot.preferences.highContrast,reduceMotion: snapshot.preferences.reduceMotion,status: snapshot.status,themeId: snapshot.preferences.themeId,@@ -51,28 +72,16 @@ export const ThemeController = () => {}, [hasResolved, themeId]);useLayoutEffect(() => {- if (!hasResolved) {- return;- }-- const root = document.documentElement;-- if (reduceMotion) {- root.dataset.reduceMotion = 'true';- } else {- delete root.dataset.reduceMotion;+ if (hasResolved) {+ applyRootFlag('reduceMotion', REDUCE_MOTION_HINT_STORAGE_KEY, reduceMotion);}+ }, [hasResolved, reduceMotion]);- try {- if (reduceMotion) {- window.localStorage.setItem(REDUCE_MOTION_HINT_STORAGE_KEY, 'true');- } else {- window.localStorage.removeItem(REDUCE_MOTION_HINT_STORAGE_KEY);- }- } catch {- // Storage unavailable — the next load just waits for settings to resolve.+ useLayoutEffect(() => {+ if (hasResolved) {+ applyRootFlag('highContrast', HIGH_CONTRAST_HINT_STORAGE_KEY, highContrast);}- }, [hasResolved, reduceMotion]);+ }, [hasResolved, highContrast]);return null;};diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/HighContrast.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/theme/HighContrast.browser.test.tsxnew file mode 100644index 0000000000..72ed0c3d8f--- /dev/null+++ b/invokeai/frontend/webv2/src/platform/ui/theme/HighContrast.browser.test.tsx@@ -0,0 +1,100 @@+import { Box, ChakraProvider, Text } from '@chakra-ui/react';+import { applyThemeToRoot } from '@theme/applyTheme';+import { getContrastRatio } from '@theme/contrastRatio.testing';+import { system } from '@theme/system';+import { THEMES } from '@theme/themes';+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, describe, expect, it } from 'vitest';++/**+ * The high-contrast preference flips `<html data-high-contrast>`; every theme's+ * muted text and borders must then clear the WCAG AA thresholds (4.5:1 for+ * text, 3:1 for a non-text boundary) on the panel surfaces chrome paints on,+ * while muted text stays a visible rank below the foreground.+ */++let host: HTMLDivElement | null = null;+let root: Root | null = null;+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++afterEach(async () => {+ await act(() => root?.unmount());+ host?.remove();+ delete document.documentElement.dataset.highContrast;+ applyThemeToRoot('classic');+ host = null;+ root = null;+});++const SURFACES = ['bg.subtle', 'bg.panel'] as const;++const renderSample = async (themeId: string, highContrast: boolean) => {+ applyThemeToRoot(themeId);+ if (highContrast) {+ document.documentElement.dataset.highContrast = 'true';+ } else {+ delete document.documentElement.dataset.highContrast;+ }+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+ await act(() => {+ root?.render(+ <ChakraProvider value={system}>+ {SURFACES.map((surface) => (+ <Box key={surface} bg={surface} data-testid={surface} p="2">+ <Text color="fg" data-testid={`${surface}-fg`}>+ fg+ </Text>+ <Text color="fg.muted" data-testid={`${surface}-muted`}>+ muted+ </Text>+ <Text color="fg.subtle" data-testid={`${surface}-subtle`}>+ subtle+ </Text>+ <Box borderColor="border" borderWidth="1px" data-testid={`${surface}-border`} />+ <Box borderColor="gray.border" borderWidth="1px" data-testid={`${surface}-gray-border`} />+ </Box>+ ))}+ </ChakraProvider>+ );+ });+ const style = (id: string) => getComputedStyle(host!.querySelector(`[data-testid="${id}"]`)!);+ return SURFACES.map((surface) => {+ const panel = style(surface).backgroundColor;+ return {+ border: getContrastRatio(style(`${surface}-border`).borderTopColor, panel, 1),+ fg: getContrastRatio(style(`${surface}-fg`).color, panel, 1),+ grayBorder: getContrastRatio(style(`${surface}-gray-border`).borderTopColor, panel, 1),+ muted: getContrastRatio(style(`${surface}-muted`).color, panel, 1),+ subtle: getContrastRatio(style(`${surface}-subtle`).color, panel, 1),+ surface,+ };+ });+};++describe('high contrast preference', () => {+ for (const theme of THEMES) {+ it(`raises muted text and borders past WCAG AA on ${theme.id}`, async () => {+ const normal = await renderSample(theme.id, false);+ await act(() => root?.unmount());+ host?.remove();+ const high = await renderSample(theme.id, true);++ high.forEach((sample, index) => {+ const before = normal[index]!;+ expect(sample.muted, `${sample.surface} muted`).toBeGreaterThan(before.muted);+ expect(sample.subtle, `${sample.surface} subtle`).toBeGreaterThan(before.subtle);+ expect(sample.border, `${sample.surface} border`).toBeGreaterThan(before.border);+ expect(sample.grayBorder, `${sample.surface} gray.border`).toBeGreaterThan(before.grayBorder);+ expect(sample.muted, `${sample.surface} muted`).toBeGreaterThanOrEqual(4.5);+ expect(sample.subtle, `${sample.surface} subtle`).toBeGreaterThanOrEqual(4.5);+ expect(sample.border, `${sample.surface} border`).toBeGreaterThanOrEqual(3);+ expect(sample.grayBorder, `${sample.surface} gray.border`).toBeGreaterThanOrEqual(3);+ // Boosted text keeps its rank: still visibly weaker than the foreground.+ expect(sample.muted, `${sample.surface} hierarchy`).toBeLessThan(sample.fg * 0.95);+ });+ });+ }+});diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts b/invokeai/frontend/webv2/src/platform/ui/theme/system.test.tsindex cb226e1588..2ce4f73b17 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts@@ -103,6 +103,21 @@ describe('ramp + mapping structure', () => {});});+describe('high contrast conditions', () => {+ it('emits a per-theme high-contrast block that lifts muted text toward the foreground', () => {+ const layer = sys.getTokenCss()['@layer tokens']!;+ for (const theme of THEMES) {+ const block = layer[`&:root[data-theme=${theme}][data-high-contrast=true]`];+ expect(block, theme).toBeDefined();+ const step = theme === 'light' ? 800 : 200;+ const varOf = (name: string) => sys.tokens.getByName(`colors.${name}`)!.extensions.cssVar.var;+ expect(block![varOf('fg.muted')]).toBe(`var(${varOf(`neutral.${step}`)})`);+ expect(block![varOf('border')]).toBeDefined();+ expect(block![varOf('gray.border')]).toBeDefined();+ }+ });+});+describe('native Chakra integration', () => {it('adds an icon-sized progress circle variant', () => {expect(progressCircleSlotRecipe.variants?.size?.['2xs']).toMatchObject({diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts b/invokeai/frontend/webv2/src/platform/ui/theme/system.tsindex 49bcf1dcf8..b54853cfcb 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/system.ts@@ -92,6 +92,36 @@ const ref = (step: NeutralStep): string => `{colors.neutral.${step}}`;const stepRef = (darkStep: NeutralStep, lightStep: NeutralStep): TokenValue =>colorToken((theme) => ref(theme.colorScheme === 'light' ? lightStep : darkStep));+/**+ * `classic` -> `highContrastClassic`: one condition per theme, since the boost+ * differs by color scheme. Unrelated to Chakra's built-in `_highContrast`+ * (`forced-colors`); these key off the app preference.+ */+const highContrastConditionName = (id: string): string => `highContrast${id.charAt(0).toUpperCase()}${id.slice(1)}`;++/**+ * Adds the high-contrast value of a token for every theme. The per-theme+ * attribute pair outranks the plain `[data-theme]` condition, so the boost+ * wins wherever `<html data-high-contrast>` is set.+ */+const withHighContrast = (token: TokenValue, compute: Compute): TokenValue => {+ for (const theme of THEMES) {+ token.value[`_${highContrastConditionName(theme.id)}`] = compute(theme);+ }+ return token;+};++/** A ramp-step token with a stronger step pair under high contrast. */+const contrastStepRef = (+ darkStep: NeutralStep,+ lightStep: NeutralStep,+ highDarkStep: NeutralStep,+ highLightStep: NeutralStep+): TokenValue =>+ withHighContrast(stepRef(darkStep, lightStep), (theme) =>+ ref(theme.colorScheme === 'light' ? highLightStep : highDarkStep)+ );+const STEPS: NeutralStep[] = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];/** The default panel surface of a theme — `bg.subtle`'s step. Used as the floor for tints. */@@ -148,20 +178,21 @@ const semanticColors = {'bg.success': mix(success, 14, surface),'bg.warning': mix(warning, 14, surface),- // Foreground.+ // Foreground. Muted/subtle text carries the contrast burden: under high+ // contrast they climb toward `fg` while staying a visible rank below it.fg: stepRef(50, 950),- 'fg.muted': stepRef(300, 700),- 'fg.subtle': stepRef(400, 500),+ 'fg.muted': contrastStepRef(300, 700, 200, 800),+ 'fg.subtle': contrastStepRef(400, 500, 300, 700),'fg.grid': colorToken((theme) => theme.colors.grid),'fg.error': colorToken(danger),'fg.success': colorToken(success),'fg.warning': colorToken(warning),// Borders.- border: stepRef(600, 300),- 'border.subtle': stepRef(600, 300),- 'border.muted': stepRef(600, 300),- 'border.emphasized': stepRef(500, 400),+ border: contrastStepRef(600, 300, 300, 500),+ 'border.subtle': contrastStepRef(600, 300, 300, 500),+ 'border.muted': contrastStepRef(600, 300, 300, 500),+ 'border.emphasized': contrastStepRef(500, 400, 200, 600),'border.error': colorToken(danger),'border.image': colorToken((theme) => (theme.colorScheme === 'light' ? 'oklch(0 0 0 / 0.1)' : 'oklch(1 0 0 / 0.1)')),@@ -182,13 +213,15 @@ const semanticColors = {fg: grayToken((theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[950] : theme.colors.neutral[50])),subtle: grayToken((theme) => theme.colors.fill),muted: grayToken((theme) => theme.colors.control),- emphasized: grayToken((theme) =>- theme.colorScheme === 'light' ? theme.colors.neutral[400] : theme.colors.neutral[500]+ emphasized: withHighContrast(+ grayToken((theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[400] : theme.colors.neutral[500])),+ (theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[600] : theme.colors.neutral[300])),solid: grayToken((theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[950] : theme.colors.neutral[50])),focusRing: grayToken(accentSolid),- border: grayToken((theme) =>- theme.colorScheme === 'light' ? theme.colors.neutral[400] : theme.colors.neutral[500]+ border: withHighContrast(+ grayToken((theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[400] : theme.colors.neutral[500])),+ (theme) => (theme.colorScheme === 'light' ? theme.colors.neutral[600] : theme.colors.neutral[300])),/*** Interaction-fill base for the default palette: fg pulled toward the@@ -244,12 +277,15 @@ const semanticColors = {const themeConditions = Object.fromEntries(NON_DEFAULT_THEMES.map((theme) => [conditionName(theme.id), `:root[data-theme=${theme.id}]`]));+const highContrastConditions = Object.fromEntries(+ THEMES.map((theme) => [highContrastConditionName(theme.id), `:root[data-theme=${theme.id}][data-high-contrast=true]`])+);const motionDurationToken = (base: string): TokenValue => ({ value: { base, _reduceMotion: '1ms' } });const motionAnimationToken = (base: string): TokenValue => ({ value: { base, _reduceMotion: 'none' } });const config = defineConfig({- conditions: { ...themeConditions, reduceMotion: ':root[data-reduce-motion=true]' },+ conditions: { ...themeConditions, ...highContrastConditions, reduceMotion: ':root[data-reduce-motion=true]' },globalCss: {'html, body, #root': {height: '100%',diff --git a/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts b/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.tsindex fb42b1e0bc..3a9a545b06 100644--- a/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/applicationContributions.ts@@ -38,6 +38,7 @@ export const appearanceSettings = section('appearance', 'Appearance', [options: WORKBENCH_LANGUAGE_OPTIONS,},preference('reduceMotion', 'Reduce motion', 'animation'),+ preference('highContrast', 'High contrast', 'accessibility a11y readability'),preference('showFocusRegionHighlight', 'Highlight focused regions', 'panel outline'),]);export const behaviorSettings = section('behavior', 'Behavior', [diff --git a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts b/invokeai/frontend/webv2/src/workbench/settings/contracts.tsindex 3ab191adb8..8ad12228a9 100644--- a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/contracts.ts@@ -84,6 +84,8 @@ export interface WorkbenchPreferences {workflowEdgeStyle: 'curved' | 'square';/** Keep connections of a selected node beneath nodes instead of raising them over node controls. */workflowEdgesBehindNodes: boolean;+ /** Raise text and border contrast on every theme (a11y). */+ highContrast: boolean;/** Account-bound overrides keyed by hotkey id (`app.invoke`, `gallery.galleryNavLeft`, etc.). */customHotkeys: Record<string, string[]>;/** Generate panel section open/closed overrides keyed by section id; absent = section default. */diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.test.ts b/invokeai/frontend/webv2/src/workbench/settings/store.test.tsindex 45d28e8f7e..502918b9ea 100644--- a/invokeai/frontend/webv2/src/workbench/settings/store.test.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/store.test.ts@@ -381,6 +381,14 @@ describe('normalizeWorkbenchPreferences prompt editing', () => {});});+describe('normalizeWorkbenchPreferences appearance', () => {+ it('keeps high contrast off unless explicitly enabled', () => {+ expect(store.normalizeWorkbenchPreferences({}).highContrast).toBe(false);+ expect(store.normalizeWorkbenchPreferences({ highContrast: 1 as never }).highContrast).toBe(false);+ expect(store.normalizeWorkbenchPreferences({ highContrast: true }).highContrast).toBe(true);+ });+});+describe('normalizeWorkbenchPreferences workflow editor', () => {it('keeps connections above nodes unless the preference is explicitly on', () => {expect(store.normalizeWorkbenchPreferences({}).workflowEdgesBehindNodes).toBe(false);diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.ts b/invokeai/frontend/webv2/src/workbench/settings/store.tsindex 0f0dd84422..2e737a8d37 100644--- a/invokeai/frontend/webv2/src/workbench/settings/store.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/store.ts@@ -64,6 +64,7 @@ export const DEFAULT_PREFERENCES: WorkbenchPreferences = {enableModelDescriptions: true,generatePresets: [],generateSectionsOpen: {},+ highContrast: false,krea2RebalancePresets: [],language: 'en',launchpadPinnedProjectIds: [],@@ -342,6 +343,8 @@ export const normalizeWorkbenchPreferences = (preferences?: WorkbenchPreferences: preferences?.queueJobsScope === 'active-project' || preferences?.queueJobsScope === 'all'? preferences.queueJobsScope: DEFAULT_PREFERENCES.queueJobsScope,+ highContrast:+ typeof preferences?.highContrast === 'boolean' ? preferences.highContrast : DEFAULT_PREFERENCES.highContrast,reduceMotion:typeof preferences?.reduceMotion === 'boolean' ? preferences.reduceMotion : DEFAULT_PREFERENCES.reduceMotion,showFocusRegionHighlight: