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 citation: "text-current",
39} as const;
40
41/**
42 * Context kinds keep one restrained color identity in both composer and sent messages.
43 * Every accent shares a lightness so no kind reads heavier than another; only hue carries
44 * identity. Chroma is capped, then clamped to what each hue can hold in sRGB, which keeps
45 * the set inside the range the themes use for their own accents rather than above it.
46 */
47export const CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES = {
48 image: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_16)]`,
49 video: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_48)]`,
50 file: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.136_237)]`,
51 mention: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.11_215)]`,
52 terminal: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_163)]`,
53 element: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_70)]`,
54 "preview-annotation": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_70)]`,
55 "review-comment": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_292)]`,
56 "pull-request": `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_277)]`,
57 skill: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_322)]`,
58 citation: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_259)]`,
59} as const;
60
61export const PULL_REQUEST_INLINE_CHIP_TONE_CLASS_NAMES = {
62 open: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.134_163)]`,
63 draft: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.02_259)]`,
64 merged: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_292)]`,
65 closed: `${CONTEXT_INLINE_CHIP_TONE_CLASS_NAME} [--context-chip-accent:oklch(0.62_0.16_16)]`,
66 unknown: CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES["pull-request"],
67} as const;
68
69export const CHAT_INLINE_CHIP_LABEL_CLASS_NAME = "truncate leading-tight";
70
71export const COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME =
72 "block self-center truncate leading-tight select-none";
73
74export 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}`;
75
76export 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>`;
77
78export const COMPOSER_INLINE_CHIP_DISMISS_BUTTON_CLASS_NAME =
79 "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";
80
81/** Keeps both the recognizable beginning and the extension/end of a long attachment name. */
82export function middleTruncateAttachmentName(name: string, maxCharacters = 36): string {
83 const characters = Array.from(name);
84 if (characters.length <= maxCharacters) return name;
85 if (maxCharacters <= 0) return "";
86 if (maxCharacters === 1) return "…";
87 const available = maxCharacters - 1;
88 const suffixLength = Math.min(available - 1, available >= 18 ? 14 : Math.ceil(available / 2));
89 const prefixLength = available - suffixLength;
90 const suffix = suffixLength === 0 ? "" : characters.slice(-suffixLength).join("");
91 return `${characters.slice(0, prefixLength).join("")}…${suffix}`;
92}