svg-path-simplify 0.4.0 → 0.4.1
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/CHANGELOG.md +5 -0
- package/README.md +36 -10
- package/dist/svg-path-simplify.esm.js +7 -3
- package/dist/svg-path-simplify.esm.min.js +2 -2
- package/dist/svg-path-simplify.js +7 -3
- package/dist/svg-path-simplify.min.js +2 -2
- package/index.html +6 -4
- package/package.json +1 -1
- package/src/svgii/svg-styles-to-attributes-const.js +1 -1
- package/src/svgii/svg_cleanup.js +3 -2
- package/src/svgii/svg_el_parse_style_props.js +7 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -15,26 +15,58 @@ While this library reduces SVG markup sizes significantly by removing commands i
|
|
|
15
15
|
Unlike most existing approaches (e.g in graphic applications), it checks where simplifications are suitable and stops simplification at the right »point« (literally).
|
|
16
16
|
|
|
17
17
|

|
|
18
|
-
*Fira Sans (based on truetype/glyph quadratic commands) converted to cubic
|
|
18
|
+
*Fira Sans (based on truetype/glyph quadratic commands) converted to cubic Béziers. Right:Original; Left:optimized*
|
|
19
19
|
|
|
20
|
-
## Features
|
|
21
|
-
|
|
20
|
+
## Features
|
|
21
|
+
### Path simplification
|
|
22
|
+
* reduces the number of SVG commands (both Béziers and lines) by converting/combining adjacent:
|
|
22
23
|
* Béziers (`C`, `Q`)
|
|
23
24
|
* flat Béziers to Linetos
|
|
24
25
|
* colinear lines (`L`)
|
|
26
|
+
* converts cubic Béziers which can be expressed as more compact quadratic
|
|
25
27
|
|
|
26
28
|
* reorders path starting points to replace unnecessary closing linetos by `Z` commands
|
|
27
29
|
* optimizes SVG file size by contextually converting to:
|
|
28
30
|
* shorthand commands (`C` => `S`, `Q` => `T`, `L`=>`H` or `V`)
|
|
29
31
|
* cubics to quadratic Béziers (only 1 control point)
|
|
30
|
-
* cubic arc-like segments to `A` (elliptic arc)
|
|
32
|
+
* cubic arc-like segments to `A` (elliptic arc) and `rx`, `ry` radii optimization for semi-circle segments
|
|
31
33
|
|
|
34
|
+
### Coordinate rounding
|
|
32
35
|
* adaptive coordinate rounding: small or large details can be auto-detected to find a suitable floating point accuracy without guessing the decimal value (3 decimals may not be the silver bullet=)
|
|
36
|
+
|
|
37
|
+
### SVG optimization
|
|
38
|
+
Cleanup for:
|
|
39
|
+
* meta data
|
|
40
|
+
* namespaced attributes or elements
|
|
41
|
+
* convert `xlink:href` to `href` and vice-versa
|
|
42
|
+
* move `defs` to the top
|
|
43
|
+
* remove futile `<clipPath>` defs spanning across the entire viewBox
|
|
44
|
+
* convert styles to presentation attributes
|
|
45
|
+
|
|
46
|
+
### Shape conversions
|
|
47
|
+
* convert shapes such as `<circle>`, `<ellipse>`, `<rect>` etc. to `<path>` – supports relative `%` or physical units like `mm`
|
|
48
|
+
* convert paths to shapes – if applicable
|
|
49
|
+
|
|
50
|
+
### Polygons
|
|
51
|
+
* convert paths to polygons
|
|
52
|
+
* reduce poly vertices
|
|
53
|
+
* convert/smooth polygons to curved path data
|
|
54
|
+
|
|
55
|
+
### Transforms
|
|
56
|
+
* convert transforms to hard-coded path data
|
|
57
|
+
* scale SVGs to desired output size
|
|
58
|
+
|
|
59
|
+
### Path directions
|
|
60
|
+
* reverse path drawing directions
|
|
61
|
+
* auto-fix compound path directions to comply with non-zero fill rules
|
|
62
|
+
|
|
63
|
+
### Additional features
|
|
33
64
|
* split segments at extremes – only useful for manual editing
|
|
34
65
|
* optimize either path data strings or SVG markup code
|
|
35
66
|
* create curves from polylines (curve-fitting)
|
|
36
67
|
|
|
37
68
|
|
|
69
|
+
|
|
38
70
|
## TOC
|
|
39
71
|
* [Usage](#usage)
|
|
40
72
|
+ [Browser](#browser)
|
|
@@ -44,12 +76,6 @@ Unlike most existing approaches (e.g in graphic applications), it checks where s
|
|
|
44
76
|
- [Example 2: Apply options](#example-2-apply-options)
|
|
45
77
|
+ [Web worker](#web-worker)
|
|
46
78
|
* [API](#api)
|
|
47
|
-
+ [Simplification parameters](#simplification-parameters)
|
|
48
|
-
+ [Advanced simplifications](#advanced-simplifications)
|
|
49
|
-
+ [Output options](#output-options)
|
|
50
|
-
+ [SVG scaling](#svg-scaling)
|
|
51
|
-
+ [SVG output optimizations](#svg-output-optimizations)
|
|
52
|
-
+ [SVG input normalization](#svg-input-normalization)
|
|
53
79
|
* [Lite version](#lite-version--only-path-data)
|
|
54
80
|
* [Demos](#demos)
|
|
55
81
|
+ [Web app](#web-app)
|
|
@@ -2004,7 +2004,7 @@ const attLookup = {
|
|
|
2004
2004
|
|
|
2005
2005
|
defaults: {
|
|
2006
2006
|
|
|
2007
|
-
transform: ["none", "matrix(1, 0, 0, 1, 0, 0)"],
|
|
2007
|
+
transform: ["none", "matrix(1, 0, 0, 1, 0, 0)", "matrix(1 0 0 1 0 0)"],
|
|
2008
2008
|
"transform-origin": ["0px, 0px", "0 0"],
|
|
2009
2009
|
rx: ["0", "0px"],
|
|
2010
2010
|
ry: ["0", "0px"],
|
|
@@ -7123,7 +7123,7 @@ function parseStylesProperties(el, {
|
|
|
7123
7123
|
* consolidate transforms to matrix
|
|
7124
7124
|
*/
|
|
7125
7125
|
function addTransFormProps(propsObj = {}, transformArr = []) {
|
|
7126
|
-
if (propsObj.transformArr === undefined
|
|
7126
|
+
if (propsObj.transformArr === undefined || !transformArr.length) return;
|
|
7127
7127
|
|
|
7128
7128
|
// take existing array or custom
|
|
7129
7129
|
transformArr = transformArr.length ? transformArr : propsObj.transformArr;
|
|
@@ -7158,13 +7158,17 @@ function filterSvgElProps(elNodename = '', props = {}, {
|
|
|
7158
7158
|
let noStrokeColor = cleanUpStrokes ? (props['stroke'] === undefined) : false;
|
|
7159
7159
|
|
|
7160
7160
|
for (let prop in props) {
|
|
7161
|
-
let
|
|
7161
|
+
let values = props[prop];
|
|
7162
|
+
let value = Array.isArray(values) ? values[0] : values;
|
|
7162
7163
|
|
|
7163
7164
|
// filter out useless
|
|
7164
7165
|
let isValid = removeInvalid ?
|
|
7165
7166
|
(attLookup.atts[prop] ? attLookup.atts[prop].includes(elNodename) : false) :
|
|
7166
7167
|
false;
|
|
7167
7168
|
|
|
7169
|
+
// remove null transforms
|
|
7170
|
+
if(prop==='transform' && value==='matrix(1 0 0 1 0 0)') isValid = false;
|
|
7171
|
+
|
|
7168
7172
|
// allow data attributes
|
|
7169
7173
|
let isDataAtt = allowDataAtts ? prop.startsWith('data-') : false;
|
|
7170
7174
|
|