~alcinnz/haskell-stylist

d5e772956857a3d9d913303b7d91d72c02de36a1 — Adrian Cochrane 4 years ago 6c1222a
Compute correct specificity for :is() & :not() pseudoclasses.
2 files changed, 4 insertions(+), 14 deletions(-)

D ISSUES/func-psudoclasses.md
M src/Data/CSS/Style/Selector/Specificity.hs
D ISSUES/func-psudoclasses.md => ISSUES/func-psudoclasses.md +0 -13
@@ 1,13 0,0 @@
# Functional psuedoclasses
These would mostly need to be added to the interpretor.

* [x]  :not() -- TODO apply specificity
* [x]  :dir()
* [x]  :is() -- TODO apply specificity
* [x]  :lang()
* [x]  :nth-child()
* [ ]  :nth-last-child()
* [x]  :nth-of-type()
* [ ]  :nth-last-child()
* [x]  :where()
* etc

M src/Data/CSS/Style/Selector/Specificity.hs => src/Data/CSS/Style/Selector/Specificity.hs +4 -1
@@ 16,11 16,14 @@ computeSpecificity "" (Child upSel sel) = computeSpecificity "" upSel `add` comp
computeSpecificity "" (Descendant upSel sel) = computeSpecificity "" upSel `add` computeSpecificity' sel
computeSpecificity "" (Adjacent upSel sel) = computeSpecificity "" upSel `add` computeSpecificity' sel
computeSpecificity "" (Sibling upSel sel) = computeSpecificity "" upSel `add` computeSpecificity' sel
computeSpecificity _ _ = (0, 0, 1) -- psuedoelements count as a tag.
computeSpecificity _ sel = computeSpecificity "" sel `add` (0, 0, 1)

computeSpecificity' :: [SimpleSelector] -> Vec
computeSpecificity' (Tag _:sel) = computeSpecificity' sel `add` (0, 0, 1)
computeSpecificity' (Class _:sel) = computeSpecificity' sel `add` (0, 1, 0)
computeSpecificity' (Psuedoclass c args:sel)
    | c `elem` ["not", "is"], (sels, []) <- parseSelectors args =
        computeSpecificity' sel `add` maximum (map (computeSpecificity "") sels)
computeSpecificity' (Psuedoclass _ _:sel) = computeSpecificity' sel `add` (0, 1, 0)
computeSpecificity' (Property _ _:sel) = computeSpecificity' sel `add` (0, 1, 0)
computeSpecificity' (Id _:sel) = computeSpecificity' sel `add` (1, 0, 0)