1pub mod args;
4pub mod config;
5pub mod debug_loc;
6pub mod diag;
7pub mod entry;
8pub mod font;
9pub mod package;
10pub mod parser;
11pub mod source;
12pub mod world;
13
14pub use compute::*;
15pub use entry::*;
16pub use snapshot::*;
17pub use world::*;
18
19pub use tinymist_vfs as vfs;
20
21mod compute;
22mod snapshot;
23
24#[cfg(feature = "system")]
26pub mod system;
27#[cfg(feature = "system")]
28pub use system::{SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld, print_diagnostics};
29
30#[cfg(feature = "browser")]
32pub(crate) mod browser;
33#[cfg(feature = "browser")]
34pub use browser::{BrowserCompilerFeat, TypstBrowserUniverse, TypstBrowserWorld};
35
36use std::{path::Path, sync::Arc};
37
38use ecow::EcoVec;
39use tinymist_vfs::PathAccessModel as VfsAccessModel;
40use typst::diag::{At, FileResult, SourceResult};
41use typst::foundations::Bytes;
42use typst::syntax::{FileId, Span};
43
44use font::FontResolver;
45use package::PackageRegistry;
46
47pub trait ShadowApi {
49 fn shadow_paths(&self) -> Vec<Arc<Path>>;
51 fn shadow_ids(&self) -> Vec<FileId>;
53
54 fn reset_shadow(&mut self) {
56 for path in self.shadow_paths() {
57 self.unmap_shadow(&path).unwrap();
58 }
59 }
60
61 fn map_shadow(&mut self, path: &Path, content: Bytes) -> FileResult<()>;
63
64 fn unmap_shadow(&mut self, path: &Path) -> FileResult<()>;
66
67 fn map_shadow_by_id(&mut self, file_id: FileId, content: Bytes) -> FileResult<()>;
71
72 fn unmap_shadow_by_id(&mut self, file_id: FileId) -> FileResult<()>;
76}
77
78pub trait ShadowApiExt {
80 fn with_shadow_file<T>(
83 &mut self,
84 file_path: &Path,
85 content: Bytes,
86 f: impl FnOnce(&mut Self) -> SourceResult<T>,
87 ) -> SourceResult<T>;
88
89 fn with_shadow_file_by_id<T>(
94 &mut self,
95 file_id: FileId,
96 content: Bytes,
97 f: impl FnOnce(&mut Self) -> SourceResult<T>,
98 ) -> SourceResult<T>;
99}
100
101impl<C: ShadowApi> ShadowApiExt for C {
102 fn with_shadow_file<T>(
105 &mut self,
106 file_path: &Path,
107 content: Bytes,
108 f: impl FnOnce(&mut Self) -> SourceResult<T>,
109 ) -> SourceResult<T> {
110 self.map_shadow(file_path, content).at(Span::detached())?;
111 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
112 self.unmap_shadow(file_path).at(Span::detached())?;
113 res
114 }
115
116 fn with_shadow_file_by_id<T>(
121 &mut self,
122 file_id: FileId,
123 content: Bytes,
124 f: impl FnOnce(&mut Self) -> SourceResult<T>,
125 ) -> SourceResult<T> {
126 self.map_shadow_by_id(file_id, content)
127 .at(Span::detached())?;
128 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
129 self.unmap_shadow_by_id(file_id).at(Span::detached())?;
130 res
131 }
132}
133
134pub trait WorldDeps {
136 fn iter_dependencies(&self, f: &mut dyn FnMut(FileId));
138}
139
140pub trait CompilerFeat: Send + Sync + 'static {
142 type FontResolver: FontResolver + Send + Sync + Sized;
144 type AccessModel: VfsAccessModel + Clone + Send + Sync + Sized;
146 type Registry: PackageRegistry + Send + Sync + Sized;
148}
149
150#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
152pub enum DiagnosticFormat {
153 #[default]
155 Human,
156 Short,
158}
159
160pub mod build_info {
162 pub static VERSION: &str = env!("CARGO_PKG_VERSION");
164}