Skip to content

Commit e279076

Browse files
authored
fix(ui): carapace follow-ups — embed font stacks, data-theme-resolved, undefined status tokens (#113724)
* feat(ui): publish carapace embed font stacks to MCP apps Adopt the carapace embed contract's sandbox-safe font stacks: publish --font-sans for the first time and switch --font-mono from the host's JetBrains-led token to the embed mono stack. Both are static, system- resolvable values byte-identical to carapace candidate/embed.css, since the sandbox font-src policy silently drops brand faces. * feat(ui): emit data-theme-resolved alongside theme attributes Carapace CSS selects on [data-theme-resolved]; keep it in lockstep with data-theme-mode at boot (index.html IIFE) and on every runtime theme change (bootstrap publish path). Rename applyStartupPresentation to applyThemePresentation: it runs on every theme change, not just startup. * fix(ui): resolve undefined --success/--warning tokens and drop dead hex fallbacks --success and --warning were never defined (real tokens: --ok/--warn), so sites with literal fallbacks rendered off-palette one-off colors and sites without them silently dropped declarations (invalid color-mix in the chat sidebar warn banner). Map all uses to the semantic tokens across board, chat sidebar/layout, layout, and components styles, and strip the stale dead var() hex fallbacks in these global stylesheets. Code-syntax palette hexes in the file view are documented as deliberate.
1 parent dd60679 commit e279076

9 files changed

Lines changed: 161 additions & 150 deletions

File tree

‎ui/index.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
? "light"
6363
: "dark";
6464
document.documentElement.setAttribute("data-theme", resolved);
65-
document.documentElement.setAttribute(
66-
"data-theme-mode",
67-
resolved.includes("light") ? "light" : "dark",
68-
);
65+
var resolvedMode = resolved.includes("light") ? "light" : "dark";
66+
document.documentElement.setAttribute("data-theme-mode", resolvedMode);
67+
// Carapace CSS selects on [data-theme-resolved]; keep in lockstep.
68+
document.documentElement.setAttribute("data-theme-resolved", resolvedMode);
6969
} catch (e) {}
7070
})();
7171
</script>

‎ui/src/app/bootstrap.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ function normalizeInitialApplicationLocation(
7676
};
7777
}
7878

79-
function applyStartupPresentation(settings: ReturnType<typeof loadSettings>): void {
79+
function applyThemePresentation(settings: ReturnType<typeof loadSettings>): void {
8080
if (typeof document === "undefined") {
8181
return;
8282
}
8383
const root = document.documentElement;
8484
const resolvedTheme = resolveTheme(settings.theme, settings.themeMode);
8585
root.dataset.theme = resolvedTheme;
8686
root.dataset.themeMode = resolvedTheme.endsWith("light") ? "light" : "dark";
87+
// Carapace CSS (openclaw/carapace) selects on [data-theme-resolved]; keep it
88+
// in lockstep with data-theme-mode so its stylesheets work unmodified here.
89+
root.dataset.themeResolved = root.dataset.themeMode;
8790
root.classList.toggle("wa-light", root.dataset.themeMode === "light");
8891
root.classList.toggle("wa-dark", root.dataset.themeMode === "dark");
8992
root.style.colorScheme = root.dataset.themeMode;
@@ -99,7 +102,7 @@ function createApplicationTheme(
99102
const listeners = new Set<() => void>();
100103

101104
const publish = () => {
102-
applyStartupPresentation(settings);
105+
applyThemePresentation(settings);
103106
for (const listener of listeners) {
104107
listener();
105108
}
@@ -328,7 +331,7 @@ export function bootstrapApplication(): ApplicationRuntime {
328331
const webPush = createWebPushCapability(gateway);
329332
const skillWorkshopRevision = createSkillWorkshopRevisionHandoff();
330333
const initialUserMessage = createInitialUserMessageHandoff();
331-
applyStartupPresentation(settings);
334+
applyThemePresentation(settings);
332335
const router = createApplicationRouter();
333336
let pendingGatewayConnection =
334337
startup.pendingGatewayUrl !== null

‎ui/src/components/mcp-app-theme.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ describe("collectMcpAppStyleVariables", () => {
6666
);
6767

6868
// Font requests are limited to resource domains the app declares, so a
69-
// host-led webfont resolves to an arbitrary system face rather than
70-
// failing visibly. Apps own their sans stack until Control UI can supply
71-
// a sandbox-safe one.
72-
expect(variables).not.toHaveProperty("--font-sans");
73-
expect(variables?.["--font-mono"]).toContain("monospace");
69+
// host-led brand face resolves to an arbitrary system face rather than
70+
// failing visibly. The published stacks are the carapace embed stacks:
71+
// system resolvable, independent of the host's own font tokens.
72+
expect(variables?.["--font-sans"]).toMatch(/^system-ui,/);
73+
expect(variables?.["--font-sans"]).not.toContain("Inter");
74+
expect(variables?.["--font-mono"]).toMatch(/^ui-monospace,/);
75+
expect(variables?.["--font-mono"]).not.toContain("JetBrains");
7476
});
7577

7678
it("publishes trimmed, non-empty values", () => {

‎ui/src/components/mcp-app-theme.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ const HOST_TOKEN_SOURCES = {
3333
"--color-border-inverse": "--bg",
3434
"--color-ring-primary": "--ring",
3535

36-
/*
37-
* Only the monospace stack is published. Control UI's body font leads with a
38-
* webfont, and an embedded app cannot load it: the sandbox policy allows
39-
* font requests only from resource domains the app itself declares. Sending
40-
* it would resolve to an arbitrary system face instead of failing visibly.
41-
* The monospace stack degrades correctly because its fallbacks are system
42-
* faces. Apps supply their own sans stack until Control UI adopts the
43-
* carapace embed tokens, which define a sandbox-safe one.
44-
*/
45-
"--font-mono": "--mono",
46-
4736
"--font-text-xs-size": "--control-ui-text-xs",
4837
"--font-text-sm-size": "--control-ui-text-sm",
4938
"--font-text-md-size": "--control-ui-text-md",
@@ -61,13 +50,27 @@ const HOST_TOKEN_SOURCES = {
6150
"--shadow-lg": "--shadow-lg",
6251
} as const;
6352

64-
/** Values with no Control UI source, fixed by the specification's own scale. */
53+
/**
54+
* Values with no Control UI source, fixed by the specification's own scale or
55+
* the carapace embed contract.
56+
*
57+
* The font stacks are the carapace embed stacks (`--oc-font-embed-sans` /
58+
* `--oc-font-embed-mono`), sent in place of Control UI's own font tokens. The
59+
* sandbox policy allows font requests only from resource domains the app
60+
* itself declares, so a stack leading with a brand face would silently
61+
* resolve to an arbitrary system font; every family here is system
62+
* resolvable. Keep them byte-identical to carapace `candidate/embed.css`.
63+
*/
6564
const STATIC_VARIABLES = {
6665
"--border-width-regular": "1px",
6766
"--font-weight-normal": "400",
6867
"--font-weight-medium": "500",
6968
"--font-weight-semibold": "600",
7069
"--font-weight-bold": "700",
70+
"--font-sans":
71+
'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji"',
72+
"--font-mono":
73+
'ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',
7174
} as const;
7275

7376
type StyleVariableKey = keyof typeof HOST_TOKEN_SOURCES | keyof typeof STATIC_VARIABLES;

0 commit comments

Comments
 (0)