Skip to content

Commit

Permalink
reorganize stroke handling & watch out for style
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Mar 2, 2024
1 parent 0973084 commit d3aabf2
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions plugins/applyTransformsShapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
removeLeadingZero,
canChangePosition,
} from '../lib/svgo/tools.js';
import { attrsGroupsDefaults } from './_collections.js';
import { transform2js, transformsMultiply } from './_transforms.js';

export const name = 'applyTransformsShapes';
Expand Down Expand Up @@ -34,12 +33,6 @@ export const fn = (root, params) => {

const computedStyle = computeStyle(stylesheet, node);
if (computedStyle.filter) return;
if (
computedStyle.stroke?.type === 'dynamic' ||
computedStyle['stroke-width']?.type === 'dynamic'
) {
return;
}
if (!canChangePosition(computedStyle)) {
return;
}
Expand All @@ -51,16 +44,28 @@ export const fn = (root, params) => {
) {
return;
}

const matrix = transformsMultiply(
transform2js(node.attributes.transform),
);
const hasStroke =
computedStyle.stroke && computedStyle.stroke.value !== 'none';
const strokeWidth = Number(
computedStyle['stroke-width']?.value ||
(hasStroke && attrsGroupsDefaults.presentation['stroke-width']),
);

if (
computedStyle.stroke?.type === 'dynamic' ||
computedStyle['stroke-width']?.type === 'dynamic'
) {
return;
}
let strokeWidth = 0;
if (computedStyle['stroke-width']) {
if (!node.attributes['stroke-width']) {
return;
}
strokeWidth = +computedStyle['stroke-width'].value;
} else if (
computedStyle.stroke &&
computedStyle.stroke.value !== 'none'
) {
strokeWidth = 1;
}

const isSimilar =
(matrix.data[0] === matrix.data[3] &&
Expand Down

0 comments on commit d3aabf2

Please sign in to comment.