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 |
|
| 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>/api/` | hive-c0re (`7000`), behind authelia | always |
|
||||||
| `<name>.hives.<swarm>/health/` | hive-c0re (`7000`) | always |
|
| `<name>.hives.<swarm>/health/` | hive-c0re (`7000`) | always |
|
||||||
| `<name>.hives.<swarm>/api/docs/` | themed Swagger UI dist (static), behind authelia | 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 /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 /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`).
|
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
|
### Per-agent static frontend split
|
||||||
|
|
||||||
hive-c0re's environment sets `HIVE_AGENT_FRONTEND_DIR` to the `agent/`
|
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
|
The nginx include generator (`gateway_nginx::write`) reads
|
||||||
this variable and, when set, emits split location blocks per agent
|
this variable and, when set, emits split location blocks per agent
|
||||||
instead of a single proxy block.
|
instead of a single proxy block.
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
# CSS custom properties (theme variables)
|
# CSS custom properties (theme variables)
|
||||||
|
|
||||||
Colour variables live in **two standalone stylesheets**, split so a theme
|
Colour variables live in **two standalone stylesheets**, split so a new theme
|
||||||
swap touches only the first:
|
touches only the first:
|
||||||
|
|
||||||
1. **`colors.css`** — the 16 `--base00`…`--base0F` base16 slots. **This is
|
1. **`colors.css`** — the 16 `--base00`…`--base0F` base16 slots. **This is
|
||||||
the entire theme swap contract.** A generator (for example one fed a stylix
|
the whole theme contract.** A theme is 16 colours here and nothing else.
|
||||||
base16 scheme, which is natively base00–base0F) replaces _only this
|
|
||||||
file_.
|
|
||||||
2. **`theme.css`** — the semantic layer: `--bg`, `--fg`, `--purple`, …
|
2. **`theme.css`** — the semantic layer: `--bg`, `--fg`, `--purple`, …
|
||||||
_derived_ from the base16 slots (`--bg: var(--base00)` etc.). This is
|
_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
|
Both files live in `frontend/packages/shared/src/`. Per-page stylesheets
|
||||||
(`common.css`, `dashboard.css`, `agent.css`)
|
(`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
|
for the raw `--baseNN` slots directly. (`base.css` holds only the shared
|
||||||
`body` typography — it references the palette but no longer defines it.)
|
`body` typography — it references the palette but no longer defines it.)
|
||||||
|
|
||||||
`colors.css` declares each palette's 16 hex values exactly once —
|
`colors.css` declares each theme's 16 hex values exactly once, as
|
||||||
`--mocha-baseNN` (dark, Catppuccin Mocha) and `--latte-baseNN` (light,
|
`--<theme>-baseNN`, for five themes that are each light or dark:
|
||||||
Catppuccin-Latte-derived; `base08`-`base0F` run darker than stock
|
|
||||||
Latte to actually clear WCAG AA against how this app uses them — real
|
| Theme | Id | Scheme | Palette |
|
||||||
contrast failures found in review, see the comment above those
|
| ---------------------- | ------------------------ | ------ | ------------------------------------------------------------------ |
|
||||||
declarations in `colors.css` for the numbers and why). Everything else
|
| hyperhive light | `hyperhive-light` | light | Latte's neutrals, accents darker than stock to clear WCAG AA |
|
||||||
in the file just points the active `--baseNN` slot at one of those two
|
| hyperhive dark | `hyperhive-dark` | dark | Mocha's neutrals, the light accents' hues lifted to suit a dark bg |
|
||||||
raw palettes via `var()`, never a second copy of a hex value: an
|
| catppuccin latte mauve | `catppuccin-latte-mauve` | light | Catppuccin Latte as published |
|
||||||
unconditional default (Mocha), a row gated behind `@media
|
| catppuccin mocha mauve | `catppuccin-mocha-mauve` | dark | Catppuccin Mocha as published |
|
||||||
(prefers-color-scheme: light)` (Latte, the OS/browser-level default),
|
| catppuccin mocha mara | `catppuccin-mocha-mara` | dark | Mocha with the accents mara picked |
|
||||||
and two `:root[data-theme='light'|'dark']` blocks a per-user override
|
|
||||||
sets (swarm-ui's `SettingsMenu`) — an attribute selector always
|
The hyperhive light accents (`base08`-`base0F`) run darker than stock Latte
|
||||||
outranks the plain `:root` inside the media query, so the override wins
|
because the stock ones fail contrast as badge text and as plain text; the
|
||||||
regardless of the actual OS preference. Absent an override, the media
|
comment above them in `colors.css` has the numbers. The hyperhive dark
|
||||||
query decides; that's what a client with no more specific theme
|
accents keep those hues and saturations and raise the lightness until each
|
||||||
decision gets (see "Theme swapping" below for how a stylix deployment
|
clears 6:1 against `base02`.
|
||||||
supersedes all of this at once).
|
|
||||||
|
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:
|
Both are deliberately standalone, not `@import`ed into the page bundles:
|
||||||
each package re-exports them (`src/{colors,theme}.css` →
|
each package re-exports them (`src/{colors,theme}.css` →
|
||||||
|
|
@ -139,26 +149,22 @@ color: var(--amber); /* warning / running */
|
||||||
color: var(--green); /* ok */
|
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
|
**The theme interface is `colors.css` — the 16 base16 slots, not the
|
||||||
semantic names.** A theme generator (for example one reading a stylix base16
|
semantic names.** The semantic layer in `theme.css` derives everything
|
||||||
scheme) overrides only `colors.css`; the semantic layer in `theme.css`
|
else, so a new theme needs nothing else to template or regenerate. The
|
||||||
derives everything else, so the whole UI re-themes with nothing else to
|
base16 slot → semantic mapping is _internal_ to `theme.css` (the "Derives
|
||||||
template or regenerate. The base16 slot → semantic mapping is _internal_
|
from" column above): a theme never needs the semantic var names, and
|
||||||
to `theme.css` (the "Derives from" column above) — a generator never
|
`theme.css` and the page bundles stay untouched.
|
||||||
needs to know the semantic var names, and `theme.css` + the page bundles stay
|
|
||||||
untouched.
|
|
||||||
|
|
||||||
**Two palettes, one contract.** `colors.css` ships both a dark default
|
**Five palettes, one contract.** `colors.css` ships the five themes in the
|
||||||
(Catppuccin Mocha, unconditional) and a light default (Catppuccin Latte,
|
table above, each light or dark, with hyperhive dark as the unconditional
|
||||||
behind `@media (prefers-color-scheme: light)`), plus a per-user override
|
default and hyperhive light behind `@media (prefers-color-scheme: light)`.
|
||||||
path (`:root[data-theme]`) — a theme generator that overrides the file
|
Each theme's block also sets `color-scheme` and the contrast shares of
|
||||||
wholesale (for example the stylix path, which writes a single unconditional
|
`theme.css` (`--muted-share` and friends) for its scheme.
|
||||||
`:root` block with no media query, no `--mocha-*`/`--latte-*` vars, no
|
|
||||||
`[data-theme]` blocks) supersedes all of it at once, same as today.
|
|
||||||
|
|
||||||
`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 |
|
| Slot | Default | Standard base16 role | Mapped to |
|
||||||
| -------- | --------- | -------------------- | ---------------------------------------------------------- |
|
| -------- | --------- | -------------------- | ---------------------------------------------------------- |
|
||||||
|
|
@ -187,10 +193,8 @@ Notes for theme authors:
|
||||||
`--muted`/`--subtext0` = `base05`↔`base00` blends). They still track a
|
`--muted`/`--subtext0` = `base05`↔`base00` blends). They still track a
|
||||||
swap automatically; no generator action needed.
|
swap automatically; no generator action needed.
|
||||||
- A standard Catppuccin base16 scheme uses **teal** for `base0C`;
|
- A standard Catppuccin base16 scheme uses **teal** for `base0C`;
|
||||||
`colors.css` defaults it to **sky** (`#89dceb`) to preserve the historical
|
`colors.css` uses **sky** (`#89dceb` in Mocha) to keep the historical
|
||||||
accent. A
|
accent.
|
||||||
stylix Catppuccin scheme will shift `--cyan` to teal — that's the
|
|
||||||
operator's chosen scheme, working as intended.
|
|
||||||
- `base04`/`base06`/`base07` aren't consumed by a semantic var today;
|
- `base04`/`base06`/`base07` aren't consumed by a semantic var today;
|
||||||
they're kept at their standard values so the 16-slot contract is
|
they're kept at their standard values so the 16-slot contract is
|
||||||
complete (a partial scheme override still works).
|
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
|
**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 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 settings menu in the header has a **hide developer details** toggle. It drops
|
||||||
the muted debug rows (coalesced ticks, harness chatter) from every
|
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
|
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 —
|
generation, mainly for shape/elevation ideas. Colour is dynamic too —
|
||||||
autoderived shades (mixing, lighter/darker) are fair game, same as
|
autoderived shades (mixing, lighter/darker) are fair game, same as
|
||||||
Material's own approach — but every derived colour still traces back
|
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
|
## 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` —
|
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:
|
read that for the how. This section is the _policy_ layered on top:
|
||||||
|
|
||||||
- **User-theming compatible by construction.** The whole point of the
|
- **Theme-agnostic by construction.** The whole point of the
|
||||||
base16/`colors.css` swap contract is that a user's own theme (stylix
|
base16/`colors.css` contract is that a new theme is 16 colours with zero
|
||||||
today) takes over with zero swarm-ui code changes. Don't build
|
swarm-ui code changes. Don't build
|
||||||
anything that assumes a specific palette's exact colours (contrast
|
anything that assumes a specific palette's exact colours (contrast
|
||||||
ratios, "this accent is always purple") beyond what the semantic var
|
ratios, "this accent is always purple") beyond what the semantic var
|
||||||
names promise.
|
names promise.
|
||||||
- **stylix wins outright when it's active, no in-between state.** When
|
- **Every theme is light or dark.** A theme declares its scheme, so the
|
||||||
an operator has stylix supplying swarm-ui's palette, that palette is
|
browser's own controls, scrollbars and dialog backdrops follow it. The
|
||||||
authoritative — swarm-ui's own light/dark preference (below) doesn't
|
user's pick wins over the OS preference; **auto** follows the OS and
|
||||||
override it. This is a deliberate simplification, not a limitation to
|
chooses hyperhive light or hyperhive dark.
|
||||||
fix: a stylix-using operator has already made their choice.
|
|
||||||
- **Light theme is accessibility, not a cosmetic extra.** Some people
|
- **Light theme is accessibility, not a cosmetic extra.** Some people
|
||||||
need light for contrast/low-vision reasons, others need dark for
|
need light for contrast/low-vision reasons, others need dark for
|
||||||
photosensitivity — there's no universally correct default. The OS
|
photosensitivity — there's no universally correct default. The OS
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* Standalone base16 palette — re-exports the shared base16 slots so
|
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
esbuild emits its own `dist/static/colors.css`, linked first by every
|
||||||
agent page (before theme.css). This is the theme swap contract: a
|
agent page (before theme.css). This is the theme contract: the
|
||||||
stylix-generated variant replaces only this file. See
|
themes' palettes live in this one file. See
|
||||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||||
@import "@hive/shared/colors.css";
|
@import "@hive/shared/colors.css";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* Standalone base16 palette — re-exports the shared base16 slots so
|
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
esbuild emits its own `dist/static/colors.css`, linked first by every
|
||||||
dashboard page (before theme.css). This is the theme swap contract: a
|
dashboard page (before theme.css). This is the theme contract: the
|
||||||
stylix-generated variant replaces only this file. See
|
themes' palettes live in this one file. See
|
||||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||||
@import "@hive/shared/colors.css";
|
@import "@hive/shared/colors.css";
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
"./icons.js": "./src/icons.tsx",
|
"./icons.js": "./src/icons.tsx",
|
||||||
"./settings-storage.js": "./src/settings/settings-storage.ts",
|
"./settings-storage.js": "./src/settings/settings-storage.ts",
|
||||||
"./theme-apply.js": "./src/settings/theme-apply.ts",
|
"./theme-apply.js": "./src/settings/theme-apply.ts",
|
||||||
|
"./themes.js": "./src/settings/themes.ts",
|
||||||
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
||||||
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
||||||
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,11 @@
|
||||||
/* Fixes badge with emoji having different size. */
|
/* Fixes badge with emoji having different size. */
|
||||||
line-height: 1;
|
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
|
any hue/lightness for `--green`/`--amber`/etc., and nothing guarantees
|
||||||
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the two
|
an arbitrary accent clears 4.5:1 against `--purple-dim` the way the
|
||||||
bundled palettes were hand-tuned to (see colors.css's comment above
|
hyperhive palettes were hand-tuned to (see colors.css's comment above
|
||||||
`--latte-base08..0F`). `--fg` is the one color the base16 contract
|
`--hh-light-base08..0F`). `--fg` is the one color the base16 contract
|
||||||
already guarantees is legible on every surface in the theme, so mixing
|
already guarantees is legible on every surface in the theme, so mixing
|
||||||
toward it gives every accent a contrast floor without trying to
|
toward it gives every accent a contrast floor without trying to
|
||||||
compute/fix an operator's own theme (mara, on the low-contrast-badges
|
compute/fix an operator's own theme (mara, on the low-contrast-badges
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,83 @@
|
||||||
/* base16 palette — THE THEME CONTRACT.
|
/* base16 palette — THE THEME CONTRACT.
|
||||||
|
|
||||||
These 16 slots are the entire swap interface. A theme generator (e.g.
|
These 16 slots are the entire palette interface: `theme.css` derives every
|
||||||
one fed a stylix base16 scheme, which is natively base00–base0F)
|
semantic var (`--bg`, `--purple`, …) from them, so a theme is 16 colours and
|
||||||
overrides *only this file*; `theme.css` derives every semantic var
|
nothing else to write. See docs/4-implementation/web-ui/css-vars.md.
|
||||||
(`--bg`, `--purple`, …) from these slots, so the whole UI re-themes
|
|
||||||
with nothing else to regenerate.
|
|
||||||
|
|
||||||
Kept as its own standalone stylesheet (not @import-ed into theme.css)
|
Kept as its own standalone stylesheet (not @import-ed into theme.css). Every
|
||||||
so a swap replaces just this file — `theme.css` and the page bundles
|
page links this BEFORE `theme.css`.
|
||||||
stay untouched. Every page links this BEFORE `theme.css`. See
|
|
||||||
docs/4-implementation/web-ui/css-vars.md.
|
|
||||||
|
|
||||||
Two raw palettes, one declaration each — `--mocha-baseNN` (dark,
|
Five themes, each light or dark, declared once as raw `--<theme>-baseNN`
|
||||||
Catppuccin Mocha) and `--latte-baseNN` (light, Catppuccin-Latte-
|
palettes: `hh-light` and `hh-dark` (the hyperhive themes: Catppuccin's
|
||||||
derived; base08-0F are darkened from stock Latte, see the comment
|
neutrals with the hyperhive accents), `latte` and `mocha` (Catppuccin
|
||||||
above those declarations for why). The four blocks below this one
|
Latte and Mocha as published, mauve accent), and `mara` (Mocha with the
|
||||||
never restate a hex value — each just points the active `--baseNN`
|
accents mara picked). The blocks below the palettes
|
||||||
slot at one of these two raw palettes via `var()`, so "which theme is
|
never restate a hex value: each points the active `--baseNN` slots at one
|
||||||
active" and "what a theme's colours are" can't drift apart the way a
|
raw palette via `var()`, so "which theme is active" and "what a theme's
|
||||||
hand-duplicated copy could. */
|
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 {
|
: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-base00: #1e1e2e; /* default bg */
|
||||||
--mocha-base01: #181825; /* lighter bg (elevated surfaces) */
|
--mocha-base01: #181825; /* lighter bg (elevated surfaces) */
|
||||||
--mocha-base02: #313244; /* selection / surface — borders */
|
--mocha-base02: #313244; /* selection / surface — borders */
|
||||||
|
|
@ -32,128 +90,118 @@
|
||||||
--mocha-base09: #fab387; /* orange / peach */
|
--mocha-base09: #fab387; /* orange / peach */
|
||||||
--mocha-base0A: #f9e2af; /* yellow */
|
--mocha-base0A: #f9e2af; /* yellow */
|
||||||
--mocha-base0B: #a6e3a1; /* green */
|
--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-base0D: #89b4fa; /* blue */
|
||||||
--mocha-base0E: #cba6f7; /* magenta / mauve */
|
--mocha-base0E: #cba6f7; /* magenta / mauve */
|
||||||
--mocha-base0F: #f5c2e7; /* extra accent — pink */
|
--mocha-base0F: #f5c2e7; /* extra accent — pink */
|
||||||
|
|
||||||
--latte-base00: #eff1f5; /* default bg */
|
--mara-base00: #1e1e2e; /* default bg */
|
||||||
--latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */
|
--mara-base01: #313244; /* lighter bg (elevated surfaces) */
|
||||||
--latte-base02: #ccd0da; /* selection / surface — borders */
|
--mara-base02: #45475a; /* selection / surface — borders */
|
||||||
--latte-base03: #bcc0cc; /* comments / dim surface */
|
--mara-base03: #6c7086; /* comments / dim surface */
|
||||||
--latte-base04: #acb0be; /* dark foreground */
|
--mara-base04: #a6adc8; /* dark foreground */
|
||||||
--latte-base05: #4c4f69; /* default foreground */
|
--mara-base05: #cdd6f4; /* default foreground */
|
||||||
--latte-base06: #dc8a78; /* light foreground */
|
--mara-base06: #f5e0dc; /* light foreground */
|
||||||
--latte-base07: #7287fd; /* lightest */
|
--mara-base07: #b4befe; /* lightest */
|
||||||
/* base08-0F: darkened from stock Catppuccin Latte's own accent hexes
|
--mara-base08: #f38ba8; /* red */
|
||||||
(same hue/saturation, lower HSL lightness), not a literal upstream
|
--mara-base09: #6f9dff; /* orange / peach */
|
||||||
port like base00-07 above. A review round computed real WCAG
|
--mara-base0A: #d162a4; /* yellow */
|
||||||
contrast ratios and found the literal Latte accents fail badly as
|
--mara-base0B: #a8c9ff; /* green */
|
||||||
`Badge`/chip fill-text (green/amber/red/yellow on
|
--mara-base0C: #a30262; /* cyan */
|
||||||
`--purple-dim`/base03: 1.4:1-3:1, need 4.5:1) and even as plain
|
--mara-base0D: #89b4fa; /* blue */
|
||||||
text on `--bg`/base00 in the agent/dashboard packages that also
|
--mara-base0E: #cba6f7; /* magenta / mauve */
|
||||||
consume this same file (2.3:1-4.8:1). Root cause: Latte's own
|
--mara-base0F: #f2cdcd; /* extra accent — pink */
|
||||||
accent colors are calibrated against Latte's near-white
|
/* mara: Catppuccin Mocha with the accents mara picked (base09-base0C). */
|
||||||
`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 */
|
|
||||||
|
|
||||||
/* Default activation: Mocha, unless the media query below or a
|
/* hyperhive dark: the default, and the dark half of "auto". */
|
||||||
per-user override (further below) says otherwise. */
|
:root,
|
||||||
--base00: var(--mocha-base00);
|
:root[data-theme="hyperhive-dark"] {
|
||||||
--base01: var(--mocha-base01);
|
--base00: var(--hh-dark-base00);
|
||||||
--base02: var(--mocha-base02);
|
--base01: var(--hh-dark-base01);
|
||||||
--base03: var(--mocha-base03);
|
--base02: var(--hh-dark-base02);
|
||||||
--base04: var(--mocha-base04);
|
--base03: var(--hh-dark-base03);
|
||||||
--base05: var(--mocha-base05);
|
--base04: var(--hh-dark-base04);
|
||||||
--base06: var(--mocha-base06);
|
--base05: var(--hh-dark-base05);
|
||||||
--base07: var(--mocha-base07);
|
--base06: var(--hh-dark-base06);
|
||||||
--base08: var(--mocha-base08);
|
--base07: var(--hh-dark-base07);
|
||||||
--base09: var(--mocha-base09);
|
--base08: var(--hh-dark-base08);
|
||||||
--base0A: var(--mocha-base0A);
|
--base09: var(--hh-dark-base09);
|
||||||
--base0B: var(--mocha-base0B);
|
--base0A: var(--hh-dark-base0A);
|
||||||
--base0C: var(--mocha-base0C);
|
--base0B: var(--hh-dark-base0B);
|
||||||
--base0D: var(--mocha-base0D);
|
--base0C: var(--hh-dark-base0C);
|
||||||
--base0E: var(--mocha-base0E);
|
--base0D: var(--hh-dark-base0D);
|
||||||
--base0F: var(--mocha-base0F);
|
--base0E: var(--hh-dark-base0E);
|
||||||
/* The browser's own controls, scrollbars and dialog backdrops follow the
|
--base0F: var(--hh-dark-base0F);
|
||||||
palette, so a forced theme does not leave them on the OS's. */
|
/* 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;
|
color-scheme: dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* OS/browser-level light-mode default. This is a *default*, not a user
|
/* "auto" under a light OS preference. An explicit theme below outranks it:
|
||||||
preference store: it only applies when nothing more specific has
|
an attribute selector always beats the plain `:root`. */
|
||||||
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). */
|
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
:root {
|
:root {
|
||||||
--base00: var(--latte-base00);
|
--base00: var(--hh-light-base00);
|
||||||
--base01: var(--latte-base01);
|
--base01: var(--hh-light-base01);
|
||||||
--base02: var(--latte-base02);
|
--base02: var(--hh-light-base02);
|
||||||
--base03: var(--latte-base03);
|
--base03: var(--hh-light-base03);
|
||||||
--base04: var(--latte-base04);
|
--base04: var(--hh-light-base04);
|
||||||
--base05: var(--latte-base05);
|
--base05: var(--hh-light-base05);
|
||||||
--base06: var(--latte-base06);
|
--base06: var(--hh-light-base06);
|
||||||
--base07: var(--latte-base07);
|
--base07: var(--hh-light-base07);
|
||||||
--base08: var(--latte-base08);
|
--base08: var(--hh-light-base08);
|
||||||
--base09: var(--latte-base09);
|
--base09: var(--hh-light-base09);
|
||||||
--base0A: var(--latte-base0A);
|
--base0A: var(--hh-light-base0A);
|
||||||
--base0B: var(--latte-base0B);
|
--base0B: var(--hh-light-base0B);
|
||||||
--base0C: var(--latte-base0C);
|
--base0C: var(--hh-light-base0C);
|
||||||
--base0D: var(--latte-base0D);
|
--base0D: var(--hh-light-base0D);
|
||||||
--base0E: var(--latte-base0E);
|
--base0E: var(--hh-light-base0E);
|
||||||
--base0F: var(--latte-base0F);
|
--base0F: var(--hh-light-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%;
|
--muted-share: 85%;
|
||||||
--subtext0-share: 93%;
|
--subtext0-share: 93%;
|
||||||
--code-bg-share: 95%;
|
--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-clear: 0;
|
||||||
--palette-glass-filter: none;
|
--palette-glass-filter: none;
|
||||||
color-scheme: light;
|
color-scheme: light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Per-user override (`SettingsMenu` and `settings/theme-apply.ts`
|
:root[data-theme="hyperhive-light"] {
|
||||||
set `data-theme` on `<html>`; unset/`"system"` removes the
|
--base00: var(--hh-light-base00);
|
||||||
attribute and lets the media query above decide, same as before this
|
--base01: var(--hh-light-base01);
|
||||||
existed). `:root[data-theme='light']` has higher specificity than
|
--base02: var(--hh-light-base02);
|
||||||
the plain `:root` inside the media query above (an attribute
|
--base03: var(--hh-light-base03);
|
||||||
selector always outranks none), so this wins regardless of the
|
--base04: var(--hh-light-base04);
|
||||||
actual OS preference or source order — no `!important`, no inline
|
--base05: var(--hh-light-base05);
|
||||||
style, and critically no second copy of either palette's hex values:
|
--base06: var(--hh-light-base06);
|
||||||
both blocks below just re-point at the same `--mocha-baseNN` /
|
--base07: var(--hh-light-base07);
|
||||||
`--latte-baseNN` custom properties declared once at the top of this
|
--base08: var(--hh-light-base08);
|
||||||
file. */
|
--base09: var(--hh-light-base09);
|
||||||
:root[data-theme="light"] {
|
--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);
|
--base00: var(--latte-base00);
|
||||||
--base01: var(--latte-base01);
|
--base01: var(--latte-base01);
|
||||||
--base02: var(--latte-base02);
|
--base02: var(--latte-base02);
|
||||||
|
|
@ -170,15 +218,17 @@
|
||||||
--base0D: var(--latte-base0D);
|
--base0D: var(--latte-base0D);
|
||||||
--base0E: var(--latte-base0E);
|
--base0E: var(--latte-base0E);
|
||||||
--base0F: var(--latte-base0F);
|
--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%;
|
--muted-share: 85%;
|
||||||
--subtext0-share: 93%;
|
--subtext0-share: 93%;
|
||||||
--code-bg-share: 95%;
|
--code-bg-share: 95%;
|
||||||
|
/* No frosted glass on a light palette: see `--glass-clear` in theme.css. */
|
||||||
--palette-glass-clear: 0;
|
--palette-glass-clear: 0;
|
||||||
--palette-glass-filter: none;
|
--palette-glass-filter: none;
|
||||||
color-scheme: light;
|
color-scheme: light;
|
||||||
}
|
}
|
||||||
:root[data-theme="dark"] {
|
|
||||||
|
:root[data-theme="catppuccin-mocha-mauve"] {
|
||||||
--base00: var(--mocha-base00);
|
--base00: var(--mocha-base00);
|
||||||
--base01: var(--mocha-base01);
|
--base01: var(--mocha-base01);
|
||||||
--base02: var(--mocha-base02);
|
--base02: var(--mocha-base02);
|
||||||
|
|
@ -196,7 +246,34 @@
|
||||||
--base0E: var(--mocha-base0E);
|
--base0E: var(--mocha-base0E);
|
||||||
--base0F: var(--mocha-base0F);
|
--base0F: var(--mocha-base0F);
|
||||||
/* A dark pick over a light OS preference: the media query's shares must not
|
/* 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%;
|
--muted-share: 58%;
|
||||||
--subtext0-share: 77.7%;
|
--subtext0-share: 77.7%;
|
||||||
--code-bg-share: 58%;
|
--code-bg-share: 58%;
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,15 @@ import type { ComponentChildren } from "preact";
|
||||||
import { IconButton } from "../icon-button/IconButton.js";
|
import { IconButton } from "../icon-button/IconButton.js";
|
||||||
import { GearIcon } from "../icons.js";
|
import { GearIcon } from "../icons.js";
|
||||||
import { useDismiss } from "../use-dismiss.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 { useMotionOverride, type MotionOverride } from "./motion-apply.js";
|
||||||
import "./SettingsMenu.css";
|
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"];
|
const MOTION_OPTIONS: MotionOverride[] = ["system", "allow", "reduce"];
|
||||||
|
|
||||||
export interface SettingsMenuProps {
|
export interface SettingsMenuProps {
|
||||||
|
|
@ -85,13 +89,11 @@ export function SettingsMenu({
|
||||||
<span>theme</span>
|
<span>theme</span>
|
||||||
<select
|
<select
|
||||||
value={theme}
|
value={theme}
|
||||||
onChange={(e) =>
|
onChange={(e) => setTheme((e.target as HTMLSelectElement).value)}
|
||||||
setTheme((e.target as HTMLSelectElement).value as ThemeOverride)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{THEME_OPTIONS.map((o) => (
|
{THEME_OPTIONS.map((o) => (
|
||||||
<option key={o} value={o}>
|
<option key={o.id} value={o.id}>
|
||||||
{o}
|
{o.label}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,46 @@
|
||||||
// Applies a stored theme override by setting `data-theme="light"|"dark"`
|
// Applies the stored theme choice by setting `data-theme="<theme id>"` on
|
||||||
// on `<html>`, cleared when the override is "system" (letting the
|
// `<html>`, cleared for `auto` (so the `prefers-color-scheme` media query in
|
||||||
// `prefers-color-scheme` media query in `./colors.css` resume control).
|
// `../colors.css` picks hyperhive light or dark). No palette values live
|
||||||
// No palette values live here — `colors.css`'s own
|
// here: `colors.css`'s `:root[data-theme="<id>"]` blocks apply the colours,
|
||||||
// `:root[data-theme='light']` / `:root[data-theme='dark']` blocks are
|
// and `./themes.ts` lists the ids.
|
||||||
// what actually apply the colours.
|
|
||||||
//
|
//
|
||||||
// Callers own their own storage key (kept in their own small constant,
|
// Callers own their own storage key (kept in their own small constant, not
|
||||||
// not derived here) so two pages never silently share one browser-local
|
// derived here) so two pages never silently share one browser-local setting
|
||||||
// setting by accident. `fallback` defaults to `'dark'`: `prefers-color-
|
// by accident. The stored value is read through `themeChoice`, so a value
|
||||||
// scheme` has no real "unset" value the way `prefers-reduced-motion`
|
// from before themes existed (`system`, `light`, `dark`) still works. The
|
||||||
// does, so a browser with no explicit dark-mode toggle reports `light`
|
// default is hyperhive dark: `prefers-color-scheme` has no real "unset" value
|
||||||
// — `'system'` as a default silently reads as light-by-default for most
|
// the way `prefers-reduced-motion` does, so a browser with no explicit
|
||||||
// first-time visitors (mara: "light mode seems to be default"). Still
|
// dark-mode toggle reports `light`, and `auto` as a default read as
|
||||||
// fully overridable per caller if a page ever wants a different default.
|
// light-by-default for most first-time visitors (mara: "light mode seems to be
|
||||||
|
// default").
|
||||||
import { useEffect } from "preact/hooks";
|
import { useEffect } from "preact/hooks";
|
||||||
import { useLocalSetting } from "./settings-storage.js";
|
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(
|
export function useThemeOverride(
|
||||||
key: string,
|
key: string,
|
||||||
fallback: ThemeOverride = "dark",
|
fallback: string = DEFAULT_THEME,
|
||||||
) {
|
): [string, (choice: string) => void] {
|
||||||
return useLocalSetting<ThemeOverride>(key, fallback);
|
const [stored, setStored] = useLocalSetting<string>(key, fallback);
|
||||||
|
return [themeChoice(stored, fallback), setStored];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mounted once, high in the tree — one mount point applies the override
|
// Mounted once, high in the tree — one mount point applies the choice
|
||||||
// regardless of what else is rendering, and `useLocalSetting`'s
|
// regardless of what else is rendering, and `useLocalSetting`'s same-tab
|
||||||
// same-tab subscription means `SettingsMenu` changing the value re-runs
|
// subscription means `SettingsMenu` changing the value re-runs this effect
|
||||||
// this effect without either component needing to know about the other
|
// without either component needing to know about the other directly.
|
||||||
// directly.
|
|
||||||
export function useApplyThemeOverride(
|
export function useApplyThemeOverride(
|
||||||
key: string,
|
key: string,
|
||||||
fallback: ThemeOverride = "dark",
|
fallback: string = DEFAULT_THEME,
|
||||||
): void {
|
): void {
|
||||||
const [override] = useThemeOverride(key, fallback);
|
const [choice] = useThemeOverride(key, fallback);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const root = document.documentElement;
|
const root = document.documentElement;
|
||||||
if (override === "system") {
|
if (choice === AUTO_THEME) {
|
||||||
delete root.dataset.theme;
|
delete root.dataset.theme;
|
||||||
} else {
|
} 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.
|
// sync with the actual build steps.
|
||||||
//
|
//
|
||||||
// `colors.css` is the ONE static asset deliberately left UNHASHED, at a
|
// `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
|
// fixed `dist/static/colors.css`: nix/host-modules/swarm-ui.nix serves that
|
||||||
// theming swaps that exact path via an `= /static/colors.css` nginx
|
// exact path through an `= /static/colors.css` nginx location that
|
||||||
// location override, no npm/esbuild rebuild involved. Hashing it would
|
// revalidates it, and the swagger page links the same file.
|
||||||
// silently break that swap. See `colors.css`'s own top comment.
|
|
||||||
//
|
//
|
||||||
// `dist/sw.js` keeps its own fixed/unhashed filename too — the browser
|
// `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
|
// 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
|
/* Standalone base16 palette — re-exports the shared base16 slots so
|
||||||
esbuild emits its own `dist/static/colors.css`, linked first by every
|
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
|
swarm-ui page (before theme.css). This is the theme contract: the
|
||||||
stylix-generated variant replaces only this file. See
|
themes' palettes live in this one file. See
|
||||||
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
@hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */
|
||||||
@import "@hive/shared/colors.css";
|
@import "@hive/shared/colors.css";
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
// Network-first for the shell, not cache-first: most assets below are
|
// 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
|
// content-hashed (a fresh URL per deploy, so a normal visit always gets
|
||||||
// the current bundle regardless of this SW), but `colors.css` stays
|
// 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
|
// 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
|
// round-trip. This SW only ever serves its cache on a FAILED fetch
|
||||||
// (offline/flaky network), never in preference to a live response.
|
// (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
|
// `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
|
// 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
|
// 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
|
// keys and the fallbacks (hyperhive dark for the theme, "system" for motion) are
|
||||||
// `shell/Shell.tsx`; `test/theme-boot.test.mjs` keeps them in step.
|
// 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 () {
|
||||||
function read(key, fallback) {
|
function read(key, fallback) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -15,8 +17,17 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var root = document.documentElement;
|
var root = document.documentElement;
|
||||||
var theme = read("swarm-ui:theme-override", "dark");
|
var themes = [
|
||||||
if (theme === "light" || theme === "dark") root.dataset.theme = theme;
|
"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");
|
var motion = read("swarm-ui:motion-override", "system");
|
||||||
if (motion === "reduce" || motion === "allow") root.dataset.motion = motion;
|
if (motion === "reduce" || motion === "allow") root.dataset.motion = motion;
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -27,25 +27,36 @@ function boot(stored) {
|
||||||
return dataset;
|
return dataset;
|
||||||
}
|
}
|
||||||
|
|
||||||
test("nothing stored sets the dark default and leaves motion to the system", () => {
|
test("nothing stored sets the hyperhive dark default and leaves motion to the system", () => {
|
||||||
assert.deepEqual(boot({}), { theme: "dark" });
|
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({
|
const set = boot({
|
||||||
"swarm-ui:theme-override": '"light"',
|
"swarm-ui:theme-override": '"light"',
|
||||||
"swarm-ui:motion-override": '"reduce"',
|
"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"' }), {});
|
assert.deepEqual(boot({ "swarm-ui:theme-override": '"system"' }), {});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a value that is not JSON, or not one of the choices, is ignored", () => {
|
test("a value that is not JSON, or not one of the choices, is ignored", () => {
|
||||||
assert.deepEqual(boot({ "swarm-ui:theme-override": "light" }), {
|
assert.deepEqual(boot({ "swarm-ui:theme-override": "light" }), {
|
||||||
theme: "dark",
|
theme: "hyperhive-dark",
|
||||||
});
|
});
|
||||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"blue"' }), {});
|
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 } },
|
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", () => {
|
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
|
# The hive-c0re coordinator daemon (runs as the unprivileged
|
||||||
# `hive-core` user), socket-activated at /run/hyperhive/host.sock.
|
# `hive-core` user), socket-activated at /run/hyperhive/host.sock.
|
||||||
# Layout: ./options.nix (option declarations), ./theme.nix (stylix
|
# Layout: ./options.nix (option declarations), ./vhosts.nix (its gateway vhosts),
|
||||||
# frontend theming → `servedFrontend`), ./vhosts.nix (its gateway vhosts),
|
|
||||||
# ./environment.nix (the daemon unit's env attrset). The root privileged
|
# ./environment.nix (the daemon unit's env attrset). The root privileged
|
||||||
# helper it delegates to is its own module (../hive-priv.nix).
|
# helper it delegates to is its own module (../hive-priv.nix).
|
||||||
{
|
{
|
||||||
|
|
@ -102,7 +101,6 @@ in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./options.nix
|
./options.nix
|
||||||
./theme.nix
|
|
||||||
./vhosts.nix
|
./vhosts.nix
|
||||||
# Hive-CA trust for this daemon's outbound TLS. The swarm services it
|
# 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 —
|
# 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
|
# nix store directly; dynamic API paths still proxied to the
|
||||||
# agent daemon. nginx runs on the host, which is where this
|
# agent daemon. nginx runs on the host, which is where this
|
||||||
# store path already is, so it is reachable as written.
|
# 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
|
# 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