-
-
Notifications
You must be signed in to change notification settings - Fork 67
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 whether an element would be traversed by selector #249
Comments
Could you provide a little more detail on your use-case? Are you trying to determine if an element matches a partial selector? |
@fb55: Sure, let's say there is a wrapper element with class |
First, practically speaking, css-select checks selectors right-to-left, so we would actually look for nodes with a Second, to execute a selector bit-by-bit, you should have a look at https://github.com/cheeriojs/cheerio-select. This library implements positional checks from jQuery, which depend on left-to-right execution. You would have to break up selectors before traversals (without removing an element), but otherwise follow the flow of this library. css-what's next version will include an |
@fb55: The Could the adapter/css-select store a statistics object for each selector that contains all the traversed elements? One issue where this can be used: svg/svgo#1077 (comment) |
The latest release ships with it 🙂
Looks like css-tree selectors would have to be stringified first, before they can be processed by css-what.
You would have to chunk up the selector using the above method, but would then be able to add all of this information. |
Fantastic! |
Assuming this has been resolve, let me know if it hasn't! |
@fb55: How can I use the |
The TypeScript types should be helpful for understanding what this is doing: To check if a selector has a traversal, you'd do: cssWhat.parse('div, a > b').some(subSelector => subSelector.some(cssWhat.isTraversal)) |
@fb55: This is a really useful tool, thanks. Example: <?xml version="1.0" standalone="no"?>
<svg width="200" height="250" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g class="wrapper">
<g class="secondary-wrapper">
<rect class="some-element" x="10" y="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/>
</g>
</g>
</svg>
Would this be easily achievable with css-select? It already uses an intelligent and high-performant way to traverse through the DOM and it 'just' would have to stop when it hits that DOM element during traversal and return |
Sometimes it is important to know whether a particular element is traversed by a CSS selector (not selected, e.g. being a descendant). How could css-tree/css-what be used to find this out in a performance-friendly manner?
The text was updated successfully, but these errors were encountered: