svg-path-simplify 0.3.5 → 0.4.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -76
  3. package/dist/svg-path-simplify.esm.js +5505 -4030
  4. package/dist/svg-path-simplify.esm.min.js +2 -8
  5. package/dist/svg-path-simplify.js +5506 -4029
  6. package/dist/svg-path-simplify.min.js +2 -8
  7. package/dist/svg-path-simplify.pathdata.esm.js +1154 -1042
  8. package/dist/svg-path-simplify.pathdata.esm.min.js +2 -8
  9. package/docs/api.md +127 -0
  10. package/index.html +279 -257
  11. package/package.json +1 -1
  12. package/src/constants.js +10 -1
  13. package/src/index.js +7 -1
  14. package/src/pathData_simplify_cubic.js +1 -18
  15. package/src/pathSimplify-main.js +87 -30
  16. package/src/pathSimplify-only-pathdata.js +2 -2
  17. package/src/svg-getAttributes.js +13 -0
  18. package/src/svg_flatten_transforms.js +1 -1
  19. package/src/svg_getViewbox.js +23 -11
  20. package/src/svg_rootSVG.js +9 -0
  21. package/src/svgii/convert_colors.js +145 -0
  22. package/src/svgii/convert_units.js +159 -0
  23. package/src/svgii/geometry.js +24 -4
  24. package/src/svgii/geometry_bbox.js +2 -1
  25. package/src/svgii/geometry_bbox_element.js +46 -0
  26. package/src/svgii/pathData_analyze.js +34 -14
  27. package/src/svgii/pathData_convert.js +204 -34
  28. package/src/svgii/pathData_parse.js +2 -99
  29. package/src/svgii/pathData_parse_els.js +217 -128
  30. package/src/svgii/pathData_simplify_refineCorners.js +72 -43
  31. package/src/svgii/pathData_stringify.js +6 -5
  32. package/src/svgii/pathData_toPolygon.js +3 -1
  33. package/src/svgii/pathData_transform.js +307 -0
  34. package/src/svgii/poly_normalize.js +21 -1
  35. package/src/svgii/rounding.js +36 -5
  36. package/src/svgii/svg-styles-getTransforms.js +119 -8
  37. package/src/svgii/svg-styles-to-attributes-const.js +26 -6
  38. package/src/svgii/svg_cleanup.js +540 -74
  39. package/src/svgii/svg_el_parse_style_props.js +561 -0
  40. package/src/svgii/transform_qr_decompose.js +74 -0
  41. package/src/svgii/pathData_scale.js +0 -42
  42. package/src/svgii/stringify.js +0 -103
  43. package/src/svgii/svg-styles-to-attributes.js +0 -217
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.4.0] - 2026-03-16
4
+ ### Added
5
+ - convert transforms to hard coded geometry
6
+ - new style-to-attribute conversion
7
+ - options to specify which shapes should be converted to paths
8
+ - path to shape conversion
9
+ - ungroup paths
10
+ - webapp refined option grouping
11
+ - arc radii minification
12
+ - minify RGB color values
13
+ - move defs to top of markup
14
+ - remove futile clip-paths
15
+ - remove SVG comments
16
+
17
+ ### Changed
18
+ - improved extreme detection for simplification
19
+ - stricter shorthand thresholds
package/README.md CHANGED
@@ -227,82 +227,9 @@ The first parameter is the SVG input:
227
227
  * a polygon string – as used in SVG `<polygon>` element's `points` attribute
228
228
  * an entire `<svg>` markup
229
229
 
