Repository navigation
SVG: apply CSS rules with id, compound and descendant selectors - #2201
RavSinghChandan wants to merge 9 commits into
Conversation
andersonhc
left a comment
There was a problem hiding this comment.
I found two small cascade cases worth covering before merging:
- *.a { fill: red } .a { fill: blue } currently renders red. These selectors have equal specificity, so the later rule should win.
- .a.a { fill: red } *.a { fill: blue } currently renders blue. Repeated classes count toward specificity, so .a.a should win here.
Could you preserve the original stylesheet order across all rule types and count class occurrences separately from the set used for matching?
…selectors # Conflicts: # CHANGELOG.md
|
Thanks, fixed. All rules now keep their position in the stylesheets, whatever their selector type, so with equal specificity the later rule wins: *.a { fill: red } .a { fill: blue } is blue. Specificity now counts every class, so .a.a beats *.a, while matching still uses the set of classes. Your two cases and their reverse order are in the tests. |
1 similar comment
|
Thanks, fixed. All rules now keep their position in the stylesheets, whatever their selector type, so with equal specificity the later rule wins: *.a { fill: red } .a { fill: blue } is blue. Specificity now counts every class, so .a.a beats *.a, while matching still uses the set of classes. Your two cases and their reverse order are in the tests. |
…selectors # Conflicts: # CHANGELOG.md
|
Thanks, the specificity and rule-order fixes look good. I found one remaining case: descendant and child selectors don’t apply inside pattern tiles. Pattern resolution deep-copies the elements, but _pattern_parents only contains the original nodes, so selectors such as pattern rect, #p rect, and g > rect fail to match. Could you preserve ancestor information when resolving patterns? |
…selectors # Conflicts: # CHANGELOG.md
Pattern resolution deep-copies the pattern, and only the original elements had a parent, so pattern rect, #p rect or g > rect did not match inside a tile. The copy now has the ancestors of the pattern and its children have it as parent.
|
Thanks, fixed. Pattern resolution deep-copies the pattern, and only the original elements had a parent, so selectors with ancestors did not match inside a tile. The copy now has the pattern's ancestors and its children have it as parent, so pattern rect, #p rect, g > rect, pattern > rect and defs rect apply, also for a pattern that refers to another by href. Tests cover them and the cases that must not match; they fail without the change. |
Mermaid styles flowcharts with rules such as
#mermaid-svg .node rect { fill: #ECECFF; stroke: #9370DB }. fpdf2 only reads class, element and*selectors, so these rules are ignored and every node of a Mermaid flowchart is drawn as a black box.Selectors made of element names, ids and classes, joined by descendant or child combinators (
#m .node rect,rect#a.b,g.node > rect), now apply. The rules of an element are applied by specificity, then in order, as in CSS; class, element and*rules behave as before. Selectors with pseudo-classes, attribute selectors or sibling combinators are still ignored. What is known about each element is kept, so matching takes linear time in the number of elements, even for a long selector over deeply nested groups.test_svg_css_selectors_with_ids_and_combinatorsandtest_svg_css_descendant_selectors_linear_timecover these; they fail without the change. None of the 258 SVGs with a<style>I tried fails where it did not before.