From ae3399ac6bef5986bc4857a159776f95a1768bfa Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 3 Dec 2026 10:58:51 -0500 Subject: [PATCH] Define the ring, card-foreground and popover-foreground --- frontend/src/index.css | 6 ++++ frontend/src/lib/theme/colorTheme.test.ts | 29 +++++++++++++++++++ frontend/src/lib/theme/colorTheme.ts | 6 ++++ .../src/lib/theme/syntaxHighlight.test.ts | 5 ---- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index d3fcf43c..d162070e 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -6,7 +6,9 @@ --color-foreground: #fafafa; --color-card: #141414; --color-card-hover: #1a1a1a; + --color-card-foreground: #fafafa; --color-border: #2a2a2a; + --color-ring: #d4d4d8; --color-primary: #1d4ed8; --color-primary-hover: #1e40af; --color-primary-foreground: #fafafa; @@ -16,6 +18,7 @@ --color-input: #323232; --color-muted: #18181b; --color-popover: #18181b; + --color-popover-foreground: #fafafa; --color-destructive: #dc2626; --color-destructive-foreground: #ffffff; --color-secondary: #27272a; @@ -53,7 +56,9 @@ --color-foreground: #111827; --color-card: #f9fafb; --color-card-hover: #f3f4f6; + --color-card-foreground: #111827; --color-border: #e5e7eb; + --color-ring: #6b7280; --color-primary: #1d4ed8; --color-primary-hover: #1e40af; --color-primary-foreground: #ffffff; @@ -63,6 +68,7 @@ --color-input: #e5e7eb; --color-muted: #f4f4f5; --color-popover: #ffffff; + --color-popover-foreground: #111827; --color-destructive: #dc2626; --color-destructive-foreground: #ffffff; --color-secondary: #f4f4f5; diff --git a/frontend/src/lib/theme/colorTheme.test.ts b/frontend/src/lib/theme/colorTheme.test.ts index 2b5d3bd6..aed8c81c 100644 --- a/frontend/src/lib/theme/colorTheme.test.ts +++ b/frontend/src/lib/theme/colorTheme.test.ts @@ -1,4 +1,5 @@ import indexHtml from '../../../index.html?raw' +import indexCss from '../../index.css?raw' import { beforeEach, describe, expect, it } from 'vitest' import { APPEARANCE_STORAGE_KEY, @@ -14,6 +15,10 @@ function themeColorMeta(): string | null { return document.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? null } +function countOccurrences(source: string, needle: string): number { + return source.split(needle).length - 1 +} + function appearanceSnapshot() { const raw = window.localStorage.getItem(APPEARANCE_STORAGE_KEY) if (!raw) throw new Error('appearance snapshot missing') @@ -35,9 +40,33 @@ describe('applyColorTheme', () => { expect(root.style.getPropertyValue('--color-foreground')).toBe('#f8f8f2') expect(root.style.getPropertyValue('--color-primary')).toBe('#bd93f9') expect(root.style.getPropertyValue('--color-destructive')).toBe('#ff5555') + expect(root.style.getPropertyValue('--color-ring')).toBe('color-mix(in oklab, #f8f8f2 62%, #1d1e28)') + expect(root.style.getPropertyValue('--color-card-foreground')).toBe('#f8f8f2') + expect(root.style.getPropertyValue('--color-popover-foreground')).toBe('#f8f8f2') expect(themeColorMeta()).toBe('#1d1e28') }) + it('derives the focus ring and the card and popover foregrounds from the palette', () => { + const dark = resolveColorThemeTokens('dracula', true) + const light = resolveColorThemeTokens('dracula', false) + + expect(dark?.ring).toBe(dark?.['muted-foreground']) + expect(dark?.['card-foreground']).toBe('#f8f8f2') + expect(dark?.['popover-foreground']).toBe('#f8f8f2') + expect(light?.['card-foreground']).toBe('#1f1f2f') + expect(light?.['popover-foreground']).toBe('#1f1f2f') + expect(resolveColorThemeTokens('oc-2', true)?.ring).toBe('#707070') + }) + + it('defines every themed token once for dark mode and once for light mode', () => { + const keys = Object.keys(resolveColorThemeTokens('dracula', true) ?? {}) + + expect(keys).toEqual(expect.arrayContaining(['ring', 'card-foreground', 'popover-foreground'])) + for (const key of keys) { + expect(countOccurrences(indexCss, `--color-${key}:`)).toBe(2) + } + }) + it('applies the Dracula light palette when the mode is light', () => { applyColorTheme(document.documentElement, 'dracula', false) diff --git a/frontend/src/lib/theme/colorTheme.ts b/frontend/src/lib/theme/colorTheme.ts index fb9b9a2f..433cb921 100644 --- a/frontend/src/lib/theme/colorTheme.ts +++ b/frontend/src/lib/theme/colorTheme.ts @@ -9,7 +9,9 @@ const MANAGER_THEME_TOKENS = [ 'foreground', 'card', 'card-hover', + 'card-foreground', 'border', + 'ring', 'primary', 'primary-hover', 'primary-foreground', @@ -18,6 +20,7 @@ const MANAGER_THEME_TOKENS = [ 'input', 'muted', 'popover', + 'popover-foreground', 'destructive', 'destructive-foreground', 'secondary', @@ -134,11 +137,14 @@ export function resolveColorThemeTokens( foreground: ink, card: mix(4), 'card-hover': mix(7), + 'card-foreground': ink, popover: mix(5), + 'popover-foreground': ink, muted: mix(6), accent: mix(10), secondary: mix(10), border: mix(14), + ring: mutedForeground, input: mix(16), 'muted-foreground': mutedForeground, primary, diff --git a/frontend/src/lib/theme/syntaxHighlight.test.ts b/frontend/src/lib/theme/syntaxHighlight.test.ts index 42ea06ea..8806b359 100644 --- a/frontend/src/lib/theme/syntaxHighlight.test.ts +++ b/frontend/src/lib/theme/syntaxHighlight.test.ts @@ -3,10 +3,6 @@ import textPart from '../../components/message/TextPart.tsx?raw' import { describe, expect, it } from 'vitest' import { resolveColorThemeTokens } from './colorTheme' -function countOccurrences(source: string, needle: string): number { - return source.split(needle).length - 1 -} - describe('syntax highlight stylesheet', () => { it('does not import GitHub highlight.js stylesheets', () => { expect(indexCss).not.toContain('highlight.js/styles') @@ -26,7 +22,6 @@ describe('syntax highlight stylesheet', () => { for (const key of syntaxKeys) { expect(indexCss).toContain(`var(--color-${key})`) - expect(countOccurrences(indexCss, `--color-${key}:`)).toBe(2) } }) })