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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! # typst-bake
//!
//! Bake Typst templates, fonts, and packages into your Rust binary — use Typst
//! as a self-contained, embedded library.
//!
//! ## Cargo Features
//!
//! - **`pdf`** (default) - Enable PDF generation via [`Document::to_pdf`]
//! - **`svg`** - Enable SVG generation via [`Document::to_svg`]
//! - **`png`** - Enable PNG rasterization via [`Document::to_png`]
//! - **`full`** - Enable all output formats
//!
//! ## Features
//!
//! - **Multiple Output Formats** - Generate PDF, SVG, or PNG from the same template
//! - **File Embedding** - All files in `template-dir` are embedded and accessible from `.typ` files
//! - **Font Embedding** - Fonts (TTF, OTF, TTC) in `fonts-dir` are automatically bundled
//! - **Package Bundling** - Scans for package imports and recursively resolves all dependencies
//! - **Optimized Binary Size** - Resources are compressed with zstd and decompressed lazily at runtime
//! - **Runtime Inputs** - Pass dynamic data from Rust structs to Typst via [`IntoValue`] / [`IntoDict`] derive macros
//! - **Page Selection** - Select specific pages for output via [`Document::select_pages`]
//!
//! ## Quick Start
//!
//! Add to your `Cargo.toml`:
//! ```toml
//! [package.metadata.typst-bake]
//! template-dir = "./templates"
//! fonts-dir = "./fonts"
//!
//! [dependencies]
//! typst-bake = "0.1"
//! ```
//!
//! Then use the [`document!`] macro:
//! ```rust,ignore
//! // Generate PDF
//! let pdf = typst_bake::document!("main.typ").to_pdf()?;
//!
//! // Generate SVG (one per page)
//! let svgs = typst_bake::document!("main.typ").to_svg()?;
//!
//! // Generate PNG at 144 DPI (Retina)
//! let pngs = typst_bake::document!("main.typ").to_png(144.0)?;
//! ```
pub use rebuild_if_changed;
pub use ;
pub use ;
pub use ;
/// Creates a [`Document`] with embedded templates, fonts, and packages.
///
/// # Usage
///
/// ```rust,ignore
/// // Generate PDF
/// let pdf = typst_bake::document!("main.typ").to_pdf()?;
///
/// // Generate SVG (one per page)
/// let svgs = typst_bake::document!("main.typ").to_svg()?;
///
/// // Generate PNG at 144 DPI (Retina)
/// let pngs = typst_bake::document!("main.typ").to_png(144.0)?;
/// ```
///
/// # Configuration
///
/// Add to your `Cargo.toml`:
/// ```toml
/// [package.metadata.typst-bake]
/// template-dir = "./templates"
/// fonts-dir = "./fonts"
/// ```
///
/// # What Gets Embedded
///
/// - **Templates**: All files in `template-dir` are embedded and accessible from `.typ` files.
/// Paths resolve relative to the referring `.typ` file.
/// - **Fonts**: Only supported font formats (TTF, OTF, TTC) are embedded. At least one font
/// is required; without fonts, Typst produces invisible text.
/// - **Packages**: Using packages requires no manual setup. Just use `#import "@preview/..."`
/// or `#import "@local/..."` as you normally would in Typst. The macro scans for package
/// imports and recursively resolves all dependencies at compile time. Shares Typst's own
/// package directories, so locally installed packages are picked up automatically.
pub use document;
/// Derive macro for converting a struct to a Typst value.
///
/// All structs that will be passed to Typst templates (directly or nested) must derive this.
///
/// - **Top-level struct**: Use both [`IntoValue`] and [`IntoDict`]
/// - **Nested structs**: Use [`IntoValue`] only
///
/// # Example
///
/// ```rust,ignore
/// use typst_bake::{IntoValue, IntoDict};
///
/// #[derive(IntoValue, IntoDict)] // Top-level: both macros
/// struct Inputs {
/// title: String,
/// products: Vec<Product>,
/// }
///
/// #[derive(IntoValue)] // Nested: IntoValue only
/// struct Product {
/// name: String,
/// price: f64,
/// }
/// ```
///
/// In `.typ` files, nested structs are accessed as dictionaries:
/// ```typ
/// #for product in inputs.products [
/// - #product.name: $#product.price
/// ]
/// ```
pub use IntoValue;
/// Derive macro for converting a struct to a Typst dictionary.
///
/// Only the top-level struct passed to [`Document::with_inputs`] needs this.
/// Nested structs should only derive [`IntoValue`].
///
/// # Example
///
/// ```rust,ignore
/// use typst_bake::{IntoValue, IntoDict};
///
/// #[derive(IntoValue, IntoDict)] // Top-level: both macros
/// struct Inputs {
/// title: String,
/// items: Vec<Item>,
/// }
///
/// #[derive(IntoValue)] // Nested: IntoValue only
/// struct Item {
/// name: String,
/// price: f64,
/// }
///
/// let pdf = typst_bake::document!("main.typ")
/// .with_inputs(Inputs { /* ... */ })
/// .to_pdf()?;
/// ```
pub use IntoDict;
/// Re-export include_dir for macro-generated code.
pub use include_dir;
/// Internal module for macro-generated code.
/// Do not use directly.