diff --git a/plugins/mergePaths.js b/plugins/mergePaths.js index 31203765c..bcfc294f9 100644 --- a/plugins/mergePaths.js +++ b/plugins/mergePaths.js @@ -1,4 +1,7 @@ /** + * @typedef {import('../lib/types.js').ComputedStyles} ComputedStyles + * @typedef {import('../lib/types.js').StaticStyle} StaticStyle + * @typedef {import('../lib/types.js').DynamicStyle} DynamicStyle * @typedef {import("../lib/types.js").PathDataItem} PathDataItem * @typedef {import('../lib/types.js').XastChild} XastChild * @typedef {import('../lib/types.js').XastElement} XastElement @@ -6,10 +9,26 @@ import { collectStylesheet, computeStyle } from '../lib/style.js'; import { path2js, js2path, intersects } from './_path.js'; +import { includesUrlReference } from '../lib/svgo/tools.js'; export const name = 'mergePaths'; export const description = 'merges multiple paths in one if possible'; +/** + * @param {ComputedStyles} computedStyle + * @param {string} attName + * @returns {boolean} + */ +function elementHasUrl(computedStyle, attName) { + const style = computedStyle[attName]; + + if (style?.type === 'static') { + return includesUrlReference(style.value); + } + + return false; +} + /** * Merge multiple Paths into one. * @@ -82,7 +101,13 @@ export const fn = (root, params) => { if ( computedStyle['marker-start'] || computedStyle['marker-mid'] || - computedStyle['marker-end'] + computedStyle['marker-end'] || + computedStyle['clip-path'] || + computedStyle['mask'] || + computedStyle['mask-image'] || + ['fill', 'filter', 'stroke'].some((attName) => + elementHasUrl(computedStyle, attName), + ) ) { if (prevPathData) { updatePreviousPath(prevChild, prevPathData); diff --git a/test/plugins/mergePaths.08.svg.txt b/test/plugins/mergePaths.08.svg.txt new file mode 100644 index 000000000..f29f30612 --- /dev/null +++ b/test/plugins/mergePaths.08.svg.txt @@ -0,0 +1,37 @@ +Don't merge paths with a linearGradient fill (issue #1267). + +=== + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugins/mergePaths.09.svg.txt b/test/plugins/mergePaths.09.svg.txt new file mode 100644 index 000000000..fc0c71090 --- /dev/null +++ b/test/plugins/mergePaths.09.svg.txt @@ -0,0 +1,37 @@ +Don't merge paths with a linearGradient stroke (issue #1267). + +=== + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugins/mergePaths.10.svg.txt b/test/plugins/mergePaths.10.svg.txt new file mode 100644 index 000000000..72f55c0e8 --- /dev/null +++ b/test/plugins/mergePaths.10.svg.txt @@ -0,0 +1,35 @@ +Don't merge paths with a filter URL (issue #1267). + +=== + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugins/mergePaths.11.svg.txt b/test/plugins/mergePaths.11.svg.txt new file mode 100644 index 000000000..96645b792 --- /dev/null +++ b/test/plugins/mergePaths.11.svg.txt @@ -0,0 +1,39 @@ +Don't merge paths with a clip-path (issue #1267). + +=== + + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugins/mergePaths.12.svg.txt b/test/plugins/mergePaths.12.svg.txt new file mode 100644 index 000000000..faf72aa5b --- /dev/null +++ b/test/plugins/mergePaths.12.svg.txt @@ -0,0 +1,41 @@ +Don't merge paths with a mask (issue #1267). + +=== + + + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + + + \ No newline at end of file