layout-cat 0.1.0

Box-model layout: cascade + block layout over a dom-cat tree using css-cat stylesheets. Produces a LayoutBox tree with positions and dimensions. No mut, no Rc/Arc, no interior mutability, no panics, exhaustive matches. Fourth sub-crate of a Servo-replacement webview runtime targeting Tauri.
//! Box-model layout engine.
//!
//! # Example
//!
//! ```
//! # fn main() -> Result<(), layout_cat::Error> {
//! use layout_cat::{layout, Viewport};
//!
//! let html_doc = html_cat::parse("<html><body><p>hi</p></body></html>")
//!     .map_err(|e| layout_cat::Error::Css(css_cat::Error::EmptySelectorList { at: css_cat::span::Span::new(css_cat::span::Position::new(1, 1, 0), css_cat::span::Position::new(1, 1, 0)) }))?;
//! let dom = dom_cat::Document::from_html_doc(&html_doc);
//! let sheet = css_cat::parse("p { width: 100px; padding: 8px; }")?;
//! let tree = layout(&dom, &sheet, Viewport::new(800, 600));
//! assert!(tree.root_box().is_some());
//! # Ok(())
//! # }
//! ```

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::similar_names)]
// IEEE-754 equality matches CSS layout comparison semantics.
#![allow(clippy::float_cmp)]

pub mod block;
pub mod box_tree;
pub mod cascade;
pub mod color;
pub mod error;
pub mod length;
pub mod style;

pub use box_tree::{LayoutBox, LayoutTree, Viewport};
pub use color::Color;
pub use error::Error;
pub use length::{Edges, LengthValue, Point, Rect};
pub use style::{ComputedStyle, Display};

use css_cat::Stylesheet;
use dom_cat::Document;

/// Compute layout for `doc` with `sheet` against `viewport`.
#[must_use]
pub fn layout(doc: &Document, sheet: &Stylesheet, viewport: Viewport) -> LayoutTree {
    let styles = cascade::cascade(doc, sheet);
    block::layout_document(doc, &styles, viewport)
}