The best way to control Claude Code, Codex and more from any computer or phone
fix(web): chips drop their pill and stay readable on every theme (#25066)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
oliver committed
Oct 27, 2026 at 13:01 UTC
4914cdd98f3d15ab2ddef34f0af70d3d68a2d8e5
16 files changed
+455
-151
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+4
-7
@@ -1,4 +1,4 @@
1
-import { documentIconColorForFileName } from "~/pierre-icons";
1
+import { documentChipKindForFileName } from "~/pierre-icons";
2
import { isProviderSkillUserInvocable } from "@t3tools/client-runtime/providerSkills";
3
import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
4
import {
@@ -46,7 +46,6 @@ import {
46
useLayoutEffect,
47
useRef,
48
useState,
49
- type CSSProperties,
49
type KeyboardEvent as ReactKeyboardEvent,
50
type RefObject,
51
} from "react";
@@ -232,7 +231,7 @@ function resolvedThemeFromDocument(): "light" | "dark" {
231
}
232
233
const CHIP_NODE_SELECTION_CLASS_NAME =
235
- "relative inline-flex select-none items-center align-middle leading-none data-[composer-chip-selected]:after:pointer-events-none data-[composer-chip-selected]:after:absolute data-[composer-chip-selected]:after:inset-0 data-[composer-chip-selected]:after:rounded-sm data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']";
234
+ "relative inline-flex min-w-0 max-w-full select-none items-baseline data-[composer-chip-selected]:after:pointer-events-none data-[composer-chip-selected]:after:absolute data-[composer-chip-selected]:after:inset-0 data-[composer-chip-selected]:after:rounded-sm data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']";
235
236
const ComposerMentionExtension = Node.create({
237
name: "composer-mention",
@@ -260,11 +259,9 @@ const ComposerMentionExtension = Node.create({
259
function ComposerMentionNodeView({ node }: NodeViewProps) {
260
const actions = use(ComposerContextActionsContext);
261
const path = (node.attrs.path as string) ?? "";
263
- const accent = documentIconColorForFileName(path);
262
const chip = (
263
<ContextChip
266
- kind="mention"
267
- style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined}
264
+ kind={documentChipKindForFileName(path) ?? "mention"}
265
dir="ltr"
266
render={<button type="button" />}
267
onClick={() => actions.openMention(path)}
@@ -442,7 +439,7 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
439
return (
440
<NodeViewWrapper
441
as="span"
445
- className={cn(CHIP_NODE_SELECTION_CLASS_NAME, "min-w-0 max-w-full")}
442
+ className={CHIP_NODE_SELECTION_CLASS_NAME}
443
contentEditable={false}
444
spellCheck={false}
445
data-composer-citation-chip="true"
apps/web/src/components/ContextChip.browser.test.tsx
new
+42
@@ -0,0 +1,42 @@
1
+import { FileIcon } from "lucide-react";
2
+import { describe, expect, it } from "vite-plus/test";
3
+
4
+import "~/index.css";
5
+import { render } from "../../test/render";
6
+import { ContextChip, ContextChipLabel } from "./ContextChip";
7
+
8
+// An empty inline-block's bottom edge sits on the baseline of the line it is in.
9
+function BaselineMarker(props: { id: string }) {
10
+ return <span data-baseline={props.id} className="inline-block size-0" />;
11
+}
12
+
13
+describe("ContextChip", () => {
14
+ it("sets its label on the sentence baseline at the sentence size without growing the line", async () => {
15
+ await using screen = await render(
16
+ <p className="w-[60ch] text-sm leading-relaxed">
17
+ Open
18
+ <BaselineMarker id="text" /> the{" "}
19
+ <ContextChip kind="mention" render={<button type="button" />}>
20
+ <FileIcon />
21
+ <ContextChipLabel>
22
+ src/
23
+ <BaselineMarker id="chip" />
24
+ Typography.tsx
25
+ </ContextChipLabel>
26
+ </ContextChip>{" "}
27
+ file
28
+ </p>,
29
+ );
30
+ const paragraph = screen.container.querySelector("p")!;
31
+ const label = screen.container.querySelector<HTMLElement>('[data-slot="context-chip-label"]')!;
32
+ const baseline = (id: string) =>
33
+ screen.container.querySelector(`[data-baseline="${id}"]`)!.getBoundingClientRect().bottom;
34
+
35
+ expect(getComputedStyle(label).fontSize).toBe(getComputedStyle(paragraph).fontSize);
36
+ expect(Math.abs(baseline("chip") - baseline("text"))).toBeLessThanOrEqual(0.5);
37
+ expect(paragraph.getBoundingClientRect().height).toBeCloseTo(
38
+ Number.parseFloat(getComputedStyle(paragraph).lineHeight),
39
+ 0,
40
+ );
41
+ });
42
+});
apps/web/src/components/ContextChip.tsx
+31
-48
@@ -6,60 +6,40 @@ import type * as React from "react";
6
import { cn } from "~/lib/utils";
7
8
const contextChipVariants = cva(
9
- "inline-flex h-[1.41em] max-w-full items-center gap-[0.33em] rounded-[0.5em] border px-[0.5em] align-middle font-medium text-[0.86em] leading-none [&_svg]:block [&_svg]:size-[1.17em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer [button&,a&]:transition-colors [button&,a&]:motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-foreground disabled:cursor-default",
9
+ "inline-flex max-w-full items-center gap-[0.2em] font-medium leading-[normal] text-(--context-chip-ink) [--context-chip-ink:var(--context-chip-accent)] [--document-icon-stroke:var(--context-chip-ink)] [&_svg]:block [&_svg]:size-[1em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-current rounded-sm disabled:cursor-default",
10
{
11
defaultVariants: { kind: "neutral" },
12
variants: {
13
kind: {
14
- neutral: "border-border/70 bg-accent/40 text-foreground",
15
- image: "[--context-chip-accent:oklch(0.62_0.16_16)]",
16
- video: "[--context-chip-accent:oklch(0.62_0.16_48)]",
17
- file: "[--context-chip-accent:oklch(0.62_0.136_237)]",
18
- mention: "[--context-chip-accent:oklch(0.62_0.11_215)]",
19
- terminal: "[--context-chip-accent:oklch(0.62_0.134_163)]",
20
- element: "[--context-chip-accent:oklch(0.62_0.134_70)]",
21
- "preview-annotation": "[--context-chip-accent:oklch(0.62_0.134_70)]",
22
- "review-comment": "[--context-chip-accent:oklch(0.62_0.16_292)]",
23
- "pull-request": "[--context-chip-accent:oklch(0.62_0.16_277)]",
24
- "pr-open": "[--context-chip-accent:oklch(0.62_0.134_163)]",
25
- "pr-draft": "[--context-chip-accent:oklch(0.62_0.02_259)]",
26
- "pr-merged": "[--context-chip-accent:oklch(0.62_0.16_292)]",
27
- "pr-closed": "[--context-chip-accent:oklch(0.62_0.16_16)]",
28
- skill: "[--context-chip-accent:oklch(0.62_0.16_322)]",
29
- thread: "[--context-chip-accent:oklch(0.62_0.12_190)]",
30
- citation: "[--context-chip-accent:oklch(0.62_0.16_259)]",
14
+ neutral: "[--context-chip-accent:currentColor]",
15
+ image: "[--context-chip-accent:var(--context-chip-image)]",
16
+ video: "[--context-chip-accent:var(--context-chip-video)]",
17
+ file: "[--context-chip-accent:var(--context-chip-file)]",
18
+ mention: "[--context-chip-accent:var(--context-chip-mention)]",
19
+ terminal: "[--context-chip-accent:var(--context-chip-terminal)]",
20
+ element: "[--context-chip-accent:var(--context-chip-element)]",
21
+ "preview-annotation": "[--context-chip-accent:var(--context-chip-preview-annotation)]",
22
+ "review-comment": "[--context-chip-accent:var(--context-chip-review-comment)]",
23
+ "pull-request": "[--context-chip-accent:var(--context-chip-pull-request)]",
24
+ "pr-open": "[--context-chip-accent:var(--context-chip-pr-open)]",
25
+ "pr-draft": "[--context-chip-accent:var(--context-chip-pr-draft)]",
26
+ "pr-merged": "[--context-chip-accent:var(--context-chip-pr-merged)]",
27
+ "pr-closed": "[--context-chip-accent:var(--context-chip-pr-closed)]",
28
+ skill: "[--context-chip-accent:var(--context-chip-skill)]",
29
+ thread: "[--context-chip-accent:var(--context-chip-thread)]",
30
+ citation: "[--context-chip-accent:var(--context-chip-citation)]",
31
+ "doc-pdf": "[--context-chip-accent:var(--context-chip-doc-pdf)]",
32
+ "doc-word": "[--context-chip-accent:var(--context-chip-doc-word)]",
33
+ "doc-spreadsheet": "[--context-chip-accent:var(--context-chip-doc-spreadsheet)]",
34
+ "doc-slides": "[--context-chip-accent:var(--context-chip-doc-slides)]",
35
+ "doc-epub": "[--context-chip-accent:var(--context-chip-doc-epub)]",
36
},
37
state: {
33
- unresolved: "border-dashed",
34
- invalid: "",
38
+ unresolved: "data-[state=unresolved]:[--context-chip-accent:currentColor]",
39
+ invalid:
40
+ "data-[state=invalid]:[--context-chip-accent:var(--context-chip-invalid,var(--destructive-foreground))]",
41
},
42
},
37
- compoundVariants: [
38
- {
39
- kind: [
40
- "image",
41
- "video",
42
- "file",
43
- "mention",
44
- "terminal",
45
- "element",
46
- "preview-annotation",
47
- "review-comment",
48
- "pull-request",
49
- "pr-open",
50
- "pr-draft",
51
- "pr-merged",
52
- "pr-closed",
53
- "skill",
54
- "thread",
55
- "citation",
56
- ],
57
- className:
58
- "[--context-chip-border:color-mix(in_oklab,var(--context-chip-accent)_34%,var(--contrast-border))] [--context-chip-border-hover:color-mix(in_oklab,var(--context-chip-accent)_48%,var(--contrast-border))] [--context-chip-foreground:color-mix(in_oklab,var(--context-chip-accent)_22%,var(--contrast-foreground))] border-(--context-chip-border) bg-(--context-chip-accent)/11 text-(--context-chip-foreground) [button:enabled&,a&]:hover:border-(--context-chip-border-hover) [button:enabled&,a&]:hover:bg-(--context-chip-accent)/17",
59
- },
60
- { state: "unresolved", className: "text-foreground" },
61
- { state: "invalid", className: "border-destructive/35 bg-destructive/8 text-destructive" },
62
- ],
43
},
44
);
45
@@ -86,7 +66,10 @@ function ContextChip({ className, kind, state, render, ...props }: ContextChipPr
66
function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) {
67
return (
68
<span
89
- className={cn("block min-w-0 self-center truncate leading-tight", className)}
69
+ className={cn(
70
+ "block min-w-0 self-baseline overflow-x-clip text-ellipsis whitespace-nowrap underline decoration-transparent decoration-1 underline-offset-[0.2em] transition-colors motion-reduce:transition-none [:is(button:enabled,a):hover>&]:decoration-current",
71
+ className,
72
+ )}
73
data-slot="context-chip-label"
74
{...props}
75
/>
@@ -96,7 +79,7 @@ function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">)
79
function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) {
80
const defaultProps = {
81
className: cn(
99
- "ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
82
+ "ml-[0.17em] inline-flex size-[1em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
83
className,
84
),
85
"data-slot": "context-chip-action",
apps/web/src/components/ThreadContextChip.tsx
+1
-1
@@ -30,7 +30,7 @@ export function ThreadContextChip(props: {
30
className="no-underline"
31
>
32
{project ? (
33
- <ProjectFavicon project={project} className="size-[1.17em] self-center" />
33
+ <ProjectFavicon project={project} className="size-[1em] self-center" />
34
) : (
35
<MessagesSquareIcon />
36
)}
apps/web/src/components/chat/AssistantCitationChip.tsx
+1
-1
@@ -124,7 +124,7 @@ export function AssistantCitationChip({
124
const composerSourceLink = (
125
<Link
126
{...sourceLinkProps}
127
- className="inline-flex h-full min-w-0 items-center gap-[0.33em] rounded-sm text-inherit no-underline focus-visible:outline-2 focus-visible:outline-foreground"
127
+ className="inline-flex min-w-0 items-center gap-[0.2em] self-baseline text-inherit no-underline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-current rounded-sm"
128
aria-label={`View cited assistant text: ${label}`}
129
>
130
<QuoteIcon aria-hidden="true" />
apps/web/src/components/chat/MarkdownFileLink.tsx
+5
-8
@@ -5,13 +5,13 @@ import {
5
type AtomCommandResult,
6
} from "@t3tools/client-runtime/state/runtime";
7
import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
8
-import { memo, type CSSProperties, type MouseEvent as ReactMouseEvent } from "react";
8
+import { memo, type MouseEvent as ReactMouseEvent } from "react";
9
10
import { readLocalApi } from "../../localApi";
11
import { cn } from "../../lib/utils";
12
import { shouldOpenMarkdownFileLinkInEditor } from "../../markdown-links";
13
import type { markdownFileCopyPaths } from "../../markdownFileHostPath";
14
-import { documentIconColorForFileName } from "../../pierre-icons";
14
+import { documentChipKindForFileName } from "../../pierre-icons";
15
import { ContextChip } from "../ContextChip";
16
import { stackedThreadToast, toastManager } from "../ui/toast";
17
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -321,8 +321,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
321
canOpenInBrowser,
322
canOpenInPanel,
323
});
324
- const accent = documentIconColorForFileName(iconPath);
325
- const chipStyle = accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined;
324
+ const chipKind = documentChipKindForFileName(iconPath) ?? "mention";
325
326
return (
327
<Tooltip>
@@ -330,11 +329,10 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
329
render={
330
hasPrimaryAction ? (
331
<ContextChip
333
- kind="mention"
332
+ kind={chipKind}
333
dir="ltr"
334
render={<a href={href} />}
335
className={MARKDOWN_FILE_LINK_CLASS_NAME}
337
- style={chipStyle}
336
data-markdown-copy={copyMarkdown}
337
onClick={(event) => {
338
event.preventDefault();
@@ -360,13 +358,12 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
358
</ContextChip>
359
) : (
360
<ContextChip
363
- kind="mention"
361
+ kind={chipKind}
362
dir="ltr"
363
render={<button type="button" />}
364
aria-label={`File options for ${label}`}
365
aria-haspopup="menu"
366
className={cn(MARKDOWN_FILE_LINK_CLASS_NAME, "select-text")}
369
- style={chipStyle}
367
data-markdown-copy={copyMarkdown}
368
onClick={handleContextMenu}
369
onContextMenu={handleContextMenu}
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+5
@@ -75,6 +75,9 @@ import {
75
import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
76
import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic";
77
78
+const BUBBLE_CHIP_CLASS_NAME =
79
+ "[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]";
80
+
81
function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {
82
const ctx = use(TimelineRowCtx);
83
// Row updates rebuild attachment objects, so the asset follows only the
@@ -165,6 +168,7 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
168
<div
169
className={cn(
170
"min-w-0 max-w-[80%] rounded-2xl bg-message text-message-foreground",
171
+ BUBBLE_CHIP_CLASS_NAME,
172
expanded && "w-full",
173
)}
174
>
@@ -454,6 +458,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
458
<div
459
className={cn(
460
"relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
461
+ BUBBLE_CHIP_CLASS_NAME,
462
userMessage.attribution === "guest" ? guestBubbleClassName(false) : "bg-message",
463
!folded && "p-3",
464
folded && expanded && "w-full",
apps/web/src/components/chat/UserMessageContextChips.tsx
+3
-5
@@ -1,4 +1,4 @@
1
-import { documentIconColorForFileName } from "~/pierre-icons";
1
+import { documentChipKindForFileName } from "~/pierre-icons";
2
import { isSvgAttachment } from "@t3tools/shared/image";
3
import { useRenderedAppearance } from "../../hooks/useTheme";
4
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
@@ -6,7 +6,7 @@ import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview";
6
import { useRightPanelStore } from "~/rightPanelStore";
7
import { COMPOSER_CONTEXT_KINDS } from "@t3tools/contracts";
8
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
9
-import { use, type CSSProperties, type ReactNode } from "react";
9
+import { use, type ReactNode } from "react";
10
import { FileDiff } from "@pierre/diffs/react";
11
import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
12
import {
@@ -65,14 +65,12 @@ function UserMessageMentionChip(props: {
65
copyMarkdown: string;
66
}) {
67
const ctx = use(TimelineRowCtx);
68
- const accent = documentIconColorForFileName(props.record.path);
68
return (
69
<Tooltip>
70
<TooltipTrigger
71
render={
72
<ContextChip
74
- kind="mention"
75
- style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined}
73
+ kind={documentChipKindForFileName(props.record.path) ?? "mention"}
74
render={<button type="button" />}
75
aria-label={`Preview ${props.record.path}`}
76
data-markdown-copy={props.copyMarkdown}
apps/web/src/components/contextChipParts.tsx
+9
-53
@@ -1,15 +1,8 @@
1
import type { EnvironmentId, PullRequestContextMetadata } from "@t3tools/contracts";
2
import { CircleDashedIcon, FilmIcon, ImageIcon } from "lucide-react";
3
-import {
4
- useEffect,
5
- useState,
6
- type ComponentProps,
7
- type CSSProperties,
8
- type MouseEvent,
9
- type ReactNode,
10
-} from "react";
3
+import { useEffect, useState, type ComponentProps, type MouseEvent, type ReactNode } from "react";
4
import { useAssetUrlState } from "~/assets/assetUrls";
12
-import { documentIconColorForFileName } from "~/pierre-icons";
5
+import { documentChipKindForFileName } from "~/pierre-icons";
6
7
import { PULL_REQUEST_STATE_PRESENTATION } from "~/components/pullRequest/pullRequestIcons";
8
import type { PullRequestContextDisplayState } from "~/lib/composerContextRecords";
@@ -139,32 +132,6 @@ export function PullRequestChip(props: {
132
);
133
}
134
142
-function averageImageColor(image: HTMLImageElement): string | undefined {
143
- try {
144
- const canvas = document.createElement("canvas");
145
- canvas.width = canvas.height = 16;
146
- const context = canvas.getContext("2d");
147
- if (!context) return;
148
- context.drawImage(image, 0, 0, 16, 16);
149
- const { data } = context.getImageData(0, 0, 16, 16);
150
- let red = 0;
151
- let green = 0;
152
- let blue = 0;
153
- let alpha = 0;
154
- for (let index = 0; index < data.length; index += 4) {
155
- const weight = data[index + 3]!;
156
- red += data[index]! * weight;
157
- green += data[index + 1]! * weight;
158
- blue += data[index + 2]! * weight;
159
- alpha += weight;
160
- }
161
- if (alpha === 0) return;
162
- return `rgb(${Math.round(red / alpha)} ${Math.round(green / alpha)} ${Math.round(blue / alpha)})`;
163
- } catch {
164
- return;
165
- }
166
-}
167
-
135
export function ImageChipButton({
136
name,
137
previewUrl,
@@ -172,7 +139,6 @@ export function ImageChipButton({
139
suffix,
140
disabled,
141
onPreviewError,
175
- style,
142
...props
143
}: Omit<ComponentProps<typeof ContextChip>, "kind" | "render"> & {
144
name: string;
@@ -182,31 +148,20 @@ export function ImageChipButton({
148
disabled?: boolean | undefined;
149
onPreviewError?: (() => void) | undefined;
150
}) {
185
- const [sample, setSample] = useState<{ url: string; color: string | undefined }>();
186
- const [corsFailedUrl, setCorsFailedUrl] = useState<string>();
187
- const accent = sample?.url === previewUrl ? sample?.color : undefined;
151
return (
152
<ContextChip
153
kind="image"
154
render={<button type="button" disabled={disabled} />}
155
aria-label={`Image attachment, ${name}, ${size}`}
193
- style={{ ...style, ...(accent ? { "--context-chip-accent": accent } : {}) } as CSSProperties}
156
{...props}
157
>
158
{previewUrl ? (
159
<img
160
key={previewUrl}
199
- crossOrigin={corsFailedUrl === previewUrl ? undefined : "anonymous"}
161
src={previewUrl}
162
alt=""
202
- className="size-[1.17em] shrink-0 rounded-sm object-cover"
203
- onError={() => {
204
- if (corsFailedUrl === previewUrl) onPreviewError?.();
205
- else setCorsFailedUrl(previewUrl);
206
- }}
207
- onLoad={(event) =>
208
- setSample({ url: previewUrl, color: averageImageColor(event.currentTarget) })
209
- }
163
+ className="size-[1em] shrink-0 self-center rounded-sm object-cover"
164
+ onError={onPreviewError}
165
/>
166
) : (
167
<ImageIcon />
@@ -243,15 +198,13 @@ export function FileChip(props: {
198
}) {
199
if (props.svgPreview && !props.unresolved) return <SvgFileChip {...props} />;
200
const content = <FileChipContent {...props} />;
246
- const accent = props.isVideo ? undefined : documentIconColorForFileName(props.name);
201
const state = props.unresolved
202
? ("unresolved" as const)
203
: props.error
204
? ("invalid" as const)
205
: null;
206
const attributes = {
253
- kind: props.isVideo ? "video" : "file",
254
- style: accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined,
207
+ kind: props.isVideo ? "video" : (documentChipKindForFileName(props.name) ?? "file"),
208
...(state ? { state } : {}),
209
"aria-label": [props.accessibleLabel, props.suffix].filter(Boolean).join(", "),
210
"data-markdown-copy": props.copyMarkdown,
@@ -348,10 +301,13 @@ function FileChipContent(props: {
301
isVideo: boolean;
302
theme: "light" | "dark";
303
suffix?: string | null;
304
+ unresolved?: boolean;
305
}) {
306
return (
307
<>
354
- {props.isVideo ? (
308
+ {props.unresolved ? (
309
+ <CircleDashedIcon />
310
+ ) : props.isVideo ? (
311
<FilmIcon />
312
) : (
313
<PierreEntryIcon pathValue={props.name} kind="file" theme={props.theme} />
apps/web/src/components/files/AudioPreview.tsx
+3
-3
@@ -111,7 +111,7 @@ function AudioChip(props: AudioPreviewProps) {
111
<ContextChip
112
kind="file"
113
{...(props.failed ? { state: "invalid" as const } : {})}
114
- className="relative isolate overflow-hidden has-[button:enabled]:hover:border-(--context-chip-border-hover) has-[button:enabled]:hover:bg-(--context-chip-accent)/17"
114
+ className="relative isolate overflow-hidden"
115
title={props.failed ? "Audio unavailable. Open the file or retry playback." : props.name}
116
>
117
<span
@@ -120,7 +120,7 @@ function AudioChip(props: AudioPreviewProps) {
120
style={{ width: `${duration > 0 ? Math.min(100, (elapsed / duration) * 100) : 0}%` }}
121
/>
122
<ContextChipAction
123
- className="ml-0 [&_svg]:size-[1.17em]"
123
+ className="ml-0 [&_svg]:size-[1em]"
124
aria-label={`${props.failed ? "Audio unavailable. " : ""}${action} ${props.name}`}
125
disabled={loading}
126
onClick={() => {
@@ -154,7 +154,7 @@ function AudioChip(props: AudioPreviewProps) {
154
middleTruncateAttachmentName(props.name)
155
)}
156
</ContextChipLabel>
157
- <span className="shrink-0 text-3xs text-current">
157
+ <span className="shrink-0 self-baseline text-3xs text-current">
158
{props.failed
159
? "Unavailable"
160
: loading
apps/web/src/lib/contextChipAccents.ts
new
+29
@@ -0,0 +1,29 @@
1
+export const CONTEXT_CHIP_ACCENTS = {
2
+ image: "oklch(0.62 0.16 16)",
3
+ video: "oklch(0.62 0.16 48)",
4
+ file: "oklch(0.62 0.136 237)",
5
+ mention: "oklch(0.62 0.11 215)",
6
+ terminal: "oklch(0.62 0.134 163)",
7
+ element: "oklch(0.62 0.134 70)",
8
+ "preview-annotation": "oklch(0.62 0.134 70)",
9
+ "review-comment": "oklch(0.62 0.16 292)",
10
+ "pull-request": "oklch(0.62 0.16 277)",
11
+ "pr-open": "oklch(0.62 0.134 163)",
12
+ "pr-draft": "oklch(0.62 0.02 259)",
13
+ "pr-merged": "oklch(0.62 0.16 292)",
14
+ "pr-closed": "oklch(0.62 0.16 16)",
15
+ skill: "oklch(0.62 0.16 322)",
16
+ thread: "oklch(0.62 0.12 190)",
17
+ citation: "oklch(0.62 0.16 259)",
18
+ "doc-pdf": "oklch(0.62 0.16 24)",
19
+ "doc-word": "oklch(0.62 0.136 248)",
20
+ "doc-spreadsheet": "oklch(0.62 0.134 148)",
21
+ "doc-slides": "oklch(0.62 0.134 56)",
22
+ "doc-epub": "oklch(0.62 0.16 291)",
23
+} as const;
24
+
25
+export type ContextChipAccentKind = keyof typeof CONTEXT_CHIP_ACCENTS;
26
+
27
+export function contextChipColorVariable(kind: ContextChipAccentKind): string {
28
+ return `--context-chip-${kind}`;
29
+}
apps/web/src/pierre-icons.ts
+17
-7
@@ -6,6 +6,8 @@ import {
6
import { VIDEO_FILE_EXTENSIONS } from "@t3tools/shared/video";
7
import { fileIconPathForMimeType } from "@t3tools/shared/mediaPreview";
8
9
+import type { ContextChipAccentKind } from "~/lib/contextChipAccents";
10
+
11
export interface PierreIconResolution {
12
name: string;
13
token?: string;
@@ -51,7 +53,7 @@ const T3_FILE_ICON_SPRITE = `
53
</symbol>
54
<!-- Lucide File Type, File Text, File Spreadsheet, Presentation and Book Open icons, ISC license. -->
55
<symbol id="t3-file-icon-pdf" viewBox="0 0 24 24">
54
- <g fill="none" style="stroke: ${DOCUMENT_ICON_COLORS["t3-file-icon-pdf"]}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
56
+ <g fill="none" style="stroke: var(--document-icon-stroke, ${DOCUMENT_ICON_COLORS["t3-file-icon-pdf"]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
57
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
58
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
59
<path d="M11 18h2" />
@@ -60,7 +62,7 @@ const T3_FILE_ICON_SPRITE = `
62
</g>
63
</symbol>
64
<symbol id="t3-file-icon-word" viewBox="0 0 24 24">
63
- <g fill="none" style="stroke: ${DOCUMENT_ICON_COLORS["t3-file-icon-word"]}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
65
+ <g fill="none" style="stroke: var(--document-icon-stroke, ${DOCUMENT_ICON_COLORS["t3-file-icon-word"]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
66
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
67
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
68
<path d="M10 9H8" />
@@ -69,7 +71,7 @@ const T3_FILE_ICON_SPRITE = `
71
</g>
72
</symbol>
73
<symbol id="t3-file-icon-spreadsheet" viewBox="0 0 24 24">
72
- <g fill="none" style="stroke: ${DOCUMENT_ICON_COLORS["t3-file-icon-spreadsheet"]}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
74
+ <g fill="none" style="stroke: var(--document-icon-stroke, ${DOCUMENT_ICON_COLORS["t3-file-icon-spreadsheet"]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
75
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
76
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
77
<path d="M8 13h2" />
@@ -79,14 +81,14 @@ const T3_FILE_ICON_SPRITE = `
81
</g>
82
</symbol>
83
<symbol id="t3-file-icon-slides" viewBox="0 0 24 24">
82
- <g fill="none" style="stroke: ${DOCUMENT_ICON_COLORS["t3-file-icon-slides"]}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
84
+ <g fill="none" style="stroke: var(--document-icon-stroke, ${DOCUMENT_ICON_COLORS["t3-file-icon-slides"]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
85
<path d="M2 3h20" />
86
<path d="M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3" />
87
<path d="m7 21 5-5 5 5" />
88
</g>
89
</symbol>
90
<symbol id="t3-file-icon-epub" viewBox="0 0 24 24">
89
- <g fill="none" style="stroke: ${DOCUMENT_ICON_COLORS["t3-file-icon-epub"]}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
91
+ <g fill="none" style="stroke: var(--document-icon-stroke, ${DOCUMENT_ICON_COLORS["t3-file-icon-epub"]})" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
92
<path d="M12 7v14" />
93
<path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z" />
94
</g>
@@ -244,9 +246,17 @@ export function resolvePierreIconForEntry(
246
: icon;
247
}
248
247
-export function documentIconColorForFileName(fileName: string) {
249
+const DOCUMENT_CHIP_KINDS: Readonly<Record<string, ContextChipAccentKind>> = {
250
+ "t3-file-icon-pdf": "doc-pdf",
251
+ "t3-file-icon-word": "doc-word",
252
+ "t3-file-icon-spreadsheet": "doc-spreadsheet",
253
+ "t3-file-icon-slides": "doc-slides",
254
+ "t3-file-icon-epub": "doc-epub",
255
+};
256
+
257
+export function documentChipKindForFileName(fileName: string) {
258
const icon = resolvePierreIconForEntry(fileName, "file");
249
- return icon ? DOCUMENT_ICON_COLORS[icon.name] : undefined;
259
+ return icon ? DOCUMENT_CHIP_KINDS[icon.name] : undefined;
260
}
261
262
export function hasSpecificPierreIconForFileName(fileName: string): boolean {
apps/web/src/themePalette.browser.test.ts
new
+56
@@ -0,0 +1,56 @@
1
+import { converter } from "culori/fn";
2
+import { describe, expect, it } from "vite-plus/test";
3
+
4
+import "~/index.css";
5
+import { getStandardPaintedThemeColors } from "./themePalette";
6
+
7
+const toRgb = converter("rgb");
8
+
9
+function paintedChannels(variable: string, canvas: readonly number[] = [0, 0, 0]): number[] {
10
+ const probe = document.createElement("div");
11
+ probe.style.backgroundColor = `var(${variable})`;
12
+ document.body.append(probe);
13
+ try {
14
+ const color = toRgb(getComputedStyle(probe).backgroundColor)!;
15
+ const alpha = color.alpha ?? 1;
16
+ return [color.r, color.g, color.b].map(
17
+ (channel, index) => (channel * alpha + (canvas[index]! / 255) * (1 - alpha)) * 255,
18
+ );
19
+ } finally {
20
+ probe.remove();
21
+ }
22
+}
23
+
24
+describe("standard painted theme colors", () => {
25
+ it("match the chip surfaces index.css paints", () => {
26
+ const root = document.documentElement;
27
+ try {
28
+ for (const redesign of [false, true, false]) {
29
+ root.toggleAttribute("data-redesign", redesign);
30
+ for (const appearance of ["light", "dark"] as const) {
31
+ root.classList.toggle("dark", appearance === "dark");
32
+ const colors = getStandardPaintedThemeColors(appearance, redesign);
33
+ const canvas = paintedChannels("--background");
34
+ for (const [variable, role] of [
35
+ ["--background", "canvas"],
36
+ ["--card", "surface"],
37
+ ["--surface-raised", "surfaceRaised"],
38
+ ["--message-surface", "messageSurface"],
39
+ ] as const) {
40
+ const expected = toRgb(colors[role])!;
41
+ const painted = paintedChannels(variable, canvas);
42
+ [expected.r, expected.g, expected.b].forEach((channel, index) => {
43
+ expect(
44
+ Math.abs(channel * 255 - painted[index]!),
45
+ `${appearance} ${role}`,
46
+ ).toBeLessThan(1.5);
47
+ });
48
+ }
49
+ }
50
+ }
51
+ } finally {
52
+ root.removeAttribute("data-redesign");
53
+ root.classList.remove("dark");
54
+ }
55
+ });
56
+});
apps/web/src/themePalette.test.ts
+151
@@ -2,7 +2,11 @@ import { describe, expect, it, vi } from "vite-plus/test";
2
import { converter } from "culori/fn";
3
import { BUILT_IN_THEMES } from "@t3tools/shared/themePalettes";
4
5
+import { CONTEXT_CHIP_ACCENTS, contextChipColorVariable } from "./lib/contextChipAccents";
6
+
7
import {
8
+ applyThemePalette,
9
+ contextChipVariables,
10
getThemeColorsForMode,
11
getThemeModes,
12
getCustomThemes,
@@ -539,6 +543,153 @@ describe("theme files", () => {
543
});
544
});
545
546
+describe("context chip colors", () => {
547
+ it.each([
548
+ ["#ffffff", 5],
549
+ ["#777777", 4.5],
550
+ ] as const)(
551
+ "chooses readable chip lightness on %s when the text is medium gray",
552
+ (surface, minimum) => {
553
+ const colors = {
554
+ ...getStandardThemeColors("light"),
555
+ canvas: surface,
556
+ surface,
557
+ surfaceRaised: surface,
558
+ messageSurface: surface,
559
+ text: "#767676",
560
+ messageForeground: "#767676",
561
+ };
562
+ for (const color of Object.values(contextChipVariables(colors))) {
563
+ expect(contrastRatio(color, surface)).toBeGreaterThanOrEqual(minimum);
564
+ }
565
+ },
566
+ );
567
+
568
+ const toOklch = converter("oklch");
569
+ const toRgb = converter("rgb");
570
+ // Surfaces stay unrounded, as CSS paints them; the chip is the 8-bit hex the solver returns.
571
+ const paintedContrastRatio = (chip: string, surface: string, canvas: string) => {
572
+ const channels = (value: string) => {
573
+ const rgb = toRgb(value)!;
574
+ return [rgb.r, rgb.g, rgb.b].map((channel) => Math.min(1, Math.max(0, channel)));
575
+ };
576
+ const back = channels(canvas);
577
+ const alpha = toRgb(surface)!.alpha ?? 1;
578
+ const painted = channels(surface).map(
579
+ (channel, index) => back[index]! * (1 - alpha) + channel * alpha,
580
+ );
581
+ const luminance = (rgb: number[]) =>
582
+ rgb
583
+ .map((channel) =>
584
+ channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4,
585
+ )
586
+ .reduce((sum, channel, index) => sum + channel * [0.2126, 0.7152, 0.0722][index]!, 0);
587
+ const first = luminance(channels(asHex(chip)));
588
+ const second = luminance(painted);
589
+ return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
590
+ };
591
+ const palettes = [
592
+ getStandardThemeColors("light"),
593
+ getStandardThemeColors("dark"),
594
+ ...BUILT_IN_THEMES.flatMap((theme) =>
595
+ getThemeModes(theme).map((mode) => getThemeColorsForMode(theme, mode)!),
596
+ ),
597
+ ];
598
+
599
+ it("reads at 5:1 on every chip surface of every built-in theme and keeps each hue", () => {
600
+ for (const colors of palettes) {
601
+ const variables = contextChipVariables(colors);
602
+ expect(variables["--context-chip-message"]).toBeUndefined();
603
+ for (const [kind, accent] of Object.entries(CONTEXT_CHIP_ACCENTS)) {
604
+ const chip =
605
+ variables[contextChipColorVariable(kind as keyof typeof CONTEXT_CHIP_ACCENTS)]!;
606
+ for (const surface of [
607
+ colors.canvas,
608
+ colors.surface,
609
+ colors.surfaceRaised,
610
+ colors.messageSurface,
611
+ ]) {
612
+ expect(paintedContrastRatio(chip, surface, colors.canvas)).toBeGreaterThanOrEqual(5);
613
+ }
614
+ const solved = toOklch(chip)!;
615
+ if ((solved.c ?? 0) > 0.04) {
616
+ const drift = Math.abs((((solved.h ?? 0) - toOklch(accent)!.h! + 540) % 360) - 180);
617
+ expect(drift).toBeLessThan(4);
618
+ }
619
+ }
620
+ }
621
+ });
622
+
623
+ it("reads at 5:1 on the standard surfaces as index.css paints them", () => {
624
+ const painted = {
625
+ light: ["#fcfcfc", "#ffffff", "#ebebed"],
626
+ dark: ["#000000", "#0a0a0a", "#111111", "#141414", "#1e1e1e"],
627
+ } as const;
628
+ const properties = new Map<string, string>();
629
+ vi.stubGlobal("window", { localStorage: { getItem: () => null } });
630
+ vi.stubGlobal("document", {
631
+ documentElement: {
632
+ dataset: {},
633
+ style: {
634
+ setProperty: (name: string, value: string) => properties.set(name, value),
635
+ removeProperty: (name: string) => properties.delete(name),
636
+ },
637
+ },
638
+ });
639
+ invalidateCustomThemes();
640
+ try {
641
+ for (const appearance of ["light", "dark"] as const) {
642
+ applyThemePalette("system", appearance);
643
+ for (const kind of Object.keys(CONTEXT_CHIP_ACCENTS) as Array<
644
+ keyof typeof CONTEXT_CHIP_ACCENTS
645
+ >) {
646
+ for (const surface of painted[appearance]) {
647
+ expect(
648
+ contrastRatio(properties.get(contextChipColorVariable(kind))!, surface),
649
+ ).toBeGreaterThanOrEqual(5);
650
+ }
651
+ }
652
+ }
653
+ } finally {
654
+ vi.unstubAllGlobals();
655
+ invalidateCustomThemes();
656
+ }
657
+ });
658
+
659
+ it("solves the invalid state's error color to 5:1 on every chip surface", () => {
660
+ for (const colors of palettes) {
661
+ const invalid = contextChipVariables(colors)["--context-chip-invalid"];
662
+ expect(invalid).toBeDefined();
663
+ for (const surface of [
664
+ colors.canvas,
665
+ colors.surface,
666
+ colors.surfaceRaised,
667
+ colors.messageSurface,
668
+ ]) {
669
+ expect(paintedContrastRatio(invalid!, surface, colors.canvas)).toBeGreaterThanOrEqual(5);
670
+ }
671
+ }
672
+ });
673
+
674
+ it("leaves a bubble with opposite-shade text out of the shared solve", () => {
675
+ const colors = {
676
+ ...getStandardThemeColors("light"),
677
+ messageSurface: "#1b4ed8",
678
+ messageForeground: "#ffffff",
679
+ };
680
+ const variables = contextChipVariables(colors);
681
+ expect(variables["--context-chip-message"]).toBe("#ffffff");
682
+ for (const kind of Object.keys(CONTEXT_CHIP_ACCENTS) as Array<
683
+ keyof typeof CONTEXT_CHIP_ACCENTS
684
+ >) {
685
+ expect(
686
+ contrastRatio(variables[contextChipColorVariable(kind)]!, colors.canvas),
687
+ ).toBeGreaterThanOrEqual(5);
688
+ }
689
+ expect(toOklch(variables[contextChipColorVariable("file")])!.c).toBeGreaterThan(0.08);
690
+ });
691
+});
692
+
693
describe("stored theme preferences", () => {
694
it("lets a configured half unlock an appearance the base theme lacks", () => {
695
const lightOnly = parseThemeFile({
apps/web/src/themePalette.ts
+95
-15
@@ -22,6 +22,11 @@ import {
22
type ThemeDefinition,
23
type ThemeVariants,
24
} from "@t3tools/shared/themePalettes";
25
+import {
26
+ CONTEXT_CHIP_ACCENTS,
27
+ contextChipColorVariable,
28
+ type ContextChipAccentKind,
29
+} from "./lib/contextChipAccents";
30
31
import { appAtomRegistry, subscribeAtomChanges } from "./rpc/atomRegistry";
32
import { primaryServerEnvironmentThemesAtom } from "./state/server";
@@ -395,6 +400,24 @@ export function getStandardThemeColors(appearance: ThemeAppearance): ThemeColors
400
return (standardLightThemeColors ??= decodeThemeColors(T3_CODE_LIGHT_THEME_COLORS));
401
}
402
403
+// index.css paints the light bubble a step darker than the shared palette mobile uses.
404
+const STANDARD_WEB_PAINTED_COLORS: Record<ThemeAppearance, Partial<ThemeColors>> = {
405
+ light: { messageSurface: "#ebebed" },
406
+ dark: {},
407
+};
408
+
409
+/** The standard theme as index.css paints it, for solves that measure the page. */
410
+export function getStandardPaintedThemeColors(
411
+ appearance: ThemeAppearance,
412
+ redesign = false,
413
+): ThemeColors {
414
+ return {
415
+ ...getStandardThemeColors(appearance),
416
+ ...STANDARD_WEB_PAINTED_COLORS[appearance],
417
+ ...(redesign && appearance === "dark" ? { canvas: "#000000", messageSurface: "#1e1e1e" } : {}),
418
+ };
419
+}
420
+
421
type ThemeRgbColor = {
422
r: number;
423
g: number;
@@ -541,9 +564,10 @@ function srgbChannelToLinear(channel: number): number {
564
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
565
}
566
544
-function linearChannelToSrgb(channel: number): number {
567
+function linearChannelToSrgb(channel: number, round = true): number {
568
const c = channel <= 0.0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - 0.055;
546
- return Math.round(Math.min(1, Math.max(0, c)) * 255);
569
+ const srgb = Math.min(1, Math.max(0, c)) * 255;
570
+ return round ? Math.round(srgb) : srgb;
571
}
572
573
function themeRgbToOklch(color: ThemeRgbColor): ThemeOklch {
@@ -597,12 +621,12 @@ function mapThemeOklchToSrgbGamut(color: ThemeOklch): ThemeOklch {
621
return { ...color, C: low };
622
}
623
600
-function themeOklchToRgb(color: ThemeOklch): ThemeRgbColor {
624
+function themeOklchToRgb(color: ThemeOklch, round = true): ThemeRgbColor {
625
const linear = oklchToRgbUnclamped(mapThemeOklchToSrgbGamut(color));
626
return {
603
- r: linearChannelToSrgb(linear.r),
604
- g: linearChannelToSrgb(linear.g),
605
- b: linearChannelToSrgb(linear.b),
627
+ r: linearChannelToSrgb(linear.r, round),
628
+ g: linearChannelToSrgb(linear.g, round),
629
+ b: linearChannelToSrgb(linear.b, round),
630
};
631
}
632
@@ -612,19 +636,20 @@ function themeOklchToThemeColor(color: ThemeOklch): string {
636
637
function solveOklchLightness(
638
base: ThemeOklch,
615
- against: ThemeRgbColor,
639
+ against: ReadonlyArray<ThemeRgbColor>,
640
minContrast: number,
641
direction: "lighter" | "darker",
642
): ThemeOklch {
643
+ const contrastOf = (color: ThemeOklch) =>
644
+ Math.min(...against.map((surface) => themeContrastRatio(themeOklchToRgb(color), surface)));
645
let low = direction === "lighter" ? base.L : 0;
646
let high = direction === "lighter" ? 1 : base.L;
647
let candidate = { ...base };
622
- if (themeContrastRatio(themeOklchToRgb(candidate), against) >= minContrast) return candidate;
648
+ if (contrastOf(candidate) >= minContrast) return candidate;
649
for (let step = 0; step < 18; step += 1) {
650
const mid = (low + high) / 2;
651
candidate = { ...base, L: mid };
626
- const contrast = themeContrastRatio(themeOklchToRgb(candidate), against);
627
- if (contrast >= minContrast) {
652
+ if (contrastOf(candidate) >= minContrast) {
653
if (direction === "lighter") high = mid;
654
else low = mid;
655
} else {
@@ -648,12 +673,63 @@ export function readableThemeColorOn(color: string, surface: string, minContrast
673
return color;
674
}
675
const direction = themeRelativeLuminance(surfaceRgb) < 0.179 ? "lighter" : "darker";
651
- const solved = solveOklchLightness(parsedColor.color, surfaceRgb, minContrast, direction);
676
+ const solved = solveOklchLightness(parsedColor.color, [surfaceRgb], minContrast, direction);
677
// Return the 8-bit color the solver measured: the unrounded OKLCH can round
678
// to a neighbor just under the target once it is stored and read back.
679
return themeRgbToHexColor(themeOklchToRgb(solved));
680
}
681
682
+const CONTEXT_CHIP_CONTRAST = 5;
683
+const CONTEXT_CHIP_MESSAGE_VARIABLE = "--context-chip-message";
684
+const CONTEXT_CHIP_INVALID_VARIABLE = "--context-chip-invalid";
685
+
686
+export function contextChipVariables(colors: ThemeColors): Readonly<Record<string, string>> {
687
+ // CSS paints surfaces from their unrounded OKLCH, so measure them unrounded.
688
+ const parsedCanvas = parseThemeColor(colors.canvas);
689
+ const canvas = parsedCanvas ? themeOklchToRgb(parsedCanvas.color, false) : THEME_WHITE_FOREGROUND;
690
+ const onCanvas = (value: string) => {
691
+ const parsed = parseThemeColor(value);
692
+ return parsed
693
+ ? mixThemeRgbColors(canvas, themeOklchToRgb(parsed.color, false), parsed.alpha)
694
+ : canvas;
695
+ };
696
+ const isDark = (color: ThemeRgbColor) => themeRelativeLuminance(color) < 0.179;
697
+ const messageMatchesCanvas = isDark(onCanvas(colors.messageSurface)) === isDark(canvas);
698
+ const surfaces = [canvas, onCanvas(colors.surface), onCanvas(colors.surfaceRaised)];
699
+ if (messageMatchesCanvas) surfaces.push(onCanvas(colors.messageSurface));
700
+ const contrastOnSurfaces = (color: ThemeRgbColor) =>
701
+ Math.min(...surfaces.map((surface) => themeContrastRatio(color, surface)));
702
+ const blackContrast = contrastOnSurfaces(THEME_BLACK_FOREGROUND);
703
+ const whiteContrast = contrastOnSurfaces(THEME_WHITE_FOREGROUND);
704
+ const direction = blackContrast >= whiteContrast ? "darker" : "lighter";
705
+ const minContrast = Math.min(CONTEXT_CHIP_CONTRAST, Math.max(blackContrast, whiteContrast));
706
+ const accents: Array<[string, string]> = [
707
+ ...(Object.entries(CONTEXT_CHIP_ACCENTS) as Array<[ContextChipAccentKind, string]>).map(
708
+ ([kind, accent]): [string, string] => [contextChipColorVariable(kind), accent],
709
+ ),
710
+ [CONTEXT_CHIP_INVALID_VARIABLE, colors.errorForeground],
711
+ ];
712
+ const variables: Record<string, string> = Object.fromEntries(
713
+ accents.flatMap(([variable, accent]) => {
714
+ const parsed = parseThemeColor(accent);
715
+ if (!parsed) return [];
716
+ const solved = solveOklchLightness(parsed.color, surfaces, minContrast, direction);
717
+ return [[variable, themeRgbToHexColor(themeOklchToRgb(solved))]];
718
+ }),
719
+ );
720
+ if (!messageMatchesCanvas) variables[CONTEXT_CHIP_MESSAGE_VARIABLE] = colors.messageForeground;
721
+ return variables;
722
+}
723
+
724
+function applyContextChipVariables(root: HTMLElement, colors: ThemeColors): void {
725
+ const variables = contextChipVariables(colors);
726
+ root.style.removeProperty(CONTEXT_CHIP_MESSAGE_VARIABLE);
727
+ root.style.removeProperty(CONTEXT_CHIP_INVALID_VARIABLE);
728
+ for (const [variable, value] of Object.entries(variables)) {
729
+ root.style.setProperty(variable, value);
730
+ }
731
+}
732
+
733
const STANDARD_STATUS_COLORS = {
734
light: {
735
error: "#fb2c36",
@@ -686,7 +762,7 @@ function standardStatusColors(canvas: ThemeRgbColor): {
762
themeOklchToThemeColor(
763
solveOklchLightness(
764
themeRgbToOklch(parseThemeRgbColor(foreground, canvas)),
689
- surface,
765
+ [surface],
766
4.6,
767
appearance === "dark" ? "lighter" : "darker",
768
),
@@ -734,7 +810,7 @@ export function createVividThemeColors(
810
C: Math.min(0.035, accent.C * 0.25),
811
h: hue,
812
};
737
- const text = solveOklchLightness(textBase, canvasRgb, 7, dark ? "lighter" : "darker");
813
+ const text = solveOklchLightness(textBase, [canvasRgb], 7, dark ? "lighter" : "darker");
814
const textRgb = themeOklchToRgb(text);
815
const textMutedRgb = standardMutedThemeText(canvasRgb, textRgb);
816
@@ -768,7 +844,7 @@ export function createVividThemeColors(
844
845
const foregroundOn = (surfaceRgb: ThemeRgbColor): string =>
846
themeOklchToThemeColor(
771
- solveOklchLightness(textBase, surfaceRgb, 4.6, dark ? "lighter" : "darker"),
847
+ solveOklchLightness(textBase, [surfaceRgb], 4.6, dark ? "lighter" : "darker"),
848
);
849
const mutedForeground = themeRgbToThemeColor(readableThemeText(mutedRgb, textRgb, 1, 4.6));
850
const placeholder = themeRgbToThemeColor(readableThemeText(surfaceRaisedRgb, textRgb, 1, 4.6));
@@ -930,7 +1006,7 @@ export function updateThemeColorFamily(
1006
themeOklchToThemeColor(
1007
solveOklchLightness(
1008
parsedSelected.color,
933
- background,
1009
+ [background],
1010
4.6,
1011
themeRelativeLuminance(background) < 0.179 ? "lighter" : "darker",
1012
),
@@ -1532,6 +1608,7 @@ export function applyThemeColorPreview(colors: ThemeColors, appearance: ThemeApp
1608
for (const [role, value] of Object.entries(colors) as Array<[ThemeColorRole, string]>) {
1609
if (isThemeColor(value)) root.style.setProperty(APP_THEME_VARIABLES[role], value);
1610
}
1611
+ applyContextChipVariables(root, colors);
1612
setThemePreviewAppearance(appearance);
1613
}
1614
@@ -1551,6 +1628,7 @@ export function applyThemePalette(theme: ThemePreference, appearance?: ThemeAppe
1628
for (const [role, value] of Object.entries(colors) as Array<[ThemeColorRole, string]>) {
1629
root.style.setProperty(APP_THEME_VARIABLES[role], value);
1630
}
1631
+ applyContextChipVariables(root, colors);
1632
return;
1633
}
1634
@@ -1558,6 +1636,8 @@ export function applyThemePalette(theme: ThemePreference, appearance?: ThemeAppe
1636
for (const variable of Object.values(APP_THEME_VARIABLES)) {
1637
root.style.removeProperty(variable);
1638
}
1639
+ // The redesign's lighter dark bubble is the stricter surface, so this ink also covers legacy UI.
1640
+ applyContextChipVariables(root, getStandardPaintedThemeColors(appearance ?? "light", true));
1641
}
1642
1643
export function resolveThemeAppearance(
vite.config.ts
+3
-3
@@ -521,9 +521,9 @@ export default defineConfig({
521
"transition",
522
"rounded-[inherit]",
523
"gap-[0.33em]",
524
- "px-[0.5em]",
525
- "rounded-[0.5em]",
526
- "text-[0.86em]",
524
+ "gap-[0.2em]",
525
+ "leading-[normal]",
526
+ "underline-offset-[0.2em]",
527
"rounded-[25%]",
528
"text-[length:80cqh]",
529
"bg-[Highlight]",