Skip to content

Commit

Permalink
dev: upgrade to typst v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 1, 2023
1 parent 4837967 commit fded827
Show file tree
Hide file tree
Showing 59 changed files with 289 additions and 1,219 deletions.
280 changes: 132 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ strip = true
pixglyph = "0.2"
typst = "0.9.0"
typst-ide = "0.9.0"
typst-library = "0.9.0"
typst-pdf = "0.9.0"
typst-syntax = "0.9.0"
ttf-parser = "0.19.2"

Expand All @@ -94,7 +94,7 @@ tokio = { version = "1.28.1", features = ["full"] }
# data structure and algorithm
append-only-vec = "0.1.2"
bytemuck = "1"
comemo = "0.3"
comemo = "0.3.1"
dissimilar = "1.0"
elsa = "1.8.1"
ecow = "0.2"
Expand Down Expand Up @@ -222,22 +222,19 @@ typst-ts-serde-exporter = { path = "exporter/serde" }
typst-ts-svg-exporter = { path = "exporter/svg" }
typst-ts-text-exporter = { path = "exporter/text" }

# typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
# typst-library = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
# typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
# typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0" }
hayagriva = { git = "https://github.com/Myriad-Dreamin/hayagriva.git", branch = "typst.ts-v0.9.0" }
# typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
# typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
# typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
# typst-pdf = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst-ts-v0.10.0" }

typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0-content-hint" }
typst-library = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0-content-hint" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0-content-hint" }
typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.9.0-content-hint" }
# hayagriva = { git = "https://github.com/Myriad-Dreamin/hayagriva.git", branch = "typst.ts-v0.9.0" }
typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst-ts-v0.10.0-content-hint" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst-ts-v0.10.0-content-hint" }
typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst-ts-v0.10.0-content-hint" }
typst-pdf = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst-ts-v0.10.0-content-hint" }

# typst = { path = "../typst/crates/typst" }
# typst-library = { path = "../typst/crates/typst-library" }
# typst-syntax = { path = "../typst/crates/typst-syntax" }
# typst-ide = { path = "../typst/crates/typst-ide" }
# hayagriva = { path = "../hayagriva" }
# typst-pdf = { path = "../typst/crates/typst-pdf" }

# fontdb = { path = "../fontdb" }
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repository.workspace = true

[dependencies]
typst.workspace = true
typst-library.workspace = true
typst-ide.workspace = true

