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;