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:
[]
= "2.3.1"
Then optimize some vector graphics:
use ;
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.