Skip to content

Commit

Permalink
Preserve stroke-width when marker-end is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Feb 24, 2021
1 parent 51f12d1 commit 3639156
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
45 changes: 26 additions & 19 deletions plugins/removeUselessStrokeAndFill.js
Expand Up @@ -41,27 +41,34 @@ exports.fn = function(item, params) {
// remove stroke*
if (
params.stroke &&
(!stroke ||
stroke == 'none' ||
item.computedAttr('stroke-opacity', '0') ||
item.computedAttr('stroke-width', '0')
(
!stroke ||
stroke == 'none' ||
item.computedAttr('stroke-opacity', '0') ||
item.computedAttr('stroke-width', '0')
)
) {
var parentStroke = item.parentNode.computedAttr('stroke'),
declineStroke = parentStroke && parentStroke != 'none';

item.eachAttr(function(attr) {
if (regStrokeProps.test(attr.name)) {
item.removeAttr(attr.name);
}
});

if (declineStroke) item.addAttr({
name: 'stroke',
value: 'none',
prefix: '',
local: 'stroke'
});
// stroke-width may affect the size of marker-end
if (
item.computedAttr('stroke-width', '0') === true ||
item.computedAttr('marker-end') == null
) {
var parentStroke = item.parentNode.computedAttr('stroke'),
declineStroke = parentStroke && parentStroke != 'none';

item.eachAttr(function(attr) {
if (regStrokeProps.test(attr.name)) {
item.removeAttr(attr.name);
}
});

if (declineStroke) item.addAttr({
name: 'stroke',
value: 'none',
prefix: '',
local: 'stroke'
});
}
}

// remove fill*
Expand Down
19 changes: 19 additions & 0 deletions test/plugins/removeUselessStrokeAndFill.04.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3639156

Please sign in to comment.