From dcb70691fdf6a7148ed03c5ac2acea2441488f03 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Wed, 2 Oct 2024 19:06:11 +0800 Subject: [PATCH] fix: compile error --- cli/src/main.rs | 7 +++++-- cli/src/query_repl.rs | 7 ++----- crates/conversion/typst2vec/src/pass/typst2vec.rs | 10 +++++----- crates/reflexo-typst/src/exporter/text.rs | 4 ++-- crates/reflexo-typst/src/lib.rs | 3 ++- crates/reflexo-typst/src/query.rs | 2 +- packages/compiler/src/lib.rs | 4 ++-- packages/typst.node/src/compiler/mod.rs | 6 +++--- packages/typst.node/src/lib.rs | 14 +++++++------- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 472c80d0..f3dffc12 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,12 +6,15 @@ 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; @@ -114,7 +117,7 @@ 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.clone().unwrap_or("null".into()); + let title = output.title().map(|e| e.as_str()).unwrap_or("null"); let serialized = serialize(&title, "json").map_err(map_err)?; println!("{}", serialized); return Ok(()); diff --git a/cli/src/query_repl.rs b/cli/src/query_repl.rs index dce3b014..3c1b60b1 100644 --- a/cli/src/query_repl.rs +++ b/cli/src/query_repl.rs @@ -1,12 +1,9 @@ -use comemo::{Track, TrackedMut}; use std::borrow::Cow::{self, Owned}; use std::cell::{RefCell, RefMut}; use std::sync::Arc; use reflexo_typst::typst::prelude::*; -use reflexo_typst::{ - CompileDriver, CompileReport, CompilerWorld, ConsoleDiagReporter, PureCompiler, -}; +use reflexo_typst::{CompileDriver, CompileReport, ConsoleDiagReporter, PureCompiler}; use reflexo_typst::{GenericExporter, ShadowApiExt, TypstSystemWorld}; use rustyline::completion::{Completer, Pair}; use rustyline::error::ReadlineError; @@ -16,7 +13,7 @@ use rustyline::validate::MatchingBracketValidator; use rustyline::{Cmd, CompletionType, Config, EditMode, Editor, KeyEvent}; use rustyline::{Helper, Validator}; use typst::diag::SourceDiagnostic; -use typst::{hint_invalid_main_file, World}; +use typst::World; use typst_ide::autocomplete; use crate::query::serialize; diff --git a/crates/conversion/typst2vec/src/pass/typst2vec.rs b/crates/conversion/typst2vec/src/pass/typst2vec.rs index 6c53fcaf..e28438c9 100644 --- a/crates/conversion/typst2vec/src/pass/typst2vec.rs +++ b/crates/conversion/typst2vec/src/pass/typst2vec.rs @@ -302,7 +302,7 @@ impl Typst2VecPassImpl { inner } FrameItem::Text(text) => { - let i = self.text(state, &text); + let i = self.text(state, text); self.spans.push_span(SourceRegion { region: src_reg, @@ -318,7 +318,7 @@ impl Typst2VecPassImpl { i } FrameItem::Shape(shape, s) => { - let i = self.shape(state, &shape); + let i = self.shape(state, shape); self.spans.push_span(SourceRegion { region: src_reg, @@ -330,7 +330,7 @@ impl Typst2VecPassImpl { i } FrameItem::Image(image, size, s) => { - let i = self.image(&image, *size); + let i = self.image(image, *size); self.spans.push_span(SourceRegion { region: src_reg, @@ -361,8 +361,8 @@ impl Typst2VecPassImpl { self.store(VecItem::ContentHint('\n')) } - // #[cfg(not(feature = "no-content-hint"))] - // FrameItem::ContentHint(c) => self.store(VecItem::ContentHint(*c)), + #[cfg(not(feature = "no-content-hint"))] + FrameItem::ContentHint(c) => self.store(VecItem::ContentHint(*c)), // todo: support page label }; diff --git a/crates/reflexo-typst/src/exporter/text.rs b/crates/reflexo-typst/src/exporter/text.rs index 1fc7058b..3c0d64b4 100644 --- a/crates/reflexo-typst/src/exporter/text.rs +++ b/crates/reflexo-typst/src/exporter/text.rs @@ -44,8 +44,8 @@ impl FullTextDigest { match item { Group(g) => Self::export_frame(f, &g.frame), Text(t) => f.write_str(t.text.as_str()), - // #[cfg(not(feature = "no-content-hint"))] - // ContentHint(c) => f.write_char(*c), + #[cfg(not(feature = "no-content-hint"))] + ContentHint(c) => f.write_char(*c), Link(..) | Tag(..) | Shape(..) | Image(..) => Ok(()), } } diff --git a/crates/reflexo-typst/src/lib.rs b/crates/reflexo-typst/src/lib.rs index d96e8cdf..d4e3a067 100644 --- a/crates/reflexo-typst/src/lib.rs +++ b/crates/reflexo-typst/src/lib.rs @@ -68,6 +68,7 @@ pub use exporter::{ GenericTransformer, Transformer, }; // pub use font::{FontLoader, FontResolver, FontSlot}; +pub use reflexo::typst_shim as compat; pub use reflexo::*; pub mod build_info { @@ -406,7 +407,7 @@ pub trait Compiler { self.reset()?; let res = match env.sink.as_mut() { - Some(sink) => ::typst::compile(world), + Some(_sink) => ::typst::compile(world), None => ::typst::compile(world), }; diff --git a/crates/reflexo-typst/src/query.rs b/crates/reflexo-typst/src/query.rs index ded5cadc..04ae626a 100644 --- a/crates/reflexo-typst/src/query.rs +++ b/crates/reflexo-typst/src/query.rs @@ -1,6 +1,6 @@ use comemo::Track; use typst::{ - diag::{EcoString, HintedString, StrResult}, + diag::{EcoString, StrResult}, eval::{eval_string, EvalMode}, foundations::{Content, LocatableSelector, Scope}, model::Document, diff --git a/packages/compiler/src/lib.rs b/packages/compiler/src/lib.rs index 6068dda4..2e2bed77 100644 --- a/packages/compiler/src/lib.rs +++ b/packages/compiler/src/lib.rs @@ -8,10 +8,10 @@ pub use reflexo_typst::*; use core::fmt; use std::{fmt::Write, path::Path, sync::Arc}; -use ::typst::utils::LazyHash; use error::TypstSourceDiagnostic; use font::cache::FontInfoCache; use js_sys::{Array, JsString, Uint32Array, Uint8Array}; +use reflexo_typst::compat::utils::LazyHash; use reflexo_typst::error::{long_diag_from_std, prelude::*, DiagMessage}; use reflexo_typst::font::web::BrowserFontSearcher; use reflexo_typst::package::browser::ProxyRegistry; @@ -266,7 +266,7 @@ impl TypstCompiler { return Err(error_once!("Unsupported offset encoding", offset_encoding: offset_encoding).into()); } }, - ); + )?; let mut result = Vec::new(); for token in tokens.iter() { result.push(token.delta_line); diff --git a/packages/typst.node/src/compiler/mod.rs b/packages/typst.node/src/compiler/mod.rs index 287d1c4e..4c926278 100644 --- a/packages/typst.node/src/compiler/mod.rs +++ b/packages/typst.node/src/compiler/mod.rs @@ -11,8 +11,8 @@ use reflexo_typst::config::{entry::EntryState, CompileFontOpts}; use reflexo_typst::error::prelude::*; use reflexo_typst::font::system::SystemFontSearcher; use reflexo_typst::package::http::HttpRegistry; -use reflexo_typst::typst::{foundations::IntoValue, prelude::Prehashed}; use reflexo_typst::vfs::{system::SystemAccessModel, Vfs}; +use reflexo_typst::{compat::LazyHash, typst::foundations::IntoValue}; use reflexo_typst::{ Bytes, CompileDriver, PureCompiler, TypstDict, TypstSystemUniverse, TypstSystemWorld, }; @@ -133,8 +133,8 @@ pub fn create_driver( } /// Convert the input pairs to a dictionary. -fn create_inputs(inputs: HashMap) -> Arc> { - Arc::new(Prehashed::new( +fn create_inputs(inputs: HashMap) -> Arc> { + Arc::new(LazyHash::new( inputs .iter() .map(|(k, v)| (k.as_str().into(), v.as_str().into_value())) diff --git a/packages/typst.node/src/lib.rs b/packages/typst.node/src/lib.rs index 1ac7e7c6..5d0e0048 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 { - self.0.title.as_ref().map(ToString::to_string) + self.0.title().as_ref().map(ToString::to_string) } /// Gets the authors of the document. #[napi(getter)] pub fn authors(&self) -> Option> { - let authors = self.0.author.iter(); + let authors = self.0.author().iter(); Some(authors.map(ToString::to_string).collect::>()) } /// Gets the keywords of the document. #[napi(getter)] pub fn keywords(&self) -> Option> { - let keywords = self.0.keywords.iter(); + let keywords = self.0.keywords().iter(); Some(keywords.map(ToString::to_string).collect::>()) } @@ -69,7 +69,7 @@ impl NodeTypstDocument { #[napi(getter)] pub fn date(&self) -> Option { self.0 - .date + .date() .custom() .flatten() .and_then(typst_datetime_to_unix_nanoseconds) @@ -81,7 +81,7 @@ impl NodeTypstDocument { /// explicitly. #[napi(getter)] pub fn enabled_auto_date(&self) -> bool { - self.0.date.is_auto() + self.0.date().is_auto() } } @@ -288,7 +288,7 @@ impl NodeCompiler { let mapped: Vec<_> = elements .into_iter() .filter_map(|c| match &args.field { - Some(field) => c.get_by_name(field), + Some(field) => c.get_by_name(field).ok(), _ => Some(c.into_value()), }) .collect();