svgo 1.0.0
svgo: ^1.0.0 copied to clipboard
A Dart library for optimizing SVG files. Port of SVGO (Node.js SVG Optimizer).
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.0.0 - 2025-12-06 #
Added #
- Initial release of SVGO Dart library
- Complete SVG parser with XAST (Abstract Syntax Tree) generation
- Visitor pattern for AST traversal and manipulation
- Comprehensive plugin system with preset support
- 54 builtin optimization plugins (full parity with node SVGO):
Cleanup Plugins
cleanupAttrs- Cleanup attributes from newlines, trailing spaces, etc.cleanupEnableBackground- Remove or fix deprecated enable-background attributecleanupIds- Remove or minify unused IDscleanupListOfValues- Round numeric values in list-like attributescleanupNumericValues- Round numeric values and remove default units
Remove Plugins
removeAttrs- Remove specified attributesremoveAttributesBySelector- Remove attributes by CSS selectorremoveComments- Remove commentsremoveDeprecatedAttrs- Remove deprecated SVG attributesremoveDesc- Remove<desc>elementsremoveDimensions- Remove width/height, add viewBox if missingremoveDoctype- Remove DOCTYPE declarationremoveEditorsNSData- Remove editor-specific namespaces and elementsremoveElementsByAttr- Remove elements by attribute valuesremoveEmptyAttrs- Remove empty attributesremoveEmptyContainers- Remove empty container elementsremoveEmptyText- Remove empty text elementsremoveHiddenElems- Remove hidden elementsremoveMetadata- Remove<metadata>elementsremoveNonInheritableGroupAttrs- Remove non-inheritable group attributesremoveOffCanvasPaths- Remove paths outside viewBoxremoveRasterImages- Remove raster image elementsremoveScripts- Remove script elements and event handlersremoveStyleElement- Remove<style>elementsremoveTitle- Remove<title>elementsremoveUnknownsAndDefaults- Remove unknown elements and default valuesremoveUnusedNS- Remove unused namespace declarationsremoveUselessDefs- Remove elements in<defs>without idremoveUselessStrokeAndFill- Remove useless stroke and fill attributesremoveViewBox- Remove viewBox when width/height presentremoveXlink- Remove deprecated xlink namespaceremoveXMLNS- Remove xmlns attribute (for embedded SVGs)removeXMLProcInst- Remove XML processing instructions
Convert Plugins
convertColors- Convert color values to shorter formatsconvertEllipseToCircle- Convert non-eccentric ellipses to circlesconvertOneStopGradients- Convert single-stop gradients to solid colorsconvertPathData- Optimize path dataconvertShapeToPath- Convert basic shapes to pathconvertStyleToAttrs- Convert inline styles to presentation attributesconvertTransform- Optimize transform attributes
Merge & Move Plugins
collapseGroups- Collapse useless groupsmergePaths- Merge adjacent path elementsmergeStyles- Merge multiple style elementsmoveElemsAttrsToGroup- Move common element attributes to parent groupmoveGroupAttrsToElems- Move group transform attributes to children
Sort Plugins
sortAttrs- Sort element attributes for better compressionsortDefsChildren- Sort children of<defs>for better gzip compression
Style Plugins
inlineStyles- Inline CSS styles from<style>elements to elementsminifyStyles- Minify CSS in style elements and attributes
Other Plugins
addAttributesToSVGElement- Add attributes to SVG elementaddClassesToSVGElement- Add classes to SVG elementapplyTransforms- Apply transforms to path dataprefixIds- Add prefix to IDsreusePaths- Replace duplicate paths with<use>references
Features #
- Default preset (
preset-default) with safe optimizations - Multipass optimization support
- SVG path data parsing and manipulation utilities
- CSS style parsing and computation using csslib
- CSS selector matching (supports tag, class, ID, attribute selectors)
- Configurable float precision
- Data URI encoding support (base64, URL-encoded, unencoded)
- Complete type-safe Dart API
Technical Features #
- Full XAST (XML Abstract Syntax Tree) implementation
- CSS selector matching for style computation
- Style specificity calculation
- CSS inheritance handling
- Path data parsing and stringification
- Path conversion between absolute and relative coordinates
- Bounding box computation for paths
- 184 unit tests with 100% pass rate
[Unreleased] #
Planned #
- Performance benchmarks and optimizations
- Streaming API for large files
- Additional path optimization algorithms