~alcinnz/haskell-stylist

ref: 768a480d006a0bb80d3f56e5ebdaee42af15fa7e haskell-stylist/src/Stylish/Style/Selector.hs -rw-r--r-- 1.2 KiB
768a480d — Adrian Cochrane Cascade CSS properties. 5 years ago
                                                                                
7d540c43 Adrian Cochrane
2881aec4 Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
2881aec4 Adrian Cochrane
768a480d Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
2881aec4 Adrian Cochrane
768a480d Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Stylish.Style.Selector(
        QueryableStyleSheet(..), queryableStyleSheet,
        queryRules
    ) where

import Stylish.Style.Selector.Index
import Stylish.Style.Selector.Interpret
import Stylish.Style.Selector.Specificity
import Stylish.Style.Selector.Importance
import Stylish.Style.Selector.Common

import Stylish.Parse (StyleSheet(..))

-- TODO do performance tests to decide beside between strict/lazy.
import Data.HashMap.Strict

ruleStore = ImportanceSplitter $ OrderedRuleStore (InterpretedRuleStore styleIndex) 0

data QueryableStyleSheet store = QueryableStyleSheet {
    store :: store,
    priority :: Int -- author vs user agent vs user styles
}

queryableStyleSheet = QueryableStyleSheet {store = ruleStore, priority = 0}

instance RuleStore s => StyleSheet (QueryableStyleSheet s) where
    addRule self@(QueryableStyleSheet store priority) rule = self {
            store = addStyleRule store priority $ styleRule' rule
        }

queryRules (QueryableStyleSheet store _) el = lookupRules store el

--------
---- Cascade
--------

cascadeRules rules = cascadeProperties $ concat $ Prelude.map properties rules

cascadeProperties ((name, value):props) = insert name value $ cascadeProperties props