Skip to content

Commit

Permalink
build: update shim
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Oct 19, 2024
1 parent 91fd4ff commit e5b7fd8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 59 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 7 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +114,12 @@ pub fn query(args: QueryArgs) -> ! {

exporter.push_front(Box::new(move |world: &dyn World, output: Arc<Document>| {
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(());
Expand Down
5 changes: 3 additions & 2 deletions crates/conversion/vec2svg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -116,7 +115,9 @@ pub fn render_svg_html<Feat: ExportFeature>(output: &TypstDocument) -> String {
html.push(r#"<!DOCTYPE html><html><head><meta charset="utf-8" /><title>"#.into());
html.push(SvgText::Plain(
output
.title()
.info
.title
.as_ref()
.map(|s| s.to_string())
.unwrap_or_else(|| "Typst TypstDocument".into()),
));
Expand Down
1 change: 0 additions & 1 deletion crates/reflexo-typst-shim/src/nightly/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod model;
pub mod syntax;
pub mod utils;

Expand Down
37 changes: 0 additions & 37 deletions crates/reflexo-typst-shim/src/nightly/model.rs

This file was deleted.

2 changes: 2 additions & 0 deletions crates/reflexo-typst-shim/src/stable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod syntax;
pub mod utils;

pub use typst::utils::LazyHash;
10 changes: 6 additions & 4 deletions crates/reflexo-typst-shim/src/stable/syntax.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion crates/reflexo-typst-shim/src/stable/utils.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//! Typst utils
pub use typst::util::*;
pub use typst::utils::*;
13 changes: 7 additions & 6 deletions packages/typst.node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<_>>())
}

Expand All @@ -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)
Expand All @@ -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()
}
}

Expand Down

0 comments on commit e5b7fd8

Please sign in to comment.