tinymist_world/
browser.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::{path::PathBuf, sync::Arc};

use tinymist_vfs::browser::ProxyAccessModel;
use typst::foundations::Dict as TypstDict;
use typst::utils::LazyHash;
use typst::Features;

use crate::entry::EntryState;
use crate::font::FontResolverImpl;
use crate::package::registry::JsRegistry;
use crate::package::RegistryPathMapper;

/// A world that provides access to the browser.
/// It is under development.
pub type TypstBrowserUniverse = crate::world::CompilerUniverse<BrowserCompilerFeat>;
pub type TypstBrowserWorld = crate::world::CompilerWorld<BrowserCompilerFeat>;

#[derive(Debug, Clone, Copy)]
pub struct BrowserCompilerFeat;

impl crate::CompilerFeat for BrowserCompilerFeat {
    /// Uses [`FontResolverImpl`] directly.
    type FontResolver = FontResolverImpl;
    type AccessModel = ProxyAccessModel;
    type Registry = JsRegistry;
}

impl TypstBrowserUniverse {
    pub fn new(
        root_dir: PathBuf,
        inputs: Option<Arc<LazyHash<TypstDict>>>,
        access_model: ProxyAccessModel,
        registry: JsRegistry,
        font_resolver: FontResolverImpl,
    ) -> Self {
        let registry = Arc::new(registry);
        let resolver = Arc::new(RegistryPathMapper::new(registry.clone()));

        let vfs = tinymist_vfs::Vfs::new(resolver, access_model);

        // todo: enable html
        Self::new_raw(
            EntryState::new_rooted(root_dir.into(), None),
            Features::default(),
            inputs,
            vfs,
            registry,
            Arc::new(font_resolver),
        )
    }
}