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

css selector calculate specificity tool #45

Merged
merged 13 commits into from
Aug 16, 2021
Merged

Conversation

idoros
Copy link
Collaborator

@idoros idoros commented Aug 7, 2021

This PR adds calcSpecificity exported function to @tokey/css-selector-parser that accepts selector AST and returns a tuple of specificity and an helper compareSpecificity function to compare 2 specificity values.

  • base selectors: *, type, ::pseudo-element, .class, [attribute], :pseudo-class, #id, &
  • inner most specific selector: :not(), :is(), :has()
  • zero specificity: :where(), combinators, An+B...
  • pseudo-class + most specific selector: :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-of-type()
  • non native functional selectors ignore arguments specificity
  • browser prefixes - no such prefixes for any special case
  • immutable / mutable input type test
  • inner AST input support: Selector | SelectorNode
  • compareSpecificity function
  • documentation

@idoros idoros added enhancement New feature or request css-selector-parser labels Aug 7, 2021
@idoros idoros requested a review from barak007 August 9, 2021 07:43
Copy link
Collaborator

@barak007 barak007 left a comment

Choose a reason for hiding this comment

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

see comments

@idoros idoros requested a review from barak007 August 16, 2021 07:40
@idoros idoros merged commit de4d988 into master Aug 16, 2021
@idoros idoros deleted the ido/specificity-calc branch August 16, 2021 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants