Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for filter in style as well as attribute. #1952

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/collapseGroups.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { computeStyle, collectStylesheet } from '../lib/style.js';
import { inheritableAttrs, elemsGroups } from './_collections.js';

/**
Expand Down Expand Up @@ -50,7 +51,9 @@ const hasAnimatedAttr = (node, name) => {
*
* @type {import('./plugins-types.js').Plugin<'collapseGroups'>}
*/
export const fn = () => {
export const fn = (root) => {
const stylesheet = collectStylesheet(root);

return {
element: {
exit: (node, parentNode) => {
Expand All @@ -68,11 +71,14 @@ export const fn = () => {
node.children.length === 1
) {
const firstChild = node.children[0];
const nodeHasFilter = !!(
node.attributes.filter || computeStyle(stylesheet, node).filter
);
// TODO untangle this mess
if (
firstChild.type === 'element' &&
firstChild.attributes.id == null &&
node.attributes.filter == null &&
!nodeHasFilter &&
(node.attributes.class == null ||
firstChild.attributes.class == null) &&
((node.attributes['clip-path'] == null &&
Expand Down
45 changes: 45 additions & 0 deletions test/plugins/collapseGroups.18.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Don't collapse groups if outer group has filter (as style or attribute).

===

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<clipPath id="a">
<circle cx="25" cy="15" r="10"/>
</clipPath>
<filter id="b">
<feColorMatrix type="saturate"/>
</filter>
<g filter="url(#b)">
<g clip-path="url(#a)">
<circle cx="30" cy="10" r="10" fill="yellow" id="c1"/>
</g>
</g>
<g style="filter:url(#b)">
<g clip-path="url(#a)">
<circle cx="20" cy="10" r="10" fill="blue" id="c2"/>
</g>
</g>
<circle cx="25" cy="15" r="10" stroke="black" stroke-width=".1" fill="none"/>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<clipPath id="a">
<circle cx="25" cy="15" r="10"/>
</clipPath>
<filter id="b">
<feColorMatrix type="saturate"/>
</filter>
<g filter="url(#b)">
<g clip-path="url(#a)">
<circle cx="30" cy="10" r="10" fill="yellow" id="c1"/>
</g>
</g>
<g style="filter:url(#b)">
<g clip-path="url(#a)">
<circle cx="20" cy="10" r="10" fill="blue" id="c2"/>
</g>
</g>
<circle cx="25" cy="15" r="10" stroke="black" stroke-width=".1" fill="none"/>
</svg>