Skip to content

Commit

Permalink
build: add stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Oct 2, 2024
1 parent 2c79cb1 commit 16f42c8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ worker = [
"web-sys/WorkerType",
]

web = ["render_canvas", "render_svg", "render_dom", "worker"]
web = ["render_canvas", "render_svg", "render_dom"]

debug_delta_update = []
test_render_document = []
Expand Down
58 changes: 50 additions & 8 deletions packages/renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pub(crate) mod utils;
pub(crate) mod builder;
pub(crate) mod render;
pub(crate) mod session;
#[cfg(feature = "worker")]
pub(crate) mod worker;

pub use builder::TypstRendererBuilder;
pub use session::RenderSession;
Expand Down Expand Up @@ -228,14 +226,58 @@ impl TypstRenderer {
session.reset_current(artifact_content)?;
Ok(session)
}
}

// ses.pixel_per_pt = options.as_ref().and_then(|o|
// o.pixel_per_pt).unwrap_or(2.);
#[cfg(feature = "worker")]
pub(crate) mod worker;
#[cfg(not(feature = "worker"))]
pub mod canvas_stub {
#![allow(dead_code)]
#![allow(unused_imports)]

use js_sys::{Promise, Uint8Array};
use reflexo_typst::error::prelude::*;
use wasm_bindgen::prelude::*;
use web_sys::HtmlCanvasElement;

use crate::{RenderPageImageOptions, RenderSession, TypstRenderer};

#[wasm_bindgen]
impl TypstRenderer {
pub async fn create_worker(&mut self, _w: JsValue) -> ZResult<TypstWorker> {
Err(error_once!("Renderer.WorkerFeatureNotEnabled"))
}

pub fn create_worker_bridge(self) -> ZResult<WorkerBridge> {
Err(error_once!("Renderer.WorkerFeatureNotEnabled"))
}
}

// ses.background_color = options
// .as_ref()
// .and_then(|o| o.background_color.clone())
// .unwrap_or("ffffff".to_string());
#[wasm_bindgen]
pub struct WorkerBridge {}

#[wasm_bindgen]
pub struct TypstWorker {}

#[wasm_bindgen]
impl TypstWorker {
pub fn manipulate_data(&mut self, _action: &str, _data: Uint8Array) -> ZResult<Promise> {
Err(error_once!("Renderer.WorkerFeatureNotEnabled"))
}

pub fn get_pages_info(&self) -> Promise {
panic!("Renderer.WorkerFeatureNotEnabled")
}

pub fn render_canvas(
&mut self,
_actions: Vec<u8>,
_canvas_list: Vec<HtmlCanvasElement>,
_data: Vec<RenderPageImageOptions>,
) -> ZResult<Promise> {
Err(error_once!("Renderer.WorkerFeatureNotEnabled"))
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 16f42c8

Please sign in to comment.