Last active
May 6, 2024 22:03
-
-
Save joshparkerj/e8c6bb9195e25ba1fd67305f8406a13b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSpecificity(selector) { | |
// Remove :is(), :not(), and :has() pseudo-classes and retain their parameters | |
const cleanedSelector = selector.replace(/:(is|not|has)\(([^)]*)\)/g, ' $2 '); | |
const attributeRegExp = /\[[^\]]*\]/g; | |
const attributeCount = cleanedSelector.match(attributeRegExp)?.length || 0; | |
const noAttributes = cleanedSelector.replace(attributeRegExp, ''); | |
const pseudoElementRegExp = /::[^.:#>~+\s]+/g; | |
const pseudoElementCount = noAttributes.match(pseudoElementRegExp)?.length || 0; | |
const noPseudoElements = noAttributes.replace(pseudoElementRegExp, ''); | |
const idRegExp = /#[^.:#>~+\s]+/g; | |
const idCount = noPseudoElements.match(idRegExp)?.length || 0; | |
const noIds = noPseudoElements.replace(idRegExp, ''); | |
const classRegExp = /[.:][^.:#>~+\s]+/g; | |
const classCount = noIds.match(classRegExp)?.length || 0; | |
const noClasses = noIds.replace(classRegExp, ''); | |
const elementRegExp = /[^.:#>~+\s]+/g; | |
const elementCount = noClasses.match(elementRegExp)?.length || 0; | |
const noElements = noClasses.replace(elementRegExp, ''); | |
// Log any remaining parts of the selector (if any) to check for omissions | |
console.log("Remaining parts of the selector:", noElements); | |
return [idCount, classCount + attributeCount, elementCount + pseudoElementCount]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# text effect dependency graph | |
```mermaid | |
flowchart TD | |
A --> K[General Element] | |
A --> L[Element Effect Handler] | |
B[Binary] --> H[General Text] | |
H --> K | |
G[Sarcasm] --> H | |
A[Marquee] --> J[CSS] | |
P --> R[Pick] | |
P --> J | |
F[Jump] --> H | |
A --> N[CSS Keyword] | |
E[Breathe] --> I | |
H --> L | |
I --> J | |
D[Blink] --> I[General Animation] | |
I --> O[Hold With Undo] | |
K --> O | |
M --> N | |
A --> M[Inline Block] | |
I --> M | |
O --> P[Available Keys] | |
O --> Q[Highlight Element] | |
C[Unbinary] | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment