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