https://github.com/bramp/svg_path_transform
Pure dart library for parsing and manipulating SVG paths.
https://github.com/bramp/svg_path_transform
Last synced: about 1 month ago
JSON representation
Pure dart library for parsing and manipulating SVG paths.
- Host: GitHub
- URL: https://github.com/bramp/svg_path_transform
- Owner: bramp
- License: bsd-2-clause
- Created: 2024-02-21T19:13:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-03-25T23:54:58.000Z (3 months ago)
- Last Synced: 2026-04-08T15:42:44.519Z (3 months ago)
- Language: Dart
- Size: 62.5 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Pure dart library for parsing and manipulating SVG paths.
[](https://pub.dev/packages/svg_path_transform)
[](https://pub.dev/publishers/bramp.net/packages)
[](https://github.com/bramp/svg_path_transform/actions/workflows/test.yml)
## Features
* Parse a SVG path
* Translate the path
* Rotate the path around a point
* Mirror the path across an axis
* Scale the path
* Reverse (e.g clockwise to counter-clockwise)
Does not depend on [Flutter](https://api.flutter.dev/index.html) or [dart:ui](https://api.flutter.dev/flutter/dart-ui/dart-ui-library.html), but these Path objects can easily be converted to dart:ui [Path objects](https://api.flutter.dev/flutter/dart-ui/Path-class.html).
## Usage
```shell
dart pub add svg_path_transform
```
```dart
import 'package:svg_path_transform/svg_path_transform.dart';
void main() {
// Read a path from a SVG path string.
final path = Path.fromString('M 10 10 H 90 V 90 H 10 L 10 10 Z');
// Translate the path 10 units in the x and y direction.
final p0 = path.translate(10, 10);
// Rotate the path 45 degrees around the point (50, 50).
final p1 = path.rotate(pi / 4, 50, 50);
// Reverse the path (drawing from the end to the start)
final p2 = path.reverse();
// Mirror the path across the X axis.
final p3 = path.mirror(Axis.x);
// Scale the path by 2 in the x direction, and 0.5 in the y direction.
final p4 = path.scale(2, 0.5);
// Print out the paths as SVG path strings.
print(p0.toString());
print(p1.toString());
print(p2.toString());
print(p3.toString());
print(p4.toString());
}
```
## Development
To run the tests:
```bash
make all
```
To publish:
```bash
# Bump the version in pubspec.yaml
# Update the CHANGELOG.md
git commit -m "chore: bump version to 1.2.0"
git tag svg_path_transform-v1.2.0
git push origin main --tags
```
## Limitations
* All SVG commands are normalised to the absolute versions of moveTo, lineTo or
curveTo. The resulting image is identical, but the path string may be longer.