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