//! `cph-typst` — typst `World`, augmented-manifest injection, compile, PDF, //! span mapping. //! //! Owned by **WU-4**. Embeds the typst 0.15 compiler as a library to: //! - **compile-check** a [`cph_model::Lesson`] for a target (collect typst //! errors+warnings as [`cph_diag::Diagnostic`]s), and //! - **export a PDF** for a render target. //! //! ## Model (ADR-0011): compile a template, inject a manifest //! //! There is **no framework-generated driver** any more. An export target is a //! build with a typed [`cph_model::Step::TypstCompile`] naming a **template //! file** (e.g. `exports/student.typ`) that lives in the engineering file. The //! engine: //! //! 1. mounts the lesson's engineering-file tree (ADR-0007) as the typst project //! root (`--root`); //! 2. sets the World's `main` to that **real template file** under the root, so //! diagnostic spans resolve to an authored file; //! 3. builds an **augmented manifest** (the lesson's `info` + ordered `parts`, //! each with a `fields` array of the content fields present on disk — see //! [`manifest`]) and serves it as a virtual in-memory file at //! [`world::MANIFEST_VPATH`], injecting `sys.inputs.manifest` to point there; //! 4. lets the template `toml()`-read that manifest and `include` each part's //! content via computed root-relative paths (legal per ADR-0011). //! //! The augmented manifest closes the OPEN optional-content point: typst has no //! file-exists primitive, so the engine (which has filesystem access) tells the //! template which optional content fields exist via the per-part `fields` array. //! //! ## typst version //! //! Pinned to the `typst` family `=0.15.0`. The 0.15 path/file API differs from //! 0.14: `FileId::new(RootedPath)` where `RootedPath::new(VirtualRoot, //! VirtualPath)`, and a diagnostic span is a `DiagSpan` (not a bare `Span`). mod diag; mod manifest; mod world; use std::path::PathBuf; use cph_diag::{DiagCode, Diagnostic}; use cph_model::{Artifact, Lesson, Step, TargetConfig}; use typst_kit::fonts::{self, FontStore}; use typst_layout::PagedDocument; use typst_pdf::PdfOptions; pub use manifest::build_augmented_manifest; pub use world::{render_package_spec, LessonWorld, MANIFEST_VPATH}; /// The compile/PDF engine: holds the shared font store and the on-disk location /// of the `cph-render` package. /// /// Fonts are discovered once (system + embedded) and shared across every /// compilation via an [`std::sync::Arc`] inside the per-compile [`LessonWorld`]. /// /// `render_dir` is the directory the World resolves `@local/cph-render` (and the /// vendored `@preview/*`) from. It is **not** where the compiled template comes /// from: the template is a real file under the lesson root (`/