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 — the fleet picker theme.
91    /// Generated from the BORN `VellumPalette`, byte-equivalent to the
92    /// hand-authored `skim-tab::NORD_COLORS`.
93    SkimVellum,
94    /// Vellum escriba theme `*.lisp` — `(deftheme)` + `(defpalette)` +
95    /// `(defhighlight …)` over escriba's `CANONICAL_GROUPS`, sourced from
96    /// the BORN `VellumPalette`. Mirrors `escriba/configs/vellum.lisp`.
97    EscribaVellum,
98}
99
100impl Target {
101    pub fn from_str(s: &str) -> Option<Self> {
102        Some(match s {
103            "css" => Self::Css,
104            "md3" | "material" | "md-sys-color" => Self::Md3,
105            "tailwind" => Self::Tailwind,
106            "scss" => Self::Scss,
107            "rust" => Self::Rust,
108            "json" => Self::Json,
109            "glsl" => Self::Glsl,
110            "ghostty" => Self::Ghostty,
111            "tui" => Self::Tui,
112            "svg" => Self::Svg,
113            "stylix" | "stylix-base16" => Self::Stylix,
114            "bat" | "bat-tmtheme" => Self::Bat,
115            "stylix-fonts" | "fonts-nix" => Self::StylixFonts,
116            "nix" | "nord-palette-nix" => Self::Nix,
117            "fleet-fonts" | "fleet_fonts" => Self::FleetFonts,
118            "stylix-vellum" | "stylix-base16-vellum" => Self::StylixVellum,
119            "stylix-vellum-nix" | "stylix-base16-vellum-nix" => Self::StylixVellumNix,
120            "stylix-vellum-base24" | "stylix-base24-vellum" => Self::StylixVellumBase24,
121            "svg-vellum-palette" | "vellum-palette" => Self::SvgVellumPalette,
122            "skim-vellum" | "skim" => Self::SkimVellum,
123            "escriba-vellum" | "escriba" => Self::EscribaVellum,
124            _ => return None,
125        })
126    }
127
128    pub fn render(&self, tokens: &ishou_tokens::TokenSet) -> String {
129        match self {
130            Self::Css => css::render(tokens),
131            Self::Md3 => md3::render(tokens),
132            Self::Tailwind => tailwind::render(tokens),
133            Self::Scss => scss::render(tokens),
134            Self::Rust => rust::render(tokens),
135            Self::Json => json::render(tokens),
136            Self::Glsl => glsl::render(tokens),
137            Self::Ghostty => ghostty::render(tokens),
138            Self::Tui => tui::render(tokens),
139            Self::Svg => svg::render(tokens),
140            Self::Stylix => stylix::render(tokens),
141            Self::Bat => bat::render(tokens),
142            Self::Nix => nix::render(tokens),
143            Self::StylixFonts => stylix_fonts::render(tokens),
144            Self::StylixVellumNix => vellum::render_base16_nix(),
145            Self::FleetFonts => fleet_fonts::render(tokens),
146            // Vellum targets are their own BORN source — the Nord
147            // `TokenSet` argument is unused.
148            Self::StylixVellum => vellum::render_base16(),
149            Self::StylixVellumBase24 => vellum::render_base24(),
150            Self::SvgVellumPalette => vellum::render_svg_palette(),
151            Self::SkimVellum => vellum::render_skim(),
152            Self::EscribaVellum => vellum::render_escriba_lisp(),
153        }
154    }
155
156    pub fn all() -> [Target; 21] {
157        [
158            Self::Css,
159            Self::Md3,
160            Self::Tailwind,
161            Self::Scss,
162            Self::Rust,
163            Self::Json,
164            Self::Glsl,
165            Self::Ghostty,
166            Self::Tui,
167            Self::Svg,
168            Self::Stylix,
169            Self::Bat,
170            Self::Nix,
171            Self::StylixFonts,
172            Self::FleetFonts,
173            Self::StylixVellum,
174            Self::StylixVellumNix,
175            Self::StylixVellumBase24,
176            Self::SvgVellumPalette,
177            Self::SkimVellum,
178            Self::EscribaVellum,
179        ]
180    }
181}