graphitepdf-stylesheet 0.4.0

Stylesheet primitives for GraphitePDF.
Documentation

Overview

graphitepdf-stylesheet provides CSS-like style maps, flattening, media-query resolution, unit normalization, and property expansion for GraphitePDF.


Scope

graphitepdf-stylesheet contains:

  • Style, StyleValue, and Stylesheet
  • Container and Orientation for environment-dependent resolution
  • flatten(), resolve_media_queries(), resolve_style(), and resolve_styles()
  • color normalization helpers such as transform_color()

Installation

cargo add graphitepdf-stylesheet

API Summary

Category Items
Style model Style, SafeStyle, ExpandedStyle, StyleValue
Resolution context Container, Orientation
Stylesheets Stylesheet
Resolution helpers flatten(), resolve_media_queries(), resolve_style(), resolve_styles(), transform_color()

Example

use graphitepdf_stylesheet::{Container, Style, Stylesheet};

fn main() {
    let mut style = Style::new();
    style.insert("width".to_string(), "50%".into());
    style.insert("padding".to_string(), 12.0.into());
    style.insert("backgroundColor".to_string(), "rgb(212, 88, 26)".into());

    let stylesheet = Stylesheet::new(style);
    let resolved = stylesheet.resolve(&Container::new(400.0, 200.0));

    assert!(resolved.contains_key("width"));
    assert!(resolved.contains_key("paddingTop"));
}

Design Principles

  • keep stylesheet behavior deterministic and data-oriented
  • separate CSS-like resolution from layout and rendering crates
  • expose flattening and resolution as ordinary functions
  • keep the crate useful outside of PDF-specific code paths

Role In GraphitePDF

This crate sits in the shared-services layer and feeds resolved style data into layout, style, document, and the root facade.


License

MIT