mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 05:06:41 +00:00
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 commitf9fc0e4872. * Revert "Revert "html changes"" This reverts commit7dc554a9e4. * 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:
parent
30a08e79ab
commit
3bc5f19cf5
23 changed files with 237 additions and 123 deletions
|
|
@ -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.
|
||||
|
|
|
|||
58
crates/tinymist-std/src/concepts/typst.rs
Normal file
58
crates/tinymist-std/src/concepts/typst.rs
Normal 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};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue