Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150//! The compiled presentation, in the shape the web UI consumes.//!//! One [`Slide`] corresponds to one *page* of the compiled Typst document, which//! is also one navigation step: touying expands a slide containing `#pause` into//! several pages, and the UI walks pages, not logical slides. The `logical` and//! `subslide` fields are what let the presenter console group them back together.
use serde::{Deserialize, Serialize};
/// A whole compiled deck.#[derive(Debug, Clone, Serialize)]pub struct Deck { /// Monotonic counter, bumped on every successful recompile. Clients use it to /// tell a genuine change from a reconnect. pub revision: u64, /// Page width in Typst points, for the overlay coordinate system. pub page_width: f64, /// Page height in Typst points. pub page_height: f64, pub slides: Vec<Slide>, /// Diagnostics from the last compile. Warnings can accompany a good deck; a /// failed compile is reported separately as [`crate::compile::CompileError`]. pub warnings: Vec<Diagnostic>,}
impl Deck { pub fn len(&self) -> usize { self.slides.len() }
pub fn slide(&self, index: usize) -> Option<&Slide> { self.slides.get(index) }
/// Every video on a page, in document order. pub fn videos_on(&self, index: usize) -> &[Video] { self.slides.get(index).map_or(&[], |s| &s.videos) }}
/// One page of the compiled document.#[derive(Debug, Clone, Serialize)]pub struct Slide { /// Zero-based page index; also this slide's position in `Deck::slides`. pub index: usize, /// Rendered page. Skipped in the JSON deck sent over the websocket -- clients /// fetch it from `/slide/{index}` instead, keeping page markup out of the /// message stream. #[serde(skip)] pub svg: String, /// The enclosing level-1 heading, if any. pub section: Option<String>, /// The slide title: this page's level-2 heading, or the one belonging to the /// logical slide this page is a subslide of. pub title: Option<String>, /// Logical slide number, shared by every subslide of one `#slide`. pub logical: u32, /// Zero-based index of this page within its logical slide. pub subslide: u32, /// Speaker notes, already flattened to text by touying. pub notes: Option<String>, pub videos: Vec<Video>,}
/// A video overlay: where it goes, what it plays, and how it plays.////// Geometry arrives from Typst in points relative to the page's top-left corner/// and is converted to fractions of the page here, because the browser sizes the/// slide box to whatever screen it lands on and only fractions survive that.#[derive(Debug, Clone, Serialize)]pub struct Video { /// Stable within a page: `v{page}-{n}` in document order. The websocket /// protocol addresses videos by this. pub id: String, /// What the deck asked for: a path relative to the deck, or a URL. pub src: String, /// The URL the browser should actually load, once the media is available. pub url: Option<String>, pub kind: VideoKind, /// Optional human-readable name for the presenter console. pub name: Option<String>, /// Fractions of the page, in `[0, 1]`. pub x: f64, pub y: f64, pub width: f64, pub height: f64, /// Playback window in seconds. pub start: Option<f64>, pub end: Option<f64>, /// Restart at `start` on reaching `end`, until the slide changes. #[serde(rename = "loop")] pub looping: bool, /// Poster image URL, if the deck supplied one. pub poster: Option<String>,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]#[serde(rename_all = "lowercase")]pub enum VideoKind { /// A file on disk, relative to the deck root. Local, /// A URL fetched ahead of time with `yt-dlp`. Remote,}
/// The raw `<presentypst-video>` record, exactly as the Typst library emits it.#[derive(Debug, Clone, Deserialize)]pub struct RawVideo { pub page: usize, pub x: f64, pub y: f64, pub w: f64, pub h: f64, pub src: String, #[serde(default)] pub start: Option<f64>, #[serde(default)] pub end: Option<f64>, #[serde(default = "default_true", rename = "loop")] pub looping: bool, #[serde(default)] pub poster: Option<String>, #[serde(default)] pub name: Option<String>,}
/// The raw `<presentypst-slide>` record.#[derive(Debug, Clone, Deserialize)]pub struct RawSlideMeta { pub page: usize, #[serde(default)] pub section: Option<String>, #[serde(default)] pub title: Option<String>,}
fn default_true() -> bool { true}
/// A compiler diagnostic, flattened for display in the browser.#[derive(Debug, Clone, Serialize)]pub struct Diagnostic { pub severity: String, pub message: String, /// `path:line:column`, when the diagnostic has a resolvable span. pub location: Option<String>, pub hints: Vec<String>,}