From 16f42c838ae659b29e7994fde87b0d245ba107fe Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Wed, 2 Oct 2024 18:28:42 +0800 Subject: [PATCH] build: add stubs --- packages/renderer/Cargo.toml | 2 +- packages/renderer/src/lib.rs | 58 +++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/packages/renderer/Cargo.toml b/packages/renderer/Cargo.toml index e2b2aebf..3e79572e 100644 --- a/packages/renderer/Cargo.toml +++ b/packages/renderer/Cargo.toml @@ -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 = [] diff --git a/packages/renderer/src/lib.rs b/packages/renderer/src/lib.rs index fe7a72ba..8c17b735 100644 --- a/packages/renderer/src/lib.rs +++ b/packages/renderer/src/lib.rs @@ -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; @@ -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 { + Err(error_once!("Renderer.WorkerFeatureNotEnabled")) + } + + pub fn create_worker_bridge(self) -> ZResult { + 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 { + Err(error_once!("Renderer.WorkerFeatureNotEnabled")) + } + + pub fn get_pages_info(&self) -> Promise { + panic!("Renderer.WorkerFeatureNotEnabled") + } + + pub fn render_canvas( + &mut self, + _actions: Vec, + _canvas_list: Vec, + _data: Vec, + ) -> ZResult { + Err(error_once!("Renderer.WorkerFeatureNotEnabled")) + } + } } #[cfg(test)]