crepuscularity_native/lib.rs
1//! Lower `.crepus` templates to a JSON view tree for SwiftUI, Jetpack Compose, and future
2//! `android-activity` / `objc2` shells.
3//!
4//! ## Crate layout
5//! - [`ir`] — serializable `ViewIr` / `ViewNode` / `ViewStyle` (the **contract** with shells).
6//! - [`style`] — Tailwind-like class → style hints (extend here for GPUI parity).
7//! - `include_expand` — `include` → `(Vec<Node>, TemplateContext)` without IR cycles.
8//! - `render` — AST lowering and public `render_*` entry points.
9//! - [`mutations`] — renderer-agnostic, path-based IR mutations and diffing.
10//! - [`hot_reload`] — structured hot-reload protocol + conservative AST gate.
11//!
12//! ## Sharing / codegen (bindgen, other repos)
13//! - **[`bindgen`](https://docs.rs/bindgen)** generates **Rust FFI** from **C/C++ headers**. It does
14//! not extract types from Rust for Swift/Kotlin, and it does not import arbitrary “other project”
15//! sources—it wraps existing native (C) APIs.
16//! - **Single source of truth** options that *do* fit native shells:
17//! - **`schemars`** on `ViewIr` + **JSON Schema** → *quicktype*, *OpenAPI generators*, etc. for Swift/Kotlin.
18//! - A tiny **build.rs** that emits `fixture.json` and optional bindings (same repo or **path dependency** / **git submodule**).
19//! - Publish **`crepuscularity-native`** to crates.io and depend on it from another Rust workspace as usual.
20//!
21//! ## Coverage vs GPUI / web
22//! Not 100% parity with GPUI `styler.rs`—expand [`style`].
23
24pub mod codegen;
25pub mod colors;
26pub mod hot_reload;
27mod include_expand;
28pub mod ir;
29pub mod mutations;
30mod render;
31pub mod style;
32
33pub use codegen::{generate_native_source, NativeCodegenTarget};
34pub use colors::resolve_rgba;
35pub use crepuscularity_core::CrepusError;
36pub use hot_reload::{ast_shape_compatible, plan_hot_reload, HotReloadEnvelope, HotReloadMessage};
37pub use ir::{PickerOption, StackAxis, ViewIr, ViewNode, ViewStyle, IR_VERSION};
38pub use mutations::{apply_mutations, diff_ir, IrMutation};
39pub use render::{
40 render_component_file_to_ir, render_from_files, render_nodes_to_ir, render_template_to_ir,
41};
42
43/// Serialize IR to JSON (compact).
44pub fn to_json(ir: &ViewIr) -> Result<String, serde_json::Error> {
45 serde_json::to_string(ir)
46}
47
48/// Serialize IR to pretty-printed JSON (fixtures / debugging).
49pub fn to_json_pretty(ir: &ViewIr) -> Result<String, serde_json::Error> {
50 serde_json::to_string_pretty(ir)
51}
52
53#[cfg(test)]
54mod tests;