stylist 2.6.0.0 → 2.7.0.0
raw patch · 7 files changed
+29/−12 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.CSS.Style: [priority] :: QueryableStyleSheet' store parser -> [Int]
+ Data.CSS.Style: [priorities] :: QueryableStyleSheet' store parser -> [Int]
+ Data.CSS.Style: priority :: PropertyParser a => a -> [Text]
Files
- ChangeLog.md +5/−0
- README.md +1/−1
- src/Data/CSS/Preprocessor/Text.hs +1/−0
- src/Data/CSS/Preprocessor/Text/CounterStyle.hs +5/−3
- src/Data/CSS/Style.hs +6/−5
- src/Data/CSS/Style/Cascade.hs +10/−2
- stylist.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for stylist +## 2.7.0 -- 2023-05-16+* Improved crash resiliency in rendering numbers+* Allow prioritizing specific properties in cascade.+* Renamed `priority` field of queryable stylesheets to avoid conflict in reexports (hence major version)+ ## 2.6.0 -- 2023-05-04 * Improved text generation * Added infrastructure forwarding pseudoelements to PropertyParsers
README.md view
@@ -15,7 +15,7 @@ ## API To parse a CSS stylesheet call `Data.CSS.Syntax.StyleSheet.parse` which returns a variant of the passed in `StyleSheet`. `StyleSheet` is a typeclass specifying methods for parsing at-rules (`parseAtRule`), storing parsed style rules (`addRule`), and optionally setting the stylesheet's priority (`setPriority`). -If these ultimately call down into a `Data.CSS.Syntax.Style.QueryableStyleSheet` you can call `queryRules` to find all matching style rules organized by psuedoelement. Once you have these style rules (typically by specifying a psuedoelement) you can call `cascade'` to resolve them into any instance of `PropertyParser`. To query rules not targetting a psuedoelement, you can either lookup the "" psuedoelement or use the `cascade` shorthand.+If these ultimately call down into a `Data.CSS.Syntax.Style.QueryableStyleSheet` you can call `cascade` to resolve them into any instance of `PropertyParser`. Or you can use `queryRules`/`cascade'` to handle the pseudoelements yourself before applying the cascade. `PropertyParser` allows to declaratively (via Haskell pattern matching) specify how to parse CSS properties, and how they're impacted by CSS inheritance. It has four methods: `longhand` and `shorthand` specify how to parse CSS properties, whilst `temp` and `inherit` specifies what the default values should be.
src/Data/CSS/Preprocessor/Text.hs view
@@ -82,6 +82,7 @@ afterPseudo = Nothing, markerPseudo = Nothing }+ priority self = priority $ inner self shorthand _ key value | key `elem` ["counter-reset", "counter-increment", "counter-set"],
src/Data/CSS/Preprocessor/Text/CounterStyle.hs view
@@ -201,11 +201,12 @@ fallbackSym = "\0" counterRenderCore :: CounterStyle -> Int -> Text-counterRenderCore CounterStyle { system = Cyclic, symbols = syms } x =- syms !! (pred x `rem` length syms) counterRenderCore CounterStyle { system = Fixed n, symbols = syms } x- | x - n < length syms = syms !! (x - n)+ | x - n < length syms && x >= n = syms !! (x - n) | otherwise = fallbackSym+counterRenderCore _ x | x < 0 = fallbackSym+counterRenderCore CounterStyle { system = Cyclic, symbols = syms } x =+ syms !! (pred x `rem` length syms) counterRenderCore CounterStyle { system = Symbolic, symbols = syms } x = succ (quot x' n) `Txt.replicate` (syms !! rem x' n) where (n, x') = (length syms, pred x)@@ -314,6 +315,7 @@ | otherwise = inRange y rest inRange _ [] = False counterRender self@CounterStyle { padLength = m, padChar = pad } x+ | Fixed _ <- system self = text -- Handles negatives specially here. | x < 0 = Txt.concat [ negativePrefix self, counterRender self { ranges = Just [(0, maxBound)] } $ -x, -- No fallback!
src/Data/CSS/Style.hs view
@@ -43,7 +43,7 @@ parser :: parser, -- | Whether author, useragent, or user styles are currently being parsed. -- The tail of this list indicates which Cascade Layer is active.- priority :: [Int], -- author vs user agent vs user styles, incorporates Cascade Layers+ priorities :: [Int], -- author vs user agent vs user styles, incorporates Cascade Layers -- | Parse data for @layer, to give webdevs explicit control over the cascade. layers :: AtLayer.Tree, --- | The name of the @layer we're within.@@ -54,17 +54,17 @@ queryableStyleSheet :: PropertyParser p => QueryableStyleSheet p queryableStyleSheet = QueryableStyleSheet' { store = new, parser = temp, layers = AtLayer.emptyTree,- priority = [0], layerNamespace = [] }+ priorities = [0], layerNamespace = [] } instance (RuleStore s, PropertyParser p) => StyleSheet (QueryableStyleSheet' s p) where- setPriorities vs self = self { priority = vs }+ setPriorities vs self = self { priorities = vs } addRule self@(QueryableStyleSheet' store' _ priority' _ _) rule = self { store = addStyleRule store' priority' $ styleRule' rule }- addAtRule self@QueryableStyleSheet' { layerNamespace = ns, layers = layers_, priority = v:_ }+ addAtRule self@QueryableStyleSheet' { layerNamespace = ns, layers = layers_, priorities = v:_ } "layer" toks = case parseAtLayer ns toks layers_ $ \ns' path -> self {- priority = v : path, layerNamespace = ns'+ priorities = v : path, layerNamespace = ns' } of (layers', Just self', toks') -> (self { store = store self', layers = layers' }, toks') (layers', Nothing, toks') -> (self { layers = layers' }, toks')@@ -120,6 +120,7 @@ instance PropertyParser p => PropertyParser (VarParser p) where temp = VarParser [] temp inherit (VarParser vars' self) = VarParser vars' $ inherit self+ priority (VarParser _ self) = priority self shorthand self name' value | Function "var" `elem` value || "--" `isPrefixOf` name' = [(name', value)] -- Fail during inheritance...
src/Data/CSS/Style/Cascade.hs view
@@ -12,7 +12,8 @@ -- TODO do performance tests to decide beside between strict/lazy, -- or is another Map implementation better?-import Data.HashMap.Strict+import Data.Hashable (Hashable)+import Data.HashMap.Strict as HM import qualified Data.HashMap.Lazy as HML import Data.Text (unpack, pack, isPrefixOf) @@ -44,12 +45,19 @@ -- | Variant of `cascade` which allows configuring base styles seperate from parent. cascadeWithParent :: PropertyParser p => [StyleRule'] -> Props -> p -> p -> p cascadeWithParent styles overrides parent' base = constructWithParent parent' base $- HML.toList $ cascadeRules (getVars base ++ overrides) styles+ toPrioList (priority base) $ cascadeRules (getVars base ++ overrides) styles cascadeRules :: Props -> [StyleRule'] -> HashMap Text [Token] cascadeRules overrides rules = cascadeProperties overrides $ concat $ Prelude.map properties rules cascadeProperties :: Props -> Props -> HashMap Text [Token] cascadeProperties overrides props = HML.fromList (props ++ overrides)++toPrioList :: Hashable k => [k] -> HashMap k v -> [(k, v)]+toPrioList (key:keys) map+ | Just val <- key `HM.lookup` map =+ (key, val):toPrioList keys (delete key map)+ | otherwise = toPrioList keys map+toPrioList [] map = toList map constructWithParent :: PropertyParser p => p -> p -> Props -> p constructWithParent parent' base props = dispatch parent' child props
stylist.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 2.6.0.0+version: 2.7.0.0 -- A short (one-line) description of the package. synopsis: Apply CSS styles to a document tree.