Skip to main content

Crate palette_core

Crate palette_core 

Source
Expand description

TOML-defined theme system with inheritance and multi-target export.

palette-core parses theme files written in TOML, resolves single-level inheritance between variants, and produces a Palette — a typed color map covering base, semantic, syntax, editor, diff, surface, typography, and terminal-ANSI slots.

§Quick start

use palette_core::{load_preset, Registry};

// Load a built-in theme (returns PaletteError on unknown ID)
let palette = load_preset("catppuccin").unwrap();

// Same API, different preset
let palette = load_preset("tokyonight").unwrap();

// Registry: built-ins + custom themes from disk
let mut reg = Registry::new();
if let Err(e) = reg.add_dir("./my-themes".as_ref()) {
    eprintln!("failed to load custom themes: {e}");
}
for info in reg.list() {
    println!("{}: {}", info.id, info.name);
}

§Export targets

TargetFeatureFunction
CSS custom propertiesPalette::to_css
JSON snapshotsnapshotPalette::to_json
ratatui Colorterminalterminal::to_terminal_theme
egui Visualseguiegui::to_egui_visuals
syntect Themesyntectsyntect::to_syntect_theme
WASM/JS bindingswasmwasm module

Re-exports§

pub use color::Color;
pub use contrast::ContrastLevel;
pub use error::PaletteError;
pub use gradient::ColorSpace;
pub use gradient::Gradient;
pub use gradient::GradientColor;
pub use gradient::GradientDef;
pub use gradient::GradientStop;
pub use palette::GradientDefs;
pub use palette::Palette;
pub use palette::PaletteMeta;
pub use registry::Registry;
pub use registry::ThemeInfo;
pub use registry::load_preset;
pub use registry::load_preset_file;
pub use registry::preset_ids;
pub use resolved::ResolvedPalette;
pub use style::StyleModifiers;

Modules§

color
8-bit RGB color type and hex parsing.
contrast
WCAG 2.1 contrast ratio checking and palette validation.
css
CSS custom-property export.
egui
egui integration: apply a Palette to egui’s Visuals.
error
Error types for theme loading and parsing.
gradient
Multi-stop color gradient with perceptual interpolation. Multi-stop color gradients with perceptual interpolation.
manifest
Raw TOML manifest types before color resolution.
manipulation
HSL color manipulation: lighten, darken, saturate, blend.
merge
Single-level manifest inheritance (variant over base).
palette
Resolved color palette and color-group structs.
platform
Platform-specific color overrides (e.g. macOS, Windows, Linux).
registry
Built-in preset registry and theme discovery.
resolved
Resolved palette types with concrete Color fields. Resolved palette types with concrete Color fields.
snapshot
JSON serialization for palettes.
style
Text style modifiers for syntax tokens. Text style modifiers for syntax tokens.
syntect
syntect Theme generation from resolved palettes. Convert a resolved palette into a syntect Theme.
terminal
Ratatui integration: convert a Palette into terminal-native colors.