{-# LANGUAGE OverloadedStrings #-}
module Data.CSS.Style.Selector.LowerWhere(
WhereLowerer(..)
) where
import Data.CSS.Syntax.Selector
import Data.CSS.Style.Common
lowerSelector :: Selector -> Selector
lowerSelector (Element sel) = Element $ lowerSelector' sel
lowerSelector (Child sel x) = Child (lowerSelector sel) x
lowerSelector (Descendant sel x) = Descendant (lowerSelector sel) x
lowerSelector (Adjacent sel x) = Adjacent (lowerSelector sel) x
lowerSelector (Sibling sel x) = Sibling (lowerSelector sel) x
lowerSelector' :: [SimpleSelector] -> [SimpleSelector]
lowerSelector' (Psuedoclass c args:sel)
| c `elem` ["is", "where"], ([Element arg'], []) <- parseSelectors args =
arg' ++ lowerSelector' sel
lowerSelector' (test:tests) = test : lowerSelector' tests
lowerSelector' [] = []
data WhereLowerer s = WhereLowerer s
instance RuleStore s => RuleStore (WhereLowerer s) where
new = WhereLowerer new
addStyleRule (WhereLowerer self) priority rule =
WhereLowerer $ addStyleRule self priority $ rule {
inner = StyleRule (lowerSelector sel) props psuedo
}
where StyleRule sel props psuedo = inner rule
lookupRules (WhereLowerer self) el = lookupRules self el