diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 08:42:30 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 08:42:30 +0100 |
| commit | aab6af1601fa4cdb9b351987220f32de062d4b2c (patch) | |
| tree | e5d2b4b6af7e5d8fd8d19717786ed0f29b619b0f /crates/wipfel/src/bridge.rs | |
| parent | d57f022243850b532239ae08dd75717f55415fbf (diff) | |
web: follow system light/dark preference
All colors moved into CSS custom properties on :root (dark default)
with a prefers-color-scheme: light override block. The two canvas-
drawn surfaces follow too: the viewport now clears transparent so the
CSS canvas background shows through, and the compass strip reads its
colors from the same variables via a new bridge::css_var helper.
theme-color metas (dark + light variants) tint mobile browser chrome
to match.
Diffstat (limited to 'crates/wipfel/src/bridge.rs')
| -rw-r--r-- | crates/wipfel/src/bridge.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/wipfel/src/bridge.rs b/crates/wipfel/src/bridge.rs index 6dbba93..0f252c1 100644 --- a/crates/wipfel/src/bridge.rs +++ b/crates/wipfel/src/bridge.rs @@ -67,3 +67,15 @@ pub fn ctx2d(canvas: &HtmlCanvasElement) -> Option<CanvasRenderingContext2d> { .flatten() .and_then(|c| c.dyn_into::<CanvasRenderingContext2d>().ok()) } + +/// Read a CSS custom property from :root (follows the active +/// prefers-color-scheme), with a fallback when unavailable. +pub fn css_var(name: &str, fallback: &str) -> String { + window() + .document() + .and_then(|d| window().get_computed_style(&d.document_element()?).ok().flatten()) + .and_then(|s| s.get_property_value(name).ok()) + .map(|v| v.trim().to_string()) + .filter(|v| !v.is_empty()) + .unwrap_or_else(|| fallback.to_string()) +} |
