From 84cc3e65d62fbb0c36fc852d36a7d260d9785d48 Mon Sep 17 00:00:00 2001 From: Orual Date: Sun, 11 Jan 2026 15:58:28 -0500 Subject: [PATCH] [weaver-renderer] add built-in themes behind feature flag --- crates/weaver-renderer/Cargo.toml | 2 + crates/weaver-renderer/src/lib.rs | 2 + .../weaver-renderer/src/themes/code_themes.rs | 65 ++++++++++++ .../src/themes/colour_schemes.rs | 98 +++++++++++++++++++ crates/weaver-renderer/src/themes/mod.rs | 9 ++ 5 files changed, 176 insertions(+) create mode 100644 crates/weaver-renderer/src/themes/code_themes.rs create mode 100644 crates/weaver-renderer/src/themes/colour_schemes.rs create mode 100644 crates/weaver-renderer/src/themes/mod.rs diff --git a/crates/weaver-renderer/Cargo.toml b/crates/weaver-renderer/Cargo.toml index 156ddf9..d0c4b79 100644 --- a/crates/weaver-renderer/Cargo.toml +++ b/crates/weaver-renderer/Cargo.toml @@ -12,6 +12,8 @@ pckt = [] syntax-highlighting = ["dep:syntect"] # CSS generation from themes (css.rs) - native only, needs plist + themes syntax-css = ["syntax-highlighting"] +# Built-in colour schemes and code themes for UI selection (server only) +themes = [] [dependencies] n0-future.workspace = true diff --git a/crates/weaver-renderer/src/lib.rs b/crates/weaver-renderer/src/lib.rs index 5d983c4..f4bd9eb 100644 --- a/crates/weaver-renderer/src/lib.rs +++ b/crates/weaver-renderer/src/lib.rs @@ -38,6 +38,8 @@ pub mod pckt; #[cfg(all(not(target_family = "wasm"), feature = "syntax-highlighting"))] pub mod static_site; pub mod theme; +#[cfg(feature = "themes")] +pub mod themes; pub mod types; pub mod utils; #[cfg(not(target_family = "wasm"))] diff --git a/crates/weaver-renderer/src/themes/code_themes.rs b/crates/weaver-renderer/src/themes/code_themes.rs new file mode 100644 index 0000000..41b3307 --- /dev/null +++ b/crates/weaver-renderer/src/themes/code_themes.rs @@ -0,0 +1,65 @@ +//! Built-in code syntax highlighting themes. + +/// A built-in code theme definition. +#[derive(Debug, Clone)] +pub struct BuiltinCodeTheme { + /// Unique identifier matching the syntect theme name. + pub id: &'static str, + /// Human-readable name. + pub name: &'static str, + /// Whether this is "dark" or "light". + pub variant: &'static str, +} + +/// All built-in code themes available for selection. +/// +/// These include embedded themes (rose-pine variants) and syntect's default themes. +pub static BUILTIN_CODE_THEMES: &[BuiltinCodeTheme] = &[ + // Embedded themes (always available). + BuiltinCodeTheme { + id: "rose-pine", + name: "Rose Pine", + variant: "dark", + }, + BuiltinCodeTheme { + id: "rose-pine-dawn", + name: "Rose Pine Dawn", + variant: "light", + }, + // Syntect default themes. + BuiltinCodeTheme { + id: "base16-ocean.dark", + name: "Base16 Ocean", + variant: "dark", + }, + BuiltinCodeTheme { + id: "base16-eighties.dark", + name: "Base16 Eighties", + variant: "dark", + }, + BuiltinCodeTheme { + id: "base16-mocha.dark", + name: "Base16 Mocha", + variant: "dark", + }, + BuiltinCodeTheme { + id: "base16-ocean.light", + name: "Base16 Ocean Light", + variant: "light", + }, + BuiltinCodeTheme { + id: "InspiredGitHub", + name: "Inspired GitHub", + variant: "light", + }, + BuiltinCodeTheme { + id: "Solarized (dark)", + name: "Solarized Dark", + variant: "dark", + }, + BuiltinCodeTheme { + id: "Solarized (light)", + name: "Solarized Light", + variant: "light", + }, +]; diff --git a/crates/weaver-renderer/src/themes/colour_schemes.rs b/crates/weaver-renderer/src/themes/colour_schemes.rs new file mode 100644 index 0000000..b2b73bb --- /dev/null +++ b/crates/weaver-renderer/src/themes/colour_schemes.rs @@ -0,0 +1,98 @@ +//! Built-in colour schemes for notebook theming. + +use std::sync::LazyLock; +use weaver_api::sh_weaver::notebook::colour_scheme::ColourSchemeColours; +use weaver_common::jacquard::CowStr; + +/// A built-in colour scheme definition. +#[derive(Debug, Clone)] +pub struct BuiltinColourScheme { + /// Unique identifier for this scheme. + pub id: &'static str, + /// Human-readable name. + pub name: &'static str, + /// Whether this is "dark" or "light". + pub variant: &'static str, + /// The actual colour values. + pub colours: ColourSchemeColours<'static>, +} + +/// All built-in colour schemes available for selection. +pub static BUILTIN_COLOUR_SCHEMES: LazyLock> = LazyLock::new(|| { + vec![ + BuiltinColourScheme { + id: "rose-pine", + name: "Rose Pine", + variant: "dark", + colours: ColourSchemeColours { + base: CowStr::new_static("#191724"), + surface: CowStr::new_static("#1f1d2e"), + overlay: CowStr::new_static("#26233a"), + text: CowStr::new_static("#e0def4"), + muted: CowStr::new_static("#6e6a86"), + subtle: CowStr::new_static("#908caa"), + emphasis: CowStr::new_static("#e0def4"), + primary: CowStr::new_static("#c4a7e7"), + secondary: CowStr::new_static("#9ccfd8"), + tertiary: CowStr::new_static("#ebbcba"), + error: CowStr::new_static("#eb6f92"), + warning: CowStr::new_static("#f6c177"), + success: CowStr::new_static("#31748f"), + border: CowStr::new_static("#403d52"), + link: CowStr::new_static("#ebbcba"), + highlight: CowStr::new_static("#524f67"), + extra_data: None, + }, + }, + BuiltinColourScheme { + id: "rose-pine-moon", + name: "Rose Pine Moon", + variant: "dark", + colours: ColourSchemeColours { + base: CowStr::new_static("#232136"), + surface: CowStr::new_static("#2a273f"), + overlay: CowStr::new_static("#393552"), + text: CowStr::new_static("#e0def4"), + muted: CowStr::new_static("#6e6a86"), + subtle: CowStr::new_static("#908caa"), + emphasis: CowStr::new_static("#e0def4"), + primary: CowStr::new_static("#c4a7e7"), + secondary: CowStr::new_static("#9ccfd8"), + tertiary: CowStr::new_static("#ea9a97"), + error: CowStr::new_static("#eb6f92"), + warning: CowStr::new_static("#f6c177"), + success: CowStr::new_static("#3e8fb0"), + border: CowStr::new_static("#44415a"), + link: CowStr::new_static("#ea9a97"), + highlight: CowStr::new_static("#56526e"), + extra_data: None, + }, + }, + BuiltinColourScheme { + id: "rose-pine-dawn", + name: "Rose Pine Dawn", + variant: "light", + colours: ColourSchemeColours { + base: CowStr::new_static("#faf4ed"), + surface: CowStr::new_static("#fffaf3"), + overlay: CowStr::new_static("#f2e9e1"), + // Text colors darkened for better contrast. + text: CowStr::new_static("#1f1d2e"), + muted: CowStr::new_static("#635e74"), + subtle: CowStr::new_static("#4a4560"), + emphasis: CowStr::new_static("#1e1a2d"), + // Accent colors at original Rose Pine Dawn values. + primary: CowStr::new_static("#907aa9"), + secondary: CowStr::new_static("#56949f"), + tertiary: CowStr::new_static("#286983"), + error: CowStr::new_static("#b4637a"), + warning: CowStr::new_static("#ea9d34"), + success: CowStr::new_static("#286983"), + border: CowStr::new_static("#dfdad9"), + link: CowStr::new_static("#d7827e"), + highlight: CowStr::new_static("#cecacd"), + extra_data: None, + }, + }, + ] +}); diff --git a/crates/weaver-renderer/src/themes/mod.rs b/crates/weaver-renderer/src/themes/mod.rs new file mode 100644 index 0000000..04cfaa3 --- /dev/null +++ b/crates/weaver-renderer/src/themes/mod.rs @@ -0,0 +1,9 @@ +//! Built-in themes for notebooks (server-only). +//! +//! Gated behind the `themes` feature to avoid bloating WASM bundles. + +mod code_themes; +mod colour_schemes; + +pub use code_themes::{BuiltinCodeTheme, BUILTIN_CODE_THEMES}; +pub use colour_schemes::{BuiltinColourScheme, BUILTIN_COLOUR_SCHEMES}; -- knotmirror 0.0.1