Comparing version 2.4.1 to 2.5.0
@@ -190,22 +190,38 @@ // SVG Path transformations library | ||
SvgPath.prototype.toString = function () { | ||
var elements = [], skipCmd, cmd; | ||
var result = '', prevCmd = '', cmdSkipped = false; | ||
this.__evaluateStack(); | ||
for (var i = 0; i < this.segments.length; i++) { | ||
// remove repeating commands names | ||
cmd = this.segments[i][0]; | ||
skipCmd = i > 0 && cmd !== 'm' && cmd !== 'M' && cmd === this.segments[i - 1][0]; | ||
elements = elements.concat(skipCmd ? this.segments[i].slice(1) : this.segments[i]); | ||
for (var i = 0, len = this.segments.length; i < len; i++) { | ||
var segment = this.segments[i]; | ||
var cmd = segment[0]; | ||
// Command not repeating => store | ||
if (cmd !== prevCmd || cmd === 'm' || cmd === 'M') { | ||
// workaround for FontForge SVG importing bug, keep space between "z m". | ||
if (cmd === 'm' && prevCmd === 'z') result += ' '; | ||
result += cmd; | ||
cmdSkipped = false; | ||
} else { | ||
cmdSkipped = true; | ||
} | ||
// Store segment params | ||
for (var pos = 1; pos < segment.length; pos++) { | ||
var val = segment[pos]; | ||
// Space can be skipped | ||
// 1. After command (always) | ||
// 2. For negative value (with '-' at start) | ||
if (pos === 1) { | ||
if (cmdSkipped && val >= 0) result += ' '; | ||
} else if (val >= 0) result += ' '; | ||
result += val; | ||
} | ||
prevCmd = cmd; | ||
} | ||
return elements.join(' ') | ||
// Optimizations: remove spaces around commands & before `-` | ||
// | ||
// We could also remove leading zeros for `0.5`-like values, | ||
// but their count is too small to spend time for. | ||
.replace(/ ?([achlmqrstvz]) ?/gi, '$1') | ||
.replace(/ \-/g, '-') | ||
// workaround for FontForge SVG importing bug | ||
.replace(/zm/g, 'z m'); | ||
return result; | ||
}; | ||
@@ -212,0 +228,0 @@ |
{ | ||
"name": "svgpath", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"description": "Low level toolkit for SVG paths transformations.", | ||
@@ -19,3 +19,5 @@ "keywords": [ | ||
"test": "npm run lint && nyc mocha", | ||
"covreport": "nyc report --reporter html && nyc report --reporter lcov" | ||
"covreport": "nyc report --reporter html && nyc report --reporter lcov", | ||
"benchmark": "benchmark/benchmark.js", | ||
"benchmark-prepare": "mkdir -p benchmark/implementations/2.4.1 && git checkout 2.4.1 && cp index.js benchmark/implementations/2.4.1 && cp -R --parents **/*.js benchmark/implementations/2.4.1 && git checkout master" | ||
}, | ||
@@ -28,3 +30,2 @@ "files": [ | ||
"devDependencies": { | ||
"ansi": "^0.3.1", | ||
"benchmark": "^2.1.1", | ||
@@ -31,0 +32,0 @@ "eslint": "^8.5.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43163
4
1221