Skip to main content

Crate use_svg

Crate use_svg 

Source
Expand description

§use-svg

Practical SVG utility primitives for inspection, extraction, normalization, minification, and lightweight document construction.

Warning: use-svg is experimental and may change before 0.3.0.

§Example

use use_svg::{SvgPath, build_svg_icon, extract_path_data, extract_view_box};

let source = r#"<svg viewBox="0 0 24 24"><path d="M3 3h18v18H3z"/></svg>"#;
let view_box = extract_view_box(source).unwrap();
let paths = extract_path_data(source);

assert_eq!(paths, vec!["M3 3h18v18H3z".to_string()]);

let icon = build_svg_icon(view_box, &[SvgPath::new("M3 3h18v18H3z")]);
assert!(icon.starts_with("<svg "));

§Scope

  • SVG document detection and root extraction
  • Width, height, and SVG size extraction
  • viewBox parsing and formatting
  • SVG element and attribute helpers
  • Path data extraction helpers
  • Fill, stroke, and transform attribute helpers
  • Metadata extraction for common title and description tags
  • Basic normalization and minification
  • Simple SVG document and icon construction

§Non-goals

  • A full SVG rendering engine
  • A full XML parser or DOM implementation
  • A complete SVG specification parser
  • CSS layout or browser compatibility behavior
  • Heavy dependency-driven parsing pipelines

§License

Licensed under either the MIT license or the Apache License, Version 2.0, at your option.

Re-exports§

pub use attribute::SvgAttribute;
pub use attribute::extract_attributes;
pub use attribute::get_attribute;
pub use attribute::has_attribute;
pub use color::extract_fill_values;
pub use color::extract_stroke_values;
pub use document::SvgDocument;
pub use document::SvgMetadata;
pub use document::build_svg_document;
pub use document::build_svg_icon;
pub use document::extract_description;
pub use document::extract_height;
pub use document::extract_metadata;
pub use document::extract_svg_root;
pub use document::extract_title;
pub use document::extract_view_box;
pub use document::extract_width;
pub use document::has_svg_root;
pub use document::is_svg;
pub use document::strip_xml_declaration;
pub use element::SvgElement;
pub use element::parse_element;
pub use normalize::minify_svg_basic;
pub use normalize::normalize_svg;
pub use normalize::strip_comments;
pub use path::SvgPath;
pub use path::extract_path_data;
pub use path::extract_paths;
pub use size::SvgSize;
pub use size::extract_size;
pub use transform::SvgTransform;
pub use transform::extract_transform_values;
pub use transform::normalize_transform;
pub use view_box::SvgViewBox;
pub use view_box::format_view_box;
pub use view_box::parse_view_box;

Modules§

attribute
color
document
element
normalize
path
size
transform
view_box