1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// this_file: crates/vexy-vsvg-plugin-sdk/src/lib.rs
//! 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
//!
//! ```ignore
//! 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(())
//! }
//! }
//! ```
// Re-export core types needed for plugin development
pub use ;
// Note: enhanced_registry was just a wrapper around the registry, merged into registry
// Plugin implementations
// Helper macros for tests
/// Extended trait for plugins that accept JSON parameters from `svgo.config.json`.
///
/// Many SVGO plugins have tunable behavior — `convertColors` has `shorthex`,
/// `cleanupNumericValues` has `floatPrecision`, etc. This trait standardizes
/// how those parameters flow from JSON config into a typed Rust struct.
///
/// The associated `Config` type is deserialized from the `params` field in
/// the plugin config entry. If omitted, `Config::default()` kicks in.
///
/// ```rust,ignore
/// #[derive(Deserialize, Default)]
/// struct MyConfig { precision: usize }
///
/// impl PluginWithParams for MyPlugin {
/// type Config = MyConfig;
/// fn with_config(config: MyConfig) -> Self { MyPlugin { precision: config.precision } }
/// }
/// ```