1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Remove spaces after ‘arcto’ path command flags

This commit is contained in:
GreLI
2019-07-13 16:18:08 +03:00
parent 95f7603983
commit 258fecfa6b
16 changed files with 66 additions and 66 deletions

View File

@ -10,33 +10,23 @@ var FS = require('fs');
* @return {String} output string
*/
exports.encodeSVGDatauri = function(str, type) {
var prefix = 'data:image/svg+xml';
// base64
if (!type || type === 'base64') {
// base64
prefix += ';base64,';
if (Buffer.from) {
str = prefix + Buffer.from(str).toString('base64');
} else {
str = prefix + new Buffer(str).toString('base64');
}
// URI encoded
} else if (type === 'enc') {
// URI encoded
str = prefix + ',' + encodeURIComponent(str);
// unencoded
} else if (type === 'unenc') {
// unencoded
str = prefix + ',' + str;
}
return str;
};
/**
@ -54,23 +44,16 @@ exports.decodeSVGDatauri = function(str) {
var data = match[3];
// base64
if (match[2]) {
// base64
str = new Buffer(data, 'base64').toString('utf8');
// URI encoded
} else if (data.charAt(0) === '%') {
// URI encoded
str = decodeURIComponent(data);
// unencoded
} else if (data.charAt(0) === '<') {
// unencoded
str = data;
}
return str;
};
@ -80,20 +63,33 @@ exports.intersectArrays = function(a, b) {
});
};
exports.cleanupOutData = function(data, params) {
/**
* Convert a row of numbers to an optimized string view.
*
* @example
* [0, -1, .5, .5] → 0-1 .5.5
*
* @param {number[]} data
* @param {Object} params
* @param {string?} command path data instruction
* @return {[type]}
*/
exports.cleanupOutData = function(data, params, command) {
var str = '',
delimiter,
prev;
data.forEach(function(item, i) {
// space delimiter by default
delimiter = ' ';
// no extra space in front of first number
if (i === 0) {
delimiter = '';
if (i == 0) delimiter = '';
// no extra space after 'arcto' command flags
if (params.noSpaceAfterFlags && (command == 'A' || command == 'a')) {
var pos = i % 7;
if (pos == 4 || pos == 5) delimiter = '';
}
// remove floating-point numbers leading zeros
@ -107,22 +103,18 @@ exports.cleanupOutData = function(data, params) {
// in front of a floating number if a previous number is floating too
if (
params.negativeExtraSpace &&
delimiter != '' &&
(item < 0 ||
(String(item).charCodeAt(0) == 46 && prev % 1 !== 0)
)
) {
delimiter = '';
}
// save prev item value
prev = item;
str += delimiter + item;
});
return str;
};
/**
@ -146,9 +138,7 @@ var removeLeadingZero = exports.removeLeadingZero = function(num) {
} else if (-1 < num && num < 0 && strNum.charCodeAt(1) == 48) {
strNum = strNum.charAt(0) + strNum.slice(2);
}
return strNum;
};

View File

@ -553,7 +553,11 @@ exports.js2path = function(path, data, params) {
}
path.attr('d').value = data.reduce(function(pathString, item) {
return pathString += item.instruction + (item.data ? cleanupOutData(item.data, params) : '');
var strData = '';
if (item.data) {
strData = cleanupOutData(item.data, params, item.instruction);
}
return pathString += item.instruction + strData;
}, '');
};

View File

@ -23,6 +23,7 @@ exports.params = {
utilizeAbsolute: true,
leadingZero: true,
negativeExtraSpace: true,
noSpaceAfterFlags: true,
forceAbsolutePath: false
};
@ -960,6 +961,10 @@ function findArcAngle(curve, relCircle) {
function data2Path(params, pathData) {
return pathData.reduce(function(pathString, item) {
return pathString + item.instruction + (item.data ? cleanupOutData(roundData(item.data.slice()), params) : '');
var strData = '';
if (item.data) {
strData = cleanupOutData(roundData(item.data.slice()), params);
}
return pathString + item.instruction + strData;
}, '');
}

View File

@ -9,7 +9,8 @@ exports.description = 'merges multiple paths in one if possible';
exports.params = {
collapseRepeated: true,
leadingZero: true,
negativeExtraSpace: true
negativeExtraSpace: true,
noSpaceAfterFlags: true
};
var path2js = require('./_path.js').path2js,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -15,5 +15,5 @@
<path d="M10 50c10-20 30 0 50 20S20 30 30 60"/>
<path d="M10 50q20 10 20 20"/>
<path d="M10 50q20 10 20 20t10 0"/>
<path d="M10 50a20 60 45 0 1 30 20"/>
<path d="M10 50a20 60 45 0130 20"/>
</svg>

Before

Width:  |  Height:  |  Size: 603 B

After

Width:  |  Height:  |  Size: 601 B

View File

@ -32,8 +32,8 @@
<path d="M10 50q20 10 20 20 10 0 20 20"/>
<path d="M10 50q20 10 20 20t10 0 10 20"/>
<path d="M10 50q20 10 20 20t10 0 10 20"/>
<path d="M10 50a20 60 45 0 1 30 20 30 50-30 1 1 10 0"/>
<path d="M10 50a20 60 45 0 1 30 20 30 50-30 1 1 10 0"/>
<path d="M10 50a20 60 45 0130 20 30 50-30 1110 0"/>
<path d="M10 50a20 60 45 0130 20 30 50-30 1110 0"/>
<path d="M0 0v5 5" marker-mid="url(#)"/>
<path d="M0 0h0" stroke="black" stroke-linecap="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -15,5 +15,5 @@
<path d="M10 50c20 30 40 50 60 70s20 40 40 50L10 20"/>
<path d="M10 50q20 60 30 70-20-60-10-50"/>
<path d="M10 50q20 60 30 70t40 70L10 20"/>
<path d="M10 50a20 60 45 0 1 40 70 20 60 45 0 1-10-50"/>
<path d="M10 50a20 60 45 0140 70 20 60 45 01-10-50"/>
</svg>

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 749 B

View File

@ -40,7 +40,7 @@
<path transform="" d="M0 0v100l70-50zm70 50l70-50v100z"/>
<path fill="red" d="M118.742 187.108l79.162 124.74-96.593-25.883 8.716-49.428c17.43-98.857 89.875-79.446 81.16-30.017s63.728 68.84 72.444 19.411q13.073-74.143 87.877 75.31t193.185 51.764z"/>
<path fill="red" stroke="red" transform="rotate(15) scale(.5) skewX(5) translate(200,100)" d="M100 200l200 200H100V300c0-200 150-200 150-100s150 100 150 0q0-150 200 100t400 0z"/>
<path fill="red" stroke="red" transform="rotate(15) scale(.5) skewX(5) translate(200,100)" d="M100 200l200 200H100V300c0-200 150-200 150-100s150 100 150 0q0-150 200 100t400 0a150 150 0 1 0 150-150z"/>
<path fill="red" stroke="red" transform="rotate(15) scale(.5) skewX(5) translate(200,100)" d="M100 200l200 200H100V300c0-200 150-200 150-100s150 100 150 0q0-150 200 100t400 0a150 150 0 10150-150z"/>
<path fill="red" stroke="red" d="M106.066 183.712l70.71 122.474-96.592-25.882 12.941-48.296c25.882-96.593 98.326-77.181 85.385-28.885s59.504 67.708 72.445 19.412q19.411-72.445 83.652 74.178t193.185 51.764z" stroke-width=".5"/>
<path fill="red" stroke="red" d="M318.198 551.135L530.33 918.56l-289.778-77.646 38.823-144.889c77.646-289.778 294.98-231.543 256.156-86.655s178.51 203.124 217.334 58.235q58.234-217.334 250.955 222.534t579.555 155.292z" stroke-width="1.5"/>
<path fill="red" stroke="red" d="M70.004 121.25l46.669 80.833L52.922 185l8.54-31.876c17.083-63.75 64.896-50.94 56.355-19.064s39.272 44.687 47.813 12.812q12.812-47.814 55.21 48.957t127.503 34.165z" stroke-width=".33"/>
@ -58,14 +58,14 @@
</g>
<path fill="url(#gradient)" transform="rotate(15) scale(0.33) translate(200,100)" d="M100 200l200 200H100V300c0-200 150-200 150-100s150 100 150 0q0-150 200 100t400 0z"/>
<path clip-path="url(#a)" transform="rotate(15) scale(0.33) translate(200,100)" d="M100 200l200 200H100V300c0-200 150-200 150-100s150 100 150 0q0-150 200 100t400 0z"/>
<path d="M10 0a10 10 0 1 0 20 0"/>
<path d="M3.864 1.035a8 12 15 1 0 15.455 4.141"/>
<path d="M3.536 3.536a10 10 0 1 0 14.142 14.142"/>
<path d="M5 0a16.18 6.18 31.717 1 0 20 0"/>
<path d="M-12.122 332.074a80 240 15 1 0 154.548 41.41 80 240 15 1 0-154.548-41.41"/>
<path d="M721.72 450.759a240 80 15 1 0 41.412-154.548 240 80 15 1 0-41.411 154.548"/>
<path d="M10 0a10 10 0 1020 0"/>
<path d="M3.864 1.035a8 12 15 1015.455 4.141"/>
<path d="M3.536 3.536a10 10 0 1014.142 14.142"/>
<path d="M5 0a16.18 6.18 31.717 1020 0"/>
<path d="M-12.122 332.074a80 240 15 10154.548 41.41 80 240 15 10-154.548-41.41"/>
<path d="M721.72 450.759a240 80 15 1041.412-154.548 240 80 15 10-41.411 154.548"/>
<path d="M8.6 6.4L5.4 9.5l3.2 3.1-.7.8L4 9.5l3.9-3.9zM5 10V9h10v1z"/>
<path d="M561.214 392.766a48.107 95.08 10.132 1 1-94.083-20.365 48.107 95.079 10.132 1 1 94.082 20.365z"/>
<path d="M-1.26-1.4a6.53 1.8-15.2 1 1 12.55-3.44"/>
<path d="M561.214 392.766a48.107 95.08 10.132 11-94.083-20.365 48.107 95.079 10.132 1194.082 20.365z"/>
<path d="M-1.26-1.4a6.53 1.8-15.2 1112.55-3.44"/>
<path d="M0 0l.21 3.99.21 3.99"/>
</svg>

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -12,12 +12,12 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg">
<path d="M0 0a5 5 0 0 1 5 5"/>
<path d="M0 0a5 5 0 0 1 5 5l5-5"/>
<path d="M15 10a5 5 0 1 1 5-5l-5 5"/>
<path d="M41.008.102a5.006 5.006 0 0 1 3.849 3.705"/>
<path d="M7.234 19.474a5 5 0 0 1-4.933-8.683"/>
<path d="M60 0a5 5 0 1 0 .001 10.001A5 5 0 0 0 60 0z"/>
<path d="M15 23.54a8.493 8.493 0 0 1-5.25-1.807"/>
<path d="M-9.5 82.311a4.81 4.81 0 1 1 .002-9.622A4.81 4.81 0 0 1-9.5 82.31z"/>
<path d="M0 0a5 5 0 015 5"/>
<path d="M0 0a5 5 0 015 5l5-5"/>
<path d="M15 10a5 5 0 115-5l-5 5"/>
<path d="M41.008.102a5.006 5.006 0 013.849 3.705"/>
<path d="M7.234 19.474a5 5 0 01-4.933-8.683"/>
<path d="M60 0a5 5 0 10.001 10.001A5 5 0 0060 0z"/>
<path d="M15 23.54a8.493 8.493 0 01-5.25-1.807"/>
<path d="M-9.5 82.311a4.81 4.81 0 11.002-9.622A4.81 4.81 0 01-9.5 82.31z"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -6,7 +6,7 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg">
<path d="M.49 8.8A6.44 6.44 0 0 1 6.48.02a6.44 6.44 0 0 1 5.99 8.78"/>
<path d="M.49 8.8A6.44 6.44 0 016.48.02a6.44 6.44 0 015.99 8.78"/>
<path d="M13.4 6.62c0-2.5-1.98-4.57-4.4-4.57S4.6 4.1 4.6 6.62"/>
</svg>

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 468 B

View File

@ -6,7 +6,7 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg">
<path d="M0 9V6a6 6 0 1 1 12 3"/>
<path d="M0 9V6a6 6 0 1112 3"/>
<path d="M13 7c0-3-2-5-4-5S5 4 5 7"/>
</svg>

Before

Width:  |  Height:  |  Size: 408 B

After

Width:  |  Height:  |  Size: 406 B

View File

@ -5,5 +5,5 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path d="M32 32a4 4 0 0 1-4 4H8a4 4 0 0 0-4-4V4a4 4 0 0 0 4-4h20a4 4 0 0 1 4 4v28z" fill="#888"/>
<path d="M32 32a4 4 0 01-4 4H8a4 4 0 00-4-4V4a4 4 0 004-4h20a4 4 0 014 4v28z" fill="#888"/>
</svg>

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 373 B

View File

@ -5,5 +5,5 @@
@@@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path d="M32 4a4 4 0 0 0-4-4H8a4 4 0 0 1-4 4v28a4 4 0 0 1 4 4h20a4 4 0 0 0 4-4V4z"/>
<path d="M32 4a4 4 0 00-4-4H8a4 4 0 01-4 4v28a4 4 0 014 4h20a4 4 0 004-4V4z"/>
</svg>

Before

Width:  |  Height:  |  Size: 314 B

After

Width:  |  Height:  |  Size: 308 B

View File

@ -29,7 +29,7 @@
<path d="M0 10H60L30 50z"/>
<path d="M0 0V50L50 0M0 60L50 10V60"/>
<g>
<path d="M100 0a50 50 0 0 1 0 100M25 25H75V75H25z"/>
<path d="M100 0a50 50 0 010 100M25 25H75V75H25z"/>
<path d="M135 85H185V135H135z"/>
</g>
<g>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB