frontend: light-theme terminal contrast, theme before first paint, color-scheme, motion and focus defaults
Light theme: the terminal and code blocks sat on --crust, a mid grey there, so text was 2:1 to 3:1. They now use --code-bg, which keeps 95% of a light palette's background (58% of the dark one's, as before); scrims and shadows keep --crust. Dark --muted goes from 4.44:1 to 4.72:1 on --bg. The stored theme and motion overrides are set by a blocking boot script in the head (the page allows no inline script), so a light OS no longer paints light before the dark default; a test keeps its keys in step with the shell. color-scheme follows the palette, so native controls and scrollbars match a forced theme. Five infinite animations (dashboard banner, container icon, pending badge, warn banner, spinner) now honour reduced motion and the in-app motion setting, ConnectionDot uses the same three-rule shape as the others, and the hive-warn element honours the system preference. Keyboard focus gets a default ring, and the cancel button and pane divider keep a visible one.
This commit is contained in:
parent
16260108ee
commit
3d88108c4f
8 changed files with 257 additions and 23 deletions
|
|
@ -121,6 +121,24 @@ const hashedCssResult = await build({
|
|||
const themeCssUrl = toUrl(outputFor(hashedCssResult, src("theme.css"))[0]);
|
||||
const swarmUiCssUrl = toUrl(outputFor(hashedCssResult, src("swarm-ui.css"))[0]);
|
||||
|
||||
// theme-boot.js: the stored theme and motion overrides, set before first
|
||||
// paint by a blocking script in the head (the page's policy allows no inline
|
||||
// script). Hashed like the rest.
|
||||
const bootResult = await build({
|
||||
absWorkingDir: here,
|
||||
entryPoints: [src("theme-boot.js")],
|
||||
outdir: staticDir(""),
|
||||
entryNames: "[name]-[hash]",
|
||||
bundle: true,
|
||||
format: "iife",
|
||||
platform: "browser",
|
||||
target: ["es2022"],
|
||||
minify: true,
|
||||
logLevel: "info",
|
||||
metafile: true,
|
||||
});
|
||||
const themeBootUrl = toUrl(outputFor(bootResult, src("theme-boot.js"))[0]);
|
||||
|
||||
// colors.css: fixed, unhashed path — see the top comment.
|
||||
await build({
|
||||
absWorkingDir: here,
|
||||
|
|
@ -137,7 +155,15 @@ await build({
|
|||
// makes the SW's own `activate` handler evict the old cache in full —
|
||||
// no more hand-bumping a CACHE_VERSION const on every shell change.
|
||||
const buildVersion = createHash("sha256")
|
||||
.update(JSON.stringify([mainJsUrl, mainCssUrl, themeCssUrl, swarmUiCssUrl]))
|
||||
.update(
|
||||
JSON.stringify([
|
||||
mainJsUrl,
|
||||
mainCssUrl,
|
||||
themeCssUrl,
|
||||
swarmUiCssUrl,
|
||||
themeBootUrl,
|
||||
]),
|
||||
)
|
||||
.digest("hex")
|
||||
.slice(0, 12);
|
||||
|
||||
|
|
@ -146,7 +172,8 @@ const rewriteAssetUrls = (text) =>
|
|||
.replaceAll("/static/main.js", mainJsUrl)
|
||||
.replaceAll("/static/main.css", mainCssUrl)
|
||||
.replaceAll("/static/theme.css", themeCssUrl)
|
||||
.replaceAll("/static/swarm-ui.css", swarmUiCssUrl);
|
||||
.replaceAll("/static/swarm-ui.css", swarmUiCssUrl)
|
||||
.replaceAll("/static/theme-boot.js", themeBootUrl);
|
||||
|
||||
writeFileSync(
|
||||
dist("index.html"),
|
||||
|
|
|
|||
|
|
@ -30,12 +30,24 @@
|
|||
right: -0.2em;
|
||||
bottom: -0.2em;
|
||||
}
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.ui-conn-dot-connecting,
|
||||
.ui-conn-dot-reconnecting {
|
||||
animation: ui-conn-dot-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ui-conn-dot-connecting,
|
||||
.ui-conn-dot-reconnecting {
|
||||
animation: ui-conn-dot-pulse 1.2s ease-in-out infinite;
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
:root[data-motion="reduce"] .ui-conn-dot-connecting,
|
||||
:root[data-motion="reduce"] .ui-conn-dot-reconnecting {
|
||||
animation: none;
|
||||
}
|
||||
:root[data-motion="allow"] .ui-conn-dot-connecting,
|
||||
:root[data-motion="allow"] .ui-conn-dot-reconnecting {
|
||||
animation: ui-conn-dot-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes ui-conn-dot-pulse {
|
||||
50% {
|
||||
opacity: 0.45;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-title" content="swarm" />
|
||||
<link rel="apple-touch-icon" href="/icon-192.png" />
|
||||
<!-- Blocking on purpose: it sets the stored theme before the first paint. -->
|
||||
<script src="/static/theme-boot.js"></script>
|
||||
<link rel="stylesheet" href="/static/colors.css" />
|
||||
<link rel="stylesheet" href="/static/theme.css" />
|
||||
<link rel="stylesheet" href="/static/swarm-ui.css" />
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const SHELL_ASSETS = [
|
|||
"/static/colors.css",
|
||||
"/static/theme.css",
|
||||
"/static/swarm-ui.css",
|
||||
"/static/theme-boot.js",
|
||||
"/manifest.webmanifest",
|
||||
];
|
||||
|
||||
|
|
|
|||
22
frontend/packages/swarm-ui/src/theme-boot.js
Normal file
22
frontend/packages/swarm-ui/src/theme-boot.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Sets the stored theme and motion overrides on <html> before the first paint.
|
||||
// The app applies them again once it mounts (`useApplyThemeOverride`,
|
||||
// `useApplyMotionOverride`), but that is after the page has painted, so a light
|
||||
// OS showed a light flash before the dark default took over. This runs from a
|
||||
// blocking script in the head, as the page's policy allows no inline script. The
|
||||
// keys and the fallbacks ("dark" for the theme, "system" for motion) are those of
|
||||
// `shell/Shell.tsx`; `test/theme-boot.test.mjs` keeps them in step.
|
||||
(function () {
|
||||
function read(key, fallback) {
|
||||
try {
|
||||
var raw = localStorage.getItem(key);
|
||||
return raw === null ? fallback : JSON.parse(raw);
|
||||
} catch (e) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
var root = document.documentElement;
|
||||
var theme = read("swarm-ui:theme-override", "dark");
|
||||
if (theme === "light" || theme === "dark") root.dataset.theme = theme;
|
||||
var motion = read("swarm-ui:motion-override", "system");
|
||||
if (motion === "reduce" || motion === "allow") root.dataset.motion = motion;
|
||||
})();
|
||||
|
|
@ -35,7 +35,10 @@
|
|||
.ui-pane-divider:hover,
|
||||
.ui-pane-divider:focus-visible {
|
||||
background: var(--purple);
|
||||
outline: none;
|
||||
}
|
||||
.ui-pane-divider:focus-visible {
|
||||
outline: 2px solid var(--purple);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
/* The half of a pane a drop would take, lit while an agent is dragged over. */
|
||||
.ui-pane-drop-zone {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
overflow: auto;
|
||||
border: 1px solid var(--border, currentColor);
|
||||
border-radius: 0.4em;
|
||||
background: color-mix(in srgb, var(--crust) 60%, transparent);
|
||||
background: color-mix(in srgb, var(--code-bg) 60%, transparent);
|
||||
font-family: var(--mono, ui-monospace, monospace);
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
|
|
|||
69
frontend/packages/swarm-ui/test/theme-boot.test.mjs
Normal file
69
frontend/packages/swarm-ui/test/theme-boot.test.mjs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// The boot script that sets the stored theme and motion overrides before the
|
||||
// first paint: what it sets for each stored value, and that its keys are the
|
||||
// ones the shell reads. Run by `npm test`.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { test } from "node:test";
|
||||
import vm from "node:vm";
|
||||
|
||||
const script = readFileSync(
|
||||
new URL("../src/theme-boot.js", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const shell = readFileSync(
|
||||
new URL("../src/shell/Shell.tsx", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
function boot(stored) {
|
||||
const dataset = {};
|
||||
const localStorage = {
|
||||
getItem: (key) => (key in stored ? stored[key] : null),
|
||||
};
|
||||
vm.runInNewContext(script, {
|
||||
localStorage,
|
||||
document: { documentElement: { dataset } },
|
||||
});
|
||||
return dataset;
|
||||
}
|
||||
|
||||
test("nothing stored sets the dark default and leaves motion to the system", () => {
|
||||
assert.deepEqual(boot({}), { theme: "dark" });
|
||||
});
|
||||
|
||||
test("a stored light theme and a motion override are set", () => {
|
||||
const set = boot({
|
||||
"swarm-ui:theme-override": '"light"',
|
||||
"swarm-ui:motion-override": '"reduce"',
|
||||
});
|
||||
assert.deepEqual(set, { theme: "light", motion: "reduce" });
|
||||
});
|
||||
|
||||
test("system leaves the attribute off, so the media query decides", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"system"' }), {});
|
||||
});
|
||||
|
||||
test("a value that is not JSON, or not one of the choices, is ignored", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": "light" }), {
|
||||
theme: "dark",
|
||||
});
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"blue"' }), {});
|
||||
});
|
||||
|
||||
test("storage that throws behaves as if nothing were stored", () => {
|
||||
const dataset = {};
|
||||
vm.runInNewContext(script, {
|
||||
localStorage: {
|
||||
getItem() {
|
||||
throw new Error("blocked");
|
||||
},
|
||||
},
|
||||
document: { documentElement: { dataset } },
|
||||
});
|
||||
assert.deepEqual(dataset, { theme: "dark" });
|
||||
});
|
||||
|
||||
test("the keys are the shell's", () => {
|
||||
assert.match(shell, /THEME_KEY = "swarm-ui:theme-override"/);
|
||||
assert.match(shell, /MOTION_KEY = "swarm-ui:motion-override"/);
|
||||
});
|
||||
Loading…
Reference in a new issue