vexy-vsvg-plugin-sdk 2.3.1

Plugin SDK for vexy-vsvg
Documentation

Plugin SDK for vexy-vsvg — everything you need to build an SVG optimization plugin.

This crate ships 52 ready-to-use plugins and the machinery to write your own. Each plugin implements the [Plugin] trait and walks the SVG AST using the [Visitor] pattern. The SDK handles registration, parameter parsing, and CSS selector matching so you can focus on the optimization logic.

What's inside

  • 52 built-in plugins in the [plugins] module — ports of every SVGO plugin, same names, same behavior.
  • [registry] — pre-populated registry of all plugins, ready to use.
  • [selector] — CSS selector engine for plugins that target elements by selector.
  • [css_matching] — matches CSS selectors against AST elements.
  • [PluginWithParams] — trait for plugins that accept JSON configuration.

Write a plugin in 4 steps

  1. Define a struct for your plugin state.
  2. Implement [Plugin] — give it a name, description, and apply() method.
  3. Implement [Visitor] — override the hooks that matter (usually visit_element_enter).
  4. Call [walk_document] from apply() to kick off traversal.

Example

use vexy_vsvg_plugin_sdk::{Plugin, Visitor, Document, Element, walk_document};
use anyhow::Result;

struct MyPlugin;

impl Plugin for MyPlugin {
    fn name(&self) -> &'static str { "myPlugin" }
    fn description(&self) -> &'static str { "Does something cool" }
    fn apply(&self, doc: &mut Document) -> Result<()> {
        let mut visitor = MyVisitor;
        walk_document(&mut visitor, doc)?;
        Ok(())
    }
}

struct MyVisitor;
impl Visitor<'_> for MyVisitor {
    fn visit_element_enter(&mut self, element: &mut Element) -> Result<(), vexy_vsvg::VexyError> {
        // Modify element here
        Ok(())
    }
}