diff options
author | codecalm <codecalm@gmail.com> | 2020-08-19 13:45:47 +0200 |
---|---|---|
committer | codecalm <codecalm@gmail.com> | 2020-08-19 13:45:47 +0200 |
commit | ef4899c2d98e9639a746660d37983afdc79fb3cd (patch) | |
tree | 275ebfd85c97588f402ff6929bb07155357da8ee /gulpfile.js | |
parent | `behance` logo (diff) | |
download | tabler-icons-ef4899c2d98e9639a746660d37983afdc79fb3cd.tar.xz |
icons optimize, `behance` fix
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gulpfile.js b/gulpfile.js index 43c55a77..79535baa 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -399,6 +399,10 @@ gulp.task('icons-stroke', gulp.series('build-jekyll', function (cb) { })); gulp.task('optimize', function (cb) { + const addFloats = function(n1, n2) { + return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 + }; + glob("src/_icons/*.svg", {}, function (er, files) { files.forEach(function (file, i) { @@ -412,7 +416,20 @@ gulp.task('optimize', function (cb) { .replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1") .replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"') .replace(/a\s?([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/g, 'a$1 $2 $3 $4 $5 $6 $7') - .replace(/\n\n+/g, "\n"); + .replace(/\n\n+/g, "\n") + + .replace(/<path d="M([0-9.]*) ([0-9.]*)l([-0-9.]*) ([-0-9.]*)"/g, function(f, r1, r2, r3, r4){ + return `<line x1="${r1}" y1="${r2}" x2="${addFloats(r1, r3)}" y2="${addFloats(r2, r4)}"`; + }) + .replace(/<path d="M([0-9.]*) ([0-9.]*)v([0-9.]*)"/g, function(f, r1, r2, r3){ + return `<line x1="${r1}" y1="${r2}" x2="${r1}" y2="${addFloats(r2, r3)}"`; + }) + .replace(/<path d="M([0-9.]*) ([0-9.]*)h([0-9.]*)"/g, function(f, r1, r2, r3){ + return `<line x1="${r1}" y1="${r2}" x2="${addFloats(r1, r3)}" y2="${r2}"`; + }); + + // + // if(svgFile.toString() !== svgFileContent) { fs.writeFileSync(file, svgFileContent); |