pub mod source;
pub mod config;
pub mod entry;
pub use entry::*;
pub mod world;
pub use world::*;
pub mod font;
pub mod package;
pub mod parser;
#[cfg(feature = "system")]
pub mod system;
#[cfg(feature = "system")]
pub use system::{SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld};
#[cfg(feature = "browser")]
pub(crate) mod browser;
#[cfg(feature = "browser")]
pub use browser::{BrowserCompilerFeat, TypstBrowserUniverse, TypstBrowserWorld};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use ecow::EcoVec;
use reflexo::ImmutPath;
use reflexo_vfs::AccessModel as VfsAccessModel;
use typst::{
diag::{At, FileResult, SourceResult},
foundations::Bytes,
syntax::FileId,
syntax::Span,
};
use font::FontResolver;
use package::PackageRegistry;
pub trait ShadowApi {
fn _shadow_map_id(&self, _file_id: FileId) -> FileResult<PathBuf> {
unimplemented!()
}
fn shadow_paths(&self) -> Vec<Arc<Path>>;
fn reset_shadow(&mut self) {
for path in self.shadow_paths() {
self.unmap_shadow(&path).unwrap();
}
}
fn map_shadow(&mut self, path: &Path, content: Bytes) -> FileResult<()>;
fn unmap_shadow(&mut self, path: &Path) -> FileResult<()>;
fn map_shadow_by_id(&mut self, file_id: FileId, content: Bytes) -> FileResult<()> {
let file_path = self._shadow_map_id(file_id)?;
self.map_shadow(&file_path, content)
}
fn unmap_shadow_by_id(&mut self, file_id: FileId) -> FileResult<()> {
let file_path = self._shadow_map_id(file_id)?;
self.unmap_shadow(&file_path)
}
}
pub trait ShadowApiExt {
fn with_shadow_file<T>(
&mut self,
file_path: &Path,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T>;
fn with_shadow_file_by_id<T>(
&mut self,
file_id: FileId,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T>;
}
impl<C: ShadowApi> ShadowApiExt for C {
fn with_shadow_file<T>(
&mut self,
file_path: &Path,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T> {
self.map_shadow(file_path, content).at(Span::detached())?;
let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
self.unmap_shadow(file_path).at(Span::detached())?;
res
}
fn with_shadow_file_by_id<T>(
&mut self,
file_id: FileId,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T> {
let file_path = self._shadow_map_id(file_id).at(Span::detached())?;
self.with_shadow_file(&file_path, content, f)
}
}
pub trait WorldDeps {
fn iter_dependencies(&self, f: &mut dyn FnMut(ImmutPath));
}
type CodespanResult<T> = Result<T, CodespanError>;
type CodespanError = codespan_reporting::files::Error;
pub trait CompilerFeat {
type FontResolver: FontResolver + Send + Sync + Sized;
type AccessModel: VfsAccessModel + Clone + Send + Sync + Sized;
type Registry: PackageRegistry + Send + Sync + Sized;
}
pub mod build_info {
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
}