embedded-typst 0.1.0

A typst::World for embedding the Typst compiler: lazily loaded fonts, a virtual filesystem over several roots, Typst packages and reproducible dates. Native and Wasm.
Documentation
//! A [`typst::World`] for embedding the Typst compiler in an application.
//!
//! - [`Fonts`]: Typst's bundled fonts, in-memory fonts, system fonts and font
//!   directories. Fonts on disk are read only when a document uses them.
//!   Build once, share between compilations.
//! - [`EmbeddedWorld`]: the main source, in-memory files, root directories
//!   searched in order, `sys.inputs`, a fixed date for reproducible output
//!   and, with the `packages` feature, `@preview` and `@local` packages.
//!
//! On `wasm32` there is no filesystem: only fonts and files given as data
//! are available, and `datetime.today()` needs a creation timestamp.
//!
//! ```
//! # #[cfg(feature = "typst-fonts")] {
//! use std::sync::Arc;
//! use embedded_typst::{EmbeddedWorld, Fonts};
//! use typst::syntax::VirtualPath;
//!
//! let fonts = Arc::new(Fonts::builder().typst_fonts().build());
//! let main = VirtualPath::new("main.typ").unwrap();
//! let world = EmbeddedWorld::new(main, "#import \"lib.typ\": greet\n#greet", fonts)
//!     .with_creation_timestamp(0);
//! world.add_file(VirtualPath::new("lib.typ").unwrap(), b"#let greet = [Hello]".to_vec());
//!
//! let document = typst::compile::<typst_layout::PagedDocument>(&world)
//!     .output
//!     .expect("compiles");
//! assert_eq!(document.pages().len(), 1);
//! # }
//! ```

mod fonts;
#[cfg(all(feature = "packages", not(target_arch = "wasm32")))]
mod packages;
mod world;

pub use fonts::{Fonts, FontsBuilder};
#[cfg(all(feature = "packages", not(target_arch = "wasm32")))]
pub use packages::Packages;
#[cfg(not(target_arch = "wasm32"))]
pub use world::Dependency;
pub use world::{project_file, EmbeddedWorld};