From e5b7fd8869dca3f0999e22460aca3ca2bade1fc0 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Sat, 19 Oct 2024 13:18:23 +0800 Subject: [PATCH] build: update shim --- Cargo.toml | 4 +- cli/src/main.rs | 12 +++--- crates/conversion/vec2svg/src/lib.rs | 5 ++- crates/reflexo-typst-shim/src/nightly/mod.rs | 1 - .../reflexo-typst-shim/src/nightly/model.rs | 37 ------------------- crates/reflexo-typst-shim/src/stable/mod.rs | 2 + .../reflexo-typst-shim/src/stable/syntax.rs | 10 +++-- crates/reflexo-typst-shim/src/stable/utils.rs | 2 +- packages/typst.node/src/lib.rs | 13 ++++--- 9 files changed, 27 insertions(+), 59 deletions(-) delete mode 100644 crates/reflexo-typst-shim/src/nightly/model.rs diff --git a/Cargo.toml b/Cargo.toml index fc64160d..520a61d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -198,9 +198,7 @@ reflexo = { version = "0.5.0-rc7-2", path = "crates/reflexo", default-features = reflexo-vfs = { version = "0.5.0-rc7-2", path = "crates/reflexo-vfs" } reflexo-world = { version = "0.5.0-rc7-2", path = "crates/reflexo-world" } reflexo-typst = { version = "0.5.0-rc7-2", path = "crates/reflexo-typst", default-features = false } -reflexo-typst-shim = { version = "0.5.0-rc7-2", path = "crates/reflexo-typst-shim", features = [ - "nightly", -] } +reflexo-typst-shim = { version = "0.5.0-rc7-2", path = "crates/reflexo-typst-shim" } # conversions reflexo-typst2vec = { version = "0.5.0-rc7-2", path = "crates/conversion/typst2vec" } diff --git a/cli/src/main.rs b/cli/src/main.rs index f3dffc12..ec6b2802 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,15 +6,12 @@ use std::{ }; use clap::FromArgMatches; +use reflexo_typst::config::{entry::EntryOpts, CompileOpts}; use reflexo_typst::error::prelude::*; use reflexo_typst::exporter_builtins::GroupExporter; use reflexo_typst::exporter_utils::map_err; use reflexo_typst::path::{unix_slash, PathClean}; use reflexo_typst::TypstSystemUniverse; -use reflexo_typst::{ - config::{entry::EntryOpts, CompileOpts}, - typst_shim::model::TypstDocumentExt, -}; use typst::{model::Document, text::FontVariant, World}; use typst_assets::fonts; use typst_ts_cli::compile::compile_export; @@ -117,7 +114,12 @@ pub fn query(args: QueryArgs) -> ! { exporter.push_front(Box::new(move |world: &dyn World, output: Arc| { if args.selector == "document_title" { - let title = output.title().map(|e| e.as_str()).unwrap_or("null"); + let title = output + .info + .title + .as_ref() + .map(|e| e.as_str()) + .unwrap_or("null"); let serialized = serialize(&title, "json").map_err(map_err)?; println!("{}", serialized); return Ok(()); diff --git a/crates/conversion/vec2svg/src/lib.rs b/crates/conversion/vec2svg/src/lib.rs index 46bae02e..6f27efa2 100644 --- a/crates/conversion/vec2svg/src/lib.rs +++ b/crates/conversion/vec2svg/src/lib.rs @@ -3,7 +3,6 @@ // todo: https://github.com/typst/typst/pull/2610 // color export -use reflexo::typst_shim::model::TypstDocumentExt; use typst::model::Document as TypstDocument; /// re-export the core types. @@ -116,7 +115,9 @@ pub fn render_svg_html(output: &TypstDocument) -> String { html.push(r#""#.into()); html.push(SvgText::Plain( output - .title() + .info + .title + .as_ref() .map(|s| s.to_string()) .unwrap_or_else(|| "Typst TypstDocument".into()), )); diff --git a/crates/reflexo-typst-shim/src/nightly/mod.rs b/crates/reflexo-typst-shim/src/nightly/mod.rs index 576e2c60..9fbd1c54 100644 --- a/crates/reflexo-typst-shim/src/nightly/mod.rs +++ b/crates/reflexo-typst-shim/src/nightly/mod.rs @@ -1,4 +1,3 @@ -pub mod model; pub mod syntax; pub mod utils; diff --git a/crates/reflexo-typst-shim/src/nightly/model.rs b/crates/reflexo-typst-shim/src/nightly/model.rs deleted file mode 100644 index 267a10cf..00000000 --- a/crates/reflexo-typst-shim/src/nightly/model.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! Extension methods for `typst`'s `model` module. - -use typst::{ - diag::EcoString, - foundations::{Datetime, Smart}, - model::Document, -}; - -/// Extension methods for `Document`. -pub trait TypstDocumentExt { - /// Returns the title of the document. - fn title(&self) -> Option<&EcoString>; - /// The document's author. - fn author(&self) -> &Vec<EcoString>; - /// The document's keywords. - fn keywords(&self) -> &Vec<EcoString>; - /// The document's creation date. - fn date(&self) -> &Smart<Option<Datetime>>; -} - -impl TypstDocumentExt for Document { - fn title(&self) -> Option<&EcoString> { - self.info.title.as_ref() - } - - fn author(&self) -> &Vec<EcoString> { - &self.info.author - } - - fn keywords(&self) -> &Vec<EcoString> { - &self.info.keywords - } - - fn date(&self) -> &Smart<Option<Datetime>> { - &self.info.date - } -} diff --git a/crates/reflexo-typst-shim/src/stable/mod.rs b/crates/reflexo-typst-shim/src/stable/mod.rs index 970ea68b..9fbd1c54 100644 --- a/crates/reflexo-typst-shim/src/stable/mod.rs +++ b/crates/reflexo-typst-shim/src/stable/mod.rs @@ -1,2 +1,4 @@ pub mod syntax; pub mod utils; + +pub use typst::utils::LazyHash; diff --git a/crates/reflexo-typst-shim/src/stable/syntax.rs b/crates/reflexo-typst-shim/src/stable/syntax.rs index 7e0c8bca..590463fa 100644 --- a/crates/reflexo-typst-shim/src/stable/syntax.rs +++ b/crates/reflexo-typst-shim/src/stable/syntax.rs @@ -1,14 +1,16 @@ //! Typst Syntax -use typst_syntax::LinkedNode; +use typst::syntax::LinkedNode; +use typst::syntax::Side; -/// The `LinkedNodeExt` trait is designed for compatibility between new and old versions of `typst`. +/// The `LinkedNodeExt` trait is designed for compatibility between new and old +/// versions of `typst`. pub trait LinkedNodeExt: Sized { /// Get the leaf at the specified byte offset. fn leaf_at_compat(&self, cursor: usize) -> Option<Self>; } -impl<'a> LinkedNodeExt for LinkedNode<'a> { +impl LinkedNodeExt for LinkedNode<'_> { fn leaf_at_compat(&self, cursor: usize) -> Option<Self> { - self.leaf_at(cursor) + self.leaf_at(cursor, Side::Before) } } diff --git a/crates/reflexo-typst-shim/src/stable/utils.rs b/crates/reflexo-typst-shim/src/stable/utils.rs index d2665984..f791775d 100644 --- a/crates/reflexo-typst-shim/src/stable/utils.rs +++ b/crates/reflexo-typst-shim/src/stable/utils.rs @@ -1,2 +1,2 @@ //! Typst utils -pub use typst::util::*; +pub use typst::utils::*; diff --git a/packages/typst.node/src/lib.rs b/packages/typst.node/src/lib.rs index 5d0e0048..09fa879b 100644 --- a/packages/typst.node/src/lib.rs +++ b/packages/typst.node/src/lib.rs @@ -17,10 +17,10 @@ use std::{ use chrono::{DateTime, Datelike, Timelike, Utc}; use napi::bindgen_prelude::*; use napi_derive::napi; +use reflexo_typst::error::prelude::*; use reflexo_typst::foundations::IntoValue; use reflexo_typst::syntax::Span; use reflexo_typst::typst::diag::{At, SourceResult}; -use reflexo_typst::{compat::model::TypstDocumentExt, error::prelude::*}; use reflexo_typst::{ Bytes, Compiler, DynamicLayoutCompiler, Exporter, ShadowApi, SystemCompilerFeat, TypstAbs, TypstDatetime, TypstDocument, TypstSystemWorld, TypstWorld, @@ -45,20 +45,20 @@ impl NodeTypstDocument { /// Gets the title of the document. #[napi(getter)] pub fn title(&self) -> Option<String> { - self.0.title().as_ref().map(ToString::to_string) + self.0.info.title.as_ref().map(ToString::to_string) } /// Gets the authors of the document. #[napi(getter)] pub fn authors(&self) -> Option<Vec<String>> { - let authors = self.0.author().iter(); + let authors = self.0.info.author.iter(); Some(authors.map(ToString::to_string).collect::<Vec<_>>()) } /// Gets the keywords of the document. #[napi(getter)] pub fn keywords(&self) -> Option<Vec<String>> { - let keywords = self.0.keywords().iter(); + let keywords = self.0.info.keywords.iter(); Some(keywords.map(ToString::to_string).collect::<Vec<_>>()) } @@ -69,7 +69,8 @@ impl NodeTypstDocument { #[napi(getter)] pub fn date(&self) -> Option<i64> { self.0 - .date() + .info + .date .custom() .flatten() .and_then(typst_datetime_to_unix_nanoseconds) @@ -81,7 +82,7 @@ impl NodeTypstDocument { /// explicitly. #[napi(getter)] pub fn enabled_auto_date(&self) -> bool { - self.0.date().is_auto() + self.0.info.date.is_auto() } }