.getByText(title, { exact: true })
.evaluate((node) => getComputedStyle(node).color);
+const MISSING_AVATAR = 'https://avatar.e2e.invalid/missing.png';
+
+/** The e2e user has an avatar seed, so the default avatar only draws once its image fails:
+ * the user payload points at an address the page refuses 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 } });
+ });
+}
+
+/** The default avatar on the sidebar account button, the one a signed-in user always sees. */
+const navAvatarPaint = async (page: Page) => {
+ const avatar = page.getByTestId('nav-user').locator('div[aria-hidden="true"]').first();
+ await expect(avatar).toBeVisible({ timeout: 20000 });
+ return avatar.evaluate((node) => {
+ const style = getComputedStyle(node);
+ return { fill: style.backgroundColor, ink: style.color };
+ });
+};
+
test.describe('clickhouse reference theme', () => {
test('the ClickHouse definition repaints the chat and the settings dialog in both modes @scenario:clickhouse-definition-repaints-chat-sidebar-and-dialog', async ({
page,
@@ -234,4 +257,109 @@ test.describe('clickhouse reference theme', () => {
await deleteConversations([conversationId]);
}
});
+
+ test('the default avatar keeps its fill and the placeholder its surface without a theme @scenario:default-avatar-keeps-its-fill', async ({
+ page,
+ }) => {
+ test.setTimeout(90000);
+ const conversationId = await seedChat('Default avatar');
+ await installThemeBridge(page, null);
+ await failUserAvatar(page);
+
+ try {
+ for (const [mode, placeholder, ink] of [
+ ['light', defaultTheme['rgb-surface-secondary'], 'rgb(33, 33, 33)'],
+ ['dark', darkTheme['rgb-surface-tertiary'], 'rgb(236, 236, 236)'],
+ ] as const) {
+ await page.goto(`/c/${conversationId}?${THEME_PARAM}=${mode}`);
+ await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({
+ timeout: 20000,
+ });
+
+ expect(await navAvatarPaint(page)).toEqual({ fill: 'rgb(121, 137, 255)', ink });
+ expect(await themeValue(page, '--avatar-placeholder')).toBe(placeholder);
+ }
+ } finally {
+ await deleteConversations([conversationId]);
+ }
+ });
+
+ test('the ClickHouse definition paints the default avatar from Click UI @scenario:clickhouse-avatar-follows-click-ui', async ({
+ page,
+ }) => {
+ test.setTimeout(90000);
+ const conversationId = await seedChat('ClickHouse avatar');
+ await installThemeBridge(page, clickHouseTheme);
+ await failUserAvatar(page);
+
+ try {
+ for (const mode of MODES) {
+ const colors = colorsFor(mode);
+ await page.goto(`/c/${conversationId}?${THEME_PARAM}=${mode}`);
+ await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({
+ timeout: 20000,
+ });
+ await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse');
+
+ expect(await navAvatarPaint(page)).toEqual({
+ fill: rgbCss(colors['rgb-avatar-fill']),
+ ink: rgbCss(colors['rgb-avatar-text']),
+ });
+ expect(await themeValue(page, '--avatar-placeholder')).toBe(
+ colors['rgb-avatar-placeholder'],
+ );
+ }
+ } finally {
+ await deleteConversations([conversationId]);
+ }
+ });
+
+ test('a legacy backdrop follows a dark toggle on the document root and on a scoped root @scenario:legacy-avatar-backdrop-follows-mode', async ({
+ page,
+ }) => {
+ test.setTimeout(90000);
+ const conversationId = await seedChat('Legacy avatar backdrop');
+ await installThemeBridge(page, null);
+
+ try {
+ await page.goto(`/c/${conversationId}?${THEME_PARAM}=light`);
+ await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({
+ timeout: 20000,
+ });
+
+ /** What a legacy palette leaves behind: surfaces set inline, applied once in light, and a
+ * scoped root marked the way `applyTheme` marks one. The mode then flips with no reapply. */
+ const painted = await page.evaluate(() => {
+ const html = document.documentElement;
+ const read = (node: Element) => getComputedStyle(node).backgroundColor;
+ const backdrop = (host: Element) => {
+ const node = document.createElement('div');
+ node.className = 'bg-avatar-placeholder';
+ host.append(node);
+ return node;
+ };
+ html.classList.remove('dark');
+ html.style.setProperty('--surface-secondary', '20 21 22');
+ html.style.setProperty('--surface-tertiary', '30 31 32');
+ const scope = document.createElement('section');
+ scope.setAttribute('data-theme-scope', '');
+ scope.style.setProperty('--surface-secondary', '40 41 42');
+ scope.style.setProperty('--surface-tertiary', '50 51 52');
+ document.body.append(scope);
+ const onRoot = backdrop(document.body);
+ const onScope = backdrop(scope);
+ const light = { root: read(onRoot), scoped: read(onScope) };
+ html.classList.add('dark');
+ const dark = { root: read(onRoot), scoped: read(onScope) };
+ return { light, dark };
+ });
+
+ expect(painted).toEqual({
+ light: { root: 'rgb(20, 21, 22)', scoped: 'rgb(40, 41, 42)' },
+ dark: { root: 'rgb(30, 31, 32)', scoped: 'rgb(50, 51, 52)' },
+ });
+ } finally {
+ await deleteConversations([conversationId]);
+ }
+ });
});
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index 68f6bc8def..c06908c1ea 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -1004,7 +1004,7 @@
},
"client/src/components/Endpoints/Icon.tsx": {
"shadcn/no-inline-styles": {
- "count": 2
+ "count": 1
}
},
"client/src/components/Endpoints/MessageEndpointIcon.tsx": {
@@ -1490,7 +1490,7 @@
},
"client/src/components/Share/MessageIcon.tsx": {
"shadcn/no-inline-styles": {
- "count": 2
+ "count": 1
}
},
"client/src/components/Share/MessagesView.tsx": {
@@ -2203,7 +2203,7 @@
},
"packages/client/src/components/Avatar.tsx": {
"shadcn/no-inline-styles": {
- "count": 3
+ "count": 2
}
},
"packages/client/src/components/Badge.tsx": {
diff --git a/packages/client/src/components/Avatar.tsx b/packages/client/src/components/Avatar.tsx
index 1f70032d40..b1ae4805aa 100644
--- a/packages/client/src/components/Avatar.tsx
+++ b/packages/client/src/components/Avatar.tsx
@@ -51,12 +51,11 @@ const Avatar: React.FC
= ({
() => (
diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md
index 1d9dd333e0..2d0ba42137 100644
--- a/packages/client/src/theme/README.md
+++ b/packages/client/src/theme/README.md
@@ -316,6 +316,13 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
### Other Colors
- `bg-brand-purple` - Brand purple color
+- `bg-avatar-fill` / `text-avatar-text` - The default user avatar drawn when a
+ user has no image, and its glyph. A theme that sets `rgb-text-primary` but not
+ `rgb-avatar-text` inks the glyph in its primary text, as it did before the role.
+- `bg-avatar-placeholder` - Behind an agent or assistant avatar while its image
+ loads or where it is transparent. A theme that sets only its surfaces keeps it
+ on `surface-secondary` in light and `surface-tertiary` in dark, where it sat
+ before the role existed.
- `bg-presentation` - Presentation background
- `ring-ring-primary` - Decorative ring color (selection and hover rings)
- `focus-outline` - The app-wide keyboard focus outline. Defaults to black in
diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.css
index c501b4b562..e745b171e3 100644
--- a/packages/client/src/theme/defaults.css
+++ b/packages/client/src/theme/defaults.css
@@ -76,6 +76,9 @@
html {
--brand-purple: 126 34 206;
+ --avatar-fill: 121 137 255;
+ --avatar-text: var(--text-primary);
+ --avatar-placeholder: var(--surface-secondary);
--presentation: var(--white);
--text-primary: var(--gray-800);
--text-secondary: var(--gray-600);
@@ -262,6 +265,9 @@ html {
}
.dark {
--brand-purple: 171 104 255;
+ --avatar-fill: 121 137 255;
+ --avatar-text: var(--text-primary);
+ --avatar-placeholder: var(--surface-tertiary);
--presentation: var(--gray-800);
--text-primary: var(--gray-100);
--focus-outline: 255 255 255;
@@ -383,3 +389,14 @@ html {
--provider-bedrock: #268672;
--provider-foreground: #ffffff;
}
+
+/* A root other than the document one that a legacy palette themes (`THEME_SCOPE_ATTRIBUTE` in
+ utils/applyTheme.ts) keeps its avatar backdrop on its own surfaces, following the mode, as the
+ document root's alias above does. An explicit avatar-placeholder set inline still wins. */
+[data-theme-scope] {
+ --avatar-placeholder: var(--surface-secondary);
+}
+.dark [data-theme-scope],
+[data-theme-scope].dark {
+ --avatar-placeholder: var(--surface-tertiary);
+}
diff --git a/packages/client/src/theme/defaults.spec.ts b/packages/client/src/theme/defaults.spec.ts
index 12324e96ff..f6f03a5076 100644
--- a/packages/client/src/theme/defaults.spec.ts
+++ b/packages/client/src/theme/defaults.spec.ts
@@ -63,7 +63,7 @@ describe.each([
const tokens = Object.keys(theme) as Array;
it('covers every registry color', () => {
- expect(tokens).toHaveLength(108);
+ expect(tokens).toHaveLength(111);
});
it('resolves every registry color to the runtime theme value', () => {
diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.ts
index a279043c4c..9da2d10b39 100644
--- a/packages/client/src/theme/registry.spec.ts
+++ b/packages/client/src/theme/registry.spec.ts
@@ -369,6 +369,64 @@ describe('theme registry', () => {
});
});
+ it('keeps the avatar backdrop on the surface each mode drew it on before the role existed', () => {
+ const colors = { 'rgb-surface-secondary': '20 21 22', 'rgb-surface-tertiary': '30 31 32' };
+ const theme = {
+ version: 1 as const,
+ name: 'legacy-avatar-placeholder',
+ modes: { light: { colors }, dark: { colors } },
+ };
+
+ expect(resolveTheme(theme, 'light').colors['rgb-avatar-placeholder']).toBe('20 21 22');
+ expect(resolveTheme(theme, 'dark').colors['rgb-avatar-placeholder']).toBe('30 31 32');
+ });
+
+ it('inks the default avatar in the primary text a theme sets, unless it sets the role', () => {
+ const inherited = resolveTheme(
+ {
+ version: 1,
+ name: 'legacy-avatar-text',
+ modes: { light: { colors: { 'rgb-text-primary': '10 11 12' } } },
+ },
+ 'light',
+ );
+ const explicit = resolveTheme(
+ {
+ version: 1,
+ name: 'explicit-avatar-text',
+ modes: {
+ light: { colors: { 'rgb-text-primary': '10 11 12', 'rgb-avatar-text': '1 2 3' } },
+ },
+ },
+ 'light',
+ );
+
+ expect(inherited.colors['rgb-avatar-text']).toBe('10 11 12');
+ expect(explicit.colors['rgb-avatar-text']).toBe('1 2 3');
+ });
+
+ it('preserves an explicit avatar backdrop and falls back to the bundled one otherwise', () => {
+ const explicit = resolveTheme(
+ {
+ version: 1,
+ name: 'explicit-avatar-placeholder',
+ modes: {
+ dark: {
+ colors: { 'rgb-surface-tertiary': '30 31 32', 'rgb-avatar-placeholder': '1 2 3' },
+ },
+ },
+ },
+ 'dark',
+ );
+ const untouched = resolveTheme(
+ { version: 1, name: 'no-surface', modes: { dark: { colors: {} } } },
+ 'dark',
+ );
+
+ expect(explicit.colors['rgb-avatar-placeholder']).toBe('1 2 3');
+ expect(untouched.colors['rgb-avatar-placeholder']).toBe(darkTheme['rgb-avatar-placeholder']);
+ });
+
it('keeps the switch thumb on the surface a theme repainted before the role existed', () => {
const resolved = resolveTheme(
{
diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts
index b36d2a997b..ed9507d730 100644
--- a/packages/client/src/theme/registry.ts
+++ b/packages/client/src/theme/registry.ts
@@ -465,6 +465,24 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
customColors?.['rgb-link-prose'] === undefined && proseLinkSource !== undefined
? { 'rgb-link-prose': proseLinkSource }
: {};
+ /**
+ * Agent and assistant avatars sat on `surface-secondary` in light and `surface-tertiary` in dark
+ * before they had a role, so a theme that repaints the one its mode used keeps that backdrop.
+ */
+ const avatarPlaceholderSource =
+ mode === 'dark'
+ ? customColors?.['rgb-surface-tertiary']
+ : customColors?.['rgb-surface-secondary'];
+ const avatarPlaceholderFallback =
+ customColors?.['rgb-avatar-placeholder'] === undefined && avatarPlaceholderSource !== undefined
+ ? { 'rgb-avatar-placeholder': avatarPlaceholderSource }
+ : {};
+ /** The default avatar's glyph inked in `text-primary` before it had a role. */
+ const avatarTextFallback =
+ customColors?.['rgb-avatar-text'] === undefined &&
+ customColors?.['rgb-text-primary'] !== undefined
+ ? { 'rgb-avatar-text': customColors['rgb-text-primary'] }
+ : {};
const chartWidgetSurfaceFallback =
customColors?.['rgb-chart-widget-surface'] === undefined &&
customColors?.['rgb-surface-primary'] !== undefined
@@ -561,6 +579,8 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
...shimmerBaseFallback,
...textMutedFallback,
...proseLinkFallback,
+ ...avatarPlaceholderFallback,
+ ...avatarTextFallback,
...chartWidgetSurfaceFallback,
...chartWidgetStrokeFallback,
...switchThumbFallback,
diff --git a/packages/client/src/theme/semanticTokens.spec.ts b/packages/client/src/theme/semanticTokens.spec.ts
index 574cc84468..db2eea9337 100644
--- a/packages/client/src/theme/semanticTokens.spec.ts
+++ b/packages/client/src/theme/semanticTokens.spec.ts
@@ -531,6 +531,31 @@ describe('verified fill defaults', () => {
});
});
+/**
+ * The default avatar's glyph is a graphical object under WCAG 1.4.11, so it needs 3:1 on its fill.
+ * The bundled dark theme keeps the 2.6:1 its avatar painted before the role existed: the glyph is
+ * decorative (aria-hidden beside the account name), and raising it is tracked on its own.
+ */
+it('keeps the bundled dark avatar glyph no fainter than it painted before its role', () => {
+ expect(
+ contrast(toRgb(darkTheme, 'rgb-avatar-text'), toRgb(darkTheme, 'rgb-avatar-fill')),
+ ).toBeGreaterThanOrEqual(2.6);
+});
+
+describe.each([
+ ['default', defaultTheme],
+ ['high contrast light', highContrastLightTheme],
+ ['high contrast dark', highContrastDarkTheme],
+ ['clickhouse light', clickHouseLightTheme],
+ ['clickhouse dark', clickHouseDarkTheme],
+])('%s default avatar', (_name, theme: IThemeRGB) => {
+ it('keeps the glyph at the 3:1 mark floor against its fill', () => {
+ expect(
+ contrast(toRgb(theme, 'rgb-avatar-text'), toRgb(theme, 'rgb-avatar-fill')),
+ ).toBeGreaterThanOrEqual(WCAG_MARK_MIN);
+ });
+});
+
/** The shared `Switch` paints this track, so it travels with the package rather
* than the app stylesheet. It is a UI component boundary under WCAG 1.4.11 and
* has to stay distinct from the `switch-thumb` knob on it and from the
diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts
index d5cb836345..cbdb71ad1a 100644
--- a/packages/client/src/theme/themes/clickhouse.ts
+++ b/packages/client/src/theme/themes/clickhouse.ts
@@ -133,6 +133,9 @@ export const clickHouseLightTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '136 0 204', // #8800cc (palette.violet.600)
+ '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)
// Code syntax
'rgb-syntax-text': '40 40 40', // #282828 (codeblock.lightMode.color.text.default)
@@ -272,6 +275,9 @@ export const clickHouseDarkTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '204 102 255', // #cc66ff (palette.violet.300)
+ '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)
// Code syntax
'rgb-syntax-text': '255 255 255', // #ffffff (codeblock.darkMode.color.text.default)
diff --git a/packages/client/src/theme/themes/clickui.json b/packages/client/src/theme/themes/clickui.json
index 1d6e528344..6e4e3935a7 100644
--- a/packages/client/src/theme/themes/clickui.json
+++ b/packages/client/src/theme/themes/clickui.json
@@ -11,6 +11,8 @@
"border.radii.2": "0.5rem",
"border.radii.3": "0.75rem",
"border.radii.full": "9999px",
+ "click.avatar.color.background.default": "#696e79",
+ "click.avatar.color.text.default": "#ffffff",
"click.badge.opaque.color.background.default": "#f6f7fa",
"click.badge.opaque.color.stroke.default": "#e6e7e9",
"click.badge.opaque.color.text.default": "#696e79",
@@ -128,6 +130,8 @@
"border.radii.2": "0.5rem",
"border.radii.3": "0.75rem",
"border.radii.full": "9999px",
+ "click.avatar.color.background.default": "#808691",
+ "click.avatar.color.text.default": "#1f1f1c",
"click.badge.opaque.color.background.default": "#1f1f1c",
"click.badge.opaque.color.stroke.default": "#323232",
"click.badge.opaque.color.text.default": "#b3b6bd",
diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.ts
index 0d63ab6afe..937f533aeb 100644
--- a/packages/client/src/theme/themes/clickui.spec.ts
+++ b/packages/client/src/theme/themes/clickui.spec.ts
@@ -141,6 +141,9 @@ const colorSources: Record>>
'rgb-status-verified': 'palette.info.600',
'rgb-text-on-status': 'palette.neutral.0',
'rgb-brand-purple': 'palette.violet.600',
+ 'rgb-avatar-fill': 'click.avatar.color.background.default',
+ 'rgb-avatar-text': 'click.avatar.color.text.default',
+ 'rgb-avatar-placeholder': 'global.color.background.muted',
'rgb-syntax-text': 'click.codeblock.lightMode.color.text.default',
'rgb-syntax-comment': 'global.color.text.muted',
'rgb-syntax-meta': 'palette.slate.700',
@@ -250,6 +253,9 @@ const colorSources: Record>>
'rgb-status-verified': 'palette.info.300',
'rgb-text-on-status': 'global.color.iconButton.badge.foreground',
'rgb-brand-purple': 'palette.violet.300',
+ 'rgb-avatar-fill': 'click.avatar.color.background.default',
+ 'rgb-avatar-text': 'click.avatar.color.text.default',
+ 'rgb-avatar-placeholder': 'global.color.background.muted',
'rgb-syntax-text': 'click.codeblock.darkMode.color.text.default',
'rgb-syntax-comment': 'global.color.text.muted',
'rgb-syntax-meta': 'palette.slate.400',
diff --git a/packages/client/src/theme/themes/dark.ts b/packages/client/src/theme/themes/dark.ts
index 5ff2d2d006..332bcac3a2 100644
--- a/packages/client/src/theme/themes/dark.ts
+++ b/packages/client/src/theme/themes/dark.ts
@@ -120,6 +120,9 @@ export const darkTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '171 104 255', // #ab68ff
+ '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)
/** 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 f562fdbeb1..c0b6b9fa7a 100644
--- a/packages/client/src/theme/themes/default.ts
+++ b/packages/client/src/theme/themes/default.ts
@@ -110,6 +110,9 @@ export const defaultTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '126 34 206', // #7e22ce (purple-700)
+ '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)
/** 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 0e27fb7ee5..1c20852a13 100644
--- a/packages/client/src/theme/themes/highContrast.ts
+++ b/packages/client/src/theme/themes/highContrast.ts
@@ -145,6 +145,9 @@ export const highContrastLightTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '107 0 179', // #6b00b3
+ '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)
/** Code syntax highlighting at AAA on the white code surface. */
'rgb-syntax-text': '0 0 0', // #000000
@@ -301,6 +304,9 @@ export const highContrastDarkTheme: IThemeRGB = {
// Brand colors
'rgb-brand-purple': '224 179 255', // #e0b3ff
+ '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)
/** 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 14d17e4e14..9aca03c885 100644
--- a/packages/client/src/theme/tokens.css
+++ b/packages/client/src/theme/tokens.css
@@ -22,6 +22,9 @@
@theme inline {
/* brand and surfaces */
--color-brand-purple: rgb(var(--brand-purple));
+ --color-avatar-fill: rgb(var(--avatar-fill));
+ --color-avatar-text: rgb(var(--avatar-text));
+ --color-avatar-placeholder: rgb(var(--avatar-placeholder));
--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 e5eebb28d4..c7236ec718 100644
--- a/packages/client/src/theme/types/index.ts
+++ b/packages/client/src/theme/types/index.ts
@@ -132,6 +132,13 @@ export interface IThemeRGB {
// Brand colors
'rgb-brand-purple'?: string;
+ /** The default user avatar's fill and glyph, drawn when a user has no image. The glyph follows
+ * `rgb-text-primary` in a theme that does not set it, as it did before it had a role. */
+ 'rgb-avatar-fill'?: string;
+ 'rgb-avatar-text'?: string;
+ /** Behind an agent or assistant avatar while its image loads or where it is transparent. */
+ 'rgb-avatar-placeholder'?: string;
+
/**
* Code syntax highlighting. Declared here rather than left as literals in the
* stylesheet so a palette stays in one place, is covered by the registry's
@@ -273,6 +280,9 @@ export interface IThemeVariables {
'--status-verified': string;
'--text-on-status': string;
'--brand-purple': string;
+ '--avatar-fill': string;
+ '--avatar-text': string;
+ '--avatar-placeholder': string;
'--syntax-text': string;
'--syntax-comment': string;
@@ -389,6 +399,9 @@ export interface IThemeColors {
'status-verified'?: string;
'text-on-status'?: string;
'brand-purple'?: string;
+ 'avatar-fill'?: string;
+ 'avatar-text'?: string;
+ 'avatar-placeholder'?: string;
'series-1'?: string;
'series-2'?: string;
diff --git a/packages/client/src/theme/utils/applyTheme.spec.ts b/packages/client/src/theme/utils/applyTheme.spec.ts
index 7be3974b49..5350b6cde5 100644
--- a/packages/client/src/theme/utils/applyTheme.spec.ts
+++ b/packages/client/src/theme/utils/applyTheme.spec.ts
@@ -4,6 +4,7 @@ import applyTheme, {
clearAppliedTheme,
themeOwnedProperties,
THEME_DISABLED_ATTRIBUTE,
+ THEME_SCOPE_ATTRIBUTE,
} from './applyTheme';
import { defaultAppearance, highContrastTheme, resolveTheme } from '../registry';
import { defaultTheme } from '../themes/default';
@@ -19,6 +20,8 @@ const semanticProperties = [
'--chart-widget-surface',
'--chart-widget-stroke',
'--switch-thumb',
+ '--avatar-placeholder',
+ '--avatar-text',
'--table-header-text',
'--table-header-fill',
'--border-destructive',
@@ -381,6 +384,53 @@ describe('applyTheme', () => {
expect(root.hasAttribute(THEME_DISABLED_ATTRIBUTE)).toBe(false);
});
+ it('leaves the document root backdrop to the stylesheet alias so it follows the mode', () => {
+ const root = document.documentElement;
+
+ applyTheme({ 'rgb-surface-secondary': '20 21 22', 'rgb-surface-tertiary': '30 31 32' }, root);
+
+ expect(root.style.getPropertyValue('--surface-secondary')).toBe('20 21 22');
+ expect(root.style.getPropertyValue('--avatar-placeholder')).toBe('');
+ });
+
+ it('marks a scoped root so the stylesheet derives its backdrop from its own surfaces', () => {
+ const scoped = document.createElement('div');
+ document.body.append(scoped);
+ try {
+ applyTheme(
+ { 'rgb-surface-secondary': '20 21 22', 'rgb-surface-tertiary': '30 31 32' },
+ scoped,
+ );
+
+ expect(scoped.hasAttribute(THEME_SCOPE_ATTRIBUTE)).toBe(true);
+ expect(scoped.style.getPropertyValue('--avatar-placeholder')).toBe('');
+ expect(document.documentElement.hasAttribute(THEME_SCOPE_ATTRIBUTE)).toBe(false);
+
+ clearAppliedTheme(scoped);
+ expect(scoped.hasAttribute(THEME_SCOPE_ATTRIBUTE)).toBe(false);
+ } finally {
+ scoped.remove();
+ }
+ });
+
+ it("inks a legacy theme's default avatar in its primary text", () => {
+ const root = document.documentElement;
+
+ applyTheme({ 'rgb-text-primary': '10 11 12' }, root);
+ expect(root.style.getPropertyValue('--avatar-text')).toBe('10 11 12');
+
+ applyTheme({ 'rgb-text-primary': '10 11 12', 'rgb-avatar-text': '1 2 3' }, root);
+ expect(root.style.getPropertyValue('--avatar-text')).toBe('1 2 3');
+ });
+
+ it('leaves an explicit avatar backdrop alone', () => {
+ const root = document.documentElement;
+
+ applyTheme({ 'rgb-surface-tertiary': '30 31 32', 'rgb-avatar-placeholder': '1 2 3' }, root);
+
+ expect(root.style.getPropertyValue('--avatar-placeholder')).toBe('1 2 3');
+ });
+
it('keeps the switch knob of a legacy theme on the surface it repainted', () => {
const root = document.documentElement;
diff --git a/packages/client/src/theme/utils/applyTheme.ts b/packages/client/src/theme/utils/applyTheme.ts
index 3f8aa871fa..4990064d47 100644
--- a/packages/client/src/theme/utils/applyTheme.ts
+++ b/packages/client/src/theme/utils/applyTheme.ts
@@ -63,6 +63,10 @@ function mapColors(colors: IThemeRGB, base?: IThemeRGB): Array<[string, string]>
variables.push(['--text-muted', colors['rgb-text-tertiary']]);
}
+ if (colors['rgb-avatar-text'] === undefined && colors['rgb-text-primary'] !== undefined) {
+ variables.push(['--avatar-text', colors['rgb-text-primary']]);
+ }
+
if (
colors['rgb-chart-widget-surface'] === undefined &&
colors['rgb-surface-primary'] !== undefined
@@ -156,10 +160,18 @@ function mapAppearance(appearance: IThemeAppearance): Array<[string, string]> {
*/
export const THEME_DISABLED_ATTRIBUTE = 'data-theme-disabled';
+/**
+ * Marks a root other than the document one that a legacy palette themes. The stylesheet points
+ * the avatar backdrop at that root's own secondary surface, or its tertiary one under a `.dark`
+ * ancestor, as the document root's alias does, so the backdrop follows a later mode change.
+ */
+export const THEME_SCOPE_ATTRIBUTE = 'data-theme-scope';
+
export function clearAppliedTheme(root: HTMLElement = document.documentElement): void {
themeOwnedProperties.forEach((property) => root.style.removeProperty(property));
root.removeAttribute('data-theme');
root.removeAttribute(THEME_DISABLED_ATTRIBUTE);
+ root.removeAttribute(THEME_SCOPE_ATTRIBUTE);
}
export function applyResolvedTheme(
@@ -196,6 +208,9 @@ export default function applyTheme(
return;
}
+ if (root !== root.ownerDocument.documentElement) {
+ root.setAttribute(THEME_SCOPE_ATTRIBUTE, '');
+ }
mapColors(themeRGB, base).forEach(([property, value]) => {
if (!validateRGB(value)) {
console.error(`Invalid RGB value for ${property}: ${value}`);
diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.ts
index dc77cee942..2e5370c807 100644
--- a/packages/data-provider/src/theme.ts
+++ b/packages/data-provider/src/theme.ts
@@ -101,6 +101,9 @@ export const themeColorTokens = Object.freeze([
'rgb-status-verified',
'rgb-text-on-status',
'rgb-brand-purple',
+ 'rgb-avatar-fill',
+ 'rgb-avatar-text',
+ 'rgb-avatar-placeholder',
'rgb-syntax-text',
'rgb-syntax-comment',
'rgb-syntax-meta',