Skip to main content

decant_render/
lib.rs

1//! `decant-render` — headless-Chrome SPA rendering (feature-gated).
2//!
3//! When compiled **without** the `render` feature this crate is an empty stub —
4//! it exports a `RenderError` type and a placeholder `not_available()` function
5//! so that the main `decant` crate can reference it unconditionally and gate at runtime.
6//!
7//! Enable the `render` Cargo feature to pull in `chromiumoxide` and the real impl:
8//! ```sh
9//! cargo build --features render
10//! ```
11
12pub mod error;
13
14#[cfg(feature = "render")]
15pub mod backend;
16#[cfg(feature = "render")]
17pub mod browser;
18#[cfg(feature = "render")]
19pub mod page;
20#[cfg(feature = "render")]
21pub mod screenshot;
22
23pub use error::RenderError;
24
25#[cfg(feature = "render")]
26pub use backend::BrowserBackend;
27#[cfg(feature = "render")]
28pub use browser::Browser;
29#[cfg(feature = "render")]
30pub use page::render_html;
31#[cfg(feature = "render")]
32pub use screenshot::{DESKTOP, MOBILE, Screenshot, TABLET, Viewport, capture_viewports};
33
34/// Returns `Err` with a helpful message when the crate was not compiled with `--features render`.
35///
36/// # Errors
37///
38/// Returns `RenderError::FeatureNotEnabled`.
39#[cfg(not(feature = "render"))]
40pub fn not_available() -> Result<(), RenderError> {
41    Err(RenderError::FeatureNotEnabled)
42}
43
44#[cfg(not(feature = "render"))]
45/// Stub module for browser backends.
46pub mod backend {
47    /// Stub type for BrowserBackend when render feature is disabled.
48    #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
49    pub enum BrowserBackend {
50        /// Chrome
51        Chrome,
52        /// Lightpanda,
53        Lightpanda,
54    }
55}
56
57#[cfg(not(feature = "render"))]
58/// Stub module for browser instance.
59pub mod browser {
60    /// Stub type for Browser when render feature is disabled.
61    pub struct Browser;
62}
63
64#[cfg(not(feature = "render"))]
65/// Stub module for viewport screenshots.
66pub mod screenshot {
67    /// Stub type for Viewport when render feature is disabled.
68    #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
69    pub struct Viewport {
70        /// Name
71        pub name: &'static str,
72        /// Width
73        pub width: u32,
74        /// Height
75        pub height: u32,
76    }
77    /// MOBILE preset stub
78    pub const MOBILE: Viewport = Viewport {
79        name: "mobile",
80        width: 390,
81        height: 844,
82    };
83    /// TABLET preset stub
84    pub const TABLET: Viewport = Viewport {
85        name: "tablet",
86        width: 768,
87        height: 1024,
88    };
89    /// DESKTOP preset stub
90    pub const DESKTOP: Viewport = Viewport {
91        name: "desktop",
92        width: 1440,
93        height: 900,
94    };
95}
96
97#[cfg(not(feature = "render"))]
98pub use backend::BrowserBackend;
99#[cfg(not(feature = "render"))]
100pub use browser::Browser;
101#[cfg(not(feature = "render"))]
102pub use screenshot::{DESKTOP, MOBILE, TABLET, Viewport};