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
fix(widgets): mark the active rail widget with brand colour, not an accent fill
joshistoast213408b55de9
diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/__fixtures__/legacyTokenBaseline.json b/invokeai/frontend/webv2/src/platform/ui/theme/__fixtures__/legacyTokenBaseline.jsonindex ac4220f96c..26ae854c66 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/__fixtures__/legacyTokenBaseline.json+++ b/invokeai/frontend/webv2/src/platform/ui/theme/__fixtures__/legacyTokenBaseline.json@@ -78,7 +78,7 @@"gray.border": "oklch(84% 0.0095 264)","brand.solid": "oklch(92.041% 0.2103 116.59)","brand.contrast": "oklch(22.5% 0.013 264)",- "brand.fg": "oklch(92.041% 0.2103 116.59)",+ "brand.fg": "color-mix(in oklab, oklch(92.041% 0.2103 116.59) 50%, oklch(22.5% 0.013 264))","brand.subtle": "color-mix(in oklab, oklch(92.041% 0.2103 116.59) 16%, oklch(99.4% 0.002 264))","brand.muted": "color-mix(in oklab, oklch(92.041% 0.2103 116.59) 26%, oklch(99.4% 0.002 264))","brand.emphasized": "color-mix(in oklab, oklch(92.041% 0.2103 116.59) 36%, oklch(99.4% 0.002 264))",diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts b/invokeai/frontend/webv2/src/platform/ui/theme/system.test.tsindex 37d377b319..ae48691acc 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/system.test.ts@@ -129,11 +129,15 @@ describe('native Chakra integration', () => {});describe('brand palette derives from its two seeds (like accent)', () => {- it('fg/border equal solid; subtle/muted/emphasized mix solid into the surface', () => {+ it('border equals solid; subtle/muted/emphasized mix solid into the surface', () => {for (const theme of THEMES) {const solid = resolveToken(sys, theme, 'brand.solid');const surface = resolveToken(sys, theme, 'bg.subtle');- expect(resolveToken(sys, theme, 'brand.fg')).toBe(solid);+ // `brand.fg` is the exception: it darkens on the light theme, where the+ // seed measures 1.20:1 against the panel it would sit on.+ expect(resolveToken(sys, theme, 'brand.fg')).toBe(+ theme === 'light' ? `color-mix(in oklab, ${solid} 50%, oklch(22.5% 0.013 264))` : solid+ );expect(resolveToken(sys, theme, 'brand.border')).toBe(solid);for (const [key, pct] of [['subtle', 16],diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts b/invokeai/frontend/webv2/src/platform/ui/theme/system.tsindex 374b208e35..c57f3806fd 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/system.ts@@ -100,6 +100,24 @@ const danger: Compute = (theme) => theme.colors.danger;const success: Compute = (theme) => theme.colors.success;const warning: Compute = (theme) => theme.colors.warning;const brandSolid: Compute = (theme) => theme.colors.brand.solid;++/**+ * Brand as a *foreground* colour rather than a fill.+ *+ * The seed is a bright lime picked to carry on the dark themes' near-black+ * surfaces, where it measures 14.5:1. On the light theme the same value sits at+ * L≈92% against a 99% white panel and measures 1.20:1 — invisible, which is why+ * the Invoke mark all but disappeared there. Darkening it halfway into the text+ * ramp brings it to 4.2:1 on the panel and 4.1:1 on `brand.subtle`: still+ * unmistakably the brand hue, now actually a colour you can put something in.+ *+ * `brand.solid` is untouched — fills keep the bright seed and pair it with+ * `brand.contrast`.+ */+const brandFg: Compute = (theme) =>+ theme.colorScheme === 'light'+ ? `color-mix(in oklab, ${theme.colors.brand.solid} 50%, ${theme.colors.neutral[950]})`+ : theme.colors.brand.solid;const accentSolid: Compute = (theme) => theme.colors.accent.solid;/** The neutral ramp, emitted as `neutral.50…neutral.950`, one value per theme. */@@ -172,14 +190,15 @@ const semanticColors = {},/*** Invoke identity palette (lime). Authored from two seeds (`solid` + `contrast`),- * like `accent`; the rest derive. NOTE: `brand.fg` is the bright `solid` fill, so- * `brand.fg` on `brand.subtle` reads well on the dark themes but is low-contrast in- * the light theme — brand is meant for emphasis fills, not body text.+ * like `accent`; the rest derive. `brand.fg` is the seed on the dark themes and a+ * darkened mix on the light one (see {@link brandFg}), so it is safe to put text+ * and icons in on any theme; `brand.solid` stays the bright fill and wants+ * `brand.contrast` on top of it.*/brand: {solid: colorToken(brandSolid),contrast: colorToken((theme) => theme.colors.brand.contrast),- fg: colorToken(brandSolid),+ fg: colorToken(brandFg),subtle: mix(brandSolid, 16, surface),muted: mix(brandSolid, 26, surface),emphasized: mix(brandSolid, 36, surface),diff --git a/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx b/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsxindex 705a94ff19..64eaf21577 100644--- a/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx@@ -34,8 +34,14 @@ interface BottomWidgetItem extends PlacedWidgetRegionItem<WidgetPlacementInstancconst BOTTOM_MENU_POSITIONING = { placement: 'top-end' } as const;const BOTTOM_MENU_TRIGGER = { kind: 'bottom' } as const;-const COMPACT_ROW_HOVER_PROPS = { color: 'fg' };-const COMPACT_ROW_ACTIVE_HOVER_PROPS = { color: 'accent.contrast' };+/**+ * Same three-step ladder as the side rails (see `WidgetBar`): the brand hue+ * marks the open widget through its content colour, on a neutral fill, because+ * a brand tint of this bar is indistinguishable from it on the light theme.+ */+const COMPACT_ROW_HOVER_PROPS = { bg: 'bg.muted', color: 'fg' };+const COMPACT_ROW_ACTIVE_PROPS = { bg: 'bg.emphasized', color: 'brand.fg' };+const COMPACT_ROW_ACTIVE_HOVER_PROPS = { bg: 'bg.emphasized', color: 'brand.fg' };const TOOLTIP_POSITIONING = { placement: 'top' } as const;export const StatusBar = ({ dropState }: { dropState: WidgetRegionDropState }) => {@@ -198,12 +204,13 @@ const CompactBottomWidget = ({<Box ref={setNodeRef} h="full" style={style}><Row{...rowDragHandleProps}- active={isActive ? 'accent' : 'none'}aria-label={item.label}aria-pressed={isActive}+ color={isActive ? undefined : 'fg.muted'}cursor={isDragging ? 'grabbing' : item.isExpandable ? 'pointer' : 'default'}h="full"w="auto"+ {...(isActive ? COMPACT_ROW_ACTIVE_PROPS : null)}_hover={isActive ? COMPACT_ROW_ACTIVE_HOVER_PROPS : COMPACT_ROW_HOVER_PROPS}{...activationProps}onClick={handleClick}diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/RailActiveContrast.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/RailActiveContrast.browser.test.tsxnew file mode 100644index 0000000000..f32d753932--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/RailActiveContrast.browser.test.tsx@@ -0,0 +1,76 @@+import { Box, ChakraProvider } from '@chakra-ui/react';+import { Row } from '@platform/ui';+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';++import { WIDGET_ITEM_SX } from './WidgetBar';++/**+ * The rail's active state is a neutral fill with the widget icon in+ * `brand.fg`. Two things can silently break it, so both are pinned here:+ * `brand.fg` reverting to the raw seed (1.20:1 on the light theme's panel —+ * invisible), and the active fill being swapped for a brand tint, which on the+ * light theme lands within 1.06:1 of the rail behind it.+ */++const RAIL_ITEM_SX = WIDGET_ITEM_SX;++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();+ applyThemeToRoot('classic');+ host = null;+ root = null;+});++const renderActiveRailItem = async (themeId: string) => {+ applyThemeToRoot(themeId);+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);++ await act(() => {+ root?.render(+ <ChakraProvider value={system}>+ <Box bg="bg.subtle" data-testid="rail" p="1">+ <Row aria-pressed css={RAIL_ITEM_SX} data-testid="item" />+ </Box>+ </ChakraProvider>+ );+ });++ return {+ item: host.querySelector<HTMLElement>('[data-testid="item"]')!,+ rail: host.querySelector<HTMLElement>('[data-testid="rail"]')!,+ };+};++describe('rail active state contrast', () => {+ for (const theme of THEMES) {+ // 3:1 is the WCAG floor for a graphical control's own colours; the icon is+ // an icon, not body text.+ it(`keeps the active icon readable on ${theme.id}`, async () => {+ const { item } = await renderActiveRailItem(theme.id);+ const style = getComputedStyle(item);++ expect(getContrastRatio(style.color, style.backgroundColor, 1)).toBeGreaterThanOrEqual(3);+ });++ it(`separates the active fill from the rail behind it on ${theme.id}`, async () => {+ const { item, rail } = await renderActiveRailItem(theme.id);++ expect(+ getContrastRatio(getComputedStyle(item).backgroundColor, getComputedStyle(rail).backgroundColor, 1)+ ).toBeGreaterThan(1.05);+ });+ }+});diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsxindex ef8de30b15..a3b1a4d39a 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx@@ -127,15 +127,34 @@ export const WidgetBar = ({);};-const WIDGET_ITEM_SX: SystemStyleObject = {+/**+ * Rail states, quietest to loudest: idle icon dimmed, hover one neutral step+ * up, active a further step with the icon in the brand hue.+ *+ * The brand lives in the icon rather than the fill because it cannot live in+ * the fill: the seed is a 92%-lightness lime, so every brand tint of the light+ * theme's near-white rail lands within 1.06:1 of it — a state you cannot see.+ * As an icon on a neutral fill it clears 3:1 on all five themes, which+ * `RailActiveContrast.browser.test.tsx` pins.+ *+ * The attribute selectors outrank `rowRecipe`'s own `_hover`, so hovering the+ * active item leaves it alone instead of flickering to the hover fill.+ */+export const WIDGET_ITEM_SX: SystemStyleObject = {display: 'flex',alignItems: 'center',justifyContent: 'center',rounded: 'md',h: 9,w: 9,+ color: 'fg.muted','&[aria-pressed="false"]:hover': {+ bg: 'bg.muted',+ color: 'fg',+ },+ '&[aria-pressed="true"]': {bg: 'bg.emphasized',+ color: 'brand.fg',},_disabled: WIDGET_SLOT_DISABLED_PROPS,};@@ -181,7 +200,6 @@ const WidgetSlot = ({<Row{...dragHandleProps}css={WIDGET_ITEM_SX}- active={isActive ? 'accent' : 'none'}aria-label={item.label}aria-disabled={isDisabled}aria-pressed={isActive}