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