Open History to see the last commit
1// Chip metrics are in em so the pills scale with the text they sit in (the
2// composer honors the prompt font-size preference). The chat variant pins the
3// original 12px, where every em value resolves to the same pixels as before.
4const INLINE_CHIP_GEOMETRY_CLASS_NAME =
5 "inline-flex h-[1.41em] max-w-full items-center gap-[0.33em] rounded-[0.5em] px-[0.5em] font-medium leading-none align-middle";
6
7const INLINE_CHIP_CLASS_NAME = `${INLINE_CHIP_GEOMETRY_CLASS_NAME} border border-border/70 bg-accent/40 text-foreground`;
8
9const CONTEXT_INLINE_CHIP_TONE_CLASS_NAME =
10 "border-[color-mix(in_oklab,var(--context-chip-accent)_34%,var(--contrast-border))] bg-[color-mix(in_oklab,var(--context-chip-accent)_11%,transparent)] text-[color-mix(in_oklab,var(--context-chip-accent)_22%,var(--contrast-foreground))]";
11
12export const CHAT_INLINE_CHIP_CLASS_NAME = `${INLINE_CHIP_CLASS_NAME} text-[12px]`;
13
14export const COMPOSER_INLINE_CHIP_CLASS_NAME = `${INLINE_CHIP_CLASS_NAME} text-[0.86em] select-none`;
15
16export const COMPOSER_INLINE_CHIP_DECORATOR_CLASS_NAME =
17 "relative inline-flex 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-[6px] data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']";
18
19export const COMPOSER_INLINE_CHIP_ICON_CLASS_NAME =
20 "block size-[1.17em] shrink-0 self-center [&>svg]:block";
21
22export const CONTEXT_INLINE_CHIP_FOCUS_CLASS_NAME =
23 "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--contrast-foreground)]";
24
25export const CONTEXT_INLINE_CHIP_INTERACTIVE_CLASS_NAME = `transition-colors hover:border-[color-mix(in_oklab,var(--context-chip-accent)_48%,var(--contrast-border))] hover:bg-[color-mix(in_oklab,var(--context-chip-accent)_17%,transparent)] motion-reduce:transition-none ${CONTEXT_INLINE_CHIP_FOCUS_CLASS_NAME}`;
26
27export const CONTEXT_INLINE_CHIP_ICON_TONE_CLASS_NAMES = {
28 image: "text-current",
29 video: "text-current",
30 file: "text-current",
31 mention: "text-current",
32 terminal: "text-current",
33 element: "text-current",
34 "preview-annotation": "text-current",
35 "review-comment": "text-current",
36 "pull-request": "text-current",
37 skill: "text-current",
38 thread: "text-current",
39 citation: "text-current",
40} as const;
41
42/**
43 * Context kinds keep one restrained color identity in both composer and sent messages.
44 * Every accent shares a lightness so no kind reads heavier than another; only hue carries
45 * identity. Chroma is capped, then clamped to what each hue can hold in sRGB, which keeps
46 * the set inside the range the themes use for their own accents rather than above it.
47 */
48export const CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES = {
49 image: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_16)]`,
50 video: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_48)]`,
51 file: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.136_237)]`,
52 mention: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.11_215)]`,
53 terminal: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_163)]`,
54 element: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_70)]`,
55 "preview-annotation": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_70)]`,
56 "review-comment": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_292)]`,
57 "pull-request": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_277)]`,
58 skill: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_322)]`,
59 thread: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.12_190)]`,
60 citation: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_259)]`,
61} as const;
62
63export const PULL_REQUEST_INLINE_CHIP_TONE_CLASS_NAMES = {
64 open: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_163)]`,
65 draft: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.02_259)]`,
66 merged: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_292)]`,
67 closed: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_16)]`,
68 unknown: CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES["pull-request"],
69} as const;
70
71export const CHAT_INLINE_CHIP_LABEL_CLASS_NAME = "truncate leading-tight";
72
73export const COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME =
74 "block self-center truncate leading-tight select-none";
75
76export const COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME = `${INLINE_CHIP_GEOMETRY_CLASS_NAME} select-none border text-[0.86em] ${CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES.skill}`;
77
78export const SKILL_CHIP_ICON_SVG = `<svg width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>`;
79
80export const COMPOSER_INLINE_CHIP_DISMISS_BUTTON_CLASS_NAME =
81 "ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/72 transition-colors hover:bg-foreground/6 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring";
82
83/** Keeps both the recognizable beginning and the extension/end of a long attachment name. */
84export function middleTruncateAttachmentName(name: string, maxCharacters = 36): string {
85 const characters = Array.from(name);
86 if (characters.length <= maxCharacters) return name;
87 if (maxCharacters <= 0) return "";
88 if (maxCharacters === 1) return "…";
89 const available = maxCharacters - 1;
90 const suffixLength = Math.min(available - 1, available >= 18 ? 14 : Math.ceil(available / 2));
91 const prefixLength = available - suffixLength;
92 const suffix = suffixLength === 0 ? "" : characters.slice(-suffixLength).join("");
93 return `${characters.slice(0, prefixLength).join("")}…${suffix}`;
94}