1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! # WebFluent
//!
//! **The Web-First Language** — a programming language that compiles to HTML, CSS, JavaScript, and PDF.
//!
//! WebFluent provides 50+ built-in UI components, signal-based reactivity, client-side routing,
//! internationalization (i18n), animations, static site generation (SSG), and PDF document output —
//! all with zero runtime dependencies.
//!
//! ## Quick Start
//!
//! Use WebFluent as a **template engine** to render `.wf` templates with JSON data:
//!
//! ```rust
//! use webfluent::Template;
//! use serde_json::json;
//!
//! let tpl = Template::from_str(r#"
//! Page Home (path: "/", title: "Hello") {
//! Container {
//! Heading("Hello, {name}!", h1)
//! Text("Welcome to WebFluent.")
//! }
//! }
//! "#).unwrap();
//!
//! let html = tpl.render_html(&json!({"name": "World"})).unwrap();
//! // Returns a full HTML document with embedded CSS
//!
//! let fragment = tpl.render_html_fragment(&json!({"name": "World"})).unwrap();
//! // Returns just the HTML fragment (no <html> wrapper)
//! ```
//!
//! ## Rendering to PDF
//!
//! ```rust,no_run
//! use webfluent::Template;
//! use serde_json::json;
//!
//! let tpl = Template::from_file("templates/invoice.wf").unwrap();
//! let pdf_bytes = tpl.render_pdf(&json!({
//! "number": "INV-001",
//! "customer": { "name": "Acme Corp" },
//! "items": [{ "name": "Widget", "price": 9.99 }],
//! "paid": true
//! })).unwrap();
//!
//! std::fs::write("invoice.pdf", pdf_bytes).unwrap();
//! ```
//!
//! ## Theming
//!
//! Override design tokens or switch themes:
//!
//! ```rust,no_run
//! use webfluent::Template;
//! use serde_json::json;
//!
//! let html = Template::from_str("Page P (path: \"/\") { Container { Text(\"Hello\") } }")
//! .unwrap()
//! .with_theme("dark")
//! .with_tokens(&[("color-primary", "#8B5CF6")])
//! .render_html(&json!({}))
//! .unwrap();
//! ```
//!
//! ## Architecture
//!
//! The compilation pipeline:
//!
//! 1. **Lexer** ([`lexer`]) — tokenizes `.wf` source into a token stream
//! 2. **Parser** ([`parser`]) — builds an AST from tokens
//! 3. **Linter** ([`linter`]) — runs accessibility and PDF validation checks
//! 4. **Codegen** ([`codegen`]) — generates HTML, CSS, JS, SSG pages, or PDF output
//! 5. **Themes** ([`themes`]) — provides design tokens and component CSS
//! 6. **Runtime** ([`runtime`]) — embeds the JavaScript runtime for reactivity and routing
//!
//! ## Crate Features
//!
//! This crate exposes the full compiler pipeline. For most use cases, the [`Template`] API
//! is the simplest entry point. For full control, use the lexer, parser, and codegen modules
//! directly.
/// Lexical analysis — tokenizes `.wf` source code.
///
/// The lexer converts raw source text into a stream of [`lexer::Token`]s, handling
/// keywords, identifiers, string literals (with `{var}` interpolation), numbers,
/// operators, and punctuation.
/// Parsing — builds an abstract syntax tree from tokens.
///
/// The parser consumes tokens from the lexer and produces a [`parser::Program`] AST
/// containing pages, components, stores, and an optional app declaration.
/// Code generation — compiles the AST to various output formats.
///
/// Supports HTML ([`codegen::generate_html`]), CSS ([`codegen::generate_css`]),
/// JavaScript ([`codegen::JsCodegen`]), static site generation ([`codegen::render_page_html`]),
/// and PDF ([`codegen::PdfCodegen`]).
/// JavaScript runtime — embedded runtime for reactivity, routing, and DOM helpers.
///
/// The runtime provides signal-based reactivity, conditional/list rendering,
/// client-side routing, store management, i18n, animations, and toast notifications.
/// It is embedded as a constant string ([`runtime::RUNTIME_JS`]) and included in
/// compiled output.
/// Design system — theme tokens and component CSS.
///
/// Provides built-in themes (`default`, `dark`, `minimal`, `brutalist`) via
/// [`themes::get_theme_tokens`] and component-level CSS via [`themes::component_css`].
/// Project configuration — loads and manages `webfluent.app.json`.
///
/// The [`config::ProjectConfig`] struct holds all project settings: theme, build options,
/// dev server config, meta tags, and i18n settings.
/// Error types and diagnostics.
///
/// Provides [`WebFluentError`] (with variants for lexer, parser, codegen, config, and I/O errors),
/// [`error::Diagnostic`] (with file, line, column, and optional hint),
/// and [`error::A11yWarning`] for accessibility lint results.
/// Linting — compile-time checks for accessibility and PDF validation.
///
/// [`linter::lint_accessibility`] runs 12 WCAG-based checks (missing alt text, form labels,
/// heading hierarchy, etc.). [`linter::validate_for_pdf`] ensures interactive components
/// aren't used in PDF output.
/// Template engine — render `.wf` templates with JSON data.
///
/// The [`Template`] struct is the primary public API for using WebFluent as a library.
/// It supports rendering to HTML documents, HTML fragments, and PDF files.
pub use Template;
pub use ;