feat(ui): Styleguide-Tokens und Theme-Auswahl, Playground mit festen Einstellungen und Eingabe (#1075, #1089, #1098)

- tokens.css und theme.js des Styleguides eingebettet (/ui/stil/), app.css ohne eigene Farbwerte; Darstellung System, Dunkel, Hell in der Fußzeile.
- Wortmarke nutzt --accent-strong, im hellen Theme dunkler (Kontrast).
- Playground: Einstellungen oben, Eingabe unten, nur der Verlauf scrollt.
- Test für die Einbindung und das Layout; im Browser lokal geprüft. Klicktests browser2stil.1 bis .3 angelegt.
- components.css bewusst nicht übernommen (andere Klassennamen).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 16:12:04 +01:00
parent 43f3008e52
commit 034d759e0a
7 changed files with 342 additions and 8 deletions

View File

@ -0,0 +1,40 @@
/*
* Theme-Auswahl nach STYLEGUIDE.md (Abschnitt 4): "system" | "dark" | "light".
* "system" entfernt data-theme, dann entscheidet prefers-color-scheme (siehe tokens.css).
*
* Gegen Aufblitzen beim Laden früh im <head> einbinden (ohne type="module"):
* <script src="theme.js"></script>
* Danach per Schalter: styleguideTheme.set("dark").
*/
(function () {
var KEY = "styleguide-theme";
var VALID = ["system", "dark", "light"];
function read() {
try {
var v = localStorage.getItem(KEY);
return VALID.indexOf(v) >= 0 ? v : "system";
} catch (e) {
return "system";
}
}
function apply(value) {
var root = document.documentElement;
if (value === "dark" || value === "light") root.setAttribute("data-theme", value);
else root.removeAttribute("data-theme");
}
function set(value) {
if (VALID.indexOf(value) < 0) value = "system";
try {
if (value === "system") localStorage.removeItem(KEY);
else localStorage.setItem(KEY, value);
} catch (e) {}
apply(value);
return value;
}
apply(read());
window.styleguideTheme = { get: read, set: set };
})();

View File

@ -0,0 +1,206 @@
/*
* Design-Tokens des Styleguides (siehe STYLEGUIDE.md, Version 1).
* Dunkel ist der Fallback, Hell gilt bei entsprechender Systemeinstellung.
* Eine bewusste Auswahl lässt sich über data-theme="dark" | "light" am <html>-Element erzwingen.
* Quelle der Werte ist STYLEGUIDE.md; beide Dateien gemeinsam ändern.
*/
/* Dunkel (Fallback) */
:root {
color-scheme: dark;
--bg: #0f1115;
--surface: #181b21;
--surface-2: #222630;
--text: #eceff4;
--muted: #9099a8;
--border: #2b303a;
--border-field: #6b7585;
--accent: #ff9b45;
--accent-strong: #ff9b45;
--accent-soft: rgba(255, 155, 69, .14);
--accent-text: #1a1005;
--ok: #6fd18a;
--warn: #ffcf5c;
--danger: #ff7b72;
--info: #4fc3dc;
--on-ok: #06180d;
--on-warn: #1a1405;
--on-danger: #1a0805;
--cat-1: #b69cff;
--cat-2: #7aa7ff;
--cat-3: #ff7ac0;
--bg-glow: rgba(255, 155, 69, .10);
--shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
/* Hell bei Systemeinstellung, sofern nicht bewusst Dunkel gewählt wurde */
@media (prefers-color-scheme: light) {
:root:not([data-theme="dark"]) {
color-scheme: light;
--bg: #f6f3ef;
--surface: #ffffff;
--surface-2: #f0ebe4;
--text: #1d1a17;
--muted: #6b645c;
--border: #e2dbd2;
--border-field: #8a8378;
--accent: #f08a2c;
--accent-strong: #a8530a;
--accent-soft: rgba(240, 138, 44, .14);
--accent-text: #ffffff;
--ok: #217346;
--warn: #8a6100;
--danger: #c0392b;
--info: #0b7285;
--on-ok: #ffffff;
--on-warn: #ffffff;
--on-danger: #ffffff;
--cat-1: #6941c6;
--cat-2: #175cd3;
--cat-3: #c11574;
--bg-glow: rgba(255, 155, 69, .16);
--shadow: 0 6px 20px rgba(60, 40, 20, .10);
}
}
/* Hell bei bewusster Auswahl */
:root[data-theme="light"] {
color-scheme: light;
--bg: #f6f3ef;
--surface: #ffffff;
--surface-2: #f0ebe4;
--text: #1d1a17;
--muted: #6b645c;
--border: #e2dbd2;
--border-field: #8a8378;
--accent: #f08a2c;
--accent-strong: #a8530a;
--accent-soft: rgba(240, 138, 44, .14);
--accent-text: #ffffff;
--ok: #217346;
--warn: #8a6100;
--danger: #c0392b;
--info: #0b7285;
--on-ok: #ffffff;
--on-warn: #ffffff;
--on-danger: #ffffff;
--cat-1: #6941c6;
--cat-2: #175cd3;
--cat-3: #c11574;
--bg-glow: rgba(255, 155, 69, .16);
--shadow: 0 6px 20px rgba(60, 40, 20, .10);
}
/* Themeunabhängig: Typografie, Radien, Layout, Bewegung */
:root {
--font-sans: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
--font-serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
--font-mono: ui-monospace, "JetBrains Mono", Menlo, monospace;
--font-size-base: 15px;
--line-height-base: 1.5;
--line-height-heading: 1.25;
--line-height-reading: 1.75;
--reading-max: 46rem;
--font-size-page-title: 1.5rem;
--font-size-page-title-compact: 1.3rem;
--font-size-section-title: 1.1rem;
--font-size-wordmark: 1.1rem;
--font-size-wordmark-large: 1.5rem;
--font-size-small: 0.8rem;
--font-size-table-head: 0.75rem;
--font-size-metric: 1.6rem;
--radius-card: 14px;
--radius-metric: 12px;
--radius-button: 10px;
--radius-field: 8px;
--radius-pill: 999px;
--content-max: 76rem;
--content-gutter: 1rem;
--card-pad-y: 1.1rem;
--card-pad-x: 1.3rem;
--card-gap: 1.1rem;
--login-max: 28rem;
--sidebar-width: 15rem;
/* Ebenen */
--z-drag: 200;
--z-sticky: 10;
--z-dropdown: 40;
--z-modal: 100;
--z-modal-2: 110;
--z-system: 300;
--z-toast: 400;
--z-tooltip: 500;
--breakpoint-compact: 40rem; /* nur zur Dokumentation; in @media als Literal verwenden */
--transition: 0.12s;
--control-size: 1.15rem;
--switch-width: 2.3rem;
--switch-height: 1.3rem;
--target-min: 24px;
--spinner-size: 1.25rem;
--icon-sm: 1rem;
--icon-md: 1.25rem;
--icon-lg: 1.5rem;
--icon-stroke: 1.5;
--icon-button: 2rem;
--tooltip-max: 18rem;
--tooltip-gap: 6px;
--tooltip-delay: 0.4s; /* nur zur Dokumentation; im Skript als Millisekunden */
--skeleton-radius: 6px;
--backdrop: rgba(0, 0, 0, .5);
--dialog-width: 560px;
--dialog-pad: 18px 22px;
--dialog-gap: 8px;
--shadow-dialog: 0 20px 60px rgba(0, 0, 0, .35);
--shadow-menu: 0 10px 30px rgba(0, 0, 0, .25);
--shadow-toast: 0 10px 30px rgba(0, 0, 0, .3);
--focus-ring: 2px solid var(--accent-strong);
--focus-offset: 2px;
}
/*
* Stil „Blau": ersetzt nur die Akzent-Tokens.
* Aktivierung per data-accent="blue" am <html>-Element; ohne Attribut gilt Orange.
* Gleiche Theme-Logik wie oben: Dunkel ist Fallback, Hell per Systemeinstellung oder data-theme="light".
*/
:root[data-accent="blue"] {
--accent: #6aa9ff;
--accent-strong: #6aa9ff;
--accent-soft: rgba(106, 169, 255, .14);
--accent-text: #0a1428;
--bg-glow: rgba(106, 169, 255, .10);
}
@media (prefers-color-scheme: light) {
:root[data-accent="blue"]:not([data-theme="dark"]) {
--accent: #3b82f6;
--accent-strong: #1d5fc4;
--accent-soft: rgba(29, 95, 196, .14);
--accent-text: #ffffff;
--bg-glow: rgba(59, 130, 246, .14);
}
}
:root[data-accent="blue"][data-theme="light"] {
--accent: #3b82f6;
--accent-strong: #1d5fc4;
--accent-soft: rgba(29, 95, 196, .14);
--accent-text: #ffffff;
--bg-glow: rgba(59, 130, 246, .14);
}
/* Sichtbarer Tastaturfokus für alle bedienbaren Elemente */
:focus-visible {
outline: var(--focus-ring);
outline-offset: var(--focus-offset);
}

View File

@ -185,12 +185,23 @@
});
}
// Darstellung (System, Dunkel, Hell) aus dem Styleguide; gespeichert wird nur im Browser dieses Geräts.
function themeAnwenden(wurzel) {
wurzel.querySelectorAll("select[data-theme-wahl]:not([data-bereit])").forEach(function (s) {
s.setAttribute("data-bereit", "1");
if (!root.styleguideTheme) { s.hidden = true; return; }
s.value = root.styleguideTheme.get();
s.addEventListener("change", function () { root.styleguideTheme.set(s.value); });
});
}
var geplant = false;
function alles() {
geplant = false;
zeitenAnwenden(document);
tabellenAnwenden(document);
formulareAnwenden(document);
themeAnwenden(document);
}
alles();
// Die Seite erneuert Teile von selbst (data-refresh); neue Zeiten und Tabellen werden nachgezogen.