230
- While svg-path-simplify aims at a convenient config-free usage you can tweak the simplification and output via these options passed as an object.
231
-
232
- ### Simplification parameters
233
- These params control shich simplifications are applied. The default settings aim at a safe or balanced performance-to-minification ratio. However if your main goal is to get the most compact result you can enable additional options which also require more processing time.
234
- | parameter | effect | type | default |
235
- | -- | -- | -- | -- |
236
- | simplifyBezier | main Bézier simplification. When disabled you get the common optimization similar to SVGO (rounding, to all relative and shorthand conversions) | Boolean | true |
237
- | tolerance | increase or decrease tolerance: higher values allow more distortions, lower ones more shape fidelity | Number | 1 |
238
- | optimizeOrder | reorders commands to get more adjacent simplification candidates. Improves optimization efficiency | Boolean | true |
239
- | removeColinear | removes unnecessary zero-length or colinear lineto commands | Boolean | true |
240
- | flatBezierToLinetos | replaces flat Béziers with linetos which also can be stripped via previous colinear removal | Boolean | true |
241
- | revertToQuadratics | replaces cubic Béziers with quadratic (more compact) ones when applicable | Boolean | true |
242
- | keepExtremes | skips simplification accross x/y extrema – improves shape fidelity | Boolean | true |
243
- | keepCorners | skips simplification corners – improves shape fidelity | Boolean | true |
244
- | keepInflections | retains commands introducing direction changes – adds complexity but may help for editing in a graphic application | Boolean | false |
245
-
246
- ### Advanced simplifications
247
- | parameter | effect | type | default |
248
- | -- | -- | -- | -- |
249
- | refineExtremes | tries to combine commands close to an adjacent x/y extreme segment | Boolean | false |
250
- | addExtremes | adds commands at x/y extrema – adds complexity but may help for editing in a graphic application – when using this option enable `refineExtremes` as well to avoid tiny adjacent segments | Boolean | false |
251
- | simplifyCorners | replaces Bézier segments enclosed by linetos with single quadratic commands – handy to reduce overly complex tiny corner roundings. See example in [webapp](https://herrstrietzel.github.io/svg-path-simplify?samples=fontawesome_gears&refineExtremes=true&simplifyCorners=true) | Boolean | false |
252
- | cubicToArc | replaces Bézier segments by elliptic arc `A` commands where applicable – can reduce complexity for semi- or full circles | Boolean | false |
253
- | simplifyRound | replaces small round segments encloses by linetos – helps to simplify shapes like gears/cogs | Boolean | false |
254
-
255
-
256
- ### Path direction
257
- | parameter | effect | type | default |
258
- | -- | -- | -- | -- |
259
- | fixDirections | alternates sub path directions to fulfill non-zero. Makes fill-rule attribute obsolete and render correct in other environments e.g when converting to fonts | Boolean | false |
260
- | reversePath | simply reverses drawing direction - sometimes needed for line animations | Boolean | false |
261
-
262
-
263
-
264
- ### Polygon options
265
- | parameter | effect | type | default |
266
- | -- | -- | -- | -- |
267
- | smoothPoly | Curve-fitting: Converts polylines to cubic beziers | Boolean | false |
268
-
269
-
270
-
271
- ### Output options
272
-
273
- | parameter | effect | type | default |
274
- | -- | -- | -- | -- |
275
- | getObject | whether to return the SVG/pathdata markup directly or a detailed object (containing more info) | Boolean | true |
276
-
277
-
278
- ### SVG output optimizations
279
- | parameter | effect | type | default |
280
- | -- | -- | -- | -- |
281
- | autoAccuracy | calculates a suitable floating point precision for coordinate rounding. Usually rather conservative – decreasing by one decimal should work without significant distortions | Boolean | true |
282
- | decimals | manual floating point rounding precision – overriden when `autoAccuracy` is enabled | Number | 3 |
283
- | minifyD | path data microoptimization: removes recurring command type tokens, whitespace and leading zeroes: 0: maximum optimization; 1: "verbose" dont't omit command type tokes; 2: "beautify" separate each command with new lines (e.g for educational purposes) | Number | 0 |
284
- | toRelative | converts all commands to relative – reduces file size | Boolean | true |
285
- | toShorthands | converts all commands to shorthand when applicable – reduces file size | Boolean | true |
286
-
287
-
288
- ### SVG scaling
289
- Scaling only indirectly affects file size analogous to rounding. Use it only for very large or small SVGs. Finding the »sweet spot« where all coordinates can be expressed in integers can reduce file size as no decimal separators are required.
290
-
291
- | parameter | effect | type | default |
292
- | -- | -- | -- | -- |
293
- | scale | scales all pathdata, `viewBox`, `width` and `height` attributes | Boolean | true |
294
- | scaleTo | scales to a specified max width | Boolean | false |
295
-
296
-
297
- ### SVG input normalization
298
- | parameter | effect | type | default |
299
- | -- | -- | -- | -- |
300
- | quadraticToCubic | converts all quadratic Béziers to cubics – recommended for efficiency | Boolean | true |
301
- | arcToCubic | converts elliptic arc `A` commands to cubic approximations – not recommended | Boolean | false |
302
- | removeHidden | removes hidden elements for SVG inputs | Boolean | true |
303
- | mergePaths | concatenates paths into single one – does not respect individual styles! | Boolean | false |
304
- | shapesToPaths | converts shapes to paths - usually not recommended as shapes are most often more compact. But useful for path concatenation | Boolean | false |
305
- | stylesToAttributes | consolidates styles and set them to attributes. Also removes invalid attributes (e.g `font-family` for paths) | Boolean | false |
230
+ While svg-path-simplify aims at a convenient usage with effective and safe defaults you can tweak the simplification and output via these options passed as an object.
231
+
232
+ See [documentation for complete list of parameters](docs/api.md)
306
233
 
307
234
 
308
235
  ## Lite version – only path data