From 719e5df64101441309876d642cd065aa740bc883 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 23 Sep 2023 23:07:07 +0100 Subject: [PATCH] fix(reusePaths): pass test-regression task Signed-off-by: Seth Falco --- plugins/reusePaths.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/reusePaths.js b/plugins/reusePaths.js index 022b1c036..f0db774d9 100644 --- a/plugins/reusePaths.js +++ b/plugins/reusePaths.js @@ -1,5 +1,6 @@ 'use strict'; +const { collectStylesheet } = require('../lib/style'); const { detachNodeFromParent, querySelectorAll } = require('../lib/xast'); /** @@ -22,7 +23,9 @@ exports.description = * * @type {import('./plugins-types').Plugin<'reusePaths'>} */ -exports.fn = () => { +exports.fn = (root) => { + const stylesheet = collectStylesheet(root); + /** * @type {Map>} */ @@ -111,10 +114,19 @@ exports.fn = () => { attributes: { ...list[0].attributes }, children: [], }; + delete reusablePath.attributes['fill-opacity']; + delete reusablePath.attributes['stroke-opacity']; + delete reusablePath.attributes.style; delete reusablePath.attributes.transform; let id; const reusablePathId = reusablePath.attributes.id; - if (reusablePathId == null || hrefs.has(reusablePathId)) { + if ( + reusablePathId == null || + hrefs.has(reusablePathId) || + stylesheet.rules.some( + (rule) => rule.selector === `#${reusablePathId}` + ) + ) { id = 'reuse-' + index; index += 1; reusablePath.attributes.id = id;