tinymist_world/
browser.rs

1use std::{path::PathBuf, sync::Arc};
2
3use tinymist_vfs::browser::ProxyAccessModel;
4use typst::Features;
5use typst::foundations::Dict as TypstDict;
6use typst::utils::LazyHash;
7
8use crate::entry::EntryState;
9use crate::font::FontResolverImpl;
10use crate::package::RegistryPathMapper;
11use crate::package::registry::JsRegistry;
12
13/// A universe that provides access to the browser.
14pub type TypstBrowserUniverse = crate::world::CompilerUniverse<BrowserCompilerFeat>;
15/// A world that provides access to the browser.
16pub type TypstBrowserWorld = crate::world::CompilerWorld<BrowserCompilerFeat>;
17
18/// The feature of the browser world.
19#[derive(Debug, Clone, Copy)]
20pub struct BrowserCompilerFeat;
21
22impl crate::CompilerFeat for BrowserCompilerFeat {
23    /// Uses [`FontResolverImpl`] directly.
24    type FontResolver = FontResolverImpl;
25    type AccessModel = ProxyAccessModel;
26    type Registry = JsRegistry;
27}
28
29impl TypstBrowserUniverse {
30    /// Creates a new browser universe.
31    pub fn new(
32        root_dir: PathBuf,
33        inputs: Option<Arc<LazyHash<TypstDict>>>,
34        access_model: ProxyAccessModel,
35        registry: JsRegistry,
36        font_resolver: FontResolverImpl,
37    ) -> Self {
38        let registry = Arc::new(registry);
39        let resolver = Arc::new(RegistryPathMapper::new(registry.clone()));
40
41        let vfs = tinymist_vfs::Vfs::new(resolver, access_model);
42
43        // todo: enable html
44        Self::new_raw(
45            EntryState::new_rooted(root_dir.into(), None),
46            Features::default(),
47            inputs,
48            vfs,
49            registry,
50            Arc::new(font_resolver),
51            None, // creation_timestamp - not used in browser context
52        )
53    }
54}