🖍️ feat: Give the Remaining Component Colour Literals Theme Roles (#16597)

* feat: Give the Last Component Colour Literals Theme Roles

The default avatar's hairline, the file drop zone's artwork and a dragged badge's lift were literals in Avatar, Icon, MessageIcon, DragDropOverlay and Badge, so no theme could reach them. avatar-edge, the illustration roles and the elevationDrag appearance role now carry them, each defaulting to the literal it replaces in every bundled theme. ClickHouse paints the artwork from Click UI's info ramp.

Canvas, favicon and screenshot code read roles through readThemeColor instead of wrapping channel triplets by hand. The Reasoning fade mask, two comments and dead commented-out SVG fills no longer carry colour literals, and the allowlist is regrouped into nine justified entries.

* test: Pin the Avatar Hairline, Drop Zone Artwork and Drag Lift Roles

* refactor: Export readThemeColor Beside the Theme Atoms

* test: Compare the Avatar Hairline by the Pixel It Paints

* test: Compare the Drag Lift as the Browser Computes It

* test: Attach Drop Zone Artwork Captures to the Report

* test: Pick the Drag Lift Theme From One Init Script
This commit is contained in:
Marco Beretta 2026-10-01 13:02:46 +02:00 • committed by GitHub
parent 0da898786c
commit 59a8a31ab2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 401 additions and 119 deletions

View file

@ -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. */

View file

@ -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"
/>
</g>
<g clipPath="url(#clip1_3605_64419)">
@ -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"
/>
</g>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M40.4004 71.8426C40.4004 57.2141 44.0575 53.5569 61.1242 53.5569H66.0004H70.8766C87.9432 53.5569 91.6004 57.2141 91.6004 71.8426V79.1569C91.6004 93.7855 87.9432 97.4426 70.8766 97.4426H61.1242C44.0575 97.4426 40.4004 93.7855 40.4004 79.1569V71.8426ZM78.8002 67.4995C78.8002 70.1504 76.6512 72.2995 74.0002 72.2995C71.3492 72.2995 69.2002 70.1504 69.2002 67.4995C69.2002 64.8485 71.3492 62.6995 74.0002 62.6995C76.6512 62.6995 78.8002 64.8485 78.8002 67.4995ZM60.7204 70.8597C60.2672 70.2553 59.5559 69.8997 58.8004 69.8997C58.045 69.8997 57.3337 70.2553 56.8804 70.8597L47.2804 83.6597C46.4851 84.72 46.7 86.2244 47.7604 87.0197C48.8208 87.8149 50.3251 87.6 51.1204 86.5397L58.8004 76.2997L66.4804 86.5397C66.8979 87.0962 67.5363 87.4443 68.2303 87.4936C68.9243 87.5429 69.6055 87.2887 70.0975 86.7967L74.8004 82.0938L79.5034 86.7967C80.4406 87.734 81.9602 87.734 82.8975 86.7967C83.8347 85.8595 83.8347 84.3399 82.8975 83.4026L76.4975 77.0026C75.5602 76.0653 74.0406 76.0653 73.1034 77.0026L68.6601 81.4459L60.7204 70.8597Z"
fill="#3C46FF"
className="fill-illustration-strong"
/>
<defs>
<clipPath id="clip0_3605_64419">
<rect
width="56"
height="56"
fill="white"
transform="translate(0 26.9939) rotate(-15)"
/>
<rect width="56" height="56" transform="translate(0 26.9939) rotate(-15)" />
</clipPath>
<clipPath id="clip1_3605_64419">
<rect
width="64"
height="64"
fill="white"
transform="translate(69.5645 0.5) rotate(15)"
/>
<rect width="64" height="64" transform="translate(69.5645 0.5) rotate(15)" />
</clipPath>
</defs>
</svg>

View file

@ -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

View file

@ -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"
>
<UserIcon />
</div>

View file

@ -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 className="size-4 text-text-secondary" />,
icon: <Icon className="text-text-secondary size-4" />,
...(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: <Workflow className="size-4 text-text-secondary" />,
icon: <Workflow className="text-text-secondary size-4" />,
...(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={
<TooltipAnchor
portalElement={portalElement}
@ -249,8 +240,8 @@ const MermaidExport = memo(function MermaidExport({
aria-label={localize('com_ui_export_mermaid')}
aria-busy={isBusy || undefined}
className={cn(
'flex items-center justify-center rounded-lg p-1.5 text-text-secondary transition-colors motion-reduce:transition-none',
'hover:bg-surface-hover hover:text-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-border-heavy',
'text-text-secondary flex items-center justify-center rounded-lg p-1.5 transition-colors motion-reduce:transition-none',
'hover:bg-surface-hover hover:text-text-primary focus-visible:outline-border-heavy focus-visible:outline focus-visible:outline-2',
buttonClassName,
)}
>

View file

@ -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"
>
<UserIcon />
</div>

View file

@ -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,

View file

@ -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,

View file

@ -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<number[]> =>
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<string[]> {
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);
}
});
});

View file

@ -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": {

View file

@ -53,9 +53,8 @@ const Avatar: React.FC<AvatarProps> = ({
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"
>
<UserIcon />

View file

@ -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' }}

View file

@ -24,7 +24,6 @@ export default function AnthropicIcon({
>
<path
shapeRendering="geometricPrecision"
// fill="rgb(24,24,24)"
fillOpacity="1"
d=" M0,0 C0,0 6.1677093505859375,15.470022201538086 6.1677093505859375,15.470022201538086 C6.1677093505859375,15.470022201538086 9.550004005432129,15.470022201538086 9.550004005432129,15.470022201538086 C9.550004005432129,15.470022201538086 3.382294178009033,0 3.382294178009033,0 C3.382294178009033,0 0,0 0,0 C0,0 0,0 0,0z"
></path>
@ -38,7 +37,6 @@ export default function AnthropicIcon({
>
<path
shapeRendering="geometricPrecision"
// fill="rgb(24,24,24)"
fillOpacity="1"
d=" M5.824605464935303,9.348296165466309 C5.824605464935303,9.348296165466309 7.93500280380249,3.911694288253784 7.93500280380249,3.911694288253784 C7.93500280380249,3.911694288253784 10.045400619506836,9.348296165466309 10.045400619506836,9.348296165466309 C10.045400619506836,9.348296165466309 5.824605464935303,9.348296165466309 5.824605464935303,9.348296165466309 C5.824605464935303,9.348296165466309 5.824605464935303,9.348296165466309 5.824605464935303,9.348296165466309z M6.166755199432373,0 C6.166755199432373,0 0,15.470022201538086 0,15.470022201538086 C0,15.470022201538086 3.4480772018432617,15.470022201538086 3.4480772018432617,15.470022201538086 C3.4480772018432617,15.470022201538086 4.709278583526611,12.22130012512207 4.709278583526611,12.22130012512207 C4.709278583526611,12.22130012512207 11.16093635559082,12.22130012512207 11.16093635559082,12.22130012512207 C11.16093635559082,12.22130012512207 12.421928405761719,15.470022201538086 12.421928405761719,15.470022201538086 C12.421928405761719,15.470022201538086 15.87000560760498,15.470022201538086 15.87000560760498,15.470022201538086 C15.87000560760498,15.470022201538086 9.703250885009766,0 9.703250885009766,0 C9.703250885009766,0 6.166755199432373,0 6.166755199432373,0 C6.166755199432373,0 6.166755199432373,0 6.166755199432373,0z"
></path>

View file

@ -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

View file

@ -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. |

View file

@ -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;

View file

@ -68,7 +68,7 @@ describe.each([
const tokens = Object.keys(theme) as Array<keyof IThemeRGB>;
it('covers every registry color', () => {
expect(tokens).toHaveLength(116);
expect(tokens).toHaveLength(120);
});
it('resolves every registry color to the runtime theme value', () => {

View file

@ -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';

View file

@ -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<IThemeAppearance>): Partial<ITheme
const shadowAppearanceKeys: ReadonlyArray<keyof IThemeAppearance> = [
'elevationSurface',
'elevationDrag',
'shadow2xs',
'shadowXs',
'shadowSm',

View file

@ -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<IThemeAppearance> => ({
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<IThemeAppearance> = {

View file

@ -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",

View file

@ -149,6 +149,9 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
'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<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
'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<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
/** 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<ThemeMode, Partial<Record<keyof IThemeRGB, string>>> = {
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<ThemeMode, Partial<Record<keyof IThemeRGB, Departure>>> = {
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<ThemeMode, Partial<Record<keyof IThemeRGB, Departure>>>
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<Record<keyof IThemeAppearance, string>> = {
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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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));

View file

@ -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;

View file

@ -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();
});
});

View file

@ -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;
}

View file

@ -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,