10 stable releases
| 2.4.2 | Mar 13, 2026 |
|---|---|
| 2.3.1 | Feb 11, 2026 |
| 0.1.0 | Feb 10, 2026 |
#678 in Images
Used in 6 crates
245KB
5.5K
SLoC
vexy-vsvg
This is the engine room. vexy-vsvg is the core library that powers the Vexy optimizer. It parses SVG text into a mutable Abstract Syntax Tree (AST), runs it through a gauntlet of optimization plugins, and spits out a leaner SVG string.
It is a Rust port of SVGO, designed to be fast, safe, and compatible.
What it does
- Parsing: Uses
quick-xmlto turn SVG text into a DOM-like structure. - Plugin Pipeline: Orchestrates 52 distinct optimization passes (e.g., removing comments, merging paths, minifying styles).
- Stringification: Serializes the AST back to SVG, with configurable indentation and formatting.
Usage
Add this to your Cargo.toml:
[dependencies]
vexy-vsvg = "2.3.1"
Then optimize some vector graphics:
use vexy_vsvg::{optimize_default, parse_svg, stringify};
fn main() {
let svg_input = r#"<svg><rect width="100" height="100"/></svg>"#;
// The easy way: one-shot optimization
let result = optimize_default(svg_input).expect("Failed to optimize");
println!("Optimized: {}", result.data);
// The manual way: parsing and stringifying
let doc = parse_svg(svg_input).expect("Failed to parse");
// ... modify doc here ...
let output = stringify(&doc).expect("Failed to stringify");
}
Features
parallel: multithreaded processing for batch operations (enabled by default in the CLI).wasm: Helper traits for WebAssembly compilation.python: Bindings for Python integration.
Architecture
We use a custom AST optimized for SVG's quirks.
Document: The root container.Element: Represents tags like<rect>or<g>. Attributes are stored in anIndexMapto preserve order.Node: The atomic unit of the tree (Element, Text, Comment, etc.).
Text nodes use Box<str> instead of String to save 8 bytes per node, because immutable text is usually enough for SVG data.
Dependencies
~7–12MB
~214K SLoC