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): tint translucent interaction fills toward the accent
Josh Corbett21b625d3c54e
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsxindex d4b5d5139d..3256d85fd8 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx@@ -1,6 +1,6 @@/* oxlint-disable react-perf/jsx-no-new-object-as-prop */import { ChakraProvider } from '@chakra-ui/react';-import { getContrastRatio } from '@platform/ui/theme/contrastRatio.testing';+import { compositeColors, getContrastRatio } from '@platform/ui/theme/contrastRatio.testing';import { system } from '@theme/system';import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -73,11 +73,13 @@ describe('GalleryViewTabs', () => {const count = counts[shownIndex]!;const style = getComputedStyle(count);- const ratio = getContrastRatio(- style.color,+ // The shown fill is translucent, so measure against what it composites to+ // over the surface beneath.+ const effectiveTabBg = compositeColors(getComputedStyle(tabs[shownIndex]!).backgroundColor,- Number(style.opacity)+ getComputedStyle(document.body).backgroundColor);+ const ratio = getContrastRatio(style.color, effectiveTabBg, Number(style.opacity));expect(ratio).toBeGreaterThanOrEqual(4.5);});diff --git a/invokeai/frontend/webv2/src/platform/ui/SegmentTabs.tsx b/invokeai/frontend/webv2/src/platform/ui/SegmentTabs.tsxindex 356113943a..5384f5425a 100644--- a/invokeai/frontend/webv2/src/platform/ui/SegmentTabs.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/SegmentTabs.tsx@@ -3,7 +3,11 @@ import type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';import { Box, chakra, HStack, Text } from '@chakra-ui/react';import { Fragment, useCallback } from 'react';-const TAB_HOVER_PROPS = { bg: 'bg.muted', color: 'fg' };+// Accent-tinted translucent fills, so the strip reads the same on the layer+// panels and on popover/dialog surfaces that share the solid fills' color,+// and sits in the menus' cool-tinted interaction family.+const TAB_HOVER_PROPS = { bg: 'gray.hoverTint/8', color: 'fg' };+const TAB_SHOWN_BG = 'gray.hoverTint/15';/** The strip's fixed height; collapsed blocks and drag snaps size against it. */export const SEGMENT_TABS_HEIGHT_PX = 40;@@ -137,7 +141,7 @@ const SegmentTabButton = <T extends string>({<chakra.buttonaria-controls={isShown ? segmentTabsPanelId(idBase) : undefined}aria-selected={isSelected}- bg={isShown ? 'bg.emphasized' : 'transparent'}+ bg={isShown ? TAB_SHOWN_BG : 'transparent'}color={isShown ? 'fg' : 'fg.muted'}fontSize="xs"fontWeight="600"diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/contrastRatio.testing.ts b/invokeai/frontend/webv2/src/platform/ui/theme/contrastRatio.testing.tsindex b1383e97bc..7a76261813 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/contrastRatio.testing.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/contrastRatio.testing.ts@@ -49,3 +49,21 @@ export const getContrastRatio = (foreground: string, background: string, alpha:return (lighter! + 0.05) / (darker! + 0.05);};++/**+ * The colour a translucent fill actually produces over an opaque surface.+ * Painted rather than parsed: `toRgb` reads raw channels and would report a+ * semi-transparent background as if it were opaque.+ */+export const compositeColors = (top: string, bottom: string): string => {+ const context = document.createElement('canvas').getContext('2d')!;++ context.fillStyle = bottom;+ context.fillRect(0, 0, 1, 1);+ context.fillStyle = top;+ context.fillRect(0, 0, 1, 1);++ const [red, green, blue] = context.getImageData(0, 0, 1, 1).data;++ return `rgb(${String(red)}, ${String(green)}, ${String(blue)})`;+};diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.tsindex b56f25430c..0a262ea219 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts@@ -185,24 +185,24 @@ export const buttonRecipe = defineRecipe({variant: {...chakraRecipes.button.variants?.variant,// Chakra's ghost/outline hover is the solid `subtle` fill, whose- // lightness collides with muted/control surfaces (invisible hover); an- // fg-derived translucent fill reads on every surface and keeps the- // palette tint.+ // lightness collides with muted/control surfaces (invisible hover); a+ // translucent `hoverTint` fill reads on every surface, leans toward the+ // accent on the default palette, and keeps the tint of the others.ghost: {...chakraRecipes.button.variants?.variant?.ghost,- _hover: { bg: 'colorPalette.fg/10' },- _expanded: { bg: 'colorPalette.fg/10' },+ _hover: { bg: 'colorPalette.hoverTint/10' },+ _expanded: { bg: 'colorPalette.hoverTint/10' },},outline: {...chakraRecipes.button.variants?.variant?.outline,- _hover: { bg: 'colorPalette.fg/10' },- _expanded: { bg: 'colorPalette.fg/10' },+ _hover: { bg: 'colorPalette.hoverTint/10' },+ _expanded: { bg: 'colorPalette.hoverTint/10' },},// Stock Chakra gives plain buttons no hover state at all; they take the// same surface-proof fill as ghost.plain: {...chakraRecipes.button.variants?.variant?.plain,- _hover: { bg: 'colorPalette.fg/10' },+ _hover: { bg: 'colorPalette.hoverTint/10' },},},} as unknown as typeof chakraRecipes.button.variants,diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts b/invokeai/frontend/webv2/src/platform/ui/theme/system.tsindex 2eb2fb5a32..ade0553651 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/system.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/system.ts@@ -189,7 +189,23 @@ const semanticColors = {border: grayToken((theme) =>theme.colorScheme === 'light' ? theme.colors.neutral[400] : theme.colors.neutral[500]),+ /**+ * Interaction-fill base for the default palette: fg pulled toward the+ * accent, so translucent hovers read in the menus' cool-tinted family+ * instead of a flat gray. Used at low alpha (`gray.hoverTint/10`).+ */+ hoverTint: grayToken(+ (theme) =>+ `color-mix(in oklab, ${theme.colors.accent.solid} 40%, ${+ theme.colorScheme === 'light' ? theme.colors.neutral[950] : theme.colors.neutral[50]+ })`+ ),},+ // Palette-tinted interaction fills for the non-default palettes buttons use.+ red: { hoverTint: { value: '{colors.red.fg}' } },+ orange: { hoverTint: { value: '{colors.orange.fg}' } },+ green: { hoverTint: { value: '{colors.green.fg}' } },+ blue: { hoverTint: { value: '{colors.blue.fg}' } },/*** Invoke identity palette (lime). Authored from two seeds (`solid` + `contrast`),* like `accent`; the rest derive. `brand.fg` is the seed on the dark themes and a@@ -206,6 +222,7 @@ const semanticColors = {emphasized: mix(brandSolid, 36, surface),focusRing: colorToken(accentSolid),border: colorToken(brandSolid),+ hoverTint: colorToken(brandFg),},/** Selection / focus palette (blue). Use via `accent.solid` or `colorPalette="accent"`. */accent: {@@ -217,6 +234,7 @@ const semanticColors = {emphasized: mix(accentSolid, 36, surface),focusRing: colorToken(accentSolid),border: colorToken(accentSolid),+ hoverTint: colorToken(accentSolid),},};