Skip to content

Commit 7b39960

Browse files
committed
feat: preserves fill-rule attribute during path merging
Modifies path merging to preserve the `fill-rule` attribute from the input paths. It now checks if any of the input paths define a `fill-rule`, and if so, applies the first one found to the merged path. This ensures that the visual appearance of overlapping shapes is maintained correctly.
1 parent 5381344 commit 7b39960

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/main.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,19 @@ function mergePaths(svgElement, paths) {
253253
const pathDataArray = [];
254254
const fills = new Set();
255255
const strokes = new Set();
256+
const fillRules = new Set();
256257
const warnings = [];
257258

258259
paths.forEach(path => {
259260
const d = path.getAttribute('d');
260261
const transform = path.getAttribute('transform');
261262
const fill = path.getAttribute('fill') || 'none';
262263
const stroke = path.getAttribute('stroke') || 'none';
264+
const fillRule = path.getAttribute('fill-rule');
263265

264266
if (fill !== 'none') fills.add(fill);
265267
if (stroke !== 'none') strokes.add(stroke);
268+
if (fillRule) fillRules.add(fillRule);
266269

267270
if (d) {
268271
// If path has a transform, we need to apply it
@@ -297,15 +300,16 @@ function mergePaths(svgElement, paths) {
297300
const fill = firstPath.getAttribute('fill');
298301
const stroke = firstPath.getAttribute('stroke');
299302
const strokeWidth = firstPath.getAttribute('stroke-width');
300-
const fillRule = firstPath.getAttribute('fill-rule');
301303

302304
if (fill) newPath.setAttribute('fill', fill);
303305
if (stroke) newPath.setAttribute('stroke', stroke);
304306
if (strokeWidth) newPath.setAttribute('stroke-width', strokeWidth);
305307

306-
// Set fill-rule to evenodd to handle overlapping paths correctly
307-
// This allows overlapping shapes to create visual cutouts
308-
newPath.setAttribute('fill-rule', fillRule || 'evenodd');
308+
// Only set fill-rule if it was defined in at least one input path
309+
if (fillRules.size > 0) {
310+
// Use the first fill-rule found
311+
newPath.setAttribute('fill-rule', [...fillRules][0]);
312+
}
309313

310314
// Append the new path to the SVG
311315
clonedSvg.appendChild(newPath);

0 commit comments

Comments
 (0)