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
21pub mod css;
22pub mod fleet_fonts;
23pub mod ghostty;
24pub mod glsl;
25pub mod json;
26pub mod nix;
27pub mod nix_ast;
28pub mod rust;
29pub mod scss;
30pub mod stylix;
31pub mod stylix_fonts;
32pub mod svg;
33pub mod tailwind;
34pub mod tui;
35
36/// Every renderable target ishou-cli understands. The string here matches the
37/// CLI flag users type (`ishou render --target css`).
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum Target {
40    Css,
41    Tailwind,
42    Scss,
43    Rust,
44    Json,
45    Glsl,
46    Ghostty,
47    Tui,
48    Svg,
49    Stylix,
50    Nix,
51    StylixFonts,
52    /// Fleet-fonts attrset — `{ primary, italic, bold, symbols, emoji,
53    /// fallback_chain }` consumed directly by every pleme-io GPU app
54    /// HM module (mado, blackmatter-ghostty, fumi, kagi, …) to name
55    /// the canonical family AND install the underlying nixpkgs
56    /// package via `home.packages`. Sibling of `StylixFonts` — same
57    /// typed Typography source, different consumer-side shape.
58    FleetFonts,
59}
60
61impl Target {
62    pub fn from_str(s: &str) -> Option<Self> {
63        Some(match s {
64            "css" => Self::Css,
65            "tailwind" => Self::Tailwind,
66            "scss" => Self::Scss,
67            "rust" => Self::Rust,
68            "json" => Self::Json,
69            "glsl" => Self::Glsl,
70            "ghostty" => Self::Ghostty,
71            "tui" => Self::Tui,
72            "svg" => Self::Svg,
73            "stylix" | "stylix-base16" => Self::Stylix,
74            "stylix-fonts" | "fonts-nix" => Self::StylixFonts,
75            "nix" | "nord-palette-nix" => Self::Nix,
76            "fleet-fonts" | "fleet_fonts" => Self::FleetFonts,
77            _ => return None,
78        })
79    }
80
81    pub fn render(&self, tokens: &ishou_tokens::TokenSet) -> String {
82        match self {
83            Self::Css => css::render(tokens),
84            Self::Tailwind => tailwind::render(tokens),
85            Self::Scss => scss::render(tokens),
86            Self::Rust => rust::render(tokens),
87            Self::Json => json::render(tokens),
88            Self::Glsl => glsl::render(tokens),
89            Self::Ghostty => ghostty::render(tokens),
90            Self::Tui => tui::render(tokens),
91            Self::Svg => svg::render(tokens),
92            Self::Stylix => stylix::render(tokens),
93            Self::Nix => nix::render(tokens),
94            Self::StylixFonts => stylix_fonts::render(tokens),
95            Self::FleetFonts => fleet_fonts::render(tokens),
96        }
97    }
98
99    pub fn all() -> [Target; 13] {
100        [
101            Self::Css,
102            Self::Tailwind,
103            Self::Scss,
104            Self::Rust,
105            Self::Json,
106            Self::Glsl,
107            Self::Ghostty,
108            Self::Tui,
109            Self::Svg,
110            Self::Stylix,
111            Self::Nix,
112            Self::StylixFonts,
113            Self::FleetFonts,
114        ]
115    }
116}