farbschema angepasst

This commit is contained in:
Bernd Reuther committed 2026-10-05 17:37:16 +02:00
1 parent 4503819d13
commit 38ddf6d870
2 files changed
+150 -110

No files matched your search

+89 -97
View File
@@ -45,7 +45,58 @@ DEFAULT_SETTINGS = {
"favicon_file": os.environ.get("FAVICON_FILE", ""),
}
DEFAULT_THEME = {'background': '#111', 'surface': '#181818', 'surface_alt': '#222', 'surface_dark': '#0b0b0b', 'text': '#eee', 'text_secondary': '#ccc', 'text_muted': '#aaa', 'text_faint': '#777', 'border': '#333', 'border_subtle': '#2b2b2b', 'control': '#333', 'control_hover': '#444', 'primary': '#1769aa', 'primary_hover': '#1f7fc2', 'accent': '#ffcc33', 'success': '#173d24', 'success_text': '#b8f5c9', 'warning': '#6b4e00', 'danger': '#8b0000', 'danger_soft': '#4a2020', 'danger_soft_hover': '#6a2b2b', 'error': '#4a1b1b', 'error_text': '#ffd0d0', 'recording': '#b00000', 'recording_border': '#3a2222', 'selection': 'rgba(80,150,255,.16)', 'shadow': '#000', 'scroll_thumb': '#777', 'scroll_thumb_hover': '#999', 'scroll_thumb_active': '#aaa', 'live_surface': '#1d1111', 'table_header': '#252525', 'table_text': '#eee', 'footer': '#666', 'white': '#fff','surface_modal':'#202020','overlay':'rgba(0,0,0,.78)'}
BASE_THEME = {
"background": "#111111", "surface": "#181818", "text": "#eeeeee",
"text_secondary": "#cccccc", "primary": "#1769aa", "accent": "#ffcc33",
"success": "#2e7d32", "warning": "#ed6c02", "danger": "#d32f2f",
}
BASE_COLOR_LABELS = {
"background": "Hintergrund", "surface": "Flächen", "text": "Text",
"text_secondary": "Sekundärtext", "primary": "Primärfarbe", "accent": "Akzentfarbe",
"success": "Erfolg", "warning": "Warnung", "danger": "Fehler / Gefahr",
}
def _hex_rgb(value):
if not isinstance(value, str) or not re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()): return None
value = value.strip(); return tuple(int(value[i:i+2], 16) for i in (1, 3, 5))
def _rgb_hex(rgb):
return "#%02x%02x%02x" % tuple(max(0, min(255, round(v))) for v in rgb)
def _mix(a, b, amount):
ra, rb = _hex_rgb(a), _hex_rgb(b)
if ra is None or rb is None: return a
return _rgb_hex(tuple(x + (y - x) * amount for x, y in zip(ra, rb)))
def _lighten(value, amount): return _mix(value, "#ffffff", amount)
def _darken(value, amount): return _mix(value, "#000000", amount)
def derive_theme(base):
c = dict(BASE_THEME)
if isinstance(base, dict):
for key in BASE_THEME:
value = base.get(key)
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()): c[key] = value.strip()
bg, surface = c["background"], c["surface"]
text, secondary = c["text"], c["text_secondary"]
primary, accent = c["primary"], c["accent"]
success, warning, danger = c["success"], c["warning"], c["danger"]
return {
"background": bg, "surface": surface, "surface_alt": _lighten(surface,.12), "surface_dark": _darken(bg,.22),
"text": text, "text_secondary": secondary, "text_muted": _mix(secondary,bg,.35), "text_faint": _mix(secondary,bg,.58),
"border": _lighten(surface,.28), "border_subtle": _lighten(surface,.16), "control": _lighten(surface,.12), "control_hover": _lighten(surface,.24),
"primary": primary, "primary_hover": _lighten(primary,.16), "accent": accent,
"success": _darken(success,.42), "success_text": _lighten(success,.68), "warning": _darken(warning,.48),
"danger": danger, "danger_soft": _darken(danger,.58), "danger_soft_hover": _darken(danger,.42),
"error": _darken(danger,.62), "error_text": _lighten(danger,.70), "recording": _darken(danger,.08), "recording_border": _darken(danger,.52),
"selection": "rgba(80,150,255,.16)", "shadow": "#000000", "scroll_thumb": _mix(secondary,bg,.35),
"scroll_thumb_hover": _mix(secondary,bg,.18), "scroll_thumb_active": secondary, "live_surface": _mix(danger,bg,.84),
"table_header": _lighten(surface,.08), "table_text": text, "footer": _mix(secondary,bg,.50), "white": "#ffffff",
"surface_modal": _lighten(surface,.05), "overlay": "rgba(0,0,0,.78)",
}
DEFAULT_THEME = derive_theme(BASE_THEME)
def load_settings():
"""Load UI/branding settings, falling back to environment defaults."""
@@ -65,29 +116,26 @@ def load_settings():
def load_theme():
"""Load semantic theme colors from settings, then theme.json, then defaults."""
theme = dict(DEFAULT_THEME)
# Keep the existing theme.json as a backwards-compatible fallback.
"""Load the base palette and derive all semantic colors."""
base = dict(BASE_THEME)
if THEME_FILE.is_file():
try:
data = json.loads(THEME_FILE.read_text(encoding="utf-8"))
colors = data.get("colors", data) if isinstance(data, dict) else {}
if isinstance(colors, dict):
for key in theme:
for key in BASE_THEME:
value = colors.get(key)
if isinstance(value, str) and re.fullmatch(r"(?:#[0-9a-fA-F]{3,8}|rgba?\([^)]*\))", value.strip()):
theme[key] = value.strip()
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()):
base[key] = value.strip()
except Exception as exc:
print(f"[branding] Theme konnte nicht geladen werden: {exc}", flush=True)
settings = load_settings()
colors = settings.get("colors") if isinstance(settings.get("colors"), dict) else {}
for key in theme:
for key in BASE_THEME:
value = colors.get(key)
if isinstance(value, str) and re.fullmatch(r"(?:#[0-9a-fA-F]{3,8}|rgba?\([^)]*\))", value.strip()):
theme[key] = value.strip()
return theme
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()):
base[key] = value.strip()
return derive_theme(base)
def theme_css():
@@ -1925,11 +1973,12 @@ a { color:var(--color-text-secondary); }
.field input { width:100%; padding:9px 10px; background:var(--color-control); color:var(--color-text); border:1px solid var(--color-control-hover); border-radius:5px; font-size:15px; }
.field.full { grid-column:1/-1; }
.color-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px 18px; }
.color-field { display:grid; grid-template-columns:minmax(0,1fr) 52px; gap:10px; align-items:end; padding:10px; background:var(--color-surface-alt); border:1px solid var(--color-border-subtle); border-radius:7px; }
.color-field .text-wrap { min-width:0; }
.color-field label { display:flex; align-items:flex-end; min-height:2.5em; margin-bottom:6px; color:var(--color-text-muted); font-size:13px; line-height:1.25; }
.color-field input:not([type=color]) { width:100%; min-width:0; padding:9px 10px; background:var(--color-control); color:var(--color-text); border:1px solid var(--color-control-hover); border-radius:5px; font-size:14px; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }
.color-field input[type=color] { width:52px; height:40px; padding:3px; background:var(--color-control); border:1px solid var(--color-control-hover); border-radius:5px; cursor:pointer; }
.color-field { padding:12px; background:var(--color-surface-alt); border:1px solid var(--color-border-subtle); border-radius:7px; }
.color-field label { display:block; min-height:2.4em; margin-bottom:7px; color:var(--color-text-muted); font-size:13px; line-height:1.25; }
.color-input-row { display:grid; grid-template-columns:minmax(0,1fr) 48px; gap:8px; align-items:center; }
.color-field input:not([type=color]) { width:100%; min-width:0; height:40px; padding:8px 10px; background:var(--color-control); color:var(--color-text); border:1px solid var(--color-control-hover); border-radius:5px; font-size:14px; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }
.color-field input[type=color] { width:48px; height:40px; padding:3px; background:var(--color-control); border:1px solid var(--color-control-hover); border-radius:5px; cursor:pointer; }
.theme-intro { margin:-4px 0 16px; color:var(--color-text-muted); font-size:14px; line-height:1.45; }
.actions { display:flex; gap:10px; flex-wrap:wrap; margin-top:20px; }
button { border:0; border-radius:5px; padding:10px 16px; background:var(--color-primary); color:var(--color-white); font-size:15px; cursor:pointer; }
button:hover { background:var(--color-primary-hover); }
@@ -1968,15 +2017,19 @@ button:hover { background:var(--color-primary-hover); }
<div class="section">
<h2>Farbschema</h2>
<p class="theme-intro">Nur die wichtigsten Grundfarben werden festgelegt. Rahmen, Hover-Farben, Flächen, Statusfarben und weitere UI-Farben werden daraus automatisch abgeleitet.</p>
<div class="color-grid">
{% for key, label, value, picker in color_fields %}
<div class="color-field">
<div class="text-wrap"><label for="color_{{ key }}">{{ label }}</label><input id="color_{{ key }}" name="color_{{ key }}" value="{{ value }}"></div>
{% if picker %}<input type="color" value="{{ picker }}" data-target="color_{{ key }}" aria-label="{{ label }} Farbe">{% else %}<span></span>{% endif %}
<label for="color_{{ key }}">{{ label }}</label>
<div class="color-input-row">
<input id="color_{{ key }}" name="color_{{ key }}" value="{{ value }}" maxlength="7" pattern="#[0-9a-fA-F]{6}">
<input type="color" value="{{ picker }}" data-target="color_{{ key }}" aria-label="{{ label }} Farbe">
</div>
</div>
{% endfor %}
</div>
<div class="note">Erlaubt sind Hex-Farben sowie rgba()/rgb()-Werte. Änderungen werden nach dem Speichern auf Editor und Benutzerseite verwendet.</div>
<div class="note">Bitte Hex-Farben im Format #RRGGBB verwenden. Die abgeleiteten Farben werden automatisch berechnet.</div>
</div>
<div class="actions"><button type="submit">Einstellungen speichern</button><a class="back" href="/">Abbrechen</a></div>
@@ -1998,96 +2051,35 @@ document.querySelectorAll('input[type=color][data-target]').forEach(picker => {
# ---------------------------------------------------------------------------
# Routes
# ---------------------------------------------------------------------------
COLOR_LABELS = {
"background": "Hintergrund",
"surface": "Fläche",
"surface_alt": "Alternative Fläche",
"surface_dark": "Dunkle Fläche",
"text": "Text",
"text_secondary": "Sekundärtext",
"text_muted": "Gedämpfter Text",
"text_faint": "Schwacher Text",
"border": "Rahmen",
"border_subtle": "Feiner Rahmen",
"control": "Steuerelement",
"control_hover": "Steuerelement Hover",
"primary": "Primärfarbe",
"primary_hover": "Primärfarbe Hover",
"accent": "Akzent",
"success": "Erfolg",
"success_text": "Erfolgstext",
"warning": "Warnung",
"danger": "Gefahr",
"danger_soft": "Gefahr Fläche",
"danger_soft_hover": "Gefahr Fläche Hover",
"error": "Fehler",
"error_text": "Fehlertext",
"recording": "Aufnahme",
"recording_border": "Aufnahme Rahmen",
"selection": "Auswahl",
"shadow": "Schatten",
"scroll_thumb": "Scrollbalken",
"scroll_thumb_hover": "Scrollbalken Hover",
"scroll_thumb_active": "Scrollbalken aktiv",
"live_surface": "Live-Fläche",
"table_header": "Tabellenkopf",
"table_text": "Tabellentext",
"footer": "Footer",
"white": "Weiß",
"surface_modal": "Dialogfläche",
"overlay": "Overlay",
}
def build_color_fields(colors):
fields = []
for key in DEFAULT_THEME:
value = colors.get(key, DEFAULT_THEME[key]) if isinstance(colors, dict) else DEFAULT_THEME[key]
picker = value if re.fullmatch(r"#[0-9a-fA-F]{6}", value) else None
fields.append((key, COLOR_LABELS.get(key, key), value, picker))
return fields
base = {key: colors.get(key, BASE_THEME[key]) for key in BASE_THEME} if isinstance(colors, dict) else dict(BASE_THEME)
return [(key, BASE_COLOR_LABELS[key], base[key], base[key]) for key in BASE_THEME]
@app.route("/settings", methods=["GET", "POST"])
def settings():
settings = load_settings()
saved = False
if request.method == "POST":
for key in DEFAULT_SETTINGS:
settings[key] = request.form.get(key, "").strip()
colors = {}
current_theme = load_theme()
for key in DEFAULT_THEME:
value = request.form.get(f"color_{key}", current_theme[key]).strip()
if re.fullmatch(r"(?:#[0-9a-fA-F]{3,8}|rgba?\([^)]*\))", value):
colors[key] = value
else:
colors[key] = current_theme[key]
settings["colors"] = colors
old_colors = settings.get("colors") if isinstance(settings.get("colors"), dict) else {}
base = {}
for key in BASE_THEME:
value = request.form.get(f"color_{key}", old_colors.get(key, BASE_THEME[key])).strip()
if not re.fullmatch(r"#[0-9a-fA-F]{6}", value):
value = old_colors.get(key, current_theme.get(key, BASE_THEME[key]))
if not re.fullmatch(r"#[0-9a-fA-F]{6}", value):
value = BASE_THEME[key]
base[key] = value
settings["colors"] = base
try:
save_settings(settings)
except OSError as exc:
return render_template_string(
SETTINGS_HTML,
settings=settings,
saved=False,
color_fields=build_color_fields(colors),
**branding_context(),
error=f"Einstellungen konnten nicht gespeichert werden: {exc}",
), 500
return render_template_string(SETTINGS_HTML, settings=settings, saved=False, color_fields=build_color_fields(base), **branding_context(), error=f"Einstellungen konnten nicht gespeichert werden: {exc}"), 500
saved = True
colors = settings.get("colors") if isinstance(settings.get("colors"), dict) else load_theme()
return render_template_string(
SETTINGS_HTML,
settings=settings,
saved=saved,
color_fields=build_color_fields(colors),
**branding_context(),
)
colors = settings.get("colors") if isinstance(settings.get("colors"), dict) else BASE_THEME
return render_template_string(SETTINGS_HTML, settings=settings, saved=saved, color_fields=build_color_fields(colors), **branding_context())
@app.route("/branding/logo")