frontend: remove the stylix overlay and add hyperhive and Catppuccin light and dark themes
This commit is contained in:
parent
989d1d578c
commit
91e2d26133
29 changed files with 486 additions and 413 deletions
|
|
@ -28,7 +28,7 @@ A service module declares its vhost as `services.hyperhive.gateway.vhosts.<name>
|
|||
|
||||
| URL | upstream | when |
|
||||
| --- | --- | --- |
|
||||
| `<name>.hives.<swarm>/` | dashboard dist (static, from `servedFrontend`), behind authelia | always |
|
||||
| `<name>.hives.<swarm>/` | dashboard dist (static, from `frontend`), behind authelia | always |
|
||||
| `<name>.hives.<swarm>/api/` | hive-c0re (`7000`), behind authelia | always |
|
||||
| `<name>.hives.<swarm>/health/` | hive-c0re (`7000`) | always |
|
||||
| `<name>.hives.<swarm>/api/docs/` | themed Swagger UI dist (static), behind authelia | always |
|
||||
|
|
@ -278,7 +278,7 @@ hive-c0re serves exactly two prefixes, so the dashboard routes by **path** — d
|
|||
|
||||
- `location /api/` → hive-c0re (`7000`): all dashboard data, actions, and the SSE stream (`/api/dashboard/stream`). `proxy_buffering off` and a 1d read timeout keep the stream live.
|
||||
- `location /health/` → hive-c0re: liveness and readiness.
|
||||
- `location /` → the dashboard dist (from the `servedFrontend` nix-store path) with `try_files $uri /index.html`.
|
||||
- `location /` → the dashboard dist (from the `frontend` nix-store path) with `try_files $uri /index.html`.
|
||||
|
||||
The gateway static-serves the dist while hive-c0re stays API-only, so a frontend-only change doesn't restart the core daemon. A new top-level c0re route prefix needs a matching `location` on the dashboard vhost (`hive-c0re/vhosts.nix`).
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ c0re process never leaves a partial or unparseable file behind.
|
|||
### Per-agent static frontend split
|
||||
|
||||
hive-c0re's environment sets `HIVE_AGENT_FRONTEND_DIR` to the `agent/`
|
||||
subdirectory of `services.hyperhive.deploy.hive-controller.servedFrontend`.
|
||||
subdirectory of `services.hyperhive.deploy.hive-controller.frontend`.
|
||||
The nginx include generator (`gateway_nginx::write`) reads
|
||||
this variable and, when set, emits split location blocks per agent
|
||||
instead of a single proxy block.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
# CSS custom properties (theme variables)
|
||||
|
||||
Colour variables live in **two standalone stylesheets**, split so a theme
|
||||
swap touches only the first:
|
||||
Colour variables live in **two standalone stylesheets**, split so a new theme
|
||||
touches only the first:
|
||||
|
||||
1. **`colors.css`** — the 16 `--base00`…`--base0F` base16 slots. **This is
|
||||
the entire theme swap contract.** A generator (for example one fed a stylix
|
||||
base16 scheme, which is natively base00–base0F) replaces _only this
|
||||
file_.
|
||||
the whole theme contract.** A theme is 16 colours here and nothing else.
|
||||
2. **`theme.css`** — the semantic layer: `--bg`, `--fg`, `--purple`, …
|
||||
_derived_ from the base16 slots (`--bg: var(--base00)` etc.). This is
|
||||
what the app references and it **never changes on a swap**.
|
||||
what the app references and it **doesn't change per theme**.
|
||||
|
||||
Both files live in `frontend/packages/shared/src/`. Per-page stylesheets
|
||||
(`common.css`, `dashboard.css`, `agent.css`)
|
||||
|
|
@ -17,23 +15,35 @@ reference the **semantic** names and must **not** redeclare them or reach
|
|||
for the raw `--baseNN` slots directly. (`base.css` holds only the shared
|
||||
`body` typography — it references the palette but no longer defines it.)
|
||||
|
||||
`colors.css` declares each palette's 16 hex values exactly once —
|
||||
`--mocha-baseNN` (dark, Catppuccin Mocha) and `--latte-baseNN` (light,
|
||||
Catppuccin-Latte-derived; `base08`-`base0F` run darker than stock
|
||||
Latte to actually clear WCAG AA against how this app uses them — real
|
||||
contrast failures found in review, see the comment above those
|
||||
declarations in `colors.css` for the numbers and why). Everything else
|
||||
in the file just points the active `--baseNN` slot at one of those two
|
||||
raw palettes via `var()`, never a second copy of a hex value: an
|
||||
unconditional default (Mocha), a row gated behind `@media
|
||||
(prefers-color-scheme: light)` (Latte, the OS/browser-level default),
|
||||
and two `:root[data-theme='light'|'dark']` blocks a per-user override
|
||||
sets (swarm-ui's `SettingsMenu`) — an attribute selector always
|
||||
outranks the plain `:root` inside the media query, so the override wins
|
||||
regardless of the actual OS preference. Absent an override, the media
|
||||
query decides; that's what a client with no more specific theme
|
||||
decision gets (see "Theme swapping" below for how a stylix deployment
|
||||
supersedes all of this at once).
|
||||
`colors.css` declares each theme's 16 hex values exactly once, as
|
||||
`--<theme>-baseNN`, for five themes that are each light or dark:
|
||||
|
||||
| Theme | Id | Scheme | Palette |
|
||||
| ---------------------- | ------------------------ | ------ | ------------------------------------------------------------------ |
|
||||
| hyperhive light | `hyperhive-light` | light | Latte's neutrals, accents darker than stock to clear WCAG AA |
|
||||
| hyperhive dark | `hyperhive-dark` | dark | Mocha's neutrals, the light accents' hues lifted to suit a dark bg |
|
||||
| catppuccin latte mauve | `catppuccin-latte-mauve` | light | Catppuccin Latte as published |
|
||||
| catppuccin mocha mauve | `catppuccin-mocha-mauve` | dark | Catppuccin Mocha as published |
|
||||
| catppuccin mocha mara | `catppuccin-mocha-mara` | dark | Mocha with the accents mara picked |
|
||||
|
||||
The hyperhive light accents (`base08`-`base0F`) run darker than stock Latte
|
||||
because the stock ones fail contrast as badge text and as plain text; the
|
||||
comment above them in `colors.css` has the numbers. The hyperhive dark
|
||||
accents keep those hues and saturations and raise the lightness until each
|
||||
clears 6:1 against `base02`.
|
||||
|
||||
Everything else in the file points the active `--baseNN` slots at one of
|
||||
those raw palettes via `var()`, never a second copy of a hex value: an
|
||||
unconditional default (hyperhive dark), a block gated behind
|
||||
`@media (prefers-color-scheme: light)` (hyperhive light, the OS-level
|
||||
default), and one `:root[data-theme='<id>']` block per theme, which the
|
||||
settings menu's theme select sets. An attribute selector always outranks
|
||||
the plain `:root` inside the media query, so a picked theme wins whatever
|
||||
the OS prefers. The select's **auto** choice sets no `data-theme`, so the
|
||||
media query decides.
|
||||
`frontend/packages/shared/src/settings/themes.ts` lists the ids, labels and
|
||||
schemes; adding a theme is one entry there and one palette plus one block in
|
||||
`colors.css`.
|
||||
|
||||
Both are deliberately standalone, not `@import`ed into the page bundles:
|
||||
each package re-exports them (`src/{colors,theme}.css` →
|
||||
|
|
@ -139,26 +149,22 @@ color: var(--amber); /* warning / running */
|
|||
color: var(--green); /* ok */
|
||||
```
|
||||
|
||||
## Theme swapping — the base16 contract
|
||||
## Themes — the base16 contract
|
||||
|
||||
**The swap interface is `colors.css` — the 16 base16 slots, not the
|
||||
semantic names.** A theme generator (for example one reading a stylix base16
|
||||
scheme) overrides only `colors.css`; the semantic layer in `theme.css`
|
||||
derives everything else, so the whole UI re-themes with nothing else to
|
||||
template or regenerate. The base16 slot → semantic mapping is _internal_
|
||||
to `theme.css` (the "Derives from" column above) — a generator never
|
||||
needs to know the semantic var names, and `theme.css` + the page bundles stay
|
||||
untouched.
|
||||
**The theme interface is `colors.css` — the 16 base16 slots, not the
|
||||
semantic names.** The semantic layer in `theme.css` derives everything
|
||||
else, so a new theme needs nothing else to template or regenerate. The
|
||||
base16 slot → semantic mapping is _internal_ to `theme.css` (the "Derives
|
||||
from" column above): a theme never needs the semantic var names, and
|
||||
`theme.css` and the page bundles stay untouched.
|
||||
|
||||
**Two palettes, one contract.** `colors.css` ships both a dark default
|
||||
(Catppuccin Mocha, unconditional) and a light default (Catppuccin Latte,
|
||||
behind `@media (prefers-color-scheme: light)`), plus a per-user override
|
||||
path (`:root[data-theme]`) — a theme generator that overrides the file
|
||||
wholesale (for example the stylix path, which writes a single unconditional
|
||||
`:root` block with no media query, no `--mocha-*`/`--latte-*` vars, no
|
||||
`[data-theme]` blocks) supersedes all of it at once, same as today.
|
||||
**Five palettes, one contract.** `colors.css` ships the five themes in the
|
||||
table above, each light or dark, with hyperhive dark as the unconditional
|
||||
default and hyperhive light behind `@media (prefers-color-scheme: light)`.
|
||||
Each theme's block also sets `color-scheme` and the contrast shares of
|
||||
`theme.css` (`--muted-share` and friends) for its scheme.
|
||||
|
||||
`colors.css` base16 slot defaults (Catppuccin Mocha, dark default):
|
||||
`colors.css` base16 slots in the dark palettes (the values are Catppuccin Mocha's; hyperhive dark differs in `base08`-`base0F`):
|
||||
|
||||
| Slot | Default | Standard base16 role | Mapped to |
|
||||
| -------- | --------- | -------------------- | ---------------------------------------------------------- |
|
||||
|
|
@ -187,10 +193,8 @@ Notes for theme authors:
|
|||
`--muted`/`--subtext0` = `base05`↔`base00` blends). They still track a
|
||||
swap automatically; no generator action needed.
|
||||
- A standard Catppuccin base16 scheme uses **teal** for `base0C`;
|
||||
`colors.css` defaults it to **sky** (`#89dceb`) to preserve the historical
|
||||
accent. A
|
||||
stylix Catppuccin scheme will shift `--cyan` to teal — that's the
|
||||
operator's chosen scheme, working as intended.
|
||||
`colors.css` uses **sky** (`#89dceb` in Mocha) to keep the historical
|
||||
accent.
|
||||
- `base04`/`base06`/`base07` aren't consumed by a semantic var today;
|
||||
they're kept at their standard values so the 16-slot contract is
|
||||
complete (a partial scheme override still works).
|
||||
|
|
|
|||
|
|
@ -240,6 +240,13 @@ stream with an error status, the browser gives up and the badge reads
|
|||
**disconnected**. The **reconnect** button beside it opens the stream again, and
|
||||
the stream replays the rows. The message log card works the same way.
|
||||
|
||||
The settings menu in the header has a **theme** select: **auto**, which follows
|
||||
the OS and picks hyperhive light or hyperhive dark, then hyperhive light,
|
||||
hyperhive dark, catppuccin latte mauve, catppuccin mocha mauve and catppuccin
|
||||
mocha mara. Each theme is light or
|
||||
dark, and a pick beats the OS preference. The browser remembers the choice, and
|
||||
hyperhive dark applies until a user picks one. The hive dashboard's menu has the same select.
|
||||
|
||||
The settings menu in the header has a **hide developer details** toggle. It drops
|
||||
the muted debug rows (coalesced ticks, harness chatter) from every
|
||||
terminal, the preview and the tabs, and rows already on screen hide or show as
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ repeated here.
|
|||
generation, mainly for shape/elevation ideas. Colour is dynamic too —
|
||||
autoderived shades (mixing, lighter/darker) are fair game, same as
|
||||
Material's own approach — but every derived colour still traces back
|
||||
to the base16/stylix contract below, never an independent source.
|
||||
to the base16 contract below, never an independent source.
|
||||
|
||||
## Motion
|
||||
|
||||
|
|
@ -64,17 +64,16 @@ The mechanical contract (base16 slots, semantic vars, what a page's CSS
|
|||
is and isn't allowed to reference) lives in `docs/4-implementation/web-ui/css-vars.md` —
|
||||
read that for the how. This section is the _policy_ layered on top:
|
||||
|
||||
- **User-theming compatible by construction.** The whole point of the
|
||||
base16/`colors.css` swap contract is that a user's own theme (stylix
|
||||
today) takes over with zero swarm-ui code changes. Don't build
|
||||
- **Theme-agnostic by construction.** The whole point of the
|
||||
base16/`colors.css` contract is that a new theme is 16 colours with zero
|
||||
swarm-ui code changes. Don't build
|
||||
anything that assumes a specific palette's exact colours (contrast
|
||||
ratios, "this accent is always purple") beyond what the semantic var
|
||||
names promise.
|
||||
- **stylix wins outright when it's active, no in-between state.** When
|
||||
an operator has stylix supplying swarm-ui's palette, that palette is
|
||||
authoritative — swarm-ui's own light/dark preference (below) doesn't
|
||||
override it. This is a deliberate simplification, not a limitation to
|
||||
fix: a stylix-using operator has already made their choice.
|
||||
- **Every theme is light or dark.** A theme declares its scheme, so the
|
||||
browser's own controls, scrollbars and dialog backdrops follow it. The
|
||||
user's pick wins over the OS preference; **auto** follows the OS and
|
||||
chooses hyperhive light or hyperhive dark.
|
||||
- **Light theme is accessibility, not a cosmetic extra.** Some people
|
||||
need light for contrast/low-vision reasons, others need dark for
|
||||
photosensitivity — there's no universally correct default. The OS
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
||||
agent page (before theme.css). This is the theme swap contract: a
|
||||
stylix-generated variant replaces only this file. See
|
||||
agent page (before theme.css). This is the theme contract: the
|
||||
themes' palettes live in this one file. See
|
||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||
@import "@hive/shared/colors.css";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
||||
dashboard page (before theme.css). This is the theme swap contract: a
|
||||
stylix-generated variant replaces only this file. See
|
||||
dashboard page (before theme.css). This is the theme contract: the
|
||||
themes' palettes live in this one file. See
|
||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||
@import "@hive/shared/colors.css";
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
"./icons.js": "./src/icons.tsx",
|
||||
"./settings-storage.js": "./src/settings/settings-storage.ts",
|
||||
"./theme-apply.js": "./src/settings/theme-apply.ts",
|
||||
"./themes.js": "./src/settings/themes.ts",
|
||||
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
||||
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
||||
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
||||
|
|
|
|||
|
|
@ -77,11 +77,11 @@
|
|||
/* Fixes badge with emoji having different size. */
|
||||
line-height: 1;
|
||||
}
|
||||
/* Blended with `--fg`, not the raw accent — a stylix-fed scheme can pick
|
||||
/* Blended with `--fg`, not the raw accent — a theme can pick
|
||||
any hue/lightness for `--green`/`--amber`/etc., and nothing guarantees
|
||||
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the two
|
||||
bundled palettes were hand-tuned to (see colors.css's comment above
|
||||
`--latte-base08..0F`). `--fg` is the one color the base16 contract
|
||||
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the
|
||||
hyperhive palettes were hand-tuned to (see colors.css's comment above
|
||||
`--hh-light-base08..0F`). `--fg` is the one color the base16 contract
|
||||
already guarantees is legible on every surface in the theme, so mixing
|
||||
toward it gives every accent a contrast floor without trying to
|
||||
compute/fix an operator's own theme (mara, on the low-contrast-badges
|
||||
|
|
|
|||
|
|
@ -1,25 +1,83 @@
|
|||
/* base16 palette — THE THEME CONTRACT.
|
||||
|
||||
These 16 slots are the entire swap interface. A theme generator (e.g.
|
||||
one fed a stylix base16 scheme, which is natively base00–base0F)
|
||||
overrides *only this file*; `theme.css` derives every semantic var
|
||||
(`--bg`, `--purple`, …) from these slots, so the whole UI re-themes
|
||||
with nothing else to regenerate.
|
||||
These 16 slots are the entire palette interface: `theme.css` derives every
|
||||
semantic var (`--bg`, `--purple`, …) from them, so a theme is 16 colours and
|
||||
nothing else to write. See docs/4-implementation/web-ui/css-vars.md.
|
||||
|
||||
Kept as its own standalone stylesheet (not @import-ed into theme.css)
|
||||
so a swap replaces just this file — `theme.css` and the page bundles
|
||||
stay untouched. Every page links this BEFORE `theme.css`. See
|
||||
docs/4-implementation/web-ui/css-vars.md.
|
||||
Kept as its own standalone stylesheet (not @import-ed into theme.css). Every
|
||||
page links this BEFORE `theme.css`.
|
||||
|
||||
Two raw palettes, one declaration each — `--mocha-baseNN` (dark,
|
||||
Catppuccin Mocha) and `--latte-baseNN` (light, Catppuccin-Latte-
|
||||
derived; base08-0F are darkened from stock Latte, see the comment
|
||||
above those declarations for why). The four blocks below this one
|
||||
never restate a hex value — each just points the active `--baseNN`
|
||||
slot at one of these two raw palettes via `var()`, so "which theme is
|
||||
active" and "what a theme's colours are" can't drift apart the way a
|
||||
hand-duplicated copy could. */
|
||||
Five themes, each light or dark, declared once as raw `--<theme>-baseNN`
|
||||
palettes: `hh-light` and `hh-dark` (the hyperhive themes: Catppuccin's
|
||||
neutrals with the hyperhive accents), `latte` and `mocha` (Catppuccin
|
||||
Latte and Mocha as published, mauve accent), and `mara` (Mocha with the
|
||||
accents mara picked). The blocks below the palettes
|
||||
never restate a hex value: each points the active `--baseNN` slots at one
|
||||
raw palette via `var()`, so "which theme is active" and "what a theme's
|
||||
colours are" can't drift apart. The registry of theme ids and labels is
|
||||
`settings/themes.ts`; `data-theme` on <html> (set by `settings/theme-apply.ts`)
|
||||
names the active one. With none set, hyperhive dark applies, and hyperhive
|
||||
light under a light OS preference ("auto"). */
|
||||
:root {
|
||||
--hh-light-base00: #eff1f5; /* default bg */
|
||||
--hh-light-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--hh-light-base02: #ccd0da; /* selection / surface — borders */
|
||||
--hh-light-base03: #bcc0cc; /* comments / dim surface */
|
||||
--hh-light-base04: #acb0be; /* dark foreground */
|
||||
--hh-light-base05: #4c4f69; /* default foreground */
|
||||
--hh-light-base06: #dc8a78; /* light foreground */
|
||||
--hh-light-base07: #7287fd; /* lightest */
|
||||
--hh-light-base08: #9c0b2a; /* red */
|
||||
--hh-light-base09: #883201; /* orange / peach */
|
||||
--hh-light-base0A: #6d450e; /* yellow */
|
||||
--hh-light-base0B: #235818; /* green */
|
||||
--hh-light-base0C: #025374; /* cyan */
|
||||
--hh-light-base0D: #0843b8; /* blue */
|
||||
--hh-light-base0E: #6311ce; /* magenta / mauve */
|
||||
--hh-light-base0F: #8f166e; /* extra accent — pink */
|
||||
/* base08-0F: darkened from stock Catppuccin Latte's accents (same hue and
|
||||
saturation, lower HSL lightness). The stock ones fail as badge text on
|
||||
base03 (1.4:1 to 3:1, need 4.5:1) and as plain text on base00 (2.3:1 to
|
||||
4.8:1): Latte's accents are tuned for its near-white base, not a mid-gray
|
||||
surface. `latte` below keeps the stock hexes. */
|
||||
|
||||
--hh-dark-base00: #1e1e2e; /* default bg */
|
||||
--hh-dark-base01: #181825; /* lighter bg (elevated surfaces) */
|
||||
--hh-dark-base02: #313244; /* selection / surface — borders */
|
||||
--hh-dark-base03: #45475a; /* comments / dim surface */
|
||||
--hh-dark-base04: #585b70; /* dark foreground */
|
||||
--hh-dark-base05: #cdd6f4; /* default foreground */
|
||||
--hh-dark-base06: #f5e0dc; /* light foreground */
|
||||
--hh-dark-base07: #b4befe; /* lightest */
|
||||
--hh-dark-base08: #f89db1; /* red */
|
||||
--hh-dark-base09: #fe9f6a; /* orange / peach */
|
||||
--hh-dark-base0A: #e9ab56; /* yellow */
|
||||
--hh-dark-base0B: #61ce4b; /* green */
|
||||
--hh-dark-base0C: #39c3fc; /* cyan */
|
||||
--hh-dark-base0D: #96b8fa; /* blue */
|
||||
--hh-dark-base0E: #cba8f8; /* magenta / mauve */
|
||||
--hh-dark-base0F: #f09cd9; /* extra accent — pink */
|
||||
/* hh-dark's base00-07 are Mocha's. base08-0F keep the hue and saturation of
|
||||
hh-light's accents at the HSL lightness where each reaches a 6.2:1 contrast
|
||||
against base02, about what Mocha's own accents have. */
|
||||
|
||||
--latte-base00: #eff1f5; /* default bg */
|
||||
--latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--latte-base02: #ccd0da; /* selection / surface — borders */
|
||||
--latte-base03: #bcc0cc; /* comments / dim surface */
|
||||
--latte-base04: #acb0be; /* dark foreground */
|
||||
--latte-base05: #4c4f69; /* default foreground */
|
||||
--latte-base06: #dc8a78; /* light foreground */
|
||||
--latte-base07: #7287fd; /* lightest */
|
||||
--latte-base08: #d20f39; /* red */
|
||||
--latte-base09: #fe640b; /* orange / peach */
|
||||
--latte-base0A: #df8e1d; /* yellow */
|
||||
--latte-base0B: #40a02b; /* green */
|
||||
--latte-base0C: #04a5e5; /* cyan */
|
||||
--latte-base0D: #1e66f5; /* blue */
|
||||
--latte-base0E: #8839ef; /* magenta / mauve */
|
||||
--latte-base0F: #ea76cb; /* extra accent — pink */
|
||||
|
||||
--mocha-base00: #1e1e2e; /* default bg */
|
||||
--mocha-base01: #181825; /* lighter bg (elevated surfaces) */
|
||||
--mocha-base02: #313244; /* selection / surface — borders */
|
||||
|
|
@ -32,128 +90,118 @@
|
|||
--mocha-base09: #fab387; /* orange / peach */
|
||||
--mocha-base0A: #f9e2af; /* yellow */
|
||||
--mocha-base0B: #a6e3a1; /* green */
|
||||
--mocha-base0C: #89dceb; /* cyan (our sky — note: Catppuccin's base0C is teal) */
|
||||
--mocha-base0C: #89dceb; /* cyan */
|
||||
--mocha-base0D: #89b4fa; /* blue */
|
||||
--mocha-base0E: #cba6f7; /* magenta / mauve */
|
||||
--mocha-base0F: #f5c2e7; /* extra accent — pink */
|
||||
|
||||
--latte-base00: #eff1f5; /* default bg */
|
||||
--latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
||||
--latte-base02: #ccd0da; /* selection / surface — borders */
|
||||
--latte-base03: #bcc0cc; /* comments / dim surface */
|
||||
--latte-base04: #acb0be; /* dark foreground */
|
||||
--latte-base05: #4c4f69; /* default foreground */
|
||||
--latte-base06: #dc8a78; /* light foreground */
|
||||
--latte-base07: #7287fd; /* lightest */
|
||||
/* base08-0F: darkened from stock Catppuccin Latte's own accent hexes
|
||||
(same hue/saturation, lower HSL lightness), not a literal upstream
|
||||
port like base00-07 above. A review round computed real WCAG
|
||||
contrast ratios and found the literal Latte accents fail badly as
|
||||
`Badge`/chip fill-text (green/amber/red/yellow on
|
||||
`--purple-dim`/base03: 1.4:1-3:1, need 4.5:1) and even as plain
|
||||
text on `--bg`/base00 in the agent/dashboard packages that also
|
||||
consume this same file (2.3:1-4.8:1). Root cause: Latte's own
|
||||
accent colors are calibrated against Latte's near-white
|
||||
`base`/`crust`, not against a mid-gray `surface1` — the Mocha
|
||||
palette doesn't have this problem because Mocha's pastel accents
|
||||
are already *light*, so they contrast fine against a *dark*
|
||||
surface1; Latte's saturated-but-mid-brightness accents don't have
|
||||
the equivalent headroom against Latte's own (much lighter)
|
||||
surface1. Each value below was picked by holding the stock Latte
|
||||
hue+saturation fixed and binary-searching HSL lightness down to
|
||||
the point real contrast against base03 clears 4.5:1 with a small
|
||||
margin (also verified against base00: all land above 7:1 there) —
|
||||
same hue identity, same base16 role, just dark/saturated enough to
|
||||
actually be legible as filled-chip or plain text either way.
|
||||
Yellow and peach read closer to olive/brown than a bright
|
||||
yellow/orange once darkened this far — an inherent property of
|
||||
darkening a warm hue in sRGB (Bezold-Brücke shift), not a mapping
|
||||
mistake; boosting saturation further didn't rescue it (verified). */
|
||||
--latte-base08: #9c0b2a; /* red */
|
||||
--latte-base09: #883201; /* orange / peach */
|
||||
--latte-base0A: #6d450e; /* yellow */
|
||||
--latte-base0B: #235818; /* green */
|
||||
--latte-base0C: #025374; /* cyan (our sky — note: Catppuccin's base0C is teal) */
|
||||
--latte-base0D: #0843b8; /* blue */
|
||||
--latte-base0E: #6311ce; /* magenta / mauve */
|
||||
--latte-base0F: #8f166e; /* extra accent — pink */
|
||||
--mara-base00: #1e1e2e; /* default bg */
|
||||
--mara-base01: #313244; /* lighter bg (elevated surfaces) */
|
||||
--mara-base02: #45475a; /* selection / surface — borders */
|
||||
--mara-base03: #6c7086; /* comments / dim surface */
|
||||
--mara-base04: #a6adc8; /* dark foreground */
|
||||
--mara-base05: #cdd6f4; /* default foreground */
|
||||
--mara-base06: #f5e0dc; /* light foreground */
|
||||
--mara-base07: #b4befe; /* lightest */
|
||||
--mara-base08: #f38ba8; /* red */
|
||||
--mara-base09: #6f9dff; /* orange / peach */
|
||||
--mara-base0A: #d162a4; /* yellow */
|
||||
--mara-base0B: #a8c9ff; /* green */
|
||||
--mara-base0C: #a30262; /* cyan */
|
||||
--mara-base0D: #89b4fa; /* blue */
|
||||
--mara-base0E: #cba6f7; /* magenta / mauve */
|
||||
--mara-base0F: #f2cdcd; /* extra accent — pink */
|
||||
/* mara: Catppuccin Mocha with the accents mara picked (base09-base0C). */
|
||||
}
|
||||
|
||||
/* Default activation: Mocha, unless the media query below or a
|
||||
per-user override (further below) says otherwise. */
|
||||
--base00: var(--mocha-base00);
|
||||
--base01: var(--mocha-base01);
|
||||
--base02: var(--mocha-base02);
|
||||
--base03: var(--mocha-base03);
|
||||
--base04: var(--mocha-base04);
|
||||
--base05: var(--mocha-base05);
|
||||
--base06: var(--mocha-base06);
|
||||
--base07: var(--mocha-base07);
|
||||
--base08: var(--mocha-base08);
|
||||
--base09: var(--mocha-base09);
|
||||
--base0A: var(--mocha-base0A);
|
||||
--base0B: var(--mocha-base0B);
|
||||
--base0C: var(--mocha-base0C);
|
||||
--base0D: var(--mocha-base0D);
|
||||
--base0E: var(--mocha-base0E);
|
||||
--base0F: var(--mocha-base0F);
|
||||
/* The browser's own controls, scrollbars and dialog backdrops follow the
|
||||
palette, so a forced theme does not leave them on the OS's. */
|
||||
/* hyperhive dark: the default, and the dark half of "auto". */
|
||||
:root,
|
||||
:root[data-theme="hyperhive-dark"] {
|
||||
--base00: var(--hh-dark-base00);
|
||||
--base01: var(--hh-dark-base01);
|
||||
--base02: var(--hh-dark-base02);
|
||||
--base03: var(--hh-dark-base03);
|
||||
--base04: var(--hh-dark-base04);
|
||||
--base05: var(--hh-dark-base05);
|
||||
--base06: var(--hh-dark-base06);
|
||||
--base07: var(--hh-dark-base07);
|
||||
--base08: var(--hh-dark-base08);
|
||||
--base09: var(--hh-dark-base09);
|
||||
--base0A: var(--hh-dark-base0A);
|
||||
--base0B: var(--hh-dark-base0B);
|
||||
--base0C: var(--hh-dark-base0C);
|
||||
--base0D: var(--hh-dark-base0D);
|
||||
--base0E: var(--hh-dark-base0E);
|
||||
--base0F: var(--hh-dark-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
--palette-glass-clear: initial;
|
||||
--palette-glass-filter: initial;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* OS/browser-level light-mode default. This is a *default*, not a user
|
||||
preference store: it only applies when nothing more specific has
|
||||
already decided the palette. A stylix-generated colors.css
|
||||
(nix/host-modules/hive-c0re/theme.nix) replaces this entire file
|
||||
wholesale — a fixed, unconditional `:root` block with no media query
|
||||
in it at all — so a stylix-themed deployment is naturally unaffected
|
||||
by, and never fights, this block. Some people need light for
|
||||
low-vision/contrast reasons, others need dark for photosensitivity,
|
||||
so respect the OS/browser signal by default the same way
|
||||
`prefers-reduced-motion` already is elsewhere — rather than always
|
||||
forcing the bundled dark palette on a client with no stylix session
|
||||
of its own (e.g. a phone browser hitting swarm-ui directly). */
|
||||
/* "auto" under a light OS preference. An explicit theme below outranks it:
|
||||
an attribute selector always beats the plain `:root`. */
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--base00: var(--latte-base00);
|
||||
--base01: var(--latte-base01);
|
||||
--base02: var(--latte-base02);
|
||||
--base03: var(--latte-base03);
|
||||
--base04: var(--latte-base04);
|
||||
--base05: var(--latte-base05);
|
||||
--base06: var(--latte-base06);
|
||||
--base07: var(--latte-base07);
|
||||
--base08: var(--latte-base08);
|
||||
--base09: var(--latte-base09);
|
||||
--base0A: var(--latte-base0A);
|
||||
--base0B: var(--latte-base0B);
|
||||
--base0C: var(--latte-base0C);
|
||||
--base0D: var(--latte-base0D);
|
||||
--base0E: var(--latte-base0E);
|
||||
--base0F: var(--latte-base0F);
|
||||
/* Dimmed text on the light palette: see `--muted-share` in theme.css. */
|
||||
--base00: var(--hh-light-base00);
|
||||
--base01: var(--hh-light-base01);
|
||||
--base02: var(--hh-light-base02);
|
||||
--base03: var(--hh-light-base03);
|
||||
--base04: var(--hh-light-base04);
|
||||
--base05: var(--hh-light-base05);
|
||||
--base06: var(--hh-light-base06);
|
||||
--base07: var(--hh-light-base07);
|
||||
--base08: var(--hh-light-base08);
|
||||
--base09: var(--hh-light-base09);
|
||||
--base0A: var(--hh-light-base0A);
|
||||
--base0B: var(--hh-light-base0B);
|
||||
--base0C: var(--hh-light-base0C);
|
||||
--base0D: var(--hh-light-base0D);
|
||||
--base0E: var(--hh-light-base0E);
|
||||
--base0F: var(--hh-light-base0F);
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on the light palette: see `--glass-clear` in theme.css. */
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
}
|
||||
|
||||
/* Per-user override (`SettingsMenu` and `settings/theme-apply.ts`
|
||||
set `data-theme` on `<html>`; unset/`"system"` removes the
|
||||
attribute and lets the media query above decide, same as before this
|
||||
existed). `:root[data-theme='light']` has higher specificity than
|
||||
the plain `:root` inside the media query above (an attribute
|
||||
selector always outranks none), so this wins regardless of the
|
||||
actual OS preference or source order — no `!important`, no inline
|
||||
style, and critically no second copy of either palette's hex values:
|
||||
both blocks below just re-point at the same `--mocha-baseNN` /
|
||||
`--latte-baseNN` custom properties declared once at the top of this
|
||||
file. */
|
||||
:root[data-theme="light"] {
|
||||
:root[data-theme="hyperhive-light"] {
|
||||
--base00: var(--hh-light-base00);
|
||||
--base01: var(--hh-light-base01);
|
||||
--base02: var(--hh-light-base02);
|
||||
--base03: var(--hh-light-base03);
|
||||
--base04: var(--hh-light-base04);
|
||||
--base05: var(--hh-light-base05);
|
||||
--base06: var(--hh-light-base06);
|
||||
--base07: var(--hh-light-base07);
|
||||
--base08: var(--hh-light-base08);
|
||||
--base09: var(--hh-light-base09);
|
||||
--base0A: var(--hh-light-base0A);
|
||||
--base0B: var(--hh-light-base0B);
|
||||
--base0C: var(--hh-light-base0C);
|
||||
--base0D: var(--hh-light-base0D);
|
||||
--base0E: var(--hh-light-base0E);
|
||||
--base0F: var(--hh-light-base0F);
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
:root[data-theme="catppuccin-latte-mauve"] {
|
||||
--base00: var(--latte-base00);
|
||||
--base01: var(--latte-base01);
|
||||
--base02: var(--latte-base02);
|
||||
|
|
@ -170,15 +218,17 @@
|
|||
--base0D: var(--latte-base0D);
|
||||
--base0E: var(--latte-base0E);
|
||||
--base0F: var(--latte-base0F);
|
||||
/* Dimmed text on the light palette: see `--muted-share` in theme.css. */
|
||||
/* Dimmed text on a light palette: see `--muted-share` in theme.css. */
|
||||
--muted-share: 85%;
|
||||
--subtext0-share: 93%;
|
||||
--code-bg-share: 95%;
|
||||
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||
--palette-glass-clear: 0;
|
||||
--palette-glass-filter: none;
|
||||
color-scheme: light;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
|
||||
:root[data-theme="catppuccin-mocha-mauve"] {
|
||||
--base00: var(--mocha-base00);
|
||||
--base01: var(--mocha-base01);
|
||||
--base02: var(--mocha-base02);
|
||||
|
|
@ -196,7 +246,34 @@
|
|||
--base0E: var(--mocha-base0E);
|
||||
--base0F: var(--mocha-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so the dark palette sets its own, the defaults of theme.css. */
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
--palette-glass-clear: initial;
|
||||
--palette-glass-filter: initial;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
:root[data-theme="catppuccin-mocha-mara"] {
|
||||
--base00: var(--mara-base00);
|
||||
--base01: var(--mara-base01);
|
||||
--base02: var(--mara-base02);
|
||||
--base03: var(--mara-base03);
|
||||
--base04: var(--mara-base04);
|
||||
--base05: var(--mara-base05);
|
||||
--base06: var(--mara-base06);
|
||||
--base07: var(--mara-base07);
|
||||
--base08: var(--mara-base08);
|
||||
--base09: var(--mara-base09);
|
||||
--base0A: var(--mara-base0A);
|
||||
--base0B: var(--mara-base0B);
|
||||
--base0C: var(--mara-base0C);
|
||||
--base0D: var(--mara-base0D);
|
||||
--base0E: var(--mara-base0E);
|
||||
--base0F: var(--mara-base0F);
|
||||
/* A dark pick over a light OS preference: the media query's shares must not
|
||||
carry over, so a dark palette sets its own, the defaults of theme.css. */
|
||||
--muted-share: 58%;
|
||||
--subtext0-share: 77.7%;
|
||||
--code-bg-share: 58%;
|
||||
|
|
|
|||
|
|
@ -28,11 +28,15 @@ import type { ComponentChildren } from "preact";
|
|||
import { IconButton } from "../icon-button/IconButton.js";
|
||||
import { GearIcon } from "../icons.js";
|
||||
import { useDismiss } from "../use-dismiss.js";
|
||||
import { useThemeOverride, type ThemeOverride } from "./theme-apply.js";
|
||||
import { useThemeOverride } from "./theme-apply.js";
|
||||
import { AUTO_THEME, THEMES } from "./themes.js";
|
||||
import { useMotionOverride, type MotionOverride } from "./motion-apply.js";
|
||||
import "./SettingsMenu.css";
|
||||
|
||||
const THEME_OPTIONS: ThemeOverride[] = ["system", "light", "dark"];
|
||||
const THEME_OPTIONS = [
|
||||
{ id: AUTO_THEME, label: "auto" },
|
||||
...THEMES.map((t) => ({ id: t.id, label: t.label })),
|
||||
];
|
||||
const MOTION_OPTIONS: MotionOverride[] = ["system", "allow", "reduce"];
|
||||
|
||||
export interface SettingsMenuProps {
|
||||
|
|
@ -85,13 +89,11 @@ export function SettingsMenu({
|
|||
<span>theme</span>
|
||||
<select
|
||||
value={theme}
|
||||
onChange={(e) =>
|
||||
setTheme((e.target as HTMLSelectElement).value as ThemeOverride)
|
||||
}
|
||||
onChange={(e) => setTheme((e.target as HTMLSelectElement).value)}
|
||||
>
|
||||
{THEME_OPTIONS.map((o) => (
|
||||
<option key={o} value={o}>
|
||||
{o}
|
||||
<option key={o.id} value={o.id}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -1,46 +1,46 @@
|
|||
// Applies a stored theme override by setting `data-theme="light"|"dark"`
|
||||
// on `<html>`, cleared when the override is "system" (letting the
|
||||
// `prefers-color-scheme` media query in `./colors.css` resume control).
|
||||
// No palette values live here — `colors.css`'s own
|
||||
// `:root[data-theme='light']` / `:root[data-theme='dark']` blocks are
|
||||
// what actually apply the colours.
|
||||
// Applies the stored theme choice by setting `data-theme="<theme id>"` on
|
||||
// `<html>`, cleared for `auto` (so the `prefers-color-scheme` media query in
|
||||
// `../colors.css` picks hyperhive light or dark). No palette values live
|
||||
// here: `colors.css`'s `:root[data-theme="<id>"]` blocks apply the colours,
|
||||
// and `./themes.ts` lists the ids.
|
||||
//
|
||||
// Callers own their own storage key (kept in their own small constant,
|
||||
// not derived here) so two pages never silently share one browser-local
|
||||
// setting by accident. `fallback` defaults to `'dark'`: `prefers-color-
|
||||
// scheme` has no real "unset" value the way `prefers-reduced-motion`
|
||||
// does, so a browser with no explicit dark-mode toggle reports `light`
|
||||
// — `'system'` as a default silently reads as light-by-default for most
|
||||
// first-time visitors (mara: "light mode seems to be default"). Still
|
||||
// fully overridable per caller if a page ever wants a different default.
|
||||
// Callers own their own storage key (kept in their own small constant, not
|
||||
// derived here) so two pages never silently share one browser-local setting
|
||||
// by accident. The stored value is read through `themeChoice`, so a value
|
||||
// from before themes existed (`system`, `light`, `dark`) still works. The
|
||||
// default is hyperhive dark: `prefers-color-scheme` has no real "unset" value
|
||||
// the way `prefers-reduced-motion` does, so a browser with no explicit
|
||||
// dark-mode toggle reports `light`, and `auto` as a default read as
|
||||
// light-by-default for most first-time visitors (mara: "light mode seems to be
|
||||
// default").
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { useLocalSetting } from "./settings-storage.js";
|
||||
import { AUTO_THEME, DEFAULT_THEME, themeChoice } from "./themes.js";
|
||||
|
||||
export type ThemeOverride = "system" | "light" | "dark";
|
||||
|
||||
/** `[choice, setChoice]`: `auto` or a theme id from `./themes.ts`. */
|
||||
export function useThemeOverride(
|
||||
key: string,
|
||||
fallback: ThemeOverride = "dark",
|
||||
) {
|
||||
return useLocalSetting<ThemeOverride>(key, fallback);
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): [string, (choice: string) => void] {
|
||||
const [stored, setStored] = useLocalSetting<string>(key, fallback);
|
||||
return [themeChoice(stored, fallback), setStored];
|
||||
}
|
||||
|
||||
// Mounted once, high in the tree — one mount point applies the override
|
||||
// regardless of what else is rendering, and `useLocalSetting`'s
|
||||
// same-tab subscription means `SettingsMenu` changing the value re-runs
|
||||
// this effect without either component needing to know about the other
|
||||
// directly.
|
||||
// Mounted once, high in the tree — one mount point applies the choice
|
||||
// regardless of what else is rendering, and `useLocalSetting`'s same-tab
|
||||
// subscription means `SettingsMenu` changing the value re-runs this effect
|
||||
// without either component needing to know about the other directly.
|
||||
export function useApplyThemeOverride(
|
||||
key: string,
|
||||
fallback: ThemeOverride = "dark",
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): void {
|
||||
const [override] = useThemeOverride(key, fallback);
|
||||
const [choice] = useThemeOverride(key, fallback);
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (override === "system") {
|
||||
if (choice === AUTO_THEME) {
|
||||
delete root.dataset.theme;
|
||||
} else {
|
||||
root.dataset.theme = override;
|
||||
root.dataset.theme = choice;
|
||||
}
|
||||
}, [override]);
|
||||
}, [choice]);
|
||||
}
|
||||
|
|
|
|||
54
frontend/packages/shared/src/settings/themes.ts
Normal file
54
frontend/packages/shared/src/settings/themes.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// The themes a user can pick, apart from how they are applied. The palettes are
|
||||
// in `../colors.css`, one `:root[data-theme="<id>"]` block per id here; a new
|
||||
// theme is one entry here and one palette there. Each theme is light or dark.
|
||||
// `auto` is not a theme: it leaves `data-theme` off, and the OS preference
|
||||
// picks hyperhive light or hyperhive dark.
|
||||
|
||||
export type ThemeScheme = "light" | "dark";
|
||||
|
||||
export interface ThemeDef {
|
||||
id: string;
|
||||
label: string;
|
||||
scheme: ThemeScheme;
|
||||
}
|
||||
|
||||
export const THEMES: readonly ThemeDef[] = [
|
||||
{ id: "hyperhive-light", label: "hyperhive light", scheme: "light" },
|
||||
{ id: "hyperhive-dark", label: "hyperhive dark", scheme: "dark" },
|
||||
{
|
||||
id: "catppuccin-latte-mauve",
|
||||
label: "catppuccin latte mauve",
|
||||
scheme: "light",
|
||||
},
|
||||
{
|
||||
id: "catppuccin-mocha-mauve",
|
||||
label: "catppuccin mocha mauve",
|
||||
scheme: "dark",
|
||||
},
|
||||
{
|
||||
id: "catppuccin-mocha-mara",
|
||||
label: "catppuccin mocha mara",
|
||||
scheme: "dark",
|
||||
},
|
||||
];
|
||||
|
||||
/** The stored choice that follows the OS preference. */
|
||||
export const AUTO_THEME = "auto";
|
||||
|
||||
/** What a page uses until the user has picked. */
|
||||
export const DEFAULT_THEME = "hyperhive-dark";
|
||||
|
||||
/**
|
||||
* The choice a stored value stands for. The values from before themes existed
|
||||
* map to their successors (`system` to `auto`, `light` and `dark` to the
|
||||
* hyperhive themes); anything unknown is `fallback`.
|
||||
*/
|
||||
export function themeChoice(
|
||||
stored: unknown,
|
||||
fallback: string = DEFAULT_THEME,
|
||||
): string {
|
||||
if (stored === AUTO_THEME || stored === "system") return AUTO_THEME;
|
||||
if (stored === "light") return "hyperhive-light";
|
||||
if (stored === "dark") return "hyperhive-dark";
|
||||
return THEMES.some((t) => t.id === stored) ? (stored as string) : fallback;
|
||||
}
|
||||
|
|
@ -7,10 +7,9 @@
|
|||
// sync with the actual build steps.
|
||||
//
|
||||
// `colors.css` is the ONE static asset deliberately left UNHASHED, at a
|
||||
// fixed `dist/static/colors.css`: nix/host-modules/swarm-ui.nix's stylix
|
||||
// theming swaps that exact path via an `= /static/colors.css` nginx
|
||||
// location override, no npm/esbuild rebuild involved. Hashing it would
|
||||
// silently break that swap. See `colors.css`'s own top comment.
|
||||
// fixed `dist/static/colors.css`: nix/host-modules/swarm-ui.nix serves that
|
||||
// exact path through an `= /static/colors.css` nginx location that
|
||||
// revalidates it, and the swagger page links the same file.
|
||||
//
|
||||
// `dist/sw.js` keeps its own fixed/unhashed filename too — the browser
|
||||
// polls this exact URL to detect a SW update, hashing it would make
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
||||
swarm-ui page (before theme.css). This is the theme swap contract: a
|
||||
stylix-generated variant replaces only this file. See
|
||||
swarm-ui page (before theme.css). This is the theme contract: the
|
||||
themes' palettes live in this one file. See
|
||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||
@import "@hive/shared/colors.css";
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
// Network-first for the shell, not cache-first: most assets below are
|
||||
// content-hashed (a fresh URL per deploy, so a normal visit always gets
|
||||
// the current bundle regardless of this SW), but `colors.css` stays
|
||||
// deliberately unhashed for the host-side stylix theme swap, so this
|
||||
// unhashed (the swagger page links it by its fixed name), so this
|
||||
// SW's own cached copy of it can only ever refresh via a real network
|
||||
// round-trip. This SW only ever serves its cache on a FAILED fetch
|
||||
// (offline/flaky network), never in preference to a live response.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
// `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.
|
||||
// keys and the fallbacks (hyperhive dark for the theme, "system" for motion) are
|
||||
// those of `shell/Shell.tsx`, and the theme ids and the values from before
|
||||
// themes existed are those of `@hive/shared`'s `settings/themes.ts`;
|
||||
// `test/theme-boot.test.mjs` keeps them in step.
|
||||
(function () {
|
||||
function read(key, fallback) {
|
||||
try {
|
||||
|
|
@ -15,8 +17,17 @@
|
|||
}
|
||||
}
|
||||
var root = document.documentElement;
|
||||
var theme = read("swarm-ui:theme-override", "dark");
|
||||
if (theme === "light" || theme === "dark") root.dataset.theme = theme;
|
||||
var themes = [
|
||||
"hyperhive-light",
|
||||
"hyperhive-dark",
|
||||
"catppuccin-latte-mauve",
|
||||
"catppuccin-mocha-mauve",
|
||||
"catppuccin-mocha-mara",
|
||||
];
|
||||
var theme = read("swarm-ui:theme-override", "hyperhive-dark");
|
||||
if (theme === "light") theme = "hyperhive-light";
|
||||
if (theme === "dark") theme = "hyperhive-dark";
|
||||
if (themes.indexOf(theme) >= 0) root.dataset.theme = theme;
|
||||
var motion = read("swarm-ui:motion-override", "system");
|
||||
if (motion === "reduce" || motion === "allow") root.dataset.motion = motion;
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -27,25 +27,36 @@ function boot(stored) {
|
|||
return dataset;
|
||||
}
|
||||
|
||||
test("nothing stored sets the dark default and leaves motion to the system", () => {
|
||||
assert.deepEqual(boot({}), { theme: "dark" });
|
||||
test("nothing stored sets the hyperhive dark default and leaves motion to the system", () => {
|
||||
assert.deepEqual(boot({}), { theme: "hyperhive-dark" });
|
||||
});
|
||||
|
||||
test("a stored light theme and a motion override are set", () => {
|
||||
test("a stored 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" });
|
||||
assert.deepEqual(set, { theme: "hyperhive-light", motion: "reduce" });
|
||||
assert.deepEqual(
|
||||
boot({ "swarm-ui:theme-override": '"catppuccin-mocha-mauve"' }),
|
||||
{ theme: "catppuccin-mocha-mauve" },
|
||||
);
|
||||
});
|
||||
|
||||
test("system leaves the attribute off, so the media query decides", () => {
|
||||
test("a stored dark, from before themes existed, is hyperhive dark", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"dark"' }), {
|
||||
theme: "hyperhive-dark",
|
||||
});
|
||||
});
|
||||
|
||||
test("auto, and system from before themes existed, leave the attribute off, so the media query decides", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"auto"' }), {});
|
||||
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",
|
||||
theme: "hyperhive-dark",
|
||||
});
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"blue"' }), {});
|
||||
});
|
||||
|
|
@ -60,7 +71,31 @@ test("storage that throws behaves as if nothing were stored", () => {
|
|||
},
|
||||
document: { documentElement: { dataset } },
|
||||
});
|
||||
assert.deepEqual(dataset, { theme: "dark" });
|
||||
assert.deepEqual(dataset, { theme: "hyperhive-dark" });
|
||||
});
|
||||
|
||||
test("the theme ids are the registry's", () => {
|
||||
const registry = readFileSync(
|
||||
new URL("../../shared/src/settings/themes.ts", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const ids = (text) =>
|
||||
[...text.matchAll(/"((?:hyperhive|catppuccin)-[a-z-]+)"/g)].map(
|
||||
(m) => m[1],
|
||||
);
|
||||
const listed = script.slice(
|
||||
script.indexOf("var themes"),
|
||||
script.indexOf("];"),
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(listed),
|
||||
ids(
|
||||
registry.slice(
|
||||
registry.indexOf("THEMES"),
|
||||
registry.indexOf("AUTO_THEME"),
|
||||
),
|
||||
).filter((id, i, all) => all.indexOf(id) === i),
|
||||
);
|
||||
});
|
||||
|
||||
test("the keys are the shell's", () => {
|
||||
|
|
|
|||
36
frontend/packages/swarm-ui/test/themes.test.mjs
Normal file
36
frontend/packages/swarm-ui/test/themes.test.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// The theme registry and how a stored choice reads. Run by `npm test`, which
|
||||
// imports the `.ts` module as it is.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import {
|
||||
AUTO_THEME,
|
||||
DEFAULT_THEME,
|
||||
THEMES,
|
||||
themeChoice,
|
||||
} from "../../shared/src/settings/themes.ts";
|
||||
|
||||
test("the default is one of the themes", () => {
|
||||
assert.ok(THEMES.some((t) => t.id === DEFAULT_THEME));
|
||||
});
|
||||
|
||||
test("every theme is light or dark, and the ids and labels are distinct", () => {
|
||||
for (const t of THEMES) assert.ok(["light", "dark"].includes(t.scheme));
|
||||
assert.equal(new Set(THEMES.map((t) => t.id)).size, THEMES.length);
|
||||
assert.equal(new Set(THEMES.map((t) => t.label)).size, THEMES.length);
|
||||
});
|
||||
|
||||
test("a theme id and auto read as themselves", () => {
|
||||
assert.equal(themeChoice("catppuccin-mocha-mauve"), "catppuccin-mocha-mauve");
|
||||
assert.equal(themeChoice(AUTO_THEME), AUTO_THEME);
|
||||
});
|
||||
|
||||
test("the values from before themes existed read as their successors", () => {
|
||||
assert.equal(themeChoice("system"), AUTO_THEME);
|
||||
assert.equal(themeChoice("light"), "hyperhive-light");
|
||||
assert.equal(themeChoice("dark"), "hyperhive-dark");
|
||||
});
|
||||
|
||||
test("an unknown value reads as the fallback", () => {
|
||||
assert.equal(themeChoice("blue"), DEFAULT_THEME);
|
||||
assert.equal(themeChoice(undefined, "hyperhive-light"), "hyperhive-light");
|
||||
});
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
# The hive-c0re coordinator daemon (runs as the unprivileged
|
||||
# `hive-core` user), socket-activated at /run/hyperhive/host.sock.
|
||||
# Layout: ./options.nix (option declarations), ./theme.nix (stylix
|
||||
# frontend theming → `servedFrontend`), ./vhosts.nix (its gateway vhosts),
|
||||
# Layout: ./options.nix (option declarations), ./vhosts.nix (its gateway vhosts),
|
||||
# ./environment.nix (the daemon unit's env attrset). The root privileged
|
||||
# helper it delegates to is its own module (../hive-priv.nix).
|
||||
{
|
||||
|
|
@ -102,7 +101,6 @@ in
|
|||
{
|
||||
imports = [
|
||||
./options.nix
|
||||
./theme.nix
|
||||
./vhosts.nix
|
||||
# Hive-CA trust for this daemon's outbound TLS. The swarm services it
|
||||
# reaches over https serve a leaf chaining to the store's pki root —
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ in
|
|||
# nix store directly; dynamic API paths still proxied to the
|
||||
# agent daemon. nginx runs on the host, which is where this
|
||||
# store path already is, so it is reachable as written.
|
||||
HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.servedFrontend}/agent";
|
||||
HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.frontend}/agent";
|
||||
}
|
||||
// {
|
||||
# Identity env vars threaded into c0re's own service env and
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue