Skip to main content

palette_core/
lib.rs

1//! TOML-defined theme system with inheritance and multi-target export.
2//!
3//! palette-core parses theme files written in TOML, resolves single-level
4//! inheritance between variants, and produces a [`Palette`] — a typed color
5//! map covering base, semantic, syntax, editor, diff, surface, typography,
6//! and terminal-ANSI slots.
7//!
8//! # Quick start
9//!
10//! ```
11//! use palette_core::{load_preset, Registry};
12//!
13//! // Load a built-in theme (returns PaletteError on unknown ID)
14//! let palette = load_preset("catppuccin").unwrap();
15//!
16//! // Same API, different preset
17//! let palette = load_preset("tokyonight").unwrap();
18//!
19//! // Registry: built-ins + custom themes from disk
20//! let mut reg = Registry::new();
21//! if let Err(e) = reg.add_dir("./my-themes".as_ref()) {
22//!     eprintln!("failed to load custom themes: {e}");
23//! }
24//! for info in reg.list() {
25//!     println!("{}: {}", info.id, info.name);
26//! }
27//! ```
28//!
29//! # Export targets
30//!
31//! | Target | Feature | Function |
32//! |--------|---------|----------|
33//! | CSS custom properties | — | [`Palette::to_css`](css) |
34//! | JSON snapshot | `snapshot` | [`Palette::to_json`](snapshot) |
35//! | ratatui `Color` | `terminal` | [`terminal::to_terminal_theme`] |
36//! | egui `Visuals` | `egui` | [`egui::to_egui_visuals`] |
37//! | syntect `Theme` | `syntect` | [`syntect::to_syntect_theme`] |
38//! | WASM/JS bindings | `wasm` | `wasm` module |
39
40/// 8-bit RGB color type and hex parsing.
41pub mod color;
42/// Error types for theme loading and parsing.
43pub mod error;
44/// Raw TOML manifest types before color resolution.
45pub mod manifest;
46/// Single-level manifest inheritance (variant over base).
47pub mod merge;
48/// Resolved color palette and color-group structs.
49pub mod palette;
50/// Built-in preset registry and theme discovery.
51pub mod registry;
52
53/// WCAG 2.1 contrast ratio checking and palette validation.
54pub mod contrast;
55/// CSS custom-property export.
56pub mod css;
57/// Multi-stop color gradient with perceptual interpolation.
58pub mod gradient;
59/// HSL color manipulation: lighten, darken, saturate, blend.
60pub mod manipulation;
61
62pub use color::Color;
63pub use contrast::ContrastLevel;
64pub use error::PaletteError;
65pub use gradient::{ColorSpace, Gradient, GradientColor, GradientDef, GradientStop};
66pub use palette::{GradientDefs, Palette, PaletteMeta};
67pub use registry::{Registry, ThemeInfo, load_preset, load_preset_file, preset_ids};
68
69/// Text style modifiers for syntax tokens.
70pub mod style;
71
72/// Resolved palette types with concrete Color fields.
73pub mod resolved;
74pub use resolved::ResolvedPalette;
75pub use style::StyleModifiers;
76
77#[cfg(feature = "terminal")]
78pub mod terminal;
79
80#[cfg(feature = "platform")]
81pub mod platform;
82
83#[cfg(feature = "snapshot")]
84pub mod snapshot;
85
86#[cfg(feature = "egui")]
87pub mod egui;
88
89/// syntect `Theme` generation from resolved palettes.
90#[cfg(feature = "syntect")]
91pub mod syntect;
92
93#[cfg(feature = "wasm")]
94pub mod wasm;