tinymist_world/
browser.rs

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