svgo 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
svgo-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xmodar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
svgo-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,432 @@
1
+ Metadata-Version: 2.4
2
+ Name: svgo
3
+ Version: 0.1.0
4
+ Summary: Pure-Python SVG path editing, optimization, matrix geometry, measurement, sanitization, viewport editing, validation, tracing, and centerline reconstruction.
5
+ Keywords: svg,path,optimizer,matrix,measurement,sanitize,viewbox,viewport,validation,trace,centerline,cli
6
+ Author: xmodar
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Multimedia :: Graphics
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.11
18
+ Project-URL: Homepage, https://github.com/xmodar/svgo
19
+ Project-URL: Repository, https://github.com/xmodar/svgo
20
+ Project-URL: Issues, https://github.com/xmodar/svgo/issues
21
+ Description-Content-Type: text/markdown
22
+
23
+ # svgo
24
+
25
+ `svgo` is a pure-Python SVG toolchain for path editing, SVG optimization,
26
+ PNG icon tracing, centerline reconstruction, geometry conversion, matrix
27
+ transforms, measurement, sanitization, viewBox/viewport edits, and SVG
28
+ inspection. It ships as an importable Python package and as a single `svgo`
29
+ command-line program.
30
+
31
+ The package has no required runtime dependencies. If `numpy` is installed,
32
+ some centerline distance-transform work can use accelerated array operations;
33
+ otherwise the standard-library fallback is used.
34
+
35
+ ## Features
36
+
37
+ - Edit SVG path data with ordered operations: translate, scale, affine matrix,
38
+ rotate, relative/absolute serialization, subpath reversal, origin changes,
39
+ and path optimization profiles.
40
+ - Optimize whole SVG files with Python implementations of common
41
+ SVGO-style cleanup and minification operations.
42
+ - Trace simple PNG icons into filled SVG paths without shelling out to
43
+ external tracing tools.
44
+ - Convert filled stroke outlines into approximate stroked centerlines.
45
+ - Convert SVG geometry primitives to path data and create common affine
46
+ matrices from Python.
47
+ - Measure path/SVG length, bounds, and point-at-length coordinates.
48
+ - Set, fit, and resize root SVG `viewBox`, `width`, and `height` values.
49
+ - Validate SVG XML, inspect dimensions/element counts/fonts, and run
50
+ structural conversions such as shape-to-path conversion, plain cleanup,
51
+ CSS style inlining, sanitization, and transform flattening.
52
+ - Use the same functionality from Python APIs or from the documented CLI.
53
+
54
+ ## Installation
55
+
56
+ From PyPI, once published:
57
+
58
+ ```bash
59
+ python -m pip install svgo
60
+ ```
61
+
62
+ From this repository:
63
+
64
+ ```bash
65
+ python -m pip install .
66
+ ```
67
+
68
+ For local development with `uv`:
69
+
70
+ ```bash
71
+ uv sync
72
+ uv run svgo --help
73
+ ```
74
+
75
+ ## CLI
76
+
77
+ The CLI entry point is `svgo`. It is organized into short subcommands, each
78
+ with a one-letter alias:
79
+
80
+ ```bash
81
+ svgo path --path "<d>" [--op OP ...] [--svgo] # alias: p
82
+ svgo path --input icon.svg --output icon.out.svg --select all|N|N,N --op OP
83
+ svgo opt --input icon.svg --output icon.min.svg [optimization options] # alias: o
84
+ svgo trace --input icon.png --output traced.svg [trace options] # alias: t
85
+ svgo trace2 --input icon.png --output traced.svg [VTracer options] # alias: t2
86
+ svgo center --input outline.svg --output stroke.svg [centerline options] # alias: c
87
+ svgo info --input icon.svg # alias: i
88
+ svgo validate --input icon.svg [--strict] # alias: v
89
+ svgo measure --input icon.svg # alias: m
90
+ svgo sanitize --input icon.svg --output safe.svg # alias: s
91
+ svgo viewbox --input icon.svg --fit-content --output fitted.svg # alias: b
92
+ svgo convert --input icon.svg --output converted.svg [conversion options] # alias: x
93
+ svgo plugins # alias: l
94
+ ```
95
+
96
+ Every command supports `--help`:
97
+
98
+ ```bash
99
+ svgo --help
100
+ svgo path --help
101
+ svgo opt --help
102
+ svgo trace --help
103
+ svgo trace2 --help
104
+ svgo center --help
105
+ svgo info --help
106
+ svgo validate --help
107
+ svgo measure --help
108
+ svgo sanitize --help
109
+ svgo viewbox --help
110
+ svgo convert --help
111
+ ```
112
+
113
+ ## Path Editing
114
+
115
+ Path operations are applied in order with repeated `--op` flags:
116
+
117
+ ```bash
118
+ svgo path --path "M10 10h5v5z" --op "matrix(-1,0,0,1,30,0)" --minify
119
+ svgo p --input icon.svg --output edited.svg --select 0,2 --op translate:2,-1 --op optimize:safe
120
+ ```
121
+
122
+ Supported operations:
123
+
124
+ - `translate:dx,dy`
125
+ - `scale:kx,ky`
126
+ - `matrix:a,b,c,d,e,f` or `matrix(a,b,c,d,e,f)`
127
+ - `rotate:ox,oy,degrees`
128
+ - `relative`
129
+ - `absolute`
130
+ - `reverse` or `reverse:itemIndex`
131
+ - `origin:itemIndex` or `origin:itemIndex:subpath`
132
+ - `cubics`, `cubic`, `to-cubics`, or `toCubics`
133
+ - `optimize:safe`, `optimize:size`, `optimize:closed`, `optimize:all`
134
+ - `optimize:remove-useless,use-shorthands,use-hv,use-relative-absolute,use-reverse,use-close-path,remove-orphan-dots`
135
+
136
+ The affine matrix uses SVG convention:
137
+
138
+ ```text
139
+ x' = a*x + c*y + e
140
+ y' = b*x + d*y + f
141
+ ```
142
+
143
+ Arcs are converted to cubic Beziers during arbitrary affine transforms so
144
+ reflections, rotations, scales, and skews stay fully Python based.
145
+
146
+ ## SVG Optimization
147
+
148
+ `svgo opt` optimizes SVG documents. `svgo path --svgo` applies the same SVG
149
+ optimizer after path edits:
150
+
151
+ ```bash
152
+ svgo opt --input icon.svg --output icon.min.svg --svgo-multipass --svgo-precision 3
153
+ svgo o --input icon.svg --svgo-disable cleanupIds --svgo-plugin removeDimensions
154
+ svgo opt --input icon.svg --svgo-preset none --svgo-plugin convertShapeToPath --svgo-plugin sortAttrs
155
+ svgo l
156
+ ```
157
+
158
+ Supported options include:
159
+
160
+ - `--svgo-preset default|none`
161
+ - `--svgo-plugin NAME[:JSON]`
162
+ - `--svgo-disable NAME`
163
+ - `--svgo-precision N`
164
+ - `--svgo-multipass`
165
+ - `--svgo-pretty`
166
+ - `--svgo-indent N`
167
+ - `--svgo-eol lf|crlf`
168
+ - `--svgo-final-newline`
169
+ - `--svgo-datauri base64|enc|unenc`
170
+ - `--svgo-config FILE`
171
+
172
+ `--svgo-config` accepts JSON files and Python-readable TOML files. JavaScript
173
+ SVGO configs are intentionally rejected because this implementation does not
174
+ execute Node.js.
175
+
176
+ ## PNG Tracing
177
+
178
+ PNG tracing has two modes. `trace` is the dependency-free pixel tracer: it
179
+ decodes non-interlaced 8-bit PNGs with the standard library, groups visible
180
+ pixels, traces connected-component boundaries, and writes filled SVG paths.
181
+
182
+ ```bash
183
+ svgo trace --input icon.png --output traced.svg --mode palette --curve-mode pixel --max-colors 8 --quantize 24 --min-area 8
184
+ ```
185
+
186
+ Modes:
187
+
188
+ - `palette`: group pixels into dominant quantized colors.
189
+ - `alpha`: trace a single alpha mask using the most common visible color.
190
+ - `exact`: keep exact quantized color buckets.
191
+
192
+ Useful options:
193
+
194
+ - `--curve-mode pixel|exact`: keep exact per-pixel boundaries. This preserves
195
+ the original tracer behavior.
196
+ - `--drop-white`
197
+ - `--alpha-threshold N`
198
+ - `--white-threshold N`
199
+ - `--quantize N`
200
+ - `--max-colors N`
201
+ - `--min-area N`
202
+ - `--scale N`
203
+ - `--decimals N`
204
+ - `--title TEXT`
205
+
206
+ For higher-quality curve fitting, use `trace2`/`t2`. It calls the real
207
+ [VTracer](https://github.com/visioncortex/vtracer) Python package when
208
+ installed, or a `vtracer` CLI on `PATH`. The default values match VTracer's
209
+ web-app defaults and the FreeConvert-style controls:
210
+
211
+ ```bash
212
+ svgo trace2 --input icon.png --output traced.svg
213
+ uv run --with vtracer svgo trace2 --input icon.png --output traced.svg
214
+ svgo t2 --input icon.png --output traced.svg --curve-mode spline --filter-speckle 4 --color-precision 6 --gradient-step 16
215
+ ```
216
+
217
+ VTracer options:
218
+
219
+ - `--color-mode color|binary`
220
+ - `--hierarchical stacked|cutout` or `--clustering stacked|cutout`
221
+ - `--color-precision N`
222
+ - `--gradient-step N`
223
+ - `--filter-speckle N`
224
+ - `--curve-mode pixel|polygon|spline`
225
+ - `--corner-threshold N`
226
+ - `--segment-length N`
227
+ - `--max-iterations N`
228
+ - `--splice-threshold N`
229
+ - `--path-precision N`
230
+
231
+ ## Centerline Reconstruction
232
+
233
+ Centerline reconstruction converts filled stroke outlines into approximate
234
+ stroked paths by flattening path data, rasterizing with even-odd fill,
235
+ skeletonizing with Zhang-Suen thinning, estimating stroke width, and tracing
236
+ the skeleton.
237
+
238
+ ```bash
239
+ svgo center --path "M0 0L100 0L100 20L0 20Z" --emit path
240
+ svgo c --input traced.svg --output centerline.svg --svg-paths all --mode all --simplify 4
241
+ ```
242
+
243
+ Important options:
244
+
245
+ - `--emit path|svg|d`
246
+ - `--mode longest|all`
247
+ - `--scale N`
248
+ - `--max-size N`
249
+ - `--curve-samples N`
250
+ - `--simplify N`
251
+ - `--min-length N`
252
+ - `--stroke-width auto|N`
253
+ - `--linecap VALUE`
254
+ - `--linejoin VALUE`
255
+ - `--polyline`
256
+ - `--svg-paths first|all`
257
+ - `--keep-failed`
258
+
259
+ Centerline output is intentionally approximate. For production icon work,
260
+ render and inspect the result before final minification.
261
+
262
+ ## Inspection And Conversion
263
+
264
+ `svgo info` prints structured JSON metadata:
265
+
266
+ ```bash
267
+ svgo info --input icon.svg
268
+ svgo i --input icon.svg --compact
269
+ ```
270
+
271
+ `svgo validate` checks SVG XML and reports structural issues. Warnings do not
272
+ make the command fail unless `--strict` is used:
273
+
274
+ ```bash
275
+ svgo validate --input icon.svg
276
+ svgo v --input icon.svg --strict --json
277
+ ```
278
+
279
+ `svgo measure` reports path/SVG length and axis-aligned bounds. It accepts raw
280
+ path data, SVG files, or text files containing path data:
281
+
282
+ ```bash
283
+ svgo measure --path "M0 0H10V10H0Z" --decimals 3
284
+ svgo m --input icon.svg --compact
285
+ svgo m --path "M0 0H10V10" --at 15
286
+ ```
287
+
288
+ `svgo sanitize` removes active or unsafe content while keeping normal static
289
+ SVG geometry:
290
+
291
+ ```bash
292
+ svgo sanitize --input icon.svg --output icon.safe.svg
293
+ svgo s --input icon.svg --remove-external-refs --remove-styles
294
+ ```
295
+
296
+ `svgo viewbox` edits root viewport metadata:
297
+
298
+ ```bash
299
+ svgo viewbox --input icon.svg --set "0 0 24 24" --remove-dimensions
300
+ svgo b --input icon.svg --fit-content --padding 1 --precision 2
301
+ svgo b --input icon.svg --width 48 --height 48
302
+ ```
303
+
304
+ `svgo convert` runs pure-Python structural conversions. With no conversion
305
+ flags it converts basic shapes to paths:
306
+
307
+ ```bash
308
+ svgo convert --input shapes.svg --output paths.svg
309
+ svgo x --input drawing.svg --output plain.svg --to-plain
310
+ svgo x --input transformed.svg --output flat.svg --shapes-to-paths --flatten-transforms
311
+ svgo x --input styled.svg --output inline.svg --inline-styles
312
+ svgo x --input source.svg --output converted.svg --all --precision 3
313
+ ```
314
+
315
+ Conversion options:
316
+
317
+ - `--to-plain`: remove common editor metadata and editor-specific attributes.
318
+ - `--shapes-to-paths`: convert `rect`, `circle`, `ellipse`, `line`,
319
+ `polyline`, and `polygon` to `path`.
320
+ - `--flatten-transforms`: bake supported transforms into path coordinates.
321
+ - `--flatten-groups`: collapse empty unstyled groups.
322
+ - `--inline-styles`: inline simple style-element rules into presentation
323
+ attributes.
324
+ - `--sanitize`: remove scripts, event handlers, and unsafe links before
325
+ conversion.
326
+ - `--all`: enable every conversion pass.
327
+ - `--precision N`: control generated numeric precision.
328
+
329
+ ## Python API
330
+
331
+ ```python
332
+ from svgo import (
333
+ PathData,
334
+ centerline_path_data,
335
+ circle_to_path,
336
+ get_svg_info,
337
+ fit_viewbox_svg,
338
+ inline_styles_svg,
339
+ optimize_svg,
340
+ path_metrics,
341
+ path_to_cubics,
342
+ rect_to_path,
343
+ resize_svg,
344
+ sanitize_svg,
345
+ set_viewbox_svg,
346
+ trace_png,
347
+ transform_2d,
348
+ translate_2d,
349
+ validate_svg,
350
+ )
351
+
352
+ path = PathData.parse("M0 0L10 0L10 10Z")
353
+ path.transform((1, 0, 0, 1, 2, -1))
354
+ path.optimize("safe")
355
+ print(path.to_string(decimals=3, minify=True))
356
+
357
+ svg = optimize_svg("<svg><rect width='10' height='10'/></svg>")
358
+ shape = rect_to_path(0, 0, 24, 12, rx=2, decimals=3, minify=True)
359
+ cubic = path_to_cubics("M0 0L10 0Q15 0 15 5", decimals=3, minify=True)
360
+ x, y = transform_2d(translate_2d(10, 5), 1, 2)
361
+ report = validate_svg("<svg viewBox='0 0 10 10'/>")
362
+ metrics = path_metrics("M0 0H10V10H0Z", decimals=3)
363
+ safe_svg = sanitize_svg("<svg onload='x()'><path d='M0 0H1'/></svg>")
364
+ fitted_svg = fit_viewbox_svg("<svg><path d='M2 3H6V7H2Z'/></svg>")
365
+ ```
366
+
367
+ The lower-level modules are:
368
+
369
+ - `svgo.pathdata`
370
+ - `svgo.geometry`
371
+ - `svgo.measure`
372
+ - `svgo.viewport`
373
+ - `svgo.inspect_svg`
374
+ - `svgo.svg_optimize`
375
+ - `svgo.raster_trace`
376
+ - `svgo.centerline`
377
+
378
+ ## Reference Tools
379
+
380
+ These projects are useful reference points for SVG feature coverage, command
381
+ shape, and API expectations:
382
+
383
+ - [SVGO](https://github.com/svg/svgo): Node.js SVG optimizer and plugin
384
+ ecosystem.
385
+ - [Scour](https://github.com/scour-project/scour): Python SVG optimizer and
386
+ cleaner.
387
+ - [svgpathtools](https://github.com/mathandy/svgpathtools): Python path,
388
+ Bezier, geometry, length, and bounds utilities.
389
+ - [svg.path](https://github.com/regebro/svg.path): Python SVG path parser and
390
+ path object model.
391
+ - [svg-matrix-python](https://github.com/Emasoft/svg-matrix-python): Python
392
+ wrapper around SVG matrix conversion and validation workflows.
393
+ - [Yqnn/svg-path-editor](https://github.com/Yqnn/svg-path-editor): SVG path
394
+ editing UI and path operation reference implementation.
395
+ - [svg-path-commander](https://github.com/thednp/svg-path-commander):
396
+ TypeScript path parsing, normalization, geometry, and transformation tools.
397
+ - [Iconify Tools](https://github.com/iconify/tools): TypeScript SVG import,
398
+ validation, cleanup, and export tooling.
399
+ - [resvg/usvg](https://github.com/linebender/resvg): Rust SVG rendering and
400
+ static SVG simplification/reference implementation.
401
+ - [VTracer](https://github.com/visioncortex/vtracer): Rust raster-to-vector
402
+ tracing tool.
403
+
404
+ ## Development
405
+
406
+ This repository uses uv's native `uv_build` backend and has no required runtime
407
+ dependencies.
408
+
409
+ ```bash
410
+ uv run python -m unittest discover -s tests
411
+ uv build
412
+ ```
413
+
414
+ ## Publishing
415
+
416
+ PyPI publishing is handled by GitHub Actions Trusted Publishing through
417
+ `.github/workflows/publish.yml`. The PyPI pending publisher must match this
418
+ repository, the `publish.yml` workflow filename, and the `pypi` environment.
419
+
420
+ To publish a release, update `project.version`, commit the change, and push a
421
+ matching tag:
422
+
423
+ ```bash
424
+ git tag v0.1.0
425
+ git push origin v0.1.0
426
+ ```
427
+
428
+ The workflow verifies that the pushed tag equals `v{project.version}`, runs the
429
+ test suite, builds the wheel and source distribution with `uv`, then publishes
430
+ to PyPI with Trusted Publishing.
431
+
432
+ The package targets Python 3.11 and newer.