Open History to see the last commit
1import { THEME_COLOR_ROLES } from "./themePalettes.ts";
2
3const FETCHES_BY_STRING = /image-set\(|\bsrc\(/i;
4// Only CSS whitespace may come first. \s also matches U+00A0, which makes the address relative.
5const URL_NOT_LOCAL = /url\((?![ \t\n\f\r]*["']?(?:data:|#))/i;
6
7/**
8 * Whether one declaration value can load a remote file. Clients drop those declarations.
9 * A value with var() stays unparsed until use, and an escape can spell `var` or `url` in it,
10 * so every value that still has a backslash is refused.
11 */
12export function themeCssValueFetches(value: string): boolean {
13 return value.includes("\\") || FETCHES_BY_STRING.test(value) || URL_NOT_LOCAL.test(value);
14}
15
16/** A text check for early feedback. CSS escapes can dodge it; the client check is the guard. */
17export function themeCssLoadsRemoteFiles(css: string): boolean {
18 const code = css.replace(/\/\*[\s\S]*?\*\//g, "");
19 return /@import/i.test(code) || FETCHES_BY_STRING.test(code) || URL_NOT_LOCAL.test(code);
20}
21
22/**
23 * Selectors that theme CSS may rely on. Other class names are Tailwind utilities and change
24 * between releases. themeCss.test.ts in apps/web fails when one of these leaves the source.
25 */
26export const THEME_CSS_HOOKS = [
27 { selector: '[data-slot="sidebar"]', styles: "app sidebar" },
28 { selector: '[data-slot="sidebar-inner"]', styles: "sidebar surface" },
29 { selector: "[data-thread-item]", styles: "sidebar thread row" },
30 {
31 selector: '[data-slot="project-monogram"]',
32 styles: "project icon with letters; its svg holds the tile",
33 },
34 { selector: "[data-chat-header]", styles: "chat header" },
35 { selector: '[data-workspace-area="conversation"]', styles: "chat area, behind the messages" },
36 { selector: ".messages-timeline-scroll", styles: "chat scroller" },
37 { selector: "[data-timeline-row-kind]", styles: 'chat row, such as ="message" or ="work"' },
38 { selector: '[data-message-role="user"]', styles: "user message row" },
39 { selector: "[data-user-message-bubble]", styles: "user message bubble" },
40 { selector: '[data-message-role="assistant"]', styles: "assistant message row" },
41 { selector: ".chat-markdown", styles: "assistant text" },
42 { selector: ".chat-markdown-codeblock", styles: "code block" },
43 { selector: "[data-chat-composer-form]", styles: "composer" },
44 { selector: '[data-slot="composer-host"]', styles: "composer card" },
45 { selector: ".composer-tiptap", styles: "composer text" },
46 { selector: "[data-thread-details-card]", styles: "thread details card" },
47 { selector: "[data-thread-terminal-drawer]", styles: "terminal drawer" },
48 { selector: "[data-settings-page-scroll]", styles: "settings page" },
49 { selector: '[data-slot="button"]', styles: "button" },
50 { selector: '[data-slot="input"]', styles: "text input" },
51 { selector: '[data-slot="switch"]', styles: "switch" },
52 { selector: '[data-slot="select-trigger"]', styles: "select" },
53 { selector: '[data-slot="dialog-popup"]', styles: "dialog" },
54 { selector: '[data-slot="popover-popup"]', styles: "popover" },
55 { selector: '[data-slot="menu-popup"]', styles: "menu" },
56 { selector: '[data-slot="tooltip-popup"]', styles: "tooltip" },
57 { selector: '[data-slot="scroll-area-scrollbar"]', styles: "overlay scrollbar" },
58 { selector: '[data-slot="scroll-area-thumb"]', styles: "overlay scrollbar thumb" },
59] as const;
60
61/** What an agent needs to restyle the app. `t3_theme_read` returns it. */
62export const THEME_GUIDE = [
63 "Themes restyle T3 Code on web and desktop. Mobile does not use them.",
64 "",
65 "Colors: `canvas` and `accent` (hex) derive a full palette. `colors` overrides single roles, and `variants.light` or `variants.dark` does that for the other appearance. Prefer colors over CSS.",
66 `Roles: ${THEME_COLOR_ROLES.join(", ")}.`,
67 "",
68 "CSS: `css` applies after the app's styles. Use `.dark` or `:root:not(.dark)` for one appearance.",
69 "It cannot load files: no @import, no image-set(), and url() only with data: or #id.",
70 "A background image must be embedded as a data: address. `css` holds 20,000 characters, so keep the image near 10 KB.",
71 "The app's own rules can be more specific. If a rule has no effect, add !important.",
72 "It cannot reach the terminal text, the file tree, or diff internals. Use color roles for those.",
73 "Native scrollbars take `::-webkit-scrollbar` and `::-webkit-scrollbar-thumb`.",
74 "Icons are `svg.lucide`. stroke-width, stroke-linecap, and stroke-linejoin restyle them.",
75 "",
76 "Stable selectors (other class names change between releases, so do not use them):",
77 ...THEME_CSS_HOOKS.map((hook) => `- ${hook.selector}: ${hook.styles}`),
78 "",
79 "You cannot see the result. Make small changes, then ask the user how it looks.",
80 "To undo, set a built-in theme: t3-chat, grove, ocean, ember, or iris.",
81].join("\n");