diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsx index eb7d21bc63..468f079a4a 100644 --- a/client/src/components/Chat/Input/ChatForm.tsx +++ b/client/src/components/Chat/Input/ChatForm.tsx @@ -828,7 +828,7 @@ const ChatForm = memo(function ChatForm({ follows the theme instead of the raw `violet-800/60` edge that composited to 1.48:1 on the high contrast dark canvas. Held at half alpha in the standard palettes, where series-6 is - a saturated #7e23cd / #ab68fe and a full-strength edge reads as + a saturated purple in both modes and a full-strength edge reads as a warning rather than a quiet mode hint. The contrast modes take it opaque, because that is the only way it clears the 3:1 non-text floor there. */ diff --git a/client/src/components/Chat/Input/Files/DragDropOverlay.tsx b/client/src/components/Chat/Input/Files/DragDropOverlay.tsx index 6b568857c5..a04b8772d7 100644 --- a/client/src/components/Chat/Input/Files/DragDropOverlay.tsx +++ b/client/src/components/Chat/Input/Files/DragDropOverlay.tsx @@ -49,7 +49,7 @@ const DragDropOverlay = memo(({ isActive }: DragDropOverlayProps) => { fillRule="evenodd" clipRule="evenodd" d="M25.2025 29.3514C10.778 33.2165 8.51524 37.1357 11.8281 49.4995L13.4846 55.6814C16.7975 68.0453 20.7166 70.308 35.1411 66.443L43.3837 64.2344C57.8082 60.3694 60.0709 56.4502 56.758 44.0864L55.1016 37.9044C51.7887 25.5406 47.8695 23.2778 33.445 27.1428L29.3237 28.2471L25.2025 29.3514ZM18.1944 42.7244C18.8572 41.5764 20.325 41.1831 21.4729 41.8459L27.3517 45.24C28.4996 45.9027 28.8929 47.3706 28.2301 48.5185L24.836 54.3972C24.1733 55.5451 22.7054 55.9384 21.5575 55.2757C20.4096 54.613 20.0163 53.1451 20.6791 51.9972L22.8732 48.1969L19.0729 46.0028C17.925 45.3401 17.5317 43.8723 18.1944 42.7244ZM29.4091 56.3843C29.066 55.104 29.8258 53.7879 31.1062 53.4449L40.3791 50.9602C41.6594 50.6172 42.9754 51.377 43.3184 52.6573C43.6615 53.9376 42.9017 55.2536 41.6214 55.5967L32.3485 58.0813C31.0682 58.4244 29.7522 57.6646 29.4091 56.3843Z" - fill="#AFC1FF" + className="fill-illustration-subtle" /> @@ -57,31 +57,21 @@ const DragDropOverlay = memo(({ isActive }: DragDropOverlayProps) => { fillRule="evenodd" clipRule="evenodd" d="M86.8124 13.4036C81.0973 11.8722 78.5673 13.2649 77.0144 19.0603L68.7322 49.97C67.1793 55.7656 68.5935 58.2151 74.4696 59.7895L97.4908 65.958C103.367 67.5326 105.816 66.1184 107.406 60.1848L115.393 30.379C115.536 29.8456 115.217 29.2959 114.681 29.16C113.478 28.8544 112.435 28.6195 111.542 28.4183C106.243 27.2253 106.22 27.2201 109.449 20.7159C109.73 20.1507 109.426 19.4638 108.816 19.3004L86.8124 13.4036ZM87.2582 28.4311C86.234 28.1567 85.1812 28.7645 84.9067 29.7888C84.6323 30.813 85.2401 31.8658 86.2644 32.1403L101.101 36.1158C102.125 36.3902 103.178 35.7824 103.453 34.7581C103.727 33.7339 103.119 32.681 102.095 32.4066L87.2582 28.4311ZM82.9189 37.2074C83.1934 36.1831 84.2462 35.5753 85.2704 35.8497L100.107 39.8252C101.131 40.0996 101.739 41.1524 101.465 42.1767C101.19 43.201 100.137 43.8088 99.1132 43.5343L84.2766 39.5589C83.2523 39.2844 82.6445 38.2316 82.9189 37.2074ZM83.2826 43.2683C82.2584 42.9939 81.2056 43.6017 80.9311 44.626C80.6567 45.6502 81.2645 46.703 82.2888 46.9775L89.7071 48.9652C90.7313 49.2396 91.7841 48.6318 92.0586 47.6076C92.333 46.5833 91.7252 45.5305 90.7009 45.256L83.2826 43.2683Z" - fill="#7989FF" + className="fill-illustration" /> - + - + diff --git a/client/src/components/Chat/Messages/Content/Parts/Reasoning.tsx b/client/src/components/Chat/Messages/Content/Parts/Reasoning.tsx index 8d158abb87..6486838e8c 100644 --- a/client/src/components/Chat/Messages/Content/Parts/Reasoning.tsx +++ b/client/src/components/Chat/Messages/Content/Parts/Reasoning.tsx @@ -47,14 +47,14 @@ const lastSentences = (text: string): string => { * panel uses. * * Custom-CSS exception, narrowly scoped: this is a `mask-image` stencil, not - * paint. Only the alpha channel is read, so `#000` means "keep this pixel" + * paint. Only the alpha channel is read, so `black` means "keep this pixel" * and `transparent` means "hide it". The hue never reaches the screen and no * theme could meaningfully restyle it. Routing it through a theme role would * invite a token with alpha, which would silently wash out the text the mask * is supposed to keep. Tailwind has no mask-image utility that expresses a * four-stop gradient with `calc()` offsets, hence the inline style. */ const PEEK_FADE = - 'linear-gradient(to bottom, transparent, #000 1.25rem, #000 calc(100% - 1.25rem), transparent)'; + 'linear-gradient(to bottom, transparent, black 1.25rem, black calc(100% - 1.25rem), transparent)'; /** * Collapsed live preview of streaming reasoning. Mirrors the expanded thought diff --git a/client/src/components/Endpoints/Icon.tsx b/client/src/components/Endpoints/Icon.tsx index c674520e1d..c335868357 100644 --- a/client/src/components/Endpoints/Icon.tsx +++ b/client/src/components/Endpoints/Icon.tsx @@ -86,9 +86,8 @@ const UserAvatar = memo( style={{ width: '20px', height: '20px', - boxShadow: 'rgba(240, 246, 252, 0.1) 0px 0px 0px 1px', }} - className="bg-avatar-fill text-avatar-text relative flex h-9 w-9 items-center justify-center rounded-sm p-1" + className="bg-avatar-fill text-avatar-text ring-avatar-edge/10 relative flex h-9 w-9 items-center justify-center rounded-sm p-1 ring-1" > diff --git a/client/src/components/Messages/Content/Mermaid/Export.tsx b/client/src/components/Messages/Content/Mermaid/Export.tsx index 171ca0bd9c..9c8c1d6056 100644 --- a/client/src/components/Messages/Content/Mermaid/Export.tsx +++ b/client/src/components/Messages/Content/Mermaid/Export.tsx @@ -1,7 +1,7 @@ import React, { memo, useCallback, useId, useMemo, useRef, useState } from 'react'; import * as Ariakit from '@ariakit/react'; -import { DropdownPopup, TooltipAnchor, useToastContext } from '@librechat/client'; import { FileCode2, FileImage, ImageDown, LoaderCircle, Workflow } from 'lucide-react'; +import { DropdownPopup, TooltipAnchor, readThemeColor, useToastContext } from '@librechat/client'; import type { LucideIcon } from 'lucide-react'; import type { MermaidDimensions } from '~/utils/diagram/export'; import type { TranslationKeys } from '~/hooks/useLocalize'; @@ -32,16 +32,7 @@ interface MermaidExportProps { } function surfaceBackground(): string | undefined { - const value = getComputedStyle(document.documentElement) - .getPropertyValue('--surface-primary-alt') - .trim(); - if (!value) { - return undefined; - } - if (/^[\d.]+(?:\s+[\d.]+){2}(?:\s*\/\s*[\d.]+%?)?$/.test(value)) { - return `rgb(${value})`; - } - return value.startsWith('var(') ? undefined : value; + return readThemeColor('--surface-primary-alt') ?? undefined; } type ExportFormat = 'svg' | 'png' | 'source'; @@ -198,7 +189,7 @@ const MermaidExport = memo(function MermaidExport({ }); const items: MenuItemProps[] = EXPORT_FORMATS.map(({ format, labelKey, Icon }) => ({ label: localize(labelKey), - icon: , + icon: , ...(exporting === format ? loadingRow(format) : {}), disabled: svg == null || isBusy, onClick: format === 'svg' ? handleSvgExport : handlePngExport, @@ -206,7 +197,7 @@ const MermaidExport = memo(function MermaidExport({ if (onDownloadSource != null) { items.push({ label: localize('com_ui_export_mermaid_source'), - icon: , + icon: , ...(exporting === 'source' ? loadingRow('source') : {}), /* The source is the artifact's own content, so unlike SVG and PNG it * does not wait on a rendered preview. */ @@ -238,7 +229,7 @@ const MermaidExport = memo(function MermaidExport({ setIsOpen={setIsOpen} items={dropdownItems} portalElement={portalElement} - className="absolute right-0 top-0 mt-2 min-w-52 motion-reduce:!transition-none" + className="absolute top-0 right-0 mt-2 min-w-52 motion-reduce:!transition-none" trigger={ diff --git a/client/src/components/Share/MessageIcon.tsx b/client/src/components/Share/MessageIcon.tsx index fc57309d83..26eed90289 100644 --- a/client/src/components/Share/MessageIcon.tsx +++ b/client/src/components/Share/MessageIcon.tsx @@ -70,9 +70,8 @@ export default function MessageIcon( style={{ width: '20px', height: '20px', - boxShadow: 'rgba(240, 246, 252, 0.1) 0px 0px 0px 1px', }} - className="bg-avatar-fill text-avatar-text relative flex h-9 w-9 items-center justify-center rounded-sm p-1" + className="bg-avatar-fill text-avatar-text ring-avatar-edge/10 relative flex h-9 w-9 items-center justify-center rounded-sm p-1 ring-1" > diff --git a/client/src/hooks/Conversations/useUnseenBadge.ts b/client/src/hooks/Conversations/useUnseenBadge.ts index b8f4389d6a..e4ecb47bd1 100644 --- a/client/src/hooks/Conversations/useUnseenBadge.ts +++ b/client/src/hooks/Conversations/useUnseenBadge.ts @@ -1,4 +1,5 @@ import { useEffect } from 'react'; +import { readThemeColor } from '@librechat/client'; import { useReplyAlertPreferences } from './replyNotificationSettings'; import { getDocumentTitleRevision } from '~/utils'; @@ -10,10 +11,7 @@ const FALLBACK_ICON_SIZE = 32; * as the sidebar indicator. Returns null when the role cannot be read, which leaves the plain * favicon in place rather than painting a colour the active theme never chose. */ -const badgeColor = (): string | null => { - const value = getComputedStyle(document.documentElement).getPropertyValue('--status-info').trim(); - return value === '' ? null : `rgb(${value})`; -}; +const badgeColor = (): string | null => readThemeColor('--status-info'); const drawBadgedFavicon = ( source: string, diff --git a/client/src/hooks/ScreenshotContext.tsx b/client/src/hooks/ScreenshotContext.tsx index ff31f4454f..e99c177a5c 100644 --- a/client/src/hooks/ScreenshotContext.tsx +++ b/client/src/hooks/ScreenshotContext.tsx @@ -1,6 +1,6 @@ import { createContext, useRef, useContext, RefObject, ReactNode } from 'react'; import { toCanvas } from 'html-to-image'; -import { ThemeContext, isDark } from '@librechat/client'; +import { ThemeContext, isDark, readThemeColor } from '@librechat/client'; import { completeProgressiveRowMounts } from '~/hooks/Messages/useProgressiveRowMount'; type ScreenshotContextType = { @@ -62,11 +62,8 @@ export const useScreenshot = () => { * an export matches the selected appearance and the state colours keep the * contrast they were calibrated against. The token is a channel triplet, * not a colour, so it has to be wrapped before html-to-image sees it. */ - const canvasTriplet = getComputedStyle(document.documentElement) - .getPropertyValue('--surface-primary') - .trim(); const fallbackBackground = isDark(theme) ? '#171717' : 'white'; - const backgroundColor = canvasTriplet ? `rgb(${canvasTriplet})` : fallbackBackground; + const backgroundColor = readThemeColor('--surface-primary') ?? fallbackBackground; const canvas = await toCanvas(node, { backgroundColor, pixelRatio, diff --git a/e2e/specs/mock/scenarios/literal-roles-theme.spec.ts b/e2e/specs/mock/scenarios/literal-roles-theme.spec.ts new file mode 100644 index 0000000000..055d4a18c7 --- /dev/null +++ b/e2e/specs/mock/scenarios/literal-roles-theme.spec.ts @@ -0,0 +1,208 @@ +import { expect, test } from '@playwright/test'; +import type { Page } from '@playwright/test'; +import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse'; +import { NEW_CHAT_PATH } from '../helpers'; + +/** + * Colours that used to be literals in components now read roles: the default avatar's hairline + * (`avatar-edge`), the file drop zone's artwork (`illustration-*`) and a dragged badge's lift + * (`elevationDrag`). Without a theme each paints exactly what the literal did; the ClickHouse + * definition repaints the artwork from Click UI's info ramp. + */ + +type Mode = 'light' | 'dark'; + +const MODES: Mode[] = ['light', 'dark']; +const THEME_PARAM = 'e2eThemeMode'; +const MISSING_AVATAR = 'https://avatar.e2e.invalid/missing.png'; +const DROP_PROMPT = 'Drop any file here to add it to the conversation'; +const STOCK_ARTWORK = ['rgb(175, 193, 255)', 'rgb(121, 137, 255)', 'rgb(60, 70, 255)']; + +test.use({ viewport: { width: 1280, height: 800 } }); + +async function installThemeBridge(page: Page, definition: unknown) { + await page.addInitScript((stored) => { + const mode = new URL(location.href).searchParams.get('e2eThemeMode'); + if (mode) { + localStorage.setItem('color-theme', mode); + } + localStorage.setItem('navVisible', 'true'); + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + if (stored) { + localStorage.setItem('theme-definition', JSON.stringify(stored)); + localStorage.setItem('theme-source', 'definition'); + } else { + localStorage.removeItem('theme-definition'); + localStorage.removeItem('theme-source'); + } + }, definition ?? null); +} + +const rgbCss = (triplet: string | undefined) => `rgb(${(triplet ?? '').split(' ').join(', ')})`; + +/** + * The RGBA a colour paints, whatever syntax the browser serialises it in: an alpha utility + * computes to `oklab(...)` where the same colour written by hand reads `rgba(...)`. + */ +const painted = (page: Page, color: string): Promise => + page.evaluate((value) => { + const canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + const context = canvas.getContext('2d'); + if (!context) { + return []; + } + context.fillStyle = value; + context.fillRect(0, 0, 1, 1); + return Array.from(context.getImageData(0, 0, 1, 1).data); + }, color); + +/** The colour of the 1px spread layer in a computed `box-shadow` list, the one a `ring-1` draws. */ +function ringColor(boxShadow: string): string { + const layers = boxShadow.split(/,(?![^(]*\))/).map((layer) => layer.trim()); + const ring = layers.find((layer) => layer.endsWith('0px 0px 0px 1px')) ?? ''; + return ring.replace(/\s*0px 0px 0px 1px$/, ''); +} + +/** The default avatar only draws once the user's image fails to load. */ +async function failUserAvatar(page: Page) { + await page.route(`${MISSING_AVATAR}*`, (route) => route.abort()); + await page.route('**/api/user', async (route) => { + const response = await route.fetch(); + const user = await response.json(); + await route.fulfill({ response, json: { ...user, avatar: MISSING_AVATAR } }); + }); +} + +/** Drags a file over the composer and reads the three fills of the drop zone's artwork. */ +async function dropZoneArtwork(page: Page, capture: string): Promise { + const input = page.getByRole('textbox', { name: 'Message input' }); + await expect(input).toBeVisible({ timeout: 20000 }); + const dataTransfer = await page.evaluateHandle(() => { + const transfer = new DataTransfer(); + transfer.items.add(new File(['notes'], 'notes.txt', { type: 'text/plain' })); + return transfer; + }); + await input.dispatchEvent('dragenter', { dataTransfer }); + await input.dispatchEvent('dragover', { dataTransfer }); + const prompt = page.getByText(DROP_PROMPT, { exact: true }); + await expect(prompt).toBeVisible(); + await test.info().attach(capture, { body: await page.screenshot(), contentType: 'image/png' }); + const fills = await prompt.evaluate((node) => + Array.from(node.parentElement?.querySelectorAll('svg > g > path, svg > path') ?? []).map( + (path) => getComputedStyle(path).fill, + ), + ); + await input.dispatchEvent('dragleave', { dataTransfer }); + return fills; +} + +test.describe('roles for former colour literals', () => { + test('the default avatar keeps its hairline in both modes @scenario:default-avatar-keeps-its-hairline', async ({ + page, + }) => { + test.setTimeout(60000); + await installThemeBridge(page, null); + await failUserAvatar(page); + + for (const mode of MODES) { + await page.goto(`${NEW_CHAT_PATH}?${THEME_PARAM}=${mode}`); + const avatar = page.getByTestId('nav-user').locator('div[aria-hidden="true"]').first(); + await expect(avatar).toBeVisible({ timeout: 20000 }); + const shadow = await avatar.evaluate((node) => getComputedStyle(node).boxShadow); + const ring = ringColor(shadow); + expect(ring).not.toBe(''); + const [got, want] = await Promise.all([ + painted(page, ring), + painted(page, 'rgb(240 246 252 / 0.1)'), + ]); + expect(got).toHaveLength(4); + /* An oklab round trip may move a channel by one step; at 10% alpha the canvas rounds + * the unpremultiplied value a step further. */ + got.forEach((channel, index) => + expect(Math.abs(channel - want[index])).toBeLessThanOrEqual(2), + ); + } + }); + + test('the drop zone artwork keeps its blues without a theme @scenario:drop-zone-artwork-keeps-its-blues', async ({ + page, + }) => { + test.setTimeout(60000); + await installThemeBridge(page, null); + + for (const mode of MODES) { + await page.goto(`${NEW_CHAT_PATH}?${THEME_PARAM}=${mode}`); + expect(await dropZoneArtwork(page, `drop-zone-default-${mode}`)).toEqual(STOCK_ARTWORK); + } + }); + + test('the ClickHouse definition paints the drop zone artwork from Click UI @scenario:clickhouse-drop-zone-artwork-follows-click-ui', async ({ + page, + }) => { + test.setTimeout(60000); + await installThemeBridge(page, clickHouseTheme); + + for (const mode of MODES) { + const colors = clickHouseTheme.modes[mode]?.colors ?? {}; + await page.goto(`${NEW_CHAT_PATH}?${THEME_PARAM}=${mode}`); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + expect(await dropZoneArtwork(page, `drop-zone-clickhouse-${mode}`)).toEqual([ + rgbCss(colors['rgb-illustration-subtle']), + rgbCss(colors['rgb-illustration']), + rgbCss(colors['rgb-illustration-strong']), + ]); + } + }); + + test('a dragged badge lifts with the theme elevation @scenario:dragged-badge-lift-follows-the-theme', async ({ + page, + }) => { + test.setTimeout(60000); + /* One init script for both cases: Playwright does not order several init scripts, so a + * second bridge could run before the first and leave the earlier theme in place. */ + await page.addInitScript((definition) => { + const params = new URL(location.href).searchParams; + localStorage.setItem('color-theme', 'light'); + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + if (params.get('e2eDefinition') === 'clickhouse') { + localStorage.setItem('theme-definition', JSON.stringify(definition)); + localStorage.setItem('theme-source', 'definition'); + } else { + localStorage.removeItem('theme-definition'); + localStorage.removeItem('theme-source'); + } + }, clickHouseTheme); + const cases: Array<[string, string | undefined]> = [ + ['stock', '0 10px 25px rgb(0 0 0 / 0.1)'], + ['clickhouse', clickHouseTheme.modes.light?.appearance?.elevationDrag], + ]; + for (const [definition, expected] of cases) { + await page.goto(`${NEW_CHAT_PATH}?e2eDefinition=${definition}`); + await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({ + timeout: 20000, + }); + if (definition === 'clickhouse') { + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + } + /* The badge animates to `var(--theme-elevation-drag)`; compare what that resolves to + * against the value the theme declares, both as the browser computes a box-shadow. */ + const [lift, declared] = await page.evaluate((value) => { + const read = (shadow: string) => { + const probe = document.createElement('div'); + probe.style.boxShadow = shadow; + document.body.append(probe); + const computed = getComputedStyle(probe).boxShadow; + probe.remove(); + return computed; + }; + return [read('var(--theme-elevation-drag)'), read(value ?? '')]; + }, expected); + expect(declared).not.toBe('none'); + expect(lift).toBe(declared); + } + }); +}); diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 3c48b1ca78..53b3a28a5b 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -216,9 +216,6 @@ "client/src/components/Chat/Input/Files/DragDropOverlay.tsx": { "shadcn/no-inline-styles": { "count": 3 - }, - "shadcn/no-raw-colors": { - "count": 5 } }, "client/src/components/Chat/Input/Files/FileRow.tsx": { @@ -990,11 +987,6 @@ "count": 1 } }, - "client/src/components/Endpoints/Icon.tsx": { - "shadcn/no-inline-styles": { - "count": 1 - } - }, "client/src/components/Endpoints/MessageEndpointIcon.tsx": { "shadcn/no-arbitrary-values": { "count": 1 @@ -1476,11 +1468,6 @@ "count": 3 } }, - "client/src/components/Share/MessageIcon.tsx": { - "shadcn/no-inline-styles": { - "count": 1 - } - }, "client/src/components/Share/MessagesView.tsx": { "shadcn/no-inline-styles": { "count": 1 @@ -2179,7 +2166,7 @@ }, "packages/client/src/components/Avatar.tsx": { "shadcn/no-inline-styles": { - "count": 2 + "count": 1 } }, "packages/client/src/components/Badge.tsx": { diff --git a/packages/client/src/components/Avatar.tsx b/packages/client/src/components/Avatar.tsx index b1ae4805aa..ecb344d707 100644 --- a/packages/client/src/components/Avatar.tsx +++ b/packages/client/src/components/Avatar.tsx @@ -53,9 +53,8 @@ const Avatar: React.FC = ({ style={{ width: `${size}px`, height: `${size}px`, - boxShadow: 'rgba(240, 246, 252, 0.1) 0px 0px 0px 1px', }} - className={`bg-avatar-fill text-avatar-text relative flex items-center justify-center rounded-full p-1 ${className}`} + className={`bg-avatar-fill text-avatar-text ring-avatar-edge/10 relative flex items-center justify-center rounded-full p-1 ring-1 ${className}`} aria-hidden="true" > diff --git a/packages/client/src/components/Badge.tsx b/packages/client/src/components/Badge.tsx index bf7c74f105..0b1480d02b 100644 --- a/packages/client/src/components/Badge.tsx +++ b/packages/client/src/components/Badge.tsx @@ -128,7 +128,7 @@ export default function Badge({ className={badgeClassName} animate={{ scale: isDragging ? 1.1 : 1, - boxShadow: isDragging ? '0 10px 25px rgba(0,0,0,0.1)' : undefined, + boxShadow: isDragging ? 'var(--theme-elevation-drag)' : undefined, }} whileTap={{ scale: getWhileTapScale() }} transition={{ type: 'tween', duration: 0.1, ease: 'easeOut' }} @@ -145,7 +145,7 @@ export default function Badge({ className={badgeClassName} animate={{ scale: isDragging ? 1.1 : 1, - boxShadow: isDragging ? '0 10px 25px rgba(0,0,0,0.1)' : undefined, + boxShadow: isDragging ? 'var(--theme-elevation-drag)' : undefined, }} whileTap={{ scale: getWhileTapScale() }} transition={{ type: 'tween', duration: 0.1, ease: 'easeOut' }} diff --git a/packages/client/src/svgs/AnthropicIcon.tsx b/packages/client/src/svgs/AnthropicIcon.tsx index 6ce5bc9897..fc82e363de 100644 --- a/packages/client/src/svgs/AnthropicIcon.tsx +++ b/packages/client/src/svgs/AnthropicIcon.tsx @@ -24,7 +24,6 @@ export default function AnthropicIcon({ > @@ -38,7 +37,6 @@ export default function AnthropicIcon({ > diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md index fecddc0c83..130948ac3f 100644 --- a/packages/client/src/theme/README.md +++ b/packages/client/src/theme/README.md @@ -37,7 +37,8 @@ through `radius3xl` (`--theme-radius-*`), `font-sans` reads `fontFamily` (`--the `shadow-2xl` (and bare `shadow`, which matches `sm`) read `shadow2xs` through `shadow2xl` (`--theme-shadow-*`). A shadow step must be a concrete `box-shadow` list (no `var()`, `env()` or `attr()`) or `none`. `elevationSurface` stays the separate role behind `shadow-theme-surface` and -keeps its original validation, so a released theme holding `var()` there still loads. On every +keeps its original validation, so a released theme holding `var()` there still loads. `elevationDrag` +(`--theme-elevation-drag`) is the lift a dragged badge takes while it is held. On every shadow role, `none` is written as a transparent layer so Tailwind can still compose it with ring utilities. The defaults reproduce the scale those utilities had before, so a theme that names none of them @@ -299,6 +300,7 @@ function MyComponent() { - `bg-surface-chat` - Chat interface background - `bg-surface-code` - Code block chrome: toolbar, output and result switcher - `bg-surface-code-body` - Code block pane behind the highlighted code +- `fill-illustration-subtle`, `fill-illustration`, `fill-illustration-strong` - The three tones of in-app artwork, such as the file drop zone's illustration - `bg-surface-qr` - Backdrop behind a QR code, kept light in every mode so it scans ### Border Colors diff --git a/packages/client/src/theme/allowlist.md b/packages/client/src/theme/allowlist.md index 673157f535..3386a775a8 100644 --- a/packages/client/src/theme/allowlist.md +++ b/packages/client/src/theme/allowlist.md @@ -1,8 +1,8 @@ # Colours outside the theme -Every colour in `client/src` and `packages/client/src` that the theme-leakage sweep reached comes from a semantic theme role, except the ones below. Each is a colour that must not follow the theme: a brand mark, artwork, a third party's surface, a document that leaves the app, or the theme definitions themselves. Scrims, chips and progress drawn over the user's own media are not exceptions: they read `surface-media-overlay` and `text-on-media`, which every bundled theme keeps black and white. An entry names the file, what the literal paints and why the theme does not own it. +Every colour in `client/src` and `packages/client/src` comes from a semantic theme role, except the entries below. Each entry is one kind of colour that must not follow the theme, with the files that hold it and why the theme does not own it. Scrims, chips and progress drawn over the user's own media are not exceptions: they read `surface-media-overlay` and `text-on-media`, which every bundled theme keeps black and white. The drop zone's artwork reads the `illustration` roles, the default avatar's hairline `avatar-edge`, and a dragged badge's lift `elevationDrag`. -The sweep skipped files an open pull request was editing; those, with their counts, are listed in berry-13/LibreChat#195, and the avatar colours that still need roles in berry-13/LibreChat#194. Until those land, a file absent from this list is not evidence that it holds no literal colour. +Files an open pull request was editing when this list was last swept, with their counts, are listed in berry-13/LibreChat#195. Until those land, a file absent from this list is not evidence that it holds no literal colour. A literal the design lint can see stays recorded in `eslint-suppressions.json` (inline disables of the design rules are rejected by the static checks), so its count there is the exception, not @@ -10,51 +10,17 @@ debt; the file-scoped allow entry for these paths belongs in `eslint.config.mjs` is invisible to the lint (CSS, strings passed to a canvas or an iframe), so this list is the record. Adding an entry needs the same bar: if a theme author would reasonably want to recolour it, it -is a role, not an exception. +is a role, not an exception. Keep the list to ten entries or fewer; a new kind of exception that +does not fit an entry below is a sign it should be a role. -## Theme definitions - -| File | Why | -| -------------------------------------------------------------- | --------------------------------------------------------------- | -| `packages/client/src/theme/themes/*.ts`, `themes/clickui.json` | The palettes themselves: these are the values roles resolve to. | -| `packages/client/src/theme/registry.ts` | Theme resolution and fallbacks written in channel triplets. | -| `packages/client/src/theme/tokens.css` | Maps each role to `rgb(var(--role))`; no literal colour. | - -## Brand marks and artwork - -| File | Why | -| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `packages/client/src/svgs/GoogleIcon.tsx` | Google's multicolour mark, fixed by its brand guidelines. | -| `packages/client/src/svgs/FacebookIcon.tsx` | Facebook's mark, fixed by its brand guidelines. | -| `packages/client/src/svgs/DiscordIcon.tsx` | Discord's mark, fixed by its brand guidelines. | -| `packages/client/src/svgs/GeminiIcon.tsx` | Gemini's gradient mark, fixed by its brand guidelines. | -| `packages/client/src/svgs/PaLMIcon.tsx` | PaLM's multicolour mark, fixed by its brand guidelines. | -| `packages/client/src/svgs/BirthdayIcon.tsx` | A multicolour illustration; the palette is artwork, not a UI role. | -| `packages/client/src/components/PixelCard.tsx` | The `blue`, `yellow` and `pink` presets are decorative palettes a caller opts into, like the `colors` prop; the app renders only the default, which reads theme roles. | -| `packages/client/src/icons/provider/registry.ts`, `icons/provider/Avatar.tsx` | Provider brand colours, each already behind a `--provider-*` variable a deployment can override; the literal is only the fallback. | -| `client/src/mobile.css` | `.azure-bg-color`, the Azure file-source chip's blue gradient, fixed by Azure's brand. | - -## Elevation ink in library stylesheets - -| File | Why | -| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `packages/client/src/components/Dropdown.css` | Popover shadows in black alpha. The app paints `.popover-ui` from its own copy of these rules in `client/src/style.css`, so moving either copy to `--theme-shadow-lg` needs both edited together. | -| `packages/client/src/components/Tooltip.css` | Tooltip shadows are smaller than any step of the theme shadow scale; black alpha ink, dropped in high contrast where the border takes over. | - -## Chat: media, artwork and documents that leave the app - -| File | Why | -| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `client/src/components/Chat/Input/Files/DragDropOverlay.tsx` | The drop-zone illustration's fills are artwork. Its backdrop is on `surface-media-overlay`. | -| `client/src/components/Chat/Input/Files/SourceIcon.tsx` | The OpenAI file-source chip (white/75, black/65 in dark) behind OpenAI's mark, like the Azure chip in `mobile.css`. The code-execution badge is on `surface-media-overlay`. | -| `client/src/utils/markdown.ts` | The downloaded HTML document's GitHub Primer stylesheet; it is read outside the app, where no theme variables exist. Its high-contrast branch already reads the roles. | -| `client/src/utils/mermaid.ts` | The mermaid artifact document and its zoom controls render in a sandboxed iframe without theme variables; the token reads' fallbacks and the luminance repair ink are literals by necessity. | -| `client/src/utils/richtext.ts` | Inline styles on HTML copied to the clipboard for pasting into other apps, which must not carry the sender's theme. | -| `client/src/utils/artifacts.ts` | The scrollbar thumb inside the sandboxed artifact document, which renders in its own iframe and never reads the app's theme. | -| `client/src/utils/officePreview.ts`, `client/src/hooks/ScreenshotContext.tsx` | Fallbacks for a theme role read at runtime, used only when the variable is unset. | - -## Panels: media and third-party surfaces - -| File | Why | -| ----------------------------------------------- | --------------------------------------------------------------------------------------------------- | -| `client/src/hooks/Files/useSharePointPicker.ts` | Background of Microsoft's SharePoint file picker iframe, matched to that third party's own surface. | +| # | Entry | Files | Why | +| --- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Theme definitions | `packages/client/src/theme/themes/*.ts`, `themes/clickui.json`, `packages/client/src/theme/registry.ts`, `packages/client/src/theme/defaults.css`, `packages/client/src/theme/tokens.css` | The palettes and appearance values themselves: these are the values roles resolve to. | +| 2 | Third-party brand marks | `packages/client/src/svgs/GoogleIcon.tsx`, `FacebookIcon.tsx`, `DiscordIcon.tsx`, `GeminiIcon.tsx`, `PaLMIcon.tsx`; `client/src/mobile.css` (`.azure-bg-color`); `client/src/components/Chat/Input/Files/SourceIcon.tsx` (the OpenAI chip) | Fixed by each company's brand guidelines: the Google, Facebook, Discord, Gemini and PaLM marks, the Azure file-source chip's blue gradient, and the OpenAI file-source chip (white/75, black/65 in dark) behind OpenAI's mark. | +| 3 | Provider brand colours | `packages/client/src/icons/provider/registry.ts`, `icons/provider/Avatar.tsx` | Each provider colour is already behind a `--provider-*` variable a deployment can override; the literal is only its fallback. | +| 4 | Opt-in decorative palettes | `packages/client/src/svgs/BirthdayIcon.tsx`, `packages/client/src/components/PixelCard.tsx` | A multicolour illustration, and the `blue`, `yellow` and `pink` PixelCard presets a caller opts into like its `colors` prop. The app renders only PixelCard's default, which reads theme roles. | +| 5 | Documents that leave the app | `client/src/utils/markdown.ts`, `client/src/utils/richtext.ts` | The downloaded HTML document's GitHub Primer stylesheet, and inline styles on HTML copied to the clipboard; both are read outside the app, where no theme variables exist and the sender's theme must not travel. The markdown high-contrast branch reads the roles. | +| 6 | Sandboxed iframe documents | `client/src/utils/mermaid.ts`, `client/src/utils/artifacts.ts` | The mermaid document and its zoom controls, and the artifact document's scrollbar thumb, render in their own iframe without theme variables; the token reads' fallbacks and the luminance repair ink are literals by necessity. | +| 7 | Third-party surface | `client/src/hooks/Files/useSharePointPicker.ts` | Background of Microsoft's SharePoint file picker iframe, matched to that third party's own surface. | +| 8 | Library stylesheet elevation | `packages/client/src/components/Dropdown.css`, `packages/client/src/components/Tooltip.css` | Popover and tooltip shadows in black alpha. The app paints `.popover-ui` from its own copy of the Dropdown rules in `client/src/style.css`, so both copies move to `--theme-shadow-lg` together; the tooltip shadow is smaller than any shadow step. | +| 9 | Fallbacks for a role read at runtime | `client/src/utils/officePreview.ts`, `client/src/hooks/ScreenshotContext.tsx` | Used only when the role's variable is unset; the value painted otherwise is the role, read with `readThemeColor` or from the bundled palette. | diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.css index 5bff62e109..57170cd16c 100644 --- a/packages/client/src/theme/defaults.css +++ b/packages/client/src/theme/defaults.css @@ -79,6 +79,10 @@ html { --avatar-fill: 121 137 255; --avatar-text: var(--text-primary); --avatar-placeholder: var(--surface-secondary); + --avatar-edge: 240 246 252; + --illustration-subtle: 175 193 255; + --illustration: 121 137 255; + --illustration-strong: 60 70 255; --presentation: var(--white); --text-primary: var(--gray-800); --text-secondary: var(--gray-600); @@ -265,6 +269,7 @@ html { 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, 'Cascadia Mono', 'Liberation Mono', Consolas, monospace; --theme-elevation-surface: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); + --theme-elevation-drag: 0 10px 25px rgb(0 0 0 / 0.1); --theme-shadow-2xs: 0 1px rgb(0 0 0 / 0.05); --theme-shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05); --theme-shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); @@ -298,6 +303,10 @@ html { --avatar-fill: 121 137 255; --avatar-text: var(--text-primary); --avatar-placeholder: var(--surface-tertiary); + --avatar-edge: 240 246 252; + --illustration-subtle: 175 193 255; + --illustration: 121 137 255; + --illustration-strong: 60 70 255; --presentation: var(--gray-800); --text-primary: var(--gray-100); --focus-outline: 255 255 255; diff --git a/packages/client/src/theme/defaults.spec.ts b/packages/client/src/theme/defaults.spec.ts index 04e12aa753..427bd7d835 100644 --- a/packages/client/src/theme/defaults.spec.ts +++ b/packages/client/src/theme/defaults.spec.ts @@ -68,7 +68,7 @@ describe.each([ const tokens = Object.keys(theme) as Array; it('covers every registry color', () => { - expect(tokens).toHaveLength(116); + expect(tokens).toHaveLength(120); }); it('resolves every registry color to the runtime theme value', () => { diff --git a/packages/client/src/theme/index.ts b/packages/client/src/theme/index.ts index d230f875cd..4c2a781589 100644 --- a/packages/client/src/theme/index.ts +++ b/packages/client/src/theme/index.ts @@ -43,5 +43,8 @@ export { // Export theme atoms for persistence export { themeModeAtom, themeColorsAtom, themeNameAtom } from './atoms/themeAtoms'; +// Read a theme color role for code that paints outside the stylesheet +export { readThemeColor } from './utils/color'; + // Export predefined themes export * from './themes'; diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts index fcb9e1d463..116ce3d4e1 100644 --- a/packages/client/src/theme/registry.ts +++ b/packages/client/src/theme/registry.ts @@ -218,6 +218,7 @@ export const themeAppearanceProperties: Readonly< alertScrimOpacity: '--theme-alert-scrim-opacity', modalScrimOpacity: '--theme-modal-scrim-opacity', elevationSurface: '--theme-elevation-surface', + elevationDrag: '--theme-elevation-drag', shadow2xs: '--theme-shadow-2xs', shadowXs: '--theme-shadow-xs', shadowSm: '--theme-shadow-sm', @@ -292,6 +293,7 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({ alertScrimOpacity: '0.9', modalScrimOpacity: '0.65', elevationSurface: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)', + elevationDrag: '0 10px 25px rgb(0 0 0 / 0.1)', shadow2xs: '0 1px rgb(0 0 0 / 0.05)', shadowXs: '0 1px 2px 0 rgb(0 0 0 / 0.05)', shadowSm: '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)', @@ -432,6 +434,7 @@ function knownAppearance(appearance?: Partial): Partial = [ 'elevationSurface', + 'elevationDrag', 'shadow2xs', 'shadowXs', 'shadowSm', diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts index 09e13aa9e6..77d7219efc 100644 --- a/packages/client/src/theme/themes/clickhouse.ts +++ b/packages/client/src/theme/themes/clickhouse.ts @@ -141,6 +141,10 @@ export const clickHouseLightTheme: IThemeRGB = { 'rgb-avatar-fill': '105 110 121', // #696e79 (avatar.color.background.default) 'rgb-avatar-text': '255 255 255', // #ffffff (avatar.color.text.default) 'rgb-avatar-placeholder': '246 247 250', // #f6f7fa (background.muted) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc (Click UI avatars draw no edge) + 'rgb-illustration-subtle': '161 190 247', // #a1bef7 (palette.info.200) + 'rgb-illustration': '67 126 239', // #437eef (palette.info.400) + 'rgb-illustration-strong': '16 78 198', // #104ec6 (palette.info.600) // Code syntax 'rgb-syntax-text': '40 40 40', // #282828 (codeblock.lightMode.color.text.default) @@ -288,6 +292,10 @@ export const clickHouseDarkTheme: IThemeRGB = { 'rgb-avatar-fill': '128 134 145', // #808691 (avatar.color.background.default) 'rgb-avatar-text': '31 31 28', // #1f1f1c (avatar.color.text.default) 'rgb-avatar-placeholder': '40 40 40', // #282828 (background.muted) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc (Click UI avatars draw no edge) + 'rgb-illustration-subtle': '161 190 247', // #a1bef7 (palette.info.200) + 'rgb-illustration': '67 126 239', // #437eef (palette.info.400) + 'rgb-illustration-strong': '16 78 198', // #104ec6 (palette.info.600) // Code syntax 'rgb-syntax-text': '255 255 255', // #ffffff (codeblock.darkMode.color.text.default) @@ -441,6 +449,7 @@ const clickHouseElevation = (alpha: number): Partial => ({ menuShadow: elevation(alpha), // genericMenu.panel.shadow.default, which is shadow.1 /** Click UI's tooltip draws no shadow (Tooltip.module.css). */ tooltipShadow: 'none', + elevationDrag: elevation(alpha), // shadow.1 }); const clickHouseLightAppearance: Partial = { diff --git a/packages/client/src/theme/themes/clickui.json b/packages/client/src/theme/themes/clickui.json index d992e31d8e..592242a30f 100644 --- a/packages/client/src/theme/themes/clickui.json +++ b/packages/client/src/theme/themes/clickui.json @@ -101,6 +101,7 @@ "palette.danger.700": "#910000", "palette.fuchsia.700": "#990073", "palette.info.200": "#a1bef7", + "palette.info.400": "#437eef", "palette.info.500": "#1d64ec", "palette.info.600": "#104ec6", "palette.neutral.0": "#ffffff", @@ -229,7 +230,9 @@ "palette.danger.200": "#ff9898", "palette.danger.300": "#ff7575", "palette.danger.700": "#910000", + "palette.info.200": "#a1bef7", "palette.info.300": "#6d9bf3", + "palette.info.400": "#437eef", "palette.info.600": "#104ec6", "palette.neutral.0": "#ffffff", "palette.neutral.500": "#808080", diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.ts index 377f3d9e22..fbab605d5f 100644 --- a/packages/client/src/theme/themes/clickui.spec.ts +++ b/packages/client/src/theme/themes/clickui.spec.ts @@ -149,6 +149,9 @@ const colorSources: Record>> 'rgb-avatar-fill': 'click.avatar.color.background.default', 'rgb-avatar-text': 'click.avatar.color.text.default', 'rgb-avatar-placeholder': 'global.color.background.muted', + 'rgb-illustration-subtle': 'palette.info.200', + 'rgb-illustration': 'palette.info.400', + 'rgb-illustration-strong': 'palette.info.600', 'rgb-syntax-text': 'click.codeblock.lightMode.color.text.default', 'rgb-syntax-comment': 'global.color.text.muted', 'rgb-syntax-meta': 'palette.slate.700', @@ -265,6 +268,9 @@ const colorSources: Record>> 'rgb-avatar-fill': 'click.avatar.color.background.default', 'rgb-avatar-text': 'click.avatar.color.text.default', 'rgb-avatar-placeholder': 'global.color.background.muted', + 'rgb-illustration-subtle': 'palette.info.200', + 'rgb-illustration': 'palette.info.400', + 'rgb-illustration-strong': 'palette.info.600', 'rgb-syntax-text': 'click.codeblock.darkMode.color.text.default', 'rgb-syntax-comment': 'global.color.text.muted', 'rgb-syntax-meta': 'palette.slate.400', @@ -292,6 +298,8 @@ const colorSources: Record>> /** Click UI has no scrim for media; a lightbox or preview frames the user's image in black. */ const MEDIA_OVERLAY_REASON = 'Click UI has no media scrim; the image frame stays black in both modes'; +const AVATAR_EDGE_REASON = + 'Click UI avatars draw no edge; the theme keeps the 10% hairline every LibreChat avatar has'; const MEDIA_SCRIM_DEPARTURE = 'the dialog scrim is the nearest Click UI job; a lightbox frames the user image in black instead'; @@ -299,11 +307,13 @@ const MEDIA_SCRIM_DEPARTURE = const unsourcedColors: Record>> = { light: { 'rgb-surface-media-overlay': MEDIA_OVERLAY_REASON, + 'rgb-avatar-edge': AVATAR_EDGE_REASON, }, dark: { 'rgb-surface-overlay': 'Click UI dark dialog.color.opaqueBackground is a gray that leaves the dialog under 3:1', 'rgb-surface-media-overlay': MEDIA_OVERLAY_REASON, + 'rgb-avatar-edge': AVATAR_EDGE_REASON, }, }; @@ -327,6 +337,11 @@ interface Departure { */ const departures: Record>> = { light: { + 'rgb-avatar-edge': { + counterpart: 'global.color.stroke.default', + status: 'near', + reason: AVATAR_EDGE_REASON, + }, 'rgb-surface-media-overlay': { counterpart: 'click.dialog.color.opaqueBackground.default', status: 'near', @@ -429,6 +444,11 @@ const departures: Record>> status: 'mismatch', reason: MEDIA_SCRIM_DEPARTURE, }, + 'rgb-avatar-edge': { + counterpart: 'global.color.stroke.default', + status: 'mismatch', + reason: AVATAR_EDGE_REASON, + }, }, }; @@ -540,6 +560,7 @@ const appearanceSources: Partial> = { shadow2xl: 'shadow.1', elevationSurface: 'shadow.1', menuShadow: 'click.genericMenu.panel.shadow.default', + elevationDrag: 'shadow.1', controlHeight: 'click.genericMenu.panel.size.height', controlPaddingX: 'click.button.basic.space.x', controlGap: 'click.button.basic.space.gap', @@ -737,7 +758,7 @@ function comparable(key: keyof IThemeAppearance, raw: string | number): string { if (scrimKeys.has(key)) { return /^[\d.]+$/.test(value) ? String(Number(value)) : String(parseColor(value)[3]); } - if (/shadow/i.test(key) || key === 'elevationSurface') { + if (/shadow/i.test(key) || key === 'elevationSurface' || key === 'elevationDrag') { return normalizeShadow(value); } /** Click UI's mono tail names `"SFMono Regular"`, which no platform installs; the theme keeps diff --git a/packages/client/src/theme/themes/dark.ts b/packages/client/src/theme/themes/dark.ts index 4514d41ced..b0a1be1dd6 100644 --- a/packages/client/src/theme/themes/dark.ts +++ b/packages/client/src/theme/themes/dark.ts @@ -128,6 +128,10 @@ export const darkTheme: IThemeRGB = { 'rgb-avatar-fill': '121 137 255', // #7989ff (the default avatar fill in every bundled theme) 'rgb-avatar-text': '236 236 236', // #ececec (gray-100, matching text-primary) 'rgb-avatar-placeholder': '47 47 47', // #2f2f2f (gray-700, matching surface-tertiary) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc at 10%, a hairline that only shows against a dark page + 'rgb-illustration-subtle': '175 193 255', // #afc1ff + 'rgb-illustration': '121 137 255', // #7989ff + 'rgb-illustration-strong': '60 70 255', // #3c46ff /** Code syntax highlighting, measured against the `surface-code` fill. The * comment and meta values are the flattened equivalents of the alpha-blended diff --git a/packages/client/src/theme/themes/default.ts b/packages/client/src/theme/themes/default.ts index aab5e683d2..ed4d60f3d0 100644 --- a/packages/client/src/theme/themes/default.ts +++ b/packages/client/src/theme/themes/default.ts @@ -118,6 +118,10 @@ export const defaultTheme: IThemeRGB = { 'rgb-avatar-fill': '121 137 255', // #7989ff (the default avatar fill in every bundled theme) 'rgb-avatar-text': '33 33 33', // #212121 (gray-800, matching text-primary) 'rgb-avatar-placeholder': '247 247 248', // #f7f7f8 (gray-50, matching surface-secondary) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc at 10%, a hairline that only shows against a dark page + 'rgb-illustration-subtle': '175 193 255', // #afc1ff + 'rgb-illustration': '121 137 255', // #7989ff + 'rgb-illustration-strong': '60 70 255', // #3c46ff /** Code syntax highlighting, measured against the `surface-code` and `surface-code-body` fills. */ 'rgb-syntax-text': '33 33 33', // #212121 (gray-800) diff --git a/packages/client/src/theme/themes/highContrast.ts b/packages/client/src/theme/themes/highContrast.ts index 0fec39e8e4..7ee379aa5c 100644 --- a/packages/client/src/theme/themes/highContrast.ts +++ b/packages/client/src/theme/themes/highContrast.ts @@ -153,6 +153,10 @@ export const highContrastLightTheme: IThemeRGB = { 'rgb-avatar-fill': '121 137 255', // #7989ff (the default avatar fill in every bundled theme) 'rgb-avatar-text': '0 0 0', // #000000 (matching text-primary) 'rgb-avatar-placeholder': '255 255 255', // #ffffff (matching surface-secondary) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc + 'rgb-illustration-subtle': '175 193 255', // #afc1ff + 'rgb-illustration': '121 137 255', // #7989ff + 'rgb-illustration-strong': '60 70 255', // #3c46ff /** Code syntax highlighting at AAA on the white code surface. */ 'rgb-syntax-text': '0 0 0', // #000000 @@ -317,6 +321,10 @@ export const highContrastDarkTheme: IThemeRGB = { 'rgb-avatar-fill': '121 137 255', // #7989ff (the default avatar fill in every bundled theme) 'rgb-avatar-text': '255 255 255', // #ffffff (matching text-primary) 'rgb-avatar-placeholder': '0 0 0', // #000000 (matching surface-tertiary) + 'rgb-avatar-edge': '240 246 252', // #f0f6fc + 'rgb-illustration-subtle': '175 193 255', // #afc1ff + 'rgb-illustration': '121 137 255', // #7989ff + 'rgb-illustration-strong': '60 70 255', // #3c46ff /** Code syntax highlighting at AAA on the black code surface. */ 'rgb-syntax-text': '255 255 255', // #ffffff diff --git a/packages/client/src/theme/tokens.css b/packages/client/src/theme/tokens.css index 89c6e19b82..927b5af8b5 100644 --- a/packages/client/src/theme/tokens.css +++ b/packages/client/src/theme/tokens.css @@ -25,6 +25,10 @@ --color-avatar-fill: rgb(var(--avatar-fill)); --color-avatar-text: rgb(var(--avatar-text)); --color-avatar-placeholder: rgb(var(--avatar-placeholder)); + --color-avatar-edge: rgb(var(--avatar-edge)); + --color-illustration-subtle: rgb(var(--illustration-subtle)); + --color-illustration: rgb(var(--illustration)); + --color-illustration-strong: rgb(var(--illustration-strong)); --color-presentation: rgb(var(--presentation)); --color-accent-primary: rgb(var(--accent-primary)); --color-accent-primary-hover: rgb(var(--accent-primary-hover)); diff --git a/packages/client/src/theme/types/index.ts b/packages/client/src/theme/types/index.ts index c1956440ec..e85074e826 100644 --- a/packages/client/src/theme/types/index.ts +++ b/packages/client/src/theme/types/index.ts @@ -150,6 +150,12 @@ export interface IThemeRGB { 'rgb-avatar-text'?: string; /** Behind an agent or assistant avatar while its image loads or where it is transparent. */ 'rgb-avatar-placeholder'?: string; + /** The hairline around the default avatar, drawn at 10% so it only shows against a dark page. */ + 'rgb-avatar-edge'?: string; + /** The three tones of in-app artwork, such as the file drop zone's illustration. */ + 'rgb-illustration-subtle'?: string; + 'rgb-illustration'?: string; + 'rgb-illustration-strong'?: string; /** * Code syntax highlighting. Declared here rather than left as literals in the @@ -300,6 +306,10 @@ export interface IThemeVariables { '--avatar-fill': string; '--avatar-text': string; '--avatar-placeholder': string; + '--avatar-edge': string; + '--illustration-subtle': string; + '--illustration': string; + '--illustration-strong': string; '--syntax-text': string; '--syntax-comment': string; @@ -424,6 +434,10 @@ export interface IThemeColors { 'avatar-fill'?: string; 'avatar-text'?: string; 'avatar-placeholder'?: string; + 'avatar-edge'?: string; + 'illustration-subtle'?: string; + illustration?: string; + 'illustration-strong'?: string; 'series-1'?: string; 'series-2'?: string; @@ -538,6 +552,8 @@ export interface IThemeAppearance { alertScrimOpacity: string; modalScrimOpacity: string; elevationSurface: string; + /** The lift a dragged badge takes while it is held. */ + elevationDrag: string; shadow2xs: string; shadowXs: string; shadowSm: string; diff --git a/packages/client/src/theme/utils/color.spec.ts b/packages/client/src/theme/utils/color.spec.ts new file mode 100644 index 0000000000..cc6cc49ba1 --- /dev/null +++ b/packages/client/src/theme/utils/color.spec.ts @@ -0,0 +1,38 @@ +import { readThemeColor } from './color'; + +describe('readThemeColor', () => { + const root = document.documentElement; + + afterEach(() => { + root.removeAttribute('style'); + }); + + it('wraps a channel triplet in rgb()', () => { + root.style.setProperty('--probe', '13 13 13'); + expect(readThemeColor('--probe')).toBe('rgb(13 13 13)'); + }); + + it('keeps an alpha written after the triplet', () => { + root.style.setProperty('--probe', '0 0 0 / 0.4'); + expect(readThemeColor('--probe')).toBe('rgb(0 0 0 / 0.4)'); + }); + + it('returns a value that is already a color as set', () => { + root.style.setProperty('--probe', '#fafafa'); + expect(readThemeColor('--probe')).toBe('#fafafa'); + }); + + it('returns null for an unset or unresolved property', () => { + expect(readThemeColor('--probe')).toBeNull(); + root.style.setProperty('--probe', 'var(--missing)'); + expect(readThemeColor('--probe')).toBeNull(); + }); + + it('reads the element it is given', () => { + const scoped = document.createElement('div'); + scoped.style.setProperty('--probe', '1 2 3'); + document.body.append(scoped); + expect(readThemeColor('--probe', scoped)).toBe('rgb(1 2 3)'); + scoped.remove(); + }); +}); diff --git a/packages/client/src/theme/utils/color.ts b/packages/client/src/theme/utils/color.ts new file mode 100644 index 0000000000..6f0a6fedf2 --- /dev/null +++ b/packages/client/src/theme/utils/color.ts @@ -0,0 +1,20 @@ +/** A theme role's stored value: a bare `R G B` channel triplet, optionally with `/ alpha`. */ +const TRIPLET = /^[\d.]+(?:\s+[\d.]+){2}(?:\s*\/\s*[\d.]+%?)?$/; + +/** + * Reads a theme color property as a CSS color, for code that paints outside the stylesheet (a + * canvas, a favicon, a screenshot backdrop). Roles hold channel triplets, which only `rgb()` + * turns into a color, so a triplet is wrapped; any other value is returned as set. Returns null + * when the property is unset or still an unresolved `var()`, so a caller never paints a color the + * active theme did not choose. + */ +export function readThemeColor( + property: string, + element: Element = document.documentElement, +): string | null { + const value = getComputedStyle(element).getPropertyValue(property).trim(); + if (!value || value.startsWith('var(')) { + return null; + } + return TRIPLET.test(value) ? `rgb(${value})` : value; +} diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.ts index f23d8920c5..9bafc741f5 100644 --- a/packages/data-provider/src/theme.ts +++ b/packages/data-provider/src/theme.ts @@ -109,6 +109,10 @@ export const themeColorTokens = Object.freeze([ 'rgb-avatar-fill', 'rgb-avatar-text', 'rgb-avatar-placeholder', + 'rgb-avatar-edge', + 'rgb-illustration-subtle', + 'rgb-illustration', + 'rgb-illustration-strong', 'rgb-syntax-text', 'rgb-syntax-comment', 'rgb-syntax-meta', @@ -394,6 +398,8 @@ const appearanceValidators = { /** Released themes may hold `var()` here, so this role keeps its original, looser check. */ elevationSurface: (value: unknown) => typeof value === 'string' && value.trim().length > 0 && !/[;{}]|url\s*\(/i.test(value), + /** The lift a dragged badge takes while it is held. */ + elevationDrag: isShadow, shadow2xs: isShadow, shadowXs: isShadow, shadowSm: isShadow,