Skip to content

Commit ba7e9bd

Browse files
committed
Fix collapsing repeated with marker-mid in style rule
1 parent 21c04e4 commit ba7e9bd

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

plugins/convertPathData.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict';
22

33
const { computeStyle } = require('../lib/style.js');
4+
const { pathElems } = require('./_collections.js');
5+
const { path2js, js2path, applyTransforms } = require('./_path.js');
6+
const { cleanupOutData } = require('../lib/svgo/tools');
47

58
exports.type = 'perItem';
69

@@ -30,17 +33,11 @@ exports.params = {
3033
forceAbsolutePath: false,
3134
};
3235

33-
var pathElems = require('./_collections.js').pathElems,
34-
path2js = require('./_path.js').path2js,
35-
js2path = require('./_path.js').js2path,
36-
applyTransforms = require('./_path.js').applyTransforms,
37-
cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
38-
roundData,
39-
precision,
40-
error,
41-
arcThreshold,
42-
arcTolerance,
43-
hasMarkerMid;
36+
let roundData;
37+
let precision;
38+
let error;
39+
let arcThreshold;
40+
let arcTolerance;
4441

4542
/**
4643
* Convert absolute Path to relative,
@@ -69,7 +66,7 @@ exports.fn = function (item, params) {
6966
arcThreshold = params.makeArcs.threshold;
7067
arcTolerance = params.makeArcs.tolerance;
7168
}
72-
hasMarkerMid = item.hasAttr('marker-mid');
69+
const hasMarkerMid = computedStyle['marker-mid'] != null;
7370

7471
const maybeHasStroke =
7572
computedStyle.stroke &&
@@ -93,6 +90,7 @@ exports.fn = function (item, params) {
9390

9491
data = filters(data, params, {
9592
maybeHasStrokeAndLinecap,
93+
hasMarkerMid,
9694
});
9795

9896
if (params.utilizeAbsolute) {
@@ -256,7 +254,7 @@ function convertToRelative(path) {
256254
* @param {Object} params plugin params
257255
* @return {Array} output path data
258256
*/
259-
function filters(path, params, { maybeHasStrokeAndLinecap }) {
257+
function filters(path, params, { maybeHasStrokeAndLinecap, hasMarkerMid }) {
260258
var stringify = data2Path.bind(null, params),
261259
relSubpoint = [0, 0],
262260
pathBase = [0, 0],
@@ -499,7 +497,7 @@ function filters(path, params, { maybeHasStrokeAndLinecap }) {
499497
// h 20 h 30 -> h 50
500498
if (
501499
params.collapseRepeated &&
502-
!hasMarkerMid &&
500+
hasMarkerMid === false &&
503501
'mhv'.indexOf(instruction) > -1 &&
504502
prev.instruction &&
505503
instruction == prev.instruction.toLowerCase() &&

test/plugins/convertPathData.03.svg

Lines changed: 20 additions & 4 deletions
Loading

test/regression.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ const runTests = async ({ svgFiles }) => {
108108
// unstable test
109109
name === 'filters-light-04-f' ||
110110
// mismatched draft cases
111-
name === 'imp-path-01-f' ||
112111
name === 'interact-pointer-04-f' ||
113-
name === 'painting-marker-properties-01-f' ||
114112
name === 'pservers-pattern-05-f' ||
115113
name === 'struct-cond-overview-03-f' ||
116114
name === 'struct-use-07-b' ||

0 commit comments

Comments
 (0)