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

Add support for the !important attribute #843

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

LaurenzV
Copy link
Contributor

@LaurenzV LaurenzV commented Nov 7, 2024

This solves the problem I had where I wanted to achieve that I can override all styles in the SVG via stylesheet injection. I tested it with rsvg-convert and it works in the same way, so it would be great to have this merged. :)

@RazrFalcon
Copy link
Collaborator

Are you sure !important shouldn't be handled on the simplecss side? I genuinely have no idea how it suppose to work.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented Nov 8, 2024

Are you sure !important shouldn't be handled on the simplecss side? I genuinely have no idea how it suppose to work.

I think simplecss is low-level enough that it's enough if it provides the information whether an attribute has the important value or not, which is what it currently does. And since style deduplication is handled on the resvg side right now, we have to do it there anyway.

@RazrFalcon
Copy link
Collaborator

Looks good to me.

@RazrFalcon
Copy link
Collaborator

#252

@LaurenzV
Copy link
Contributor Author

Will try it.

@LaurenzV
Copy link
Contributor Author

Seems to work as intended. :)

Before:
test
sbahn2

After:
test
sbahn

@LaurenzV
Copy link
Contributor Author

I just noticed this, though:

When a declaration is important, the order of precedence is reversed. Declarations marked as important in the user-agent style sheets override all important declarations in the user style sheets. Similarly, all important declarations in the user style sheets override all important declarations in the author's style sheets. Finally, all important declarations take precedence over all animations.

So I think I need to adapt the swapping condition a bit. Will do so a bit later.

@LaurenzV
Copy link
Contributor Author

The condition should probably be:

  • Existing is not important, new is not important -> swap
  • Existing is important, new is not important -> don't swap
  • Existing is not important, new is important -> swap
  • Existing is important, new is important -> don't swap (since the order is reversed, so existing important attributes take precedence over new important attributes)

Will adapt it and extend the test cases.

@LaurenzV
Copy link
Contributor Author

Should be good now.

@LaurenzV
Copy link
Contributor Author

Is this okay to merge? Not sure who to ping, @waywardmonkeys maybe?

@waywardmonkeys
Copy link
Collaborator

@LaurenzV Well, I think @RazrFalcon said it looks good, so I think I can approve it and you can merge it?

@DJMcNab
Copy link
Member

DJMcNab commented Nov 26, 2024

It's Linebender policy to not merge without an approval. #843 (comment) is close enough to approval that I'm happy to formalise it, although I'll just give the actual change a quick scan.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@LaurenzV LaurenzV merged commit a53573b into linebender:main Nov 26, 2024
3 checks passed
@LaurenzV LaurenzV deleted the important branch November 26, 2024 17:08
@LaurenzV
Copy link
Contributor Author

Thanks!

@DJMcNab
Copy link
Member

DJMcNab commented Nov 26, 2024

where I wanted to achieve that I can override all styles in the SVG via stylesheet injection

Incidentally, does the new swapping behaviour not break this? This injection is basically equivalent to a user agent/user stylesheet, right?

@LaurenzV
Copy link
Contributor Author

Incidentally, does the new swapping behaviour not break this? This injection is basically equivalent to a user agent/user stylesheet, right?

Hmm, do you have an example? I don't think so though, otherwise the test cases wouldn't work. :D The swapping behavior also existed before, all I changed is that in case the original attribute in the injected stylesheet had !important, it will not be swapped (and thus not removed from the style chain).

@DJMcNab
Copy link
Member

DJMcNab commented Nov 26, 2024

Ooh, I see. That makes so much more sense.
I had the condition inverted in my head.

Because my intuition was that the user stylesheet would override the document, since that seems obviously correct. But that's not how the spec is written (the document overwriting the user agent makes sense of course, which I missed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants