feat: convert TypstDocument to enum (#1256)

* feat: convert `TypstDocument` to enum

* fix: errors

* build: update cargo.lock

* fix: warnings

* fix: error

* html changes

* Revert "html changes"

This reverts commit f9fc0e4872.

* Revert "Revert "html changes""

This reverts commit 7dc554a9e4.

* use std typst docs

* span

* paged

* paged

* html change

* paged

* html change

* bytes

* paged

* paged

* paged

* html changes

* paged

* html changes

* paged
This commit is contained in:
Myriad-Dreamin 2025-02-03 11:17:58 +08:00 committed by GitHub
parent 30a08e79ab
commit 3bc5f19cf5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 237 additions and 123 deletions

View file

@ -14,6 +14,9 @@ pub use read::*;
mod marker;
pub use marker::*;
#[cfg(feature = "typst")]
pub mod typst;
/// An immutable string.
pub type ImmutStr = Arc<str>;
/// An immutable byte slice.

View file

@ -0,0 +1,58 @@
//! Re-export of the typst crate.
pub(crate) mod well_known {
pub use typst::foundations::Bytes;
pub use typst::utils::LazyHash;
/// Although this is not good to expose this, we make an alias here to
/// let it as a part of typst-ts.
pub use typst::syntax::FileId as TypstFileId;
pub use typst::World as TypstWorld;
pub use typst::layout::Abs as TypstAbs;
pub use typst::model::Document as TypstPagedDocument;
pub use typst::text::Font as TypstFont;
pub use typst::foundations::Dict as TypstDict;
pub use typst::foundations::Datetime as TypstDatetime;
pub use typst::{diag, foundations, syntax};
}
/// The enum of all well-known Typst documents.
#[derive(Debug, Clone)]
pub enum TypstDocument {
/// The document compiled with `paged` target.
Paged(Arc<well_known::TypstPagedDocument>),
}
impl TypstDocument {
/// Gets details about the document.
pub fn info(&self) -> &typst::model::DocumentInfo {
match self {
Self::Paged(doc) => &doc.info,
}
}
/// Gets the introspector that can be queried for elements and their
/// positions.
pub fn introspector(&self) -> &typst::introspection::Introspector {
match self {
Self::Paged(doc) => &doc.introspector,
}
}
}
use std::sync::Arc;
pub use well_known::*;
/// The prelude of the Typst module.
pub mod prelude {
pub use comemo::Prehashed;
pub use ecow::{eco_format, eco_vec, EcoString, EcoVec};
}