svg-path-simplify 0.2.4 → 0.2.7
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.
- package/README.md +30 -0
- package/dist/svg-path-simplify.esm.js +465 -390
- package/dist/svg-path-simplify.esm.min.js +6 -6
- package/dist/svg-path-simplify.js +465 -390
- package/dist/svg-path-simplify.min.js +6 -6
- package/dist/svg-path-simplify.min.js.gz +0 -0
- package/dist/svg-path-simplify.poly.cjs +10 -1
- package/dist/svg-path-simplify.worker.js +62 -0
- package/dist/svg-path-simplify.worker.polyfills.js +32 -0
- package/index.html +90 -17
- package/package.json +3 -2
- package/src/index-poly.js +9 -1
- package/src/index-worker.js +17 -0
- package/src/index.js +4 -1
- package/src/pathData_simplify_revertToquadratics.js +2 -2
- package/src/pathSimplify-main.js +53 -71
- package/src/svgii/geometry.js +48 -4
- package/src/svgii/pathData_analyze.js +8 -6
- package/src/svgii/pathData_convert.js +1 -1
- package/src/svgii/pathData_fix_directions.js +83 -0
- package/src/svgii/pathData_line_to_cubic.js +21 -0
- package/src/svgii/pathData_parse_els.js +7 -2
- package/src/svgii/pathData_remove_zerolength.js +0 -1
- package/src/svgii/pathData_reverse.js +0 -1
- package/src/svgii/pathData_toPolygon.js +61 -12
- package/src/svgii/rounding.js +2 -0
- package/src/svgii/svg-styles-to-attributes-const.js +2 -0
- package/src/svgii/svg_cleanup.js +92 -15
- package/tests/testSVG.js +1 -0
- package/tests/testSVG2.js +55 -0
package/README.md
CHANGED
|
@@ -238,6 +238,21 @@ These params control shich simplifications are applied. The default settings aim
|
|
|
238
238
|
| simplifyRound | replaces small round segments encloses by linetos – helps to simplify shapes like gears/cogs | Boolean | false |
|
|
239
239
|
|
|
240
240
|
|
|
241
|
+
### Path direction
|
|
242
|
+
| parameter | effect | type | default |
|
|
243
|
+
| -- | -- | -- | -- |
|
|
244
|
+
| 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 |
|
|
245
|
+
| reversePath | simply reverses drawing direction - sometimes needed for line animations | Boolean | false |
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
### Polygon options
|
|
250
|
+
| parameter | effect | type | default |
|
|
251
|
+
| -- | -- | -- | -- |
|
|
252
|
+
| smoothPoly | Curve-fitting: Converts polylines to cubic beziers | Boolean | false |
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
241
256
|
### Output options
|
|
242
257
|
|
|
243
258
|
| parameter | effect | type | default |
|
|
@@ -254,6 +269,7 @@ These params control shich simplifications are applied. The default settings aim
|
|
|
254
269
|
| toRelative | converts all commands to relative – reduces file size | Boolean | true |
|
|
255
270
|
| toShorthands | converts all commands to shorthand when applicable – reduces file size | Boolean | true |
|
|
256
271
|
|
|
272
|
+
|
|
257
273
|
### SVG scaling
|
|
258
274
|
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.
|
|
259
275
|
|
|
@@ -270,6 +286,9 @@ Scaling only indirectly affects file size analogous to rounding. Use it only for
|
|
|
270
286
|
| arcToCubic | converts elliptic arc `A` commands to cubic approximations – not recommended | Boolean | false |
|
|
271
287
|
| removeHidden | removes hidden elements for SVG inputs | Boolean | true |
|
|
272
288
|
| mergePaths | concatenates paths into single one – does not respect individual styles! | Boolean | false |
|
|
289
|
+
| shapesToPaths | converts shapes to paths - usually not recommended as shapes are most often more compact. But useful for path concatenation | Boolean | false |
|
|
290
|
+
| stylesToAttributes | consolidates styles and set them to attributes. Also removes invalid attributes (e.g `font-family` for paths) | Boolean | false |
|
|
291
|
+
|
|
273
292
|
|
|
274
293
|
|
|
275
294
|
|
|
@@ -279,6 +298,15 @@ You can easily test this library via the [**webapp**](https://herrstrietzel.gith
|
|
|
279
298
|
|
|
280
299
|

|
|
281
300
|
|
|
301
|
+
#### Features
|
|
302
|
+
* test all provided simplification option - export settings as JS object
|
|
303
|
+
* preview different settings
|
|
304
|
+
* accepts SVG files
|
|
305
|
+
* path data strings
|
|
306
|
+
* supports multi file batch processing
|
|
307
|
+
* open results in codepen or svg-path-editor
|
|
308
|
+
* download self contained SVG
|
|
309
|
+
|
|
282
310
|
|
|
283
311
|
### Demo files
|
|
284
312
|
* [simple setup IIFE](./demo/simple-iife.html)
|
|
@@ -338,4 +366,6 @@ You can also post in the [discussions](https://github.com/herrstrietzel/svg-path
|
|
|
338
366
|
* [Vitaly Puzrin](https://github.com/puzrin) for [svgpath library](https://github.com/fontello/svgpath) providing for instance a great and customizable [arc-to-cubic approximation](https://github.com/fontello/svgpath/blob/master/lib/a2c.js) – the base for the more accurate arc-to-cubic approximations
|
|
339
367
|
* [Jarek Foksa](https://github.com/jarek-foksa) for developping the great [getPathData() polyfill](https://github.com/jarek-foksa/path-data-polyfill) – probably the most productive contributor to the ["new" W3C SVGPathData interface draft](https://svgwg.org/specs/paths/#InterfaceSVGPathData)
|
|
340
368
|
* obviously, [Dmitry Baranovskiy](https://github.com/dmitrybaranovskiy) – a lot of these helper functions originate either from Raphaël or snap.svg – or are at least heavily inspired by some helpers from these libraries
|
|
369
|
+
* [Andrea Giammarchi a.k.a WebReflection](https://github.com/WebReflection) for [linkedom](https://github.com/WebReflection/linkedom) which helped to make this lib run also in node or a web worker
|
|
370
|
+
* [Photopea](https://github.com/photopea) for the fast [UZIP](https://github.com/photopea/UZIP.js) which is deployed in the webapp for batch file downloads.
|
|
341
371
|
|