View File

@ -155,6 +155,8 @@ pub fn routes() -> Router<Arc<AppState>> {
.route("/ui/teil/uebersicht", get(overview_fragment))
.route("/ui/app.js", get(app_js))
.route("/ui/tabellen.js", get(tabellen_js))
.route("/ui/stil/tokens.css", get(stil_tokens))
.route("/ui/stil/theme.js", get(stil_theme))
.route("/ui/app.css", get(app_css))
.route("/ui/favicon.svg", get(favicon))
// PWA (→ #1062): Manifest und Symbole sind ohne Anmeldung lesbar, enthalten
@ -435,7 +437,7 @@ fn head(title: &str) -> String {
<link rel=\"apple-touch-icon\" href=\"/ui/icons/icon-192.png\">\
<meta name=\"theme-color\" content=\"#0f1115\" media=\"(prefers-color-scheme: dark)\">\
<meta name=\"theme-color\" content=\"#f6f3ef\" media=\"(prefers-color-scheme: light)\">\
<link rel=\"stylesheet\" href=\"/ui/app.css\"></head>",
<script src=\"/ui/stil/theme.js\"></script><link rel=\"stylesheet\" href=\"/ui/stil/tokens.css\"><link rel=\"stylesheet\" href=\"/ui/app.css\"></head>",
esc(title)
)
}
@ -486,7 +488,7 @@ pub(crate) fn layout(title: &str, active: &str, viewer: &Viewer, body: &str) ->
<form method=\"post\" action=\"/ui/logout\"><a class=\"chip konto\" href=\"/ui/konto\" title=\"Mein Konto\">{key}</a>{role}\
<button class=\"sm\" type=\"submit\">Abmelden</button></form></div></header>\
<main><h1>{title}</h1>{body}</main>\
<footer>{WORTMARKE} {version} · {mode} · Zeiten in Ortszeit (ohne JavaScript UTC)</footer>\
<footer>{WORTMARKE} {version} · {mode} · Zeiten in Ortszeit (ohne JavaScript UTC) · <label>Darstellung <select data-theme-wahl aria-label=\"Darstellung\"><option value=\"system\">System</option><option value=\"dark\">Dunkel</option><option value=\"light\">Hell</option></select></label></footer>\
<script src=\"/ui/tabellen.js\"></script><script src=\"/ui/app.js\"></script></body></html>",
head = head(title),
title = esc(title),
@ -1098,8 +1100,7 @@ document.addEventListener("click", function (e) {
"#;
const APP_CSS: &str = r#"/* Design nach llm-arena: dunkel als Standard, hell nach Systemeinstellung, Akzent Orange. */
:root{color-scheme:dark;--bg:#0f1115;--bg-glow:rgba(255,155,69,.10);--surface:#181b21;--surface-2:#222630;--text:#eceff4;--muted:#9099a8;--border:#2b303a;--accent:#ff9b45;--accent-soft:rgba(255,155,69,.14);--accent-text:#1a1005;--danger:#ff7b72;--ok:#6fd18a;--warn:#ffcf5c;--radius:14px;--shadow:0 6px 24px rgba(0,0,0,.35);font-family:Inter,"Segoe UI",system-ui,-apple-system,sans-serif;font-size:15px;line-height:1.5;color:var(--text);background:var(--bg);-webkit-text-size-adjust:100%}
@media (prefers-color-scheme:light){:root{color-scheme:light;--bg:#f6f3ef;--bg-glow:rgba(255,155,69,.16);--surface:#fff;--surface-2:#f0ebe4;--text:#1d1a17;--muted:#6b645c;--border:#e2dbd2;--accent:#f08a2c;--accent-soft:rgba(240,138,44,.14);--accent-text:#fff;--danger:#c0392b;--ok:#2e8b57;--warn:#b07d00;--shadow:0 6px 20px rgba(60,40,20,.10)}}
:root{--radius:var(--radius-card);font-family:var(--font-sans);font-size:var(--font-size-base);line-height:var(--line-height-base);color:var(--text);background:var(--bg);-webkit-text-size-adjust:100%}
*{box-sizing:border-box}
body{margin:0;min-height:100vh;background:radial-gradient(ellipse 70rem 28rem at 50% -8rem,var(--bg-glow),transparent),var(--bg);color:var(--text)}
h1,h2,h3{line-height:1.25;margin:0 0 .6rem}h1{font-size:1.5rem;letter-spacing:-.01em;margin:.4rem 0 1.1rem}h2{font-size:1.1rem;letter-spacing:-.01em}
@ -1107,7 +1108,7 @@ a{color:var(--accent)}
header{background:color-mix(in srgb,var(--bg) 82%,transparent);backdrop-filter:blur(10px);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:5}
header .innen{max-width:76rem;margin:0 auto;padding:.7rem 1rem;display:flex;flex-wrap:wrap;align-items:center;gap:.7rem 1.2rem}
.logo{display:inline-flex;align-items:center;gap:.55rem;font-weight:700;font-size:1.1rem;letter-spacing:-.01em;color:var(--text);text-decoration:none}
.wordmark{color:var(--text);font-weight:700}.wordmark-accent{color:var(--accent)}
.wordmark{color:var(--text);font-weight:700}.wordmark-accent{color:var(--accent-strong)}
.logo.gross{font-size:1.5rem;margin-bottom:.8rem}.logo.gross .zeichen{width:40px;height:40px}
header nav{display:flex;flex-wrap:wrap;gap:.3rem;background:var(--surface);border:1px solid var(--border);border-radius:999px;padding:.25rem}
header nav a{border-radius:999px;padding:.35rem .65rem;color:var(--muted);text-decoration:none}
@ -1190,9 +1191,15 @@ dl.daten dd{margin:0;overflow-wrap:anywhere}dl.daten .breit-zeile{grid-column:1/
pre.befehl{margin:0;padding:.6rem .8rem;background:var(--bg);border:1px solid var(--border);border-radius:10px;font-family:ui-monospace,"JetBrains Mono",Menlo,monospace;font-size:.82rem;white-space:pre-wrap;overflow-wrap:anywhere}
.engine h2{margin:0}.chips{display:flex;flex-wrap:wrap;gap:.35rem;margin:.7rem 0 .2rem}
.engine .zeile{gap:.5rem .7rem}
footer label{display:inline-flex;gap:.35rem;align-items:center}footer select{padding:.15rem .4rem;font-size:.8rem}
.tabellenleiste{display:flex;flex-wrap:wrap;gap:.5rem .7rem;align-items:center;margin:0 0 .7rem}.tabellenleiste input[type=search]{min-width:12rem}
th.sortierbar{cursor:pointer;user-select:none}th.sortierbar:hover{color:var(--text)}
th[aria-sort=ascending]::after{content:" ▲";color:var(--accent)}th[aria-sort=descending]::after{content:" ▼";color:var(--accent)}
/* Playground (#1098): Einstellungen fest oben, Eingabe fest unten, nur der Verlauf scrollt. */
#chat{display:flex;flex-direction:column;height:calc(100vh - 13rem);height:calc(100dvh - 13rem);min-height:22rem;margin-bottom:.6rem}
#chat .verlauf{flex:1 1 auto;min-height:0;overflow-y:auto;margin:.8rem 0}
#chat>.zeile,#chat>form{flex:0 0 auto}
@media (max-width:40rem){#chat{height:calc(100vh - 10.5rem);height:calc(100dvh - 10.5rem)}}
@media (max-width:40rem){header .innen{gap:.6rem 1rem}header form{margin-left:auto}header nav{order:3;width:100%;flex-wrap:nowrap;overflow-x:auto}
header nav a{padding:.3rem .8rem;white-space:nowrap}h1{font-size:1.3rem}.card{padding:.9rem 1rem}}
"#;
@ -1200,6 +1207,24 @@ header nav a{padding:.3rem .8rem;white-space:nowrap}h1{font-size:1.3rem}.card{pa
/// Ortszeit und Filtern/Sortieren der Tabellen (#1082, #1085), Quelle in `assets/tabellen.js`.
const TABELLEN_JS: &str = include_str!("../assets/tabellen.js");
/// Design-Tokens und Theme-Auswahl aus dem gemeinsamen Styleguide (`wlkns-dev/stylguide`, #1075, #1089).
const STIL_TOKENS: &str = include_str!("../assets/stil/tokens.css");
const STIL_THEME: &str = include_str!("../assets/stil/theme.js");
async fn stil_tokens() -> Response {
secure(Response::builder())
.header(CONTENT_TYPE, "text/css; charset=utf-8")
.body(Body::from(STIL_TOKENS))
.unwrap_or_default()
}
async fn stil_theme() -> Response {
secure(Response::builder())
.header(CONTENT_TYPE, "text/javascript; charset=utf-8")
.body(Body::from(STIL_THEME))
.unwrap_or_default()
}
async fn tabellen_js() -> Response {
secure(Response::builder())
.header(CONTENT_TYPE, "text/javascript; charset=utf-8")

View File

@ -1163,6 +1163,47 @@ async fn pwa_manifest_und_symbole_sind_ohne_sitzung_lesbar() {
assert!(!login.contains("serviceWorker"));
}
#[tokio::test]
async fn styleguide_tokens_theme_und_playground_layout_sind_eingebunden() {
let gw = gateway(0, false).await;
let cookie = ui_cookie(&gw).await;
// Tokens und Theme-Skript des Styleguides liegen wie app.css ohne Anmeldung bereit.
let (status, headers, css) = ui_get(&gw, "/ui/stil/tokens.css", None).await;
assert_eq!(status, 200);
assert!(
headers["content-type"]
.to_str()
.unwrap()
.starts_with("text/css")
);
assert!(css.contains("--accent-strong") && css.contains("data-theme"));
let (status, headers, js) = ui_get(&gw, "/ui/stil/theme.js", None).await;
assert_eq!(status, 200);
assert!(
headers["content-type"]
.to_str()
.unwrap()
.starts_with("text/javascript")
);
assert!(js.contains("styleguideTheme"));
// Jede Seite bindet beide ein und bietet die Darstellung (System, Dunkel, Hell) an.
let (_, _, seite) = ui_get(&gw, "/ui/modelle", Some(&cookie)).await;
assert!(
seite.contains("href=\"/ui/stil/tokens.css\"")
&& seite.contains("src=\"/ui/stil/theme.js\"")
);
assert!(seite.contains("data-theme-wahl"));
// Die Farbwerte kommen aus den Tokens, nicht mehr aus app.css.
let (_, _, app) = ui_get(&gw, "/ui/app.css", None).await;
assert!(
!app.contains("--accent-text:#1a1005"),
"app.css trägt noch eigene Farbwerte"
);
// Playground: Einstellungen und Eingabe bleiben stehen, nur der Verlauf scrollt (#1098).
assert!(app.contains("#chat{display:flex;flex-direction:column"));
assert!(app.contains("#chat .verlauf{flex:1 1 auto;min-height:0;overflow-y:auto"));
}
#[tokio::test]
async fn tabellen_skript_mit_ortszeit_und_filter_ist_eingebunden() {
let gw = gateway(0, false).await;