From 454b4277a3634d5a9289d2cf8a24f43ce8f25a3b Mon Sep 17 00:00:00 2001 From: Josep del Rio Date: Thu, 12 Aug 2021 19:51:26 +0100 Subject: [PATCH] Remove flag spaces for all arcs (#1484) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref #1476 The issue is that a path command may have multiple arcs, and the space optimization was only applied to the first one. Modified a test to check it. Co-authored-by: Josep del Río Co-authored-by: Bogdan Chadkin --- lib/path.js | 3 ++- lib/path.test.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/path.js b/lib/path.js index f8d4822b..7525341a 100644 --- a/lib/path.js +++ b/lib/path.js @@ -278,7 +278,8 @@ const stringifyArgs = ({ if ( disableSpaceAfterFlags && (command === 'A' || command === 'a') && - (i === 4 || i === 5) + // consider combined arcs + (i % 7 === 4 || i % 7 === 5) ) { result += numberString; } else if (i === 0 || numberString.startsWith('-')) { diff --git a/lib/path.test.js b/lib/path.test.js index f8edc3d8..04f7d516 100644 --- a/lib/path.test.js +++ b/lib/path.test.js @@ -165,18 +165,19 @@ describe('stringify path data', () => { { command: 'M', args: [0, 0] }, { command: 'A', args: [50, 50, 10, 1, 0, 0.2, 20] }, { command: 'a', args: [50, 50, 10, 1, 0, 0.2, 20] }, + { command: 'a', args: [50, 50, 10, 1, 0, 0.2, 20] }, ]; expect( stringifyPathData({ pathData, disableSpaceAfterFlags: false, }) - ).toEqual('M0 0A50 50 10 1 0 .2 20a50 50 10 1 0 .2 20'); + ).toEqual('M0 0A50 50 10 1 0 .2 20a50 50 10 1 0 .2 20 50 50 10 1 0 .2 20'); expect( stringifyPathData({ pathData, disableSpaceAfterFlags: true, }) - ).toEqual('M0 0A50 50 10 10.2 20a50 50 10 10.2 20'); + ).toEqual('M0 0A50 50 10 10.2 20a50 50 10 10.2 20 50 50 10 10.2 20'); }); });