mirror of
https://github.com/svg/svgo.git
synced 2025-08-09 02:22:08 +03:00
Fix collapsing repeated with marker-mid in style rule
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { computeStyle } = require('../lib/style.js');
|
||||
const { pathElems } = require('./_collections.js');
|
||||
const { path2js, js2path, applyTransforms } = require('./_path.js');
|
||||
const { cleanupOutData } = require('../lib/svgo/tools');
|
||||
|
||||
exports.type = 'perItem';
|
||||
|
||||
@@ -30,17 +33,11 @@ exports.params = {
|
||||
forceAbsolutePath: false,
|
||||
};
|
||||
|
||||
var pathElems = require('./_collections.js').pathElems,
|
||||
path2js = require('./_path.js').path2js,
|
||||
js2path = require('./_path.js').js2path,
|
||||
applyTransforms = require('./_path.js').applyTransforms,
|
||||
cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
|
||||
roundData,
|
||||
precision,
|
||||
error,
|
||||
arcThreshold,
|
||||
arcTolerance,
|
||||
hasMarkerMid;
|
||||
let roundData;
|
||||
let precision;
|
||||
let error;
|
||||
let arcThreshold;
|
||||
let arcTolerance;
|
||||
|
||||
/**
|
||||
* Convert absolute Path to relative,
|
||||
@@ -69,7 +66,7 @@ exports.fn = function (item, params) {
|
||||
arcThreshold = params.makeArcs.threshold;
|
||||
arcTolerance = params.makeArcs.tolerance;
|
||||
}
|
||||
hasMarkerMid = item.hasAttr('marker-mid');
|
||||
const hasMarkerMid = computedStyle['marker-mid'] != null;
|
||||
|
||||
const maybeHasStroke =
|
||||
computedStyle.stroke &&
|
||||
@@ -93,6 +90,7 @@ exports.fn = function (item, params) {
|
||||
|
||||
data = filters(data, params, {
|
||||
maybeHasStrokeAndLinecap,
|
||||
hasMarkerMid,
|
||||
});
|
||||
|
||||
if (params.utilizeAbsolute) {
|
||||
@@ -256,7 +254,7 @@ function convertToRelative(path) {
|
||||
* @param {Object} params plugin params
|
||||
* @return {Array} output path data
|
||||
*/
|
||||
function filters(path, params, { maybeHasStrokeAndLinecap }) {
|
||||
function filters(path, params, { maybeHasStrokeAndLinecap, hasMarkerMid }) {
|
||||
var stringify = data2Path.bind(null, params),
|
||||
relSubpoint = [0, 0],
|
||||
pathBase = [0, 0],
|
||||
@@ -499,7 +497,7 @@ function filters(path, params, { maybeHasStrokeAndLinecap }) {
|
||||
// h 20 h 30 -> h 50
|
||||
if (
|
||||
params.collapseRepeated &&
|
||||
!hasMarkerMid &&
|
||||
hasMarkerMid === false &&
|
||||
'mhv'.indexOf(instruction) > -1 &&
|
||||
prev.instruction &&
|
||||
instruction == prev.instruction.toLowerCase() &&
|
||||
|
@@ -13,11 +13,19 @@
|
||||
<path d="M 10,50 Q 30,60 30,70 T 40,70 50,90"/>
|
||||
<path d="M 10,50 A 20,60 45 0,1 40,70 A 30,50 -30 1,1 50,70"/>
|
||||
<path d="M 10,50 A 20,60 45 0,1 40,70 30,50 -30 1,1 50,70"/>
|
||||
<style>
|
||||
.marker-mid { marker-mid: url(#); }
|
||||
</style>
|
||||
<path d="M0,0 0,5 0,10" class="marker-mid"/>
|
||||
<path d="M0,0 0,5 0,10" marker-mid="url(#)"/>
|
||||
<style>
|
||||
.linecap-round { stroke: black; stroke-linecap: round; }
|
||||
.linecap-butt { stroke: black; stroke-linecap: butt; }
|
||||
</style>
|
||||
<path d="M0,0 0,0" stroke="black" stroke-linecap="round"/>
|
||||
<path d="M0,0 0,0" style="stroke: black; stroke-linecap: round;"/>
|
||||
<path d="M0,0 0,0" class="linecap-round"/>
|
||||
<path d="M0,0 0,0" stroke="black" stroke-linecap="butt"/>
|
||||
<path d="M0,0 0,0" style="stroke: black; stroke-linecap: butt;"/>
|
||||
<path d="M0,0 0,0" class="linecap-butt"/>
|
||||
</svg>
|
||||
|
||||
@@@
|
||||
@@ -37,9 +45,17 @@
|
||||
<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"/>
|
||||
<style>
|
||||
.marker-mid { marker-mid: url(#); }
|
||||
</style>
|
||||
<path d="M0 0v5 5" class="marker-mid"/>
|
||||
<path d="M0 0v5 5" marker-mid="url(#)"/>
|
||||
<style>
|
||||
.linecap-round { stroke: black; stroke-linecap: round; }
|
||||
.linecap-butt { stroke: black; stroke-linecap: butt; }
|
||||
</style>
|
||||
<path d="M0 0h0" stroke="black" stroke-linecap="round"/>
|
||||
<path d="M0 0h0" style="stroke:black;stroke-linecap:round"/>
|
||||
<path d="M0 0h0" class="linecap-round"/>
|
||||
<path d="M0 0" stroke="black" stroke-linecap="butt"/>
|
||||
<path d="M0 0" style="stroke:black;stroke-linecap:butt"/>
|
||||
<path d="M0 0" class="linecap-butt"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.5 KiB |
@@ -108,9 +108,7 @@ const runTests = async ({ svgFiles }) => {
|
||||
// unstable test
|
||||
name === 'filters-light-04-f' ||
|
||||
// mismatched draft cases
|
||||
name === 'imp-path-01-f' ||
|
||||
name === 'interact-pointer-04-f' ||
|
||||
name === 'painting-marker-properties-01-f' ||
|
||||
name === 'pservers-pattern-05-f' ||
|
||||
name === 'struct-cond-overview-03-f' ||
|
||||
name === 'struct-use-07-b' ||
|
||||
|
Reference in New Issue
Block a user