Skip to main content

ishou_render/
lib.rs

1//! ishou-render — target-specific renderers from `ishou_tokens::TokenSet`.
2//!
3//! Every renderer is a pure function: `TokenSet → String`. Determinism is a
4//! test invariant — same tokens produce byte-identical output.
5//!
6//! Morphism table (identical in spirit to arch-synthesizer's morphism graph):
7//!
8//! | Source         | Target                                 | Module       |
9//! |----------------|----------------------------------------|--------------|
10//! | `TokenSet`     | CSS custom properties + utility classes | `css`        |
11//! | `TokenSet`     | tailwind.config.js                     | `tailwind`   |
12//! | `TokenSet`     | SCSS variables                         | `scss`       |
13//! | `TokenSet`     | Rust `pub const` module                | `rust`       |
14//! | `TokenSet`     | W3C Design Tokens JSON                 | `json`       |
15//! | `TokenSet`     | GLSL `#define` header                  | `glsl`       |
16//! | `TokenSet`     | Ghostty config block                   | `ghostty`    |
17//! | `TokenSet`     | TUI ratatui / crossterm Color table    | `tui`        |
18//! | `TokenSet`     | SVG (brand mark + swerve)              | `svg`        |
19//! | `TokenSet`     | stylix base16 YAML                     | `stylix`     |
20//! | `TokenSet`     | base16 bat `.tmTheme` (Sublime plist)  | `bat`        |
21
22pub mod base16_nix;
23pub mod bat;
24pub mod css;
25pub mod fleet_fonts;
26pub mod ghostty;
27pub mod glsl;
28pub mod json;
29pub mod md3;
30pub mod mono;
31pub mod nix;
32pub mod nix_ast;
33pub mod rust;
34pub mod scss;
35pub mod stylix;
36pub mod stylix_fonts;
37pub mod svg;
38pub mod tailwind;
39pub mod tui;
40pub mod vellum;
41
42/// Every renderable target ishou-cli understands. The string here matches the
43/// CLI flag users type (`ishou render --target css`).
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub enum Target {
46    Css,
47    /// Material Design 3 system colors (`--md-sys-color-*`) mapped from the
48    /// TokenSet — the target Material consumers (`pleme-mui`) bind to so they
49    /// can consume ishou instead of forking a hard-coded MD3 palette.
50    Md3,
51    Tailwind,
52    Scss,
53    Rust,
54    Json,
55    Glsl,
56    Ghostty,
57    Tui,
58    Svg,
59    Stylix,
60    /// base16 bat `.tmTheme` (Sublime-Text XML plist) — the FIRST per-app
61    /// *config-file* target. bat consumes it as a custom theme; this is the
62    /// M0 proof ishou can natively emit a per-app config file (toward ishou
63    /// replacing stylix as the fleet theming engine). Same base16 slot→Nord
64    /// mapping as `Stylix`.
65    Bat,
66    Nix,
67    StylixFonts,
68    /// Fleet-fonts attrset — `{ primary, italic, bold, symbols, emoji,
69    /// fallback_chain }` consumed directly by every pleme-io GPU app
70    /// HM module (mado, blackmatter-ghostty, fumi, kagi, …) to name
71    /// the canonical family AND install the underlying nixpkgs
72    /// package via `home.packages`. Sibling of `StylixFonts` — same
73    /// typed Typography source, different consumer-side shape.
74    FleetFonts,
75    /// Vellum base16 stylix scheme YAML (the prescribed fleet theme).
76    /// Sourced from the BORN `VellumPalette`, not the Nord `TokenSet`.
77    StylixVellum,
78    /// Vellum base16 as a PARSED Nix attrset — the IFD-free form.
79    ///
80    /// Sibling of `StylixVellum` (same palette) and of `StylixFonts` (same
81    /// consumer, same reason). stylix reads a `{ yaml = <drv>; }` via
82    /// `readFile`, which is an import-from-derivation: it forces a build
83    /// during evaluation, and for NixOS consumers that build is a linux
84    /// one — so a Mac cannot evaluate any node. A literal attrset takes
85    /// stylix's already-parsed branch and costs nothing.
86    StylixVellumNix,
87    /// Nord base16 as an already-parsed Nix attrset — the IFD-free shape.
88    StylixNordNix,
89    /// Mono, as an already-parsed Nix attrset.
90    StylixMonoNix,
91    /// Vellum base24 stylix scheme YAML — base16 + the real two-tier
92    /// brights (base10–17).
93    StylixVellumBase24,
94    /// Vellum palette preview SVG — one labelled chip per BORN token.
95    SvgVellumPalette,
96    /// Vellum skim/fzf `--color=k:v,…` string, generated from the BORN
97    /// `VellumPalette`. Byte-equal to `skim-tab::VELLUM_COLORS` — the
98    /// SAVED branch, not the live picker theme (skim-tab paints
99    /// `NORD_COLORS`, and has no ishou dependency). See
100    /// `vellum::render_skim` for the full relationship + the destination.
101    SkimVellum,
102    /// Vellum escriba theme `*.lisp` — `(deftheme)` + `(defpalette)` +
103    /// `(defhighlight …)` over escriba's `CANONICAL_GROUPS`, sourced from
104    /// the BORN `VellumPalette`. Mirrors `escriba/configs/vellum.lisp`.
105    EscribaVellum,
106}
107
108impl Target {
109    pub fn from_str(s: &str) -> Option<Self> {
110        Some(match s {
111            "css" => Self::Css,
112            "md3" | "material" | "md-sys-color" => Self::Md3,
113            "tailwind" => Self::Tailwind,
114            "scss" => Self::Scss,
115            "rust" => Self::Rust,
116            "json" => Self::Json,
117            "glsl" => Self::Glsl,
118            "ghostty" => Self::Ghostty,
119            "tui" => Self::Tui,
120            "svg" => Self::Svg,
121            "stylix" | "stylix-base16" => Self::Stylix,
122            "bat" | "bat-tmtheme" => Self::Bat,
123            "stylix-fonts" | "fonts-nix" => Self::StylixFonts,
124            "nix" | "nord-palette-nix" => Self::Nix,
125            "fleet-fonts" | "fleet_fonts" => Self::FleetFonts,
126            "stylix-vellum" | "stylix-base16-vellum" => Self::StylixVellum,
127            "stylix-vellum-nix" | "stylix-base16-vellum-nix" => Self::StylixVellumNix,
128            "stylix-nord-nix" | "stylix-base16-nord-nix" => Self::StylixNordNix,
129            "stylix-mono-nix" => Self::StylixMonoNix,
130            "stylix-vellum-base24" | "stylix-base24-vellum" => Self::StylixVellumBase24,
131            "svg-vellum-palette" | "vellum-palette" => Self::SvgVellumPalette,
132            "skim-vellum" | "skim" => Self::SkimVellum,
133            "escriba-vellum" | "escriba" => Self::EscribaVellum,
134            _ => return None,
135        })
136    }
137
138    pub fn render(&self, tokens: &ishou_tokens::TokenSet) -> String {
139        match self {
140            Self::Css => css::render(tokens),
141            Self::Md3 => md3::render(tokens),
142            Self::Tailwind => tailwind::render(tokens),
143            Self::Scss => scss::render(tokens),
144            Self::Rust => rust::render(tokens),
145            Self::Json => json::render(tokens),
146            Self::Glsl => glsl::render(tokens),
147            Self::Ghostty => ghostty::render(tokens),
148            Self::Tui => tui::render(tokens),
149            Self::Svg => svg::render(tokens),
150            Self::Stylix => stylix::render(tokens),
151            Self::Bat => bat::render(tokens),
152            Self::Nix => nix::render(tokens),
153            Self::StylixFonts => stylix_fonts::render(tokens),
154            Self::StylixVellumNix => vellum::render_base16_nix(),
155            Self::StylixNordNix => stylix::render_nix(tokens),
156            Self::StylixMonoNix => mono::render_base16_nix(),
157            Self::FleetFonts => fleet_fonts::render(tokens),
158            // Vellum targets are their own BORN source — the Nord
159            // `TokenSet` argument is unused.
160            Self::StylixVellum => vellum::render_base16(),
161            Self::StylixVellumBase24 => vellum::render_base24(),
162            Self::SvgVellumPalette => vellum::render_svg_palette(),
163            Self::SkimVellum => vellum::render_skim(),
164            Self::EscribaVellum => vellum::render_escriba_lisp(),
165        }
166    }
167
168    pub fn all() -> [Target; 23] {
169        [
170            Self::Css,
171            Self::Md3,
172            Self::Tailwind,
173            Self::Scss,
174            Self::Rust,
175            Self::Json,
176            Self::Glsl,
177            Self::Ghostty,
178            Self::Tui,
179            Self::Svg,
180            Self::Stylix,
181            Self::Bat,
182            Self::Nix,
183            Self::StylixFonts,
184            Self::FleetFonts,
185            Self::StylixVellum,
186            Self::StylixVellumNix,
187            Self::StylixNordNix,
188            Self::StylixMonoNix,
189            Self::StylixVellumBase24,
190            Self::SvgVellumPalette,
191            Self::SkimVellum,
192            Self::EscribaVellum,
193        ]
194    }
195}