mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Fix noSpaceAfterFlags support
This commit is contained in:
25
lib/path.js
25
lib/path.js
@ -228,16 +228,29 @@ const stringifyNumber = ({ number, precision }) => {
|
||||
|
||||
// elliptical arc large-arc and sweep flags are rendered with spaces
|
||||
// because many non-browser environments are not able to parse such paths
|
||||
const stringifyArgs = ({ args, precision }) => {
|
||||
const stringifyArgs = ({
|
||||
command,
|
||||
args,
|
||||
precision,
|
||||
disableSpaceAfterFlags,
|
||||
}) => {
|
||||
let result = '';
|
||||
let prev;
|
||||
for (let i = 0; i < args.length; i += 1) {
|
||||
const number = args[i];
|
||||
const numberString = stringifyNumber({ number, precision });
|
||||
// avoid space before first and negative numbers
|
||||
if (i === 0 || numberString.startsWith('-')) {
|
||||
if (
|
||||
disableSpaceAfterFlags &&
|
||||
(command === 'A' || command === 'a') &&
|
||||
(i === 4 || i === 5)
|
||||
) {
|
||||
result += numberString;
|
||||
} else if (i === 0 || numberString.startsWith('-')) {
|
||||
// avoid space before first and negative numbers
|
||||
result += numberString;
|
||||
} else if (prev.includes('.') && numberString.startsWith('.')) {
|
||||
// remove space before decimal with zero whole
|
||||
// only when previous number is also decimal
|
||||
result += numberString;
|
||||
} else {
|
||||
result += ` ${numberString}`;
|
||||
@ -247,7 +260,7 @@ const stringifyArgs = ({ args, precision }) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const stringifyPathData = ({ pathData, precision }) => {
|
||||
const stringifyPathData = ({ pathData, precision, disableSpaceAfterFlags }) => {
|
||||
// combine sequence of the same commands
|
||||
let combined = [];
|
||||
for (let i = 0; i < pathData.length; i += 1) {
|
||||
@ -281,7 +294,9 @@ const stringifyPathData = ({ pathData, precision }) => {
|
||||
}
|
||||
let result = '';
|
||||
for (const { command, args } of combined) {
|
||||
result += command + stringifyArgs({ args, precision });
|
||||
result +=
|
||||
command +
|
||||
stringifyArgs({ command, args, precision, disableSpaceAfterFlags });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
Reference in New Issue
Block a user