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
14#[cfg(any(test, feature = "mock"))]
16pub mod mock;
17
18pub use compute::*;
19pub use entry::*;
20pub use snapshot::*;
21pub use world::*;
22
23pub use tinymist_vfs as vfs;
24
25mod compute;
26mod snapshot;
27
28#[cfg(feature = "system")]
30pub mod system;
31#[cfg(feature = "system")]
32pub use system::{SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld, print_diagnostics};
33
34#[cfg(feature = "browser")]
36pub(crate) mod browser;
37#[cfg(feature = "browser")]
38pub use browser::{BrowserCompilerFeat, TypstBrowserUniverse, TypstBrowserWorld};
39
40use std::{path::Path, sync::Arc};
41
42use ecow::EcoVec;
43use tinymist_vfs::PathAccessModel as VfsAccessModel;
44use typst::diag::{At, FileResult, SourceResult};
45use typst::foundations::Bytes;
46use typst::syntax::{FileId, Span};
47
48use font::FontResolver;
49use package::PackageRegistry;
50
51pub trait ShadowApi {
53 fn shadow_paths(&self) -> Vec<Arc<Path>>;
55 fn shadow_ids(&self) -> Vec<FileId>;
57
58 fn reset_shadow(&mut self) {
60 for path in self.shadow_paths() {
61 self.unmap_shadow(&path).unwrap();
62 }
63 }
64
65 fn map_shadow(&mut self, path: &Path, content: Bytes) -> FileResult<()>;
67
68 fn unmap_shadow(&mut self, path: &Path) -> FileResult<()>;
70
71 fn map_shadow_by_id(&mut self, file_id: FileId, content: Bytes) -> FileResult<()>;
75
76 fn unmap_shadow_by_id(&mut self, file_id: FileId) -> FileResult<()>;
80}
81
82pub trait ShadowApiExt {
84 fn with_shadow_file<T>(
87 &mut self,
88 file_path: &Path,
89 content: Bytes,
90 f: impl FnOnce(&mut Self) -> SourceResult<T>,
91 ) -> SourceResult<T>;
92
93 fn with_shadow_file_by_id<T>(
98 &mut self,
99 file_id: FileId,
100 content: Bytes,
101 f: impl FnOnce(&mut Self) -> SourceResult<T>,
102 ) -> SourceResult<T>;
103}
104
105impl<C: ShadowApi> ShadowApiExt for C {
106 fn with_shadow_file<T>(
109 &mut self,
110 file_path: &Path,
111 content: Bytes,
112 f: impl FnOnce(&mut Self) -> SourceResult<T>,
113 ) -> SourceResult<T> {
114 self.map_shadow(file_path, content).at(Span::detached())?;
115 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
116 self.unmap_shadow(file_path).at(Span::detached())?;
117 res
118 }
119
120 fn with_shadow_file_by_id<T>(
125 &mut self,
126 file_id: FileId,
127 content: Bytes,
128 f: impl FnOnce(&mut Self) -> SourceResult<T>,
129 ) -> SourceResult<T> {
130 self.map_shadow_by_id(file_id, content)
131 .at(Span::detached())?;
132 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
133 self.unmap_shadow_by_id(file_id).at(Span::detached())?;
134 res
135 }
136}
137
138pub trait WorldDeps {
140 fn iter_dependencies(&self, f: &mut dyn FnMut(FileId));
142}
143
144pub trait CompilerFeat: Send + Sync + 'static {
146 type FontResolver: FontResolver + Send + Sync + Sized;
148 type AccessModel: VfsAccessModel + Clone + Send + Sync + Sized;
150 type Registry: PackageRegistry + Send + Sync + Sized;
152}
153
154#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
156pub enum DiagnosticFormat {
157 #[default]
159 Human,
160 Short,
162}
163
164pub mod build_info {
166 pub static VERSION: &str = env!("CARGO_PKG_VERSION");
168}