clap.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion cli/src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use typst::doc::Document;
use typst::model::Document;
use typst_ts_compiler::{
service::{
features::{FeatureSet, DIAG_FMT_FEATURE},
Expand Down
4 changes: 2 additions & 2 deletions cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use typst_ts_svg_exporter::DefaultExportFeature;

use crate::{CompileArgs, ExportArgs};

type GroupDocExporter = GroupExporter<typst::doc::Document>;
type GroupDocExporter = GroupExporter<typst::model::Document>;

/// builtin formats should be enabled by default, and non-builtin formats should
/// be
Expand Down Expand Up @@ -114,7 +114,7 @@ fn prepare_exporters_impl(
}
return GroupExporter::new(doc);

type Doc = typst::doc::Document;
type Doc = typst::model::Document;

type WithAst = typst_ts_ast_exporter::AstExporter;
// type WithJson<T> = typst_ts_serde_exporter::JsonExporter<T>;
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use clap::FromArgMatches;
use typst::{doc::Document, font::FontVariant, World};
use typst::{model::Document, text::FontVariant, World};

use typst_ts_cli::{
compile::compile_export,
Expand Down Expand Up @@ -45,8 +45,8 @@ fn main() {
// Better?
if !matches!(&opts.sub, Some(Subcommands::Compile(CompileArgs { trace: _trace @ Some(_), .. }))) {
builder
.filter_module("typst::", log::LevelFilter::Warn)
.filter_module("typst_library::", log::LevelFilter::Warn)
.filter_module("typst", log::LevelFilter::Warn)
.filter_module("typst_ts", log::LevelFilter::Info)
.filter_module("tracing::", log::LevelFilter::Off);
}
builder.init();
Expand Down
8 changes: 5 additions & 3 deletions cli/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::Serialize;
use typst::diag::{bail, StrResult};
use typst_library::prelude::*;
use typst::{
diag::{bail, eco_format, StrResult},
foundations::{Content, IntoValue},
};

use crate::QueryArgs;

Expand All @@ -13,7 +15,7 @@ pub fn format(elements: Vec<Content>, command: &QueryArgs) -> StrResult<String>
let mapped: Vec<_> = elements
.into_iter()
.filter_map(|c| match &command.field {
Some(field) => c.field(field),
Some(field) => c.get_by_name(field),
_ => Some(c.into_value()),
})
.collect();
Expand Down
15 changes: 9 additions & 6 deletions cli/src/query_repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustyline::{Helper, Validator};

use typst_ts_compiler::service::{CompileDriver, CompileReport, Compiler, ConsoleDiagReporter};
use typst_ts_compiler::{ShadowApi, TypstSystemWorld};
use typst_ts_core::{typst::prelude::*, GenericExporter, TakeAs};
use typst_ts_core::{typst::prelude::*, GenericExporter};

use crate::query::serialize;
use crate::CompileOnceArgs;
Expand Down Expand Up @@ -129,12 +129,15 @@ impl Completer for ReplContext {
driver.world.reset();
let typst_completions = driver
.with_shadow_file_by_id(main_id, dyn_content.as_bytes().into(), |driver| {
let frames = driver
.compile(&mut Default::default())
.map(|d| d.take().pages);
let frames = frames.as_ref().map(|v| v.as_slice()).unwrap_or_default();
let doc = driver.compile(&mut Default::default()).ok();
let source = driver.world.main();
Ok(autocomplete(&driver.world, frames, &source, cursor, true))
Ok(autocomplete(
&driver.world,
doc.as_ref().map(|f| f.as_ref()),
&source,
cursor,
true,
))
})
.ok()
.flatten();
Expand Down
1 change: 0 additions & 1 deletion compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repository.workspace = true
[dependencies]

typst.workspace = true
typst-library.workspace = true
comemo.workspace = true

once_cell.workspace = true
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/eval.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use comemo::{Track, TrackedMut};
use typst::{
diag::SourceResult,
eval::{Module, Route, Tracer},
World,
};
use typst::{diag::SourceResult, engine::Route, eval::Tracer, foundations::Module, World};

/// Compile a source file into a module.
///
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/font/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use fontdb::Database;
use sha2::{Digest, Sha256};
use typst::{
diag::{FileError, FileResult},
font::{FontBook, FontInfo},
text::{FontBook, FontInfo},
};

use typst_ts_core::{
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/font/web/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use js_sys::ArrayBuffer;
use typst::font::{
use typst::text::{
Coverage, Font, FontBook, FontFlags, FontInfo, FontStretch, FontStyle, FontVariant, FontWeight,
};
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -250,7 +250,7 @@ impl FontBuilder {
fn font_web_to_typst(
&self,
val: &JsValue,
) -> ZResult<(JsValue, js_sys::Function, Vec<typst::font::FontInfo>)> {
) -> ZResult<(JsValue, js_sys::Function, Vec<typst::text::FontInfo>)> {
let mut postscript_name = String::new();
let mut family = String::new();
let mut full_name = String::new();
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/package/browser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{io::Read, path::Path};

use js_sys::Uint8Array;
use typst_library::prelude::*;
use typst::diag::eco_format;
use wasm_bindgen::{prelude::*, JsValue};

use super::{PackageError, PackageSpec, Registry};
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/package/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::Path, sync::Arc};

use parking_lot::Mutex;
use typst::eval::eco_format;
use typst::diag::eco_format;

use super::{DummyNotifier, Notifier, PackageError, PackageSpec, Registry};

Expand Down
3 changes: 1 addition & 2 deletions compiler/src/service/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::{
use serde::Serialize;
use tokio::sync::{mpsc, oneshot};
use typst::{
doc::{Frame, FrameItem, Position},
geom::Point,
layout::{Frame, FrameItem, Point, Position},
syntax::{LinkedNode, Source, Span, SyntaxKind, VirtualPath},
World,
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/service/diag/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use typst::syntax::Span;
use typst::WorldExt;
use typst::{diag::SourceDiagnostic, World};

use typst::eval::eco_format;
use typst::diag::eco_format;
use typst_ts_core::{typst::prelude::*, GenericExporter, PhantomParamData, TakeAs, TypstFileId};

use crate::service::features::{
Expand Down
19 changes: 10 additions & 9 deletions compiler/src/service/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
};

pub trait WorldExporter {
fn export(&mut self, output: Arc<typst::doc::Document>) -> SourceResult<()>;
fn export(&mut self, output: Arc<typst::model::Document>) -> SourceResult<()>;
}

pub struct CompileExporter<C: Compiler> {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<C: Compiler> CompileExporter<C> {

impl<C: Compiler> WorldExporter for CompileExporter<C> {
/// Export a typst document using `typst_ts_core::DocumentExporter`.
fn export(&mut self, output: Arc<typst::doc::Document>) -> SourceResult<()> {
fn export(&mut self, output: Arc<typst::model::Document>) -> SourceResult<()> {
self.exporter.export(self.compiler.world(), output)
}
}
Expand All @@ -62,7 +62,7 @@ impl<C: Compiler> CompileMiddleware for CompileExporter<C> {
&mut self.compiler
}

fn wrap_compile(&mut self, env: &mut CompileEnv) -> SourceResult<Arc<typst::doc::Document>> {
fn wrap_compile(&mut self, env: &mut CompileEnv) -> SourceResult<Arc<typst::model::Document>> {
let doc = self.inner_mut().compile(env)?;
self.export(doc.clone())?;

Expand Down Expand Up @@ -141,7 +141,7 @@ where

impl<C: Compiler + WorldExporter> WorldExporter for CompileReporter<C> {
/// Export a typst document using `typst_ts_core::DocumentExporter`.
fn export(&mut self, output: Arc<typst::doc::Document>) -> SourceResult<()> {
fn export(&mut self, output: Arc<typst::model::Document>) -> SourceResult<()> {
self.compiler.export(output)
}
}
Expand All @@ -157,7 +157,7 @@ impl<C: Compiler> CompileMiddleware for CompileReporter<C> {
&mut self.compiler
}

fn wrap_compile(&mut self, env: &mut CompileEnv) -> SourceResult<Arc<typst::doc::Document>> {
fn wrap_compile(&mut self, env: &mut CompileEnv) -> SourceResult<Arc<typst::model::Document>> {
let start = crate::Time::now();
let id = self.main_id();
if WITH_COMPILING_STATUS_FEATURE.retrieve(&env.features) {
Expand Down Expand Up @@ -207,7 +207,7 @@ impl<C: Compiler> CompileMiddleware for CompileReporter<C> {
}
}

pub type LayoutWidths = Vec<typst::geom::Abs>;
pub type LayoutWidths = Vec<typst::layout::Abs>;

pub type PostProcessLayoutFn = Box<
dyn Fn(&mut ModuleBuilder, Arc<TypstDocument>, LayoutRegionNode) -> LayoutRegionNode
Expand Down Expand Up @@ -249,8 +249,9 @@ impl<C: Compiler + ShadowApi> DynamicLayoutCompiler<C> {
enable_dynamic_layout: false,
extension: "multi.sir.in".to_owned(),
layout_widths: LayoutWidths::from_iter(
(0..40)
.map(|i| typst::geom::Abs::pt(750.0) - typst::geom::Abs::pt(i as f64 * 10.0)),
(0..40).map(|i| {
typst::layout::Abs::pt(750.0) - typst::layout::Abs::pt(i as f64 * 10.0)
}),
),
post_process_layout: None,
post_process_layouts: None,
Expand Down Expand Up @@ -309,7 +310,7 @@ impl<C: Compiler + ShadowApi> DynamicLayoutCompiler<C> {
#[cfg(feature = "dynamic-layout")]
impl<C: Compiler + ShadowApi> WorldExporter for DynamicLayoutCompiler<C> {
/// Export a typst document using `typst_ts_core::DocumentExporter`.
fn export(&mut self, _output: Arc<typst::doc::Document>) -> SourceResult<()> {
fn export(&mut self, _output: Arc<typst::model::Document>) -> SourceResult<()> {
use std::str::FromStr;

use typst::{
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::{
use crate::{vfs::notify::FilesystemEvent, ShadowApi};
use typst::{
diag::{At, FileResult, Hint, SourceDiagnostic, SourceResult},
doc::Document,
eval::Tracer,
model::Content,
foundations::Content,
model::Document,
syntax::Span,
World,
};
Expand Down
9 changes: 5 additions & 4 deletions compiler/src/service/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use comemo::Track;
use typst::{
diag::{EcoString, StrResult},
doc::Document,
eval::{eval_string, EvalMode, Scope},
model::{Content, Introspector, LocatableSelector},
eval::{eval_string, EvalMode},
foundations::{Content, LocatableSelector, Scope},
model::Document,
syntax::Span,
World,
};
Expand All @@ -28,7 +28,8 @@ pub fn retrieve(world: &dyn World, selector: &str, document: &Document) -> StrRe
})?
.cast::<LocatableSelector>()?;

Ok(Introspector::new(&document.pages)
Ok(document
.introspector
.query(&selector.0)
.into_iter()
.map(|x| x.into_inner())
Expand Down
9 changes: 4 additions & 5 deletions compiler/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use typst::{
diag::{FileError, FileResult, SourceResult},
eval::{Datetime, Library},
font::{Font, FontBook},
foundations::Datetime,
syntax::{Source, VirtualPath},
World,
text::{Font, FontBook},
Library, World,
};

use typst_ts_core::{
Expand Down Expand Up @@ -82,8 +82,7 @@ impl<F: CompilerFeat> CompilerWorld<F> {
) -> Self {
// Hook up the lang items.
// todo: bad upstream changes
let library = Prehashed::new(typst_library::build());
typst::eval::set_lang_items(library.items.clone());
let library = Prehashed::new(typst::Library::build());

Self {
root: root_dir.into(),
Expand Down
20 changes: 0 additions & 20 deletions core/src/annotation/link.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use serde::{Deserialize, Serialize};
use typst::{
doc::{Document, Position},
model::{Introspector, Location},
};

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct AnnotationBox {
Expand Down Expand Up @@ -46,19 +42,3 @@ pub struct LinkAnnotation {
/// The action to perform when the annotation is activated.
pub action: LinkAction,
}

pub struct AnnotationProcessor {
introspector: Introspector,
}

impl AnnotationProcessor {
pub fn new(doc: &Document) -> Self {
Self {
introspector: Introspector::new(&doc.pages),
}
}

pub fn process_location(&self, location: Location) -> Position {
self.introspector.position(location)
}
}
Loading

0 comments on commit fded827

Please sign in to comment.